@kitschpatrol/tldraw-cli 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,315 @@
1
+ var TO=Object.defineProperty;var $O=(e,n,t)=>n in e?TO(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var y=(e,n,t)=>($O(e,typeof n!="symbol"?n+"":n,t),t);function AO(e,n){for(var t=0;t<n.length;t++){const r=n[t];if(typeof r!="string"&&!Array.isArray(r)){for(const o in r)if(o!=="default"&&!(o in e)){const s=Object.getOwnPropertyDescriptor(r,o);s&&Object.defineProperty(e,o,s.get?s:{enumerable:!0,get:()=>r[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const o of document.querySelectorAll('link[rel="modulepreload"]'))r(o);new MutationObserver(o=>{for(const s of o)if(s.type==="childList")for(const i of s.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function t(o){const s={};return o.integrity&&(s.integrity=o.integrity),o.referrerPolicy&&(s.referrerPolicy=o.referrerPolicy),o.crossOrigin==="use-credentials"?s.credentials="include":o.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(o){if(o.ep)return;o.ep=!0;const s=t(o);fetch(o.href,s)}})();var Xt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ka(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var XC={exports:{}},Zp={},qC={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 ou=Symbol.for("react.element"),MO=Symbol.for("react.portal"),OO=Symbol.for("react.fragment"),RO=Symbol.for("react.strict_mode"),DO=Symbol.for("react.profiler"),jO=Symbol.for("react.provider"),LO=Symbol.for("react.context"),NO=Symbol.for("react.forward_ref"),FO=Symbol.for("react.suspense"),zO=Symbol.for("react.memo"),BO=Symbol.for("react.lazy"),fx=Symbol.iterator;function UO(e){return e===null||typeof e!="object"?null:(e=fx&&e[fx]||e["@@iterator"],typeof e=="function"?e:null)}var ZC={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},QC=Object.assign,JC={};function Wa(e,n,t){this.props=e,this.context=n,this.refs=JC,this.updater=t||ZC}Wa.prototype.isReactComponent={};Wa.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")};Wa.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function eE(){}eE.prototype=Wa.prototype;function gv(e,n,t){this.props=e,this.context=n,this.refs=JC,this.updater=t||ZC}var mv=gv.prototype=new eE;mv.constructor=gv;QC(mv,Wa.prototype);mv.isPureReactComponent=!0;var gx=Array.isArray,tE=Object.prototype.hasOwnProperty,yv={current:null},nE={key:!0,ref:!0,__self:!0,__source:!0};function rE(e,n,t){var r,o={},s=null,i=null;if(n!=null)for(r in n.ref!==void 0&&(i=n.ref),n.key!==void 0&&(s=""+n.key),n)tE.call(n,r)&&!nE.hasOwnProperty(r)&&(o[r]=n[r]);var a=arguments.length-2;if(a===1)o.children=t;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];o.children=l}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:ou,type:e,key:s,ref:i,props:o,_owner:yv.current}}function HO(e,n){return{$$typeof:ou,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Sv(e){return typeof e=="object"&&e!==null&&e.$$typeof===ou}function VO(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var mx=/\/+/g;function ag(e,n){return typeof e=="object"&&e!==null&&e.key!=null?VO(""+e.key):n.toString(36)}function Gd(e,n,t,r,o){var s=typeof e;(s==="undefined"||s==="boolean")&&(e=null);var i=!1;if(e===null)i=!0;else switch(s){case"string":case"number":i=!0;break;case"object":switch(e.$$typeof){case ou:case MO:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+ag(i,0):r,gx(o)?(t="",e!=null&&(t=e.replace(mx,"$&/")+"/"),Gd(o,n,t,"",function(c){return c})):o!=null&&(Sv(o)&&(o=HO(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(mx,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",gx(e))for(var a=0;a<e.length;a++){s=e[a];var l=r+ag(s,a);i+=Gd(s,n,t,l,o)}else if(l=UO(e),typeof l=="function")for(e=l.call(e),a=0;!(s=e.next()).done;)s=s.value,l=r+ag(s,a++),i+=Gd(s,n,t,l,o);else if(s==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return i}function Hu(e,n,t){if(e==null)return e;var r=[],o=0;return Gd(e,r,"","",function(s){return n.call(t,s,o++)}),r}function KO(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 ln={current:null},Yd={transition:null},WO={ReactCurrentDispatcher:ln,ReactCurrentBatchConfig:Yd,ReactCurrentOwner:yv};xe.Children={map:Hu,forEach:function(e,n,t){Hu(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return Hu(e,function(){n++}),n},toArray:function(e){return Hu(e,function(n){return n})||[]},only:function(e){if(!Sv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};xe.Component=Wa;xe.Fragment=OO;xe.Profiler=DO;xe.PureComponent=gv;xe.StrictMode=RO;xe.Suspense=FO;xe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=WO;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=QC({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=yv.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in n)tE.call(n,l)&&!nE.hasOwnProperty(l)&&(r[l]=n[l]===void 0&&a!==void 0?a[l]:n[l])}var l=arguments.length-2;if(l===1)r.children=t;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:ou,type:e.type,key:o,ref:s,props:r,_owner:i}};xe.createContext=function(e){return e={$$typeof:LO,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:jO,_context:e},e.Consumer=e};xe.createElement=rE;xe.createFactory=function(e){var n=rE.bind(null,e);return n.type=e,n};xe.createRef=function(){return{current:null}};xe.forwardRef=function(e){return{$$typeof:NO,render:e}};xe.isValidElement=Sv;xe.lazy=function(e){return{$$typeof:BO,_payload:{_status:-1,_result:e},_init:KO}};xe.memo=function(e,n){return{$$typeof:zO,type:e,compare:n===void 0?null:n}};xe.startTransition=function(e){var n=Yd.transition;Yd.transition={};try{e()}finally{Yd.transition=n}};xe.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.")};xe.useCallback=function(e,n){return ln.current.useCallback(e,n)};xe.useContext=function(e){return ln.current.useContext(e)};xe.useDebugValue=function(){};xe.useDeferredValue=function(e){return ln.current.useDeferredValue(e)};xe.useEffect=function(e,n){return ln.current.useEffect(e,n)};xe.useId=function(){return ln.current.useId()};xe.useImperativeHandle=function(e,n,t){return ln.current.useImperativeHandle(e,n,t)};xe.useInsertionEffect=function(e,n){return ln.current.useInsertionEffect(e,n)};xe.useLayoutEffect=function(e,n){return ln.current.useLayoutEffect(e,n)};xe.useMemo=function(e,n){return ln.current.useMemo(e,n)};xe.useReducer=function(e,n,t){return ln.current.useReducer(e,n,t)};xe.useRef=function(e){return ln.current.useRef(e)};xe.useState=function(e){return ln.current.useState(e)};xe.useSyncExternalStore=function(e,n,t){return ln.current.useSyncExternalStore(e,n,t)};xe.useTransition=function(){return ln.current.useTransition()};xe.version="18.2.0";qC.exports=xe;var w=qC.exports;const ne=Ka(w),GO=AO({__proto__:null,default:ne},[w]);/**
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 YO=w,XO=Symbol.for("react.element"),qO=Symbol.for("react.fragment"),ZO=Object.prototype.hasOwnProperty,QO=YO.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,JO={key:!0,ref:!0,__self:!0,__source:!0};function oE(e,n,t){var r,o={},s=null,i=null;t!==void 0&&(s=""+t),n.key!==void 0&&(s=""+n.key),n.ref!==void 0&&(i=n.ref);for(r in n)ZO.call(n,r)&&!JO.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:XO,type:e,key:s,ref:i,props:o,_owner:QO.current}}Zp.Fragment=qO;Zp.jsx=oE;Zp.jsxs=oE;XC.exports=Zp;var g=XC.exports;function M(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 eR(e){return{fonts:{monospace:M("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:M("./fonts/IBMPlexSans-Medium.woff2",e),serif:M("./fonts/IBMPlexSerif-Medium.woff2",e),draw:M("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom-center":M("./icons/icon/align-bottom-center.svg",e),"align-bottom-left":M("./icons/icon/align-bottom-left.svg",e),"align-bottom-right":M("./icons/icon/align-bottom-right.svg",e),"align-bottom":M("./icons/icon/align-bottom.svg",e),"align-center-center":M("./icons/icon/align-center-center.svg",e),"align-center-horizontal":M("./icons/icon/align-center-horizontal.svg",e),"align-center-left":M("./icons/icon/align-center-left.svg",e),"align-center-right":M("./icons/icon/align-center-right.svg",e),"align-center-vertical":M("./icons/icon/align-center-vertical.svg",e),"align-left":M("./icons/icon/align-left.svg",e),"align-right":M("./icons/icon/align-right.svg",e),"align-top-center":M("./icons/icon/align-top-center.svg",e),"align-top-left":M("./icons/icon/align-top-left.svg",e),"align-top-right":M("./icons/icon/align-top-right.svg",e),"align-top":M("./icons/icon/align-top.svg",e),"arrow-left":M("./icons/icon/arrow-left.svg",e),"arrowhead-arrow":M("./icons/icon/arrowhead-arrow.svg",e),"arrowhead-bar":M("./icons/icon/arrowhead-bar.svg",e),"arrowhead-diamond":M("./icons/icon/arrowhead-diamond.svg",e),"arrowhead-dot":M("./icons/icon/arrowhead-dot.svg",e),"arrowhead-none":M("./icons/icon/arrowhead-none.svg",e),"arrowhead-square":M("./icons/icon/arrowhead-square.svg",e),"arrowhead-triangle-inverted":M("./icons/icon/arrowhead-triangle-inverted.svg",e),"arrowhead-triangle":M("./icons/icon/arrowhead-triangle.svg",e),"aspect-ratio":M("./icons/icon/aspect-ratio.svg",e),avatar:M("./icons/icon/avatar.svg",e),blob:M("./icons/icon/blob.svg",e),"bring-forward":M("./icons/icon/bring-forward.svg",e),"bring-to-front":M("./icons/icon/bring-to-front.svg",e),check:M("./icons/icon/check.svg",e),"checkbox-checked":M("./icons/icon/checkbox-checked.svg",e),"checkbox-empty":M("./icons/icon/checkbox-empty.svg",e),"chevron-down":M("./icons/icon/chevron-down.svg",e),"chevron-left":M("./icons/icon/chevron-left.svg",e),"chevron-right":M("./icons/icon/chevron-right.svg",e),"chevron-up":M("./icons/icon/chevron-up.svg",e),"chevrons-ne":M("./icons/icon/chevrons-ne.svg",e),"chevrons-sw":M("./icons/icon/chevrons-sw.svg",e),"clipboard-copied":M("./icons/icon/clipboard-copied.svg",e),"clipboard-copy":M("./icons/icon/clipboard-copy.svg",e),code:M("./icons/icon/code.svg",e),collab:M("./icons/icon/collab.svg",e),color:M("./icons/icon/color.svg",e),comment:M("./icons/icon/comment.svg",e),"cross-2":M("./icons/icon/cross-2.svg",e),cross:M("./icons/icon/cross.svg",e),"dash-dashed":M("./icons/icon/dash-dashed.svg",e),"dash-dotted":M("./icons/icon/dash-dotted.svg",e),"dash-draw":M("./icons/icon/dash-draw.svg",e),"dash-solid":M("./icons/icon/dash-solid.svg",e),discord:M("./icons/icon/discord.svg",e),"distribute-horizontal":M("./icons/icon/distribute-horizontal.svg",e),"distribute-vertical":M("./icons/icon/distribute-vertical.svg",e),dot:M("./icons/icon/dot.svg",e),"dots-horizontal":M("./icons/icon/dots-horizontal.svg",e),"dots-vertical":M("./icons/icon/dots-vertical.svg",e),"drag-handle-dots":M("./icons/icon/drag-handle-dots.svg",e),duplicate:M("./icons/icon/duplicate.svg",e),edit:M("./icons/icon/edit.svg",e),"external-link":M("./icons/icon/external-link.svg",e),file:M("./icons/icon/file.svg",e),"fill-none":M("./icons/icon/fill-none.svg",e),"fill-pattern":M("./icons/icon/fill-pattern.svg",e),"fill-semi":M("./icons/icon/fill-semi.svg",e),"fill-solid":M("./icons/icon/fill-solid.svg",e),follow:M("./icons/icon/follow.svg",e),following:M("./icons/icon/following.svg",e),"font-draw":M("./icons/icon/font-draw.svg",e),"font-mono":M("./icons/icon/font-mono.svg",e),"font-sans":M("./icons/icon/font-sans.svg",e),"font-serif":M("./icons/icon/font-serif.svg",e),"geo-arrow-down":M("./icons/icon/geo-arrow-down.svg",e),"geo-arrow-left":M("./icons/icon/geo-arrow-left.svg",e),"geo-arrow-right":M("./icons/icon/geo-arrow-right.svg",e),"geo-arrow-up":M("./icons/icon/geo-arrow-up.svg",e),"geo-check-box":M("./icons/icon/geo-check-box.svg",e),"geo-cloud":M("./icons/icon/geo-cloud.svg",e),"geo-diamond":M("./icons/icon/geo-diamond.svg",e),"geo-ellipse":M("./icons/icon/geo-ellipse.svg",e),"geo-hexagon":M("./icons/icon/geo-hexagon.svg",e),"geo-octagon":M("./icons/icon/geo-octagon.svg",e),"geo-oval":M("./icons/icon/geo-oval.svg",e),"geo-pentagon":M("./icons/icon/geo-pentagon.svg",e),"geo-rectangle":M("./icons/icon/geo-rectangle.svg",e),"geo-rhombus-2":M("./icons/icon/geo-rhombus-2.svg",e),"geo-rhombus":M("./icons/icon/geo-rhombus.svg",e),"geo-star":M("./icons/icon/geo-star.svg",e),"geo-trapezoid":M("./icons/icon/geo-trapezoid.svg",e),"geo-triangle":M("./icons/icon/geo-triangle.svg",e),"geo-x-box":M("./icons/icon/geo-x-box.svg",e),github:M("./icons/icon/github.svg",e),group:M("./icons/icon/group.svg",e),hidden:M("./icons/icon/hidden.svg",e),image:M("./icons/icon/image.svg",e),"info-circle":M("./icons/icon/info-circle.svg",e),leading:M("./icons/icon/leading.svg",e),link:M("./icons/icon/link.svg",e),"lock-small":M("./icons/icon/lock-small.svg",e),lock:M("./icons/icon/lock.svg",e),menu:M("./icons/icon/menu.svg",e),minus:M("./icons/icon/minus.svg",e),mixed:M("./icons/icon/mixed.svg",e),pack:M("./icons/icon/pack.svg",e),page:M("./icons/icon/page.svg",e),plus:M("./icons/icon/plus.svg",e),"question-mark-circle":M("./icons/icon/question-mark-circle.svg",e),"question-mark":M("./icons/icon/question-mark.svg",e),redo:M("./icons/icon/redo.svg",e),"reset-zoom":M("./icons/icon/reset-zoom.svg",e),"rotate-ccw":M("./icons/icon/rotate-ccw.svg",e),"rotate-cw":M("./icons/icon/rotate-cw.svg",e),ruler:M("./icons/icon/ruler.svg",e),search:M("./icons/icon/search.svg",e),"send-backward":M("./icons/icon/send-backward.svg",e),"send-to-back":M("./icons/icon/send-to-back.svg",e),"settings-horizontal":M("./icons/icon/settings-horizontal.svg",e),"settings-vertical-1":M("./icons/icon/settings-vertical-1.svg",e),"settings-vertical":M("./icons/icon/settings-vertical.svg",e),"share-1":M("./icons/icon/share-1.svg",e),"share-2":M("./icons/icon/share-2.svg",e),"size-extra-large":M("./icons/icon/size-extra-large.svg",e),"size-large":M("./icons/icon/size-large.svg",e),"size-medium":M("./icons/icon/size-medium.svg",e),"size-small":M("./icons/icon/size-small.svg",e),"spline-cubic":M("./icons/icon/spline-cubic.svg",e),"spline-line":M("./icons/icon/spline-line.svg",e),"stack-horizontal":M("./icons/icon/stack-horizontal.svg",e),"stack-vertical":M("./icons/icon/stack-vertical.svg",e),"status-offline":M("./icons/icon/status-offline.svg",e),"status-online":M("./icons/icon/status-online.svg",e),"stretch-horizontal":M("./icons/icon/stretch-horizontal.svg",e),"stretch-vertical":M("./icons/icon/stretch-vertical.svg",e),"text-align-center":M("./icons/icon/text-align-center.svg",e),"text-align-justify":M("./icons/icon/text-align-justify.svg",e),"text-align-left":M("./icons/icon/text-align-left.svg",e),"text-align-right":M("./icons/icon/text-align-right.svg",e),"tool-arrow":M("./icons/icon/tool-arrow.svg",e),"tool-embed":M("./icons/icon/tool-embed.svg",e),"tool-eraser":M("./icons/icon/tool-eraser.svg",e),"tool-frame":M("./icons/icon/tool-frame.svg",e),"tool-hand":M("./icons/icon/tool-hand.svg",e),"tool-highlight":M("./icons/icon/tool-highlight.svg",e),"tool-laser":M("./icons/icon/tool-laser.svg",e),"tool-line":M("./icons/icon/tool-line.svg",e),"tool-media":M("./icons/icon/tool-media.svg",e),"tool-note":M("./icons/icon/tool-note.svg",e),"tool-pencil":M("./icons/icon/tool-pencil.svg",e),"tool-pointer":M("./icons/icon/tool-pointer.svg",e),"tool-text":M("./icons/icon/tool-text.svg",e),trash:M("./icons/icon/trash.svg",e),"triangle-down":M("./icons/icon/triangle-down.svg",e),"triangle-up":M("./icons/icon/triangle-up.svg",e),twitter:M("./icons/icon/twitter.svg",e),undo:M("./icons/icon/undo.svg",e),ungroup:M("./icons/icon/ungroup.svg",e),"unlock-small":M("./icons/icon/unlock-small.svg",e),unlock:M("./icons/icon/unlock.svg",e),"vertical-align-center":M("./icons/icon/vertical-align-center.svg",e),"vertical-align-end":M("./icons/icon/vertical-align-end.svg",e),"vertical-align-start":M("./icons/icon/vertical-align-start.svg",e),visible:M("./icons/icon/visible.svg",e),"warning-triangle":M("./icons/icon/warning-triangle.svg",e),"zoom-in":M("./icons/icon/zoom-in.svg",e),"zoom-out":M("./icons/icon/zoom-out.svg",e)},translations:{ar:M("./translations/ar.json",e),ca:M("./translations/ca.json",e),cs:M("./translations/cs.json",e),da:M("./translations/da.json",e),de:M("./translations/de.json",e),en:M("./translations/en.json",e),es:M("./translations/es.json",e),fa:M("./translations/fa.json",e),fi:M("./translations/fi.json",e),fr:M("./translations/fr.json",e),gl:M("./translations/gl.json",e),he:M("./translations/he.json",e),"hi-in":M("./translations/hi-in.json",e),hu:M("./translations/hu.json",e),it:M("./translations/it.json",e),ja:M("./translations/ja.json",e),"ko-kr":M("./translations/ko-kr.json",e),ku:M("./translations/ku.json",e),languages:M("./translations/languages.json",e),main:M("./translations/main.json",e),my:M("./translations/my.json",e),ne:M("./translations/ne.json",e),no:M("./translations/no.json",e),pl:M("./translations/pl.json",e),"pt-br":M("./translations/pt-br.json",e),"pt-pt":M("./translations/pt-pt.json",e),ro:M("./translations/ro.json",e),ru:M("./translations/ru.json",e),sv:M("./translations/sv.json",e),te:M("./translations/te.json",e),th:M("./translations/th.json",e),tr:M("./translations/tr.json",e),uk:M("./translations/uk.json",e),vi:M("./translations/vi.json",e),"zh-cn":M("./translations/zh-cn.json",e),"zh-tw":M("./translations/zh-tw.json",e)},embedIcons:{codepen:M("./embed-icons/codepen.png",e),codesandbox:M("./embed-icons/codesandbox.png",e),excalidraw:M("./embed-icons/excalidraw.png",e),felt:M("./embed-icons/felt.png",e),figma:M("./embed-icons/figma.png",e),github_gist:M("./embed-icons/github_gist.png",e),google_calendar:M("./embed-icons/google_calendar.png",e),google_maps:M("./embed-icons/google_maps.png",e),google_slides:M("./embed-icons/google_slides.png",e),observable:M("./embed-icons/observable.png",e),replit:M("./embed-icons/replit.png",e),scratch:M("./embed-icons/scratch.png",e),spotify:M("./embed-icons/spotify.png",e),tldraw:M("./embed-icons/tldraw.png",e),val_town:M("./embed-icons/val_town.png",e),vimeo:M("./embed-icons/vimeo.png",e),youtube:M("./embed-icons/youtube.png",e)}}}function sE(e){return e&&typeof e=="object"&&"parents"in e}function iE(e){for(let n=0,t=e.parents.length;n<t;n++)if(e.parents[n].__unsafe__getWithoutCapture(),e.parents[n].lastChangedEpoch!==e.parentEpochs[n])return!0;return!1}const Kh=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&sE(e))for(let t=0,r=e.parents.length;t<r;t++)Kh(e.parents[t],e)},vv=(e,n)=>{if(e.children.add(n)&&sE(e))for(let t=0,r=e.parents.length;t<r;t++)vv(e.parents[t],e)};function aE(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function Rs(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const ko=Rs("empty_array",()=>Object.freeze([])),yx=8;class lE{constructor(){y(this,"arraySize",0);y(this,"array",Array(yx));y(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<yx?(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")}}const Un=Symbol.for("com.tldraw.state/RESET_VALUE");class cE{constructor(n){y(this,"index",0);y(this,"buffer");this.capacity=n,this.buffer=new Array(n)}pushEntry(n,t,r){if(r!==void 0){if(r===Un){this.clear();return}this.buffer[this.index]=[n,t,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(n){const{index:t,capacity:r,buffer:o}=this;for(let s=0;s<r;s++){const i=(t-1+r-s)%r,a=o[i];if(!a)return Un;const[l,c]=a;if(s===0&&n>=c)return[];if(l<=n&&n<c){const u=s+1,d=new Array(u);for(let h=0;h<u;h++)d[h]=o[(i+h)%r][2];return d}}return Un}}class tR{constructor(n,t){y(this,"offset",0);y(this,"numNewParents",0);y(this,"maybeRemoved");this.below=n,this.child=t}}const Je=Rs("capture",()=>({stack:null}));function uE(e){Je.stack=new tR(Je.stack,e)}function dE(){var t;const e=Je.stack;if(Je.stack=e.below,e.numNewParents>0||e.offset!==e.child.parents.length){for(let r=e.offset;r<e.child.parents.length;r++){const o=e.child.parents[r];e.child.parents.indexOf(o)>=e.offset&&Kh(o,e.child)}if(e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset,(t=Je.stack)!=null&&t.maybeRemoved)for(let r=0;r<Je.stack.maybeRemoved.length;r++){const o=Je.stack.maybeRemoved[r];e.child.parents.indexOf(o)===-1&&Kh(o,e.child)}}}function yy(e){if(Je.stack){const n=Je.stack.child.parents.indexOf(e);if(n<0&&(Je.stack.numNewParents++,Je.stack.child.isActivelyListening&&vv(e,Je.stack.child)),n<0||n>=Je.stack.offset){if(n!==Je.stack.offset&&n>0){const t=Je.stack.child.parents[Je.stack.offset];Je.stack.maybeRemoved?Je.stack.maybeRemoved.indexOf(t)===-1&&Je.stack.maybeRemoved.push(t):Je.stack.maybeRemoved=[t]}Je.stack.child.parents[Je.stack.offset]=e,Je.stack.child.parentEpochs[Je.stack.offset]=e.lastChangedEpoch,Je.stack.offset++}}}const Js=-1;class nR{constructor(n,t,r){y(this,"_isActivelyListening",!1);y(this,"lastTraversedEpoch",Js);y(this,"lastReactedEpoch",Js);y(this,"_scheduleCount",0);y(this,"parentEpochs",[]);y(this,"parents",[]);y(this,"_scheduleEffect");y(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!==jn()){if(this.parents.length&&!iE(this)){this.lastReactedEpoch=jn();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++)vv(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)Kh(this.parents[n],this)}execute(){try{uE(this);const n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=jn(),n}finally{dE()}}}const Ga=Rs("EffectScheduler",()=>nR);function su(e,n,t){const r=new Ga(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function rR(e,n,t){const r=new Ga(e,n,t);return{scheduler:r,start:o=>{const s=(o==null?void 0:o.force)??!1;r.attach(),s?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class oR{constructor(n){y(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){if(this.isRoot){const n=this.initialAtomValues;this.initialAtomValues=new Map,hE(n.keys())}else this.initialAtomValues.forEach((n,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,n)})}abort(){Yt.globalEpoch++,this.initialAtomValues.forEach((n,t)=>{var r;t.set(n),(r=t.historyBuffer)==null||r.clear()}),this.commit()}}const Yt=Rs("transactions",()=>({globalEpoch:Js+1,globalIsReacting:!1,currentTransaction:null}));function jn(){return Yt.globalEpoch}function hE(e){if(Yt.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{Yt.globalIsReacting=!0;const n=new Set,t=r=>{r.lastTraversedEpoch!==Yt.globalEpoch&&(r.lastTraversedEpoch=Yt.globalEpoch,r instanceof Ga?n.add(r):r.children.visit(t))};for(const r of e)r.children.visit(t);for(const r of n)r.maybeScheduleEffect()}finally{Yt.globalIsReacting=!1}}function sR(e,n){Yt.currentTransaction?Yt.currentTransaction.initialAtomValues.has(e)||Yt.currentTransaction.initialAtomValues.set(e,n):hE([e])}function iR(){Yt.globalEpoch++}function aR(e){const n=new oR(Yt.currentTransaction);Yt.currentTransaction=n;try{let t=!1;const r=e(()=>t=!0);return t?n.abort():n.commit(),r}catch(t){throw n.abort(),t}finally{Yt.currentTransaction=Yt.currentTransaction.parent}}function br(e){return Yt.currentTransaction?e():aR(e)}class lR{constructor(n,t,r){y(this,"isEqual");y(this,"computeDiff");y(this,"lastChangedEpoch",jn());y(this,"children",new lE);y(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new cE(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(){return this.current}get(){return yy(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??aE(this.current,n))return this.current;iR(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,jn(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,jn()))??Un),this.lastChangedEpoch=jn();const r=this.current;return this.current=n,sR(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return yy(this),n>=this.lastChangedEpoch?ko:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Un}}const cR=Rs("Atom",()=>lR);function sn(e,n,t){return new cR(e,n,t)}let Sx=!1;function uR(){Sx||(Sx=!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.
18
+
19
+ // Before
20
+ @computed
21
+ get foo() {
22
+ return 'foo'
23
+ }
24
+
25
+ // After
26
+ @computed
27
+ getFoo() {
28
+ return 'foo'
29
+ }
30
+ `))}const Sy=Symbol.for("com.tldraw.state/UNINITIALIZED"),wa=e=>e===Sy,vy=Rs("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function Vl(e,n){return new vy(e,n)}class dR{constructor(n,t,r){y(this,"lastChangedEpoch",Js);y(this,"lastTraversedEpoch",Js);y(this,"lastCheckedEpoch",Js);y(this,"parents",[]);y(this,"parentEpochs",[]);y(this,"children",new lE);y(this,"historyBuffer");y(this,"state",Sy);y(this,"computeDiff");y(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new cE(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??aE}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(){var t;const n=this.lastChangedEpoch===Js;if(!n&&(this.lastCheckedEpoch===jn()||!iE(this)))return this.lastCheckedEpoch=jn(),this.state;try{uE(this);const r=this.derive(this.state,this.lastCheckedEpoch),o=r instanceof vy?r.value:r;if(this.state===Sy||!this.isEqual(o,this.state)){if(this.historyBuffer&&!n){const s=r instanceof vy?r.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,jn(),s??((t=this.computeDiff)==null?void 0:t.call(this,this.state,o,this.lastCheckedEpoch,jn()))??Un)}this.lastChangedEpoch=jn(),this.state=o}return this.lastCheckedEpoch=jn(),this.state}finally{dE()}}get(){const n=this.__unsafe__getWithoutCapture();return yy(this),n}getDiffSince(n){var t;return this.get(),n>=this.lastChangedEpoch?ko:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Un}}const wv=Rs("Computed",()=>dR);function hR(e={},n,t,r){const o=r.value,s=Symbol.for("__@tldraw/state__computed__"+t);return r.value=function(){let i=this[s];return i||(i=new wv(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[fR]=!0,r}function vx(e={},n,t,r){return r.get?(uR(),pR(e,n,t,r)):hR(e,n,t,r)}function pR(e={},n,t,r){const o=r.get,s=Symbol.for("__@tldraw/state__computed__"+t);return r.get=function(){let i=this[s];return i||(i=new wv(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const fR="@@__isComputedMethod__@@";function Z(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>vx(e,n,t,r)}else return typeof arguments[0]=="string"?new wv(arguments[0],arguments[1],arguments[2]):vx(void 0,arguments[0],arguments[1],arguments[2])}const pE=1,gR=Rs("apiVersion",()=>pE);if(gR!==pE)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function Qp(e,n){const t=ne.useRef(n);t.current=n;const[r,o,s]=ne.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new Ga(`useStateTracking(${e})`,()=>{var u;return(u=t.current)==null?void 0:u.call(t)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[e]);return ne.useSyncExternalStore(o,s,s),ne.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const wx={apply(e,n,t){return Qp(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},mR=Symbol.for("react.memo"),yR=Symbol.for("react.forward_ref");function je(e){let n=null;const t=e.$$typeof;return t===mR&&(e=e.type,n=e.compare),t===yR?w.memo(w.forwardRef(new Proxy(e.render,wx))):w.memo(new Proxy(e,wx),n)}function fE(){const e=arguments[0],n=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return w.useMemo(()=>Z(`useComputed(${e})`,n,t),r)}function ii(e,n,t=ko){w.useEffect(()=>{const r=new Ga(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=w.useRef(!0);r.current=!0;const o=w.useMemo(()=>e.length===1?e[0]:Z(t,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),n);try{const{subscribe:s,getSnapshot:i}=w.useMemo(()=>({subscribe:a=>su(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return w.useSyncExternalStore(s,i,i)}finally{r.current=!1}}class Xd{constructor(n){y(this,"nextValue");y(this,"diff");this.previousValue=n}get(){var r,o,s,i;const n=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,t=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(n===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(n),this.diff??(this.diff={}),t?(r=this.diff.removed)==null||r.delete(n):((o=this.diff).added??(o.added=new Set),this.diff.added.add(n))}add(n){var o,s,i;const t=this.previousValue.has(n);if(t)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(n))?this._add(n,t):void 0;(i=this.nextValue)!=null&&i.has(n)||this._add(n,t)}_remove(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(n),this.diff??(this.diff={}),t?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(n)):(o=this.diff.added)==null||o.delete(n)}remove(n){var o,s,i,a;const t=this.previousValue.has(n);if(!t)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(n))?this._remove(n,t):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(n)||this._remove(n,t)}}function Wh(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 pe(e){return e.filter(n=>n!=null)}function mn(e){return e[e.length-1]}function SR(e,n){let t,r=1/0;for(const o of e){const s=n(o);s<r&&(t=o,r=s)}return t}function vR(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}function gE(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const Ys={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function Ya(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const Io=gE((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),mE=gE((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function yE(e,n){let t;const r=(...o)=>(t||(t={},t.promise=new Promise((s,i)=>{t.resolve=s,t.reject=i})),clearTimeout(t.timeout),t.latestArgs=o,t.timeout=setTimeout(()=>{const s=t;t=void 0;try{s.resolve(e(...s.latestArgs))}catch(i){s.reject(i)}},n),t.promise);return r.cancel=()=>{t&&clearTimeout(t.timeout)},r}const xx=new WeakMap;function xv(e,n){if(typeof e!="object"||e===null)return;let t=xx.get(e);t||(t={tags:{},extras:{}},xx.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}function wy(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function wR(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+""}let xy=[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"&&(xy=new Int32Array(xy));const xR=(e,n)=>{let t=n===0?0:~~n^-1;for(let r=0;r<e.length;r++)t=xy[(t^e[r])&255]^t>>>8;return t^-1},bx=4,Px=4;class Kr{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(!Kr.isPng(n,t))throw new Error("Not a PNG");for(t+=8;t<=n.buffer.byteLength;){const o=t,s=n.getInt32(t);t+=4;const i=Kr.getChunkType(n,t);if(i==="IDAT"&&r[i]){t+=s+bx+Px;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+bx+Px}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 Kr.readChunks(n)[t]}static setPhysChunk(n,t=1,r){let o=46,s=0;const i=Kr.findChunk(n,"pHYs");i&&(o=i.start,s=i.size);const a=Kr.findChunk(n,"IDAT");a&&(o=a.start,s=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const u=2835.5;c.setInt32(8,u*t),c.setInt32(12,u*t),c.setInt8(16,1);const d=new Uint8Array(l.slice(4,17));c.setInt32(17,xR(d));const h=n.buffer.slice(0,o),p=n.buffer.slice(o+s);return new Blob([h,l,p],r)}}class Yr{static loadVideo(n){return new Promise((t,r)=>{const o=document.createElement("video");o.onloadeddata=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load video"))},o.crossOrigin="anonymous",o.src=n})}static loadImage(n){return new Promise((t,r)=>{const o=new Image;o.onload=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.src=n})}static blobToDataUrl(n){return new Promise((t,r)=>{const o=new FileReader;o.onload=()=>t(o.result),o.onerror=s=>{console.error(s),r(new Error("Could not read blob"))},o.readAsDataURL(n)})}static async getVideoSize(n){return Yr.usingObjectURL(n,async t=>{const r=await Yr.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await Yr.usingObjectURL(n,Yr.loadImage);try{if(n.type==="image/png"){const r=new DataView(await n.arrayBuffer());if(Kr.isPng(r,0)){const o=Kr.findChunk(r,"pHYs");if(o){const s=Kr.parsePhys(r,o.dataOffset);if(s.unit===0&&s.ppux===s.ppuy){const i=Math.max(s.ppux/2834.5,1);return{w:Math.round(t.naturalWidth/i),h:Math.round(t.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:t.naturalWidth,h:t.naturalHeight}}return{w:t.naturalWidth,h:t.naturalHeight}}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function fs(e=""){let n=0,t=0,r=0,o=0;function s(){const i=n^n<<11;return n=t,t=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)n^=e.charCodeAt(i)|0,s();return s}function Gh(e,n,t,r=!1){const[o,s]=n,[i,a]=t,l=i+(e-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function Jp(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function ai(e,n){if(Jp(e,n))return e[n]}function Zt(e){if(!e)return e;if(Array.isArray(e)){const n=[],t=e.length;for(let r=0;r<t;r++)n.push(Zt(e[r]));return n}else if(typeof e=="object"){const n=Object.keys(e),t=n.length,r={};for(let o=0;o<t;o++){const s=n[o];r[s]=Zt(e[s])}return r}return e}function Cx(e){return Object.keys(e)}function dt(e){return Object.values(e)}function Xr(e){return Object.entries(e)}function SE(e){return Object.fromEntries(e)}function lg(e,n){const t={};let r=!1;for(const[o,s]of Xr(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function by(e,n){const t={};for(const[r,o]of Xr(e)){const s=n(r,o);t[r]=s}return t}function vE(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 bR=()=>typeof process<"u"&&!1,Yh=[],PR=()=>{const e=Yh.splice(0,Yh.length);for(const n of e)n()};let cg;function CR(){cg||(cg=requestAnimationFrame(()=>{cg=void 0,PR()}))}function ER(e){if(bR())return e();Yh.includes(e)||(Yh.push(e),CR())}function kR(e,n){return e.id>n.id?1:-1}function IR(e){return e!==null}const gs=typeof window<"u"&&window.structuredClone?window.structuredClone:e=>e&&JSON.parse(JSON.stringify(e));let ef=(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 bv{constructor(n,t){y(this,"createDefaultProperties");y(this,"migrations");y(this,"validator");y(this,"scope");y(this,"isInstance",n=>(n==null?void 0:n.typeName)===this.typeName);this.typeName=n,this.createDefaultProperties=t.createDefaultProperties,this.migrations=t.migrations,this.validator=t.validator??{validate:r=>r},this.scope=t.scope??"document"}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{...gs(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??ef())}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 bv(this.typeName,{createDefaultProperties:n,migrations:this.migrations,validator:this.validator,scope:this.scope})}validate(n){return this.validator.validate(n)}}function Bo(e,n){return new bv(e,{createDefaultProperties:()=>({}),migrations:n.migrations??{currentVersion:0,firstVersion:0,migrators:{}},validator:n.validator,scope:n.scope})}class Ex{constructor(){y(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}}var Xh={exports:{}};Xh.exports;(function(e,n){var t=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",d="[object Date]",h="[object Error]",p="[object Function]",m="[object GeneratorFunction]",f="[object Map]",S="[object Number]",v="[object Null]",x="[object Object]",b="[object Promise]",P="[object Proxy]",E="[object RegExp]",k="[object Set]",I="[object String]",_="[object Symbol]",A="[object Undefined]",T="[object WeakMap]",D="[object ArrayBuffer]",L="[object DataView]",z="[object Float32Array]",j="[object Float64Array]",F="[object Int8Array]",Y="[object Int16Array]",K="[object Int32Array]",H="[object Uint8Array]",B="[object Uint8ClampedArray]",V="[object Uint16Array]",X="[object Uint32Array]",ae=/[\\^$.*+?()[\]{}|]/g,ye=/^\[object .+?Constructor\]$/,Ie=/^(?:0|[1-9]\d*)$/,le={};le[z]=le[j]=le[F]=le[Y]=le[K]=le[H]=le[B]=le[V]=le[X]=!0,le[a]=le[l]=le[D]=le[u]=le[L]=le[d]=le[h]=le[p]=le[f]=le[S]=le[x]=le[E]=le[k]=le[I]=le[T]=!1;var ke=typeof Xt=="object"&&Xt&&Xt.Object===Object&&Xt,Ae=typeof self=="object"&&self&&self.Object===Object&&self,nt=ke||Ae||Function("return this")(),Pe=n&&!n.nodeType&&n,ct=Pe&&!0&&e&&!e.nodeType&&e,Be=ct&&ct.exports===Pe,Jn=Be&&ke.process,Tn=function(){try{return Jn&&Jn.binding&&Jn.binding("util")}catch{}}(),$n=Tn&&Tn.isTypedArray;function Ye($,R){for(var W=-1,J=$==null?0:$.length,Xe=0,me=[];++W<J;){var ut=$[W];R(ut,W,$)&&(me[Xe++]=ut)}return me}function kt($,R){for(var W=-1,J=R.length,Xe=$.length;++W<J;)$[Xe+W]=R[W];return $}function co($,R){for(var W=-1,J=$==null?0:$.length;++W<J;)if(R($[W],W,$))return!0;return!1}function pl($,R){for(var W=-1,J=Array($);++W<$;)J[W]=R(W);return J}function fl($){return function(R){return $(R)}}function Jf($,R){return $.has(R)}function Oi($,R){return $==null?void 0:$[R]}function kM($){var R=-1,W=Array($.size);return $.forEach(function(J,Xe){W[++R]=[Xe,J]}),W}function IM($,R){return function(W){return $(R(W))}}function _M($){var R=-1,W=Array($.size);return $.forEach(function(J){W[++R]=J}),W}var TM=Array.prototype,$M=Function.prototype,Du=Object.prototype,eg=nt["__core-js_shared__"],qw=$M.toString,Fr=Du.hasOwnProperty,Zw=function(){var $=/[^.]+$/.exec(eg&&eg.keys&&eg.keys.IE_PROTO||"");return $?"Symbol(src)_1."+$:""}(),Qw=Du.toString,AM=RegExp("^"+qw.call(Fr).replace(ae,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Jw=Be?nt.Buffer:void 0,ju=nt.Symbol,ex=nt.Uint8Array,tx=Du.propertyIsEnumerable,MM=TM.splice,Hs=ju?ju.toStringTag:void 0,nx=Object.getOwnPropertySymbols,OM=Jw?Jw.isBuffer:void 0,RM=IM(Object.keys,Object),tg=Ri(nt,"DataView"),gl=Ri(nt,"Map"),ng=Ri(nt,"Promise"),rg=Ri(nt,"Set"),og=Ri(nt,"WeakMap"),ml=Ri(Object,"create"),DM=Ws(tg),jM=Ws(gl),LM=Ws(ng),NM=Ws(rg),FM=Ws(og),rx=ju?ju.prototype:void 0,sg=rx?rx.valueOf:void 0;function Vs($){var R=-1,W=$==null?0:$.length;for(this.clear();++R<W;){var J=$[R];this.set(J[0],J[1])}}function zM(){this.__data__=ml?ml(null):{},this.size=0}function BM($){var R=this.has($)&&delete this.__data__[$];return this.size-=R?1:0,R}function UM($){var R=this.__data__;if(ml){var W=R[$];return W===r?void 0:W}return Fr.call(R,$)?R[$]:void 0}function HM($){var R=this.__data__;return ml?R[$]!==void 0:Fr.call(R,$)}function VM($,R){var W=this.__data__;return this.size+=this.has($)?0:1,W[$]=ml&&R===void 0?r:R,this}Vs.prototype.clear=zM,Vs.prototype.delete=BM,Vs.prototype.get=UM,Vs.prototype.has=HM,Vs.prototype.set=VM;function uo($){var R=-1,W=$==null?0:$.length;for(this.clear();++R<W;){var J=$[R];this.set(J[0],J[1])}}function KM(){this.__data__=[],this.size=0}function WM($){var R=this.__data__,W=Nu(R,$);if(W<0)return!1;var J=R.length-1;return W==J?R.pop():MM.call(R,W,1),--this.size,!0}function GM($){var R=this.__data__,W=Nu(R,$);return W<0?void 0:R[W][1]}function YM($){return Nu(this.__data__,$)>-1}function XM($,R){var W=this.__data__,J=Nu(W,$);return J<0?(++this.size,W.push([$,R])):W[J][1]=R,this}uo.prototype.clear=KM,uo.prototype.delete=WM,uo.prototype.get=GM,uo.prototype.has=YM,uo.prototype.set=XM;function Ks($){var R=-1,W=$==null?0:$.length;for(this.clear();++R<W;){var J=$[R];this.set(J[0],J[1])}}function qM(){this.size=0,this.__data__={hash:new Vs,map:new(gl||uo),string:new Vs}}function ZM($){var R=Fu(this,$).delete($);return this.size-=R?1:0,R}function QM($){return Fu(this,$).get($)}function JM($){return Fu(this,$).has($)}function eO($,R){var W=Fu(this,$),J=W.size;return W.set($,R),this.size+=W.size==J?0:1,this}Ks.prototype.clear=qM,Ks.prototype.delete=ZM,Ks.prototype.get=QM,Ks.prototype.has=JM,Ks.prototype.set=eO;function Lu($){var R=-1,W=$==null?0:$.length;for(this.__data__=new Ks;++R<W;)this.add($[R])}function tO($){return this.__data__.set($,r),this}function nO($){return this.__data__.has($)}Lu.prototype.add=Lu.prototype.push=tO,Lu.prototype.has=nO;function Xo($){var R=this.__data__=new uo($);this.size=R.size}function rO(){this.__data__=new uo,this.size=0}function oO($){var R=this.__data__,W=R.delete($);return this.size=R.size,W}function sO($){return this.__data__.get($)}function iO($){return this.__data__.has($)}function aO($,R){var W=this.__data__;if(W instanceof uo){var J=W.__data__;if(!gl||J.length<t-1)return J.push([$,R]),this.size=++W.size,this;W=this.__data__=new Ks(J)}return W.set($,R),this.size=W.size,this}Xo.prototype.clear=rO,Xo.prototype.delete=oO,Xo.prototype.get=sO,Xo.prototype.has=iO,Xo.prototype.set=aO;function lO($,R){var W=zu($),J=!W&&PO($),Xe=!W&&!J&&ig($),me=!W&&!J&&!Xe&&hx($),ut=W||J||Xe||me,wt=ut?pl($.length,String):[],It=wt.length;for(var rt in $)(R||Fr.call($,rt))&&!(ut&&(rt=="length"||Xe&&(rt=="offset"||rt=="parent")||me&&(rt=="buffer"||rt=="byteLength"||rt=="byteOffset")||SO(rt,It)))&&wt.push(rt);return wt}function Nu($,R){for(var W=$.length;W--;)if(lx($[W][0],R))return W;return-1}function cO($,R,W){var J=R($);return zu($)?J:kt(J,W($))}function yl($){return $==null?$===void 0?A:v:Hs&&Hs in Object($)?mO($):bO($)}function ox($){return Sl($)&&yl($)==a}function sx($,R,W,J,Xe){return $===R?!0:$==null||R==null||!Sl($)&&!Sl(R)?$!==$&&R!==R:uO($,R,W,J,sx,Xe)}function uO($,R,W,J,Xe,me){var ut=zu($),wt=zu(R),It=ut?l:qo($),rt=wt?l:qo(R);It=It==a?x:It,rt=rt==a?x:rt;var An=It==x,mr=rt==x,Ft=It==rt;if(Ft&&ig($)){if(!ig(R))return!1;ut=!0,An=!1}if(Ft&&!An)return me||(me=new Xo),ut||hx($)?ix($,R,W,J,Xe,me):fO($,R,It,W,J,Xe,me);if(!(W&o)){var er=An&&Fr.call($,"__wrapped__"),tr=mr&&Fr.call(R,"__wrapped__");if(er||tr){var Zo=er?$.value():$,ho=tr?R.value():R;return me||(me=new Xo),Xe(Zo,ho,W,J,me)}}return Ft?(me||(me=new Xo),gO($,R,W,J,Xe,me)):!1}function dO($){if(!dx($)||wO($))return!1;var R=cx($)?AM:ye;return R.test(Ws($))}function hO($){return Sl($)&&ux($.length)&&!!le[yl($)]}function pO($){if(!xO($))return RM($);var R=[];for(var W in Object($))Fr.call($,W)&&W!="constructor"&&R.push(W);return R}function ix($,R,W,J,Xe,me){var ut=W&o,wt=$.length,It=R.length;if(wt!=It&&!(ut&&It>wt))return!1;var rt=me.get($);if(rt&&me.get(R))return rt==R;var An=-1,mr=!0,Ft=W&s?new Lu:void 0;for(me.set($,R),me.set(R,$);++An<wt;){var er=$[An],tr=R[An];if(J)var Zo=ut?J(tr,er,An,R,$,me):J(er,tr,An,$,R,me);if(Zo!==void 0){if(Zo)continue;mr=!1;break}if(Ft){if(!co(R,function(ho,Gs){if(!Jf(Ft,Gs)&&(er===ho||Xe(er,ho,W,J,me)))return Ft.push(Gs)})){mr=!1;break}}else if(!(er===tr||Xe(er,tr,W,J,me))){mr=!1;break}}return me.delete($),me.delete(R),mr}function fO($,R,W,J,Xe,me,ut){switch(W){case L:if($.byteLength!=R.byteLength||$.byteOffset!=R.byteOffset)return!1;$=$.buffer,R=R.buffer;case D:return!($.byteLength!=R.byteLength||!me(new ex($),new ex(R)));case u:case d:case S:return lx(+$,+R);case h:return $.name==R.name&&$.message==R.message;case E:case I:return $==R+"";case f:var wt=kM;case k:var It=J&o;if(wt||(wt=_M),$.size!=R.size&&!It)return!1;var rt=ut.get($);if(rt)return rt==R;J|=s,ut.set($,R);var An=ix(wt($),wt(R),J,Xe,me,ut);return ut.delete($),An;case _:if(sg)return sg.call($)==sg.call(R)}return!1}function gO($,R,W,J,Xe,me){var ut=W&o,wt=ax($),It=wt.length,rt=ax(R),An=rt.length;if(It!=An&&!ut)return!1;for(var mr=It;mr--;){var Ft=wt[mr];if(!(ut?Ft in R:Fr.call(R,Ft)))return!1}var er=me.get($);if(er&&me.get(R))return er==R;var tr=!0;me.set($,R),me.set(R,$);for(var Zo=ut;++mr<It;){Ft=wt[mr];var ho=$[Ft],Gs=R[Ft];if(J)var px=ut?J(Gs,ho,Ft,R,$,me):J(ho,Gs,Ft,$,R,me);if(!(px===void 0?ho===Gs||Xe(ho,Gs,W,J,me):px)){tr=!1;break}Zo||(Zo=Ft=="constructor")}if(tr&&!Zo){var Bu=$.constructor,Uu=R.constructor;Bu!=Uu&&"constructor"in $&&"constructor"in R&&!(typeof Bu=="function"&&Bu instanceof Bu&&typeof Uu=="function"&&Uu instanceof Uu)&&(tr=!1)}return me.delete($),me.delete(R),tr}function ax($){return cO($,kO,yO)}function Fu($,R){var W=$.__data__;return vO(R)?W[typeof R=="string"?"string":"hash"]:W.map}function Ri($,R){var W=Oi($,R);return dO(W)?W:void 0}function mO($){var R=Fr.call($,Hs),W=$[Hs];try{$[Hs]=void 0;var J=!0}catch{}var Xe=Qw.call($);return J&&(R?$[Hs]=W:delete $[Hs]),Xe}var yO=nx?function($){return $==null?[]:($=Object($),Ye(nx($),function(R){return tx.call($,R)}))}:IO,qo=yl;(tg&&qo(new tg(new ArrayBuffer(1)))!=L||gl&&qo(new gl)!=f||ng&&qo(ng.resolve())!=b||rg&&qo(new rg)!=k||og&&qo(new og)!=T)&&(qo=function($){var R=yl($),W=R==x?$.constructor:void 0,J=W?Ws(W):"";if(J)switch(J){case DM:return L;case jM:return f;case LM:return b;case NM:return k;case FM:return T}return R});function SO($,R){return R=R??i,!!R&&(typeof $=="number"||Ie.test($))&&$>-1&&$%1==0&&$<R}function vO($){var R=typeof $;return R=="string"||R=="number"||R=="symbol"||R=="boolean"?$!=="__proto__":$===null}function wO($){return!!Zw&&Zw in $}function xO($){var R=$&&$.constructor,W=typeof R=="function"&&R.prototype||Du;return $===W}function bO($){return Qw.call($)}function Ws($){if($!=null){try{return qw.call($)}catch{}try{return $+""}catch{}}return""}function lx($,R){return $===R||$!==$&&R!==R}var PO=ox(function(){return arguments}())?ox:function($){return Sl($)&&Fr.call($,"callee")&&!tx.call($,"callee")},zu=Array.isArray;function CO($){return $!=null&&ux($.length)&&!cx($)}var ig=OM||_O;function EO($,R){return sx($,R)}function cx($){if(!dx($))return!1;var R=yl($);return R==p||R==m||R==c||R==P}function ux($){return typeof $=="number"&&$>-1&&$%1==0&&$<=i}function dx($){var R=typeof $;return $!=null&&(R=="object"||R=="function")}function Sl($){return $!=null&&typeof $=="object"}var hx=$n?fl($n):hO;function kO($){return CO($)?lO($):pO($)}function IO(){return[]}function _O(){return!1}e.exports=EO})(Xh,Xh.exports);var _R=Xh.exports;const TR=Ka(_R);function $R(e){if(e.length===0)return new Set;const n=e[0],t=e.slice(1),r=new Set;for(const o of n)t.every(s=>s.has(o))&&r.add(o);return r}function AR(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 kx(e,n){for(const[t,r]of Object.entries(e)){const o=r,s=n[t];if("eq"in o&&s!==o.eq||"neq"in o&&s===o.neq||"gt"in o&&(typeof s!="number"||s<=o.gt))return!1}return!0}function Ix(e,n,t){const r=Object.fromEntries(Object.keys(t).map(o=>[o,new Set]));for(const[o,s]of Object.entries(t))if("eq"in s){const a=e.index(n,o).get().get(s.eq);if(a)for(const l of a)r[o].add(l)}else if("neq"in s){const i=e.index(n,o);for(const[a,l]of i.get())if(a!==s.neq)for(const c of l)r[o].add(c)}else if("gt"in s){const i=e.index(n,o);for(const[a,l]of i.get())if(a>s.gt)for(const c of l)r[o].add(c)}return $R(Object.values(r))}class MR{constructor(n,t){y(this,"indexCache",new Map);y(this,"historyCache",new Map);this.atoms=n,this.history=t}filterHistory(n){if(this.historyCache.has(n))return this.historyCache.get(n);const t=Z("filterHistory:"+n,(r,o)=>{if(wa(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Un)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of s){for(const d of dt(u.added))if(d.typeName===n)if(i.removed[d.id]){const h=i.removed[d.id];delete i.removed[d.id],l--,h!==d&&(i.updated[d.id]=[h,d],c++)}else i.added[d.id]=d,a++;for(const[d,h]of dt(u.updated))h.typeName===n&&(i.added[h.id]?i.added[h.id]=h:i.updated[h.id]?i.updated[h.id]=[i.updated[h.id][0],h]:(i.updated[h.id]=[d,h],c++));for(const d of dt(u.removed))d.typeName===n&&(i.added[d.id]?(delete i.added[d.id],a--):i.updated[d.id]?(i.removed[d.id]=i.updated[d.id][0],delete i.updated[d.id],c--,l++):(i.removed[d.id]=d,l++))}return a||l||c?Vl(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(n,t),t}index(n,t){const r=n+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(n,t);return this.indexCache.set(r,o),o}__uncached_createIndex(n,t){const r=this.filterHistory(n),o=()=>{r.get();const s=new Map;for(const i of dt(this.atoms.get())){const a=i.get();if(a.typeName===n){const l=a[t];s.has(l)||s.set(l,new Set),s.get(l).add(a.id)}}return s};return Z("index:"+n+":"+t,(s,i)=>{if(wa(s))return o();const a=r.getDiffSince(i);if(a===Un)return o();const l=new Map,c=(p,m)=>{let f=l.get(p);f||(f=new Xd(s.get(p)??new Set)),f.add(m),l.set(p,f)},u=(p,m)=>{let f=l.get(p);f||(f=new Xd(s.get(p)??new Set)),f.remove(m),l.set(p,f)};for(const p of a){for(const m of dt(p.added))if(m.typeName===n){const f=m[t];c(f,m.id)}for(const[m,f]of dt(p.updated))if(f.typeName===n){const S=m[t],v=f[t];S!==v&&(u(S,f.id),c(v,f.id))}for(const m of dt(p.removed))if(m.typeName===n){const f=m[t];u(f,m.id)}}let d,h;for(const[p,m]of l){const f=m.get();f&&(d||(d=new Map(s)),h||(h=new Map),f.value.size===0?d.delete(p):d.set(p,f.value),h.set(p,f.diff))}return d&&h?Vl(d,h):s},{historyLength:100})}record(n,t=()=>({}),r="record:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,r);return Z(r,()=>{var s;for(const i of o.get())return(s=this.atoms.get()[i])==null?void 0:s.get()})}records(n,t=()=>({}),r="records:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,"ids:"+r);return Z(r,()=>[...o.get()].map(s=>{const i=this.atoms.get()[s];if(!i)throw new Error("no atom found for record id: "+s);return i.get()}))}ids(n,t=()=>({}),r="ids:"+n+(t?":"+t.toString():"")){const o=this.filterHistory(n),s=()=>{o.get();const l=t();return Object.keys(l).length===0?new Set(dt(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===n?u.id:[]})):Ix(this,n,l)},i=l=>{const c=s(),u=AR(l,c);return u?Vl(c,u):l},a=Z("ids_query:"+r,t,{isEqual:TR});return Z("query:"+r,(l,c)=>{const u=a.get();if(wa(l))return s();if(c<a.lastChangedEpoch)return i(l);const d=o.getDiffSince(c);if(d===Un)return i(l);const h=new Xd(l);for(const m of d){for(const f of dt(m.added))f.typeName===n&&kx(u,f)&&h.add(f.id);for(const[f,S]of dt(m.updated))S.typeName===n&&(kx(u,S)?h.add(S.id):h.remove(S.id));for(const f of dt(m.removed))f.typeName===n&&h.remove(f.id)}const p=h.get();return p?Vl(p.value,p.diff):l},{historyLength:50})}exec(n,t){const r=Ix(this,n,t);if(r.size===0)return ko;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class wE{constructor(n){y(this,"id",ef());y(this,"atoms",sn("store_atoms",{}));y(this,"history",sn("history",0,{historyLength:1e3}));y(this,"query",new MR(this.atoms,this.history));y(this,"listeners",new Set);y(this,"historyAccumulator",new RR);y(this,"historyReactor");y(this,"schema");y(this,"props");y(this,"scopedTypes");y(this,"onBeforeCreate");y(this,"onAfterCreate");y(this,"onBeforeChange");y(this,"onAfterChange");y(this,"onBeforeDelete");y(this,"onAfterDelete");y(this,"_runCallbacks",!0);y(this,"put",(n,t)=>{br(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.onBeforeCreate&&this._runCallbacks?this.onBeforeCreate:null,u=this.onBeforeChange&&this._runCallbacks?this.onBeforeChange:null,d=this.isMergingRemoteChanges?"remote":"user";for(let h=0,p=n.length;h<p;h++){a=n[h];const m=(i??s)[a.id];if(m){const f=m.__unsafe__getWithoutCapture();u&&(a=u(f,a,d)),a=this.schema.validateRecord(this,a,t??"updateRecord",f),m.set(a);const S=m.__unsafe__getWithoutCapture();f!==S&&(l=!0,r[a.id]=[f,S])}else c&&(a=c(a,d)),l=!0,a=this.schema.validateRecord(this,a,t??"createRecord",null),o[a.id]=a,i||(i={...s}),i[a.id]=sn("atom:"+a.id,a)}if(i&&this.atoms.set(i),!!l&&(this.updateHistory({added:o,updated:r,removed:{}}),this._runCallbacks)){const{onAfterCreate:h,onAfterChange:p}=this;h&&Object.values(o).forEach(m=>{h(m,d)}),p&&Object.values(r).forEach(([m,f])=>{p(m,f,d)})}})});y(this,"remove",n=>{br(()=>{const t=[],r=this.isMergingRemoteChanges?"remote":"user";if(this.onBeforeDelete&&this._runCallbacks)for(const s of n){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.onBeforeDelete(i.get(),r)===!1&&t.push(s)}let o;if(this.atoms.update(s=>{let i;for(const a of n)t.includes(a)||a in s&&(i||(i={...s}),o||(o={}),delete i[a],o[a]=s[a].get());return i??s}),!!o&&(this.updateHistory({added:{},updated:{},removed:o}),this.onAfterDelete&&this._runCallbacks)){let s;for(let i=0,a=n.length;i<a;i++)s=o[n[i]],s&&this.onAfterDelete(s,r)}})});y(this,"get",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.get()});y(this,"unsafeGetWithoutCapture",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.__unsafe__getWithoutCapture()});y(this,"serialize",(n="document")=>{const t={};for(const[r,o]of Xr(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});y(this,"allRecords",()=>dt(this.atoms.get()).map(n=>n.get()));y(this,"clear",()=>{this.remove(Cx(this.atoms.get()))});y(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())])});y(this,"has",n=>!!this.atoms.get()[n]);y(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()}});y(this,"isMergingRemoteChanges",!1);y(this,"mergeRemoteChanges",n=>{if(this.isMergingRemoteChanges)return n();try{this.isMergingRemoteChanges=!0,br(n)}finally{this.isMergingRemoteChanges=!1}});y(this,"createComputedCache",(n,t,r)=>{const o=new Ex;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?Z(i.name+":equals",()=>i.get(),{isEqual:r}):i;return Z(n+":"+s,()=>t(a.get()))}).get()}}});y(this,"createSelectedComputedCache",(n,t,r)=>{const o=new Ex;return{get:s=>{const i=this.atoms.get()[s];if(!i)return;const a=Z(n+":"+s+":selector",()=>t(i.get()));return o.get(i,()=>Z(n+":"+s,()=>r(a.get()))).get()}}});y(this,"getRecordType",n=>{const t=this.schema.types[n.typeName];if(!t)throw new Error(`Record type ${n.typeName} not found`);return t});y(this,"_integrityChecker");y(this,"_isPossiblyCorrupted",!1);const{initialData:t,schema:r}=n;this.schema=r,this.props=n.props,t&&this.atoms.set(SE(Xr(t).map(([o,s])=>[o,sn("atom:"+o,this.schema.validateRecord(this,s,"initialize",null))]))),this.historyReactor=rR("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>ER(o)}),this.scopedTypes={document:new Set(dt(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(dt(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(dt(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const n=this.historyAccumulator.flush();for(const{changes:t,source:r}of n){let o=null,s=null,i=null;for(const{onHistory:a,filters:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(s??(s=this.filterChangesByScope(t,"document")),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(o??(o=this.filterChangesByScope(t,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(t,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:t,source:r})}}}filterChangesByScope(n,t){const r={added:lg(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:lg(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:lg(n.removed,(o,s)=>this.scopedTypes[t].has(s.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(n){this.historyAccumulator.add({changes:n,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,n)}validate(n){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,n,null))}getSnapshot(n="document"){return{store:this.serialize(n),schema:this.schema.serialize()}}migrateSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);br(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()})}extractingChanges(n){const t=[],r=this.historyAccumulator.intercepting(o=>t.push(o.changes));try{return br(n),tf(t)}finally{r()}}applyDiff(n,t=!0){const r=this._runCallbacks;try{this._runCallbacks=t,br(()=>{const o=dt(n.added).concat(dt(n.updated).map(([i,a])=>a)),s=Cx(n.removed);o.length&&this.put(o),s.length&&this.remove(s)})}finally{this._runCallbacks=r}}ensureStoreIsUsable(){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}}function tf(e){const n={added:{},removed:{},updated:{}};for(const t of e){for(const[r,o]of Xr(t.added))if(n.removed[r]){const s=n.removed[r];delete n.removed[r],s!==o&&(n.updated[r]=[s,o])}else n.added[r]=o;for(const[r,[o,s]]of Xr(t.updated)){if(n.added[r]){n.added[r]=s,delete n.updated[r],delete n.removed[r];continue}if(n.updated[r]){n.updated[r]=[n.updated[r][0],s],delete n.removed[r];continue}n.updated[r]=t.updated[r],delete n.removed[r]}for(const[r,o]of Xr(t.removed))n.added[r]?delete n.added[r]:n.updated[r]?(n.removed[r]=n.updated[r][0],delete n.updated[r]):n.removed[r]=o}return n}function OR(e){const n=[];let t=e[0],r;for(let o=1,s=e.length;o<s;o++)r=e[o],t.source!==r.source?(n.push(t),t=r):t={source:t.source,changes:tf([t.changes,r.changes])};return n.push(t),n}class RR{constructor(){y(this,"_history",[]);y(this,"_interceptors",new Set)}intercepting(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=OR(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function DR(e){return typeof e=="object"&&e!==null&&"id"in e&&"typeName"in e}function $e(e){const{currentVersion:n,firstVersion:t,migrators:r={},subTypeKey:o,subTypeMigrations:s}=e;if(typeof n=="number"&&typeof t=="number"){if(n===t)throw Error("Current version is equal to initial version.");if(n<t)throw Error("Current version is lower than initial version.")}return{firstVersion:t??0,currentVersion:n??0,migrators:r,subTypeKey:o,subTypeMigrations:s}}var Kl=(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))(Kl||{});function Vu({record:e,migrations:n,fromVersion:t,toVersion:r}){let o=t;if(!DR(e))throw new Error("[migrateRecord] object is not a record");const{typeName:s,id:i,...a}=e;let l=a;for(;o<r;){const c=o+1,u=n.migrators[c];if(!u)return{type:"error",reason:"target-version-too-new"};l=u.up(l),o=c}for(;o>r;){const c=o-1,u=n.migrators[o];if(!u)return{type:"error",reason:"target-version-too-old"};l=u.down(l),o=c}return{type:"success",value:{...l,id:i,typeName:s}}}function Pv({value:e,migrations:n,fromVersion:t,toVersion:r}){let o=t;for(;o<r;){const s=o+1,i=n.migrators[s];if(!i)return{type:"error",reason:"target-version-too-new"};e=i.up(e),o=s}for(;o>r;){const s=o-1,i=n.migrators[o];if(!i)return{type:"error",reason:"target-version-too-old"};e=i.down(e),o=s}return{type:"success",value:e}}class Cv{constructor(n,t){this.types=n,this.options=t}static create(n,t){return new Cv(n,t??{})}get currentStoreVersion(){var n;return((n=this.options.snapshotMigrations)==null?void 0:n.currentVersion)??0}validateRecord(n,t,r,o){try{const s=ai(this.types,t.typeName);if(!s)throw new Error(`Missing definition for record type ${t.typeName}`);return s.validate(t)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:n,record:t,phase:r,recordBefore:o,error:s});throw s}}migratePersistedRecord(n,t,r="up"){var d;const o=ai(this.types,n.typeName),s=t.recordVersions[n.typeName];if(!s||!o)return{type:"error",reason:Kl.UnknownType};const i=o.migrations.currentVersion,a=s.version;if(i!==a){const h=Vu(r==="up"?{record:n,migrations:o.migrations,fromVersion:a,toVersion:i}:{record:n,migrations:o.migrations,fromVersion:i,toVersion:a});if(h.type==="error")return h;n=h.value}if(!o.migrations.subTypeKey)return{type:"success",value:n};const l=(d=o.migrations.subTypeMigrations)==null?void 0:d[n[o.migrations.subTypeKey]],c="subTypeVersions"in s?s.subTypeVersions[n[o.migrations.subTypeKey]]:void 0;if(l===void 0)return{type:"error",reason:Kl.UnrecognizedSubtype};if(c===void 0)return{type:"error",reason:Kl.IncompatibleSubtype};const u=Vu(r==="up"?{record:n,migrations:l,fromVersion:c,toVersion:l.currentVersion}:{record:n,migrations:l,fromVersion:l.currentVersion,toVersion:c});return u.type==="error"?u:{type:"success",value:u.value}}migrateStoreSnapshot(n){let{store:t}=n;const r=this.options.snapshotMigrations;if(!r)return{type:"success",value:t};const o=r.currentVersion,s=n.schema.storeVersion??0;if(o<s)return{type:"error",reason:Kl.TargetVersionTooOld};if(o>s){const a=Pv({value:t,migrations:r,fromVersion:s,toVersion:o});if(a.type==="error")return a;t=a.value}const i=[];for(const a of dt(t)){const l=this.migratePersistedRecord(a,n.schema);if(l.type==="error")return l;l.value&&l.value!==a&&i.push(l.value)}if(i.length){t={...t};for(const a of i)t[a.id]=a}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(){var n;return{schemaVersion:1,storeVersion:((n=this.options.snapshotMigrations)==null?void 0:n.currentVersion)??0,recordVersions:Object.fromEntries(dt(this.types).map(t=>[t.typeName,t.migrations.subTypeKey&&t.migrations.subTypeMigrations?{version:t.migrations.currentVersion,subTypeKey:t.migrations.subTypeKey,subTypeVersions:t.migrations.subTypeMigrations?Object.fromEntries(Object.entries(t.migrations.subTypeMigrations).map(([r,o])=>[r,o.currentVersion])):void 0}:{version:t.migrations.currentVersion}]))}}serializeEarliestVersion(){var n;return{schemaVersion:1,storeVersion:((n=this.options.snapshotMigrations)==null?void 0:n.firstVersion)??0,recordVersions:Object.fromEntries(dt(this.types).map(t=>[t.typeName,t.migrations.subTypeKey&&t.migrations.subTypeMigrations?{version:t.migrations.firstVersion,subTypeKey:t.migrations.subTypeKey,subTypeVersions:t.migrations.subTypeMigrations?Object.fromEntries(Object.entries(t.migrations.subTypeMigrations).map(([r,o])=>[r,o.firstVersion])):void 0}:{version:t.migrations.firstVersion}]))}}}const jR=(e,n)=>{if(e.schemaVersion>n.schemaVersion)return 1;if(e.schemaVersion<n.schemaVersion)return-1;if(e.storeVersion>n.storeVersion)return 1;if(e.storeVersion<n.storeVersion)return-1;for(const t of Object.keys(e.recordVersions)){const r=e.recordVersions[t],o=n.recordVersions[t];if(r.version>o.version)return 1;if(r.version<o.version)return-1;if("subTypeVersions"in r&&!("subTypeVersions"in o))return 1;if(!("subTypeVersions"in r)&&"subTypeVersions"in o)return-1;if(!(!("subTypeVersions"in r)||!("subTypeVersions"in o)))for(const s of Object.keys(r.subTypeVersions)){const i=r.subTypeVersions[s],a=o.subTypeVersions[s];if(i>a)return 1;if(i<a)return-1}}return 0};function LR(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.startsWith(".")?n.slice(1):n}class Fe extends Error{constructor(t,r=[]){const o=LR(r),s=t.split(`
31
+ `).map((i,a)=>a===0?i:` ${i}`).join(`
32
+ `);super(r?`At ${o}: ${s}`:s);y(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Xa(e,n){try{return n()}catch(t){throw t instanceof Fe?new Fe(t.rawMessage,[e,...t.path]):new Fe(t.toString(),[e])}}function Aa(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:Ya(n)}}class cn{constructor(n){this.validationFn=n}validate(n){return this.validationFn(n)}isValid(n){try{return this.validate(n),!0}catch{return!1}}nullable(){return HR(this)}optional(){return bE(this)}refine(n){return new cn(t=>n(this.validate(t)))}check(n,t){return typeof n=="string"?this.refine(r=>(Xa(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class NR extends cn{constructor(n){super(t=>{const r=UR.validate(t);for(let o=0;o<r.length;o++)Xa(o,()=>n.validate(r[o]));return r}),this.itemValidator=n}nonEmpty(){return this.check(n=>{if(n.length===0)throw new Fe("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new Fe("Expected an array with length greater than 1")})}}class qh extends cn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Fe(`Expected object, got ${Aa(r)}`);for(const[o,s]of Object.entries(n))Xa(o,()=>{s.validate(ai(r,o))});if(!t){for(const o of Object.keys(r))if(!Jp(n,o))throw new Fe("Unexpected property",[o])}return r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new qh(this.config,!0)}extend(n){return new qh({...this.config,...n})}}class Ev extends cn{constructor(n,t,r){super(o=>{if(typeof o!="object"||o===null)throw new Fe(`Expected an object, got ${Aa(o)}`,[]);const s=ai(o,n);if(typeof s!="string")throw new Fe(`Expected a string for key "${n}", got ${Aa(s)}`);const i=Jp(t,s)?t[s]:void 0;return i===void 0?this.unknownValueValidation(o,s):Xa(`(${n} = ${s})`,()=>i.validate(o))}),this.key=n,this.config=t,this.unknownValueValidation=r}validateUnknownVariants(n){return new Ev(this.key,this.config,n)}}class FR extends cn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Fe(`Expected object, got ${Aa(r)}`);for(const[o,s]of Object.entries(r))Xa(o,()=>{n.validate(o),t.validate(s)});return r}),this.keyValidator=n,this.valueValidator=t}}function kv(e){return new cn(n=>{if(typeof n!==e)throw new Fe(`Expected ${e}, got ${Aa(n)}`);return n})}const zR=new cn(e=>e),ge=kv("string"),he=kv("number").check(e=>{if(Number.isNaN(e))throw new Fe("Expected a number, got NaN");if(!Number.isFinite(e))throw new Fe(`Expected a finite number, got ${e}`)}),Iv=he.check(e=>{if(e<0)throw new Fe(`Expected a positive number, got ${e}`)}),En=he.check(e=>{if(e<=0)throw new Fe(`Expected a non-zero positive number, got ${e}`)}),xE=he.check(e=>{if(!Number.isInteger(e))throw new Fe(`Expected an integer, got ${e}`)}),Ku=xE.check(e=>{if(e<0)throw new Fe(`Expected a positive integer, got ${e}`)}),BR=xE.check(e=>{if(e<=0)throw new Fe(`Expected a non-zero positive integer, got ${e}`)}),ve=kv("boolean");function kn(e){return new cn(n=>{if(n!==e)throw new Fe(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const UR=new cn(e=>{if(!Array.isArray(e))throw new Fe(`Expected an array, got ${Aa(e)}`);return e});function Ot(e){return new NR(e)}function we(e){return new qh(e)}function Py(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(Py):typeof e=="object"?Object.values(e).every(Py):!1}const Jr=new cn(e=>{if(Py(e))return e;throw new Fe(`Expected json serializable value, got ${typeof e}`)});function Cy(e,n){return new FR(e,n)}function _v(e,n){return new Ev(e,n,(t,r)=>{throw new Fe(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])})}function Uo(e,n){return new cn(t=>{const r=t&&typeof t=="object"&&"id"in t&&typeof t.id=="string"?`${e}(id = ${t.id})`:e;return Xa(r,()=>n.validate(t))})}function iu(e){return new cn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Fe(`Expected ${t}, got ${n}`)}return n})}function bE(e){return new cn(n=>{if(n!==void 0)return e.validate(n)})}function HR(e){return new cn(n=>n===null?null:e.validate(n))}function PE(...e){return iu(new Set(e))}function CE(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Fe(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Fe(`Expected a valid url, got ${JSON.stringify(e)}`)}}const VR=new Set(["http:","https:","mailto:"]),Wn=ge.check(e=>{if(e==="")return;const n=CE(e);if(!VR.has(n.protocol.toLowerCase()))throw new Fe(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),KR=new Set(["http:","https:","data:"]),qa=ge.check(e=>{if(e==="")return;const n=CE(e);if(!KR.has(n.protocol.toLowerCase()))throw new Fe(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)});function ur(e){return ge.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const nf=ur("asset");function Tv(e,n){return we({id:nf,typeName:kn("asset"),type:kn(e),props:n,meta:Jr})}const WR=Uo("camera",we({typeName:kn("camera"),id:ur("camera"),x:he,y:he,z:he,meta:Jr})),_x={AddMeta:1},GR=$e({currentVersion:_x.AddMeta,migrators:{[_x.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Vt=Bo("camera",{validator:WR,migrations:GR,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),yc=we({x:he,y:he,z:he.optional()}),Jl=we({x:he,y:he,w:he,h:he}),YR=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"]),EE=iu(YR),XR=we({type:EE,rotation:he}),kE=he.check(e=>{if(e<0||e>1)throw new Fe("Opacity must be between 0 and 1")}),qR=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),ZR=iu(qR),QR=new Set(["starting","paused","active","stopping"]),IE=we({id:ge,points:Ot(yc),size:Iv,color:ZR,opacity:he,state:iu(QR),delay:he,shrink:he,taper:ve}),Sc=ur("page"),JR=Uo("page",we({typeName:kn("page"),id:Sc,name:ge,index:ge,meta:Jr})),Tx={AddMeta:1},e3=$e({currentVersion:Tx.AddMeta,migrators:{[Tx.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Oo=Bo("page",{validator:JR,migrations:e3,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function gn(e){return Oo.isId(e)}ur("instance");function t3(e){const n={};for(const[r,o]of e)n[r]=bE(o);const t=Uo("instance",we({typeName:kn("instance"),id:ur("instance"),currentPageId:Sc,followingUserId:ge.nullable(),brush:Jl.nullable(),opacityForNextShape:kE,stylesForNextShape:we(n),cursor:XR,scribbles:Ot(IE),isFocusMode:ve,isDebugMode:ve,isToolLocked:ve,exportBackground:ve,screenBounds:Jl,insets:Ot(ve),zoomBrush:Jl.nullable(),isPenMode:ve,isGridMode:ve,chatMessage:ge,isChatting:ve,highlightedUserIds:Ot(ge),canMoveCamera:ve,isFocused:ve,devicePixelRatio:he,isCoarsePointer:ve,isHoveringCanvas:ve.nullable(),openMenus:Ot(ge),isChangingStyle:ve,isReadonly:ve,meta:Jr,duplicateProps:we({shapeIds:Ot(ur("shape")),offset:we({x:he,y:he})}).nullable()}));return Bo("instance",{migrations:n3,validator:t,scope:"session"}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],canMoveCamera:!0,isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const qe={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},n3=$e({currentVersion:qe.AddDuplicateProps,migrators:{[qe.AddTransparentExportBgs]:{up:e=>({...e,exportBackground:!0}),down:({exportBackground:e,...n})=>n},[qe.RemoveDialog]:{up:({dialog:e,...n})=>n,down:e=>({...e,dialog:null})},[qe.AddToolLockMode]:{up:e=>({...e,isToolLocked:!1}),down:({isToolLocked:e,...n})=>n},[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)))}),down:e=>e},[qe.AddLabelColor]:{up:({propsForNextShape:e,...n})=>({...n,propsForNextShape:{...e,labelColor:"black"}}),down:e=>{const{labelColor:n,...t}=e.propsForNextShape;return{...e,propsForNextShape:{...t}}}},[qe.AddFollowingUserId]:{up:e=>({...e,followingUserId:null}),down:({followingUserId:e,...n})=>n},[qe.RemoveAlignJustify]:{up:e=>{let n=e.propsForNextShape.align;return n==="justify"&&(n="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:n}}},down:e=>({...e})},[qe.AddZoom]:{up:e=>({...e,zoomBrush:null}),down:({zoomBrush:e,...n})=>n},[qe.AddVerticalAlign]:{up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:n,...t}=e.propsForNextShape;return{...e,propsForNextShape:t}}},[qe.AddScribbleDelay]:{up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e},down:e=>{if(e.scribble!==null){const{delay:n,...t}=e.scribble;return{...e,scribble:t}}return{...e}}},[qe.RemoveUserId]:{up:({userId:e,...n})=>n,down:e=>({...e,userId:"user:none"})},[qe.AddIsPenModeAndIsGridMode]:{up:e=>({...e,isPenMode:!1,isGridMode:!1}),down:({isPenMode:e,isGridMode:n,...t})=>t},[qe.HoistOpacity]:{up:({propsForNextShape:{opacity:e,...n},...t})=>({...t,opacityForNextShape:Number(e??"1"),propsForNextShape:n}),down:({opacityForNextShape:e,...n})=>({...n,propsForNextShape:{...n.propsForNextShape,opacity:e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}})},[qe.AddChat]:{up:e=>({...e,chatMessage:"",isChatting:!1}),down:({chatMessage:e,isChatting:n,...t})=>t},[qe.AddHighlightedUserIds]:{up:e=>({...e,highlightedUserIds:[]}),down:({highlightedUserIds:e,...n})=>n},[qe.ReplacePropsForNextShapeWithStylesForNextShape]:{up:({propsForNextShape:e,...n})=>({...n,stylesForNextShape:{}}),down:({stylesForNextShape:e,...n})=>({...n,propsForNextShape:{color:"black",labelColor:"black",dash:"draw",fill:"none",size:"m",icon:"file",font:"draw",align:"middle",verticalAlign:"middle",geo:"rectangle",arrowheadStart:"none",arrowheadEnd:"arrow",spline:"line"}})},[qe.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})},[qe.RemoveCursorColor]:{up:e=>{const{color:n,...t}=e.cursor;return{...e,cursor:t}},down:e=>({...e,cursor:{...e.cursor,color:"black"}})},[qe.AddLonelyProperties]:{up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1}),down:({canMoveCamera:e,isFocused:n,devicePixelRatio:t,isCoarsePointer:r,openMenus:o,isChangingStyle:s,isReadOnly:i,...a})=>({...a})},[qe.ReadOnlyReadonly]:{up:({isReadOnly:e,...n})=>({...n,isReadonly:e}),down:({isReadonly:e,...n})=>({...n,isReadOnly:e})},[qe.AddHoveringCanvas]:{up:e=>({...e,isHoveringCanvas:null}),down:({isHoveringCanvas:e,...n})=>({...n})},[qe.AddScribbles]:{up:({scribble:e,...n})=>({...n,scribbles:[]}),down:({scribbles:e,...n})=>({...n,scribble:null})},[qe.AddInset]:{up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...n})=>({...n})},[qe.AddDuplicateProps]:{up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...n})=>({...n})}}}),$t="instance:instance",r3=ge.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),vr=ur("shape");function o3(e,n,t){return we({id:vr,typeName:kn("shape"),x:he,y:he,rotation:he,index:ge,parentId:r3,type:kn(e),isLocked:ve,opacity:kE,props:n?we(n):Jr,meta:t?we(t):Jr})}const s3=Uo("instance_page_state",we({typeName:kn("instance_page_state"),id:ur("instance_page_state"),pageId:Sc,selectedShapeIds:Ot(vr),hintingShapeIds:Ot(vr),erasingShapeIds:Ot(vr),hoveredShapeId:vr.nullable(),editingShapeId:vr.nullable(),croppingShapeId:vr.nullable(),focusedGroupId:vr.nullable(),meta:Jr})),Di={AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5},i3=$e({currentVersion:Di.RenamePropertiesAgain,migrators:{[Di.AddCroppingId]:{up(e){return{...e,croppingShapeId:null}},down({croppingShapeId:e,...n}){return n}},[Di.RemoveInstanceIdAndCameraId]:{up({instanceId:e,cameraId:n,...t}){return t},down(e){return{...e,instanceId:$t,cameraId:Vt.createId("void")}}},[Di.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})},[Di.RenameProperties]:{up:e=>{const{selectedShapeIds:n,hintingShapeIds:t,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}=e;return{selectedShapeIds:n,hintingShapeIds:t,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}},down:e=>{const{selectedShapeIds:n,hintingShapeIds:t,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}=e;return{selectedShapeIds:n,hintingShapeIds:t,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}}},[Di.RenamePropertiesAgain]:{up:e=>{const{selectedIds:n,hintingIds:t,erasingIds:r,hoveredId:o,editingId:s,croppingShapeId:i,croppingId:a,focusLayerId:l,...c}=e;return{...c,selectedShapeIds:n,hintingShapeIds:t,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i??a??null,focusedGroupId:l}},down:e=>{const{selectedShapeIds:n,hintingShapeIds:t,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}=e;return{...l,selectedIds:n,hintingIds:t,erasingIds:r,hoveredId:o,editingId:s,croppingId:i,focusLayerId:a}}}}}),Kt=Bo("instance_page_state",{migrations:i3,validator:s3,scope:"session"}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),a3=Uo("pointer",we({typeName:kn("pointer"),id:ur("pointer"),x:he,y:he,lastActivityTimestamp:he,meta:Jr})),$x={AddMeta:1},l3=$e({currentVersion:$x.AddMeta,migrators:{[$x.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),$v=Bo("pointer",{validator:a3,migrations:l3,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Zh=$v.createId("pointer"),c3=Uo("instance_presence",we({typeName:kn("instance_presence"),id:ur("instance_presence"),userId:ge,userName:ge,lastActivityTimestamp:he,followingUserId:ge.nullable(),cursor:we({x:he,y:he,type:EE,rotation:he}),color:ge,camera:we({x:he,y:he,z:he}),screenBounds:Jl,selectedShapeIds:Ot(ur("shape")),currentPageId:ur("page"),brush:Jl.nullable(),scribbles:Ot(IE),chatMessage:ge,meta:Jr})),ji={AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5},u3=$e({currentVersion:ji.RenameSelectedShapeIds,migrators:{[ji.AddScribbleDelay]:{up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e},down:e=>{if(e.scribble!==null){const{delay:n,...t}=e.scribble;return{...e,scribble:t}}return{...e}}},[ji.RemoveInstanceId]:{up:({instanceId:e,...n})=>n,down:e=>({...e,instanceId:$t})},[ji.AddChatMessage]:{up:e=>({...e,chatMessage:""}),down:({chatMessage:e,...n})=>n},[ji.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})},[ji.RenameSelectedShapeIds]:{up:e=>{const{selectedShapeIds:n,...t}=e;return{selectedShapeIds:n,...t}},down:e=>{const{selectedShapeIds:n,...t}=e;return{selectedShapeIds:n,...t}}}}}),d3=Bo("instance_presence",{migrations:u3,validator:c3,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:{}})),h3=Uo("document",we({typeName:kn("document"),id:kn("document:document"),gridSize:he,name:ge,meta:Jr})),ug={AddName:1,AddMeta:2},p3=$e({currentVersion:ug.AddMeta,migrators:{[ug.AddName]:{up:e=>({...e,name:""}),down:({name:e,...n})=>n},[ug.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Av=Bo("document",{migrations:p3,validator:h3,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),Ey=Av.createId("document");function f3(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function Ax(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const g3=({error:e,phase:n,record:t,recordBefore:r})=>{throw xv(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?Ax(gs(r)):void 0,recordAfter:Ax(gs(t))}}),e};function m3(){return[Oo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function y3(e){const n=e.query.ids("page"),t=()=>{if(!e.has(Ey))return e.put([Av.create({id:Ey,name:e.props.defaultName})]),t();if(!e.has(Zh))return e.put([$v.create({id:Zh})]),t();const r=n.get();if(r.size===0)return e.put(m3()),t();const o=()=>[...r].map(l=>e.get(l)).sort(f3)[0].id,s=e.get($t);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:$t,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const l of r){const c=Kt.createId(l);e.has(c)||i.add(c);const u=Vt.createId(l);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(l=>Kt.create({id:l,pageId:Kt.parseId(l)}))),a.size>0&&e.put([...a].map(l=>Vt.create({id:l})))};return t}const S3=Tv("bookmark",we({title:ge,description:ge,image:ge,src:qa.nullable()})),Mx={MakeUrlsValid:1},v3=$e({currentVersion:Mx.MakeUrlsValid,migrators:{[Mx.MakeUrlsValid]:{up:e=>{const n=e.props.src;return n&&!qa.isValid(n)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),w3=Tv("image",we({w:he,h:he,name:ge,isAnimated:ve,mimeType:ge.nullable(),src:qa.nullable()})),Wu={AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3},x3=$e({currentVersion:Wu.MakeUrlsValid,migrators:{[Wu.AddIsAnimated]:{up:e=>({...e,props:{...e.props,isAnimated:!1}}),down:e=>{const{isAnimated:n,...t}=e.props;return{...e,props:t}}},[Wu.RenameWidthHeight]:{up:e=>{const{width:n,height:t,...r}=e.props;return{...e,props:{w:n,h:t,...r}}},down:e=>{const{w:n,h:t,...r}=e.props;return{...e,props:{width:n,height:t,...r}}}},[Wu.MakeUrlsValid]:{up:e=>{const n=e.props.src;return n&&!qa.isValid(n)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),b3=Tv("video",we({w:he,h:he,name:ge,isAnimated:ve,mimeType:ge.nullable(),src:qa.nullable()})),Gu={AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3},P3=$e({currentVersion:Gu.MakeUrlsValid,migrators:{[Gu.AddIsAnimated]:{up:e=>({...e,props:{...e.props,isAnimated:!1}}),down:e=>{const{isAnimated:n,...t}=e.props;return{...e,props:t}}},[Gu.RenameWidthHeight]:{up:e=>{const{width:n,height:t,...r}=e.props;return{...e,props:{w:n,h:t,...r}}},down:e=>{const{w:n,h:t,...r}=e.props;return{...e,props:{width:n,height:t,...r}}}},[Gu.MakeUrlsValid]:{up:e=>{const n=e.props.src;return n&&!qa.isValid(n)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),C3=Uo("asset",_v("type",{image:w3,video:b3,bookmark:S3})),Ox={AddMeta:1},E3=$e({subTypeKey:"type",subTypeMigrations:{image:x3,video:P3,bookmark:v3},currentVersion:Ox.AddMeta,migrators:{[Ox.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),ei=Bo("asset",{migrations:E3,validator:C3,scope:"document"}).withDefaultProperties(()=>({meta:{}}));class tn{constructor(n,t,r){this.id=n,this.defaultValue=t,this.type=r}static define(n,t){const{defaultValue:r,type:o=zR}=t;return new tn(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new k3(n,r,o)}validate(n){return this.type.validate(n)}}class k3 extends tn{constructor(n,t,r){super(n,t,PE(...r)),this.values=r}}const Yu={AddIsLocked:1,HoistOpacity:2,AddMeta:3},dg=$e({currentVersion:Yu.AddMeta,migrators:{[Yu.AddIsLocked]:{up:e=>({...e,isLocked:!1}),down:e=>{const{isLocked:n,...t}=e;return{...t}}},[Yu.HoistOpacity]:{up:({props:{opacity:e,...n},...t})=>({...t,opacity:Number(e??"1"),props:n}),down:({opacity:e,...n})=>({...n,props:{...n.props,opacity:e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}})},[Yu.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}});function ti(e){return e?e.typeName==="shape":!1}function Rn(e){return e?e.startsWith("shape:"):!1}function We(e){return`shape:${e??ef()}`}function _E(e){const n=new Map;for(const[t,r]of Object.entries(e))if(r instanceof tn){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 I3(e){return Bo("shape",{migrations:$e({currentVersion:dg.currentVersion,firstVersion:dg.firstVersion,migrators:dg.migrators,subTypeKey:"type",subTypeMigrations:by(e,(n,t)=>t.migrations??$e({}))}),scope:"document",validator:Uo("shape",_v("type",by(e,(n,{props:t,meta:r})=>o3(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}const vl={RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4},_3=$e({currentVersion:vl.RemoveUserDocument,migrators:{[vl.RemoveCodeAndIconShapeTypes]:{up:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>t.typeName!=="shape"||t.type!=="icon"&&t.type!=="code")),down:e=>e},[vl.AddInstancePresenceType]:{up:e=>e,down:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>t.typeName!=="instance_presence"))},[vl.RemoveTLUserAndPresenceAndAddPointer]:{up:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>!t.typeName.match(/^(user|user_presence)$/))),down:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>t.typeName!=="pointer"))},[vl.RemoveUserDocument]:{up:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>!t.typeName.match("user_document"))),down:e=>e}}});function T3({shapes:e}){const n=new Map;for(const o of dt(e))for(const s of _E(o.props??{}).keys()){if(n.has(s.id)&&n.get(s.id)!==s)throw new Error(`Multiple StyleProp instances with the same id: ${s.id}`);n.set(s.id,s)}const t=I3(e),r=t3(n);return Cv.create({asset:ei,camera:Vt,document:Av,instance:r,instance_page_state:Kt,page:Oo,shape:t,instance_presence:d3,pointer:$v},{snapshotMigrations:_3,onValidationFailure:g3,createIntegrityChecker:y3})}const TE=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red"],Qh={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4263eb",semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#adb5bd",semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4dabf7",semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#40c057",semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#ff8787",semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e599f7",semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#f76707",semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#ffc078",semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 8%)",solid:"#010403",black:{solid:"#e1e1e1",semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4263eb",semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}}}};function In(e){return e.isDarkMode?Qh.darkMode:Qh.lightMode}const hr=tn.defineEnum("tldraw:color",{defaultValue:"black",values:TE}),$E=tn.defineEnum("tldraw:labelColor",{defaultValue:"black",values:TE}),ui=tn.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Ma=tn.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern"]}),eo=tn.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),au={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},to=tn.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),AE=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Jh=tn.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:AE}),ep=tn.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:AE}),Rx=_v("type",{binding:we({type:kn("binding"),boundShapeId:vr,normalizedAnchor:yc,isExact:ve,isPrecise:ve}),point:we({type:kn("point"),x:he,y:he})}),$3={labelColor:$E,color:hr,fill:Ma,dash:ui,size:to,arrowheadStart:Jh,arrowheadEnd:ep,font:eo,start:Rx,end:Rx,bend:he,text:ge,labelPosition:he},Xu={AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3},A3=$e({currentVersion:Xu.AddLabelPosition,migrators:{[Xu.AddLabelColor]:{up:e=>({...e,props:{...e.props,labelColor:"black"}}),down:e=>{const{labelColor:n,...t}=e.props;return{...e,props:t}}},[Xu.AddIsPrecise]:{up:e=>{const{start:n,end:t}=e.props;return{...e,props:{...e.props,start:n.type==="binding"?{...n,isPrecise:!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5)}:n,end:t.type==="binding"?{...t,isPrecise:!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5)}:t}}},down:e=>{const{start:n,end:t}=e.props,r={...n},o={...t};return r.type==="binding"&&(r.isPrecise||(r.normalizedAnchor={x:.5,y:.5}),delete r.isPrecise),o.type==="binding"&&(o.isPrecise||(o.normalizedAnchor={x:.5,y:.5}),delete o.isPrecise),{...e,props:{...e.props,start:r,end:o}}}},[Xu.AddLabelPosition]:{up:e=>({...e,props:{...e.props,labelPosition:.5}}),down:e=>{const{labelPosition:n,...t}=e.props;return{...e,props:t}}}}}),M3={w:En,h:En,assetId:nf.nullable(),url:Wn},hg={NullAssetId:1,MakeUrlsValid:2},O3=$e({currentVersion:hg.MakeUrlsValid,migrators:{[hg.NullAssetId]:{up:e=>e.props.assetId===void 0?{...e,props:{...e.props,assetId:null}}:e,down:e=>{if(e.props.assetId===null){const{assetId:n,...t}=e.props;return{...e,props:t}}return e}},[hg.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Wn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),ME=we({type:PE("free","straight"),points:Ot(yc)}),R3={color:hr,fill:Ma,dash:ui,size:to,segments:Ot(ME),isComplete:ve,isClosed:ve,isPen:ve},Dx={AddInPen:1},D3=$e({currentVersion:Dx.AddInPen,migrators:{[Dx.AddInPen]:{up:e=>{const{points:n}=e.props.segments[0];if(n.length===0)return{...e,props:{...e.props,isPen:!1}};let t=!(n[0].z===0||n[0].z===.5);return n[1]&&(t=t&&!(n[1].z===0||n[1].z===.5)),{...e,props:{...e.props,isPen:t}}},down:e=>{const{isPen:n,...t}=e.props;return{...e,props:{...t}}}}}});var j3={};const jx=/(^\/r\/[^/]+\/?$)/,Le=e=>{try{return new URL(e)}catch{return}},Oa=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,canUnmount:!0,toEmbedUrl:e=>{const n=Le(e);if(n&&n.pathname.match(jx))return e},fromEmbedUrl:e=>{const n=Le(e);if(n&&n.pathname.match(jx))return e}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,canUnmount:!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=Le(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,canUnmount:!1,toEmbedUrl:e=>{if(e.includes("/maps/")){const n=e.match(/@(.*),(.*),(.*)z/);let t;if(n){const[,r,o,s]=n;t=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${j3.NEXT_PUBLIC_GC_API_KEY}&center=${r},${o}&zoom=${s}`}else t="";return t}},fromEmbedUrl:e=>{const n=Le(e);if(!n)return;if(n.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&n.searchParams.has("center")&&n.searchParams.get("zoom")){const r=n.searchParams.get("zoom"),[o,s]=n.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${s},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,canUnmount:!1,toEmbedUrl:e=>{const n=Le(e),t=n&&n.pathname.match(/\/v\/([^/]+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:e=>{const n=Le(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,canUnmount:!1,toEmbedUrl:e=>{const n=Le(e),t=n&&n.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:e=>{const n=Le(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,canUnmount:!1,toEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,canUnmount:!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,canUnmount:!1,overridePermissions:{"allow-presentation":!0},isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Le(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=Le(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,canUnmount:!1,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",toEmbedUrl:e=>{const n=Le(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=Le(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,canUnmount:!1,toEmbedUrl:e=>{const n=Le(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=Le(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,canUnmount:!0,toEmbedUrl:e=>{const n=Le(e);if(n&&n.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const n=Le(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,canUnmount:!1,toEmbedUrl:e=>{const n=Le(e);if(n&&n.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const n=Le(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,canUnmount:!1,toEmbedUrl:e=>{const n=Le(e);if(n&&n.pathname.match(/^\/map\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=Le(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,canUnmount:!1,toEmbedUrl:e=>{const n=Le(e);if(n&&n.pathname.match(/^\/(artist|album)\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=Le(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,canUnmount:!1,isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Le(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=Le(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,canUnmount:!1,isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Le(e);if(n&&n.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const n=Le(e);if(n&&n.hash.match(/#room=/))return e}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,canUnmount:!1,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:e=>{const n=Le(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=Le(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-*`}}],L3={"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},N3={w:En,h:En,url:ge},wl={GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4},F3=$e({currentVersion:wl.RemovePermissionOverrides,migrators:{[wl.GenOriginalUrlInEmbed]:{up:e=>{const n=e.props.url,t=new URL(n).host.replace("www.","");let r;for(const o of Oa)if(o.hostnames.includes(t))try{r=o.fromEmbedUrl(n)}catch(s){console.warn(s)}return{...e,props:{...e.props,tmpOldUrl:e.props.url,url:r??""}}},down:e=>{let n=e.props.tmpOldUrl;if(!n||n===""){const o=e.props.url,s=new URL(o).host.replace("www.","");for(const i of Oa)if(i.hostnames.includes(s))try{n=i.toEmbedUrl(o)}catch(a){console.warn(a)}}const{tmpOldUrl:t,...r}=e.props;return{...e,props:{...r,url:n??""}}}},[wl.RemoveDoesResize]:{up:e=>{const{doesResize:n,...t}=e.props;return{...e,props:{...t}}},down:e=>({...e,props:{...e.props,doesResize:!0}})},[wl.RemoveTmpOldUrl]:{up:e=>{const{tmpOldUrl:n,...t}=e.props;return{...e,props:{...t}}},down:e=>({...e,props:{...e.props}})},[wl.RemovePermissionOverrides]:{up:e=>{const{overridePermissions:n,...t}=e.props;return{...e,props:{...t}}},down:e=>({...e,props:{...e.props}})}}}),z3={w:En,h:En,name:ge},B3=$e({}),vc=tn.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),tp=tn.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),qr=tn.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"]}),U3={geo:qr,labelColor:$E,color:hr,fill:Ma,dash:ui,size:to,font:eo,align:vc,verticalAlign:tp,url:Wn,w:En,h:En,growY:Iv,text:ge},po={AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8},H3=$e({currentVersion:po.MakeUrlsValid,migrators:{[po.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[po.AddLabelColor]:{up:e=>({...e,props:{...e.props,labelColor:"black"}}),down:e=>{const{labelColor:n,...t}=e.props;return{...e,props:t}}},[po.RemoveJustify]:{up:e=>{let n=e.props.align;return n==="justify"&&(n="start"),{...e,props:{...e.props,align:n}}},down:e=>({...e})},[po.AddCheckBox]:{up:e=>({...e}),down:e=>({...e,props:{...e.props,geo:e.props.geo==="check-box"?"rectangle":e.props.geo}})},[po.AddVerticalAlign]:{up:e=>({...e,props:{...e.props,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:n,...t}=e.props;return{...e,props:t}}},[po.MigrateLegacyAlign]:{up:e=>{let n;switch(e.props.align){case"start":n="start-legacy";break;case"end":n="end-legacy";break;default:n="middle-legacy";break}return{...e,props:{...e.props,align:n}}},down:e=>{let n;switch(e.props.align){case"start-legacy":n="start";break;case"end-legacy":n="end";break;case"middle-legacy":n="middle";break;default:n=e.props.align}return{...e,props:{...e.props,align:n}}}},[po.AddCloud]:{up:e=>e,down:e=>{if(e.props.geo==="cloud")return{...e,props:{...e.props,geo:"rectangle"}}}},[po.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Wn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),V3={},K3=$e({}),W3={color:hr,size:to,segments:Ot(ME),isComplete:ve,isPen:ve},G3=$e({}),Y3=we({topLeft:yc,bottomRight:yc}),X3={w:En,h:En,playing:ve,url:Wn,assetId:nf.nullable(),crop:Y3.nullable()},qu={AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3},q3=$e({currentVersion:qu.MakeUrlsValid,migrators:{[qu.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[qu.AddCropProp]:{up:e=>({...e,props:{...e.props,crop:null}}),down:e=>{const{crop:n,...t}=e.props;return{...e,props:t}}},[qu.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Wn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),Z3=new Set(["vertex","virtual","create"]),Q3=we({id:ge,type:iu(Z3),canBind:ve.optional(),canSnap:ve.optional(),index:ge,x:he,y:he}),np=tn.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),J3={color:hr,dash:ui,size:to,spline:np,handles:Cy(ge,Q3)},Lx={AddSnapHandles:1},eD=$e({currentVersion:Lx.AddSnapHandles,migrators:{[Lx.AddSnapHandles]:{up:e=>{const n=Zt(e.props.handles);for(const t in n)n[t].canSnap=!0;return{...e,props:{...e.props,handles:n}}},down:e=>{const n=Zt(e.props.handles);for(const t in n)delete n[t].canSnap;return{...e,props:{...e.props,handles:n}}}}}}),tD={color:hr,size:to,font:eo,align:vc,verticalAlign:tp,growY:Iv,url:Wn,text:ge},Li={AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5},nD=$e({currentVersion:Li.MakeUrlsValid,migrators:{[Li.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[Li.RemoveJustify]:{up:e=>{let n=e.props.align;return n==="justify"&&(n="start"),{...e,props:{...e.props,align:n}}},down:e=>({...e})},[Li.MigrateLegacyAlign]:{up:e=>{let n;switch(e.props.align){case"start":n="start-legacy";break;case"end":n="end-legacy";break;default:n="middle-legacy";break}return{...e,props:{...e.props,align:n}}},down:e=>{let n;switch(e.props.align){case"start-legacy":n="start";break;case"end-legacy":n="end";break;case"middle-legacy":n="middle";break;default:n=e.props.align}return{...e,props:{...e.props,align:n}}}},[Li.AddVerticalAlign]:{up:e=>({...e,props:{...e.props,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:n,...t}=e.props;return{...e,props:t}}},[Li.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Wn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),rD={color:hr,size:to,font:eo,align:vc,w:En,text:ge,scale:En,autoSize:ve},Nx={RemoveJustify:1},oD=$e({currentVersion:Nx.RemoveJustify,migrators:{[Nx.RemoveJustify]:{up:e=>{let n=e.props.align;return n==="justify"&&(n="start"),{...e,props:{...e.props,align:n}}},down:e=>({...e})}}}),sD={w:En,h:En,time:he,playing:ve,url:Wn,assetId:nf.nullable()},pg={AddUrlProp:1,MakeUrlsValid:2},iD=$e({currentVersion:pg.MakeUrlsValid,migrators:{[pg.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[pg.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Wn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),wc=[{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:"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:"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 aD(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return lD(e)}function lD(e){for(const n of e){const t=cD(n);if(t)return t}return"en"}const Fx={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function cD(e){const n=wc.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=wc.find(s=>s.locale===t);if(o)return o.locale}return t in Fx?Fx[t]:null}var OE={exports:{}};/*!
33
+ Copyright (c) 2018 Jed Watson.
34
+ Licensed under the MIT License (MIT), see
35
+ http://jedwatson.github.io/classnames
36
+ */(function(e){(function(){var n={}.hasOwnProperty;function t(){for(var s="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(s=o(s,r(a)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return t.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var i="";for(var a in s)n.call(s,a)&&s[a]&&(i=o(i,a));return i}function o(s,i){return i?s?s+" "+i:s+i:s}e.exports?(t.default=t,e.exports=t):window.classNames=t})()})(OE);var uD=OE.exports;const fe=Ka(uD),qt={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},fo=2e3,rp=40,xo=320,Ni=[.1,.25,.5,1,2,4,8],xl=.1,os=8,dD=.5,hD=.1,pD=.2,fD=.005,gD=.05,mD=450,yD=200,ky=6,xc=4,SD=32,op={};for(let e=1;e<=Math.ceil(os);e++)op[e+"_dark"]=`hash_pattern_zoom_${e}_dark`,op[e+"_light"]=`hash_pattern_zoom_${e}_light`;const vD={duration:0,easing:qt.easeInOutCubic},qd=.09,zx=[{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}],wD=6e4,RE=3e3,xD=1200,Bx={CAMERA_MOVE:-10},bD=64,PD=620,Or=8,CD=20,ED=8,kD=12,DE=20,jE=12;var fg={};const ID={},Oe={preventDefaultLogging:fn("preventDefaultLogging",{defaults:{all:!1}}),pointerCaptureLogging:fn("pointerCaptureLogging",{defaults:{all:!1}}),pointerCaptureTracking:fn("pointerCaptureTracking",{defaults:{all:!1}}),pointerCaptureTrackingObject:fn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),elementRemovalLogging:fn("elementRemovalLogging",{defaults:{all:!1}}),debugSvg:fn("debugSvg",{defaults:{all:!1}}),showFps:fn("showFps",{defaults:{all:!1}}),throwToBlob:fn("throwToBlob",{defaults:{all:!1}}),logMessages:fn("uiLog",{defaults:{all:[]}}),resetConnectionEveryPing:fn("resetConnectionEveryPing",{defaults:{all:!1}}),debugCursors:fn("debugCursors",{defaults:{all:!1}}),forceSrgb:fn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:fn("debugGeometry",{defaults:{all:!1}}),hideShapes:fn("hideShapes",{defaults:{all:!1}})};typeof window<"u"&&(window.tldrawLog=e=>{Oe.logMessages.set(Oe.logMessages.get().concat(e))});if(typeof Element<"u"){const e=Element.prototype.removeChild;su("element removal logging",()=>{Oe.elementRemovalLogging.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function fn(e,{defaults:n,shouldStoreForSession:t=!0}){return _D({name:e,defaults:n,shouldStoreForSession:t})}function _D(e){const n=$D(e),t=e.shouldStoreForSession?TD(e.name):null,r=sn(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&su(`debug:${e.name}`,()=>{const o=r.get();try{o===n?window.sessionStorage.removeItem(`tldraw_debug:${e.name}`):window.sessionStorage.setItem(`tldraw_debug:${e.name}`,JSON.stringify(o))}catch{}}),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 TD(e){try{return JSON.parse((window==null?void 0:window.sessionStorage.getItem(`tldraw_debug:${e}`))??"null")}catch{return null}}function gg(e){try{return e()}catch{return null}}function $D(e){switch(gg(()=>fg.TLDRAW_ENV)??gg(()=>fg.VERCEL_PUBLIC_TLDRAW_ENV)??gg(()=>fg.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 sp(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return sp(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ee(e){e.preventDefault(),Oe.preventDefaultLogging.get()&&console.warn("preventDefault called on event:",e)}function lu(e,n){if(e.setPointerCapture(n.pointerId),Oe.pointerCaptureTracking.get()){const t=Oe.pointerCaptureTrackingObject.get();t.set(e,(t.get(e)??0)+1)}Oe.pointerCaptureLogging.get()&&console.warn("setPointerCapture called on element:",e,n)}function cu(e,n){if(e.hasPointerCapture(n.pointerId)){if(e.releasePointerCapture(n.pointerId),Oe.pointerCaptureTracking.get()){const t=Oe.pointerCaptureTrackingObject.get();t.get(e)===1?t.delete(e):t.has(e)?t.set(e,t.get(e)-1):console.warn("Release without capture")}Oe.pointerCaptureLogging.get()&&console.warn("releasePointerCapture called on element:",e,n)}}const Dt=e=>e.stopPropagation();function vn(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"}}const Mv=ne.createContext({});function U(){return ne.useContext(Mv)}function AD(){const e=U();return w.useMemo(function(){let r,o;function s(f){if(!f.isKilled){if(f.button===2){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...vn(f)});return}f.button!==0&&f.button!==1&&f.button!==5||(lu(f.currentTarget,f),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...vn(f)}),e.getOpenMenus().length>0&&(e.updateInstanceState({openMenus:[]}),document.body.click(),e.getContainer().focus()))}}function i(f){f.isKilled||f.clientX===r&&f.clientY===o||(r=f.clientX,o=f.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...vn(f)}))}function a(f){f.isKilled||f.button!==0&&f.button!==1&&f.button!==2&&f.button!==5||(r=f.clientX,o=f.clientY,cu(f.currentTarget,f),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...vn(f)}))}function l(f){if(f.isKilled||e.getInstanceState().isPenMode&&f.pointerType!=="pen")return;const S=f.pointerType==="mouse"||f.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:S?!0:null})}function c(f){if(f.isKilled||e.getInstanceState().isPenMode&&f.pointerType!=="pen")return;const S=f.pointerType==="mouse"||f.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:S?!1:null})}function u(f){f.isKilled=!0,document.body.click(),Ee(f)}function d(f){f.isKilled=!0,f.target.tagName!=="A"&&f.target.tagName!=="TEXTAREA"&&Ee(f)}function h(f){Ee(f)}async function p(f){var v,x;if(Ee(f),!((x=(v=f.dataTransfer)==null?void 0:v.files)!=null&&x.length))return;const S=Array.from(f.dataTransfer.files);await e.putExternalContent({type:"files",files:S,point:e.screenToPage({x:f.clientX,y:f.clientY}),ignoreParent:!1})}function m(f){Dt(f)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:h,onDrop:p,onTouchStart:u,onTouchEnd:d,onClick:m}},[e])}function MD(){const e=U();w.useEffect(()=>{if(e.environment.isFirefox&&!e.environment.isAndroid&&!e.environment.isIos){e.updateInstanceState({isCoarsePointer:!1});return}if(window.matchMedia){const n=window.matchMedia("(pointer: coarse)"),t=()=>{e.updateInstanceState({isCoarsePointer:!!n.matches})};if(t(),n)return n.addEventListener("change",t),()=>n.removeEventListener("change",t)}},[e])}const LE=w.createContext(null);function OD({container:e,children:n}){return g.jsx(LE.Provider,{value:e,children:n})}function un(){return mE(w.useContext(LE),"useContainer used outside of <Tldraw />")}function RD(){const e=U(),n=un(),t=G("isFocused",()=>e.getInstanceState().isFocused,[e]);w.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=l=>{l.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},e.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[e]),w.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!Zu()&&Ee(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Ee(a);return}break}case"Tab":{if(Zu()||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(),n.focus());return}default:if(Zu()||e.getIsMenuOpen())return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)},o=a=>{if(a.isKilled||(a.isKilled=!0,Zu()||e.getIsMenuOpen())||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)};function s(a){var l,c;if(n.contains(a.target)){const u=a.touches[0].pageX,d=a.touches[0].radiusX||0;(u-d<10||u+d>e.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),Ee(a))}}const i=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ee(a)};return n.addEventListener("touchstart",s,{passive:!1}),n.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ee),document.addEventListener("gesturechange",Ee),document.addEventListener("gestureend",Ee),n.addEventListener("keydown",r),n.addEventListener("keyup",o),()=>{n.removeEventListener("touchstart",s),n.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ee),document.removeEventListener("gesturechange",Ee),document.removeEventListener("gestureend",Ee),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const DD=["input","select","button","textarea"];function Zu(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||DD.indexOf(e.tagName.toLowerCase())>-1))}const jD={error:null};class NE extends w.Component{constructor(){super(...arguments);y(this,"state",jD)}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 g.jsx(r,{error:t})}return this.props.children}}function bc({children:e,fallback:n,...t}){return n===null?g.jsx(g.Fragment,{children:e}):g.jsx(NE,{fallback:n,...t,children:e})}class LD{constructor(n){this.shape=n}equals(n){var t,r,o,s,i,a;return((t=this.shape)==null?void 0:t.isLocked)===((r=n==null?void 0:n.shape)==null?void 0:r.isLocked)&&((o=this.shape)==null?void 0:o.props)===((s=n==null?void 0:n.shape)==null?void 0:s.props)&&((i=this.shape)==null?void 0:i.meta)===((a=n==null?void 0:n.shape)==null?void 0:a.meta)}}const ND=({shape:e,util:n})=>Qp("Indicator:"+e.type,()=>n.indicator(e)),FD=({editor:e,id:n})=>{const t=G("shape",()=>new LD(e.store.get(n)),[e,n]),{ShapeIndicatorErrorFallback:r}=Pt();return!t.shape||t.shape.isLocked?null:g.jsx(bc,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:g.jsx(ND,{shape:t.shape,util:e.getShapeUtil(t.shape)},t.shape.id)})},zD=({id:e,className:n,color:t,opacity:r})=>{const o=U(),s=G("transform",()=>{const i=o.getShapePageTransform(e);return i?i.toCssString():""},[o,e]);return g.jsx("svg",{className:fe("tl-overlays__item",n),children:g.jsx("g",{className:"tl-shape-indicator",transform:s,stroke:t??"var(--color-selected)",opacity:r,children:g.jsx(FD,{editor:o,id:e})})})},uu=w.memo(zD);function BD(){return g.jsx("div",{className:"tl-background"})}function Za(e,n,t,r,o,s){w.useLayoutEffect(()=>{const i=e.current;if(!i||n===void 0)return;let a=`translate(${n}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),o!==void 0&&(a+=` rotate(${o}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),i.style.transform=a})}class C{constructor(n=0,t=0,r=1){this.x=n,this.y=t,this.z=r}get pressure(){return this.z}set(n=this.x,t=this.y,r=this.z){return this.x=n,this.y=t,this.z=r,this}setTo({x:n=0,y:t=0,z:r=1}){return this.x=n,this.y=t,this.z=r,this}rot(n){if(n===0)return this;const{x:t,y:r}=this,o=Math.sin(n),s=Math.cos(n);return this.x=t*s-r*o,this.y=t*o+r*s,this}rotWith(n,t){if(t===0)return this;const r=this.x-n.x,o=this.y-n.y,s=Math.sin(t),i=Math.cos(t);return this.x=n.x+(r*i-o*s),this.y=n.y+(r*s+o*i),this}clone(){const{x:n,y:t,z:r}=this;return new C(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=C.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 C.Dpr(this,n)}cpr(n){return C.Cpr(this,n)}len2(){return C.Len2(this)}len(){return C.Len(this)}pry(n){return C.Pry(this,n)}per(){const{x:n,y:t}=this;return this.x=t,this.y=-n,this}uni(){return C.Uni(this)}tan(n){return C.Tan(this,n)}dist(n){return C.Dist(this,n)}distanceToLineSegment(n,t){return C.DistanceToLineSegment(n,t,this)}slope(n){return C.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 C.Angle(this,n)}toAngle(){return C.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 C.Equals(this,n)}equalsXY(n,t){return C.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 C.ToFixed(this)}toString(){return C.ToString(C.ToFixed(this))}toJson(){return C.ToJson(this)}toArray(){return C.ToArray(this)}static Add(n,t){return new C(n.x+t.x,n.y+t.y)}static AddXY(n,t,r){return new C(n.x+t,n.y+r)}static Sub(n,t){return new C(n.x-t.x,n.y-t.y)}static SubXY(n,t,r){return new C(n.x-t,n.y-r)}static AddScalar(n,t){return new C(n.x+t,n.y+t)}static SubScalar(n,t){return new C(n.x-t,n.y-t)}static Div(n,t){return new C(n.x/t,n.y/t)}static Mul(n,t){return new C(n.x*t,n.y*t)}static DivV(n,t){return new C(n.x/t.x,n.y/t.y)}static MulV(n,t){return new C(n.x*t.x,n.y*t.y)}static Neg(n){return new C(-n.x,-n.y)}static Per(n){return new C(n.y,-n.x)}static Dist2(n,t){return C.Sub(n,t).len2()}static Abs(n){return new C(Math.abs(n.x),Math.abs(n.y))}static Dist(n,t){return Math.hypot(n.y-t.y,n.x-t.x)}static Dpr(n,t){return n.x*t.x+n.y*t.y}static Cross(n,t){return new C(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 Math.hypot(n.x,n.y)}static Pry(n,t){return C.Dpr(n,t)/C.Len(t)}static Uni(n){return C.Div(n,C.Len(n))}static Tan(n,t){return C.Uni(C.Sub(n,t))}static Min(n,t){return new C(Math.min(n.x,t.x),Math.min(n.y,t.y))}static Max(n,t){return new C(Math.max(n.x,t.x),Math.max(n.y,t.y))}static From({x:n,y:t,z:r=1}){return new C(n,t,r)}static FromArray(n){return new C(n[0],n[1])}static Rot(n,t=0){const r=Math.sin(t),o=Math.cos(t);return new C(n.x*o-n.y*r,n.x*r+n.y*o)}static RotWith(n,t,r){const o=n.x-t.x,s=n.y-t.y,i=Math.sin(r),a=Math.cos(r);return new C(t.x+(o*a-s*i),t.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(n,t,r){return C.Mul(t,C.Sub(r,n).pry(t)).add(n)}static NearestPointOnLineSegment(n,t,r,o=!0){const s=C.Tan(t,n),i=C.Add(n,C.Mul(s,C.Sub(r,n).pry(s)));if(o){if(i.x<Math.min(n.x,t.x))return C.Cast(n.x<t.x?n:t);if(i.x>Math.max(n.x,t.x))return C.Cast(n.x>t.x?n:t);if(i.y<Math.min(n.y,t.y))return C.Cast(n.y<t.y?n:t);if(i.y>Math.max(n.y,t.y))return C.Cast(n.y>t.y?n:t)}return i}static DistanceToLineThroughPoint(n,t,r){return C.Dist(r,C.NearestPointOnLineThroughPoint(n,t,r))}static DistanceToLineSegment(n,t,r,o=!0){return C.Dist(r,C.NearestPointOnLineSegment(n,t,r,o))}static Snap(n,t=1){return new C(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}static Cast(n){return n instanceof C?n:C.From(n)}static Slope(n,t){return n.x===t.y?NaN:(n.y-t.y)/(n.x-t.x)}static Angle(n,t){return Math.atan2(t.y-n.y,t.x-n.x)}static Lrp(n,t,r){return C.Sub(t,n).mul(r).add(n)}static Med(n,t){return new C((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=C.Len(n);return new C(t*n.x/r,t*n.y/r)}static ScaleWithOrigin(n,t,r){return C.Sub(n,r).mul(t).add(r)}static ToFixed(n,t=2){return new C(+n.x.toFixed(t),+n.y.toFixed(t),+n.z.toFixed(t))}static Nudge(n,t,r){return C.Add(n,C.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 C(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 C(0,0);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 C(Math.min(Math.max(n.x,t)),Math.min(Math.max(n.y,t))):new C(Math.min(Math.max(n.x,t),r),Math.min(Math.max(n.y,t),r))}static PointsBetween(n,t,r=6){const o=[];for(let s=0;s<r;s++){const i=qt.easeInQuad(s/(r-1)),a=C.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-UD(i))*.65),o.push(a)}return o}static SnapToGrid(n,t=8){return new C(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}}const UD=e=>e<.5?2*e*e:-1+(4-2*e)*e;function At(e){return`${O(e.x)},${O(e.y)} `}function yn(e,n){return`${O((e.x+n.x)/2)},${O((e.y+n.y)/2)} `}const Te=Math.PI,Ve=Te/2,Re=Te*2,HD=Math.sin;function or(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function Qu(e,n=1e10){return e?Math.round(e*n)/n:0}function ec(e,n,t=1e-6){return Math.abs(e-n)<=t}function Pc(e,n){const t=Math.pow(e-n,2)/Math.pow(e+n,2);return Te*(e+n)*(1+3*t/(10+Math.sqrt(4-3*t)))}function _r(e){return e=e%Re,e<0?e=e+Re:e===0&&(e=0),e}function du(e,n){return e=_r(e),n=_r(n),e>n&&(n+=Re),n-e}function FE(e,n){return Re-du(e,n)}function tc(e,n){const t=(n-e)%Re;return 2*t%Re-t}function Iy(e){return(Re+e)%Re}function ip(e,n){const t=Re/n;let r=Math.floor((Iy(e)+t/2)/t)*t%Re;return r<Te&&(r+=Re),r>Te&&(r-=Re),r}function zE(e,n){return e===n||ec(e%(Math.PI/2)-n%(Math.PI/2),0)}function VD(e){return e*Te/180}function KD(e){return e*180/Te}function di(e,n,t){return new C(e.x,e.y).add(C.FromAngle(t,n))}function mg(e,n,t){const r=e/2,o=n/2,s=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let m=0;m<t;m++){const f=Re/t,S=-Ve+m*f,v=r+r*Math.cos(S),x=o+o*Math.sin(S);v<i&&(i=v),x<l&&(l=x),v>a&&(a=v),x>c&&(c=x),s.push(new C(v,x))}const u=a-i,d=c-l,h=e-u,p=n-d;if(h!==0||p!==0)for(let m=0;m<s.length;m++){const f=s[m];f.x=(f.x-i)/u*e,f.y=(f.y-l)/d*n}return s}function bl(e,n,t,r){return e<r&&t<n}function wr(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function Ux(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function Rr(e,n){let t=0,r,o;for(let s=0;s<n.length;s++){if(r=n[s],r.x===e.x&&r.y===e.y||(o=n[(s+1)%n.length],C.Dist(e,r)+C.Dist(e,o)===C.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&Ux(r,o,e)>0&&(t+=1):o.y<=e.y&&Ux(r,o,e)<0&&(t-=1)}return t!==0}function O(e){return+e.toFixed(4)}function ap(e){return+e.toFixed(2)}const Hx=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function ss(e,n,t){return t<0?du(e,n):FE(e,n)}function _y(e,n,t,r){let o;if(Math.abs(e)>Te){o=tc(n,r);const s=tc(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=tc(n,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function WD(e,n,t,r){const o=2*((n-e)%Re)%Re-(n-e)%Re;return r?(Re-Math.abs(o))*(t?1:-1):o}const Ju=({brush:e,color:n,opacity:t,className:r})=>{const o=w.useRef(null);Za(o,e.x,e.y);const s=O(Math.max(1,e.w)),i=O(Math.max(1,e.h));return g.jsx("svg",{className:"tl-overlays__item",ref:o,children:n?g.jsxs("g",{className:"tl-brush",opacity:t,children:[g.jsx("rect",{width:s,height:i,fill:n,opacity:.75}),g.jsx("rect",{width:s,height:i,fill:"none",stroke:n,opacity:.1})]}):g.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},GD=({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1})=>{const i=w.useRef(null);return Za(i,or(t.x,o.minX+5/n,o.maxX-5/n),or(t.y,o.minY+5/n,o.maxY-5/n),1/n,C.Angle(o.center,t)),g.jsxs("svg",{ref:i,className:fe("tl-overlays__item",e),children:[g.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),g.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})},YD=({className:e,zoom:n,point:t,color:r,name:o,chatMessage:s})=>{const i=w.useRef(null);return Za(i,t==null?void 0:t.x,t==null?void 0:t.y,1/n),t?g.jsxs("div",{ref:i,className:fe("tl-overlays__item",e),children:[g.jsx("svg",{className:"tl-cursor",children:g.jsx("use",{href:"#cursor",color:r})}),s?g.jsxs(g.Fragment,{children:[o&&g.jsx("div",{className:"tl-nametag-title",style:{color:r},children:o}),g.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:r},children:s})]}):o&&g.jsx("div",{className:"tl-nametag",style:{backgroundColor:r},children:o})]}):null},Vx=w.memo(YD),Ov={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 BE(){Ov.hardReset()}function XD(){Ov.refreshPage()}const qD="https://github.com/tldraw/tldraw/issues/new";function ZD(){}const UE=({error:e,editor:n})=>{const t=w.useRef(null),[r,o]=w.useState(!1),[s,i]=w.useState(!1),[a,l]=w.useState(!1),c=e instanceof Error?e.message:String(e),u=e instanceof Error?e.stack:null,d=G("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[h,p]=w.useState(null);w.useLayoutEffect(()=>{var P;d!==null&&p(d);let x=(P=t.current)==null?void 0:P.parentElement,b=!1;for(;x;){if(x.classList.contains("tl-theme__dark")||x.classList.contains("tl-theme__light")){b=!0;break}x=x.parentElement}if(b){p(null);return}p(window.matchMedia("(prefers-color-scheme: dark)").matches)},[d]),w.useEffect(()=>{if(s){const x=setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(x)}},[s]);const m=()=>{const x=document.createElement("textarea");x.value=u??c,document.body.appendChild(x),x.select(),document.execCommand("copy"),x.remove(),i(!0)},f=()=>{XD()},S=async()=>{BE()},v=new URL(qD);return v.searchParams.set("title",c),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
37
+
38
+ \`\`\`js
39
+ ${u??c}
40
+ \`\`\`
41
+
42
+ My browser: ${navigator.userAgent}`),g.jsxs("div",{ref:t,className:fe("tl-container tl-error-boundary",h===null?"":h?"tl-theme__dark":"tl-theme__light"),children:[g.jsx("div",{className:"tl-error-boundary__overlay"}),n&&g.jsx(NE,{onError:ZD,fallback:()=>null,children:g.jsx(Mv.Provider,{value:n,children:g.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:g.jsx(Fv,{})})})}),g.jsx("div",{className:fe("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?g.jsxs(g.Fragment,{children:[g.jsx("h2",{children:"Are you sure?"}),g.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),g.jsxs("div",{className:"tl-error-boundary__content__actions",children:[g.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),g.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):g.jsxs(g.Fragment,{children:[g.jsx("h2",{children:"Something's gone wrong."}),g.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",g.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",g.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&g.jsxs("div",{className:"tl-error-boundary__content__error",children:[g.jsx("pre",{children:g.jsx("code",{children:u??c})}),g.jsx("button",{onClick:m,children:s?"Copied!":"Copy"})]}),g.jsxs("div",{className:"tl-error-boundary__content__actions",children:[g.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),g.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[g.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),g.jsx("button",{className:"tl-error-boundary__refresh",onClick:f,children:"Refresh Page"})]})]})]})})]})},QD=({x:e,y:n,z:t,size:r})=>g.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[g.jsx("defs",{children:zx.map(({min:o,mid:s,step:i},a)=>{const l=i*r*t,c=.5+e*t,u=.5+n*t,d=c>0?c%l:l+c%l,h=u>0?u%l:l+u%l,p=t<s?Gh(t,[o,s],[0,1]):1;return g.jsx("pattern",{id:`grid-${i}`,width:l,height:l,patternUnits:"userSpaceOnUse",children:g.jsx("circle",{className:"tl-grid-dot",cx:d,cy:h,r:1,opacity:p})},`grid-pattern-${a}`)})}),zx.map(({step:o},s)=>g.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${o})`},`grid-rect-${s}`))]}),JD=({handle:e,isCoarse:n,className:t,zoom:r})=>{const o=(n?DE:jE)/r,s=(e.type==="create"&&n?3:4)/r;return g.jsxs("g",{className:fe("tl-handle",{"tl-handle__virtual":e.type==="virtual","tl-handle__create":e.type==="create"},t),children:[g.jsx("circle",{className:"tl-handle__bg",r:o}),g.jsx("circle",{className:"tl-handle__fg",r:s})]})},ej=({children:e})=>g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),tj=({shapeId:e})=>g.jsx(uu,{className:"tl-user-indicator__hovered",id:e});function hu(e,n=!0){const t=e.length;if(t<2)return"";let r=e[0],o=e[1];if(t===2)return`M${At(r)}L${At(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i],o=e[i+1],s+=yn(r,o);return n?`M${yn(e[0],e[1])}Q${At(e[1])}${yn(e[1],e[2])}T${s}${yn(e[t-1],e[0])}${yn(e[0],e[1])}Z`:`M${At(e[0])}Q${At(e[1])}${yn(e[1],e[2])}${e.length>3?"T":""}${s}L${At(e[t-1])}`}const Kx=({scribble:e,zoom:n,color:t,opacity:r,className:o})=>e.points.length?g.jsx("svg",{className:o&&fe("tl-overlays__item",o),children:g.jsx("path",{className:"tl-scribble",d:hu(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null,HE=({bounds:e,rotation:n})=>{const t=w.useRef(null);return Za(t,e.x,e.y,1,n),w.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=O(Math.max(1,e.width))+"px",r.style.height=O(Math.max(1,e.height))+"px")},[e.width,e.height]),g.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})},nj=({bounds:e,rotation:n})=>{const t=U(),r=w.useRef(null),o=G("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Za(r,e==null?void 0:e.x,e==null?void 0:e.y,1,n,{x:-s,y:-s}),e=e.clone().expandBy(s).zeroFix(),g.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:g.jsx("rect",{className:fe("tl-selection__fg__outline"),width:O(e.width),height:O(e.height)})})},rj=()=>g.jsx("div",{className:"tl-shape-error-boundary"}),oj=()=>g.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function sj({points:e,zoom:n}){const t=2.5/n,r=e.reduce((h,p)=>Math.min(h,p.x),1/0),o=e.reduce((h,p)=>Math.max(h,p.x),-1/0),s=e.reduce((h,p)=>Math.min(h,p.y),1/0),i=e.reduce((h,p)=>Math.max(h,p.y),-1/0),a=e.some(h=>h.x===r&&h.y===s);let l,c,u,d;return a?(l=r,c=s,u=o,d=i):(l=r,c=i,u=o,d=s),g.jsxs("g",{className:"tl-snap-line",children:[g.jsx("line",{x1:l,y1:c,x2:u,y2:d}),e.map((h,p)=>g.jsx("g",{transform:`translate(${h.x},${h.y})`,children:g.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},p))]})}function ij({gaps:e,direction:n,zoom:t}){const r=3.5/t;let o=[-1/0,1/0],s=null;const i=n==="horizontal";for(const l of e){if(s=wr(o[0],o[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),s)o=s;else continue;if(s=wr(o[0],o[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return g.jsx("g",{className:"tl-snap-line",children:e.map(({startEdge:l,endEdge:c},u)=>g.jsx(w.Fragment,{children:i?g.jsxs(g.Fragment,{children:[g.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),g.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),g.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),g.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):g.jsxs(g.Fragment,{children:[g.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),g.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),g.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),g.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},u))})}const aj=({className:e,line:n,zoom:t})=>g.jsx("svg",{className:fe("tl-overlays__item",e),children:n.type==="points"?g.jsx(sj,{...n,zoom:t}):n.type==="gaps"?g.jsx(ij,{...n,zoom:t}):null}),lj=()=>g.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:g.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[g.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"var(--color-text-1)"}),g.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"var(--color-text-1)",children:g.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})}),cj=()=>null,VE=w.createContext({});function uj({overrides:e,children:n}){return g.jsx(VE.Provider,{value:w.useMemo(()=>({Background:BD,SvgDefs:cj,Brush:Ju,ZoomBrush:Ju,ScreenshotBrush:Ju,CollaboratorBrush:Ju,Cursor:Vx,CollaboratorCursor:Vx,CollaboratorHint:GD,CollaboratorShapeIndicator:uu,Grid:QD,Scribble:Kx,SnapLine:aj,Handles:ej,Handle:JD,CollaboratorScribble:Kx,ErrorFallback:UE,ShapeErrorFallback:rj,ShapeIndicatorErrorFallback:oj,Spinner:lj,SelectionBackground:HE,SelectionForeground:nj,HoveredShapeIndicator:tj,OnTheCanvas:null,InFrontOfTheCanvas:null,...e}),[e]),children:n})}function Pt(){return w.useContext(VE)}const dj=["textarea","input"];function hj(e){const n=U();w.useEffect(()=>{const t=e.current;if(!t)return;const r=o=>{var s;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:i}=o;if(dj.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||n.isIn("select.editing_shape"))return;Ee(o)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[n,e])}function pj(e,n,t){return Math.max(n,Math.min(e,t))}const Rt={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 Wx(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function Gx(e,n,t,r=.15){return r===0?pj(e,n,t):e<n?-Wx(n-e,t-n,r)+n:e>t?+Wx(e-t,t-n,r)+t:e}function fj(e,[n,t],[r,o]){const[[s,i],[a,l]]=e;return[Gx(n,s,i,r),Gx(t,a,l,o)]}function gj(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 mj(e){var n=gj(e,"string");return typeof n=="symbol"?n:String(n)}function Ht(e,n,t){return n=mj(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function Yx(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 st(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?Yx(Object(t),!0).forEach(function(r){Ht(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):Yx(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const KE={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 Xx(e){return e?e[0].toUpperCase()+e.slice(1):""}const yj=["enter","leave"];function Sj(e=!1,n){return e&&!yj.includes(n)}function vj(e,n="",t=!1){const r=KE[e],o=r&&r[n]||n;return"on"+Xx(e)+Xx(o)+(Sj(t,o)?"Capture":"")}const wj=["gotpointercapture","lostpointercapture"];function xj(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=wj.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function bj(e,n=""){const t=KE[e],r=t&&t[n]||n;return e+r}function WE(e){return"touches"in e}function Pj(e){return WE(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function Cj(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 Ty(e,n){try{const t=n.clientX-e.clientX,r=n.clientY-e.clientY,o=(n.clientX+e.clientX)/2,s=(n.clientY+e.clientY)/2,i=Math.hypot(t,r);return{angle:-(Math.atan2(t,r)*180)/Math.PI,distance:i,origin:[o,s]}}catch{}return null}function Ej(e){return Cj(e).map(n=>n.identifier)}function qx(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return Ty(t,r)}const Zx=40,Qx=800;function GE(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=Zx,t*=Zx):r===2&&(n*=Qx,t*=Qx),[n,t]}function kj(e){const n={};if("buttons"in e&&(n.buttons=e.buttons),"shiftKey"in e){const{shiftKey:t,altKey:r,metaKey:o,ctrlKey:s}=e;Object.assign(n,{shiftKey:t,altKey:r,metaKey:o,ctrlKey:s})}return n}function lp(e,...n){return typeof e=="function"?e(...n):e}function Ij(){}function _j(...e){return e.length===0?Ij:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function Jx(e,n){return Object.assign({},n,e||{})}const Tj=32;class YE{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?lp(r.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=n.timeStamp)}computeValues(n){const t=this.state;t._values=n,t.values=this.config.transform(n)}computeInitial(){const n=this.state;n._initial=n._values,n.initial=n.values}compute(n){const{state:t,config:r,shared:o}=this;t.args=this.args;let s=0;if(n&&(t.event=n,r.preventDefault&&n.cancelable&&t.event.preventDefault(),t.type=n.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,kj(n)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=n.timeStamp-t.timeStamp,t.timeStamp=n.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const k=t._delta.map(Math.abs);Rt.addTo(t._distance,k)}this.axisIntent&&this.axisIntent(n);const[i,a]=t._movement,[l,c]=r.threshold,{_step:u,values:d}=t;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&d[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&d[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),t.intentional=u[0]!==!1||u[1]!==!1,!t.intentional)return;const h=[0,0];if(r.hasCustomTransform){const[k,I]=d;h[0]=u[0]!==!1?k-u[0]:0,h[1]=u[1]!==!1?I-u[1]:0}else h[0]=u[0]!==!1?i-u[0]:0,h[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(h);const p=t.offset,m=t._active&&!t._blocked||t.active;m&&(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=lp(r.bounds,t)),this.setup&&this.setup()),t.movement=h,this.computeOffset()));const[f,S]=t.offset,[[v,x],[b,P]]=t._bounds;t.overflow=[f<v?-1:f>x?1:0,S<b?-1:S>P?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 E=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=fj(t._bounds,t.offset,E),t.delta=Rt.sub(t.offset,p),this.computeMovement(),m&&(!t.last||s>Tj)){t.delta=Rt.sub(t.offset,p);const k=t.delta.map(Math.abs);Rt.addTo(t.distance,k),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&s>0&&(t.velocity=[k[0]/s,k[1]/s],t.timeDelta=s)}}emit(){const n=this.state,t=this.shared,r=this.config;if(n._active||this.clean(),(n._blocked||!n.intentional)&&!n._force&&!r.triggerAllEvents)return;const o=this.handler(st(st(st({},t),n),{},{[this.aliasKey]:n.values}));o!==void 0&&(n.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function $j([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 Aj extends YE{constructor(...n){super(...n),Ht(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=Rt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Rt.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[Pj(n)]:r.axisThreshold;t.axis=$j(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 Mj=e=>e,eb=.15,XE={enabled(e=!0){return e},eventOptions(e,n,t){return st(st({},t.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[eb,eb];case!1:return[0,0];default:return Rt.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return Rt.toVector(e)},transform(e,n,t){const r=e||t.shared.transform;return this.hasCustomTransform=!!r,r||Mj},threshold(e){return Rt.toVector(e,0)}},Oj=0,pu=st(st({},XE),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=Oj){return e},bounds(e={}){if(typeof e=="function")return s=>pu.bounds(e(s));if("current"in e)return()=>e.current;if(typeof HTMLElement=="function"&&e instanceof HTMLElement)return e;const{left:n=-1/0,right:t=1/0,top:r=-1/0,bottom:o=1/0}=e;return[[n,t],[r,o]]}}),fu=typeof window<"u"&&window.document&&window.document.createElement;function qE(){return fu&&"ontouchstart"in window}function Rj(){return qE()||fu&&window.navigator.maxTouchPoints>1}function Dj(){return fu&&"onpointerdown"in window}function jj(){return fu&&"exitPointerLock"in window.document}function Lj(){try{return"constructor"in GestureEvent}catch{return!1}}const sr={isBrowser:fu,gesture:Lj(),touch:qE(),touchscreen:Rj(),pointer:Dj(),pointerLock:jj()},Nj=250,Fj=180,zj=.5,Bj=50,Uj=250,Hj=10,tb={mouse:0,touch:0,pen:8};st(st({},pu),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&sr.pointerLock,sr.touch&&t?"touch":this.pointerLock?"mouse":sr.pointer&&!o?"pointer":sr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?Nj:void 0,!(!sr.touchscreen||t===!1))return e||(t!==void 0?"y":void 0)},pointerCapture(e,n,{pointer:{capture:t=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&t},threshold(e,n,{filterTaps:t=!1,tapsThreshold:r=3,axis:o=void 0}){const s=Rt.toVector(e,t?r:o?1:0);return this.filterTaps=t,this.tapsThreshold=r,s},swipe({velocity:e=zj,distance:n=Bj,duration:t=Uj}={}){return{velocity:this.transform(Rt.toVector(e)),distance:this.transform(Rt.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return Fj;case!1:return 0;default:return e}},axisThreshold(e){return e?st(st({},tb),e):tb},keyboardDisplacement(e=Hj){return e}});function ZE(e){const[n,t]=e.overflow,[r,o]=e._delta,[s,i]=e._direction;(n<0&&r>0&&s<0||n>0&&r<0&&s>0)&&(e._movement[0]=e._movementBound[0]),(t<0&&o>0&&i<0||t>0&&o<0&&i>0)&&(e._movement[1]=e._movementBound[1])}const Vj=30,Kj=100;class Wj extends YE{constructor(...n){super(...n),Ht(this,"ingKey","pinching"),Ht(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=Rt.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)*Vj-Math.abs(r);o<0?n.axis="angle":o>0&&(n.axis="scale")}}restrictToAxis(n){this.config.lockDirection&&(this.state.axis==="scale"?n[1]=0:this.state.axis==="angle"&&(n[0]=0))}cancel(){const n=this.state;n.canceled||setTimeout(()=>{n.canceled=!0,n._active=!1,this.compute(),this.emit()},0)}touchStart(n){this.ctrl.setEventIds(n);const t=this.state,r=this.ctrl.touchIds;if(t._active&&t._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(n),t._touchIds=Array.from(r).slice(0,2);const o=qx(n,t._touchIds);o&&this.pinchStart(n,o)}pointerStart(n){if(n.buttons!=null&&n.buttons%2!==1)return;this.ctrl.setEventIds(n),n.target.setPointerCapture(n.pointerId);const t=this.state,r=t._pointerEvents,o=this.ctrl.pointerIds;if(t._active&&Array.from(r.keys()).every(i=>o.has(i))||(r.size<2&&r.set(n.pointerId,n),t._pointerEvents.size<2))return;this.start(n);const s=Ty(...Array.from(r.values()));s&&this.pinchStart(n,s)}pinchStart(n,t){const r=this.state;r.origin=t.origin,this.computeValues([t.distance,t.angle]),this.computeInitial(),this.compute(n),this.emit()}touchMove(n){if(!this.state._active)return;const t=qx(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=Ty(...Array.from(t.values()));r&&this.pinchMove(n,r)}pinchMove(n,t){const r=this.state,o=r._values[1],s=t.angle-o;let i=0;Math.abs(s)>270&&(i+=Math.sign(s)),this.computeValues([t.distance,t.angle-360*i]),r.origin=t.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(n),this.emit()}touchEnd(n){this.ctrl.setEventIds(n),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(n),this.emit())}pointerEnd(n){const t=this.state;this.ctrl.setEventIds(n);try{n.target.releasePointerCapture(n.pointerId)}catch{}t._pointerEvents.has(n.pointerId)&&t._pointerEvents.delete(n.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(n),this.emit())}gestureStart(n){n.cancelable&&n.preventDefault();const t=this.state;t._active||(this.start(n),this.computeValues([n.scale,n.rotation]),t.origin=[n.clientX,n.clientY],this.compute(n),this.emit())}gestureMove(n){if(n.cancelable&&n.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([n.scale,n.rotation]),t.origin=[n.clientX,n.clientY];const r=t._movement;t._movement=[n.scale-1,n.rotation],t._delta=Rt.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=[-GE(n)[1]/Kj*r.offset[0],0],Rt.addTo(r._movement,r._delta),ZE(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 Gj=st(st({},XE),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!sr.touch&&sr.gesture)return"gesture";if(sr.touch&&r)return"touch";if(sr.touchscreen){if(sr.pointer)return"pointer";if(sr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=i=>{const a=Jx(lp(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=Jx(lp(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[o(),s()]:i=>[o(i),s(i)]},threshold(e,n,t){return this.lockDirection=t.axis==="lock",Rt.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});st(st({},pu),{},{mouseOnly:(e=!0)=>e});class Yj extends Aj{constructor(...n){super(...n),Ht(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=GE(n),Rt.addTo(t._movement,t._delta),ZE(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 Xj=pu;st(st({},pu),{},{mouseOnly:(e=!0)=>e});const Rv=new Map,$y=new Map;function qj(e){Rv.set(e.key,e.engine),$y.set(e.key,e.resolver)}const Zj={key:"pinch",engine:Wj,resolver:Gj},Qj={key:"wheel",engine:Yj,resolver:Xj};function Jj(e,n){if(e==null)return{};var t={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(n.indexOf(o)>=0)&&(t[o]=e[o]);return t}function eL(e,n){if(e==null)return{};var t=Jj(e,n),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r])}return t}const tL={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=sr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},nL=["target","eventOptions","window","enabled","transform"];function Zd(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]=Zd(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function rL(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=eL(r,nL);if(t.shared=Zd({target:o,eventOptions:s,window:i,enabled:a,transform:l},tL),n){const u=$y.get(n);t[n]=Zd(st({shared:t.shared},c),u)}else for(const u in c){const d=$y.get(u);d&&(t[u]=Zd(st({shared:t.shared},c[u]),d))}return t}class QE{constructor(n,t){Ht(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,s){const i=this._listeners,a=bj(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=st(st({},l),s);n.addEventListener(a,o,c);const u=()=>{n.removeEventListener(a,o,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class oL{constructor(){Ht(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 sL{constructor(n){Ht(this,"gestures",new Set),Ht(this,"_targetEventStore",new QE(this)),Ht(this,"gestureEventStores",{}),Ht(this,"gestureTimeoutStores",{}),Ht(this,"handlers",{}),Ht(this,"config",{}),Ht(this,"pointerIds",new Set),Ht(this,"touchIds",new Set),Ht(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),iL(this,n)}setEventIds(n){if(WE(n))return this.touchIds=new Set(Ej(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=rL(n,t,this.config)}clean(){this._targetEventStore.clean();for(const n of this.gestures)this.gestureEventStores[n].clean(),this.gestureTimeoutStores[n].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...n){const t=this.config.shared,r={};let o;if(!(t.target&&(o=t.target(),!o))){if(t.enabled){for(const i of this.gestures){const a=this.config[i],l=nb(r,a.eventOptions,!!o);if(a.enabled){const c=Rv.get(i);new c(this,n,i).bind(l)}}const s=nb(r,t.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](st(st({},this.state.shared),{},{event:a,args:n})),void 0,!0)}for(const s in r)r[s]=_j(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=xj(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function Fi(e,n){e.gestures.add(n),e.gestureEventStores[n]=new QE(e,n),e.gestureTimeoutStores[n]=new oL}function iL(e,n){n.drag&&Fi(e,"drag"),n.wheel&&Fi(e,"wheel"),n.scroll&&Fi(e,"scroll"),n.move&&Fi(e,"move"),n.pinch&&Fi(e,"pinch"),n.hover&&Fi(e,"hover")}const nb=(e,n,t)=>(r,o,s,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:n.capture,d=(c=i.passive)!==null&&c!==void 0?c:n.passive;let h=a?r:vj(r,o,u);t&&d&&(h+="Passive"),e[h]=e[h]||[],e[h].push(s)},aL=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function lL(e){const n={},t={},r=new Set;for(let o in e)aL.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function zi(e,n,t,r,o,s){if(!e.has(t)||!Rv.has(r))return;const i=t+"Start",a=t+"End",l=c=>{let u;return c.first&&i in n&&n[i](c),t in n&&(u=n[t](c)),c.last&&a in n&&n[a](c),u};o[r]=l,s[r]=s[r]||{}}function cL(e,n){const[t,r,o]=lL(e),s={};return zi(o,t,"onDrag","drag",s,n),zi(o,t,"onWheel","wheel",s,n),zi(o,t,"onScroll","scroll",s,n),zi(o,t,"onPinch","pinch",s,n),zi(o,t,"onMove","move",s,n),zi(o,t,"onHover","hover",s,n),{handlers:s,config:n,nativeHandlers:r}}function uL(e,n={},t,r){const o=ne.useMemo(()=>new sL(e),[]);if(o.applyHandlers(e,r),o.applyConfig(n,t),ne.useEffect(o.effect.bind(o)),ne.useEffect(()=>o.clean.bind(o),[]),n.target===void 0)return o.bind.bind(o)}function dL(e){return e.forEach(qj),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=cL(t,r||{});return uL(o,i,void 0,s)}}const rb=10,hL=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function JE(e){let{deltaY:n,deltaX:t}=e,r=0;if(e.ctrlKey||e.altKey||e.metaKey){const o=Math.sign(e.deltaY),s=Math.abs(e.deltaY);let i=n;s>rb&&(i=rb*o),r=i/100}else e.shiftKey&&!hL&&(t=n,n=0);return{x:-t,y:-n,z:-r}}const pL=dL([Qj,Zj]);let Bi;const fL=e=>Bi===void 0?(Bi=e,!1):e-Bi>120&&e-Bi<160?(Bi=e,!0):(Bi=e,!1);function gL(e){const n=U(),t=w.useMemo(()=>{let r="not sure";const o=({event:f})=>{if(!n.getInstanceState().isFocused||(r="not sure",fL(Date.now())))return;const S=n.getEditingShapeId();if(S){const b=n.getShape(S);if(b&&n.getShapeUtil(b).canScroll(b)){const E=n.getShapePageBounds(S);if(E!=null&&E.containsPoint(n.inputs.currentPagePoint))return}}Ee(f);const v=JE(f);if(v.x===0&&v.y===0)return;const x={type:"wheel",name:"wheel",delta:v,point:new C(f.clientX,f.clientY),shiftKey:f.shiftKey,altKey:f.altKey,ctrlKey:f.metaKey||f.ctrlKey};n.dispatch(x)};let s=1,i=1,a=1,l=0;const c=new C,u=new C,d=f=>{const S=e.current;r="not sure";const{event:v,origin:x,da:b}=f;v instanceof WheelEvent||(v.target===S||S!=null&&S.contains(v.target))&&(u.x=x[0],u.y=x[1],c.x=x[0],c.y=x[1],s=b[0],i=n.getZoomLevel(),n.dispatch({type:"pinch",name:"pinch_start",point:{x:x[0],y:x[1],z:n.getZoomLevel()},delta:{x:0,y:0},shiftKey:v.shiftKey,altKey:v.altKey,ctrlKey:v.metaKey||v.ctrlKey}))},h=f=>{if(f&&(r="zooming"),r==="zooming")return;const S=Math.abs(l-s),v=C.Dist(c,u);switch(r){case"not sure":{S>24?r="zooming":v>16&&(r="panning");break}case"panning":{S>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:d,onPinchEnd:f=>{const S=e.current,{event:v,origin:x,offset:b}=f;if(v instanceof WheelEvent||!(v.target===S||S!=null&&S.contains(v.target)))return;const P=b[0];r="not sure",requestAnimationFrame(()=>{n.dispatch({type:"pinch",name:"pinch_end",point:{x:x[0],y:x[1],z:P},delta:{x:x[0],y:x[1]},shiftKey:v.shiftKey,altKey:v.altKey,ctrlKey:v.metaKey||v.ctrlKey})})},onPinch:f=>{const S=e.current,{event:v,origin:x,offset:b,da:P}=f;if(v instanceof WheelEvent||!(v.target===S||S!=null&&S.contains(v.target)))return;const E=f.type==="gesturechange"||f.type==="gestureend";l=P[0];const k=x[0]-u.x,I=x[1]-u.y;switch(u.x=x[0],u.y=x[1],h(E),r){case"zooming":{a=b[0],n.dispatch({type:"pinch",name:"pinch",point:{x:x[0],y:x[1],z:a},delta:{x:k,y:I},shiftKey:v.shiftKey,altKey:v.altKey,ctrlKey:v.metaKey||v.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:x[0],y:x[1],z:i},delta:{x:k,y:I},shiftKey:v.shiftKey,altKey:v.altKey,ctrlKey:v.metaKey||v.ctrlKey});break}}}}},[n,e]);pL(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function yg(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function mL(e,n){const t=U();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=sp(l.currentTarget);lu(c,l);const{shape:u,handle:d}=yg(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_down",...vn(l)})};let o,s;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===o&&l.clientY===s)return;o=l.clientX,s=l.clientY;const{shape:c,handle:u}=yg(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...vn(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=sp(l.currentTarget);cu(c,l);const{shape:u,handle:d}=yg(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_up",...vn(l)})}}},[t,e,n])}var ek="Expected a function",ob=NaN,yL="[object Symbol]",SL=/^\s+|\s+$/g,vL=/^[-+]0x[0-9a-f]+$/i,wL=/^0b[01]+$/i,xL=/^0o[0-7]+$/i,bL=parseInt,PL=typeof Xt=="object"&&Xt&&Xt.Object===Object&&Xt,CL=typeof self=="object"&&self&&self.Object===Object&&self,EL=PL||CL||Function("return this")(),kL=Object.prototype,IL=kL.toString,_L=Math.max,TL=Math.min,Sg=function(){return EL.Date.now()};function $L(e,n,t){var r,o,s,i,a,l,c=0,u=!1,d=!1,h=!0;if(typeof e!="function")throw new TypeError(ek);n=sb(n)||0,cp(t)&&(u=!!t.leading,d="maxWait"in t,s=d?_L(sb(t.maxWait)||0,n):s,h="trailing"in t?!!t.trailing:h);function p(k){var I=r,_=o;return r=o=void 0,c=k,i=e.apply(_,I),i}function m(k){return c=k,a=setTimeout(v,n),u?p(k):i}function f(k){var I=k-l,_=k-c,A=n-I;return d?TL(A,s-_):A}function S(k){var I=k-l,_=k-c;return l===void 0||I>=n||I<0||d&&_>=s}function v(){var k=Sg();if(S(k))return x(k);a=setTimeout(v,f(k))}function x(k){return a=void 0,h&&r?p(k):(r=o=void 0,i)}function b(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function P(){return a===void 0?i:x(Sg())}function E(){var k=Sg(),I=S(k);if(r=arguments,o=this,l=k,I){if(a===void 0)return m(l);if(d)return a=setTimeout(v,n),p(l)}return a===void 0&&(a=setTimeout(v,n)),i}return E.cancel=b,E.flush=P,E}function AL(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(ek);return cp(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),$L(e,n,{leading:r,maxWait:n,trailing:o})}function cp(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function ML(e){return!!e&&typeof e=="object"}function OL(e){return typeof e=="symbol"||ML(e)&&IL.call(e)==yL}function sb(e){if(typeof e=="number")return e;if(OL(e))return ob;if(cp(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=cp(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(SL,"");var t=wL.test(e);return t||xL.test(e)?bL(e.slice(2),t?2:8):vL.test(e)?ob:+e}var RL=AL;const DL=Ka(RL);function jL(){const e=U();w.useLayoutEffect(()=>{const n=DL(()=>{e.updateViewportScreenBounds()},200,{trailing:!0});e.updateViewportScreenBounds();const t=setInterval(n,1e3);return window.addEventListener("resize",n),window.addEventListener("scroll",n),()=>{clearInterval(t),window.removeEventListener("resize",n),window.removeEventListener("scroll",n)}},[e])}const Qe=class Qe{constructor(n=0,t=0,r=0,o=0){y(this,"x",0);y(this,"y",0);y(this,"w",0);y(this,"h",0);this.x=n,this.y=t,this.w=r,this.h=o}get point(){return new C(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 C(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 C(this.minX,this.minY),new C(this.maxX,this.minY),new C(this.maxX,this.maxY),new C(this.minX,this.maxY)]}get snapPoints(){return[new C(this.minX,this.minY),new C(this.maxX,this.minY),new C(this.maxX,this.maxY),new C(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 C(this.w,this.h)}toFixed(){return this.x=Qu(this.x),this.y=Qu(this.y),this.w=Qu(this.w),this.h=Qu(this.h),this}setTo(n){return this.x=n.x,this.y=n.y,this.w=n.w,this.h=n.h,this}set(n=0,t=0,r=0,o=0){return this.x=n,this.y=t,this.w=r,this.h=o,this}expand(n){const t=Math.min(this.minX,n.minX),r=Math.min(this.minY,n.minY),o=Math.max(this.maxX,n.maxX),s=Math.max(this.maxY,n.maxY);return this.x=t,this.y=r,this.w=o-t,this.h=s-r,this}expandBy(n){return this.x-=n,this.y-=n,this.w+=n*2,this.h+=n*2,this}scale(n){return this.x/=n,this.y/=n,this.w/=n,this.h/=n,this}clone(){const{x:n,y:t,w:r,h:o}=this;return new Qe(n,t,r,o)}translate(n){return this.x+=n.x,this.y+=n.y,this}snapToGrid(n){const t=Math.round(this.minX/n)*n,r=Math.round(this.minY/n)*n,o=Math.round(this.maxX/n)*n,s=Math.round(this.maxY/n)*n;this.minX=t,this.minY=r,this.width=Math.max(1,o-t),this.height=Math.max(1,s-r)}collides(n){return Qe.Collides(this,n)}contains(n){return Qe.Contains(this,n)}includes(n){return Qe.Includes(this,n)}containsPoint(n,t=0){return Qe.ContainsPoint(this,n,t)}getHandlePoint(n){switch(n){case"top_left":return new C(this.minX,this.minY);case"top_right":return new C(this.maxX,this.minY);case"bottom_left":return new C(this.minX,this.maxY);case"bottom_right":return new C(this.maxX,this.maxY);case"top":return new C(this.midX,this.minY);case"right":return new C(this.maxX,this.midY);case"bottom":return new C(this.midX,this.maxY);case"left":return new C(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(n,t,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:d}=this;switch(n){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{u+=t;break}}switch(n){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{d+=r;break}}const h=(u-l)/(i-o),p=(d-c)/(a-s),m=h<0,f=p<0;if(m){const S=u;u=l,l=S}if(f){const S=d;d=c,c=S}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(d-c)}union(n){const t=Math.min(this.minX,n.x),r=Math.min(this.minY,n.y),o=Math.max(this.maxX,n.w+n.x),s=Math.max(this.maxY,n.h+n.y);return this.x=t,this.y=r,this.width=o-t,this.height=s-r,this}static From(n){return new Qe(n.x,n.y,n.w,n.h)}static FromCenter(n,t){return new Qe(n.x-t.x/2,n.y-t.y/2,t.x,t.y)}static FromPoints(n){if(n.length===0)return new Qe;let t=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,l=n.length;a<l;a++)i=n[a],t=Math.min(i.x,t),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new Qe(t,r,o-t,s-r)}static Expand(n,t){const r=Math.min(t.minX,n.minX),o=Math.min(t.minY,n.minY),s=Math.max(t.maxX,n.maxX),i=Math.max(t.maxY,n.maxY);return new Qe(r,o,s-r,i-o)}static ExpandBy(n,t){return new Qe(n.minX-t,n.minY-t,n.width+t*2,n.height+t*2)}static Resize(n,t,r,o,s=!1){const{minX:i,minY:a,maxX:l,maxY:c}=n;let{minX:u,minY:d,maxX:h,maxY:p}=n;switch(t){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{h+=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 m=(h-u)/(l-i),f=(p-d)/(c-a),S=m<0,v=f<0;if(s){const b=(l-i)/(c-a),P=Math.abs(h-u),E=Math.abs(p-d),k=P*(f<0?1:-1)*(1/b),I=E*(m<0?1:-1)*b,_=b<P/E;switch(t){case"top_left":{_?d=p+k:u=h+I;break}case"top_right":{_?d=p+k:h=u-I;break}case"bottom_right":{_?p=d-k:h=u-I;break}case"bottom_left":{_?p=d-k:u=h+I;break}case"bottom":case"top":{const A=(u+h)/2,T=E*b;u=A-T/2,h=A+T/2;break}case"left":case"right":{const A=(d+p)/2,T=P/b;d=A-T/2,p=A+T/2;break}}}if(S){const b=h;h=u,u=b}if(v){const b=p;p=d,d=b}const x=new Qe(u,d,Math.abs(h-u),Math.abs(p-d));return{box:x,scaleX:+(x.width/n.width*(m>0?1:-1)).toFixed(5),scaleY:+(x.height/n.height*(f>0?1:-1)).toFixed(5)}}equals(n){return Qe.Equals(this,n)}static Equals(n,t){return t.x===n.x&&t.y===n.y&&t.w===n.w&&t.h===n.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(n){return new Qe(n.x,n.y,Math.max(1,n.w),Math.max(1,n.h))}};y(Qe,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),y(Qe,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),y(Qe,"Includes",(n,t)=>Qe.Collides(n,t)||Qe.Contains(n,t)),y(Qe,"ContainsPoint",(n,t,r=0)=>!(t.x<n.minX-r||t.y<n.minY-r||t.x>n.maxX+r||t.y>n.maxY+r)),y(Qe,"Common",n=>{let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<n.length;i++){const a=n[i];t=Math.min(t,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new Qe(t,r,o-t,s-r)}),y(Qe,"Sides",(n,t=0)=>{const{corners:r}=n;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let re=Qe;function LL(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 NL(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 FL(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}const _e=class _e{constructor(n,t,r,o,s,i){y(this,"a",1);y(this,"b",0);y(this,"c",0);y(this,"d",1);y(this,"e",0);y(this,"f",0);this.a=n,this.b=t,this.c=r,this.d=o,this.e=s,this.f=i}equals(n){return this.a===n.a&&this.b===n.b&&this.c===n.c&&this.d===n.d&&this.e===n.e&&this.f===n.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(n){const t=n,{a:r,b:o,c:s,d:i,e:a,f:l}=this;return this.a=r*t.a+s*t.b,this.c=r*t.c+s*t.d,this.e=r*t.e+s*t.f+a,this.b=o*t.a+i*t.b,this.d=o*t.c+i*t.d,this.f=o*t.e+i*t.f+l,this}rotate(n,t,r){return n===0?this:t===void 0?this.multiply(_e.Rotate(n)):this.translate(t,r).multiply(_e.Rotate(n)).translate(-t,-r)}translate(n,t){return this.multiply(_e.Translate(n,t))}scale(n,t){return this.multiply(_e.Scale(n,t))}invert(){const{a:n,b:t,c:r,d:o,e:s,f:i}=this,a=n*o-t*r;return this.a=o/a,this.b=t/-a,this.c=r/-a,this.d=n/a,this.e=(o*s-r*i)/-a,this.f=(t*s-n*i)/a,this}applyToPoint(n){return _e.applyToPoint(this,n)}applyToPoints(n){return _e.applyToPoints(this,n)}rotation(){return _e.Rotation(this)}point(){return _e.Point(this)}decomposed(){return _e.Decompose(this)}toCssString(){return _e.toCssString(this)}setTo(n){return Object.assign(this,n),this}decompose(){return _e.Decompose(this)}clone(){return new _e(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new _e(1,0,0,1,0,0)}static Translate(n,t){return new _e(1,0,0,1,n,t)}static Rotate(n,t,r){if(n===0)return _e.Identity();const o=Math.cos(n),s=Math.sin(n),i=new _e(o,s,-s,o,0,0);return t===void 0?i:_e.Compose(_e.Translate(t,r),i,_e.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=_e.Identity();for(let r=0,o=n.length;r<o;r++)t.multiply(n[r]);return t}static Point(n){return new C(n.e,n.f)}static Rotation(n){let t;if(n.a!==0||n.c!==0){const r=Math.hypot(n.a,n.c);t=Math.acos(n.a/r)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const r=Math.hypot(n.b,n.d);t=Ve+Math.acos(n.b/r)*(n.d>0?-1:1)}else t=0;return Iy(t)}static Decompose(n){let t,r,o;if(n.a!==0||n.c!==0){const s=Math.hypot(n.a,n.c);t=s,r=(n.a*n.d-n.b*n.c)/s,o=Math.acos(n.a/s)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const s=Math.hypot(n.b,n.d);t=(n.a*n.d-n.b*n.c)/s,r=s,o=Ve+Math.acos(n.b/s)*(n.d>0?-1:1)}else t=0,r=0,o=0;return{x:n.e,y:n.f,scaleX:t,scaleY:r,rotation:Iy(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(${O(n.a)}, ${O(n.b)}, ${O(n.c)}, ${O(n.d)}, ${O(n.e)}, ${O(n.f)})`}static applyToPoint(n,t){return new C(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 C(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 re(n.e+t.minX,n.f+t.minY,t.width,t.height)}static From(n){return new _e(n.a,n.b,n.c,n.d,n.e,n.f)}static Cast(n){return n instanceof _e?n:_e.From(n)}};y(_e,"Scale",(n,t,r,o)=>{const s=new _e(n,0,0,t,0,0);return r===void 0?s:_e.Compose(_e.Translate(r,o),s,_e.Translate(-r,-o))});let te=_e;class bi{constructor(n){y(this,"isFilled",!1);y(this,"isClosed",!0);y(this,"isLabel",!1);y(this,"isSnappable",!0);y(this,"debugColor");y(this,"ignore");y(this,"_vertices");y(this,"_bounds");y(this,"_snapPoints");y(this,"_area");this.isFilled=n.isFilled,this.isClosed=n.isClosed,this.isSnappable=n.isSnappable??!1,this.isLabel=n.isLabel??!1,this.debugColor=n.debugColor,this.ignore=n.ignore}hitTestPoint(n,t=0,r=!1){return this.distanceToPoint(n,r)<=t}distanceToPoint(n,t=!1){const r=n.dist(this.nearestPoint(n));return this.isClosed&&(this.isFilled||t)&&Rr(n,this.vertices)?-r:r}distanceToLineSegment(n,t){const r=this.nearestPointOnLineSegment(n,t),o=C.DistanceToLineSegment(n,t,r);return this.isClosed&&this.isFilled&&Rr(r,this.vertices)?-o:o}hitTestLineSegment(n,t,r=0){return this.distanceToLineSegment(n,t)<=r}nearestPointOnLineSegment(n,t){let r=1/0,o;for(let s=0;s<this.vertices.length;s++){const i=this.vertices[s],a=C.DistanceToLineSegment(n,t,i);a<r&&(r=a,o=i)}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 re.FromPoints(this.vertices)}get bounds(){return this._bounds||(this._bounds=this.getBounds()),this._bounds}get snapPoints(){return this._snapPoints||(this._snapPoints=this.bounds.snapPoints),this._snapPoints}get center(){return this.bounds.center}get area(){return this._area||(this._area=this.getArea()),this._area}getArea(){if(!this.isClosed)return 0;const{vertices:n}=this;let t=0;for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];t+=s.x*i.y-i.x*s.y}return t/2}toSimpleSvgPath(){let n="";const{vertices:t}=this,r=t.length;if(r===0)return n;n+=`M${t[0].x},${t[0].y}`;for(let o=1;o<r;o++)n+=`L${t[o].x},${t[o].y}`;return this.isClosed&&(n+="Z"),n}}class Po extends bi{constructor(t){super({...t,isClosed:!0,isFilled:!1});y(this,"children",[]);y(this,"ignoredChildren",[]);for(const r of t.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(t=>!t.isLabel).flatMap(t=>t.vertices)}nearestPoint(t){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");for(const i of s){const a=i.nearestPoint(t),l=a.dist(t);l<r&&(r=l,o=a)}if(!o)throw Error("nearest point not found");return o}distanceToPoint(t,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(t,r||s>0)))}hitTestPoint(t,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(t,r,o))}hitTestLineSegment(t,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(t,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let t="";for(const o of this.children)t+=o.toSimpleSvgPath();const r=re.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],l=i.dist(a),c=r[(o+1)%s],u=i.dist(c),d=i.clone().lrp(a,4/l),h=i,p=i.clone().lrp(c,4/u);t+=`M${d.x},${d.y} L${h.x},${h.y} L${p.x},${p.y} `}return t}}function zL(e=!0){const[n,t]=w.useState(0),r=U();w.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const BL=je(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=U();zL(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return g.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=o.getShape(l.id);if(c.type==="group")return null;const u=o.getShapeGeometry(c),d=o.getShapePageTransform(c),h=o.getPointInShapeSpace(c,a),p=u.nearestPoint(h),m=u.distanceToPoint(h,!0),f=Math.abs(m)*s,S=m<0,{vertices:v}=u;return g.jsxs("g",{transform:d.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&g.jsx(tk,{geometry:u}),t&&v.map((x,b)=>g.jsx("circle",{cx:x.x,cy:x.y,r:"2",fill:`hsl(${Gh(b,[0,v.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:"1"},`v${b}`)),r&&f<150&&g.jsx("line",{x1:p.x,y1:p.y,x2:h.x,y2:h.y,opacity:1-f/150,stroke:S?"goldenrod":"dodgerblue",strokeWidth:"2"})]},l.id+"_outline")})})});function tk({geometry:e}){return e instanceof Po?g.jsx(g.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>g.jsx(tk,{geometry:n},t))}):g.jsx("path",{stroke:e.debugColor??"red",strokeWidth:"2",fill:"none",opacity:"1",d:e.toSimpleSvgPath()})}var UL=200,Dv="__lodash_hash_undefined__",HL=1/0,VL="[object Function]",KL="[object GeneratorFunction]",WL=/[\\^$.*+?()[\]{}|]/g,GL=/^\[object .+?Constructor\]$/,YL=typeof Xt=="object"&&Xt&&Xt.Object===Object&&Xt,XL=typeof self=="object"&&self&&self.Object===Object&&self,jv=YL||XL||Function("return this")();function qL(e,n){var t=e?e.length:0;return!!t&&JL(e,n,0)>-1}function ZL(e,n,t){for(var r=-1,o=e?e.length:0;++r<o;)if(t(n,e[r]))return!0;return!1}function QL(e,n,t,r){for(var o=e.length,s=t+(r?1:-1);r?s--:++s<o;)if(n(e[s],s,e))return s;return-1}function JL(e,n,t){if(n!==n)return QL(e,e5,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function e5(e){return e!==e}function t5(e,n){return e.has(n)}function n5(e,n){return e==null?void 0:e[n]}function r5(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function nk(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var o5=Array.prototype,s5=Function.prototype,rk=Object.prototype,vg=jv["__core-js_shared__"],ib=function(){var e=/[^.]+$/.exec(vg&&vg.keys&&vg.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ok=s5.toString,Lv=rk.hasOwnProperty,i5=rk.toString,a5=RegExp("^"+ok.call(Lv).replace(WL,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),l5=o5.splice,c5=Nv(jv,"Map"),wg=Nv(jv,"Set"),Cc=Nv(Object,"create");function hi(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 u5(){this.__data__=Cc?Cc(null):{}}function d5(e){return this.has(e)&&delete this.__data__[e]}function h5(e){var n=this.__data__;if(Cc){var t=n[e];return t===Dv?void 0:t}return Lv.call(n,e)?n[e]:void 0}function p5(e){var n=this.__data__;return Cc?n[e]!==void 0:Lv.call(n,e)}function f5(e,n){var t=this.__data__;return t[e]=Cc&&n===void 0?Dv:n,this}hi.prototype.clear=u5;hi.prototype.delete=d5;hi.prototype.get=h5;hi.prototype.has=p5;hi.prototype.set=f5;function Qa(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 g5(){this.__data__=[]}function m5(e){var n=this.__data__,t=rf(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():l5.call(n,t,1),!0}function y5(e){var n=this.__data__,t=rf(n,e);return t<0?void 0:n[t][1]}function S5(e){return rf(this.__data__,e)>-1}function v5(e,n){var t=this.__data__,r=rf(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}Qa.prototype.clear=g5;Qa.prototype.delete=m5;Qa.prototype.get=y5;Qa.prototype.has=S5;Qa.prototype.set=v5;function Ja(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 w5(){this.__data__={hash:new hi,map:new(c5||Qa),string:new hi}}function x5(e){return of(this,e).delete(e)}function b5(e){return of(this,e).get(e)}function P5(e){return of(this,e).has(e)}function C5(e,n){return of(this,e).set(e,n),this}Ja.prototype.clear=w5;Ja.prototype.delete=x5;Ja.prototype.get=b5;Ja.prototype.has=P5;Ja.prototype.set=C5;function up(e){var n=-1,t=e?e.length:0;for(this.__data__=new Ja;++n<t;)this.add(e[n])}function E5(e){return this.__data__.set(e,Dv),this}function k5(e){return this.__data__.has(e)}up.prototype.add=up.prototype.push=E5;up.prototype.has=k5;function rf(e,n){for(var t=e.length;t--;)if(R5(e[t][0],n))return t;return-1}function I5(e){if(!sk(e)||A5(e))return!1;var n=D5(e)||r5(e)?a5:GL;return n.test(M5(e))}function _5(e,n,t){var r=-1,o=qL,s=e.length,i=!0,a=[],l=a;if(t)i=!1,o=ZL;else if(s>=UL){var c=n?null:T5(e);if(c)return nk(c);i=!1,o=t5,l=new up}else l=n?[]:a;e:for(;++r<s;){var u=e[r],d=n?n(u):u;if(u=t||u!==0?u:0,i&&d===d){for(var h=l.length;h--;)if(l[h]===d)continue e;n&&l.push(d),a.push(u)}else o(l,d,t)||(l!==a&&l.push(d),a.push(u))}return a}var T5=wg&&1/nk(new wg([,-0]))[1]==HL?function(e){return new wg(e)}:j5;function of(e,n){var t=e.__data__;return $5(n)?t[typeof n=="string"?"string":"hash"]:t.map}function Nv(e,n){var t=n5(e,n);return I5(t)?t:void 0}function $5(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function A5(e){return!!ib&&ib in e}function M5(e){if(e!=null){try{return ok.call(e)}catch{}try{return e+""}catch{}}return""}function O5(e){return e&&e.length?_5(e):[]}function R5(e,n){return e===n||e!==e&&n!==n}function D5(e){var n=sk(e)?i5.call(e):"";return n==VL||n==KL}function sk(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function j5(){}var L5=O5;const N5=Ka(L5);function ik(e){return N5(e)}function F5(){const e=U(),n=w.useMemo(()=>e.store.query.records("instance_presence",()=>({userId:{neq:e.user.getId()}})),[e]),t=fE("userIds",()=>ik(n.get().map(r=>r.userId)).sort(),{isEqual:(r,o)=>{var s;return r.join(",")===((s=o.join)==null?void 0:s.call(o,","))}},[n]);return G(t)}function ak(e){const n=U(),t=w.useMemo(()=>n.store.query.records("instance_presence",()=>({userId:{eq:e}})),[n,e]);return G(`latestPresence:${e}`,()=>t.get().slice().sort((o,s)=>s.lastActivityTimestamp-o.lastActivityTimestamp)[0],[])??null}const z5=je(function(){const n=F5();return g.jsx(g.Fragment,{children:n.map(t=>g.jsx(B5,{collaboratorId:t},t))})}),B5=je(function({collaboratorId:n}){const t=U(),r=ak(n),o=H5(r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:s,highlightedUserIds:i}=t.getInstanceState();if(!(s===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return g.jsx(U5,{latestPresence:r})}),U5=je(function({latestPresence:n}){const t=U(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=Pt(),l=t.getZoomLevel(),c=t.getViewportPageBounds(),{userId:u,chatMessage:d,brush:h,scribbles:p,selectedShapeIds:m,userName:f,cursor:S,color:v}=n,x=!(S.x<c.minX-12/l||S.y<c.minY-16/l||S.x>c.maxX-12/l||S.y>c.maxY-16/l);return g.jsxs(g.Fragment,{children:[h&&r?g.jsx(r,{className:"tl-collaborator__brush",brush:h,color:v,opacity:.1},u+"_brush"):null,x&&s?g.jsx(s,{className:"tl-collaborator__cursor",point:S,color:v,zoom:l,name:f!=="New User"?f:null,chatMessage:d},u+"_cursor"):i?g.jsx(i,{className:"tl-collaborator__cursor-hint",point:S,color:v,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&p.length?g.jsx(g.Fragment,{children:p.map(b=>g.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:v,zoom:l,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&m.map(b=>g.jsx(a,{className:"tl-collaborator__shape-indicator",id:b,color:v,opacity:.5},u+"_"+b))]})});function ab(e){return e>wD?"inactive":e>RE?"idle":"active"}function H5(e){const n=w.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[t,r]=w.useState(()=>ab(Date.now()-n.current));return w.useEffect(()=>{const o=setInterval(()=>{r(ab(Date.now()-n.current))},xD);return()=>clearInterval(o)},[]),e&&(n.current=e.lastActivityTimestamp),t}function lk(e,n){return n===0?e:lk(n,e%n)}function V5(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/lk(r,t)}const ck=je(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,isCulled:a}){const l=U(),{ShapeErrorFallback:c}=Pt(),u=w.useRef(null),d=w.useRef(null),h=w.useCallback((m,f)=>{var S,v;(S=u.current)==null||S.style.setProperty(m,f),(v=d.current)==null||v.style.setProperty(m,f)},[]);ii("set shape container transform position",()=>{if(!l.getShape(n))return;const f=l.getShapePageTransform(n),S=te.toCssString(f);h("transform",S)},[l,h]),ii("set shape container clip path",()=>{if(!l.getShape(n))return null;const f=l.getShapeClipPath(n);h("clip-path",f??"none")},[l,h]),ii("set shape height and width",()=>{const m=l.getShape(n);if(!m)return null;const f=l.getShapeGeometry(m).bounds,S=Math.floor(l.getInstanceState().devicePixelRatio*100)/100,v=V5(S),x=f.w%v,b=x===0?f.w:f.w+(v-x),P=f.h%v,E=P===0?f.h:f.h+(v-P);h("width",Math.max(b,v)+"px"),h("height",Math.max(E,v)+"px")},[l]),w.useLayoutEffect(()=>{var m,f;h("opacity",i+""),(m=u.current)==null||m.style.setProperty("z-index",o+""),(f=d.current)==null||f.style.setProperty("z-index",s+"")},[i,o,s,h]);const p=w.useCallback(m=>{l.annotateError(m,{origin:"react.shape",willCrashApp:!1})},[l]);return t?g.jsxs(g.Fragment,{children:[r.backgroundComponent&&g.jsx("div",{ref:d,className:"tl-shape tl-shape-background","data-shape-type":t.type,draggable:!1,children:!a&&g.jsx(bc,{fallback:c,onError:p,children:g.jsx(W5,{shape:t,util:r})})}),g.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,draggable:!1,children:a?g.jsx(G5,{shape:t}):g.jsx(bc,{fallback:c,onError:p,children:g.jsx(K5,{shape:t,util:r})})})]}):null}),K5=w.memo(function({shape:n,util:t}){return Qp("InnerShape:"+n.type,()=>t.component(n))},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta&&e.util===n.util),W5=w.memo(function({shape:n,util:t}){return Qp("InnerShape:"+n.type,()=>{var r;return(r=t.backgroundComponent)==null?void 0:r.call(t,n)})},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta),G5=w.memo(function({shape:n}){const r=U().getShapeGeometry(n).bounds;return g.jsx("div",{className:"tl-shape__culled",style:{transform:`translate(${O(r.minX)}px, ${O(r.minY)}px)`,width:Math.max(1,O(r.width)),height:Math.max(1,O(r.height))}})},()=>!0);function Fv({className:e}){const n=U(),{Background:t,SvgDefs:r}=Pt(),o=ne.useRef(null),s=ne.useRef(null),i=ne.useRef(null);jL(),RD(),MD(),gL(o),hj(o),ii("position layers",()=>{const h=s.current;if(!h)return;const p=i.current;if(!p)return;const{x:m,y:f,z:S}=n.getCamera(),v=S>=1?Gh(S,[1,8],[.125,.5],!0):Gh(S,[.1,1],[-2,.125],!0),x=`scale(${O(S)}) translate(${O(m+v)}px,${O(f+v)}px)`;h.style.setProperty("transform",x),p.style.setProperty("transform",x)},[n]);const a=AD(),l=G("shapeSvgDefs",()=>{const h=new Map;for(const p of dt(n.shapeUtils)){if(!p)return;const m=p.getCanvasSvgDefs();for(const{key:f,component:S}of m)h.has(f)||h.set(f,g.jsx(S,{},f))}return[...h.values()]},[n]),c=G("debug_shapes",()=>Oe.hideShapes.get(),[Oe]),u=G("debug_svg",()=>Oe.debugSvg.get(),[Oe]),d=G("debug_geometry",()=>Oe.debugGeometry.get(),[Oe]);return g.jsxs("div",{ref:o,draggable:!1,className:fe("tl-canvas",e),"data-testid":"canvas",...a,children:[t&&g.jsx(t,{}),g.jsx(Y5,{}),g.jsx(u6,{}),g.jsx("svg",{className:"tl-svg-context",children:g.jsxs("defs",{children:[l,lb&&g.jsx(lb,{}),g.jsx(i6,{}),g.jsx(a6,{}),g.jsx(l6,{}),r&&g.jsx(r,{})]})}),g.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[g.jsx(p6,{}),g.jsx(h6,{}),c?null:u?g.jsx(t6,{}):g.jsx(n6,{})]}),g.jsxs("div",{className:"tl-fixed-layer tl-overlays",children:[g.jsxs("div",{ref:i,className:"tl-html-layer",children:[d?g.jsx(BL,{}):null,g.jsx(J5,{}),g.jsx(q5,{}),g.jsx(X5,{}),g.jsx(Z5,{}),g.jsx(r6,{}),g.jsx(o6,{}),g.jsx(s6,{}),g.jsx(Q5,{}),g.jsx(d6,{}),g.jsx(z5,{})]}),g.jsx(f6,{})]})]})}function Y5(){const e=U(),n=G("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=G("camera",()=>e.getCamera(),[e]),s=G("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=Pt();return i&&s?g.jsx(i,{x:t,y:r,z:o,size:n}):null}function X5(){const e=U(),n=G("scribbles",()=>e.getInstanceState().scribbles,[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=Pt();return r&&n.length?g.jsx(g.Fragment,{children:n.map(o=>g.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:t},o.id))}):null}function q5(){const e=U(),n=G("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=Pt();return t&&n?g.jsx(t,{className:"tl-user-brush",brush:n}):null}function Z5(){const e=U(),n=G("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=Pt();return t&&n?g.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function Q5(){const e=U(),n=G("snapLines",()=>e.snaps.getLines(),[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapLine:r}=Pt();return r&&n.length>0?g.jsx(g.Fragment,{children:n.map(o=>g.jsx(r,{className:"tl-user-snapline",line:o,zoom:t},o.id))}):null}function J5(){const e=U(),{Handles:n}=Pt(),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),r=G("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),o=G("isChangingStyle",()=>e.getInstanceState().isReadonly,[e]),s=G("isChangingStyle",()=>e.getInstanceState().isChangingStyle,[e]),i=G("onlySelectedShape",()=>e.getOnlySelectedShape(),[e]),a=G("transform",()=>i?e.getShapePageTransform(i):null,[e,i]),l=G("handles",()=>{if(!i)return null;const c=e.getShapeHandles(i);if(!c)return null;const u=(r?DE:jE)/t*2;return c.filter(d=>d.type!=="virtual"||!c.some(h=>h!==d&&h.type==="vertex"&&C.Dist(d,h)<u)).sort(d=>d.type==="vertex"?1:-1)},[e,i,t,r]);return!n||!i||s||o||!l||!a?null:g.jsx(n,{children:g.jsx("g",{transform:te.toCssString(a),children:l.map(c=>g.jsx(e6,{shapeId:i.id,handle:c,zoom:t,isCoarse:r},c.id))})})}function e6({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=mL(e,n.id),{Handle:s}=Pt();return s?g.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:g.jsx(s,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function t6(){const e=U(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]);return g.jsx(g.Fragment,{children:n.map(t=>g.jsxs(ne.Fragment,{children:[g.jsx(ck,{...t}),g.jsx(c6,{id:t.id})]},t.id+"_fragment"))})}function n6(){const e=U(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]);return g.jsx(g.Fragment,{children:n.map(t=>g.jsx(ck,{...t},t.id+"_shape"))})}function r6(){const e=U(),n=G("selectedShapeIds",()=>e.getCurrentPageState().selectedShapeIds,[e]);return G("should display selected ids",()=>e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!e.getInstanceState().isChangingStyle,[e])?g.jsx(g.Fragment,{children:n.map(r=>g.jsx(uu,{className:"tl-user-indicator__selected",id:r},r+"_indicator"))}):null}const o6=function(){const n=U(),{HoveredShapeIndicator:t}=Pt(),r=G("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),o=G("hovering canvas",()=>n.getInstanceState().isHoveringCanvas,[n]),s=G("hovered id",()=>n.getCurrentPageState().hoveredShapeId,[n]);return r||!o||!s||!t?null:g.jsx(t,{shapeId:s})},s6=je(function(){const n=U(),t=Wh(n.getHintingShapeIds());return t.length?g.jsx(g.Fragment,{children:t.map(r=>g.jsx(uu,{className:"tl-user-indicator__hint",id:r},r+"_hinting"))}):null});function lb(){return g.jsxs("g",{id:"cursor",children:[g.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[g.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),g.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),g.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[g.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),g.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),g.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[g.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),g.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function i6(){return g.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function a6(){return g.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:g.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function l6(){return g.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[g.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),g.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const c6=je(function({id:n}){const t=U(),r=t.getShape(n),[o,s]=ne.useState(""),i=(r==null?void 0:r.parentId)===t.getCurrentPageId();return ne.useEffect(()=>{if(!i)return;let a=null;const l=su("shape to svg",async()=>{const c=Math.random();a=c;const u=t.getShapePageBounds(n),d=await t.getSvg([n],{padding:0,background:t.getInstanceState().exportBackground});d&&u&&a===c&&(d.style.setProperty("overflow","visible"),d.setAttribute("preserveAspectRatio","xMidYMin slice"),d.style.setProperty("transform",`translate(${u.x}px, ${u.y+u.h+12}px)`),d.style.setProperty("border","1px solid black"),s(d==null?void 0:d.outerHTML))});return()=>{a=null,l()}},[t,n,i]),i?g.jsx("div",{style:{paddingTop:12,position:"absolute"},children:g.jsx("div",{style:{display:"flex"},dangerouslySetInnerHTML:{__html:o}})}):null});function u6(){const e=G("debugging ui log",()=>Oe.logMessages.get(),[Oe]);return e.length?g.jsx("div",{className:"debug__ui-logger",children:e.map((n,t)=>{const r=typeof n=="string"?n:JSON.stringify(n);return g.jsx("div",{className:"debug__ui-logger__line",children:r},t)})}):null}function d6(){const e=U(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=Pt();return!t||!r?null:g.jsx(r,{bounds:t,rotation:n})}function h6(){const e=U(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=Pt();return!t||!r?null:g.jsx(r,{bounds:t,rotation:n})}function p6(){const{OnTheCanvas:e}=Pt();return e?g.jsx(e,{}):null}function f6(){const{InFrontOfTheCanvas:e}=Pt();return e?g.jsx(e,{}):null}const g6=()=>g.jsx(Dk,{children:"Connecting..."});function Ue(){return ef()}const uk="TLDRAW_USER_DATA_v3",dk=we({id:ge,name:ge.nullable().optional(),locale:ge.nullable().optional(),color:ge.nullable().optional(),isDarkMode:ve.nullable().optional(),animationSpeed:he.nullable().optional(),edgeScrollSpeed:he.nullable().optional(),isSnapMode:ve.nullable().optional()}),Pl={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4},dp=$e({currentVersion:Pl.AddEdgeScrollSpeed,migrators:{[Pl.AddAnimationSpeed]:{up:e=>({...e,animationSpeed:1}),down:({animationSpeed:e,...n})=>n},[Pl.AddIsSnapMode]:{up:e=>({...e,isSnapMode:!1}),down:({isSnapMode:e,...n})=>n},[Pl.MakeFieldsNullable]:{up:e=>e,down:e=>({id:e.id,name:e.name??ir.name,locale:e.locale??ir.locale,color:e.color??ir.color,isDarkMode:e.isDarkMode??ir.isDarkMode,animationSpeed:e.animationSpeed??ir.animationSpeed,isSnapMode:e.isSnapMode??ir.isSnapMode})},[Pl.AddEdgeScrollSpeed]:{up:e=>({...e,edgeScrollSpeed:1}),down:({edgeScrollSpeed:e,...n})=>n}}}),cb=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function m6(){return cb[Math.floor(Math.random()*cb.length)]}function y6(){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 S6(){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 ir=Object.freeze({name:"New User",locale:aD(),color:m6(),isDarkMode:!1,edgeScrollSpeed:1,animationSpeed:S6()?0:1,isSnapMode:!1});function ed(){return{id:Ue()}}function hk(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return ed();const n=Pv({value:e.user,fromVersion:e.version,toVersion:dp.currentVersion??0,migrations:dp});if(n.type==="error")return ed();try{dk.validate(n.value)}catch{return ed()}return n.value}function v6(){var n;const e=typeof window>"u"?null:JSON.parse(((n=window==null?void 0:window.localStorage)==null?void 0:n.getItem(uk))||"null")??null;return hk(e)}const gu=sn("globalUserData",v6());function w6(){typeof window<"u"&&window.localStorage&&window.localStorage.setItem(uk,JSON.stringify({version:dp.currentVersion,user:gu.get()}))}function x6(e){dk.validate(e),gu.set(e),w6(),P6()}const b6=typeof process<"u"&&!1,xa=typeof BroadcastChannel<"u"&&!b6?new BroadcastChannel("tldraw-user-sync"):null;xa==null||xa.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===fk&&(n==null?void 0:n.origin)!==pk&&gu.set(hk(n.data))});const pk=Ue(),fk="tldraw-user-preferences-change";function P6(){xa==null||xa.postMessage({type:fk,origin:pk,data:{user:gu.get(),version:dp.currentVersion}})}function C6(){return gu.get()}function gk(e={}){return{derivePresenceState:e.derivePresenceState??(()=>Z("presence",()=>null)),userPreferences:e.userPreferences??Z("userPreferences",()=>C6()),setUserPreferences:e.setUserPreferences??x6}}var mk={exports:{}};(function(e){var n=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function o(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,d,h){if(typeof u!="function")throw new TypeError("The listener must be a function");var p=new o(u,d||l,h),m=t?t+c:c;return l._events[m]?l._events[m].fn?l._events[m]=[l._events[m],p]:l._events[m].push(p):(l._events[m]=p,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,d;if(this._eventsCount===0)return c;for(d in u=this._events)n.call(u,d)&&c.push(t?d.slice(1):d);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=t?t+c:c,d=this._events[u];if(!d)return[];if(d.fn)return[d.fn];for(var h=0,p=d.length,m=new Array(p);h<p;h++)m[h]=d[h].fn;return m},a.prototype.listenerCount=function(c){var u=t?t+c:c,d=this._events[u];return d?d.fn?1:d.length:0},a.prototype.emit=function(c,u,d,h,p,m){var f=t?t+c:c;if(!this._events[f])return!1;var S=this._events[f],v=arguments.length,x,b;if(S.fn){switch(S.once&&this.removeListener(c,S.fn,void 0,!0),v){case 1:return S.fn.call(S.context),!0;case 2:return S.fn.call(S.context,u),!0;case 3:return S.fn.call(S.context,u,d),!0;case 4:return S.fn.call(S.context,u,d,h),!0;case 5:return S.fn.call(S.context,u,d,h,p),!0;case 6:return S.fn.call(S.context,u,d,h,p,m),!0}for(b=1,x=new Array(v-1);b<v;b++)x[b-1]=arguments[b];S.fn.apply(S.context,x)}else{var P=S.length,E;for(b=0;b<P;b++)switch(S[b].once&&this.removeListener(c,S[b].fn,void 0,!0),v){case 1:S[b].fn.call(S[b].context);break;case 2:S[b].fn.call(S[b].context,u);break;case 3:S[b].fn.call(S[b].context,u,d);break;case 4:S[b].fn.call(S[b].context,u,d,h);break;default:if(!x)for(E=1,x=new Array(v-1);E<v;E++)x[E-1]=arguments[E];S[b].fn.apply(S[b].context,x)}}return!0},a.prototype.on=function(c,u,d){return s(this,c,u,d,!1)},a.prototype.once=function(c,u,d){return s(this,c,u,d,!0)},a.prototype.removeListener=function(c,u,d,h){var p=t?t+c:c;if(!this._events[p])return this;if(!u)return i(this,p),this;var m=this._events[p];if(m.fn)m.fn===u&&(!h||m.once)&&(!d||m.context===d)&&i(this,p);else{for(var f=0,S=[],v=m.length;f<v;f++)(m[f].fn!==u||h&&!m[f].once||d&&m[f].context!==d)&&S.push(m[f]);S.length?this._events[p]=S.length===1?S[0]:S:i(this,p)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=t?t+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,e.exports=a})(mk);var E6=mk.exports;function Ln({children:e,className:n="",...t}){return g.jsx("svg",{...t,className:`tl-svg-container ${n}`,children:e})}function zv(e,n,t,r){const o=e.x-t.x,s=e.y-t.y,i=r.x-t.x,a=r.y-t.y,l=n.x-e.x,c=n.y-e.y,u=i*s-a*o,d=l*s-c*o,h=a*l-i*c;if(u===0||d===0||h===0)return null;if(h!==0){const p=u/h,m=d/h;if(0<=p&&p<=1&&0<=m&&m<=1)return C.AddXY(e,p*l,p*c)}return null}function sf(e,n,t,r){const o=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),s=2*((n.x-e.x)*(e.x-t.x)+(n.y-e.y)*(e.y-t.y)),i=t.x*t.x+t.y*t.y+e.x*e.x+e.y*e.y-2*(t.x*e.x+t.y*e.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-s+l)/(2*o),u=(-s-l)/(2*o);if((c<0||c>1)&&(u<0||u>1))return null;const d=[];return 0<=c&&c<=1&&d.push(C.Lrp(e,n,c)),0<=u&&u<=1&&d.push(C.Lrp(e,n,u)),d.length===0?null:d}function yk(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=zv(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function Sk(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=zv(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function k6(e,n,t,r){let o=t.x-e.x,s=t.y-e.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+n*n)/(2*i),l=Math.sqrt(n*n-a*a);return o/=i,s/=i,[new C(e.x+o*a-s*l,e.y+s*a+o*l),new C(e.x+o*a+s*l,e.y+s*a-o*l)]}function Ay(e,n,t){const r=[];let o,s,i;for(let a=0,l=t.length;a<l;a++)o=t[a],s=t[(a+1)%t.length],i=sf(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function ub(e,n,t){const r=[];let o,s,i;for(let a=1,l=t.length;a<l;a++)o=t[a-1],s=t[a],i=sf(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function td(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function vk(e,n,t,r){return td(e,t,r)!==td(n,t,r)&&td(e,n,t)!==td(e,n,r)}function My(e,n){const t=new Map;let r,o,s,i;for(let a=0,l=e.length;a<l;a++)if(r=e[a],Rr(r,n)){const c=xg(r);t.has(c)||t.set(c,r)}for(let a=0,l=n.length;a<l;a++)if(r=n[a],Rr(r,e)){const c=xg(r);t.has(c)||t.set(c,r)}for(let a=0,l=e.length;a<l;a++){r=e[a],o=e[(a+1)%e.length];for(let c=0,u=n.length;c<u;c++){s=n[c],i=n[(c+1)%n.length];const d=zv(r,o,s,i);if(d!==null){const h=xg(d);t.has(h)||t.set(h,d)}}}return t.size===0?null:I6([...t.values()])}function xg(e){return`${e.x},${e.y}`}function I6(e){const n=C.Average(e);return e.sort((t,r)=>C.Angle(n,t)-C.Angle(n,r))}function _6(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let l=0,c=n.length;l<c;l++)if(o=n[l],s=n[(l+1)%c],vk(t,r,o,s))return!0}return!1}class Ec extends bi{constructor(t){super({...t,isClosed:!1,isFilled:!1});y(this,"start");y(this,"end");y(this,"d");y(this,"u");y(this,"ul");y(this,"_length");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()}get length(){return this._length?this._length:this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(t){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=C.Sub(t,r).dpr(s)/i,l=r.x+s.x*a;if(l<Math.min(r.x,o.x))return r.x<o.x?r:o;if(l>Math.max(r.x,o.x))return r.x>o.x?r:o;const c=r.y+s.y*a;return c<Math.min(r.y,o.y)?r.y<o.y?r:o:c>Math.max(r.y,o.y)?r.y>o.y?r:o:new C(l,c)}hitTestLineSegment(t,r,o){return vk(t,r,this.start,this.end)}}class Pi extends bi{constructor(t){super({isClosed:!1,isFilled:!1,...t});y(this,"points");y(this,"_segments");y(this,"_length");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:t}=this;for(let r=0,o=t.length-1;r<o;r++){const s=t[r],i=t[r+1];this._segments.push(new Ec({start:s,end:i}))}this.isClosed&&this._segments.push(new Ec({start:t[t.length-1],end:t[0]}))}return this._segments}get length(){return this._length||(this._length=this.segments.reduce((t,r)=>t+r.length,0)),this._length}getVertices(){return this.points}nearestPoint(t){const{segments:r}=this;let o=this.points[0],s=1/0,i,a;for(let l=0;l<r.length;l++)i=r[l].nearestPoint(t),a=i.dist(t),a<s&&(o=i,s=a);return o}hitTestLineSegment(t,r,o){return this.segments.some(s=>s.hitTestLineSegment(t,r,o))}}class gt extends Pi{constructor(n){super({...n}),this.isClosed=!0}}class Es extends gt{constructor(t){const{x:r=0,y:o=0,width:s,height:i}=t;super({...t,points:[new C(r,o),new C(r+s,o),new C(r+s,o+i),new C(r,o+i)]});y(this,"x");y(this,"y");y(this,"w");y(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new re(this.x,this.y,this.w,this.h)}}class Tr{constructor(n){y(this,"canSnap",()=>!0);y(this,"canScroll",()=>!1);y(this,"canUnmount",()=>!0);y(this,"canBind",(n,t)=>!0);y(this,"canEdit",()=>!1);y(this,"canResize",()=>!0);y(this,"canEditInReadOnly",()=>!1);y(this,"canCrop",()=>!1);y(this,"hideResizeHandles",()=>!1);y(this,"hideRotateHandle",()=>!1);y(this,"hideSelectionBoundsBg",()=>!1);y(this,"hideSelectionBoundsFg",()=>!1);y(this,"isAspectRatioLocked",()=>!1);y(this,"onBeforeCreate");y(this,"onBeforeUpdate");y(this,"onDragShapesOver");y(this,"onDragShapesOut");y(this,"onDropShapesOver");y(this,"onResizeStart");y(this,"onResize");y(this,"onResizeEnd");y(this,"onTranslateStart");y(this,"onTranslate");y(this,"onTranslateEnd");y(this,"onHandleDrag");y(this,"onRotateStart");y(this,"onRotate");y(this,"onRotateEnd");y(this,"onBindingChange");y(this,"onChildrenChange");y(this,"onDoubleClickHandle");y(this,"onDoubleClickEdge");y(this,"onDoubleClick");y(this,"onClick");y(this,"onEditEnd");this.editor=n}providesBackgroundForChildren(n){return!1}getOutlineSegments(n){return[this.editor.getShapeGeometry(n).vertices]}canReceiveNewChildrenOfType(n,t){return!1}canDropShapes(n,t){return!1}expandSelectionOutlinePx(n){return 0}getCanvasSvgDefs(){return[]}}y(Tr,"props"),y(Tr,"migrations"),y(Tr,"type");function T6(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=t;let c=0,u=0,d=1,h=0,p=0;switch(l){case"dashed":{d=1,c=Math.min(n*a,e/4);break}case"dotted":{d=100,c=n/d;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=c/2,p+=c/2):s==="skip"&&(e-=c,p-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),u=Math.floor(e/c/(2*d)),u-=u%o,u<3&&l==="dashed"?e/n<5?(c=e,u=1,h=0):(c=e*.333,h=e*.333):(u=Math.max(u,3),c=e/u/(2*d),r?(p=c/2,h=(e-u*c)/u):h=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,h].join(" "),strokeDashoffset:p.toString()}}function db({bounds:e,className:n}){const t=U(),r=G("zoom level",()=>t.getZoomLevel(),[t]);return g.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=T6(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return g.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class Qd extends Tr{constructor(){super(...arguments);y(this,"hideSelectionBoundsFg",()=>!0);y(this,"canBind",()=>!1);y(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 Es({width:1,height:1,isFilled:!1}):new Po({children:r.map(o=>{const s=this.editor.getShape(o),i=this.editor.getShapeGeometry(o),a=this.editor.getShapeLocalTransform(s).applyToPoints(i.vertices);return i.isClosed?new gt({points:a,isFilled:!0}):new Pi({points:a})})})}component(t){const r=this.editor.getErasingShapeIds().includes(t.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(l=>l!==t.id&&this.editor.isShapeOfType(this.editor.getShape(l),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==t.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(t).bounds;return g.jsx(Ln,{id:t.id,children:g.jsx(db,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return g.jsx(db,{className:"",bounds:r})}}y(Qd,"type","group"),y(Qd,"props",V3),y(Qd,"migrations",K3);const wk=[Qd],$6=new Set(wk.map(e=>e.type));function xk(e){const n=[...wk],t=new Set;for(const r of e){if($6.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(t.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);n.push(r),t.add(r.type)}return n}function hb(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 Ya(e)}}class A6{constructor(n){y(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(!hb(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!hb(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 Oy extends A6{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:Ya(r,"type")}}}class Bv{constructor(){y(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}access(n){return this.items.get(n)}set(n,t){this.items.set(n,t)}has(n){return this.items.has(n)}invalidate(n){this.items.delete(n)}bust(){this.items=new WeakMap}}function M6(e,n,t){return fetch(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function O6(e,n){var o;let t=e;const r=new Set(n);for(;r.has(t);)t=(o=/^.*(\d+)$/.exec(t))!=null&&o[1]?t.replace(/(\d+)(?=\D?)$/,s=>(+s+1).toString()):`${t} 1`;return t}const zn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",R6="a0",bk="A00000000000000000000000000";function Pk(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 Ck(e){if(e.length!==Pk(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function pb(e){if(e===void 0)throw Error("n is undefined")}function fb(e){Ck(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=zn.indexOf(t[o])+1;s===zn.length?t[o]="0":(t[o]=zn.charAt(s),r=!1)}if(r){if(n==="Z")return"a0";if(n==="z")return;const o=String.fromCharCode(n.charCodeAt(0)+1);return o>"a"?t.push("0"):t.pop(),o+t.join("")}else return n+t.join("")}function D6(e){Ck(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=zn.indexOf(t[o])-1;s===-1?t[o]=zn.slice(-1):(t[o]=zn.charAt(s),r=!1)}if(r){if(n==="a")return"Z"+zn.slice(-1);if(n==="A")return;const o=String.fromCharCode(n.charCodeAt(0)-1);return o<"Z"?t.push(zn.slice(-1)):t.pop(),o+t.join("")}else return n+t.join("")}function ea(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)+ea(e.slice(o),n.slice(o))}const t=e?zn.indexOf(e.charAt(0)):0,r=n!==void 0?zn.indexOf(n.charAt(0)):zn.length;if(r-t>1){const o=Math.round(.5*(t+r));return zn.charAt(o)}else return n&&n.length>1?n.slice(0,1):zn.charAt(t)+ea(e.slice(1),void 0)}function Wl(e){const n=Pk(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function gb(e){if(e===bk)throw new Error("invalid index: "+e);const n=Wl(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function Ui(e,n){if(e!==void 0&&gb(e),n!==void 0&&gb(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return R6;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=Wl(n),l=n.slice(a.length);if(a===bk)return a+ea("",l);if(a<n)return a;const c=D6(a);return pb(c),c}if(n===void 0){const a=Wl(e),l=e.slice(a.length),c=fb(a);return c===void 0?a+ea(l,void 0):c}const t=Wl(e),r=e.slice(t.length),o=Wl(n),s=n.slice(o.length);if(t===o)return t+ea(r,s);const i=fb(t);return pb(i),i<n?i:t+ea(r,void 0)}function ks(e,n,t){if(t===0)return[];if(t===1)return[Ui(e,n)];if(n===void 0){let s=Ui(e,n);const i=[s];for(let a=0;a<t-1;a++)s=Ui(s,n),i.push(s);return i}if(e===void 0){let s=Ui(e,n);const i=[s];for(let a=0;a<t-1;a++)s=Ui(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=Ui(e,n);return[...ks(e,o,r),o,...ks(o,n,t-r-1)]}function Ra(e,n,t){return ks(e,n,t)}function bg(e,n){return ks(e,void 0,n)}function nc(e,n){return ks(e,n,1)[0]}function So(e){return ks(e,void 0,1)[0]}function j6(e){return ks(void 0,e,1)[0]}function Ek(e,n="a1"){return[n,...ks(n,void 0,e)]}function Wt(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function nd(e,n,t){if(t.length===0)return[];const r=new Map;for(const s of pe(t.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:pe(e.getSortedChildIdsForParent(i).map(a=>e.getShape(a))),moving:new Set}),r.get(i).moving.add(s)}const o=[];switch(n){case"toBack":{r.forEach(({moving:s,children:i})=>L6(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>N6(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>F6(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>z6(s,i,o));break}}return o}function L6(e,n,t){const r=n.length;if(e.size===r)return;let o,s;for(let i=0;i<r;i++){const a=n[i];if(e.has(a))o=a.index,e.delete(a);else{s=a.index;break}}if(e.size!==0){const i=Ra(o,s,e.size);t.push(...Array.from(e.values()).sort(Wt).map((a,l)=>({...a,index:i[l]})))}}function N6(e,n,t){const r=n.length;if(e.size===r)return;let o,s;for(let i=r-1;i>-1;i--){const a=n[i];if(e.has(a))s=a.index,e.delete(a);else{o=a.index;break}}if(e.size!==0){const i=Ra(o,s,e.size);t.push(...Array.from(e.values()).sort(Wt).map((a,l)=>({...a,index:i[l]})))}}function F6(e,n,t){var s;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(n[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=o;Ra(n[i].index,(s=n[i+1])==null?void 0:s.index,i-l).forEach((c,u)=>t.push({...n[l+u],index:c})),o={name:"skipping"};break}}}}function z6(e,n,t){var s;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let i=r-1;i>-1;i--){const a=e.has(n[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;Ra((s=n[i-1])==null?void 0:s.index,n[i].index,o.selectIndex-i).forEach((l,c)=>{t.push({...n[i+c+1],index:l})}),o={name:"skipping"};break}}}}function kk({editor:e}){const n=e.getSelectedShapes(),t=e.getSelectionRotation(),r=e.getSelectionRotatedPageBounds(),{inputs:{originPagePoint:o}}=e;if(!r)return null;const s=r.center.clone().rotWith(r.point,t);return{selectionPageCenter:s,initialCursorAngle:s.angle(o),initialSelectionRotation:t,shapeSnapshots:n.map(i=>({shape:gs(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function Jd({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:l})=>{const c=Rn(a.parentId)?n.getShapePageTransform(a.parentId):te.Identity(),u=C.RotWith(l,o,e),d=te.applyToPoint(te.Inverse(c),u),h=_r(a.rotation+e);return{id:a.id,type:a.type,x:d.x,y:d.y,rotation:h}}));const i=[];s.forEach(({shape:a})=>{var d,h,p;const l=n.getShape(a.id);if(!l)return;const c=n.getShapeUtil(a);if(r==="start"||r==="one-off"){const m=(d=c.onRotateStart)==null?void 0:d.call(c,a);m&&i.push(m)}const u=(h=c.onRotate)==null?void 0:h.call(c,a,l);if(u&&i.push(u),r==="end"||r==="one-off"){const m=(p=c.onRotateEnd)==null?void 0:p.call(c,a,l);m&&i.push(m)}}),i.length>0&&n.updateShapes(i)}const B6=e=>{const{store:n}=e,t=n.query.filterHistory("shape"),r=n.query.records("shape",()=>({type:{eq:"arrow"}}));function o(){const s=r.get(),i={};for(const a of s){const{start:l,end:c}=a.props;if(l.type==="binding"){const u=i[l.boundShapeId];u?u.push({arrowId:a.id,handleId:"start"}):i[l.boundShapeId]=[{arrowId:a.id,handleId:"start"}]}if(c.type==="binding"){const u=i[c.boundShapeId];u?u.push({arrowId:a.id,handleId:"end"}):i[c.boundShapeId]=[{arrowId:a.id,handleId:"end"}]}}return i}return Z("arrowBindingsIndex",(s,i)=>{if(wa(s))return o();const a=s,l=t.getDiffSince(i);if(l===Un)return o();let c;function u(p){c||(c={...a}),c[p]?c[p]===a[p]&&(c[p]=[...c[p]]):c[p]=[]}function d(p,m,f){u(p),c[p]=c[p].filter(S=>S.arrowId!==m||S.handleId!==f),c[p].length===0&&delete c[p]}function h(p,m,f){u(p),c[p].push({arrowId:m,handleId:f})}for(const p of l){for(const m of Object.values(p.added))if(e.isShapeOfType(m,"arrow")){const{start:f,end:S}=m.props;f.type==="binding"&&h(f.boundShapeId,m.id,"start"),S.type==="binding"&&h(S.boundShapeId,m.id,"end")}for(const[m,f]of Object.values(p.updated))if(!(!e.isShapeOfType(m,"arrow")||!e.isShapeOfType(f,"arrow")))for(const S of["start","end"]){const v=m.props[S],x=f.props[S];v.type==="binding"&&x.type==="point"?d(v.boundShapeId,m.id,S):v.type==="point"&&x.type==="binding"?h(x.boundShapeId,f.id,S):v.type==="binding"&&x.type==="binding"&&v.boundShapeId!==x.boundShapeId&&(d(v.boundShapeId,m.id,S),h(x.boundShapeId,f.id,S))}for(const m of Object.values(p.removed))if(e.isShapeOfType(m,"arrow")){const{start:f,end:S}=m.props;f.type==="binding"&&d(f.boundShapeId,m.id,"start"),S.type==="binding"&&d(S.boundShapeId,m.id,"end")}}return c??a})},U6=e=>{const n=e.query.ids("shape");function t(){const r={},o=n.get(),s=Array(o.size);return o.forEach(i=>s.push(e.get(i))),s.sort(Wt),s.forEach(i=>{r[i.parentId]||(r[i.parentId]=[]),r[i.parentId].push(i.id)}),r}return Z("parentsToChildrenWithIndexes",(r,o)=>{if(wa(r))return t();const s=e.history.getDiffSince(o);if(s===Un)return t();if(s.length===0)return r;let i=null;const a=u=>{i||(i={...r}),i[u]?i[u]===r[u]&&(i[u]=[...i[u]]):i[u]=[]},l=new Set;let c;for(let u=0,d=s.length;u<d;u++){c=s[u];for(const h of Object.values(c.added))ti(h)&&(a(h.parentId),i[h.parentId].push(h.id),l.add(i[h.parentId]));for(const[h,p]of Object.values(c.updated))if(ti(p)&&ti(h)){if(h.parentId!==p.parentId)a(h.parentId),a(p.parentId),i[h.parentId].splice(i[h.parentId].indexOf(p.id),1),i[p.parentId].push(p.id),l.add(i[p.parentId]);else if(h.index!==p.index){a(p.parentId);const m=i[p.parentId].indexOf(p.id);i[p.parentId][m]=p.id,l.add(i[p.parentId])}}for(const h of Object.values(c.removed))ti(h)&&(a(h.parentId),i[h.parentId].splice(i[h.parentId].indexOf(h.id),1))}for(const u of l){const d=pe(u.map(h=>e.get(h)));d.sort(Wt),u.splice(0,u.length,...d.map(h=>h.id))}return i??r})},Pg=(e,n,t)=>{for(;!gn(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},H6=(e,n)=>{const t=e.query.ids("shape");let r=null;function o(){const s=n();return r=s,new Set([...t.get()].filter(i=>Pg(e,s,e.get(i))))}return Z("_shapeIdsInCurrentPage",(s,i)=>{if(wa(s))return o();const a=n();if(a!==r)return o();const l=e.history.getDiffSince(i);if(l===Un)return o();const c=new Xd(s);for(const d of l){for(const h of Object.values(d.added))ti(h)&&Pg(e,a,h)&&c.add(h.id);for(const[h,p]of Object.values(d.updated))ti(p)&&(Pg(e,a,p)?c.add(p.id):c.remove(p.id));for(const h of Object.keys(d.removed))Rn(h)&&c.remove(h)}const u=c.get();return u?Vl(u.value,u.diff):s})},V6=40;class K6{constructor(n){y(this,"_clickId","");y(this,"_clickTimeout");y(this,"_clickScreenPoint");y(this,"_previousScreenPoint");y(this,"_getClickTimeout",(n,t=Ue())=>{this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=setTimeout(()=>{if(this._clickState===n&&this._clickId===t){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},n==="idle"||n==="pendingDouble"?mD:yD)});y(this,"_clickState","idle");y(this,"lastPointerInfo",{});y(this,"transformPointerDownEvent",n=>{if(!this._clickState)return n;switch(this._clickScreenPoint=C.From(n.point),this._previousScreenPoint&&this._previousScreenPoint.dist(this._clickScreenPoint)>V6&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=n,this._clickState){case"idle":return this._clickState="pendingDouble",this._clickTimeout=this._getClickTimeout(this._clickState),n;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"pendingOverflow":return this._clickState="overflow",this._clickTimeout=this._getClickTimeout(this._clickState),n;default:return this._clickTimeout=this._getClickTimeout(this._clickState),n}});y(this,"transformPointerUpEvent",n=>{if(!this._clickState)return n;switch(this._clickScreenPoint=C.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"};default:return n}});y(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});y(this,"handleMove",()=>{this._clickState!=="idle"&&this._clickScreenPoint&&this._clickScreenPoint.dist(this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?ky:xc)&&this.cancelDoubleClickTimeout()});this.editor=n}get clickState(){return this._clickState}}class W6{constructor(n){y(this,"isSafari");y(this,"isIos");y(this,"isChromeForIos");y(this,"isFirefox");y(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)}}function Xs(e){if(e){let n=mb;for(;e.length;)n=n.push(e.pop());return n}return mb}class G6{constructor(){y(this,"length",0);y(this,"head",null);y(this,"tail",this)}push(n){return new Uv(n,this)}toArray(){return ko}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const mb=new G6;class Uv{constructor(n,t){y(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Uv(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 Y6{constructor(n,t){y(this,"_undos",sn("HistoryManager.undos",Xs()));y(this,"_redos",sn("HistoryManager.redos",Xs()));y(this,"_batchDepth",0);y(this,"onBatchComplete",()=>{});y(this,"_commands",{});y(this,"createCommand",(n,t,r)=>{if(this._commands[n])throw new Error(`Duplicate command: ${n}`);this._commands[n]=r;const o=(...s)=>{if(!this._batchDepth)return this.batch(()=>o(...s)),this.ctx;const i=t(...s);if(!i)return this.ctx;const{data:a,ephemeral:l,squashing:c,preservesRedoStack:u}=i;if(this.ignoringUpdates((d,h)=>(r.do(a),{undos:d,redos:h})),!l){const d=this._undos.get().head;c&&d&&d.type==="command"&&d.name===n&&d.preservesRedoStack===u?this._undos.update(h=>h.tail.push({...d,id:Ue(),data:r.squash(d.data,a)})):this._undos.update(h=>h.push({type:"command",name:n,data:a,id:Ue(),preservesRedoStack:u})),i.preservesRedoStack||this._redos.set(Xs()),this.ctx.emit("change-history",{reason:"push"})}return this.ctx};return o});y(this,"batch",n=>{try{this._batchDepth++,this._batchDepth===1?br(()=>{var r,o;const t=(r=this._undos.get().head)==null?void 0:r.id;n(),t!==((o=this._undos.get().head)==null?void 0:o.id)&&this.onBatchComplete()}):n()}catch(t){throw this.annotateError(t),t}finally{this._batchDepth--}return this});y(this,"ignoringUpdates",n=>{let t=this._undos.get(),r=this._redos.get();this._undos.set(Xs()),this._redos.set(Xs());try{({undos:t,redos:r}=br(()=>n(t,r)))}finally{this._undos.set(t),this._redos.set(r)}});y(this,"_undo",({pushToRedoStack:n,toMark:t=void 0})=>(this.ignoringUpdates((r,o)=>{var s;if(r.length===0)return{undos:r,redos:o};for(;((s=r.head)==null?void 0:s.type)==="STOP";){const i=r.head;if(r=r.tail,n&&(o=o.push(i)),i.id===t)return this.ctx.emit("change-history",n?{reason:"undo"}:{reason:"bail",markId:t}),{undos:r,redos:o}}if(r.length===0)return this.ctx.emit("change-history",n?{reason:"undo"}:{reason:"bail",markId:t}),{undos:r,redos:o};for(;r.head;){const i=r.head;if(r=r.tail,n&&(o=o.push(i)),i.type==="STOP"){if(i.onUndo&&(!t||i.id===t))return this.ctx.emit("change-history",n?{reason:"undo"}:{reason:"bail",markId:t}),{undos:r,redos:o}}else this._commands[i.name].undo(i.data)}return this.ctx.emit("change-history",n?{reason:"undo"}:{reason:"bail",markId:t}),{undos:r,redos:o}}),this));y(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));y(this,"redo",()=>(this.ignoringUpdates((n,t)=>{var r;if(t.length===0)return{undos:n,redos:t};for(;((r=t.head)==null?void 0:r.type)==="STOP";)n=n.push(t.head),t=t.tail;if(t.length===0)return this.ctx.emit("change-history",{reason:"redo"}),{undos:n,redos:t};for(;t.head;){const o=t.head;if(n=n.push(t.head),t=t.tail,o.type==="STOP"){if(o.onRedo)break}else{const s=this._commands[o.name];s.redo?s.redo(o.data):s.do(o.data)}}return this.ctx.emit("change-history",{reason:"redo"}),{undos:n,redos:t}}),this));y(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));y(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));y(this,"mark",(n=Ue(),t=!0,r=!0)=>{const o=this._undos.get().head;return o&&o.type==="STOP"&&o.id===n&&o.onUndo===t&&o.onRedo===r?o.id:(this._undos.update(s=>s.push({type:"STOP",id:n,onUndo:t,onRedo:r})),this.ctx.emit("mark-history",{id:n}),n)});this.ctx=n,this.annotateError=t}getNumUndos(){return this._undos.get().length}getNumRedos(){return this._redos.get().length}clear(){this._undos.set(Xs()),this._redos.set(Xs())}}class X6{constructor(n){y(this,"scribbleItems",new Map);y(this,"state","paused");y(this,"addScribble",(n,t=Ue())=>{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),this.state==="paused"&&this.resume(),r});y(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});y(this,"addPoint",(n,t,r)=>{const o=this.scribbleItems.get(n);if(!o)throw Error(`Scribble with id ${n} not found`);const{prev:s}=o,i={x:t,y:r,z:.5};return(!s||C.Dist(s,i)>=1)&&(o.next=i),o});y(this,"tick",n=>{this.editor.batch(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:l,prev:c}=t;l&&l!==c&&(t.prev=l,t.scribble.points.push(l)),t.scribble.points.length>8&&(t.scribble.state="active");return}t.delayRemaining>0&&(t.delayRemaining=Math.max(0,t.delayRemaining-n)),t.timeoutMs+=n,t.timeoutMs>=16&&(t.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=t;switch(a.state){case"active":{i&&i!==s?(t.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(t.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:t})=>({...t,points:[...t.points]})).slice(-5)}),this.scribbleItems.size===0&&this.pause()})});this.editor=n}resume(){this.state="running",this.editor.addListener("tick",this.tick)}pause(){this.editor.removeListener("tick",this.tick),this.state="paused"}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear(),this.pause()}}class q6{constructor(n){y(this,"_beforeCreateHandlers",{});y(this,"_afterCreateHandlers",{});y(this,"_beforeChangeHandlers",{});y(this,"_afterChangeHandlers",{});y(this,"_beforeDeleteHandlers",{});y(this,"_afterDeleteHandlers",{});y(this,"_batchCompleteHandlers",[]);this.editor=n,n.store.onBeforeCreate=(r,o)=>{const s=this._beforeCreateHandlers[r.typeName];if(s){let i=r;for(const a of s)i=a(i,o);return i}return r},n.store.onAfterCreate=(r,o)=>{const s=this._afterCreateHandlers[r.typeName];if(s)for(const i of s)i(r,o)},n.store.onBeforeChange=(r,o,s)=>{const i=this._beforeChangeHandlers[o.typeName];if(i){let a=o;for(const l of i)a=l(r,a,s);return a}return o};let t=0;n.store.onAfterChange=(r,o,s)=>{if(t++,t>1e3)console.error("[CleanupManager.onAfterChange] Maximum update depth exceeded, bailing out.");else{const i=this._afterChangeHandlers[o.typeName];if(i)for(const a of i)a(r,o,s)}t--},n.store.onBeforeDelete=(r,o)=>{const s=this._beforeDeleteHandlers[r.typeName];if(s){for(const i of s)if(i(r,o)===!1)return!1}},n.store.onAfterDelete=(r,o)=>{const s=this._afterDeleteHandlers[r.typeName];if(s)for(const i of s)i(r,o)},n.history.onBatchComplete=()=>{this._batchCompleteHandlers.forEach(r=>r())}}registerBeforeCreateHandler(n,t){return this._beforeCreateHandlers[n]||(this._beforeCreateHandlers[n]=[]),this._beforeCreateHandlers[n].push(t),()=>qs(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>qs(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>qs(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>qs(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>qs(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>qs(this._afterDeleteHandlers[n],t)}registerBatchCompleteHandler(n){return this._batchCompleteHandlers.push(n),()=>qs(this._batchCompleteHandlers,n)}}function qs(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}var Z6=Object.defineProperty,Q6=Object.getOwnPropertyDescriptor,Ci=(e,n,t,r)=>{for(var o=r>1?void 0:r?Q6(n,t):n,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(n,t,o):i(o))||o);return r&&o&&Z6(n,t,o),o};const de=e=>Math.round(e*10**8)/10**8;function go(e,n,t,r,o){const s=e.filter(a=>(r==="forward"?a.startNode.id===n:a.endNode.id===n)&&de(a.length)===de(t)&&wr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=go(e,l,t,r,wr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function J6(e){e.sort((n,t)=>t.gaps.length-n.gaps.length);for(let n=e.length-1;n>0;n--){const t=e[n];for(let r=n-1;r>=0;r--){const o=e[r];if(o.direction===t.direction&&t.gaps.every(s=>o.gaps.some(i=>de(s.startEdge[0].x)===de(i.startEdge[0].x)&&de(s.startEdge[0].y)===de(i.startEdge[0].y)&&de(s.startEdge[1].x)===de(i.startEdge[1].x)&&de(s.startEdge[1].y)===de(i.startEdge[1].y))&&o.gaps.some(i=>de(s.endEdge[0].x)===de(i.endEdge[0].x)&&de(s.endEdge[0].y)===de(i.endEdge[0].y)&&de(s.endEdge[1].x)===de(i.endEdge[1].x)&&de(s.endEdge[1].y)===de(i.endEdge[1].y)))){e.splice(n,1);break}}}}class Ds{constructor(n){y(this,"_snapLines",sn("snapLines",void 0));this.editor=n}getLines(){return this._snapLines.get()??ko}clear(){this.getLines().length&&this._snapLines.set(void 0)}setLines(n){this._snapLines.set(n)}getSnapPointsCache(){const{editor:n}=this;return n.store.createComputedCache("snapPoints",t=>{const r=n.getShapePageTransform(t.id);return r?this.editor.getShapeGeometry(t).snapPoints.map((s,i)=>{const{x:a,y:l}=te.applyToPoint(r,s);return{x:a,y:l,id:`${t.id}:${i}`}}):void 0})}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:n}=this,t=n.getRenderingBounds(),r=n.getSelectedShapeIds(),o=[],s=i=>{if(Rn(i)){const l=n.getShape(i);l&&n.isShapeOfType(l,"frame")&&o.push({id:i,pageBounds:n.getShapePageBounds(i),isClosed:n.getShapeGeometry(l).isClosed})}const a=n.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=n.getShape(l);if(!c||!n.getShapeUtil(c).canSnap(c))continue;const d=n.getShapePageBounds(l);if(d&&t.includes(d)){if(n.isShapeOfType(c,"group")){s(l);continue}o.push({id:l,pageBounds:d,isClosed:n.getShapeGeometry(c).isClosed})}}};return s(this.getCurrentCommonAncestor()??n.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}getSnappablePoints(){const n=this.getSnapPointsCache(),t=this.getSnappableShapes(),r=[];return t.forEach(o=>{const s=n.get(o.id);s&&r.push(...s)}),r}getVisibleGaps(){const n=[],t=[];let r,o;const s=this.getSnappableShapes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let l=a+1;l<s.length;l++)o=s[l],r.pageBounds.maxX<o.pageBounds.minX&&bl(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&n.push({startNode:r,endNode:o,startEdge:[new C(r.pageBounds.maxX,r.pageBounds.minY),new C(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new C(o.pageBounds.minX,o.pageBounds.minY),new C(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:wr(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)o=i[l],r.pageBounds.maxY<o.pageBounds.minY&&bl(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&t.push({startNode:r,endNode:o,startEdge:[new C(r.pageBounds.minX,r.pageBounds.maxY),new C(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new C(o.pageBounds.minX,o.pageBounds.minY),new C(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:wr(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:n,vertical:t}}snapTranslate({lockedAxis:n,initialSelectionPageBounds:t,initialSelectionSnapPoints:r,dragDelta:o}){var S,v;const s=this.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(o),l=r.map(({x,y:b},P)=>({id:"selection:"+P,x:x+o.x,y:b+o.y})),c=i,u=[],d=[],h=new C(s,s);this.collectPointSnaps({minOffset:h,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:h});const p=new C(n==="x"?0:((S=u[0])==null?void 0:S.nudge)??0,n==="y"?0:((v=d[0])==null?void 0:v.nudge)??0);h.x=0,h.y=0,u.length=0,d.length=0,l.forEach(x=>{x.x+=p.x,x.y+=p.y}),a.translate(p),this.collectPointSnaps({minOffset:h,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:h});const m=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:d}),f=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d});return this._snapLines.set([...f,...m]),{nudge:p}}getOutlinesInPageSpace(){return this.getSnappableShapes().map(({id:n,isClosed:t})=>{const r=Zt(this.editor.getShapeGeometry(n).vertices);t&&r.push(r[0]);const o=this.editor.getShapePageTransform(n);if(!o)throw Error("No page transform");return te.applyToPoints(o,r)})}getSnappingHandleDelta({handlePoint:n,additionalSegments:t}){const r=this.getSnapThreshold(),o=this.getOutlinesInPageSpace();let s=r,i=null,a,l,c,u;const d=[...o,...t];for(const h of d)for(let p=0;p<h.length-1;p++)a=h[p],l=h[p+1],c=C.NearestPointOnLineSegment(a,l,n),u=C.Dist(n,c),!isNaN(u)&&u<s&&(s=u,i=c);return i?(this._snapLines.set([{id:Ue(),type:"points",points:[i]}]),C.Sub(i,n)):null}snapResize({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var I,_;const i=this.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=re.Resize(n,r,s?t.x*2:t.x,s?t.y*2:t.y,o);let u=r;l<0&&(u=NL(u)),c<0&&(u=LL(u)),s&&(a.center=n.center);const d=u==="top"||u==="bottom",h=u==="left"||u==="right",p=yb(u,a),m=this.getSnappablePoints(),f=[],S=[],v=new C(i,i);this.collectPointSnaps({minOffset:v,nearestSnapsX:f,nearestSnapsY:S,otherNodeSnapPoints:m,selectionSnapPoints:p});const x=new C(d?0:((I=f[0])==null?void 0:I.nudge)??0,h?0:((_=S[0])==null?void 0:_.nudge)??0);if(o&&FL(u)&&x.len()!==0){const A=f.length&&S.length?Math.abs(x.x)<Math.abs(x.y)?"x":"y":f.length?"x":"y",T=n.aspectRatio;A==="x"?(S.length=0,x.y=x.x/T,(u==="bottom_left"||u==="top_right")&&(x.y=-x.y)):(f.length=0,x.x=x.y*T,(u==="bottom_left"||u==="top_right")&&(x.x=-x.x))}const b=C.Add(t,x),{box:P}=re.Resize(n,r,s?b.x*2:b.x,s?b.y*2:b.y,o);s&&(P.center=n.center);const E=yb("any",P);f.length=0,S.length=0,v.x=0,v.y=0,this.collectPointSnaps({minOffset:v,nearestSnapsX:f,nearestSnapsY:S,otherNodeSnapPoints:m,selectionSnapPoints:E});const k=this.getPointSnapLines({nearestSnapsX:f,nearestSnapsY:S});return this._snapLines.set([...k]),{nudge:x}}collectPointSnaps({selectionSnapPoints:n,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of n)for(const a of t){const l=C.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);de(c)<=de(r.x)&&(de(c)<de(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!bl(a.breadthIntersection[0],a.breadthIntersection[1],n.minY,n.maxY))continue;const c=a.startEdge[0].x+a.length/2-n.center.x;if(a.length>n.width&&de(Math.abs(c))<=de(t.x)){de(Math.abs(c))<de(t.x)&&(r.length=0),t.x=Math.abs(c);const v={type:"gap_center",gap:a,nudge:c},x=r.find(({type:P})=>P==="gap_center"),b=x&&wr(a.breadthIntersection[0],a.breadthIntersection[1],x.gap.breadthIntersection[0],x.gap.breadthIntersection[1]);x&&x.gap.length>a.length&&b?r[r.indexOf(x)]=v:(!x||!b)&&r.push(v)}const d=a.startNode.pageBounds.minX-a.length,h=n.maxX,p=d-h;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 m=a.endNode.pageBounds.maxX+a.length,f=n.minX,S=m-f;de(Math.abs(S))<=de(t.x)&&(de(Math.abs(S))<de(t.x)&&(r.length=0),t.x=Math.abs(S),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:S}))}for(const a of i){if(!bl(a.breadthIntersection[0],a.breadthIntersection[1],n.minX,n.maxX))continue;const c=a.startEdge[0].y+a.length/2-n.center.y;if(a.length>n.height&&de(Math.abs(c))<=de(t.y)){de(Math.abs(c))<de(t.y)&&(o.length=0),t.y=Math.abs(c);const v={type:"gap_center",gap:a,nudge:c},x=o.find(({type:P})=>P==="gap_center"),b=x&&bl(x.gap.breadthIntersection[0],x.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);x&&x.gap.length>a.length&&b?o[o.indexOf(x)]=v:(!x||!b)&&o.push(v);continue}const d=a.startNode.pageBounds.minY-a.length,h=n.maxY,p=d-h;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 m=a.endNode.pageBounds.maxY+a.length,f=n.minY,S=m-f;de(Math.abs(S))<=de(t.y)&&(de(Math.abs(S))<de(t.y)&&(o.length=0),t.y=Math.abs(S),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:S}))}}getPointSnapLines({nearestSnapsX:n,nearestSnapsY:t}){const r={},o={};if(n.length>0){for(const s of n)if(s.type==="points"){const i=de(s.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(s.points)}}if(t.length>0){for(const s of t)if(s.type==="points"){const i=de(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:Ue(),type:"points",points:Wh(s.map(i=>C.From(i.otherPoint)).concat(s.map(i=>C.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:n,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:n.sides[0],right:n.sides[1],bottom:[n.corners[3],n.corners[2]],left:[n.corners[0],n.corners[3]]},a=[];if(t.length>0)for(const l of t){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:d,endNode:h,length:p,endEdge:m}}=l;switch(l.type){case"gap_center":{const f=(p-n.width)/2,S=wr(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:Ue(),gaps:[...go(s,d.id,f,"backward",S),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:m},...go(s,h.id,f,"forward",S)]});break}case"gap_duplicate":{const f=wr(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:Ue(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(S=>S.clone().addXY(-d.pageBounds.width,0))},{startEdge:u,endEdge:m},...go(s,h.id,p,"forward",f)]:[...go(s,d.id,p,"backward",f),{startEdge:u,endEdge:m},{startEdge:m.map(S=>S.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:d,endNode:h,length:p,endEdge:m}}=l;switch(l.type){case"gap_center":{const f=(p-n.height)/2,S=wr(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:Ue(),gaps:[...go(o,d.id,f,"backward",S),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:m},...go(o,l.gap.endNode.id,f,"forward",S)]});break}case"gap_duplicate":{const f=wr(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:Ue(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(S=>S.clone().addXY(0,-d.pageBounds.height))},{startEdge:u,endEdge:m},...go(o,h.id,p,"forward",f)]:[...go(o,d.id,p,"backward",f),{startEdge:u,endEdge:m},{startEdge:m.map(S=>S.clone().addXY(0,h.pageBounds.height)),endEdge:i.top}]})}break}}return J6(a),a}}Ci([Z],Ds.prototype,"getSnapPointsCache",1);Ci([Z],Ds.prototype,"getSnapThreshold",1);Ci([Z],Ds.prototype,"getSnappableShapes",1);Ci([Z],Ds.prototype,"getCurrentCommonAncestor",1);Ci([Z],Ds.prototype,"getSnappablePoints",1);Ci([Z],Ds.prototype,"getVisibleGaps",1);Ci([Z],Ds.prototype,"getOutlinesInPageSpace",1);function yb(e,n){const{minX:t,maxX:r,minY:o,maxY:s}=n,i=[];switch(e){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:t,y:o})}switch(e){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:o})}switch(e){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:s})}switch(e){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:t,y:s})}return i}const eN=/\r?\n|\r/g;function Sb(e){return e.replace(eN,`
43
+ `).split(`
44
+ `).map(n=>n||" ").join(`
45
+ `)}const tN={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},nN=/\s/;class rN{constructor(n){y(this,"baseElm");y(this,"measureText",(n,t)=>{var s;const r=(s=this.baseElm)==null?void 0:s.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","ltr"),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),r.style.setProperty("padding",t.padding),r.textContent=Sb(n);const o=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:o.width,h:o.height}});this.editor=n;const t=document.createElement("div");t.id="tldraw_text_measure",t.classList.add("tl-text"),t.classList.add("tl-text-measure"),t.tabIndex=-1,this.editor.getContainer().appendChild(t),this.baseElm=t}measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:t=!1}={}){const r=[],o=n.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,l=n.childNodes[0];let c=0,u=null,d=null,h=0,p=!1;for(const m of n.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const f of m.textContent??""){a.setStart(l,c),a.setEnd(l,c+f.length);const S=a.getClientRects(),v=S[S.length-1],x=v.top+i,b=v.left+s,P=v.right+s,E=nN.test(f);if(E!==d||x!==h||!u){if(u){if(t&&x!==h){p=!0;break}r.push(u)}u={box:{x:b,y:x,w:v.width,h:v.height},text:f}}else u.box.w=P-u.box.x,u.text+=f;d=E,h=x,c+=f.length}return u&&r.push(u),{spans:r,didTruncate:p}}measureTextSpans(n,t){var c;if(n==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(t.width-t.padding*2);r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("dir","ltr"),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",tN[t.textAlign]);const s=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";s&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=Sb(n);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(t.overflow==="truncate-ellipsis"&&l){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const d=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,h=d[d.length-1];return d.push({text:"…",box:{x:Math.min(h.box.x+h.box.w,t.width-t.padding-u),y:h.box.y,w:u,h:h.box.h}}),d}return r.remove(),a}}class oN{constructor(n){y(this,"raf");y(this,"isPaused",!0);y(this,"last",0);y(this,"t",0);y(this,"start",()=>{this.isPaused=!1,cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(this.tick),this.last=Date.now()});y(this,"tick",()=>{if(this.isPaused)return;const n=Date.now(),t=n-this.last;if(this.last=n,this.t+=t,this.editor.emit("frame",t),this.t<16){this.raf=requestAnimationFrame(this.tick);return}this.t-=16,this.updatePointerVelocity(t),this.editor.emit("tick",t),this.raf=requestAnimationFrame(this.tick)});y(this,"dispose",()=>{this.isPaused=!0,cancelAnimationFrame(this.raf)});y(this,"prevPoint",new C);y(this,"updatePointerVelocity",n=>{const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(n===0)return;const s=C.Sub(r,t);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new C(0,0),l=o.clone().lrp(a.mul(i/n),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),o.equals(l)||(this.editor.inputs.pointerVelocity=l)});this.editor=n,this.editor.disposables.add(this.dispose),this.start()}}var sN=Object.defineProperty,iN=Object.getOwnPropertyDescriptor,Ho=(e,n,t,r)=>{for(var o=r>1?void 0:r?iN(n,t):n,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(n,t,o):i(o))||o);return r&&o&&sN(n,t,o),o};class so{constructor(n,t){y(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(),isDarkMode:this.getIsDarkMode(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode()}}getIsDarkMode(){return this.user.userPreferences.get().isDarkMode??(this.inferDarkMode?y6():!1)}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??ir.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??ir.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??ir.name}getLocale(){return this.user.userPreferences.get().locale??ir.locale}getColor(){return this.user.userPreferences.get().color??ir.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??ir.isSnapMode}}Ho([Z],so.prototype,"getUserPreferences",1);Ho([Z],so.prototype,"getIsDarkMode",1);Ho([Z],so.prototype,"getEdgeScrollSpeed",1);Ho([Z],so.prototype,"getAnimationSpeed",1);Ho([Z],so.prototype,"getId",1);Ho([Z],so.prototype,"getName",1);Ho([Z],so.prototype,"getLocale",1);Ho([Z],so.prototype,"getColor",1);Ho([Z],so.prototype,"getIsSnapMode",1);function Cl(e){return Math.abs(e.props.bend)<8}function hp(e,n){if(n.type==="point")return;const t=e.getShape(n.boundShapeId),r=e.getShapePageTransform(t),o=e.getShapeGeometry(t),s=o instanceof Po?o.children[0].vertices:o.vertices;return{shape:t,transform:r,isClosed:o.isClosed,isExact:n.isExact,didIntersect:!1,outline:s}}function vb(e,n,t,r){if(t.type==="point")return C.From(t);const o=e.getShape(t.boundShapeId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=C.Add(s,C.MulV(t.isPrecise||r?t.normalizedAnchor:{x:.5,y:.5},i)),l=te.applyToPoint(e.getShapePageTransform(o),a);return te.applyToPoint(te.Inverse(n),l)}else return new C(0,0)}function Er(e,n){const t=e.getShapePageTransform(n);let r,o;n.props.start.type==="binding"&&n.props.end.type==="binding"&&(r=n.props.start.boundShapeId,o=n.props.end.boundShapeId);const s=Hv(e,r,o),i=vb(e,t,n.props.start,s==="double-bound"||s==="start-contains-end"),a=vb(e,t,n.props.end,s==="double-bound"||s==="end-contains-start");return{start:i,end:a}}const ta=10,pp=10,aN=10,cs={s:2,m:3.5,l:5,xl:10};function Hv(e,n,t){if(!n||!t)return"safe";if(n===t)return"double-bound";const r=e.getShapePageBounds(n),o=e.getShapePageBounds(t);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}function rc(e,n){const{start:t,end:r,arrowheadStart:o,arrowheadEnd:s}=n.props,i=Er(e,n),a=i.start.clone(),l=i.end.clone(),c=C.Med(a,l);if(C.Equals(a,l))return{isStraight:!0,start:{handle:a,point:a,arrowhead:n.props.arrowheadStart},end:{handle:l,point:l,arrowhead:n.props.arrowheadEnd},middle:c,isValid:!1,length:0};const u=C.Sub(l,a).uni(),d=hp(e,t),h=hp(e,r),p=e.getShapePageTransform(n);wb(l,i.start,p,h),wb(a,i.end,p,d);let m=0,f=0,S=0,v=0,x=ta;const b=d&&h&&d.shape===h.shape,P=d&&h?Hv(e,d.shape.id,h.shape.id):"safe";P==="safe"&&d&&h&&!b&&!d.isExact&&!h.isExact&&(h.didIntersect&&!d.didIntersect?d.isClosed&&a.setTo(l.clone().add(u.clone().mul(ta))):h.didIntersect||h.isClosed&&l.setTo(a.clone().sub(u.clone().mul(ta))));const E=C.Sub(l,a).uni(),k=!C.Equals(E,u);b||(P!=="start-contains-end"&&d&&o!=="none"&&!d.isExact&&(S=cs[n.props.size]/2+("size"in d.shape.props?cs[d.shape.props.size]/2:0),m=pp+S,x+=S),P!=="end-contains-start"&&h&&s!=="none"&&!h.isExact&&(v=cs[n.props.size]/2+("size"in h.shape.props?cs[h.shape.props.size]/2:0),f=pp+v,x+=v));const I=a.clone().add(E.clone().mul(m*(k?-1:1))),_=l.clone().sub(E.clone().mul(f*(k?-1:1)));C.Dist(I,_)<x&&(m!==0&&f!==0?(m*=-1.5,f*=-1.5):m!==0?m*=-1:f!==0&&(f*=-1)),a.add(E.clone().mul(m*(k?-1:1))),l.sub(E.clone().mul(f*(k?-1:1))),k?(d&&h&&l.setTo(C.Add(a,E.clone().mul(-ta))),c.setTo(C.Med(i.start,i.end))):c.setTo(C.Med(a,l));const T=C.Dist(a,l);return{isStraight:!0,start:{handle:i.start,point:a,arrowhead:n.props.arrowheadStart},end:{handle:i.end,point:l,arrowhead:n.props.arrowheadEnd},middle:c,isValid:T>0,length:T}}function wb(e,n,t,r){if(r===void 0||r.isExact)return;const o=te.applyToPoint(t,n),s=te.applyToPoint(t,e),i=te.applyToPoint(te.Inverse(r.transform),o),a=te.applyToPoint(te.Inverse(r.transform),s),l=r.isClosed,u=(l?Sk:yk)(i,a,r.outline);let d;if(u!==null&&(d=u.sort((m,f)=>C.Dist(m,i)-C.Dist(f,i))[0]??(l?void 0:a)),d===void 0)return;const h=te.applyToPoint(r.transform,d),p=te.applyToPoint(te.Inverse(t),h);e.setTo(p),r.didIntersect=!0}function Cg(e,n,t=0){const{arrowheadEnd:r,arrowheadStart:o}=n.props,s=n.props.bend+t;if(Math.abs(s)>Math.abs(n.props.bend*aN))return rc(e,n);const i=Er(e,n),a=C.Med(i.start,i.end),l=C.Sub(i.end,i.start).uni(),c=C.Add(a,l.per().mul(-s)),u=hp(e,n.props.start),d=hp(e,n.props.end),h=i.start.clone(),p=i.end.clone(),m=c.clone();if(C.Equals(h,p))return{isStraight:!0,start:{handle:h,point:h,arrowhead:n.props.arrowheadStart},end:{handle:p,point:p,arrowhead:n.props.arrowheadEnd},middle:m,isValid:!1,length:0};const f=n.props.bend<0,S=f?du:FE,v=xb(h,p,m),x=C.Angle(v.center,h),b=C.Angle(v.center,p),P=S(x,b);if(v.length===0||v.size===0||!Hx(v.length)||!Hx(v.size))return rc(e,n);const E=h.clone(),k=p.clone(),I=m.clone(),_=e.getShapePageTransform(n);let A=0,T=0,D=ta;if(u&&!u.isExact){const V=te.applyToPoint(_,E),X=te.applyToPoint(_,v.center),ae=te.applyToPoint(_,k),ye=te.Inverse(u.transform),Ie=te.applyToPoint(ye,V),le=te.applyToPoint(ye,X),ke=te.applyToPoint(ye,ae),{isClosed:Ae}=u,nt=Ae?Ay:ub;let Pe,ct=nt(le,v.radius,u.outline);if(ct){const Be=le.angle(Ie),Jn=le.angle(ke),Tn=S(Be,Jn);ct=ct.filter(Ye=>S(Be,le.angle(Ye))<=Tn);const $n=Tn*.25;ct.sort(Ae?(Ye,kt)=>Math.abs(S(Be,le.angle(Ye))-$n)<Math.abs(S(Be,le.angle(kt))-$n)?-1:1:(Ye,kt)=>S(Be,le.angle(Ye))<S(Be,le.angle(kt))?-1:1),Pe=ct[0]??(Ae?void 0:Ie)}else Pe=Ae?void 0:Ie;if(Pe&&(E.setTo(e.getPointInShapeSpace(n,te.applyToPoint(u.transform,Pe))),u.didIntersect=!0,o!=="none")){const Be=cs[n.props.size]/2+("size"in u.shape.props?cs[u.shape.props.size]/2:0);A=pp+Be,D+=Be}}if(d&&!d.isExact){const V=te.applyToPoint(_,E),X=te.applyToPoint(_,k),ae=te.applyToPoint(_,v.center),ye=te.Inverse(d.transform),Ie=te.applyToPoint(ye,V),le=te.applyToPoint(ye,ae),ke=te.applyToPoint(ye,X),Ae=d.isClosed,nt=Ae?Ay:ub;let Pe,ct=nt(le,v.radius,d.outline);if(ct){const Be=le.angle(Ie),Jn=le.angle(ke),Tn=S(Be,Jn),$n=Tn*.75;ct=ct.filter(Ye=>S(Be,le.angle(Ye))<=Tn),ct.sort(Ae?(Ye,kt)=>Math.abs(S(Be,le.angle(Ye))-$n)<Math.abs(S(Be,le.angle(kt))-$n)?-1:1:(Ye,kt)=>S(Be,le.angle(Ye))<S(Be,le.angle(kt))?-1:1),ct[0]?Pe=ct[0]:Pe=Ae?void 0:ke}else Pe=Ae?void 0:ke;if(Pe&&(k.setTo(e.getPointInShapeSpace(n,te.applyToPoint(d.transform,Pe))),d.didIntersect=!0,r!=="none")){const Be=cs[n.props.size]/2+("size"in d.shape.props?cs[d.shape.props.size]/2:0);T=pp+Be,D+=Be}}let L=C.Angle(v.center,E),z=C.Angle(v.center,k),j=S(L,z),F=j*v.radius;const Y=E.clone(),K=k.clone();if(A!==0){const V=A/F*(f?1:-1),X=C.FromAngle(L+j*V);Y.setTo(v.center).add(X.mul(v.radius))}if(T!==0){const V=T/F*(f?-1:1),X=C.FromAngle(z+j*V);K.setTo(v.center).add(X.mul(v.radius))}if(C.Dist(Y,K)<D&&(A!==0&&T!==0?(A*=-1.5,T*=-1.5):A!==0?A*=-2:T!==0&&(T*=-2)),A!==0){const V=A/F*(f?1:-1),X=C.FromAngle(L+j*V);E.setTo(v.center).add(X.mul(v.radius))}if(T!==0){const V=T/F*(f?-1:1),X=C.FromAngle(z+j*V);k.setTo(v.center).add(X.mul(v.radius))}if(u&&d&&!u.isExact&&!d.isExact){L=C.Angle(v.center,E),z=C.Angle(v.center,k),j=S(L,z),F=j*v.radius;const V=Hv(e,u.shape.id,d.shape.id);if(V==="double-bound"&&F<30)E.setTo(h),k.setTo(p),I.setTo(m);else if(V==="safe"&&(u&&!u.didIntersect&&E.setTo(h),d&&!d.didIntersect||S(x,L)>S(x,z))){const X=Math.min(.9,ta/F)*(f?1:-1),ae=C.FromAngle(L+j*X);k.setTo(v.center).add(ae.mul(v.radius))}}lN(v.center,v.radius,E,k,I,P,f),E.equals(k)&&(E.setTo(I.clone().addXY(1,1)),k.setTo(I.clone().subXY(1,1))),h.setTo(E),p.setTo(k),m.setTo(I);const B=xb(h,p,m);return{isStraight:!1,start:{point:h,handle:i.start,arrowhead:n.props.arrowheadStart},end:{point:p,handle:i.end,arrowhead:n.props.arrowheadEnd},middle:m,handleArc:v,bodyArc:B,isValid:B.length!==0&&isFinite(B.center.x)&&isFinite(B.center.y)}}function xb(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),o={x:((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,y:((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},s=C.Dist(o,e),i=+C.Clockwise(e,t,n),a=Math.hypot(e.y-n.y,e.x-n.x),l=Math.hypot(n.y-t.y,n.x-t.x),c=Math.hypot(t.y-e.y,t.x-e.x),u=Math.acos((l*l+c*c-a*a)/(2*l*c))*2,d=+(Te>u),h=(Re-u)*(i?1:-1),p=h*s;return{center:o,radius:s,size:h,length:p,largeArcFlag:d,sweepFlag:i}}function lN(e,n,t,r,o,s,i){const a=C.Angle(e,t),l=C.Angle(e,r);let c=du(a,l);i||(c=Re-c);const u=.5*(i?1:-1),d=C.FromAngle(a+c*u);if(o.setTo(e).add(d.mul(n)),c>s){o.rotWith(e,Te);const h=r.clone();r.setTo(t),t.setTo(h)}}const cN={wheel:"onWheel",pointer_down:"onPointerDown",pointer_move:"onPointerMove",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"};class oe{constructor(n,t){y(this,"id");y(this,"type");y(this,"shapeType");y(this,"initial");y(this,"children");y(this,"parent");y(this,"_path");y(this,"_current");y(this,"_isActive");y(this,"transition",(n,t={})=>{var s;const r=n.split(".");let o=this;for(let i=0;i<r.length;i++){const a=r[i],l=o.getCurrent(),c=(s=o.children)==null?void 0:s[a];if(!c)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(t,a),o._current.set(c),c.enter(t,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;o=c}return this});y(this,"handleEvent",n=>{var o;const t=cN[n.name],r=this.getCurrent();(o=this[t])==null||o.call(this,n),this.getCurrent()===r&&this.getIsActive()&&(r==null||r.handleEvent(n))});y(this,"enter",(n,t)=>{var r;if(this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,n,t),this.onTick&&this.editor.on("tick",this.onTick),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(n,t)}});y(this,"exit",(n,t)=>{var r,o;this._isActive.set(!1),this.onTick&&this.editor.off("tick",this.onTick),(r=this.onExit)==null||r.call(this,n,t),this.getIsActive()||(o=this.getCurrent())==null||o.exit(n,t)});y(this,"_currentToolIdMask",sn("curent tool id mask",void 0));y(this,"onWheel");y(this,"onPointerDown");y(this,"onPointerMove");y(this,"onPointerUp");y(this,"onDoubleClick");y(this,"onTripleClick");y(this,"onQuadrupleClick");y(this,"onRightClick");y(this,"onMiddleClick");y(this,"onKeyDown");y(this,"onKeyUp");y(this,"onKeyRepeat");y(this,"onCancel");y(this,"onComplete");y(this,"onInterrupt");y(this,"onEnter");y(this,"onExit");y(this,"onTick");this.editor=n;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=sn("toolIsActive"+this.id,!1),this._current=sn("toolState"+this.id,void 0),this._path=Z("toolPath"+this.id,()=>{const i=this.getCurrent();return this.id+(i?`.${i.getPath()}`:"")}),this.parent=t??{},this.parent?o&&s?(this.type="branch",this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&s&&(this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])))}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)}}y(oe,"id"),y(oe,"initial"),y(oe,"children");class eh extends oe{constructor(){super(...arguments);y(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}}})}}y(eh,"id","root"),y(eh,"initial",""),y(eh,"children",()=>[]);var uN=Object.defineProperty,dN=Object.getOwnPropertyDescriptor,ue=(e,n,t,r)=>{for(var o=r>1?void 0:r?dN(n,t):n,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(n,t,o):i(o))||o);return r&&o&&uN(n,t,o),o};class ce extends E6.EventEmitter{constructor({store:t,user:r,shapeUtils:o,tools:s,getContainer:i,initialState:a,inferDarkMode:l}){super();y(this,"store");y(this,"root");y(this,"disposables",new Set);y(this,"_tickManager",new oN(this));y(this,"snaps");y(this,"user");y(this,"textMeasure");y(this,"environment");y(this,"scribbles");y(this,"getContainer");y(this,"sideEffects");y(this,"shapeUtils");y(this,"styleProps");y(this,"history",new Y6(this,t=>{this.annotateError(t,{origin:"history.batch",willCrashApp:!0}),this.crash(t)}));y(this,"_crashingError",null);y(this,"_updateInstanceState",this.history.createCommand("updateInstanceState",(t,r)=>{const o=this.store.get(this.getInstanceState().id),s={...o,...t};return{data:{prev:o,next:s},ephemeral:!1,squashing:!1,...r}},{do:({next:t})=>{this.store.put([t])},undo:({prev:t})=>{this.store.put([t])},squash({prev:t},{next:r}){return{prev:t,next:r}}}));y(this,"_isChangingStyleTimeout",-1);y(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}},{ephemeral:!0}),this));y(this,"_setInstancePageState",this.history.createCommand("setInstancePageState",(t,r)=>({data:{prev:this.store.get(t.id??this.getCurrentPageState().id),partial:t},...r}),{do:({prev:t,partial:r})=>{this.store.update(t.id,o=>({...o,...r}))},undo:({prev:t})=>{this.store.update(t.id,()=>t)}}));y(this,"_setSelectedShapes",this.history.createCommand("setSelectedShapes",(t,r)=>{const{selectedShapeIds:o}=this.getCurrentPageState(),s=new Set(o);return t.length===s.size&&t.every(i=>s.has(i))?null:{data:{selectedShapeIds:t,prevSelectedShapeIds:o},preservesRedoStack:!0,...r}},{do:({selectedShapeIds:t})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:t}])},undo:({prevSelectedShapeIds:t})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:t}])},squash({prevSelectedShapeIds:t},{selectedShapeIds:r}){return{selectedShapeIds:r,prevSelectedShapeIds:t}}}));y(this,"_setFocusedGroupId",this.history.createCommand("setFocusedGroupId",t=>{const r=this.getCurrentPageState().focusedGroupId;if(r!==t)return{data:{prev:r,next:t},preservesRedoStack:!0,squashing:!0}},{do:({next:t})=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:t}))},undo:({prev:t})=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:t}))},squash({prev:t},{next:r}){return{prev:t,next:r}}}));y(this,"_viewportAnimation",null);y(this,"_willSetInitialBounds",!0);y(this,"_wasInset",!1);y(this,"_cameraState",sn("camera state","idle"));y(this,"_cameraStateTimeoutRemaining",0);y(this,"_lastUpdateRenderingBoundsTimestamp",Date.now());y(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,this._cameraStateTimeoutRemaining<=0&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"),this.updateRenderingBounds())});y(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=bD;const t=Date.now();this._cameraState.__unsafe__getWithoutCapture()==="idle"?(this._lastUpdateRenderingBoundsTimestamp=t,this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout)):t-this._lastUpdateRenderingBoundsTimestamp>PD&&this.updateRenderingBounds()});y(this,"_renderingBounds",sn("rendering viewport",new re));y(this,"_renderingBoundsExpanded",sn("rendering viewport expanded",new re));y(this,"renderingBoundsMargin",100);y(this,"_currentPageShapeIds");y(this,"_setCurrentPageId",this.history.createCommand("setCurrentPage",(t,r)=>{if(!this.store.has(t)){console.error("Tried to set the current page id to a page that doesn't exist.");return}return this.stopFollowingUser(),{data:{toId:t,fromId:this.getCurrentPageId()},squashing:!0,preservesRedoStack:!0,...r}},{do:({toId:t})=>{if(this.store.has(t)){if(!this.getPageStates().find(r=>r.pageId===t)){const r=Vt.create({id:Vt.createId(t)});this.store.put([r,Kt.create({id:Kt.createId(t),pageId:t})])}this.store.put([{...this.getInstanceState(),currentPageId:t}]),this.updateRenderingBounds()}},undo:({fromId:t})=>{this.store.has(t)&&(this.store.put([{...this.getInstanceState(),currentPageId:t}]),this.updateRenderingBounds())},squash:({fromId:t},{toId:r})=>({toId:r,fromId:t})}));y(this,"_updatePage",this.history.createCommand("updatePage",(t,r)=>{if(this.getInstanceState().isReadonly)return null;const o=this.getPage(t.id);return o?{data:{prev:o,partial:t},...r}:null},{do:({partial:t})=>{this.store.update(t.id,r=>({...r,...t}))},undo:({prev:t,partial:r})=>{this.store.update(r.id,()=>t)},squash(t,r){return{prev:{...t.prev,...r.prev},partial:r.partial}}}));y(this,"_createPage",this.history.createCommand("createPage",t=>{if(this.getInstanceState().isReadonly||this.getPages().length>=rp)return null;const r=this.getPages(),o=O6(t.name??"Page 1",r.map(c=>c.name));let s=t.index;(!s||r.some(c=>c.index===s))&&(s=So(r[r.length-1].index));const i=Oo.create({meta:{},...t,name:o,index:s}),a=Vt.create({id:Vt.createId(i.id)}),l=Kt.create({id:Kt.createId(i.id),pageId:i.id});return{data:{newPage:i,newTabPageState:l,newCamera:a}}},{do:({newPage:t,newTabPageState:r,newCamera:o})=>{this.store.put([t,o,r])},undo:({newPage:t,newTabPageState:r,newCamera:o})=>{this.getPages().length!==1&&this.store.remove([r.id,t.id,o.id])}}));y(this,"_deletePage",this.history.createCommand("delete_page",t=>{if(this.getInstanceState().isReadonly)return null;const r=this.getPages();if(r.length===1)return null;const o=this.getPage(t),s=this.getPageStates().filter(i=>i.pageId===t);if(!o)return null;if(t===this.getCurrentPageId()){const i=r.findIndex(l=>l.id===t),a=r[i-1]??r[i+1];this.setCurrentPage(a.id)}return{data:{id:t,deletedPage:o,deletedPageStates:s}}},{do:({deletedPage:t,deletedPageStates:r})=>{const o=this.getPages();if(o.length!==1){if(t.id===this.getCurrentPageId()){const s=o.findIndex(a=>a.id===t.id),i=o[s-1]??o[s+1];this.setCurrentPage(i.id)}this.store.remove(r.map(s=>s.id)),this.store.remove([t.id]),this.updateRenderingBounds()}},undo:({deletedPage:t,deletedPageStates:r})=>{this.store.put([t]),this.store.put(r),this.updateRenderingBounds()}}));y(this,"_createAssets",this.history.createCommand("createAssets",t=>this.getInstanceState().isReadonly||t.length<=0?null:{data:{assets:t}},{do:({assets:t})=>{this.store.put(t)},undo:({assets:t})=>{this.store.remove(t.map(r=>r.id))}}));y(this,"_updateAssets",this.history.createCommand("updateAssets",t=>this.getInstanceState().isReadonly||t.length<=0?void 0:{data:{snapshots:{},assets:t}},{do:({assets:t,snapshots:r})=>{this.store.put(t.map(o=>{const s=this.store.get(o.id);return r[o.id]=s,{...s,...o}}))},undo:({snapshots:t})=>{this.store.put(Object.values(t))}}));y(this,"_deleteAssets",this.history.createCommand("deleteAssets",t=>{if(this.getInstanceState().isReadonly||t.length<=0)return;const r=pe(t.map(o=>this.store.get(o)));return{data:{ids:t,prev:r}}},{do:({ids:t})=>{this.store.remove(t)},undo:({prev:t})=>{this.store.put(t)}}));y(this,"_parentIdsToChildIds");y(this,"_childIdsCache",new Bv);y(this,"_createShapes",this.history.createCommand("createShapes",t=>{if(this.getInstanceState().isReadonly||t.length<=0)return null;const r=this.getCurrentPageShapeIds();if(t.length+r.size>fo){rd(this);return}return t.length===0?null:{data:{currentPageId:this.getCurrentPageId(),partials:t.map(s=>s.id?s:{...s,id:We()})}}},{do:({partials:t})=>{var a,l;const r=this.getFocusedGroupId(),o=this.getCurrentPageShapesSorted();t=t.map(c=>{if(!c.parentId||!(this.store.has(c.parentId)||t.some(u=>u.id===c.parentId))){let u=this.getFocusedGroupId();for(let h=o.length-1;h>=0;h--){const p=o[h];if(this.getShapeUtil(p).canReceiveNewChildrenOfType(p,c.type)&&this.isPointInShape(p,{x:c.x??0,y:c.y??0},{margin:0,hitInside:!0})){u=p.id;break}}const d=c.parentId;if(u===c.id&&(u=r),u!==d&&(c={...c},c.parentId=u,Rn(u))){const h=this.getPointInShapeSpace(this.getShape(u),{x:c.x??0,y:c.y??0});c.x=h.x,c.y=h.y,c.rotation=-this.getShapePageTransform(u).rotation()+(c.rotation??0)}}return c});const s=new Map,i=[];for(const c of t){const u=this.getShapeUtil(c);let d=c.index;if(!d){const f=c.parentId??r;s.has(f)||s.set(f,this.getHighestIndexForParent(f)),d=s.get(f),s.set(f,So(d))}const h=u.getDefaultProps();for(const[f,S]of this.styleProps[c.type])h[S]=this.getStyleForNextShape(f);let p=this.store.schema.types.shape.create({...c,index:d,opacity:c.opacity??this.getInstanceState().opacityForNextShape,parentId:c.parentId??r,props:"props"in c?{...h,...c.props}:h});if(p.index===void 0)throw Error("no index!");const m=(l=(a=this.getShapeUtil(p)).onBeforeCreate)==null?void 0:l.call(a,p);m&&(p=m),i.push(p)}i.forEach(c=>{c.meta={...this.getInitialMetaForShape(c),...c.meta}}),this.store.put(i)},undo:({partials:t})=>{this.store.remove(t.map(r=>r.id))}}));y(this,"animatingShapes",new Map);y(this,"_updateShapes",this.history.createCommand("updateShapes",(t,r)=>{if(this.getInstanceState().isReadonly)return null;const o=pe(t),s=Object.fromEntries(pe(o.map(({id:l})=>this.getShape(l))).map(l=>[l.id,l]));if(o.length<=0)return null;const i=pe(o.map(l=>{const c=s[l.id];return c?El(c,l):null})),a=Object.fromEntries(i.map(l=>[l.id,l]));return{data:{snapshots:s,updates:a},...r}},{do:({updates:t})=>{var o,s;const r=Object.values(t);for(let i=0;i<r.length;i++){const a=r[i],l=this.store.get(a.id);if(!l)continue;const c=(s=(o=this.getShapeUtil(a)).onBeforeUpdate)==null?void 0:s.call(o,l,a);c&&(r[i]=c)}this.store.put(r)},undo:({snapshots:t})=>{this.store.put(Object.values(t))},squash(t,r){return{snapshots:{...r.snapshots,...t.snapshots},updates:{...t.updates,...r.updates}}}}));y(this,"_deleteShapes",this.history.createCommand("delete_shapes",t=>{if(this.getInstanceState().isReadonly||t.length===0)return null;const r=[...this.getCurrentPageState().selectedShapeIds],o=new Set(t);for(const c of t)this.visitDescendants(c,u=>{o.add(u)});const s=[...o],i=this._getArrowBindingsIndex().get(),a=pe(s.flatMap(c=>{const u=this.getShape(c),d=i[c];return d&&d.length>0?d.map(({arrowId:h})=>this.getShape(h)).concat(u):u})),l=r.filter(c=>!o.has(c));return{data:{deletedIds:s,snapshots:a,prevSelectedShapeIds:r,postSelectedShapeIds:l}}},{do:({deletedIds:t,postSelectedShapeIds:r})=>{this.store.remove(t),this.store.update(this.getCurrentPageState().id,o=>({...o,selectedShapeIds:r}))},undo:({snapshots:t,prevSelectedShapeIds:r})=>{this.store.put(t),this.store.update(this.getCurrentPageState().id,o=>({...o,selectedShapeIds:r}))}}));y(this,"_selectionSharedStyles",Z("_selectionSharedStyles",()=>{const t=this.getSelectedShapes(),r=new Oy;for(const o of t)this._extractSharedStyles(o,r);return r}));y(this,"externalAssetContentHandlers",{file:null,url:null});y(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});y(this,"inputs",{originPagePoint:new C,originScreenPoint:new C,previousPagePoint:new C,previousScreenPoint:new C,currentPagePoint:new C,currentScreenPoint:new C,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 C});y(this,"_clickManager",new K6(this));y(this,"_prevCursor","default");y(this,"_shiftKeyTimeout",-1);y(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"})});y(this,"_altKeyTimeout",-1);y(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"})});y(this,"_ctrlKeyTimeout",-1);y(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"})});y(this,"_restoreToolId","select");y(this,"_pinchStart",1);y(this,"_didPinch",!1);y(this,"_selectedShapeIdsAtPointerDown",[]);y(this,"capturedPointerId",null);y(this,"dispatch",t=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=t;return this.batch(()=>{if(t.type==="misc"){(t.name==="cancel"||t.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}}))),this.root.handleEvent(t);return}t.shiftKey?(clearInterval(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!t.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=setTimeout(this._setShiftKeyTimeout,150)),t.altKey?(clearInterval(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!t.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=setTimeout(this._setAltKeyTimeout,150)),t.ctrlKey?(clearInterval(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!t.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,originScreenPoint:i,currentPagePoint:a,currentScreenPoint:l}=r;switch(r.isPointing||(r.isDragging=!1),o){case"pinch":{if(!this.getInstanceState().canMoveCamera)return;switch(this._updateInputsFromEvent(t),t.name){case"pinch_start":{if(r.isPinching)return;r.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds()),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{delta:{x:c,y:u}}=t,{screenBounds:d}=this.store.unsafeGetWithoutCapture($t),{x:h,y:p,z:m=1}=C.SubXY(t.point,d.x,d.y),{x:f,y:S,z:v}=this.getCamera(),x=Math.min(os,Math.max(xl,m));this.setCamera({x:f+c/v-h/v+h/x,y:S+u/v-p/v+p/x,z:x});return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:c}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown,{squashing:!0}),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,requestAnimationFrame(()=>{this._didPinch||this.setSelectedShapes(c,{squashing:!0})}));return}}}case"wheel":{if(!this.getInstanceState().canMoveCamera)return;if(this._updateInputsFromEvent(t),!this.getIsMenuOpen()){if(r.ctrlKey){const{x:c,y:u}=this.inputs.currentScreenPoint,{x:d,y:h,z:p}=this.getCamera(),m=Math.min(os,Math.max(xl,p+(t.delta.z??0)*p));this.setCamera({x:d+(c/m-c)-(c/p-c),y:h+(u/m-u)-(u/p-u),z:m});return}this.pan(t.delta),!r.isDragging&&r.isPointing&&s.dist(a)>(this.getInstanceState().isCoarsePointer?ky:xc)/this.getZoomLevel()&&(r.isDragging=!0)}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(t);const{isPen:c}=t;switch(t.name){case"pointer_down":{if(this.clearOpenMenus(),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),t.button===0&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,this.getInstanceState().isPenMode){if(!c)return}else c&&this.updateInstanceState({isPenMode:!0});if(t.button===5?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===1&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0),this.inputs.isPanning)return this.stopCameraAnimation(),this.updateInstanceState({cursor:{type:"grabbing",rotation:0}}),this;i.setTo(l),s.setTo(a);break}case"pointer_move":{if(!c&&this.getInstanceState().isPenMode)return;if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:u,previousScreenPoint:d}=this.inputs;this.pan(C.Sub(u,d));return}!r.isDragging&&r.isPointing&&s.dist(a)>(this.getInstanceState().isCoarsePointer?ky:xc)/this.getZoomLevel()&&(r.isDragging=!0);break}case"pointer_up":{if(r.buttons.delete(t.button),r.isPointing=!1,r.isDragging=!1,this.getIsMenuOpen()||!c&&this.getInstanceState().isPenMode)return;this.capturedPointerId===t.pointerId&&(this.capturedPointerId=null,t.button=0),r.isPanning?t.button===1?this.inputs.keys.has(" ")?(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:qd}),this.updateInstanceState({cursor:{type:"grab",rotation:0}})):(r.isPanning=!1,this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:qd}),this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}})):t.button===0&&(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:qd}),this.updateInstanceState({cursor:{type:"grab",rotation:0}})):t.button===5&&(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.ctrlKey&&t.code==="Space"&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,this.updateInstanceState({cursor:{type:this.inputs.isPointing?"grabbing":"grab",rotation:0}}));break}case"key_up":{r.keys.delete(t.code),t.code==="Space"&&!this.inputs.buttons.has(1)&&(this.inputs.isPanning=!1,this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}}));break}}break}}if(t.type==="pointer"&&(t.button===1?t.name="middle_click":t.button===2&&(t.name="right_click"),t.isPen===this.getInstanceState().isPenMode))switch(t.name){case"pointer_down":{const c=this._clickManager.transformPointerDownEvent(t);if(t.name!==c.name){this.root.handleEvent(t),this.emit("event",t),this.root.handleEvent(c),this.emit("event",c);return}break}case"pointer_up":{const c=this._clickManager.transformPointerUpEvent(t);if(t.name!==c.name){this.root.handleEvent(t),this.emit("event",t),this.root.handleEvent(c),this.emit("event",c);return}break}case"pointer_move":{this._clickManager.handleMove();break}}this.root.handleEvent(t),this.emit("event",t)}),this});this.store=t,this.snaps=new Ds(this),this.user=new so(r??gk(),l??!1),this.getContainer=i??(()=>document.body),this.textMeasure=new rN(this);class c extends eh{}y(c,"initial",a??""),this.root=new c(this),this.root.children={};const u=xk(o),d=new Set(Object.keys(t.schema.types.shape.migrations.subTypeMigrations));for(const P of u){if(!d.has(P.type))throw Error(`Editor and store have different shapes: "${P.type}" was passed into the editor but not the schema`);d.delete(P.type)}if(d.size>0)throw Error(`Editor and store have different shapes: "${[...d][0]}" is present in the store schema but not provided to the editor`);const h={},p={},m=new Map;for(const P of u){const E=new P(this);h[P.type]=E;const k=_E(P.props??{});p[P.type]=k;for(const I of k.keys())if(!m.has(I.id))m.set(I.id,I);else if(m.get(I.id)!==I)throw Error(`Multiple style props with id "${I.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=h,this.styleProps=p;for(const P of[...s]){if(Jp(this.root.children,P.id))throw Error(`Can't override tool with id "${P.id}"`);this.root.children[P.id]=new P(this,this.root)}this.environment=new W6(this),this.scribbles=new X6(this);const f=new Set,S=P=>{var H;const E=this.getShape(P);if(!E)return;const{start:k,end:I}=E.props,_=k.type==="binding"?this.getShape(k.boundShapeId):void 0,A=I.type==="binding"?this.getShape(I.boundShapeId):void 0,T=this.getAncestorPageId(E);if(!T)return;let D;if(_&&A)D=this.findCommonAncestor([_,A])??T;else if(_||A){const B=(H=_||A)==null?void 0:H.parentId;B&&B===E.parentId?D=E.parentId:D=T}else return;D&&D!==E.parentId&&this.reparentShapes([P],D);const L=this.getShape(P);if(!L)throw Error("no reparented arrow");const z=this.getShapeNearestSibling(L,_),j=this.getShapeNearestSibling(L,A);let F;if(z&&j)F=z.index>j.index?z:j;else if(z&&!j)F=z;else if(j&&!z)F=j;else return;let Y;const K=this.getSortedChildIdsForParent(F.parentId).map(B=>this.getShape(B)).filter(B=>B.index>F.index);if(K.length){const B=K.find(V=>V.type!=="arrow");if(L.index>F.index&&(!B||L.index<B.index))return;Y=nc(F.index,K[0].index)}else Y=So(F.index);Y!==L.index&&this.updateShapes([{id:P,type:"arrow",index:Y}])},v=(P,E)=>{const{x:k,y:I}=Er(this,P)[E];this.store.put([{...P,props:{...P.props,[E]:{type:"point",x:k,y:I}}}])},x=P=>{for(const E of["start","end"]){const k=P.props[E];if(k.type!=="binding")continue;const I=this.getShape(k.boundShapeId),_=this.getAncestorPageId(P)===this.getAncestorPageId(I);(!I||!_)&&v(P,E)}S(P.id)},b=(P,E)=>{let k=null;const I=P.selectedShapeIds.filter(T=>!E.has(T));I.length!==P.selectedShapeIds.length&&(k||(k={...P}),k.selectedShapeIds=I);const _=P.erasingShapeIds.filter(T=>!E.has(T));_.length!==P.erasingShapeIds.length&&(k||(k={...P}),k.erasingShapeIds=_),P.hoveredShapeId&&E.has(P.hoveredShapeId)&&(k||(k={...P}),k.hoveredShapeId=null),P.editingShapeId&&E.has(P.editingShapeId)&&(k||(k={...P}),k.editingShapeId=null);const A=P.hintingShapeIds.filter(T=>!E.has(T));return A.length!==P.hintingShapeIds.length&&(k||(k={...P}),k.hintingShapeIds=A),P.focusedGroupId&&E.has(P.focusedGroupId)&&(k||(k={...P}),k.focusedGroupId=null),k};if(this.sideEffects=new q6(this),this.sideEffects.registerBatchCompleteHandler(()=>{var P;for(const E of f){f.delete(E);const k=this.getShape(E);if(!k)continue;const I=this.getShapeUtil(k),_=(P=I.onChildrenChange)==null?void 0:P.call(I,k);_!=null&&_.length&&this.updateShapes(_,{squashing:!0})}this.emit("update")}),this.sideEffects.registerBeforeDeleteHandler("shape",P=>{P.parentId&&Rn(P.parentId)&&f.add(P.parentId);const E=this._getArrowBindingsIndex().get()[P.id];if(E!=null&&E.length)for(const{arrowId:_,handleId:A}of E){const T=this.getShape(_);T&&v(T,A)}const k=new Set([P.id]),I=pe(this.getPageStates().map(_=>b(_,k)));I.length&&this.store.put(I)}),this.sideEffects.registerBeforeDeleteHandler("page",P=>{var _;if(this.getInstanceState().currentPageId!==P.id)return;const E=(_=this.getPages().find(A=>A.id!==P.id))==null?void 0:_.id;if(!E)return;this.store.put([{...this.getInstanceState(),currentPageId:E}]);const k=Vt.createId(P.id),I=Kt.createId(P.id);this.store.remove([k,I])}),this.sideEffects.registerAfterChangeHandler("shape",(P,E)=>{if(this.isShapeOfType(E,"arrow")&&x(E),P.parentId!==E.parentId){const k=I=>{const _=this._getArrowBindingsIndex().get()[I];if(_!=null&&_.length)for(const A of _)S(A.arrowId)};k(E.id),this.visitDescendants(E.id,k)}if(P.parentId!==E.parentId&&gn(E.parentId)){const k=new Set([P.id]);this.visitDescendants(P.id,I=>{k.add(I)});for(const I of this.getPageStates()){if(I.pageId===E.parentId)continue;const _=b(I,k);_&&this.store.put([_])}}P.parentId&&Rn(P.parentId)&&f.add(P.parentId),E.parentId!==P.parentId&&Rn(E.parentId)&&f.add(E.parentId)}),this.sideEffects.registerAfterChangeHandler("instance_page_state",(P,E)=>{if((P==null?void 0:P.selectedShapeIds)!==(E==null?void 0:E.selectedShapeIds)){const k=E.selectedShapeIds.filter(_=>{var T,D;let A=(T=this.getShape(_))==null?void 0:T.parentId;for(;Rn(A);){if(E.selectedShapeIds.includes(A))return!1;A=(D=this.getShape(A))==null?void 0:D.parentId}return!0});let I=null;if(k.length>0){const _=this.findCommonAncestor(pe(k.map(A=>this.getShape(A))),A=>this.isShapeOfType(A,"group"));_&&(I=_)}else E!=null&&E.focusedGroupId&&(I=E.focusedGroupId);(k.length!==E.selectedShapeIds.length||I!==E.focusedGroupId)&&this.store.put([{...E,selectedShapeIds:k,focusedGroupId:I??null}])}}),this.sideEffects.registerAfterCreateHandler("shape",P=>{this.isShapeOfType(P,"arrow")&&x(P)}),this.sideEffects.registerAfterCreateHandler("page",P=>{const E=Vt.createId(P.id),k=Kt.createId(P.id);this.store.has(E)||this.store.put([Vt.create({id:E})]),this.store.has(k)||this.store.put([Kt.create({id:k,pageId:P.id})])}),this._currentPageShapeIds=H6(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=U6(this.store),this.disposables.add(this.store.listen(P=>{this.emit("change",P)})),this.store.ensureStoreIsUsable(),this._setInstancePageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]},{ephemeral:!0}),a&&this.root.children[a]===void 0)throw Error(`No state found for initialState "${a}".`);this.root.enter(void 0,"initial"),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.updateRenderingBounds(),requestAnimationFrame(()=>{this._tickManager.start()})}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear()}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=ai(this.shapeUtils,r);return Io(o,`No shape util found for type "${r}"`),o}undo(){return this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(t,r,o){return this.history.mark(t,r,o),this}bail(){return this.history.bail(),this}bailToMark(t){return this.history.bailToMark(t),this}batch(t){return this.history.batch(t),this}_getArrowBindingsIndex(){return B6(this)}getArrowsBoundTo(t){return this._getArrowBindingsIndex().get()[t]||ko}getArrowInfoCache(){return this.store.createComputedCache("arrow infoCache",t=>Cl(t)?rc(this,t):Cg(this,t))}getArrowInfo(t){const r=typeof t=="string"?t:t.id;return this.getArrowInfoCache().get(r)}annotateError(t,{origin:r,willCrashApp:o,tags:s,extras:i}){const a=this.createErrorAnnotations(r,o);return xv(t,{tags:{...a.tags,...s},extras:{...a.extras,...i}}),o&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(t,r){try{const o=this.getEditingShapeId();return{tags:{origin:t,willCrashApp:r},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:o?this.getShape(o):void 0,inputs:this.inputs}}}catch{return{tags:{origin:t,willCrashApp:r},extras:{}}}}getCrashingError(){return this._crashingError}crash(t){return this._crashingError=t,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:t}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(t){const r=t.split(".").reverse();let o=this.root;for(;r.length>0;){const s=r.pop();if(!s)return!0;const i=o.getCurrent();if((i==null?void 0:i.id)===s){if(r.length===0)return!0;o=i;continue}else return!1}return!1}isInAny(...t){return t.some(r=>this.isIn(r))}setCurrentTool(t,r={}){return this.root.transition(t,r),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const t=this.getCurrentTool();return t?t.getCurrentToolIdMask()??t.id:""}getStateDescendant(t){var s;const r=t.split(".").reverse();let o=this.root;for(;r.length>0;){const i=r.pop();if(!i)return o;const a=(s=o.children)==null?void 0:s[i];if(!a)return;o=a}return o}getDocumentSettings(){return this.store.get(Ey)}updateDocumentSettings(t){return this.store.put([{...this.getDocumentSettings(),...t}]),this}getInstanceState(){return this.store.get($t)}updateInstanceState(t,r){return this._updateInstanceState(t,{ephemeral:!0,squashing:!0,...r}),t.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),t.isChangingStyle===!0&&(this._isChangingStyleTimeout=setTimeout(()=>{this.updateInstanceState({isChangingStyle:!1})},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 Kt.createId(this.getCurrentPageId())}updateCurrentPageState(t,r){return this._setInstancePageState(t,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:t}=this.getCurrentPageState();return pe(t.map(r=>this.store.get(r)))}setSelectedShapes(t,r){const o=t.map(s=>typeof s=="string"?s:s.id);return this._setSelectedShapes(o,r),this}isAncestorSelected(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null,o=this.getShape(r);if(!o)return!1;const s=this.getSelectedShapeIds();return!!this.findShapeAncestor(o,i=>s.includes(i.id))}select(...t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.setSelectedShapes(r),this}deselect(...t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=this.getSelectedShapeIds();return o.length>0&&r.length>0&&this.setSelectedShapes(o.filter(s=>!r.includes(s))),this}selectAll(){const t=this.getSortedChildIdsForParent(this.getCurrentPageId());return t.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(t)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShape(){const t=this.getSelectedShapes();return t.length===1?t[0]:null}getSelectionPageBounds(){const t=this.getCurrentPageState().selectedShapeIds;return t.length===0?null:re.Common(pe(t.map(r=>this.getShapePageBounds(r))))}getSelectionRotation(){const t=this.getSelectedShapeIds();if(t.length===0)return 0;if(t.length===1)return this.getShapePageTransform(this.getSelectedShapeIds()[0]).rotation();const r=t.map(o=>this.getShapePageTransform(o).rotation());return r.every(o=>Math.abs(o-r[0])<Math.PI/180)?this.getShapePageTransform(t[0]).rotation():0}getSelectionRotatedPageBounds(){const t=this.getSelectedShapeIds();if(t.length===0)return;const r=this.getSelectionRotation();if(r===0)return this.getSelectionPageBounds();if(t.length===1){const s=this.getShapeGeometry(t[0]).bounds.clone(),i=this.getShapePageTransform(t[0]);return s.point=i.applyToPoint(s.point),s}const o=re.FromPoints(this.getSelectedShapeIds().flatMap(s=>{const i=this.getShapePageTransform(s);return i?i.applyToPoints(this.getShapeGeometry(s).vertices):[]}).map(s=>C.Rot(s,-r)));return o.point=o.point.rot(r),o}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._setFocusedGroupId(r),this)}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._setInstancePageState({editingShapeId:r}),this}this._setInstancePageState({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},{ephemeral:!0}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const t=this.getHintingShapeIds();return pe(t.map(r=>this.getShape(r)))}setHintingShapes(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:Wh(r)},{ephemeral:!0}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const t=this.getErasingShapeIds();return pe(t.map(r=>this.getShape(r)))}setErasingShapes(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id);r.sort();const o=this.getErasingShapeIds();if(r.length===o.length){for(let s=0;s<r.length;s++)if(r[s]!==o[s]){this._setInstancePageState({erasingShapeIds:r},{ephemeral:!0});break}}else this._setInstancePageState({erasingShapeIds:r},{ephemeral:!0});return this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==this.getCroppingShapeId())if(!r)this.updateCurrentPageState({croppingShapeId:null});else{const o=this.getShape(r),s=this.getShapeUtil(o);o&&s.canCrop(o)&&this.updateCurrentPageState({croppingShapeId:r})}return this}getCameraId(){return Vt.createId(this.getCurrentPageId())}getCamera(){return this.store.get(this.getCameraId())}getZoomLevel(){return this.getCamera().z}_setCamera(t){const r=this.getCamera();return r.x===t.x&&r.y===t.y&&r.z===t.z?this:(this.batch(()=>{this.store.put([{...r,...t}]);const{currentScreenPoint:o}=this.inputs,{screenBounds:s}=this.store.unsafeGetWithoutCapture($t);this.dispatch({type:"pointer",target:"canvas",name:"pointer_move",point:C.AddXY(o,s.x,s.y),pointerId:Bx.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1}),this._tickCameraState()}),this)}setCamera(t,r){const o=Number.isFinite(t.x)?t.x:0,s=Number.isFinite(t.y)?t.y:0,i=Number.isFinite(t.z)?t.z:this.getZoomLevel();if(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),r){const{width:a,height:l}=this.getViewportScreenBounds();return this._animateToViewport(new re(-o,-s,a/i,l/i),r)}else this._setCamera({x:o,y:s,z:i});return this}centerOnPoint(t,r){if(!this.getInstanceState().canMoveCamera)return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera({x:-(t.x-o/2),y:-(t.y-s/2),z:this.getCamera().z},r),this}zoomToContent(){const t=this.getSelectionPageBounds()??this.getCurrentPageBounds();return t&&this.zoomToBounds(t,Math.min(1,this.getZoomLevel()),{duration:220}),this}zoomToFit(t){if(!this.getInstanceState().canMoveCamera)return this;const r=[...this.getCurrentPageShapeIds()];if(r.length<=0)return this;const o=re.Common(pe(r.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(o,void 0,t),this}resetZoom(t=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera(),{x:a,y:l}=t;return this.setCamera({x:o+(a/1-a)-(a/i-a),y:s+(l/1-l)-(l/i-l),z:1},r),this}zoomIn(t=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();let a=os;for(let u=1;u<Ni.length;u++){const d=Ni[u-1],h=Ni[u];if(!(h-i<=(h-d)/2)){a=h;break}}const{x:l,y:c}=t;return this.setCamera({x:o+(l/a-l)-(l/i-l),y:s+(c/a-c)-(c/i-c),z:a},r),this}zoomOut(t=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();let a=xl;for(let u=Ni.length-1;u>0;u--){const d=Ni[u-1],h=Ni[u];if(!(h-i>=(h-d)/2)){a=d;break}}const{x:l,y:c}=t;return this.setCamera({x:o+(l/a-l)-(l/i-l),y:s+(c/a-c)-(c/i-c),z:a},r),this}zoomToSelection(t){if(!this.getInstanceState().canMoveCamera)return this;const r=this.getSelectionPageBounds();return r?(this.zoomToBounds(r,Math.max(1,this.getZoomLevel()),t),this):this}panZoomIntoView(t,r){if(!this.getInstanceState().canMoveCamera)return this;if(t.length<=0)return this;const o=re.Common(pe(t.map(i=>this.getShapePageBounds(i)))),s=this.getViewportPageBounds();if(s.h<o.h||s.w<o.w)return this.zoomToBounds(o,this.getCamera().z,r),this;{const i=this.getViewportPageBounds().clone().expandBy(-32/this.getZoomLevel());let a=0,l=0;i.maxY<o.maxY?l=i.maxY-o.maxY:i.minY>o.minY&&(l=i.minY-o.minY),i.maxX<o.maxX?a=i.maxX-o.maxX:i.minX>o.minX&&(a=i.minX-o.minX);const c=this.getCamera();this.setCamera({x:c.x+a,y:c.y+l,z:c.z},r)}return this}zoomToBounds(t,r,o){if(!this.getInstanceState().canMoveCamera)return this;const s=this.getViewportScreenBounds(),i=Math.min(256,s.width*.28);let a=or(Math.min((s.width-i)/t.width,(s.height-i)/t.height),xl,os);return r!==void 0&&(a=Math.min(r,a)),this.setCamera({x:-t.minX+(s.width-t.width*a)/2/a,y:-t.minY+(s.height-t.height*a)/2/a,z:a},o),this}pan(t,r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();return this.setCamera({x:o+t.x/i,y:s+t.y/i,z:i},r),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(t){if(!this._viewportAnimation)return;const r=()=>{this.removeListener("tick",this._animateViewport),this.removeListener("stop-camera-animation",r),this._viewportAnimation=null};this.once("stop-camera-animation",r),this._viewportAnimation.elapsed+=t;const{elapsed:o,easing:s,duration:i,start:a,end:l}=this._viewportAnimation;if(o>i){this._setCamera({x:-l.x,y:-l.y,z:this.getViewportScreenBounds().width/l.width}),r();return}const c=i-o,u=s(1-c/i),d=a.minX+(l.minX-a.minX)*u,h=a.minY+(l.minY-a.minY)*u,p=a.maxX+(l.maxX-a.maxX)*u;this._setCamera({x:-d,y:-h,z:this.getViewportScreenBounds().width/(p-d)})}_animateToViewport(t,r={}){const{duration:o=0,easing:s=qt.easeInOutCubic}=r,i=this.user.getAnimationSpeed(),a=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),o===0||i===0?this._setCamera({x:-t.x,y:-t.y,z:a.width/t.width}):(this._viewportAnimation={elapsed:0,duration:o/i,easing:s,start:a.clone(),end:t.clone()},this.addListener("tick",this._animateViewport),this)}slideCamera(t={}){if(!this.getInstanceState().canMoveCamera)return this;if(this.stopCameraAnimation(),this.user.getAnimationSpeed()===0)return this;const{speed:o,friction:s,direction:i,speedThreshold:a=.01}=t;let l=Math.min(o,1);const c=()=>{this.removeListener("tick",u),this.removeListener("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=d=>{const{x:h,y:p,z:m}=this.getCamera(),f=C.Mul(i,l*d/m);l*=1-s,l<a?c():this._setCamera({x:h+f.x,y:p+f.y,z:m})};return this.addListener("tick",u),this}animateToUser(t){const o=[...this.store.query.records("instance_presence",()=>({userId:{eq:t}})).get()].sort((s,i)=>s.lastActivityTimestamp-i.lastActivityTimestamp).pop();return o?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const s=o.currentPageId===this.getCurrentPageId();s||this.setCurrentPage(o.currentPageId);const i=s?{duration:500}:void 0;this.centerOnPoint(o.cursor,i);const{highlightedUserIds:a}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...a,t]}),setTimeout(()=>{const l=[...this.getInstanceState().highlightedUserIds],c=l.indexOf(t);c<0||(l.splice(c,1),this.updateInstanceState({highlightedUserIds:l}))},RE)}),this):this}animateToShape(t,r=vD){if(!this.getInstanceState().canMoveCamera)return this;const o=this.getViewportScreenBounds().clone().expandBy(-32),s=o.width/o.height,i=this.getShapePageBounds(t);if(!i)return this;const a=i.width/i.height,l=i.clone(),c=i.width/o.width;return l.width+=(o.minX+o.maxX)*c,l.height+=(o.minY+o.maxY)*c,l.x-=o.minX*c,l.y-=o.minY*c,a>s?(l.height=i.width/s,l.y-=(l.height-i.height)/2):(l.width=i.height*s,l.x-=(l.width-i.width)/2),this._animateToViewport(l,r)}updateViewportScreenBounds(t=!1){const r=this.getContainer();if(!r)return this;const o=r.getBoundingClientRect(),s=new re(o.left||o.x,o.top||o.y,Math.max(o.width,1),Math.max(o.height,1)),i=[s.minY!==0,document.body.scrollWidth!==s.maxX,document.body.scrollHeight!==s.maxY,s.minX!==0],a=s.equals(this.getViewportScreenBounds()),{_willSetInitialBounds:l}=this;if(a)this._willSetInitialBounds=!1;else if(l)this._willSetInitialBounds=!1,this.updateInstanceState({screenBounds:s.toJson(),insets:i},{squashing:!0,ephemeral:!0});else if(t&&!this.getInstanceState().followingUserId){const c=this.getViewportPageCenter();this.updateInstanceState({screenBounds:s.toJson(),insets:i},{squashing:!0,ephemeral:!0}),this.centerOnPoint(c)}else this.updateInstanceState({screenBounds:s.toJson(),insets:i},{squashing:!0,ephemeral:!0});return this._tickCameraState(),this.updateRenderingBounds(),this}getViewportScreenBounds(){const{x:t,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new re(t,r,o,s)}getViewportScreenCenter(){const t=this.getViewportScreenBounds();return new C(t.midX-t.minX,t.midY-t.minY)}getViewportPageBounds(){const{w:t,h:r}=this.getViewportScreenBounds(),{x:o,y:s,z:i}=this.getCamera();return new re(-o,-s,t/i,r/i)}getViewportPageCenter(){return this.getViewportPageBounds().center}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture($t),{x:o,y:s,z:i=1}=this.getCamera();return{x:(t.x-r.x)/i-o,y:(t.y-r.y)/i-s,z:t.z??.5}}pageToScreen(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture($t),{x:o,y:s,z:i=1}=this.getCamera();return{x:(t.x+o)*i+r.x,y:(t.y+s)*i+r.y,z:t.z??.5}}startFollowingUser(t){const r=this.store.query.records("instance_presence",()=>({userId:{eq:t}})),o=this.user.getId();if(o||console.warn("You should set the userId for the current instance before following a user"),r.get().some(l=>l.followingUserId===o))return this;br(()=>{this.stopFollowingUser(),this.updateInstanceState({followingUserId:t},{ephemeral:!0})});const s=()=>{this.removeListener("frame",a),this.removeListener("stop-following",s)};let i=!1;const a=()=>{const l=[...r.get()].sort((z,j)=>z.lastActivityTimestamp-j.lastActivityTimestamp).pop();if(!l){this.stopFollowingUser();return}const c=l.currentPageId===this.getCurrentPageId(),u=c?dD:1;if(!c){this.stopFollowingUser(),this.setCurrentPage(l.currentPageId),this.startFollowingUser(t);return}const{center:d,width:h,height:p}=this.getViewportPageBounds(),m=re.From(l.screenBounds),f=m.width/l.camera.z,S=m.height/l.camera.z,v=new C(f/2-l.camera.x,S/2-l.camera.y),x=l.followingUserId===o,b=h+(f-h)*u,P=p+(S-p)*u,E=x?p/P:Math.min(h/b,p/P),k=or(this.getCamera().z*E,xl,os),I=this.getViewportScreenBounds().w/k,_=this.getViewportScreenBounds().h/k,A=v.sub(d),T=C.Add(d,C.Mul(A,u)),D=C.Sub(T,d).len(),L=Math.abs(k-this.getCamera().z);if(D<hD&&L<fD){i=!0;return}i&&D<pD&&L<gD||(i=!1,this.stopCameraAnimation(),this._setCamera({x:-(T.x-I/2),y:-(T.y-_/2),z:k}))};return this.once("stop-following",s),this.addListener("frame",a),this}stopFollowingUser(){return this.updateInstanceState({followingUserId:null},{ephemeral:!0}),this.emit("stop-following"),this}getCameraState(){return this._cameraState.get()}getUnorderedRenderingShapes(t){const r=[];let o=fo*2,s=fo;const i=this.getEditingShapeId(),a=this.getSelectedShapeIds(),l=this.getErasingShapeIds(),c=this.getRenderingBoundsExpanded(),u=Number.isFinite(this.renderingBoundsMargin),d=(h,p,m)=>{const f=this.getShape(h);if(!f)return;p*=f.opacity;let S=!1,v=!1;const x=this.getShapeUtil(f),b=this.getShapeMaskedPageBounds(h);t&&(v=!m&&l.includes(h),v&&(p*=.32),S=u&&x.canUnmount(f)&&i!==h&&(b===void 0||!c.includes(b)&&!a.includes(h))),r.push({id:h,shape:f,util:x,index:o,backgroundIndex:s,opacity:p,isCulled:S,maskedPageBounds:b}),o+=1,s+=1;const P=this.getSortedChildIdsForParent(h);if(!P.length)return;let E=null;x.providesBackgroundForChildren(f)&&(E=s,s=o,o+=fo);for(const k of P)d(k,p,m||v);E!==null&&(s=E)};for(const h of this.getSortedChildIdsForParent(this.getCurrentPageId()))d(h,1,!1);return r}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(kR)}getRenderingBounds(){return this._renderingBounds.get()}getRenderingBoundsExpanded(){return this._renderingBoundsExpanded.get()}updateRenderingBounds(){const t=this.getViewportPageBounds();return t.equals(this._renderingBounds.__unsafe__getWithoutCapture())?this:(this._renderingBounds.set(t.clone()),Number.isFinite(this.renderingBoundsMargin)?this._renderingBoundsExpanded.set(t.clone().expandBy(this.renderingBoundsMargin/this.getZoomLevel())):this._renderingBoundsExpanded.set(t),this)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(Wt)}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()}getPageShapeIds(t){const r=typeof t=="string"?t:t.id,o=this.store.query.exec("shape",{parentId:{eq:r}});return this.getShapeAndDescendantIds(o.map(s=>s.id))}setCurrentPage(t,r){const o=typeof t=="string"?t:t.id;return this._setCurrentPageId(o,r),this}updatePage(t,r){return this._updatePage(t,r),this}createPage(t){return this._createPage(t),this}deletePage(t){const r=typeof t=="string"?t:t.id;return this._deletePage(r),this}duplicatePage(t,r=Oo.createId()){if(this.getPages().length>=rp)return this;const o=typeof t=="string"?t:t.id,s=this.getPage(o);if(!s)return this;const i={...this.getCamera()},a=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.batch(()=>{var u;const l=this.getPages(),c=nc(s.index,(u=l[l.indexOf(s)+1])==null?void 0:u.index);if(this.createPage({name:s.name+" Copy",id:r,index:c}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(t,r,o){const s=typeof t=="string"?t:t.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:s,name:r},o),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(t){return this._createAssets(t),this}updateAssets(t){return this._updateAssets(t),this}deleteAssets(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this._deleteAssets(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)}_getShapeOutlineSegmentsCache(){return this.store.createComputedCache("outline-segments",t=>this.getShapeUtil(t).getOutlineSegments(t))}getShapeOutlineSegments(t){return this._getShapeOutlineSegmentsCache().get(typeof t=="string"?t:t.id)??ko}_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 te.Identity().translate(o.x,o.y).rotate(o.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",t=>{if(gn(t.parentId))return this.getShapeLocalTransform(t);const r=this._getShapePageTransformCache().get(t.parentId)??te.Identity();return te.Compose(r,this.getShapeLocalTransform(t))})}getShapeParentTransform(t){const r=typeof t=="string"?t:t.id,o=this.getShape(r);return!o||gn(o.parentId)?te.Identity():this._getShapePageTransformCache().get(o.parentId)??te.Identity()}getShapePageTransform(t){const r=typeof t=="string"?t:this.getShape(t).id;return this._getShapePageTransformCache().get(r)??te.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",t=>{const r=this._getShapePageTransformCache().get(t.id);return r?re.FromPoints(te.applyToPoints(r,this.getShapeGeometry(t).vertices)):new re})}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(${te.applyToPoints(te.Inverse(o),r).map(i=>`${i.x}px ${i.y}px`).join(",")})`:void 0})}getShapeClipPath(t){return this._getShapeClipPathCache().get(typeof t=="string"?t:t.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",t=>{if(gn(t.parentId))return;const r=this.getShapeAncestors(t.id).filter(s=>this.isShapeOfType(s,"frame"));return r.length===0?void 0:r.map(s=>this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)).reduce((s,i)=>{if(!(i&&s))return;const a=My(s,i);return a?a.map(C.Cast):[]})})}getShapeMask(t){return this._getShapeMaskCache().get(typeof t=="string"?t:t.id)}getShapeMaskedPageBounds(t){typeof t!="string"&&(t=t.id);const r=this._getShapePageBoundsCache().get(t);if(!r)return;const o=this._getShapeMaskCache().get(t);if(o){if(o.length===0)return;const{corners:s}=r;if(s.every((a,l)=>a&&C.Equals(a,o[l])))return r.clone();const i=My(o,s);return i?re.FromPoints(i):void 0}return r}getShapeAncestors(t,r=[]){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return r;const i=s.parentId;if(gn(i))return r.reverse(),r;const a=this.store.get(i);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return;const i=s.parentId;if(gn(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(t,r){const o=typeof t=="string"?t:t==null?void 0:t.id,s=o&&this.getShape(o);return s?s.parentId===r?!0:this.hasAncestor(this.getShapeParent(s),r):!1}findCommonAncestor(t,r){var c;if(t.length===0)return;const o=typeof t[0]=="string"?t:t.map(u=>u.id),s=pe(o.map(u=>this.getShape(u)));if(s.length===1){const u=s[0].parentId;return gn(u)?void 0:r?(c=this.findShapeAncestor(s[0],r))==null?void 0:c.id:u}const[i,...a]=s;let l=this.getShapeParent(i);for(;l;){if(r&&!r(l)){l=this.getShapeParent(l);continue}if(a.every(u=>this.hasAncestor(u,l.id)))return l.id;l=this.getShapeParent(l)}}isShapeOrAncestorLocked(t){const r=typeof t=="string"?this.getShape(t):t;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}getCurrentPageBounds(){let t;return this.getCurrentPageShapeIds().forEach(r=>{const o=this.getShapeMaskedPageBounds(r);o&&(t?t=t.expand(o):t=o.clone())}),t}getSelectedShapeAtPoint(t){const r=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(o=>o.type!=="group"&&r.includes(o.id)).reverse().find(o=>this.isPointInShape(o,t,{hitInside:!0,margin:0}))}getShapeAtPoint(t,r={}){const o=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:i,margin:a=0,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:u=!1}=r;let d=1/0,h=null,p=1/0,m=null;const f=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(S=>{if(this.isShapeOfType(S,"group"))return!1;const v=this.getShapeMask(S);return v&&!Rr(t,v)?!1:i?i(S):!0});for(let S=f.length-1;S>=0;S--){const v=f[S],x=this.getShapeGeometry(v),b=x instanceof Po,P=this.getPointInShapeSpace(v,t);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const k of x.children)if(k.isLabel&&k.isPointInBounds(P))return v}if(this.isShapeOfType(v,"frame")){const k=x.distanceToPoint(P,c);if(Math.abs(k)<=a)return m||v;if(x.hitTestPoint(P,0,!0))return m||h||(u?v:void 0);continue}let E;if(b){let k=1/0;for(const I of x.children){if(I.isLabel&&!l)continue;const _=I.distanceToPoint(P,c);_<k&&(k=_)}E=k}else a===0&&(x.bounds.w<1||x.bounds.h<1)||x.bounds.containsPoint(P,a)?E=x.distanceToPoint(P,c):E=1/0;if(x.isClosed){if(E<=a){if(x.isFilled||b&&x.children[0].isFilled)return m||v;if(this.getShapePageBounds(v).contains(s))continue;if(Math.abs(E)<a)Math.abs(E)<p&&(p=Math.abs(E),m=v);else if(!m){const{area:k}=x;k<d&&(d=k,h=v)}}}else if(E<Or/o)return v}return m||h||void 0}getShapesAtPoint(t,r={}){return this.getCurrentPageShapes().filter(o=>this.isPointInShape(o,t,r))}isPointInShape(t,r,o={}){const{hitInside:s=!1,margin:i=0}=o,a=typeof t=="string"?t:t.id,l=this.getShapeMask(a);return l&&!Rr(r,l)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(t,r),i,s)}getPointInShapeSpace(t,r){const o=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(o).clone().invert().applyToPoint(r)}getPointInParentSpace(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return new C(0,0);if(gn(s.parentId))return C.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):C.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),t=>this.store.get(t))}getCurrentPageShapesSorted(){const t=new Set(this.getCurrentPageShapes().sort(Wt)),r=[];function o(s){r.push(s),t.delete(s),t.forEach(i=>{i.parentId===s.id&&o(i)})}return t.forEach(s=>{const i=this.getShape(s.parentId);ti(i)||o(s)}),r}getCurrentPageRenderingShapesSorted(){return this.getRenderingShapes().filter(({isCulled:t})=>!t).sort((t,r)=>t.index-r.index).map(({shape:t})=>t)}isShapeOfType(t,r){return(typeof t=="string"?this.getShape(t):t).type===r}getShape(t){const r=typeof t=="string"?t:t.id;if(Rn(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||!Rn(o.parentId)))return this.store.get(o.parentId)}getShapeNearestSibling(t,r){return r?r.parentId===t.parentId?r:this.findShapeAncestor(r,s=>s.parentId===t.parentId):void 0}isShapeInPage(t,r=this.getCurrentPageId()){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return!1;let i=!1;if(s.parentId===r)i=!0;else{let a=this.getShape(s.parentId);e:for(;a;){if(a.parentId===r){i=!0;break e}a=this.getShape(a.parentId)}}return i}getAncestorPageId(t){const r=typeof t=="string"?t:t==null?void 0:t.id,o=r&&this.getShape(r);if(o)return gn(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(m=>m.id);if(s.length===0)return this;const i=[],a=gn(r)?te.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const u=pe(this.getSortedChildIdsForParent(r).map(m=>this.getShape(m)));if(o){const m=u.find(f=>f.index===o);if(m){const f=u[u.indexOf(m)+1];f?c=Ra(o,f.index,s.length):c=bg(o,s.length)}else{const f=u.sort(Wt).find(S=>S.index>o);f?c=Ra(o,f.index,s.length):c=bg(o,s.length)}}else{const m=u.length&&u[u.length-1];c=m?bg(m.index,s.length):Ek(s.length)}const d=a.clone().invert(),h=pe(s.map(m=>this.getShape(m))),p=h.filter(m=>m.isLocked);p.length&&this.updateShapes(p.map(({id:m,type:f})=>({id:m,type:f,isLocked:!1})));for(let m=0;m<h.length;m++){const f=h[m],S=this.getShapePageTransform(f);if(!S)continue;const v=S.point();if(!v)continue;const x=d.applyToPoint(v),b=S.rotation()-l;i.push({id:f.id,type:f.type,parentId:r,x:x.x,y:x.y,rotation:b,index:c[m],isLocked:f.isLocked})}return this.updateShapes(i),this}getHighestIndexForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const s=this.getShape(o[o.length-1]);return So(s.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o?this._childIdsCache.get(o,()=>o):ko}visitDescendants(t,r){const o=typeof t=="string"?t:t.id,s=this.getSortedChildIdsForParent(o);for(const i of s)r(i)!==!1&&this.visitDescendants(i,r);return this}getShapeAndDescendantIds(t){const r=new Set,o=[...t];for(;o.length>0;){const s=o.pop();if(!s)break;if(!r.has(s)){r.add(s);for(const i of this.getSortedChildIdsForParent(s))o.push(i)}}return r}getDroppingOverShape(t,r=[]){const o=this.getCurrentPageShapesSorted();for(let s=o.length-1;s>=0;s--){const i=o[s];if(!this.getShapeUtil(i).canDropShapes(i,r)||r.find(l=>l.id===i.id||this.hasAncestor(i,l.id)))continue;const a=this.getShapeMaskedPageBounds(i.id);if(a&&a.containsPoint(t)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,t),0,!0))return i}}getOutermostSelectableShape(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);let i=s,a=s;const l=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(l==null?void 0:l.id)!==a.id&&!this.hasAncestor(l,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((l==null?void 0:l.id)===a.id)break;a=this.getShapeParent(a)}return i}rotateShapesBy(t,r){if((typeof t[0]=="string"?t:t.map(i=>i.id)).length<=0)return this;const s=kk({editor:this});return s?(Jd({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(t,r){var i,a,l;let o=t;const s=this.getShapeUtil(t);return o=El(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=El(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=El(o,((a=s.onTranslate)==null?void 0:a.call(s,t,o))??void 0),o=El(o,((l=s.onTranslateEnd)==null?void 0:l.call(s,t,o))??void 0),o}nudgeShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(a=>a.id);if(s.length<=0)return this;const i=[];for(const a of s){const l=this.getShape(a),c=C.From(r),u=this.getShapeParentTransform(l);u&&c.rot(-u.rotation()),i.push(this.getChangesToTranslateShape(l,c.add(l)))}return this.updateShapes(i,{squashing:!0,...o}),this}duplicateShapes(t,r){const o=typeof t[0]=="string"?t:t.map(u=>u.id);if(o.length<=0)return this;const s=new Set(o),i=[],a=[...o];for(;a.length>0;){const u=a.pop();if(!u)break;i.push(u),this.getSortedChildIdsForParent(u).forEach(d=>a.push(d))}i.reverse();const l=new Map(i.map(u=>[u,We()])),c=pe(i.map(u=>{const d=this.getShape(u);if(!d)return null;const h=l.get(u);let p=0,m=0;if(r&&s.has(u)){const k=this.getShapeParentTransform(d),I=new C(r.x,r.y).rot(-k.rotation());p=I.x,m=I.y}const f=d.parentId??this.getCurrentPageId(),S=this.getSortedChildIdsForParent(f),v=S.indexOf(d.id),x=S[v+1],b=x?this.getShape(x):null,P=b?nc(d.index,b.index):So(d.index);let E=Zt(d);if(this.isShapeOfType(d,"arrow")&&this.isShapeOfType(E,"arrow")){const k=this.getArrowInfo(d);let I,_;if(d.props.start.type==="binding"&&(I=l.get(d.props.start.boundShapeId),!I))if(k!=null&&k.isValid){const{x:T,y:D}=k.start.point;E.props.start={type:"point",x:T,y:D}}else{const{start:T}=Er(this,d);E.props.start={type:"point",x:T.x,y:T.y}}if(d.props.end.type==="binding"&&(_=l.get(d.props.end.boundShapeId),!_))if(k!=null&&k.isValid){const{x:T,y:D}=k.end.point;E.props.end={type:"point",x:T,y:D}}else{const{end:T}=Er(this,d);E.props.start={type:"point",x:T.x,y:T.y}}const A=Cl(E)?rc(this,E):Cg(this,E);if(k!=null&&k.isValid&&(A!=null&&A.isValid)&&!Cl(d)){const T=C.Med(k.start.handle,k.end.handle),D=C.Dist(k.middle,T),L=C.Dist(A.middle,T);E.props.bend<0?E.props.bend+=L-D:E.props.bend-=L-D}E.props.start.type==="binding"&&I&&(E.props.start.boundShapeId=I),E.props.end.type==="binding"&&_&&(E.props.end.boundShapeId=_)}return E={...E,id:h,x:d.x+p,y:d.y+m,index:P},E}));return c.forEach(u=>{Rn(u.parentId)&&l.has(u.parentId)&&(u.parentId=l.get(u.parentId))}),this.history.batch(()=>{const u=c.length+this.getCurrentPageShapeIds().size>fo;u&&rd(this);const d=u?c.slice(0,fo-this.getCurrentPageShapeIds().size):c,h=d.map(p=>p.id);if(this.createShapes(d),this.setSelectedShapes(h),r!==void 0){const p=this.getSelectionPageBounds(),m=this.getViewportPageBounds();p&&!m.contains(p)&&this.centerOnPoint(p.center,{duration:xo})}}),this}moveShapesToPage(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.id);if(o.length===0)return this;if(this.getInstanceState().isReadonly)return this;const s=this.getCurrentPageId();if(r===s)return this;if(!this.store.has(r))return this;const i=this.getContentFromCurrentPage(o);if(!i)return this;if(this.getPageShapeIds(r).size+i.shapes.length>fo)return rd(this,r),this;const a=this.getCamera().z;return this.history.batch(()=>{this.deleteShapes(o),this.setCurrentPage(r),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(i,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:a}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(t){const r=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly||r.length===0)return this;let o=!0,s=!0;const i=[];for(const a of r){const l=this.getShape(a);l&&(i.push(l),l.isLocked?s=!1:o=!1)}return this.batch(()=>{s?(this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):o?this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=nd(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=nd(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=nd(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=nd(this,"toFront",r);return o&&this.updateShapes(o),this}flipShapes(t,r){const o=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;let s=pe(o.map(a=>this.getShape(a)));if(!s.length)return this;s=pe(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(l=>this.getShape(l)):a).flat());const i=re.Common(pe(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const l=this.getShapeGeometry(a).bounds,c=this.getShapePageTransform(a.id);c&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:l,initialPageTransform:c,initialShape:a,mode:"scale_shape",scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(S=>S.id);if(this.getInstanceState().isReadonly)return this;const i=pe(s.map(S=>this.getShape(S)).filter(S=>!(!S||this.isShapeOfType(S,"arrow")&&(S.props.start.type==="binding"||S.props.end.type==="binding")))),a=i.length;if(o===0&&a<3||a<2)return this;const l=Object.fromEntries(i.map(S=>[S.id,this.getShapePageBounds(S)]));let c,u,d,h;r==="horizontal"?(c="x",u="minX",d="maxX",h="width"):(c="y",u="minY",d="maxY",h="height");let p;if(o===0){const S=[];i.sort((x,b)=>l[x.id][u]-l[b.id][u]);for(let x=0;x<a-1;x++){const b=i[x],P=i[x+1],E=l[b.id],I=l[P.id][u]-E[d],_=S.find(A=>A.gap===I);_?_.count++:S.push({gap:I,count:1})}let v=0;S.forEach(x=>{x.count>v&&(v=x.count,p=x.gap)}),v===1&&(p=Math.max(0,S.reduce((x,b)=>x+b.gap*b.count,0)/(a-1)))}else p=o;const m=[];let f=l[i[0].id][d];return i.forEach((S,v)=>{var k,I;if(v===0)return;const x={x:0,y:0};x[c]=f+p-l[S.id][c];const b=this.getShapeParent(S),P=b?C.Rot(x,-this.getShapePageTransform(b).decompose().rotation):x,E=(I=(k=this.getShapeUtil(S)).onTranslateStart)==null?void 0:I.call(k,S);m.push(E?{...E,[c]:S[c]+P[c]}:{id:S.id,type:S.type,[c]:S[c]+P[c]}),f+=l[S.id][h]+p}),this.updateShapes(m),this}packShapes(t,r){var I,_;const o=typeof t[0]=="string"?t:t.map(A=>A.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=pe(o.map(A=>this.getShape(A)).filter(A=>!(!A||this.isShapeOfType(A,"arrow")&&(A.props.start.type==="binding"||A.props.end.type==="binding")))),i={},a={};let l,c,u=0;for(let A=0;A<s.length;A++)l=s[A],c=this.getShapePageBounds(l),i[l.id]=c,a[l.id]=c.clone(),u+=c.width*c.height;const d=re.Common(pe(Object.values(i))),h=d.width;s.sort((A,T)=>i[T.id].height-i[A.id].height);const p=Math.max(Math.ceil(Math.sqrt(u/.95)),h),m=[new re(d.x,d.y,p,1/0)];let f=0,S=0,v,x;for(let A=0;A<s.length;A++){l=s[A],c=a[l.id];for(let T=m.length-1;T>=0;T--)if(v=m[T],!(c.width>v.width||c.height>v.height)){c.x=v.x,c.y=v.y,S=Math.max(S,c.maxY),f=Math.max(f,c.maxX),c.width===v.width&&c.height===v.height?(x=m.pop(),T<m.length&&(m[T]=x)):c.height===v.height?(v.x+=c.width+r,v.width-=c.width+r):c.width===v.width?(v.y+=c.height+r,v.height-=c.height+r):(m.push(new re(v.x+(c.width+r),v.y,v.width-(c.width+r),c.height)),v.y+=c.height+r,v.height-=c.height+r);break}}const b=re.Common(Object.values(a)),P=C.Sub(d.center,b.center);let E;const k=[];for(let A=0;A<s.length;A++){l=s[A],c=i[l.id],E=a[l.id];const T=C.Sub(E.point,c.point).add(P),D=this.getShapeParentTransform(l);D&&T.rot(-D.rotation());const L={id:l.id,type:l.type,x:l.x+T.x,y:l.y+T.y},z=(_=(I=this.getShapeUtil(l)).onTranslateStart)==null?void 0:_.call(I,{...l,...L});z?k.push({...L,...z}):k.push(L)}return k.length&&this.updateShapes(k),this}alignShapes(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=pe(o.map(c=>this.getShape(c))),i=Object.fromEntries(s.map(c=>[c.id,this.getShapePageBounds(c)])),a=re.Common(pe(Object.values(i))),l=[];return s.forEach(c=>{const u=i[c.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 h=this.getShapeParent(c),p=h?C.Rot(d,-this.getShapePageTransform(h).decompose().rotation):d;l.push(this.getChangesToTranslateShape(c,C.Add(c,p)))}),this.updateShapes(l),this}distributeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(b=>b.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=pe(o.map(b=>this.getShape(b))),a=Object.fromEntries(i.map(b=>[b.id,this.getShapePageBounds(b)]));let l,c,u,d,h;r==="horizontal"?(l="x",c="minX",u="maxX",d="midX",h="width"):(l="y",c="minY",u="maxY",d="midY",h="height");const p=[],m=i.sort((b,P)=>a[b.id][c]-a[P.id][c])[0],f=i.sort((b,P)=>a[P.id][u]-a[b.id][u])[0],S=a[m.id][d],v=(a[f.id][d]-S)/(s-1),x=S+v;return i.filter(b=>b!==m&&b!==f).sort((b,P)=>a[b.id][d]-a[P.id][d]).forEach((b,P)=>{const E={x:0,y:0};E[l]=x+v*P-a[b.id][h]/2-a[b.id][l];const k=this.getShapeParent(b),I=k?C.Rot(E,-this.getShapePageTransform(k).rotation()):E;p.push(this.getChangesToTranslateShape(b,C.Add(b,I)))}),this.updateShapes(p),this}stretchShapes(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=pe(o.map(c=>this.getShape(c))),i=Object.fromEntries(o.map(c=>[c,this.getShapeGeometry(c).bounds])),a=Object.fromEntries(o.map(c=>[c,this.getShapePageBounds(c)])),l=re.Common(pe(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const c of s){if(this.getShapePageTransform(c).rotation()%Re)continue;const d=i[c.id],h=a[c.id],p=new C(0,l.minY-h.minY),m=this.getShapeParentTransform(c);m&&p.rot(-m.rotation());const{x:f,y:S}=C.Add(p,c);this.updateShapes([{id:c.id,type:c.type,x:f,y:S}],{squashing:!0});const v=new C(1,l.height/h.height);this.resizeShape(c.id,v,{initialBounds:d,scaleOrigin:new C(h.center.x,l.minY),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const c of s){const u=i[c.id],d=a[c.id];if(this.getShapePageTransform(c).rotation()%Re)continue;const p=new C(l.minX-d.minX,0),m=this.getShapeParentTransform(c);m&&p.rot(-m.rotation());const{x:f,y:S}=C.Add(p,c);this.updateShapes([{id:c.id,type:c.type,x:f,y:S}],{squashing:!0});const v=new C(l.width/d.width,1);this.resizeShape(c.id,v,{initialBounds:u,scaleOrigin:new C(l.minX,d.center.y),scaleAxisRotation:0})}});break}}return this}resizeShape(t,r,o={}){var p;const s=typeof t=="string"?t:t.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new C(1,r.y)),Number.isFinite(r.y)||(r=new C(r.x,1));const i=o.initialShape??this.getShape(s);if(!i)return this;const a=o.scaleOrigin??((p=this.getShapePageBounds(s))==null?void 0:p.center);if(!a)return this;const l=o.initialPageTransform?te.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!l)return this;const c=l.rotation();if(c==null)return this;const u=o.scaleAxisRotation??c,d=o.initialBounds??this.getShapeGeometry(s).bounds;if(!d)return this;if(!zE(c,u))return this._resizeUnalignedShape(s,r,{...o,initialBounds:d,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:l,initialShape:i});const h=this.getShapeUtil(i);if(h.isAspectRatioLocked(i)&&(Math.abs(r.x)>Math.abs(r.y)?r=new C(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new C(Math.sign(r.x)*Math.abs(r.y),r.y)),h.onResize&&h.canResize(i)){const m=this._scalePagePoint(te.applyToPoint(l,new C(0,0)),a,r,u),f=this.getPointInParentSpace(i.id,m),S=new C(r.x,r.y),v=ec((c-u)%Math.PI,0);S.x=v?r.x:r.y,S.y=v?r.y:r.x;const x=te.applyToPoint(l,new C),{x:b,y:P}=this.getPointInParentSpace(i.id,x);this.updateShapes([{id:s,type:i.type,x:f.x,y:f.y,...h.onResize({...i,x:b,y:P},{newPoint:f,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:S.x,scaleY:S.y,initialBounds:d,initialShape:i})}],{squashing:!0})}else{const m=te.applyToPoint(l,d.center),f=this._scalePagePoint(m,a,r,u),S=this.getPointInParentSpace(i.id,m),v=this.getPointInParentSpace(i.id,f),x=C.Sub(v,S);this.updateShapes([{id:s,type:i.type,x:i.x+x.x,y:i.y+x.y}],{squashing:!0})}return this}_scalePagePoint(t,r,o,s){const i=C.RotWith(t,r,-s).sub(r),a=C.MulV(i,o);return C.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(t,r,o){const{type:s}=o.initialShape,i=new C(r.x,r.y);if(Math.abs(r.x)>Math.abs(r.y)?i.x=Math.sign(r.x)*Math.abs(r.y):i.y=Math.sign(r.y)*Math.abs(r.x),this.resizeShape(t,i,{initialShape:o.initialShape,initialBounds:o.initialBounds}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:v}=te.Decompose(o.initialPageTransform);v-=2*v,this.updateShapes([{id:t,type:s,rotation:v}],{squashing:!0})}const a=te.applyToPoint(o.initialPageTransform,o.initialBounds.center),l=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),c=this.getShapePageBounds(t),u=this.getShapePageTransform(t),d=c.center,h=u.point();if(!d||!h)return this;const p=C.Sub(l,d),m=C.Add(h,p),{x:f,y:S}=this.getPointInParentSpace(t,m);return this.updateShapes([{id:t,type:s,x:f,y:S}],{squashing:!0}),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");return this._createShapes(t),this}animateShape(t,r){return this.animateShapes([t],r)}animateShapes(t,r={}){const{duration:o=500,easing:s=qt.linear}=r,i=Ue();let a=o,l;const c=[];t.forEach(h=>{if(!h)return;const p={partial:h,values:[]},m=this.getShape(h.id);if(m){for(const f of["x","y","rotation"])h[f]!==void 0&&m[f]!==h[f]&&p.values.push({prop:f,from:m[f],to:h[f]});c.push(p),this.animatingShapes.set(m.id,i)}});let u;const d=h=>{if(a-=h,a<0){const{animatingShapes:m}=this,f=t.filter(S=>S&&m.get(S.id)===i);f.length&&this.updateShapes(f,{squashing:!1}),this.removeListener("tick",d);return}l=s(1-a/o);const{animatingShapes:p}=this;try{const m=[];for(let f=0;f<c.length;f++)u=c[f],p.get(u.partial.id)===i&&m.push({id:u.partial.id,type:u.partial.type,...u.values.reduce((S,{prop:v,from:x,to:b})=>(S[v]=x+(b-x)*l,S),{})});this._updateShapes(m,{squashing:!0})}catch{}};return this.addListener("tick",d),this}groupShapes(t,r=We()){var p;if(!Array.isArray(t))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const o=typeof t[0]=="string"?t:t.map(m=>m.id);if(o.length<=1)return this;const s=pe(this._getUnlockedShapeIds(o).map(m=>this.getShape(m))),i=s.sort(Wt).map(m=>m.id),a=re.Common(pe(s.map(m=>this.getShapePageBounds(m)))),{x:l,y:c}=a.point,u=this.findCommonAncestor(s)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const d=s.filter(m=>m.parentId===u).sort(Wt),h=(p=d[d.length-1])==null?void 0:p.index;return this.batch(()=>{this.createShapes([{id:r,type:"group",parentId:u,index:h,x:l,y:c,opacity:1,props:{}}]),this.reparentShapes(i,r),this.select(r)}),this}ungroupShapes(t){const r=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const o=new Set,s=pe(r.map(a=>this.getShape(a))),i=[];return s.forEach(a=>{this.isShapeOfType(a,"group")?i.push(a):o.add(a.id)}),i.length===0?this:(this.batch(()=>{let a;for(let l=0,c=i.length;l<c;l++){a=i[l];const u=this.getSortedChildIdsForParent(a.id);for(let d=0,h=u.length;d<h;d++)o.add(u[d]);this.reparentShapes(u,a.parentId,a.index)}this.deleteShapes(i.map(l=>l.id)),this.select(...o)}),this)}updateShape(t,r){return this.updateShapes([t],r),this}updateShapes(t,r){let o=pe(t);return this.animatingShapes.size>0&&o.forEach(s=>this.animatingShapes.delete(s.id)),o=o.filter(s=>{const i=this.getShape(s.id);return!(!i||this.isShapeOrAncestorLocked(i)&&!Object.hasOwn(s,"isLocked"))}),this._updateShapes(o,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");return this._deleteShapes(this._getUnlockedShapeIds(typeof t[0]=="string"?t:t.map(r=>r.id))),this}deleteShape(t){return this.deleteShapes([typeof t=="string"?t:t.id]),this}_extractSharedStyles(t,r){if(this.isShapeOfType(t,"group")){const o=this._parentIdsToChildIds.get()[t.id];if(!o)return;for(let s=0,i=o.length;s<i;s++)this._extractSharedStyles(this.getShape(o[s]),r)}else for(const[o,s]of this.styleProps[t.type])r.applyValue(o,ai(t.props,s))}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 ai(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._selectionSharedStyles.get();const t=this.root.getCurrent(),r=new Oy;if(!t)return r;if(t.shapeType)for(const o of this.styleProps[t.shapeType].keys())r.applyValue(o,this.getStyleForNextShape(o));return r}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const t=[],r=s=>{const i=this.getShape(s);if(i)if(this.isShapeOfType(i,"group"))for(const a of this.getSortedChildIdsForParent(i.id))r(a);else t.push(i)};for(const s of this.getSelectedShapeIds())r(s);let o=null;for(const s of t)if(o===null)o=s.opacity;else if(o!==s.opacity)return{type:"mixed"};if(o!==null)return{type:"shared",value:o}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(t,r){return this.updateInstanceState({opacityForNextShape:t},r),this}setOpacityForSelectedShapes(t,r){const o=this.getSelectedShapes();if(o.length>0){const s=[],i=a=>{if(this.isShapeOfType(a,"group")){const l=this.getSortedChildIdsForParent(a);for(const c of l)i(this.getShape(c))}else s.push(a)};for(const a of o)i(a);this.updateShapes(s.map(a=>({id:a.id,type:a.type,opacity:t})),r)}return this}setStyleForNextShapes(t,r,o){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[t.id]:r}},o),this}setStyleForSelectedShapes(t,r,o){const s=this.getSelectedShapes();if(s.length>0){const i=[],a=l=>{if(this.isShapeOfType(l,"group")){const c=this.getSortedChildIdsForParent(l.id);for(const u of c)a(this.getShape(u))}else{const c=this.getShapeUtil(l),u=this.styleProps[l.type].get(t);if(u){const d={id:l.id,type:l.type,props:{[u]:r}};i.push({util:c,originalShape:l,updatePartial:d})}}};for(const l of s)a(l);this.updateShapes(i.map(({updatePartial:l})=>l),o)}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(l=>l.id);if(!r||r.length===0)return;const o={};let s=Wh(r.map(l=>this.getShape(l)).sort(Wt).flatMap(l=>{const c=[l];return this.visitDescendants(l.id,u=>{c.push(this.getShape(u))}),c}));s=s.map(l=>{if(o[l.id]=this.getShapePageTransform(l.id),l=gs(l),this.isShapeOfType(l,"arrow")){const c=l.props.start.type==="binding"?l.props.start.boundShapeId:void 0,u=l.props.end.type==="binding"?l.props.end.boundShapeId:void 0,d=this.getArrowInfo(l);if(l.props.start.type==="binding"&&!s.some(p=>p.id===c))if(d!=null&&d.isValid){const{x:p,y:m}=d.start.point;l.props.start={type:"point",x:p,y:m}}else{const{start:p}=Er(this,l);l.props.start={type:"point",x:p.x,y:p.y}}if(l.props.end.type==="binding"&&!s.some(p=>p.id===u))if(d!=null&&d.isValid){const{x:p,y:m}=d.end.point;l.props.end={type:"point",x:p,y:m}}else{const{end:p}=Er(this,l);l.props.end={type:"point",x:p.x,y:p.y}}const h=Cl(l)?rc(this,l):Cg(this,l);if(d!=null&&d.isValid&&(h!=null&&h.isValid)&&!Cl(l)){const p=C.Med(d.start.handle,d.end.handle),m=C.Dist(d.middle,p),f=C.Dist(h.middle,p);l.props.bend<0?l.props.bend+=f-m:l.props.bend-=f-m}return l}return l});const i=[];s.forEach(l=>{if(s.find(c=>c.id===l.parentId)===void 0){const c=this.getShapePageTransform(l.id),u=c.point(),d=c.rotation();l.x=u.x,l.y=u.y,l.rotation=d,l.parentId=this.getCurrentPageId(),i.push(l.id)}});const a=new Set;return s.forEach(l=>{"assetId"in l.props&&l.props.assetId!==null&&a.add(l.props.assetId)}),{shapes:s,rootShapeIds:i,schema:this.store.schema.serialize(),assets:pe(Array.from(a).map(l=>this.getAsset(l)))}}putContentOntoCurrentPage(t,r={}){if(this.getInstanceState().isReadonly)return this;if(!t.schema)throw Error(`Could not put content:
46
+ content is missing a schema.`);const{select:o=!1,preserveIds:s=!1,preservePosition:i=!1}=r;let{point:a=void 0}=r;const l=this.getCurrentPageId(),{assets:c,shapes:u,rootShapeIds:d}=t,h=new Map(u.map(E=>[E.id,We()]));let p=this.getCurrentPageId(),m=1/0,f=[];for(const E of this.getSelectedShapes()){if(m===0)break;const k=this.isShapeOfType(E,"frame"),I=this.getShapeAncestors(E);k&&I.push(E);const _=k?I.length+1:I.length;if(_<m)m=_,f=I,p=k?E.id:E.parentId;else if(_===m){if(f.length!==I.length)throw Error(`Ancestors: ${f.length} !== ${I.length}`);if(f.length===0){p=l;break}else{p=l;for(let A=0;A<f.length&&I[A]===f[A];A++)p=I[A].id}}}let S=!1;if(!gn(p)){const E=this.getShape(p);if(E){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(E)))p=l;else if(d.length===1){const k=u.find(I=>I.id===d[0]);this.isShapeOfType(E,"frame")&&this.isShapeOfType(k,"frame")&&k.props.w===(E==null?void 0:E.props.w)&&k.props.h===(E==null?void 0:E.props.h)&&(S=!0)}}else p=l}S||(S=h.has(p)),S&&(p=this.getShape(p).parentId);let v=this.getHighestIndexForParent(p);const x=[],b=u.map(E=>{let k;if(s)k=Zt(E),h.set(E.id,E.id);else{const I=h.get(E.id);k=Zt({...E,id:I})}if(d.includes(E.id)&&(k.parentId=l,x.push(k)),h.has(k.parentId)?k.parentId=h.get(E.parentId):(d.push(k.id),k.index=v,v=So(v)),this.isShapeOfType(k,"arrow")){if(k.props.start.type==="binding"){const I=h.get(k.props.start.boundShapeId);k.props.start=I?{...k.props.start,boundShapeId:I}:{type:"point",x:0,y:0}}if(k.props.end.type==="binding"){const I=h.get(k.props.end.boundShapeId);k.props.end=I?{...k.props.end,boundShapeId:I}:{type:"point",x:0,y:0}}}return k});if(b.length+this.getCurrentPageShapeIds().size>fo)return rd(this),this;let P=[];if(c){for(let k=0;k<c.length;k++){const I=c[k],_=this.store.schema.migratePersistedRecord(I,t.schema);if(_.type==="success")c[k]=_.value;else throw Error(`Could not put content:
47
+ could not migrate content for asset:
48
+ ${I.id}
49
+ ${I.type}
50
+ reason:${_.reason}`)}const E=[];P=c.filter(k=>!this.store.has(k.id)).map(k=>{var I;return(k.type==="image"||k.type==="video")&&(k.props.src&&((I=k.props.src)!=null&&I.startsWith("data:image"))?(E.push(gs(k)),k.props.src=null):E.push(gs(k))),k}),Promise.allSettled(E.map(async k=>{const I=await M6(k.props.src,k.props.name,k.props.mimeType??"image/png"),_=await this.getAssetForExternalContent({type:"file",file:I});return _?[k,_]:null})).then(k=>{this.updateAssets(pe(k.map(I=>I.status==="fulfilled"&&I.value?{...I.value[1],id:I.value[0].id}:void 0)))})}for(let E=0;E<b.length;E++){const k=b[E],I=this.store.schema.migratePersistedRecord(k,t.schema);if(I.type==="success")b[E]=I.value;else throw Error(`Could not put content:
51
+ could not migrate content for shape:
52
+ ${k.id}, ${k.type}
53
+ reason:${I.reason}`)}return this.batch(()=>{P.length>0&&this.createAssets(P),this.createShapes(b),o&&this.select(...x.map(A=>A.id)),p!==l&&this.reparentShapes(x.map(A=>A.id),p);const E=b.map(A=>this.getShape(A.id)),k=re.Common(E.map(A=>this.getShapePageBounds(A)));if(a===void 0)if(gn(p)){const A=this.getViewportPageBounds();i||A.includes(re.From(k))?a=k.center:a=A.center}else{const A=this.getShape(p);a=te.applyToPoint(this.getShapePageTransform(A),this.getShapeGeometry(A).bounds.center)}if(x.length===1){const A=x[0];if(this.isShapeOfType(A,"frame"))for(;this.getShapesAtPoint(a).some(T=>this.isShapeOfType(T,"frame")&&T.props.w===A.props.w&&T.props.h===A.props.h);)a.x+=k.w+16}const I=re.Common(pe(x.map(({id:A})=>this.getShapePageBounds(A)))).center,_=C.Sub(a,I);this.updateShapes(x.map(({id:A})=>{const T=this.getShape(A),D=this.getShapeParentTransform(A).decompose().rotation,L=C.Rot(_,-D);return{id:T.id,type:T.type,x:T.x+L.x,y:T.y+L.y}}))}),this}async getSvg(t,r={}){var E,k;const o=typeof t[0]=="string"?t:t.map(I=>I.id);if(o.length===0)return;if(!window.document)throw Error("No document");const{scale:s=1,background:i=!1,padding:a=SD,preserveAspectRatio:l=!1}=r,c=In({isDarkMode:this.user.getIsDarkMode()}),u=this.getShapeAndDescendantIds(o),d=this.getUnorderedRenderingShapes(!1).filter(({id:I})=>u.has(I));let h=null;if(r.bounds)h=r.bounds;else for(const{maskedPageBounds:I}of d)I&&(h?h.union(I):h=I.clone());if(!h)return;const p=o.length===1&&this.isShapeOfType(this.getShape(o[0]),"frame")?o[0]:null;p||h.expandBy(a);const m=h.width*s,f=h.height*s,S=window.document.createElementNS("http://www.w3.org/2000/svg","svg");l&&S.setAttribute("preserveAspectRatio",l),S.setAttribute("direction","ltr"),S.setAttribute("width",m+""),S.setAttribute("height",f+""),S.setAttribute("viewBox",`${h.minX} ${h.minY} ${h.width} ${h.height}`),S.setAttribute("stroke-linecap","round"),S.setAttribute("stroke-linejoin","round"),i?p?S.style.setProperty("background",c.solid):S.style.setProperty("background-color",c.background):S.style.setProperty("background-color","transparent");try{(k=(E=document.body).focus)==null||k.call(E)}catch{}const v=window.document.createElementNS("http://www.w3.org/2000/svg","defs");S.append(v);const x=new Map,b={addExportDef:I=>{if(x.has(I.key))return;const _=(async()=>{const A=await I.getElement();if(!A)return;const T=document.createComment(`def: ${I.key}`);v.appendChild(T);for(const D of Array.isArray(A)?A:[A])v.appendChild(D)})();x.set(I.key,_)}},P=(await Promise.all(d.map(async({id:I,opacity:_,index:A,backgroundIndex:T})=>{var H,B;if(I===p)return[];const D=this.getShape(I);if(this.isShapeOfType(D,"group"))return[];const L=this.getShapeUtil(D);let z=await((H=L.toSvg)==null?void 0:H.call(L,D,b)),j=await((B=L.toBackgroundSvg)==null?void 0:B.call(L,D,b));if(z){const V=document.createElementNS("http://www.w3.org/2000/svg","g");V.appendChild(z),z=V}if(j){const V=document.createElementNS("http://www.w3.org/2000/svg","g");V.appendChild(j),j=V}if(!z&&!j){const V=this.getShapePageBounds(D),X=window.document.createElementNS("http://www.w3.org/2000/svg","rect");X.setAttribute("width",V.width+""),X.setAttribute("height",V.height+""),X.setAttribute("fill",c.solid),X.setAttribute("stroke",c.grey.pattern),X.setAttribute("stroke-width","1"),z=X}let F=this.getShapePageTransform(D).toCssString();"scale"in D.props&&D.props.scale!==1&&(F=`${F} scale(${D.props.scale}, ${D.props.scale})`),z==null||z.setAttribute("transform",F),j==null||j.setAttribute("transform",F),z==null||z.setAttribute("opacity",_+""),j==null||j.setAttribute("opacity",_+"");const Y=this.getShapeMask(D.id);if(Y){const V=document.createElementNS("http://www.w3.org/2000/svg","clipPath");v.appendChild(V);const X=Ue();V.id=X;const ae=document.createElementNS("http://www.w3.org/2000/svg","path");if(ae.setAttribute("d",`M${Y.map(({x:ye,y:Ie})=>`${ye},${Ie}`).join("L")}Z`),V.appendChild(ae),z){const ye=document.createElementNS("http://www.w3.org/2000/svg","g");ye.setAttribute("clip-path",`url(#${X})`),ye.appendChild(z),z=ye}if(j){const ye=document.createElementNS("http://www.w3.org/2000/svg","g");ye.setAttribute("clip-path",`url(#${X})`),ye.appendChild(j),j=ye}}const K=[];return z&&K.push({zIndex:A,element:z}),j&&K.push({zIndex:T,element:j}),K}))).flat();await Promise.all(x.values());for(const{element:I}of P.sort((_,A)=>_.zIndex-A.zIndex))S.appendChild(I);return S}_updateInputsFromEvent(t){var m;const{previousScreenPoint:r,previousPagePoint:o,currentScreenPoint:s,currentPagePoint:i}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture($t),{x:l,y:c,z:u}=this.getCamera(),d=t.point.x-a.x,h=t.point.y-a.y,p=t.point.z;r.setTo(s),o.setTo(i),s.set(d,h),i.set(d/u-l,h/u-c,p??.5),this.inputs.isPen=t.type==="pointer"&&t.isPen,t.name==="pointer_down"&&this.inputs.pointerVelocity.set(0,0),this.store.put([{id:Zh,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===Bx.CAMERA_MOVE?((m=this.store.get(Zh))==null?void 0:m.lastActivityTimestamp)??Date.now():Date.now(),meta:{}}])}cancel(){return this.dispatch({type:"misc",name:"cancel"}),this}interrupt(){return this.dispatch({type:"misc",name:"interrupt"}),this}complete(){return this.dispatch({type:"misc",name:"complete"}),this}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}}ue([Z],ce.prototype,"getCanUndo",1);ue([Z],ce.prototype,"getCanRedo",1);ue([Z],ce.prototype,"_getArrowBindingsIndex",1);ue([Z],ce.prototype,"getArrowInfoCache",1);ue([Z],ce.prototype,"getPath",1);ue([Z],ce.prototype,"getCurrentTool",1);ue([Z],ce.prototype,"getCurrentToolId",1);ue([Z],ce.prototype,"getDocumentSettings",1);ue([Z],ce.prototype,"getInstanceState",1);ue([Z],ce.prototype,"getOpenMenus",1);ue([Z],ce.prototype,"getIsMenuOpen",1);ue([Z],ce.prototype,"getPageStates",1);ue([Z],ce.prototype,"_getPageStatesQuery",1);ue([Z],ce.prototype,"getCurrentPageState",1);ue([Z],ce.prototype,"_getCurrentPageStateId",1);ue([Z],ce.prototype,"getSelectedShapeIds",1);ue([Z],ce.prototype,"getSelectedShapes",1);ue([Z],ce.prototype,"getOnlySelectedShape",1);ue([Z],ce.prototype,"getSelectionPageBounds",1);ue([Z],ce.prototype,"getSelectionRotation",1);ue([Z],ce.prototype,"getSelectionRotatedPageBounds",1);ue([Z],ce.prototype,"getFocusedGroupId",1);ue([Z],ce.prototype,"getFocusedGroup",1);ue([Z],ce.prototype,"getEditingShapeId",1);ue([Z],ce.prototype,"getEditingShape",1);ue([Z],ce.prototype,"getHoveredShapeId",1);ue([Z],ce.prototype,"getHoveredShape",1);ue([Z],ce.prototype,"getHintingShapeIds",1);ue([Z],ce.prototype,"getHintingShape",1);ue([Z],ce.prototype,"getErasingShapeIds",1);ue([Z],ce.prototype,"getErasingShapes",1);ue([Z],ce.prototype,"getCameraId",1);ue([Z],ce.prototype,"getCamera",1);ue([Z],ce.prototype,"getZoomLevel",1);ue([Z],ce.prototype,"getViewportScreenBounds",1);ue([Z],ce.prototype,"getViewportScreenCenter",1);ue([Z],ce.prototype,"getViewportPageBounds",1);ue([Z],ce.prototype,"getViewportPageCenter",1);ue([Z],ce.prototype,"getRenderingShapes",1);ue([Z],ce.prototype,"_getAllPagesQuery",1);ue([Z],ce.prototype,"getPages",1);ue([Z],ce.prototype,"_getAllAssetsQuery",1);ue([Z],ce.prototype,"_getShapeGeometryCache",1);ue([Z],ce.prototype,"_getShapeOutlineSegmentsCache",1);ue([Z],ce.prototype,"_getShapeHandlesCache",1);ue([Z],ce.prototype,"_getShapePageTransformCache",1);ue([Z],ce.prototype,"_getShapePageBoundsCache",1);ue([Z],ce.prototype,"_getShapeClipPathCache",1);ue([Z],ce.prototype,"_getShapeMaskCache",1);ue([Z],ce.prototype,"getCurrentPageBounds",1);ue([Z],ce.prototype,"getCurrentPageShapes",1);ue([Z],ce.prototype,"getCurrentPageShapesSorted",1);ue([Z],ce.prototype,"getCurrentPageRenderingShapesSorted",1);ue([Z({isEqual:(e,n)=>e.equals(n)})],ce.prototype,"getSharedStyles",1);ue([Z],ce.prototype,"getSharedOpacity",1);function rd(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:fo})}function El(e,n){if(!n)return e;let t=null;for(const[r,o]of Object.entries(n))if(o!==void 0)switch(r){case"id":case"type":continue;default:if(o!==e[r])if(t||(t={...e}),r==="props"){const s={...e.props};for(const[i,a]of Object.entries(o))a!==void 0&&(s[i]=a);t.props=s}else if(r==="meta"){const s={...e.meta};for(const[i,a]of Object.entries(o))a!==void 0&&(s[i]=a);t.meta=s}else t[r]=o}return t??e}function af(){const e=U();return G("isDarkMode",()=>e.user.getIsDarkMode(),[e])}const bb="<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'/>",Pb="<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 Qo(e,n,t,r,o,s=16,i=16){const a=(-t-n)*(Te/180),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,d=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${d}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${n+t} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const hN=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],pN={none:()=>"none","ew-resize":(e,n,t)=>Qo(Pb,e,0,n,t),"ns-resize":(e,n,t)=>Qo(Pb,e,90,n,t),"nesw-resize":(e,n,t)=>Qo(bb,e,0,n,t),"nwse-resize":(e,n,t)=>Qo(bb,e,90,n,t),"nwse-rotate":(e,n,t)=>Qo(od,e,0,n,t),"nesw-rotate":(e,n,t)=>Qo(od,e,90,n,t),"senw-rotate":(e,n,t)=>Qo(od,e,180,n,t),"swne-rotate":(e,n,t)=>Qo(od,e,270,n,t)};function Mn(e,n=0,t="black"){return pN[e](KD(n),!1,t)}function fN(){const e=U(),n=un(),t=af();ii("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(hN.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Mn(r,o,t?"white":"black"))},[e,n,t])}function gN(){const e=U(),n=un(),t=af(),r=G(Oe.forceSrgb);ne.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 mN(e){const n=w.useRef();return w.useLayoutEffect(()=>{n.current=e}),w.useDebugValue(e),w.useCallback((...t)=>{const r=n.current;return Io(r,"fn does not exist"),r(...t)},[])}function yN(e){const n=U(),t=un();w.useLayoutEffect(()=>{e?(n.getInstanceState().isFocused||n.updateInstanceState({isFocused:!0}),n.getContainer().focus()):n.getInstanceState().isFocused&&n.updateInstanceState({isFocused:!1})},[n,t,e])}function SN(){const[e,n]=w.useState(0);w.useEffect(()=>n(t=>t+1),[])}const ba="TLDRAW_TAB_ID_v2",Mt=globalThis.window;function vN(){return Mt?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(Mt.navigator.platform)||Mt.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const fp=(Mt==null?void 0:Mt[ba])??(Mt==null?void 0:Mt.sessionStorage[ba])??"TLDRAW_INSTANCE_STATE_V1_"+Ue();Mt&&(Mt[ba]=fp,vN()?Mt.sessionStorage[ba]=fp:delete Mt.sessionStorage[ba]);Mt==null||Mt.addEventListener("beforeunload",()=>{Mt.sessionStorage[ba]=fp});const wN={Initial:0},kc=wN.Initial,Ik=we({version:he,currentPageId:Sc,isFocusMode:ve,exportBackground:ve,isDebugMode:ve,isToolLocked:ve,isGridMode:ve,pageStates:Ot(we({pageId:Sc,camera:we({x:he,y:he,z:he}),selectedShapeIds:Ot(vr),focusedGroupId:vr.nullable()}))}),xN=$e({currentVersion:kc});function bN(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;const n=Pv({value:e,fromVersion:e.version,toVersion:kc,migrations:xN});if(n.type==="error")return console.warn(n.reason),null;const t={...n.value,version:kc};try{Ik.validate(t)}catch(r){return console.warn(r),null}return t}function PN(e){const n=e.query.ids("page");return Z("sessionStateSnapshot",()=>{const t=e.get($t);if(!t)return null;const r=[...n.get()];return{version:kc,currentPageId:t.currentPageId,exportBackground:t.exportBackground,isFocusMode:t.isFocusMode,isDebugMode:t.isDebugMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,pageStates:r.map(o=>{const s=e.get(Kt.createId(o)),i=e.get(Vt.createId(o));return{pageId:o,camera:{x:(i==null?void 0:i.x)??0,y:(i==null?void 0:i.y)??0,z:(i==null?void 0:i.z)??1},selectedShapeIds:(s==null?void 0:s.selectedShapeIds)??[],focusedGroupId:(s==null?void 0:s.focusedGroupId)??null}})}})}function CN(e,n){const t=bN(n);if(!t)return;const r=e.allRecords().filter(i=>i.typeName==="instance_page_state"||i.typeName==="camera"),o={added:{},updated:{},removed:{...SE(r.map(i=>[i.id,i]))}};e.has($t)&&(o.removed[$t]=e.get($t));const s={removed:{},updated:{},added:{[$t]:e.schema.types.instance.create({id:$t,currentPageId:t.currentPageId,isDebugMode:t.isDebugMode,isFocusMode:t.isFocusMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,exportBackground:t.exportBackground})}};for(const i of t.pageStates){const a=Vt.createId(i.pageId),l=Kt.createId(i.pageId);s.added[a]=Vt.create({id:Vt.createId(i.pageId),x:i.camera.x,y:i.camera.y,z:i.camera.z}),s.added[l]=Kt.create({id:Kt.createId(i.pageId),pageId:i.pageId,selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId})}br(()=>{e.applyDiff(tf([o,s])),e.ensureStoreIsUsable()})}function EN(e){var o;const n=[];for(const s of Object.values(e))(o=s.typeName)!=null&&o.match(/^(instance.*|pointer|camera)$/)&&n.push(s);const t=n.filter(s=>s.typeName==="instance"&&s.id!==$t)[0];if(!t)return null;const r={version:kc,currentPageId:t.currentPageId,exportBackground:!!t.exportBackground,isFocusMode:!!t.isFocusMode,isDebugMode:!!t.isDebugMode,isToolLocked:!!t.isToolLocked,isGridMode:!1,pageStates:n.filter(s=>s.typeName==="instance_page_state"&&s.instanceId===t.id).map(s=>{const i=e[s.cameraId]??{x:0,y:0,z:1};return{pageId:s.pageId,camera:{x:i.x,y:i.y,z:i.z},selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId}})};try{return Ik.validate(r),r}catch{return null}}function kN(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
54
+
55
+ Keep seeing this message?
56
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
57
+ • If your hard disk is full, try clearing up some space and then reload the page.`)}function IN(){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.
58
+
59
+ Keep seeing this message?
60
+ • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const _N=(e,n)=>n.some(t=>e instanceof t);let Cb,Eb;function TN(){return Cb||(Cb=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function $N(){return Eb||(Eb=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const _k=new WeakMap,Ry=new WeakMap,Tk=new WeakMap,Eg=new WeakMap,Vv=new WeakMap;function AN(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(_o(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return n.then(t=>{t instanceof IDBCursor&&_k.set(t,e)}).catch(()=>{}),Vv.set(n,e),n}function MN(e){if(Ry.has(e))return;const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{t(),o()},i=()=>{r(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});Ry.set(e,n)}let Dy={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return Ry.get(e);if(n==="objectStoreNames")return e.objectStoreNames||Tk.get(e);if(n==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return _o(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 ON(e){Dy=e(Dy)}function RN(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(kg(this),n,...t);return Tk.set(r,n.sort?n.sort():[n]),_o(r)}:$N().includes(e)?function(...n){return e.apply(kg(this),n),_o(_k.get(this))}:function(...n){return _o(e.apply(kg(this),n))}}function DN(e){return typeof e=="function"?RN(e):(e instanceof IDBTransaction&&MN(e),_N(e,TN())?new Proxy(e,Dy):e)}function _o(e){if(e instanceof IDBRequest)return AN(e);if(Eg.has(e))return Eg.get(e);const n=DN(e);return n!==e&&(Eg.set(e,n),Vv.set(n,e)),n}const kg=e=>Vv.get(e);function jN(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=_o(i);return r&&i.addEventListener("upgradeneeded",l=>{r(_o(i.result),l.oldVersion,l.newVersion,_o(i.transaction),l)}),t&&i.addEventListener("blocked",l=>t(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),o&&l.addEventListener("versionchange",c=>o(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function LN(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),_o(t).then(()=>{})}const NN=["get","getKey","getAll","getAllKeys","count"],FN=["put","add","delete","clear"],Ig=new Map;function kb(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(Ig.get(n))return Ig.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=FN.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||NN.includes(t)))return;const s=async function(i,...a){const l=this.transaction(i,o?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[t](...a),o&&l.done]))[0]};return Ig.set(n,s),s}ON(e=>({...e,get:(n,t,r)=>kb(n,t)||e.get(n,t,r),has:(n,t)=>!!kb(n,t)||e.has(n,t)}));const lf="TLDRAW_DOCUMENT_v2",$k="TLDRAW_DB_NAME_INDEX_v2",Me={Records:"records",Schema:"schema",SessionState:"session_state"};async function cf(e,n){VN(e);const t=await jN(e,3,{upgrade(r){r.objectStoreNames.contains(Me.Records)||r.createObjectStore(Me.Records),r.objectStoreNames.contains(Me.Schema)||r.createObjectStore(Me.Schema),r.objectStoreNames.contains(Me.SessionState)||r.createObjectStore(Me.SessionState)}});try{return await n(t)}finally{t.close()}}async function zN({persistenceKey:e,sessionId:n,didCancel:t}){const r=lf+e;if(Kv().includes(r))return await HN({persistenceKey:e,didCancel:t}),await cf(r,async o=>{var d,h;if(t!=null&&t())return;const s=o.transaction([Me.Records,Me.Schema,Me.SessionState],"readonly"),i=s.objectStore(Me.Records),a=s.objectStore(Me.Schema),l=s.objectStore(Me.SessionState);let c=n?(d=await l.get(n))==null?void 0:d.snapshot:null;c||(c=(h=(await l.getAll()).sort((m,f)=>m.updatedAt-f.updatedAt).pop())==null?void 0:h.snapshot);const u={records:await i.getAll(),schema:await a.get(Me.Schema),sessionStateSnapshot:c};if(t!=null&&t()){s.abort();return}return await s.done,u})}async function BN({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=lf+e;await cf(i,async a=>{const l=a.transaction([Me.Records,Me.Schema,Me.SessionState],"readwrite"),c=l.objectStore(Me.Records),u=l.objectStore(Me.Schema),d=l.objectStore(Me.SessionState);for(const[h,p]of Object.entries(t.added))await c.put(p,h);for(const[h,p]of Object.values(t.updated))await c.put(p,p.id);for(const h of Object.keys(t.removed))await c.delete(h);if(u.put(n.serialize(),Me.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function UN({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=lf+e;await cf(i,async a=>{const l=a.transaction([Me.Records,Me.Schema,Me.SessionState],"readwrite"),c=l.objectStore(Me.Records),u=l.objectStore(Me.Schema),d=l.objectStore(Me.SessionState);await c.clear();for(const[h,p]of Object.entries(t))await c.put(p,h);if(u.put(n.serialize(),Me.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function HN({persistenceKey:e,didCancel:n}){await cf(lf+e,async t=>{const r=t.transaction([Me.SessionState],"readwrite"),o=r.objectStore(Me.SessionState),s=(await o.getAll()).sort((a,l)=>a.updatedAt-l.updatedAt);if(s.length<10){await r.done;return}const i=s.slice(0,s.length-10);for(const{id:a}of i)await o.delete(a);if(n!=null&&n())return r.abort();await r.done})}function Kv(){const e=JSON.parse((window==null?void 0:window.localStorage.getItem($k))||"[]")??[];return Array.isArray(e)?e:[]}function VN(e){const n=new Set(Kv());n.add(e),window==null||window.localStorage.setItem($k,JSON.stringify([...n]))}const KN=350,WN=1e4,Ib=Symbol("UPDATE_INSTANCE_STATE"),GN=e=>e;class YN{constructor(n){y(this,"onmessage")}postMessage(n){}close(){}}const XN=typeof BroadcastChannel>"u"?YN:BroadcastChannel;class qN{constructor(n,{persistenceKey:t,sessionId:r=fp,onLoad:o,onLoadError:s},i=new XN(`tldraw-tab-sync-${t}`)){y(this,"disposables",new Set);y(this,"diffQueue",[]);y(this,"didDispose",!1);y(this,"shouldDoFullDBWrite",!0);y(this,"isReloading",!1);y(this,"persistenceKey");y(this,"sessionId");y(this,"serializedSchema");y(this,"isDebugging",!1);y(this,"documentTypes");y(this,"$sessionStateSnapshot");y(this,"initTime",Date.now());y(this,"isPersisting",!1);y(this,"didLastWriteError",!1);y(this,"scheduledPersistTimeout",null);this.store=n,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=PN(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(GN({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(Ib),this.schedulePersist()},{scope:"session"})),this.connect(o,s),this.documentTypes=new Set(Object.values(this.store.schema.types).filter(a=>a.scope==="document").map(a=>a.typeName))}debug(...n){this.isDebugging&&console.debug(...n)}async connect(n,t){this.debug("connecting");let r;try{r=await zN({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),IN(),typeof window<"u"&&window.location.reload();return}if(this.debug("loaded data from store",r,"didDispose",this.didDispose),!this.didDispose)try{if(r){const o=Object.fromEntries(r.records.map(a=>[a.id,a])),s=r.sessionStateSnapshot??EN(o),i=this.store.schema.migrateStoreSnapshot({store:o,schema:r.schema??this.store.schema.serializeEarliestVersion()});if(i.type==="error"){console.error("failed to migrate store",i),t(new Error(`Failed to migrate store: ${i.reason}`));return}this.store.mergeRemoteChanges(()=>{this.store.put(Object.values(i.value).filter(a=>this.documentTypes.has(a.typeName)),"initialize")}),s&&CN(this.store,s)}this.channel.onmessage=({data:o})=>{var a,l;this.debug("got message",o);const s=o,i=jR(this.serializedSchema,s.schema??this.store.schema.serializeEarliestVersion());if(i===-1){if(Date.now()-this.initTime<5e3){t(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}else if(i===1){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}s.type==="diff"&&(this.debug("applying diff"),br(()=>{this.store.mergeRemoteChanges(()=>{this.store.applyDiff(s.changes),this.store.ensureStoreIsUsable()})}))},this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.disposables.add(()=>{this.channel.close()}),n(this)}catch(o){if(this.debug("error loading data from store",o),this.didDispose)return;t(o);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(n=>n())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?WN:KN))}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(){Io(!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 UN({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=tf(n.filter(r=>r!==Ib));await BN({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),kN(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function Ak({initialData:e,defaultName:n="",...t}){const r="schema"in t&&t.schema?t.schema:T3({shapes:ZN(xk("shapeUtils"in t&&t.shapeUtils?t.shapeUtils:[]))});return new wE({schema:r,initialData:e,props:{defaultName:n}})}function ZN(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function _b(e){const n=Ak(e);return e.snapshot&&n.loadSnapshot(e.snapshot),{store:n,opts:e}}function QN(e){const[n,t]=w.useState(()=>_b(e));if(!vE(n.opts,e)){const r=_b(e);return t(r),r.store}return n.store}function JN({persistenceKey:e,sessionId:n,...t}){const[r,o]=w.useState(null),s=QN(t);return w.useEffect(()=>{const i=Ue();if(!e){o({id:i,storeWithStatus:{status:"not-synced",store:s}});return}o({id:i,storeWithStatus:{status:"loading"}});const a=c=>{o(u=>(u==null?void 0:u.id)===i?{id:i,storeWithStatus:c}:u)},l=new qN(s,{sessionId:n,persistenceKey:e,onLoad(){a({store:s,status:"synced-local"})},onLoadError(c){a({status:"error",error:c})}});return()=>{o(c=>(c==null?void 0:c.id)===i?null:c),l.close()}},[e,s,n]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}let Mk=!1;if(typeof window<"u"){const e=window.navigator.userAgent,n=!!e.match(/iPad/i)||!!e.match(/iPhone/i),t=!!e.match(/WebKit/i);Mk=n&&t&&!e.match(/CriOS/i)}function e4(){const e=U();w.useEffect(()=>{if(!Mk)return;function n(t){(t.target instanceof HTMLInputElement&&t.target.type==="text"||t.target instanceof HTMLTextAreaElement)&&e.complete()}return document.addEventListener("focusout",n),()=>document.removeEventListener("focusout",n)},[e])}function t4(){const e=U(),n=un();w.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=yE(t,100),o=new Ga("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach()}},[e,n])}const n4=[],r4=[],o4=w.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=ne.useState(null),l=w.useMemo(()=>o??gk(),[o]),c=(t==null?void 0:t.ErrorFallback)===void 0?UE:t==null?void 0:t.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??n4,tools:s.tools??r4,components:t};return g.jsx("div",{ref:a,draggable:!1,className:fe("tl-container tl-theme__light",r),onPointerDown:Dt,tabIndex:-1,children:g.jsx(bc,{fallback:c,onError:d=>xv(d,{tags:{origin:"react.tldraw-before-app"}}),children:i&&g.jsx(OD,{container:i,children:g.jsx(uj,{overrides:t,children:n?n instanceof wE?g.jsx(Rk,{...u,store:n,user:l}):g.jsx(Ok,{...u,store:n,user:l}):g.jsx(s4,{...u,store:n,user:l})})})})})});function s4(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,persistenceKey:s,sessionId:i,user:a}=e,l=JN({shapeUtils:o,initialData:r,persistenceKey:s,sessionId:i,defaultName:n,snapshot:t});return g.jsx(Ok,{...e,store:l,user:a})}const Ok=w.memo(function({store:n,user:t,...r}){var s;const o=un();switch(w.useLayoutEffect(()=>{t.userPreferences.get().isDarkMode&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,t]),n.status){case"error":throw n.error;case"loading":{const i=((s=r.components)==null?void 0:s.LoadingScreen)??g6;return g.jsx(i,{})}}return g.jsx(Rk,{...r,store:n.store,user:t})});function Rk({onMount:e,children:n,store:t,tools:r,shapeUtils:o,user:s,initialState:i,autoFocus:a=!0,inferDarkMode:l}){const{ErrorFallback:c}=Pt(),u=un(),[d,h]=w.useState(null);w.useLayoutEffect(()=>{const m=new ce({store:t,shapeUtils:o,tools:r,getContainer:()=>u,user:s,initialState:i,inferDarkMode:l});return window.app=m,window.editor=m,h(m),()=>{m.dispose()}},[u,o,r,t,s,i,l]);const p=w.useSyncExternalStore(w.useCallback(m=>d?(d.on("crash",m),()=>d.off("crash",m)):()=>{},[d]),()=>(d==null?void 0:d.getCrashingError())??null);return d?g.jsx(bc,{fallback:c,onError:m=>d.annotateError(m,{origin:"react.tldraw",willCrashApp:!0}),children:p?g.jsx(a4,{crashingError:p}):g.jsx(Mv.Provider,{value:d,children:g.jsx(i4,{autoFocus:a,onMount:e,children:n})})}):null}function i4({children:e,onMount:n,autoFocus:t}){return t4(),fN(),gN(),e4(),SN(),yN(t),c4(n),U().updateViewportScreenBounds(),e??g.jsx(Fv,{})}function a4({crashingError:e}){throw e}function Dk({children:e}){const{Spinner:n}=Pt();return g.jsxs("div",{className:"tl-loading",children:[n?g.jsx(n,{}):null,e]})}function l4({children:e}){return g.jsx("div",{className:"tl-loading",children:e})}function c4(e){const n=U(),t=mN(r=>{const o=e==null?void 0:e(r);return r.emit("mount"),window.tldrawReady=!0,o});ne.useLayoutEffect(()=>{if(n)return t==null?void 0:t(n)},[n,t])}function pi({children:e,className:n="",...t}){return g.jsx("div",{...t,className:`tl-html-container ${n}`,children:e})}je(function({x:n=0,y:t=0,rotation:r=0,...o}){const s=U(),i=w.useRef(null),a=s.getCamera();return w.useLayoutEffect(()=>{const{x:l,y:c,z:u}=s.getCamera(),d=i.current;d&&l!==void 0&&(d.style.transform=`translate(${l}px, ${c}px) scale(${u}) rotate(${r}rad) translate(${n}px, ${t}px)`)},[a,s,n,t,r]),g.jsx("div",{ref:i,...o,className:fe("tl-positioned",o.className)})});function jk(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=t;let d=e.props.w*s,h=e.props.h*i;const p=new C(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(h>0){if(h<c){switch(o){case"top_left":case"top":case"top_right":{p.y=h-c;break}case"right":case"left":{p.y=(h-c)/2;break}default:p.y=0}h=c}}else if(p.y=h,h=-h,h<c){switch(o){case"top_left":case"top":case"top_right":{p.y=-h;break}default:p.y=-c}h=c}const{x:m,y:f}=p.rot(e.rotation).add(r);return{x:m,y:f,props:{w:Math.min(l,d),h:Math.min(u,h)}}}class el extends Tr{constructor(){super(...arguments);y(this,"onResize",(t,r)=>jk(t,r))}getGeometry(t){return new Es({width:t.props.w,height:t.props.h,isFilled:!0})}}var Zm;let u4=(Zm=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(Zm,"id","idle"),Zm);var Qm;let d4=(Qm=class extends oe{constructor(){super(...arguments);y(this,"markId","");y(this,"wasFocusedOnEnter",!1);y(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});y(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=We();this.markId=`creating:${s}`,this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(s),this.editor.setCurrentTool("select.resizing",{...t,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:this.parent.onCreate})}});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(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=We();this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:r,x:t.x,y:t.y}]);const s=this.editor.getShape(o),{w:i,h:a}=this.editor.getShapeUtil(s).getDefaultProps(),l=new C(i/2,a/2),c=this.editor.getShapeParentTransform(s);c&&l.rot(-c.rotation()),this.editor.updateShapes([{id:o,type:r,x:s.x-l.x,y:s.y-l.y}]),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},y(Qm,"id","pointing"),Qm);class th extends oe{constructor(){super(...arguments);y(this,"onCreate")}}y(th,"id","box"),y(th,"initial","idle"),y(th,"children",()=>[u4,d4]);function Lk(e,n){const t=w.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Tb(e){return Lk(e,vR)}function h4(e){return Lk(e,vE)}function $b(e){const n=U();return G("isCropping",()=>n.getCroppingShapeId()===e,[n,e])}function uf(e){const n=U();return G("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function Ur(e){const n=U();return w.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===2){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...vn(c)});return}if(c.button!==0)return;const u=sp(c.currentTarget);function d(){u.removeEventListener("pointerup",d),cu(u,c)}lu(u,c),u.addEventListener("pointerup",d),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...vn(c)}),Dt(c)};let s,i;function a(c){c.isKilled||c.button===0&&(c.clientX===s&&c.clientY===i||(s=c.clientX,i=c.clientY,n.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...vn(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...vn(c)})}}},[n,e])}const p4=20,f4=8;function Wv(e,n=p4){return Math.max(f4,Math.ceil(e/n))}class Nk extends bi{constructor(t){super({...t,isFilled:!1,isClosed:!1});y(this,"_center");y(this,"radius");y(this,"start");y(this,"end");y(this,"measure");y(this,"length");y(this,"angleStart");y(this,"angleEnd");const{center:r,radius:o,sweepFlag:s,largeArcFlag:i,start:a,end:l}=t;if(a.equals(l))throw Error("Arc must have different start and end points.");this.angleStart=C.Angle(r,a),this.angleEnd=C.Angle(r,l),this.measure=WD(this.angleStart,this.angleEnd,s,i),this.length=this.measure*o,this.start=a,this.end=l,this._center=r,this.radius=o}nearestPoint(t){const{_center:r,measure:o,radius:s,angleEnd:i,angleStart:a,start:l,end:c}=this,u=_y(o,a,i,r.angle(t));if(u<=0)return l;if(u>=1)return c;const d=r.clone().add(t.clone().sub(r).uni().mul(s));let h=1/0,p;for(const m of[l,c,d])t.dist(m)<h&&(p=m,h=t.dist(m));if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(t,r,o){const{_center:s,radius:i,measure:a,angleStart:l,angleEnd:c}=this,u=sf(t,r,s,i);return u===null?!1:u.some(d=>{const h=_y(a,l,c,s.angle(d));return h>=0&&h<=1})}getVertices(){const{_center:t,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let l=0,c=Wv(Math.abs(o));l<c+1;l++){const u=l/c*r,d=i+u;a.push(di(t,s,d))}return a}}class Gv extends bi{constructor(t){super({isClosed:!0,...t});y(this,"_center");y(this,"radius");y(this,"x");y(this,"y");this.config=t;const{x:r=0,y:o=0,radius:s}=t;this.x=r,this.y=o,this._center=new C(s+r,s+o),this.radius=s}getBounds(){return new re(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,o=Re*r,s=[];for(let i=0,a=Wv(o);i<a;i++){const l=i/a*Re;s.push(di(t,r,l))}return s}nearestPoint(t){const{_center:r,radius:o}=this;return r.equals(t)?C.AddXY(r,o,0):r.clone().add(t.clone().sub(r).uni().mul(o))}hitTestLineSegment(t,r,o){const{_center:s,radius:i}=this;return sf(t,r,s,i)!==null}}class g4 extends Pi{constructor(t){const{start:r,cp1:o,cp2:s,end:i}=t;super({...t,points:[r,i]});y(this,"a");y(this,"b");y(this,"c");y(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const t=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;t.push(new C((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*o.x+3*(1-c)*(c*c)*s.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*o.y+3*(1-c)*(c*c)*s.y+c*c*c*i.y))}return t}midPoint(){return m4(this,.5)}nearestPoint(t){let r,o=1/0;for(const s of this.segments){const i=s.nearestPoint(t),a=i.dist(t);a<o&&(r=i,o=a)}if(!r)throw Error("nearest point not found");return r}}function m4(e,n){const{a:t,b:r,c:o,d:s}=e;return new C((1-n)*(1-n)*(1-n)*t.x+3*((1-n)*(1-n))*n*r.x+3*(1-n)*(n*n)*o.x+n*n*n*s.x,(1-n)*(1-n)*(1-n)*t.y+3*((1-n)*(1-n))*n*r.y+3*(1-n)*(n*n)*o.y+n*n*n*s.y)}class nh extends bi{constructor(t){super({...t,isClosed:!1,isFilled:!1});y(this,"points");y(this,"_segments");y(this,"_length");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:t}=this,r=t.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?t[0]:t[i-1],l=t[i],c=t[i+1],u=i===o?c:t[i+2],d=l,h=i===0?a:new C(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),p=i===o?c:new C(c.x-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),m=c;this._segments.push(new g4({start:d,cp1:h,cp2:p,end:m}))}}return this._segments}get length(){return this._length||(this._length=this.segments.reduce((t,r)=>t+r.length,0)),this._length}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;for(const s of this.segments){const i=s.nearestPoint(t),a=i.dist(t);a<o&&(r=i,o=a)}if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r,o){return this.segments.some(s=>s.hitTestLineSegment(t,r,o))}}class Fk extends bi{constructor(t){super({...t,isClosed:!0});y(this,"w");y(this,"h");y(this,"_edges");this.config=t;const{width:r,height:o}=t;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:t}=this;this._edges=[];for(let r=0,o=t.length;r<o;r++){const s=t[r],i=t[(r+1)%o];this._edges.push(new Ec({start:s,end:i}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),o=t/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=Te*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),l=Wv(a),c=Re/l,u=Math.cos(c),d=Math.sin(c);let h=0,p=1,m=0,f=1;const S=Array(l);for(let v=0;v<l;v++)S[v]=new C(o+o*p,s+s*h),m=d*p+u*h,f=u*p-d*h,h=m,p=f;return S}nearestPoint(t){let r,o=1/0;for(const s of this.edges){const i=s.nearestPoint(t),a=i.dist(t);a<o&&(r=i,o=a)}if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r,o){return this.edges.some(s=>s.hitTestLineSegment(t,r,o))}getBounds(){return new re(0,0,this.w,this.h)}}class y4 extends Fk{constructor(n){super({...n}),this.config=n}getVertices(){const n=Math.max(1,this.w),t=Math.max(1,this.h),r=n/2,o=t/2,s=10,i=Array(s*2-2);if(t>n)for(let a=0;a<s-1;a++){const l=-Te+Te*a/(s-2),c=Te*a/(s-2);i[a]=new C(r+r*Math.cos(l),r+r*Math.sin(l)),i[a+(s-1)]=new C(r+r*Math.cos(c),t-r+r*Math.sin(c))}else for(let a=0;a<s-1;a++){const l=-Ve+Te*a/(s-2),c=Ve+Te*-a/(s-2);i[a]=new C(n-o+o*Math.cos(l),t-o+o*Math.sin(l)),i[a+(s-1)]=new C(o-o*Math.cos(c),t-o+o*Math.sin(c))}return i}}function Ab(e,n,t,r,o){const s=ED,i=t?kD:0,a=e-i,l=e+i,c=r?0:s,u=o?n:n-s;return a<c?Math.min(1,(c-a)/s):l>u?-Math.min(1,(l-u)/s):0}function Yv(e){if(!e.inputs.isDragging||e.inputs.isPanning)return;const{inputs:{currentScreenPoint:{x:n,y:t}}}=e,r=e.getZoomLevel(),o=e.getViewportScreenBounds(),s=o.w<1e3?.612:1,i=o.h<1e3?.612:1,{isCoarsePointer:a,insets:[l,c,u,d]}=e.getInstanceState(),h=Ab(n,o.w,a,d,c),p=Ab(t,o.h,a,l,u);if(h===0&&p===0)return;const m=e.user.getEdgeScrollSpeed()*CD,f=m*h*s/r,S=m*p*i/r,v=e.getCamera();e.setCamera({x:v.x+f,y:v.y+S})}async function S4({shouldReload:e=!0}={}){sessionStorage.clear(),await Promise.all(Kv().map(n=>LN(n))),localStorage.clear(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=S4);function v4(e,n="_blank"){Ov.openWindow(e,n)}var kl=function(e){return e&&e.Math===Math&&e},_n=kl(typeof globalThis=="object"&&globalThis)||kl(typeof window=="object"&&window)||kl(typeof self=="object"&&self)||kl(typeof Xt=="object"&&Xt)||kl(typeof Xt=="object"&&Xt)||function(){return this}()||Function("return this")(),Xv={},dn=function(e){try{return!!e()}catch{return!0}},w4=dn,js=!w4(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),x4=dn,df=!x4(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),b4=df,sd=Function.prototype.call,Vo=b4?sd.bind(sd):function(){return sd.apply(sd,arguments)},zk={},Bk={}.propertyIsEnumerable,Uk=Object.getOwnPropertyDescriptor,P4=Uk&&!Bk.call({1:2},1);zk.f=P4?function(n){var t=Uk(this,n);return!!t&&t.enumerable}:Bk;var Hk=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},Vk=df,Kk=Function.prototype,jy=Kk.call,C4=Vk&&Kk.bind.bind(jy,jy),Ct=Vk?C4:function(e){return function(){return jy.apply(e,arguments)}},Wk=Ct,E4=Wk({}.toString),k4=Wk("".slice),tl=function(e){return k4(E4(e),8,-1)},I4=Ct,_4=dn,T4=tl,_g=Object,$4=I4("".split),A4=_4(function(){return!_g("z").propertyIsEnumerable(0)})?function(e){return T4(e)==="String"?$4(e,""):_g(e)}:_g,hf=function(e){return e==null},M4=hf,O4=TypeError,nl=function(e){if(M4(e))throw new O4("Can't call method on "+e);return e},R4=A4,D4=nl,pf=function(e){return R4(D4(e))},Tg=typeof document=="object"&&document.all,hn=typeof Tg>"u"&&Tg!==void 0?function(e){return typeof e=="function"||e===Tg}:function(e){return typeof e=="function"},j4=hn,Ei=function(e){return typeof e=="object"?e!==null:j4(e)},$g=_n,L4=hn,N4=function(e){return L4(e)?e:void 0},ff=function(e,n){return arguments.length<2?N4($g[e]):$g[e]&&$g[e][n]},F4=Ct,Gk=F4({}.isPrototypeOf),z4=typeof navigator<"u"&&String(navigator.userAgent)||"",Yk=_n,Ag=z4,Mb=Yk.process,Ob=Yk.Deno,Rb=Mb&&Mb.versions||Ob&&Ob.version,Db=Rb&&Rb.v8,Pr,gp;Db&&(Pr=Db.split("."),gp=Pr[0]>0&&Pr[0]<4?1:+(Pr[0]+Pr[1]));!gp&&Ag&&(Pr=Ag.match(/Edge\/(\d+)/),(!Pr||Pr[1]>=74)&&(Pr=Ag.match(/Chrome\/(\d+)/),Pr&&(gp=+Pr[1])));var B4=gp,jb=B4,U4=dn,H4=_n,V4=H4.String,Xk=!!Object.getOwnPropertySymbols&&!U4(function(){var e=Symbol("symbol detection");return!V4(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&jb&&jb<41}),K4=Xk,qk=K4&&!Symbol.sham&&typeof Symbol.iterator=="symbol",W4=ff,G4=hn,Y4=Gk,X4=qk,q4=Object,Zk=X4?function(e){return typeof e=="symbol"}:function(e){var n=W4("Symbol");return G4(n)&&Y4(n.prototype,q4(e))},Z4=String,Q4=function(e){try{return Z4(e)}catch{return"Object"}},J4=hn,eF=Q4,tF=TypeError,qv=function(e){if(J4(e))return e;throw new tF(eF(e)+" is not a function")},nF=qv,rF=hf,Zv=function(e,n){var t=e[n];return rF(t)?void 0:nF(t)},Mg=Vo,Og=hn,Rg=Ei,oF=TypeError,sF=function(e,n){var t,r;if(n==="string"&&Og(t=e.toString)&&!Rg(r=Mg(t,e))||Og(t=e.valueOf)&&!Rg(r=Mg(t,e))||n!=="string"&&Og(t=e.toString)&&!Rg(r=Mg(t,e)))return r;throw new oF("Can't convert object to primitive value")},Qk={exports:{}},Lb=_n,iF=Object.defineProperty,Qv=function(e,n){try{iF(Lb,e,{value:n,configurable:!0,writable:!0})}catch{Lb[e]=n}return n},aF=_n,lF=Qv,Nb="__core-js_shared__",cF=aF[Nb]||lF(Nb,{}),Jv=cF,Fb=Jv;(Qk.exports=function(e,n){return Fb[e]||(Fb[e]=n!==void 0?n:{})})("versions",[]).push({version:"3.35.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.35.1/LICENSE",source:"https://github.com/zloirock/core-js"});var e0=Qk.exports,uF=nl,dF=Object,mu=function(e){return dF(uF(e))},hF=Ct,pF=mu,fF=hF({}.hasOwnProperty),Ls=Object.hasOwn||function(n,t){return fF(pF(n),t)},gF=Ct,mF=0,yF=Math.random(),SF=gF(1 .toString),Jk=function(e){return"Symbol("+(e===void 0?"":e)+")_"+SF(++mF+yF,36)},vF=_n,wF=e0,zb=Ls,xF=Jk,bF=Xk,PF=qk,na=vF.Symbol,Dg=wF("wks"),CF=PF?na.for||na:na&&na.withoutSetter||xF,Ko=function(e){return zb(Dg,e)||(Dg[e]=bF&&zb(na,e)?na[e]:CF("Symbol."+e)),Dg[e]},EF=Vo,Bb=Ei,Ub=Zk,kF=Zv,IF=sF,_F=Ko,TF=TypeError,$F=_F("toPrimitive"),AF=function(e,n){if(!Bb(e)||Ub(e))return e;var t=kF(e,$F),r;if(t){if(n===void 0&&(n="default"),r=EF(t,e,n),!Bb(r)||Ub(r))return r;throw new TF("Can't convert object to primitive value")}return n===void 0&&(n="number"),IF(e,n)},MF=AF,OF=Zk,eI=function(e){var n=MF(e,"string");return OF(n)?n:n+""},RF=_n,Hb=Ei,Ly=RF.document,DF=Hb(Ly)&&Hb(Ly.createElement),tI=function(e){return DF?Ly.createElement(e):{}},jF=js,LF=dn,NF=tI,nI=!jF&&!LF(function(){return Object.defineProperty(NF("div"),"a",{get:function(){return 7}}).a!==7}),FF=js,zF=Vo,BF=zk,UF=Hk,HF=pf,VF=eI,KF=Ls,WF=nI,Vb=Object.getOwnPropertyDescriptor;Xv.f=FF?Vb:function(n,t){if(n=HF(n),t=VF(t),WF)try{return Vb(n,t)}catch{}if(KF(n,t))return UF(!zF(BF.f,n,t),n[t])};var rl={},GF=js,YF=dn,rI=GF&&YF(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),XF=Ei,qF=String,ZF=TypeError,ki=function(e){if(XF(e))return e;throw new ZF(qF(e)+" is not an object")},QF=js,JF=nI,ez=rI,id=ki,Kb=eI,tz=TypeError,jg=Object.defineProperty,nz=Object.getOwnPropertyDescriptor,Lg="enumerable",Ng="configurable",Fg="writable";rl.f=QF?ez?function(n,t,r){if(id(n),t=Kb(t),id(r),typeof n=="function"&&t==="prototype"&&"value"in r&&Fg in r&&!r[Fg]){var o=nz(n,t);o&&o[Fg]&&(n[t]=r.value,r={configurable:Ng in r?r[Ng]:o[Ng],enumerable:Lg in r?r[Lg]:o[Lg],writable:!1})}return jg(n,t,r)}:jg:function(n,t,r){if(id(n),t=Kb(t),id(r),JF)try{return jg(n,t,r)}catch{}if("get"in r||"set"in r)throw new tz("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var rz=js,oz=rl,sz=Hk,t0=rz?function(e,n,t){return oz.f(e,n,sz(1,t))}:function(e,n,t){return e[n]=t,e},oI={exports:{}},Ny=js,iz=Ls,sI=Function.prototype,az=Ny&&Object.getOwnPropertyDescriptor,n0=iz(sI,"name"),lz=n0&&(function(){}).name==="something",cz=n0&&(!Ny||Ny&&az(sI,"name").configurable),uz={EXISTS:n0,PROPER:lz,CONFIGURABLE:cz},dz=Ct,hz=hn,Fy=Jv,pz=dz(Function.toString);hz(Fy.inspectSource)||(Fy.inspectSource=function(e){return pz(e)});var iI=Fy.inspectSource,fz=_n,gz=hn,Wb=fz.WeakMap,mz=gz(Wb)&&/native code/.test(String(Wb)),yz=e0,Sz=Jk,Gb=yz("keys"),aI=function(e){return Gb[e]||(Gb[e]=Sz(e))},r0={},vz=mz,lI=_n,wz=Ei,xz=t0,zg=Ls,Bg=Jv,bz=aI,Pz=r0,Yb="Object already initialized",zy=lI.TypeError,Cz=lI.WeakMap,mp,Ic,yp,Ez=function(e){return yp(e)?Ic(e):mp(e,{})},kz=function(e){return function(n){var t;if(!wz(n)||(t=Ic(n)).type!==e)throw new zy("Incompatible receiver, "+e+" required");return t}};if(vz||Bg.state){var zr=Bg.state||(Bg.state=new Cz);zr.get=zr.get,zr.has=zr.has,zr.set=zr.set,mp=function(e,n){if(zr.has(e))throw new zy(Yb);return n.facade=e,zr.set(e,n),n},Ic=function(e){return zr.get(e)||{}},yp=function(e){return zr.has(e)}}else{var Hi=bz("state");Pz[Hi]=!0,mp=function(e,n){if(zg(e,Hi))throw new zy(Yb);return n.facade=e,xz(e,Hi,n),n},Ic=function(e){return zg(e,Hi)?e[Hi]:{}},yp=function(e){return zg(e,Hi)}}var cI={set:mp,get:Ic,has:yp,enforce:Ez,getterFor:kz},o0=Ct,Iz=dn,_z=hn,ad=Ls,By=js,Tz=uz.CONFIGURABLE,$z=iI,uI=cI,Az=uI.enforce,Mz=uI.get,Xb=String,rh=Object.defineProperty,Oz=o0("".slice),Rz=o0("".replace),Dz=o0([].join),jz=By&&!Iz(function(){return rh(function(){},"length",{value:8}).length!==8}),Lz=String(String).split("String"),Nz=oI.exports=function(e,n,t){Oz(Xb(n),0,7)==="Symbol("&&(n="["+Rz(Xb(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!ad(e,"name")||Tz&&e.name!==n)&&(By?rh(e,"name",{value:n,configurable:!0}):e.name=n),jz&&t&&ad(t,"arity")&&e.length!==t.arity&&rh(e,"length",{value:t.arity});try{t&&ad(t,"constructor")&&t.constructor?By&&rh(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=Az(e);return ad(r,"source")||(r.source=Dz(Lz,typeof n=="string"?n:"")),e};Function.prototype.toString=Nz(function(){return _z(this)&&Mz(this).source||$z(this)},"toString");var Fz=oI.exports,zz=hn,Bz=rl,Uz=Fz,Hz=Qv,dI=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(zz(t)&&Uz(t,s,r),r.global)o?e[n]=t:Hz(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:Bz.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},hI={},Vz=Math.ceil,Kz=Math.floor,Wz=Math.trunc||function(n){var t=+n;return(t>0?Kz:Vz)(t)},Gz=Wz,Ii=function(e){var n=+e;return n!==n||n===0?0:Gz(n)},Yz=Ii,Xz=Math.max,qz=Math.min,Zz=function(e,n){var t=Yz(e);return t<0?Xz(t+n,0):qz(t,n)},Qz=Ii,Jz=Math.min,pI=function(e){var n=Qz(e);return n>0?Jz(n,9007199254740991):0},e8=pI,yu=function(e){return e8(e.length)},t8=pf,n8=Zz,r8=yu,qb=function(e){return function(n,t,r){var o=t8(n),s=r8(o),i=n8(r,s),a;if(e&&t!==t){for(;s>i;)if(a=o[i++],a!==a)return!0}else for(;s>i;i++)if((e||i in o)&&o[i]===t)return e||i||0;return!e&&-1}},o8={includes:qb(!0),indexOf:qb(!1)},s8=Ct,Ug=Ls,i8=pf,a8=o8.indexOf,l8=r0,Zb=s8([].push),fI=function(e,n){var t=i8(e),r=0,o=[],s;for(s in t)!Ug(l8,s)&&Ug(t,s)&&Zb(o,s);for(;n.length>r;)Ug(t,s=n[r++])&&(~a8(o,s)||Zb(o,s));return o},s0=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],c8=fI,u8=s0,d8=u8.concat("length","prototype");hI.f=Object.getOwnPropertyNames||function(n){return c8(n,d8)};var gI={};gI.f=Object.getOwnPropertySymbols;var h8=ff,p8=Ct,f8=hI,g8=gI,m8=ki,y8=p8([].concat),S8=h8("Reflect","ownKeys")||function(n){var t=f8.f(m8(n)),r=g8.f;return r?y8(t,r(n)):t},Qb=Ls,v8=S8,w8=Xv,x8=rl,b8=function(e,n,t){for(var r=v8(n),o=x8.f,s=w8.f,i=0;i<r.length;i++){var a=r[i];!Qb(e,a)&&!(t&&Qb(t,a))&&o(e,a,s(n,a))}},P8=dn,C8=hn,E8=/#|\.prototype\./,Su=function(e,n){var t=I8[k8(e)];return t===T8?!0:t===_8?!1:C8(n)?P8(n):!!n},k8=Su.normalize=function(e){return String(e).replace(E8,".").toLowerCase()},I8=Su.data={},_8=Su.NATIVE="N",T8=Su.POLYFILL="P",$8=Su,ld=_n,A8=Xv.f,M8=t0,O8=dI,R8=Qv,D8=b8,j8=$8,ol=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,l,c,u;if(r?i=ld:o?i=ld[t]||R8(t,{}):i=ld[t]&&ld[t].prototype,i)for(a in n){if(c=n[a],e.dontCallGetSet?(u=A8(i,a),l=u&&u.value):l=i[a],s=j8(r?a:t+(o?".":"#")+a,e.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;D8(c,l)}(e.sham||l&&l.sham)&&M8(c,"sham",!0),O8(i,a,c,e)}},mI={},L8=fI,N8=s0,F8=Object.keys||function(n){return L8(n,N8)},z8=js,B8=rI,U8=rl,H8=ki,V8=pf,K8=F8;mI.f=z8&&!B8?Object.defineProperties:function(n,t){H8(n);for(var r=V8(t),o=K8(t),s=o.length,i=0,a;s>i;)U8.f(n,a=o[i++],r[a]);return n};var W8=ff,G8=W8("document","documentElement"),Y8=ki,X8=mI,Jb=s0,q8=r0,Z8=G8,Q8=tI,J8=aI,e1=">",t1="<",Uy="prototype",Hy="script",yI=J8("IE_PROTO"),Hg=function(){},SI=function(e){return t1+Hy+e1+e+t1+"/"+Hy+e1},n1=function(e){e.write(SI("")),e.close();var n=e.parentWindow.Object;return e=null,n},e7=function(){var e=Q8("iframe"),n="java"+Hy+":",t;return e.style.display="none",Z8.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(SI("document.F=Object")),t.close(),t.F},cd,oh=function(){try{cd=new ActiveXObject("htmlfile")}catch{}oh=typeof document<"u"?document.domain&&cd?n1(cd):e7():n1(cd);for(var e=Jb.length;e--;)delete oh[Uy][Jb[e]];return oh()};q8[yI]=!0;var vI=Object.create||function(n,t){var r;return n!==null?(Hg[Uy]=Y8(n),r=new Hg,Hg[Uy]=null,r[yI]=n):r=oh(),t===void 0?r:X8.f(r,t)},t7=Ko,n7=vI,r7=rl.f,Vy=t7("unscopables"),Ky=Array.prototype;Ky[Vy]===void 0&&r7(Ky,Vy,{configurable:!0,value:n7(null)});var i0=function(e){Ky[Vy][e]=!0},o7=ol,s7=mu,i7=yu,a7=Ii,l7=i0;o7({target:"Array",proto:!0},{at:function(n){var t=s7(this),r=i7(t),o=a7(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});l7("at");var c7=_n,u7=Ct,vu=function(e,n){return u7(c7[e].prototype[n])},d7=vu;d7("Array","at");var h7=tl,wI=Array.isArray||function(n){return h7(n)==="Array"},p7=TypeError,f7=9007199254740991,g7=function(e){if(e>f7)throw p7("Maximum allowed index exceeded");return e},m7=tl,y7=Ct,S7=function(e){if(m7(e)==="Function")return y7(e)},r1=S7,v7=qv,w7=df,x7=r1(r1.bind),b7=function(e,n){return v7(e),n===void 0?e:w7?x7(e,n):function(){return e.apply(n,arguments)}},P7=wI,C7=yu,E7=g7,k7=b7,xI=function(e,n,t,r,o,s,i,a){for(var l=o,c=0,u=i?k7(i,a):!1,d,h;c<r;)c in t&&(d=u?u(t[c],c,n):t[c],s>0&&P7(d)?(h=C7(d),l=xI(e,n,d,h,l,s-1)-1):(E7(l+1),e[l]=d),l++),c++;return l},bI=xI,I7=Ko,_7=I7("toStringTag"),PI={};PI[_7]="z";var T7=String(PI)==="[object z]",$7=T7,A7=hn,sh=tl,M7=Ko,O7=M7("toStringTag"),R7=Object,D7=sh(function(){return arguments}())==="Arguments",j7=function(e,n){try{return e[n]}catch{}},CI=$7?sh:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=j7(n=R7(e),O7))=="string"?t:D7?sh(n):(r=sh(n))==="Object"&&A7(n.callee)?"Arguments":r},L7=Ct,N7=dn,EI=hn,F7=CI,z7=ff,B7=iI,kI=function(){},II=z7("Reflect","construct"),a0=/^\s*(?:class|function)\b/,U7=L7(a0.exec),H7=!a0.test(kI),Il=function(n){if(!EI(n))return!1;try{return II(kI,[],n),!0}catch{return!1}},_I=function(n){if(!EI(n))return!1;switch(F7(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return H7||!!U7(a0,B7(n))}catch{return!0}};_I.sham=!0;var V7=!II||N7(function(){var e;return Il(Il.call)||!Il(Object)||!Il(function(){e=!0})||e})?_I:Il,o1=wI,K7=V7,W7=Ei,G7=Ko,Y7=G7("species"),s1=Array,X7=function(e){var n;return o1(e)&&(n=e.constructor,K7(n)&&(n===s1||o1(n.prototype))?n=void 0:W7(n)&&(n=n[Y7],n===null&&(n=void 0))),n===void 0?s1:n},q7=X7,TI=function(e,n){return new(q7(e))(n===0?0:n)},Z7=ol,Q7=bI,J7=mu,eB=yu,tB=Ii,nB=TI;Z7({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=J7(this),r=eB(t),o=nB(t,0);return o.length=Q7(o,t,t,r,0,n===void 0?1:tB(n)),o}});var rB=i0;rB("flat");var oB=vu;oB("Array","flat");var sB=ol,iB=bI,aB=qv,lB=mu,cB=yu,uB=TI;sB({target:"Array",proto:!0},{flatMap:function(n){var t=lB(this),r=cB(t),o;return aB(n),o=uB(t,0),o.length=iB(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var dB=i0;dB("flatMap");var hB=vu;hB("Array","flatMap");var pB=CI,fB=String,wu=function(e){if(pB(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return fB(e)},gB=ol,mB=Ct,yB=nl,SB=Ii,vB=wu,wB=dn,xB=mB("".charAt),bB=wB(function(){return"𠮷".at(-2)!=="\uD842"});gB({target:"String",proto:!0,forced:bB},{at:function(n){var t=vB(yB(this)),r=t.length,o=SB(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:xB(t,s)}});var PB=vu;PB("String","at");var CB=ki,$I=function(){var e=CB(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},l0=dn,EB=_n,c0=EB.RegExp,u0=l0(function(){var e=c0("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),kB=u0||l0(function(){return!c0("a","y").sticky}),IB=u0||l0(function(){var e=c0("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),_B={BROKEN_CARET:IB,MISSED_STICKY:kB,UNSUPPORTED_Y:u0},TB=dn,$B=_n,AB=$B.RegExp,MB=TB(function(){var e=AB(".","s");return!(e.dotAll&&e.test(`
61
+ `)&&e.flags==="s")}),OB=dn,RB=_n,DB=RB.RegExp,jB=OB(function(){var e=DB("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),ra=Vo,gf=Ct,LB=wu,NB=$I,FB=_B,zB=e0,BB=vI,UB=cI.get,HB=MB,VB=jB,KB=zB("native-string-replace",String.prototype.replace),Sp=RegExp.prototype.exec,Wy=Sp,WB=gf("".charAt),GB=gf("".indexOf),YB=gf("".replace),Vg=gf("".slice),Gy=function(){var e=/a/,n=/b*/g;return ra(Sp,e,"a"),ra(Sp,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),AI=FB.BROKEN_CARET,Yy=/()??/.exec("")[1]!==void 0,XB=Gy||Yy||AI||HB||VB;XB&&(Wy=function(n){var t=this,r=UB(t),o=LB(n),s=r.raw,i,a,l,c,u,d,h;if(s)return s.lastIndex=t.lastIndex,i=ra(Wy,s,o),t.lastIndex=s.lastIndex,i;var p=r.groups,m=AI&&t.sticky,f=ra(NB,t),S=t.source,v=0,x=o;if(m&&(f=YB(f,"y",""),GB(f,"g")===-1&&(f+="g"),x=Vg(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&WB(o,t.lastIndex-1)!==`
62
+ `)&&(S="(?: "+S+")",x=" "+x,v++),a=new RegExp("^(?:"+S+")",f)),Yy&&(a=new RegExp("^"+S+"$(?!\\s)",f)),Gy&&(l=t.lastIndex),c=ra(Sp,m?a:t,x),m?c?(c.input=Vg(c.input,v),c[0]=Vg(c[0],v),c.index=t.lastIndex,t.lastIndex+=c[0].length):t.lastIndex=0:Gy&&c&&(t.lastIndex=t.global?c.index+c[0].length:l),Yy&&c&&c.length>1&&ra(KB,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&p)for(c.groups=d=BB(null),u=0;u<p.length;u++)h=p[u],d[h[0]]=c[h[1]];return c});var d0=Wy,qB=ol,i1=d0;qB({target:"RegExp",proto:!0,forced:/./.exec!==i1},{exec:i1});var ZB=df,MI=Function.prototype,a1=MI.apply,l1=MI.call,QB=typeof Reflect=="object"&&Reflect.apply||(ZB?l1.bind(a1):function(){return l1.apply(a1,arguments)}),c1=Vo,u1=dI,JB=d0,d1=dn,OI=Ko,e9=t0,t9=OI("species"),Kg=RegExp.prototype,n9=function(e,n,t,r){var o=OI(e),s=!d1(function(){var c={};return c[o]=function(){return 7},""[e](c)!==7}),i=s&&!d1(function(){var c=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[t9]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return c=!0,null},u[o](""),!c});if(!s||!i||t){var a=/./[o],l=n(o,""[e],function(c,u,d,h,p){var m=u.exec;return m===JB||m===Kg.exec?s&&!p?{done:!0,value:c1(a,u,d,h)}:{done:!0,value:c1(c,d,u,h)}:{done:!1}});u1(String.prototype,e,l[0]),u1(Kg,o,l[1])}r&&e9(Kg[o],"sham",!0)},h0=Ct,r9=Ii,o9=wu,s9=nl,i9=h0("".charAt),h1=h0("".charCodeAt),a9=h0("".slice),p1=function(e){return function(n,t){var r=o9(s9(n)),o=r9(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=h1(r,o),i<55296||i>56319||o+1===s||(a=h1(r,o+1))<56320||a>57343?e?i9(r,o):i:e?a9(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},l9={codeAt:p1(!1),charAt:p1(!0)},c9=l9.charAt,u9=function(e,n,t){return n+(t?c9(e,n).length:1)},p0=Ct,d9=mu,h9=Math.floor,Wg=p0("".charAt),p9=p0("".replace),Gg=p0("".slice),f9=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,g9=/\$([$&'`]|\d{1,2})/g,RI=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,l=g9;return o!==void 0&&(o=d9(o),l=f9),p9(s,l,function(c,u){var d;switch(Wg(u,0)){case"$":return"$";case"&":return e;case"`":return Gg(n,0,t);case"'":return Gg(n,i);case"<":d=o[Gg(u,1,-1)];break;default:var h=+u;if(h===0)return c;if(h>a){var p=h9(h/10);return p===0?c:p<=a?r[p-1]===void 0?Wg(u,1):r[p-1]+Wg(u,1):c}d=r[h-1]}return d===void 0?"":d})},f1=Vo,m9=ki,y9=hn,S9=tl,v9=d0,w9=TypeError,x9=function(e,n){var t=e.exec;if(y9(t)){var r=f1(t,e,n);return r!==null&&m9(r),r}if(S9(e)==="RegExp")return f1(v9,e,n);throw new w9("RegExp#exec called on incompatible receiver")},b9=QB,g1=Vo,mf=Ct,P9=n9,C9=dn,E9=ki,k9=hn,I9=hf,_9=Ii,T9=pI,Vi=wu,$9=nl,A9=u9,M9=Zv,O9=RI,R9=x9,D9=Ko,Xy=D9("replace"),j9=Math.max,L9=Math.min,N9=mf([].concat),Yg=mf([].push),m1=mf("".indexOf),y1=mf("".slice),F9=function(e){return e===void 0?e:String(e)},z9=function(){return"a".replace(/./,"$0")==="$0"}(),S1=function(){return/./[Xy]?/./[Xy]("a","$0")==="":!1}(),B9=!C9(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});P9("replace",function(e,n,t){var r=S1?"$":"$0";return[function(s,i){var a=$9(this),l=I9(s)?void 0:M9(s,Xy);return l?g1(l,s,a,i):g1(n,Vi(a),s,i)},function(o,s){var i=E9(this),a=Vi(o);if(typeof s=="string"&&m1(s,r)===-1&&m1(s,"$<")===-1){var l=t(n,i,a,s);if(l.done)return l.value}var c=k9(s);c||(s=Vi(s));var u=i.global,d;u&&(d=i.unicode,i.lastIndex=0);for(var h=[],p;p=R9(i,a),!(p===null||(Yg(h,p),!u));){var m=Vi(p[0]);m===""&&(i.lastIndex=A9(a,T9(i.lastIndex),d))}for(var f="",S=0,v=0;v<h.length;v++){p=h[v];for(var x=Vi(p[0]),b=j9(L9(_9(p.index),a.length),0),P=[],E,k=1;k<p.length;k++)Yg(P,F9(p[k]));var I=p.groups;if(c){var _=N9([x],P,b,a);I!==void 0&&Yg(_,I),E=Vi(b9(s,void 0,_))}else E=O9(x,a,b,P,I,s);b>=S&&(f+=y1(a,S,b)+E,S=b+x.length)}return f+y1(a,S)}]},!B9||!z9||S1);var U9=Ei,H9=tl,V9=Ko,K9=V9("match"),W9=function(e){var n;return U9(e)&&((n=e[K9])!==void 0?!!n:H9(e)==="RegExp")},G9=Vo,Y9=Ls,X9=Gk,q9=$I,v1=RegExp.prototype,Z9=function(e){var n=e.flags;return n===void 0&&!("flags"in v1)&&!Y9(e,"flags")&&X9(v1,e)?G9(q9,e):n},Q9=ol,J9=Vo,f0=Ct,w1=nl,eU=hn,tU=hf,nU=W9,_l=wu,rU=Zv,oU=Z9,sU=RI,iU=Ko,aU=iU("replace"),lU=TypeError,Xg=f0("".indexOf);f0("".replace);var x1=f0("".slice),cU=Math.max;Q9({target:"String",proto:!0},{replaceAll:function(n,t){var r=w1(this),o,s,i,a,l,c,u,d,h,p=0,m=0,f="";if(!tU(n)){if(o=nU(n),o&&(s=_l(w1(oU(n))),!~Xg(s,"g")))throw new lU("`.replaceAll` does not allow non-global regexes");if(i=rU(n,aU),i)return J9(i,n,r,t)}for(a=_l(r),l=_l(n),c=eU(t),c||(t=_l(t)),u=l.length,d=cU(1,u),p=Xg(a,l);p!==-1;)h=c?_l(t(l,p,a)):sU(l,a,p,[],void 0,t),f+=x1(a,m,p)+h,m=p+u,p=p+d>a.length?-1:Xg(a,l,p+d);return m<a.length&&(f+=x1(a,m)),f}});var uU=vu;uU("String","replaceAll");const dU=({children:e})=>{const n=U();return G("shouldDisplayHandles",()=>n.isInAny("select.idle","select.pointing_handle"),[n])?g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null},hU=({shapeId:e})=>{const n=U();return G("show hovered",()=>n.isIn("select.editing_shape")?n.getHoveredShapeId()!==n.getEditingShapeId():n.isInAny("select.idle"),[n])?g.jsx(uu,{className:"tl-user-indicator__hovered",id:e}):null},{PI:pU}=Math,Pa=pU+1e-4;function DI(e,n={}){const{size:t=16,smoothing:r=.5}=n;if(e.length===0||t<=0)return{left:[],right:[]};const o=e[0],s=e[e.length-1],i=s.runningLength,a=Math.pow(t*r,2),l=[],c=[];let u=e[0].vector,d=e[0].point,h=d,p=d,m=h,f=!1,S;for(let v=0;v<e.length;v++){S=e[v];const{point:x,vector:b}=e[v],P=S.vector.dpr(u),E=(v<e.length-1?e[v+1]:e[v]).vector,k=v<e.length-1?E.dpr(S.vector):1,I=P<0&&!f,_=k!==null&&k<.2;if(I||_){if(k>-.62&&i-S.runningLength>S.radius){const T=u.clone().mul(S.radius);u.clone().cpr(E)<0?(p=C.Add(x,T),m=C.Sub(x,T)):(p=C.Sub(x,T),m=C.Add(x,T)),l.push(p),c.push(m)}else{const T=u.clone().mul(S.radius).per(),D=C.Sub(S.input,T);for(let L=1/13,z=0;z<1;z+=L)p=C.RotWith(D,S.input,Pa*z),l.push(p),m=C.RotWith(D,S.input,Pa+Pa*-z),c.push(m)}d=p,h=m,_&&(f=!0);continue}if(f=!1,S===o||S===s){const T=C.Per(b).mul(S.radius);l.push(C.Sub(x,T)),c.push(C.Add(x,T));continue}const A=C.Lrp(E,b,k).per().mul(S.radius);p=C.Sub(x,A),(v<=1||C.Dist2(d,p)>a)&&(l.push(p),d=p),m=C.Add(x,A),(v<=1||C.Dist2(h,m)>a)&&(c.push(m),h=m),u=b}return{left:l,right:c}}function xu(e,n={}){const{size:t=16,start:r={},end:o={},last:s=!1}=n,{cap:i=!0}=r,{cap:a=!0}=o;if(e.length===0||t<=0)return[];const l=e[0],c=e[e.length-1],u=c.runningLength,d=r.taper===!1?0:r.taper===!0?Math.max(t,u):r.taper,h=o.taper===!1?0:o.taper===!0?Math.max(t,u):o.taper,{left:p,right:m}=DI(e,n),f=l.point,S=e.length>1?e[e.length-1].point:C.AddXY(l.point,1,1);if(e.length===1&&(!(d||h)||s)){const P=C.Add(f,C.Sub(f,S).uni().per().mul(-l.radius)),E=[];for(let k=1/13,I=k;I<=1;I+=k)E.push(C.RotWith(P,f,Pa*2*I));return E}const v=[];if(!(d||h&&e.length===1))if(i)for(let P=1/8,E=P;E<=1;E+=P){const k=C.RotWith(m[0],f,Pa*E);v.push(k)}else{const P=C.Sub(p[0],m[0]),E=C.Mul(P,.5),k=C.Mul(P,.51);v.push(C.Sub(f,E),C.Sub(f,k),C.Add(f,k),C.Add(f,E))}const x=[],b=c.vector.clone().per().neg();if(h||d&&e.length===1)x.push(S);else if(a){const P=C.Add(S,C.Mul(b,c.radius));for(let E=1/29,k=E;k<1;k+=E)x.push(C.RotWith(P,S,Pa*3*k))}else x.push(C.Add(S,C.Mul(b,c.radius)),C.Add(S,C.Mul(b,c.radius*.99)),C.Sub(S,C.Mul(b,c.radius*.99)),C.Sub(S,C.Mul(b,c.radius)));return p.concat(x,m.reverse(),v)}const fU=.025,gU=.01;function kr(e,n={}){var S;const{streamline:t=.5,size:r=16,simulatePressure:o=!1}=n;if(e.length===0)return[];const s=.15+(1-t)*.85;let i=e.map(C.From),a=0;if(!o){let v=i[0];for(;v&&!(v.z>=fU);)i.shift(),v=i[0]}if(!o){let v=i[i.length-1];for(;v&&!(v.z>=gU);)i.pop(),v=i[i.length-1]}if(i.length===0)return[{point:C.From(e[0]),input:C.From(e[0]),pressure:o?.5:.15,vector:new C(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(C.Dist(l,i[0])>r/3);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(C.Dist(l,c)>r/3);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=n.last||!n.simulatePressure||i.length>1&&C.Dist(i[i.length-1],i[i.length-2])<r||a>0;if(i.length===2&&n.simulatePressure){const v=i[1];i=i.slice(0,-1);for(let x=1;x<5;x++){const b=C.Lrp(i[0],v,x/4);b.z=(i[0].z+(v.z-i[0].z))*x/4,i.push(b)}}const d=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new C(1,1),distance:0,runningLength:0,radius:1}];let h=0,p=d[0],m,f;u&&t>0&&i.push(i[i.length-1].clone());for(let v=1,x=i.length;v<x;v++)m=!s||n.last&&v===x-1?i[v].clone():i[v].clone().lrp(p.point,1-s),!p.point.equals(m)&&(f=C.Dist(m,p.point),h+=f,!(v<4&&h<r)&&(p={input:i[v],point:m,pressure:o?.5:i[v].z,vector:C.Sub(p.point,m).uni(),distance:f,runningLength:h,radius:1},d.push(p)));if((S=d[1])!=null&&S.vector&&(d[0].vector=d[1].vector.clone()),h<1){const v=Math.max(.5,...d.map(x=>x.pressure));d.forEach(x=>x.pressure=v)}return d}const{min:Jo}=Math,qg=.275;function sl(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=S=>S,start:i={},end:a={}}=n,{easing:l=qt.easeOutQuad}=i,{easing:c=qt.easeOutCubic}=a,u=e[e.length-1].runningLength;let d,h=e[0].pressure,p;if(!o&&u<t){const S=e.reduce((v,x)=>Math.max(v,x.pressure),.5);return e.forEach(v=>{v.pressure=S,v.radius=t*s(.5-r*(.5-v.pressure))}),e}else{let S;for(let v=0,x=e.length;v<x&&(p=e[v],!(p.runningLength>t*5));v++){const b=Jo(1,p.distance/t);if(o){const P=Jo(1,1-b);S=Jo(1,h+(P-h)*(b*qg))}else S=Jo(1,h+(p.pressure-h)*.5);h=h+(S-h)*.5}for(let v=0;v<e.length;v++){if(p=e[v],r){let{pressure:x}=p;const b=Jo(1,p.distance/t);if(o){const P=Jo(1,1-b);x=Jo(1,h+(P-h)*(b*qg))}else x=Jo(1,h+(x-h)*(b*qg));p.radius=t*s(.5-r*(.5-x)),h=x}else p.radius=t/2;d===void 0&&(d=p.radius)}}const m=i.taper===!1?0:i.taper===!0?Math.max(t,u):i.taper,f=a.taper===!1?0:a.taper===!0?Math.max(t,u):a.taper;if(m||f)for(let S=0;S<e.length;S++){p=e[S];const{runningLength:v}=p,x=v<m?l(v/m):1,b=u-v<f?c((u-v)/f):1;p.radius=Math.max(.01,p.radius*Math.min(x,b))}return e}function mU(e,n={}){return xu(sl(kr(e,n),n),n)}const b1=({scribble:e,zoom:n,color:t,opacity:r,className:o})=>{if(!e.points.length)return null;const s=mU(e.points,{size:e.size/n,start:{taper:e.taper,easing:qt.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=e.size/n/2,{x:l,y:c}=e.points[e.points.length-1];i=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=hu(s);return g.jsx("svg",{className:o&&fe("tl-overlays__item",o),children:g.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})},yU=({bounds:e,rotation:n})=>{const t=U();return G("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?g.jsx(HE,{bounds:e,rotation:n}):null};function Yn(){const e=U();return G("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function SU({size:e,width:n,height:t,hideAlternateHandles:r}){const o=O(e/3),s=o/2;return g.jsxs("svg",{className:"tl-overlays__item",children:[g.jsx("polyline",{className:"tl-corner-crop-handle",points:`
63
+ ${O(0-s)},${O(e)}
64
+ ${O(0-s)},${O(0-s)}
65
+ ${O(e)},${O(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),g.jsx("line",{className:fe("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(n/2-e),y1:O(0-s),x2:O(n/2+e),y2:O(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),g.jsx("polyline",{className:fe("tl-corner-crop-handle",{"tl-hidden":r}),points:`
66
+ ${O(n-e)},${O(0-s)}
67
+ ${O(n+s)},${O(0-s)}
68
+ ${O(n+s)},${O(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),g.jsx("line",{className:fe("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(n+s),y1:O(t/2-e),x2:O(n+s),y2:O(t/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),g.jsx("polyline",{className:"tl-corner-crop-handle",points:`
69
+ ${O(n+s)},${O(t-e)}
70
+ ${O(n+s)},${O(t+s)}
71
+ ${O(n-e)},${O(t+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),g.jsx("line",{className:fe("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(n/2-e),y1:O(t+s),x2:O(n/2+e),y2:O(t+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),g.jsx("polyline",{className:fe("tl-corner-crop-handle",{"tl-hidden":r}),points:`
72
+ ${O(0+e)},${O(t+s)}
73
+ ${O(0-s)},${O(t+s)}
74
+ ${O(0-s)},${O(t-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),g.jsx("line",{className:fe("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(0-s),y1:O(t/2-e),x2:O(0-s),y2:O(t/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const vU=je(function({bounds:n,rotation:t}){const r=U(),o=w.useRef(null),s=Yn(),i=Ur("top"),a=Ur("right"),l=Ur("bottom"),c=Ur("left"),u=Ur("top_left"),d=Ur("top_right"),h=Ur("bottom_right"),p=Ur("bottom_left"),m=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",f=r.getInstanceState().isCoarsePointer,S=r.getOnlySelectedShape(),v=S&&r.isShapeOrAncestorLocked(S),x=S?r.getShapeUtil(S).expandSelectionOutlinePx(S):0;if(Za(o,n==null?void 0:n.x,n==null?void 0:n.y,1,r.getSelectionRotation(),{x:-x,y:-x}),!n)return null;n=n.clone().expandBy(x).zeroFix();const b=r.getZoomLevel(),P=r.getInstanceState().isChangingStyle,E=n.width,k=n.height,I=8/b,_=E<I*2,A=k<I*2,T=E<I*4,D=k<I*4,L=E<I*5,z=k<I*5,j=f?1.75:1,F=6/b*j,Y=(T?F/2:F)*(j*.75),K=(D?F/2:F)*(j*.75),H=(S?!r.getShapeUtil(S).hideSelectionBoundsFg(S):!0)&&!P;let B=H&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.pointing_resize_handle","select.pointing_crop_handle")||H&&r.isIn("select.resizing")&&S&&r.isShapeOfType(S,"text");S&&B&&r.environment.isFirefox&&r.isShapeOfType(S,"embed")&&(B=!1);const V=r.isInAny("select.pointing_crop_handle","select.crop.idle","select.crop.pointing_crop")&&!P&&!s,X=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!P&&!s,ae=!f&&!(_||A)&&(X||V)&&(S?!r.getShapeUtil(S).hideRotateHandle(S):!0)&&!v,ye=f&&(!T||!D)&&(X||V)&&(S?!r.getShapeUtil(S).hideRotateHandle(S):!0)&&!v,Ie=X&&(S?r.getShapeUtil(S).canResize(S)&&!r.getShapeUtil(S).hideResizeHandles(S):!0)&&!V&&!v,le=_||A,ke=_&&A,Ae=L||z,nt=Ie||V,Pe=!ae,ct=!X||!ye,Be=!X||!nt,Jn=!X||!nt||le,Tn=!X||!nt||le,$n=!X||!nt||ke&&!V;let Ye=!0,kt=!0;if(V)Ye=Ae,kt=Ae;else if(Ie){Ye=le||ke||f;const fl=f&&S&&S.type==="text";kt=Ye&&!fl}const co=Math.min(24/b,k-K*3),pl=X&&f&&S&&r.isShapeOfType(S,"text")&&co*b>=4;return g.jsx("svg",{className:"tl-overlays__item tl-selection__fg tl-svg-context","data-testid":"selection-foreground",children:g.jsxs("g",{ref:o,children:[B&&g.jsx("rect",{className:fe("tl-selection__fg__outline"),width:O(E),height:O(k)}),g.jsx(ud,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:F,corner:"top_left_rotate",cursor:m?Mn("nwse-rotate",t):void 0,isHidden:Pe}),g.jsx(ud,{"data-testid":"selection.rotate.top-right",cx:E+F*3,cy:0,targetSize:F,corner:"top_right_rotate",cursor:m?Mn("nesw-rotate",t):void 0,isHidden:Pe}),g.jsx(ud,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:k+F*3,targetSize:F,corner:"bottom_left_rotate",cursor:m?Mn("swne-rotate",t):void 0,isHidden:Pe}),g.jsx(ud,{"data-testid":"selection.rotate.bottom-right",cx:E+F*3,cy:k+F*3,targetSize:F,corner:"bottom_right_rotate",cursor:m?Mn("senw-rotate",t):void 0,isHidden:Pe}),g.jsx(xU,{"data-testid":"selection.rotate.mobile",cx:T?-F*1.5:E/2,cy:T?k/2:-F*1.5,size:I,isHidden:ct}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":Ye}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:O(0-(D?K*2:K)),width:O(E),height:O(Math.max(1,K*2)),style:m?{cursor:Mn("ns-resize",t)}:void 0,...i}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":kt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:O(E-(T?0:Y)),y:0,height:O(k),width:O(Math.max(1,Y*2)),style:m?{cursor:Mn("ew-resize",t)}:void 0,...a}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":Ye}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:O(k-(D?0:K)),width:O(E),height:O(Math.max(1,K*2)),style:m?{cursor:Mn("ns-resize",t)}:void 0,...l}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":kt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:O(0-(T?Y*2:Y)),y:0,height:O(k),width:O(Math.max(1,Y*2)),style:m?{cursor:Mn("ew-resize",t)}:void 0,...c}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":Be}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:O(0-(T?Y*2:Y*1.5)),y:O(0-(D?K*2:K*1.5)),width:O(Y*3),height:O(K*3),style:m?{cursor:Mn("nwse-resize",t)}:void 0,...u}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":Jn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:O(E-(T?0:Y*1.5)),y:O(0-(D?K*2:K*1.5)),width:O(Y*3),height:O(K*3),style:m?{cursor:Mn("nesw-resize",t)}:void 0,...d}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":$n}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:O(E-(T?Y:Y*1.5)),y:O(k-(D?K:K*1.5)),width:O(Y*3),height:O(K*3),style:m?{cursor:Mn("nwse-resize",t)}:void 0,...h}),g.jsx("rect",{className:fe("tl-transparent",{"tl-hidden":Tn}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:O(0-(T?Y*3:Y*1.5)),y:O(k-(D?0:K*1.5)),width:O(Y*3),height:O(K*3),style:m?{cursor:Mn("nesw-resize",t)}:void 0,...p}),Ie&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.resize.top-left",className:fe("tl-corner-handle",{"tl-hidden":Be}),"aria-label":"top_left handle",x:O(0-I/2),y:O(0-I/2),width:O(I),height:O(I)}),g.jsx("rect",{"data-testid":"selection.resize.top-right",className:fe("tl-corner-handle",{"tl-hidden":Jn}),"aria-label":"top_right handle",x:O(E-I/2),y:O(0-I/2),width:O(I),height:O(I)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:fe("tl-corner-handle",{"tl-hidden":$n}),"aria-label":"bottom_right handle",x:O(E-I/2),y:O(k-I/2),width:O(I),height:O(I)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:fe("tl-corner-handle",{"tl-hidden":Tn}),"aria-label":"bottom_left handle",x:O(0-I/2),y:O(k-I/2),width:O(I),height:O(I)})]}),pl&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:O(0-I/4),y:O(k/2-co/2),rx:I/4,width:O(I/2),height:O(co)}),g.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:I/4,x:O(E-I/4),y:O(k/2-co/2),width:O(I/2),height:O(co)})]}),V&&g.jsx(SU,{size:I,width:E,height:k,hideAlternateHandles:Ae})]})})}),ud=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=Ur(o);return g.jsx("rect",{className:fe("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:O(n-r*3),y:O(t-r*3),width:O(Math.max(1,r*3)),height:O(Math.max(1,r*3)),cursor:s,...l})},wU=Math.sqrt(Math.PI),xU=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=Ur("mobile_rotate"),a=U(),l=G("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return g.jsxs("g",{children:[g.jsx("circle",{"data-testid":s,pointerEvents:"all",className:fe("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:c,...i}),g.jsx("circle",{className:fe("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/wU})]})},jt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},St={s:2,m:3.5,l:5,xl:10},us={s:18,m:24,l:36,xl:44},Da={s:18,m:22,l:26,xl:32},is={s:18,m:20,l:24,xl:28},To={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},bU=20,PU=4.25;/*!
75
+ * canvas-size
76
+ * v1.2.6
77
+ * https://github.com/jhildenbiddle/canvas-size
78
+ * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
79
+ * MIT license
80
+ */function CU(e,n){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var r,o,s,i,a=[],l=!0,c=!1;try{if(s=(t=t.call(e)).next,n===0){if(Object(t)!==t)return;l=!1}else for(;!(l=(r=s.call(t)).done)&&(a.push(r.value),a.length!==n);l=!0);}catch(u){c=!0,o=u}finally{try{if(!l&&t.return!=null&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function P1(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 On(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?P1(Object(t),!0).forEach(function(r){EU(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):P1(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function EU(e,n,t){return n=RU(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function kU(e,n){if(e==null)return{};var t={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(n.indexOf(o)>=0)&&(t[o]=e[o]);return t}function IU(e,n){if(e==null)return{};var t=kU(e,n),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(n.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(t[r]=e[r])}return t}function C1(e,n){return TU(e)||CU(e,n)||jI(e,n)||MU()}function dd(e){return _U(e)||$U(e)||jI(e)||AU()}function _U(e){if(Array.isArray(e))return qy(e)}function TU(e){if(Array.isArray(e))return e}function $U(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function jI(e,n){if(e){if(typeof e=="string")return qy(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 qy(e,n)}}function qy(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 AU(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
81
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function MU(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
82
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function OU(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 RU(e){var n=OU(e,"string");return typeof n=="symbol"?n:String(n)}function oc(e){var n=e.sizes.shift(),t=Math.max(Math.ceil(n[0]),1),r=Math.max(Math.ceil(n[1]),1),o=[t-1,r-1,1,1],s=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,l;i?(a=new OffscreenCanvas(1,1),l=new OffscreenCanvas(t,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,l=document.createElement("canvas"),l.width=t,l.height=r);var c=a.getContext("2d"),u=l.getContext("2d");u&&(u.fillRect.apply(u,o),c.drawImage(l,t-1,r-1,1,1,0,0,1,1));var d=c&&c.getImageData(0,0,1,1).data[3]!==0,h=Date.now()-s;return[a,l].forEach(function(p){p.height=0,p.width=0}),i?(postMessage({width:t,height:r,benchmark:h,isTestPass:d}),!d&&e.sizes.length&&oc(e)):d?e.onSuccess(t,r,h):(e.onError(t,r,h),e.sizes.length&&oc(e)),d}var Zg={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]},DU=["onError","onSuccess"],oa={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},Tl={};function Qg(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,h=n||r?u:1;o.push([d,h])});else for(var s=e.min||oa.min,i=e.step||oa.step,a=Math.max(e.width,e.height);a>=s;){var l=n||t?a:1,c=n||r?a:1;o.push([l,c]),a-=i}return o}function hd(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=IU(e,DU),a=null;if(!n)return!1;if(e.useWorker&&t){var l=`
83
+ var canvasTest = `.concat(oc.toString(),`;
84
+ onmessage = function(e) {
85
+ canvasTest(e.data);
86
+ };
87
+ `),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(d){var h=d.data,p=h.width,m=h.height,f=h.benchmark,S=h.isTestPass;S?(Tl[r].onSuccess(p,m,f),delete Tl[r]):Tl[r].onError(p,m,f)}}if(e.usePromise)return new Promise(function(d,h){var p=On(On({},e),{},{onError:function(v,x,b){var P;if(e.sizes.length===0)P=!0;else{var E=e.sizes.slice(-1),k=C1(E,1),I=C1(k[0],2),_=I[0],A=I[1];P=v===_&&x===A}o(v,x,b),P&&h({width:v,height:x,benchmark:b})},onSuccess:function(v,x,b){s(v,x,b),d({width:v,height:x,benchmark:b})}});if(a){var m=p.onError,f=p.onSuccess;Tl[r]={onError:m,onSuccess:f},a.postMessage(i)}else oc(p)});if(a)Tl[r]={onError:o,onSuccess:s},a.postMessage(i);else return oc(e)}var Jg={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Qg({width:n.max,height:n.max,min:n.min,step:n.step,sizes:dd(Zg.area)}),r=On(On(On({},oa),n),{},{sizes:t});return hd(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Qg({width:1,height:n.max,min:n.min,step:n.step,sizes:dd(Zg.height)}),r=On(On(On({},oa),n),{},{sizes:t});return hd(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Qg({width:n.max,height:1,min:n.min,step:n.step,sizes:dd(Zg.width)}),r=On(On(On({},oa),n),{},{sizes:t});return hd(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=On(On({},oa),n);return t.sizes=dd(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),hd(t)}};let em=null;function jU(){return em||(em=LU()),em}async function LU(){const e=await Jg.maxWidth({usePromise:!0}),n=await Jg.maxHeight({usePromise:!0}),t=await Jg.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const E1=8192,NU=4096*4096;async function LI(e,n){if(e<=E1&&n<=E1&&e*n<=NU)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await jU(),s=e/n;if(e>t&&(e=t,n=e/s),n>r&&(n=r,e=n*s),e*n>o){const i=Math.sqrt(o/(e*n));e*=i,n*=i}return[e,n]}function k1(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function FU(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function zU(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!FU(e))return!1;for(t=n[10]&128,r=n[10]&7,o+=6,o+=7,o+=t?3*Math.pow(2,r+1):0;s<2&&o<n.length;)switch(n[o]){case 44:s+=1,t=n[o+9]&128,r=n[o+9]&7,o+=10,o+=t?3*Math.pow(2,r+1):0,o+=k1(n,o+1)+1;break;case 33:o+=2,o+=k1(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}function BU(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 UU(e,n,t,r={}){const o=await Yr.usingObjectURL(e,Yr.loadImage),{type:s=e.type,quality:i=.92}=r,[a,l]=await LI(Math.min(n*2,o.naturalWidth),Math.min(t*2,o.naturalHeight)),c=document.createElement("canvas");c.width=a,c.height=l;const u=mE(c.getContext("2d",{willReadFrequently:!0}),"Could not get canvas context");return u.imageSmoothingEnabled=!0,u.imageSmoothingQuality="high",u.drawImage(o,0,0,a,l),new Promise((d,h)=>{c.toBlob(p=>{p?d(p):h(new Error("Could not resize image"))},s,i)})}async function HU(e){return zU(await e.arrayBuffer())}function VU(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function KU(e){const n=new URL(e).host.replace("www.","");for(const t of Oa)if(NI(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const WU=e=>e.split("*").map(n=>VU(n)).join(".+"),NI=(e,n)=>!!e.find(t=>{const r=new RegExp(WU(t));return n.match(r)});function GU(e){const n=new URL(e).host.replace("www.","");for(const t of Oa)if(NI(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function FI(e){return GU(e)??KU(e)}function bo(e){try{return FI(e)}catch(n){console.error(n)}}const sa=" ",rn=class rn{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)||rn.insertTextFirefox(n,t),o===r.body?n.blur():o instanceof HTMLElement&&o!==n&&o.focus()}static set(n,t){n.select(),rn.insert(n,t)}static getSelection(n){const{selectionStart:t,selectionEnd:r}=n;return n.value.slice(t||void 0,r||void 0)}static wrapSelection(n,t,r){const{selectionStart:o,selectionEnd:s}=n,i=rn.getSelection(n);rn.insert(n,t+i+(r??t)),n.selectionStart=(o||0)+t.length,n.selectionEnd=(s||0)+t.length}static replace(n,t,r){let o=0;n.value.replace(t,(...s)=>{const i=o+s[s.length-2],a=s[0].length;n.selectionStart=i,n.selectionEnd=i+a;const l=typeof r=="string"?r:r(...s);return rn.insert(n,l),n.selectionStart=i,o+=l.length-a,l})}static findLineEnd(n,t){const r=n.lastIndexOf(`
88
+ `,t-1)+1;return n.charAt(r)!==" "?t:r+1}static indent(n){var a;const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.slice(t,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const l=o.lastIndexOf(`
89
+ `,t-1)+1,c=n.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${sa}`),d=u.length-c.length;n.setSelectionRange(l,r-1),rn.insert(n,u),n.setSelectionRange(t+1,r+d)}else rn.insert(n,sa)}static unindent(n){const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.lastIndexOf(`
90
+ `,t-1)+1,i=rn.findLineEnd(o,r),a=n.value.slice(s,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;n.setSelectionRange(s,i),rn.insert(n,l);const u=/\t| {1,2}/.exec(o.slice(s,t)),d=u?u[0].length:0,h=t-d;n.setSelectionRange(t-d,Math.max(h,r-c))}static indentCE(n){var l;const t=window.getSelection(),r=n.innerText,o=pd(n)??0,s=pd(n)??0,i=r.slice(o,s),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
91
+ `,o-1)+1,u=r.slice(c,s-1),h=u.replace(/^|\n/g,`$&${sa}`).length-u.length;t&&t.setBaseAndExtent(n,o+1,n,s+h)}else{const c=window.getSelection();n.innerText=r.slice(0,o)+sa+r.slice(o),c==null||c.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=pd(n)??0,s=pd(n)??0,i=r.lastIndexOf(`
92
+ `,o-1)+1,a=rn.findLineEnd(r,s),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=l.length-c.length;if(t){t.setBaseAndExtent(n,i,n,a);const d=/\t| {1,2}/.exec(r.slice(i,o)),h=d?d[0].length:0,p=o-h;t.setBaseAndExtent(n,o-h,n,Math.max(p,s-u))}}static normalizeText(n){return n.replace(rn.fixNewLines,`
93
+ `)}static normalizeTextForDom(n){return n.replace(rn.fixNewLines,`
94
+ `).split(`
95
+ `).map(t=>t||" ").join(`
96
+ `)}};y(rn,"fixNewLines",/\r?\n|\r/g);let ms=rn;function pd(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 YU=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function XU(e){return YU.test(e)}function qU(e){return e.replace(/\t/g,sa)}function ZU(e){const n=e.split(`
97
+ `);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(`
98
+ `)}function QU(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function JU(e){return QU(ZU(qU(e)))}const sc=(e,n)=>e.length<=n?e:e.substring(0,n-3)+"...";function eH(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o}){e.registerExternalAssetHandler("file",async({file:s})=>{const i=s.name;let a=s;const l=r.includes(a.type),c=o.includes(a.type);Io(l||c,`File type not allowed: ${a.type}`),Io(a.size<=t,`File size too big: ${(a.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),a.type==="video/quicktime"&&(a=new Blob([a],{type:"video/mp4"}));let u=l?await Yr.getImageSize(a):await Yr.getVideoSize(a);const d=a.type==="image/gif"?await HU(a):c,h=await wR(await a.arrayBuffer());if(isFinite(n)){const f=BU(u,{w:n,h:n});u!==f&&(a.type==="image/jpeg"||a.type==="image/png")&&(u=f)}(a.type==="image/jpeg"||a.type==="image/png")&&(a=await UU(a,u.w,u.h,{type:a.type,quality:.92}));const p=ei.createId(h);return ei.create({id:p,type:l?"image":"video",typeName:"asset",props:{name:i,src:await Yr.blobToDataUrl(a),w:u.w,h:u.h,mimeType:a.type,isAnimated:d}})}),e.registerExternalAssetHandler("url",async({url:s})=>{var a,l,c;let i;try{const d=await(await fetch(s,{method:"GET",mode:"no-cors"})).text(),h=new DOMParser().parseFromString(d,"text/html");i={image:((a=h.head.querySelector('meta[property="og:image"]'))==null?void 0:a.getAttribute("content"))??"",title:((l=h.head.querySelector('meta[property="og:title"]'))==null?void 0:l.getAttribute("content"))??sc(s,32),description:((c=h.head.querySelector('meta[property="og:description"]'))==null?void 0:c.getAttribute("content"))??""}}catch(u){console.error(u),i={image:"",title:sc(s,32),description:""}}return{id:ei.createId(wy(s)),typeName:"asset",type:"bookmark",props:{src:s,description:i.description,image:i.image,title:i.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:s,text:i})=>{const a=s??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),l=new DOMParser().parseFromString(i,"image/svg+xml").querySelector("svg");if(!l)throw new Error("No <svg/> element present");let c=parseFloat(l.getAttribute("width")||"0"),u=parseFloat(l.getAttribute("height")||"0");if(!(c&&u)){document.body.appendChild(l);const h=l.getBoundingClientRect();document.body.removeChild(l),c=h.width,u=h.height}const d=await e.getAssetForExternalContent({type:"file",file:new File([i],"asset.svg",{type:"image/svg+xml"})});if(!d)throw Error("Could not create an asset");I1(e,[d],a)}),e.registerExternalContentHandler("embed",({point:s,url:i,embed:a})=>{const l=s??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),{width:c,height:u}=a,d=We(),h={id:d,type:"embed",x:l.x-(c||450)/2,y:l.y-(u||450)/2,props:{w:c,h:u,url:i}};e.createShapes([h]).select(d)}),e.registerExternalContentHandler("files",async({point:s,files:i})=>{const a=s??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),l=new C(a.x,a.y),c=[];await Promise.all(i.map(async(u,d)=>{if(u.size>t)return console.warn(`File size too big: ${(u.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),null;if(!u.type)throw new Error("No mime type");if(!r.concat(o).includes(u.type))return console.warn(`${u.name} not loaded - Extension not allowed.`),null;try{const h=await e.getAssetForExternalContent({type:"file",file:u});if(!h)throw Error("Could not create an asset");c[d]=h}catch(h){return console.error(h),null}})),I1(e,pe(c),l)}),e.registerExternalContentHandler("text",async({point:s,text:i})=>{const a=s??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),l=e.getShapeUtil("text").getDefaultProps(),c=JU(i);let u,d,h,p="middle";const m=c.split(`
99
+ `).length>1,f=XU(c);m&&(p=m?f?"end":"start":"middle");const S=e.textMeasure.measureText(c,{...jt,fontFamily:To[l.font],fontSize:us[l.size],maxWidth:null}),v=Math.min(m?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(S.w>v){const x=e.textMeasure.measureText(c,{...jt,fontFamily:To[l.font],fontSize:us[l.size],maxWidth:v});u=x.w,d=x.h,h=!1,p=f?"end":"start"}else u=S.w,d=S.h,h=!0;a.y-d/2<e.getViewportPageBounds().minY+40&&(a.y=e.getViewportPageBounds().minY+40+d/2),e.createShapes([{id:We(),type:"text",x:a.x-u/2,y:a.y-d/2,props:{text:c,align:p,autoSize:h,w:u}}])}),e.registerExternalContentHandler("url",async({point:s,url:i})=>{const a=bo(i);if(a)return e.putExternalContent({type:"embed",url:a.url,point:s,embed:a.definition});const l=s??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),c=ei.createId(wy(i)),u=tH(e,i,l);let d=e.getAsset(c),h=!1;if(!d){h=!0;const p=await e.getAssetForExternalContent({type:"url",url:i});if(!p)throw Error("Could not create an asset");d=p}e.batch(()=>{h&&e.createAssets([d]),e.updateShapes([{id:u.id,type:u.type,props:{assetId:d.id}}])})})}async function I1(e,n,t){if(!n.length)return[];const r=C.From(t),o=[];for(const s of n)switch(s.type){case"bookmark":{o.push({id:We(),type:"bookmark",x:r.x-150,y:r.y-160,opacity:1,props:{assetId:s.id,url:s.props.src}}),r.x+=300;break}case"image":{o.push({id:We(),type:"image",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w;break}case"video":o.push({id:We(),type:"video",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w}return e.batch(()=>{const s=n.filter(i=>!e.getAsset(i.id));s.length&&e.createAssets(s),e.createShapes(o).select(...o.map(i=>i.id)),zI(e,t)}),o.map(s=>s.id)}function zI(e,n){const t=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const o=r.center.sub(n);e.updateShapes(e.getSelectedShapes().map(s=>{const i=e.getShapeParentTransform(s).decompose().rotation,a=C.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!t.contains(r)&&e.zoomToSelection()}function tH(e,n,t){const r={id:We(),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),zI(e,t)}),e.getShape(r.id)}var Jm;let nH=(Jm=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")});y(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}))}})}},y(Jm,"id","idle"),Jm);var ey;let rH=(ey=class extends oe{constructor(){super(...arguments);y(this,"shape");y(this,"markId","");y(this,"onEnter",()=>{this.didTimeout=!1;const t=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.getShapeUtil(r).canBind(r),margin:0,hitInside:!0,renderingOnly:!0});t?this.editor.setHintingShapes([t.id]):this.createArrowShape(),this.startPreciseTimeout()});y(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});y(this,"onPointerMove",()=>{if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:this.editor.getShapeHandles(this.shape).find(t=>t.id==="end"),isCreating:!0,onInteractionEnd:"arrow"})}});y(this,"onPointerUp",()=>{this.cancel()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()});y(this,"preciseTimeout",-1);y(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u,d;const{originPagePoint:t}=this.editor.inputs,r=We();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"arrow",x:t.x,y:t.y}]);const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=s.find(h=>h.id==="start"),c=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});if(c){const h=(d=c.props)==null?void 0:d.start;(h==null?void 0:h.type)==="binding"&&this.editor.setHintingShapes([h.boundShapeId]),this.editor.updateShapes([c],{squashing:!0})}this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,i,a;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 o={...t,props:{...t.props,end:{...t.props.end,x:0,y:0}}};{const l=this.editor.getShapeUtil("arrow"),c=this.shape,u=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),d=r.find(p=>p.id==="end"),h=(s=l.onHandleDrag)==null?void 0:s.call(l,o,{handle:{...d,x:u.x,y:u.y},isPrecise:!1,initial:c});if(h){const p=(i=h.props)==null?void 0:i.end;(p==null?void 0:p.type)==="binding"&&this.editor.setHintingShapes([p.boundShapeId]),this.editor.updateShapes([h],{squashing:!0})}}{const l=this.editor.getShapeUtil("arrow"),c=this.shape,u=r.find(h=>h.id==="start"),d=(a=l.onHandleDrag)==null?void 0:a.call(l,o,{handle:{...u,x:0,y:0},isPrecise:this.didTimeout,initial:c});d&&this.editor.updateShapes([d],{squashing:!0})}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=window.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},y(ey,"id","pointing"),ey);class ih extends oe{constructor(){super(...arguments);y(this,"shapeType","arrow")}}y(ih,"id","arrow"),y(ih,"initial","idle"),y(ih,"children",()=>[nH,rH]);class g0 extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"initialShape");y(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");y(this,"util",this.editor.getShapeUtil(this.shapeType));y(this,"isPen",!1);y(this,"segmentMode","free");y(this,"didJustShiftClickToExtendPreviousShapeLine",!1);y(this,"pagePointWhereCurrentSegmentChanged",{});y(this,"pagePointWhereNextSegmentChanged",null);y(this,"lastRecordedPoint",{});y(this,"mergeNextPoint",!1);y(this,"currentLineLength",0);y(this,"canDraw",!1);y(this,"markId",null);y(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()});y(this,"onPointerMove",()=>{const{editor:{inputs:t}}=this;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&&(t.isPen?C.Dist(t.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=t.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateShapes())});y(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.updateShapes()});y(this,"onKeyUp",t=>{if(t.key==="Shift")switch(this.editor.snaps.clear(),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.updateShapes()});y(this,"onExit",()=>{this.editor.snaps.clear(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(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=St[r],s=t[0].points[0],i=t[t.length-1],a=i.points[i.points.length-1];return s!==a&&this.currentLineLength>o*4&&C.Dist(s,a)<o*2}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+Ue(),this.editor.mark(this.markId),this.isPen=r;const o=this.isPen?this.info.point.z*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=t.clone(),this.initialShape){const i=this.editor.getShape(this.initialShape.id);if(i&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const a=mn(i.props.segments);if(!a)throw Error("Expected a previous segment!");const l=mn(a.points);if(!l)throw Error("Expected a previous point!");const{x:c,y:u}=this.editor.getPointInShapeSpace(i,t).toFixed(),d=this.isPen?this.info.point.z*1.25:.5,h={type:this.segmentMode,points:[{x:l.x,y:l.y,z:+d.toFixed(2)},{x:c,y:u,z:+d.toFixed(2)}]},p=te.applyToPoint(this.editor.getShapePageTransform(i.id),l);this.pagePointWhereCurrentSegmentChanged=p,this.pagePointWhereNextSegmentChanged=null;const m=[...i.props.segments,h];this.currentLineLength=this.getLineLength(m);const f={id:i.id,type:this.shapeType,props:{segments:m}};this.canClose()&&(f.props.isClosed=this.getIsClosed(m,i.props.size)),this.editor.updateShapes([f]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const s=We();this.editor.createShapes([{id:s,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPen,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+o.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(s)}updateShapes(){const{inputs:t}=this.editor,{initialShape:r}=this;if(!r)return;const{id:o,props:{size:s}}=r,i=this.editor.getShape(o);if(!i)return;const{segments:a}=i.props,{x:l,y:c,z:u}=this.editor.getPointInShapeSpace(i,t.currentPagePoint).toFixed(),d={x:l,y:c,z:this.isPen?+(u*1.25).toFixed(2):.5};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:h}=this;if(h===null)throw Error("We should have a point where the segment changed");if(C.Dist(h,t.currentPagePoint)>xc){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const m=mn(a);if(!m)throw Error("Expected a previous segment!");const f=mn(m.points);if(!f)throw Error("Expected a previous last point!");let S;const v=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(m.type==="straight"){this.currentLineLength+=C.Dist(f,v),S={type:"straight",points:[{...f},v]};const b=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=te.applyToPoint(b,f)}else S={type:"straight",points:[v,d]};const x={id:o,type:this.shapeType,props:{segments:[...a,S]}};this.canClose()&&(x.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([x],{squashing:!0})}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:h}=this;if(h===null)throw Error("We should have a point where the segment changed");if(C.Dist(h,t.currentPagePoint)>xc){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const m=a.slice(),f=m[m.length-1],S=mn(f.points);if(!S)throw Error("No previous point!");const v={type:"free",points:[...C.PointsBetween(S,d,6).map(P=>P.toFixed().toJson())]},x=[...m,v];this.currentLineLength=this.getLineLength(x);const b={id:o,type:this.shapeType,props:{segments:x}};this.canClose()&&(b.props.isClosed=this.getIsClosed(x,s)),this.editor.updateShapes([b],{squashing:!0})}break}case"straight":{const h=a.slice(),p=h[h.length-1],{pagePointWhereCurrentSegmentChanged:m}=this,{currentPagePoint:f,ctrlKey:S}=this.editor.inputs;if(!m)throw Error("We should have a point where the segment changed");let v,x=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(x=!S,this.didJustShiftClickToExtendPreviousShapeLine=!1):x=!S;let b=this.editor.getPointInShapeSpace(i,f).toFixed().toJson(),P=!1,E;if((this.editor.user.getIsSnapMode()?!S:S)&&h.length>2){let _,A=8/this.editor.getZoomLevel();for(let T=0,D=a.length-2;T<D;T++){const L=a[T];if(!L)break;if(L.type==="free")continue;const z=L.points[0],j=mn(L.points);if(!(z&&j))continue;const F=C.NearestPointOnLineSegment(z,j,b),Y=C.Dist(F,b);if(Y<A){_=F.toFixed().toJson(),A=Y,E=L;break}}_&&(P=!0,b=_)}if(P&&E){const _=this.editor.getShapePageTransform(i),A=E.points[0],T=mn(E.points);if(!T)throw Error("Expected a last point!");const D=te.applyToPoint(_,A),L=te.applyToPoint(_,T),z=te.applyToPoint(_,b);this.editor.snaps.setLines([{id:Ue(),type:"points",points:[D,z,L]}])}else{if(this.editor.snaps.clear(),x){const _=C.Angle(m,f),T=ip(_,24)-_;v=C.RotWith(f,m,T)}else v=f;b=this.editor.getPointInShapeSpace(i,v).toFixed().toJson()}this.currentLineLength+=C.Dist(p.points[0],b),h[h.length-1]={...p,type:"straight",points:[p.points[0],b]};const I={id:o,type:this.shapeType,props:{segments:h}};this.canClose()&&(I.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([I],{squashing:!0});break}case"free":{const h=a.slice(),p=h[h.length-1],m=[...p.points];if(m.length&&this.mergeNextPoint){const{z:S}=m[m.length-1];m[m.length-1]={x:d.x,y:d.y,z:S?Math.max(S,d.z):d.z}}else this.currentLineLength+=C.Dist(m[m.length-1],d),m.push(d);h[h.length-1]={...p,points:m},this.currentLineLength=this.getLineLength(h);const f={id:o,type:this.shapeType,props:{segments:h}};if(this.canClose()&&(f.props.isClosed=this.getIsClosed(h,s)),this.editor.updateShapes([f],{squashing:!0}),m.length>500){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const{currentPagePoint:S}=this.editor.inputs,v=We();this.editor.createShapes([{id:v,type:this.shapeType,x:ap(S.x),y:ap(S.y),props:{isPen:this.isPen,segments:[{type:"free",points:[{x:0,y:0,z:this.isPen?+(u*1.25).toFixed():.5}]}]}}]),this.initialShape=structuredClone(this.editor.getShape(v)),this.mergeNextPoint=!1,this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(t){let r=0;for(const o of t)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=C.Sub(a,i).len2()}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)}}y(g0,"id","drawing");var ty;let BI=(ty=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("drawing",t)});y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(ty,"id","idle"),ty);class ah extends oe{constructor(){super(...arguments);y(this,"shapeType","draw");y(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}y(ah,"id","draw"),y(ah,"initial","idle"),y(ah,"children",()=>[BI,g0]);class Zy extends th{constructor(){super(...arguments);y(this,"shapeType","frame");y(this,"onCreate",t=>{if(!t)return;const r=this.editor.getShapePageBounds(t),o=[],s=this.editor.getShapeAncestors(t).map(i=>i.id);this.editor.getCurrentPageShapes().map(i=>{if(i.id===t.id||i.isLocked)return;const a=this.editor.getShapePageBounds(i);a&&r.contains(a)&&oH(i,s,t)&&o.push(i.id)}),this.editor.reparentShapes(o,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}y(Zy,"id","frame"),y(Zy,"initial","idle");function oH(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var ny;let sH=(ny=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});y(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}))}});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(ny,"id","idle"),ny);var ry;let iH=(ry=class extends oe{constructor(){super(...arguments);y(this,"markId","");y(this,"onPointerUp",()=>{this.complete()});y(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=We();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(qr)}}]).select(o).setCurrentTool("select.resizing",{...t,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:t}=this.editor.inputs,r=We();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(qr),w:1,h:1}}]);const o=this.editor.getShape(r);if(!o)return;const s=o.props.geo==="star"?new re(0,0,200,190):o.props.geo==="cloud"?new re(0,0,300,180):new re(0,0,200,200),i=s.center,a=this.editor.getShapeParentTransform(o);a&&i.rot(-a.rotation()),this.editor.select(r),this.editor.updateShapes([{id:o.id,type:"geo",x:o.x-i.x,y:o.y-i.y,props:{geo:this.editor.getStyleForNextShape(qr),w:s.width,h:s.height}}]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},y(ry,"id","pointing"),ry);class lh extends oe{constructor(){super(...arguments);y(this,"shapeType","geo")}}y(lh,"id","geo"),y(lh,"initial","idle"),y(lh,"children",()=>[sH,iH]);class ch extends oe{constructor(){super(...arguments);y(this,"shapeType","highlight");y(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}y(ch,"id","highlight"),y(ch,"initial","idle"),y(ch,"children",()=>[BI,g0]);var oy;let aH=(oy=class extends oe{constructor(){super(...arguments);y(this,"shapeId","");y(this,"onEnter",t=>{this.shapeId=t.shapeId,this.editor.setCursor({type:"cross",rotation:0})});y(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(oy,"id","idle"),oy);const _1=2;var sy;let lH=(sy=class extends oe{constructor(){super(...arguments);y(this,"shape",{});y(this,"markId");y(this,"onEnter",t=>{const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=t.shapeId&&this.editor.getShape(t.shapeId);if(s&&r.shiftKey){this.markId=`creating:${s.id}`,this.editor.mark(this.markId),this.shape=s;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(S=>S.type==="vertex").sort(Wt),l=a[a.length-1],c=a[a.length-2],u=te.applyToPoint(this.editor.getShapeParentTransform(this.shape),new C(this.shape.x,this.shape.y));let d,h,p;const m=C.Sub(o,u);C.Dist(l,c)<_1||C.Dist(m,l)<_1?(d=l.index,h=l.id,p={...l,x:m.x+.1,y:m.y+.1}):(d=So(l.index),h="handle:"+d,p={id:h,type:"vertex",index:d,x:m.x+.1,y:m.y+.1,canBind:!1});const f=gs(this.shape.props.handles);f[p.id]=p,this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{handles:f}}])}else{const i=We();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});y(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=mn(t);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(this,"onInterrupt",()=>{this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clear()})}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clear()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clear()}},y(sy,"id","pointing"),sy);class uh extends oe{constructor(){super(...arguments);y(this,"shapeType","line")}}y(uh,"id","line"),y(uh,"initial","idle"),y(uh,"children",()=>[aH,lH]);var iy;let cH=(iy=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(iy,"id","idle"),iy);var ay;let uH=(ay=class extends oe{constructor(){super(...arguments);y(this,"dragged",!1);y(this,"info",{});y(this,"wasFocusedOnEnter",!1);y(this,"markId","");y(this,"shape",{});y(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen(),this.wasFocusedOnEnter&&(this.shape=this.createShape())});y(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&(this.wasFocusedOnEnter||(this.shape=this.createShape()),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")}}))});y(this,"onPointerUp",()=>{this.complete()});y(this,"onInterrupt",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(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)}createShape(){const{inputs:{originPagePoint:t}}=this.editor,r=We();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"note",x:t.x,y:t.y}]).select(r);const o=this.editor.getShape(r),s=this.editor.getShapeGeometry(o).bounds;return this.editor.updateShapes([{id:r,type:"note",x:o.x-s.width/2,y:o.y-s.height/2}]),this.editor.getShape(r)}},y(ay,"id","pointing"),ay);class dh extends oe{constructor(){super(...arguments);y(this,"shapeType","note")}}y(dh,"id","note"),y(dh,"initial","idle"),y(dh,"children",()=>[cH,uH]);function _c(e){const n=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:Or/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)}var ly;let dH=(ly=class extends oe{constructor(){super(...arguments);y(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":_c(this.editor)}});y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});y(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}))}});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(ly,"id","idle"),ly);var cy;let hH=(cy=class extends oe{constructor(){super(...arguments);y(this,"shape");y(this,"markId","");y(this,"onExit",()=>{this.editor.setHintingShapes([])});y(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,o=We();if(this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:!1,w:20}}]),this.editor.select(o),this.shape=this.editor.getShape(o),!this.shape)return;const{shape:s}=this;this.editor.setCurrentTool("select.resizing",{...t,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"text",onCreate:()=>{this.editor.setEditingShape(s.id),this.editor.setCurrentTool("select.editing_shape")}})}});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.cancel()});y(this,"onCancel",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}complete(){var s;this.editor.mark("creating text shape");const t=We(),{x:r,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:t,type:"text",x:r,y:o,props:{text:"",autoSize:!0}}]).select(t),this.editor.setEditingShape(t),this.editor.setCurrentTool("select"),(s=this.editor.root.getCurrent())==null||s.transition("editing_shape")}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}},y(cy,"id","pointing"),cy);class hh extends oe{constructor(){super(...arguments);y(this,"shapeType","text")}}y(hh,"id","text"),y(hh,"initial","idle"),y(hh,"children",()=>[dH,hH]);const pH=[hh,ah,lh,dh,uh,Zy,ih,ch];function Et(){return In({isDarkMode:af()})}const pt=ne.memo(function({theme:n,d:t,color:r,fill:o}){switch(o){case"none":return null;case"solid":return g.jsx("path",{fill:n[r].semi,d:t});case"semi":return g.jsx("path",{fill:n.solid,d:t});case"pattern":return g.jsx(fH,{theme:n,color:r,fill:o,d:t})}}),fH=function({d:n,color:t,theme:r}){const o=U(),s=G("zoomLevel",()=>o.getZoomLevel(),[o]),i=Math.ceil(s),a=o.getZoomLevel()<=.18;return g.jsxs(g.Fragment,{children:[g.jsx("path",{fill:r[t].pattern,d:n}),g.jsx("path",{fill:a?r[t].semi:`url(#${op[`${i}_${r.id}`]})`,d:n})]})};function Xn({d:e,color:n,fill:t,theme:r}){if(t==="none")return;if(t==="pattern"){const s=document.createElementNS("http://www.w3.org/2000/svg","g"),i=document.createElementNS("http://www.w3.org/2000/svg","path");i.setAttribute("d",e),i.setAttribute("fill",r[n].pattern);const a=document.createElementNS("http://www.w3.org/2000/svg","path");return a.setAttribute("d",e),a.setAttribute("fill","url(#hash_pattern)"),s.appendChild(i),s.appendChild(a),s}const o=document.createElementNS("http://www.w3.org/2000/svg","path");switch(o.setAttribute("d",e),t){case"semi":{o.setAttribute("fill",r.solid);break}case"solid":{o.setAttribute("fill",r[n].semi);break}}return o}function jr(e,n){if(n){const t=document.createElementNS("http://www.w3.org/2000/svg","g");return t.appendChild(n),t.appendChild(e),t}else return e}function gH(e){return e.replace(/\s/g," ")}function yf(e,n,t){const{padding:r=0}=t,o=document.createElementNS("http://www.w3.org/2000/svg","text");if(o.setAttribute("font-size",t.fontSize+"px"),o.setAttribute("font-family",t.fontFamily),o.setAttribute("font-style",t.fontStyle),o.setAttribute("font-weight",t.fontWeight),o.setAttribute("line-height",t.lineHeight*t.fontSize+"px"),o.setAttribute("dominant-baseline","mathematical"),o.setAttribute("alignment-baseline","mathematical"),n.length===0)return o;const s=re.From(n[0].box);for(const{box:c}of n)s.union(c);const i=r+(t.offsetX??0),a=(t.offsetY??0)+t.fontSize/2+(t.verticalTextAlign==="start"?r:t.verticalTextAlign==="end"?t.height-r-s.height:(Math.ceil(t.height)-s.height)/2);let l=null;for(const{text:c,box:u}of n){if(l!==null&&u.y>l){const m=document.createElementNS("http://www.w3.org/2000/svg","tspan");m.setAttribute("alignment-baseline","mathematical"),m.setAttribute("x",i+"px"),m.setAttribute("y",u.y+a+"px"),m.textContent=`
100
+ `,o.appendChild(m)}const h=document.createElementNS("http://www.w3.org/2000/svg","tspan");h.setAttribute("alignment-baseline","mathematical"),h.setAttribute("x",u.x+i+"px"),h.setAttribute("y",u.y+a+"px");const p=gH(c);h.textContent=p,o.appendChild(h),l=u.y}return t.stroke&&t.strokeWidth&&(o.setAttribute("stroke",t.stroke),o.setAttribute("stroke-width",t.strokeWidth+"px")),t.fill&&o.setAttribute("fill",t.fill),o}function Sf(e){return{key:`${eo.id}:${e}`,getElement:async()=>{const n=mH(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await fetch(t)).blob(),s=await new Promise((l,c)=>{const u=new FileReader;u.onload=()=>l(u.result),u.onerror=c,u.readAsDataURL(o)}),i=r.replace(t,s),a=document.createElementNS("http://www.w3.org/2000/svg","style");return a.textContent=i,a}}}function mH(e){const n=au[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function m0(e,n){return{key:`${eo.id}:${e}`,getElement:async()=>{if(e!=="pattern")return null;const t=8/12,r=document.createElement("div");return r.innerHTML=`
101
+ <svg>
102
+ <defs>
103
+ <mask id="hash_pattern_mask">
104
+ <rect x="0" y="0" width="8" height="8" fill="white" />
105
+ <g
106
+ strokeLinecap="round"
107
+ stroke="black"
108
+ >
109
+ <line x1="${t*1}" y1="${t*3}" x2="${t*3}" y2="${t*1}" />
110
+ <line x1="${t*5}" y1="${t*7}" x2="${t*7}" y2="${t*5}" />
111
+ <line x1="${t*9}" y1="${t*11}" x2="${t*11}" y2="${t*9}" />
112
+ </g>
113
+ </mask>
114
+ <pattern
115
+ id="hash_pattern"
116
+ width="8"
117
+ height="8"
118
+ patternUnits="userSpaceOnUse"
119
+ >
120
+ <rect x="0" y="0" width="8" height="8" fill="${n.solid}" mask="url(#hash_pattern_mask)" />
121
+ </pattern>
122
+ </defs>
123
+ </svg>
124
+ `,Array.from(r.querySelectorAll("defs > *"))}}}function y0(){return{key:`${eo.id}:pattern`,component:vH}}const Gl=8,T1=(e,n,t)=>new Promise((r,o)=>{const s=Gl*n*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?"#212529":"#f8f9fa",a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*n*e;const l=8/12,c=u=>u*n*e;a.beginPath(),a.moveTo(c(l*1),c(l*3)),a.lineTo(c(l*3),c(l*1)),a.moveTo(c(l*5),c(l*7)),a.lineTo(c(l*7),c(l*5)),a.moveTo(c(l*9),c(l*11)),a.lineTo(c(l*11),c(l*9)),a.stroke(),i.toBlob(u=>{!u||Oe.throwToBlob.get()?o():r(u)})}),$1=(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()):""},yH=()=>{const e=[];for(let n=1;n<=Math.ceil(os);n++){const t=$1([1,1],o=>{o.fillStyle=Qh.lightMode.black.semi,o.fillRect(0,0,1,1)}),r=$1([1,1],o=>{o.fillStyle=Qh.darkMode.black.semi,o.fillRect(0,0,1,1)});e.push({zoom:n,url:t,darkMode:!1}),e.push({zoom:n,url:r,darkMode:!0})}return e};function SH(){const n=U().getInstanceState().devicePixelRatio,[t,r]=w.useState(!1),o=w.useMemo(()=>yH(),[]),[s,i]=w.useState(o);return w.useEffect(()=>{const l=[];for(let u=1;u<=Math.ceil(os);u++)l.push(T1(n,u,!1).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!1}))),l.push(T1(n,u,!0).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!0})));let c=!1;return Promise.all(l).then(u=>{c||(i(u),r(!0))}),()=>{c=!0,r(!1)}},[n]),{defs:g.jsx(g.Fragment,{children:s.map(l=>{const c=l.zoom+(l.darkMode?"_dark":"_light");return g.jsx("pattern",{id:op[c],width:Gl,height:Gl,patternUnits:"userSpaceOnUse",children:g.jsx("image",{href:l.url,width:Gl,height:Gl})},c)})}),isReady:t}}function vH(){const e=U(),n=w.useRef(null),{defs:t,isReady:r}=SH();return w.useEffect(()=>{if(r&&e.environment.isSafari){const o=UI(n.current);o&&requestAnimationFrame(()=>{o.style.display="none",requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),g.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function UI(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?UI(e.parentElement):null}function Qt(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=t;let c=0,u=0,d=1,h=0,p=0;switch(l){case"dashed":{d=1,c=Math.min(n*a,e/4);break}case"dotted":{d=100,c=n/d;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=c/2,p+=c/2):s==="skip"&&(e-=c,p-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),u=Math.floor(e/c/(2*d)),u-=u%o,u<3&&l==="dashed"?e/n<5?(c=e,u=1,h=0):(c=e*.333,h=e*.333):(u=Math.max(u,3),c=e/u/(2*d),r?(p=c/2,h=(e-u*c)/u):h=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,h].join(" "),strokeDashoffset:p.toString()}}const A1=new WeakMap;function S0(e,n){const t=A1.get(n);if(t)return t;const r=e.getArrowInfo(n);let o=0,s=0;const i=r.isStraight?new Ec({start:C.From(r.start.point),end:C.From(r.end.point)}):new Nk({center:C.Cast(r.handleArc.center),radius:r.handleArc.radius,start:C.Cast(r.start.point),end:C.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(n.props.text.trim()){const l=i.bounds,{w:c,h:u}=e.textMeasure.measureText(n.props.text,{...jt,fontFamily:To[n.props.font],fontSize:is[n.props.size],maxWidth:null});if(o=c,s=u,l.width>l.height){o=Math.max(Math.min(c,64),Math.min(l.width-64,c));const{w:d,h}=e.textMeasure.measureText(n.props.text,{...jt,fontFamily:To[n.props.font],fontSize:is[n.props.size],maxWidth:o});o=d,s=h}if(o>16*is[n.props.size]){o=16*is[n.props.size];const{w:d,h}=e.textMeasure.measureText(n.props.text,{...jt,fontFamily:To[n.props.font],fontSize:is[n.props.size],maxWidth:o});o=d,s=h}}const a=new C(o,s).addScalar(PU*2);return A1.set(n,a),a}function HI(e,n){const t=St[n.props.size];return bU+(t-St.s)*2+(t===St.xl?20:0)}function wH(e,n,t){const r=S0(e,n),o=HI(e,n),s=C.Nudge(t.start.point,t.end.point,o),i=C.Nudge(t.end.point,t.start.point,o),a=Sk(s,i,re.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;C.Dist2(l,s)>C.Dist2(c,s)&&([c,l]=a);const u=s.add(C.Sub(t.middle,l)),d=i.add(C.Sub(t.middle,c)),h=C.Dist(t.start.point,u)/t.length,p=C.Dist(t.start.point,d)/t.length;return{start:h,end:p}}function xH(e,n,t){const r=S0(e,n),o=HI(e,n),s=Math.sign(n.props.bend),i=o/t.handleArc.radius*s,a=C.Angle(t.bodyArc.center,t.start.point)-i,l=C.Angle(t.bodyArc.center,t.end.point)+i,c=di(t.bodyArc.center,t.bodyArc.radius,a),u=di(t.bodyArc.center,t.bodyArc.radius,l),d=[],h=O1(t.bodyArc.center,t.bodyArc.radius,a,l,s,re.FromCenter(c,r).corners);d.push(new gt({points:re.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const p=O1(t.bodyArc.center,t.bodyArc.radius,a,l,s,re.FromCenter(u,r).corners);d.push(new gt({points:re.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const I of[...h??[],...p??[],c,u])d.push(new Gv({x:I.x-3,y:I.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const m=(h&&R1(t.start.point,h))??t.middle,f=(p&&R1(t.end.point,p))??t.middle,S=C.Angle(t.bodyArc.center,t.start.point),v=C.Angle(t.bodyArc.center,t.end.point),x=C.Angle(t.bodyArc.center,m),b=C.Angle(t.bodyArc.center,f);if(ss(S,x,s)>ss(S,b,s))return{start:.5,end:.5,dbg:d};const P=ss(S,v,s),E=ss(S,x,s)/P,k=ss(S,b,s)/P;return{start:E,end:k,dbg:d}}function M1(e,n){let t;const r=[],o=e.getArrowInfo(n),s=o.start.arrowhead!=="none",i=o.end.arrowhead!=="none";if(o.isStraight){const l=wH(e,n,o);let c=or(n.props.labelPosition,s?l.start:0,i?l.end:1);c=c>=.48&&c<=.52?.5:c,t=C.Lrp(o.start.point,o.end.point,c)}else{const l=xH(e,n,o);l.dbg&&r.push(...l.dbg);let c=or(n.props.labelPosition,s?l.start:0,i?l.end:1);c=c>=.48&&c<=.52?.5:c;const u=bH(C.Angle(o.bodyArc.center,o.start.point),C.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),c);t=di(o.bodyArc.center,o.bodyArc.radius,u)}const a=S0(e,n);return{box:re.FromCenter(t,a),debugGeom:r}}function O1(e,n,t,r,o,s){const i=Ay(e,n,s),a=ss(t,r,o);return i==null?void 0:i.filter(l=>{const c=ss(t,C.Angle(e,l),o);return c>=0&&c<=a})}function R1(e,n){let t=null,r=-1/0;for(const o of n){const s=C.Dist2(e,o);s>r&&(t=o,r=s)}return t}function bH(e,n,t,r){const o=ss(e,n,t);return e+o*r*t*-1}function PH(e,n,t){const r=n==="end"?e.end.point:e.start.point,o=n==="end"?e.start.point:e.end.point,s=e.isStraight?C.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,t*3),t);let a;if(e.isStraight)a=C.Nudge(r,o,i);else{const l=k6(r,i,e.handleArc.center,e.handleArc.radius);a=n==="end"?e.handleArc.sweepFlag?l[0]:l[1]:e.handleArc.sweepFlag?l[1]:l[0]}return{point:r,int:a}}function CH({point:e,int:n}){const t=C.RotWith(n,e,Te/6),r=C.RotWith(n,e,-Te/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function EH({point:e,int:n}){const t=C.RotWith(n,e,Te/6),r=C.RotWith(n,e,-Te/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function kH({point:e,int:n}){const t=C.Sub(n,e).div(2),r=C.Add(e,C.Rot(t,Ve)),o=C.Sub(e,C.Rot(t,Ve));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function IH({point:e,int:n}){const t=C.Lrp(e,n,.45),r=C.Dist(t,e);return`M ${t.x-r},${t.y}
125
+ a ${r},${r} 0 1,0 ${r*2},0
126
+ a ${r},${r} 0 1,0 -${r*2},0 `}function _H({point:e,int:n}){const t=C.Lrp(e,n,.75),r=C.RotWith(t,e,Te/4),o=C.RotWith(t,e,-Te/4),s=C.Lrp(r,o,.5);return s.add(C.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function TH({int:e,point:n}){const t=C.Lrp(n,e,.85),r=C.Sub(t,n).div(2),o=C.Add(n,C.Rot(r,Ve)),s=C.Sub(n,C.Rot(r,Ve)),i=C.Add(t,C.Rot(r,Ve)),a=C.Sub(t,C.Rot(r,Ve));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function $H({int:e,point:n}){const t=C.Sub(e,n).div(2),r=C.Add(n,C.Rot(t,Ve)),o=C.Sub(n,C.Rot(t,Ve));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function Ki(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=PH(e,n,t);if(o){switch(r){case"bar":return $H(o);case"square":return TH(o);case"diamond":return _H(o);case"dot":return IH(o);case"inverted":return kH(o);case"arrow":return CH(o);case"triangle":return EH(o)}return""}}function AH(e){const{start:n,end:t,handleArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${n.handle.x},${n.handle.y} A${r} ${r} 0 ${o} ${s} ${t.handle.x},${t.handle.y}`}function tm(e){const{start:n,end:t,bodyArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${n.point.x},${n.point.y} A${r} ${r} 0 ${o} ${s} ${t.point.x},${t.point.y}`}function VI(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function MH(e){return VI(e.start.handle,e.end.handle)}function nm(e){return VI(e.start.point,e.end.point)}function v0(e,n,t){const r=U(),o=w.useRef(null),s=w.useRef(!1),i=w.useRef(),a=G("isEditing",()=>r.getEditingShapeId()===e,[r,e]);w.useEffect(()=>{const f=o.current;f&&a&&document.activeElement!==f&&f.focus()},[a]);const l=w.useCallback(()=>{const f=s.current;s.current=!1,requestAnimationFrame(()=>{const S=o.current;if(!S)return;const v=r.getShape(e);v&&(S.value=v.props.text,S.value.length&&!f&&S.select())})},[r,e]),c=w.useCallback(()=>{const f=i.current;requestAnimationFrame(()=>{var x;const S=o.current,v=r.getEditingShapeId();if(S&&v){if(v===e)if(f)if(!f.length)S.focus();else{s.current=!0,S.focus();const b=window.getSelection();b&&f.forEach(P=>b.addRange(P))}else S.focus()}else(x=window.getSelection())==null||x.removeAllRanges(),r.complete()})},[r,e]),u=w.useCallback(f=>{if(a)switch(f.key){case"Enter":{(f.ctrlKey||f.metaKey)&&r.complete();break}case"Tab":{Ee(f),f.shiftKey?ms.unindent(f.currentTarget):ms.indent(f.currentTarget);break}}},[r,a]),d=w.useCallback(f=>{if(!a)return;let S=ms.normalizeText(f.currentTarget.value);const v=S.replace(/\t/g,sa);if(v!==S){const x=f.currentTarget.selectionStart;f.currentTarget.value=v,f.currentTarget.selectionStart=x+(v.length-S.length),f.currentTarget.selectionEnd=x+(v.length-S.length),S=v}r.updateShapes([{id:e,type:n,props:{text:S}}])},[r,e,n,a]),h=t.trim().length===0;w.useEffect(()=>{if(!a)return;if(o.current){let S=function(){var x,b;const v=(x=window.getSelection)==null?void 0:x.call(window);if(v&&v.type!=="None"){const P=[];if(v)for(let E=0;E<v.rangeCount;E++)P.push((b=v.getRangeAt)==null?void 0:b.call(v,E));i.current=P}};return document.addEventListener("selectionchange",S),()=>{document.removeEventListener("selectionchange",S)}}},[a]);const p=w.useCallback(f=>{r.dispatch({...vn(f),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Dt(f)},[r,e]);return{rInput:o,isEditing:a,handleFocus:l,handleBlur:c,handleKeyDown:u,handleChange:d,handleInputPointerDown:p,handleDoubleClick:Dt,isEmpty:h}}const OH=w.memo(function({id:n,text:t,size:r,font:o,position:s,width:i,labelColor:a}){const{rInput:l,isEditing:c,handleFocus:u,handleBlur:d,handleKeyDown:h,handleChange:p,isEmpty:m,handleInputPointerDown:f,handleDoubleClick:S}=v0(n,"arrow",t),x=ms.normalizeTextForDom(t).trim().length>0;return!c&&!x?null:g.jsx("div",{className:"tl-arrow-label","data-font":o,"data-align":"center","data-hastext":!m,"data-isediting":c,style:{textAlign:"center",fontSize:is[r],lineHeight:is[r]*jt.lineHeight+"px",transform:`translate(${s.x}px, ${s.y}px)`,color:a},children:g.jsxs("div",{className:"tl-arrow-label__inner",children:[g.jsx("p",{style:{width:i||"9px"},children:t?ms.normalizeTextForDom(t):" "}),c&&g.jsx("textarea",{ref:l,className:"tl-text tl-text-input",name:"text",tabIndex:-1,autoComplete:"false",autoCapitalize:"false",autoCorrect:"false",autoSave:"false",autoFocus:!0,placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",datatype:"wysiwyg",defaultValue:t,onFocus:u,onChange:p,onKeyDown:h,onBlur:d,onContextMenu:Dt,onPointerDown:f,onDoubleClick:S})]})})});let RH=0;class ph extends Tr{constructor(){super(...arguments);y(this,"canEdit",()=>!0);y(this,"canBind",()=>!1);y(this,"canSnap",()=>!1);y(this,"hideResizeHandles",()=>!0);y(this,"hideRotateHandle",()=>!0);y(this,"hideSelectionBoundsBg",()=>!0);y(this,"hideSelectionBoundsFg",()=>!0);y(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const s=r.id;if(s==="middle"){const{start:S,end:v}=Er(this.editor,t),x=C.Sub(v,S),b=C.Per(x),P=C.Med(v,S),E=C.Sub(P,b),k=C.Add(P,b),I=C.NearestPointOnLineSegment(E,k,r,!1);let _=C.Dist(I,P);return C.Clockwise(I,v,P)&&(_*=-1),{id:t.id,type:t.type,props:{bend:_}}}const i=Zt(t);if(this.editor.inputs.ctrlKey)return i.props[s]={type:"point",x:r.x,y:r.y},i;const a=this.editor.getShapePageTransform(t.id).applyToPoint(r),l=this.editor.getShapeAtPoint(a,{hitInside:!0,hitFrameInside:!0,margin:0,filter:S=>!S.isLocked&&this.editor.getShapeUtil(S).canBind(S)});if(!l)return i.props[s]={type:"point",x:r.x,y:r.y},i;const c=this.editor.getShapeGeometry(l),u=re.ZeroFix(c.bounds),h=this.editor.getShapePageTransform(i.id).applyToPoint(r),p=this.editor.getPointInShapeSpace(l,h);let m=o;if(!m){const S=i.props[s];(S.type==="point"||S.type==="binding"&&l.id!==S.boundShapeId)&&(m=this.editor.inputs.pointerVelocity.len()<.5)}if(!o){c.isClosed||(m=!0);const S=i.props[s==="start"?"end":"start"];S.type==="binding"&&l.id===S.boundShapeId&&S.isPrecise&&(m=!0)}const f={x:(p.x-u.minX)/u.width,y:(p.y-u.minY)/u.height};return m&&C.Dist(p,u.center)<Math.max(4,Math.min(Math.min(u.width,u.height)*.15,16))/this.editor.getZoomLevel()&&(f.x=.5,f.y=.5),i.props[s]={type:"binding",boundShapeId:l.id,normalizedAnchor:f,isPrecise:m,isExact:this.editor.inputs.altKey},i.props.start.type==="binding"&&i.props.end.type==="binding"&&i.props.start.boundShapeId===i.props.end.boundShapeId&&C.Equals(i.props.start.normalizedAnchor,i.props.end.normalizedAnchor)&&(i.props.end.normalizedAnchor.x+=.05),i});y(this,"onTranslateStart",t=>{const r=t.props.start.type==="binding"?t.props.start.boundShapeId:null,o=t.props.end.type==="binding"?t.props.end.boundShapeId:null,s=Er(this.editor,t),i=this.editor.getShapePageTransform(t.id),a=this.editor.getSelectedShapeIds();if(r&&(a.includes(r)||this.editor.isAncestorSelected(r))||o&&(a.includes(o)||this.editor.isAncestorSelected(o)))return;let l=t;L1.set(t,{pagePosition:i.applyToPoint(t),terminalBindings:by(s,(c,u)=>{const d=t.props[c];return d.type!=="binding"?null:{binding:d,shapePosition:u,pagePosition:i.applyToPoint(u)}})});for(const c of["start","end"]){const u=t.props[c];u.type==="binding"&&(l={...t,props:{...t.props,[c]:{...u,isPrecise:!0}}})}return l});y(this,"onTranslate",(t,r)=>{const o=L1.get(t);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=C.Sub(s.applyToPoint(r),o.pagePosition);let a=r;for(const[l,c]of Xr(o.terminalBindings)){if(!c)continue;const u=C.Add(c.pagePosition,C.Mul(i,.5)),d=this.editor.getShapeAtPoint(u,{hitInside:!0,hitFrameInside:!0,margin:0,filter:h=>!h.isLocked&&this.editor.getShapeUtil(h).canBind(h)});if((d==null?void 0:d.id)===c.binding.boundShapeId){const h=re.ZeroFix(this.editor.getShapeGeometry(d).bounds),p=this.editor.getPointInShapeSpace(d,u),m={x:(p.x-h.minX)/h.width,y:(p.y-h.minY)/h.height};a={...a,props:{...a.props,[l]:{...c.binding,isPrecise:!0,normalizedAnchor:m}}}}else a={...a,props:{...a.props,[l]:{type:"point",x:c.shapePosition.x,y:c.shapePosition.y}}}}return a});y(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=Er(this.editor,t),{start:a,end:l}=Zt(t.props);let{bend:c}=t.props;a.type==="point"&&(a.x=i.start.x*o,a.y=i.start.y*s),l.type==="point"&&(l.x=i.end.x*o,l.y=i.end.y*s);const u=Math.abs(o),d=Math.abs(s);return o<0&&s>=0?(c!==0&&(c*=-1,c*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.x=1-a.normalizedAnchor.x),l.type==="binding"&&(l.normalizedAnchor.x=1-l.normalizedAnchor.x)):o>=0&&s<0?(c!==0&&(c*=-1,c*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.y=1-a.normalizedAnchor.y),l.type==="binding"&&(l.normalizedAnchor.y=1-l.normalizedAnchor.y)):o>=0&&s>=0?c!==0&&(c*=Math.max(u,d)):o<0&&s<0&&(c!==0&&(c*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.x=1-a.normalizedAnchor.x,a.normalizedAnchor.y=1-a.normalizedAnchor.y),l.type==="binding"&&(l.normalizedAnchor.x=1-l.normalizedAnchor.x,l.normalizedAnchor.y=1-l.normalizedAnchor.y)),{props:{start:a,end:l,bend:c}}});y(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"}}}});y(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{type:"point",x:0,y:0},end:{type:"point",x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw"}}getGeometry(t){const r=this.editor.getArrowInfo(t),o=[],s=r.isStraight?new Ec({start:C.From(r.start.point),end:C.From(r.end.point)}):new Nk({center:C.Cast(r.handleArc.center),radius:r.handleArc.radius,start:C.Cast(r.start.point),end:C.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(t.props.text.trim()){const a=M1(this.editor,t);o.push(...a.debugGeom),i=new Es({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Po({children:[...i?[s,i]:[s],...o],isSnappable:!1})}getLength(t){const r=this.editor.getArrowInfo(t);return r.isStraight?C.Dist(r.start.handle,r.end.handle):Math.abs(r.handleArc.length)}getHandles(t){const r=this.editor.getArrowInfo(t);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y,canBind:!0},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y,canBind:!1},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y,canBind:!0}].filter(Boolean)}component(t){const r=Et(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,i=this.editor.getArrowInfo(t),a=re.ZeroFix(this.editor.getShapeGeometry(t).bounds),l=ne.useMemo(()=>this.editor.environment.isSafari?RH+=1:0,[t]);if(!(i!=null&&i.isValid))return null;const c=St[t.props.size],u=i.start.arrowhead&&Ki(i,"start",c),d=i.end.arrowhead&&Ki(i,"end",c),h=i.isStraight?nm(i):tm(i);let p=null;if(o===t&&s){const{strokeDasharray:E,strokeDashoffset:k}=Qt(this.getLength(t),2,{end:"skip",start:"skip",lengthRatio:2.5});p=t.props.start.type==="binding"||t.props.end.type==="binding"?g.jsx("path",{className:"tl-arrow-hint",d:i.isStraight?MH(i):AH(i),strokeDasharray:E,strokeDashoffset:k,strokeWidth:2,markerStart:t.props.start.type==="binding"?t.props.start.isExact?"":t.props.start.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:t.props.end.type==="binding"?t.props.end.isExact?"":t.props.end.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:m,strokeDashoffset:f}=Qt(i.isStraight?i.length:Math.abs(i.bodyArc.length),c,{style:t.props.dash}),S=M1(this.editor,t),v=!(i.start.arrowhead==="none"||i.start.arrowhead==="arrow"),x=!(i.end.arrowhead==="none"||i.end.arrowhead==="arrow"),b=(t.id+"_clip_"+l).replace(":","_");return g.jsxs(g.Fragment,{children:[g.jsxs(Ln,{id:t.id,style:{minWidth:50,minHeight:50},children:[g.jsx("defs",{children:g.jsxs("mask",{id:b,children:[g.jsx("rect",{x:O(-100+a.minX),y:O(-100+a.minY),width:O(a.width+200),height:O(a.height+200),fill:"white"}),t.props.text.trim()&&g.jsx("rect",{x:S.box.x,y:S.box.y,width:S.box.w,height:S.box.h,fill:"black",rx:4,ry:4}),u&&v&&g.jsx("path",{d:u,fill:i.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),d&&x&&g.jsx("path",{d,fill:i.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),g.jsxs("g",{fill:"none",stroke:r[t.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[p,g.jsxs("g",{mask:`url(#${b})`,children:[g.jsx("rect",{x:O(a.minX-100),y:O(a.minY-100),width:O(a.width+200),height:O(a.height+200),opacity:0}),g.jsx("path",{d:h,strokeDasharray:m,strokeDashoffset:f})]}),u&&v&&t.props.fill!=="none"&&g.jsx(pt,{theme:r,d:u,color:t.props.color,fill:t.props.fill}),d&&x&&t.props.fill!=="none"&&g.jsx(pt,{theme:r,d,color:t.props.color,fill:t.props.fill}),u&&g.jsx("path",{d:u}),d&&g.jsx("path",{d})]})]}),g.jsx(OH,{id:t.id,text:t.props.text,font:t.props.font,size:t.props.size,position:S.box.center,width:S.box.w,labelColor:r[t.props.labelColor].solid})]})}indicator(t){const{start:r,end:o}=Er(this.editor,t),s=this.editor.getArrowInfo(t),i=this.editor.getShapeGeometry(t),a=i.bounds,l=t.props.text.trim()?i.children[1]:null,c=uf(t.id);if(!s||C.Equals(r,o))return null;const u=St[t.props.size],d=s.start.arrowhead&&Ki(s,"start",u),h=s.end.arrowhead&&Ki(s,"end",u),p=s.isStraight?nm(s):tm(s),m=d&&s.start.arrowhead!=="arrow"||h&&s.end.arrowhead!=="arrow"||!!l,f=(t.id+"_clip").replace(":","_");return c&&l?g.jsx("rect",{x:O(l.x),y:O(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5}):g.jsxs("g",{children:[m&&g.jsx("defs",{children:g.jsxs("mask",{id:f,children:[g.jsx("rect",{x:a.minX-100,y:a.minY-100,width:a.w+200,height:a.h+200,fill:"white"}),l&&g.jsx("rect",{x:O(l.x),y:O(l.y),width:l.w,height:l.h,fill:"black",rx:3.5,ry:3.5}),d&&g.jsx("path",{d,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),h&&g.jsx("path",{d:h,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),g.jsxs("g",{...m?{mask:`url(#${f})`}:void 0,children:[m&&g.jsx("rect",{x:a.minX-100,y:a.minY-100,width:a.width+200,height:a.height+200,opacity:0}),g.jsx("path",{d:p})]}),d&&g.jsx("path",{d}),h&&g.jsx("path",{d:h}),l&&g.jsx("rect",{x:O(l.x),y:O(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5})]})}toSvg(t,r){const o=In({isDarkMode:this.editor.user.getIsDarkMode()});r.addExportDef(m0(t.props.fill,o));const s=o[t.props.color].solid,i=this.editor.getArrowInfo(t),a=St[t.props.size],l=document.createElementNS("http://www.w3.org/2000/svg","g");if(!i)return l;const c=i.start.arrowhead&&Ki(i,"start",a),u=i.end.arrowhead&&Ki(i,"end",a),d=this.editor.getShapeGeometry(t),h=d.bounds,p=t.props.text.trim()?d.children[1]:null,m=(t.id+"_clip").replace(":","_");if(c||u||p){const P=document.createElementNS("http://www.w3.org/2000/svg","defs"),E=document.createElementNS("http://www.w3.org/2000/svg","mask");E.id=m;const k=document.createElementNS("http://www.w3.org/2000/svg","rect");if(k.setAttribute("x",h.minX-100+""),k.setAttribute("y",h.minY-100+""),k.setAttribute("width",h.width+200+""),k.setAttribute("height",h.height+200+""),k.setAttribute("fill","white"),E.appendChild(k),c&&E.appendChild(D1(c,i.start.arrowhead)),u&&E.appendChild(D1(u,i.end.arrowhead)),p){const I=document.createElementNS("http://www.w3.org/2000/svg","rect");I.setAttribute("x",p.x+""),I.setAttribute("y",p.y+""),I.setAttribute("width",p.w+""),I.setAttribute("height",p.h+""),I.setAttribute("fill","black"),E.appendChild(I)}P.appendChild(E),l.appendChild(P)}const f=document.createElementNS("http://www.w3.org/2000/svg","g");f.setAttribute("mask",`url(#${m})`),l.appendChild(f);const S=document.createElementNS("http://www.w3.org/2000/svg","rect");S.setAttribute("x","-100"),S.setAttribute("y","-100"),S.setAttribute("width",h.width+200+""),S.setAttribute("height",h.height+200+""),S.setAttribute("fill","transparent"),S.setAttribute("stroke","none"),f.appendChild(S);const v=DH(i.isStraight?nm(i):tm(i),s,a),{strokeDasharray:x,strokeDashoffset:b}=Qt(i.isStraight?i.length:Math.abs(i.bodyArc.length),a,{style:t.props.dash});if(v.setAttribute("stroke-dasharray",x),v.setAttribute("stroke-dashoffset",b),f.appendChild(v),c&&l.appendChild(j1(c,t.props.color,a,t.props.arrowheadStart==="arrow"?"none":t.props.fill,o)),u&&l.appendChild(j1(u,t.props.color,a,t.props.arrowheadEnd==="arrow"?"none":t.props.fill,o)),p){r.addExportDef(Sf(t.props.font));const P={fontSize:is[t.props.size],lineHeight:jt.lineHeight,fontFamily:au[t.props.font],padding:0,textAlign:"middle",width:p.w-8,verticalTextAlign:"middle",height:p.h,fontStyle:"normal",fontWeight:"normal",overflow:"wrap"},E=yf(this.editor,this.editor.textMeasure.measureTextSpans(t.props.text,P),P);E.setAttribute("fill",o[t.props.labelColor].solid),Array.from(E.children).forEach(_=>{const A=parseFloat(_.getAttribute("x")||"0"),T=parseFloat(_.getAttribute("y")||"0");_.setAttribute("x",A+4+p.x+"px"),_.setAttribute("y",T+p.y+"px")});const I=E.cloneNode(!0);I.setAttribute("stroke-width","2"),I.setAttribute("fill",o.background),I.setAttribute("stroke",o.background),l.appendChild(I),l.appendChild(E)}return l}getCanvasSvgDefs(){return[y0()]}}y(ph,"type","arrow"),y(ph,"props",$3),y(ph,"migrations",A3);function D1(e,n){const t=document.createElementNS("http://www.w3.org/2000/svg","path");return t.setAttribute("d",e),t.setAttribute("fill",n==="arrow"?"none":"black"),t.setAttribute("stroke","none"),t}function DH(e,n,t){const r=document.createElementNS("http://www.w3.org/2000/svg","path");return r.setAttribute("d",e),r.setAttribute("fill","none"),r.setAttribute("stroke",n),r.setAttribute("stroke-width",t+""),r}function j1(e,n,t,r,o){const s=document.createElementNS("http://www.w3.org/2000/svg","path");s.setAttribute("d",e),s.setAttribute("fill","none"),s.setAttribute("stroke",o[n].solid),s.setAttribute("stroke-width",t+"");const i=Xn({d:e,fill:r,color:n,theme:o});if(i){const a=document.createElementNS("http://www.w3.org/2000/svg","g");return a.appendChild(i),a.appendChild(s),a}else return s}const L1=new WeakMap,N1="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 bu({url:e,zoomLevel:n}){return g.jsx("a",{className:fe("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Dt,onPointerUp:Dt,title:e,draggable:!1,children:g.jsx("div",{className:"tl-hyperlink-button__icon",style:{mask:`url("${N1}") center 100% / 100% no-repeat`,WebkitMask:`url("${N1}") center 100% / 100% no-repeat`}})})}const jH=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function w0(e){return jH.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,l=new C(r,o),{x:c,y:u}=l.rot(-e);return`${c}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}class fh extends el{constructor(){super(...arguments);y(this,"canResize",()=>!1);y(this,"hideSelectionBoundsFg",()=>!0);y(this,"onBeforeCreate",t=>{F1(this.editor,t)});y(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(Wn.isValid(r.props.url))F1(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}}})}getDefaultProps(){return{url:"",w:300,h:320,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),s=LH(t);return g.jsx(pi,{children:g.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:w0(o)},children:[g.jsxs("div",{className:"tl-bookmark__image_container",children:[r!=null&&r.props.image?g.jsx("img",{className:"tl-bookmark__image",draggable:!1,src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):g.jsx("div",{className:"tl-bookmark__placeholder"}),g.jsx(bu,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),g.jsxs("div",{className:"tl-bookmark__copy_container",children:[(r==null?void 0:r.props.title)&&g.jsx("h2",{className:"tl-bookmark__heading",children:sc((r==null?void 0:r.props.title)||"",54)}),(r==null?void 0:r.props.description)&&g.jsx("p",{className:"tl-bookmark__description",children:sc((r==null?void 0:r.props.description)||"",128)}),g.jsx("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Dt,onPointerUp:Dt,onClick:Dt,children:sc(s,45)})]})]})})}indicator(t){return g.jsx("rect",{width:O(t.props.w),height:O(t.props.h),rx:"6",ry:"6"})}}y(fh,"type","bookmark"),y(fh,"props",M3),y(fh,"migrations",O3);const LH=e=>{try{const n=new URL(e.props.url),t=n.pathname.replace(/\/*$/,"");return`${n.hostname}${t}`}catch{return e.props.url}};function F1(e,n){const{url:t}=n.props,r=ei.createId(wy(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}}]),NH(e,n))}const NH=yE(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 ds(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${At(r)}L${At(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=yn(r,o);return n?`M${yn(e[0].point,e[1].point)}Q${At(e[1].point)}${yn(e[1].point,e[2].point)}T${s}${yn(e[t-1].point,e[0].point)}${yn(e[0].point,e[1].point)}Z`:`M${At(e[0].point)}Q${At(e[1].point)}${yn(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${At(e[t-1].point)}`}function FH(e,n={}){const{start:t={},end:r={}}=n,{cap:o=!0}=t,{cap:s=!0}=r;Io(!t.taper&&!r.taper,"cap taper not supported here"),Io(!t.easing&&!r.easing,"cap easing not supported here"),Io(o&&s,"cap must be true");const i=kr(e,n);sl(i,n);const a=zH(i);let l="";for(const c of a)l+=UH(c,n);return l}function zH(e){if(e.length<=2)return[e];const n=[];let t=[e[0]];for(let r=1;r<e.length-1;r++){const o=e[r-1],s=e[r],i=e[r+1],a=C.Angle(o.point,s.point),l=C.Angle(s.point,i.point),c=Math.abs(tc(a,l))/Math.PI;if(c>.8){const m={...s,point:s.input};t.push(m),n.push(rm(t)),t=[m];continue}if(t.push(s),c<.25)continue;const u=(o.radius+s.radius+i.radius)/3,d=C.Dist(o.point,s.point)/u,h=C.Dist(s.point,i.point)/u;if(d+h<1.5){t.push(s),n.push(rm(t)),t=[s];continue}}return t.push(e[e.length-1]),n.push(rm(t)),n}function rm(e){const n=e[0];for(;e.length>2;){const r=e[1],o=C.Dist(n.point,r.point),s=(n.radius+r.radius)/2;if(o<s*.5)e.splice(1,1);else break}const t=e[e.length-1];for(;e.length>2;){const r=e[e.length-2],o=C.Dist(t.point,r.point),s=(t.radius+r.radius)/2;if(o<s*.5)e.splice(e.length-2,1);else break}return e.length>1&&(e[0]={...e[0],vector:C.FromAngle(C.Angle(e[1].point,e[0].point))},e[e.length-1]={...e[e.length-1],vector:C.FromAngle(C.Angle(e[e.length-1].point,e[e.length-2].point))}),e}function BH(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 UH(e,n={}){if(e.length===0)return"";if(e.length===1)return BH(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=DI(e,n);r.reverse();let o=`M${At(t[0])}T`;for(let s=1;s<t.length;s++)o+=yn(t[s-1],t[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),l=C.Add(s.point,C.Mul(a,i)),c=C.Add(s.point,C.Mul(a,-i));o+=`${At(l)}A${O(i)},${O(i)} 0 0 1 ${At(c)}T`}for(let s=1;s<r.length;s++)o+=yn(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),l=C.Add(s.point,C.Mul(a,i)),c=C.Add(s.point,C.Mul(a,-i));o+=`${At(l)}A${O(i)},${O(i)} 0 0 1 ${At(c)}Z`}return o}function vp(){const e=U();return G("zoom",()=>e.getZoomLevel()<.35,[e])}const HH=e=>e*.65+HD(e*Te/2)*.35,VH=e=>({size:1+e,thinning:.5,streamline:.62+(1+e)/8*.06,smoothing:.62,easing:qt.easeOutSine,simulatePressure:!0}),KH=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:HH}),z1=e=>({size:1+e,thinning:0,streamline:.62+(1+e)/8*.06,smoothing:.62,simulatePressure:!1,easing:qt.linear});function Qy({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:qt.easeOutSine,last:n}}function fd(e,n,t,r){return{...r?z1(n):e.dash==="draw"?e.isPen?KH(n):VH(n):z1(n),last:e.isComplete||t}}function ia(e){const n=[];for(const t of e)if(t.type==="free"||t.points.length<2)n.push(...t.points.map(C.Cast));else{const r=Math.max(4,Math.floor(C.Dist(t.points[0],t.points[1])/16));n.push(...C.PointsBetween(t.points[0],t.points[1],r))}return n}function B1(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class gh extends Tr{constructor(){super(...arguments);y(this,"hideResizeHandles",t=>sm(t));y(this,"hideRotateHandle",t=>sm(t));y(this,"hideSelectionBoundsFg",t=>sm(t));y(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:ap(o*l),y:ap(s*c),z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1}}getGeometry(t){const r=ia(t.props.segments),o=St[t.props.size];if(t.props.segments.length===1){const i=re.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new Gv({x:-o,y:-o,radius:o,isFilled:!0})}const s=kr(r,fd(t.props,o,!0,!0)).map(i=>i.point);return t.props.isClosed?new gt({points:s,isFilled:t.props.fill!=="none"}):new Pi({points:s})}component(t){var p;const r=Et(),o=vp(),s=St[t.props.size],i=ia(t.props.segments),a=t.props.isComplete||((p=mn(t.props.segments))==null?void 0:p.type)==="straight";let l=s;!o&&!t.props.isPen&&t.props.dash==="draw"&&i.length===1&&(l+=fs(t.id)()*(s/6));const c=fd(t.props,l,a,o);if(!o&&t.props.dash==="draw")return g.jsxs(Ln,{id:t.id,children:[t.props.isClosed&&t.props.fill&&i.length>1?g.jsx(pt,{theme:r,fill:t.props.isClosed?t.props.fill:"none",color:t.props.color,d:ds(kr(i,c),t.props.isClosed)}):null,g.jsx("path",{d:FH(i,c),strokeLinecap:"round",fill:r[t.props.color].solid})]});const u=kr(i,c),d=u.length<2,h=d?om(i[0],0):ds(u,t.props.isClosed);return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{theme:r,color:t.props.color,fill:d||t.props.isClosed?t.props.fill:"none",d:h}),g.jsx("path",{d:h,strokeLinecap:"round",fill:d?r[t.props.color].solid:"none",stroke:r[t.props.color].solid,strokeWidth:s,strokeDasharray:d?"none":B1(t,s),strokeDashoffset:"0"})]})}indicator(t){var d;const r=vp(),o=St[t.props.size],s=ia(t.props.segments);let i=o;!r&&!t.props.isPen&&t.props.dash==="draw"&&s.length===1&&(i+=fs(t.id)()*(o/6));const a=t.props.isComplete||((d=mn(t.props.segments))==null?void 0:d.type)==="straight",l=fd(t.props,i,a,!0),c=kr(s,l),u=c.length>1?ds(c,t.props.isClosed):om(s[0],i);return g.jsx("path",{d:u})}toSvg(t,r){var f;const o=In({isDarkMode:this.editor.user.getIsDarkMode()});r.addExportDef(m0(t.props.fill,o));const{color:s}=t.props,i=St[t.props.size],a=ia(t.props.segments),l=t.props.isComplete||((f=mn(t.props.segments))==null?void 0:f.type)==="straight";let c=i;!t.props.isPen&&t.props.dash==="draw"&&a.length===1&&(c+=fs(t.id)()*(i/6));const u=fd(t.props,c,l,!1),d=kr(a,u),h=d.length>1?ds(d,t.props.isClosed):om(a[0],c);let p;if(t.props.dash==="draw"||d.length<2){sl(d,u);const S=xu(d,u),v=document.createElementNS("http://www.w3.org/2000/svg","path");v.setAttribute("d",hu(S,!0)),v.setAttribute("fill",o[s].solid),v.setAttribute("stroke-linecap","round"),p=v}else{const S=document.createElementNS("http://www.w3.org/2000/svg","path");S.setAttribute("d",h),S.setAttribute("stroke",o[s].solid),S.setAttribute("fill","none"),S.setAttribute("stroke-linecap","round"),S.setAttribute("stroke-width",i.toString()),S.setAttribute("stroke-dasharray",B1(t,i)),S.setAttribute("stroke-dashoffset","0"),p=S}const m=Xn({fill:t.props.isClosed?t.props.fill:"none",d:h,color:t.props.color,theme:o});if(m){const S=document.createElementNS("http://www.w3.org/2000/svg","g");return S.appendChild(m),S.appendChild(p),S}return p}getCanvasSvgDefs(){return[y0()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return St[t.props.size]*r/2}}y(gh,"type","draw"),y(gh,"props",R3),y(gh,"migrations",D3);function om(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 sm(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function WH(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=t;let d=e.props.w*s,h=e.props.h*i;const p=new C(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(h>0){if(h<c){switch(o){case"top_left":case"top":case"top_right":{p.y=h-c;break}case"right":case"left":{p.y=(h-c)/2;break}default:p.y=0}h=c}}else if(p.y=h,h=-h,h<c){switch(o){case"top_left":case"top":case"top_right":{p.y=-h;break}default:p.y=-c}h=c}const{x:m,y:f}=p.rot(e.rotation).add(r);return{x:m,y:f,props:{w:Math.min(l,d),h:Math.min(u,h)}}}const GH=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class mh extends el{constructor(){super(...arguments);y(this,"hideSelectionBoundsFg",t=>!this.canResize(t));y(this,"canEdit",()=>!0);y(this,"canUnmount",t=>{var r,o;return!!((o=(r=bo(t.props.url))==null?void 0:r.definition)!=null&&o.canUnmount)});y(this,"canResize",t=>{var r,o;return!!((o=(r=bo(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});y(this,"canEditInReadOnly",()=>!0);y(this,"isAspectRatioLocked",t=>{const r=bo(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});y(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=bo(t.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const l=t.props.w/t.props.h;l>1?i*=l:a/=l}return WH(t,r,{minWidth:i,minHeight:a})})}getDefaultProps(){return{w:300,h:300,url:""}}component(t){const{w:r,h:o,url:s}=t.props,i=uf(t.id),a=w.useMemo(()=>FI(s),[s]),l=G("is hovering",()=>{const{editingShapeId:h,hoveredShapeId:p}=this.editor.getCurrentPageState();if(h&&p!==h){const m=this.editor.getShape(h);if(m&&this.editor.isShapeOfType(m,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(t).rotation(),u=i||l;if((a==null?void 0:a.definition.type)==="github_gist"){const h=a.url.split("/").pop();if(!h)throw Error("No gist id!");return g.jsx(pi,{className:"tl-embed-container",id:t.id,children:g.jsx(YH,{id:h,width:O(r),height:O(o),isInteractive:u,pageRotation:c})})}const d=GH({...L3,...(a==null?void 0:a.definition.overridePermissions)??{}});return g.jsx(pi,{className:"tl-embed-container",id:t.id,children:a!=null&&a.definition?g.jsx("iframe",{className:"tl-embed",sandbox:d,src:a.embedUrl,width:O(r),height:O(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:w0(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(t){const r=w.useMemo(()=>bo(t.props.url),[t.props.url]);return g.jsx("rect",{width:O(t.props.w),height:O(t.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}y(mh,"type","embed"),y(mh,"props",N3),y(mh,"migrations",F3);function YH({id:e,file:n,isInteractive:t,width:r,height:o,style:s,pageRotation:i}){return g.jsx("iframe",{className:"tl-embed",draggable:!1,width:O(r),height:O(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:t?"all":"none",zIndex:t?"":"-1",boxShadow:w0(i)},srcDoc:`
127
+ <html>
128
+ <head>
129
+ <base target="_blank">
130
+ </head>
131
+ <body>
132
+ <script src=${`https://gist.github.com/${e}.js${n?`?file=${n}`:""}`}><\/script>
133
+ <style type="text/css">
134
+ * { margin: 0px; }
135
+ table { height: 100%; background-color: red; }
136
+ .gist { background-color: none; height: 100%; }
137
+ .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
138
+ </style>
139
+ </body>
140
+ </html>`})}const XH=w.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=U(),s=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Dt(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=w.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,d=l.currentTarget.value.trim();u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}],{squashing:!0})},[e,o]),a=w.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,d=l.currentTarget.value;u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}],{squashing:!0})},[e,o]);return g.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[g.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:t?void 0:"none"},value:n,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),KI(n,"Frame")+"​"]})}),qH=function({id:n,name:t,width:r,height:o}){const s=U(),i=G("shape rotation",()=>_r(s.getShapePageTransform(n).rotation()),[s,n]),a=uf(n),l=w.useRef(null),c=w.useCallback(m=>{const f=vn(m);s.getEditingShapeId()!==n&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...f}),m.preventDefault())},[s,n]);w.useEffect(()=>{const m=l.current;m&&a&&(m.focus(),m.select(),requestAnimationFrame(()=>{document.activeElement!==m&&(m.focus(),m.select())}))},[l,a]);const d=((i+Math.PI/4)*(2/Math.PI)+4)%4,h=["top","left","bottom","right"][Math.floor(d)];let p;switch(h){case"top":p="";break;case"right":p=`translate(${O(r)}px, 0px) rotate(90deg)`;break;case"bottom":p=`translate(${O(r)}px, ${O(o)}px) rotate(180deg)`;break;case"left":p=`translate(0px, ${O(o)}px) rotate(270deg)`;break}return g.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(h==="top"||h==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${p} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:c,children:g.jsx("div",{className:"tl-frame-heading-hit-area",children:g.jsx(XH,{ref:l,id:n,name:t,isEditing:a})})})};function KI(e,n){return e.match(/^\s*$/)?n:e}class yh extends el{constructor(){super(...arguments);y(this,"canBind",()=>!0);y(this,"canEdit",()=>!0);y(this,"canReceiveNewChildrenOfType",(t,r)=>!t.isLocked);y(this,"canDropShapes",(t,r)=>!t.isLocked);y(this,"onDragShapesOver",(t,r)=>r.every(o=>o.parentId===t.id)?{shouldHint:!1}:(this.editor.reparentShapes(r.map(o=>o.id),t.id),{shouldHint:!0}));y(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())});y(this,"onResizeEnd",t=>{const r=this.editor.getShapePageBounds(t),o=this.editor.getSortedChildIdsForParent(t.id),s=[];for(const i of o){const a=this.editor.getShapePageBounds(i);r.includes(a)||s.push(i)}s.length>0&&this.editor.reparentShapes(s,this.editor.getCurrentPageId())});y(this,"onResize",(t,r)=>jk(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new Es({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=Et(),s=G("is creating this shape",()=>{var l;const i=this.editor.getStateDescendant("select.resizing");if(!i||!i.getIsActive())return!1;const a=i==null?void 0:i.info;return a?a.isCreating&&((l=this.editor.getOnlySelectedShape())==null?void 0:l.id)===t.id:!1},[t.id]);return g.jsxs(g.Fragment,{children:[g.jsx(Ln,{children:g.jsx("rect",{className:fe("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:g.jsx(qH,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t){const r=In({isDarkMode:this.editor.user.getIsDarkMode()}),o=document.createElementNS("http://www.w3.org/2000/svg","g"),s=document.createElementNS("http://www.w3.org/2000/svg","rect");s.setAttribute("width",t.props.w.toString()),s.setAttribute("height",t.props.h.toString()),s.setAttribute("fill",r.solid),s.setAttribute("stroke",r.black.solid),s.setAttribute("stroke-width","1"),s.setAttribute("rx","1"),s.setAttribute("ry","1"),o.appendChild(s);const l=((_r(this.editor.getShapePageTransform(t.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,c=["top","left","bottom","right"][Math.floor(l)];let u;switch(c){case"top":u="";break;case"right":u=`translate(${O(t.props.w)}px, 0px) rotate(90deg)`;break;case"bottom":u=`translate(${O(t.props.w)}px, ${O(t.props.h)}px) rotate(180deg)`;break;case"left":u=`translate(0px, ${O(t.props.h)}px) rotate(270deg)`;break;default:u=""}const d={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:t.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle"},h=this.editor.textMeasure.measureTextSpans(KI(t.props.name,"Frame")+"​",d),p=h[0],m=mn(h),f=m.box.w+m.box.x-p.box.x,S=yf(this.editor,h,{offsetY:-d.height-2,...d});S.style.setProperty("transform",u);const v=document.createElementNS("http://www.w3.org/2000/svg","rect");return v.setAttribute("x","-8px"),v.setAttribute("y",-d.height-4+"px"),v.setAttribute("width",f+16+"px"),v.setAttribute("height",`${d.height}px`),v.setAttribute("rx","4px"),v.setAttribute("ry","4px"),v.setAttribute("fill",r.background),o.appendChild(v),o.appendChild(S),o}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return g.jsx("rect",{width:O(r.width),height:O(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}y(yh,"type","frame"),y(yh,"props",z3),y(yh,"migrations",B3);function ZH(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=re.From(t[0].box);for(const{box:s}of t)o.union(s);if(e==="start-legacy")return(r-2*n-o.width)/2;if(e==="end-legacy")return-(r-2*n-o.width)/2}}function QH(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}const WI=ne.memo(function({id:n,type:t,text:r,size:o,labelColor:s,font:i,align:a,verticalAlign:l,wrap:c,bounds:u}){const{rInput:d,isEmpty:h,isEditing:p,handleFocus:m,handleChange:f,handleKeyDown:S,handleBlur:v,handleInputPointerDown:x,handleDoubleClick:b}=v0(n,t,r),P=ms.normalizeTextForDom(r),E=P.length>0,k=QH(a),I=Et();return!p&&!E?null:g.jsx("div",{className:"tl-text-label","data-font":i,"data-align":a,"data-hastext":!h,"data-isediting":p,"data-textwrap":!!c,style:{justifyContent:a==="middle"||k?"center":a,alignItems:l==="middle"?"center":l,...u?{top:u.minY,left:u.minX,width:u.width,height:u.height,position:"absolute"}:{}},children:g.jsxs("div",{className:"tl-text-label__inner",style:{fontSize:Da[o],lineHeight:Da[o]*jt.lineHeight+"px",minHeight:jt.lineHeight+32,minWidth:0,color:I[s].solid},children:[g.jsx("div",{className:"tl-text tl-text-content",dir:"ltr",children:P}),p&&g.jsx("textarea",{ref:d,className:"tl-text tl-text-input",name:"text",tabIndex:-1,autoComplete:"false",autoCapitalize:"false",autoCorrect:"false",autoSave:"false",autoFocus:!0,placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",datatype:"wysiwyg",defaultValue:r,onFocus:m,onChange:f,onKeyDown:S,onBlur:v,onContextMenu:Dt,onPointerDown:x,onDoubleClick:b})]})})});function GI({bounds:e,editor:n,font:t,shape:r}){const s={fontSize:Da[r.props.size],fontFamily:t,textAlign:r.props.align,verticalTextAlign:r.props.verticalAlign,width:Math.ceil(e.width),height:Math.ceil(e.height),padding:16,lineHeight:jt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0},i=n.textMeasure.measureTextSpans(r.props.text,s),a=ZH(r.props.align,16,i,e.width);return a&&(s.offsetX=a),yf(n,i,s)}function Ut(e){return`${O(e.x)},${O(e.y)} `}function YI(e=""){let n=0,t=0,r=0,o=0;function s(){const i=n^n<<11;return n=t,t=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)n^=e.charCodeAt(i)|0,s();return s}function Tc(e){let n="M";const t=e.length;let r,o,s;for(let i=0,a=t;i<a;i+=3)r=e[i],o=e[i+1],s=e[i+2],n+=`${Ut(r)}L${Ut(o)}Q${Ut(s)}`;return n+=`${Ut(e[0])}`,n}function $c(e,n,t,r,o){const s=[],i=YI(e);let a=n[0],l;const c=n.length;for(let u=0,d=c*o;u<d;u++){l=C.AddXY(n[(u+1)%c],i()*t,i()*t);const h=C.Sub(l,a),p=C.Len(h),m=C.Div(h,p).mul(Math.min(p/4,r));s.push(C.Add(a,m),C.Add(l,m.neg()),l),a=l}return s}function im(e,n,t){let r=`M ${Ut(n[0])}L`,o=`M ${Ut(n[0])}L`;const s=t/3,i=t*2,a=YI(e);let l=n[0],c,u=n[0],d;const h=n.length;for(let p=0,m=h-1;p<m;p++){c=n[p+1],d=C.AddXY(n[p+1],a()*s,a()*s);const f=C.Sub(c,l),S=C.Len(f),v=C.Div(f,S).mul(Math.min(S/4,i)),x=C.Add(l,v),b=C.Add(c,v.neg()),P=C.Sub(d,u),E=C.Len(P),k=C.Div(P,E).mul(Math.min(E/4,i)),I=C.Add(u,k),_=C.Add(d,k.neg());p===m-1?(r+=`${Ut(x)}L ${Ut(c)}`,o+=`${Ut(I)}L ${Ut(d)}`):(r+=`${Ut(x)}L ${Ut(b)}Q ${Ut(c)}`,o+=`${Ut(I)}L ${Ut(_)}Q ${Ut(d)}`,l=c,u=d)}return[r,r+o]}function U1(e,n){const t=Math.min(e,n)/2,r=Math.max(e,n)-t*2;return Math.PI*(t*2)+2*r}function JH(e,n,t){const r=Math.min(e,n)/2,o=Math.max(e,n)-r*2,i=(Math.PI*(r*2)+2*o)/t,a=e>n?[{type:"straight",start:new C(r,0),delta:new C(1,0)},{type:"arc",center:new C(e-r,r),startAngle:-Te/2},{type:"straight",start:new C(e-r,n),delta:new C(-1,0)},{type:"arc",center:new C(r,r),startAngle:Te/2}]:[{type:"straight",start:new C(e,r),delta:new C(0,1)},{type:"arc",center:new C(r,n-r),startAngle:0},{type:"straight",start:new C(0,n-r),delta:new C(0,-1)},{type:"arc",center:new C(r,r),startAngle:Te}];let l=0;const c=[];for(let u=0;u<t;u++){const d=a[0];d.type==="straight"?c.push(C.Add(d.start,C.Mul(d.delta,l))):c.push(di(d.center,r,d.startAngle+l/r)),l+=i;let h=d.type==="straight"?o:Te*r;for(;l>h;)l-=h,a.push(a.shift()),h=a[0].type==="straight"?o:Te*r}return c}const eV=(e,n,t,r,o)=>{switch(e){case"s":return n;case"m":return t;case"l":return r;case"xl":return o}};function Pu(e,n,t,r){const o=fs(t),s=U1(e,n),i=Math.max(Math.ceil(s/eV(r,50,70,100,130)),6,Math.ceil(s/Math.min(e,n))),a=s/i*.2,l=Math.max(e-a*2,1),c=Math.max(n-a*2,1),u=(e-l)/2,d=(n-c)/2,h=U1(l,c)/i,p=JH(l,c,i).map(x=>x.addXY(u,d)),m=e<20?0:a*.3,f=n<20?0:a*.3,S=p.slice(0);for(let x=0;x<Math.floor(i/2);x++)S[x]=C.AddXY(S[x],o()*m,o()*f),S[i-x-1]=C.AddXY(S[i-x-1],o()*m,o()*f);const v=[];for(let x=0;x<S.length;x++){const b=x===S.length-1?0:x+1,P=S[x],E=S[b],k=p[x],I=p[b],_=C.Average([k,I]),A=C.Angle(k,I)-Math.PI/2,T=C.Dist(k,I),D=h-T,z=C.Dist(P,E)/T,j=(Math.max(u,d)+D)*z,F=C.Add(_,C.FromAngle(A,j));F.x<0?F.x=0:F.x>e&&(F.x=e),F.y<0?F.y=0:F.y>n&&(F.y=n);const Y=XI(P,E,F),K=C.Dist(Y||C.Average([P,E]),P);v.push({leftPoint:P,rightPoint:E,arcPoint:F,center:Y,radius:K})}return v}function XI(e,n,t){const r=e.x*(n.y-t.y)-e.y*(n.x-t.x)+n.x*t.y-t.x*n.y,o=(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),s=(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),i=-o/(2*r),a=-s/(2*r);return!Number.isFinite(i)||!Number.isFinite(a)?null:new C(i,a)}function tV(e,n,t,r){const o=[],s=Pu(e,n,t,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of s)o.push(...nV(l,c,i,a,10));return o}function Cu(e,n,t,r){const o=Pu(e,n,t,r);let s=`M${O(o[0].leftPoint.x)},${O(o[0].leftPoint.y)}`;for(const{leftPoint:i,rightPoint:a,radius:l,center:c}of o){if(c===null){s+=` L${O(a.x)},${O(a.y)}`;continue}const u=ZI(i,a,c)?"0":"1";s+=` A${O(l)},${O(l)} 0 ${u},1 ${O(a.x)},${O(a.y)}`}return s+=" Z",s}function qI(e,n,t,r){const o=fs(t),s=r==="s"?.5:r==="m"?.7:r==="l"?.9:1.6,i=m=>m+o()*s*2,a=Pu(e,n,t,r),u=a.reduce((m,f)=>m+C.Dist(f.leftPoint,f.rightPoint),0)/a.length>s*15?m=>new C(i(m.x),i(m.y)):m=>m;let d=`M${O(a[0].leftPoint.x)},${O(a[0].leftPoint.y)}`,h=u(a[0].leftPoint),p=`M${O(h.x)},${O(h.y)}`;for(const{leftPoint:m,center:f,rightPoint:S,radius:v,arcPoint:x}of a){if(f===null){d+=` L${O(S.x)},${O(S.y)}`;const _=u(S);p+=` L${O(_.x)},${O(_.y)}`,h=_;continue}const b=ZI(m,S,f)?"0":"1";d+=` A${O(v)},${O(v)} 0 ${b},1 ${O(S.x)},${O(S.y)}`;const P=u(S),E=u(x),k=XI(h,P,E);if(!k){p+=` L${O(P.x)},${O(P.y)}`,h=P;continue}const I=Math.abs(C.Dist(k,h));p+=` A${O(I)},${O(I)} 0 ${b},1 ${O(P.x)},${O(P.y)}`,h=P}return d+p+" Z"}function nV(e,n,t,r,o){if(t===null)return[C.From(e),C.From(n)];const s=[],i=C.Angle(t,e),a=C.Angle(t,n),l=du(i,a);for(let c=0;c<o;c++){const u=c/(o-1),d=i+l*u,h=di(t,r,d);s.push(h)}return s}function ZI(e,n,t){return(n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x)>0}const rV=w.memo(function({dash:n,fill:t,color:r,strokeWidth:o,w:s,h:i,id:a,size:l}){const c=Et(),u=Cu(s,i,a,l),d=Pu(s,i,a,l);return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:c,d:u,fill:t,color:r}),g.jsx("g",{strokeWidth:o,stroke:c[r].solid,fill:"none",pointerEvents:"all",children:d.map(({leftPoint:h,rightPoint:p,center:m,radius:f},S)=>{const v=m?f*_r(_r(C.Angle(m,p))-_r(C.Angle(m,h))):C.Dist(h,p),{strokeDasharray:x,strokeDashoffset:b}=Qt(v,o,{style:n,start:"outset",end:"outset"});return g.jsx("path",{d:m?`M${h.x},${h.y}A${f},${f},0,0,1,${p.x},${p.y}`:`M${h.x},${h.y}L${p.x},${p.y}`,strokeDasharray:x,strokeDashoffset:b},S)})})]})});function oV({dash:e,fill:n,color:t,theme:r,strokeWidth:o,w:s,h:i,id:a,size:l}){const c=Cu(s,i,a,l),u=Pu(s,i,a,l),d=document.createElementNS("http://www.w3.org/2000/svg","g");d.setAttribute("stroke-width",o.toString()),d.setAttribute("stroke",r[t].solid),d.setAttribute("fill","none");for(const{leftPoint:p,rightPoint:m,center:f,radius:S}of u){const v=f?S*_r(_r(C.Angle(f,m))-_r(C.Angle(f,p))):C.Dist(p,m),{strokeDasharray:x,strokeDashoffset:b}=Qt(v,o,{style:e,start:"outset",end:"outset"}),P=document.createElementNS("http://www.w3.org/2000/svg","path");P.setAttribute("d",f?`M${p.x},${p.y}A${S},${S},0,0,1,${m.x},${m.y}`:`M${p.x},${p.y}L${m.x},${m.y}`),P.setAttribute("stroke-dasharray",x.toString()),P.setAttribute("stroke-dashoffset",b.toString()),d.appendChild(P)}const h=Xn({d:c,fill:n,color:t,theme:r});return jr(d,h)}const sV=w.memo(function({w:n,h:t,strokeWidth:r,dash:o,color:s,fill:i}){const a=Et(),l=n/2,c=t/2,u=Math.max(0,l),d=Math.max(0,c),h=Pc(u,d),{strokeDasharray:p,strokeDashoffset:m}=Qt(h<64?h*2:h,r,{style:o,snap:4,closed:!0}),f=`M${l-u},${c}a${u},${d},0,1,1,${u*2},0a${u},${d},0,1,1,-${u*2},0`;return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:a,d:f,color:s,fill:i}),g.jsx("path",{d:f,strokeWidth:r,width:O(n),height:O(t),fill:"none",stroke:a[s].solid,strokeDasharray:p,strokeDashoffset:m,pointerEvents:"all"})]})});function iV({w:e,h:n,strokeWidth:t,dash:r,color:o,theme:s,fill:i}){const a=e/2,l=n/2,c=Math.max(0,a-t/2),u=Math.max(0,l-t/2),d=Pc(c,u),{strokeDasharray:h,strokeDashoffset:p}=Qt(d<64?d*2:d,t,{style:r,snap:4,closed:!0}),m=`M${a-c},${l}a${c},${u},0,1,1,${c*2},0a${c},${u},0,1,1,-${c*2},0`,f=document.createElementNS("http://www.w3.org/2000/svg","path");f.setAttribute("d",m),f.setAttribute("stroke-width",t.toString()),f.setAttribute("width",e.toString()),f.setAttribute("height",n.toString()),f.setAttribute("fill","none"),f.setAttribute("stroke",s[o].solid),f.setAttribute("stroke-dasharray",h),f.setAttribute("stroke-dashoffset",p);const S=Xn({d:m,fill:i,color:o,theme:s});return jr(f,S)}function QI(e,n){if(n>e){const r=e/2;return`
141
+ M0,${r}
142
+ a${r},${r},0,1,1,${r*2},0
143
+ L${e},${n-r}
144
+ a${r},${r},0,1,1,-${r*2},0
145
+ Z`}const t=n/2;return`
146
+ M${t},0
147
+ L${e-t},0
148
+ a${t},${t},0,1,1,0,${t*2}
149
+ L${t},${n}
150
+ a${t},${t},0,1,1,0,${-t*2}
151
+ Z`}function JI(e,n){if(e>n){const r=n/2;return Pc(r,r)+(e-r*2)*2}const t=e/2;return Pc(t,t)+(n-t*2)*2}const aV=w.memo(function({w:n,h:t,strokeWidth:r,dash:o,color:s,fill:i}){const a=Et(),l=QI(n,t),c=JI(n,t),{strokeDasharray:u,strokeDashoffset:d}=Qt(c<64?c*2:c,r,{style:o,snap:4,start:"outset",end:"outset",closed:!0});return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:a,d:l,color:s,fill:i}),g.jsx("path",{d:l,strokeWidth:r,width:O(n),height:O(t),fill:"none",stroke:a[s].solid,strokeDasharray:u,strokeDashoffset:d,pointerEvents:"all"})]})});function H1({w:e,h:n,strokeWidth:t,dash:r,color:o,theme:s,fill:i}){const a=QI(e,n),l=JI(e,n),{strokeDasharray:c,strokeDashoffset:u}=Qt(l<64?l*2:l,t,{style:r,snap:4,closed:!0}),d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("d",a),d.setAttribute("stroke-width",t.toString()),d.setAttribute("width",e.toString()),d.setAttribute("height",n.toString()),d.setAttribute("fill","none"),d.setAttribute("stroke",s[o].solid),d.setAttribute("stroke-dasharray",c),d.setAttribute("stroke-dashoffset",u);const h=Xn({d:a,fill:i,color:o,theme:s});return jr(d,h)}const lV=w.memo(function({dash:n,fill:t,color:r,strokeWidth:o,outline:s,lines:i}){const a=Et(),l="M"+s[0]+"L"+s.slice(1)+"Z";return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:a,d:l,fill:t,color:r}),g.jsxs("g",{strokeWidth:o,stroke:a[r].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(s.length)).map((c,u)=>{const d=s[u],h=s[(u+1)%s.length],p=C.Dist(d,h),{strokeDasharray:m,strokeDashoffset:f}=Qt(p,o,{style:n,start:"outset",end:"outset"});return g.jsx("line",{x1:d.x,y1:d.y,x2:h.x,y2:h.y,strokeDasharray:m,strokeDashoffset:f},u)}),i&&i.map(([c,u],d)=>{const h=C.Dist(c,u),{strokeDasharray:p,strokeDashoffset:m}=Qt(h,o,{style:n,start:"skip",end:"outset",snap:n==="dotted"?4:void 0});return g.jsx("path",{d:`M${c.x},${c.y}L${u.x},${u.y}`,stroke:a[r].solid,strokeWidth:o,fill:"none",strokeDasharray:p,strokeDashoffset:m},`line_fg_${d}`)})]})]})});function cV({dash:e,fill:n,color:t,theme:r,strokeWidth:o,outline:s,lines:i}){const a=document.createElementNS("http://www.w3.org/2000/svg","g");if(a.setAttribute("stroke-width",o.toString()),a.setAttribute("stroke",r[t].solid),a.setAttribute("fill","none"),Array.from(Array(s.length)).forEach((c,u)=>{const d=s[u],h=s[(u+1)%s.length],p=C.Dist(d,h),{strokeDasharray:m,strokeDashoffset:f}=Qt(p,o,{style:e}),S=document.createElementNS("http://www.w3.org/2000/svg","line");S.setAttribute("x1",d.x.toString()),S.setAttribute("y1",d.y.toString()),S.setAttribute("x2",h.x.toString()),S.setAttribute("y2",h.y.toString()),S.setAttribute("stroke-dasharray",m.toString()),S.setAttribute("stroke-dashoffset",f.toString()),a.appendChild(S)}),i)for(const[c,u]of i){const d=C.Dist(c,u),{strokeDasharray:h,strokeDashoffset:p}=Qt(d,o,{style:e,start:"skip",end:"skip",snap:e==="dotted"?4:2}),m=document.createElementNS("http://www.w3.org/2000/svg","line");m.setAttribute("x1",c.x.toString()),m.setAttribute("y1",c.y.toString()),m.setAttribute("x2",u.x.toString()),m.setAttribute("y2",u.y.toString()),m.setAttribute("stroke-dasharray",h.toString()),m.setAttribute("stroke-dashoffset",p.toString()),a.appendChild(m)}const l=Xn({d:"M"+s[0]+"L"+s.slice(1)+"Z",fill:n,color:t,theme:r});return jr(a,l)}const uV=w.memo(function({fill:n,color:t,strokeWidth:r,w:o,h:s,id:i,size:a}){const l=Et(),c=qI(o,s,i,a);return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:l,d:c,fill:n,color:t}),g.jsx("path",{d:c,stroke:l[t].solid,strokeWidth:r,fill:"none"})]})});function dV({fill:e,color:n,strokeWidth:t,theme:r,w:o,h:s,id:i,size:a}){const l=qI(o,s,i,a),c=document.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",l),c.setAttribute("stroke-width",t.toString()),c.setAttribute("stroke",r[n].solid),c.setAttribute("fill","none");const u=Xn({d:l,fill:e,color:n,theme:r});return jr(c,u)}w.memo(function({id:n,w:t,h:r,strokeWidth:o,fill:s,color:i}){const a=Et(),l=x0(n,t,r,o),c=n_(n,t,r,o);return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:a,d:l,color:i,fill:s}),g.jsx("path",{d:c,fill:a[i].solid,strokeWidth:0,pointerEvents:"all"})]})});function hV({id:e,w:n,h:t,strokeWidth:r,fill:o,color:s,theme:i}){const a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",n_(e,n,t,r)),a.setAttribute("fill",i[s].solid);const l=Xn({d:x0(e,n,t,r),fill:o,color:s,theme:i});return jr(a,l)}function e_(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function t_(e,n,t,r){const o=fs(e),s=n/2,i=t/2,a=Pc(s,i),l=[],c=Re*o(),u=Re+Ve/2+Math.abs(o())*Ve,d=Math.max(16,a/10);for(let h=0;h<d;h++){const p=h/(d-1),m=c+p*u,f=Math.cos(m),S=Math.sin(m);l.push(new C(s*f+n*.5+.05*o(),i*S+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?qt.easeInOutSine(p):qt.easeInExpo(p)))/2)))}return kr(l,e_(r))}function n_(e,n,t,r){const o=e_(r);return hu(xu(sl(t_(e,n,t,r),o),o))}function x0(e,n,t,r){return ds(t_(e,n,t,r))}const pV=w.memo(function({id:n,outline:t,lines:r,fill:o,color:s,strokeWidth:i}){const a=Et(),l=$c(n,t,i/3,i*2,2);let c=Tc(l);if(r)for(const[h,p]of r)c+=`M${h.x},${h.y}L${p.x},${p.y}`;const u=$c(n,t,0,i*2,1),d=Tc(u);return g.jsxs(g.Fragment,{children:[g.jsx(pt,{d,fill:o,color:s,theme:a}),g.jsx("path",{d:c,stroke:a[s].solid,strokeWidth:i,fill:"none"})]})});function fV({id:e,outline:n,lines:t,fill:r,color:o,theme:s,strokeWidth:i}){const a=$c(e,n,i/3,i*2,2);let l=Tc(a);if(t)for(const[p,m]of t)l+=`M${p.x},${p.y}L${m.x},${m.y}`;const c=$c(e,n,0,i*2,1),u=Tc(c),d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("d",l),d.setAttribute("fill","none"),d.setAttribute("stroke",s[o].solid),d.setAttribute("stroke-width",i.toString());const h=Xn({d:u,fill:r,color:o,theme:s});return jr(d,h)}const gV=w.memo(function({fill:n,color:t,strokeWidth:r,w:o,h:s,id:i,size:a}){const l=Et(),c=Cu(o,s,i,a);return g.jsxs(g.Fragment,{children:[g.jsx(pt,{theme:l,d:c,fill:n,color:t}),g.jsx("path",{d:c,stroke:l[t].solid,strokeWidth:r,fill:"none"})]})});function mV({fill:e,color:n,strokeWidth:t,theme:r,w:o,h:s,id:i,size:a}){const l=Cu(o,s,i,a),c=document.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",l),c.setAttribute("stroke-width",t.toString()),c.setAttribute("stroke",r[n].solid),c.setAttribute("fill","none");const u=Xn({d:l,fill:e,color:n,theme:r});return jr(c,u)}const V1=w.memo(function({w:n,h:t,strokeWidth:r,fill:o,color:s}){const i=Et(),a=n/2,l=t/2,c=Math.max(0,a),u=Math.max(0,l),d=`M${a-c},${l}a${c},${u},0,1,1,${c*2},0a${c},${u},0,1,1,-${c*2},0`;return g.jsxs(g.Fragment,{children:[g.jsx(pt,{d,color:s,fill:o,theme:i}),g.jsx("path",{d,stroke:i[s].solid,strokeWidth:r,fill:"none"})]})});function yV({w:e,h:n,strokeWidth:t,fill:r,color:o,theme:s}){const i=e/2,a=n/2,l=Math.max(0,i),c=Math.max(0,a),u=`M${i-l},${a}a${l},${c},0,1,1,${l*2},0a${l},${c},0,1,1,-${l*2},0`,d=document.createElementNS("http://www.w3.org/2000/svg","path");d.setAttribute("d",u),d.setAttribute("stroke-width",t.toString()),d.setAttribute("width",e.toString()),d.setAttribute("height",n.toString()),d.setAttribute("fill","none"),d.setAttribute("stroke",s[o].solid);const h=Xn({d:u,fill:r,color:o,theme:s});return jr(d,h)}const K1=w.memo(function({w:n,h:t,strokeWidth:r,fill:o,color:s}){const i=Et(),a=b0(n,t);return g.jsxs(g.Fragment,{children:[g.jsx(pt,{d:a,color:s,fill:o,theme:i}),g.jsx("path",{d:a,stroke:i[s].solid,strokeWidth:r,fill:"none"})]})});function SV({w:e,h:n,strokeWidth:t,fill:r,color:o,theme:s}){const i=b0(e,n),a=document.createElementNS("http://www.w3.org/2000/svg","path");a.setAttribute("d",i),a.setAttribute("stroke-width",t.toString()),a.setAttribute("width",e.toString()),a.setAttribute("height",n.toString()),a.setAttribute("fill","none"),a.setAttribute("stroke",s[o].solid);const l=Xn({d:i,fill:r,color:o,theme:s});return jr(a,l)}function b0(e,n){let t;if(n>e){const r=e/2;t=`
152
+ M0,${r}
153
+ a${r},${r},0,1,1,${r*2},0
154
+ L${e},${n-r}
155
+ a${r},${r},0,1,1,-${r*2},0
156
+ Z`}else{const r=n/2;t=`
157
+ M${r},0
158
+ L${e-r},0
159
+ a${r},${r},0,1,1,0,${r*2}
160
+ L${r},${n}
161
+ a${r},${r},0,1,1,0,${-r*2}
162
+ Z`}return t}const vV=w.memo(function({outline:n,lines:t,fill:r,color:o,strokeWidth:s}){const i=Et();let a="M"+n[0]+"L"+n.slice(1)+"Z";if(t)for(const[l,c]of t)a+=`M${l.x},${l.y}L${c.x},${c.y}`;return g.jsxs(g.Fragment,{children:[g.jsx(pt,{d:a,fill:r,color:o,theme:i}),g.jsx("path",{d:a,stroke:i[o].solid,strokeWidth:s,fill:"none"})]})});function wV({outline:e,lines:n,fill:t,color:r,strokeWidth:o,theme:s}){const i="M"+e[0]+"L"+e.slice(1)+"Z",a=i;let l=i;if(n)for(const[d,h]of n)l+=`M${d.x},${d.y}L${h.x},${h.y}`;const c=document.createElementNS("http://www.w3.org/2000/svg","path");c.setAttribute("d",l),c.setAttribute("stroke-width",o.toString()),c.setAttribute("stroke",s[r].solid),c.setAttribute("fill","none");const u=Xn({d:a,fill:t,color:r,theme:s});return jr(c,u)}const am=16,nr=17*3;class Sh extends el{constructor(){super(...arguments);y(this,"canEdit",()=>!0);y(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});y(this,"onResize",(t,{handle:r,newPoint:o,scaleX:s,scaleY:i,initialShape:a})=>{let l=a.props.w*s,c=(a.props.h+a.props.growY)*i,u=0,d=0;if(t.props.text.trim()){let f=Math.max(Math.abs(l),nr),S=Math.max(Math.abs(c),nr);f<nr&&S===nr&&(f=nr),f===nr&&S<nr&&(S=nr);const v=gd(this.editor,{...t,props:{...t.props,w:f,h:S}}),x=Math.max(Math.abs(l),v.w)*Math.sign(l),b=Math.max(Math.abs(c),v.h)*Math.sign(c);u=Math.abs(x)-Math.abs(l),d=Math.abs(b)-Math.abs(c),l=x,c=b}const h=new C(0,0);s<0&&(h.x+=l),(r==="left"||r==="top_left"||r==="bottom_left")&&(h.x+=s<0?u:-u),i<0&&(h.y+=c),(r==="top"||r==="top_left"||r==="top_right")&&(h.y+=i<0?d:-d);const{x:p,y:m}=h.rot(t.rotation).add(o);return{x:p,y:m,props:{w:Math.max(Math.abs(l),1),h:Math.max(Math.abs(c),1),growY:0}}});y(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=gd(this.editor,t).h;let s=null;if(o>r?s=o-r:t.props.growY&&(s=0),s!==null)return{...t,props:{...t.props,growY:s}}});y(this,"onBeforeUpdate",(t,r)=>{const o=t.props.text,s=r.props.text;if(o===s&&t.props.font===r.props.font&&t.props.size===r.props.size)return;if(o&&!s)return{...r,props:{...r.props,growY:0}};const i=t.props.w,a=t.props.h,l=gd(this.editor,r),c=l.w,u=l.h;if(!o&&s&&s.length===1){let h=Math.max(i,c),p=Math.max(a,u);return t.props.w<nr&&t.props.h<nr&&(h=Math.max(h,nr),p=Math.max(p,nr),h=Math.max(h,p),p=Math.max(h,p)),{...r,props:{...r.props,w:h,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,c)}};if(c>t.props.w)return{...r,props:{...r.props,w:c}}});y(this,"onDoubleClick",t=>{if(this.editor.inputs.altKey)switch(t.props.geo){case"rectangle":return{...t,props:{geo:"check-box"}};case"check-box":return{...t,props:{geo:"rectangle"}}}})}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:""}}getGeometry(t){const r=Math.max(1,t.props.w),o=Math.max(1,t.props.h+t.props.growY),s=r/2,i=o/2,a=St[t.props.size],l=t.props.fill!=="none";let c;switch(t.props.geo){case"cloud":{c=new gt({points:tV(r,o,t.id,t.props.size),isFilled:l});break}case"triangle":{c=new gt({points:[new C(s,0),new C(r,o),new C(0,o)],isFilled:l});break}case"diamond":{c=new gt({points:[new C(s,0),new C(r,i),new C(s,o),new C(0,i)],isFilled:l});break}case"pentagon":{c=new gt({points:mg(r,o,5),isFilled:l});break}case"hexagon":{c=new gt({points:mg(r,o,6),isFilled:l});break}case"octagon":{c=new gt({points:mg(r,o,8),isFilled:l});break}case"ellipse":{c=new Fk({width:r,height:o,isFilled:l});break}case"oval":{c=new y4({width:r,height:o,isFilled:l});break}case"star":{const S=Re/5/2,v=Math.floor(5/4)*2,x=5*2-v,b=0,P=Math.floor(5/2)*2,E=Math.cos(-Ve+v*S)*r/2,k=Math.cos(-Ve+x*S)*r/2,I=Math.sin(-Ve+b*S)*o/2,_=Math.sin(-Ve+P*S)*o/2,A=r-Math.abs(E-k),T=o-Math.abs(_-I),D=r/2+k-(r/2-E),L=o/2+I-(o/2-_),z=1,j=(r-D)/2,F=(o-L)/2,Y=(r+A)/2,K=(o+T)/2,H=Y*z/2,B=K*z/2;c=new gt({points:Array.from(Array(5*2)).map((V,X)=>{const ae=-Ve+X*S;return new C(j+(X%2?H:Y)*Math.cos(ae),F+(X%2?B:K)*Math.sin(ae))}),isFilled:l});break}case"rhombus":{const f=Math.min(r*.38,o*.38);c=new gt({points:[new C(f,0),new C(r,0),new C(r-f,o),new C(0,o)],isFilled:l});break}case"rhombus-2":{const f=Math.min(r*.38,o*.38);c=new gt({points:[new C(0,0),new C(r-f,0),new C(r,o),new C(f,o)],isFilled:l});break}case"trapezoid":{const f=Math.min(r*.38,o*.38);c=new gt({points:[new C(f,0),new C(r-f,0),new C(r,o),new C(0,o)],isFilled:l});break}case"arrow-right":{const f=Math.min(r,o)*.38,S=o*.16;c=new gt({points:[new C(0,S),new C(r-f,S),new C(r-f,0),new C(r,o/2),new C(r-f,o),new C(r-f,o-S),new C(0,o-S)],isFilled:l});break}case"arrow-left":{const f=Math.min(r,o)*.38,S=o*.16;c=new gt({points:[new C(f,0),new C(f,S),new C(r,S),new C(r,o-S),new C(f,o-S),new C(f,o),new C(0,o/2)],isFilled:l});break}case"arrow-up":{const f=r*.16,S=Math.min(r,o)*.38;c=new gt({points:[new C(r/2,0),new C(r,S),new C(r-f,S),new C(r-f,o),new C(f,o),new C(f,S),new C(0,S)],isFilled:l});break}case"arrow-down":{const f=r*.16,S=Math.min(r,o)*.38;c=new gt({points:[new C(f,0),new C(r-f,0),new C(r-f,o-S),new C(r,o-S),new C(r/2,o),new C(0,o-S),new C(f,o-S)],isFilled:l});break}case"check-box":case"x-box":case"rectangle":{c=new Es({width:r,height:o,isFilled:l,isSnappable:!0});break}}const u=gd(this.editor,t),d=Math.min(r,Math.max(u.w,Math.min(32,Math.max(1,r-8)))),h=Math.min(o,Math.max(u.h,Math.min(32,Math.max(1,r-8)))),p=md(t.props,a),m=p?p.map(f=>new Pi({points:f})):[];return new Po({children:[c,new Es({x:t.props.align==="start"?0:t.props.align==="end"?r-d:(r-d)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?o-h:(o-h)/2,width:d,height:h,isFilled:!0,isSnappable:!1,isLabel:!0}),...m],isSnappable:!1})}component(t){const{id:r,type:o,props:s}=t,i=St[s.size],{w:a,color:l,labelColor:c,fill:u,dash:d,growY:h,font:p,align:m,verticalAlign:f,size:S,text:v}=s,x=()=>{const b=s.h+h;switch(s.geo){case"cloud":{if(d==="solid")return g.jsx(gV,{color:l,fill:u,strokeWidth:i,w:a,h:b,id:r,size:S});if(d==="dashed"||d==="dotted")return g.jsx(rV,{color:l,fill:u,strokeWidth:i,w:a,h:b,id:r,size:S,dash:d});if(d==="draw")return g.jsx(uV,{color:l,fill:u,strokeWidth:i,w:a,h:b,id:r,size:S});break}case"ellipse":{if(d==="solid")return g.jsx(V1,{strokeWidth:i,w:a,h:b,color:l,fill:u});if(d==="dashed"||d==="dotted")return g.jsx(sV,{id:r,strokeWidth:i,w:a,h:b,dash:d,color:l,fill:u});if(d==="draw")return g.jsx(V1,{strokeWidth:i,w:a,h:b,color:l,fill:u});break}case"oval":{if(d==="solid")return g.jsx(K1,{strokeWidth:i,w:a,h:b,color:l,fill:u});if(d==="dashed"||d==="dotted")return g.jsx(aV,{id:r,strokeWidth:i,w:a,h:b,dash:d,color:l,fill:u});if(d==="draw")return g.jsx(K1,{strokeWidth:i,w:a,h:b,color:l,fill:u});break}default:{const P=this.editor.getShapeGeometry(t),E=P instanceof Po?P.children[0].vertices:P.vertices,k=md(t.props,i);if(d==="solid")return g.jsx(vV,{fill:u,color:l,strokeWidth:i,outline:E,lines:k});if(d==="dashed"||d==="dotted")return g.jsx(lV,{dash:d,fill:u,color:l,strokeWidth:i,outline:E,lines:k});if(d==="draw")return g.jsx(pV,{id:r,fill:u,color:l,strokeWidth:i,outline:E,lines:k})}}};return g.jsxs(g.Fragment,{children:[g.jsx(Ln,{id:r,children:x()}),g.jsxs(pi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:[g.jsx(WI,{id:r,type:o,font:p,fill:u,size:S,align:m,verticalAlign:f,text:v,labelColor:c,wrap:!0,bounds:s.geo==="cloud"?this.getGeometry(t).bounds:void 0}),t.props.url&&g.jsx(bu,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]})}indicator(t){const{id:r,props:o}=t,{w:s,size:i}=o,a=o.h+o.growY,l=St[i];switch(o.geo){case"ellipse":return o.dash==="draw"?g.jsx("path",{d:x0(r,s,a,l)}):g.jsx("ellipse",{cx:s/2,cy:a/2,rx:s/2,ry:a/2});case"oval":return g.jsx("path",{d:b0(s,a)});case"cloud":return g.jsx("path",{d:Cu(s,a,r,i)});default:{const c=this.editor.getShapeGeometry(t),u=c instanceof Po?c.children[0].vertices:c.vertices;let d;if(o.dash==="draw"){const p=$c(r,u,0,l*2,1);d=Tc(p)}else d="M"+u[0]+"L"+u.slice(1)+"Z";const h=md(t.props,l);if(h)for(const[p,m]of h)d+=`M${p.x},${p.y}L${m.x},${m.y}`;return g.jsx("path",{d})}}}toSvg(t,r){const{id:o,props:s}=t,i=St[s.size],a=In({isDarkMode:this.editor.user.getIsDarkMode()});r.addExportDef(m0(t.props.fill,a));let l;switch(s.geo){case"ellipse":{switch(s.dash){case"draw":l=hV({id:o,w:s.w,h:s.h,color:s.color,fill:s.fill,strokeWidth:i,theme:a});break;case"solid":l=yV({strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,theme:a});break;default:l=iV({id:o,strokeWidth:i,w:s.w,h:s.h,dash:s.dash,color:s.color,fill:s.fill,theme:a});break}break}case"oval":{switch(s.dash){case"draw":l=H1({id:o,strokeWidth:i,w:s.w,h:s.h,dash:s.dash,color:s.color,fill:s.fill,theme:a});break;case"solid":l=SV({strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,theme:a});break;default:l=H1({id:o,strokeWidth:i,w:s.w,h:s.h,dash:s.dash,color:s.color,fill:s.fill,theme:a})}break}case"cloud":{switch(s.dash){case"draw":l=dV({id:o,strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,size:s.size,theme:a});break;case"solid":l=mV({strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,size:s.size,id:o,theme:a});break;default:l=oV({id:o,strokeWidth:i,w:s.w,h:s.h,dash:s.dash,color:s.color,fill:s.fill,theme:a,size:s.size})}break}default:{const c=this.editor.getShapeGeometry(t),u=c instanceof Po?c.children[0].vertices:c.vertices,d=md(t.props,i);switch(s.dash){case"draw":l=fV({id:o,fill:s.fill,color:s.color,strokeWidth:i,outline:u,lines:d,theme:a});break;case"solid":l=wV({fill:s.fill,color:s.color,strokeWidth:i,outline:u,lines:d,theme:a});break;default:l=cV({dash:s.dash,fill:s.fill,color:s.color,strokeWidth:i,outline:u,lines:d,theme:a});break}break}}if(s.text){const c=this.editor.getShapeGeometry(t).bounds;r.addExportDef(Sf(t.props.font));const u=GI({editor:this.editor,shape:t,font:au[t.props.font],bounds:c}),d=u.cloneNode(!0);d.setAttribute("fill",a[t.props.labelColor].solid),d.setAttribute("stroke","none");const h=u.cloneNode(!0);h.setAttribute("stroke-width","2"),h.setAttribute("fill",a.background),h.setAttribute("stroke",a.background);const p=document.createElementNS("http://www.w3.org/2000/svg","g");if(p.append(h),p.append(d),l.nodeName==="g")return l.appendChild(p),l;{const m=document.createElementNS("http://www.w3.org/2000/svg","g");return m.appendChild(l),m.appendChild(p),m}}return l}getCanvasSvgDefs(){return[y0()]}}y(Sh,"type","geo"),y(Sh,"props",U3),y(Sh,"migrations",H3);function gd(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...jt,fontFamily:To[n.props.font],fontSize:Da[n.props.size],maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(t,{...jt,fontFamily:To[n.props.font],fontSize:Da[n.props.size],minWidth:r.w+"px",maxWidth:Math.max(0,Math.ceil(r.w+o[n.props.size]),Math.ceil(n.props.w-am*2))});return{w:s.w+am*2,h:s.h+am*2}}function md(e,n){switch(e.geo){case"x-box":return xV(e.w,e.h,n,e.dash);case"check-box":return bV(e.w,e.h);default:return}}function xV(e,n,t,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new C(0,0),new C(e/2,n/2)],[new C(e,n),new C(e/2,n/2)],[new C(0,n),new C(e/2,n/2)],[new C(e,0),new C(e/2,n/2)]];const s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(n,a));return[[new C(s(t*o),i(t*o)),new C(s(e-t*o),i(n-t*o))],[new C(s(t*o),i(n-t*o)),new C(s(e-t*o),i(t*o))]]}function bV(e,n){const t=Math.min(e,n)*.82,r=(e-t)/2,o=(n-t)/2,s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(n,a));return[[new C(s(r+t*.25),i(o+t*.52)),new C(s(r+t*.45),i(o+t*.82))],[new C(s(r+t*.45),i(o+t*.82)),new C(s(r+t*.82),i(o+t*.22))]]}function PV(){const[e,n]=w.useState(!1);return w.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");n(r&&o.matches);const s=()=>n(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),G(Oe.forceSrgb)||!e?"srgb":"p3"}const W1=.35,G1=.82;class vh extends Tr{constructor(){super(...arguments);y(this,"hideResizeHandles",t=>yd(t));y(this,"hideRotateHandle",t=>yd(t));y(this,"hideSelectionBoundsFg",t=>yd(t));y(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:o*l,y:s*c,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1}}getGeometry(t){const r=Wi(t);if(yd(t))return new Gv({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=r_(t,r,!0),i=Qy({strokeWidth:s,showAsComplete:!0});return sl(o,i),new gt({points:xu(o,i),isFilled:!0})}component(t){return g.jsx(Y1,{strokeWidth:Wi(t),shape:t,opacity:W1})}backgroundComponent(t){return g.jsx(Y1,{strokeWidth:Wi(t),shape:t,opacity:G1})}indicator(t){var d;const r=vp(),o=Wi(t),s=ia(t.props.segments);let i=o;!r&&!t.props.isPen&&s.length===1&&(i+=fs(t.id)()*(o/6));const a=t.props.isComplete||((d=mn(t.props.segments))==null?void 0:d.type)==="straight",l=Qy({strokeWidth:o,showAsComplete:a}),c=kr(s,l);let u;return c.length<2?u=EV(s[0],i):u=ds(c,!1),g.jsx("path",{d:u})}toSvg(t){const r=In({isDarkMode:this.editor.user.getIsDarkMode()});return X1(Wi(t),t,W1,r)}toBackgroundSvg(t){const r=In({isDarkMode:this.editor.user.getIsDarkMode()});return X1(Wi(t),t,G1,r)}}y(vh,"type","highlight"),y(vh,"props",W3),y(vh,"migrations",G3);function CV(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 EV(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 r_(e,n,t){var l;const r=ia(e.props.segments),o=e.props.isComplete||((l=mn(e.props.segments))==null?void 0:l.type)==="straight";let s=n;!t&&!e.props.isPen&&r.length===1&&(s+=fs(e.id)()*(n/6));const i=Qy({strokeWidth:s,showAsComplete:o});return{strokePoints:kr(r,i),sw:s}}function o_(e,n,t){const{strokePoints:r,sw:o}=r_(e,n,t);return{solidStrokePath:r.length>1?ds(r,!1):CV(e.props.segments[0].points[0]),sw:o}}function Y1({strokeWidth:e,shape:n,opacity:t}){const r=Et(),o=vp(),{solidStrokePath:s,sw:i}=o_(n,e,o),a=PV(),l=r[n.props.color].highlight[a];return g.jsx(Ln,{id:n.id,style:{opacity:t},children:g.jsx("path",{d:s,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:l,strokeWidth:i})})}function X1(e,n,t,r){const{solidStrokePath:o,sw:s}=o_(n,e,!1),i=document.createElementNS("http://www.w3.org/2000/svg","path");return i.setAttribute("d",o),i.setAttribute("fill","none"),i.setAttribute("stroke",r[n.props.color].highlight.srgb),i.setAttribute("stroke-width",`${s}`),i.setAttribute("opacity",`${t}`),i}function Wi(e){return us[e.props.size]*1.12}function yd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function s_(){const[e,n]=w.useState(!1);return w.useEffect(()=>{const t=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{n(t.matches)};return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),e}const kV=async e=>new Promise((n,t)=>{const r=new Image;r.onload=()=>n(r),r.onerror=()=>t(new Error("Failed to load image")),r.crossOrigin="anonymous",r.src=e}),IV=async e=>{const n=await kV(e),t=document.createElement("canvas");t.width=n.width,t.height=n.height;const r=t.getContext("2d");if(r)return r.drawImage(n,0,0),t.toDataURL()};async function _V(e){const t=await(await fetch(e)).blob();return new Promise((r,o)=>{const s=new FileReader;s.onloadend=()=>r(s.result),s.onerror=o,s.readAsDataURL(t)})}class wh extends el{constructor(){super(...arguments);y(this,"isAspectRatioLocked",()=>!0);y(this,"canCrop",()=>!0);y(this,"onDoubleClick",t=>{const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;!r||!(r.props.src&&"mimeType"in r.props&&r.props.mimeType==="image/gif")||this.editor.updateShapes([{type:"image",id:t.id,props:{playing:!t.props.playing}}])});y(this,"onDoubleClickEdge",t=>{const r=t.props;if(!r||this.editor.getCroppingShapeId()!==t.id)return;const o=Zt(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},s=1/(o.bottomRight.x-o.topLeft.x)*t.props.w,i=1/(o.bottomRight.y-o.topLeft.y)*t.props.h,a=new C(o.topLeft.x*s,o.topLeft.y*i).rot(t.rotation),l={id:t.id,type:t.type,x:t.x-a.x,y:t.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([l])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}component(t){var h,p;const r=q1(t),o=$b(t.id),s=s_(),[i,a]=w.useState(""),l=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;if((l==null?void 0:l.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const u=G("onlySelectedShape",()=>{var m;return t.id===((m=this.editor.getOnlySelectedShape())==null?void 0:m.id)},[this.editor])&&o&&this.editor.isInAny("select.crop","select.cropping","select.pointing_crop_handle"),d=s&&(((h=l==null?void 0:l.props.mimeType)==null?void 0:h.includes("video"))||((p=l==null?void 0:l.props.mimeType)==null?void 0:p.includes("gif")));return w.useEffect(()=>{if(l!=null&&l.props.src&&"mimeType"in l.props&&(l==null?void 0:l.props.mimeType)==="image/gif"){let m=!1;return(async()=>{const S=await IV(l.props.src);m||S&&a(S)})(),()=>{m=!0}}},[s,l==null?void 0:l.props]),g.jsxs(g.Fragment,{children:[(l==null?void 0:l.props.src)&&u&&g.jsx("div",{style:r,children:g.jsx("div",{className:"tl-image",style:{opacity:.1,backgroundImage:`url(${!t.props.playing||d?i:l.props.src})`},draggable:!1})}),g.jsxs(pi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h},children:[g.jsxs("div",{className:"tl-image-container",style:r,children:[l!=null&&l.props.src?g.jsx("div",{className:"tl-image",style:{backgroundImage:`url(${!t.props.playing||d?i:l.props.src})`},draggable:!1}):null,(l==null?void 0:l.props.isAnimated)&&!t.props.playing&&g.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),"url"in t.props&&t.props.url&&g.jsx(bu,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]})}indicator(t){return $b(t.id)?null:g.jsx("rect",{width:O(t.props.w),height:O(t.props.h)})}shouldGetDataURI(t){return t&&(t.startsWith("http")||t.startsWith("/")||t.startsWith("./"))}async toSvg(t){const r=document.createElementNS("http://www.w3.org/2000/svg","g"),o=t.props.assetId?this.editor.getAsset(t.props.assetId):null;let s=(o==null?void 0:o.props.src)||"";this.shouldGetDataURI(s)&&(s=await _V(s)||"");const i=document.createElementNS("http://www.w3.org/2000/svg","image");i.setAttributeNS("http://www.w3.org/1999/xlink","href",s);const a=q1(t),l=t.props.crop;if(a.transform&&l){const{transform:c,width:u,height:d}=a,h=(l.bottomRight.x-l.topLeft.x)*u,p=(l.bottomRight.y-l.topLeft.y)*d,m=[new C(0,0),new C(h,0),new C(h,p),new C(0,p)],f=document.createElementNS("http://www.w3.org/2000/svg","polygon");f.setAttribute("points",m.map(b=>`${b.x},${b.y}`).join(" "));const S=document.createElementNS("http://www.w3.org/2000/svg","clipPath");S.setAttribute("id","cropClipPath"),S.appendChild(f);const v=document.createElementNS("http://www.w3.org/2000/svg","defs");v.appendChild(S),r.appendChild(v);const x=document.createElementNS("http://www.w3.org/2000/svg","g");x.setAttribute("clip-path","url(#cropClipPath)"),i.setAttribute("width",u.toString()),i.setAttribute("height",d.toString()),i.style.transform=c,x.appendChild(i),r.appendChild(x)}else i.setAttribute("width",t.props.w.toString()),i.setAttribute("height",t.props.h.toString()),r.appendChild(i);return r}}y(wh,"type","image"),y(wh,"props",X3),y(wh,"migrations",q3);function q1(e){const n=e.props.crop,t=n==null?void 0:n.topLeft;if(!t)return{width:e.props.w,height:e.props.h};const r=1/(n.bottomRight.x-n.topLeft.x)*e.props.w,o=1/(n.bottomRight.y-n.topLeft.y)*e.props.h,s=-t.x*r,i=-t.y*o;return{transform:`translate(${s}px, ${i}px)`,width:r,height:o}}function Jy(e,n){const{start:t,end:r}=e;return n?`M${O(t.x)},${O(t.y)} L${O(r.x)},${O(r.y)} `:`${O(r.x)},${O(r.y)} `}function eS(e,n){const{a:t,b:r,c:o,d:s}=e;return C.Equals(t,s)?"":`${n?`M${O(t.x)},${O(t.y)}`:""}C${O(r.x)},${O(r.y)} ${O(o.x)},${O(o.y)} ${O(s.x)},${O(s.y)}`}function i_(e,n){let t=e.segments.reduce((r,o,s)=>r+eS(o,s===0),"");return n&&(t+="Z"),t}function TV(e,n){let t=e.segments.reduce((r,o,s)=>r+Jy(o,s===0),"");return n&&(t+="Z"),t}function a_(e,n=!1){return e instanceof Pi?TV(e,n):i_(e,n)}function l_(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function c_(e,n,t){const r=n.vertices,o=l_(t);return kr(r,o)}function $V(e,n,t){const r=l_(t);return xu(sl(c_(e,n,t),r),r)}function Z1(e,n,t){const r=$V(e,n,t);return hu(r)}function AV(e,n,t){if(e.props.dash==="draw"){const r=c_(e,n,t);return ds(r)}return a_(n)}const MV=new Bv;class xh extends Tr{constructor(){super(...arguments);y(this,"hideResizeHandles",()=>!0);y(this,"hideRotateHandle",()=>!0);y(this,"hideSelectionBoundsFg",()=>!0);y(this,"hideSelectionBoundsBg",()=>!0);y(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=Zt(t.props.handles);return Object.values(t.props.handles).forEach(({id:a,x:l,y:c})=>{i[a].x=l*o,i[a].y=c*s}),{props:{handles:i}}});y(this,"onHandleDrag",(t,{handle:r})=>{const o=Zt(t);switch(r.id){case"start":case"end":{o.props.handles[r.id]={...o.props.handles[r.id],x:r.x,y:r.y};break}default:{const s="handle:"+r.index,i=t.props.handles[s];i?o.props.handles[s]={...i,x:r.x,y:r.y}:o.props.handles[s]={id:s,type:"vertex",canBind:!1,index:r.index,x:r.x,y:r.y};break}}return o})}getDefaultProps(){return{dash:"draw",size:"m",color:"black",spline:"line",handles:{start:{id:"start",type:"vertex",canBind:!1,canSnap:!0,index:"a1",x:0,y:0},end:{id:"end",type:"vertex",canBind:!1,canSnap:!0,index:"a2",x:.1,y:.1}}}}getGeometry(t){return $l(t)}getHandles(t){return MV.get(t.props,()=>{const r=t.props.handles,o=$l(t),s=Object.values(r).sort(Wt),i=s.slice();for(let a=0;a<o.segments.length;a++){const c=o.segments[a].midPoint(),u=nc(s[a].index,s[a+1].index);i.push({id:`mid-${a}`,type:"create",index:u,x:c.x,y:c.y})}return i.sort(Wt)})}getOutlineSegments(t){return this.editor.getShapeGeometry(t).segments.map(o=>o.vertices)}component(t){const r=Et(),o=$l(t),s=St[t.props.size],{dash:i,color:a}=t.props;if(t.props.spline==="line"){if(i==="solid"){const l=o.points,c="M"+l[0]+"L"+l.slice(1);return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{d:c,fill:"none",color:a,theme:r}),g.jsx("path",{d:c,stroke:r[a].solid,strokeWidth:s,fill:"none"})]})}if(i==="dashed"||i==="dotted"){const l=o.points,c="M"+l[0]+"L"+l.slice(1);return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{d:c,fill:"none",color:a,theme:r}),g.jsx("g",{stroke:r[a].solid,strokeWidth:s,children:o.segments.map((u,d)=>{const{strokeDasharray:h,strokeDashoffset:p}=Qt(u.length,s,{style:i,start:d>0?"outset":"none",end:d<o.segments.length-1?"outset":"none"});return g.jsx("path",{strokeDasharray:h,strokeDashoffset:p,d:Jy(u,!0),fill:"none"},d)})})]})}if(i==="draw"){const l=o.points,[c,u]=im(t.id,l,s);return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{d:c,fill:"none",color:a,theme:r}),g.jsx("path",{d:u,stroke:r[a].solid,strokeWidth:s,fill:"none"})]})}}if(t.props.spline==="cubic"){const l=a_(o);if(i==="solid")return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{d:l,fill:"none",color:a,theme:r}),g.jsx("path",{strokeWidth:s,stroke:r[a].solid,fill:"none",d:l})]});if(i==="dashed"||i==="dotted")return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{d:l,fill:"none",color:a,theme:r}),g.jsx("g",{stroke:r[a].solid,strokeWidth:s,children:o.segments.map((c,u)=>{const{strokeDasharray:d,strokeDashoffset:h}=Qt(c.length,s,{style:i,start:u>0?"outset":"none",end:u<o.segments.length-1?"outset":"none"});return g.jsx("path",{strokeDasharray:d,strokeDashoffset:h,d:eS(c,!0),fill:"none"},u)})})]});if(i==="draw")return g.jsxs(Ln,{id:t.id,children:[g.jsx(pt,{d:l,fill:"none",color:a,theme:r}),g.jsx("path",{d:Z1(t,o,s),strokeWidth:1,stroke:r[a].solid,fill:r[a].solid})]})}}indicator(t){const r=St[t.props.size],o=$l(t),{dash:s}=t.props;let i;if(t.props.spline==="line"){const a=o.points;if(s==="solid"||s==="dotted"||s==="dashed")i="M"+a[0]+"L"+a.slice(1);else{const[l]=im(t.id,a,r);i=l}}else i=AV(t,o,r);return g.jsx("path",{d:i})}toSvg(t){const o=In({isDarkMode:this.editor.user.getIsDarkMode()})[t.props.color].solid,s=$l(t),i=St[t.props.size];switch(t.props.dash){case"draw":{let a;if(s instanceof nh)a=Z1(t,s,i);else{const[c,u]=im(t.id,s.points,i);a=u}const l=document.createElementNS("http://www.w3.org/2000/svg","path");return l.setAttribute("stroke-width",i+"px"),l.setAttribute("stroke",o),l.setAttribute("fill","none"),l.setAttribute("d",a),l}case"solid":{let a;if(s instanceof nh)a=i_(s,!1);else{const c=s.points;a="M"+c[0]+"L"+c.slice(1)}const l=document.createElementNS("http://www.w3.org/2000/svg","path");return l.setAttribute("stroke-width",i+"px"),l.setAttribute("stroke",o),l.setAttribute("fill","none"),l.setAttribute("d",a),l}default:{const{segments:a}=s,l=document.createElementNS("http://www.w3.org/2000/svg","g");l.setAttribute("stroke",o),l.setAttribute("stroke-width",i.toString());const c=s instanceof nh?eS:Jy;return a.forEach((u,d)=>{const h=document.createElementNS("http://www.w3.org/2000/svg","path"),{strokeDasharray:p,strokeDashoffset:m}=Qt(u.length,i,{style:t.props.dash,start:d>0?"outset":"none",end:d<a.length-1?"outset":"none"});h.setAttribute("stroke-dasharray",p.toString()),h.setAttribute("stroke-dashoffset",m.toString()),h.setAttribute("d",c(u,!0)),h.setAttribute("fill","none"),l.appendChild(h)}),l}}}}y(xh,"type","line"),y(xh,"props",J3),y(xh,"migrations",eD);function $l(e){const{spline:n,handles:t}=e.props,r=Object.values(t).sort(Wt).map(C.From);switch(n){case"cubic":return new nh({points:r});case"line":return new Pi({points:r})}}const vo=200;class bh extends Tr{constructor(){super(...arguments);y(this,"canEdit",()=>!0);y(this,"hideResizeHandles",()=>!0);y(this,"hideSelectionBoundsFg",()=>!0);y(this,"onBeforeCreate",t=>Q1(this.editor,t,t.props.growY));y(this,"onBeforeUpdate",(t,r)=>{if(!(t.props.text===r.props.text&&t.props.font===r.props.font&&t.props.size===r.props.size))return Q1(this.editor,r,t.props.growY)});y(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,url:""}}getHeight(t){return vo+t.props.growY}getGeometry(t){const r=this.getHeight(t);return new Es({width:vo,height:r,isFilled:!0})}component(t){const{id:r,type:o,props:{color:s,font:i,size:a,align:l,text:c,verticalAlign:u}}=t,d=Et(),h=s==="black"?"yellow":s;return g.jsxs(g.Fragment,{children:[g.jsx("div",{style:{position:"absolute",width:vo,height:this.getHeight(t)},children:g.jsxs("div",{className:"tl-note__container",style:{color:d[h].solid,backgroundColor:d[h].solid},children:[g.jsx("div",{className:"tl-note__scrim"}),g.jsx(WI,{id:r,type:o,font:i,size:a,align:l,verticalAlign:u,text:c,labelColor:"black",wrap:!0})]})}),"url"in t.props&&t.props.url&&g.jsx(bu,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return g.jsx("rect",{rx:"6",width:O(vo),height:O(this.getHeight(t))})}toSvg(t,r){r.addExportDef(Sf(t.props.font));const o=In({isDarkMode:this.editor.user.getIsDarkMode()}),s=this.editor.getShapeGeometry(t).bounds,i=document.createElementNS("http://www.w3.org/2000/svg","g"),a=t.props.color==="black"?"yellow":t.props.color,l=document.createElementNS("http://www.w3.org/2000/svg","rect");l.setAttribute("rx","10"),l.setAttribute("width",vo.toString()),l.setAttribute("height",s.height.toString()),l.setAttribute("fill",o[a].solid),l.setAttribute("stroke",o[a].solid),l.setAttribute("stroke-width","1"),i.appendChild(l);const c=document.createElementNS("http://www.w3.org/2000/svg","rect");c.setAttribute("rx","10"),c.setAttribute("width",vo.toString()),c.setAttribute("height",s.height.toString()),c.setAttribute("fill",o.background),c.setAttribute("opacity",".28"),i.appendChild(c);const u=GI({editor:this.editor,shape:t,font:au[t.props.font],bounds:s});return u.setAttribute("fill",o.text),u.setAttribute("stroke","none"),i.appendChild(u),i}}y(bh,"type","note"),y(bh,"props",tD),y(bh,"migrations",nD);function Q1(e,n,t=0){const s=e.textMeasure.measureText(n.props.text,{...jt,fontFamily:To[n.props.font],fontSize:Da[n.props.size],maxWidth:vo-34}).h+17*2;let i=null;if(s>vo?i=s-vo:t&&(i=0),i!==null)return{...n,props:{...n.props,growY:i}}}function OV(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),i=new C(0,0);t<0&&(i.x=-(n.width*s)),r<0&&(i.y=-(n.height*s));const{x:a,y:l}=C.Add(o,i.rot(e.rotation));return{x:a,y:l,props:{scale:s*e.props.scale}}}const RV=new Bv;class Ph extends Tr{constructor(){super(...arguments);y(this,"canEdit",()=>!0);y(this,"isAspectRatioLocked",()=>!0);y(this,"onResize",(t,r)=>{const{initialBounds:o,initialShape:s,scaleX:i,handle:a}=r;if(r.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:t.id,type:t.type,...OV(t,r)};{const l=o.width;let c=l*i;const u=new C(0,0);c=Math.max(1,Math.abs(c)),a==="left"?(u.x=l-c,i<0&&(u.x+=c)):i<0&&(u.x-=c);const{x:d,y:h}=u.rot(t.rotation).add(s);return{id:t.id,type:t.type,x:d,y:h,props:{w:c/s.props.scale,autoSize:!1}}}});y(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}});y(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t,i=t.props.text.trimEnd();i.length===0?this.editor.deleteShapes([t.id]):i!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});y(this,"onBeforeUpdate",(t,r)=>{if(!r.props.autoSize)return;const o=t.props.size!==r.props.size||t.props.align!==r.props.align||t.props.font!==r.props.font||t.props.scale!==1&&r.props.scale===1,s=t.props.text!==r.props.text;if(!o&&!s)return;const i=this.getMinDimensions(t),a=J1(this.editor,r.props),l=i.width*t.props.scale,c=i.height*t.props.scale,u=a.width*r.props.scale,d=a.height*r.props.scale;let h;switch(r.props.align){case"middle":{h=new C((u-l)/2,s?0:(d-c)/2);break}case"end":{h=new C(u-l,s?0:(d-c)/2);break}default:{if(s)break;h=new C(0,(d-c)/2);break}}if(h){h.rot(r.rotation);const{x:p,y:m}=r;return{...r,x:p-h.x,y:m-h.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}});y(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",align:"middle",autoSize:!0,scale:1}}getMinDimensions(t){return RV.get(t.props,r=>J1(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:s}=this.getMinDimensions(t);return new Es({width:o*r,height:s*r,isFilled:!0})}component(t){const{id:r,type:o,props:{text:s,color:i}}=t,a=In({isDarkMode:this.editor.user.getIsDarkMode()}),{width:l,height:c}=this.getMinDimensions(t),{rInput:u,isEmpty:d,isEditing:h,handleFocus:p,handleChange:m,handleKeyDown:f,handleBlur:S,handleInputPointerDown:v,handleDoubleClick:x}=v0(r,o,s);return g.jsx(pi,{id:t.id,children:g.jsxs("div",{className:"tl-text-shape__wrapper tl-text-shadow","data-font":t.props.font,"data-align":t.props.align,"data-hastext":!d,"data-isediting":h,"data-textwrap":!0,style:{fontSize:us[t.props.size],lineHeight:us[t.props.size]*jt.lineHeight+"px",transform:`scale(${t.props.scale})`,transformOrigin:"top left",width:Math.max(1,l),height:Math.max(us[t.props.size]*jt.lineHeight,c),color:a[i].solid},children:[g.jsx("div",{className:"tl-text tl-text-content",dir:"ltr",children:s}),h?g.jsx("textarea",{ref:u,className:"tl-text tl-text-input",name:"text",tabIndex:-1,autoComplete:"false",autoCapitalize:"false",autoCorrect:"false",autoSave:"false",autoFocus:h,placeholder:"",spellCheck:"true",wrap:"off",dir:"ltr",datatype:"wysiwyg",defaultValue:s,onFocus:p,onChange:m,onKeyDown:f,onBlur:S,onTouchEnd:Dt,onContextMenu:Dt,onPointerDown:v,onDoubleClick:x}):null]})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=U();return t.props.autoSize&&o.getEditingShapeId()===t.id?null:g.jsx("rect",{width:O(r.width),height:O(r.height)})}toSvg(t,r){r.addExportDef(Sf(t.props.font));const o=In({isDarkMode:this.editor.user.getIsDarkMode()}),s=this.editor.getShapeGeometry(t).bounds,i=t.props.text,a=s.width/(t.props.scale??1),l=s.height/(t.props.scale??1),c={fontSize:us[t.props.size],fontFamily:au[t.props.font],textAlign:t.props.align,verticalTextAlign:"middle",width:a,height:l,padding:0,lineHeight:jt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap"},u=o[t.props.color].solid,d=document.createElementNS("http://www.w3.org/2000/svg","g"),h=yf(this.editor,this.editor.textMeasure.measureTextSpans(i,c),{...c,stroke:o.background,strokeWidth:2,fill:o.background,padding:0}),p=h.cloneNode(!0);return p.setAttribute("fill",u),p.setAttribute("stroke","none"),d.append(h),d.append(p),d}}y(Ph,"type","text"),y(Ph,"props",rD),y(Ph,"migrations",oD);function J1(e,n){const{font:t,text:r,autoSize:o,size:s,w:i}=n,a=o?16:Math.max(16,i),l=us[s],c=o?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...jt,fontFamily:To[t],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}class Ch extends el{constructor(){super(...arguments);y(this,"canEdit",()=>!0);y(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(t){return g.jsx(jV,{shape:t,videoUtil:this})}indicator(t){return g.jsx("rect",{width:O(t.props.w),height:O(t.props.h)})}toSvg(t){const r=document.createElementNS("http://www.w3.org/2000/svg","g"),o=document.createElementNS("http://www.w3.org/2000/svg","image");return o.setAttributeNS("http://www.w3.org/1999/xlink","href",DV(t.id)),o.setAttribute("width",t.props.w.toString()),o.setAttribute("height",t.props.h.toString()),r.appendChild(o),r}}y(Ch,"type","video"),y(Ch,"props",sD),y(Ch,"migrations",iD);function DV(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 id "+n+" not found")}const jV=je(function(n){const{shape:t,videoUtil:r}=n,o=r.editor.getShapeGeometry(t).bounds.w*r.editor.getZoomLevel()>=110,s=t.props.assetId?r.editor.getAsset(t.props.assetId):null,{time:i,playing:a}=t.props,l=uf(t.id),c=s_(),u=ne.useRef(null),d=ne.useCallback(v=>{const x=v.currentTarget;r.editor.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:x.currentTime}}])},[t.id,r.editor]),h=ne.useCallback(v=>{const x=v.currentTarget;r.editor.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:x.currentTime}}])},[t.id,r.editor]),p=ne.useCallback(v=>{const x=v.currentTarget;l&&r.editor.updateShapes([{type:"video",id:t.id,props:{time:x.currentTime}}])},[l,t.id,r.editor]),[m,f]=ne.useState(!1),S=ne.useCallback(v=>{const x=v.currentTarget;i!==x.currentTime&&(x.currentTime=i),a||x.pause(),f(!0)},[a,i]);return ne.useEffect(()=>{const v=u.current;v&&(m&&!l&&i!==v.currentTime&&(v.currentTime=i),l&&document.activeElement!==v&&v.focus())},[l,m,i]),ne.useEffect(()=>{if(c){const v=u.current;v.pause(),v.currentTime=0}},[u,c]),g.jsxs(g.Fragment,{children:[g.jsx(pi,{id:t.id,children:g.jsx("div",{className:"tl-counter-scaled",children:s!=null&&s.props.src?g.jsx("video",{ref:u,style:l?{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:l&&o,onPlay:d,onPause:h,onTimeUpdate:p,onLoadedData:S,hidden:!m,children:g.jsx("source",{src:s.props.src})}):null})}),"url"in t.props&&t.props.url&&g.jsx(bu,{url:t.props.url,zoomLevel:r.editor.getZoomLevel()})]})}),LV=[Ph,fh,gh,Sh,bh,xh,yh,ph,vh,mh,wh,Ch];function NV(e){return[e.sideEffects.registerAfterChangeHandler("instance",(n,t)=>{n.isFocused!==t.isFocused&&(t.isFocused?(e.getContainer().focus(),e.updateViewportScreenBounds()):(e.complete(),e.getContainer().blur(),e.updateViewportScreenBounds()))}),e.sideEffects.registerAfterChangeHandler("instance_page_state",(n,t)=>{if(n.croppingShapeId!==t.croppingShapeId){const r=e.isInAny("select.crop","select.pointing_crop_handle","select.cropping");!n.croppingShapeId&&t.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):n.croppingShapeId&&!t.croppingShapeId&&r&&e.setCurrentTool("select.idle")}n.editingShapeId!==t.editingShapeId&&(!n.editingShapeId&&t.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):n.editingShapeId&&!t.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))})]}class u_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"scribbleId","id");y(this,"markId","");y(this,"excludedShapeIds",new Set);y(this,"onEnter",t=>{this.markId="erase scribble begin",this.editor.mark(this.markId),this.info=t;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>{if(this.editor.isShapeOrAncestorLocked(s))return!0;if(this.editor.isShapeOfType(s,"group")||this.editor.isShapeOfType(s,"frame")){const i=this.editor.getPointInShapeSpace(s,r);return this.editor.getShapeGeometry(s).bounds.containsPoint(i)}return!1}).map(s=>s.id));const o=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=o.id,this.update()});y(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});y(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});y(this,"onPointerMove",()=>{this.update()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()})}update(){const t=this.editor.getErasingShapeIds(),r=this.editor.getZoomLevel(),o=this.editor.getCurrentPageShapes(),{inputs:{currentPagePoint:s,previousPagePoint:i}}=this.editor,{excludedShapeIds:a}=this;this.pushPointToScribble();const l=new Set(t);for(const c of o){if(this.editor.isShapeOfType(c,"group"))continue;const u=this.editor.getShapeMask(c.id);if(u&&!Rr(s,u))continue;const d=this.editor.getShapeGeometry(c),h=this.editor.getPointInShapeSpace(c,i),p=this.editor.getPointInShapeSpace(c,s);d.hitTestLineSegment(h,p,Or/r)&&l.add(this.editor.getOutermostSelectableShape(c).id)}this.editor.setErasingShapes([...l].filter(c=>!a.has(c)))}complete(){this.editor.deleteShapes(this.editor.getCurrentPageState().erasingShapeIds),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}}y(u_,"id","erasing");var uy;let FV=(uy=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(uy,"id","idle"),uy);var dy;let zV=(dy=class extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{const t=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:o}}=this.editor,s=new Set,i=s.size;for(let a=r.length,l=a-1;l>=0;l--){const c=r[l];if(!(this.editor.isShapeOrAncestorLocked(c)||this.editor.isShapeOfType(c,"group"))&&this.editor.isPointInShape(c,o,{hitInside:!1,margin:Or/t})){const u=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(u,"frame")&&s.size>i)break;s.add(u.id)}}this.editor.setErasingShapes([...s])});y(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("erasing",t)});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(this,"onInterrupt",()=>{this.cancel()})}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")}},y(dy,"id","pointing"),dy);class Eh extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}y(Eh,"id","eraser"),y(Eh,"initial","idle"),y(Eh,"children",()=>[FV,zV,u_]);class d_ extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.update()});y(this,"onPointerMove",()=>{this.update()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()})}update(){const{currentScreenPoint:t,previousScreenPoint:r}=this.editor.inputs,o=C.Sub(t,r);(Math.abs(o.x)>0||Math.abs(o.y)>0)&&this.editor.pan(o)}complete(){this.editor.slideCamera({speed:Math.min(2,this.editor.inputs.pointerVelocity.len()),direction:this.editor.inputs.pointerVelocity,friction:qd}),this.parent.transition("idle")}}y(d_,"id","dragging");var hy;let BV=(hy=class extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});y(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});y(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},y(hy,"id","idle"),hy);var py;let UV=(py=class extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});y(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("dragging",t)});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onInterrupt",()=>{this.complete()})}complete(){this.parent.transition("idle")}},y(py,"id","pointing"),py);class kh extends oe{constructor(){super(...arguments);y(this,"onDoubleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{duration:220,easing:qt.easeOutQuint})}});y(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{duration:320,easing:qt.easeOutQuint})}});y(this,"onQuadrupleClick",t=>{if(t.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:o}}=this.editor;r===1?this.editor.zoomToFit({duration:400,easing:qt.easeOutQuint}):this.editor.resetZoom(o,{duration:320,easing:qt.easeOutQuint})}})}}y(kh,"id","hand"),y(kh,"initial","idle"),y(kh,"children",()=>[BV,UV,d_]);var fy;let HV=(fy=class extends oe{constructor(){super(...arguments);y(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},y(fy,"id","idle"),fy);class h_ extends oe{constructor(){super(...arguments);y(this,"scribbleId","id");y(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()});y(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});y(this,"onPointerMove",()=>{this.pushPointToScribble()});y(this,"onPointerUp",()=>{this.complete()});y(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}y(h_,"id","lasering");class Ih extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}y(Ih,"id","laser"),y(Ih,"initial","idle"),y(Ih,"children",()=>[HV,h_]);class p_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"brush",new re);y(this,"initialSelectedShapeIds",[]);y(this,"excludedShapeIds",new Set);y(this,"initialStartShape",null);y(this,"onEnter",t=>{const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(r){this.parent.transition("scribble_brushing",t);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=t,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.onPointerMove()});y(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});y(this,"onTick",()=>{Yv(this.editor)});y(this,"onPointerMove",()=>{this.hitTestShapes()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",t=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds,{squashing:!0}),this.parent.transition("idle",t)});y(this,"onKeyDown",t=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()});y(this,"onKeyUp",()=>{this.hitTestShapes()});y(this,"onInterrupt",()=>{this.editor.updateInstanceState({brush:null})})}complete(){this.parent.transition("idle")}hitTestShapes(){const t=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapes(),o=this.editor.getCurrentPageId(),{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=this.editor;this.brush.setTo(re.FromPoints([s,i]));const c=new Set(a?this.initialSelectedShapeIds:[]);let u,d,h,p,m,f;const{corners:S}=this.brush,{excludedShapeIds:v}=this;e:for(let x=0,b=r.length;x<b;x++){if(h=r[x],v.has(h.id)||c.has(h.id)||(p=this.editor.getShapePageBounds(h),!p))continue e;if(this.brush.contains(p)){this.handleHit(h,i,o,c,S);continue e}if(l||this.editor.isShapeOfType(h,"frame"))continue e;if(this.brush.collides(p)){const P=this.editor.getShapeGeometry(h);if(m=this.editor.getShapePageTransform(h),!m)continue e;f=m.clone().invert().applyToPoints(S);t:for(let E=0;E<f.length;E++)if(u=f[E],d=f[(E+1)%f.length],P.hitTestLineSegment(u,d,Or/t)){this.handleHit(h,i,o,c,S);break t}}}this.editor.updateInstanceState({brush:{...this.brush.toJson()}}),this.editor.setSelectedShapes(Array.from(c),{squashing:!0})}handleHit(t,r,o,s,i){if(t.parentId===o){s.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),l=this.editor.getShapeMask(a.id);l&&!_6(l,i)&&!Rr(r,l)||s.add(a.id)}}y(p_,"id","brushing");function P0(e){const n=e.getZoomLevel(),{inputs:{currentPagePoint:t}}=e;return e.getShapeAtPoint(t,{hitInside:!1,hitLabels:!1,margin:Or/n,renderingOnly:!0})??e.getSelectedShapeAtPoint(t)}function f_(e,n,t){if(!n)throw Error("Needs to translate a cropped shape!");const{crop:r}=n.props;if(!r)return;const o=e.inputs.shiftKey?Math.abs(t.x)<Math.abs(t.y)?"x":"y":null;o==="x"?t.x=0:o==="y"&&(t.y=0),t.rot(-n.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*n.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*n.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=Zt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-t.x/s)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-t.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:n.id,type:n.type,props:{crop:c}}}var gy;let VV=(gy=class extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0});const t=this.editor.getOnlySelectedShape();this.editor.on("change-history",this.cleanupCroppingState),t&&(this.editor.mark("crop"),this.editor.setCroppingShape(t.id))});y(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.off("change-history",this.cleanupCroppingState)});y(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});y(this,"onPointerDown",t=>{var r;if(!this.editor.getIsMenuOpen()){if(t.ctrlKey){this.cancel(),this.editor.root.handleEvent(t);return}switch(t.target){case"canvas":{const o=P0(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...t,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(t);break}case"shape":{if(t.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",t);return}else(r=this.editor.getShapeUtil(t.shape))!=null&&r.canCrop(t.shape)?(this.editor.setCroppingShape(t.shape.id),this.editor.setSelectedShapes([t.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",t)):(this.cancel(),this.editor.root.handleEvent(t));break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...t,onInteractionEnd:"select.crop"});break}case"top":case"right":case"bottom":case"left":{this.editor.setCurrentTool("select.pointing_crop_handle",{...t,onInteractionEnd:"select.crop"});break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.pointing_crop_handle",{...t,onInteractionEnd:"select.crop"});break}default:this.cancel()}break}}}});y(this,"onDoubleClick",t=>{var i;if(this.editor.inputs.shiftKey||t.phase!=="up")return;const r=this.editor.getCroppingShapeId();if(!r)return;const o=this.editor.getShape(r);if(!o)return;const s=this.editor.getShapeUtil(o);s&&t.target==="selection"&&((i=s.onDoubleClickEdge)==null||i.call(s,o))});y(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});y(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});y(this,"onKeyUp",t=>{switch(t.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}});y(this,"cleanupCroppingState",()=>{this.editor.getCroppingShapeId()||this.editor.setCurrentTool("select.idle",{})})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new C(0,0);if(r.has("ArrowLeft")&&(s.x+=1),r.has("ArrowRight")&&(s.x-=1),r.has("ArrowUp")&&(s.y+=1),r.has("ArrowDown")&&(s.y-=1),s.equals(new C(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=f_(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},y(gy,"id","idle"),gy);class g_ extends oe{constructor(){super(...arguments);y(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});y(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",t)});y(this,"onPointerUp",t=>{this.editor.setCurrentTool("select.crop.idle",t)})}}y(g_,"id","pointing_crop");class m_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"markId","translating crop");y(this,"snapshot",{});y(this,"onEnter",t=>{this.info=t,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});y(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});y(this,"onPointerMove",()=>{this.updateShapes()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onKeyDown",t=>{switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}});y(this,"onKeyUp",t=>{switch(t.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}})}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const t=this.snapshot.shape;if(!t)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=f_(this.editor,t,s);i&&this.editor.updateShapes([i],{squashing:!0})}}y(m_,"id","translating_crop");class _h extends oe{}y(_h,"id","crop"),y(_h,"initial","idle"),y(_h,"children",()=>[VV,m_,g_]);const rr=8,ja={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 y_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t,this.updateCursor()});y(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("resizing",this.info)});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const t=this.editor.getSelectedShapes(),r=ja[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:t.length===1?t[0].rotation:0}})}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")}}y(y_,"id","pointing_resize_handle");class S_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"markId","");y(this,"snapshot",{});y(this,"onEnter",t=>{this.info=t,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});y(this,"onPointerMove",()=>{this.updateShapes()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){const t=this.editor.getSelectedShapes()[0];if(!t)return;const r=ja[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:t.rotation}})}updateShapes(){const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t||!this.editor.getShapeUtil("image"))return;const s=t.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),l=i.clone().sub(a).rot(-t.rotation),c=s.crop??this.getDefaultCrop(),u=Zt(c),d=new C(t.x,t.y),h=new C(0,0),p=1/(c.bottomRight.x-c.topLeft.x)*s.w,m=1/(c.bottomRight.y-c.topLeft.y)*s.h;let f=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(m<rr)break;f=!0,u.topLeft.y=u.topLeft.y+l.y/m,m*(u.bottomRight.y-u.topLeft.y)<rr?(u.topLeft.y=u.bottomRight.y-rr/m,h.y=(u.topLeft.y-c.topLeft.y)*m):u.topLeft.y<=0?(u.topLeft.y=0,h.y=(u.topLeft.y-c.topLeft.y)*m):h.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(m<rr)break;f=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/m),m*(u.bottomRight.y-u.topLeft.y)<rr&&(u.bottomRight.y=u.topLeft.y+rr/m);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<rr)break;f=!0,u.topLeft.x=u.topLeft.x+l.x/p,p*(u.bottomRight.x-u.topLeft.x)<rr?(u.topLeft.x=u.bottomRight.x-rr/p,h.x=(u.topLeft.x-c.topLeft.x)*p):u.topLeft.x<=0?(u.topLeft.x=0,h.x=(u.topLeft.x-c.topLeft.x)*p):h.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(p<rr)break;f=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/p),p*(u.bottomRight.x-u.topLeft.x)<rr&&(u.bottomRight.x=u.topLeft.x+rr/p);break}}if(!f)return;d.add(h.rot(t.rotation));const S={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)*m}};this.editor.updateShapes([S],{squashing:!0}),this.updateCursor()}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}createSnapshot(){const t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=C.RotWith(s.getHandlePoint(this.info.handle),s.point,t),a=C.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}y(S_,"id","cropping");class v_ extends oe{constructor(){super(...arguments);y(this,"shapeId","");y(this,"initialHandle",{});y(this,"initialAdjacentHandle",null);y(this,"initialPagePoint",{});y(this,"markId","");y(this,"initialPageTransform");y(this,"initialPageRotation");y(this,"info",{});y(this,"isPrecise",!1);y(this,"isPreciseId",null);y(this,"pointingId",null);y(this,"onEnter",t=>{const{shape:r,isCreating:o,handle:s}=t;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=Zt(s),this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.updateInstanceState({cursor:{type:o?"cross":"grabbing",rotation:0}},{ephemeral:!0});const i=this.editor.getShapeHandles(r).sort(Wt),a=i.findIndex(c=>c.id===t.handle.id);this.initialAdjacentHandle=null;for(let c=a+1;c<i.length;c++){const u=i[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==t.handle.id){this.initialAdjacentHandle=u;break}}if(!this.initialAdjacentHandle)for(let c=i.length-1;c>=0;c--){const u=i[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==t.handle.id){this.initialAdjacentHandle=u;break}}const l=r.props[t.handle.id];this.isPrecise=!1,(l==null?void 0:l.type)==="binding"?(this.editor.setHintingShapes([l.boundShapeId]),this.isPrecise=l.isPrecise,this.isPrecise?this.isPreciseId=l.boundShapeId:this.resetExactTimeout()):this.editor.setHintingShapes([]),this.update(),this.editor.select(this.shapeId)});y(this,"exactTimeout",-1);y(this,"onPointerMove",()=>{this.update()});y(this,"onKeyDown",()=>{this.update()});y(this,"onKeyUp",()=>{this.update()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clear(),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clear();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.clear();const{onInteractionEnd:t}=this.info;if(t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var k;const{editor:t,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:d,shiftKey:h,ctrlKey:p,altKey:m,pointerVelocity:f}}=t,S=this.info.shape,v=t.getShape(r);if(!v)return;const x=t.getShapeUtil(v);let b=d.clone().sub(o).rot(-i).add(s);if(h&&a&&s.id!=="middle"){const I=C.Angle(a,b),A=ip(I,24)-I;b=C.RotWith(b,a,A)}if(t.snaps.clear(),s.canSnap&&(c?!p:p)){const I=t.getShapePageTransform(v.id);if(!I)throw Error("Expected a page transform");const _=t.getShapeHandles(v).filter(({type:D})=>D==="vertex").sort(Wt).findIndex(({index:D})=>s.index===D),A=x.getOutlineSegments(v).map(D=>te.applyToPoints(I,D)).filter((D,L)=>L!==_-1&&L!==_),T=u.getSnappingHandleDelta({additionalSegments:A,handlePoint:te.applyToPoint(I,b)});T&&(T.rot(-t.getShapeParentTransform(v).rotation()),b.add(T))}const P=(k=x.onHandleDrag)==null?void 0:k.call(x,v,{handle:{...s,x:b.x,y:b.y},isPrecise:this.isPrecise||m,initial:S}),E={...v,...P};if(s.canBind){const I=E.props[s.id];(I==null?void 0:I.type)==="binding"?l[0]!==I.boundShapeId&&(t.setHintingShapes([I.boundShapeId]),this.pointingId=I.boundShapeId,this.isPrecise=f.len()<.5||m,this.isPreciseId=this.isPrecise?I.boundShapeId:null,this.resetExactTimeout()):l.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}P&&t.updateShapes([E],{squashing:!0})}}y(v_,"id","dragging_handle");class w_ extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{const t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");_c(this.editor),this.editor.select(t)});y(this,"onExit",()=>{var s;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null);const r=this.editor.getShape(t),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r),setTimeout(()=>{this.editor.updateViewportScreenBounds()},500)});y(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":{_c(this.editor);return}}});y(this,"onPointerDown",t=>{switch(t.target){case"canvas":{const r=P0(this.editor);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!");if(r.type===o.type)if(this.editor.isShapeOfType(r,"geo")||this.editor.isShapeOfType(r,"arrow")){const i=this.editor.getShapeUtil(r).getGeometry(r).children[1];if(i){const a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(i.bounds.containsPoint(a)){if(r.id===o.id)return;this.parent.transition("pointing_shape",t);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)});y(this,"onComplete",t=>{this.parent.transition("idle",t)});y(this,"onCancel",t=>{this.parent.transition("idle",t)})}}y(w_,"id","editing_shape");function eP(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function wp(e){const n=e.getSelectedShapeIds(),{shiftKey:t,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin:Or/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(s){const i=e.getOutermostSelectableShape(s);if(t&&!r)e.cancelDoubleClick(),n.includes(i.id)?(e.mark("deselecting shape"),e.deselect(i)):(e.mark("shift selecting shape"),e.setSelectedShapes([...n,i.id]));else{let a;i===s||i.id===e.getFocusedGroupId()||n.includes(i.id)?a=s:a=i,a&&!n.includes(a.id)&&(e.mark("selecting shape"),e.select(a.id))}}else{if(t)return;{n.length>0&&(e.mark("selecting none"),e.selectNone());const i=e.getFocusedGroupId();if(Rn(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}var my;let KV=(my=class extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),_c(this.editor),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});y(this,"onPointerMove",()=>{_c(this.editor)});y(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&eP(this.editor);if(t.ctrlKey&&!r){if(t.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(t.shape)){this.parent.transition("pointing_shape",t);return}this.parent.transition("brushing",t);return}switch(t.target){case"canvas":{const o=P0(this.editor);if(o&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&tP(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{const{shape:o}=t,s=this.editor.getPointInShapeSpace(o,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(o,"arrow")){const i=this.editor.getShapeGeometry(o).children[1];if(i&&Rr(s,i.vertices)){this.parent.transition("pointing_arrow_label",t);break}}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",t);break}this.parent.transition("pointing_shape",t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",t):this.parent.transition("pointing_handle",t);break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",t);break}case"top":case"right":case"bottom":case"left":{r?this.parent.transition("pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",t)}}break}}});y(this,"onDoubleClick",t=>{var r,o,s,i;if(!(this.editor.inputs.shiftKey||t.phase!=="up"))switch(t.target){case"canvas":{const a=this.editor.getHoveredShape(),l=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:Or/this.editor.getZoomLevel(),hitInside:!1}),c=this.editor.getFocusedGroupId();if(l){if(this.editor.isShapeOfType(l,"group")){wp(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){wp(this.editor);return}}this.onDoubleClick({...t,shape:l,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(t);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const l=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(t.handle==="right"||t.handle==="left"||t.handle==="top"||t.handle==="bottom"){const c=(r=l.onDoubleClickEdge)==null?void 0:r.call(l,a);if(c){this.editor.mark("double click edge"),this.editor.updateShapes([c]);return}}if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",t);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,t)}break}case"shape":{const{shape:a}=t,l=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(l.onDoubleClick){const c=(o=l.onDoubleClick)==null?void 0:o.call(l,a);if(c){this.editor.updateShapes([c]);return}else if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((s=t.shape)==null?void 0:s.id),this.parent.transition("crop",t);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,t):this.handleDoubleClickOnCanvas(t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:l}=t,c=this.editor.getShapeUtil(a),u=(i=c.onDoubleClickHandle)==null?void 0:i.call(c,a,l);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,t)}}});y(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:Or/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...t,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&tP(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=t,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));r.includes(s.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});y(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});y(this,"onKeyDown",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);break}}});y(this,"onKeyRepeat",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});y(this,"onKeyUp",t=>{switch(t.code){case"Enter":{const r=this.editor.getSelectedShapes();if(r.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(r.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const o=this.editor.getOnlySelectedShape();if(o&&this.shouldStartEditingShape(o)){this.startEditingShape(o,{...t,target:"shape",shape:o});return}eP(this.editor)&&this.parent.transition("crop",t);break}}});y(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){this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||(this.editor.mark("editing shape"),this.editor.setEditingShape(t.id),this.parent.transition("editing_shape",r))}handleDoubleClickOnCanvas(t){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=We(),{x:o,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:o,y:s,props:{text:"",autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",t))}nudgeSelectedShapes(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new C(0,0);if(r.has("ArrowLeft")&&(s.x-=1),r.has("ArrowRight")&&(s.x+=1),r.has("ArrowUp")&&(s.y-=1),r.has("ArrowDown")&&(s.y+=1),s.equals(new C(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*YV:i:o?WV:GV;this.editor.nudgeShapes(this.editor.getSelectedShapeIds(),s.mul(a))}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},y(my,"id","idle"),my);const WV=10,GV=1,YV=5;function tP(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?Rr(n,t.corners.map(o=>C.RotWith(o,t.point,r))):t.containsPoint(n)}class x_ extends oe{constructor(){super(...arguments);y(this,"shapeId","");y(this,"markId","");y(this,"info",{});y(this,"onEnter",t=>{const{shape:r}=t;this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.shapeId=r.id,this.updateCursor();const s=this.editor.getShapeGeometry(r).children[1];if(!s)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=C.Sub(s.center,a),this.markId="label-drag start",this.editor.mark(this.markId),this.editor.setSelectedShapes([this.shapeId])});y(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});y(this,"_labelDragOffset",new C(0,0));y(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;if(!t)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=this.editor.getArrowInfo(r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(C.Add(a,this._labelDragOffset));let c;if(o.isStraight){const u=C.Dist(o.start.point,o.end.point);c=1-C.Dist(o.end.point,l)/u}else{const{_center:u,measure:d,angleEnd:h,angleStart:p}=s.children[0];c=_y(d,p,h,u.angle(l))}this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}},{squashing:!0})});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.updateInstanceState({cursor:{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")}}y(x_,"id","pointing_arrow_label");class b_ extends oe{constructor(){super(...arguments);y(this,"onEnter",()=>{const{inputs:t}=this.editor;t.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});y(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",t)});y(this,"onPointerUp",()=>{wp(this.editor),this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}y(b_,"id","pointing_canvas");class P_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];r&&(this.updateCursor(r),this.editor.setCroppingShape(r.id))});y(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});y(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})});y(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}updateCursor(t){const r=ja[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:t.rotation}})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}}y(P_,"id","pointing_crop_handle");class C_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t;const r=t.shape.props[t.handle.id];(r==null?void 0:r.type)==="binding"&&this.editor.setHintingShapes([r.boundShapeId]),this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});y(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});y(this,"onPointerUp",()=>{this.parent.transition("idle",this.info)});y(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("dragging_handle",this.info)});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}cancel(){this.parent.transition("idle")}}y(C_,"id","pointing_handle");class E_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.updateCursor()});y(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});y(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;t&&this.parent.transition("rotating",this.info)});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const t=this.editor.getSelectionRotation();this.editor.updateInstanceState({cursor:{type:ja[this.info.handle],rotation:t}})}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")}}y(E_,"id","pointing_rotate_handle");class k_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t});y(this,"onPointerUp",t=>{wp(this.editor),this.parent.transition("idle",t)});y(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.parent.transition("translating",t)}});y(this,"onDoubleClick",t=>{var s,i;const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(o){this.parent.transition("idle"),(i=(s=this.parent).onDoubleClick)==null||i.call(s,{...t,target:"shape",shape:this.editor.getShape(o)});return}});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}cancel(){this.parent.transition("idle")}}y(k_,"id","pointing_selection");class I_ extends oe{constructor(){super(...arguments);y(this,"hitShape",{});y(this,"hitShapeForPointerUp",{});y(this,"didSelectOnEnter",!1);y(this,"onEnter",t=>{const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:l}}=this.editor;this.hitShape=t.shape;const c=this.editor.getOutermostSelectableShape(t.shape);if(this.editor.getShapeUtil(t.shape).onClick||c.id===s||r.includes(c.id)||this.editor.isAncestorSelected(c.id)||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=c;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(c.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,c.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([c.id]))});y(this,"onPointerUp",t=>{var u;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,l=this.editor.getShapeAtPoint(i,{margin:Or/s,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const d=this.editor.getShapeUtil(c);if(d.onClick){const h=(u=d.onClick)==null?void 0:u.call(d,c);if(h){this.editor.mark("shape on click"),this.editor.updateShapes([h]),this.parent.transition("idle",t);return}}if(c.id===o){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",t);return}}if(!this.didSelectOnEnter){const d=this.editor.getOutermostSelectableShape(l,h=>!r.includes(h.id));if(r.includes(d.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1&&(this.editor.isShapeOfType(c,"geo")||this.editor.isShapeOfType(c,"arrow"))){const p=this.editor.getShapeGeometry(c).children[1];if(p){const m=this.editor.getPointInShapeSpace(c,i);if(p.bounds.containsPoint(m,0)&&p.hitTestPoint(m)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(c.id);const f=this.editor.getShapeUtil(c);this.editor.getInstanceState().isReadonly&&!f.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(c.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(c);else if(a){const h=this.editor.getShapeAncestors(d);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(p=>!h.find(m=>m.id===p)),d.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([d.id])}this.parent.transition("idle",t)});y(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.parent.transition("translating",t)}});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.cancel()});y(this,"onInterrupt",()=>{this.cancel()})}cancel(){this.parent.transition("idle")}}y(I_,"id","pointing_shape");class __ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"markId","");y(this,"didHoldCommand",!1);y(this,"creationCursorOffset",{x:0,y:0});y(this,"snapshot",{});y(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.updateInstanceState({cursor:{type:"cross",rotation:0}},{ephemeral:!0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});y(this,"onTick",()=>{Yv(this.editor)});y(this,"onPointerMove",()=>{this.updateShapes()});y(this,"onKeyDown",()=>{this.updateShapes()});y(this,"onKeyUp",()=>{this.updateShapes()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.snaps.clear()});y(this,"_createSnapshot",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=C.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=C.Sub(o,i),l=new Map,c=[];t.forEach(d=>{const h=this.editor.getShape(d);if(h){if(h.type==="frame"&&c.push({id:d,children:pe(this.editor.getSortedChildIdsForParent(h).map(p=>this.editor.getShape(p)))}),l.set(h.id,this._createShapeSnapshot(h)),this.editor.isShapeOfType(h,"frame")&&t.length===1)return;this.editor.visitDescendants(h.id,p=>{const m=this.editor.getShape(p);if(m&&(l.set(m.id,this._createShapeSnapshot(m)),this.editor.isShapeOfType(m,"frame")))return!1})}});const u=![...l.values()].some(d=>!zE(d.pageRotation,r)||d.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});y(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:te.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(this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(t=this.info).onCreate)==null||r.call(t,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:o})=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onResizeStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:o})=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onResizeEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot,d=r||!u,{ctrlKey:h}=this.editor.inputs,p=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),m=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!h){const{gridSize:_}=this.editor.getDocumentSettings();p.snapToGrid(_)}const f=this.info.handle,S=nP(f,Math.PI);if(this.editor.snaps.clear(),(this.editor.user.getIsSnapMode()?!h:h)&&c%Ve===0){const{nudge:_}=this.editor.snaps.snapResize({dragDelta:C.Sub(p,m),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:nP(f,c),isAspectRatioLocked:d,isResizingFromCenter:t});p.add(_)}const x=C.RotWith(t?i.center:i.getHandlePoint(S),i.point,c),b=C.Sub(p,x).rot(-c),P=C.Sub(m,x).rot(-c),E=C.DivV(b,P);Number.isFinite(E.x)||(E.x=1),Number.isFinite(E.y)||(E.y=1);const k=f==="top"||f==="bottom",I=f==="left"||f==="right";d?I?E.y=Math.abs(E.x):k?E.x=Math.abs(E.y):Math.abs(E.x)>Math.abs(E.y)?E.y=Math.abs(E.x)*(E.y<0?-1:1):E.x=Math.abs(E.y)*(E.x<0?-1:1):(k&&(E.x=1),I&&(E.y=1)),this.info.isCreating||this.updateCursor({dragHandle:f,isFlippedX:E.x<0,isFlippedY:E.y<0,rotation:c});for(const _ of s.keys()){const A=s.get(_);this.editor.resizeShape(_,E,{initialShape:A.shape,initialBounds:A.bounds,initialPageTransform:A.pageTransform,dragHandle:f,mode:l.length===1&&_===l[0]?"resize_bounds":"scale_shape",scaleOrigin:x,scaleAxisRotation:c})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:_,children:A}of o){if(!A.length)continue;const T=s.get(_).shape,D=this.editor.getShape(_);if(!(T&&D))continue;const L=D.x-T.x,z=D.y-T.y,j=new C(L,z).rot(-T.rotation);if(j.x!==0||j.y!==0)for(const F of A)this.editor.updateShape({id:F.id,type:F.type,x:F.x-j.x,y:F.y-j.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:_}of o)if(_.length)for(const A of _)this.editor.updateShape({id:A.id,type:A.type,x:A.x,y:A.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(t){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}}y(__,"id","resizing");const lm=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function nP(e,n){n=n%Re;const t=Math.round(n/(Te/4)),r=lm.indexOf(e);return lm[(r+t)%lm.length]}const rP=Math.PI/180;class T_ extends oe{constructor(){super(...arguments);y(this,"snapshot",{});y(this,"info",{});y(this,"markId","");y(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=kk({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r,this.handleStart()});y(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});y(this,"onPointerMove",()=>{this.update()});y(this,"onKeyDown",()=>{this.update()});y(this,"onKeyUp",()=>{this.update()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"update",()=>{const t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Jd({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.updateInstanceState({cursor:{type:ja[this.info.handle],rotation:t+this.snapshot.initialSelectionRotation}})});y(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});y(this,"complete",()=>{Jd({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)})}handleStart(){const t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Jd({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.updateInstanceState({cursor:{type:ja[this.info.handle],rotation:t+this.snapshot.initialSelectionRotation}})}_getRotationFromPointerPosition({snapToNearestDegree:t}){const r=this.editor.getSelectionRotation(),o=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:s,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:l}=this.snapshot;if(!o)return l;const u=o.center.clone().rotWith(o.point,r).angle(i)-a;let d=l+u;if(s)d=ip(d,24);else if(t&&(d=Math.round(d/rP)*rP,this.editor.getInstanceState().isCoarsePointer)){const h=ip(d,4),p=tc(d,h);Math.abs(p)<VD(5)&&(d=h)}return d-l}}y(T_,"id","rotating");class $_ extends oe{constructor(){super(...arguments);y(this,"hits",new Set);y(this,"size",0);y(this,"scribbleId","id");y(this,"initialSelectedShapeIds",new Set);y(this,"newlySelectedShapeIds",new Set);y(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),requestAnimationFrame(()=>{this.editor.updateInstanceState({brush:null})})});y(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});y(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});y(this,"onPointerUp",()=>{this.complete()});y(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});y(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});y(this,"onCancel",()=>{this.cancel()});y(this,"onComplete",()=>{this.complete()});y(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)})}updateScribbleSelection(t){const r=this.editor.getZoomLevel(),o=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;t&&this.pushPointToScribble();const d=o;let h,p,m,f;for(let S=0,v=d.length;S<v;S++)if(h=d[S],p=this.editor.getShapeGeometry(h),!(this.editor.isShapeOfType(h,"group")||c.has(h.id)||this.editor.isShapeOrAncestorLocked(h))){if(this.editor.isShapeOfType(h,"frame")){const x=this.editor.getPointInShapeSpace(h,i);if(p.bounds.containsPoint(x))continue}if(m=this.editor.getPointInShapeSpace(h,a),f=this.editor.getPointInShapeSpace(h,l),p.hitTestLineSegment(m,f,Or/r)){const x=this.editor.getOutermostSelectableShape(h),b=this.editor.getShapeMask(x.id);if(b&&yk(a,l,b)!==null&&!Rr(l,b))continue;c.add(x.id)}}this.editor.setSelectedShapes([...new Set(s?[...c,...u]:[...c])],{squashing:!0})}complete(){this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds],{squashing:!0}),this.parent.transition("idle")}}y($_,"id","scribble_brushing");const oP=100;class XV{constructor(n){y(this,"prevDroppingShapeId",null);y(this,"droppingNodeTimer",null);y(this,"first",!0);y(this,"dispose",()=>{this.clear()});this.editor=n,n.disposables.add(this.dispose)}updateDroppingNode(n,t){var r;this.first&&(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,oP*10,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearInterval(this.droppingNodeTimer),this.setDragTimer(n,oP,t))}setDragTimer(n,t,r){this.droppingNodeTimer=setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,n,r)}),this.droppingNodeTimer=null},t)}handleDrag(n,t,r){var l,c,u,d,h;t=pe(t.map(p=>this.editor.getShape(p.id)));const o=((l=this.editor.getDroppingOverShape(n,t))==null?void 0:l.id)??null;if(o===this.prevDroppingShapeId)return;const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);if(i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,t)),a){const p=(h=(d=this.editor.getShapeUtil(a)).onDragShapesOver)==null?void 0:h.call(d,a,t);p&&p.shouldHint&&this.editor.setHintingShapes([a.id])}else this.editor.setHintingShapes([]);r==null||r(),this.prevDroppingShapeId=o}dropShapes(n){var r,o;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,n),t){const s=this.editor.getShape(t);if(!s)return;(o=(r=this.editor.getShapeUtil(s)).onDropShapesOver)==null||o.call(r,s,n)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearInterval(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class A_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"selectionSnapshot",{});y(this,"snapshot",{});y(this,"markId","");y(this,"isCloning",!1);y(this,"isCreating",!1);y(this,"onCreate",()=>{});y(this,"dragAndDropManager",new XV(this.editor));y(this,"onEnter",t=>{const{isCreating:r=!1,onCreate:o=()=>{}}=t;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=sP(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});y(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clear(),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.dragAndDropManager.clear()});y(this,"onTick",()=>{this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),Yv(this.editor)});y(this,"onPointerMove",()=>{this.updateShapes()});y(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});y(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onComplete",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()});y(this,"updateParentTransforms",()=>{const{editor:t,snapshot:{shapeSnapshots:r}}=this;r.forEach(o=>{const s=t.getShape(o.shape.id);if(!s)return null;const i=gn(s.parentId)?null:te.Inverse(t.getShapePageTransform(s.parentId));o.parentTransform=i})})}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=sP(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),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(t=this.onCreate)==null||t.call(this,this.editor.getOnlySelectedShape()):this.parent.transition("idle")}cancel(){this.reset(),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.parent.transition("idle",this.info)}handleStart(){const{movingShapes:t}=this.snapshot,r=[];t.forEach(o=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onTranslateStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:t}=this.snapshot;if(this.isCloning){const o=C.Average(t.map(i=>this.editor.getShapePageTransform(i.id).point())),s=C.Sub(o,this.selectionSnapshot.averagePagePoint);this.editor.updateInstanceState({duplicateProps:{shapeIds:t.map(i=>i.id),offset:{x:s.x,y:s.y}}})}const r=[];t.forEach(o=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslateEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}handleChange(){const{movingShapes:t}=this.snapshot,r=[];t.forEach(o=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslate)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:t}=this;this.dragAndDropManager.updateDroppingNode(t.movingShapes,this.updateParentTransforms),qV({editor:this.editor,shapeSnapshots:t.shapeSnapshots,averagePagePoint:t.averagePagePoint,initialSelectionPageBounds:t.initialPageBounds,initialSelectionSnapPoints:t.initialSnapPoints}),this.handleChange()}}y(A_,"id","translating");function sP(e){const n=[],t=[],r=pe(e.getSelectedShapeIds().map(s=>{const i=e.getShape(s);if(!i)return null;n.push(i);const a=e.getShapePageTransform(s).point();if(!a)return null;t.push(a);const l=Oo.isId(i.parentId)?null:te.Inverse(e.getShapePageTransform(i.parentId));return{shape:i,pagePoint:a,parentTransform:l}}));let o=[];if(e.getSelectedShapeIds().length===1)o=e.snaps.getSnapPointsCache().get(e.getSelectedShapeIds()[0]);else{const s=e.getSelectionPageBounds();s&&(o=s.snapPoints.map((i,a)=>({id:"selection:"+a,x:i.x,y:i.y})))}return{averagePagePoint:C.Average(t),movingShapes:n,shapeSnapshots:r,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:o}}function qV({editor:e,shapeSnapshots:n,averagePagePoint:t,initialSelectionPageBounds:r,initialSelectionSnapPoints:o}){const{inputs:s}=e,i=e.getInstanceState().isGridMode,a=e.getDocumentSettings().gridSize,l=C.Sub(s.currentPagePoint,s.originPagePoint),c=e.inputs.shiftKey?Math.abs(l.x)<Math.abs(l.y)?"x":"y":null;if(c==="x"?l.x=0:c==="y"&&(l.y=0),e.snaps.clear(),(e.user.getIsSnapMode()?!s.ctrlKey:s.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:p}=e.snaps.snapTranslate({dragDelta:l,initialSelectionPageBounds:r,lockedAxis:c,initialSelectionSnapPoints:o});l.add(p)}const d=C.Add(t,l);i&&!s.ctrlKey&&d.snapToGrid(a);const h=C.Sub(d,t);e.updateShapes(pe(n.map(({shape:p,pagePoint:m,parentTransform:f})=>{const S=C.Add(m,h),v=f?te.applyToPoint(f,S):S;return{id:p.id,type:p.type,x:v.x,y:v.y}})),{squashing:!0})}class Th extends oe{constructor(){super(...arguments);y(this,"reactor");y(this,"cleanUpDuplicateProps",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);t.length===o.size&&t.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})});y(this,"onEnter",()=>{this.reactor=su("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(t){typeof process<"u",console.error(t)}})});y(this,"onExit",()=>{var t;(t=this.reactor)==null||t.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}y(Th,"id","select"),y(Th,"initial","idle"),y(Th,"children",()=>[_h,S_,KV,b_,I_,A_,p_,$_,P_,k_,y_,w_,__,T_,E_,x_,C_,v_]);class M_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t});y(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}y(M_,"id","idle");class O_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t});y(this,"onPointerUp",()=>{this.complete()});y(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});y(this,"onCancel",()=>{this.cancel()})}complete(){const{currentScreenPoint:t}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(t,{duration:220}):this.editor.zoomIn(t,{duration:220}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}y(O_,"id","pointing");class R_ extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"zoomBrush",new re);y(this,"onEnter",t=>{this.info=t,this.update()});y(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});y(this,"onPointerMove",()=>{this.update()});y(this,"onPointerUp",()=>{this.complete()});y(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:t,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(re.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,{duration:220}):this.editor.zoomIn(o,{duration:220})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(t,o,{duration:220})}this.parent.transition("idle",this.info)}}y(R_,"id","zoom_brushing");class $h extends oe{constructor(){super(...arguments);y(this,"info",{});y(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.updateCursor()});y(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});y(this,"onKeyDown",()=>{this.updateCursor()});y(this,"onKeyUp",t=>{this.updateCursor(),t.code==="KeyZ"&&this.complete()});y(this,"onInterrupt",()=>{this.complete()})}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.updateInstanceState({cursor:{type:"zoom-out",rotation:0}},{ephemeral:!0}):this.editor.updateInstanceState({cursor:{type:"zoom-in",rotation:0}},{ephemeral:!0})}}y($h,"id","zoom"),y($h,"initial","idle"),y($h,"children",()=>[M_,R_,O_]);const ZV=[Eh,kh,Ih,$h,Th];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)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},Q.apply(this,arguments)}var D_={exports:{}},qn={},j_={exports:{}},L_={};/**
163
+ * @license React
164
+ * scheduler.production.min.js
165
+ *
166
+ * Copyright (c) Facebook, Inc. and its affiliates.
167
+ *
168
+ * This source code is licensed under the MIT license found in the
169
+ * LICENSE file in the root directory of this source tree.
170
+ */(function(e){function n(H,B){var V=H.length;H.push(B);e:for(;0<V;){var X=V-1>>>1,ae=H[X];if(0<o(ae,B))H[X]=B,H[V]=ae,V=X;else break e}}function t(H){return H.length===0?null:H[0]}function r(H){if(H.length===0)return null;var B=H[0],V=H.pop();if(V!==B){H[0]=V;e:for(var X=0,ae=H.length,ye=ae>>>1;X<ye;){var Ie=2*(X+1)-1,le=H[Ie],ke=Ie+1,Ae=H[ke];if(0>o(le,V))ke<ae&&0>o(Ae,le)?(H[X]=Ae,H[ke]=V,X=ke):(H[X]=le,H[Ie]=V,X=Ie);else if(ke<ae&&0>o(Ae,V))H[X]=Ae,H[ke]=V,X=ke;else break e}}return B}function o(H,B){var V=H.sortIndex-B.sortIndex;return V!==0?V:H.id-B.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,d=null,h=3,p=!1,m=!1,f=!1,S=typeof setTimeout=="function"?setTimeout:null,v=typeof clearTimeout=="function"?clearTimeout:null,x=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function b(H){for(var B=t(c);B!==null;){if(B.callback===null)r(c);else if(B.startTime<=H)r(c),B.sortIndex=B.expirationTime,n(l,B);else break;B=t(c)}}function P(H){if(f=!1,b(H),!m)if(t(l)!==null)m=!0,Y(E);else{var B=t(c);B!==null&&K(P,B.startTime-H)}}function E(H,B){m=!1,f&&(f=!1,v(_),_=-1),p=!0;var V=h;try{for(b(B),d=t(l);d!==null&&(!(d.expirationTime>B)||H&&!D());){var X=d.callback;if(typeof X=="function"){d.callback=null,h=d.priorityLevel;var ae=X(d.expirationTime<=B);B=e.unstable_now(),typeof ae=="function"?d.callback=ae:d===t(l)&&r(l),b(B)}else r(l);d=t(l)}if(d!==null)var ye=!0;else{var Ie=t(c);Ie!==null&&K(P,Ie.startTime-B),ye=!1}return ye}finally{d=null,h=V,p=!1}}var k=!1,I=null,_=-1,A=5,T=-1;function D(){return!(e.unstable_now()-T<A)}function L(){if(I!==null){var H=e.unstable_now();T=H;var B=!0;try{B=I(!0,H)}finally{B?z():(k=!1,I=null)}}else k=!1}var z;if(typeof x=="function")z=function(){x(L)};else if(typeof MessageChannel<"u"){var j=new MessageChannel,F=j.port2;j.port1.onmessage=L,z=function(){F.postMessage(null)}}else z=function(){S(L,0)};function Y(H){I=H,k||(k=!0,z())}function K(H,B){_=S(function(){H(e.unstable_now())},B)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(H){H.callback=null},e.unstable_continueExecution=function(){m||p||(m=!0,Y(E))},e.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):A=0<H?Math.floor(1e3/H):5},e.unstable_getCurrentPriorityLevel=function(){return h},e.unstable_getFirstCallbackNode=function(){return t(l)},e.unstable_next=function(H){switch(h){case 1:case 2:case 3:var B=3;break;default:B=h}var V=h;h=B;try{return H()}finally{h=V}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(H,B){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var V=h;h=H;try{return B()}finally{h=V}},e.unstable_scheduleCallback=function(H,B,V){var X=e.unstable_now();switch(typeof V=="object"&&V!==null?(V=V.delay,V=typeof V=="number"&&0<V?X+V:X):V=X,H){case 1:var ae=-1;break;case 2:ae=250;break;case 5:ae=1073741823;break;case 4:ae=1e4;break;default:ae=5e3}return ae=V+ae,H={id:u++,callback:B,priorityLevel:H,startTime:V,expirationTime:ae,sortIndex:-1},V>X?(H.sortIndex=V,n(c,H),t(l)===null&&H===t(c)&&(f?(v(_),_=-1):f=!0,K(P,V-X))):(H.sortIndex=ae,n(l,H),m||p||(m=!0,Y(E))),H},e.unstable_shouldYield=D,e.unstable_wrapCallback=function(H){var B=h;return function(){var V=h;h=B;try{return H.apply(this,arguments)}finally{h=V}}}})(L_);j_.exports=L_;var QV=j_.exports;/**
171
+ * @license React
172
+ * react-dom.production.min.js
173
+ *
174
+ * Copyright (c) Facebook, Inc. and its affiliates.
175
+ *
176
+ * This source code is licensed under the MIT license found in the
177
+ * LICENSE file in the root directory of this source tree.
178
+ */var N_=w,Gn=QV;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 F_=new Set,Ac={};function _i(e,n){La(e,n),La(e+"Capture",n)}function La(e,n){for(Ac[e]=n,e=0;e<n.length;e++)F_.add(n[e])}var Ro=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),tS=Object.prototype.hasOwnProperty,JV=/^[: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]*$/,iP={},aP={};function eK(e){return tS.call(aP,e)?!0:tS.call(iP,e)?!1:JV.test(e)?aP[e]=!0:(iP[e]=!0,!1)}function tK(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 nK(e,n,t,r){if(n===null||typeof n>"u"||tK(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 pn(e,n,t,r,o,s,i){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=t,this.propertyName=e,this.type=n,this.sanitizeURL=s,this.removeEmptyString=i}var Nt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Nt[e]=new pn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Nt[n]=new pn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Nt[e]=new pn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Nt[e]=new pn(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){Nt[e]=new pn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Nt[e]=new pn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Nt[e]=new pn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Nt[e]=new pn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Nt[e]=new pn(e,5,!1,e.toLowerCase(),null,!1,!1)});var C0=/[\-:]([a-z])/g;function E0(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(C0,E0);Nt[n]=new pn(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(C0,E0);Nt[n]=new pn(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(C0,E0);Nt[n]=new pn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Nt[e]=new pn(e,1,!1,e.toLowerCase(),null,!1,!1)});Nt.xlinkHref=new pn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Nt[e]=new pn(e,1,!1,e.toLowerCase(),null,!0,!0)});function k0(e,n,t,r){var o=Nt.hasOwnProperty(n)?Nt[n]:null;(o!==null?o.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(nK(n,t,o,r)&&(t=null),r||o===null?eK(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 Wo=N_.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Sd=Symbol.for("react.element"),aa=Symbol.for("react.portal"),la=Symbol.for("react.fragment"),I0=Symbol.for("react.strict_mode"),nS=Symbol.for("react.profiler"),z_=Symbol.for("react.provider"),B_=Symbol.for("react.context"),_0=Symbol.for("react.forward_ref"),rS=Symbol.for("react.suspense"),oS=Symbol.for("react.suspense_list"),T0=Symbol.for("react.memo"),ns=Symbol.for("react.lazy"),U_=Symbol.for("react.offscreen"),lP=Symbol.iterator;function Al(e){return e===null||typeof e!="object"?null:(e=lP&&e[lP]||e["@@iterator"],typeof e=="function"?e:null)}var lt=Object.assign,cm;function Yl(e){if(cm===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);cm=n&&n[1]||""}return`
179
+ `+cm+e}var um=!1;function dm(e,n){if(!e||um)return"";um=!0;var t=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(c){var r=c}Reflect.construct(e,[],n)}else{try{n.call()}catch(c){r=c}e.call(n.prototype)}else{try{throw Error()}catch(c){r=c}e()}}catch(c){if(c&&r&&typeof c.stack=="string"){for(var o=c.stack.split(`
180
+ `),s=r.stack.split(`
181
+ `),i=o.length-1,a=s.length-1;1<=i&&0<=a&&o[i]!==s[a];)a--;for(;1<=i&&0<=a;i--,a--)if(o[i]!==s[a]){if(i!==1||a!==1)do if(i--,a--,0>a||o[i]!==s[a]){var l=`
182
+ `+o[i].replace(" at new "," at ");return e.displayName&&l.includes("<anonymous>")&&(l=l.replace("<anonymous>",e.displayName)),l}while(1<=i&&0<=a);break}}}finally{um=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?Yl(e):""}function rK(e){switch(e.tag){case 5:return Yl(e.type);case 16:return Yl("Lazy");case 13:return Yl("Suspense");case 19:return Yl("SuspenseList");case 0:case 2:case 15:return e=dm(e.type,!1),e;case 11:return e=dm(e.type.render,!1),e;case 1:return e=dm(e.type,!0),e;default:return""}}function sS(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 la:return"Fragment";case aa:return"Portal";case nS:return"Profiler";case I0:return"StrictMode";case rS:return"Suspense";case oS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case B_:return(e.displayName||"Context")+".Consumer";case z_:return(e._context.displayName||"Context")+".Provider";case _0:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case T0:return n=e.displayName||null,n!==null?n:sS(e.type)||"Memo";case ns:n=e._payload,e=e._init;try{return sS(e(n))}catch{}}return null}function oK(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 sS(n);case 8:return n===I0?"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 Is(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function H_(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function sK(e){var n=H_(e)?"checked":"value",t=Object.getOwnPropertyDescriptor(e.constructor.prototype,n),r=""+e[n];if(!e.hasOwnProperty(n)&&typeof t<"u"&&typeof t.get=="function"&&typeof t.set=="function"){var o=t.get,s=t.set;return Object.defineProperty(e,n,{configurable:!0,get:function(){return o.call(this)},set:function(i){r=""+i,s.call(this,i)}}),Object.defineProperty(e,n,{enumerable:t.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){e._valueTracker=null,delete e[n]}}}}function vd(e){e._valueTracker||(e._valueTracker=sK(e))}function V_(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=H_(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function xp(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 iS(e,n){var t=n.checked;return lt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function cP(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Is(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 K_(e,n){n=n.checked,n!=null&&k0(e,"checked",n,!1)}function aS(e,n){K_(e,n);var t=Is(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")?lS(e,n.type,t):n.hasOwnProperty("defaultValue")&&lS(e,n.type,Is(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function uP(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 lS(e,n,t){(n!=="number"||xp(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var Xl=Array.isArray;function Ca(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=""+Is(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 cS(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return lt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function dP(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(Xl(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Is(t)}}function W_(e,n){var t=Is(n.value),r=Is(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 hP(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function G_(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 uS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?G_(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var wd,Y_=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(wd=wd||document.createElement("div"),wd.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=wd.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Mc(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var ic={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},iK=["Webkit","ms","Moz","O"];Object.keys(ic).forEach(function(e){iK.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),ic[n]=ic[e]})});function X_(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||ic.hasOwnProperty(e)&&ic[e]?(""+n).trim():n+"px"}function q_(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=X_(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var aK=lt({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 dS(e,n){if(n){if(aK[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 hS(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 pS=null;function $0(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var fS=null,Ea=null,ka=null;function pP(e){if(e=Iu(e)){if(typeof fS!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Pf(n),fS(e.stateNode,e.type,n))}}function Z_(e){Ea?ka?ka.push(e):ka=[e]:Ea=e}function Q_(){if(Ea){var e=Ea,n=ka;if(ka=Ea=null,pP(e),n)for(e=0;e<n.length;e++)pP(n[e])}}function J_(e,n){return e(n)}function e2(){}var hm=!1;function t2(e,n,t){if(hm)return e(n,t);hm=!0;try{return J_(e,n,t)}finally{hm=!1,(Ea!==null||ka!==null)&&(e2(),Q_())}}function Oc(e,n){var t=e.stateNode;if(t===null)return null;var r=Pf(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 gS=!1;if(Ro)try{var Ml={};Object.defineProperty(Ml,"passive",{get:function(){gS=!0}}),window.addEventListener("test",Ml,Ml),window.removeEventListener("test",Ml,Ml)}catch{gS=!1}function lK(e,n,t,r,o,s,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{n.apply(t,c)}catch(u){this.onError(u)}}var ac=!1,bp=null,Pp=!1,mS=null,cK={onError:function(e){ac=!0,bp=e}};function uK(e,n,t,r,o,s,i,a,l){ac=!1,bp=null,lK.apply(cK,arguments)}function dK(e,n,t,r,o,s,i,a,l){if(uK.apply(this,arguments),ac){if(ac){var c=bp;ac=!1,bp=null}else throw Error(q(198));Pp||(Pp=!0,mS=c)}}function Ti(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 n2(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 fP(e){if(Ti(e)!==e)throw Error(q(188))}function hK(e){var n=e.alternate;if(!n){if(n=Ti(e),n===null)throw Error(q(188));return n!==e?null:e}for(var t=e,r=n;;){var o=t.return;if(o===null)break;var s=o.alternate;if(s===null){if(r=o.return,r!==null){t=r;continue}break}if(o.child===s.child){for(s=o.child;s;){if(s===t)return fP(o),e;if(s===r)return fP(o),n;s=s.sibling}throw Error(q(188))}if(t.return!==r.return)t=o,r=s;else{for(var i=!1,a=o.child;a;){if(a===t){i=!0,t=o,r=s;break}if(a===r){i=!0,r=o,t=s;break}a=a.sibling}if(!i){for(a=s.child;a;){if(a===t){i=!0,t=s,r=o;break}if(a===r){i=!0,r=s,t=o;break}a=a.sibling}if(!i)throw Error(q(189))}}if(t.alternate!==r)throw Error(q(190))}if(t.tag!==3)throw Error(q(188));return t.stateNode.current===t?e:n}function r2(e){return e=hK(e),e!==null?o2(e):null}function o2(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=o2(e);if(n!==null)return n;e=e.sibling}return null}var s2=Gn.unstable_scheduleCallback,gP=Gn.unstable_cancelCallback,pK=Gn.unstable_shouldYield,fK=Gn.unstable_requestPaint,ft=Gn.unstable_now,gK=Gn.unstable_getCurrentPriorityLevel,A0=Gn.unstable_ImmediatePriority,i2=Gn.unstable_UserBlockingPriority,Cp=Gn.unstable_NormalPriority,mK=Gn.unstable_LowPriority,a2=Gn.unstable_IdlePriority,vf=null,Zr=null;function yK(e){if(Zr&&typeof Zr.onCommitFiberRoot=="function")try{Zr.onCommitFiberRoot(vf,e,void 0,(e.current.flags&128)===128)}catch{}}var $r=Math.clz32?Math.clz32:wK,SK=Math.log,vK=Math.LN2;function wK(e){return e>>>=0,e===0?32:31-(SK(e)/vK|0)|0}var xd=64,bd=4194304;function ql(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 Ep(e,n){var t=e.pendingLanes;if(t===0)return 0;var r=0,o=e.suspendedLanes,s=e.pingedLanes,i=t&268435455;if(i!==0){var a=i&~o;a!==0?r=ql(a):(s&=i,s!==0&&(r=ql(s)))}else i=t&~o,i!==0?r=ql(i):s!==0&&(r=ql(s));if(r===0)return 0;if(n!==0&&n!==r&&!(n&o)&&(o=r&-r,s=n&-n,o>=s||o===16&&(s&4194240)!==0))return n;if(r&4&&(r|=t&16),n=e.entangledLanes,n!==0)for(e=e.entanglements,n&=r;0<n;)t=31-$r(n),o=1<<t,r|=e[t],n&=~o;return r}function xK(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 bK(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-$r(s),a=1<<i,l=o[i];l===-1?(!(a&t)||a&r)&&(o[i]=xK(a,n)):l<=n&&(e.expiredLanes|=a),s&=~a}}function yS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function l2(){var e=xd;return xd<<=1,!(xd&4194240)&&(xd=64),e}function pm(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function Eu(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-$r(n),e[n]=t}function PK(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-$r(t),s=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~s}}function M0(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-$r(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var De=0;function c2(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var u2,O0,d2,h2,p2,SS=!1,Pd=[],ys=null,Ss=null,vs=null,Rc=new Map,Dc=new Map,as=[],CK="mousedown mouseup touchcancel touchend touchstart auxclick dblclick pointercancel pointerdown pointerup dragend dragstart drop compositionend compositionstart keydown keypress keyup input textInput copy cut paste click change contextmenu reset submit".split(" ");function mP(e,n){switch(e){case"focusin":case"focusout":ys=null;break;case"dragenter":case"dragleave":Ss=null;break;case"mouseover":case"mouseout":vs=null;break;case"pointerover":case"pointerout":Rc.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Dc.delete(n.pointerId)}}function Ol(e,n,t,r,o,s){return e===null||e.nativeEvent!==s?(e={blockedOn:n,domEventName:t,eventSystemFlags:r,nativeEvent:s,targetContainers:[o]},n!==null&&(n=Iu(n),n!==null&&O0(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function EK(e,n,t,r,o){switch(n){case"focusin":return ys=Ol(ys,e,n,t,r,o),!0;case"dragenter":return Ss=Ol(Ss,e,n,t,r,o),!0;case"mouseover":return vs=Ol(vs,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return Rc.set(s,Ol(Rc.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,Dc.set(s,Ol(Dc.get(s)||null,e,n,t,r,o)),!0}return!1}function f2(e){var n=ni(e.target);if(n!==null){var t=Ti(n);if(t!==null){if(n=t.tag,n===13){if(n=n2(t),n!==null){e.blockedOn=n,p2(e.priority,function(){d2(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 Ah(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=vS(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);pS=r,t.target.dispatchEvent(r),pS=null}else return n=Iu(t),n!==null&&O0(n),e.blockedOn=t,!1;n.shift()}return!0}function yP(e,n,t){Ah(e)&&t.delete(n)}function kK(){SS=!1,ys!==null&&Ah(ys)&&(ys=null),Ss!==null&&Ah(Ss)&&(Ss=null),vs!==null&&Ah(vs)&&(vs=null),Rc.forEach(yP),Dc.forEach(yP)}function Rl(e,n){e.blockedOn===n&&(e.blockedOn=null,SS||(SS=!0,Gn.unstable_scheduleCallback(Gn.unstable_NormalPriority,kK)))}function jc(e){function n(o){return Rl(o,e)}if(0<Pd.length){Rl(Pd[0],e);for(var t=1;t<Pd.length;t++){var r=Pd[t];r.blockedOn===e&&(r.blockedOn=null)}}for(ys!==null&&Rl(ys,e),Ss!==null&&Rl(Ss,e),vs!==null&&Rl(vs,e),Rc.forEach(n),Dc.forEach(n),t=0;t<as.length;t++)r=as[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<as.length&&(t=as[0],t.blockedOn===null);)f2(t),t.blockedOn===null&&as.shift()}var Ia=Wo.ReactCurrentBatchConfig,kp=!0;function IK(e,n,t,r){var o=De,s=Ia.transition;Ia.transition=null;try{De=1,R0(e,n,t,r)}finally{De=o,Ia.transition=s}}function _K(e,n,t,r){var o=De,s=Ia.transition;Ia.transition=null;try{De=4,R0(e,n,t,r)}finally{De=o,Ia.transition=s}}function R0(e,n,t,r){if(kp){var o=vS(e,n,t,r);if(o===null)Pm(e,n,r,Ip,t),mP(e,r);else if(EK(o,e,n,t,r))r.stopPropagation();else if(mP(e,r),n&4&&-1<CK.indexOf(e)){for(;o!==null;){var s=Iu(o);if(s!==null&&u2(s),s=vS(e,n,t,r),s===null&&Pm(e,n,r,Ip,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else Pm(e,n,r,null,t)}}var Ip=null;function vS(e,n,t,r){if(Ip=null,e=$0(r),e=ni(e),e!==null)if(n=Ti(e),n===null)e=null;else if(t=n.tag,t===13){if(e=n2(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 Ip=e,null}function g2(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(gK()){case A0:return 1;case i2:return 4;case Cp:case mK:return 16;case a2:return 536870912;default:return 16}default:return 16}}var hs=null,D0=null,Mh=null;function m2(){if(Mh)return Mh;var e,n=D0,t=n.length,r,o="value"in hs?hs.value:hs.textContent,s=o.length;for(e=0;e<t&&n[e]===o[e];e++);var i=t-e;for(r=1;r<=i&&n[t-r]===o[s-r];r++);return Mh=o.slice(e,1<r?1-r:void 0)}function Oh(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 Cd(){return!0}function SP(){return!1}function Zn(e){function n(t,r,o,s,i){this._reactName=t,this._targetInst=o,this.type=r,this.nativeEvent=s,this.target=i,this.currentTarget=null;for(var a in e)e.hasOwnProperty(a)&&(t=e[a],this[a]=t?t(s):s[a]);return this.isDefaultPrevented=(s.defaultPrevented!=null?s.defaultPrevented:s.returnValue===!1)?Cd:SP,this.isPropagationStopped=SP,this}return lt(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=Cd)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=Cd)},persist:function(){},isPersistent:Cd}),n}var il={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},j0=Zn(il),ku=lt({},il,{view:0,detail:0}),TK=Zn(ku),fm,gm,Dl,wf=lt({},ku,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:L0,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!==Dl&&(Dl&&e.type==="mousemove"?(fm=e.screenX-Dl.screenX,gm=e.screenY-Dl.screenY):gm=fm=0,Dl=e),fm)},movementY:function(e){return"movementY"in e?e.movementY:gm}}),vP=Zn(wf),$K=lt({},wf,{dataTransfer:0}),AK=Zn($K),MK=lt({},ku,{relatedTarget:0}),mm=Zn(MK),OK=lt({},il,{animationName:0,elapsedTime:0,pseudoElement:0}),RK=Zn(OK),DK=lt({},il,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),jK=Zn(DK),LK=lt({},il,{data:0}),wP=Zn(LK),NK={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},FK={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"},zK={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function BK(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=zK[e])?!!n[e]:!1}function L0(){return BK}var UK=lt({},ku,{key:function(e){if(e.key){var n=NK[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Oh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?FK[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:L0,charCode:function(e){return e.type==="keypress"?Oh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Oh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),HK=Zn(UK),VK=lt({},wf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),xP=Zn(VK),KK=lt({},ku,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:L0}),WK=Zn(KK),GK=lt({},il,{propertyName:0,elapsedTime:0,pseudoElement:0}),YK=Zn(GK),XK=lt({},wf,{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}),qK=Zn(XK),ZK=[9,13,27,32],N0=Ro&&"CompositionEvent"in window,lc=null;Ro&&"documentMode"in document&&(lc=document.documentMode);var QK=Ro&&"TextEvent"in window&&!lc,y2=Ro&&(!N0||lc&&8<lc&&11>=lc),bP=" ",PP=!1;function S2(e,n){switch(e){case"keyup":return ZK.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function v2(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ca=!1;function JK(e,n){switch(e){case"compositionend":return v2(n);case"keypress":return n.which!==32?null:(PP=!0,bP);case"textInput":return e=n.data,e===bP&&PP?null:e;default:return null}}function eW(e,n){if(ca)return e==="compositionend"||!N0&&S2(e,n)?(e=m2(),Mh=D0=hs=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 y2&&n.locale!=="ko"?null:n.data;default:return null}}var tW={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 CP(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!tW[e.type]:n==="textarea"}function w2(e,n,t,r){Z_(r),n=_p(n,"onChange"),0<n.length&&(t=new j0("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var cc=null,Lc=null;function nW(e){A2(e,0)}function xf(e){var n=ha(e);if(V_(n))return e}function rW(e,n){if(e==="change")return n}var x2=!1;if(Ro){var ym;if(Ro){var Sm="oninput"in document;if(!Sm){var EP=document.createElement("div");EP.setAttribute("oninput","return;"),Sm=typeof EP.oninput=="function"}ym=Sm}else ym=!1;x2=ym&&(!document.documentMode||9<document.documentMode)}function kP(){cc&&(cc.detachEvent("onpropertychange",b2),Lc=cc=null)}function b2(e){if(e.propertyName==="value"&&xf(Lc)){var n=[];w2(n,Lc,e,$0(e)),t2(nW,n)}}function oW(e,n,t){e==="focusin"?(kP(),cc=n,Lc=t,cc.attachEvent("onpropertychange",b2)):e==="focusout"&&kP()}function sW(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return xf(Lc)}function iW(e,n){if(e==="click")return xf(n)}function aW(e,n){if(e==="input"||e==="change")return xf(n)}function lW(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Dr=typeof Object.is=="function"?Object.is:lW;function Nc(e,n){if(Dr(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(!tS.call(n,o)||!Dr(e[o],n[o]))return!1}return!0}function IP(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function _P(e,n){var t=IP(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=IP(t)}}function P2(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?P2(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function C2(){for(var e=window,n=xp();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=xp(e.document)}return n}function F0(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 cW(e){var n=C2(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&P2(t.ownerDocument.documentElement,t)){if(r!==null&&F0(t)){if(n=r.start,e=r.end,e===void 0&&(e=n),"selectionStart"in t)t.selectionStart=n,t.selectionEnd=Math.min(e,t.value.length);else if(e=(n=t.ownerDocument||document)&&n.defaultView||window,e.getSelection){e=e.getSelection();var o=t.textContent.length,s=Math.min(r.start,o);r=r.end===void 0?s:Math.min(r.end,o),!e.extend&&s>r&&(o=r,r=s,s=o),o=_P(t,s);var i=_P(t,r);o&&i&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(n=n.createRange(),n.setStart(o.node,o.offset),e.removeAllRanges(),s>r?(e.addRange(n),e.extend(i.node,i.offset)):(n.setEnd(i.node,i.offset),e.addRange(n)))}}for(n=[],e=t;e=e.parentNode;)e.nodeType===1&&n.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof t.focus=="function"&&t.focus(),t=0;t<n.length;t++)e=n[t],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var uW=Ro&&"documentMode"in document&&11>=document.documentMode,ua=null,wS=null,uc=null,xS=!1;function TP(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;xS||ua==null||ua!==xp(r)||(r=ua,"selectionStart"in r&&F0(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}),uc&&Nc(uc,r)||(uc=r,r=_p(wS,"onSelect"),0<r.length&&(n=new j0("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=ua)))}function Ed(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var da={animationend:Ed("Animation","AnimationEnd"),animationiteration:Ed("Animation","AnimationIteration"),animationstart:Ed("Animation","AnimationStart"),transitionend:Ed("Transition","TransitionEnd")},vm={},E2={};Ro&&(E2=document.createElement("div").style,"AnimationEvent"in window||(delete da.animationend.animation,delete da.animationiteration.animation,delete da.animationstart.animation),"TransitionEvent"in window||delete da.transitionend.transition);function bf(e){if(vm[e])return vm[e];if(!da[e])return e;var n=da[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in E2)return vm[e]=n[t];return e}var k2=bf("animationend"),I2=bf("animationiteration"),_2=bf("animationstart"),T2=bf("transitionend"),$2=new Map,$P="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 Ns(e,n){$2.set(e,n),_i(n,[e])}for(var wm=0;wm<$P.length;wm++){var xm=$P[wm],dW=xm.toLowerCase(),hW=xm[0].toUpperCase()+xm.slice(1);Ns(dW,"on"+hW)}Ns(k2,"onAnimationEnd");Ns(I2,"onAnimationIteration");Ns(_2,"onAnimationStart");Ns("dblclick","onDoubleClick");Ns("focusin","onFocus");Ns("focusout","onBlur");Ns(T2,"onTransitionEnd");La("onMouseEnter",["mouseout","mouseover"]);La("onMouseLeave",["mouseout","mouseover"]);La("onPointerEnter",["pointerout","pointerover"]);La("onPointerLeave",["pointerout","pointerover"]);_i("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));_i("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));_i("onBeforeInput",["compositionend","keypress","textInput","paste"]);_i("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));_i("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));_i("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Zl="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(" "),pW=new Set("cancel close invalid load scroll toggle".split(" ").concat(Zl));function AP(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,dK(r,n,void 0,e),e.currentTarget=null}function A2(e,n){n=(n&4)!==0;for(var t=0;t<e.length;t++){var r=e[t],o=r.event;r=r.listeners;e:{var s=void 0;if(n)for(var i=r.length-1;0<=i;i--){var a=r[i],l=a.instance,c=a.currentTarget;if(a=a.listener,l!==s&&o.isPropagationStopped())break e;AP(o,a,c),s=l}else for(i=0;i<r.length;i++){if(a=r[i],l=a.instance,c=a.currentTarget,a=a.listener,l!==s&&o.isPropagationStopped())break e;AP(o,a,c),s=l}}}if(Pp)throw e=mS,Pp=!1,mS=null,e}function Ze(e,n){var t=n[kS];t===void 0&&(t=n[kS]=new Set);var r=e+"__bubble";t.has(r)||(M2(n,e,2,!1),t.add(r))}function bm(e,n,t){var r=0;n&&(r|=4),M2(t,e,r,n)}var kd="_reactListening"+Math.random().toString(36).slice(2);function Fc(e){if(!e[kd]){e[kd]=!0,F_.forEach(function(t){t!=="selectionchange"&&(pW.has(t)||bm(t,!1,e),bm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[kd]||(n[kd]=!0,bm("selectionchange",!1,n))}}function M2(e,n,t,r){switch(g2(n)){case 1:var o=IK;break;case 4:o=_K;break;default:o=R0}t=o.bind(null,n,t,e),o=void 0,!gS||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 Pm(e,n,t,r,o){var s=r;if(!(n&1)&&!(n&2)&&r!==null)e:for(;;){if(r===null)return;var i=r.tag;if(i===3||i===4){var a=r.stateNode.containerInfo;if(a===o||a.nodeType===8&&a.parentNode===o)break;if(i===4)for(i=r.return;i!==null;){var l=i.tag;if((l===3||l===4)&&(l=i.stateNode.containerInfo,l===o||l.nodeType===8&&l.parentNode===o))return;i=i.return}for(;a!==null;){if(i=ni(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}t2(function(){var c=s,u=$0(t),d=[];e:{var h=$2.get(e);if(h!==void 0){var p=j0,m=e;switch(e){case"keypress":if(Oh(t)===0)break e;case"keydown":case"keyup":p=HK;break;case"focusin":m="focus",p=mm;break;case"focusout":m="blur",p=mm;break;case"beforeblur":case"afterblur":p=mm;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=vP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=AK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=WK;break;case k2:case I2:case _2:p=RK;break;case T2:p=YK;break;case"scroll":p=TK;break;case"wheel":p=qK;break;case"copy":case"cut":case"paste":p=jK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=xP}var f=(n&4)!==0,S=!f&&e==="scroll",v=f?h!==null?h+"Capture":null:h;f=[];for(var x=c,b;x!==null;){b=x;var P=b.stateNode;if(b.tag===5&&P!==null&&(b=P,v!==null&&(P=Oc(x,v),P!=null&&f.push(zc(x,P,b)))),S)break;x=x.return}0<f.length&&(h=new p(h,m,null,t,u),d.push({event:h,listeners:f}))}}if(!(n&7)){e:{if(h=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",h&&t!==pS&&(m=t.relatedTarget||t.fromElement)&&(ni(m)||m[Do]))break e;if((p||h)&&(h=u.window===u?u:(h=u.ownerDocument)?h.defaultView||h.parentWindow:window,p?(m=t.relatedTarget||t.toElement,p=c,m=m?ni(m):null,m!==null&&(S=Ti(m),m!==S||m.tag!==5&&m.tag!==6)&&(m=null)):(p=null,m=c),p!==m)){if(f=vP,P="onMouseLeave",v="onMouseEnter",x="mouse",(e==="pointerout"||e==="pointerover")&&(f=xP,P="onPointerLeave",v="onPointerEnter",x="pointer"),S=p==null?h:ha(p),b=m==null?h:ha(m),h=new f(P,x+"leave",p,t,u),h.target=S,h.relatedTarget=b,P=null,ni(u)===c&&(f=new f(v,x+"enter",m,t,u),f.target=b,f.relatedTarget=S,P=f),S=P,p&&m)t:{for(f=p,v=m,x=0,b=f;b;b=Gi(b))x++;for(b=0,P=v;P;P=Gi(P))b++;for(;0<x-b;)f=Gi(f),x--;for(;0<b-x;)v=Gi(v),b--;for(;x--;){if(f===v||v!==null&&f===v.alternate)break t;f=Gi(f),v=Gi(v)}f=null}else f=null;p!==null&&MP(d,h,p,f,!1),m!==null&&S!==null&&MP(d,S,m,f,!0)}}e:{if(h=c?ha(c):window,p=h.nodeName&&h.nodeName.toLowerCase(),p==="select"||p==="input"&&h.type==="file")var E=rW;else if(CP(h))if(x2)E=aW;else{E=sW;var k=oW}else(p=h.nodeName)&&p.toLowerCase()==="input"&&(h.type==="checkbox"||h.type==="radio")&&(E=iW);if(E&&(E=E(e,c))){w2(d,E,t,u);break e}k&&k(e,h,c),e==="focusout"&&(k=h._wrapperState)&&k.controlled&&h.type==="number"&&lS(h,"number",h.value)}switch(k=c?ha(c):window,e){case"focusin":(CP(k)||k.contentEditable==="true")&&(ua=k,wS=c,uc=null);break;case"focusout":uc=wS=ua=null;break;case"mousedown":xS=!0;break;case"contextmenu":case"mouseup":case"dragend":xS=!1,TP(d,t,u);break;case"selectionchange":if(uW)break;case"keydown":case"keyup":TP(d,t,u)}var I;if(N0)e:{switch(e){case"compositionstart":var _="onCompositionStart";break e;case"compositionend":_="onCompositionEnd";break e;case"compositionupdate":_="onCompositionUpdate";break e}_=void 0}else ca?S2(e,t)&&(_="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(_="onCompositionStart");_&&(y2&&t.locale!=="ko"&&(ca||_!=="onCompositionStart"?_==="onCompositionEnd"&&ca&&(I=m2()):(hs=u,D0="value"in hs?hs.value:hs.textContent,ca=!0)),k=_p(c,_),0<k.length&&(_=new wP(_,e,null,t,u),d.push({event:_,listeners:k}),I?_.data=I:(I=v2(t),I!==null&&(_.data=I)))),(I=QK?JK(e,t):eW(e,t))&&(c=_p(c,"onBeforeInput"),0<c.length&&(u=new wP("onBeforeInput","beforeinput",null,t,u),d.push({event:u,listeners:c}),u.data=I))}A2(d,n)})}function zc(e,n,t){return{instance:e,listener:n,currentTarget:t}}function _p(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=Oc(e,t),s!=null&&r.unshift(zc(e,s,o)),s=Oc(e,n),s!=null&&r.push(zc(e,s,o))),e=e.return}return r}function Gi(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function MP(e,n,t,r,o){for(var s=n._reactName,i=[];t!==null&&t!==r;){var a=t,l=a.alternate,c=a.stateNode;if(l!==null&&l===r)break;a.tag===5&&c!==null&&(a=c,o?(l=Oc(t,s),l!=null&&i.unshift(zc(t,l,a))):o||(l=Oc(t,s),l!=null&&i.push(zc(t,l,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var fW=/\r\n?/g,gW=/\u0000|\uFFFD/g;function OP(e){return(typeof e=="string"?e:""+e).replace(fW,`
183
+ `).replace(gW,"")}function Id(e,n,t){if(n=OP(n),OP(e)!==n&&t)throw Error(q(425))}function Tp(){}var bS=null,PS=null;function CS(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 ES=typeof setTimeout=="function"?setTimeout:void 0,mW=typeof clearTimeout=="function"?clearTimeout:void 0,RP=typeof Promise=="function"?Promise:void 0,yW=typeof queueMicrotask=="function"?queueMicrotask:typeof RP<"u"?function(e){return RP.resolve(null).then(e).catch(SW)}:ES;function SW(e){setTimeout(function(){throw e})}function Cm(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),jc(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);jc(n)}function ws(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 DP(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 al=Math.random().toString(36).slice(2),Wr="__reactFiber$"+al,Bc="__reactProps$"+al,Do="__reactContainer$"+al,kS="__reactEvents$"+al,vW="__reactListeners$"+al,wW="__reactHandles$"+al;function ni(e){var n=e[Wr];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Do]||t[Wr]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=DP(e);e!==null;){if(t=e[Wr])return t;e=DP(e)}return n}e=t,t=e.parentNode}return null}function Iu(e){return e=e[Wr]||e[Do],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function ha(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Pf(e){return e[Bc]||null}var IS=[],pa=-1;function Fs(e){return{current:e}}function et(e){0>pa||(e.current=IS[pa],IS[pa]=null,pa--)}function Ke(e,n){pa++,IS[pa]=e.current,e.current=n}var _s={},Jt=Fs(_s),bn=Fs(!1),fi=_s;function Na(e,n){var t=e.type.contextTypes;if(!t)return _s;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var o={},s;for(s in t)o[s]=n[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=o),o}function Pn(e){return e=e.childContextTypes,e!=null}function $p(){et(bn),et(Jt)}function jP(e,n,t){if(Jt.current!==_s)throw Error(q(168));Ke(Jt,n),Ke(bn,t)}function O2(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,oK(e)||"Unknown",o));return lt({},t,r)}function Ap(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||_s,fi=Jt.current,Ke(Jt,e),Ke(bn,bn.current),!0}function LP(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=O2(e,n,fi),r.__reactInternalMemoizedMergedChildContext=e,et(bn),et(Jt),Ke(Jt,e)):et(bn),Ke(bn,t)}var wo=null,Cf=!1,Em=!1;function R2(e){wo===null?wo=[e]:wo.push(e)}function xW(e){Cf=!0,R2(e)}function zs(){if(!Em&&wo!==null){Em=!0;var e=0,n=De;try{var t=wo;for(De=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}wo=null,Cf=!1}catch(o){throw wo!==null&&(wo=wo.slice(e+1)),s2(A0,zs),o}finally{De=n,Em=!1}}return null}var fa=[],ga=0,Mp=null,Op=0,ar=[],lr=0,gi=null,Co=1,Eo="";function Zs(e,n){fa[ga++]=Op,fa[ga++]=Mp,Mp=e,Op=n}function D2(e,n,t){ar[lr++]=Co,ar[lr++]=Eo,ar[lr++]=gi,gi=e;var r=Co;e=Eo;var o=32-$r(r)-1;r&=~(1<<o),t+=1;var s=32-$r(n)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,Co=1<<32-$r(n)+o|t<<o|r,Eo=s+e}else Co=1<<s|t<<o|r,Eo=e}function z0(e){e.return!==null&&(Zs(e,1),D2(e,1,0))}function B0(e){for(;e===Mp;)Mp=fa[--ga],fa[ga]=null,Op=fa[--ga],fa[ga]=null;for(;e===gi;)gi=ar[--lr],ar[lr]=null,Eo=ar[--lr],ar[lr]=null,Co=ar[--lr],ar[lr]=null}var Hn=null,Bn=null,tt=!1,Cr=null;function j2(e,n){var t=cr(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 NP(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,Hn=e,Bn=ws(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,Hn=e,Bn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=gi!==null?{id:Co,overflow:Eo}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=cr(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,Hn=e,Bn=null,!0):!1;default:return!1}}function _S(e){return(e.mode&1)!==0&&(e.flags&128)===0}function TS(e){if(tt){var n=Bn;if(n){var t=n;if(!NP(e,n)){if(_S(e))throw Error(q(418));n=ws(t.nextSibling);var r=Hn;n&&NP(e,n)?j2(r,t):(e.flags=e.flags&-4097|2,tt=!1,Hn=e)}}else{if(_S(e))throw Error(q(418));e.flags=e.flags&-4097|2,tt=!1,Hn=e}}}function FP(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Hn=e}function _d(e){if(e!==Hn)return!1;if(!tt)return FP(e),tt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!CS(e.type,e.memoizedProps)),n&&(n=Bn)){if(_S(e))throw L2(),Error(q(418));for(;n;)j2(e,n),n=ws(n.nextSibling)}if(FP(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){Bn=ws(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}Bn=null}}else Bn=Hn?ws(e.stateNode.nextSibling):null;return!0}function L2(){for(var e=Bn;e;)e=ws(e.nextSibling)}function Fa(){Bn=Hn=null,tt=!1}function U0(e){Cr===null?Cr=[e]:Cr.push(e)}var bW=Wo.ReactCurrentBatchConfig;function Sr(e,n){if(e&&e.defaultProps){n=lt({},n),e=e.defaultProps;for(var t in e)n[t]===void 0&&(n[t]=e[t]);return n}return n}var Rp=Fs(null),Dp=null,ma=null,H0=null;function V0(){H0=ma=Dp=null}function K0(e){var n=Rp.current;et(Rp),e._currentValue=n}function $S(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 _a(e,n){Dp=e,H0=ma=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(wn=!0),e.firstContext=null)}function pr(e){var n=e._currentValue;if(H0!==e)if(e={context:e,memoizedValue:n,next:null},ma===null){if(Dp===null)throw Error(q(308));ma=e,Dp.dependencies={lanes:0,firstContext:e}}else ma=ma.next=e;return n}var ri=null;function W0(e){ri===null?ri=[e]:ri.push(e)}function N2(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,W0(n)):(t.next=o.next,o.next=t),n.interleaved=t,jo(e,r)}function jo(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 rs=!1;function G0(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function F2(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 $o(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function xs(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Ce&2){var o=r.pending;return o===null?n.next=n:(n.next=o.next,o.next=n),r.pending=n,jo(e,t)}return o=r.interleaved,o===null?(n.next=n,W0(r)):(n.next=o.next,o.next=n),r.interleaved=n,jo(e,t)}function Rh(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,M0(e,t)}}function zP(e,n){var t=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,t===r)){var o=null,s=null;if(t=t.firstBaseUpdate,t!==null){do{var i={eventTime:t.eventTime,lane:t.lane,tag:t.tag,payload:t.payload,callback:t.callback,next:null};s===null?o=s=i:s=s.next=i,t=t.next}while(t!==null);s===null?o=s=n:s=s.next=n}else o=s=n;t={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:s,shared:r.shared,effects:r.effects},e.updateQueue=t;return}e=t.lastBaseUpdate,e===null?t.firstBaseUpdate=n:e.next=n,t.lastBaseUpdate=n}function jp(e,n,t,r){var o=e.updateQueue;rs=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var l=a,c=l.next;l.next=null,i===null?s=c:i.next=c,i=l;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=c:a.next=c,u.lastBaseUpdate=l))}if(s!==null){var d=o.baseState;i=0,u=c=l=null,a=s;do{var h=a.lane,p=a.eventTime;if((r&h)===h){u!==null&&(u=u.next={eventTime:p,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var m=e,f=a;switch(h=n,p=t,f.tag){case 1:if(m=f.payload,typeof m=="function"){d=m.call(p,d,h);break e}d=m;break e;case 3:m.flags=m.flags&-65537|128;case 0:if(m=f.payload,h=typeof m=="function"?m.call(p,d,h):m,h==null)break e;d=lt({},d,h);break e;case 2:rs=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,h=o.effects,h===null?o.effects=[a]:h.push(a))}else p={eventTime:p,lane:h,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(c=u=p,l=d):u=u.next=p,i|=h;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;h=a,a=h.next,h.next=null,o.lastBaseUpdate=h,o.shared.pending=null}}while(!0);if(u===null&&(l=d),o.baseState=l,o.firstBaseUpdate=c,o.lastBaseUpdate=u,n=o.shared.interleaved,n!==null){o=n;do i|=o.lane,o=o.next;while(o!==n)}else s===null&&(o.shared.lanes=0);yi|=i,e.lanes=i,e.memoizedState=d}}function BP(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 z2=new N_.Component().refs;function AS(e,n,t,r){n=e.memoizedState,t=t(r,n),t=t==null?n:lt({},n,t),e.memoizedState=t,e.lanes===0&&(e.updateQueue.baseState=t)}var Ef={isMounted:function(e){return(e=e._reactInternals)?Ti(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=an(),o=Ps(e),s=$o(r,o);s.payload=n,t!=null&&(s.callback=t),n=xs(e,s,o),n!==null&&(Ar(n,e,o,r),Rh(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=an(),o=Ps(e),s=$o(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=xs(e,s,o),n!==null&&(Ar(n,e,o,r),Rh(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=an(),r=Ps(e),o=$o(t,r);o.tag=2,n!=null&&(o.callback=n),n=xs(e,o,r),n!==null&&(Ar(n,e,r,t),Rh(n,e,r))}};function UP(e,n,t,r,o,s,i){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,s,i):n.prototype&&n.prototype.isPureReactComponent?!Nc(t,r)||!Nc(o,s):!0}function B2(e,n,t){var r=!1,o=_s,s=n.contextType;return typeof s=="object"&&s!==null?s=pr(s):(o=Pn(n)?fi:Jt.current,r=n.contextTypes,s=(r=r!=null)?Na(e,o):_s),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Ef,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function HP(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&&Ef.enqueueReplaceState(n,n.state,null)}function MS(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs=z2,G0(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=pr(s):(s=Pn(n)?fi:Jt.current,o.context=Na(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(AS(e,n,s,t),o.state=e.memoizedState),typeof n.getDerivedStateFromProps=="function"||typeof o.getSnapshotBeforeUpdate=="function"||typeof o.UNSAFE_componentWillMount!="function"&&typeof o.componentWillMount!="function"||(n=o.state,typeof o.componentWillMount=="function"&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount=="function"&&o.UNSAFE_componentWillMount(),n!==o.state&&Ef.enqueueReplaceState(o,o.state,null),jp(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function jl(e,n,t){if(e=t.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(t._owner){if(t=t._owner,t){if(t.tag!==1)throw Error(q(309));var r=t.stateNode}if(!r)throw Error(q(147,e));var o=r,s=""+e;return n!==null&&n.ref!==null&&typeof n.ref=="function"&&n.ref._stringRef===s?n.ref:(n=function(i){var a=o.refs;a===z2&&(a=o.refs={}),i===null?delete a[s]:a[s]=i},n._stringRef=s,n)}if(typeof e!="string")throw Error(q(284));if(!t._owner)throw Error(q(290,e))}return e}function Td(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function VP(e){var n=e._init;return n(e._payload)}function U2(e){function n(v,x){if(e){var b=v.deletions;b===null?(v.deletions=[x],v.flags|=16):b.push(x)}}function t(v,x){if(!e)return null;for(;x!==null;)n(v,x),x=x.sibling;return null}function r(v,x){for(v=new Map;x!==null;)x.key!==null?v.set(x.key,x):v.set(x.index,x),x=x.sibling;return v}function o(v,x){return v=Cs(v,x),v.index=0,v.sibling=null,v}function s(v,x,b){return v.index=b,e?(b=v.alternate,b!==null?(b=b.index,b<x?(v.flags|=2,x):b):(v.flags|=2,x)):(v.flags|=1048576,x)}function i(v){return e&&v.alternate===null&&(v.flags|=2),v}function a(v,x,b,P){return x===null||x.tag!==6?(x=Mm(b,v.mode,P),x.return=v,x):(x=o(x,b),x.return=v,x)}function l(v,x,b,P){var E=b.type;return E===la?u(v,x,b.props.children,P,b.key):x!==null&&(x.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===ns&&VP(E)===x.type)?(P=o(x,b.props),P.ref=jl(v,x,b),P.return=v,P):(P=zh(b.type,b.key,b.props,null,v.mode,P),P.ref=jl(v,x,b),P.return=v,P)}function c(v,x,b,P){return x===null||x.tag!==4||x.stateNode.containerInfo!==b.containerInfo||x.stateNode.implementation!==b.implementation?(x=Om(b,v.mode,P),x.return=v,x):(x=o(x,b.children||[]),x.return=v,x)}function u(v,x,b,P,E){return x===null||x.tag!==7?(x=ci(b,v.mode,P,E),x.return=v,x):(x=o(x,b),x.return=v,x)}function d(v,x,b){if(typeof x=="string"&&x!==""||typeof x=="number")return x=Mm(""+x,v.mode,b),x.return=v,x;if(typeof x=="object"&&x!==null){switch(x.$$typeof){case Sd:return b=zh(x.type,x.key,x.props,null,v.mode,b),b.ref=jl(v,null,x),b.return=v,b;case aa:return x=Om(x,v.mode,b),x.return=v,x;case ns:var P=x._init;return d(v,P(x._payload),b)}if(Xl(x)||Al(x))return x=ci(x,v.mode,b,null),x.return=v,x;Td(v,x)}return null}function h(v,x,b,P){var E=x!==null?x.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return E!==null?null:a(v,x,""+b,P);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case Sd:return b.key===E?l(v,x,b,P):null;case aa:return b.key===E?c(v,x,b,P):null;case ns:return E=b._init,h(v,x,E(b._payload),P)}if(Xl(b)||Al(b))return E!==null?null:u(v,x,b,P,null);Td(v,b)}return null}function p(v,x,b,P,E){if(typeof P=="string"&&P!==""||typeof P=="number")return v=v.get(b)||null,a(x,v,""+P,E);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case Sd:return v=v.get(P.key===null?b:P.key)||null,l(x,v,P,E);case aa:return v=v.get(P.key===null?b:P.key)||null,c(x,v,P,E);case ns:var k=P._init;return p(v,x,b,k(P._payload),E)}if(Xl(P)||Al(P))return v=v.get(b)||null,u(x,v,P,E,null);Td(x,P)}return null}function m(v,x,b,P){for(var E=null,k=null,I=x,_=x=0,A=null;I!==null&&_<b.length;_++){I.index>_?(A=I,I=null):A=I.sibling;var T=h(v,I,b[_],P);if(T===null){I===null&&(I=A);break}e&&I&&T.alternate===null&&n(v,I),x=s(T,x,_),k===null?E=T:k.sibling=T,k=T,I=A}if(_===b.length)return t(v,I),tt&&Zs(v,_),E;if(I===null){for(;_<b.length;_++)I=d(v,b[_],P),I!==null&&(x=s(I,x,_),k===null?E=I:k.sibling=I,k=I);return tt&&Zs(v,_),E}for(I=r(v,I);_<b.length;_++)A=p(I,v,_,b[_],P),A!==null&&(e&&A.alternate!==null&&I.delete(A.key===null?_:A.key),x=s(A,x,_),k===null?E=A:k.sibling=A,k=A);return e&&I.forEach(function(D){return n(v,D)}),tt&&Zs(v,_),E}function f(v,x,b,P){var E=Al(b);if(typeof E!="function")throw Error(q(150));if(b=E.call(b),b==null)throw Error(q(151));for(var k=E=null,I=x,_=x=0,A=null,T=b.next();I!==null&&!T.done;_++,T=b.next()){I.index>_?(A=I,I=null):A=I.sibling;var D=h(v,I,T.value,P);if(D===null){I===null&&(I=A);break}e&&I&&D.alternate===null&&n(v,I),x=s(D,x,_),k===null?E=D:k.sibling=D,k=D,I=A}if(T.done)return t(v,I),tt&&Zs(v,_),E;if(I===null){for(;!T.done;_++,T=b.next())T=d(v,T.value,P),T!==null&&(x=s(T,x,_),k===null?E=T:k.sibling=T,k=T);return tt&&Zs(v,_),E}for(I=r(v,I);!T.done;_++,T=b.next())T=p(I,v,_,T.value,P),T!==null&&(e&&T.alternate!==null&&I.delete(T.key===null?_:T.key),x=s(T,x,_),k===null?E=T:k.sibling=T,k=T);return e&&I.forEach(function(L){return n(v,L)}),tt&&Zs(v,_),E}function S(v,x,b,P){if(typeof b=="object"&&b!==null&&b.type===la&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case Sd:e:{for(var E=b.key,k=x;k!==null;){if(k.key===E){if(E=b.type,E===la){if(k.tag===7){t(v,k.sibling),x=o(k,b.props.children),x.return=v,v=x;break e}}else if(k.elementType===E||typeof E=="object"&&E!==null&&E.$$typeof===ns&&VP(E)===k.type){t(v,k.sibling),x=o(k,b.props),x.ref=jl(v,k,b),x.return=v,v=x;break e}t(v,k);break}else n(v,k);k=k.sibling}b.type===la?(x=ci(b.props.children,v.mode,P,b.key),x.return=v,v=x):(P=zh(b.type,b.key,b.props,null,v.mode,P),P.ref=jl(v,x,b),P.return=v,v=P)}return i(v);case aa:e:{for(k=b.key;x!==null;){if(x.key===k)if(x.tag===4&&x.stateNode.containerInfo===b.containerInfo&&x.stateNode.implementation===b.implementation){t(v,x.sibling),x=o(x,b.children||[]),x.return=v,v=x;break e}else{t(v,x);break}else n(v,x);x=x.sibling}x=Om(b,v.mode,P),x.return=v,v=x}return i(v);case ns:return k=b._init,S(v,x,k(b._payload),P)}if(Xl(b))return m(v,x,b,P);if(Al(b))return f(v,x,b,P);Td(v,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,x!==null&&x.tag===6?(t(v,x.sibling),x=o(x,b),x.return=v,v=x):(t(v,x),x=Mm(b,v.mode,P),x.return=v,v=x),i(v)):t(v,x)}return S}var za=U2(!0),H2=U2(!1),_u={},Qr=Fs(_u),Uc=Fs(_u),Hc=Fs(_u);function oi(e){if(e===_u)throw Error(q(174));return e}function Y0(e,n){switch(Ke(Hc,n),Ke(Uc,e),Ke(Qr,_u),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:uS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=uS(n,e)}et(Qr),Ke(Qr,n)}function Ba(){et(Qr),et(Uc),et(Hc)}function V2(e){oi(Hc.current);var n=oi(Qr.current),t=uS(n,e.type);n!==t&&(Ke(Uc,e),Ke(Qr,t))}function X0(e){Uc.current===e&&(et(Qr),et(Uc))}var ot=Fs(0);function Lp(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 km=[];function q0(){for(var e=0;e<km.length;e++)km[e]._workInProgressVersionPrimary=null;km.length=0}var Dh=Wo.ReactCurrentDispatcher,Im=Wo.ReactCurrentBatchConfig,mi=0,at=null,yt=null,xt=null,Np=!1,dc=!1,Vc=0,PW=0;function zt(){throw Error(q(321))}function Z0(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Dr(e[t],n[t]))return!1;return!0}function Q0(e,n,t,r,o,s){if(mi=s,at=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Dh.current=e===null||e.memoizedState===null?IW:_W,e=t(r,o),dc){s=0;do{if(dc=!1,Vc=0,25<=s)throw Error(q(301));s+=1,xt=yt=null,n.updateQueue=null,Dh.current=TW,e=t(r,o)}while(dc)}if(Dh.current=Fp,n=yt!==null&&yt.next!==null,mi=0,xt=yt=at=null,Np=!1,n)throw Error(q(300));return e}function J0(){var e=Vc!==0;return Vc=0,e}function Hr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return xt===null?at.memoizedState=xt=e:xt=xt.next=e,xt}function fr(){if(yt===null){var e=at.alternate;e=e!==null?e.memoizedState:null}else e=yt.next;var n=xt===null?at.memoizedState:xt.next;if(n!==null)xt=n,yt=e;else{if(e===null)throw Error(q(310));yt=e,e={memoizedState:yt.memoizedState,baseState:yt.baseState,baseQueue:yt.baseQueue,queue:yt.queue,next:null},xt===null?at.memoizedState=xt=e:xt=xt.next=e}return xt}function Kc(e,n){return typeof n=="function"?n(e):n}function _m(e){var n=fr(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=yt,o=r.baseQueue,s=t.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,t.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,l=null,c=s;do{var u=c.lane;if((mi&u)===u)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:e(r,c.action);else{var d={lane:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=d,i=r):l=l.next=d,at.lanes|=u,yi|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Dr(r,n.memoizedState)||(wn=!0),n.memoizedState=r,n.baseState=i,n.baseQueue=l,t.lastRenderedState=r}if(e=t.interleaved,e!==null){o=e;do s=o.lane,at.lanes|=s,yi|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function Tm(e){var n=fr(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=t.dispatch,o=t.pending,s=n.memoizedState;if(o!==null){t.pending=null;var i=o=o.next;do s=e(s,i.action),i=i.next;while(i!==o);Dr(s,n.memoizedState)||(wn=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function K2(){}function W2(e,n){var t=at,r=fr(),o=n(),s=!Dr(r.memoizedState,o);if(s&&(r.memoizedState=o,wn=!0),r=r.queue,ew(X2.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||xt!==null&&xt.memoizedState.tag&1){if(t.flags|=2048,Wc(9,Y2.bind(null,t,r,o,n),void 0,null),bt===null)throw Error(q(349));mi&30||G2(t,n,o)}return o}function G2(e,n,t){e.flags|=16384,e={getSnapshot:n,value:t},n=at.updateQueue,n===null?(n={lastEffect:null,stores:null},at.updateQueue=n,n.stores=[e]):(t=n.stores,t===null?n.stores=[e]:t.push(e))}function Y2(e,n,t,r){n.value=t,n.getSnapshot=r,q2(n)&&Z2(e)}function X2(e,n,t){return t(function(){q2(n)&&Z2(e)})}function q2(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Dr(e,t)}catch{return!0}}function Z2(e){var n=jo(e,1);n!==null&&Ar(n,e,1,-1)}function KP(e){var n=Hr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Kc,lastRenderedState:e},n.queue=e,e=e.dispatch=kW.bind(null,at,e),[n.memoizedState,e]}function Wc(e,n,t,r){return e={tag:e,create:n,destroy:t,deps:r,next:null},n=at.updateQueue,n===null?(n={lastEffect:null,stores:null},at.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 Q2(){return fr().memoizedState}function jh(e,n,t,r){var o=Hr();at.flags|=e,o.memoizedState=Wc(1|n,t,void 0,r===void 0?null:r)}function kf(e,n,t,r){var o=fr();r=r===void 0?null:r;var s=void 0;if(yt!==null){var i=yt.memoizedState;if(s=i.destroy,r!==null&&Z0(r,i.deps)){o.memoizedState=Wc(n,t,s,r);return}}at.flags|=e,o.memoizedState=Wc(1|n,t,s,r)}function WP(e,n){return jh(8390656,8,e,n)}function ew(e,n){return kf(2048,8,e,n)}function J2(e,n){return kf(4,2,e,n)}function eT(e,n){return kf(4,4,e,n)}function tT(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 nT(e,n,t){return t=t!=null?t.concat([e]):null,kf(4,4,tT.bind(null,n,e),t)}function tw(){}function rT(e,n){var t=fr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&Z0(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function oT(e,n){var t=fr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&Z0(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function sT(e,n,t){return mi&21?(Dr(t,n)||(t=l2(),at.lanes|=t,yi|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,wn=!0),e.memoizedState=t)}function CW(e,n){var t=De;De=t!==0&&4>t?t:4,e(!0);var r=Im.transition;Im.transition={};try{e(!1),n()}finally{De=t,Im.transition=r}}function iT(){return fr().memoizedState}function EW(e,n,t){var r=Ps(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},aT(e))lT(n,t);else if(t=N2(e,n,t,r),t!==null){var o=an();Ar(t,e,r,o),cT(t,n,r)}}function kW(e,n,t){var r=Ps(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(aT(e))lT(n,o);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=n.lastRenderedReducer,s!==null))try{var i=n.lastRenderedState,a=s(i,t);if(o.hasEagerState=!0,o.eagerState=a,Dr(a,i)){var l=n.interleaved;l===null?(o.next=o,W0(n)):(o.next=l.next,l.next=o),n.interleaved=o;return}}catch{}finally{}t=N2(e,n,o,r),t!==null&&(o=an(),Ar(t,e,r,o),cT(t,n,r))}}function aT(e){var n=e.alternate;return e===at||n!==null&&n===at}function lT(e,n){dc=Np=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function cT(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,M0(e,t)}}var Fp={readContext:pr,useCallback:zt,useContext:zt,useEffect:zt,useImperativeHandle:zt,useInsertionEffect:zt,useLayoutEffect:zt,useMemo:zt,useReducer:zt,useRef:zt,useState:zt,useDebugValue:zt,useDeferredValue:zt,useTransition:zt,useMutableSource:zt,useSyncExternalStore:zt,useId:zt,unstable_isNewReconciler:!1},IW={readContext:pr,useCallback:function(e,n){return Hr().memoizedState=[e,n===void 0?null:n],e},useContext:pr,useEffect:WP,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,jh(4194308,4,tT.bind(null,n,e),t)},useLayoutEffect:function(e,n){return jh(4194308,4,e,n)},useInsertionEffect:function(e,n){return jh(4,2,e,n)},useMemo:function(e,n){var t=Hr();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=Hr();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=EW.bind(null,at,e),[r.memoizedState,e]},useRef:function(e){var n=Hr();return e={current:e},n.memoizedState=e},useState:KP,useDebugValue:tw,useDeferredValue:function(e){return Hr().memoizedState=e},useTransition:function(){var e=KP(!1),n=e[0];return e=CW.bind(null,e[1]),Hr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=at,o=Hr();if(tt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),bt===null)throw Error(q(349));mi&30||G2(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,WP(X2.bind(null,r,s,e),[e]),r.flags|=2048,Wc(9,Y2.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=Hr(),n=bt.identifierPrefix;if(tt){var t=Eo,r=Co;t=(r&~(1<<32-$r(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=Vc++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=PW++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},_W={readContext:pr,useCallback:rT,useContext:pr,useEffect:ew,useImperativeHandle:nT,useInsertionEffect:J2,useLayoutEffect:eT,useMemo:oT,useReducer:_m,useRef:Q2,useState:function(){return _m(Kc)},useDebugValue:tw,useDeferredValue:function(e){var n=fr();return sT(n,yt.memoizedState,e)},useTransition:function(){var e=_m(Kc)[0],n=fr().memoizedState;return[e,n]},useMutableSource:K2,useSyncExternalStore:W2,useId:iT,unstable_isNewReconciler:!1},TW={readContext:pr,useCallback:rT,useContext:pr,useEffect:ew,useImperativeHandle:nT,useInsertionEffect:J2,useLayoutEffect:eT,useMemo:oT,useReducer:Tm,useRef:Q2,useState:function(){return Tm(Kc)},useDebugValue:tw,useDeferredValue:function(e){var n=fr();return yt===null?n.memoizedState=e:sT(n,yt.memoizedState,e)},useTransition:function(){var e=Tm(Kc)[0],n=fr().memoizedState;return[e,n]},useMutableSource:K2,useSyncExternalStore:W2,useId:iT,unstable_isNewReconciler:!1};function Ua(e,n){try{var t="",r=n;do t+=rK(r),r=r.return;while(r);var o=t}catch(s){o=`
184
+ Error generating stack: `+s.message+`
185
+ `+s.stack}return{value:e,source:n,stack:o,digest:null}}function $m(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function OS(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var $W=typeof WeakMap=="function"?WeakMap:Map;function uT(e,n,t){t=$o(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){Bp||(Bp=!0,HS=r),OS(e,n)},t}function dT(e,n,t){t=$o(-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(){OS(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){OS(e,n),typeof r!="function"&&(bs===null?bs=new Set([this]):bs.add(this));var i=n.stack;this.componentDidCatch(n.value,{componentStack:i!==null?i:""})}),t}function GP(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new $W;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=VW.bind(null,e,n,t),n.then(e,e))}function YP(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 XP(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=$o(-1,1),n.tag=2,xs(t,n,1))),t.lanes|=1),e)}var AW=Wo.ReactCurrentOwner,wn=!1;function on(e,n,t,r){n.child=e===null?H2(n,null,t,r):za(n,e.child,t,r)}function qP(e,n,t,r,o){t=t.render;var s=n.ref;return _a(n,o),r=Q0(e,n,t,r,s,o),t=J0(),e!==null&&!wn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Lo(e,n,o)):(tt&&t&&z0(n),n.flags|=1,on(e,n,r,o),n.child)}function ZP(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!cw(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,hT(e,n,s,r,o)):(e=zh(t.type,null,r,n,n.mode,o),e.ref=n.ref,e.return=n,n.child=e)}if(s=e.child,!(e.lanes&o)){var i=s.memoizedProps;if(t=t.compare,t=t!==null?t:Nc,t(i,r)&&e.ref===n.ref)return Lo(e,n,o)}return n.flags|=1,e=Cs(s,r),e.ref=n.ref,e.return=n,n.child=e}function hT(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(Nc(s,r)&&e.ref===n.ref)if(wn=!1,n.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(wn=!0);else return n.lanes=e.lanes,Lo(e,n,o)}return RS(e,n,t,r,o)}function pT(e,n,t){var r=n.pendingProps,o=r.children,s=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ke(Sa,Dn),Dn|=t;else{if(!(t&1073741824))return e=s!==null?s.baseLanes|t:t,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Ke(Sa,Dn),Dn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ke(Sa,Dn),Dn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ke(Sa,Dn),Dn|=r;return on(e,n,o,t),n.child}function fT(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function RS(e,n,t,r,o){var s=Pn(t)?fi:Jt.current;return s=Na(n,s),_a(n,o),t=Q0(e,n,t,r,s,o),r=J0(),e!==null&&!wn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Lo(e,n,o)):(tt&&r&&z0(n),n.flags|=1,on(e,n,t,o),n.child)}function QP(e,n,t,r,o){if(Pn(t)){var s=!0;Ap(n)}else s=!1;if(_a(n,o),n.stateNode===null)Lh(e,n),B2(n,t,r),MS(n,t,r,o),r=!0;else if(e===null){var i=n.stateNode,a=n.memoizedProps;i.props=a;var l=i.context,c=t.contextType;typeof c=="object"&&c!==null?c=pr(c):(c=Pn(t)?fi:Jt.current,c=Na(n,c));var u=t.getDerivedStateFromProps,d=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";d||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&HP(n,i,r,c),rs=!1;var h=n.memoizedState;i.state=h,jp(n,r,i,o),l=n.memoizedState,a!==r||h!==l||bn.current||rs?(typeof u=="function"&&(AS(n,t,u,r),l=n.memoizedState),(a=rs||UP(n,t,a,r,h,l,c))?(d||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(n.flags|=4194308)):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=l),i.props=r,i.state=l,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{i=n.stateNode,F2(e,n),a=n.memoizedProps,c=n.type===n.elementType?a:Sr(n.type,a),i.props=c,d=n.pendingProps,h=i.context,l=t.contextType,typeof l=="object"&&l!==null?l=pr(l):(l=Pn(t)?fi:Jt.current,l=Na(n,l));var p=t.getDerivedStateFromProps;(u=typeof p=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==d||h!==l)&&HP(n,i,r,l),rs=!1,h=n.memoizedState,i.state=h,jp(n,r,i,o);var m=n.memoizedState;a!==d||h!==m||bn.current||rs?(typeof p=="function"&&(AS(n,t,p,r),m=n.memoizedState),(c=rs||UP(n,t,c,r,h,m,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,m,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,m,l)),typeof i.componentDidUpdate=="function"&&(n.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=m),i.props=r,i.state=m,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=1024),r=!1)}return DS(e,n,t,r,s,o)}function DS(e,n,t,r,o,s){fT(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&LP(n,t,!1),Lo(e,n,s);r=n.stateNode,AW.current=n;var a=i&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&i?(n.child=za(n,e.child,null,s),n.child=za(n,null,a,s)):on(e,n,a,s),n.memoizedState=r.state,o&&LP(n,t,!0),n.child}function gT(e){var n=e.stateNode;n.pendingContext?jP(e,n.pendingContext,n.pendingContext!==n.context):n.context&&jP(e,n.context,!1),Y0(e,n.containerInfo)}function JP(e,n,t,r,o){return Fa(),U0(o),n.flags|=256,on(e,n,t,r),n.child}var jS={dehydrated:null,treeContext:null,retryLane:0};function LS(e){return{baseLanes:e,cachePool:null,transitions:null}}function mT(e,n,t){var r=n.pendingProps,o=ot.current,s=!1,i=(n.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(s=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ke(ot,o&1),e===null)return TS(n),e=n.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(n.mode&1?e.data==="$!"?n.lanes=8:n.lanes=1073741824:n.lanes=1,null):(i=r.children,e=r.fallback,s?(r=n.mode,s=n.child,i={mode:"hidden",children:i},!(r&1)&&s!==null?(s.childLanes=0,s.pendingProps=i):s=Tf(i,r,0,null),e=ci(e,r,t,null),s.return=n,e.return=n,s.sibling=e,n.child=s,n.child.memoizedState=LS(t),n.memoizedState=jS,e):nw(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return MW(e,n,i,r,a,o,t);if(s){s=r.fallback,i=n.mode,o=e.child,a=o.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&n.child!==o?(r=n.child,r.childLanes=0,r.pendingProps=l,n.deletions=null):(r=Cs(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Cs(a,s):(s=ci(s,i,t,null),s.flags|=2),s.return=n,r.return=n,r.sibling=s,n.child=r,r=s,s=n.child,i=e.child.memoizedState,i=i===null?LS(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=jS,r}return s=e.child,e=s.sibling,r=Cs(s,{mode:"visible",children:r.children}),!(n.mode&1)&&(r.lanes=t),r.return=n,r.sibling=null,e!==null&&(t=n.deletions,t===null?(n.deletions=[e],n.flags|=16):t.push(e)),n.child=r,n.memoizedState=null,r}function nw(e,n){return n=Tf({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function $d(e,n,t,r){return r!==null&&U0(r),za(n,e.child,null,t),e=nw(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function MW(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=$m(Error(q(422))),$d(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=Tf({mode:"visible",children:r.children},o,0,null),s=ci(s,o,i,null),s.flags|=2,r.return=n,s.return=n,r.sibling=s,n.child=r,n.mode&1&&za(n,e.child,null,i),n.child.memoizedState=LS(i),n.memoizedState=jS,s);if(!(n.mode&1))return $d(e,n,i,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var a=r.dgst;return r=a,s=Error(q(419)),r=$m(s,r,void 0),$d(e,n,i,r)}if(a=(i&e.childLanes)!==0,wn||a){if(r=bt,r!==null){switch(i&-i){case 4:o=2;break;case 16:o=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:o=32;break;case 536870912:o=268435456;break;default:o=0}o=o&(r.suspendedLanes|i)?0:o,o!==0&&o!==s.retryLane&&(s.retryLane=o,jo(e,o),Ar(r,e,o,-1))}return lw(),r=$m(Error(q(421))),$d(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=KW.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,Bn=ws(o.nextSibling),Hn=n,tt=!0,Cr=null,e!==null&&(ar[lr++]=Co,ar[lr++]=Eo,ar[lr++]=gi,Co=e.id,Eo=e.overflow,gi=n),n=nw(n,r.children),n.flags|=4096,n)}function eC(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),$S(e.return,n,t)}function Am(e,n,t,r,o){var s=e.memoizedState;s===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:t,tailMode:o}:(s.isBackwards=n,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=t,s.tailMode=o)}function yT(e,n,t){var r=n.pendingProps,o=r.revealOrder,s=r.tail;if(on(e,n,r.children,t),r=ot.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&&eC(e,t,n);else if(e.tag===19)eC(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(Ke(ot,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&&Lp(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),Am(n,!1,o,t,s);break;case"backwards":for(t=null,o=n.child,n.child=null;o!==null;){if(e=o.alternate,e!==null&&Lp(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}Am(n,!0,t,null,s);break;case"together":Am(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Lh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function Lo(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),yi|=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=Cs(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=Cs(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function OW(e,n,t){switch(n.tag){case 3:gT(n),Fa();break;case 5:V2(n);break;case 1:Pn(n.type)&&Ap(n);break;case 4:Y0(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ke(Rp,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ke(ot,ot.current&1),n.flags|=128,null):t&n.child.childLanes?mT(e,n,t):(Ke(ot,ot.current&1),e=Lo(e,n,t),e!==null?e.sibling:null);Ke(ot,ot.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return yT(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ke(ot,ot.current),r)break;return null;case 22:case 23:return n.lanes=0,pT(e,n,t)}return Lo(e,n,t)}var ST,NS,vT,wT;ST=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}};NS=function(){};vT=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,oi(Qr.current);var s=null;switch(t){case"input":o=iS(e,o),r=iS(e,r),s=[];break;case"select":o=lt({},o,{value:void 0}),r=lt({},r,{value:void 0}),s=[];break;case"textarea":o=cS(e,o),r=cS(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Tp)}dS(t,r);var i;t=null;for(c in o)if(!r.hasOwnProperty(c)&&o.hasOwnProperty(c)&&o[c]!=null)if(c==="style"){var a=o[c];for(i in a)a.hasOwnProperty(i)&&(t||(t={}),t[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Ac.hasOwnProperty(c)?s||(s=[]):(s=s||[]).push(c,null));for(c in r){var l=r[c];if(a=o!=null?o[c]:void 0,r.hasOwnProperty(c)&&l!==a&&(l!=null||a!=null))if(c==="style")if(a){for(i in a)!a.hasOwnProperty(i)||l&&l.hasOwnProperty(i)||(t||(t={}),t[i]="");for(i in l)l.hasOwnProperty(i)&&a[i]!==l[i]&&(t||(t={}),t[i]=l[i])}else t||(s||(s=[]),s.push(c,t)),t=l;else c==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,a=a?a.__html:void 0,l!=null&&a!==l&&(s=s||[]).push(c,l)):c==="children"?typeof l!="string"&&typeof l!="number"||(s=s||[]).push(c,""+l):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(Ac.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&Ze("scroll",e),s||a===l||(s=[])):(s=s||[]).push(c,l))}t&&(s=s||[]).push("style",t);var c=s;(n.updateQueue=c)&&(n.flags|=4)}};wT=function(e,n,t,r){t!==r&&(n.flags|=4)};function Ll(e,n){if(!tt)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 Bt(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 RW(e,n,t){var r=n.pendingProps;switch(B0(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Bt(n),null;case 1:return Pn(n.type)&&$p(),Bt(n),null;case 3:return r=n.stateNode,Ba(),et(bn),et(Jt),q0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(_d(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Cr!==null&&(WS(Cr),Cr=null))),NS(e,n),Bt(n),null;case 5:X0(n);var o=oi(Hc.current);if(t=n.type,e!==null&&n.stateNode!=null)vT(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 Bt(n),null}if(e=oi(Qr.current),_d(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[Wr]=n,r[Bc]=s,e=(n.mode&1)!==0,t){case"dialog":Ze("cancel",r),Ze("close",r);break;case"iframe":case"object":case"embed":Ze("load",r);break;case"video":case"audio":for(o=0;o<Zl.length;o++)Ze(Zl[o],r);break;case"source":Ze("error",r);break;case"img":case"image":case"link":Ze("error",r),Ze("load",r);break;case"details":Ze("toggle",r);break;case"input":cP(r,s),Ze("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Ze("invalid",r);break;case"textarea":dP(r,s),Ze("invalid",r)}dS(t,s),o=null;for(var i in s)if(s.hasOwnProperty(i)){var a=s[i];i==="children"?typeof a=="string"?r.textContent!==a&&(s.suppressHydrationWarning!==!0&&Id(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Id(r.textContent,a,e),o=["children",""+a]):Ac.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Ze("scroll",r)}switch(t){case"input":vd(r),uP(r,s,!0);break;case"textarea":vd(r),hP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Tp)}r=o,n.updateQueue=r,r!==null&&(n.flags|=4)}else{i=o.nodeType===9?o:o.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=G_(t)),e==="http://www.w3.org/1999/xhtml"?t==="script"?(e=i.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(t,{is:r.is}):(e=i.createElement(t),t==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,t),e[Wr]=n,e[Bc]=r,ST(e,n,!1,!1),n.stateNode=e;e:{switch(i=hS(t,r),t){case"dialog":Ze("cancel",e),Ze("close",e),o=r;break;case"iframe":case"object":case"embed":Ze("load",e),o=r;break;case"video":case"audio":for(o=0;o<Zl.length;o++)Ze(Zl[o],e);o=r;break;case"source":Ze("error",e),o=r;break;case"img":case"image":case"link":Ze("error",e),Ze("load",e),o=r;break;case"details":Ze("toggle",e),o=r;break;case"input":cP(e,r),o=iS(e,r),Ze("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=lt({},r,{value:void 0}),Ze("invalid",e);break;case"textarea":dP(e,r),o=cS(e,r),Ze("invalid",e);break;default:o=r}dS(t,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?q_(e,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&Y_(e,l)):s==="children"?typeof l=="string"?(t!=="textarea"||l!=="")&&Mc(e,l):typeof l=="number"&&Mc(e,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Ac.hasOwnProperty(s)?l!=null&&s==="onScroll"&&Ze("scroll",e):l!=null&&k0(e,s,l,i))}switch(t){case"input":vd(e),uP(e,r,!1);break;case"textarea":vd(e),hP(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Is(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?Ca(e,!!r.multiple,s,!1):r.defaultValue!=null&&Ca(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Tp)}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 Bt(n),null;case 6:if(e&&n.stateNode!=null)wT(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=oi(Hc.current),oi(Qr.current),_d(n)){if(r=n.stateNode,t=n.memoizedProps,r[Wr]=n,(s=r.nodeValue!==t)&&(e=Hn,e!==null))switch(e.tag){case 3:Id(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Id(r.nodeValue,t,(e.mode&1)!==0)}s&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[Wr]=n,n.stateNode=r}return Bt(n),null;case 13:if(et(ot),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(tt&&Bn!==null&&n.mode&1&&!(n.flags&128))L2(),Fa(),n.flags|=98560,s=!1;else if(s=_d(n),r!==null&&r.dehydrated!==null){if(e===null){if(!s)throw Error(q(318));if(s=n.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(q(317));s[Wr]=n}else Fa(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Bt(n),s=!1}else Cr!==null&&(WS(Cr),Cr=null),s=!0;if(!s)return n.flags&65536?n:null}return n.flags&128?(n.lanes=t,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||ot.current&1?vt===0&&(vt=3):lw())),n.updateQueue!==null&&(n.flags|=4),Bt(n),null);case 4:return Ba(),NS(e,n),e===null&&Fc(n.stateNode.containerInfo),Bt(n),null;case 10:return K0(n.type._context),Bt(n),null;case 17:return Pn(n.type)&&$p(),Bt(n),null;case 19:if(et(ot),s=n.memoizedState,s===null)return Bt(n),null;if(r=(n.flags&128)!==0,i=s.rendering,i===null)if(r)Ll(s,!1);else{if(vt!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=Lp(e),i!==null){for(n.flags|=128,Ll(s,!1),r=i.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=t,t=n.child;t!==null;)s=t,e=r,s.flags&=14680066,i=s.alternate,i===null?(s.childLanes=0,s.lanes=e,s.child=null,s.subtreeFlags=0,s.memoizedProps=null,s.memoizedState=null,s.updateQueue=null,s.dependencies=null,s.stateNode=null):(s.childLanes=i.childLanes,s.lanes=i.lanes,s.child=i.child,s.subtreeFlags=0,s.deletions=null,s.memoizedProps=i.memoizedProps,s.memoizedState=i.memoizedState,s.updateQueue=i.updateQueue,s.type=i.type,e=i.dependencies,s.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),t=t.sibling;return Ke(ot,ot.current&1|2),n.child}e=e.sibling}s.tail!==null&&ft()>Ha&&(n.flags|=128,r=!0,Ll(s,!1),n.lanes=4194304)}else{if(!r)if(e=Lp(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),Ll(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!tt)return Bt(n),null}else 2*ft()-s.renderingStartTime>Ha&&t!==1073741824&&(n.flags|=128,r=!0,Ll(s,!1),n.lanes=4194304);s.isBackwards?(i.sibling=n.child,n.child=i):(t=s.last,t!==null?t.sibling=i:n.child=i,s.last=i)}return s.tail!==null?(n=s.tail,s.rendering=n,s.tail=n.sibling,s.renderingStartTime=ft(),n.sibling=null,t=ot.current,Ke(ot,r?t&1|2:t&1),n):(Bt(n),null);case 22:case 23:return aw(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Dn&1073741824&&(Bt(n),n.subtreeFlags&6&&(n.flags|=8192)):Bt(n),null;case 24:return null;case 25:return null}throw Error(q(156,n.tag))}function DW(e,n){switch(B0(n),n.tag){case 1:return Pn(n.type)&&$p(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Ba(),et(bn),et(Jt),q0(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return X0(n),null;case 13:if(et(ot),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));Fa()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return et(ot),null;case 4:return Ba(),null;case 10:return K0(n.type._context),null;case 22:case 23:return aw(),null;case 24:return null;default:return null}}var Ad=!1,Gt=!1,jW=typeof WeakSet=="function"?WeakSet:Set,ee=null;function ya(e,n){var t=e.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){ht(e,n,r)}else t.current=null}function FS(e,n,t){try{t()}catch(r){ht(e,n,r)}}var tC=!1;function LW(e,n){if(bS=kp,e=C2(),F0(e)){if("selectionStart"in e)var t={start:e.selectionStart,end:e.selectionEnd};else e:{t=(t=e.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{t.nodeType,s.nodeType}catch{t=null;break e}var i=0,a=-1,l=-1,c=0,u=0,d=e,h=null;t:for(;;){for(var p;d!==t||o!==0&&d.nodeType!==3||(a=i+o),d!==s||r!==0&&d.nodeType!==3||(l=i+r),d.nodeType===3&&(i+=d.nodeValue.length),(p=d.firstChild)!==null;)h=d,d=p;for(;;){if(d===e)break t;if(h===t&&++c===o&&(a=i),h===s&&++u===r&&(l=i),(p=d.nextSibling)!==null)break;d=h,h=d.parentNode}d=p}t=a===-1||l===-1?null:{start:a,end:l}}else t=null}t=t||{start:0,end:0}}else t=null;for(PS={focusedElem:e,selectionRange:t},kp=!1,ee=n;ee!==null;)if(n=ee,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,ee=e;else for(;ee!==null;){n=ee;try{var m=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(m!==null){var f=m.memoizedProps,S=m.memoizedState,v=n.stateNode,x=v.getSnapshotBeforeUpdate(n.elementType===n.type?f:Sr(n.type,f),S);v.__reactInternalSnapshotBeforeUpdate=x}break;case 3:var b=n.stateNode.containerInfo;b.nodeType===1?b.textContent="":b.nodeType===9&&b.documentElement&&b.removeChild(b.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(q(163))}}catch(P){ht(n,n.return,P)}if(e=n.sibling,e!==null){e.return=n.return,ee=e;break}ee=n.return}return m=tC,tC=!1,m}function hc(e,n,t){var r=n.updateQueue;if(r=r!==null?r.lastEffect:null,r!==null){var o=r=r.next;do{if((o.tag&e)===e){var s=o.destroy;o.destroy=void 0,s!==void 0&&FS(n,t,s)}o=o.next}while(o!==r)}}function If(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 zS(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 xT(e){var n=e.alternate;n!==null&&(e.alternate=null,xT(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Wr],delete n[Bc],delete n[kS],delete n[vW],delete n[wW])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function bT(e){return e.tag===5||e.tag===3||e.tag===4}function nC(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||bT(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue e;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function BS(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=Tp));else if(r!==4&&(e=e.child,e!==null))for(BS(e,n,t),e=e.sibling;e!==null;)BS(e,n,t),e=e.sibling}function US(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(US(e,n,t),e=e.sibling;e!==null;)US(e,n,t),e=e.sibling}var _t=null,xr=!1;function es(e,n,t){for(t=t.child;t!==null;)PT(e,n,t),t=t.sibling}function PT(e,n,t){if(Zr&&typeof Zr.onCommitFiberUnmount=="function")try{Zr.onCommitFiberUnmount(vf,t)}catch{}switch(t.tag){case 5:Gt||ya(t,n);case 6:var r=_t,o=xr;_t=null,es(e,n,t),_t=r,xr=o,_t!==null&&(xr?(e=_t,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):_t.removeChild(t.stateNode));break;case 18:_t!==null&&(xr?(e=_t,t=t.stateNode,e.nodeType===8?Cm(e.parentNode,t):e.nodeType===1&&Cm(e,t),jc(e)):Cm(_t,t.stateNode));break;case 4:r=_t,o=xr,_t=t.stateNode.containerInfo,xr=!0,es(e,n,t),_t=r,xr=o;break;case 0:case 11:case 14:case 15:if(!Gt&&(r=t.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){o=r=r.next;do{var s=o,i=s.destroy;s=s.tag,i!==void 0&&(s&2||s&4)&&FS(t,n,i),o=o.next}while(o!==r)}es(e,n,t);break;case 1:if(!Gt&&(ya(t,n),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(a){ht(t,n,a)}es(e,n,t);break;case 21:es(e,n,t);break;case 22:t.mode&1?(Gt=(r=Gt)||t.memoizedState!==null,es(e,n,t),Gt=r):es(e,n,t);break;default:es(e,n,t)}}function rC(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new jW),n.forEach(function(r){var o=WW.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function yr(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var s=e,i=n,a=i;e:for(;a!==null;){switch(a.tag){case 5:_t=a.stateNode,xr=!1;break e;case 3:_t=a.stateNode.containerInfo,xr=!0;break e;case 4:_t=a.stateNode.containerInfo,xr=!0;break e}a=a.return}if(_t===null)throw Error(q(160));PT(s,i,o),_t=null,xr=!1;var l=o.alternate;l!==null&&(l.return=null),o.return=null}catch(c){ht(o,n,c)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)CT(n,e),n=n.sibling}function CT(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(yr(n,e),Br(e),r&4){try{hc(3,e,e.return),If(3,e)}catch(f){ht(e,e.return,f)}try{hc(5,e,e.return)}catch(f){ht(e,e.return,f)}}break;case 1:yr(n,e),Br(e),r&512&&t!==null&&ya(t,t.return);break;case 5:if(yr(n,e),Br(e),r&512&&t!==null&&ya(t,t.return),e.flags&32){var o=e.stateNode;try{Mc(o,"")}catch(f){ht(e,e.return,f)}}if(r&4&&(o=e.stateNode,o!=null)){var s=e.memoizedProps,i=t!==null?t.memoizedProps:s,a=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&K_(o,s),hS(a,i);var c=hS(a,s);for(i=0;i<l.length;i+=2){var u=l[i],d=l[i+1];u==="style"?q_(o,d):u==="dangerouslySetInnerHTML"?Y_(o,d):u==="children"?Mc(o,d):k0(o,u,d,c)}switch(a){case"input":aS(o,s);break;case"textarea":W_(o,s);break;case"select":var h=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var p=s.value;p!=null?Ca(o,!!s.multiple,p,!1):h!==!!s.multiple&&(s.defaultValue!=null?Ca(o,!!s.multiple,s.defaultValue,!0):Ca(o,!!s.multiple,s.multiple?[]:"",!1))}o[Bc]=s}catch(f){ht(e,e.return,f)}}break;case 6:if(yr(n,e),Br(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(f){ht(e,e.return,f)}}break;case 3:if(yr(n,e),Br(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{jc(n.containerInfo)}catch(f){ht(e,e.return,f)}break;case 4:yr(n,e),Br(e);break;case 13:yr(n,e),Br(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(sw=ft())),r&4&&rC(e);break;case 22:if(u=t!==null&&t.memoizedState!==null,e.mode&1?(Gt=(c=Gt)||u,yr(n,e),Gt=c):yr(n,e),Br(e),r&8192){if(c=e.memoizedState!==null,(e.stateNode.isHidden=c)&&!u&&e.mode&1)for(ee=e,u=e.child;u!==null;){for(d=ee=u;ee!==null;){switch(h=ee,p=h.child,h.tag){case 0:case 11:case 14:case 15:hc(4,h,h.return);break;case 1:ya(h,h.return);var m=h.stateNode;if(typeof m.componentWillUnmount=="function"){r=h,t=h.return;try{n=r,m.props=n.memoizedProps,m.state=n.memoizedState,m.componentWillUnmount()}catch(f){ht(r,t,f)}}break;case 5:ya(h,h.return);break;case 22:if(h.memoizedState!==null){sC(d);continue}}p!==null?(p.return=h,ee=p):sC(d)}u=u.sibling}e:for(u=null,d=e;;){if(d.tag===5){if(u===null){u=d;try{o=d.stateNode,c?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=d.stateNode,l=d.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=X_("display",i))}catch(f){ht(e,e.return,f)}}}else if(d.tag===6){if(u===null)try{d.stateNode.nodeValue=c?"":d.memoizedProps}catch(f){ht(e,e.return,f)}}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:yr(n,e),Br(e),r&4&&rC(e);break;case 21:break;default:yr(n,e),Br(e)}}function Br(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(bT(t)){var r=t;break e}t=t.return}throw Error(q(160))}switch(r.tag){case 5:var o=r.stateNode;r.flags&32&&(Mc(o,""),r.flags&=-33);var s=nC(e);US(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=nC(e);BS(e,a,i);break;default:throw Error(q(161))}}catch(l){ht(e,e.return,l)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function NW(e,n,t){ee=e,ET(e)}function ET(e,n,t){for(var r=(e.mode&1)!==0;ee!==null;){var o=ee,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||Ad;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||Gt;a=Ad;var c=Gt;if(Ad=i,(Gt=l)&&!c)for(ee=o;ee!==null;)i=ee,l=i.child,i.tag===22&&i.memoizedState!==null?iC(o):l!==null?(l.return=i,ee=l):iC(o);for(;s!==null;)ee=s,ET(s),s=s.sibling;ee=o,Ad=a,Gt=c}oC(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,ee=s):oC(e)}}function oC(e){for(;ee!==null;){var n=ee;if(n.flags&8772){var t=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:Gt||If(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Gt)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:Sr(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&BP(n,s,r);break;case 3:var i=n.updateQueue;if(i!==null){if(t=null,n.child!==null)switch(n.child.tag){case 5:t=n.child.stateNode;break;case 1:t=n.child.stateNode}BP(n,i,t)}break;case 5:var a=n.stateNode;if(t===null&&n.flags&4){t=a;var l=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&t.focus();break;case"img":l.src&&(t.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var c=n.alternate;if(c!==null){var u=c.memoizedState;if(u!==null){var d=u.dehydrated;d!==null&&jc(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}Gt||n.flags&512&&zS(n)}catch(h){ht(n,n.return,h)}}if(n===e){ee=null;break}if(t=n.sibling,t!==null){t.return=n.return,ee=t;break}ee=n.return}}function sC(e){for(;ee!==null;){var n=ee;if(n===e){ee=null;break}var t=n.sibling;if(t!==null){t.return=n.return,ee=t;break}ee=n.return}}function iC(e){for(;ee!==null;){var n=ee;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{If(4,n)}catch(l){ht(n,t,l)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var o=n.return;try{r.componentDidMount()}catch(l){ht(n,o,l)}}var s=n.return;try{zS(n)}catch(l){ht(n,s,l)}break;case 5:var i=n.return;try{zS(n)}catch(l){ht(n,i,l)}}}catch(l){ht(n,n.return,l)}if(n===e){ee=null;break}var a=n.sibling;if(a!==null){a.return=n.return,ee=a;break}ee=n.return}}var FW=Math.ceil,zp=Wo.ReactCurrentDispatcher,rw=Wo.ReactCurrentOwner,dr=Wo.ReactCurrentBatchConfig,Ce=0,bt=null,mt=null,Lt=0,Dn=0,Sa=Fs(0),vt=0,Gc=null,yi=0,_f=0,ow=0,pc=null,Sn=null,sw=0,Ha=1/0,mo=null,Bp=!1,HS=null,bs=null,Md=!1,ps=null,Up=0,fc=0,VS=null,Nh=-1,Fh=0;function an(){return Ce&6?ft():Nh!==-1?Nh:Nh=ft()}function Ps(e){return e.mode&1?Ce&2&&Lt!==0?Lt&-Lt:bW.transition!==null?(Fh===0&&(Fh=l2()),Fh):(e=De,e!==0||(e=window.event,e=e===void 0?16:g2(e.type)),e):1}function Ar(e,n,t,r){if(50<fc)throw fc=0,VS=null,Error(q(185));Eu(e,t,r),(!(Ce&2)||e!==bt)&&(e===bt&&(!(Ce&2)&&(_f|=t),vt===4&&ls(e,Lt)),Cn(e,r),t===1&&Ce===0&&!(n.mode&1)&&(Ha=ft()+500,Cf&&zs()))}function Cn(e,n){var t=e.callbackNode;bK(e,n);var r=Ep(e,e===bt?Lt:0);if(r===0)t!==null&&gP(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&gP(t),n===1)e.tag===0?xW(aC.bind(null,e)):R2(aC.bind(null,e)),yW(function(){!(Ce&6)&&zs()}),t=null;else{switch(c2(r)){case 1:t=A0;break;case 4:t=i2;break;case 16:t=Cp;break;case 536870912:t=a2;break;default:t=Cp}t=OT(t,kT.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function kT(e,n){if(Nh=-1,Fh=0,Ce&6)throw Error(q(327));var t=e.callbackNode;if(Ta()&&e.callbackNode!==t)return null;var r=Ep(e,e===bt?Lt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=Hp(e,r);else{n=r;var o=Ce;Ce|=2;var s=_T();(bt!==e||Lt!==n)&&(mo=null,Ha=ft()+500,li(e,n));do try{UW();break}catch(a){IT(e,a)}while(!0);V0(),zp.current=s,Ce=o,mt!==null?n=0:(bt=null,Lt=0,n=vt)}if(n!==0){if(n===2&&(o=yS(e),o!==0&&(r=o,n=KS(e,o))),n===1)throw t=Gc,li(e,0),ls(e,r),Cn(e,ft()),t;if(n===6)ls(e,r);else{if(o=e.current.alternate,!(r&30)&&!zW(o)&&(n=Hp(e,r),n===2&&(s=yS(e),s!==0&&(r=s,n=KS(e,s))),n===1))throw t=Gc,li(e,0),ls(e,r),Cn(e,ft()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:Qs(e,Sn,mo);break;case 3:if(ls(e,r),(r&130023424)===r&&(n=sw+500-ft(),10<n)){if(Ep(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){an(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=ES(Qs.bind(null,e,Sn,mo),n);break}Qs(e,Sn,mo);break;case 4:if(ls(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var i=31-$r(r);s=1<<i,i=n[i],i>o&&(o=i),r&=~s}if(r=o,r=ft()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*FW(r/1960))-r,10<r){e.timeoutHandle=ES(Qs.bind(null,e,Sn,mo),r);break}Qs(e,Sn,mo);break;case 5:Qs(e,Sn,mo);break;default:throw Error(q(329))}}}return Cn(e,ft()),e.callbackNode===t?kT.bind(null,e):null}function KS(e,n){var t=pc;return e.current.memoizedState.isDehydrated&&(li(e,n).flags|=256),e=Hp(e,n),e!==2&&(n=Sn,Sn=t,n!==null&&WS(n)),e}function WS(e){Sn===null?Sn=e:Sn.push.apply(Sn,e)}function zW(e){for(var n=e;;){if(n.flags&16384){var t=n.updateQueue;if(t!==null&&(t=t.stores,t!==null))for(var r=0;r<t.length;r++){var o=t[r],s=o.getSnapshot;o=o.value;try{if(!Dr(s(),o))return!1}catch{return!1}}}if(t=n.child,n.subtreeFlags&16384&&t!==null)t.return=n,n=t;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function ls(e,n){for(n&=~ow,n&=~_f,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-$r(n),r=1<<t;e[t]=-1,n&=~r}}function aC(e){if(Ce&6)throw Error(q(327));Ta();var n=Ep(e,0);if(!(n&1))return Cn(e,ft()),null;var t=Hp(e,n);if(e.tag!==0&&t===2){var r=yS(e);r!==0&&(n=r,t=KS(e,r))}if(t===1)throw t=Gc,li(e,0),ls(e,n),Cn(e,ft()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,Qs(e,Sn,mo),Cn(e,ft()),null}function iw(e,n){var t=Ce;Ce|=1;try{return e(n)}finally{Ce=t,Ce===0&&(Ha=ft()+500,Cf&&zs())}}function Si(e){ps!==null&&ps.tag===0&&!(Ce&6)&&Ta();var n=Ce;Ce|=1;var t=dr.transition,r=De;try{if(dr.transition=null,De=1,e)return e()}finally{De=r,dr.transition=t,Ce=n,!(Ce&6)&&zs()}}function aw(){Dn=Sa.current,et(Sa)}function li(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,mW(t)),mt!==null)for(t=mt.return;t!==null;){var r=t;switch(B0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&$p();break;case 3:Ba(),et(bn),et(Jt),q0();break;case 5:X0(r);break;case 4:Ba();break;case 13:et(ot);break;case 19:et(ot);break;case 10:K0(r.type._context);break;case 22:case 23:aw()}t=t.return}if(bt=e,mt=e=Cs(e.current,null),Lt=Dn=n,vt=0,Gc=null,ow=_f=yi=0,Sn=pc=null,ri!==null){for(n=0;n<ri.length;n++)if(t=ri[n],r=t.interleaved,r!==null){t.interleaved=null;var o=r.next,s=t.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}t.pending=r}ri=null}return e}function IT(e,n){do{var t=mt;try{if(V0(),Dh.current=Fp,Np){for(var r=at.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Np=!1}if(mi=0,xt=yt=at=null,dc=!1,Vc=0,rw.current=null,t===null||t.return===null){vt=1,Gc=n,mt=null;break}e:{var s=e,i=t.return,a=t,l=n;if(n=Lt,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,u=a,d=u.tag;if(!(u.mode&1)&&(d===0||d===11||d===15)){var h=u.alternate;h?(u.updateQueue=h.updateQueue,u.memoizedState=h.memoizedState,u.lanes=h.lanes):(u.updateQueue=null,u.memoizedState=null)}var p=YP(i);if(p!==null){p.flags&=-257,XP(p,i,a,s,n),p.mode&1&&GP(s,c,n),n=p,l=c;var m=n.updateQueue;if(m===null){var f=new Set;f.add(l),n.updateQueue=f}else m.add(l);break e}else{if(!(n&1)){GP(s,c,n),lw();break e}l=Error(q(426))}}else if(tt&&a.mode&1){var S=YP(i);if(S!==null){!(S.flags&65536)&&(S.flags|=256),XP(S,i,a,s,n),U0(Ua(l,a));break e}}s=l=Ua(l,a),vt!==4&&(vt=2),pc===null?pc=[s]:pc.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var v=uT(s,l,n);zP(s,v);break e;case 1:a=l;var x=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof x.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(bs===null||!bs.has(b)))){s.flags|=65536,n&=-n,s.lanes|=n;var P=dT(s,a,n);zP(s,P);break e}}s=s.return}while(s!==null)}$T(t)}catch(E){n=E,mt===t&&t!==null&&(mt=t=t.return);continue}break}while(!0)}function _T(){var e=zp.current;return zp.current=Fp,e===null?Fp:e}function lw(){(vt===0||vt===3||vt===2)&&(vt=4),bt===null||!(yi&268435455)&&!(_f&268435455)||ls(bt,Lt)}function Hp(e,n){var t=Ce;Ce|=2;var r=_T();(bt!==e||Lt!==n)&&(mo=null,li(e,n));do try{BW();break}catch(o){IT(e,o)}while(!0);if(V0(),Ce=t,zp.current=r,mt!==null)throw Error(q(261));return bt=null,Lt=0,vt}function BW(){for(;mt!==null;)TT(mt)}function UW(){for(;mt!==null&&!pK();)TT(mt)}function TT(e){var n=MT(e.alternate,e,Dn);e.memoizedProps=e.pendingProps,n===null?$T(e):mt=n,rw.current=null}function $T(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=DW(t,n),t!==null){t.flags&=32767,mt=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{vt=6,mt=null;return}}else if(t=RW(t,n,Dn),t!==null){mt=t;return}if(n=n.sibling,n!==null){mt=n;return}mt=n=e}while(n!==null);vt===0&&(vt=5)}function Qs(e,n,t){var r=De,o=dr.transition;try{dr.transition=null,De=1,HW(e,n,t,r)}finally{dr.transition=o,De=r}return null}function HW(e,n,t,r){do Ta();while(ps!==null);if(Ce&6)throw Error(q(327));t=e.finishedWork;var o=e.finishedLanes;if(t===null)return null;if(e.finishedWork=null,e.finishedLanes=0,t===e.current)throw Error(q(177));e.callbackNode=null,e.callbackPriority=0;var s=t.lanes|t.childLanes;if(PK(e,s),e===bt&&(mt=bt=null,Lt=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||Md||(Md=!0,OT(Cp,function(){return Ta(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=dr.transition,dr.transition=null;var i=De;De=1;var a=Ce;Ce|=4,rw.current=null,LW(e,t),CT(t,e),cW(PS),kp=!!bS,PS=bS=null,e.current=t,NW(t),fK(),Ce=a,De=i,dr.transition=s}else e.current=t;if(Md&&(Md=!1,ps=e,Up=o),s=e.pendingLanes,s===0&&(bs=null),yK(t.stateNode),Cn(e,ft()),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(Bp)throw Bp=!1,e=HS,HS=null,e;return Up&1&&e.tag!==0&&Ta(),s=e.pendingLanes,s&1?e===VS?fc++:(fc=0,VS=e):fc=0,zs(),null}function Ta(){if(ps!==null){var e=c2(Up),n=dr.transition,t=De;try{if(dr.transition=null,De=16>e?16:e,ps===null)var r=!1;else{if(e=ps,ps=null,Up=0,Ce&6)throw Error(q(331));var o=Ce;for(Ce|=4,ee=e.current;ee!==null;){var s=ee,i=s.child;if(ee.flags&16){var a=s.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(ee=c;ee!==null;){var u=ee;switch(u.tag){case 0:case 11:case 15:hc(8,u,s)}var d=u.child;if(d!==null)d.return=u,ee=d;else for(;ee!==null;){u=ee;var h=u.sibling,p=u.return;if(xT(u),u===c){ee=null;break}if(h!==null){h.return=p,ee=h;break}ee=p}}}var m=s.alternate;if(m!==null){var f=m.child;if(f!==null){m.child=null;do{var S=f.sibling;f.sibling=null,f=S}while(f!==null)}}ee=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,ee=i;else e:for(;ee!==null;){if(s=ee,s.flags&2048)switch(s.tag){case 0:case 11:case 15:hc(9,s,s.return)}var v=s.sibling;if(v!==null){v.return=s.return,ee=v;break e}ee=s.return}}var x=e.current;for(ee=x;ee!==null;){i=ee;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,ee=b;else e:for(i=x;ee!==null;){if(a=ee,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:If(9,a)}}catch(E){ht(a,a.return,E)}if(a===i){ee=null;break e}var P=a.sibling;if(P!==null){P.return=a.return,ee=P;break e}ee=a.return}}if(Ce=o,zs(),Zr&&typeof Zr.onPostCommitFiberRoot=="function")try{Zr.onPostCommitFiberRoot(vf,e)}catch{}r=!0}return r}finally{De=t,dr.transition=n}}return!1}function lC(e,n,t){n=Ua(t,n),n=uT(e,n,1),e=xs(e,n,1),n=an(),e!==null&&(Eu(e,1,n),Cn(e,n))}function ht(e,n,t){if(e.tag===3)lC(e,e,t);else for(;n!==null;){if(n.tag===3){lC(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(bs===null||!bs.has(r))){e=Ua(t,e),e=dT(n,e,1),n=xs(n,e,1),e=an(),n!==null&&(Eu(n,1,e),Cn(n,e));break}}n=n.return}}function VW(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=an(),e.pingedLanes|=e.suspendedLanes&t,bt===e&&(Lt&t)===t&&(vt===4||vt===3&&(Lt&130023424)===Lt&&500>ft()-sw?li(e,0):ow|=t),Cn(e,n)}function AT(e,n){n===0&&(e.mode&1?(n=bd,bd<<=1,!(bd&130023424)&&(bd=4194304)):n=1);var t=an();e=jo(e,n),e!==null&&(Eu(e,n,t),Cn(e,t))}function KW(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),AT(e,t)}function WW(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),AT(e,t)}var MT;MT=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||bn.current)wn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return wn=!1,OW(e,n,t);wn=!!(e.flags&131072)}else wn=!1,tt&&n.flags&1048576&&D2(n,Op,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Lh(e,n),e=n.pendingProps;var o=Na(n,Jt.current);_a(n,t),o=Q0(null,n,r,e,o,t);var s=J0();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,Pn(r)?(s=!0,Ap(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,G0(n),o.updater=Ef,n.stateNode=o,o._reactInternals=n,MS(n,r,e,t),n=DS(null,n,r,!0,s,t)):(n.tag=0,tt&&s&&z0(n),on(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(Lh(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=YW(r),e=Sr(r,e),o){case 0:n=RS(null,n,r,e,t);break e;case 1:n=QP(null,n,r,e,t);break e;case 11:n=qP(null,n,r,e,t);break e;case 14:n=ZP(null,n,r,Sr(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:Sr(r,o),RS(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Sr(r,o),QP(e,n,r,o,t);case 3:e:{if(gT(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,F2(e,n),jp(n,r,null,t);var i=n.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},n.updateQueue.baseState=s,n.memoizedState=s,n.flags&256){o=Ua(Error(q(423)),n),n=JP(e,n,r,t,o);break e}else if(r!==o){o=Ua(Error(q(424)),n),n=JP(e,n,r,t,o);break e}else for(Bn=ws(n.stateNode.containerInfo.firstChild),Hn=n,tt=!0,Cr=null,t=H2(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(Fa(),r===o){n=Lo(e,n,t);break e}on(e,n,r,t)}n=n.child}return n;case 5:return V2(n),e===null&&TS(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,CS(r,o)?i=null:s!==null&&CS(r,s)&&(n.flags|=32),fT(e,n),on(e,n,i,t),n.child;case 6:return e===null&&TS(n),null;case 13:return mT(e,n,t);case 4:return Y0(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=za(n,null,r,t):on(e,n,r,t),n.child;case 11:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Sr(r,o),qP(e,n,r,o,t);case 7:return on(e,n,n.pendingProps,t),n.child;case 8:return on(e,n,n.pendingProps.children,t),n.child;case 12:return on(e,n,n.pendingProps.children,t),n.child;case 10:e:{if(r=n.type._context,o=n.pendingProps,s=n.memoizedProps,i=o.value,Ke(Rp,r._currentValue),r._currentValue=i,s!==null)if(Dr(s.value,i)){if(s.children===o.children&&!bn.current){n=Lo(e,n,t);break e}}else for(s=n.child,s!==null&&(s.return=n);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var l=a.firstContext;l!==null;){if(l.context===r){if(s.tag===1){l=$o(-1,t&-t),l.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var u=c.pending;u===null?l.next=l:(l.next=u.next,u.next=l),c.pending=l}}s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),$S(s.return,t,n),a.lanes|=t;break}l=l.next}}else if(s.tag===10)i=s.type===n.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(q(341));i.lanes|=t,a=i.alternate,a!==null&&(a.lanes|=t),$S(i,t,n),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===n){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}on(e,n,o.children,t),n=n.child}return n;case 9:return o=n.type,r=n.pendingProps.children,_a(n,t),o=pr(o),r=r(o),n.flags|=1,on(e,n,r,t),n.child;case 14:return r=n.type,o=Sr(r,n.pendingProps),o=Sr(r.type,o),ZP(e,n,r,o,t);case 15:return hT(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:Sr(r,o),Lh(e,n),n.tag=1,Pn(r)?(e=!0,Ap(n)):e=!1,_a(n,t),B2(n,r,o),MS(n,r,o,t),DS(null,n,r,!0,e,t);case 19:return yT(e,n,t);case 22:return pT(e,n,t)}throw Error(q(156,n.tag))};function OT(e,n){return s2(e,n)}function GW(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 cr(e,n,t,r){return new GW(e,n,t,r)}function cw(e){return e=e.prototype,!(!e||!e.isReactComponent)}function YW(e){if(typeof e=="function")return cw(e)?1:0;if(e!=null){if(e=e.$$typeof,e===_0)return 11;if(e===T0)return 14}return 2}function Cs(e,n){var t=e.alternate;return t===null?(t=cr(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 zh(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")cw(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case la:return ci(t.children,o,s,n);case I0:i=8,o|=8;break;case nS:return e=cr(12,t,n,o|2),e.elementType=nS,e.lanes=s,e;case rS:return e=cr(13,t,n,o),e.elementType=rS,e.lanes=s,e;case oS:return e=cr(19,t,n,o),e.elementType=oS,e.lanes=s,e;case U_:return Tf(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case z_:i=10;break e;case B_:i=9;break e;case _0:i=11;break e;case T0:i=14;break e;case ns:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=cr(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function ci(e,n,t,r){return e=cr(7,e,r,n),e.lanes=t,e}function Tf(e,n,t,r){return e=cr(22,e,r,n),e.elementType=U_,e.lanes=t,e.stateNode={isHidden:!1},e}function Mm(e,n,t){return e=cr(6,e,null,n),e.lanes=t,e}function Om(e,n,t){return n=cr(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function XW(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=pm(0),this.expirationTimes=pm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=pm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function uw(e,n,t,r,o,s,i,a,l){return e=new XW(e,n,t,a,l),n===1?(n=1,s===!0&&(n|=8)):n=0,s=cr(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},G0(s),e}function qW(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:aa,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function RT(e){if(!e)return _s;e=e._reactInternals;e:{if(Ti(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(Pn(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(Pn(t))return O2(e,t,n)}return n}function DT(e,n,t,r,o,s,i,a,l){return e=uw(t,r,!0,e,o,s,i,a,l),e.context=RT(null),t=e.current,r=an(),o=Ps(t),s=$o(r,o),s.callback=n??null,xs(t,s,o),e.current.lanes=o,Eu(e,o,r),Cn(e,r),e}function $f(e,n,t,r){var o=n.current,s=an(),i=Ps(o);return t=RT(t),n.context===null?n.context=t:n.pendingContext=t,n=$o(s,i),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=xs(o,n,i),e!==null&&(Ar(e,o,i,s),Rh(e,o,i)),i}function Vp(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 cC(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function dw(e,n){cC(e,n),(e=e.alternate)&&cC(e,n)}function ZW(){return null}var jT=typeof reportError=="function"?reportError:function(e){console.error(e)};function hw(e){this._internalRoot=e}Af.prototype.render=hw.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));$f(e,n,null,null)};Af.prototype.unmount=hw.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Si(function(){$f(null,e,null,null)}),n[Do]=null}};function Af(e){this._internalRoot=e}Af.prototype.unstable_scheduleHydration=function(e){if(e){var n=h2();e={blockedOn:null,target:e,priority:n};for(var t=0;t<as.length&&n!==0&&n<as[t].priority;t++);as.splice(t,0,e),t===0&&f2(e)}};function pw(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Mf(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function uC(){}function QW(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=Vp(i);s.call(c)}}var i=DT(n,r,e,0,null,!1,!1,"",uC);return e._reactRootContainer=i,e[Do]=i.current,Fc(e.nodeType===8?e.parentNode:e),Si(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=Vp(l);a.call(c)}}var l=uw(e,0,!1,null,null,!1,!1,"",uC);return e._reactRootContainer=l,e[Do]=l.current,Fc(e.nodeType===8?e.parentNode:e),Si(function(){$f(n,l,t,r)}),l}function Of(e,n,t,r,o){var s=t._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var l=Vp(i);a.call(l)}}$f(n,i,e,o)}else i=QW(t,n,e,o,r);return Vp(i)}u2=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=ql(n.pendingLanes);t!==0&&(M0(n,t|1),Cn(n,ft()),!(Ce&6)&&(Ha=ft()+500,zs()))}break;case 13:Si(function(){var r=jo(e,1);if(r!==null){var o=an();Ar(r,e,1,o)}}),dw(e,1)}};O0=function(e){if(e.tag===13){var n=jo(e,134217728);if(n!==null){var t=an();Ar(n,e,134217728,t)}dw(e,134217728)}};d2=function(e){if(e.tag===13){var n=Ps(e),t=jo(e,n);if(t!==null){var r=an();Ar(t,e,n,r)}dw(e,n)}};h2=function(){return De};p2=function(e,n){var t=De;try{return De=e,n()}finally{De=t}};fS=function(e,n,t){switch(n){case"input":if(aS(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=Pf(r);if(!o)throw Error(q(90));V_(r),aS(r,o)}}}break;case"textarea":W_(e,t);break;case"select":n=t.value,n!=null&&Ca(e,!!t.multiple,n,!1)}};J_=iw;e2=Si;var JW={usingClientEntryPoint:!1,Events:[Iu,ha,Pf,Z_,Q_,iw]},Nl={findFiberByHostInstance:ni,bundleType:0,version:"18.2.0",rendererPackageName:"react-dom"},eG={bundleType:Nl.bundleType,version:Nl.version,rendererPackageName:Nl.rendererPackageName,rendererConfig:Nl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Wo.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=r2(e),e===null?null:e.stateNode},findFiberByHostInstance:Nl.findFiberByHostInstance||ZW,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.2.0-next-9e3b772b8-20220608"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Od=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Od.isDisabled&&Od.supportsFiber)try{vf=Od.inject(eG),Zr=Od}catch{}}qn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=JW;qn.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!pw(n))throw Error(q(200));return qW(e,n,null,t)};qn.createRoot=function(e,n){if(!pw(e))throw Error(q(299));var t=!1,r="",o=jT;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=uw(e,1,!1,null,null,t,!1,r,o),e[Do]=n.current,Fc(e.nodeType===8?e.parentNode:e),new hw(n)};qn.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=r2(n),e=e===null?null:e.stateNode,e};qn.flushSync=function(e){return Si(e)};qn.hydrate=function(e,n,t){if(!Mf(n))throw Error(q(200));return Of(null,e,n,!0,t)};qn.hydrateRoot=function(e,n,t){if(!pw(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=jT;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=DT(n,null,e,1,t??null,o,!1,s,i),e[Do]=n.current,Fc(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 Af(n)};qn.render=function(e,n,t){if(!Mf(n))throw Error(q(200));return Of(null,e,n,!1,t)};qn.unmountComponentAtNode=function(e){if(!Mf(e))throw Error(q(40));return e._reactRootContainer?(Si(function(){Of(null,null,e,!1,function(){e._reactRootContainer=null,e[Do]=null})}),!0):!1};qn.unstable_batchedUpdates=iw;qn.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!Mf(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return Of(e,n,t,!1,r)};qn.version="18.2.0-next-9e3b772b8-20220608";function LT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(LT)}catch(e){console.error(e)}}LT(),D_.exports=qn;var ll=D_.exports;const tG=Ka(ll);function se(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 nG(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function Rf(...e){return n=>e.forEach(t=>nG(t,n))}function Ge(...e){return w.useCallback(Rf(...e),e)}function io(e,n=[]){let t=[];function r(s,i){const a=w.createContext(i),l=t.length;t=[...t,i];function c(d){const{scope:h,children:p,...m}=d,f=(h==null?void 0:h[e][l])||a,S=w.useMemo(()=>m,Object.values(m));return w.createElement(f.Provider,{value:S},p)}function u(d,h){const p=(h==null?void 0:h[e][l])||a,m=w.useContext(p);if(m)return m;if(i!==void 0)return i;throw new Error(`\`${d}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,u]}const o=()=>{const s=t.map(i=>w.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return w.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,rG(o,...n)]}function rG(...e){const n=e[0];if(e.length===1)return n;const t=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const d=l(s)[`__scope${c}`];return{...a,...d}},{});return w.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return t.scopeName=n.scopeName,t}const vi=w.forwardRef((e,n)=>{const{children:t,...r}=e,o=w.Children.toArray(t),s=o.find(sG);if(s){const i=s.props.children,a=o.map(l=>l===s?w.Children.count(i)>1?w.Children.only(null):w.isValidElement(i)?i.props.children:null:l);return w.createElement(GS,Q({},r,{ref:n}),w.isValidElement(i)?w.cloneElement(i,void 0,a):null)}return w.createElement(GS,Q({},r,{ref:n}),t)});vi.displayName="Slot";const GS=w.forwardRef((e,n)=>{const{children:t,...r}=e;return w.isValidElement(t)?w.cloneElement(t,{...iG(r,t.props),ref:n?Rf(n,t.ref):t.ref}):w.Children.count(t)>1?w.Children.only(null):null});GS.displayName="SlotClone";const oG=({children:e})=>w.createElement(w.Fragment,null,e);function sG(e){return w.isValidElement(e)&&e.type===oG}function iG(e,n){const t={...n};for(const r in n){const o=e[r],s=n[r];/^on[A-Z]/.test(r)?o&&s?t[r]=(...a)=>{s(...a),o(...a)}:o&&(t[r]=o):r==="style"?t[r]={...o,...s}:r==="className"&&(t[r]=[o,s].filter(Boolean).join(" "))}return{...e,...t}}function Df(e){const n=e+"CollectionProvider",[t,r]=io(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:m,children:f}=p,S=ne.useRef(null),v=ne.useRef(new Map).current;return ne.createElement(o,{scope:m,itemMap:v,collectionRef:S},f)},a=e+"CollectionSlot",l=ne.forwardRef((p,m)=>{const{scope:f,children:S}=p,v=s(a,f),x=Ge(m,v.collectionRef);return ne.createElement(vi,{ref:x},S)}),c=e+"CollectionItemSlot",u="data-radix-collection-item",d=ne.forwardRef((p,m)=>{const{scope:f,children:S,...v}=p,x=ne.useRef(null),b=Ge(m,x),P=s(c,f);return ne.useEffect(()=>(P.itemMap.set(x,{ref:x,...v}),()=>void P.itemMap.delete(x))),ne.createElement(vi,{[u]:"",ref:b},S)});function h(p){const m=s(e+"CollectionConsumer",p);return ne.useCallback(()=>{const S=m.collectionRef.current;if(!S)return[];const v=Array.from(S.querySelectorAll(`[${u}]`));return Array.from(m.itemMap.values()).sort((P,E)=>v.indexOf(P.ref.current)-v.indexOf(E.ref.current))},[m.collectionRef,m.itemMap])}return[{Provider:i,Slot:l,ItemSlot:d},h,r]}const aG=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],ze=aG.reduce((e,n)=>{const t=w.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?vi:n;return w.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),w.createElement(a,Q({},i,{ref:o}))});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function fw(e,n){e&&ll.flushSync(()=>e.dispatchEvent(n))}function en(e){const n=w.useRef(e);return w.useEffect(()=>{n.current=e}),w.useMemo(()=>(...t)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...t)},[])}function lG(e,n=globalThis==null?void 0:globalThis.document){const t=en(e);w.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r),()=>n.removeEventListener("keydown",r)},[t,n])}const YS="dismissableLayer.update",cG="dismissableLayer.pointerDownOutside",uG="dismissableLayer.focusOutside";let dC;const NT=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),jf=w.forwardRef((e,n)=>{var t;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:a,onDismiss:l,...c}=e,u=w.useContext(NT),[d,h]=w.useState(null),p=(t=d==null?void 0:d.ownerDocument)!==null&&t!==void 0?t:globalThis==null?void 0:globalThis.document,[,m]=w.useState({}),f=Ge(n,_=>h(_)),S=Array.from(u.layers),[v]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),x=S.indexOf(v),b=d?S.indexOf(d):-1,P=u.layersWithOutsidePointerEventsDisabled.size>0,E=b>=x,k=hG(_=>{const A=_.target,T=[...u.branches].some(D=>D.contains(A));!E||T||(s==null||s(_),a==null||a(_),_.defaultPrevented||l==null||l())},p),I=pG(_=>{const A=_.target;[...u.branches].some(D=>D.contains(A))||(i==null||i(_),a==null||a(_),_.defaultPrevented||l==null||l())},p);return lG(_=>{b===u.layers.size-1&&(o==null||o(_),!_.defaultPrevented&&l&&(_.preventDefault(),l()))},p),w.useEffect(()=>{if(d)return r&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(dC=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),hC(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=dC)}},[d,p,r,u]),w.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),hC())},[d,u]),w.useEffect(()=>{const _=()=>m({});return document.addEventListener(YS,_),()=>document.removeEventListener(YS,_)},[]),w.createElement(ze.div,Q({},c,{ref:f,style:{pointerEvents:P?E?"auto":"none":void 0,...e.style},onFocusCapture:se(e.onFocusCapture,I.onFocusCapture),onBlurCapture:se(e.onBlurCapture,I.onBlurCapture),onPointerDownCapture:se(e.onPointerDownCapture,k.onPointerDownCapture)}))}),dG=w.forwardRef((e,n)=>{const t=w.useContext(NT),r=w.useRef(null),o=Ge(n,r);return w.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),w.createElement(ze.div,Q({},e,{ref:o}))});function hG(e,n=globalThis==null?void 0:globalThis.document){const t=en(e),r=w.useRef(!1),o=w.useRef(()=>{});return w.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let u=function(){FT(cG,t,c,{discrete:!0})};var l=u;const c={originalEvent:a};a.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=u,n.addEventListener("click",o.current,{once:!0})):u()}else n.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{n.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),n.removeEventListener("pointerdown",s),n.removeEventListener("click",o.current)}},[n,t]),{onPointerDownCapture:()=>r.current=!0}}function pG(e,n=globalThis==null?void 0:globalThis.document){const t=en(e),r=w.useRef(!1);return w.useEffect(()=>{const o=s=>{s.target&&!r.current&&FT(uG,t,{originalEvent:s},{discrete:!1})};return n.addEventListener("focusin",o),()=>n.removeEventListener("focusin",o)},[n,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function hC(){const e=new CustomEvent(YS);document.dispatchEvent(e)}function FT(e,n,t,{discrete:r}){const o=t.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?fw(o,s):o.dispatchEvent(s)}const fG=jf,gG=dG,Lf=w.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?tG.createPortal(w.createElement(ze.div,Q({},o,{ref:n})),r):null}),wi=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{};function mG(e,n){return w.useReducer((t,r)=>{const o=n[t][r];return o??t},e)}const Lr=e=>{const{present:n,children:t}=e,r=yG(n),o=typeof t=="function"?t({present:r.isPresent}):w.Children.only(t),s=Ge(r.ref,o.ref);return typeof t=="function"||r.isPresent?w.cloneElement(o,{ref:s}):null};Lr.displayName="Presence";function yG(e){const[n,t]=w.useState(),r=w.useRef({}),o=w.useRef(e),s=w.useRef("none"),i=e?"mounted":"unmounted",[a,l]=mG(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=Rd(r.current);s.current=a==="mounted"?c:"none"},[a]),wi(()=>{const c=r.current,u=o.current;if(u!==e){const h=s.current,p=Rd(c);e?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&h!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),wi(()=>{if(n){const c=d=>{const p=Rd(r.current).includes(d.animationName);d.target===n&&p&&ll.flushSync(()=>l("ANIMATION_END"))},u=d=>{d.target===n&&(s.current=Rd(r.current))};return n.addEventListener("animationstart",u),n.addEventListener("animationcancel",c),n.addEventListener("animationend",c),()=>{n.removeEventListener("animationstart",u),n.removeEventListener("animationcancel",c),n.removeEventListener("animationend",c)}}else l("ANIMATION_END")},[n,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:w.useCallback(c=>{c&&(r.current=getComputedStyle(c)),t(c)},[])}}function Rd(e){return(e==null?void 0:e.animationName)||"none"}function Bs({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=SG({defaultProp:n,onChange:t}),s=e!==void 0,i=s?e:r,a=en(t),l=w.useCallback(c=>{if(s){const d=typeof c=="function"?c(e):c;d!==e&&a(d)}else o(c)},[s,e,o,a]);return[i,l]}function SG({defaultProp:e,onChange:n}){const t=w.useState(e),[r]=t,o=w.useRef(r),s=en(n);return w.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),t}const zT=w.forwardRef((e,n)=>w.createElement(ze.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}}))),BT="ToastProvider",[gw,vG,wG]=Df("Toast"),[UT,gte]=io("Toast",[wG]),[xG,Nf]=UT(BT),HT=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=w.useState(null),[c,u]=w.useState(0),d=w.useRef(!1),h=w.useRef(!1);return w.createElement(gw.Provider,{scope:n},w.createElement(xG,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:w.useCallback(()=>u(p=>p+1),[]),onToastRemove:w.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:d,isClosePausedRef:h},i))};HT.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const n=`Invalid prop \`label\` supplied to \`${BT}\`. Expected non-empty \`string\`.`;return new Error(n)}return null}};const bG="ToastViewport",PG=["F8"],XS="toast.viewportPause",qS="toast.viewportResume",CG=w.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=PG,label:o="Notifications ({hotkey})",...s}=e,i=Nf(bG,t),a=vG(t),l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),d=w.useRef(null),h=Ge(n,d,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),m=i.toastCount>0;w.useEffect(()=>{const S=v=>{var x;r.every(P=>v[P]||v.code===P)&&((x=d.current)===null||x===void 0||x.focus())};return document.addEventListener("keydown",S),()=>document.removeEventListener("keydown",S)},[r]),w.useEffect(()=>{const S=l.current,v=d.current;if(m&&S&&v){const x=()=>{if(!i.isClosePausedRef.current){const k=new CustomEvent(XS);v.dispatchEvent(k),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const k=new CustomEvent(qS);v.dispatchEvent(k),i.isClosePausedRef.current=!1}},P=k=>{!S.contains(k.relatedTarget)&&b()},E=()=>{S.contains(document.activeElement)||b()};return S.addEventListener("focusin",x),S.addEventListener("focusout",P),S.addEventListener("pointermove",x),S.addEventListener("pointerleave",E),window.addEventListener("blur",x),window.addEventListener("focus",b),()=>{S.removeEventListener("focusin",x),S.removeEventListener("focusout",P),S.removeEventListener("pointermove",x),S.removeEventListener("pointerleave",E),window.removeEventListener("blur",x),window.removeEventListener("focus",b)}}},[m,i.isClosePausedRef]);const f=w.useCallback(({tabbingDirection:S})=>{const x=a().map(b=>{const P=b.ref.current,E=[P,...zG(P)];return S==="forwards"?E:E.reverse()});return(S==="forwards"?x.reverse():x).flat()},[a]);return w.useEffect(()=>{const S=d.current;if(S){const v=x=>{const b=x.altKey||x.ctrlKey||x.metaKey;if(x.key==="Tab"&&!b){const _=document.activeElement,A=x.shiftKey;if(x.target===S&&A){var E;(E=c.current)===null||E===void 0||E.focus();return}const L=f({tabbingDirection:A?"backwards":"forwards"}),z=L.findIndex(j=>j===_);if(Rm(L.slice(z+1)))x.preventDefault();else{var k,I;A?(k=c.current)===null||k===void 0||k.focus():(I=u.current)===null||I===void 0||I.focus()}}};return S.addEventListener("keydown",v),()=>S.removeEventListener("keydown",v)}},[a,f]),w.createElement(gG,{ref:l,role:"region","aria-label":o.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:m?void 0:"none"}},m&&w.createElement(pC,{ref:c,onFocusFromOutsideViewport:()=>{const S=f({tabbingDirection:"forwards"});Rm(S)}}),w.createElement(gw.Slot,{scope:t},w.createElement(ze.ol,Q({tabIndex:-1},s,{ref:h}))),m&&w.createElement(pC,{ref:u,onFocusFromOutsideViewport:()=>{const S=f({tabbingDirection:"backwards"});Rm(S)}}))}),EG="ToastFocusProxy",pC=w.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=Nf(EG,t);return w.createElement(zT,Q({"aria-hidden":!0,tabIndex:0},o,{ref:n,style:{position:"fixed"},onFocus:i=>{var a;const l=i.relatedTarget;!((a=s.viewport)!==null&&a!==void 0&&a.contains(l))&&r()}}))}),Ff="Toast",kG="toast.swipeStart",IG="toast.swipeMove",_G="toast.swipeCancel",TG="toast.swipeEnd",$G=w.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,l]=Bs({prop:r,defaultProp:o,onChange:s});return w.createElement(Lr,{present:t||a},w.createElement(VT,Q({open:a},i,{ref:n,onClose:()=>l(!1),onPause:en(e.onPause),onResume:en(e.onResume),onSwipeStart:se(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:se(e.onSwipeMove,c=>{const{x:u,y:d}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${d}px`)}),onSwipeCancel:se(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:se(e.onSwipeEnd,c=>{const{x:u,y:d}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${d}px`),l(!1)})})))}),[AG,MG]=UT(Ff,{onClose(){}}),VT=w.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:d,onSwipeCancel:h,onSwipeEnd:p,...m}=e,f=Nf(Ff,t),[S,v]=w.useState(null),x=Ge(n,j=>v(j)),b=w.useRef(null),P=w.useRef(null),E=o||f.duration,k=w.useRef(0),I=w.useRef(E),_=w.useRef(0),{onToastAdd:A,onToastRemove:T}=f,D=en(()=>{var j;(S==null?void 0:S.contains(document.activeElement))&&((j=f.viewport)===null||j===void 0||j.focus()),i()}),L=w.useCallback(j=>{!j||j===1/0||(window.clearTimeout(_.current),k.current=new Date().getTime(),_.current=window.setTimeout(D,j))},[D]);w.useEffect(()=>{const j=f.viewport;if(j){const F=()=>{L(I.current),c==null||c()},Y=()=>{const K=new Date().getTime()-k.current;I.current=I.current-K,window.clearTimeout(_.current),l==null||l()};return j.addEventListener(XS,Y),j.addEventListener(qS,F),()=>{j.removeEventListener(XS,Y),j.removeEventListener(qS,F)}}},[f.viewport,E,l,c,L]),w.useEffect(()=>{s&&!f.isClosePausedRef.current&&L(E)},[s,E,f.isClosePausedRef,L]),w.useEffect(()=>(A(),()=>T()),[A,T]);const z=w.useMemo(()=>S?YT(S):null,[S]);return f.viewport?w.createElement(w.Fragment,null,z&&w.createElement(OG,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},z),w.createElement(AG,{scope:t,onClose:D},ll.createPortal(w.createElement(gw.ItemSlot,{scope:t},w.createElement(fG,{asChild:!0,onEscapeKeyDown:se(a,()=>{f.isFocusedToastEscapeKeyDownRef.current||D(),f.isFocusedToastEscapeKeyDownRef.current=!1})},w.createElement(ze.li,Q({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":f.swipeDirection},m,{ref:x,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:se(e.onKeyDown,j=>{j.key==="Escape"&&(a==null||a(j.nativeEvent),j.nativeEvent.defaultPrevented||(f.isFocusedToastEscapeKeyDownRef.current=!0,D()))}),onPointerDown:se(e.onPointerDown,j=>{j.button===0&&(b.current={x:j.clientX,y:j.clientY})}),onPointerMove:se(e.onPointerMove,j=>{if(!b.current)return;const F=j.clientX-b.current.x,Y=j.clientY-b.current.y,K=!!P.current,H=["left","right"].includes(f.swipeDirection),B=["left","up"].includes(f.swipeDirection)?Math.min:Math.max,V=H?B(0,F):0,X=H?0:B(0,Y),ae=j.pointerType==="touch"?10:2,ye={x:V,y:X},Ie={originalEvent:j,delta:ye};K?(P.current=ye,Dd(IG,d,Ie,{discrete:!1})):fC(ye,f.swipeDirection,ae)?(P.current=ye,Dd(kG,u,Ie,{discrete:!1}),j.target.setPointerCapture(j.pointerId)):(Math.abs(F)>ae||Math.abs(Y)>ae)&&(b.current=null)}),onPointerUp:se(e.onPointerUp,j=>{const F=P.current,Y=j.target;if(Y.hasPointerCapture(j.pointerId)&&Y.releasePointerCapture(j.pointerId),P.current=null,b.current=null,F){const K=j.currentTarget,H={originalEvent:j,delta:F};fC(F,f.swipeDirection,f.swipeThreshold)?Dd(TG,p,H,{discrete:!0}):Dd(_G,h,H,{discrete:!0}),K.addEventListener("click",B=>B.preventDefault(),{once:!0})}})})))),f.viewport))):null});VT.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const n=`Invalid prop \`type\` supplied to \`${Ff}\`. Expected \`foreground | background\`.`;return new Error(n)}return null}};const OG=e=>{const{__scopeToast:n,children:t,...r}=e,o=Nf(Ff,n),[s,i]=w.useState(!1),[a,l]=w.useState(!1);return NG(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:w.createElement(Lf,{asChild:!0},w.createElement(zT,r,s&&w.createElement(w.Fragment,null,o.label," ",t)))},RG=w.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return w.createElement(ze.div,Q({},r,{ref:n}))}),DG=w.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return w.createElement(ze.div,Q({},r,{ref:n}))}),jG="ToastAction",KT=w.forwardRef((e,n)=>{const{altText:t,...r}=e;return t?w.createElement(GT,{altText:t,asChild:!0},w.createElement(WT,Q({},r,{ref:n}))):null});KT.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${jG}\``)}};const LG="ToastClose",WT=w.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=MG(LG,t);return w.createElement(GT,{asChild:!0},w.createElement(ze.button,Q({type:"button"},r,{ref:n,onClick:se(e.onClick,o.onClose)})))}),GT=w.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return w.createElement(ze.div,Q({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0},o,{ref:n}))});function YT(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),FG(r)){const o=r.ariaHidden||r.hidden||r.style.display==="none",s=r.dataset.radixToastAnnounceExclude==="";if(!o)if(s){const i=r.dataset.radixToastAnnounceAlt;i&&n.push(i)}else n.push(...YT(r))}}),n}function Dd(e,n,t,{discrete:r}){const o=t.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?fw(o,s):o.dispatchEvent(s)}const fC=(e,n,t=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return n==="left"||n==="right"?s&&r>t:!s&&o>t};function NG(e=()=>{}){const n=en(e);wi(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function FG(e){return e.nodeType===e.ELEMENT_NODE}function zG(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 Rm(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}const BG=$G,UG=RG,HG=DG,VG=KT,gC=WT,si="2.0.0-canary.e6e4e7f6cbac";let ZS={fonts:{draw:`https://unpkg.com/@tldraw/assets@${si}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${si}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${si}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${si}/fonts/IBMPlexMono-Medium.woff2`}};function KG(e){return w.useMemo(()=>e?{fonts:{...ZS.fonts,...e==null?void 0:e.fonts}}:ZS,[e])}const WG=["align-bottom-center","align-bottom-left","align-bottom-right","align-bottom","align-center-center","align-center-horizontal","align-center-left","align-center-right","align-center-vertical","align-left","align-right","align-top-center","align-top-left","align-top-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","aspect-ratio","avatar","blob","bring-forward","bring-to-front","check","checkbox-checked","checkbox-empty","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","collab","color","comment","cross-2","cross","dash-dashed","dash-dotted","dash-draw","dash-solid","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","file","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","hidden","image","info-circle","leading","link","lock-small","lock","menu","minus","mixed","pack","page","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","ruler","search","send-backward","send-to-back","settings-horizontal","settings-vertical-1","settings-vertical","share-1","share-2","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","status-online","stretch-horizontal","stretch-vertical","text-align-center","text-align-justify","text-align-left","text-align-right","tool-arrow","tool-embed","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-text","trash","triangle-down","triangle-up","twitter","undo","ungroup","unlock-small","unlock","vertical-align-center","vertical-align-end","vertical-align-start","visible","warning-triangle","zoom-in","zoom-out"];let Fl={...ZS,icons:Object.fromEntries(WG.map(e=>[e,`https://unpkg.com/@tldraw/assets@${si}/icons/icon/${e}.svg`])),translations:Object.fromEntries(wc.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${si}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Oa.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${si}/embed-icons/${e.type}.png`]))};function GG(e){return e?{fonts:Object.assign({...Fl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...Fl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...Fl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...Fl.translations},{...e==null?void 0:e.translations})}:Fl}function YG(e,n){const t=pe(n.map(o=>e.getShape(o)).filter(o=>o&&e.isShapeOfType(o,"frame")));if(!t.length)return;const r=[];e.batch(()=>{t.map(o=>{const s=e.getSortedChildIdsForParent(o.id);s.length&&(e.reparentShapes(s,o.parentId,o.index),r.push(...s))}),e.setSelectedShapes(r),e.deleteShapes(n)})}const XG=50;function qG(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=pe(o.map(p=>e.getShape(p)));if(!s.length)return;const i=re.FromPoints(s.flatMap(p=>{const m=e.getShapeGeometry(p.id);return e.getShapeLocalTransform(p).applyToPoints(m.vertices)})),{padding:a=XG}=t,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,d=a-i.minY;if(u===0&&d===0&&r.props.w===l&&r.props.h===c)return;const h=new C(u,d).rot(r.rotation);e.batch(()=>{const p=o.map(m=>{const f=e.getShape(m);return{id:f.id,type:f.type,x:f.x+u,y:f.y+d}});p.push({id:r.id,type:r.type,x:r.x-h.x,y:r.y-h.y,props:{w:l,h:c}}),e.updateShapes(p)})}const XT=w.createContext(null);function ZG({assetUrls:e,children:n}){return g.jsx(XT.Provider,{value:e,children:n})}function mw(){const e=w.useContext(XT);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const QS={"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.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.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-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","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","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.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy share link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy read-only link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to view (but not edit) this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},Yi={locale:"en",label:"English",messages:QS};async function QG(e,n){if(!(await fetch(n.translations.en)).ok)return console.warn("No main translations found."),Yi;if(e==="en")return Yi;const r=wc.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),Yi;const s=await(await fetch(n.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),Yi;const i=[];for(const a in Yi.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,messages:{...Yi.messages,...s}}}const qT=w.createContext({}),JG=()=>w.useContext(qT),eY=je(function({overrides:n,children:t}){const o=U().user.getLocale(),s=mw(),[i,a]=w.useState(()=>n&&n.en?{locale:"en",label:"English",messages:{...QS,...n.en}}:{locale:"en",label:"English",messages:QS});return w.useEffect(()=>{let l=!1;async function c(){const u=await QG(o,s);u&&!l&&(n&&n[o]?a({...u,messages:{...u.messages,...n[o]}}):a(u))}return c(),()=>{l=!0}},[s,o,n]),g.jsx(qT.Provider,{value:i,children:t})});function be(){const e=JG();return w.useCallback(function(t){return e.messages[t]??t},[e])}function tY(e){return g.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:g.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[g.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),g.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:g.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const Vn=w.memo(function({small:n,invertIcon:t,icon:r,color:o,className:s,...i}){const a=mw(),l=a.icons[r]??a.icons["question-mark-circle"],c=w.useRef(null);return w.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),g.jsx("div",{...i,ref:c,className:fe("tlui-icon",{"tlui-icon__small":n},s),style:{color:o,mask:`url(${l}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})}),ZT=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,QT=ZT?"⌘":"Ctrl",JT=ZT?"⌥":"Alt";function nY(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,QT).replace(/\?/g,JT).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function no(e){return"— "+e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,QT).replace(/\?/g,JT).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)}).join(" ")}function zf({children:e}){return g.jsx("kbd",{className:"tlui-kbd",children:nY(e).map((n,t)=>g.jsx("span",{children:n},t))})}const ie=w.forwardRef(function({label:n,icon:t,invertIcon:r,iconLeft:o,smallIcon:s,kbd:i,isChecked:a=!1,type:l,children:c,spinner:u,disabled:d,...h},p){const m=be(),f=n?m(n):"",S=U(),v=p==null?void 0:p.current;return d&&v===document.activeElement&&S.getContainer().focus(),g.jsxs("button",{ref:p,draggable:!1,type:"button",disabled:d,...h,title:h.title??f,className:fe("tlui-button",`tlui-button__${l}`,h.className),children:[o&&g.jsx(Vn,{icon:o,className:"tlui-button__icon-left",small:!0}),c,n&&g.jsxs("span",{className:"tlui-button__label",draggable:!1,children:[f,a&&g.jsx(Vn,{icon:"check"})]}),i&&g.jsx(zf,{children:i}),t&&!u&&g.jsx(Vn,{icon:t,small:!!n||s,invertIcon:r}),u&&g.jsx(tY,{})]})}),rY=GO.useId||(()=>{});let oY=0;function Ao(e){const[n,t]=w.useState(rY());return wi(()=>{e||t(r=>r??String(oY++))},[e]),e||(n?`radix-${n}`:"")}const Dm="focusScope.autoFocusOnMount",jm="focusScope.autoFocusOnUnmount",mC={bubbles:!1,cancelable:!0},yw=w.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=w.useState(null),c=en(o),u=en(s),d=w.useRef(null),h=Ge(n,f=>l(f)),p=w.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;w.useEffect(()=>{if(r){let x=function(k){if(p.paused||!a)return;const I=k.target;a.contains(I)?d.current=I:ts(d.current,{select:!0})},b=function(k){if(p.paused||!a)return;const I=k.relatedTarget;I!==null&&(a.contains(I)||ts(d.current,{select:!0}))},P=function(k){if(document.activeElement===document.body)for(const _ of k)_.removedNodes.length>0&&ts(a)};var f=x,S=b,v=P;document.addEventListener("focusin",x),document.addEventListener("focusout",b);const E=new MutationObserver(P);return a&&E.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",x),document.removeEventListener("focusout",b),E.disconnect()}}},[r,a,p.paused]),w.useEffect(()=>{if(a){SC.add(p);const f=document.activeElement;if(!a.contains(f)){const v=new CustomEvent(Dm,mC);a.addEventListener(Dm,c),a.dispatchEvent(v),v.defaultPrevented||(sY(uY(e$(a)),{select:!0}),document.activeElement===f&&ts(a))}return()=>{a.removeEventListener(Dm,c),setTimeout(()=>{const v=new CustomEvent(jm,mC);a.addEventListener(jm,u),a.dispatchEvent(v),v.defaultPrevented||ts(f??document.body,{select:!0}),a.removeEventListener(jm,u),SC.remove(p)},0)}}},[a,c,u,p]);const m=w.useCallback(f=>{if(!t&&!r||p.paused)return;const S=f.key==="Tab"&&!f.altKey&&!f.ctrlKey&&!f.metaKey,v=document.activeElement;if(S&&v){const x=f.currentTarget,[b,P]=iY(x);b&&P?!f.shiftKey&&v===P?(f.preventDefault(),t&&ts(b,{select:!0})):f.shiftKey&&v===b&&(f.preventDefault(),t&&ts(P,{select:!0})):v===x&&f.preventDefault()}},[t,r,p.paused]);return w.createElement(ze.div,Q({tabIndex:-1},i,{ref:h,onKeyDown:m}))});function sY(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(ts(r,{select:n}),document.activeElement!==t)return}function iY(e){const n=e$(e),t=yC(n,e),r=yC(n.reverse(),e);return[t,r]}function e$(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 yC(e,n){for(const t of e)if(!aY(t,{upTo:n}))return t}function aY(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 lY(e){return e instanceof HTMLInputElement&&"select"in e}function ts(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&lY(e)&&n&&e.select()}}const SC=cY();function cY(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=vC(e,n),e.unshift(n)},remove(n){var t;e=vC(e,n),(t=e[0])===null||t===void 0||t.resume()}}}function vC(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function uY(e){return e.filter(n=>n.tagName!=="A")}let Lm=0;function Sw(){w.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:wC()),document.body.insertAdjacentElement("beforeend",(n=t[1])!==null&&n!==void 0?n:wC()),Lm++,()=>{Lm===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),Lm--}},[])}function wC(){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 Gr=function(){return Gr=Object.assign||function(n){for(var t,r=1,o=arguments.length;r<o;r++){t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=t[s])}return n},Gr.apply(this,arguments)};function t$(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 dY(e,n,t){if(t||arguments.length===2)for(var r=0,o=n.length,s;r<o;r++)(s||!(r in n))&&(s||(s=Array.prototype.slice.call(n,0,r)),s[r]=n[r]);return e.concat(s||Array.prototype.slice.call(n))}var Bh="right-scroll-bar-position",Uh="width-before-scroll-bar",hY="with-scroll-bars-hidden",pY="--removed-body-scroll-bar-size";function Nm(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function fY(e,n){var t=w.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 xC=new WeakMap;function gY(e,n){var t=fY(n||null,function(r){return e.forEach(function(o){return Nm(o,r)})});return w.useLayoutEffect(function(){var r=xC.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||Nm(a,null)}),s.forEach(function(a){o.has(a)||Nm(a,i)})}xC.set(t,e)},[e]),t}function mY(e){return e}function yY(e,n){n===void 0&&(n=mY);var t=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return t.length?t[t.length-1]:e},useMedium:function(s){var i=n(s,r);return t.push(i),function(){t=t.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;t.length;){var i=t;t=[],i.forEach(s)}t={push:function(a){return s(a)},filter:function(){return t}}},assignMedium:function(s){r=!0;var i=[];if(t.length){var a=t;t=[],a.forEach(s),i=t}var l=function(){var u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),t={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),t}}}};return o}function SY(e){e===void 0&&(e={});var n=yY(null);return n.options=Gr({async:!0,ssr:!1},e),n}var n$=function(e){var n=e.sideCar,t=t$(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 w.createElement(r,Gr({},t))};n$.isSideCarExport=!0;function vY(e,n){return e.useMedium(n),n$}var r$=SY(),Fm=function(){},Bf=w.forwardRef(function(e,n){var t=w.useRef(null),r=w.useState({onScrollCapture:Fm,onWheelCapture:Fm,onTouchMoveCapture:Fm}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,d=e.shards,h=e.sideCar,p=e.noIsolation,m=e.inert,f=e.allowPinchZoom,S=e.as,v=S===void 0?"div":S,x=t$(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),b=h,P=gY([t,n]),E=Gr(Gr({},x),o);return w.createElement(w.Fragment,null,u&&w.createElement(b,{sideCar:r$,removeScrollBar:c,shards:d,noIsolation:p,inert:m,setCallbacks:s,allowPinchZoom:!!f,lockRef:t}),i?w.cloneElement(w.Children.only(a),Gr(Gr({},E),{ref:P})):w.createElement(v,Gr({},E,{className:l,ref:P}),a))});Bf.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Bf.classNames={fullWidth:Uh,zeroRight:Bh};var wY=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function xY(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=wY();return n&&e.setAttribute("nonce",n),e}function bY(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function PY(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var CY=function(){var e=0,n=null;return{add:function(t){e==0&&(n=xY())&&(bY(n,t),PY(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},EY=function(){var e=CY();return function(n,t){w.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},o$=function(){var e=EY(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},kY={left:0,top:0,right:0,gap:0},zm=function(e){return parseInt(e||"",10)||0},IY=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[zm(t),zm(r),zm(o)]},_Y=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return kY;var n=IY(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])}},TY=o$(),$Y=function(e,n,t,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return t===void 0&&(t="margin"),`
186
+ .`.concat(hY,` {
187
+ overflow: hidden `).concat(r,`;
188
+ padding-right: `).concat(a,"px ").concat(r,`;
189
+ }
190
+ body {
191
+ overflow: hidden `).concat(r,`;
192
+ overscroll-behavior: contain;
193
+ `).concat([n&&"position: relative ".concat(r,";"),t==="margin"&&`
194
+ padding-left: `.concat(o,`px;
195
+ padding-top: `).concat(s,`px;
196
+ padding-right: `).concat(i,`px;
197
+ margin-left:0;
198
+ margin-top:0;
199
+ margin-right: `).concat(a,"px ").concat(r,`;
200
+ `),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
201
+ }
202
+
203
+ .`).concat(Bh,` {
204
+ right: `).concat(a,"px ").concat(r,`;
205
+ }
206
+
207
+ .`).concat(Uh,` {
208
+ margin-right: `).concat(a,"px ").concat(r,`;
209
+ }
210
+
211
+ .`).concat(Bh," .").concat(Bh,` {
212
+ right: 0 `).concat(r,`;
213
+ }
214
+
215
+ .`).concat(Uh," .").concat(Uh,` {
216
+ margin-right: 0 `).concat(r,`;
217
+ }
218
+
219
+ body {
220
+ `).concat(pY,": ").concat(a,`px;
221
+ }
222
+ `)},AY=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r,s=w.useMemo(function(){return _Y(o)},[o]);return w.createElement(TY,{styles:$Y(s,!n,o,t?"":"!important")})},JS=!1;if(typeof window<"u")try{var jd=Object.defineProperty({},"passive",{get:function(){return JS=!0,!0}});window.addEventListener("test",jd,jd),window.removeEventListener("test",jd,jd)}catch{JS=!1}var Xi=JS?{passive:!1}:!1,MY=function(e){return e.tagName==="TEXTAREA"},s$=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!MY(e)&&t[n]==="visible")},OY=function(e){return s$(e,"overflowY")},RY=function(e){return s$(e,"overflowX")},bC=function(e,n){var t=n;do{typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&(t=t.host);var r=i$(e,t);if(r){var o=a$(e,t),s=o[1],i=o[2];if(s>i)return!0}t=t.parentNode}while(t&&t!==document.body);return!1},DY=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},jY=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},i$=function(e,n){return e==="v"?OY(n):RY(n)},a$=function(e,n){return e==="v"?DY(n):jY(n)},LY=function(e,n){return e==="h"&&n==="rtl"?-1:1},NY=function(e,n,t,r,o){var s=LY(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,l=n.contains(a),c=!1,u=i>0,d=0,h=0;do{var p=a$(e,a),m=p[0],f=p[1],S=p[2],v=f-S-s*m;(m||v)&&i$(e,a)&&(d+=v,h+=m),a=a.parentNode}while(!l&&a!==document.body||l&&(n.contains(a)||n===a));return(u&&(o&&d===0||!o&&i>d)||!u&&(o&&h===0||!o&&-i>h))&&(c=!0),c},Ld=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},PC=function(e){return[e.deltaX,e.deltaY]},CC=function(e){return e&&"current"in e?e.current:e},FY=function(e,n){return e[0]===n[0]&&e[1]===n[1]},zY=function(e){return`
223
+ .block-interactivity-`.concat(e,` {pointer-events: none;}
224
+ .allow-interactivity-`).concat(e,` {pointer-events: all;}
225
+ `)},BY=0,qi=[];function UY(e){var n=w.useRef([]),t=w.useRef([0,0]),r=w.useRef(),o=w.useState(BY++)[0],s=w.useState(function(){return o$()})[0],i=w.useRef(e);w.useEffect(function(){i.current=e},[e]),w.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var f=dY([e.lockRef.current],(e.shards||[]).map(CC),!0).filter(Boolean);return f.forEach(function(S){return S.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),f.forEach(function(S){return S.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=w.useCallback(function(f,S){if("touches"in f&&f.touches.length===2)return!i.current.allowPinchZoom;var v=Ld(f),x=t.current,b="deltaX"in f?f.deltaX:x[0]-v[0],P="deltaY"in f?f.deltaY:x[1]-v[1],E,k=f.target,I=Math.abs(b)>Math.abs(P)?"h":"v";if("touches"in f&&I==="h"&&k.type==="range")return!1;var _=bC(I,k);if(!_)return!0;if(_?E=I:(E=I==="v"?"h":"v",_=bC(I,k)),!_)return!1;if(!r.current&&"changedTouches"in f&&(b||P)&&(r.current=E),!E)return!0;var A=r.current||E;return NY(A,S,f,A==="h"?b:P,!0)},[]),l=w.useCallback(function(f){var S=f;if(!(!qi.length||qi[qi.length-1]!==s)){var v="deltaY"in S?PC(S):Ld(S),x=n.current.filter(function(E){return E.name===S.type&&E.target===S.target&&FY(E.delta,v)})[0];if(x&&x.should){S.cancelable&&S.preventDefault();return}if(!x){var b=(i.current.shards||[]).map(CC).filter(Boolean).filter(function(E){return E.contains(S.target)}),P=b.length>0?a(S,b[0]):!i.current.noIsolation;P&&S.cancelable&&S.preventDefault()}}},[]),c=w.useCallback(function(f,S,v,x){var b={name:f,delta:S,target:v,should:x};n.current.push(b),setTimeout(function(){n.current=n.current.filter(function(P){return P!==b})},1)},[]),u=w.useCallback(function(f){t.current=Ld(f),r.current=void 0},[]),d=w.useCallback(function(f){c(f.type,PC(f),f.target,a(f,e.lockRef.current))},[]),h=w.useCallback(function(f){c(f.type,Ld(f),f.target,a(f,e.lockRef.current))},[]);w.useEffect(function(){return qi.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Xi),document.addEventListener("touchmove",l,Xi),document.addEventListener("touchstart",u,Xi),function(){qi=qi.filter(function(f){return f!==s}),document.removeEventListener("wheel",l,Xi),document.removeEventListener("touchmove",l,Xi),document.removeEventListener("touchstart",u,Xi)}},[]);var p=e.removeScrollBar,m=e.inert;return w.createElement(w.Fragment,null,m?w.createElement(s,{styles:zY(o)}):null,p?w.createElement(AY,{gapMode:"margin"}):null)}const HY=vY(r$,UY);var l$=w.forwardRef(function(e,n){return w.createElement(Bf,Gr({},e,{ref:n,sideCar:HY}))});l$.classNames=Bf.classNames;const vw=l$;var VY=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},Zi=new WeakMap,Nd=new WeakMap,Fd={},Bm=0,c$=function(e){return e&&(e.host||c$(e.parentNode))},KY=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=c$(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})},WY=function(e,n,t,r){var o=KY(n,Array.isArray(e)?e:[e]);Fd[t]||(Fd[t]=new WeakMap);var s=Fd[t],i=[],a=new Set,l=new Set(o),c=function(d){!d||a.has(d)||(a.add(d),c(d.parentNode))};o.forEach(c);var u=function(d){!d||l.has(d)||Array.prototype.forEach.call(d.children,function(h){if(a.has(h))u(h);else{var p=h.getAttribute(r),m=p!==null&&p!=="false",f=(Zi.get(h)||0)+1,S=(s.get(h)||0)+1;Zi.set(h,f),s.set(h,S),i.push(h),f===1&&m&&Nd.set(h,!0),S===1&&h.setAttribute(t,"true"),m||h.setAttribute(r,"true")}})};return u(n),a.clear(),Bm++,function(){i.forEach(function(d){var h=Zi.get(d)-1,p=s.get(d)-1;Zi.set(d,h),s.set(d,p),h||(Nd.has(d)||d.removeAttribute(r),Nd.delete(d)),p||d.removeAttribute(t)}),Bm--,Bm||(Zi=new WeakMap,Zi=new WeakMap,Nd=new WeakMap,Fd={})}},ww=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=n||VY(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),WY(r,o,t,"aria-hidden")):function(){return null}};const u$="Dialog",[d$,mte]=io(u$),[GY,Go]=d$(u$),YY=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=w.useRef(null),l=w.useRef(null),[c=!1,u]=Bs({prop:r,defaultProp:o,onChange:s});return w.createElement(GY,{scope:n,triggerRef:a,contentRef:l,contentId:Ao(),titleId:Ao(),descriptionId:Ao(),open:c,onOpenChange:u,onOpenToggle:w.useCallback(()=>u(d=>!d),[u]),modal:i},t)},h$="DialogPortal",[XY,p$]=d$(h$,{forceMount:void 0}),qY=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=Go(h$,n);return w.createElement(XY,{scope:n,forceMount:t},w.Children.map(r,i=>w.createElement(Lr,{present:t||s.open},w.createElement(Lf,{asChild:!0,container:o},i))))},ev="DialogOverlay",ZY=w.forwardRef((e,n)=>{const t=p$(ev,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=Go(ev,e.__scopeDialog);return s.modal?w.createElement(Lr,{present:r||s.open},w.createElement(QY,Q({},o,{ref:n}))):null}),QY=w.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Go(ev,t);return w.createElement(vw,{as:vi,allowPinchZoom:!0,shards:[o.contentRef]},w.createElement(ze.div,Q({"data-state":g$(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),Yc="DialogContent",JY=w.forwardRef((e,n)=>{const t=p$(Yc,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=Go(Yc,e.__scopeDialog);return w.createElement(Lr,{present:r||s.open},s.modal?w.createElement(eX,Q({},o,{ref:n})):w.createElement(tX,Q({},o,{ref:n})))}),eX=w.forwardRef((e,n)=>{const t=Go(Yc,e.__scopeDialog),r=w.useRef(null),o=Ge(n,t.contentRef,r);return w.useEffect(()=>{const s=r.current;if(s)return ww(s)},[]),w.createElement(f$,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault())}))}),tX=w.forwardRef((e,n)=>{const t=Go(Yc,e.__scopeDialog),r=w.useRef(!1),o=w.useRef(!1);return w.createElement(f$,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),f$=w.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Go(Yc,t),l=w.useRef(null),c=Ge(n,l);return Sw(),w.createElement(w.Fragment,null,w.createElement(yw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},w.createElement(jf,Q({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":g$(a.open)},i,{ref:c,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),nX="DialogTitle",rX=w.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Go(nX,t);return w.createElement(ze.h2,Q({id:o.titleId},r,{ref:n}))});const oX="DialogClose",sX=w.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Go(oX,t);return w.createElement(ze.button,Q({type:"button"},r,{ref:n,onClick:se(e.onClick,()=>o.onOpenChange(!1))}))});function g$(e){return e?"open":"closed"}const iX=YY,aX=qY,lX=ZY,cX=JY;function Uf({className:e,children:n}){return g.jsx("div",{className:fe("tlui-dialog__header",e),children:n})}function Hf({className:e,children:n}){return g.jsx(rX,{dir:"ltr",className:fe("tlui-dialog__header__title",e),children:n})}function Vf(){return g.jsx("div",{className:"tlui-dialog__header__close",children:g.jsx(sX,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:g.jsx(ie,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:g.jsx(Vn,{small:!0,icon:"cross-2"})})})})}function Xc({className:e,children:n,style:t}){return g.jsx("div",{className:fe("tlui-dialog__body",e),style:t,children:n})}function xw({className:e,children:n}){return g.jsx("div",{className:fe("tlui-dialog__footer",e),children:n})}const bw=w.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoselect:s=!1,autofocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:d,onBlur:h,shouldManuallyMaintainScrollPositionWhenFocused:p=!1,children:m,value:f},S){const v=U(),x=w.useRef(null);w.useImperativeHandle(S,()=>x.current);const b=be(),P=w.useRef(a??""),E=w.useRef(a??""),[k,I]=w.useState(!1),_=w.useCallback(L=>{I(!0);const z=L.currentTarget;E.current=z.value,requestAnimationFrame(()=>{s&&z.select()})},[s]),A=w.useCallback(L=>{const z=L.currentTarget.value;E.current=z,u==null||u(z)},[u]),T=w.useCallback(L=>{switch(L.key){case"Enter":{L.currentTarget.blur(),Dt(L),c==null||c(L.currentTarget.value);break}case"Escape":{L.currentTarget.value=P.current,L.currentTarget.blur(),Dt(L),d==null||d(L.currentTarget.value);break}}},[c,d]),D=w.useCallback(L=>{I(!1);const z=L.currentTarget.value;h==null||h(z)},[h]);return w.useEffect(()=>{if(!v.environment.isIos)return;const L=window.visualViewport;if(k&&p&&L){const z=()=>{var j;(j=x.current)==null||j.scrollIntoView({block:"center"})};return L.addEventListener("resize",z),L.addEventListener("scroll",z),requestAnimationFrame(()=>{var j;(j=x.current)==null||j.scrollIntoView({block:"center"})}),()=>{L.removeEventListener("resize",z),L.removeEventListener("scroll",z)}}},[v,k,p]),g.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,t&&g.jsx("label",{children:b(t)}),o&&g.jsx(Vn,{icon:o,className:"tlui-icon-left",small:!0}),g.jsx("input",{ref:x,className:fe("tlui-input",n),type:"text",defaultValue:a,onKeyUp:T,onChange:A,onFocus:_,onBlur:D,autoFocus:i,placeholder:l,value:f}),r&&g.jsx(Vn,{icon:r,small:!!t})]})});function EC(e){return Wn.isValid(e)?{isValid:!0,hasProtocol:!0}:Wn.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const uX=je(function({onClose:n}){const r=U().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?g.jsx(dX,{onClose:n,selectedShape:r}):null}),dX=je(function({onClose:n,selectedShape:t}){const r=U(),o=be(),s=w.useRef(null);w.useEffect(()=>{requestAnimationFrame(()=>{var m;return(m=s.current)==null?void 0:m.focus()})},[]);const i=w.useRef(t.props.url),[a,l]=w.useState(()=>{const m=EC(t.props.url),f=m.isValid===!0?m.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:f,safe:f,valid:!0}}),c=w.useCallback(m=>{const f=m.replace(/https?:\/\/(https?:\/\/)/,(x,b)=>b),S=EC(f),v=S.isValid===!0?S.hasProtocol?f:"https://"+f:"https://";l({actual:f,safe:v,valid:S.isValid})},[]),u=w.useCallback(()=>{const m=r.getOnlySelectedShape();m&&(r.updateShapes([{id:m.id,type:m.type,props:{url:""}}]),n())},[r,n]),d=w.useCallback(()=>{const m=r.getOnlySelectedShape();m&&(m&&"url"in m.props&&m.props.url!==a.safe&&r.updateShapes([{id:m.id,type:m.type,props:{url:a.safe}}]),n())},[r,n,a]),h=w.useCallback(()=>{n()},[n]);if(!t)return n(),null;const p=i.current&&!a.valid;return g.jsxs(g.Fragment,{children:[g.jsxs(Uf,{children:[g.jsx(Hf,{children:o("edit-link-dialog.title")}),g.jsx(Vf,{})]}),g.jsx(Xc,{children:g.jsxs("div",{className:"tlui-edit-link-dialog",children:[g.jsx(bw,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autofocus:!0,value:a.actual,onValueChange:c,onComplete:d,onCancel:h}),g.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),g.jsxs(xw,{className:"tlui-dialog__footer__actions",children:[g.jsx(ie,{type:"normal",onClick:h,onTouchEnd:h,children:o("edit-link-dialog.cancel")}),p?g.jsx(ie,{type:"danger",onTouchEnd:u,onClick:u,children:o("edit-link-dialog.clear")}):g.jsx(ie,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:o("edit-link-dialog.save")})]})]})}),m$=je(function({onClose:n}){const t=U(),r=be(),o=mw(),[s,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[d,h]=w.useState(!1),p=w.useRef(-1);return g.jsxs(g.Fragment,{children:[g.jsxs(Uf,{children:[g.jsx(Hf,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),g.jsx(Vf,{})]}),s?g.jsxs(g.Fragment,{children:[g.jsxs(Xc,{className:"tlui-embed-dialog__enter",children:[g.jsx(bw,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autofocus:!0,onValueChange:m=>{l(m);const f=bo(m);u(f&&f.definition.type===s.type?f:null),h(!1),clearTimeout(p.current),p.current=setTimeout(()=>h(!f),320)}}),a===""?g.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[g.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&g.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",g.jsx(Vn,{icon:"external-link",small:!0})]})]}):g.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),g.jsxs(xw,{className:"tlui-dialog__footer__actions",children:[g.jsx(ie,{type:"normal",onClick:()=>{i(null),u(null),l("")},label:"embed-dialog.back"}),g.jsx("div",{className:"tlui-embed__spacer"}),g.jsx(ie,{type:"normal",label:"embed-dialog.cancel",onClick:n}),g.jsx(ie,{type:"primary",disabled:!c,label:"embed-dialog.create",onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageCenter(),embed:c.definition}),n())}})]})]}):g.jsx(g.Fragment,{children:g.jsx(Xc,{className:"tlui-embed-dialog__list",children:Oa.map(m=>g.jsx(ie,{type:"menu",onClick:()=>i(m),label:m.title,children:g.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[m.type]})`}})},m.type))})})]})});var Pw={exports:{}};Pw.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),d=0,h=c.length;d<h;d++){var p=c.charCodeAt(d);u[d*2]=p>>>8,u[d*2+1]=p%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,d=c.length;u<d;u++)c[u]=l[u*2]*256+l[u*2+1];var h=[];return c.forEach(function(p){h.push(t(p))}),a.decompress(h.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,u){if(l==null)return"";var d,h,p={},m={},f="",S="",v="",x=2,b=3,P=2,E=[],k=0,I=0,_;for(_=0;_<l.length;_+=1)if(f=l.charAt(_),Object.prototype.hasOwnProperty.call(p,f)||(p[f]=b++,m[f]=!0),S=v+f,Object.prototype.hasOwnProperty.call(p,S))v=S;else{if(Object.prototype.hasOwnProperty.call(m,v)){if(v.charCodeAt(0)<256){for(d=0;d<P;d++)k=k<<1,I==c-1?(I=0,E.push(u(k)),k=0):I++;for(h=v.charCodeAt(0),d=0;d<8;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1}else{for(h=1,d=0;d<P;d++)k=k<<1|h,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=0;for(h=v.charCodeAt(0),d=0;d<16;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1}x--,x==0&&(x=Math.pow(2,P),P++),delete m[v]}else for(h=p[v],d=0;d<P;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1;x--,x==0&&(x=Math.pow(2,P),P++),p[S]=b++,v=String(f)}if(v!==""){if(Object.prototype.hasOwnProperty.call(m,v)){if(v.charCodeAt(0)<256){for(d=0;d<P;d++)k=k<<1,I==c-1?(I=0,E.push(u(k)),k=0):I++;for(h=v.charCodeAt(0),d=0;d<8;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1}else{for(h=1,d=0;d<P;d++)k=k<<1|h,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=0;for(h=v.charCodeAt(0),d=0;d<16;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1}x--,x==0&&(x=Math.pow(2,P),P++),delete m[v]}else for(h=p[v],d=0;d<P;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1;x--,x==0&&(x=Math.pow(2,P),P++)}for(h=2,d=0;d<P;d++)k=k<<1|h&1,I==c-1?(I=0,E.push(u(k)),k=0):I++,h=h>>1;for(;;)if(k=k<<1,I==c-1){E.push(u(k));break}else I++;return E.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var d=[],h=4,p=4,m=3,f="",S=[],v,x,b,P,E,k,I,_={val:u(0),position:c,index:1};for(v=0;v<3;v+=1)d[v]=v;for(b=0,E=Math.pow(2,2),k=1;k!=E;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*k,k<<=1;switch(b){case 0:for(b=0,E=Math.pow(2,8),k=1;k!=E;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*k,k<<=1;I=t(b);break;case 1:for(b=0,E=Math.pow(2,16),k=1;k!=E;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*k,k<<=1;I=t(b);break;case 2:return""}for(d[3]=I,x=I,S.push(I);;){if(_.index>l)return"";for(b=0,E=Math.pow(2,m),k=1;k!=E;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*k,k<<=1;switch(I=b){case 0:for(b=0,E=Math.pow(2,8),k=1;k!=E;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*k,k<<=1;d[p++]=t(b),I=p-1,h--;break;case 1:for(b=0,E=Math.pow(2,16),k=1;k!=E;)P=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),b|=(P>0?1:0)*k,k<<=1;d[p++]=t(b),I=p-1,h--;break;case 2:return S.join("")}if(h==0&&(h=Math.pow(2,m),m++),d[I])f=d[I];else if(I===p)f=x+x.charAt(0);else return null;S.push(f),d[p++]=x+f.charAt(0),h--,x=f,h==0&&(h=Math.pow(2,m),m++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(Pw);var y$=Pw.exports;async function hX(e,n,t){var v,x,b;const{elements:r,files:o}=n,s={shapes:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,u=[],d=new Set;r.forEach(P=>{if(c.set(P.id,We()),P.boundElements!==null)for(const E of P.boundElements)E.type==="text"&&d.add(E.id)});let h="a1";for(const P of r){if(d.has(P.id))continue;const E=c.get(P.id),k={id:E,typeName:"shape",parentId:l,index:h,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:pX(P.opacity),meta:{}};switch(P.angle!==0&&a.set(E,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(v=i.get(P.groupIds[0]))==null||v.push(E):i.set(P.groupIds[0],[E]):u.push(E),P.type){case"rectangle":case"ellipse":case"diamond":{let I="",_="middle";if(P.boundElements!==null){for(const T of P.boundElements)if(T.type==="text"){const D=r.find(L=>L.id===T.id);D&&(I=D.text,_=kC[D.textAlign])}}const A=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;s.shapes.push({...k,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:zd[P.strokeWidth]??"draw",color:zl[A]??"black",text:I,align:_,dash:Bd(P),fill:wX(P)}});break}case"freedraw":{s.shapes.push({...k,type:"draw",props:{dash:Bd(P),size:zd[P.strokeWidth],color:zl[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([I,_,A=.5])=>({x:I,y:_,z:A}))}]}});break}case"line":{const I=P.points[0],_=P.points[P.points.length-1],A=Ek(P.points.length);s.shapes.push({...k,type:"line",props:{dash:Bd(P),size:zd[P.strokeWidth],color:zl[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",handles:{start:{id:"start",type:"vertex",index:A[0],x:I[0],y:I[1]},end:{id:"end",type:"vertex",index:A[A.length-1],x:_[0],y:_[1]},...Object.fromEntries(P.points.slice(1,-1).map(([T,D],L)=>{const z=Ue();return[z,{id:z,type:"vertex",index:A[L+1],x:T,y:D}]}))}}});break}case"arrow":{let I="";if(P.boundElements!==null){for(const L of P.boundElements)if(L.type==="text"){const z=r.find(j=>j.id===L.id);z&&(I=z.text)}}const _=P.points[0],A=P.points[P.points.length-1],T=c.get((x=P.startBinding)==null?void 0:x.elementId),D=c.get((b=P.endBinding)==null?void 0:b.elementId);s.shapes.push({...k,type:"arrow",props:{text:I,bend:vX(P,_,A),dash:Bd(P),size:zd[P.strokeWidth]??"m",color:zl[P.strokeColor]??"black",start:T?{type:"binding",boundShapeId:T,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:_[0],y:_[1]},end:D?{type:"binding",boundShapeId:D,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:A[0],y:A[1]},arrowheadEnd:IC[P.endArrowhead]??"none",arrowheadStart:IC[P.startArrowhead]??"none"}});break}case"text":{const{size:I,scale:_}=gX(P.fontSize);s.shapes.push({...k,type:"text",props:{size:I,scale:_,font:mX[P.fontFamily]??"draw",color:zl[P.strokeColor]??"black",text:P.text,align:kC[P.textAlign]}});break}case"image":{const I=o[P.fileId];if(!I)break;const _=ei.createId();s.assets.push({id:_,typeName:"asset",type:"image",props:{w:P.width,h:P.height,name:P.id??"Untitled",isAnimated:!1,mimeType:I.mimeType,src:I.dataURL},meta:{}}),s.shapes.push({...k,type:"image",props:{w:P.width,h:P.height,assetId:_}})}}h=So(h)}const p=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:p,select:!1,preserveIds:!0});for(const P of i.values())if(P.length>1){e.groupShapes(P);const E=e.getShape(P[0]);E!=null&&E.parentId&&Rn(E.parentId)&&u.push(E.parentId)}for(const[P,E]of a)e.select(P),e.rotateShapesBy([P],E);const m=pe(u.map(P=>e.getShape(P))),f=re.Common(m.map(P=>e.getShapePageBounds(P))),S=e.getViewportPageBounds().center;e.updateShapes(m.map(P=>{const E={x:(P.x??0)-(f.x+f.w/2),y:(P.y??0)-(f.y+f.h/2)};return{id:P.id,type:P.type,x:S.x+E.x,y:S.y+E.y}})),e.setSelectedShapes(u)}const pX=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},zd={1:"s",2:"m",3:"l",4:"xl"},fX={16:"s",20:"m",28:"l",36:"xl"};function gX(e){const n=fX[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 mX={1:"draw",2:"sans",3:"mono"},zl={"#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"},yX={solid:"draw",dashed:"dashed",dotted:"dotted"},SX={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},kC={left:"start",center:"middle",right:"end"},IC={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function vX(e,n,t){let r=0;if(e.points.length>2){const o=new C(n[0],n[1]),s=new C(t[0],t[1]),i=new C(e.points[1][0],e.points[1][1]),a=C.Sub(s,o),l=C.Per(a),c=C.Med(s,o),u=C.Sub(c,l),d=C.Add(c,l),h=C.NearestPointOnLineSegment(u,d,i,!1);r=C.Dist(h,c),C.Clockwise(h,s,c)&&(r*=-1)}return r}const Bd=e=>{let n=yX[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},wX=e=>e.backgroundColor==="transparent"?"none":SX[e.fillStyle]??"solid";async function S$(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await fetch(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r}),n.forEach(i=>URL.revokeObjectURL(i))}function xX(e,n,t){const r=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(n,{point:r,select:!0})}async function tv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await fetch(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),S$(e,[n]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:t,url:n,sources:r})}const v$=()=>{},w$=w.createContext({});function bX({onEvent:e,children:n}){return g.jsx(w$.Provider,{value:e??v$,children:n})}function cl(){return w.useContext(w$)??v$}function PX(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const CX=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},EX=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 ik(n)},kX=e=>/^<svg/.test(e),IX=["input","select","textarea"];function Hh(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||IX.indexOf(n.tagName.toLowerCase())>-1)}async function Um(e){return new Promise((n,t)=>{const r=new FileReader;r.addEventListener("loadend",()=>{const o=r.result;n(o)}),r.addEventListener("error",()=>{t(r.error)}),r.readAsText(e)})}const _X=e=>e.types.find(n=>n.match(/^image\//)),Hm=(e,n,t,r)=>{const o=EX(n);if(o)for(const s of o)tv(e,s,t);else CX(n)?tv(e,n,t):kX(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}))},TX=async(e,n,t)=>{if(e.getEditingShapeId()!==null)return;if(!n)throw Error("No clipboard data");const r=[];for(const o of Object.values(n.items))switch(o.kind){case"file":{r.push({type:"file",source:new Promise(s=>s(o.getAsFile()))});break}case"string":{o.type==="text/html"?r.push({type:"html",source:new Promise(s=>o.getAsString(s))}):o.type==="text/plain"?r.push({type:"text",source:new Promise(s=>o.getAsString(s))}):r.push({type:o.type,source:new Promise(s=>o.getAsString(s))});break}}b$(e,r,t)},x$=async(e,n,t)=>{const r=[];for(const o of n){if(_X(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:new Promise(s=>o.getType("text/html").then(i=>Um(i).then(s)))}),o.types.includes("text/uri-list")&&r.push({type:"url",source:new Promise(s=>o.getType("text/uri-list").then(i=>Um(i).then(s)))}),o.types.includes("text/plain")&&r.push({type:"text",source:new Promise(s=>o.getType("text/plain").then(i=>Um(i).then(s)))})}return await b$(e,r,t)};async function b$(e,n,t){const r=n.filter(s=>(s.type==="file"||s.type==="blob")&&s.source!==null);if(r.length){const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await S$(e,i,t)}const o=await Promise.all(n.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:u[1];if(c)try{const d=y$.decompressFromBase64(c);if(d===null){i({type:"error",data:d,reason:"found tldraw data comment but could not parse base64"});return}else{const h=JSON.parse(d);if(h.type!=="application/tldraw"&&i({type:"error",data:h,reason:`found tldraw data comment but JSON was of a different type: ${h.type}`}),typeof h.data=="string"){i({type:"error",data:h,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:h.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const d=JSON.parse(l);if(d.type==="excalidraw/clipboard"){i({type:"excalidraw",data:d});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){xX(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){hX(e,s.data,t);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");Hm(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){Hm(e,PX(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){tv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){Hm(e,s.data,t,o);return}}const Kp=e=>{var r;const n=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=y$.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:n}));if(!(typeof navigator>"u")){const o=n.shapes.map(s=>e.isShapeOfType(s,"text")||e.isShapeOfType(s,"geo")||e.isShapeOfType(s,"arrow")?s.props.text:e.isShapeOfType(s,"bookmark")||e.isShapeOfType(s,"embed")?s.props.url:null).filter(IR);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<tldraw>${t}</tldraw>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${t}</tldraw>`)}};function $X(){const e=U(),n=cl(),t=w.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(Kp(e),n("copy",{source:i}))},[e,n]),r=w.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(Kp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=w.useCallback(async function(i,a,l){e.getEditingShapeId()!==null||Hh(e)||(Array.isArray(i)&&i[0]instanceof ClipboardItem?(x$(e,i,l),n("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[e,n]);return{copy:t,cut:r,paste:o}}function AX(){const e=U(),n=cl(),t=G("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);w.useEffect(()=>{if(!t)return;const r=()=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Hh(e)||(Kp(e),n("copy",{source:"kbd"}))};function o(){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Hh(e)||(Kp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){l.stopPropagation();return}e.getEditingShapeId()!==null||Hh(e)||(l.clipboardData&&!e.inputs.shiftKey?TX(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&x$(e,c,e.inputs.currentPagePoint)}),n("paste",{source:"kbd"}))};return document.addEventListener("copy",r),document.addEventListener("cut",o),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[e,n,t])}async function MX(e,n,t){const{type:r,quality:o,scale:s}=t,i=+e.getAttribute("width"),a=+e.getAttribute("height");let[l,c]=await LI(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,d=await P$(e),h=URL.createObjectURL(new Blob([d],{type:"image/svg+xml"})),p=await new Promise(S=>{const v=new Image;v.crossOrigin="anonymous",v.onload=async()=>{n&&await new Promise(P=>setTimeout(P,250));const x=document.createElement("canvas"),b=x.getContext("2d");x.width=l,x.height=c,b.imageSmoothingEnabled=!0,b.imageSmoothingQuality="high",b.drawImage(v,0,0,l,c),URL.revokeObjectURL(h),S(x)},v.onerror=()=>{S(null)},v.src=h});if(!p)return null;const m=await new Promise(S=>p.toBlob(v=>{(!v||Oe.throwToBlob.get())&&S(null),S(v)},"image/"+r,o));if(!m)return null;const f=new DataView(await m.arrayBuffer());return Kr.setPhysChunk(f,u,{type:"image/"+r})}async function P$(e){const n=e.cloneNode(!0);e.setAttribute("width",+e.getAttribute("width")+""),e.setAttribute("height",+e.getAttribute("height")+"");const t=new FileReader,r=Array.from(n.querySelectorAll("image"));for(const s of r){const i=s.getAttribute("xlink:href");if(i&&!i.startsWith("data:")){const a=await(await fetch(i)).blob(),l=await new Promise((c,u)=>{t.onload=()=>c(t.result),t.onerror=()=>u(t.error),t.readAsDataURL(a)});s.setAttribute("xlink:href",l)}}return new XMLSerializer().serializeToString(n).replaceAll("&#10; ","").replaceAll(/((\s|")[0-9]*\.[0-9]{2})([0-9]*)(\b|"|\))/g,"$1")}async function C$(e,n,t){const r=await e.getSvg(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 nv(e,n,t,r={}){switch(t){case"svg":return P$(await C$(e,n,r));case"json":{const o=e.getContentFromCurrentPage(n);return JSON.stringify(o)}default:Ya(t)}}async function E$(e,n,t,r={}){switch(t){case"svg":return new Blob([await nv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await nv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await MX(await C$(e,n,r),e.environment.isSafari,{type:t,quality:1,scale:2});if(!o)throw new Error("Could not construct image.");return o}default:Ya(t)}}const OX={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function RX(e,n,t,r={}){return{blobPromise:E$(e,n,t,r),mimeType:OX[t]}}function DX(e,n,t="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=RX(e,n,t,r);return window.navigator.clipboard.write([new ClipboardItem({[s]:o})]).catch(i=>(console.error(i),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[s]:a})]))))}switch(t){case"json":case"svg":return jX(async()=>nv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ya(t)}}async function jX(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}const k$=w.createContext({});function LX({children:e}){const[n,t]=w.useState([]),r=w.useCallback(i=>{const a=i.id??Ue();return t(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=w.useCallback(i=>(t(a=>a.filter(l=>l.id!==i)),i),[]),s=w.useCallback(()=>{t(()=>[])},[]);return g.jsx(k$.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})}function ao(){const e=w.useContext(k$);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}function NX(){const e=U(),{addToast:n}=ao(),t=be();return w.useCallback((r,o="svg")=>{DX(e,r,o).catch(()=>{n({id:"copy-fail",icon:"warning-triangle",title:t("toast.error.copy-fail.title"),description:t("toast.error.copy-fail.desc")})})},[e,n,t])}const I$=w.createContext({});function FX({children:e}){const n=U(),t=cl(),[r,o]=w.useState([]),s=w.useCallback(c=>{const u=c.id??Ue();return o(d=>[...d.filter(h=>h.id!==c.id),{...c,id:u}]),t("open-menu",{source:"dialog",id:u}),n.addOpenMenu(u),u},[n,t]),i=w.useCallback((c,u)=>(o(d=>d.map(h=>h.id===c?{...h,...u}:h)),t("open-menu",{source:"dialog",id:c}),n.addOpenMenu(c),c),[n,t]),a=w.useCallback(c=>(o(u=>u.filter(d=>{var h;return d.id===c?((h=d.onClose)==null||h.call(d),!1):!0})),t("close-menu",{source:"dialog",id:c}),n.deleteOpenMenu(c),c),[n,t]),l=w.useCallback(()=>{o(c=>(c.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 g.jsx(I$.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function $i(){const e=w.useContext(I$);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}async function zX(e,n,t="png",r={}){let o=`shapes at ${_C()}`;if(n.length===1){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?o=a.props.name??"frame":o=`${a.id.replace(/:/,"_")} at ${_C()}`}o+=`.${t}`;const s=await E$(e,n,t,r),i=new File([s],o,{type:s.type});BX(i)}function _C(){const e=new Date,n=String(e.getFullYear()).slice(2),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return`${n}-${t}-${r} ${o}.${s}.${i}`}function BX(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function UX(){const e=U(),{addToast:n}=ao(),t=be();return w.useCallback((r,o="png")=>{zX(e,r,o,{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")})})},[e,n,t])}function _$(){const e=U(),n=w.useRef();return w.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept="image/jpeg,image/png,image/gif,image/svg+xml,video/mp4,video/quicktime",t.multiple=!0,n.current=t;async function r(o){const s=o.target.files;!s||s.length===0||(await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),t.value="")}return t.addEventListener("change",r),()=>{n.current=void 0,t.removeEventListener("change",r)}},[e]),w.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}function HX(){const e=U(),n=w.useRef(null),t=w.useRef(null);return w.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(v,x)=>{v&&(v.innerHTML=""),x&&document.head.contains(x)&&document.head.removeChild(x),v&&document.body.contains(v)&&document.body.removeChild(v)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${Ue()}`;o.className=a,s.innerHTML=`
226
+ .${a} {
227
+ display: none;
228
+ }
229
+
230
+ .${a} svg {
231
+ max-width: 100%;
232
+ height: 100%;
233
+ display: block;
234
+ }
235
+
236
+ @media print {
237
+ html, body {
238
+ min-height: 100%;
239
+ height: 100%;
240
+ margin: 0;
241
+ }
242
+
243
+ body {
244
+ position: relative;
245
+ }
246
+
247
+ body > * {
248
+ display: none;
249
+ }
250
+
251
+ .tldraw__editor {
252
+ display: none;
253
+ }
254
+
255
+ .${a} {
256
+ display: block !important;
257
+ background: white;
258
+ min-height: 100%;
259
+ height: 100%;
260
+ max-width: 100%;
261
+ }
262
+
263
+ .${a}__item {
264
+ padding: 10mm;
265
+ display: flex;
266
+ min-height: 100%;
267
+ flex-direction: column;
268
+ page-break-after: always;
269
+ position: relative;
270
+ overflow: hidden;
271
+ height: 100%;
272
+ }
273
+
274
+ .${a}__item__main {
275
+ flex: 1;
276
+ display: flex;
277
+ align-items: center;
278
+ justify-content: center;
279
+ max-height: 100%;
280
+ }
281
+
282
+ .${a}__item__header {
283
+ display: none;
284
+ }
285
+
286
+ .${a}__item__footer {
287
+ display: none;
288
+ text-align: right;
289
+ }
290
+
291
+ .${a}__item__footer__hide {
292
+ display: none;
293
+ }
294
+
295
+
296
+ }
297
+
298
+ `;const l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{e.once("change-history",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(v,x,b){try{o.innerHTML+=`<div class="${a}__item">
299
+ <div class="${a}__item__header">
300
+ ${v.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
301
+ </div>
302
+ <div class="${a}__item__main">
303
+ ${b.outerHTML}
304
+ </div>
305
+ <div class="${a}__item__footer ${a}__item__footer__${x?"":"hide"}">
306
+ ${x??""}
307
+ </div>
308
+ </div>`}catch(P){console.error(P)}}function d(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const h=e.getSelectedShapeIds(),p=e.getCurrentPageId(),m=e.getPages(),S={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const v=await e.getSvg(h,S);if(v){const x=m.find(b=>b.id===p);u(`tldraw — ${x==null?void 0:x.name}`,null,v),d()}}else{const v=e.getCurrentPage(),x=await e.getSvg(e.getSortedChildIdsForParent(v.id),S);x&&(u(`tldraw — ${v.name}`,null,x),d())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const T$=w.createContext({});function VX(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function KX({overrides:e,children:n}){const t=U(),{addDialog:r,clearDialogs:o}=$i(),{clearToasts:s}=ao(),i=_$(),a=HX(),{cut:l,copy:c,paste:u}=$X(),d=NX(),h=UX(),p=cl(),m=w.useMemo(()=>{function f(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function S(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const x=VX([{id:"edit-link",label:"action.edit-link",icon:"link",readonlyOk:!1,onSelect(b){S()&&(f()||(p("edit-link",{source:b}),t.mark("edit-link"),r({component:uX})))}},{id:"insert-embed",label:"action.insert-embed",readonlyOk:!1,kbd:"$i",onSelect(b){p("insert-embed",{source:b}),r({component:m$})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",readonlyOk:!1,onSelect(b){p("insert-media",{source:b}),i()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",readonlyOk:!1,onSelect(b){p("undo",{source:b}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",readonlyOk:!1,onSelect(b){p("redo",{source:b}),t.redo()}},{id:"export-as-svg",label:"action.export-as-svg",menuLabel:"action.export-as-svg.short",contextMenuLabel:"action.export-as-svg.short",readonlyOk:!0,onSelect(b){p("export-as",{format:"svg",source:b}),h(t.getSelectedShapeIds(),"svg")}},{id:"export-as-png",label:"action.export-as-png",menuLabel:"action.export-as-png.short",contextMenuLabel:"action.export-as-png.short",readonlyOk:!0,onSelect(b){p("export-as",{format:"png",source:b}),h(t.getSelectedShapeIds(),"png")}},{id:"export-as-json",label:"action.export-as-json",menuLabel:"action.export-as-json.short",contextMenuLabel:"action.export-as-json.short",readonlyOk:!0,onSelect(b){p("export-as",{format:"json",source:b}),h(t.getSelectedShapeIds(),"json")}},{id:"copy-as-svg",label:"action.copy-as-svg",menuLabel:"action.copy-as-svg.short",contextMenuLabel:"action.copy-as-svg.short",kbd:"$!c",readonlyOk:!0,onSelect(b){p("copy-as",{format:"svg",source:b}),d(t.getSelectedShapeIds(),"svg")}},{id:"copy-as-png",label:"action.copy-as-png",menuLabel:"action.copy-as-png.short",contextMenuLabel:"action.copy-as-png.short",readonlyOk:!0,onSelect(b){p("copy-as",{format:"png",source:b}),d(t.getSelectedShapeIds(),"png")}},{id:"copy-as-json",label:"action.copy-as-json",menuLabel:"action.copy-as-json.short",contextMenuLabel:"action.copy-as-json.short",readonlyOk:!0,onSelect(b){p("copy-as",{format:"json",source:b}),d(t.getSelectedShapeIds(),"json")}},{id:"toggle-auto-size",label:"action.toggle-auto-size",readonlyOk:!1,onSelect(b){S()&&(f()||(p("toggle-auto-size",{source:b}),t.mark("toggling auto size"),t.updateShapes(t.getSelectedShapes().filter(P=>t.isShapeOfType(P,"text")&&P.props.autoSize===!1).map(P=>({id:P.id,type:P.type,props:{...P.props,w:8,autoSize:!0}})))))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(b){p("open-embed-link",{source:b});const P=t.getSelectedShapeIds(),E="No embed shapes selected";if(P.length!==1){console.error(E);return}const k=t.getShape(P[0]);if(!k||!t.isShapeOfType(k,"embed")){console.error(E);return}v4(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(b){var P,E;if(((P=t.root.getCurrent())==null?void 0:P.id)!=="zoom"&&(p("zoom-tool",{source:b}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const k=t.root.getCurrent();k&&((E=k.getCurrent())==null?void 0:E.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",readonlyOk:!1,onSelect(b){S()&&(f()||t.batch(()=>{p("convert-to-bookmark",{source:b});const P=t.getSelectedShapes(),E=[],k=[];for(const I of P){if(!I||!t.isShapeOfType(I,"embed")||!I.props.url)continue;const _=new C(I.x,I.y);_.rot(-I.rotation),_.add(new C(I.props.w/2-300/2,I.props.h/2-320/2)),_.rot(I.rotation);const A={id:We(),type:"bookmark",rotation:I.rotation,x:_.x,y:_.y,opacity:1,props:{url:I.props.url}};E.push(A),k.push(I.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(k),t.createShapes(E)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",readonlyOk:!1,onSelect(b){S()&&(f()||(p("convert-to-embed",{source:b}),t.batch(()=>{const P=t.getSelectedShapeIds(),E=pe(P.map(_=>t.getShape(_))),k=[],I=[];for(const _ of E){if(!t.isShapeOfType(_,"bookmark"))continue;const{url:A}=_.props,T=bo(_.props.url);if(!T||!T.definition)continue;const{width:D,height:L}=T.definition,z=new C(_.x,_.y);z.rot(-_.rotation),z.add(new C(_.props.w/2-D/2,_.props.h/2-L/2)),z.rot(_.rotation);const j={id:We(),type:"embed",x:z.x,y:z.y,rotation:_.rotation,props:{url:A,w:D,h:L}};k.push(j),I.push(_.id)}t.mark("convert shapes to embed"),t.deleteShapes(I),t.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",readonlyOk:!1,onSelect(b){if(!S()||f())return;p("duplicate-shapes",{source:b});const P=t.getInstanceState();let E,k;if(P.duplicateProps)E=P.duplicateProps.shapeIds,k=P.duplicateProps.offset;else{E=t.getSelectedShapeIds();const I=re.Common(pe(E.map(_=>t.getShapePageBounds(_))));k=P.canMoveCamera?{x:I.width+10,y:0}:{x:16/t.getZoomLevel(),y:16/t.getZoomLevel()}}t.mark("duplicate shapes"),t.duplicateShapes(E,k),P.duplicateProps&&t.updateInstanceState({duplicateProps:{...P.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",readonlyOk:!1,onSelect(b){S()&&(f()||(p("ungroup-shapes",{source:b}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",readonlyOk:!1,onSelect(b){if(!S()||f())return;p("group-shapes",{source:b});const P=t.getOnlySelectedShape();P&&t.isShapeOfType(P,"group")?(t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())):(t.mark("group"),t.groupShapes(t.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",readonlyOk:!1,onSelect(b){if(!S())return;p("remove-frame",{source:b});const P=t.getSelectedShapes();P.length>0&&P.every(E=>t.isShapeOfType(E,"frame"))&&(t.mark("remove-frame"),YG(t,P.map(E=>E.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",readonlyOk:!1,onSelect(b){if(!S())return;p("fit-frame-to-content",{source:b});const P=t.getOnlySelectedShape();P&&t.isShapeOfType(P,"frame")&&(t.mark("fit-frame-to-content"),qG(t,P.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",readonlyOk:!1,onSelect(b){S()&&(f()||(p("align-shapes",{operation:"left",source:b}),t.mark("align left"),t.alignShapes(t.getSelectedShapeIds(),"left")))}},{id:"align-center-horizontal",label:"action.align-center-horizontal",contextMenuLabel:"action.align-center-horizontal.short",kbd:"?H",icon:"align-center-horizontal",readonlyOk:!1,onSelect(b){S()&&(f()||(p("align-shapes",{operation:"center-horizontal",source:b}),t.mark("align center horizontal"),t.alignShapes(t.getSelectedShapeIds(),"center-horizontal")))}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",readonlyOk:!1,onSelect(b){S()&&(f()||(p("align-shapes",{operation:"right",source:b}),t.mark("align right"),t.alignShapes(t.getSelectedShapeIds(),"right")))}},{id:"align-center-vertical",label:"action.align-center-vertical",contextMenuLabel:"action.align-center-vertical.short",kbd:"?V",icon:"align-center-vertical",readonlyOk:!1,onSelect(b){S()&&(f()||(p("align-shapes",{operation:"center-vertical",source:b}),t.mark("align center vertical"),t.alignShapes(t.getSelectedShapeIds(),"center-vertical")))}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",readonlyOk:!1,onSelect(b){S()&&(f()||(p("align-shapes",{operation:"top",source:b}),t.mark("align top"),t.alignShapes(t.getSelectedShapeIds(),"top")))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",readonlyOk:!1,onSelect(b){S()&&(f()||(p("align-shapes",{operation:"bottom",source:b}),t.mark("align bottom"),t.alignShapes(t.getSelectedShapeIds(),"bottom")))}},{id:"distribute-horizontal",label:"action.distribute-horizontal",contextMenuLabel:"action.distribute-horizontal.short",icon:"distribute-horizontal",kbd:"?!h",readonlyOk:!1,onSelect(b){S()&&(f()||(p("distribute-shapes",{operation:"horizontal",source:b}),t.mark("distribute horizontal"),t.distributeShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"distribute-vertical",label:"action.distribute-vertical",contextMenuLabel:"action.distribute-vertical.short",icon:"distribute-vertical",kbd:"?!V",readonlyOk:!1,onSelect(b){S()&&(f()||(p("distribute-shapes",{operation:"vertical",source:b}),t.mark("distribute vertical"),t.distributeShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"stretch-horizontal",label:"action.stretch-horizontal",contextMenuLabel:"action.stretch-horizontal.short",icon:"stretch-horizontal",readonlyOk:!1,onSelect(b){S()&&(f()||(p("stretch-shapes",{operation:"horizontal",source:b}),t.mark("stretch horizontal"),t.stretchShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"stretch-vertical",label:"action.stretch-vertical",contextMenuLabel:"action.stretch-vertical.short",icon:"stretch-vertical",readonlyOk:!1,onSelect(b){S()&&(f()||(p("stretch-shapes",{operation:"vertical",source:b}),t.mark("stretch vertical"),t.stretchShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"flip-horizontal",label:"action.flip-horizontal",contextMenuLabel:"action.flip-horizontal.short",kbd:"!h",readonlyOk:!1,onSelect(b){S()&&(f()||(p("flip-shapes",{operation:"horizontal",source:b}),t.mark("flip horizontal"),t.flipShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"flip-vertical",label:"action.flip-vertical",contextMenuLabel:"action.flip-vertical.short",kbd:"!v",readonlyOk:!1,onSelect(b){S()&&(f()||(p("flip-shapes",{operation:"vertical",source:b}),t.mark("flip vertical"),t.flipShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"pack",label:"action.pack",icon:"pack",readonlyOk:!1,onSelect(b){S()&&(f()||(p("pack-shapes",{source:b}),t.mark("pack"),t.packShapes(t.getSelectedShapeIds(),16)))}},{id:"stack-vertical",label:"action.stack-vertical",contextMenuLabel:"action.stack-vertical.short",icon:"stack-vertical",readonlyOk:!1,onSelect(b){S()&&(f()||(p("stack-shapes",{operation:"vertical",source:b}),t.mark("stack-vertical"),t.stackShapes(t.getSelectedShapeIds(),"vertical",16)))}},{id:"stack-horizontal",label:"action.stack-horizontal",contextMenuLabel:"action.stack-horizontal.short",icon:"stack-horizontal",readonlyOk:!1,onSelect(b){S()&&(f()||(p("stack-shapes",{operation:"horizontal",source:b}),t.mark("stack-horizontal"),t.stackShapes(t.getSelectedShapeIds(),"horizontal",16)))}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",readonlyOk:!1,onSelect(b){S()&&(f()||(p("reorder-shapes",{operation:"toFront",source:b}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",readonlyOk:!1,onSelect(b){S()&&(f()||(p("reorder-shapes",{operation:"forward",source:b}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",readonlyOk:!1,onSelect(b){S()&&(f()||(p("reorder-shapes",{operation:"backward",source:b}),t.mark("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",readonlyOk:!1,onSelect(b){S()&&(f()||(p("reorder-shapes",{operation:"toBack",source:b}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",readonlyOk:!1,onSelect(b){S()&&(f()||(t.mark("cut"),l(b)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(b){S()&&(f()||c(b))}},{id:"paste",label:"action.paste",kbd:"$v",readonlyOk:!1,onSelect(b){var P;(P=navigator.clipboard)==null||P.read().then(E=>{u(E,b,b==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(b){t.batch(()=>{f()||(p("select-all-shapes",{source:b}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(b){S()&&(f()||(p("select-none-shapes",{source:b}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",readonlyOk:!1,onSelect(b){S()&&(f()||(p("delete-shapes",{source:b}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",readonlyOk:!1,onSelect(b){if(!S()||f())return;p("rotate-cw",{source:b}),t.mark("rotate-cw");const P=t.getSelectionRotation()%(Ve/2),E=ec(P,0)||ec(P,Ve/2);t.rotateShapesBy(t.getSelectedShapeIds(),Ve/2-(E?0:P))}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",readonlyOk:!1,onSelect(b){if(!S()||f())return;p("rotate-ccw",{source:b}),t.mark("rotate-ccw");const P=t.getSelectionRotation()%(Ve/2),E=ec(P,0);t.rotateShapesBy(t.getSelectedShapeIds(),E?-(Ve/2):-P)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(b){p("zoom-in",{source:b}),t.zoomIn(t.getViewportScreenCenter(),{duration:xo})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(b){p("zoom-out",{source:b}),t.zoomOut(t.getViewportScreenCenter(),{duration:xo})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(b){p("reset-zoom",{source:b}),t.resetZoom(t.getViewportScreenCenter(),{duration:xo})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(b){p("zoom-to-fit",{source:b}),t.zoomToFit({duration:xo})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(b){S()&&(f()||(p("zoom-to-selection",{source:b}),t.zoomToSelection({duration:xo})))}},{id:"toggle-snap-mode",label:"action.toggle-snap-mode",menuLabel:"action.toggle-snap-mode.menu",readonlyOk:!1,onSelect(b){p("toggle-snap-mode",{source:b}),t.user.updateUserPreferences({isSnapMode:!t.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:"action.toggle-dark-mode",menuLabel:"action.toggle-dark-mode.menu",kbd:"$/",readonlyOk:!0,onSelect(b){p("toggle-dark-mode",{source:b}),t.user.updateUserPreferences({isDarkMode:!t.user.getIsDarkMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:"action.toggle-reduce-motion",menuLabel:"action.toggle-reduce-motion.menu",readonlyOk:!0,onSelect(b){p("toggle-reduce-motion",{source:b}),t.user.updateUserPreferences({animationSpeed:t.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:"action.toggle-edge-scrolling",menuLabel:"action.toggle-edge-scrolling.menu",readonlyOk:!0,onSelect(b){p("toggle-edge-scrolling",{source:b}),t.user.updateUserPreferences({edgeScrollSpeed:t.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:"action.toggle-transparent",menuLabel:"action.toggle-transparent.menu",contextMenuLabel:"action.toggle-transparent.context-menu",readonlyOk:!0,onSelect(b){p("toggle-transparent",{source:b}),t.updateInstanceState({exportBackground:!t.getInstanceState().exportBackground},{ephemeral:!0})},checkbox:!0},{id:"toggle-tool-lock",label:"action.toggle-tool-lock",menuLabel:"action.toggle-tool-lock.menu",readonlyOk:!1,kbd:"q",onSelect(b){p("toggle-tool-lock",{source:b}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",readonlyOk:!1,onSelect(b){p("unlock-all",{source:b});const P=[];for(const E of t.getCurrentPageShapes())E.isLocked&&P.push({id:E.id,type:E.type,isLocked:!1});P.length>0&&t.updateShapes(P)}},{id:"toggle-focus-mode",label:"action.toggle-focus-mode",menuLabel:"action.toggle-focus-mode.menu",readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(b){requestAnimationFrame(()=>{t.batch(()=>{p("toggle-focus-mode",{source:b}),o(),s(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:"action.toggle-grid",menuLabel:"action.toggle-grid.menu",readonlyOk:!0,kbd:"$'",onSelect(b){p("toggle-grid-mode",{source:b}),t.updateInstanceState({isGridMode:!t.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:"action.toggle-debug-mode",menuLabel:"action.toggle-debug-mode.menu",readonlyOk:!0,onSelect(b){p("toggle-debug-mode",{source:b}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(b){p("print",{source:b}),a()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(b){p("exit-pen-mode",{source:b}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(b){p("stop-following",{source:b}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(b){p("zoom-to-content",{source:b}),t.zoomToContent()}},{id:"toggle-lock",label:"action.toggle-lock",readonlyOk:!1,kbd:"!l",onSelect(b){t.mark("locking"),p("toggle-lock",{source:b}),t.toggleLock(t.getSelectedShapeIds())}}]);return e?e(t,x,void 0):x},[t,p,e,r,i,h,d,l,c,u,o,s,a]);return g.jsx(T$.Provider,{value:m,children:n})}function nn(){const e=w.useContext(T$);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function Kf(e){return e.filter(n=>n!=null&&n!==!1)}function Se(e,...n){const t=Kf(n);return t.length===0?null:{id:e,type:"group",checkbox:t.every(r=>r.type==="item"&&r.actionItem.checkbox),disabled:t.every(r=>r.disabled),readonlyOk:t.some(r=>r.readonlyOk),children:t}}function Vr(e,n,...t){const r=Kf(t);return r.length===0?null:{id:e,type:"submenu",label:n,children:r,disabled:r.every(o=>o.disabled),readonlyOk:r.some(o=>o.readonlyOk)}}function Cw(e,n={}){const{readonlyOk:t=!0,disabled:r=!1}=n;return{id:e,type:"custom",disabled:r,readonlyOk:t}}function N(e,n={}){if(!e)throw Error("No action item provided to menuItem");if(!e.label)throw Error("Trying to create menu item for action item that doesn't have a label");const{checked:t=!1,disabled:r=!1}=n;return{id:e.id,type:"item",actionItem:e,disabled:r,checked:t,readonlyOk:e.readonlyOk}}function WX(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>!(!r||e.isShapeOfType(r,"arrow")&&r.props.start.type==="binding"||e.isShapeOfType(r,"arrow")&&r.props.end.type==="binding"))}const $$=()=>{const e=U();return G("threeStackableItems",()=>WX(e).length>2,[e])};function GX(e){const n=e.getSelectedShapes(),t=[],r=new Map;n.forEach(s=>{s.type==="arrow"?t.push(s):r.set(s.id,s)});const o=t.filter(s=>!(s.props.start.type==="binding"&&!r.has(s.props.start.boundShapeId)||s.props.end.type==="binding"&&!r.has(s.props.end.boundShapeId)));return Array.from(r.values()).concat(o)}const Ew=()=>{const e=U();return G("allowGroup",()=>GX(e).length>1,[e])},kw=()=>{const e=U();return G("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},A$=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read,Vm=[0,390,428,468,580,640,840,1023],M$=ne.createContext(0);function YX({forceMobile:e=!1,children:n}){const t=U(),r=G("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?3:Vm.length-1;for(let i=0;i<s;i++)if(o>Vm[i]&&o<=Vm[i+1])return i;return s},[t]);return g.jsx(M$.Provider,{value:r,children:n})}function Qn(){return w.useContext(M$)}function Iw(){const e=U();return G("hasLinkShapeSelected",()=>{const n=e.getSelectedShapes();return n.length===1&&"url"in n[0].props&&n[0].type!=="embed"},[e])}const O$=ne.createContext({}),XX=({overrides:e,children:n})=>{const t=U(),r=nn(),o=G("selected count",()=>t.getSelectedShapeIds().length,[t]),s=o>0,i=o>1,a=o>2,l=$$(),c=Ew(),u=kw(),d=Iw(),h=Qn(),p=G("zoom is 1",()=>t.getZoomLevel()===1,[t]),m=w.useMemo(()=>{const f=[N(r["align-left"],{disabled:!i}),N(r["align-center-horizontal"],{disabled:!i}),N(r["align-right"],{disabled:!i}),N(r["stretch-horizontal"],{disabled:!i}),N(r["align-top"],{disabled:!i}),N(r["align-center-vertical"],{disabled:!i}),N(r["align-bottom"],{disabled:!i}),N(r["stretch-vertical"],{disabled:!i}),N(r["distribute-horizontal"],{disabled:!a}),N(r["distribute-vertical"],{disabled:!a}),N(r["stack-horizontal"],{disabled:!l}),N(r["stack-vertical"],{disabled:!l}),N(r["send-to-back"],{disabled:!s}),N(r["send-backward"],{disabled:!s}),N(r["bring-forward"],{disabled:!s}),N(r["bring-to-front"],{disabled:!s}),h<5?N(r["zoom-to-100"],{disabled:!!p}):N(r["rotate-ccw"],{disabled:!s}),N(r["rotate-cw"],{disabled:!s}),N(r["edit-link"],{disabled:!d}),c?N(r.group,{disabled:!i}):u?N(r.ungroup):N(r.group,{disabled:!i})];return e?e(t,f,{actions:r,oneSelected:s,twoSelected:i,threeSelected:a}):f},[t,p,c,e,r,s,i,a,l,u,d,h]);return g.jsx(O$.Provider,{value:m,children:n})};function qX(){const e=ne.useContext(O$);if(!e)throw new Error("useActionsMenuSchema must be used inside of a ActionsMenuSchemaProvider.");return e}function ZX(){const e=U();return G("onlyFlippableShape",()=>{const n=e.getSelectedShapes();return n.length===1&&n.every(t=>e.isShapeOfType(t,"group")||e.isShapeOfType(t,"arrow")||e.isShapeOfType(t,"line")||e.isShapeOfType(t,"draw"))},[e])}function R$(){const e=U();return G("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}const D$=ne.createContext({}),QX=je(function({overrides:n,children:t}){var A;const r=U(),o=nn(),s=R$(),i=ZX(),a=r.getSelectedShapes(),l=a.length,c=l>0,u=l>1,d=l>2,h=$$(),p=G("atLeastOneShapeOnPage",()=>r.getCurrentPageShapeIds().size>0,[]),m=G("isTransparentBg",()=>r.getInstanceState().exportBackground,[]),f=Ew(),S=kw(),v=!!((A=window.navigator.clipboard)!=null&&A.write),x=Iw(),b=r.getOnlySelectedShape(),P=c&&a.every(T=>r.isShapeOfType(T,"frame")),E=b&&r.isShapeOfType(b,"frame")&&r.getSortedChildIdsForParent(b).length>0,k=b&&r.isShapeOrAncestorLocked(b),I=w.useMemo(()=>Kf([Se("selection",s&&N(o["toggle-auto-size"]),x&&!k&&N(o["edit-link"]),c&&!k&&N(o.duplicate),f&&!k&&N(o.group),S&&!k&&N(o.ungroup),P&&!k&&N(o["remove-frame"]),E&&!k&&N(o["fit-frame-to-content"]),c&&N(o["toggle-lock"])),Se("modify",(u||i)&&Vr("arrange","context-menu.arrange",u&&Se("align",N(o["align-left"]),N(o["align-center-horizontal"]),N(o["align-right"]),N(o["align-top"]),N(o["align-center-vertical"]),N(o["align-bottom"])),d&&Se("distribute",N(o["distribute-horizontal"]),N(o["distribute-vertical"])),u&&Se("stretch",N(o["stretch-horizontal"]),N(o["stretch-vertical"])),i&&!k&&Se("flip",N(o["flip-horizontal"]),N(o["flip-vertical"])),u&&Se("order",N(o.pack,{disabled:!u}),h&&N(o["stack-vertical"]),h&&N(o["stack-horizontal"]))),c&&!k&&Vr("reorder","context-menu.reorder",Se("reorder",N(o["bring-to-front"]),N(o["bring-forward"]),N(o["send-backward"]),N(o["send-to-back"]))),c&&!k&&Cw("MOVE_TO_PAGE_MENU",{readonlyOk:!1})),Se("clipboard-group",c&&!k&&N(o.cut),c&&N(o.copy),A$&&N(o.paste)),p&&Se("conversions",Vr("copy-as","context-menu.copy-as",Se("copy-as-group",N(o["copy-as-svg"]),v&&N(o["copy-as-png"]),N(o["copy-as-json"])),Se("export-bg",N(o["toggle-transparent"],{checked:!m}))),Vr("export-as","context-menu.export-as",Se("export-as-group",N(o["export-as-svg"]),N(o["export-as-png"]),N(o["export-as-json"])),Se("export-bg,",N(o["toggle-transparent"],{checked:!m})))),p&&Se("set-selection-group",N(o["select-all"]),c&&N(o["select-none"])),c&&!k&&Se("delete-group",N(o.delete))]),[o,c,u,d,s,i,p,h,f,S,P,E,v,x,m,k]),_=G("overrides",()=>n?n(r,I,{actions:o,oneSelected:c,twoSelected:u,threeSelected:d,showAutoSizeToggle:s,showUngroup:S,onlyFlippableShapeSelected:i}):I,[o,S,I,r,c,i,n,s,d,u]);return g.jsx(D$.Provider,{value:_,children:t})});function j$(){const e=ne.useContext(D$);if(!e)throw new Error("useContextMenuSchema must be used inside of a TLUiContextMenuSchemaProvider.");return e}const L$=w.createContext({});function JX({overrides:e,children:n}){const t=U(),r=cl(),{addDialog:o}=$i(),s=_$(),i=w.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){t.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){t.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",readonlyOk:!1,onSelect(c){t.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",readonlyOk:!1,icon:"tool-pencil",kbd:"d,b,x",onSelect(c){t.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...qr.values].map(c=>({id:c,label:`tool.${c}`,readonlyOk:!1,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){t.batch(()=>{t.updateInstanceState({stylesForNextShape:{...t.getInstanceState().stylesForNextShape,[qr.id]:c}},{ephemeral:!0}),t.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",readonlyOk:!1,icon:"tool-arrow",kbd:"a",onSelect(c){t.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",readonlyOk:!1,icon:"tool-line",kbd:"l",onSelect(c){t.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",readonlyOk:!1,icon:"tool-frame",kbd:"f",onSelect(c){t.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",readonlyOk:!1,icon:"tool-text",kbd:"t",onSelect(c){t.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",readonlyOk:!1,icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",readonlyOk:!1,icon:"tool-note",kbd:"n",onSelect(c){t.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){t.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",readonlyOk:!1,icon:"tool-embed",onSelect(c){o({component:m$}),r("select-tool",{source:c,id:"embed"})}}];a.push({id:"highlight",label:"tool.highlight",readonlyOk:!1,icon:"tool-highlight",kbd:"!d",onSelect(c){t.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}});const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(t,l,{insertMedia:s}):l},[e,t,r,s,o]);return g.jsx(L$.Provider,{value:i,children:n})}function _w(){const e=w.useContext(L$);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const N$=ne.createContext({}),eq=je(function({overrides:n,children:t}){const r=U(),o=_w(),s=nn(),i=w.useMemo(()=>{const a=pe([Se("shortcuts-dialog.tools",N(s["toggle-tool-lock"]),N(o.select),N(o.draw),N(o.eraser),N(o.hand),N(o.rectangle),N(o.ellipse),N(o.arrow),N(o.line),N(o.text),N(o.frame),N(o.note),N(o.laser)),Se("shortcuts-dialog.file",N(s["insert-media"]),N(s.print)),Se("shortcuts-dialog.preferences",N(s["toggle-dark-mode"]),N(s["toggle-focus-mode"]),N(s["toggle-grid"])),Se("shortcuts-dialog.edit",N(s.undo),N(s.redo),N(s.cut),N(s.copy),N(s.paste),N(s["select-all"]),N(s.delete),N(s.duplicate),N(s["export-as-svg"]),N(s["export-as-png"])),Se("shortcuts-dialog.view",N(s["zoom-in"]),N(s["zoom-out"]),N(s["zoom-to-100"]),N(s["zoom-to-fit"]),N(s["zoom-to-selection"])),Se("shortcuts-dialog.transform",N(s["bring-to-front"]),N(s["bring-forward"]),N(s["send-backward"]),N(s["send-to-back"]),N(s.group),N(s.ungroup),N(s["flip-horizontal"]),N(s["flip-vertical"]),N(s["align-top"]),N(s["align-center-vertical"]),N(s["align-bottom"]),N(s["align-left"]),N(s["align-center-horizontal"]),N(s["align-right"]))]);return n?n(r,a,{tools:o,actions:s}):a},[r,n,s,o]);return g.jsx(N$.Provider,{value:i,children:t})});function tq(){const e=ne.useContext(N$);if(!e)throw new Error("Shortcuts must be used inside of a ShortcutsProvider.");return e}const nq=()=>{const e=be(),n=Yn(),t=tq();function r(o){if(!o||n&&!o.readonlyOk)return null;switch(o.type){case"group":return g.jsxs("div",{className:"tlui-shortcuts-dialog__group",children:[g.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:e(o.id)}),g.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:o.children.filter(s=>s&&s.type==="item"&&s.actionItem.kbd).map(r)})]},o.id);case"item":{const{id:s,label:i,shortcutsLabel:a,kbd:l}=o.actionItem;return g.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair",children:[g.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:e(a??i)}),g.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:g.jsx(zf,{children:l})})]},s)}}}return g.jsxs(g.Fragment,{children:[g.jsxs(Uf,{className:"tlui-shortcuts-dialog__header",children:[g.jsx(Hf,{children:e("shortcuts-dialog.title")}),g.jsx(Vf,{})]}),g.jsx(Xc,{className:"tlui-shortcuts-dialog__body",children:t.map(r)}),g.jsx("div",{className:"tlui-dialog__scrim"})]})};function F$(){const e=U();return{languages:wc,currentLanguage:e.user.getLocale()}}const z$=ne.createContext({}),rq=je(function({overrides:n,children:t}){const r=U(),o=nn(),s=r.getSelectedShapeIds().length,i=s>0,a=s>1,l=s>2,{languages:c,currentLanguage:u}=F$(),{addDialog:d}=$i(),h=w.useMemo(()=>{const p=pe([Se("top",Cw("LANGUAGE_MENU",{readonlyOk:!0}),N({id:"keyboard-shortcuts",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect(){d({component:nq})}}))]);return n?n(r,p,{actions:o,currentLanguage:u,languages:c,oneSelected:i,twoSelected:a,threeSelected:l}):p},[r,n,c,o,i,a,l,u,d]);return g.jsx(z$.Provider,{value:h,children:t})});function oq(){const e=ne.useContext(z$);if(!e)throw new Error("useHelpMenuSchema must be used inside of a helpTLUiMenuSchemaProvider.");return e}function B$(){const e=U();return G("useCanRedo",()=>e.getCanRedo(),[e])}function U$(){const e=U();return G("useCanUndo",()=>e.getCanUndo(),[e])}const H$=ne.createContext({});function sq({overrides:e,children:n}){var Y;const t=U(),r=nn(),s=Qn()<5,i=G("isDarkMode",()=>t.user.getIsDarkMode(),[t]),a=G("animationSpeed",()=>t.user.getAnimationSpeed(),[t]),l=G("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]),c=G("isGridMode",()=>t.getInstanceState().isGridMode,[t]),u=G("isSnapMode",()=>t.user.getIsSnapMode(),[t]),d=G("isToolLock",()=>t.getInstanceState().isToolLocked,[t]),h=G("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]),p=G("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]),m=G("exportBackground",()=>t.getInstanceState().exportBackground,[t]),f=G("emptyPage",()=>t.getCurrentPageShapeIds().size===0,[t]),S=G("selectedCount",()=>t.getSelectedShapeIds().length,[t]),v=S===0,x=S>0,b=S>1,P=S>2,E=!!((Y=window.navigator.clipboard)!=null&&Y.write),k=Iw(),I=R$(),_=Ew(),A=kw(),T=U$(),D=B$(),L=G("isZoomedTo100",()=>t.getZoomLevel()===1,[t]),z=G("oneEmbedSelected",()=>{const K=t.getOnlySelectedShape();return K?!!(t.isShapeOfType(K,"embed")&&K.props.url&&!t.isShapeOrAncestorLocked(K)):!1},[]),j=G("oneEmbeddableBookmarkSelected",()=>{const K=t.getOnlySelectedShape();return K?!!(t.isShapeOfType(K,"bookmark")&&K.props.url&&bo(K.props.url)&&!t.isShapeOrAncestorLocked(K)):!1},[]),F=w.useMemo(()=>{const K=Kf([Se("menu",Vr("file","menu.file",Se("print",N(r.print,{disabled:f}))),Vr("edit","menu.edit",Se("undo-actions",N(r.undo,{disabled:!T}),N(r.redo,{disabled:!D})),Se("clipboard-actions",N(r.cut,{disabled:v}),N(r.copy,{disabled:v}),N(r.paste,{disabled:!A$})),Se("conversions",Vr("copy-as","menu.copy-as",Se("copy-as-group",N(r["copy-as-svg"],{disabled:f}),N(r["copy-as-png"],{disabled:f||!E}),N(r["copy-as-json"],{disabled:f})),Se("export-bg",N(r["toggle-transparent"],{checked:!m}))),Vr("export-as","menu.export-as",Se("export-as-group",N(r["export-as-svg"],{disabled:f}),N(r["export-as-png"],{disabled:f}),N(r["export-as-json"],{disabled:f})),Se("export-bg",N(r["toggle-transparent"],{checked:!m})))),Se("set-selection-group",N(r["select-all"],{disabled:f}),N(r["select-none"],{disabled:!x})),Se("selection",I&&N(r["toggle-auto-size"]),k&&N(r["edit-link"]),N(r.duplicate,{disabled:!x}),_&&N(r.group),A&&N(r.ungroup),N(r["unlock-all"],{disabled:f})),Se("delete-group",N(r.delete,{disabled:!x})),Se("embeds",z&&N(r["open-embed-link"]),z&&N(r["convert-to-bookmark"]),j&&N(r["convert-to-embed"]))),Vr("view","menu.view",Se("view-actions",N(r["zoom-in"]),N(r["zoom-out"]),N(r["zoom-to-100"],{disabled:L}),N(r["zoom-to-fit"],{disabled:f}),N(r["zoom-to-selection"],{disabled:f||!x})))),Se("extras",N(r["insert-embed"]),N(r["insert-media"])),Se("preferences",Vr("preferences","menu.preferences",Se("preferences-actions",N(r["toggle-snap-mode"],{checked:u}),N(r["toggle-tool-lock"],{checked:d}),N(r["toggle-grid"],{checked:c}),N(r["toggle-dark-mode"],{checked:i}),N(r["toggle-focus-mode"],{checked:h}),N(r["toggle-edge-scrolling"],{checked:l===1}),N(r["toggle-reduce-motion"],{checked:a===0}),N(r["toggle-debug-mode"],{checked:p}))),s&&Cw("LANGUAGE_MENU",{readonlyOk:!0}))]);return e?e(t,K,{actions:r,noneSelected:v,oneSelected:x,twoSelected:b,threeSelected:P}):K},[t,e,r,x,b,P,f,s,_,A,k,E,I,v,T,D,a,i,c,u,d,h,m,p,l,L,j,z]);return g.jsx(H$.Provider,{value:F,children:n})}function iq(){const e=ne.useContext(H$);if(!e)throw new Error("useMenuSchema must be used inside of a TLUiMenuSchemaProvider.");return e}function Ne(e){return{id:e.id,type:"item",readonlyOk:e.readonlyOk,toolItem:e}}const V$=ne.createContext([]);function aq({overrides:e,children:n}){const t=U(),r=_w(),o=ne.useMemo(()=>{const s=pe([Ne(r.select),Ne(r.hand),Ne(r.draw),Ne(r.eraser),Ne(r.arrow),Ne(r.text),Ne(r.note),Ne(r.asset),Ne(r.rectangle),Ne(r.ellipse),Ne(r.diamond),Ne(r.triangle),Ne(r.trapezoid),Ne(r.rhombus),Ne(r.hexagon),Ne(r.cloud),Ne(r.star),Ne(r.oval),Ne(r["x-box"]),Ne(r["check-box"]),Ne(r["arrow-left"]),Ne(r["arrow-up"]),Ne(r["arrow-down"]),Ne(r["arrow-right"]),Ne(r.line),Ne(r.highlight),Ne(r.frame),Ne(r.laser)]);return e?e(t,s,{tools:r}):s},[t,e,r]);return g.jsx(V$.Provider,{value:o,children:n})}function K$(){const e=ne.useContext(V$);if(!e)throw new Error("useToolbarSchema must be used within a ToolbarSchemaProvider");return e}function lq(){const{addToast:e,removeToast:n,clearToasts:t}=ao(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=$i(),l=Qn()<5,c=be();return w.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,e,o,t,c,s,n,i,l])}function cq(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of Xr(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return{actionsMenu:(r,o,s)=>{for(const i of e)i.actionsMenu&&(o=i.actionsMenu(r,o,{...n,...s}));return o},actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,n));return o},contextMenu:(r,o,s)=>{for(const i of e)i.contextMenu&&(o=i.contextMenu(r,o,{...n,...s}));return o},helpMenu:(r,o,s)=>{for(const i of e)i.helpMenu&&(o=i.helpMenu(r,o,{...n,...s}));return o},menu:(r,o,s)=>{for(const i of e)i.menu&&(o=i.menu(r,o,{...n,...s}));return o},toolbar:(r,o,s)=>{for(const i of e)i.toolbar&&(o=i.toolbar(r,o,{...n,...s}));return o},keyboardShortcutsMenu:(r,o,s)=>{for(const i of e)i.keyboardShortcutsMenu&&(o=i.keyboardShortcutsMenu(r,o,{...n,...s}));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...n,...s}));return o},translations:t}}function W$(e){return w.useMemo(()=>e,e)}function uq(e){const n=W$(e==null?[]:Array.isArray(e)?e:[e]);return w.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of Xr(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function dq(e){const n=lq(),t=W$(e==null?[]:Array.isArray(e)?e:[e]);return w.useMemo(()=>cq(t,n),[t,n])}function hq({overrides:e,assetUrls:n,onUiEvent:t,forceMobile:r,children:o}){return g.jsx(ZG,{assetUrls:GG(n),children:g.jsx(eY,{overrides:uq(e),children:g.jsx(bX,{onEvent:t,children:g.jsx(LX,{children:g.jsx(FX,{children:g.jsx(YX,{forceMobile:r,children:g.jsx(pq,{overrides:e,children:o})})})})})})})}function pq({overrides:e,children:n}){const t=dq(e);return g.jsx(KX,{overrides:t.actions,children:g.jsx(JX,{overrides:t.tools,children:g.jsx(aq,{overrides:t.toolbar,children:g.jsx(XX,{overrides:t.actionsMenu,children:g.jsx(eq,{overrides:t.keyboardShortcutsMenu,children:g.jsx(QX,{overrides:t.contextMenu,children:g.jsx(rq,{overrides:t.helpMenu,children:g.jsx(sq,{overrides:t.menu,children:n})})})})})})})})}function fq(){const e=U(),t=nn()["back-to-content"],[r,o]=w.useState(!1);return w.useEffect(()=>{let s=!1;const i=setInterval(()=>{const a=e.getRenderingShapes(),l=e.getRenderingBounds(),u=a.filter(d=>d.maskedPageBounds&&l.includes(d.maskedPageBounds)).length===0&&e.getCurrentPageShapes().length>0;s!==u&&(o(u),s=u)},1e3);return()=>{clearInterval(i)}},[e]),r?g.jsx(ie,{iconLeft:t.icon,label:t.label,type:"low",onClick:()=>{t.onSelect("helper-buttons"),o(!1)}}):null}const gq=w.createContext(void 0);function Tw(e){const n=w.useContext(gq);return e||n||"ltr"}const mq=["top","right","bottom","left"],Ts=Math.min,Nn=Math.max,Wp=Math.round,Ud=Math.floor,$s=e=>({x:e,y:e}),yq={left:"right",right:"left",bottom:"top",top:"bottom"},Sq={start:"end",end:"start"};function rv(e,n,t){return Nn(e,Ts(n,t))}function No(e,n){return typeof e=="function"?e(n):e}function Fo(e){return e.split("-")[0]}function ul(e){return e.split("-")[1]}function $w(e){return e==="x"?"y":"x"}function Aw(e){return e==="y"?"height":"width"}function dl(e){return["top","bottom"].includes(Fo(e))?"y":"x"}function Mw(e){return $w(dl(e))}function vq(e,n,t){t===void 0&&(t=!1);const r=ul(e),o=Mw(e),s=Aw(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=Gp(i)),[i,Gp(i)]}function wq(e){const n=Gp(e);return[ov(e),n,ov(n)]}function ov(e){return e.replace(/start|end/g,n=>Sq[n])}function xq(e,n,t){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(e){case"top":case"bottom":return t?n?o:r:n?r:o;case"left":case"right":return n?s:i;default:return[]}}function bq(e,n,t,r){const o=ul(e);let s=xq(Fo(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(ov)))),s}function Gp(e){return e.replace(/left|right|bottom|top/g,n=>yq[n])}function Pq(e){return{top:0,right:0,bottom:0,left:0,...e}}function G$(e){return typeof e!="number"?Pq(e):{top:e,right:e,bottom:e,left:e}}function Yp(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}function TC(e,n,t){let{reference:r,floating:o}=e;const s=dl(n),i=Mw(n),a=Aw(i),l=Fo(n),c=s==="y",u=r.x+r.width/2-o.width/2,d=r.y+r.height/2-o.height/2,h=r[a]/2-o[a]/2;let p;switch(l){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(ul(n)){case"start":p[i]-=h*(t&&c?-1:1);break;case"end":p[i]+=h*(t&&c?-1:1);break}return p}const Cq=async(e,n,t)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=t,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(n));let c=await i.getElementRects({reference:e,floating:n,strategy:o}),{x:u,y:d}=TC(c,r,l),h=r,p={},m=0;for(let f=0;f<a.length;f++){const{name:S,fn:v}=a[f],{x,y:b,data:P,reset:E}=await v({x:u,y:d,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:n}});u=x??u,d=b??d,p={...p,[S]:{...p[S],...P}},E&&m<=50&&(m++,typeof E=="object"&&(E.placement&&(h=E.placement),E.rects&&(c=E.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):E.rects),{x:u,y:d}=TC(c,h,l)),f=-1)}return{x:u,y:d,placement:h,strategy:o,middlewareData:p}};async function qc(e,n){var t;n===void 0&&(n={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:h=!1,padding:p=0}=No(n,e),m=G$(p),S=a[h?d==="floating"?"reference":"floating":d],v=Yp(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(S)))==null||t?S:S.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),x=d==="floating"?{...i.floating,x:r,y:o}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),P=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},E=Yp(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:x,offsetParent:b,strategy:l}):x);return{top:(v.top-E.top+m.top)/P.y,bottom:(E.bottom-v.bottom+m.bottom)/P.y,left:(v.left-E.left+m.left)/P.x,right:(E.right-v.right+m.right)/P.x}}const Eq=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=n,{element:c,padding:u=0}=No(e,n)||{};if(c==null)return{};const d=G$(u),h={x:t,y:r},p=Mw(o),m=Aw(p),f=await i.getDimensions(c),S=p==="y",v=S?"top":"left",x=S?"bottom":"right",b=S?"clientHeight":"clientWidth",P=s.reference[m]+s.reference[p]-h[p]-s.floating[m],E=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=k?k[b]:0;(!I||!await(i.isElement==null?void 0:i.isElement(k)))&&(I=a.floating[b]||s.floating[m]);const _=P/2-E/2,A=I/2-f[m]/2-1,T=Ts(d[v],A),D=Ts(d[x],A),L=T,z=I-f[m]-D,j=I/2-f[m]/2+_,F=rv(L,j,z),Y=!l.arrow&&ul(o)!=null&&j!==F&&s.reference[m]/2-(j<L?T:D)-f[m]/2<0,K=Y?j<L?j-L:j-z:0;return{[p]:h[p]+K,data:{[p]:F,centerOffset:j-F-K,...Y&&{alignmentOffset:K}},reset:Y}}}),kq=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var t,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=n,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:f=!0,...S}=No(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const v=Fo(o),x=Fo(a)===a,b=await(l.isRTL==null?void 0:l.isRTL(c.floating)),P=h||(x||!f?[Gp(a)]:wq(a));!h&&m!=="none"&&P.push(...bq(a,f,m,b));const E=[a,...P],k=await qc(n,S),I=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&I.push(k[v]),d){const L=vq(o,i,b);I.push(k[L[0]],k[L[1]])}if(_=[..._,{placement:o,overflows:I}],!I.every(L=>L<=0)){var A,T;const L=(((A=s.flip)==null?void 0:A.index)||0)+1,z=E[L];if(z)return{data:{index:L,overflows:_},reset:{placement:z}};let j=(T=_.filter(F=>F.overflows[0]<=0).sort((F,Y)=>F.overflows[1]-Y.overflows[1])[0])==null?void 0:T.placement;if(!j)switch(p){case"bestFit":{var D;const F=(D=_.map(Y=>[Y.placement,Y.overflows.filter(K=>K>0).reduce((K,H)=>K+H,0)]).sort((Y,K)=>Y[1]-K[1])[0])==null?void 0:D[0];F&&(j=F);break}case"initialPlacement":j=a;break}if(o!==j)return{reset:{placement:j}}}return{}}}};function $C(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function AC(e){return mq.some(n=>e[n]>=0)}const Iq=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=No(e,n);switch(r){case"referenceHidden":{const s=await qc(n,{...o,elementContext:"reference"}),i=$C(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:AC(i)}}}case"escaped":{const s=await qc(n,{...o,altBoundary:!0}),i=$C(s,t.floating);return{data:{escapedOffsets:i,escaped:AC(i)}}}default:return{}}}}};async function _q(e,n){const{placement:t,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Fo(t),a=ul(t),l=dl(t)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,d=No(n,e);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...d};return a&&typeof m=="number"&&(p=a==="end"?m*-1:m),l?{x:p*u,y:h*c}:{x:h*c,y:p*u}}const Tq=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var t,r;const{x:o,y:s,placement:i,middlewareData:a}=n,l=await _q(n,e);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},$q=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:t,y:r,placement:o}=n,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:S=>{let{x:v,y:x}=S;return{x:v,y:x}}},...l}=No(e,n),c={x:t,y:r},u=await qc(n,l),d=dl(Fo(o)),h=$w(d);let p=c[h],m=c[d];if(s){const S=h==="y"?"top":"left",v=h==="y"?"bottom":"right",x=p+u[S],b=p-u[v];p=rv(x,p,b)}if(i){const S=d==="y"?"top":"left",v=d==="y"?"bottom":"right",x=m+u[S],b=m-u[v];m=rv(x,m,b)}const f=a.fn({...n,[h]:p,[d]:m});return{...f,data:{x:f.x-t,y:f.y-r}}}}},Aq=function(e){return e===void 0&&(e={}),{options:e,fn(n){const{x:t,y:r,placement:o,rects:s,middlewareData:i}=n,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=No(e,n),u={x:t,y:r},d=dl(o),h=$w(d);let p=u[h],m=u[d];const f=No(a,n),S=typeof f=="number"?{mainAxis:f,crossAxis:0}:{mainAxis:0,crossAxis:0,...f};if(l){const b=h==="y"?"height":"width",P=s.reference[h]-s.floating[b]+S.mainAxis,E=s.reference[h]+s.reference[b]-S.mainAxis;p<P?p=P:p>E&&(p=E)}if(c){var v,x;const b=h==="y"?"width":"height",P=["top","left"].includes(Fo(o)),E=s.reference[d]-s.floating[b]+(P&&((v=i.offset)==null?void 0:v[d])||0)+(P?0:S.crossAxis),k=s.reference[d]+s.reference[b]+(P?0:((x=i.offset)==null?void 0:x[d])||0)-(P?S.crossAxis:0);m<E?m=E:m>k&&(m=k)}return{[h]:p,[d]:m}}}},Mq=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:t,rects:r,platform:o,elements:s}=n,{apply:i=()=>{},...a}=No(e,n),l=await qc(n,a),c=Fo(t),u=ul(t),d=dl(t)==="y",{width:h,height:p}=r.floating;let m,f;c==="top"||c==="bottom"?(m=c,f=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(f=c,m=u==="end"?"top":"bottom");const S=p-l[m],v=h-l[f],x=!n.middlewareData.shift;let b=S,P=v;if(d){const k=h-l.left-l.right;P=u||x?Ts(v,k):k}else{const k=p-l.top-l.bottom;b=u||x?Ts(S,k):k}if(x&&!u){const k=Nn(l.left,0),I=Nn(l.right,0),_=Nn(l.top,0),A=Nn(l.bottom,0);d?P=h-2*(k!==0||I!==0?k+I:Nn(l.left,l.right)):b=p-2*(_!==0||A!==0?_+A:Nn(l.top,l.bottom))}await i({...n,availableWidth:P,availableHeight:b});const E=await o.getDimensions(s.floating);return h!==E.width||p!==E.height?{reset:{rects:!0}}:{}}}};function As(e){return Y$(e)?(e.nodeName||"").toLowerCase():"#document"}function Kn(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function Yo(e){var n;return(n=(Y$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function Y$(e){return e instanceof Node||e instanceof Kn(e).Node}function zo(e){return e instanceof Element||e instanceof Kn(e).Element}function ro(e){return e instanceof HTMLElement||e instanceof Kn(e).HTMLElement}function MC(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Kn(e).ShadowRoot}function Tu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=gr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function Oq(e){return["table","td","th"].includes(As(e))}function Ow(e){const n=Rw(),t=gr(e);return t.transform!=="none"||t.perspective!=="none"||(t.containerType?t.containerType!=="normal":!1)||!n&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!n&&(t.filter?t.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(t.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(t.contain||"").includes(r))}function X$(e){let n=Va(e);for(;ro(n)&&!Wf(n);){if(Ow(n))return n;n=Va(n)}return null}function Rw(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Wf(e){return["html","body","#document"].includes(As(e))}function gr(e){return Kn(e).getComputedStyle(e)}function Gf(e){return zo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Va(e){if(As(e)==="html")return e;const n=e.assignedSlot||e.parentNode||MC(e)&&e.host||Yo(e);return MC(n)?n.host:n}function q$(e){const n=Va(e);return Wf(n)?e.ownerDocument?e.ownerDocument.body:e.body:ro(n)&&Tu(n)?n:q$(n)}function Zc(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=q$(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Kn(o);return s?n.concat(i,i.visualViewport||[],Tu(o)?o:[],i.frameElement&&t?Zc(i.frameElement):[]):n.concat(o,Zc(o,[],t))}function Z$(e){const n=gr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=ro(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=Wp(t)!==s||Wp(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function Dw(e){return zo(e)?e:e.contextElement}function $a(e){const n=Dw(e);if(!ro(n))return $s(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=Z$(n);let i=(s?Wp(t.width):t.width)/r,a=(s?Wp(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Rq=$s(0);function Q$(e){const n=Kn(e);return!Rw()||!n.visualViewport?Rq:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function Dq(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==Kn(e)?!1:n}function xi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=Dw(e);let i=$s(1);n&&(r?zo(r)&&(i=$a(r)):i=$a(e));const a=Dq(s,t,r)?Q$(s):$s(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,d=o.height/i.y;if(s){const h=Kn(s),p=r&&zo(r)?Kn(r):r;let m=h.frameElement;for(;m&&r&&p!==h;){const f=$a(m),S=m.getBoundingClientRect(),v=gr(m),x=S.left+(m.clientLeft+parseFloat(v.paddingLeft))*f.x,b=S.top+(m.clientTop+parseFloat(v.paddingTop))*f.y;l*=f.x,c*=f.y,u*=f.x,d*=f.y,l+=x,c+=b,m=Kn(m).frameElement}}return Yp({width:u,height:d,x:l,y:c})}const jq=[":popover-open",":modal"];function J$(e){let n=!1,t=0,r=0;function o(s){try{n=n||e.matches(s)}catch{}}if(jq.forEach(s=>{o(s)}),n){const s=X$(e);if(s){const i=s.getBoundingClientRect();t=i.x,r=i.y}}return[n,t,r]}function Lq(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const s=Yo(r),[i]=n?J$(n.floating):[!1];if(r===s||i)return t;let a={scrollLeft:0,scrollTop:0},l=$s(1);const c=$s(0),u=ro(r);if((u||!u&&o!=="fixed")&&((As(r)!=="body"||Tu(s))&&(a=Gf(r)),ro(r))){const d=xi(r);l=$a(r),c.x=d.x+r.clientLeft,c.y=d.y+r.clientTop}return{width:t.width*l.x,height:t.height*l.y,x:t.x*l.x-a.scrollLeft*l.x+c.x,y:t.y*l.y-a.scrollTop*l.y+c.y}}function Nq(e){return Array.from(e.getClientRects())}function eA(e){return xi(Yo(e)).left+Gf(e).scrollLeft}function Fq(e){const n=Yo(e),t=Gf(e),r=e.ownerDocument.body,o=Nn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=Nn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+eA(e);const a=-t.scrollTop;return gr(r).direction==="rtl"&&(i+=Nn(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function zq(e,n){const t=Kn(e),r=Yo(e),o=t.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const c=Rw();(!c||c&&n==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function Bq(e,n){const t=xi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=ro(e)?$a(e):$s(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function OC(e,n,t){let r;if(n==="viewport")r=zq(e,t);else if(n==="document")r=Fq(Yo(e));else if(zo(n))r=Bq(n,t);else{const o=Q$(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return Yp(r)}function tA(e,n){const t=Va(e);return t===n||!zo(t)||Wf(t)?!1:gr(t).position==="fixed"||tA(t,n)}function Uq(e,n){const t=n.get(e);if(t)return t;let r=Zc(e,[],!1).filter(a=>zo(a)&&As(a)!=="body"),o=null;const s=gr(e).position==="fixed";let i=s?Va(e):e;for(;zo(i)&&!Wf(i);){const a=gr(i),l=Ow(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Tu(i)&&!l&&tA(e,i))?r=r.filter(u=>u!==i):o=a,i=Va(i)}return n.set(e,r),r}function Hq(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?Uq(n,this._c):[].concat(t),r],a=i[0],l=i.reduce((c,u)=>{const d=OC(n,u,o);return c.top=Nn(d.top,c.top),c.right=Ts(d.right,c.right),c.bottom=Ts(d.bottom,c.bottom),c.left=Nn(d.left,c.left),c},OC(n,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Vq(e){const{width:n,height:t}=Z$(e);return{width:n,height:t}}function Kq(e,n,t,r){const o=ro(n),s=Yo(n),i=t==="fixed",a=xi(e,!0,i,n);let l={scrollLeft:0,scrollTop:0};const c=$s(0);if(o||!o&&!i)if((As(n)!=="body"||Tu(s))&&(l=Gf(n)),o){const f=xi(n,!0,i,n);c.x=f.x+n.clientLeft,c.y=f.y+n.clientTop}else s&&(c.x=eA(s));let u=a.left+l.scrollLeft-c.x,d=a.top+l.scrollTop-c.y;const[h,p,m]=J$(r);return h&&(u+=p,d+=m,o&&(u+=n.clientLeft,d+=n.clientTop)),{x:u,y:d,width:a.width,height:a.height}}function RC(e,n){return!ro(e)||gr(e).position==="fixed"?null:n?n(e):e.offsetParent}function nA(e,n){const t=Kn(e);if(!ro(e))return t;let r=RC(e,n);for(;r&&Oq(r)&&gr(r).position==="static";)r=RC(r,n);return r&&(As(r)==="html"||As(r)==="body"&&gr(r).position==="static"&&!Ow(r))?t:r||X$(e)||t}const Wq=async function(e){const n=this.getOffsetParent||nA,t=this.getDimensions;return{reference:Kq(e.reference,await n(e.floating),e.strategy,e.floating),floating:{x:0,y:0,...await t(e.floating)}}};function Gq(e){return gr(e).direction==="rtl"}const Yq={convertOffsetParentRelativeRectToViewportRelativeRect:Lq,getDocumentElement:Yo,getClippingRect:Hq,getOffsetParent:nA,getElementRects:Wq,getClientRects:Nq,getDimensions:Vq,getScale:$a,isElement:zo,isRTL:Gq};function Xq(e,n){let t=null,r;const o=Yo(e);function s(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const{left:c,top:u,width:d,height:h}=e.getBoundingClientRect();if(a||n(),!d||!h)return;const p=Ud(u),m=Ud(o.clientWidth-(c+d)),f=Ud(o.clientHeight-(u+h)),S=Ud(c),x={rootMargin:-p+"px "+-m+"px "+-f+"px "+-S+"px",threshold:Nn(0,Ts(1,l))||1};let b=!0;function P(E){const k=E[0].intersectionRatio;if(k!==l){if(!b)return i();k?i(!1,k):r=setTimeout(()=>{i(!1,1e-7)},100)}b=!1}try{t=new IntersectionObserver(P,{...x,root:o.ownerDocument})}catch{t=new IntersectionObserver(P,x)}t.observe(e)}return i(!0),s}function qq(e,n,t,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Dw(e),u=o||s?[...c?Zc(c):[],...Zc(n)]:[];u.forEach(v=>{o&&v.addEventListener("scroll",t,{passive:!0}),s&&v.addEventListener("resize",t)});const d=c&&a?Xq(c,t):null;let h=-1,p=null;i&&(p=new ResizeObserver(v=>{let[x]=v;x&&x.target===c&&p&&(p.unobserve(n),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var b;(b=p)==null||b.observe(n)})),t()}),c&&!l&&p.observe(c),p.observe(n));let m,f=l?xi(e):null;l&&S();function S(){const v=xi(e);f&&(v.x!==f.x||v.y!==f.y||v.width!==f.width||v.height!==f.height)&&t(),f=v,m=requestAnimationFrame(S)}return t(),()=>{var v;u.forEach(x=>{o&&x.removeEventListener("scroll",t),s&&x.removeEventListener("resize",t)}),d==null||d(),(v=p)==null||v.disconnect(),p=null,l&&cancelAnimationFrame(m)}}const Zq=$q,Qq=kq,Jq=Mq,eZ=Iq,DC=Eq,tZ=Aq,nZ=(e,n,t)=>{const r=new Map,o={platform:Yq,...t},s={...o.platform,_c:r};return Cq(e,n,{...o,platform:s})},rZ=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?DC({element:r.current,padding:o}).fn(t):{}:r?DC({element:r,padding:o}).fn(t):{}}}};var Vh=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Xp(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let t,r,o;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(t=e.length,t!==n.length)return!1;for(r=t;r--!==0;)if(!Xp(e[r],n[r]))return!1;return!0}if(o=Object.keys(e),t=o.length,t!==Object.keys(n).length)return!1;for(r=t;r--!==0;)if(!{}.hasOwnProperty.call(n,o[r]))return!1;for(r=t;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!Xp(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function rA(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function jC(e,n){const t=rA(e);return Math.round(n*t)/t}function LC(e){const n=w.useRef(e);return Vh(()=>{n.current=e}),n}function oZ(e){e===void 0&&(e={});const{placement:n="bottom",strategy:t="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[u,d]=w.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[h,p]=w.useState(r);Xp(h,r)||p(r);const[m,f]=w.useState(null),[S,v]=w.useState(null),x=w.useCallback(K=>{K!==k.current&&(k.current=K,f(K))},[]),b=w.useCallback(K=>{K!==I.current&&(I.current=K,v(K))},[]),P=s||m,E=i||S,k=w.useRef(null),I=w.useRef(null),_=w.useRef(u),A=l!=null,T=LC(l),D=LC(o),L=w.useCallback(()=>{if(!k.current||!I.current)return;const K={placement:n,strategy:t,middleware:h};D.current&&(K.platform=D.current),nZ(k.current,I.current,K).then(H=>{const B={...H,isPositioned:!0};z.current&&!Xp(_.current,B)&&(_.current=B,ll.flushSync(()=>{d(B)}))})},[h,n,t,D]);Vh(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,d(K=>({...K,isPositioned:!1})))},[c]);const z=w.useRef(!1);Vh(()=>(z.current=!0,()=>{z.current=!1}),[]),Vh(()=>{if(P&&(k.current=P),E&&(I.current=E),P&&E){if(T.current)return T.current(P,E,L);L()}},[P,E,L,T,A]);const j=w.useMemo(()=>({reference:k,floating:I,setReference:x,setFloating:b}),[x,b]),F=w.useMemo(()=>({reference:P,floating:E}),[P,E]),Y=w.useMemo(()=>{const K={position:t,left:0,top:0};if(!F.floating)return K;const H=jC(F.floating,u.x),B=jC(F.floating,u.y);return a?{...K,transform:"translate("+H+"px, "+B+"px)",...rA(F.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:H,top:B}},[t,a,F.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:L,refs:j,elements:F,floatingStyles:Y}),[u,L,j,F,Y])}function oA(e){const[n,t]=w.useState(void 0);return wi(()=>{if(e){t({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;t({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else t(void 0)},[e]),n}const sA="Popper",[iA,Yf]=io(sA),[sZ,aA]=iA(sA),iZ=e=>{const{__scopePopper:n,children:t}=e,[r,o]=w.useState(null);return w.createElement(sZ,{scope:n,anchor:r,onAnchorChange:o},t)},aZ="PopperAnchor",lZ=w.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=aA(aZ,t),i=w.useRef(null),a=Ge(n,i);return w.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:w.createElement(ze.div,Q({},o,{ref:a}))}),lA="PopperContent",[cZ,yte]=iA(lA),uZ=w.forwardRef((e,n)=>{var t,r,o,s,i,a,l,c;const{__scopePopper:u,side:d="bottom",sideOffset:h=0,align:p="center",alignOffset:m=0,arrowPadding:f=0,avoidCollisions:S=!0,collisionBoundary:v=[],collisionPadding:x=0,sticky:b="partial",hideWhenDetached:P=!1,updatePositionStrategy:E="optimized",onPlaced:k,...I}=e,_=aA(lA,u),[A,T]=w.useState(null),D=Ge(n,Ye=>T(Ye)),[L,z]=w.useState(null),j=oA(L),F=(t=j==null?void 0:j.width)!==null&&t!==void 0?t:0,Y=(r=j==null?void 0:j.height)!==null&&r!==void 0?r:0,K=d+(p!=="center"?"-"+p:""),H=typeof x=="number"?x:{top:0,right:0,bottom:0,left:0,...x},B=Array.isArray(v)?v:[v],V=B.length>0,X={padding:H,boundary:B.filter(dZ),altBoundary:V},{refs:ae,floatingStyles:ye,placement:Ie,isPositioned:le,middlewareData:ke}=oZ({strategy:"fixed",placement:K,whileElementsMounted:(...Ye)=>qq(...Ye,{animationFrame:E==="always"}),elements:{reference:_.anchor},middleware:[Tq({mainAxis:h+Y,alignmentAxis:m}),S&&Zq({mainAxis:!0,crossAxis:!1,limiter:b==="partial"?tZ():void 0,...X}),S&&Qq({...X}),Jq({...X,apply:({elements:Ye,rects:kt,availableWidth:co,availableHeight:pl})=>{const{width:fl,height:Jf}=kt.reference,Oi=Ye.floating.style;Oi.setProperty("--radix-popper-available-width",`${co}px`),Oi.setProperty("--radix-popper-available-height",`${pl}px`),Oi.setProperty("--radix-popper-anchor-width",`${fl}px`),Oi.setProperty("--radix-popper-anchor-height",`${Jf}px`)}}),L&&rZ({element:L,padding:f}),hZ({arrowWidth:F,arrowHeight:Y}),P&&eZ({strategy:"referenceHidden",...X})]}),[Ae,nt]=cA(Ie),Pe=en(k);wi(()=>{le&&(Pe==null||Pe())},[le,Pe]);const ct=(o=ke.arrow)===null||o===void 0?void 0:o.x,Be=(s=ke.arrow)===null||s===void 0?void 0:s.y,Jn=((i=ke.arrow)===null||i===void 0?void 0:i.centerOffset)!==0,[Tn,$n]=w.useState();return wi(()=>{A&&$n(window.getComputedStyle(A).zIndex)},[A]),w.createElement("div",{ref:ae.setFloating,"data-radix-popper-content-wrapper":"",style:{...ye,transform:le?ye.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Tn,"--radix-popper-transform-origin":[(a=ke.transformOrigin)===null||a===void 0?void 0:a.x,(l=ke.transformOrigin)===null||l===void 0?void 0:l.y].join(" ")},dir:e.dir},w.createElement(cZ,{scope:u,placedSide:Ae,onArrowChange:z,arrowX:ct,arrowY:Be,shouldHideArrow:Jn},w.createElement(ze.div,Q({"data-side":Ae,"data-align":nt},I,{ref:D,style:{...I.style,animation:le?void 0:"none",opacity:(c=ke.hide)!==null&&c!==void 0&&c.referenceHidden?0:void 0}}))))});function dZ(e){return e!==null}const hZ=e=>({name:"transformOrigin",options:e,fn(n){var t,r,o,s,i;const{placement:a,rects:l,middlewareData:c}=n,d=((t=c.arrow)===null||t===void 0?void 0:t.centerOffset)!==0,h=d?0:e.arrowWidth,p=d?0:e.arrowHeight,[m,f]=cA(a),S={start:"0%",center:"50%",end:"100%"}[f],v=((r=(o=c.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+h/2,x=((s=(i=c.arrow)===null||i===void 0?void 0:i.y)!==null&&s!==void 0?s:0)+p/2;let b="",P="";return m==="bottom"?(b=d?S:`${v}px`,P=`${-p}px`):m==="top"?(b=d?S:`${v}px`,P=`${l.floating.height+p}px`):m==="right"?(b=`${-p}px`,P=d?S:`${x}px`):m==="left"&&(b=`${l.floating.width+p}px`,P=d?S:`${x}px`),{data:{x:b,y:P}}}});function cA(e){const[n,t="center"]=e.split("-");return[n,t]}const jw=iZ,uA=lZ,dA=uZ,Km="rovingFocusGroup.onEntryFocus",pZ={bubbles:!1,cancelable:!0},Lw="RovingFocusGroup",[sv,hA,fZ]=Df(Lw),[gZ,pA]=io(Lw,[fZ]),[mZ,yZ]=gZ(Lw),SZ=w.forwardRef((e,n)=>w.createElement(sv.Provider,{scope:e.__scopeRovingFocusGroup},w.createElement(sv.Slot,{scope:e.__scopeRovingFocusGroup},w.createElement(vZ,Q({},e,{ref:n}))))),vZ=w.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,...u}=e,d=w.useRef(null),h=Ge(n,d),p=Tw(s),[m=null,f]=Bs({prop:i,defaultProp:a,onChange:l}),[S,v]=w.useState(!1),x=en(c),b=hA(t),P=w.useRef(!1),[E,k]=w.useState(0);return w.useEffect(()=>{const I=d.current;if(I)return I.addEventListener(Km,x),()=>I.removeEventListener(Km,x)},[x]),w.createElement(mZ,{scope:t,orientation:r,dir:p,loop:o,currentTabStopId:m,onItemFocus:w.useCallback(I=>f(I),[f]),onItemShiftTab:w.useCallback(()=>v(!0),[]),onFocusableItemAdd:w.useCallback(()=>k(I=>I+1),[]),onFocusableItemRemove:w.useCallback(()=>k(I=>I-1),[])},w.createElement(ze.div,Q({tabIndex:S||E===0?-1:0,"data-orientation":r},u,{ref:h,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{P.current=!0}),onFocus:se(e.onFocus,I=>{const _=!P.current;if(I.target===I.currentTarget&&_&&!S){const A=new CustomEvent(Km,pZ);if(I.currentTarget.dispatchEvent(A),!A.defaultPrevented){const T=b().filter(F=>F.focusable),D=T.find(F=>F.active),L=T.find(F=>F.id===m),j=[D,L,...T].filter(Boolean).map(F=>F.ref.current);fA(j)}}P.current=!1}),onBlur:se(e.onBlur,()=>v(!1))})))}),wZ="RovingFocusGroupItem",xZ=w.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Ao(),l=s||a,c=yZ(wZ,t),u=c.currentTabStopId===l,d=hA(t),{onFocusableItemAdd:h,onFocusableItemRemove:p}=c;return w.useEffect(()=>{if(r)return h(),()=>p()},[r,h,p]),w.createElement(sv.ItemSlot,{scope:t,id:l,focusable:r,active:o},w.createElement(ze.span,Q({tabIndex:u?0:-1,"data-orientation":c.orientation},i,{ref:n,onMouseDown:se(e.onMouseDown,m=>{r?c.onItemFocus(l):m.preventDefault()}),onFocus:se(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(e.onKeyDown,m=>{if(m.key==="Tab"&&m.shiftKey){c.onItemShiftTab();return}if(m.target!==m.currentTarget)return;const f=CZ(m,c.orientation,c.dir);if(f!==void 0){m.preventDefault();let v=d().filter(x=>x.focusable).map(x=>x.ref.current);if(f==="last")v.reverse();else if(f==="prev"||f==="next"){f==="prev"&&v.reverse();const x=v.indexOf(m.currentTarget);v=c.loop?EZ(v,x+1):v.slice(x+1)}setTimeout(()=>fA(v))}})})))}),bZ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function PZ(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function CZ(e,n,t){const r=PZ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return bZ[r]}function fA(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function EZ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const kZ=SZ,IZ=xZ,iv=["Enter"," "],_Z=["ArrowDown","PageUp","Home"],gA=["ArrowUp","PageDown","End"],TZ=[..._Z,...gA],$Z={ltr:[...iv,"ArrowRight"],rtl:[...iv,"ArrowLeft"]},AZ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xf="Menu",[Qc,MZ,OZ]=Df(Xf),[Ai,qf]=io(Xf,[OZ,Yf,pA]),Zf=Yf(),mA=pA(),[yA,Us]=Ai(Xf),[RZ,$u]=Ai(Xf),DZ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Zf(n),[l,c]=w.useState(null),u=w.useRef(!1),d=en(s),h=Tw(o);return w.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",m,{capture:!0,once:!0}),document.addEventListener("pointermove",m,{capture:!0,once:!0})},m=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",m,{capture:!0}),document.removeEventListener("pointermove",m,{capture:!0})}},[]),w.createElement(jw,a,w.createElement(yA,{scope:n,open:t,onOpenChange:d,content:l,onContentChange:c},w.createElement(RZ,{scope:n,onClose:w.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:h,modal:i},r)))},SA=w.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=Zf(t);return w.createElement(uA,Q({},o,r,{ref:n}))}),vA="MenuPortal",[jZ,wA]=Ai(vA,{forceMount:void 0}),LZ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=Us(vA,n);return w.createElement(jZ,{scope:n,forceMount:t},w.createElement(Lr,{present:t||s.open},w.createElement(Lf,{asChild:!0,container:o},r)))},Mr="MenuContent",[NZ,Nw]=Ai(Mr),FZ=w.forwardRef((e,n)=>{const t=wA(Mr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=Us(Mr,e.__scopeMenu),i=$u(Mr,e.__scopeMenu);return w.createElement(Qc.Provider,{scope:e.__scopeMenu},w.createElement(Lr,{present:r||s.open},w.createElement(Qc.Slot,{scope:e.__scopeMenu},i.modal?w.createElement(zZ,Q({},o,{ref:n})):w.createElement(BZ,Q({},o,{ref:n})))))}),zZ=w.forwardRef((e,n)=>{const t=Us(Mr,e.__scopeMenu),r=w.useRef(null),o=Ge(n,r);return w.useEffect(()=>{const s=r.current;if(s)return ww(s)},[]),w.createElement(Fw,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)}))}),BZ=w.forwardRef((e,n)=>{const t=Us(Mr,e.__scopeMenu);return w.createElement(Fw,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),Fw=w.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:p,disableOutsideScroll:m,...f}=e,S=Us(Mr,t),v=$u(Mr,t),x=Zf(t),b=mA(t),P=MZ(t),[E,k]=w.useState(null),I=w.useRef(null),_=Ge(n,I,S.onContentChange),A=w.useRef(0),T=w.useRef(""),D=w.useRef(0),L=w.useRef(null),z=w.useRef("right"),j=w.useRef(0),F=m?vw:w.Fragment,Y=m?{as:vi,allowPinchZoom:!0}:void 0,K=B=>{var V,X;const ae=T.current+B,ye=P().filter(Pe=>!Pe.disabled),Ie=document.activeElement,le=(V=ye.find(Pe=>Pe.ref.current===Ie))===null||V===void 0?void 0:V.textValue,ke=ye.map(Pe=>Pe.textValue),Ae=tQ(ke,ae,le),nt=(X=ye.find(Pe=>Pe.textValue===Ae))===null||X===void 0?void 0:X.ref.current;(function Pe(ct){T.current=ct,window.clearTimeout(A.current),ct!==""&&(A.current=window.setTimeout(()=>Pe(""),1e3))})(ae),nt&&setTimeout(()=>nt.focus())};w.useEffect(()=>()=>window.clearTimeout(A.current),[]),Sw();const H=w.useCallback(B=>{var V,X;return z.current===((V=L.current)===null||V===void 0?void 0:V.side)&&rQ(B,(X=L.current)===null||X===void 0?void 0:X.area)},[]);return w.createElement(NZ,{scope:t,searchRef:T,onItemEnter:w.useCallback(B=>{H(B)&&B.preventDefault()},[H]),onItemLeave:w.useCallback(B=>{var V;H(B)||((V=I.current)===null||V===void 0||V.focus(),k(null))},[H]),onTriggerLeave:w.useCallback(B=>{H(B)&&B.preventDefault()},[H]),pointerGraceTimerRef:D,onPointerGraceIntentChange:w.useCallback(B=>{L.current=B},[])},w.createElement(F,Y,w.createElement(yw,{asChild:!0,trapped:o,onMountAutoFocus:se(s,B=>{var V;B.preventDefault(),(V=I.current)===null||V===void 0||V.focus()}),onUnmountAutoFocus:i},w.createElement(jf,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:p},w.createElement(kZ,Q({asChild:!0},b,{dir:v.dir,orientation:"vertical",loop:r,currentTabStopId:E,onCurrentTabStopIdChange:k,onEntryFocus:se(l,B=>{v.isUsingKeyboardRef.current||B.preventDefault()})}),w.createElement(dA,Q({role:"menu","aria-orientation":"vertical","data-state":kA(S.open),"data-radix-menu-content":"",dir:v.dir},x,f,{ref:_,style:{outline:"none",...f.style},onKeyDown:se(f.onKeyDown,B=>{const X=B.target.closest("[data-radix-menu-content]")===B.currentTarget,ae=B.ctrlKey||B.altKey||B.metaKey,ye=B.key.length===1;X&&(B.key==="Tab"&&B.preventDefault(),!ae&&ye&&K(B.key));const Ie=I.current;if(B.target!==Ie||!TZ.includes(B.key))return;B.preventDefault();const ke=P().filter(Ae=>!Ae.disabled).map(Ae=>Ae.ref.current);gA.includes(B.key)&&ke.reverse(),JZ(ke)}),onBlur:se(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(A.current),T.current="")}),onPointerMove:se(e.onPointerMove,Jc(B=>{const V=B.target,X=j.current!==B.clientX;if(B.currentTarget.contains(V)&&X){const ae=B.clientX>j.current?"right":"left";z.current=ae,j.current=B.clientX}}))})))))))}),UZ=w.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return w.createElement(ze.div,Q({role:"group"},r,{ref:n}))}),av="MenuItem",NC="menu.itemSelect",xA=w.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=w.useRef(null),i=$u(av,e.__scopeMenu),a=Nw(av,e.__scopeMenu),l=Ge(n,s),c=w.useRef(!1),u=()=>{const d=s.current;if(!t&&d){const h=new CustomEvent(NC,{bubbles:!0,cancelable:!0});d.addEventListener(NC,p=>r==null?void 0:r(p),{once:!0}),fw(d,h),h.defaultPrevented?c.current=!1:i.onClose()}};return w.createElement(bA,Q({},o,{ref:l,disabled:t,onClick:se(e.onClick,u),onPointerDown:d=>{var h;(h=e.onPointerDown)===null||h===void 0||h.call(e,d),c.current=!0},onPointerUp:se(e.onPointerUp,d=>{var h;c.current||(h=d.currentTarget)===null||h===void 0||h.click()}),onKeyDown:se(e.onKeyDown,d=>{const h=a.searchRef.current!=="";t||h&&d.key===" "||iv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),bA=w.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=Nw(av,t),a=mA(t),l=w.useRef(null),c=Ge(n,l),[u,d]=w.useState(!1),[h,p]=w.useState("");return w.useEffect(()=>{const m=l.current;if(m){var f;p(((f=m.textContent)!==null&&f!==void 0?f:"").trim())}},[s.children]),w.createElement(Qc.ItemSlot,{scope:t,disabled:r,textValue:o??h},w.createElement(IZ,Q({asChild:!0},a,{focusable:!r}),w.createElement(ze.div,Q({role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:c,onPointerMove:se(e.onPointerMove,Jc(m=>{r?i.onItemLeave(m):(i.onItemEnter(m),m.defaultPrevented||m.currentTarget.focus())})),onPointerLeave:se(e.onPointerLeave,Jc(m=>i.onItemLeave(m))),onFocus:se(e.onFocus,()=>d(!0)),onBlur:se(e.onBlur,()=>d(!1))}))))}),HZ=w.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return w.createElement(KZ,{scope:e.__scopeMenu,checked:t},w.createElement(xA,Q({role:"menuitemcheckbox","aria-checked":qp(t)?"mixed":t},o,{ref:n,"data-state":IA(t),onSelect:se(o.onSelect,()=>r==null?void 0:r(qp(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),VZ="MenuRadioGroup";Ai(VZ,{value:void 0,onValueChange:()=>{}});const PA="MenuItemIndicator",[KZ,WZ]=Ai(PA,{checked:!1}),GZ=w.forwardRef((e,n)=>{const{__scopeMenu:t,forceMount:r,...o}=e,s=WZ(PA,t);return w.createElement(Lr,{present:r||qp(s.checked)||s.checked===!0},w.createElement(ze.span,Q({},o,{ref:n,"data-state":IA(s.checked)})))}),CA="MenuSub",[YZ,EA]=Ai(CA),XZ=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=Us(CA,n),i=Zf(n),[a,l]=w.useState(null),[c,u]=w.useState(null),d=en(o);return w.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),w.createElement(jw,i,w.createElement(yA,{scope:n,open:r,onOpenChange:d,content:c,onContentChange:u},w.createElement(YZ,{scope:n,contentId:Ao(),triggerId:Ao(),trigger:a,onTriggerChange:l},t)))},Hd="MenuSubTrigger",qZ=w.forwardRef((e,n)=>{const t=Us(Hd,e.__scopeMenu),r=$u(Hd,e.__scopeMenu),o=EA(Hd,e.__scopeMenu),s=Nw(Hd,e.__scopeMenu),i=w.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=w.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return w.useEffect(()=>u,[u]),w.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),w.createElement(SA,Q({asChild:!0},c),w.createElement(bA,Q({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":kA(t.open)},e,{ref:Rf(n,o.onTriggerChange),onClick:d=>{var h;(h=e.onClick)===null||h===void 0||h.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:se(e.onPointerMove,Jc(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:se(e.onPointerLeave,Jc(d=>{var h;u();const p=(h=t.content)===null||h===void 0?void 0:h.getBoundingClientRect();if(p){var m;const f=(m=t.content)===null||m===void 0?void 0:m.dataset.side,S=f==="right",v=S?-5:5,x=p[S?"left":"right"],b=p[S?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+v,y:d.clientY},{x,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x,y:p.bottom}],side:f}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:se(e.onKeyDown,d=>{const h=s.searchRef.current!=="";if(!(e.disabled||h&&d.key===" ")&&$Z[r.dir].includes(d.key)){var p;t.onOpenChange(!0),(p=t.content)===null||p===void 0||p.focus(),d.preventDefault()}})})))}),ZZ="MenuSubContent",QZ=w.forwardRef((e,n)=>{const t=wA(Mr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=Us(Mr,e.__scopeMenu),i=$u(Mr,e.__scopeMenu),a=EA(ZZ,e.__scopeMenu),l=w.useRef(null),c=Ge(n,l);return w.createElement(Qc.Provider,{scope:e.__scopeMenu},w.createElement(Lr,{present:r||s.open},w.createElement(Qc.Slot,{scope:e.__scopeMenu},w.createElement(Fw,Q({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;i.isUsingKeyboardRef.current&&((d=l.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:se(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:se(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:se(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),h=AZ[i.dir].includes(u.key);if(d&&h){var p;s.onOpenChange(!1),(p=a.trigger)===null||p===void 0||p.focus(),u.preventDefault()}})})))))});function kA(e){return e?"open":"closed"}function qp(e){return e==="indeterminate"}function IA(e){return qp(e)?"indeterminate":e?"checked":"unchecked"}function JZ(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function eQ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function tQ(e,n,t){const o=n.length>1&&Array.from(n).every(c=>c===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=eQ(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==t));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==t?l:void 0}function nQ(e,n){const{x:t,y:r}=e;let o=!1;for(let s=0,i=n.length-1;s<n.length;i=s++){const a=n[s].x,l=n[s].y,c=n[i].x,u=n[i].y;l>r!=u>r&&t<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function rQ(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return nQ(t,n)}function Jc(e){return n=>n.pointerType==="mouse"?e(n):void 0}const _A=DZ,TA=SA,$A=LZ,AA=FZ,MA=UZ,OA=xA,RA=HZ,oQ=GZ,DA=XZ,jA=qZ,LA=QZ,NA="DropdownMenu",[sQ,Ste]=io(NA,[qf]),Nr=qf(),[iQ,FA]=sQ(NA),aQ=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Nr(n),c=w.useRef(null),[u=!1,d]=Bs({prop:o,defaultProp:s,onChange:i});return w.createElement(iQ,{scope:n,triggerId:Ao(),triggerRef:c,contentId:Ao(),open:u,onOpenChange:d,onOpenToggle:w.useCallback(()=>d(h=>!h),[d]),modal:a},w.createElement(_A,Q({},l,{open:u,onOpenChange:d,dir:r,modal:a}),t))},lQ="DropdownMenuTrigger",cQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=FA(lQ,t),i=Nr(t);return w.createElement(TA,Q({asChild:!0},i),w.createElement(ze.button,Q({type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r},o,{ref:Rf(n,s.triggerRef),onPointerDown:se(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:se(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),uQ=e=>{const{__scopeDropdownMenu:n,...t}=e,r=Nr(n);return w.createElement($A,Q({},r,t))},dQ="DropdownMenuContent",hQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=FA(dQ,t),s=Nr(t),i=w.useRef(!1);return w.createElement(AA,Q({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:n,onCloseAutoFocus:se(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)===null||l===void 0||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),pQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Nr(t);return w.createElement(MA,Q({},o,r,{ref:n}))}),fQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Nr(t);return w.createElement(OA,Q({},o,r,{ref:n}))}),gQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Nr(t);return w.createElement(RA,Q({},o,r,{ref:n}))}),mQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Nr(t);return w.createElement(oQ,Q({},o,r,{ref:n}))}),yQ=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=Nr(n),[a=!1,l]=Bs({prop:r,defaultProp:s,onChange:o});return w.createElement(DA,Q({},i,{open:a,onOpenChange:l}),t)},SQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Nr(t);return w.createElement(jA,Q({},o,r,{ref:n}))}),vQ=w.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Nr(t);return w.createElement(LA,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)"}}))}),zA=aQ,eu=cQ,zw=uQ,BA=hQ,wQ=pQ,Ji=fQ,UA=gQ,xQ=mQ,bQ=yQ,PQ=SQ,CQ=vQ;function Mi(e,n){const t=U(),r=w.useRef(!1),o=cl(),s=w.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(l=>!l.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=G("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return w.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),t.addOpenMenu(e)),()=>{r.current&&(t.deleteOpenMenu(e),t.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),t.deleteOpenMenu(a))}),r.current=!1)}),[t,e,o]),[i,s]}function Ms({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=Mi(e);return g.jsx(zA,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function Au({children:e,"data-testid":n}){return g.jsx(eu,{dir:"ltr","data-testid":n,asChild:!0,onTouchEnd:t=>Ee(t),children:e})}function Os({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=un();return g.jsx(zw,{container:s,children:g.jsx(BA,{className:"tlui-menu",align:n,sideOffset:t,side:e,alignOffset:r,collisionPadding:4,children:o})})}function Bw({id:e,children:n}){const[t,r]=Mi(e);return g.jsx(bQ,{open:t,onOpenChange:r,children:n})}function Uw({label:e,"data-testid":n,"data-direction":t}){return g.jsx(PQ,{dir:"ltr","data-direction":t,"data-testid":n,asChild:!0,children:g.jsx(ie,{type:"menu",className:"tlui-menu__submenu__trigger",label:e,icon:"chevron-right"})})}function Hw({alignOffset:e=0,sideOffset:n=5,children:t}){const r=un();return g.jsx(zw,{container:r,children:g.jsx(CQ,{className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,children:t})})}function Mo({children:e,size:n="medium"}){return g.jsx(wQ,{dir:"ltr",className:"tlui-menu__group","data-size":n,children:e})}function Fn({noClose:e,...n}){return g.jsx(Ji,{dir:"ltr",asChild:!0,onClick:e||n.isChecked!==void 0?Ee:void 0,children:g.jsx(ie,{...n})})}function HA({children:e,onSelect:n,...t}){return g.jsxs(UA,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",onSelect:r=>{n==null||n(r),Ee(r)},...t,children:[g.jsx(Vn,{small:!0,icon:t.checked?"check":"checkbox-empty"}),e]})}function EQ({children:e,onSelect:n,...t}){return g.jsxs(UA,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",onSelect:r=>{n==null||n(r),Ee(r)},...t,children:[g.jsx("div",{className:"tlui-button__checkbox__indicator",children:g.jsx(xQ,{dir:"ltr",children:g.jsx(Vn,{icon:"check",small:!0})})}),e]})}let FC=0;function kQ(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)FC++,t[o]={id:We("box"+FC),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}const IQ=w.memo(function({renderDebugMenuItems:n}){const t=be(),r=G("show_fps",()=>Oe.showFps.get(),[Oe]);return g.jsxs("div",{className:"tlui-debug-panel",children:[g.jsx(TQ,{}),r&&g.jsx($Q,{}),g.jsx(AQ,{}),g.jsxs(Ms,{id:"debug",children:[g.jsx(Au,{children:g.jsx(ie,{type:"icon",icon:"dots-horizontal",title:t("debug-panel.more")})}),g.jsx(Os,{side:"top",align:"end",alignOffset:0,children:g.jsx(MQ,{renderDebugMenuItems:n})})]})]})});function _Q(e=!0){const[n,t]=w.useState(0),r=U();w.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const TQ=je(function(){_Q();const n=U(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),s=t==="select.idle"||!t.includes("select.")?r:o,i=s&&t.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${C.ToFixed(n.getPointInShapeSpace(s,n.inputs.currentPagePoint),0)}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${C.ToFixed(n.inputs.originPagePoint,0)}] → [${C.ToFixed(n.inputs.currentPagePoint,0)}] = ${C.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return g.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function $Q(){const e=w.useRef(null);return w.useEffect(()=>{let t=0,r=!1,o=performance.now(),s=0,i=0,a=!1;function l(){if(!r){if(i++,s=performance.now()-o,s>250){const c=Math.round(i*(250/s)*4);c>t&&(t=c);const u=t*.75;(c<u&&!a||c>=u&&a)&&(a=!a),e.current.innerHTML=`FPS ${c.toString()}`,e.current.className="tlui-debug-panel__fps"+(a?" tlui-debug-panel__fps__slow":""),s-=250,i=0,o=performance.now()}requestAnimationFrame(l)}}return l(),()=>{r=!0}},[]),g.jsx("div",{ref:e})}const AQ=function(){const n=U(),t=G("rendering shapes count",()=>n.getRenderingShapes().length,[n]);return g.jsxs("div",{children:[t," Shapes"]})},MQ=je(function({renderDebugMenuItems:n}){const t=U(),{addToast:r}=ao(),{addDialog:o}=$i(),[s,i]=w.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(Mo,{children:[g.jsx(Fn,{type:"menu",onClick:()=>{r({id:Ue(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0}),r({id:Ue(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),r({id:Ue(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,icon:"twitter",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]})},label:"Show toast"}),g.jsx(Fn,{type:"menu",onClick:()=>{o({component:({onClose:a})=>g.jsx(RQ,{displayDontShowAgain:!0,onCancel:()=>{a()},onContinue:()=>{a()}}),onClose:()=>{}})},label:"Show dialog"}),g.jsx(Fn,{type:"menu",onClick:()=>kQ(t,100),label:"Create 100 shapes"}),g.jsx(Fn,{type:"menu",onClick:()=>{function a({children:h}){let p=0;if(!h.length)return 0;for(const m of[...h])p++,p+=a(m);return p}const l=t.getSelectedShapes(),c=l.length===0?t.getRenderingShapes():l,u=c.map(h=>document.getElementById(h.id).parentElement);let d=u.length;for(const h of u)d+=a(h);window.alert(`Shapes ${c.length}, DOM nodes:${d}`)},label:"Count shapes / nodes"}),(()=>{if(s)throw Error("oh no!")})(),g.jsx(Fn,{type:"menu",onClick:()=>{i(!0)},label:"Throw error"}),g.jsx(Fn,{type:"menu",onClick:()=>{BE()},label:"Hard reset"})]}),g.jsxs(Mo,{children:[g.jsx(Qi,{flag:Oe.debugSvg}),g.jsx(Qi,{flag:Oe.showFps}),g.jsx(Qi,{flag:Oe.forceSrgb}),g.jsx(Qi,{flag:Oe.debugGeometry}),g.jsx(Qi,{flag:Oe.hideShapes})]}),g.jsx(Mo,{children:Object.values(ID).map(a=>g.jsx(Qi,{flag:a},a.name))}),n==null?void 0:n()]})});function OQ({label:e,value:n,onChange:t}){return g.jsx(HA,{title:e,checked:n,onSelect:()=>t(!n),children:g.jsx("span",{className:"tlui-button__label",draggable:!1,children:e})})}const Qi=je(function({flag:n,onChange:t}){return g.jsx(OQ,{label:n.name.replace(/([a-z0-9])([A-Z])/g,r=>`${r[0]} ${r[1].toLowerCase()}`).replace(/^[a-z]/,r=>r.toUpperCase()),value:n.get(),onChange:r=>{n.set(r),t==null||t(r)}})});function RQ({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=w.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(Uf,{children:[g.jsx(Hf,{children:e}),g.jsx(Vf,{})]}),g.jsx(Xc,{style:{maxWidth:350},children:n}),g.jsxs(xw,{className:"tlui-dialog__footer__actions",children:[o&&g.jsx(ie,{type:"normal",onClick:()=>l(!a),iconLeft:a?"check":"checkbox-empty",style:{marginRight:"auto"},children:"Don't show again"}),g.jsx(ie,{type:"normal",onClick:s,children:t}),g.jsx(ie,{type:"primary",onClick:async()=>i(),children:r})]})]})}const DQ=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=$i(),o=un(),s=w.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return g.jsx(iX,{onOpenChange:s,defaultOpen:!0,children:g.jsx(aX,{container:o,children:g.jsx(lX,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:g.jsx(cX,{dir:"ltr",className:"tlui-dialog__content",children:g.jsx(n,{onClose:()=>s(!1)})})})})})};function jQ(){const{dialogs:e}=$i();return g.jsx(g.Fragment,{children:e.map(n=>g.jsx(DQ,{...n},n.id))})}const LQ=ne.memo(jQ);function NQ(){const e=U(),n=G("follow",()=>e.getInstanceState().followingUserId,[e]);return n?g.jsx(FQ,{userId:n}):null}function FQ({userId:e}){const n=ak(e);return n?g.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function VA(){const e=U(),{languages:n,currentLanguage:t}=F$(),r=w.useCallback(o=>e.user.updateUserPreferences({locale:o}),[e]);return g.jsxs(Bw,{id:"help menu language",children:[g.jsx(Uw,{label:"menu.language","data-direction":"left"}),g.jsx(Hw,{sideOffset:-4,children:g.jsx(Mo,{children:n.map(({locale:o,label:s})=>g.jsx(EQ,{title:o,checked:o===t,onSelect:()=>r(o),children:g.jsx("span",{className:"tlui-button__label",children:s})},o))})})]})}const zQ=w.memo(function(){const n=un(),t=be(),[r,o]=Mi("help menu");return g.jsx("div",{className:"tlui-help-menu",children:g.jsxs(zA,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[g.jsx(eu,{asChild:!0,dir:"ltr",children:g.jsx(ie,{type:"help",className:"tlui-button",smallIcon:!0,title:t("help-menu.title"),icon:"question-mark"})}),g.jsx(zw,{container:n,children:g.jsx(BA,{className:"tlui-menu",side:"top",sideOffset:8,align:"end",alignOffset:0,collisionPadding:4,children:g.jsx(BQ,{})})})]})})});function BQ(){const e=oq(),n=Yn();function t(r){if(!r||n&&!r.readonlyOk)return null;switch(r.type){case"custom":{if(r.id==="LANGUAGE_MENU")return g.jsx(VA,{},"item");break}case"group":return g.jsx(Mo,{size:"small",children:r.children.map(t)},r.id);case"submenu":return g.jsxs(Bw,{id:`help menu ${r.id}`,children:[g.jsx(Uw,{label:r.label}),g.jsx(Hw,{children:r.children.map(t)})]},r.id);case"item":{const{id:o,kbd:s,label:i,onSelect:a,icon:l}=r.actionItem;return g.jsx(Fn,{type:"menu",kbd:s,label:i,onClick:()=>a("help-menu"),iconLeft:l},o)}}}return g.jsx(g.Fragment,{children:e.map(t)})}const KA="Popover",[WA,vte]=io(KA,[Yf]),Vw=Yf(),[UQ,hl]=WA(KA),HQ=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Vw(n),l=w.useRef(null),[c,u]=w.useState(!1),[d=!1,h]=Bs({prop:r,defaultProp:o,onChange:s});return w.createElement(jw,a,w.createElement(UQ,{scope:n,contentId:Ao(),triggerRef:l,open:d,onOpenChange:h,onOpenToggle:w.useCallback(()=>h(p=>!p),[h]),hasCustomAnchor:c,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:i},t))},VQ="PopoverTrigger",KQ=w.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=hl(VQ,t),s=Vw(t),i=Ge(n,o.triggerRef),a=w.createElement(ze.button,Q({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":XA(o.open)},r,{ref:i,onClick:se(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:w.createElement(uA,Q({asChild:!0},s),a)}),GA="PopoverPortal",[WQ,GQ]=WA(GA,{forceMount:void 0}),YQ=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=hl(GA,n);return w.createElement(WQ,{scope:n,forceMount:t},w.createElement(Lr,{present:t||s.open},w.createElement(Lf,{asChild:!0,container:o},r)))},tu="PopoverContent",XQ=w.forwardRef((e,n)=>{const t=GQ(tu,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=hl(tu,e.__scopePopover);return w.createElement(Lr,{present:r||s.open},s.modal?w.createElement(qQ,Q({},o,{ref:n})):w.createElement(ZQ,Q({},o,{ref:n})))}),qQ=w.forwardRef((e,n)=>{const t=hl(tu,e.__scopePopover),r=w.useRef(null),o=Ge(n,r),s=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return ww(i)},[]),w.createElement(vw,{as:vi,allowPinchZoom:!0},w.createElement(YA,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),ZQ=w.forwardRef((e,n)=>{const t=hl(tu,e.__scopePopover),r=w.useRef(!1),o=w.useRef(!1);return w.createElement(YA,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),YA=w.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...d}=e,h=hl(tu,t),p=Vw(t);return Sw(),w.createElement(yw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},w.createElement(jf,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>h.onOpenChange(!1)},w.createElement(dA,Q({"data-state":XA(h.open),role:"dialog",id:h.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 XA(e){return e?"open":"closed"}const QQ=HQ,JQ=KQ,qA=YQ,ZA=XQ,Kw=({id:e,children:n,onOpenChange:t,open:r})=>{const[o,s]=Mi(e,t);return g.jsx(QQ,{onOpenChange:s,open:r||o,children:g.jsx("div",{className:"tlui-popover",children:n})})},Ww=({children:e,disabled:n,"data-testid":t})=>g.jsx(JQ,{"data-testid":t,disabled:n,asChild:!0,dir:"ltr",children:e}),QA=({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0})=>{const s=un();return g.jsx(qA,{container:s,children:g.jsx(ZA,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})},JA=w.memo(function(){const n=be(),t=un(),r=qX(),o=Yn();function s(i){if(!i||o&&!i.readonlyOk)return null;switch(i.type){case"item":{const{id:a,icon:l,label:c,kbd:u,onSelect:d}=i.actionItem;return g.jsx(ie,{"data-testid":`menu-item.${i.id}`,icon:l,type:"icon",title:c?u?`${n(c)} ${no(u)}`:`${n(c)}`:u?`${no(u)}`:"",onClick:()=>d("actions-menu"),disabled:i.disabled},a)}}}return g.jsxs(Kw,{id:"actions-menu",children:[g.jsx(Ww,{children:g.jsx(ie,{className:"tlui-menu__trigger","data-testid":"main.action-menu",icon:"dots-vertical",title:n("actions-menu.title"),type:"icon",smallIcon:!0})}),g.jsx(qA,{container:t,children:g.jsx(ZA,{className:"tlui-popover__content",side:"bottom",dir:"ltr",sideOffset:6,children:g.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid",children:r.map(s)})})})]})}),eM=je(function(){const n=U(),t=nn(),r=be(),o=t.duplicate,s=w.useRef(null);return g.jsx(ie,{icon:o.icon,type:"icon",onClick:()=>o.onSelect("quick-actions"),disabled:!(n.isIn("select")&&n.getSelectedShapeIds().length>0),title:`${r(o.label)} ${no(o.kbd)}`,smallIcon:!0,ref:s})}),eJ=w.memo(function(){const n=be();return g.jsxs(Ms,{id:"main menu",children:[g.jsx(Au,{children:g.jsx(ie,{type:"icon",className:"tlui-menu__trigger","data-testid":"main.menu",title:n("menu.title"),icon:"menu",smallIcon:!0})}),g.jsx(Os,{alignOffset:0,sideOffset:6,children:g.jsx(tJ,{})})]})});function tJ(){const e=U(),n=be(),t=iq(),r=Qn(),o=Yn();function s(i,a,l,c){if(!a)return null;switch(a.type){case"custom":return o&&!a.readonlyOk?null:a.id==="LANGUAGE_MENU"?g.jsx(VA,{},"item"):null;case"group":return o&&!a.readonlyOk?null:g.jsx(Mo,{size:c<=1?"medium":r<3||(l==null?void 0:l.type)==="submenu"&&c>2?"tiny":"medium",children:a.children.map(u=>s(i,u,a,c+1))},a.id);case"submenu":return o&&!a.readonlyOk?null:g.jsxs(Bw,{id:`main menu ${l?l.id+" ":""}${a.id}`,children:[g.jsx(Uw,{label:a.label,"data-testid":`menu-item.${a.id}`}),g.jsx(Hw,{sideOffset:-4,alignOffset:-1,children:a.children.map(u=>s(i,u,a,c+1))})]},a.id);case"item":{if(o&&!a.readonlyOk)return null;const{id:u,checkbox:d,menuLabel:h,label:p,onSelect:m,kbd:f}=a.actionItem,S=h??p,v=S?n(S):void 0;return d?g.jsxs(HA,{onSelect:()=>m("menu"),title:v||"",checked:a.checked,disabled:a.disabled,children:[v&&g.jsx("span",{className:"tlui-button__label",children:v}),f&&g.jsx(zf,{children:f})]},u):g.jsx(Fn,{type:"menu","data-testid":`menu-item.${a.id}`,kbd:f,label:S,onClick:()=>m("menu"),disabled:a.disabled},u)}}}return g.jsx(g.Fragment,{children:t.map(i=>s(e,i,null,0))})}const nJ=function({name:n,id:t,isCurrentPage:r}){const o=U(),s=w.useRef(null),i=w.useCallback(l=>{o.renamePage(t,l||"New Page",{ephemeral:!0})},[o,t]),a=w.useCallback(l=>{o.mark("rename page"),o.renamePage(t,l||"New Page",{ephemeral:!1})},[o,t]);return g.jsx(bw,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:n,onValueChange:i,onComplete:a,onCancel:a,shouldManuallyMaintainScrollPositionWhenFocused:!0,autofocus:r,autoselect:!0})},lv=(e,n,t,r)=>{let o;const s=e.getPages(),i=t>r?s[r-1]:s[r],a=t>r?s[r]:s[r+1];i&&!a?o=So(i.index):!i&&a?o=j6(s[0].index):o=nc(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},zC=je(function({index:n,listSize:t,item:r,onRename:o}){const s=U(),i=be(),a=s.getPages(),l=w.useCallback(()=>{s.mark("creating page");const h=Oo.createId();s.duplicatePage(r.id,h)},[s,r]),c=w.useCallback(()=>{lv(s,r.id,n,n-1)},[s,r,n]),u=w.useCallback(()=>{lv(s,r.id,n,n+1)},[s,r,n]),d=w.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return g.jsxs(Ms,{id:`page item submenu ${n}`,children:[g.jsx(Au,{children:g.jsx(ie,{type:"icon",title:i("page-menu.submenu.title"),icon:"dots-vertical"})}),g.jsxs(Os,{alignOffset:0,children:[g.jsxs(Mo,{children:[o&&g.jsx(Ji,{dir:"ltr",onSelect:o,asChild:!0,children:g.jsx(ie,{type:"menu",label:"page-menu.submenu.rename"})}),g.jsx(Ji,{dir:"ltr",onSelect:l,disabled:a.length>=rp,asChild:!0,children:g.jsx(ie,{type:"menu",label:"page-menu.submenu.duplicate-page"})}),n>0&&g.jsx(Ji,{dir:"ltr",onSelect:c,asChild:!0,children:g.jsx(ie,{type:"menu",label:"page-menu.submenu.move-up"})}),n<t-1&&g.jsx(Ji,{dir:"ltr",onSelect:u,asChild:!0,children:g.jsx(ie,{type:"menu",label:"page-menu.submenu.move-down"})})]}),t>1&&g.jsx(Mo,{children:g.jsx(Ji,{dir:"ltr",onSelect:d,asChild:!0,children:g.jsx(ie,{type:"menu",label:"page-menu.submenu.delete"})})})]})]})}),rJ=function(){const n=U(),t=be(),r=Qn(),o=w.useCallback(()=>S(!1),[]),[s,i]=Mi("page-menu",o),a=36,l=w.useRef(null),c=G("pages",()=>n.getPages(),[n]),u=G("currentPage",()=>n.getCurrentPage(),[n]),d=G("currentPageId",()=>n.getCurrentPageId(),[n]),h=Yn(),p=G("maxPageCountReached",()=>n.getPages().length>=rp,[n]),m=G("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[f,S]=w.useState(!1),v=w.useCallback(()=>{h||S(T=>!T)},[h]),x=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[b,P]=w.useState(Object.fromEntries(c.map((T,D)=>[T.id,{y:D*a,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{P(Object.fromEntries(c.map((T,D)=>[T.id,{y:D*a,offsetY:0,isSelected:!1}])))},[a,c]),w.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const D=l.current;if(!D)return;const L=T.offsetTop,z=D.scrollTop;L<z&&D.scrollTo({top:L});const j=L+a,F=D.scrollTop+D.offsetHeight;j>F&&D.scrollTo({top:j-D.offsetHeight})}})},[a,d,s]);const E=w.useCallback(T=>{const{clientY:D,currentTarget:L}=T,{dataset:{id:z,index:j}}=L;if(!z||!j)return;const F=x.current;lu(T.currentTarget,T),F.status="pointing",F.pointing={id:z,index:+j};const K=b[z].y;F.startY=D,F.startIndex=Math.max(0,Math.min(Math.round(K/a),c.length-1))},[a,c.length,b]),k=w.useCallback(T=>{const D=x.current;if(D.status==="pointing"){const{clientY:L}=T,z=L-D.startY;Math.abs(z)>5&&(D.status="dragging")}if(D.status==="dragging"){const{clientY:L}=T,z=L-D.startY,j=b[D.pointing.id],{startIndex:F,pointing:Y}=D,K=j.y+z,H=Math.max(0,Math.min(Math.round(K/a),c.length-1)),B={...b};if(B[Y.id]={y:j.y,offsetY:z,isSelected:!0},H!==D.dragIndex){D.dragIndex=H;for(let V=0;V<c.length;V++){const X=c[V];if(X.id===D.pointing.id)continue;let{y:ae}=B[X.id];H===F?ae=V*a:H<F?H<=V&&V<F?ae=(V+1)*a:ae=V*a:H>F&&(H>=V&&V>F?ae=(V-1)*a:ae=V*a),ae!==B[X.id].y&&(B[X.id]={y:ae,offsetY:0,isSelected:!0})}}P(B)}},[a,c,b]),I=w.useCallback(T=>{const D=x.current;if(D.status==="dragging"){const{id:L,index:z}=D.pointing;lv(n,L,z,D.dragIndex)}cu(T.currentTarget,T),D.status="idle"},[n]),_=w.useCallback(T=>{const D=x.current;T.key==="Escape"&&(D.status==="dragging"&&P(Object.fromEntries(c.map((L,z)=>[L.id,{y:z*a,offsetY:0,isSelected:!1}]))),D.status="idle")},[a,c]),A=w.useCallback(()=>{h||n.batch(()=>{n.mark("creating page");const T=Oo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),S(!0)})},[n,t,h]);return g.jsxs(Kw,{id:"pages",onOpenChange:i,open:s,children:[g.jsx(Ww,{children:g.jsx(ie,{className:"tlui-page-menu__trigger tlui-menu__trigger","data-testid":"main.page-menu",icon:"chevron-down",type:"menu",title:u.name,children:g.jsx("div",{className:"tlui-page-menu__name",children:u.name})})}),g.jsx(QA,{side:"bottom",align:"start",sideOffset:6,children:g.jsxs("div",{className:"tlui-page-menu__wrapper",children:[g.jsxs("div",{className:"tlui-page-menu__header",children:[g.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!h&&g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsx(ie,{type:"icon","data-testid":"page-menu.edit",title:t(f?"page-menu.edit-done":"page-menu.edit-start"),icon:f?"check":"edit",onClick:v}),g.jsx(ie,{type:"icon","data-testid":"page-menu.create",icon:"plus",title:t(p?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:p,onClick:A})]})]}),g.jsx("div",{className:"tlui-page-menu__list tlui-menu__group",style:{height:a*c.length+4},ref:l,children:c.map((T,D)=>{const L=b[T.id]??{position:D*40,offsetY:0};return f?g.jsxs("div",{"data-testid":`page-menu-item-${T.id}`,className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===u.id?888:D,transform:`translate(0px, ${L.y+L.offsetY}px)`},children:[g.jsx(ie,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",icon:"drag-handle-dots",onPointerDown:E,onPointerUp:I,onPointerMove:k,onKeyDown:_,"data-id":T.id,"data-index":D}),r<5&&m?g.jsx(ie,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const z=window.prompt("Rename page",T.name);z&&z!==T.name&&n.renamePage(T.id,z)},onDoubleClick:v,isChecked:T.id===u.id,children:g.jsx("span",{children:T.name})}):g.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:g.jsx(nJ,{id:T.id,name:T.name,isCurrentPage:T.id===u.id})}),!h&&g.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":f,children:g.jsx(zC,{index:D,item:T,listSize:c.length})})]},T.id+"_editing"):g.jsxs("div",{"data-testid":`page-menu-item-${T.id}`,className:"tlui-page-menu__item",children:[g.jsxs(ie,{type:"normal",className:"tlui-page-menu__item__button tlui-page-menu__item__button__checkbox",onClick:()=>n.setCurrentPage(T.id),onDoubleClick:v,isChecked:T.id===u.id,title:t("page-menu.go-to-page"),children:[g.jsx("div",{className:"tlui-page-menu__item__button__check",children:T.id===u.id&&g.jsx(Vn,{icon:"check"})}),g.jsx("span",{children:T.name})]}),!h&&g.jsx("div",{className:"tlui-page_menu__item__submenu",children:g.jsx(zC,{index:D,item:T,listSize:c.length,onRename:()=>{if(n.environment.isIos){const z=window.prompt("Rename page",T.name);z&&z!==T.name&&n.renamePage(T.id,z)}else n.batch(()=>{S(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})},tM=w.memo(function(){const n=be(),t=B$(),o=nn().redo,s=w.useRef(null);return g.jsx(ie,{"data-testid":"main.redo",icon:o.icon,type:"icon",title:`${n(o.label)} ${no(o.kbd)}`,disabled:!t,onClick:()=>o.onSelect("quick-actions"),smallIcon:!0,ref:s})}),nM=je(function(){const n=U(),t=nn(),r=be(),o=t.delete,s=Yn(),i=w.useRef(null);return s?null:g.jsx(ie,{icon:o.icon,type:"icon",onClick:()=>{o.onSelect("quick-actions"),n.getContainer().focus()},disabled:!(n.isIn("select")&&n.getSelectedShapeIds().length>0),title:`${r(o.label)} ${no(o.kbd)}`,smallIcon:!0,ref:i})}),rM=w.memo(function(){const n=be(),t=U$(),r=nn(),o=w.useRef(null),s=r.undo;return g.jsx(ie,{"data-testid":"main.undo",icon:s.icon,type:"icon",title:`${n(s.label)} ${no(s.kbd)}`,disabled:!t,onClick:()=>s.onSelect("quick-actions"),smallIcon:!0,ref:o})}),oJ=je(function(){const n=U(),t=Qn(),r=Yn();return g.jsx("div",{className:"tlui-menu-zone",children:g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsx(eJ,{}),g.jsx(rJ,{}),t>=6&&!r&&!n.isInAny("hand","zoom")&&g.jsxs(g.Fragment,{children:[g.jsx(rM,{}),g.jsx(tM,{}),g.jsx(nM,{}),g.jsx(eM,{}),g.jsx(JA,{})]})]})})});function sJ(e,n){const[t,r]=ne.useState(n);ne.useLayoutEffect(()=>{const s=localStorage.getItem(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=ne.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return localStorage.setItem(e,JSON.stringify(a)),a})},[e]);return[t,o]}class gc{constructor(n){y(this,"dpr",1);y(this,"colors",{shapeFill:"rgba(144, 144, 144, .1)",selectFill:"#2f80ed",viewportFill:"rgba(144, 144, 144, .1)"});y(this,"id",Ue());y(this,"cvs",null);y(this,"pageBounds",[]);y(this,"collaborators",[]);y(this,"canvasScreenBounds",new re);y(this,"canvasPageBounds",new re);y(this,"contentPageBounds",new re);y(this,"contentScreenBounds",new re);y(this,"originPagePoint",new C);y(this,"originPageCenter",new C);y(this,"isInViewport",!1);y(this,"debug",!1);y(this,"updateContentScreenBounds",()=>{const{contentScreenBounds:n,contentPageBounds:t,canvasScreenBounds:r}=this;let{x:o,y:s,w:i,h:a}=n;if(t.w>t.h){const l=r.w/(t.w/t.h);l>r.h?(o=(r.w-r.w*(r.h/l))/2,s=0,i=r.w*(r.h/l),a=r.h):(o=0,s=(r.h-l)/2,i=r.w,a=l)}else if(t.w<t.h){const l=r.h/(t.h/t.w);o=(r.w-l)/2,s=0,i=l,a=r.h}else o=r.h/2,s=0,i=r.h,a=r.h;n.set(o,s,i,a)});y(this,"updateCanvasPageBounds",()=>{const{canvasPageBounds:n,canvasScreenBounds:t,contentPageBounds:r,contentScreenBounds:o}=this;n.set(0,0,r.width/(o.width/t.width),r.height/(o.height/t.height)),n.center=r.center});y(this,"getScreenPoint",(n,t)=>{const{canvasScreenBounds:r}=this,o=(n-r.minX)*this.dpr,s=(t-r.minY)*this.dpr;return{x:o,y:s}});y(this,"getPagePoint",(n,t)=>{const{contentPageBounds:r,contentScreenBounds:o,canvasPageBounds:s}=this,{x:i,y:a}=this.getScreenPoint(n,t);return new C(s.minX+i*r.width/o.width,s.minY+a*r.height/o.height,1)});y(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getPagePoint(n,t);if(o){const c=this.editor.getCurrentPageBounds(),u=i,d=((c==null?void 0:c.minX)??0)-u.width/2,h=((c==null?void 0:c.maxX)??0)+u.width/2,p=((c==null?void 0:c.minY)??0)-u.height/2,m=((c==null?void 0:c.maxY)??0)+u.height/2,f=Math.max(0,d+u.width-a),S=Math.max(0,-(h-u.width-a)),v=Math.max(0,p+u.height-l),x=Math.max(0,-(m-u.height-l)),b=Math.max(0,f-S),P=Math.max(0,S-f),E=Math.max(0,v-x),k=Math.max(0,x-v);b&&b>P?a+=b/2:P&&(a-=P/2),E&&E>k?l+=E/2:k&&(l-=k/2),a=or(a,d,h),l=or(l,p,m)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),d=Math.abs(l-c.y);u>d?l=c.y:a=c.x}return new C(a,l)});y(this,"render",()=>{const{cvs:n,pageBounds:t}=this;this.updateCanvasPageBounds();const{editor:r,canvasScreenBounds:o,canvasPageBounds:s,contentPageBounds:i,contentScreenBounds:a}=this,{width:l,height:c}=o,u=r.getSelectedShapeIds(),d=r.getViewportPageBounds();if(!n||!t)return;const h=n.getContext("2d");if(!h)throw new Error("Minimap (shapes): Could not get context");h.resetTransform(),h.globalAlpha=1,h.clearRect(0,0,l,c);const p=a.width/i.width,m=a.height/i.height;h.translate((l-a.width)/2,(c-a.height)/2),h.scale(p,m),h.translate(-i.minX,-i.minY);const f=8/p,S=8/p,v=1/p,x=1/p,b=f/4,P=S/4,E=new Path2D,k=new Path2D,{shapeFill:I,selectFill:_,viewportFill:A}=this.colors;let T;for(let F=0,Y=t.length;F<Y;F++)T=t[F],gc.roundedRect(u.includes(T.id)?k:E,T.minX,T.minY,T.width,T.height,or(f,v,T.width/b),or(S,x,T.height/P));if(h.fillStyle=I,h.fill(E),h.fillStyle=_,h.fill(k),this.debug){const F=re.Common(t),{minX:Y,minY:K,width:H,height:B}=F;h.strokeStyle="green",h.lineWidth=2/p,h.strokeRect(Y+1/p,K+1/m,H-2/p,B-2/m)}{const{brush:F}=r.getInstanceState();if(F){const{x:Y,y:K,w:H,h:B}=F;h.beginPath(),gc.sharpRect(h,Y,K,H,B),h.closePath(),h.fillStyle=A,h.fill()}}{const{minX:F,minY:Y,width:K,height:H}=d;h.beginPath();const B=12/p,V=12/p;gc.roundedRect(h,F,Y,K,H,Math.min(K/4,B),Math.min(H/4,V)),h.closePath(),h.fillStyle=A,h.fill(),this.debug&&(h.strokeStyle="orange",h.strokeRect(F+1/p,Y+1/m,K-2/p,H-2/m))}const D=2.5/p,L=2.5/m,z=r.getCurrentPageId();let j;for(let F=0;F<this.collaborators.length;F++)j=this.collaborators[F],j.currentPageId===z&&(h.beginPath(),h.ellipse(or(j.cursor.x,s.minX+D,s.maxX-D),or(j.cursor.y,s.minY+L,s.maxY-L),5/p,5/m,0,0,Re),h.fillStyle=j.color,h.fill());if(this.debug){h.lineWidth=2/p;{const{minX:F,minY:Y,width:K,height:H}=i;h.strokeStyle="red",h.strokeRect(F+1/p,Y+1/m,K-2/p,H-2/m)}{const{minX:F,minY:Y,width:K,height:H}=s;h.strokeStyle="blue",h.strokeRect(F+1/p,Y+1/m,K-2/p,H-2/m)}}});this.editor=n}setDpr(n){this.dpr=+n.toFixed(2)}static roundedRect(n,t,r,o,s,i,a){if(i<1&&a<1){n.rect(t,r,o,s);return}n.moveTo(t+i,r),n.lineTo(t+o-i,r),n.quadraticCurveTo(t+o,r,t+o,r+a),n.lineTo(t+o,r+s-a),n.quadraticCurveTo(t+o,r+s,t+o-i,r+s),n.lineTo(t+i,r+s),n.quadraticCurveTo(t,r+s,t,r+s-a),n.lineTo(t,r+a),n.quadraticCurveTo(t,r,t+i,r)}static sharpRect(n,t,r,o,s,i,a){n.rect(t,r,o,s)}}function iJ({shapeFill:e,selectFill:n,viewportFill:t}){const r=U(),o=w.useRef(null),s=w.useRef(!1),i=af(),a=fE("dpr",()=>r.getInstanceState().devicePixelRatio,[r]),l=w.useMemo(()=>r.store.query.records("instance_presence"),[r]),c=w.useMemo(()=>new gc(r),[r]);w.useEffect(()=>{const m=requestAnimationFrame(()=>{const f=getComputedStyle(r.getContainer());c.colors={shapeFill:f.getPropertyValue(e).trim(),selectFill:f.getPropertyValue(n).trim(),viewportFill:f.getPropertyValue(t).trim()},c.render()});return()=>{cancelAnimationFrame(m)}},[r,n,e,t,c,i]);const u=w.useCallback(m=>{if(!r.getCurrentPageShapeIds().size)return;const f=c.minimapScreenPointToPagePoint(m.clientX,m.clientY,!1,!1),S=c.minimapScreenPointToPagePoint(m.clientX,m.clientY,!1,!0);c.originPagePoint.setTo(S),c.originPageCenter.setTo(r.getViewportPageBounds().center),r.centerOnPoint(f,{duration:xo})},[r,c]),d=w.useCallback(m=>{const f=m.currentTarget;if(lu(f,m),!r.getCurrentPageShapeIds().size)return;s.current=!0,c.isInViewport=!1;const S=c.minimapScreenPointToPagePoint(m.clientX,m.clientY,!1,!1),v=c.minimapScreenPointToPagePoint(m.clientX,m.clientY,!1,!0),x=r.getViewportPageBounds();if(c.isInViewport=x.containsPoint(v),c.isInViewport)c.originPagePoint.setTo(v),c.originPageCenter.setTo(x.center);else{const P=C.Sub(x.center,x.point),E=C.Add(S,P);c.originPagePoint.setTo(E),c.originPageCenter.setTo(S),r.centerOnPoint(S,{duration:xo})}function b(P){f&&cu(f,P),s.current=!1,document.body.removeEventListener("pointerup",b)}document.body.addEventListener("pointerup",b)},[r,c]),h=w.useCallback(m=>{const f=c.minimapScreenPointToPagePoint(m.clientX,m.clientY,m.shiftKey,!0);if(s.current){if(c.isInViewport){const b=c.originPagePoint.clone().sub(c.originPageCenter);r.centerOnPoint(C.Sub(f,b));return}r.centerOnPoint(f)}const S=c.getPagePoint(m.clientX,m.clientY),v=r.pageToScreen(S),x={type:"pointer",target:"canvas",name:"pointer_move",...vn(m),point:v,isPen:r.getInstanceState().isPenMode};r.dispatch(x)},[r,c]),p=w.useCallback(m=>{const f=JE(m);r.dispatch({type:"wheel",name:"wheel",delta:f,point:new C(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey})},[r]);return ii("update when dpr changes",()=>{const m=a.get();c.setDpr(m);const f=o.current,S=f.getBoundingClientRect(),v=S.width*m,x=S.height*m;f.width=v,f.height=x,c.canvasScreenBounds.set(S.x,S.y,v,x),c.cvs=o.current},[a,c]),ii("minimap render when pagebounds or collaborators changes",()=>{const m=r.getCurrentPageShapeIds(),f=r.getCurrentPageBounds(),S=r.getViewportPageBounds();a.get(),c.contentPageBounds=f?re.Expand(f,S):S,c.updateContentScreenBounds();const v=[];m.forEach(x=>{let b=r.getShapePageBounds(x);if(!b)return;const P=r.getShapeMask(x);if(P){const E=My(P,b.corners);if(!E)return;b=re.FromPoints(E)}b&&(b.id=x,v.push(b))}),c.pageBounds=v,c.collaborators=l.get(),c.render()},[r,c]),g.jsx("div",{className:"tlui-minimap",children:g.jsx("canvas",{ref:o,className:"tlui-minimap__canvas",onDoubleClick:u,onPointerMove:h,onPointerDown:d,onWheel:p})})}const Wm=je(function(){const n=U(),t=be(),r=Qn(),o=n.getZoomLevel(),s=n.getCurrentPageShapeIds().size>0,i=n.getSelectedShapeIds().length>0,a=n.getZoomLevel()===1,l=w.useCallback(()=>{n.resetZoom(n.getViewportScreenCenter(),{duration:xo})},[n]);return g.jsxs(Ms,{id:"zoom",children:[g.jsx(Au,{children:g.jsx(ie,{type:"icon",title:`${t("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu",className:r<5?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:l,icon:r<4?"zoom-in":void 0,children:r<4?null:g.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(o*100),"%"]})})}),g.jsx(Os,{side:"top",align:"start",alignOffset:0,children:g.jsxs(Mo,{children:[g.jsx(Bl,{action:"zoom-in","data-testid":"minimap.zoom-menu.zoom-in",noClose:!0}),g.jsx(Bl,{action:"zoom-out","data-testid":"minimap.zoom-menu.zoom-out",noClose:!0}),g.jsx(Bl,{action:"zoom-to-100","data-testid":"minimap.zoom-menu.zoom-to-100",noClose:!0,disabled:a}),g.jsx(Bl,{action:"zoom-to-fit",disabled:!s,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0}),g.jsx(Bl,{action:"zoom-to-selection",disabled:!i,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})]})})]})});function Bl(e){const{action:n,disabled:t=!1,noClose:r=!1}=e,o=nn();return g.jsx(Fn,{type:"menu",label:o[n].label,kbd:o[n].kbd,"data-testid":e["data-testid"],onClick:()=>o[n].onSelect("zoom-menu"),noClose:r,disabled:t})}const aJ=w.memo(function(){const n=nn(),t=be(),r=Qn(),[o,s]=sJ("minimap",!0),i=w.useCallback(()=>{s(a=>!a)},[s]);return r<4?null:g.jsxs("div",{className:"tlui-navigation-zone",children:[g.jsx("div",{className:"tlui-buttons__horizontal",children:r<6?g.jsx(Wm,{}):o?g.jsxs(g.Fragment,{children:[g.jsx(Wm,{}),g.jsx(ie,{type:"icon",icon:o?"chevrons-ne":"chevrons-sw","data-testid":"minimap.toggle",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-zone__toggle",onClick:i})]}):g.jsxs(g.Fragment,{children:[g.jsx(ie,{type:"icon",icon:"minus","data-testid":"minimap.zoom-out",title:`${t(n["zoom-out"].label)} ${no(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone")}),g.jsx(Wm,{}),g.jsx(ie,{type:"icon",icon:"plus","data-testid":"minimap.zoom-in",title:`${t(n["zoom-in"].label)} ${no(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone")}),g.jsx(ie,{type:"icon",icon:o?"chevrons-ne":"chevrons-sw","data-testid":"minimap.toggle",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-zone__toggle",onClick:i})]})}),r>=6&&!o&&g.jsx(iJ,{viewportFill:"--color-muted-1",selectFill:"--color-selected",shapeFill:"--color-text-3"})]})}),lJ=je(function(){const t=U().getInstanceState().isPenMode,r=nn();if(!t)return null;const o=r["exit-pen-mode"];return g.jsx(ie,{type:"normal",label:o.label,iconLeft:o.icon,onClick:()=>o.onSelect("helper-buttons")})}),cJ=je(function(){const n=U(),t=nn();if(!n.getInstanceState().followingUserId)return null;const r=t["stop-following"];return g.jsx(ie,{type:"normal",label:r.label,iconLeft:r.icon,onClick:()=>r.onSelect("people-menu")})}),uJ=[hr,ui,Ma,to];function oM(){const e=U();return G("getRelevantStyles",()=>{var r;const n=new Oy(e.getSharedStyles()),t=e.getSelectedShapeIds().length>0||!!((r=e.root.getCurrent())!=null&&r.shapeType);if(n.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const o of uJ)n.applyValue(o,e.getStyleForNextShape(o));return n.size===0&&!t?null:{styles:n,opacity:e.getSharedOpacity()}},[e])}function dJ(e){const{uiType:n,items:t,title:r,style:o,value:s,onValueChange:i}=e,a=U(),l=be(),c=w.useRef(!1),{handleButtonClick:u,handleButtonPointerDown:d,handleButtonPointerEnter:h,handleButtonPointerUp:p}=w.useMemo(()=>{const f=()=>{c.current=!1,window.removeEventListener("pointerup",f)};return{handleButtonClick:P=>{const{id:E}=P.currentTarget.dataset;s.type==="shared"&&s.value===E||(a.mark("point picker item"),i(o,E,!1))},handleButtonPointerDown:P=>{const{id:E}=P.currentTarget.dataset;a.mark("point picker item"),i(o,E,!0),c.current=!0,window.addEventListener("pointerup",f)},handleButtonPointerEnter:P=>{if(!c.current)return;const{id:E}=P.currentTarget.dataset;i(o,E,!0)},handleButtonPointerUp:P=>{const{id:E}=P.currentTarget.dataset;i(o,E,!1)}}},[s,a,i,o]),m=G("theme",()=>In({isDarkMode:a.user.getIsDarkMode()}),[a]);return g.jsx("div",{className:fe("tlui-buttons__grid"),children:t.map(f=>g.jsx(ie,{type:"icon","data-id":f.value,"data-testid":`style.${n}.${f.value}`,"aria-label":f.value,"data-state":s.type==="shared"&&s.value===f.value?"hinted":void 0,title:r+" — "+l(`${n}-style.${f.value}`),className:fe("tlui-button-grid__button"),style:o===hr?{color:m[f.value].solid}:void 0,onPointerEnter:h,onPointerDown:d,onPointerUp:p,onClick:u,icon:f.icon},f.value))})}const va=w.memo(dJ);function sM(e,[n,t]){return Math.min(t,Math.max(n,e))}function hJ(e){const n=w.useRef({value:e,previous:e});return w.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}const iM=["PageUp","PageDown"],aM=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],lM={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Mu="Slider",[cv,pJ,fJ]=Df(Mu),[cM,wte]=io(Mu,[fJ]),[gJ,Qf]=cM(Mu),mJ=w.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:d=()=>{},onValueCommit:h=()=>{},inverted:p=!1,...m}=e,[f,S]=w.useState(null),v=Ge(n,j=>S(j)),x=w.useRef(new Set),b=w.useRef(0),P=i==="horizontal",E=f?!!f.closest("form"):!0,k=P?yJ:SJ,[I=[],_]=Bs({prop:u,defaultProp:c,onChange:j=>{var F;(F=[...x.current][b.current])===null||F===void 0||F.focus(),d(j)}}),A=w.useRef(I);function T(j){const F=IJ(I,j);z(j,F)}function D(j){z(j,b.current)}function L(){const j=A.current[b.current];I[b.current]!==j&&h(I)}function z(j,F,{commit:Y}={commit:!1}){const K=AJ(s),H=MJ(Math.round((j-r)/s)*s+r,K),B=sM(H,[r,o]);_((V=[])=>{const X=EJ(V,B,F);if($J(X,l*s)){b.current=X.indexOf(B);const ae=String(X)!==String(V);return ae&&Y&&h(X),ae?X:V}else return V})}return w.createElement(gJ,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:b,thumbs:x.current,values:I,orientation:i},w.createElement(cv.Provider,{scope:e.__scopeSlider},w.createElement(cv.Slot,{scope:e.__scopeSlider},w.createElement(k,Q({"aria-disabled":a,"data-disabled":a?"":void 0},m,{ref:v,onPointerDown:se(m.onPointerDown,()=>{a||(A.current=I)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:T,onSlideMove:a?void 0:D,onSlideEnd:a?void 0:L,onHomeKeyDown:()=>!a&&z(r,0,{commit:!0}),onEndKeyDown:()=>!a&&z(o,I.length-1,{commit:!0}),onStepKeyDown:({event:j,direction:F})=>{if(!a){const H=iM.includes(j.key)||j.shiftKey&&aM.includes(j.key)?10:1,B=b.current,V=I[B],X=s*H*F;z(V+X,B,{commit:!0})}}})))),E&&I.map((j,F)=>w.createElement(CJ,{key:F,name:t?t+(I.length>1?"[]":""):void 0,value:j})))}),[uM,dM]=cM(Mu,{startEdge:"left",endEdge:"right",size:"width",direction:1}),yJ=w.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[d,h]=w.useState(null),p=Ge(n,b=>h(b)),m=w.useRef(),f=Tw(o),S=f==="ltr",v=S&&!s||!S&&s;function x(b){const P=m.current||d.getBoundingClientRect(),E=[0,P.width],I=Gw(E,v?[t,r]:[r,t]);return m.current=P,I(b-P.left)}return w.createElement(uM,{scope:e.__scopeSlider,startEdge:v?"left":"right",endEdge:v?"right":"left",direction:v?1:-1,size:"width"},w.createElement(hM,Q({dir:f,"data-orientation":"horizontal"},u,{ref:p,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=x(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=x(b.clientX);a==null||a(P)},onSlideEnd:()=>{m.current=void 0,l==null||l()},onStepKeyDown:b=>{const E=lM[v?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:E?-1:1})}})))}),SJ=w.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=w.useRef(null),d=Ge(n,u),h=w.useRef(),p=!o;function m(f){const S=h.current||u.current.getBoundingClientRect(),v=[0,S.height],b=Gw(v,p?[r,t]:[t,r]);return h.current=S,b(f-S.top)}return w.createElement(uM,{scope:e.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1},w.createElement(hM,Q({"data-orientation":"vertical"},c,{ref:d,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:f=>{const S=m(f.clientY);s==null||s(S)},onSlideMove:f=>{const S=m(f.clientY);i==null||i(S)},onSlideEnd:()=>{h.current=void 0,a==null||a()},onStepKeyDown:f=>{const v=lM[p?"from-bottom":"from-top"].includes(f.key);l==null||l({event:f,direction:v?-1:1})}})))}),hM=w.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=Qf(Mu,t);return w.createElement(ze.span,Q({},c,{ref:n,onKeyDown:se(e.onKeyDown,d=>{d.key==="Home"?(i(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):iM.concat(aM).includes(d.key)&&(l(d),d.preventDefault())}),onPointerDown:se(e.onPointerDown,d=>{const h=d.target;h.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(h)?h.focus():r(d)}),onPointerMove:se(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:se(e.onPointerUp,d=>{const h=d.target;h.hasPointerCapture(d.pointerId)&&(h.releasePointerCapture(d.pointerId),s(d))})}))}),vJ="SliderTrack",wJ=w.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Qf(vJ,t);return w.createElement(ze.span,Q({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),BC="SliderRange",xJ=w.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Qf(BC,t),s=dM(BC,t),i=w.useRef(null),a=Ge(n,i),l=o.values.length,c=o.values.map(h=>pM(h,o.min,o.max)),u=l>1?Math.min(...c):0,d=100-Math.max(...c);return w.createElement(ze.span,Q({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:d+"%"}}))}),UC="SliderThumb",bJ=w.forwardRef((e,n)=>{const t=pJ(e.__scopeSlider),[r,o]=w.useState(null),s=Ge(n,a=>o(a)),i=w.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return w.createElement(PJ,Q({},e,{ref:s,index:i}))}),PJ=w.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,s=Qf(UC,t),i=dM(UC,t),[a,l]=w.useState(null),c=Ge(n,S=>l(S)),u=oA(a),d=s.values[r],h=d===void 0?0:pM(d,s.min,s.max),p=kJ(r,s.values.length),m=u==null?void 0:u[i.size],f=m?_J(m,h,i.direction):0;return w.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),w.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${h}% + ${f}px)`}},w.createElement(cv.ItemSlot,{scope:e.__scopeSlider},w.createElement(ze.span,Q({role:"slider","aria-label":e["aria-label"]||p,"aria-valuemin":s.min,"aria-valuenow":d,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:c,style:d===void 0?{display:"none"}:e.style,onFocus:se(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),CJ=e=>{const{value:n,...t}=e,r=w.useRef(null),o=hJ(n);return w.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&l){const c=new Event("input",{bubbles:!0});l.call(s,n),s.dispatchEvent(c)}},[o,n]),w.createElement("input",Q({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function EJ(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function pM(e,n,t){const s=100/(t-n)*(e-n);return sM(s,[0,100])}function kJ(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function IJ(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 _J(e,n,t){const r=e/2,s=Gw([0,50],[0,r]);return(r-s(n)*t)*t}function TJ(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function $J(e,n){if(n>0){const t=TJ(e);return Math.min(...t)>=n}return!0}function Gw(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 AJ(e){return(String(e).split(".")[1]||"").length}function MJ(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const OJ=mJ,RJ=wJ,DJ=xJ,jJ=bJ,LJ=w.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=U(),l=be(),c=w.useCallback(h=>{i(h[0],!0)},[i]),u=w.useCallback(()=>{a.mark("click slider")},[a]),d=w.useCallback(()=>{o&&i(o,!1)},[o,i]);return g.jsx("div",{className:"tlui-slider__container",children:g.jsxs(OJ,{"data-testid":n["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:d,title:t+" — "+l(s),children:[g.jsx(RJ,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&g.jsx(DJ,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&g.jsx(jJ,{className:"tlui-slider__thumb",dir:"ltr"})]})})}),NJ=w.memo(function({label:n,uiTypeA:t,uiTypeB:r,labelA:o,labelB:s,itemsA:i,itemsB:a,styleA:l,styleB:c,valueA:u,valueB:d,onValueChange:h}){const p=be(),m=w.useMemo(()=>{var S;return((S=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:S.icon)??"mixed"},[i,u]),f=w.useMemo(()=>{var S;return((S=a.find(v=>d.type==="shared"&&d.value===v.value))==null?void 0:S.icon)??"mixed"},[a,d]);return u===void 0&&d===void 0?null:g.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[g.jsx("div",{title:p(n),className:"tlui-style-panel__double-select-picker-label",children:p(n)}),g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsxs(Ms,{id:`style panel ${t} A`,children:[g.jsx(eu,{asChild:!0,onTouchEnd:S=>Ee(S),children:g.jsx(ie,{type:"icon","data-testid":`style.${t}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${u.value}`)),icon:m,invertIcon:!0,smallIcon:!0})}),g.jsx(Os,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:g.jsx("div",{className:"tlui-buttons__grid",children:i.map(S=>g.jsx(Fn,{type:"icon",title:p(o)+" — "+p(`${t}-style.${S.value}`),"data-testid":`style.${t}.${S.value}`,icon:S.icon,onClick:()=>h(l,S.value,!1),invertIcon:!0},S.value))})})]}),g.jsxs(Ms,{id:`style panel ${r}`,children:[g.jsx(eu,{asChild:!0,onTouchEnd:S=>Ee(S),children:g.jsx(ie,{type:"icon","data-testid":`style.${r}`,title:p(s)+" — "+(d===null||d.type==="mixed"?p("style-panel.mixed"):p(`${r}-style.${d.value}`)),icon:f,smallIcon:!0})}),g.jsx(Os,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:g.jsx("div",{className:"tlui-buttons__grid",children:a.map(S=>g.jsx(Fn,{type:"icon",title:p(s)+" — "+p(`${r}-style.${S.value}`),"data-testid":`style.${r}.${S.value}`,icon:S.icon,onClick:()=>h(c,S.value,!1)},S.value))})})]})]})]})}),Yw=w.memo(function({id:n,label:t,uiType:r,style:o,items:s,type:i,value:a,onValueChange:l}){const c=be(),u=w.useMemo(()=>{var d;return(d=s.find(h=>a.type==="shared"&&h.value===a.value))==null?void 0:d.icon},[s,a]);return g.jsxs(Ms,{id:`style panel ${n}`,children:[g.jsx(eu,{asChild:!0,onTouchEnd:d=>Ee(d),children:g.jsx(ie,{type:i,"data-testid":`style.${r}`,title:a.type==="mixed"?c("style-panel.mixed"):c(`${r}-style.${a.value}`),label:t,icon:u??"mixed"})}),g.jsx(Os,{side:"left",align:"center",alignOffset:0,children:g.jsx("div",{className:"tlui-buttons__grid",children:s.map(d=>g.jsx(Fn,{type:"icon","data-testid":`style.${r}.${d.value}`,title:c(`${r}-style.${d.value}`),icon:d.icon,onClick:()=>l(o,d.value,!1)},d.value))})})]})}),Ir={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],horizontalAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-center"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"cloud",icon:"geo-cloud"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"star",icon:"geo-star"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},fM=function({isMobile:n}){const t=U(),r=oM(),o=w.useCallback(()=>{n||t.updateInstanceState({isChangingStyle:!1})},[t,n]);if(!r)return null;const{styles:s,opacity:i}=r,a=s.get(qr),l=s.get(ep),c=s.get(Jh),u=s.get(np),d=s.get(eo),h=a===void 0,p=l===void 0&&c===void 0,m=u===void 0,f=d===void 0;return g.jsxs("div",{className:"tlui-style-panel","data-ismobile":n,onPointerLeave:o,children:[g.jsx(FJ,{styles:s,opacity:i}),!f&&g.jsx(zJ,{styles:s}),!(h&&p&&m)&&g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[g.jsx(BJ,{styles:s}),g.jsx(HJ,{styles:s}),g.jsx(UJ,{styles:s})]})]})};function Ou(){const e=U();return ne.useMemo(()=>function(t,r,o){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(t,r,{squashing:o}),e.setStyleForNextShapes(t,r,{squashing:o}),e.updateInstanceState({isChangingStyle:!0})})},[e])}const Ul=[.1,.25,.5,.75,1];function FJ({styles:e,opacity:n}){const t=U(),r=be(),o=Ou(),s=ne.useCallback((h,p)=>{const m=Ul[h];t.batch(()=>{t.isIn("select")&&t.setOpacityForSelectedShapes(m,{ephemeral:p}),t.setOpacityForNextShapes(m,{ephemeral:p}),t.updateInstanceState({isChangingStyle:!0})})},[t]),i=e.get(hr),a=e.get(Ma),l=e.get(ui),c=e.get(to),u=a!==void 0||l!==void 0||c!==void 0,d=n.type==="mixed"?-1:Ul.indexOf(SR(Ul,h=>Math.abs(h-n.value)));return g.jsxs(g.Fragment,{children:[g.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles",children:[i===void 0?null:g.jsx(va,{title:r("style-panel.color"),uiType:"color",style:hr,items:Ir.color,value:i,onValueChange:o}),n===void 0?null:g.jsx(LJ,{"data-testid":"style.opacity",value:d>=0?d:Ul.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:s,steps:Ul.length-1,title:r("style-panel.opacity")})]}),u&&g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:g.jsx(va,{title:r("style-panel.fill"),uiType:"fill",style:Ma,items:Ir.fill,value:a,onValueChange:o}),l===void 0?null:g.jsx(va,{title:r("style-panel.dash"),uiType:"dash",style:ui,items:Ir.dash,value:l,onValueChange:o}),c===void 0?null:g.jsx(va,{title:r("style-panel.size"),uiType:"size",style:to,items:Ir.size,value:c,onValueChange:o})]})]})}function zJ({styles:e}){const n=be(),t=Ou(),r=e.get(eo),o=e.get(vc),s=e.get(tp);return r===void 0&&o===void 0?null:g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[r===void 0?null:g.jsx(va,{title:n("style-panel.font"),uiType:"font",style:eo,items:Ir.font,value:r,onValueChange:t}),o===void 0?null:g.jsxs("div",{className:"tlui-style-panel__row",children:[g.jsx(va,{title:n("style-panel.align"),uiType:"align",style:vc,items:Ir.horizontalAlign,value:o,onValueChange:t}),g.jsx("div",{className:"tlui-style-panel__row__extra-button",children:s===void 0?g.jsx(ie,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",icon:"vertical-align-center",disabled:!0}):g.jsx(Yw,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:tp,items:Ir.verticalAlign,value:s,onValueChange:t})})]})]})}function BJ({styles:e}){const n=Ou(),t=e.get(qr);return t===void 0?null:g.jsx(Yw,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:qr,items:Ir.geo,value:t,onValueChange:n})}function UJ({styles:e}){const n=Ou(),t=e.get(np);return t===void 0?null:g.jsx(Yw,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:np,items:Ir.spline,value:t,onValueChange:n})}function HJ({styles:e}){const n=Ou(),t=e.get(ep),r=e.get(Jh);return!t||!r?null:g.jsx(NJ,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Jh,itemsA:Ir.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:ep,itemsB:Ir.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}function VJ({toast:e}){const{removeToast:n}=ao(),t=be(),r=s=>{s||n(e.id)},o=e.actions&&e.actions.length>0;return g.jsxs(BG,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,children:[e.icon&&g.jsx("div",{className:"tlui-toast__icon",children:g.jsx(Vn,{icon:e.icon})}),g.jsxs("div",{className:"tlui-toast__main",children:[g.jsxs("div",{className:"tlui-toast__content",children:[e.title&&g.jsx(UG,{className:"tlui-toast__title",children:e.title}),e.description&&g.jsx(HG,{className:"tlui-toast__description",children:e.description})]}),e.actions&&g.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((s,i)=>g.jsx(VG,{altText:s.label,asChild:!0,onClick:s.onClick,children:g.jsx(ie,{type:s.type,children:s.label})},i)),g.jsx(gC,{asChild:!0,children:g.jsx(ie,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:e.closeLabel??t("toast.close")})})]})]}),!o&&g.jsx(gC,{asChild:!0,children:g.jsx(ie,{type:"normal",className:"tlui-toast__close",children:e.closeLabel??t("toast.close")})})]})}function KJ(){const{toasts:e}=ao();return g.jsx(g.Fragment,{children:e.map(n=>g.jsx(VJ,{toast:n},n.id))})}const WJ=w.memo(KJ);function GJ(){const{toasts:e}=ao(),[n,t]=w.useState(!1);return w.useEffect(()=>{let r=!1;return e.length?t(!0):setTimeout(()=>{r||t(!1)},1e3),()=>{r=!0}},[e.length,t]),n?g.jsx(CG,{className:"tlui-toast__viewport"}):null}const Gm=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Ym(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function Hl(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.deachEvent&&e.deachEvent("on".concat(n),t)}function gM(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 mM(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 YJ(e,n){const t=e.length>=n.length?e:n,r=e.length>=n.length?n:e;let o=!0;for(let s=0;s<t.length;s++)r.indexOf(t[s])===-1&&(o=!1);return o}const nu={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,"-":Gm?173:189,"=":Gm?61:187,";":Gm?59:186,"'":222,"[":219,"]":221,"\\":220},oo={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},uv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Tt={16:!1,18:!1,17:!1,91:!1},it={};for(let e=1;e<20;e++)nu["f".concat(e)]=111+e;let He=[],mc=null,yM="all";const yo=new Map,Ru=e=>nu[e.toLowerCase()]||oo[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),XJ=e=>Object.keys(nu).find(n=>nu[n]===e),qJ=e=>Object.keys(oo).find(n=>oo[n]===e);function SM(e){yM=e||"all"}function ru(){return yM||"all"}function ZJ(){return He.slice(0)}function QJ(){return He.map(e=>XJ(e)||qJ(e)||String.fromCharCode(e))}function JJ(){const e=[];return Object.keys(it).forEach(n=>{it[n].forEach(t=>{let{key:r,scope:o,mods:s,shortcut:i}=t;e.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>Ru(a))})})}),e}function eee(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 tee(e){return typeof e=="string"&&(e=Ru(e)),He.indexOf(e)!==-1}function nee(e,n){let t,r;e||(e=ru());for(const o in it)if(Object.prototype.hasOwnProperty.call(it,o))for(t=it[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return Xw(a)}):r++;ru()===e&&SM(n||"all")}function ree(e){let n=e.keyCode||e.which||e.charCode;const t=He.indexOf(n);if(t>=0&&He.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&He.splice(0,He.length),(n===93||n===224)&&(n=91),n in Tt){Tt[n]=!1;for(const r in oo)oo[r]===n&&(xn[r]=!1)}}function vM(e){if(typeof e>"u")Object.keys(it).forEach(o=>{Array.isArray(it[o])&&it[o].forEach(s=>Vd(s)),delete it[o]}),Xw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Vd(o)});else if(typeof e=="object")e.key&&Vd(e);else if(typeof e=="string"){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];let[o,s]=t;typeof o=="function"&&(s=o,o=""),Vd({key:e,scope:o,method:s,splitKey:"+"})}}const Vd=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;mM(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Ru(c);if(!it[u])return;t||(t=ru());const d=l>1?gM(oo,a):[],h=[];it[u]=it[u].filter(p=>{const f=(r?p.method===r:!0)&&p.scope===t&&YJ(p.mods,d);return f&&h.push(p.element),!f}),h.forEach(p=>Xw(p))})};function HC(e,n,t,r){if(n.element!==r)return;let o;if(n.scope===t||n.scope==="all"){o=n.mods.length>0;for(const s in Tt)Object.prototype.hasOwnProperty.call(Tt,s)&&(!Tt[s]&&n.mods.indexOf(+s)>-1||Tt[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!Tt[16]&&!Tt[18]&&!Tt[17]&&!Tt[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(He),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function VC(e,n){const t=it["*"];let r=e.keyCode||e.which||e.charCode;if(!xn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),He.indexOf(r)===-1&&r!==229&&He.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=uv[a];e[a]&&He.indexOf(l)===-1?He.push(l):!e[a]&&He.indexOf(l)>-1?He.splice(He.indexOf(l),1):a==="metaKey"&&e[a]&&He.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(He=He.slice(He.indexOf(l))))}),r in Tt){Tt[r]=!0;for(const a in oo)oo[a]===r&&(xn[a]=!0);if(!t)return}for(const a in Tt)Object.prototype.hasOwnProperty.call(Tt,a)&&(Tt[a]=e[uv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(He.indexOf(17)===-1&&He.push(17),He.indexOf(18)===-1&&He.push(18),Tt[17]=!0,Tt[18]=!0);const o=ru();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)&&HC(e,t[a],o,n);if(!(r in it))return;const s=it[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,u=l.key.split(c),d=[];for(let h=0;h<u.length;h++)d.push(Ru(u[h]));d.sort().join("")===He.sort().join("")&&HC(e,l,o,n)}}function xn(e,n,t){He=[];const r=mM(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",d=!1,h=!1;for(t===void 0&&typeof n=="function"&&(t=n),Object.prototype.toString.call(n)==="[object Object]"&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(l=n.keyup),n.keydown!==void 0&&(c=n.keydown),n.capture!==void 0&&(d=n.capture),typeof n.splitKey=="string"&&(u=n.splitKey),n.single===!0&&(h=!0)),typeof n=="string"&&(s=n),h&&vM(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=gM(oo,e)),e=e[e.length-1],e=e==="*"?"*":Ru(e),e in it||(it[e]=[]),it[e].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!yo.has(i)){const p=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return VC(f,i)},m=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;VC(f,i),ree(f)};yo.set(i,{keydownListener:p,keyupListenr:m,capture:d}),Ym(i,"keydown",p,d),Ym(i,"keyup",m,d)}if(!mc){const p=()=>{He=[]};mc={listener:p,capture:d},Ym(window,"focus",p,d)}}}function oee(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(it).forEach(t=>{it[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function Xw(e){const n=Object.values(it).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=yo.get(e)||{};r&&o&&(Hl(e,"keyup",o,s),Hl(e,"keydown",r,s),yo.delete(e))}if((n.length<=0||yo.size<=0)&&(Object.keys(yo).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=yo.get(o)||{};s&&i&&(Hl(o,"keyup",i,a),Hl(o,"keydown",s,a),yo.delete(o))}),yo.clear(),Object.keys(it).forEach(o=>delete it[o]),mc)){const{listener:o,capture:s}=mc;Hl(window,"focus",o,s),mc=null}}const Xm={getPressedKeyString:QJ,setScope:SM,getScope:ru,deleteScope:nee,getPressedKeyCodes:ZJ,getAllKeyCodes:JJ,isPressed:tee,filter:eee,trigger:oee,unbind:vM,keyMap:nu,modifier:oo,modifierMap:uv};for(const e in Xm)Object.prototype.hasOwnProperty.call(Xm,e)&&(xn[e]=Xm[e]);if(typeof window<"u"){const e=window.hotkeys;xn.noConflict=n=>(n&&window.hotkeys===xn&&(window.hotkeys=e),xn),window.hotkeys=xn}const KC=["copy","cut","paste","asset"];function see(){const e=U(),n=Yn(),t=nn(),r=_w(),o=G("is focused",()=>e.getInstanceState().isFocused,[e]),{itemsInPanel:s}=wM();w.useEffect(()=>{if(!o)return;const i=e.getContainer();xn.setScope(e.store.id);const a=(c,u)=>{xn(c,{element:i,scope:e.store.id},u)},l=(c,u)=>{xn(c,{element:i,keyup:!0,keydown:!1,scope:e.store.id},u)};for(const c of Object.values(t))c.kbd&&(n&&!c.readonlyOk||KC.includes(c.id)||a(WC(c.kbd),u=>{Ql(e)||(Ee(u),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&e.getInstanceState().isReadonly||KC.includes(c.id)||a(WC(c.kbd),u=>{Ql(e)||(Ee(u),c.onSelect("kbd"))});return a(",",c=>{if(Ql(e)||e.inputs.keys.has("Comma"))return;Ee(c),i.focus(),e.inputs.keys.add("Comma");const{x:u,y:d,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:u,y:d,z:h},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),l(",",c=>{if(Ql(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:u,y:d,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:u,y:d,z:h},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{xn.deleteScope(e.store.id)}},[t,r,n,e,o,s])}function WC(e){return iee(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 iee(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 Ql(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}function aee(){const e=U(),n=be(),t=oM(),r=t==null?void 0:t.styles.get(hr),o=In({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=G("isHandOrEraserToolActive",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=w.useCallback(l=>{l||e.updateInstanceState({isChangingStyle:!1})},[e]);return g.jsxs(Kw,{id:"style menu",onOpenChange:a,children:[g.jsx(Ww,{disabled:i,children:g.jsx(ie,{type:"tool","data-testid":"mobile.styles",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),children:g.jsx(Vn,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),g.jsx(QA,{side:"top",align:"end",children:g.jsx(fM,{isMobile:!0})})]})}const lee=["select","hand","draw","eraser","text","zoom","laser","highlight"];function cee({activeToolId:e}){const n=U(),t=Qn(),r=be(),o=G("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||lee.includes(e)?null:g.jsx(ie,{type:"normal",title:r("action.toggle-tool-lock"),className:fe("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<5}),icon:o?"lock":"unlock",onClick:()=>n.updateInstanceState({isToolLocked:!o}),smallIcon:!0})}const uee=w.memo(function(){const n=U(),t=be(),r=Qn(),o=ne.useRef(void 0),s=Yn(),i=K$(),a=G("current tool id",()=>n.getCurrentToolId(),[n]),l=G("geo",()=>n.getSharedStyles().getAsKnownValue(qr),[n]),c=m=>m.label?`${t(m.label)} ${m.kbd?no(m.kbd):""}`:"",u=i.find(m=>qm(m.toolItem,a,l)),{itemsInPanel:d,itemsInDropdown:h}=wM(),p=w.useMemo(()=>{let m=h.find(f=>f===u);return m||(o.current||(o.current=h[0]),m=o.current,h.includes(m)||(m=h[0])),o.current=m,m},[u,h]);return w.useEffect(()=>{const m=[...d,p];for(let f=0;f<Math.min(10,m.length);f++){const S=`${f+1}`.slice(-1);xn(S,v=>{Ql(n)||(Ee(v),m[f].toolItem.onSelect("kbd"))})}return()=>{xn.unbind("1,2,3,4,5,6,7,8,9,0")}},[p,n,d]),g.jsx("div",{className:"tlui-toolbar",children:g.jsxs("div",{className:"tlui-toolbar__inner",children:[g.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&g.jsxs("div",{className:"tlui-toolbar__extras",children:[r<6&&!(a==="hand"||a==="zoom")&&g.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[g.jsx(rM,{}),g.jsx(tM,{}),g.jsx(nM,{}),g.jsx(eM,{}),g.jsx(JA,{})]}),g.jsx(cee,{activeToolId:a})]}),g.jsxs("div",{className:fe("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<5}),children:[d.map(({toolItem:m})=>g.jsx(GC,{item:m,title:c(m),isSelected:qm(m,a,l)},m.id)),h.length?g.jsxs(g.Fragment,{children:[g.jsx(GC,{item:p.toolItem,title:c(p.toolItem),isSelected:qm(p.toolItem,a,l)},p.toolItem.id),g.jsxs(Ms,{id:"toolbar overflow",modal:!1,children:[g.jsx(Au,{children:g.jsx(ie,{className:"tlui-toolbar__overflow",icon:"chevron-up",type:"tool","data-testid":"tools.more",title:t("tool-panel.more")})}),g.jsx(Os,{side:"top",align:"center",children:g.jsx(dee,{toolbarItems:h})})]})]}):null]})]}),r<5&&!s&&g.jsx("div",{className:"tlui-toolbar__tools",children:g.jsx(aee,{})})]})})}),dee=je(function({toolbarItems:n}){const t=be();return g.jsx("div",{className:"tlui-buttons__grid",children:n.map(({toolItem:{id:r,meta:o,kbd:s,label:i,onSelect:a,icon:l}})=>g.jsx(Fn,{type:"icon",className:"tlui-button-grid__button","data-testid":`tools.more.${r}`,"data-tool":r,"data-geo":(o==null?void 0:o.geo)??"","aria-label":i,onClick:()=>a("toolbar"),title:i?`${t(i)} ${s?no(s):""}`:"",icon:l},r))})});function GC({item:e,title:n,isSelected:t}){var r;return g.jsx(ie,{type:"tool","data-testid":`tools.${e.id}`,"data-tool":e.id,"data-geo":((r=e.meta)==null?void 0:r.geo)??"","aria-label":e.label,title:n,icon:e.icon,"data-state":t?"selected":void 0,onClick:()=>e.onSelect("toolbar"),onTouchStart:o=>{Ee(o),e.onSelect("toolbar")}})}const qm=(e,n,t)=>{var r,o;return(r=e.meta)!=null&&r.geo?n==="geo"&&t===((o=e.meta)==null?void 0:o.geo):n===e.id};function wM(){const e=Qn(),n=K$(),t=Yn();return w.useMemo(()=>{const r=n.filter(a=>!t||a.readonlyOk),o=Math.min(8,5+e),s=r.slice(0,o),i=r.slice(o);return i.length<=2?{itemsInPanel:r,itemsInDropdown:[]}:{itemsInPanel:s,itemsInDropdown:i}},[n,e,t])}function hee(){const e=U(),{addToast:n}=ao();w.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.`})}return e.addListener("max-shapes",t),()=>{e.removeListener("max-shapes",t)}},[e,n])}const pee=ne.memo(function({shareZone:n,topZone:t,renderDebugMenuItems:r,children:o,hideUi:s,...i}){return g.jsx(hq,{...i,children:g.jsx(fee,{hideUi:s,shareZone:n,topZone:t,renderDebugMenuItems:r,children:o})})}),fee=ne.memo(function({children:n,hideUi:t,...r}){return g.jsxs(g.Fragment,{children:[n,t?null:g.jsx(gee,{...r})]})}),gee=ne.memo(function({shareZone:n,topZone:t,renderDebugMenuItems:r}){const o=U(),s=be(),i=Qn(),a=G("isReadonlyMode",()=>o.getInstanceState().isReadonly,[o]),l=G("focus",()=>o.getInstanceState().isFocusMode,[o]),c=G("debug",()=>o.getInstanceState().isDebugMode,[o]);see(),AX(),hee();const{"toggle-focus-mode":u}=nn();return g.jsx(HT,{children:g.jsxs("div",{className:fe("tlui-layout",{"tlui-layout__mobile":i<5}),"data-breakpoint":i,children:[l?g.jsx("div",{className:"tlui-layout__top",children:g.jsx(ie,{type:"icon",className:"tlui-focus-button",title:`${s("focus-mode.toggle-focus-mode")}`,icon:"dot",onClick:()=>u.onSelect("menu")})}):g.jsxs(g.Fragment,{children:[g.jsxs("div",{className:"tlui-layout__top",children:[g.jsxs("div",{className:"tlui-layout__top__left",children:[g.jsx(oJ,{}),g.jsxs("div",{className:"tlui-helper-buttons",children:[g.jsx(lJ,{}),g.jsx(fq,{}),g.jsx(cJ,{})]})]}),g.jsx("div",{className:"tlui-layout__top__center",children:t}),g.jsxs("div",{className:"tlui-layout__top__right",children:[n,i>=5&&!a&&g.jsx("div",{className:"tlui-style-panel__wrapper",children:g.jsx(fM,{})})]})]}),g.jsxs("div",{className:"tlui-layout__bottom",children:[g.jsxs("div",{className:"tlui-layout__bottom__main",children:[g.jsx(aJ,{}),g.jsx(uee,{}),i>=4&&g.jsx(zQ,{})]}),c&&g.jsx(IQ,{renderDebugMenuItems:r??null})]})]}),g.jsx(WJ,{}),g.jsx(LQ,{}),g.jsx(GJ,{}),g.jsx(NQ,{})]})})}),xM="ContextMenu",[mee,xte]=io(xM,[qf]),lo=qf(),[yee,bM]=mee(xM),See=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=w.useState(!1),l=lo(n),c=en(r),u=w.useCallback(d=>{a(d),c(d)},[c]);return w.createElement(yee,{scope:n,open:i,onOpenChange:u,modal:s},w.createElement(_A,Q({},l,{dir:o,open:i,onOpenChange:u,modal:s}),t))},vee="ContextMenuTrigger",wee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=bM(vee,t),i=lo(t),a=w.useRef({x:0,y:0}),l=w.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=w.useRef(0),u=w.useCallback(()=>window.clearTimeout(c.current),[]),d=h=>{a.current={x:h.clientX,y:h.clientY},s.onOpenChange(!0)};return w.useEffect(()=>u,[u]),w.useEffect(()=>void(r&&u()),[r,u]),w.createElement(w.Fragment,null,w.createElement(TA,Q({},i,{virtualRef:l})),w.createElement(ze.span,Q({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:se(e.onContextMenu,h=>{u(),d(h),h.preventDefault()}),onPointerDown:r?e.onPointerDown:se(e.onPointerDown,Kd(h=>{u(),c.current=window.setTimeout(()=>d(h),700)})),onPointerMove:r?e.onPointerMove:se(e.onPointerMove,Kd(u)),onPointerCancel:r?e.onPointerCancel:se(e.onPointerCancel,Kd(u)),onPointerUp:r?e.onPointerUp:se(e.onPointerUp,Kd(u))})))}),xee=e=>{const{__scopeContextMenu:n,...t}=e,r=lo(n);return w.createElement($A,Q({},r,t))},bee="ContextMenuContent",Pee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=bM(bee,t),s=lo(t),i=w.useRef(!1);return w.createElement(AA,Q({},s,r,{ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),Cee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=lo(t);return w.createElement(MA,Q({},o,r,{ref:n}))}),Eee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=lo(t);return w.createElement(OA,Q({},o,r,{ref:n}))}),kee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=lo(t);return w.createElement(RA,Q({},o,r,{ref:n}))}),Iee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=lo(n),[a,l]=Bs({prop:o,defaultProp:s,onChange:r});return w.createElement(DA,Q({},i,{open:a,onOpenChange:l}),t)},_ee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=lo(t);return w.createElement(jA,Q({},o,r,{ref:n}))}),Tee=w.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=lo(t);return w.createElement(LA,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 Kd(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const $ee=See,Aee=wee,dv=xee,Mee=Pee,hv=Cee,pv=Eee,Oee=kee,PM=Iee,CM=_ee,EM=Tee,Ree=je(function(){const n=U(),t=un(),r=n.getPages(),o=n.getCurrentPageId(),s=be(),{addToast:i}=ao();return g.jsxs(PM,{children:[g.jsx(CM,{dir:"ltr",asChild:!0,children:g.jsx(ie,{type:"menu",label:"context-menu.move-to-page","data-testid":"menu-item.move-to-page",icon:"chevron-right"})}),g.jsx(dv,{container:t,children:g.jsxs(EM,{className:"tlui-menu",sideOffset:-4,collisionPadding:4,children:[g.jsx(hv,{dir:"ltr",className:"tlui-menu__group","data-testid":"menu-item.pages",children:r.map(a=>g.jsx(pv,{disabled:o===a.id,onSelect:()=>{n.mark("move_shapes_to_page"),n.moveShapesToPage(n.getSelectedShapeIds(),a.id);const l=n.getPage(a.id);l&&i({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{n.mark("change-page"),n.setCurrentPage(o)}}]})},asChild:!0,children:g.jsx(ie,{type:"menu",title:a.name,className:"tlui-context-menu__move-to-page__name",children:g.jsx("span",{className:"tlui-button__label",children:a.name})})},a.id))},"pages"),g.jsx(hv,{dir:"ltr",className:"tlui-menu__group","data-testid":"menu-item.new-page",children:g.jsx(pv,{onSelect:()=>{const a=Oo.createId(),l=n.getSelectedShapeIds();n.batch(()=>{n.mark("move_shapes_to_page"),n.createPage({name:s("page-menu.new-page-initial-name"),id:a}),n.moveShapesToPage(l,a)})},asChild:!0,children:g.jsx(ie,{type:"menu",title:s("context.pages.new-page"),className:"tlui-context-menu__move-to-page__name",children:g.jsx("span",{className:"tlui-button__label",children:s("context.pages.new-page")})})},"new-page")},"new-page")]})})]})}),Dee=function({children:n}){const t=U(),r=j$(),o=w.useCallback(d=>{if(d){if(t.getInstanceState().isCoarsePointer){const h=t.getSelectedShapes(),{inputs:{currentPagePoint:p}}=t,m=t.getShapesAtPoint(p);if(!t.getSelectedShapes().length||!m.some(f=>h.includes(f))){const f=m.filter(S=>t.isShapeOrAncestorLocked(S));f.length&&t.select(...f.map(S=>S.id))}}}else{const h=t.getOnlySelectedShape();h&&t.isShapeOrAncestorLocked(h)&&t.setSelectedShapes([])}},[t]),[s,i]=Mi("context menu",o),a=Yn(),l=r.length===0||a&&r.every(d=>!d.readonlyOk),u=!G("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t])||l;return g.jsxs($ee,{dir:"ltr",onOpenChange:i,modal:!1,children:[g.jsx(Aee,{onContextMenu:u?Ee:void 0,dir:"ltr",disabled:u,children:n}),s&&g.jsx(jee,{})]})},jee=w.forwardRef(function(){const n=U(),t=be(),r=j$(),[o,s]=Mi("context menu sub"),i=Yn(),a=Qn(),l=un(),[c,u]=w.useState(!1);function d(h,p,m,f){if(!p||i&&!p.readonlyOk)return null;switch(p.type){case"custom":{switch(p.id){case"MOVE_TO_PAGE_MENU":return g.jsx(Ree,{},p.id)}break}case"group":return g.jsx(hv,{dir:"ltr",className:fe("tlui-menu__group",{"tlui-menu__group__small":(m==null?void 0:m.type)==="submenu"}),"data-testid":`menu-item.${p.id}`,children:p.children.map(S=>d(h,S,p,f+1))},p.id);case"submenu":return g.jsxs(PM,{onOpenChange:s,children:[g.jsx(CM,{dir:"ltr",disabled:p.disabled,asChild:!0,children:g.jsx(ie,{type:"menu",label:p.label,"data-testid":`menu-item.${p.id}`,icon:"chevron-right"})}),g.jsx(dv,{container:l,children:g.jsx(EM,{className:"tlui-menu",sideOffset:-4,collisionPadding:4,children:p.children.map(S=>d(h,S,p,f+1))})})]},p.id);case"item":{if(i&&!p.readonlyOk)return null;const{id:S,checkbox:v,contextMenuLabel:x,label:b,onSelect:P,kbd:E,icon:k}=p.actionItem,I=x??b,_=I?t(I):void 0;return v?g.jsxs(Oee,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",disabled:p.disabled,onSelect:A=>{P("context-menu"),Ee(A)},title:_||void 0,checked:p.checked,children:[g.jsx(Vn,{small:!0,icon:p.checked?"check":"checkbox-empty"}),_&&g.jsx("span",{className:"tlui-button__label",draggable:!1,children:_}),E&&g.jsx(zf,{children:E})]},S):g.jsx(pv,{dir:"ltr",asChild:!0,children:g.jsx(ie,{type:"menu","data-testid":`menu-item.${S}`,kbd:E,label:I,disabled:p.disabled,iconLeft:a<3&&f>2?k:void 0,onClick:()=>{c?u(!1):P("context-menu")}})},S)}}}return g.jsx(dv,{container:l,children:g.jsx(Mee,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ee,children:r.map(h=>d(n,h,null,0))})})}),Wd=(e,n)=>{const[t,r]=w.useState(2);return w.useEffect(()=>{const{url:o,style:s="normal",weight:i="500",display:a,featureSettings:l,stretch:c,unicodeRange:u,variant:d}=n;let h=!1;r(2);const p={style:s,weight:i,display:a,featureSettings:l,stretch:c,unicodeRange:u,variant:d},m=new FontFace(e,`url(${o})`,p);return m.load().then(()=>{h||(document.fonts.add(m),r(0))}).catch(f=>{h||(console.error(f),r(1))}),m.$$_url=o,m.$$_fontface=`
309
+ @font-face {
310
+ font-family: ${m.family};
311
+ font-stretch: ${m.stretch};
312
+ font-weight: ${m.weight};
313
+ font-style: ${m.style};
314
+ src: url("${o}") format("woff2")
315
+ }`,()=>{document.fonts.delete(m),h=!0}},[e,n]),t};function Lee(e){return{draw:{url:e.fonts.draw},serif:{url:e.fonts.serif},sansSerif:{url:e.fonts.sansSerif},monospace:{url:e.fonts.monospace}}}function Nee(e){const n=w.useMemo(()=>Lee(e),[e]),t=[Wd("tldraw_draw",n.draw),Wd("tldraw_serif",n.serif),Wd("tldraw_sans",n.sansSerif),Wd("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Fee(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,...a}=e,l=h4(a.components??{}),c=Tb(a.shapeUtils??[]),u=Tb(a.tools??[]),d={initialState:"select",...a,components:w.useMemo(()=>({Scribble:b1,CollaboratorScribble:b1,SelectionForeground:vU,SelectionBackground:yU,Handles:dU,HoveredShapeIndicator:hU,...l}),[l]),shapeUtils:w.useMemo(()=>[...LV,...c],[c]),tools:w.useMemo(()=>[...ZV,...pH,...u],[u])},h=KG(a.assetUrls),{done:p,error:m}=Nee(h);return m?g.jsx(l4,{children:"Could not load assets. Please refresh the page."}):p?g.jsx(o4,{...d,children:g.jsxs(pee,{...d,children:[g.jsx(Dee,{children:g.jsx(Fv,{})}),g.jsx(zee,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),n]})}):g.jsx(Dk,{children:"Loading assets..."})}function zee({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=["image/jpeg","image/png","image/gif","image/svg+xml"],acceptedVideoMimeTypes:r=["video/mp4","video/quicktime"],onMount:o}){const s=U(),i=Bee(a=>{const l=[];return l.push(...NV(a)),eH(a,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r}),l.push(o==null?void 0:o(a)),()=>{l.forEach(c=>c==null?void 0:c())}});return w.useLayoutEffect(()=>{if(s)return i==null?void 0:i(s)},[s,i]),null}function Bee(e){const n=w.useRef();return w.useLayoutEffect(()=>{n.current=e}),w.useDebugValue(e),w.useCallback((...t)=>{const r=n.current;return Io(r,"fn does not exist"),r(...t)},[])}const Uee=1,Hee=we({tldrawFileFormatVersion:BR,schema:we({schemaVersion:Ku,storeVersion:Ku,recordVersions:Cy(ge,we({version:Ku,subTypeVersions:Cy(ge,Ku).optional(),subTypeKey:ge.optional()}))}),records:Ot(we({id:ge,typeName:ge}).allowUnknownProperties())});function Vee(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function Kee({json:e,schema:n}){let t;try{t=Hee.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),Vee(t))return Ys.err({type:"v1File",data:t})}catch{}return Ys.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>Uee)return Ys.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=Object.fromEntries(t.records.map(s=>[s.id,s]));r=n.migrateStoreSnapshot({store:o,schema:t.schema})}catch(o){return Ys.err({type:"invalidRecords",cause:o})}if(r.type==="error")return Ys.err({type:"migrationFailed",reason:r.reason});try{return Ys.ok(Ak({initialData:r.value,schema:n}))}catch(o){return Ys.err({type:"invalidRecords",cause:o})}}function Wee(){const[e,n]=w.useState();function t(r){e===void 0?fetch("/tldr-data").then(async o=>{if(!o.ok){console.log(`No tldr data to load from local endpoint (${o.status})`);return}return o.text()}).then(o=>{if(o===void 0)return;const s=Kee({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),n(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.updateViewportScreenBounds(),r.zoomToFit(),window.app.clearOpenMenus())}return g.jsx("div",{style:{inset:0,position:"fixed"},children:g.jsx(Fee,{assetUrls:eR(),onMount:t,store:e})})}var fv={},YC=ll;fv.createRoot=YC.createRoot,fv.hydrateRoot=YC.hydrateRoot;fv.createRoot(document.querySelector("#root")).render(g.jsx(ne.StrictMode,{children:g.jsx(Wee,{})}));