@kitschpatrol/tldraw-cli 4.6.3 → 4.6.5

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,323 +0,0 @@
1
- var eD=Object.defineProperty;var tD=(e,n,t)=>n in e?eD(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var g=(e,n,t)=>tD(e,typeof n!="symbol"?n+"":n,t);function nD(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 i=Object.getOwnPropertyDescriptor(r,o);i&&Object.defineProperty(e,o,i.get?i:{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 i of o)if(i.type==="childList")for(const s of i.addedNodes)s.tagName==="LINK"&&s.rel==="modulepreload"&&r(s)}).observe(document,{childList:!0,subtree:!0});function t(o){const i={};return o.integrity&&(i.integrity=o.integrity),o.referrerPolicy&&(i.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?i.credentials="include":o.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(o){if(o.ep)return;o.ep=!0;const i=t(o);fetch(o.href,i)}})();var tn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ki(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var RI={exports:{}},yp={},LI={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 wu=Symbol.for("react.element"),rD=Symbol.for("react.portal"),oD=Symbol.for("react.fragment"),iD=Symbol.for("react.strict_mode"),sD=Symbol.for("react.profiler"),aD=Symbol.for("react.provider"),cD=Symbol.for("react.context"),lD=Symbol.for("react.forward_ref"),uD=Symbol.for("react.suspense"),dD=Symbol.for("react.memo"),hD=Symbol.for("react.lazy"),eb=Symbol.iterator;function fD(e){return e===null||typeof e!="object"?null:(e=eb&&e[eb]||e["@@iterator"],typeof e=="function"?e:null)}var FI={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},NI=Object.assign,zI={};function yc(e,n,t){this.props=e,this.context=n,this.refs=zI,this.updater=t||FI}yc.prototype.isReactComponent={};yc.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")};yc.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function BI(){}BI.prototype=yc.prototype;function Kv(e,n,t){this.props=e,this.context=n,this.refs=zI,this.updater=t||FI}var Wv=Kv.prototype=new BI;Wv.constructor=Kv;NI(Wv,yc.prototype);Wv.isPureReactComponent=!0;var tb=Array.isArray,UI=Object.prototype.hasOwnProperty,Gv={current:null},HI={key:!0,ref:!0,__self:!0,__source:!0};function KI(e,n,t){var r,o={},i=null,s=null;if(n!=null)for(r in n.ref!==void 0&&(s=n.ref),n.key!==void 0&&(i=""+n.key),n)UI.call(n,r)&&!HI.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:wu,type:e,key:i,ref:s,props:o,_owner:Gv.current}}function pD(e,n){return{$$typeof:wu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Vv(e){return typeof e=="object"&&e!==null&&e.$$typeof===wu}function gD(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var nb=/\/+/g;function Mg(e,n){return typeof e=="object"&&e!==null&&e.key!=null?gD(""+e.key):n.toString(36)}function rh(e,n,t,r,o){var i=typeof e;(i==="undefined"||i==="boolean")&&(e=null);var s=!1;if(e===null)s=!0;else switch(i){case"string":case"number":s=!0;break;case"object":switch(e.$$typeof){case wu:case rD:s=!0}}if(s)return s=e,o=o(s),e=r===""?"."+Mg(s,0):r,tb(o)?(t="",e!=null&&(t=e.replace(nb,"$&/")+"/"),rh(o,n,t,"",function(l){return l})):o!=null&&(Vv(o)&&(o=pD(o,t+(!o.key||s&&s.key===o.key?"":(""+o.key).replace(nb,"$&/")+"/")+e)),n.push(o)),1;if(s=0,r=r===""?".":r+":",tb(e))for(var a=0;a<e.length;a++){i=e[a];var c=r+Mg(i,a);s+=rh(i,n,t,c,o)}else if(c=fD(e),typeof c=="function")for(e=c.call(e),a=0;!(i=e.next()).done;)i=i.value,c=r+Mg(i,a++),s+=rh(i,n,t,c,o);else if(i==="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 s}function td(e,n,t){if(e==null)return e;var r=[],o=0;return rh(e,r,"","",function(i){return n.call(t,i,o++)}),r}function mD(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 gn={current:null},oh={transition:null},yD={ReactCurrentDispatcher:gn,ReactCurrentBatchConfig:oh,ReactCurrentOwner:Gv};function WI(){throw Error("act(...) is not supported in production builds of React.")}xe.Children={map:td,forEach:function(e,n,t){td(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return td(e,function(){n++}),n},toArray:function(e){return td(e,function(n){return n})||[]},only:function(e){if(!Vv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};xe.Component=yc;xe.Fragment=oD;xe.Profiler=sD;xe.PureComponent=Kv;xe.StrictMode=iD;xe.Suspense=uD;xe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=yD;xe.act=WI;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=NI({},e.props),o=e.key,i=e.ref,s=e._owner;if(n!=null){if(n.ref!==void 0&&(i=n.ref,s=Gv.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(c in n)UI.call(n,c)&&!HI.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:wu,type:e.type,key:o,ref:i,props:r,_owner:s}};xe.createContext=function(e){return e={$$typeof:cD,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:aD,_context:e},e.Consumer=e};xe.createElement=KI;xe.createFactory=function(e){var n=KI.bind(null,e);return n.type=e,n};xe.createRef=function(){return{current:null}};xe.forwardRef=function(e){return{$$typeof:lD,render:e}};xe.isValidElement=Vv;xe.lazy=function(e){return{$$typeof:hD,_payload:{_status:-1,_result:e},_init:mD}};xe.memo=function(e,n){return{$$typeof:dD,type:e,compare:n===void 0?null:n}};xe.startTransition=function(e){var n=oh.transition;oh.transition={};try{e()}finally{oh.transition=n}};xe.unstable_act=WI;xe.useCallback=function(e,n){return gn.current.useCallback(e,n)};xe.useContext=function(e){return gn.current.useContext(e)};xe.useDebugValue=function(){};xe.useDeferredValue=function(e){return gn.current.useDeferredValue(e)};xe.useEffect=function(e,n){return gn.current.useEffect(e,n)};xe.useId=function(){return gn.current.useId()};xe.useImperativeHandle=function(e,n,t){return gn.current.useImperativeHandle(e,n,t)};xe.useInsertionEffect=function(e,n){return gn.current.useInsertionEffect(e,n)};xe.useLayoutEffect=function(e,n){return gn.current.useLayoutEffect(e,n)};xe.useMemo=function(e,n){return gn.current.useMemo(e,n)};xe.useReducer=function(e,n,t){return gn.current.useReducer(e,n,t)};xe.useRef=function(e){return gn.current.useRef(e)};xe.useState=function(e){return gn.current.useState(e)};xe.useSyncExternalStore=function(e,n,t){return gn.current.useSyncExternalStore(e,n,t)};xe.useTransition=function(){return gn.current.useTransition()};xe.version="18.3.1";LI.exports=xe;var x=LI.exports;const Se=Ki(x),SD=nD({__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 vD=x,xD=Symbol.for("react.element"),wD=Symbol.for("react.fragment"),bD=Object.prototype.hasOwnProperty,PD=vD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,CD={key:!0,ref:!0,__self:!0,__source:!0};function GI(e,n,t){var r,o={},i=null,s=null;t!==void 0&&(i=""+t),n.key!==void 0&&(i=""+n.key),n.ref!==void 0&&(s=n.ref);for(r in n)bD.call(n,r)&&!CD.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:xD,type:e,key:i,ref:s,props:o,_owner:PD.current}}yp.Fragment=wD;yp.jsx=GI;yp.jsxs=GI;RI.exports=yp;var h=RI.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 ID(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)}}}var zc=function(e){return e&&e.Math===Math&&e},Ln=zc(typeof globalThis=="object"&&globalThis)||zc(typeof window=="object"&&window)||zc(typeof self=="object"&&self)||zc(typeof tn=="object"&&tn)||zc(typeof tn=="object"&&tn)||function(){return this}()||Function("return this")(),Yv={},mn=function(e){try{return!!e()}catch{return!0}},ED=mn,Wi=!ED(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),_D=mn,Sp=!_D(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),kD=Sp,nd=Function.prototype.call,Qo=kD?nd.bind(nd):function(){return nd.apply(nd,arguments)},VI={},YI={}.propertyIsEnumerable,XI=Object.getOwnPropertyDescriptor,TD=XI&&!YI.call({1:2},1);VI.f=TD?function(n){var t=XI(this,n);return!!t&&t.enumerable}:YI;var qI=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},ZI=Sp,QI=Function.prototype,By=QI.call,$D=ZI&&QI.bind.bind(By,By),jt=ZI?$D:function(e){return function(){return By.apply(e,arguments)}},JI=jt,MD=JI({}.toString),AD=JI("".slice),Sc=function(e){return AD(MD(e),8,-1)},jD=jt,OD=mn,DD=Sc,Ag=Object,RD=jD("".split),LD=OD(function(){return!Ag("z").propertyIsEnumerable(0)})?function(e){return DD(e)==="String"?RD(e,""):Ag(e)}:Ag,vp=function(e){return e==null},FD=vp,ND=TypeError,vc=function(e){if(FD(e))throw new ND("Can't call method on "+e);return e},zD=LD,BD=vc,xp=function(e){return zD(BD(e))},jg=typeof document=="object"&&document.all,yn=typeof jg>"u"&&jg!==void 0?function(e){return typeof e=="function"||e===jg}:function(e){return typeof e=="function"},UD=yn,Hs=function(e){return typeof e=="object"?e!==null:UD(e)},Og=Ln,HD=yn,KD=function(e){return HD(e)?e:void 0},wp=function(e,n){return arguments.length<2?KD(Og[e]):Og[e]&&Og[e][n]},WD=jt,eE=WD({}.isPrototypeOf),GD=typeof navigator<"u"&&String(navigator.userAgent)||"",tE=Ln,Dg=GD,rb=tE.process,ob=tE.Deno,ib=rb&&rb.versions||ob&&ob.version,sb=ib&&ib.v8,Or,af;sb&&(Or=sb.split("."),af=Or[0]>0&&Or[0]<4?1:+(Or[0]+Or[1]));!af&&Dg&&(Or=Dg.match(/Edge\/(\d+)/),(!Or||Or[1]>=74)&&(Or=Dg.match(/Chrome\/(\d+)/),Or&&(af=+Or[1])));var VD=af,ab=VD,YD=mn,XD=Ln,qD=XD.String,nE=!!Object.getOwnPropertySymbols&&!YD(function(){var e=Symbol("symbol detection");return!qD(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&ab&&ab<41}),ZD=nE,rE=ZD&&!Symbol.sham&&typeof Symbol.iterator=="symbol",QD=wp,JD=yn,eR=eE,tR=rE,nR=Object,oE=tR?function(e){return typeof e=="symbol"}:function(e){var n=QD("Symbol");return JD(n)&&eR(n.prototype,nR(e))},rR=String,oR=function(e){try{return rR(e)}catch{return"Object"}},iR=yn,sR=oR,aR=TypeError,Xv=function(e){if(iR(e))return e;throw new aR(sR(e)+" is not a function")},cR=Xv,lR=vp,qv=function(e,n){var t=e[n];return lR(t)?void 0:cR(t)},Rg=Qo,Lg=yn,Fg=Hs,uR=TypeError,dR=function(e,n){var t,r;if(n==="string"&&Lg(t=e.toString)&&!Fg(r=Rg(t,e))||Lg(t=e.valueOf)&&!Fg(r=Rg(t,e))||n!=="string"&&Lg(t=e.toString)&&!Fg(r=Rg(t,e)))return r;throw new uR("Can't convert object to primitive value")},iE={exports:{}},cb=Ln,hR=Object.defineProperty,Zv=function(e,n){try{hR(cb,e,{value:n,configurable:!0,writable:!0})}catch{cb[e]=n}return n},fR=Ln,pR=Zv,lb="__core-js_shared__",ub=iE.exports=fR[lb]||pR(lb,{});(ub.versions||(ub.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 Qv=iE.exports,db=Qv,Jv=function(e,n){return db[e]||(db[e]=n||{})},gR=vc,mR=Object,bu=function(e){return mR(gR(e))},yR=jt,SR=bu,vR=yR({}.hasOwnProperty),Gi=Object.hasOwn||function(n,t){return vR(SR(n),t)},xR=jt,wR=0,bR=Math.random(),PR=xR(1 .toString),sE=function(e){return"Symbol("+(e===void 0?"":e)+")_"+PR(++wR+bR,36)},CR=Ln,IR=Jv,hb=Gi,ER=sE,_R=nE,kR=rE,ya=CR.Symbol,Ng=IR("wks"),TR=kR?ya.for||ya:ya&&ya.withoutSetter||ER,Jo=function(e){return hb(Ng,e)||(Ng[e]=_R&&hb(ya,e)?ya[e]:TR("Symbol."+e)),Ng[e]},$R=Qo,fb=Hs,pb=oE,MR=qv,AR=dR,jR=Jo,OR=TypeError,DR=jR("toPrimitive"),RR=function(e,n){if(!fb(e)||pb(e))return e;var t=MR(e,DR),r;if(t){if(n===void 0&&(n="default"),r=$R(t,e,n),!fb(r)||pb(r))return r;throw new OR("Can't convert object to primitive value")}return n===void 0&&(n="number"),AR(e,n)},LR=RR,FR=oE,aE=function(e){var n=LR(e,"string");return FR(n)?n:n+""},NR=Ln,gb=Hs,Uy=NR.document,zR=gb(Uy)&&gb(Uy.createElement),cE=function(e){return zR?Uy.createElement(e):{}},BR=Wi,UR=mn,HR=cE,lE=!BR&&!UR(function(){return Object.defineProperty(HR("div"),"a",{get:function(){return 7}}).a!==7}),KR=Wi,WR=Qo,GR=VI,VR=qI,YR=xp,XR=aE,qR=Gi,ZR=lE,mb=Object.getOwnPropertyDescriptor;Yv.f=KR?mb:function(n,t){if(n=YR(n),t=XR(t),ZR)try{return mb(n,t)}catch{}if(qR(n,t))return VR(!WR(GR.f,n,t),n[t])};var xc={},QR=Wi,JR=mn,uE=QR&&JR(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),e3=Hs,t3=String,n3=TypeError,Ks=function(e){if(e3(e))return e;throw new n3(t3(e)+" is not an object")},r3=Wi,o3=lE,i3=uE,rd=Ks,yb=aE,s3=TypeError,zg=Object.defineProperty,a3=Object.getOwnPropertyDescriptor,Bg="enumerable",Ug="configurable",Hg="writable";xc.f=r3?i3?function(n,t,r){if(rd(n),t=yb(t),rd(r),typeof n=="function"&&t==="prototype"&&"value"in r&&Hg in r&&!r[Hg]){var o=a3(n,t);o&&o[Hg]&&(n[t]=r.value,r={configurable:Ug in r?r[Ug]:o[Ug],enumerable:Bg in r?r[Bg]:o[Bg],writable:!1})}return zg(n,t,r)}:zg:function(n,t,r){if(rd(n),t=yb(t),rd(r),o3)try{return zg(n,t,r)}catch{}if("get"in r||"set"in r)throw new s3("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var c3=Wi,l3=xc,u3=qI,e0=c3?function(e,n,t){return l3.f(e,n,u3(1,t))}:function(e,n,t){return e[n]=t,e},dE={exports:{}},Hy=Wi,d3=Gi,hE=Function.prototype,h3=Hy&&Object.getOwnPropertyDescriptor,t0=d3(hE,"name"),f3=t0&&(function(){}).name==="something",p3=t0&&(!Hy||Hy&&h3(hE,"name").configurable),g3={EXISTS:t0,PROPER:f3,CONFIGURABLE:p3},m3=jt,y3=yn,Ky=Qv,S3=m3(Function.toString);y3(Ky.inspectSource)||(Ky.inspectSource=function(e){return S3(e)});var fE=Ky.inspectSource,v3=Ln,x3=yn,Sb=v3.WeakMap,w3=x3(Sb)&&/native code/.test(String(Sb)),b3=Jv,P3=sE,vb=b3("keys"),pE=function(e){return vb[e]||(vb[e]=P3(e))},n0={},C3=w3,gE=Ln,I3=Hs,E3=e0,Kg=Gi,Wg=Qv,_3=pE,k3=n0,xb="Object already initialized",Wy=gE.TypeError,T3=gE.WeakMap,cf,Ll,lf,$3=function(e){return lf(e)?Ll(e):cf(e,{})},M3=function(e){return function(n){var t;if(!I3(n)||(t=Ll(n)).type!==e)throw new Wy("Incompatible receiver, "+e+" required");return t}};if(C3||Wg.state){var Yr=Wg.state||(Wg.state=new T3);Yr.get=Yr.get,Yr.has=Yr.has,Yr.set=Yr.set,cf=function(e,n){if(Yr.has(e))throw new Wy(xb);return n.facade=e,Yr.set(e,n),n},Ll=function(e){return Yr.get(e)||{}},lf=function(e){return Yr.has(e)}}else{var ea=_3("state");k3[ea]=!0,cf=function(e,n){if(Kg(e,ea))throw new Wy(xb);return n.facade=e,E3(e,ea,n),n},Ll=function(e){return Kg(e,ea)?e[ea]:{}},lf=function(e){return Kg(e,ea)}}var mE={set:cf,get:Ll,has:lf,enforce:$3,getterFor:M3},r0=jt,A3=mn,j3=yn,od=Gi,Gy=Wi,O3=g3.CONFIGURABLE,D3=fE,yE=mE,R3=yE.enforce,L3=yE.get,wb=String,ih=Object.defineProperty,F3=r0("".slice),N3=r0("".replace),z3=r0([].join),B3=Gy&&!A3(function(){return ih(function(){},"length",{value:8}).length!==8}),U3=String(String).split("String"),H3=dE.exports=function(e,n,t){F3(wb(n),0,7)==="Symbol("&&(n="["+N3(wb(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!od(e,"name")||O3&&e.name!==n)&&(Gy?ih(e,"name",{value:n,configurable:!0}):e.name=n),B3&&t&&od(t,"arity")&&e.length!==t.arity&&ih(e,"length",{value:t.arity});try{t&&od(t,"constructor")&&t.constructor?Gy&&ih(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=R3(e);return od(r,"source")||(r.source=z3(U3,typeof n=="string"?n:"")),e};Function.prototype.toString=H3(function(){return j3(this)&&L3(this).source||D3(this)},"toString");var K3=dE.exports,W3=yn,G3=xc,V3=K3,Y3=Zv,SE=function(e,n,t,r){r||(r={});var o=r.enumerable,i=r.name!==void 0?r.name:n;if(W3(t)&&V3(t,i,r),r.global)o?e[n]=t:Y3(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:G3.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},vE={},X3=Math.ceil,q3=Math.floor,Z3=Math.trunc||function(n){var t=+n;return(t>0?q3:X3)(t)},Q3=Z3,Ws=function(e){var n=+e;return n!==n||n===0?0:Q3(n)},J3=Ws,eL=Math.max,tL=Math.min,nL=function(e,n){var t=J3(e);return t<0?eL(t+n,0):tL(t,n)},rL=Ws,oL=Math.min,xE=function(e){var n=rL(e);return n>0?oL(n,9007199254740991):0},iL=xE,Pu=function(e){return iL(e.length)},sL=xp,aL=nL,cL=Pu,bb=function(e){return function(n,t,r){var o=sL(n),i=cL(o);if(i===0)return!e&&-1;var s=aL(r,i),a;if(e&&t!==t){for(;i>s;)if(a=o[s++],a!==a)return!0}else for(;i>s;s++)if((e||s in o)&&o[s]===t)return e||s||0;return!e&&-1}},lL={includes:bb(!0),indexOf:bb(!1)},uL=jt,Gg=Gi,dL=xp,hL=lL.indexOf,fL=n0,Pb=uL([].push),wE=function(e,n){var t=dL(e),r=0,o=[],i;for(i in t)!Gg(fL,i)&&Gg(t,i)&&Pb(o,i);for(;n.length>r;)Gg(t,i=n[r++])&&(~hL(o,i)||Pb(o,i));return o},o0=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],pL=wE,gL=o0,mL=gL.concat("length","prototype");vE.f=Object.getOwnPropertyNames||function(n){return pL(n,mL)};var bE={};bE.f=Object.getOwnPropertySymbols;var yL=wp,SL=jt,vL=vE,xL=bE,wL=Ks,bL=SL([].concat),PL=yL("Reflect","ownKeys")||function(n){var t=vL.f(wL(n)),r=xL.f;return r?bL(t,r(n)):t},Cb=Gi,CL=PL,IL=Yv,EL=xc,_L=function(e,n,t){for(var r=CL(n),o=EL.f,i=IL.f,s=0;s<r.length;s++){var a=r[s];!Cb(e,a)&&!(t&&Cb(t,a))&&o(e,a,i(n,a))}},kL=mn,TL=yn,$L=/#|\.prototype\./,Cu=function(e,n){var t=AL[ML(e)];return t===OL?!0:t===jL?!1:TL(n)?kL(n):!!n},ML=Cu.normalize=function(e){return String(e).replace($L,".").toLowerCase()},AL=Cu.data={},jL=Cu.NATIVE="N",OL=Cu.POLYFILL="P",DL=Cu,id=Ln,RL=Yv.f,LL=e0,FL=SE,NL=Zv,zL=_L,BL=DL,wc=function(e,n){var t=e.target,r=e.global,o=e.stat,i,s,a,c,l,u;if(r?s=id:o?s=id[t]||NL(t,{}):s=id[t]&&id[t].prototype,s)for(a in n){if(l=n[a],e.dontCallGetSet?(u=RL(s,a),c=u&&u.value):c=s[a],i=BL(r?a:t+(o?".":"#")+a,e.forced),!i&&c!==void 0){if(typeof l==typeof c)continue;zL(l,c)}(e.sham||c&&c.sham)&&LL(l,"sham",!0),FL(s,a,l,e)}},PE={},UL=wE,HL=o0,KL=Object.keys||function(n){return UL(n,HL)},WL=Wi,GL=uE,VL=xc,YL=Ks,XL=xp,qL=KL;PE.f=WL&&!GL?Object.defineProperties:function(n,t){YL(n);for(var r=XL(t),o=qL(t),i=o.length,s=0,a;i>s;)VL.f(n,a=o[s++],r[a]);return n};var ZL=wp,QL=ZL("document","documentElement"),JL=Ks,eF=PE,Ib=o0,tF=n0,nF=QL,rF=cE,oF=pE,Eb=">",_b="<",Vy="prototype",Yy="script",CE=oF("IE_PROTO"),Vg=function(){},IE=function(e){return _b+Yy+Eb+e+_b+"/"+Yy+Eb},kb=function(e){e.write(IE("")),e.close();var n=e.parentWindow.Object;return e=null,n},iF=function(){var e=rF("iframe"),n="java"+Yy+":",t;return e.style.display="none",nF.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(IE("document.F=Object")),t.close(),t.F},sd,sh=function(){try{sd=new ActiveXObject("htmlfile")}catch{}sh=typeof document<"u"?document.domain&&sd?kb(sd):iF():kb(sd);for(var e=Ib.length;e--;)delete sh[Vy][Ib[e]];return sh()};tF[CE]=!0;var EE=Object.create||function(n,t){var r;return n!==null?(Vg[Vy]=JL(n),r=new Vg,Vg[Vy]=null,r[CE]=n):r=sh(),t===void 0?r:eF.f(r,t)},sF=Jo,aF=EE,cF=xc.f,Xy=sF("unscopables"),qy=Array.prototype;qy[Xy]===void 0&&cF(qy,Xy,{configurable:!0,value:aF(null)});var i0=function(e){qy[Xy][e]=!0},lF=wc,uF=bu,dF=Pu,hF=Ws,fF=i0;lF({target:"Array",proto:!0},{at:function(n){var t=uF(this),r=dF(t),o=hF(n),i=o>=0?o:r+o;return i<0||i>=r?void 0:t[i]}});fF("at");var pF=Ln,gF=jt,Iu=function(e,n){return gF(pF[e].prototype[n])},mF=Iu;mF("Array","at");var yF=Sc,_E=Array.isArray||function(n){return yF(n)==="Array"},SF=TypeError,vF=9007199254740991,xF=function(e){if(e>vF)throw SF("Maximum allowed index exceeded");return e},wF=Sc,bF=jt,PF=function(e){if(wF(e)==="Function")return bF(e)},Tb=PF,CF=Xv,IF=Sp,EF=Tb(Tb.bind),_F=function(e,n){return CF(e),n===void 0?e:IF?EF(e,n):function(){return e.apply(n,arguments)}},kF=_E,TF=Pu,$F=xF,MF=_F,kE=function(e,n,t,r,o,i,s,a){for(var c=o,l=0,u=s?MF(s,a):!1,d,f;l<r;)l in t&&(d=u?u(t[l],l,n):t[l],i>0&&kF(d)?(f=TF(d),c=kE(e,n,d,f,c,i-1)-1):($F(c+1),e[c]=d),c++),l++;return c},TE=kE,AF=Jo,jF=AF("toStringTag"),$E={};$E[jF]="z";var OF=String($E)==="[object z]",DF=OF,RF=yn,ah=Sc,LF=Jo,FF=LF("toStringTag"),NF=Object,zF=ah(function(){return arguments}())==="Arguments",BF=function(e,n){try{return e[n]}catch{}},ME=DF?ah:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=BF(n=NF(e),FF))=="string"?t:zF?ah(n):(r=ah(n))==="Object"&&RF(n.callee)?"Arguments":r},UF=jt,HF=mn,AE=yn,KF=ME,WF=wp,GF=fE,jE=function(){},OE=WF("Reflect","construct"),s0=/^\s*(?:class|function)\b/,VF=UF(s0.exec),YF=!s0.test(jE),Bc=function(n){if(!AE(n))return!1;try{return OE(jE,[],n),!0}catch{return!1}},DE=function(n){if(!AE(n))return!1;switch(KF(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return YF||!!VF(s0,GF(n))}catch{return!0}};DE.sham=!0;var XF=!OE||HF(function(){var e;return Bc(Bc.call)||!Bc(Object)||!Bc(function(){e=!0})||e})?DE:Bc,$b=_E,qF=XF,ZF=Hs,QF=Jo,JF=QF("species"),Mb=Array,e5=function(e){var n;return $b(e)&&(n=e.constructor,qF(n)&&(n===Mb||$b(n.prototype))?n=void 0:ZF(n)&&(n=n[JF],n===null&&(n=void 0))),n===void 0?Mb:n},t5=e5,RE=function(e,n){return new(t5(e))(n===0?0:n)},n5=wc,r5=TE,o5=Xv,i5=bu,s5=Pu,a5=RE;n5({target:"Array",proto:!0},{flatMap:function(n){var t=i5(this),r=s5(t),o;return o5(n),o=a5(t,0),o.length=r5(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var c5=i0;c5("flatMap");var l5=Iu;l5("Array","flatMap");var u5=wc,d5=TE,h5=bu,f5=Pu,p5=Ws,g5=RE;u5({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=h5(this),r=f5(t),o=g5(t,0);return o.length=d5(o,t,t,r,0,n===void 0?1:p5(n)),o}});var m5=i0;m5("flat");var y5=Iu;y5("Array","flat");var S5=ME,v5=String,Eu=function(e){if(S5(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return v5(e)},x5=wc,w5=jt,b5=vc,P5=Ws,C5=Eu,I5=mn,E5=w5("".charAt),_5=I5(function(){return"𠮷".at(-2)!=="\uD842"});x5({target:"String",proto:!0,forced:_5},{at:function(n){var t=C5(b5(this)),r=t.length,o=P5(n),i=o>=0?o:r+o;return i<0||i>=r?void 0:E5(t,i)}});var k5=Iu;k5("String","at");var T5=Ks,LE=function(){var e=T5(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},a0=mn,$5=Ln,c0=$5.RegExp,l0=a0(function(){var e=c0("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),M5=l0||a0(function(){return!c0("a","y").sticky}),A5=l0||a0(function(){var e=c0("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),j5={BROKEN_CARET:A5,MISSED_STICKY:M5,UNSUPPORTED_Y:l0},O5=mn,D5=Ln,R5=D5.RegExp,L5=O5(function(){var e=R5(".","s");return!(e.dotAll&&e.test(`
18
- `)&&e.flags==="s")}),F5=mn,N5=Ln,z5=N5.RegExp,B5=F5(function(){var e=z5("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),Sa=Qo,bp=jt,U5=Eu,H5=LE,K5=j5,W5=Jv,G5=EE,V5=mE.get,Y5=L5,X5=B5,q5=W5("native-string-replace",String.prototype.replace),uf=RegExp.prototype.exec,Zy=uf,Z5=bp("".charAt),Q5=bp("".indexOf),J5=bp("".replace),Yg=bp("".slice),Qy=function(){var e=/a/,n=/b*/g;return Sa(uf,e,"a"),Sa(uf,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),FE=K5.BROKEN_CARET,Jy=/()??/.exec("")[1]!==void 0,e6=Qy||Jy||FE||Y5||X5;e6&&(Zy=function(n){var t=this,r=V5(t),o=U5(n),i=r.raw,s,a,c,l,u,d,f;if(i)return i.lastIndex=t.lastIndex,s=Sa(Zy,i,o),t.lastIndex=i.lastIndex,s;var p=r.groups,S=FE&&t.sticky,m=Sa(H5,t),w=t.source,y=0,v=o;if(S&&(m=J5(m,"y",""),Q5(m,"g")===-1&&(m+="g"),v=Yg(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&Z5(o,t.lastIndex-1)!==`
19
- `)&&(w="(?: "+w+")",v=" "+v,y++),a=new RegExp("^(?:"+w+")",m)),Jy&&(a=new RegExp("^"+w+"$(?!\\s)",m)),Qy&&(c=t.lastIndex),l=Sa(uf,S?a:t,v),S?l?(l.input=Yg(l.input,y),l[0]=Yg(l[0],y),l.index=t.lastIndex,t.lastIndex+=l[0].length):t.lastIndex=0:Qy&&l&&(t.lastIndex=t.global?l.index+l[0].length:c),Jy&&l&&l.length>1&&Sa(q5,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=G5(null),u=0;u<p.length;u++)f=p[u],d[f[0]]=l[f[1]];return l});var u0=Zy,t6=wc,Ab=u0;t6({target:"RegExp",proto:!0,forced:/./.exec!==Ab},{exec:Ab});var n6=Sp,NE=Function.prototype,jb=NE.apply,Ob=NE.call,r6=typeof Reflect=="object"&&Reflect.apply||(n6?Ob.bind(jb):function(){return Ob.apply(jb,arguments)}),Db=Qo,Rb=SE,o6=u0,Lb=mn,zE=Jo,i6=e0,s6=zE("species"),Xg=RegExp.prototype,a6=function(e,n,t,r){var o=zE(e),i=!Lb(function(){var l={};return l[o]=function(){return 7},""[e](l)!==7}),s=i&&!Lb(function(){var l=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[s6]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return l=!0,null},u[o](""),!l});if(!i||!s||t){var a=/./[o],c=n(o,""[e],function(l,u,d,f,p){var S=u.exec;return S===o6||S===Xg.exec?i&&!p?{done:!0,value:Db(a,u,d,f)}:{done:!0,value:Db(l,d,u,f)}:{done:!1}});Rb(String.prototype,e,c[0]),Rb(Xg,o,c[1])}r&&i6(Xg[o],"sham",!0)},d0=jt,c6=Ws,l6=Eu,u6=vc,d6=d0("".charAt),Fb=d0("".charCodeAt),h6=d0("".slice),Nb=function(e){return function(n,t){var r=l6(u6(n)),o=c6(t),i=r.length,s,a;return o<0||o>=i?e?"":void 0:(s=Fb(r,o),s<55296||s>56319||o+1===i||(a=Fb(r,o+1))<56320||a>57343?e?d6(r,o):s:e?h6(r,o,o+2):(s-55296<<10)+(a-56320)+65536)}},f6={codeAt:Nb(!1),charAt:Nb(!0)},p6=f6.charAt,g6=function(e,n,t){return n+(t?p6(e,n).length:1)},h0=jt,m6=bu,y6=Math.floor,qg=h0("".charAt),S6=h0("".replace),Zg=h0("".slice),v6=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,x6=/\$([$&'`]|\d{1,2})/g,BE=function(e,n,t,r,o,i){var s=t+e.length,a=r.length,c=x6;return o!==void 0&&(o=m6(o),c=v6),S6(i,c,function(l,u){var d;switch(qg(u,0)){case"$":return"$";case"&":return e;case"`":return Zg(n,0,t);case"'":return Zg(n,s);case"<":d=o[Zg(u,1,-1)];break;default:var f=+u;if(f===0)return l;if(f>a){var p=y6(f/10);return p===0?l:p<=a?r[p-1]===void 0?qg(u,1):r[p-1]+qg(u,1):l}d=r[f-1]}return d===void 0?"":d})},zb=Qo,w6=Ks,b6=yn,P6=Sc,C6=u0,I6=TypeError,E6=function(e,n){var t=e.exec;if(b6(t)){var r=zb(t,e,n);return r!==null&&w6(r),r}if(P6(e)==="RegExp")return zb(C6,e,n);throw new I6("RegExp#exec called on incompatible receiver")},_6=r6,Bb=Qo,Pp=jt,k6=a6,T6=mn,$6=Ks,M6=yn,A6=vp,j6=Ws,O6=xE,ta=Eu,D6=vc,R6=g6,L6=qv,F6=BE,N6=E6,z6=Jo,eS=z6("replace"),B6=Math.max,U6=Math.min,H6=Pp([].concat),Qg=Pp([].push),Ub=Pp("".indexOf),Hb=Pp("".slice),K6=function(e){return e===void 0?e:String(e)},W6=function(){return"a".replace(/./,"$0")==="$0"}(),Kb=function(){return/./[eS]?/./[eS]("a","$0")==="":!1}(),G6=!T6(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});k6("replace",function(e,n,t){var r=Kb?"$":"$0";return[function(i,s){var a=D6(this),c=A6(i)?void 0:L6(i,eS);return c?Bb(c,i,a,s):Bb(n,ta(a),i,s)},function(o,i){var s=$6(this),a=ta(o);if(typeof i=="string"&&Ub(i,r)===-1&&Ub(i,"$<")===-1){var c=t(n,s,a,i);if(c.done)return c.value}var l=M6(i);l||(i=ta(i));var u=s.global,d;u&&(d=s.unicode,s.lastIndex=0);for(var f=[],p;p=N6(s,a),!(p===null||(Qg(f,p),!u));){var S=ta(p[0]);S===""&&(s.lastIndex=R6(a,O6(s.lastIndex),d))}for(var m="",w=0,y=0;y<f.length;y++){p=f[y];for(var v=ta(p[0]),P=B6(U6(j6(p.index),a.length),0),E=[],C,I=1;I<p.length;I++)Qg(E,K6(p[I]));var _=p.groups;if(l){var k=H6([v],E,P,a);_!==void 0&&Qg(k,_),C=ta(_6(i,void 0,k))}else C=F6(v,a,P,E,_,i);P>=w&&(m+=Hb(a,w,P)+C,w=P+v.length)}return m+Hb(a,w)}]},!G6||!W6||Kb);var V6=Hs,Y6=Sc,X6=Jo,q6=X6("match"),Z6=function(e){var n;return V6(e)&&((n=e[q6])!==void 0?!!n:Y6(e)==="RegExp")},Q6=Qo,J6=Gi,eN=eE,tN=LE,Wb=RegExp.prototype,nN=function(e){var n=e.flags;return n===void 0&&!("flags"in Wb)&&!J6(e,"flags")&&eN(Wb,e)?Q6(tN,e):n},rN=wc,oN=Qo,f0=jt,Gb=vc,iN=yn,sN=vp,aN=Z6,Uc=Eu,cN=qv,lN=nN,uN=BE,dN=Jo,hN=dN("replace"),fN=TypeError,Jg=f0("".indexOf);f0("".replace);var Vb=f0("".slice),pN=Math.max;rN({target:"String",proto:!0},{replaceAll:function(n,t){var r=Gb(this),o,i,s,a,c,l,u,d,f,p=0,S=0,m="";if(!sN(n)){if(o=aN(n),o&&(i=Uc(Gb(lN(n))),!~Jg(i,"g")))throw new fN("`.replaceAll` does not allow non-global regexes");if(s=cN(n,hN),s)return oN(s,n,r,t)}for(a=Uc(r),c=Uc(n),l=iN(t),l||(t=Uc(t)),u=c.length,d=pN(1,u),p=Jg(a,c);p!==-1;)f=l?Uc(t(c,p,a)):uN(c,a,p,[],void 0,t),m+=Vb(a,S,p)+f,S=p+u,p=p+d>a.length?-1:Jg(a,c,p+d);return S<a.length&&(m+=Vb(a,S)),m}});var gN=Iu;gN("String","replaceAll");class ch{constructor(n){g(this,"nextValue");g(this,"diff");this.previousValue=n}get(){var r,o,i,s;const n=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,t=((s=(i=this.diff)==null?void 0:i.added)==null?void 0:s.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,i,s;const t=this.previousValue.has(n);if(t)return((i=(o=this.diff)==null?void 0:o.removed)==null?void 0:i.has(n))?this._add(n,t):void 0;(s=this.nextValue)!=null&&s.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,i,s,a;const t=this.previousValue.has(n);if(!t)return((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.has(n))?this._remove(n,t):void 0;(a=(s=this.diff)==null?void 0:s.removed)!=null&&a.has(n)||this._remove(n,t)}}const ll={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},mN=ll.Good;class UE{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?ll.Good:t>30?ll.Mid:ll.Poor,o=r===ll.Mid?"black":"white",i=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${i} %c${t}%c fps`,`color: white; background: ${mN};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 p0(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 Ft(e){return e[e.length-1]}function yN(e,n){let t,r=1/0;for(const o of e){const i=n(o);i<r&&(t=o,r=i)}return t}function SN(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 Cs{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 vN(e,n){let t,r;return function(...o){return t||(t=!0,setTimeout(()=>t=!1,n),r=e(...o)),r}}function HE(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const df=()=>{},hn={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function nn(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const it=HE((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),Gn=HE((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function KE(e,n){let t;const r=(...o)=>(t||(t={},t.promise=new Promise((i,s)=>{t.resolve=i,t.reject=s})),clearTimeout(t.timeout),t.latestArgs=o,t.timeout=setTimeout(()=>{const i=t;t=void 0;try{i.resolve(e(...i.latestArgs))}catch(s){i.reject(s)}},n),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const Yb=new WeakMap;function g0(e,n){if(typeof e!="object"||e===null)return;let t=Yb.get(e);t||(t={tags:{},extras:{}},Yb.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}class za{static async dataUrlToArrayBuffer(n){return fetch(n,{referrerPolicy:"strict-origin-when-cross-origin"}).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=i=>r(i),o.onabort=i=>r(i),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=i=>r(i),o.onabort=i=>r(i),o.readAsText(n)}})}}function tS(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function xN(e){const n=new DataView(e);let t=0;for(let r=0;r<n.byteLength;r++)t=(t<<5)-t+n.getUint8(r),t|=0;return t+""}/*!
20
- * MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
21
- * Copyright (c) Philip van Heemstra
22
- */function wN(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(i,s,a,c,l=1024){if(!s)return-1;s=new RegExp(s,"g");const u=s.source.length,d=new TextDecoder,f=i.length;if(typeof c>"u"&&(c=f),a>=f||c<=0||a>=c)return-1;i=i.subarray(a,c);let p=-1,S=0,m=0,w="";e:for(;S<i.length;){const y=S+l,v=i.subarray(S,y),P=d.decode(v,{stream:!0}),E=w+P;let C,I=-1;for(;(C=s.exec(E))!==null;){I=C.index-w.length,p=m+I;break e}S=y,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 bN=e=>new Uint8Array(e)[3]===44;/*!
23
- * MIT License
24
- * Modified code originally from <https://github.com/qzb/is-animated>
25
- * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
26
- */function Xb(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function PN(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function CN(e){const n=new Uint8Array(e);let t,r,o=0,i=0;if(!PN(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;i<2&&o<n.length;)switch(n[o]){case 44:i+=1,t=n[o+9]&128,r=n[o+9]&7,o+=10,o+=t?3*Math.pow(2,r+1):0,o+=Xb(n,o+1)+1;break;case 33:o+=2,o+=Xb(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return i>1}let nS=[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"&&(nS=new Int32Array(nS));/*!
27
- * MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
28
- * Copyright: 2014 Alex Gorbatchev
29
- * Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
30
- */const IN=(e,n)=>{let t=~~n^-1;for(let r=0;r<e.length;r++)t=nS[(t^e[r])&255]^t>>>8;return t^-1},qb=4,Zb=4;class Jr{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(!Jr.isPng(n,t))throw new Error("Not a PNG");for(t+=8;t<=n.buffer.byteLength;){const o=t,i=n.getInt32(t);t+=4;const s=Jr.getChunkType(n,t);if(s==="IDAT"&&r[s]){t+=i+qb+Zb;continue}if(s==="IEND")break;r[s]={start:o,dataOffset:t+4,size:i},t+=i+qb+Zb}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 Jr.readChunks(n)[t]}static setPhysChunk(n,t=1,r){let o=46,i=0;const s=Jr.findChunk(n,"pHYs");s&&(o=s.start,i=s.size);const a=Jr.findChunk(n,"IDAT");a&&(o=a.start,i=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,IN(d));const f=n.buffer.slice(0,o),p=n.buffer.slice(o+i);return new Blob([f,c,p],r)}}/*!
31
- * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
32
- * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
33
- */function EN(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function _N(e){const n=new Uint8Array(e);return!EN(n)||!n||n.length<21?!1:(n[20]>>1&1)===1}const kN=Object.freeze(["image/svg+xml"]),WE=Object.freeze(["image/jpeg","image/png","image/webp"]),GE=Object.freeze(["image/gif","image/apng","image/avif"]),m0=Object.freeze([...WE,...kN,...GE]),VE=Object.freeze(["video/mp4","video/webm","video/quicktime"]),TN=[...m0,...VE].join(",");class Yn{static loadVideo(n){return new Promise((t,r)=>{const o=document.createElement("video");o.onloadeddata=()=>t(o),o.onerror=i=>{console.error(i),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=i=>{console.error(i),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.referrerPolicy="strict-origin-when-cross-origin",o.src=n})}static async getVideoSize(n){return Yn.usingObjectURL(n,async t=>{const r=await Yn.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await Yn.usingObjectURL(n,Yn.loadImage);try{if(n.type==="image/png"){const r=new DataView(await n.arrayBuffer());if(Jr.isPng(r,0)){const o=Jr.findChunk(r,"pHYs");if(o){const i=Jr.parsePhys(r,o.dataOffset);if(i.unit===0&&i.ppux===i.ppuy){const s=Math.max(i.ppux/2834.5,1);return{w:Math.round(t.naturalWidth/s),h:Math.round(t.naturalHeight/s)}}}}}}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"?CN(await n.arrayBuffer()):n.type==="image/avif"?bN(await n.arrayBuffer()):n.type==="image/webp"?_N(await n.arrayBuffer()):n.type==="image/apng"?wN(await n.arrayBuffer()):!1}static isAnimatedImageType(n){return GE.includes(n||"")}static isStaticImageType(n){return WE.includes(n||"")}static isImageType(n){return m0.includes(n)}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function ad(e,n,t){return e+(n-e)*t}function Kr(e=""){let n=0,t=0,r=0,o=0;function i(){const s=n^n<<11;return n=t,t=r,r=o,o^=(o>>>19^s^s>>>8)>>>0,o/4294967296*2}for(let s=0;s<e.length+64;s++)n^=e.charCodeAt(s)|0,i();return i}function hf(e,n,t,r=!1){const[o,i]=n,[s,a]=t,c=s+(e-o)/(i-o)*(a-s);return r?s<a?Math.max(Math.min(c,a),s):Math.max(Math.min(c,s),a):c}function io(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function _n(e,n){if(io(e,n))return e[n]}function Qb(e){return Object.keys(e)}function yt(e){return Object.values(e)}function Mn(e){return Object.entries(e)}function YE(e){return Object.fromEntries(e)}function wl(e,n){const t={};let r=!1;for(const[o,i]of Mn(e))n(o,i)?t[o]=i:r=!0;return r?t:e}function _u(e,n){const t={};for(const[r,o]of Mn(e)){const i=n(r,o);t[r]=i}return t}function XE(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 Xn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",qE="a0",ZE="A00000000000000000000000000";function QE(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 JE(e){if(e.length!==QE(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function Jb(e){if(e===void 0)throw Error("n is undefined")}function e1(e){JE(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const i=Xn.indexOf(t[o])+1;i===Xn.length?t[o]="0":(t[o]=Xn.charAt(i),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 $N(e){JE(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const i=Xn.indexOf(t[o])-1;i===-1?t[o]=Xn.slice(-1):(t[o]=Xn.charAt(i),r=!1)}if(r){if(n==="a")return"Z"+Xn.slice(-1);if(n==="A")return;const o=String.fromCharCode(n.charCodeAt(0)-1);return o<"Z"?t.push(Xn.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?Xn.indexOf(e.charAt(0)):0,r=n!==void 0?Xn.indexOf(n.charAt(0)):Xn.length;if(r-t>1){const o=Math.round(.5*(t+r));return Xn.charAt(o)}else return n&&n.length>1?n.slice(0,1):Xn.charAt(t)+va(e.slice(1),void 0)}function ul(e){const n=QE(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function rS(e){if(e===ZE)throw new Error("invalid index: "+e);const n=ul(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function na(e,n){if(e!==void 0&&rS(e),n!==void 0&&rS(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return qE;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=ul(n),c=n.slice(a.length);if(a===ZE)return a+va("",c);if(a<n)return a;const l=$N(a);return Jb(l),l}if(n===void 0){const a=ul(e),c=e.slice(a.length),l=e1(a);return l===void 0?a+va(c,void 0):l}const t=ul(e),r=e.slice(t.length),o=ul(n),i=n.slice(o.length);if(t===o)return t+va(r,i);const s=e1(t);return Jb(s),s<n?s:t+va(r,void 0)}function Ri(e,n,t){if(t===0)return[];if(t===1)return[na(e,n)];if(n===void 0){let i=na(e,n);const s=[i];for(let a=0;a<t-1;a++)i=na(i,n),s.push(i);return s}if(e===void 0){let i=na(e,n);const s=[i];for(let a=0;a<t-1;a++)i=na(e,i),s.push(i);return s.reverse(),s}const r=Math.floor(t/2),o=na(e,n);return[...Ri(e,o,r),o,...Ri(o,n,t-r-1)]}const MN=qE;function AN(e){rS(e)}function tc(e,n,t){return Ri(e,n,t)}function em(e,n){return Ri(e,void 0,n)}function Fl(e,n){return Ri(e,n,1)[0]}function Do(e){return Ri(e,void 0,1)[0]}function jN(e){return Ri(void 0,e,1)[0]}function Nl(e,n="a1"){return[n,...Ri(n,void 0,e)]}function en(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function ON(e,n){return e.id>n.id?1:-1}function y0(e){try{return localStorage.getItem(e)}catch{return null}}function S0(e,n){try{localStorage.setItem(e,n)}catch{}}function DN(){try{localStorage.clear()}catch{}}function e_(e){try{return sessionStorage.getItem(e)}catch{return null}}function v0(e,n){try{sessionStorage.setItem(e,n)}catch{}}function t_(e){try{sessionStorage.removeItem(e)}catch{}}function RN(){try{sessionStorage.clear()}catch{}}const LN=()=>typeof process<"u"&&!1,xa=[],FN=60,lh=Math.ceil(1e3/FN);let Hc,tm=0,oS=0;const NN=()=>{const e=xa.splice(0,xa.length);for(const n of e)n()};function n_(){if(Hc)return;const e=Date.now(),n=e-oS;if(tm+n<lh){Hc=requestAnimationFrame(()=>{Hc=void 0,n_()});return}Hc=requestAnimationFrame(()=>{Hc=void 0,oS=e,tm=Math.min(tm+n-lh,lh*10),NN()})}let t1=!1;function r_(e){return LN()?(e(),()=>{}):(xa.includes(e)||(xa.push(e),t1||(t1=!0,oS=Date.now()-lh-1),n_()),()=>{const n=xa.indexOf(e);n>-1&&xa.splice(n,1)})}class zN{constructor(){g(this,"timeouts",[]);g(this,"intervals",[]);g(this,"rafs",[])}setTimeout(n,t,...r){const o=window.setTimeout(n,t,r);return this.timeouts.push(o),o}setInterval(n,t,...r){const o=window.setInterval(n,t,r);return this.intervals.push(o),o}requestAnimationFrame(n){const t=window.requestAnimationFrame(n);return this.rafs.push(t),t}dispose(){this.timeouts.forEach(n=>clearTimeout(n)),this.intervals.forEach(n=>clearInterval(n)),this.rafs.forEach(n=>cancelAnimationFrame(n)),this.timeouts.length=0,this.intervals.length=0,this.rafs.length=0}}function BN(e){return e!==null}function UN(){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 o_=UN(),vt=o_[0];o_[1];const HN=Object.getPrototypeOf(vt({}));let ku=(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 Cp{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,i]of Mn(t.ephemeralKeys))i&&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{...vt(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??ku())}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 Cp(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 So(e,n){return new Cp(e,{createDefaultProperties:()=>({}),validator:n.validator,scope:n.scope,ephemeralKeys:n.ephemeralKeys})}function ff(){return{added:{},updated:{},removed:{}}}function iS(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 i_(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function x0(e){const n={added:{},removed:{},updated:{}};return bl(n,e),n}function bl(e,n){for(const t of n){for(const[r,o]of Mn(t.added))if(e.removed[r]){const i=e.removed[r];delete e.removed[r],i!==o&&(e.updated[r]=[i,o])}else e.added[r]=o;for(const[r,[o,i]]of Mn(t.updated)){if(e.added[r]){e.added[r]=i,delete e.updated[r],delete e.removed[r];continue}if(e.updated[r]){e.updated[r]=[e.updated[r][0],i],delete e.removed[r];continue}e.updated[r]=t.updated[r],delete e.removed[r]}for(const[r,o]of Mn(t.removed))e.added[r]?delete e.added[r]:e.updated[r]?(e.removed[r]=e.updated[r][0],delete e.updated[r]):e.removed[r]=o}}function s_(e){return e&&typeof e=="object"&&"parents"in e}function a_(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 pf=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&s_(e))for(let t=0,r=e.parents.length;t<r;t++)pf(e.parents[t],e)},w0=(e,n)=>{if(e.children.add(n)&&s_(e))for(let t=0,r=e.parents.length;t<r;t++)w0(e.parents[t],e)};function c_(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function Vi(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const No=Vi("empty_array",()=>Object.freeze([])),n1=8;class gf{constructor(){g(this,"arraySize",0);g(this,"array",Array(n1));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<n1?(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 Zn=Symbol.for("com.tldraw.state/RESET_VALUE");class l_{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===Zn){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 i=0;i<r;i++){const s=(t-1+r-i)%r,a=o[s];if(!a)return Zn;const[c,l]=a;if(i===0&&n>=l)return[];if(c<=n&&n<l){const u=i+1,d=new Array(u);for(let f=0;f<u;f++)d[f]=o[(s+f)%r][2];return d}}return Zn}}class KN{constructor(n,t){g(this,"offset",0);g(this,"maybeRemoved");this.below=n,this.child=t}}const nt=Vi("capture",()=>({stack:null}));function nm(e){const n=nt.stack;nt.stack=null;try{return e()}finally{nt.stack=n}}function u_(e){nt.stack=new KN(nt.stack,e),e.parentSet.clear()}function d_(){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)||pf(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)||pf(t,e.child)}}function mf(e){if(nt.stack){if(nt.stack.child.parentSet.has(e))return;if(nt.stack.child.parentSet.add(e),nt.stack.child.isActivelyListening&&w0(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 wi=-1;class WN{constructor(n,t,r){g(this,"_isActivelyListening",!1);g(this,"lastTraversedEpoch",wi);g(this,"lastReactedEpoch",wi);g(this,"_scheduleCount",0);g(this,"parentSet",new gf);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!==Pn()){if(this.parents.length&&!a_(this)){this.lastReactedEpoch=Pn();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++)w0(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)pf(this.parents[n],this)}execute(){try{u_(this);const n=Pn(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=n,t}finally{d_()}}}const bc=Vi("EffectScheduler",()=>WN);function Gs(e,n,t){const r=new bc(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function GN(e,n,t){const r=new bc(e,n,t);return{scheduler:r,start:o=>{const i=(o==null?void 0:o.force)??!1;r.attach(),i?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class VN{constructor(n){g(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){this.isRoot?h_(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=Vi("transactions",()=>({globalEpoch:wi+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:wi+1}));function YN(){return ze.reactionEpoch}function Pn(){return ze.globalEpoch}function XN(){return ze.globalIsReacting}function b0(e,n){n.lastTraversedEpoch!==ze.globalEpoch&&(n.lastTraversedEpoch=ze.globalEpoch,n instanceof bc?e.add(n):n.children.visit(t=>b0(e,t)))}function h_(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(i=>b0(t,i));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 i of o)i.maybeScheduleEffect()}}finally{ze.cleanupReactors=null,ze.globalIsReacting=!1}}function qN(e,n){if(ze.globalIsReacting){const t=ze.cleanupReactors??(ze.cleanupReactors=new Set);e.children.visit(r=>b0(t,r))}else ze.currentTransaction?ze.currentTransaction.initialAtomValues.has(e)||ze.currentTransaction.initialAtomValues.set(e,n):h_([e])}function ZN(){ze.globalEpoch++}function QN(e){const n=new VN(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 vs(e){return ze.currentTransaction?e():QN(e)}class JN{constructor(n,t,r){g(this,"isEqual");g(this,"computeDiff");g(this,"lastChangedEpoch",Pn());g(this,"children",new gf);g(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new l_(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(n){return this.current}get(){return mf(this),this.current}set(n,t){var o,i;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??c_(this.current,n))return this.current;ZN(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Pn(),t??((i=this.computeDiff)==null?void 0:i.call(this,this.current,n,this.lastChangedEpoch,Pn()))??Zn),this.lastChangedEpoch=Pn();const r=this.current;return this.current=n,qN(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return mf(this),n>=this.lastChangedEpoch?No:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Zn}}const e4=Vi("Atom",()=>JN);function rn(e,n,t){return new e4(e,n,t)}let r1=!1;function t4(){r1||(r1=!0,console.warn(`Using \`@computed\` as a decorator for getters is deprecated and will be removed in the near future. Please refactor to use \`@computed\` as a decorator for methods.
34
-
35
- // Before
36
- @computed
37
- get foo() {
38
- return 'foo'
39
- }
40
-
41
- // After
42
- @computed
43
- getFoo() {
44
- return 'foo'
45
- }
46
- `))}const dl=Symbol.for("com.tldraw.state/UNINITIALIZED"),xs=e=>e===dl,sS=Vi("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function hl(e,n){return new sS(e,n)}class n4{constructor(n,t,r){g(this,"lastChangedEpoch",wi);g(this,"lastTraversedEpoch",wi);g(this,"lastCheckedEpoch",wi);g(this,"parentSet",new gf);g(this,"parents",[]);g(this,"parentEpochs",[]);g(this,"children",new gf);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 l_(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??c_}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(n){var o;const t=this.lastChangedEpoch===wi,r=Pn();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&XN()&&this.lastTraversedEpoch<YN()||!a_(this)))if(this.lastCheckedEpoch=r,this.error){if(n)return this.state;throw this.error.thrownValue}else return this.state;try{u_(this);const i=this.derive(this.state,this.lastCheckedEpoch),s=i instanceof sS?i.value:i,a=this.state===dl;if(a||!this.isEqual(s,this.state)){if(this.historyBuffer&&!a){const c=i instanceof sS?i.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Pn(),c??((o=this.computeDiff)==null?void 0:o.call(this,this.state,s,this.lastCheckedEpoch,Pn()))??Zn)}this.lastChangedEpoch=Pn(),this.state=s}return this.error=null,this.lastCheckedEpoch=Pn(),this.state}catch(i){if(this.state!==dl&&(this.state=dl,this.lastChangedEpoch=Pn()),this.lastCheckedEpoch=Pn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:i},!n)throw i;return this.state}finally{d_()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{mf(this)}}getDiffSince(n){var t;return this.__unsafe__getWithoutCapture(!0),mf(this),n>=this.lastChangedEpoch?No:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Zn}}const P0=Vi("Computed",()=>n4);function r4(e={},n,t,r){const o=r.value,i=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let s=this[i];return s||(s=new P0(t,o.bind(this),e),Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()},r.value[i4]=!0,r}function o1(e={},n,t,r){return r.get?(t4(),o4(e,n,t,r)):r4(e,n,t,r)}function o4(e={},n,t,r){const o=r.get,i=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let s=this[i];return s||(s=new P0(t,o.bind(this),e),Object.defineProperty(this,i,{enumerable:!1,configurable:!1,writable:!1,value:s})),s.get()},r}const i4="@@__isComputedMethod__@@";function V(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>o1(e,n,t,r)}else return typeof arguments[0]=="string"?new P0(arguments[0],arguments[1],arguments[2]):o1(void 0,arguments[0],arguments[1],arguments[2])}const f_=1,s4=Vi("apiVersion",()=>f_);if(s4!==f_)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function Ip(e,n){const t=Se.useRef(n);t.current=n;const[r,o,i]=Se.useMemo(()=>{let s=null;const a=u=>(s=u,()=>{s=null}),c=new bc(`useStateTracking(${e})`,()=>{var u;return(u=t.current)==null?void 0:u.call(t)},{scheduleEffect(){s==null||s()}});return[c,a,()=>c.scheduleCount]},[e]);return Se.useSyncExternalStore(o,i,i),Se.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const i1={apply(e,n,t){return Ip(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},a4=Symbol.for("react.memo"),c4=Symbol.for("react.forward_ref");function ir(e){let n=null;const t=e.$$typeof;return t===a4&&(e=e.type,n=e.compare),t===c4?x.memo(x.forwardRef(new Proxy(e.render,i1))):x.memo(new Proxy(e,i1),n)}function l4(){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(()=>V(`useComputed(${e})`,n,t),r)}function Ei(e,n,t=No){x.useEffect(()=>{const r=new bc(e,n);return r.attach(),r.execute(),()=>{r.detach()}},t)}function G(){const e=arguments,n=e.length===3?e[2]:[e[0]],t=e.length===3?e[0]:`useValue(${e[0].name})`,r=x.useRef(!0);r.current=!0;const o=x.useMemo(()=>e.length===1?e[0]:V(t,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),n);try{const{subscribe:i,getSnapshot:s}=x.useMemo(()=>({subscribe:a=>Gs(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return x.useSyncExternalStore(i,s,s)}finally{r.current=!1}}var yf={exports:{}};yf.exports;(function(e,n){var t=200,r="__lodash_hash_undefined__",o=1,i=2,s=9007199254740991,a="[object Arguments]",c="[object Array]",l="[object AsyncFunction]",u="[object Boolean]",d="[object Date]",f="[object Error]",p="[object Function]",S="[object GeneratorFunction]",m="[object Map]",w="[object Number]",y="[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]",A="[object ArrayBuffer]",N="[object DataView]",j="[object Float32Array]",O="[object Float64Array]",R="[object Int8Array]",Y="[object Int16Array]",K="[object Int32Array]",U="[object Uint8Array]",H="[object Uint8ClampedArray]",W="[object Uint16Array]",Z="[object Uint32Array]",oe=/[\\^$.*+?()[\]{}|]/g,be=/^\[object .+?Constructor\]$/,Ae=/^(?:0|[1-9]\d*)$/,ce={};ce[j]=ce[O]=ce[R]=ce[Y]=ce[K]=ce[U]=ce[H]=ce[W]=ce[Z]=!0,ce[a]=ce[c]=ce[A]=ce[u]=ce[N]=ce[d]=ce[f]=ce[p]=ce[m]=ce[w]=ce[v]=ce[C]=ce[I]=ce[_]=ce[T]=!1;var je=typeof tn=="object"&&tn&&tn.Object===Object&&tn,Le=typeof self=="object"&&self&&self.Object===Object&&self,at=je||Le||Function("return this")(),Ie=n&&!n.nodeType&&n,pt=Ie&&!0&&e&&!e.nodeType&&e,Ue=pt&&pt.exports===Ie,lr=Ue&&je.process,zn=function(){try{return lr&&lr.binding&&lr.binding("util")}catch{}}(),Bn=zn&&zn.isTypedArray;function qe(M,L){for(var X=-1,te=M==null?0:M.length,Ze=0,ge=[];++X<te;){var gt=M[X];L(gt,X,M)&&(ge[Ze++]=gt)}return ge}function Ot(M,L){for(var X=-1,te=L.length,Ze=M.length;++X<te;)M[Ze+X]=L[X];return M}function _o(M,L){for(var X=-1,te=M==null?0:M.length;++X<te;)if(L(M[X],X,M))return!0;return!1}function Oc(M,L){for(var X=-1,te=Array(M);++X<M;)te[X]=L(X);return te}function Dc(M){return function(L){return M(L)}}function Pg(M,L){return M.has(L)}function Qs(M,L){return M==null?void 0:M[L]}function Zj(M){var L=-1,X=Array(M.size);return M.forEach(function(te,Ze){X[++L]=[Ze,te]}),X}function Qj(M,L){return function(X){return M(L(X))}}function Jj(M){var L=-1,X=Array(M.size);return M.forEach(function(te){X[++L]=te}),X}var eO=Array.prototype,tO=Function.prototype,Vu=Object.prototype,Cg=at["__core-js_shared__"],Rw=tO.toString,Vr=Vu.hasOwnProperty,Lw=function(){var M=/[^.]+$/.exec(Cg&&Cg.keys&&Cg.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),Fw=Vu.toString,nO=RegExp("^"+Rw.call(Vr).replace(oe,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Nw=Ue?at.Buffer:void 0,Yu=at.Symbol,zw=at.Uint8Array,Bw=Vu.propertyIsEnumerable,rO=eO.splice,rs=Yu?Yu.toStringTag:void 0,Uw=Object.getOwnPropertySymbols,oO=Nw?Nw.isBuffer:void 0,iO=Qj(Object.keys,Object),Ig=Js(at,"DataView"),Rc=Js(at,"Map"),Eg=Js(at,"Promise"),_g=Js(at,"Set"),kg=Js(at,"WeakMap"),Lc=Js(Object,"create"),sO=ss(Ig),aO=ss(Rc),cO=ss(Eg),lO=ss(_g),uO=ss(kg),Hw=Yu?Yu.prototype:void 0,Tg=Hw?Hw.valueOf:void 0;function os(M){var L=-1,X=M==null?0:M.length;for(this.clear();++L<X;){var te=M[L];this.set(te[0],te[1])}}function dO(){this.__data__=Lc?Lc(null):{},this.size=0}function hO(M){var L=this.has(M)&&delete this.__data__[M];return this.size-=L?1:0,L}function fO(M){var L=this.__data__;if(Lc){var X=L[M];return X===r?void 0:X}return Vr.call(L,M)?L[M]:void 0}function pO(M){var L=this.__data__;return Lc?L[M]!==void 0:Vr.call(L,M)}function gO(M,L){var X=this.__data__;return this.size+=this.has(M)?0:1,X[M]=Lc&&L===void 0?r:L,this}os.prototype.clear=dO,os.prototype.delete=hO,os.prototype.get=fO,os.prototype.has=pO,os.prototype.set=gO;function ko(M){var L=-1,X=M==null?0:M.length;for(this.clear();++L<X;){var te=M[L];this.set(te[0],te[1])}}function mO(){this.__data__=[],this.size=0}function yO(M){var L=this.__data__,X=qu(L,M);if(X<0)return!1;var te=L.length-1;return X==te?L.pop():rO.call(L,X,1),--this.size,!0}function SO(M){var L=this.__data__,X=qu(L,M);return X<0?void 0:L[X][1]}function vO(M){return qu(this.__data__,M)>-1}function xO(M,L){var X=this.__data__,te=qu(X,M);return te<0?(++this.size,X.push([M,L])):X[te][1]=L,this}ko.prototype.clear=mO,ko.prototype.delete=yO,ko.prototype.get=SO,ko.prototype.has=vO,ko.prototype.set=xO;function is(M){var L=-1,X=M==null?0:M.length;for(this.clear();++L<X;){var te=M[L];this.set(te[0],te[1])}}function wO(){this.size=0,this.__data__={hash:new os,map:new(Rc||ko),string:new os}}function bO(M){var L=Zu(this,M).delete(M);return this.size-=L?1:0,L}function PO(M){return Zu(this,M).get(M)}function CO(M){return Zu(this,M).has(M)}function IO(M,L){var X=Zu(this,M),te=X.size;return X.set(M,L),this.size+=X.size==te?0:1,this}is.prototype.clear=wO,is.prototype.delete=bO,is.prototype.get=PO,is.prototype.has=CO,is.prototype.set=IO;function Xu(M){var L=-1,X=M==null?0:M.length;for(this.__data__=new is;++L<X;)this.add(M[L])}function EO(M){return this.__data__.set(M,r),this}function _O(M){return this.__data__.has(M)}Xu.prototype.add=Xu.prototype.push=EO,Xu.prototype.has=_O;function ai(M){var L=this.__data__=new ko(M);this.size=L.size}function kO(){this.__data__=new ko,this.size=0}function TO(M){var L=this.__data__,X=L.delete(M);return this.size=L.size,X}function $O(M){return this.__data__.get(M)}function MO(M){return this.__data__.has(M)}function AO(M,L){var X=this.__data__;if(X instanceof ko){var te=X.__data__;if(!Rc||te.length<t-1)return te.push([M,L]),this.size=++X.size,this;X=this.__data__=new is(te)}return X.set(M,L),this.size=X.size,this}ai.prototype.clear=kO,ai.prototype.delete=TO,ai.prototype.get=$O,ai.prototype.has=MO,ai.prototype.set=AO;function jO(M,L){var X=Qu(M),te=!X&&YO(M),Ze=!X&&!te&&$g(M),ge=!X&&!te&&!Ze&&Qw(M),gt=X||te||Ze||ge,kt=gt?Oc(M.length,String):[],Dt=kt.length;for(var ct in M)Vr.call(M,ct)&&!(gt&&(ct=="length"||Ze&&(ct=="offset"||ct=="parent")||ge&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||HO(ct,Dt)))&&kt.push(ct);return kt}function qu(M,L){for(var X=M.length;X--;)if(Yw(M[X][0],L))return X;return-1}function OO(M,L,X){var te=L(M);return Qu(M)?te:Ot(te,X(M))}function Fc(M){return M==null?M===void 0?$:y:rs&&rs in Object(M)?BO(M):VO(M)}function Kw(M){return Nc(M)&&Fc(M)==a}function Ww(M,L,X,te,Ze){return M===L?!0:M==null||L==null||!Nc(M)&&!Nc(L)?M!==M&&L!==L:DO(M,L,X,te,Ww,Ze)}function DO(M,L,X,te,Ze,ge){var gt=Qu(M),kt=Qu(L),Dt=gt?c:ci(M),ct=kt?c:ci(L);Dt=Dt==a?v:Dt,ct=ct==a?v:ct;var Un=Dt==v,kr=ct==v,Vt=Dt==ct;if(Vt&&$g(M)){if(!$g(L))return!1;gt=!0,Un=!1}if(Vt&&!Un)return ge||(ge=new ai),gt||Qw(M)?Gw(M,L,X,te,Ze,ge):NO(M,L,Dt,X,te,Ze,ge);if(!(X&o)){var ur=Un&&Vr.call(M,"__wrapped__"),dr=kr&&Vr.call(L,"__wrapped__");if(ur||dr){var li=ur?M.value():M,To=dr?L.value():L;return ge||(ge=new ai),Ze(li,To,X,te,ge)}}return Vt?(ge||(ge=new ai),zO(M,L,X,te,Ze,ge)):!1}function RO(M){if(!Zw(M)||WO(M))return!1;var L=Xw(M)?nO:be;return L.test(ss(M))}function LO(M){return Nc(M)&&qw(M.length)&&!!ce[Fc(M)]}function FO(M){if(!GO(M))return iO(M);var L=[];for(var X in Object(M))Vr.call(M,X)&&X!="constructor"&&L.push(X);return L}function Gw(M,L,X,te,Ze,ge){var gt=X&o,kt=M.length,Dt=L.length;if(kt!=Dt&&!(gt&&Dt>kt))return!1;var ct=ge.get(M);if(ct&&ge.get(L))return ct==L;var Un=-1,kr=!0,Vt=X&i?new Xu:void 0;for(ge.set(M,L),ge.set(L,M);++Un<kt;){var ur=M[Un],dr=L[Un];if(te)var li=gt?te(dr,ur,Un,L,M,ge):te(ur,dr,Un,M,L,ge);if(li!==void 0){if(li)continue;kr=!1;break}if(Vt){if(!_o(L,function(To,as){if(!Pg(Vt,as)&&(ur===To||Ze(ur,To,X,te,ge)))return Vt.push(as)})){kr=!1;break}}else if(!(ur===dr||Ze(ur,dr,X,te,ge))){kr=!1;break}}return ge.delete(M),ge.delete(L),kr}function NO(M,L,X,te,Ze,ge,gt){switch(X){case N:if(M.byteLength!=L.byteLength||M.byteOffset!=L.byteOffset)return!1;M=M.buffer,L=L.buffer;case A:return!(M.byteLength!=L.byteLength||!ge(new zw(M),new zw(L)));case u:case d:case w:return Yw(+M,+L);case f:return M.name==L.name&&M.message==L.message;case C:case _:return M==L+"";case m:var kt=Zj;case I:var Dt=te&o;if(kt||(kt=Jj),M.size!=L.size&&!Dt)return!1;var ct=gt.get(M);if(ct)return ct==L;te|=i,gt.set(M,L);var Un=Gw(kt(M),kt(L),te,Ze,ge,gt);return gt.delete(M),Un;case k:if(Tg)return Tg.call(M)==Tg.call(L)}return!1}function zO(M,L,X,te,Ze,ge){var gt=X&o,kt=Vw(M),Dt=kt.length,ct=Vw(L),Un=ct.length;if(Dt!=Un&&!gt)return!1;for(var kr=Dt;kr--;){var Vt=kt[kr];if(!(gt?Vt in L:Vr.call(L,Vt)))return!1}var ur=ge.get(M);if(ur&&ge.get(L))return ur==L;var dr=!0;ge.set(M,L),ge.set(L,M);for(var li=gt;++kr<Dt;){Vt=kt[kr];var To=M[Vt],as=L[Vt];if(te)var Jw=gt?te(as,To,Vt,L,M,ge):te(To,as,Vt,M,L,ge);if(!(Jw===void 0?To===as||Ze(To,as,X,te,ge):Jw)){dr=!1;break}li||(li=Vt=="constructor")}if(dr&&!li){var Ju=M.constructor,ed=L.constructor;Ju!=ed&&"constructor"in M&&"constructor"in L&&!(typeof Ju=="function"&&Ju instanceof Ju&&typeof ed=="function"&&ed instanceof ed)&&(dr=!1)}return ge.delete(M),ge.delete(L),dr}function Vw(M){return OO(M,ZO,UO)}function Zu(M,L){var X=M.__data__;return KO(L)?X[typeof L=="string"?"string":"hash"]:X.map}function Js(M,L){var X=Qs(M,L);return RO(X)?X:void 0}function BO(M){var L=Vr.call(M,rs),X=M[rs];try{M[rs]=void 0;var te=!0}catch{}var Ze=Fw.call(M);return te&&(L?M[rs]=X:delete M[rs]),Ze}var UO=Uw?function(M){return M==null?[]:(M=Object(M),qe(Uw(M),function(L){return Bw.call(M,L)}))}:QO,ci=Fc;(Ig&&ci(new Ig(new ArrayBuffer(1)))!=N||Rc&&ci(new Rc)!=m||Eg&&ci(Eg.resolve())!=P||_g&&ci(new _g)!=I||kg&&ci(new kg)!=T)&&(ci=function(M){var L=Fc(M),X=L==v?M.constructor:void 0,te=X?ss(X):"";if(te)switch(te){case sO:return N;case aO:return m;case cO:return P;case lO:return I;case uO:return T}return L});function HO(M,L){return L=L??s,!!L&&(typeof M=="number"||Ae.test(M))&&M>-1&&M%1==0&&M<L}function KO(M){var L=typeof M;return L=="string"||L=="number"||L=="symbol"||L=="boolean"?M!=="__proto__":M===null}function WO(M){return!!Lw&&Lw in M}function GO(M){var L=M&&M.constructor,X=typeof L=="function"&&L.prototype||Vu;return M===X}function VO(M){return Fw.call(M)}function ss(M){if(M!=null){try{return Rw.call(M)}catch{}try{return M+""}catch{}}return""}function Yw(M,L){return M===L||M!==M&&L!==L}var YO=Kw(function(){return arguments}())?Kw:function(M){return Nc(M)&&Vr.call(M,"callee")&&!Bw.call(M,"callee")},Qu=Array.isArray;function XO(M){return M!=null&&qw(M.length)&&!Xw(M)}var $g=oO||JO;function qO(M,L){return Ww(M,L)}function Xw(M){if(!Zw(M))return!1;var L=Fc(M);return L==p||L==S||L==l||L==E}function qw(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=s}function Zw(M){var L=typeof M;return M!=null&&(L=="object"||L=="function")}function Nc(M){return M!=null&&typeof M=="object"}var Qw=Bn?Dc(Bn):LO;function ZO(M){return XO(M)?jO(M):FO(M)}function QO(){return[]}function JO(){return!1}e.exports=qO})(yf,yf.exports);var u4=yf.exports;const d4=Ki(u4);function h4(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(i=>i.has(o))&&r.add(o);return r}function f4(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 s1(e,n){for(const[t,r]of Object.entries(e)){const o=r,i=n[t];if("eq"in o&&i!==o.eq||"neq"in o&&i===o.neq||"gt"in o&&(typeof i!="number"||i<=o.gt))return!1}return!0}function a1(e,n,t){const r=Object.fromEntries(Object.keys(t).map(o=>[o,new Set]));for(const[o,i]of Object.entries(t))if("eq"in i){const a=e.index(n,o).get().get(i.eq);if(a)for(const c of a)r[o].add(c)}else if("neq"in i){const s=e.index(n,o);for(const[a,c]of s.get())if(a!==i.neq)for(const l of c)r[o].add(l)}else if("gt"in i){const s=e.index(n,o);for(const[a,c]of s.get())if(a>i.gt)for(const l of c)r[o].add(l)}return h4(Object.values(r))}class p4{constructor(n,t){g(this,"indexCache",new Map);g(this,"historyCache",new Map);this.atoms=n,this.history=t}filterHistory(n){if(this.historyCache.has(n))return this.historyCache.get(n);const t=V("filterHistory:"+n,(r,o)=>{if(xs(r))return this.history.get();const i=this.history.getDiffSince(o);if(i===Zn)return this.history.get();const s={added:{},removed:{},updated:{}};let a=0,c=0,l=0;for(const u of i){for(const d of yt(u.added))if(d.typeName===n)if(s.removed[d.id]){const f=s.removed[d.id];delete s.removed[d.id],c--,f!==d&&(s.updated[d.id]=[f,d],l++)}else s.added[d.id]=d,a++;for(const[d,f]of yt(u.updated))f.typeName===n&&(s.added[f.id]?s.added[f.id]=f:s.updated[f.id]?s.updated[f.id]=[s.updated[f.id][0],f]:(s.updated[f.id]=[d,f],l++));for(const d of yt(u.removed))d.typeName===n&&(s.added[d.id]?(delete s.added[d.id],a--):s.updated[d.id]?(s.removed[d.id]=s.updated[d.id][0],delete s.updated[d.id],l--,c++):(s.removed[d.id]=d,c++))}return a||c||l?hl(this.history.get(),s):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 i=new Map;for(const s of yt(this.atoms.get())){const a=s.get();if(a.typeName===n){const c=a[t];i.has(c)||i.set(c,new Set),i.get(c).add(a.id)}}return i};return V("index:"+n+":"+t,(i,s)=>{if(xs(i))return o();const a=r.getDiffSince(s);if(a===Zn)return o();const c=new Map,l=(p,S)=>{let m=c.get(p);m||(m=new ch(i.get(p)??new Set)),m.add(S),c.set(p,m)},u=(p,S)=>{let m=c.get(p);m||(m=new ch(i.get(p)??new Set)),m.remove(S),c.set(p,m)};for(const p of a){for(const S of yt(p.added))if(S.typeName===n){const m=S[t];l(m,S.id)}for(const[S,m]of yt(p.updated))if(m.typeName===n){const w=S[t],y=m[t];w!==y&&(u(w,m.id),l(y,m.id))}for(const S of yt(p.removed))if(S.typeName===n){const m=S[t];u(m,S.id)}}let d,f;for(const[p,S]of c){const m=S.get();m&&(d||(d=new Map(i)),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):i},{historyLength:100})}record(n,t=()=>({}),r="record:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,r);return V(r,()=>{var i;for(const s of o.get())return(i=this.atoms.get()[s])==null?void 0:i.get()})}records(n,t=()=>({}),r="records:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,"ids:"+r);return V(r,()=>[...o.get()].map(i=>{const s=this.atoms.get()[i];if(!s)throw new Error("no atom found for record id: "+i);return s.get()}))}ids(n,t=()=>({}),r="ids:"+n+(t?":"+t.toString():"")){const o=this.filterHistory(n),i=()=>{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:[]})):a1(this,n,c)},s=c=>{const l=i(),u=f4(c,l);return u?hl(l,u):c},a=V("ids_query:"+r,t,{isEqual:d4});return V("query:"+r,(c,l)=>{const u=a.get();if(xs(c))return i();if(l<a.lastChangedEpoch)return s(c);const d=o.getDiffSince(l);if(d===Zn)return s(c);const f=new ch(c);for(const S of d){for(const m of yt(S.added))m.typeName===n&&s1(u,m)&&f.add(m.id);for(const[m,w]of yt(S.updated))w.typeName===n&&(s1(u,w)?f.add(w.id):f.remove(w.id));for(const m of yt(S.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=a1(this,n,t);if(r.size===0)return No;const o=this.atoms.get();return[...r].map(i=>o[i].get())}}class g4{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 i of r)o=i(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 i=t;for(const s of o)i=s(n,i,r);return i}return t}handleAfterChange(n,t,r){if(!this._isEnabled)return;const o=this._afterChangeHandlers[t.typeName];if(o)for(const i of o)i(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),()=>cs(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>cs(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>cs(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>cs(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>cs(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>cs(this._afterDeleteHandlers[n],t)}registerOperationCompleteHandler(n){return this._operationCompleteHandlers.push(n),()=>cs(this._operationCompleteHandlers,n)}}function cs(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}class C0{constructor(n){g(this,"id");g(this,"atoms",rn("store_atoms",{}));g(this,"history",rn("history",0,{historyLength:1e3}));g(this,"query",new p4(this.atoms,this.history));g(this,"listeners",new Set);g(this,"historyAccumulator",new y4);g(this,"historyReactor");g(this,"schema");g(this,"props");g(this,"scopedTypes");g(this,"sideEffects",new g4(this));g(this,"put",(n,t)=>{this.atomic(()=>{const r={},o={},i=this.atoms.__unsafe__getWithoutCapture();let s=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=(s??i)[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),s||(s={...i}),s[a.id]=rn("atom:"+a.id,a)}s&&this.atoms.set(s),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 i of n){const s=this.atoms.__unsafe__getWithoutCapture()[i];s&&this.sideEffects.handleBeforeDelete(s.get(),r)===!1&&t.add(i)}let o;this.atoms.update(i=>{let s;for(const a of n){if(t.has(a)||!(a in i))continue;s||(s={...i}),o||(o={}),delete s[a];const c=i[a].get();o[a]=c,this.addDiffForAfterEvent(c,null)}return s??i}),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 Mn(this.atoms.get())){const i=o.get();(n==="all"||this.scopedTypes[n].has(i.typeName))&&(t[r]=i)}return t});g(this,"allRecords",()=>yt(this.atoms.get()).map(n=>n.get()));g(this,"clear",()=>{this.remove(Qb(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,vs(n)}finally{this.isMergingRemoteChanges=!1}});g(this,"createComputedCache",(n,t,r)=>{const o=new Cs;return{get:i=>{const s=this.atoms.get()[i];if(s)return o.get(s,()=>{const a=r?V(s.name+":equals",()=>s.get(),{isEqual:r}):s;return V(n+":"+i,()=>t(a.get()))}).get()}}});g(this,"createSelectedComputedCache",(n,t,r)=>{const o=new Cs;return{get:i=>{const s=this.atoms.get()[i];if(s)return o.get(s,()=>{const a=V(n+":"+i+":selector",()=>t(s.get()));return V(n+":"+i,()=>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??ku(),this.schema=r,this.props=n.props,t&&this.atoms.set(YE(Mn(t).map(([i,s])=>[i,rn("atom:"+i,this.schema.validateRecord(this,s,"initialize",null))]))),this.historyReactor=GN("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:i=>r_(i)}),this.scopedTypes={document:new Set(yt(this.schema.types).filter(i=>i.scope==="document").map(i=>i.typeName)),session:new Set(yt(this.schema.types).filter(i=>i.scope==="session").map(i=>i.typeName)),presence:new Set(yt(this.schema.types).filter(i=>i.scope==="presence").map(i=>i.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const n=this.historyAccumulator.flush();for(const{changes:t,source:r}of n){let o=null,i=null,s=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(i??(i=this.filterChangesByScope(t,"document")),!i)continue;a({changes:i,source:r})}else if(c.scope==="session"){if(o??(o=this.filterChangesByScope(t,"session")),!o)continue;a({changes:o,source:r})}else{if(s??(s=this.filterChangesByScope(t,"presence")),!s)continue;a({changes:s,source:r})}else a({changes:t,source:r})}}}filterChangesByScope(n,t){const r={added:wl(n.added,(o,i)=>this.scopedTypes[t].has(i.typeName)),updated:wl(n.updated,(o,i)=>this.scopedTypes[t].has(i[1].typeName)),removed:wl(n.removed,(o,i)=>this.scopedTypes[t].has(i.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(n){this.historyAccumulator.add({changes:n,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,n)}validate(n){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,n,null))}getStoreSnapshot(n="document"){return{store:this.serialize(n),schema:this.schema.serialize()}}getSnapshot(n="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(n)}migrateSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(n){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(n)}extractingChanges(n){const t=[],r=this.historyAccumulator.addInterceptor(o=>t.push(o.changes));try{return vs(n),x0(t)}finally{r()}}applyDiff(n,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=yt(n.added);for(const[s,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,_n(l,d))||(u||(u={...l}),u[d]=f);u&&o.push(u)}else o.push(a)}const i=Qb(n.removed);o.length&&this.put(o),i.length&&this.remove(i)},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(it(this.pendingAfterEvents,"must be in event operation"),n===t||(n&&t&&it(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:i}of r.values())o&&i?this.sideEffects.handleAfterChange(o,i,t):o&&!i?this.sideEffects.handleAfterDelete(o,t):!o&&i&&this.sideEffects.handleAfterCreate(i,t);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(t)}}}atomic(n,t=!0){return vs(()=>{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 m4(e){if(e.length===0)return[];const n=[];let t=[e[0]],r;for(let o=1,i=e.length;o<i;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:x0(o.map(i=>i.changes))}))}class y4{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=m4(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function S4(e,n,t){const r=new Cs;return{get(o,i){return r.get(o,()=>(o instanceof C0?o:o.store).createComputedCache(e,c=>n(o,c),t)).get(i)}}}function v4(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,i=n[0];i&&(n[0]={...i,dependsOn:o.concat(i.dependsOn??[])})}}return n}function Ba({sequence:e,sequenceId:n,retroactive:t=!0}){const r={sequenceId:n,retroactive:t,sequence:v4(e)};return p_(r),r}function Fn(e,n){return Object.fromEntries(Mn(n).map(([t,r])=>[t,`${e}/${r}`]))}function sr(e){const n=e.sequenceId;return Ba({sequenceId:n,retroactive:e.retroactive??!0,sequence:e.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>{var o,i;return r.typeName===e.recordType&&(((o=t.filter)==null?void 0:o.call(t,r))??!0)&&(((i=e.filter)==null?void 0:i.call(e,r))??!0)}}:t)})}function x4(e){const n=new Map(e.map(i=>[i.id,i])),t=new Set,r=[];function o(i){it(!t.has(i.id),`Circular dependency in migrations: ${i.id}`),t.add(i.id);const{version:s,sequenceId:a}=Sf(i.id),c=n.get(`${a}/${s-1}`);if(c&&o(c),i.dependsOn)for(const l of i.dependsOn){const u=n.get(l);u&&o(u)}n.delete(i.id),r.push(i)}for(const i of n.values())o(i);return r}function Sf(e){const[n,t]=e.split("/");return{sequenceId:n,version:parseInt(t)}}function c1(e,n){n&&it(e.startsWith(n+"/"),`Every migration in sequence '${n}' must have an id starting with '${n}/'. Got invalid id: '${e}'`),it(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function p_(e){if(it(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),it(e.sequenceId.length,"sequenceId must be a non-empty string"),e.sequence.length===0)return;c1(e.sequence[0].id,e.sequenceId);let n=Sf(e.sequence[0].id).version;it(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;c1(r,e.sequenceId);const o=Sf(r).version;it(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 pi=(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))(pi||{});function w4(e){if(e.schemaVersion>2||e.schemaVersion<1)return hn.err("Bad schema version");if(e.schemaVersion===2)return hn.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,i]of Object.entries(r.subTypeVersions))n.sequences[`com.tldraw.${t}.${o}`]=i;return hn.ok(n)}class I0{constructor(n,t){g(this,"migrations",{});g(this,"sortedMigrations");var o;this.types=n,this.options=t;for(const i of t.migrations??[])it(!this.migrations[i.sequenceId],`Duplicate migration sequenceId ${i.sequenceId}`),p_(i),this.migrations[i.sequenceId]=i;const r=Object.values(this.migrations).flatMap(i=>i.sequence);this.sortedMigrations=x4(r);for(const i of this.sortedMigrations)if((o=i.dependsOn)!=null&&o.length)for(const s of i.dependsOn){const a=r.find(c=>c.id===s);it(a,`Migration '${i.id}' depends on missing migration '${s}'`)}}static create(n,t){return new I0(n,t??{})}validateRecord(n,t,r,o){try{const i=_n(this.types,t.typeName);if(!i)throw new Error(`Missing definition for record type ${t.typeName}`);return i.validate(t,o??void 0)}catch(i){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:n,record:t,phase:r,recordBefore:o,error:i});throw i}}getMigrationsSince(n){const t=w4(n);if(!t.ok)return t;const r=t.value,o=new Set(Object.keys(r.sequences).filter(s=>this.migrations[s]));for(const s in this.migrations)r.sequences[s]===void 0&&this.migrations[s].retroactive&&o.add(s);if(o.size===0)return hn.ok([]);const i=new Set;for(const s of o){const a=r.sequences[s];if(typeof a!="number"&&this.migrations[s].retroactive||a===0){for(const u of this.migrations[s].sequence)i.add(u.id);continue}const c=`${s}/${a}`,l=this.migrations[s].sequence.findIndex(u=>u.id===c);if(l===-1)return hn.err("Incompatible schema?");for(const u of this.migrations[s].sequence.slice(l+1))i.add(u.id)}return hn.ok(this.sortedMigrations.filter(({id:s})=>i.has(s)))}migratePersistedRecord(n,t,r="up"){const o=this.getMigrationsSince(t);if(!o.ok)return console.error("Error migrating record",o.error),{type:"error",reason:pi.MigrationError};let i=o.value;if(i.length===0)return{type:"success",value:n};if(i.some(s=>s.scope==="store"))return{type:"error",reason:r==="down"?pi.TargetVersionTooOld:pi.TargetVersionTooNew};if(r==="down"){if(!i.every(s=>s.down))return{type:"error",reason:pi.TargetVersionTooOld};i=i.slice().reverse()}n=vt(n);try{for(const s of i){if(s.scope==="store")throw new Error;if(!(s.filter?s.filter(n):!0))continue;const c=s[r](n);c&&(n=vt(c))}}catch(s){return console.error("Error migrating record",s),{type:"error",reason:pi.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:pi.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:t};t=vt(t);try{for(const i of o)if(i.scope==="record")for(const[s,a]of Object.entries(t)){if(!(i.filter?i.filter(a):!0))continue;const l=i.up(a);l&&(t[s]=vt(l))}else if(i.scope==="store"){const s=i.up(t);s&&(t=vt(s))}else nn(i)}catch(i){return console.error("Error migrating store",i),{type:"error",reason:pi.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?Sf(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=_n(this.types,n);return it(t,"record type does not exists"),t}}function b4(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=b4(r),i=t.split(`
47
- `).map((s,a)=>a===0?s:` ${s}`).join(`
48
- `);super(r?`At ${o}: ${i}`:i);g(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function An(e,n){try{return n()}catch(t){throw t instanceof Ce?new Ce(t.rawMessage,[e,...t.path]):new Ce(t.toString(),[e])}}function Li(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:nn(n)}}class Sn{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 k4(this)}optional(){return m_(this)}refine(n){return new Sn(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=>(An(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class P4 extends Sn{constructor(n){super(t=>{const r=l1.validate(t);for(let o=0;o<r.length;o++)An(o,()=>n.validate(r[o]));return r},(t,r)=>{if(!n.validateUsingKnownGoodVersion)return this.validate(r);const o=l1.validate(r);let i=t.length!==o.length;for(let s=0;s<o.length;s++){const a=o[s];if(s>=t.length){i=!0,An(s,()=>n.validate(a));continue}if(Object.is(t[s],a))continue;const c=An(s,()=>n.validateUsingKnownGoodVersion(t[s],a));Object.is(c,t[s])||(i=!0)}return i?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 vf extends Sn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Li(r)}`);for(const[o,i]of Object.entries(n))An(o,()=>{i.validate(_n(r,o))});if(!t){for(const o of Object.keys(r))if(!io(n,o))throw new Ce("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Li(o)}`);let i=!1;for(const[s,a]of Object.entries(n)){const c=_n(r,s),l=_n(o,s);if(Object.is(c,l))continue;const u=An(s,()=>{const d=a;return d.validateUsingKnownGoodVersion?d.validateUsingKnownGoodVersion(c,l):d.validate(l)});Object.is(u,c)||(i=!0)}if(!t){for(const s of Object.keys(o))if(!io(n,s))throw new Ce("Unexpected property",[s])}for(const s of Object.keys(r))if(!io(o,s)){i=!0;break}return i?o:r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new vf(this.config,!0)}extend(n){return new vf({...this.config,...n})}}class Ep extends Sn{constructor(n,t,r,o){super(i=>{this.expectObject(i);const{matchingSchema:s,variant:a}=this.getMatchingSchemaAndVariant(i);return s===void 0?this.unknownValueValidation(i,a):An(`(${n} = ${a})`,()=>s.validate(i))},(i,s)=>{this.expectObject(s),this.expectObject(i);const{matchingSchema:a,variant:c}=this.getMatchingSchemaAndVariant(s);return a===void 0?this.unknownValueValidation(s,c):_n(i,n)!==_n(s,n)?An(`(${n} = ${c})`,()=>a.validate(s)):An(`(${n} = ${c})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(i,s):a.validate(s))}),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 ${Li(n)}`,[])}getMatchingSchemaAndVariant(n){const t=_n(n,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new Ce(`Expected a string for key "${this.key}", got ${Li(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new Ce(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:io(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(n){return new Ep(this.key,this.config,n,this.useNumberKeys)}}class C4 extends Sn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Li(r)}`);for(const[o,i]of Object.entries(r))An(o,()=>{n.validate(o),t.validate(i)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Li(o)}`);let i=!1;for(const[s,a]of Object.entries(o)){if(!io(r,s)){i=!0,An(s,()=>{n.validate(s),t.validate(a)});continue}const c=_n(r,s),l=a;if(Object.is(c,l))continue;const u=An(s,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(c,l):t.validate(l));Object.is(u,c)||(i=!0)}for(const s of Object.keys(r))if(!io(o,s)){i=!0;break}return i?o:r}),this.keyValidator=n,this.valueValidator=t}}function E0(e){return new Sn(n=>{if(typeof n!==e)throw new Ce(`Expected ${e}, got ${Li(n)}`);return n})}const I4=new Sn(e=>e),pe=E0("string"),fe=E0("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}`)}),xf=fe.check(e=>{if(e<0)throw new Ce(`Expected a positive number, got ${e}`)}),Rn=fe.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive number, got ${e}`)}),g_=fe.check(e=>{if(!Number.isInteger(e))throw new Ce(`Expected an integer, got ${e}`)}),uh=g_.check(e=>{if(e<0)throw new Ce(`Expected a positive integer, got ${e}`)}),E4=g_.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive integer, got ${e}`)}),we=E0("boolean");function sn(e){return new Sn(n=>{if(n!==e)throw new Ce(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const l1=new Sn(e=>{if(!Array.isArray(e))throw new Ce(`Expected an array, got ${Li(e)}`);return e});function Nt(e){return new P4(e)}function ve(e){return new vf(e)}function aS(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===HN)}function cS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(cS):aS(e)?Object.values(e).every(cS):!1}const zt=new Sn(e=>{if(cS(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,zt.validate(n[r]);continue}const o=e[r],i=n[r];if(Object.is(o,i))continue;const s=zt.validateUsingKnownGoodVersion(o,i);Object.is(s,o)||(t=!0)}return t?n:e}else if(aS(e)&&aS(n)){let t=!1;for(const r of Object.keys(n)){if(!io(e,r)){t=!0,zt.validate(n[r]);continue}const o=e[r],i=n[r];if(Object.is(o,i))continue;const s=zt.validateUsingKnownGoodVersion(o,i);Object.is(s,o)||(t=!0)}for(const r of Object.keys(e))if(!io(n,r)){t=!0;break}return t?n:e}else return zt.validate(n)});function wf(e,n){return new C4(e,n)}function _0(e,n){return new Ep(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 _4(e,n){return new Ep(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 vo(e,n){return new Sn(t=>An(e,()=>n.validate(t)),(t,r)=>An(e,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(t,r):n.validate(r)))}function _p(e){return new Sn(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 m_(e){return new Sn(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 k4(e){return new Sn(n=>n===null?null:e.validate(n),(n,t)=>t===null?null:e.validateUsingKnownGoodVersion&&n!==null?e.validateUsingKnownGoodVersion(n,t):e.validate(t))}function k0(...e){return _p(new Set(e))}function y_(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 T4=new Set(["http:","https:","mailto:"]),nr=pe.check(e=>{if(e==="")return;const n=y_(e);if(!T4.has(n.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),$4=new Set(["http:","https:","data:"]),Is=pe.check(e=>{if(e==="")return;const n=y_(e);if(!$4.has(n.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),T0=pe.refine(e=>{try{return AN(e),e}catch{throw new Ce(`Expected an index key, got ${JSON.stringify(e)}`)}});function Qn(e){return pe.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const kp=Qn("asset");function $0(e,n){return ve({id:kp,typeName:sn("asset"),type:sn(e),props:n,meta:zt})}const Es=ve({x:fe,y:fe,z:fe.optional()}),Pl=ve({x:fe,y:fe,w:fe,h:fe}),S_=fe.check(e=>{if(e<0||e>1)throw new Ce("Opacity must be between 0 and 1")}),M4=pe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),pr=Qn("shape");function A4(e,n,t){return ve({id:pr,typeName:sn("shape"),x:fe,y:fe,rotation:fe,index:T0,parentId:M4,type:sn(e),isLocked:we,opacity:S_,props:n?ve(n):zt,meta:t?ve(t):zt})}const j4=Qn("binding");function O4(e,n,t){return ve({id:j4,typeName:sn("binding"),type:sn(e),fromId:pr,toId:pr,props:n?ve(n):zt,meta:t?ve(t):zt})}Fn("com.tldraw.binding",{});sr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function ws(e){return`binding:${ku()}`}function D4(e){return So("binding",{scope:"document",validator:vo("binding",_0("type",_u(e,(n,{props:t,meta:r})=>O4(n,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class Gt{constructor(n,t,r){this.id=n,this.defaultValue=t,this.type=r}static define(n,t){const{defaultValue:r,type:o=I4}=t;return new Gt(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new R4(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 R4 extends Gt{constructor(n,t,r){super(n,t,k0(...r)),this.values=r}}const cd=Fn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),L4=sr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:cd.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:cd.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:cd.AddMeta,up:e=>{e.meta={}}},{id:cd.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function wa(e){return e?e.typeName==="shape":!1}function gr(e){return e?e.startsWith("shape:"):!1}function Be(e){return`shape:${e??ku()}`}function v_(e){const n=new Map;for(const[t,r]of Object.entries(e))if(r instanceof Gt){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 xo(e,n){return _u(n,(t,r)=>`com.tldraw.shape.${e}/${r}`)}function F4(e){return So("shape",{scope:"document",validator:vo("shape",_0("type",_u(e,(n,{props:t,meta:r})=>A4(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function u1(e,n){const t=[];for(const[r,{migrations:o}]of Object.entries(n)){const i=`com.tldraw.${e}.${r}`;o?"sequenceId"in o?(it(i===o.sequenceId,`sequenceId mismatch for ${r} ${Cp} migrations. Expected '${i}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o?t.push(Ba({sequenceId:i,retroactive:!1,sequence:o.sequence.map(s=>"id"in s?x_(e,r,s):s)})):t.push(Ba({sequenceId:i,retroactive:!1,sequence:Object.keys(o.migrators).map(s=>Number(s)).sort((s,a)=>s-a).map(s=>({id:`${i}/${s}`,scope:"record",filter:a=>a.typeName===e&&a.type===r,up:a=>{const c=o.migrators[s].up(a);if(c)return c},down:a=>{const c=o.migrators[s].down(a);if(c)return c}}))})):t.push(Ba({sequenceId:i,retroactive:!1,sequence:[]}))}return t}function x_(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 w_=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],bf={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 ei(e){return e.isDarkMode?bf.darkMode:bf.lightMode}const rr=Gt.defineEnum("tldraw:color",{defaultValue:"black",values:w_}),b_=Gt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:w_}),_s=Gt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),nc=Gt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern"]}),ho=Gt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),P_={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},fo=Gt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),C_=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Pf=Gt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:C_}),Cf=Gt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:C_}),I_={labelColor:b_,color:rr,fill:nc,dash:_s,size:fo,arrowheadStart:Pf,arrowheadEnd:Cf,font:ho,start:Es,end:Es,bend:fe,text:pe,labelPosition:fe},fl=xo("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4});function rm(e){return x_("shape","arrow",e)}const E_=Ba({sequenceId:"com.tldraw.shape.arrow",sequence:[rm({id:fl.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),rm({id:fl.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)}}),rm({id:fl.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:fl.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 i=ws(),s={typeName:"binding",id:i,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};e[i]=s,t.props.start={x:0,y:0}}else delete t.props.start.type;if(o.type==="binding"){const i=ws(),s={typeName:"binding",id:i,type:"arrow",fromId:t.id,toId:o.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:o.normalizedAnchor,isExact:o.isExact,isPrecise:o.isPrecise}};e[i]=s,t.props.end={x:0,y:0}}else delete t.props.end.type}}}]}),__={terminal:k0("start","end"),normalizedAnchor:Es,isExact:we,isPrecise:we},k_={sequence:[{dependsOn:[fl.ExtractBindings]}]},N4=vo("camera",ve({typeName:sn("camera"),id:Qn("camera"),x:fe,y:fe,z:fe,meta:zt})),z4=Fn("com.tldraw.camera",{AddMeta:1}),B4=sr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:z4.AddMeta,up:e=>{e.meta={}}}]}),no=So("camera",{validator:N4,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),U4=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"]),T_=_p(U4),H4=ve({type:T_,rotation:fe}),K4=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),W4=_p(K4),G4=new Set(["starting","paused","active","stopping"]),$_=ve({id:pe,points:Nt(Es),size:xf,color:W4,opacity:fe,state:_p(G4),delay:fe,shrink:fe,taper:we}),zl=Qn("page"),V4=vo("page",ve({typeName:sn("page"),id:zl,name:pe,index:T0,meta:zt})),Y4=Fn("com.tldraw.page",{AddMeta:1}),X4=sr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:Y4.AddMeta,up:e=>{e.meta={}}}]}),Ko=So("page",{validator:V4,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function bn(e){return Ko.isId(e)}const q4={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1},M_=e=>e?wl(e,n=>q4[n]):null;Qn("instance");function Z4(e){const n={};for(const[r,o]of e)n[r]=m_(o);const t=vo("instance",ve({typeName:sn("instance"),id:Qn("instance"),currentPageId:zl,followingUserId:pe.nullable(),brush:Pl.nullable(),opacityForNextShape:S_,stylesForNextShape:ve(n),cursor:H4,scribbles:Nt($_),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:Pl,insets:Nt(we),zoomBrush:Pl.nullable(),isPenMode:we,isGridMode:we,chatMessage:pe,isChatting:we,highlightedUserIds:Nt(pe),isFocused:we,devicePixelRatio:fe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Nt(pe),isChangingStyle:we,isReadonly:we,meta:zt,duplicateProps:ve({shapeIds:Nt(Qn("shape")),offset:ve({x:fe,y:fe})}).nullable()}));return So("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}),Q4=sr({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})}]}),fn="instance:instance",J4=vo("instance_page_state",ve({typeName:sn("instance_page_state"),id:Qn("instance_page_state"),pageId:zl,selectedShapeIds:Nt(pr),hintingShapeIds:Nt(pr),erasingShapeIds:Nt(pr),hoveredShapeId:pr.nullable(),editingShapeId:pr.nullable(),croppingShapeId:pr.nullable(),focusedGroupId:pr.nullable(),meta:zt})),Kc=Fn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),ez=sr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Kc.AddCroppingId,up(e){e.croppingShapeId=null}},{id:Kc.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:Kc.AddMeta,up:e=>{e.meta={}}},{id:Kc.RenameProperties,up:e=>{},down:e=>{}},{id:Kc.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}}]}),Rr=So("instance_page_state",{validator:J4,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:{}})),tz=vo("pointer",ve({typeName:sn("pointer"),id:Qn("pointer"),x:fe,y:fe,lastActivityTimestamp:fe,meta:zt})),nz=Fn("com.tldraw.pointer",{AddMeta:1}),rz=sr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:nz.AddMeta,up:e=>{e.meta={}}}]}),M0=So("pointer",{validator:tz,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),If=M0.createId("pointer"),oz=vo("instance_presence",ve({typeName:sn("instance_presence"),id:Qn("instance_presence"),userId:pe,userName:pe,lastActivityTimestamp:fe,followingUserId:pe.nullable(),cursor:ve({x:fe,y:fe,type:T_,rotation:fe}),color:pe,camera:ve({x:fe,y:fe,z:fe}),screenBounds:Pl,selectedShapeIds:Nt(Qn("shape")),currentPageId:Qn("page"),brush:Pl.nullable(),scribbles:Nt($_),chatMessage:pe,meta:zt})),Wc=Fn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),iz=sr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Wc.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:Wc.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:Wc.AddChatMessage,up:e=>{e.chatMessage=""}},{id:Wc.AddMeta,up:e=>{e.meta={}}},{id:Wc.RenameSelectedShapeIds,up:e=>{}}]}),sz=So("instance_presence",{validator:oz,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:{}})),az=vo("document",ve({typeName:sn("document"),id:sn("document:document"),gridSize:fe,name:pe,meta:zt})),d1=Fn("com.tldraw.document",{AddName:1,AddMeta:2}),cz=sr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:d1.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:d1.AddMeta,up:e=>{e.meta={}}}]}),A0=So("document",{validator:az,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),lS=A0.createId("document");function lz(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function h1(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const uz=({error:e,phase:n,record:t,recordBefore:r})=>{throw g0(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?h1(vt(r)):void 0,recordAfter:h1(vt(t))}}),e};function dz(){return[Ko.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function hz(e){const n=e.query.ids("page"),t=()=>{if(!e.has(lS))return e.put([A0.create({id:lS,name:e.props.defaultName})]),t();if(!e.has(If))return e.put([M0.create({id:If})]),t();const r=n.get();if(r.size===0)return e.put(dz()),t();const o=()=>[...r].map(c=>e.get(c)).sort(lz)[0].id,i=e.get(fn);if(i){if(!r.has(i.currentPageId))return e.put([{...i,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:fn,currentPageId:o(),exportBackground:!0})]),t();const s=new Set,a=new Set;for(const c of r){const l=Rr.createId(c);e.has(l)||s.add(l);const u=no.createId(c);e.has(u)||a.add(u)}s.size>0&&e.put([...s].map(c=>Rr.create({id:c,pageId:Rr.parseId(c)}))),a.size>0&&e.put([...a].map(c=>no.create({id:c})))};return t}const fz=$0("bookmark",ve({title:pe,description:pe,image:pe,favicon:pe,src:Is.nullable()})),f1=Fn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),pz=sr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:f1.MakeUrlsValid,up:e=>{Is.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:f1.AddFavicon,up:e=>{Is.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),gz=$0("image",ve({w:fe,h:fe,name:pe,isAnimated:we,mimeType:pe.nullable(),src:Is.nullable()})),om=Fn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3}),mz=sr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:om.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:om.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:om.MakeUrlsValid,up:e=>{Is.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),yz=$0("video",ve({w:fe,h:fe,name:pe,isAnimated:we,mimeType:pe.nullable(),src:Is.nullable()})),im=Fn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3}),Sz=sr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:im.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:im.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:im.MakeUrlsValid,up:e=>{Is.isValid(e.props.src)||(e.props.src="")},down:e=>{}}]}),vz=vo("asset",_0("type",{image:gz,video:yz,bookmark:fz})),xz=Fn("com.tldraw.asset",{AddMeta:1}),wz=sr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:xz.AddMeta,up:e=>{e.meta={}}}]}),fs=So("asset",{validator:vz,scope:"document"}).withDefaultProperties(()=>({meta:{}})),A_={w:Rn,h:Rn,assetId:kp.nullable(),url:nr},p1=xo("bookmark",{NullAssetId:1,MakeUrlsValid:2}),j_={sequence:[{id:p1.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:"retired"},{id:p1.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},O_=ve({type:k0("free","straight"),points:Nt(Es)}),D_={color:rr,fill:nc,dash:_s,size:fo,segments:Nt(O_),isComplete:we,isClosed:we,isPen:we},bz=xo("draw",{AddInPen:1}),R_={sequence:[{id:bz.AddInPen,up:e=>{const{points:n}=e.segments[0];if(n.length===0){e.isPen=!1;return}let t=!(n[0].z===0||n[0].z===.5);n[1]&&(t=t&&!(n[1].z===0||n[1].z===.5)),e.isPen=t},down:"retired"}]};var Pz={};const g1=/(^\/r\/[^/]+\/?$)/,Oe=e=>{try{return new URL(e)}catch{return}},Tu=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(g1))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(g1))return e}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!e.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${e}`},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/?$/)){const t=n.searchParams.get("url");if(t)return t}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:e=>{if(e.includes("/maps/")){const n=e.match(/@(.*),(.*),(.*)z/);let t;if(n){const[,r,o,i]=n;t=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${Pz.NEXT_PUBLIC_GC_API_KEY}&center=${r},${o}&zoom=${i}`}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,i]=n.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${i},${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,i]=t;return`https://codepen.io/${o}/embed/${i}`}},fromEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o,i]=t;return`https://codepen.io/${o}/pen/${i}`}}},{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","")}}],Cz={"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},L_={w:Rn,h:Rn,url:pe},ld=xo("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),F_={sequence:[{id:ld.GenOriginalUrlInEmbed,up:e=>{try{const n=e.url,t=new URL(n).host.replace("www.","");let r;for(const o of Tu)if(o.hostnames.includes(t))try{r=o.fromEmbedUrl(n)}catch(i){console.warn(i)}e.tmpOldUrl=e.url,e.url=r??""}catch{e.url="",e.tmpOldUrl=e.url}},down:"retired"},{id:ld.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:ld.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:ld.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},N_={w:Rn,h:Rn,name:pe},z_={sequence:[]},Ef=Gt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),_f=Gt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),so=Gt.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"]}),B_={geo:so,labelColor:b_,color:rr,fill:nc,dash:_s,size:fo,font:ho,align:Ef,verticalAlign:_f,url:nr,w:Rn,h:Rn,growY:xf,text:pe},ui=xo("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8}),U_={sequence:[{id:ui.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:ui.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:ui.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:ui.AddCheckBox,up:e=>{},down:"retired"},{id:ui.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:ui.MigrateLegacyAlign,up:e=>{let n;switch(e.align){case"start":n="start-legacy";break;case"end":n="end-legacy";break;default:n="middle-legacy";break}e.align=n},down:"retired"},{id:ui.AddCloud,up:e=>{},down:"retired"},{id:ui.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},H_={},K_={sequence:[]},W_={color:rr,size:fo,segments:Nt(O_),isComplete:we,isPen:we},G_={sequence:[]},Iz=ve({topLeft:Es,bottomRight:Es}),V_={w:Rn,h:Rn,playing:we,url:nr,assetId:kp.nullable(),crop:Iz.nullable()},sm=xo("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3}),Y_={sequence:[{id:sm.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:sm.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:sm.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},kf=Gt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),Ez=ve({id:pe,index:T0,x:fe,y:fe}),X_={color:rr,dash:_s,size:fo,spline:kf,points:wf(pe,Ez)},ud=xo("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4}),q_={sequence:[{id:ud.AddSnapHandles,up:e=>{for(const n of Object.values(e.handles))n.canSnap=!0},down:"retired"},{id:ud.RemoveExtraHandleProps,up:e=>{e.handles=YE(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(en);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:ud.HandlesToPoints,up:e=>{const n=Object.entries(e.handles).map(([t,{x:r,y:o}])=>({x:r,y:o,index:t})).sort(en);e.points=n.map(({x:t,y:r})=>({x:t,y:r})),delete e.handles},down:e=>{const n=Nl(e.points.length);e.handles=Object.fromEntries(e.points.map((t,r)=>[n[r],{x:t.x,y:t.y}])),delete e.points}},{id:ud.PointIndexIds,up:e=>{const n=Nl(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(en);e.points=n.map(({x:t,y:r})=>({x:t,y:r}))}}]},Z_={color:rr,size:fo,font:ho,fontSizeAdjustment:xf,align:Ef,verticalAlign:_f,growY:xf,url:nr,text:pe},ra=xo("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6}),Q_={sequence:[{id:ra.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:ra.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{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:"retired"},{id:ra.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:ra.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}},{id:ra.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}}]},uS=Gt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),J_={color:rr,size:fo,font:ho,textAlign:uS,w:Rn,text:pe,scale:Rn,autoSize:we},m1=xo("text",{RemoveJustify:1,AddTextAlign:2}),ek={sequence:[{id:m1.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:m1.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},tk={w:Rn,h:Rn,time:fe,playing:we,url:nr,assetId:kp.nullable()},y1=xo("video",{AddUrlProp:1,MakeUrlsValid:2}),nk={sequence:[{id:y1.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:y1.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},dd=Fn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),_z=Ba({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:dd.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[n,t]of Mn(e))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete e[n]}},{id:dd.AddInstancePresenceType,scope:"store",up(e){}},{id:dd.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[n,t]of Mn(e))t.typeName.match(/^(user|user_presence)$/)&&delete e[n]}},{id:dd.RemoveUserDocument,scope:"store",up:e=>{for(const[n,t]of Mn(e))t.typeName.match("user_document")&&delete e[n]}}]}),kz={arrow:{migrations:E_,props:I_},bookmark:{migrations:j_,props:A_},draw:{migrations:R_,props:D_},embed:{migrations:F_,props:L_},frame:{migrations:z_,props:N_},geo:{migrations:U_,props:B_},group:{migrations:K_,props:H_},highlight:{migrations:G_,props:W_},image:{migrations:Y_,props:V_},line:{migrations:q_,props:X_},note:{migrations:Q_,props:Z_},text:{migrations:ek,props:J_},video:{migrations:nk,props:tk}},Tz={arrow:{migrations:k_,props:__}};function $z({shapes:e=kz,bindings:n=Tz,migrations:t}={}){const r=new Map;for(const a of yt(e))for(const c of v_(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=F4(e),i=D4(n),s=Z4(r);return I0.create({asset:fs,binding:i,camera:no,document:A0,instance:s,instance_page_state:Rr,page:Ko,instance_presence:sz,pointer:M0,shape:o},{migrations:[_z,wz,B4,cz,Q4,ez,X4,iz,rz,L4,pz,mz,Sz,...u1("shape",e),...u1("binding",n),...t??[]],onValidationFailure:uz,createIntegrityChecker:hz})}const Bl=[{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 Mz(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return Az(e)}function Az(e){for(const n of e){const t=jz(n);if(t)return t}return"en"}const S1={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function jz(e){const n=Bl.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Bl.find(i=>i.locale===t);if(o)return o.locale}return t in S1?S1[t]:null}var rk={exports:{}};/*!
49
- Copyright (c) 2018 Jed Watson.
50
- Licensed under the MIT License (MIT), see
51
- http://jedwatson.github.io/classnames
52
- */(function(e){(function(){var n={}.hasOwnProperty;function t(){for(var i="",s=0;s<arguments.length;s++){var a=arguments[s];a&&(i=o(i,r(a)))}return i}function r(i){if(typeof i=="string"||typeof i=="number")return i;if(typeof i!="object")return"";if(Array.isArray(i))return t.apply(null,i);if(i.toString!==Object.prototype.toString&&!i.toString.toString().includes("[native code]"))return i.toString();var s="";for(var a in i)n.call(i,a)&&i[a]&&(s=o(s,a));return s}function o(i,s){return s?i?i+" "+s:i+s:i}e.exports?(t.default=t,e.exports=t):window.classNames=t})()})(rk);var Oz=rk.exports;const ue=Ki(Oz),Dz={error:null};class ok extends x.Component{constructor(){super(...arguments);g(this,"state",Dz)}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 Ul({children:e,fallback:n,...t}){return n===null?h.jsx(h.Fragment,{children:e}):h.jsx(ok,{fallback:n,...t,children:e})}const Tp=Se.createContext(null);function z(){const e=Se.useContext(Tp);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function Rz(){return h.jsx("div",{className:"tl-background"})}function Pc(e,n,t,r,o,i){x.useLayoutEffect(()=>{const s=e.current;if(!s||n===void 0)return;let a=`translate(${n}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),o!==void 0&&(a+=` rotate(${o}rad)`),i&&(a+=` translate(${i.x}px, ${i.y}px)`),s.style.transform=a})}const on={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),i=Math.cos(n);return this.x=t*i-r*o,this.y=t*o+r*i,this}rotWith(n,t){if(t===0)return this;const r=this.x-n.x,o=this.y-n.y,i=Math.sin(t),s=Math.cos(t);return this.x=n.x+(r*s-o*i),this.y=n.y+(r*i+o*s),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,i=n.y-t.y,s=Math.sin(r),a=Math.cos(r);return new b(t.x+(o*a-i*s),t.y+(o*s+i*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 i=b.Tan(t,n),s=b.Add(n,b.Mul(i,b.Sub(r,n).pry(i)));if(o){if(s.x<Math.min(n.x,t.x))return b.Cast(n.x<t.x?n:t);if(s.x>Math.max(n.x,t.x))return b.Cast(n.x>t.x?n:t);if(s.y<Math.min(n.y,t.y))return b.Cast(n.y<t.y?n:t);if(s.y>Math.max(n.y,t.y))return b.Cast(n.y>t.y?n:t)}return s}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(rc(n.x),rc(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 i=0;i<r;i++){const s=on.easeInQuad(i/(r-1)),a=b.Lrp(n,t,s);a.z=Math.min(1,.5+Math.abs(.5-Lz(s))*.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 Lz=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ee(e){return`${F(e.x)},${F(e.y)} `}function Cn(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,Fz=Math.sin;function Tt(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function hd(e,n=1e10){return e?Math.round(e*n)/n:0}function Ua(e,n,t=1e-6){return Math.abs(e-n)<=t}function ik(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 _i(e){return e=e%Re,e<0?e=e+Re:e===0&&(e=0),e}function $u(e,n){return e=_i(e),n=_i(n),e>n&&(n+=Re),n-e}function sk(e,n){return Re-$u(e,n)}function dh(e,n){const t=(n-e)%Re;return 2*t%Re-t}function dS(e){return(Re+e)%Re}function Tf(e,n){const t=Re/n;let r=Math.floor((dS(e)+t/2)/t)*t%Re;return r<ke&&(r+=Re),r>ke&&(r-=Re),r}function ak(e,n){return e===n||Ua(e%(Math.PI/2)-n%(Math.PI/2),0)}function Nz(e){return e*ke/180}function zz(e){return e*180/ke}function ks(e,n,t){return new b(e.x,e.y).add(b.FromAngle(t,n))}function am(e,n,t){const r=e/2,o=n/2,i=[];let s=1/0,a=-1/0,c=1/0,l=-1/0;for(let S=0;S<t;S++){const m=Re/t,w=-Ve+S*m,y=r+r*Math.cos(w),v=o+o*Math.sin(w);y<s&&(s=y),v<c&&(c=v),y>a&&(a=y),v>l&&(l=v),i.push(new b(y,v))}const u=a-s,d=l-c,f=e-u,p=n-d;if(f!==0||p!==0)for(let S=0;S<i.length;S++){const m=i[S];m.x=(m.x-s)/u*e,m.y=(m.y-c)/d*n}return i}function Gc(e,n,t,r){return e<r&&t<n}function Mr(e,n,t,r){const o=Math.max(e,t),i=Math.min(n,r);return o<=i?[o,i]:null}function v1(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function Jn(e,n){let t=0,r,o;for(let i=0;i<n.length;i++){if(r=n[i],r.x===e.x&&r.y===e.y||(o=n[(i+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&&v1(r,o,e)>0&&(t+=1):o.y<=e.y&&v1(r,o,e)<0&&(t-=1)}return t!==0}function F(e){return Math.round(e*1e4)/1e4}function rc(e){return Math.round(e*100)/100}const x1=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function Si(e,n,t){return t<0?$u(e,n):sk(e,n)}function hS(e,n,t,r){let o;if(Math.abs(e)>ke){o=dh(n,r);const i=dh(r,t);return Math.abs(o)<Math.abs(i)?o/e:(e-i)/e}else{o=dh(n,r);const i=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(i)>.5?1:0:i}}function Bz(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 j0(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 Uz(e,n,t,r,o){if(t===null)return[b.From(e),b.From(n)];const i=[],s=b.Angle(t,e),a=b.Angle(t,n),c=$u(s,a);for(let l=0;l<o;l++){const u=l/(o-1),d=s+c*u,f=ks(t,r,d);i.push(f)}return i}const cm=({brush:e,color:n,opacity:t,className:r})=>{const o=x.useRef(null);Pc(o,e.x,e.y);const i=F(Math.max(1,e.w)),s=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:i,height:s,fill:n,opacity:.75}),h.jsx("rect",{width:i,height:s,fill:"none",stroke:n,opacity:.1})]}):h.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:i,height:s})})},w1={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},lm={duration:0,easing:on.easeInOutCubic},b1={CAMERA_MOVE:-10},Hz=["top","right","bottom","left"],P1=0,O0=2,fd=1,C1=5,Kz=128;var um={};const Wz={},ck=wn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),bt={logPreventDefaults:wn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:wn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:wn("logElementRemoves",{defaults:{all:!1}}),debugSvg:wn("debugSvg",{defaults:{all:!1}}),showFps:wn("showFps",{defaults:{all:!1}}),measurePerformance:wn("measurePerformance",{defaults:{all:!1}}),throwToBlob:wn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:wn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:wn("debugCursors",{defaults:{all:!1}}),forceSrgb:wn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:wn("debugGeometry",{defaults:{all:!1}}),hideShapes:wn("hideShapes",{defaults:{all:!1}}),editOnType:wn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;Gs("element removal logging",()=>{bt.logElementRemoves.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function wn(e,{defaults:n,shouldStoreForSession:t=!0}){return Gz({name:e,defaults:n,shouldStoreForSession:t})}function Gz(e){const n=Yz(e),t=e.shouldStoreForSession?Vz(e.name):null,r=rn(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&Gs(`debug:${e.name}`,()=>{const o=r.get();o===n?t_(`tldraw_debug:${e.name}`):v0(`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 Vz(e){try{return JSON.parse(e_(`tldraw_debug:${e}`)??"null")}catch{return null}}function dm(e){try{return e()}catch{return null}}function Yz(e){switch(dm(()=>um.TLDRAW_ENV)??dm(()=>um.VERCEL_PUBLIC_TLDRAW_ENV)??dm(()=>um.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return e.defaults.production??e.defaults.all;case"preview":case"staging":return e.defaults.staging??e.defaults.all;default:return e.defaults.development??e.defaults.all}}function $f(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return $f(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function _e(e){e.preventDefault(),bt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Mu(e,n){if(e.setPointerCapture(n.pointerId),bt.logPointerCaptures.get()){const t=ck.get();t.set(e,(t.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,n)}}function Au(e,n){if(e.hasPointerCapture(n.pointerId)&&(e.releasePointerCapture(n.pointerId),bt.logPointerCaptures.get())){const t=ck.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 Ut=e=>e.stopPropagation(),qt=(e,n,t)=>{e&&e.style.setProperty(n,t)};function kn(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 Xz(){const e=z();return x.useMemo(function(){let r,o;function i(m){if(!m.isKilled){if(m.button===O0){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...kn(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(Mu(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...kn(m)}))}}function s(m){m.isKilled||m.clientX===r&&m.clientY===o||(r=m.clientX,o=m.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...kn(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,Au(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...kn(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 y,v;if(_e(m),!((v=(y=m.dataTransfer)==null?void 0:y.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 S(m){Ut(m)}return{onPointerDown:i,onPointerMove:s,onPointerUp:a,onPointerEnter:c,onPointerLeave:l,onDragOver:f,onDrop:p,onTouchStart:u,onTouchEnd:d,onClick:S}},[e])}function qz(){const e=z();x.useEffect(()=>{let n=e.getInstanceState().isCoarsePointer;const t=s=>{const a=s.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,i=()=>{const s=o?!1:r.matches;n===s&&(n=s,e.updateInstanceState({isCoarsePointer:s}))};return r&&(r.addEventListener("change",i),i()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",i)}},[e])}const lk=x.createContext(null);function Zz({container:e,children:n}){return h.jsx(lk.Provider,{value:e,children:n})}function ln(){return Gn(x.useContext(lk),"useContainer used outside of <Tldraw />")}function Qz(){const e=z(),n=ln(),t=G("isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const i=`(resolution: ${window.devicePixelRatio}dppx)`,s=matchMedia(i),a=c=>{c.type==="change"&&o()};s.addEventListener?s.addEventListener("change",o):s.addListener&&s.addListener(a),r=()=>{s.removeEventListener?s.removeEventListener("change",o):s.removeListener&&s.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"))&&!pd()&&_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(pd()||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(pd()||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,pd()||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 i(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 s=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&_e(a)};return n.addEventListener("touchstart",i,{passive:!1}),n.addEventListener("wheel",s,{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",i),n.removeEventListener("wheel",s),document.removeEventListener("gesturestart",_e),document.removeEventListener("gesturechange",_e),document.removeEventListener("gestureend",_e),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const Jz=["input","select","button","textarea"];function pd(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||Jz.indexOf(e.tagName.toLowerCase())>-1))}const e8=["textarea","input"];function t8(e){const n=z();x.useEffect(()=>{const t=e.current;if(!t)return;const r=o=>{var i;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:s}=o;if(e8.includes((i=s.tagName)==null?void 0:i.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 n8(e,n,t){return Math.max(n,Math.min(e,t))}const Bt={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 I1(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function E1(e,n,t,r=.15){return r===0?n8(e,n,t):e<n?-I1(n-e,t-n,r)+n:e>t?+I1(e-t,t-n,r)+t:e}function r8(e,[n,t],[r,o]){const[[i,s],[a,c]]=e;return[E1(n,i,s,r),E1(t,a,c,o)]}function o8(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 i8(e){var n=o8(e,"string");return typeof n=="symbol"?n:String(n)}function Zt(e,n,t){return n=i8(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function _1(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),t.push.apply(t,r)}return t}function ut(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?_1(Object(t),!0).forEach(function(r){Zt(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):_1(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const uk={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 k1(e){return e?e[0].toUpperCase()+e.slice(1):""}const s8=["enter","leave"];function a8(e=!1,n){return e&&!s8.includes(n)}function c8(e,n="",t=!1){const r=uk[e],o=r&&r[n]||n;return"on"+k1(e)+k1(o)+(a8(t,o)?"Capture":"")}const l8=["gotpointercapture","lostpointercapture"];function u8(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=l8.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function d8(e,n=""){const t=uk[e],r=t&&t[n]||n;return e+r}function dk(e){return"touches"in e}function h8(e){return dk(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function f8(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 fS(e,n){try{const t=n.clientX-e.clientX,r=n.clientY-e.clientY,o=(n.clientX+e.clientX)/2,i=(n.clientY+e.clientY)/2,s=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:s,origin:[o,i]}}catch{}return null}function p8(e){return f8(e).map(n=>n.identifier)}function T1(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return fS(t,r)}const $1=40,M1=800;function hk(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=$1,t*=$1):r===2&&(n*=M1,t*=M1),[n,t]}function g8(e){const n={};if("buttons"in e&&(n.buttons=e.buttons),"shiftKey"in e){const{shiftKey:t,altKey:r,metaKey:o,ctrlKey:i}=e;Object.assign(n,{shiftKey:t,altKey:r,metaKey:o,ctrlKey:i})}return n}function Mf(e,...n){return typeof e=="function"?e(...n):e}function m8(){}function y8(...e){return e.length===0?m8:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function A1(e,n){return Object.assign({},n,e||{})}const S8=32;class fk{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?Mf(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 i=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,g8(n)),o.down=o.pressed=o.buttons%2===1||o.touches>0,i=n.timeStamp-t.timeStamp,t.timeStamp=n.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const I=t._delta.map(Math.abs);Bt.addTo(t._distance,I)}this.axisIntent&&this.axisIntent(n);const[s,a]=t._movement,[c,l]=r.threshold,{_step:u,values:d}=t;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(s)>=c&&d[0]),u[1]===!1&&(u[1]=Math.abs(a)>=l&&d[1])):(u[0]===!1&&(u[0]=Math.abs(s)>=c&&Math.sign(s)*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?s-u[0]:0,f[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(f);const p=t.offset,S=t._active&&!t._blocked||t.active;S&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=o[this.ingKey]=t._active,n&&(t.first&&("bounds"in r&&(t._bounds=Mf(r.bounds,t)),this.setup&&this.setup()),t.movement=f,this.computeOffset()));const[m,w]=t.offset,[[y,v],[P,E]]=t._bounds;t.overflow=[m<y?-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=r8(t._bounds,t.offset,C),t.delta=Bt.sub(t.offset,p),this.computeMovement(),S&&(!t.last||i>S8)){t.delta=Bt.sub(t.offset,p);const I=t.delta.map(Math.abs);Bt.addTo(t.distance,I),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&i>0&&(t.velocity=[I[0]/i,I[1]/i],t.timeDelta=i)}}emit(){const n=this.state,t=this.shared,r=this.config;if(n._active||this.clean(),(n._blocked||!n.intentional)&&!n._force&&!r.triggerAllEvents)return;const o=this.handler(ut(ut(ut({},t),n),{},{[this.aliasKey]:n.values}));o!==void 0&&(n.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function v8([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 x8 extends fk{constructor(...n){super(...n),Zt(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=Bt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Bt.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[h8(n)]:r.axisThreshold;t.axis=v8(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 w8=e=>e,j1=.15,pk={enabled(e=!0){return e},eventOptions(e,n,t){return ut(ut({},t.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[j1,j1];case!1:return[0,0];default:return Bt.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return Bt.toVector(e)},transform(e,n,t){const r=e||t.shared.transform;return this.hasCustomTransform=!!r,r||w8},threshold(e){return Bt.toVector(e,0)}},b8=0,ju=ut(ut({},pk),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=b8){return e},bounds(e={}){if(typeof e=="function")return i=>ju.bounds(e(i));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]]}}),Ou=typeof window<"u"&&window.document&&window.document.createElement;function gk(){return Ou&&"ontouchstart"in window}function P8(){return gk()||Ou&&window.navigator.maxTouchPoints>1}function C8(){return Ou&&"onpointerdown"in window}function I8(){return Ou&&"exitPointerLock"in window.document}function E8(){try{return"constructor"in GestureEvent}catch{return!1}}const mr={isBrowser:Ou,gesture:E8(),touch:gk(),touchscreen:P8(),pointer:C8(),pointerLock:I8()},_8=250,k8=180,T8=.5,$8=50,M8=250,A8=10,O1={mouse:0,touch:0,pen:8};ut(ut({},ju),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&mr.pointerLock,mr.touch&&t?"touch":this.pointerLock?"mouse":mr.pointer&&!o?"pointer":mr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?_8:void 0,!(!mr.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 i=Bt.toVector(e,t?r:o?1:0);return this.filterTaps=t,this.tapsThreshold=r,i},swipe({velocity:e=T8,distance:n=$8,duration:t=M8}={}){return{velocity:this.transform(Bt.toVector(e)),distance:this.transform(Bt.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return k8;case!1:return 0;default:return e}},axisThreshold(e){return e?ut(ut({},O1),e):O1},keyboardDisplacement(e=A8){return e}});function mk(e){const[n,t]=e.overflow,[r,o]=e._delta,[i,s]=e._direction;(n<0&&r>0&&i<0||n>0&&r<0&&i>0)&&(e._movement[0]=e._movementBound[0]),(t<0&&o>0&&s<0||t>0&&o<0&&s>0)&&(e._movement[1]=e._movementBound[1])}const j8=30,O8=100;class D8 extends fk{constructor(...n){super(...n),Zt(this,"ingKey","pinching"),Zt(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=Bt.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)*j8-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(i=>r.has(i))||r.size<2)return;this.start(n),t._touchIds=Array.from(r).slice(0,2);const o=T1(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(s=>o.has(s))||(r.size<2&&r.set(n.pointerId,n),t._pointerEvents.size<2))return;this.start(n);const i=fS(...Array.from(r.values()));i&&this.pinchStart(n,i)}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=T1(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=fS(...Array.from(t.values()));r&&this.pinchMove(n,r)}pinchMove(n,t){const r=this.state,o=r._values[1],i=t.angle-o;let s=0;Math.abs(i)>270&&(s+=Math.sign(i)),this.computeValues([t.distance,t.angle-360*s]),r.origin=t.origin,r.turns=s,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=Bt.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=[-hk(n)[1]/O8*r.offset[0],0],Bt.addTo(r._movement,r._delta),mk(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 R8=ut(ut({},pk),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!mr.touch&&mr.gesture)return"gesture";if(mr.touch&&r)return"touch";if(mr.touchscreen){if(mr.pointer)return"pointer";if(mr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=s=>{const a=A1(Mf(t,s),{min:-1/0,max:1/0});return[a.min,a.max]},i=s=>{const a=A1(Mf(r,s),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[o(),i()]:s=>[o(s),i(s)]},threshold(e,n,t){return this.lockDirection=t.axis==="lock",Bt.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});ut(ut({},ju),{},{mouseOnly:(e=!0)=>e});class L8 extends x8{constructor(...n){super(...n),Zt(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=hk(n),Bt.addTo(t._movement,t._delta),mk(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 F8=ju;ut(ut({},ju),{},{mouseOnly:(e=!0)=>e});const D0=new Map,pS=new Map;function N8(e){D0.set(e.key,e.engine),pS.set(e.key,e.resolver)}const z8={key:"pinch",engine:D8,resolver:R8},B8={key:"wheel",engine:L8,resolver:F8};function U8(e,n){if(e==null)return{};var t={},r=Object.keys(e),o,i;for(i=0;i<r.length;i++)o=r[i],!(n.indexOf(o)>=0)&&(t[o]=e[o]);return t}function H8(e,n){if(e==null)return{};var t=U8(e,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r])}return t}const K8={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=mr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},W8=["target","eventOptions","window","enabled","transform"];function hh(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]=hh(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function G8(e,n,t={}){const r=e,{target:o,eventOptions:i,window:s,enabled:a,transform:c}=r,l=H8(r,W8);if(t.shared=hh({target:o,eventOptions:i,window:s,enabled:a,transform:c},K8),n){const u=pS.get(n);t[n]=hh(ut({shared:t.shared},l),u)}else for(const u in l){const d=pS.get(u);d&&(t[u]=hh(ut({shared:t.shared},l[u]),d))}return t}class yk{constructor(n,t){Zt(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,i){const s=this._listeners,a=d8(t,r),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},l=ut(ut({},c),i);n.addEventListener(a,o,l);const u=()=>{n.removeEventListener(a,o,l),s.delete(u)};return s.add(u),u}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class V8{constructor(){Zt(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 Y8{constructor(n){Zt(this,"gestures",new Set),Zt(this,"_targetEventStore",new yk(this)),Zt(this,"gestureEventStores",{}),Zt(this,"gestureTimeoutStores",{}),Zt(this,"handlers",{}),Zt(this,"config",{}),Zt(this,"pointerIds",new Set),Zt(this,"touchIds",new Set),Zt(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),X8(this,n)}setEventIds(n){if(dk(n))return this.touchIds=new Set(p8(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=G8(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 s of this.gestures){const a=this.config[s],c=D1(r,a.eventOptions,!!o);if(a.enabled){const l=D0.get(s);new l(this,n,s).bind(c)}}const i=D1(r,t.eventOptions,!!o);for(const s in this.nativeHandlers)i(s,"",a=>this.nativeHandlers[s](ut(ut({},this.state.shared),{},{event:a,args:n})),void 0,!0)}for(const i in r)r[i]=y8(...r[i]);if(!o)return r;for(const i in r){const{device:s,capture:a,passive:c}=u8(i);this._targetEventStore.add(o,s,"",r[i],{capture:a,passive:c})}}}}function oa(e,n){e.gestures.add(n),e.gestureEventStores[n]=new yk(e,n),e.gestureTimeoutStores[n]=new V8}function X8(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 D1=(e,n,t)=>(r,o,i,s={},a=!1)=>{var c,l;const u=(c=s.capture)!==null&&c!==void 0?c:n.capture,d=(l=s.passive)!==null&&l!==void 0?l:n.passive;let f=a?r:c8(r,o,u);t&&d&&(f+="Passive"),e[f]=e[f]||[],e[f].push(i)},q8=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Z8(e){const n={},t={},r=new Set;for(let o in e)q8.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function ia(e,n,t,r,o,i){if(!e.has(t)||!D0.has(r))return;const s=t+"Start",a=t+"End",c=l=>{let u;return l.first&&s in n&&n[s](l),t in n&&(u=n[t](l)),l.last&&a in n&&n[a](l),u};o[r]=c,i[r]=i[r]||{}}function Q8(e,n){const[t,r,o]=Z8(e),i={};return ia(o,t,"onDrag","drag",i,n),ia(o,t,"onWheel","wheel",i,n),ia(o,t,"onScroll","scroll",i,n),ia(o,t,"onPinch","pinch",i,n),ia(o,t,"onMove","move",i,n),ia(o,t,"onHover","hover",i,n),{handlers:i,config:n,nativeHandlers:r}}function J8(e,n={},t,r){const o=Se.useMemo(()=>new Y8(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 e7(e){return e.forEach(N8),function(t,r){const{handlers:o,nativeHandlers:i,config:s}=Q8(t,r||{});return J8(o,s,void 0,i)}}const R1=10,t7=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function Sk(e){let{deltaY:n,deltaX:t}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(n)>R1?R1*Math.sign(n):n)/100:e.shiftKey&&!t7&&(t=n,n=0),{x:-t,y:-n,z:-r}}const n7=e7([B8,z8]);let sa;const r7=e=>sa===void 0?(sa=e,!1):e-sa>120&&e-sa<160?(sa=e,!0):(sa=e,!1);function o7(e){const n=z(),t=x.useMemo(()=>{let r="not sure";const o=({event:m})=>{if(!n.getInstanceState().isFocused||(r="not sure",r7(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),Ut(m);const y=Sk(m);if(y.x===0&&y.y===0)return;const v={type:"wheel",name:"wheel",delta:y,point:new b(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey};n.dispatch(v)};let i=1,s=1,a=1,c=0;const l=new b,u=new b,d=m=>{const w=e.current;r="not sure";const{event:y,origin:v,da:P}=m;y instanceof WheelEvent||(y.target===w||w!=null&&w.contains(y.target))&&(u.x=v[0],u.y=v[1],l.x=v[0],l.y=v[1],i=P[0],s=n.getZoomLevel(),n.dispatch({type:"pinch",name:"pinch_start",point:{x:v[0],y:v[1],z:n.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey}))},f=m=>{if(m&&(r="zooming"),r==="zooming")return;const w=Math.abs(c-i),y=b.Dist(l,u);switch(r){case"not sure":{w>24?r="zooming":y>16&&(r="panning");break}case"panning":{w>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:d,onPinchEnd:m=>{const w=e.current,{event:y,origin:v,offset:P}=m;if(y instanceof WheelEvent||!(y.target===w||w!=null&&w.contains(y.target)))return;const E=P[0];r="not sure",n.timers.requestAnimationFrame(()=>{n.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:E},delta:{x:v[0],y:v[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey})})},onPinch:m=>{const w=e.current,{event:y,origin:v,offset:P,da:E}=m;if(y instanceof WheelEvent||!(y.target===w||w!=null&&w.contains(y.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:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:s},delta:{x:I,y:_},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}}}}},[n,e]);n7(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function hm(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(i=>i.id===t)}}function i7(e,n){const t=z();return x.useMemo(()=>{const r=c=>{if(c.isKilled)return;const l=$f(c.currentTarget);Mu(l,c);const{shape:u,handle:d}=hm(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_down",...kn(c)})};let o,i;return{onPointerDown:r,onPointerMove:c=>{if(c.isKilled||c.clientX===o&&c.clientY===i)return;o=c.clientX,i=c.clientY;const{shape:l,handle:u}=hm(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:l,name:"pointer_move",...kn(c)})},onPointerUp:c=>{if(c.isKilled)return;const l=$f(c.currentTarget);Au(l,c);const{shape:u,handle:d}=hm(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_up",...kn(c)})}}},[t,e,n])}var vk="Expected a function",L1=NaN,s7="[object Symbol]",a7=/^\s+|\s+$/g,c7=/^[-+]0x[0-9a-f]+$/i,l7=/^0b[01]+$/i,u7=/^0o[0-7]+$/i,d7=parseInt,h7=typeof tn=="object"&&tn&&tn.Object===Object&&tn,f7=typeof self=="object"&&self&&self.Object===Object&&self,p7=h7||f7||Function("return this")(),g7=Object.prototype,m7=g7.toString,y7=Math.max,S7=Math.min,fm=function(){return p7.Date.now()};function v7(e,n,t){var r,o,i,s,a,c,l=0,u=!1,d=!1,f=!0;if(typeof e!="function")throw new TypeError(vk);n=F1(n)||0,Af(t)&&(u=!!t.leading,d="maxWait"in t,i=d?y7(F1(t.maxWait)||0,n):i,f="trailing"in t?!!t.trailing:f);function p(I){var _=r,k=o;return r=o=void 0,l=I,s=e.apply(k,_),s}function S(I){return l=I,a=setTimeout(y,n),u?p(I):s}function m(I){var _=I-c,k=I-l,$=n-_;return d?S7($,i-k):$}function w(I){var _=I-c,k=I-l;return c===void 0||_>=n||_<0||d&&k>=i}function y(){var I=fm();if(w(I))return v(I);a=setTimeout(y,m(I))}function v(I){return a=void 0,f&&r?p(I):(r=o=void 0,s)}function P(){a!==void 0&&clearTimeout(a),l=0,r=c=o=a=void 0}function E(){return a===void 0?s:v(fm())}function C(){var I=fm(),_=w(I);if(r=arguments,o=this,c=I,_){if(a===void 0)return S(c);if(d)return a=setTimeout(y,n),p(c)}return a===void 0&&(a=setTimeout(y,n)),s}return C.cancel=P,C.flush=E,C}function x7(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(vk);return Af(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),v7(e,n,{leading:r,maxWait:n,trailing:o})}function Af(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function w7(e){return!!e&&typeof e=="object"}function b7(e){return typeof e=="symbol"||w7(e)&&m7.call(e)==s7}function F1(e){if(typeof e=="number")return e;if(b7(e))return L1;if(Af(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=Af(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(a7,"");var t=l7.test(e);return t||u7.test(e)?d7(e.slice(2),t?2:8):c7.test(e)?L1:+e}var P7=x7;const C7=Ki(P7),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=hd(this.x),this.y=hd(this.y),this.w=hd(this.w),this.h=hd(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),i=Math.max(this.maxY,n.maxY);return this.x=t,this.y=r,this.w=o-t,this.h=i-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,i=Math.round(this.maxY/n)*n;this.minX=t,this.minY=r,this.width=Math.max(1,o-t),this.height=Math.max(1,i-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:i,maxX:s,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)/(s-o),p=(d-l)/(a-i),S=f<0,m=p<0;if(S){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),i=Math.max(this.maxY,n.h+n.y);return this.x=t,this.y=r,this.width=o-t,this.height=i-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,i=-1/0,s;for(let a=0,c=n.length;a<c;a++)s=n[a],t=Math.min(s.x,t),r=Math.min(s.y,r),o=Math.max(s.x,o),i=Math.max(s.y,i);return new et(t,r,o-t,i-r)}static Expand(n,t){const r=Math.min(t.minX,n.minX),o=Math.min(t.minY,n.minY),i=Math.max(t.maxX,n.maxX),s=Math.max(t.maxY,n.maxY);return new et(r,o,i-r,s-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,i=!1){const{minX:s,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 S=(f-u)/(c-s),m=(p-d)/(l-a),w=S<0,y=m<0;if(i){const P=(c-s)/(l-a),E=Math.abs(f-u),C=Math.abs(p-d),I=E*(m<0?1:-1)*(1/P),_=C*(S<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(y){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*(S>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,i=-1/0;for(let s=0;s<n.length;s++){const a=n[s];t=Math.min(t,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),i=Math.max(i,a.maxY)}return new et(t,r,o-t,i-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 I7(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 E7(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 _7(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function k7(e){const n=z();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=C7(r,200,{trailing:!0}),i=n.timers.setInterval(o,1e3);window.addEventListener("resize",o);const s=new ResizeObserver(l=>{l[0].contentRect&&o()}),a=e.current;let c=null;return a&&(s.observe(a),c=T7(a),c.addEventListener("scroll",o)),()=>{clearInterval(i),window.removeEventListener("resize",o),s.disconnect(),c==null||c.removeEventListener("scroll",o)}},[n,e])}/*!
53
- * Author: excalidraw
54
- * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
55
- * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
56
- */const T7=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,i,s){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=i,this.f=s}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:i,d:s,e:a,f:c}=this;return this.a=r*t.a+i*t.b,this.c=r*t.c+i*t.d,this.e=r*t.e+i*t.f+a,this.b=o*t.a+s*t.b,this.d=o*t.c+s*t.d,this.f=o*t.e+s*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:i,f:s}=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*i-r*s)/-a,this.f=(t*i-n*s)/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),i=Math.sin(n),s=new De(o,i,-i,o,0,0);return t===void 0?s:De.Compose(De.Translate(t,r),s,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 dS(t)}static Decompose(n){let t,r,o;if(n.a!==0||n.c!==0){const i=(n.a*n.a+n.c*n.c)**.5;t=i,r=(n.a*n.d-n.b*n.c)/i,o=Math.acos(n.a/i)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const i=(n.b*n.b+n.d*n.d)**.5;t=(n.a*n.d-n.b*n.c)/i,r=i,o=Ve+Math.acos(n.b/i)*(n.d>0?-1:1)}else t=0,r=0,o=0;return{x:n.e,y:n.f,scaleX:t,scaleY:r,rotation:dS(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 i=new De(n,0,0,t,0,0);return r===void 0?i:De.Compose(De.Translate(r,o),i,De.Translate(-r,-o))});let ie=De;function xk(e,n){return n===0?e:xk(n,e%n)}function wk(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/xk(r,t)}class Yi{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)&&Jn(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)&&Jn(n,this.vertices)?-1:1)}distanceToLineSegment(n,t){if(n.equals(t))return this.distanceToPoint(n);const{vertices:r}=this;let o,i=1/0,s,a,c;for(let l=0;l<r.length;l++)a=r[l],c=b.NearestPointOnLineSegment(n,t,a,!0),s=b.Dist2(a,c),s<i&&(i=s,o=c);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Jn(o,this.vertices)?-i:i}hitTestLineSegment(n,t,r=0){return this.distanceToLineSegment(n,t)<=r}nearestPointOnLineSegment(n,t){const{vertices:r}=this;let o,i=1/0,s,a,c;for(let l=0;l<r.length;l++)a=r[l],c=b.NearestPointOnLineSegment(n,t,a,!0),s=b.Dist2(a,c),s<i&&(i=s,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 i=n[r],s=n[(r+1)%o];t+=i.x*s.y-s.x*i.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 i=1;i<n.length;i++)t=n[i],o+=b.Dist2(r,t),r=t;return Math.sqrt(o)}}class Br extends Yi{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:i}=this;if(i.length===0)throw Error("no children");let s,a;for(const c of i)s=c.nearestPoint(t),a=b.Dist2(s,t),a<r&&(r=a,o=s);if(!o)throw Error("nearest point not found");return o}distanceToPoint(t,r=!1){return Math.min(...this.children.map((o,i)=>o.distanceToPoint(t,r||i>0)))}hitTestPoint(t,r,o){return!!this.children.filter(i=>!i.isLabel).find(i=>i.hitTestPoint(t,r,o))}hitTestLineSegment(t,r,o){return!!this.children.filter(i=>!i.isLabel).find(i=>i.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,i=r.length;o<i;o++){const s=r[o],a=r[(o-1+i)%i],c=s.dist(a),l=r[(o+1)%i],u=s.dist(l),d=s.clone().lrp(a,4/c),f=s,p=s.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 $7(e=!0){const[n,t]=x.useState(0),r=z();x.useEffect(()=>{if(!e)return;const o=()=>t(i=>i+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const M7=ir(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=z();$7(r);const i=o.getZoomLevel(),s=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return h.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:s.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),S=u.distanceToPoint(f,!0),m=Math.abs(S)*i,w=S<0,{vertices:y}=u;return h.jsxs("g",{transform:d.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&h.jsx(bk,{geometry:u}),t&&y.map((v,P)=>h.jsx("circle",{cx:v.x,cy:v.y,r:"2",fill:`hsl(${hf(P,[0,y.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 bk({geometry:e}){return e instanceof Br?h.jsx(h.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>h.jsx(bk,{geometry:n},t))}):h.jsx("path",{stroke:e.debugColor??"red",strokeWidth:"2",fill:"none",opacity:"1",d:e.toSimpleSvgPath()})}var A7=200,R0="__lodash_hash_undefined__",j7=1/0,O7="[object Function]",D7="[object GeneratorFunction]",R7=/[\\^$.*+?()[\]{}|]/g,L7=/^\[object .+?Constructor\]$/,F7=typeof tn=="object"&&tn&&tn.Object===Object&&tn,N7=typeof self=="object"&&self&&self.Object===Object&&self,L0=F7||N7||Function("return this")();function z7(e,n){var t=e?e.length:0;return!!t&&U7(e,n,0)>-1}function B7(e,n,t,r){for(var o=e.length,i=t+-1;++i<o;)if(n(e[i],i,e))return i;return-1}function U7(e,n,t){if(n!==n)return B7(e,H7,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function H7(e){return e!==e}function K7(e,n){return e.has(n)}function W7(e,n){return e==null?void 0:e[n]}function G7(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function Pk(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var V7=Array.prototype,Y7=Function.prototype,Ck=Object.prototype,pm=L0["__core-js_shared__"],N1=function(){var e=/[^.]+$/.exec(pm&&pm.keys&&pm.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Ik=Y7.toString,F0=Ck.hasOwnProperty,X7=Ck.toString,q7=RegExp("^"+Ik.call(F0).replace(R7,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Z7=V7.splice,Q7=N0(L0,"Map"),gm=N0(L0,"Set"),Hl=N0(Object,"create");function Ts(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 J7(){this.__data__=Hl?Hl(null):{}}function eB(e){return this.has(e)&&delete this.__data__[e]}function tB(e){var n=this.__data__;if(Hl){var t=n[e];return t===R0?void 0:t}return F0.call(n,e)?n[e]:void 0}function nB(e){var n=this.__data__;return Hl?n[e]!==void 0:F0.call(n,e)}function rB(e,n){var t=this.__data__;return t[e]=Hl&&n===void 0?R0:n,this}Ts.prototype.clear=J7;Ts.prototype.delete=eB;Ts.prototype.get=tB;Ts.prototype.has=nB;Ts.prototype.set=rB;function Cc(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 oB(){this.__data__=[]}function iB(e){var n=this.__data__,t=$p(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():Z7.call(n,t,1),!0}function sB(e){var n=this.__data__,t=$p(n,e);return t<0?void 0:n[t][1]}function aB(e){return $p(this.__data__,e)>-1}function cB(e,n){var t=this.__data__,r=$p(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}Cc.prototype.clear=oB;Cc.prototype.delete=iB;Cc.prototype.get=sB;Cc.prototype.has=aB;Cc.prototype.set=cB;function Ic(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 lB(){this.__data__={hash:new Ts,map:new(Q7||Cc),string:new Ts}}function uB(e){return Mp(this,e).delete(e)}function dB(e){return Mp(this,e).get(e)}function hB(e){return Mp(this,e).has(e)}function fB(e,n){return Mp(this,e).set(e,n),this}Ic.prototype.clear=lB;Ic.prototype.delete=uB;Ic.prototype.get=dB;Ic.prototype.has=hB;Ic.prototype.set=fB;function jf(e){var n=-1,t=e?e.length:0;for(this.__data__=new Ic;++n<t;)this.add(e[n])}function pB(e){return this.__data__.set(e,R0),this}function gB(e){return this.__data__.has(e)}jf.prototype.add=jf.prototype.push=pB;jf.prototype.has=gB;function $p(e,n){for(var t=e.length;t--;)if(PB(e[t][0],n))return t;return-1}function mB(e){if(!Ek(e)||xB(e))return!1;var n=CB(e)||G7(e)?q7:L7;return n.test(wB(e))}function yB(e,n,t){var r=-1,o=z7,i=e.length,s=!0,a=[],c=a;if(i>=A7){var l=SB(e);if(l)return Pk(l);s=!1,o=K7,c=new jf}else c=a;e:for(;++r<i;){var u=e[r],d=u;if(u=u!==0?u:0,s&&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 SB=gm&&1/Pk(new gm([,-0]))[1]==j7?function(e){return new gm(e)}:IB;function Mp(e,n){var t=e.__data__;return vB(n)?t[typeof n=="string"?"string":"hash"]:t.map}function N0(e,n){var t=W7(e,n);return mB(t)?t:void 0}function vB(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function xB(e){return!!N1&&N1 in e}function wB(e){if(e!=null){try{return Ik.call(e)}catch{}try{return e+""}catch{}}return""}function bB(e){return e&&e.length?yB(e):[]}function PB(e,n){return e===n||e!==e&&n!==n}function CB(e){var n=Ek(e)?X7.call(e):"";return n==O7||n==D7}function Ek(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function IB(){}var EB=bB;const _B=Ki(EB);function _k(e){return _B(e)}function kB(){const e=z(),n=l4("userIds",()=>_k(e.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>{var o;return t.join(",")===((o=r.join)==null?void 0:o.call(r,","))}},[e]);return G(n)}function kk(e){const n=z();return G(`latestPresence:${e}`,()=>n.getCollaborators().find(r=>r.userId===e),[n])??null}const TB=ir(function(){const n=kB();return h.jsx(h.Fragment,{children:n.map(t=>h.jsx($B,{collaboratorId:t},t))})}),$B=ir(function({collaboratorId:n}){const t=z(),r=kk(n),o=AB(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:i,highlightedUserIds:s}=t.getInstanceState();if(!(i===r.userId||s.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:i}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||i.includes(r.userId)))return null;break}}return h.jsx(MB,{latestPresence:r})}),MB=ir(function({latestPresence:n}){const t=z(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:i,CollaboratorHint:s,CollaboratorShapeIndicator:a}=st(),c=t.getZoomLevel(),l=t.getViewportPageBounds(),{userId:u,chatMessage:d,brush:f,scribbles:p,selectedShapeIds:S,userName:m,cursor:w,color:y}=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:y,opacity:.1},u+"_brush"):null,v&&i?h.jsx(i,{className:"tl-collaborator__cursor",point:w,color:y,zoom:c,name:m!=="New User"?m:null,chatMessage:d},u+"_cursor"):s?h.jsx(s,{className:"tl-collaborator__cursor-hint",point:w,color:y,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:y,zoom:c,opacity:P.color==="laser"?.5:.1},u+"_scribble_"+P.id))}):null,a&&S.map(P=>h.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:P,color:y,opacity:.5},u+"_"+P))]})});function z1(e,n){return n>e.options.collaboratorInactiveTimeoutMs?"inactive":n>e.options.collaboratorIdleTimeoutMs?"idle":"active"}function AB(e,n){const t=x.useRef((n==null?void 0:n.lastActivityTimestamp)??-1),[r,o]=x.useState(()=>z1(e,Date.now()-t.current));return x.useEffect(()=>{const i=e.timers.setInterval(()=>{o(z1(e,Date.now()-t.current))},e.options.collaboratorCheckIntervalMs);return()=>clearInterval(i)},[e]),n&&(t.current=n.lastActivityTimestamp),r}const Tk=x.memo(function({id:n,shape:t,util:r,index:o,backgroundIndex:i,opacity:s,dprMultiple:a}){const c=z(),{ShapeErrorFallback:l}=st(),u=x.useRef(null),d=x.useRef(null),f=x.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Ei("set shape stuff",()=>{const m=c.getShape(n);if(!m)return;const w=f.current,y=c.getShapeClipPath(n)??"none";y!==w.clipPath&&(qt(u.current,"clip-path",y),qt(d.current,"clip-path",y),w.clipPath=y);const v=c.getShapePageTransform(n),P=ie.toCssString(v),E=c.getShapeGeometry(m).bounds;P!==w.transform&&(qt(u.current,"transform",P),qt(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)&&(qt(u.current,"width",Math.max(_,a)+"px"),qt(u.current,"height",Math.max(k,a)+"px"),qt(d.current,"width",Math.max(_,a)+"px"),qt(d.current,"height",Math.max(k,a)+"px"),w.width=_,w.height=k)},[c]),Ei("set opacity and z-index",()=>{const m=u.current,w=d.current;qt(m,"opacity",s),qt(w,"opacity",s),qt(m,"z-index",o),qt(w,"z-index",i)},[s,o,i]),Ei("set display",()=>{if(!c.getShape(n))return;const y=c.getCulledShapes().has(n);y!==f.current.isCulled&&(qt(u.current,"display",y?"none":"block"),qt(d.current,"display",y?"none":"block"),f.current.isCulled=y)},[c]);const p=x.useCallback(m=>c.annotateError(m,{origin:"shape",willCrashApp:!1}),[c]);if(!t)return null;const S="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(Ul,{fallback:l,onError:p,children:h.jsx(OB,{shape:t,util:r})})}),h.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":S,draggable:!1,children:h.jsx(Ul,{fallback:l,onError:p,children:h.jsx(jB,{shape:t,util:r})})})]})}),jB=x.memo(function({shape:n,util:t}){return Ip("InnerShape:"+n.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(n.id)))},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta),OB=x.memo(function({shape:n,util:t}){return Ip("InnerShape:"+n.type,()=>{var r;return(r=t.backgroundComponent)==null?void 0:r.call(t,t.editor.store.unsafeGetWithoutCapture(n.id))})},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta);function DB({className:e}){const n=z(),{Background:t,SvgDefs:r}=st(),o=x.useRef(null),i=x.useRef(null),s=x.useRef(null),a=ln();k7(o),Qz(),qz(),o7(o),t8(o);const c=x.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Ei("position layers",function(){const{x:y,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<n.options.textShadowLod!==c.current.lodDisableTextOutline){const I=P<n.options.textShadowLod;a.style.setProperty("--tl-text-outline",I?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=I}const E=P>=1?hf(P,[1,8],[.125,.5],!0):hf(P,[.1,1],[-2,.125],!0),C=`scale(${F(P)}) translate(${F(y+E)}px,${F(v+E)}px)`;qt(i.current,"transform",C),qt(s.current,"transform",C)},[n,a]);const l=Xz(),u=G("shapeSvgDefs",()=>{const w=new Map;for(const y of yt(n.shapeUtils)){if(!y)return;const v=y.getCanvasSvgDefs();for(const{key:P,component:E}of v)w.has(P)||w.set(P,h.jsx(E,{},P))}return[...w.values()]},[n]),d=G("debug_shapes",()=>bt.hideShapes.get(),[bt]),f=G("debug_svg",()=>bt.debugSvg.get(),[bt]),p=G("debug_geometry",()=>bt.debugGeometry.get(),[bt]),S=G("isEditingAnything",()=>n.getEditingShapeId()!==null,[n]),m=G("isSelectingAnything",()=>!!n.getSelectedShapeIds().length,[n]);return h.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":S,"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(XB,{}),h.jsx(qB,{}),r&&h.jsx(r,{})]})}),t&&h.jsx("div",{className:"tl-background__wrapper",children:h.jsx(t,{})}),h.jsx(RB,{}),h.jsxs("div",{ref:i,className:"tl-html-layer tl-shapes",draggable:!1,children:[h.jsx(e9,{}),h.jsx(JB,{}),d?null:f?h.jsx(KB,{}):h.jsx(GB,{})]}),h.jsx("div",{className:"tl-overlays",children:h.jsxs("div",{ref:s,className:"tl-html-layer",children:[p?h.jsx(M7,{}):null,h.jsx(BB,{}),h.jsx(FB,{}),h.jsx(LB,{}),h.jsx(NB,{}),h.jsx(VB,{}),h.jsx(YB,{}),h.jsx(zB,{}),h.jsx(QB,{}),h.jsx(TB,{})]})}),h.jsx(t9,{})]})}function RB(){const e=z(),n=G("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=G("camera",()=>e.getCamera(),[e]),i=G("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:s}=st();return s&&i?h.jsx(s,{x:t,y:r,z:o,size:n}):null}function LB(){const e=z(),n=G("scribbles",()=>e.getInstanceState().scribbles,[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=st();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 FB(){const e=z(),n=G("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=st();return t&&n?h.jsx(t,{className:"tl-user-brush",brush:n}):null}function NB(){const e=z(),n=G("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=st();return t&&n?h.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function zB(){const e=z(),n=G("snapLines",()=>e.snaps.getIndicators(),[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=st();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 BB(){const e=z(),n=G("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=e.getInstanceState();if(t||r)return!1;const o=e.getOnlySelectedShape();return!o||!e.getShapeHandles(o)?!1:o.id},[e]);return n?h.jsx(UB,{shapeId:n}):null}function UB({shapeId:e}){const n=z(),{Handles:t}=st(),r=G("zoomLevel",()=>n.getZoomLevel(),[n]),o=G("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),i=G("handles transform",()=>n.getShapePageTransform(e),[n,e]),s=G("handles",()=>{const a=n.getShapeHandles(e);if(!a)return null;const c=(o?n.options.coarseHandleRadius:n.options.handleRadius)/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||!s||!i?null:h.jsx(t,{children:h.jsx("g",{transform:ie.toCssString(i),children:s.map(a=>h.jsx(HB,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function HB({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=i7(e,n.id),{Handle:i}=st();return i?h.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:h.jsx(i,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function KB(){const e=z(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>wk(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsx(h.Fragment,{children:n.map(r=>h.jsxs(x.Fragment,{children:[h.jsx(Tk,{...r,dprMultiple:t}),h.jsx(ZB,{id:r.id})]},r.id+"_fragment"))})}function WB(){const e=z(),n=x.useRef(new Set);return Ei("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 GB(){const e=z(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>wk(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsxs(h.Fragment,{children:[n.map(r=>h.jsx(Tk,{...r,dprMultiple:t},r.id+"_shape")),e.environment.isSafari&&h.jsx(WB,{})]})}function VB(){const e=z(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=x.useRef(new Set),r=G("should display selected ids",()=>{const i=t.current,s=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)s.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const l=e.getHoveredShapeId();l&&s.add(l)}}}if(i.size!==s.size)return t.current=s,s;for(const a of s)if(!i.has(a))return t.current=s,s;return i},[e]),{ShapeIndicator:o}=st();return o?h.jsx(h.Fragment,{children:n.map(({id:i})=>h.jsx(o,{shapeId:i,hidden:!r.has(i)},i+"_indicator"))}):null}function YB(){const e=z(),{ShapeIndicator:n}=st(),t=G("hinting shape ids",()=>p0(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 XB(){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 qB(){return h.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function ZB({id:e}){const n=z(),[t,r]=x.useState(null),o=G("is in root",()=>{const i=n.getShape(e);return(i==null?void 0:i.parentId)===n.getCurrentPageId()},[n,e]);return x.useEffect(()=>{if(!o)return;let i=null;const s=Gs("shape to svg",async()=>{const a=Math.random();i=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(i!==a||!d)return;const f=`data:image/svg+xml;utf8,${encodeURIComponent(d.svg)}`;r({src:f,bounds:u})});return()=>{i=null,s()}},[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 QB(){const e=z(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=st();return!t||!r?null:h.jsx(r,{bounds:t,rotation:n})}function JB(){const e=z(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=st();return!t||!r?null:h.jsx(r,{bounds:t,rotation:n})}function e9(){const{OnTheCanvas:e}=st();return e?h.jsx(e,{}):null}function t9(){const e=z(),n=G("camera state",()=>e.getCameraState(),[e]);return h.jsx("div",{className:ue("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":n==="idle"})})}function n9({className:e,zoom:n,point:t,color:r,viewport:o,opacity:i=1}){const s=x.useRef(null);return Pc(s,Tt(t.x,o.minX+5/n,o.maxX-5/n),Tt(t.y,o.minY+5/n,o.maxY-5/n),1/n,b.Angle(o.center,t)),h.jsxs("svg",{ref:s,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:i})]})}const B1=x.memo(function({className:n,zoom:t,point:r,color:o,name:i,chatMessage:s}){const a=x.useRef(null);return Pc(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})}),s?h.jsxs(h.Fragment,{children:[i&&h.jsx("div",{className:"tl-nametag-title",style:{color:o},children:i}),h.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:s})]}):i&&h.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:i})]}):null});function r9({x:e,y:n,z:t,size:r}){const o=z(),{gridSteps:i}=o.options;return h.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("defs",{children:i.map(({min:s,mid:a,step:c},l)=>{const u=c*r*t,d=.5+e*t,f=.5+n*t,p=d>0?d%u:u+d%u,S=f>0?f%u:u+f%u,m=t<a?hf(t,[s,a],[0,1]):1;return h.jsx("pattern",{id:`grid-${c}`,width:u,height:u,patternUnits:"userSpaceOnUse",children:h.jsx("circle",{className:"tl-grid-dot",cx:p,cy:S,r:1,opacity:m})},`grid-pattern-${l}`)})}),i.map(({step:s},a)=>h.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${s})`},`grid-rect-${a}`))]})}function o9({handle:e,isCoarse:n,className:t,zoom:r}){const o=z(),i=(n?o.options.coarseHandleRadius:o.options.handleRadius)/r;if(e.type==="clone"){const a=3/Math.max(r,.35),c=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,l=Hz.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:i}),h.jsx("path",{className:"tl-handle__fg",d:c,transform:`rotate(${-90+90*l})`})]})}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:i}),h.jsx("circle",{className:"tl-handle__fg",r:s})]})}const i9=({children:e})=>h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),s9=()=>{const{Spinner:e}=st();return h.jsx(Ux,{children:e?h.jsx(e,{}):null})};function z0(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 i="";for(let s=2,a=t-1;s<a;s++)r=e[s],o=e[s+1],i+=Cn(r,o);return n?`M${Cn(e[0],e[1])}Q${Ee(e[1])}${Cn(e[1],e[2])}T${i}${Cn(e[t-1],e[0])}${Cn(e[0],e[1])}Z`:`M${Ee(e[0])}Q${Ee(e[1])}${Cn(e[1],e[2])}${e.length>3?"T":""}${i}L${Ee(e[t-1])}`}function U1({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:z0(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null}function $k({bounds:e,rotation:n}){const t=x.useRef(null);return Pc(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 a9({bounds:e,rotation:n}){const t=z(),r=x.useRef(null),o=G("only selected shape",()=>t.getOnlySelectedShape(),[t]),i=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Pc(r,e==null?void 0:e.x,e==null?void 0:e.y,1,n,{x:-i,y:-i}),e=e.clone().expandBy(i).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 c9=()=>h.jsx("div",{className:"tl-shape-error-boundary"}),l9=({shape:e,util:n})=>Ip("Indicator: "+e.type,()=>n.indicator(n.editor.store.unsafeGetWithoutCapture(e.id))),u9=({editor:e,id:n})=>{const t=G("shape for indicator",()=>e.store.get(n),[e,n]),{ShapeIndicatorErrorFallback:r}=st();return!t||t.isLocked?null:h.jsx(Ul,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:h.jsx(l9,{shape:t,util:e.getShapeUtil(t)},t.id)})},H1=x.memo(function({shapeId:n,className:t,color:r,hidden:o,opacity:i}){const s=z(),a=x.useRef(null);return Ei("indicator transform",()=>{const c=a.current;if(!c)return;const l=s.getShapePageTransform(n);l&&c.style.setProperty("transform",l.toCssString())},[s,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:i,children:h.jsx(u9,{editor:s,id:n})})})}),d9=()=>h.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function h9({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),i=e.reduce((f,p)=>Math.min(f,p.y),1/0),s=e.reduce((f,p)=>Math.max(f,p.y),-1/0),a=e.some(f=>f.x===r&&f.y===i);let c,l,u,d;return a?(c=r,l=i,u=o,d=s):(c=r,l=s,u=o,d=i),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 f9({gaps:e,direction:n,zoom:t}){const r=3.5/t;let o=[-1/0,1/0],i=null;const s=n==="horizontal";for(const c of e){if(i=Mr(o[0],o[1],s?c.startEdge[0].y:c.startEdge[0].x,s?c.startEdge[1].y:c.startEdge[1].x),i)o=i;else continue;if(i=Mr(o[0],o[1],s?c.endEdge[0].y:c.endEdge[0].x,s?c.endEdge[1].y:c.endEdge[1].x),i)o=i;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:s?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 p9({className:e,line:n,zoom:t}){return h.jsx("svg",{className:ue("tl-overlays__item",e),children:n.type==="points"?h.jsx(h9,{...n,zoom:t}):n.type==="gaps"?h.jsx(f9,{...n,zoom:t}):null})}function g9(){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 m9=()=>null;function Mk(e,n){const t=x.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Cl(e){return Mk(e,SN)}function B0(e){return Mk(e,XE)}const Ak=x.createContext(null);function y9({overrides:e={},children:n}){const t=B0(e);return h.jsx(Ak.Provider,{value:x.useMemo(()=>({Background:Rz,SvgDefs:m9,Brush:cm,ZoomBrush:cm,CollaboratorBrush:cm,Cursor:B1,CollaboratorCursor:B1,CollaboratorHint:n9,CollaboratorShapeIndicator:H1,Grid:r9,Scribble:U1,SnapIndicator:p9,Handles:i9,Handle:o9,CollaboratorScribble:U1,ErrorFallback:Ok,ShapeErrorFallback:c9,ShapeIndicatorErrorFallback:d9,Spinner:g9,SelectionBackground:$k,SelectionForeground:a9,ShapeIndicator:H1,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:DB,LoadingScreen:s9,...t}),[t]),children:n})}function st(){const e=x.useContext(Ak);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const U0={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 jk(){U0.hardReset()}function S9(){U0.refreshPage()}const v9="https://github.com/tldraw/tldraw/issues/new",Ok=({error:e,editor:n})=>{const t=x.useRef(null),[r,o]=x.useState(!1),[i,s]=x.useState(!1),[a,c]=x.useState(!1);let l=null;try{l=st().Canvas??null}catch{}const u=e instanceof Error?e.message:String(e),d=e instanceof Error?e.stack:null,f=G("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[p,S]=x.useState(null);x.useLayoutEffect(()=>{var C;f!==null&&S(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){S(null);return}S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[f]),x.useEffect(()=>{if(i){const P=n==null?void 0:n.timers.setTimeout(()=>{s(!1)},2e3);return()=>clearTimeout(P)}},[i,n]);const m=()=>{const P=document.createElement("textarea");P.value=d??u,document.body.appendChild(P),P.select(),document.execCommand("copy"),P.remove(),s(!0)},w=()=>{S9()},y=async()=>{jk()},v=new URL(v9);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
57
-
58
- \`\`\`js
59
- ${d??u}
60
- \`\`\`
61
-
62
- 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(ok,{onError:df,fallback:()=>null,children:h.jsx(Tp.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:y,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:i?"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 ku()}const Dk="TLDRAW_USER_DATA_v3",Rk=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()}),pa={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5},H0=Math.max(...Object.values(pa));function x9(e){e.version<pa.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<pa.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<pa.MakeFieldsNullable,e.version<pa.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<pa.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version=H0}const K1=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function w9(){return K1[Math.floor(Math.random()*K1.length)]}function b9(){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 P9(){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 ls=Object.freeze({name:"New User",locale:Mz(),color:w9(),isDarkMode:!1,edgeScrollSpeed:1,animationSpeed:P9()?0:1,isSnapMode:!1,isWrapMode:!1});function mm(){return{id:ot()}}function Lk(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return mm();const n=vt(e);x9(n);try{return Rk.validate(n.user)}catch{return mm()}}function C9(){const e=JSON.parse(y0(Dk)||"null")??null;return Lk(e)}const Kl=rn("globalUserData",null);function I9(){S0(Dk,JSON.stringify({version:H0,user:Kl.get()}))}function E9(e){Rk.validate(e),Kl.set(e),I9(),k9()}const _9=typeof process<"u"&&!1,Ha=typeof BroadcastChannel<"u"&&!_9?new BroadcastChannel("tldraw-user-sync"):null;Ha==null||Ha.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===Nk&&(n==null?void 0:n.origin)!==Fk()&&Kl.set(Lk(n.data))});let ym=null;function Fk(){return ym===null&&(ym=ot()),ym}const Nk="tldraw-user-preferences-change";function k9(){Ha==null||Ha.postMessage({type:Nk,origin:Fk(),data:{user:zk(),version:H0}})}function zk(){let e=Kl.get();return e||(e=C9(),Kl.set(e)),e}function Bk(e={}){return{derivePresenceState:e.derivePresenceState??(()=>V("presence",()=>null)),userPreferences:e.userPreferences??V("userPreferences",()=>zk()),setUserPreferences:e.setUserPreferences??E9}}var Uk={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 i(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),S=t?t+l:l;return c._events[S]?c._events[S].fn?c._events[S]=[c._events[S],p]:c._events[S].push(p):(c._events[S]=p,c._eventsCount++),c}function s(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,S=new Array(p);f<p;f++)S[f]=d[f].fn;return S},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,S){var m=t?t+l:l;if(!this._events[m])return!1;var w=this._events[m],y=arguments.length,v,P;if(w.fn){switch(w.once&&this.removeListener(l,w.fn,void 0,!0),y){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,S),!0}for(P=1,v=new Array(y-1);P<y;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),y){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(y-1);C<y;C++)v[C-1]=arguments[C];w[P].fn.apply(w[P].context,v)}}return!0},a.prototype.on=function(l,u,d){return i(this,l,u,d,!1)},a.prototype.once=function(l,u,d){return i(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 s(this,p),this;var S=this._events[p];if(S.fn)S.fn===u&&(!f||S.once)&&(!d||S.context===d)&&s(this,p);else{for(var m=0,w=[],y=S.length;m<y;m++)(S[m].fn!==u||f&&!S[m].once||d&&S[m].context!==d)&&w.push(S[m]);w.length?this._events[p]=w.length===1?w[0]:w:s(this,p)}return this},a.prototype.removeAllListeners=function(l){var u;return l?(u=t?t+l:l,this._events[u]&&s(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})(Uk);var T9=Uk.exports;const $9=Ki(T9);var Hk={exports:{}},ar={},Kk={exports:{}},Wk={};/**
63
- * @license React
64
- * scheduler.production.min.js
65
- *
66
- * Copyright (c) Facebook, Inc. and its affiliates.
67
- *
68
- * This source code is licensed under the MIT license found in the
69
- * LICENSE file in the root directory of this source tree.
70
- */(function(e){function n(U,H){var W=U.length;U.push(H);e:for(;0<W;){var Z=W-1>>>1,oe=U[Z];if(0<o(oe,H))U[Z]=H,U[W]=oe,W=Z;else break e}}function t(U){return U.length===0?null:U[0]}function r(U){if(U.length===0)return null;var H=U[0],W=U.pop();if(W!==H){U[0]=W;e:for(var Z=0,oe=U.length,be=oe>>>1;Z<be;){var Ae=2*(Z+1)-1,ce=U[Ae],je=Ae+1,Le=U[je];if(0>o(ce,W))je<oe&&0>o(Le,ce)?(U[Z]=Le,U[je]=W,Z=je):(U[Z]=ce,U[Ae]=W,Z=Ae);else if(je<oe&&0>o(Le,W))U[Z]=Le,U[je]=W,Z=je;else break e}}return H}function o(U,H){var W=U.sortIndex-H.sortIndex;return W!==0?W:U.id-H.id}if(typeof performance=="object"&&typeof performance.now=="function"){var i=performance;e.unstable_now=function(){return i.now()}}else{var s=Date,a=s.now();e.unstable_now=function(){return s.now()-a}}var c=[],l=[],u=1,d=null,f=3,p=!1,S=!1,m=!1,w=typeof setTimeout=="function"?setTimeout:null,y=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function P(U){for(var H=t(l);H!==null;){if(H.callback===null)r(l);else if(H.startTime<=U)r(l),H.sortIndex=H.expirationTime,n(c,H);else break;H=t(l)}}function E(U){if(m=!1,P(U),!S)if(t(c)!==null)S=!0,Y(C);else{var H=t(l);H!==null&&K(E,H.startTime-U)}}function C(U,H){S=!1,m&&(m=!1,y(k),k=-1),p=!0;var W=f;try{for(P(H),d=t(c);d!==null&&(!(d.expirationTime>H)||U&&!A());){var Z=d.callback;if(typeof Z=="function"){d.callback=null,f=d.priorityLevel;var oe=Z(d.expirationTime<=H);H=e.unstable_now(),typeof oe=="function"?d.callback=oe:d===t(c)&&r(c),P(H)}else r(c);d=t(c)}if(d!==null)var be=!0;else{var Ae=t(l);Ae!==null&&K(E,Ae.startTime-H),be=!1}return be}finally{d=null,f=W,p=!1}}var I=!1,_=null,k=-1,$=5,T=-1;function A(){return!(e.unstable_now()-T<$)}function N(){if(_!==null){var U=e.unstable_now();T=U;var H=!0;try{H=_(!0,U)}finally{H?j():(I=!1,_=null)}}else I=!1}var j;if(typeof v=="function")j=function(){v(N)};else if(typeof MessageChannel<"u"){var O=new MessageChannel,R=O.port2;O.port1.onmessage=N,j=function(){R.postMessage(null)}}else j=function(){w(N,0)};function Y(U){_=U,I||(I=!0,j())}function K(U,H){k=w(function(){U(e.unstable_now())},H)}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(U){U.callback=null},e.unstable_continueExecution=function(){S||p||(S=!0,Y(C))},e.unstable_forceFrameRate=function(U){0>U||125<U?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<U?Math.floor(1e3/U):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_getFirstCallbackNode=function(){return t(c)},e.unstable_next=function(U){switch(f){case 1:case 2:case 3:var H=3;break;default:H=f}var W=f;f=H;try{return U()}finally{f=W}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(U,H){switch(U){case 1:case 2:case 3:case 4:case 5:break;default:U=3}var W=f;f=U;try{return H()}finally{f=W}},e.unstable_scheduleCallback=function(U,H,W){var Z=e.unstable_now();switch(typeof W=="object"&&W!==null?(W=W.delay,W=typeof W=="number"&&0<W?Z+W:Z):W=Z,U){case 1:var oe=-1;break;case 2:oe=250;break;case 5:oe=1073741823;break;case 4:oe=1e4;break;default:oe=5e3}return oe=W+oe,U={id:u++,callback:H,priorityLevel:U,startTime:W,expirationTime:oe,sortIndex:-1},W>Z?(U.sortIndex=W,n(l,U),t(c)===null&&U===t(l)&&(m?(y(k),k=-1):m=!0,K(E,W-Z))):(U.sortIndex=oe,n(c,U),S||p||(S=!0,Y(C))),U},e.unstable_shouldYield=A,e.unstable_wrapCallback=function(U){var H=f;return function(){var W=f;f=H;try{return U.apply(this,arguments)}finally{f=W}}}})(Wk);Kk.exports=Wk;var M9=Kk.exports;/**
71
- * @license React
72
- * react-dom.production.min.js
73
- *
74
- * Copyright (c) Facebook, Inc. and its affiliates.
75
- *
76
- * This source code is licensed under the MIT license found in the
77
- * LICENSE file in the root directory of this source tree.
78
- */var A9=x,or=M9;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 Gk=new Set,Wl={};function Vs(e,n){oc(e,n),oc(e+"Capture",n)}function oc(e,n){for(Wl[e]=n,e=0;e<n.length;e++)Gk.add(n[e])}var Wo=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),gS=Object.prototype.hasOwnProperty,j9=/^[: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]*$/,W1={},G1={};function O9(e){return gS.call(G1,e)?!0:gS.call(W1,e)?!1:j9.test(e)?G1[e]=!0:(W1[e]=!0,!1)}function D9(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 R9(e,n,t,r){if(n===null||typeof n>"u"||D9(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 vn(e,n,t,r,o,i,s){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=i,this.removeEmptyString=s}var Wt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Wt[e]=new vn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Wt[n]=new vn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Wt[e]=new vn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Wt[e]=new vn(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){Wt[e]=new vn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Wt[e]=new vn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Wt[e]=new vn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Wt[e]=new vn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Wt[e]=new vn(e,5,!1,e.toLowerCase(),null,!1,!1)});var K0=/[\-:]([a-z])/g;function W0(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(K0,W0);Wt[n]=new vn(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(K0,W0);Wt[n]=new vn(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(K0,W0);Wt[n]=new vn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Wt[e]=new vn(e,1,!1,e.toLowerCase(),null,!1,!1)});Wt.xlinkHref=new vn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Wt[e]=new vn(e,1,!1,e.toLowerCase(),null,!0,!0)});function G0(e,n,t,r){var o=Wt.hasOwnProperty(n)?Wt[n]:null;(o!==null?o.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(R9(n,t,o,r)&&(t=null),r||o===null?O9(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 ti=A9.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,gd=Symbol.for("react.element"),ba=Symbol.for("react.portal"),Pa=Symbol.for("react.fragment"),V0=Symbol.for("react.strict_mode"),mS=Symbol.for("react.profiler"),Vk=Symbol.for("react.provider"),Yk=Symbol.for("react.context"),Y0=Symbol.for("react.forward_ref"),yS=Symbol.for("react.suspense"),SS=Symbol.for("react.suspense_list"),X0=Symbol.for("react.memo"),mi=Symbol.for("react.lazy"),Xk=Symbol.for("react.offscreen"),V1=Symbol.iterator;function Vc(e){return e===null||typeof e!="object"?null:(e=V1&&e[V1]||e["@@iterator"],typeof e=="function"?e:null)}var ft=Object.assign,Sm;function pl(e){if(Sm===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);Sm=n&&n[1]||""}return`
79
- `+Sm+e}var vm=!1;function xm(e,n){if(!e||vm)return"";vm=!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(`
80
- `),i=r.stack.split(`
81
- `),s=o.length-1,a=i.length-1;1<=s&&0<=a&&o[s]!==i[a];)a--;for(;1<=s&&0<=a;s--,a--)if(o[s]!==i[a]){if(s!==1||a!==1)do if(s--,a--,0>a||o[s]!==i[a]){var c=`
82
- `+o[s].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=s&&0<=a);break}}}finally{vm=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?pl(e):""}function L9(e){switch(e.tag){case 5:return pl(e.type);case 16:return pl("Lazy");case 13:return pl("Suspense");case 19:return pl("SuspenseList");case 0:case 2:case 15:return e=xm(e.type,!1),e;case 11:return e=xm(e.type.render,!1),e;case 1:return e=xm(e.type,!0),e;default:return""}}function vS(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 mS:return"Profiler";case V0:return"StrictMode";case yS:return"Suspense";case SS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case Yk:return(e.displayName||"Context")+".Consumer";case Vk:return(e._context.displayName||"Context")+".Provider";case Y0:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case X0:return n=e.displayName||null,n!==null?n:vS(e.type)||"Memo";case mi:n=e._payload,e=e._init;try{return vS(e(n))}catch{}}return null}function F9(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 vS(n);case 8:return n===V0?"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 Fi(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function qk(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function N9(e){var n=qk(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,i=t.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return o.call(this)},set:function(s){r=""+s,i.call(this,s)}}),Object.defineProperty(e,n,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(s){r=""+s},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function md(e){e._valueTracker||(e._valueTracker=N9(e))}function Zk(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=qk(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function Of(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 xS(e,n){var t=n.checked;return ft({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function Y1(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Fi(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 Qk(e,n){n=n.checked,n!=null&&G0(e,"checked",n,!1)}function wS(e,n){Qk(e,n);var t=Fi(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")?bS(e,n.type,t):n.hasOwnProperty("defaultValue")&&bS(e,n.type,Fi(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function X1(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 bS(e,n,t){(n!=="number"||Of(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var gl=Array.isArray;function Ka(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=""+Fi(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 PS(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return ft({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function q1(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(gl(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Fi(t)}}function Jk(e,n){var t=Fi(n.value),r=Fi(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 Z1(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function eT(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 CS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?eT(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var yd,tT=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(n,t,r,o){MSApp.execUnsafeLocalFunction(function(){return e(n,t,r,o)})}:e}(function(e,n){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=n;else{for(yd=yd||document.createElement("div"),yd.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=yd.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Gl(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var Il={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},z9=["Webkit","ms","Moz","O"];Object.keys(Il).forEach(function(e){z9.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),Il[n]=Il[e]})});function nT(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||Il.hasOwnProperty(e)&&Il[e]?(""+n).trim():n+"px"}function rT(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=nT(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var B9=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 IS(e,n){if(n){if(B9[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 ES(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 _S=null;function q0(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var kS=null,Wa=null,Ga=null;function Q1(e){if(e=Lu(e)){if(typeof kS!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Rp(n),kS(e.stateNode,e.type,n))}}function oT(e){Wa?Ga?Ga.push(e):Ga=[e]:Wa=e}function iT(){if(Wa){var e=Wa,n=Ga;if(Ga=Wa=null,Q1(e),n)for(e=0;e<n.length;e++)Q1(n[e])}}function sT(e,n){return e(n)}function aT(){}var wm=!1;function cT(e,n,t){if(wm)return e(n,t);wm=!0;try{return sT(e,n,t)}finally{wm=!1,(Wa!==null||Ga!==null)&&(aT(),iT())}}function Vl(e,n){var t=e.stateNode;if(t===null)return null;var r=Rp(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 TS=!1;if(Wo)try{var Yc={};Object.defineProperty(Yc,"passive",{get:function(){TS=!0}}),window.addEventListener("test",Yc,Yc),window.removeEventListener("test",Yc,Yc)}catch{TS=!1}function U9(e,n,t,r,o,i,s,a,c){var l=Array.prototype.slice.call(arguments,3);try{n.apply(t,l)}catch(u){this.onError(u)}}var El=!1,Df=null,Rf=!1,$S=null,H9={onError:function(e){El=!0,Df=e}};function K9(e,n,t,r,o,i,s,a,c){El=!1,Df=null,U9.apply(H9,arguments)}function W9(e,n,t,r,o,i,s,a,c){if(K9.apply(this,arguments),El){if(El){var l=Df;El=!1,Df=null}else throw Error(q(198));Rf||(Rf=!0,$S=l)}}function Ys(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 lT(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 J1(e){if(Ys(e)!==e)throw Error(q(188))}function G9(e){var n=e.alternate;if(!n){if(n=Ys(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 i=o.alternate;if(i===null){if(r=o.return,r!==null){t=r;continue}break}if(o.child===i.child){for(i=o.child;i;){if(i===t)return J1(o),e;if(i===r)return J1(o),n;i=i.sibling}throw Error(q(188))}if(t.return!==r.return)t=o,r=i;else{for(var s=!1,a=o.child;a;){if(a===t){s=!0,t=o,r=i;break}if(a===r){s=!0,r=o,t=i;break}a=a.sibling}if(!s){for(a=i.child;a;){if(a===t){s=!0,t=i,r=o;break}if(a===r){s=!0,r=i,t=o;break}a=a.sibling}if(!s)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 uT(e){return e=G9(e),e!==null?dT(e):null}function dT(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=dT(e);if(n!==null)return n;e=e.sibling}return null}var hT=or.unstable_scheduleCallback,eP=or.unstable_cancelCallback,V9=or.unstable_shouldYield,Y9=or.unstable_requestPaint,Pt=or.unstable_now,X9=or.unstable_getCurrentPriorityLevel,Z0=or.unstable_ImmediatePriority,fT=or.unstable_UserBlockingPriority,Lf=or.unstable_NormalPriority,q9=or.unstable_LowPriority,pT=or.unstable_IdlePriority,Ap=null,ao=null;function Z9(e){if(ao&&typeof ao.onCommitFiberRoot=="function")try{ao.onCommitFiberRoot(Ap,e,void 0,(e.current.flags&128)===128)}catch{}}var Lr=Math.clz32?Math.clz32:eU,Q9=Math.log,J9=Math.LN2;function eU(e){return e>>>=0,e===0?32:31-(Q9(e)/J9|0)|0}var Sd=64,vd=4194304;function ml(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 Ff(e,n){var t=e.pendingLanes;if(t===0)return 0;var r=0,o=e.suspendedLanes,i=e.pingedLanes,s=t&268435455;if(s!==0){var a=s&~o;a!==0?r=ml(a):(i&=s,i!==0&&(r=ml(i)))}else s=t&~o,s!==0?r=ml(s):i!==0&&(r=ml(i));if(r===0)return 0;if(n!==0&&n!==r&&!(n&o)&&(o=r&-r,i=n&-n,o>=i||o===16&&(i&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-Lr(n),o=1<<t,r|=e[t],n&=~o;return r}function tU(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 nU(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,i=e.pendingLanes;0<i;){var s=31-Lr(i),a=1<<s,c=o[s];c===-1?(!(a&t)||a&r)&&(o[s]=tU(a,n)):c<=n&&(e.expiredLanes|=a),i&=~a}}function MS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function gT(){var e=Sd;return Sd<<=1,!(Sd&4194240)&&(Sd=64),e}function bm(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function Du(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Lr(n),e[n]=t}function rU(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-Lr(t),i=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~i}}function Q0(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-Lr(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var Ne=0;function mT(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var yT,J0,ST,vT,xT,AS=!1,xd=[],ki=null,Ti=null,$i=null,Yl=new Map,Xl=new Map,vi=[],oU="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 tP(e,n){switch(e){case"focusin":case"focusout":ki=null;break;case"dragenter":case"dragleave":Ti=null;break;case"mouseover":case"mouseout":$i=null;break;case"pointerover":case"pointerout":Yl.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Xl.delete(n.pointerId)}}function Xc(e,n,t,r,o,i){return e===null||e.nativeEvent!==i?(e={blockedOn:n,domEventName:t,eventSystemFlags:r,nativeEvent:i,targetContainers:[o]},n!==null&&(n=Lu(n),n!==null&&J0(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function iU(e,n,t,r,o){switch(n){case"focusin":return ki=Xc(ki,e,n,t,r,o),!0;case"dragenter":return Ti=Xc(Ti,e,n,t,r,o),!0;case"mouseover":return $i=Xc($i,e,n,t,r,o),!0;case"pointerover":var i=o.pointerId;return Yl.set(i,Xc(Yl.get(i)||null,e,n,t,r,o)),!0;case"gotpointercapture":return i=o.pointerId,Xl.set(i,Xc(Xl.get(i)||null,e,n,t,r,o)),!0}return!1}function wT(e){var n=ps(e.target);if(n!==null){var t=Ys(n);if(t!==null){if(n=t.tag,n===13){if(n=lT(t),n!==null){e.blockedOn=n,xT(e.priority,function(){ST(t)});return}}else if(n===3&&t.stateNode.current.memoizedState.isDehydrated){e.blockedOn=t.tag===3?t.stateNode.containerInfo:null;return}}}e.blockedOn=null}function fh(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=jS(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);_S=r,t.target.dispatchEvent(r),_S=null}else return n=Lu(t),n!==null&&J0(n),e.blockedOn=t,!1;n.shift()}return!0}function nP(e,n,t){fh(e)&&t.delete(n)}function sU(){AS=!1,ki!==null&&fh(ki)&&(ki=null),Ti!==null&&fh(Ti)&&(Ti=null),$i!==null&&fh($i)&&($i=null),Yl.forEach(nP),Xl.forEach(nP)}function qc(e,n){e.blockedOn===n&&(e.blockedOn=null,AS||(AS=!0,or.unstable_scheduleCallback(or.unstable_NormalPriority,sU)))}function ql(e){function n(o){return qc(o,e)}if(0<xd.length){qc(xd[0],e);for(var t=1;t<xd.length;t++){var r=xd[t];r.blockedOn===e&&(r.blockedOn=null)}}for(ki!==null&&qc(ki,e),Ti!==null&&qc(Ti,e),$i!==null&&qc($i,e),Yl.forEach(n),Xl.forEach(n),t=0;t<vi.length;t++)r=vi[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<vi.length&&(t=vi[0],t.blockedOn===null);)wT(t),t.blockedOn===null&&vi.shift()}var Va=ti.ReactCurrentBatchConfig,Nf=!0;function aU(e,n,t,r){var o=Ne,i=Va.transition;Va.transition=null;try{Ne=1,ex(e,n,t,r)}finally{Ne=o,Va.transition=i}}function cU(e,n,t,r){var o=Ne,i=Va.transition;Va.transition=null;try{Ne=4,ex(e,n,t,r)}finally{Ne=o,Va.transition=i}}function ex(e,n,t,r){if(Nf){var o=jS(e,n,t,r);if(o===null)Am(e,n,r,zf,t),tP(e,r);else if(iU(o,e,n,t,r))r.stopPropagation();else if(tP(e,r),n&4&&-1<oU.indexOf(e)){for(;o!==null;){var i=Lu(o);if(i!==null&&yT(i),i=jS(e,n,t,r),i===null&&Am(e,n,r,zf,t),i===o)break;o=i}o!==null&&r.stopPropagation()}else Am(e,n,r,null,t)}}var zf=null;function jS(e,n,t,r){if(zf=null,e=q0(r),e=ps(e),e!==null)if(n=Ys(e),n===null)e=null;else if(t=n.tag,t===13){if(e=lT(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 zf=e,null}function bT(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(X9()){case Z0:return 1;case fT:return 4;case Lf:case q9:return 16;case pT:return 536870912;default:return 16}default:return 16}}var bi=null,tx=null,ph=null;function PT(){if(ph)return ph;var e,n=tx,t=n.length,r,o="value"in bi?bi.value:bi.textContent,i=o.length;for(e=0;e<t&&n[e]===o[e];e++);var s=t-e;for(r=1;r<=s&&n[t-r]===o[i-r];r++);return ph=o.slice(e,1<r?1-r:void 0)}function gh(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 wd(){return!0}function rP(){return!1}function cr(e){function n(t,r,o,i,s){this._reactName=t,this._targetInst=o,this.type=r,this.nativeEvent=i,this.target=s,this.currentTarget=null;for(var a in e)e.hasOwnProperty(a)&&(t=e[a],this[a]=t?t(i):i[a]);return this.isDefaultPrevented=(i.defaultPrevented!=null?i.defaultPrevented:i.returnValue===!1)?wd:rP,this.isPropagationStopped=rP,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=wd)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=wd)},persist:function(){},isPersistent:wd}),n}var Ec={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},nx=cr(Ec),Ru=ft({},Ec,{view:0,detail:0}),lU=cr(Ru),Pm,Cm,Zc,jp=ft({},Ru,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:rx,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!==Zc&&(Zc&&e.type==="mousemove"?(Pm=e.screenX-Zc.screenX,Cm=e.screenY-Zc.screenY):Cm=Pm=0,Zc=e),Pm)},movementY:function(e){return"movementY"in e?e.movementY:Cm}}),oP=cr(jp),uU=ft({},jp,{dataTransfer:0}),dU=cr(uU),hU=ft({},Ru,{relatedTarget:0}),Im=cr(hU),fU=ft({},Ec,{animationName:0,elapsedTime:0,pseudoElement:0}),pU=cr(fU),gU=ft({},Ec,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),mU=cr(gU),yU=ft({},Ec,{data:0}),iP=cr(yU),SU={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},vU={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"},xU={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function wU(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=xU[e])?!!n[e]:!1}function rx(){return wU}var bU=ft({},Ru,{key:function(e){if(e.key){var n=SU[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=gh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?vU[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:rx,charCode:function(e){return e.type==="keypress"?gh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?gh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),PU=cr(bU),CU=ft({},jp,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),sP=cr(CU),IU=ft({},Ru,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:rx}),EU=cr(IU),_U=ft({},Ec,{propertyName:0,elapsedTime:0,pseudoElement:0}),kU=cr(_U),TU=ft({},jp,{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}),$U=cr(TU),MU=[9,13,27,32],ox=Wo&&"CompositionEvent"in window,_l=null;Wo&&"documentMode"in document&&(_l=document.documentMode);var AU=Wo&&"TextEvent"in window&&!_l,CT=Wo&&(!ox||_l&&8<_l&&11>=_l),aP=" ",cP=!1;function IT(e,n){switch(e){case"keyup":return MU.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function ET(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Ca=!1;function jU(e,n){switch(e){case"compositionend":return ET(n);case"keypress":return n.which!==32?null:(cP=!0,aP);case"textInput":return e=n.data,e===aP&&cP?null:e;default:return null}}function OU(e,n){if(Ca)return e==="compositionend"||!ox&&IT(e,n)?(e=PT(),ph=tx=bi=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 CT&&n.locale!=="ko"?null:n.data;default:return null}}var DU={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 lP(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!DU[e.type]:n==="textarea"}function _T(e,n,t,r){oT(r),n=Bf(n,"onChange"),0<n.length&&(t=new nx("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var kl=null,Zl=null;function RU(e){FT(e,0)}function Op(e){var n=_a(e);if(Zk(n))return e}function LU(e,n){if(e==="change")return n}var kT=!1;if(Wo){var Em;if(Wo){var _m="oninput"in document;if(!_m){var uP=document.createElement("div");uP.setAttribute("oninput","return;"),_m=typeof uP.oninput=="function"}Em=_m}else Em=!1;kT=Em&&(!document.documentMode||9<document.documentMode)}function dP(){kl&&(kl.detachEvent("onpropertychange",TT),Zl=kl=null)}function TT(e){if(e.propertyName==="value"&&Op(Zl)){var n=[];_T(n,Zl,e,q0(e)),cT(RU,n)}}function FU(e,n,t){e==="focusin"?(dP(),kl=n,Zl=t,kl.attachEvent("onpropertychange",TT)):e==="focusout"&&dP()}function NU(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Op(Zl)}function zU(e,n){if(e==="click")return Op(n)}function BU(e,n){if(e==="input"||e==="change")return Op(n)}function UU(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Ur=typeof Object.is=="function"?Object.is:UU;function Ql(e,n){if(Ur(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var t=Object.keys(e),r=Object.keys(n);if(t.length!==r.length)return!1;for(r=0;r<t.length;r++){var o=t[r];if(!gS.call(n,o)||!Ur(e[o],n[o]))return!1}return!0}function hP(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function fP(e,n){var t=hP(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=hP(t)}}function $T(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?$T(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function MT(){for(var e=window,n=Of();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=Of(e.document)}return n}function ix(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 HU(e){var n=MT(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&$T(t.ownerDocument.documentElement,t)){if(r!==null&&ix(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,i=Math.min(r.start,o);r=r.end===void 0?i:Math.min(r.end,o),!e.extend&&i>r&&(o=r,r=i,i=o),o=fP(t,i);var s=fP(t,r);o&&s&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==s.node||e.focusOffset!==s.offset)&&(n=n.createRange(),n.setStart(o.node,o.offset),e.removeAllRanges(),i>r?(e.addRange(n),e.extend(s.node,s.offset)):(n.setEnd(s.node,s.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 KU=Wo&&"documentMode"in document&&11>=document.documentMode,Ia=null,OS=null,Tl=null,DS=!1;function pP(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;DS||Ia==null||Ia!==Of(r)||(r=Ia,"selectionStart"in r&&ix(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}),Tl&&Ql(Tl,r)||(Tl=r,r=Bf(OS,"onSelect"),0<r.length&&(n=new nx("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=Ia)))}function bd(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var Ea={animationend:bd("Animation","AnimationEnd"),animationiteration:bd("Animation","AnimationIteration"),animationstart:bd("Animation","AnimationStart"),transitionend:bd("Transition","TransitionEnd")},km={},AT={};Wo&&(AT=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 Dp(e){if(km[e])return km[e];if(!Ea[e])return e;var n=Ea[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in AT)return km[e]=n[t];return e}var jT=Dp("animationend"),OT=Dp("animationiteration"),DT=Dp("animationstart"),RT=Dp("transitionend"),LT=new Map,gP="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 Xi(e,n){LT.set(e,n),Vs(n,[e])}for(var Tm=0;Tm<gP.length;Tm++){var $m=gP[Tm],WU=$m.toLowerCase(),GU=$m[0].toUpperCase()+$m.slice(1);Xi(WU,"on"+GU)}Xi(jT,"onAnimationEnd");Xi(OT,"onAnimationIteration");Xi(DT,"onAnimationStart");Xi("dblclick","onDoubleClick");Xi("focusin","onFocus");Xi("focusout","onBlur");Xi(RT,"onTransitionEnd");oc("onMouseEnter",["mouseout","mouseover"]);oc("onMouseLeave",["mouseout","mouseover"]);oc("onPointerEnter",["pointerout","pointerover"]);oc("onPointerLeave",["pointerout","pointerover"]);Vs("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Vs("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Vs("onBeforeInput",["compositionend","keypress","textInput","paste"]);Vs("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Vs("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Vs("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var yl="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(" "),VU=new Set("cancel close invalid load scroll toggle".split(" ").concat(yl));function mP(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,W9(r,n,void 0,e),e.currentTarget=null}function FT(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 i=void 0;if(n)for(var s=r.length-1;0<=s;s--){var a=r[s],c=a.instance,l=a.currentTarget;if(a=a.listener,c!==i&&o.isPropagationStopped())break e;mP(o,a,l),i=c}else for(s=0;s<r.length;s++){if(a=r[s],c=a.instance,l=a.currentTarget,a=a.listener,c!==i&&o.isPropagationStopped())break e;mP(o,a,l),i=c}}}if(Rf)throw e=$S,Rf=!1,$S=null,e}function Je(e,n){var t=n[zS];t===void 0&&(t=n[zS]=new Set);var r=e+"__bubble";t.has(r)||(NT(n,e,2,!1),t.add(r))}function Mm(e,n,t){var r=0;n&&(r|=4),NT(t,e,r,n)}var Pd="_reactListening"+Math.random().toString(36).slice(2);function Jl(e){if(!e[Pd]){e[Pd]=!0,Gk.forEach(function(t){t!=="selectionchange"&&(VU.has(t)||Mm(t,!1,e),Mm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[Pd]||(n[Pd]=!0,Mm("selectionchange",!1,n))}}function NT(e,n,t,r){switch(bT(n)){case 1:var o=aU;break;case 4:o=cU;break;default:o=ex}t=o.bind(null,n,t,e),o=void 0,!TS||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 Am(e,n,t,r,o){var i=r;if(!(n&1)&&!(n&2)&&r!==null)e:for(;;){if(r===null)return;var s=r.tag;if(s===3||s===4){var a=r.stateNode.containerInfo;if(a===o||a.nodeType===8&&a.parentNode===o)break;if(s===4)for(s=r.return;s!==null;){var c=s.tag;if((c===3||c===4)&&(c=s.stateNode.containerInfo,c===o||c.nodeType===8&&c.parentNode===o))return;s=s.return}for(;a!==null;){if(s=ps(a),s===null)return;if(c=s.tag,c===5||c===6){r=i=s;continue e}a=a.parentNode}}r=r.return}cT(function(){var l=i,u=q0(t),d=[];e:{var f=LT.get(e);if(f!==void 0){var p=nx,S=e;switch(e){case"keypress":if(gh(t)===0)break e;case"keydown":case"keyup":p=PU;break;case"focusin":S="focus",p=Im;break;case"focusout":S="blur",p=Im;break;case"beforeblur":case"afterblur":p=Im;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=oP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=dU;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=EU;break;case jT:case OT:case DT:p=pU;break;case RT:p=kU;break;case"scroll":p=lU;break;case"wheel":p=$U;break;case"copy":case"cut":case"paste":p=mU;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=sP}var m=(n&4)!==0,w=!m&&e==="scroll",y=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,y!==null&&(E=Vl(v,y),E!=null&&m.push(eu(v,E,P)))),w)break;v=v.return}0<m.length&&(f=new p(f,S,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!==_S&&(S=t.relatedTarget||t.fromElement)&&(ps(S)||S[Go]))break e;if((p||f)&&(f=u.window===u?u:(f=u.ownerDocument)?f.defaultView||f.parentWindow:window,p?(S=t.relatedTarget||t.toElement,p=l,S=S?ps(S):null,S!==null&&(w=Ys(S),S!==w||S.tag!==5&&S.tag!==6)&&(S=null)):(p=null,S=l),p!==S)){if(m=oP,E="onMouseLeave",y="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(m=sP,E="onPointerLeave",y="onPointerEnter",v="pointer"),w=p==null?f:_a(p),P=S==null?f:_a(S),f=new m(E,v+"leave",p,t,u),f.target=w,f.relatedTarget=P,E=null,ps(u)===l&&(m=new m(y,v+"enter",S,t,u),m.target=P,m.relatedTarget=w,E=m),w=E,p&&S)t:{for(m=p,y=S,v=0,P=m;P;P=aa(P))v++;for(P=0,E=y;E;E=aa(E))P++;for(;0<v-P;)m=aa(m),v--;for(;0<P-v;)y=aa(y),P--;for(;v--;){if(m===y||y!==null&&m===y.alternate)break t;m=aa(m),y=aa(y)}m=null}else m=null;p!==null&&yP(d,f,p,m,!1),S!==null&&w!==null&&yP(d,w,S,m,!0)}}e:{if(f=l?_a(l):window,p=f.nodeName&&f.nodeName.toLowerCase(),p==="select"||p==="input"&&f.type==="file")var C=LU;else if(lP(f))if(kT)C=BU;else{C=NU;var I=FU}else(p=f.nodeName)&&p.toLowerCase()==="input"&&(f.type==="checkbox"||f.type==="radio")&&(C=zU);if(C&&(C=C(e,l))){_T(d,C,t,u);break e}I&&I(e,f,l),e==="focusout"&&(I=f._wrapperState)&&I.controlled&&f.type==="number"&&bS(f,"number",f.value)}switch(I=l?_a(l):window,e){case"focusin":(lP(I)||I.contentEditable==="true")&&(Ia=I,OS=l,Tl=null);break;case"focusout":Tl=OS=Ia=null;break;case"mousedown":DS=!0;break;case"contextmenu":case"mouseup":case"dragend":DS=!1,pP(d,t,u);break;case"selectionchange":if(KU)break;case"keydown":case"keyup":pP(d,t,u)}var _;if(ox)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?IT(e,t)&&(k="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(k="onCompositionStart");k&&(CT&&t.locale!=="ko"&&(Ca||k!=="onCompositionStart"?k==="onCompositionEnd"&&Ca&&(_=PT()):(bi=u,tx="value"in bi?bi.value:bi.textContent,Ca=!0)),I=Bf(l,k),0<I.length&&(k=new iP(k,e,null,t,u),d.push({event:k,listeners:I}),_?k.data=_:(_=ET(t),_!==null&&(k.data=_)))),(_=AU?jU(e,t):OU(e,t))&&(l=Bf(l,"onBeforeInput"),0<l.length&&(u=new iP("onBeforeInput","beforeinput",null,t,u),d.push({event:u,listeners:l}),u.data=_))}FT(d,n)})}function eu(e,n,t){return{instance:e,listener:n,currentTarget:t}}function Bf(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,i=o.stateNode;o.tag===5&&i!==null&&(o=i,i=Vl(e,t),i!=null&&r.unshift(eu(e,i,o)),i=Vl(e,n),i!=null&&r.push(eu(e,i,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 yP(e,n,t,r,o){for(var i=n._reactName,s=[];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=Vl(t,i),c!=null&&s.unshift(eu(t,c,a))):o||(c=Vl(t,i),c!=null&&s.push(eu(t,c,a)))),t=t.return}s.length!==0&&e.push({event:n,listeners:s})}var YU=/\r\n?/g,XU=/\u0000|\uFFFD/g;function SP(e){return(typeof e=="string"?e:""+e).replace(YU,`
83
- `).replace(XU,"")}function Cd(e,n,t){if(n=SP(n),SP(e)!==n&&t)throw Error(q(425))}function Uf(){}var RS=null,LS=null;function FS(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 NS=typeof setTimeout=="function"?setTimeout:void 0,qU=typeof clearTimeout=="function"?clearTimeout:void 0,vP=typeof Promise=="function"?Promise:void 0,ZU=typeof queueMicrotask=="function"?queueMicrotask:typeof vP<"u"?function(e){return vP.resolve(null).then(e).catch(QU)}:NS;function QU(e){setTimeout(function(){throw e})}function jm(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 Mi(e){for(;e!=null;e=e.nextSibling){var n=e.nodeType;if(n===1||n===3)break;if(n===8){if(n=e.data,n==="$"||n==="$!"||n==="$?")break;if(n==="/$")return null}}return e}function xP(e){e=e.previousSibling;for(var n=0;e;){if(e.nodeType===8){var t=e.data;if(t==="$"||t==="$!"||t==="$?"){if(n===0)return e;n--}else t==="/$"&&n++}e=e.previousSibling}return null}var _c=Math.random().toString(36).slice(2),eo="__reactFiber$"+_c,tu="__reactProps$"+_c,Go="__reactContainer$"+_c,zS="__reactEvents$"+_c,JU="__reactListeners$"+_c,eH="__reactHandles$"+_c;function ps(e){var n=e[eo];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Go]||t[eo]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=xP(e);e!==null;){if(t=e[eo])return t;e=xP(e)}return n}e=t,t=e.parentNode}return null}function Lu(e){return e=e[eo]||e[Go],!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 Rp(e){return e[tu]||null}var BS=[],ka=-1;function qi(e){return{current:e}}function tt(e){0>ka||(e.current=BS[ka],BS[ka]=null,ka--)}function Ye(e,n){ka++,BS[ka]=e.current,e.current=n}var Ni={},an=qi(Ni),jn=qi(!1),$s=Ni;function ic(e,n){var t=e.type.contextTypes;if(!t)return Ni;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var o={},i;for(i in t)o[i]=n[i];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=o),o}function On(e){return e=e.childContextTypes,e!=null}function Hf(){tt(jn),tt(an)}function wP(e,n,t){if(an.current!==Ni)throw Error(q(168));Ye(an,n),Ye(jn,t)}function zT(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,F9(e)||"Unknown",o));return ft({},t,r)}function Kf(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ni,$s=an.current,Ye(an,e),Ye(jn,jn.current),!0}function bP(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=zT(e,n,$s),r.__reactInternalMemoizedMergedChildContext=e,tt(jn),tt(an),Ye(an,e)):tt(jn),Ye(jn,t)}var Oo=null,Lp=!1,Om=!1;function BT(e){Oo===null?Oo=[e]:Oo.push(e)}function tH(e){Lp=!0,BT(e)}function Zi(){if(!Om&&Oo!==null){Om=!0;var e=0,n=Ne;try{var t=Oo;for(Ne=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}Oo=null,Lp=!1}catch(o){throw Oo!==null&&(Oo=Oo.slice(e+1)),hT(Z0,Zi),o}finally{Ne=n,Om=!1}}return null}var Ta=[],$a=0,Wf=null,Gf=0,yr=[],Sr=0,Ms=null,Ro=1,Lo="";function us(e,n){Ta[$a++]=Gf,Ta[$a++]=Wf,Wf=e,Gf=n}function UT(e,n,t){yr[Sr++]=Ro,yr[Sr++]=Lo,yr[Sr++]=Ms,Ms=e;var r=Ro;e=Lo;var o=32-Lr(r)-1;r&=~(1<<o),t+=1;var i=32-Lr(n)+o;if(30<i){var s=o-o%5;i=(r&(1<<s)-1).toString(32),r>>=s,o-=s,Ro=1<<32-Lr(n)+o|t<<o|r,Lo=i+e}else Ro=1<<i|t<<o|r,Lo=e}function sx(e){e.return!==null&&(us(e,1),UT(e,1,0))}function ax(e){for(;e===Wf;)Wf=Ta[--$a],Ta[$a]=null,Gf=Ta[--$a],Ta[$a]=null;for(;e===Ms;)Ms=yr[--Sr],yr[Sr]=null,Lo=yr[--Sr],yr[Sr]=null,Ro=yr[--Sr],yr[Sr]=null}var er=null,qn=null,rt=!1,Dr=null;function HT(e,n){var t=vr(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 PP(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,er=e,qn=Mi(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,er=e,qn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=Ms!==null?{id:Ro,overflow:Lo}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=vr(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,er=e,qn=null,!0):!1;default:return!1}}function US(e){return(e.mode&1)!==0&&(e.flags&128)===0}function HS(e){if(rt){var n=qn;if(n){var t=n;if(!PP(e,n)){if(US(e))throw Error(q(418));n=Mi(t.nextSibling);var r=er;n&&PP(e,n)?HT(r,t):(e.flags=e.flags&-4097|2,rt=!1,er=e)}}else{if(US(e))throw Error(q(418));e.flags=e.flags&-4097|2,rt=!1,er=e}}}function CP(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;er=e}function Id(e){if(e!==er)return!1;if(!rt)return CP(e),rt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!FS(e.type,e.memoizedProps)),n&&(n=qn)){if(US(e))throw KT(),Error(q(418));for(;n;)HT(e,n),n=Mi(n.nextSibling)}if(CP(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){qn=Mi(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}qn=null}}else qn=er?Mi(e.stateNode.nextSibling):null;return!0}function KT(){for(var e=qn;e;)e=Mi(e.nextSibling)}function sc(){qn=er=null,rt=!1}function cx(e){Dr===null?Dr=[e]:Dr.push(e)}var nH=ti.ReactCurrentBatchConfig;function Qc(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,i=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===i?n.ref:(n=function(s){var a=o.refs;s===null?delete a[i]:a[i]=s},n._stringRef=i,n)}if(typeof e!="string")throw Error(q(284));if(!t._owner)throw Error(q(290,e))}return e}function Ed(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function IP(e){var n=e._init;return n(e._payload)}function WT(e){function n(y,v){if(e){var P=y.deletions;P===null?(y.deletions=[v],y.flags|=16):P.push(v)}}function t(y,v){if(!e)return null;for(;v!==null;)n(y,v),v=v.sibling;return null}function r(y,v){for(y=new Map;v!==null;)v.key!==null?y.set(v.key,v):y.set(v.index,v),v=v.sibling;return y}function o(y,v){return y=Di(y,v),y.index=0,y.sibling=null,y}function i(y,v,P){return y.index=P,e?(P=y.alternate,P!==null?(P=P.index,P<v?(y.flags|=2,v):P):(y.flags|=2,v)):(y.flags|=1048576,v)}function s(y){return e&&y.alternate===null&&(y.flags|=2),y}function a(y,v,P,E){return v===null||v.tag!==6?(v=Bm(P,y.mode,E),v.return=y,v):(v=o(v,P),v.return=y,v)}function c(y,v,P,E){var C=P.type;return C===Pa?u(y,v,P.props.children,E,P.key):v!==null&&(v.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===mi&&IP(C)===v.type)?(E=o(v,P.props),E.ref=Qc(y,v,P),E.return=y,E):(E=bh(P.type,P.key,P.props,null,y.mode,E),E.ref=Qc(y,v,P),E.return=y,E)}function l(y,v,P,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==P.containerInfo||v.stateNode.implementation!==P.implementation?(v=Um(P,y.mode,E),v.return=y,v):(v=o(v,P.children||[]),v.return=y,v)}function u(y,v,P,E,C){return v===null||v.tag!==7?(v=Ps(P,y.mode,E,C),v.return=y,v):(v=o(v,P),v.return=y,v)}function d(y,v,P){if(typeof v=="string"&&v!==""||typeof v=="number")return v=Bm(""+v,y.mode,P),v.return=y,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case gd:return P=bh(v.type,v.key,v.props,null,y.mode,P),P.ref=Qc(y,null,v),P.return=y,P;case ba:return v=Um(v,y.mode,P),v.return=y,v;case mi:var E=v._init;return d(y,E(v._payload),P)}if(gl(v)||Vc(v))return v=Ps(v,y.mode,P,null),v.return=y,v;Ed(y,v)}return null}function f(y,v,P,E){var C=v!==null?v.key:null;if(typeof P=="string"&&P!==""||typeof P=="number")return C!==null?null:a(y,v,""+P,E);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case gd:return P.key===C?c(y,v,P,E):null;case ba:return P.key===C?l(y,v,P,E):null;case mi:return C=P._init,f(y,v,C(P._payload),E)}if(gl(P)||Vc(P))return C!==null?null:u(y,v,P,E,null);Ed(y,P)}return null}function p(y,v,P,E,C){if(typeof E=="string"&&E!==""||typeof E=="number")return y=y.get(P)||null,a(v,y,""+E,C);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case gd:return y=y.get(E.key===null?P:E.key)||null,c(v,y,E,C);case ba:return y=y.get(E.key===null?P:E.key)||null,l(v,y,E,C);case mi:var I=E._init;return p(y,v,P,I(E._payload),C)}if(gl(E)||Vc(E))return y=y.get(P)||null,u(v,y,E,C,null);Ed(v,E)}return null}function S(y,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(y,_,P[k],E);if(T===null){_===null&&(_=$);break}e&&_&&T.alternate===null&&n(y,_),v=i(T,v,k),I===null?C=T:I.sibling=T,I=T,_=$}if(k===P.length)return t(y,_),rt&&us(y,k),C;if(_===null){for(;k<P.length;k++)_=d(y,P[k],E),_!==null&&(v=i(_,v,k),I===null?C=_:I.sibling=_,I=_);return rt&&us(y,k),C}for(_=r(y,_);k<P.length;k++)$=p(_,y,k,P[k],E),$!==null&&(e&&$.alternate!==null&&_.delete($.key===null?k:$.key),v=i($,v,k),I===null?C=$:I.sibling=$,I=$);return e&&_.forEach(function(A){return n(y,A)}),rt&&us(y,k),C}function m(y,v,P,E){var C=Vc(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 A=f(y,_,T.value,E);if(A===null){_===null&&(_=$);break}e&&_&&A.alternate===null&&n(y,_),v=i(A,v,k),I===null?C=A:I.sibling=A,I=A,_=$}if(T.done)return t(y,_),rt&&us(y,k),C;if(_===null){for(;!T.done;k++,T=P.next())T=d(y,T.value,E),T!==null&&(v=i(T,v,k),I===null?C=T:I.sibling=T,I=T);return rt&&us(y,k),C}for(_=r(y,_);!T.done;k++,T=P.next())T=p(_,y,k,T.value,E),T!==null&&(e&&T.alternate!==null&&_.delete(T.key===null?k:T.key),v=i(T,v,k),I===null?C=T:I.sibling=T,I=T);return e&&_.forEach(function(N){return n(y,N)}),rt&&us(y,k),C}function w(y,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 gd: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(y,I.sibling),v=o(I,P.props.children),v.return=y,y=v;break e}}else if(I.elementType===C||typeof C=="object"&&C!==null&&C.$$typeof===mi&&IP(C)===I.type){t(y,I.sibling),v=o(I,P.props),v.ref=Qc(y,I,P),v.return=y,y=v;break e}t(y,I);break}else n(y,I);I=I.sibling}P.type===Pa?(v=Ps(P.props.children,y.mode,E,P.key),v.return=y,y=v):(E=bh(P.type,P.key,P.props,null,y.mode,E),E.ref=Qc(y,v,P),E.return=y,y=E)}return s(y);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(y,v.sibling),v=o(v,P.children||[]),v.return=y,y=v;break e}else{t(y,v);break}else n(y,v);v=v.sibling}v=Um(P,y.mode,E),v.return=y,y=v}return s(y);case mi:return I=P._init,w(y,v,I(P._payload),E)}if(gl(P))return S(y,v,P,E);if(Vc(P))return m(y,v,P,E);Ed(y,P)}return typeof P=="string"&&P!==""||typeof P=="number"?(P=""+P,v!==null&&v.tag===6?(t(y,v.sibling),v=o(v,P),v.return=y,y=v):(t(y,v),v=Bm(P,y.mode,E),v.return=y,y=v),s(y)):t(y,v)}return w}var ac=WT(!0),GT=WT(!1),Vf=qi(null),Yf=null,Ma=null,lx=null;function ux(){lx=Ma=Yf=null}function dx(e){var n=Vf.current;tt(Vf),e._currentValue=n}function KS(e,n,t){for(;e!==null;){var r=e.alternate;if((e.childLanes&n)!==n?(e.childLanes|=n,r!==null&&(r.childLanes|=n)):r!==null&&(r.childLanes&n)!==n&&(r.childLanes|=n),e===t)break;e=e.return}}function Ya(e,n){Yf=e,lx=Ma=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(Tn=!0),e.firstContext=null)}function br(e){var n=e._currentValue;if(lx!==e)if(e={context:e,memoizedValue:n,next:null},Ma===null){if(Yf===null)throw Error(q(308));Ma=e,Yf.dependencies={lanes:0,firstContext:e}}else Ma=Ma.next=e;return n}var gs=null;function hx(e){gs===null?gs=[e]:gs.push(e)}function VT(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,hx(n)):(t.next=o.next,o.next=t),n.interleaved=t,Vo(e,r)}function Vo(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 yi=!1;function fx(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function YT(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 zo(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Ai(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,Vo(e,t)}return o=r.interleaved,o===null?(n.next=n,hx(r)):(n.next=o.next,o.next=n),r.interleaved=n,Vo(e,t)}function mh(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,Q0(e,t)}}function EP(e,n){var t=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,t===r)){var o=null,i=null;if(t=t.firstBaseUpdate,t!==null){do{var s={eventTime:t.eventTime,lane:t.lane,tag:t.tag,payload:t.payload,callback:t.callback,next:null};i===null?o=i=s:i=i.next=s,t=t.next}while(t!==null);i===null?o=i=n:i=i.next=n}else o=i=n;t={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:i,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 Xf(e,n,t,r){var o=e.updateQueue;yi=!1;var i=o.firstBaseUpdate,s=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var c=a,l=c.next;c.next=null,s===null?i=l:s.next=l,s=c;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==s&&(a===null?u.firstBaseUpdate=l:a.next=l,u.lastBaseUpdate=c))}if(i!==null){var d=o.baseState;s=0,u=l=c=null,a=i;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 S=e,m=a;switch(f=n,p=t,m.tag){case 1:if(S=m.payload,typeof S=="function"){d=S.call(p,d,f);break e}d=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=m.payload,f=typeof S=="function"?S.call(p,d,f):S,f==null)break e;d=ft({},d,f);break e;case 2:yi=!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,s|=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 s|=o.lane,o=o.next;while(o!==n)}else i===null&&(o.shared.lanes=0);js|=s,e.lanes=s,e.memoizedState=d}}function _P(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 Fu={},co=qi(Fu),nu=qi(Fu),ru=qi(Fu);function ms(e){if(e===Fu)throw Error(q(174));return e}function px(e,n){switch(Ye(ru,n),Ye(nu,e),Ye(co,Fu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:CS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=CS(n,e)}tt(co),Ye(co,n)}function cc(){tt(co),tt(nu),tt(ru)}function XT(e){ms(ru.current);var n=ms(co.current),t=CS(n,e.type);n!==t&&(Ye(nu,e),Ye(co,t))}function gx(e){nu.current===e&&(tt(co),tt(nu))}var lt=qi(0);function qf(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 Dm=[];function mx(){for(var e=0;e<Dm.length;e++)Dm[e]._workInProgressVersionPrimary=null;Dm.length=0}var yh=ti.ReactCurrentDispatcher,Rm=ti.ReactCurrentBatchConfig,As=0,ht=null,Et=null,$t=null,Zf=!1,$l=!1,ou=0,rH=0;function Yt(){throw Error(q(321))}function yx(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Ur(e[t],n[t]))return!1;return!0}function Sx(e,n,t,r,o,i){if(As=i,ht=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,yh.current=e===null||e.memoizedState===null?aH:cH,e=t(r,o),$l){i=0;do{if($l=!1,ou=0,25<=i)throw Error(q(301));i+=1,$t=Et=null,n.updateQueue=null,yh.current=lH,e=t(r,o)}while($l)}if(yh.current=Qf,n=Et!==null&&Et.next!==null,As=0,$t=Et=ht=null,Zf=!1,n)throw Error(q(300));return e}function vx(){var e=ou!==0;return ou=0,e}function qr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return $t===null?ht.memoizedState=$t=e:$t=$t.next=e,$t}function Pr(){if(Et===null){var e=ht.alternate;e=e!==null?e.memoizedState:null}else e=Et.next;var n=$t===null?ht.memoizedState:$t.next;if(n!==null)$t=n,Et=e;else{if(e===null)throw Error(q(310));Et=e,e={memoizedState:Et.memoizedState,baseState:Et.baseState,baseQueue:Et.baseQueue,queue:Et.queue,next:null},$t===null?ht.memoizedState=$t=e:$t=$t.next=e}return $t}function iu(e,n){return typeof n=="function"?n(e):n}function Lm(e){var n=Pr(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=Et,o=r.baseQueue,i=t.pending;if(i!==null){if(o!==null){var s=o.next;o.next=i.next,i.next=s}r.baseQueue=o=i,t.pending=null}if(o!==null){i=o.next,r=r.baseState;var a=s=null,c=null,l=i;do{var u=l.lane;if((As&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,s=r):c=c.next=d,ht.lanes|=u,js|=u}l=l.next}while(l!==null&&l!==i);c===null?s=r:c.next=a,Ur(r,n.memoizedState)||(Tn=!0),n.memoizedState=r,n.baseState=s,n.baseQueue=c,t.lastRenderedState=r}if(e=t.interleaved,e!==null){o=e;do i=o.lane,ht.lanes|=i,js|=i,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function Fm(e){var n=Pr(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=t.dispatch,o=t.pending,i=n.memoizedState;if(o!==null){t.pending=null;var s=o=o.next;do i=e(i,s.action),s=s.next;while(s!==o);Ur(i,n.memoizedState)||(Tn=!0),n.memoizedState=i,n.baseQueue===null&&(n.baseState=i),t.lastRenderedState=i}return[i,r]}function qT(){}function ZT(e,n){var t=ht,r=Pr(),o=n(),i=!Ur(r.memoizedState,o);if(i&&(r.memoizedState=o,Tn=!0),r=r.queue,xx(e2.bind(null,t,r,e),[e]),r.getSnapshot!==n||i||$t!==null&&$t.memoizedState.tag&1){if(t.flags|=2048,su(9,JT.bind(null,t,r,o,n),void 0,null),At===null)throw Error(q(349));As&30||QT(t,n,o)}return o}function QT(e,n,t){e.flags|=16384,e={getSnapshot:n,value:t},n=ht.updateQueue,n===null?(n={lastEffect:null,stores:null},ht.updateQueue=n,n.stores=[e]):(t=n.stores,t===null?n.stores=[e]:t.push(e))}function JT(e,n,t,r){n.value=t,n.getSnapshot=r,t2(n)&&n2(e)}function e2(e,n,t){return t(function(){t2(n)&&n2(e)})}function t2(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Ur(e,t)}catch{return!0}}function n2(e){var n=Vo(e,1);n!==null&&Fr(n,e,1,-1)}function kP(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:iu,lastRenderedState:e},n.queue=e,e=e.dispatch=sH.bind(null,ht,e),[n.memoizedState,e]}function su(e,n,t,r){return e={tag:e,create:n,destroy:t,deps:r,next:null},n=ht.updateQueue,n===null?(n={lastEffect:null,stores:null},ht.updateQueue=n,n.lastEffect=e.next=e):(t=n.lastEffect,t===null?n.lastEffect=e.next=e:(r=t.next,t.next=e,e.next=r,n.lastEffect=e)),e}function r2(){return Pr().memoizedState}function Sh(e,n,t,r){var o=qr();ht.flags|=e,o.memoizedState=su(1|n,t,void 0,r===void 0?null:r)}function Fp(e,n,t,r){var o=Pr();r=r===void 0?null:r;var i=void 0;if(Et!==null){var s=Et.memoizedState;if(i=s.destroy,r!==null&&yx(r,s.deps)){o.memoizedState=su(n,t,i,r);return}}ht.flags|=e,o.memoizedState=su(1|n,t,i,r)}function TP(e,n){return Sh(8390656,8,e,n)}function xx(e,n){return Fp(2048,8,e,n)}function o2(e,n){return Fp(4,2,e,n)}function i2(e,n){return Fp(4,4,e,n)}function s2(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 a2(e,n,t){return t=t!=null?t.concat([e]):null,Fp(4,4,s2.bind(null,n,e),t)}function wx(){}function c2(e,n){var t=Pr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&yx(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function l2(e,n){var t=Pr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&yx(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function u2(e,n,t){return As&21?(Ur(t,n)||(t=gT(),ht.lanes|=t,js|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,Tn=!0),e.memoizedState=t)}function oH(e,n){var t=Ne;Ne=t!==0&&4>t?t:4,e(!0);var r=Rm.transition;Rm.transition={};try{e(!1),n()}finally{Ne=t,Rm.transition=r}}function d2(){return Pr().memoizedState}function iH(e,n,t){var r=Oi(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},h2(e))f2(n,t);else if(t=VT(e,n,t,r),t!==null){var o=pn();Fr(t,e,r,o),p2(t,n,r)}}function sH(e,n,t){var r=Oi(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(h2(e))f2(n,o);else{var i=e.alternate;if(e.lanes===0&&(i===null||i.lanes===0)&&(i=n.lastRenderedReducer,i!==null))try{var s=n.lastRenderedState,a=i(s,t);if(o.hasEagerState=!0,o.eagerState=a,Ur(a,s)){var c=n.interleaved;c===null?(o.next=o,hx(n)):(o.next=c.next,c.next=o),n.interleaved=o;return}}catch{}finally{}t=VT(e,n,o,r),t!==null&&(o=pn(),Fr(t,e,r,o),p2(t,n,r))}}function h2(e){var n=e.alternate;return e===ht||n!==null&&n===ht}function f2(e,n){$l=Zf=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function p2(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,Q0(e,t)}}var Qf={readContext:br,useCallback:Yt,useContext:Yt,useEffect:Yt,useImperativeHandle:Yt,useInsertionEffect:Yt,useLayoutEffect:Yt,useMemo:Yt,useReducer:Yt,useRef:Yt,useState:Yt,useDebugValue:Yt,useDeferredValue:Yt,useTransition:Yt,useMutableSource:Yt,useSyncExternalStore:Yt,useId:Yt,unstable_isNewReconciler:!1},aH={readContext:br,useCallback:function(e,n){return qr().memoizedState=[e,n===void 0?null:n],e},useContext:br,useEffect:TP,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,Sh(4194308,4,s2.bind(null,n,e),t)},useLayoutEffect:function(e,n){return Sh(4194308,4,e,n)},useInsertionEffect:function(e,n){return Sh(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=iH.bind(null,ht,e),[r.memoizedState,e]},useRef:function(e){var n=qr();return e={current:e},n.memoizedState=e},useState:kP,useDebugValue:wx,useDeferredValue:function(e){return qr().memoizedState=e},useTransition:function(){var e=kP(!1),n=e[0];return e=oH.bind(null,e[1]),qr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=ht,o=qr();if(rt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),At===null)throw Error(q(349));As&30||QT(r,n,t)}o.memoizedState=t;var i={value:t,getSnapshot:n};return o.queue=i,TP(e2.bind(null,r,i,e),[e]),r.flags|=2048,su(9,JT.bind(null,r,i,t,n),void 0,null),t},useId:function(){var e=qr(),n=At.identifierPrefix;if(rt){var t=Lo,r=Ro;t=(r&~(1<<32-Lr(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=ou++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=rH++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},cH={readContext:br,useCallback:c2,useContext:br,useEffect:xx,useImperativeHandle:a2,useInsertionEffect:o2,useLayoutEffect:i2,useMemo:l2,useReducer:Lm,useRef:r2,useState:function(){return Lm(iu)},useDebugValue:wx,useDeferredValue:function(e){var n=Pr();return u2(n,Et.memoizedState,e)},useTransition:function(){var e=Lm(iu)[0],n=Pr().memoizedState;return[e,n]},useMutableSource:qT,useSyncExternalStore:ZT,useId:d2,unstable_isNewReconciler:!1},lH={readContext:br,useCallback:c2,useContext:br,useEffect:xx,useImperativeHandle:a2,useInsertionEffect:o2,useLayoutEffect:i2,useMemo:l2,useReducer:Fm,useRef:r2,useState:function(){return Fm(iu)},useDebugValue:wx,useDeferredValue:function(e){var n=Pr();return Et===null?n.memoizedState=e:u2(n,Et.memoizedState,e)},useTransition:function(){var e=Fm(iu)[0],n=Pr().memoizedState;return[e,n]},useMutableSource:qT,useSyncExternalStore:ZT,useId:d2,unstable_isNewReconciler:!1};function $r(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 WS(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 Np={isMounted:function(e){return(e=e._reactInternals)?Ys(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=pn(),o=Oi(e),i=zo(r,o);i.payload=n,t!=null&&(i.callback=t),n=Ai(e,i,o),n!==null&&(Fr(n,e,o,r),mh(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=pn(),o=Oi(e),i=zo(r,o);i.tag=1,i.payload=n,t!=null&&(i.callback=t),n=Ai(e,i,o),n!==null&&(Fr(n,e,o,r),mh(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=pn(),r=Oi(e),o=zo(t,r);o.tag=2,n!=null&&(o.callback=n),n=Ai(e,o,r),n!==null&&(Fr(n,e,r,t),mh(n,e,r))}};function $P(e,n,t,r,o,i,s){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,i,s):n.prototype&&n.prototype.isPureReactComponent?!Ql(t,r)||!Ql(o,i):!0}function g2(e,n,t){var r=!1,o=Ni,i=n.contextType;return typeof i=="object"&&i!==null?i=br(i):(o=On(n)?$s:an.current,r=n.contextTypes,i=(r=r!=null)?ic(e,o):Ni),n=new n(t,i),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Np,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=i),n}function MP(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&&Np.enqueueReplaceState(n,n.state,null)}function GS(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs={},fx(e);var i=n.contextType;typeof i=="object"&&i!==null?o.context=br(i):(i=On(n)?$s:an.current,o.context=ic(e,i)),o.state=e.memoizedState,i=n.getDerivedStateFromProps,typeof i=="function"&&(WS(e,n,i,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&&Np.enqueueReplaceState(o,o.state,null),Xf(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function lc(e,n){try{var t="",r=n;do t+=L9(r),r=r.return;while(r);var o=t}catch(i){o=`
84
- Error generating stack: `+i.message+`
85
- `+i.stack}return{value:e,source:n,stack:o,digest:null}}function Nm(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function VS(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var uH=typeof WeakMap=="function"?WeakMap:Map;function m2(e,n,t){t=zo(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){ep||(ep=!0,rv=r),VS(e,n)},t}function y2(e,n,t){t=zo(-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(){VS(e,n)}}var i=e.stateNode;return i!==null&&typeof i.componentDidCatch=="function"&&(t.callback=function(){VS(e,n),typeof r!="function"&&(ji===null?ji=new Set([this]):ji.add(this));var s=n.stack;this.componentDidCatch(n.value,{componentStack:s!==null?s:""})}),t}function AP(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new uH;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=CH.bind(null,e,n,t),n.then(e,e))}function jP(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 OP(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=zo(-1,1),n.tag=2,Ai(t,n,1))),t.lanes|=1),e)}var dH=ti.ReactCurrentOwner,Tn=!1;function dn(e,n,t,r){n.child=e===null?GT(n,null,t,r):ac(n,e.child,t,r)}function DP(e,n,t,r,o){t=t.render;var i=n.ref;return Ya(n,o),r=Sx(e,n,t,r,i,o),t=vx(),e!==null&&!Tn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Yo(e,n,o)):(rt&&t&&sx(n),n.flags|=1,dn(e,n,r,o),n.child)}function RP(e,n,t,r,o){if(e===null){var i=t.type;return typeof i=="function"&&!Tx(i)&&i.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=i,S2(e,n,i,r,o)):(e=bh(t.type,null,r,n,n.mode,o),e.ref=n.ref,e.return=n,n.child=e)}if(i=e.child,!(e.lanes&o)){var s=i.memoizedProps;if(t=t.compare,t=t!==null?t:Ql,t(s,r)&&e.ref===n.ref)return Yo(e,n,o)}return n.flags|=1,e=Di(i,r),e.ref=n.ref,e.return=n,n.child=e}function S2(e,n,t,r,o){if(e!==null){var i=e.memoizedProps;if(Ql(i,r)&&e.ref===n.ref)if(Tn=!1,n.pendingProps=r=i,(e.lanes&o)!==0)e.flags&131072&&(Tn=!0);else return n.lanes=e.lanes,Yo(e,n,o)}return YS(e,n,t,r,o)}function v2(e,n,t){var r=n.pendingProps,o=r.children,i=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ye(ja,Wn),Wn|=t;else{if(!(t&1073741824))return e=i!==null?i.baseLanes|t:t,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Ye(ja,Wn),Wn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=i!==null?i.baseLanes:t,Ye(ja,Wn),Wn|=r}else i!==null?(r=i.baseLanes|t,n.memoizedState=null):r=t,Ye(ja,Wn),Wn|=r;return dn(e,n,o,t),n.child}function x2(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function YS(e,n,t,r,o){var i=On(t)?$s:an.current;return i=ic(n,i),Ya(n,o),t=Sx(e,n,t,r,i,o),r=vx(),e!==null&&!Tn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Yo(e,n,o)):(rt&&r&&sx(n),n.flags|=1,dn(e,n,t,o),n.child)}function LP(e,n,t,r,o){if(On(t)){var i=!0;Kf(n)}else i=!1;if(Ya(n,o),n.stateNode===null)vh(e,n),g2(n,t,r),GS(n,t,r,o),r=!0;else if(e===null){var s=n.stateNode,a=n.memoizedProps;s.props=a;var c=s.context,l=t.contextType;typeof l=="object"&&l!==null?l=br(l):(l=On(t)?$s:an.current,l=ic(n,l));var u=t.getDerivedStateFromProps,d=typeof u=="function"||typeof s.getSnapshotBeforeUpdate=="function";d||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(a!==r||c!==l)&&MP(n,s,r,l),yi=!1;var f=n.memoizedState;s.state=f,Xf(n,r,s,o),c=n.memoizedState,a!==r||f!==c||jn.current||yi?(typeof u=="function"&&(WS(n,t,u,r),c=n.memoizedState),(a=yi||$P(n,t,a,r,f,c,l))?(d||typeof s.UNSAFE_componentWillMount!="function"&&typeof s.componentWillMount!="function"||(typeof s.componentWillMount=="function"&&s.componentWillMount(),typeof s.UNSAFE_componentWillMount=="function"&&s.UNSAFE_componentWillMount()),typeof s.componentDidMount=="function"&&(n.flags|=4194308)):(typeof s.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),s.props=r,s.state=c,s.context=l,r=a):(typeof s.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{s=n.stateNode,YT(e,n),a=n.memoizedProps,l=n.type===n.elementType?a:$r(n.type,a),s.props=l,d=n.pendingProps,f=s.context,c=t.contextType,typeof c=="object"&&c!==null?c=br(c):(c=On(t)?$s:an.current,c=ic(n,c));var p=t.getDerivedStateFromProps;(u=typeof p=="function"||typeof s.getSnapshotBeforeUpdate=="function")||typeof s.UNSAFE_componentWillReceiveProps!="function"&&typeof s.componentWillReceiveProps!="function"||(a!==d||f!==c)&&MP(n,s,r,c),yi=!1,f=n.memoizedState,s.state=f,Xf(n,r,s,o);var S=n.memoizedState;a!==d||f!==S||jn.current||yi?(typeof p=="function"&&(WS(n,t,p,r),S=n.memoizedState),(l=yi||$P(n,t,l,r,f,S,c)||!1)?(u||typeof s.UNSAFE_componentWillUpdate!="function"&&typeof s.componentWillUpdate!="function"||(typeof s.componentWillUpdate=="function"&&s.componentWillUpdate(r,S,c),typeof s.UNSAFE_componentWillUpdate=="function"&&s.UNSAFE_componentWillUpdate(r,S,c)),typeof s.componentDidUpdate=="function"&&(n.flags|=4),typeof s.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof s.componentDidUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=S),s.props=r,s.state=S,s.context=c,r=l):(typeof s.componentDidUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof s.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),r=!1)}return XS(e,n,t,r,i,o)}function XS(e,n,t,r,o,i){x2(e,n);var s=(n.flags&128)!==0;if(!r&&!s)return o&&bP(n,t,!1),Yo(e,n,i);r=n.stateNode,dH.current=n;var a=s&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&s?(n.child=ac(n,e.child,null,i),n.child=ac(n,null,a,i)):dn(e,n,a,i),n.memoizedState=r.state,o&&bP(n,t,!0),n.child}function w2(e){var n=e.stateNode;n.pendingContext?wP(e,n.pendingContext,n.pendingContext!==n.context):n.context&&wP(e,n.context,!1),px(e,n.containerInfo)}function FP(e,n,t,r,o){return sc(),cx(o),n.flags|=256,dn(e,n,t,r),n.child}var qS={dehydrated:null,treeContext:null,retryLane:0};function ZS(e){return{baseLanes:e,cachePool:null,transitions:null}}function b2(e,n,t){var r=n.pendingProps,o=lt.current,i=!1,s=(n.flags&128)!==0,a;if((a=s)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(i=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ye(lt,o&1),e===null)return HS(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):(s=r.children,e=r.fallback,i?(r=n.mode,i=n.child,s={mode:"hidden",children:s},!(r&1)&&i!==null?(i.childLanes=0,i.pendingProps=s):i=Up(s,r,0,null),e=Ps(e,r,t,null),i.return=n,e.return=n,i.sibling=e,n.child=i,n.child.memoizedState=ZS(t),n.memoizedState=qS,e):bx(n,s));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return hH(e,n,s,r,a,o,t);if(i){i=r.fallback,s=n.mode,o=e.child,a=o.sibling;var c={mode:"hidden",children:r.children};return!(s&1)&&n.child!==o?(r=n.child,r.childLanes=0,r.pendingProps=c,n.deletions=null):(r=Di(o,c),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?i=Di(a,i):(i=Ps(i,s,t,null),i.flags|=2),i.return=n,r.return=n,r.sibling=i,n.child=r,r=i,i=n.child,s=e.child.memoizedState,s=s===null?ZS(t):{baseLanes:s.baseLanes|t,cachePool:null,transitions:s.transitions},i.memoizedState=s,i.childLanes=e.childLanes&~t,n.memoizedState=qS,r}return i=e.child,e=i.sibling,r=Di(i,{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 bx(e,n){return n=Up({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function _d(e,n,t,r){return r!==null&&cx(r),ac(n,e.child,null,t),e=bx(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function hH(e,n,t,r,o,i,s){if(t)return n.flags&256?(n.flags&=-257,r=Nm(Error(q(422))),_d(e,n,s,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(i=r.fallback,o=n.mode,r=Up({mode:"visible",children:r.children},o,0,null),i=Ps(i,o,s,null),i.flags|=2,r.return=n,i.return=n,r.sibling=i,n.child=r,n.mode&1&&ac(n,e.child,null,s),n.child.memoizedState=ZS(s),n.memoizedState=qS,i);if(!(n.mode&1))return _d(e,n,s,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var a=r.dgst;return r=a,i=Error(q(419)),r=Nm(i,r,void 0),_d(e,n,s,r)}if(a=(s&e.childLanes)!==0,Tn||a){if(r=At,r!==null){switch(s&-s){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|s)?0:o,o!==0&&o!==i.retryLane&&(i.retryLane=o,Vo(e,o),Fr(r,e,o,-1))}return kx(),r=Nm(Error(q(421))),_d(e,n,s,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=IH.bind(null,e),o._reactRetry=n,null):(e=i.treeContext,qn=Mi(o.nextSibling),er=n,rt=!0,Dr=null,e!==null&&(yr[Sr++]=Ro,yr[Sr++]=Lo,yr[Sr++]=Ms,Ro=e.id,Lo=e.overflow,Ms=n),n=bx(n,r.children),n.flags|=4096,n)}function NP(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),KS(e.return,n,t)}function zm(e,n,t,r,o){var i=e.memoizedState;i===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:t,tailMode:o}:(i.isBackwards=n,i.rendering=null,i.renderingStartTime=0,i.last=r,i.tail=t,i.tailMode=o)}function P2(e,n,t){var r=n.pendingProps,o=r.revealOrder,i=r.tail;if(dn(e,n,r.children,t),r=lt.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&&NP(e,t,n);else if(e.tag===19)NP(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(lt,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&&qf(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),zm(n,!1,o,t,i);break;case"backwards":for(t=null,o=n.child,n.child=null;o!==null;){if(e=o.alternate,e!==null&&qf(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}zm(n,!0,t,null,i);break;case"together":zm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function vh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function Yo(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),js|=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=Di(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=Di(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function fH(e,n,t){switch(n.tag){case 3:w2(n),sc();break;case 5:XT(n);break;case 1:On(n.type)&&Kf(n);break;case 4:px(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ye(Vf,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ye(lt,lt.current&1),n.flags|=128,null):t&n.child.childLanes?b2(e,n,t):(Ye(lt,lt.current&1),e=Yo(e,n,t),e!==null?e.sibling:null);Ye(lt,lt.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return P2(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ye(lt,lt.current),r)break;return null;case 22:case 23:return n.lanes=0,v2(e,n,t)}return Yo(e,n,t)}var C2,QS,I2,E2;C2=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}};QS=function(){};I2=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,ms(co.current);var i=null;switch(t){case"input":o=xS(e,o),r=xS(e,r),i=[];break;case"select":o=ft({},o,{value:void 0}),r=ft({},r,{value:void 0}),i=[];break;case"textarea":o=PS(e,o),r=PS(e,r),i=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Uf)}IS(t,r);var s;t=null;for(l in o)if(!r.hasOwnProperty(l)&&o.hasOwnProperty(l)&&o[l]!=null)if(l==="style"){var a=o[l];for(s in a)a.hasOwnProperty(s)&&(t||(t={}),t[s]="")}else l!=="dangerouslySetInnerHTML"&&l!=="children"&&l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&l!=="autoFocus"&&(Wl.hasOwnProperty(l)?i||(i=[]):(i=i||[]).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(s in a)!a.hasOwnProperty(s)||c&&c.hasOwnProperty(s)||(t||(t={}),t[s]="");for(s in c)c.hasOwnProperty(s)&&a[s]!==c[s]&&(t||(t={}),t[s]=c[s])}else t||(i||(i=[]),i.push(l,t)),t=c;else l==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,a=a?a.__html:void 0,c!=null&&a!==c&&(i=i||[]).push(l,c)):l==="children"?typeof c!="string"&&typeof c!="number"||(i=i||[]).push(l,""+c):l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&(Wl.hasOwnProperty(l)?(c!=null&&l==="onScroll"&&Je("scroll",e),i||a===c||(i=[])):(i=i||[]).push(l,c))}t&&(i=i||[]).push("style",t);var l=i;(n.updateQueue=l)&&(n.flags|=4)}};E2=function(e,n,t,r){t!==r&&(n.flags|=4)};function Jc(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 Xt(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 pH(e,n,t){var r=n.pendingProps;switch(ax(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Xt(n),null;case 1:return On(n.type)&&Hf(),Xt(n),null;case 3:return r=n.stateNode,cc(),tt(jn),tt(an),mx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Id(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Dr!==null&&(sv(Dr),Dr=null))),QS(e,n),Xt(n),null;case 5:gx(n);var o=ms(ru.current);if(t=n.type,e!==null&&n.stateNode!=null)I2(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 Xt(n),null}if(e=ms(co.current),Id(n)){r=n.stateNode,t=n.type;var i=n.memoizedProps;switch(r[eo]=n,r[tu]=i,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<yl.length;o++)Je(yl[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":Y1(r,i),Je("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!i.multiple},Je("invalid",r);break;case"textarea":q1(r,i),Je("invalid",r)}IS(t,i),o=null;for(var s in i)if(i.hasOwnProperty(s)){var a=i[s];s==="children"?typeof a=="string"?r.textContent!==a&&(i.suppressHydrationWarning!==!0&&Cd(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(i.suppressHydrationWarning!==!0&&Cd(r.textContent,a,e),o=["children",""+a]):Wl.hasOwnProperty(s)&&a!=null&&s==="onScroll"&&Je("scroll",r)}switch(t){case"input":md(r),X1(r,i,!0);break;case"textarea":md(r),Z1(r);break;case"select":case"option":break;default:typeof i.onClick=="function"&&(r.onclick=Uf)}r=o,n.updateQueue=r,r!==null&&(n.flags|=4)}else{s=o.nodeType===9?o:o.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=eT(t)),e==="http://www.w3.org/1999/xhtml"?t==="script"?(e=s.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=s.createElement(t,{is:r.is}):(e=s.createElement(t),t==="select"&&(s=e,r.multiple?s.multiple=!0:r.size&&(s.size=r.size))):e=s.createElementNS(e,t),e[eo]=n,e[tu]=r,C2(e,n,!1,!1),n.stateNode=e;e:{switch(s=ES(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<yl.length;o++)Je(yl[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":Y1(e,r),o=xS(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":q1(e,r),o=PS(e,r),Je("invalid",e);break;default:o=r}IS(t,o),a=o;for(i in a)if(a.hasOwnProperty(i)){var c=a[i];i==="style"?rT(e,c):i==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&tT(e,c)):i==="children"?typeof c=="string"?(t!=="textarea"||c!=="")&&Gl(e,c):typeof c=="number"&&Gl(e,""+c):i!=="suppressContentEditableWarning"&&i!=="suppressHydrationWarning"&&i!=="autoFocus"&&(Wl.hasOwnProperty(i)?c!=null&&i==="onScroll"&&Je("scroll",e):c!=null&&G0(e,i,c,s))}switch(t){case"input":md(e),X1(e,r,!1);break;case"textarea":md(e),Z1(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Fi(r.value));break;case"select":e.multiple=!!r.multiple,i=r.value,i!=null?Ka(e,!!r.multiple,i,!1):r.defaultValue!=null&&Ka(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Uf)}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 Xt(n),null;case 6:if(e&&n.stateNode!=null)E2(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=ms(ru.current),ms(co.current),Id(n)){if(r=n.stateNode,t=n.memoizedProps,r[eo]=n,(i=r.nodeValue!==t)&&(e=er,e!==null))switch(e.tag){case 3:Cd(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Cd(r.nodeValue,t,(e.mode&1)!==0)}i&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[eo]=n,n.stateNode=r}return Xt(n),null;case 13:if(tt(lt),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(rt&&qn!==null&&n.mode&1&&!(n.flags&128))KT(),sc(),n.flags|=98560,i=!1;else if(i=Id(n),r!==null&&r.dehydrated!==null){if(e===null){if(!i)throw Error(q(318));if(i=n.memoizedState,i=i!==null?i.dehydrated:null,!i)throw Error(q(317));i[eo]=n}else sc(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Xt(n),i=!1}else Dr!==null&&(sv(Dr),Dr=null),i=!0;if(!i)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||lt.current&1?_t===0&&(_t=3):kx())),n.updateQueue!==null&&(n.flags|=4),Xt(n),null);case 4:return cc(),QS(e,n),e===null&&Jl(n.stateNode.containerInfo),Xt(n),null;case 10:return dx(n.type._context),Xt(n),null;case 17:return On(n.type)&&Hf(),Xt(n),null;case 19:if(tt(lt),i=n.memoizedState,i===null)return Xt(n),null;if(r=(n.flags&128)!==0,s=i.rendering,s===null)if(r)Jc(i,!1);else{if(_t!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(s=qf(e),s!==null){for(n.flags|=128,Jc(i,!1),r=s.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=t,t=n.child;t!==null;)i=t,e=r,i.flags&=14680066,s=i.alternate,s===null?(i.childLanes=0,i.lanes=e,i.child=null,i.subtreeFlags=0,i.memoizedProps=null,i.memoizedState=null,i.updateQueue=null,i.dependencies=null,i.stateNode=null):(i.childLanes=s.childLanes,i.lanes=s.lanes,i.child=s.child,i.subtreeFlags=0,i.deletions=null,i.memoizedProps=s.memoizedProps,i.memoizedState=s.memoizedState,i.updateQueue=s.updateQueue,i.type=s.type,e=s.dependencies,i.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),t=t.sibling;return Ye(lt,lt.current&1|2),n.child}e=e.sibling}i.tail!==null&&Pt()>uc&&(n.flags|=128,r=!0,Jc(i,!1),n.lanes=4194304)}else{if(!r)if(e=qf(s),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),Jc(i,!0),i.tail===null&&i.tailMode==="hidden"&&!s.alternate&&!rt)return Xt(n),null}else 2*Pt()-i.renderingStartTime>uc&&t!==1073741824&&(n.flags|=128,r=!0,Jc(i,!1),n.lanes=4194304);i.isBackwards?(s.sibling=n.child,n.child=s):(t=i.last,t!==null?t.sibling=s:n.child=s,i.last=s)}return i.tail!==null?(n=i.tail,i.rendering=n,i.tail=n.sibling,i.renderingStartTime=Pt(),n.sibling=null,t=lt.current,Ye(lt,r?t&1|2:t&1),n):(Xt(n),null);case 22:case 23:return _x(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Wn&1073741824&&(Xt(n),n.subtreeFlags&6&&(n.flags|=8192)):Xt(n),null;case 24:return null;case 25:return null}throw Error(q(156,n.tag))}function gH(e,n){switch(ax(n),n.tag){case 1:return On(n.type)&&Hf(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return cc(),tt(jn),tt(an),mx(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return gx(n),null;case 13:if(tt(lt),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));sc()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return tt(lt),null;case 4:return cc(),null;case 10:return dx(n.type._context),null;case 22:case 23:return _x(),null;case 24:return null;default:return null}}var kd=!1,Jt=!1,mH=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 JS(e,n,t){try{t()}catch(r){St(e,n,r)}}var zP=!1;function yH(e,n){if(RS=Nf,e=MT(),ix(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,i=r.focusNode;r=r.focusOffset;try{t.nodeType,i.nodeType}catch{t=null;break e}var s=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=s+o),d!==i||r!==0&&d.nodeType!==3||(c=s+r),d.nodeType===3&&(s+=d.nodeValue.length),(p=d.firstChild)!==null;)f=d,d=p;for(;;){if(d===e)break t;if(f===t&&++l===o&&(a=s),f===i&&++u===r&&(c=s),(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(LS={focusedElem:e,selectionRange:t},Nf=!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 S=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var m=S.memoizedProps,w=S.memoizedState,y=n.stateNode,v=y.getSnapshotBeforeUpdate(n.elementType===n.type?m:$r(n.type,m),w);y.__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 S=zP,zP=!1,S}function Ml(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 i=o.destroy;o.destroy=void 0,i!==void 0&&JS(n,t,i)}o=o.next}while(o!==r)}}function zp(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 ev(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 _2(e){var n=e.alternate;n!==null&&(e.alternate=null,_2(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[eo],delete n[tu],delete n[zS],delete n[JU],delete n[eH])),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 k2(e){return e.tag===5||e.tag===3||e.tag===4}function BP(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||k2(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 tv(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=Uf));else if(r!==4&&(e=e.child,e!==null))for(tv(e,n,t),e=e.sibling;e!==null;)tv(e,n,t),e=e.sibling}function nv(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(nv(e,n,t),e=e.sibling;e!==null;)nv(e,n,t),e=e.sibling}var Rt=null,Ar=!1;function di(e,n,t){for(t=t.child;t!==null;)T2(e,n,t),t=t.sibling}function T2(e,n,t){if(ao&&typeof ao.onCommitFiberUnmount=="function")try{ao.onCommitFiberUnmount(Ap,t)}catch{}switch(t.tag){case 5:Jt||Aa(t,n);case 6:var r=Rt,o=Ar;Rt=null,di(e,n,t),Rt=r,Ar=o,Rt!==null&&(Ar?(e=Rt,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):Rt.removeChild(t.stateNode));break;case 18:Rt!==null&&(Ar?(e=Rt,t=t.stateNode,e.nodeType===8?jm(e.parentNode,t):e.nodeType===1&&jm(e,t),ql(e)):jm(Rt,t.stateNode));break;case 4:r=Rt,o=Ar,Rt=t.stateNode.containerInfo,Ar=!0,di(e,n,t),Rt=r,Ar=o;break;case 0:case 11:case 14:case 15:if(!Jt&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var i=o,s=i.destroy;i=i.tag,s!==void 0&&(i&2||i&4)&&JS(t,n,s),o=o.next}while(o!==r)}di(e,n,t);break;case 1:if(!Jt&&(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)}di(e,n,t);break;case 21:di(e,n,t);break;case 22:t.mode&1?(Jt=(r=Jt)||t.memoizedState!==null,di(e,n,t),Jt=r):di(e,n,t);break;default:di(e,n,t)}}function UP(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new mH),n.forEach(function(r){var o=EH.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function Tr(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var i=e,s=n,a=s;e:for(;a!==null;){switch(a.tag){case 5:Rt=a.stateNode,Ar=!1;break e;case 3:Rt=a.stateNode.containerInfo,Ar=!0;break e;case 4:Rt=a.stateNode.containerInfo,Ar=!0;break e}a=a.return}if(Rt===null)throw Error(q(160));T2(i,s,o),Rt=null,Ar=!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;)$2(n,e),n=n.sibling}function $2(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Tr(n,e),Xr(e),r&4){try{Ml(3,e,e.return),zp(3,e)}catch(m){St(e,e.return,m)}try{Ml(5,e,e.return)}catch(m){St(e,e.return,m)}}break;case 1:Tr(n,e),Xr(e),r&512&&t!==null&&Aa(t,t.return);break;case 5:if(Tr(n,e),Xr(e),r&512&&t!==null&&Aa(t,t.return),e.flags&32){var o=e.stateNode;try{Gl(o,"")}catch(m){St(e,e.return,m)}}if(r&4&&(o=e.stateNode,o!=null)){var i=e.memoizedProps,s=t!==null?t.memoizedProps:i,a=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{a==="input"&&i.type==="radio"&&i.name!=null&&Qk(o,i),ES(a,s);var l=ES(a,i);for(s=0;s<c.length;s+=2){var u=c[s],d=c[s+1];u==="style"?rT(o,d):u==="dangerouslySetInnerHTML"?tT(o,d):u==="children"?Gl(o,d):G0(o,u,d,l)}switch(a){case"input":wS(o,i);break;case"textarea":Jk(o,i);break;case"select":var f=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!i.multiple;var p=i.value;p!=null?Ka(o,!!i.multiple,p,!1):f!==!!i.multiple&&(i.defaultValue!=null?Ka(o,!!i.multiple,i.defaultValue,!0):Ka(o,!!i.multiple,i.multiple?[]:"",!1))}o[tu]=i}catch(m){St(e,e.return,m)}}break;case 6:if(Tr(n,e),Xr(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,i=e.memoizedProps;try{o.nodeValue=i}catch(m){St(e,e.return,m)}}break;case 3:if(Tr(n,e),Xr(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{ql(n.containerInfo)}catch(m){St(e,e.return,m)}break;case 4:Tr(n,e),Xr(e);break;case 13:Tr(n,e),Xr(e),o=e.child,o.flags&8192&&(i=o.memoizedState!==null,o.stateNode.isHidden=i,!i||o.alternate!==null&&o.alternate.memoizedState!==null||(Ix=Pt())),r&4&&UP(e);break;case 22:if(u=t!==null&&t.memoizedState!==null,e.mode&1?(Jt=(l=Jt)||u,Tr(n,e),Jt=l):Tr(n,e),Xr(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:Ml(4,f,f.return);break;case 1:Aa(f,f.return);var S=f.stateNode;if(typeof S.componentWillUnmount=="function"){r=f,t=f.return;try{n=r,S.props=n.memoizedProps,S.state=n.memoizedState,S.componentWillUnmount()}catch(m){St(r,t,m)}}break;case 5:Aa(f,f.return);break;case 22:if(f.memoizedState!==null){KP(d);continue}}p!==null?(p.return=f,ne=p):KP(d)}u=u.sibling}e:for(u=null,d=e;;){if(d.tag===5){if(u===null){u=d;try{o=d.stateNode,l?(i=o.style,typeof i.setProperty=="function"?i.setProperty("display","none","important"):i.display="none"):(a=d.stateNode,c=d.memoizedProps.style,s=c!=null&&c.hasOwnProperty("display")?c.display:null,a.style.display=nT("display",s))}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:Tr(n,e),Xr(e),r&4&&UP(e);break;case 21:break;default:Tr(n,e),Xr(e)}}function Xr(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(k2(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&&(Gl(o,""),r.flags&=-33);var i=BP(e);nv(e,i,o);break;case 3:case 4:var s=r.stateNode.containerInfo,a=BP(e);tv(e,a,s);break;default:throw Error(q(161))}}catch(c){St(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function SH(e,n,t){ne=e,M2(e)}function M2(e,n,t){for(var r=(e.mode&1)!==0;ne!==null;){var o=ne,i=o.child;if(o.tag===22&&r){var s=o.memoizedState!==null||kd;if(!s){var a=o.alternate,c=a!==null&&a.memoizedState!==null||Jt;a=kd;var l=Jt;if(kd=s,(Jt=c)&&!l)for(ne=o;ne!==null;)s=ne,c=s.child,s.tag===22&&s.memoizedState!==null?WP(o):c!==null?(c.return=s,ne=c):WP(o);for(;i!==null;)ne=i,M2(i),i=i.sibling;ne=o,kd=a,Jt=l}HP(e)}else o.subtreeFlags&8772&&i!==null?(i.return=o,ne=i):HP(e)}}function HP(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:Jt||zp(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Jt)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:$r(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var i=n.updateQueue;i!==null&&_P(n,i,r);break;case 3:var s=n.updateQueue;if(s!==null){if(t=null,n.child!==null)switch(n.child.tag){case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}_P(n,s,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))}Jt||n.flags&512&&ev(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 KP(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 WP(e){for(;ne!==null;){var n=ne;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{zp(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 i=n.return;try{ev(n)}catch(c){St(n,i,c)}break;case 5:var s=n.return;try{ev(n)}catch(c){St(n,s,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 vH=Math.ceil,Jf=ti.ReactCurrentDispatcher,Px=ti.ReactCurrentOwner,wr=ti.ReactCurrentBatchConfig,Te=0,At=null,It=null,Ht=0,Wn=0,ja=qi(0),_t=0,au=null,js=0,Bp=0,Cx=0,Al=null,In=null,Ix=0,uc=1/0,Ao=null,ep=!1,rv=null,ji=null,Td=!1,Pi=null,tp=0,jl=0,ov=null,xh=-1,wh=0;function pn(){return Te&6?Pt():xh!==-1?xh:xh=Pt()}function Oi(e){return e.mode&1?Te&2&&Ht!==0?Ht&-Ht:nH.transition!==null?(wh===0&&(wh=gT()),wh):(e=Ne,e!==0||(e=window.event,e=e===void 0?16:bT(e.type)),e):1}function Fr(e,n,t,r){if(50<jl)throw jl=0,ov=null,Error(q(185));Du(e,t,r),(!(Te&2)||e!==At)&&(e===At&&(!(Te&2)&&(Bp|=t),_t===4&&xi(e,Ht)),Dn(e,r),t===1&&Te===0&&!(n.mode&1)&&(uc=Pt()+500,Lp&&Zi()))}function Dn(e,n){var t=e.callbackNode;nU(e,n);var r=Ff(e,e===At?Ht:0);if(r===0)t!==null&&eP(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&eP(t),n===1)e.tag===0?tH(GP.bind(null,e)):BT(GP.bind(null,e)),ZU(function(){!(Te&6)&&Zi()}),t=null;else{switch(mT(r)){case 1:t=Z0;break;case 4:t=fT;break;case 16:t=Lf;break;case 536870912:t=pT;break;default:t=Lf}t=N2(t,A2.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function A2(e,n){if(xh=-1,wh=0,Te&6)throw Error(q(327));var t=e.callbackNode;if(Xa()&&e.callbackNode!==t)return null;var r=Ff(e,e===At?Ht:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=np(e,r);else{n=r;var o=Te;Te|=2;var i=O2();(At!==e||Ht!==n)&&(Ao=null,uc=Pt()+500,bs(e,n));do try{bH();break}catch(a){j2(e,a)}while(!0);ux(),Jf.current=i,Te=o,It!==null?n=0:(At=null,Ht=0,n=_t)}if(n!==0){if(n===2&&(o=MS(e),o!==0&&(r=o,n=iv(e,o))),n===1)throw t=au,bs(e,0),xi(e,r),Dn(e,Pt()),t;if(n===6)xi(e,r);else{if(o=e.current.alternate,!(r&30)&&!xH(o)&&(n=np(e,r),n===2&&(i=MS(e),i!==0&&(r=i,n=iv(e,i))),n===1))throw t=au,bs(e,0),xi(e,r),Dn(e,Pt()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:ds(e,In,Ao);break;case 3:if(xi(e,r),(r&130023424)===r&&(n=Ix+500-Pt(),10<n)){if(Ff(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){pn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=NS(ds.bind(null,e,In,Ao),n);break}ds(e,In,Ao);break;case 4:if(xi(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var s=31-Lr(r);i=1<<s,s=n[s],s>o&&(o=s),r&=~i}if(r=o,r=Pt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*vH(r/1960))-r,10<r){e.timeoutHandle=NS(ds.bind(null,e,In,Ao),r);break}ds(e,In,Ao);break;case 5:ds(e,In,Ao);break;default:throw Error(q(329))}}}return Dn(e,Pt()),e.callbackNode===t?A2.bind(null,e):null}function iv(e,n){var t=Al;return e.current.memoizedState.isDehydrated&&(bs(e,n).flags|=256),e=np(e,n),e!==2&&(n=In,In=t,n!==null&&sv(n)),e}function sv(e){In===null?In=e:In.push.apply(In,e)}function xH(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],i=o.getSnapshot;o=o.value;try{if(!Ur(i(),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 xi(e,n){for(n&=~Cx,n&=~Bp,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-Lr(n),r=1<<t;e[t]=-1,n&=~r}}function GP(e){if(Te&6)throw Error(q(327));Xa();var n=Ff(e,0);if(!(n&1))return Dn(e,Pt()),null;var t=np(e,n);if(e.tag!==0&&t===2){var r=MS(e);r!==0&&(n=r,t=iv(e,r))}if(t===1)throw t=au,bs(e,0),xi(e,n),Dn(e,Pt()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,ds(e,In,Ao),Dn(e,Pt()),null}function Ex(e,n){var t=Te;Te|=1;try{return e(n)}finally{Te=t,Te===0&&(uc=Pt()+500,Lp&&Zi())}}function Os(e){Pi!==null&&Pi.tag===0&&!(Te&6)&&Xa();var n=Te;Te|=1;var t=wr.transition,r=Ne;try{if(wr.transition=null,Ne=1,e)return e()}finally{Ne=r,wr.transition=t,Te=n,!(Te&6)&&Zi()}}function _x(){Wn=ja.current,tt(ja)}function bs(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,qU(t)),It!==null)for(t=It.return;t!==null;){var r=t;switch(ax(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Hf();break;case 3:cc(),tt(jn),tt(an),mx();break;case 5:gx(r);break;case 4:cc();break;case 13:tt(lt);break;case 19:tt(lt);break;case 10:dx(r.type._context);break;case 22:case 23:_x()}t=t.return}if(At=e,It=e=Di(e.current,null),Ht=Wn=n,_t=0,au=null,Cx=Bp=js=0,In=Al=null,gs!==null){for(n=0;n<gs.length;n++)if(t=gs[n],r=t.interleaved,r!==null){t.interleaved=null;var o=r.next,i=t.pending;if(i!==null){var s=i.next;i.next=o,r.next=s}t.pending=r}gs=null}return e}function j2(e,n){do{var t=It;try{if(ux(),yh.current=Qf,Zf){for(var r=ht.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Zf=!1}if(As=0,$t=Et=ht=null,$l=!1,ou=0,Px.current=null,t===null||t.return===null){_t=1,au=n,It=null;break}e:{var i=e,s=t.return,a=t,c=n;if(n=Ht,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=jP(s);if(p!==null){p.flags&=-257,OP(p,s,a,i,n),p.mode&1&&AP(i,l,n),n=p,c=l;var S=n.updateQueue;if(S===null){var m=new Set;m.add(c),n.updateQueue=m}else S.add(c);break e}else{if(!(n&1)){AP(i,l,n),kx();break e}c=Error(q(426))}}else if(rt&&a.mode&1){var w=jP(s);if(w!==null){!(w.flags&65536)&&(w.flags|=256),OP(w,s,a,i,n),cx(lc(c,a));break e}}i=c=lc(c,a),_t!==4&&(_t=2),Al===null?Al=[i]:Al.push(i),i=s;do{switch(i.tag){case 3:i.flags|=65536,n&=-n,i.lanes|=n;var y=m2(i,c,n);EP(i,y);break e;case 1:a=c;var v=i.type,P=i.stateNode;if(!(i.flags&128)&&(typeof v.getDerivedStateFromError=="function"||P!==null&&typeof P.componentDidCatch=="function"&&(ji===null||!ji.has(P)))){i.flags|=65536,n&=-n,i.lanes|=n;var E=y2(i,a,n);EP(i,E);break e}}i=i.return}while(i!==null)}R2(t)}catch(C){n=C,It===t&&t!==null&&(It=t=t.return);continue}break}while(!0)}function O2(){var e=Jf.current;return Jf.current=Qf,e===null?Qf:e}function kx(){(_t===0||_t===3||_t===2)&&(_t=4),At===null||!(js&268435455)&&!(Bp&268435455)||xi(At,Ht)}function np(e,n){var t=Te;Te|=2;var r=O2();(At!==e||Ht!==n)&&(Ao=null,bs(e,n));do try{wH();break}catch(o){j2(e,o)}while(!0);if(ux(),Te=t,Jf.current=r,It!==null)throw Error(q(261));return At=null,Ht=0,_t}function wH(){for(;It!==null;)D2(It)}function bH(){for(;It!==null&&!V9();)D2(It)}function D2(e){var n=F2(e.alternate,e,Wn);e.memoizedProps=e.pendingProps,n===null?R2(e):It=n,Px.current=null}function R2(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=gH(t,n),t!==null){t.flags&=32767,It=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{_t=6,It=null;return}}else if(t=pH(t,n,Wn),t!==null){It=t;return}if(n=n.sibling,n!==null){It=n;return}It=n=e}while(n!==null);_t===0&&(_t=5)}function ds(e,n,t){var r=Ne,o=wr.transition;try{wr.transition=null,Ne=1,PH(e,n,t,r)}finally{wr.transition=o,Ne=r}return null}function PH(e,n,t,r){do Xa();while(Pi!==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 i=t.lanes|t.childLanes;if(rU(e,i),e===At&&(It=At=null,Ht=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||Td||(Td=!0,N2(Lf,function(){return Xa(),null})),i=(t.flags&15990)!==0,t.subtreeFlags&15990||i){i=wr.transition,wr.transition=null;var s=Ne;Ne=1;var a=Te;Te|=4,Px.current=null,yH(e,t),$2(t,e),HU(LS),Nf=!!RS,LS=RS=null,e.current=t,SH(t),Y9(),Te=a,Ne=s,wr.transition=i}else e.current=t;if(Td&&(Td=!1,Pi=e,tp=o),i=e.pendingLanes,i===0&&(ji=null),Z9(t.stateNode),Dn(e,Pt()),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(ep)throw ep=!1,e=rv,rv=null,e;return tp&1&&e.tag!==0&&Xa(),i=e.pendingLanes,i&1?e===ov?jl++:(jl=0,ov=e):jl=0,Zi(),null}function Xa(){if(Pi!==null){var e=mT(tp),n=wr.transition,t=Ne;try{if(wr.transition=null,Ne=16>e?16:e,Pi===null)var r=!1;else{if(e=Pi,Pi=null,tp=0,Te&6)throw Error(q(331));var o=Te;for(Te|=4,ne=e.current;ne!==null;){var i=ne,s=i.child;if(ne.flags&16){var a=i.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:Ml(8,u,i)}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(_2(u),u===l){ne=null;break}if(f!==null){f.return=p,ne=f;break}ne=p}}}var S=i.alternate;if(S!==null){var m=S.child;if(m!==null){S.child=null;do{var w=m.sibling;m.sibling=null,m=w}while(m!==null)}}ne=i}}if(i.subtreeFlags&2064&&s!==null)s.return=i,ne=s;else e:for(;ne!==null;){if(i=ne,i.flags&2048)switch(i.tag){case 0:case 11:case 15:Ml(9,i,i.return)}var y=i.sibling;if(y!==null){y.return=i.return,ne=y;break e}ne=i.return}}var v=e.current;for(ne=v;ne!==null;){s=ne;var P=s.child;if(s.subtreeFlags&2064&&P!==null)P.return=s,ne=P;else e:for(s=v;ne!==null;){if(a=ne,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:zp(9,a)}}catch(C){St(a,a.return,C)}if(a===s){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,Zi(),ao&&typeof ao.onPostCommitFiberRoot=="function")try{ao.onPostCommitFiberRoot(Ap,e)}catch{}r=!0}return r}finally{Ne=t,wr.transition=n}}return!1}function VP(e,n,t){n=lc(t,n),n=m2(e,n,1),e=Ai(e,n,1),n=pn(),e!==null&&(Du(e,1,n),Dn(e,n))}function St(e,n,t){if(e.tag===3)VP(e,e,t);else for(;n!==null;){if(n.tag===3){VP(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(ji===null||!ji.has(r))){e=lc(t,e),e=y2(n,e,1),n=Ai(n,e,1),e=pn(),n!==null&&(Du(n,1,e),Dn(n,e));break}}n=n.return}}function CH(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=pn(),e.pingedLanes|=e.suspendedLanes&t,At===e&&(Ht&t)===t&&(_t===4||_t===3&&(Ht&130023424)===Ht&&500>Pt()-Ix?bs(e,0):Cx|=t),Dn(e,n)}function L2(e,n){n===0&&(e.mode&1?(n=vd,vd<<=1,!(vd&130023424)&&(vd=4194304)):n=1);var t=pn();e=Vo(e,n),e!==null&&(Du(e,n,t),Dn(e,t))}function IH(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),L2(e,t)}function EH(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),L2(e,t)}var F2;F2=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||jn.current)Tn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return Tn=!1,fH(e,n,t);Tn=!!(e.flags&131072)}else Tn=!1,rt&&n.flags&1048576&&UT(n,Gf,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;vh(e,n),e=n.pendingProps;var o=ic(n,an.current);Ya(n,t),o=Sx(null,n,r,e,o,t);var i=vx();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,On(r)?(i=!0,Kf(n)):i=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,fx(n),o.updater=Np,n.stateNode=o,o._reactInternals=n,GS(n,r,e,t),n=XS(null,n,r,!0,i,t)):(n.tag=0,rt&&i&&sx(n),dn(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(vh(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=kH(r),e=$r(r,e),o){case 0:n=YS(null,n,r,e,t);break e;case 1:n=LP(null,n,r,e,t);break e;case 11:n=DP(null,n,r,e,t);break e;case 14:n=RP(null,n,r,$r(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:$r(r,o),YS(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),LP(e,n,r,o,t);case 3:e:{if(w2(n),e===null)throw Error(q(387));r=n.pendingProps,i=n.memoizedState,o=i.element,YT(e,n),Xf(n,r,null,t);var s=n.memoizedState;if(r=s.element,i.isDehydrated)if(i={element:r,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},n.updateQueue.baseState=i,n.memoizedState=i,n.flags&256){o=lc(Error(q(423)),n),n=FP(e,n,r,t,o);break e}else if(r!==o){o=lc(Error(q(424)),n),n=FP(e,n,r,t,o);break e}else for(qn=Mi(n.stateNode.containerInfo.firstChild),er=n,rt=!0,Dr=null,t=GT(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(sc(),r===o){n=Yo(e,n,t);break e}dn(e,n,r,t)}n=n.child}return n;case 5:return XT(n),e===null&&HS(n),r=n.type,o=n.pendingProps,i=e!==null?e.memoizedProps:null,s=o.children,FS(r,o)?s=null:i!==null&&FS(r,i)&&(n.flags|=32),x2(e,n),dn(e,n,s,t),n.child;case 6:return e===null&&HS(n),null;case 13:return b2(e,n,t);case 4:return px(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=ac(n,null,r,t):dn(e,n,r,t),n.child;case 11:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),DP(e,n,r,o,t);case 7:return dn(e,n,n.pendingProps,t),n.child;case 8:return dn(e,n,n.pendingProps.children,t),n.child;case 12:return dn(e,n,n.pendingProps.children,t),n.child;case 10:e:{if(r=n.type._context,o=n.pendingProps,i=n.memoizedProps,s=o.value,Ye(Vf,r._currentValue),r._currentValue=s,i!==null)if(Ur(i.value,s)){if(i.children===o.children&&!jn.current){n=Yo(e,n,t);break e}}else for(i=n.child,i!==null&&(i.return=n);i!==null;){var a=i.dependencies;if(a!==null){s=i.child;for(var c=a.firstContext;c!==null;){if(c.context===r){if(i.tag===1){c=zo(-1,t&-t),c.tag=2;var l=i.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}}i.lanes|=t,c=i.alternate,c!==null&&(c.lanes|=t),KS(i.return,t,n),a.lanes|=t;break}c=c.next}}else if(i.tag===10)s=i.type===n.type?null:i.child;else if(i.tag===18){if(s=i.return,s===null)throw Error(q(341));s.lanes|=t,a=s.alternate,a!==null&&(a.lanes|=t),KS(s,t,n),s=i.sibling}else s=i.child;if(s!==null)s.return=i;else for(s=i;s!==null;){if(s===n){s=null;break}if(i=s.sibling,i!==null){i.return=s.return,s=i;break}s=s.return}i=s}dn(e,n,o.children,t),n=n.child}return n;case 9:return o=n.type,r=n.pendingProps.children,Ya(n,t),o=br(o),r=r(o),n.flags|=1,dn(e,n,r,t),n.child;case 14:return r=n.type,o=$r(r,n.pendingProps),o=$r(r.type,o),RP(e,n,r,o,t);case 15:return S2(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),vh(e,n),n.tag=1,On(r)?(e=!0,Kf(n)):e=!1,Ya(n,t),g2(n,r,o),GS(n,r,o,t),XS(null,n,r,!0,e,t);case 19:return P2(e,n,t);case 22:return v2(e,n,t)}throw Error(q(156,n.tag))};function N2(e,n){return hT(e,n)}function _H(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 vr(e,n,t,r){return new _H(e,n,t,r)}function Tx(e){return e=e.prototype,!(!e||!e.isReactComponent)}function kH(e){if(typeof e=="function")return Tx(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Y0)return 11;if(e===X0)return 14}return 2}function Di(e,n){var t=e.alternate;return t===null?(t=vr(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 bh(e,n,t,r,o,i){var s=2;if(r=e,typeof e=="function")Tx(e)&&(s=1);else if(typeof e=="string")s=5;else e:switch(e){case Pa:return Ps(t.children,o,i,n);case V0:s=8,o|=8;break;case mS:return e=vr(12,t,n,o|2),e.elementType=mS,e.lanes=i,e;case yS:return e=vr(13,t,n,o),e.elementType=yS,e.lanes=i,e;case SS:return e=vr(19,t,n,o),e.elementType=SS,e.lanes=i,e;case Xk:return Up(t,o,i,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case Vk:s=10;break e;case Yk:s=9;break e;case Y0:s=11;break e;case X0:s=14;break e;case mi:s=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=vr(s,t,n,o),n.elementType=e,n.type=r,n.lanes=i,n}function Ps(e,n,t,r){return e=vr(7,e,r,n),e.lanes=t,e}function Up(e,n,t,r){return e=vr(22,e,r,n),e.elementType=Xk,e.lanes=t,e.stateNode={isHidden:!1},e}function Bm(e,n,t){return e=vr(6,e,null,n),e.lanes=t,e}function Um(e,n,t){return n=vr(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function TH(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=bm(0),this.expirationTimes=bm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=bm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function $x(e,n,t,r,o,i,s,a,c){return e=new TH(e,n,t,a,c),n===1?(n=1,i===!0&&(n|=8)):n=0,i=vr(3,null,null,n),e.current=i,i.stateNode=e,i.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},fx(i),e}function $H(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 z2(e){if(!e)return Ni;e=e._reactInternals;e:{if(Ys(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(On(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(On(t))return zT(e,t,n)}return n}function B2(e,n,t,r,o,i,s,a,c){return e=$x(t,r,!0,e,o,i,s,a,c),e.context=z2(null),t=e.current,r=pn(),o=Oi(t),i=zo(r,o),i.callback=n??null,Ai(t,i,o),e.current.lanes=o,Du(e,o,r),Dn(e,r),e}function Hp(e,n,t,r){var o=n.current,i=pn(),s=Oi(o);return t=z2(t),n.context===null?n.context=t:n.pendingContext=t,n=zo(i,s),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Ai(o,n,s),e!==null&&(Fr(e,o,s,i),mh(e,o,s)),s}function rp(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 YP(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function Mx(e,n){YP(e,n),(e=e.alternate)&&YP(e,n)}function MH(){return null}var U2=typeof reportError=="function"?reportError:function(e){console.error(e)};function Ax(e){this._internalRoot=e}Kp.prototype.render=Ax.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));Hp(e,n,null,null)};Kp.prototype.unmount=Ax.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Os(function(){Hp(null,e,null,null)}),n[Go]=null}};function Kp(e){this._internalRoot=e}Kp.prototype.unstable_scheduleHydration=function(e){if(e){var n=vT();e={blockedOn:null,target:e,priority:n};for(var t=0;t<vi.length&&n!==0&&n<vi[t].priority;t++);vi.splice(t,0,e),t===0&&wT(e)}};function jx(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Wp(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function XP(){}function AH(e,n,t,r,o){if(o){if(typeof r=="function"){var i=r;r=function(){var l=rp(s);i.call(l)}}var s=B2(n,r,e,0,null,!1,!1,"",XP);return e._reactRootContainer=s,e[Go]=s.current,Jl(e.nodeType===8?e.parentNode:e),Os(),s}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var l=rp(c);a.call(l)}}var c=$x(e,0,!1,null,null,!1,!1,"",XP);return e._reactRootContainer=c,e[Go]=c.current,Jl(e.nodeType===8?e.parentNode:e),Os(function(){Hp(n,c,t,r)}),c}function Gp(e,n,t,r,o){var i=t._reactRootContainer;if(i){var s=i;if(typeof o=="function"){var a=o;o=function(){var c=rp(s);a.call(c)}}Hp(n,s,e,o)}else s=AH(t,n,e,o,r);return rp(s)}yT=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=ml(n.pendingLanes);t!==0&&(Q0(n,t|1),Dn(n,Pt()),!(Te&6)&&(uc=Pt()+500,Zi()))}break;case 13:Os(function(){var r=Vo(e,1);if(r!==null){var o=pn();Fr(r,e,1,o)}}),Mx(e,1)}};J0=function(e){if(e.tag===13){var n=Vo(e,134217728);if(n!==null){var t=pn();Fr(n,e,134217728,t)}Mx(e,134217728)}};ST=function(e){if(e.tag===13){var n=Oi(e),t=Vo(e,n);if(t!==null){var r=pn();Fr(t,e,n,r)}Mx(e,n)}};vT=function(){return Ne};xT=function(e,n){var t=Ne;try{return Ne=e,n()}finally{Ne=t}};kS=function(e,n,t){switch(n){case"input":if(wS(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=Rp(r);if(!o)throw Error(q(90));Zk(r),wS(r,o)}}}break;case"textarea":Jk(e,t);break;case"select":n=t.value,n!=null&&Ka(e,!!t.multiple,n,!1)}};sT=Ex;aT=Os;var jH={usingClientEntryPoint:!1,Events:[Lu,_a,Rp,oT,iT,Ex]},el={findFiberByHostInstance:ps,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},OH={bundleType:el.bundleType,version:el.version,rendererPackageName:el.rendererPackageName,rendererConfig:el.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:ti.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=uT(e),e===null?null:e.stateNode},findFiberByHostInstance:el.findFiberByHostInstance||MH,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 $d=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!$d.isDisabled&&$d.supportsFiber)try{Ap=$d.inject(OH),ao=$d}catch{}}ar.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=jH;ar.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!jx(n))throw Error(q(200));return $H(e,n,null,t)};ar.createRoot=function(e,n){if(!jx(e))throw Error(q(299));var t=!1,r="",o=U2;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=$x(e,1,!1,null,null,t,!1,r,o),e[Go]=n.current,Jl(e.nodeType===8?e.parentNode:e),new Ax(n)};ar.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=uT(n),e=e===null?null:e.stateNode,e};ar.flushSync=function(e){return Os(e)};ar.hydrate=function(e,n,t){if(!Wp(n))throw Error(q(200));return Gp(null,e,n,!0,t)};ar.hydrateRoot=function(e,n,t){if(!jx(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,i="",s=U2;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(i=t.identifierPrefix),t.onRecoverableError!==void 0&&(s=t.onRecoverableError)),n=B2(n,null,e,1,t??null,o,!1,i,s),e[Go]=n.current,Jl(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 Kp(n)};ar.render=function(e,n,t){if(!Wp(n))throw Error(q(200));return Gp(null,e,n,!1,t)};ar.unmountComponentAtNode=function(e){if(!Wp(e))throw Error(q(40));return e._reactRootContainer?(Os(function(){Gp(null,null,e,!1,function(){e._reactRootContainer=null,e[Go]=null})}),!0):!1};ar.unstable_batchedUpdates=Ex;ar.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!Wp(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return Gp(e,n,t,!1,r)};ar.version="18.3.1-next-f1338f8080-20240426";function H2(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(H2)}catch(e){console.error(e)}}H2(),Hk.exports=ar;var Xs=Hk.exports;const DH=Ki(Xs);var av={},K2,qP=Xs;K2=av.createRoot=qP.createRoot,av.hydrateRoot=qP.hydrateRoot;function W2(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 zi({children:e,className:n="",...t}){return h.jsx("svg",{...t,className:ue("tl-svg-container",n),children:e})}function Ox(e,n,t,r){const o=e.x-t.x,i=e.y-t.y,s=r.x-t.x,a=r.y-t.y,c=n.x-e.x,l=n.y-e.y,u=s*i-a*o,d=c*i-l*o,f=a*c-s*l;if(u===0||d===0||f===0)return null;if(f!==0){const p=u/f,S=d/f;if(0<=p&&p<=1&&0<=S&&S<=1)return b.AddXY(e,p*c,p*l)}return null}function Nu(e,n,t,r){const o=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),i=2*((n.x-e.x)*(e.x-t.x)+(n.y-e.y)*(e.y-t.y)),s=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=i*i-4*o*s;if(a<0||a===0)return null;const c=Math.sqrt(a),l=(-i+c)/(2*o),u=(-i-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 RH(e,n,t){const r=[];let o;for(let i=0,s=t.length-1;i<s;i++)o=Ox(e,n,t[i],t[i+1]),o&&r.push(o);return r.length===0?null:r}function Dx(e,n,t){const r=[];let o;for(let i=1,s=t.length;i<s+1;i++)o=Ox(e,n,t[i-1],t[i%t.length]),o&&r.push(o);return r.length===0?null:r}function LH(e,n,t,r){let o=t.x-e.x,i=t.y-e.y;const s=Math.sqrt(o*o+i*i),a=(s*s-r*r+n*n)/(2*s),c=Math.sqrt(n*n-a*a);return o/=s,i/=s,[new b(e.x+o*a-i*c,e.y+i*a+o*c),new b(e.x+o*a+i*c,e.y+i*a-o*c)]}function cv(e,n,t){const r=[];let o,i,s;for(let a=0,c=t.length;a<c;a++)o=t[a],i=t[(a+1)%t.length],s=Nu(o,i,e,n),s&&r.push(...s);return r.length===0?null:r}function ZP(e,n,t){const r=[];let o,i,s;for(let a=1,c=t.length;a<c;a++)o=t[a-1],i=t[a],s=Nu(o,i,e,n),s&&r.push(...s);return r.length===0?null:r}function Md(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function Rx(e,n,t,r){return Md(e,t,r)!==Md(n,t,r)&&Md(e,n,t)!==Md(e,n,r)}function QP(e,n){const t=new Map;let r,o,i,s;for(let a=0,c=e.length;a<c;a++)if(r=e[a],Jn(r,n)){const l=Hm(r);t.has(l)||t.set(l,r)}for(let a=0,c=n.length;a<c;a++)if(r=n[a],Jn(r,e)){const l=Hm(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++){i=n[l],s=n[(l+1)%n.length];const d=Ox(r,o,i,s);if(d!==null){const f=Hm(d);t.has(f)||t.set(f,d)}}}return t.size===0?null:FH([...t.values()])}function Hm(e){return`${e.x},${e.y}`}function FH(e){const n=b.Average(e);return e.sort((t,r)=>b.Angle(n,t)-b.Angle(n,r))}function G2(e,n){let t,r,o,i;for(let s=0,a=e.length;s<a;s++){t=e[s],r=e[(s+1)%a];for(let c=0,l=n.length;c<l;c++)if(o=n[c],i=n[(c+1)%l],Rx(t,r,o,i))return!0}return!1}function NH(e,n){let t,r,o,i;for(let s=0,a=e.length;s<a;s++){t=e[s],r=e[(s+1)%a];for(let c=1,l=n.length;c<l;c++)if(o=n[c-1],i=n[c],Rx(t,r,o,i))return!0}return!1}class Fo extends Yi{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:i,ul:s}=this;if(s===0)return r;const a=b.Sub(t,r).dpr(i)/s,c=r.x+i.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+i.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 Rx(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 kc extends Yi{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 i=t[r],s=t[r+1];this._segments.push(new Fo({start:i,end:s}))}this.isClosed&&this._segments.push(new Fo({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],i=1/0,s,a;for(let c=0;c<r.length;c++)s=r[c].nearestPoint(t),a=b.Dist2(s,t),a<i&&(o=s,i=a);if(!o)throw Error("nearest point not found");return o}hitTestLineSegment(t,r,o=0){const{segments:i}=this;for(let s=0,a=i.length;s<a;s++)if(i[s].hitTestLineSegment(t,r,o))return!0;return!1}getSvgPathData(){const{vertices:t}=this;return t.length<2?"":t.reduce((r,o,i)=>i===0?`M ${o.x} ${o.y}`:`${r} L ${o.x} ${o.y}`,"")}}class wt extends kc{constructor(n){super({...n}),this.isClosed=!0}}class Xo extends wt{constructor(t){const{x:r=0,y:o=0,width:i,height:s}=t;super({...t,points:[new b(r,o),new b(r+i,o),new b(r+i,o+s),new b(r,o+s)]});g(this,"x");g(this,"y");g(this,"w");g(this,"h");this.x=r,this.y=o,this.w=i,this.h=s}getBounds(){return new J(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:o,h:i}=this;return`M${t},${r} h${o} v${i} h-${o}z`}}class Nr{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(Nr,"props"),g(Nr,"migrations"),g(Nr,"type");function zH(e,n,t={}){const{closed:r=!1,snap:o=1,start:i="outset",end:s="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||(i==="outset"?(e+=l/2,p+=l/2):i==="skip"&&(e-=l,p-=l),s==="outset"?e+=l/2:s==="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 JP({bounds:e,className:n}){const t=z(),r=G("zoom level",()=>t.getZoomLevel(),[t]);return h.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,i)=>{const{strokeDasharray:s,strokeDashoffset:a}=zH(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:s,strokeDashoffset:a},i)})})}class Ph extends Nr{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 Xo({width:1,height:1,isFilled:!1}):new Br({children:r.map(o=>{const i=this.editor.getShape(o),s=this.editor.getShapeGeometry(o),a=this.editor.getShapeLocalTransform(i).applyToPoints(s.vertices);return s.isClosed?new wt({points:a,isFilled:!0}):new kc({points:a})})})}component(t){const r=this.editor.getErasingShapeIds().includes(t.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),i=o.length>0&&o.some(c=>c!==t.id&&this.editor.isShapeOfType(this.editor.getShape(c),"group")),s=this.editor.getCurrentPageState().focusedGroupId!==t.id;if(!r&&(s||i))return null;const a=this.editor.getShapeGeometry(t).bounds;return h.jsx(zi,{id:t.id,children:h.jsx(JP,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return h.jsx(JP,{className:"",bounds:r})}}g(Ph,"type","group"),g(Ph,"props",H_),g(Ph,"migrations",K_);const V2=[Ph],BH=new Set(V2.map(e=>e.type));function Y2(e){const n=[...V2],t=new Set;for(const r of e){if(BH.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(t.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);n.push(r),t.add(r.type)}return n}const UH={maxShapesPerPage:4e3,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,maxPointsPerDrawShape:500,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:8,edgeScrollSpeed:20,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10};function eC(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 nn(e)}}class HH{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(!eC(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!eC(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 lv extends HH{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:nn(r,"type")}}}function KH(e,n,t){return fetch(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function WH(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?)$/,i=>(+i+1).toString()):`${t} 1`;return t}function Ad(e,n,t){if(t.length===0)return[];const r=new Map;for(const i of ye(t.map(s=>e.getShape(s)))){const{parentId:s}=i;r.has(s)||r.set(s,{children:ye(e.getSortedChildIdsForParent(s).map(a=>e.getShape(a))),moving:new Set}),r.get(s).moving.add(i)}const o=[];switch(n){case"toBack":{r.forEach(({moving:i,children:s})=>GH(i,s,o));break}case"toFront":{r.forEach(({moving:i,children:s})=>VH(i,s,o));break}case"forward":{r.forEach(({moving:i,children:s})=>YH(i,s,o));break}case"backward":{r.forEach(({moving:i,children:s})=>XH(i,s,o));break}}return o}function GH(e,n,t){const r=n.length;if(e.size===r)return;let o,i;for(let s=0;s<r;s++){const a=n[s];if(e.has(a))o=a.index,e.delete(a);else{i=a.index;break}}if(e.size!==0){const s=tc(o,i,e.size);t.push(...Array.from(e.values()).sort(en).map((a,c)=>({...a,index:s[c]})))}}function VH(e,n,t){const r=n.length;if(e.size===r)return;let o,i;for(let s=r-1;s>-1;s--){const a=n[s];if(e.has(a))i=a.index,e.delete(a);else{o=a.index;break}}if(e.size!==0){const s=tc(o,i,e.size);t.push(...Array.from(e.values()).sort(en).map((a,c)=>({...a,index:s[c]})))}}function YH(e,n,t){var i;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let s=0;s<r;s++){const a=e.has(n[s]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:s};break}case"selecting":{if(a)continue;const{selectIndex:c}=o;tc(n[s].index,(i=n[s+1])==null?void 0:i.index,s-c).forEach((l,u)=>t.push({...n[c+u],index:l})),o={name:"skipping"};break}}}}function XH(e,n,t){var i;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let s=r-1;s>-1;s--){const a=e.has(n[s]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:s};break}case"selecting":{if(a)continue;tc((i=n[s-1])==null?void 0:i.index,n[s].index,o.selectIndex-s).forEach((c,l)=>{t.push({...n[s+l+1],index:c})}),o={name:"skipping"};break}}}}function X2({editor:e}){const n=e.getSelectedShapes(),t=e.getSelectionRotation(),r=e.getSelectionRotatedPageBounds(),{inputs:{originPagePoint:o}}=e;if(!r)return null;const i=r.center.clone().rotWith(r.point,t);return{selectionPageCenter:i,initialCursorAngle:i.angle(o),initialSelectionRotation:t,shapeSnapshots:n.map(s=>({shape:vt(s),initialPagePoint:e.getShapePageTransform(s.id).point()}))}}function Ch({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:i}=t;n.updateShapes(i.map(({shape:a,initialPagePoint:c})=>{const l=gr(a.parentId)?n.getShapePageTransform(a.parentId):ie.Identity(),u=b.RotWith(c,o,e),d=ie.applyToPoint(ie.Inverse(l),u),f=_i(a.rotation+e);return{id:a.id,type:a.type,x:d.x,y:d.y,rotation:f}}));const s=[];i.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 S=(d=l.onRotateStart)==null?void 0:d.call(l,a);S&&s.push(S)}const u=(f=l.onRotate)==null?void 0:f.call(l,a,c);if(u&&s.push(u),r==="end"||r==="one-off"){const S=(p=l.onRotateEnd)==null?void 0:p.call(l,a,c);S&&s.push(S)}}),s.length>0&&n.updateShapes(s)}const qH=e=>{const{store:n}=e,t=n.query.filterHistory("binding"),r=n.query.records("binding");function o(){const i=r.get(),s=new Map;for(const a of i){const{fromId:c,toId:l}=a,u=s.get(c);u?u.push(a):s.set(c,[a]);const d=s.get(l);d?d.push(a):s.set(l,[a])}return s}return V("arrowBindingsIndex",(i,s)=>{if(xs(i))return o();const a=i,c=t.getDiffSince(s);if(c===Zn)return o();let l;function u(p){l??(l=new Map(a));const S=l.get(p.fromId),m=S==null?void 0:S.filter(v=>v.id!==p.id);m!=null&&m.length?l.set(p.fromId,m):l.delete(p.fromId);const w=l.get(p.toId),y=w==null?void 0:w.filter(v=>v.id!==p.id);y!=null&&y.length?l.set(p.toId,y):l.delete(p.toId)}function d(p){l??(l=new Map(a));let S=l.get(p);return S?S===a.get(p)&&(S=S.slice(0),l.set(p,S)):(S=[],l.set(p,S)),S}function f(p){d(p.fromId).push(p),d(p.toId).push(p)}for(const p of c){for(const S of yt(p.added))f(S);for(const[S,m]of yt(p.updated))u(S),f(m);for(const S of yt(p.removed))u(S)}return l??a})};function ZH(e,n,t){const r=e.getShapeMaskedPageBounds(n);return r===void 0?!0:!t.includes(r)}const QH=e=>{function n(t){const r=t.getCurrentPageShapeIds(),o=t.getViewportPageBounds(),i=new Set;return r.forEach(s=>{ZH(t,s,o)&&i.add(s)}),i}return V("getCulledShapes",t=>{if(xs(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})},JH=e=>{const n=e.query.ids("shape"),t=e.query.filterHistory("shape");function r(){const o={},i=n.get(),s=Array(i.size);return i.forEach(a=>s.push(e.get(a))),s.sort(en),s.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return V("parentsToChildrenWithIndexes",(o,i)=>{if(xs(o))return r();const s=t.getDiffSince(i);if(s===Zn)return r();if(s.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=s.length;d<f;d++){u=s[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,S]of Object.values(u.updated))if(wa(S)&&wa(p)){if(p.parentId!==S.parentId)c(p.parentId),c(S.parentId),a[p.parentId].splice(a[p.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),l.add(a[S.parentId]);else if(p.index!==S.index){c(S.parentId);const m=a[S.parentId].indexOf(S.id);a[S.parentId][m]=S.id,l.add(a[S.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(en),d.splice(0,d.length,...f.map(p=>p.id))}return a??o})},Km=(e,n,t)=>{for(;!bn(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},eK=(e,n)=>{const t=e.query.ids("shape");let r=null;function o(){const i=n();return r=i,new Set([...t.get()].filter(s=>Km(e,i,e.get(s))))}return V("_shapeIdsInCurrentPage",(i,s)=>{if(xs(i))return o();const a=n();if(a!==r)return o();const c=e.history.getDiffSince(s);if(c===Zn)return o();const l=new ch(i);for(const d of c){for(const f of Object.values(d.added))wa(f)&&Km(e,a,f)&&l.add(f.id);for(const[f,p]of Object.values(d.updated))wa(p)&&(Km(e,a,p)?l.add(p.id):l.remove(p.id));for(const f of Object.keys(d.removed))gr(f)&&l.remove(f)}const u=l.get();return u?hl(u.value,u.diff):i})},q2=x.createContext(null);function tK({context:e,editor:n,children:t}){return h.jsx(Tp.Provider,{value:n,children:h.jsx(q2.Provider,{value:e,children:t})})}function Z2(){const e=x.useContext(q2);return e?{isDarkMode:e.isDarkMode}:null}async function nK(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:i=!1,padding:s=e.options.defaultSvgPadding,preserveAspectRatio:a=!1}=t,c=t.darkMode??e.user.getIsDarkMode(),l=ei({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(s);const S=f.width*o,m=f.height*o;try{(I=(C=document.body).focus)==null||I.call(C)}catch{}const w=[],y=new Map,v={isDarkMode:c,addExportDef:_=>{if(y.has(_.key))return;const k=(async()=>{const $=await _.getElement();$&&w.push(h.jsx(x.Fragment,{children:$},w.length))})();y.set(_.key,k)}},P=(await Promise.all(d.map(async({id:_,opacity:k,index:$,backgroundIndex:T})=>{var U,H;if(_===p)return[];const A=e.getShape(_);if(e.isShapeOfType(A,"group"))return[];const N=e.getShapeUtil(A);let j=await((U=N.toSvg)==null?void 0:U.call(N,A,v)),O=await((H=N.toBackgroundSvg)==null?void 0:H.call(N,A,v));if(!j&&!O){const W=e.getShapePageBounds(A);j=h.jsx("rect",{width:W.w,height:W.h,fill:l.solid,stroke:l.grey.pattern,strokeWidth:1})}let R=e.getShapePageTransform(A).toCssString();"scale"in A.props&&A.props.scale!==1&&(R=`${R} scale(${A.props.scale}, ${A.props.scale})`),j&&(j=h.jsx("g",{transform:R,opacity:k,children:j},A.id)),O&&(O=h.jsx("g",{transform:R,opacity:k,children:O},`bg_${A.id}`));const Y=e.getShapeMask(A.id);if(Y){const W=`mask_${A.id.replace(":","_")}`;w.push(h.jsx("clipPath",{id:W,children:h.jsx("path",{d:`M${Y.map(({x:Z,y:oe})=>`${Z},${oe}`).join("L")}Z`})},w.length)),j&&(j=h.jsx("g",{clipPath:`url(#${W})`,children:j},A.id)),O&&(O=h.jsx("g",{clipPath:`url(#${W})`,children:O},`bg_${A.id}`))}const K=[];return j&&K.push({zIndex:$,element:j}),O&&K.push({zIndex:T,element:O}),K}))).flat();return await Promise.all(y.values()),{jsx:h.jsx(tK,{editor:e,context:v,children:h.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:S,height:m,viewBox:`${f.minX} ${f.minY} ${f.width} ${f.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:i?p?l.solid:l.background:"transparent"},children:[h.jsx("defs",{children:w}),P.sort((_,k)=>_.zIndex-k.zIndex).map(({element:_})=>_)]})}),width:S,height:m}}const rK=40;class oK{constructor(n){g(this,"_clickId","");g(this,"_clickTimeout");g(this,"_clickScreenPoint");g(this,"_previousScreenPoint");g(this,"_getClickTimeout",(n,t=ot())=>{this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===n&&this._clickId===t){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},n==="idle"||n==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)});g(this,"_clickState","idle");g(this,"lastPointerInfo",{});g(this,"handlePointerEvent",n=>{switch(n.name){case"pointer_down":{if(!this._clickState)return n;switch(this._clickScreenPoint=b.From(n.point),this._previousScreenPoint&&b.Dist2(this._previousScreenPoint,this._clickScreenPoint)>rK**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?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),n}return n});g(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});this.editor=n}get clickState(){return this._clickState}}class iK{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 sK{constructor(n,t){g(this,"disposeSideEffectListener");this.editor=n,this.disposeSideEffectListener=n.sideEffects.registerAfterChangeHandler("instance",(o,i)=>{o.isFocused!==i.isFocused&&(i.isFocused?this.focus():this.blur(),this.updateContainerClass())});const r=n.getInstanceState().isFocused;t!==r&&n.updateInstanceState({isFocused:!!t}),this.updateContainerClass()}updateContainerClass(){const n=this.editor.getContainer();this.editor.getInstanceState().isFocused?n.classList.add("tl-container__focused"):n.classList.remove("tl-container__focused")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var n;(n=this.disposeSideEffectListener)==null||n.call(this)}}function tl(e){return cK}class aK{constructor(){g(this,"length",0);g(this,"head",null);g(this,"tail",this)}push(n){return new Lx(n,this)}toArray(){return No}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const cK=new aK;class Lx{constructor(n,t){g(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Lx(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 lK{constructor(n){g(this,"store");g(this,"dispose");g(this,"state","recording");g(this,"pendingDiff",new dK);g(this,"stacks",rn("HistoryManager.stacks",{undos:tl(),redos:tl()},{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=uK[t.history]);try{if(this._isInBatch)return n(),this;this._isInBatch=!0;try{vs(()=>{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:i,redos:s}=this.stacks.get();const a=this.pendingDiff.clear(),c=i_(a),l=iS(a);n&&!c&&(s=s.push({type:"diff",diff:a}));let u=!1;if(c)for(;((o=i.head)==null?void 0:o.type)==="stop";){const d=i.head;if(i=i.tail,n&&(s=s.push(d)),d.id===t){u=!0;break}}if(!u)e:for(;i.head;){const d=i.head;switch(i=i.tail,n&&(s=s.push(d)),d.type){case"diff":bl(l,[iS(d.diff)]);break;case"stop":if(!t||d.id===t)break e;break;default:nn(d)}}this.store.applyDiff(l,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:i,redos:s})}finally{this.state=r}return this});g(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));g(this,"redo",()=>{var t;const n=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:o}=this.stacks.get();if(o.length===0)return this;for(;((t=o.head)==null?void 0:t.type)==="stop";)r=r.push(o.head),o=o.tail;const i=ff();for(;o.head;){const s=o.head;if(r=r.push(s),o=o.tail,s.type==="diff")bl(i,[s.diff]);else break}this.store.applyDiff(i,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:o})}finally{this.state=n}return this});g(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));g(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));g(this,"squashToMark",n=>{var i;let t=this.stacks.get().undos;const r=[];for(;t.head&&!(t.head.type==="stop"&&t.head.id===n);)t.head.type==="diff"&&r.push(t.head.diff),t=t.tail;if(!t.head||((i=t.head)==null?void 0:i.id)!==n)return console.error("Could not find mark to squash to: ",n),this;if(r.length===0)return this;const o=ff();return bl(o,r.reverse()),this.stacks.update(({redos:s})=>({undos:t.push({type:"diff",diff:o}),redos:s})),this});g(this,"mark",(n=ot())=>(vs(()=>{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??df,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:tl()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:nn(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:tl(),redos:tl()}),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 uK={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class dK{constructor(){g(this,"diff",ff());g(this,"isEmptyAtom",rn("PendingDiff.isEmpty",!0))}clear(){const n=this.diff;return this.diff=ff(),this.isEmptyAtom.set(!0),n}isEmpty(){return this.isEmptyAtom.get()}apply(n){bl(this.diff,[n]),this.isEmptyAtom.set(i_(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class hK{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:i}=o,s={x:t,y:r,z:.5};return(!i||b.Dist(i,s)>=1)&&(o.next=s),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:i,next:s,scribble:a}=t;switch(a.state){case"active":{s&&s!==i?(t.prev=s,a.points.push(s),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 fK=Object.defineProperty,pK=Object.getOwnPropertyDescriptor,Vp=(e,n,t,r)=>{for(var o=pK(n,t),i=e.length-1,s;i>=0;i--)(s=e[i])&&(o=s(n,t,o)||o);return o&&fK(n,t,o),o};const de=e=>Math.round(e*10**8)/10**8;function Mo(e,n,t,r,o){const i=e.filter(a=>(r==="forward"?a.startNode.id===n:a.endNode.id===n)&&de(a.length)===de(t)&&Mr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(i.length===0)return[];const s=new Set;return i.forEach(a=>{const c=r==="forward"?a.endNode.id:a.startNode.id;if(!s.has(c)){s.add(c);const l=Mo(e,c,t,r,Mr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));i.push(...l)}}),i}function gK(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(i=>o.gaps.some(s=>de(i.startEdge[0].x)===de(s.startEdge[0].x)&&de(i.startEdge[0].y)===de(s.startEdge[0].y)&&de(i.startEdge[1].x)===de(s.startEdge[1].x)&&de(i.startEdge[1].y)===de(s.startEdge[1].y))&&o.gaps.some(s=>de(i.endEdge[0].x)===de(s.endEdge[0].x)&&de(i.endEdge[0].y)===de(s.endEdge[0].y)&&de(i.endEdge[1].x)===de(s.endEdge[1].x)&&de(i.endEdge[1].y)===de(s.endEdge[1].y)))){e.splice(n,1);break}}}}class zu{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 i=n.getShapeUtil(t).getBoundsSnapGeometry(t).points??n.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!i))return i.map((s,a)=>{const{x:c,y:l}=ie.applyToPoint(r,s);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 i=n.get(o);i&&r.push(...i)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),n=>({id:n,pageBounds:Gn(this.editor.getShapePageBounds(n))}))}getVisibleGaps(){const n=[],t=[];let r,o;const i=this.getSnappableGapNodes().sort((a,c)=>a.pageBounds.minX-c.pageBounds.minX);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.maxX<o.pageBounds.minX&&Gc(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:Mr(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const s=i.sort((a,c)=>a.pageBounds.minY-c.pageBounds.minY);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.maxY<o.pageBounds.minY&&Gc(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:Mr(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,y;const i=this.manager.getSnapThreshold(),s=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=s,u=[],d=[],f=new b(i,i);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:((y=d[0])==null?void 0:y.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 S=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:d}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d});return this.manager.setIndicators([...m,...S]),{nudge:p}}snapResizeShapes({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:i}){var _,k;const s=this.manager.getSnapThreshold(),{box:a,scaleX:c,scaleY:l}=J.Resize(n,r,i?t.x*2:t.x,i?t.y*2:t.y,o);let u=r;c<0&&(u=E7(u)),l<0&&(u=I7(u)),i&&(a.center=n.center);const d=u==="top"||u==="bottom",f=u==="left"||u==="right",p=tC(u,a),S=this.getSnappablePoints(),m=[],w=[],y=new b(s,s);this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:w,otherNodeSnapPoints:S,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&&_7(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,i?P.x*2:P.x,i?P.y*2:P.y,o);i&&(E.center=n.center);const C=tC("any",E);m.length=0,w.length=0,y.x=0,y.y=0,this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:w,otherNodeSnapPoints:S,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:i}){for(const s of n)for(const a of t){const c=b.Sub(s,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:s,otherPoint:a},nudge:a.x-s.x}),r.x=l),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(i.length=0),i.push({type:"points",points:{thisPoint:s,otherPoint:a},nudge:a.y-s.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:i,vertical:s}=this.getVisibleGaps();for(const a of i){if(!Gc(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 y={type:"gap_center",gap:a,nudge:l},v=r.find(({type:E})=>E==="gap_center"),P=v&&Mr(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)]=y:(!v||!P)&&r.push(y)}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 S=a.endNode.pageBounds.maxX+a.length,m=n.minX,w=S-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 s){if(!Gc(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 y={type:"gap_center",gap:a,nudge:l},v=o.find(({type:E})=>E==="gap_center"),P=v&&Gc(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)]=y:(!v||!P)&&o.push(y);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 S=a.endNode.pageBounds.maxY+a.length,m=n.minY,w=S-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 i of n)if(i.type==="points"){const s=de(i.points.otherPoint.x);r[s]||(r[s]=[]),r[s].push(i.points)}}if(t.length>0){for(const i of t)if(i.type==="points"){const s=de(i.points.otherPoint.y);o[s]||(o[s]=[]),o[s].push(i.points)}}return Object.values(r).concat(Object.values(o)).map(i=>({id:ot(),type:"points",points:p0(i.map(s=>b.From(s.otherPoint)).concat(i.map(s=>b.From(s.thisPoint))),(s,a)=>s.equals(a))}))}getGapSnapLines({selectionPageBounds:n,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:o,horizontal:i}=this.getVisibleGaps(),s={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:S}}=c;switch(c.type){case"gap_center":{const m=(p-n.width)/2,w=Mr(l[0],l[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:[...Mo(i,d.id,m,"backward",w),{startEdge:u,endEdge:s.left},{startEdge:s.right,endEdge:S},...Mo(i,f.id,m,"forward",w)]});break}case"gap_duplicate":{const m=Mr(l[0],l[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:c.protrusionDirection==="left"?[{startEdge:s.right,endEdge:u.map(w=>w.clone().addXY(-d.pageBounds.width,0))},{startEdge:u,endEdge:S},...Mo(i,f.id,p,"forward",m)]:[...Mo(i,d.id,p,"backward",m),{startEdge:u,endEdge:S},{startEdge:S.map(w=>w.clone().addXY(c.gap.endNode.pageBounds.width,0)),endEdge:s.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:S}}=c;switch(c.type){case"gap_center":{const m=(p-n.height)/2,w=Mr(l[0],l[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:[...Mo(o,d.id,m,"backward",w),{startEdge:u,endEdge:s.top},{startEdge:s.bottom,endEdge:S},...Mo(o,c.gap.endNode.id,m,"forward",w)]});break}case"gap_duplicate":{const m=Mr(l[0],l[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:c.protrusionDirection==="top"?[{startEdge:s.bottom,endEdge:u.map(w=>w.clone().addXY(0,-d.pageBounds.height))},{startEdge:u,endEdge:S},...Mo(o,f.id,p,"forward",m)]:[...Mo(o,d.id,p,"backward",m),{startEdge:u,endEdge:S},{startEdge:S.map(w=>w.clone().addXY(0,f.pageBounds.height)),endEdge:s.top}]})}break}}return gK(a),a}}Vp([V],zu.prototype,"getSnapPointsCache");Vp([V],zu.prototype,"getSnappablePoints");Vp([V],zu.prototype,"getSnappableGapNodes");Vp([V],zu.prototype,"getVisibleGaps");function tC(e,n){const{minX:t,maxX:r,minY:o,maxY:i}=n,s=[];switch(e){case"top":case"left":case"top_left":case"any":s.push({id:"top_left",handle:"top_left",x:t,y:o})}switch(e){case"top":case"right":case"top_right":case"any":s.push({id:"top_right",handle:"top_right",x:r,y:o})}switch(e){case"bottom":case"right":case"bottom_right":case"any":s.push({id:"bottom_right",handle:"bottom_right",x:r,y:i})}switch(e){case"bottom":case"left":case"bottom_left":case"any":s.push({id:"bottom_left",handle:"bottom_left",x:t,y:i})}return s}var mK=Object.defineProperty,yK=Object.getOwnPropertyDescriptor,SK=(e,n,t,r)=>{for(var o=yK(n,t),i=e.length-1,s;i>=0;i--)(s=e[i])&&(o=s(n,t,o)||o);return o&&mK(n,t,o),o};const vK=()=>null,xK=()=>[];class Q2{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??vK,getSelfSnapPoints:r.getSelfSnapPoints??xK}})}*iterateSnapPointsInPageSpace(n,t){var o,i;const r=(o=this.getSnapGeometryCache().get(n))==null?void 0:o.getSelfSnapPoints(t);if(r&&r.length){const s=Gn(this.editor.getShapePageTransform(n));for(const a of r)yield s.applyToPoint(a)}for(const s of this.manager.getSnappableShapes()){if(s===n)continue;const a=(i=this.getSnapGeometryCache().get(s))==null?void 0:i.points;if(!a||!a.length)continue;const c=Gn(this.editor.getShapePageTransform(s));for(const l of a)yield c.applyToPoint(l)}}*iterateSnapOutlines(n,t){var o,i;const r=(o=this.getSnapGeometryCache().get(n))==null?void 0:o.getSelfSnapOutline(t);r&&(yield{shapeId:n,outline:r});for(const s of this.manager.getSnappableShapes()){if(s===n)continue;const a=(i=this.getSnapGeometryCache().get(s))==null?void 0:i.outline;a&&(yield{shapeId:s,outline:a})}}getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:r}){const o=this.manager.getSnapThreshold();let i=o,s=null;for(const l of this.iterateSnapPointsInPageSpace(n,t))b.DistMin(r,l,i)&&(i=b.Dist(r,l),s=l);if(s)return s;let a=o,c=null;for(const{shapeId:l,outline:u}of this.iterateSnapOutlines(n,t)){const d=Gn(this.editor.getShapePageTransform(l)),f=this.editor.getPointInShapeSpace(l,r),p=u.nearestPoint(f),S=d.applyToPoint(p);b.DistMin(r,S,a)&&(a=b.Dist(r,S),c=S)}return c||null}snapHandle({currentShapeId:n,handle:t}){const o=Gn(this.editor.getShapePageTransform(n)).applyToPoint(t),i=this.getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:o});return i?(this.manager.setIndicators([{id:ot(),type:"points",points:[i]}]),{nudge:b.Sub(i,o)}):null}}SK([V],Q2.prototype,"getSnapGeometryCache");var wK=Object.defineProperty,bK=Object.getOwnPropertyDescriptor,Fx=(e,n,t,r)=>{for(var o=bK(n,t),i=e.length-1,s;i>=0;i--)(s=e[i])&&(o=s(n,t,o)||o);return o&&wK(n,t,o),o};class Yp{constructor(n){g(this,"shapeBounds");g(this,"handles");g(this,"_snapIndicators",rn("snapLines",void 0));this.editor=n,this.shapeBounds=new zu(this),this.handles=new Q2(this)}getIndicators(){return this._snapIndicators.get()??No}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,i=s=>{if(gr(s)){const c=n.getShape(s);c&&n.isShapeOfType(c,"frame")&&o.add(s)}const a=n.getSortedChildIdsForParent(s);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")){i(c);continue}o.add(c)}}};return i(this.getCurrentCommonAncestor()??n.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Fx([V],Yp.prototype,"getSnapThreshold");Fx([V],Yp.prototype,"getSnappableShapes");Fx([V],Yp.prototype,"getCurrentCommonAncestor");const PK=/\r?\n|\r/g;function nC(e){return e.replace(PK,`
86
- `).split(`
87
- `).map(n=>n||" ").join(`
88
- `)}const CK={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},IK=/\s/;class EK{constructor(n){g(this,"baseElm");g(this,"measureText",(n,t)=>{var s;const r=(s=this.baseElm)==null?void 0:s.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=nC(n);const o=r.scrollWidth,i=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:i.width,h:i.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(),i=-o.left,s=-o.top,a=new Range,c=n.childNodes[0];let l=0,u=null,d=null,f=0,p=0,S=!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 y=a.getClientRects(),v=y[y.length-1],P=v.top+s,E=v.left+i,C=v.right+i,I=E<p,_=IK.test(w);if(_!==d||P!==f||!u){if(u){if(t&&P!==f){S=!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===`
89
- `&&(p=0),d=_,f=P,l+=w.length}return u&&r.push(u),{spans:r,didTruncate:S}}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",CK[t.textAlign]);const i=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";i&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const s=nC(n);r.textContent=s;const{spans:a,didTruncate:c}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:i});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=s;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 rC=(typeof process<"u",r_);class _K{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=rC(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=rC(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 i=b.Sub(r,t);this.prevPoint=r.clone();const s=i.len(),a=s?i.div(s):new b(0,0),c=o.clone().lrp(a.mul(s/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 kK=Object.defineProperty,TK=Object.getOwnPropertyDescriptor,wo=(e,n,t,r)=>{for(var o=TK(n,t),i=e.length-1,s;i>=0;i--)(s=e[i])&&(o=s(n,t,o)||o);return o&&kK(n,t,o),o};class Wr{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?b9():!1)}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??ls.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??ls.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??ls.name}getLocale(){return this.user.userPreferences.get().locale??ls.locale}getColor(){return this.user.userPreferences.get().color??ls.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??ls.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??ls.isWrapMode}}wo([V],Wr.prototype,"getUserPreferences");wo([V],Wr.prototype,"getIsDarkMode");wo([V],Wr.prototype,"getEdgeScrollSpeed");wo([V],Wr.prototype,"getAnimationSpeed");wo([V],Wr.prototype,"getId");wo([V],Wr.prototype,"getName");wo([V],Wr.prototype,"getLocale");wo([V],Wr.prototype,"getColor");wo([V],Wr.prototype,"getIsSnapMode");wo([V],Wr.prototype,"getIsWrapMode");const $K={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"},MK=["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 i;const r=n.split(".");let o=this;for(let s=0;s<r.length;s++){const a=r[s],c=o.getCurrent(),l=(i=o.children)==null?void 0:i[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=$K[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(bt.measurePerformance.get()&&MK.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;bt.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",rn("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:i}=this.constructor;this.id=r,this._isActive=rn("toolIsActive"+this.id,!1),this._current=rn("toolState"+this.id,void 0),this._path=V("toolPath"+this.id,()=>{const s=this.getCurrent();return this.id+(s?`.${s.getPath()}`:"")}),this.parent=t??{},this.parent?o&&i?(this.type="branch",this.initial=i,this.children=Object.fromEntries(o().map(s=>[s.id,new s(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&i&&(this.initial=i,this.children=Object.fromEntries(o().map(s=>[s.id,new s(this.editor,this)])),this._current.set(this.children[this.initial]))),this.performanceTracker=new UE}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 Ih 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(Ih,"id","root"),g(Ih,"initial",""),g(Ih,"children",()=>[]);var AK=Object.defineProperty,jK=Object.getOwnPropertyDescriptor,re=(e,n,t,r)=>{for(var o=jK(n,t),i=e.length-1,s;i>=0;i--)(s=e[i])&&(o=s(n,t,o)||o);return o&&AK(n,t,o),o};class ee extends $9{constructor({store:t,user:r,shapeUtils:o,bindingUtils:i,tools:s,getContainer:a,cameraOptions:c,initialState:l,autoFocus:u,inferDarkMode:d,options:f}){super();g(this,"options");g(this,"store");g(this,"root");g(this,"disposables",new Set);g(this,"_tickManager");g(this,"snaps");g(this,"timers");g(this,"user");g(this,"textMeasure");g(this,"environment");g(this,"scribbles");g(this,"sideEffects");g(this,"focusManager");g(this,"getContainer");g(this,"shapeUtils");g(this,"styleProps");g(this,"bindingUtils");g(this,"history");g(this,"_crashingError",null);g(this,"_updateInstanceState",(t,r)=>{this.batch(()=>{this.store.put([{...this.getInstanceState(),...t}])},r)});g(this,"_isChangingStyleTimeout",-1);g(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}}),this));g(this,"_updateCurrentPageState",(t,r)=>{this.batch(()=>{this.store.update(t.id??this.getCurrentPageState().id,o=>({...o,...t}))},{history:"ignore",...r})});g(this,"_cameraOptions",rn("camera options",w1));g(this,"_viewportAnimation",null);g(this,"_willSetInitialBounds",!0);g(this,"_isLockedOnFollowingUser",rn("isLockedOnFollowingUser",!1));g(this,"_cameraState",rn("camera state","idle"));g(this,"_cameraStateTimeoutRemaining",0);g(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))});g(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});g(this,"_currentPageShapeIds");g(this,"_parentIdsToChildIds");g(this,"animatingShapes",new Map);g(this,"_updateShapes",t=>{this.getInstanceState().isReadonly||this.batch(()=>{var s,a;const r=[];let o,i;for(let c=0,l=t.length;c<l;c++){const u=t[c];u&&(o=this.getShape(u.id),o&&(i=$o(o,u),i!==o&&(i=((a=(s=this.getShapeUtil(o)).onBeforeUpdate)==null?void 0:a.call(s,o,i))??i,r.push(i))))}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 oK(this));g(this,"_prevCursor","default");g(this,"_shiftKeyTimeout",-1);g(this,"_setShiftKeyTimeout",()=>{this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ShiftLeft"})});g(this,"_altKeyTimeout",-1);g(this,"_setAltKeyTimeout",()=>{this.inputs.altKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Alt",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"AltLeft"})});g(this,"_ctrlKeyTimeout",-1);g(this,"_setCtrlKeyTimeout",()=>{this.inputs.ctrlKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Ctrl",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ControlLeft"})});g(this,"_restoreToolId","select");g(this,"_pinchStart",1);g(this,"_didPinch",!1);g(this,"_selectedShapeIdsAtPointerDown",[]);g(this,"_longPressTimeout",-1);g(this,"capturedPointerId",null);g(this,"performanceTracker");g(this,"performanceTrackerTimeout",-1);g(this,"dispatch",t=>(this._pendingEventsForNextTick.push(t),t.type==="pointer"&&t.name==="pointer_move"||t.type==="wheel"||t.type==="pinch"||this._flushEventsForTick(0),this));g(this,"_pendingEventsForNextTick",[]);g(this,"_flushEventForTick",t=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=t;if(t.type==="misc"){(t.name==="cancel"||t.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(t);return}t.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!t.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),t.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!t.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),t.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!t.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:i,currentPagePoint:s}=r;r.isPointing||(r.isDragging=!1);const a=this.store.unsafeGetWithoutCapture(fn),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:S}=b.SubXY(t.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:m,y:w,z:y}=nm(()=>this.getCamera()),{panSpeed:v,zoomSpeed:P}=l;this._setCamera(new b(m+d*v/y-p/y+p/(u*P),w+f*v/y-S/y+S/(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:S,z:m}=nm(()=>this.getCamera()),{x:w,y,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(y)>10?I=10*Math.sign(y)/100:I=y/100);const _=m+(I??0)*d*m;this._setCamera(new b(p+(E/_-E)-(E/m-E),S+(C/_-C)-(C/m-C),_),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new b(p+w*u/m,S+y*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=this.timers.setTimeout(()=>{this.dispatch({...t,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),t.button===P1&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,!d&&u&&this.updateInstanceState({isPenMode:!0}),t.button===C1?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===fd&&(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:S}=nm(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:m,previousScreenPoint:w}=this.inputs,{panSpeed:y}=l,v=b.Sub(m,w);this.setCamera(new b(f+v.x*y/S,p+v.y*y/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&b.Dist2(i,s)*this.getZoomLevel()>(a.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/S&&(r.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(r.isDragging=!1,r.isPointing=!1,clearTimeout(this._longPressTimeout),r.buttons.delete(t.button),this.getIsMenuOpen()||a.isPenMode&&!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 P1:{this.setCursor({type:"grab",rotation:0});break}case fd: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})}else t.button===C1&&(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(fd)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(t.type==="pointer"){t.button===fd?t.name="middle_click":t.button===O0&&(t.name="right_click");const{isPenMode:u}=this.store.unsafeGetWithoutCapture(fn);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.options={...UH,...f},this.store=t,this.history=new lK({store:t,annotateError:$=>{this.annotateError($,{origin:"history.batch",willCrashApp:!0}),this.crash($)}}),this.snaps=new Yp(this),this.timers=new zN,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...w1,...c}),this.user=new Wr(r??Bk(),d??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new EK(this),this._tickManager=new _K(this);class p extends Ih{}g(p,"initial",l??""),this.root=new p(this),this.root.children={};const S=Y2(o),m={},w={},y=new Map;for(const $ of S){const T=new $(this);m[$.type]=T;const A=v_($.props??{});w[$.type]=A;for(const N of A.keys())if(!y.has(N.id))y.set(N.id,N);else if(y.get(N.id)!==N)throw Error(`Multiple style props with id "${N.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=m,this.styleProps=w;const v=W2(i),P={};for(const $ of v){const T=new $(this);P[$.type]=T}this.bindingUtils=P;for(const $ of[...s]){if(io(this.root.children,$.id))throw Error(`Can't override tool with id "${$.id}"`);this.root.children[$.id]=new $(this,this.root)}this.environment=new iK(this),this.scribbles=new hK(this);const E=($,T)=>{let A=null;const N=$.selectedShapeIds.filter(R=>!T.has(R));N.length!==$.selectedShapeIds.length&&(A||(A={...$}),A.selectedShapeIds=N);const j=$.erasingShapeIds.filter(R=>!T.has(R));j.length!==$.erasingShapeIds.length&&(A||(A={...$}),A.erasingShapeIds=j),$.hoveredShapeId&&T.has($.hoveredShapeId)&&(A||(A={...$}),A.hoveredShapeId=null),$.editingShapeId&&T.has($.editingShapeId)&&(A||(A={...$}),A.editingShapeId=null);const O=$.hintingShapeIds.filter(R=>!T.has(R));return O.length!==$.hintingShapeIds.length&&(A||(A={...$}),A.hintingShapeIds=O),$.focusedGroupId&&T.has($.focusedGroupId)&&(A||(A={...$}),A.focusedGroupId=null),A};this.sideEffects=this.store.sideEffects;let C=new Map;const I=new Set,_=new Set;let k=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var $,T,A,N;I.clear();for(const j of _){_.delete(j);const O=this.getShape(j);if(!O)continue;const R=this.getShapeUtil(O),Y=($=R.onChildrenChange)==null?void 0:$.call(R,O);Y!=null&&Y.length&&this.updateShapes(Y)}if(k.size){const j=k;k=new Set;for(const O of j){const R=this.getBindingUtil(O);(T=R.onOperationComplete)==null||T.call(R)}}if(C.size){const j=C;C=new Map;for(const O of j.values())(N=(A=this.getBindingUtil(O.binding)).onAfterDelete)==null||N.call(A,O)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:($,T)=>{var A,N,j,O;for(const R of this.getBindingsInvolvingShape(T))k.add(R.type),R.fromId===T.id&&((N=(A=this.getBindingUtil(R)).onAfterChangeFromShape)==null||N.call(A,{binding:R,shapeBefore:$,shapeAfter:T})),R.toId===T.id&&((O=(j=this.getBindingUtil(R)).onAfterChangeToShape)==null||O.call(j,{binding:R,shapeBefore:$,shapeAfter:T}));if($.parentId!==T.parentId){const R=Y=>{var U,H,W,Z;const K=this.getShape(Y);if(K)for(const oe of this.getBindingsInvolvingShape(K))k.add(oe.type),oe.fromId===K.id&&((H=(U=this.getBindingUtil(oe)).onAfterChangeFromShape)==null||H.call(U,{binding:oe,shapeBefore:K,shapeAfter:K})),oe.toId===K.id&&((Z=(W=this.getBindingUtil(oe)).onAfterChangeToShape)==null||Z.call(W,{binding:oe,shapeBefore:K,shapeAfter:K}))};R(T.id),this.visitDescendants(T.id,R)}if($.parentId!==T.parentId&&bn(T.parentId)){const R=new Set([$.id]);this.visitDescendants($.id,Y=>{R.add(Y)});for(const Y of this.getPageStates()){if(Y.pageId===T.parentId)continue;const K=E(Y,R);K&&this.store.put([K])}}$.parentId&&gr($.parentId)&&_.add($.parentId),T.parentId!==$.parentId&&gr(T.parentId)&&_.add(T.parentId)},beforeDelete:$=>{var j,O,R,Y;if(I.has($.id))return;$.parentId&&gr($.parentId)&&_.add($.parentId),I.add($.id);const T=[];for(const K of this.getBindingsInvolvingShape($)){k.add(K.type),T.push(K.id);const U=this.getBindingUtil(K);K.fromId===$.id?((j=U.onBeforeIsolateToShape)==null||j.call(U,{binding:K,removedShape:$}),(O=U.onBeforeDeleteFromShape)==null||O.call(U,{binding:K,shape:$})):((R=U.onBeforeIsolateFromShape)==null||R.call(U,{binding:K,removedShape:$}),(Y=U.onBeforeDeleteToShape)==null||Y.call(U,{binding:K,shape:$}))}T.length&&this.deleteBindings(T);const A=new Set([$.id]),N=ye(this.getPageStates().map(K=>E(K,A)));N.length&&this.store.put(N)}},binding:{beforeCreate:$=>{var A,N;const T=(N=(A=this.getBindingUtil($)).onBeforeCreate)==null?void 0:N.call(A,{binding:$});return T||$},afterCreate:$=>{var T,A;k.add($.type),(A=(T=this.getBindingUtil($)).onAfterCreate)==null||A.call(T,{binding:$})},beforeChange:($,T)=>{var N,j;const A=(j=(N=this.getBindingUtil(T)).onBeforeChange)==null?void 0:j.call(N,{bindingBefore:$,bindingAfter:T});return A||T},afterChange:($,T)=>{var A,N;k.add(T.type),(N=(A=this.getBindingUtil(T)).onAfterChange)==null||N.call(A,{bindingBefore:$,bindingAfter:T})},beforeDelete:$=>{var T,A;(A=(T=this.getBindingUtil($)).onBeforeDelete)==null||A.call(T,{binding:$})},afterDelete:$=>{var T,A;(A=(T=this.getBindingUtil($)).onAfterDelete)==null||A.call(T,{binding:$}),k.add($.type)}},page:{afterCreate:$=>{const T=no.createId($.id),A=Rr.createId($.id);this.store.has(T)||this.store.put([no.create({id:T})]),this.store.has(A)||this.store.put([Rr.create({id:A,pageId:$.id})])},afterDelete:($,T)=>{var j,O;if(((j=this.getInstanceState())==null?void 0:j.currentPageId)===$.id){const R=(O=this.getPages().find(Y=>Y.id!==$.id))==null?void 0:O.id;R?this.store.put([{...this.getInstanceState(),currentPageId:R}]):T==="user"&&this.store.ensureStoreIsUsable()}const A=no.createId($.id),N=Rr.createId($.id);this.store.remove([A,N])}},instance:{afterChange:($,T,A)=>{var N;if(!this.store.has(T.currentPageId)){const j=this.store.has($.currentPageId)?$.currentPageId:(N=this.getPages()[0])==null?void 0:N.id;j?this.store.update(T.id,O=>({...O,currentPageId:j})):A==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:($,T)=>{if(($==null?void 0:$.selectedShapeIds)!==(T==null?void 0:T.selectedShapeIds)){const A=T.selectedShapeIds.filter(j=>{var R,Y;let O=(R=this.getShape(j))==null?void 0:R.parentId;for(;gr(O);){if(T.selectedShapeIds.includes(O))return!1;O=(Y=this.getShape(O))==null?void 0:Y.parentId}return!0});let N=null;if(A.length>0){const j=this.findCommonAncestor(ye(A.map(O=>this.getShape(O))),O=>this.isShapeOfType(O,"group"));j&&(N=j)}else T!=null&&T.focusedGroupId&&(N=T.focusedGroupId);(A.length!==T.selectedShapeIds.length||N!==T.focusedGroupId)&&this.store.put([{...T,selectedShapeIds:A,focusedGroupId:N??null}])}}}})),this._currentPageShapeIds=eK(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=JH(this.store),this.disposables.add(this.store.listen($=>{this.emit("change",$)})),this.disposables.add(this.history.dispose),this.history.ignore(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})}),l&&this.root.children[l]===void 0)throw Error(`No state found for initialState "${l}".`);this.root.enter(void 0,"initial"),this.focusManager=new sK(this,u),this.disposables.add(this.focusManager.dispose.bind(this.focusManager)),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.on("tick",this._flushEventsForTick),this.timers.requestAnimationFrame(()=>{this._tickManager.start()}),this.performanceTracker=new UE}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear()}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=_n(this.shapeUtils,r);return it(o,`No shape util found for type "${r}"`),o}getBindingUtil(t){const r=typeof t=="string"?t:t.type,o=_n(this.bindingUtils,r);return it(o,`No binding util found for type "${r}"`),o}undo(){return this._flushEventsForTick(0),this.complete(),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.complete(),this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(t){return this.history.mark(t),this}bail(){return this.history.bail(),this}bailToMark(t){return this.history.bailToMark(t),this}batch(t,r){return this.history.batch(t,r),this}annotateError(t,{origin:r,willCrashApp:o,tags:i,extras:s}){const a=this.createErrorAnnotations(r,o);return g0(t,{tags:{...a.tags,...i},extras:{...a.extras,...s}}),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 i=r.pop();if(!i)return!0;const s=o.getCurrent();if((s==null?void 0:s.id)===i){if(r.length===0)return!0;o=s;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 i;const r=t.split(".").reverse();let o=this.root;for(;r.length>0;){const s=r.pop();if(!s)return o;const a=(i=o.children)==null?void 0:i[s];if(!a)return;o=a}return o}getDocumentSettings(){return this.store.get(lS)}updateDocumentSettings(t){return this.history.ignore(()=>{this.store.put([{...this.getDocumentSettings(),...t}])}),this}getInstanceState(){return this.store.get(fn)}updateInstanceState(t,r){return this._updateInstanceState(t,{history:"ignore",...r}),t.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),t.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},2e3))),this}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(t){const r=new Set(this.getOpenMenus());return r.has(t)||(r.add(t),this.updateInstanceState({openMenus:[...r]})),this}deleteOpenMenu(t){const r=new Set(this.getOpenMenus());return r.has(t)&&(r.delete(t),this.updateInstanceState({openMenus:[...r]})),this}clearOpenMenus(){return this.getOpenMenus().length&&this.updateInstanceState({openMenus:[]}),this}getIsMenuOpen(){return this.getOpenMenus().length>0}getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return Rr.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(s=>typeof s=="string"?s:s.id),{selectedShapeIds:o}=this.getCurrentPageState(),i=new Set(o);if(r.length===i.size&&r.every(s=>i.has(s)))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 i=this.getSelectedShapeIds();return!!this.findShapeAncestor(o,s=>i.includes(s.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(i=>i.id),o=this.getSelectedShapeIds();return o.length>0&&r.length>0&&this.setSelectedShapes(o.filter(i=>!r.includes(i))),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 i=0,s=t.length;i<s;i++){const a=this.getShapePageTransform(t[i]);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 i=this.getShapeGeometry(t[0]).bounds.clone(),s=this.getShapePageTransform(t[0]);return i.point=s.applyToPoint(i.point),i}const o=J.FromPoints(this.getSelectedShapeIds().flatMap(i=>{const s=this.getShapePageTransform(i);return s?s.applyToPoints(this.getShapeGeometry(i).bounds.corners):[]}).map(i=>i.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),i=this.getZoomLevel();return new J(r,o,t.width*i,t.height*i)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const t=this.getFocusedGroupId();return t?this.getShape(t):void 0}setFocusedGroup(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==null){const o=this.getShape(r);if(!o)throw Error(`Editor.setFocusedGroup: Shape with id ${r} does not exist`);if(!this.isShapeOfType(o,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${o.type}`)}return r===this.getFocusedGroupId()?this:this.batch(()=>{this.store.update(this.getCurrentPageState().id,o=>({...o,focusedGroupId:r}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const t=this.getFocusedGroup();if(t){const r=this.findShapeAncestor(t,o=>this.isShapeOfType(o,"group"));this.setFocusedGroup((r==null?void 0:r.id)??null),this.select(t.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const t=this.getEditingShapeId();return t?this.getShape(t):void 0}setEditingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==this.getEditingShapeId()){if(r){const o=this.getShape(r);if(o&&this.getShapeUtil(o).canEdit(o))return this._updateCurrentPageState({editingShapeId:r}),this}this._updateCurrentPageState({editingShapeId:null})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const t=this.getHoveredShapeId();return t?this.getShape(t):void 0}setHoveredShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;return r===this.getHoveredShapeId()?this:(this.updateCurrentPageState({hoveredShapeId:r},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const t=this.getHintingShapeIds();return 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:p0(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(i=>i.id);r.sort();const o=this.getErasingShapeIds();return this.history.ignore(()=>{if(r.length===o.length){for(let i=0;i<r.length;i++)if(r[i]!==o[i]){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),i=this.getShapeUtil(o);o&&i.canCrop(o)&&this.updateCurrentPageState({croppingShapeId:r})}return this}getCameraId(){return no.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:i}=r.screenBounds,{x:s,y:a,z:c}=r.camera,l=new J(-s,-a,o/c,i/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}=iC(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 nn(t.constraints.initialZoom)}}getBaseZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.baseZoom==="default")return 1;const{zx:r,zy:o}=iC(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 nn(t.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(t){var o;const r=vt({...this._cameraOptions.__unsafe__getWithoutCapture(),...t});return((o=r.zoomSteps)==null?void 0:o.length)<1&&(r.zoomSteps=[1]),this._cameraOptions.set(r),this}getConstrainedCamera(t,r){const o=this.getCamera();let{x:i,y:s,z:a=o.z}=t;if(!(r!=null&&r.force)){const c=this.getCameraOptions(),l=c.zoomSteps[0],u=Ft(c.zoomSteps),d=this.getViewportScreenBounds();if(c.constraints){const{constraints:f}=c,p=Math.min(f.padding.y,d.w/2),S=Math.min(f.padding.x,d.h/2),m=J.From(c.constraints.bounds),w=(d.w-S*2)/m.w,y=(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:j,y:O,z:R}=o,Y=-j+d.w/R/2,K=-O+d.h/R/2;a=Tt(a,E,P);const U=-j+d.w/a/2,H=-O+d.h/a/2;i=j+U-Y,s=O+H-K}const C=S/a-m.x,I=p/a-m.y,_=(d.w-S*2)/a-m.w,k=(d.h-p*2)/a-m.h,$=C+_*f.origin.x,T=I+k*f.origin.y,A=typeof f.behavior=="string"?f.behavior:f.behavior.x,N=typeof f.behavior=="string"?f.behavior:f.behavior.y;if(r!=null&&r.reset)i=$,s=T;else{switch(A){case"fixed":{i=$;break}case"contain":{a<w?i=$:i=Tt(i,C+_,C);break}case"inside":{a<w?i=Tt(i,C,(d.w-S)/a-m.w):i=Tt(i,C+_,C);break}case"outside":{i=Tt(i,S/a-m.w,(d.w-S)/a);break}case"free":break;default:throw nn(A)}switch(N){case"fixed":{s=T;break}case"contain":{a<y?s=T:s=Tt(s,I+k,I);break}case"inside":{a<y?s=Tt(s,I,(d.h-p)/a-m.h):s=Tt(s,I+k,I);break}case"outside":{s=Tt(s,p/a-m.h,(d.h-p)/a);break}case"free":break;default:throw nn(N)}}}else if(a>u||a<l){const{x:f,y:p,z:S}=o;a=Tt(a,l,u),i=f+(-f+d.w/a/2)-(-f+d.w/S/2),s=p+(-p+d.h/a/2)-(-p+d.h/S/2)}}return{x:i,y:s,z:a}}_setCamera(t,r){const o=this.getCamera(),{x:i,y:s,z:a}=this.getConstrainedCamera(t,r);return o.x===i&&o.y===s&&o.z===a?this:(this.batch(()=>{const c={...o,x:i,y:s,z:a};this.history.ignore(()=>{this.store.put([c])});const{currentScreenPoint:l,currentPagePoint:u}=this.inputs,{screenBounds:d}=this.store.unsafeGetWithoutCapture(fn);if(l.x/a-i!==u.x||l.y/a-s!==u.y){const f={type:"pointer",target:"canvas",name:"pointer_move",point:b.AddXY(l,d.x,d.y),pointerId:b1.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 i=b.Cast(t);Number.isFinite(i.x)||(i.x=0),Number.isFinite(i.y)||(i.y=0),(i.z===void 0||!Number.isFinite(i.z))&&(t.z=this.getZoomLevel());const s=this.getConstrainedCamera(i,r);if(r!=null&&r.animation){const{width:a,height:c}=this.getViewportScreenBounds();this._animateToViewport(new J(-s.x,-s.y,a/s.z,c/s.z),r)}else this._setCamera(s,{...r,force:!0});return this}centerOnPoint(t,r){if(this.getCameraOptions().isLocked)return this;const{width:o,height:i}=this.getViewportPageBounds();return this.setCamera(new b(-(t.x-o/2),-(t.y-i/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(i=>this.getShapePageBounds(i))));return this.zoomToBounds(o,t),this}resetZoom(t=this.getViewportScreenCenter(),r){const{isLocked:o,constraints:i}=this.getCameraOptions();if(o)return this;const s=this.getCamera(),{x:a,y:c,z:l}=s,{x:u,y:d}=t;let f=1;if(i){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:i,z:s}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const c=this.getBaseZoom();let l=Ft(a)*c;for(let u=1;u<a.length;u++){const d=a[u-1]*c,f=a[u]*c;if(!(f-s<=(f-d)/2)){l=f;break}}this.setCamera(new b(o+(t.x/l-t.x)-(t.x/s-t.x),i+(t.y/l-t.y)-(t.y/s-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 i=this.getBaseZoom(),{x:s,y:a,z:c}=this.getCamera();let l=o[0]*i;for(let u=o.length-1;u>0;u--){const d=o[u-1]*i,f=o[u]*i;if(!(f-c>=(f-d)/2)){l=d;break}}this.setCamera(new b(s+(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 i=this.getViewportScreenBounds(),s=(r==null?void 0:r.inset)??Math.min(Kz,i.width*.28),a=this.getBaseZoom(),c=o.zoomSteps[0],l=Ft(o.zoomSteps);let u=Tt(Math.min((i.width-s)/t.w,(i.height-s)/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+(i.width-t.w*u)/2/u,-t.y+(i.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:i,start:s,end:a}=this._viewportAnimation;if(r>i){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new b(-a.x,-a.y,this.getViewportScreenBounds().width/a.width));return}const c=i-r,l=o(1-c/i),u=s.minX+(a.minX-s.minX)*l,d=s.minY+(a.minY-s.minY)*l,f=s.maxX+(a.maxX-s.maxX)*l;this._setCamera(new b(-u,-d,this.getViewportScreenBounds().width/(f-u)),{force:!0})}_animateToViewport(t,r={animation:lm}){const{animation:o,...i}=r;if(!o)return;const{duration:s=0,easing:a=on.easeInOutCubic}=o,c=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),s===0||c===0?this._setCamera(new b(-t.x,-t.y,this.getViewportScreenBounds().width/t.width),{...i}):(this._viewportAnimation={elapsed:0,duration:s/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:i=this.options.cameraSlideFriction,direction:s,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:S}=this.getCamera(),m=b.Mul(s,c*d/S);c*=1-i,c<a?l():this._setCamera(new b(f+m.x,p+m.y,S))};return this.on("tick",u),this}zoomToUser(t,r={animation:{duration:500}}){const o=this.getCollaborators().find(i=>i.userId===t);return o?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const i=o.currentPageId===this.getCurrentPageId();i||this.setCurrentPage(o.currentPageId),r&&r.animation&&!i&&(r.animation=void 0),this.centerOnPoint(o.cursor,r);const{highlightedUserIds:s}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...s,t]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],c=a.indexOf(t);c<0||(a.splice(c,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(t,r=!1){t.width=Math.max(t.width,1),t.height=Math.max(t.height,1);const o=[t.minY!==0,document.body.scrollWidth!==t.maxX,document.body.scrollHeight!==t.maxY,t.minX!==0],{screenBounds:i,insets:s}=this.getInstanceState();if(t.equals(i)&&o.every((c,l)=>c===s[l]))return this;const{_willSetInitialBounds:a}=this;if(this._willSetInitialBounds=!1,a)this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.setCamera(this.getCamera());else if(r&&!this.getInstanceState().followingUserId){const c=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.centerOnPoint(c)}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:i}=this.getInstanceState().screenBounds;return new J(t,r,o,i)}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:i,z:s}=this.getCamera();return new J(-o,-i,t/s,r/s)}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(fn),{x:o,y:i,z:s=1}=this.getCamera();return new b((t.x-r.x)/s-o,(t.y-r.y)/s-i,t.z??.5)}pageToScreen(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(fn),{x:o,y:i,z:s=1}=this.getCamera();return new b((t.x+o)*s+r.x,(t.y+i)*s+r.y,t.z??.5)}pageToViewport(t){const{x:r,y:o,z:i=1}=this.getCamera();return new b((t.x+r)*i,(t.y+o)*i,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(s=>s.userId===o).sort((s,a)=>a.lastActivityTimestamp-s.lastActivityTimestamp)[0]):No}getCollaboratorsOnCurrentPage(){const t=this.getCurrentPageId();return this.getCollaborators().filter(r=>r.currentPageId===t)}startFollowingUser(t){this.stopFollowingUser();const r=this._getCollaboratorsQuery().get().filter(s=>s.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(s=>s.followingUserId===o))return this;const i=V("latestLeaderPresence",()=>this.getCollaborators().find(s=>s.userId===t));return vs(()=>{this.updateInstanceState({followingUserId:t},{history:"ignore"});const s=Gs("update current page",()=>{const l=i.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=()=>{s(),this._isLockedOnFollowingUser.set(!1),this.off("frame",c),this.off("stop-following",a)},c=()=>{if(!i.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),S=Math.abs(d.minY-f.minY)+Math.abs(d.maxY-f.maxY);if(p<this.options.followChaseViewportSnap&&S<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const m=Tt(u*.5,.1,.8),w=new J(ad(f.minX,d.minX,m),ad(f.minY,d.minY,m),ad(f.width,d.width,m),ad(f.height,d.height,m)),y=new b(-w.x,-w.y,this.getViewportScreenBounds().width/w.width);this.stopCameraAnimation(),this._setCamera(y)};this.once("stop-following",a),this.addListener("frame",c),c()}),this}stopFollowingUser(){return this.history.ignore(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")}),this}getUnorderedRenderingShapes(t){const r=[];let o=this.options.maxShapesPerPage*2,i=this.options.maxShapesPerPage;const s=this.getErasingShapeIds(),a=(l,u,d)=>{const f=this.getShape(l);if(!f)return;u*=f.opacity;let p=!1;const S=this.getShapeUtil(f);t&&(p=!d&&s.includes(l),p&&(u*=.32)),r.push({id:l,shape:f,util:S,index:o,backgroundIndex:i,opacity:u}),o+=1,i+=1;const m=this.getSortedChildIdsForParent(l);if(!m.length)return;let w=null;S.providesBackgroundForChildren(f)&&(w=i,i=o,o+=this.options.maxShapesPerPage);for(const y of m)a(y,u,d||p);w!==null&&(i=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(ON)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(en)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(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(i=>i.id))}setCurrentPage(t){const r=typeof t=="string"?t:t.id;return this.store.has(r)?(this.stopFollowingUser(),this.complete(),this.batch(()=>this.store.put([{...this.getInstanceState(),currentPageId:r}]),{history:"record-preserveRedoStack"})):(console.error("Tried to set the current page id to a page that doesn't exist."),this)}updatePage(t){return this.getInstanceState().isReadonly?this:this.getPage(t.id)?this.batch(()=>this.store.update(t.id,o=>({...o,...t}))):this}createPage(t){return this.history.batch(()=>{if(this.getInstanceState().isReadonly||this.getPages().length>=this.options.maxPages)return;const r=this.getPages(),o=WH(t.name??"Page 1",r.map(a=>a.name));let i=t.index;(!i||r.some(a=>a.index===i))&&(i=Do(r[r.length-1].index));const s=Ko.create({meta:{},...t,name:o,index:i});this.store.put([s])}),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 i=this.getPage(r);if(i){if(r===this.getCurrentPageId()){const s=o.findIndex(c=>c.id===r),a=o[s-1]??o[s+1];this.setCurrentPage(a.id)}this.store.remove([i.id])}}),this}duplicatePage(t,r=Ko.createId()){if(this.getPages().length>=this.options.maxPages)return this;const o=typeof t=="string"?t:t.id,i=this.getPage(o);if(!i)return this;const s={...this.getCamera()},a=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(i.id));return this.batch(()=>{var u;const c=this.getPages(),l=Fl(i.index,(u=c[c.indexOf(i)+1])==null?void 0:u.index);if(this.createPage({name:i.name+" Copy",id:r,index:l}),this.setCurrentPage(r),this.setCamera(s),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(t,r){const o=typeof t=="string"?t:t.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:o,name:r}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:(this.history.ignore(()=>this.store.put(t)),this)}updateAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:(this.history.ignore(()=>{this.store.put(t.map(r=>({...this.store.get(r.id),...r})))}),this)}deleteAssets(t){if(this.getInstanceState().isReadonly)return this;const r=typeof t[0]=="string"?t:t.map(o=>o.id);return r.length<=0?this:(this.history.ignore(()=>this.store.remove(r)),this)}getAsset(t){return this.store.get(typeof t=="string"?t:t.id)}_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 ie.Identity().translate(o.x,o.y).rotate(o.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",t=>{if(bn(t.parentId))return this.getShapeLocalTransform(t);const r=this._getShapePageTransformCache().get(t.parentId)??ie.Identity();return ie.Compose(r,this.getShapeLocalTransform(t))})}getShapeParentTransform(t){const r=typeof t=="string"?t:t.id,o=this.getShape(r);return!o||bn(o.parentId)?ie.Identity():this._getShapePageTransformCache().get(o.parentId)??ie.Identity()}getShapePageTransform(t){const r=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(r)??ie.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",t=>{const r=this._getShapePageTransformCache().get(t.id);return r?J.FromPoints(ie.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(${ie.applyToPoints(ie.Inverse(o),r).map(s=>`${s.x}px ${s.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(bn(t.parentId))return;const r=this.getShapeAncestors(t.id).filter(i=>this.isShapeOfType(i,"frame"));return r.length===0?void 0:r.map(i=>this._getShapePageTransformCache().get(i.id).applyToPoints(this.getShapeGeometry(i).vertices)).reduce((i,s)=>{if(!(s&&i))return;const a=QP(i,s);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:i}=r;if(i.every((a,c)=>a&&b.Equals(a,o[c])))return r.clone();const s=QP(o,i);return s?J.FromPoints(s):void 0}return r})}getShapeAncestors(t,r=[]){const o=typeof t=="string"?t:t.id,i=this.getShape(o);if(!i)return r;const s=i.parentId;if(bn(s))return r.reverse(),r;const a=this.store.get(s);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(t,r){const o=typeof t=="string"?t:t.id,i=this.getShape(o);if(!i)return;const s=i.parentId;if(bn(s))return;const a=this.getShape(s);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,i=o&&this.getShape(o);return i?i.parentId===r?!0:this.hasAncestor(this.getShapeParent(i),r):!1}findCommonAncestor(t,r){var l;if(t.length===0)return;const o=typeof t[0]=="string"?t:t.map(u=>u.id),i=ye(o.map(u=>this.getShape(u)));if(i.length===1){const u=i[0].parentId;return bn(u)?void 0:r?(l=this.findShapeAncestor(i[0],r))==null?void 0:l.id:u}const[s,...a]=i;let c=this.getShapeParent(s);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 QH(this)}getCulledShapes(){const t=this._notVisibleShapes().get(),r=this.getSelectedShapeIds(),o=this.getEditingShapeId(),i=new Set(t);return o&&i.delete(o),r.forEach(s=>{i.delete(s)}),i}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(),i=this.getViewportPageBounds(),{filter:s,margin:a=0,hitLocked:c=!1,hitLabels:l=!1,hitInside:u=!1,hitFrameInside:d=!1}=r;let f=1/0,p=null,S=1/0,m=null;const w=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(y=>{if(y.isLocked&&!c||this.isShapeOfType(y,"group"))return!1;const v=this.getShapeMask(y);return v&&!Jn(t,v)?!1:s?s(y):!0});for(let y=w.length-1;y>=0;y--){const v=w[y],P=this.getShapeGeometry(v),E=P instanceof Br,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(i))continue;if(Math.abs(I)<a)Math.abs(I)<S&&(S=Math.abs(I),m=v);else if(!m){const{area:_}=P;_<f&&(f=_,p=v)}}}else if(I<this.options.hitTestMargin/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:i=!1,margin:s=0}=o,a=typeof t=="string"?t:t.id,c=this.getShapeMask(a);return c&&!Jn(r,c)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(t,r),s,i)}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,i=this.getShape(o);if(!i)return new b(0,0);if(bn(i.parentId))return b.From(r);const s=this.getShapePageTransform(i.parentId);return s?s.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,i=r.length;o<i;o++)J2(this,r[o],t);return t}getCurrentPageRenderingShapesSorted(){const t=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:r})=>!t.has(r))}isShapeOfType(t,r){const o=typeof t=="string"?this.getShape(t):t;return o?o.type===r:!1}getShape(t){const r=typeof t=="string"?t:t.id;if(gr(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||!gr(o.parentId)))return this.store.get(o.parentId)}getShapeNearestSibling(t,r){return r?r.parentId===t.parentId?r:this.findShapeAncestor(r,i=>i.parentId===t.parentId):void 0}isShapeInPage(t,r=this.getCurrentPageId()){const o=typeof t=="string"?t:t.id,i=this.getShape(o);if(!i)return!1;let s=!1;if(i.parentId===r)s=!0;else{let a=this.getShape(i.parentId);e:for(;a;){if(a.parentId===r){s=!0;break e}a=this.getShape(a.parentId)}}return s}getAncestorPageId(t){const r=typeof t=="string"?t:t==null?void 0:t.id,o=r&&this.getShape(r);if(o)return bn(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(t,r,o){const i=typeof t[0]=="string"?t:t.map(S=>S.id);if(i.length===0)return this;const s=[],a=bn(r)?ie.Identity():this.getShapePageTransform(r),c=a.rotation();let l=[];const u=ye(this.getSortedChildIdsForParent(r).map(S=>this.getShape(S)));if(o){const S=u.find(m=>m.index===o);if(S){const m=u[u.indexOf(S)+1];m?l=tc(o,m.index,i.length):l=em(o,i.length)}else{const m=u.sort(en).find(w=>w.index>o);m?l=tc(o,m.index,i.length):l=em(o,i.length)}}else{const S=u.length&&u[u.length-1];l=S?em(S.index,i.length):Nl(i.length)}const d=a.clone().invert(),f=ye(i.map(S=>this.getShape(S))),p=f.filter(S=>S.isLocked);p.length&&this.updateShapes(p.map(({id:S,type:m})=>({id:S,type:m,isLocked:!1})));for(let S=0;S<f.length;S++){const m=f[S],w=this.getShapePageTransform(m);if(!w)continue;const y=w.point();if(!y)continue;const v=d.applyToPoint(y),P=w.rotation()-c;s.push({id:m.id,type:m.type,parentId:r,x:v.x,y:v.y,rotation:P,index:l[S],isLocked:m.isLocked})}return this.updateShapes(s),this}getHighestIndexForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const i=this.getShape(o[o.length-1]);return Do(i.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o||No}visitDescendants(t,r){const o=typeof t=="string"?t:t.id,i=this.getSortedChildIdsForParent(o);for(const s of i)r(s)!==!1&&this.visitDescendants(s,r);return this}getShapeAndDescendantIds(t){const r=new Set;for(const o of t.map(i=>this.getShape(i)).sort(en))r.add(o.id),this.visitDescendants(o,i=>{r.add(i)});return r}getDroppingOverShape(t,r=[]){const o=this.getCurrentPageShapesSorted();for(let i=o.length-1;i>=0;i--){const s=o[i];if(this.getSelectedShapeIds().includes(s.id)||!this.getShapeUtil(s).canDropShapes(s,r)||r.find(c=>c.id===s.id||this.hasAncestor(s,c.id)))continue;const a=this.getShapeMaskedPageBounds(s.id);if(a&&a.containsPoint(t)&&this.getShapeGeometry(s).hitTestPoint(this.getPointInShapeSpace(s,t),0,!0))return s}}getOutermostSelectableShape(t,r){const o=typeof t=="string"?t:t.id,i=this.getShape(o);let s=i,a=i;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))s=a;else if((c==null?void 0:c.id)===a.id)break;a=this.getShapeParent(a)}return s}_getBindingsIndexCache(){const t=qH(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(i=>i.fromId===o&&i.type===r)}getBindingsToShape(t,r){const o=typeof t=="string"?t:t.id;return this.getBindingsInvolvingShape(o).filter(i=>i.toId===o&&i.type===r)}getBindingsInvolvingShape(t,r){const o=typeof t=="string"?t:t.id,i=this._getBindingsIndexCache().get(o)??No;return r?i.filter(s=>s.type===r):i}createBindings(t){const r=[];for(const o of t){const i=this.getShape(o.fromId),s=this.getShape(o.toId);if(!i||!s||!this.canBindShapes({fromShape:i,toShape:s,binding:o}))continue;const c=this.getBindingUtil(o.type).getDefaultProps(),l=this.store.schema.types.binding.create({...o,id:o.id??ws(),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 i=this.getBinding(o.id);if(!i)continue;const s=$o(i,o);if(s===i)continue;const a=this.getShape(s.fromId),c=this.getShape(s.toId);!a||!c||this.canBindShapes({fromShape:a,toShape:c,binding:s})&&r.push(s)}return this.store.put(r),this}updateBinding(t){return this.updateBindings([t])}deleteBindings(t,{isolateShapes:r=!1}={}){const o=t.map(i=>typeof i=="string"?i:i.id);return r?this.store.atomic(()=>{var i,s;for(const a of o){const c=this.getBinding(a);if(!c)continue;const l=this.getBindingUtil(c);(i=l.onBeforeIsolateFromShape)==null||i.call(l,{binding:c,removedShape:this.getShape(c.toId)}),(s=l.onBeforeIsolateToShape)==null||s.call(l,{binding:c,removedShape:this.getShape(c.fromId)}),this.store.remove([a])}}):this.store.remove(o),this}deleteBinding(t,r){return this.deleteBindings([t],r)}canBindShapes({fromShape:t,toShape:r,binding:o}){const i=typeof t=="string"?t:t.type,s=typeof r=="string"?r:r.type,a=typeof o=="string"?o:o.type,c={fromShapeType:i,toShapeType:s,bindingType:a};return i===s?this.getShapeUtil(i).canBind(c):this.getShapeUtil(i).canBind(c)&&this.getShapeUtil(s).canBind(c)}rotateShapesBy(t,r){if((typeof t[0]=="string"?t:t.map(s=>s.id)).length<=0)return this;const i=X2({editor:this});return i?(Ch({delta:r,snapshot:i,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(t,r){var s,a,c;let o=t;const i=this.getShapeUtil(t);return o=$o(o,((s=i.onTranslateStart)==null?void 0:s.call(i,o))??void 0),o=$o(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=$o(o,((a=i.onTranslate)==null?void 0:a.call(i,t,o))??void 0),o=$o(o,((c=i.onTranslateEnd)==null?void 0:c.call(i,t,o))??void 0),o}nudgeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(s=>s.id);if(o.length<=0)return this;const i=[];for(const s of o){const a=this.getShape(s),c=b.From(r),l=this.getShapeParentTransform(a);l&&c.rot(-l.rotation()),i.push(this.getChangesToTranslateShape(a,c.add(a)))}return this.updateShapes(i),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 i=new Set(o),s=this.getShapeAndDescendantIds(o),a=[...s].reverse(),c=new Map;for(const f of s)c.set(f,Be());const{shapesToCreate:l,bindingsToCreate:u}=oC(this,s,f=>{const p=[];for(const m of f){const w=this.getBinding(m);if(!w)continue;const y=ws();p.push({...w,id:y,fromId:Gn(c.get(w.fromId)),toId:Gn(c.get(w.toId))})}const S=[];for(const m of a){const w=Gn(c.get(m)),y=this.getShape(m);if(!y)continue;let v=0,P=0;if(r&&i.has(m)){const T=this.getShapeParentTransform(y),A=new b(r.x,r.y).rot(-T.rotation());v=A.x,P=A.y}const E=y.parentId,C=this.getSortedChildIdsForParent(E),I=C.indexOf(y.id),_=C[I+1],k=_?this.getShape(_):null,$=k?Fl(y.index,k.index):Do(y.index);S.push({...y,id:w,x:y.x+v,y:y.y+P,index:$,parentId:c.get(y.parentId)??y.parentId})}return{shapesToCreate:S,bindingsToCreate:p}});if(l.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){jd(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:this.options.animationMediumMs}})}}),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 i=this.getCurrentPageId();if(r===i)return this;if(!this.store.has(r))return this;const s=this.getContentFromCurrentPage(o);if(!s)return this;if(this.getPageShapeIds(r).size+s.shapes.length>this.options.maxShapesPerPage)return jd(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(s,{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,i=!0;const s=[];for(const a of r){const c=this.getShape(a);c&&(s.push(c),c.isLocked?i=!1:o=!1)}return this.batch(()=>{i?(this.updateShapes(s.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):o?this.updateShapes(s.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(s.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(t){const r=typeof t[0]=="string"?t:t.map(i=>i.id),o=Ad(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(i=>i.id),o=Ad(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(i=>i.id),o=Ad(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(i=>i.id),o=Ad(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 i=ye(o.map(a=>this.getShape(a)));if(!i.length)return this;i=ye(i.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(c=>this.getShape(c)):a).flat());const s=J.Common(ye(i.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of i){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:s,scaleAxisRotation:0})}}),this}stackShapes(t,r,o){const i=typeof t[0]=="string"?t:t.map(w=>w.id);if(this.getInstanceState().isReadonly)return this;const s=i.map(w=>this.getShape(w)).filter(w=>w?this.getShapeUtil(w).canBeLaidOut(w):!1),a=s.length;if(o===0&&a<3||a<2)return this;const c=Object.fromEntries(s.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=[];s.sort((v,P)=>c[v.id][u]-c[P.id][u]);for(let v=0;v<a-1;v++){const P=s[v],E=s[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 y=0;w.forEach(v=>{v.count>y&&(y=v.count,p=v.gap)}),y===1&&(p=Math.max(0,w.reduce((v,P)=>v+P.gap*P.count,0)/(a-1)))}else p=o;const S=[];let m=c[s[0].id][d];return s.forEach((w,y)=>{var I,_;if(y===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);S.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(S),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 i=o.map($=>this.getShape($)).filter($=>$?this.getShapeUtil($).canBeLaidOut($):!1),s={},a={};let c,l,u=0;for(let $=0;$<i.length;$++)c=i[$],l=this.getShapePageBounds(c),s[c.id]=l,a[c.id]=l.clone(),u+=l.width*l.height;const d=J.Common(ye(Object.values(s))),f=d.width;i.sort(($,T)=>s[T.id].height-s[$.id].height);const p=Math.max(Math.ceil(Math.sqrt(u/.95)),f),S=[new J(d.x,d.y,p,1/0)];let m=0,w=0,y,v;for(let $=0;$<i.length;$++){c=i[$],l=a[c.id];for(let T=S.length-1;T>=0;T--)if(y=S[T],!(l.width>y.width||l.height>y.height)){l.x=y.x,l.y=y.y,w=Math.max(w,l.maxY),m=Math.max(m,l.maxX),l.width===y.width&&l.height===y.height?(v=S.pop(),T<S.length&&(S[T]=v)):l.height===y.height?(y.x+=l.width+r,y.width-=l.width+r):l.width===y.width?(y.y+=l.height+r,y.height-=l.height+r):(S.push(new J(y.x+(l.width+r),y.y,y.width-(l.width+r),l.height)),y.y+=l.height+r,y.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;$<i.length;$++){c=i[$],l=s[c.id],C=a[c.id];const T=b.Sub(C.point,l.point).add(E),A=this.getShapeParentTransform(c);A&&T.rot(-A.rotation());const N={id:c.id,type:c.type,x:c.x+T.x,y:c.y+T.y},j=(k=(_=this.getShapeUtil(c)).onTranslateStart)==null?void 0:k.call(_,{...c,...N});j?I.push({...N,...j}):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 i=ye(o.map(l=>this.getShape(l))),s=Object.fromEntries(i.map(l=>[l.id,this.getShapePageBounds(l)])),a=J.Common(ye(Object.values(s))),c=[];return i.forEach(l=>{const u=s[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 i=o.length,s=ye(o.map(P=>this.getShape(P))),a=Object.fromEntries(s.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=[],S=s.sort((P,E)=>a[P.id][l]-a[E.id][l])[0],m=s.sort((P,E)=>a[E.id][u]-a[P.id][u])[0],w=a[S.id][d],y=(a[m.id][d]-w)/(i-1),v=w+y;return s.filter(P=>P!==S&&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+y*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 i=ye(o.map(l=>this.getShape(l))),s=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 i){if(this.getShapePageTransform(l).rotation()%Re)continue;const d=s[l.id],f=a[l.id],p=new b(0,c.minY-f.minY),S=this.getShapeParentTransform(l);S&&p.rot(-S.rotation());const{x:m,y:w}=b.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:m,y:w}]);const y=new b(1,c.height/f.height);this.resizeShape(l.id,y,{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 i){const u=s[l.id],d=a[l.id];if(this.getShapePageTransform(l).rotation()%Re)continue;const p=new b(c.minX-d.minX,0),S=this.getShapeParentTransform(l);S&&p.rot(-S.rotation());const{x:m,y:w}=b.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:m,y:w}]);const y=new b(c.width/d.width,1);this.resizeShape(l.id,y,{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 S,m,w;const i=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 s=o.initialShape??this.getShape(i);if(!s)return this;const a=o.scaleOrigin??((S=this.getShapePageBounds(i))==null?void 0:S.center);if(!a)return this;const c=o.initialPageTransform?ie.Cast(o.initialPageTransform):this.getShapePageTransform(i);if(!c)return this;const l=c.rotation();if(l==null)return this;const u=o.scaleAxisRotation??l,d=o.initialBounds??this.getShapeGeometry(i).bounds;if(!d)return this;const f=o.isAspectRatioLocked??this.getShapeUtil(s).isAspectRatioLocked(s);if(!ak(l,u))return this._resizeUnalignedShape(i,r,{...o,initialBounds:d,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:c,isAspectRatioLocked:f,initialShape:s});const p=this.getShapeUtil(s);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(s)){const y=this._scalePagePoint(ie.applyToPoint(c,new b(0,0)),a,r,u),v=this.getPointInParentSpace(s.id,y),P=new b(r.x,r.y),E=Ua((l-u)%Math.PI,0);P.x=E?r.x:r.y,P.y=E?r.y:r.x;const C=ie.applyToPoint(c,new b),{x:I,y:_}=this.getPointInParentSpace(s.id,C);let k=s;o.skipStartAndEndCallbacks||(k=$o(s,((m=p.onResizeStart)==null?void 0:m.call(p,s))??void 0)),k=$o(k,{id:i,type:s.type,x:v.x,y:v.y,...p.onResize({...s,x:I,y:_},{newPoint:v,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:P.x,scaleY:P.y,initialBounds:d,initialShape:s})}),o.skipStartAndEndCallbacks||(k=$o(k,((w=p.onResizeEnd)==null?void 0:w.call(p,s,k))??void 0)),this.updateShapes([k])}else{const y=ie.applyToPoint(c,d.center),v=this._scalePagePoint(y,a,r,u),P=this.getPointInParentSpace(s.id,y),E=this.getPointInParentSpace(s.id,v),C=b.Sub(E,P);this.updateShapes([{id:i,type:s.type,x:s.x+C.x,y:s.y+C.y}])}return this}_scalePagePoint(t,r,o,i){const s=b.RotWith(t,r,-i).sub(r),a=b.MulV(s,o);return b.Add(a,r).rotWith(r,i)}_resizeUnalignedShape(t,r,o){const{type:i}=o.initialShape,s=new b(r.x,r.y);if(Math.abs(r.x)>Math.abs(r.y)?s.x=Math.sign(r.x)*Math.abs(r.y):s.y=Math.sign(r.y)*Math.abs(r.x),this.resizeShape(t,s,{initialShape:o.initialShape,initialBounds:o.initialBounds,isAspectRatioLocked:o.isAspectRatioLocked}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:y}=ie.Decompose(o.initialPageTransform);y-=2*y,this.updateShapes([{id:t,type:i,rotation:y}])}const a=ie.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),S=b.Add(f,p),{x:m,y:w}=this.getPointInParentSpace(t,S);return this.updateShapes([{id:t,type:i,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>this.options.maxShapesPerPage)return jd(this),this;const i=this.getFocusedGroupId();return this.batch(()=>{var d,f;const s=this.getCurrentPageShapesSorted(),a=t.map(p=>{if(p.id||(p={id:Be(),...p}),!p.parentId||!(this.store.has(p.parentId)||t.some(S=>S.id===p.parentId))){let S=this.getFocusedGroupId();for(let w=s.length-1;w>=0;w--){const y=s[w];if(this.getShapeUtil(y).canReceiveNewChildrenOfType(y,p.type)&&this.isPointInShape(y,{x:p.x??0,y:p.y??0},{margin:0,hitInside:!0})){S=y.id;break}}const m=p.parentId;if(S===p.id&&(S=i),S!==m&&(p={...p},p.parentId=S,gr(S))){const w=this.getPointInShapeSpace(this.getShape(S),{x:p.x??0,y:p.y??0});p.x=w.x,p.y=w.y,p.rotation=-this.getShapePageTransform(S).rotation()+(p.rotation??0)}}return p}),c=new Map,l=[],{opacityForNextShape:u}=this.getInstanceState();for(const p of a){const S=this.getShapeUtil(p);let m=p.index;if(!m){const P=p.parentId??i;c.has(P)||c.set(P,this.getHighestIndexForParent(P)),m=c.get(P),c.set(P,Do(m))}const w=S.getDefaultProps();for(const[P,E]of this.styleProps[p.type])w[E]=this.getStyleForNextShape(P);let y=this.store.schema.types.shape.create({...p,index:m,opacity:p.opacity??u,parentId:p.parentId??i,props:"props"in p?{...w,...p.props}:w});if(y.index===void 0)throw Error("no index!");const v=(f=(d=this.getShapeUtil(y)).onBeforeCreate)==null?void 0:f.call(d,y);v&&(y=v),l.push(y)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)})}animateShape(t,r={animation:lm}){return this.animateShapes([t],r)}animateShapes(t,r={animation:lm}){if(!r.animation)return this;const{duration:o=500,easing:i=on.linear}=r.animation,s=ot();let a=o,c;const l=[];let u,d;for(let S=0,m=t.length;S<m;S++){if(u=t[S],!u)continue;d={partial:u,values:[]};const w=this.getShape(u.id);if(w){for(const y of["x","y","rotation"])u[y]!==void 0&&w[y]!==u[y]&&d.values.push({prop:y,from:w[y],to:u[y]});l.push(d),this.animatingShapes.set(w.id,s)}}let f;const p=S=>{if(a-=S,a<0){const{animatingShapes:v}=this,P=t.filter(E=>E&&v.get(E.id)===s);P.length&&this.updateShapes(P),this.off("tick",p);return}c=i(1-a/o);const{animatingShapes:m}=this,w=[];let y;for(let v=0,P=l.length;v<P;v++)f=l[v],y=m.get(f.partial.id),y===s&&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={}){var m;const{groupId:o=Be(),select:i=!0}=r;if(!Array.isArray(t))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const s=typeof t[0]=="string"?t:t.map(w=>w.id);if(s.length<=1)return this;const a=ye(this._getUnlockedShapeIds(s).map(w=>this.getShape(w))),c=a.sort(en).map(w=>w.id),l=J.Common(ye(a.map(w=>this.getShapePageBounds(w)))),{x:u,y:d}=l.point,f=this.findCommonAncestor(a)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const p=a.filter(w=>w.parentId===f).sort(en),S=(m=p[p.length-1])==null?void 0:m.index;return this.batch(()=>{this.createShapes([{id:o,type:"group",parentId:f,index:S,x:u,y:d,opacity:1,props:{}}]),this.reparentShapes(c,o),i&&this.select(o)}),this}ungroupShapes(t,r={}){const{select:o=!0}=r,i=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(i.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const s=new Set,a=[];return ye(i.map(c=>this.getShape(c))).forEach(c=>{this.isShapeOfType(c,"group")?a.push(c):s.add(c.id)}),a.length===0?this:(this.batch(()=>{let c;for(let l=0,u=a.length;l<u;l++){c=a[l];const d=this.getSortedChildIdsForParent(c.id);for(let f=0,p=d.length;f<p;f++)s.add(d[f]);this.reparentShapes(d,c.parentId,c.index)}this.deleteShapes(a.map(l=>l.id)),o&&this.select(...s)}),this)}updateShape(t){return this.updateShapes([t]),this}updateShapes(t){const r=Array(t.length);for(let o=0,i=t.length;o<i;o++){const s=t[o];if(!s)continue;const a=this.getShape(s.id);a&&(this.isShapeOrAncestorLocked(a)&&!Object.hasOwn(s,"isLocked")||(this.animatingShapes.delete(s.id),r.push(s)))}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(s=>s.id));if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;const o=new Set(r);for(const s of r)this.visitDescendants(s,a=>{o.add(a)});const i=[...o];return this.batch(()=>this.store.remove(i))}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 i=0,s=o.length;i<s;i++)this._extractSharedStyles(this.getShape(o[i]),r)}else for(const[o,i]of this.styleProps[t.type])r.applyValue(o,_n(t.props,i))}_getSelectionSharedStyles(){const t=this.getSelectedShapes(),r=new lv;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 _n(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const t=this.root.getCurrent(),r=new lv;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=i=>{const s=this.getShape(i);if(s)if(this.isShapeOfType(s,"group"))for(const a of this.getSortedChildIdsForParent(s.id))r(a);else t.push(s)};for(const i of this.getSelectedShapeIds())r(i);let o=null;for(const i of t)if(o===null)o=i.opacity;else if(o!==i.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=[],i=s=>{if(this.isShapeOfType(s,"group")){const a=this.getSortedChildIdsForParent(s);for(const c of a)i(this.getShape(c))}else o.push(s)};for(const s of r)i(s);this.updateShapes(o.map(s=>({id:s.id,type:s.type,opacity:t})))}return this}setStyleForNextShapes(t,r,o){const i=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...i,[t.id]:r}},o),this}setStyleForSelectedShapes(t,r){const o=this.getSelectedShapes();if(o.length>0){const i=[],s=a=>{if(this.isShapeOfType(a,"group")){const c=this.getSortedChildIdsForParent(a.id);for(const l of c)s(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}};i.push({util:c,originalShape:a,updatePartial:u})}}};for(const a of o)s(a);this.updateShapes(i.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(i=>i.id);if(!r||r.length===0)return;const o=this.getShapeAndDescendantIds(r);return oC(this,o,i=>{const s=[];for(const d of i){const f=this.getBinding(d);f&&s.push(f)}const a=[],c=[];for(const d of o){const f=this.getShape(d);if(!f)continue;if(!o.has(f.parentId)){const S=this.getShapePageTransform(f.id),m=S.point();c.push({...f,x:m.x,y:m.y,rotation:S.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:s,assets:l}})}putContentOntoCurrentPage(t,r={}){var A,N;if(this.getInstanceState().isReadonly)return this;if(!t.schema)throw Error(`Could not put content:
90
- content is missing a schema.`);const{select:o=!1,preserveIds:i=!1,preservePosition:s=!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(j=>[j.id,j])),...Object.fromEntries(t.shapes.map(j=>[j.id,j])),...Object.fromEntries(((A=t.bindings)==null?void 0:A.map(j=>[j.id,j]))??[])},schema:t.schema},S=this.store.schema.migrateStoreSnapshot(p);if(S.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(S.value))switch(j.typeName){case"asset":{u.push(j);break}case"shape":{d.push(j);break}case"binding":{f.push(j);break}}const m=new Map(i?d.map(j=>[j.id,j.id]):d.map(j=>[j.id,Be()])),w=new Map(i?f.map(j=>[j.id,j.id]):f.map(j=>[j.id,ws()]));let y=this.getCurrentPageId(),v=1/0,P=[];for(const j of this.getSelectedShapes()){if(v===0)break;const O=this.isShapeOfType(j,"frame"),R=this.getShapeAncestors(j);O&&R.push(j);const Y=O?R.length+1:R.length;if(Y<v)v=Y,P=R,y=O?j.id:j.parentId;else if(Y===v){if(P.length!==R.length)throw Error(`Ancestors: ${P.length} !== ${R.length}`);if(P.length===0){y=c;break}else{y=c;for(let K=0;K<P.length&&R[K]===P[K];K++)y=R[K].id}}}let E=!1;if(!bn(y)){const j=this.getShape(y);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))y=c;else if(l.length===1){const O=d.find(R=>R.id===l[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(j==null?void 0:j.props.w)&&O.props.h===(j==null?void 0:j.props.h)&&(E=!0)}}else y=c}E||(E=m.has(y)),E&&(y=this.getShape(y).parentId);let C=this.getHighestIndexForParent(y);const I=[],_=d.map(j=>{const O=m.get(j.id),R={...j,id:O};return l.includes(j.id)&&(R.parentId=c,I.push(R)),m.has(R.parentId)?R.parentId=m.get(j.parentId):(l.push(R.id),R.index=C,C=Do(C)),R});if(_.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return jd(this),this;const k=f.map(j=>({...j,id:Gn(w.get(j.id)),fromId:Gn(m.get(j.fromId)),toId:Gn(m.get(j.toId))})),$=[],T=[];for(const j of u)this.store.has(j.id)||((j.type==="image"||j.type==="video")&&((N=j.props.src)!=null&&N.startsWith("data:image"))&&(T.push(vt(j)),j.props.src=null),$.push(j));return Promise.allSettled(T.map(async j=>{const O=await KH(j.props.src,j.props.name,j.props.mimeType??"image/png"),R=await this.getAssetForExternalContent({type:"file",file:O});if(!R){this.deleteAssets([j.id]);return}this.updateAssets([{...R,id:j.id}])})),this.batch(()=>{$.length>0&&this.createAssets($),this.createShapes(_),this.createBindings(k),o&&this.select(...I.map(K=>K.id)),y!==c&&this.reparentShapes(I.map(K=>K.id),y);const j=_.map(K=>this.getShape(K.id)),O=J.Common(j.map(K=>this.getShapePageBounds(K)));if(a===void 0)if(bn(y)){const K=this.getViewportPageBounds();s||K.includes(J.From(O))?a=O.center:a=K.center}else{const K=this.getShape(y);a=ie.applyToPoint(this.getShapePageTransform(K),this.getShapeGeometry(K).bounds.center)}if(I.length===1){const K=I[0];if(this.isShapeOfType(K,"frame"))for(;this.getShapesAtPoint(a).some(U=>this.isShapeOfType(U,"frame")&&U.props.w===K.props.w&&U.props.h===K.props.h);)a.x+=O.w+16}const R=J.Common(ye(I.map(({id:K})=>this.getShapePageBounds(K)))).center,Y=b.Sub(a,R);this.updateShapes(I.map(({id:K})=>{const U=this.getShape(K),H=this.getShapeParentTransform(K).decompose().rotation,W=b.Rot(Y,-H);return{id:U.id,type:U.type,x:U.x+W.x,y:U.y+W.y}}))}),this}async getSvgElement(t,r={}){const o=await nK(this,t,r);if(!o)return;const i=document.createDocumentFragment(),s=K2(i);Xs.flushSync(()=>{s.render(o.jsx)});const a=i.firstElementChild;return it(a instanceof SVGSVGElement,"Expected an SVG element"),s.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:i,currentScreenPoint:s,currentPagePoint:a}=this.inputs,{screenBounds:c}=this.store.unsafeGetWithoutCapture(fn),{x:l,y:u,z:d}=this.store.unsafeGetWithoutCapture(this.getCameraId()),f=t.point.x-c.x,p=t.point.y-c.y,S=t.point.z??.5;o.setTo(s),i.setTo(a),s.set(f,p);const m=f/d-l,w=p/d-u;isFinite(m)&&isFinite(w)&&a.set(m,w,S),this.inputs.isPen=t.type==="pointer"&&t.isPen,(t.name==="pointer_down"||this.inputs.isPinching)&&(r.set(0,0),this.inputs.originScreenPoint.setTo(s),this.inputs.originPagePoint.setTo(a)),this.history.ignore(()=>{var y;this.store.put([{id:If,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===b1.CAMERA_MOVE?((y=this.store.unsafeGetWithoutCapture(If))==null?void 0:y.lastActivityTimestamp)??this._tickManager.now:this._tickManager.now,meta:{}}])})}cancel(){return this.dispatch({type:"misc",name:"cancel"}),this}interrupt(){return this.dispatch({type:"misc",name:"interrupt"}),this}complete(){return this.dispatch({type:"misc",name:"complete"}),this}focus({focusContainer:t=!0}={}){return t&&this.focusManager.focus(),this.updateInstanceState({isFocused:!0}),this}blur({blurContainer:t=!0}={}){return this.getIsFocused()?(t?this.focusManager.blur():this.complete(),this.updateInstanceState({isFocused:!1}),this):this}getIsFocused(){return this.getInstanceState().isFocused}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){bt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(t),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}re([V],ee.prototype,"getCanUndo");re([V],ee.prototype,"getCanRedo");re([V],ee.prototype,"getPath");re([V],ee.prototype,"getCurrentTool");re([V],ee.prototype,"getCurrentToolId");re([V],ee.prototype,"getDocumentSettings");re([V],ee.prototype,"getInstanceState");re([V],ee.prototype,"getOpenMenus");re([V],ee.prototype,"getIsMenuOpen");re([V],ee.prototype,"getPageStates");re([V],ee.prototype,"_getPageStatesQuery");re([V],ee.prototype,"getCurrentPageState");re([V],ee.prototype,"_getCurrentPageStateId");re([V],ee.prototype,"getSelectedShapeIds");re([V],ee.prototype,"getSelectedShapes");re([V],ee.prototype,"getOnlySelectedShapeId");re([V],ee.prototype,"getOnlySelectedShape");re([V],ee.prototype,"getSelectionPageBounds");re([V],ee.prototype,"getSelectionRotation");re([V],ee.prototype,"getSelectionRotatedPageBounds");re([V],ee.prototype,"getSelectionRotatedScreenBounds");re([V],ee.prototype,"getFocusedGroupId");re([V],ee.prototype,"getFocusedGroup");re([V],ee.prototype,"getEditingShapeId");re([V],ee.prototype,"getEditingShape");re([V],ee.prototype,"getHoveredShapeId");re([V],ee.prototype,"getHoveredShape");re([V],ee.prototype,"getHintingShapeIds");re([V],ee.prototype,"getHintingShape");re([V],ee.prototype,"getErasingShapeIds");re([V],ee.prototype,"getErasingShapes");re([V],ee.prototype,"getCameraId");re([V],ee.prototype,"getCamera");re([V],ee.prototype,"getViewportPageBoundsForFollowing");re([V],ee.prototype,"getCameraForFollowing");re([V],ee.prototype,"getZoomLevel");re([V],ee.prototype,"getViewportScreenBounds");re([V],ee.prototype,"getViewportScreenCenter");re([V],ee.prototype,"getViewportPageBounds");re([V],ee.prototype,"_getCollaboratorsQuery");re([V],ee.prototype,"getCollaborators");re([V],ee.prototype,"getCollaboratorsOnCurrentPage");re([V],ee.prototype,"getRenderingShapes");re([V],ee.prototype,"_getAllPagesQuery");re([V],ee.prototype,"getPages");re([V],ee.prototype,"getCurrentPageId");re([V],ee.prototype,"getCurrentPageShapeIdsSorted");re([V],ee.prototype,"_getAllAssetsQuery");re([V],ee.prototype,"_getShapeGeometryCache");re([V],ee.prototype,"_getShapeHandlesCache");re([V],ee.prototype,"_getShapePageTransformCache");re([V],ee.prototype,"_getShapePageBoundsCache");re([V],ee.prototype,"_getShapeClipPathCache");re([V],ee.prototype,"_getShapeMaskCache");re([V],ee.prototype,"_getShapeMaskedPageBoundsCache");re([V],ee.prototype,"_notVisibleShapes");re([V],ee.prototype,"getCulledShapes");re([V],ee.prototype,"getCurrentPageBounds");re([V],ee.prototype,"getCurrentPageShapes");re([V],ee.prototype,"getCurrentPageShapesSorted");re([V],ee.prototype,"getCurrentPageRenderingShapesSorted");re([V],ee.prototype,"_getBindingsIndexCache");re([V],ee.prototype,"_getSelectionSharedStyles");re([V({isEqual:(e,n)=>e.equals(n)})],ee.prototype,"getSharedStyles");re([V],ee.prototype,"getSharedOpacity");re([V],ee.prototype,"getIsFocused");function jd(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:e.options.maxShapesPerPage})}function $o(e,n){if(!n)return e;let t=null;const r=Object.entries(n);for(let o=0,i=r.length;o<i;o++){const[s,a]=r[o];if(a!==void 0&&!(s==="id"||s==="type"||s==="typeName")&&a!==e[s]){if(t||(t={...e}),s==="props"||s==="meta"){t[s]={...e[s]};for(const[c,l]of Object.entries(a))l!==void 0&&(t[s][c]=l);continue}t[s]=a}}return t||e}function J2(e,n,t){const r=e.getShape(n);if(!r)return;t.push(r);const o=e.getSortedChildIdsForParent(n);for(let i=0,s=o.length;i<s;i++)J2(e,o[i],t)}function oC(e,n,t){let r;if(e.history.ignore(()=>{const o=e.store.extractingChanges(()=>{const i=new Set,s=new Set;for(const a of n)if(e.getShape(a))for(const l of e.getBindingsInvolvingShape(a)){const u=n.has(l.fromId),d=n.has(l.toId);if(u&&d){i.add(l.id);continue}(!u||!d)&&s.add(l.id)}e.deleteBindings([...s],{isolateShapes:!0});try{r=hn.ok(t(i))}catch(a){r=hn.err(a)}});e.store.applyDiff(iS(o))}),r.ok)return r.value;throw r.error}function iC(e,n){if(!n.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=n.constraints,o=e.getViewportScreenBounds(),i=J.From(n.constraints.bounds),s=(o.w-t*2)/i.w,a=(o.h-r*2)/i.h;return{zx:s,zy:a}}function Bu(){const e=z(),n=Z2();return G("isDarkMode",()=>(n==null?void 0:n.isDarkMode)??e.user.getIsDarkMode(),[n,e])}const sC="<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'/>",aC="<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'/>",Od='<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 hi(e,n,t,r,o,i=16,s=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>") ${i} ${s}, pointer`}const OK=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],DK={none:()=>"none","ew-resize":(e,n,t)=>hi(aC,e,0,n,t),"ns-resize":(e,n,t)=>hi(aC,e,90,n,t),"nesw-resize":(e,n,t)=>hi(sC,e,0,n,t),"nwse-resize":(e,n,t)=>hi(sC,e,90,n,t),"nwse-rotate":(e,n,t)=>hi(Od,e,0,n,t),"nesw-rotate":(e,n,t)=>hi(Od,e,90,n,t),"senw-rotate":(e,n,t)=>hi(Od,e,180,n,t),"swne-rotate":(e,n,t)=>hi(Od,e,270,n,t)};function Hn(e,n=0,t="black"){return DK[e](zz(n),!1,t)}function RK(){const e=z(),n=ln(),t=Bu();Ei("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(OK.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Hn(r,o,t?"white":"black"))},[e,n,t])}function LK(){const e=z(),n=ln(),t=Bu(),r=G(bt.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 Nx(e){const n=x.useRef();return x.useLayoutEffect(()=>{n.current=e}),x.useDebugValue(e),x.useCallback((...t)=>{const r=n.current;return it(r,"fn does not exist"),r(...t)},[])}function FK(){const[e,n]=x.useState(0);x.useEffect(()=>n(t=>t+1),[])}const qa="TLDRAW_TAB_ID_v2",lo=globalThis.window;function NK(){return lo?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(lo.navigator.platform)||lo.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const op=lo?lo[qa]??e_(qa)??"TLDRAW_INSTANCE_STATE_V1_"+ot():"<error>";lo&&(lo[qa]=op,NK()?v0(qa,op):t_(qa));lo==null||lo.addEventListener("beforeunload",()=>{v0(qa,op)});const e$={Initial:0},Xp=Math.max(...Object.values(e$));function zK(e){e.version<e$.Initial,e.version=Xp}const t$=ve({version:fe,currentPageId:zl,isFocusMode:we,exportBackground:we,isDebugMode:we,isToolLocked:we,isGridMode:we,pageStates:Nt(ve({pageId:zl,camera:ve({x:fe,y:fe,z:fe}),selectedShapeIds:Nt(pr),focusedGroupId:pr.nullable()}))});function BK(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!==Xp&&(e=vt(e),zK(e));try{return t$.validate(e)}catch(n){return console.warn(n),null}}function UK(e){const n=e.query.ids("page");return V("sessionStateSnapshot",()=>{const t=e.get(fn);if(!t)return null;const r=[...n.get()];return{version:Xp,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(o=>{const i=e.get(Rr.createId(o)),s=e.get(no.createId(o));return{pageId:o,camera:{x:(s==null?void 0:s.x)??0,y:(s==null?void 0:s.y)??0,z:(s==null?void 0:s.z)??1},selectedShapeIds:(i==null?void 0:i.selectedShapeIds)??[],focusedGroupId:(i==null?void 0:i.focusedGroupId)??null}})}})}function n$(e,n){const t=BK(n);if(!t)return;const r=e.schema.types.instance.create({id:fn,...M_(e.get(fn)),currentPageId:t.currentPageId,isDebugMode:t.isDebugMode,isFocusMode:t.isFocusMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,exportBackground:t.exportBackground}),o=e.allRecords().filter(i=>i.typeName==="instance_page_state"||i.typeName==="camera");e.atomic(()=>{e.remove(o.map(i=>i.id));for(const i of t.pageStates)e.put([no.create({id:no.createId(i.pageId),x:i.camera.x,y:i.camera.y,z:i.camera.z}),Rr.create({id:Rr.createId(i.pageId),pageId:i.pageId,selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId})]);e.put([r]),e.ensureStoreIsUsable()})}function HK(e){var o;const n=[];for(const i of Object.values(e))(o=i.typeName)!=null&&o.match(/^(instance.*|pointer|camera)$/)&&n.push(i);const t=n.filter(i=>i.typeName==="instance"&&i.id!==fn)[0];if(!t)return null;const r={version:Xp,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:n.filter(i=>i.typeName==="instance_page_state"&&i.instanceId===t.id).map(i=>{const s=e[i.cameraId]??{x:0,y:0,z:1};return{pageId:i.pageId,camera:{x:s.x,y:s.y,z:s.z},selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId}})};try{return t$.validate(r),r}catch{return null}}function KK(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
91
-
92
- Keep seeing this message?
93
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
94
- • If your hard disk is full, try clearing up some space and then reload the page.`)}function WK(){window.alert(`Oops! We could not access your browser's storage—and the app won't work correctly without that. We now need to reload the page and try again.
95
-
96
- Keep seeing this message?
97
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const GK=(e,n)=>n.some(t=>e instanceof t);let cC,lC;function VK(){return cC||(cC=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function YK(){return lC||(lC=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const r$=new WeakMap,uv=new WeakMap,o$=new WeakMap,Wm=new WeakMap,zx=new WeakMap;function XK(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",i),e.removeEventListener("error",s)},i=()=>{t(Bo(e.result)),o()},s=()=>{r(e.error),o()};e.addEventListener("success",i),e.addEventListener("error",s)});return n.then(t=>{t instanceof IDBCursor&&r$.set(t,e)}).catch(()=>{}),zx.set(n,e),n}function qK(e){if(uv.has(e))return;const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("complete",i),e.removeEventListener("error",s),e.removeEventListener("abort",s)},i=()=>{t(),o()},s=()=>{r(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",i),e.addEventListener("error",s),e.addEventListener("abort",s)});uv.set(e,n)}let dv={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return uv.get(e);if(n==="objectStoreNames")return e.objectStoreNames||o$.get(e);if(n==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Bo(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 ZK(e){dv=e(dv)}function QK(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(Gm(this),n,...t);return o$.set(r,n.sort?n.sort():[n]),Bo(r)}:YK().includes(e)?function(...n){return e.apply(Gm(this),n),Bo(r$.get(this))}:function(...n){return Bo(e.apply(Gm(this),n))}}function JK(e){return typeof e=="function"?QK(e):(e instanceof IDBTransaction&&qK(e),GK(e,VK())?new Proxy(e,dv):e)}function Bo(e){if(e instanceof IDBRequest)return XK(e);if(Wm.has(e))return Wm.get(e);const n=JK(e);return n!==e&&(Wm.set(e,n),zx.set(n,e)),n}const Gm=e=>zx.get(e);function eW(e,n,{blocked:t,upgrade:r,blocking:o,terminated:i}={}){const s=indexedDB.open(e,n),a=Bo(s);return r&&s.addEventListener("upgradeneeded",c=>{r(Bo(s.result),c.oldVersion,c.newVersion,Bo(s.transaction),c)}),t&&s.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),a.then(c=>{i&&c.addEventListener("close",()=>i()),o&&c.addEventListener("versionchange",l=>o(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}function tW(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),Bo(t).then(()=>{})}const nW=["get","getKey","getAll","getAllKeys","count"],rW=["put","add","delete","clear"],Vm=new Map;function uC(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(Vm.get(n))return Vm.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=rW.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||nW.includes(t)))return;const i=async function(s,...a){const c=this.transaction(s,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 Vm.set(n,i),i}ZK(e=>({...e,get:(n,t,r)=>uC(n,t)||e.get(n,t,r),has:(n,t)=>!!uC(n,t)||e.has(n,t)}));const qp="TLDRAW_DOCUMENT_v2",i$="TLDRAW_DB_NAME_INDEX_v2",Fe={Records:"records",Schema:"schema",SessionState:"session_state"};async function Zp(e,n){cW(e);const t=await eW(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 oW({persistenceKey:e,sessionId:n,didCancel:t}){const r=qp+e;if(Bx().includes(r))return await aW({persistenceKey:e,didCancel:t}),await Zp(r,async o=>{var d,f;if(t!=null&&t())return;const i=o.transaction([Fe.Records,Fe.Schema,Fe.SessionState],"readonly"),s=i.objectStore(Fe.Records),a=i.objectStore(Fe.Schema),c=i.objectStore(Fe.SessionState);let l=n?(d=await c.get(n))==null?void 0:d.snapshot:null;l||(l=(f=(await c.getAll()).sort((S,m)=>S.updatedAt-m.updatedAt).pop())==null?void 0:f.snapshot);const u={records:await s.getAll(),schema:await a.get(Fe.Schema),sessionStateSnapshot:l};if(t!=null&&t()){i.abort();return}return await i.done,u})}async function iW({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:i}){const s=qp+e;await Zp(s,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"),i!=null&&i())return c.abort();await c.done})}async function sW({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:i}){const s=qp+e;await Zp(s,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"),i!=null&&i())return c.abort();await c.done})}async function aW({persistenceKey:e,didCancel:n}){await Zp(qp+e,async t=>{const r=t.transaction([Fe.SessionState],"readwrite"),o=r.objectStore(Fe.SessionState),i=(await o.getAll()).sort((a,c)=>a.updatedAt-c.updatedAt);if(i.length<10){await r.done;return}const s=i.slice(0,i.length-10);for(const{id:a}of s)await o.delete(a);if(n!=null&&n())return r.abort();await r.done})}function Bx(){const e=JSON.parse(y0(i$)||"[]")??[];return Array.isArray(e)?e:[]}function cW(e){const n=new Set(Bx());n.add(e),S0(i$,JSON.stringify([...n]))}const lW=350,uW=1e4,dC=Symbol("UPDATE_INSTANCE_STATE"),dW=e=>e;class hW{constructor(n){g(this,"onmessage")}postMessage(n){}close(){}}const fW=typeof BroadcastChannel>"u"?hW:BroadcastChannel;class pW{constructor(n,{persistenceKey:t,sessionId:r=op,onLoad:o,onLoadError:i},s=new fW(`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=s,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=UK(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(dW({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(dC),this.schedulePersist()},{scope:"session"})),this.connect(o,i),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 oW({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),WK(),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])),i=r.sessionStateSnapshot??HK(o),s=this.store.schema.migrateStoreSnapshot({store:o,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(s.type==="error"){console.error("failed to migrate store",s),t(new Error(`Failed to migrate store: ${s.reason}`));return}this.store.mergeRemoteChanges(()=>{this.store.put(Object.values(s.value).filter(a=>this.documentTypes.has(a.typeName)),"initialize")}),i&&n$(this.store,i)}this.channel.onmessage=({data:o})=>{var a,c;this.debug("got message",o);const i=o,s=this.store.schema.getMigrationsSince(i.schema);if(s.ok){if(s.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}i.type==="diff"&&(this.debug("applying diff"),vs(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(i.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?uW:lW))}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(){it(!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 sW({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=x0(n.filter(r=>r!==dC));await iW({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),KK(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function gW(e,n){let t={};if("store"in n){const o=e.schema.migrateStoreSnapshot(n);if(o.type!=="success")throw new Error("Failed to migrate store snapshot: "+o.reason);t.document={schema:e.schema.serialize(),store:wl(o.value,(i,{typeName:s})=>e.scopedTypes.document.has(s))}}else t=n;const r=M_(e.get(fn));e.atomic(()=>{t.document&&e.loadStoreSnapshot(t.document),r&&e.update(fn,o=>({...o,...r})),t.session&&n$(e,t.session)})}function s$({initialData:e,defaultName:n="",id:t,...r}={}){const o="schema"in r&&r.schema?r.schema:$z({shapes:"shapeUtils"in r&&r.shapeUtils?hC(Y2(r.shapeUtils)):void 0,bindings:"bindingUtils"in r&&r.bindingUtils?hC(W2(r.bindingUtils)):void 0,migrations:"migrations"in r?r.migrations:void 0});return new C0({id:t,schema:o,initialData:e,props:{defaultName:n}})}function hC(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function fC(e){const n=s$(e);return e.snapshot&&gW(n,e.snapshot),{store:n,opts:e}}function a$(e){const[n,t]=x.useState(()=>fC(e));if(!XE(n.opts,e)){const r=fC(e);return t(r),r.store}return n.store}function mW({persistenceKey:e,sessionId:n,...t}){const[r,o]=x.useState(null),i=a$(t);return x.useEffect(()=>{const s=ot();if(!e){o({id:s,storeWithStatus:{status:"not-synced",store:i}});return}o({id:s,storeWithStatus:{status:"loading"}});const a=l=>{o(u=>(u==null?void 0:u.id)===s?{id:s,storeWithStatus:l}:u)},c=new pW(i,{sessionId:n,persistenceKey:e,onLoad(){a({store:i,status:"synced-local"})},onLoadError(l){a({status:"error",error:l})}});return()=>{o(l=>(l==null?void 0:l.id)===s?null:l),c.close()}},[e,i,n]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}function yW(){const e=z(),n=ln();x.useEffect(()=>{const t=i=>n.style.setProperty("--tl-zoom",i.toString()),r=KE(t,100),o=new bc("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach()}},[e,n])}const SW=[],vW=[],xW=[],wW=x.memo(function({store:n,components:t,className:r,user:o,...i}){const[s,a]=Se.useState(null),c=x.useMemo(()=>o??Bk(),[o]),l=(t==null?void 0:t.ErrorFallback)===void 0?Ok:t==null?void 0:t.ErrorFallback,u={...i,shapeUtils:i.shapeUtils??SW,bindingUtils:i.bindingUtils??vW,tools:i.tools??xW,components:t};return h.jsx("div",{ref:a,draggable:!1,className:ue("tl-container tl-theme__light",r),onPointerDown:Ut,tabIndex:-1,children:h.jsx(Ul,{fallback:l,onError:d=>g0(d,{tags:{origin:"react.tldraw-before-app"}}),children:s&&h.jsx(Zz,{container:s,children:h.jsx(y9,{overrides:t,children:n?n instanceof C0?h.jsx(l$,{...u,store:n,user:c}):h.jsx(c$,{...u,store:n,user:c}):h.jsx(bW,{...u,store:n,user:c})})})})})});function bW(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,bindingUtils:i,persistenceKey:s,sessionId:a,user:c}=e,l=mW({shapeUtils:o,bindingUtils:i,initialData:r,persistenceKey:s,sessionId:a,defaultName:n,snapshot:t});return h.jsx(c$,{...e,store:l,user:c})}const c$=x.memo(function({store:n,user:t,...r}){const o=ln();x.useLayoutEffect(()=>{t.userPreferences.get().isDarkMode&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,t]);const{LoadingScreen:i}=st();switch(n.status){case"error":throw n.error;case"loading":return i?h.jsx(i,{}):null}return h.jsx(l$,{...r,store:n.store,user:t})});function l$({onMount:e,children:n,store:t,tools:r,shapeUtils:o,bindingUtils:i,user:s,initialState:a,autoFocus:c=!0,inferDarkMode:l,cameraOptions:u,options:d}){const{ErrorFallback:f}=st(),p=ln(),[S,m]=x.useState(null),[w]=x.useState(c);x.useLayoutEffect(()=>{const P=new ee({store:t,shapeUtils:o,bindingUtils:i,tools:r,getContainer:()=>p,user:s,initialState:a,autoFocus:w,inferDarkMode:l,cameraOptions:u,options:d});return m(P),()=>{P.dispose()}},[p,o,i,r,t,s,a,w,l,u,d]);const y=x.useSyncExternalStore(x.useCallback(P=>S?(S.on("crash",P),()=>S.off("crash",P)):()=>{},[S]),()=>(S==null?void 0:S.getCrashingError())??null),{Canvas:v}=st();return S?h.jsx(Ul,{fallback:f,onError:P=>S.annotateError(P,{origin:"react.tldraw",willCrashApp:!0}),children:y?h.jsx(CW,{crashingError:y}):h.jsx(Tp.Provider,{value:S,children:h.jsx(PW,{onMount:e,children:n??(v?h.jsx(v,{}):null)})})}):null}function PW({children:e,onMount:n}){return yW(),RK(),LK(),FK(),IW(n),h.jsx(h.Fragment,{children:e})}function CW({crashingError:e}){throw e}function Ux({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function u$({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function IW(e){const n=z(),t=Nx(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 Ds({children:e,className:n="",...t}){return h.jsx("div",{...t,className:ue("tl-html-container",n),children:e})}class Eh{constructor(n){this.editor=n}}g(Eh,"props"),g(Eh,"migrations"),g(Eh,"type");function d$(e,n,t={}){const{newPoint:r,handle:o,scaleX:i,scaleY:s}=n,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:u=1/0}=t;let d=e.props.w*i,f=e.props.h*s;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:S,y:m}=p.rot(e.rotation).add(r);return{x:S,y:m,props:{w:Math.min(c,d),h:Math.min(u,f)}}}class Tc extends Nr{constructor(){super(...arguments);g(this,"onResize",(t,r)=>d$(t,r))}getGeometry(t){return new Xo({width:t.props.w,height:t.props.h,isFilled:!0})}getHandleSnapGeometry(t){return{points:this.getGeometry(t).bounds.cornersAndCenter}}}var wy;let EW=(wy=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(wy,"id","idle"),wy);var by;let _W=(by=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,i=Be();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(i),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 i=this.editor.getShape(o),{w:s,h:a}=this.editor.getShapeUtil(i).getDefaultProps(),c=new b(s/2,a/2),l=this.editor.getShapeParentTransform(i);l&&c.rot(-l.rotation()),this.editor.updateShapes([{id:o,type:r,x:i.x-c.x,y:i.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(by,"id","pointing"),by);class _h extends se{constructor(){super(...arguments);g(this,"onCreate")}}g(_h,"id","box"),g(_h,"initial","idle"),g(_h,"children",()=>[EW,_W]);function Qp(e){const n=z();return G("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function kW(){return x.useId().replace(/:/g,"_")}function Zr(e){const n=z();return x.useMemo(function(){const o=l=>{if(l.isKilled)return;if(l.button===O0){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...kn(l)});return}if(l.button!==0)return;const u=$f(l.currentTarget);function d(){u.removeEventListener("pointerup",d),Au(u,l)}Mu(u,l),u.addEventListener("pointerup",d),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...kn(l)}),Ut(l)};let i,s;function a(l){l.isKilled||l.button===0&&(l.clientX===i&&l.clientY===s||(i=l.clientX,s=l.clientY,n.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...kn(l)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:l=>{l.isKilled||l.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...kn(l)})}}},[n,e])}const TW=20,$W=8;function Hx(e,n=TW){return Math.max($W,Math.ceil(e/n))}class Oa extends Yi{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:i,start:s,end:a}=t;if(s.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=b.Angle(r,s),this.angleEnd=b.Angle(r,a),this.radius=b.Dist(r,s),this.measure=Bz(this.angleStart,this.angleEnd,o,i),this.start=s,this.end=a,this.sweepFlag=o,this.largeArcFlag=i,this._center=r}nearestPoint(t){const{_center:r,measure:o,radius:i,angleEnd:s,angleStart:a,start:c,end:l}=this,u=hS(o,a,s,r.angle(t));if(u<=0)return c;if(u>=1)return l;const d=r.clone().add(t.clone().sub(r).uni().mul(i));let f,p=1/0,S;for(const m of[c,l,d])S=b.Dist2(t,m),S<p&&(f=m,p=S);if(!f)throw Error("nearest point not found");return f}hitTestLineSegment(t,r){const{_center:o,radius:i,measure:s,angleStart:a,angleEnd:c}=this,l=Nu(t,r,o,i);return l===null?!1:l.some(u=>{const d=hS(s,a,c,o.angle(u));return d>=0&&d<=1})}getVertices(){const{_center:t,measure:r,length:o,radius:i,angleStart:s}=this,a=[];for(let c=0,l=Hx(Math.abs(o));c<l+1;c++){const u=c/l*r,d=s+u;a.push(ks(t,i,d))}return a}getSvgPathData(t=!0){const{start:r,end:o,radius:i,largeArcFlag:s,sweepFlag:a}=this;return`${t?`M${r.toFixed()}`:""} A${i} ${i} 0 ${s} ${a} ${o.toFixed()}`}getLength(){return this.measure*this.radius}}class Kx extends Yi{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:i}=t;this.x=r,this.y=o,this._center=new b(i+r,i+o),this.radius=i}getBounds(){return new J(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,o=Re*r,i=[];for(let s=0,a=Hx(o);s<a;s++){const c=s/a*Re;i.push(ks(t,r,c))}return i}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:i,radius:s}=this;return Nu(t,r,i,s+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 Qt extends kc{constructor(t){const{start:r,cp1:o,cp2:i,end:s}=t;super({...t,points:[r,s]});g(this,"a");g(this,"b");g(this,"c");g(this,"d");this.a=r,this.b=o,this.c=i,this.d=s}getVertices(){const t=[],{a:r,b:o,c:i,d:s}=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)*i.x+l*l*l*s.x,(1-l)*(1-l)*(1-l)*r.y+3*((1-l)*(1-l))*l*o.y+3*(1-l)*(l*l)*i.y+l*l*l*s.y))}return t}midPoint(){return Qt.GetAtT(this,.5)}nearestPoint(t){let r,o=1/0,i,s;for(const a of this.segments)s=a.nearestPoint(t),i=b.Dist2(s,t),i<o&&(r=s,o=i);if(!r)throw Error("nearest point not found");return r}getSvgPathData(t=!0){const{a:r,b:o,c:i,d:s}=this;return`${t?`M ${r.toFixed()} `:""} C${o.toFixed()} ${i.toFixed()} ${s.toFixed()}`}static GetAtT(t,r){const{a:o,b:i,c:s,d:a}=t;return new b((1-r)*(1-r)*(1-r)*o.x+3*((1-r)*(1-r))*r*i.x+3*(1-r)*(r*r)*s.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*o.y+3*((1-r)*(1-r))*r*i.y+3*(1-r)*(r*r)*s.y+r*r*r*a.y)}getLength(t=32){let r,o=this.a,i=0;for(let s=1;s<=t;s++)r=Qt.GetAtT(this,s/t),i+=b.Dist(o,r),o=r;return i}}class MW extends Yi{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,i=1.25;for(let s=0;s<r-1;s++){const a=s===0?t[0]:t[s-1],c=t[s],l=t[s+1],u=s===o?l:t[s+2],d=c,f=s===0?a:new b(c.x+(l.x-a.x)/6*i,c.y+(l.y-a.y)/6*i),p=s===o?l:new b(l.x-(u.x-c.x)/6*i,l.y-(u.y-c.y)/6*i),S=l;this._segments.push(new Qt({start:d,cp1:f,cp2:p,end:S}))}}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){const t=this.segments.reduce((r,o)=>r.concat(o.vertices),[]);return t.push(this.points[this.points.length-1]),t}nearestPoint(t){let r,o=1/0,i,s;for(const a of this.segments)s=a.nearestPoint(t),i=b.Dist2(s,t),i<o&&(r=s,o=i);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,i)=>r+o.getSvgPathData(i===0),"");return this.isClosed&&(t+="Z"),t}}class AW extends Yi{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 i=t[r],s=t[(r+1)%o];this._edges.push(new Fo({start:i,end:s}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),o=t/2,i=r/2,s=Math.pow(o-i,2)/Math.pow(o+i,2),a=ke*(o+i)*(1+3*s/(10+Math.sqrt(4-3*s))),c=Hx(a),l=Re/c,u=Math.cos(l),d=Math.sin(l);let f=0,p=1,S=0,m=1;const w=Array(c);for(let y=0;y<c;y++)w[y]=new b(o+o*p,i+i*f),S=d*p+u*f,m=u*p-d*f,f=S,p=m;return w}nearestPoint(t){let r,o=1/0,i,s;for(const a of this.edges)s=a.nearestPoint(t),i=b.Dist2(s,t),i<o&&(r=s,o=i);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,i=r/2,s=Math.max(0,o),a=Math.max(0,i);return ik(s,a)}getSvgPathData(t=!1){const{w:r,h:o}=this,i=r/2,s=o/2,a=Math.max(0,i),c=Math.max(0,s);return`${t?`M${i-a},${s}`:""} a${a},${c},0,1,1,${a*2},0a${a},${c},0,1,1,-${a*2},0`}}class jW extends Yi{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 i=r/2;this.a=new Oa({start:new b(0,i),end:new b(r,i),center:new b(r/2,i),sweepFlag:1,largeArcFlag:1}),this.b=new Fo({start:new b(r,i),end:new b(r,o-i)}),this.c=new Oa({start:new b(r,o-i),end:new b(0,o-i),center:new b(r/2,o-i),sweepFlag:1,largeArcFlag:1}),this.d=new Fo({start:new b(0,o-i),end:new b(0,i)})}else{const i=o/2;this.a=new Oa({start:new b(i,o),end:new b(i,0),center:new b(i,i),sweepFlag:1,largeArcFlag:1}),this.b=new Fo({start:new b(i,0),end:new b(r-i,0)}),this.c=new Oa({start:new b(r-i,0),end:new b(r-i,o),center:new b(r-i,i),sweepFlag:1,largeArcFlag:1}),this.d=new Fo({start:new b(r-i,o),end:new b(i,o)})}}nearestPoint(t){let r,o=1/0,i,s;const{a,b:c,c:l,d:u}=this;for(const d of[a,c,l,u])s=d.nearestPoint(t),i=b.Dist2(s,t),i<o&&(r=s,o=i);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){const{a:o,b:i,c:s,d:a}=this;return[o,i,s,a].some(c=>c.hitTestLineSegment(t,r))}getVertices(){const{a:t,b:r,c:o,d:i}=this;return[t,r,o,i].reduce((s,a)=>(s.push(...a.vertices),s),[])}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:i}=this;return[t,r,o,i].map((s,a)=>s.getSvgPathData(a===0)).join(" ")+" Z"}}function pC(e,n,t,r,o,i){const s=e.options.edgeScrollDistance,a=r?e.options.coarsePointerWidth:0,c=n-a,l=n+a,u=o?0:s,d=i?t:t-s;return c<u?Math.min(1,(u-c)/s):l>d?-Math.min(1,(l-d)/s):0}function Wx(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(),i=o.w<1e3?.612:1,s=o.h<1e3?.612:1,{isCoarsePointer:a,insets:[c,l,u,d]}=e.getInstanceState(),f=pC(e,n,o.w,a,d,l),p=pC(e,t,o.h,a,c,u);if(f===0&&p===0)return;const S=e.user.getEdgeScrollSpeed()*e.options.edgeScrollSpeed,m=S*f*i/r,w=S*p*s/r,y=e.getCamera();e.setCamera(new b(y.x+m,y.y+w,y.z))}async function OW({shouldReload:e=!0}={}){RN(),await Promise.all(Bx().map(n=>tW(n))),DN(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=OW);function DW(e,n="_blank"){U0.openWindow(e,n)}function RW({children:e}){const n=z();return G("shouldDisplayHandles",()=>{if(n.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(n.isInAny("select.editing_shape")){const r=n.getOnlySelectedShape();return r&&n.isShapeOfType(r,"note")}return!1},[n])?h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:LW}=Math,Za=LW+1e-4;function h$(e,n={}){const{size:t=16,smoothing:r=.5}=n;if(e.length===0||t<=0)return{left:[],right:[]};const o=e[0],i=e[e.length-1],s=i.runningLength,a=Math.pow(t*r,2),c=[],l=[];let u=e[0].vector,d=e[0].point,f=d,p=d,S=f,m=!1,w;for(let y=0;y<e.length;y++){w=e[y];const{point:v,vector:P}=e[y],E=w.vector.dpr(u),C=(y<e.length-1?e[y+1]:e[y]).vector,I=y<e.length-1?C.dpr(w.vector):1,_=E<0&&!m,k=I!==null&&I<.2;if(_||k){if(I>-.62&&s-w.runningLength>w.radius){const T=u.clone().mul(w.radius);u.clone().cpr(C)<0?(p=b.Add(v,T),S=b.Sub(v,T)):(p=b.Sub(v,T),S=b.Add(v,T)),c.push(p),l.push(S)}else{const T=u.clone().mul(w.radius).per(),A=b.Sub(w.input,T);for(let N=1/13,j=0;j<1;j+=N)p=b.RotWith(A,w.input,Za*j),c.push(p),S=b.RotWith(A,w.input,Za+Za*-j),l.push(S)}d=p,f=S,k&&(m=!0);continue}if(m=!1,w===o||w===i){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,$),(y<=1||b.Dist2(d,p)>a)&&(c.push(p),d=p),S=b.Add(v,$),(y<=1||b.Dist2(f,S)>a)&&(l.push(S),f=S),u=P}return{left:c,right:l}}function Gx(e,n={}){const{size:t=16,start:r={},end:o={},last:i=!1}=n,{cap:s=!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:S}=h$(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)||i)){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,Za*2*_));return C}const y=[];if(!(d||f&&e.length===1))if(s)for(let E=1/8,C=E;C<=1;C+=E){const I=b.RotWith(S[0],m,Za*C);y.push(I)}else{const E=b.Sub(p[0],S[0]),C=b.Mul(E,.5),I=b.Mul(E,.51);y.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,Za*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,S.reverse(),y)}const FW=.025,NW=.01;function po(e,n={}){var w;const{streamline:t=.5,size:r=16,simulatePressure:o=!1}=n;if(e.length===0)return[];const i=.15+(1-t)*.85;let s=e.map(b.From),a=0;if(!o){let y=s[0];for(;y&&!(y.z>=FW);)s.shift(),y=s[0]}if(!o){let y=s[s.length-1];for(;y&&!(y.z>=NW);)s.pop(),y=s[s.length-1]}if(s.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=s[1];for(;c&&!(b.Dist2(c,s[0])>(r/3)**2);)s[0].z=Math.max(s[0].z,c.z),s.splice(1,1),c=s[1];const l=s.pop();for(c=s[s.length-1];c&&!(b.Dist2(c,l)>(r/3)**2);)s.pop(),c=s[s.length-1],a++;s.push(l);const u=n.last||!n.simulatePressure||s.length>1&&b.Dist2(s[s.length-1],s[s.length-2])<r**2||a>0;if(s.length===2&&n.simulatePressure){const y=s[1];s=s.slice(0,-1);for(let v=1;v<5;v++){const P=b.Lrp(s[0],y,v/4);P.z=(s[0].z+(y.z-s[0].z))*v/4,s.push(P)}}const d=[{point:s[0],input:s[0],pressure:o?.5:s[0].z,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let f=0,p=d[0],S,m;u&&t>0&&s.push(s[s.length-1].clone());for(let y=1,v=s.length;y<v;y++)S=!i||n.last&&y===v-1?s[y].clone():s[y].clone().lrp(p.point,1-i),!p.point.equals(S)&&(m=b.Dist(S,p.point),f+=m,!(y<4&&f<r)&&(p={input:s[y],point:S,pressure:o?.5:s[y].z,vector:b.Sub(p.point,S).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 y=Math.max(.5,...d.map(v=>v.pressure));d.forEach(v=>v.pressure=y)}return d}const{min:fi}=Math,Ym=.275;function Jp(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:i=w=>w,start:s={},end:a={}}=n,{easing:c=on.easeOutQuad}=s,{easing:l=on.easeOutCubic}=a,u=e[e.length-1].runningLength;let d,f=e[0].pressure,p;if(!o&&u<t){const w=e.reduce((y,v)=>Math.max(y,v.pressure),.5);return e.forEach(y=>{y.pressure=w,y.radius=t*i(.5-r*(.5-y.pressure))}),e}else{let w;for(let y=0,v=e.length;y<v&&(p=e[y],!(p.runningLength>t*5));y++){const P=fi(1,p.distance/t);if(o){const E=fi(1,1-P);w=fi(1,f+(E-f)*(P*Ym))}else w=fi(1,f+(p.pressure-f)*.5);f=f+(w-f)*.5}for(let y=0;y<e.length;y++){if(p=e[y],r){let{pressure:v}=p;const P=fi(1,p.distance/t);if(o){const E=fi(1,1-P);v=fi(1,f+(E-f)*(P*Ym))}else v=fi(1,f+(v-f)*(P*Ym));p.radius=t*i(.5-r*(.5-v)),f=v}else p.radius=t/2;d===void 0&&(d=p.radius)}}const S=s.taper===!1?0:s.taper===!0?Math.max(t,u):s.taper,m=a.taper===!1?0:a.taper===!0?Math.max(t,u):a.taper;if(S||m)for(let w=0;w<e.length;w++){p=e[w];const{runningLength:y}=p,v=y<S?c(y/S):1,P=u-y<m?l((u-y)/m):1;p.radius=Math.max(.01,p.radius*Math.min(v,P))}return e}function zW(e,n={}){return Gx(Jp(po(e,n),n),n)}function gC({scribble:e,zoom:n,color:t,opacity:r,className:o}){if(!e.points.length)return null;const i=zW(e.points,{size:e.size/n,start:{taper:e.taper,easing:on.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let s;if(i.length<4){const a=e.size/n/2,{x:c,y:l}=e.points[e.points.length-1];s=`M ${c-a},${l} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else s=z0(i);return h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:s,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})}const BW=({bounds:e,rotation:n})=>{const t=z();return G("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?h.jsx($k,{bounds:e,rotation:n}):null};function ni(){const e=z();return G("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function UW({size:e,width:n,height:t,hideAlternateHandles:r}){const o=F(e/3),i=o/2;return h.jsxs("svg",{className:"tl-overlays__item",children:[h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
98
- ${F(0-i)},${F(e)}
99
- ${F(0-i)},${F(0-i)}
100
- ${F(e)},${F(0-i)}`,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-i),x2:F(n/2+e),y2:F(0-i),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
101
- ${F(n-e)},${F(0-i)}
102
- ${F(n+i)},${F(0-i)}
103
- ${F(n+i)},${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+i),y1:F(t/2-e),x2:F(n+i),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:`
104
- ${F(n+i)},${F(t-e)}
105
- ${F(n+i)},${F(t+i)}
106
- ${F(n-e)},${F(t+i)}`,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+i),x2:F(n/2+e),y2:F(t+i),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
107
- ${F(0+e)},${F(t+i)}
108
- ${F(0-i)},${F(t+i)}
109
- ${F(0-i)},${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-i),y1:F(t/2-e),x2:F(0-i),y2:F(t/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const HW=ir(function({bounds:n,rotation:t}){const r=z(),o=x.useRef(null),i=ni(),s=Zr("top"),a=Zr("right"),c=Zr("bottom"),l=Zr("left"),u=Zr("top_left"),d=Zr("top_right"),f=Zr("bottom_right"),p=Zr("bottom_left"),S=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),y=w&&r.isShapeOrAncestorLocked(w),v=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0;if(Pc(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,A=I<_*4,N=C<_*5,j=I<_*5,O=m?1.75:1,R=6/P*O,Y=(T?R/2:R)*(O*.75),K=(A?R/2:R)*(O*.75),U=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!E;let H=U&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle","select.pointing_resize_handle")||U&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&H&&r.environment.isFirefox&&r.isShapeOfType(w,"embed")&&(H=!1);const W=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!E&&!i,Z=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!E&&!i,oe=!m&&!(k||$)&&(Z||W)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!y,be=m&&(!T||!A)&&(Z||W)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!y,Ae=Z&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!W&&!y,ce=k||$,je=k&&$,Le=N||j,at=Ae||W,Ie=!oe,pt=!Z||!be,Ue=!Z||!at,lr=!Z||!at||ce,zn=!Z||!at||ce,Bn=!Z||!at||je&&!W;let qe=!0,Ot=!0;if(W)qe=Le,Ot=Le;else if(Ae){qe=ce||je||m;const Dc=m&&w&&w.type==="text";Ot=qe&&!Dc}const _o=Math.min(24/P,I-K*3),Oc=Z&&m&&w&&r.isShapeOfType(w,"text")&&_o*P>=4;return h.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsxs("g",{ref:o,children:[H&&h.jsx("rect",{className:"tl-selection__fg__outline",width:F(C),height:F(I)}),h.jsx(Dd,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:R,corner:"top_left_rotate",cursor:S?Hn("nwse-rotate",t):void 0,isHidden:Ie}),h.jsx(Dd,{"data-testid":"selection.rotate.top-right",cx:C+R*3,cy:0,targetSize:R,corner:"top_right_rotate",cursor:S?Hn("nesw-rotate",t):void 0,isHidden:Ie}),h.jsx(Dd,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:I+R*3,targetSize:R,corner:"bottom_left_rotate",cursor:S?Hn("swne-rotate",t):void 0,isHidden:Ie}),h.jsx(Dd,{"data-testid":"selection.rotate.bottom-right",cx:C+R*3,cy:I+R*3,targetSize:R,corner:"bottom_right_rotate",cursor:S?Hn("senw-rotate",t):void 0,isHidden:Ie}),h.jsx(WW,{"data-testid":"selection.rotate.mobile",cx:T?-R*1.5:C/2,cy:T?I/2:-R*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-(A?K*2:K)),width:F(C),height:F(Math.max(1,K*2)),style:S?{cursor:Hn("ns-resize",t)}:void 0,...s}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Ot}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:F(C-(T?0:Y)),y:0,height:F(I),width:F(Math.max(1,Y*2)),style:S?{cursor:Hn("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-(A?0:K)),width:F(C),height:F(Math.max(1,K*2)),style:S?{cursor:Hn("ns-resize",t)}:void 0,...c}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Ot}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:F(0-(T?Y*2:Y)),y:0,height:F(I),width:F(Math.max(1,Y*2)),style:S?{cursor:Hn("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?Y*2:Y*1.5)),y:F(0-(A?K*2:K*1.5)),width:F(Y*3),height:F(K*3),style:S?{cursor:Hn("nwse-resize",t)}:void 0,...u}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":lr}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:F(C-(T?0:Y*1.5)),y:F(0-(A?K*2:K*1.5)),width:F(Y*3),height:F(K*3),style:S?{cursor:Hn("nesw-resize",t)}:void 0,...d}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Bn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:F(C-(T?Y:Y*1.5)),y:F(I-(A?K:K*1.5)),width:F(Y*3),height:F(K*3),style:S?{cursor:Hn("nwse-resize",t)}:void 0,...f}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":zn}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:F(0-(T?Y*3:Y*1.5)),y:F(I-(A?0:K*1.5)),width:F(Y*3),height:F(K*3),style:S?{cursor:Hn("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":lr}),"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":Bn}),"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":zn}),"aria-label":"bottom_left handle",x:F(0-_/2),y:F(I-_/2),width:F(_),height:F(_)})]}),Oc&&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-_o/2),rx:_/4,width:F(_/2),height:F(_o)}),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-_o/2),width:F(_/2),height:F(_o)})]}),W&&h.jsx(UW,{size:_,width:C,height:I,hideAlternateHandles:Le})]})})}),Dd=function({cx:n,cy:t,targetSize:r,corner:o,cursor:i,isHidden:s,"data-testid":a}){const c=Zr(o);return h.jsx("rect",{className:ue("tl-transparent","tl-rotate-corner",{"tl-hidden":s}),"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:i,...c})},KW=Math.sqrt(Math.PI),WW=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":i}){const s=Zr("mobile_rotate"),a=z(),c=G("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":i,pointerEvents:"all",className:ue("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:l,...s}),h.jsx("circle",{className:ue("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/KW})]})};function hv(e,n,t){const{arrowheadStart:r,arrowheadEnd:o}=n.props,i=Da(e,n,t),s=i.start.clone(),a=i.end.clone(),c=b.Med(s,a);if(b.Equals(s,a))return{bindings:t,isStraight:!0,start:{handle:s,point:s,arrowhead:n.props.arrowheadStart},end:{handle:a,point:a,arrowhead:n.props.arrowheadEnd},middle:c,isValid:!1,length:0};const l=b.Sub(a,s).uni(),u=ip(e,n,"start"),d=ip(e,n,"end"),f=e.getShapePageTransform(n);mC(a,i.start,f,d),mC(s,i.end,f,u);let p=0,S=0,m=0,w=0,y=Ra;const v=u&&d&&u.shape===d.shape,P=u&&d?Vx(e,u.shape.id,d.shape.id):"safe";P==="safe"&&u&&d&&!v&&!u.isExact&&!d.isExact&&(d.didIntersect&&!u.didIntersect?u.isClosed&&s.setTo(a.clone().add(l.clone().mul(Ra))):d.didIntersect||d.isClosed&&a.setTo(s.clone().sub(l.clone().mul(Ra))));const E=b.Sub(a,s),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=Ci[n.props.size]/2+("size"in u.shape.props?Ci[u.shape.props.size]/2:0),p=sp+m,y+=m),P!=="end-contains-start"&&d&&o!=="none"&&!d.isExact&&(w=Ci[n.props.size]/2+("size"in d.shape.props?Ci[d.shape.props.size]/2:0),S=sp+w,y+=w));const _=s.clone().add(C.clone().mul(p*(I?-1:1))),k=a.clone().sub(C.clone().mul(S*(I?-1:1)));b.DistMin(_,k,y)&&(p!==0&&S!==0?(p*=-1.5,S*=-1.5):p!==0?p*=-1:S!==0&&(S*=-1)),s.add(C.clone().mul(p*(I?-1:1))),a.sub(C.clone().mul(S*(I?-1:1))),I?(u&&d&&a.setTo(b.Add(s,C.clone().mul(-Ra))),c.setTo(b.Med(i.start,i.end))):c.setTo(b.Med(s,a));const $=b.Dist(s,a);return{bindings:t,isStraight:!0,start:{handle:i.start,point:s,arrowhead:n.props.arrowheadStart},end:{handle:i.end,point:a,arrowhead:n.props.arrowheadEnd},middle:c,isValid:$>0,length:$}}function mC(e,n,t,r){if(r===void 0||r.isExact)return;const o=ie.applyToPoint(t,n),i=ie.applyToPoint(t,e),s=ie.applyToPoint(ie.Inverse(r.transform),o),a=ie.applyToPoint(ie.Inverse(r.transform),i),c=r.isClosed,u=(c?Dx:RH)(s,a,r.outline);let d;if(u!==null&&(d=u.sort((S,m)=>b.Dist2(S,s)-b.Dist2(m,s))[0]??(c?void 0:a)),d===void 0)return;const f=ie.applyToPoint(r.transform,d),p=ie.applyToPoint(ie.Inverse(t),f);e.setTo(p),r.didIntersect=!0}function GW(e,n,t){const{arrowheadEnd:r,arrowheadStart:o}=n.props,i=n.props.bend;if(Math.abs(i)>Math.abs(n.props.bend*qW))return hv(e,n,t);const s=Da(e,n,t),a=b.Med(s.start,s.end),c=b.Sub(s.end,s.start),l=b.Len(c)?c.uni():b.From(c),u=b.Add(a,l.per().mul(-i)),d=ip(e,n,"start"),f=ip(e,n,"end"),p=s.start.clone(),S=s.end.clone(),m=u.clone();if(b.Equals(p,S))return{bindings:t,isStraight:!0,start:{handle:p,point:p,arrowhead:n.props.arrowheadStart},end:{handle:S,point:S,arrowhead:n.props.arrowheadEnd},middle:m,isValid:!1,length:0};const w=n.props.bend<0,y=w?$u:sk,v=yC(p,S,m),P=b.Angle(v.center,p),E=b.Angle(v.center,S),C=y(P,E);if(v.length===0||v.size===0||!x1(v.length)||!x1(v.size))return hv(e,n,t);const I=p.clone(),_=S.clone(),k=m.clone(),$=e.getShapePageTransform(n);let T=0,A=0,N=Ra;if(d&&!d.isExact){const W=ie.applyToPoint($,I),Z=ie.applyToPoint($,v.center),oe=ie.applyToPoint($,_),be=ie.Inverse(d.transform),Ae=ie.applyToPoint(be,W),ce=ie.applyToPoint(be,Z),je=ie.applyToPoint(be,oe),{isClosed:Le}=d,at=Le?cv:ZP;let Ie,pt=at(ce,v.radius,d.outline);if(pt){const Ue=ce.angle(Ae),lr=ce.angle(je),zn=y(Ue,lr);pt=pt.filter(qe=>y(Ue,ce.angle(qe))<=zn);const Bn=zn*.25;pt.sort(Le?(qe,Ot)=>Math.abs(y(Ue,ce.angle(qe))-Bn)<Math.abs(y(Ue,ce.angle(Ot))-Bn)?-1:1:(qe,Ot)=>y(Ue,ce.angle(qe))<y(Ue,ce.angle(Ot))?-1:1),Ie=pt[0]??(Le?void 0:Ae)}else Ie=Le?void 0:Ae;if(Ie&&(I.setTo(e.getPointInShapeSpace(n,ie.applyToPoint(d.transform,Ie))),d.didIntersect=!0,o!=="none")){const Ue=Ci[n.props.size]/2+("size"in d.shape.props?Ci[d.shape.props.size]/2:0);T=sp+Ue,N+=Ue}}if(f&&!f.isExact){const W=ie.applyToPoint($,I),Z=ie.applyToPoint($,_),oe=ie.applyToPoint($,v.center),be=ie.Inverse(f.transform),Ae=ie.applyToPoint(be,W),ce=ie.applyToPoint(be,oe),je=ie.applyToPoint(be,Z),Le=f.isClosed,at=Le?cv:ZP;let Ie,pt=at(ce,v.radius,f.outline);if(pt){const Ue=ce.angle(Ae),lr=ce.angle(je),zn=y(Ue,lr),Bn=zn*.75;pt=pt.filter(qe=>y(Ue,ce.angle(qe))<=zn),pt.sort(Le?(qe,Ot)=>Math.abs(y(Ue,ce.angle(qe))-Bn)<Math.abs(y(Ue,ce.angle(Ot))-Bn)?-1:1:(qe,Ot)=>y(Ue,ce.angle(qe))<y(Ue,ce.angle(Ot))?-1:1),pt[0]?Ie=pt[0]:Ie=Le?void 0:je}else Ie=Le?void 0:je;if(Ie&&(_.setTo(e.getPointInShapeSpace(n,ie.applyToPoint(f.transform,Ie))),f.didIntersect=!0,r!=="none")){const Ue=Ci[n.props.size]/2+("size"in f.shape.props?Ci[f.shape.props.size]/2:0);A=sp+Ue,N+=Ue}}let j=b.Angle(v.center,I),O=b.Angle(v.center,_),R=y(j,O),Y=R*v.radius;const K=I.clone(),U=_.clone();if(T!==0){const W=T/Y*(w?1:-1),Z=b.FromAngle(j+R*W);K.setTo(v.center).add(Z.mul(v.radius))}if(A!==0){const W=A/Y*(w?-1:1),Z=b.FromAngle(O+R*W);U.setTo(v.center).add(Z.mul(v.radius))}if(b.DistMin(K,U,N)&&(T!==0&&A!==0?(T*=-1.5,A*=-1.5):T!==0?T*=-2:A!==0&&(A*=-2)),T!==0){const W=T/Y*(w?1:-1),Z=b.FromAngle(j+R*W);I.setTo(v.center).add(Z.mul(v.radius))}if(A!==0){const W=A/Y*(w?-1:1),Z=b.FromAngle(O+R*W);_.setTo(v.center).add(Z.mul(v.radius))}if(d&&f&&!d.isExact&&!f.isExact){j=b.Angle(v.center,I),O=b.Angle(v.center,_),R=y(j,O),Y=R*v.radius;const W=Vx(e,d.shape.id,f.shape.id);if(W==="double-bound"&&Y<30)I.setTo(p),_.setTo(S),k.setTo(m);else if(W==="safe"&&(d&&!d.didIntersect&&I.setTo(p),f&&!f.didIntersect||y(P,j)>y(P,O))){const Z=Math.min(.9,Ra/Y)*(w?1:-1),oe=b.FromAngle(j+R*Z);_.setTo(v.center).add(oe.mul(v.radius))}}VW(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),S.setTo(_),m.setTo(k);const H=yC(p,S,m);return{bindings:t,isStraight:!1,start:{point:p,handle:s.start,arrowhead:n.props.arrowheadStart},end:{point:S,handle:s.end,arrowhead:n.props.arrowheadEnd},middle:m,handleArc:v,bodyArc:H,isValid:H.length!==0&&isFinite(H.center.x)&&isFinite(H.center.y)}}function yC(e,n,t){const r=j0(e,n,t),o=b.Dist(r,e),i=+b.Clockwise(e,t,n),s=((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-s*s)/(2*a*c))*2,u=+(ke>l),d=(Re-l)*(i?1:-1),f=d*o;return{center:r,radius:o,size:d,length:f,largeArcFlag:u,sweepFlag:i}}function VW(e,n,t,r,o,i,s){const a=b.Angle(e,t),c=b.Angle(e,r);let l=$u(a,c);s||(l=Re-l);const u=.5*(s?1:-1),d=b.FromAngle(a+l*u);if(o.setTo(e).add(d.mul(n)),l>i){o.rotWith(e,ke);const f=r.clone();r.setTo(t),t.setTo(f)}}function YW(e){return Math.abs(e.props.bend)<8}function ip(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 i=e.getShapePageTransform(o),s=e.getShapeGeometry(o),a=s instanceof Br?s.children[0].vertices:s.vertices;return{shape:o,transform:i,isClosed:s.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function SC(e,n,t,r){const o=e.getShape(t.toId);if(o){const{point:i,size:s}=e.getShapeGeometry(o).bounds,a=b.Add(i,b.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},s)),c=ie.applyToPoint(e.getShapePageTransform(o),a);return ie.applyToPoint(ie.Inverse(n),c)}else return new b(0,0)}function En(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 XW=S4("arrow info",(e,n)=>{const t=En(e,n);return YW(n)?hv(e,n,t):GW(e,n,t)});function ro(e,n){const t=typeof n=="string"?n:n.id;return XW.get(e,t)}function Da(e,n,t){var a,c;const r=e.getShapePageTransform(n),o=Vx(e,(a=t.start)==null?void 0:a.toId,(c=t.end)==null?void 0:c.toId),i=t.start?SC(e,r,t.start,o==="double-bound"||o==="start-contains-end"):b.From(n.props.start),s=t.end?SC(e,r,t.end,o==="double-bound"||o==="end-contains-start"):b.From(n.props.end);return{start:i,end:s}}function nl(e,n,t,r){const o=typeof n=="string"?n:n.id,i=typeof t=="string"?t:t.id,s=e.getBindingsFromShape(o,"arrow").filter(c=>c.props.terminal===r.terminal);s.length>1&&e.deleteBindings(s.slice(1));const a=s[0];a?e.updateBinding({...a,toId:i,props:r}):e.createBinding({type:"arrow",fromId:o,toId:i,props:r})}function kh(e,n,t){const r=e.getBindingsFromShape(n,"arrow").filter(o=>o.props.terminal===t);e.deleteBindings(r)}const Ra=10,sp=10,qW=10,Ci={s:2,m:3.5,l:5,xl:10};function Vx(e,n,t){if(!n||!t)return"safe";if(n===t)return"double-bound";const r=e.getShapePageBounds(n),o=e.getShapePageBounds(t);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}class Th extends Eh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:n}){Xm(this.editor,this.editor.getShape(n.fromId))}onAfterChange({bindingAfter:n}){Xm(this.editor,this.editor.getShape(n.fromId))}onAfterChangeFromShape({shapeAfter:n}){Xm(this.editor,n)}onAfterChangeToShape({binding:n}){f$(this.editor,n.fromId)}onBeforeIsolateFromShape({binding:n}){const t=this.editor.getShape(n.fromId);t&&ap({editor:this.editor,arrow:t,terminal:n.props.terminal})}}g(Th,"type","arrow"),g(Th,"props",__),g(Th,"migrations",k_);function f$(e,n){var w;const t=e.getShape(n);if(!t)return;const r=En(e,t),{start:o,end:i}=r,s=o?e.getShape(o.toId):void 0,a=i?e.getShape(i.toId):void 0,c=e.getAncestorPageId(t);if(!c)return;let l;if(s&&a)l=e.findCommonAncestor([s,a])??c;else if(s||a){const y=(w=s||a)==null?void 0:w.parentId;y&&y===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,s),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 S;const m=e.getSortedChildIdsForParent(p.parentId).map(y=>e.getShape(y)).filter(y=>y.index>p.index);if(m.length){const y=m.find(v=>v.type!=="arrow");if(u.index>p.index&&(!y||u.index<y.index))return;S=Fl(p.index,m[0].index)}else S=Do(p.index);S!==u.index&&e.updateShapes([{id:n,type:"arrow",index:S}])}function Xm(e,n){const t=En(e,n);for(const r of["start","end"]){const o=t[r];if(!o)continue;const i=e.getShape(o.toId),s=e.getAncestorPageId(n)===e.getAncestorPageId(i);(!i||!s)&&ap({editor:e,arrow:n,terminal:r,unbind:!0})}f$(e,n.id)}function ap({editor:e,arrow:n,terminal:t,unbind:r=!1,useHandle:o=!1}){const i=ro(e,n);if(!i)throw new Error("expected arrow info");const s=o?i.start.handle:i.start.point,a=o?i.end.handle:i.end.point,c=t==="start"?s:a,l={id:n.id,type:"arrow",props:{[t]:{x:c.x,y:c.y},bend:n.props.bend}};if(!i.isStraight){const u=t==="start"?s:i.start.handle,d=t==="end"?a:i.end.handle,f=b.Med(u,d),p=b.Sub(u,d).per().uni().mul(i.handleArc.radius*2*Math.sign(n.props.bend)),S=Nu(i.handleArc.center,b.Add(f,p),i.handleArc.center,i.handleArc.radius);it((S==null?void 0:S.length)===1);const m=b.Dist(f,S[0])*Math.sign(n.props.bend);Ua(m,l.props.bend)||(l.props.bend=m)}e.updateShape(l),r&&kh(e,n,t)}const p$=[Th],Kt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},Mt={s:2,m:3.5,l:5,xl:10},dc={s:18,m:24,l:36,xl:44},Uo={s:18,m:22,l:26,xl:32},hs={s:18,m:20,l:24,xl:28},uo={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},ZW=20,QW=4.25,jr=16;/*!
110
- * canvas-size
111
- * v1.2.6
112
- * https://github.com/jhildenbiddle/canvas-size
113
- * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
114
- * MIT license
115
- */function JW(e,n){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var r,o,i,s,a=[],c=!0,l=!1;try{if(i=(t=t.call(e)).next,n===0){if(Object(t)!==t)return;c=!1}else for(;!(c=(r=i.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&&(s=t.return(),Object(s)!==s))return}finally{if(l)throw o}}return a}}function vC(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),t.push.apply(t,r)}return t}function Kn(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?vC(Object(t),!0).forEach(function(r){eG(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):vC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function eG(e,n,t){return n=lG(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function tG(e,n){if(e==null)return{};var t={},r=Object.keys(e),o,i;for(i=0;i<r.length;i++)o=r[i],!(n.indexOf(o)>=0)&&(t[o]=e[o]);return t}function nG(e,n){if(e==null)return{};var t=tG(e,n),r,o;if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(o=0;o<i.length;o++)r=i[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r])}return t}function xC(e,n){return oG(e)||JW(e,n)||g$(e,n)||aG()}function Rd(e){return rG(e)||iG(e)||g$(e)||sG()}function rG(e){if(Array.isArray(e))return fv(e)}function oG(e){if(Array.isArray(e))return e}function iG(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function g$(e,n){if(e){if(typeof e=="string")return fv(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 fv(e,n)}}function fv(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 sG(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
116
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function aG(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
117
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function cG(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 lG(e){var n=cG(e,"string");return typeof n=="symbol"?n:String(n)}function Ol(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],i=Date.now(),s=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,c;s?(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()-i;return[a,c].forEach(function(p){p.height=0,p.width=0}),s?(postMessage({width:t,height:r,benchmark:f,isTestPass:d}),!d&&e.sizes.length&&Ol(e)):d?e.onSuccess(t,r,f):(e.onError(t,r,f),e.sizes.length&&Ol(e)),d}var qm={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]},uG=["onError","onSuccess"],La={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},rl={};function Zm(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 i=e.min||La.min,s=e.step||La.step,a=Math.max(e.width,e.height);a>=i;){var c=n||t?a:1,l=n||r?a:1;o.push([c,l]),a-=s}return o}function Ld(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,i=e.onSuccess,s=nG(e,uG),a=null;if(!n)return!1;if(e.useWorker&&t){var c=`
118
- var canvasTest = `.concat(Ol.toString(),`;
119
- onmessage = function(e) {
120
- canvasTest(e.data);
121
- };
122
- `),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,S=f.height,m=f.benchmark,w=f.isTestPass;w?(rl[r].onSuccess(p,S,m),delete rl[r]):rl[r].onError(p,S,m)}}if(e.usePromise)return new Promise(function(d,f){var p=Kn(Kn({},e),{},{onError:function(y,v,P){var E;if(e.sizes.length===0)E=!0;else{var C=e.sizes.slice(-1),I=xC(C,1),_=xC(I[0],2),k=_[0],$=_[1];E=y===k&&v===$}o(y,v,P),E&&f({width:y,height:v,benchmark:P})},onSuccess:function(y,v,P){i(y,v,P),d({width:y,height:v,benchmark:P})}});if(a){var S=p.onError,m=p.onSuccess;rl[r]={onError:S,onSuccess:m},a.postMessage(s)}else Ol(p)});if(a)rl[r]={onError:o,onSuccess:i},a.postMessage(s);else return Ol(e)}var Qm={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Zm({width:n.max,height:n.max,min:n.min,step:n.step,sizes:Rd(qm.area)}),r=Kn(Kn(Kn({},La),n),{},{sizes:t});return Ld(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Zm({width:1,height:n.max,min:n.min,step:n.step,sizes:Rd(qm.height)}),r=Kn(Kn(Kn({},La),n),{},{sizes:t});return Ld(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Zm({width:n.max,height:1,min:n.min,step:n.step,sizes:Rd(qm.width)}),r=Kn(Kn(Kn({},La),n),{},{sizes:t});return Ld(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Kn(Kn({},La),n);return t.sizes=Rd(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),Ld(t)}};let Jm=null;function dG(){return Jm||(Jm=hG()),Jm}async function hG(){const e=await Qm.maxWidth({usePromise:!0}),n=await Qm.maxHeight({usePromise:!0}),t=await Qm.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const wC=8192,fG=4096*4096;async function m$(e,n){if(e<=wC&&n<=wC&&e*n<=fG)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await dG(),i=e/n;if(e>t&&(e=t,n=e/i),n>r&&(n=r,e=n*i),e*n>o){const s=Math.sqrt(o/(e*n));e*=s,n*=s}return[e,n]}function pG(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 gG(e,n,t,r={}){const o=await Yn.usingObjectURL(e,Yn.loadImage),{type:i=e.type,quality:s=.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=Gn(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"))},i,s)})}function mG(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function yG(e){const n=new URL(e).host.replace("www.","");for(const t of Tu)if(y$(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const SG=e=>e.split("*").map(n=>mG(n)).join(".+"),y$=(e,n)=>!!e.find(t=>{const r=new RegExp(SG(t));return n.match(r)});function vG(e){const n=new URL(e).host.replace("www.","");for(const t of Tu)if(y$(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function S$(e){return vG(e)??yG(e)}function Ii(e){try{return S$(e)}catch(n){console.error(n)}}/*!
123
- * MIT License
124
- * Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
125
- * Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
126
- */const Fa=" ",un=class un{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)||un.insertTextFirefox(n,t),o===r.body?n.blur():o instanceof HTMLElement&&o!==n&&o.focus()}static set(n,t){n.select(),un.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:i}=n,s=un.getSelection(n);un.insert(n,t+s+(r??t)),n.selectionStart=(o||0)+t.length,n.selectionEnd=(i||0)+t.length}static replace(n,t,r){let o=0;n.value.replace(t,(...i)=>{const s=o+i[i.length-2],a=i[0].length;n.selectionStart=s,n.selectionEnd=s+a;const c=typeof r=="string"?r:r(...i);return un.insert(n,c),n.selectionStart=s,o+=c.length-a,c})}static findLineEnd(n,t){const r=n.lastIndexOf(`
127
- `,t-1)+1;return n.charAt(r)!==" "?t:r+1}static indent(n){var a;const{selectionStart:t,selectionEnd:r,value:o}=n,i=o.slice(t,r),s=(a=/\n/g.exec(i))==null?void 0:a.length;if(s&&s>0){const c=o.lastIndexOf(`
128
- `,t-1)+1,l=n.value.slice(c,r-1),u=l.replace(/^|\n/g,`$&${Fa}`),d=u.length-l.length;n.setSelectionRange(c,r-1),un.insert(n,u),n.setSelectionRange(t+1,r+d)}else un.insert(n,Fa)}static unindent(n){const{selectionStart:t,selectionEnd:r,value:o}=n,i=o.lastIndexOf(`
129
- `,t-1)+1,s=un.findLineEnd(o,r),a=n.value.slice(i,s),c=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),l=a.length-c.length;n.setSelectionRange(i,s),un.insert(n,c);const u=/\t| {1,2}/.exec(o.slice(i,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=Fd(n)??0,i=Fd(n)??0,s=r.slice(o,i),a=(c=/\n/g.exec(s))==null?void 0:c.length;if(a&&a>0){const l=r.lastIndexOf(`
130
- `,o-1)+1,u=r.slice(l,i-1),f=u.replace(/^|\n/g,`$&${Fa}`).length-u.length;t&&t.setBaseAndExtent(n,o+1,n,i+f)}else{const l=window.getSelection();n.innerText=r.slice(0,o)+Fa+r.slice(o),l==null||l.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=Fd(n)??0,i=Fd(n)??0,s=r.lastIndexOf(`
131
- `,o-1)+1,a=un.findLineEnd(r,i),c=r.slice(s,a),l=c.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=c.length-l.length;if(t){t.setBaseAndExtent(n,s,n,a);const d=/\t| {1,2}/.exec(r.slice(s,o)),f=d?d[0].length:0,p=o-f;t.setBaseAndExtent(n,o-f,n,Math.max(p,i-u))}}static normalizeText(n){return n.replace(un.fixNewLines,`
132
- `)}static normalizeTextForDom(n){return n.replace(un.fixNewLines,`
133
- `).split(`
134
- `).map(t=>t||" ").join(`
135
- `)}};g(un,"fixNewLines",/\r?\n|\r/g);let hc=un;function Fd(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 xG=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function v$(e){return xG.test(e)}function wG(e){return e.replace(/\t/g,Fa)}function bG(e){const n=e.split(`
136
- `);for(;n[0]&&n[0].trim().length===0;)n.shift();let t=1/0;for(const r of n)if(r.trim().length>0){const o=r.length-r.trimStart().length;t=Math.min(t,o)}return n.map(r=>r.slice(t)).join(`
137
- `)}function PG(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function CG(e){return PG(bG(wG(e)))}function IG(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:i,msg:s}){e.registerExternalAssetHandler("file",async({file:a})=>{const c=a.name;let l=a;const u=r.includes(l.type),d=o.includes(l.type);it(u||d,`File type not allowed: ${l.type}`),it(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 Yn.getImageSize(l):await Yn.getVideoSize(l);const p=await Yn.isAnimated(l)||d,S=await xN(await l.arrayBuffer());if(isFinite(n)){const y=pG(f,{w:n,h:n});f!==y&&Yn.isStaticImageType(l.type)&&(f=y)}!p&&Yn.isStaticImageType(l.type)&&(l=await gG(l,f.w,f.h,{type:l.type,quality:.92}));const m=fs.createId(S);return fs.create({id:m,type:u?"image":"video",typeName:"asset",props:{name:c,src:await za.blobToDataUrl(l),w:f.w,h:f.h,mimeType:l.type,isAnimated:p}})}),e.registerExternalAssetHandler("url",async({url:a})=>{var l,u,d,f,p;let c;try{const m=await(await fetch(a,{method:"GET",mode:"no-cors",referrerPolicy:"strict-origin-when-cross-origin"})).text(),w=new DOMParser().parseFromString(m,"text/html");c={image:((l=w.head.querySelector('meta[property="og:image"]'))==null?void 0:l.getAttribute("content"))??"",favicon:((u=w.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:u.getAttribute("href"))??((d=w.head.querySelector('link[rel="icon"]'))==null?void 0:d.getAttribute("href"))??"",title:((f=w.head.querySelector('meta[property="og:title"]'))==null?void 0:f.getAttribute("content"))??a,description:((p=w.head.querySelector('meta[property="og:description"]'))==null?void 0:p.getAttribute("content"))??""},c.image.startsWith("/")&&(c.image=new URL(c.image,a).href),c.favicon.startsWith("/")&&(c.favicon=new URL(c.favicon,a).href)}catch(S){console.error(S),i.addToast({title:s("assets.url.failed"),severity:"error"}),c={image:"",favicon:"",title:"",description:""}}return{id:fs.createId(tS(a)),typeName:"asset",type:"bookmark",props:{src:a,description:c.description,image:c.image,favicon:c.favicon,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 S=u.getBoundingClientRect();document.body.removeChild(u),d=S.width,f=S.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");bC(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(),S={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([S]).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 S=await e.getAssetForExternalContent({type:"file",file:f});if(!S)throw Error("Could not create an asset");d[p]=S}catch(S){return i.addToast({title:s("assets.files.upload-failed"),severity:"error"}),console.error(S),null}})),bC(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=CG(c),f=e.getOnlySelectedShape();if(f&&"text"in f.props){e.updateShapes([{id:f.id,type:f.type,props:{text:d}}]);return}let p,S,m,w="middle";const y=d.split(`
138
- `).length>1,v=v$(d);y&&(w=y?v?"end":"start":"middle");const P=e.textMeasure.measureText(d,{...Kt,fontFamily:uo[u.font],fontSize:dc[u.size],maxWidth:null}),E=Math.min(y?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(P.w>E){const C=e.textMeasure.measureText(d,{...Kt,fontFamily:uo[u.font],fontSize:dc[u.size],maxWidth:E});p=C.w,S=C.h,m=!1,w=v?"end":"start"}else p=P.w,S=P.h,m=!0;l.y-S/2<e.getViewportPageBounds().minY+40&&(l.y=e.getViewportPageBounds().minY+40+S/2),e.createShapes([{id:Be(),type:"text",x:l.x-p/2,y:l.y-S/2,props:{text:d,textAlign:w,autoSize:m,w:p}}])}),e.registerExternalContentHandler("url",async({point:a,url:c})=>{const l=Ii(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=fs.createId(tS(c)),f=EG(e,c,u);let p=e.getAsset(d),S=!1;if(!p){S=!0;try{const m=await e.getAssetForExternalContent({type:"url",url:c});if(!m)throw Error("Could not create an asset");p=m}catch{i.addToast({title:s("assets.url.failed"),severity:"error"});return}}e.batch(()=>{S&&e.createAssets([p]),e.updateShapes([{id:f.id,type:f.type,props:{assetId:p.id}}])})})}async function bC(e,n,t){if(!n.length)return[];const r=b.From(t),o=[];for(const i of n)switch(i.type){case"bookmark":{o.push({id:Be(),type:"bookmark",x:r.x-150,y:r.y-160,opacity:1,props:{assetId:i.id,url:i.props.src}}),r.x+=300;break}case"image":{o.push({id:Be(),type:"image",x:r.x-i.props.w/2,y:r.y-i.props.h/2,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":o.push({id:Be(),type:"video",x:r.x-i.props.w/2,y:r.y-i.props.h/2,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}return e.batch(()=>{const i=n.filter(s=>!e.getAsset(s.id));i.length&&e.createAssets(i),e.createShapes(o).select(...o.map(s=>s.id)),x$(e,t)}),o.map(i=>i.id)}function x$(e,n){const t=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const o=r.center.sub(n);e.updateShapes(e.getSelectedShapes().map(i=>{const s=e.getShapeParentTransform(i).decompose().rotation,a=b.Rot(o,-s);return{id:i.id,type:i.type,x:i.x-a.x,y:i.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!t.contains(r)&&e.zoomToSelection()}function EG(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),x$(e,t)}),e.getShape(r.id)}var Py;let _G=(Py=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(Py,"id","idle"),Py);var Cy;let kG=(Cy=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 i=this.editor.getShapeHandles(o);if(!i)throw Error("expected handles for arrow");const s=this.editor.getShapeUtil("arrow"),a=this.shape,c=i.find(d=>d.id==="start"),l=(u=s.onHandleDrag)==null?void 0:u.call(s,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,i;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 s=this.editor.getShapeUtil("arrow"),a=this.shape,c=r.find(u=>u.id==="start"),l=(o=s.onHandleDrag)==null?void 0:o.call(s,t,{handle:{...c,x:0,y:0},isPrecise:this.didTimeout,initial:a});l&&this.editor.updateShapes([l])}{const s=this.editor.getShapeUtil("arrow"),a=this.shape,c=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),l=r.find(d=>d.id==="end"),u=(i=s.onHandleDrag)==null?void 0:i.call(s,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=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},g(Cy,"id","pointing"),Cy);class $h extends se{constructor(){super(...arguments);g(this,"shapeType","arrow")}}g($h,"id","arrow"),g($h,"initial","idle"),g($h,"children",()=>[_G,kG]);class Yx 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=Mt[r],i=t[0].points[0],s=t[t.length-1],a=s.points[s.points.length-1];return i!==a&&this.currentLineLength>o*4&&b.DistMin(i,a,o*2)}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+ot(),this.editor.mark(this.markId);const{z:o=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||o>0&&o<.5||o>.5&&o<1;const i=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=Ft(a.props.segments);if(!c)throw Error("Expected a previous segment!");const l=Ft(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:+i.toFixed(2)},{x:u,y:d,z:+i.toFixed(2)}]},p=ie.applyToPoint(this.editor.getShapePageTransform(a.id),l);this.pagePointWhereCurrentSegmentChanged=p,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,f];this.currentLineLength<Mt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const m={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(m.props.isClosed=this.getIsClosed(S,a.props.size)),this.editor.updateShapes([m]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const s=Be();this.editor.createShapes([{id:s,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPenOrStylus,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+i.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(s)}updateDrawingShape(){const{initialShape:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:o,props:{size:i}}=t,s=this.editor.getShape(o);if(!s)return;const{segments:a}=s.props,{x:c,y:l,z:u}=this.editor.getPointInShapeSpace(s,r.currentPagePoint).toFixed(),d=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,f={x:c,y:l,z:d};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(b.Dist2(p,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const m=Ft(a);if(!m)throw Error("Expected a previous segment!");const w=Ft(m.points);if(!w)throw Error("Expected a previous last point!");let y;const v=this.editor.getPointInShapeSpace(s,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(m.type==="straight"){this.currentLineLength+=b.Dist(w,v),y={type:"straight",points:[{...w},v]};const E=this.editor.getShapePageTransform(s);this.pagePointWhereCurrentSegmentChanged=ie.applyToPoint(E,w)}else y={type:"straight",points:[v,f]};const P={id:o,type:this.shapeType,props:{segments:[...a,y]}};this.canClose()&&(P.props.isClosed=this.getIsClosed(a,i)),this.editor.updateShapes([P])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(b.Dist2(p,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const m=a.slice(),w=m[m.length-1],y=Ft(w.points);if(!y)throw Error("No previous point!");const v={type:"free",points:[...b.PointsBetween(y,f,6).map(C=>C.toFixed().toJson())]},P=[...m,v];this.currentLineLength<Mt[s.props.size]*4&&(this.currentLineLength=this.getLineLength(P));const E={id:o,type:this.shapeType,props:{segments:P}};this.canClose()&&(E.props.isClosed=this.getIsClosed(P,i)),this.editor.updateShapes([E])}break}case"straight":{const p=a.slice(),S=p[p.length-1],{pagePointWhereCurrentSegmentChanged:m}=this,{ctrlKey:w,currentPagePoint:y}=this.editor.inputs;if(!m)throw Error("We should have a point where the segment changed");let v,P=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(P=!w,this.didJustShiftClickToExtendPreviousShapeLine=!1):P=!w;let E=this.editor.getPointInShapeSpace(s,y).toFixed().toJson(),C=!1,I;if((this.editor.user.getIsSnapMode()?!w:w)&&p.length>2){let $,T=8/this.editor.getZoomLevel();for(let A=0,N=a.length-2;A<N;A++){const j=a[A];if(!j)break;if(j.type==="free")continue;const O=j.points[0],R=Ft(j.points);if(!(O&&R))continue;const Y=b.NearestPointOnLineSegment(O,R,E);if(b.DistMin(Y,E,T)){$=Y.toFixed().toJson(),T=b.Dist(Y,E),I=j;break}}$&&(C=!0,E=$)}if(C&&I){const $=this.editor.getShapePageTransform(s),T=I.points[0],A=Ft(I.points);if(!A)throw Error("Expected a last point!");const N=ie.applyToPoint($,T),j=ie.applyToPoint($,A),O=ie.applyToPoint($,E);this.editor.snaps.setIndicators([{id:ot(),type:"points",points:[N,O,j]}])}else{if(this.editor.snaps.clearIndicators(),P){const $=b.Angle(m,y),A=Tf($,24)-$;v=b.RotWith(y,m,A)}else v=y;E=this.editor.getPointInShapeSpace(s,v).toFixed().toJson()}this.currentLineLength+=b.Dist(S.points[0],E),p[p.length-1]={...S,type:"straight",points:[S.points[0],E]};const k={id:o,type:this.shapeType,props:{segments:p}};this.canClose()&&(k.props.isClosed=this.getIsClosed(a,i)),this.editor.updateShapes([k]);break}case"free":{const p=a.slice(),S=p[p.length-1],m=[...S.points];if(m.length&&this.mergeNextPoint){const{z:y}=m[m.length-1];m[m.length-1]={x:f.x,y:f.y,z:y?Math.max(y,f.z):f.z}}else this.currentLineLength+=b.Dist(m[m.length-1],f),m.push(f);p[p.length-1]={...S,points:m},this.currentLineLength<Mt[s.props.size]*4&&(this.currentLineLength=this.getLineLength(p));const w={id:o,type:this.shapeType,props:{segments:p}};if(this.canClose()&&(w.props.isClosed=this.getIsClosed(p,i)),this.editor.updateShapes([w]),m.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const y=Be();this.editor.createShapes([{id:y,type:this.shapeType,x:rc(r.currentPagePoint.x),y:rc(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=vt(this.editor.getShape(y)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(t){let r=0;for(const o of t)for(let i=0;i<o.points.length-1;i++){const s=o.points[i],a=o.points[i+1];r+=b.Dist2(a,s)}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(Yx,"id","drawing");var Iy;let w$=(Iy=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(Iy,"id","idle"),Iy);class Mh extends se{constructor(){super(...arguments);g(this,"shapeType","draw");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Mh,"id","draw"),g(Mh,"initial","idle"),g(Mh,"children",()=>[w$,Yx]);class pv extends _h{constructor(){super(...arguments);g(this,"shapeType","frame");g(this,"onCreate",t=>{if(!t)return;const r=this.editor.getShapePageBounds(t),o=[],i=this.editor.getShapeAncestors(t).map(s=>s.id);this.editor.getSortedChildIdsForParent(t.parentId).map(s=>{const a=this.editor.getShape(s);if(!a||a.id===t.id||a.isLocked)return;const c=this.editor.getShapePageBounds(a);c&&r.contains(c)&&TG(a,i,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(pv,"id","frame"),g(pv,"initial","idle");function TG(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var Ey;let $G=(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,"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(Ey,"id","idle"),Ey);var _y;let MG=(_y=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(so)}}]).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(so),w:1,h:1}}]);const o=this.editor.getShape(r);if(!o)return;const i=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),s=i.center,a=this.editor.getShapeParentTransform(o);a&&s.rot(-a.rotation()),this.editor.select(r),this.editor.updateShapes([{id:o.id,type:"geo",x:o.x-s.x,y:o.y-s.y,props:{geo:this.editor.getStyleForNextShape(so),w:i.width,h:i.height}}]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},g(_y,"id","pointing"),_y);class Ah extends se{constructor(){super(...arguments);g(this,"shapeType","geo")}}g(Ah,"id","geo"),g(Ah,"initial","idle"),g(Ah,"children",()=>[$G,MG]);class jh extends se{constructor(){super(...arguments);g(this,"shapeType","highlight");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(jh,"id","highlight"),g(jh,"initial","idle"),g(jh,"children",()=>[w$,Yx]);var ky;let AG=(ky=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(ky,"id","idle"),ky);const PC=2;var Ty;let jG=(Ty=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 i=t.shapeId&&this.editor.getShape(t.shapeId);if(i&&r.shiftKey){this.markId=`creating:${i.id}`,this.editor.mark(this.markId),this.shape=i;const s=this.editor.getShapeHandles(this.shape);if(!s)return;const a=s.filter(p=>p.type==="vertex").sort(en),c=a[a.length-1],l=a[a.length-2],u=ie.applyToPoint(this.editor.getShapeParentTransform(this.shape),new b(this.shape.x,this.shape.y)),d=b.Sub(o,u).addXY(.1,.1),f=vt(this.shape.props.points);if(b.DistMin(c,l,PC)||b.DistMin(d,c,PC))f[c.id]={id:c.id,index:c.index,x:d.x,y:d.y};else{const p=Do(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 s=Be();this.markId=`creating:${s}`,this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:"line",x:o.x,y:o.y}]),this.editor.select(s),this.shape=this.editor.getShape(s)}});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=Ft(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(Ty,"id","pointing"),Ty);class Oh extends se{constructor(){super(...arguments);g(this,"shapeType","line")}}g(Oh,"id","line"),g(Oh,"initial","idle"),g(Oh,"children",()=>[AG,jG]);var $y;let OG=($y=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g($y,"id","idle"),$y);function We(e,n){var o;const t=new Set;for(const i of n){const s=e.getShape(i);if(!s)continue;e.getShapeUtil(s).onDragShapesOut&&t.add(s);const a=e.getShape(s.parentId);a&&e.getShapeUtil(a).onDragShapesOut&&t.add(a)}const r=new Map;for(const i of t){const s=b$(e,i);s.length&&r.set(i,s)}for(const[i,s]of r){const a=e.getShapeUtil(i),c=ye(s.map(l=>e.getShape(l)));(o=a.onDragShapesOut)==null||o.call(a,i,c)}}function b$(e,n){const t=e.getSortedChildIdsForParent(n.id);if(t.length===0)return[];const r=e.getShapePageBounds(n);if(!r)return[];let o,i,s;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)),i??(i=e.getShapePageTransform(n)),s??(s=i.applyToPoints(o.vertices));const u=e.getShapePageTransform(c).clone().invert().applyToPoints(s),{vertices:d,isClosed:f}=e.getShapeGeometry(c);if(!d.some(p=>Jn(p,u))){if(f){if(G2(u,d))continue}else if(NH(u,d))continue;a.push(c)}}return a}function cp(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}),P$(e)}const DG=16;function P$(e){const n=e.getSelectionPageBounds(),t=e.getViewportPageBounds();if(n&&!t.contains(n)){const r=n.clone().expandBy(DG/e.getZoomLevel()).expand(t),o=t.clone().translate({x:(r.center.x-t.center.x)*2,y:(r.center.y-t.center.y)*2});e.zoomToBounds(o,{animation:{duration:e.options.animationMediumMs},inset:0})}}const Na=20,RG=0,$e=200,Xx={x:$e/2,y:$e/2},C$=10,LG={a1:new b($e*.5,$e*-.5-Na),a2:new b($e*1.5+Na,$e*.5),a3:new b($e*.5,$e*1.5+Na),a4:new b($e*-.5-Na,$e*.5)};function I$(e,n,t,r){return Object.fromEntries(Object.entries(LG).map(([o,i],s)=>{const a=i.clone();return s===0&&r?a.y-=r:s===2&&t&&(a.y+=t),[o,a.rot(n).add(e)]}))}function E$(e,n,t){const r=new Set(e.getSelectedShapeIds()),o=($e+Na+t)**2,i=new Map,s=[];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()&&(i.set(l,e.getShapePageBounds(l).center),s.push(...Object.values(I$(u.point(),n,l.props.growY,t))))}const a=s.length;let c;for(const[l,u]of i)for(let d=0;d<a;d++)c=s[d],c&&(b.Dist2(u,c)>o||e.isPointInShape(l,c)&&(s[d]=void 0));return ye(s)}function _$(e,n,t,r,o=!1){let i;const s=e.getCurrentPageShapesSorted(),a=$e+Na**2;for(let c=s.length-1;c>=0;c--){const l=s[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)){i=l;break}}}if(e.complete(),!i||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(Xx,r)));e.updateShape({id:c,type:"note",x:u.x,y:u.y}),i=e.getShape(c)}return P$(e),i}var My;let FG=(My=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(),i=CC(this.editor,o);i&&o.sub(i),this.shape=IC(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(),i=CC(this.editor,o);i&&o.sub(i),this.shape=IC(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(My,"id","pointing"),My);function CC(e,n){let t=C$/e.getZoomLevel(),r;for(const o of E$(e,0,0)){const i=b.Sub(n,o),s=i.len();s<t&&(t=s,r=i)}return r}function IC(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 Dh extends se{constructor(){super(...arguments);g(this,"shapeType","note")}}g(Dh,"id","note"),g(Dh,"initial","idle"),g(Dh,"children",()=>[OG,FG]);function NG(e){const n=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),renderingOnly:!0});if(!n)return e.setHoveredShape(null);let t;const r=e.getOutermostSelectableShape(n);return r===n||r.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(r.id)?t=n:t=r,e.setHoveredShape(t.id)}const Qa=vN(NG,32);var Ay;let zG=(Ay=class extends se{constructor(){super(...arguments);g(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Qa(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(Ay,"id","idle"),Ay);var jy;let BG=(jy=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:i}=this;this.editor.setCurrentTool("select.resizing",{...t,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:18,y:1},onInteractionEnd:"text",onCreate:()=>{this.editor.setEditingShape(i.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 i;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"),(i=this.editor.root.getCurrent())==null||i.transition("editing_shape")}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}},g(jy,"id","pointing"),jy);class Rh extends se{constructor(){super(...arguments);g(this,"shapeType","text")}}g(Rh,"id","text"),g(Rh,"initial","idle"),g(Rh,"children",()=>[zG,BG]);const UG=[Rh,Mh,Ah,Dh,Oh,pv,$h,jh];function fc(e){return{key:`${ho.id}:${e}`,getElement:async()=>{const n=HG(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await fetch(t,{referrerPolicy:"strict-origin-when-cross-origin"})).blob(),i=await za.blobToDataUrl(o),s=r.replace(t,i);return h.jsx("style",{children:s})}}}function HG(e){const n=P_[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function qx(e){return{key:`${ho.id}:${e}`,getElement:async()=>e!=="pattern"?null:h.jsx(KG,{})}}function KG(){const e=Ir(),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:lp(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 Zx(){return{key:`${ho.id}:pattern`,component:YG}}const Sl=8,EC=(e,n,t)=>new Promise((r,o)=>{const i=Sl*n*e,s=document.createElement("canvas");s.width=i,s.height=i;const a=s.getContext("2d");if(!a)return;a.fillStyle=t?bf.darkMode.solid:bf.lightMode.solid,a.fillRect(0,0,i,i),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(),s.toBlob(u=>{!u||bt.throwToBlob.get()?o():r(u)})}),_C=(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 ey=null;function WG(){return ey||(ey={white:_C([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:_C([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),ey}function k$(e){return Math.ceil(Math.log2(Math.max(1,e)))}function lp(e,n){const t=k$(e);return`tldraw_hash_pattern_${n}_${t}`}function T$(e){const n=[],r=k$(e);for(let o=0;o<=r;o++)n.push(Math.pow(2,o));return n}function GG(e){const n=WG();return T$(e).flatMap(t=>[{zoom:t,url:n.white,theme:"light"},{zoom:t,url:n.black,theme:"dark"}])}function VG(){const e=z(),n=G("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),t=G("maxZoom",()=>Math.ceil(Ft(e.getCameraOptions().zoomSteps)),[e]),[r,o]=x.useState(!1),[i,s]=x.useState(()=>GG(t));return x.useEffect(()=>{const c=Promise.all(T$(t).flatMap(u=>[EC(n,u,!1).then(d=>({zoom:u,theme:"light",url:URL.createObjectURL(d)})),EC(n,u,!0).then(d=>({zoom:u,theme:"dark",url:URL.createObjectURL(d)}))]));let l=!1;return c.then(u=>{l||(s(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:i.map(c=>{const l=lp(c.zoom,c.theme);return h.jsx("pattern",{id:l,width:Sl,height:Sl,patternUnits:"userSpaceOnUse",children:h.jsx("image",{href:c.url,width:Sl,height:Sl})},l)})}),isReady:r}}function YG(){const e=z(),n=x.useRef(null),{defs:t,isReady:r}=VG();return x.useEffect(()=>{if(r&&e.environment.isSafari){const o=$$(n.current);o&&e.timers.requestAnimationFrame(()=>{o.style.display="none",e.timers.requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),h.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function $$(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?$$(e.parentElement):null}function Ir(){return ei({isDarkMode:Bu()})}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(XG,{theme:n,color:r,fill:o,d:t})}});function XG({d:e,color:n,theme:t}){const r=z(),o=Z2(),i=G("zoomLevel",()=>r.getZoomLevel(),[r]),s=r.getZoomLevel()<=.18;return h.jsxs(h.Fragment,{children:[h.jsx("path",{fill:t[n].pattern,d:e}),h.jsx("path",{fill:o?`url(#${lp(1,t.id)})`:s?t[n].semi:`url(#${lp(i,t.id)})`,d:e})]})}function qG(e){return e.replace(/\s/g," ")}function gv(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 i=r+(t.offsetX??0),s=(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:i,y:u.y+s,children:`
139
- `},c.length)),c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+i,y:u.y+s,unicodeBidi:"plaintext",children:qG(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 ZG(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=J.From(t[0].box);for(const{box:i}of t)o.union(i);if(e==="start-legacy")return(r-2*n-o.width)/2;if(e==="end-legacy")return-(r-2*n-o.width)/2}}function QG(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function eg({fontSize:e,font:n,align:t,verticalAlign:r,text:o,labelColor:i,bounds:s,padding:a=16,stroke:c=!0}){const l=z(),u=Ir(),d={fontSize:e,fontFamily:P_[n],textAlign:t,verticalTextAlign:r,width:Math.ceil(s.width),height:Math.ceil(s.height),padding:a,lineHeight:Kt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:i,stroke:void 0,strokeWidth:void 0},f=l.textMeasure.measureTextSpans(o,d),p=ZG(t,a,f,s.width);p&&(d.offsetX=p),d.offsetX+=s.x,d.offsetY+=s.y;const S=gv(l,f,d);let m=null;return c&&(d.fill=u.background,d.stroke=u.background,d.strokeWidth=2,m=gv(l,f,d)),h.jsxs(h.Fragment,{children:[m,S]})}function Qr(e,n,t={}){const{closed:r=!1,snap:o=1,start:i="outset",end:s="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||(i==="outset"?(e+=l/2,p+=l/2):i==="skip"&&(e-=l,p-=l),s==="outset"?e+=l/2:s==="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 kC=new WeakMap;function Qx(e,n){const t=kC.get(n);if(t)return t;const r=ro(e,n);let o=0,i=0;const s=r.isStraight?new Fo({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=s.bounds,{w:l,h:u}=e.textMeasure.measureText(n.props.text,{...Kt,fontFamily:uo[n.props.font],fontSize:hs[n.props.size],maxWidth:null});if(o=l,i=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,{...Kt,fontFamily:uo[n.props.font],fontSize:hs[n.props.size],maxWidth:o});o=d,i=f}if(o>16*hs[n.props.size]){o=16*hs[n.props.size];const{w:d,h:f}=e.textMeasure.measureText(n.props.text,{...Kt,fontFamily:uo[n.props.font],fontSize:hs[n.props.size],maxWidth:o});o=d,i=f}}const a=new b(o,i).addScalar(QW*2);return kC.set(n,a),a}function M$(e,n){const t=Mt[n.props.size];return ZW+(t-Mt.s)*2+(t===Mt.xl?20:0)}function JG(e,n,t){const r=Qx(e,n),o=M$(e,n),i=b.Nudge(t.start.point,t.end.point,o),s=b.Nudge(t.end.point,t.start.point,o),a=Dx(i,s,J.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[c,l]=a;b.Dist2(c,i)>b.Dist2(l,i)&&([l,c]=a);const u=i.add(b.Sub(t.middle,c)),d=s.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=Qx(e,n),o=M$(e,n),i=Math.sign(n.props.bend),s=o/t.handleArc.radius*i,a=b.Angle(t.bodyArc.center,t.start.point)-s,c=b.Angle(t.bodyArc.center,t.end.point)+s,l=ks(t.bodyArc.center,t.bodyArc.radius,a),u=ks(t.bodyArc.center,t.bodyArc.radius,c),d=[],f=TC(t.bodyArc.center,t.bodyArc.radius,a,c,i,J.FromCenter(l,r).corners);d.push(new wt({points:J.FromCenter(l,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const p=TC(t.bodyArc.center,t.bodyArc.radius,a,c,i,J.FromCenter(u,r).corners);d.push(new wt({points:J.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const _ of[...f??[],...p??[],l,u])d.push(new Kx({x:_.x-3,y:_.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const S=(f&&$C(t.start.point,f))??t.middle,m=(p&&$C(t.end.point,p))??t.middle,w=b.Angle(t.bodyArc.center,t.start.point),y=b.Angle(t.bodyArc.center,t.end.point),v=b.Angle(t.bodyArc.center,S),P=b.Angle(t.bodyArc.center,m);if(Si(w,v,i)>Si(w,P,i))return{start:.5,end:.5,dbg:d};const E=Si(w,y,i),C=Si(w,v,i)/E,I=Si(w,P,i)/E;return{start:C,end:I,dbg:d}}function Lh(e,n){let t;const r=[],o=ro(e,n),i=!!o.bindings.start,s=!!o.bindings.end,a=o.start.arrowhead!=="none",c=o.end.arrowhead!=="none";if(o.isStraight){const u=JG(e,n,o);let d=Tt(n.props.labelPosition,a||i?u.start:0,c||s?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=Tt(n.props.labelPosition,a||i?u.start:0,c||s?u.end:1);d=d>=.48&&d<=.52?.5:d;const f=tV(b.Angle(o.bodyArc.center,o.start.point),b.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),d);t=ks(o.bodyArc.center,o.bodyArc.radius,f)}const l=Qx(e,n);return{box:J.FromCenter(t,l),debugGeom:r}}function TC(e,n,t,r,o,i){const s=cv(e,n,i),a=Si(t,r,o);return s==null?void 0:s.filter(c=>{const l=Si(t,b.Angle(e,c),o);return l>=0&&l<=a})}function $C(e,n){let t=null,r=-1/0;for(const o of n){const i=b.Dist2(e,o);i>r&&(t=o,r=i)}return t}function tV(e,n,t,r){const o=Si(e,n,t);return e+o*r*t*-1}function nV(e,n,t){const r=n==="end"?e.end.point:e.start.point,o=n==="end"?e.start.point:e.end.point,i=e.isStraight?b.Dist(o,r):Math.abs(e.bodyArc.length),s=Math.max(Math.min(i/5,t*3),t);let a;if(e.isStraight)a=b.Nudge(r,o,s);else{const c=LH(r,s,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 rV({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 oV({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 iV({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 sV({point:e,int:n}){const t=b.Lrp(e,n,.45),r=b.Dist(t,e);return`M ${t.x-r},${t.y}
140
- a ${r},${r} 0 1,0 ${r*2},0
141
- a ${r},${r} 0 1,0 -${r*2},0 `}function aV({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),i=b.Lrp(r,o,.5);return i.add(b.Sub(i,e)),`M ${i.x} ${i.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function cV({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)),i=b.Sub(n,b.Rot(r,Ve)),s=b.Add(t,b.Rot(r,Ve)),a=b.Sub(t,b.Rot(r,Ve));return`M ${o.x} ${o.y} L ${s.x} ${s.y} L ${a.x} ${a.y} L ${i.x} ${i.y} Z`}function lV({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 up(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=nV(e,n,t);if(o){switch(r){case"bar":return lV(o);case"square":return cV(o);case"diamond":return aV(o);case"dot":return sV(o);case"inverted":return iV(o);case"arrow":return rV(o);case"triangle":return oV(o)}return""}}function uV(e){const{start:n,end:t,handleArc:{radius:r,largeArcFlag:o,sweepFlag:i}}=e;return`M${n.handle.x},${n.handle.y} A${r} ${r} 0 ${o} ${i} ${t.handle.x},${t.handle.y}`}function A$(e){const{start:n,end:t,bodyArc:{radius:r,largeArcFlag:o,sweepFlag:i}}=e;return`M${n.point.x},${n.point.y} A${r} ${r} 0 ${o} ${i} ${t.point.x},${t.point.y}`}function j$(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function dV(e){return j$(e.start.handle,e.end.handle)}function O$(e){return j$(e.start.point,e.end.point)}const hV=x.forwardRef(function({isEditing:n,text:t,handleFocus:r,handleChange:o,handleKeyDown:i,handleBlur:s,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:i,onBlur:s,onTouchEnd:Ut,onContextMenu:n?Ut:void 0,onPointerDown:a,onDoubleClick:c,onDragStart:_e})});function fV(e,n,t){const r=z(),o=x.useRef(null),i=G("isEditing",()=>r.getEditingShapeId()===e,[r]),s=G("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,i]),x.useEffect(()=>{var u,d,f,p;i&&(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,i]);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=hc.normalizeText(u.currentTarget.value);const f=d.replace(/\t/g,Fa);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({...kn(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Ut(u)},[r,e]);return{rInput:o,handleFocus:df,handleBlur:df,handleKeyDown:a,handleChange:c,handleInputPointerDown:l,handleDoubleClick:Ut,isEmpty:t.trim().length===0,isEditing:i,isEditingAnything:s}}const tg=Se.memo(function({id:n,type:t,text:r,labelColor:o,font:i,fontSize:s,lineHeight:a,align:c,verticalAlign:l,wrap:u,isSelected:d,onKeyDown:f,classNamePrefix:p,style:S,textWidth:m,textHeight:w}){const{rInput:y,isEmpty:v,isEditing:P,isEditingAnything:E,...C}=fV(n,t,r),[I,_]=x.useState(r);x.useEffect(()=>{P||_(r)},[P,r]);const k=hc.normalizeTextForDom(r),$=k.length>0,T=QG(c);if(!P&&!$)return null;const A=p||"tl-text";return h.jsx("div",{className:`${A}-label tl-text-wrapper`,"data-font":i,"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,...S},children:h.jsxs("div",{className:`${A}-label__inner tl-text-content__wrapper`,style:{fontSize:s,lineHeight:Math.floor(s*a)+"px",minHeight:a+32,minWidth:Math.ceil(m||0),color:o,width:m?Math.ceil(m):void 0,height:w?Math.ceil(w):void 0},children:[h.jsx("div",{className:`${A} tl-text tl-text-content`,dir:"auto",children:k.split(`
142
- `).map((N,j)=>h.jsx("div",{dir:"auto",children:N},j))}),(E||d)&&h.jsx(hV,{ref:y,text:r,isEditing:P,...C,handleKeyDown:f??C.handleKeyDown},I)]})})}),pV=x.memo(function({id:n,text:t,size:r,font:o,position:i,width:s,isSelected:a,labelColor:c}){const l=Ir();return h.jsx(tg,{id:n,classNamePrefix:"tl-arrow",type:"arrow",font:o,fontSize:hs[r],lineHeight:Kt.lineHeight,align:"middle",verticalAlign:"middle",text:t,labelColor:l[c].solid,textWidth:s,isSelected:a,style:{transform:`translate(${i.x}px, ${i.y}px)`}})});let gV=0;class Fh extends Nr{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=En(this.editor,t);return!r.start&&!r.end});g(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const i=r.id,s=En(this.editor,t);if(i==="middle"){const{start:I,end:_}=Da(this.editor,t,s),k=b.Sub(_,I),$=b.Per(k),T=b.Med(_,I),A=b.Sub(T,$),N=b.Add(T,$),j=b.NearestPointOnLineSegment(A,N,r,!1);let O=b.Dist(j,T);return b.Clockwise(j,_,T)&&(O*=-1),{id:t.id,type:t.type,props:{bend:O}}}const a={id:t.id,type:"arrow",props:{}},c=s[i],u=s[i==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return kh(this.editor,t,i),a.props[i]={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 kh(this.editor,t,i),a.props[i]={x:r.x,y:r.y},a;const p=this.editor.getShapeGeometry(f),S=J.ZeroFix(p.bounds),w=this.editor.getShapePageTransform(a.id).applyToPoint(r),y=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:(y.x-S.minX)/S.width,y:(y.y-S.minY)/S.height};v&&b.Dist(y,S.center)<Math.max(4,Math.min(Math.min(S.width,S.height)*.15,16))/this.editor.getZoomLevel()&&(P.x=.5,P.y=.5);const E={terminal:i,normalizedAnchor:P,isPrecise:v,isExact:this.editor.inputs.altKey};nl(this.editor,t,f.id,E),this.editor.setHintingShapes([f.id]);const C=En(this.editor,t);return C.start&&C.end&&C.start.toId===C.end.toId&&b.Equals(C.start.props.normalizedAnchor,C.end.props.normalizedAnchor)&&nl(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=En(this.editor,t),o=Da(this.editor,t,r),i=this.editor.getShapePageTransform(t.id),s=this.editor.getSelectedShapeIds();if(!(r.start&&(s.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(s.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){AC.set(t,{pagePosition:i.applyToPoint(t),terminalBindings:_u(o,(a,c)=>{const l=r[a];return l?{binding:l,shapePosition:c,pagePosition:i.applyToPoint(c)}:null})}),r.start&&(ap({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&ap({editor:this.editor,arrow:t,terminal:"end",useHandle:!0});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=AC.get(t);if(!o)return;const i=this.editor.getShapePageTransform(r.id),s=b.Sub(i.applyToPoint(r),o.pagePosition);for(const a of Object.values(o.terminalBindings)){if(!a)continue;const c=b.Add(a.pagePosition,b.Mul(s,.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};nl(this.editor,r,l.id,{...a.binding.props,normalizedAnchor:f,isPrecise:!0})}else kh(this.editor,r,a.binding.props.terminal)}});g(this,"_resizeInitialBindings",new Cs);g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:i}=r,s=this._resizeInitialBindings.get(t,()=>En(this.editor,t)),a=Da(this.editor,t,s),{start:c,end:l}=vt(t.props);let{bend:u}=t.props;s.start||(c.x=a.start.x*o,c.y=a.start.y*i),s.end||(l.x=a.end.x*o,l.y=a.end.y*i);const d=Math.abs(o),f=Math.abs(i),p=s!=null&&s.start?b.From(s.start.props.normalizedAnchor):null,S=s!=null&&s.end?b.From(s.end.props.normalizedAnchor):null;return o<0&&i>=0?(u!==0&&(u*=-1,u*=Math.max(d,f)),p&&(p.x=1-p.x),S&&(S.x=1-S.x)):o>=0&&i<0?(u!==0&&(u*=-1,u*=Math.max(d,f)),p&&(p.y=1-p.y),S&&(S.y=1-S.y)):o>=0&&i>=0?u!==0&&(u*=Math.max(d,f)):o<0&&i<0&&(u!==0&&(u*=Math.max(d,f)),p&&(p.x=1-p.x,p.y=1-p.y),S&&(S.x=1-S.x,S.y=1-S.y)),s.start&&p&&nl(this.editor,t,s.start.toId,{...s.start.props,normalizedAnchor:p.toJson()}),s.end&&S&&nl(this.editor,t,s.end.toId,{...s.end.props,normalizedAnchor:S.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:i}}=t;i.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:i.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=ro(this.editor,t),o=[],i=r.isStraight?new Fo({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 s;if(t.props.text.trim()){const a=Lh(this.editor,t);o.push(...a.debugGeom),s=new Xo({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Br({children:[...s?[i,s]:[i],...o]})}getHandles(t){const r=ro(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,i=ro(this.editor,t);if(!(i!=null&&i.isValid))return null;const s=Lh(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(zi,{id:t.id,style:{minWidth:50,minHeight:50},children:h.jsx(MC,{shape:t,shouldDisplayHandles:o&&(r==null?void 0:r.id)===t.id})}),l&&h.jsx(pV,{id:t.id,text:t.props.text,font:t.props.font,size:t.props.size,position:s.box.center,width:s.box.w,isSelected:a,labelColor:t.props.labelColor})]})}indicator(t){const r=Qp(t.id),o=ro(this.editor,t);if(!o)return null;const{start:i,end:s}=Da(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(i,s))return null;const u=Mt[t.props.size],d=o.start.arrowhead&&up(o,"start",u),f=o.end.arrowhead&&up(o,"end",u),p=o.isStraight?O$(o):A$(o),S=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:[S&&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",{...S?{mask:`url(#${m})`}:void 0,children:[S&&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(qx(t.props.fill)),t.props.text&&r.addExportDef(fc(t.props.font));const o=ei(r);return h.jsxs(h.Fragment,{children:[h.jsx(MC,{shape:t,shouldDisplayHandles:!1}),h.jsx(eg,{fontSize:hs[t.props.size],font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:o[t.props.labelColor].solid,bounds:Lh(this.editor,t).box,padding:4})]})}getCanvasSvgDefs(){return[Zx(),{key:"arrow:dot",component:yV},{key:"arrow:cross",component:SV}]}}g(Fh,"type","arrow"),g(Fh,"props",I_),g(Fh,"migrations",E_);function mV(e,n){const t=ro(e,n);return t.isStraight?b.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const MC=ir(function({shape:n,shouldDisplayHandles:t}){const r=z(),o=Ir(),i=ro(r,n),s=J.ZeroFix(r.getShapeGeometry(n).bounds),a=En(r,n),c=Se.useMemo(()=>r.environment.isSafari?gV+=1:0,[n]);if(!(i!=null&&i.isValid))return null;const l=Mt[n.props.size],u=i.start.arrowhead&&up(i,"start",l),d=i.end.arrowhead&&up(i,"end",l),f=i.isStraight?O$(i):A$(i);let p=null;if(t){const{strokeDasharray:C,strokeDashoffset:I}=Qr(mV(r,n),2,{end:"skip",start:"skip",lengthRatio:2.5});p=a.start||a.end?h.jsx("path",{className:"tl-arrow-hint",d:i.isStraight?dV(i):uV(i),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:S,strokeDashoffset:m}=Qr(i.isStraight?i.length:Math.abs(i.bodyArc.length),l,{style:n.props.dash}),w=Lh(r,n),y=!(i.start.arrowhead==="none"||i.start.arrowhead==="arrow"),v=!(i.end.arrowhead==="none"||i.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+s.minX),y:F(-100+s.minY),width:F(s.width+200),height:F(s.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&&y&&h.jsx("path",{d:u,fill:i.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),d&&v&&h.jsx("path",{d,fill:i.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(s.minX-100),y:F(s.minY-100),width:F(s.width+200),height:F(s.height+200),opacity:0}),h.jsx("path",{d:f,strokeDasharray:S,strokeDashoffset:m})]}),u&&y&&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})]})]})}),AC=new WeakMap;function yV(){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 SV(){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 jC="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 pc({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:Ut,onPointerUp:Ut,title:e,draggable:!1,children:h.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${jC}") center 100% / 100% no-repeat`,WebkitMask:`url("${jC}") center 100% / 100% no-repeat`}})})}const OC="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",vV=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Jx(e){return vV.map(t=>{const{offsetX:r,offsetY:o,blur:i,spread:s,color:a}=t,c=new b(r,o),{x:l,y:u}=c.rot(-e);return`${l}px ${u}px ${i}px ${s}px ${a}`}).join(", ")}const xV=300,D$=320,wV=46,bV=110;class Nh extends Tc{constructor(){super(...arguments);g(this,"canResize",()=>!1);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"onBeforeCreate",t=>DC(this.editor,t));g(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(nr.isValid(r.props.url))CV(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}};if(t.props.assetId!==r.props.assetId)return DC(this.editor,r)})}getDefaultProps(){return{url:"",w:xV,h:D$,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),i=PV(t);return h.jsx(Ds,{children:h.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:Jx(o)},children:[(!r||r.props.image)&&h.jsxs("div",{className:"tl-bookmark__image_container",children:[r?h.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):h.jsx("div",{className:"tl-bookmark__placeholder"}),(r==null?void 0:r.props.image)&&h.jsx(pc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),h.jsxs("div",{className:"tl-bookmark__copy_container",children:[r!=null&&r.props.title?h.jsx("h2",{className:"tl-bookmark__heading",children:r.props.title}):null,r!=null&&r.props.description&&(r!=null&&r.props.image)?h.jsx("p",{className:"tl-bookmark__description",children:r.props.description}):null,h.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ut,onPointerUp:Ut,onClick:Ut,children:[r!=null&&r.props.favicon?h.jsx("img",{className:"tl-bookmark__favicon",src:r==null?void 0:r.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",alt:`favicon of ${i}`}):h.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${OC}") center 100% / 100% no-repeat`,WebkitMask:`url("${OC}") center 100% / 100% no-repeat`}}),h.jsx("span",{children:i})]})]})]})})}indicator(t){return h.jsx("rect",{width:F(t.props.w),height:F(t.props.h),rx:"6",ry:"6"})}}g(Nh,"type","bookmark"),g(Nh,"props",A_),g(Nh,"migrations",j_);function DC(e,n){const t=n.props.assetId?e.getAsset(n.props.assetId):null;let r=D$;return t&&(t.props.image||(t.props.title?r=bV:r=wV)),{...n,props:{...n.props,h:r}}}const PV=e=>{try{return new URL(e.props.url).hostname.replace(/^www\./,"")}catch{return e.props.url}};function CV(e,n){const{url:t}=n.props,r=fs.createId(tS(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}}]),IV(e,n))}const IV=KE(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 Rs(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 i="";for(let s=2,a=t-1;s<a;s++)r=e[s].point,o=e[s+1].point,i+=Cn(r,o);return n?`M${Cn(e[0].point,e[1].point)}Q${Ee(e[1].point)}${Cn(e[1].point,e[2].point)}T${i}${Cn(e[t-1].point,e[0].point)}${Cn(e[0].point,e[1].point)}Z`:`M${Ee(e[0].point)}Q${Ee(e[1].point)}${Cn(e[1].point,e[2].point)}${e.length>3?"T":""}${i}L${Ee(e[t-1].point)}`}function EV(e,n={}){const{start:t={},end:r={}}=n,{cap:o=!0}=t,{cap:i=!0}=r;it(!t.taper&&!r.taper,"cap taper not supported here"),it(!t.easing&&!r.easing,"cap easing not supported here"),it(o&&i,"cap must be true");const s=po(e,n);Jp(s,n);const a=_V(s);let c="";for(const l of a)c+=TV(l,n);return c}function _V(e){if(e.length<=2)return[e];const n=[];let t=[e[0]],r=b.Sub(e[1].point,e[0].point).uni(),o,i,s,a,c;for(let l=1,u=e.length;l<u-1;l++){if(s=e[l-1],a=e[l],c=e[l+1],o=b.Sub(c.point,a.point).uni(),i=b.Dpr(r,o),r=o,i<-.8){const d={...a,point:a.input};t.push(d),n.push(ty(t)),t=[d];continue}if(t.push(a),!(i>.7)&&(b.Dist2(s.point,a.point)+b.Dist2(a.point,c.point))/((s.radius+a.radius+c.radius)/3)**2<1.5){t.push(a),n.push(ty(t)),t=[a];continue}}return t.push(e[e.length-1]),n.push(ty(t)),n}function ty(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 kV(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 TV(e,n={}){if(e.length===0)return"";if(e.length===1)return kV(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=h$(e,n);r.reverse();let o=`M${Ee(t[0])}T`;for(let i=1;i<t.length;i++)o+=Cn(t[i-1],t[i]);{const i=e[e.length-1],s=i.radius,a=i.vector.clone().per().neg(),c=b.Add(i.point,b.Mul(a,s)),l=b.Add(i.point,b.Mul(a,-s));o+=`${Ee(c)}A${F(s)},${F(s)} 0 0 1 ${Ee(l)}T`}for(let i=1;i<r.length;i++)o+=Cn(r[i-1],r[i]);{const i=e[0],s=i.radius,a=i.vector.clone().per(),c=b.Add(i.point,b.Mul(a,s)),l=b.Add(i.point,b.Mul(a,-s));o+=`${Ee(c)}A${F(s)},${F(s)} 0 0 1 ${Ee(l)}Z`}return o}function cu(){const e=z();return G("zoom",()=>e.getZoomLevel()<.35,[e])}const $V=e=>e*.65+Fz(e*ke/2)*.35,MV=e=>({size:1+e,thinning:.5,streamline:.62+(1+e)/8*.06,smoothing:.62,easing:on.easeOutSine,simulatePressure:!0}),AV=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:$V}),RC=e=>({size:1+e,thinning:0,streamline:.62+(1+e)/8*.06,smoothing:.62,simulatePressure:!1,easing:on.linear});function mv({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:on.easeOutSine,last:n}}function yv(e,n,t,r){return{...r?RC(n):e.dash==="draw"?e.isPen?AV(n):MV(n):RC(n),last:e.isComplete||t}}function lu(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 jV(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class zh extends Nr{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>ny(t));g(this,"hideRotateHandle",t=>ny(t));g(this,"hideSelectionBoundsFg",t=>ny(t));g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:i}=r,s=[];for(const a of t.props.segments)s.push({...a,points:a.points.map(({x:c,y:l,z:u})=>({x:rc(o*c),y:rc(i*l),z:u}))});return{props:{segments:s}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1}}getGeometry(t){const r=lu(t.props.segments),o=Mt[t.props.size];if(t.props.segments.length===1){const s=J.FromPoints(r);if(s.width<o*2&&s.height<o*2)return new Kx({x:-o,y:-o,radius:o,isFilled:!0})}const i=po(r,yv(t.props,o,!0,!0)).map(s=>s.point);return t.props.isClosed?new wt({points:i,isFilled:t.props.fill!=="none"}):new kc({points:i})}component(t){return h.jsx(zi,{id:t.id,children:h.jsx(LC,{shape:t,forceSolid:cu()})})}indicator(t){var d;const r=cu(),o=Mt[t.props.size],i=lu(t.props.segments);let s=o;!r&&!t.props.isPen&&t.props.dash==="draw"&&i.length===1&&(s+=Kr(t.id)()*(o/6));const a=t.props.isComplete||((d=Ft(t.props.segments))==null?void 0:d.type)==="straight",c=yv(t.props,s,a,!0),l=po(i,c),u=l.length>1?Rs(l,t.props.isClosed):R$(i[0],s);return h.jsx("path",{d:u})}toSvg(t,r){return r.addExportDef(qx(t.props.fill)),h.jsx(LC,{shape:t,forceSolid:!1})}getCanvasSvgDefs(){return[Zx()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return Mt[t.props.size]*r/2}}g(zh,"type","draw"),g(zh,"props",D_),g(zh,"migrations",R_);function R$(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 ny(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function LC({shape:e,forceSolid:n}){var d;const t=Ir(),r=Mt[e.props.size],o=lu(e.props.segments),i=e.props.isComplete||((d=Ft(e.props.segments))==null?void 0:d.type)==="straight";let s=r;!n&&!e.props.isPen&&e.props.dash==="draw"&&o.length===1&&(s+=Kr(e.id)()*(r/6));const a=yv(e.props,s,i,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:Rs(po(o,a),e.props.isClosed)}):null,h.jsx("path",{d:EV(o,a),strokeLinecap:"round",fill:t[e.props.color].solid})]});const c=po(o,a),l=c.length<2,u=l?R$(o[0],0):Rs(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":jV(e,r),strokeDashoffset:"0"})]})}function OV(e,n,t={}){const{newPoint:r,handle:o,scaleX:i,scaleY:s}=n,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:u=1/0}=t;let d=e.props.w*i,f=e.props.h*s;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:S,y:m}=p.rot(e.rotation).add(r);return{x:S,y:m,props:{w:Math.min(c,d),h:Math.min(u,f)}}}const DV=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class Bh extends Tc{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",t=>!this.canResize(t));g(this,"canEdit",()=>!0);g(this,"canResize",t=>{var r,o;return!!((o=(r=Ii(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});g(this,"canEditInReadOnly",()=>!0);g(this,"isAspectRatioLocked",t=>{const r=Ii(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});g(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),i=Ii(t.props.url);let s=(i==null?void 0:i.definition.minWidth)??200,a=(i==null?void 0:i.definition.minHeight)??200;if(o){const c=t.props.w/t.props.h;c>1?s*=c:a/=c}return OV(t,r,{minWidth:s,minHeight:a})})}getDefaultProps(){return{w:300,h:300,url:""}}component(t){const{w:r,h:o,url:i}=t.props,s=Qp(t.id),a=x.useMemo(()=>S$(i),[i]),c=G("is hovering",()=>{const{editingShapeId:p,hoveredShapeId:S}=this.editor.getCurrentPageState();if(p&&S!==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=s||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(Ds,{className:"tl-embed-container",id:t.id,children:h.jsx(RV,{id:p,width:F(r),height:F(o),isInteractive:u,pageRotation:l})})}const f=DV({...Cz,...(a==null?void 0:a.definition.overridePermissions)??{}});return h.jsx(Ds,{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:Jx(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(()=>Ii(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(Bh,"type","embed"),g(Bh,"props",L_),g(Bh,"migrations",F_);function RV({id:e,file:n,isInteractive:t,width:r,height:o,style:i,pageRotation:s}){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:{...i,pointerEvents:t?"all":"none",zIndex:t?"":"-1",boxShadow:Jx(s)},srcDoc:`
143
- <html>
144
- <head>
145
- <base target="_blank">
146
- </head>
147
- <body>
148
- <script src=${`https://gist.github.com/${e}.js${n?`?file=${n}`:""}`}><\/script>
149
- <style type="text/css">
150
- * { margin: 0px; }
151
- table { height: 100%; background-color: red; }
152
- .gist { background-color: none; height: 100%; }
153
- .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
154
- </style>
155
- </body>
156
- </html>`})}const LV=x.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=z(),i=x.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(Ut(c),c.currentTarget.blur(),o.setEditingShape(null))},[o]),s=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:i,onBlur:s,onChange:a}),L$(n,"Frame")+"​"]})}),FV=function({id:n,name:t,width:r,height:o}){const i=z(),s=G("shape rotation",()=>_i(i.getShapePageTransform(n).rotation()),[i,n]),a=Qp(n),c=x.useRef(null),l=x.useCallback(S=>{const m=kn(S);i.getEditingShapeId()!==n&&(i.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:i.getShape(n),...m}),S.preventDefault())},[i,n]);x.useEffect(()=>{const S=c.current;S&&a&&(S.focus(),S.select())},[c,a]);const d=((s+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(LV,{ref:c,id:n,name:t,isEditing:a})})})};function L$(e,n){return e.match(/^\s*$/)?n:e}class Uh extends Tc{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)=>d$(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new Xo({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=Ir(),i=G("is creating this shape",()=>{const s=this.editor.getStateDescendant("select.resizing");if(!s||!s.getIsActive())return!1;const a=s==null?void 0:s.info;return a?a.isCreating&&this.editor.getOnlySelectedShapeId()===t.id:!1},[t.id]);return h.jsxs(h.Fragment,{children:[h.jsx(zi,{children:h.jsx("rect",{className:ue("tl-frame__body",{"tl-frame__creating":i}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),i?null:h.jsx(FV,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t,r){const o=ei({isDarkMode:r.isDarkMode}),a=((_i(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(L$(t.props.name,"Frame")+"​",u),f=d[0],p=Ft(d),S=p.box.w+p.box.x-f.box.x,m=gv(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:S+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(Uh,"type","frame"),g(Uh,"props",N_),g(Uh,"migrations",z_);function FC(e,n){return e>n?(ke*(n/2)+(e-n))*2:(ke*(e/2)+(n-e))*2}function F$(e,n){return ew(e,n).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function NV(e,n,t,r){const o=e/4,i=n/4,s=Kr(r),a=t*.75,c=v=>v.addXY(s()*a,s()*a),l=new b(e/2,n),u=new b(0,i*1.2),d=new b(e/2,i*.9),f=new b(e,i*1.2),p=c(new b(e/2,n)),S=c(new b(0,i*1.2)),m=c(new b(e/2,i*.9)),w=c(new b(e,i*1.2));return[new Qt({start:l,cp1:new b(o*1.5,i*3),cp2:new b(0,i*2.5),end:u}),new Qt({start:u,cp1:new b(0,-i*.32),cp2:new b(o*1.85,-i*.32),end:d}),new Qt({start:d,cp1:new b(o*2.15,-i*.32),cp2:new b(e,-i*.32),end:f}),new Qt({start:f,cp1:new b(e,i*2.5),cp2:new b(o*2.5,i*3),end:p}),new Qt({start:p,cp1:new b(o*1.5,i*3),cp2:new b(0,i*2.5),end:S}),new Qt({start:S,cp1:new b(0,-i*.32),cp2:new b(o*1.85,-i*.32),end:m}),new Qt({start:m,cp1:new b(o*2.15,-i*.32),cp2:new b(e,-i*.32),end:w}),new Qt({start:w,cp1:new b(e,i*2.5),cp2:new b(o*2.5,i*3),end:l})].map((v,P)=>v.getSvgPathData(P===0)).join(" ")+" Z"}function ew(e,n){const t=e/4,r=n/4;return[new Qt({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 Qt({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 Qt({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 Qt({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 zV(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function BV(e,n,t,r){const o=Kr(e),i=n/2,s=t/2,a=ik(i,s),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),S=l+p*u,m=Math.cos(S),w=Math.sin(S);c.push(new b(i*m+n*.5+.05*o(),s*w+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?on.easeInOutSine(p):on.easeInExpo(p)))/2)))}return po(c,zV(r))}function UV(e,n,t,r){return Rs(BV(e,n,t,r))}function Sv(e){let n="M";const t=e.length;let r,o,i;for(let s=0,a=t;s<a;s+=3)r=e[s],o=e[s+1],i=e[s+2],n+=`${Ee(r)}L${Ee(o)}Q${Ee(i)}`;return n+=`${Ee(e[0])}`,n}function vv(e,n,t,r,o){const i=[],s=Kr(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],s()*t,s()*t);const f=b.Sub(c,a),p=b.Len(f),S=b.Div(f,p).mul(Math.min(p/4,r));i.push(b.Add(a,S),b.Add(c,S.neg()),c),a=c}return i}function HV(e,n,t){const r=Math.min(e,n)/2,o=Math.max(e,n)-r*2,s=(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(ks(d.center,r,d.startAngle+c/r)),c+=s;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 KV={s:50,m:70,l:100,xl:130},WV=.2;function ng(e,n,t,r){const o=Kr(t),i=FC(e,n),s=Math.max(Math.ceil(i/KV[r]),6,Math.ceil(i/Math.min(e,n))),a=i/s*WV,c=Math.max(e-a*2,1),l=Math.max(n-a*2,1),d=FC(c,l)/s,f=(e-c)/2,p=(n-l)/2,S=HV(c,l,s).map(P=>P.addXY(f,p)),m=e<20?0:a*.3,w=n<20?0:a*.3,y=S.slice(0);for(let P=0;P<Math.floor(s/2);P++)y[P]=b.AddXY(y[P],o()*m,o()*w),y[s-P-1]=b.AddXY(y[s-P-1],o()*m,o()*w);const v=[];for(let P=0;P<y.length;P++){const E=P===y.length-1?0:P+1,C=y[P],I=y[E],_=S[P],k=S[E],$=b.Dist(_,k),T=d-$,N=b.Dist(C,I)/$,j=(Math.max(f,p)+T)*N,O=b.Lrp(_,k,.5).add(b.Sub(k,_).uni().per().mul(j));O.x<0?O.x=0:O.x>e&&(O.x=e),O.y<0?O.y=0:O.y>n&&(O.y=n);const R=j0(C,I,O),Y=b.Dist(R||b.Average([C,I]),C);v.push({leftPoint:C,rightPoint:I,arcPoint:O,center:R,radius:Y})}return v}function GV(e,n,t,r){const o=[],i=ng(e,n,t,r);for(const{center:s,radius:a,leftPoint:c,rightPoint:l}of i)o.push(...Uz(c,l,s,a,10));return o}function xv(e,n,t,r){const o=ng(e,n,t,r);let i=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:s,rightPoint:a,radius:c,center:l}of o){if(l===null){i+=` L${a.toFixed()}`;continue}const u=b.Clockwise(s,a,l)?"0":"1";i+=` A${F(c)},${F(c)} 0 ${u},1 ${a.toFixed()}`}return i+=" Z",i}const VV={s:.5,m:.7,l:.9,xl:1.6};function YV(e,n,t,r){const o=Kr(t),i=VV[r],s=ng(e,n,t,r),l=s.reduce((p,S)=>p+b.Dist2(S.leftPoint,S.rightPoint),0)/s.length>(i*15)**2?p=>p.addXY(o()*i*2,o()*i*2):p=>p;let u=`M${s[0].leftPoint.toFixed()}`,d=l(s[0].leftPoint),f=`M${d.toFixed()}`;for(const{leftPoint:p,center:S,rightPoint:m,radius:w,arcPoint:y}of s){if(S===null){u+=` L${m.toFixed()}`;const _=l(m);f+=` L${_.toFixed()}`,d=_;continue}const v=b.Clockwise(p,m,S)?"0":"1";u+=` A${F(w)},${F(w)} 0 ${v},1 ${m.toFixed()}`;const P=l(m),E=l(y),C=j0(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 wv(e,n){switch(e.geo){case"x-box":return XV(e.w,e.h,n,e.dash);case"check-box":return qV(e.w,e.h);default:return}}function XV(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 i=a=>Math.max(0,Math.min(e,a)),s=a=>Math.max(0,Math.min(n,a));return[[new b(i(t*o),s(t*o)),new b(i(e-t*o),s(n-t*o))],[new b(i(t*o),s(n-t*o)),new b(i(e-t*o),s(t*o))]]}function qV(e,n){const t=Math.min(e,n)*.82,r=(e-t)/2,o=(n-t)/2,i=a=>Math.max(0,Math.min(e,a)),s=a=>Math.max(0,Math.min(n,a));return[[new b(i(r+t*.25),s(o+t*.52)),new b(i(r+t*.45),s(o+t*.82))],[new b(i(r+t*.45),s(o+t*.82)),new b(i(r+t*.82),s(o+t*.22))]]}function NC({shape:e}){const n=z(),t=Ir(),{id:r,props:o}=e,{w:i,color:s,fill:a,dash:c,growY:l,size:u}=o,d=Mt[u],f=o.h+l;switch(o.geo){case"cloud":if(c==="solid"){const p=xv(i,f,r,u);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:s,fill:a}),h.jsx("path",{d:p,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}else if(c==="draw"){const p=YV(i,f,r,u);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:s,fill:a}),h.jsx("path",{d:p,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}else{const p=xv(i,f,r,u),S=ng(i,f,r,u);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:s,fill:a}),h.jsx("g",{strokeWidth:d,stroke:t[s].solid,fill:"none",pointerEvents:"all",children:S.map(({leftPoint:m,rightPoint:w,center:y,radius:v},P)=>{const E=y?v*_i(_i(b.Angle(y,w))-_i(b.Angle(y,m))):b.Dist(m,w),{strokeDasharray:C,strokeDashoffset:I}=Qr(E,d,{style:c,start:"outset",end:"outset"});return h.jsx("path",{d:y?`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),S=p.getSvgPathData(!0);if(c==="dashed"||c==="dotted"){const m=p.length,{strokeDasharray:w,strokeDashoffset:y}=Qr(m<64?m*2:m,d,{style:c,snap:4,closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:S,color:s,fill:a}),h.jsx("path",{d:S,strokeWidth:d,fill:"none",stroke:t[s].solid,strokeDasharray:w,strokeDashoffset:y})]})}else{const w=n.getShapeGeometry(e).getSvgPathData(!0);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:w,color:s,fill:a}),h.jsx("path",{d:w,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}}case"oval":{const p=n.getShapeGeometry(e),S=p.getSvgPathData(!0);if(c==="dashed"||c==="dotted"){const m=p.getLength(),{strokeDasharray:w,strokeDashoffset:y}=Qr(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:S,color:s,fill:a}),h.jsx("path",{d:S,strokeWidth:d,fill:"none",stroke:t[s].solid,strokeDasharray:w,strokeDashoffset:y})]})}else return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:S,color:s,fill:a}),h.jsx("path",{d:S,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}case"heart":if(c==="dashed"||c==="dotted"){const p=F$(i,f),S=ew(i,f);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:p,color:s,fill:a}),S.map((m,w)=>{const{strokeDasharray:y,strokeDashoffset:v}=Qr(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[s].solid,strokeDasharray:y,strokeDashoffset:v,pointerEvents:"all"},`curve_${w}`)})]})}else{const p=NV(i,f,d,e.id);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:p,color:s,fill:a,theme:t}),h.jsx("path",{d:p,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}default:{const p=n.getShapeGeometry(e),S=p instanceof Br?p.children[0].vertices:p.vertices,m=wv(e.props,d);if(c==="solid"){let w="M"+S[0]+"L"+S.slice(1)+"Z";if(m)for(const[y,v]of m)w+=`M${y.x},${y.y}L${v.x},${v.y}`;return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:w,color:s,fill:a}),h.jsx("path",{d:w,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}else if(c==="dashed"||c==="dotted"){const w="M"+S[0]+"L"+S.slice(1)+"Z";return h.jsxs(h.Fragment,{children:[h.jsx(mt,{theme:t,d:w,fill:a,color:s}),h.jsxs("g",{strokeWidth:d,stroke:t[s].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(S.length)).map((y,v)=>{const P=b.ToFixed(S[v]),E=b.ToFixed(S[(v+1)%S.length]),C=b.Dist(P,E),{strokeDasharray:I,strokeDashoffset:_}=Qr(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(([y,v],P)=>{const E=b.Dist(y,v),{strokeDasharray:C,strokeDashoffset:I}=Qr(E,d,{style:c,start:"skip",end:"skip",snap:c==="dotted"?4:void 0});return h.jsx("path",{d:`M${y.x},${y.y}L${v.x},${v.y}`,stroke:t[s].solid,strokeWidth:d,fill:"none",strokeDasharray:C,strokeDashoffset:I},`line_fg_${P}`)})]})]})}else if(c==="draw"){const w=vv(r,S,d/3,d*2,2);let y=Sv(w);if(m)for(const[E,C]of m)y+=`M${E.toFixed()}L${C.toFixed()}`;const v=vv(r,S,0,d*2,1),P=Sv(v);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:P,fill:a,color:s,theme:t}),h.jsx("path",{d:y,stroke:t[s].solid,strokeWidth:d,fill:"none"})]})}}}}const hr=17*3;class Hh extends Tc{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:i}}=t;i.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:i.trimEnd()}}])});g(this,"onResize",(t,{handle:r,newPoint:o,scaleX:i,scaleY:s,initialShape:a})=>{let c=a.props.w*i,l=(a.props.h+a.props.growY)*s,u=0,d=0;if(t.props.text.trim()){let m=Math.max(Math.abs(c),hr),w=Math.max(Math.abs(l),hr);m<hr&&w===hr&&(m=hr),m===hr&&w<hr&&(w=hr);const y=Nd(this.editor,{...t,props:{...t.props,w:m,h:w}}),v=Math.max(Math.abs(c),y.w)*Math.sign(c),P=Math.max(Math.abs(l),y.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);i<0&&(f.x+=c),(r==="left"||r==="top_left"||r==="bottom_left")&&(f.x+=i<0?u:-u),s<0&&(f.y+=l),(r==="top"||r==="top_left"||r==="top_right")&&(f.y+=s<0?d:-d);const{x:p,y:S}=f.rot(t.rotation).add(o);return{x:p,y:S,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=Nd(this.editor,t).h;let i=null;if(o>r?i=o-r:t.props.growY&&(i=0),i!==null)return{...t,props:{...t.props,growY:i}}});g(this,"onBeforeUpdate",(t,r)=>{const o=t.props.text,i=r.props.text;if(o===i&&t.props.font===r.props.font&&t.props.size===r.props.size)return;if(o&&!i)return{...r,props:{...r.props,growY:0}};const s=t.props.w,a=t.props.h,c=Nd(this.editor,r),l=c.w,u=c.h;if(!o&&i&&i.length===1){let f=Math.max(s,l),p=Math.max(a,u);return t.props.w<hr&&t.props.h<hr&&(f=Math.max(f,hr),p=Math.max(p,hr),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),i=r/2,s=o/2,a=Mt[t.props.size],c=t.props.fill!=="none";let l;switch(t.props.geo){case"cloud":{l=new wt({points:GV(r,o,t.id,t.props.size),isFilled:c});break}case"triangle":{l=new wt({points:[new b(i,0),new b(r,o),new b(0,o)],isFilled:c});break}case"diamond":{l=new wt({points:[new b(i,0),new b(r,s),new b(i,o),new b(0,s)],isFilled:c});break}case"pentagon":{l=new wt({points:am(r,o,5),isFilled:c});break}case"hexagon":{l=new wt({points:am(r,o,6),isFilled:c});break}case"octagon":{l=new wt({points:am(r,o,8),isFilled:c});break}case"ellipse":{l=new AW({width:r,height:o,isFilled:c});break}case"oval":{l=new jW({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,A=r-Math.abs(_-k),N=o-Math.abs(T-$),j=r/2+k-(r/2-_),O=o/2+$-(o/2-T),R=1,Y=(r-j)/2,K=(o-O)/2,U=(r+A)/2,H=(o+N)/2,W=U*R/2,Z=H*R/2;l=new wt({points:Array.from(Array(5*2)).map((oe,be)=>{const Ae=-Ve+be*v;return new b(Y+(be%2?W:U)*Math.cos(Ae),K+(be%2?Z:H)*Math.sin(Ae))}),isFilled:c});break}case"rhombus":{const y=Math.min(r*.38,o*.38);l=new wt({points:[new b(y,0),new b(r,0),new b(r-y,o),new b(0,o)],isFilled:c});break}case"rhombus-2":{const y=Math.min(r*.38,o*.38);l=new wt({points:[new b(0,0),new b(r-y,0),new b(r,o),new b(y,o)],isFilled:c});break}case"trapezoid":{const y=Math.min(r*.38,o*.38);l=new wt({points:[new b(y,0),new b(r-y,0),new b(r,o),new b(0,o)],isFilled:c});break}case"arrow-right":{const y=Math.min(r,o)*.38,v=o*.16;l=new wt({points:[new b(0,v),new b(r-y,v),new b(r-y,0),new b(r,o/2),new b(r-y,o),new b(r-y,o-v),new b(0,o-v)],isFilled:c});break}case"arrow-left":{const y=Math.min(r,o)*.38,v=o*.16;l=new wt({points:[new b(y,0),new b(y,v),new b(r,v),new b(r,o-v),new b(y,o-v),new b(y,o),new b(0,o/2)],isFilled:c});break}case"arrow-up":{const y=r*.16,v=Math.min(r,o)*.38;l=new wt({points:[new b(r/2,0),new b(r,v),new b(r-y,v),new b(r-y,o),new b(y,o),new b(y,v),new b(0,v)],isFilled:c});break}case"arrow-down":{const y=r*.16,v=Math.min(r,o)*.38;l=new wt({points:[new b(y,0),new b(r-y,0),new b(r-y,o-v),new b(r,o-v),new b(r/2,o),new b(0,o-v),new b(y,o-v)],isFilled:c});break}case"check-box":case"x-box":case"rectangle":{l=new Xo({width:r,height:o,isFilled:c});break}case"heart":{const v=ew(r,o).reduce((P,E)=>(P.push(...E.vertices),P),[]);l=new wt({points:v,isFilled:c});break}default:nn(t.props.geo)}const u=Nd(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(Uo[t.props.size]*Kt.lineHeight+jr*2,o/2),S=Math.min(o,Math.max(u.h,Math.min(p,Math.max(1,r-8)))),m=wv(t.props,a),w=m?m.map(y=>new kc({points:y})):[];return new Br({children:[l,new Xo({x:t.props.align==="start"?0:t.props.align==="end"?r-f:(r-f)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?o-S:(o-S)/2,width:f,height:S,isFilled:!0,isLabel:!0}),...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:nn(t.props.geo)}}component(t){const{id:r,type:o,props:i}=t,{fill:s,font:a,align:c,verticalAlign:l,size:u,text:d}=i,f=t.id===this.editor.getOnlySelectedShapeId(),p=Ir(),m=this.editor.getEditingShapeId()!==null||t.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(zi,{id:r,children:h.jsx(NC,{shape:t})}),m&&h.jsx(Ds,{style:{overflow:"hidden",width:t.props.w,height:t.props.h+i.growY},children:h.jsx(tg,{id:r,type:o,font:a,fontSize:Uo[u],lineHeight:Kt.lineHeight,fill:s,align:c,verticalAlign:l,text:d,isSelected:f,labelColor:p[i.labelColor].solid,wrap:!0})}),t.props.url&&h.jsx(pc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{id:r,props:o}=t,{w:i,size:s}=o,a=o.h+o.growY,c=Mt[s],l=this.editor.getShapeGeometry(t);switch(o.geo){case"ellipse":return o.dash==="draw"?h.jsx("path",{d:UV(r,i,a,c)}):h.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return h.jsx("path",{d:F$(i,a)});case"oval":return h.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return h.jsx("path",{d:xv(i,a,r,s)});default:{const u=this.editor.getShapeGeometry(t),d=u instanceof Br?u.children[0].vertices:u.vertices;let f;if(o.dash==="draw"){const S=vv(r,d,0,c*2,1);f=Sv(S)}else f="M"+d[0]+"L"+d.slice(1)+"Z";const p=wv(t.props,c);if(p)for(const[S,m]of p)f+=`M${S.x},${S.y}L${m.x},${m.y}`;return h.jsx("path",{d:f})}}}toSvg(t,r){const{props:o}=t;r.addExportDef(qx(t.props.fill));let i;if(o.text){r.addExportDef(fc(t.props.font));const s=ei(r),a=this.editor.getShapeGeometry(t).bounds;i=h.jsx(eg,{fontSize:Uo[o.size],font:o.font,align:o.align,verticalAlign:o.verticalAlign,text:o.text,labelColor:s[o.labelColor].solid,bounds:a})}return h.jsxs(h.Fragment,{children:[h.jsx(NC,{shape:t}),i]})}getCanvasSvgDefs(){return[Zx()]}}g(Hh,"type","geo"),g(Hh,"props",B_),g(Hh,"migrations",U_);function Nd(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Kt,fontFamily:uo[n.props.font],fontSize:Uo[n.props.size],maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},i=e.textMeasure.measureText(t,{...Kt,fontFamily:uo[n.props.font],fontSize:Uo[n.props.size],minWidth:r.w,maxWidth:Math.max(0,Math.ceil(r.w+o[n.props.size]),Math.ceil(n.props.w-jr*2))});return{w:i.w+jr*2,h:i.h+jr*2}}function ZV(){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 i=()=>n(r&&o.matches);return o.addEventListener("change",i),()=>o.removeEventListener("change",i)},[]),G(bt.forceSrgb)||!e?"srgb":"p3"}const zC=.35,BC=.82;class Kh extends Nr{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>Bd(t));g(this,"hideRotateHandle",t=>Bd(t));g(this,"hideSelectionBoundsFg",t=>Bd(t));g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:i}=r,s=[];for(const a of t.props.segments)s.push({...a,points:a.points.map(({x:c,y:l,z:u})=>({x:o*c,y:i*l,z:u}))});return{props:{segments:s}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1}}getGeometry(t){const r=ca(t);if(Bd(t))return new Kx({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:i}=N$(t,r,!0),s=mv({strokeWidth:i,showAsComplete:!0});return Jp(o,s),new wt({points:Gx(o,s),isFilled:!0})}component(t){return h.jsx(zi,{id:t.id,style:{opacity:zC},children:h.jsx(zd,{strokeWidth:ca(t),shape:t})})}backgroundComponent(t){return h.jsx(zi,{id:t.id,style:{opacity:BC},children:h.jsx(zd,{strokeWidth:ca(t),shape:t})})}indicator(t){var d;const r=cu(),o=ca(t),i=lu(t.props.segments);let s=o;!r&&!t.props.isPen&&i.length===1&&(s+=Kr(t.id)()*(o/6));const a=t.props.isComplete||((d=Ft(t.props.segments))==null?void 0:d.type)==="straight",c=mv({strokeWidth:o,showAsComplete:a}),l=po(i,c);let u;return l.length<2?u=JV(i[0],s):u=Rs(l,!1),h.jsx("path",{d:u})}toSvg(t){return h.jsx(zd,{strokeWidth:ca(t),shape:t,opacity:zC})}toBackgroundSvg(t){return h.jsx(zd,{strokeWidth:ca(t),shape:t,opacity:BC})}}g(Kh,"type","highlight"),g(Kh,"props",W_),g(Kh,"migrations",G_);function QV(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 JV(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 N$(e,n,t){var c;const r=lu(e.props.segments),o=e.props.isComplete||((c=Ft(e.props.segments))==null?void 0:c.type)==="straight";let i=n;!t&&!e.props.isPen&&r.length===1&&(i+=Kr(e.id)()*(n/6));const s=mv({strokeWidth:i,showAsComplete:o});return{strokePoints:po(r,s),sw:i}}function eY(e,n,t){const{strokePoints:r,sw:o}=N$(e,n,t);return{solidStrokePath:r.length>1?Rs(r,!1):QV(e.props.segments[0].points[0]),sw:o}}function zd({strokeWidth:e,shape:n,opacity:t}){const r=Ir(),o=cu(),{solidStrokePath:i,sw:s}=eY(n,e,o),a=ZV(),c=r[n.props.color].highlight[a];return h.jsx("path",{d:i,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:c,strokeWidth:s,opacity:t})}function ca(e){return dc[e.props.size]*1.12}function Bd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function z$(){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 B$(){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 tY(e){const t=await(await fetch(e,{referrerPolicy:"strict-origin-when-cross-origin"})).blob();return za.blobToDataUrl(t)}class Wh extends Tc{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=vt(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},i=1/(o.bottomRight.x-o.topLeft.x)*t.props.w,s=1/(o.bottomRight.y-o.topLeft.y)*t.props.h,a=new b(o.topLeft.x*i,o.topLeft.y*s).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:i,h:s}};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&&Yn.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=B$(),[i,s]=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 S=a.props.src;if(!S)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 y=w.getContext("2d");y&&(y.drawImage(m,0,0),s(w.toDataURL()))},m.crossOrigin="anonymous",m.referrerPolicy="strict-origin-when-cross-origin",m.src=S,()=>{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.isIn("select.crop"),u=o&&(((f=a==null?void 0:a.props.mimeType)==null?void 0:f.includes("video"))||this.isAnimated(t)),d=UC(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?i:a.props.src})`},draggable:!1})}),h.jsxs(Ds,{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?i: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(pc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):h.jsxs(Ds,{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(z$,{})}),")","url"in t.props&&t.props.url&&h.jsx(pc,{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 tY(o)||"");const i=UC(t),s=t.props.crop;if(i.transform&&s){const{transform:a,width:c,height:l}=i,u=(s.bottomRight.x-s.topLeft.x)*c,d=(s.bottomRight.y-s.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(S=>`${S.x},${S.y}`).join(" ")})})}),h.jsx("g",{clipPath:`url(#${p})`,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(Wh,"type","image"),g(Wh,"props",V_),g(Wh,"migrations",Y_);function UC(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,i=-t.x*r,s=-t.y*o;return{transform:`translate(${i}px, ${s}px)`,width:r,height:o}}function U$(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function H$(e,n,t){const r=n.vertices,o=U$(t);return po(r,o)}function nY(e,n,t){const r=U$(t);return Gx(Jp(H$(e,n,t),r),r)}function rY(e,n,t){const r=nY(e,n,t);return z0(r)}function oY(e,n,t){if(e.props.dash==="draw"){const r=H$(e,n,t);return Rs(r)}return n.getSvgPathData()}function K$(e,n,t){let r=`M ${Ee(n[0])}L`,o=`M ${Ee(n[0])}L`;const i=t/3,s=t*2,a=Kr(e);let c=n[0],l,u=n[0],d;const f=n.length;for(let p=0,S=f-1;p<S;p++){l=n[p+1],d=b.AddXY(n[p+1],a()*i,a()*i);const m=b.Sub(l,c),w=b.Len(m),y=b.Div(m,w).mul(Math.min(w/4,s)),v=b.Add(c,y),P=b.Add(l,y.neg()),E=b.Sub(d,u),C=b.Len(E),I=b.Div(E,C).mul(Math.min(C/4,s)),_=b.Add(u,I),k=b.Add(d,I.neg());p===S-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 iY=new Cs;class Gh extends Nr{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:i}=r;return{props:{points:_u(t.props.points,(s,{id:a,index:c,x:l,y:u})=>({id:a,index:c,x:l*o,y:u*i}))}}});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]=Nl(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 vl(t)}getHandles(t){return iY.get(t.props,()=>{const r=vl(t),o=bv(t),i=o.map(s=>({...s,id:s.index,type:"vertex",canSnap:!0}));for(let s=0;s<o.length-1;s++){const a=Fl(o[s].index,o[s+1].index),l=r.segments[s].midPoint();i.push({id:a,type:"create",index:a,x:l.x,y:l.y,canSnap:!0})}return i.sort(en)})}component(t){return h.jsx(zi,{id:t.id,children:h.jsx(HC,{shape:t})})}indicator(t){const r=Mt[t.props.size],o=vl(t),{dash:i}=t.props;let s;if(t.props.spline==="line"){const a=o.points;if(i==="solid"||i==="dotted"||i==="dashed")s="M"+a[0]+"L"+a.slice(1);else{const[c]=K$(t.id,a,r);s=c}}else s=oY(t,o,r);return h.jsx("path",{d:s})}toSvg(t){return h.jsx(HC,{shape:t})}getHandleSnapGeometry(t){const r=bv(t);return{points:r,getSelfSnapPoints:o=>{const i=this.getHandles(t).filter(s=>s.type==="vertex").findIndex(s=>s.id===o.id);return r.filter((s,a)=>Math.abs(a-i)>1).map(b.From)},getSelfSnapOutline:o=>{const i=this.getHandles(t).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),s=vl(t).segments.filter((a,c)=>c!==i-1&&c!==i);return s.length?new Br({children:s}):null}}}}g(Gh,"type","line"),g(Gh,"props",X_),g(Gh,"migrations",q_);function bv(e){return Object.values(e.props.points).sort(en)}function vl(e){const n=bv(e).map(b.From);switch(e.props.spline){case"cubic":return new MW({points:n});case"line":return new kc({points:n})}}function HC({shape:e}){const n=Ir(),t=vl(e),r=Mt[e.props.size],{dash:o,color:i}=e.props;if(e.props.spline==="line"){if(o==="solid"){const s=t.points,a="M"+s[0]+"L"+s.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:a,fill:"none",color:i,theme:n}),h.jsx("path",{d:a,stroke:n[i].solid,strokeWidth:r,fill:"none"})]})}if(o==="dashed"||o==="dotted"){const s=t.points,a="M"+s[0]+"L"+s.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:a,fill:"none",color:i,theme:n}),h.jsx("g",{stroke:n[i].solid,strokeWidth:r,children:t.segments.map((c,l)=>{const{strokeDasharray:u,strokeDashoffset:d}=Qr(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 s=t.points,[a,c]=K$(e.id,s,r);return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:a,fill:"none",color:i,theme:n}),h.jsx("path",{d:c,stroke:n[i].solid,strokeWidth:r,fill:"none"})]})}}if(e.props.spline==="cubic"){const s=t.getSvgPathData();if(o==="solid")return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:s,fill:"none",color:i,theme:n}),h.jsx("path",{strokeWidth:r,stroke:n[i].solid,fill:"none",d:s})]});if(o==="dashed"||o==="dotted")return h.jsxs(h.Fragment,{children:[h.jsx(mt,{d:s,fill:"none",color:i,theme:n}),h.jsx("g",{stroke:n[i].solid,strokeWidth:r,children:t.segments.map((a,c)=>{const{strokeDasharray:l,strokeDashoffset:u}=Qr(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:s,fill:"none",color:i,theme:n}),h.jsx("path",{d:rY(e,t,r),strokeWidth:1,stroke:n[i].solid,fill:n[i].solid})]})}}const W$=x.createContext(null);function sY({assetUrls:e,children:n}){return x.useEffect(()=>{for(const t of Object.values(e.icons)){const r=new Image;r.referrerPolicy="strict-origin-when-cross-origin",r.src=t,r.decode()}for(const t of Object.values(e.embedIcons)){const r=new Image;r.referrerPolicy="strict-origin-when-cross-origin",r.src=t,r.decode()}},[e]),h.jsx(W$.Provider,{value:e,children:n})}function tw(){const e=x.useContext(W$);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const Pv={"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 editor link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},aY=new Set(["ar","fa","he","ur","ku"]),la={locale:"en",label:"English",messages:Pv,dir:"ltr"};async function cY(e,n){if(!(await fetch(n.translations.en)).ok)return console.warn("No main translations found."),la;if(e==="en")return la;const r=Bl.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),la;const i=await(await fetch(n.translations[r.locale])).json();if(!i)return console.warn(`No messages found for locale ${e}`),la;const s=[];for(const a in la.messages)i[a]||s.push(a);return s.length>0,{locale:e,label:r.label,dir:aY.has(r.locale)?"rtl":"ltr",messages:{...la.messages,...i}}}const G$=x.createContext(null);function V$(){const e=x.useContext(G$);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const lY=ir(function({overrides:n,children:t}){const o=z().user.getLocale(),i=tw(),[s,a]=x.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...Pv,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:Pv});return x.useEffect(()=>{let c=!1;async function l(){const u=await cY(o,i);u&&!c&&(n&&n[o]?a({...u,messages:{...u.messages,...n[o]}}):a(u))}return l(),()=>{c=!0}},[i,o,n]),h.jsx(G$.Provider,{value:s,children:t})});function Me(){const e=V$();return x.useCallback(function(t){return e.messages[t]??t},[e])}class Vh extends Nr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"hideResizeHandles",()=>!0);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"onBeforeCreate",t=>KC(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 KC(this.editor,r)});g(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:i}}=t;i.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:i.trimEnd()}}])})}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:""}}getGeometry(t){const r=Ud(t),{labelHeight:o,labelWidth:i}=Y$(this.editor,t);return new Br({children:[new Xo({width:$e,height:r,isFilled:!0}),new Xo({x:t.props.align==="start"?0:t.props.align==="end"?$e-i:($e-i)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?r-o:(r-o)/2,width:i,height:o,isFilled:!0,isLabel:!0})]})}getHandles(t){const r=this.editor.getZoomLevel(),o=RG/r,i=Ud(t),s=this.editor.getInstanceState().isCoarsePointer;return r<.25||s?[]:r<.5?[{id:"bottom",index:"a3",type:"clone",x:$e/2,y:i+o}]:[{id:"top",index:"a1",type:"clone",x:$e/2,y:-o},{id:"right",index:"a2",type:"clone",x:$e+o,y:i/2},{id:"bottom",index:"a3",type:"clone",x:$e/2,y:i+o},{id:"left",index:"a4",type:"clone",x:-o,y:i/2}]}component(t){const{id:r,type:o,props:{color:i,font:s,size:a,align:c,text:l,verticalAlign:u,fontSizeAdjustment:d}}=t,f=hY(r),p=Ir(),S=Ud(t),m=G("shape rotation",()=>{var v;return((v=this.editor.getShapePageTransform(r))==null?void 0:v.rotation())??0},[this.editor]),w=cu(),y=t.id===this.editor.getOnlySelectedShapeId();return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:r,className:"tl-note__container",style:{width:$e,height:S,backgroundColor:p[i].note.fill,borderBottom:w?"3px solid rgb(15, 23, 31, .2)":"none",boxShadow:w?"none":fY(t.id,m)},children:h.jsx(tg,{id:r,type:o,font:s,fontSize:d||Uo[a],lineHeight:Kt.lineHeight,align:c,verticalAlign:u,text:l,isNote:!0,isSelected:y,labelColor:p[i].note.text,wrap:!0,onKeyDown:f})}),"url"in t.props&&t.props.url&&h.jsx(pc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return h.jsx("rect",{rx:"1",width:F($e),height:F(Ud(t))})}toSvg(t,r){r.addExportDef(fc(t.props.font)),t.props.text&&r.addExportDef(fc(t.props.font));const o=ei({isDarkMode:r.isDarkMode}),i=this.editor.getShapeGeometry(t).bounds;return h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:5,y:5,rx:1,width:$e-10,height:i.h,fill:"rgba(0,0,0,.1)"}),h.jsx("rect",{rx:1,width:$e,height:i.h,fill:o[t.props.color].note.fill}),h.jsx(eg,{fontSize:t.props.fontSizeAdjustment||Uo[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:i,stroke:!1})]})}}g(Vh,"type","note"),g(Vh,"props",Z_),g(Vh,"migrations",Q_);function KC(e,n){const{labelHeight:t,fontSizeAdjustment:r}=Y$(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 uY(e,n){const t=n.props.text;if(!t)return{labelHeight:Uo[n.props.size]*Kt.lineHeight+jr*2,labelWidth:100,fontSizeAdjustment:0};const r=Uo[n.props.size];let o=0,i=0,s=$e,a=$e;const c=1;do{o=Math.min(r,r-i);const l=e.textMeasure.measureText(t,{...Kt,fontFamily:uo[n.props.font],fontSize:o,maxWidth:$e-jr*2-c,disableOverflowWrapBreaking:!0});if(s=l.h+jr*2,a=l.w+jr*2,o<=14){const u=e.textMeasure.measureText(t,{...Kt,fontFamily:uo[n.props.font],fontSize:o,maxWidth:$e-jr*2-c});s=u.h+jr*2,a=u.w+jr*2;break}if(l.scrollWidth.toFixed(0)===l.w.toFixed(0))break}while(i++<50);return{labelHeight:s,labelWidth:a,fontSizeAdjustment:o}}const dY=new Cs;function Y$(e,n){return dY.get(n,()=>uY(e,n))}function hY(e){const n=z(),t=V$();return x.useCallback(r=>{const o=n.getShape(e);if(!o)return;const i=r.key==="Tab",s=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(i||s){r.preventDefault();const a=n.getShapePageTransform(e),c=a.rotation(),l=!!(t.dir==="rtl"||v$(o.props.text)),u=$e+n.options.adjacentShapeMargin+(s&&!r.shiftKey?o.props.growY:0),d=new b(i?r.shiftKey!=l?-1:1:0,s?r.shiftKey?-1:1:0).mul(u).add(Xx).rot(c).add(a.point()),f=_$(n,o,d,c);f&&(n.mark("editing adjacent shape"),cp(n,f,!0))}},[e,n,t.dir])}function Ud(e){return $e+e.props.growY}function fY(e,n){const t=Kr(e),r=Math.abs(t())+.5,o=Math.cos(n);return`0px ${5-r}px 5px -5px rgba(15, 23, 31, .6),
157
- 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)}),
158
- 0px 48px 10px -10px inset rgba(15, 23, 44, ${((.022+t()*.005)*((1+o)/2)).toFixed(2)})`}function pY(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const i=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),s=new b(0,0);t<0&&(s.x=-(n.width*i)),r<0&&(s.y=-(n.height*i));const{x:a,y:c}=b.Add(o,s.rot(e.rotation));return{x:a,y:c,props:{scale:i*e.props.scale}}}const gY=new Cs;class Yh extends Nr{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"isAspectRatioLocked",()=>!0);g(this,"onResize",(t,r)=>{const{newPoint:o,initialBounds:i,initialShape:s,scaleX:a,handle:c}=r;if(r.mode==="scale_shape"||c!=="right"&&c!=="left")return{id:t.id,type:t.type,...pY(t,r)};{const l=Math.max(1,Math.abs(i.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/s.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:i}}=t,s=t.props.text.trimEnd();s.length===0?this.editor.deleteShapes([t.id]):s!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:i.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,i=t.props.text!==r.props.text;if(!o&&!i)return;const s=this.getMinDimensions(t),a=WC(this.editor,r.props),c=s.width*t.props.scale,l=s.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,i?0:(d-l)/2);break}case"end":{f=new b(u-c,i?0:(d-l)/2);break}default:{if(i)break;f=new b(0,(d-l)/2);break}}if(f){f.rot(r.rotation);const{x:p,y:S}=r;return{...r,x:p-f.x,y:S-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 gY.get(t.props,r=>WC(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:i}=this.getMinDimensions(t);return new Xo({width:o*r,height:i*r,isFilled:!0,isLabel:!0})}component(t){const{id:r,props:{font:o,size:i,text:s,color:a,scale:c,textAlign:l}}=t,{width:u,height:d}=this.getMinDimensions(t),f=t.id===this.editor.getOnlySelectedShapeId(),p=Ir(),S=mY(r);return h.jsx(tg,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:dc[i],lineHeight:Kt.lineHeight,align:l,verticalAlign:"middle",text:s,labelColor:p[a].solid,isSelected:f,textWidth:u,textHeight:d,style:{transform:`scale(${c})`,transformOrigin:"top left"},wrap:!0,onKeyDown:S})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=z();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(fc(t.props.font)),t.props.text&&r.addExportDef(fc(t.props.font));const o=this.editor.getShapeGeometry(t).bounds,i=o.width/(t.props.scale??1),s=o.height/(t.props.scale??1),a=ei(r);return h.jsx(eg,{fontSize:dc[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,i,s),padding:0})}}g(Yh,"type","text"),g(Yh,"props",J_),g(Yh,"migrations",ek);function WC(e,n){const{font:t,text:r,autoSize:o,size:i,w:s}=n,a=o?16:Math.max(16,s),c=dc[i],l=o?null:Math.floor(Math.max(a,s)),u=e.textMeasure.measureText(r,{...Kt,fontFamily:uo[t],fontSize:c,maxWidth:l});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(c,u.h)}}function mY(e){const n=z();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?hc.unindent(t.currentTarget):hc.indent(t.currentTarget);break}}},[n,e])}class Xh extends Tc{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,i=t.props.assetId?r.getAsset(t.props.assetId):null,{time:s,playing:a}=t.props,c=Qp(t.id),l=B$(),u=x.useRef(null),d=x.useCallback(y=>{const v=y.currentTarget;v&&r.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:v.currentTime}}])},[t.id,r]),f=x.useCallback(y=>{const v=y.currentTarget;v&&r.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:v.currentTime}}])},[t.id,r]),p=x.useCallback(y=>{const v=y.currentTarget;v&&c&&r.updateShapes([{type:"video",id:t.id,props:{time:v.currentTime}}])},[c,t.id,r]),[S,m]=x.useState(!1),w=x.useCallback(y=>{const v=y.currentTarget;v&&(s!==v.currentTime&&(v.currentTime=s),a||v.pause(),m(!0))},[a,s]);return x.useEffect(()=>{const y=u.current;y&&(S&&!c&&s!==y.currentTime&&(y.currentTime=s),c&&document.activeElement!==y&&y.focus())},[c,S,s]),x.useEffect(()=>{if(l){const y=u.current;if(!y)return;y.pause(),y.currentTime=0}},[u,l]),h.jsxs(h.Fragment,{children:[h.jsx(Ds,{id:t.id,style:{color:"var(--color-text-3)",backgroundColor:i?"transparent":"var(--color-low)",border:i?"none":"1px solid var(--color-low-border)"},children:h.jsx("div",{className:"tl-counter-scaled",children:h.jsx("div",{className:"tl-video-container",children:i!=null&&i.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:!S,children:h.jsx("source",{src:i.props.src})}):h.jsx(z$,{})})})}),"url"in t.props&&t.props.url&&h.jsx(pc,{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:yY(t.id),width:t.props.w,height:t.props.h})}}g(Xh,"type","video"),g(Xh,"props",tk),g(Xh,"migrations",nk);function yY(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 X$=[Yh,Nh,zh,Hh,Vh,Gh,Uh,Fh,Kh,Bh,Wh,Xh];function SY(e){return[e.sideEffects.registerAfterChangeHandler("instance_page_state",(n,t)=>{if(n.croppingShapeId!==t.croppingShapeId){const r=e.isIn("select.crop");!n.croppingShapeId&&t.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):n.croppingShapeId&&!t.croppingShapeId&&r&&e.setCurrentTool("select.idle")}n.editingShapeId!==t.editingShapeId&&(!n.editingShapeId&&t.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):n.editingShapeId&&!t.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))})]}class q$ 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(i=>{if(this.editor.isShapeOrAncestorLocked(i))return!0;if(this.editor.isShapeOfType(i,"group")||this.editor.isShapeOfType(i,"frame")){const s=this.editor.getPointInShapeSpace(i,r);return this.editor.getShapeGeometry(i).bounds.containsPoint(s)}return!1}).map(i=>i.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(),i=t.getZoomLevel(),s=t.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:c}}=t;this.pushPointToScribble();const l=new Set(o),u=this.editor.options.hitTestMargin/i;for(const d of s){if(t.isShapeOfType(d,"group"))continue;const f=t.getShapeMask(d.id);if(f&&!Jn(a,f))continue;const p=t.getShapeGeometry(d),S=t.getShapePageTransform(d);if(!p||!S)continue;const m=S.clone().invert(),w=m.applyToPoint(c),y=m.applyToPoint(a),{bounds:v}=p;v.minX-u>Math.max(w.x,y.x)||v.minY-u>Math.max(w.y,y.y)||v.maxX+u<Math.min(w.x,y.x)||v.maxY+u<Math.min(w.y,y.y)||p.hitTestLineSegment(w,y,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(q$,"id","erasing");var Oy;let vY=(Oy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Oy,"id","idle"),Oy);var Dy;let xY=(Dy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{const t=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:o}}=this.editor,i=new Set,s=i.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:this.editor.options.hitTestMargin/t})){const u=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(u,"frame")&&i.size>s)break;i.add(u.id)}}this.editor.setErasingShapes([...i])});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(Dy,"id","pointing"),Dy);class qh extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(qh,"id","eraser"),g(qh,"initial","idle"),g(qh,"children",()=>[vY,xY,q$]);class Z$ 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:i}=r.inputs,s=b.Sub(o,i).div(r.getZoomLevel());s.len2()!==0&&r.setCamera(t.clone().add(s))}complete(){const{editor:t}=this,{pointerVelocity:r}=t.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r}),this.parent.transition("idle")}}g(Z$,"id","dragging");var Ry;let wY=(Ry=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(Ry,"id","idle"),Ry);var Ly;let bY=(Ly=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(Ly,"id","pointing"),Ly);class Zh 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:on.easeOutQuint}})}});g(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:on.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:on.easeOutQuint}}):this.editor.resetZoom(o,{animation:{duration:320,easing:on.easeOutQuint}})}})}}g(Zh,"id","hand"),g(Zh,"initial","idle"),g(Zh,"children",()=>[wY,bY,Z$]);var Fy;let PY=(Fy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},g(Fy,"id","idle"),Fy);class Q$ 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(Q$,"id","lasering");class Qh extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(Qh,"id","laser"),g(Qh,"initial","idle"),g(Qh,"children",()=>[PY,Q$]);class J$ 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(i=>this.editor.isShapeOfType(i,"group")||this.editor.isShapeOrAncestorLocked(i)).map(i=>i.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",()=>{Wx(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:i,currentPagePoint:s,shiftKey:a,ctrlKey:c}}=t,l=new Set(a?this.initialSelectedShapeIds:[]),u=o?!c:c,d=J.FromPoints([i,s]),{corners:f}=d;let p,S,m,w,y,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,s,E,l,f);continue e}if(u||t.isShapeOfType(m,"frame"))continue e;if(d.collides(w)){if(y=t.getShapePageTransform(m),!y)continue e;v=y.clone().invert().applyToPoints(f);const $=t.getShapeGeometry(m);t:for(let T=0;T<4;T++)if(p=v[T],S=v[(T+1)%4],$.hitTestLineSegment(p,S,0)){this.handleHit(m,s,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,i,s){if(t.parentId===o){i.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),c=this.editor.getShapeMask(a.id);c&&!G2(c,s)&&!Jn(r,c)||i.add(a.id)}}g(J$,"id","brushing");const gc={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 eM 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=gc[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(eM,"id","pointing_resize_handle");const fr=8;class nw 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=gc[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 i=t.props,s=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),c=s.clone().sub(a).rot(-t.rotation),l=i.crop??this.getDefaultCrop(),u=vt(l),d=new b(t.x,t.y),f=new b(0,0),p=1/(l.bottomRight.x-l.topLeft.x)*i.w,S=1/(l.bottomRight.y-l.topLeft.y)*i.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(S<fr)break;m=!0,u.topLeft.y=u.topLeft.y+c.y/S,S*(u.bottomRight.y-u.topLeft.y)<fr?(u.topLeft.y=u.bottomRight.y-fr/S,f.y=(u.topLeft.y-l.topLeft.y)*S):u.topLeft.y<=0?(u.topLeft.y=0,f.y=(u.topLeft.y-l.topLeft.y)*S):f.y=c.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(S<fr)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+c.y/S),S*(u.bottomRight.y-u.topLeft.y)<fr&&(u.bottomRight.y=u.topLeft.y+fr/S);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<fr)break;m=!0,u.topLeft.x=u.topLeft.x+c.x/p,p*(u.bottomRight.x-u.topLeft.x)<fr?(u.topLeft.x=u.bottomRight.x-fr/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<fr)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+c.x/p),p*(u.bottomRight.x-u.topLeft.x)<fr&&(u.bottomRight.x=u.topLeft.x+fr/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)*S}};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.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),i=this.editor.getSelectionRotatedPageBounds(),s=b.RotWith(i.getHandlePoint(this.info.handle),i.point,t),a=b.Sub(r,s);return{shape:o,cursorHandleOffset:a}}}g(nw,"id","cropping");function rw(e,n=!1){const t=e.getZoomLevel(),{inputs:{currentPagePoint:r}}=e;return e.getShapeAtPoint(r,{hitInside:!1,hitLabels:n,margin:e.options.hitTestMargin/t,renderingOnly:!0})??e.getSelectedShapeAtPoint(r)}function tM(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 i=1/(r.bottomRight.x-r.topLeft.x)*n.props.w,s=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=vt(r);return l.topLeft.x=Math.min(1-c,Math.max(0,l.topLeft.x-t.x/i)),l.topLeft.y=Math.min(1-a,Math.max(0,l.topLeft.y-t.y/s)),l.bottomRight.x=l.topLeft.x+c,l.bottomRight.y=l.topLeft.y+a,{id:n.id,type:n.type,props:{crop:l}}}var Ny;let CY=(Ny=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const t=this.editor.getOnlySelectedShape();t&&this.editor.setCroppingShape(t.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});g(this,"onPointerDown",t=>{var r;if(!this.editor.getIsMenuOpen()){if(t.ctrlKey){this.cancel(),this.editor.root.handleEvent(t);return}switch(t.target){case"canvas":{const o=rw(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...t,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(t);break}case"shape":{if(t.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",t);return}else(r=this.editor.getShapeUtil(t.shape))!=null&&r.canCrop(t.shape)?(this.editor.setCroppingShape(t.shape.id),this.editor.setSelectedShapes([t.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",t)):(this.cancel(),this.editor.root.handleEvent(t));break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...t,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...t,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}});g(this,"onDoubleClick",t=>{var s;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 i=this.editor.getShapeUtil(o);if(i){if(t.target==="selection"){(s=i.onDoubleClickEdge)==null||s.call(i,o);return}this.cancel(),this.editor.root.handleEvent(t)}});g(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});g(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});g(this,"onKeyUp",t=>{switch(t.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),i=new b(0,0);if(r.has("ArrowLeft")&&(i.x+=1),r.has("ArrowRight")&&(i.x-=1),r.has("ArrowUp")&&(i.y+=1),r.has("ArrowDown")&&(i.y-=1),i.equals(new b(0,0)))return;o&&i.mul(10);const s=this.editor.getShape(this.editor.getCroppingShapeId());if(!s)return;const a=tM(this.editor,s,i);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},g(Ny,"id","idle"),Ny);class nM 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(nM,"id","pointing_crop");class ow 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=gc[this.info.handle];this.editor.setCursor({type:o,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});g(this,"onLongPress",()=>{this.startCropping()});g(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}g(ow,"id","pointing_crop_handle");class rM 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,i=o.clone().sub(r),s=tM(this.editor,t,i);s&&this.editor.updateShapes([s])}}g(rM,"id","translating_crop");class Jh extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onEnter",()=>{this.didCancel=!1,this.markId=this.editor.history.mark()});g(this,"didCancel",!1);g(this,"onExit",()=>{this.didCancel?this.editor.bailToMark(this.markId):this.editor.history.squashToMark(this.markId)});g(this,"onCancel",()=>{this.didCancel=!0})}}g(Jh,"id","crop"),g(Jh,"initial","idle"),g(Jh,"children",()=>[CY,rM,nM,ow,nw]);class oM 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:i}=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=vt(i),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[i.index]:{id:i.index,index:i.index,x:i.x,y:i.y}}}});const l=this.editor.getShapeHandles(r).find(u=>u.index===i.index);this.initialHandle=vt(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 s=this.editor.getShapeHandles(r).sort(en),a=s.findIndex(c=>c.id===t.handle.id);this.initialAdjacentHandle=null;for(let c=a+1;c<s.length;c++){const l=s[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==t.handle.id){this.initialAdjacentHandle=l;break}}if(!this.initialAdjacentHandle)for(let c=s.length-1;c>=0;c--){const l=s[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=En(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=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),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:i,initialPageRotation:s,initialAdjacentHandle:a}=this,c=this.editor.getHintingShapeIds(),l=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:d,shiftKey:f,ctrlKey:p,altKey:S,pointerVelocity:m}}=t,w=this.info.shape,y=t.getShape(r);if(!y)return;const v=t.getShapeUtil(y);let P=d.clone().sub(o).rot(-s).add(i);if(f&&a&&i.id!=="middle"){const k=b.Angle(a,P),T=Tf(k,24)-k;P=b.RotWith(P,a,T)}t.snaps.clearIndicators();let E={...i,x:P.x,y:P.y};if(i.canSnap&&(l?!p:p)){if(!t.getShapePageTransform(y.id))throw Error("Expected a page transform");const $=u.handles.snapHandle({currentShapeId:r,handle:E});$&&($.nudge.rot(-t.getShapeParentTransform(y).rotation()),P.add($.nudge),E={...i,x:P.x,y:P.y})}const C=(_=v.onHandleDrag)==null?void 0:_.call(v,y,{handle:E,isPrecise:this.isPrecise||S,initial:w}),I={id:y.id,type:y.type,...C};if(i.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const k=En(t,y)[i.id];k?c[0]!==k.toId&&(t.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=m.len()<.5||S,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(oM,"id","dragging_handle");function iM(e){return e.isLabel?[e]:e instanceof Br?e.children.filter(n=>n.isLabel):[]}class sM 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,Qa(this.editor),this.editor.select(t)});g(this,"onExit",()=>{var i;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null);const r=this.editor.getShape(t),o=this.editor.getShapeUtil(r);(i=o.onEditEnd)==null||i.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":{Qa(this.editor);return}}});g(this,"onPointerDown",t=>{switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=rw(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 i=this.editor.getShapeUtil(r).getGeometry(r),s=iM(i),a=s.length===1?s[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),Qa(this.editor)});g(this,"onComplete",t=>{this.parent.transition("idle",t)});g(this,"onCancel",t=>{this.parent.transition("idle",t)})}}g(sM,"id","editing_shape");function GC(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function dp(e){const n=e.getSelectedShapeIds(),{shiftKey:t,altKey:r,currentPagePoint:o}=e.inputs,i=e.getShapeAtPoint(o,{hitInside:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:s=>!s.isLocked});if(i){const s=e.getOutermostSelectableShape(i);if(t&&!r)e.cancelDoubleClick(),n.includes(s.id)?(e.mark("deselecting shape"),e.deselect(s)):(e.mark("shift selecting shape"),e.setSelectedShapes([...n,s.id]));else{let a;s===i||s.id===e.getFocusedGroupId()||n.includes(s.id)?a=i:a=s,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 s=e.getFocusedGroupId();if(gr(s)){const a=e.getShape(s);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const IY=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var zy;let EY=(zy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Qa(this.editor),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{Qa(this.editor)});g(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&GC(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=rw(this.editor);if(o&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}const i=this.editor.getSelectedShapeIds(),s=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((i.length>1||s&&!this.editor.getShapeUtil(s).hideSelectionBoundsBg(s))&&VC(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{const{shape:o}=t;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",t);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",t);break}this.parent.transition("pointing_shape",t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",t):this.parent.transition("pointing_handle",t);break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",t);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("crop.pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",t)}}break}}});g(this,"onDoubleClick",t=>{var r,o,i,s;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:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(c){if(this.editor.isShapeOfType(c,"group")){dp(this.editor);return}else{const u=this.editor.getShape(c.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(l&&u.id===l)){dp(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((i=t.shape)==null?void 0:i.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=(s=l.onDoubleClickHandle)==null?void 0:s.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:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...t,shape:o,target:"shape"});return}const i=this.editor.getSelectedShapeIds(),s=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((i.length>1||s&&!this.editor.getShapeUtil(s).hideSelectionBoundsBg(s))&&VC(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=t,i=this.editor.getOutermostSelectableShape(o,s=>!r.includes(s.id));r.includes(i.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([i.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(bt.editOnType.get()&&!IY.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(i=>this.editor.isShapeOfType(i,"group"))){this.editor.setSelectedShapes(r.flatMap(i=>this.editor.getSortedChildIdsForParent(i.id)));return}const o=this.editor.getOnlySelectedShape();if(o&&this.shouldStartEditingShape(o)){this.startEditingShape(o,{...t,target:"shape",shape:o},!0);return}GC(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"),cp(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&&Jn(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:i}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:o,y:i,props:{text:"",autoSize:!0}}]);const s=this.editor.getShape(r);if(!s)return;const a=this.editor.getShapeUtil(s);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(s)||(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"),i=new b(0,0);if(r.has("ArrowLeft")&&(i.x-=1),r.has("ArrowRight")&&(i.x+=1),r.has("ArrowUp")&&(i.y-=1),r.has("ArrowDown")&&(i.y+=1),i.equals(new b(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:s}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?s*TY:s:o?_Y:kY,c=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(c,i.mul(a)),We(this.editor,c)}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},g(zy,"id","idle"),zy);const _Y=10,kY=1,TY=5;function VC(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?Jn(n,t.corners.map(o=>b.RotWith(o,t.point,r))):t.containsPoint(n)}class aM 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 i=this.editor.getShapeGeometry(r).children[1];if(!i)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:s}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,s);this._labelDragOffset=b.Sub(i.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=ro(this.editor,r),i=this.editor.getShapeGeometry(r),s=i.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),c=s.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}=i.children[0];l=hS(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(aM,"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",()=>{dp(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 lM 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=En(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,i=YC(o,t,r,!1);if(i){cp(o,i,!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 i=YC(t,r,o,!0);if(i){const s=t.getPointInParentSpace(i,t.inputs.originPagePoint).sub(b.Rot(Xx,i.rotation));t.updateShape({...i,x:s.x,y:s.y}),t.setHoveredShape(i.id).select(i.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:t.getShape(i),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{cp(t,i,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}g(lM,"id","pointing_handle");function YC(e,n,t,r){const o=e.getShapePageTransform(n.id),i=o.point(),s=o.rotation(),c=I$(i,s,n.props.growY,0)[t.index];if(c)return _$(e,n,c,s,r)}class uM 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:gc[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(uM,"id","pointing_rotate_handle");class dM extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerUp",t=>{dp(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 i,s;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"),(s=(i=this.parent).onDoubleClick)==null||s.call(i,{...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(dM,"id","pointing_selection");class hM 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(),i=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:s,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===i||r.includes(l.id)||u||r.length>1&&(o!=null&&o.containsPoint(s))){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(),i=this.editor.getZoomLevel(),{inputs:{currentPagePoint:s,shiftKey:a}}=this.editor,c=this.editor.getShapeAtPoint(s,{margin:this.editor.options.hitTestMargin/i,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=iM(f),S=p.length===1?p[0]:void 0;if(S){const m=this.editor.getPointInShapeSpace(l,s);if(S.bounds.containsPoint(m,0)&&S.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(S=>S.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(hM,"id","pointing_shape");class fM 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",()=>{Wx(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,i=this.editor.getSelectionRotatedPageBounds(),s=b.RotWith(i.getHandlePoint(this.info.handle),i.point,r),a=b.Sub(o,s),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 S=this.editor.getShape(p);if(S&&(c.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const u=![...c.values()].some(d=>!ak(d.pageRotation,r)||d.isAspectRatioLocked);return{shapeSnapshots:c,selectionBounds:i,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:ie.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 i=this.editor.getShapeUtil(o),s=(a=i.onResizeStart)==null?void 0:a.call(i,o);s&&r.push(s)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:o})=>{var c;const i=this.editor.getShape(o.id),s=this.editor.getShapeUtil(o),a=(c=s.onResizeEnd)==null?void 0:c.call(s,o,i);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:i,selectionBounds:s,cursorHandleOffset:a,selectedShapeIds:c,selectionRotation:l,canShapesDeform:u}=this.snapshot;let d=r||!u;if(i.size===1){const k=[...i.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),S=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=XC(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,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:XC(m,l),isAspectRatioLocked:d,isResizingFromCenter:t});p.add(k)}const v=b.RotWith(t?s.center:s.getHandlePoint(w),s.point,l),P=b.Sub(p,v).rot(-l),E=b.Sub(S,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 i.keys()){const $=i.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=i.get(k).shape,A=this.editor.getShape(k);if(!(T&&A))continue;const N=A.x-T.x,j=A.y-T.y,O=new b(N,j).rot(-T.rotation);if(O.x!==0||O.y!==0)for(const R of $)this.editor.updateShape({id:R.id,type:R.type,x:R.x-O.x,y:R.y-O.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:i}){const s={...this.editor.getInstanceState().cursor};switch(t){case"top_left":case"bottom_right":{s.type="nwse-resize",r!==o&&(s.type="nesw-resize");break}case"top_right":case"bottom_left":{s.type="nesw-resize",r!==o&&(s.type="nwse-resize");break}}s.rotation=i,this.editor.setCursor(s)}}g(fM,"id","resizing");const ry=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function XC(e,n){n=n%Re;const t=Math.round(n/(ke/4)),r=ry.indexOf(e);return ry[(r+t)%ry.length]}const qC=Math.PI/180;class pM 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=X2({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Ch({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:gc[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});Ch({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:gc[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",()=>{Ch({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:i,currentPagePoint:s}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:c}=this.snapshot;if(!o)return c;const u=o.center.clone().rotWith(o.point,r).angle(s)-a;let d=c+u;if(i)d=Tf(d,24);else if(t&&(d=Math.round(d/qC)*qC,this.editor.getInstanceState().isCoarsePointer)){const f=Tf(d,4),p=dh(d,f);Math.abs(p)<Nz(5)&&(d=f)}return d-c}}g(pM,"id","rotating");class gM 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:i,originPagePoint:s,previousPagePoint:a,currentPagePoint:c}}=this.editor,{newlySelectedShapeIds:l,initialSelectedShapeIds:u}=this;t&&this.pushPointToScribble();const d=o;let f,p,S,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,s))))continue;const C=r.getShapePageTransform(f);if(!p||!C)continue;const I=C.clone().invert();S=I.applyToPoint(a),m=I.applyToPoint(c);const{bounds:_}=p;if(!(_.minX-w>Math.max(S.x,m.x)||_.minY-w>Math.max(S.y,m.y)||_.maxX+w<Math.min(S.x,m.x)||_.maxY+w<Math.min(S.y,m.y))&&p.hitTestLineSegment(S,m,w)){const k=this.editor.getOutermostSelectableShape(f),$=this.editor.getShapeMask(k.id);if($&&Dx(a,c,$)!==null&&!Jn(c,$))continue;l.add(k.id)}}const y=r.getSelectedShapeIds(),v=new Set(i?[...l,...u]:[...l]);(y.length!==v.size||y.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(gM,"id","scribble_brushing");const $Y=20,MY=100;class AY{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,i=>i.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,$Y,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(n,MY,t))}setDragTimer(n,t,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,n,r)}),this.droppingNodeTimer=null},t)}handleDrag(n,t,r){var 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:i}=this,s=i&&this.editor.getShape(i),a=o&&this.editor.getShape(o);s&&((u=(l=this.editor.getShapeUtil(s)).onDragShapesOut)==null||u.call(l,s,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 i=this.editor.findShapeAncestor(o,s=>s.type!=="group");i&&(t.has(i.id)||t.set(i.id,[]),t.get(i.id).push(o.id))}const r=[];for(const[o,i]of t){const s=this.editor.getShape(o);s&&b$(this.editor,s).length<i.length&&r.push(s.id)}this.editor.setHintingShapes(r)}dropShapes(n){var r,o;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,n),t){const i=this.editor.getShape(t);if(!i)return;(o=(r=this.editor.getShapeUtil(i)).onDropShapesOver)==null||o.call(r,i,n)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class mM 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 AY(this.editor));g(this,"onEnter",t=>{var i;const{isCreating:r=!1,onCreate:o=()=>{}}=t;if(!((i=this.editor.getSelectedShapeIds())!=null&&i.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=ZC(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),Wx(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 i=t.getShape(o.shape.id);if(!i)return null;const s=bn(i.parentId)?null:ie.Inverse(t.getShapePageTransform(i.parentId));o.parentTransform=s})})}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=ZC(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 i=this.editor.getShapeUtil(o),s=(a=i.onTranslateStart)==null?void 0:a.call(i,o);s&&r.push(s)}),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(s=>this.editor.getShapePageTransform(s.id).point())),i=b.Sub(o,this.selectionSnapshot.averagePagePoint);b.IsNaN(i)||this.editor.updateInstanceState({duplicateProps:{shapeIds:t.map(s=>s.id),offset:{x:i.x,y:i.y}}})}const r=[];t.forEach(o=>{var c;const i=this.editor.getShape(o.id),s=this.editor.getShapeUtil(o),a=(c=s.onTranslateEnd)==null?void 0:c.call(s,o,i);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:t}=this;this.dragAndDropManager.updateDroppingNode(t.movingShapes,this.updateParentTransforms),jY({editor:this.editor,snapshot:t});const{movingShapes:r}=t,o=[];r.forEach(i=>{var l;const s=this.editor.getShape(i.id),a=this.editor.getShapeUtil(i),c=(l=a.onTranslate)==null?void 0:l.call(a,i,s);c&&o.push(c)}),o.length>0&&this.editor.updateShapes(o)}}g(mM,"id","translating");function ZC(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 S=e.getShapePageTransform(f),m=S.point(),w=S.rotation();t.push(m);const y=Ko.isId(p.parentId)?null:ie.Inverse(e.getShapePageTransform(p.parentId));return{shape:p,pagePoint:m,pageRotation:w,parentTransform:y}})),i=e.getOnlySelectedShape();let s=[];if(i)s=e.snaps.shapeBounds.getSnapPoints(i.id);else{const f=e.getSelectionPageBounds();f&&(s=f.cornersAndCenter.map((p,S)=>({id:"selection:"+S,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(S=>S.id===p.shape.id)})).sort((p,S)=>S.index-p.index)[0])==null?void 0:d.snapshot}return c&&(a=E$(e,c.pageRotation,c.shape.props.growY??0)),{averagePagePoint:b.Average(t),movingShapes:n,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:s,noteAdjacentPositions:a,noteSnapshot:c}}function jY({editor:e,snapshot:n}){const{inputs:t}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:i,initialSnapPoints:s,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:i,lockedAxis:f,initialSelectionSnapPoints:s});d.add(w)}else if(r&&o){let w=C$/e.getZoomLevel(),y=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,y=E)}d.sub(y)}const S=b.Add(c,d);l&&!t.ctrlKey&&S.snapToGrid(u);const m=b.Sub(S,c);e.updateShapes(ye(a.map(({shape:w,pagePoint:y,parentTransform:v})=>{const P=b.Add(y,m),E=v?ie.applyToPoint(v,P):P;return{id:w.id,type:w.type,x:E.x,y:E.y}})))}class ef 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(i=>o.has(i))||this.editor.updateInstanceState({duplicateProps:null})});g(this,"onEnter",()=>{this.reactor=Gs("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(ef,"id","select"),g(ef,"initial","idle"),g(ef,"children",()=>[Jh,nw,EY,cM,hM,mM,J$,gM,ow,dM,eM,sM,fM,pM,uM,aM,lM,oM]);class yM 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(yM,"id","idle");class SM 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(SM,"id","pointing");class vM 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(vM,"id","zoom_brushing");class tf 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(tf,"id","zoom"),g(tf,"initial","idle"),g(tf,"children",()=>[yM,vM,SM]);const OY=[qh,Zh,Qh,tf,ef];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 ae(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 DY(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function rg(...e){return n=>e.forEach(t=>DY(t,n))}function Xe(...e){return x.useCallback(rg(...e),e)}function bo(e,n=[]){let t=[];function r(i,s){const a=x.createContext(s),c=t.length;t=[...t,s];function l(d){const{scope:f,children:p,...S}=d,m=(f==null?void 0:f[e][c])||a,w=x.useMemo(()=>S,Object.values(S));return x.createElement(m.Provider,{value:w},p)}function u(d,f){const p=(f==null?void 0:f[e][c])||a,S=x.useContext(p);if(S)return S;if(s!==void 0)return s;throw new Error(`\`${d}\` must be used within \`${i}\``)}return l.displayName=i+"Provider",[l,u]}const o=()=>{const i=t.map(s=>x.createContext(s));return function(a){const c=(a==null?void 0:a[e])||i;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,RY(o,...n)]}function RY(...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(i){const s=r.reduce((a,{useScope:c,scopeName:l})=>{const d=c(i)[`__scope${l}`];return{...a,...d}},{});return x.useMemo(()=>({[`__scope${n.scopeName}`]:s}),[s])}};return t.scopeName=n.scopeName,t}const Ls=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{},LY=SD.useId||(()=>{});let FY=0;function Ho(e){const[n,t]=x.useState(LY());return Ls(()=>{e||t(r=>r??String(FY++))},[e]),e||(n?`radix-${n}`:"")}function cn(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 Qi({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=NY({defaultProp:n,onChange:t}),i=e!==void 0,s=i?e:r,a=cn(t),c=x.useCallback(l=>{if(i){const d=typeof l=="function"?l(e):l;d!==e&&a(d)}else o(l)},[i,e,o,a]);return[s,c]}function NY({defaultProp:e,onChange:n}){const t=x.useState(e),[r]=t,o=x.useRef(r),i=cn(n);return x.useEffect(()=>{o.current!==r&&(i(r),o.current=r)},[r,o,i]),t}const Fs=x.forwardRef((e,n)=>{const{children:t,...r}=e,o=x.Children.toArray(t),i=o.find(BY);if(i){const s=i.props.children,a=o.map(c=>c===i?x.Children.count(s)>1?x.Children.only(null):x.isValidElement(s)?s.props.children:null:c);return x.createElement(Cv,Q({},r,{ref:n}),x.isValidElement(s)?x.cloneElement(s,void 0,a):null)}return x.createElement(Cv,Q({},r,{ref:n}),t)});Fs.displayName="Slot";const Cv=x.forwardRef((e,n)=>{const{children:t,...r}=e;return x.isValidElement(t)?x.cloneElement(t,{...UY(r,t.props),ref:n?rg(n,t.ref):t.ref}):x.Children.count(t)>1?x.Children.only(null):null});Cv.displayName="SlotClone";const zY=({children:e})=>x.createElement(x.Fragment,null,e);function BY(e){return x.isValidElement(e)&&e.type===zY}function UY(e,n){const t={...n};for(const r in n){const o=e[r],i=n[r];/^on[A-Z]/.test(r)?o&&i?t[r]=(...a)=>{i(...a),o(...a)}:o&&(t[r]=o):r==="style"?t[r]={...o,...i}:r==="className"&&(t[r]=[o,i].filter(Boolean).join(" "))}return{...e,...t}}const HY=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],He=HY.reduce((e,n)=>{const t=x.forwardRef((r,o)=>{const{asChild:i,...s}=r,a=i?Fs:n;return x.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),x.createElement(a,Q({},s,{ref:o}))});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function iw(e,n){e&&Xs.flushSync(()=>e.dispatchEvent(n))}function KY(e,n=globalThis==null?void 0:globalThis.document){const t=cn(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r),()=>n.removeEventListener("keydown",r)},[t,n])}const Iv="dismissableLayer.update",WY="dismissableLayer.pointerDownOutside",GY="dismissableLayer.focusOutside";let QC;const xM=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),og=x.forwardRef((e,n)=>{var t;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:i,onFocusOutside:s,onInteractOutside:a,onDismiss:c,...l}=e,u=x.useContext(xM),[d,f]=x.useState(null),p=(t=d==null?void 0:d.ownerDocument)!==null&&t!==void 0?t:globalThis==null?void 0:globalThis.document,[,S]=x.useState({}),m=Xe(n,k=>f(k)),w=Array.from(u.layers),[y]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=w.indexOf(y),P=d?w.indexOf(d):-1,E=u.layersWithOutsidePointerEventsDisabled.size>0,C=P>=v,I=YY(k=>{const $=k.target,T=[...u.branches].some(A=>A.contains($));!C||T||(i==null||i(k),a==null||a(k),k.defaultPrevented||c==null||c())},p),_=XY(k=>{const $=k.target;[...u.branches].some(A=>A.contains($))||(s==null||s(k),a==null||a(k),k.defaultPrevented||c==null||c())},p);return KY(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&&(QC=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),JC(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=QC)}},[d,p,r,u]),x.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),JC())},[d,u]),x.useEffect(()=>{const k=()=>S({});return document.addEventListener(Iv,k),()=>document.removeEventListener(Iv,k)},[]),x.createElement(He.div,Q({},l,{ref:m,style:{pointerEvents:E?C?"auto":"none":void 0,...e.style},onFocusCapture:ae(e.onFocusCapture,_.onFocusCapture),onBlurCapture:ae(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:ae(e.onPointerDownCapture,I.onPointerDownCapture)}))}),VY=x.forwardRef((e,n)=>{const t=x.useContext(xM),r=x.useRef(null),o=Xe(n,r);return x.useEffect(()=>{const i=r.current;if(i)return t.branches.add(i),()=>{t.branches.delete(i)}},[t.branches]),x.createElement(He.div,Q({},e,{ref:o}))});function YY(e,n=globalThis==null?void 0:globalThis.document){const t=cn(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const i=a=>{if(a.target&&!r.current){let u=function(){wM(WY,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},s=window.setTimeout(()=>{n.addEventListener("pointerdown",i)},0);return()=>{window.clearTimeout(s),n.removeEventListener("pointerdown",i),n.removeEventListener("click",o.current)}},[n,t]),{onPointerDownCapture:()=>r.current=!0}}function XY(e,n=globalThis==null?void 0:globalThis.document){const t=cn(e),r=x.useRef(!1);return x.useEffect(()=>{const o=i=>{i.target&&!r.current&&wM(GY,t,{originalEvent:i},{discrete:!1})};return n.addEventListener("focusin",o),()=>n.removeEventListener("focusin",o)},[n,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function JC(){const e=new CustomEvent(Iv);document.dispatchEvent(e)}function wM(e,n,t,{discrete:r}){const o=t.originalEvent.target,i=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?iw(o,i):o.dispatchEvent(i)}const qY=og,ZY=VY,oy="focusScope.autoFocusOnMount",iy="focusScope.autoFocusOnUnmount",eI={bubbles:!1,cancelable:!0},sw=x.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:i,...s}=e,[a,c]=x.useState(null),l=cn(o),u=cn(i),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=_:gi(d.current,{select:!0})},P=function(I){if(p.paused||!a)return;const _=I.relatedTarget;_!==null&&(a.contains(_)||gi(d.current,{select:!0}))},E=function(I){if(document.activeElement===document.body)for(const k of I)k.removedNodes.length>0&&gi(a)};var m=v,w=P,y=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){nI.add(p);const m=document.activeElement;if(!a.contains(m)){const y=new CustomEvent(oy,eI);a.addEventListener(oy,l),a.dispatchEvent(y),y.defaultPrevented||(QY(rX(bM(a)),{select:!0}),document.activeElement===m&&gi(a))}return()=>{a.removeEventListener(oy,l),setTimeout(()=>{const y=new CustomEvent(iy,eI);a.addEventListener(iy,u),a.dispatchEvent(y),y.defaultPrevented||gi(m??document.body,{select:!0}),a.removeEventListener(iy,u),nI.remove(p)},0)}}},[a,l,u,p]);const S=x.useCallback(m=>{if(!t&&!r||p.paused)return;const w=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,y=document.activeElement;if(w&&y){const v=m.currentTarget,[P,E]=JY(v);P&&E?!m.shiftKey&&y===E?(m.preventDefault(),t&&gi(P,{select:!0})):m.shiftKey&&y===P&&(m.preventDefault(),t&&gi(E,{select:!0})):y===v&&m.preventDefault()}},[t,r,p.paused]);return x.createElement(He.div,Q({tabIndex:-1},s,{ref:f,onKeyDown:S}))});function QY(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(gi(r,{select:n}),document.activeElement!==t)return}function JY(e){const n=bM(e),t=tI(n,e),r=tI(n.reverse(),e);return[t,r]}function bM(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 tI(e,n){for(const t of e)if(!eX(t,{upTo:n}))return t}function eX(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 tX(e){return e instanceof HTMLInputElement&&"select"in e}function gi(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&tX(e)&&n&&e.select()}}const nI=nX();function nX(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=rI(e,n),e.unshift(n)},remove(n){var t;e=rI(e,n),(t=e[0])===null||t===void 0||t.resume()}}}function rI(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function rX(e){return e.filter(n=>n.tagName!=="A")}const ig=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?DH.createPortal(x.createElement(He.div,Q({},o,{ref:n})),r):null});function oX(e,n){return x.useReducer((t,r)=>{const o=n[t][r];return o??t},e)}const Po=e=>{const{present:n,children:t}=e,r=iX(n),o=typeof t=="function"?t({present:r.isPresent}):x.Children.only(t),i=Xe(r.ref,o.ref);return typeof t=="function"||r.isPresent?x.cloneElement(o,{ref:i}):null};Po.displayName="Presence";function iX(e){const[n,t]=x.useState(),r=x.useRef({}),o=x.useRef(e),i=x.useRef("none"),s=e?"mounted":"unmounted",[a,c]=oX(s,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const l=Hd(r.current);i.current=a==="mounted"?l:"none"},[a]),Ls(()=>{const l=r.current,u=o.current;if(u!==e){const f=i.current,p=Hd(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]),Ls(()=>{if(n){const l=d=>{const p=Hd(r.current).includes(d.animationName);d.target===n&&p&&Xs.flushSync(()=>c("ANIMATION_END"))},u=d=>{d.target===n&&(i.current=Hd(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 Hd(e){return(e==null?void 0:e.animationName)||"none"}let sy=0;function aw(){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:oI()),document.body.insertAdjacentElement("beforeend",(n=t[1])!==null&&n!==void 0?n:oI()),sy++,()=>{sy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),sy--}},[])}function oI(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",e}var to=function(){return to=Object.assign||function(n){for(var t,r=1,o=arguments.length;r<o;r++){t=arguments[r];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i])}return n},to.apply(this,arguments)};function PM(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 sX(e,n,t){if(t||arguments.length===2)for(var r=0,o=n.length,i;r<o;r++)(i||!(r in n))&&(i||(i=Array.prototype.slice.call(n,0,r)),i[r]=n[r]);return e.concat(i||Array.prototype.slice.call(n))}var nf="right-scroll-bar-position",rf="width-before-scroll-bar",aX="with-scroll-bars-hidden",cX="--removed-body-scroll-bar-size";function ay(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function lX(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 uX=typeof window<"u"?x.useLayoutEffect:x.useEffect,iI=new WeakMap;function dX(e,n){var t=lX(null,function(r){return e.forEach(function(o){return ay(o,r)})});return uX(function(){var r=iI.get(t);if(r){var o=new Set(r),i=new Set(e),s=t.current;o.forEach(function(a){i.has(a)||ay(a,null)}),i.forEach(function(a){o.has(a)||ay(a,s)})}iI.set(t,e)},[e]),t}function hX(e){return e}function fX(e,n){n===void 0&&(n=hX);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(i){var s=n(i,r);return t.push(s),function(){t=t.filter(function(a){return a!==s})}},assignSyncMedium:function(i){for(r=!0;t.length;){var s=t;t=[],s.forEach(i)}t={push:function(a){return i(a)},filter:function(){return t}}},assignMedium:function(i){r=!0;var s=[];if(t.length){var a=t;t=[],a.forEach(i),s=t}var c=function(){var u=s;s=[],u.forEach(i)},l=function(){return Promise.resolve().then(c)};l(),t={push:function(u){s.push(u),l()},filter:function(u){return s=s.filter(u),t}}}};return o}function pX(e){e===void 0&&(e={});var n=fX(null);return n.options=to({async:!0,ssr:!1},e),n}var CM=function(e){var n=e.sideCar,t=PM(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,to({},t))};CM.isSideCarExport=!0;function gX(e,n){return e.useMedium(n),CM}var IM=pX(),cy=function(){},sg=x.forwardRef(function(e,n){var t=x.useRef(null),r=x.useState({onScrollCapture:cy,onWheelCapture:cy,onTouchMoveCapture:cy}),o=r[0],i=r[1],s=e.forwardProps,a=e.children,c=e.className,l=e.removeScrollBar,u=e.enabled,d=e.shards,f=e.sideCar,p=e.noIsolation,S=e.inert,m=e.allowPinchZoom,w=e.as,y=w===void 0?"div":w,v=PM(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),P=f,E=dX([t,n]),C=to(to({},v),o);return x.createElement(x.Fragment,null,u&&x.createElement(P,{sideCar:IM,removeScrollBar:l,shards:d,noIsolation:p,inert:S,setCallbacks:i,allowPinchZoom:!!m,lockRef:t}),s?x.cloneElement(x.Children.only(a),to(to({},C),{ref:E})):x.createElement(y,to({},C,{className:c,ref:E}),a))});sg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};sg.classNames={fullWidth:rf,zeroRight:nf};var mX=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function yX(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=mX();return n&&e.setAttribute("nonce",n),e}function SX(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function vX(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var xX=function(){var e=0,n=null;return{add:function(t){e==0&&(n=yX())&&(SX(n,t),vX(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},wX=function(){var e=xX();return function(n,t){x.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},EM=function(){var e=wX(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},bX={left:0,top:0,right:0,gap:0},ly=function(e){return parseInt(e||"",10)||0},PX=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[ly(t),ly(r),ly(o)]},CX=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return bX;var n=PX(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])}},IX=EM(),Ja="data-scroll-locked",EX=function(e,n,t,r){var o=e.left,i=e.top,s=e.right,a=e.gap;return t===void 0&&(t="margin"),`
159
- .`.concat(aX,` {
160
- overflow: hidden `).concat(r,`;
161
- padding-right: `).concat(a,"px ").concat(r,`;
162
- }
163
- body[`).concat(Ja,`] {
164
- overflow: hidden `).concat(r,`;
165
- overscroll-behavior: contain;
166
- `).concat([n&&"position: relative ".concat(r,";"),t==="margin"&&`
167
- padding-left: `.concat(o,`px;
168
- padding-top: `).concat(i,`px;
169
- padding-right: `).concat(s,`px;
170
- margin-left:0;
171
- margin-top:0;
172
- margin-right: `).concat(a,"px ").concat(r,`;
173
- `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
174
- }
175
-
176
- .`).concat(nf,` {
177
- right: `).concat(a,"px ").concat(r,`;
178
- }
179
-
180
- .`).concat(rf,` {
181
- margin-right: `).concat(a,"px ").concat(r,`;
182
- }
183
-
184
- .`).concat(nf," .").concat(nf,` {
185
- right: 0 `).concat(r,`;
186
- }
187
-
188
- .`).concat(rf," .").concat(rf,` {
189
- margin-right: 0 `).concat(r,`;
190
- }
191
-
192
- body[`).concat(Ja,`] {
193
- `).concat(cX,": ").concat(a,`px;
194
- }
195
- `)},sI=function(){var e=parseInt(document.body.getAttribute(Ja)||"0",10);return isFinite(e)?e:0},_X=function(){x.useEffect(function(){return document.body.setAttribute(Ja,(sI()+1).toString()),function(){var e=sI()-1;e<=0?document.body.removeAttribute(Ja):document.body.setAttribute(Ja,e.toString())}},[])},kX=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;_X();var i=x.useMemo(function(){return CX(o)},[o]);return x.createElement(IX,{styles:EX(i,!n,o,t?"":"!important")})},Ev=!1;if(typeof window<"u")try{var Kd=Object.defineProperty({},"passive",{get:function(){return Ev=!0,!0}});window.addEventListener("test",Kd,Kd),window.removeEventListener("test",Kd,Kd)}catch{Ev=!1}var ua=Ev?{passive:!1}:!1,TX=function(e){return e.tagName==="TEXTAREA"},_M=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!TX(e)&&t[n]==="visible")},$X=function(e){return _M(e,"overflowY")},MX=function(e){return _M(e,"overflowX")},aI=function(e,n){var t=n;do{typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&(t=t.host);var r=kM(e,t);if(r){var o=TM(e,t),i=o[1],s=o[2];if(i>s)return!0}t=t.parentNode}while(t&&t!==document.body);return!1},AX=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},jX=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},kM=function(e,n){return e==="v"?$X(n):MX(n)},TM=function(e,n){return e==="v"?AX(n):jX(n)},OX=function(e,n){return e==="h"&&n==="rtl"?-1:1},DX=function(e,n,t,r,o){var i=OX(e,window.getComputedStyle(n).direction),s=i*r,a=t.target,c=n.contains(a),l=!1,u=s>0,d=0,f=0;do{var p=TM(e,a),S=p[0],m=p[1],w=p[2],y=m-w-i*S;(S||y)&&kM(e,a)&&(d+=y,f+=S),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},Wd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},cI=function(e){return[e.deltaX,e.deltaY]},lI=function(e){return e&&"current"in e?e.current:e},RX=function(e,n){return e[0]===n[0]&&e[1]===n[1]},LX=function(e){return`
196
- .block-interactivity-`.concat(e,` {pointer-events: none;}
197
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
198
- `)},FX=0,da=[];function NX(e){var n=x.useRef([]),t=x.useRef([0,0]),r=x.useRef(),o=x.useState(FX++)[0],i=x.useState(function(){return EM()})[0],s=x.useRef(e);x.useEffect(function(){s.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=sX([e.lockRef.current],(e.shards||[]).map(lI),!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!s.current.allowPinchZoom;var y=Wd(m),v=t.current,P="deltaX"in m?m.deltaX:v[0]-y[0],E="deltaY"in m?m.deltaY:v[1]-y[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=aI(_,I);if(!k)return!0;if(k?C=_:(C=_==="v"?"h":"v",k=aI(_,I)),!k)return!1;if(!r.current&&"changedTouches"in m&&(P||E)&&(r.current=C),!C)return!0;var $=r.current||C;return DX($,w,m,$==="h"?P:E,!0)},[]),c=x.useCallback(function(m){var w=m;if(!(!da.length||da[da.length-1]!==i)){var y="deltaY"in w?cI(w):Wd(w),v=n.current.filter(function(C){return C.name===w.type&&C.target===w.target&&RX(C.delta,y)})[0];if(v&&v.should){w.cancelable&&w.preventDefault();return}if(!v){var P=(s.current.shards||[]).map(lI).filter(Boolean).filter(function(C){return C.contains(w.target)}),E=P.length>0?a(w,P[0]):!s.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),l=x.useCallback(function(m,w,y,v){var P={name:m,delta:w,target:y,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=Wd(m),r.current=void 0},[]),d=x.useCallback(function(m){l(m.type,cI(m),m.target,a(m,e.lockRef.current))},[]),f=x.useCallback(function(m){l(m.type,Wd(m),m.target,a(m,e.lockRef.current))},[]);x.useEffect(function(){return da.push(i),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:f}),document.addEventListener("wheel",c,ua),document.addEventListener("touchmove",c,ua),document.addEventListener("touchstart",u,ua),function(){da=da.filter(function(m){return m!==i}),document.removeEventListener("wheel",c,ua),document.removeEventListener("touchmove",c,ua),document.removeEventListener("touchstart",u,ua)}},[]);var p=e.removeScrollBar,S=e.inert;return x.createElement(x.Fragment,null,S?x.createElement(i,{styles:LX(o)}):null,p?x.createElement(kX,{gapMode:"margin"}):null)}const zX=gX(IM,NX);var ag=x.forwardRef(function(e,n){return x.createElement(sg,to({},e,{ref:n,sideCar:zX}))});ag.classNames=sg.classNames;var BX=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},ha=new WeakMap,Gd=new WeakMap,Vd={},uy=0,$M=function(e){return e&&(e.host||$M(e.parentNode))},UX=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=$M(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})},HX=function(e,n,t,r){var o=UX(n,Array.isArray(e)?e:[e]);Vd[t]||(Vd[t]=new WeakMap);var i=Vd[t],s=[],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),S=p!==null&&p!=="false",m=(ha.get(f)||0)+1,w=(i.get(f)||0)+1;ha.set(f,m),i.set(f,w),s.push(f),m===1&&S&&Gd.set(f,!0),w===1&&f.setAttribute(t,"true"),S||f.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",f,y)}})};return u(n),a.clear(),uy++,function(){s.forEach(function(d){var f=ha.get(d)-1,p=i.get(d)-1;ha.set(d,f),i.set(d,p),f||(Gd.has(d)||d.removeAttribute(r),Gd.delete(d)),p||d.removeAttribute(t)}),uy--,uy||(ha=new WeakMap,ha=new WeakMap,Gd=new WeakMap,Vd={})}},cw=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=BX(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),HX(r,o,t,"aria-hidden")):function(){return null}};const MM="Dialog",[AM,Boe]=bo(MM),[KX,ri]=AM(MM),WX=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:i,modal:s=!0}=e,a=x.useRef(null),c=x.useRef(null),[l=!1,u]=Qi({prop:r,defaultProp:o,onChange:i});return x.createElement(KX,{scope:n,triggerRef:a,contentRef:c,contentId:Ho(),titleId:Ho(),descriptionId:Ho(),open:l,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(d=>!d),[u]),modal:s},t)},jM="DialogPortal",[GX,OM]=AM(jM,{forceMount:void 0}),VX=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,i=ri(jM,n);return x.createElement(GX,{scope:n,forceMount:t},x.Children.map(r,s=>x.createElement(Po,{present:t||i.open},x.createElement(ig,{asChild:!0,container:o},s))))},_v="DialogOverlay",YX=x.forwardRef((e,n)=>{const t=OM(_v,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,i=ri(_v,e.__scopeDialog);return i.modal?x.createElement(Po,{present:r||i.open},x.createElement(XX,Q({},o,{ref:n}))):null}),XX=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=ri(_v,t);return x.createElement(ag,{as:Fs,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(He.div,Q({"data-state":RM(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),uu="DialogContent",qX=x.forwardRef((e,n)=>{const t=OM(uu,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,i=ri(uu,e.__scopeDialog);return x.createElement(Po,{present:r||i.open},i.modal?x.createElement(ZX,Q({},o,{ref:n})):x.createElement(QX,Q({},o,{ref:n})))}),ZX=x.forwardRef((e,n)=>{const t=ri(uu,e.__scopeDialog),r=x.useRef(null),o=Xe(n,t.contentRef,r);return x.useEffect(()=>{const i=r.current;if(i)return cw(i)},[]),x.createElement(DM,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ae(e.onCloseAutoFocus,i=>{var s;i.preventDefault(),(s=t.triggerRef.current)===null||s===void 0||s.focus()}),onPointerDownOutside:ae(e.onPointerDownOutside,i=>{const s=i.detail.originalEvent,a=s.button===0&&s.ctrlKey===!0;(s.button===2||a)&&i.preventDefault()}),onFocusOutside:ae(e.onFocusOutside,i=>i.preventDefault())}))}),QX=x.forwardRef((e,n)=>{const t=ri(uu,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(DM,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var s;if((s=e.onCloseAutoFocus)===null||s===void 0||s.call(e,i),!i.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),i.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:i=>{var s,a;(s=e.onInteractOutside)===null||s===void 0||s.call(e,i),i.defaultPrevented||(r.current=!0,i.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=i.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&o.current&&i.preventDefault()}}))}),DM=x.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:i,...s}=e,a=ri(uu,t),c=x.useRef(null),l=Xe(n,c);return aw(),x.createElement(x.Fragment,null,x.createElement(sw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:i},x.createElement(og,Q({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":RM(a.open)},s,{ref:l,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),JX="DialogTitle",eq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=ri(JX,t);return x.createElement(He.h2,Q({id:o.titleId},r,{ref:n}))});const tq="DialogClose",nq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=ri(tq,t);return x.createElement(He.button,Q({type:"button"},r,{ref:n,onClick:ae(e.onClick,()=>o.onOpenChange(!1))}))});function RM(e){return e?"open":"closed"}const rq=WX,oq=VX,iq=YX,sq=qX,LM=()=>{},FM=x.createContext(null);function aq({onEvent:e,children:n}){return h.jsx(FM.Provider,{value:e??LM,children:n})}function Co(){return x.useContext(FM)??LM}const NM=x.createContext(null);function cq({children:e}){const n=z(),t=Co(),[r,o]=x.useState([]),i=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]),s=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(NM.Provider,{value:{dialogs:r,addDialog:i,removeDialog:a,clearDialogs:c,updateDialog:s},children:e})}function qs(){const e=x.useContext(NM);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const lq=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=qs(),o=ln(),i=x.useCallback(s=>{if(!s){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return h.jsx(rq,{onOpenChange:i,defaultOpen:!0,children:h.jsx(oq,{container:o,children:h.jsx(iq,{dir:"ltr",className:"tlui-dialog__overlay",onClick:s=>{s.target===s.currentTarget&&i(!1)},children:h.jsx(sq,{dir:"ltr",className:"tlui-dialog__content",children:h.jsx(n,{onClose:()=>i(!1)})})})})})};function uq(){const{dialogs:e}=qs();return h.jsx(h.Fragment,{children:e.map(n=>h.jsx(lq,{...n},n.id))})}const dq=Se.memo(uq);function hq(){const e=z(),n=G("follow",()=>e.getInstanceState().followingUserId,[e]);return n?h.jsx(fq,{userId:n}):null}function fq({userId:e}){const n=kk(e);return n?h.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function cg(e){const n=e+"CollectionProvider",[t,r]=bo(n),[o,i]=t(n,{collectionRef:{current:null},itemMap:new Map}),s=p=>{const{scope:S,children:m}=p,w=Se.useRef(null),y=Se.useRef(new Map).current;return Se.createElement(o,{scope:S,itemMap:y,collectionRef:w},m)},a=e+"CollectionSlot",c=Se.forwardRef((p,S)=>{const{scope:m,children:w}=p,y=i(a,m),v=Xe(S,y.collectionRef);return Se.createElement(Fs,{ref:v},w)}),l=e+"CollectionItemSlot",u="data-radix-collection-item",d=Se.forwardRef((p,S)=>{const{scope:m,children:w,...y}=p,v=Se.useRef(null),P=Xe(S,v),E=i(l,m);return Se.useEffect(()=>(E.itemMap.set(v,{ref:v,...y}),()=>void E.itemMap.delete(v))),Se.createElement(Fs,{[u]:"",ref:P},w)});function f(p){const S=i(e+"CollectionConsumer",p);return Se.useCallback(()=>{const w=S.collectionRef.current;if(!w)return[];const y=Array.from(w.querySelectorAll(`[${u}]`));return Array.from(S.itemMap.values()).sort((E,C)=>y.indexOf(E.ref.current)-y.indexOf(C.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:s,Slot:c,ItemSlot:d},f,r]}const zM=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}}))),BM="ToastProvider",[lw,pq,gq]=cg("Toast"),[UM,Uoe]=bo("Toast",[gq]),[mq,lg]=UM(BM),HM=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:i=50,children:s}=e,[a,c]=x.useState(null),[l,u]=x.useState(0),d=x.useRef(!1),f=x.useRef(!1);return x.createElement(lw.Provider,{scope:n},x.createElement(mq,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:i,toastCount:l,viewport:a,onViewportChange:c,onToastAdd:x.useCallback(()=>u(p=>p+1),[]),onToastRemove:x.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:d,isClosePausedRef:f},s))};HM.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const n=`Invalid prop \`label\` supplied to \`${BM}\`. Expected non-empty \`string\`.`;return new Error(n)}return null}};const yq="ToastViewport",Sq=["F8"],kv="toast.viewportPause",Tv="toast.viewportResume",vq=x.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=Sq,label:o="Notifications ({hotkey})",...i}=e,s=lg(yq,t),a=pq(t),c=x.useRef(null),l=x.useRef(null),u=x.useRef(null),d=x.useRef(null),f=Xe(n,d,s.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=s.toastCount>0;x.useEffect(()=>{const w=y=>{var v;r.every(E=>y[E]||y.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,y=d.current;if(S&&w&&y){const v=()=>{if(!s.isClosePausedRef.current){const I=new CustomEvent(kv);y.dispatchEvent(I),s.isClosePausedRef.current=!0}},P=()=>{if(s.isClosePausedRef.current){const I=new CustomEvent(Tv);y.dispatchEvent(I),s.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)}}},[S,s.isClosePausedRef]);const m=x.useCallback(({tabbingDirection:w})=>{const v=a().map(P=>{const E=P.ref.current,C=[E,...Dq(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 y=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"}),j=N.findIndex(O=>O===k);if(dy(N.slice(j+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",y),()=>w.removeEventListener("keydown",y)}},[a,m]),x.createElement(ZY,{ref:c,role:"region","aria-label":o.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:S?void 0:"none"}},S&&x.createElement(uI,{ref:l,onFocusFromOutsideViewport:()=>{const w=m({tabbingDirection:"forwards"});dy(w)}}),x.createElement(lw.Slot,{scope:t},x.createElement(He.ol,Q({tabIndex:-1},i,{ref:f}))),S&&x.createElement(uI,{ref:u,onFocusFromOutsideViewport:()=>{const w=m({tabbingDirection:"backwards"});dy(w)}}))}),xq="ToastFocusProxy",uI=x.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,i=lg(xq,t);return x.createElement(zM,Q({"aria-hidden":!0,tabIndex:0},o,{ref:n,style:{position:"fixed"},onFocus:s=>{var a;const c=s.relatedTarget;!((a=i.viewport)!==null&&a!==void 0&&a.contains(c))&&r()}}))}),ug="Toast",wq="toast.swipeStart",bq="toast.swipeMove",Pq="toast.swipeCancel",Cq="toast.swipeEnd",Iq=x.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:i,...s}=e,[a=!0,c]=Qi({prop:r,defaultProp:o,onChange:i});return x.createElement(Po,{present:t||a},x.createElement(KM,Q({open:a},s,{ref:n,onClose:()=>c(!1),onPause:cn(e.onPause),onResume:cn(e.onResume),onSwipeStart:ae(e.onSwipeStart,l=>{l.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ae(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:ae(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:ae(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)})})))}),[Eq,_q]=UM(ug,{onClose(){}}),KM=x.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:i,onClose:s,onEscapeKeyDown:a,onPause:c,onResume:l,onSwipeStart:u,onSwipeMove:d,onSwipeCancel:f,onSwipeEnd:p,...S}=e,m=lg(ug,t),[w,y]=x.useState(null),v=Xe(n,O=>y(O)),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,A=cn(()=>{var O;(w==null?void 0:w.contains(document.activeElement))&&((O=m.viewport)===null||O===void 0||O.focus()),s()}),N=x.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),I.current=new Date().getTime(),k.current=window.setTimeout(A,O))},[A]);x.useEffect(()=>{const O=m.viewport;if(O){const R=()=>{N(_.current),l==null||l()},Y=()=>{const K=new Date().getTime()-I.current;_.current=_.current-K,window.clearTimeout(k.current),c==null||c()};return O.addEventListener(kv,Y),O.addEventListener(Tv,R),()=>{O.removeEventListener(kv,Y),O.removeEventListener(Tv,R)}}},[m.viewport,C,c,l,N]),x.useEffect(()=>{i&&!m.isClosePausedRef.current&&N(C)},[i,C,m.isClosePausedRef,N]),x.useEffect(()=>($(),()=>T()),[$,T]);const j=x.useMemo(()=>w?YM(w):null,[w]);return m.viewport?x.createElement(x.Fragment,null,j&&x.createElement(kq,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},j),x.createElement(Eq,{scope:t,onClose:A},Xs.createPortal(x.createElement(lw.ItemSlot,{scope:t},x.createElement(qY,{asChild:!0,onEscapeKeyDown:ae(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||A(),m.isFocusedToastEscapeKeyDownRef.current=!1})},x.createElement(He.li,Q({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":i?"open":"closed","data-swipe-direction":m.swipeDirection},S,{ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:ae(e.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,A()))}),onPointerDown:ae(e.onPointerDown,O=>{O.button===0&&(P.current={x:O.clientX,y:O.clientY})}),onPointerMove:ae(e.onPointerMove,O=>{if(!P.current)return;const R=O.clientX-P.current.x,Y=O.clientY-P.current.y,K=!!E.current,U=["left","right"].includes(m.swipeDirection),H=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,W=U?H(0,R):0,Z=U?0:H(0,Y),oe=O.pointerType==="touch"?10:2,be={x:W,y:Z},Ae={originalEvent:O,delta:be};K?(E.current=be,Yd(bq,d,Ae,{discrete:!1})):dI(be,m.swipeDirection,oe)?(E.current=be,Yd(wq,u,Ae,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(R)>oe||Math.abs(Y)>oe)&&(P.current=null)}),onPointerUp:ae(e.onPointerUp,O=>{const R=E.current,Y=O.target;if(Y.hasPointerCapture(O.pointerId)&&Y.releasePointerCapture(O.pointerId),E.current=null,P.current=null,R){const K=O.currentTarget,U={originalEvent:O,delta:R};dI(R,m.swipeDirection,m.swipeThreshold)?Yd(Cq,p,U,{discrete:!0}):Yd(Pq,f,U,{discrete:!0}),K.addEventListener("click",H=>H.preventDefault(),{once:!0})}})})))),m.viewport))):null});KM.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const n=`Invalid prop \`type\` supplied to \`${ug}\`. Expected \`foreground | background\`.`;return new Error(n)}return null}};const kq=e=>{const{__scopeToast:n,children:t,...r}=e,o=lg(ug,n),[i,s]=x.useState(!1),[a,c]=x.useState(!1);return jq(()=>s(!0)),x.useEffect(()=>{const l=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(l)},[]),a?null:x.createElement(ig,{asChild:!0},x.createElement(zM,r,i&&x.createElement(x.Fragment,null,o.label," ",t)))},Tq=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return x.createElement(He.div,Q({},r,{ref:n}))}),$q=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return x.createElement(He.div,Q({},r,{ref:n}))}),Mq="ToastAction",WM=x.forwardRef((e,n)=>{const{altText:t,...r}=e;return t?x.createElement(VM,{altText:t,asChild:!0},x.createElement(GM,Q({},r,{ref:n}))):null});WM.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${Mq}\``)}};const Aq="ToastClose",GM=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=_q(Aq,t);return x.createElement(VM,{asChild:!0},x.createElement(He.button,Q({type:"button"},r,{ref:n,onClick:ae(e.onClick,o.onClose)})))}),VM=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 YM(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),Oq(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",i=r.dataset.radixToastAnnounceExclude==="";if(!o)if(i){const s=r.dataset.radixToastAnnounceAlt;s&&n.push(s)}else n.push(...YM(r))}}),n}function Yd(e,n,t,{discrete:r}){const o=t.originalEvent.currentTarget,i=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?iw(o,i):o.dispatchEvent(i)}const dI=(e,n,t=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),i=r>o;return n==="left"||n==="right"?i&&r>t:!i&&o>t};function jq(e=()=>{}){const n=cn(e);Ls(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function Oq(e){return e.nodeType===e.ELEMENT_NODE}function Dq(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 dy(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}const Rq=Iq,Lq=Tq,Fq=$q,Nq=WM,hI=GM,XM=x.createContext(null);function zq({children:e}){const[n,t]=x.useState([]),r=x.useCallback(s=>{const a=s.id??ot();return t(c=>[...c.filter(l=>l.id!==s.id),{...s,id:a}]),a},[]),o=x.useCallback(s=>(t(a=>a.filter(c=>c.id!==s)),s),[]),i=x.useCallback(()=>{t(()=>[])},[]);return h.jsx(HM,{children:h.jsx(XM.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:i},children:e})})}function Gr(){const e=x.useContext(XM);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},i){return h.jsx("button",{ref:i,type:"button",draggable:!1,disabled:t,...o,className:ue("tlui-button",`tlui-button__${r}`,o.className),children:n})});function Ct({children:e}){return h.jsx("span",{className:"tlui-button__label",children:e})}const Bi=x.memo(function({small:n,invertIcon:t,icon:r,color:o,className:i,...s}){const a=tw(),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},i)}):h.jsx("div",{...s,ref:l,className:ue("tlui-icon",{"tlui-icon__small":n},i),style:{color:o,mask:`url(${c}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})}),Bq={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function Uq({toast:e}){const{removeToast:n}=Gr(),t=Me(),r=s=>{s||n(e.id)},o=e.actions&&e.actions.length>0,i=e.icon||e.severity&&Bq[e.severity];return h.jsxs(Rq,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[i&&h.jsx("div",{className:"tlui-toast__icon",children:h.jsx(Bi,{icon:i})}),h.jsxs("div",{className:"tlui-toast__main",children:[h.jsxs("div",{className:"tlui-toast__content",children:[e.title&&h.jsx(Lq,{className:"tlui-toast__title",children:e.title}),e.description&&h.jsx(Fq,{className:"tlui-toast__description",children:e.description})]}),e.actions&&h.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((s,a)=>h.jsx(Nq,{altText:s.label,asChild:!0,onClick:s.onClick,children:h.jsx(he,{type:s.type,children:h.jsx(Ct,{children:s.label})})},a)),h.jsx(hI,{asChild:!0,children:h.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:h.jsx(Ct,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&h.jsx(hI,{asChild:!0,children:h.jsx(he,{type:"normal",className:"tlui-toast__close",children:h.jsx(Ct,{children:e.closeLabel??t("toast.close")})})})]})}function Hq(){const{toasts:e}=Gr();return h.jsx(h.Fragment,{children:e.map(n=>h.jsx(Uq,{toast:n},n.id))})}const Kq=x.memo(Hq);function Wq(){const e=z(),{toasts:n}=Gr(),[t,r]=x.useState(!1);return x.useEffect(()=>{let o=-1;return n.length?r(!0):o=e.timers.setTimeout(()=>{r(!1)},1e3),()=>{clearTimeout(o)}},[n.length,r,e]),t?h.jsx(vq,{className:"tlui-toast__viewport"}):null}function Pe({icon:e,small:n,invertIcon:t}){return h.jsx(Bi,{className:"tlui-button__icon",icon:e,small:n,invertIcon:t})}const hy=[0,390,428,468,580,640,840,1023];var xt=(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))(xt||{});const ys="2.2.0";let $v={fonts:{draw:`https://unpkg.com/@tldraw/assets@${ys}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${ys}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${ys}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${ys}/fonts/IBMPlexMono-Medium.woff2`}};function qM(e){return x.useMemo(()=>e?{fonts:{...$v.fonts,...e==null?void 0:e.fonts}}:$v,[e])}const Gq=["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 ol={...$v,icons:Object.fromEntries(Gq.map(e=>[e,`https://unpkg.com/@tldraw/assets@${ys}/icons/icon/${e}.svg`])),translations:Object.fromEntries(Bl.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${ys}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Tu.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${ys}/embed-icons/${e.type}.png`]))};function Vq(e){return e?{fonts:Object.assign({...ol.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...ol.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...ol.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...ol.translations},{...e==null?void 0:e.translations})}:ol}function dg({className:e,children:n}){return h.jsx("div",{className:ue("tlui-dialog__header",e),children:n})}function hg({className:e,children:n}){return h.jsx(eq,{dir:"ltr",className:ue("tlui-dialog__header__title",e),children:n})}function fg(){return h.jsx("div",{className:"tlui-dialog__header__close",children:h.jsx(nq,{"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 du({className:e,children:n,style:t}){return h.jsx("div",{className:ue("tlui-dialog__body",e),style:t,children:n})}function uw({className:e,children:n}){return h.jsx("div",{className:ue("tlui-dialog__footer",e),children:n})}const dw=x.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoSelect:i=!1,autoFocus:s=!1,defaultValue:a,placeholder:c,onComplete:l,onValueChange:u,onCancel:d,onFocus:f,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:S=!1,children:m,value:w},y){const v=z(),P=x.useRef(null);x.useImperativeHandle(y,()=>P.current);const E=Me(),C=x.useRef(a??""),I=x.useRef(a??""),[_,k]=x.useState(!1),$=x.useCallback(j=>{k(!0);const O=j.currentTarget;I.current=O.value,v.timers.requestAnimationFrame(()=>{i&&O.select()}),f==null||f()},[i,f,v.timers]),T=x.useCallback(j=>{const O=j.currentTarget.value;I.current=O,u==null||u(O)},[u]),A=x.useCallback(j=>{switch(j.key){case"Enter":{j.currentTarget.blur(),Ut(j),l==null||l(j.currentTarget.value);break}case"Escape":{j.currentTarget.value=C.current,j.currentTarget.blur(),Ut(j),d==null||d(j.currentTarget.value);break}}},[l,d]),N=x.useCallback(j=>{k(!1);const O=j.currentTarget.value;p==null||p(O)},[p]);return x.useEffect(()=>{if(!v.environment.isIos)return;const j=window.visualViewport;if(_&&S&&j){const O=()=>{var R;(R=P.current)==null||R.scrollIntoView({block:"center"})};return j.addEventListener("resize",O),j.addEventListener("scroll",O),v.timers.requestAnimationFrame(()=>{var R;(R=P.current)==null||R.scrollIntoView({block:"center"})}),()=>{j.removeEventListener("resize",O),j.removeEventListener("scroll",O)}}},[v,_,S]),h.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,t&&h.jsx("label",{children:E(t)}),o&&h.jsx(Bi,{icon:o,className:"tlui-icon-left",small:!0}),h.jsx("input",{ref:P,className:ue("tlui-input",n),type:"text",defaultValue:a,onKeyUp:A,onChange:T,onFocus:$,onBlur:N,autoFocus:s,placeholder:c,value:w}),r&&h.jsx(Bi,{icon:r,small:!!t})]})}),ZM=ir(function({onClose:n}){const t=z(),r=Me(),o=tw(),[i,s]=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(dg,{children:[h.jsx(hg,{children:i?`${r("embed-dialog.title")} — ${i.title}`:r("embed-dialog.title")}),h.jsx(fg,{})]}),i?h.jsxs(h.Fragment,{children:[h.jsxs(du,{className:"tlui-embed-dialog__enter",children:[h.jsx(dw,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:S=>{c(S);const m=Ii(S);u(m&&m.definition.type===i.type?m:null),f(!1),clearTimeout(p.current),p.current=t.timers.setTimeout(()=>f(!m),320)}}),a===""?h.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[h.jsx("span",{children:r("embed-dialog.instruction")})," ",i.instructionLink&&h.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:i.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",h.jsx(Bi,{icon:"external-link",small:!0})]})]}):h.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),h.jsxs(uw,{className:"tlui-dialog__footer__actions",children:[h.jsx(he,{type:"normal",onClick:()=>{s(null),u(null),c("")},children:h.jsx(Ct,{children:r("embed-dialog.back")})}),h.jsx("div",{className:"tlui-embed__spacer"}),h.jsx(he,{type:"normal",onClick:n,children:h.jsx(Ct,{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(Ct,{children:r("embed-dialog.create")})})]})]}):h.jsx(h.Fragment,{children:h.jsx(du,{className:"tlui-embed-dialog__list",children:Tu.map(S=>h.jsxs(he,{type:"menu",onClick:()=>s(S),children:[h.jsx(Ct,{children:S.title}),h.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[S.type]})`}})]},S.type))})})]})});function QM(){const e=z(),n=x.useRef();return x.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept=TN,t.multiple=!0,n.current=t;async function r(o){const i=o.target.files;!i||i.length===0||(e.mark("insert media"),await e.putExternalContent({type:"files",files:Array.from(i),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 JM=x.createContext(null);function Yq({overrides:e,children:n}){const t=z(),r=Co(),{addDialog:o}=qs(),i=QM(),s=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"})}},...[...so.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(so,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){i(),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:ZM}),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:i}):c},[e,t,r,i,o]);return h.jsx(JM.Provider,{value:s,children:n})}function pg(){const e=x.useContext(JM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const eA=Se.createContext(null);function Xq({forceMobile:e=!1,children:n}){const t=z(),r=G("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),i=e?xt.MOBILE_SM:hy.length-1;for(let s=0;s<i;s++)if(o>hy[s]&&o<=hy[s+1])return s;return i},[t]);return h.jsx(eA.Provider,{value:r,children:n})}function Nn(){const e=x.useContext(eA);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function qq(){const{addToast:e,removeToast:n,clearToasts:t}=Gr(),{addDialog:r,clearDialogs:o,removeDialog:i,updateDialog:s}=qs(),c=Nn()<xt.TABLET_SM,l=Me();return x.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:i,updateDialog:s,msg:l,isMobile:c}),[r,e,o,t,l,i,n,s,c])}function Zq(e,n){const t={};for(const r of e)if(r.translations)for(const[o,i]of Mn(r.translations)){let s=t[o];s||(s=t[o]={}),Object.assign(s,i)}return{actions:(r,o)=>{for(const i of e)i.actions&&(o=i.actions(r,o,n));return o},tools:(r,o,i)=>{for(const s of e)s.tools&&(o=s.tools(r,o,{...n,...i}));return o},translations:t}}function tA(e){return x.useMemo(()=>e,e)}function Qq(e){const n=tA(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,i]of Mn(r.translations)){let s=t[o];s||(s=t[o]={}),Object.assign(s,i)}return t},[n])}function Jq(e){const n=qq(),t=tA(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>Zq(t,n),[t,n])}function eZ(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 i=e.getSortedChildIdsForParent(o.id);i.length&&(e.reparentShapes(i,o.parentId,o.index),r.push(...i))}),e.setSelectedShapes(r),e.deleteShapes(n)})}const tZ=50;function nZ(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),i=ye(o.map(p=>e.getShape(p)));if(!i.length)return;const s=J.FromPoints(i.flatMap(p=>{const S=e.getShapeGeometry(p.id);return e.getShapeLocalTransform(p).applyToPoints(S.vertices)})),{padding:a=tZ}=t,c=s.w+2*a,l=s.h+2*a,u=a-s.minX,d=a-s.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(S=>{const m=e.getShape(S);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 fI(e){return nr.isValid(e)?{isValid:!0,hasProtocol:!0}:nr.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const rZ=ir(function({onClose:n}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?h.jsx(oZ,{onClose:n,selectedShape:r}):null}),oZ=ir(function({onClose:n,selectedShape:t}){const r=z(),o=Me(),i=x.useRef(null);x.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=i.current)==null?void 0:S.focus()})},[r]);const s=x.useRef(t.props.url),[a,c]=x.useState(()=>{const S=fI(t.props.url),m=S.isValid===!0?S.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:m,safe:m,valid:!0}}),l=x.useCallback(S=>{const m=S.replace(/https?:\/\/(https?:\/\/)/,(v,P)=>P),w=fI(m),y=w.isValid===!0?w.hasProtocol?m:"https://"+m:"https://";c({actual:m,safe:y,valid:w.isValid})},[]),u=x.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),n())},[r,n]),d=x.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(S&&"url"in S.props&&S.props.url!==a.safe&&r.updateShapes([{id:S.id,type:S.type,props:{url:a.safe}}]),n())},[r,n,a]),f=x.useCallback(()=>{n()},[n]);if(!t)return n(),null;const p=s.current&&!a.valid;return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{children:[h.jsx(hg,{children:o("edit-link-dialog.title")}),h.jsx(fg,{})]}),h.jsx(du,{children:h.jsxs("div",{className:"tlui-edit-link-dialog",children:[h.jsx(dw,{ref:i,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(uw,{className:"tlui-dialog__footer__actions",children:[h.jsx(he,{type:"normal",onClick:f,onTouchEnd:f,children:h.jsx(Ct,{children:o("edit-link-dialog.cancel")})}),p?h.jsx(he,{type:"danger",onTouchEnd:u,onClick:u,children:h.jsx(Ct,{children:o("edit-link-dialog.clear")})}):h.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:h.jsx(Ct,{children:o("edit-link-dialog.save")})})]})]})});var hw={exports:{}};hw.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",i={};function s(c,l){if(!i[c]){i[c]={};for(var u=0;u<c.length;u++)i[c][c.charAt(u)]=u}return i[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 s(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 s(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={},S={},m="",w="",y="",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++,S[m]=!0),w=y+m,Object.prototype.hasOwnProperty.call(p,w))y=w;else{if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(d=0;d<E;d++)I=I<<1,_==l-1?(_=0,C.push(u(I)),I=0):_++;for(f=y.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=y.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 S[y]}else for(f=p[y],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++,y=String(m)}if(y!==""){if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(d=0;d<E;d++)I=I<<1,_==l-1?(_=0,C.push(u(I)),I=0):_++;for(f=y.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=y.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 S[y]}else for(f=p[y],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,S=3,m="",w=[],y,v,P,E,C,I,_,k={val:u(0),position:l,index:1};for(y=0;y<3;y+=1)d[y]=y;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,S),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,S),S++),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,S),S++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(hw);var iZ=hw.exports;const nA=Ki(iZ);async function sZ(e,n,t){var y,v,P;const{elements:r,files:o}=n,i={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},s=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=MN;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:aZ(E.opacity),meta:{}};switch(E.angle!==0&&a.set(C,E.angle),E.groupIds&&E.groupIds.length>0?s.has(E.groupIds[0])?(y=s.get(E.groupIds[0]))==null||y.push(C):s.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 A=r.find(N=>N.id===T.id);A&&(_=A.text,k=fZ[A.textAlign])}}const $=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;i.shapes.push({...I,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:Xd[E.strokeWidth]??"draw",color:il[$]??"black",text:_,align:k,dash:qd(E),fill:mZ(E)}});break}case"freedraw":{i.shapes.push({...I,type:"draw",props:{dash:qd(E),size:Xd[E.strokeWidth],color:il[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=Nl(E.points.length);i.shapes.push({...I,type:"line",props:{dash:qd(E),size:Xd[E.strokeWidth],color:il[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([$,T],A)=>{const N=k[A];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 j=r.find(O=>O.id===N.id);j&&(_=j.text)}}const k=E.points[0],$=E.points[E.points.length-1],T=l.get((v=E.startBinding)==null?void 0:v.elementId),A=l.get((P=E.endBinding)==null?void 0:P.elementId);i.shapes.push({...I,type:"arrow",props:{text:_,bend:gZ(E,k,$),dash:qd(E),size:Xd[E.strokeWidth]??"m",color:il[E.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:$[0],y:$[1]},arrowheadEnd:pI[E.endArrowhead]??"none",arrowheadStart:pI[E.startArrowhead]??"none"}}),T&&i.bindings.push({id:ws(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),A&&i.bindings.push({id:ws(),typeName:"binding",type:"arrow",fromId:C,toId:A,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:_,scale:k}=lZ(E.fontSize);i.shapes.push({...I,type:"text",props:{size:_,scale:k,font:uZ[E.fontFamily]??"draw",color:il[E.strokeColor]??"black",text:E.text,textAlign:pZ[E.textAlign]}});break}case"image":{const _=o[E.fileId];if(!_)break;const k=fs.createId();i.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:{}}),i.shapes.push({...I,type:"image",props:{w:E.width,h:E.height,assetId:k}})}}f=Do(f)}const p=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(i,{point:p,select:!1,preserveIds:!0});for(const E of s.values())if(E.length>1){e.groupShapes(E);const C=e.getShape(E[0]);C!=null&&C.parentId&&gr(C.parentId)&&u.push(C.parentId)}for(const[E,C]of a)e.select(E),e.rotateShapesBy([E],C);const S=ye(u.map(E=>e.getShape(E))),m=J.Common(S.map(E=>e.getShapePageBounds(E))),w=e.getViewportPageBounds().center;e.updateShapes(S.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 aZ=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},Xd={1:"s",2:"m",3:"l",4:"xl"},cZ={16:"s",20:"m",28:"l",36:"xl"};function lZ(e){const n=cZ[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 uZ={1:"draw",2:"sans",3:"mono"},il={"#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"},dZ={solid:"draw",dashed:"dashed",dotted:"dotted"},hZ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},fZ={left:"start",center:"middle",right:"end"},pZ={left:"start",center:"middle",right:"end"},pI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function gZ(e,n,t){let r=0;if(e.points.length>2){const o=new b(n[0],n[1]),i=new b(t[0],t[1]),s=new b(e.points[1][0],e.points[1][1]),a=b.Sub(i,o),c=b.Per(a),l=b.Med(i,o),u=b.Sub(l,c),d=b.Add(l,c),f=b.NearestPointOnLineSegment(u,d,s,!1);r=b.Dist(f,l),b.Clockwise(f,i,l)&&(r*=-1)}return r}const qd=e=>{let n=dZ[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},mZ=e=>e.backgroundColor==="transparent"?"none":hZ[e.fillStyle]??"solid";async function rA(e,n,t,r){const i=(await Promise.all(n.map(async s=>await(await fetch(s,{referrerPolicy:"strict-origin-when-cross-origin"})).blob()))).map(s=>new File([s],"tldrawFile",{type:s.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:i,point:t,ignoreParent:!1,sources:r}),n.forEach(s=>URL.revokeObjectURL(s))}function yZ(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 i=e.getSelectionPageBounds();o&&i&&(o!=null&&o.collides(i))&&(e.updateInstanceState({isChangingStyle:!0}),e.timers.setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))}async function Mv(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",referrerPolicy:"strict-origin-when-cross-origin"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),rA(e,[n]);return}}catch(i){i.message!=="Failed to fetch"&&console.error(i)}return e.mark("paste"),await e.putExternalContent({type:"url",point:t,url:n,sources:r})}function SZ(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const vZ=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},xZ=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 _k(n)},wZ=e=>/^<svg/.test(e),bZ=["input","select","textarea"];function fy(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||bZ.indexOf(n.tagName.toLowerCase())>-1)}const PZ=e=>e.types.find(n=>n.match(/^image\//)),py=(e,n,t,r)=>{const o=xZ(n);if(o)for(const i of o)Mv(e,i,t);else vZ(n)?Mv(e,n,t):wZ(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}))},CZ=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(i=>i(o.getAsFile()))});break}case"string":{o.type==="text/html"?r.push({type:"html",source:new Promise(i=>o.getAsString(i))}):o.type==="text/plain"?r.push({type:"text",source:new Promise(i=>o.getAsString(i))}):r.push({type:o.type,source:new Promise(i=>o.getAsString(i))});break}}iA(e,r,t)},oA=async(e,n,t)=>{const r=[];for(const o of n){if(PZ(o))for(const i of o.types)i.match(/^image\//)&&r.push({type:"blob",source:o.getType(i)});o.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const i=await o.getType("text/html");return await za.blobToText(i)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const i=await o.getType("text/uri-list");return await za.blobToText(i)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const i=await o.getType("text/plain");return await za.blobToText(i)})()})}return await iA(e,r,t)};async function iA(e,n,t){const r=n.filter(i=>(i.type==="file"||i.type==="blob")&&i.source!==null);if(r.length){const s=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await rA(e,s,t)}const o=await Promise.all(n.filter(i=>i.type!=="file").map(i=>new Promise(s=>{const a=i;if(a.type==="file"){s({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=nA.decompressFromBase64(l);if(d===null){s({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"&&s({type:"error",data:f,reason:`found tldraw data comment but JSON was of a different type: ${f.type}`}),typeof f.data=="string"){s({type:"error",data:f,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}s({type:"tldraw",data:f.data});return}}catch{s({type:"error",data:l,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){s({type:"text",data:c,subtype:"html"});return}if(a.type==="url"){s({type:"text",data:c,subtype:"url"});return}try{const d=JSON.parse(c);if(d.type==="excalidraw/clipboard"){s({type:"excalidraw",data:d});return}else{s({type:"text",data:c,subtype:"json"});return}}catch{s({type:"text",data:c,subtype:"text"});return}}s({type:"error",data:c,reason:"unhandled case"})})})));for(const i of o)if(i.type==="tldraw"){yZ(e,i.data,t);return}for(const i of o)if(i.type==="excalidraw"){sZ(e,i.data,t);return}for(const i of o)if(i.type==="text"&&i.subtype==="html"){const a=new DOMParser().parseFromString(i.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");py(e,l,t,o);return}if(!o.some(l=>l.type==="text"&&l.subtype!=="html")&&i.data.trim()){py(e,SZ(i.data),t,o);return}}for(const i of o)if(i.type==="text"&&i.subtype==="url"){Mv(e,i.data,t,o);return}for(const i of o)if(i.type==="text"&&i.subtype==="text"&&i.data.trim()){py(e,i.data,t,o);return}}const hp=e=>{var r;const n=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=nA.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:n}));if(!(typeof navigator>"u")){const o=n.shapes.map(i=>e.isShapeOfType(i,"text")||e.isShapeOfType(i,"geo")||e.isShapeOfType(i,"arrow")?i.props.text:e.isShapeOfType(i,"bookmark")||e.isShapeOfType(i,"embed")?i.props.url:null).filter(BN);if((r=navigator.clipboard)!=null&&r.write){const i=new Blob([`<tldraw>${t}</tldraw>`],{type:"text/html"});let s=o.join(" ");s===""&&(s=" "),navigator.clipboard.write([new ClipboardItem({"text/html":i,"text/plain":new Blob([s],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${t}</tldraw>`)}};function IZ(){const e=z(),n=Co(),t=x.useCallback(function(s){e.getSelectedShapeIds().length!==0&&(hp(e),n("copy",{source:s}))},[e,n]),r=x.useCallback(function(s){e.getSelectedShapeIds().length!==0&&(hp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:s}))},[e,n]),o=x.useCallback(async function(s,a,c){e.getEditingShapeId()===null&&(Array.isArray(s)&&s[0]instanceof ClipboardItem?(oA(e,s,c),n("paste",{source:"menu"})):navigator.clipboard.read().then(l=>{o(l,a,c)}))},[e,n]);return{copy:t,cut:r,paste:o}}function EZ(){const e=z(),n=Co(),t=G("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!t)return;const r=c=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||fy(e)||(_e(c),hp(e),n("copy",{source:"kbd"}))};function o(c){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||fy(e)||(_e(c),hp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let i=!1;const s=c=>{c.button===1&&(i=!0,e.timers.requestAnimationFrame(()=>{i=!1}))},a=c=>{if(i){Ut(c);return}e.getEditingShapeId()!==null||fy(e)||(c.clipboardData&&!e.inputs.shiftKey?CZ(e,c.clipboardData):navigator.clipboard.read().then(l=>{Array.isArray(l)&&l[0]instanceof ClipboardItem&&oA(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",s),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",s)}},[e,n,t])}async function sA(e,n,t){const{type:r,quality:o,scale:i,width:s,height:a}=t;let[c,l]=await m$(s*i,a*i);c=Math.floor(c),l=Math.floor(l);const u=c/s,d=URL.createObjectURL(new Blob([n],{type:"image/svg+xml"})),f=await new Promise(S=>{const m=new Image;m.crossOrigin="anonymous",m.onload=async()=>{e.environment.isSafari&&await new Promise(v=>e.timers.setTimeout(v,250));const w=document.createElement("canvas"),y=w.getContext("2d");w.width=c,w.height=l,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(m,0,0,c,l),URL.revokeObjectURL(d),S(w)},m.onerror=()=>{S(null)},m.referrerPolicy="strict-origin-when-cross-origin",m.src=d});if(!f)return null;const p=await new Promise(S=>f.toBlob(m=>{(!m||bt.throwToBlob.get())&&S(null),S(m)},"image/"+r,o));if(!p)return null;if(r==="png"){const S=new DataView(await p.arrayBuffer());return Jr.setPhysChunk(S,u,{type:"image/"+r})}else return p}async function aA(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 Av(e,n,t,r={}){var o;switch(t){case"svg":return(o=await aA(e,n,r))==null?void 0:o.svg;case"json":{const i=e.getContentFromCurrentPage(n);return JSON.stringify(i)}default:nn(t)}}async function cA({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await Av(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Av(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await aA(e,n,r);if(!o)throw new Error("Could not construct image.");const i=await sA(e,o.svg,{type:t,quality:1,scale:2,width:o.width,height:o.height});if(!i)throw new Error("Could not construct image.");return i}default:nn(t)}}const _Z={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function kZ(e,n,t,r={}){return{blobPromise:cA({editor:e,ids:n,format:t,opts:r}),mimeType:_Z[t]}}function TZ(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:i}=kZ(e,n,t,r);return window.navigator.clipboard.write([new ClipboardItem({[i]:o})]).catch(s=>(console.error(s),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[i]:a})]))))}switch(t){case"json":case"svg":return $Z(async()=>Av(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:nn(t)}}async function $Z(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}function MZ(){const e=z(),{addToast:n}=Gr(),t=Me();return x.useCallback((r,o="svg")=>{TZ(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 AZ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${gI()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${gI()}`}r+=`.${t}`;const i=await cA({editor:e,ids:n,format:t,opts:o}),s=new File([i],r,{type:i.type});jZ(s)}function gI(){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"),i=String(e.getMinutes()).padStart(2,"0"),s=String(e.getSeconds()).padStart(2,"0");return`${n}-${t}-${r} ${o}.${i}.${s}`}function jZ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function OZ(){const e=z(),{addToast:n}=Gr(),t=Me();return x.useCallback((r,o="png",i)=>{AZ(e,r,o,i,{scale:1,background:e.getInstanceState().exportBackground}).catch(s=>{console.error(s.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 DZ(){const e=z(),n=x.useRef(null),t=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),i=document.createElement("style"),s=(y,v)=>{y&&(y.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),y&&document.body.contains(y)&&document.body.removeChild(y)};s(n.current,t.current),n.current=o,t.current=i;const a=`tl-print-surface-${ot()}`;o.className=a,i.innerHTML=`
199
- .${a} {
200
- display: none;
201
- }
202
-
203
- .${a} svg {
204
- max-width: 100%;
205
- height: 100%;
206
- display: block;
207
- }
208
-
209
- @media print {
210
- html, body {
211
- min-height: 100%;
212
- height: 100%;
213
- margin: 0;
214
- }
215
-
216
- body {
217
- position: relative;
218
- }
219
-
220
- body > * {
221
- display: none;
222
- }
223
-
224
- .tldraw__editor {
225
- display: none;
226
- }
227
-
228
- .${a} {
229
- display: block !important;
230
- background: white;
231
- min-height: 100%;
232
- height: 100%;
233
- max-width: 100%;
234
- }
235
-
236
- .${a}__item {
237
- padding: 10mm;
238
- display: flex;
239
- min-height: 100%;
240
- flex-direction: column;
241
- page-break-after: always;
242
- position: relative;
243
- overflow: hidden;
244
- height: 100%;
245
- }
246
-
247
- .${a}__item__main {
248
- flex: 1;
249
- display: flex;
250
- align-items: center;
251
- justify-content: center;
252
- max-height: 100%;
253
- }
254
-
255
- .${a}__item__header {
256
- display: none;
257
- }
258
-
259
- .${a}__item__footer {
260
- display: none;
261
- text-align: right;
262
- }
263
-
264
- .${a}__item__footer__hide {
265
- display: none;
266
- }
267
-
268
-
269
- }
270
-
271
- `;const c=()=>{document.head.appendChild(i),document.body.appendChild(o)},l=()=>{e.once("tick",()=>{s(o,i)})};window.addEventListener("beforeprint",c),window.addEventListener("afterprint",l);function u(y,v,P){try{o.innerHTML+=`<div class="${a}__item">
272
- <div class="${a}__item__header">
273
- ${y.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
274
- </div>
275
- <div class="${a}__item__main">
276
- ${P}
277
- </div>
278
- <div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
279
- ${v??""}
280
- </div>
281
- </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(),S=e.getPages(),w={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const y=await e.getSvgString(f,w);if(y){const v=S.find(P=>P.id===p);u(`tldraw — ${v==null?void 0:v.name}`,null,y.svg),d()}}else{const y=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(y.id),w);v&&(u(`tldraw — ${y.name}`,null,v.svg),d())}window.removeEventListener("beforeprint",c),window.removeEventListener("afterprint",l)},[e])}const lA=x.createContext(null);function RZ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function fa(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function LZ({overrides:e,children:n}){const t=z(),{addDialog:r,clearDialogs:o}=qs(),{clearToasts:i}=Gr(),s=Me(),a=QM(),c=DZ(),{cut:l,copy:u,paste:d}=IZ(),f=MZ(),p=OZ(),S=s("document.default-name"),m=Co(),w=x.useMemo(()=>{function y(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function v(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const E=RZ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(C){v()&&(y()||(m("edit-link",{source:C}),t.mark("edit-link"),r({component:rZ})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(C){m("insert-embed",{source:C}),r({component:ZM})}},{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",fa(t,S)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(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",fa(t,S)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(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",fa(t,S)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(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",fa(t,S)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(C){const I=Array.from(t.getCurrentPageShapeIds().values());I.length!==0&&(m("export-all-as",{format:"png",source:C}),p(I,"png",fa(t,S)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(C){const I=Array.from(t.getCurrentPageShapeIds().values());I.length!==0&&(m("export-all-as",{format:"json",source:C}),p(I,"json",fa(t,S)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(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()||y())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}DW(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()&&(y()||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 A={id:Be(),type:"bookmark",rotation:$.rotation,x:T.x,y:T.y,opacity:1,props:{url:$.props.url}};_.push(A),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()&&(y()||(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:A}=T.props,N=Ii(T.props.url);if(!N||!N.definition)continue;const{width:j,height:O}=N.definition,R=new b(T.x,T.y);R.rot(-T.rotation),R.add(new b(T.props.w/2-j/2,T.props.h/2-O/2)),R.rot(T.rotation);const Y={id:Be(),type:"embed",x:R.x,y:R.y,rotation:T.rotation,props:{url:A,w:j,h:O}};k.push(Y),$.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()||y())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()&&(y()||(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()||y())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"),eZ(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"),nZ(t,I.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(C){if(!v()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())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()||y())return;m("pack-shapes",{source:C}),t.mark("pack");const I=t.getSelectedShapeIds();t.packShapes(I,t.options.adjacentShapeMargin),We(t,I)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(C){if(!v()||y())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()||y())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()&&(y()||(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()&&(y()||(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()&&(y()||(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()&&(y()||(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()&&(y()||(t.mark("cut"),l(C)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(C){v()&&(y()||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(()=>{y()||(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()&&(y()||(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()&&(y()||(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()||y())return;m("rotate-cw",{source:C}),t.mark("rotate-cw");const I=t.getSelectionRotation()%(Ve/2),_=Ua(I,0)||Ua(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()||y())return;m("rotate-ccw",{source:C}),t.mark("rotate-ccw");const I=t.getSelectionRotation()%(Ve/2),_=Ua(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:t.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(C){m("zoom-out",{source:C}),t.zoomOut(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(C){m("reset-zoom",{source:C}),t.resetZoom(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(C){m("zoom-to-fit",{source:C}),t.zoomToFit({animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(C){v()&&(y()||(m("zoom-to-selection",{source:C}),t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(C){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){t.timers.requestAnimationFrame(()=>{t.batch(()=>{m("toggle-focus-mode",{source:C}),o(),i(),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=Ko.createId(),_=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:s("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=rr;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,i,c,s,S]);return h.jsx(lA.Provider,{value:w,children:n})}function le(){const e=x.useContext(lA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function hu(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const FZ=["top","right","bottom","left"],oo=Math.min,Vn=Math.max,fp=Math.round,Zd=Math.floor,Ui=e=>({x:e,y:e}),NZ={left:"right",right:"left",bottom:"top",top:"bottom"},zZ={start:"end",end:"start"};function jv(e,n,t){return Vn(e,oo(n,t))}function qo(e,n){return typeof e=="function"?e(n):e}function Zo(e){return e.split("-")[0]}function $c(e){return e.split("-")[1]}function fw(e){return e==="x"?"y":"x"}function pw(e){return e==="y"?"height":"width"}function Mc(e){return["top","bottom"].includes(Zo(e))?"y":"x"}function gw(e){return fw(Mc(e))}function BZ(e,n,t){t===void 0&&(t=!1);const r=$c(e),o=gw(e),i=pw(o);let s=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[i]>n.floating[i]&&(s=pp(s)),[s,pp(s)]}function UZ(e){const n=pp(e);return[Ov(e),n,Ov(n)]}function Ov(e){return e.replace(/start|end/g,n=>zZ[n])}function HZ(e,n,t){const r=["left","right"],o=["right","left"],i=["top","bottom"],s=["bottom","top"];switch(e){case"top":case"bottom":return t?n?o:r:n?r:o;case"left":case"right":return n?i:s;default:return[]}}function KZ(e,n,t,r){const o=$c(e);let i=HZ(Zo(e),t==="start",r);return o&&(i=i.map(s=>s+"-"+o),n&&(i=i.concat(i.map(Ov)))),i}function pp(e){return e.replace(/left|right|bottom|top/g,n=>NZ[n])}function WZ(e){return{top:0,right:0,bottom:0,left:0,...e}}function uA(e){return typeof e!="number"?WZ(e):{top:e,right:e,bottom:e,left:e}}function gp(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 mI(e,n,t){let{reference:r,floating:o}=e;const i=Mc(n),s=gw(n),a=pw(s),c=Zo(n),l=i==="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($c(n)){case"start":p[s]-=f*(t&&l?-1:1);break;case"end":p[s]+=f*(t&&l?-1:1);break}return p}const GZ=async(e,n,t)=>{const{placement:r="bottom",strategy:o="absolute",middleware:i=[],platform:s}=t,a=i.filter(Boolean),c=await(s.isRTL==null?void 0:s.isRTL(n));let l=await s.getElementRects({reference:e,floating:n,strategy:o}),{x:u,y:d}=mI(l,r,c),f=r,p={},S=0;for(let m=0;m<a.length;m++){const{name:w,fn:y}=a[m],{x:v,y:P,data:E,reset:C}=await y({x:u,y:d,initialPlacement:r,placement:f,strategy:o,middlewareData:p,rects:l,platform:s,elements:{reference:e,floating:n}});u=v??u,d=P??d,p={...p,[w]:{...p[w],...E}},C&&S<=50&&(S++,typeof C=="object"&&(C.placement&&(f=C.placement),C.rects&&(l=C.rects===!0?await s.getElementRects({reference:e,floating:n,strategy:o}):C.rects),{x:u,y:d}=mI(l,f,c)),m=-1)}return{x:u,y:d,placement:f,strategy:o,middlewareData:p}};async function fu(e,n){var t;n===void 0&&(n={});const{x:r,y:o,platform:i,rects:s,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:f=!1,padding:p=0}=qo(n,e),S=uA(p),w=a[f?d==="floating"?"reference":"floating":d],y=gp(await i.getClippingRect({element:(t=await(i.isElement==null?void 0:i.isElement(w)))==null||t?w:w.contextElement||await(i.getDocumentElement==null?void 0:i.getDocumentElement(a.floating)),boundary:l,rootBoundary:u,strategy:c})),v=d==="floating"?{x:r,y:o,width:s.floating.width,height:s.floating.height}:s.reference,P=await(i.getOffsetParent==null?void 0:i.getOffsetParent(a.floating)),E=await(i.isElement==null?void 0:i.isElement(P))?await(i.getScale==null?void 0:i.getScale(P))||{x:1,y:1}:{x:1,y:1},C=gp(i.convertOffsetParentRelativeRectToViewportRelativeRect?await i.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:P,strategy:c}):v);return{top:(y.top-C.top+S.top)/E.y,bottom:(C.bottom-y.bottom+S.bottom)/E.y,left:(y.left-C.left+S.left)/E.x,right:(C.right-y.right+S.right)/E.x}}const VZ=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:i,platform:s,elements:a,middlewareData:c}=n,{element:l,padding:u=0}=qo(e,n)||{};if(l==null)return{};const d=uA(u),f={x:t,y:r},p=gw(o),S=pw(p),m=await s.getDimensions(l),w=p==="y",y=w?"top":"left",v=w?"bottom":"right",P=w?"clientHeight":"clientWidth",E=i.reference[S]+i.reference[p]-f[p]-i.floating[S],C=f[p]-i.reference[p],I=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l));let _=I?I[P]:0;(!_||!await(s.isElement==null?void 0:s.isElement(I)))&&(_=a.floating[P]||i.floating[S]);const k=E/2-C/2,$=_/2-m[S]/2-1,T=oo(d[y],$),A=oo(d[v],$),N=T,j=_-m[S]-A,O=_/2-m[S]/2+k,R=jv(N,O,j),Y=!c.arrow&&$c(o)!=null&&O!==R&&i.reference[S]/2-(O<N?T:A)-m[S]/2<0,K=Y?O<N?O-N:O-j:0;return{[p]:f[p]+K,data:{[p]:R,centerOffset:O-R-K,...Y&&{alignmentOffset:K}},reset:Y}}}),YZ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var t,r;const{placement:o,middlewareData:i,rects:s,initialPlacement:a,platform:c,elements:l}=n,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:m=!0,...w}=qo(e,n);if((t=i.arrow)!=null&&t.alignmentOffset)return{};const y=Zo(o),v=Zo(a)===a,P=await(c.isRTL==null?void 0:c.isRTL(l.floating)),E=f||(v||!m?[pp(a)]:UZ(a));!f&&S!=="none"&&E.push(...KZ(a,m,S,P));const C=[a,...E],I=await fu(n,w),_=[];let k=((r=i.flip)==null?void 0:r.overflows)||[];if(u&&_.push(I[y]),d){const N=BZ(o,s,P);_.push(I[N[0]],I[N[1]])}if(k=[...k,{placement:o,overflows:_}],!_.every(N=>N<=0)){var $,T;const N=((($=i.flip)==null?void 0:$.index)||0)+1,j=C[N];if(j)return{data:{index:N,overflows:k},reset:{placement:j}};let O=(T=k.filter(R=>R.overflows[0]<=0).sort((R,Y)=>R.overflows[1]-Y.overflows[1])[0])==null?void 0:T.placement;if(!O)switch(p){case"bestFit":{var A;const R=(A=k.map(Y=>[Y.placement,Y.overflows.filter(K=>K>0).reduce((K,U)=>K+U,0)]).sort((Y,K)=>Y[1]-K[1])[0])==null?void 0:A[0];R&&(O=R);break}case"initialPlacement":O=a;break}if(o!==O)return{reset:{placement:O}}}return{}}}};function yI(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function SI(e){return FZ.some(n=>e[n]>=0)}const XZ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=qo(e,n);switch(r){case"referenceHidden":{const i=await fu(n,{...o,elementContext:"reference"}),s=yI(i,t.reference);return{data:{referenceHiddenOffsets:s,referenceHidden:SI(s)}}}case"escaped":{const i=await fu(n,{...o,altBoundary:!0}),s=yI(i,t.floating);return{data:{escapedOffsets:s,escaped:SI(s)}}}default:return{}}}}};async function qZ(e,n){const{placement:t,platform:r,elements:o}=e,i=await(r.isRTL==null?void 0:r.isRTL(o.floating)),s=Zo(t),a=$c(t),c=Mc(t)==="y",l=["left","top"].includes(s)?-1:1,u=i&&c?-1:1,d=qo(n,e);let{mainAxis:f,crossAxis:p,alignmentAxis:S}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...d};return a&&typeof S=="number"&&(p=a==="end"?S*-1:S),c?{x:p*u,y:f*l}:{x:f*l,y:p*u}}const ZZ=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var t,r;const{x:o,y:i,placement:s,middlewareData:a}=n,c=await qZ(n,e);return s===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:i+c.y,data:{...c,placement:s}}}}},QZ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:t,y:r,placement:o}=n,{mainAxis:i=!0,crossAxis:s=!1,limiter:a={fn:w=>{let{x:y,y:v}=w;return{x:y,y:v}}},...c}=qo(e,n),l={x:t,y:r},u=await fu(n,c),d=Mc(Zo(o)),f=fw(d);let p=l[f],S=l[d];if(i){const w=f==="y"?"top":"left",y=f==="y"?"bottom":"right",v=p+u[w],P=p-u[y];p=jv(v,p,P)}if(s){const w=d==="y"?"top":"left",y=d==="y"?"bottom":"right",v=S+u[w],P=S-u[y];S=jv(v,S,P)}const m=a.fn({...n,[f]:p,[d]:S});return{...m,data:{x:m.x-t,y:m.y-r}}}}},JZ=function(e){return e===void 0&&(e={}),{options:e,fn(n){const{x:t,y:r,placement:o,rects:i,middlewareData:s}=n,{offset:a=0,mainAxis:c=!0,crossAxis:l=!0}=qo(e,n),u={x:t,y:r},d=Mc(o),f=fw(d);let p=u[f],S=u[d];const m=qo(a,n),w=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(c){const P=f==="y"?"height":"width",E=i.reference[f]-i.floating[P]+w.mainAxis,C=i.reference[f]+i.reference[P]-w.mainAxis;p<E?p=E:p>C&&(p=C)}if(l){var y,v;const P=f==="y"?"width":"height",E=["top","left"].includes(Zo(o)),C=i.reference[d]-i.floating[P]+(E&&((y=s.offset)==null?void 0:y[d])||0)+(E?0:w.crossAxis),I=i.reference[d]+i.reference[P]+(E?0:((v=s.offset)==null?void 0:v[d])||0)-(E?w.crossAxis:0);S<C?S=C:S>I&&(S=I)}return{[f]:p,[d]:S}}}},eQ=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:t,rects:r,platform:o,elements:i}=n,{apply:s=()=>{},...a}=qo(e,n),c=await fu(n,a),l=Zo(t),u=$c(t),d=Mc(t)==="y",{width:f,height:p}=r.floating;let S,m;l==="top"||l==="bottom"?(S=l,m=u===(await(o.isRTL==null?void 0:o.isRTL(i.floating))?"start":"end")?"left":"right"):(m=l,S=u==="end"?"top":"bottom");const w=p-c.top-c.bottom,y=f-c.left-c.right,v=oo(p-c[S],w),P=oo(f-c[m],y),E=!n.middlewareData.shift;let C=v,I=P;if(d?I=u||E?oo(P,y):y:C=u||E?oo(v,w):w,E&&!u){const k=Vn(c.left,0),$=Vn(c.right,0),T=Vn(c.top,0),A=Vn(c.bottom,0);d?I=f-2*(k!==0||$!==0?k+$:Vn(c.left,c.right)):C=p-2*(T!==0||A!==0?T+A:Vn(c.top,c.bottom))}await s({...n,availableWidth:I,availableHeight:C});const _=await o.getDimensions(i.floating);return f!==_.width||p!==_.height?{reset:{rects:!0}}:{}}}};function Ac(e){return dA(e)?(e.nodeName||"").toLowerCase():"#document"}function tr(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function oi(e){var n;return(n=(dA(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function dA(e){return e instanceof Node||e instanceof tr(e).Node}function go(e){return e instanceof Element||e instanceof tr(e).Element}function mo(e){return e instanceof HTMLElement||e instanceof tr(e).HTMLElement}function vI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof tr(e).ShadowRoot}function Uu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=Hr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function tQ(e){return["table","td","th"].includes(Ac(e))}function mw(e){const n=yw(),t=Hr(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 nQ(e){let n=Hi(e);for(;mo(n)&&!mc(n);){if(mw(n))return n;n=Hi(n)}return null}function yw(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function mc(e){return["html","body","#document"].includes(Ac(e))}function Hr(e){return tr(e).getComputedStyle(e)}function gg(e){return go(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Hi(e){if(Ac(e)==="html")return e;const n=e.assignedSlot||e.parentNode||vI(e)&&e.host||oi(e);return vI(n)?n.host:n}function hA(e){const n=Hi(e);return mc(n)?e.ownerDocument?e.ownerDocument.body:e.body:mo(n)&&Uu(n)?n:hA(n)}function pu(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=hA(e),i=o===((r=e.ownerDocument)==null?void 0:r.body),s=tr(o);return i?n.concat(s,s.visualViewport||[],Uu(o)?o:[],s.frameElement&&t?pu(s.frameElement):[]):n.concat(o,pu(o,[],t))}function fA(e){const n=Hr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=mo(e),i=o?e.offsetWidth:t,s=o?e.offsetHeight:r,a=fp(t)!==i||fp(r)!==s;return a&&(t=i,r=s),{width:t,height:r,$:a}}function Sw(e){return go(e)?e:e.contextElement}function ec(e){const n=Sw(e);if(!mo(n))return Ui(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:i}=fA(n);let s=(i?fp(t.width):t.width)/r,a=(i?fp(t.height):t.height)/o;return(!s||!Number.isFinite(s))&&(s=1),(!a||!Number.isFinite(a))&&(a=1),{x:s,y:a}}const rQ=Ui(0);function pA(e){const n=tr(e);return!yw()||!n.visualViewport?rQ:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function oQ(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==tr(e)?!1:n}function Ns(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),i=Sw(e);let s=Ui(1);n&&(r?go(r)&&(s=ec(r)):s=ec(e));const a=oQ(i,t,r)?pA(i):Ui(0);let c=(o.left+a.x)/s.x,l=(o.top+a.y)/s.y,u=o.width/s.x,d=o.height/s.y;if(i){const f=tr(i),p=r&&go(r)?tr(r):r;let S=f,m=S.frameElement;for(;m&&r&&p!==S;){const w=ec(m),y=m.getBoundingClientRect(),v=Hr(m),P=y.left+(m.clientLeft+parseFloat(v.paddingLeft))*w.x,E=y.top+(m.clientTop+parseFloat(v.paddingTop))*w.y;c*=w.x,l*=w.y,u*=w.x,d*=w.y,c+=P,l+=E,S=tr(m),m=S.frameElement}}return gp({width:u,height:d,x:c,y:l})}const iQ=[":popover-open",":modal"];function vw(e){return iQ.some(n=>{try{return e.matches(n)}catch{return!1}})}function sQ(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const i=o==="fixed",s=oi(r),a=n?vw(n.floating):!1;if(r===s||a&&i)return t;let c={scrollLeft:0,scrollTop:0},l=Ui(1);const u=Ui(0),d=mo(r);if((d||!d&&!i)&&((Ac(r)!=="body"||Uu(s))&&(c=gg(r)),mo(r))){const f=Ns(r);l=ec(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 aQ(e){return Array.from(e.getClientRects())}function gA(e){return Ns(oi(e)).left+gg(e).scrollLeft}function cQ(e){const n=oi(e),t=gg(e),r=e.ownerDocument.body,o=Vn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),i=Vn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let s=-t.scrollLeft+gA(e);const a=-t.scrollTop;return Hr(r).direction==="rtl"&&(s+=Vn(n.clientWidth,r.clientWidth)-o),{width:o,height:i,x:s,y:a}}function lQ(e,n){const t=tr(e),r=oi(e),o=t.visualViewport;let i=r.clientWidth,s=r.clientHeight,a=0,c=0;if(o){i=o.width,s=o.height;const l=yw();(!l||l&&n==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:i,height:s,x:a,y:c}}function uQ(e,n){const t=Ns(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,i=mo(e)?ec(e):Ui(1),s=e.clientWidth*i.x,a=e.clientHeight*i.y,c=o*i.x,l=r*i.y;return{width:s,height:a,x:c,y:l}}function xI(e,n,t){let r;if(n==="viewport")r=lQ(e,t);else if(n==="document")r=cQ(oi(e));else if(go(n))r=uQ(n,t);else{const o=pA(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return gp(r)}function mA(e,n){const t=Hi(e);return t===n||!go(t)||mc(t)?!1:Hr(t).position==="fixed"||mA(t,n)}function dQ(e,n){const t=n.get(e);if(t)return t;let r=pu(e,[],!1).filter(a=>go(a)&&Ac(a)!=="body"),o=null;const i=Hr(e).position==="fixed";let s=i?Hi(e):e;for(;go(s)&&!mc(s);){const a=Hr(s),c=mw(s);!c&&a.position==="fixed"&&(o=null),(i?!c&&!o:!c&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Uu(s)&&!c&&mA(e,s))?r=r.filter(u=>u!==s):o=a,s=Hi(s)}return n.set(e,r),r}function hQ(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const s=[...t==="clippingAncestors"?vw(n)?[]:dQ(n,this._c):[].concat(t),r],a=s[0],c=s.reduce((l,u)=>{const d=xI(n,u,o);return l.top=Vn(d.top,l.top),l.right=oo(d.right,l.right),l.bottom=oo(d.bottom,l.bottom),l.left=Vn(d.left,l.left),l},xI(n,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function fQ(e){const{width:n,height:t}=fA(e);return{width:n,height:t}}function pQ(e,n,t){const r=mo(n),o=oi(n),i=t==="fixed",s=Ns(e,!0,i,n);let a={scrollLeft:0,scrollTop:0};const c=Ui(0);if(r||!r&&!i)if((Ac(n)!=="body"||Uu(o))&&(a=gg(n)),r){const d=Ns(n,!0,i,n);c.x=d.x+n.clientLeft,c.y=d.y+n.clientTop}else o&&(c.x=gA(o));const l=s.left+a.scrollLeft-c.x,u=s.top+a.scrollTop-c.y;return{x:l,y:u,width:s.width,height:s.height}}function gy(e){return Hr(e).position==="static"}function wI(e,n){return!mo(e)||Hr(e).position==="fixed"?null:n?n(e):e.offsetParent}function yA(e,n){const t=tr(e);if(vw(e))return t;if(!mo(e)){let o=Hi(e);for(;o&&!mc(o);){if(go(o)&&!gy(o))return o;o=Hi(o)}return t}let r=wI(e,n);for(;r&&tQ(r)&&gy(r);)r=wI(r,n);return r&&mc(r)&&gy(r)&&!mw(r)?t:r||nQ(e)||t}const gQ=async function(e){const n=this.getOffsetParent||yA,t=this.getDimensions,r=await t(e.floating);return{reference:pQ(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function mQ(e){return Hr(e).direction==="rtl"}const yQ={convertOffsetParentRelativeRectToViewportRelativeRect:sQ,getDocumentElement:oi,getClippingRect:hQ,getOffsetParent:yA,getElementRects:gQ,getClientRects:aQ,getDimensions:fQ,getScale:ec,isElement:go,isRTL:mQ};function SQ(e,n){let t=null,r;const o=oi(e);function i(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function s(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),i();const{left:l,top:u,width:d,height:f}=e.getBoundingClientRect();if(a||n(),!d||!f)return;const p=Zd(u),S=Zd(o.clientWidth-(l+d)),m=Zd(o.clientHeight-(u+f)),w=Zd(l),v={rootMargin:-p+"px "+-S+"px "+-m+"px "+-w+"px",threshold:Vn(0,oo(1,c))||1};let P=!0;function E(C){const I=C[0].intersectionRatio;if(I!==c){if(!P)return s();I?s(!1,I):r=setTimeout(()=>{s(!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 s(!0),i}function vQ(e,n,t,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:i=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,l=Sw(e),u=o||i?[...l?pu(l):[],...pu(n)]:[];u.forEach(y=>{o&&y.addEventListener("scroll",t,{passive:!0}),i&&y.addEventListener("resize",t)});const d=l&&a?SQ(l,t):null;let f=-1,p=null;s&&(p=new ResizeObserver(y=>{let[v]=y;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 S,m=c?Ns(e):null;c&&w();function w(){const y=Ns(e);m&&(y.x!==m.x||y.y!==m.y||y.width!==m.width||y.height!==m.height)&&t(),m=y,S=requestAnimationFrame(w)}return t(),()=>{var y;u.forEach(v=>{o&&v.removeEventListener("scroll",t),i&&v.removeEventListener("resize",t)}),d==null||d(),(y=p)==null||y.disconnect(),p=null,c&&cancelAnimationFrame(S)}}const xQ=ZZ,wQ=QZ,bQ=YZ,PQ=eQ,CQ=XZ,bI=VZ,IQ=JZ,EQ=(e,n,t)=>{const r=new Map,o={platform:yQ,...t},i={...o.platform,_c:r};return GZ(e,n,{...o,platform:i})};var of=typeof document<"u"?x.useLayoutEffect:x.useEffect;function mp(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(!mp(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 i=o[r];if(!(i==="_owner"&&e.$$typeof)&&!mp(e[i],n[i]))return!1}return!0}return e!==e&&n!==n}function SA(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function PI(e,n){const t=SA(e);return Math.round(n*t)/t}function CI(e){const n=x.useRef(e);return of(()=>{n.current=e}),n}function _Q(e){e===void 0&&(e={});const{placement:n="bottom",strategy:t="absolute",middleware:r=[],platform:o,elements:{reference:i,floating:s}={},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);mp(f,r)||p(r);const[S,m]=x.useState(null),[w,y]=x.useState(null),v=x.useCallback(K=>{K!==I.current&&(I.current=K,m(K))},[]),P=x.useCallback(K=>{K!==_.current&&(_.current=K,y(K))},[]),E=i||S,C=s||w,I=x.useRef(null),_=x.useRef(null),k=x.useRef(u),$=c!=null,T=CI(c),A=CI(o),N=x.useCallback(()=>{if(!I.current||!_.current)return;const K={placement:n,strategy:t,middleware:f};A.current&&(K.platform=A.current),EQ(I.current,_.current,K).then(U=>{const H={...U,isPositioned:!0};j.current&&!mp(k.current,H)&&(k.current=H,Xs.flushSync(()=>{d(H)}))})},[f,n,t,A]);of(()=>{l===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,d(K=>({...K,isPositioned:!1})))},[l]);const j=x.useRef(!1);of(()=>(j.current=!0,()=>{j.current=!1}),[]),of(()=>{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 O=x.useMemo(()=>({reference:I,floating:_,setReference:v,setFloating:P}),[v,P]),R=x.useMemo(()=>({reference:E,floating:C}),[E,C]),Y=x.useMemo(()=>{const K={position:t,left:0,top:0};if(!R.floating)return K;const U=PI(R.floating,u.x),H=PI(R.floating,u.y);return a?{...K,transform:"translate("+U+"px, "+H+"px)",...SA(R.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:U,top:H}},[t,a,R.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:N,refs:O,elements:R,floatingStyles:Y}),[u,N,O,R,Y])}const kQ=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?bI({element:r.current,padding:o}).fn(t):{}:r?bI({element:r,padding:o}).fn(t):{}}}},TQ=(e,n)=>({...xQ(e),options:[e,n]}),$Q=(e,n)=>({...wQ(e),options:[e,n]}),MQ=(e,n)=>({...IQ(e),options:[e,n]}),AQ=(e,n)=>({...bQ(e),options:[e,n]}),jQ=(e,n)=>({...PQ(e),options:[e,n]}),OQ=(e,n)=>({...CQ(e),options:[e,n]}),DQ=(e,n)=>({...kQ(e),options:[e,n]});function vA(e){const[n,t]=x.useState(void 0);return Ls(()=>{if(e){t({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const i=o[0];let s,a;if("borderBoxSize"in i){const c=i.borderBoxSize,l=Array.isArray(c)?c[0]:c;s=l.inlineSize,a=l.blockSize}else s=e.offsetWidth,a=e.offsetHeight;t({width:s,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else t(void 0)},[e]),n}const xA="Popper",[wA,mg]=bo(xA),[RQ,bA]=wA(xA),LQ=e=>{const{__scopePopper:n,children:t}=e,[r,o]=x.useState(null);return x.createElement(RQ,{scope:n,anchor:r,onAnchorChange:o},t)},FQ="PopperAnchor",NQ=x.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,i=bA(FQ,t),s=x.useRef(null),a=Xe(n,s);return x.useEffect(()=>{i.onAnchorChange((r==null?void 0:r.current)||s.current)}),r?null:x.createElement(He.div,Q({},o,{ref:a}))}),PA="PopperContent",[zQ,Hoe]=wA(PA),BQ=x.forwardRef((e,n)=>{var t,r,o,i,s,a,c,l;const{__scopePopper:u,side:d="bottom",sideOffset:f=0,align:p="center",alignOffset:S=0,arrowPadding:m=0,avoidCollisions:w=!0,collisionBoundary:y=[],collisionPadding:v=0,sticky:P="partial",hideWhenDetached:E=!1,updatePositionStrategy:C="optimized",onPlaced:I,..._}=e,k=bA(PA,u),[$,T]=x.useState(null),A=Xe(n,qe=>T(qe)),[N,j]=x.useState(null),O=vA(N),R=(t=O==null?void 0:O.width)!==null&&t!==void 0?t:0,Y=(r=O==null?void 0:O.height)!==null&&r!==void 0?r:0,K=d+(p!=="center"?"-"+p:""),U=typeof v=="number"?v:{top:0,right:0,bottom:0,left:0,...v},H=Array.isArray(y)?y:[y],W=H.length>0,Z={padding:U,boundary:H.filter(UQ),altBoundary:W},{refs:oe,floatingStyles:be,placement:Ae,isPositioned:ce,middlewareData:je}=_Q({strategy:"fixed",placement:K,whileElementsMounted:(...qe)=>vQ(...qe,{animationFrame:C==="always"}),elements:{reference:k.anchor},middleware:[TQ({mainAxis:f+Y,alignmentAxis:S}),w&&$Q({mainAxis:!0,crossAxis:!1,limiter:P==="partial"?MQ():void 0,...Z}),w&&AQ({...Z}),jQ({...Z,apply:({elements:qe,rects:Ot,availableWidth:_o,availableHeight:Oc})=>{const{width:Dc,height:Pg}=Ot.reference,Qs=qe.floating.style;Qs.setProperty("--radix-popper-available-width",`${_o}px`),Qs.setProperty("--radix-popper-available-height",`${Oc}px`),Qs.setProperty("--radix-popper-anchor-width",`${Dc}px`),Qs.setProperty("--radix-popper-anchor-height",`${Pg}px`)}}),N&&DQ({element:N,padding:m}),HQ({arrowWidth:R,arrowHeight:Y}),E&&OQ({strategy:"referenceHidden",...Z})]}),[Le,at]=CA(Ae),Ie=cn(I);Ls(()=>{ce&&(Ie==null||Ie())},[ce,Ie]);const pt=(o=je.arrow)===null||o===void 0?void 0:o.x,Ue=(i=je.arrow)===null||i===void 0?void 0:i.y,lr=((s=je.arrow)===null||s===void 0?void 0:s.centerOffset)!==0,[zn,Bn]=x.useState();return Ls(()=>{$&&Bn(window.getComputedStyle($).zIndex)},[$]),x.createElement("div",{ref:oe.setFloating,"data-radix-popper-content-wrapper":"",style:{...be,transform:ce?be.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:zn,"--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(zQ,{scope:u,placedSide:Le,onArrowChange:j,arrowX:pt,arrowY:Ue,shouldHideArrow:lr},x.createElement(He.div,Q({"data-side":Le,"data-align":at},_,{ref:A,style:{..._.style,animation:ce?void 0:"none",opacity:(l=je.hide)!==null&&l!==void 0&&l.referenceHidden?0:void 0}}))))});function UQ(e){return e!==null}const HQ=e=>({name:"transformOrigin",options:e,fn(n){var t,r,o,i,s;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,[S,m]=CA(a),w={start:"0%",center:"50%",end:"100%"}[m],y=((r=(o=l.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+f/2,v=((i=(s=l.arrow)===null||s===void 0?void 0:s.y)!==null&&i!==void 0?i:0)+p/2;let P="",E="";return S==="bottom"?(P=d?w:`${y}px`,E=`${-p}px`):S==="top"?(P=d?w:`${y}px`,E=`${c.floating.height+p}px`):S==="right"?(P=`${-p}px`,E=d?w:`${v}px`):S==="left"&&(P=`${c.floating.width+p}px`,E=d?w:`${v}px`),{data:{x:P,y:E}}}});function CA(e){const[n,t="center"]=e.split("-");return[n,t]}const xw=LQ,IA=NQ,EA=BQ,_A="Popover",[kA,Koe]=bo(_A,[mg]),ww=mg(),[KQ,jc]=kA(_A),WQ=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:i,modal:s=!1}=e,a=ww(n),c=x.useRef(null),[l,u]=x.useState(!1),[d=!1,f]=Qi({prop:r,defaultProp:o,onChange:i});return x.createElement(xw,a,x.createElement(KQ,{scope:n,contentId:Ho(),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:s},t))},GQ="PopoverTrigger",VQ=x.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=jc(GQ,t),i=ww(t),s=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":MA(o.open)},r,{ref:s,onClick:ae(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(IA,Q({asChild:!0},i),a)}),TA="PopoverPortal",[YQ,XQ]=kA(TA,{forceMount:void 0}),qQ=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,i=jc(TA,n);return x.createElement(YQ,{scope:n,forceMount:t},x.createElement(Po,{present:t||i.open},x.createElement(ig,{asChild:!0,container:o},r)))},gu="PopoverContent",ZQ=x.forwardRef((e,n)=>{const t=XQ(gu,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,i=jc(gu,e.__scopePopover);return x.createElement(Po,{present:r||i.open},i.modal?x.createElement(QQ,Q({},o,{ref:n})):x.createElement(JQ,Q({},o,{ref:n})))}),QQ=x.forwardRef((e,n)=>{const t=jc(gu,e.__scopePopover),r=x.useRef(null),o=Xe(n,r),i=x.useRef(!1);return x.useEffect(()=>{const s=r.current;if(s)return cw(s)},[]),x.createElement(ag,{as:Fs,allowPinchZoom:!0},x.createElement($A,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ae(e.onCloseAutoFocus,s=>{var a;s.preventDefault(),i.current||(a=t.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:ae(e.onPointerDownOutside,s=>{const a=s.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,l=a.button===2||c;i.current=l},{checkForDefaultPrevented:!1}),onFocusOutside:ae(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1})})))}),JQ=x.forwardRef((e,n)=>{const t=jc(gu,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement($A,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:i=>{var s;if((s=e.onCloseAutoFocus)===null||s===void 0||s.call(e,i),!i.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),i.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:i=>{var s,a;(s=e.onInteractOutside)===null||s===void 0||s.call(e,i),i.defaultPrevented||(r.current=!0,i.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=i.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&i.preventDefault(),i.detail.originalEvent.type==="focusin"&&o.current&&i.preventDefault()}}))}),$A=x.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:i,disableOutsidePointerEvents:s,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:u,...d}=e,f=jc(gu,t),p=ww(t);return aw(),x.createElement(sw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:i},x.createElement(og,{asChild:!0,disableOutsidePointerEvents:s,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1)},x.createElement(EA,Q({"data-state":MA(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 MA(e){return e?"open":"closed"}const eJ=WQ,tJ=VQ,nJ=qQ,rJ=ZQ;function Ji(e,n){const t=z(),r=x.useRef(!1),o=Co(),i=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]),s=G("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]),[s,i]}function bw({id:e,children:n,onOpenChange:t,open:r}){const[o,i]=Ji(e,t);return h.jsx(eJ,{onOpenChange:i,open:r||o,children:h.jsx("div",{className:"tlui-popover",children:n})})}function Pw({children:e}){return h.jsx(tJ,{asChild:!0,dir:"ltr",children:e})}function Cw({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const i=ln();return h.jsx(nJ,{container:i,children:h.jsx(rJ,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const AA=x.createContext(null);function yg(){const e=x.useContext(AA);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function Cr({type:e,sourceId:n,children:t}){return h.jsx(AA.Provider,{value:{type:e,sourceId:n},children:t})}function oJ(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const o=En(e,r);if(o.start||o.end)return!1}return!0})}const jA=()=>{const e=z();return G("threeStackableItems",()=>oJ(e).length>2,[e])},ii=()=>{const e=z();return G("isInSelectState",()=>e.isIn("select"),[e])},OA=()=>{const e=z();return G("allow group",()=>{const n=e.getSelectedShapes();if(n.length<2)return!1;for(const t of n)if(e.isShapeOfType(t,"arrow")){const r=En(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])},DA=()=>{const e=z();return G("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},iJ=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function sJ(e,n){const t=z();return G("selectedShapes",()=>t.getSelectedShapes().length>=e,[t,e,n])}function xn(e,n){const t=z();return G("selectedShapes",()=>{const r=t.getSelectedShapes().filter(o=>!t.isShapeOrAncestorLocked(o)).length;return e===void 0?r:r>=e},[t])}function aJ(){const e=z();return G("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}function RA(){const e=z();return G("hasLinkShapeSelected",()=>{const n=e.getOnlySelectedShape();return!!(n&&n.type!=="embed"&&"url"in n.props&&!n.isLocked)},[e])}function cJ(){const e=z();return G("onlyFlippableShape",()=>{const n=e.getOnlySelectedShape();return n&&(e.isShapeOfType(n,"group")||e.isShapeOfType(n,"arrow")||e.isShapeOfType(n,"line")||e.isShapeOfType(n,"draw"))},[e])}function LA(){const e=z();return G("useCanRedo",()=>e.getCanRedo(),[e])}function FA(){const e=z();return G("useCanUndo",()=>e.getCanUndo(),[e])}const lJ=x.createContext(void 0);function Iw(e){const n=x.useContext(lJ);return e||n||"ltr"}const my="rovingFocusGroup.onEntryFocus",uJ={bubbles:!1,cancelable:!0},Ew="RovingFocusGroup",[Dv,NA,dJ]=cg(Ew),[hJ,zA]=bo(Ew,[dJ]),[fJ,pJ]=hJ(Ew),gJ=x.forwardRef((e,n)=>x.createElement(Dv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(Dv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(mJ,Q({},e,{ref:n}))))),mJ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:i,currentTabStopId:s,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:l,...u}=e,d=x.useRef(null),f=Xe(n,d),p=Iw(i),[S=null,m]=Qi({prop:s,defaultProp:a,onChange:c}),[w,y]=x.useState(!1),v=cn(l),P=NA(t),E=x.useRef(!1),[C,I]=x.useState(0);return x.useEffect(()=>{const _=d.current;if(_)return _.addEventListener(my,v),()=>_.removeEventListener(my,v)},[v]),x.createElement(fJ,{scope:t,orientation:r,dir:p,loop:o,currentTabStopId:S,onItemFocus:x.useCallback(_=>m(_),[m]),onItemShiftTab:x.useCallback(()=>y(!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:ae(e.onMouseDown,()=>{E.current=!0}),onFocus:ae(e.onFocus,_=>{const k=!E.current;if(_.target===_.currentTarget&&k&&!w){const $=new CustomEvent(my,uJ);if(_.currentTarget.dispatchEvent($),!$.defaultPrevented){const T=P().filter(R=>R.focusable),A=T.find(R=>R.active),N=T.find(R=>R.id===S),O=[A,N,...T].filter(Boolean).map(R=>R.ref.current);BA(O)}}E.current=!1}),onBlur:ae(e.onBlur,()=>y(!1))})))}),yJ="RovingFocusGroupItem",SJ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:i,...s}=e,a=Ho(),c=i||a,l=pJ(yJ,t),u=l.currentTabStopId===c,d=NA(t),{onFocusableItemAdd:f,onFocusableItemRemove:p}=l;return x.useEffect(()=>{if(r)return f(),()=>p()},[r,f,p]),x.createElement(Dv.ItemSlot,{scope:t,id:c,focusable:r,active:o},x.createElement(He.span,Q({tabIndex:u?0:-1,"data-orientation":l.orientation},s,{ref:n,onMouseDown:ae(e.onMouseDown,S=>{r?l.onItemFocus(c):S.preventDefault()}),onFocus:ae(e.onFocus,()=>l.onItemFocus(c)),onKeyDown:ae(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){l.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const m=wJ(S,l.orientation,l.dir);if(m!==void 0){S.preventDefault();let y=d().filter(v=>v.focusable).map(v=>v.ref.current);if(m==="last")y.reverse();else if(m==="prev"||m==="next"){m==="prev"&&y.reverse();const v=y.indexOf(S.currentTarget);y=l.loop?bJ(y,v+1):y.slice(v+1)}setTimeout(()=>BA(y))}})})))}),vJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function xJ(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function wJ(e,n,t){const r=xJ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return vJ[r]}function BA(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function bJ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const PJ=gJ,CJ=SJ,Rv=["Enter"," "],IJ=["ArrowDown","PageUp","Home"],UA=["ArrowUp","PageDown","End"],EJ=[...IJ,...UA],_J={ltr:[...Rv,"ArrowRight"],rtl:[...Rv,"ArrowLeft"]},kJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Sg="Menu",[mu,TJ,$J]=cg(Sg),[Zs,vg]=bo(Sg,[$J,mg,zA]),xg=mg(),HA=zA(),[KA,es]=Zs(Sg),[MJ,Hu]=Zs(Sg),AJ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:i,modal:s=!0}=e,a=xg(n),[c,l]=x.useState(null),u=x.useRef(!1),d=cn(i),f=Iw(o);return x.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),x.createElement(xw,a,x.createElement(KA,{scope:n,open:t,onOpenChange:d,content:c,onContentChange:l},x.createElement(MJ,{scope:n,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:f,modal:s},r)))},WA=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=xg(t);return x.createElement(IA,Q({},o,r,{ref:n}))}),GA="MenuPortal",[jJ,VA]=Zs(GA,{forceMount:void 0}),OJ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,i=es(GA,n);return x.createElement(jJ,{scope:n,forceMount:t},x.createElement(Po,{present:t||i.open},x.createElement(ig,{asChild:!0,container:o},r)))},zr="MenuContent",[DJ,_w]=Zs(zr),RJ=x.forwardRef((e,n)=>{const t=VA(zr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,i=es(zr,e.__scopeMenu),s=Hu(zr,e.__scopeMenu);return x.createElement(mu.Provider,{scope:e.__scopeMenu},x.createElement(Po,{present:r||i.open},x.createElement(mu.Slot,{scope:e.__scopeMenu},s.modal?x.createElement(LJ,Q({},o,{ref:n})):x.createElement(FJ,Q({},o,{ref:n})))))}),LJ=x.forwardRef((e,n)=>{const t=es(zr,e.__scopeMenu),r=x.useRef(null),o=Xe(n,r);return x.useEffect(()=>{const i=r.current;if(i)return cw(i)},[]),x.createElement(kw,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:ae(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)}))}),FJ=x.forwardRef((e,n)=>{const t=es(zr,e.__scopeMenu);return x.createElement(kw,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),kw=x.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:i,onCloseAutoFocus:s,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p,disableOutsideScroll:S,...m}=e,w=es(zr,t),y=Hu(zr,t),v=xg(t),P=HA(t),E=TJ(t),[C,I]=x.useState(null),_=x.useRef(null),k=Xe(n,_,w.onContentChange),$=x.useRef(0),T=x.useRef(""),A=x.useRef(0),N=x.useRef(null),j=x.useRef("right"),O=x.useRef(0),R=S?ag:x.Fragment,Y=S?{as:Fs,allowPinchZoom:!0}:void 0,K=H=>{var W,Z;const oe=T.current+H,be=E().filter(Ie=>!Ie.disabled),Ae=document.activeElement,ce=(W=be.find(Ie=>Ie.ref.current===Ae))===null||W===void 0?void 0:W.textValue,je=be.map(Ie=>Ie.textValue),Le=QJ(je,oe,ce),at=(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))})(oe),at&&setTimeout(()=>at.focus())};x.useEffect(()=>()=>window.clearTimeout($.current),[]),aw();const U=x.useCallback(H=>{var W,Z;return j.current===((W=N.current)===null||W===void 0?void 0:W.side)&&eee(H,(Z=N.current)===null||Z===void 0?void 0:Z.area)},[]);return x.createElement(DJ,{scope:t,searchRef:T,onItemEnter:x.useCallback(H=>{U(H)&&H.preventDefault()},[U]),onItemLeave:x.useCallback(H=>{var W;U(H)||((W=_.current)===null||W===void 0||W.focus(),I(null))},[U]),onTriggerLeave:x.useCallback(H=>{U(H)&&H.preventDefault()},[U]),pointerGraceTimerRef:A,onPointerGraceIntentChange:x.useCallback(H=>{N.current=H},[])},x.createElement(R,Y,x.createElement(sw,{asChild:!0,trapped:o,onMountAutoFocus:ae(i,H=>{var W;H.preventDefault(),(W=_.current)===null||W===void 0||W.focus()}),onUnmountAutoFocus:s},x.createElement(og,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:f,onDismiss:p},x.createElement(PJ,Q({asChild:!0},P,{dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:C,onCurrentTabStopIdChange:I,onEntryFocus:ae(c,H=>{y.isUsingKeyboardRef.current||H.preventDefault()})}),x.createElement(EA,Q({role:"menu","aria-orientation":"vertical","data-state":QA(w.open),"data-radix-menu-content":"",dir:y.dir},v,m,{ref:k,style:{outline:"none",...m.style},onKeyDown:ae(m.onKeyDown,H=>{const Z=H.target.closest("[data-radix-menu-content]")===H.currentTarget,oe=H.ctrlKey||H.altKey||H.metaKey,be=H.key.length===1;Z&&(H.key==="Tab"&&H.preventDefault(),!oe&&be&&K(H.key));const Ae=_.current;if(H.target!==Ae||!EJ.includes(H.key))return;H.preventDefault();const je=E().filter(Le=>!Le.disabled).map(Le=>Le.ref.current);UA.includes(H.key)&&je.reverse(),qJ(je)}),onBlur:ae(e.onBlur,H=>{H.currentTarget.contains(H.target)||(window.clearTimeout($.current),T.current="")}),onPointerMove:ae(e.onPointerMove,yu(H=>{const W=H.target,Z=O.current!==H.clientX;if(H.currentTarget.contains(W)&&Z){const oe=H.clientX>O.current?"right":"left";j.current=oe,O.current=H.clientX}}))})))))))}),NJ=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return x.createElement(He.div,Q({role:"group"},r,{ref:n}))}),Lv="MenuItem",II="menu.itemSelect",YA=x.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,i=x.useRef(null),s=Hu(Lv,e.__scopeMenu),a=_w(Lv,e.__scopeMenu),c=Xe(n,i),l=x.useRef(!1),u=()=>{const d=i.current;if(!t&&d){const f=new CustomEvent(II,{bubbles:!0,cancelable:!0});d.addEventListener(II,p=>r==null?void 0:r(p),{once:!0}),iw(d,f),f.defaultPrevented?l.current=!1:s.onClose()}};return x.createElement(XA,Q({},o,{ref:c,disabled:t,onClick:ae(e.onClick,u),onPointerDown:d=>{var f;(f=e.onPointerDown)===null||f===void 0||f.call(e,d),l.current=!0},onPointerUp:ae(e.onPointerUp,d=>{var f;l.current||(f=d.currentTarget)===null||f===void 0||f.click()}),onKeyDown:ae(e.onKeyDown,d=>{const f=a.searchRef.current!=="";t||f&&d.key===" "||Rv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),XA=x.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...i}=e,s=_w(Lv,t),a=HA(t),c=x.useRef(null),l=Xe(n,c),[u,d]=x.useState(!1),[f,p]=x.useState("");return x.useEffect(()=>{const S=c.current;if(S){var m;p(((m=S.textContent)!==null&&m!==void 0?m:"").trim())}},[i.children]),x.createElement(mu.ItemSlot,{scope:t,disabled:r,textValue:o??f},x.createElement(CJ,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},i,{ref:l,onPointerMove:ae(e.onPointerMove,yu(S=>{r?s.onItemLeave(S):(s.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus())})),onPointerLeave:ae(e.onPointerLeave,yu(S=>s.onItemLeave(S))),onFocus:ae(e.onFocus,()=>d(!0)),onBlur:ae(e.onBlur,()=>d(!1))}))))}),zJ=x.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return x.createElement(HJ,{scope:e.__scopeMenu,checked:t},x.createElement(YA,Q({role:"menuitemcheckbox","aria-checked":Fv(t)?"mixed":t},o,{ref:n,"data-state":XJ(t),onSelect:ae(o.onSelect,()=>r==null?void 0:r(Fv(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),BJ="MenuRadioGroup";Zs(BJ,{value:void 0,onValueChange:()=>{}});const UJ="MenuItemIndicator",[HJ,Woe]=Zs(UJ,{checked:!1}),qA="MenuSub",[KJ,ZA]=Zs(qA),WJ=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,i=es(qA,n),s=xg(n),[a,c]=x.useState(null),[l,u]=x.useState(null),d=cn(o);return x.useEffect(()=>(i.open===!1&&d(!1),()=>d(!1)),[i.open,d]),x.createElement(xw,s,x.createElement(KA,{scope:n,open:r,onOpenChange:d,content:l,onContentChange:u},x.createElement(KJ,{scope:n,contentId:Ho(),triggerId:Ho(),trigger:a,onTriggerChange:c},t)))},Qd="MenuSubTrigger",GJ=x.forwardRef((e,n)=>{const t=es(Qd,e.__scopeMenu),r=Hu(Qd,e.__scopeMenu),o=ZA(Qd,e.__scopeMenu),i=_w(Qd,e.__scopeMenu),s=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=i,l={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{s.current&&window.clearTimeout(s.current),s.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),c(null)}},[a,c]),x.createElement(WA,Q({asChild:!0},l),x.createElement(XA,Q({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":QA(t.open)},e,{ref:rg(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:ae(e.onPointerMove,yu(d=>{i.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!t.open&&!s.current&&(i.onPointerGraceIntentChange(null),s.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:ae(e.onPointerLeave,yu(d=>{var f;u();const p=(f=t.content)===null||f===void 0?void 0:f.getBoundingClientRect();if(p){var S;const m=(S=t.content)===null||S===void 0?void 0:S.dataset.side,w=m==="right",y=w?-5:5,v=p[w?"left":"right"],P=p[w?"right":"left"];i.onPointerGraceIntentChange({area:[{x:d.clientX+y,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(()=>i.onPointerGraceIntentChange(null),300)}else{if(i.onTriggerLeave(d),d.defaultPrevented)return;i.onPointerGraceIntentChange(null)}})),onKeyDown:ae(e.onKeyDown,d=>{const f=i.searchRef.current!=="";if(!(e.disabled||f&&d.key===" ")&&_J[r.dir].includes(d.key)){var p;t.onOpenChange(!0),(p=t.content)===null||p===void 0||p.focus(),d.preventDefault()}})})))}),VJ="MenuSubContent",YJ=x.forwardRef((e,n)=>{const t=VA(zr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,i=es(zr,e.__scopeMenu),s=Hu(zr,e.__scopeMenu),a=ZA(VJ,e.__scopeMenu),c=x.useRef(null),l=Xe(n,c);return x.createElement(mu.Provider,{scope:e.__scopeMenu},x.createElement(Po,{present:r||i.open},x.createElement(mu.Slot,{scope:e.__scopeMenu},x.createElement(kw,Q({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:l,align:"start",side:s.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;s.isUsingKeyboardRef.current&&((d=c.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:ae(e.onFocusOutside,u=>{u.target!==a.trigger&&i.onOpenChange(!1)}),onEscapeKeyDown:ae(e.onEscapeKeyDown,u=>{s.onClose(),u.preventDefault()}),onKeyDown:ae(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),f=kJ[s.dir].includes(u.key);if(d&&f){var p;i.onOpenChange(!1),(p=a.trigger)===null||p===void 0||p.focus(),u.preventDefault()}})})))))});function QA(e){return e?"open":"closed"}function Fv(e){return e==="indeterminate"}function XJ(e){return Fv(e)?"indeterminate":e?"checked":"unchecked"}function qJ(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function ZJ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function QJ(e,n,t){const o=n.length>1&&Array.from(n).every(l=>l===n[0])?n[0]:n,i=t?e.indexOf(t):-1;let s=ZJ(e,Math.max(i,0));o.length===1&&(s=s.filter(l=>l!==t));const c=s.find(l=>l.toLowerCase().startsWith(o.toLowerCase()));return c!==t?c:void 0}function JJ(e,n){const{x:t,y:r}=e;let o=!1;for(let i=0,s=n.length-1;i<n.length;s=i++){const a=n[i].x,c=n[i].y,l=n[s].x,u=n[s].y;c>r!=u>r&&t<(l-a)*(r-c)/(u-c)+a&&(o=!o)}return o}function eee(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return JJ(t,n)}function yu(e){return n=>n.pointerType==="mouse"?e(n):void 0}const JA=AJ,ej=WA,tj=OJ,nj=RJ,rj=NJ,oj=YA,ij=zJ,sj=WJ,aj=GJ,cj=YJ,lj="ContextMenu",[tee,Goe]=bo(lj,[vg]),Io=vg(),[nee,uj]=tee(lj),ree=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:i=!0}=e,[s,a]=x.useState(!1),c=Io(n),l=cn(r),u=x.useCallback(d=>{a(d),l(d)},[l]);return x.createElement(nee,{scope:n,open:s,onOpenChange:u,modal:i},x.createElement(JA,Q({},c,{dir:o,open:s,onOpenChange:u,modal:i}),t))},oee="ContextMenuTrigger",iee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,i=uj(oee,t),s=Io(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},i.onOpenChange(!0)};return x.useEffect(()=>u,[u]),x.useEffect(()=>void(r&&u()),[r,u]),x.createElement(x.Fragment,null,x.createElement(ej,Q({},s,{virtualRef:c})),x.createElement(He.span,Q({"data-state":i.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:ae(e.onContextMenu,f=>{u(),d(f),f.preventDefault()}),onPointerDown:r?e.onPointerDown:ae(e.onPointerDown,Jd(f=>{u(),l.current=window.setTimeout(()=>d(f),700)})),onPointerMove:r?e.onPointerMove:ae(e.onPointerMove,Jd(u)),onPointerCancel:r?e.onPointerCancel:ae(e.onPointerCancel,Jd(u)),onPointerUp:r?e.onPointerUp:ae(e.onPointerUp,Jd(u))})))}),dj=e=>{const{__scopeContextMenu:n,...t}=e,r=Io(n);return x.createElement(tj,Q({},r,t))},see="ContextMenuContent",aee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=uj(see,t),i=Io(t),s=x.useRef(!1);return x.createElement(nj,Q({},i,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&&s.current&&a.preventDefault(),s.current=!1},onInteractOutside:a=>{var c;(c=e.onInteractOutside)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&!o.modal&&(s.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)"}}))}),cee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Io(t);return x.createElement(rj,Q({},o,r,{ref:n}))}),lee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Io(t);return x.createElement(oj,Q({},o,r,{ref:n}))}),uee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Io(t);return x.createElement(ij,Q({},o,r,{ref:n}))}),dee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:i}=e,s=Io(n),[a,c]=Qi({prop:o,defaultProp:i,onChange:r});return x.createElement(sj,Q({},s,{open:a,onOpenChange:c}),t)},hee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Io(t);return x.createElement(aj,Q({},o,r,{ref:n}))}),fee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Io(t);return x.createElement(cj,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 Jd(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const pee=ree,gee=iee,mee=dj,yee=aee,See=uee,hj=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,vee=hj?"⌘":"Ctrl",xee=hj?"⌥":"Alt";function fj(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,vee).replace(/\?/g,xee).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Nv(e){return"— "+fj(e).join(" ")}function wee(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 pj="DropdownMenu",[bee,Voe]=bo(pj,[vg]),Eo=vg(),[Pee,gj]=bee(pj),Cee=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:i,onOpenChange:s,modal:a=!0}=e,c=Eo(n),l=x.useRef(null),[u=!1,d]=Qi({prop:o,defaultProp:i,onChange:s});return x.createElement(Pee,{scope:n,triggerId:Ho(),triggerRef:l,contentId:Ho(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(f=>!f),[d]),modal:a},x.createElement(JA,Q({},c,{open:u,onOpenChange:d,dir:r,modal:a}),t))},Iee="DropdownMenuTrigger",Eee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,i=gj(Iee,t),s=Eo(t);return x.createElement(ej,Q({asChild:!0},s),x.createElement(He.button,Q({type:"button",id:i.triggerId,"aria-haspopup":"menu","aria-expanded":i.open,"aria-controls":i.open?i.contentId:void 0,"data-state":i.open?"open":"closed","data-disabled":r?"":void 0,disabled:r},o,{ref:rg(n,i.triggerRef),onPointerDown:ae(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(i.onOpenToggle(),i.open||a.preventDefault())}),onKeyDown:ae(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&i.onOpenToggle(),a.key==="ArrowDown"&&i.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),_ee=e=>{const{__scopeDropdownMenu:n,...t}=e,r=Eo(n);return x.createElement(tj,Q({},r,t))},kee="DropdownMenuContent",Tee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=gj(kee,t),i=Eo(t),s=x.useRef(!1);return x.createElement(nj,Q({id:o.contentId,"aria-labelledby":o.triggerId},i,r,{ref:n,onCloseAutoFocus:ae(e.onCloseAutoFocus,a=>{var c;s.current||(c=o.triggerRef.current)===null||c===void 0||c.focus(),s.current=!1,a.preventDefault()}),onInteractOutside:ae(e.onInteractOutside,a=>{const c=a.detail.originalEvent,l=c.button===0&&c.ctrlKey===!0,u=c.button===2||l;(!o.modal||u)&&(s.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)"}}))}),$ee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Eo(t);return x.createElement(rj,Q({},o,r,{ref:n}))}),Mee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Eo(t);return x.createElement(oj,Q({},o,r,{ref:n}))}),Aee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Eo(t);return x.createElement(ij,Q({},o,r,{ref:n}))}),jee=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:i}=e,s=Eo(n),[a=!1,c]=Qi({prop:r,defaultProp:i,onChange:o});return x.createElement(sj,Q({},s,{open:a,onOpenChange:c}),t)},Oee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Eo(t);return x.createElement(aj,Q({},o,r,{ref:n}))}),Dee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Eo(t);return x.createElement(cj,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)"}}))}),Tw=Cee,$w=Eee,wg=_ee,Mw=Tee,Ree=$ee,Lee=Mee,Fee=Aee,Nee=jee,zee=Oee,Bee=Dee;function zs({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,i]=Ji(e);return h.jsx(Tw,{open:r||o,dir:"ltr",modal:t,onOpenChange:i,children:n})}function Bs({children:e,...n}){return h.jsx($w,{dir:"ltr",asChild:!0,onTouchEnd:t=>_e(t),...n,children:e})}function Us({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const i=ln();return h.jsx(wg,{container:i,children:h.jsx(Mw,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function Uee({id:e,children:n}){const[t,r]=Ji(e);return h.jsx(Nee,{open:t,onOpenChange:r,children:n})}function Hee({id:e,label:n,title:t,disabled:r}){return h.jsx(zee,{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(Ct,{children:n}),h.jsx(Pe,{icon:"chevron-right",small:!0})]})})}function Kee({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const i=ln();return h.jsx(wg,{container:i,children:h.jsx(Bee,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function Wee({children:e}){return h.jsx(Ree,{dir:"ltr",className:"tlui-menu__group",children:e})}function Su({noClose:e,children:n}){return h.jsx(Lee,{dir:"ltr",asChild:!0,onClick:e?_e:void 0,children:n})}function Dl({children:e,visibleOnMobileLayout:n=!1}){const t=Nn();return!n&&t<xt.MOBILE?null:h.jsx("kbd",{className:"tlui-kbd",children:fj(e).map((r,o)=>h.jsx("span",{children:r},o))})}function B({disabled:e=!1,spinner:n=!1,readonlyOk:t=!1,id:r,kbd:o,label:i,icon:s,onSelect:a,noClose:c,isSelected:l}){const{type:u,sourceId:d}=yg(),f=Me(),[p,S]=x.useState(!1);if(ni()&&!t)return null;const w=hu(i,u),y=o?Nv(o):void 0,v=w?f(w):void 0,P=v&&y?`${v} ${y}`:v;switch(u){case"menu":return h.jsx(Su,{children:h.jsxs(he,{type:"menu","data-testid":`${d}.${r}`,disabled:e,title:P,onClick:E=>{c&&_e(E),p?S(!1):a(d)},children:[h.jsx(Ct,{children:v}),o&&h.jsx(Dl,{children:o})]})});case"context-menu":return e?null:h.jsxs(lee,{dir:"ltr",title:P,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${d}.${r}`,onSelect:E=>{c&&_e(E),p?S(!1):a(d)},children:[h.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&h.jsx(Dl,{children:o}),n&&h.jsx(wee,{})]});case"panel":return h.jsxs(he,{"data-testid":`${d}.${r}`,type:"menu",title:P,disabled:e,onClick:()=>a(d),children:[h.jsx(Ct,{children:v}),s&&h.jsx(Pe,{icon:s})]});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:s,small:u==="small-icons"})});case"keyboard-shortcuts":return o?h.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${d}.${r}`,children:[h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:h.jsx(Dl,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${i}' 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:s}),h.jsx(Ct,{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:s})});case"toolbar-overflow":return h.jsx(Su,{"aria-label":i,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:s})})});default:throw nn(u)}}function Gee(){return h.jsxs(h.Fragment,{children:[h.jsx(Vee,{}),h.jsx(Yee,{}),h.jsx(Xee,{}),h.jsx(qee,{}),h.jsx(Zee,{}),h.jsx(ete,{}),h.jsx(tte,{}),h.jsx(nte,{})]})}function Vee(){const e=le(),n=xn(2),t=ii(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(B,{...e["align-left"],disabled:!r}),h.jsx(B,{...e["align-center-horizontal"],disabled:!r}),h.jsx(B,{...e["align-right"],disabled:!r}),h.jsx(B,{...e["stretch-horizontal"],disabled:!r}),h.jsx(B,{...e["align-top"],disabled:!r}),h.jsx(B,{...e["align-center-vertical"],disabled:!r}),h.jsx(B,{...e["align-bottom"],disabled:!r}),h.jsx(B,{...e["stretch-vertical"],disabled:!r})]})}function Yee(){const e=le(),n=xn(3),t=ii(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(B,{...e["distribute-horizontal"],disabled:!r}),h.jsx(B,{...e["distribute-vertical"],disabled:!r})]})}function Xee(){const e=le(),n=jA(),t=ii(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(B,{...e["stack-horizontal"],disabled:!r}),h.jsx(B,{...e["stack-vertical"],disabled:!r})]})}function qee(){const e=le(),n=xn(1),t=ii(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(B,{...e["send-to-back"],disabled:!r}),h.jsx(B,{...e["send-backward"],disabled:!r}),h.jsx(B,{...e["bring-forward"],disabled:!r}),h.jsx(B,{...e["bring-to-front"],disabled:!r})]})}function Zee(){return Nn()<xt.TABLET_SM?h.jsx(Qee,{}):h.jsx(Jee,{})}function Qee(){const e=le(),n=z(),t=G("zoom is 1",()=>n.getZoomLevel()===1,[n]);return h.jsx(B,{...e["zoom-to-100"],disabled:t})}function Jee(){const e=le(),n=xn(1),t=ii(),r=n&&t;return h.jsx(B,{...e["rotate-ccw"],disabled:!r})}function ete(){const e=le(),n=xn(1),t=ii(),r=n&&t;return h.jsx(B,{...e["rotate-cw"],disabled:!r})}function tte(){const e=le(),n=RA(),t=ii(),r=n&&t;return h.jsx(B,{...e["edit-link"],disabled:!r})}function nte(){const e=OA(),n=DA();return e?h.jsx(EI,{}):n?h.jsx(rte,{}):h.jsx(EI,{})}function EI(){const e=le(),n=xn(2),t=ii(),r=n&&t;return h.jsx(B,{...e.group,disabled:!r})}function rte(){const e=le();return h.jsx(B,{...e.ungroup})}const ote=x.memo(function({children:n}){const t=Me(),r=Nn(),o=ni(),i=z(),s=G("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),a=n??h.jsx(Gee,{});if(!(o&&!s))return h.jsxs(bw,{id:"actions-menu",children:[h.jsx(Pw,{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(Cw,{side:r>=xt.TABLET?"bottom":"top",sideOffset:6,children:h.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:h.jsx(Cr,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function Er({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,toggle:i=!1,disabled:s=!1,checked:a=!1}){const{type:c,sourceId:l}=yg(),u=ni(),d=Me();if(u&&!r)return null;const f=hu(t,c),p=f?d(f):void 0;switch(c){case"menu":return h.jsxs(Fee,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:p,onSelect:S=>{o==null||o(l),_e(S)},disabled:s,checked:a,children:[h.jsx(Bi,{small:!0,icon:i?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),n&&h.jsx(Dl,{children:n})]});case"context-menu":return h.jsxs(See,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:p,onSelect:S=>{o(l),_e(S)},disabled:s,checked:a,children:[h.jsx(Bi,{small:!0,icon:i?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),n&&h.jsx(Dl,{children:n})]},e);default:return null}}function me({id:e,label:n,children:t}){const{type:r,sourceId:o}=yg(),i=Me(),s=hu(n,r),a=s?i(s):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(Wee,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return h.jsx(cee,{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 _r({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:i,sourceId:s}=yg(),a=ln(),c=Me(),l=t?typeof t=="string"?t:t[i]??t.default:void 0,u=l?c(l):void 0;switch(i){case"menu":return h.jsxs(Uee,{id:`${s}-sub.${e}`,children:[h.jsx(Hee,{id:`${s}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:n,label:u,title:u}),h.jsx(Kee,{id:`${s}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:h.jsxs(ite,{id:`${s}-sub.${e}`,children:[h.jsx(hee,{dir:"ltr",disabled:n,asChild:!0,children:h.jsxs(he,{"data-testid":`${s}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[h.jsx(Ct,{children:u}),h.jsx(Pe,{icon:"chevron-right",small:!0})]})}),h.jsx(dj,{container:a,children:h.jsx(fee,{"data-testid":`${s}-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 ite({id:e,children:n}){const[t,r]=Ji(e);return h.jsx(dee,{open:t,onOpenChange:r,children:n})}function mj(){const e=le();return aJ()?h.jsx(B,{...e["toggle-auto-size"]}):null}function yj(){const e=le();return RA()?h.jsx(B,{...e["edit-link"]}):null}function ste(){const e=le();return xn(1)?h.jsx(B,{...e.duplicate}):null}function Sj(){const e=le();return OA()?h.jsx(B,{...e.group}):null}function vj(){const e=le();return DA()?h.jsx(B,{...e.ungroup}):null}function xj(){const e=z(),n=le();return G("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?h.jsx(B,{...n["remove-frame"]}):null}function wj(){const e=z(),n=le();return G("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?h.jsx(B,{...n["fit-frame-to-content"]}):null}function bj(){const e=z(),n=le();return G("selected shapes",()=>e.getSelectedShapes().length>0,[e])?h.jsx(B,{...n["toggle-lock"]}):null}function Aw(){const e=le(),n=z(),t=G("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return h.jsx(Er,{...e["toggle-transparent"],checked:t,toggle:!0})}function ate(){const e=z(),n=le(),t=G("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsx(B,{...n["unlock-all"],disabled:!t})}function Pj(){const e=z(),n=G("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=le();return h.jsx(B,{...t["zoom-to-100"],noClose:!0,disabled:n})}function Cj(){const e=z(),n=G("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=le();return h.jsx(B,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function Ij(){const e=z(),n=G("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=le();return h.jsx(B,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function Ej(){return h.jsxs(me,{id:"clipboard",children:[h.jsx(lte,{}),h.jsx(ute,{}),h.jsx(dte,{}),h.jsx(ste,{}),h.jsx(hte,{})]})}function cte(){var r;const e=z(),n=le(),t=G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsxs(_r,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[h.jsxs(me,{id:"copy-as-group",children:[h.jsx(B,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&h.jsx(B,{...n["copy-as-png"]}),h.jsx(B,{...n["copy-as-json"]})]}),h.jsx(me,{id:"copy-as-bg",children:h.jsx(Aw,{})})]})}function lte(){const e=le(),n=xn(1);return h.jsx(B,{...e.cut,disabled:!n})}function ute(){const e=le(),n=sJ(1);return h.jsx(B,{...e.copy,disabled:!n})}function dte(){const e=le(),n=iJ;return h.jsx(B,{...e.paste,disabled:!n})}function _j(){const e=z(),n=le();return G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?h.jsxs(me,{id:"conversions",children:[h.jsx(cte,{}),h.jsxs(_r,{id:"export-as",label:"context-menu.export-as",size:"small",children:[h.jsxs(me,{id:"export-as-group",children:[h.jsx(B,{...n["export-as-svg"]}),h.jsx(B,{...n["export-as-png"]}),h.jsx(B,{...n["export-as-json"]})]}),h.jsx(me,{id:"export-as-bg",children:h.jsx(Aw,{})})]})]}):null}function kj(){const e=le(),n=z(),t=G("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return h.jsx(B,{...e["select-all"],disabled:!t})}function hte(){const e=le(),n=xn(1);return h.jsx(B,{...e.delete,disabled:!n})}function fte(){const e=xn(2),n=cJ(),t=le();return e||n?h.jsxs(_r,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&h.jsxs(me,{id:"align",children:[h.jsx(B,{...t["align-left"]}),h.jsx(B,{...t["align-center-horizontal"]}),h.jsx(B,{...t["align-right"]}),h.jsx(B,{...t["align-top"]}),h.jsx(B,{...t["align-center-vertical"]}),h.jsx(B,{...t["align-bottom"]})]}),h.jsx(pte,{}),e&&h.jsxs(me,{id:"stretch",children:[h.jsx(B,{...t["stretch-horizontal"]}),h.jsx(B,{...t["stretch-vertical"]})]}),(e||n)&&h.jsxs(me,{id:"flip",children:[h.jsx(B,{...t["flip-horizontal"]}),h.jsx(B,{...t["flip-vertical"]})]}),h.jsx(gte,{})]}):null}function pte(){const e=le();return xn(3)?h.jsxs(me,{id:"distribute",children:[h.jsx(B,{...e["distribute-horizontal"]}),h.jsx(B,{...e["distribute-vertical"]})]}):null}function gte(){const e=le(),n=xn(2),t=jA();return n?h.jsxs(me,{id:"order",children:[h.jsx(B,{...e.pack}),t&&h.jsx(B,{...e["stack-horizontal"]}),t&&h.jsx(B,{...e["stack-vertical"]})]}):null}function mte(){const e=le();return xn(1)?h.jsx(_r,{id:"reorder",label:"context-menu.reorder",size:"small",children:h.jsxs(me,{id:"reorder",children:[h.jsx(B,{...e["bring-to-front"]}),h.jsx(B,{...e["bring-forward"]}),h.jsx(B,{...e["send-backward"]}),h.jsx(B,{...e["send-to-back"]})]})}):null}function yte(){const e=z(),n=G("pages",()=>e.getPages(),[e]),t=G("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Gr(),o=le(),i=Co();return xn(1)?h.jsxs(_r,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[h.jsx(me,{id:"pages",children:n.map(a=>h.jsx(B,{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)}}]}),i("move-to-page",{source:"context-menu"})}},a.id))}),h.jsx(me,{id:"new-page",children:h.jsx(B,{...o["new-page"]})})]}):null}function Tj(){const e=z(),n=le();return G("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(B,{...n["convert-to-bookmark"]}):null}function $j(){const e=z(),n=le();return G("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&Ii(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(B,{...n["convert-to-embed"]}):null}function Ste(){const e=le(),n=z(),t=G("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return h.jsx(Er,{...e["toggle-snap-mode"],checked:t})}function vte(){const e=le(),n=z(),t=G("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return h.jsx(Er,{...e["toggle-tool-lock"],checked:t})}function xte(){const e=le(),n=z(),t=G("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return h.jsx(Er,{...e["toggle-grid"],checked:t})}function wte(){const e=le(),n=z(),t=G("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return h.jsx(Er,{...e["toggle-wrap-mode"],checked:t})}function bte(){const e=le(),n=z(),t=G("isDarkMode",()=>n.user.getIsDarkMode(),[n]);return h.jsx(Er,{...e["toggle-dark-mode"],checked:t})}function Pte(){const e=le(),n=z(),t=G("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return h.jsx(Er,{...e["toggle-focus-mode"],checked:t})}function Cte(){const e=le(),n=z(),t=G("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return h.jsx(Er,{...e["toggle-edge-scrolling"],checked:t===1})}function Ite(){const e=le(),n=z(),t=G("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return h.jsx(Er,{...e["toggle-reduce-motion"],checked:t===0})}function Ete(){const e=le(),n=z(),t=G("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return h.jsx(Er,{...e["toggle-debug-mode"],checked:t})}function _te(){const e=z();return G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?h.jsxs(h.Fragment,{children:[h.jsxs(me,{id:"misc",children:[h.jsx(Sj,{}),h.jsx(vj,{}),h.jsx(yj,{}),h.jsx(mj,{}),h.jsx(xj,{}),h.jsx(wj,{}),h.jsx($j,{}),h.jsx(Tj,{}),h.jsx(bj,{})]}),h.jsxs(me,{id:"modify",children:[h.jsx(fte,{}),h.jsx(mte,{}),h.jsx(yte,{})]}),h.jsx(Ej,{}),h.jsx(_j,{}),h.jsx(me,{id:"select-all",children:h.jsx(kj,{})})]}):null}const kte=x.memo(function({children:n}){const t=z(),{Canvas:r}=st(),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(S=>t.isShapeOrAncestorLocked(S));p.length&&t.select(...p.map(S=>S.id))}}}else{const u=t.getOnlySelectedShape();u&&t.isShapeOrAncestorLocked(u)&&t.setSelectedShapes([])}},[t]),i=ln(),[s,a]=Ji("context menu",o),c=n??h.jsx(_te,{});return h.jsxs(pee,{dir:"ltr",onOpenChange:a,modal:!1,children:[h.jsx(gee,{onContextMenu:void 0,dir:"ltr",children:r?h.jsx(r,{}):null}),s&&h.jsx(mee,{container:i,children:h.jsx(yee,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:_e,children:h.jsx(Cr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})});function zv({checked:e}){return h.jsx(Bi,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function Tte(){const e=z(),{addToast:n}=Gr(),{addDialog:t}=qs(),[r,o]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(me,{id:"items",children:[h.jsx(B,{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(B,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:i})=>h.jsx(Ate,{displayDontShowAgain:!0,onCancel:()=>i(),onContinue:()=>i()}),onClose:()=>{}})}}),h.jsx(B,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>jte(e,100)}),h.jsx(B,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const i=e.getSelectedShapes(),s=i.length===0?e.getRenderingShapes():i;window.alert(`Shapes ${s.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),h.jsx(B,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),h.jsx(B,{id:"hard-reset",onSelect:jk,label:"Hard reset"})]}),h.jsxs(me,{id:"flags",children:[h.jsx($te,{}),h.jsx(Mte,{})]})]})}function $te(){const e=Object.values(bt);return e.length?h.jsx(_r,{id:"debug flags",label:"Debug Flags",children:h.jsx(me,{id:"debug flags",children:e.map(n=>h.jsx(Mj,{flag:n},n.name))})}):null}function Mte(){const e=Object.values(Wz);return e.length?h.jsx(_r,{id:"feature flags",label:"Feature Flags",children:h.jsx(me,{id:"feature flags",children:e.map(n=>h.jsx(Mj,{flag:n},n.name))})}):null}function Ate({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:i,onContinue:s}){const[a,c]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{children:[h.jsx(hg,{children:e}),h.jsx(fg,{})]}),h.jsx(du,{style:{maxWidth:350},children:n}),h.jsxs(uw,{className:"tlui-dialog__footer__actions",children:[o&&h.jsxs(he,{type:"normal",onClick:()=>c(!a),style:{marginRight:"auto"},children:[h.jsx(zv,{checked:a}),h.jsx(Ct,{children:"Don't show again"})]}),h.jsx(he,{type:"normal",onClick:i,children:h.jsx(Ct,{children:t})}),h.jsx(he,{type:"primary",onClick:async()=>s(),children:h.jsx(Ct,{children:r})})]})]})}const Mj=ir(function({flag:n,onChange:t}){const r=n.get();return h.jsx(Er,{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 _I=0;function jte(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)_I++,t[o]={id:Be("box"+_I),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function Ote({children:e}){const n=e??h.jsx(Tte,{});return h.jsxs(zs,{id:"debug",children:[h.jsx(Bs,{children:h.jsx(he,{type:"icon",title:"Debug menu",children:h.jsx(Pe,{icon:"dots-horizontal"})})}),h.jsx(Us,{side:"top",align:"end",alignOffset:0,children:h.jsx(Cr,{type:"menu",sourceId:"debug-panel",children:n})})]})}const Dte=x.memo(function(){const{DebugMenu:n}=ns();return h.jsxs("div",{className:"tlui-debug-panel",children:[h.jsx(Lte,{}),h.jsx(Fte,{}),n&&h.jsx(n,{})]})});function Rte(e=!0){const[n,t]=x.useState(0),r=z();x.useEffect(()=>{if(!e)return;const o=()=>t(i=>i+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const Lte=ir(function(){Rte();const n=z(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),i=t==="select.idle"||!t.includes("select.")?r:o,s=i&&t.includes("select.")?` / ${i.type||""}${"geo"in i.props?" / "+i.props.geo:""} / [${b.ToInt(n.getPointInShapeSpace(i,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}${s}${a}`})});function Fte(){const e=z(),n=G("show_fps",()=>bt.showFps.get(),[bt]),t=x.useRef(null);return x.useEffect(()=>{if(!n)return;const r=250;let o=0,i=-1,s=performance.now(),a=0,c=0,l=!1;function u(){if(c++,a=performance.now()-s,a>r){const d=Math.round(c*(r/a)*(1e3/r));d>o&&(o=d);const f=o*.75;(d<f&&!l||d>=f&&l)&&(l=!l),t.current.innerHTML=`FPS ${d.toString()}`,t.current.className="tlui-debug-panel__fps"+(l?" tlui-debug-panel__fps__slow":""),a-=r,c=0,s=performance.now()}i=e.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(i)}},[n,e]),n?h.jsx("div",{ref:t}):null}function Aj(){const e=z(),n=Co(),t=G("locale",()=>e.user.getLocale(),[e]);return h.jsx(_r,{id:"help menu language",label:"menu.language",children:h.jsx(me,{id:"languages",children:Bl.map(({locale:r,label:o})=>h.jsx(Er,{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 Nte(){return h.jsxs(h.Fragment,{children:[h.jsx(Aj,{}),h.jsx(zte,{})]})}function zte(){const{KeyboardShortcutsDialog:e}=ns(),{addDialog:n}=qs();return e?h.jsx(B,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const Bte=x.memo(function({children:n}){const t=Me(),r=Nn(),o=n??h.jsx(Nte,{});return r<xt.MOBILE?null:h.jsx("div",{className:"tlui-help-menu",children:h.jsxs(zs,{id:"help menu",children:[h.jsx(Bs,{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(Us,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:h.jsx(Cr,{type:"menu",sourceId:"help-menu",children:o})})]})})});function Ute(){const e=z(),n=le(),[t,r]=x.useState(!1),o=x.useRef(!1);return Ei("toggle showback to content",()=>{const i=o.current,s=e.getCurrentPageShapeIds();let a=!1;s.size&&(a=s.size===e.getCulledShapes().size),i!==a&&(r(a),o.current=a)},[e]),t?h.jsx(B,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Hte(){const e=z(),n=le();return G("is pen mode",()=>e.getInstanceState().isPenMode,[e])?h.jsx(B,{...n["exit-pen-mode"]}):null}function Kte(){const e=z(),n=le();return G("is following user",()=>!!e.getInstanceState().followingUserId,[e])?h.jsx(B,{...n["stop-following"]}):null}function Wte(){return h.jsxs(h.Fragment,{children:[h.jsx(Hte,{}),h.jsx(Ute,{}),h.jsx(Kte,{})]})}function Gte({children:e}){const n=e??h.jsx(Wte,{});return h.jsx("div",{className:"tlui-helper-buttons",children:h.jsx(Cr,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}function Vte(){const e=le(),n=pg();return h.jsxs(h.Fragment,{children:[h.jsxs(me,{label:"shortcuts-dialog.tools",id:"tools",children:[h.jsx(B,{...e["toggle-tool-lock"]}),h.jsx(B,{...e["insert-media"]}),h.jsx(B,{...n.select}),h.jsx(B,{...n.draw}),h.jsx(B,{...n.eraser}),h.jsx(B,{...n.hand}),h.jsx(B,{...n.rectangle}),h.jsx(B,{...n.ellipse}),h.jsx(B,{...n.arrow}),h.jsx(B,{...n.line}),h.jsx(B,{...n.text}),h.jsx(B,{...n.frame}),h.jsx(B,{...n.note}),h.jsx(B,{...n.laser})]}),h.jsxs(me,{label:"shortcuts-dialog.preferences",id:"preferences",children:[h.jsx(B,{...e["toggle-dark-mode"]}),h.jsx(B,{...e["toggle-focus-mode"]}),h.jsx(B,{...e["toggle-grid"]})]}),h.jsxs(me,{label:"shortcuts-dialog.edit",id:"edit",children:[h.jsx(B,{...e.undo}),h.jsx(B,{...e.redo}),h.jsx(B,{...e.cut}),h.jsx(B,{...e.copy}),h.jsx(B,{...e.paste}),h.jsx(B,{...e["select-all"]}),h.jsx(B,{...e.delete}),h.jsx(B,{...e.duplicate})]}),h.jsxs(me,{label:"shortcuts-dialog.view",id:"view",children:[h.jsx(B,{...e["zoom-in"]}),h.jsx(B,{...e["zoom-out"]}),h.jsx(B,{...e["zoom-to-100"]}),h.jsx(B,{...e["zoom-to-fit"]}),h.jsx(B,{...e["zoom-to-selection"]})]}),h.jsxs(me,{label:"shortcuts-dialog.transform",id:"transform",children:[h.jsx(B,{...e["bring-to-front"]}),h.jsx(B,{...e["bring-forward"]}),h.jsx(B,{...e["send-backward"]}),h.jsx(B,{...e["send-to-back"]}),h.jsx(B,{...e.group}),h.jsx(B,{...e.ungroup}),h.jsx(B,{...e["flip-horizontal"]}),h.jsx(B,{...e["flip-vertical"]}),h.jsx(B,{...e["align-top"]}),h.jsx(B,{...e["align-center-vertical"]}),h.jsx(B,{...e["align-bottom"]}),h.jsx(B,{...e["align-left"]}),h.jsx(B,{...e["align-center-horizontal"]}),h.jsx(B,{...e["align-right"]})]})]})}const Yte=x.memo(function({children:n}){const t=Me(),r=Nn(),o=n??h.jsx(Vte,{});return h.jsxs(h.Fragment,{children:[h.jsxs(dg,{className:"tlui-shortcuts-dialog__header",children:[h.jsx(hg,{children:t("shortcuts-dialog.title")}),h.jsx(fg,{})]}),h.jsx(du,{className:ue("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=xt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=xt.TABLET}),children:h.jsx(Cr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),h.jsx("div",{className:"tlui-dialog__scrim"})]})});function Xte(){return h.jsxs(h.Fragment,{children:[h.jsx(Zte,{}),h.jsx(tne,{}),h.jsx(qte,{}),h.jsx(nne,{}),h.jsx(rne,{})]})}function qte(){const e=le();return h.jsxs(_r,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[h.jsxs(me,{id:"export-all-as-group",children:[h.jsx(B,{...e["export-all-as-svg"]}),h.jsx(B,{...e["export-all-as-png"]}),h.jsx(B,{...e["export-all-as-json"]})]}),h.jsx(me,{id:"export-all-as-bg",children:h.jsx(Aw,{})})]})}function Zte(){const e=z(),n=G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return h.jsxs(_r,{id:"edit",label:"menu.edit",disabled:!n,children:[h.jsx(ene,{}),h.jsx(Ej,{}),h.jsx(_j,{}),h.jsx(Qte,{}),h.jsx(Jte,{}),h.jsx(me,{id:"select-all",children:h.jsx(kj,{})})]})}function Qte(){return h.jsxs(me,{id:"misc",children:[h.jsx(Sj,{}),h.jsx(vj,{}),h.jsx(yj,{}),h.jsx(mj,{}),h.jsx(xj,{}),h.jsx(wj,{}),h.jsx($j,{}),h.jsx(Tj,{})]})}function Jte(){return h.jsxs(me,{id:"lock",children:[h.jsx(bj,{}),h.jsx(ate,{})]})}function ene(){const e=le(),n=FA(),t=LA();return h.jsxs(me,{id:"undo-redo",children:[h.jsx(B,{...e.undo,disabled:!n}),h.jsx(B,{...e.redo,disabled:!t})]})}function tne(){const e=le();return h.jsx(_r,{id:"view",label:"menu.view",children:h.jsxs(me,{id:"view-actions",children:[h.jsx(B,{...e["zoom-in"]}),h.jsx(B,{...e["zoom-out"]}),h.jsx(Pj,{}),h.jsx(Cj,{}),h.jsx(Ij,{})]})})}function nne(){const e=le();return h.jsxs(me,{id:"extras",children:[h.jsx(B,{...e["insert-embed"]}),h.jsx(B,{...e["insert-media"]})]})}function rne(){return h.jsx(me,{id:"preferences",children:h.jsxs(_r,{id:"preferences",label:"menu.preferences",children:[h.jsxs(me,{id:"preferences-actions",children:[h.jsx(Ste,{}),h.jsx(vte,{}),h.jsx(xte,{}),h.jsx(wte,{}),h.jsx(bte,{}),h.jsx(Pte,{}),h.jsx(Cte,{}),h.jsx(Ite,{}),h.jsx(Ete,{})]}),h.jsx(me,{id:"language",children:h.jsx(Aj,{})})]})})}const one=x.memo(function({children:n}){const t=ln(),[r,o]=Ji("main menu"),i=Me(),s=n??h.jsx(Xte,{});return h.jsxs(Tw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx($w,{asChild:!0,dir:"ltr",children:h.jsx(he,{type:"icon","data-testid":"main-menu.button",title:i("menu.title"),children:h.jsx(Pe,{icon:"menu",small:!0})})}),h.jsx(wg,{container:t,children:h.jsx(Mw,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:h.jsx(Cr,{type:"menu",sourceId:"main-menu",children:s})})})]})}),ine=x.memo(function(){const n=Nn(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:i}=ns();return!t&&!i&&n<6?null:h.jsx("div",{className:"tlui-menu-zone",children:h.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&h.jsx(t,{}),i&&h.jsx(i,{}),n<6?null:h.jsxs(h.Fragment,{children:[r&&h.jsx(r,{}),o&&h.jsx(o,{})]})]})})}),yy={};function sl(e){if(yy[e])return yy[e];const t=document.createElement("canvas").getContext("2d");t.fillStyle=e,t.fillRect(0,0,1,1);const[r,o,i,s]=t.getImageData(0,0,1,1).data,a=new Float32Array([r/255,o/255,i/255,s/255]);return yy[e]=a,a}const sf=10,jj=4*6*sf+12+4*12;function ga(e,{center:n,radius:t,numArcSegments:r=20,startAngle:o=0,endAngle:i=Re,offset:s=0}){const a=(i-o)/r;let c=s;for(let l=o;l<i;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 ma(e,n,t,r,o,i){e[n++]=t,e[n++]=r,e[n++]=t,e[n++]=r+i,e[n++]=t+o,e[n++]=r,e[n++]=t+o,e[n++]=r,e[n++]=t,e[n++]=r+i,e[n++]=t+o,e[n++]=r+i}function sne(e,n,t){const r=sf;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 ga(e,{center:n.center,radius:t,numArcSegments:sf*4}),sf*4*6;let i=0;return ma(e,i,o.minX,o.minY,o.w,o.h),i+=12,ma(e,i,o.minX,n.minY,o.w,t),i+=12,ma(e,i,o.maxX,o.minY,t,o.h),i+=12,ma(e,i,o.minX,o.maxY,o.w,t),i+=12,ma(e,i,n.minX,o.minY,t,o.h),i+=12,ga(e,{numArcSegments:r,offset:i,center:o.point,radius:t,startAngle:ke,endAngle:ke*1.5}),i+=r*6,ga(e,{numArcSegments:r,offset:i,center:b.Add(o.point,new b(o.w,0)),radius:t,startAngle:ke*1.5,endAngle:Re}),i+=r*6,ga(e,{numArcSegments:r,offset:i,center:b.Add(o.point,o.size),radius:t,startAngle:0,endAngle:Ve}),i+=r*6,ga(e,{numArcSegments:r,offset:i,center:b.Add(o.point,new b(0,o.h)),radius:t,startAngle:Ve,endAngle:ke}),jj}function ane(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
282
- precision mediump float;
283
-
284
- in vec2 shapeVertexPosition;
285
-
286
- uniform vec4 canvasPageBounds;
287
-
288
- // taken (with thanks) from
289
- // https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
290
- void main() {
291
- // convert the position from pixels to 0.0 to 1.0
292
- vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
293
-
294
- // convert from 0->1 to 0->2
295
- vec2 zeroToTwo = zeroToOne * 2.0;
296
-
297
- // convert from 0->2 to -1->+1 (clipspace)
298
- vec2 clipSpace = zeroToTwo - 1.0;
299
-
300
- gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
301
- }`,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
302
- precision mediump float;
303
-
304
- uniform vec4 fillColor;
305
- out vec4 outputColor;
306
-
307
- void main() {
308
- outputColor = fillColor;
309
- }`,i=n.createShader(n.FRAGMENT_SHADER);if(!i)throw new Error("Failed to create fragment shader");if(n.shaderSource(i,o),n.compileShader(i),!n.getShaderParameter(i,n.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const s=n.createProgram();if(!s)throw new Error("Failed to create program");if(n.attachShader(s,r),n.attachShader(s,i),n.linkProgram(s),!n.getProgramParameter(s,n.LINK_STATUS))throw new Error("Failed to link program");n.useProgram(s);const a=n.getAttribLocation(s,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");n.enableVertexAttribArray(a);const c=n.getUniformLocation(s,"canvasPageBounds"),l=n.getUniformLocation(s,"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:eh(n,1024),unselectedShapes:eh(n,4096),viewport:eh(n,jj),collaborators:eh(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 eh(e,n){const t=e.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(n)}}function kI(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 cne=Object.defineProperty,lne=Object.getOwnPropertyDescriptor,ts=(e,n,t,r)=>{for(var o=lne(n,t),i=e.length-1,s;i>=0;i--)(s=e[i])&&(o=s(n,t,o)||o);return o&&cne(n,t,o),o};class si{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",rn("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 i=n-o.x,s=t-o.y;return i*=r.width/o.width,s*=r.height/o.height,i+=r.minX,s+=r.minY,new b(i,s,1)});g(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:i}=this,s=i.getViewportPageBounds();let{x:a,y:c}=this.getMinimapPagePoint(n,t);if(o){const l=this.editor.getCurrentPageBounds()??new J,u=l.minX-s.width/2,d=l.maxX+s.width/2,f=l.minY-s.height/2,p=l.maxY+s.height/2,S=Math.max(0,u+s.width-a),m=Math.max(0,-(d-s.width-a)),w=Math.max(0,f+s.height-c),y=Math.max(0,-(p-s.height-c));a+=(S-m)/2,c+=(w-y)/2,a=Tt(a,u,d),c=Tt(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 i=0,s=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)?(kI(this.gl.selectedShapes,i,d),i+=f):(kI(this.gl.unselectedShapes,s,d),s+=f)}this.drawShapes(this.gl.unselectedShapes,s,o.shapeFill),this.drawShapes(this.gl.selectedShapes,i,o.selectFill),this.drawViewport(),this.drawCollaborators()});this.editor=n,this.elem=t,this.container=r,this.gl=ane(t),this.shapeGeometryCache=n.store.createComputedCache("webgl-geometry",o=>{const i=n.getShapeMaskedPageBounds(o.id);if(!i)return null;const s=new Float32Array(12);return ma(s,0,i.x,i.y,i.w,i.h),s}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),Gs("minimap render",this.render))}_getColors(){const n=getComputedStyle(this.editor.getContainer());return{shapeFill:sl(n.getPropertyValue("--color-text-3").trim()),selectFill:sl(n.getPropertyValue("--color-selected").trim()),viewportFill:sl(n.getPropertyValue("--color-muted-1").trim()),background:sl(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,i=o/r;i<t.height&&(i=t.height,o=i*r);const s=new J(0,0,o,i);return s.center=t.center,s}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=sne(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 i=this.gl.collaborators.vertices;let s=0;const a=this.getZoom();for(const{cursor:c}of n)ga(i,{center:b.From(c),radius:3*a,offset:s,numArcSegments:t}),s+=r;this.gl.prepareTriangles(this.gl.collaborators,o),s=0;for(const{color:c}of n)this.gl.setFillColor(sl(c)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,s/2,r/2),s+=r}}ts([V],si.prototype,"getDpr");ts([V],si.prototype,"getContentPageBounds");ts([V],si.prototype,"getContentScreenBounds");ts([V],si.prototype,"getCanvasSize");ts([V],si.prototype,"getCanvasClientPosition");ts([V],si.prototype,"getCanvasPageBounds");ts([V],si.prototype,"getZoom");ts([V],si.prototype,"getCanvasPageBoundsArray");function une(){const e=z(),n=ln(),t=x.useRef(null),r=x.useRef(!1),o=x.useRef();x.useEffect(()=>{try{const u=new si(e,t.current,n);return o.current=u,o.current.close}catch(u){e.annotateError(u,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw u})}},[e,n]);const i=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:e.options.animationMediumMs}})},[e]),s=x.useCallback(u=>{if(!o.current)return;const d=u.currentTarget;if(Mu(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(),S=o.current.getContentPageBounds();if(new J(S.x-p.width/2,S.y-p.height/2,S.width+p.width,S.height+p.height).containsPoint(f)&&!p.containsPoint(f)){o.current.isInViewport=p.containsPoint(f);const y=b.Sub(p.center,p.point),v=b.Add(f,y);o.current.originPagePoint.setTo(v),o.current.originPageCenter.setTo(f),e.centerOnPoint(f,{animation:{duration:e.options.animationMediumMs}})}else{const y=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=p.containsPoint(y),o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(p.center)}function w(y){d&&Au(d,y),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),S={type:"pointer",target:"canvas",name:"pointer_move",...kn(u),point:p,isPen:e.getInstanceState().isPenMode};e.dispatch(S)},[e]),c=x.useCallback(u=>{const d=Sk(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=Bu();return x.useEffect(()=>{e.timers.setTimeout(()=>{var u,d;(u=o.current)==null||u.updateColors(),(d=o.current)==null||d.render()})},[l,e]),h.jsx("div",{className:"tlui-minimap",children:h.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:i,onPointerMove:a,onPointerDown:s,onWheel:c})})}function dne(e,n){const[t,r]=Se.useState(n);Se.useLayoutEffect(()=>{const i=y0(e);if(i)try{r(JSON.parse(i))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=Se.useCallback(i=>{r(s=>{const a=typeof i=="function"?i(s):i;return S0(e,JSON.stringify(a)),a})},[e]);return[t,o]}const hne=x.memo(function(){const n=le(),t=Me(),r=Nn(),[o,i]=dne("minimap",!0),s=x.useCallback(()=>{i(l=>!l)},[i]),{ZoomMenu:a,Minimap:c}=ns();return r<xt.MOBILE?null:h.jsxs("div",{className:"tlui-navigation-panel",children:[h.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<xt.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:s,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(hu(n["zoom-out"].label))} ${Nv(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(hu(n["zoom-in"].label))} ${Nv(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:s,children:h.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=xt.TABLET&&!o&&h.jsx(c,{})]})}),fne=function({name:n,id:t,isCurrentPage:r}){const o=z(),i=x.useRef(null),s=x.useCallback(()=>{o.mark("rename page")},[o]),a=x.useCallback(c=>{o.renamePage(t,c||"New Page")},[o,t]);return h.jsx(dw,{className:"tlui-page-menu__item__input",ref:c=>i.current=c,defaultValue:n,onValueChange:a,onFocus:s,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},Bv=(e,n,t,r)=>{let o;const i=e.getPages(),s=t>r?i[r-1]:i[r],a=t>r?i[r]:i[r+1];s&&!a?o=Do(s.index):!s&&a?o=jN(i[0].index):o=Fl(s.index,a.index),o!==i[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},TI=ir(function({index:n,listSize:t,item:r,onRename:o}){const i=z(),s=Me(),a=i.getPages(),c=x.useCallback(()=>{i.mark("creating page");const f=Ko.createId();i.duplicatePage(r.id,f)},[i,r]),l=x.useCallback(()=>{Bv(i,r.id,n,n-1)},[i,r,n]),u=x.useCallback(()=>{Bv(i,r.id,n,n+1)},[i,r,n]),d=x.useCallback(()=>{i.mark("deleting page"),i.deletePage(r.id)},[i,r]);return h.jsxs(zs,{id:`page item submenu ${n}`,children:[h.jsx(Bs,{children:h.jsx(he,{type:"icon",title:s("page-menu.submenu.title"),children:h.jsx(Pe,{icon:"dots-vertical"})})}),h.jsx(Us,{alignOffset:0,side:"right",sideOffset:-4,children:h.jsxs(Cr,{type:"menu",sourceId:"page-menu",children:[h.jsxs(me,{id:"modify",children:[o&&h.jsx(B,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),h.jsx(B,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=i.options.maxPages}),n>0&&h.jsx(B,{id:"move-up",onSelect:l,label:"page-menu.submenu.move-up"}),n<t-1&&h.jsx(B,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),t>1&&h.jsx(me,{id:"delete",children:h.jsx(B,{id:"delete",onSelect:d,label:"page-menu.submenu.delete"})})]})})]})}),pne=x.memo(function(){const n=z(),t=Me(),r=Nn(),o=x.useCallback(()=>w(!1),[]),[i,s]=Ji("page-menu",o),a=36,c=x.useRef(null),l=G("pages",()=>n.getPages(),[n]),u=G("currentPage",()=>n.getCurrentPage(),[n]),d=G("currentPageId",()=>n.getCurrentPageId(),[n]),f=ni(),p=G("maxPageCountReached",()=>n.getPages().length>=n.options.maxPages,[n]),S=G("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[m,w]=x.useState(!1),y=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,A)=>[T.id,{y:A*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{E(Object.fromEntries(l.map((T,A)=>[T.id,{y:A*a,offsetY:0,isSelected:!1}])))},[a,l]),x.useEffect(()=>{i&&n.timers.requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const A=c.current;if(!A)return;const N=T.offsetTop,j=A.scrollTop;N<j&&A.scrollTo({top:N});const O=N+a,R=A.scrollTop+A.offsetHeight;O>R&&A.scrollTo({top:O-A.offsetHeight})}})},[a,d,i,n]);const C=x.useCallback(T=>{const{clientY:A,currentTarget:N}=T,{dataset:{id:j,index:O}}=N;if(!j||!O)return;const R=v.current;Mu(T.currentTarget,T),R.status="pointing",R.pointing={id:j,index:+O};const K=P[j].y;R.startY=A,R.startIndex=Math.max(0,Math.min(Math.round(K/a),l.length-1))},[a,l.length,P]),I=x.useCallback(T=>{const A=v.current;if(A.status==="pointing"){const{clientY:N}=T,j=N-A.startY;Math.abs(j)>5&&(A.status="dragging")}if(A.status==="dragging"){const{clientY:N}=T,j=N-A.startY,O=P[A.pointing.id],{startIndex:R,pointing:Y}=A,K=O.y+j,U=Math.max(0,Math.min(Math.round(K/a),l.length-1)),H={...P};if(H[Y.id]={y:O.y,offsetY:j,isSelected:!0},U!==A.dragIndex){A.dragIndex=U;for(let W=0;W<l.length;W++){const Z=l[W];if(Z.id===A.pointing.id)continue;let{y:oe}=H[Z.id];U===R?oe=W*a:U<R?U<=W&&W<R?oe=(W+1)*a:oe=W*a:U>R&&(U>=W&&W>R?oe=(W-1)*a:oe=W*a),oe!==H[Z.id].y&&(H[Z.id]={y:oe,offsetY:0,isSelected:!0})}}E(H)}},[a,l,P]),_=x.useCallback(T=>{const A=v.current;if(A.status==="dragging"){const{id:N,index:j}=A.pointing;Bv(n,N,j,A.dragIndex)}Au(T.currentTarget,T),A.status="idle"},[n]),k=x.useCallback(T=>{const A=v.current;T.key==="Escape"&&(A.status==="dragging"&&E(Object.fromEntries(l.map((N,j)=>[N.id,{y:j*a,offsetY:0,isSelected:!1}]))),A.status="idle")},[a,l]),$=x.useCallback(()=>{f||n.batch(()=>{n.mark("creating page");const T=Ko.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),w(!0)})},[n,t,f]);return h.jsxs(bw,{id:"pages",onOpenChange:s,open:i,children:[h.jsx(Pw,{"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(Cw,{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:y,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,A)=>{const N=P[T.id]??{position:A*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:A,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":A,children:h.jsx(Pe,{icon:"drag-handle-dots"})}),r<xt.TABLET_SM&&S?h.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const j=window.prompt("Rename page",T.name);j&&j!==T.name&&n.renamePage(T.id,j)},onDoubleClick:y,children:[h.jsx(zv,{checked:T.id===u.id}),h.jsx(Ct,{children:T.name})]}):h.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:h.jsx(fne,{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(TI,{index:A,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:y,title:t("page-menu.go-to-page"),children:[h.jsx(zv,{checked:T.id===u.id}),h.jsx(Ct,{children:T.name})]}),!f&&h.jsx("div",{className:"tlui-page_menu__item__submenu",children:h.jsx(TI,{index:A,item:T,listSize:l.length,onRename:()=>{if(n.environment.isIos){const j=window.prompt("Rename page",T.name);j&&j!==T.name&&n.renamePage(T.id,j)}else n.batch(()=>{w(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function gne(){const e=le(),n=z(),t=FA(),r=LA(),o=xn(1),i=ni(),s=G("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]),a=ii(),c=o&&a;if(!(i&&!s))return h.jsxs(h.Fragment,{children:[h.jsx(B,{...e.undo,disabled:!t}),h.jsx(B,{...e.redo,disabled:!r}),h.jsx(B,{...e.delete,disabled:!c}),h.jsx(B,{...e.duplicate,disabled:!c})]})}const mne=x.memo(function({children:n}){const t=n??h.jsx(gne,{});return h.jsx(Cr,{type:"small-icons",sourceId:"quick-actions",children:t})}),yne=Object.freeze([rr,_s,nc,fo]);function Oj(e=yne){const n=z();return G("getRelevantStyles",()=>{var i;const t=new lv(n.getSharedStyles()),r=!!((i=n.root.getCurrent())!=null&&i.shapeType),o=n.isIn("select")&&n.getSelectedShapeIds().length>0;if(t.size===0&&n.isIn("select")&&n.getSelectedShapeIds().length===0)for(const s of e)t.applyValue(s,n.getStyleForNextShape(s));return r||o||t.size>0?t:null},[n])}const xr={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"}]},Ss=x.memo(function(n){const{uiType:t,items:r,title:o,style:i,value:s,onValueChange:a,theme:c}=n,l=z(),u=Me(),d=x.useRef(!1),f=x.useRef(null),{handleButtonClick:p,handleButtonPointerDown:S,handleButtonPointerEnter:m,handleButtonPointerUp:w}=x.useMemo(()=>{const y=()=>{d.current=!1,window.removeEventListener("pointerup",y);const I=f.current;I&&["TEXTAREA","INPUT"].includes(I.nodeName)&&I.focus(),f.current=null};return{handleButtonClick:I=>{const{id:_}=I.currentTarget.dataset;s.type==="shared"&&s.value===_||(l.mark("point picker item"),a(i,_))},handleButtonPointerDown:I=>{const{id:_}=I.currentTarget.dataset;l.mark("point picker item"),a(i,_),d.current=!0,f.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:I=>{if(!d.current)return;const{id:_}=I.currentTarget.dataset;a(i,_)},handleButtonPointerUp:I=>{const{id:_}=I.currentTarget.dataset;s.type==="shared"&&s.value===_||a(i,_)}}},[s,l,a,i]);return h.jsx("div",{"data-testid":`style.${t}`,className:ue("tlui-buttons__grid"),children:r.map(y=>h.jsx(he,{type:"icon","data-id":y.value,"data-testid":`style.${t}.${y.value}`,"aria-label":y.value,"data-state":s.type==="shared"&&s.value===y.value?"hinted":void 0,title:o+" — "+u(`${t}-style.${y.value}`),className:ue("tlui-button-grid__button"),style:i===rr?{color:c[y.value].solid}:void 0,onPointerEnter:m,onPointerDown:S,onPointerUp:w,onClick:p,children:h.jsx(Pe,{icon:y.icon})},y.value))})});function Dj(e,[n,t]){return Math.min(t,Math.max(n,e))}function Sne(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 Rj=["PageUp","PageDown"],Lj=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],Fj={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Ku="Slider",[Uv,vne,xne]=cg(Ku),[Nj,Yoe]=bo(Ku,[xne]),[wne,bg]=Nj(Ku),bne=x.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:i=1,orientation:s="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:l=[r],value:u,onValueChange:d=()=>{},onValueCommit:f=()=>{},inverted:p=!1,...S}=e,[m,w]=x.useState(null),y=Xe(n,O=>w(O)),v=x.useRef(new Set),P=x.useRef(0),E=s==="horizontal",C=m?!!m.closest("form"):!0,I=E?Pne:Cne,[_=[],k]=Qi({prop:u,defaultProp:l,onChange:O=>{var R;(R=[...v.current][P.current])===null||R===void 0||R.focus(),d(O)}}),$=x.useRef(_);function T(O){const R=jne(_,O);j(O,R)}function A(O){j(O,P.current)}function N(){const O=$.current[P.current];_[P.current]!==O&&f(_)}function j(O,R,{commit:Y}={commit:!1}){const K=Lne(i),U=Fne(Math.round((O-r)/i)*i+r,K),H=Dj(U,[r,o]);k((W=[])=>{const Z=Mne(W,H,R);if(Rne(Z,c*i)){P.current=Z.indexOf(H);const oe=String(Z)!==String(W);return oe&&Y&&f(Z),oe?Z:W}else return W})}return x.createElement(wne,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:P,thumbs:v.current,values:_,orientation:s},x.createElement(Uv.Provider,{scope:e.__scopeSlider},x.createElement(Uv.Slot,{scope:e.__scopeSlider},x.createElement(I,Q({"aria-disabled":a,"data-disabled":a?"":void 0},S,{ref:y,onPointerDown:ae(S.onPointerDown,()=>{a||($.current=_)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:T,onSlideMove:a?void 0:A,onSlideEnd:a?void 0:N,onHomeKeyDown:()=>!a&&j(r,0,{commit:!0}),onEndKeyDown:()=>!a&&j(o,_.length-1,{commit:!0}),onStepKeyDown:({event:O,direction:R})=>{if(!a){const U=Rj.includes(O.key)||O.shiftKey&&Lj.includes(O.key)?10:1,H=P.current,W=_[H],Z=i*U*R;j(W+Z,H,{commit:!0})}}})))),C&&_.map((O,R)=>x.createElement($ne,{key:R,name:t?t+(_.length>1?"[]":""):void 0,value:O})))}),[zj,Bj]=Nj(Ku,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Pne=x.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:i,onSlideStart:s,onSlideMove:a,onSlideEnd:c,onStepKeyDown:l,...u}=e,[d,f]=x.useState(null),p=Xe(n,P=>f(P)),S=x.useRef(),m=Iw(o),w=m==="ltr",y=w&&!i||!w&&i;function v(P){const E=S.current||d.getBoundingClientRect(),C=[0,E.width],_=jw(C,y?[t,r]:[r,t]);return S.current=E,_(P-E.left)}return x.createElement(zj,{scope:e.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width"},x.createElement(Uj,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);s==null||s(E)},onSlideMove:P=>{const E=v(P.clientX);a==null||a(E)},onSlideEnd:()=>{S.current=void 0,c==null||c()},onStepKeyDown:P=>{const C=Fj[y?"from-left":"from-right"].includes(P.key);l==null||l({event:P,direction:C?-1:1})}})))}),Cne=x.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:i,onSlideMove:s,onSlideEnd:a,onStepKeyDown:c,...l}=e,u=x.useRef(null),d=Xe(n,u),f=x.useRef(),p=!o;function S(m){const w=f.current||u.current.getBoundingClientRect(),y=[0,w.height],P=jw(y,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(Uj,Q({"data-orientation":"vertical"},l,{ref:d,style:{...l.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const w=S(m.clientY);i==null||i(w)},onSlideMove:m=>{const w=S(m.clientY);s==null||s(w)},onSlideEnd:()=>{f.current=void 0,a==null||a()},onStepKeyDown:m=>{const y=Fj[p?"from-bottom":"from-top"].includes(m.key);c==null||c({event:m,direction:y?-1:1})}})))}),Uj=x.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:i,onHomeKeyDown:s,onEndKeyDown:a,onStepKeyDown:c,...l}=e,u=bg(Ku,t);return x.createElement(He.span,Q({},l,{ref:n,onKeyDown:ae(e.onKeyDown,d=>{d.key==="Home"?(s(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):Rj.concat(Lj).includes(d.key)&&(c(d),d.preventDefault())}),onPointerDown:ae(e.onPointerDown,d=>{const f=d.target;f.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(f)?f.focus():r(d)}),onPointerMove:ae(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:ae(e.onPointerUp,d=>{const f=d.target;f.hasPointerCapture(d.pointerId)&&(f.releasePointerCapture(d.pointerId),i(d))})}))}),Ine="SliderTrack",Ene=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=bg(Ine,t);return x.createElement(He.span,Q({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),$I="SliderRange",_ne=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=bg($I,t),i=Bj($I,t),s=x.useRef(null),a=Xe(n,s),c=o.values.length,l=o.values.map(f=>Hj(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,[i.startEdge]:u+"%",[i.endEdge]:d+"%"}}))}),MI="SliderThumb",kne=x.forwardRef((e,n)=>{const t=vne(e.__scopeSlider),[r,o]=x.useState(null),i=Xe(n,a=>o(a)),s=x.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return x.createElement(Tne,Q({},e,{ref:i,index:s}))}),Tne=x.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,i=bg(MI,t),s=Bj(MI,t),[a,c]=x.useState(null),l=Xe(n,w=>c(w)),u=vA(a),d=i.values[r],f=d===void 0?0:Hj(d,i.min,i.max),p=Ane(r,i.values.length),S=u==null?void 0:u[s.size],m=S?One(S,f,s.direction):0;return x.useEffect(()=>{if(a)return i.thumbs.add(a),()=>{i.thumbs.delete(a)}},[a,i.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[s.startEdge]:`calc(${f}% + ${m}px)`}},x.createElement(Uv.ItemSlot,{scope:e.__scopeSlider},x.createElement(He.span,Q({role:"slider","aria-label":e["aria-label"]||p,"aria-valuemin":i.min,"aria-valuenow":d,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0},o,{ref:l,style:d===void 0?{display:"none"}:e.style,onFocus:ae(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})}))))}),$ne=e=>{const{value:n,...t}=e,r=x.useRef(null),o=Sne(n);return x.useEffect(()=>{const i=r.current,s=window.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(s,"value").set;if(o!==n&&c){const l=new Event("input",{bubbles:!0});c.call(i,n),i.dispatchEvent(l)}},[o,n]),x.createElement("input",Q({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function Mne(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,i)=>o-i)}function Hj(e,n,t){const i=100/(t-n)*(e-n);return Dj(i,[0,100])}function Ane(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function jne(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 One(e,n,t){const r=e/2,i=jw([0,50],[0,r]);return(r-i(n)*t)*t}function Dne(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function Rne(e,n){if(n>0){const t=Dne(e);return Math.min(...t)>=n}return!0}function jw(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 Lne(e){return(String(e).split(".")[1]||"").length}function Fne(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const Nne=bne,zne=Ene,Bne=_ne,Une=kne,Hne=x.memo(function(n){const{title:t,steps:r,value:o,label:i,onValueChange:s}=n,a=z(),c=Me(),l=x.useCallback(f=>{s(f[0])},[s]),u=x.useCallback(()=>{a.mark("click slider")},[a]),d=x.useCallback(()=>{o&&s(o)},[o,s]);return h.jsx("div",{className:"tlui-slider__container",children:h.jsxs(Nne,{"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(i),children:[h.jsx(zne,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&h.jsx(Bne,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&h.jsx(Une,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Kne({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:i,itemsB:s,styleA:a,styleB:c,valueA:l,valueB:u,onValueChange:d}){const f=Me(),p=x.useMemo(()=>{var m;return((m=i.find(w=>l.type==="shared"&&l.value===w.value))==null?void 0:m.icon)??"mixed"},[i,l]),S=x.useMemo(()=>{var m;return((m=s.find(w=>u.type==="shared"&&u.value===w.value))==null?void 0:m.icon)??"mixed"},[s,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(zs,{id:`style panel ${n} A`,children:[h.jsx(Bs,{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(Us,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:i.map((m,w)=>h.jsx(Su,{"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(zs,{id:`style panel ${t}`,children:[h.jsx(Bs,{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:S,small:!0})})}),h.jsx(Us,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:s.map(m=>h.jsx(Su,{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 Wne=x.memo(Kne);function Gne({id:e,label:n,uiType:t,style:r,items:o,type:i,value:s,onValueChange:a}){const c=Me(),l=z(),u=x.useMemo(()=>{var p;return(p=o.find(S=>s.type==="shared"&&S.value===s.value))==null?void 0:p.icon},[o,s]),d=s.type==="mixed"?c("style-panel.mixed"):c(`${t}-style.${s.value}`),f=n?c(n):"";return h.jsxs(zs,{id:`style panel ${e}`,children:[h.jsx(Bs,{children:h.jsxs(he,{type:i,"data-testid":`style.${t}`,title:d,children:[h.jsx(Ct,{children:f}),h.jsx(Pe,{icon:u??"mixed"})]})}),h.jsx(Us,{side:"left",align:"center",alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:o.map(p=>h.jsx(Su,{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 Ow=x.memo(Gne);function Vne({styles:e}){const n=Bu();if(!e)return null;const t=e.get(so),r=e.get(Cf),o=e.get(Pf),i=e.get(kf),s=e.get(ho),a=t===void 0,c=r===void 0&&o===void 0,l=i===void 0,u=s===void 0,d=ei({isDarkMode:n});return h.jsxs(h.Fragment,{children:[h.jsx(Yne,{theme:d,styles:e}),!u&&h.jsx(Xne,{theme:d,styles:e}),!(a&&c&&l)&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[h.jsx(qne,{styles:e}),h.jsx(Qne,{styles:e}),h.jsx(Zne,{styles:e})]})]})}function Wu(){const e=z(),n=Co();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 Yne({styles:e,theme:n}){const t=Me(),r=z(),o=Wu(),i=e.get(rr),s=e.get(nc),a=e.get(_s),c=e.get(fo),l=s!==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:[i===void 0?null:h.jsx(Ss,{title:t("style-panel.color"),uiType:"color",style:rr,items:xr.color,value:i,onValueChange:o,theme:n}),h.jsx(Jne,{})]}),l&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[s===void 0?null:h.jsx(Ss,{title:t("style-panel.fill"),uiType:"fill",style:nc,items:xr.fill,value:s,onValueChange:o,theme:n}),a===void 0?null:h.jsx(Ss,{title:t("style-panel.dash"),uiType:"dash",style:_s,items:xr.dash,value:a,onValueChange:o,theme:n}),c===void 0?null:h.jsx(Ss,{title:t("style-panel.size"),uiType:"size",style:fo,items:xr.size,value:c,onValueChange:(u,d)=>{o(u,d);const f=r.getSelectedShapeIds();f.length>0&&We(r,f)},theme:n})]})]})}function Xne({theme:e,styles:n}){const t=Me(),r=Wu(),o=n.get(ho),i=n.get(uS),s=n.get(Ef),a=n.get(_f);return o===void 0&&s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:h.jsx(Ss,{title:t("style-panel.font"),uiType:"font",style:ho,items:xr.font,value:o,onValueChange:r,theme:e}),i===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(Ss,{title:t("style-panel.align"),uiType:"align",style:uS,items:xr.textAlign,value:i,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"})})})]}),s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(Ss,{title:t("style-panel.align"),uiType:"align",style:Ef,items:xr.horizontalAlign,value:s,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(Ow,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:_f,items:xr.verticalAlign,value:a,onValueChange:r})})]})]})}function qne({styles:e}){const n=Wu(),t=e.get(so);return t===void 0?null:h.jsx(Ow,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:so,items:xr.geo,value:t,onValueChange:n})}function Zne({styles:e}){const n=Wu(),t=e.get(kf);return t===void 0?null:h.jsx(Ow,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:kf,items:xr.spline,value:t,onValueChange:n})}function Qne({styles:e}){const n=Wu(),t=e.get(Cf),r=e.get(Pf);return!t||!r?null:h.jsx(Wne,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Pf,itemsA:xr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Cf,itemsB:xr.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const al=[.1,.25,.5,.75,1];function Jne(){const e=z(),n=G("opacity",()=>e.getSharedOpacity(),[e]),t=Co(),r=Me(),o=Se.useCallback(s=>{const a=al[s];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(a),e.setOpacityForNextShapes(a),e.updateInstanceState({isChangingStyle:!0})}),t("set-style",{source:"style-panel",id:"opacity",value:s})},[e,t]);if(n===void 0)return null;const i=n.type==="mixed"?-1:al.indexOf(yN(al,s=>Math.abs(s-n.value)));return h.jsx(Hne,{"data-testid":"style.opacity",value:i>=0?i:al.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:al.length-1,title:r("style-panel.opacity")})}const ere=x.memo(function({isMobile:n,children:t}){const r=z(),o=Oj(),i=x.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1})},[r,n]),s=t??h.jsx(Vne,{styles:o});return h.jsx("div",{className:ue("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:i,children:s})});function tre(){const e=z(),n=Me(),t=Oj(),r=t==null?void 0:t.get(rr),o=ei({isDarkMode:e.user.getIsDarkMode()}),i=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,s=G("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(l=>{l||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:c}=ns();return c?h.jsxs(bw,{id:"mobile style menu",onOpenChange:a,children:[h.jsx(Pw,{children:h.jsx(he,{type:"tool","data-testid":"mobile-styles.button",style:{color:s?"var(--color-muted-1)":i},title:n("style-panel.title"),disabled:s,children:h.jsx(Pe,{icon:s?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),h.jsx(Cw,{side:"top",align:"end",children:c&&h.jsx(c,{isMobile:!0})})]}):null}function nre(){return h.jsxs(h.Fragment,{children:[h.jsx(ore,{}),h.jsx(ire,{}),h.jsx(sre,{}),h.jsx(are,{}),h.jsx(cre,{}),h.jsx(lre,{}),h.jsx(ure,{}),h.jsx(dre,{}),h.jsx(hre,{}),h.jsx(fre,{}),h.jsx(gre,{}),h.jsx(pre,{}),h.jsx(Sre,{}),h.jsx(wre,{}),h.jsx(mre,{}),h.jsx(xre,{}),h.jsx(vre,{}),h.jsx(yre,{}),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(Mre,{}),h.jsx($re,{})]})}function rre(e){var r;const n=z(),t=(r=e.meta)==null?void 0:r.geo;return G("is tool selected",()=>{const o=n.getCurrentToolId(),i=n.getSharedStyles().getAsKnownValue(so);return t?o==="geo"&&i===t:o===e.id},[n,e.id,t])}function Ke({tool:e}){const n=pg(),t=rre(n[e]);return h.jsx(B,{...n[e],isSelected:t})}function ore(){return h.jsx(Ke,{tool:"select"})}function ire(){return h.jsx(Ke,{tool:"hand"})}function sre(){return h.jsx(Ke,{tool:"draw"})}function are(){return h.jsx(Ke,{tool:"eraser"})}function cre(){return h.jsx(Ke,{tool:"arrow"})}function lre(){return h.jsx(Ke,{tool:"text"})}function ure(){return h.jsx(Ke,{tool:"note"})}function dre(){const e=pg();return h.jsx(B,{...e.asset})}function hre(){return h.jsx(Ke,{tool:"rectangle"})}function fre(){return h.jsx(Ke,{tool:"ellipse"})}function pre(){return h.jsx(Ke,{tool:"diamond"})}function gre(){return h.jsx(Ke,{tool:"triangle"})}function mre(){return h.jsx(Ke,{tool:"rhombus"})}function yre(){return h.jsx(Ke,{tool:"heart"})}function Sre(){return h.jsx(Ke,{tool:"hexagon"})}function vre(){return h.jsx(Ke,{tool:"cloud"})}function xre(){return h.jsx(Ke,{tool:"star"})}function wre(){return h.jsx(Ke,{tool:"oval"})}function bre(){return h.jsx(Ke,{tool:"x-box"})}function Pre(){return h.jsx(Ke,{tool:"check-box"})}function Cre(){return h.jsx(Ke,{tool:"arrow-left"})}function Ire(){return h.jsx(Ke,{tool:"arrow-up"})}function Ere(){return h.jsx(Ke,{tool:"arrow-down"})}function _re(){return h.jsx(Ke,{tool:"arrow-right"})}function kre(){return h.jsx(Ke,{tool:"line"})}function Tre(){return h.jsx(Ke,{tool:"highlight"})}function $re(){return h.jsx(Ke,{tool:"frame"})}function Mre(){return h.jsx(Ke,{tool:"laser"})}const Sy=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function vy(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function cl(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function Kj(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 Wj(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 Are(e,n){const t=e.length>=n.length?e:n,r=e.length>=n.length?n:e;let o=!0;for(let i=0;i<t.length;i++)r.indexOf(t[i])===-1&&(o=!1);return o}const vu={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,"-":Sy?173:189,"=":Sy?61:187,";":Sy?59:186,"'":222,"[":219,"]":221,"\\":220},yo={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Hv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Lt={16:!1,18:!1,17:!1,91:!1},dt={};for(let e=1;e<20;e++)vu["f".concat(e)]=111+e;let Ge=[],Rl=null,Gj="all";const jo=new Map,Gu=e=>vu[e.toLowerCase()]||yo[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),jre=e=>Object.keys(vu).find(n=>vu[n]===e),Ore=e=>Object.keys(yo).find(n=>yo[n]===e);function Vj(e){Gj=e||"all"}function xu(){return Gj||"all"}function Dre(){return Ge.slice(0)}function Rre(){return Ge.map(e=>jre(e)||Ore(e)||String.fromCharCode(e))}function Lre(){const e=[];return Object.keys(dt).forEach(n=>{dt[n].forEach(t=>{let{key:r,scope:o,mods:i,shortcut:s}=t;e.push({scope:o,shortcut:s,mods:i,keys:r.split("+").map(a=>Gu(a))})})}),e}function Fre(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 Nre(e){return typeof e=="string"&&(e=Gu(e)),Ge.indexOf(e)!==-1}function zre(e,n){let t,r;e||(e=xu());for(const o in dt)if(Object.prototype.hasOwnProperty.call(dt,o))for(t=dt[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(s=>{let{element:a}=s;return Dw(a)}):r++;xu()===e&&Vj(n||"all")}function Bre(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 Lt){Lt[n]=!1;for(const r in yo)yo[r]===n&&($n[r]=!1)}}function Yj(e){if(typeof e>"u")Object.keys(dt).forEach(o=>{Array.isArray(dt[o])&&dt[o].forEach(i=>th(i)),delete dt[o]}),Dw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&th(o)});else if(typeof e=="object")e.key&&th(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,i]=t;typeof o=="function"&&(i=o,o=""),th({key:e,scope:o,method:i,splitKey:"+"})}}const th=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;Wj(n).forEach(s=>{const a=s.split(o),c=a.length,l=a[c-1],u=l==="*"?"*":Gu(l);if(!dt[u])return;t||(t=xu());const d=c>1?Kj(yo,a):[],f=[];dt[u]=dt[u].filter(p=>{const m=(r?p.method===r:!0)&&p.scope===t&&Are(p.mods,d);return m&&f.push(p.element),!m}),f.forEach(p=>Dw(p))})};function AI(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 i in Lt)Object.prototype.hasOwnProperty.call(Lt,i)&&(!Lt[i]&&n.mods.indexOf(+i)>-1||Lt[i]&&n.mods.indexOf(+i)===-1)&&(o=!1);(n.mods.length===0&&!Lt[16]&&!Lt[18]&&!Lt[17]&&!Lt[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 jI(e,n){const t=dt["*"];let r=e.keyCode||e.which||e.charCode;if(!$n.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=Hv[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 Lt){Lt[r]=!0;for(const a in yo)yo[a]===r&&($n[a]=!0);if(!t)return}for(const a in Lt)Object.prototype.hasOwnProperty.call(Lt,a)&&(Lt[a]=e[Hv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Ge.indexOf(17)===-1&&Ge.push(17),Ge.indexOf(18)===-1&&Ge.push(18),Lt[17]=!0,Lt[18]=!0);const o=xu();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)&&AI(e,t[a],o,n);if(!(r in dt))return;const i=dt[r],s=i.length;for(let a=0;a<s;a++)if((e.type==="keydown"&&i[a].keydown||e.type==="keyup"&&i[a].keyup)&&i[a].key){const c=i[a],{splitKey:l}=c,u=c.key.split(l),d=[];for(let f=0;f<u.length;f++)d.push(Gu(u[f]));d.sort().join("")===Ge.sort().join("")&&AI(e,c,o,n)}}function $n(e,n,t){Ge=[];const r=Wj(e);let o=[],i="all",s=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&&(i=n.scope),n.element&&(s=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"&&(i=n),f&&Yj(e,i);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=Kj(yo,e)),e=e[e.length-1],e=e==="*"?"*":Gu(e),e in dt||(dt[e]=[]),dt[e].push({keyup:c,keydown:l,scope:i,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:u,element:s});if(typeof s<"u"&&window){if(!jo.has(s)){const p=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return jI(m,s)},S=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;jI(m,s),Bre(m)};jo.set(s,{keydownListener:p,keyupListenr:S,capture:d}),vy(s,"keydown",p,d),vy(s,"keyup",S,d)}if(!Rl){const p=()=>{Ge=[]};Rl={listener:p,capture:d},vy(window,"focus",p,d)}}}function Ure(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(dt).forEach(t=>{dt[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function Dw(e){const n=Object.values(dt).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:i}=jo.get(e)||{};r&&o&&(cl(e,"keyup",o,i),cl(e,"keydown",r,i),jo.delete(e))}if((n.length<=0||jo.size<=0)&&(Object.keys(jo).forEach(o=>{const{keydownListener:i,keyupListenr:s,capture:a}=jo.get(o)||{};i&&s&&(cl(o,"keyup",s,a),cl(o,"keydown",i,a),jo.delete(o))}),jo.clear(),Object.keys(dt).forEach(o=>delete dt[o]),Rl)){const{listener:o,capture:i}=Rl;cl(window,"focus",o,i),Rl=null}}const xy={getPressedKeyString:Rre,setScope:Vj,getScope:xu,deleteScope:zre,getPressedKeyCodes:Dre,getAllKeyCodes:Lre,isPressed:Nre,filter:Fre,trigger:Ure,unbind:Yj,keyMap:vu,modifier:yo,modifierMap:Hv};for(const e in xy)Object.prototype.hasOwnProperty.call(xy,e)&&($n[e]=xy[e]);if(typeof window<"u"){const e=window.hotkeys;$n.noConflict=n=>(n&&window.hotkeys===$n&&(window.hotkeys=e),$n),window.hotkeys=$n}const OI=["copy","cut","paste","asset"];function Hre(){const e=z(),n=ni(),t=le(),r=pg(),o=G("is focused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!o)return;const i=new Array,s=(c,l)=>{$n(c,{element:document.body},l),i.push(()=>{$n.unbind(c,l)})},a=(c,l)=>{$n(c,{element:document.body,keyup:!0,keydown:!1},l),i.push(()=>{$n.unbind(c,l)})};for(const c of Object.values(t))c.kbd&&(n&&!c.readonlyOk||OI.includes(c.id)||s(DI(c.kbd),l=>{xl(e)||(_e(l),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&e.getInstanceState().isReadonly||OI.includes(c.id)||s(DI(c.kbd),l=>{xl(e)||(_e(l),c.onSelect("kbd"))});return s(",",c=>{if(xl(e)||e.inputs.keys.has("Comma"))return;_e(c),e.focus(),e.inputs.keys.add("Comma");const{x:l,y:u,z:d}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_down",point:{x:l,y:u,z:d},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),a(",",c=>{if(xl(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:l,y:u,z:d}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_up",point:{x:l,y:u,z:d},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),()=>{i.forEach(c=>c())}},[t,r,n,e,o])}function DI(e){return Kre(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 Kre(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 xl(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const Wre=x.createContext(!1);function Gre({children:e}){const n=z(),t=kW(),r=Nn(),o=Me(),i=Math.min(8,5+r),[s,a]=x.useState(0),c=x.useRef(null),[l,u]=x.useState(null),d=x.useMemo(()=>{const p=l?`:not([data-value="${l}"])`:"";return`
310
- #${t}_main > *:nth-child(n + ${i+(l?1:2)})${p} {
311
- display: none;
312
- }
313
- #${t}_more > *:nth-child(-n + ${i}) {
314
- display: none;
315
- }
316
- `},[l,t,i]),f=Nx(()=>{if(!c.current)return;const p=Array.from(c.current.children);a(p.length),p.findIndex(w=>w.getAttribute("data-value")===l)<=i&&u(null);const m=Array.from(c.current.children).findIndex(w=>w.getAttribute("aria-checked")==="true");m!==-1&&m>=i&&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[S,m]of p)$n(S,w=>{var P;if(xl(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()=>{$n.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<xt.TABLET_SM}),role:"radiogroup",children:[h.jsx("div",{id:`${t}_main`,ref:c,className:"tlui-toolbar__tools__list",children:h.jsx(Cr,{type:"toolbar",sourceId:"toolbar",children:e})}),s>i+1&&h.jsx(Wre.Provider,{value:!0,children:h.jsxs(zs,{id:"toolbar overflow",modal:!1,children:[h.jsx(Bs,{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(Us,{side:"top",align:"center",children:h.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:h.jsx(Cr,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const Vre=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Yre({activeToolId:e}){const n=z(),t=Nn(),r=Me(),o=G("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||Vre.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<xt.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:h.jsx(Pe,{icon:o?"lock":"unlock",small:!0})})}const Xre=x.memo(function({children:n}){const t=z(),r=Nn(),o=ni(),i=G("current tool id",()=>t.getCurrentToolId(),[t]),{ActionsMenu:s,QuickActions:a}=ns();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<xt.TABLET&&h.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&h.jsx(a,{}),s&&h.jsx(s,{})]}),h.jsx(Yre,{activeToolId:i})]}),h.jsx(Gre,{children:n??h.jsx(nre,{})})]}),r<xt.TABLET_SM&&!o&&h.jsx("div",{className:"tlui-toolbar__tools",children:h.jsx(tre,{})})]})})});function qre(){const e=le();return h.jsxs(h.Fragment,{children:[h.jsx(B,{...e["zoom-in"],noClose:!0}),h.jsx(B,{...e["zoom-out"],noClose:!0}),h.jsx(Pj,{}),h.jsx(Cj,{}),h.jsx(Ij,{})]})}const Zre=x.memo(function({children:n}){const t=ln(),[r,o]=Ji("zoom menu"),i=n??h.jsx(qre,{});return h.jsxs(Tw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx($w,{asChild:!0,dir:"ltr",children:h.jsx(Qre,{})}),h.jsx(wg,{container:t,children:h.jsx(Mw,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:h.jsx(Cr,{type:"menu",sourceId:"zoom-menu",children:i})})})]})}),Qre=x.forwardRef(function(n,t){const r=z(),o=Nn(),i=G("zoom",()=>r.getZoomLevel(),[r]),s=Me(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return h.jsx(he,{ref:t,...n,type:"icon",title:`${s("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<xt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<xt.MOBILE?"zoom-in":void 0,children:o<xt.MOBILE?null:h.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(i*100),"%"]})})}),Xj=x.createContext(null);function Jre({overrides:e={},children:n}){const t=B0(e);return h.jsx(Xj.Provider,{value:x.useMemo(()=>({ContextMenu:kte,ActionsMenu:ote,HelpMenu:Bte,ZoomMenu:Zre,MainMenu:one,Minimap:une,StylePanel:ere,PageMenu:pne,NavigationPanel:hne,Toolbar:Xre,KeyboardShortcutsDialog:Yte,QuickActions:mne,HelperButtons:Gte,DebugPanel:Dte,DebugMenu:Ote,MenuPanel:ine,...t}),[t]),children:n})}function ns(){const e=x.useContext(Xj);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function eoe({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:i}){return h.jsx(sY,{assetUrls:Vq(t),children:h.jsx(lY,{overrides:Qq(e),children:h.jsx(aq,{onEvent:r,children:h.jsx(zq,{children:h.jsx(cq,{children:h.jsx(Xq,{forceMobile:o,children:h.jsx(Jre,{overrides:n,children:h.jsx(toe,{overrides:e,children:i})})})})})})})})}function toe({overrides:e,children:n}){const t=Jq(e);return h.jsx(LZ,{overrides:t.actions,children:h.jsx(Yq,{overrides:t.tools,children:n})})}function noe(){const e=z(),{addToast:n}=Gr();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 roe=Se.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...i}){return h.jsx(eoe,{...i,components:o,children:h.jsx(ooe,{hideUi:r,renderDebugMenuItems:n,children:t})})}),ooe=Se.memo(function({children:n,hideUi:t,...r}){return h.jsxs(h.Fragment,{children:[n,t?null:h.jsx(soe,{...r}),h.jsx(ioe,{})]})});function ioe(){const{InFrontOfTheCanvas:e}=st();return e?h.jsx("div",{className:"tl-front",children:h.jsx(e,{})}):null}const soe=Se.memo(function(){const n=z(),t=Me(),r=Nn(),o=ni(),i=G("focus",()=>n.getInstanceState().isFocusMode,[n]),s=G("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:c,MenuPanel:l,StylePanel:u,Toolbar:d,HelpMenu:f,NavigationPanel:p,HelperButtons:S,DebugPanel:m}=ns();Hre(),EZ(),noe();const{"toggle-focus-mode":w}=le();return h.jsxs("div",{className:ue("tlui-layout",{"tlui-layout__mobile":r<xt.TABLET_SM}),"data-breakpoint":r,children:[i?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,{}),S&&h.jsx(S,{})]}),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>=xt.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,{})]}),s&&m&&h.jsx(m,{})]})]}),h.jsx(Kq,{}),h.jsx(dq,{}),h.jsx(Wq,{}),h.jsx(hq,{})]})});async function aoe(e,n){const{url:t,style:r="normal",weight:o="500",display:i,featureSettings:s,stretch:a,unicodeRange:c,variant:l,format:u}=n,d={style:r,weight:o,display:i,featureSettings:s,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=`
317
- @font-face {
318
- font-family: ${f.family};
319
- font-stretch: ${f.stretch};
320
- font-weight: ${f.weight};
321
- font-style: ${f.style};
322
- src: url("${t}") format("${u}")
323
- }`,f}const nh=(e,n)=>{const[t,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),aoe(e,n).then(()=>{o||r(0)}).catch(i=>{o||(console.error(i),r(1))}),()=>{o=!0}},[e,n]),t};function coe(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 qj(e){const n=x.useMemo(()=>coe(e),[e]),t=[nh("tldraw_draw",n.draw),nh("tldraw_serif",n.serif),nh("tldraw_sans",n.sansSerif),nh("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function loe(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:i,onMount:s,components:a={},shapeUtils:c=[],bindingUtils:l=[],tools:u=[],...d}=e,f=B0(a),p=x.useMemo(()=>({Scribble:gC,CollaboratorScribble:gC,SelectionForeground:HW,SelectionBackground:BW,Handles:RW,...f}),[f]),S=Cl(c),m=x.useMemo(()=>[...X$,...S],[S]),w=Cl(l),y=x.useMemo(()=>[...p$,...w],[w]),v=Cl(u),P=x.useMemo(()=>[...OY,...UG,...v],[v]),E=qM(d.assetUrls),{done:C,error:I}=qj(E);return I?h.jsx(u$,{children:"Could not load assets. Please refresh the page."}):C?h.jsx(wW,{initialState:"select",...d,components:p,shapeUtils:m,bindingUtils:y,tools:P,children:h.jsxs(roe,{...d,components:p,children:[h.jsx(uoe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:i,onMount:s}),n]})}):h.jsx(Ux,{children:"Loading assets..."})}function uoe({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=m0,acceptedVideoMimeTypes:r=VE,onMount:o}){const i=z(),s=Gr(),a=Me(),c=Nx(d=>{const f=[];return f.push(...SY(d)),IG(d,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:s,msg:a}),f.push(o==null?void 0:o(d)),()=>{f.forEach(p=>p==null?void 0:p())}});x.useLayoutEffect(()=>{if(i)return c==null?void 0:c(i)},[i,c]);const{Canvas:l}=st(),{ContextMenu:u}=ns();return u?h.jsx(u,{}):l?h.jsx(l,{}):null}x.memo(function(n){const[t,r]=x.useState(null),[o,i]=x.useState(null),s=Cl(n.shapeUtils??[]),a=x.useMemo(()=>[...X$,...s],[s]),c=Cl(n.bindingUtils??[]),l=x.useMemo(()=>[...p$,...c],[c]),u=a$({snapshot:n.snapshot,shapeUtils:a}),d=qM(),{done:f,error:p}=qj(d),{pageId:S,bounds:m,scale:w,background:y,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:()=>_});S&&k.setCurrentPage(S);const $=k.getCurrentPageShapeIds();async function T(){const A=await k.getSvgString([...$],{bounds:m,scale:w,background:y,padding:v,darkMode:P,preserveAspectRatio:E});if(A&&!I){if(C==="svg"){if(!I){const N=new Blob([A.svg],{type:"image/svg+xml"}),j=URL.createObjectURL(N);r(j)}}else if(C==="png"){const N=await sA(k,A.svg,{type:C,quality:1,scale:2,width:A.width,height:A.height});if(N&&!I){const j=URL.createObjectURL(N);r(j)}}}k.dispose()}return T(),()=>{I=!0}},[C,o,u,a,l,S,m,w,y,v,P,E,f,p]),p?h.jsx(u$,{children:"Could not load assets."}):f?h.jsx("div",{ref:i,style:{position:"relative",width:"100%",height:"100%"},children:t&&h.jsx("img",{src:t,style:{width:"100%",height:"100%"}})}):h.jsx(Ux,{children:"Loading assets..."})});const doe=1,hoe=ve({schemaVersion:sn(1),storeVersion:uh,recordVersions:wf(pe,ve({version:uh,subTypeVersions:wf(pe,uh).optional(),subTypeKey:pe.optional()}))}),foe=ve({schemaVersion:sn(2),sequences:wf(pe,uh)}),poe=ve({tldrawFileFormatVersion:E4,schema:_4("schemaVersion",{1:hoe,2:foe}),records:Nt(ve({id:pe,typeName:pe}).allowUnknownProperties())});function goe(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function moe({json:e,schema:n}){let t;try{t=poe.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),goe(t))return hn.err({type:"v1File",data:t})}catch{}return hn.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>doe)return hn.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=yoe(t.records),i=Object.fromEntries(o.map(s=>[s.id,s]));r=n.migrateStoreSnapshot({store:i,schema:t.schema})}catch(o){return hn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return hn.err({type:"migrationFailed",reason:r.reason});try{return hn.ok(s$({initialData:r.value,schema:n}))}catch(o){return hn.err({type:"invalidRecords",cause:o})}}function yoe(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 Soe(){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 i=moe({json:o,schema:r.store.schema});i.ok?(console.log("Loaded tldr file from local endpoint"),n(i.value)):console.error(`Couldn't parse tldr file: ${String(i.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(loe,{assetUrls:ID(),onMount:t,store:e})})}av.createRoot(document.querySelector("#root")).render(h.jsx(Se.StrictMode,{children:h.jsx(Soe,{})}));