@kitschpatrol/tldraw-cli 1.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.
- package/bin/cli.js +105 -0
- package/dist/assets/index-38ua_y9K.js +315 -0
- package/dist/assets/index-Go1mR3Ch.css +1 -0
- package/dist/embed-icons/codepen.png +0 -0
- package/dist/embed-icons/codesandbox.png +0 -0
- package/dist/embed-icons/excalidraw.png +0 -0
- package/dist/embed-icons/felt.png +0 -0
- package/dist/embed-icons/figma.png +0 -0
- package/dist/embed-icons/github_gist.png +0 -0
- package/dist/embed-icons/google_calendar.png +0 -0
- package/dist/embed-icons/google_maps.png +0 -0
- package/dist/embed-icons/google_slides.png +0 -0
- package/dist/embed-icons/observable.png +0 -0
- package/dist/embed-icons/replit.png +0 -0
- package/dist/embed-icons/scratch.png +0 -0
- package/dist/embed-icons/spotify.png +0 -0
- package/dist/embed-icons/tldraw.png +0 -0
- package/dist/embed-icons/val_town.png +0 -0
- package/dist/embed-icons/vimeo.png +0 -0
- package/dist/embed-icons/youtube.png +0 -0
- package/dist/fonts/IBMPlexMono-Medium.woff2 +0 -0
- package/dist/fonts/IBMPlexSans-Medium.woff2 +0 -0
- package/dist/fonts/IBMPlexSerif-Medium.woff2 +0 -0
- package/dist/fonts/Shantell_Sans-Tldrawish.woff2 +0 -0
- package/dist/icons/icon/align-bottom-center.svg +1 -0
- package/dist/icons/icon/align-bottom-left.svg +1 -0
- package/dist/icons/icon/align-bottom-right.svg +1 -0
- package/dist/icons/icon/align-bottom.svg +1 -0
- package/dist/icons/icon/align-center-center.svg +1 -0
- package/dist/icons/icon/align-center-horizontal.svg +1 -0
- package/dist/icons/icon/align-center-left.svg +1 -0
- package/dist/icons/icon/align-center-right.svg +1 -0
- package/dist/icons/icon/align-center-vertical.svg +1 -0
- package/dist/icons/icon/align-left.svg +1 -0
- package/dist/icons/icon/align-right.svg +1 -0
- package/dist/icons/icon/align-top-center.svg +1 -0
- package/dist/icons/icon/align-top-left.svg +1 -0
- package/dist/icons/icon/align-top-right.svg +1 -0
- package/dist/icons/icon/align-top.svg +1 -0
- package/dist/icons/icon/arrow-left.svg +1 -0
- package/dist/icons/icon/arrowhead-arrow.svg +1 -0
- package/dist/icons/icon/arrowhead-bar.svg +1 -0
- package/dist/icons/icon/arrowhead-diamond.svg +1 -0
- package/dist/icons/icon/arrowhead-dot.svg +1 -0
- package/dist/icons/icon/arrowhead-none.svg +1 -0
- package/dist/icons/icon/arrowhead-square.svg +1 -0
- package/dist/icons/icon/arrowhead-triangle-inverted.svg +1 -0
- package/dist/icons/icon/arrowhead-triangle.svg +1 -0
- package/dist/icons/icon/aspect-ratio.svg +1 -0
- package/dist/icons/icon/avatar.svg +1 -0
- package/dist/icons/icon/blob.svg +1 -0
- package/dist/icons/icon/bring-forward.svg +1 -0
- package/dist/icons/icon/bring-to-front.svg +1 -0
- package/dist/icons/icon/check.svg +1 -0
- package/dist/icons/icon/checkbox-checked.svg +1 -0
- package/dist/icons/icon/checkbox-empty.svg +1 -0
- package/dist/icons/icon/chevron-down.svg +1 -0
- package/dist/icons/icon/chevron-left.svg +1 -0
- package/dist/icons/icon/chevron-right.svg +1 -0
- package/dist/icons/icon/chevron-up.svg +1 -0
- package/dist/icons/icon/chevrons-ne.svg +1 -0
- package/dist/icons/icon/chevrons-sw.svg +1 -0
- package/dist/icons/icon/clipboard-copied.svg +1 -0
- package/dist/icons/icon/clipboard-copy.svg +1 -0
- package/dist/icons/icon/code.svg +1 -0
- package/dist/icons/icon/collab.svg +1 -0
- package/dist/icons/icon/color.svg +1 -0
- package/dist/icons/icon/comment.svg +1 -0
- package/dist/icons/icon/cross-2.svg +1 -0
- package/dist/icons/icon/cross.svg +1 -0
- package/dist/icons/icon/dash-dashed.svg +1 -0
- package/dist/icons/icon/dash-dotted.svg +1 -0
- package/dist/icons/icon/dash-draw.svg +1 -0
- package/dist/icons/icon/dash-solid.svg +1 -0
- package/dist/icons/icon/discord.svg +1 -0
- package/dist/icons/icon/distribute-horizontal.svg +1 -0
- package/dist/icons/icon/distribute-vertical.svg +1 -0
- package/dist/icons/icon/dot.svg +1 -0
- package/dist/icons/icon/dots-horizontal.svg +1 -0
- package/dist/icons/icon/dots-vertical.svg +1 -0
- package/dist/icons/icon/drag-handle-dots.svg +1 -0
- package/dist/icons/icon/duplicate.svg +1 -0
- package/dist/icons/icon/edit.svg +1 -0
- package/dist/icons/icon/external-link.svg +1 -0
- package/dist/icons/icon/file.svg +1 -0
- package/dist/icons/icon/fill-none.svg +1 -0
- package/dist/icons/icon/fill-pattern.svg +1 -0
- package/dist/icons/icon/fill-semi.svg +1 -0
- package/dist/icons/icon/fill-solid.svg +1 -0
- package/dist/icons/icon/follow.svg +1 -0
- package/dist/icons/icon/following.svg +1 -0
- package/dist/icons/icon/font-draw.svg +1 -0
- package/dist/icons/icon/font-mono.svg +1 -0
- package/dist/icons/icon/font-sans.svg +1 -0
- package/dist/icons/icon/font-serif.svg +1 -0
- package/dist/icons/icon/geo-arrow-down.svg +1 -0
- package/dist/icons/icon/geo-arrow-left.svg +1 -0
- package/dist/icons/icon/geo-arrow-right.svg +1 -0
- package/dist/icons/icon/geo-arrow-up.svg +1 -0
- package/dist/icons/icon/geo-check-box.svg +1 -0
- package/dist/icons/icon/geo-cloud.svg +1 -0
- package/dist/icons/icon/geo-diamond.svg +1 -0
- package/dist/icons/icon/geo-ellipse.svg +1 -0
- package/dist/icons/icon/geo-hexagon.svg +1 -0
- package/dist/icons/icon/geo-octagon.svg +1 -0
- package/dist/icons/icon/geo-oval.svg +1 -0
- package/dist/icons/icon/geo-pentagon.svg +1 -0
- package/dist/icons/icon/geo-rectangle.svg +1 -0
- package/dist/icons/icon/geo-rhombus-2.svg +1 -0
- package/dist/icons/icon/geo-rhombus.svg +1 -0
- package/dist/icons/icon/geo-star.svg +1 -0
- package/dist/icons/icon/geo-trapezoid.svg +1 -0
- package/dist/icons/icon/geo-triangle.svg +1 -0
- package/dist/icons/icon/geo-x-box.svg +1 -0
- package/dist/icons/icon/github.svg +1 -0
- package/dist/icons/icon/group.svg +1 -0
- package/dist/icons/icon/hidden.svg +1 -0
- package/dist/icons/icon/icon-names.json +166 -0
- package/dist/icons/icon/image.svg +1 -0
- package/dist/icons/icon/info-circle.svg +1 -0
- package/dist/icons/icon/leading.svg +1 -0
- package/dist/icons/icon/link.svg +1 -0
- package/dist/icons/icon/lock-small.svg +1 -0
- package/dist/icons/icon/lock.svg +1 -0
- package/dist/icons/icon/menu.svg +1 -0
- package/dist/icons/icon/minus.svg +1 -0
- package/dist/icons/icon/mixed.svg +1 -0
- package/dist/icons/icon/pack.svg +1 -0
- package/dist/icons/icon/page.svg +1 -0
- package/dist/icons/icon/plus.svg +1 -0
- package/dist/icons/icon/question-mark-circle.svg +1 -0
- package/dist/icons/icon/question-mark.svg +1 -0
- package/dist/icons/icon/redo.svg +1 -0
- package/dist/icons/icon/reset-zoom.svg +1 -0
- package/dist/icons/icon/rotate-ccw.svg +1 -0
- package/dist/icons/icon/rotate-cw.svg +1 -0
- package/dist/icons/icon/ruler.svg +1 -0
- package/dist/icons/icon/search.svg +1 -0
- package/dist/icons/icon/send-backward.svg +1 -0
- package/dist/icons/icon/send-to-back.svg +1 -0
- package/dist/icons/icon/settings-horizontal.svg +1 -0
- package/dist/icons/icon/settings-vertical-1.svg +1 -0
- package/dist/icons/icon/settings-vertical.svg +1 -0
- package/dist/icons/icon/share-1.svg +1 -0
- package/dist/icons/icon/share-2.svg +1 -0
- package/dist/icons/icon/size-extra-large.svg +1 -0
- package/dist/icons/icon/size-large.svg +1 -0
- package/dist/icons/icon/size-medium.svg +1 -0
- package/dist/icons/icon/size-small.svg +1 -0
- package/dist/icons/icon/spline-cubic.svg +1 -0
- package/dist/icons/icon/spline-line.svg +1 -0
- package/dist/icons/icon/stack-horizontal.svg +1 -0
- package/dist/icons/icon/stack-vertical.svg +1 -0
- package/dist/icons/icon/status-offline.svg +1 -0
- package/dist/icons/icon/status-online.svg +1 -0
- package/dist/icons/icon/stretch-horizontal.svg +1 -0
- package/dist/icons/icon/stretch-vertical.svg +1 -0
- package/dist/icons/icon/text-align-center.svg +1 -0
- package/dist/icons/icon/text-align-justify.svg +1 -0
- package/dist/icons/icon/text-align-left.svg +1 -0
- package/dist/icons/icon/text-align-right.svg +1 -0
- package/dist/icons/icon/tool-arrow.svg +1 -0
- package/dist/icons/icon/tool-embed.svg +1 -0
- package/dist/icons/icon/tool-eraser.svg +1 -0
- package/dist/icons/icon/tool-frame.svg +1 -0
- package/dist/icons/icon/tool-hand.svg +1 -0
- package/dist/icons/icon/tool-highlight.svg +1 -0
- package/dist/icons/icon/tool-laser.svg +1 -0
- package/dist/icons/icon/tool-line.svg +1 -0
- package/dist/icons/icon/tool-media.svg +1 -0
- package/dist/icons/icon/tool-note.svg +1 -0
- package/dist/icons/icon/tool-pencil.svg +1 -0
- package/dist/icons/icon/tool-pointer.svg +1 -0
- package/dist/icons/icon/tool-text.svg +1 -0
- package/dist/icons/icon/trash.svg +1 -0
- package/dist/icons/icon/triangle-down.svg +1 -0
- package/dist/icons/icon/triangle-up.svg +1 -0
- package/dist/icons/icon/twitter.svg +1 -0
- package/dist/icons/icon/undo.svg +1 -0
- package/dist/icons/icon/ungroup.svg +1 -0
- package/dist/icons/icon/unlock-small.svg +1 -0
- package/dist/icons/icon/unlock.svg +1 -0
- package/dist/icons/icon/vertical-align-center.svg +1 -0
- package/dist/icons/icon/vertical-align-end.svg +1 -0
- package/dist/icons/icon/vertical-align-start.svg +1 -0
- package/dist/icons/icon/visible.svg +1 -0
- package/dist/icons/icon/warning-triangle.svg +1 -0
- package/dist/icons/icon/zoom-in.svg +1 -0
- package/dist/icons/icon/zoom-out.svg +1 -0
- package/dist/index.html +13 -0
- package/dist/translations/ar.json +295 -0
- package/dist/translations/ca.json +295 -0
- package/dist/translations/cs.json +352 -0
- package/dist/translations/da.json +160 -0
- package/dist/translations/de.json +310 -0
- package/dist/translations/en.json +1 -0
- package/dist/translations/es.json +299 -0
- package/dist/translations/fa.json +343 -0
- package/dist/translations/fi.json +312 -0
- package/dist/translations/fr.json +295 -0
- package/dist/translations/gl.json +349 -0
- package/dist/translations/he.json +86 -0
- package/dist/translations/hi-in.json +290 -0
- package/dist/translations/hu.json +5 -0
- package/dist/translations/it.json +330 -0
- package/dist/translations/ja.json +351 -0
- package/dist/translations/ko-kr.json +355 -0
- package/dist/translations/ku.json +93 -0
- package/dist/translations/languages.json +138 -0
- package/dist/translations/main.json +355 -0
- package/dist/translations/my.json +112 -0
- package/dist/translations/ne.json +295 -0
- package/dist/translations/no.json +62 -0
- package/dist/translations/pl.json +113 -0
- package/dist/translations/pt-br.json +333 -0
- package/dist/translations/pt-pt.json +86 -0
- package/dist/translations/ro.json +351 -0
- package/dist/translations/ru.json +347 -0
- package/dist/translations/sv.json +96 -0
- package/dist/translations/te.json +112 -0
- package/dist/translations/th.json +295 -0
- package/dist/translations/tr.json +294 -0
- package/dist/translations/uk.json +347 -0
- package/dist/translations/vi.json +295 -0
- package/dist/translations/zh-cn.json +353 -0
- package/dist/translations/zh-tw.json +316 -0
- package/license.txt +21 -0
- package/package.json +83 -0
- package/readme.md +105 -0
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
var hA=Object.defineProperty;var pA=(e,n,t)=>n in e?hA(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var v=(e,n,t)=>(pA(e,typeof n!="symbol"?n+"":n,t),t);function fA(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 Ot=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Si(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var NC={exports:{}},Wp={},zC={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 tu=Symbol.for("react.element"),gA=Symbol.for("react.portal"),mA=Symbol.for("react.fragment"),yA=Symbol.for("react.strict_mode"),vA=Symbol.for("react.profiler"),SA=Symbol.for("react.provider"),wA=Symbol.for("react.context"),xA=Symbol.for("react.forward_ref"),bA=Symbol.for("react.suspense"),CA=Symbol.for("react.memo"),PA=Symbol.for("react.lazy"),s1=Symbol.iterator;function EA(e){return e===null||typeof e!="object"?null:(e=s1&&e[s1]||e["@@iterator"],typeof e=="function"?e:null)}var FC={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},BC=Object.assign,UC={};function Va(e,n,t){this.props=e,this.context=n,this.refs=UC,this.updater=t||FC}Va.prototype.isReactComponent={};Va.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")};Va.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function HC(){}HC.prototype=Va.prototype;function lv(e,n,t){this.props=e,this.context=n,this.refs=UC,this.updater=t||FC}var cv=lv.prototype=new HC;cv.constructor=lv;BC(cv,Va.prototype);cv.isPureReactComponent=!0;var i1=Array.isArray,VC=Object.prototype.hasOwnProperty,uv={current:null},KC={key:!0,ref:!0,__self:!0,__source:!0};function WC(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)VC.call(n,r)&&!KC.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:tu,type:e,key:s,ref:i,props:o,_owner:uv.current}}function kA(e,n){return{$$typeof:tu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function dv(e){return typeof e=="object"&&e!==null&&e.$$typeof===tu}function IA(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var a1=/\/+/g;function og(e,n){return typeof e=="object"&&e!==null&&e.key!=null?IA(""+e.key):n.toString(36)}function Fd(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 tu:case gA:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+og(i,0):r,i1(o)?(t="",e!=null&&(t=e.replace(a1,"$&/")+"/"),Fd(o,n,t,"",function(c){return c})):o!=null&&(dv(o)&&(o=kA(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(a1,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",i1(e))for(var a=0;a<e.length;a++){s=e[a];var l=r+og(s,a);i+=Fd(s,n,t,l,o)}else if(l=EA(e),typeof l=="function")for(e=l.call(e),a=0;!(s=e.next()).done;)s=s.value,l=r+og(s,a++),i+=Fd(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 zu(e,n,t){if(e==null)return e;var r=[],o=0;return Fd(e,r,"","",function(s){return n.call(t,s,o++)}),r}function _A(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 un={current:null},Bd={transition:null},TA={ReactCurrentDispatcher:un,ReactCurrentBatchConfig:Bd,ReactCurrentOwner:uv};xe.Children={map:zu,forEach:function(e,n,t){zu(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return zu(e,function(){n++}),n},toArray:function(e){return zu(e,function(n){return n})||[]},only:function(e){if(!dv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};xe.Component=Va;xe.Fragment=mA;xe.Profiler=vA;xe.PureComponent=lv;xe.StrictMode=yA;xe.Suspense=bA;xe.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=TA;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=BC({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=uv.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in n)VC.call(n,l)&&!KC.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:tu,type:e.type,key:o,ref:s,props:r,_owner:i}};xe.createContext=function(e){return e={$$typeof:wA,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:SA,_context:e},e.Consumer=e};xe.createElement=WC;xe.createFactory=function(e){var n=WC.bind(null,e);return n.type=e,n};xe.createRef=function(){return{current:null}};xe.forwardRef=function(e){return{$$typeof:xA,render:e}};xe.isValidElement=dv;xe.lazy=function(e){return{$$typeof:PA,_payload:{_status:-1,_result:e},_init:_A}};xe.memo=function(e,n){return{$$typeof:CA,type:e,compare:n===void 0?null:n}};xe.startTransition=function(e){var n=Bd.transition;Bd.transition={};try{e()}finally{Bd.transition=n}};xe.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.")};xe.useCallback=function(e,n){return un.current.useCallback(e,n)};xe.useContext=function(e){return un.current.useContext(e)};xe.useDebugValue=function(){};xe.useDeferredValue=function(e){return un.current.useDeferredValue(e)};xe.useEffect=function(e,n){return un.current.useEffect(e,n)};xe.useId=function(){return un.current.useId()};xe.useImperativeHandle=function(e,n,t){return un.current.useImperativeHandle(e,n,t)};xe.useInsertionEffect=function(e,n){return un.current.useInsertionEffect(e,n)};xe.useLayoutEffect=function(e,n){return un.current.useLayoutEffect(e,n)};xe.useMemo=function(e,n){return un.current.useMemo(e,n)};xe.useReducer=function(e,n,t){return un.current.useReducer(e,n,t)};xe.useRef=function(e){return un.current.useRef(e)};xe.useState=function(e){return un.current.useState(e)};xe.useSyncExternalStore=function(e,n,t){return un.current.useSyncExternalStore(e,n,t)};xe.useTransition=function(){return un.current.useTransition()};xe.version="18.2.0";zC.exports=xe;var b=zC.exports;const ne=Si(b),$A=fA({__proto__:null,default:ne},[b]);/**
|
|
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 MA=b,AA=Symbol.for("react.element"),OA=Symbol.for("react.fragment"),RA=Object.prototype.hasOwnProperty,DA=MA.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,jA={key:!0,ref:!0,__self:!0,__source:!0};function GC(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)RA.call(n,r)&&!jA.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:AA,type:e,key:s,ref:i,props:o,_owner:DA.current}}Wp.Fragment=OA;Wp.jsx=GC;Wp.jsxs=GC;NC.exports=Wp;var g=NC.exports;function A(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 LA(e){return{fonts:{monospace:A("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:A("./fonts/IBMPlexSans-Medium.woff2",e),serif:A("./fonts/IBMPlexSerif-Medium.woff2",e),draw:A("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom-center":A("./icons/icon/align-bottom-center.svg",e),"align-bottom-left":A("./icons/icon/align-bottom-left.svg",e),"align-bottom-right":A("./icons/icon/align-bottom-right.svg",e),"align-bottom":A("./icons/icon/align-bottom.svg",e),"align-center-center":A("./icons/icon/align-center-center.svg",e),"align-center-horizontal":A("./icons/icon/align-center-horizontal.svg",e),"align-center-left":A("./icons/icon/align-center-left.svg",e),"align-center-right":A("./icons/icon/align-center-right.svg",e),"align-center-vertical":A("./icons/icon/align-center-vertical.svg",e),"align-left":A("./icons/icon/align-left.svg",e),"align-right":A("./icons/icon/align-right.svg",e),"align-top-center":A("./icons/icon/align-top-center.svg",e),"align-top-left":A("./icons/icon/align-top-left.svg",e),"align-top-right":A("./icons/icon/align-top-right.svg",e),"align-top":A("./icons/icon/align-top.svg",e),"arrow-left":A("./icons/icon/arrow-left.svg",e),"arrowhead-arrow":A("./icons/icon/arrowhead-arrow.svg",e),"arrowhead-bar":A("./icons/icon/arrowhead-bar.svg",e),"arrowhead-diamond":A("./icons/icon/arrowhead-diamond.svg",e),"arrowhead-dot":A("./icons/icon/arrowhead-dot.svg",e),"arrowhead-none":A("./icons/icon/arrowhead-none.svg",e),"arrowhead-square":A("./icons/icon/arrowhead-square.svg",e),"arrowhead-triangle-inverted":A("./icons/icon/arrowhead-triangle-inverted.svg",e),"arrowhead-triangle":A("./icons/icon/arrowhead-triangle.svg",e),"aspect-ratio":A("./icons/icon/aspect-ratio.svg",e),avatar:A("./icons/icon/avatar.svg",e),blob:A("./icons/icon/blob.svg",e),"bring-forward":A("./icons/icon/bring-forward.svg",e),"bring-to-front":A("./icons/icon/bring-to-front.svg",e),check:A("./icons/icon/check.svg",e),"checkbox-checked":A("./icons/icon/checkbox-checked.svg",e),"checkbox-empty":A("./icons/icon/checkbox-empty.svg",e),"chevron-down":A("./icons/icon/chevron-down.svg",e),"chevron-left":A("./icons/icon/chevron-left.svg",e),"chevron-right":A("./icons/icon/chevron-right.svg",e),"chevron-up":A("./icons/icon/chevron-up.svg",e),"chevrons-ne":A("./icons/icon/chevrons-ne.svg",e),"chevrons-sw":A("./icons/icon/chevrons-sw.svg",e),"clipboard-copied":A("./icons/icon/clipboard-copied.svg",e),"clipboard-copy":A("./icons/icon/clipboard-copy.svg",e),code:A("./icons/icon/code.svg",e),collab:A("./icons/icon/collab.svg",e),color:A("./icons/icon/color.svg",e),comment:A("./icons/icon/comment.svg",e),"cross-2":A("./icons/icon/cross-2.svg",e),cross:A("./icons/icon/cross.svg",e),"dash-dashed":A("./icons/icon/dash-dashed.svg",e),"dash-dotted":A("./icons/icon/dash-dotted.svg",e),"dash-draw":A("./icons/icon/dash-draw.svg",e),"dash-solid":A("./icons/icon/dash-solid.svg",e),discord:A("./icons/icon/discord.svg",e),"distribute-horizontal":A("./icons/icon/distribute-horizontal.svg",e),"distribute-vertical":A("./icons/icon/distribute-vertical.svg",e),dot:A("./icons/icon/dot.svg",e),"dots-horizontal":A("./icons/icon/dots-horizontal.svg",e),"dots-vertical":A("./icons/icon/dots-vertical.svg",e),"drag-handle-dots":A("./icons/icon/drag-handle-dots.svg",e),duplicate:A("./icons/icon/duplicate.svg",e),edit:A("./icons/icon/edit.svg",e),"external-link":A("./icons/icon/external-link.svg",e),file:A("./icons/icon/file.svg",e),"fill-none":A("./icons/icon/fill-none.svg",e),"fill-pattern":A("./icons/icon/fill-pattern.svg",e),"fill-semi":A("./icons/icon/fill-semi.svg",e),"fill-solid":A("./icons/icon/fill-solid.svg",e),follow:A("./icons/icon/follow.svg",e),following:A("./icons/icon/following.svg",e),"font-draw":A("./icons/icon/font-draw.svg",e),"font-mono":A("./icons/icon/font-mono.svg",e),"font-sans":A("./icons/icon/font-sans.svg",e),"font-serif":A("./icons/icon/font-serif.svg",e),"geo-arrow-down":A("./icons/icon/geo-arrow-down.svg",e),"geo-arrow-left":A("./icons/icon/geo-arrow-left.svg",e),"geo-arrow-right":A("./icons/icon/geo-arrow-right.svg",e),"geo-arrow-up":A("./icons/icon/geo-arrow-up.svg",e),"geo-check-box":A("./icons/icon/geo-check-box.svg",e),"geo-cloud":A("./icons/icon/geo-cloud.svg",e),"geo-diamond":A("./icons/icon/geo-diamond.svg",e),"geo-ellipse":A("./icons/icon/geo-ellipse.svg",e),"geo-hexagon":A("./icons/icon/geo-hexagon.svg",e),"geo-octagon":A("./icons/icon/geo-octagon.svg",e),"geo-oval":A("./icons/icon/geo-oval.svg",e),"geo-pentagon":A("./icons/icon/geo-pentagon.svg",e),"geo-rectangle":A("./icons/icon/geo-rectangle.svg",e),"geo-rhombus-2":A("./icons/icon/geo-rhombus-2.svg",e),"geo-rhombus":A("./icons/icon/geo-rhombus.svg",e),"geo-star":A("./icons/icon/geo-star.svg",e),"geo-trapezoid":A("./icons/icon/geo-trapezoid.svg",e),"geo-triangle":A("./icons/icon/geo-triangle.svg",e),"geo-x-box":A("./icons/icon/geo-x-box.svg",e),github:A("./icons/icon/github.svg",e),group:A("./icons/icon/group.svg",e),hidden:A("./icons/icon/hidden.svg",e),image:A("./icons/icon/image.svg",e),"info-circle":A("./icons/icon/info-circle.svg",e),leading:A("./icons/icon/leading.svg",e),link:A("./icons/icon/link.svg",e),"lock-small":A("./icons/icon/lock-small.svg",e),lock:A("./icons/icon/lock.svg",e),menu:A("./icons/icon/menu.svg",e),minus:A("./icons/icon/minus.svg",e),mixed:A("./icons/icon/mixed.svg",e),pack:A("./icons/icon/pack.svg",e),page:A("./icons/icon/page.svg",e),plus:A("./icons/icon/plus.svg",e),"question-mark-circle":A("./icons/icon/question-mark-circle.svg",e),"question-mark":A("./icons/icon/question-mark.svg",e),redo:A("./icons/icon/redo.svg",e),"reset-zoom":A("./icons/icon/reset-zoom.svg",e),"rotate-ccw":A("./icons/icon/rotate-ccw.svg",e),"rotate-cw":A("./icons/icon/rotate-cw.svg",e),ruler:A("./icons/icon/ruler.svg",e),search:A("./icons/icon/search.svg",e),"send-backward":A("./icons/icon/send-backward.svg",e),"send-to-back":A("./icons/icon/send-to-back.svg",e),"settings-horizontal":A("./icons/icon/settings-horizontal.svg",e),"settings-vertical-1":A("./icons/icon/settings-vertical-1.svg",e),"settings-vertical":A("./icons/icon/settings-vertical.svg",e),"share-1":A("./icons/icon/share-1.svg",e),"share-2":A("./icons/icon/share-2.svg",e),"size-extra-large":A("./icons/icon/size-extra-large.svg",e),"size-large":A("./icons/icon/size-large.svg",e),"size-medium":A("./icons/icon/size-medium.svg",e),"size-small":A("./icons/icon/size-small.svg",e),"spline-cubic":A("./icons/icon/spline-cubic.svg",e),"spline-line":A("./icons/icon/spline-line.svg",e),"stack-horizontal":A("./icons/icon/stack-horizontal.svg",e),"stack-vertical":A("./icons/icon/stack-vertical.svg",e),"status-offline":A("./icons/icon/status-offline.svg",e),"status-online":A("./icons/icon/status-online.svg",e),"stretch-horizontal":A("./icons/icon/stretch-horizontal.svg",e),"stretch-vertical":A("./icons/icon/stretch-vertical.svg",e),"text-align-center":A("./icons/icon/text-align-center.svg",e),"text-align-justify":A("./icons/icon/text-align-justify.svg",e),"text-align-left":A("./icons/icon/text-align-left.svg",e),"text-align-right":A("./icons/icon/text-align-right.svg",e),"tool-arrow":A("./icons/icon/tool-arrow.svg",e),"tool-embed":A("./icons/icon/tool-embed.svg",e),"tool-eraser":A("./icons/icon/tool-eraser.svg",e),"tool-frame":A("./icons/icon/tool-frame.svg",e),"tool-hand":A("./icons/icon/tool-hand.svg",e),"tool-highlight":A("./icons/icon/tool-highlight.svg",e),"tool-laser":A("./icons/icon/tool-laser.svg",e),"tool-line":A("./icons/icon/tool-line.svg",e),"tool-media":A("./icons/icon/tool-media.svg",e),"tool-note":A("./icons/icon/tool-note.svg",e),"tool-pencil":A("./icons/icon/tool-pencil.svg",e),"tool-pointer":A("./icons/icon/tool-pointer.svg",e),"tool-text":A("./icons/icon/tool-text.svg",e),trash:A("./icons/icon/trash.svg",e),"triangle-down":A("./icons/icon/triangle-down.svg",e),"triangle-up":A("./icons/icon/triangle-up.svg",e),twitter:A("./icons/icon/twitter.svg",e),undo:A("./icons/icon/undo.svg",e),ungroup:A("./icons/icon/ungroup.svg",e),"unlock-small":A("./icons/icon/unlock-small.svg",e),unlock:A("./icons/icon/unlock.svg",e),"vertical-align-center":A("./icons/icon/vertical-align-center.svg",e),"vertical-align-end":A("./icons/icon/vertical-align-end.svg",e),"vertical-align-start":A("./icons/icon/vertical-align-start.svg",e),visible:A("./icons/icon/visible.svg",e),"warning-triangle":A("./icons/icon/warning-triangle.svg",e),"zoom-in":A("./icons/icon/zoom-in.svg",e),"zoom-out":A("./icons/icon/zoom-out.svg",e)},translations:{ar:A("./translations/ar.json",e),ca:A("./translations/ca.json",e),cs:A("./translations/cs.json",e),da:A("./translations/da.json",e),de:A("./translations/de.json",e),en:A("./translations/en.json",e),es:A("./translations/es.json",e),fa:A("./translations/fa.json",e),fi:A("./translations/fi.json",e),fr:A("./translations/fr.json",e),gl:A("./translations/gl.json",e),he:A("./translations/he.json",e),"hi-in":A("./translations/hi-in.json",e),hu:A("./translations/hu.json",e),it:A("./translations/it.json",e),ja:A("./translations/ja.json",e),"ko-kr":A("./translations/ko-kr.json",e),ku:A("./translations/ku.json",e),languages:A("./translations/languages.json",e),main:A("./translations/main.json",e),my:A("./translations/my.json",e),ne:A("./translations/ne.json",e),no:A("./translations/no.json",e),pl:A("./translations/pl.json",e),"pt-br":A("./translations/pt-br.json",e),"pt-pt":A("./translations/pt-pt.json",e),ro:A("./translations/ro.json",e),ru:A("./translations/ru.json",e),sv:A("./translations/sv.json",e),te:A("./translations/te.json",e),th:A("./translations/th.json",e),tr:A("./translations/tr.json",e),uk:A("./translations/uk.json",e),vi:A("./translations/vi.json",e),"zh-cn":A("./translations/zh-cn.json",e),"zh-tw":A("./translations/zh-tw.json",e)},embedIcons:{codepen:A("./embed-icons/codepen.png",e),codesandbox:A("./embed-icons/codesandbox.png",e),excalidraw:A("./embed-icons/excalidraw.png",e),felt:A("./embed-icons/felt.png",e),figma:A("./embed-icons/figma.png",e),github_gist:A("./embed-icons/github_gist.png",e),google_calendar:A("./embed-icons/google_calendar.png",e),google_maps:A("./embed-icons/google_maps.png",e),google_slides:A("./embed-icons/google_slides.png",e),observable:A("./embed-icons/observable.png",e),replit:A("./embed-icons/replit.png",e),scratch:A("./embed-icons/scratch.png",e),spotify:A("./embed-icons/spotify.png",e),tldraw:A("./embed-icons/tldraw.png",e),val_town:A("./embed-icons/val_town.png",e),vimeo:A("./embed-icons/vimeo.png",e),youtube:A("./embed-icons/youtube.png",e)}}}function YC(e){return e&&typeof e=="object"&&"parents"in e}function XC(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 zh=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&YC(e))for(let t=0,r=e.parents.length;t<r;t++)zh(e.parents[t],e)},hv=(e,n)=>{if(e.children.add(n)&&YC(e))for(let t=0,r=e.parents.length;t<r;t++)hv(e.parents[t],e)};function qC(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function $s(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const Po=$s("empty_array",()=>Object.freeze([])),l1=8;class ZC{constructor(){v(this,"arraySize",0);v(this,"array",Array(l1));v(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<l1?(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 Bn=Symbol.for("com.tldraw.state/RESET_VALUE");class QC{constructor(n){v(this,"index",0);v(this,"buffer");this.capacity=n,this.buffer=new Array(n)}pushEntry(n,t,r){if(r!==void 0){if(r===Bn){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 Bn;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 Bn}}class NA{constructor(n,t){v(this,"offset",0);v(this,"numNewParents",0);v(this,"maybeRemoved");this.below=n,this.child=t}}const qe=$s("capture",()=>({stack:null}));function JC(e){qe.stack=new NA(qe.stack,e)}function eP(){var t;const e=qe.stack;if(qe.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&&zh(o,e.child)}if(e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset,(t=qe.stack)!=null&&t.maybeRemoved)for(let r=0;r<qe.stack.maybeRemoved.length;r++){const o=qe.stack.maybeRemoved[r];e.child.parents.indexOf(o)===-1&&zh(o,e.child)}}}function fy(e){if(qe.stack){const n=qe.stack.child.parents.indexOf(e);if(n<0&&(qe.stack.numNewParents++,qe.stack.child.isActivelyListening&&hv(e,qe.stack.child)),n<0||n>=qe.stack.offset){if(n!==qe.stack.offset&&n>0){const t=qe.stack.child.parents[qe.stack.offset];qe.stack.maybeRemoved?qe.stack.maybeRemoved.indexOf(t)===-1&&qe.stack.maybeRemoved.push(t):qe.stack.maybeRemoved=[t]}qe.stack.child.parents[qe.stack.offset]=e,qe.stack.child.parentEpochs[qe.stack.offset]=e.lastChangedEpoch,qe.stack.offset++}}}const qs=-1;class zA{constructor(n,t,r){v(this,"_isActivelyListening",!1);v(this,"lastTraversedEpoch",qs);v(this,"lastReactedEpoch",qs);v(this,"_scheduleCount",0);v(this,"parentEpochs",[]);v(this,"parents",[]);v(this,"_scheduleEffect");v(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!==Dn()){if(this.parents.length&&!XC(this)){this.lastReactedEpoch=Dn();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++)hv(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)zh(this.parents[n],this)}execute(){try{JC(this);const n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=Dn(),n}finally{eP()}}}const Ka=$s("EffectScheduler",()=>zA);function nu(e,n,t){const r=new Ka(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function FA(e,n,t){const r=new Ka(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 BA{constructor(n){v(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,tP(n.keys())}else this.initialAtomValues.forEach((n,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,n)})}abort(){Gt.globalEpoch++,this.initialAtomValues.forEach((n,t)=>{var r;t.set(n),(r=t.historyBuffer)==null||r.clear()}),this.commit()}}const Gt=$s("transactions",()=>({globalEpoch:qs+1,globalIsReacting:!1,currentTransaction:null}));function Dn(){return Gt.globalEpoch}function tP(e){if(Gt.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{Gt.globalIsReacting=!0;const n=new Set,t=r=>{r.lastTraversedEpoch!==Gt.globalEpoch&&(r.lastTraversedEpoch=Gt.globalEpoch,r instanceof Ka?n.add(r):r.children.visit(t))};for(const r of e)r.children.visit(t);for(const r of n)r.maybeScheduleEffect()}finally{Gt.globalIsReacting=!1}}function UA(e,n){Gt.currentTransaction?Gt.currentTransaction.initialAtomValues.has(e)||Gt.currentTransaction.initialAtomValues.set(e,n):tP([e])}function HA(){Gt.globalEpoch++}function VA(e){const n=new BA(Gt.currentTransaction);Gt.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{Gt.currentTransaction=Gt.currentTransaction.parent}}function nr(e){return Gt.currentTransaction?e():VA(e)}class KA{constructor(n,t,r){v(this,"isEqual");v(this,"computeDiff");v(this,"lastChangedEpoch",Dn());v(this,"children",new ZC);v(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new QC(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(){return this.current}get(){return fy(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??qC(this.current,n))return this.current;HA(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Dn(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,Dn()))??Bn),this.lastChangedEpoch=Dn();const r=this.current;return this.current=n,UA(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return fy(this),n>=this.lastChangedEpoch?Po:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Bn}}const WA=$s("Atom",()=>KA);function an(e,n,t){return new WA(e,n,t)}let c1=!1;function GA(){c1||(c1=!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 gy=Symbol.for("com.tldraw.state/UNINITIALIZED"),Sa=e=>e===gy,my=$s("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function Hl(e,n){return new my(e,n)}class YA{constructor(n,t,r){v(this,"lastChangedEpoch",qs);v(this,"lastTraversedEpoch",qs);v(this,"lastCheckedEpoch",qs);v(this,"parents",[]);v(this,"parentEpochs",[]);v(this,"children",new ZC);v(this,"historyBuffer");v(this,"state",gy);v(this,"computeDiff");v(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new QC(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??qC}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(){var t;const n=this.lastChangedEpoch===qs;if(!n&&(this.lastCheckedEpoch===Dn()||!XC(this)))return this.lastCheckedEpoch=Dn(),this.state;try{JC(this);const r=this.derive(this.state,this.lastCheckedEpoch),o=r instanceof my?r.value:r;if(this.state===gy||!this.isEqual(o,this.state)){if(this.historyBuffer&&!n){const s=r instanceof my?r.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Dn(),s??((t=this.computeDiff)==null?void 0:t.call(this,this.state,o,this.lastCheckedEpoch,Dn()))??Bn)}this.lastChangedEpoch=Dn(),this.state=o}return this.lastCheckedEpoch=Dn(),this.state}finally{eP()}}get(){const n=this.__unsafe__getWithoutCapture();return fy(this),n}getDiffSince(n){var t;return this.get(),n>=this.lastChangedEpoch?Po:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Bn}}const pv=$s("Computed",()=>YA);function XA(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 pv(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[ZA]=!0,r}function u1(e={},n,t,r){return r.get?(GA(),qA(e,n,t,r)):XA(e,n,t,r)}function qA(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 pv(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const ZA="@@__isComputedMethod__@@";function Z(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>u1(e,n,t,r)}else return typeof arguments[0]=="string"?new pv(arguments[0],arguments[1],arguments[2]):u1(void 0,arguments[0],arguments[1],arguments[2])}const nP=1,QA=$s("apiVersion",()=>nP);if(QA!==nP)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function Gp(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 Ka(`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 d1={apply(e,n,t){return Gp(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},JA=Symbol.for("react.memo"),e5=Symbol.for("react.forward_ref");function Re(e){let n=null;const t=e.$$typeof;return t===JA&&(e=e.type,n=e.compare),t===e5?b.memo(b.forwardRef(new Proxy(e.render,d1))):b.memo(new Proxy(e,d1),n)}function rP(){const e=arguments[0],n=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return b.useMemo(()=>Z(`useComputed(${e})`,n,t),r)}function ri(e,n,t=Po){b.useEffect(()=>{const r=new Ka(e,n);return r.attach(),r.execute(),()=>{r.detach()}},t)}function Y(){const e=arguments,n=e.length===3?e[2]:[e[0]],t=e.length===3?e[0]:`useValue(${e[0].name})`,r=b.useRef(!0);r.current=!0;const o=b.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}=b.useMemo(()=>({subscribe:a=>nu(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return b.useSyncExternalStore(s,i,i)}finally{r.current=!1}}class Ud{constructor(n){v(this,"nextValue");v(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 Fh(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 he(e){return e.filter(n=>n!=null)}function mn(e){return e[e.length-1]}function t5(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 n5(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 oP(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const Ks={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function Wa(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const oi=oP((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),r5=oP((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function sP(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 h1=new WeakMap;function fv(e,n){if(typeof e!="object"||e===null)return;let t=h1.get(e);t||(t={tags:{},extras:{}},h1.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}class o5{static async base64ToFile(n){return fetch(n).then(function(t){return t.arrayBuffer()})}static async fileToBase64(n){return await new Promise((t,r)=>{if(n){const o=new FileReader;o.readAsDataURL(n),o.onload=()=>t(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s)}})}}function Hd(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}let yy=[0,1996959894,3993919788,2567524794,124634137,1886057615,3915621685,2657392035,249268274,2044508324,3772115230,2547177864,162941995,2125561021,3887607047,2428444049,498536548,1789927666,4089016648,2227061214,450548861,1843258603,4107580753,2211677639,325883990,1684777152,4251122042,2321926636,335633487,1661365465,4195302755,2366115317,997073096,1281953886,3579855332,2724688242,1006888145,1258607687,3524101629,2768942443,901097722,1119000684,3686517206,2898065728,853044451,1172266101,3705015759,2882616665,651767980,1373503546,3369554304,3218104598,565507253,1454621731,3485111705,3099436303,671266974,1594198024,3322730930,2970347812,795835527,1483230225,3244367275,3060149565,1994146192,31158534,2563907772,4023717930,1907459465,112637215,2680153253,3904427059,2013776290,251722036,2517215374,3775830040,2137656763,141376813,2439277719,3865271297,1802195444,476864866,2238001368,4066508878,1812370925,453092731,2181625025,4111451223,1706088902,314042704,2344532202,4240017532,1658658271,366619977,2362670323,4224994405,1303535960,984961486,2747007092,3569037538,1256170817,1037604311,2765210733,3554079995,1131014506,879679996,2909243462,3663771856,1141124467,855842277,2852801631,3708648649,1342533948,654459306,3188396048,3373015174,1466479909,544179635,3110523913,3462522015,1591671054,702138776,2966460450,3352799412,1504918807,783551873,3082640443,3233442989,3988292384,2596254646,62317068,1957810842,3939845945,2647816111,81470997,1943803523,3814918930,2489596804,225274430,2053790376,3826175755,2466906013,167816743,2097651377,4027552580,2265490386,503444072,1762050814,4150417245,2154129355,426522225,1852507879,4275313526,2312317920,282753626,1742555852,4189708143,2394877945,397917763,1622183637,3604390888,2714866558,953729732,1340076626,3518719985,2797360999,1068828381,1219638859,3624741850,2936675148,906185462,1090812512,3747672003,2825379669,829329135,1181335161,3412177804,3160834842,628085408,1382605366,3423369109,3138078467,570562233,1426400815,3317316542,2998733608,733239954,1555261956,3268935591,3050360625,752459403,1541320221,2607071920,3965973030,1969922972,40735498,2617837225,3943577151,1913087877,83908371,2512341634,3803740692,2075208622,213261112,2463272603,3855990285,2094854071,198958881,2262029012,4057260610,1759359992,534414190,2176718541,4139329115,1873836001,414664567,2282248934,4279200368,1711684554,285281116,2405801727,4167216745,1634467795,376229701,2685067896,3608007406,1308918612,956543938,2808555105,3495958263,1231636301,1047427035,2932959818,3654703836,1088359270,936918e3,2847714899,3736837829,1202900863,817233897,3183342108,3401237130,1404277552,615818150,3134207493,3453421203,1423857449,601450431,3009837614,3294710456,1567103746,711928724,3020668471,3272380065,1510334235,755167117];typeof Int32Array<"u"&&(yy=new Int32Array(yy));const s5=(e,n)=>{let t=n===0?0:~~n^-1;for(let r=0;r<e.length;r++)t=yy[(t^e[r])&255]^t>>>8;return t^-1},p1=4,f1=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+p1+f1;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+p1+f1}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,s5(d));const h=n.buffer.slice(0,o),p=n.buffer.slice(o+s);return new Blob([h,l,p],r)}}class g1{static async getVideoSizeFromSrc(n){return await new Promise((t,r)=>{const o=document.createElement("video");o.onloadeddata=()=>t({w:o.videoWidth,h:o.videoHeight}),o.onerror=s=>{console.error(s),r(new Error("Could not get video size"))},o.crossOrigin="anonymous",o.src=n})}static async getImageSizeFromSrc(n){return await new Promise((t,r)=>{const o=new Image;o.onload=async()=>{try{const s=await o5.base64ToFile(n),i=new DataView(s);if(Kr.isPng(i,0)){const a=Kr.findChunk(i,"pHYs");if(a){const l=Kr.parsePhys(i,a.dataOffset);if(l.unit===0&&l.ppux===l.ppuy){const c=Math.max(l.ppux/2834.5,1);t({w:Math.round(o.width/c),h:Math.round(o.height/c)});return}}}t({w:o.width,h:o.height})}catch(s){console.error(s),t({w:o.width,h:o.height})}},o.onerror=s=>{console.error(s),r(new Error("Could not get image size"))},o.crossOrigin="anonymous",o.src=n})}}function us(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 Bh(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 Yp(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function si(e,n){if(Yp(e,n))return e[n]}function qt(e){if(!e)return e;if(Array.isArray(e)){const n=[],t=e.length;for(let r=0;r<t;r++)n.push(qt(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]=qt(e[s])}return r}return e}function m1(e){return Object.keys(e)}function dt(e){return Object.values(e)}function Eo(e){return Object.entries(e)}function iP(e){return Object.fromEntries(e)}function sg(e,n){const t={};let r=!1;for(const[o,s]of Eo(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function y1(e,n){const t={};for(const[r,o]of Eo(e)){const s=n(r,o);t[r]=s}return t}function aP(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 i5=()=>typeof process<"u"&&!1,Uh=[],a5=()=>{const e=Uh.splice(0,Uh.length);for(const n of e)n()};let ig;function l5(){ig||(ig=requestAnimationFrame(()=>{ig=void 0,a5()}))}function c5(e){if(i5())return e();Uh.includes(e)||(Uh.push(e),l5())}function u5(e,n){return e.id>n.id?1:-1}function d5(e){return e!==null}const ds=typeof window<"u"&&window.structuredClone?window.structuredClone:e=>e&&JSON.parse(JSON.stringify(e));let Xp=(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 gv{constructor(n,t){v(this,"createDefaultProperties");v(this,"migrations");v(this,"validator");v(this,"scope");v(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{...ds(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??Xp())}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 gv(this.typeName,{createDefaultProperties:n,migrations:this.migrations,validator:this.validator,scope:this.scope})}validate(n){return this.validator.validate(n)}}function zo(e,n){return new gv(e,{createDefaultProperties:()=>({}),migrations:n.migrations??{currentVersion:0,firstVersion:0,migrators:{}},validator:n.validator,scope:n.scope})}class v1{constructor(){v(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}}var Hh={exports:{}};Hh.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]",y="[object GeneratorFunction]",f="[object Map]",m="[object Number]",S="[object Null]",w="[object Object]",x="[object Promise]",C="[object Proxy]",P="[object RegExp]",k="[object Set]",I="[object String]",_="[object Symbol]",$="[object Undefined]",T="[object WeakMap]",R="[object ArrayBuffer]",L="[object DataView]",N="[object Float32Array]",D="[object Float64Array]",z="[object Int8Array]",F="[object Int16Array]",W="[object Int32Array]",H="[object Uint8Array]",U="[object Uint8ClampedArray]",V="[object Uint16Array]",X="[object Uint32Array]",re=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Ce=/^(?:0|[1-9]\d*)$/,oe={};oe[N]=oe[D]=oe[z]=oe[F]=oe[W]=oe[H]=oe[U]=oe[V]=oe[X]=!0,oe[a]=oe[l]=oe[R]=oe[u]=oe[L]=oe[d]=oe[h]=oe[p]=oe[f]=oe[m]=oe[w]=oe[P]=oe[k]=oe[I]=oe[T]=!1;var Se=typeof Ot=="object"&&Ot&&Ot.Object===Object&&Ot,De=typeof self=="object"&&self&&self.Object===Object&&self,et=Se||De||Function("return this")(),Ee=n&&!n.nodeType&&n,ct=Ee&&!0&&e&&!e.nodeType&&e,Fe=ct&&ct.exports===Ee,qn=Fe&&Se.process,_n=function(){try{return qn&&qn.binding&&qn.binding("util")}catch{}}(),Tn=_n&&_n.isTypedArray;function tt(M,j){for(var G=-1,J=M==null?0:M.length,Ye=0,ye=[];++G<J;){var ut=M[G];j(ut,G,M)&&(ye[Ye++]=ut)}return ye}function mt(M,j){for(var G=-1,J=j.length,Ye=M.length;++G<J;)M[Ye+G]=j[G];return M}function lo(M,j){for(var G=-1,J=M==null?0:M.length;++G<J;)if(j(M[G],G,M))return!0;return!1}function dl(M,j){for(var G=-1,J=Array(M);++G<M;)J[G]=j(G);return J}function Xf(M){return function(j){return M(j)}}function qf(M,j){return M.has(j)}function Mi(M,j){return M==null?void 0:M[j]}function cM(M){var j=-1,G=Array(M.size);return M.forEach(function(J,Ye){G[++j]=[Ye,J]}),G}function uM(M,j){return function(G){return M(j(G))}}function dM(M){var j=-1,G=Array(M.size);return M.forEach(function(J){G[++j]=J}),G}var hM=Array.prototype,pM=Function.prototype,Mu=Object.prototype,Zf=et["__core-js_shared__"],Bw=pM.toString,Nr=Mu.hasOwnProperty,Uw=function(){var M=/[^.]+$/.exec(Zf&&Zf.keys&&Zf.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),Hw=Mu.toString,fM=RegExp("^"+Bw.call(Nr).replace(re,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Vw=Fe?et.Buffer:void 0,Au=et.Symbol,Kw=et.Uint8Array,Ww=Mu.propertyIsEnumerable,gM=hM.splice,Fs=Au?Au.toStringTag:void 0,Gw=Object.getOwnPropertySymbols,mM=Vw?Vw.isBuffer:void 0,yM=uM(Object.keys,Object),Qf=Ai(et,"DataView"),hl=Ai(et,"Map"),Jf=Ai(et,"Promise"),eg=Ai(et,"Set"),tg=Ai(et,"WeakMap"),pl=Ai(Object,"create"),vM=Hs(Qf),SM=Hs(hl),wM=Hs(Jf),xM=Hs(eg),bM=Hs(tg),Yw=Au?Au.prototype:void 0,ng=Yw?Yw.valueOf:void 0;function Bs(M){var j=-1,G=M==null?0:M.length;for(this.clear();++j<G;){var J=M[j];this.set(J[0],J[1])}}function CM(){this.__data__=pl?pl(null):{},this.size=0}function PM(M){var j=this.has(M)&&delete this.__data__[M];return this.size-=j?1:0,j}function EM(M){var j=this.__data__;if(pl){var G=j[M];return G===r?void 0:G}return Nr.call(j,M)?j[M]:void 0}function kM(M){var j=this.__data__;return pl?j[M]!==void 0:Nr.call(j,M)}function IM(M,j){var G=this.__data__;return this.size+=this.has(M)?0:1,G[M]=pl&&j===void 0?r:j,this}Bs.prototype.clear=CM,Bs.prototype.delete=PM,Bs.prototype.get=EM,Bs.prototype.has=kM,Bs.prototype.set=IM;function co(M){var j=-1,G=M==null?0:M.length;for(this.clear();++j<G;){var J=M[j];this.set(J[0],J[1])}}function _M(){this.__data__=[],this.size=0}function TM(M){var j=this.__data__,G=Ru(j,M);if(G<0)return!1;var J=j.length-1;return G==J?j.pop():gM.call(j,G,1),--this.size,!0}function $M(M){var j=this.__data__,G=Ru(j,M);return G<0?void 0:j[G][1]}function MM(M){return Ru(this.__data__,M)>-1}function AM(M,j){var G=this.__data__,J=Ru(G,M);return J<0?(++this.size,G.push([M,j])):G[J][1]=j,this}co.prototype.clear=_M,co.prototype.delete=TM,co.prototype.get=$M,co.prototype.has=MM,co.prototype.set=AM;function Us(M){var j=-1,G=M==null?0:M.length;for(this.clear();++j<G;){var J=M[j];this.set(J[0],J[1])}}function OM(){this.size=0,this.__data__={hash:new Bs,map:new(hl||co),string:new Bs}}function RM(M){var j=Du(this,M).delete(M);return this.size-=j?1:0,j}function DM(M){return Du(this,M).get(M)}function jM(M){return Du(this,M).has(M)}function LM(M,j){var G=Du(this,M),J=G.size;return G.set(M,j),this.size+=G.size==J?0:1,this}Us.prototype.clear=OM,Us.prototype.delete=RM,Us.prototype.get=DM,Us.prototype.has=jM,Us.prototype.set=LM;function Ou(M){var j=-1,G=M==null?0:M.length;for(this.__data__=new Us;++j<G;)this.add(M[j])}function NM(M){return this.__data__.set(M,r),this}function zM(M){return this.__data__.has(M)}Ou.prototype.add=Ou.prototype.push=NM,Ou.prototype.has=zM;function Wo(M){var j=this.__data__=new co(M);this.size=j.size}function FM(){this.__data__=new co,this.size=0}function BM(M){var j=this.__data__,G=j.delete(M);return this.size=j.size,G}function UM(M){return this.__data__.get(M)}function HM(M){return this.__data__.has(M)}function VM(M,j){var G=this.__data__;if(G instanceof co){var J=G.__data__;if(!hl||J.length<t-1)return J.push([M,j]),this.size=++G.size,this;G=this.__data__=new Us(J)}return G.set(M,j),this.size=G.size,this}Wo.prototype.clear=FM,Wo.prototype.delete=BM,Wo.prototype.get=UM,Wo.prototype.has=HM,Wo.prototype.set=VM;function KM(M,j){var G=ju(M),J=!G&&iA(M),Ye=!G&&!J&&rg(M),ye=!G&&!J&&!Ye&&r1(M),ut=G||J||Ye||ye,St=ut?dl(M.length,String):[],It=St.length;for(var nt in M)(j||Nr.call(M,nt))&&!(ut&&(nt=="length"||Ye&&(nt=="offset"||nt=="parent")||ye&&(nt=="buffer"||nt=="byteLength"||nt=="byteOffset")||tA(nt,It)))&&St.push(nt);return St}function Ru(M,j){for(var G=M.length;G--;)if(Jw(M[G][0],j))return G;return-1}function WM(M,j,G){var J=j(M);return ju(M)?J:mt(J,G(M))}function fl(M){return M==null?M===void 0?$:S:Fs&&Fs in Object(M)?JM(M):sA(M)}function Xw(M){return gl(M)&&fl(M)==a}function qw(M,j,G,J,Ye){return M===j?!0:M==null||j==null||!gl(M)&&!gl(j)?M!==M&&j!==j:GM(M,j,G,J,qw,Ye)}function GM(M,j,G,J,Ye,ye){var ut=ju(M),St=ju(j),It=ut?l:Go(M),nt=St?l:Go(j);It=It==a?w:It,nt=nt==a?w:nt;var $n=It==w,gr=nt==w,Nt=It==nt;if(Nt&&rg(M)){if(!rg(j))return!1;ut=!0,$n=!1}if(Nt&&!$n)return ye||(ye=new Wo),ut||r1(M)?Zw(M,j,G,J,Ye,ye):ZM(M,j,It,G,J,Ye,ye);if(!(G&o)){var Zn=$n&&Nr.call(M,"__wrapped__"),Qn=gr&&Nr.call(j,"__wrapped__");if(Zn||Qn){var Yo=Zn?M.value():M,uo=Qn?j.value():j;return ye||(ye=new Wo),Ye(Yo,uo,G,J,ye)}}return Nt?(ye||(ye=new Wo),QM(M,j,G,J,Ye,ye)):!1}function YM(M){if(!n1(M)||rA(M))return!1;var j=e1(M)?fM:ge;return j.test(Hs(M))}function XM(M){return gl(M)&&t1(M.length)&&!!oe[fl(M)]}function qM(M){if(!oA(M))return yM(M);var j=[];for(var G in Object(M))Nr.call(M,G)&&G!="constructor"&&j.push(G);return j}function Zw(M,j,G,J,Ye,ye){var ut=G&o,St=M.length,It=j.length;if(St!=It&&!(ut&&It>St))return!1;var nt=ye.get(M);if(nt&&ye.get(j))return nt==j;var $n=-1,gr=!0,Nt=G&s?new Ou:void 0;for(ye.set(M,j),ye.set(j,M);++$n<St;){var Zn=M[$n],Qn=j[$n];if(J)var Yo=ut?J(Qn,Zn,$n,j,M,ye):J(Zn,Qn,$n,M,j,ye);if(Yo!==void 0){if(Yo)continue;gr=!1;break}if(Nt){if(!lo(j,function(uo,Vs){if(!qf(Nt,Vs)&&(Zn===uo||Ye(Zn,uo,G,J,ye)))return Nt.push(Vs)})){gr=!1;break}}else if(!(Zn===Qn||Ye(Zn,Qn,G,J,ye))){gr=!1;break}}return ye.delete(M),ye.delete(j),gr}function ZM(M,j,G,J,Ye,ye,ut){switch(G){case L:if(M.byteLength!=j.byteLength||M.byteOffset!=j.byteOffset)return!1;M=M.buffer,j=j.buffer;case R:return!(M.byteLength!=j.byteLength||!ye(new Kw(M),new Kw(j)));case u:case d:case m:return Jw(+M,+j);case h:return M.name==j.name&&M.message==j.message;case P:case I:return M==j+"";case f:var St=cM;case k:var It=J&o;if(St||(St=dM),M.size!=j.size&&!It)return!1;var nt=ut.get(M);if(nt)return nt==j;J|=s,ut.set(M,j);var $n=Zw(St(M),St(j),J,Ye,ye,ut);return ut.delete(M),$n;case _:if(ng)return ng.call(M)==ng.call(j)}return!1}function QM(M,j,G,J,Ye,ye){var ut=G&o,St=Qw(M),It=St.length,nt=Qw(j),$n=nt.length;if(It!=$n&&!ut)return!1;for(var gr=It;gr--;){var Nt=St[gr];if(!(ut?Nt in j:Nr.call(j,Nt)))return!1}var Zn=ye.get(M);if(Zn&&ye.get(j))return Zn==j;var Qn=!0;ye.set(M,j),ye.set(j,M);for(var Yo=ut;++gr<It;){Nt=St[gr];var uo=M[Nt],Vs=j[Nt];if(J)var o1=ut?J(Vs,uo,Nt,j,M,ye):J(uo,Vs,Nt,M,j,ye);if(!(o1===void 0?uo===Vs||Ye(uo,Vs,G,J,ye):o1)){Qn=!1;break}Yo||(Yo=Nt=="constructor")}if(Qn&&!Yo){var Lu=M.constructor,Nu=j.constructor;Lu!=Nu&&"constructor"in M&&"constructor"in j&&!(typeof Lu=="function"&&Lu instanceof Lu&&typeof Nu=="function"&&Nu instanceof Nu)&&(Qn=!1)}return ye.delete(M),ye.delete(j),Qn}function Qw(M){return WM(M,cA,eA)}function Du(M,j){var G=M.__data__;return nA(j)?G[typeof j=="string"?"string":"hash"]:G.map}function Ai(M,j){var G=Mi(M,j);return YM(G)?G:void 0}function JM(M){var j=Nr.call(M,Fs),G=M[Fs];try{M[Fs]=void 0;var J=!0}catch{}var Ye=Hw.call(M);return J&&(j?M[Fs]=G:delete M[Fs]),Ye}var eA=Gw?function(M){return M==null?[]:(M=Object(M),tt(Gw(M),function(j){return Ww.call(M,j)}))}:uA,Go=fl;(Qf&&Go(new Qf(new ArrayBuffer(1)))!=L||hl&&Go(new hl)!=f||Jf&&Go(Jf.resolve())!=x||eg&&Go(new eg)!=k||tg&&Go(new tg)!=T)&&(Go=function(M){var j=fl(M),G=j==w?M.constructor:void 0,J=G?Hs(G):"";if(J)switch(J){case vM:return L;case SM:return f;case wM:return x;case xM:return k;case bM:return T}return j});function tA(M,j){return j=j??i,!!j&&(typeof M=="number"||Ce.test(M))&&M>-1&&M%1==0&&M<j}function nA(M){var j=typeof M;return j=="string"||j=="number"||j=="symbol"||j=="boolean"?M!=="__proto__":M===null}function rA(M){return!!Uw&&Uw in M}function oA(M){var j=M&&M.constructor,G=typeof j=="function"&&j.prototype||Mu;return M===G}function sA(M){return Hw.call(M)}function Hs(M){if(M!=null){try{return Bw.call(M)}catch{}try{return M+""}catch{}}return""}function Jw(M,j){return M===j||M!==M&&j!==j}var iA=Xw(function(){return arguments}())?Xw:function(M){return gl(M)&&Nr.call(M,"callee")&&!Ww.call(M,"callee")},ju=Array.isArray;function aA(M){return M!=null&&t1(M.length)&&!e1(M)}var rg=mM||dA;function lA(M,j){return qw(M,j)}function e1(M){if(!n1(M))return!1;var j=fl(M);return j==p||j==y||j==c||j==C}function t1(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=i}function n1(M){var j=typeof M;return M!=null&&(j=="object"||j=="function")}function gl(M){return M!=null&&typeof M=="object"}var r1=Tn?Xf(Tn):XM;function cA(M){return aA(M)?KM(M):qM(M)}function uA(){return[]}function dA(){return!1}e.exports=lA})(Hh,Hh.exports);var h5=Hh.exports;const p5=Si(h5);function f5(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 g5(e,n){const t={};for(const r of n)e.has(r)||(t.added??(t.added=new Set),t.added.add(r));for(const r of e)n.has(r)||(t.removed??(t.removed=new Set),t.removed.add(r));return t.added||t.removed?t:void 0}function S1(e,n){for(const[t,r]of Object.entries(e)){const o=r,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 w1(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 f5(Object.values(r))}class m5{constructor(n,t){v(this,"indexCache",new Map);v(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(Sa(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Bn)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?Hl(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(n,t),t}index(n,t){const r=n+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(n,t);return this.indexCache.set(r,o),o}__uncached_createIndex(n,t){const r=this.filterHistory(n),o=()=>{r.get();const s=new Map;for(const i of 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(Sa(s))return o();const a=r.getDiffSince(i);if(a===Bn)return o();const l=new Map,c=(p,y)=>{let f=l.get(p);f||(f=new Ud(s.get(p)??new Set)),f.add(y),l.set(p,f)},u=(p,y)=>{let f=l.get(p);f||(f=new Ud(s.get(p)??new Set)),f.remove(y),l.set(p,f)};for(const p of a){for(const y of dt(p.added))if(y.typeName===n){const f=y[t];c(f,y.id)}for(const[y,f]of dt(p.updated))if(f.typeName===n){const m=y[t],S=f[t];m!==S&&(u(m,f.id),c(S,f.id))}for(const y of dt(p.removed))if(y.typeName===n){const f=y[t];u(f,y.id)}}let d,h;for(const[p,y]of l){const f=y.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?Hl(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:[]})):w1(this,n,l)},i=l=>{const c=s(),u=g5(l,c);return u?Hl(c,u):l},a=Z("ids_query:"+r,t,{isEqual:p5});return Z("query:"+r,(l,c)=>{const u=a.get();if(Sa(l))return s();if(c<a.lastChangedEpoch)return i(l);const d=o.getDiffSince(c);if(d===Bn)return i(l);const h=new Ud(l);for(const y of d){for(const f of dt(y.added))f.typeName===n&&S1(u,f)&&h.add(f.id);for(const[f,m]of dt(y.updated))m.typeName===n&&(S1(u,m)?h.add(m.id):h.remove(m.id));for(const f of dt(y.removed))f.typeName===n&&h.remove(f.id)}const p=h.get();return p?Hl(p.value,p.diff):l},{historyLength:50})}exec(n,t){const r=w1(this,n,t);if(r.size===0)return Po;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class lP{constructor(n){v(this,"id",Xp());v(this,"atoms",an("store_atoms",{}));v(this,"history",an("history",0,{historyLength:1e3}));v(this,"query",new m5(this.atoms,this.history));v(this,"listeners",new Set);v(this,"historyAccumulator",new v5);v(this,"historyReactor");v(this,"schema");v(this,"props");v(this,"scopedTypes");v(this,"onBeforeCreate");v(this,"onAfterCreate");v(this,"onBeforeChange");v(this,"onAfterChange");v(this,"onBeforeDelete");v(this,"onAfterDelete");v(this,"_runCallbacks",!0);v(this,"put",(n,t)=>{nr(()=>{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 y=(i??s)[a.id];if(y){const f=y.__unsafe__getWithoutCapture();u&&(a=u(f,a,d)),a=this.schema.validateRecord(this,a,t??"updateRecord",f),y.set(a);const m=y.__unsafe__getWithoutCapture();f!==m&&(l=!0,r[a.id]=[f,m])}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]=an("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(y=>{h(y,d)}),p&&Object.values(r).forEach(([y,f])=>{p(y,f,d)})}})});v(this,"remove",n=>{nr(()=>{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)}})});v(this,"get",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.get()});v(this,"unsafeGetWithoutCapture",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.__unsafe__getWithoutCapture()});v(this,"serialize",(n="document")=>{const t={};for(const[r,o]of Eo(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});v(this,"allRecords",()=>dt(this.atoms.get()).map(n=>n.get()));v(this,"clear",()=>{this.remove(m1(this.atoms.get()))});v(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())])});v(this,"has",n=>!!this.atoms.get()[n]);v(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()}});v(this,"isMergingRemoteChanges",!1);v(this,"mergeRemoteChanges",n=>{if(this.isMergingRemoteChanges)return n();try{this.isMergingRemoteChanges=!0,nr(n)}finally{this.isMergingRemoteChanges=!1}});v(this,"createComputedCache",(n,t,r)=>{const o=new v1;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()}}});v(this,"createSelectedComputedCache",(n,t,r)=>{const o=new v1;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()}}});v(this,"getRecordType",n=>{const t=this.schema.types[n.typeName];if(!t)throw new Error(`Record type ${n.typeName} not found`);return t});v(this,"_integrityChecker");v(this,"_isPossiblyCorrupted",!1);const{initialData:t,schema:r}=n;this.schema=r,this.props=n.props,t&&this.atoms.set(iP(Eo(t).map(([o,s])=>[o,an("atom:"+o,this.schema.validateRecord(this,s,"initialize",null))]))),this.historyReactor=FA("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>c5(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:sg(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:sg(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:sg(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}`);nr(()=>{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 nr(n),qp(t)}finally{r()}}applyDiff(n,t=!0){const r=this._runCallbacks;try{this._runCallbacks=t,nr(()=>{const o=dt(n.added).concat(dt(n.updated).map(([i,a])=>a)),s=m1(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 qp(e){const n={added:{},removed:{},updated:{}};for(const t of e){for(const[r,o]of Eo(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 Eo(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 Eo(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 y5(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:qp([t.changes,r.changes])};return n.push(t),n}class v5{constructor(){v(this,"_history",[]);v(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=y5(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function S5(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 Vl=(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))(Vl||{});function Fu({record:e,migrations:n,fromVersion:t,toVersion:r}){let o=t;if(!S5(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 mv({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 yv{constructor(n,t){this.types=n,this.options=t}static create(n,t){return new yv(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=si(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=si(this.types,n.typeName),s=t.recordVersions[n.typeName];if(!s||!o)return{type:"error",reason:Vl.UnknownType};const i=o.migrations.currentVersion,a=s.version;if(i!==a){const h=Fu(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:Vl.UnrecognizedSubtype};if(c===void 0)return{type:"error",reason:Vl.IncompatibleSubtype};const u=Fu(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:Vl.TargetVersionTooOld};if(o>s){const a=mv({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 w5=(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 x5(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 Be extends Error{constructor(t,r=[]){const o=x5(r),s=t.split(`
|
|
31
|
+
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
32
|
+
`);super(r?`At ${o}: ${s}`:s);v(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function Ga(e,n){try{return n()}catch(t){throw t instanceof Be?new Be(t.rawMessage,[e,...t.path]):new Be(t.toString(),[e])}}function $a(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:Wa(n)}}class dn{constructor(n){this.validationFn=n}validate(n){return this.validationFn(n)}isValid(n){try{return this.validate(n),!0}catch{return!1}}nullable(){return I5(this)}optional(){return uP(this)}refine(n){return new dn(t=>n(this.validate(t)))}check(n,t){return typeof n=="string"?this.refine(r=>(Ga(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class b5 extends dn{constructor(n){super(t=>{const r=k5.validate(t);for(let o=0;o<r.length;o++)Ga(o,()=>n.validate(r[o]));return r}),this.itemValidator=n}nonEmpty(){return this.check(n=>{if(n.length===0)throw new Be("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new Be("Expected an array with length greater than 1")})}}class Vh extends dn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Be(`Expected object, got ${$a(r)}`);for(const[o,s]of Object.entries(n))Ga(o,()=>{s.validate(si(r,o))});if(!t){for(const o of Object.keys(r))if(!Yp(n,o))throw new Be("Unexpected property",[o])}return r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new Vh(this.config,!0)}extend(n){return new Vh({...this.config,...n})}}class vv extends dn{constructor(n,t,r){super(o=>{if(typeof o!="object"||o===null)throw new Be(`Expected an object, got ${$a(o)}`,[]);const s=si(o,n);if(typeof s!="string")throw new Be(`Expected a string for key "${n}", got ${$a(s)}`);const i=Yp(t,s)?t[s]:void 0;return i===void 0?this.unknownValueValidation(o,s):Ga(`(${n} = ${s})`,()=>i.validate(o))}),this.key=n,this.config=t,this.unknownValueValidation=r}validateUnknownVariants(n){return new vv(this.key,this.config,n)}}class C5 extends dn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Be(`Expected object, got ${$a(r)}`);for(const[o,s]of Object.entries(r))Ga(o,()=>{n.validate(o),t.validate(s)});return r}),this.keyValidator=n,this.valueValidator=t}}function Sv(e){return new dn(n=>{if(typeof n!==e)throw new Be(`Expected ${e}, got ${$a(n)}`);return n})}const P5=new dn(e=>e),me=Sv("string"),fe=Sv("number").check(e=>{if(Number.isNaN(e))throw new Be("Expected a number, got NaN");if(!Number.isFinite(e))throw new Be(`Expected a finite number, got ${e}`)}),wv=fe.check(e=>{if(e<0)throw new Be(`Expected a positive number, got ${e}`)}),Pn=fe.check(e=>{if(e<=0)throw new Be(`Expected a non-zero positive number, got ${e}`)}),cP=fe.check(e=>{if(!Number.isInteger(e))throw new Be(`Expected an integer, got ${e}`)}),Bu=cP.check(e=>{if(e<0)throw new Be(`Expected a positive integer, got ${e}`)}),E5=cP.check(e=>{if(e<=0)throw new Be(`Expected a non-zero positive integer, got ${e}`)}),we=Sv("boolean");function En(e){return new dn(n=>{if(n!==e)throw new Be(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const k5=new dn(e=>{if(!Array.isArray(e))throw new Be(`Expected an array, got ${$a(e)}`);return e});function ln(e){return new b5(e)}function Pe(e){return new Vh(e)}function vy(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(vy):typeof e=="object"?Object.values(e).every(vy):!1}const Zr=new dn(e=>{if(vy(e))return e;throw new Be(`Expected json serializable value, got ${typeof e}`)});function Sy(e,n){return new C5(e,n)}function xv(e,n){return new vv(e,n,(t,r)=>{throw new Be(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])})}function Fo(e,n){return new dn(t=>{const r=t&&typeof t=="object"&&"id"in t&&typeof t.id=="string"?`${e}(id = ${t.id})`:e;return Ga(r,()=>n.validate(t))})}function ru(e){return new dn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Be(`Expected ${t}, got ${n}`)}return n})}function uP(e){return new dn(n=>{if(n!==void 0)return e.validate(n)})}function I5(e){return new dn(n=>n===null?null:e.validate(n))}function dP(...e){return ru(new Set(e))}function hP(e){try{return new URL(e)}catch{throw new Be(`Expected a valid url, got ${JSON.stringify(e)}`)}}const _5=new Set(["http:","https:","mailto:"]),Kn=me.check(e=>{if(e==="")return;const n=hP(e);if(!_5.has(n.protocol.toLowerCase()))throw new Be(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),T5=new Set(["http:","https:","data:"]),Ya=me.check(e=>{if(e==="")return;const n=hP(e);if(!T5.has(n.protocol.toLowerCase()))throw new Be(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)});function Ir(e){return me.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const Zp=Ir("asset");function bv(e,n){return Pe({id:Zp,typeName:En("asset"),type:En(e),props:n,meta:Zr})}const $5=Fo("camera",Pe({typeName:En("camera"),id:Ir("camera"),x:fe,y:fe,z:fe,meta:Zr})),x1={AddMeta:1},M5=$e({currentVersion:x1.AddMeta,migrators:{[x1.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Ht=zo("camera",{validator:$5,migrations:M5,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),gc=Pe({x:fe,y:fe,z:fe.optional()}),Zl=Pe({x:fe,y:fe,w:fe,h:fe}),A5=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"]),pP=ru(A5),O5=Pe({type:pP,rotation:fe}),fP=fe.check(e=>{if(e<0||e>1)throw new Be("Opacity must be between 0 and 1")}),R5=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),D5=ru(R5),j5=new Set(["starting","paused","active","stopping"]),gP=Pe({id:me,points:ln(gc),size:wv,color:D5,opacity:fe,state:ru(j5),delay:fe,shrink:fe,taper:we}),mc=Ir("page"),L5=Fo("page",Pe({typeName:En("page"),id:mc,name:me,index:me,meta:Zr})),b1={AddMeta:1},N5=$e({currentVersion:b1.AddMeta,migrators:{[b1.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Mo=zo("page",{validator:L5,migrations:N5,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function gn(e){return Mo.isId(e)}Ir("instance");function z5(e){const n={};for(const[r,o]of e)n[r]=uP(o);const t=Fo("instance",Pe({typeName:En("instance"),id:Ir("instance"),currentPageId:mc,followingUserId:me.nullable(),brush:Zl.nullable(),opacityForNextShape:fP,stylesForNextShape:Pe(n),cursor:O5,scribbles:ln(gP),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:Zl,zoomBrush:Zl.nullable(),isPenMode:we,isGridMode:we,chatMessage:me,isChatting:we,highlightedUserIds:ln(me),canMoveCamera:we,isFocused:we,devicePixelRatio:fe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:ln(me),isChangingStyle:we,isReadonly:we,meta:Zr}));return zo("instance",{migrations:F5,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},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:{}}))}const rt={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},F5=$e({currentVersion:rt.AddScribbles,migrators:{[rt.AddTransparentExportBgs]:{up:e=>({...e,exportBackground:!0}),down:({exportBackground:e,...n})=>n},[rt.RemoveDialog]:{up:({dialog:e,...n})=>n,down:e=>({...e,dialog:null})},[rt.AddToolLockMode]:{up:e=>({...e,isToolLocked:!1}),down:({isToolLocked:e,...n})=>n},[rt.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},[rt.AddLabelColor]:{up:({propsForNextShape:e,...n})=>({...n,propsForNextShape:{...e,labelColor:"black"}}),down:e=>{const{labelColor:n,...t}=e.propsForNextShape;return{...e,propsForNextShape:{...t}}}},[rt.AddFollowingUserId]:{up:e=>({...e,followingUserId:null}),down:({followingUserId:e,...n})=>n},[rt.RemoveAlignJustify]:{up:e=>{let n=e.propsForNextShape.align;return n==="justify"&&(n="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:n}}},down:e=>({...e})},[rt.AddZoom]:{up:e=>({...e,zoomBrush:null}),down:({zoomBrush:e,...n})=>n},[rt.AddVerticalAlign]:{up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:n,...t}=e.propsForNextShape;return{...e,propsForNextShape:t}}},[rt.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}}},[rt.RemoveUserId]:{up:({userId:e,...n})=>n,down:e=>({...e,userId:"user:none"})},[rt.AddIsPenModeAndIsGridMode]:{up:e=>({...e,isPenMode:!1,isGridMode:!1}),down:({isPenMode:e,isGridMode:n,...t})=>t},[rt.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"}})},[rt.AddChat]:{up:e=>({...e,chatMessage:"",isChatting:!1}),down:({chatMessage:e,isChatting:n,...t})=>t},[rt.AddHighlightedUserIds]:{up:e=>({...e,highlightedUserIds:[]}),down:({highlightedUserIds:e,...n})=>n},[rt.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"}})},[rt.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})},[rt.RemoveCursorColor]:{up:e=>{const{color:n,...t}=e.cursor;return{...e,cursor:t}},down:e=>({...e,cursor:{...e.cursor,color:"black"}})},[rt.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})},[rt.ReadOnlyReadonly]:{up:({isReadOnly:e,...n})=>({...n,isReadonly:e}),down:({isReadonly:e,...n})=>({...n,isReadOnly:e})},[rt.AddHoveringCanvas]:{up:e=>({...e,isHoveringCanvas:null}),down:({isHoveringCanvas:e,...n})=>({...n})},[rt.AddScribbles]:{up:({scribble:e,...n})=>({...n,scribbles:[]}),down:({scribbles:e,...n})=>({...n,scribble:null})}}}),sn="instance:instance",B5=me.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),vr=Ir("shape");function U5(e,n,t){return Pe({id:vr,typeName:En("shape"),x:fe,y:fe,rotation:fe,index:me,parentId:B5,type:En(e),isLocked:we,opacity:fP,props:n?Pe(n):Zr,meta:t?Pe(t):Zr})}const H5=Fo("instance_page_state",Pe({typeName:En("instance_page_state"),id:Ir("instance_page_state"),pageId:mc,selectedShapeIds:ln(vr),hintingShapeIds:ln(vr),erasingShapeIds:ln(vr),hoveredShapeId:vr.nullable(),editingShapeId:vr.nullable(),croppingShapeId:vr.nullable(),focusedGroupId:vr.nullable(),meta:Zr})),Oi={AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5},V5=$e({currentVersion:Oi.RenamePropertiesAgain,migrators:{[Oi.AddCroppingId]:{up(e){return{...e,croppingShapeId:null}},down({croppingShapeId:e,...n}){return n}},[Oi.RemoveInstanceIdAndCameraId]:{up({instanceId:e,cameraId:n,...t}){return t},down(e){return{...e,instanceId:sn,cameraId:Ht.createId("void")}}},[Oi.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})},[Oi.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}}},[Oi.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}}}}}),Vt=zo("instance_page_state",{migrations:V5,validator:H5,scope:"session"}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),K5=Fo("pointer",Pe({typeName:En("pointer"),id:Ir("pointer"),x:fe,y:fe,lastActivityTimestamp:fe,meta:Zr})),C1={AddMeta:1},W5=$e({currentVersion:C1.AddMeta,migrators:{[C1.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Cv=zo("pointer",{validator:K5,migrations:W5,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Kh=Cv.createId("pointer"),G5=Fo("instance_presence",Pe({typeName:En("instance_presence"),id:Ir("instance_presence"),userId:me,userName:me,lastActivityTimestamp:fe,followingUserId:me.nullable(),cursor:Pe({x:fe,y:fe,type:pP,rotation:fe}),color:me,camera:Pe({x:fe,y:fe,z:fe}),screenBounds:Zl,selectedShapeIds:ln(Ir("shape")),currentPageId:Ir("page"),brush:Zl.nullable(),scribbles:ln(gP),chatMessage:me,meta:Zr})),Ri={AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5},Y5=$e({currentVersion:Ri.RenameSelectedShapeIds,migrators:{[Ri.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}}},[Ri.RemoveInstanceId]:{up:({instanceId:e,...n})=>n,down:e=>({...e,instanceId:sn})},[Ri.AddChatMessage]:{up:e=>({...e,chatMessage:""}),down:({chatMessage:e,...n})=>n},[Ri.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})},[Ri.RenameSelectedShapeIds]:{up:e=>{const{selectedShapeIds:n,...t}=e;return{selectedShapeIds:n,...t}},down:e=>{const{selectedShapeIds:n,...t}=e;return{selectedShapeIds:n,...t}}}}}),X5=zo("instance_presence",{migrations:Y5,validator:G5,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:{}})),q5=Fo("document",Pe({typeName:En("document"),id:En("document:document"),gridSize:fe,name:me,meta:Zr})),ag={AddName:1,AddMeta:2},Z5=$e({currentVersion:ag.AddMeta,migrators:{[ag.AddName]:{up:e=>({...e,name:""}),down:({name:e,...n})=>n},[ag.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Pv=zo("document",{migrations:Z5,validator:q5,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),wy=Pv.createId("document");function Q5(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function P1(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const J5=({error:e,phase:n,record:t,recordBefore:r})=>{throw fv(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?P1(ds(r)):void 0,recordAfter:P1(ds(t))}}),e};function eO(){return[Mo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function tO(e){const n=e.query.ids("page"),t=()=>{if(!e.has(wy))return e.put([Pv.create({id:wy,name:e.props.defaultName})]),t();if(!e.has(Kh))return e.put([Cv.create({id:Kh})]),t();const r=n.get();if(r.size===0)return e.put(eO()),t();const o=()=>[...r].map(l=>e.get(l)).sort(Q5)[0].id,s=e.get(sn);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:sn,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const l of r){const c=Vt.createId(l);e.has(c)||i.add(c);const u=Ht.createId(l);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(l=>Vt.create({id:l,pageId:Vt.parseId(l)}))),a.size>0&&e.put([...a].map(l=>Ht.create({id:l})))};return t}const nO=bv("bookmark",Pe({title:me,description:me,image:me,src:Ya.nullable()})),E1={MakeUrlsValid:1},rO=$e({currentVersion:E1.MakeUrlsValid,migrators:{[E1.MakeUrlsValid]:{up:e=>{const n=e.props.src;return n&&!Ya.isValid(n)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),oO=bv("image",Pe({w:fe,h:fe,name:me,isAnimated:we,mimeType:me.nullable(),src:Ya.nullable()})),Uu={AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3},sO=$e({currentVersion:Uu.MakeUrlsValid,migrators:{[Uu.AddIsAnimated]:{up:e=>({...e,props:{...e.props,isAnimated:!1}}),down:e=>{const{isAnimated:n,...t}=e.props;return{...e,props:t}}},[Uu.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}}}},[Uu.MakeUrlsValid]:{up:e=>{const n=e.props.src;return n&&!Ya.isValid(n)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),iO=bv("video",Pe({w:fe,h:fe,name:me,isAnimated:we,mimeType:me.nullable(),src:Ya.nullable()})),Hu={AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3},aO=$e({currentVersion:Hu.MakeUrlsValid,migrators:{[Hu.AddIsAnimated]:{up:e=>({...e,props:{...e.props,isAnimated:!1}}),down:e=>{const{isAnimated:n,...t}=e.props;return{...e,props:t}}},[Hu.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}}}},[Hu.MakeUrlsValid]:{up:e=>{const n=e.props.src;return n&&!Ya.isValid(n)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),lO=Fo("asset",xv("type",{image:oO,video:iO,bookmark:nO})),k1={AddMeta:1},cO=$e({subTypeKey:"type",subTypeMigrations:{image:sO,video:aO,bookmark:rO},currentVersion:k1.AddMeta,migrators:{[k1.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}}),Zs=zo("asset",{migrations:cO,validator:lO,scope:"document"}).withDefaultProperties(()=>({meta:{}}));class en{constructor(n,t,r){this.id=n,this.defaultValue=t,this.type=r}static define(n,t){const{defaultValue:r,type:o=P5}=t;return new en(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new uO(n,r,o)}validate(n){return this.type.validate(n)}}class uO extends en{constructor(n,t,r){super(n,t,dP(...r)),this.values=r}}const Vu={AddIsLocked:1,HoistOpacity:2,AddMeta:3},lg=$e({currentVersion:Vu.AddMeta,migrators:{[Vu.AddIsLocked]:{up:e=>({...e,isLocked:!1}),down:e=>{const{isLocked:n,...t}=e;return{...t}}},[Vu.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"}})},[Vu.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...n})=>({...n})}}});function Qs(e){return e?e.typeName==="shape":!1}function tr(e){return e?e.startsWith("shape:"):!1}function We(e){return`shape:${e??Xp()}`}function mP(e){const n=new Map;for(const[t,r]of Object.entries(e))if(r instanceof en){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 dO(e){return zo("shape",{migrations:$e({currentVersion:lg.currentVersion,firstVersion:lg.firstVersion,migrators:lg.migrators,subTypeKey:"type",subTypeMigrations:y1(e,(n,t)=>t.migrations??$e({}))}),scope:"document",validator:Fo("shape",xv("type",y1(e,(n,{props:t,meta:r})=>U5(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}const ml={RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4},hO=$e({currentVersion:ml.RemoveUserDocument,migrators:{[ml.RemoveCodeAndIconShapeTypes]:{up:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>t.typeName!=="shape"||t.type!=="icon"&&t.type!=="code")),down:e=>e},[ml.AddInstancePresenceType]:{up:e=>e,down:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>t.typeName!=="instance_presence"))},[ml.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"))},[ml.RemoveUserDocument]:{up:e=>Object.fromEntries(Object.entries(e).filter(([n,t])=>!t.typeName.match("user_document"))),down:e=>e}}});function pO({shapes:e}){const n=new Map;for(const o of dt(e))for(const s of mP(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=dO(e),r=z5(n);return yv.create({asset:Zs,camera:Ht,document:Pv,instance:r,instance_page_state:Vt,page:Mo,shape:t,instance_presence:X5,pointer:Cv},{snapshotMigrations:hO,onValidationFailure:J5,createIntegrityChecker:tO})}const yP=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red"],Wh={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:"#f8f9fa",background:"#212529",solid:"#28292e",black:{solid:"#e1e1e1",semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4156be",semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#3b7b5e",semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#93989f",semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#588fc9",semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#599f57",semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#c67877",semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#b583c9",semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#bf612e",semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#aa3c37",semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#873fa3",semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#cba371",semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}}}};function kn(e){return e.isDarkMode?Wh.darkMode:Wh.lightMode}const cr=en.defineEnum("tldraw:color",{defaultValue:"black",values:yP}),vP=en.defineEnum("tldraw:labelColor",{defaultValue:"black",values:yP}),li=en.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Ma=en.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern"]}),Qr=en.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),ou={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},Jr=en.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),SP=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Gh=en.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:SP}),Yh=en.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:SP}),I1=xv("type",{binding:Pe({type:En("binding"),boundShapeId:vr,normalizedAnchor:gc,isExact:we,isPrecise:we}),point:Pe({type:En("point"),x:fe,y:fe})}),fO={labelColor:vP,color:cr,fill:Ma,dash:li,size:Jr,arrowheadStart:Gh,arrowheadEnd:Yh,font:Qr,start:I1,end:I1,bend:fe,text:me},cg={AddLabelColor:1,AddIsPrecise:2},gO=$e({currentVersion:cg.AddIsPrecise,migrators:{[cg.AddLabelColor]:{up:e=>({...e,props:{...e.props,labelColor:"black"}}),down:e=>{const{labelColor:n,...t}=e.props;return{...e,props:t}}},[cg.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}}}}}}),mO={w:Pn,h:Pn,assetId:Zp.nullable(),url:Kn},ug={NullAssetId:1,MakeUrlsValid:2},yO=$e({currentVersion:ug.MakeUrlsValid,migrators:{[ug.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}},[ug.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Kn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),wP=Pe({type:dP("free","straight"),points:ln(gc)}),vO={color:cr,fill:Ma,dash:li,size:Jr,segments:ln(wP),isComplete:we,isClosed:we,isPen:we},_1={AddInPen:1},SO=$e({currentVersion:_1.AddInPen,migrators:{[_1.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 wO={};const T1=/(^\/r\/[^/]+\/?$)/,je=e=>{try{return new URL(e)}catch{return}},Aa=[{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=je(e);if(n&&n.pathname.match(T1))return e},fromEmbedUrl:e=>{const n=je(e);if(n&&n.pathname.match(T1))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=je(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=${wO.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${o}&zoom=${s}`}else t="";return t}},fromEmbedUrl:e=>{const n=je(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=je(e),t=n&&n.pathname.match(/\/v\/([^/]+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:e=>{const n=je(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=je(e),t=n&&n.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:e=>{const n=je(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=je(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=je(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=je(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=je(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=je(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=je(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=je(e);if(n&&n.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const n=je(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=je(e);if(n&&n.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const n=je(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=je(e);if(n&&n.pathname.match(/^\/map\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=je(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=je(e);if(n&&n.pathname.match(/^\/(artist|album)\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=je(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=je(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=je(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=je(e);if(n&&n.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const n=je(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=je(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=je(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-*`}}],xO={"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},bO={w:Pn,h:Pn,url:me},yl={GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4},CO=$e({currentVersion:yl.RemovePermissionOverrides,migrators:{[yl.GenOriginalUrlInEmbed]:{up:e=>{const n=e.props.url,t=new URL(n).host.replace("www.","");let r;for(const o of Aa)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 Aa)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??""}}}},[yl.RemoveDoesResize]:{up:e=>{const{doesResize:n,...t}=e.props;return{...e,props:{...t}}},down:e=>({...e,props:{...e.props,doesResize:!0}})},[yl.RemoveTmpOldUrl]:{up:e=>{const{tmpOldUrl:n,...t}=e.props;return{...e,props:{...t}}},down:e=>({...e,props:{...e.props}})},[yl.RemovePermissionOverrides]:{up:e=>{const{overridePermissions:n,...t}=e.props;return{...e,props:{...t}}},down:e=>({...e,props:{...e.props}})}}}),PO={w:Pn,h:Pn,name:me},EO=$e({}),yc=en.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Xh=en.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Yr=en.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"]}),kO={geo:Yr,labelColor:vP,color:cr,fill:Ma,dash:li,size:Jr,font:Qr,align:yc,verticalAlign:Xh,url:Kn,w:Pn,h:Pn,growY:wv,text:me},ho={AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8},IO=$e({currentVersion:ho.MakeUrlsValid,migrators:{[ho.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[ho.AddLabelColor]:{up:e=>({...e,props:{...e.props,labelColor:"black"}}),down:e=>{const{labelColor:n,...t}=e.props;return{...e,props:t}}},[ho.RemoveJustify]:{up:e=>{let n=e.props.align;return n==="justify"&&(n="start"),{...e,props:{...e.props,align:n}}},down:e=>({...e})},[ho.AddCheckBox]:{up:e=>({...e}),down:e=>({...e,props:{...e.props,geo:e.props.geo==="check-box"?"rectangle":e.props.geo}})},[ho.AddVerticalAlign]:{up:e=>({...e,props:{...e.props,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:n,...t}=e.props;return{...e,props:t}}},[ho.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}}}},[ho.AddCloud]:{up:e=>e,down:e=>{if(e.props.geo==="cloud")return{...e,props:{...e.props,geo:"rectangle"}}}},[ho.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Kn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),_O={},TO=$e({}),$O={color:cr,size:Jr,segments:ln(wP),isComplete:we,isPen:we},MO=$e({}),AO=Pe({topLeft:gc,bottomRight:gc}),OO={w:Pn,h:Pn,playing:we,url:Kn,assetId:Zp.nullable(),crop:AO.nullable()},Ku={AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3},RO=$e({currentVersion:Ku.MakeUrlsValid,migrators:{[Ku.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[Ku.AddCropProp]:{up:e=>({...e,props:{...e.props,crop:null}}),down:e=>{const{crop:n,...t}=e.props;return{...e,props:t}}},[Ku.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Kn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),DO=new Set(["vertex","virtual","create"]),jO=Pe({id:me,type:ru(DO),canBind:we.optional(),canSnap:we.optional(),index:me,x:fe,y:fe}),qh=en.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),LO={color:cr,dash:li,size:Jr,spline:qh,handles:Sy(me,jO)},$1={AddSnapHandles:1},NO=$e({currentVersion:$1.AddSnapHandles,migrators:{[$1.AddSnapHandles]:{up:e=>{const n=qt(e.props.handles);for(const t in n)n[t].canSnap=!0;return{...e,props:{...e.props,handles:n}}},down:e=>{const n=qt(e.props.handles);for(const t in n)delete n[t].canSnap;return{...e,props:{...e.props,handles:n}}}}}}),zO={color:cr,size:Jr,font:Qr,align:yc,verticalAlign:Xh,growY:wv,url:Kn,text:me},Di={AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5},FO=$e({currentVersion:Di.MakeUrlsValid,migrators:{[Di.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[Di.RemoveJustify]:{up:e=>{let n=e.props.align;return n==="justify"&&(n="start"),{...e,props:{...e.props,align:n}}},down:e=>({...e})},[Di.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}}}},[Di.AddVerticalAlign]:{up:e=>({...e,props:{...e.props,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:n,...t}=e.props;return{...e,props:t}}},[Di.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Kn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),BO={color:cr,size:Jr,font:Qr,align:yc,w:Pn,text:me,scale:Pn,autoSize:we},M1={RemoveJustify:1},UO=$e({currentVersion:M1.RemoveJustify,migrators:{[M1.RemoveJustify]:{up:e=>{let n=e.props.align;return n==="justify"&&(n="start"),{...e,props:{...e.props,align:n}}},down:e=>({...e})}}}),HO={w:Pn,h:Pn,time:fe,playing:we,url:Kn,assetId:Zp.nullable()},dg={AddUrlProp:1,MakeUrlsValid:2},VO=$e({currentVersion:dg.MakeUrlsValid,migrators:{[dg.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:n,...t}=e.props;return{...e,props:t}}},[dg.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Kn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),vc=[{locale:"ar",label:"عربي"},{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:"fa",label:"فارسی"},{locale:"fi",label:"Suomi"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"he",label:"עברית"},{locale:"it",label:"Italiano"},{locale:"ja",label:"日本語"},{locale:"ko-kr",label:"한국어"},{locale:"ku",label:"کوردی"},{locale:"hi-in",label:"हिन्दी"},{locale:"hu",label:"Magyar"},{locale:"my",label:"မြန်မာစာ"},{locale:"ne",label:"नेपाली"},{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:"sv",label:"Svenska"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"vi",label:"Tiếng Việt"},{locale:"zh-cn",label:"Chinese - Simplified"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function KO(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return WO(e)}function WO(e){for(const n of e){const t=GO(n);if(t)return t}return"en"}const A1={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function GO(e){const n=vc.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=vc.find(s=>s.locale===t);if(o)return o.locale}return t in A1?A1[t]:null}var xP={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})()})(xP);var YO=xP.exports;const pe=Si(YO);var hg={};const XO={},He={preventDefaultLogging:Mn("preventDefaultLogging",{defaults:{all:!1}}),pointerCaptureLogging:Mn("pointerCaptureLogging",{defaults:{all:!1}}),pointerCaptureTracking:Mn("pointerCaptureTracking",{defaults:{all:!1}}),pointerCaptureTrackingObject:Mn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),elementRemovalLogging:Mn("elementRemovalLogging",{defaults:{all:!1}}),debugSvg:Mn("debugSvg",{defaults:{all:!1}}),throwToBlob:Mn("throwToBlob",{defaults:{all:!1}}),logMessages:Mn("uiLog",{defaults:{all:[]}}),resetConnectionEveryPing:Mn("resetConnectionEveryPing",{defaults:{all:!1}}),debugCursors:Mn("debugCursors",{defaults:{all:!1}}),forceSrgb:Mn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Mn("debugGeometry",{defaults:{all:!1}}),hideShapes:Mn("hideShapes",{defaults:{all:!1}})};typeof window<"u"&&(window.tldrawLog=e=>{He.logMessages.set(He.logMessages.get().concat(e))});if(typeof Element<"u"){const e=Element.prototype.removeChild;nu("element removal logging",()=>{He.elementRemovalLogging.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function Mn(e,{defaults:n,shouldStoreForSession:t=!0}){return qO({name:e,defaults:n,shouldStoreForSession:t})}function qO(e){const n=QO(e),t=e.shouldStoreForSession?ZO(e.name):null,r=an(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&nu(`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 ZO(e){try{return JSON.parse((window==null?void 0:window.sessionStorage.getItem(`tldraw_debug:${e}`))??"null")}catch{return null}}function pg(e){try{return e()}catch{return null}}function QO(e){switch(pg(()=>hg.TLDRAW_ENV)??pg(()=>hg.VERCEL_PUBLIC_TLDRAW_ENV)??pg(()=>hg.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 Zh(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return Zh(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ie(e){e.preventDefault(),He.preventDefaultLogging.get()&&console.warn("preventDefault called on event:",e)}function su(e,n){if(e.setPointerCapture(n.pointerId),He.pointerCaptureTracking.get()){const t=He.pointerCaptureTrackingObject.get();t.set(e,(t.get(e)??0)+1)}He.pointerCaptureLogging.get()&&console.warn("setPointerCapture called on element:",e,n)}function iu(e,n){if(e.hasPointerCapture(n.pointerId)){if(e.releasePointerCapture(n.pointerId),He.pointerCaptureTracking.get()){const t=He.pointerCaptureTrackingObject.get();t.get(e)===1?t.delete(e):t.has(e)?t.set(e,t.get(e)-1):console.warn("Release without capture")}He.pointerCaptureLogging.get()&&console.warn("releasePointerCapture called on element:",e,n)}}const bt=e=>e.stopPropagation();function Sn(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 Ev=ne.createContext({});function K(){return ne.useContext(Ev)}function JO(){const e=K();return b.useMemo(function(){let r,o;function s(f){if(!f.isKilled){if(f.button===2){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...Sn(f)});return}f.button!==0&&f.button!==1&&f.button!==5||(su(f.currentTarget,f),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...Sn(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",...Sn(f)}))}function a(f){f.isKilled||f.button!==0&&f.button!==1&&f.button!==2&&f.button!==5||(r=f.clientX,o=f.clientY,iu(f.currentTarget,f),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...Sn(f)}))}function l(f){if(f.isKilled||e.getInstanceState().isPenMode&&f.pointerType!=="pen")return;const m=f.pointerType==="mouse"||f.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:m?!0:null})}function c(f){if(f.isKilled||e.getInstanceState().isPenMode&&f.pointerType!=="pen")return;const m=f.pointerType==="mouse"||f.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:m?!1:null})}function u(f){f.isKilled=!0,document.body.click(),Ie(f)}function d(f){f.isKilled=!0,f.target.tagName!=="A"&&f.target.tagName!=="TEXTAREA"&&Ie(f)}function h(f){Ie(f)}async function p(f){var S,w;if(Ie(f),!((w=(S=f.dataTransfer)==null?void 0:S.files)!=null&&w.length))return;const m=Array.from(f.dataTransfer.files);await e.putExternalContent({type:"files",files:m,point:e.screenToPage({x:f.clientX,y:f.clientY}),ignoreParent:!1})}function y(f){bt(f)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:h,onDrop:p,onTouchStart:u,onTouchEnd:d,onClick:y}},[e])}function e4(){const e=K();b.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 bP=b.createContext(null);function t4({container:e,children:n}){return g.jsx(bP.Provider,{value:e,children:n})}function tn(){return r5(b.useContext(bP),"useContainer used outside of <Tldraw />")}function n4(){const e=K(),n=tn(),t=Y("isFocused",()=>e.getInstanceState().isFocused,[e]);b.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]),b.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!vl()&&Ie(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Ie(a);return}break}case"Tab":{if(vl()||e.getIsMenuOpen())return;break}case",":{if(!vl()&&(Ie(a),!e.inputs.keys.has("Comma"))){const{x:c,y:u,z:d}=e.inputs.currentScreenPoint;e.inputs.keys.add("Comma");const h={type:"pointer",name:"pointer_down",point:{x:c,y:u,z:d},shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(h);return}break}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(vl()||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=>{var c;if(a.isKilled||(a.isKilled=!0,vl()||e.getIsMenuOpen()))return;if(a.key===","&&((c=document.activeElement)!=null&&c.ELEMENT_NODE&&Ie(a),e.inputs.keys.has(a.code))){const{x:u,y:d,z:h}=e.inputs.currentScreenPoint;e.inputs.keys.delete(a.code);const p={type:"pointer",name:"pointer_up",point:{x:u,y:d,z:h},shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p);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()),Ie(a))}}const i=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ie(a)};return n.addEventListener("touchstart",s,{passive:!1}),n.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ie),document.addEventListener("gesturechange",Ie),document.addEventListener("gestureend",Ie),n.addEventListener("keydown",r),n.addEventListener("keyup",o),()=>{n.removeEventListener("touchstart",s),n.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ie),document.removeEventListener("gesturechange",Ie),document.removeEventListener("gestureend",Ie),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const r4=["input","select","button","textarea"];function vl(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||r4.indexOf(e.tagName.toLowerCase())>-1))}const o4={error:null};class CP extends b.Component{constructor(){super(...arguments);v(this,"state",o4)}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 Sc({children:e,fallback:n,...t}){return n===null?g.jsx(g.Fragment,{children:e}):g.jsx(CP,{fallback:n,...t,children:e})}class s4{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 i4=({shape:e,util:n})=>Gp("Indicator:"+e.type,()=>n.indicator(e)),a4=({editor:e,id:n})=>{const t=Y("shape",()=>new s4(e.store.get(n)),[e,n]),{ShapeIndicatorErrorFallback:r}=Pt();return!t.shape||t.shape.isLocked?null:g.jsx(Sc,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:g.jsx(i4,{shape:t.shape,util:e.getShapeUtil(t.shape)},t.shape.id)})},l4=({id:e,className:n,color:t,opacity:r})=>{const o=K(),s=Y("transform",()=>{const i=o.getShapePageTransform(e);return i?i.toCssString():""},[o,e]);return g.jsx("svg",{className:pe("tl-overlays__item",n),children:g.jsx("g",{className:"tl-shape-indicator",transform:s,stroke:t??"var(--color-selected)",opacity:r,children:g.jsx(a4,{editor:o,id:e})})})},au=b.memo(l4);function c4(){return g.jsx("div",{className:"tl-background"})}function Xa(e,n,t,r,o,s){b.useLayoutEffect(()=>{const i=e.current;if(!i||n===void 0)return;let a=`translate(${n}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),o!==void 0&&(a+=` rotate(${o}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),i.style.transform=a})}const Xt={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>--e*e*e+1,easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1- --e*e*e*e,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-8*--e*e*e*e,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1+--e*e*e*e*e,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e<=0?0:Math.pow(2,10*e-10),easeOutExpo:e=>e>=1?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>e<=0?0:e>=1?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2};class E{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 E(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=E.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 E.Dpr(this,n)}cpr(n){return E.Cpr(this,n)}len2(){return E.Len2(this)}len(){return E.Len(this)}pry(n){return E.Pry(this,n)}per(){const{x:n,y:t}=this;return this.x=t,this.y=-n,this}uni(){return E.Uni(this)}tan(n){return E.Tan(this,n)}dist(n){return E.Dist(this,n)}distanceToLineSegment(n,t){return E.DistanceToLineSegment(n,t,this)}slope(n){return E.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 E.Angle(this,n)}toAngle(){return E.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 E.Equals(this,n)}equalsXY(n,t){return E.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 E.ToFixed(this)}toString(){return E.ToString(E.ToFixed(this))}toJson(){return E.ToJson(this)}toArray(){return E.ToArray(this)}static Add(n,t){return new E(n.x+t.x,n.y+t.y)}static AddXY(n,t,r){return new E(n.x+t,n.y+r)}static Sub(n,t){return new E(n.x-t.x,n.y-t.y)}static SubXY(n,t,r){return new E(n.x-t,n.y-r)}static AddScalar(n,t){return new E(n.x+t,n.y+t)}static SubScalar(n,t){return new E(n.x-t,n.y-t)}static Div(n,t){return new E(n.x/t,n.y/t)}static Mul(n,t){return new E(n.x*t,n.y*t)}static DivV(n,t){return new E(n.x/t.x,n.y/t.y)}static MulV(n,t){return new E(n.x*t.x,n.y*t.y)}static Neg(n){return new E(-n.x,-n.y)}static Per(n){return new E(n.y,-n.x)}static Dist2(n,t){return E.Sub(n,t).len2()}static Abs(n){return new E(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 E(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 E.Dpr(n,t)/E.Len(t)}static Uni(n){return E.Div(n,E.Len(n))}static Tan(n,t){return E.Uni(E.Sub(n,t))}static Min(n,t){return new E(Math.min(n.x,t.x),Math.min(n.y,t.y))}static Max(n,t){return new E(Math.max(n.x,t.x),Math.max(n.y,t.y))}static From({x:n,y:t,z:r=1}){return new E(n,t,r)}static FromArray(n){return new E(n[0],n[1])}static Rot(n,t=0){const r=Math.sin(t),o=Math.cos(t);return new E(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 E(t.x+(o*a-s*i),t.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(n,t,r){return E.Mul(t,E.Sub(r,n).pry(t)).add(n)}static NearestPointOnLineSegment(n,t,r,o=!0){const s=E.Tan(t,n),i=E.Add(n,E.Mul(s,E.Sub(r,n).pry(s)));if(o){if(i.x<Math.min(n.x,t.x))return E.Cast(n.x<t.x?n:t);if(i.x>Math.max(n.x,t.x))return E.Cast(n.x>t.x?n:t);if(i.y<Math.min(n.y,t.y))return E.Cast(n.y<t.y?n:t);if(i.y>Math.max(n.y,t.y))return E.Cast(n.y>t.y?n:t)}return i}static DistanceToLineThroughPoint(n,t,r){return E.Dist(r,E.NearestPointOnLineThroughPoint(n,t,r))}static DistanceToLineSegment(n,t,r,o=!0){return E.Dist(r,E.NearestPointOnLineSegment(n,t,r,o))}static Snap(n,t=1){return new E(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}static Cast(n){return n instanceof E?n:E.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 E.Sub(t,n).mul(r).add(n)}static Med(n,t){return new E((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=E.Len(n);return new E(t*n.x/r,t*n.y/r)}static ScaleWithOrigin(n,t,r){return E.Sub(n,r).mul(t).add(r)}static ToFixed(n,t=2){return new E(+n.x.toFixed(t),+n.y.toFixed(t),+n.z.toFixed(t))}static Nudge(n,t,r){return E.Add(n,E.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 E(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 E(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 E(Math.min(Math.max(n.x,t)),Math.min(Math.max(n.y,t))):new E(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=Xt.easeInQuad(s/(r-1)),a=E.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-u4(i))*.65),o.push(a)}return o}static SnapToGrid(n,t=8){return new E(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}}const u4=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Mt(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,Ae=Te*2,d4=Math.sin;function Hr(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function Wu(e,n=1e10){return e?Math.round(e*n)/n:0}function Ql(e,n,t=1e-6){return Math.abs(e-n)<=t}function wc(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%Ae,e<0?e=e+Ae:e===0&&(e=0),e}function Qp(e,n){return e=_r(e),n=_r(n),e>n&&(n+=Ae),n-e}function h4(e,n){return Ae-Qp(e,n)}function Jl(e,n){const t=(n-e)%Ae;return 2*t%Ae-t}function xy(e){return(Ae+e)%Ae}function Qh(e,n){const t=Ae/n;let r=Math.floor((xy(e)+t/2)/t)*t%Ae;return r<Te&&(r+=Ae),r>Te&&(r-=Ae),r}function PP(e,n){return e===n||Ql(e%(Math.PI/2)-n%(Math.PI/2),0)}function p4(e){return e*Te/180}function f4(e){return e*180/Te}function EP(e,n,t,r){return new E(e+t*Math.cos(r),n+t*Math.sin(r))}function fg(e,n,t){const r=e/2,o=n/2,s=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let y=0;y<t;y++){const f=Ae/t,m=-Ve+y*f,S=r+r*Math.cos(m),w=o+o*Math.sin(m);S<i&&(i=S),w<l&&(l=w),S>a&&(a=S),w>c&&(c=w),s.push(new E(S,w))}const u=a-i,d=c-l,h=e-u,p=n-d;if(h!==0||p!==0)for(let y=0;y<s.length;y++){const f=s[y];f.x=(f.x-i)/u*e,f.y=(f.y-l)/d*n}return s}function Sl(e,n,t,r){return e<r&&t<n}function Sr(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function O1(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function eo(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],E.Dist(e,r)+E.Dist(e,o)===E.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&O1(r,o,e)>0&&(t+=1):o.y<=e.y&&O1(r,o,e)<0&&(t-=1)}return t!==0}function O(e){return+e.toFixed(4)}function Jh(e){return+e.toFixed(2)}const R1=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER,Gu=({brush:e,color:n,opacity:t,className:r})=>{const o=b.useRef(null);Xa(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})})},g4=({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1})=>{const i=b.useRef(null);return Xa(i,Hr(t.x,o.minX+5/n,o.maxX-5/n),Hr(t.y,o.minY+5/n,o.maxY-5/n),1/n,E.Angle(o.center,t)),g.jsxs("svg",{ref:i,className:pe("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})]})},m4=({className:e,zoom:n,point:t,color:r,name:o,chatMessage:s})=>{const i=b.useRef(null);return Xa(i,t==null?void 0:t.x,t==null?void 0:t.y,1/n),t?g.jsxs("div",{ref:i,className:pe("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},D1=b.memo(m4),kv={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 kP(){kv.hardReset()}function y4(){kv.refreshPage()}const v4="https://github.com/tldraw/tldraw/issues/new";function S4(){}const IP=({error:e,editor:n})=>{const t=b.useRef(null),[r,o]=b.useState(!1),[s,i]=b.useState(!1),[a,l]=b.useState(!1),c=e instanceof Error?e.message:String(e),u=e instanceof Error?e.stack:null,d=Y("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[h,p]=b.useState(null);b.useLayoutEffect(()=>{var C;d!==null&&p(d);let w=(C=t.current)==null?void 0:C.parentElement,x=!1;for(;w;){if(w.classList.contains("tl-theme__dark")||w.classList.contains("tl-theme__light")){x=!0;break}w=w.parentElement}if(x){p(null);return}p(window.matchMedia("(prefers-color-scheme: dark)").matches)},[d]),b.useEffect(()=>{if(s){const w=setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(w)}},[s]);const y=()=>{const w=document.createElement("textarea");w.value=u??c,document.body.appendChild(w),w.select(),document.execCommand("copy"),w.remove(),i(!0)},f=()=>{y4()},m=async()=>{kP()},S=new URL(v4);return S.searchParams.set("title",c),S.searchParams.set("labels","bug"),S.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:pe("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(CP,{onError:S4,fallback:()=>null,children:g.jsx(Ev.Provider,{value:n,children:g.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:g.jsx(Av,{})})})}),g.jsx("div",{className:pe("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:m,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:S.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:y,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"})]})]})]})})]})},po=2e3,ep=40,wo=320,ji=[.1,.25,.5,1,2,4,8],wl=.1,ts=8,w4=.5,x4=.1,b4=.2,C4=.005,P4=.05,E4=450,k4=200,by=6,xc=4,I4=32,tp={};for(let e=1;e<=Math.ceil(ts);e++)tp[e+"_dark"]=`hash_pattern_zoom_${e}_dark`,tp[e+"_light"]=`hash_pattern_zoom_${e}_light`;const _4={duration:0,easing:Xt.easeInOutCubic},Vd=.09,j1=[{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}],T4=6e4,_P=3e3,$4=1200,L1={CAMERA_MOVE:-10},M4=64,A4=620,Or=8,O4=20,Li=32,R4=({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:j1.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?Bh(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}`)})}),j1.map(({step:o},s)=>g.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${o})`},`grid-rect-${s}`))]}),D4=({handle:e,isCoarse:n,className:t,zoom:r})=>{const o=(n?20:12)/r,s=(e.type==="create"&&n?3:4)/r;return g.jsxs("g",{className:pe("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})]})},j4=({children:e})=>g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),L4=({shapeId:e})=>g.jsx(au,{className:"tl-user-indicator__hovered",id:e});function lu(e,n=!0){const t=e.length;if(t<2)return"";let r=e[0],o=e[1];if(t===2)return`M${Mt(r)}L${Mt(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${Mt(e[1])}${yn(e[1],e[2])}T${s}${yn(e[t-1],e[0])}${yn(e[0],e[1])}Z`:`M${Mt(e[0])}Q${Mt(e[1])}${yn(e[1],e[2])}${e.length>3?"T":""}${s}L${Mt(e[t-1])}`}const N1=({scribble:e,zoom:n,color:t,opacity:r,className:o})=>e.points.length?g.jsx("svg",{className:o&&pe("tl-overlays__item",o),children:g.jsx("path",{className:"tl-scribble",d:lu(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null,TP=({bounds:e,rotation:n})=>{const t=b.useRef(null);return Xa(t,e.x,e.y,1,n),b.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})},N4=({bounds:e,rotation:n})=>{const t=K(),r=b.useRef(null),o=Y("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Xa(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:pe("tl-selection__fg__outline"),width:O(e.width),height:O(e.height)})})},z4=()=>g.jsx("div",{className:"tl-shape-error-boundary"}),F4=()=>g.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function B4({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 U4({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=Sr(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=Sr(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(b.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 H4=({className:e,line:n,zoom:t})=>g.jsx("svg",{className:pe("tl-overlays__item",e),children:n.type==="points"?g.jsx(B4,{...n,zoom:t}):n.type==="gaps"?g.jsx(U4,{...n,zoom:t}):null}),V4=()=>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"})})]})}),K4=()=>null,$P=b.createContext({});function W4({overrides:e,children:n}){return g.jsx($P.Provider,{value:b.useMemo(()=>({Background:c4,SvgDefs:K4,Brush:Gu,ZoomBrush:Gu,ScreenshotBrush:Gu,CollaboratorBrush:Gu,Cursor:D1,CollaboratorCursor:D1,CollaboratorHint:g4,CollaboratorShapeIndicator:au,Grid:R4,Scribble:N1,SnapLine:H4,Handles:j4,Handle:D4,CollaboratorScribble:N1,ErrorFallback:IP,ShapeErrorFallback:z4,ShapeIndicatorErrorFallback:F4,Spinner:V4,SelectionBackground:TP,SelectionForeground:N4,HoveredShapeIndicator:L4,OnTheCanvas:null,InFrontOfTheCanvas:null,...e}),[e]),children:n})}function Pt(){return b.useContext($P)}const G4=["textarea","input"];function Y4(e){const n=K();b.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(G4.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||n.isIn("select.editing_shape"))return;Ie(o)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[n,e])}function X4(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 z1(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function F1(e,n,t,r=.15){return r===0?X4(e,n,t):e<n?-z1(n-e,t-n,r)+n:e>t?+z1(e-t,t-n,r)+t:e}function q4(e,[n,t],[r,o]){const[[s,i],[a,l]]=e;return[F1(n,s,i,r),F1(t,a,l,o)]}function Z4(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 Q4(e){var n=Z4(e,"string");return typeof n=="symbol"?n:String(n)}function Ut(e,n,t){return n=Q4(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function B1(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?B1(Object(t),!0).forEach(function(r){Ut(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):B1(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const MP={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 U1(e){return e?e[0].toUpperCase()+e.slice(1):""}const J4=["enter","leave"];function e6(e=!1,n){return e&&!J4.includes(n)}function t6(e,n="",t=!1){const r=MP[e],o=r&&r[n]||n;return"on"+U1(e)+U1(o)+(e6(t,o)?"Capture":"")}const n6=["gotpointercapture","lostpointercapture"];function r6(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=n6.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function o6(e,n=""){const t=MP[e],r=t&&t[n]||n;return e+r}function AP(e){return"touches"in e}function s6(e){return AP(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function i6(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 Cy(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 a6(e){return i6(e).map(n=>n.identifier)}function H1(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return Cy(t,r)}const V1=40,K1=800;function OP(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=V1,t*=V1):r===2&&(n*=K1,t*=K1),[n,t]}function l6(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 np(e,...n){return typeof e=="function"?e(...n):e}function c6(){}function u6(...e){return e.length===0?c6:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function W1(e,n){return Object.assign({},n,e||{})}const d6=32;class RP{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?np(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,l6(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,y=t._active&&!t._blocked||t.active;y&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=o[this.ingKey]=t._active,n&&(t.first&&("bounds"in r&&(t._bounds=np(r.bounds,t)),this.setup&&this.setup()),t.movement=h,this.computeOffset()));const[f,m]=t.offset,[[S,w],[x,C]]=t._bounds;t.overflow=[f<S?-1:f>w?1:0,m<x?-1:m>C?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 P=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=q4(t._bounds,t.offset,P),t.delta=Rt.sub(t.offset,p),this.computeMovement(),y&&(!t.last||s>d6)){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 h6([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 p6 extends RP{constructor(...n){super(...n),Ut(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[s6(n)]:r.axisThreshold;t.axis=h6(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 f6=e=>e,G1=.15,DP={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[G1,G1];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||f6},threshold(e){return Rt.toVector(e,0)}},g6=0,cu=st(st({},DP),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=g6){return e},bounds(e={}){if(typeof e=="function")return s=>cu.bounds(e(s));if("current"in e)return()=>e.current;if(typeof HTMLElement=="function"&&e instanceof HTMLElement)return e;const{left:n=-1/0,right:t=1/0,top:r=-1/0,bottom:o=1/0}=e;return[[n,t],[r,o]]}}),uu=typeof window<"u"&&window.document&&window.document.createElement;function jP(){return uu&&"ontouchstart"in window}function m6(){return jP()||uu&&window.navigator.maxTouchPoints>1}function y6(){return uu&&"onpointerdown"in window}function v6(){return uu&&"exitPointerLock"in window.document}function S6(){try{return"constructor"in GestureEvent}catch{return!1}}const rr={isBrowser:uu,gesture:S6(),touch:jP(),touchscreen:m6(),pointer:y6(),pointerLock:v6()},w6=250,x6=180,b6=.5,C6=50,P6=250,E6=10,Y1={mouse:0,touch:0,pen:8};st(st({},cu),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&rr.pointerLock,rr.touch&&t?"touch":this.pointerLock?"mouse":rr.pointer&&!o?"pointer":rr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?w6:void 0,!(!rr.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=b6,distance:n=C6,duration:t=P6}={}){return{velocity:this.transform(Rt.toVector(e)),distance:this.transform(Rt.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return x6;case!1:return 0;default:return e}},axisThreshold(e){return e?st(st({},Y1),e):Y1},keyboardDisplacement(e=E6){return e}});function LP(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 k6=30,I6=100;class _6 extends RP{constructor(...n){super(...n),Ut(this,"ingKey","pinching"),Ut(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)*k6-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=H1(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=Cy(...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=H1(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=Cy(...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=[-OP(n)[1]/I6*r.offset[0],0],Rt.addTo(r._movement,r._delta),LP(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 T6=st(st({},DP),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!rr.touch&&rr.gesture)return"gesture";if(rr.touch&&r)return"touch";if(rr.touchscreen){if(rr.pointer)return"pointer";if(rr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=i=>{const a=W1(np(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=W1(np(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({},cu),{},{mouseOnly:(e=!0)=>e});class $6 extends p6{constructor(...n){super(...n),Ut(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=OP(n),Rt.addTo(t._movement,t._delta),LP(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 M6=cu;st(st({},cu),{},{mouseOnly:(e=!0)=>e});const Iv=new Map,Py=new Map;function A6(e){Iv.set(e.key,e.engine),Py.set(e.key,e.resolver)}const O6={key:"pinch",engine:_6,resolver:T6},R6={key:"wheel",engine:$6,resolver:M6};function D6(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 j6(e,n){if(e==null)return{};var t=D6(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 L6={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=rr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},N6=["target","eventOptions","window","enabled","transform"];function Kd(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]=Kd(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function z6(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=j6(r,N6);if(t.shared=Kd({target:o,eventOptions:s,window:i,enabled:a,transform:l},L6),n){const u=Py.get(n);t[n]=Kd(st({shared:t.shared},c),u)}else for(const u in c){const d=Py.get(u);d&&(t[u]=Kd(st({shared:t.shared},c[u]),d))}return t}class NP{constructor(n,t){Ut(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,s){const i=this._listeners,a=o6(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 F6{constructor(){Ut(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 B6{constructor(n){Ut(this,"gestures",new Set),Ut(this,"_targetEventStore",new NP(this)),Ut(this,"gestureEventStores",{}),Ut(this,"gestureTimeoutStores",{}),Ut(this,"handlers",{}),Ut(this,"config",{}),Ut(this,"pointerIds",new Set),Ut(this,"touchIds",new Set),Ut(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),U6(this,n)}setEventIds(n){if(AP(n))return this.touchIds=new Set(a6(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=z6(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=X1(r,a.eventOptions,!!o);if(a.enabled){const c=Iv.get(i);new c(this,n,i).bind(l)}}const s=X1(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]=u6(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=r6(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function Ni(e,n){e.gestures.add(n),e.gestureEventStores[n]=new NP(e,n),e.gestureTimeoutStores[n]=new F6}function U6(e,n){n.drag&&Ni(e,"drag"),n.wheel&&Ni(e,"wheel"),n.scroll&&Ni(e,"scroll"),n.move&&Ni(e,"move"),n.pinch&&Ni(e,"pinch"),n.hover&&Ni(e,"hover")}const X1=(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:t6(r,o,u);t&&d&&(h+="Passive"),e[h]=e[h]||[],e[h].push(s)},H6=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function V6(e){const n={},t={},r=new Set;for(let o in e)H6.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)||!Iv.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 K6(e,n){const[t,r,o]=V6(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 W6(e,n={},t,r){const o=ne.useMemo(()=>new B6(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 G6(e){return e.forEach(A6),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=K6(t,r||{});return W6(o,i,void 0,s)}}const q1=10,Y6=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function zP(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>q1&&(i=q1*o),r=i/100}else e.shiftKey&&!Y6&&(t=n,n=0);return{x:-t,y:-n,z:-r}}const X6=G6([R6,O6]);let Fi;const q6=e=>Fi===void 0?(Fi=e,!1):e-Fi>120&&e-Fi<160?(Fi=e,!0):(Fi=e,!1);function Z6(e){const n=K(),t=b.useMemo(()=>{let r="not sure";const o=({event:f})=>{if(!n.getInstanceState().isFocused||(r="not sure",q6(Date.now())))return;const m=n.getEditingShapeId();if(m){const C=n.getShape(m);if(C&&n.getShapeUtil(C).canScroll(C)){const k=n.getShapePageBounds(m);if(k!=null&&k.containsPoint(n.inputs.currentPagePoint))return}}Ie(f);const S=zP(f);if(S.x===0&&S.y===0)return;const w=n.getContainer().getBoundingClientRect(),x={type:"wheel",name:"wheel",delta:S,point:new E(f.clientX,f.clientY).sub({x:w.left,y:w.top}),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 E,u=new E,d=f=>{const m=e.current;r="not sure";const{event:S,origin:w,da:x}=f;S instanceof WheelEvent||(S.target===m||m!=null&&m.contains(S.target))&&(u.x=w[0],u.y=w[1],c.x=w[0],c.y=w[1],s=x[0],i=n.getZoomLevel(),n.dispatch({type:"pinch",name:"pinch_start",point:{x:w[0],y:w[1],z:n.getZoomLevel()},delta:{x:0,y:0},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey}))},h=f=>{if(f&&(r="zooming"),r==="zooming")return;const m=Math.abs(l-s),S=E.Dist(c,u);switch(r){case"not sure":{m>24?r="zooming":S>16&&(r="panning");break}case"panning":{m>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:d,onPinchEnd:f=>{const m=e.current,{event:S,origin:w,offset:x}=f;if(S instanceof WheelEvent||!(S.target===m||m!=null&&m.contains(S.target)))return;const C=x[0];r="not sure",requestAnimationFrame(()=>{n.dispatch({type:"pinch",name:"pinch_end",point:{x:w[0],y:w[1],z:C},delta:{x:w[0],y:w[1]},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey})})},onPinch:f=>{const m=e.current,{event:S,origin:w,offset:x,da:C}=f;if(S instanceof WheelEvent||!(S.target===m||m!=null&&m.contains(S.target)))return;const P=f.type==="gesturechange"||f.type==="gestureend";l=C[0];const k=w[0]-u.x,I=w[1]-u.y;switch(u.x=w[0],u.y=w[1],h(P),r){case"zooming":{a=x[0],n.dispatch({type:"pinch",name:"pinch",point:{x:w[0],y:w[1],z:a},delta:{x:k,y:I},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:w[0],y:w[1],z:i},delta:{x:k,y:I},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}}}}},[n,e]);X6(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function gg(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function Q6(e,n){const t=K();return b.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Zh(l.currentTarget);su(c,l);const{shape:u,handle:d}=gg(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_down",...Sn(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}=gg(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...Sn(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Zh(l.currentTarget);iu(c,l);const{shape:u,handle:d}=gg(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_up",...Sn(l)})}}},[t,e,n])}var FP="Expected a function",Z1=NaN,J6="[object Symbol]",eR=/^\s+|\s+$/g,tR=/^[-+]0x[0-9a-f]+$/i,nR=/^0b[01]+$/i,rR=/^0o[0-7]+$/i,oR=parseInt,sR=typeof Ot=="object"&&Ot&&Ot.Object===Object&&Ot,iR=typeof self=="object"&&self&&self.Object===Object&&self,aR=sR||iR||Function("return this")(),lR=Object.prototype,cR=lR.toString,uR=Math.max,dR=Math.min,mg=function(){return aR.Date.now()};function hR(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(FP);n=Q1(n)||0,rp(t)&&(u=!!t.leading,d="maxWait"in t,s=d?uR(Q1(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 y(k){return c=k,a=setTimeout(S,n),u?p(k):i}function f(k){var I=k-l,_=k-c,$=n-I;return d?dR($,s-_):$}function m(k){var I=k-l,_=k-c;return l===void 0||I>=n||I<0||d&&_>=s}function S(){var k=mg();if(m(k))return w(k);a=setTimeout(S,f(k))}function w(k){return a=void 0,h&&r?p(k):(r=o=void 0,i)}function x(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function C(){return a===void 0?i:w(mg())}function P(){var k=mg(),I=m(k);if(r=arguments,o=this,l=k,I){if(a===void 0)return y(l);if(d)return a=setTimeout(S,n),p(l)}return a===void 0&&(a=setTimeout(S,n)),i}return P.cancel=x,P.flush=C,P}function pR(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(FP);return rp(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),hR(e,n,{leading:r,maxWait:n,trailing:o})}function rp(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function fR(e){return!!e&&typeof e=="object"}function gR(e){return typeof e=="symbol"||fR(e)&&cR.call(e)==J6}function Q1(e){if(typeof e=="number")return e;if(gR(e))return Z1;if(rp(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=rp(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(eR,"");var t=nR.test(e);return t||rR.test(e)?oR(e.slice(2),t?2:8):tR.test(e)?Z1:+e}var mR=pR;const yR=Si(mR);function vR(){const e=K();b.useLayoutEffect(()=>{const n=yR(()=>{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){v(this,"x",0);v(this,"y",0);v(this,"w",0);v(this,"h",0);this.x=n,this.y=t,this.w=r,this.h=o}get point(){return new E(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 E(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 E(this.minX,this.minY),new E(this.maxX,this.minY),new E(this.maxX,this.maxY),new E(this.minX,this.maxY)]}get snapPoints(){return[new E(this.minX,this.minY),new E(this.maxX,this.minY),new E(this.maxX,this.maxY),new E(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 E(this.w,this.h)}toFixed(){return this.x=Wu(this.x),this.y=Wu(this.y),this.w=Wu(this.w),this.h=Wu(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 E(this.minX,this.minY);case"top_right":return new E(this.maxX,this.minY);case"bottom_left":return new E(this.minX,this.maxY);case"bottom_right":return new E(this.maxX,this.maxY);case"top":return new E(this.midX,this.minY);case"right":return new E(this.maxX,this.midY);case"bottom":return new E(this.midX,this.maxY);case"left":return new E(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),y=h<0,f=p<0;if(y){const m=u;u=l,l=m}if(f){const m=d;d=c,c=m}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 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 y=(h-u)/(l-i),f=(p-d)/(c-a),m=y<0,S=f<0;if(s){const x=(l-i)/(c-a),C=Math.abs(h-u),P=Math.abs(p-d),k=C*(f<0?1:-1)*(1/x),I=P*(y<0?1:-1)*x,_=x<C/P;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 $=(u+h)/2,T=P*x;u=$-T/2,h=$+T/2;break}case"left":case"right":{const $=(d+p)/2,T=C/x;d=$-T/2,p=$+T/2;break}}}if(m){const x=h;h=u,u=x}if(S){const x=p;p=d,d=x}const w=new Qe(u,d,Math.abs(h-u),Math.abs(p-d));return{box:w,scaleX:+(w.width/n.width*(y>0?1:-1)).toFixed(5),scaleY:+(w.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))}};v(Qe,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),v(Qe,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),v(Qe,"Includes",(n,t)=>Qe.Collides(n,t)||Qe.Contains(n,t)),v(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)),v(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)}),v(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 le=Qe;function SR(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 wR(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 xR(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){v(this,"a",1);v(this,"b",0);v(this,"c",0);v(this,"d",1);v(this,"e",0);v(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 E(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 xy(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:xy(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 E(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 E(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 le(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)}};v(_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;function bR(e=!0){const[n,t]=b.useState(0),r=K();b.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const CR=Re(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=K();bR(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),y=u.distanceToPoint(h,!0),f=Math.abs(y)*s,m=y<0,{vertices:S}=u;return g.jsxs("g",{transform:d.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&g.jsx("path",{stroke:"red",strokeWidth:"2",fill:"none",opacity:"1",d:u.toSimpleSvgPath()}),t&&S.map((w,x)=>g.jsx("circle",{cx:w.x,cy:w.y,r:"2",fill:`hsl(${Bh(x,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:"1"},`v${x}`)),r&&f<150&&g.jsx("line",{x1:p.x,y1:p.y,x2:h.x,y2:h.y,opacity:1-f/150,stroke:m?"goldenrod":"dodgerblue",strokeWidth:"2"})]},l.id+"_outline")})})});var PR=200,_v="__lodash_hash_undefined__",ER=1/0,kR="[object Function]",IR="[object GeneratorFunction]",_R=/[\\^$.*+?()[\]{}|]/g,TR=/^\[object .+?Constructor\]$/,$R=typeof Ot=="object"&&Ot&&Ot.Object===Object&&Ot,MR=typeof self=="object"&&self&&self.Object===Object&&self,Tv=$R||MR||Function("return this")();function AR(e,n){var t=e?e.length:0;return!!t&&DR(e,n,0)>-1}function OR(e,n,t){for(var r=-1,o=e?e.length:0;++r<o;)if(t(n,e[r]))return!0;return!1}function RR(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 DR(e,n,t){if(n!==n)return RR(e,jR,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function jR(e){return e!==e}function LR(e,n){return e.has(n)}function NR(e,n){return e==null?void 0:e[n]}function zR(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function BP(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var FR=Array.prototype,BR=Function.prototype,UP=Object.prototype,yg=Tv["__core-js_shared__"],J1=function(){var e=/[^.]+$/.exec(yg&&yg.keys&&yg.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),HP=BR.toString,$v=UP.hasOwnProperty,UR=UP.toString,HR=RegExp("^"+HP.call($v).replace(_R,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),VR=FR.splice,KR=Mv(Tv,"Map"),vg=Mv(Tv,"Set"),bc=Mv(Object,"create");function ci(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 WR(){this.__data__=bc?bc(null):{}}function GR(e){return this.has(e)&&delete this.__data__[e]}function YR(e){var n=this.__data__;if(bc){var t=n[e];return t===_v?void 0:t}return $v.call(n,e)?n[e]:void 0}function XR(e){var n=this.__data__;return bc?n[e]!==void 0:$v.call(n,e)}function qR(e,n){var t=this.__data__;return t[e]=bc&&n===void 0?_v:n,this}ci.prototype.clear=WR;ci.prototype.delete=GR;ci.prototype.get=YR;ci.prototype.has=XR;ci.prototype.set=qR;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 ZR(){this.__data__=[]}function QR(e){var n=this.__data__,t=Jp(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():VR.call(n,t,1),!0}function JR(e){var n=this.__data__,t=Jp(n,e);return t<0?void 0:n[t][1]}function eD(e){return Jp(this.__data__,e)>-1}function tD(e,n){var t=this.__data__,r=Jp(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}qa.prototype.clear=ZR;qa.prototype.delete=QR;qa.prototype.get=JR;qa.prototype.has=eD;qa.prototype.set=tD;function Za(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 nD(){this.__data__={hash:new ci,map:new(KR||qa),string:new ci}}function rD(e){return ef(this,e).delete(e)}function oD(e){return ef(this,e).get(e)}function sD(e){return ef(this,e).has(e)}function iD(e,n){return ef(this,e).set(e,n),this}Za.prototype.clear=nD;Za.prototype.delete=rD;Za.prototype.get=oD;Za.prototype.has=sD;Za.prototype.set=iD;function op(e){var n=-1,t=e?e.length:0;for(this.__data__=new Za;++n<t;)this.add(e[n])}function aD(e){return this.__data__.set(e,_v),this}function lD(e){return this.__data__.has(e)}op.prototype.add=op.prototype.push=aD;op.prototype.has=lD;function Jp(e,n){for(var t=e.length;t--;)if(mD(e[t][0],n))return t;return-1}function cD(e){if(!VP(e)||pD(e))return!1;var n=yD(e)||zR(e)?HR:TR;return n.test(fD(e))}function uD(e,n,t){var r=-1,o=AR,s=e.length,i=!0,a=[],l=a;if(t)i=!1,o=OR;else if(s>=PR){var c=n?null:dD(e);if(c)return BP(c);i=!1,o=LR,l=new op}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 dD=vg&&1/BP(new vg([,-0]))[1]==ER?function(e){return new vg(e)}:vD;function ef(e,n){var t=e.__data__;return hD(n)?t[typeof n=="string"?"string":"hash"]:t.map}function Mv(e,n){var t=NR(e,n);return cD(t)?t:void 0}function hD(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function pD(e){return!!J1&&J1 in e}function fD(e){if(e!=null){try{return HP.call(e)}catch{}try{return e+""}catch{}}return""}function gD(e){return e&&e.length?uD(e):[]}function mD(e,n){return e===n||e!==e&&n!==n}function yD(e){var n=VP(e)?UR.call(e):"";return n==kR||n==IR}function VP(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function vD(){}var SD=gD;const wD=Si(SD);function KP(e){return wD(e)}function xD(){const e=K(),n=b.useMemo(()=>e.store.query.records("instance_presence",()=>({userId:{neq:e.user.getId()}})),[e]),t=rP("userIds",()=>KP(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 Y(t)}function WP(e){const n=K(),t=b.useMemo(()=>n.store.query.records("instance_presence",()=>({userId:{eq:e}})),[n,e]);return Y(`latestPresence:${e}`,()=>t.get().slice().sort((o,s)=>s.lastActivityTimestamp-o.lastActivityTimestamp)[0],[])??null}const bD=Re(function(){const n=xD();return g.jsx(g.Fragment,{children:n.map(t=>g.jsx(CD,{collaboratorId:t},t))})}),CD=Re(function({collaboratorId:n}){const t=K(),r=WP(n),o=ED(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(PD,{latestPresence:r})}),PD=Re(function({latestPresence:n}){const t=K(),{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:y,userName:f,cursor:m,color:S}=n,w=!(m.x<c.minX-12/l||m.y<c.minY-16/l||m.x>c.maxX-12/l||m.y>c.maxY-16/l);return g.jsxs(g.Fragment,{children:[h&&r?g.jsx(r,{className:"tl-collaborator__brush",brush:h,color:S,opacity:.1},u+"_brush"):null,w&&s?g.jsx(s,{className:"tl-collaborator__cursor",point:m,color:S,zoom:l,name:f!=="New User"?f:null,chatMessage:d},u+"_cursor"):i?g.jsx(i,{className:"tl-collaborator__cursor-hint",point:m,color:S,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&p.length?g.jsx(g.Fragment,{children:p.map(x=>g.jsx(o,{className:"tl-collaborator__scribble",scribble:x,color:S,zoom:l,opacity:x.color==="laser"?.5:.1},u+"_scribble_"+x.id))}):null,a&&y.map(x=>g.jsx(a,{className:"tl-collaborator__shape-indicator",id:x,color:S,opacity:.5},u+"_"+x))]})});function ex(e){return e>T4?"inactive":e>_P?"idle":"active"}function ED(e){const n=b.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[t,r]=b.useState(()=>ex(Date.now()-n.current));return b.useEffect(()=>{const o=setInterval(()=>{r(ex(Date.now()-n.current))},$4);return()=>clearInterval(o)},[]),e&&(n.current=e.lastActivityTimestamp),t}function GP(e,n){return n===0?e:GP(n,e%n)}function YP(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/GP(r,t)}function kD(){const e=K(),n=tn();b.useEffect(()=>nu("useDPRMultiple",()=>{const t=e.getInstanceState().devicePixelRatio;n.style.setProperty("--tl-dpr-multiple",YP(t).toString())}),[e,n])}const XP=Re(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,isCulled:a}){const l=K(),{ShapeErrorFallback:c}=Pt(),u=b.useRef(null),d=b.useRef(null),h=b.useCallback((y,f)=>{var m,S;(m=u.current)==null||m.style.setProperty(y,f),(S=d.current)==null||S.style.setProperty(y,f)},[]);ri("set shape container transform position",()=>{if(!l.getShape(n))return;const f=l.getShapePageTransform(n),m=te.toCssString(f);h("transform",m)},[l,h]),ri("set shape container clip path",()=>{if(!l.getShape(n))return null;const f=l.getShapeClipPath(n);h("clip-path",f??"none")},[l,h]),ri("set shape height and width",()=>{const y=l.getShape(n);if(!y)return null;const f=l.getShapeGeometry(y).bounds,m=Math.floor(l.getInstanceState().devicePixelRatio*100)/100,S=YP(m),w=f.w%S,x=w===0?f.w:f.w+(S-w),C=f.h%S,P=C===0?f.h:f.h+(S-C);h("width",Math.max(x,S)+"px"),h("height",Math.max(P,S)+"px")},[l]),b.useLayoutEffect(()=>{var y,f;h("opacity",i+""),(y=u.current)==null||y.style.setProperty("z-index",o+""),(f=d.current)==null||f.style.setProperty("z-index",s+"")},[i,o,s,h]);const p=b.useCallback(y=>{l.annotateError(y,{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(Sc,{fallback:c,onError:p,children:g.jsx(_D,{shape:t,util:r})})}),g.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,draggable:!1,children:a?g.jsx(TD,{shape:t}):g.jsx(Sc,{fallback:c,onError:p,children:g.jsx(ID,{shape:t,util:r})})})]}):null}),ID=b.memo(function({shape:n,util:t}){return Gp("InnerShape:"+n.type,()=>t.component(n))},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta&&e.util===n.util),_D=b.memo(function({shape:n,util:t}){return Gp("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),TD=b.memo(function({shape:n}){const r=K().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 Av({className:e}){const n=K(),{Background:t,SvgDefs:r}=Pt(),o=ne.useRef(null),s=ne.useRef(null),i=ne.useRef(null);vR(),n4(),e4(),Z6(o),Y4(o),ri("position layers",()=>{const h=s.current;if(!h)return;const p=i.current;if(!p)return;const{x:y,y:f,z:m}=n.getCamera(),S=m>=1?Bh(m,[1,8],[.125,.5],!0):Bh(m,[.1,1],[-2,.125],!0),w=`scale(${O(m)}) translate(${O(y+S)}px,${O(f+S)}px)`;h.style.setProperty("transform",w),p.style.setProperty("transform",w)},[n]);const a=JO(),l=Y("shapeSvgDefs",()=>{const h=new Map;for(const p of dt(n.shapeUtils)){if(!p)return;const y=p.getCanvasSvgDefs();for(const{key:f,component:m}of y)h.has(f)||h.set(f,g.jsx(m,{},f))}return[...h.values()]},[n]),c=Y("debug_shapes",()=>He.hideShapes.get(),[He]),u=Y("debug_svg",()=>He.debugSvg.get(),[He]),d=Y("debug_geometry",()=>He.debugGeometry.get(),[He]);return g.jsxs("div",{ref:o,draggable:!1,className:pe("tl-canvas",e),"data-testid":"canvas",...a,children:[t&&g.jsx(t,{}),g.jsx($D,{}),g.jsx(GD,{}),g.jsx("svg",{className:"tl-svg-context",children:g.jsxs("defs",{children:[l,tx&&g.jsx(tx,{}),g.jsx(HD,{}),g.jsx(VD,{}),g.jsx(KD,{}),r&&g.jsx(r,{})]})}),g.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[g.jsx(qD,{}),g.jsx(XD,{}),c?null:u?g.jsx(ND,{}):g.jsx(zD,{})]}),g.jsxs("div",{className:"tl-fixed-layer tl-overlays",children:[g.jsxs("div",{ref:i,className:"tl-html-layer",children:[d?g.jsx(CR,{}):null,g.jsx(jD,{}),g.jsx(AD,{}),g.jsx(MD,{}),g.jsx(OD,{}),g.jsx(FD,{}),g.jsx(BD,{}),g.jsx(UD,{}),g.jsx(RD,{}),g.jsx(YD,{}),g.jsx(bD,{})]}),g.jsx(ZD,{})]})]})}function $D(){const e=K(),n=Y("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=Y("camera",()=>e.getCamera(),[e]),s=Y("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=Pt();return i&&s?g.jsx(i,{x:t,y:r,z:o,size:n}):null}function MD(){const e=K(),n=Y("scribbles",()=>e.getInstanceState().scribbles,[e]),t=Y("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 AD(){const e=K(),n=Y("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=Pt();return t&&n?g.jsx(t,{className:"tl-user-brush",brush:n}):null}function OD(){const e=K(),n=Y("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 RD(){const e=K(),n=Y("snapLines",()=>e.snaps.getLines(),[e]),t=Y("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}const DD=48;function jD(){const e=K(),{Handles:n}=Pt(),t=Y("zoomLevel",()=>e.getZoomLevel(),[e]),r=Y("coarse pointer",()=>e.getInstanceState().isCoarsePointer,[e]),o=Y("onlySelectedShape",()=>e.getOnlySelectedShape(),[e]),s=Y("isChangingStyle",()=>e.getInstanceState().isChangingStyle,[e]),i=Y("isChangingStyle",()=>e.getInstanceState().isReadonly,[e]),a=Y("handles",()=>{const u=e.getOnlySelectedShape();if(u)return e.getShapeHandles(u)},[e]),l=Y("transform",()=>{const u=e.getOnlySelectedShape();if(u)return e.getShapePageTransform(u)},[e]);if(!n||!o||s||i||!a||!l)return null;const c=[];for(let u=0,d=a[u];u<a.length;u++,d=a[u]){if(d.type!=="vertex"){const h=a[u-1],p=a[u+1];if(h&&p&&Math.hypot(h.y-p.y,h.x-p.x)<DD/t)continue}c.push(d)}return c.sort(u=>u.type==="vertex"?1:-1),g.jsx(n,{children:g.jsx("g",{transform:te.toCssString(l),children:c.map(u=>g.jsx(LD,{shapeId:o.id,handle:u,zoom:t,isCoarse:r},u.id))})})}function LD({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=Q6(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 ND(){const e=K(),n=Y("rendering shapes",()=>e.getRenderingShapes(),[e]);return g.jsx(g.Fragment,{children:n.map(t=>g.jsxs(ne.Fragment,{children:[g.jsx(XP,{...t}),g.jsx(WD,{id:t.id})]},t.id+"_fragment"))})}function zD(){const e=K(),n=Y("rendering shapes",()=>e.getRenderingShapes(),[e]);return g.jsx(g.Fragment,{children:n.map(t=>g.jsx(XP,{...t},t.id+"_shape"))})}function FD(){const e=K(),n=Y("selectedShapeIds",()=>e.getCurrentPageState().selectedShapeIds,[e]);return Y("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(au,{className:"tl-user-indicator__selected",id:r},r+"_indicator"))}):null}const BD=function(){const n=K(),{HoveredShapeIndicator:t}=Pt(),r=Y("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),o=Y("hovering canvas",()=>n.getInstanceState().isHoveringCanvas,[n]),s=Y("hovered id",()=>n.getCurrentPageState().hoveredShapeId,[n]);return r||!o||!s||!t?null:g.jsx(t,{shapeId:s})},UD=Re(function(){const n=K(),t=Fh(n.getHintingShapeIds());return t.length?g.jsx(g.Fragment,{children:t.map(r=>g.jsx(au,{className:"tl-user-indicator__hint",id:r},r+"_hinting"))}):null});function tx(){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 HD(){return g.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function VD(){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 KD(){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 WD=Re(function({id:n}){const t=K(),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=nu("shape to svg",async()=>{const c=Math.random();a=c;const u=t.getShapePageBounds(n),d=await t.getSvg([n],{padding:0});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 GD(){const e=Y("debugging ui log",()=>He.logMessages.get(),[He]);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 YD(){const e=K(),n=Y("selection rotation",()=>e.getSelectionRotation(),[e]),t=Y("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=Pt();return!t||!r?null:g.jsx(r,{bounds:t,rotation:n})}function XD(){const e=K(),n=Y("selection rotation",()=>e.getSelectionRotation(),[e]),t=Y("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=Pt();return!t||!r?null:g.jsx(r,{bounds:t,rotation:n})}function qD(){const{OnTheCanvas:e}=Pt();return e?g.jsx(e,{}):null}function ZD(){const{InFrontOfTheCanvas:e}=Pt();return e?g.jsx(e,{}):null}const QD=()=>g.jsx(wE,{children:"Connecting..."});function Ne(){return Xp()}const qP="TLDRAW_USER_DATA_v3",ZP=Pe({id:me,name:me.nullable().optional(),locale:me.nullable().optional(),color:me.nullable().optional(),isDarkMode:we.nullable().optional(),animationSpeed:fe.nullable().optional(),edgeScrollSpeed:fe.nullable().optional(),isSnapMode:we.nullable().optional()}),xl={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4},sp=$e({currentVersion:xl.AddEdgeScrollSpeed,migrators:{[xl.AddAnimationSpeed]:{up:e=>({...e,animationSpeed:1}),down:({animationSpeed:e,...n})=>n},[xl.AddIsSnapMode]:{up:e=>({...e,isSnapMode:!1}),down:({isSnapMode:e,...n})=>n},[xl.MakeFieldsNullable]:{up:e=>e,down:e=>({id:e.id,name:e.name??or.name,locale:e.locale??or.locale,color:e.color??or.color,isDarkMode:e.isDarkMode??or.isDarkMode,animationSpeed:e.animationSpeed??or.animationSpeed,isSnapMode:e.isSnapMode??or.isSnapMode})},[xl.AddEdgeScrollSpeed]:{up:e=>({...e,edgeScrollSpeed:1}),down:({edgeScrollSpeed:e,...n})=>n}}}),nx=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function JD(){return nx[Math.floor(Math.random()*nx.length)]}function e8(){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 t8(){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 or=Object.freeze({name:"New User",locale:KO(),color:JD(),isDarkMode:!1,edgeScrollSpeed:1,animationSpeed:t8()?0:1,isSnapMode:!1});function Yu(){return{id:Ne()}}function QP(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return Yu();const n=mv({value:e.user,fromVersion:e.version,toVersion:sp.currentVersion??0,migrations:sp});if(n.type==="error")return Yu();try{ZP.validate(n.value)}catch{return Yu()}return n.value}function n8(){var n;const e=typeof window>"u"?null:JSON.parse(((n=window==null?void 0:window.localStorage)==null?void 0:n.getItem(qP))||"null")??null;return QP(e)}const du=an("globalUserData",n8());function r8(){typeof window<"u"&&window.localStorage&&window.localStorage.setItem(qP,JSON.stringify({version:sp.currentVersion,user:du.get()}))}function o8(e){ZP.validate(e),du.set(e),r8(),i8()}const s8=typeof process<"u"&&!1,wa=typeof BroadcastChannel<"u"&&!s8?new BroadcastChannel("tldraw-user-sync"):null;wa==null||wa.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===eE&&(n==null?void 0:n.origin)!==JP&&du.set(QP(n.data))});const JP=Ne(),eE="tldraw-user-preferences-change";function i8(){wa==null||wa.postMessage({type:eE,origin:JP,data:{user:du.get(),version:sp.currentVersion}})}function a8(){return du.get()}function tE(e={}){return{derivePresenceState:e.derivePresenceState??(()=>Z("presence",()=>null)),userPreferences:e.userPreferences??Z("userPreferences",()=>a8()),setUserPreferences:e.setUserPreferences??o8}}var nE={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),y=t?t+c:c;return l._events[y]?l._events[y].fn?l._events[y]=[l._events[y],p]:l._events[y].push(p):(l._events[y]=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,y=new Array(p);h<p;h++)y[h]=d[h].fn;return y},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,y){var f=t?t+c:c;if(!this._events[f])return!1;var m=this._events[f],S=arguments.length,w,x;if(m.fn){switch(m.once&&this.removeListener(c,m.fn,void 0,!0),S){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,u),!0;case 3:return m.fn.call(m.context,u,d),!0;case 4:return m.fn.call(m.context,u,d,h),!0;case 5:return m.fn.call(m.context,u,d,h,p),!0;case 6:return m.fn.call(m.context,u,d,h,p,y),!0}for(x=1,w=new Array(S-1);x<S;x++)w[x-1]=arguments[x];m.fn.apply(m.context,w)}else{var C=m.length,P;for(x=0;x<C;x++)switch(m[x].once&&this.removeListener(c,m[x].fn,void 0,!0),S){case 1:m[x].fn.call(m[x].context);break;case 2:m[x].fn.call(m[x].context,u);break;case 3:m[x].fn.call(m[x].context,u,d);break;case 4:m[x].fn.call(m[x].context,u,d,h);break;default:if(!w)for(P=1,w=new Array(S-1);P<S;P++)w[P-1]=arguments[P];m[x].fn.apply(m[x].context,w)}}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 y=this._events[p];if(y.fn)y.fn===u&&(!h||y.once)&&(!d||y.context===d)&&i(this,p);else{for(var f=0,m=[],S=y.length;f<S;f++)(y[f].fn!==u||h&&!y[f].once||d&&y[f].context!==d)&&m.push(y[f]);m.length?this._events[p]=m.length===1?m[0]:m: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})(nE);var l8=nE.exports;function jn({children:e,className:n="",...t}){return g.jsx("svg",{...t,className:`tl-svg-container ${n}`,children:e})}class wi{constructor(n){v(this,"isFilled",!1);v(this,"isClosed",!0);v(this,"isLabel",!1);v(this,"isSnappable",!0);v(this,"_vertices");v(this,"_bounds");v(this,"_snapPoints");v(this,"_area");this.isFilled=n.isFilled,this.isClosed=n.isClosed,this.isSnappable=n.isSnappable??!1,this.isLabel=n.isLabel??!1}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)&&eo(n,this.vertices)?-r:r}distanceToLineSegment(n,t){const r=this.nearestPointOnLineSegment(n,t),o=E.DistanceToLineSegment(n,t,r);return this.isClosed&&this.isFilled&&eo(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=E.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 le.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 os extends wi{constructor(t){super({...t,isClosed:!0,isFilled:!1});v(this,"children");const{children:r}=t;if(r.length===0)throw Error("Group2d must have at least one child");this.children=r}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=le.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 Ov(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,y=d/h;if(0<=p&&p<=1&&0<=y&&y<=1)return E.AddXY(e,p*l,p*c)}return null}function tf(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(E.Lrp(e,n,c)),0<=u&&u<=1&&d.push(E.Lrp(e,n,u)),d.length===0?null:d}function rE(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=Ov(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function c8(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=Ov(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function u8(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 E(e.x+o*a-s*l,e.y+s*a+o*l),new E(e.x+o*a+s*l,e.y+s*a-o*l)]}function rx(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=tf(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function ox(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=tf(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function Xu(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function oE(e,n,t,r){return Xu(e,t,r)!==Xu(n,t,r)&&Xu(e,n,t)!==Xu(e,n,r)}function Ey(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],eo(r,n)){const c=Sg(r);t.has(c)||t.set(c,r)}for(let a=0,l=n.length;a<l;a++)if(r=n[a],eo(r,e)){const c=Sg(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=Ov(r,o,s,i);if(d!==null){const h=Sg(d);t.has(h)||t.set(h,d)}}}return t.size===0?null:d8([...t.values()])}function Sg(e){return`${e.x},${e.y}`}function d8(e){const n=E.Average(e);return e.sort((t,r)=>E.Angle(n,t)-E.Angle(n,r))}function h8(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],oE(t,r,o,s))return!0}return!1}class ip extends wi{constructor(t){super({...t,isClosed:!1,isFilled:!1});v(this,"start");v(this,"end");v(this,"d");v(this,"u");v(this,"ul");v(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=E.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 E(l,c)}hitTestLineSegment(t,r,o){return oE(t,r,this.start,this.end)}}class xi extends wi{constructor(t){super({isClosed:!1,isFilled:!1,...t});v(this,"points");v(this,"_segments");v(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 ip({start:s,end:i}))}this.isClosed&&this._segments.push(new ip({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 wt extends xi{constructor(n){super({...n}),this.isClosed=!0}}class xs extends wt{constructor(t){const{x:r=0,y:o=0,width:s,height:i}=t;super({...t,points:[new E(r,o),new E(r+s,o),new E(r+s,o+i),new E(r,o+i)]});v(this,"x");v(this,"y");v(this,"w");v(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new le(this.x,this.y,this.w,this.h)}}class Tr{constructor(n){v(this,"canSnap",()=>!0);v(this,"canScroll",()=>!1);v(this,"canUnmount",()=>!0);v(this,"canBind",(n,t)=>!0);v(this,"canEdit",()=>!1);v(this,"canResize",()=>!0);v(this,"canEditInReadOnly",()=>!1);v(this,"canCrop",()=>!1);v(this,"hideResizeHandles",()=>!1);v(this,"hideRotateHandle",()=>!1);v(this,"hideSelectionBoundsBg",()=>!1);v(this,"hideSelectionBoundsFg",()=>!1);v(this,"isAspectRatioLocked",()=>!1);v(this,"onBeforeCreate");v(this,"onBeforeUpdate");v(this,"onDragShapesOver");v(this,"onDragShapesOut");v(this,"onDropShapesOver");v(this,"onResizeStart");v(this,"onResize");v(this,"onResizeEnd");v(this,"onTranslateStart");v(this,"onTranslate");v(this,"onTranslateEnd");v(this,"onRotateStart");v(this,"onRotate");v(this,"onRotateEnd");v(this,"onHandleChange");v(this,"onBindingChange");v(this,"onChildrenChange");v(this,"onDoubleClickHandle");v(this,"onDoubleClickEdge");v(this,"onDoubleClick");v(this,"onClick");v(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[]}}v(Tr,"props"),v(Tr,"migrations"),v(Tr,"type");function p8(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 sx({bounds:e,className:n}){const t=K(),r=Y("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}=p8(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 Wd extends Tr{constructor(){super(...arguments);v(this,"hideSelectionBoundsFg",()=>!0);v(this,"canBind",()=>!1);v(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 xs({width:1,height:1,isFilled:!1}):new os({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 wt({points:a,isFilled:!0}):new xi({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(jn,{id:t.id,children:g.jsx(sx,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return g.jsx(sx,{className:"",bounds:r})}}v(Wd,"type","group"),v(Wd,"props",_O),v(Wd,"migrations",TO);const sE=[Wd],f8=new Set(sE.map(e=>e.type));function iE(e){const n=[...sE],t=new Set;for(const r of e){if(f8.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 ix(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 Wa(e)}}class g8{constructor(n){v(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(!ix(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!ix(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 ky extends g8{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:Wa(r,"type")}}}class Rv{constructor(){v(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 m8(e,n,t){return fetch(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function y8(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",v8="a0",aE="A00000000000000000000000000";function lE(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 cE(e){if(e.length!==lE(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function ax(e){if(e===void 0)throw Error("n is undefined")}function lx(e){cE(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 S8(e){cE(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 Ji(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)+Ji(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)+Ji(e.slice(1),void 0)}function Kl(e){const n=lE(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function cx(e){if(e===aE)throw new Error("invalid index: "+e);const n=Kl(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function Bi(e,n){if(e!==void 0&&cx(e),n!==void 0&&cx(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return v8;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=Kl(n),l=n.slice(a.length);if(a===aE)return a+Ji("",l);if(a<n)return a;const c=S8(a);return ax(c),c}if(n===void 0){const a=Kl(e),l=e.slice(a.length),c=lx(a);return c===void 0?a+Ji(l,void 0):c}const t=Kl(e),r=e.slice(t.length),o=Kl(n),s=n.slice(o.length);if(t===o)return t+Ji(r,s);const i=lx(t);return ax(i),i<n?i:t+Ji(r,void 0)}function bs(e,n,t){if(t===0)return[];if(t===1)return[Bi(e,n)];if(n===void 0){let s=Bi(e,n);const i=[s];for(let a=0;a<t-1;a++)s=Bi(s,n),i.push(s);return i}if(e===void 0){let s=Bi(e,n);const i=[s];for(let a=0;a<t-1;a++)s=Bi(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=Bi(e,n);return[...bs(e,o,r),o,...bs(o,n,t-r-1)]}function Oa(e,n,t){return bs(e,n,t)}function wg(e,n){return bs(e,void 0,n)}function ec(e,n){return bs(e,n,1)[0]}function yo(e){return bs(e,void 0,1)[0]}function w8(e){return bs(void 0,e,1)[0]}function uE(e,n="a1"){return[n,...bs(n,void 0,e)]}function Kt(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function qu(e,n,t){if(t.length===0)return[];const r=new Map;for(const s of he(t.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:he(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})=>x8(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>b8(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>C8(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>P8(s,i,o));break}}return o}function x8(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=Oa(o,s,e.size);t.push(...Array.from(e.values()).sort(Kt).map((a,l)=>({...a,index:i[l]})))}}function b8(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=Oa(o,s,e.size);t.push(...Array.from(e.values()).sort(Kt).map((a,l)=>({...a,index:i[l]})))}}function C8(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;Oa(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 P8(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;Oa((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 dE({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:ds(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function Gd({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:l})=>{const c=tr(a.parentId)?n.getShapePageTransform(a.parentId):te.Identity(),u=E.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 y=(d=c.onRotateStart)==null?void 0:d.call(c,a);y&&i.push(y)}const u=(h=c.onRotate)==null?void 0:h.call(c,a,l);if(u&&i.push(u),r==="end"||r==="one-off"){const y=(p=c.onRotateEnd)==null?void 0:p.call(c,a,l);y&&i.push(y)}}),i.length>0&&n.updateShapes(i)}const E8=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(Sa(s))return o();const a=s,l=t.getDiffSince(i);if(l===Bn)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,y,f){u(p),c[p]=c[p].filter(m=>m.arrowId!==y||m.handleId!==f),c[p].length===0&&delete c[p]}function h(p,y,f){u(p),c[p].push({arrowId:y,handleId:f})}for(const p of l){for(const y of Object.values(p.added))if(e.isShapeOfType(y,"arrow")){const{start:f,end:m}=y.props;f.type==="binding"&&h(f.boundShapeId,y.id,"start"),m.type==="binding"&&h(m.boundShapeId,y.id,"end")}for(const[y,f]of Object.values(p.updated))if(!(!e.isShapeOfType(y,"arrow")||!e.isShapeOfType(f,"arrow")))for(const m of["start","end"]){const S=y.props[m],w=f.props[m];S.type==="binding"&&w.type==="point"?d(S.boundShapeId,y.id,m):S.type==="point"&&w.type==="binding"?h(w.boundShapeId,f.id,m):S.type==="binding"&&w.type==="binding"&&S.boundShapeId!==w.boundShapeId&&(d(S.boundShapeId,y.id,m),h(w.boundShapeId,f.id,m))}for(const y of Object.values(p.removed))if(e.isShapeOfType(y,"arrow")){const{start:f,end:m}=y.props;f.type==="binding"&&d(f.boundShapeId,y.id,"start"),m.type==="binding"&&d(m.boundShapeId,y.id,"end")}}return c??a})},k8=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(Kt),s.forEach(i=>{r[i.parentId]||(r[i.parentId]=[]),r[i.parentId].push(i.id)}),r}return Z("parentsToChildrenWithIndexes",(r,o)=>{if(Sa(r))return t();const s=e.history.getDiffSince(o);if(s===Bn)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))Qs(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(Qs(p)&&Qs(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 y=i[p.parentId].indexOf(p.id);i[p.parentId][y]=p.id,l.add(i[p.parentId])}}for(const h of Object.values(c.removed))Qs(h)&&(a(h.parentId),i[h.parentId].splice(i[h.parentId].indexOf(h.id),1))}for(const u of l){const d=he(u.map(h=>e.get(h)));d.sort(Kt),u.splice(0,u.length,...d.map(h=>h.id))}return i??r})},xg=(e,n,t)=>{for(;!gn(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},I8=(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=>xg(e,s,e.get(i))))}return Z("_shapeIdsInCurrentPage",(s,i)=>{if(Sa(s))return o();const a=n();if(a!==r)return o();const l=e.history.getDiffSince(i);if(l===Bn)return o();const c=new Ud(s);for(const d of l){for(const h of Object.values(d.added))Qs(h)&&xg(e,a,h)&&c.add(h.id);for(const[h,p]of Object.values(d.updated))Qs(p)&&(xg(e,a,p)?c.add(p.id):c.remove(p.id));for(const h of Object.keys(d.removed))tr(h)&&c.remove(h)}const u=c.get();return u?Hl(u.value,u.diff):s})},_8=40;class T8{constructor(n){v(this,"_clickId","");v(this,"_clickTimeout");v(this,"_clickScreenPoint");v(this,"_previousScreenPoint");v(this,"_getClickTimeout",(n,t=Ne())=>{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"?E4:k4)});v(this,"_clickState","idle");v(this,"lastPointerInfo",{});v(this,"transformPointerDownEvent",n=>{if(!this._clickState)return n;switch(this._clickScreenPoint=E.From(n.point),this._previousScreenPoint&&this._previousScreenPoint.dist(this._clickScreenPoint)>_8&&(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}});v(this,"transformPointerUpEvent",n=>{if(!this._clickState)return n;switch(this._clickScreenPoint=E.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}});v(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});v(this,"handleMove",()=>{this._clickState!=="idle"&&this._clickScreenPoint&&this._clickScreenPoint.dist(this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?by:xc)&&this.cancelDoubleClickTimeout()});this.editor=n}get clickState(){return this._clickState}}class $8{constructor(n){v(this,"isSafari");v(this,"isIos");v(this,"isChromeForIos");v(this,"isFirefox");v(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 Ws(e){if(e){let n=ux;for(;e.length;)n=n.push(e.pop());return n}return ux}class M8{constructor(){v(this,"length",0);v(this,"head",null);v(this,"tail",this)}push(n){return new Dv(n,this)}toArray(){return Po}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const ux=new M8;class Dv{constructor(n,t){v(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Dv(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 A8{constructor(n,t){v(this,"_undos",an("HistoryManager.undos",Ws()));v(this,"_redos",an("HistoryManager.redos",Ws()));v(this,"_batchDepth",0);v(this,"onBatchComplete",()=>{});v(this,"_commands",{});v(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:Ne(),data:r.squash(d.data,a)})):this._undos.update(h=>h.push({type:"command",name:n,data:a,id:Ne(),preservesRedoStack:u})),i.preservesRedoStack||this._redos.set(Ws()),this.ctx.emit("change-history",{reason:"push"})}return this.ctx};return o});v(this,"batch",n=>{try{this._batchDepth++,this._batchDepth===1?nr(()=>{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});v(this,"ignoringUpdates",n=>{let t=this._undos.get(),r=this._redos.get();this._undos.set(Ws()),this._redos.set(Ws());try{({undos:t,redos:r}=nr(()=>n(t,r)))}finally{this._undos.set(t),this._redos.set(r)}});v(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));v(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));v(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));v(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));v(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));v(this,"mark",(n=Ne(),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(Ws()),this._redos.set(Ws())}}class O8{constructor(n){v(this,"scribbleItems",new Map);v(this,"state","paused");v(this,"addScribble",(n,t=Ne())=>{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});v(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});v(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||E.Dist(s,i)>=1)&&(o.next=i),o});v(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 R8{constructor(n){v(this,"_beforeCreateHandlers",{});v(this,"_afterCreateHandlers",{});v(this,"_beforeChangeHandlers",{});v(this,"_afterChangeHandlers",{});v(this,"_beforeDeleteHandlers",{});v(this,"_afterDeleteHandlers",{});v(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),()=>Gs(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>Gs(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>Gs(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>Gs(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>Gs(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>Gs(this._afterDeleteHandlers[n],t)}registerBatchCompleteHandler(n){return this._batchCompleteHandlers.push(n),()=>Gs(this._batchCompleteHandlers,n)}}function Gs(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}var D8=Object.defineProperty,j8=Object.getOwnPropertyDescriptor,bi=(e,n,t,r)=>{for(var o=r>1?void 0:r?j8(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&&D8(n,t,o),o};const de=e=>Math.round(e*10**8)/10**8;function fo(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)&&Sr(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=fo(e,l,t,r,Sr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function L8(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 Ms{constructor(n){v(this,"_snapLines",an("snapLines",void 0));this.editor=n}getLines(){return this._snapLines.get()??Po}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=>{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&&Sl(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&n.push({startNode:r,endNode:o,startEdge:[new E(r.pageBounds.maxX,r.pageBounds.minY),new E(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new E(o.pageBounds.minX,o.pageBounds.minY),new E(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Sr(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&&Sl(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&t.push({startNode:r,endNode:o,startEdge:[new E(r.pageBounds.minX,r.pageBounds.maxY),new E(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new E(o.pageBounds.minX,o.pageBounds.minY),new E(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Sr(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 m,S;const s=this.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(o),l=r.map(({x:w,y:x},C)=>({id:"selection:"+C,x:w+o.x,y:x+o.y})),c=i,u=[],d=[],h=new E(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 E(n==="x"?0:((m=u[0])==null?void 0:m.nudge)??0,n==="y"?0:((S=d[0])==null?void 0:S.nudge)??0);h.x=0,h.y=0,u.length=0,d.length=0,l.forEach(w=>{w.x+=p.x,w.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 y=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:d}),f=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d});return this._snapLines.set([...f,...y]),{nudge:p}}getOutlinesInPageSpace(){return this.getSnappableShapes().map(({id:n,isClosed:t})=>{const r=qt(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=E.NearestPointOnLineSegment(a,l,n),u=E.Dist(n,c),!isNaN(u)&&u<s&&(s=u,i=c);return i?(this._snapLines.set([{id:Ne(),type:"points",points:[i]}]),E.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}=le.Resize(n,r,s?t.x*2:t.x,s?t.y*2:t.y,o);let u=r;l<0&&(u=wR(u)),c<0&&(u=SR(u)),s&&(a.center=n.center);const d=u==="top"||u==="bottom",h=u==="left"||u==="right",p=dx(u,a),y=this.getSnappablePoints(),f=[],m=[],S=new E(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:f,nearestSnapsY:m,otherNodeSnapPoints:y,selectionSnapPoints:p});const w=new E(d?0:((I=f[0])==null?void 0:I.nudge)??0,h?0:((_=m[0])==null?void 0:_.nudge)??0);if(o&&xR(u)&&w.len()!==0){const $=f.length&&m.length?Math.abs(w.x)<Math.abs(w.y)?"x":"y":f.length?"x":"y",T=n.aspectRatio;$==="x"?(m.length=0,w.y=w.x/T,(u==="bottom_left"||u==="top_right")&&(w.y=-w.y)):(f.length=0,w.x=w.y*T,(u==="bottom_left"||u==="top_right")&&(w.x=-w.x))}const x=E.Add(t,w),{box:C}=le.Resize(n,r,s?x.x*2:x.x,s?x.y*2:x.y,o);s&&(C.center=n.center);const P=dx("any",C);f.length=0,m.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:f,nearestSnapsY:m,otherNodeSnapPoints:y,selectionSnapPoints:P});const k=this.getPointSnapLines({nearestSnapsX:f,nearestSnapsY:m});return this._snapLines.set([...k]),{nudge:w}}collectPointSnaps({selectionSnapPoints:n,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of n)for(const a of t){const l=E.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(!Sl(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 S={type:"gap_center",gap:a,nudge:c},w=r.find(({type:C})=>C==="gap_center"),x=w&&Sr(a.breadthIntersection[0],a.breadthIntersection[1],w.gap.breadthIntersection[0],w.gap.breadthIntersection[1]);w&&w.gap.length>a.length&&x?r[r.indexOf(w)]=S:(!w||!x)&&r.push(S)}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 y=a.endNode.pageBounds.maxX+a.length,f=n.minX,m=y-f;de(Math.abs(m))<=de(t.x)&&(de(Math.abs(m))<de(t.x)&&(r.length=0),t.x=Math.abs(m),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:m}))}for(const a of i){if(!Sl(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 S={type:"gap_center",gap:a,nudge:c},w=o.find(({type:C})=>C==="gap_center"),x=w&&Sl(w.gap.breadthIntersection[0],w.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);w&&w.gap.length>a.length&&x?o[o.indexOf(w)]=S:(!w||!x)&&o.push(S);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 y=a.endNode.pageBounds.maxY+a.length,f=n.minY,m=y-f;de(Math.abs(m))<=de(t.y)&&(de(Math.abs(m))<de(t.y)&&(o.length=0),t.y=Math.abs(m),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:m}))}}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:Ne(),type:"points",points:Fh(s.map(i=>E.From(i.otherPoint)).concat(s.map(i=>E.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:y}}=l;switch(l.type){case"gap_center":{const f=(p-n.width)/2,m=Sr(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:Ne(),gaps:[...fo(s,d.id,f,"backward",m),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:y},...fo(s,h.id,f,"forward",m)]});break}case"gap_duplicate":{const f=Sr(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:Ne(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(m=>m.clone().addXY(-d.pageBounds.width,0))},{startEdge:u,endEdge:y},...fo(s,h.id,p,"forward",f)]:[...fo(s,d.id,p,"backward",f),{startEdge:u,endEdge:y},{startEdge:y.map(m=>m.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:y}}=l;switch(l.type){case"gap_center":{const f=(p-n.height)/2,m=Sr(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:Ne(),gaps:[...fo(o,d.id,f,"backward",m),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:y},...fo(o,l.gap.endNode.id,f,"forward",m)]});break}case"gap_duplicate":{const f=Sr(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:Ne(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(m=>m.clone().addXY(0,-d.pageBounds.height))},{startEdge:u,endEdge:y},...fo(o,h.id,p,"forward",f)]:[...fo(o,d.id,p,"backward",f),{startEdge:u,endEdge:y},{startEdge:y.map(m=>m.clone().addXY(0,h.pageBounds.height)),endEdge:i.top}]})}break}}return L8(a),a}}bi([Z],Ms.prototype,"getSnapPointsCache",1);bi([Z],Ms.prototype,"getSnapThreshold",1);bi([Z],Ms.prototype,"getSnappableShapes",1);bi([Z],Ms.prototype,"getCurrentCommonAncestor",1);bi([Z],Ms.prototype,"getSnappablePoints",1);bi([Z],Ms.prototype,"getVisibleGaps",1);bi([Z],Ms.prototype,"getOutlinesInPageSpace",1);function dx(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 N8=/\r?\n|\r/g;function hx(e){return e.replace(N8,`
|
|
43
|
+
`).split(`
|
|
44
|
+
`).map(n=>n||" ").join(`
|
|
45
|
+
`)}const z8={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},F8=/\s/;class B8{constructor(n){v(this,"measureText",(n,t)=>{const r=this.getTextElement();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=hx(n);const o=r.getBoundingClientRect();return{x:0,y:0,w:o.width,h:o.height}});this.editor=n}getTextElement(){const n=document.querySelector(".tl-text-measure");n==null||n.remove();const t=document.createElement("div");return this.editor.getContainer().appendChild(t),t.id=`__textMeasure_${Ne()}`,t.classList.add("tl-text"),t.classList.add("tl-text-measure"),t.tabIndex=-1,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 y of n.childNodes)if(y.nodeType===Node.TEXT_NODE)for(const f of y.textContent??""){a.setStart(l,c),a.setEnd(l,c+f.length);const m=a.getClientRects(),S=m[m.length-1],w=S.top+i,x=S.left+s,C=S.right+s,P=F8.test(f);if(P!==d||w!==h||!u){if(u){if(t&&w!==h){p=!0;break}r.push(u)}u={box:{x,y:w,w:S.width,h:S.height},text:f}}else u.box.w=C-u.box.x,u.text+=f;d=P,h=w,c+=f.length}return u&&r.push(u),{spans:r,didTruncate:p}}measureTextSpans(n,t){if(n==="")return[];const r=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip",o=this.getTextElement(),s=Math.ceil(t.width-t.padding*2);o.style.setProperty("width",`${s}px`),o.style.setProperty("height","min-content"),o.style.setProperty("dir","ltr"),o.style.setProperty("font-size",`${t.fontSize}px`),o.style.setProperty("font-family",t.fontFamily),o.style.setProperty("font-weight",t.fontWeight),o.style.setProperty("line-height",`${t.lineHeight*t.fontSize}px`),o.style.setProperty("text-align",z8[t.textAlign]),r&&(o.style.setProperty("overflow-wrap","anywhere"),o.style.setProperty("word-break","break-all")),n=hx(n),o.textContent=n;const{spans:i,didTruncate:a}=this.measureElementTextNodeSpans(o,{shouldTruncateToFirstLine:r});if(t.overflow==="truncate-ellipsis"&&a){o.textContent="…";const l=Math.ceil(this.measureElementTextNodeSpans(o).spans[0].box.w);o.style.setProperty("width",`${s-l}px`),o.textContent=n;const c=this.measureElementTextNodeSpans(o,{shouldTruncateToFirstLine:!0}).spans,u=c[c.length-1];return c.push({text:"…",box:{x:Math.min(u.box.x+u.box.w,t.width-t.padding-l),y:u.box.y,w:l,h:u.box.h}}),c}return o.remove(),i}}class U8{constructor(n){v(this,"raf");v(this,"isPaused",!0);v(this,"last",0);v(this,"t",0);v(this,"start",()=>{this.isPaused=!1,cancelAnimationFrame(this.raf),this.raf=requestAnimationFrame(this.tick),this.last=Date.now()});v(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)});v(this,"dispose",()=>{this.isPaused=!0,cancelAnimationFrame(this.raf)});v(this,"prevPoint",new E);v(this,"updatePointerVelocity",n=>{const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(n===0)return;const s=E.Sub(r,t);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new E(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 H8=Object.defineProperty,V8=Object.getOwnPropertyDescriptor,Bo=(e,n,t,r)=>{for(var o=r>1?void 0:r?V8(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&&H8(n,t,o),o};class oo{constructor(n,t){v(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?e8():!1)}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??or.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??or.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??or.name}getLocale(){return this.user.userPreferences.get().locale??or.locale}getColor(){return this.user.userPreferences.get().color??or.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??or.isSnapMode}}Bo([Z],oo.prototype,"getUserPreferences",1);Bo([Z],oo.prototype,"getIsDarkMode",1);Bo([Z],oo.prototype,"getEdgeScrollSpeed",1);Bo([Z],oo.prototype,"getAnimationSpeed",1);Bo([Z],oo.prototype,"getId",1);Bo([Z],oo.prototype,"getName",1);Bo([Z],oo.prototype,"getLocale",1);Bo([Z],oo.prototype,"getColor",1);Bo([Z],oo.prototype,"getIsSnapMode",1);function bl(e){return Math.abs(e.props.bend)<8}function ap(e,n){if(n.type==="point")return;const t=e.getShape(n.boundShapeId),r=e.getShapePageTransform(t),o=e.getShapeGeometry(t),s=o instanceof os?o.children[0].vertices:o.vertices;return{shape:t,transform:r,isClosed:o.isClosed,isExact:n.isExact,didIntersect:!1,outline:s}}function px(e,n,t,r){if(t.type==="point")return E.From(t);const o=e.getShape(t.boundShapeId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=E.Add(s,E.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 E(0,0)}function Cr(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=jv(e,r,o),i=px(e,t,n.props.start,s==="double-bound"||s==="start-contains-end"),a=px(e,t,n.props.end,s==="double-bound"||s==="end-contains-start");return{start:i,end:a}}const ea=10,lp=10,K8=10,ss={s:2,m:3.5,l:5,xl:10};function jv(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 tc(e,n){const{start:t,end:r,arrowheadStart:o,arrowheadEnd:s}=n.props,i=Cr(e,n),a=i.start.clone(),l=i.end.clone(),c=E.Med(a,l);if(E.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=E.Sub(l,a).uni(),d=ap(e,t),h=ap(e,r),p=e.getShapePageTransform(n);fx(l,i.start,p,h),fx(a,i.end,p,d);let y=0,f=0,m=0,S=0,w=ea;const x=d&&h&&d.shape===h.shape,C=d&&h?jv(e,d.shape.id,h.shape.id):"safe";C==="safe"&&d&&h&&!x&&!d.isExact&&!h.isExact&&(h.didIntersect&&!d.didIntersect?d.isClosed&&a.setTo(l.clone().add(u.clone().mul(ea))):h.didIntersect||h.isClosed&&l.setTo(a.clone().sub(u.clone().mul(ea))));const P=E.Sub(l,a).uni(),k=!E.Equals(P,u);x||(C!=="start-contains-end"&&d&&o!=="none"&&!d.isExact&&(m=ss[n.props.size]/2+("size"in d.shape.props?ss[d.shape.props.size]/2:0),y=lp+m,w+=m),C!=="end-contains-start"&&h&&s!=="none"&&!h.isExact&&(S=ss[n.props.size]/2+("size"in h.shape.props?ss[h.shape.props.size]/2:0),f=lp+S,w+=S));const I=a.clone().add(P.clone().mul(y*(k?-1:1))),_=l.clone().sub(P.clone().mul(f*(k?-1:1)));E.Dist(I,_)<w&&(y!==0&&f!==0?(y*=-1.5,f*=-1.5):y!==0?y*=-1:f!==0&&(f*=-1)),a.add(P.clone().mul(y*(k?-1:1))),l.sub(P.clone().mul(f*(k?-1:1))),k?(d&&h&&l.setTo(E.Add(a,P.clone().mul(-ea))),c.setTo(E.Med(i.start,i.end))):c.setTo(E.Med(a,l));const T=E.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 fx(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?c8:rE)(i,a,r.outline);let d;if(u!==null&&(d=u.sort((y,f)=>E.Dist(y,i)-E.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 bg(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*K8))return tc(e,n);const i=Cr(e,n),a=E.Med(i.start,i.end),l=E.Sub(i.end,i.start).uni(),c=E.Add(a,l.per().mul(-s)),u=ap(e,n.props.start),d=ap(e,n.props.end),h=i.start.clone(),p=i.end.clone(),y=c.clone();if(E.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:y,isValid:!1,length:0};const f=n.props.bend<0,m=f?Qp:h4,S=gx(h,p,y),w=E.Angle(S.center,h),x=E.Angle(S.center,p),C=m(w,x);if(S.length===0||S.size===0||!R1(S.length)||!R1(S.size))return tc(e,n);const P=h.clone(),k=p.clone(),I=y.clone(),_=e.getShapePageTransform(n);let $=0,T=0,R=ea;if(u&&!u.isExact){const V=te.applyToPoint(_,P),X=te.applyToPoint(_,S.center),re=te.applyToPoint(_,k),ge=te.Inverse(u.transform),Ce=te.applyToPoint(ge,V),oe=te.applyToPoint(ge,X),Se=te.applyToPoint(ge,re),{isClosed:De}=u,et=De?rx:ox;let Ee,ct=et(oe,S.radius,u.outline);if(ct){const Fe=oe.angle(Ce),qn=oe.angle(Se),_n=m(Fe,qn);ct=ct.filter(tt=>m(Fe,oe.angle(tt))<=_n);const Tn=_n*.25;ct.sort(De?(tt,mt)=>Math.abs(m(Fe,oe.angle(tt))-Tn)<Math.abs(m(Fe,oe.angle(mt))-Tn)?-1:1:(tt,mt)=>m(Fe,oe.angle(tt))<m(Fe,oe.angle(mt))?-1:1),Ee=ct[0]??(De?void 0:Ce)}else Ee=De?void 0:Ce;if(Ee&&(P.setTo(e.getPointInShapeSpace(n,te.applyToPoint(u.transform,Ee))),u.didIntersect=!0,o!=="none")){const Fe=ss[n.props.size]/2+("size"in u.shape.props?ss[u.shape.props.size]/2:0);$=lp+Fe,R+=Fe}}if(d&&!d.isExact){const V=te.applyToPoint(_,P),X=te.applyToPoint(_,k),re=te.applyToPoint(_,S.center),ge=te.Inverse(d.transform),Ce=te.applyToPoint(ge,V),oe=te.applyToPoint(ge,re),Se=te.applyToPoint(ge,X),De=d.isClosed,et=De?rx:ox;let Ee,ct=et(oe,S.radius,d.outline);if(ct){const Fe=oe.angle(Ce),qn=oe.angle(Se),_n=m(Fe,qn),Tn=_n*.75;ct=ct.filter(tt=>m(Fe,oe.angle(tt))<=_n),ct.sort(De?(tt,mt)=>Math.abs(m(Fe,oe.angle(tt))-Tn)<Math.abs(m(Fe,oe.angle(mt))-Tn)?-1:1:(tt,mt)=>m(Fe,oe.angle(tt))<m(Fe,oe.angle(mt))?-1:1),ct[0]?Ee=ct[0]:Ee=De?void 0:Se}else Ee=De?void 0:Se;if(Ee&&(k.setTo(e.getPointInShapeSpace(n,te.applyToPoint(d.transform,Ee))),d.didIntersect=!0,r!=="none")){const Fe=ss[n.props.size]/2+("size"in d.shape.props?ss[d.shape.props.size]/2:0);T=lp+Fe,R+=Fe}}let L=E.Angle(S.center,P),N=E.Angle(S.center,k),D=m(L,N),z=D*S.radius;const F=P.clone(),W=k.clone();if($!==0){const V=$/z*(f?1:-1),X=E.FromAngle(L+D*V);F.setTo(S.center).add(X.mul(S.radius))}if(T!==0){const V=T/z*(f?-1:1),X=E.FromAngle(N+D*V);W.setTo(S.center).add(X.mul(S.radius))}if(E.Dist(F,W)<R&&($!==0&&T!==0?($*=-1.5,T*=-1.5):$!==0?$*=-2:T!==0&&(T*=-2)),$!==0){const V=$/z*(f?1:-1),X=E.FromAngle(L+D*V);P.setTo(S.center).add(X.mul(S.radius))}if(T!==0){const V=T/z*(f?-1:1),X=E.FromAngle(N+D*V);k.setTo(S.center).add(X.mul(S.radius))}if(u&&d&&!u.isExact&&!d.isExact){L=E.Angle(S.center,P),N=E.Angle(S.center,k),D=m(L,N),z=D*S.radius;const V=jv(e,u.shape.id,d.shape.id);if(V==="double-bound"&&z<30)P.setTo(h),k.setTo(p),I.setTo(y);else if(V==="safe"&&(u&&!u.didIntersect&&P.setTo(h),d&&!d.didIntersect||m(w,L)>m(w,N))){const X=Math.min(.9,ea/z)*(f?1:-1),re=E.FromAngle(L+D*X);k.setTo(S.center).add(re.mul(S.radius))}}W8(S.center,S.radius,P,k,I,C,f),P.equals(k)&&(P.setTo(I.clone().addXY(1,1)),k.setTo(I.clone().subXY(1,1))),h.setTo(P),p.setTo(k),y.setTo(I);const U=gx(h,p,y);return{isStraight:!1,start:{point:h,handle:i.start,arrowhead:n.props.arrowheadStart},end:{point:p,handle:i.end,arrowhead:n.props.arrowheadEnd},middle:y,handleArc:S,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function gx(e,n,t){const r=-2*(e.x*(n.y-t.y)-e.y*(n.x-t.x)+n.x*t.y-t.x*n.y),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=E.Dist(o,e),i=+E.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=(Ae-u)*(i?1:-1),p=h*s;return{center:o,radius:s,size:h,length:p,largeArcFlag:d,sweepFlag:i}}function W8(e,n,t,r,o,s,i){const a=E.Angle(e,t),l=E.Angle(e,r);let c=Qp(a,l);i||(c=Ae-c);const u=.5*(i?1:-1),d=E.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 G8={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 ie{constructor(n,t){v(this,"id");v(this,"type");v(this,"shapeType");v(this,"initial");v(this,"children");v(this,"parent");v(this,"_path");v(this,"_current");v(this,"_isActive");v(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});v(this,"handleEvent",n=>{var o;const t=G8[n.name],r=this.getCurrent();(o=this[t])==null||o.call(this,n),this.getCurrent()===r&&this.getIsActive()&&(r==null||r.handleEvent(n))});v(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)}});v(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)});v(this,"_currentToolIdMask",an("curent tool id mask",void 0));v(this,"onWheel");v(this,"onPointerDown");v(this,"onPointerMove");v(this,"onPointerUp");v(this,"onDoubleClick");v(this,"onTripleClick");v(this,"onQuadrupleClick");v(this,"onRightClick");v(this,"onMiddleClick");v(this,"onKeyDown");v(this,"onKeyUp");v(this,"onKeyRepeat");v(this,"onCancel");v(this,"onComplete");v(this,"onInterrupt");v(this,"onEnter");v(this,"onExit");v(this,"onTick");this.editor=n;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=an("toolIsActive"+this.id,!1),this._current=an("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)}}v(ie,"id"),v(ie,"initial"),v(ie,"children");class Yd extends ie{constructor(){super(...arguments);v(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}}})}}v(Yd,"id","root"),v(Yd,"initial",""),v(Yd,"children",()=>[]);var Y8=Object.defineProperty,X8=Object.getOwnPropertyDescriptor,ue=(e,n,t,r)=>{for(var o=r>1?void 0:r?X8(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&&Y8(n,t,o),o};class ce extends l8.EventEmitter{constructor({store:t,user:r,shapeUtils:o,tools:s,getContainer:i,initialState:a,inferDarkMode:l}){super();v(this,"store");v(this,"root");v(this,"disposables",new Set);v(this,"_tickManager",new U8(this));v(this,"snaps");v(this,"user");v(this,"textMeasure");v(this,"environment");v(this,"scribbles");v(this,"getContainer");v(this,"sideEffects");v(this,"shapeUtils");v(this,"styleProps");v(this,"history",new A8(this,t=>{this.annotateError(t,{origin:"history.batch",willCrashApp:!0}),this.crash(t)}));v(this,"_crashingError",null);v(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}}}));v(this,"_isChangingStyleTimeout",-1);v(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}},{ephemeral:!0}),this));v(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)}}));v(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}}}));v(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}}}));v(this,"_viewportAnimation",null);v(this,"_willSetInitialBounds",!0);v(this,"_cameraState",an("camera state","idle"));v(this,"_cameraStateTimeoutRemaining",0);v(this,"_lastUpdateRenderingBoundsTimestamp",Date.now());v(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,this._cameraStateTimeoutRemaining<=0&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"),this.updateRenderingBounds())});v(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=M4;const t=Date.now();this._cameraState.__unsafe__getWithoutCapture()==="idle"?(this._lastUpdateRenderingBoundsTimestamp=t,this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout)):t-this._lastUpdateRenderingBoundsTimestamp>A4&&this.updateRenderingBounds()});v(this,"_renderingBounds",an("rendering viewport",new le));v(this,"_renderingBoundsExpanded",an("rendering viewport expanded",new le));v(this,"renderingBoundsMargin",100);v(this,"_currentPageShapeIds");v(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=Ht.create({id:Ht.createId(t)});this.store.put([r,Vt.create({id:Vt.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})}));v(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}}}));v(this,"_createPage",this.history.createCommand("createPage",t=>{if(this.getInstanceState().isReadonly||this.getPages().length>=ep)return null;const r=this.getPages(),o=y8(t.name??"Page 1",r.map(c=>c.name));let s=t.index;(!s||r.some(c=>c.index===s))&&(s=yo(r[r.length-1].index));const i=Mo.create({meta:{},...t,name:o,index:s}),a=Ht.create({id:Ht.createId(i.id)}),l=Vt.create({id:Vt.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])}}));v(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()}}));v(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))}}));v(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))}}));v(this,"_deleteAssets",this.history.createCommand("deleteAssets",t=>{if(this.getInstanceState().isReadonly||t.length<=0)return;const r=he(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)}}));v(this,"_parentIdsToChildIds");v(this,"_childIdsCache",new Rv);v(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>po){Zu(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,tr(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,yo(d))}const h=u.getDefaultProps();for(const[f,m]of this.styleProps[c.type])h[m]=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 y=(l=(a=this.getShapeUtil(p)).onBeforeCreate)==null?void 0:l.call(a,p);y&&(p=y),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))}}));v(this,"animatingShapes",new Map);v(this,"_updateShapes",this.history.createCommand("updateShapes",(t,r)=>{if(this.getInstanceState().isReadonly)return null;const o=he(t),s=Object.fromEntries(he(o.map(({id:l})=>this.getShape(l))).map(l=>[l.id,l]));if(o.length<=0)return null;const i=he(o.map(l=>{const c=s[l.id];if(!c)return null;let u=null;for(const[d,h]of Object.entries(l))if(h!==void 0)switch(d){case"id":case"type":continue;default:if(h!==c[d])if(u||(u={...c}),d==="props"){const p={...c.props};for(const[y,f]of Object.entries(h))f!==void 0&&(p[y]=f);u.props=p}else if(d==="meta"){const p={...c.meta};for(const[y,f]of Object.entries(h))f!==void 0&&(p[y]=f);u.meta=p}else u[d]=h}return u??c})),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}}}}));v(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=he(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}))}}));v(this,"_selectionSharedStyles",Z("_selectionSharedStyles",()=>{const t=this.getSelectedShapes(),r=new ky;for(const o of t)this._extractSharedStyles(o,r);return r}));v(this,"externalAssetContentHandlers",{file:null,url:null});v(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});v(this,"inputs",{originPagePoint:new E,originScreenPoint:new E,previousPagePoint:new E,previousScreenPoint:new E,currentPagePoint:new E,currentScreenPoint:new E,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 E});v(this,"_clickManager",new T8(this));v(this,"_prevCursor","default");v(this,"_shiftKeyTimeout",-1);v(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"})});v(this,"_altKeyTimeout",-1);v(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"})});v(this,"_ctrlKeyTimeout",-1);v(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"})});v(this,"_restoreToolId","select");v(this,"_pinchStart",1);v(this,"_didPinch",!1);v(this,"_selectedShapeIdsAtPointerDown",[]);v(this,"capturedPointerId",null);v(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{point:{x:c,y:u,z:d=1},delta:{x:h,y:p}}=t,{x:y,y:f,z:m}=this.getCamera(),S=Math.min(ts,Math.max(wl,d));this.setCamera({x:y+h/m-c/m+c/S,y:f+p/m-u/m+u/S,z:S});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(),y=Math.min(ts,Math.max(wl,p+(t.delta.z??0)*p));this.setCamera({x:d+(c/y-c)-(c/p-c),y:h+(u/y-u)-(u/p-u),z:y});return}this.pan(t.delta),!r.isDragging&&r.isPointing&&s.dist(a)>(this.getInstanceState().isCoarsePointer?by: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(E.Sub(u,d));return}!r.isDragging&&r.isPointing&&s.dist(a)>(this.getInstanceState().isCoarsePointer?by: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:Vd}),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:Vd}),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:Vd}),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 Ms(this),this.user=new oo(r??tE(),l??!1),this.getContainer=i??(()=>document.body),this.textMeasure=new B8(this);class c extends Yd{}v(c,"initial",a??""),this.root=new c(this),this.root.children={};const u=iE(o),d=new Set(Object.keys(t.schema.types.shape.migrations.subTypeMigrations));for(const C of u){if(!d.has(C.type))throw Error(`Editor and store have different shapes: "${C.type}" was passed into the editor but not the schema`);d.delete(C.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={},y=new Map;for(const C of u){const P=new C(this);h[C.type]=P;const k=mP(C.props??{});p[C.type]=k;for(const I of k.keys())if(!y.has(I.id))y.set(I.id,I);else if(y.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 C of[...s]){if(Yp(this.root.children,C.id))throw Error(`Can't override tool with id "${C.id}"`);this.root.children[C.id]=new C(this,this.root)}this.environment=new $8(this),this.scribbles=new O8(this);const f=new Set,m=C=>{var H;const P=this.getShape(C);if(!P)return;const{start:k,end:I}=P.props,_=k.type==="binding"?this.getShape(k.boundShapeId):void 0,$=I.type==="binding"?this.getShape(I.boundShapeId):void 0,T=this.getAncestorPageId(P);if(!T)return;let R;if(_&&$)R=this.findCommonAncestor([_,$])??T;else if(_||$){const U=(H=_||$)==null?void 0:H.parentId;U&&U===P.parentId?R=P.parentId:R=T}else return;R&&R!==P.parentId&&this.reparentShapes([C],R);const L=this.getShape(C);if(!L)throw Error("no reparented arrow");const N=this.getShapeNearestSibling(L,_),D=this.getShapeNearestSibling(L,$);let z;if(N&&D)z=N.index>D.index?N:D;else if(N&&!D)z=N;else if(D&&!N)z=D;else return;let F;const W=this.getSortedChildIdsForParent(z.parentId).map(U=>this.getShape(U)).filter(U=>U.index>z.index);if(W.length){const U=W.find(V=>V.type!=="arrow");if(L.index>z.index&&(!U||L.index<U.index))return;F=ec(z.index,W[0].index)}else F=yo(z.index);F!==L.index&&this.updateShapes([{id:C,type:"arrow",index:F}])},S=(C,P)=>{const{x:k,y:I}=Cr(this,C)[P];this.store.put([{...C,props:{...C.props,[P]:{type:"point",x:k,y:I}}}])},w=C=>{for(const P of["start","end"]){const k=C.props[P];if(k.type!=="binding")continue;const I=this.getShape(k.boundShapeId),_=this.getAncestorPageId(C)===this.getAncestorPageId(I);(!I||!_)&&S(C,P)}m(C.id)},x=(C,P)=>{let k=null;const I=C.selectedShapeIds.filter(T=>!P.has(T));I.length!==C.selectedShapeIds.length&&(k||(k={...C}),k.selectedShapeIds=I);const _=C.erasingShapeIds.filter(T=>!P.has(T));_.length!==C.erasingShapeIds.length&&(k||(k={...C}),k.erasingShapeIds=_),C.hoveredShapeId&&P.has(C.hoveredShapeId)&&(k||(k={...C}),k.hoveredShapeId=null),C.editingShapeId&&P.has(C.editingShapeId)&&(k||(k={...C}),k.editingShapeId=null);const $=C.hintingShapeIds.filter(T=>!P.has(T));return $.length!==C.hintingShapeIds.length&&(k||(k={...C}),k.hintingShapeIds=$),C.focusedGroupId&&P.has(C.focusedGroupId)&&(k||(k={...C}),k.focusedGroupId=null),k};if(this.sideEffects=new R8(this),this.sideEffects.registerBatchCompleteHandler(()=>{var C;for(const P of f){f.delete(P);const k=this.getShape(P);if(!k)continue;const I=this.getShapeUtil(k),_=(C=I.onChildrenChange)==null?void 0:C.call(I,k);_!=null&&_.length&&this.updateShapes(_,{squashing:!0})}this.emit("update")}),this.sideEffects.registerBeforeDeleteHandler("shape",C=>{C.parentId&&tr(C.parentId)&&f.add(C.parentId);const P=this._getArrowBindingsIndex().get()[C.id];if(P!=null&&P.length)for(const{arrowId:_,handleId:$}of P){const T=this.getShape(_);T&&S(T,$)}const k=new Set([C.id]),I=he(this.getPageStates().map(_=>x(_,k)));I.length&&this.store.put(I)}),this.sideEffects.registerBeforeDeleteHandler("page",C=>{var _;if(this.getInstanceState().currentPageId!==C.id)return;const P=(_=this.getPages().find($=>$.id!==C.id))==null?void 0:_.id;if(!P)return;this.store.put([{...this.getInstanceState(),currentPageId:P}]);const k=Ht.createId(C.id),I=Vt.createId(C.id);this.store.remove([k,I])}),this.sideEffects.registerAfterChangeHandler("shape",(C,P)=>{if(this.isShapeOfType(P,"arrow")&&w(P),C.parentId!==P.parentId){const k=I=>{const _=this._getArrowBindingsIndex().get()[I];if(_!=null&&_.length)for(const $ of _)m($.arrowId)};k(P.id),this.visitDescendants(P.id,k)}if(C.parentId!==P.parentId&&gn(P.parentId)){const k=new Set([C.id]);this.visitDescendants(C.id,I=>{k.add(I)});for(const I of this.getPageStates()){if(I.pageId===P.parentId)continue;const _=x(I,k);_&&this.store.put([_])}}C.parentId&&tr(C.parentId)&&f.add(C.parentId),P.parentId!==C.parentId&&tr(P.parentId)&&f.add(P.parentId)}),this.sideEffects.registerAfterChangeHandler("instance_page_state",(C,P)=>{if((C==null?void 0:C.selectedShapeIds)!==(P==null?void 0:P.selectedShapeIds)){const k=P.selectedShapeIds.filter(_=>{var T,R;let $=(T=this.getShape(_))==null?void 0:T.parentId;for(;tr($);){if(P.selectedShapeIds.includes($))return!1;$=(R=this.getShape($))==null?void 0:R.parentId}return!0});let I=null;if(k.length>0){const _=this.findCommonAncestor(he(k.map($=>this.getShape($))),$=>this.isShapeOfType($,"group"));_&&(I=_)}else P!=null&&P.focusedGroupId&&(I=P.focusedGroupId);(k.length!==P.selectedShapeIds.length||I!==P.focusedGroupId)&&this.store.put([{...P,selectedShapeIds:k,focusedGroupId:I??null}])}}),this.sideEffects.registerAfterCreateHandler("shape",C=>{this.isShapeOfType(C,"arrow")&&w(C)}),this.sideEffects.registerAfterCreateHandler("page",C=>{const P=Ht.createId(C.id),k=Vt.createId(C.id);this.store.has(P)||this.store.put([Ht.create({id:P})]),this.store.has(k)||this.store.put([Vt.create({id:k,pageId:C.id})])}),this._currentPageShapeIds=I8(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=k8(this.store),this.disposables.add(this.store.listen(C=>{this.emit("change",C)})),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=si(this.shapeUtils,r);return oi(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 E8(this)}getArrowsBoundTo(t){return this._getArrowBindingsIndex().get()[t]||Po}getArrowInfoCache(){return this.store.createComputedCache("arrow infoCache",t=>bl(t)?tc(this,t):bg(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 fv(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(wy)}updateDocumentSettings(t){return this.store.put([{...this.getDocumentSettings(),...t}]),this}getInstanceState(){return this.store.get(sn)}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 Vt.createId(this.getCurrentPageId())}updateCurrentPageState(t,r){return this._setInstancePageState(t,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:t}=this.getCurrentPageState();return he(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:le.Common(he(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=le.FromPoints(this.getSelectedShapeIds().flatMap(s=>{const i=this.getShapePageTransform(s);return i?i.applyToPoints(this.getShapeGeometry(s).vertices):[]}).map(s=>E.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 he(t.map(r=>this.getShape(r)))}setHintingShapes(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:Fh(r)},{ephemeral:!0}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const t=this.getErasingShapeIds();return he(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 Ht.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;this.dispatch({type:"pointer",target:"canvas",name:"pointer_move",point:o,pointerId:L1.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 le(-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=le.Common(he(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=ts;for(let u=1;u<ji.length;u++){const d=ji[u-1],h=ji[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=wl;for(let u=ji.length-1;u>0;u--){const d=ji[u-1],h=ji[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=le.Common(he(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=Hr(Math.min((s.width-i)/t.width,(s.height-i)/t.height),wl,ts);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=Xt.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:this.getViewportScreenBounds().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:y}=this.getCamera(),f=E.Mul(i,l*d/y);l*=1-s,l<a?c():this._setCamera({x:h+f.x,y:p+f.y,z:y})};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}))},_P)}),this):this}animateToShape(t,r=_4){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 le(o.left||o.x,o.top||o.y,Math.max(o.width,1),Math.max(o.height,1)),i=s.equals(this.getViewportScreenBounds()),{_willSetInitialBounds:a}=this;if(i)this._willSetInitialBounds=!1;else if(a)this._willSetInitialBounds=!1,this.updateInstanceState({screenBounds:s.toJson()},{squashing:!0,ephemeral:!0});else if(t&&!this.getInstanceState().followingUserId){const l=this.getViewportPageCenter();this.updateInstanceState({screenBounds:s.toJson()},{squashing:!0,ephemeral:!0}),this.centerOnPoint(l)}else this.updateInstanceState({screenBounds:s.toJson()},{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 le(t,r,o,s)}getViewportScreenCenter(){return this.getViewportScreenBounds().center}getViewportPageBounds(){const{w:t,h:r}=this.getViewportScreenBounds(),{x:o,y:s,z:i}=this.getCamera();return new le(-o,-s,t/i,r/i)}getViewportPageCenter(){return this.getViewportPageBounds().center}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(sn),{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(sn),{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;nr(()=>{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((N,D)=>N.lastActivityTimestamp-D.lastActivityTimestamp).pop();if(!l){this.stopFollowingUser();return}const c=l.currentPageId===this.getCurrentPageId(),u=c?w4:1;if(!c){this.stopFollowingUser(),this.setCurrentPage(l.currentPageId),this.startFollowingUser(t);return}const{center:d,width:h,height:p}=this.getViewportPageBounds(),y=le.From(l.screenBounds),f=y.width/l.camera.z,m=y.height/l.camera.z,S=new E(f/2-l.camera.x,m/2-l.camera.y),w=l.followingUserId===o,x=h+(f-h)*u,C=p+(m-p)*u,P=w?p/C:Math.min(h/x,p/C),k=Hr(this.getCamera().z*P,wl,ts),I=this.getViewportScreenBounds().w/k,_=this.getViewportScreenBounds().h/k,$=S.sub(d),T=E.Add(d,E.Mul($,u)),R=E.Sub(T,d).len(),L=Math.abs(k-this.getCamera().z);if(R<x4&&L<C4){i=!0;return}i&&R<b4&&L<P4||(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=po*2,s=po;const i=this.getEditingShapeId(),a=this.getSelectedShapeIds(),l=this.getErasingShapeIds(),c=this.getRenderingBoundsExpanded(),u=Number.isFinite(this.renderingBoundsMargin),d=(h,p,y)=>{const f=this.getShape(h);if(!f)return;p*=f.opacity;let m=!1,S=!1;const w=this.getShapeUtil(f),x=this.getShapeMaskedPageBounds(h);t&&(S=!y&&l.includes(h),S&&(p*=.32),m=u&&w.canUnmount(f)&&i!==h&&(x===void 0||!c.includes(x)&&!a.includes(h))),r.push({id:h,shape:f,util:w,index:o,backgroundIndex:s,opacity:p,isCulled:m,maskedPageBounds:x}),o+=1,s+=1;const C=this.getSortedChildIdsForParent(h);if(!C.length)return;let P=null;w.providesBackgroundForChildren(f)&&(P=s,s=o,o+=po);for(const k of C)d(k,p,y||S);P!==null&&(s=P)};for(const h of this.getSortedChildIdsForParent(this.getCurrentPageId()))d(h,1,!1);return r}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(u5)}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(Kt)}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=Mo.createId()){if(this.getPages().length>=ep)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=ec(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)??Po}_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?le.FromPoints(te.applyToPoints(r,this.getShapeGeometry(t).vertices)):new le})}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=Ey(s,i);return a?a.map(E.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&&E.Equals(a,o[l])))return r.clone();const i=Ey(o,s);return i?le.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=he(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,y=null;const f=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(m=>{if(this.isShapeOfType(m,"group"))return!1;const S=this.getShapeMask(m);return S&&!eo(t,S)?!1:i?i(m):!0});for(let m=f.length-1;m>=0;m--){const S=f[m],w=this.getShapeGeometry(S),x=w instanceof os,C=this.getPointInShapeSpace(S,t);if((this.isShapeOfType(S,"arrow")||this.isShapeOfType(S,"geo")&&S.props.fill==="none")&&S.props.text.trim()){for(const k of w.children)if(k.isLabel&&k.isPointInBounds(C))return S}if(this.isShapeOfType(S,"frame")){const k=w.distanceToPoint(C,c);if(Math.abs(k)<=a)return y||S;if(w.hitTestPoint(C,0,!0))return y||h||(u?S:void 0);continue}let P;if(x){let k=1/0;for(const I of w.children){if(I.isLabel&&!l)continue;const _=I.distanceToPoint(C,c);_<k&&(k=_)}P=k}else a===0&&(w.bounds.w<1||w.bounds.h<1)||w.bounds.containsPoint(C,a)?P=w.distanceToPoint(C,c):P=1/0;if(w.isClosed){if(P<=a){if(w.isFilled||x&&w.children[0].isFilled)return y||S;if(this.getShapePageBounds(S).contains(s))continue;if(Math.abs(P)<a)Math.abs(P)<p&&(p=Math.abs(P),y=S);else if(!y){const{area:k}=w;k<d&&(d=k,h=S)}}}else if(P<Or/o)return S}return y||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&&!eo(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 E(0,0);if(gn(s.parentId))return E.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):E.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),t=>this.store.get(t))}getCurrentPageShapesSorted(){const t=new Set(this.getCurrentPageShapes().sort(Kt)),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);Qs(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(tr(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||!tr(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(y=>y.id);if(s.length===0)return this;const i=[],a=gn(r)?te.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const u=he(this.getSortedChildIdsForParent(r).map(y=>this.getShape(y)));if(o){const y=u.find(f=>f.index===o);if(y){const f=u[u.indexOf(y)+1];f?c=Oa(o,f.index,s.length):c=wg(o,s.length)}else{const f=u.sort(Kt).find(m=>m.index>o);f?c=Oa(o,f.index,s.length):c=wg(o,s.length)}}else{const y=u.length&&u[u.length-1];c=y?wg(y.index,s.length):uE(s.length)}const d=a.clone().invert(),h=he(s.map(y=>this.getShape(y))),p=h.filter(y=>y.isLocked);p.length&&this.updateShapes(p.map(({id:y,type:f})=>({id:y,type:f,isLocked:!1})));for(let y=0;y<h.length;y++){const f=h[y],m=this.getShapePageTransform(f);if(!m)continue;const S=m.point();if(!S)continue;const w=d.applyToPoint(S),x=m.rotation()-l;i.push({id:f.id,type:f.type,parentId:r,x:w.x,y:w.y,rotation:x,index:c[y],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 yo(s.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o?this._childIdsCache.get(o,()=>o):Po}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=dE({editor:this});return s?(Gd({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}nudgeShapes(t,r,o){var a,l;const s=typeof t[0]=="string"?t:t.map(c=>c.id);if(s.length<=0)return this;const i=[];for(const c of s){const u=this.getShape(c);if(!u)throw Error(`Could not find a shape with the id ${c}.`);const d=E.Cast(r),h=this.getShapeParentTransform(u);h&&d.rot(-h.rotation());const p=(l=(a=this.getShapeUtil(u)).onTranslateStart)==null?void 0:l.call(a,u);i.push(p?{...p,x:u.x+d.x,y:u.y+d.y}:{id:c,x:u.x+d.x,y:u.y+d.y,type:u.type})}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=he(i.map(u=>{const d=this.getShape(u);if(!d)return null;const h=l.get(u);let p=0,y=0;if(r&&s.has(u)){const k=this.getShapeParentTransform(d),I=new E(r.x,r.y).rot(-k.rotation());p=I.x,y=I.y}const f=d.parentId??this.getCurrentPageId(),m=this.getSortedChildIdsForParent(f),S=m.indexOf(d.id),w=m[S+1],x=w?this.getShape(w):null,C=x?ec(d.index,x.index):yo(d.index);let P=qt(d);if(this.isShapeOfType(d,"arrow")&&this.isShapeOfType(P,"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:R}=k.start.point;P.props.start={type:"point",x:T,y:R}}else{const{start:T}=Cr(this,d);P.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:R}=k.end.point;P.props.end={type:"point",x:T,y:R}}else{const{end:T}=Cr(this,d);P.props.start={type:"point",x:T.x,y:T.y}}const $=bl(P)?tc(this,P):bg(this,P);if(k!=null&&k.isValid&&($!=null&&$.isValid)&&!bl(d)){const T=E.Med(k.start.handle,k.end.handle),R=E.Dist(k.middle,T),L=E.Dist($.middle,T);P.props.bend<0?P.props.bend+=L-R:P.props.bend-=L-R}P.props.start.type==="binding"&&I&&(P.props.start.boundShapeId=I),P.props.end.type==="binding"&&_&&(P.props.end.boundShapeId=_)}return P={...P,id:h,x:d.x+p,y:d.y+y,index:C},P}));return c.forEach(u=>{tr(u.parentId)&&l.has(u.parentId)&&(u.parentId=l.get(u.parentId))}),this.history.batch(()=>{const u=c.length+this.getCurrentPageShapeIds().size>po;u&&Zu(this);const d=u?c.slice(0,po-this.getCurrentPageShapeIds().size):c,h=d.map(p=>p.id);if(this.createShapes(d),this.setSelectedShapes(h),r!==void 0){const p=this.getSelectionPageBounds(),y=this.getViewportPageBounds();p&&!y.contains(p)&&this.centerOnPoint(p.center,{duration:wo})}}),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>po)return Zu(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=qu(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=qu(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=qu(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=qu(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=he(o.map(a=>this.getShape(a)));if(!s.length)return this;s=he(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(l=>this.getShape(l)):a).flat());const i=le.Common(he(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(m=>m.id);if(this.getInstanceState().isReadonly)return this;const i=he(s.map(m=>this.getShape(m)).filter(m=>!(!m||this.isShapeOfType(m,"arrow")&&(m.props.start.type==="binding"||m.props.end.type==="binding")))),a=i.length;if(o===0&&a<3||a<2)return this;const l=Object.fromEntries(i.map(m=>[m.id,this.getShapePageBounds(m)]));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 m=[];i.sort((w,x)=>l[w.id][u]-l[x.id][u]);for(let w=0;w<a-1;w++){const x=i[w],C=i[w+1],P=l[x.id],I=l[C.id][u]-P[d],_=m.find($=>$.gap===I);_?_.count++:m.push({gap:I,count:1})}let S=0;m.forEach(w=>{w.count>S&&(S=w.count,p=w.gap)}),S===1&&(p=Math.max(0,m.reduce((w,x)=>w+x.gap*x.count,0)/(a-1)))}else p=o;const y=[];let f=l[i[0].id][d];return i.forEach((m,S)=>{var k,I;if(S===0)return;const w={x:0,y:0};w[c]=f+p-l[m.id][c];const x=this.getShapeParent(m),C=x?E.Rot(w,-this.getShapePageTransform(x).decompose().rotation):w,P=(I=(k=this.getShapeUtil(m)).onTranslateStart)==null?void 0:I.call(k,m);y.push(P?{...P,[c]:m[c]+C[c]}:{id:m.id,type:m.type,[c]:m[c]+C[c]}),f+=l[m.id][h]+p}),this.updateShapes(y),this}packShapes(t,r){var I,_;const o=typeof t[0]=="string"?t:t.map($=>$.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=he(o.map($=>this.getShape($)).filter($=>!(!$||this.isShapeOfType($,"arrow")&&($.props.start.type==="binding"||$.props.end.type==="binding")))),i={},a={};let l,c,u=0;for(let $=0;$<s.length;$++)l=s[$],c=this.getShapePageBounds(l),i[l.id]=c,a[l.id]=c.clone(),u+=c.width*c.height;const d=le.Common(he(Object.values(i))),h=d.width;s.sort(($,T)=>i[T.id].height-i[$.id].height);const p=Math.max(Math.ceil(Math.sqrt(u/.95)),h),y=[new le(d.x,d.y,p,1/0)];let f=0,m=0,S,w;for(let $=0;$<s.length;$++){l=s[$],c=a[l.id];for(let T=y.length-1;T>=0;T--)if(S=y[T],!(c.width>S.width||c.height>S.height)){c.x=S.x,c.y=S.y,m=Math.max(m,c.maxY),f=Math.max(f,c.maxX),c.width===S.width&&c.height===S.height?(w=y.pop(),T<y.length&&(y[T]=w)):c.height===S.height?(S.x+=c.width+r,S.width-=c.width+r):c.width===S.width?(S.y+=c.height+r,S.height-=c.height+r):(y.push(new le(S.x+(c.width+r),S.y,S.width-(c.width+r),c.height)),S.y+=c.height+r,S.height-=c.height+r);break}}const x=le.Common(Object.values(a)),C=E.Sub(d.center,x.center);let P;const k=[];for(let $=0;$<s.length;$++){l=s[$],c=i[l.id],P=a[l.id];const T=E.Sub(P.point,c.point).add(C),R=this.getShapeParentTransform(l);R&&T.rot(-R.rotation());const L={id:l.id,type:l.type,x:l.x+T.x,y:l.y+T.y},N=(_=(I=this.getShapeUtil(l)).onTranslateStart)==null?void 0:_.call(I,{...l,...L});N?k.push({...L,...N}):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=he(o.map(c=>this.getShape(c))),i=Object.fromEntries(s.map(c=>[c.id,this.getShapePageBounds(c)])),a=le.Common(he(Object.values(i))),l=[];return s.forEach(c=>{var f,m;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?E.Rot(d,-this.getShapePageTransform(h).decompose().rotation):d,y=(m=(f=this.getShapeUtil(c)).onTranslateStart)==null?void 0:m.call(f,c);l.push(y?{...y,x:c.x+p.x,y:c.y+p.y}:{id:c.id,type:c.type,x:c.x+p.x,y:c.y+p.y})}),this.updateShapes(l),this}distributeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(x=>x.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=he(o.map(x=>this.getShape(x))),a=Object.fromEntries(i.map(x=>[x.id,this.getShapePageBounds(x)]));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=[],y=i.sort((x,C)=>a[x.id][c]-a[C.id][c])[0],f=i.sort((x,C)=>a[C.id][u]-a[x.id][u])[0],m=a[y.id][d],S=(a[f.id][d]-m)/(s-1),w=m+S;return i.filter(x=>x!==y&&x!==f).sort((x,C)=>a[x.id][d]-a[C.id][d]).forEach((x,C)=>{var $,T;const P={x:0,y:0};P[l]=w+S*C-a[x.id][h]/2-a[x.id][l];const k=this.getShapeParent(x),I=k?E.Rot(P,-this.getShapePageTransform(k).rotation()):P,_=(T=($=this.getShapeUtil(x)).onTranslateStart)==null?void 0:T.call($,x);p.push(_?{..._,[l]:x[l]+I[l]}:{id:x.id,type:x.type,[l]:x[l]+I[l]})}),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=he(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=le.Common(he(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const c of s){if(this.getShapePageTransform(c).rotation()%Ae)continue;const d=i[c.id],h=a[c.id],p=new E(0,l.minY-h.minY),y=this.getShapeParentTransform(c);y&&p.rot(-y.rotation());const{x:f,y:m}=E.Add(p,c);this.updateShapes([{id:c.id,type:c.type,x:f,y:m}],{squashing:!0});const S=new E(1,l.height/h.height);this.resizeShape(c.id,S,{initialBounds:d,scaleOrigin:new E(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()%Ae)continue;const p=new E(l.minX-d.minX,0),y=this.getShapeParentTransform(c);y&&p.rot(-y.rotation());const{x:f,y:m}=E.Add(p,c);this.updateShapes([{id:c.id,type:c.type,x:f,y:m}],{squashing:!0});const S=new E(l.width/d.width,1);this.resizeShape(c.id,S,{initialBounds:u,scaleOrigin:new E(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 E(1,r.y)),Number.isFinite(r.y)||(r=new E(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(!PP(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 E(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new E(Math.sign(r.x)*Math.abs(r.y),r.y)),h.onResize&&h.canResize(i)){const y=this._scalePagePoint(te.applyToPoint(l,new E(0,0)),a,r,u),f=this.getPointInParentSpace(i.id,y),m=new E(r.x,r.y),S=Ql((c-u)%Math.PI,0);m.x=S?r.x:r.y,m.y=S?r.y:r.x;const w=te.applyToPoint(l,new E),{x,y:C}=this.getPointInParentSpace(i.id,w);this.updateShapes([{id:s,type:i.type,x:f.x,y:f.y,...h.onResize({...i,x,y:C},{newPoint:f,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:m.x,scaleY:m.y,initialBounds:d,initialShape:i})}],{squashing:!0})}else{const y=te.applyToPoint(l,d.center),f=this._scalePagePoint(y,a,r,u),m=this.getPointInParentSpace(i.id,y),S=this.getPointInParentSpace(i.id,f),w=E.Sub(S,m);this.updateShapes([{id:s,type:i.type,x:i.x+w.x,y:i.y+w.y}],{squashing:!0})}return this}_scalePagePoint(t,r,o,s){const i=E.RotWith(t,r,-s).sub(r),a=E.MulV(i,o);return E.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(t,r,o){const{type:s}=o.initialShape,i=new E(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:S}=te.Decompose(o.initialPageTransform);S-=2*S,this.updateShapes([{id:t,type:s,rotation:S}],{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=E.Sub(l,d),y=E.Add(h,p),{x:f,y:m}=this.getPointInParentSpace(t,y);return this.updateShapes([{id:t,type:s,x:f,y:m}],{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=Xt.linear}=r,i=Ne();let a=o,l;const c=[];t.forEach(h=>{if(!h)return;const p={partial:h,values:[]},y=this.getShape(h.id);if(y){for(const f of["x","y","rotation"])h[f]!==void 0&&y[f]!==h[f]&&p.values.push({prop:f,from:y[f],to:h[f]});c.push(p),this.animatingShapes.set(y.id,i)}});let u;const d=h=>{if(a-=h,a<0){const{animatingShapes:y}=this,f=t.filter(m=>m&&y.get(m.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 y=[];for(let f=0;f<c.length;f++)u=c[f],p.get(u.partial.id)===i&&y.push({id:u.partial.id,type:u.partial.type,...u.values.reduce((m,{prop:S,from:w,to:x})=>(m[S]=w+(x-w)*l,m),{})});this._updateShapes(y,{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(y=>y.id);if(o.length<=1)return this;const s=he(this._getUnlockedShapeIds(o).map(y=>this.getShape(y))),i=s.sort(Kt).map(y=>y.id),a=le.Common(he(s.map(y=>this.getShapePageBounds(y)))),{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(y=>y.parentId===u).sort(Kt),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=he(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=he(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,si(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 si(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._selectionSharedStyles.get();const t=this.root.getCurrent(),r=new ky;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=Fh(r.map(l=>this.getShape(l)).sort(Kt).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=ds(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}=d.start.point;l.props.start={type:"point",x:p,y}}else{const{start:p}=Cr(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}=d.end.point;l.props.end={type:"point",x:p,y}}else{const{end:p}=Cr(this,l);l.props.end={type:"point",x:p.x,y:p.y}}const h=bl(l)?tc(this,l):bg(this,l);if(d!=null&&d.isValid&&(h!=null&&h.isValid)&&!bl(l)){const p=E.Med(d.start.handle,d.end.handle),y=E.Dist(d.middle,p),f=E.Dist(h.middle,p);l.props.bend<0?l.props.bend+=f-y:l.props.bend-=f-y}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:he(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(P=>[P.id,We()]));let p=this.getCurrentPageId(),y=1/0,f=[];for(const P of this.getSelectedShapes()){if(y===0)break;const k=this.isShapeOfType(P,"frame"),I=this.getShapeAncestors(P);k&&I.push(P);const _=k?I.length+1:I.length;if(_<y)y=_,f=I,p=k?P.id:P.parentId;else if(_===y){if(f.length!==I.length)throw Error(`Ancestors: ${f.length} !== ${I.length}`);if(f.length===0){p=l;break}else{p=l;for(let $=0;$<f.length&&I[$]===f[$];$++)p=I[$].id}}}let m=!1;if(!gn(p)){const P=this.getShape(p);if(P){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(P)))p=l;else if(d.length===1){const k=u.find(I=>I.id===d[0]);this.isShapeOfType(P,"frame")&&this.isShapeOfType(k,"frame")&&k.props.w===(P==null?void 0:P.props.w)&&k.props.h===(P==null?void 0:P.props.h)&&(m=!0)}}else p=l}m||(m=h.has(p)),m&&(p=this.getShape(p).parentId);let S=this.getHighestIndexForParent(p);const w=[],x=u.map(P=>{let k;if(s)k=qt(P),h.set(P.id,P.id);else{const I=h.get(P.id);k=qt({...P,id:I})}if(d.includes(P.id)&&(k.parentId=l,w.push(k)),h.has(k.parentId)?k.parentId=h.get(P.parentId):(d.push(k.id),k.index=S,S=yo(S)),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(x.length+this.getCurrentPageShapeIds().size>po)return Zu(this),this;let C=[];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 P=[];C=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"))?(P.push(ds(k)),k.props.src=null):P.push(ds(k))),k}),Promise.allSettled(P.map(async k=>{const I=await m8(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(he(k.map(I=>I.status==="fulfilled"&&I.value?{...I.value[1],id:I.value[0].id}:void 0)))})}for(let P=0;P<x.length;P++){const k=x[P],I=this.store.schema.migratePersistedRecord(k,t.schema);if(I.type==="success")x[P]=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(()=>{C.length>0&&this.createAssets(C),this.createShapes(x),o&&this.select(...w.map($=>$.id)),p!==l&&this.reparentShapes(w.map($=>$.id),p);const P=x.map($=>this.getShape($.id)),k=le.Common(P.map($=>this.getShapePageBounds($)));if(a===void 0)if(gn(p)){const $=this.getViewportPageBounds();i||$.includes(le.From(k))?a=k.center:a=$.center}else{const $=this.getShape(p);a=te.applyToPoint(this.getShapePageTransform($),this.getShapeGeometry($).bounds.center)}if(w.length===1){const $=w[0];if(this.isShapeOfType($,"frame"))for(;this.getShapesAtPoint(a).some(T=>this.isShapeOfType(T,"frame")&&T.props.w===$.props.w&&T.props.h===$.props.h);)a.x+=k.w+16}const I=le.Common(he(w.map(({id:$})=>this.getShapePageBounds($)))).center,_=E.Sub(a,I);this.updateShapes(w.map(({id:$})=>{const T=this.getShape($),R=this.getShapeParentTransform($).decompose().rotation,L=E.Rot(_,-R);return{id:T.id,type:T.type,x:T.x+L.x,y:T.y+L.y}}))}),this}async getSvg(t,r={}){var P,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=I4,preserveAspectRatio:l=!1}=r,c=kn({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 y=h.width*s,f=h.height*s,m=window.document.createElementNS("http://www.w3.org/2000/svg","svg");l&&m.setAttribute("preserveAspectRatio",l),m.setAttribute("direction","ltr"),m.setAttribute("width",y+""),m.setAttribute("height",f+""),m.setAttribute("viewBox",`${h.minX} ${h.minY} ${h.width} ${h.height}`),m.setAttribute("stroke-linecap","round"),m.setAttribute("stroke-linejoin","round"),i?p?m.style.setProperty("background",c.solid):m.style.setProperty("background-color",c.background):m.style.setProperty("background-color","transparent");try{(k=(P=document.body).focus)==null||k.call(P)}catch{}const S=window.document.createElementNS("http://www.w3.org/2000/svg","defs");m.append(S);const w=new Map,x={addExportDef:I=>{if(w.has(I.key))return;const _=(async()=>{const $=await I.getElement();if(!$)return;const T=document.createComment(`def: ${I.key}`);S.appendChild(T);for(const R of Array.isArray($)?$:[$])S.appendChild(R)})();w.set(I.key,_)}},C=(await Promise.all(d.map(async({id:I,opacity:_,index:$,backgroundIndex:T})=>{var H,U;if(I===p)return[];const R=this.getShape(I);if(this.isShapeOfType(R,"group"))return[];const L=this.getShapeUtil(R);let N=await((H=L.toSvg)==null?void 0:H.call(L,R,x)),D=await((U=L.toBackgroundSvg)==null?void 0:U.call(L,R,x));if(N){const V=document.createElementNS("http://www.w3.org/2000/svg","g");V.appendChild(N),N=V}if(D){const V=document.createElementNS("http://www.w3.org/2000/svg","g");V.appendChild(D),D=V}if(!N&&!D){const V=this.getShapePageBounds(R),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"),N=X}let z=this.getShapePageTransform(R).toCssString();"scale"in R.props&&R.props.scale!==1&&(z=`${z} scale(${R.props.scale}, ${R.props.scale})`),N==null||N.setAttribute("transform",z),D==null||D.setAttribute("transform",z),N==null||N.setAttribute("opacity",_+""),D==null||D.setAttribute("opacity",_+"");const F=this.getShapeMask(R.id);if(F){const V=document.createElementNS("http://www.w3.org/2000/svg","clipPath");S.appendChild(V);const X=Ne();V.id=X;const re=document.createElementNS("http://www.w3.org/2000/svg","path");if(re.setAttribute("d",`M${F.map(({x:ge,y:Ce})=>`${ge},${Ce}`).join("L")}Z`),V.appendChild(re),N){const ge=document.createElementNS("http://www.w3.org/2000/svg","g");ge.setAttribute("clip-path",`url(#${X})`),ge.appendChild(N),N=ge}if(D){const ge=document.createElementNS("http://www.w3.org/2000/svg","g");ge.setAttribute("clip-path",`url(#${X})`),ge.appendChild(D),D=ge}}const W=[];return N&&W.push({zIndex:$,element:N}),D&&W.push({zIndex:T,element:D}),W}))).flat();await Promise.all(w.values());for(const{element:I}of C.sort((_,$)=>_.zIndex-$.zIndex))m.appendChild(I);return m}_updateInputsFromEvent(t){var y;const{previousScreenPoint:r,previousPagePoint:o,currentScreenPoint:s,currentPagePoint:i}=this.inputs,{screenBounds:a}=this.store.unsafeGetWithoutCapture(sn),{x:l,y:c,z:u}=t.point,{x:d,y:h,z:p}=this.getCamera();r.setTo(s),o.setTo(i),s.set(l,c),i.set((l-a.x)/p-d,(c-a.y)/p-h,u??.5),this.inputs.isPen=t.type==="pointer"&&t.isPen,t.name==="pointer_down"&&this.inputs.pointerVelocity.set(0,0),this.store.put([{id:Kh,typeName:"pointer",x:i.x,y:i.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===L1.CAMERA_MOVE?((y=this.store.get(Kh))==null?void 0:y.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 Zu(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:po})}function nf(){const e=K();return Y("isDarkMode",()=>e.user.getIsDarkMode(),[e])}const q8='<path d="m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z" fill="white"/><path d="m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z" fill="white"/><path d="m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z" fill="black"/><path d="m13 10.814v11.188l2.969-2.866.428-.139h4.768z" fill="black"/>',Z8='<path d="m13.3315 21.3799c-.284-.359-.629-1.093-1.243-1.984-.348-.504-1.211-1.453-1.468-1.935-.223-.426-.199-.617-.146-.97.094-.628.738-1.117 1.425-1.051.519.049.959.392 1.355.716.239.195.533.574.71.788.163.196.203.277.377.509.23.307.302.459.214.121-.071-.496-.187-1.343-.355-2.092-.128-.568-.159-.657-.281-1.093-.129-.464-.195-.789-.316-1.281-.084-.348-.235-1.059-.276-1.459-.057-.547-.087-1.439.264-1.849.275-.321.906-.418 1.297-.22.512.259.803 1.003.936 1.3.239.534.387 1.151.516 1.961.164 1.031.466 2.462.476 2.763.024-.369-.068-1.146-.004-1.5.058-.321.328-.694.666-.795.286-.085.621-.116.916-.055.313.064.643.288.766.499.362.624.369 1.899.384 1.831.086-.376.071-1.229.284-1.584.14-.234.497-.445.687-.479.294-.052.655-.068.964-.008.249.049.586.345.677.487.218.344.342 1.317.379 1.658.015.141.074-.392.293-.736.406-.639 1.843-.763 1.898.639.025.654.02.624.02 1.064 0 .517-.012.828-.04 1.202-.031.4-.117 1.304-.242 1.742-.086.301-.371.978-.652 1.384 0 0-1.074 1.25-1.191 1.813-.118.562-.079.566-.102.965-.023.398.121.922.121.922s-.802.104-1.234.035c-.391-.063-.875-.841-1-1.079-.172-.328-.539-.265-.682-.023-.225.383-.709 1.07-1.051 1.113-.668.084-2.054.031-3.139.02 0 0 .185-1.011-.227-1.358-.305-.259-.83-.784-1.144-1.06z" fill="white"/><g stroke="black" stroke-linecap="round" stroke-width=".75"><path d="m13.3315 21.3799c-.284-.359-.629-1.093-1.243-1.984-.348-.504-1.211-1.453-1.468-1.935-.223-.426-.199-.617-.146-.97.094-.628.738-1.117 1.425-1.051.519.049.959.392 1.355.716.239.195.533.574.71.788.163.196.203.277.377.509.23.307.302.459.214.121-.071-.496-.187-1.343-.355-2.092-.128-.568-.159-.657-.281-1.093-.129-.464-.195-.789-.316-1.281-.084-.348-.235-1.059-.276-1.459-.057-.547-.087-1.439.264-1.849.275-.321.906-.418 1.297-.22.512.259.803 1.003.936 1.3.239.534.387 1.151.516 1.961.164 1.031.466 2.462.476 2.763.024-.369-.068-1.146-.004-1.5.058-.321.328-.694.666-.795.286-.085.621-.116.916-.055.313.064.643.288.766.499.362.624.369 1.899.384 1.831.086-.376.071-1.229.284-1.584.14-.234.497-.445.687-.479.294-.052.655-.068.964-.008.249.049.586.345.677.487.218.344.342 1.317.379 1.658.015.141.074-.392.293-.736.406-.639 1.843-.763 1.898.639.025.654.02.624.02 1.064 0 .517-.012.828-.04 1.202-.031.4-.117 1.304-.242 1.742-.086.301-.371.978-.652 1.384 0 0-1.074 1.25-1.191 1.813-.118.562-.079.566-.102.965-.023.398.121.922.121.922s-.802.104-1.234.035c-.391-.063-.875-.841-1-1.079-.172-.328-.539-.265-.682-.023-.225.383-.709 1.07-1.051 1.113-.668.084-2.054.031-3.139.02 0 0 .185-1.011-.227-1.358-.305-.259-.83-.784-1.144-1.06z" stroke-linejoin="round"/><path d="m21.5664 21.7344v-3.459"/><path d="m19.5508 21.7461-.016-3.473"/><path d="m17.5547 18.3047.021 3.426"/></g>',Q8='<path d="m25 16h-6.01v-6h-2.98v6h-6.01v3h6.01v6h2.98v-6h6.01z" fill="white"/><path d="m23.9902 17.0103h-6v-6.01h-.98v6.01h-6v.98h6v6.01h.98v-6.01h6z" fill="%23231f1f"/>',J8='<path d="m19 14h1v1h-1zm1 6h-1v-1h1zm-5-5h-1v-1h1zm0 5h-1v-1h1zm2-10.987-7.985 7.988 5.222 5.221 2.763 2.763 7.984-7.985z" fill="white"/><g fill="black"><path d="m23.5664 16.9971-2.557-2.809v1.829h-4.009-4.001v-1.829l-2.571 2.809 2.572 2.808-.001-1.808h4.001 4.009l-.001 1.808z"/><path d="m17.9873 17h.013v-4.001l1.807.001-2.807-2.571-2.809 2.57h1.809v4.001h.008v4.002l-1.828-.001 2.807 2.577 2.805-2.576h-1.805z"/></g>',mx="<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'/>",yx="<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'/>",Qu='<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"/>',ej='<path fill="white" d="M7.94 0a5.25 5.25 0 0 0-3.47 1.17A5.27 5.27 0 0 0 1 0H0v3h1c1.41 0 1.85.7 2 1v3.94H2v3h1v3c-.13.3-.57 1-2 1H0v3h1a5.27 5.27 0 0 0 3.47-1.17c.98.8 2.21 1.21 3.47 1.17h1v-3h-1c-1.41 0-1.85-.7-2-1v-3H7v-3H6V4c.13-.3.57-1 2-1h1V0H7.94z"/><path fill="black" d="M7.94 2V1a4 4 0 0 0-3.47 1.64A4 4 0 0 0 1 1v1c1.3-.17 2.56.6 3 1.84v5.1H3v1h1v4.16c-.45 1.24-1.7 2-3 1.84v1a4.05 4.05 0 0 0 3.47-1.63 4.05 4.05 0 0 0 3.47 1.63v-1A2.82 2.82 0 0 1 5 14.1V9.93h1v-1H5V3.85A2.81 2.81 0 0 1 7.94 2z"/>',tj="<path d='m13.5732 12.0361c.48-.178 1.427-.069 1.677.473.213.462.396 1.241.406 1.075.024-.369-.024-1.167.137-1.584.117-.304.347-.59.686-.691.285-.086.62-.116.916-.055.313.064.642.287.765.499.362.623.368 1.899.385 1.831.064-.272.07-1.229.283-1.584.141-.235.497-.445.687-.479.294-.052.656-.068.964-.008.249.049.586.344.677.487.219.344.342 1.316.379 1.658.016.141.074-.393.293-.736.406-.639 1.844-.763 1.898.639.026.654.02.624.02 1.064 0 .516-.012.828-.04 1.202-.03.399-.116 1.304-.241 1.742-.086.301-.371.978-.653 1.384 0 0-1.074 1.25-1.191 1.812-.117.563-.078.567-.102.965-.023.399.121.923.121.923s-.801.104-1.234.034c-.391-.062-.875-.84-1-1.078-.172-.328-.539-.265-.682-.023-.224.383-.709 1.07-1.05 1.113-.669.084-2.055.03-3.14.02 0 0 .185-1.011-.227-1.358-.305-.26-.83-.784-1.144-1.06l-.832-.921c-.283-.36-1.002-.929-1.243-1.985-.213-.936-.192-1.395.037-1.77.232-.381.67-.589.854-.625.208-.042.692-.039.875.062.223.123.313.159.488.391.23.307.312.456.213.121-.076-.262-.322-.595-.434-.97-.109-.361-.401-.943-.38-1.526.008-.221.103-.771.832-1.042' fill='white'/><g stroke='black' stroke-width='.75'><path d='m13.5732 12.0361c.48-.178 1.427-.069 1.677.473.213.462.396 1.241.406 1.075.024-.369-.024-1.167.137-1.584.117-.304.347-.59.686-.691.285-.086.62-.116.916-.055.313.064.642.287.765.499.362.623.368 1.899.385 1.831.064-.272.07-1.229.283-1.584.141-.235.497-.445.687-.479.294-.052.656-.068.964-.008.249.049.586.344.677.487.219.344.342 1.316.379 1.658.016.141.074-.393.293-.736.406-.639 1.844-.763 1.898.639.026.654.02.624.02 1.064 0 .516-.012.828-.04 1.202-.03.399-.116 1.304-.241 1.742-.086.301-.371.978-.653 1.384 0 0-1.074 1.25-1.191 1.812-.117.563-.078.567-.102.965-.023.399.121.923.121.923s-.801.104-1.234.034c-.391-.062-.875-.84-1-1.078-.172-.328-.539-.265-.682-.023-.224.383-.709 1.07-1.05 1.113-.669.084-2.055.03-3.14.02 0 0 .185-1.011-.227-1.358-.305-.26-.83-.784-1.144-1.06l-.832-.921c-.283-.36-1.002-.929-1.243-1.985-.213-.936-.192-1.395.037-1.77.232-.381.67-.589.854-.625.208-.042.692-.039.875.062.223.123.313.159.488.391.23.307.312.456.213.121-.076-.262-.322-.595-.434-.97-.109-.361-.401-.943-.38-1.526.008-.221.103-.771.832-1.042z' stroke-linejoin='round'/><path d='m20.5664 19.7344v-3.459' stroke-linecap='round'/><path d='m18.5508 19.7461-.016-3.473' stroke-linecap='round'/><path d='m16.5547 16.3047.021 3.426' stroke-linecap='round'/></g>",nj='<path d="m13.5557 17.5742c-.098-.375-.196-.847-.406-1.552-.167-.557-.342-.859-.47-1.233-.155-.455-.303-.721-.496-1.181-.139-.329-.364-1.048-.457-1.44-.119-.509.033-.924.244-1.206.253-.339.962-.49 1.357-.351.371.13.744.512.916.788.288.46.357.632.717 1.542.393.992.564 1.918.611 2.231l.085.452c-.001-.04-.043-1.122-.044-1.162-.035-1.029-.06-1.823-.038-2.939.002-.126.064-.587.084-.715.078-.5.305-.8.673-.979.412-.201.926-.215 1.401-.017.423.173.626.55.687 1.022.014.109.094.987.093 1.107-.013 1.025.006 1.641.015 2.174.004.231.003 1.625.017 1.469.061-.656.094-3.189.344-3.942.144-.433.405-.746.794-.929.431-.203 1.113-.07 1.404.243.285.305.446.692.482 1.153.032.405-.019.897-.02 1.245 0 .867-.021 1.324-.037 2.121-.001.038-.015.298.023.182.094-.28.188-.542.266-.745.049-.125.241-.614.359-.859.114-.234.211-.369.415-.688.2-.313.415-.448.668-.561.54-.235 1.109.112 1.301.591.086.215.009.713-.028 1.105-.061.647-.254 1.306-.352 1.648-.128.447-.274 1.235-.34 1.601-.072.394-.234 1.382-.359 1.82-.086.301-.371.978-.652 1.384 0 0-1.074 1.25-1.192 1.812-.117.563-.078.567-.101.965-.024.399.121.923.121.923s-.802.104-1.234.034c-.391-.062-.875-.841-1-1.078-.172-.328-.539-.265-.682-.023-.225.383-.709 1.07-1.051 1.113-.668.084-2.054.03-3.139.02 0 0 .185-1.011-.227-1.358-.305-.26-.83-.784-1.144-1.06l-.832-.921c-.284-.36-.629-1.093-1.243-1.985-.348-.504-1.027-1.085-1.284-1.579-.223-.425-.331-.954-.19-1.325.225-.594.675-.897 1.362-.832.519.05.848.206 1.238.537.225.19.573.534.75.748.163.195.203.276.377.509.23.307.302.459.214.121" fill="white"/><g stroke="black" stroke-linecap="round" stroke-width=".75"><path d="m13.5557 17.5742c-.098-.375-.196-.847-.406-1.552-.167-.557-.342-.859-.47-1.233-.155-.455-.303-.721-.496-1.181-.139-.329-.364-1.048-.457-1.44-.119-.509.033-.924.244-1.206.253-.339.962-.49 1.357-.351.371.13.744.512.916.788.288.46.357.632.717 1.542.393.992.564 1.918.611 2.231l.085.452c-.001-.04-.043-1.122-.044-1.162-.035-1.029-.06-1.823-.038-2.939.002-.126.064-.587.084-.715.078-.5.305-.8.673-.979.412-.201.926-.215 1.401-.017.423.173.626.55.687 1.022.014.109.094.987.093 1.107-.013 1.025.006 1.641.015 2.174.004.231.003 1.625.017 1.469.061-.656.094-3.189.344-3.942.144-.433.405-.746.794-.929.431-.203 1.113-.07 1.404.243.285.305.446.692.482 1.153.032.405-.019.897-.02 1.245 0 .867-.021 1.324-.037 2.121-.001.038-.015.298.023.182.094-.28.188-.542.266-.745.049-.125.241-.614.359-.859.114-.234.211-.369.415-.688.2-.313.415-.448.668-.561.54-.235 1.109.112 1.301.591.086.215.009.713-.028 1.105-.061.647-.254 1.306-.352 1.648-.128.447-.274 1.235-.34 1.601-.072.394-.234 1.382-.359 1.82-.086.301-.371.978-.652 1.384 0 0-1.074 1.25-1.192 1.812-.117.563-.078.567-.101.965-.024.399.121.923.121.923s-.802.104-1.234.034c-.391-.062-.875-.841-1-1.078-.172-.328-.539-.265-.682-.023-.225.383-.709 1.07-1.051 1.113-.668.084-2.054.03-3.139.02 0 0 .185-1.011-.227-1.358-.305-.26-.83-.784-1.144-1.06l-.832-.921c-.284-.36-.629-1.093-1.243-1.985-.348-.504-1.027-1.085-1.284-1.579-.223-.425-.331-.954-.19-1.325.225-.594.675-.897 1.362-.832.519.05.848.206 1.238.537.225.19.573.534.75.748.163.195.203.276.377.509.23.307.302.459.214.121" stroke-linejoin="round"/><path d="m20.5664 21.7344v-3.459"/><path d="m18.5508 21.7461-.016-3.473"/><path d="m16.5547 18.3047.021 3.426"/></g>',rj='<path d="m20.5 15c0 3.038-2.462 5.5-5.5 5.5s-5.5-2.462-5.5-5.5 2.462-5.5 5.5-5.5 5.5 2.462 5.5 5.5" fill="white"/><path d="m20.5 15c0 3.038-2.462 5.5-5.5 5.5s-5.5-2.462-5.5-5.5 2.462-5.5 5.5-5.5 5.5 2.462 5.5 5.5z" stroke="black"/><g fill="black"><path d="m18 14h-2v-2h-2v2h-2v1.98h2v2.02h2v-2.02h2z"/><path d="m23.5859 25 1.414-1.414-5.449-5.449-1.414 1.414z"/></g>',oj='<path d="m20.5 15c0 3.038-2.462 5.5-5.5 5.5s-5.5-2.462-5.5-5.5 2.462-5.5 5.5-5.5 5.5 2.462 5.5 5.5" fill="white"/><path d="m20.5 15c0 3.038-2.462 5.5-5.5 5.5s-5.5-2.462-5.5-5.5 2.462-5.5 5.5-5.5 5.5 2.462 5.5 5.5z" stroke="black"/><g fill="black"><path d="m18 16h-5.98v-1.98h5.98z"/><path d="m23.5859 25 1.414-1.414-5.449-5.449-1.414 1.414z"/></g>';function _t(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 sj={none:()=>"none",default:(e,n,t)=>_t(q8,e,0,n,t,12,8),pointer:(e,n,t)=>_t(Z8,e,0,n,t,14,10),cross:(e,n,t)=>_t(Q8,e,0,n,t),move:(e,n,t)=>_t(J8,e,0,n,t),grab:(e,n,t)=>_t(nj,e,0,n,t),grabbing:(e,n,t)=>_t(tj,e,0,n,t),text:(e,n,t)=>_t(ej,e,0,n,t,4,10),"ew-resize":(e,n,t)=>_t(yx,e,0,n,t),"ns-resize":(e,n,t)=>_t(yx,e,90,n,t),"nesw-resize":(e,n,t)=>_t(mx,e,0,n,t),"nwse-resize":(e,n,t)=>_t(mx,e,90,n,t),"nwse-rotate":(e,n,t)=>_t(Qu,e,0,n,t),"nesw-rotate":(e,n,t)=>_t(Qu,e,90,n,t),"senw-rotate":(e,n,t)=>_t(Qu,e,180,n,t),"swne-rotate":(e,n,t)=>_t(Qu,e,270,n,t),"zoom-in":(e,n,t)=>_t(rj,e,0,n,t),"zoom-out":(e,n,t)=>_t(oj,e,0,n,t)};function An(e,n=0,t="black"){return sj[e](f4(n),!1,t)}const ij=["default","pointer","cross","move","grab","grabbing","text"];function aj(){const e=K(),n=tn(),t=nf();ri("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(ij.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",An(r,o,t?"white":"black"))},[e,n,t])}function lj(){const e=K(),n=tn(),t=nf(),r=Y(He.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 cj(e){const n=b.useRef();return b.useLayoutEffect(()=>{n.current=e}),b.useDebugValue(e),b.useCallback((...t)=>{const r=n.current;return oi(r,"fn does not exist"),r(...t)},[])}function uj(e){const n=K(),t=tn();b.useLayoutEffect(()=>{e?(n.getInstanceState().isFocused||n.updateInstanceState({isFocused:!0}),n.getContainer().focus()):n.getInstanceState().isFocused&&n.updateInstanceState({isFocused:!1})},[n,t,e])}function dj(){const[e,n]=b.useState(0);b.useEffect(()=>n(t=>t+1),[])}const xa="TLDRAW_TAB_ID_v2",At=globalThis.window;function hj(){return At?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(At.navigator.platform)||At.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const cp=(At==null?void 0:At[xa])??(At==null?void 0:At.sessionStorage[xa])??"TLDRAW_INSTANCE_STATE_V1_"+Ne();At&&(At[xa]=cp,hj()?At.sessionStorage[xa]=cp:delete At.sessionStorage[xa]);At==null||At.addEventListener("beforeunload",()=>{At.sessionStorage[xa]=cp});const pj={Initial:0},Cc=pj.Initial,hE=Pe({version:fe,currentPageId:mc,isFocusMode:we,exportBackground:we,isDebugMode:we,isToolLocked:we,isGridMode:we,pageStates:ln(Pe({pageId:mc,camera:Pe({x:fe,y:fe,z:fe}),selectedShapeIds:ln(vr),focusedGroupId:vr.nullable()}))}),fj=$e({currentVersion:Cc});function gj(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=mv({value:e,fromVersion:e.version,toVersion:Cc,migrations:fj});if(n.type==="error")return console.warn(n.reason),null;const t={...n.value,version:Cc};try{hE.validate(t)}catch(r){return console.warn(r),null}return t}function mj(e){const n=e.query.ids("page");return Z("sessionStateSnapshot",()=>{const t=e.get(sn);if(!t)return null;const r=[...n.get()];return{version:Cc,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(Vt.createId(o)),i=e.get(Ht.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 yj(e,n){const t=gj(n);if(!t)return;const r=e.allRecords().filter(i=>i.typeName==="instance_page_state"||i.typeName==="camera"),o={added:{},updated:{},removed:{...iP(r.map(i=>[i.id,i]))}};e.has(sn)&&(o.removed[sn]=e.get(sn));const s={removed:{},updated:{},added:{[sn]:e.schema.types.instance.create({id:sn,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=Ht.createId(i.pageId),l=Vt.createId(i.pageId);s.added[a]=Ht.create({id:Ht.createId(i.pageId),x:i.camera.x,y:i.camera.y,z:i.camera.z}),s.added[l]=Vt.create({id:Vt.createId(i.pageId),pageId:i.pageId,selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId})}nr(()=>{e.applyDiff(qp([o,s])),e.ensureStoreIsUsable()})}function vj(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!==sn)[0];if(!t)return null;const r={version:Cc,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 hE.validate(r),r}catch{return null}}function Sj(){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 wj(){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 xj=(e,n)=>n.some(t=>e instanceof t);let vx,Sx;function bj(){return vx||(vx=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Cj(){return Sx||(Sx=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const pE=new WeakMap,Iy=new WeakMap,fE=new WeakMap,Cg=new WeakMap,Lv=new WeakMap;function Pj(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(ko(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return n.then(t=>{t instanceof IDBCursor&&pE.set(t,e)}).catch(()=>{}),Lv.set(n,e),n}function Ej(e){if(Iy.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)});Iy.set(e,n)}let _y={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return Iy.get(e);if(n==="objectStoreNames")return e.objectStoreNames||fE.get(e);if(n==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return ko(e[n])},set(e,n,t){return e[n]=t,!0},has(e,n){return e instanceof IDBTransaction&&(n==="done"||n==="store")?!0:n in e}};function kj(e){_y=e(_y)}function Ij(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(Pg(this),n,...t);return fE.set(r,n.sort?n.sort():[n]),ko(r)}:Cj().includes(e)?function(...n){return e.apply(Pg(this),n),ko(pE.get(this))}:function(...n){return ko(e.apply(Pg(this),n))}}function _j(e){return typeof e=="function"?Ij(e):(e instanceof IDBTransaction&&Ej(e),xj(e,bj())?new Proxy(e,_y):e)}function ko(e){if(e instanceof IDBRequest)return Pj(e);if(Cg.has(e))return Cg.get(e);const n=_j(e);return n!==e&&(Cg.set(e,n),Lv.set(n,e)),n}const Pg=e=>Lv.get(e);function Tj(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=ko(i);return r&&i.addEventListener("upgradeneeded",l=>{r(ko(i.result),l.oldVersion,l.newVersion,ko(i.transaction),l)}),t&&i.addEventListener("blocked",l=>t(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),o&&l.addEventListener("versionchange",c=>o(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function $j(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),ko(t).then(()=>{})}const Mj=["get","getKey","getAll","getAllKeys","count"],Aj=["put","add","delete","clear"],Eg=new Map;function wx(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(Eg.get(n))return Eg.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=Aj.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||Mj.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 Eg.set(n,s),s}kj(e=>({...e,get:(n,t,r)=>wx(n,t)||e.get(n,t,r),has:(n,t)=>!!wx(n,t)||e.has(n,t)}));const rf="TLDRAW_DOCUMENT_v2",gE="TLDRAW_DB_NAME_INDEX_v2",Me={Records:"records",Schema:"schema",SessionState:"session_state"};async function of(e,n){Lj(e);const t=await Tj(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 Oj({persistenceKey:e,sessionId:n,didCancel:t}){const r=rf+e;if(Nv().includes(r))return await jj({persistenceKey:e,didCancel:t}),await of(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((y,f)=>y.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 Rj({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=rf+e;await of(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 Dj({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=rf+e;await of(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 jj({persistenceKey:e,didCancel:n}){await of(rf+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 Nv(){const e=JSON.parse((window==null?void 0:window.localStorage.getItem(gE))||"[]")??[];return Array.isArray(e)?e:[]}function Lj(e){const n=new Set(Nv());n.add(e),window==null||window.localStorage.setItem(gE,JSON.stringify([...n]))}const Nj=350,zj=1e4,xx=Symbol("UPDATE_INSTANCE_STATE"),Fj=e=>e;class Bj{constructor(n){v(this,"onmessage")}postMessage(n){}close(){}}const Uj=typeof BroadcastChannel>"u"?Bj:BroadcastChannel;class Hj{constructor(n,{persistenceKey:t,sessionId:r=cp,onLoad:o,onLoadError:s},i=new Uj(`tldraw-tab-sync-${t}`)){v(this,"disposables",new Set);v(this,"diffQueue",[]);v(this,"didDispose",!1);v(this,"shouldDoFullDBWrite",!0);v(this,"isReloading",!1);v(this,"persistenceKey");v(this,"sessionId");v(this,"serializedSchema");v(this,"isDebugging",!1);v(this,"documentTypes");v(this,"$sessionStateSnapshot");v(this,"initTime",Date.now());v(this,"isPersisting",!1);v(this,"didLastWriteError",!1);v(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=mj(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(Fj({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(xx),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 Oj({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),wj(),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??vj(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&&yj(this.store,s)}this.channel.onmessage=({data:o})=>{var a,l;this.debug("got message",o);const s=o,i=w5(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"),nr(()=>{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?zj:Nj))}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(){oi(!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 Dj({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=qp(n.filter(r=>r!==xx));await Rj({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),Sj(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function mE({initialData:e,defaultName:n="",...t}){const r="schema"in t&&t.schema?t.schema:pO({shapes:Vj(iE("shapeUtils"in t&&t.shapeUtils?t.shapeUtils:[]))});return new lP({schema:r,initialData:e,props:{defaultName:n}})}function Vj(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function bx(e){const n=mE(e);return e.snapshot&&n.loadSnapshot(e.snapshot),{store:n,opts:e}}function Kj(e){const[n,t]=b.useState(()=>bx(e));if(!aP(n.opts,e)){const r=bx(e);return t(r),r.store}return n.store}function Wj({persistenceKey:e,sessionId:n,...t}){const[r,o]=b.useState(null),s=Kj(t);return b.useEffect(()=>{const i=Ne();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 Hj(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 yE=!1;if(typeof window<"u"){const e=window.navigator.userAgent,n=!!e.match(/iPad/i)||!!e.match(/iPhone/i),t=!!e.match(/WebKit/i);yE=n&&t&&!e.match(/CriOS/i)}function Gj(){const e=K();b.useEffect(()=>{if(!yE)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 Yj(){const e=K(),n=tn();b.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=sP(t,100),o=new Ka("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach()}},[e,n])}const Xj=[],qj=[],Zj=b.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=ne.useState(null),l=b.useMemo(()=>o??tE(),[o]),c=(t==null?void 0:t.ErrorFallback)===void 0?IP:t==null?void 0:t.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??Xj,tools:s.tools??qj,components:t};return g.jsx("div",{ref:a,draggable:!1,className:pe("tl-container tl-theme__light",r),onPointerDown:bt,tabIndex:-1,children:g.jsx(Sc,{fallback:c,onError:d=>fv(d,{tags:{origin:"react.tldraw-before-app"}}),children:i&&g.jsx(t4,{container:i,children:g.jsx(W4,{overrides:t,children:n?n instanceof lP?g.jsx(SE,{...u,store:n,user:l}):g.jsx(vE,{...u,store:n,user:l}):g.jsx(Qj,{...u,store:n,user:l})})})})})});function Qj(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,persistenceKey:s,sessionId:i,user:a}=e,l=Wj({shapeUtils:o,initialData:r,persistenceKey:s,sessionId:i,defaultName:n,snapshot:t});return g.jsx(vE,{...e,store:l,user:a})}const vE=b.memo(function({store:n,user:t,...r}){var s;const o=tn();switch(b.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)??QD;return g.jsx(i,{})}}return g.jsx(SE,{...r,store:n.store,user:t})});function SE({onMount:e,children:n,store:t,tools:r,shapeUtils:o,user:s,initialState:i,autoFocus:a=!0,inferDarkMode:l}){const{ErrorFallback:c}=Pt(),u=tn(),[d,h]=b.useState(null);b.useLayoutEffect(()=>{const y=new ce({store:t,shapeUtils:o,tools:r,getContainer:()=>u,user:s,initialState:i,inferDarkMode:l});return window.app=y,window.editor=y,h(y),()=>{y.dispose()}},[u,o,r,t,s,i,l]);const p=b.useSyncExternalStore(b.useCallback(y=>d?(d.on("crash",y),()=>d.off("crash",y)):()=>{},[d]),()=>(d==null?void 0:d.getCrashingError())??null);return d?g.jsx(Sc,{fallback:c,onError:y=>d.annotateError(y,{origin:"react.tldraw",willCrashApp:!0}),children:p?g.jsx(eL,{crashingError:p}):g.jsx(Ev.Provider,{value:d,children:g.jsx(Jj,{autoFocus:a,onMount:e,children:n})})}):null}function Jj({children:e,onMount:n,autoFocus:t}){return Yj(),aj(),lj(),Gj(),dj(),uj(t),nL(n),kD(),K().updateViewportScreenBounds(),e??g.jsx(Av,{})}function eL({crashingError:e}){throw e}function wE({children:e}){const{Spinner:n}=Pt();return g.jsxs("div",{className:"tl-loading",children:[n?g.jsx(n,{}):null,e]})}function tL({children:e}){return g.jsx("div",{className:"tl-loading",children:e})}function nL(e){const n=K(),t=cj(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 ui({children:e,className:n="",...t}){return g.jsx("div",{...t,className:`tl-html-container ${n}`,children:e})}Re(function({x:n=0,y:t=0,rotation:r=0,...o}){const s=K(),i=b.useRef(null),a=s.getCamera();return b.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:pe("tl-positioned",o.className)})});function xE(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 E(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:y,y:f}=p.rot(e.rotation).add(r);return{x:y,y:f,props:{w:Math.min(l,d),h:Math.min(u,h)}}}class Qa extends Tr{constructor(){super(...arguments);v(this,"onResize",(t,r)=>xE(t,r))}getGeometry(t){return new xs({width:t.props.w,height:t.props.h,isFilled:!0})}}var Ym;let rL=(Ym=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(Ym,"id","idle"),Ym);var Xm;let oL=(Xm=class extends ie{constructor(){super(...arguments);v(this,"markId","");v(this,"wasFocusedOnEnter",!1);v(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});v(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})}});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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 E(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")}},v(Xm,"id","pointing"),Xm);class Xd extends ie{constructor(){super(...arguments);v(this,"onCreate")}}v(Xd,"id","box"),v(Xd,"initial","idle"),v(Xd,"children",()=>[rL,oL]);function bE(e,n){const t=b.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Cx(e){return bE(e,n5)}function sL(e){return bE(e,aP)}function Px(e){const n=K();return Y("isCropping",()=>n.getCroppingShapeId()===e,[n,e])}function sf(e){const n=K();return Y("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function Br(e){const n=K();return b.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===2){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...Sn(c)});return}if(c.button!==0)return;const u=Zh(c.currentTarget);function d(){u.removeEventListener("pointerup",d),iu(u,c)}su(u,c),u.addEventListener("pointerup",d),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...Sn(c)}),bt(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,...Sn(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...Sn(c)})}}},[n,e])}const iL=20,aL=8;function zv(e,n=iL){return Math.max(aL,Math.ceil(e/n))}class lL extends wi{constructor(t){super({...t,isFilled:!1,isClosed:!1});v(this,"_center");v(this,"radius");v(this,"start");v(this,"end");v(this,"measure");v(this,"length");v(this,"angleStart");v(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=E.Angle(r,a),this.angleEnd=E.Angle(r,l),this.measure=cL(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=Ex(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 y of[l,c,d])t.dist(y)<h&&(p=y,h=t.dist(y));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=tf(t,r,s,i);return u===null?!1:u.some(d=>{const h=Ex(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=zv(Math.abs(o));l<c+1;l++){const u=l/c*r,d=i+u;a.push(t.clone().add(new E(Math.cos(d),Math.sin(d)).mul(s)))}return a}}function Ex(e,n,t,r){let o;if(Math.abs(e)>Te){o=Jl(n,r);const s=Jl(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else return o=Jl(n,r),o/e}function cL(e,n,t,r){const o=2*((n-e)%Ae)%Ae-(n-e)%Ae;return r?(Ae-Math.abs(o))*(t?1:-1):o}class CE extends wi{constructor(t){super({isClosed:!0,...t});v(this,"_center");v(this,"radius");v(this,"x");v(this,"y");this.config=t;const{x:r=0,y:o=0,radius:s}=t;this.x=r,this.y=o,this._center=new E(s+r,s+o),this.radius=s}getBounds(){return new le(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,o=Ae*r,s=[];for(let i=0,a=zv(o);i<a;i++){const l=i/a*Ae;s.push(t.clone().add(E.FromAngle(l).mul(r)))}return s}nearestPoint(t){const{_center:r,radius:o}=this;return r.equals(t)?E.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 tf(t,r,s,i)!==null}}class uL extends xi{constructor(t){const{start:r,cp1:o,cp2:s,end:i}=t;super({...t,points:[r,i]});v(this,"a");v(this,"b");v(this,"c");v(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 E((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 dL(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 dL(e,n){const{a:t,b:r,c:o,d:s}=e;return new E((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 qd extends wi{constructor(t){super({...t,isClosed:!1,isFilled:!1});v(this,"points");v(this,"_segments");v(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 E(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),p=i===o?c:new E(c.x-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),y=c;this._segments.push(new uL({start:d,cp1:h,cp2:p,end:y}))}}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 PE extends wi{constructor(t){super({...t,isClosed:!0});v(this,"w");v(this,"h");v(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 ip({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=zv(a),c=Ae/l,u=Math.cos(c),d=Math.sin(c);let h=0,p=1,y=0,f=1;const m=Array(l);for(let S=0;S<l;S++)m[S]=new E(o+o*p,s+s*h),y=d*p+u*h,f=u*p-d*h,h=y,p=f;return m}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 le(0,0,this.w,this.h)}}class hL extends PE{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 E(r+r*Math.cos(l),r+r*Math.sin(l)),i[a+(s-1)]=new E(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 E(n-o+o*Math.cos(l),t-o+o*Math.sin(l)),i[a+(s-1)]=new E(o-o*Math.cos(c),t-o+o*Math.sin(c))}return i}}function kx(e,n){return e<0?1:e>n?-1:e<Li?(Li-e)/Li:e>n-Li?-(Li-n+e)/Li:0}function Fv(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,a=kx(n-o.x,o.w),l=kx(t-o.y,o.h);if(a===0&&l===0)return;const c=e.user.getEdgeScrollSpeed()*O4,u=c*a*s/r,d=c*l*i/r,h=e.getCamera();e.setCamera({x:h.x+u,y:h.y+d})}async function pL({shouldReload:e=!0}={}){sessionStorage.clear(),await Promise.all(Nv().map(n=>$j(n))),localStorage.clear(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=pL);function fL(e,n="_blank"){kv.openWindow(e,n)}var Cl=function(e){return e&&e.Math===Math&&e},In=Cl(typeof globalThis=="object"&&globalThis)||Cl(typeof window=="object"&&window)||Cl(typeof self=="object"&&self)||Cl(typeof Ot=="object"&&Ot)||Cl(typeof Ot=="object"&&Ot)||function(){return this}()||Function("return this")(),Bv={},hn=function(e){try{return!!e()}catch{return!0}},gL=hn,As=!gL(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),mL=hn,af=!mL(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),yL=af,Ju=Function.prototype.call,Os=yL?Ju.bind(Ju):function(){return Ju.apply(Ju,arguments)},EE={},kE={}.propertyIsEnumerable,IE=Object.getOwnPropertyDescriptor,vL=IE&&!kE.call({1:2},1);EE.f=vL?function(n){var t=IE(this,n);return!!t&&t.enumerable}:kE;var _E=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},TE=af,$E=Function.prototype,Ty=$E.call,SL=TE&&$E.bind.bind(Ty,Ty),Et=TE?SL:function(e){return function(){return Ty.apply(e,arguments)}},ME=Et,wL=ME({}.toString),xL=ME("".slice),Ja=function(e){return xL(wL(e),8,-1)},bL=Et,CL=hn,PL=Ja,kg=Object,EL=bL("".split),kL=CL(function(){return!kg("z").propertyIsEnumerable(0)})?function(e){return PL(e)==="String"?EL(e,""):kg(e)}:kg,lf=function(e){return e==null},IL=lf,_L=TypeError,el=function(e){if(IL(e))throw new _L("Can't call method on "+e);return e},TL=kL,$L=el,cf=function(e){return TL($L(e))},Ig=typeof document=="object"&&document.all,pn=typeof Ig>"u"&&Ig!==void 0?function(e){return typeof e=="function"||e===Ig}:function(e){return typeof e=="function"},ML=pn,Ci=function(e){return typeof e=="object"?e!==null:ML(e)},_g=In,AL=pn,OL=function(e){return AL(e)?e:void 0},uf=function(e,n){return arguments.length<2?OL(_g[e]):_g[e]&&_g[e][n]},RL=Et,AE=RL({}.isPrototypeOf),DL=typeof navigator<"u"&&String(navigator.userAgent)||"",OE=In,Tg=DL,Ix=OE.process,_x=OE.Deno,Tx=Ix&&Ix.versions||_x&&_x.version,$x=Tx&&Tx.v8,xr,up;$x&&(xr=$x.split("."),up=xr[0]>0&&xr[0]<4?1:+(xr[0]+xr[1]));!up&&Tg&&(xr=Tg.match(/Edge\/(\d+)/),(!xr||xr[1]>=74)&&(xr=Tg.match(/Chrome\/(\d+)/),xr&&(up=+xr[1])));var jL=up,Mx=jL,LL=hn,NL=In,zL=NL.String,RE=!!Object.getOwnPropertySymbols&&!LL(function(){var e=Symbol("symbol detection");return!zL(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&Mx&&Mx<41}),FL=RE,DE=FL&&!Symbol.sham&&typeof Symbol.iterator=="symbol",BL=uf,UL=pn,HL=AE,VL=DE,KL=Object,jE=VL?function(e){return typeof e=="symbol"}:function(e){var n=BL("Symbol");return UL(n)&&HL(n.prototype,KL(e))},WL=String,GL=function(e){try{return WL(e)}catch{return"Object"}},YL=pn,XL=GL,qL=TypeError,Uv=function(e){if(YL(e))return e;throw new qL(XL(e)+" is not a function")},ZL=Uv,QL=lf,Hv=function(e,n){var t=e[n];return QL(t)?void 0:ZL(t)},$g=Os,Mg=pn,Ag=Ci,JL=TypeError,e7=function(e,n){var t,r;if(n==="string"&&Mg(t=e.toString)&&!Ag(r=$g(t,e))||Mg(t=e.valueOf)&&!Ag(r=$g(t,e))||n!=="string"&&Mg(t=e.toString)&&!Ag(r=$g(t,e)))return r;throw new JL("Can't convert object to primitive value")},LE={exports:{}},Ax=In,t7=Object.defineProperty,Vv=function(e,n){try{t7(Ax,e,{value:n,configurable:!0,writable:!0})}catch{Ax[e]=n}return n},n7=In,r7=Vv,Ox="__core-js_shared__",o7=n7[Ox]||r7(Ox,{}),Kv=o7,Rx=Kv;(LE.exports=function(e,n){return Rx[e]||(Rx[e]=n!==void 0?n:{})})("versions",[]).push({version:"3.35.0",mode:"global",copyright:"© 2014-2023 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.35.0/LICENSE",source:"https://github.com/zloirock/core-js"});var Wv=LE.exports,s7=el,i7=Object,hu=function(e){return i7(s7(e))},a7=Et,l7=hu,c7=a7({}.hasOwnProperty),Rs=Object.hasOwn||function(n,t){return c7(l7(n),t)},u7=Et,d7=0,h7=Math.random(),p7=u7(1 .toString),NE=function(e){return"Symbol("+(e===void 0?"":e)+")_"+p7(++d7+h7,36)},f7=In,g7=Wv,Dx=Rs,m7=NE,y7=RE,v7=DE,ta=f7.Symbol,Og=g7("wks"),S7=v7?ta.for||ta:ta&&ta.withoutSetter||m7,Uo=function(e){return Dx(Og,e)||(Og[e]=y7&&Dx(ta,e)?ta[e]:S7("Symbol."+e)),Og[e]},w7=Os,jx=Ci,Lx=jE,x7=Hv,b7=e7,C7=Uo,P7=TypeError,E7=C7("toPrimitive"),k7=function(e,n){if(!jx(e)||Lx(e))return e;var t=x7(e,E7),r;if(t){if(n===void 0&&(n="default"),r=w7(t,e,n),!jx(r)||Lx(r))return r;throw new P7("Can't convert object to primitive value")}return n===void 0&&(n="number"),b7(e,n)},I7=k7,_7=jE,zE=function(e){var n=I7(e,"string");return _7(n)?n:n+""},T7=In,Nx=Ci,$y=T7.document,$7=Nx($y)&&Nx($y.createElement),FE=function(e){return $7?$y.createElement(e):{}},M7=As,A7=hn,O7=FE,BE=!M7&&!A7(function(){return Object.defineProperty(O7("div"),"a",{get:function(){return 7}}).a!==7}),R7=As,D7=Os,j7=EE,L7=_E,N7=cf,z7=zE,F7=Rs,B7=BE,zx=Object.getOwnPropertyDescriptor;Bv.f=R7?zx:function(n,t){if(n=N7(n),t=z7(t),B7)try{return zx(n,t)}catch{}if(F7(n,t))return L7(!D7(j7.f,n,t),n[t])};var tl={},U7=As,H7=hn,UE=U7&&H7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),V7=Ci,K7=String,W7=TypeError,Pi=function(e){if(V7(e))return e;throw new W7(K7(e)+" is not an object")},G7=As,Y7=BE,X7=UE,ed=Pi,Fx=zE,q7=TypeError,Rg=Object.defineProperty,Z7=Object.getOwnPropertyDescriptor,Dg="enumerable",jg="configurable",Lg="writable";tl.f=G7?X7?function(n,t,r){if(ed(n),t=Fx(t),ed(r),typeof n=="function"&&t==="prototype"&&"value"in r&&Lg in r&&!r[Lg]){var o=Z7(n,t);o&&o[Lg]&&(n[t]=r.value,r={configurable:jg in r?r[jg]:o[jg],enumerable:Dg in r?r[Dg]:o[Dg],writable:!1})}return Rg(n,t,r)}:Rg:function(n,t,r){if(ed(n),t=Fx(t),ed(r),Y7)try{return Rg(n,t,r)}catch{}if("get"in r||"set"in r)throw new q7("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var Q7=As,J7=tl,e9=_E,Gv=Q7?function(e,n,t){return J7.f(e,n,e9(1,t))}:function(e,n,t){return e[n]=t,e},HE={exports:{}},My=As,t9=Rs,VE=Function.prototype,n9=My&&Object.getOwnPropertyDescriptor,Yv=t9(VE,"name"),r9=Yv&&(function(){}).name==="something",o9=Yv&&(!My||My&&n9(VE,"name").configurable),s9={EXISTS:Yv,PROPER:r9,CONFIGURABLE:o9},i9=Et,a9=pn,Ay=Kv,l9=i9(Function.toString);a9(Ay.inspectSource)||(Ay.inspectSource=function(e){return l9(e)});var KE=Ay.inspectSource,c9=In,u9=pn,Bx=c9.WeakMap,d9=u9(Bx)&&/native code/.test(String(Bx)),h9=Wv,p9=NE,Ux=h9("keys"),WE=function(e){return Ux[e]||(Ux[e]=p9(e))},Xv={},f9=d9,GE=In,g9=Ci,m9=Gv,Ng=Rs,zg=Kv,y9=WE,v9=Xv,Hx="Object already initialized",Oy=GE.TypeError,S9=GE.WeakMap,dp,Pc,hp,w9=function(e){return hp(e)?Pc(e):dp(e,{})},x9=function(e){return function(n){var t;if(!g9(n)||(t=Pc(n)).type!==e)throw new Oy("Incompatible receiver, "+e+" required");return t}};if(f9||zg.state){var zr=zg.state||(zg.state=new S9);zr.get=zr.get,zr.has=zr.has,zr.set=zr.set,dp=function(e,n){if(zr.has(e))throw new Oy(Hx);return n.facade=e,zr.set(e,n),n},Pc=function(e){return zr.get(e)||{}},hp=function(e){return zr.has(e)}}else{var Ui=y9("state");v9[Ui]=!0,dp=function(e,n){if(Ng(e,Ui))throw new Oy(Hx);return n.facade=e,m9(e,Ui,n),n},Pc=function(e){return Ng(e,Ui)?e[Ui]:{}},hp=function(e){return Ng(e,Ui)}}var YE={set:dp,get:Pc,has:hp,enforce:w9,getterFor:x9},qv=Et,b9=hn,C9=pn,td=Rs,Ry=As,P9=s9.CONFIGURABLE,E9=KE,XE=YE,k9=XE.enforce,I9=XE.get,Vx=String,Zd=Object.defineProperty,_9=qv("".slice),T9=qv("".replace),$9=qv([].join),M9=Ry&&!b9(function(){return Zd(function(){},"length",{value:8}).length!==8}),A9=String(String).split("String"),O9=HE.exports=function(e,n,t){_9(Vx(n),0,7)==="Symbol("&&(n="["+T9(Vx(n),/^Symbol\(([^)]*)\)/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!td(e,"name")||P9&&e.name!==n)&&(Ry?Zd(e,"name",{value:n,configurable:!0}):e.name=n),M9&&t&&td(t,"arity")&&e.length!==t.arity&&Zd(e,"length",{value:t.arity});try{t&&td(t,"constructor")&&t.constructor?Ry&&Zd(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=k9(e);return td(r,"source")||(r.source=$9(A9,typeof n=="string"?n:"")),e};Function.prototype.toString=O9(function(){return C9(this)&&I9(this).source||E9(this)},"toString");var R9=HE.exports,D9=pn,j9=tl,L9=R9,N9=Vv,qE=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(D9(t)&&L9(t,s,r),r.global)o?e[n]=t:N9(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:j9.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},ZE={},z9=Math.ceil,F9=Math.floor,B9=Math.trunc||function(n){var t=+n;return(t>0?F9:z9)(t)},U9=B9,Ei=function(e){var n=+e;return n!==n||n===0?0:U9(n)},H9=Ei,V9=Math.max,K9=Math.min,W9=function(e,n){var t=H9(e);return t<0?V9(t+n,0):K9(t,n)},G9=Ei,Y9=Math.min,QE=function(e){return e>0?Y9(G9(e),9007199254740991):0},X9=QE,pu=function(e){return X9(e.length)},q9=cf,Z9=W9,Q9=pu,Kx=function(e){return function(n,t,r){var o=q9(n),s=Q9(o),i=Z9(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}},J9={includes:Kx(!0),indexOf:Kx(!1)},eN=Et,Fg=Rs,tN=cf,nN=J9.indexOf,rN=Xv,Wx=eN([].push),JE=function(e,n){var t=tN(e),r=0,o=[],s;for(s in t)!Fg(rN,s)&&Fg(t,s)&&Wx(o,s);for(;n.length>r;)Fg(t,s=n[r++])&&(~nN(o,s)||Wx(o,s));return o},Zv=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],oN=JE,sN=Zv,iN=sN.concat("length","prototype");ZE.f=Object.getOwnPropertyNames||function(n){return oN(n,iN)};var ek={};ek.f=Object.getOwnPropertySymbols;var aN=uf,lN=Et,cN=ZE,uN=ek,dN=Pi,hN=lN([].concat),pN=aN("Reflect","ownKeys")||function(n){var t=cN.f(dN(n)),r=uN.f;return r?hN(t,r(n)):t},Gx=Rs,fN=pN,gN=Bv,mN=tl,yN=function(e,n,t){for(var r=fN(n),o=mN.f,s=gN.f,i=0;i<r.length;i++){var a=r[i];!Gx(e,a)&&!(t&&Gx(t,a))&&o(e,a,s(n,a))}},vN=hn,SN=pn,wN=/#|\.prototype\./,fu=function(e,n){var t=bN[xN(e)];return t===PN?!0:t===CN?!1:SN(n)?vN(n):!!n},xN=fu.normalize=function(e){return String(e).replace(wN,".").toLowerCase()},bN=fu.data={},CN=fu.NATIVE="N",PN=fu.POLYFILL="P",EN=fu,Bg=In,kN=Bv.f,IN=Gv,_N=qE,TN=Vv,$N=yN,MN=EN,nl=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,l,c,u;if(r?i=Bg:o?i=Bg[t]||TN(t,{}):i=(Bg[t]||{}).prototype,i)for(a in n){if(c=n[a],e.dontCallGetSet?(u=kN(i,a),l=u&&u.value):l=i[a],s=MN(r?a:t+(o?".":"#")+a,e.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;$N(c,l)}(e.sham||l&&l.sham)&&IN(c,"sham",!0),_N(i,a,c,e)}},tk={},AN=JE,ON=Zv,RN=Object.keys||function(n){return AN(n,ON)},DN=As,jN=UE,LN=tl,NN=Pi,zN=cf,FN=RN;tk.f=DN&&!jN?Object.defineProperties:function(n,t){NN(n);for(var r=zN(t),o=FN(t),s=o.length,i=0,a;s>i;)LN.f(n,a=o[i++],r[a]);return n};var BN=uf,UN=BN("document","documentElement"),HN=Pi,VN=tk,Yx=Zv,KN=Xv,WN=UN,GN=FE,YN=WE,Xx=">",qx="<",Dy="prototype",jy="script",nk=YN("IE_PROTO"),Ug=function(){},rk=function(e){return qx+jy+Xx+e+qx+"/"+jy+Xx},Zx=function(e){e.write(rk("")),e.close();var n=e.parentWindow.Object;return e=null,n},XN=function(){var e=GN("iframe"),n="java"+jy+":",t;return e.style.display="none",WN.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(rk("document.F=Object")),t.close(),t.F},nd,Qd=function(){try{nd=new ActiveXObject("htmlfile")}catch{}Qd=typeof document<"u"?document.domain&&nd?Zx(nd):XN():Zx(nd);for(var e=Yx.length;e--;)delete Qd[Dy][Yx[e]];return Qd()};KN[nk]=!0;var ok=Object.create||function(n,t){var r;return n!==null?(Ug[Dy]=HN(n),r=new Ug,Ug[Dy]=null,r[nk]=n):r=Qd(),t===void 0?r:VN.f(r,t)},qN=Uo,ZN=ok,QN=tl.f,Ly=qN("unscopables"),Ny=Array.prototype;Ny[Ly]===void 0&&QN(Ny,Ly,{configurable:!0,value:ZN(null)});var Qv=function(e){Ny[Ly][e]=!0},JN=nl,ez=hu,tz=pu,nz=Ei,rz=Qv;JN({target:"Array",proto:!0},{at:function(n){var t=ez(this),r=tz(t),o=nz(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});rz("at");var oz=In,sz=Et,gu=function(e,n){return sz(oz[e].prototype[n])},iz=gu;iz("Array","at");var az=Ja,sk=Array.isArray||function(n){return az(n)==="Array"},lz=TypeError,cz=9007199254740991,uz=function(e){if(e>cz)throw lz("Maximum allowed index exceeded");return e},dz=Ja,hz=Et,ik=function(e){if(dz(e)==="Function")return hz(e)},Qx=ik,pz=Uv,fz=af,gz=Qx(Qx.bind),mz=function(e,n){return pz(e),n===void 0?e:fz?gz(e,n):function(){return e.apply(n,arguments)}},yz=sk,vz=pu,Sz=uz,wz=mz,ak=function(e,n,t,r,o,s,i,a){for(var l=o,c=0,u=i?wz(i,a):!1,d,h;c<r;)c in t&&(d=u?u(t[c],c,n):t[c],s>0&&yz(d)?(h=vz(d),l=ak(e,n,d,h,l,s-1)-1):(Sz(l+1),e[l]=d),l++),c++;return l},lk=ak,xz=Uo,bz=xz("toStringTag"),ck={};ck[bz]="z";var Cz=String(ck)==="[object z]",Pz=Cz,Ez=pn,Jd=Ja,kz=Uo,Iz=kz("toStringTag"),_z=Object,Tz=Jd(function(){return arguments}())==="Arguments",$z=function(e,n){try{return e[n]}catch{}},uk=Pz?Jd:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=$z(n=_z(e),Iz))=="string"?t:Tz?Jd(n):(r=Jd(n))==="Object"&&Ez(n.callee)?"Arguments":r},Mz=Et,Az=hn,dk=pn,Oz=uk,Rz=uf,Dz=KE,hk=function(){},jz=[],pk=Rz("Reflect","construct"),Jv=/^\s*(?:class|function)\b/,Lz=Mz(Jv.exec),Nz=!Jv.test(hk),Pl=function(n){if(!dk(n))return!1;try{return pk(hk,jz,n),!0}catch{return!1}},fk=function(n){if(!dk(n))return!1;switch(Oz(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return Nz||!!Lz(Jv,Dz(n))}catch{return!0}};fk.sham=!0;var zz=!pk||Az(function(){var e;return Pl(Pl.call)||!Pl(Object)||!Pl(function(){e=!0})||e})?fk:Pl,Jx=sk,Fz=zz,Bz=Ci,Uz=Uo,Hz=Uz("species"),eb=Array,Vz=function(e){var n;return Jx(e)&&(n=e.constructor,Fz(n)&&(n===eb||Jx(n.prototype))?n=void 0:Bz(n)&&(n=n[Hz],n===null&&(n=void 0))),n===void 0?eb:n},Kz=Vz,gk=function(e,n){return new(Kz(e))(n===0?0:n)},Wz=nl,Gz=lk,Yz=hu,Xz=pu,qz=Ei,Zz=gk;Wz({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=Yz(this),r=Xz(t),o=Zz(t,0);return o.length=Gz(o,t,t,r,0,n===void 0?1:qz(n)),o}});var Qz=Qv;Qz("flat");var Jz=gu;Jz("Array","flat");var eF=nl,tF=lk,nF=Uv,rF=hu,oF=pu,sF=gk;eF({target:"Array",proto:!0},{flatMap:function(n){var t=rF(this),r=oF(t),o;return nF(n),o=sF(t,0),o.length=tF(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var iF=Qv;iF("flatMap");var aF=gu;aF("Array","flatMap");var lF=uk,cF=String,mu=function(e){if(lF(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return cF(e)},uF=nl,dF=Et,hF=el,pF=Ei,fF=mu,gF=hn,mF=dF("".charAt),yF=gF(function(){return"𠮷".at(-2)!=="\uD842"});uF({target:"String",proto:!0,forced:yF},{at:function(n){var t=fF(hF(this)),r=t.length,o=pF(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:mF(t,s)}});var vF=gu;vF("String","at");var SF=Pi,mk=function(){var e=SF(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},eS=hn,wF=In,tS=wF.RegExp,nS=eS(function(){var e=tS("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),xF=nS||eS(function(){return!tS("a","y").sticky}),bF=nS||eS(function(){var e=tS("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),CF={BROKEN_CARET:bF,MISSED_STICKY:xF,UNSUPPORTED_Y:nS},PF=hn,EF=In,kF=EF.RegExp,IF=PF(function(){var e=kF(".","s");return!(e.dotAll&&e.test(`
|
|
61
|
+
`)&&e.flags==="s")}),_F=hn,TF=In,$F=TF.RegExp,MF=_F(function(){var e=$F("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),na=Os,df=Et,AF=mu,OF=mk,RF=CF,DF=Wv,jF=ok,LF=YE.get,NF=IF,zF=MF,FF=DF("native-string-replace",String.prototype.replace),pp=RegExp.prototype.exec,zy=pp,BF=df("".charAt),UF=df("".indexOf),HF=df("".replace),Hg=df("".slice),Fy=function(){var e=/a/,n=/b*/g;return na(pp,e,"a"),na(pp,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),yk=RF.BROKEN_CARET,By=/()??/.exec("")[1]!==void 0,VF=Fy||By||yk||NF||zF;VF&&(zy=function(n){var t=this,r=LF(t),o=AF(n),s=r.raw,i,a,l,c,u,d,h;if(s)return s.lastIndex=t.lastIndex,i=na(zy,s,o),t.lastIndex=s.lastIndex,i;var p=r.groups,y=yk&&t.sticky,f=na(OF,t),m=t.source,S=0,w=o;if(y&&(f=HF(f,"y",""),UF(f,"g")===-1&&(f+="g"),w=Hg(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&BF(o,t.lastIndex-1)!==`
|
|
62
|
+
`)&&(m="(?: "+m+")",w=" "+w,S++),a=new RegExp("^(?:"+m+")",f)),By&&(a=new RegExp("^"+m+"$(?!\\s)",f)),Fy&&(l=t.lastIndex),c=na(pp,y?a:t,w),y?c?(c.input=Hg(c.input,S),c[0]=Hg(c[0],S),c.index=t.lastIndex,t.lastIndex+=c[0].length):t.lastIndex=0:Fy&&c&&(t.lastIndex=t.global?c.index+c[0].length:l),By&&c&&c.length>1&&na(FF,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=jF(null),u=0;u<p.length;u++)h=p[u],d[h[0]]=c[h[1]];return c});var rS=zy,KF=nl,tb=rS;KF({target:"RegExp",proto:!0,forced:/./.exec!==tb},{exec:tb});var WF=af,vk=Function.prototype,nb=vk.apply,rb=vk.call,GF=typeof Reflect=="object"&&Reflect.apply||(WF?rb.bind(nb):function(){return rb.apply(nb,arguments)}),ob=ik,sb=qE,YF=rS,ib=hn,Sk=Uo,XF=Gv,qF=Sk("species"),Vg=RegExp.prototype,ZF=function(e,n,t,r){var o=Sk(e),s=!ib(function(){var c={};return c[o]=function(){return 7},""[e](c)!==7}),i=s&&!ib(function(){var c=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[qF]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return c=!0,null},u[o](""),!c});if(!s||!i||t){var a=ob(/./[o]),l=n(o,""[e],function(c,u,d,h,p){var y=ob(c),f=u.exec;return f===YF||f===Vg.exec?s&&!p?{done:!0,value:a(u,d,h)}:{done:!0,value:y(d,u,h)}:{done:!1}});sb(String.prototype,e,l[0]),sb(Vg,o,l[1])}r&&XF(Vg[o],"sham",!0)},oS=Et,QF=Ei,JF=mu,eB=el,tB=oS("".charAt),ab=oS("".charCodeAt),nB=oS("".slice),lb=function(e){return function(n,t){var r=JF(eB(n)),o=QF(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=ab(r,o),i<55296||i>56319||o+1===s||(a=ab(r,o+1))<56320||a>57343?e?tB(r,o):i:e?nB(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},rB={codeAt:lb(!1),charAt:lb(!0)},oB=rB.charAt,sB=function(e,n,t){return n+(t?oB(e,n).length:1)},sS=Et,iB=hu,aB=Math.floor,Kg=sS("".charAt),lB=sS("".replace),Wg=sS("".slice),cB=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,uB=/\$([$&'`]|\d{1,2})/g,wk=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,l=uB;return o!==void 0&&(o=iB(o),l=cB),lB(s,l,function(c,u){var d;switch(Kg(u,0)){case"$":return"$";case"&":return e;case"`":return Wg(n,0,t);case"'":return Wg(n,i);case"<":d=o[Wg(u,1,-1)];break;default:var h=+u;if(h===0)return c;if(h>a){var p=aB(h/10);return p===0?c:p<=a?r[p-1]===void 0?Kg(u,1):r[p-1]+Kg(u,1):c}d=r[h-1]}return d===void 0?"":d})},cb=Os,dB=Pi,hB=pn,pB=Ja,fB=rS,gB=TypeError,mB=function(e,n){var t=e.exec;if(hB(t)){var r=cb(t,e,n);return r!==null&&dB(r),r}if(pB(e)==="RegExp")return cb(fB,e,n);throw new gB("RegExp#exec called on incompatible receiver")},yB=GF,ub=Os,hf=Et,vB=ZF,SB=hn,wB=Pi,xB=pn,bB=lf,CB=Ei,PB=QE,Hi=mu,EB=el,kB=sB,IB=Hv,_B=wk,TB=mB,$B=Uo,Uy=$B("replace"),MB=Math.max,AB=Math.min,OB=hf([].concat),Gg=hf([].push),db=hf("".indexOf),hb=hf("".slice),RB=function(e){return e===void 0?e:String(e)},DB=function(){return"a".replace(/./,"$0")==="$0"}(),pb=function(){return/./[Uy]?/./[Uy]("a","$0")==="":!1}(),jB=!SB(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});vB("replace",function(e,n,t){var r=pb?"$":"$0";return[function(s,i){var a=EB(this),l=bB(s)?void 0:IB(s,Uy);return l?ub(l,s,a,i):ub(n,Hi(a),s,i)},function(o,s){var i=wB(this),a=Hi(o);if(typeof s=="string"&&db(s,r)===-1&&db(s,"$<")===-1){var l=t(n,i,a,s);if(l.done)return l.value}var c=xB(s);c||(s=Hi(s));var u=i.global,d;u&&(d=i.unicode,i.lastIndex=0);for(var h=[],p;p=TB(i,a),!(p===null||(Gg(h,p),!u));){var y=Hi(p[0]);y===""&&(i.lastIndex=kB(a,PB(i.lastIndex),d))}for(var f="",m=0,S=0;S<h.length;S++){p=h[S];for(var w=Hi(p[0]),x=MB(AB(CB(p.index),a.length),0),C=[],P,k=1;k<p.length;k++)Gg(C,RB(p[k]));var I=p.groups;if(c){var _=OB([w],C,x,a);I!==void 0&&Gg(_,I),P=Hi(yB(s,void 0,_))}else P=_B(w,a,x,C,I,s);x>=m&&(f+=hb(a,m,x)+P,m=x+w.length)}return f+hb(a,m)}]},!jB||!DB||pb);var LB=Ci,NB=Ja,zB=Uo,FB=zB("match"),BB=function(e){var n;return LB(e)&&((n=e[FB])!==void 0?!!n:NB(e)==="RegExp")},UB=Os,HB=Rs,VB=AE,KB=mk,fb=RegExp.prototype,WB=function(e){var n=e.flags;return n===void 0&&!("flags"in fb)&&!HB(e,"flags")&&VB(fb,e)?UB(KB,e):n},GB=nl,YB=Os,iS=Et,gb=el,XB=pn,qB=lf,ZB=BB,El=mu,QB=Hv,JB=WB,eU=wk,tU=Uo,nU=tU("replace"),rU=TypeError,xk=iS("".indexOf);iS("".replace);var mb=iS("".slice),oU=Math.max,yb=function(e,n,t){return t>e.length?-1:n===""?t:xk(e,n,t)};GB({target:"String",proto:!0},{replaceAll:function(n,t){var r=gb(this),o,s,i,a,l,c,u,d,h,p=0,y=0,f="";if(!qB(n)){if(o=ZB(n),o&&(s=El(gb(JB(n))),!~xk(s,"g")))throw new rU("`.replaceAll` does not allow non-global regexes");if(i=QB(n,nU),i)return YB(i,n,r,t)}for(a=El(r),l=El(n),c=XB(t),c||(t=El(t)),u=l.length,d=oU(1,u),p=yb(a,l,0);p!==-1;)h=c?El(t(l,p,a)):eU(l,a,p,[],void 0,t),f+=mb(a,y,p)+h,y=p+u,p=yb(a,l,p+d);return y<a.length&&(f+=mb(a,y)),f}});var sU=gu;sU("String","replaceAll");const iU=({children:e})=>{const n=K();return Y("shouldDisplayHandles",()=>n.isInAny("select.idle","select.pointing_handle"),[n])?g.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null},aU=({shapeId:e})=>{const n=K();return Y("show hovered",()=>n.isIn("select.editing_shape")?n.getHoveredShapeId()!==n.getEditingShapeId():n.isInAny("select.idle"),[n])?g.jsx(au,{className:"tl-user-indicator__hovered",id:e}):null},{PI:lU}=Math,ba=lU+1e-4;function bk(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,y=h,f=!1,m;for(let S=0;S<e.length;S++){m=e[S];const{point:w,vector:x}=e[S],C=m.vector.dpr(u),P=(S<e.length-1?e[S+1]:e[S]).vector,k=S<e.length-1?P.dpr(m.vector):1,I=C<0&&!f,_=k!==null&&k<.2;if(I||_){if(k>-.62&&i-m.runningLength>m.radius){const T=u.clone().mul(m.radius);u.clone().cpr(P)<0?(p=E.Add(w,T),y=E.Sub(w,T)):(p=E.Sub(w,T),y=E.Add(w,T)),l.push(p),c.push(y)}else{const T=u.clone().mul(m.radius).per(),R=E.Sub(m.input,T);for(let L=1/13,N=0;N<1;N+=L)p=E.RotWith(R,m.input,ba*N),l.push(p),y=E.RotWith(R,m.input,ba+ba*-N),c.push(y)}d=p,h=y,_&&(f=!0);continue}if(f=!1,m===o||m===s){const T=E.Per(x).mul(m.radius);l.push(E.Sub(w,T)),c.push(E.Add(w,T));continue}const $=E.Lrp(P,x,k).per().mul(m.radius);p=E.Sub(w,$),(S<=1||E.Dist2(d,p)>a)&&(l.push(p),d=p),y=E.Add(w,$),(S<=1||E.Dist2(h,y)>a)&&(c.push(y),h=y),u=x}return{left:l,right:c}}function yu(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:y}=bk(e,n),f=l.point,m=e.length>1?e[e.length-1].point:E.AddXY(l.point,1,1);if(e.length===1&&(!(d||h)||s)){const C=E.Add(f,E.Sub(f,m).uni().per().mul(-l.radius)),P=[];for(let k=1/13,I=k;I<=1;I+=k)P.push(E.RotWith(C,f,ba*2*I));return P}const S=[];if(!(d||h&&e.length===1))if(i)for(let C=1/8,P=C;P<=1;P+=C){const k=E.RotWith(y[0],f,ba*P);S.push(k)}else{const C=E.Sub(p[0],y[0]),P=E.Mul(C,.5),k=E.Mul(C,.51);S.push(E.Sub(f,P),E.Sub(f,k),E.Add(f,k),E.Add(f,P))}const w=[],x=c.vector.clone().per().neg();if(h||d&&e.length===1)w.push(m);else if(a){const C=E.Add(m,E.Mul(x,c.radius));for(let P=1/29,k=P;k<1;k+=P)w.push(E.RotWith(C,m,ba*3*k))}else w.push(E.Add(m,E.Mul(x,c.radius)),E.Add(m,E.Mul(x,c.radius*.99)),E.Sub(m,E.Mul(x,c.radius*.99)),E.Sub(m,E.Mul(x,c.radius)));return p.concat(w,y.reverse(),S)}const cU=.025,uU=.01;function Pr(e,n={}){var m;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(E.From),a=0;if(!o){let S=i[0];for(;S&&!(S.z>=cU);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=uU);)i.pop(),S=i[i.length-1]}if(i.length===0)return[{point:E.From(e[0]),input:E.From(e[0]),pressure:o?.5:.15,vector:new E(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(E.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&&!(E.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&&E.Dist(i[i.length-1],i[i.length-2])<r||a>0;if(i.length===2&&n.simulatePressure){const S=i[1];i=i.slice(0,-1);for(let w=1;w<5;w++){const x=E.Lrp(i[0],S,w/4);x.z=(i[0].z+(S.z-i[0].z))*w/4,i.push(x)}}const d=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new E(1,1),distance:0,runningLength:0,radius:1}];let h=0,p=d[0],y,f;u&&t>0&&i.push(i[i.length-1].clone());for(let S=1,w=i.length;S<w;S++)y=!s||n.last&&S===w-1?i[S].clone():i[S].clone().lrp(p.point,1-s),!p.point.equals(y)&&(f=E.Dist(y,p.point),h+=f,!(S<4&&h<r)&&(p={input:i[S],point:y,pressure:o?.5:i[S].z,vector:E.Sub(p.point,y).uni(),distance:f,runningLength:h,radius:1},d.push(p)));if((m=d[1])!=null&&m.vector&&(d[0].vector=d[1].vector.clone()),h<1){const S=Math.max(.5,...d.map(w=>w.pressure));d.forEach(w=>w.pressure=S)}return d}const{min:Xo}=Math,Yg=.275;function rl(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=m=>m,start:i={},end:a={}}=n,{easing:l=Xt.easeOutQuad}=i,{easing:c=Xt.easeOutCubic}=a,u=e[e.length-1].runningLength;let d,h=e[0].pressure,p;if(!o&&u<t){const m=e.reduce((S,w)=>Math.max(S,w.pressure),.5);return e.forEach(S=>{S.pressure=m,S.radius=t*s(.5-r*(.5-S.pressure))}),e}else{let m;for(let S=0,w=e.length;S<w&&(p=e[S],!(p.runningLength>t*5));S++){const x=Xo(1,p.distance/t);if(o){const C=Xo(1,1-x);m=Xo(1,h+(C-h)*(x*Yg))}else m=Xo(1,h+(p.pressure-h)*.5);h=h+(m-h)*.5}for(let S=0;S<e.length;S++){if(p=e[S],r){let{pressure:w}=p;const x=Xo(1,p.distance/t);if(o){const C=Xo(1,1-x);w=Xo(1,h+(C-h)*(x*Yg))}else w=Xo(1,h+(w-h)*(x*Yg));p.radius=t*s(.5-r*(.5-w)),h=w}else p.radius=t/2;d===void 0&&(d=p.radius)}}const y=i.taper===!1?0:i.taper===!0?Math.max(t,u):i.taper,f=a.taper===!1?0:a.taper===!0?Math.max(t,u):a.taper;if(y||f)for(let m=0;m<e.length;m++){p=e[m];const{runningLength:S}=p,w=S<y?l(S/y):1,x=u-S<f?c((u-S)/f):1;p.radius=Math.max(.01,p.radius*Math.min(w,x))}return e}function dU(e,n={}){return yu(rl(Pr(e,n),n),n)}const vb=({scribble:e,zoom:n,color:t,opacity:r,className:o})=>{if(!e.points.length)return null;const s=dU(e.points,{size:e.size/n,start:{taper:e.taper,easing:Xt.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=lu(s);return g.jsx("svg",{className:o&&pe("tl-overlays__item",o),children:g.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})},hU=({bounds:e,rotation:n})=>{const t=K();return Y("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?g.jsx(TP,{bounds:e,rotation:n}):null};function pr(){const e=K();return Y("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function pU({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:pe("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:pe("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:pe("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:pe("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:pe("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:pe("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 fU=Re(function({bounds:n,rotation:t}){const r=K(),o=b.useRef(null),s=pr(),i=Br("top"),a=Br("right"),l=Br("bottom"),c=Br("left"),u=Br("top_left"),d=Br("top_right"),h=Br("bottom_right"),p=Br("bottom_left"),y=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",f=r.getInstanceState().isCoarsePointer,m=r.getOnlySelectedShape(),S=m&&r.isShapeOrAncestorLocked(m),w=m?r.getShapeUtil(m).expandSelectionOutlinePx(m):0;if(Xa(o,n==null?void 0:n.x,n==null?void 0:n.y,1,r.getSelectionRotation(),{x:-w,y:-w}),!n)return null;n=n.clone().expandBy(w).zeroFix();const x=r.getZoomLevel(),C=r.getInstanceState().isChangingStyle,P=n.width,k=n.height,I=8/x,_=P<I*2,$=k<I*2,T=P<I*4,R=k<I*4,L=P<I*5,N=k<I*5,D=f?1.75:1,z=6/x*D,F=(T?z/2:z)*(D*.75),W=(R?z/2:z)*(D*.75),H=(m?!r.getShapeUtil(m).hideSelectionBoundsFg(m):!0)&&!C;let U=H&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.pointing_resize_handle","select.pointing_crop_handle")||H&&r.isIn("select.resizing")&&m&&r.isShapeOfType(m,"text");m&&U&&r.environment.isFirefox&&r.isShapeOfType(m,"embed")&&(U=!1);const V=r.isInAny("select.pointing_crop_handle","select.crop.idle","select.crop.pointing_crop")&&!C&&!s,X=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!C&&!s,re=!f&&!(_||$)&&(X||V)&&(m?!r.getShapeUtil(m).hideRotateHandle(m):!0)&&!S,ge=f&&(!T||!R)&&(X||V)&&(m?!r.getShapeUtil(m).hideRotateHandle(m):!0)&&!S,Ce=X&&(m?r.getShapeUtil(m).canResize(m)&&!r.getShapeUtil(m).hideResizeHandles(m):!0)&&!V&&!S,oe=_||$,Se=_&&$,De=L||N,et=Ce||V,Ee=!re,ct=!X||!ge,Fe=!X||!et,qn=!X||!et||oe,_n=!X||!et||oe,Tn=!X||!et||Se&&!V;let tt=f;tt&&m&&m.type==="text"&&(tt=!1);let mt=!0;V?mt=De:Ce&&(mt=oe||Se||tt);const lo=Math.min(24/x,k-W*3),dl=X&&f&&m&&r.isShapeOfType(m,"text")&&lo*x>=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:[U&&g.jsx("rect",{className:pe("tl-selection__fg__outline"),width:O(P),height:O(k)}),g.jsx(rd,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:z,corner:"top_left_rotate",cursor:y?An("nwse-rotate",t):void 0,isHidden:Ee}),g.jsx(rd,{"data-testid":"selection.rotate.top-right",cx:P+z*3,cy:0,targetSize:z,corner:"top_right_rotate",cursor:y?An("nesw-rotate",t):void 0,isHidden:Ee}),g.jsx(rd,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:k+z*3,targetSize:z,corner:"bottom_left_rotate",cursor:y?An("swne-rotate",t):void 0,isHidden:Ee}),g.jsx(rd,{"data-testid":"selection.rotate.bottom-right",cx:P+z*3,cy:k+z*3,targetSize:z,corner:"bottom_right_rotate",cursor:y?An("senw-rotate",t):void 0,isHidden:Ee}),g.jsx(mU,{"data-testid":"selection.rotate.mobile",cx:T?-z*1.5:P/2,cy:T?k/2:-z*1.5,size:I,isHidden:ct}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":mt}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:O(0-(R?W*2:W)),width:O(P),height:O(Math.max(1,W*2)),style:y?{cursor:An("ns-resize",t)}:void 0,...i}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":mt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:O(P-(T?0:F)),y:0,height:O(k),width:O(Math.max(1,F*2)),style:y?{cursor:An("ew-resize",t)}:void 0,...a}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":mt}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:O(k-(R?0:W)),width:O(P),height:O(Math.max(1,W*2)),style:y?{cursor:An("ns-resize",t)}:void 0,...l}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":mt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:O(0-(T?F*2:F)),y:0,height:O(k),width:O(Math.max(1,F*2)),style:y?{cursor:An("ew-resize",t)}:void 0,...c}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":Fe}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:O(0-(T?F*2:F*1.5)),y:O(0-(R?W*2:W*1.5)),width:O(F*3),height:O(W*3),style:y?{cursor:An("nwse-resize",t)}:void 0,...u}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":qn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:O(P-(T?0:F*1.5)),y:O(0-(R?W*2:W*1.5)),width:O(F*3),height:O(W*3),style:y?{cursor:An("nesw-resize",t)}:void 0,...d}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":Tn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:O(P-(T?F:F*1.5)),y:O(k-(R?W:W*1.5)),width:O(F*3),height:O(W*3),style:y?{cursor:An("nwse-resize",t)}:void 0,...h}),g.jsx("rect",{className:pe("tl-transparent",{"tl-hidden":_n}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:O(0-(T?F*3:F*1.5)),y:O(k-(R?0:W*1.5)),width:O(F*3),height:O(W*3),style:y?{cursor:An("nesw-resize",t)}:void 0,...p}),Ce&&g.jsxs(g.Fragment,{children:[g.jsx("rect",{"data-testid":"selection.resize.top-left",className:pe("tl-corner-handle",{"tl-hidden":Fe}),"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:pe("tl-corner-handle",{"tl-hidden":qn}),"aria-label":"top_right handle",x:O(P-I/2),y:O(0-I/2),width:O(I),height:O(I)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:pe("tl-corner-handle",{"tl-hidden":Tn}),"aria-label":"bottom_right handle",x:O(P-I/2),y:O(k-I/2),width:O(I),height:O(I)}),g.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:pe("tl-corner-handle",{"tl-hidden":_n}),"aria-label":"bottom_left handle",x:O(0-I/2),y:O(k-I/2),width:O(I),height:O(I)})]}),dl&&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-lo/2),rx:I/4,width:O(I/2),height:O(lo)}),g.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:I/4,x:O(P-I/4),y:O(k/2-lo/2),width:O(I/2),height:O(lo)})]}),V&&g.jsx(pU,{size:I,width:P,height:k,hideAlternateHandles:De})]})})}),rd=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=Br(o);return g.jsx("rect",{className:pe("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})},gU=Math.sqrt(Math.PI),mU=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=Br("mobile_rotate"),a=K(),l=Y("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:pe("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:c,...i}),g.jsx("circle",{className:pe("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/gU})]})},Dt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},Yt={s:2,m:3.5,l:5,xl:10},is={s:18,m:24,l:36,xl:44},Ra={s:18,m:22,l:26,xl:32},Qo={s:18,m:20,l:24,xl:28},Io={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"};var Ck={exports:{}};(function(e){(function(n,t){e.exports?e.exports=t():n.downscale=t()})(Ot,function(){function n(_,S,w,x,C,P,k,I){var _=document.createElement("canvas");_.width=w,_.height=x;var $=_.getContext("2d");return $.mozImageSmoothingEnabled=!0,$.imageSmoothingQuality="high",$.webkitImageSmoothingEnabled=!0,$.msImageSmoothingEnabled=!0,$.imageSmoothingEnabled=!0,$.drawImage(S,C,P,k,I,0,0,w,x),_}function t(m){return m+.49<<0}function r(m,S,w,x,C,P,k){for(var I=new ImageData(S,w),_=new Int32Array(m.data.buffer),$=m.width,T=new Int32Array(I.data.buffer),R=I.width,L=S/P,N=w/k,D=t(1/L),z=t(1/N),F=D*z,W=0;W<I.height;W++)for(var H=0;H<R;H++){for(var U=x+t(H/L)+(C+t(W/N))*$,V=0,X=0,re=0,ge=0,Ce=0;Ce<z;Ce++)for(var oe=0;oe<D;oe++){var Se=_[U+oe+Ce*$];V+=Se<<24>>>24,X+=Se<<16>>>24,re+=Se<<8>>>24,ge+=Se>>>24}V=t(V/F),X=t(X/F),re=t(re/F),ge=t(ge/F),T[H+W*R]=ge<<24|re<<16|X<<8|V}return I}function o(m,S,w,x){var C=new Date,P={},k=C,I="01";return{mark:m?function(_){_=I+". "+(_||"..."),P[_]={"time (ms)":new Date-k},k=new Date,I=("0"+((I>>0)+1)).substr(-2)}:new Function,finish:m?function(){P[I+" TOTAL"]={"time (ms)":new Date-C},console.log("IMAGE SOURCE:",S),console.log("DOWNSCALE TO:",w+"x"+x),console.table(P)}:new Function}}function s(){var m=[],S=[],w=[],x=new Object;return{createSetter:function(C){if(!this.get(C)){var P=m.push(C)-1;return S.push(x),w.push([]),function(k){S[P]=k,w[P]=w[P].reduce(function(I,_){_(k)},[])}}},get:function(C,P){var k=m.indexOf(C);if(~k){if(S[k]===x){w[k].push(P);return}P(S[k])}},has:function(C){return!!~m.indexOf(C)}}}function i(m,S,w,x){m.width=w,m.height=x;var C=m.getContext("2d");return C.drawImage(S,0,0),C.getImageData(0,0,w,x)}function a(m,S){m.width=S.width,m.height=S.height;var w=m.getContext("2d");return w.putImageData(S,0,0),m}function l(m,S,T,R,C,P){var k=C,I=P,_=C/P;m===0&&(m=S*_>>0),S===0&&(S=m/_>>0);var $=m/S;$>_?P=C/$>>0:C=P*$>>0;var T=T||(k-C)/2>>0,R=R||(I-P)/2>>0;return{destWidth:m,destHeight:S,sourceX:T,sourceY:R,sourceWidth:C,sourceHeight:P}}function c(m,S,w){if(S.returnCanvas){w(m);return}if(S.returnBlob){m.toBlob(w,"image/"+(S.imageType||"jpeg"),S.quality||.85);return}var x=m.toDataURL("image/"+(S.imageType||"jpeg"),S.quality||.85);w(x)}function u(m,S){var w=new XMLHttpRequest;w.open("GET",m),w.responseType="arraybuffer",w.addEventListener("load",function(){S(this.response)}),w.send()}function d(m,S){m.complete?S():m.addEventListener("load",S)}function h(m,S){m.readyState>1?S():m.addEventListener("loadeddata",S)}function p(m){if(m instanceof File)return"File";if(m instanceof HTMLImageElement)return"HTMLImageElement";if(m instanceof HTMLVideoElement)return"HTMLVideoElement";if(typeof m=="string")return"URL"}function y(m){if(m.length<3)return new TypeError("3 arguments required, but only "+m.length+" present.");if(!p(m[0]))return new TypeError("First argument should be HTMLImageElement, HTMLVideoElement, File of String");if(typeof m[1]!="number")return new TypeError("Second argument should be a number");if(typeof m[2]!="number")return new TypeError("Third argument should be a number")}function f(m,S,w,x){var C=o(x&&x.debug||!1,m,S,w),P=y(arguments);if(P instanceof TypeError)return Promise.reject(P);x=x||{};var k,I=new Promise(function(N,D){k=N});f.canvas=f.canvas||document.createElement("canvas"),f.cache=f.cache||s();var _=f.canvas,$=f.cache;if($.has(m))return C.mark(),$.get(m,function(N){C.mark("PENDING CACHE");var D=N[0],z=N[1],F=l(S,w,x.sourceX,x.sourceY,z.width,z.height);if(F.sourceWidth/F.destWidth>=2&&F.sourceHeight/F.destHeight>=2){C.mark();var W=r(z,F.destWidth,F.destHeight,F.sourceX,F.sourceY,F.sourceWidth,F.sourceHeight);C.mark("DOWNSCALE"),_=a(_,W)}else _=n(_,D,F.destWidth,F.destHeight,F.sourceX,F.sourceY,F.sourceWidth,F.sourceHeight),C.mark("RESIZE WITH CANVAS");c(_,x,function(H){C.mark("PRODUCE RESULT"),k(H),C.finish()})}),I;var T=function(N,D,z){var F=l(S,w,x.sourceX,x.sourceY,D,z);if(F.sourceWidth/F.destWidth>=2&&F.sourceHeight/F.destHeight>=2){C.mark();var W=i(_,N,D,z);C.mark("GET IMAGE DATA");var H=r(W,F.destWidth,F.destHeight,F.sourceX,F.sourceY,F.sourceWidth,F.sourceHeight);C.mark("DOWNSCALE"),_=a(_,H),p(N)!=="HTMLVideoElement"&&$.createSetter(N)([N,W])}else _=n(_,N,F.destWidth,F.destHeight,F.sourceX,F.sourceY,F.sourceWidth,F.sourceHeight),C.mark("RESIZE WITH CANVAS");c(_,x,function(U){C.mark("PRODUCE RESULT"),k(U),C.finish()})},R=window.URL||window.webkitURL;switch(p(m)){case"File":var L=document.createElement("img");C.mark(),L.src=R.createObjectURL(m),C.mark("READ FILE"),d(L,function(){C.mark("LOAD IMAGE"),T(L,L.naturalWidth,L.naturalHeight)});break;case"HTMLImageElement":C.mark(),d(m,function(){C.mark("LOAD IMAGE"),T(m,m.naturalWidth,m.naturalHeight)});break;case"HTMLVideoElement":h(m,function(){T(m,m.videoWidth,m.videoHeight)});break;case"URL":C.mark(),setTimeout(function(){u(m,function(N){C.mark("LOAD ARRAY BUFFER");var D=new Uint8Array(N),z=new Blob([D],{type:"image/jpeg"}),F=document.createElement("img");F.src=R.createObjectURL(z),C.mark(),d(F,function(){C.mark("LOAD IMAGE"),T(F,F.naturalWidth,F.naturalHeight)})})});break}return I}return f})})(Ck);var yU=Ck.exports;const vU=Si(yU);/*!
|
|
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 SU(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 Sb(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?Sb(Object(t),!0).forEach(function(r){wU(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):Sb(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function wU(e,n,t){return n=TU(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function xU(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 bU(e,n){if(e==null)return{};var t=xU(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 wb(e,n){return PU(e)||SU(e,n)||Pk(e,n)||IU()}function od(e){return CU(e)||EU(e)||Pk(e)||kU()}function CU(e){if(Array.isArray(e))return Hy(e)}function PU(e){if(Array.isArray(e))return e}function EU(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function Pk(e,n){if(e){if(typeof e=="string")return Hy(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 Hy(e,n)}}function Hy(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 kU(){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 IU(){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 _U(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 TU(e){var n=_U(e,"string");return typeof n=="symbol"?n:String(n)}function nc(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&&nc(e)):d?e.onSuccess(t,r,h):(e.onError(t,r,h),e.sizes.length&&nc(e)),d}var Xg={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]},$U=["onError","onSuccess"],ra={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},kl={};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||ra.min,i=e.step||ra.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 sd(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=bU(e,$U),a=null;if(!n)return!1;if(e.useWorker&&t){var l=`
|
|
83
|
+
var canvasTest = `.concat(nc.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,y=h.height,f=h.benchmark,m=h.isTestPass;m?(kl[r].onSuccess(p,y,f),delete kl[r]):kl[r].onError(p,y,f)}}if(e.usePromise)return new Promise(function(d,h){var p=On(On({},e),{},{onError:function(S,w,x){var C;if(e.sizes.length===0)C=!0;else{var P=e.sizes.slice(-1),k=wb(P,1),I=wb(k[0],2),_=I[0],$=I[1];C=S===_&&w===$}o(S,w,x),C&&h({width:S,height:w,benchmark:x})},onSuccess:function(S,w,x){s(S,w,x),d({width:S,height:w,benchmark:x})}});if(a){var y=p.onError,f=p.onSuccess;kl[r]={onError:y,onSuccess:f},a.postMessage(i)}else nc(p)});if(a)kl[r]={onError:o,onSuccess:s},a.postMessage(i);else return nc(e)}var Zg={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:od(Xg.area)}),r=On(On(On({},ra),n),{},{sizes:t});return sd(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:od(Xg.height)}),r=On(On(On({},ra),n),{},{sizes:t});return sd(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:od(Xg.width)}),r=On(On(On({},ra),n),{},{sizes:t});return sd(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=On(On({},ra),n);return t.sizes=od(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),sd(t)}};let Qg=null;function Ek(){return Qg||(Qg=MU()),Qg}async function MU(){const e=await Zg.maxWidth({usePromise:!0}),n=await Zg.maxHeight({usePromise:!0}),t=await Zg.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}function xb(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function AU(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function OU(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!AU(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+=xb(n,o+1)+1;break;case 33:o+=2,o+=xb(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}function RU(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 DU(e,n,t,r={}){let o=n*2,s=t*2;const{type:i="image/jpeg",quality:a=.92}=r,l=await Ek(),c=n/t;if(o>l.maxWidth&&(o=l.maxWidth,s=o/c),s>l.maxHeight&&(s=l.maxHeight,o=s*c),o*s>l.maxArea){const u=Math.sqrt(l.maxArea/(o*s));o*=u,s*=u}return await vU(e,o,s,{imageType:i.replace("image/",""),quality:a})}async function jU(e){return await new Promise((n,t)=>{const r=new FileReader;r.onerror=()=>t(r.error),r.onload=()=>{n(r.result?OU(r.result):!1)},r.readAsArrayBuffer(e)})}function LU(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function NU(e){const n=new URL(e).host.replace("www.","");for(const t of Aa)if(kk(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const zU=e=>e.split("*").map(n=>LU(n)).join(".+"),kk=(e,n)=>!!e.find(t=>{const r=new RegExp(zU(t));return n.match(r)});function FU(e){const n=new URL(e).host.replace("www.","");for(const t of Aa)if(kk(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function Ik(e){return FU(e)??NU(e)}function xo(e){try{return Ik(e)}catch(n){console.error(n)}}const oa=" ",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,`$&${oa}`),d=u.length-c.length;n.setSelectionRange(l,r-1),rn.insert(n,u),n.setSelectionRange(t+1,r+d)}else rn.insert(n,oa)}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=id(n)??0,s=id(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,`$&${oa}`).length-u.length;t&&t.setBaseAndExtent(n,o+1,n,s+h)}else{const c=window.getSelection();n.innerText=r.slice(0,o)+oa+r.slice(o),c==null||c.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=id(n)??0,s=id(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
|
+
`)}};v(rn,"fixNewLines",/\r?\n|\r/g);let hs=rn;function id(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 BU=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function UU(e){return BU.test(e)}function HU(e){return e.replace(/\t/g,oa)}function VU(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 KU(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function WU(e){return KU(VU(HU(e)))}const rc=(e,n)=>e.length<=n?e:e.substring(0,n-3)+"...";function GU(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o}){e.registerExternalAssetHandler("file",async({file:s})=>await new Promise((i,a)=>{!r.includes(s.type)&&!o.includes(s.type)&&(console.warn(`File type not allowed: ${s.type}`),a()),s.size>t&&(console.warn(`File size too big: ${(s.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),a());const l=new FileReader;l.onerror=()=>a(l.error),l.onload=async()=>{let c=l.result;s.type==="video/quicktime"&&c.includes("video/quicktime")&&(c=c.replace("video/quicktime","video/mp4"));const u=r.includes(s.type);let d,h;if(u?(d=await g1.getImageSizeFromSrc(c),h=s.type==="image/gif"&&await jU(s)):(h=!0,d=await g1.getVideoSizeFromSrc(c)),isFinite(n)){const f=RU(d,{w:n,h:n});d!==f&&(s.type==="image/jpeg"||s.type==="image/png")&&(d=f)}(s.type==="image/jpeg"||s.type==="image/png")&&(c=await DU(c,d.w,d.h,{type:s.type,quality:.92}));const p=Zs.createId(Hd(c)),y=Zs.create({id:p,type:u?"image":"video",typeName:"asset",props:{name:s.name,src:c,w:d.w,h:d.h,mimeType:s.type,isAnimated:h}});i(y)},l.readAsDataURL(s)})),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"))??rc(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:rc(s,32),description:""}}return{id:Zs.createId(Hd(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");bb(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 E(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}})),bb(e,he(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=WU(i);let u,d,h,p="middle";const y=c.split(`
|
|
99
|
+
`).length>1,f=UU(c);y&&(p=y?f?"end":"start":"middle");const m=e.textMeasure.measureText(c,{...Dt,fontFamily:Io[l.font],fontSize:is[l.size],maxWidth:null}),S=Math.min(y?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(m.w>S){const w=e.textMeasure.measureText(c,{...Dt,fontFamily:Io[l.font],fontSize:is[l.size],maxWidth:S});u=w.w,d=w.h,h=!1,p=f?"end":"start"}else u=m.w,d=m.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=xo(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=Zs.createId(Hd(i)),u=YU(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 bb(e,n,t){if(!n.length)return[];const r=E.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)),_k(e,t)}),o.map(s=>s.id)}function _k(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=E.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 YU(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),_k(e,t)}),e.getShape(r.id)}var qm;let XU=(qm=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")});v(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}))}})}},v(qm,"id","idle"),qm);var Zm;let qU=(Zm=class extends ie{constructor(){super(...arguments);v(this,"shape");v(this,"markId","");v(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()});v(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});v(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"})}});v(this,"onPointerUp",()=>{this.cancel()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()});v(this,"preciseTimeout",-1);v(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.onHandleChange)==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.onHandleChange)==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.onHandleChange)==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)}},v(Zm,"id","pointing"),Zm);class eh extends ie{constructor(){super(...arguments);v(this,"shapeType","arrow")}}v(eh,"id","arrow"),v(eh,"initial","idle"),v(eh,"children",()=>[XU,qU]);class aS extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"initialShape");v(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");v(this,"util",this.editor.getShapeUtil(this.shapeType));v(this,"isPen",!1);v(this,"segmentMode","free");v(this,"didJustShiftClickToExtendPreviousShapeLine",!1);v(this,"pagePointWhereCurrentSegmentChanged",{});v(this,"pagePointWhereNextSegmentChanged",null);v(this,"lastRecordedPoint",{});v(this,"mergeNextPoint",!1);v(this,"currentLineLength",0);v(this,"canDraw",!1);v(this,"markId",null);v(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()});v(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?E.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())});v(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()});v(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()});v(this,"onExit",()=>{this.editor.snaps.clear(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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=Yt[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&&E.Dist(s,a)<o*2}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+Ne(),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 y=[...i.props.segments,h];this.currentLineLength=this.getLineLength(y);const f={id:i.id,type:this.shapeType,props:{segments:y}};this.canClose()&&(f.props.isClosed=this.getIsClosed(y,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(E.Dist(h,t.currentPagePoint)>xc){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const y=mn(a);if(!y)throw Error("Expected a previous segment!");const f=mn(y.points);if(!f)throw Error("Expected a previous last point!");let m;const S=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(y.type==="straight"){this.currentLineLength+=E.Dist(f,S),m={type:"straight",points:[{...f},S]};const x=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=te.applyToPoint(x,f)}else m={type:"straight",points:[S,d]};const w={id:o,type:this.shapeType,props:{segments:[...a,m]}};this.canClose()&&(w.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([w],{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(E.Dist(h,t.currentPagePoint)>xc){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const y=a.slice(),f=y[y.length-1],m=mn(f.points);if(!m)throw Error("No previous point!");const S={type:"free",points:[...E.PointsBetween(m,d,6).map(C=>C.toFixed().toJson())]},w=[...y,S];this.currentLineLength=this.getLineLength(w);const x={id:o,type:this.shapeType,props:{segments:w}};this.canClose()&&(x.props.isClosed=this.getIsClosed(w,s)),this.editor.updateShapes([x],{squashing:!0})}break}case"straight":{const h=a.slice(),p=h[h.length-1],{pagePointWhereCurrentSegmentChanged:y}=this,{currentPagePoint:f,ctrlKey:m}=this.editor.inputs;if(!y)throw Error("We should have a point where the segment changed");let S,w=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(w=!m,this.didJustShiftClickToExtendPreviousShapeLine=!1):w=!m;let x=this.editor.getPointInShapeSpace(i,f).toFixed().toJson(),C=!1,P;if((this.editor.user.getIsSnapMode()?!m:m)&&h.length>2){let _,$=8/this.editor.getZoomLevel();for(let T=0,R=a.length-2;T<R;T++){const L=a[T];if(!L)break;if(L.type==="free")continue;const N=L.points[0],D=mn(L.points);if(!(N&&D))continue;const z=E.NearestPointOnLineSegment(N,D,x),F=E.Dist(z,x);if(F<$){_=z.toFixed().toJson(),$=F,P=L;break}}_&&(C=!0,x=_)}if(C&&P){const _=this.editor.getShapePageTransform(i),$=P.points[0],T=mn(P.points);if(!T)throw Error("Expected a last point!");const R=te.applyToPoint(_,$),L=te.applyToPoint(_,T),N=te.applyToPoint(_,x);this.editor.snaps.setLines([{id:Ne(),type:"points",points:[R,N,L]}])}else{if(this.editor.snaps.clear(),w){const _=E.Angle(y,f),T=Qh(_,24)-_;S=E.RotWith(f,y,T)}else S=f;x=this.editor.getPointInShapeSpace(i,S).toFixed().toJson()}this.currentLineLength+=E.Dist(p.points[0],x),h[h.length-1]={...p,type:"straight",points:[p.points[0],x]};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],y=[...p.points];if(y.length&&this.mergeNextPoint){const{z:m}=y[y.length-1];y[y.length-1]={x:d.x,y:d.y,z:m?Math.max(m,d.z):d.z}}else this.currentLineLength+=E.Dist(y[y.length-1],d),y.push(d);h[h.length-1]={...p,points:y},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}),y.length>500){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const{currentPagePoint:m}=this.editor.inputs,S=We();this.editor.createShapes([{id:S,type:this.shapeType,x:Jh(m.x),y:Jh(m.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(S)),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+=E.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)}}v(aS,"id","drawing");var Qm;let Tk=(Qm=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("drawing",t)});v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(Qm,"id","idle"),Qm);class th extends ie{constructor(){super(...arguments);v(this,"shapeType","draw");v(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}v(th,"id","draw"),v(th,"initial","idle"),v(th,"children",()=>[Tk,aS]);class Vy extends Xd{constructor(){super(...arguments);v(this,"shapeType","frame");v(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)&&ZU(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")})}}v(Vy,"id","frame"),v(Vy,"initial","idle");function ZU(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var Jm;let QU=(Jm=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});v(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}))}});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(Jm,"id","idle"),Jm);var ey;let JU=(ey=class extends ie{constructor(){super(...arguments);v(this,"markId","");v(this,"onPointerUp",()=>{this.complete()});v(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(Yr)}}]).select(o).setCurrentTool("select.resizing",{...t,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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(Yr),w:1,h:1}}]);const o=this.editor.getShape(r);if(!o)return;const s=o.props.geo==="star"?new le(0,0,200,190):o.props.geo==="cloud"?new le(0,0,300,180):new le(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(Yr),w:s.width,h:s.height}}]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},v(ey,"id","pointing"),ey);class nh extends ie{constructor(){super(...arguments);v(this,"shapeType","geo")}}v(nh,"id","geo"),v(nh,"initial","idle"),v(nh,"children",()=>[QU,JU]);class rh extends ie{constructor(){super(...arguments);v(this,"shapeType","highlight");v(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}v(rh,"id","highlight"),v(rh,"initial","idle"),v(rh,"children",()=>[Tk,aS]);var ty;let eH=(ty=class extends ie{constructor(){super(...arguments);v(this,"shapeId","");v(this,"onEnter",t=>{this.shapeId=t.shapeId,this.editor.setCursor({type:"cross",rotation:0})});v(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(ty,"id","idle"),ty);const Cb=2;var ny;let tH=(ny=class extends ie{constructor(){super(...arguments);v(this,"shape",{});v(this,"markId");v(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(m=>m.type==="vertex").sort(Kt),l=a[a.length-1],c=a[a.length-2],u=te.applyToPoint(this.editor.getShapeParentTransform(this.shape),new E(this.shape.x,this.shape.y));let d,h,p;const y=E.Sub(o,u);E.Dist(l,c)<Cb||E.Dist(y,l)<Cb?(d=l.index,h=l.id,p={...l,x:y.x+.1,y:y.y+.1}):(d=yo(l.index),h="handle:"+d,p={id:h,type:"vertex",index:d,x:y.x+.1,y:y.y+.1,canBind:!1});const f=ds(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)}});v(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"})}});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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()}},v(ny,"id","pointing"),ny);class oh extends ie{constructor(){super(...arguments);v(this,"shapeType","line")}}v(oh,"id","line"),v(oh,"initial","idle"),v(oh,"children",()=>[eH,tH]);var ry;let nH=(ry=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(ry,"id","idle"),ry);var oy;let rH=(oy=class extends ie{constructor(){super(...arguments);v(this,"dragged",!1);v(this,"info",{});v(this,"wasFocusedOnEnter",!1);v(this,"markId","");v(this,"shape",{});v(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen(),this.wasFocusedOnEnter&&(this.shape=this.createShape())});v(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")}}))});v(this,"onPointerUp",()=>{this.complete()});v(this,"onInterrupt",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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)}},v(oy,"id","pointing"),oy);class sh extends ie{constructor(){super(...arguments);v(this,"shapeType","note")}}v(sh,"id","note"),v(sh,"initial","idle"),v(sh,"children",()=>[nH,rH]);function Ec(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 sy;let oH=(sy=class extends ie{constructor(){super(...arguments);v(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Ec(this.editor)}});v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});v(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}))}});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(sy,"id","idle"),sy);var iy;let sH=(iy=class extends ie{constructor(){super(...arguments);v(this,"shape");v(this,"markId","");v(this,"onExit",()=>{this.editor.setHintingShapes([])});v(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")}})}});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.cancel()});v(this,"onCancel",()=>{this.cancel()});v(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)}},v(iy,"id","pointing"),iy);class ih extends ie{constructor(){super(...arguments);v(this,"shapeType","text")}}v(ih,"id","text"),v(ih,"initial","idle"),v(ih,"children",()=>[oH,sH]);const iH=[ih,th,nh,sh,oh,Vy,eh,rh];function kt(){return kn({isDarkMode:nf()})}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(aH,{theme:n,color:r,fill:o,d:t})}}),aH=function({d:n,color:t,theme:r}){const o=K(),s=Y("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(#${tp[`${i}_${r.id}`]})`,d:n})]})};function Gn({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 Dr(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 lH(e){return e.replace(/\s/g," ")}function pf(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=le.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 y=document.createElementNS("http://www.w3.org/2000/svg","tspan");y.setAttribute("alignment-baseline","mathematical"),y.setAttribute("x",i+"px"),y.setAttribute("y",u.y+a+"px"),y.textContent=`
|
|
100
|
+
`,o.appendChild(y)}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=lH(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 ff(e){return{key:`${Qr.id}:${e}`,getElement:async()=>{const n=cH(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 cH(e){const n=ou[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function lS(e,n){return{key:`${Qr.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 cS(){return{key:`${Qr.id}:pattern`,component:hH}}const Wl=8,Pb=(e,n,t)=>new Promise((r,o)=>{const s=Wl*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||He.throwToBlob.get()?o():r(u)})}),Eb=(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()):""},uH=()=>{const e=[];for(let n=1;n<=Math.ceil(ts);n++){const t=Eb([1,1],o=>{o.fillStyle=Wh.lightMode.black.semi,o.fillRect(0,0,1,1)}),r=Eb([1,1],o=>{o.fillStyle=Wh.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 dH(){const n=K().getInstanceState().devicePixelRatio,[t,r]=b.useState(!1),o=b.useMemo(()=>uH(),[]),[s,i]=b.useState(o);return b.useEffect(()=>{const l=[];for(let u=1;u<=Math.ceil(ts);u++)l.push(Pb(n,u,!1).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!1}))),l.push(Pb(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:tp[c],width:Wl,height:Wl,patternUnits:"userSpaceOnUse",children:g.jsx("image",{href:l.url,width:Wl,height:Wl})},c)})}),isReady:t}}function hH(){const e=K(),n=b.useRef(null),{defs:t,isReady:r}=dH();return b.useEffect(()=>{if(r&&e.environment.isSafari){const o=$k(n.current);o&&requestAnimationFrame(()=>{o.style.display="none",requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),g.jsx("g",{ref:n,children:t})}function $k(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?$k(e.parentElement):null}function Zt(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 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?E.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,t*3),t);let a;if(e.isStraight)a=E.Nudge(r,o,i);else{const l=u8(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 fH({point:e,int:n}){const t=E.RotWith(n,e,Te/6),r=E.RotWith(n,e,-Te/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function gH({point:e,int:n}){const t=E.RotWith(n,e,Te/6),r=E.RotWith(n,e,-Te/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function mH({point:e,int:n}){const t=E.Sub(n,e).div(2),r=E.Add(e,E.Rot(t,Ve)),o=E.Sub(e,E.Rot(t,Ve));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function yH({point:e,int:n}){const t=E.Lrp(e,n,.45),r=E.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 vH({point:e,int:n}){const t=E.Lrp(e,n,.75),r=E.RotWith(t,e,Te/4),o=E.RotWith(t,e,-Te/4),s=E.Lrp(r,o,.5);return s.add(E.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function SH({int:e,point:n}){const t=E.Lrp(n,e,.85),r=E.Sub(t,n).div(2),o=E.Add(n,E.Rot(r,Ve)),s=E.Sub(n,E.Rot(r,Ve)),i=E.Add(t,E.Rot(r,Ve)),a=E.Sub(t,E.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 wH({int:e,point:n}){const t=E.Sub(e,n).div(2),r=E.Add(n,E.Rot(t,Ve)),o=E.Sub(n,E.Rot(t,Ve));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function Vi(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 wH(o);case"square":return SH(o);case"diamond":return vH(o);case"dot":return yH(o);case"inverted":return mH(o);case"arrow":return fH(o);case"triangle":return gH(o)}return""}}function xH(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 Jg(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 Mk(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function bH(e){return Mk(e.start.handle,e.end.handle)}function em(e){return Mk(e.start.point,e.end.point)}function uS(e,n,t){const r=K(),o=b.useRef(null),s=b.useRef(!1),i=b.useRef(),a=Y("isEditing",()=>r.getEditingShapeId()===e,[r,e]);b.useEffect(()=>{const f=o.current;f&&a&&document.activeElement!==f&&f.focus()},[a]);const l=b.useCallback(()=>{const f=s.current;s.current=!1,requestAnimationFrame(()=>{const m=o.current;if(!m)return;const S=r.getShape(e);S&&(m.value=S.props.text,m.value.length&&!f&&m.select())})},[r,e]),c=b.useCallback(()=>{const f=i.current;requestAnimationFrame(()=>{var w;const m=o.current,S=r.getEditingShapeId();if(m&&S){if(S===e)if(f)if(!f.length)m.focus();else{s.current=!0,m.focus();const x=window.getSelection();x&&f.forEach(C=>x.addRange(C))}else m.focus()}else(w=window.getSelection())==null||w.removeAllRanges(),r.complete()})},[r,e]),u=b.useCallback(f=>{if(a)switch((f.ctrlKey||f.metaKey)&&bt(f),f.key){case"Enter":{(f.ctrlKey||f.metaKey)&&r.complete();break}case"Tab":{Ie(f),f.shiftKey?hs.unindent(f.currentTarget):hs.indent(f.currentTarget);break}}},[r,a]),d=b.useCallback(f=>{if(!a)return;let m=hs.normalizeText(f.currentTarget.value);const S=m.replace(/\t/g,oa);if(S!==m){const w=f.currentTarget.selectionStart;f.currentTarget.value=S,f.currentTarget.selectionStart=w+(S.length-m.length),f.currentTarget.selectionEnd=w+(S.length-m.length),m=S}r.updateShapes([{id:e,type:n,props:{text:m}}])},[r,e,n,a]),h=t.trim().length===0;b.useEffect(()=>{if(!a)return;if(o.current){let m=function(){var w,x;const S=(w=window.getSelection)==null?void 0:w.call(window);if(S&&S.type!=="None"){const C=[];if(S)for(let P=0;P<S.rangeCount;P++)C.push((x=S.getRangeAt)==null?void 0:x.call(S,P));i.current=C}};return document.addEventListener("selectionchange",m),()=>{document.removeEventListener("selectionchange",m)}}},[a]);const p=b.useCallback(f=>{r.dispatch({...Sn(f),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),bt(f)},[r,e]);return{rInput:o,isEditing:a,handleFocus:l,handleBlur:c,handleKeyDown:u,handleChange:d,handleInputPointerDown:p,handleDoubleClick:bt,isEmpty:h}}const CH=b.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:y,handleInputPointerDown:f,handleDoubleClick:m}=uS(n,"arrow",t),w=hs.normalizeTextForDom(t).trim().length>0;return!c&&!w?null:g.jsx("div",{className:"tl-arrow-label","data-font":o,"data-align":"center","data-hastext":!y,"data-isediting":c,style:{textAlign:"center",fontSize:Qo[r],lineHeight:Qo[r]*Dt.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?hs.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:bt,onPointerDown:f,onDoubleClick:m})]})})});let PH=0;class ah extends Tr{constructor(){super(...arguments);v(this,"canEdit",()=>!0);v(this,"canBind",()=>!1);v(this,"canSnap",()=>!1);v(this,"hideResizeHandles",()=>!0);v(this,"hideRotateHandle",()=>!0);v(this,"hideSelectionBoundsBg",()=>!0);v(this,"hideSelectionBoundsFg",()=>!0);v(this,"onHandleChange",(t,{handle:r,isPrecise:o})=>{const s=r.id;if(s==="middle"){const{start:m,end:S}=Cr(this.editor,t),w=E.Sub(S,m),x=E.Per(w),C=E.Med(S,m),P=E.Sub(C,x),k=E.Add(C,x),I=E.NearestPointOnLineSegment(P,k,r,!1);let _=E.Dist(I,C);return E.Clockwise(I,S,C)&&(_*=-1),{id:t.id,type:t.type,props:{bend:_}}}const i=qt(t),l=this.editor.getShapePageTransform(i.id).applyToPoint(r);if(this.editor.inputs.ctrlKey)return i.props[s]={type:"point",x:r.x,y:r.y},i;const c=this.editor.getShapePageTransform(t.id).applyToPoint(r),u=this.editor.getShapeAtPoint(c,{hitInside:!0,hitFrameInside:!0,margin:0,filter:m=>!m.isLocked&&this.editor.getShapeUtil(m).canBind(m)});if(!u)return i.props[s]={type:"point",x:r.x,y:r.y},i;const d=this.editor.getShapeGeometry(u),h=le.ZeroFix(d.bounds),p=this.editor.getPointInShapeSpace(u,l);let y=o;if(!y){const m=i.props[s];(m.type==="point"||m.type==="binding"&&u.id!==m.boundShapeId)&&(y=this.editor.inputs.pointerVelocity.len()<.5)}if(!o){d.isClosed||(y=!0);const m=i.props[s==="start"?"end":"start"];m.type==="binding"&&u.id===m.boundShapeId&&m.isPrecise&&(y=!0)}const f={x:(p.x-h.minX)/h.width,y:(p.y-h.minY)/h.height};return y&&E.Dist(p,h.center)<Math.max(4,Math.min(Math.min(h.width,h.height)*.15,16))/this.editor.getZoomLevel()&&(f.x=.5,f.y=.5),i.props[s]={type:"binding",boundShapeId:u.id,normalizedAnchor:f,isPrecise:y,isExact:this.editor.inputs.altKey},i.props.start.type==="binding"&&i.props.end.type==="binding"&&i.props.start.boundShapeId===i.props.end.boundShapeId&&E.Equals(i.props.start.normalizedAnchor,i.props.end.normalizedAnchor)&&(i.props.end.normalizedAnchor.x+=.05),i});v(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=this.editor.getSelectedShapeIds();if(r&&(s.includes(r)||this.editor.isAncestorSelected(r))||o&&(s.includes(o)||this.editor.isAncestorSelected(o)))return;const{start:i,end:a}=Cr(this.editor,t);return{id:t.id,type:t.type,props:{...t.props,start:{type:"point",x:i.x,y:i.y},end:{type:"point",x:a.x,y:a.y}}}});v(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=Cr(this.editor,t),{start:a,end:l}=qt(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}}});v(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"}}}});v(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:"",font:"draw"}}getGeometry(t){const r=this.editor.getArrowInfo(t),o=r.isStraight?new ip({start:E.From(r.start.point),end:E.From(r.end.point)}):new lL({center:E.Cast(r.handleArc.center),radius:r.handleArc.radius,start:E.Cast(r.start.point),end:E.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let s;if(t.props.text.trim()){const i=o.bounds,{w:a,h:l}=this.editor.textMeasure.measureText(t.props.text,{...Dt,fontFamily:Io[t.props.font],fontSize:Qo[t.props.size],maxWidth:null});let c=a,u=l;if(i.width>i.height){c=Math.max(Math.min(a,64),Math.min(i.width-64,a));const{w:d,h}=this.editor.textMeasure.measureText(t.props.text,{...Dt,fontFamily:Io[t.props.font],fontSize:Qo[t.props.size],maxWidth:c});c=d,u=h}if(c>16*Qo[t.props.size]){c=16*Qo[t.props.size];const{w:d,h}=this.editor.textMeasure.measureText(t.props.text,{...Dt,fontFamily:Io[t.props.font],fontSize:Qo[t.props.size],maxWidth:c});c=d,u=h}s=new xs({x:r.middle.x-c/2-4.25,y:r.middle.y-u/2-4.25,width:c+8.5,height:u+8.5,isFilled:!0,isLabel:!0})}return new os({children:s?[o,s]:[o],isSnappable:!1})}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}]}component(t){const r=kt(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,i=this.editor.getArrowInfo(t),a=le.ZeroFix(this.editor.getShapeGeometry(t).bounds),l=ne.useMemo(()=>this.editor.environment.isSafari?PH+=1:0,[t]);if(!(i!=null&&i.isValid))return null;const c=Yt[t.props.size],u=i.start.arrowhead&&Vi(i,"start",c),d=i.end.arrowhead&&Vi(i,"end",c),h=i.isStraight?em(i):Jg(i);let p=null;if(o===t&&s){const{strokeDasharray:P,strokeDashoffset:k}=Zt(i.isStraight?E.Dist(i.start.handle,i.end.handle):Math.abs(i.handleArc.length),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?bH(i):xH(i),strokeDasharray:P,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:y,strokeDashoffset:f}=Zt(i.isStraight?i.length:Math.abs(i.bodyArc.length),c,{style:t.props.dash}),m=t.props.text.trim()?this.editor.getShapeGeometry(t).children[1]:null,S=!(i.start.arrowhead==="none"||i.start.arrowhead==="arrow"),w=!(i.end.arrowhead==="none"||i.end.arrowhead==="arrow"),x=(t.id+"_clip_"+l).replace(":","_");return g.jsxs(g.Fragment,{children:[g.jsxs(jn,{id:t.id,style:{minWidth:50,minHeight:50},children:[g.jsx("defs",{children:g.jsxs("mask",{id:x,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"}),m&&g.jsx("rect",{x:m.x,y:m.y,width:m.w,height:m.h,fill:"black",rx:4,ry:4}),u&&S&&g.jsx("path",{d:u,fill:i.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),d&&w&&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(#${x})`,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:y,strokeDashoffset:f})]}),u&&S&&t.props.fill!=="none"&&g.jsx(pt,{theme:r,d:u,color:t.props.color,fill:t.props.fill}),d&&w&&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(CH,{id:t.id,text:t.props.text,font:t.props.font,size:t.props.size,position:i.middle,width:(m==null?void 0:m.w)??0,labelColor:r[t.props.labelColor].solid})]})}indicator(t){const{start:r,end:o}=Cr(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=sf(t.id);if(!s||E.Equals(r,o))return null;const u=Yt[t.props.size],d=s.start.arrowhead&&Vi(s,"start",u),h=s.end.arrowhead&&Vi(s,"end",u),p=s.isStraight?em(s):Jg(s),y=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:[y&&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",{...y?{mask:`url(#${f})`}:void 0,children:[y&&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=kn({isDarkMode:this.editor.user.getIsDarkMode()});r.addExportDef(lS(t.props.fill,o));const s=o[t.props.color].solid,i=this.editor.getArrowInfo(t),a=Yt[t.props.size],l=document.createElementNS("http://www.w3.org/2000/svg","g");if(!i)return l;const c=i.start.arrowhead&&Vi(i,"start",a),u=i.end.arrowhead&&Vi(i,"end",a),d=this.editor.getShapeGeometry(t),h=d.bounds,p=t.props.text.trim()?d.children[1]:null,y=(t.id+"_clip").replace(":","_");if(c||u||p){const C=document.createElementNS("http://www.w3.org/2000/svg","defs"),P=document.createElementNS("http://www.w3.org/2000/svg","mask");P.id=y;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"),P.appendChild(k),c&&P.appendChild(kb(c,i.start.arrowhead)),u&&P.appendChild(kb(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"),P.appendChild(I)}C.appendChild(P),l.appendChild(C)}const f=document.createElementNS("http://www.w3.org/2000/svg","g");f.setAttribute("mask",`url(#${y})`),l.appendChild(f);const m=document.createElementNS("http://www.w3.org/2000/svg","rect");m.setAttribute("x","-100"),m.setAttribute("y","-100"),m.setAttribute("width",h.width+200+""),m.setAttribute("height",h.height+200+""),m.setAttribute("fill","transparent"),m.setAttribute("stroke","none"),f.appendChild(m);const S=EH(i.isStraight?em(i):Jg(i),s,a),{strokeDasharray:w,strokeDashoffset:x}=Zt(i.isStraight?i.length:Math.abs(i.bodyArc.length),a,{style:t.props.dash});if(S.setAttribute("stroke-dasharray",w),S.setAttribute("stroke-dashoffset",x),f.appendChild(S),c&&l.appendChild(Ib(c,t.props.color,a,t.props.arrowheadStart==="arrow"?"none":t.props.fill,o)),u&&l.appendChild(Ib(u,t.props.color,a,t.props.arrowheadEnd==="arrow"?"none":t.props.fill,o)),p){r.addExportDef(ff(t.props.font));const C={fontSize:Qo[t.props.size],lineHeight:Dt.lineHeight,fontFamily:ou[t.props.font],padding:0,textAlign:"middle",width:p.w-8,verticalTextAlign:"middle",height:p.h,fontStyle:"normal",fontWeight:"normal",overflow:"wrap"},P=pf(this.editor,this.editor.textMeasure.measureTextSpans(t.props.text,C),C);P.setAttribute("fill",o[t.props.labelColor].solid),Array.from(P.children).forEach(_=>{const $=parseFloat(_.getAttribute("x")||"0"),T=parseFloat(_.getAttribute("y")||"0");_.setAttribute("x",$+4+p.x+"px"),_.setAttribute("y",T+p.y+"px")});const I=P.cloneNode(!0);I.setAttribute("stroke-width","2"),I.setAttribute("fill",o.background),I.setAttribute("stroke",o.background),l.appendChild(I),l.appendChild(P)}return l}getCanvasSvgDefs(){return[cS()]}}v(ah,"type","arrow"),v(ah,"props",fO),v(ah,"migrations",gO);function kb(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 EH(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 Ib(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=Gn({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 _b="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 vu({url:e,zoomLevel:n}){return g.jsx("a",{className:pe("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:bt,onPointerUp:bt,title:e,draggable:!1,children:g.jsx("div",{className:"tl-hyperlink-button__icon",style:{mask:`url("${_b}") center 100% / 100% no-repeat`,WebkitMask:`url("${_b}") center 100% / 100% no-repeat`}})})}const kH=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function dS(e){return kH.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,l=new E(r,o),{x:c,y:u}=l.rot(-e);return`${c}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}class lh extends Qa{constructor(){super(...arguments);v(this,"canResize",()=>!1);v(this,"hideSelectionBoundsFg",()=>!0);v(this,"onBeforeCreate",t=>{Tb(this.editor,t)});v(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(Kn.isValid(r.props.url))Tb(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=IH(t);return g.jsx(ui,{children:g.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:dS(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(vu,{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:rc((r==null?void 0:r.props.title)||"",54)}),(r==null?void 0:r.props.description)&&g.jsx("p",{className:"tl-bookmark__description",children:rc((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:bt,onPointerUp:bt,onClick:bt,children:rc(s,45)})]})]})})}indicator(t){return g.jsx("rect",{width:O(t.props.w),height:O(t.props.h),rx:"6",ry:"6"})}}v(lh,"type","bookmark"),v(lh,"props",mO),v(lh,"migrations",yO);const IH=e=>{try{const n=new URL(e.props.url),t=n.pathname.replace(/\/*$/,"");return`${n.hostname}${t}`}catch{return e.props.url}};function Tb(e,n){const{url:t}=n.props,r=Zs.createId(Hd(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}}]),_H(e,n))}const _H=sP(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 as(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${Mt(r)}L${Mt(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${Mt(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${Mt(e[0].point)}Q${Mt(e[1].point)}${yn(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Mt(e[t-1].point)}`}function TH(e,n={}){const{start:t={},end:r={}}=n,{cap:o=!0}=t,{cap:s=!0}=r;oi(!t.taper&&!r.taper,"cap taper not supported here"),oi(!t.easing&&!r.easing,"cap easing not supported here"),oi(o&&s,"cap must be true");const i=Pr(e,n);rl(i,n);const a=$H(i);let l="";for(const c of a)l+=AH(c,n);return l}function $H(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=E.Angle(o.point,s.point),l=E.Angle(s.point,i.point),c=Math.abs(Jl(a,l))/Math.PI;if(c>.8){const y={...s,point:s.input};t.push(y),n.push(tm(t)),t=[y];continue}if(t.push(s),c<.25)continue;const u=(o.radius+s.radius+i.radius)/3,d=E.Dist(o.point,s.point)/u,h=E.Dist(s.point,i.point)/u;if(d+h<1.5){t.push(s),n.push(tm(t)),t=[s];continue}}return t.push(e[e.length-1]),n.push(tm(t)),n}function tm(e){const n=e[0];for(;e.length>2;){const r=e[1],o=E.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=E.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:E.FromAngle(E.Angle(e[1].point,e[0].point))},e[e.length-1]={...e[e.length-1],vector:E.FromAngle(E.Angle(e[e.length-1].point,e[e.length-2].point))}),e}function MH(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 AH(e,n={}){if(e.length===0)return"";if(e.length===1)return MH(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=bk(e,n);r.reverse();let o=`M${Mt(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=E.Add(s.point,E.Mul(a,i)),c=E.Add(s.point,E.Mul(a,-i));o+=`${Mt(l)}A${O(i)},${O(i)} 0 0 1 ${Mt(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=E.Add(s.point,E.Mul(a,i)),c=E.Add(s.point,E.Mul(a,-i));o+=`${Mt(l)}A${O(i)},${O(i)} 0 0 1 ${Mt(c)}Z`}return o}function fp(){const e=K();return Y("zoom",()=>e.getZoomLevel()<.35,[e])}const OH=e=>e*.65+d4(e*Te/2)*.35,RH=e=>({size:1+e,thinning:.5,streamline:.62+(1+e)/8*.06,smoothing:.62,easing:Xt.easeOutSine,simulatePressure:!0}),DH=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:OH}),$b=e=>({size:1+e,thinning:0,streamline:.62+(1+e)/8*.06,smoothing:.62,simulatePressure:!1,easing:Xt.linear});function Ky({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:Xt.easeOutSine,last:n}}function ad(e,n,t,r){return{...r?$b(n):e.dash==="draw"?e.isPen?DH(n):RH(n):$b(n),last:e.isComplete||t}}function sa(e){const n=[];for(const t of e)if(t.type==="free"||t.points.length<2)n.push(...t.points.map(E.Cast));else{const r=Math.max(4,Math.floor(E.Dist(t.points[0],t.points[1])/16));n.push(...E.PointsBetween(t.points[0],t.points[1],r))}return n}function Mb(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class ch extends Tr{constructor(){super(...arguments);v(this,"hideResizeHandles",t=>rm(t));v(this,"hideRotateHandle",t=>rm(t));v(this,"hideSelectionBoundsFg",t=>rm(t));v(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:Jh(o*l),y:Jh(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=sa(t.props.segments),o=Yt[t.props.size];if(t.props.segments.length===1){const i=le.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new CE({x:-o,y:-o,radius:o,isFilled:!0})}const s=Pr(r,ad(t.props,o,!0,!0)).map(i=>i.point);return t.props.isClosed?new wt({points:s,isFilled:t.props.fill!=="none"}):new xi({points:s})}component(t){var p;const r=kt(),o=fp(),s=Yt[t.props.size],i=sa(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+=us(t.id)()*(s/6));const c=ad(t.props,l,a,o);if(!o&&t.props.dash==="draw")return g.jsxs(jn,{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:as(Pr(i,c),t.props.isClosed)}):null,g.jsx("path",{d:TH(i,c),strokeLinecap:"round",fill:r[t.props.color].solid})]});const u=Pr(i,c),d=u.length<2,h=d?nm(i[0],0):as(u,t.props.isClosed);return g.jsxs(jn,{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":Mb(t,s),strokeDashoffset:"0"})]})}indicator(t){var d;const r=fp(),o=Yt[t.props.size],s=sa(t.props.segments);let i=o;!r&&!t.props.isPen&&t.props.dash==="draw"&&s.length===1&&(i+=us(t.id)()*(o/6));const a=t.props.isComplete||((d=mn(t.props.segments))==null?void 0:d.type)==="straight",l=ad(t.props,i,a,!0),c=Pr(s,l),u=c.length>1?as(c,t.props.isClosed):nm(s[0],i);return g.jsx("path",{d:u})}toSvg(t,r){var f;const o=kn({isDarkMode:this.editor.user.getIsDarkMode()});r.addExportDef(lS(t.props.fill,o));const{color:s}=t.props,i=Yt[t.props.size],a=sa(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+=us(t.id)()*(i/6));const u=ad(t.props,c,l,!1),d=Pr(a,u),h=d.length>1?as(d,t.props.isClosed):nm(a[0],c);let p;if(t.props.dash==="draw"||d.length<2){rl(d,u);const m=yu(d,u),S=document.createElementNS("http://www.w3.org/2000/svg","path");S.setAttribute("d",lu(m,!0)),S.setAttribute("fill",o[s].solid),S.setAttribute("stroke-linecap","round"),p=S}else{const m=document.createElementNS("http://www.w3.org/2000/svg","path");m.setAttribute("d",h),m.setAttribute("stroke",o[s].solid),m.setAttribute("fill","none"),m.setAttribute("stroke-linecap","round"),m.setAttribute("stroke-width",i.toString()),m.setAttribute("stroke-dasharray",Mb(t,i)),m.setAttribute("stroke-dashoffset","0"),p=m}const y=Gn({fill:t.props.isClosed?t.props.fill:"none",d:h,color:t.props.color,theme:o});if(y){const m=document.createElementNS("http://www.w3.org/2000/svg","g");return m.appendChild(y),m.appendChild(p),m}return p}getCanvasSvgDefs(){return[cS()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return Yt[t.props.size]*r/2}}v(ch,"type","draw"),v(ch,"props",vO),v(ch,"migrations",SO);function nm(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 rm(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function jH(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 E(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:y,y:f}=p.rot(e.rotation).add(r);return{x:y,y:f,props:{w:Math.min(l,d),h:Math.min(u,h)}}}const LH=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class uh extends Qa{constructor(){super(...arguments);v(this,"hideSelectionBoundsFg",t=>!this.canResize(t));v(this,"canEdit",()=>!0);v(this,"canUnmount",t=>{var r,o;return!!((o=(r=xo(t.props.url))==null?void 0:r.definition)!=null&&o.canUnmount)});v(this,"canResize",t=>{var r,o;return!!((o=(r=xo(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});v(this,"canEditInReadOnly",()=>!0);v(this,"isAspectRatioLocked",t=>{const r=xo(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});v(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=xo(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 jH(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=sf(t.id),a=b.useMemo(()=>Ik(s),[s]),l=Y("is hovering",()=>{const{editingShapeId:h,hoveredShapeId:p}=this.editor.getCurrentPageState();if(h&&p!==h){const y=this.editor.getShape(h);if(y&&this.editor.isShapeOfType(y,"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(ui,{className:"tl-embed-container",id:t.id,children:g.jsx(NH,{id:h,width:O(r),height:O(o),isInteractive:u,pageRotation:c})})}const d=LH({...xO,...(a==null?void 0:a.definition.overridePermissions)??{}});return g.jsx(ui,{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:dS(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(t){const r=b.useMemo(()=>xo(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})}}v(uh,"type","embed"),v(uh,"props",bO),v(uh,"migrations",CO);function NH({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:dS(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 zH=b.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=K(),s=b.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(bt(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=b.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=b.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}),Ak(n,"Frame")+""]})}),FH=function({id:n,name:t,width:r,height:o}){const s=K(),i=Y("shape rotation",()=>_r(s.getShapePageTransform(n).rotation()),[s,n]),a=sf(n),l=b.useRef(null),c=b.useCallback(y=>{const f=Sn(y);s.getEditingShapeId()!==n&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...f}),y.preventDefault())},[s,n]);b.useEffect(()=>{const y=l.current;y&&a&&(y.focus(),y.select(),requestAnimationFrame(()=>{document.activeElement!==y&&(y.focus(),y.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(zH,{ref:l,id:n,name:t,isEditing:a})})})};function Ak(e,n){return e.match(/^\s*$/)?n:e}class dh extends Qa{constructor(){super(...arguments);v(this,"canBind",()=>!0);v(this,"canEdit",()=>!0);v(this,"canReceiveNewChildrenOfType",(t,r)=>!t.isLocked);v(this,"canDropShapes",(t,r)=>!t.isLocked);v(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}));v(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())});v(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())});v(this,"onResize",(t,r)=>xE(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new xs({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=kt(),s=Y("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(jn,{children:g.jsx("rect",{className:pe("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:g.jsx(FH,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t){const r=kn({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(Ak(t.props.name,"Frame")+"",d),p=h[0],y=mn(h),f=y.box.w+y.box.x-p.box.x,m=pf(this.editor,h,{offsetY:-d.height-2,...d});m.style.setProperty("transform",u);const S=document.createElementNS("http://www.w3.org/2000/svg","rect");return S.setAttribute("x","-8px"),S.setAttribute("y",-d.height-4+"px"),S.setAttribute("width",f+16+"px"),S.setAttribute("height",`${d.height}px`),S.setAttribute("rx","4px"),S.setAttribute("ry","4px"),S.setAttribute("fill",r.background),o.appendChild(S),o.appendChild(m),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}}v(dh,"type","frame"),v(dh,"props",PO),v(dh,"migrations",EO);function BH(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=le.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 UH(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}const Ok=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:y,handleChange:f,handleKeyDown:m,handleBlur:S,handleInputPointerDown:w,handleDoubleClick:x}=uS(n,t,r),C=hs.normalizeTextForDom(r),P=C.length>0,k=UH(a),I=kt();return!p&&!P?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:Ra[o],lineHeight:Ra[o]*Dt.lineHeight+"px",minHeight:Dt.lineHeight+32,minWidth:0,color:I[s].solid},children:[g.jsx("div",{className:"tl-text tl-text-content",dir:"ltr",children:C}),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:y,onChange:f,onKeyDown:m,onBlur:S,onContextMenu:bt,onPointerDown:w,onDoubleClick:x})]})})});function Rk({bounds:e,editor:n,font:t,shape:r}){const s={fontSize:Ra[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:Dt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0},i=n.textMeasure.measureTextSpans(r.props.text,s),a=BH(r.props.align,16,i,e.width);return a&&(s.offsetX=a),pf(n,i,s)}function Bt(e){return`${O(e.x)},${O(e.y)} `}function Dk(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 kc(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+=`${Bt(r)}L${Bt(o)}Q${Bt(s)}`;return n+=`${Bt(e[0])}`,n}function Ic(e,n,t,r,o){const s=[],i=Dk(e);let a=n[0],l;const c=n.length;for(let u=0,d=c*o;u<d;u++){l=E.AddXY(n[(u+1)%c],i()*t,i()*t);const h=E.Sub(l,a),p=E.Len(h),y=E.Div(h,p).mul(Math.min(p/4,r));s.push(E.Add(a,y),E.Add(l,y.neg()),l),a=l}return s}function om(e,n,t){let r=`M ${Bt(n[0])}L`,o=`M ${Bt(n[0])}L`;const s=t/3,i=t*2,a=Dk(e);let l=n[0],c,u=n[0],d;const h=n.length;for(let p=0,y=h-1;p<y;p++){c=n[p+1],d=E.AddXY(n[p+1],a()*s,a()*s);const f=E.Sub(c,l),m=E.Len(f),S=E.Div(f,m).mul(Math.min(m/4,i)),w=E.Add(l,S),x=E.Add(c,S.neg()),C=E.Sub(d,u),P=E.Len(C),k=E.Div(C,P).mul(Math.min(P/4,i)),I=E.Add(u,k),_=E.Add(d,k.neg());p===y-1?(r+=`${Bt(w)}L ${Bt(c)}`,o+=`${Bt(I)}L ${Bt(d)}`):(r+=`${Bt(w)}L ${Bt(x)}Q ${Bt(c)}`,o+=`${Bt(I)}L ${Bt(_)}Q ${Bt(d)}`,l=c,u=d)}return[r,r+o]}function Ab(e,n){const t=Math.min(e,n)/2,r=Math.max(e,n)-t*2;return Math.PI*(t*2)+2*r}function HH(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 E(r,0),delta:new E(1,0)},{type:"arc",center:new E(e-r,r),startAngle:-Te/2},{type:"straight",start:new E(e-r,n),delta:new E(-1,0)},{type:"arc",center:new E(r,r),startAngle:Te/2}]:[{type:"straight",start:new E(e,r),delta:new E(0,1)},{type:"arc",center:new E(r,n-r),startAngle:0},{type:"straight",start:new E(0,n-r),delta:new E(0,-1)},{type:"arc",center:new E(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(E.Add(d.start,E.Mul(d.delta,l))):c.push(EP(d.center.x,d.center.y,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 VH=(e,n,t,r,o)=>{switch(e){case"s":return n;case"m":return t;case"l":return r;case"xl":return o}};function Su(e,n,t,r){const o=us(t),s=Ab(e,n),i=Math.max(Math.ceil(s/VH(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=Ab(l,c)/i,p=HH(l,c,i).map(w=>w.addXY(u,d)),y=e<20?0:a*.3,f=n<20?0:a*.3,m=p.slice(0);for(let w=0;w<Math.floor(i/2);w++)m[w]=E.AddXY(m[w],o()*y,o()*f),m[i-w-1]=E.AddXY(m[i-w-1],o()*y,o()*f);const S=[];for(let w=0;w<m.length;w++){const x=w===m.length-1?0:w+1,C=m[w],P=m[x],k=p[w],I=p[x],_=E.Average([k,I]),$=E.Angle(k,I)-Math.PI/2,T=E.Dist(k,I),R=h-T,N=E.Dist(C,P)/T,D=(Math.max(u,d)+R)*N,z=E.Add(_,E.FromAngle($,D));z.x<0?z.x=0:z.x>e&&(z.x=e),z.y<0?z.y=0:z.y>n&&(z.y=n);const F=jk(C,P,z),W=E.Dist(F||E.Average([C,P]),C);S.push({leftPoint:C,rightPoint:P,arcPoint:z,center:F,radius:W})}return S}function jk(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 E(i,a)}function KH(e,n,t,r){const o=[],s=Su(e,n,t,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of s)o.push(...WH(l,c,i,a,10));return o}function wu(e,n,t,r){const o=Su(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=Nk(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 Lk(e,n,t,r){const o=us(t),s=r==="s"?.5:r==="m"?.7:r==="l"?.9:1.6,i=y=>y+o()*s*2,a=Su(e,n,t,r),u=a.reduce((y,f)=>y+E.Dist(f.leftPoint,f.rightPoint),0)/a.length>s*15?y=>new E(i(y.x),i(y.y)):y=>y;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:y,center:f,rightPoint:m,radius:S,arcPoint:w}of a){if(f===null){d+=` L${O(m.x)},${O(m.y)}`;const _=u(m);p+=` L${O(_.x)},${O(_.y)}`,h=_;continue}const x=Nk(y,m,f)?"0":"1";d+=` A${O(S)},${O(S)} 0 ${x},1 ${O(m.x)},${O(m.y)}`;const C=u(m),P=u(w),k=jk(h,C,P);if(!k){p+=` L${O(C.x)},${O(C.y)}`,h=C;continue}const I=Math.abs(E.Dist(k,h));p+=` A${O(I)},${O(I)} 0 ${x},1 ${O(C.x)},${O(C.y)}`,h=C}return d+p+" Z"}function WH(e,n,t,r,o){if(t===null)return[E.From(e),E.From(n)];const s=[],i=E.Angle(t,e),a=E.Angle(t,n),l=Qp(i,a);for(let c=0;c<o;c++){const u=c/(o-1),d=i+l*u,h=EP(t.x,t.y,r,d);s.push(h)}return s}function Nk(e,n,t){return(n.x-e.x)*(t.y-e.y)-(n.y-e.y)*(t.x-e.x)>0}const GH=b.memo(function({dash:n,fill:t,color:r,strokeWidth:o,w:s,h:i,id:a,size:l}){const c=kt(),u=wu(s,i,a,l),d=Su(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:y,radius:f},m)=>{const S=y?f*_r(_r(E.Angle(y,p))-_r(E.Angle(y,h))):E.Dist(h,p),{strokeDasharray:w,strokeDashoffset:x}=Zt(S,o,{style:n,start:"outset",end:"outset"});return g.jsx("path",{d:y?`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:w,strokeDashoffset:x},m)})})]})});function YH({dash:e,fill:n,color:t,theme:r,strokeWidth:o,w:s,h:i,id:a,size:l}){const c=wu(s,i,a,l),u=Su(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:y,center:f,radius:m}of u){const S=f?m*_r(_r(E.Angle(f,y))-_r(E.Angle(f,p))):E.Dist(p,y),{strokeDasharray:w,strokeDashoffset:x}=Zt(S,o,{style:e,start:"outset",end:"outset"}),C=document.createElementNS("http://www.w3.org/2000/svg","path");C.setAttribute("d",f?`M${p.x},${p.y}A${m},${m},0,0,1,${y.x},${y.y}`:`M${p.x},${p.y}L${y.x},${y.y}`),C.setAttribute("stroke-dasharray",w.toString()),C.setAttribute("stroke-dashoffset",x.toString()),d.appendChild(C)}const h=Gn({d:c,fill:n,color:t,theme:r});return Dr(d,h)}const XH=b.memo(function({w:n,h:t,strokeWidth:r,dash:o,color:s,fill:i}){const a=kt(),l=n/2,c=t/2,u=Math.max(0,l),d=Math.max(0,c),h=wc(u,d),{strokeDasharray:p,strokeDashoffset:y}=Zt(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:y,pointerEvents:"all"})]})});function qH({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=wc(c,u),{strokeDasharray:h,strokeDashoffset:p}=Zt(d<64?d*2:d,t,{style:r,snap:4,closed:!0}),y=`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",y),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 m=Gn({d:y,fill:i,color:o,theme:s});return Dr(f,m)}function zk(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 Fk(e,n){if(e>n){const r=n/2;return wc(r,r)+(e-r*2)*2}const t=e/2;return wc(t,t)+(n-t*2)*2}const ZH=b.memo(function({w:n,h:t,strokeWidth:r,dash:o,color:s,fill:i}){const a=kt(),l=zk(n,t),c=Fk(n,t),{strokeDasharray:u,strokeDashoffset:d}=Zt(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 Ob({w:e,h:n,strokeWidth:t,dash:r,color:o,theme:s,fill:i}){const a=zk(e,n),l=Fk(e,n),{strokeDasharray:c,strokeDashoffset:u}=Zt(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=Gn({d:a,fill:i,color:o,theme:s});return Dr(d,h)}const QH=b.memo(function({dash:n,fill:t,color:r,strokeWidth:o,outline:s,lines:i}){const a=kt(),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=E.Dist(d,h),{strokeDasharray:y,strokeDashoffset:f}=Zt(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:y,strokeDashoffset:f},u)}),i&&i.map(([c,u],d)=>{const h=E.Dist(c,u),{strokeDasharray:p,strokeDashoffset:y}=Zt(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:y},`line_fg_${d}`)})]})]})});function JH({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=E.Dist(d,h),{strokeDasharray:y,strokeDashoffset:f}=Zt(p,o,{style:e}),m=document.createElementNS("http://www.w3.org/2000/svg","line");m.setAttribute("x1",d.x.toString()),m.setAttribute("y1",d.y.toString()),m.setAttribute("x2",h.x.toString()),m.setAttribute("y2",h.y.toString()),m.setAttribute("stroke-dasharray",y.toString()),m.setAttribute("stroke-dashoffset",f.toString()),a.appendChild(m)}),i)for(const[c,u]of i){const d=E.Dist(c,u),{strokeDasharray:h,strokeDashoffset:p}=Zt(d,o,{style:e,start:"skip",end:"skip",snap:e==="dotted"?4:2}),y=document.createElementNS("http://www.w3.org/2000/svg","line");y.setAttribute("x1",c.x.toString()),y.setAttribute("y1",c.y.toString()),y.setAttribute("x2",u.x.toString()),y.setAttribute("y2",u.y.toString()),y.setAttribute("stroke-dasharray",h.toString()),y.setAttribute("stroke-dashoffset",p.toString()),a.appendChild(y)}const l=Gn({d:"M"+s[0]+"L"+s.slice(1)+"Z",fill:n,color:t,theme:r});return Dr(a,l)}const eV=b.memo(function({fill:n,color:t,strokeWidth:r,w:o,h:s,id:i,size:a}){const l=kt(),c=Lk(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 tV({fill:e,color:n,strokeWidth:t,theme:r,w:o,h:s,id:i,size:a}){const l=Lk(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=Gn({d:l,fill:e,color:n,theme:r});return Dr(c,u)}b.memo(function({id:n,w:t,h:r,strokeWidth:o,fill:s,color:i}){const a=kt(),l=hS(n,t,r,o),c=Hk(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 nV({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",Hk(e,n,t,r)),a.setAttribute("fill",i[s].solid);const l=Gn({d:hS(e,n,t,r),fill:o,color:s,theme:i});return Dr(a,l)}function Bk(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function Uk(e,n,t,r){const o=us(e),s=n/2,i=t/2,a=wc(s,i),l=[],c=Ae*o(),u=Ae+Ve/2+Math.abs(o())*Ve,d=Math.max(16,a/10);for(let h=0;h<d;h++){const p=h/(d-1),y=c+p*u,f=Math.cos(y),m=Math.sin(y);l.push(new E(s*f+n*.5+.05*o(),i*m+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?Xt.easeInOutSine(p):Xt.easeInExpo(p)))/2)))}return Pr(l,Bk(r))}function Hk(e,n,t,r){const o=Bk(r);return lu(yu(rl(Uk(e,n,t,r),o),o))}function hS(e,n,t,r){return as(Uk(e,n,t,r))}const rV=b.memo(function({id:n,outline:t,lines:r,fill:o,color:s,strokeWidth:i}){const a=kt(),l=Ic(n,t,i/3,i*2,2);let c=kc(l);if(r)for(const[h,p]of r)c+=`M${h.x},${h.y}L${p.x},${p.y}`;const u=Ic(n,t,0,i*2,1),d=kc(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 oV({id:e,outline:n,lines:t,fill:r,color:o,theme:s,strokeWidth:i}){const a=Ic(e,n,i/3,i*2,2);let l=kc(a);if(t)for(const[p,y]of t)l+=`M${p.x},${p.y}L${y.x},${y.y}`;const c=Ic(e,n,0,i*2,1),u=kc(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=Gn({d:u,fill:r,color:o,theme:s});return Dr(d,h)}const sV=b.memo(function({fill:n,color:t,strokeWidth:r,w:o,h:s,id:i,size:a}){const l=kt(),c=wu(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 iV({fill:e,color:n,strokeWidth:t,theme:r,w:o,h:s,id:i,size:a}){const l=wu(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=Gn({d:l,fill:e,color:n,theme:r});return Dr(c,u)}const Rb=b.memo(function({w:n,h:t,strokeWidth:r,fill:o,color:s}){const i=kt(),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 aV({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=Gn({d:u,fill:r,color:o,theme:s});return Dr(d,h)}const Db=b.memo(function({w:n,h:t,strokeWidth:r,fill:o,color:s}){const i=kt(),a=pS(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 lV({w:e,h:n,strokeWidth:t,fill:r,color:o,theme:s}){const i=pS(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=Gn({d:i,fill:r,color:o,theme:s});return Dr(a,l)}function pS(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 cV=b.memo(function({outline:n,lines:t,fill:r,color:o,strokeWidth:s}){const i=kt();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 uV({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=Gn({d:a,fill:t,color:r,theme:s});return Dr(c,u)}const sm=16,Jn=17*3;class hh extends Qa{constructor(){super(...arguments);v(this,"canEdit",()=>!0);v(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()}}])});v(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),Jn),m=Math.max(Math.abs(c),Jn);f<Jn&&m===Jn&&(f=Jn),f===Jn&&m<Jn&&(m=Jn);const S=ld(this.editor,{...t,props:{...t.props,w:f,h:m}}),w=Math.max(Math.abs(l),S.w)*Math.sign(l),x=Math.max(Math.abs(c),S.h)*Math.sign(c);u=Math.abs(w)-Math.abs(l),d=Math.abs(x)-Math.abs(c),l=w,c=x}const h=new E(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}=h.rot(t.rotation).add(o);return{x:p,y,props:{w:Math.max(Math.abs(l),1),h:Math.max(Math.abs(c),1),growY:0}}});v(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=ld(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}}});v(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=ld(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<Jn&&t.props.h<Jn&&(h=Math.max(h,Jn),p=Math.max(p,Jn),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}}});v(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=Yt[t.props.size],l=t.props.fill!=="none";let c;switch(t.props.geo){case"cloud":{c=new wt({points:KH(r,o,t.id,t.props.size),isFilled:l});break}case"triangle":{c=new wt({points:[new E(s,0),new E(r,o),new E(0,o)],isFilled:l});break}case"diamond":{c=new wt({points:[new E(s,0),new E(r,i),new E(s,o),new E(0,i)],isFilled:l});break}case"pentagon":{c=new wt({points:fg(r,o,5),isFilled:l});break}case"hexagon":{c=new wt({points:fg(r,o,6),isFilled:l});break}case"octagon":{c=new wt({points:fg(r,o,8),isFilled:l});break}case"ellipse":{c=new PE({width:r,height:o,isFilled:l});break}case"oval":{c=new hL({width:r,height:o,isFilled:l});break}case"star":{const m=Ae/5/2,S=Math.floor(5/4)*2,w=5*2-S,x=0,C=Math.floor(5/2)*2,P=Math.cos(-Ve+S*m)*r/2,k=Math.cos(-Ve+w*m)*r/2,I=Math.sin(-Ve+x*m)*o/2,_=Math.sin(-Ve+C*m)*o/2,$=r-Math.abs(P-k),T=o-Math.abs(_-I),R=r/2+k-(r/2-P),L=o/2+I-(o/2-_),N=1,D=(r-R)/2,z=(o-L)/2,F=(r+$)/2,W=(o+T)/2,H=F*N/2,U=W*N/2;c=new wt({points:Array.from(Array(5*2)).map((V,X)=>{const re=-Ve+X*m;return new E(D+(X%2?H:F)*Math.cos(re),z+(X%2?U:W)*Math.sin(re))}),isFilled:l});break}case"rhombus":{const f=Math.min(r*.38,o*.38);c=new wt({points:[new E(f,0),new E(r,0),new E(r-f,o),new E(0,o)],isFilled:l});break}case"rhombus-2":{const f=Math.min(r*.38,o*.38);c=new wt({points:[new E(0,0),new E(r-f,0),new E(r,o),new E(f,o)],isFilled:l});break}case"trapezoid":{const f=Math.min(r*.38,o*.38);c=new wt({points:[new E(f,0),new E(r-f,0),new E(r,o),new E(0,o)],isFilled:l});break}case"arrow-right":{const f=Math.min(r,o)*.38,m=o*.16;c=new wt({points:[new E(0,m),new E(r-f,m),new E(r-f,0),new E(r,o/2),new E(r-f,o),new E(r-f,o-m),new E(0,o-m)],isFilled:l});break}case"arrow-left":{const f=Math.min(r,o)*.38,m=o*.16;c=new wt({points:[new E(f,0),new E(f,m),new E(r,m),new E(r,o-m),new E(f,o-m),new E(f,o),new E(0,o/2)],isFilled:l});break}case"arrow-up":{const f=r*.16,m=Math.min(r,o)*.38;c=new wt({points:[new E(r/2,0),new E(r,m),new E(r-f,m),new E(r-f,o),new E(f,o),new E(f,m),new E(0,m)],isFilled:l});break}case"arrow-down":{const f=r*.16,m=Math.min(r,o)*.38;c=new wt({points:[new E(f,0),new E(r-f,0),new E(r-f,o-m),new E(r,o-m),new E(r/2,o),new E(0,o-m),new E(f,o-m)],isFilled:l});break}case"check-box":case"x-box":case"rectangle":{c=new xs({width:r,height:o,isFilled:l,isSnappable:!0});break}}const u=ld(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=cd(t.props,a),y=p?p.map(f=>new xi({points:f})):[];return new os({children:[c,new xs({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}),...y],isSnappable:!1})}component(t){const{id:r,type:o,props:s}=t,i=Yt[s.size],{w:a,color:l,labelColor:c,fill:u,dash:d,growY:h,font:p,align:y,verticalAlign:f,size:m,text:S}=s,w=()=>{const x=s.h+h;switch(s.geo){case"cloud":{if(d==="solid")return g.jsx(sV,{color:l,fill:u,strokeWidth:i,w:a,h:x,id:r,size:m});if(d==="dashed"||d==="dotted")return g.jsx(GH,{color:l,fill:u,strokeWidth:i,w:a,h:x,id:r,size:m,dash:d});if(d==="draw")return g.jsx(eV,{color:l,fill:u,strokeWidth:i,w:a,h:x,id:r,size:m});break}case"ellipse":{if(d==="solid")return g.jsx(Rb,{strokeWidth:i,w:a,h:x,color:l,fill:u});if(d==="dashed"||d==="dotted")return g.jsx(XH,{id:r,strokeWidth:i,w:a,h:x,dash:d,color:l,fill:u});if(d==="draw")return g.jsx(Rb,{strokeWidth:i,w:a,h:x,color:l,fill:u});break}case"oval":{if(d==="solid")return g.jsx(Db,{strokeWidth:i,w:a,h:x,color:l,fill:u});if(d==="dashed"||d==="dotted")return g.jsx(ZH,{id:r,strokeWidth:i,w:a,h:x,dash:d,color:l,fill:u});if(d==="draw")return g.jsx(Db,{strokeWidth:i,w:a,h:x,color:l,fill:u});break}default:{const C=this.editor.getShapeGeometry(t),P=C instanceof os?C.children[0].vertices:C.vertices,k=cd(t.props,i);if(d==="solid")return g.jsx(cV,{fill:u,color:l,strokeWidth:i,outline:P,lines:k});if(d==="dashed"||d==="dotted")return g.jsx(QH,{dash:d,fill:u,color:l,strokeWidth:i,outline:P,lines:k});if(d==="draw")return g.jsx(rV,{id:r,fill:u,color:l,strokeWidth:i,outline:P,lines:k})}}};return g.jsxs(g.Fragment,{children:[g.jsx(jn,{id:r,children:w()}),g.jsxs(ui,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:[g.jsx(Ok,{id:r,type:o,font:p,fill:u,size:m,align:y,verticalAlign:f,text:S,labelColor:c,wrap:!0,bounds:s.geo==="cloud"?this.getGeometry(t).bounds:void 0}),t.props.url&&g.jsx(vu,{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=Yt[i];switch(o.geo){case"ellipse":return o.dash==="draw"?g.jsx("path",{d:hS(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:pS(s,a)});case"cloud":return g.jsx("path",{d:wu(s,a,r,i)});default:{const c=this.editor.getShapeGeometry(t),u=c instanceof os?c.children[0].vertices:c.vertices;let d;if(o.dash==="draw"){const p=Ic(r,u,0,l*2,1);d=kc(p)}else d="M"+u[0]+"L"+u.slice(1)+"Z";const h=cd(t.props,l);if(h)for(const[p,y]of h)d+=`M${p.x},${p.y}L${y.x},${y.y}`;return g.jsx("path",{d})}}}toSvg(t,r){const{id:o,props:s}=t,i=Yt[s.size],a=kn({isDarkMode:this.editor.user.getIsDarkMode()});r.addExportDef(lS(t.props.fill,a));let l;switch(s.geo){case"ellipse":{switch(s.dash){case"draw":l=nV({id:o,w:s.w,h:s.h,color:s.color,fill:s.fill,strokeWidth:i,theme:a});break;case"solid":l=aV({strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,theme:a});break;default:l=qH({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=Ob({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=lV({strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,theme:a});break;default:l=Ob({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=tV({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=iV({strokeWidth:i,w:s.w,h:s.h,color:s.color,fill:s.fill,size:s.size,id:o,theme:a});break;default:l=YH({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 os?c.children[0].vertices:c.vertices,d=cd(t.props,i);switch(s.dash){case"draw":l=oV({id:o,fill:s.fill,color:s.color,strokeWidth:i,outline:u,lines:d,theme:a});break;case"solid":l=uV({fill:s.fill,color:s.color,strokeWidth:i,outline:u,lines:d,theme:a});break;default:l=JH({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(ff(t.props.font));const u=Rk({editor:this.editor,shape:t,font:ou[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 y=document.createElementNS("http://www.w3.org/2000/svg","g");return y.appendChild(l),y.appendChild(p),y}}return l}getCanvasSvgDefs(){return[cS()]}}v(hh,"type","geo"),v(hh,"props",kO),v(hh,"migrations",IO);function ld(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Dt,fontFamily:Io[n.props.font],fontSize:Ra[n.props.size],maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(t,{...Dt,fontFamily:Io[n.props.font],fontSize:Ra[n.props.size],minWidth:r.w+"px",maxWidth:Math.max(0,Math.ceil(r.w+o[n.props.size]),Math.ceil(n.props.w-sm*2))});return{w:s.w+sm*2,h:s.h+sm*2}}function cd(e,n){switch(e.geo){case"x-box":return dV(e.w,e.h,n,e.dash);case"check-box":return hV(e.w,e.h);default:return}}function dV(e,n,t,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new E(0,0),new E(e/2,n/2)],[new E(e,n),new E(e/2,n/2)],[new E(0,n),new E(e/2,n/2)],[new E(e,0),new E(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 E(s(t*o),i(t*o)),new E(s(e-t*o),i(n-t*o))],[new E(s(t*o),i(n-t*o)),new E(s(e-t*o),i(t*o))]]}function hV(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 E(s(r+t*.25),i(o+t*.52)),new E(s(r+t*.45),i(o+t*.82))],[new E(s(r+t*.45),i(o+t*.82)),new E(s(r+t*.82),i(o+t*.22))]]}function pV(){const[e,n]=b.useState(!1);return b.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)},[]),Y(He.forceSrgb)||!e?"srgb":"p3"}const jb=.35,Lb=.82;class ph extends Tr{constructor(){super(...arguments);v(this,"hideResizeHandles",t=>ud(t));v(this,"hideRotateHandle",t=>ud(t));v(this,"hideSelectionBoundsFg",t=>ud(t));v(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=Ki(t);if(ud(t))return new CE({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=Vk(t,r,!0),i=Ky({strokeWidth:s,showAsComplete:!0});return rl(o,i),new wt({points:yu(o,i),isFilled:!0})}component(t){return g.jsx(Nb,{strokeWidth:Ki(t),shape:t,opacity:jb})}backgroundComponent(t){return g.jsx(Nb,{strokeWidth:Ki(t),shape:t,opacity:Lb})}indicator(t){var d;const r=fp(),o=Ki(t),s=sa(t.props.segments);let i=o;!r&&!t.props.isPen&&s.length===1&&(i+=us(t.id)()*(o/6));const a=t.props.isComplete||((d=mn(t.props.segments))==null?void 0:d.type)==="straight",l=Ky({strokeWidth:o,showAsComplete:a}),c=Pr(s,l);let u;return c.length<2?u=gV(s[0],i):u=as(c,!1),g.jsx("path",{d:u})}toSvg(t){const r=kn({isDarkMode:this.editor.user.getIsDarkMode()});return zb(Ki(t),t,jb,r)}toBackgroundSvg(t){const r=kn({isDarkMode:this.editor.user.getIsDarkMode()});return zb(Ki(t),t,Lb,r)}}v(ph,"type","highlight"),v(ph,"props",$O),v(ph,"migrations",MO);function fV(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 gV(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 Vk(e,n,t){var l;const r=sa(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+=us(e.id)()*(n/6));const i=Ky({strokeWidth:s,showAsComplete:o});return{strokePoints:Pr(r,i),sw:s}}function Kk(e,n,t){const{strokePoints:r,sw:o}=Vk(e,n,t);return{solidStrokePath:r.length>1?as(r,!1):fV(e.props.segments[0].points[0]),sw:o}}function Nb({strokeWidth:e,shape:n,opacity:t}){const r=kt(),o=fp(),{solidStrokePath:s,sw:i}=Kk(n,e,o),a=pV(),l=r[n.props.color].highlight[a];return g.jsx(jn,{id:n.id,style:{opacity:t},children:g.jsx("path",{d:s,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:l,strokeWidth:i})})}function zb(e,n,t,r){const{solidStrokePath:o,sw:s}=Kk(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 Ki(e){return is[e.props.size]*1.12}function ud(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function Wk(){const[e,n]=b.useState(!1);return b.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 mV=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}),yV=async e=>{const n=await mV(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 vV(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 fh extends Qa{constructor(){super(...arguments);v(this,"isAspectRatioLocked",()=>!0);v(this,"canCrop",()=>!0);v(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}}])});v(this,"onDoubleClickEdge",t=>{const r=t.props;if(!r||this.editor.getCroppingShapeId()!==t.id)return;const o=qt(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 E(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=Fb(t),o=Px(t.id),s=Wk(),[i,a]=b.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=Y("onlySelectedShape",()=>{var y;return t.id===((y=this.editor.getOnlySelectedShape())==null?void 0:y.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 b.useEffect(()=>{if(l!=null&&l.props.src&&"mimeType"in l.props&&(l==null?void 0:l.props.mimeType)==="image/gif"){let y=!1;return(async()=>{const m=await yV(l.props.src);y||m&&a(m)})(),()=>{y=!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(ui,{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(vu,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]})}indicator(t){return Px(t.id)?null:g.jsx("rect",{width:O(t.props.w),height:O(t.props.h)})}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)||"";s&&s.startsWith("http")&&(s=await vV(s)||"");const i=document.createElementNS("http://www.w3.org/2000/svg","image");i.setAttributeNS("http://www.w3.org/1999/xlink","href",s);const a=Fb(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,y=[new E(0,0),new E(h,0),new E(h,p),new E(0,p)],f=document.createElementNS("http://www.w3.org/2000/svg","polygon");f.setAttribute("points",y.map(x=>`${x.x},${x.y}`).join(" "));const m=document.createElementNS("http://www.w3.org/2000/svg","clipPath");m.setAttribute("id","cropClipPath"),m.appendChild(f);const S=document.createElementNS("http://www.w3.org/2000/svg","defs");S.appendChild(m),r.appendChild(S);const w=document.createElementNS("http://www.w3.org/2000/svg","g");w.setAttribute("clip-path","url(#cropClipPath)"),i.setAttribute("width",u.toString()),i.setAttribute("height",d.toString()),i.style.transform=c,w.appendChild(i),r.appendChild(w)}else i.setAttribute("width",t.props.w.toString()),i.setAttribute("height",t.props.h.toString()),r.appendChild(i);return r}}v(fh,"type","image"),v(fh,"props",OO),v(fh,"migrations",RO);function Fb(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 Wy(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 Gy(e,n){const{a:t,b:r,c:o,d:s}=e;return E.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 Gk(e,n){let t=e.segments.reduce((r,o,s)=>r+Gy(o,s===0),"");return n&&(t+="Z"),t}function SV(e,n){let t=e.segments.reduce((r,o,s)=>r+Wy(o,s===0),"");return n&&(t+="Z"),t}function Yk(e,n=!1){return e instanceof xi?SV(e,n):Gk(e,n)}function Xk(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function qk(e,n,t){const r=n.vertices,o=Xk(t);return Pr(r,o)}function wV(e,n,t){const r=Xk(t);return yu(rl(qk(e,n,t),r),r)}function Bb(e,n,t){const r=wV(e,n,t);return lu(r)}function xV(e,n,t){if(e.props.dash==="draw"){const r=qk(e,n,t);return as(r)}return Yk(n)}const bV=new Rv;class gh extends Tr{constructor(){super(...arguments);v(this,"hideResizeHandles",()=>!0);v(this,"hideRotateHandle",()=>!0);v(this,"hideSelectionBoundsFg",()=>!0);v(this,"hideSelectionBoundsBg",()=>!0);v(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=qt(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}}});v(this,"onHandleChange",(t,{handle:r})=>{const o=qt(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 Il(t)}getHandles(t){return bV.get(t.props,()=>{const r=t.props.handles,o=Il(t),s=Object.values(r).sort(Kt),i=s.slice();for(let a=0;a<o.segments.length;a++){const c=o.segments[a].midPoint(),u=ec(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(Kt)})}getOutlineSegments(t){return this.editor.getShapeGeometry(t).segments.map(o=>o.vertices)}component(t){const r=kt(),o=Il(t),s=Yt[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(jn,{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(jn,{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}=Zt(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:Wy(u,!0),fill:"none"},d)})})]})}if(i==="draw"){const l=o.points,[c,u]=om(t.id,l,s);return g.jsxs(jn,{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=Yk(o);if(i==="solid")return g.jsxs(jn,{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(jn,{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}=Zt(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:Gy(c,!0),fill:"none"},u)})})]});if(i==="draw")return g.jsxs(jn,{id:t.id,children:[g.jsx(pt,{d:l,fill:"none",color:a,theme:r}),g.jsx("path",{d:Bb(t,o,s),strokeWidth:1,stroke:r[a].solid,fill:r[a].solid})]})}}indicator(t){const r=Yt[t.props.size],o=Il(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]=om(t.id,a,r);i=l}}else i=xV(t,o,r);return g.jsx("path",{d:i})}toSvg(t){const o=kn({isDarkMode:this.editor.user.getIsDarkMode()})[t.props.color].solid,s=Il(t),i=Yt[t.props.size];switch(t.props.dash){case"draw":{let a;if(s instanceof qd)a=Bb(t,s,i);else{const[c,u]=om(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 qd)a=Gk(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 qd?Gy:Wy;return a.forEach((u,d)=>{const h=document.createElementNS("http://www.w3.org/2000/svg","path"),{strokeDasharray:p,strokeDashoffset:y}=Zt(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",y.toString()),h.setAttribute("d",c(u,!0)),h.setAttribute("fill","none"),l.appendChild(h)}),l}}}}v(gh,"type","line"),v(gh,"props",LO),v(gh,"migrations",NO);function Il(e){const{spline:n,handles:t}=e.props,r=Object.values(t).sort(Kt).map(E.From);switch(n){case"cubic":return new qd({points:r});case"line":return new xi({points:r})}}const vo=200;class mh extends Tr{constructor(){super(...arguments);v(this,"canEdit",()=>!0);v(this,"hideResizeHandles",()=>!0);v(this,"hideSelectionBoundsFg",()=>!0);v(this,"onBeforeCreate",t=>Ub(this.editor,t,t.props.growY));v(this,"onBeforeUpdate",(t,r)=>{if(!(t.props.text===r.props.text&&t.props.font===r.props.font&&t.props.size===r.props.size))return Ub(this.editor,r,t.props.growY)});v(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 xs({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=kt(),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(Ok,{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(vu,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return g.jsx("rect",{rx:"7",width:O(vo),height:O(this.getHeight(t))})}toSvg(t,r){r.addExportDef(ff(t.props.font));const o=kn({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=Rk({editor:this.editor,shape:t,font:ou[t.props.font],bounds:s});return u.setAttribute("fill",o.text),u.setAttribute("stroke","none"),i.appendChild(u),i}}v(mh,"type","note"),v(mh,"props",zO),v(mh,"migrations",FO);function Ub(e,n,t=0){const s=e.textMeasure.measureText(n.props.text,{...Dt,fontFamily:Io[n.props.font],fontSize:Ra[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 CV(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),i=new E(0,0);t<0&&(i.x=-(n.width*s)),r<0&&(i.y=-(n.height*s));const{x:a,y:l}=E.Add(o,i.rot(e.rotation));return{x:a,y:l,props:{scale:s*e.props.scale}}}const PV=new Rv;class yh extends Tr{constructor(){super(...arguments);v(this,"canEdit",()=>!0);v(this,"isAspectRatioLocked",()=>!0);v(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,...CV(t,r)};{const l=o.width;let c=l*i;const u=new E(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}}}});v(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}});v(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()}}])});v(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=Hb(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 E((u-l)/2,s?0:(d-c)/2);break}case"end":{h=new E(u-l,s?0:(d-c)/2);break}default:{if(s)break;h=new E(0,(d-c)/2);break}}if(h){h.rot(r.rotation);const{x:p,y}=r;return{...r,x:p-h.x,y:y-h.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}});v(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 PV.get(t.props,r=>Hb(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:s}=this.getMinDimensions(t);return new xs({width:o*r,height:s*r,isFilled:!0})}component(t){const{id:r,type:o,props:{text:s,color:i}}=t,a=kn({isDarkMode:this.editor.user.getIsDarkMode()}),{width:l,height:c}=this.getMinDimensions(t),{rInput:u,isEmpty:d,isEditing:h,handleFocus:p,handleChange:y,handleKeyDown:f,handleBlur:m,handleInputPointerDown:S,handleDoubleClick:w}=uS(r,o,s);return g.jsx(ui,{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:is[t.props.size],lineHeight:is[t.props.size]*Dt.lineHeight+"px",transform:`scale(${t.props.scale})`,transformOrigin:"top left",width:Math.max(1,l),height:Math.max(is[t.props.size]*Dt.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:y,onKeyDown:f,onBlur:m,onTouchEnd:bt,onContextMenu:bt,onPointerDown:S,onDoubleClick:w}):null]})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=K();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(ff(t.props.font));const o=kn({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:is[t.props.size],fontFamily:ou[t.props.font],textAlign:t.props.align,verticalTextAlign:"middle",width:a,height:l,padding:0,lineHeight:Dt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap"},u=o[t.props.color].solid,d=document.createElementNS("http://www.w3.org/2000/svg","g"),h=pf(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}}v(yh,"type","text"),v(yh,"props",BO),v(yh,"migrations",UO);function Hb(e,n){const{font:t,text:r,autoSize:o,size:s,w:i}=n,a=o?16:Math.max(16,i),l=is[s],c=o?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...Dt,fontFamily:Io[t],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}class vh extends Qa{constructor(){super(...arguments);v(this,"canEdit",()=>!0);v(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(t){return g.jsx(kV,{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",EV(t.id)),o.setAttribute("width",t.props.w.toString()),o.setAttribute("height",t.props.h.toString()),r.appendChild(o),r}}v(vh,"type","video"),v(vh,"props",HO),v(vh,"migrations",VO);function EV(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 kV=Re(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=sf(t.id),c=Wk(),u=ne.useRef(null),d=ne.useCallback(S=>{const w=S.currentTarget;r.editor.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:w.currentTime}}])},[t.id,r.editor]),h=ne.useCallback(S=>{const w=S.currentTarget;r.editor.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:w.currentTime}}])},[t.id,r.editor]),p=ne.useCallback(S=>{const w=S.currentTarget;l&&r.editor.updateShapes([{type:"video",id:t.id,props:{time:w.currentTime}}])},[l,t.id,r.editor]),[y,f]=ne.useState(!1),m=ne.useCallback(S=>{const w=S.currentTarget;i!==w.currentTime&&(w.currentTime=i),a||w.pause(),f(!0)},[a,i]);return ne.useEffect(()=>{const S=u.current;S&&(y&&!l&&i!==S.currentTime&&(S.currentTime=i),l&&document.activeElement!==S&&S.focus())},[l,y,i]),ne.useEffect(()=>{if(c){const S=u.current;S.pause(),S.currentTime=0}},[u,c]),g.jsxs(g.Fragment,{children:[g.jsx(ui,{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:m,hidden:!y,children:g.jsx("source",{src:s.props.src})}):null})}),"url"in t.props&&t.props.url&&g.jsx(vu,{url:t.props.url,zoomLevel:r.editor.getZoomLevel()})]})}),IV=[yh,lh,ch,hh,mh,gh,dh,ah,ph,uh,fh,vh];function _V(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 Zk extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"scribbleId","id");v(this,"markId","");v(this,"excludedShapeIds",new Set);v(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()});v(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});v(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});v(this,"onPointerMove",()=>{this.update()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(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&&!eo(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)}}v(Zk,"id","erasing");var ay;let TV=(ay=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(ay,"id","idle"),ay);var ly;let $V=(ly=class extends ie{constructor(){super(...arguments);v(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])});v(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("erasing",t)});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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")}},v(ly,"id","pointing"),ly);class Sh extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}v(Sh,"id","eraser"),v(Sh,"initial","idle"),v(Sh,"children",()=>[TV,$V,Zk]);class Qk extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{this.update()});v(this,"onPointerMove",()=>{this.update()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()})}update(){const{currentScreenPoint:t,previousScreenPoint:r}=this.editor.inputs,o=E.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:Vd}),this.parent.transition("idle")}}v(Qk,"id","dragging");var cy;let MV=(cy=class extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});v(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});v(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},v(cy,"id","idle"),cy);var uy;let AV=(uy=class extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});v(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("dragging",t)});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onInterrupt",()=>{this.complete()})}complete(){this.parent.transition("idle")}},v(uy,"id","pointing"),uy);class wh extends ie{constructor(){super(...arguments);v(this,"onDoubleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{duration:220,easing:Xt.easeOutQuint})}});v(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{duration:320,easing:Xt.easeOutQuint})}});v(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:Xt.easeOutQuint}):this.editor.resetZoom(o,{duration:320,easing:Xt.easeOutQuint})}})}}v(wh,"id","hand"),v(wh,"initial","idle"),v(wh,"children",()=>[MV,AV,Qk]);var dy;let OV=(dy=class extends ie{constructor(){super(...arguments);v(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},v(dy,"id","idle"),dy);class Jk extends ie{constructor(){super(...arguments);v(this,"scribbleId","id");v(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()});v(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});v(this,"onPointerMove",()=>{this.pushPointToScribble()});v(this,"onPointerUp",()=>{this.complete()});v(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}v(Jk,"id","lasering");class xh extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}v(xh,"id","laser"),v(xh,"initial","idle"),v(xh,"children",()=>[OV,Jk]);class eI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"brush",new le);v(this,"initialSelectedShapeIds",[]);v(this,"excludedShapeIds",new Set);v(this,"initialStartShape",null);v(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()});v(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});v(this,"onTick",()=>{Fv(this.editor)});v(this,"onPointerMove",()=>{this.hitTestShapes()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",t=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds,{squashing:!0}),this.parent.transition("idle",t)});v(this,"onKeyDown",t=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()});v(this,"onKeyUp",()=>{this.hitTestShapes()});v(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(le.FromPoints([s,i]));const c=new Set(a?this.initialSelectedShapeIds:[]);let u,d,h,p,y,f;const{corners:m}=this.brush,{excludedShapeIds:S}=this;e:for(let w=0,x=r.length;w<x;w++){if(h=r[w],S.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,m);continue e}if(l||this.editor.isShapeOfType(h,"frame"))continue e;if(this.brush.collides(p)){const C=this.editor.getShapeGeometry(h);if(y=this.editor.getShapePageTransform(h),!y)continue e;f=y.clone().invert().applyToPoints(m);t:for(let P=0;P<f.length;P++)if(u=f[P],d=f[(P+1)%f.length],C.hitTestLineSegment(u,d,Or/t)){this.handleHit(h,i,o,c,m);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&&!h8(l,i)&&!eo(r,l)||s.add(a.id)}}v(eI,"id","brushing");function fS(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 tI(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=qt(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 hy;let RV=(hy=class extends ie{constructor(){super(...arguments);v(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))});v(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.off("change-history",this.cleanupCroppingState)});v(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});v(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=fS(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}}}});v(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))});v(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});v(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});v(this,"onKeyUp",t=>{switch(t.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}});v(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 E(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 E(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=tI(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},v(hy,"id","idle"),hy);class nI extends ie{constructor(){super(...arguments);v(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});v(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",t)});v(this,"onPointerUp",t=>{this.editor.setCurrentTool("select.crop.idle",t)})}}v(nI,"id","pointing_crop");class rI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"markId","translating crop");v(this,"snapshot",{});v(this,"onEnter",t=>{this.info=t,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});v(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});v(this,"onPointerMove",()=>{this.updateShapes()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onKeyDown",t=>{switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}});v(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=tI(this.editor,t,s);i&&this.editor.updateShapes([i],{squashing:!0})}}v(rI,"id","translating_crop");class bh extends ie{}v(bh,"id","crop"),v(bh,"initial","idle"),v(bh,"children",()=>[RV,rI,nI]);const er=8,Da={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 oI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"onEnter",t=>{this.info=t,this.updateCursor()});v(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("resizing",this.info)});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const t=this.editor.getSelectedShapes(),r=Da[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")}}v(oI,"id","pointing_resize_handle");class sI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"markId","");v(this,"snapshot",{});v(this,"onEnter",t=>{this.info=t,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});v(this,"onPointerMove",()=>{this.updateShapes()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){const t=this.editor.getSelectedShapes()[0];if(!t)return;const r=Da[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=qt(c),d=new E(t.x,t.y),h=new E(0,0),p=1/(c.bottomRight.x-c.topLeft.x)*s.w,y=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(y<er)break;f=!0,u.topLeft.y=u.topLeft.y+l.y/y,y*(u.bottomRight.y-u.topLeft.y)<er?(u.topLeft.y=u.bottomRight.y-er/y,h.y=(u.topLeft.y-c.topLeft.y)*y):u.topLeft.y<=0?(u.topLeft.y=0,h.y=(u.topLeft.y-c.topLeft.y)*y):h.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(y<er)break;f=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/y),y*(u.bottomRight.y-u.topLeft.y)<er&&(u.bottomRight.y=u.topLeft.y+er/y);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<er)break;f=!0,u.topLeft.x=u.topLeft.x+l.x/p,p*(u.bottomRight.x-u.topLeft.x)<er?(u.topLeft.x=u.bottomRight.x-er/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<er)break;f=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/p),p*(u.bottomRight.x-u.topLeft.x)<er&&(u.bottomRight.x=u.topLeft.x+er/p);break}}if(!f)return;d.add(h.rot(t.rotation));const m={id:t.id,type:t.type,x:d.x,y:d.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*p,h:(u.bottomRight.y-u.topLeft.y)*y}};this.editor.updateShapes([m],{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=E.RotWith(s.getHandlePoint(this.info.handle),s.point,t),a=E.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}v(sI,"id","cropping");class iI extends ie{constructor(){super(...arguments);v(this,"shapeId","");v(this,"initialHandle",{});v(this,"initialAdjacentHandle",null);v(this,"initialPagePoint",{});v(this,"markId","");v(this,"initialPageTransform");v(this,"initialPageRotation");v(this,"info",{});v(this,"isPrecise",!1);v(this,"isPreciseId",null);v(this,"pointingId",null);v(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=qt(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(Kt),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)});v(this,"exactTimeout",-1);v(this,"onPointerMove",()=>{this.update()});v(this,"onKeyDown",()=>{this.update()});v(this,"onKeyUp",()=>{this.update()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(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:y,pointerVelocity:f}}=t,m=this.info.shape,S=t.getShape(r);if(!S)return;const w=t.getShapeUtil(S);let x=d.clone().sub(o).rot(-i).add(s);if(h&&a&&s.id!=="middle"){const I=E.Angle(a,x),$=Qh(I,24)-I;x=E.RotWith(x,a,$)}if(t.snaps.clear(),s.canSnap&&(c?!p:p)){const I=t.getShapePageTransform(S.id);if(!I)throw Error("Expected a page transform");const _=t.getShapeHandles(S).filter(({type:R})=>R==="vertex").sort(Kt).findIndex(({index:R})=>s.index===R),$=w.getOutlineSegments(S).map(R=>te.applyToPoints(I,R)).filter((R,L)=>L!==_-1&&L!==_),T=u.getSnappingHandleDelta({additionalSegments:$,handlePoint:te.applyToPoint(I,x)});T&&(T.rot(-t.getShapeParentTransform(S).rotation()),x.add(T))}const C=(k=w.onHandleChange)==null?void 0:k.call(w,S,{handle:{...s,x:x.x,y:x.y},isPrecise:this.isPrecise||y,initial:m}),P={...S,...C};if(s.canBind){const I=P.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||y,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())}C&&t.updateShapes([P],{squashing:!0})}}v(iI,"id","dragging_handle");class aI extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{const t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");Ec(this.editor),this.editor.select(t)});v(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)});v(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":{Ec(this.editor);return}}});v(this,"onPointerDown",t=>{switch(t.target){case"canvas":{const r=fS(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)});v(this,"onComplete",t=>{this.parent.transition("idle",t)});v(this,"onCancel",t=>{this.parent.transition("idle",t)})}}v(aI,"id","editing_shape");function Vb(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function gp(e){const n=e.getSelectedShapeIds(),{shiftKey:t,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin: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(tr(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}var py;let DV=(py=class extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Ec(this.editor),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});v(this,"onPointerMove",()=>{Ec(this.editor)});v(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&Vb(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=fS(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))&&Kb(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{if(this.editor.isShapeOrAncestorLocked(t.shape)){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}}});v(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")){gp(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){gp(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)}}});v(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))&&Kb(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}}});v(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});v(this,"onKeyDown",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);break}}});v(this,"onKeyRepeat",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});v(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}Vb(this.editor)&&this.parent.transition("crop",t);break}}});v(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 E(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 E(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*NV:i:o?jV:LV;this.editor.nudgeShapes(this.editor.getSelectedShapeIds(),s.mul(a))}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},v(py,"id","idle"),py);const jV=10,LV=1,NV=5;function Kb(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?eo(n,t.corners.map(o=>E.RotWith(o,t.point,r))):t.containsPoint(n)}class lI extends ie{constructor(){super(...arguments);v(this,"onEnter",()=>{const{inputs:t}=this.editor;t.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});v(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",t)});v(this,"onPointerUp",()=>{gp(this.editor),this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}v(lI,"id","pointing_canvas");class cI extends ie{constructor(){super(...arguments);v(this,"info",{});v(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))});v(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});v(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})});v(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()})}updateCursor(t){const r=Da[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"))}}v(cI,"id","pointing_crop_handle");class uI extends ie{constructor(){super(...arguments);v(this,"info",{});v(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})});v(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});v(this,"onPointerUp",()=>{this.parent.transition("idle",this.info)});v(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("dragging_handle",this.info)});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()})}cancel(){this.parent.transition("idle")}}v(uI,"id","pointing_handle");class dI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"onEnter",t=>{this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.updateCursor()});v(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});v(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;t&&this.parent.transition("rotating",this.info)});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const t=this.editor.getSelectionRotation();this.editor.updateInstanceState({cursor:{type:Da[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")}}v(dI,"id","pointing_rotate_handle");class hI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"onEnter",t=>{this.info=t});v(this,"onPointerUp",t=>{gp(this.editor),this.parent.transition("idle",t)});v(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.parent.transition("translating",t)}});v(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}});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()})}cancel(){this.parent.transition("idle")}}v(hI,"id","pointing_selection");class pI extends ie{constructor(){super(...arguments);v(this,"hitShape",{});v(this,"hitShapeForPointerUp",{});v(this,"didSelectOnEnter",!1);v(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]))});v(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 y=this.editor.getPointInShapeSpace(c,i);if(p.bounds.containsPoint(y,0)&&p.hitTestPoint(y)){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(y=>y.id===p)),d.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([d.id])}this.parent.transition("idle",t)});v(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.parent.transition("translating",t)}});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.cancel()});v(this,"onInterrupt",()=>{this.cancel()})}cancel(){this.parent.transition("idle")}}v(pI,"id","pointing_shape");class fI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"markId","");v(this,"didHoldCommand",!1);v(this,"creationCursorOffset",{x:0,y:0});v(this,"snapshot",{});v(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()});v(this,"onTick",()=>{Fv(this.editor)});v(this,"onPointerMove",()=>{this.updateShapes()});v(this,"onKeyDown",()=>{this.updateShapes()});v(this,"onKeyUp",()=>{this.updateShapes()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.snaps.clear()});v(this,"_createSnapshot",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=E.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=E.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:he(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 y=this.editor.getShape(p);if(y&&(l.set(y.id,this._createShapeSnapshot(y)),this.editor.isShapeOfType(y,"frame")))return!1})}});const u=![...l.values()].some(d=>!PP(d.pageRotation,r)||d.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});v(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),y=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,m=Wb(f,Math.PI);if(this.editor.snaps.clear(),(this.editor.user.getIsSnapMode()?!h:h)&&c%Ve===0){const{nudge:_}=this.editor.snaps.snapResize({dragDelta:E.Sub(p,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:Wb(f,c),isAspectRatioLocked:d,isResizingFromCenter:t});p.add(_)}const w=E.RotWith(t?i.center:i.getHandlePoint(m),i.point,c),x=E.Sub(p,w).rot(-c),C=E.Sub(y,w).rot(-c),P=E.DivV(x,C);Number.isFinite(P.x)||(P.x=1),Number.isFinite(P.y)||(P.y=1);const k=f==="top"||f==="bottom",I=f==="left"||f==="right";d?I?P.y=Math.abs(P.x):k?P.x=Math.abs(P.y):Math.abs(P.x)>Math.abs(P.y)?P.y=Math.abs(P.x)*(P.y<0?-1:1):P.x=Math.abs(P.y)*(P.x<0?-1:1):(k&&(P.x=1),I&&(P.y=1)),this.info.isCreating||this.updateCursor({dragHandle:f,isFlippedX:P.x<0,isFlippedY:P.y<0,rotation:c});for(const _ of s.keys()){const $=s.get(_);this.editor.resizeShape(_,P,{initialShape:$.shape,initialBounds:$.bounds,initialPageTransform:$.pageTransform,dragHandle:f,mode:l.length===1&&_===l[0]?"resize_bounds":"scale_shape",scaleOrigin:w,scaleAxisRotation:c})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:_,children:$}of o){if(!$.length)continue;const T=s.get(_).shape,R=this.editor.getShape(_);if(!(T&&R))continue;const L=R.x-T.x,N=R.y-T.y,D=new E(L,N).rot(-T.rotation);if(D.x!==0||D.y!==0)for(const z of $)this.editor.updateShape({id:z.id,type:z.type,x:z.x-D.x,y:z.y-D.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:_}of o)if(_.length)for(const $ of _)this.editor.updateShape({id:$.id,type:$.type,x:$.x,y:$.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(t){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}}v(fI,"id","resizing");const im=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function Wb(e,n){n=n%Ae;const t=Math.round(n/(Te/4)),r=im.indexOf(e);return im[(r+t)%im.length]}const Gb=Math.PI/180;class gI extends ie{constructor(){super(...arguments);v(this,"snapshot",{});v(this,"info",{});v(this,"markId","");v(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=dE({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r,this.handleStart()});v(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});v(this,"onPointerMove",()=>{this.update()});v(this,"onKeyDown",()=>{this.update()});v(this,"onKeyUp",()=>{this.update()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(this,"update",()=>{const t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Gd({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.updateInstanceState({cursor:{type:Da[this.info.handle],rotation:t+this.snapshot.initialSelectionRotation}})});v(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});v(this,"complete",()=>{Gd({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});Gd({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.updateInstanceState({cursor:{type:Da[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=Qh(d,24);else if(t&&(d=Math.round(d/Gb)*Gb,this.editor.getInstanceState().isCoarsePointer)){const h=Qh(d,4),p=Jl(d,h);Math.abs(p)<p4(5)&&(d=h)}return d-l}}v(gI,"id","rotating");class mI extends ie{constructor(){super(...arguments);v(this,"hits",new Set);v(this,"size",0);v(this,"scribbleId","id");v(this,"initialSelectedShapeIds",new Set);v(this,"newlySelectedShapeIds",new Set);v(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})})});v(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});v(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});v(this,"onPointerUp",()=>{this.complete()});v(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});v(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});v(this,"onCancel",()=>{this.cancel()});v(this,"onComplete",()=>{this.complete()});v(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,y,f;for(let m=0,S=d.length;m<S;m++)if(h=d[m],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 w=this.editor.getPointInShapeSpace(h,i);if(p.bounds.containsPoint(w))continue}if(y=this.editor.getPointInShapeSpace(h,a),f=this.editor.getPointInShapeSpace(h,l),p.hitTestLineSegment(y,f,Or/r)){const w=this.editor.getOutermostSelectableShape(h),x=this.editor.getShapeMask(w.id);if(x&&rE(a,l,x)!==null&&!eo(l,x))continue;c.add(w.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")}}v(mI,"id","scribble_brushing");const Yb=100;class zV{constructor(n){v(this,"prevDroppingShapeId",null);v(this,"droppingNodeTimer",null);v(this,"first",!0);v(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,Yb*10,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearInterval(this.droppingNodeTimer),this.setDragTimer(n,Yb,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=he(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 yI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"selectionSnapshot",{});v(this,"snapshot",{});v(this,"markId","");v(this,"isCloning",!1);v(this,"isCreating",!1);v(this,"onCreate",()=>{});v(this,"dragAndDropManager",new zV(this.editor));v(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=Xb(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});v(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()});v(this,"onTick",()=>{this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),Fv(this.editor)});v(this,"onPointerMove",()=>{this.updateShapes()});v(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});v(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onComplete",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()});v(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=Xb(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,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),FV({editor:this.editor,shapeSnapshots:t.shapeSnapshots,averagePagePoint:t.averagePagePoint,initialSelectionPageBounds:t.initialPageBounds,initialSelectionSnapPoints:t.initialSnapPoints}),this.handleChange()}}v(yI,"id","translating");function Xb(e){const n=[],t=[],r=he(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=Mo.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:E.Average(t),movingShapes:n,shapeSnapshots:r,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:o}}function FV({editor:e,shapeSnapshots:n,averagePagePoint:t,initialSelectionPageBounds:r,initialSelectionSnapPoints:o}){const{inputs:s}=e,i=e.getInstanceState().isGridMode,a=e.getDocumentSettings().gridSize,l=E.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=E.Add(t,l);i&&!s.ctrlKey&&d.snapToGrid(a);const h=E.Sub(d,t);e.updateShapes(he(n.map(({shape:p,pagePoint:y,parentTransform:f})=>{const m=E.Add(y,h),S=f?te.applyToPoint(f,m):m;return{id:p.id,type:p.type,x:S.x,y:S.y}})),{squashing:!0})}class Ch extends ie{constructor(){super(...arguments);v(this,"onExit",()=>{this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}v(Ch,"id","select"),v(Ch,"initial","idle"),v(Ch,"children",()=>[bh,sI,DV,lI,pI,yI,eI,mI,cI,hI,oI,aI,fI,gI,dI,uI,iI]);class vI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"onEnter",t=>{this.info=t});v(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}v(vI,"id","idle");class SI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"onEnter",t=>{this.info=t});v(this,"onPointerUp",()=>{this.complete()});v(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});v(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)}}v(SI,"id","pointing");class wI extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"zoomBrush",new le);v(this,"onEnter",t=>{this.info=t,this.update()});v(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});v(this,"onPointerMove",()=>{this.update()});v(this,"onPointerUp",()=>{this.complete()});v(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:t,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(le.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)}}v(wI,"id","zoom_brushing");class Ph extends ie{constructor(){super(...arguments);v(this,"info",{});v(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.updateCursor()});v(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});v(this,"onKeyDown",()=>{this.updateCursor()});v(this,"onKeyUp",t=>{this.updateCursor(),t.code==="KeyZ"&&this.complete()});v(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})}}v(Ph,"id","zoom"),v(Ph,"initial","idle"),v(Ph,"children",()=>[vI,wI,SI]);const BV=[Sh,wh,xh,Ph,Ch];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 xI={exports:{}},Yn={},bI={exports:{}},CI={};/**
|
|
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,U){var V=H.length;H.push(U);e:for(;0<V;){var X=V-1>>>1,re=H[X];if(0<o(re,U))H[X]=U,H[V]=re,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 U=H[0],V=H.pop();if(V!==U){H[0]=V;e:for(var X=0,re=H.length,ge=re>>>1;X<ge;){var Ce=2*(X+1)-1,oe=H[Ce],Se=Ce+1,De=H[Se];if(0>o(oe,V))Se<re&&0>o(De,oe)?(H[X]=De,H[Se]=V,X=Se):(H[X]=oe,H[Ce]=V,X=Ce);else if(Se<re&&0>o(De,V))H[X]=De,H[Se]=V,X=Se;else break e}}return U}function o(H,U){var V=H.sortIndex-U.sortIndex;return V!==0?V:H.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,d=null,h=3,p=!1,y=!1,f=!1,m=typeof setTimeout=="function"?setTimeout:null,S=typeof clearTimeout=="function"?clearTimeout:null,w=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function x(H){for(var U=t(c);U!==null;){if(U.callback===null)r(c);else if(U.startTime<=H)r(c),U.sortIndex=U.expirationTime,n(l,U);else break;U=t(c)}}function C(H){if(f=!1,x(H),!y)if(t(l)!==null)y=!0,F(P);else{var U=t(c);U!==null&&W(C,U.startTime-H)}}function P(H,U){y=!1,f&&(f=!1,S(_),_=-1),p=!0;var V=h;try{for(x(U),d=t(l);d!==null&&(!(d.expirationTime>U)||H&&!R());){var X=d.callback;if(typeof X=="function"){d.callback=null,h=d.priorityLevel;var re=X(d.expirationTime<=U);U=e.unstable_now(),typeof re=="function"?d.callback=re:d===t(l)&&r(l),x(U)}else r(l);d=t(l)}if(d!==null)var ge=!0;else{var Ce=t(c);Ce!==null&&W(C,Ce.startTime-U),ge=!1}return ge}finally{d=null,h=V,p=!1}}var k=!1,I=null,_=-1,$=5,T=-1;function R(){return!(e.unstable_now()-T<$)}function L(){if(I!==null){var H=e.unstable_now();T=H;var U=!0;try{U=I(!0,H)}finally{U?N():(k=!1,I=null)}}else k=!1}var N;if(typeof w=="function")N=function(){w(L)};else if(typeof MessageChannel<"u"){var D=new MessageChannel,z=D.port2;D.port1.onmessage=L,N=function(){z.postMessage(null)}}else N=function(){m(L,0)};function F(H){I=H,k||(k=!0,N())}function W(H,U){_=m(function(){H(e.unstable_now())},U)}e.unstable_IdlePriority=5,e.unstable_ImmediatePriority=1,e.unstable_LowPriority=4,e.unstable_NormalPriority=3,e.unstable_Profiling=null,e.unstable_UserBlockingPriority=2,e.unstable_cancelCallback=function(H){H.callback=null},e.unstable_continueExecution=function(){y||p||(y=!0,F(P))},e.unstable_forceFrameRate=function(H){0>H||125<H?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<H?Math.floor(1e3/H):5},e.unstable_getCurrentPriorityLevel=function(){return h},e.unstable_getFirstCallbackNode=function(){return t(l)},e.unstable_next=function(H){switch(h){case 1:case 2:case 3:var U=3;break;default:U=h}var V=h;h=U;try{return H()}finally{h=V}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(H,U){switch(H){case 1:case 2:case 3:case 4:case 5:break;default:H=3}var V=h;h=H;try{return U()}finally{h=V}},e.unstable_scheduleCallback=function(H,U,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 re=-1;break;case 2:re=250;break;case 5:re=1073741823;break;case 4:re=1e4;break;default:re=5e3}return re=V+re,H={id:u++,callback:U,priorityLevel:H,startTime:V,expirationTime:re,sortIndex:-1},V>X?(H.sortIndex=V,n(c,H),t(l)===null&&H===t(c)&&(f?(S(_),_=-1):f=!0,W(C,V-X))):(H.sortIndex=re,n(l,H),y||p||(y=!0,F(P))),H},e.unstable_shouldYield=R,e.unstable_wrapCallback=function(H){var U=h;return function(){var V=h;h=U;try{return H.apply(this,arguments)}finally{h=V}}}})(CI);bI.exports=CI;var UV=bI.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 PI=b,Wn=UV;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 EI=new Set,_c={};function ki(e,n){ja(e,n),ja(e+"Capture",n)}function ja(e,n){for(_c[e]=n,e=0;e<n.length;e++)EI.add(n[e])}var Ao=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),Yy=Object.prototype.hasOwnProperty,HV=/^[: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]*$/,qb={},Zb={};function VV(e){return Yy.call(Zb,e)?!0:Yy.call(qb,e)?!1:HV.test(e)?Zb[e]=!0:(qb[e]=!0,!1)}function KV(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 WV(e,n,t,r){if(n===null||typeof n>"u"||KV(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 fn(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 Lt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Lt[e]=new fn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Lt[n]=new fn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Lt[e]=new fn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Lt[e]=new fn(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){Lt[e]=new fn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Lt[e]=new fn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Lt[e]=new fn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Lt[e]=new fn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Lt[e]=new fn(e,5,!1,e.toLowerCase(),null,!1,!1)});var gS=/[\-:]([a-z])/g;function mS(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(gS,mS);Lt[n]=new fn(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(gS,mS);Lt[n]=new fn(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(gS,mS);Lt[n]=new fn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Lt[e]=new fn(e,1,!1,e.toLowerCase(),null,!1,!1)});Lt.xlinkHref=new fn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Lt[e]=new fn(e,1,!1,e.toLowerCase(),null,!0,!0)});function yS(e,n,t,r){var o=Lt.hasOwnProperty(n)?Lt[n]:null;(o!==null?o.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(WV(n,t,o,r)&&(t=null),r||o===null?VV(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 Ho=PI.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,dd=Symbol.for("react.element"),ia=Symbol.for("react.portal"),aa=Symbol.for("react.fragment"),vS=Symbol.for("react.strict_mode"),Xy=Symbol.for("react.profiler"),kI=Symbol.for("react.provider"),II=Symbol.for("react.context"),SS=Symbol.for("react.forward_ref"),qy=Symbol.for("react.suspense"),Zy=Symbol.for("react.suspense_list"),wS=Symbol.for("react.memo"),Jo=Symbol.for("react.lazy"),_I=Symbol.for("react.offscreen"),Qb=Symbol.iterator;function _l(e){return e===null||typeof e!="object"?null:(e=Qb&&e[Qb]||e["@@iterator"],typeof e=="function"?e:null)}var lt=Object.assign,am;function Gl(e){if(am===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);am=n&&n[1]||""}return`
|
|
179
|
+
`+am+e}var lm=!1;function cm(e,n){if(!e||lm)return"";lm=!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{lm=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?Gl(e):""}function GV(e){switch(e.tag){case 5:return Gl(e.type);case 16:return Gl("Lazy");case 13:return Gl("Suspense");case 19:return Gl("SuspenseList");case 0:case 2:case 15:return e=cm(e.type,!1),e;case 11:return e=cm(e.type.render,!1),e;case 1:return e=cm(e.type,!0),e;default:return""}}function Qy(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 aa:return"Fragment";case ia:return"Portal";case Xy:return"Profiler";case vS:return"StrictMode";case qy:return"Suspense";case Zy:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case II:return(e.displayName||"Context")+".Consumer";case kI:return(e._context.displayName||"Context")+".Provider";case SS:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case wS:return n=e.displayName||null,n!==null?n:Qy(e.type)||"Memo";case Jo:n=e._payload,e=e._init;try{return Qy(e(n))}catch{}}return null}function YV(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 Qy(n);case 8:return n===vS?"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 Cs(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function TI(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function XV(e){var n=TI(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 hd(e){e._valueTracker||(e._valueTracker=XV(e))}function $I(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=TI(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function mp(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 Jy(e,n){var t=n.checked;return lt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function Jb(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Cs(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 MI(e,n){n=n.checked,n!=null&&yS(e,"checked",n,!1)}function e0(e,n){MI(e,n);var t=Cs(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")?t0(e,n.type,t):n.hasOwnProperty("defaultValue")&&t0(e,n.type,Cs(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function e2(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 t0(e,n,t){(n!=="number"||mp(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var Yl=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=""+Cs(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 n0(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return lt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function t2(e,n){var t=n.value;if(t==null){if(t=n.children,n=n.defaultValue,t!=null){if(n!=null)throw Error(q(92));if(Yl(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Cs(t)}}function AI(e,n){var t=Cs(n.value),r=Cs(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 n2(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function OI(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 r0(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?OI(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var pd,RI=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(pd=pd||document.createElement("div"),pd.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=pd.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Tc(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var oc={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},qV=["Webkit","ms","Moz","O"];Object.keys(oc).forEach(function(e){qV.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),oc[n]=oc[e]})});function DI(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||oc.hasOwnProperty(e)&&oc[e]?(""+n).trim():n+"px"}function jI(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=DI(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var ZV=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 o0(e,n){if(n){if(ZV[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 s0(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 i0=null;function xS(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var a0=null,Pa=null,Ea=null;function r2(e){if(e=Cu(e)){if(typeof a0!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Sf(n),a0(e.stateNode,e.type,n))}}function LI(e){Pa?Ea?Ea.push(e):Ea=[e]:Pa=e}function NI(){if(Pa){var e=Pa,n=Ea;if(Ea=Pa=null,r2(e),n)for(e=0;e<n.length;e++)r2(n[e])}}function zI(e,n){return e(n)}function FI(){}var um=!1;function BI(e,n,t){if(um)return e(n,t);um=!0;try{return zI(e,n,t)}finally{um=!1,(Pa!==null||Ea!==null)&&(FI(),NI())}}function $c(e,n){var t=e.stateNode;if(t===null)return null;var r=Sf(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 l0=!1;if(Ao)try{var Tl={};Object.defineProperty(Tl,"passive",{get:function(){l0=!0}}),window.addEventListener("test",Tl,Tl),window.removeEventListener("test",Tl,Tl)}catch{l0=!1}function QV(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 sc=!1,yp=null,vp=!1,c0=null,JV={onError:function(e){sc=!0,yp=e}};function eK(e,n,t,r,o,s,i,a,l){sc=!1,yp=null,QV.apply(JV,arguments)}function tK(e,n,t,r,o,s,i,a,l){if(eK.apply(this,arguments),sc){if(sc){var c=yp;sc=!1,yp=null}else throw Error(q(198));vp||(vp=!0,c0=c)}}function Ii(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 UI(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 o2(e){if(Ii(e)!==e)throw Error(q(188))}function nK(e){var n=e.alternate;if(!n){if(n=Ii(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 o2(o),e;if(s===r)return o2(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 HI(e){return e=nK(e),e!==null?VI(e):null}function VI(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=VI(e);if(n!==null)return n;e=e.sibling}return null}var KI=Wn.unstable_scheduleCallback,s2=Wn.unstable_cancelCallback,rK=Wn.unstable_shouldYield,oK=Wn.unstable_requestPaint,ft=Wn.unstable_now,sK=Wn.unstable_getCurrentPriorityLevel,bS=Wn.unstable_ImmediatePriority,WI=Wn.unstable_UserBlockingPriority,Sp=Wn.unstable_NormalPriority,iK=Wn.unstable_LowPriority,GI=Wn.unstable_IdlePriority,gf=null,Xr=null;function aK(e){if(Xr&&typeof Xr.onCommitFiberRoot=="function")try{Xr.onCommitFiberRoot(gf,e,void 0,(e.current.flags&128)===128)}catch{}}var $r=Math.clz32?Math.clz32:uK,lK=Math.log,cK=Math.LN2;function uK(e){return e>>>=0,e===0?32:31-(lK(e)/cK|0)|0}var fd=64,gd=4194304;function Xl(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 wp(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=Xl(a):(s&=i,s!==0&&(r=Xl(s)))}else i=t&~o,i!==0?r=Xl(i):s!==0&&(r=Xl(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 dK(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 hK(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]=dK(a,n)):l<=n&&(e.expiredLanes|=a),s&=~a}}function u0(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function YI(){var e=fd;return fd<<=1,!(fd&4194240)&&(fd=64),e}function dm(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function xu(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 CS(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 Oe=0;function XI(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var qI,PS,ZI,QI,JI,d0=!1,md=[],ps=null,fs=null,gs=null,Mc=new Map,Ac=new Map,ns=[],fK="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 i2(e,n){switch(e){case"focusin":case"focusout":ps=null;break;case"dragenter":case"dragleave":fs=null;break;case"mouseover":case"mouseout":gs=null;break;case"pointerover":case"pointerout":Mc.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":Ac.delete(n.pointerId)}}function $l(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=Cu(n),n!==null&&PS(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function gK(e,n,t,r,o){switch(n){case"focusin":return ps=$l(ps,e,n,t,r,o),!0;case"dragenter":return fs=$l(fs,e,n,t,r,o),!0;case"mouseover":return gs=$l(gs,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return Mc.set(s,$l(Mc.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,Ac.set(s,$l(Ac.get(s)||null,e,n,t,r,o)),!0}return!1}function e_(e){var n=Js(e.target);if(n!==null){var t=Ii(n);if(t!==null){if(n=t.tag,n===13){if(n=UI(t),n!==null){e.blockedOn=n,JI(e.priority,function(){ZI(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 Eh(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=h0(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);i0=r,t.target.dispatchEvent(r),i0=null}else return n=Cu(t),n!==null&&PS(n),e.blockedOn=t,!1;n.shift()}return!0}function a2(e,n,t){Eh(e)&&t.delete(n)}function mK(){d0=!1,ps!==null&&Eh(ps)&&(ps=null),fs!==null&&Eh(fs)&&(fs=null),gs!==null&&Eh(gs)&&(gs=null),Mc.forEach(a2),Ac.forEach(a2)}function Ml(e,n){e.blockedOn===n&&(e.blockedOn=null,d0||(d0=!0,Wn.unstable_scheduleCallback(Wn.unstable_NormalPriority,mK)))}function Oc(e){function n(o){return Ml(o,e)}if(0<md.length){Ml(md[0],e);for(var t=1;t<md.length;t++){var r=md[t];r.blockedOn===e&&(r.blockedOn=null)}}for(ps!==null&&Ml(ps,e),fs!==null&&Ml(fs,e),gs!==null&&Ml(gs,e),Mc.forEach(n),Ac.forEach(n),t=0;t<ns.length;t++)r=ns[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<ns.length&&(t=ns[0],t.blockedOn===null);)e_(t),t.blockedOn===null&&ns.shift()}var ka=Ho.ReactCurrentBatchConfig,xp=!0;function yK(e,n,t,r){var o=Oe,s=ka.transition;ka.transition=null;try{Oe=1,ES(e,n,t,r)}finally{Oe=o,ka.transition=s}}function vK(e,n,t,r){var o=Oe,s=ka.transition;ka.transition=null;try{Oe=4,ES(e,n,t,r)}finally{Oe=o,ka.transition=s}}function ES(e,n,t,r){if(xp){var o=h0(e,n,t,r);if(o===null)xm(e,n,r,bp,t),i2(e,r);else if(gK(o,e,n,t,r))r.stopPropagation();else if(i2(e,r),n&4&&-1<fK.indexOf(e)){for(;o!==null;){var s=Cu(o);if(s!==null&&qI(s),s=h0(e,n,t,r),s===null&&xm(e,n,r,bp,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else xm(e,n,r,null,t)}}var bp=null;function h0(e,n,t,r){if(bp=null,e=xS(r),e=Js(e),e!==null)if(n=Ii(e),n===null)e=null;else if(t=n.tag,t===13){if(e=UI(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 bp=e,null}function t_(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(sK()){case bS:return 1;case WI:return 4;case Sp:case iK:return 16;case GI:return 536870912;default:return 16}default:return 16}}var ls=null,kS=null,kh=null;function n_(){if(kh)return kh;var e,n=kS,t=n.length,r,o="value"in ls?ls.value:ls.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 kh=o.slice(e,1<r?1-r:void 0)}function Ih(e){var n=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&n===13&&(e=13)):e=n,e===10&&(e=13),32<=e||e===13?e:0}function yd(){return!0}function l2(){return!1}function Xn(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)?yd:l2,this.isPropagationStopped=l2,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=yd)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=yd)},persist:function(){},isPersistent:yd}),n}var ol={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},IS=Xn(ol),bu=lt({},ol,{view:0,detail:0}),SK=Xn(bu),hm,pm,Al,mf=lt({},bu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:_S,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!==Al&&(Al&&e.type==="mousemove"?(hm=e.screenX-Al.screenX,pm=e.screenY-Al.screenY):pm=hm=0,Al=e),hm)},movementY:function(e){return"movementY"in e?e.movementY:pm}}),c2=Xn(mf),wK=lt({},mf,{dataTransfer:0}),xK=Xn(wK),bK=lt({},bu,{relatedTarget:0}),fm=Xn(bK),CK=lt({},ol,{animationName:0,elapsedTime:0,pseudoElement:0}),PK=Xn(CK),EK=lt({},ol,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),kK=Xn(EK),IK=lt({},ol,{data:0}),u2=Xn(IK),_K={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},TK={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"},$K={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function MK(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=$K[e])?!!n[e]:!1}function _S(){return MK}var AK=lt({},bu,{key:function(e){if(e.key){var n=_K[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Ih(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?TK[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:_S,charCode:function(e){return e.type==="keypress"?Ih(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Ih(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),OK=Xn(AK),RK=lt({},mf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),d2=Xn(RK),DK=lt({},bu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:_S}),jK=Xn(DK),LK=lt({},ol,{propertyName:0,elapsedTime:0,pseudoElement:0}),NK=Xn(LK),zK=lt({},mf,{deltaX:function(e){return"deltaX"in e?e.deltaX:"wheelDeltaX"in e?-e.wheelDeltaX:0},deltaY:function(e){return"deltaY"in e?e.deltaY:"wheelDeltaY"in e?-e.wheelDeltaY:"wheelDelta"in e?-e.wheelDelta:0},deltaZ:0,deltaMode:0}),FK=Xn(zK),BK=[9,13,27,32],TS=Ao&&"CompositionEvent"in window,ic=null;Ao&&"documentMode"in document&&(ic=document.documentMode);var UK=Ao&&"TextEvent"in window&&!ic,r_=Ao&&(!TS||ic&&8<ic&&11>=ic),h2=" ",p2=!1;function o_(e,n){switch(e){case"keyup":return BK.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function s_(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var la=!1;function HK(e,n){switch(e){case"compositionend":return s_(n);case"keypress":return n.which!==32?null:(p2=!0,h2);case"textInput":return e=n.data,e===h2&&p2?null:e;default:return null}}function VK(e,n){if(la)return e==="compositionend"||!TS&&o_(e,n)?(e=n_(),kh=kS=ls=null,la=!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 r_&&n.locale!=="ko"?null:n.data;default:return null}}var KK={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function f2(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!KK[e.type]:n==="textarea"}function i_(e,n,t,r){LI(r),n=Cp(n,"onChange"),0<n.length&&(t=new IS("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var ac=null,Rc=null;function WK(e){y_(e,0)}function yf(e){var n=da(e);if($I(n))return e}function GK(e,n){if(e==="change")return n}var a_=!1;if(Ao){var gm;if(Ao){var mm="oninput"in document;if(!mm){var g2=document.createElement("div");g2.setAttribute("oninput","return;"),mm=typeof g2.oninput=="function"}gm=mm}else gm=!1;a_=gm&&(!document.documentMode||9<document.documentMode)}function m2(){ac&&(ac.detachEvent("onpropertychange",l_),Rc=ac=null)}function l_(e){if(e.propertyName==="value"&&yf(Rc)){var n=[];i_(n,Rc,e,xS(e)),BI(WK,n)}}function YK(e,n,t){e==="focusin"?(m2(),ac=n,Rc=t,ac.attachEvent("onpropertychange",l_)):e==="focusout"&&m2()}function XK(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return yf(Rc)}function qK(e,n){if(e==="click")return yf(n)}function ZK(e,n){if(e==="input"||e==="change")return yf(n)}function QK(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Rr=typeof Object.is=="function"?Object.is:QK;function Dc(e,n){if(Rr(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(!Yy.call(n,o)||!Rr(e[o],n[o]))return!1}return!0}function y2(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function v2(e,n){var t=y2(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=y2(t)}}function c_(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?c_(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function u_(){for(var e=window,n=mp();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=mp(e.document)}return n}function $S(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 JK(e){var n=u_(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&c_(t.ownerDocument.documentElement,t)){if(r!==null&&$S(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=v2(t,s);var i=v2(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 eW=Ao&&"documentMode"in document&&11>=document.documentMode,ca=null,p0=null,lc=null,f0=!1;function S2(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;f0||ca==null||ca!==mp(r)||(r=ca,"selectionStart"in r&&$S(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),lc&&Dc(lc,r)||(lc=r,r=Cp(p0,"onSelect"),0<r.length&&(n=new IS("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=ca)))}function vd(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var ua={animationend:vd("Animation","AnimationEnd"),animationiteration:vd("Animation","AnimationIteration"),animationstart:vd("Animation","AnimationStart"),transitionend:vd("Transition","TransitionEnd")},ym={},d_={};Ao&&(d_=document.createElement("div").style,"AnimationEvent"in window||(delete ua.animationend.animation,delete ua.animationiteration.animation,delete ua.animationstart.animation),"TransitionEvent"in window||delete ua.transitionend.transition);function vf(e){if(ym[e])return ym[e];if(!ua[e])return e;var n=ua[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in d_)return ym[e]=n[t];return e}var h_=vf("animationend"),p_=vf("animationiteration"),f_=vf("animationstart"),g_=vf("transitionend"),m_=new Map,w2="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 Ds(e,n){m_.set(e,n),ki(n,[e])}for(var vm=0;vm<w2.length;vm++){var Sm=w2[vm],tW=Sm.toLowerCase(),nW=Sm[0].toUpperCase()+Sm.slice(1);Ds(tW,"on"+nW)}Ds(h_,"onAnimationEnd");Ds(p_,"onAnimationIteration");Ds(f_,"onAnimationStart");Ds("dblclick","onDoubleClick");Ds("focusin","onFocus");Ds("focusout","onBlur");Ds(g_,"onTransitionEnd");ja("onMouseEnter",["mouseout","mouseover"]);ja("onMouseLeave",["mouseout","mouseover"]);ja("onPointerEnter",["pointerout","pointerover"]);ja("onPointerLeave",["pointerout","pointerover"]);ki("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));ki("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));ki("onBeforeInput",["compositionend","keypress","textInput","paste"]);ki("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));ki("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));ki("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var ql="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(" "),rW=new Set("cancel close invalid load scroll toggle".split(" ").concat(ql));function x2(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,tK(r,n,void 0,e),e.currentTarget=null}function y_(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;x2(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;x2(o,a,c),s=l}}}if(vp)throw e=c0,vp=!1,c0=null,e}function Xe(e,n){var t=n[S0];t===void 0&&(t=n[S0]=new Set);var r=e+"__bubble";t.has(r)||(v_(n,e,2,!1),t.add(r))}function wm(e,n,t){var r=0;n&&(r|=4),v_(t,e,r,n)}var Sd="_reactListening"+Math.random().toString(36).slice(2);function jc(e){if(!e[Sd]){e[Sd]=!0,EI.forEach(function(t){t!=="selectionchange"&&(rW.has(t)||wm(t,!1,e),wm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[Sd]||(n[Sd]=!0,wm("selectionchange",!1,n))}}function v_(e,n,t,r){switch(t_(n)){case 1:var o=yK;break;case 4:o=vK;break;default:o=ES}t=o.bind(null,n,t,e),o=void 0,!l0||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 xm(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=Js(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}BI(function(){var c=s,u=xS(t),d=[];e:{var h=m_.get(e);if(h!==void 0){var p=IS,y=e;switch(e){case"keypress":if(Ih(t)===0)break e;case"keydown":case"keyup":p=OK;break;case"focusin":y="focus",p=fm;break;case"focusout":y="blur",p=fm;break;case"beforeblur":case"afterblur":p=fm;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=c2;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=xK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=jK;break;case h_:case p_:case f_:p=PK;break;case g_:p=NK;break;case"scroll":p=SK;break;case"wheel":p=FK;break;case"copy":case"cut":case"paste":p=kK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=d2}var f=(n&4)!==0,m=!f&&e==="scroll",S=f?h!==null?h+"Capture":null:h;f=[];for(var w=c,x;w!==null;){x=w;var C=x.stateNode;if(x.tag===5&&C!==null&&(x=C,S!==null&&(C=$c(w,S),C!=null&&f.push(Lc(w,C,x)))),m)break;w=w.return}0<f.length&&(h=new p(h,y,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!==i0&&(y=t.relatedTarget||t.fromElement)&&(Js(y)||y[Oo]))break e;if((p||h)&&(h=u.window===u?u:(h=u.ownerDocument)?h.defaultView||h.parentWindow:window,p?(y=t.relatedTarget||t.toElement,p=c,y=y?Js(y):null,y!==null&&(m=Ii(y),y!==m||y.tag!==5&&y.tag!==6)&&(y=null)):(p=null,y=c),p!==y)){if(f=c2,C="onMouseLeave",S="onMouseEnter",w="mouse",(e==="pointerout"||e==="pointerover")&&(f=d2,C="onPointerLeave",S="onPointerEnter",w="pointer"),m=p==null?h:da(p),x=y==null?h:da(y),h=new f(C,w+"leave",p,t,u),h.target=m,h.relatedTarget=x,C=null,Js(u)===c&&(f=new f(S,w+"enter",y,t,u),f.target=x,f.relatedTarget=m,C=f),m=C,p&&y)t:{for(f=p,S=y,w=0,x=f;x;x=Wi(x))w++;for(x=0,C=S;C;C=Wi(C))x++;for(;0<w-x;)f=Wi(f),w--;for(;0<x-w;)S=Wi(S),x--;for(;w--;){if(f===S||S!==null&&f===S.alternate)break t;f=Wi(f),S=Wi(S)}f=null}else f=null;p!==null&&b2(d,h,p,f,!1),y!==null&&m!==null&&b2(d,m,y,f,!0)}}e:{if(h=c?da(c):window,p=h.nodeName&&h.nodeName.toLowerCase(),p==="select"||p==="input"&&h.type==="file")var P=GK;else if(f2(h))if(a_)P=ZK;else{P=XK;var k=YK}else(p=h.nodeName)&&p.toLowerCase()==="input"&&(h.type==="checkbox"||h.type==="radio")&&(P=qK);if(P&&(P=P(e,c))){i_(d,P,t,u);break e}k&&k(e,h,c),e==="focusout"&&(k=h._wrapperState)&&k.controlled&&h.type==="number"&&t0(h,"number",h.value)}switch(k=c?da(c):window,e){case"focusin":(f2(k)||k.contentEditable==="true")&&(ca=k,p0=c,lc=null);break;case"focusout":lc=p0=ca=null;break;case"mousedown":f0=!0;break;case"contextmenu":case"mouseup":case"dragend":f0=!1,S2(d,t,u);break;case"selectionchange":if(eW)break;case"keydown":case"keyup":S2(d,t,u)}var I;if(TS)e:{switch(e){case"compositionstart":var _="onCompositionStart";break e;case"compositionend":_="onCompositionEnd";break e;case"compositionupdate":_="onCompositionUpdate";break e}_=void 0}else la?o_(e,t)&&(_="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(_="onCompositionStart");_&&(r_&&t.locale!=="ko"&&(la||_!=="onCompositionStart"?_==="onCompositionEnd"&&la&&(I=n_()):(ls=u,kS="value"in ls?ls.value:ls.textContent,la=!0)),k=Cp(c,_),0<k.length&&(_=new u2(_,e,null,t,u),d.push({event:_,listeners:k}),I?_.data=I:(I=s_(t),I!==null&&(_.data=I)))),(I=UK?HK(e,t):VK(e,t))&&(c=Cp(c,"onBeforeInput"),0<c.length&&(u=new u2("onBeforeInput","beforeinput",null,t,u),d.push({event:u,listeners:c}),u.data=I))}y_(d,n)})}function Lc(e,n,t){return{instance:e,listener:n,currentTarget:t}}function Cp(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=$c(e,t),s!=null&&r.unshift(Lc(e,s,o)),s=$c(e,n),s!=null&&r.push(Lc(e,s,o))),e=e.return}return r}function Wi(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function b2(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=$c(t,s),l!=null&&i.unshift(Lc(t,l,a))):o||(l=$c(t,s),l!=null&&i.push(Lc(t,l,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var oW=/\r\n?/g,sW=/\u0000|\uFFFD/g;function C2(e){return(typeof e=="string"?e:""+e).replace(oW,`
|
|
183
|
+
`).replace(sW,"")}function wd(e,n,t){if(n=C2(n),C2(e)!==n&&t)throw Error(q(425))}function Pp(){}var g0=null,m0=null;function y0(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 v0=typeof setTimeout=="function"?setTimeout:void 0,iW=typeof clearTimeout=="function"?clearTimeout:void 0,P2=typeof Promise=="function"?Promise:void 0,aW=typeof queueMicrotask=="function"?queueMicrotask:typeof P2<"u"?function(e){return P2.resolve(null).then(e).catch(lW)}:v0;function lW(e){setTimeout(function(){throw e})}function bm(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),Oc(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);Oc(n)}function ms(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 E2(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 sl=Math.random().toString(36).slice(2),Wr="__reactFiber$"+sl,Nc="__reactProps$"+sl,Oo="__reactContainer$"+sl,S0="__reactEvents$"+sl,cW="__reactListeners$"+sl,uW="__reactHandles$"+sl;function Js(e){var n=e[Wr];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Oo]||t[Wr]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=E2(e);e!==null;){if(t=e[Wr])return t;e=E2(e)}return n}e=t,t=e.parentNode}return null}function Cu(e){return e=e[Wr]||e[Oo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function da(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Sf(e){return e[Nc]||null}var w0=[],ha=-1;function js(e){return{current:e}}function Ze(e){0>ha||(e.current=w0[ha],w0[ha]=null,ha--)}function Ke(e,n){ha++,w0[ha]=e.current,e.current=n}var Ps={},Qt=js(Ps),xn=js(!1),di=Ps;function La(e,n){var t=e.type.contextTypes;if(!t)return Ps;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 bn(e){return e=e.childContextTypes,e!=null}function Ep(){Ze(xn),Ze(Qt)}function k2(e,n,t){if(Qt.current!==Ps)throw Error(q(168));Ke(Qt,n),Ke(xn,t)}function S_(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,YV(e)||"Unknown",o));return lt({},t,r)}function kp(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ps,di=Qt.current,Ke(Qt,e),Ke(xn,xn.current),!0}function I2(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=S_(e,n,di),r.__reactInternalMemoizedMergedChildContext=e,Ze(xn),Ze(Qt),Ke(Qt,e)):Ze(xn),Ke(xn,t)}var So=null,wf=!1,Cm=!1;function w_(e){So===null?So=[e]:So.push(e)}function dW(e){wf=!0,w_(e)}function Ls(){if(!Cm&&So!==null){Cm=!0;var e=0,n=Oe;try{var t=So;for(Oe=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}So=null,wf=!1}catch(o){throw So!==null&&(So=So.slice(e+1)),KI(bS,Ls),o}finally{Oe=n,Cm=!1}}return null}var pa=[],fa=0,Ip=null,_p=0,sr=[],ir=0,hi=null,bo=1,Co="";function Ys(e,n){pa[fa++]=_p,pa[fa++]=Ip,Ip=e,_p=n}function x_(e,n,t){sr[ir++]=bo,sr[ir++]=Co,sr[ir++]=hi,hi=e;var r=bo;e=Co;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,bo=1<<32-$r(n)+o|t<<o|r,Co=s+e}else bo=1<<s|t<<o|r,Co=e}function MS(e){e.return!==null&&(Ys(e,1),x_(e,1,0))}function AS(e){for(;e===Ip;)Ip=pa[--fa],pa[fa]=null,_p=pa[--fa],pa[fa]=null;for(;e===hi;)hi=sr[--ir],sr[ir]=null,Co=sr[--ir],sr[ir]=null,bo=sr[--ir],sr[ir]=null}var Un=null,Fn=null,Je=!1,br=null;function b_(e,n){var t=ar(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 _2(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,Un=e,Fn=ms(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,Un=e,Fn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=hi!==null?{id:bo,overflow:Co}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=ar(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,Un=e,Fn=null,!0):!1;default:return!1}}function x0(e){return(e.mode&1)!==0&&(e.flags&128)===0}function b0(e){if(Je){var n=Fn;if(n){var t=n;if(!_2(e,n)){if(x0(e))throw Error(q(418));n=ms(t.nextSibling);var r=Un;n&&_2(e,n)?b_(r,t):(e.flags=e.flags&-4097|2,Je=!1,Un=e)}}else{if(x0(e))throw Error(q(418));e.flags=e.flags&-4097|2,Je=!1,Un=e}}}function T2(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Un=e}function xd(e){if(e!==Un)return!1;if(!Je)return T2(e),Je=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!y0(e.type,e.memoizedProps)),n&&(n=Fn)){if(x0(e))throw C_(),Error(q(418));for(;n;)b_(e,n),n=ms(n.nextSibling)}if(T2(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){Fn=ms(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}Fn=null}}else Fn=Un?ms(e.stateNode.nextSibling):null;return!0}function C_(){for(var e=Fn;e;)e=ms(e.nextSibling)}function Na(){Fn=Un=null,Je=!1}function OS(e){br===null?br=[e]:br.push(e)}var hW=Ho.ReactCurrentBatchConfig;function yr(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 Tp=js(null),$p=null,ga=null,RS=null;function DS(){RS=ga=$p=null}function jS(e){var n=Tp.current;Ze(Tp),e._currentValue=n}function C0(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 Ia(e,n){$p=e,RS=ga=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(wn=!0),e.firstContext=null)}function ur(e){var n=e._currentValue;if(RS!==e)if(e={context:e,memoizedValue:n,next:null},ga===null){if($p===null)throw Error(q(308));ga=e,$p.dependencies={lanes:0,firstContext:e}}else ga=ga.next=e;return n}var ei=null;function LS(e){ei===null?ei=[e]:ei.push(e)}function P_(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,LS(n)):(t.next=o.next,o.next=t),n.interleaved=t,Ro(e,r)}function Ro(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 es=!1;function NS(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function E_(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 ys(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,ke&2){var o=r.pending;return o===null?n.next=n:(n.next=o.next,o.next=n),r.pending=n,Ro(e,t)}return o=r.interleaved,o===null?(n.next=n,LS(r)):(n.next=o.next,o.next=n),r.interleaved=n,Ro(e,t)}function _h(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,CS(e,t)}}function $2(e,n){var t=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,t===r)){var o=null,s=null;if(t=t.firstBaseUpdate,t!==null){do{var i={eventTime:t.eventTime,lane:t.lane,tag:t.tag,payload:t.payload,callback:t.callback,next:null};s===null?o=s=i:s=s.next=i,t=t.next}while(t!==null);s===null?o=s=n:s=s.next=n}else o=s=n;t={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:s,shared:r.shared,effects:r.effects},e.updateQueue=t;return}e=t.lastBaseUpdate,e===null?t.firstBaseUpdate=n:e.next=n,t.lastBaseUpdate=n}function Mp(e,n,t,r){var o=e.updateQueue;es=!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 y=e,f=a;switch(h=n,p=t,f.tag){case 1:if(y=f.payload,typeof y=="function"){d=y.call(p,d,h);break e}d=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=f.payload,h=typeof y=="function"?y.call(p,d,h):y,h==null)break e;d=lt({},d,h);break e;case 2:es=!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);fi|=i,e.lanes=i,e.memoizedState=d}}function M2(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 k_=new PI.Component().refs;function P0(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 xf={isMounted:function(e){return(e=e._reactInternals)?Ii(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=cn(),o=Ss(e),s=_o(r,o);s.payload=n,t!=null&&(s.callback=t),n=ys(e,s,o),n!==null&&(Mr(n,e,o,r),_h(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=cn(),o=Ss(e),s=_o(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=ys(e,s,o),n!==null&&(Mr(n,e,o,r),_h(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=cn(),r=Ss(e),o=_o(t,r);o.tag=2,n!=null&&(o.callback=n),n=ys(e,o,r),n!==null&&(Mr(n,e,r,t),_h(n,e,r))}};function A2(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?!Dc(t,r)||!Dc(o,s):!0}function I_(e,n,t){var r=!1,o=Ps,s=n.contextType;return typeof s=="object"&&s!==null?s=ur(s):(o=bn(n)?di:Qt.current,r=n.contextTypes,s=(r=r!=null)?La(e,o):Ps),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=xf,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function O2(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&&xf.enqueueReplaceState(n,n.state,null)}function E0(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs=k_,NS(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=ur(s):(s=bn(n)?di:Qt.current,o.context=La(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(P0(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&&xf.enqueueReplaceState(o,o.state,null),Mp(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function Ol(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===k_&&(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 bd(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function R2(e){var n=e._init;return n(e._payload)}function __(e){function n(S,w){if(e){var x=S.deletions;x===null?(S.deletions=[w],S.flags|=16):x.push(w)}}function t(S,w){if(!e)return null;for(;w!==null;)n(S,w),w=w.sibling;return null}function r(S,w){for(S=new Map;w!==null;)w.key!==null?S.set(w.key,w):S.set(w.index,w),w=w.sibling;return S}function o(S,w){return S=ws(S,w),S.index=0,S.sibling=null,S}function s(S,w,x){return S.index=x,e?(x=S.alternate,x!==null?(x=x.index,x<w?(S.flags|=2,w):x):(S.flags|=2,w)):(S.flags|=1048576,w)}function i(S){return e&&S.alternate===null&&(S.flags|=2),S}function a(S,w,x,C){return w===null||w.tag!==6?(w=$m(x,S.mode,C),w.return=S,w):(w=o(w,x),w.return=S,w)}function l(S,w,x,C){var P=x.type;return P===aa?u(S,w,x.props.children,C,x.key):w!==null&&(w.elementType===P||typeof P=="object"&&P!==null&&P.$$typeof===Jo&&R2(P)===w.type)?(C=o(w,x.props),C.ref=Ol(S,w,x),C.return=S,C):(C=Rh(x.type,x.key,x.props,null,S.mode,C),C.ref=Ol(S,w,x),C.return=S,C)}function c(S,w,x,C){return w===null||w.tag!==4||w.stateNode.containerInfo!==x.containerInfo||w.stateNode.implementation!==x.implementation?(w=Mm(x,S.mode,C),w.return=S,w):(w=o(w,x.children||[]),w.return=S,w)}function u(S,w,x,C,P){return w===null||w.tag!==7?(w=ai(x,S.mode,C,P),w.return=S,w):(w=o(w,x),w.return=S,w)}function d(S,w,x){if(typeof w=="string"&&w!==""||typeof w=="number")return w=$m(""+w,S.mode,x),w.return=S,w;if(typeof w=="object"&&w!==null){switch(w.$$typeof){case dd:return x=Rh(w.type,w.key,w.props,null,S.mode,x),x.ref=Ol(S,null,w),x.return=S,x;case ia:return w=Mm(w,S.mode,x),w.return=S,w;case Jo:var C=w._init;return d(S,C(w._payload),x)}if(Yl(w)||_l(w))return w=ai(w,S.mode,x,null),w.return=S,w;bd(S,w)}return null}function h(S,w,x,C){var P=w!==null?w.key:null;if(typeof x=="string"&&x!==""||typeof x=="number")return P!==null?null:a(S,w,""+x,C);if(typeof x=="object"&&x!==null){switch(x.$$typeof){case dd:return x.key===P?l(S,w,x,C):null;case ia:return x.key===P?c(S,w,x,C):null;case Jo:return P=x._init,h(S,w,P(x._payload),C)}if(Yl(x)||_l(x))return P!==null?null:u(S,w,x,C,null);bd(S,x)}return null}function p(S,w,x,C,P){if(typeof C=="string"&&C!==""||typeof C=="number")return S=S.get(x)||null,a(w,S,""+C,P);if(typeof C=="object"&&C!==null){switch(C.$$typeof){case dd:return S=S.get(C.key===null?x:C.key)||null,l(w,S,C,P);case ia:return S=S.get(C.key===null?x:C.key)||null,c(w,S,C,P);case Jo:var k=C._init;return p(S,w,x,k(C._payload),P)}if(Yl(C)||_l(C))return S=S.get(x)||null,u(w,S,C,P,null);bd(w,C)}return null}function y(S,w,x,C){for(var P=null,k=null,I=w,_=w=0,$=null;I!==null&&_<x.length;_++){I.index>_?($=I,I=null):$=I.sibling;var T=h(S,I,x[_],C);if(T===null){I===null&&(I=$);break}e&&I&&T.alternate===null&&n(S,I),w=s(T,w,_),k===null?P=T:k.sibling=T,k=T,I=$}if(_===x.length)return t(S,I),Je&&Ys(S,_),P;if(I===null){for(;_<x.length;_++)I=d(S,x[_],C),I!==null&&(w=s(I,w,_),k===null?P=I:k.sibling=I,k=I);return Je&&Ys(S,_),P}for(I=r(S,I);_<x.length;_++)$=p(I,S,_,x[_],C),$!==null&&(e&&$.alternate!==null&&I.delete($.key===null?_:$.key),w=s($,w,_),k===null?P=$:k.sibling=$,k=$);return e&&I.forEach(function(R){return n(S,R)}),Je&&Ys(S,_),P}function f(S,w,x,C){var P=_l(x);if(typeof P!="function")throw Error(q(150));if(x=P.call(x),x==null)throw Error(q(151));for(var k=P=null,I=w,_=w=0,$=null,T=x.next();I!==null&&!T.done;_++,T=x.next()){I.index>_?($=I,I=null):$=I.sibling;var R=h(S,I,T.value,C);if(R===null){I===null&&(I=$);break}e&&I&&R.alternate===null&&n(S,I),w=s(R,w,_),k===null?P=R:k.sibling=R,k=R,I=$}if(T.done)return t(S,I),Je&&Ys(S,_),P;if(I===null){for(;!T.done;_++,T=x.next())T=d(S,T.value,C),T!==null&&(w=s(T,w,_),k===null?P=T:k.sibling=T,k=T);return Je&&Ys(S,_),P}for(I=r(S,I);!T.done;_++,T=x.next())T=p(I,S,_,T.value,C),T!==null&&(e&&T.alternate!==null&&I.delete(T.key===null?_:T.key),w=s(T,w,_),k===null?P=T:k.sibling=T,k=T);return e&&I.forEach(function(L){return n(S,L)}),Je&&Ys(S,_),P}function m(S,w,x,C){if(typeof x=="object"&&x!==null&&x.type===aa&&x.key===null&&(x=x.props.children),typeof x=="object"&&x!==null){switch(x.$$typeof){case dd:e:{for(var P=x.key,k=w;k!==null;){if(k.key===P){if(P=x.type,P===aa){if(k.tag===7){t(S,k.sibling),w=o(k,x.props.children),w.return=S,S=w;break e}}else if(k.elementType===P||typeof P=="object"&&P!==null&&P.$$typeof===Jo&&R2(P)===k.type){t(S,k.sibling),w=o(k,x.props),w.ref=Ol(S,k,x),w.return=S,S=w;break e}t(S,k);break}else n(S,k);k=k.sibling}x.type===aa?(w=ai(x.props.children,S.mode,C,x.key),w.return=S,S=w):(C=Rh(x.type,x.key,x.props,null,S.mode,C),C.ref=Ol(S,w,x),C.return=S,S=C)}return i(S);case ia:e:{for(k=x.key;w!==null;){if(w.key===k)if(w.tag===4&&w.stateNode.containerInfo===x.containerInfo&&w.stateNode.implementation===x.implementation){t(S,w.sibling),w=o(w,x.children||[]),w.return=S,S=w;break e}else{t(S,w);break}else n(S,w);w=w.sibling}w=Mm(x,S.mode,C),w.return=S,S=w}return i(S);case Jo:return k=x._init,m(S,w,k(x._payload),C)}if(Yl(x))return y(S,w,x,C);if(_l(x))return f(S,w,x,C);bd(S,x)}return typeof x=="string"&&x!==""||typeof x=="number"?(x=""+x,w!==null&&w.tag===6?(t(S,w.sibling),w=o(w,x),w.return=S,S=w):(t(S,w),w=$m(x,S.mode,C),w.return=S,S=w),i(S)):t(S,w)}return m}var za=__(!0),T_=__(!1),Pu={},qr=js(Pu),zc=js(Pu),Fc=js(Pu);function ti(e){if(e===Pu)throw Error(q(174));return e}function zS(e,n){switch(Ke(Fc,n),Ke(zc,e),Ke(qr,Pu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:r0(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=r0(n,e)}Ze(qr),Ke(qr,n)}function Fa(){Ze(qr),Ze(zc),Ze(Fc)}function $_(e){ti(Fc.current);var n=ti(qr.current),t=r0(n,e.type);n!==t&&(Ke(zc,e),Ke(qr,t))}function FS(e){zc.current===e&&(Ze(qr),Ze(zc))}var ot=js(0);function Ap(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 Pm=[];function BS(){for(var e=0;e<Pm.length;e++)Pm[e]._workInProgressVersionPrimary=null;Pm.length=0}var Th=Ho.ReactCurrentDispatcher,Em=Ho.ReactCurrentBatchConfig,pi=0,at=null,yt=null,xt=null,Op=!1,cc=!1,Bc=0,pW=0;function zt(){throw Error(q(321))}function US(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Rr(e[t],n[t]))return!1;return!0}function HS(e,n,t,r,o,s){if(pi=s,at=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Th.current=e===null||e.memoizedState===null?yW:vW,e=t(r,o),cc){s=0;do{if(cc=!1,Bc=0,25<=s)throw Error(q(301));s+=1,xt=yt=null,n.updateQueue=null,Th.current=SW,e=t(r,o)}while(cc)}if(Th.current=Rp,n=yt!==null&&yt.next!==null,pi=0,xt=yt=at=null,Op=!1,n)throw Error(q(300));return e}function VS(){var e=Bc!==0;return Bc=0,e}function Ur(){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 dr(){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 Uc(e,n){return typeof n=="function"?n(e):n}function km(e){var n=dr(),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((pi&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,fi|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Rr(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,fi|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function Im(e){var n=dr(),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);Rr(s,n.memoizedState)||(wn=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function M_(){}function A_(e,n){var t=at,r=dr(),o=n(),s=!Rr(r.memoizedState,o);if(s&&(r.memoizedState=o,wn=!0),r=r.queue,KS(D_.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||xt!==null&&xt.memoizedState.tag&1){if(t.flags|=2048,Hc(9,R_.bind(null,t,r,o,n),void 0,null),Ct===null)throw Error(q(349));pi&30||O_(t,n,o)}return o}function O_(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 R_(e,n,t,r){n.value=t,n.getSnapshot=r,j_(n)&&L_(e)}function D_(e,n,t){return t(function(){j_(n)&&L_(e)})}function j_(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Rr(e,t)}catch{return!0}}function L_(e){var n=Ro(e,1);n!==null&&Mr(n,e,1,-1)}function D2(e){var n=Ur();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Uc,lastRenderedState:e},n.queue=e,e=e.dispatch=mW.bind(null,at,e),[n.memoizedState,e]}function Hc(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 N_(){return dr().memoizedState}function $h(e,n,t,r){var o=Ur();at.flags|=e,o.memoizedState=Hc(1|n,t,void 0,r===void 0?null:r)}function bf(e,n,t,r){var o=dr();r=r===void 0?null:r;var s=void 0;if(yt!==null){var i=yt.memoizedState;if(s=i.destroy,r!==null&&US(r,i.deps)){o.memoizedState=Hc(n,t,s,r);return}}at.flags|=e,o.memoizedState=Hc(1|n,t,s,r)}function j2(e,n){return $h(8390656,8,e,n)}function KS(e,n){return bf(2048,8,e,n)}function z_(e,n){return bf(4,2,e,n)}function F_(e,n){return bf(4,4,e,n)}function B_(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 U_(e,n,t){return t=t!=null?t.concat([e]):null,bf(4,4,B_.bind(null,n,e),t)}function WS(){}function H_(e,n){var t=dr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&US(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function V_(e,n){var t=dr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&US(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function K_(e,n,t){return pi&21?(Rr(t,n)||(t=YI(),at.lanes|=t,fi|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,wn=!0),e.memoizedState=t)}function fW(e,n){var t=Oe;Oe=t!==0&&4>t?t:4,e(!0);var r=Em.transition;Em.transition={};try{e(!1),n()}finally{Oe=t,Em.transition=r}}function W_(){return dr().memoizedState}function gW(e,n,t){var r=Ss(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},G_(e))Y_(n,t);else if(t=P_(e,n,t,r),t!==null){var o=cn();Mr(t,e,r,o),X_(t,n,r)}}function mW(e,n,t){var r=Ss(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(G_(e))Y_(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,Rr(a,i)){var l=n.interleaved;l===null?(o.next=o,LS(n)):(o.next=l.next,l.next=o),n.interleaved=o;return}}catch{}finally{}t=P_(e,n,o,r),t!==null&&(o=cn(),Mr(t,e,r,o),X_(t,n,r))}}function G_(e){var n=e.alternate;return e===at||n!==null&&n===at}function Y_(e,n){cc=Op=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function X_(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,CS(e,t)}}var Rp={readContext:ur,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},yW={readContext:ur,useCallback:function(e,n){return Ur().memoizedState=[e,n===void 0?null:n],e},useContext:ur,useEffect:j2,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,$h(4194308,4,B_.bind(null,n,e),t)},useLayoutEffect:function(e,n){return $h(4194308,4,e,n)},useInsertionEffect:function(e,n){return $h(4,2,e,n)},useMemo:function(e,n){var t=Ur();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=Ur();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=gW.bind(null,at,e),[r.memoizedState,e]},useRef:function(e){var n=Ur();return e={current:e},n.memoizedState=e},useState:D2,useDebugValue:WS,useDeferredValue:function(e){return Ur().memoizedState=e},useTransition:function(){var e=D2(!1),n=e[0];return e=fW.bind(null,e[1]),Ur().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=at,o=Ur();if(Je){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),Ct===null)throw Error(q(349));pi&30||O_(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,j2(D_.bind(null,r,s,e),[e]),r.flags|=2048,Hc(9,R_.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=Ur(),n=Ct.identifierPrefix;if(Je){var t=Co,r=bo;t=(r&~(1<<32-$r(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=Bc++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=pW++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},vW={readContext:ur,useCallback:H_,useContext:ur,useEffect:KS,useImperativeHandle:U_,useInsertionEffect:z_,useLayoutEffect:F_,useMemo:V_,useReducer:km,useRef:N_,useState:function(){return km(Uc)},useDebugValue:WS,useDeferredValue:function(e){var n=dr();return K_(n,yt.memoizedState,e)},useTransition:function(){var e=km(Uc)[0],n=dr().memoizedState;return[e,n]},useMutableSource:M_,useSyncExternalStore:A_,useId:W_,unstable_isNewReconciler:!1},SW={readContext:ur,useCallback:H_,useContext:ur,useEffect:KS,useImperativeHandle:U_,useInsertionEffect:z_,useLayoutEffect:F_,useMemo:V_,useReducer:Im,useRef:N_,useState:function(){return Im(Uc)},useDebugValue:WS,useDeferredValue:function(e){var n=dr();return yt===null?n.memoizedState=e:K_(n,yt.memoizedState,e)},useTransition:function(){var e=Im(Uc)[0],n=dr().memoizedState;return[e,n]},useMutableSource:M_,useSyncExternalStore:A_,useId:W_,unstable_isNewReconciler:!1};function Ba(e,n){try{var t="",r=n;do t+=GV(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 k0(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var wW=typeof WeakMap=="function"?WeakMap:Map;function q_(e,n,t){t=_o(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){jp||(jp=!0,j0=r),k0(e,n)},t}function Z_(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(){k0(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){k0(e,n),typeof r!="function"&&(vs===null?vs=new Set([this]):vs.add(this));var i=n.stack;this.componentDidCatch(n.value,{componentStack:i!==null?i:""})}),t}function L2(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new wW;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=RW.bind(null,e,n,t),n.then(e,e))}function N2(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 z2(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,ys(t,n,1))),t.lanes|=1),e)}var xW=Ho.ReactCurrentOwner,wn=!1;function on(e,n,t,r){n.child=e===null?T_(n,null,t,r):za(n,e.child,t,r)}function F2(e,n,t,r,o){t=t.render;var s=n.ref;return Ia(n,o),r=HS(e,n,t,r,s,o),t=VS(),e!==null&&!wn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Do(e,n,o)):(Je&&t&&MS(n),n.flags|=1,on(e,n,r,o),n.child)}function B2(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!ew(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,Q_(e,n,s,r,o)):(e=Rh(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:Dc,t(i,r)&&e.ref===n.ref)return Do(e,n,o)}return n.flags|=1,e=ws(s,r),e.ref=n.ref,e.return=n,n.child=e}function Q_(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(Dc(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,Do(e,n,o)}return I0(e,n,t,r,o)}function J_(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(ya,Rn),Rn|=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(ya,Rn),Rn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ke(ya,Rn),Rn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ke(ya,Rn),Rn|=r;return on(e,n,o,t),n.child}function eT(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function I0(e,n,t,r,o){var s=bn(t)?di:Qt.current;return s=La(n,s),Ia(n,o),t=HS(e,n,t,r,s,o),r=VS(),e!==null&&!wn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Do(e,n,o)):(Je&&r&&MS(n),n.flags|=1,on(e,n,t,o),n.child)}function U2(e,n,t,r,o){if(bn(t)){var s=!0;kp(n)}else s=!1;if(Ia(n,o),n.stateNode===null)Mh(e,n),I_(n,t,r),E0(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=ur(c):(c=bn(t)?di:Qt.current,c=La(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)&&O2(n,i,r,c),es=!1;var h=n.memoizedState;i.state=h,Mp(n,r,i,o),l=n.memoizedState,a!==r||h!==l||xn.current||es?(typeof u=="function"&&(P0(n,t,u,r),l=n.memoizedState),(a=es||A2(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,E_(e,n),a=n.memoizedProps,c=n.type===n.elementType?a:yr(n.type,a),i.props=c,d=n.pendingProps,h=i.context,l=t.contextType,typeof l=="object"&&l!==null?l=ur(l):(l=bn(t)?di:Qt.current,l=La(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)&&O2(n,i,r,l),es=!1,h=n.memoizedState,i.state=h,Mp(n,r,i,o);var y=n.memoizedState;a!==d||h!==y||xn.current||es?(typeof p=="function"&&(P0(n,t,p,r),y=n.memoizedState),(c=es||A2(n,t,c,r,h,y,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,y,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,y,l)),typeof i.componentDidUpdate=="function"&&(n.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=y),i.props=r,i.state=y,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&h===e.memoizedState||(n.flags|=1024),r=!1)}return _0(e,n,t,r,s,o)}function _0(e,n,t,r,o,s){eT(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&I2(n,t,!1),Do(e,n,s);r=n.stateNode,xW.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&&I2(n,t,!0),n.child}function tT(e){var n=e.stateNode;n.pendingContext?k2(e,n.pendingContext,n.pendingContext!==n.context):n.context&&k2(e,n.context,!1),zS(e,n.containerInfo)}function H2(e,n,t,r,o){return Na(),OS(o),n.flags|=256,on(e,n,t,r),n.child}var T0={dehydrated:null,treeContext:null,retryLane:0};function $0(e){return{baseLanes:e,cachePool:null,transitions:null}}function nT(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 b0(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=Ef(i,r,0,null),e=ai(e,r,t,null),s.return=n,e.return=n,s.sibling=e,n.child=s,n.child.memoizedState=$0(t),n.memoizedState=T0,e):GS(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return bW(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=ws(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=ws(a,s):(s=ai(s,i,t,null),s.flags|=2),s.return=n,r.return=n,r.sibling=s,n.child=r,r=s,s=n.child,i=e.child.memoizedState,i=i===null?$0(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=T0,r}return s=e.child,e=s.sibling,r=ws(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 GS(e,n){return n=Ef({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Cd(e,n,t,r){return r!==null&&OS(r),za(n,e.child,null,t),e=GS(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function bW(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=_m(Error(q(422))),Cd(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=Ef({mode:"visible",children:r.children},o,0,null),s=ai(s,o,i,null),s.flags|=2,r.return=n,s.return=n,r.sibling=s,n.child=r,n.mode&1&&za(n,e.child,null,i),n.child.memoizedState=$0(i),n.memoizedState=T0,s);if(!(n.mode&1))return Cd(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),Cd(e,n,i,r)}if(a=(i&e.childLanes)!==0,wn||a){if(r=Ct,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,Ro(e,o),Mr(r,e,o,-1))}return JS(),r=_m(Error(q(421))),Cd(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=DW.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,Fn=ms(o.nextSibling),Un=n,Je=!0,br=null,e!==null&&(sr[ir++]=bo,sr[ir++]=Co,sr[ir++]=hi,bo=e.id,Co=e.overflow,hi=n),n=GS(n,r.children),n.flags|=4096,n)}function V2(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),C0(e.return,n,t)}function Tm(e,n,t,r,o){var s=e.memoizedState;s===null?e.memoizedState={isBackwards:n,rendering:null,renderingStartTime:0,last:r,tail:t,tailMode:o}:(s.isBackwards=n,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=t,s.tailMode=o)}function rT(e,n,t){var r=n.pendingProps,o=r.revealOrder,s=r.tail;if(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&&V2(e,t,n);else if(e.tag===19)V2(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&&Ap(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),Tm(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&&Ap(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}Tm(n,!0,t,null,s);break;case"together":Tm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Mh(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function Do(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),fi|=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=ws(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=ws(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function CW(e,n,t){switch(n.tag){case 3:tT(n),Na();break;case 5:$_(n);break;case 1:bn(n.type)&&kp(n);break;case 4:zS(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ke(Tp,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?nT(e,n,t):(Ke(ot,ot.current&1),e=Do(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 rT(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,J_(e,n,t)}return Do(e,n,t)}var oT,M0,sT,iT;oT=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}};M0=function(){};sT=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,ti(qr.current);var s=null;switch(t){case"input":o=Jy(e,o),r=Jy(e,r),s=[];break;case"select":o=lt({},o,{value:void 0}),r=lt({},r,{value:void 0}),s=[];break;case"textarea":o=n0(e,o),r=n0(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Pp)}o0(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"&&(_c.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"&&(_c.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&Xe("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)}};iT=function(e,n,t,r){t!==r&&(n.flags|=4)};function Rl(e,n){if(!Je)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 Ft(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 PW(e,n,t){var r=n.pendingProps;switch(AS(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Ft(n),null;case 1:return bn(n.type)&&Ep(),Ft(n),null;case 3:return r=n.stateNode,Fa(),Ze(xn),Ze(Qt),BS(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(xd(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,br!==null&&(z0(br),br=null))),M0(e,n),Ft(n),null;case 5:FS(n);var o=ti(Fc.current);if(t=n.type,e!==null&&n.stateNode!=null)sT(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 Ft(n),null}if(e=ti(qr.current),xd(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[Wr]=n,r[Nc]=s,e=(n.mode&1)!==0,t){case"dialog":Xe("cancel",r),Xe("close",r);break;case"iframe":case"object":case"embed":Xe("load",r);break;case"video":case"audio":for(o=0;o<ql.length;o++)Xe(ql[o],r);break;case"source":Xe("error",r);break;case"img":case"image":case"link":Xe("error",r),Xe("load",r);break;case"details":Xe("toggle",r);break;case"input":Jb(r,s),Xe("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Xe("invalid",r);break;case"textarea":t2(r,s),Xe("invalid",r)}o0(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&&wd(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&wd(r.textContent,a,e),o=["children",""+a]):_c.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Xe("scroll",r)}switch(t){case"input":hd(r),e2(r,s,!0);break;case"textarea":hd(r),n2(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Pp)}r=o,n.updateQueue=r,r!==null&&(n.flags|=4)}else{i=o.nodeType===9?o:o.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=OI(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[Nc]=r,oT(e,n,!1,!1),n.stateNode=e;e:{switch(i=s0(t,r),t){case"dialog":Xe("cancel",e),Xe("close",e),o=r;break;case"iframe":case"object":case"embed":Xe("load",e),o=r;break;case"video":case"audio":for(o=0;o<ql.length;o++)Xe(ql[o],e);o=r;break;case"source":Xe("error",e),o=r;break;case"img":case"image":case"link":Xe("error",e),Xe("load",e),o=r;break;case"details":Xe("toggle",e),o=r;break;case"input":Jb(e,r),o=Jy(e,r),Xe("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=lt({},r,{value:void 0}),Xe("invalid",e);break;case"textarea":t2(e,r),o=n0(e,r),Xe("invalid",e);break;default:o=r}o0(t,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?jI(e,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&RI(e,l)):s==="children"?typeof l=="string"?(t!=="textarea"||l!=="")&&Tc(e,l):typeof l=="number"&&Tc(e,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(_c.hasOwnProperty(s)?l!=null&&s==="onScroll"&&Xe("scroll",e):l!=null&&yS(e,s,l,i))}switch(t){case"input":hd(e),e2(e,r,!1);break;case"textarea":hd(e),n2(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Cs(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=Pp)}switch(t){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return Ft(n),null;case 6:if(e&&n.stateNode!=null)iT(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=ti(Fc.current),ti(qr.current),xd(n)){if(r=n.stateNode,t=n.memoizedProps,r[Wr]=n,(s=r.nodeValue!==t)&&(e=Un,e!==null))switch(e.tag){case 3:wd(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&wd(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 Ft(n),null;case 13:if(Ze(ot),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Je&&Fn!==null&&n.mode&1&&!(n.flags&128))C_(),Na(),n.flags|=98560,s=!1;else if(s=xd(n),r!==null&&r.dehydrated!==null){if(e===null){if(!s)throw Error(q(318));if(s=n.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(q(317));s[Wr]=n}else Na(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Ft(n),s=!1}else br!==null&&(z0(br),br=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):JS())),n.updateQueue!==null&&(n.flags|=4),Ft(n),null);case 4:return Fa(),M0(e,n),e===null&&jc(n.stateNode.containerInfo),Ft(n),null;case 10:return jS(n.type._context),Ft(n),null;case 17:return bn(n.type)&&Ep(),Ft(n),null;case 19:if(Ze(ot),s=n.memoizedState,s===null)return Ft(n),null;if(r=(n.flags&128)!==0,i=s.rendering,i===null)if(r)Rl(s,!1);else{if(vt!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=Ap(e),i!==null){for(n.flags|=128,Rl(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()>Ua&&(n.flags|=128,r=!0,Rl(s,!1),n.lanes=4194304)}else{if(!r)if(e=Ap(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),Rl(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!Je)return Ft(n),null}else 2*ft()-s.renderingStartTime>Ua&&t!==1073741824&&(n.flags|=128,r=!0,Rl(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):(Ft(n),null);case 22:case 23:return QS(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Rn&1073741824&&(Ft(n),n.subtreeFlags&6&&(n.flags|=8192)):Ft(n),null;case 24:return null;case 25:return null}throw Error(q(156,n.tag))}function EW(e,n){switch(AS(n),n.tag){case 1:return bn(n.type)&&Ep(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return Fa(),Ze(xn),Ze(Qt),BS(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return FS(n),null;case 13:if(Ze(ot),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));Na()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Ze(ot),null;case 4:return Fa(),null;case 10:return jS(n.type._context),null;case 22:case 23:return QS(),null;case 24:return null;default:return null}}var Pd=!1,Wt=!1,kW=typeof WeakSet=="function"?WeakSet:Set,ee=null;function ma(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 A0(e,n,t){try{t()}catch(r){ht(e,n,r)}}var K2=!1;function IW(e,n){if(g0=xp,e=u_(),$S(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(m0={focusedElem:e,selectionRange:t},xp=!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 y=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var f=y.memoizedProps,m=y.memoizedState,S=n.stateNode,w=S.getSnapshotBeforeUpdate(n.elementType===n.type?f:yr(n.type,f),m);S.__reactInternalSnapshotBeforeUpdate=w}break;case 3:var x=n.stateNode.containerInfo;x.nodeType===1?x.textContent="":x.nodeType===9&&x.documentElement&&x.removeChild(x.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(q(163))}}catch(C){ht(n,n.return,C)}if(e=n.sibling,e!==null){e.return=n.return,ee=e;break}ee=n.return}return y=K2,K2=!1,y}function uc(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&&A0(n,t,s)}o=o.next}while(o!==r)}}function Cf(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 O0(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 aT(e){var n=e.alternate;n!==null&&(e.alternate=null,aT(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[Wr],delete n[Nc],delete n[S0],delete n[cW],delete n[uW])),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 lT(e){return e.tag===5||e.tag===3||e.tag===4}function W2(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||lT(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 R0(e,n,t){var r=e.tag;if(r===5||r===6)e=e.stateNode,n?t.nodeType===8?t.parentNode.insertBefore(e,n):t.insertBefore(e,n):(t.nodeType===8?(n=t.parentNode,n.insertBefore(e,t)):(n=t,n.appendChild(e)),t=t._reactRootContainer,t!=null||n.onclick!==null||(n.onclick=Pp));else if(r!==4&&(e=e.child,e!==null))for(R0(e,n,t),e=e.sibling;e!==null;)R0(e,n,t),e=e.sibling}function D0(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(D0(e,n,t),e=e.sibling;e!==null;)D0(e,n,t),e=e.sibling}var Tt=null,wr=!1;function qo(e,n,t){for(t=t.child;t!==null;)cT(e,n,t),t=t.sibling}function cT(e,n,t){if(Xr&&typeof Xr.onCommitFiberUnmount=="function")try{Xr.onCommitFiberUnmount(gf,t)}catch{}switch(t.tag){case 5:Wt||ma(t,n);case 6:var r=Tt,o=wr;Tt=null,qo(e,n,t),Tt=r,wr=o,Tt!==null&&(wr?(e=Tt,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):Tt.removeChild(t.stateNode));break;case 18:Tt!==null&&(wr?(e=Tt,t=t.stateNode,e.nodeType===8?bm(e.parentNode,t):e.nodeType===1&&bm(e,t),Oc(e)):bm(Tt,t.stateNode));break;case 4:r=Tt,o=wr,Tt=t.stateNode.containerInfo,wr=!0,qo(e,n,t),Tt=r,wr=o;break;case 0:case 11:case 14:case 15:if(!Wt&&(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)&&A0(t,n,i),o=o.next}while(o!==r)}qo(e,n,t);break;case 1:if(!Wt&&(ma(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)}qo(e,n,t);break;case 21:qo(e,n,t);break;case 22:t.mode&1?(Wt=(r=Wt)||t.memoizedState!==null,qo(e,n,t),Wt=r):qo(e,n,t);break;default:qo(e,n,t)}}function G2(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new kW),n.forEach(function(r){var o=jW.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function mr(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var s=e,i=n,a=i;e:for(;a!==null;){switch(a.tag){case 5:Tt=a.stateNode,wr=!1;break e;case 3:Tt=a.stateNode.containerInfo,wr=!0;break e;case 4:Tt=a.stateNode.containerInfo,wr=!0;break e}a=a.return}if(Tt===null)throw Error(q(160));cT(s,i,o),Tt=null,wr=!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;)uT(n,e),n=n.sibling}function uT(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(mr(n,e),Fr(e),r&4){try{uc(3,e,e.return),Cf(3,e)}catch(f){ht(e,e.return,f)}try{uc(5,e,e.return)}catch(f){ht(e,e.return,f)}}break;case 1:mr(n,e),Fr(e),r&512&&t!==null&&ma(t,t.return);break;case 5:if(mr(n,e),Fr(e),r&512&&t!==null&&ma(t,t.return),e.flags&32){var o=e.stateNode;try{Tc(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&&MI(o,s),s0(a,i);var c=s0(a,s);for(i=0;i<l.length;i+=2){var u=l[i],d=l[i+1];u==="style"?jI(o,d):u==="dangerouslySetInnerHTML"?RI(o,d):u==="children"?Tc(o,d):yS(o,u,d,c)}switch(a){case"input":e0(o,s);break;case"textarea":AI(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[Nc]=s}catch(f){ht(e,e.return,f)}}break;case 6:if(mr(n,e),Fr(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(mr(n,e),Fr(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{Oc(n.containerInfo)}catch(f){ht(e,e.return,f)}break;case 4:mr(n,e),Fr(e);break;case 13:mr(n,e),Fr(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(qS=ft())),r&4&&G2(e);break;case 22:if(u=t!==null&&t.memoizedState!==null,e.mode&1?(Wt=(c=Wt)||u,mr(n,e),Wt=c):mr(n,e),Fr(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:uc(4,h,h.return);break;case 1:ma(h,h.return);var y=h.stateNode;if(typeof y.componentWillUnmount=="function"){r=h,t=h.return;try{n=r,y.props=n.memoizedProps,y.state=n.memoizedState,y.componentWillUnmount()}catch(f){ht(r,t,f)}}break;case 5:ma(h,h.return);break;case 22:if(h.memoizedState!==null){X2(d);continue}}p!==null?(p.return=h,ee=p):X2(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=DI("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:mr(n,e),Fr(e),r&4&&G2(e);break;case 21:break;default:mr(n,e),Fr(e)}}function Fr(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(lT(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&&(Tc(o,""),r.flags&=-33);var s=W2(e);D0(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=W2(e);R0(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 _W(e,n,t){ee=e,dT(e)}function dT(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||Pd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||Wt;a=Pd;var c=Wt;if(Pd=i,(Wt=l)&&!c)for(ee=o;ee!==null;)i=ee,l=i.child,i.tag===22&&i.memoizedState!==null?q2(o):l!==null?(l.return=i,ee=l):q2(o);for(;s!==null;)ee=s,dT(s),s=s.sibling;ee=o,Pd=a,Wt=c}Y2(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,ee=s):Y2(e)}}function Y2(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:Wt||Cf(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!Wt)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:yr(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&M2(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}M2(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&&Oc(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}Wt||n.flags&512&&O0(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 X2(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 q2(e){for(;ee!==null;){var n=ee;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{Cf(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{O0(n)}catch(l){ht(n,s,l)}break;case 5:var i=n.return;try{O0(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 TW=Math.ceil,Dp=Ho.ReactCurrentDispatcher,YS=Ho.ReactCurrentOwner,lr=Ho.ReactCurrentBatchConfig,ke=0,Ct=null,gt=null,jt=0,Rn=0,ya=js(0),vt=0,Vc=null,fi=0,Pf=0,XS=0,dc=null,vn=null,qS=0,Ua=1/0,go=null,jp=!1,j0=null,vs=null,Ed=!1,cs=null,Lp=0,hc=0,L0=null,Ah=-1,Oh=0;function cn(){return ke&6?ft():Ah!==-1?Ah:Ah=ft()}function Ss(e){return e.mode&1?ke&2&&jt!==0?jt&-jt:hW.transition!==null?(Oh===0&&(Oh=YI()),Oh):(e=Oe,e!==0||(e=window.event,e=e===void 0?16:t_(e.type)),e):1}function Mr(e,n,t,r){if(50<hc)throw hc=0,L0=null,Error(q(185));xu(e,t,r),(!(ke&2)||e!==Ct)&&(e===Ct&&(!(ke&2)&&(Pf|=t),vt===4&&rs(e,jt)),Cn(e,r),t===1&&ke===0&&!(n.mode&1)&&(Ua=ft()+500,wf&&Ls()))}function Cn(e,n){var t=e.callbackNode;hK(e,n);var r=wp(e,e===Ct?jt:0);if(r===0)t!==null&&s2(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&s2(t),n===1)e.tag===0?dW(Z2.bind(null,e)):w_(Z2.bind(null,e)),aW(function(){!(ke&6)&&Ls()}),t=null;else{switch(XI(r)){case 1:t=bS;break;case 4:t=WI;break;case 16:t=Sp;break;case 536870912:t=GI;break;default:t=Sp}t=ST(t,hT.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function hT(e,n){if(Ah=-1,Oh=0,ke&6)throw Error(q(327));var t=e.callbackNode;if(_a()&&e.callbackNode!==t)return null;var r=wp(e,e===Ct?jt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=Np(e,r);else{n=r;var o=ke;ke|=2;var s=fT();(Ct!==e||jt!==n)&&(go=null,Ua=ft()+500,ii(e,n));do try{AW();break}catch(a){pT(e,a)}while(!0);DS(),Dp.current=s,ke=o,gt!==null?n=0:(Ct=null,jt=0,n=vt)}if(n!==0){if(n===2&&(o=u0(e),o!==0&&(r=o,n=N0(e,o))),n===1)throw t=Vc,ii(e,0),rs(e,r),Cn(e,ft()),t;if(n===6)rs(e,r);else{if(o=e.current.alternate,!(r&30)&&!$W(o)&&(n=Np(e,r),n===2&&(s=u0(e),s!==0&&(r=s,n=N0(e,s))),n===1))throw t=Vc,ii(e,0),rs(e,r),Cn(e,ft()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:Xs(e,vn,go);break;case 3:if(rs(e,r),(r&130023424)===r&&(n=qS+500-ft(),10<n)){if(wp(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){cn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=v0(Xs.bind(null,e,vn,go),n);break}Xs(e,vn,go);break;case 4:if(rs(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*TW(r/1960))-r,10<r){e.timeoutHandle=v0(Xs.bind(null,e,vn,go),r);break}Xs(e,vn,go);break;case 5:Xs(e,vn,go);break;default:throw Error(q(329))}}}return Cn(e,ft()),e.callbackNode===t?hT.bind(null,e):null}function N0(e,n){var t=dc;return e.current.memoizedState.isDehydrated&&(ii(e,n).flags|=256),e=Np(e,n),e!==2&&(n=vn,vn=t,n!==null&&z0(n)),e}function z0(e){vn===null?vn=e:vn.push.apply(vn,e)}function $W(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(!Rr(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 rs(e,n){for(n&=~XS,n&=~Pf,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 Z2(e){if(ke&6)throw Error(q(327));_a();var n=wp(e,0);if(!(n&1))return Cn(e,ft()),null;var t=Np(e,n);if(e.tag!==0&&t===2){var r=u0(e);r!==0&&(n=r,t=N0(e,r))}if(t===1)throw t=Vc,ii(e,0),rs(e,n),Cn(e,ft()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,Xs(e,vn,go),Cn(e,ft()),null}function ZS(e,n){var t=ke;ke|=1;try{return e(n)}finally{ke=t,ke===0&&(Ua=ft()+500,wf&&Ls())}}function gi(e){cs!==null&&cs.tag===0&&!(ke&6)&&_a();var n=ke;ke|=1;var t=lr.transition,r=Oe;try{if(lr.transition=null,Oe=1,e)return e()}finally{Oe=r,lr.transition=t,ke=n,!(ke&6)&&Ls()}}function QS(){Rn=ya.current,Ze(ya)}function ii(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,iW(t)),gt!==null)for(t=gt.return;t!==null;){var r=t;switch(AS(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Ep();break;case 3:Fa(),Ze(xn),Ze(Qt),BS();break;case 5:FS(r);break;case 4:Fa();break;case 13:Ze(ot);break;case 19:Ze(ot);break;case 10:jS(r.type._context);break;case 22:case 23:QS()}t=t.return}if(Ct=e,gt=e=ws(e.current,null),jt=Rn=n,vt=0,Vc=null,XS=Pf=fi=0,vn=dc=null,ei!==null){for(n=0;n<ei.length;n++)if(t=ei[n],r=t.interleaved,r!==null){t.interleaved=null;var o=r.next,s=t.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}t.pending=r}ei=null}return e}function pT(e,n){do{var t=gt;try{if(DS(),Th.current=Rp,Op){for(var r=at.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Op=!1}if(pi=0,xt=yt=at=null,cc=!1,Bc=0,YS.current=null,t===null||t.return===null){vt=1,Vc=n,gt=null;break}e:{var s=e,i=t.return,a=t,l=n;if(n=jt,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=N2(i);if(p!==null){p.flags&=-257,z2(p,i,a,s,n),p.mode&1&&L2(s,c,n),n=p,l=c;var y=n.updateQueue;if(y===null){var f=new Set;f.add(l),n.updateQueue=f}else y.add(l);break e}else{if(!(n&1)){L2(s,c,n),JS();break e}l=Error(q(426))}}else if(Je&&a.mode&1){var m=N2(i);if(m!==null){!(m.flags&65536)&&(m.flags|=256),z2(m,i,a,s,n),OS(Ba(l,a));break e}}s=l=Ba(l,a),vt!==4&&(vt=2),dc===null?dc=[s]:dc.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var S=q_(s,l,n);$2(s,S);break e;case 1:a=l;var w=s.type,x=s.stateNode;if(!(s.flags&128)&&(typeof w.getDerivedStateFromError=="function"||x!==null&&typeof x.componentDidCatch=="function"&&(vs===null||!vs.has(x)))){s.flags|=65536,n&=-n,s.lanes|=n;var C=Z_(s,a,n);$2(s,C);break e}}s=s.return}while(s!==null)}mT(t)}catch(P){n=P,gt===t&&t!==null&&(gt=t=t.return);continue}break}while(!0)}function fT(){var e=Dp.current;return Dp.current=Rp,e===null?Rp:e}function JS(){(vt===0||vt===3||vt===2)&&(vt=4),Ct===null||!(fi&268435455)&&!(Pf&268435455)||rs(Ct,jt)}function Np(e,n){var t=ke;ke|=2;var r=fT();(Ct!==e||jt!==n)&&(go=null,ii(e,n));do try{MW();break}catch(o){pT(e,o)}while(!0);if(DS(),ke=t,Dp.current=r,gt!==null)throw Error(q(261));return Ct=null,jt=0,vt}function MW(){for(;gt!==null;)gT(gt)}function AW(){for(;gt!==null&&!rK();)gT(gt)}function gT(e){var n=vT(e.alternate,e,Rn);e.memoizedProps=e.pendingProps,n===null?mT(e):gt=n,YS.current=null}function mT(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=EW(t,n),t!==null){t.flags&=32767,gt=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{vt=6,gt=null;return}}else if(t=PW(t,n,Rn),t!==null){gt=t;return}if(n=n.sibling,n!==null){gt=n;return}gt=n=e}while(n!==null);vt===0&&(vt=5)}function Xs(e,n,t){var r=Oe,o=lr.transition;try{lr.transition=null,Oe=1,OW(e,n,t,r)}finally{lr.transition=o,Oe=r}return null}function OW(e,n,t,r){do _a();while(cs!==null);if(ke&6)throw Error(q(327));t=e.finishedWork;var o=e.finishedLanes;if(t===null)return null;if(e.finishedWork=null,e.finishedLanes=0,t===e.current)throw Error(q(177));e.callbackNode=null,e.callbackPriority=0;var s=t.lanes|t.childLanes;if(pK(e,s),e===Ct&&(gt=Ct=null,jt=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||Ed||(Ed=!0,ST(Sp,function(){return _a(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=lr.transition,lr.transition=null;var i=Oe;Oe=1;var a=ke;ke|=4,YS.current=null,IW(e,t),uT(t,e),JK(m0),xp=!!g0,m0=g0=null,e.current=t,_W(t),oK(),ke=a,Oe=i,lr.transition=s}else e.current=t;if(Ed&&(Ed=!1,cs=e,Lp=o),s=e.pendingLanes,s===0&&(vs=null),aK(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(jp)throw jp=!1,e=j0,j0=null,e;return Lp&1&&e.tag!==0&&_a(),s=e.pendingLanes,s&1?e===L0?hc++:(hc=0,L0=e):hc=0,Ls(),null}function _a(){if(cs!==null){var e=XI(Lp),n=lr.transition,t=Oe;try{if(lr.transition=null,Oe=16>e?16:e,cs===null)var r=!1;else{if(e=cs,cs=null,Lp=0,ke&6)throw Error(q(331));var o=ke;for(ke|=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:uc(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(aT(u),u===c){ee=null;break}if(h!==null){h.return=p,ee=h;break}ee=p}}}var y=s.alternate;if(y!==null){var f=y.child;if(f!==null){y.child=null;do{var m=f.sibling;f.sibling=null,f=m}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:uc(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,ee=S;break e}ee=s.return}}var w=e.current;for(ee=w;ee!==null;){i=ee;var x=i.child;if(i.subtreeFlags&2064&&x!==null)x.return=i,ee=x;else e:for(i=w;ee!==null;){if(a=ee,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:Cf(9,a)}}catch(P){ht(a,a.return,P)}if(a===i){ee=null;break e}var C=a.sibling;if(C!==null){C.return=a.return,ee=C;break e}ee=a.return}}if(ke=o,Ls(),Xr&&typeof Xr.onPostCommitFiberRoot=="function")try{Xr.onPostCommitFiberRoot(gf,e)}catch{}r=!0}return r}finally{Oe=t,lr.transition=n}}return!1}function Q2(e,n,t){n=Ba(t,n),n=q_(e,n,1),e=ys(e,n,1),n=cn(),e!==null&&(xu(e,1,n),Cn(e,n))}function ht(e,n,t){if(e.tag===3)Q2(e,e,t);else for(;n!==null;){if(n.tag===3){Q2(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(vs===null||!vs.has(r))){e=Ba(t,e),e=Z_(n,e,1),n=ys(n,e,1),e=cn(),n!==null&&(xu(n,1,e),Cn(n,e));break}}n=n.return}}function RW(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=cn(),e.pingedLanes|=e.suspendedLanes&t,Ct===e&&(jt&t)===t&&(vt===4||vt===3&&(jt&130023424)===jt&&500>ft()-qS?ii(e,0):XS|=t),Cn(e,n)}function yT(e,n){n===0&&(e.mode&1?(n=gd,gd<<=1,!(gd&130023424)&&(gd=4194304)):n=1);var t=cn();e=Ro(e,n),e!==null&&(xu(e,n,t),Cn(e,t))}function DW(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),yT(e,t)}function jW(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),yT(e,t)}var vT;vT=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||xn.current)wn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return wn=!1,CW(e,n,t);wn=!!(e.flags&131072)}else wn=!1,Je&&n.flags&1048576&&x_(n,_p,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Mh(e,n),e=n.pendingProps;var o=La(n,Qt.current);Ia(n,t),o=HS(null,n,r,e,o,t);var s=VS();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,bn(r)?(s=!0,kp(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,NS(n),o.updater=xf,n.stateNode=o,o._reactInternals=n,E0(n,r,e,t),n=_0(null,n,r,!0,s,t)):(n.tag=0,Je&&s&&MS(n),on(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(Mh(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=NW(r),e=yr(r,e),o){case 0:n=I0(null,n,r,e,t);break e;case 1:n=U2(null,n,r,e,t);break e;case 11:n=F2(null,n,r,e,t);break e;case 14:n=B2(null,n,r,yr(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:yr(r,o),I0(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:yr(r,o),U2(e,n,r,o,t);case 3:e:{if(tT(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,E_(e,n),Mp(n,r,null,t);var i=n.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},n.updateQueue.baseState=s,n.memoizedState=s,n.flags&256){o=Ba(Error(q(423)),n),n=H2(e,n,r,t,o);break e}else if(r!==o){o=Ba(Error(q(424)),n),n=H2(e,n,r,t,o);break e}else for(Fn=ms(n.stateNode.containerInfo.firstChild),Un=n,Je=!0,br=null,t=T_(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(Na(),r===o){n=Do(e,n,t);break e}on(e,n,r,t)}n=n.child}return n;case 5:return $_(n),e===null&&b0(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,y0(r,o)?i=null:s!==null&&y0(r,s)&&(n.flags|=32),eT(e,n),on(e,n,i,t),n.child;case 6:return e===null&&b0(n),null;case 13:return nT(e,n,t);case 4:return zS(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:yr(r,o),F2(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(Tp,r._currentValue),r._currentValue=i,s!==null)if(Rr(s.value,i)){if(s.children===o.children&&!xn.current){n=Do(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),C0(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),C0(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,Ia(n,t),o=ur(o),r=r(o),n.flags|=1,on(e,n,r,t),n.child;case 14:return r=n.type,o=yr(r,n.pendingProps),o=yr(r.type,o),B2(e,n,r,o,t);case 15:return Q_(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:yr(r,o),Mh(e,n),n.tag=1,bn(r)?(e=!0,kp(n)):e=!1,Ia(n,t),I_(n,r,o),E0(n,r,o,t),_0(null,n,r,!0,e,t);case 19:return rT(e,n,t);case 22:return J_(e,n,t)}throw Error(q(156,n.tag))};function ST(e,n){return KI(e,n)}function LW(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 ar(e,n,t,r){return new LW(e,n,t,r)}function ew(e){return e=e.prototype,!(!e||!e.isReactComponent)}function NW(e){if(typeof e=="function")return ew(e)?1:0;if(e!=null){if(e=e.$$typeof,e===SS)return 11;if(e===wS)return 14}return 2}function ws(e,n){var t=e.alternate;return t===null?(t=ar(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 Rh(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")ew(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case aa:return ai(t.children,o,s,n);case vS:i=8,o|=8;break;case Xy:return e=ar(12,t,n,o|2),e.elementType=Xy,e.lanes=s,e;case qy:return e=ar(13,t,n,o),e.elementType=qy,e.lanes=s,e;case Zy:return e=ar(19,t,n,o),e.elementType=Zy,e.lanes=s,e;case _I:return Ef(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case kI:i=10;break e;case II:i=9;break e;case SS:i=11;break e;case wS:i=14;break e;case Jo:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=ar(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function ai(e,n,t,r){return e=ar(7,e,r,n),e.lanes=t,e}function Ef(e,n,t,r){return e=ar(22,e,r,n),e.elementType=_I,e.lanes=t,e.stateNode={isHidden:!1},e}function $m(e,n,t){return e=ar(6,e,null,n),e.lanes=t,e}function Mm(e,n,t){return n=ar(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function zW(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=dm(0),this.expirationTimes=dm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=dm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function tw(e,n,t,r,o,s,i,a,l){return e=new zW(e,n,t,a,l),n===1?(n=1,s===!0&&(n|=8)):n=0,s=ar(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},NS(s),e}function FW(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:ia,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function wT(e){if(!e)return Ps;e=e._reactInternals;e:{if(Ii(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(bn(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(bn(t))return S_(e,t,n)}return n}function xT(e,n,t,r,o,s,i,a,l){return e=tw(t,r,!0,e,o,s,i,a,l),e.context=wT(null),t=e.current,r=cn(),o=Ss(t),s=_o(r,o),s.callback=n??null,ys(t,s,o),e.current.lanes=o,xu(e,o,r),Cn(e,r),e}function kf(e,n,t,r){var o=n.current,s=cn(),i=Ss(o);return t=wT(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=ys(o,n,i),e!==null&&(Mr(e,o,i,s),_h(e,o,i)),i}function zp(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 J2(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function nw(e,n){J2(e,n),(e=e.alternate)&&J2(e,n)}function BW(){return null}var bT=typeof reportError=="function"?reportError:function(e){console.error(e)};function rw(e){this._internalRoot=e}If.prototype.render=rw.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));kf(e,n,null,null)};If.prototype.unmount=rw.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;gi(function(){kf(null,e,null,null)}),n[Oo]=null}};function If(e){this._internalRoot=e}If.prototype.unstable_scheduleHydration=function(e){if(e){var n=QI();e={blockedOn:null,target:e,priority:n};for(var t=0;t<ns.length&&n!==0&&n<ns[t].priority;t++);ns.splice(t,0,e),t===0&&e_(e)}};function ow(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function _f(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function eC(){}function UW(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=zp(i);s.call(c)}}var i=xT(n,r,e,0,null,!1,!1,"",eC);return e._reactRootContainer=i,e[Oo]=i.current,jc(e.nodeType===8?e.parentNode:e),gi(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=zp(l);a.call(c)}}var l=tw(e,0,!1,null,null,!1,!1,"",eC);return e._reactRootContainer=l,e[Oo]=l.current,jc(e.nodeType===8?e.parentNode:e),gi(function(){kf(n,l,t,r)}),l}function Tf(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=zp(i);a.call(l)}}kf(n,i,e,o)}else i=UW(t,n,e,o,r);return zp(i)}qI=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=Xl(n.pendingLanes);t!==0&&(CS(n,t|1),Cn(n,ft()),!(ke&6)&&(Ua=ft()+500,Ls()))}break;case 13:gi(function(){var r=Ro(e,1);if(r!==null){var o=cn();Mr(r,e,1,o)}}),nw(e,1)}};PS=function(e){if(e.tag===13){var n=Ro(e,134217728);if(n!==null){var t=cn();Mr(n,e,134217728,t)}nw(e,134217728)}};ZI=function(e){if(e.tag===13){var n=Ss(e),t=Ro(e,n);if(t!==null){var r=cn();Mr(t,e,n,r)}nw(e,n)}};QI=function(){return Oe};JI=function(e,n){var t=Oe;try{return Oe=e,n()}finally{Oe=t}};a0=function(e,n,t){switch(n){case"input":if(e0(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=Sf(r);if(!o)throw Error(q(90));$I(r),e0(r,o)}}}break;case"textarea":AI(e,t);break;case"select":n=t.value,n!=null&&Ca(e,!!t.multiple,n,!1)}};zI=ZS;FI=gi;var HW={usingClientEntryPoint:!1,Events:[Cu,da,Sf,LI,NI,ZS]},Dl={findFiberByHostInstance:Js,bundleType:0,version:"18.2.0",rendererPackageName:"react-dom"},VW={bundleType:Dl.bundleType,version:Dl.version,rendererPackageName:Dl.rendererPackageName,rendererConfig:Dl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Ho.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=HI(e),e===null?null:e.stateNode},findFiberByHostInstance:Dl.findFiberByHostInstance||BW,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 kd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!kd.isDisabled&&kd.supportsFiber)try{gf=kd.inject(VW),Xr=kd}catch{}}Yn.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=HW;Yn.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!ow(n))throw Error(q(200));return FW(e,n,null,t)};Yn.createRoot=function(e,n){if(!ow(e))throw Error(q(299));var t=!1,r="",o=bT;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=tw(e,1,!1,null,null,t,!1,r,o),e[Oo]=n.current,jc(e.nodeType===8?e.parentNode:e),new rw(n)};Yn.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=HI(n),e=e===null?null:e.stateNode,e};Yn.flushSync=function(e){return gi(e)};Yn.hydrate=function(e,n,t){if(!_f(n))throw Error(q(200));return Tf(null,e,n,!0,t)};Yn.hydrateRoot=function(e,n,t){if(!ow(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=bT;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=xT(n,null,e,1,t??null,o,!1,s,i),e[Oo]=n.current,jc(e),r)for(e=0;e<r.length;e++)t=r[e],o=t._getVersion,o=o(t._source),n.mutableSourceEagerHydrationData==null?n.mutableSourceEagerHydrationData=[t,o]:n.mutableSourceEagerHydrationData.push(t,o);return new If(n)};Yn.render=function(e,n,t){if(!_f(n))throw Error(q(200));return Tf(null,e,n,!1,t)};Yn.unmountComponentAtNode=function(e){if(!_f(e))throw Error(q(40));return e._reactRootContainer?(gi(function(){Tf(null,null,e,!1,function(){e._reactRootContainer=null,e[Oo]=null})}),!0):!1};Yn.unstable_batchedUpdates=ZS;Yn.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!_f(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return Tf(e,n,t,!1,r)};Yn.version="18.2.0-next-9e3b772b8-20220608";function CT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(CT)}catch(e){console.error(e)}}CT(),xI.exports=Yn;var il=xI.exports;const KW=Si(il);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 WW(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function $f(...e){return n=>e.forEach(t=>WW(t,n))}function Ge(...e){return b.useCallback($f(...e),e)}function so(e,n=[]){let t=[];function r(s,i){const a=b.createContext(i),l=t.length;t=[...t,i];function c(d){const{scope:h,children:p,...y}=d,f=(h==null?void 0:h[e][l])||a,m=b.useMemo(()=>y,Object.values(y));return b.createElement(f.Provider,{value:m},p)}function u(d,h){const p=(h==null?void 0:h[e][l])||a,y=b.useContext(p);if(y)return y;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=>b.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return b.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,GW(o,...n)]}function GW(...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 b.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return t.scopeName=n.scopeName,t}const mi=b.forwardRef((e,n)=>{const{children:t,...r}=e,o=b.Children.toArray(t),s=o.find(XW);if(s){const i=s.props.children,a=o.map(l=>l===s?b.Children.count(i)>1?b.Children.only(null):b.isValidElement(i)?i.props.children:null:l);return b.createElement(F0,Q({},r,{ref:n}),b.isValidElement(i)?b.cloneElement(i,void 0,a):null)}return b.createElement(F0,Q({},r,{ref:n}),t)});mi.displayName="Slot";const F0=b.forwardRef((e,n)=>{const{children:t,...r}=e;return b.isValidElement(t)?b.cloneElement(t,{...qW(r,t.props),ref:n?$f(n,t.ref):t.ref}):b.Children.count(t)>1?b.Children.only(null):null});F0.displayName="SlotClone";const YW=({children:e})=>b.createElement(b.Fragment,null,e);function XW(e){return b.isValidElement(e)&&e.type===YW}function qW(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 Mf(e){const n=e+"CollectionProvider",[t,r]=so(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:y,children:f}=p,m=ne.useRef(null),S=ne.useRef(new Map).current;return ne.createElement(o,{scope:y,itemMap:S,collectionRef:m},f)},a=e+"CollectionSlot",l=ne.forwardRef((p,y)=>{const{scope:f,children:m}=p,S=s(a,f),w=Ge(y,S.collectionRef);return ne.createElement(mi,{ref:w},m)}),c=e+"CollectionItemSlot",u="data-radix-collection-item",d=ne.forwardRef((p,y)=>{const{scope:f,children:m,...S}=p,w=ne.useRef(null),x=Ge(y,w),C=s(c,f);return ne.useEffect(()=>(C.itemMap.set(w,{ref:w,...S}),()=>void C.itemMap.delete(w))),ne.createElement(mi,{[u]:"",ref:x},m)});function h(p){const y=s(e+"CollectionConsumer",p);return ne.useCallback(()=>{const m=y.collectionRef.current;if(!m)return[];const S=Array.from(m.querySelectorAll(`[${u}]`));return Array.from(y.itemMap.values()).sort((C,P)=>S.indexOf(C.ref.current)-S.indexOf(P.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:l,ItemSlot:d},h,r]}const ZW=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],ze=ZW.reduce((e,n)=>{const t=b.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?mi:n;return b.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),b.createElement(a,Q({},i,{ref:o}))});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function sw(e,n){e&&il.flushSync(()=>e.dispatchEvent(n))}function Jt(e){const n=b.useRef(e);return b.useEffect(()=>{n.current=e}),b.useMemo(()=>(...t)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...t)},[])}function QW(e,n=globalThis==null?void 0:globalThis.document){const t=Jt(e);b.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r),()=>n.removeEventListener("keydown",r)},[t,n])}const B0="dismissableLayer.update",JW="dismissableLayer.pointerDownOutside",eG="dismissableLayer.focusOutside";let tC;const PT=b.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Af=b.forwardRef((e,n)=>{var t;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:a,onDismiss:l,...c}=e,u=b.useContext(PT),[d,h]=b.useState(null),p=(t=d==null?void 0:d.ownerDocument)!==null&&t!==void 0?t:globalThis==null?void 0:globalThis.document,[,y]=b.useState({}),f=Ge(n,_=>h(_)),m=Array.from(u.layers),[S]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),w=m.indexOf(S),x=d?m.indexOf(d):-1,C=u.layersWithOutsidePointerEventsDisabled.size>0,P=x>=w,k=nG(_=>{const $=_.target,T=[...u.branches].some(R=>R.contains($));!P||T||(s==null||s(_),a==null||a(_),_.defaultPrevented||l==null||l())},p),I=rG(_=>{const $=_.target;[...u.branches].some(R=>R.contains($))||(i==null||i(_),a==null||a(_),_.defaultPrevented||l==null||l())},p);return QW(_=>{x===u.layers.size-1&&(o==null||o(_),!_.defaultPrevented&&l&&(_.preventDefault(),l()))},p),b.useEffect(()=>{if(d)return r&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(tC=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),nC(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=tC)}},[d,p,r,u]),b.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),nC())},[d,u]),b.useEffect(()=>{const _=()=>y({});return document.addEventListener(B0,_),()=>document.removeEventListener(B0,_)},[]),b.createElement(ze.div,Q({},c,{ref:f,style:{pointerEvents:C?P?"auto":"none":void 0,...e.style},onFocusCapture:se(e.onFocusCapture,I.onFocusCapture),onBlurCapture:se(e.onBlurCapture,I.onBlurCapture),onPointerDownCapture:se(e.onPointerDownCapture,k.onPointerDownCapture)}))}),tG=b.forwardRef((e,n)=>{const t=b.useContext(PT),r=b.useRef(null),o=Ge(n,r);return b.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),b.createElement(ze.div,Q({},e,{ref:o}))});function nG(e,n=globalThis==null?void 0:globalThis.document){const t=Jt(e),r=b.useRef(!1),o=b.useRef(()=>{});return b.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let u=function(){ET(JW,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 rG(e,n=globalThis==null?void 0:globalThis.document){const t=Jt(e),r=b.useRef(!1);return b.useEffect(()=>{const o=s=>{s.target&&!r.current&&ET(eG,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 nC(){const e=new CustomEvent(B0);document.dispatchEvent(e)}function ET(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?sw(o,s):o.dispatchEvent(s)}const oG=Af,sG=tG,Of=b.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?KW.createPortal(b.createElement(ze.div,Q({},o,{ref:n})),r):null}),yi=globalThis!=null&&globalThis.document?b.useLayoutEffect:()=>{};function iG(e,n){return b.useReducer((t,r)=>{const o=n[t][r];return o??t},e)}const jr=e=>{const{present:n,children:t}=e,r=aG(n),o=typeof t=="function"?t({present:r.isPresent}):b.Children.only(t),s=Ge(r.ref,o.ref);return typeof t=="function"||r.isPresent?b.cloneElement(o,{ref:s}):null};jr.displayName="Presence";function aG(e){const[n,t]=b.useState(),r=b.useRef({}),o=b.useRef(e),s=b.useRef("none"),i=e?"mounted":"unmounted",[a,l]=iG(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return b.useEffect(()=>{const c=Id(r.current);s.current=a==="mounted"?c:"none"},[a]),yi(()=>{const c=r.current,u=o.current;if(u!==e){const h=s.current,p=Id(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]),yi(()=>{if(n){const c=d=>{const p=Id(r.current).includes(d.animationName);d.target===n&&p&&il.flushSync(()=>l("ANIMATION_END"))},u=d=>{d.target===n&&(s.current=Id(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:b.useCallback(c=>{c&&(r.current=getComputedStyle(c)),t(c)},[])}}function Id(e){return(e==null?void 0:e.animationName)||"none"}function Ns({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=lG({defaultProp:n,onChange:t}),s=e!==void 0,i=s?e:r,a=Jt(t),l=b.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 lG({defaultProp:e,onChange:n}){const t=b.useState(e),[r]=t,o=b.useRef(r),s=Jt(n);return b.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),t}const kT=b.forwardRef((e,n)=>b.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}}))),IT="ToastProvider",[iw,cG,uG]=Mf("Toast"),[_T,ste]=so("Toast",[uG]),[dG,Rf]=_T(IT),TT=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=b.useState(null),[c,u]=b.useState(0),d=b.useRef(!1),h=b.useRef(!1);return b.createElement(iw.Provider,{scope:n},b.createElement(dG,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:b.useCallback(()=>u(p=>p+1),[]),onToastRemove:b.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:d,isClosePausedRef:h},i))};TT.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const n=`Invalid prop \`label\` supplied to \`${IT}\`. Expected non-empty \`string\`.`;return new Error(n)}return null}};const hG="ToastViewport",pG=["F8"],U0="toast.viewportPause",H0="toast.viewportResume",fG=b.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=pG,label:o="Notifications ({hotkey})",...s}=e,i=Rf(hG,t),a=cG(t),l=b.useRef(null),c=b.useRef(null),u=b.useRef(null),d=b.useRef(null),h=Ge(n,d,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=i.toastCount>0;b.useEffect(()=>{const m=S=>{var w;r.every(C=>S[C]||S.code===C)&&((w=d.current)===null||w===void 0||w.focus())};return document.addEventListener("keydown",m),()=>document.removeEventListener("keydown",m)},[r]),b.useEffect(()=>{const m=l.current,S=d.current;if(y&&m&&S){const w=()=>{if(!i.isClosePausedRef.current){const k=new CustomEvent(U0);S.dispatchEvent(k),i.isClosePausedRef.current=!0}},x=()=>{if(i.isClosePausedRef.current){const k=new CustomEvent(H0);S.dispatchEvent(k),i.isClosePausedRef.current=!1}},C=k=>{!m.contains(k.relatedTarget)&&x()},P=()=>{m.contains(document.activeElement)||x()};return m.addEventListener("focusin",w),m.addEventListener("focusout",C),m.addEventListener("pointermove",w),m.addEventListener("pointerleave",P),window.addEventListener("blur",w),window.addEventListener("focus",x),()=>{m.removeEventListener("focusin",w),m.removeEventListener("focusout",C),m.removeEventListener("pointermove",w),m.removeEventListener("pointerleave",P),window.removeEventListener("blur",w),window.removeEventListener("focus",x)}}},[y,i.isClosePausedRef]);const f=b.useCallback(({tabbingDirection:m})=>{const w=a().map(x=>{const C=x.ref.current,P=[C,...$G(C)];return m==="forwards"?P:P.reverse()});return(m==="forwards"?w.reverse():w).flat()},[a]);return b.useEffect(()=>{const m=d.current;if(m){const S=w=>{const x=w.altKey||w.ctrlKey||w.metaKey;if(w.key==="Tab"&&!x){const _=document.activeElement,$=w.shiftKey;if(w.target===m&&$){var P;(P=c.current)===null||P===void 0||P.focus();return}const L=f({tabbingDirection:$?"backwards":"forwards"}),N=L.findIndex(D=>D===_);if(Am(L.slice(N+1)))w.preventDefault();else{var k,I;$?(k=c.current)===null||k===void 0||k.focus():(I=u.current)===null||I===void 0||I.focus()}}};return m.addEventListener("keydown",S),()=>m.removeEventListener("keydown",S)}},[a,f]),b.createElement(sG,{ref:l,role:"region","aria-label":o.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:y?void 0:"none"}},y&&b.createElement(rC,{ref:c,onFocusFromOutsideViewport:()=>{const m=f({tabbingDirection:"forwards"});Am(m)}}),b.createElement(iw.Slot,{scope:t},b.createElement(ze.ol,Q({tabIndex:-1},s,{ref:h}))),y&&b.createElement(rC,{ref:u,onFocusFromOutsideViewport:()=>{const m=f({tabbingDirection:"backwards"});Am(m)}}))}),gG="ToastFocusProxy",rC=b.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=Rf(gG,t);return b.createElement(kT,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()}}))}),Df="Toast",mG="toast.swipeStart",yG="toast.swipeMove",vG="toast.swipeCancel",SG="toast.swipeEnd",wG=b.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,l]=Ns({prop:r,defaultProp:o,onChange:s});return b.createElement(jr,{present:t||a},b.createElement($T,Q({open:a},i,{ref:n,onClose:()=>l(!1),onPause:Jt(e.onPause),onResume:Jt(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)})})))}),[xG,bG]=_T(Df,{onClose(){}}),$T=b.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,...y}=e,f=Rf(Df,t),[m,S]=b.useState(null),w=Ge(n,D=>S(D)),x=b.useRef(null),C=b.useRef(null),P=o||f.duration,k=b.useRef(0),I=b.useRef(P),_=b.useRef(0),{onToastAdd:$,onToastRemove:T}=f,R=Jt(()=>{var D;(m==null?void 0:m.contains(document.activeElement))&&((D=f.viewport)===null||D===void 0||D.focus()),i()}),L=b.useCallback(D=>{!D||D===1/0||(window.clearTimeout(_.current),k.current=new Date().getTime(),_.current=window.setTimeout(R,D))},[R]);b.useEffect(()=>{const D=f.viewport;if(D){const z=()=>{L(I.current),c==null||c()},F=()=>{const W=new Date().getTime()-k.current;I.current=I.current-W,window.clearTimeout(_.current),l==null||l()};return D.addEventListener(U0,F),D.addEventListener(H0,z),()=>{D.removeEventListener(U0,F),D.removeEventListener(H0,z)}}},[f.viewport,P,l,c,L]),b.useEffect(()=>{s&&!f.isClosePausedRef.current&&L(P)},[s,P,f.isClosePausedRef,L]),b.useEffect(()=>($(),()=>T()),[$,T]);const N=b.useMemo(()=>m?RT(m):null,[m]);return f.viewport?b.createElement(b.Fragment,null,N&&b.createElement(CG,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},N),b.createElement(xG,{scope:t,onClose:R},il.createPortal(b.createElement(iw.ItemSlot,{scope:t},b.createElement(oG,{asChild:!0,onEscapeKeyDown:se(a,()=>{f.isFocusedToastEscapeKeyDownRef.current||R(),f.isFocusedToastEscapeKeyDownRef.current=!1})},b.createElement(ze.li,Q({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":f.swipeDirection},y,{ref:w,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:se(e.onKeyDown,D=>{D.key==="Escape"&&(a==null||a(D.nativeEvent),D.nativeEvent.defaultPrevented||(f.isFocusedToastEscapeKeyDownRef.current=!0,R()))}),onPointerDown:se(e.onPointerDown,D=>{D.button===0&&(x.current={x:D.clientX,y:D.clientY})}),onPointerMove:se(e.onPointerMove,D=>{if(!x.current)return;const z=D.clientX-x.current.x,F=D.clientY-x.current.y,W=!!C.current,H=["left","right"].includes(f.swipeDirection),U=["left","up"].includes(f.swipeDirection)?Math.min:Math.max,V=H?U(0,z):0,X=H?0:U(0,F),re=D.pointerType==="touch"?10:2,ge={x:V,y:X},Ce={originalEvent:D,delta:ge};W?(C.current=ge,_d(yG,d,Ce,{discrete:!1})):oC(ge,f.swipeDirection,re)?(C.current=ge,_d(mG,u,Ce,{discrete:!1}),D.target.setPointerCapture(D.pointerId)):(Math.abs(z)>re||Math.abs(F)>re)&&(x.current=null)}),onPointerUp:se(e.onPointerUp,D=>{const z=C.current,F=D.target;if(F.hasPointerCapture(D.pointerId)&&F.releasePointerCapture(D.pointerId),C.current=null,x.current=null,z){const W=D.currentTarget,H={originalEvent:D,delta:z};oC(z,f.swipeDirection,f.swipeThreshold)?_d(SG,p,H,{discrete:!0}):_d(vG,h,H,{discrete:!0}),W.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})))),f.viewport))):null});$T.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const n=`Invalid prop \`type\` supplied to \`${Df}\`. Expected \`foreground | background\`.`;return new Error(n)}return null}};const CG=e=>{const{__scopeToast:n,children:t,...r}=e,o=Rf(Df,n),[s,i]=b.useState(!1),[a,l]=b.useState(!1);return _G(()=>i(!0)),b.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:b.createElement(Of,{asChild:!0},b.createElement(kT,r,s&&b.createElement(b.Fragment,null,o.label," ",t)))},PG=b.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return b.createElement(ze.div,Q({},r,{ref:n}))}),EG=b.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return b.createElement(ze.div,Q({},r,{ref:n}))}),kG="ToastAction",MT=b.forwardRef((e,n)=>{const{altText:t,...r}=e;return t?b.createElement(OT,{altText:t,asChild:!0},b.createElement(AT,Q({},r,{ref:n}))):null});MT.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${kG}\``)}};const IG="ToastClose",AT=b.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=bG(IG,t);return b.createElement(OT,{asChild:!0},b.createElement(ze.button,Q({type:"button"},r,{ref:n,onClick:se(e.onClick,o.onClose)})))}),OT=b.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return b.createElement(ze.div,Q({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0},o,{ref:n}))});function RT(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),TG(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(...RT(r))}}),n}function _d(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?sw(o,s):o.dispatchEvent(s)}const oC=(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 _G(e=()=>{}){const n=Jt(e);yi(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function TG(e){return e.nodeType===e.ELEMENT_NODE}function $G(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 Am(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}const MG=wG,AG=PG,OG=EG,RG=MT,sC=AT,ni="2.0.0-beta.2";let V0={fonts:{draw:`https://unpkg.com/@tldraw/assets@${ni}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${ni}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${ni}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${ni}/fonts/IBMPlexMono-Medium.woff2`}};function DG(e){return b.useMemo(()=>e?{fonts:{...V0.fonts,...e==null?void 0:e.fonts}}:V0,[e])}const jG=["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 jl={...V0,icons:Object.fromEntries(jG.map(e=>[e,`https://unpkg.com/@tldraw/assets@${ni}/icons/icon/${e}.svg`])),translations:Object.fromEntries(vc.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${ni}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Aa.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${ni}/embed-icons/${e.type}.png`]))};function LG(e){return e?{fonts:Object.assign({...jl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...jl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...jl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...jl.translations},{...e==null?void 0:e.translations})}:jl}function NG(e,n){const t=he(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 zG=50;function FG(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=he(o.map(p=>e.getShape(p)));if(!s.length)return;const i=le.FromPoints(s.flatMap(p=>{const y=e.getShapeGeometry(p.id);return e.getShapeLocalTransform(p).applyToPoints(y.vertices)})),{padding:a=zG}=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 E(u,d).rot(r.rotation);e.batch(()=>{const p=o.map(y=>{const f=e.getShape(y);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 DT=b.createContext(null);function BG({assetUrls:e,children:n}){return g.jsx(DT.Provider,{value:e,children:n})}function aw(){const e=b.useContext(DT);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const K0={"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","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..."},Gi={locale:"en",label:"English",messages:K0};async function UG(e,n){if(!(await fetch(n.translations.en)).ok)return console.warn("No main translations found."),Gi;if(e==="en")return Gi;const r=vc.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),Gi;const s=await(await fetch(n.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),Gi;const i=[];for(const a in Gi.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,messages:{...Gi.messages,...s}}}const jT=b.createContext({}),HG=()=>b.useContext(jT),VG=Re(function({overrides:n,children:t}){const o=K().user.getLocale(),s=aw(),[i,a]=b.useState(()=>n&&n.en?{locale:"en",label:"English",messages:{...K0,...n.en}}:{locale:"en",label:"English",messages:K0});return b.useEffect(()=>{let l=!1;async function c(){const u=await UG(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(jT.Provider,{value:i,children:t})});function be(){const e=HG();return b.useCallback(function(t){return e.messages[t]??t},[e])}function KG(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 Hn=b.memo(function({small:n,invertIcon:t,icon:r,color:o,className:s,...i}){const a=aw(),l=a.icons[r]??a.icons["question-mark-circle"],c=b.useRef(null);return b.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:pe("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}})}),LT=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,NT=LT?"⌘":"Ctrl",zT=LT?"⌥":"Alt";function WG(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,NT).replace(/\?/g,zT).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function to(e){return"— "+e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,NT).replace(/\?/g,zT).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)}).join(" ")}function jf({children:e}){return g.jsx("kbd",{className:"tlui-kbd",children:WG(e).map((n,t)=>g.jsx("span",{children:n},t))})}const ae=b.forwardRef(function({label:n,icon:t,invertIcon:r,iconLeft:o,smallIcon:s,kbd:i,isChecked:a=!1,type:l,children:c,spinner:u,...d},h){const p=be(),y=n?p(n):"";return g.jsxs("button",{ref:h,draggable:!1,type:"button",...d,title:d.title??y,className:pe("tlui-button",`tlui-button__${l}`,d.className),children:[o&&g.jsx(Hn,{icon:o,className:"tlui-button__icon-left",small:!0}),c,n&&g.jsxs("span",{className:"tlui-button__label",draggable:!1,children:[y,a&&g.jsx(Hn,{icon:"check"})]}),i&&g.jsx(jf,{children:i}),t&&!u&&g.jsx(Hn,{icon:t,small:!!n||s,invertIcon:r}),u&&g.jsx(KG,{})]})}),GG=$A.useId||(()=>{});let YG=0;function To(e){const[n,t]=b.useState(GG());return yi(()=>{e||t(r=>r??String(YG++))},[e]),e||(n?`radix-${n}`:"")}const Om="focusScope.autoFocusOnMount",Rm="focusScope.autoFocusOnUnmount",iC={bubbles:!1,cancelable:!0},lw=b.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=b.useState(null),c=Jt(o),u=Jt(s),d=b.useRef(null),h=Ge(n,f=>l(f)),p=b.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;b.useEffect(()=>{if(r){let w=function(k){if(p.paused||!a)return;const I=k.target;a.contains(I)?d.current=I:Zo(d.current,{select:!0})},x=function(k){if(p.paused||!a)return;const I=k.relatedTarget;I!==null&&(a.contains(I)||Zo(d.current,{select:!0}))},C=function(k){if(document.activeElement===document.body)for(const _ of k)_.removedNodes.length>0&&Zo(a)};var f=w,m=x,S=C;document.addEventListener("focusin",w),document.addEventListener("focusout",x);const P=new MutationObserver(C);return a&&P.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",w),document.removeEventListener("focusout",x),P.disconnect()}}},[r,a,p.paused]),b.useEffect(()=>{if(a){lC.add(p);const f=document.activeElement;if(!a.contains(f)){const S=new CustomEvent(Om,iC);a.addEventListener(Om,c),a.dispatchEvent(S),S.defaultPrevented||(XG(eY(FT(a)),{select:!0}),document.activeElement===f&&Zo(a))}return()=>{a.removeEventListener(Om,c),setTimeout(()=>{const S=new CustomEvent(Rm,iC);a.addEventListener(Rm,u),a.dispatchEvent(S),S.defaultPrevented||Zo(f??document.body,{select:!0}),a.removeEventListener(Rm,u),lC.remove(p)},0)}}},[a,c,u,p]);const y=b.useCallback(f=>{if(!t&&!r||p.paused)return;const m=f.key==="Tab"&&!f.altKey&&!f.ctrlKey&&!f.metaKey,S=document.activeElement;if(m&&S){const w=f.currentTarget,[x,C]=qG(w);x&&C?!f.shiftKey&&S===C?(f.preventDefault(),t&&Zo(x,{select:!0})):f.shiftKey&&S===x&&(f.preventDefault(),t&&Zo(C,{select:!0})):S===w&&f.preventDefault()}},[t,r,p.paused]);return b.createElement(ze.div,Q({tabIndex:-1},i,{ref:h,onKeyDown:y}))});function XG(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(Zo(r,{select:n}),document.activeElement!==t)return}function qG(e){const n=FT(e),t=aC(n,e),r=aC(n.reverse(),e);return[t,r]}function FT(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 aC(e,n){for(const t of e)if(!ZG(t,{upTo:n}))return t}function ZG(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 QG(e){return e instanceof HTMLInputElement&&"select"in e}function Zo(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&QG(e)&&n&&e.select()}}const lC=JG();function JG(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=cC(e,n),e.unshift(n)},remove(n){var t;e=cC(e,n),(t=e[0])===null||t===void 0||t.resume()}}}function cC(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function eY(e){return e.filter(n=>n.tagName!=="A")}let Dm=0;function cw(){b.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:uC()),document.body.insertAdjacentElement("beforeend",(n=t[1])!==null&&n!==void 0?n:uC()),Dm++,()=>{Dm===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),Dm--}},[])}function uC(){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 BT(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 tY(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 Dh="right-scroll-bar-position",jh="width-before-scroll-bar",nY="with-scroll-bars-hidden",rY="--removed-body-scroll-bar-size";function jm(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function oY(e,n){var t=b.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 dC=new WeakMap;function sY(e,n){var t=oY(n||null,function(r){return e.forEach(function(o){return jm(o,r)})});return b.useLayoutEffect(function(){var r=dC.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||jm(a,null)}),s.forEach(function(a){o.has(a)||jm(a,i)})}dC.set(t,e)},[e]),t}function iY(e){return e}function aY(e,n){n===void 0&&(n=iY);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 lY(e){e===void 0&&(e={});var n=aY(null);return n.options=Gr({async:!0,ssr:!1},e),n}var UT=function(e){var n=e.sideCar,t=BT(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 b.createElement(r,Gr({},t))};UT.isSideCarExport=!0;function cY(e,n){return e.useMedium(n),UT}var HT=lY(),Lm=function(){},Lf=b.forwardRef(function(e,n){var t=b.useRef(null),r=b.useState({onScrollCapture:Lm,onWheelCapture:Lm,onTouchMoveCapture:Lm}),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,y=e.inert,f=e.allowPinchZoom,m=e.as,S=m===void 0?"div":m,w=BT(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),x=h,C=sY([t,n]),P=Gr(Gr({},w),o);return b.createElement(b.Fragment,null,u&&b.createElement(x,{sideCar:HT,removeScrollBar:c,shards:d,noIsolation:p,inert:y,setCallbacks:s,allowPinchZoom:!!f,lockRef:t}),i?b.cloneElement(b.Children.only(a),Gr(Gr({},P),{ref:C})):b.createElement(S,Gr({},P,{className:l,ref:C}),a))});Lf.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};Lf.classNames={fullWidth:jh,zeroRight:Dh};var uY=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function dY(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=uY();return n&&e.setAttribute("nonce",n),e}function hY(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 fY=function(){var e=0,n=null;return{add:function(t){e==0&&(n=dY())&&(hY(n,t),pY(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},gY=function(){var e=fY();return function(n,t){b.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},VT=function(){var e=gY(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},mY={left:0,top:0,right:0,gap:0},Nm=function(e){return parseInt(e||"",10)||0},yY=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[Nm(t),Nm(r),Nm(o)]},vY=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return mY;var n=yY(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])}},SY=VT(),wY=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(nY,` {
|
|
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(Dh,` {
|
|
204
|
+
right: `).concat(a,"px ").concat(r,`;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.`).concat(jh,` {
|
|
208
|
+
margin-right: `).concat(a,"px ").concat(r,`;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.`).concat(Dh," .").concat(Dh,` {
|
|
212
|
+
right: 0 `).concat(r,`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.`).concat(jh," .").concat(jh,` {
|
|
216
|
+
margin-right: 0 `).concat(r,`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
body {
|
|
220
|
+
`).concat(rY,": ").concat(a,`px;
|
|
221
|
+
}
|
|
222
|
+
`)},xY=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r,s=b.useMemo(function(){return vY(o)},[o]);return b.createElement(SY,{styles:wY(s,!n,o,t?"":"!important")})},W0=!1;if(typeof window<"u")try{var Td=Object.defineProperty({},"passive",{get:function(){return W0=!0,!0}});window.addEventListener("test",Td,Td),window.removeEventListener("test",Td,Td)}catch{W0=!1}var Yi=W0?{passive:!1}:!1,bY=function(e){return e.tagName==="TEXTAREA"},KT=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!bY(e)&&t[n]==="visible")},CY=function(e){return KT(e,"overflowY")},PY=function(e){return KT(e,"overflowX")},hC=function(e,n){var t=n;do{typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&(t=t.host);var r=WT(e,t);if(r){var o=GT(e,t),s=o[1],i=o[2];if(s>i)return!0}t=t.parentNode}while(t&&t!==document.body);return!1},EY=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},kY=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},WT=function(e,n){return e==="v"?CY(n):PY(n)},GT=function(e,n){return e==="v"?EY(n):kY(n)},IY=function(e,n){return e==="h"&&n==="rtl"?-1:1},_Y=function(e,n,t,r,o){var s=IY(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=GT(e,a),y=p[0],f=p[1],m=p[2],S=f-m-s*y;(y||S)&&WT(e,a)&&(d+=S,h+=y),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},$d=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},pC=function(e){return[e.deltaX,e.deltaY]},fC=function(e){return e&&"current"in e?e.current:e},TY=function(e,n){return e[0]===n[0]&&e[1]===n[1]},$Y=function(e){return`
|
|
223
|
+
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
224
|
+
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
225
|
+
`)},MY=0,Xi=[];function AY(e){var n=b.useRef([]),t=b.useRef([0,0]),r=b.useRef(),o=b.useState(MY++)[0],s=b.useState(function(){return VT()})[0],i=b.useRef(e);b.useEffect(function(){i.current=e},[e]),b.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var f=tY([e.lockRef.current],(e.shards||[]).map(fC),!0).filter(Boolean);return f.forEach(function(m){return m.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),f.forEach(function(m){return m.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=b.useCallback(function(f,m){if("touches"in f&&f.touches.length===2)return!i.current.allowPinchZoom;var S=$d(f),w=t.current,x="deltaX"in f?f.deltaX:w[0]-S[0],C="deltaY"in f?f.deltaY:w[1]-S[1],P,k=f.target,I=Math.abs(x)>Math.abs(C)?"h":"v";if("touches"in f&&I==="h"&&k.type==="range")return!1;var _=hC(I,k);if(!_)return!0;if(_?P=I:(P=I==="v"?"h":"v",_=hC(I,k)),!_)return!1;if(!r.current&&"changedTouches"in f&&(x||C)&&(r.current=P),!P)return!0;var $=r.current||P;return _Y($,m,f,$==="h"?x:C,!0)},[]),l=b.useCallback(function(f){var m=f;if(!(!Xi.length||Xi[Xi.length-1]!==s)){var S="deltaY"in m?pC(m):$d(m),w=n.current.filter(function(P){return P.name===m.type&&P.target===m.target&&TY(P.delta,S)})[0];if(w&&w.should){m.cancelable&&m.preventDefault();return}if(!w){var x=(i.current.shards||[]).map(fC).filter(Boolean).filter(function(P){return P.contains(m.target)}),C=x.length>0?a(m,x[0]):!i.current.noIsolation;C&&m.cancelable&&m.preventDefault()}}},[]),c=b.useCallback(function(f,m,S,w){var x={name:f,delta:m,target:S,should:w};n.current.push(x),setTimeout(function(){n.current=n.current.filter(function(C){return C!==x})},1)},[]),u=b.useCallback(function(f){t.current=$d(f),r.current=void 0},[]),d=b.useCallback(function(f){c(f.type,pC(f),f.target,a(f,e.lockRef.current))},[]),h=b.useCallback(function(f){c(f.type,$d(f),f.target,a(f,e.lockRef.current))},[]);b.useEffect(function(){return Xi.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:h}),document.addEventListener("wheel",l,Yi),document.addEventListener("touchmove",l,Yi),document.addEventListener("touchstart",u,Yi),function(){Xi=Xi.filter(function(f){return f!==s}),document.removeEventListener("wheel",l,Yi),document.removeEventListener("touchmove",l,Yi),document.removeEventListener("touchstart",u,Yi)}},[]);var p=e.removeScrollBar,y=e.inert;return b.createElement(b.Fragment,null,y?b.createElement(s,{styles:$Y(o)}):null,p?b.createElement(xY,{gapMode:"margin"}):null)}const OY=cY(HT,AY);var YT=b.forwardRef(function(e,n){return b.createElement(Lf,Gr({},e,{ref:n,sideCar:OY}))});YT.classNames=Lf.classNames;const uw=YT;var RY=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},qi=new WeakMap,Md=new WeakMap,Ad={},zm=0,XT=function(e){return e&&(e.host||XT(e.parentNode))},DY=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=XT(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})},jY=function(e,n,t,r){var o=DY(n,Array.isArray(e)?e:[e]);Ad[t]||(Ad[t]=new WeakMap);var s=Ad[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),y=p!==null&&p!=="false",f=(qi.get(h)||0)+1,m=(s.get(h)||0)+1;qi.set(h,f),s.set(h,m),i.push(h),f===1&&y&&Md.set(h,!0),m===1&&h.setAttribute(t,"true"),y||h.setAttribute(r,"true")}})};return u(n),a.clear(),zm++,function(){i.forEach(function(d){var h=qi.get(d)-1,p=s.get(d)-1;qi.set(d,h),s.set(d,p),h||(Md.has(d)||d.removeAttribute(r),Md.delete(d)),p||d.removeAttribute(t)}),zm--,zm||(qi=new WeakMap,qi=new WeakMap,Md=new WeakMap,Ad={})}},dw=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=n||RY(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),jY(r,o,t,"aria-hidden")):function(){return null}};const qT="Dialog",[ZT,ite]=so(qT),[LY,Vo]=ZT(qT),NY=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=b.useRef(null),l=b.useRef(null),[c=!1,u]=Ns({prop:r,defaultProp:o,onChange:s});return b.createElement(LY,{scope:n,triggerRef:a,contentRef:l,contentId:To(),titleId:To(),descriptionId:To(),open:c,onOpenChange:u,onOpenToggle:b.useCallback(()=>u(d=>!d),[u]),modal:i},t)},QT="DialogPortal",[zY,JT]=ZT(QT,{forceMount:void 0}),FY=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=Vo(QT,n);return b.createElement(zY,{scope:n,forceMount:t},b.Children.map(r,i=>b.createElement(jr,{present:t||s.open},b.createElement(Of,{asChild:!0,container:o},i))))},G0="DialogOverlay",BY=b.forwardRef((e,n)=>{const t=JT(G0,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=Vo(G0,e.__scopeDialog);return s.modal?b.createElement(jr,{present:r||s.open},b.createElement(UY,Q({},o,{ref:n}))):null}),UY=b.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Vo(G0,t);return b.createElement(uw,{as:mi,allowPinchZoom:!0,shards:[o.contentRef]},b.createElement(ze.div,Q({"data-state":t$(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),Kc="DialogContent",HY=b.forwardRef((e,n)=>{const t=JT(Kc,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=Vo(Kc,e.__scopeDialog);return b.createElement(jr,{present:r||s.open},s.modal?b.createElement(VY,Q({},o,{ref:n})):b.createElement(KY,Q({},o,{ref:n})))}),VY=b.forwardRef((e,n)=>{const t=Vo(Kc,e.__scopeDialog),r=b.useRef(null),o=Ge(n,t.contentRef,r);return b.useEffect(()=>{const s=r.current;if(s)return dw(s)},[]),b.createElement(e$,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())}))}),KY=b.forwardRef((e,n)=>{const t=Vo(Kc,e.__scopeDialog),r=b.useRef(!1),o=b.useRef(!1);return b.createElement(e$,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()}}))}),e$=b.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=Vo(Kc,t),l=b.useRef(null),c=Ge(n,l);return cw(),b.createElement(b.Fragment,null,b.createElement(lw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},b.createElement(Af,Q({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":t$(a.open)},i,{ref:c,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),WY="DialogTitle",GY=b.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Vo(WY,t);return b.createElement(ze.h2,Q({id:o.titleId},r,{ref:n}))});const YY="DialogClose",XY=b.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=Vo(YY,t);return b.createElement(ze.button,Q({type:"button"},r,{ref:n,onClick:se(e.onClick,()=>o.onOpenChange(!1))}))});function t$(e){return e?"open":"closed"}const qY=NY,ZY=FY,QY=BY,JY=HY;function Nf({className:e,children:n}){return g.jsx("div",{className:pe("tlui-dialog__header",e),children:n})}function zf({className:e,children:n}){return g.jsx(GY,{dir:"ltr",className:pe("tlui-dialog__header__title",e),children:n})}function Ff(){return g.jsx("div",{className:"tlui-dialog__header__close",children:g.jsx(XY,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:g.jsx(ae,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:g.jsx(Hn,{small:!0,icon:"cross-2"})})})})}function Wc({className:e,children:n,style:t}){return g.jsx("div",{className:pe("tlui-dialog__body",e),style:t,children:n})}function hw({className:e,children:n}){return g.jsx("div",{className:pe("tlui-dialog__footer",e),children:n})}const pw=b.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:y,value:f},m){const S=K(),w=b.useRef(null);b.useImperativeHandle(m,()=>w.current);const x=be(),C=b.useRef(a??""),P=b.useRef(a??""),[k,I]=b.useState(!1),_=b.useCallback(L=>{I(!0);const N=L.currentTarget;P.current=N.value,requestAnimationFrame(()=>{s&&N.select()})},[s]),$=b.useCallback(L=>{const N=L.currentTarget.value;P.current=N,u==null||u(N)},[u]),T=b.useCallback(L=>{switch(L.key){case"Enter":{L.currentTarget.blur(),bt(L),c==null||c(L.currentTarget.value);break}case"Escape":{L.currentTarget.value=C.current,L.currentTarget.blur(),bt(L),d==null||d(L.currentTarget.value);break}}},[c,d]),R=b.useCallback(L=>{I(!1);const N=L.currentTarget.value;h==null||h(N)},[h]);return b.useEffect(()=>{if(!S.environment.isIos)return;const L=window.visualViewport;if(k&&p&&L){const N=()=>{var D;(D=w.current)==null||D.scrollIntoView({block:"center"})};return L.addEventListener("resize",N),L.addEventListener("scroll",N),requestAnimationFrame(()=>{var D;(D=w.current)==null||D.scrollIntoView({block:"center"})}),()=>{L.removeEventListener("resize",N),L.removeEventListener("scroll",N)}}},[S,k,p]),g.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,t&&g.jsx("label",{children:x(t)}),o&&g.jsx(Hn,{icon:o,className:"tlui-icon-left",small:!0}),g.jsx("input",{ref:w,className:pe("tlui-input",n),type:"text",defaultValue:a,onKeyUp:T,onChange:$,onFocus:_,onBlur:R,autoFocus:i,placeholder:l,value:f}),r&&g.jsx(Hn,{icon:r,small:!!t})]})});function gC(e){return Kn.isValid(e)?{isValid:!0,hasProtocol:!0}:Kn.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const eX=Re(function({onClose:n}){const r=K().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?g.jsx(tX,{onClose:n,selectedShape:r}):null}),tX=Re(function({onClose:n,selectedShape:t}){const r=K(),o=be(),s=b.useRef(null);b.useEffect(()=>{requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[]);const i=b.useRef(t.props.url),[a,l]=b.useState(()=>{const y=gC(t.props.url),f=y.isValid===!0?y.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:f,safe:f,valid:!0}}),c=b.useCallback(y=>{const f=y.replace(/https?:\/\/(https?:\/\/)/,(w,x)=>x),m=gC(f),S=m.isValid===!0?m.hasProtocol?f:"https://"+f:"https://";l({actual:f,safe:S,valid:m.isValid})},[]),u=b.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),n())},[r,n]),d=b.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),n())},[r,n,a]),h=b.useCallback(()=>{n()},[n]);if(!t)return n(),null;const p=i.current&&!a.valid;return g.jsxs(g.Fragment,{children:[g.jsxs(Nf,{children:[g.jsx(zf,{children:o("edit-link-dialog.title")}),g.jsx(Ff,{})]}),g.jsx(Wc,{children:g.jsxs("div",{className:"tlui-edit-link-dialog",children:[g.jsx(pw,{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(hw,{className:"tlui-dialog__footer__actions",children:[g.jsx(ae,{type:"normal",onClick:h,onTouchEnd:h,children:o("edit-link-dialog.cancel")}),p?g.jsx(ae,{type:"danger",onTouchEnd:u,onClick:u,children:o("edit-link-dialog.clear")}):g.jsx(ae,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:o("edit-link-dialog.save")})]})]})}),n$=Re(function({onClose:n}){const t=K(),r=be(),o=aw(),[s,i]=b.useState(null),[a,l]=b.useState(""),[c,u]=b.useState(null),[d,h]=b.useState(!1),p=b.useRef(-1);return g.jsxs(g.Fragment,{children:[g.jsxs(Nf,{children:[g.jsx(zf,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),g.jsx(Ff,{})]}),s?g.jsxs(g.Fragment,{children:[g.jsxs(Wc,{className:"tlui-embed-dialog__enter",children:[g.jsx(pw,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autofocus:!0,onValueChange:y=>{l(y);const f=xo(y);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(Hn,{icon:"external-link",small:!0})]})]}):g.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),g.jsxs(hw,{className:"tlui-dialog__footer__actions",children:[g.jsx(ae,{type:"normal",onClick:()=>{i(null),u(null),l("")},label:"embed-dialog.back"}),g.jsx("div",{className:"tlui-embed__spacer"}),g.jsx(ae,{type:"normal",label:"embed-dialog.cancel",onClick:n}),g.jsx(ae,{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(Wc,{className:"tlui-embed-dialog__list",children:Aa.map(y=>g.jsx(ae,{type:"menu",onClick:()=>i(y),label:y.title,children:g.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})},y.type))})})]})});var fw={exports:{}};fw.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={},y={},f="",m="",S="",w=2,x=3,C=2,P=[],k=0,I=0,_;for(_=0;_<l.length;_+=1)if(f=l.charAt(_),Object.prototype.hasOwnProperty.call(p,f)||(p[f]=x++,y[f]=!0),m=S+f,Object.prototype.hasOwnProperty.call(p,m))S=m;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<C;d++)k=k<<1,I==c-1?(I=0,P.push(u(k)),k=0):I++;for(h=S.charCodeAt(0),d=0;d<8;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1}else{for(h=1,d=0;d<C;d++)k=k<<1|h,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=0;for(h=S.charCodeAt(0),d=0;d<16;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1}w--,w==0&&(w=Math.pow(2,C),C++),delete y[S]}else for(h=p[S],d=0;d<C;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1;w--,w==0&&(w=Math.pow(2,C),C++),p[m]=x++,S=String(f)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<C;d++)k=k<<1,I==c-1?(I=0,P.push(u(k)),k=0):I++;for(h=S.charCodeAt(0),d=0;d<8;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1}else{for(h=1,d=0;d<C;d++)k=k<<1|h,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=0;for(h=S.charCodeAt(0),d=0;d<16;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1}w--,w==0&&(w=Math.pow(2,C),C++),delete y[S]}else for(h=p[S],d=0;d<C;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1;w--,w==0&&(w=Math.pow(2,C),C++)}for(h=2,d=0;d<C;d++)k=k<<1|h&1,I==c-1?(I=0,P.push(u(k)),k=0):I++,h=h>>1;for(;;)if(k=k<<1,I==c-1){P.push(u(k));break}else I++;return P.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,y=3,f="",m=[],S,w,x,C,P,k,I,_={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)d[S]=S;for(x=0,P=Math.pow(2,2),k=1;k!=P;)C=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),x|=(C>0?1:0)*k,k<<=1;switch(x){case 0:for(x=0,P=Math.pow(2,8),k=1;k!=P;)C=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),x|=(C>0?1:0)*k,k<<=1;I=t(x);break;case 1:for(x=0,P=Math.pow(2,16),k=1;k!=P;)C=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),x|=(C>0?1:0)*k,k<<=1;I=t(x);break;case 2:return""}for(d[3]=I,w=I,m.push(I);;){if(_.index>l)return"";for(x=0,P=Math.pow(2,y),k=1;k!=P;)C=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),x|=(C>0?1:0)*k,k<<=1;switch(I=x){case 0:for(x=0,P=Math.pow(2,8),k=1;k!=P;)C=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),x|=(C>0?1:0)*k,k<<=1;d[p++]=t(x),I=p-1,h--;break;case 1:for(x=0,P=Math.pow(2,16),k=1;k!=P;)C=_.val&_.position,_.position>>=1,_.position==0&&(_.position=c,_.val=u(_.index++)),x|=(C>0?1:0)*k,k<<=1;d[p++]=t(x),I=p-1,h--;break;case 2:return m.join("")}if(h==0&&(h=Math.pow(2,y),y++),d[I])f=d[I];else if(I===p)f=w+w.charAt(0);else return null;m.push(f),d[p++]=w+f.charAt(0),h--,w=f,h==0&&(h=Math.pow(2,y),y++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(fw);var r$=fw.exports;async function nX(e,n,t){var S,w,x;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(C=>{if(c.set(C.id,We()),C.boundElements!==null)for(const P of C.boundElements)P.type==="text"&&d.add(P.id)});let h="a1";for(const C of r){if(d.has(C.id))continue;const P=c.get(C.id),k={id:P,typeName:"shape",parentId:l,index:h,x:C.x,y:C.y,rotation:0,isLocked:C.locked,opacity:rX(C.opacity),meta:{}};switch(C.angle!==0&&a.set(P,C.angle),C.groupIds&&C.groupIds.length>0?i.has(C.groupIds[0])?(S=i.get(C.groupIds[0]))==null||S.push(P):i.set(C.groupIds[0],[P]):u.push(P),C.type){case"rectangle":case"ellipse":case"diamond":{let I="",_="middle";if(C.boundElements!==null){for(const T of C.boundElements)if(T.type==="text"){const R=r.find(L=>L.id===T.id);R&&(I=R.text,_=mC[R.textAlign])}}const $=C.backgroundColor==="transparent"?C.strokeColor:C.backgroundColor;s.shapes.push({...k,type:"geo",props:{geo:C.type,url:C.link??"",w:C.width,h:C.height,size:Od[C.strokeWidth]??"draw",color:Ll[$]??"black",text:I,align:_,dash:Rd(C),fill:uX(C)}});break}case"freedraw":{s.shapes.push({...k,type:"draw",props:{dash:Rd(C),size:Od[C.strokeWidth],color:Ll[C.strokeColor]??"black",segments:[{type:"free",points:C.points.map(([I,_,$=.5])=>({x:I,y:_,z:$}))}]}});break}case"line":{const I=C.points[0],_=C.points[C.points.length-1],$=uE(C.points.length);s.shapes.push({...k,type:"line",props:{dash:Rd(C),size:Od[C.strokeWidth],color:Ll[C.strokeColor]??"black",spline:C.roundness?"cubic":"line",handles:{start:{id:"start",type:"vertex",index:$[0],x:I[0],y:I[1]},end:{id:"end",type:"vertex",index:$[$.length-1],x:_[0],y:_[1]},...Object.fromEntries(C.points.slice(1,-1).map(([T,R],L)=>{const N=Ne();return[N,{id:N,type:"vertex",index:$[L+1],x:T,y:R}]}))}}});break}case"arrow":{let I="";if(C.boundElements!==null){for(const L of C.boundElements)if(L.type==="text"){const N=r.find(D=>D.id===L.id);N&&(I=N.text)}}const _=C.points[0],$=C.points[C.points.length-1],T=c.get((w=C.startBinding)==null?void 0:w.elementId),R=c.get((x=C.endBinding)==null?void 0:x.elementId);s.shapes.push({...k,type:"arrow",props:{text:I,bend:cX(C,_,$),dash:Rd(C),size:Od[C.strokeWidth]??"m",color:Ll[C.strokeColor]??"black",start:T?{type:"binding",boundShapeId:T,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:_[0],y:_[1]},end:R?{type:"binding",boundShapeId:R,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:$[0],y:$[1]},arrowheadEnd:yC[C.endArrowhead]??"none",arrowheadStart:yC[C.startArrowhead]??"none"}});break}case"text":{const{size:I,scale:_}=sX(C.fontSize);s.shapes.push({...k,type:"text",props:{size:I,scale:_,font:iX[C.fontFamily]??"draw",color:Ll[C.strokeColor]??"black",text:C.text,align:mC[C.textAlign]}});break}case"image":{const I=o[C.fileId];if(!I)break;const _=Zs.createId();s.assets.push({id:_,typeName:"asset",type:"image",props:{w:C.width,h:C.height,name:C.id??"Untitled",isAnimated:!1,mimeType:I.mimeType,src:I.dataURL},meta:{}}),s.shapes.push({...k,type:"image",props:{w:C.width,h:C.height,assetId:_}})}}h=yo(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 C of i.values())if(C.length>1){e.groupShapes(C);const P=e.getShape(C[0]);P!=null&&P.parentId&&tr(P.parentId)&&u.push(P.parentId)}for(const[C,P]of a)e.select(C),e.rotateShapesBy([C],P);const y=he(u.map(C=>e.getShape(C))),f=le.Common(y.map(C=>e.getShapePageBounds(C))),m=e.getViewportPageBounds().center;e.updateShapes(y.map(C=>{const P={x:(C.x??0)-(f.x+f.w/2),y:(C.y??0)-(f.y+f.h/2)};return{id:C.id,type:C.type,x:m.x+P.x,y:m.y+P.y}})),e.setSelectedShapes(u)}const rX=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},Od={1:"s",2:"m",3:"l",4:"xl"},oX={16:"s",20:"m",28:"l",36:"xl"};function sX(e){const n=oX[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 iX={1:"draw",2:"sans",3:"mono"},Ll={"#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"},aX={solid:"draw",dashed:"dashed",dotted:"dotted"},lX={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},mC={left:"start",center:"middle",right:"end"},yC={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function cX(e,n,t){let r=0;if(e.points.length>2){const o=new E(n[0],n[1]),s=new E(t[0],t[1]),i=new E(e.points[1][0],e.points[1][1]),a=E.Sub(s,o),l=E.Per(a),c=E.Med(s,o),u=E.Sub(c,l),d=E.Add(c,l),h=E.NearestPointOnLineSegment(u,d,i,!1);r=E.Dist(h,c),E.Clockwise(h,s,c)&&(r*=-1)}return r}const Rd=e=>{let n=aX[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},uX=e=>e.backgroundColor==="transparent"?"none":lX[e.fillStyle]??"solid";async function o$(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 dX(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 Y0(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"),o$(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 s$=()=>{},i$=b.createContext({});function hX({onEvent:e,children:n}){return g.jsx(i$.Provider,{value:e??s$,children:n})}function al(){return b.useContext(i$)??s$}function pX(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const fX=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},gX=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 KP(n)},mX=e=>/^<svg/.test(e),yX=["input","select","textarea"];function Lh(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||yX.indexOf(n.tagName.toLowerCase())>-1)}async function Fm(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 vX=e=>e.types.find(n=>n.match(/^image\//)),Bm=(e,n,t,r)=>{const o=gX(n);if(o)for(const s of o)Y0(e,s,t);else fX(n)?Y0(e,n,t):mX(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}))},SX=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}}l$(e,r,t)},a$=async(e,n,t)=>{const r=[];for(const o of n){if(vX(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=>Fm(i).then(s)))}),o.types.includes("text/uri-list")&&r.push({type:"url",source:new Promise(s=>o.getType("text/uri-list").then(i=>Fm(i).then(s)))}),o.types.includes("text/plain")&&r.push({type:"text",source:new Promise(s=>o.getType("text/plain").then(i=>Fm(i).then(s)))})}return await l$(e,r,t)};async function l$(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 o$(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=r$.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"){dX(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){nX(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");Bm(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){Bm(e,pX(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Y0(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){Bm(e,s.data,t,o);return}}const Fp=e=>{var r;const n=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=r$.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(d5);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 wX(){const e=K(),n=al(),t=b.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(Fp(e),n("copy",{source:i}))},[e,n]),r=b.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(Fp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=b.useCallback(async function(i,a,l){e.getEditingShapeId()!==null||Lh(e)||(Array.isArray(i)&&i[0]instanceof ClipboardItem?(a$(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 xX(){const e=K(),n=al(),t=Y("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);b.useEffect(()=>{if(!t)return;const r=()=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Lh(e)||(Fp(e),n("copy",{source:"kbd"}))};function o(){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Lh(e)||(Fp(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||Lh(e)||(l.clipboardData&&!e.inputs.shiftKey?SX(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&a$(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 bX(e,n,t){const{type:r,quality:o,scale:s}=t,i=+e.getAttribute("width"),a=+e.getAttribute("height");let l=i*s,c=a*s;const u=await c$(e),d=URL.createObjectURL(new Blob([u],{type:"image/svg+xml"})),h=await Ek();if(i>h.maxWidth&&(l=h.maxWidth,c=l/i*a),a>h.maxHeight&&(c=h.maxHeight,l=c/a*i),l*c>h.maxArea){const S=Math.sqrt(h.maxArea/(l*c));l*=S,c*=S}l=Math.floor(l),c=Math.floor(c);const p=l/i,y=await new Promise(S=>{const w=new Image;w.crossOrigin="anonymous",w.onload=async()=>{n&&await new Promise(P=>setTimeout(P,250));const x=document.createElement("canvas"),C=x.getContext("2d");x.width=l,x.height=c,C.imageSmoothingEnabled=!0,C.imageSmoothingQuality="high",C.drawImage(w,0,0,l,c),URL.revokeObjectURL(d),S(x)},w.onerror=()=>{S(null)},w.src=d});if(!y)return null;const f=await new Promise(S=>y.toBlob(w=>{(!w||He.throwToBlob.get())&&S(null),S(w)},"image/"+r,o));if(!f)return null;const m=new DataView(await f.arrayBuffer());return Kr.setPhysChunk(m,p,{type:"image/"+r})}async function c$(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(" ","").replaceAll(/((\s|")[0-9]*\.[0-9]{2})([0-9]*)(\b|"|\))/g,"$1")}async function u$(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 X0(e,n,t,r={}){switch(t){case"svg":return c$(await u$(e,n,r));case"json":{const o=e.getContentFromCurrentPage(n);return JSON.stringify(o)}default:Wa(t)}}async function d$(e,n,t,r={}){switch(t){case"svg":return new Blob([await X0(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await X0(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await bX(await u$(e,n,r),e.environment.isSafari,{type:t,quality:1,scale:2});if(!o)throw new Error("Could not construct image.");return o}default:Wa(t)}}const CX={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function PX(e,n,t,r={}){return{blobPromise:d$(e,n,t,r),mimeType:CX[t]}}function EX(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}=PX(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 kX(async()=>X0(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Wa(t)}}async function kX(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}const h$=b.createContext({});function IX({children:e}){const[n,t]=b.useState([]),r=b.useCallback(i=>{const a=i.id??Ne();return t(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=b.useCallback(i=>(t(a=>a.filter(l=>l.id!==i)),i),[]),s=b.useCallback(()=>{t(()=>[])},[]);return g.jsx(h$.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})}function io(){const e=b.useContext(h$);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}function _X(){const e=K(),{addToast:n}=io(),t=be();return b.useCallback((r,o="svg")=>{EX(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 p$=b.createContext({});function TX({children:e}){const n=K(),t=al(),[r,o]=b.useState([]),s=b.useCallback(c=>{const u=c.id??Ne();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=b.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=b.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=b.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(p$.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function _i(){const e=b.useContext(p$);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}async function f$(e,n,t="png",r={}){let o=`shapes at ${vC()}`;if(n.length===1){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?o=a.props.name??"frame":o=`${a.id.replace(/:/,"_")} at ${vC()}`}o+=`.${t}`;const s=await d$(e,n,t,r),i=new File([s],o,{type:s.type});$X(i)}function vC(){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 $X(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function MX(){const e=K(),{addToast:n}=io(),t=be();return b.useCallback((r,o="png")=>{f$(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 g$(){const e=K(),n=b.useRef();return b.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]),b.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}function AX(){const e=K(),n=b.useRef(null),t=b.useRef(null);return b.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,w)=>{S&&(S.innerHTML=""),w&&document.head.contains(w)&&document.head.removeChild(w),S&&document.body.contains(S)&&document.body.removeChild(S)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${Ne()}`;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(S,w,x){try{o.innerHTML+=`<div class="${a}__item">
|
|
299
|
+
<div class="${a}__item__header">
|
|
300
|
+
${S.replace(/</g,"<").replace(/>/g,">")}
|
|
301
|
+
</div>
|
|
302
|
+
<div class="${a}__item__main">
|
|
303
|
+
${x.outerHTML}
|
|
304
|
+
</div>
|
|
305
|
+
<div class="${a}__item__footer ${a}__item__footer__${w?"":"hide"}">
|
|
306
|
+
${w??""}
|
|
307
|
+
</div>
|
|
308
|
+
</div>`}catch(C){console.error(C)}}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(),y=e.getPages(),m={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvg(h,m);if(S){const w=y.find(x=>x.id===p);u(`tldraw — ${w==null?void 0:w.name}`,null,S),d()}}else{const S=e.getCurrentPage(),w=await e.getSvg(e.getSortedChildIdsForParent(S.id),m);w&&(u(`tldraw — ${S.name}`,null,w),d())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const m$=b.createContext({});function OX(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function RX({overrides:e,children:n}){const t=K(),{addDialog:r,clearDialogs:o}=_i(),{clearToasts:s}=io(),i=g$(),a=AX(),{cut:l,copy:c,paste:u}=wX(),d=_X(),h=MX(),p=al(),y=b.useMemo(()=>{function f(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function m(){return t.getSelectedShapeIds().length>0}const w=OX([{id:"edit-link",label:"action.edit-link",icon:"link",readonlyOk:!1,onSelect(x){m()&&(f()||(p("edit-link",{source:x}),t.mark("edit-link"),r({component:eX})))}},{id:"insert-embed",label:"action.insert-embed",readonlyOk:!1,kbd:"$i",onSelect(x){p("insert-embed",{source:x}),r({component:n$})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",readonlyOk:!1,onSelect(x){p("insert-media",{source:x}),i()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",readonlyOk:!1,onSelect(x){p("undo",{source:x}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",readonlyOk:!1,onSelect(x){p("redo",{source:x}),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(x){p("export-as",{format:"svg",source:x}),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(x){p("export-as",{format:"png",source:x}),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(x){p("export-as",{format:"json",source:x}),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(x){p("copy-as",{format:"svg",source:x}),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(x){p("copy-as",{format:"png",source:x}),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(x){p("copy-as",{format:"json",source:x}),d(t.getSelectedShapeIds(),"json")}},{id:"toggle-auto-size",label:"action.toggle-auto-size",readonlyOk:!1,onSelect(x){m()&&(f()||(p("toggle-auto-size",{source:x}),t.mark("toggling auto size"),t.updateShapes(t.getSelectedShapes().filter(C=>t.isShapeOfType(C,"text")&&C.props.autoSize===!1).map(C=>({id:C.id,type:C.type,props:{...C.props,w:8,autoSize:!0}})))))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(x){p("open-embed-link",{source:x});const C=t.getSelectedShapeIds(),P="No embed shapes selected";if(C.length!==1){console.error(P);return}const k=t.getShape(C[0]);if(!k||!t.isShapeOfType(k,"embed")){console.error(P);return}fL(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(x){var C,P;if(((C=t.root.getCurrent())==null?void 0:C.id)!=="zoom"&&(p("zoom-tool",{source:x}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const k=t.root.getCurrent();k&&((P=k.getCurrent())==null?void 0:P.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",readonlyOk:!1,onSelect(x){m()&&(f()||t.batch(()=>{p("convert-to-bookmark",{source:x});const C=t.getSelectedShapes(),P=[],k=[];for(const I of C){if(!I||!t.isShapeOfType(I,"embed")||!I.props.url)continue;const _=new E(I.x,I.y);_.rot(-I.rotation),_.add(new E(I.props.w/2-300/2,I.props.h/2-320/2)),_.rot(I.rotation);const $={id:We(),type:"bookmark",rotation:I.rotation,x:_.x,y:_.y,opacity:1,props:{url:I.props.url}};P.push($),k.push(I.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(k),t.createShapes(P)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",readonlyOk:!1,onSelect(x){m()&&(f()||(p("convert-to-embed",{source:x}),t.batch(()=>{const C=t.getSelectedShapeIds(),P=he(C.map(_=>t.getShape(_))),k=[],I=[];for(const _ of P){if(!t.isShapeOfType(_,"bookmark"))continue;const{url:$}=_.props,T=xo(_.props.url);if(!T||!T.definition)continue;const{width:R,height:L}=T.definition,N=new E(_.x,_.y);N.rot(-_.rotation),N.add(new E(_.props.w/2-R/2,_.props.h/2-L/2)),N.rot(_.rotation);const D={id:We(),type:"embed",x:N.x,y:N.y,rotation:_.rotation,props:{url:$,w:R,h:L}};k.push(D),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(x){if(!m()||f())return;p("duplicate-shapes",{source:x});const C=t.getSelectedShapeIds(),P=le.Common(he(C.map(I=>t.getShapePageBounds(I)))),k=t.getInstanceState().canMoveCamera?{x:P.width+10,y:0}:{x:16/t.getZoomLevel(),y:16/t.getZoomLevel()};t.mark("duplicate shapes"),t.duplicateShapes(C,k)}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",readonlyOk:!1,onSelect(x){m()&&(f()||(p("ungroup-shapes",{source:x}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",readonlyOk:!1,onSelect(x){if(!m()||f())return;p("group-shapes",{source:x});const C=t.getOnlySelectedShape();C&&t.isShapeOfType(C,"group")?(t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())):(t.mark("group"),t.groupShapes(t.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",readonlyOk:!1,onSelect(x){if(!m())return;p("remove-frame",{source:x});const C=t.getSelectedShapes();C.length>0&&C.every(P=>t.isShapeOfType(P,"frame"))&&(t.mark("remove-frame"),NG(t,C.map(P=>P.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",readonlyOk:!1,onSelect(x){if(!m())return;p("fit-frame-to-content",{source:x});const C=t.getOnlySelectedShape();C&&t.isShapeOfType(C,"frame")&&(t.mark("fit-frame-to-content"),FG(t,C.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",readonlyOk:!1,onSelect(x){m()&&(f()||(p("align-shapes",{operation:"left",source:x}),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(x){m()&&(f()||(p("align-shapes",{operation:"center-horizontal",source:x}),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(x){m()&&(f()||(p("align-shapes",{operation:"right",source:x}),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(x){m()&&(f()||(p("align-shapes",{operation:"center-vertical",source:x}),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(x){m()&&(f()||(p("align-shapes",{operation:"top",source:x}),t.mark("align top"),t.alignShapes(t.getSelectedShapeIds(),"top")))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",readonlyOk:!1,onSelect(x){m()&&(f()||(p("align-shapes",{operation:"bottom",source:x}),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(x){m()&&(f()||(p("distribute-shapes",{operation:"horizontal",source:x}),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(x){m()&&(f()||(p("distribute-shapes",{operation:"vertical",source:x}),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(x){m()&&(f()||(p("stretch-shapes",{operation:"horizontal",source:x}),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(x){m()&&(f()||(p("stretch-shapes",{operation:"vertical",source:x}),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(x){m()&&(f()||(p("flip-shapes",{operation:"horizontal",source:x}),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(x){m()&&(f()||(p("flip-shapes",{operation:"vertical",source:x}),t.mark("flip vertical"),t.flipShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"pack",label:"action.pack",icon:"pack",readonlyOk:!1,onSelect(x){m()&&(f()||(p("pack-shapes",{source:x}),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(x){m()&&(f()||(p("stack-shapes",{operation:"vertical",source:x}),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(x){m()&&(f()||(p("stack-shapes",{operation:"horizontal",source:x}),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(x){m()&&(f()||(p("reorder-shapes",{operation:"toFront",source:x}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",readonlyOk:!1,onSelect(x){m()&&(f()||(p("reorder-shapes",{operation:"forward",source:x}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",readonlyOk:!1,onSelect(x){m()&&(f()||(p("reorder-shapes",{operation:"backward",source:x}),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(x){m()&&(f()||(p("reorder-shapes",{operation:"toBack",source:x}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",readonlyOk:!1,onSelect(x){m()&&(f()||(t.mark("cut"),l(x)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(x){m()&&(f()||c(x))}},{id:"paste",label:"action.paste",kbd:"$v",readonlyOk:!1,onSelect(x){var C;(C=navigator.clipboard)==null||C.read().then(P=>{u(P,x,x==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(x){t.batch(()=>{f()||(p("select-all-shapes",{source:x}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(x){m()&&(f()||(p("select-none-shapes",{source:x}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",readonlyOk:!1,onSelect(x){m()&&(f()||(p("delete-shapes",{source:x}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",readonlyOk:!1,onSelect(x){if(!m()||f())return;p("rotate-cw",{source:x}),t.mark("rotate-cw");const C=t.getSelectionRotation()%(Ve/2),P=Ql(C,0)||Ql(C,Ve/2);t.rotateShapesBy(t.getSelectedShapeIds(),Ve/2-(P?0:C))}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",readonlyOk:!1,onSelect(x){if(!m()||f())return;p("rotate-ccw",{source:x}),t.mark("rotate-ccw");const C=t.getSelectionRotation()%(Ve/2),P=Ql(C,0);t.rotateShapesBy(t.getSelectedShapeIds(),P?-(Ve/2):-C)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(x){p("zoom-in",{source:x}),t.zoomIn(t.getViewportScreenCenter(),{duration:wo})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(x){p("zoom-out",{source:x}),t.zoomOut(t.getViewportScreenCenter(),{duration:wo})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(x){p("reset-zoom",{source:x}),t.resetZoom(t.getViewportScreenCenter(),{duration:wo})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(x){p("zoom-to-fit",{source:x}),t.zoomToFit({duration:wo})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(x){m()&&(f()||(p("zoom-to-selection",{source:x}),t.zoomToSelection({duration:wo})))}},{id:"toggle-snap-mode",label:"action.toggle-snap-mode",menuLabel:"action.toggle-snap-mode.menu",readonlyOk:!1,onSelect(x){p("toggle-snap-mode",{source:x}),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(x){p("toggle-dark-mode",{source:x}),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(x){p("toggle-reduce-motion",{source:x}),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(x){p("toggle-edge-scrolling",{source:x}),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(x){p("toggle-transparent",{source:x}),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(x){p("toggle-tool-lock",{source:x}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",readonlyOk:!1,onSelect(x){p("unlock-all",{source:x});const C=[];for(const P of t.getCurrentPageShapes())P.isLocked&&C.push({id:P.id,type:P.type,isLocked:!1});C.length>0&&t.updateShapes(C)}},{id:"toggle-focus-mode",label:"action.toggle-focus-mode",menuLabel:"action.toggle-focus-mode.menu",readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(x){requestAnimationFrame(()=>{t.batch(()=>{p("toggle-focus-mode",{source:x}),o(),s(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:"action.toggle-grid",menuLabel:"action.toggle-grid.menu",readonlyOk:!0,kbd:"$'",onSelect(x){p("toggle-grid-mode",{source:x}),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(x){p("toggle-debug-mode",{source:x}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(x){p("print",{source:x}),a()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(x){p("exit-pen-mode",{source:x}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(x){p("stop-following",{source:x}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(x){p("zoom-to-content",{source:x}),t.zoomToContent()}},{id:"toggle-lock",label:"action.toggle-lock",readonlyOk:!1,kbd:"!l",onSelect(x){t.mark("locking"),p("toggle-lock",{source:x}),t.toggleLock(t.getSelectedShapeIds())}}]);return e?e(t,w,void 0):w},[t,p,e,r,i,h,d,l,c,u,o,s,a]);return g.jsx(m$.Provider,{value:y,children:n})}function nn(){const e=b.useContext(m$);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function Bf(e){return e.filter(n=>n!=null&&n!==!1)}function ve(e,...n){const t=Bf(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=Bf(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 gw(e,n={}){const{readonlyOk:t=!0,disabled:r=!1}=n;return{id:e,type:"custom",disabled:r,readonlyOk:t}}function B(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 DX(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 y$=()=>{const e=K();return Y("threeStackableItems",()=>DX(e).length>2,[e])};function jX(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 mw=()=>{const e=K();return Y("allowGroup",()=>jX(e).length>1,[e])},yw=()=>{const e=K();return Y("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},v$=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read,Um=[0,390,428,468,580,640,840,1023],S$=ne.createContext(0);function LX({forceMobile:e=!1,children:n}){const t=K(),r=Y("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?3:Um.length-1;for(let i=0;i<s;i++)if(o>Um[i]&&o<=Um[i+1])return i;return s},[t]);return g.jsx(S$.Provider,{value:r,children:n})}function fr(){return b.useContext(S$)}function vw(){const e=K();return Y("hasLinkShapeSelected",()=>{const n=e.getSelectedShapes();return n.length===1&&"url"in n[0].props&&n[0].type!=="embed"},[e])}const w$=ne.createContext({}),NX=({overrides:e,children:n})=>{const t=K(),r=nn(),o=Y("selected count",()=>t.getSelectedShapeIds().length,[t]),s=o>0,i=o>1,a=o>2,l=y$(),c=mw(),u=yw(),d=vw(),h=fr(),p=Y("zoom is 1",()=>t.getZoomLevel()===1,[t]),y=b.useMemo(()=>{const f=[B(r["align-left"],{disabled:!i}),B(r["align-center-horizontal"],{disabled:!i}),B(r["align-right"],{disabled:!i}),B(r["stretch-horizontal"],{disabled:!i}),B(r["align-top"],{disabled:!i}),B(r["align-center-vertical"],{disabled:!i}),B(r["align-bottom"],{disabled:!i}),B(r["stretch-vertical"],{disabled:!i}),B(r["distribute-horizontal"],{disabled:!a}),B(r["distribute-vertical"],{disabled:!a}),B(r["stack-horizontal"],{disabled:!l}),B(r["stack-vertical"],{disabled:!l}),B(r["send-to-back"],{disabled:!s}),B(r["send-backward"],{disabled:!s}),B(r["bring-forward"],{disabled:!s}),B(r["bring-to-front"],{disabled:!s}),h<5?B(r["zoom-to-100"],{disabled:!!p}):B(r["rotate-ccw"],{disabled:!s}),B(r["rotate-cw"],{disabled:!s}),B(r["edit-link"],{disabled:!d}),c?B(r.group,{disabled:!i}):u?B(r.ungroup):B(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(w$.Provider,{value:y,children:n})};function zX(){const e=ne.useContext(w$);if(!e)throw new Error("useActionsMenuSchema must be used inside of a ActionsMenuSchemaProvider.");return e}function FX(){const e=K();return Y("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 x$(){const e=K();return Y("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}const b$=ne.createContext({}),BX=Re(function({overrides:n,children:t}){var _;const r=K(),o=nn(),s=x$(),i=FX(),a=r.getSelectedShapes(),l=a.length,c=l>0,u=l>1,d=l>2,h=y$(),p=Y("atLeastOneShapeOnPage",()=>r.getCurrentPageShapeIds().size>0,[]),y=Y("isTransparentBg",()=>r.getInstanceState().exportBackground,[]),f=mw(),m=yw(),S=!!((_=window.navigator.clipboard)!=null&&_.write),w=vw(),x=r.getOnlySelectedShape(),C=c&&a.every($=>r.isShapeOfType($,"frame")),P=x&&r.isShapeOfType(x,"frame")&&r.getSortedChildIdsForParent(x).length>0,k=x&&r.isShapeOrAncestorLocked(x),I=b.useMemo(()=>{let $=Bf([ve("selection",s&&B(o["toggle-auto-size"]),w&&!k&&B(o["edit-link"]),c&&!k&&B(o.duplicate),f&&!k&&B(o.group),m&&!k&&B(o.ungroup),C&&!k&&B(o["remove-frame"]),P&&!k&&B(o["fit-frame-to-content"]),c&&B(o["toggle-lock"])),ve("modify",(u||i)&&Vr("arrange","context-menu.arrange",u&&ve("align",B(o["align-left"]),B(o["align-center-horizontal"]),B(o["align-right"]),B(o["align-top"]),B(o["align-center-vertical"]),B(o["align-bottom"])),d&&ve("distribute",B(o["distribute-horizontal"]),B(o["distribute-vertical"])),u&&ve("stretch",B(o["stretch-horizontal"]),B(o["stretch-vertical"])),i&&!k&&ve("flip",B(o["flip-horizontal"]),B(o["flip-vertical"])),u&&ve("order",B(o.pack,{disabled:!u}),h&&B(o["stack-vertical"]),h&&B(o["stack-horizontal"]))),c&&!k&&Vr("reorder","context-menu.reorder",ve("reorder",B(o["bring-to-front"]),B(o["bring-forward"]),B(o["send-backward"]),B(o["send-to-back"]))),c&&!k&&gw("MOVE_TO_PAGE_MENU",{readonlyOk:!1})),ve("clipboard-group",c&&!k&&B(o.cut),c&&B(o.copy),v$&&B(o.paste)),p&&ve("conversions",Vr("copy-as","context-menu.copy-as",ve("copy-as-group",B(o["copy-as-svg"]),S&&B(o["copy-as-png"]),B(o["copy-as-json"])),ve("export-bg",B(o["toggle-transparent"],{checked:!y}))),Vr("export-as","context-menu.export-as",ve("export-as-group",B(o["export-as-svg"]),B(o["export-as-png"]),B(o["export-as-json"])),ve("export-bg,",B(o["toggle-transparent"],{checked:!y})))),p&&ve("set-selection-group",B(o["select-all"]),c&&B(o["select-none"])),c&&!k&&ve("delete-group",B(o.delete))]);return n&&($=n(r,$,{actions:o,oneSelected:c,twoSelected:u,threeSelected:d,showAutoSizeToggle:s,showUngroup:m,onlyFlippableShapeSelected:i})),$},[r,n,o,c,u,d,s,i,p,h,f,m,C,P,S,w,y,k]);return g.jsx(b$.Provider,{value:I,children:t})});function C$(){const e=ne.useContext(b$);if(!e)throw new Error("useContextMenuSchema must be used inside of a TLUiContextMenuSchemaProvider.");return e}const P$=b.createContext({});function UX({overrides:e,children:n}){const t=K(),r=al(),{addDialog:o}=_i(),s=g$(),i=b.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"})}},...[...Yr.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,[Yr.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:n$}),r("select-tool",{source:c,id:"embed"})}}];a.push({id:"highlight",label:"tool.highlight",readonlyOk:!0,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(P$.Provider,{value:i,children:n})}function Sw(){const e=b.useContext(P$);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const E$=ne.createContext({}),HX=Re(function({overrides:n,children:t}){const r=K(),o=Sw(),s=nn(),i=b.useMemo(()=>{const a=he([ve("shortcuts-dialog.tools",B(s["toggle-tool-lock"]),B(o.select),B(o.draw),B(o.eraser),B(o.hand),B(o.rectangle),B(o.ellipse),B(o.arrow),B(o.line),B(o.text),B(o.frame),B(o.note),B(o.laser)),ve("shortcuts-dialog.file",B(s["insert-media"]),B(s.print)),ve("shortcuts-dialog.preferences",B(s["toggle-dark-mode"]),B(s["toggle-focus-mode"]),B(s["toggle-grid"])),ve("shortcuts-dialog.edit",B(s.undo),B(s.redo),B(s.cut),B(s.copy),B(s.paste),B(s["select-all"]),B(s.delete),B(s.duplicate),B(s["export-as-svg"]),B(s["export-as-png"])),ve("shortcuts-dialog.view",B(s["zoom-in"]),B(s["zoom-out"]),B(s["zoom-to-100"]),B(s["zoom-to-fit"]),B(s["zoom-to-selection"])),ve("shortcuts-dialog.transform",B(s["bring-to-front"]),B(s["bring-forward"]),B(s["send-backward"]),B(s["send-to-back"]),B(s.group),B(s.ungroup),B(s["flip-horizontal"]),B(s["flip-vertical"]),B(s["align-top"]),B(s["align-center-vertical"]),B(s["align-bottom"]),B(s["align-left"]),B(s["align-center-horizontal"]),B(s["align-right"]))]);return n?n(r,a,{tools:o,actions:s}):a},[r,n,s,o]);return g.jsx(E$.Provider,{value:i,children:t})});function VX(){const e=ne.useContext(E$);if(!e)throw new Error("Shortcuts must be used inside of a ShortcutsProvider.");return e}const KX=()=>{const e=be(),n=pr(),t=VX();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(jf,{children:l})})]},s)}}}return g.jsxs(g.Fragment,{children:[g.jsxs(Nf,{className:"tlui-shortcuts-dialog__header",children:[g.jsx(zf,{children:e("shortcuts-dialog.title")}),g.jsx(Ff,{})]}),g.jsx(Wc,{className:"tlui-shortcuts-dialog__body",children:t.map(r)}),g.jsx("div",{className:"tlui-dialog__scrim"})]})};function k$(){const e=K();return{languages:vc,currentLanguage:e.user.getLocale()}}const I$=ne.createContext({}),WX=Re(function({overrides:n,children:t}){const r=K(),o=nn(),s=r.getSelectedShapeIds().length,i=s>0,a=s>1,l=s>2,{languages:c,currentLanguage:u}=k$(),{addDialog:d}=_i(),h=b.useMemo(()=>{const p=he([ve("top",gw("LANGUAGE_MENU",{readonlyOk:!0}),B({id:"keyboard-shortcuts",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect(){d({component:KX})}}))]);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(I$.Provider,{value:h,children:t})});function GX(){const e=ne.useContext(I$);if(!e)throw new Error("useHelpMenuSchema must be used inside of a helpTLUiMenuSchemaProvider.");return e}function _$(){const e=K();return Y("useCanRedo",()=>e.getCanRedo(),[e])}function T$(){const e=K();return Y("useCanUndo",()=>e.getCanUndo(),[e])}const $$=ne.createContext({});function YX({overrides:e,children:n}){var F;const t=K(),r=nn(),s=fr()<5,i=Y("isDarkMode",()=>t.user.getIsDarkMode(),[t]),a=Y("animationSpeed",()=>t.user.getAnimationSpeed(),[t]),l=Y("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]),c=Y("isGridMode",()=>t.getInstanceState().isGridMode,[t]),u=Y("isSnapMode",()=>t.user.getIsSnapMode(),[t]),d=Y("isToolLock",()=>t.getInstanceState().isToolLocked,[t]),h=Y("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]),p=Y("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]),y=Y("exportBackground",()=>t.getInstanceState().exportBackground,[t]),f=Y("emptyPage",()=>t.getCurrentPageShapeIds().size===0,[t]),m=Y("selectedCount",()=>t.getSelectedShapeIds().length,[t]),S=m===0,w=m>0,x=m>1,C=m>2,P=!!((F=window.navigator.clipboard)!=null&&F.write),k=vw(),I=x$(),_=mw(),$=yw(),T=T$(),R=_$(),L=Y("isZoomedTo100",()=>t.getZoomLevel()===1,[t]),N=Y("oneEmbedSelected",()=>{const W=t.getOnlySelectedShape();return W?!!(t.isShapeOfType(W,"embed")&&W.props.url&&!t.isShapeOrAncestorLocked(W)):!1},[]),D=Y("oneEmbeddableBookmarkSelected",()=>{const W=t.getOnlySelectedShape();return W?!!(t.isShapeOfType(W,"bookmark")&&W.props.url&&xo(W.props.url)&&!t.isShapeOrAncestorLocked(W)):!1},[]),z=b.useMemo(()=>{const W=Bf([ve("menu",Vr("file","menu.file",ve("print",B(r.print,{disabled:f}))),Vr("edit","menu.edit",ve("undo-actions",B(r.undo,{disabled:!T}),B(r.redo,{disabled:!R})),ve("clipboard-actions",B(r.cut,{disabled:S}),B(r.copy,{disabled:S}),B(r.paste,{disabled:!v$})),ve("conversions",Vr("copy-as","menu.copy-as",ve("copy-as-group",B(r["copy-as-svg"],{disabled:f}),B(r["copy-as-png"],{disabled:f||!P}),B(r["copy-as-json"],{disabled:f})),ve("export-bg",B(r["toggle-transparent"],{checked:!y}))),Vr("export-as","menu.export-as",ve("export-as-group",B(r["export-as-svg"],{disabled:f}),B(r["export-as-png"],{disabled:f}),B(r["export-as-json"],{disabled:f})),ve("export-bg",B(r["toggle-transparent"],{checked:!y})))),ve("set-selection-group",B(r["select-all"],{disabled:f}),B(r["select-none"],{disabled:!w})),ve("selection",I&&B(r["toggle-auto-size"]),k&&B(r["edit-link"]),B(r.duplicate,{disabled:!w}),_&&B(r.group),$&&B(r.ungroup),B(r["unlock-all"],{disabled:f})),ve("delete-group",B(r.delete,{disabled:!w})),ve("embeds",N&&B(r["open-embed-link"]),N&&B(r["convert-to-bookmark"]),D&&B(r["convert-to-embed"]))),Vr("view","menu.view",ve("view-actions",B(r["zoom-in"]),B(r["zoom-out"]),B(r["zoom-to-100"],{disabled:L}),B(r["zoom-to-fit"],{disabled:f}),B(r["zoom-to-selection"],{disabled:f||!w})))),ve("extras",B(r["insert-embed"]),B(r["insert-media"])),ve("preferences",Vr("preferences","menu.preferences",ve("preferences-actions",B(r["toggle-snap-mode"],{checked:u}),B(r["toggle-tool-lock"],{checked:d}),B(r["toggle-grid"],{checked:c}),B(r["toggle-dark-mode"],{checked:i}),B(r["toggle-focus-mode"],{checked:h}),B(r["toggle-edge-scrolling"],{checked:l===1}),B(r["toggle-reduce-motion"],{checked:a===0}),B(r["toggle-debug-mode"],{checked:p}))),s&&gw("LANGUAGE_MENU",{readonlyOk:!0}))]);return e?e(t,W,{actions:r,noneSelected:S,oneSelected:w,twoSelected:x,threeSelected:C}):W},[t,e,r,w,x,C,f,s,_,$,k,P,I,S,T,R,a,i,c,u,d,h,y,p,l,L,D,N]);return g.jsx($$.Provider,{value:z,children:n})}function XX(){const e=ne.useContext($$);if(!e)throw new Error("useMenuSchema must be used inside of a TLUiMenuSchemaProvider.");return e}function Le(e){return{id:e.id,type:"item",readonlyOk:e.readonlyOk,toolItem:e}}const M$=ne.createContext([]);function qX({overrides:e,children:n}){const t=K(),r=Sw(),o=ne.useMemo(()=>{const s=he([Le(r.select),Le(r.hand),Le(r.draw),Le(r.eraser),Le(r.arrow),Le(r.text),Le(r.note),Le(r.asset),Le(r.rectangle),Le(r.ellipse),Le(r.diamond),Le(r.triangle),Le(r.trapezoid),Le(r.rhombus),Le(r.hexagon),Le(r.cloud),Le(r.star),Le(r.oval),Le(r["x-box"]),Le(r["check-box"]),Le(r["arrow-left"]),Le(r["arrow-up"]),Le(r["arrow-down"]),Le(r["arrow-right"]),Le(r.line),Le(r.highlight),Le(r.frame),Le(r.laser)]);return e?e(t,s,{tools:r}):s},[t,e,r]);return g.jsx(M$.Provider,{value:o,children:n})}function ZX(){const e=ne.useContext(M$);if(!e)throw new Error("useToolbarSchema must be used within a ToolbarSchemaProvider");return e}function QX(){const{addToast:e,removeToast:n,clearToasts:t}=io(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=_i(),l=fr()<5,c=be();return b.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 JX(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of Eo(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 A$(e){return b.useMemo(()=>e,e)}function eq(e){const n=A$(e==null?[]:Array.isArray(e)?e:[e]);return b.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of Eo(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function tq(e){const n=QX(),t=A$(e==null?[]:Array.isArray(e)?e:[e]);return b.useMemo(()=>JX(t,n),[t,n])}function nq({overrides:e,assetUrls:n,onUiEvent:t,forceMobile:r,children:o}){return g.jsx(BG,{assetUrls:LG(n),children:g.jsx(VG,{overrides:eq(e),children:g.jsx(hX,{onEvent:t,children:g.jsx(IX,{children:g.jsx(TX,{children:g.jsx(LX,{forceMobile:r,children:g.jsx(rq,{overrides:e,children:o})})})})})})})}function rq({overrides:e,children:n}){const t=tq(e);return g.jsx(RX,{overrides:t.actions,children:g.jsx(UX,{overrides:t.tools,children:g.jsx(qX,{overrides:t.toolbar,children:g.jsx(NX,{overrides:t.actionsMenu,children:g.jsx(HX,{overrides:t.keyboardShortcutsMenu,children:g.jsx(BX,{overrides:t.contextMenu,children:g.jsx(WX,{overrides:t.helpMenu,children:g.jsx(YX,{overrides:t.menu,children:n})})})})})})})})}function oq(){const e=K(),t=nn()["back-to-content"],[r,o]=b.useState(!1);return b.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(ae,{iconLeft:t.icon,label:t.label,type:"low",onClick:()=>{t.onSelect("helper-buttons"),o(!1)}}):null}const sq=b.createContext(void 0);function ww(e){const n=b.useContext(sq);return e||n||"ltr"}const iq=["top","right","bottom","left"],Es=Math.min,Ln=Math.max,Bp=Math.round,Dd=Math.floor,ks=e=>({x:e,y:e}),aq={left:"right",right:"left",bottom:"top",top:"bottom"},lq={start:"end",end:"start"};function q0(e,n,t){return Ln(e,Es(n,t))}function jo(e,n){return typeof e=="function"?e(n):e}function Lo(e){return e.split("-")[0]}function ll(e){return e.split("-")[1]}function xw(e){return e==="x"?"y":"x"}function bw(e){return e==="y"?"height":"width"}function cl(e){return["top","bottom"].includes(Lo(e))?"y":"x"}function Cw(e){return xw(cl(e))}function cq(e,n,t){t===void 0&&(t=!1);const r=ll(e),o=Cw(e),s=bw(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=Up(i)),[i,Up(i)]}function uq(e){const n=Up(e);return[Z0(e),n,Z0(n)]}function Z0(e){return e.replace(/start|end/g,n=>lq[n])}function dq(e,n,t){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(e){case"top":case"bottom":return t?n?o:r:n?r:o;case"left":case"right":return n?s:i;default:return[]}}function hq(e,n,t,r){const o=ll(e);let s=dq(Lo(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(Z0)))),s}function Up(e){return e.replace(/left|right|bottom|top/g,n=>aq[n])}function pq(e){return{top:0,right:0,bottom:0,left:0,...e}}function O$(e){return typeof e!="number"?pq(e):{top:e,right:e,bottom:e,left:e}}function Hp(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}function SC(e,n,t){let{reference:r,floating:o}=e;const s=cl(n),i=Cw(n),a=bw(i),l=Lo(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(ll(n)){case"start":p[i]-=h*(t&&c?-1:1);break;case"end":p[i]+=h*(t&&c?-1:1);break}return p}const fq=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}=SC(c,r,l),h=r,p={},y=0;for(let f=0;f<a.length;f++){const{name:m,fn:S}=a[f],{x:w,y:x,data:C,reset:P}=await S({x:u,y:d,initialPlacement:r,placement:h,strategy:o,middlewareData:p,rects:c,platform:i,elements:{reference:e,floating:n}});if(u=w??u,d=x??d,p={...p,[m]:{...p[m],...C}},P&&y<=50){y++,typeof P=="object"&&(P.placement&&(h=P.placement),P.rects&&(c=P.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):P.rects),{x:u,y:d}=SC(c,h,l)),f=-1;continue}}return{x:u,y:d,placement:h,strategy:o,middlewareData:p}};async function Gc(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}=jo(n,e),y=O$(p),m=a[h?d==="floating"?"reference":"floating":d],S=Hp(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(m)))==null||t?m:m.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),w=d==="floating"?{...i.floating,x:r,y:o}:i.reference,x=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),C=await(s.isElement==null?void 0:s.isElement(x))?await(s.getScale==null?void 0:s.getScale(x))||{x:1,y:1}:{x:1,y:1},P=Hp(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({rect:w,offsetParent:x,strategy:l}):w);return{top:(S.top-P.top+y.top)/C.y,bottom:(P.bottom-S.bottom+y.bottom)/C.y,left:(S.left-P.left+y.left)/C.x,right:(P.right-S.right+y.right)/C.x}}const gq=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=n,{element:c,padding:u=0}=jo(e,n)||{};if(c==null)return{};const d=O$(u),h={x:t,y:r},p=Cw(o),y=bw(p),f=await i.getDimensions(c),m=p==="y",S=m?"top":"left",w=m?"bottom":"right",x=m?"clientHeight":"clientWidth",C=s.reference[y]+s.reference[p]-h[p]-s.floating[y],P=h[p]-s.reference[p],k=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let I=k?k[x]:0;(!I||!await(i.isElement==null?void 0:i.isElement(k)))&&(I=a.floating[x]||s.floating[y]);const _=C/2-P/2,$=I/2-f[y]/2-1,T=Es(d[S],$),R=Es(d[w],$),L=T,N=I-f[y]-R,D=I/2-f[y]/2+_,z=q0(L,D,N),F=!l.arrow&&ll(o)!=null&&D!=z&&s.reference[y]/2-(D<L?T:R)-f[y]/2<0,W=F?D<L?D-L:D-N:0;return{[p]:h[p]+W,data:{[p]:z,centerOffset:D-z-W,...F&&{alignmentOffset:W}},reset:F}}}),mq=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var t,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=n,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:f=!0,...m}=jo(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const S=Lo(o),w=Lo(a)===a,x=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=h||(w||!f?[Up(a)]:uq(a));!h&&y!=="none"&&C.push(...hq(a,f,y,x));const P=[a,...C],k=await Gc(n,m),I=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&I.push(k[S]),d){const L=cq(o,i,x);I.push(k[L[0]],k[L[1]])}if(_=[..._,{placement:o,overflows:I}],!I.every(L=>L<=0)){var $,T;const L=((($=s.flip)==null?void 0:$.index)||0)+1,N=P[L];if(N)return{data:{index:L,overflows:_},reset:{placement:N}};let D=(T=_.filter(z=>z.overflows[0]<=0).sort((z,F)=>z.overflows[1]-F.overflows[1])[0])==null?void 0:T.placement;if(!D)switch(p){case"bestFit":{var R;const z=(R=_.map(F=>[F.placement,F.overflows.filter(W=>W>0).reduce((W,H)=>W+H,0)]).sort((F,W)=>F[1]-W[1])[0])==null?void 0:R[0];z&&(D=z);break}case"initialPlacement":D=a;break}if(o!==D)return{reset:{placement:D}}}return{}}}};function wC(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function xC(e){return iq.some(n=>e[n]>=0)}const yq=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=jo(e,n);switch(r){case"referenceHidden":{const s=await Gc(n,{...o,elementContext:"reference"}),i=wC(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:xC(i)}}}case"escaped":{const s=await Gc(n,{...o,altBoundary:!0}),i=wC(s,t.floating);return{data:{escapedOffsets:i,escaped:xC(i)}}}default:return{}}}}};async function vq(e,n){const{placement:t,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Lo(t),a=ll(t),l=cl(t)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,d=jo(n,e);let{mainAxis:h,crossAxis:p,alignmentAxis:y}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...d};return a&&typeof y=="number"&&(p=a==="end"?y*-1:y),l?{x:p*u,y:h*c}:{x:h*c,y:p*u}}const Sq=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 vq(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}}}}},wq=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:m=>{let{x:S,y:w}=m;return{x:S,y:w}}},...l}=jo(e,n),c={x:t,y:r},u=await Gc(n,l),d=cl(Lo(o)),h=xw(d);let p=c[h],y=c[d];if(s){const m=h==="y"?"top":"left",S=h==="y"?"bottom":"right",w=p+u[m],x=p-u[S];p=q0(w,p,x)}if(i){const m=d==="y"?"top":"left",S=d==="y"?"bottom":"right",w=y+u[m],x=y-u[S];y=q0(w,y,x)}const f=a.fn({...n,[h]:p,[d]:y});return{...f,data:{x:f.x-t,y:f.y-r}}}}},xq=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}=jo(e,n),u={x:t,y:r},d=cl(o),h=xw(d);let p=u[h],y=u[d];const f=jo(a,n),m=typeof f=="number"?{mainAxis:f,crossAxis:0}:{mainAxis:0,crossAxis:0,...f};if(l){const x=h==="y"?"height":"width",C=s.reference[h]-s.floating[x]+m.mainAxis,P=s.reference[h]+s.reference[x]-m.mainAxis;p<C?p=C:p>P&&(p=P)}if(c){var S,w;const x=h==="y"?"width":"height",C=["top","left"].includes(Lo(o)),P=s.reference[d]-s.floating[x]+(C&&((S=i.offset)==null?void 0:S[d])||0)+(C?0:m.crossAxis),k=s.reference[d]+s.reference[x]+(C?0:((w=i.offset)==null?void 0:w[d])||0)-(C?m.crossAxis:0);y<P?y=P:y>k&&(y=k)}return{[h]:p,[d]:y}}}},bq=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(n){const{placement:t,rects:r,platform:o,elements:s}=n,{apply:i=()=>{},...a}=jo(e,n),l=await Gc(n,a),c=Lo(t),u=ll(t),d=cl(t)==="y",{width:h,height:p}=r.floating;let y,f;c==="top"||c==="bottom"?(y=c,f=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(f=c,y=u==="end"?"top":"bottom");const m=p-l[y],S=h-l[f],w=!n.middlewareData.shift;let x=m,C=S;if(d){const k=h-l.left-l.right;C=u||w?Es(S,k):k}else{const k=p-l.top-l.bottom;x=u||w?Es(m,k):k}if(w&&!u){const k=Ln(l.left,0),I=Ln(l.right,0),_=Ln(l.top,0),$=Ln(l.bottom,0);d?C=h-2*(k!==0||I!==0?k+I:Ln(l.left,l.right)):x=p-2*(_!==0||$!==0?_+$:Ln(l.top,l.bottom))}await i({...n,availableWidth:C,availableHeight:x});const P=await o.getDimensions(s.floating);return h!==P.width||p!==P.height?{reset:{rects:!0}}:{}}}};function Is(e){return R$(e)?(e.nodeName||"").toLowerCase():"#document"}function Vn(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function Ko(e){var n;return(n=(R$(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function R$(e){return e instanceof Node||e instanceof Vn(e).Node}function No(e){return e instanceof Element||e instanceof Vn(e).Element}function no(e){return e instanceof HTMLElement||e instanceof Vn(e).HTMLElement}function bC(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Vn(e).ShadowRoot}function Eu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=hr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function Cq(e){return["table","td","th"].includes(Is(e))}function Pw(e){const n=Ew(),t=hr(e);return t.transform!=="none"||t.perspective!=="none"||(t.containerType?t.containerType!=="normal":!1)||!n&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!n&&(t.filter?t.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(t.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(t.contain||"").includes(r))}function Pq(e){let n=Ha(e);for(;no(n)&&!Uf(n);){if(Pw(n))return n;n=Ha(n)}return null}function Ew(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Uf(e){return["html","body","#document"].includes(Is(e))}function hr(e){return Vn(e).getComputedStyle(e)}function Hf(e){return No(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Ha(e){if(Is(e)==="html")return e;const n=e.assignedSlot||e.parentNode||bC(e)&&e.host||Ko(e);return bC(n)?n.host:n}function D$(e){const n=Ha(e);return Uf(n)?e.ownerDocument?e.ownerDocument.body:e.body:no(n)&&Eu(n)?n:D$(n)}function Yc(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=D$(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Vn(o);return s?n.concat(i,i.visualViewport||[],Eu(o)?o:[],i.frameElement&&t?Yc(i.frameElement):[]):n.concat(o,Yc(o,[],t))}function j$(e){const n=hr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=no(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=Bp(t)!==s||Bp(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function kw(e){return No(e)?e:e.contextElement}function Ta(e){const n=kw(e);if(!no(n))return ks(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=j$(n);let i=(s?Bp(t.width):t.width)/r,a=(s?Bp(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const Eq=ks(0);function L$(e){const n=Vn(e);return!Ew()||!n.visualViewport?Eq:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function kq(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==Vn(e)?!1:n}function vi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=kw(e);let i=ks(1);n&&(r?No(r)&&(i=Ta(r)):i=Ta(e));const a=kq(s,t,r)?L$(s):ks(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=Vn(s),p=r&&No(r)?Vn(r):r;let y=h.frameElement;for(;y&&r&&p!==h;){const f=Ta(y),m=y.getBoundingClientRect(),S=hr(y),w=m.left+(y.clientLeft+parseFloat(S.paddingLeft))*f.x,x=m.top+(y.clientTop+parseFloat(S.paddingTop))*f.y;l*=f.x,c*=f.y,u*=f.x,d*=f.y,l+=w,c+=x,y=Vn(y).frameElement}}return Hp({width:u,height:d,x:l,y:c})}function Iq(e){let{rect:n,offsetParent:t,strategy:r}=e;const o=no(t),s=Ko(t);if(t===s)return n;let i={scrollLeft:0,scrollTop:0},a=ks(1);const l=ks(0);if((o||!o&&r!=="fixed")&&((Is(t)!=="body"||Eu(s))&&(i=Hf(t)),no(t))){const c=vi(t);a=Ta(t),l.x=c.x+t.clientLeft,l.y=c.y+t.clientTop}return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-i.scrollLeft*a.x+l.x,y:n.y*a.y-i.scrollTop*a.y+l.y}}function _q(e){return Array.from(e.getClientRects())}function N$(e){return vi(Ko(e)).left+Hf(e).scrollLeft}function Tq(e){const n=Ko(e),t=Hf(e),r=e.ownerDocument.body,o=Ln(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=Ln(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+N$(e);const a=-t.scrollTop;return hr(r).direction==="rtl"&&(i+=Ln(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function $q(e,n){const t=Vn(e),r=Ko(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=Ew();(!c||c&&n==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function Mq(e,n){const t=vi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=no(e)?Ta(e):ks(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 CC(e,n,t){let r;if(n==="viewport")r=$q(e,t);else if(n==="document")r=Tq(Ko(e));else if(No(n))r=Mq(n,t);else{const o=L$(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return Hp(r)}function z$(e,n){const t=Ha(e);return t===n||!No(t)||Uf(t)?!1:hr(t).position==="fixed"||z$(t,n)}function Aq(e,n){const t=n.get(e);if(t)return t;let r=Yc(e,[],!1).filter(a=>No(a)&&Is(a)!=="body"),o=null;const s=hr(e).position==="fixed";let i=s?Ha(e):e;for(;No(i)&&!Uf(i);){const a=hr(i),l=Pw(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Eu(i)&&!l&&z$(e,i))?r=r.filter(u=>u!==i):o=a,i=Ha(i)}return n.set(e,r),r}function Oq(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?Aq(n,this._c):[].concat(t),r],a=i[0],l=i.reduce((c,u)=>{const d=CC(n,u,o);return c.top=Ln(d.top,c.top),c.right=Es(d.right,c.right),c.bottom=Es(d.bottom,c.bottom),c.left=Ln(d.left,c.left),c},CC(n,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function Rq(e){const{width:n,height:t}=j$(e);return{width:n,height:t}}function Dq(e,n,t){const r=no(n),o=Ko(n),s=t==="fixed",i=vi(e,!0,s,n);let a={scrollLeft:0,scrollTop:0};const l=ks(0);if(r||!r&&!s)if((Is(n)!=="body"||Eu(o))&&(a=Hf(n)),r){const c=vi(n,!0,s,n);l.x=c.x+n.clientLeft,l.y=c.y+n.clientTop}else o&&(l.x=N$(o));return{x:i.left+a.scrollLeft-l.x,y:i.top+a.scrollTop-l.y,width:i.width,height:i.height}}function PC(e,n){return!no(e)||hr(e).position==="fixed"?null:n?n(e):e.offsetParent}function F$(e,n){const t=Vn(e);if(!no(e))return t;let r=PC(e,n);for(;r&&Cq(r)&&hr(r).position==="static";)r=PC(r,n);return r&&(Is(r)==="html"||Is(r)==="body"&&hr(r).position==="static"&&!Pw(r))?t:r||Pq(e)||t}const jq=async function(e){let{reference:n,floating:t,strategy:r}=e;const o=this.getOffsetParent||F$,s=this.getDimensions;return{reference:Dq(n,await o(t),r),floating:{x:0,y:0,...await s(t)}}};function Lq(e){return hr(e).direction==="rtl"}const Nq={convertOffsetParentRelativeRectToViewportRelativeRect:Iq,getDocumentElement:Ko,getClippingRect:Oq,getOffsetParent:F$,getElementRects:jq,getClientRects:_q,getDimensions:Rq,getScale:Ta,isElement:No,isRTL:Lq};function zq(e,n){let t=null,r;const o=Ko(e);function s(){clearTimeout(r),t&&t.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=Dd(u),y=Dd(o.clientWidth-(c+d)),f=Dd(o.clientHeight-(u+h)),m=Dd(c),w={rootMargin:-p+"px "+-y+"px "+-f+"px "+-m+"px",threshold:Ln(0,Es(1,l))||1};let x=!0;function C(P){const k=P[0].intersectionRatio;if(k!==l){if(!x)return i();k?i(!1,k):r=setTimeout(()=>{i(!1,1e-7)},100)}x=!1}try{t=new IntersectionObserver(C,{...w,root:o.ownerDocument})}catch{t=new IntersectionObserver(C,w)}t.observe(e)}return i(!0),s}function Fq(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=kw(e),u=o||s?[...c?Yc(c):[],...Yc(n)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",t,{passive:!0}),s&&S.addEventListener("resize",t)});const d=c&&a?zq(c,t):null;let h=-1,p=null;i&&(p=new ResizeObserver(S=>{let[w]=S;w&&w.target===c&&p&&(p.unobserve(n),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{p&&p.observe(n)})),t()}),c&&!l&&p.observe(c),p.observe(n));let y,f=l?vi(e):null;l&&m();function m(){const S=vi(e);f&&(S.x!==f.x||S.y!==f.y||S.width!==f.width||S.height!==f.height)&&t(),f=S,y=requestAnimationFrame(m)}return t(),()=>{u.forEach(S=>{o&&S.removeEventListener("scroll",t),s&&S.removeEventListener("resize",t)}),d&&d(),p&&p.disconnect(),p=null,l&&cancelAnimationFrame(y)}}const Bq=wq,Uq=mq,Hq=bq,Vq=yq,EC=gq,Kq=xq,Wq=(e,n,t)=>{const r=new Map,o={platform:Nq,...t},s={...o.platform,_c:r};return fq(e,n,{...o,platform:s})},Gq=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?EC({element:r.current,padding:o}).fn(t):{}:r?EC({element:r,padding:o}).fn(t):{}}}};var Nh=typeof document<"u"?b.useLayoutEffect:b.useEffect;function Vp(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(!Vp(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)&&!Vp(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function B$(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kC(e,n){const t=B$(e);return Math.round(n*t)/t}function IC(e){const n=b.useRef(e);return Nh(()=>{n.current=e}),n}function Yq(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]=b.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[h,p]=b.useState(r);Vp(h,r)||p(r);const[y,f]=b.useState(null),[m,S]=b.useState(null),w=b.useCallback(F=>{F!=k.current&&(k.current=F,f(F))},[f]),x=b.useCallback(F=>{F!==I.current&&(I.current=F,S(F))},[S]),C=s||y,P=i||m,k=b.useRef(null),I=b.useRef(null),_=b.useRef(u),$=IC(l),T=IC(o),R=b.useCallback(()=>{if(!k.current||!I.current)return;const F={placement:n,strategy:t,middleware:h};T.current&&(F.platform=T.current),Wq(k.current,I.current,F).then(W=>{const H={...W,isPositioned:!0};L.current&&!Vp(_.current,H)&&(_.current=H,il.flushSync(()=>{d(H)}))})},[h,n,t,T]);Nh(()=>{c===!1&&_.current.isPositioned&&(_.current.isPositioned=!1,d(F=>({...F,isPositioned:!1})))},[c]);const L=b.useRef(!1);Nh(()=>(L.current=!0,()=>{L.current=!1}),[]),Nh(()=>{if(C&&(k.current=C),P&&(I.current=P),C&&P){if($.current)return $.current(C,P,R);R()}},[C,P,R,$]);const N=b.useMemo(()=>({reference:k,floating:I,setReference:w,setFloating:x}),[w,x]),D=b.useMemo(()=>({reference:C,floating:P}),[C,P]),z=b.useMemo(()=>{const F={position:t,left:0,top:0};if(!D.floating)return F;const W=kC(D.floating,u.x),H=kC(D.floating,u.y);return a?{...F,transform:"translate("+W+"px, "+H+"px)",...B$(D.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:W,top:H}},[t,a,D.floating,u.x,u.y]);return b.useMemo(()=>({...u,update:R,refs:N,elements:D,floatingStyles:z}),[u,R,N,D,z])}function U$(e){const[n,t]=b.useState(void 0);return yi(()=>{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 H$="Popper",[V$,Vf]=so(H$),[Xq,K$]=V$(H$),qq=e=>{const{__scopePopper:n,children:t}=e,[r,o]=b.useState(null);return b.createElement(Xq,{scope:n,anchor:r,onAnchorChange:o},t)},Zq="PopperAnchor",Qq=b.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=K$(Zq,t),i=b.useRef(null),a=Ge(n,i);return b.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:b.createElement(ze.div,Q({},o,{ref:a}))}),W$="PopperContent",[Jq,ate]=V$(W$),eZ=b.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:y=0,arrowPadding:f=0,avoidCollisions:m=!0,collisionBoundary:S=[],collisionPadding:w=0,sticky:x="partial",hideWhenDetached:C=!1,updatePositionStrategy:P="optimized",onPlaced:k,...I}=e,_=K$(W$,u),[$,T]=b.useState(null),R=Ge(n,tt=>T(tt)),[L,N]=b.useState(null),D=U$(L),z=(t=D==null?void 0:D.width)!==null&&t!==void 0?t:0,F=(r=D==null?void 0:D.height)!==null&&r!==void 0?r:0,W=d+(p!=="center"?"-"+p:""),H=typeof w=="number"?w:{top:0,right:0,bottom:0,left:0,...w},U=Array.isArray(S)?S:[S],V=U.length>0,X={padding:H,boundary:U.filter(tZ),altBoundary:V},{refs:re,floatingStyles:ge,placement:Ce,isPositioned:oe,middlewareData:Se}=Yq({strategy:"fixed",placement:W,whileElementsMounted:(...tt)=>Fq(...tt,{animationFrame:P==="always"}),elements:{reference:_.anchor},middleware:[Sq({mainAxis:h+F,alignmentAxis:y}),m&&Bq({mainAxis:!0,crossAxis:!1,limiter:x==="partial"?Kq():void 0,...X}),m&&Uq({...X}),Hq({...X,apply:({elements:tt,rects:mt,availableWidth:lo,availableHeight:dl})=>{const{width:Xf,height:qf}=mt.reference,Mi=tt.floating.style;Mi.setProperty("--radix-popper-available-width",`${lo}px`),Mi.setProperty("--radix-popper-available-height",`${dl}px`),Mi.setProperty("--radix-popper-anchor-width",`${Xf}px`),Mi.setProperty("--radix-popper-anchor-height",`${qf}px`)}}),L&&Gq({element:L,padding:f}),nZ({arrowWidth:z,arrowHeight:F}),C&&Vq({strategy:"referenceHidden",...X})]}),[De,et]=G$(Ce),Ee=Jt(k);yi(()=>{oe&&(Ee==null||Ee())},[oe,Ee]);const ct=(o=Se.arrow)===null||o===void 0?void 0:o.x,Fe=(s=Se.arrow)===null||s===void 0?void 0:s.y,qn=((i=Se.arrow)===null||i===void 0?void 0:i.centerOffset)!==0,[_n,Tn]=b.useState();return yi(()=>{$&&Tn(window.getComputedStyle($).zIndex)},[$]),b.createElement("div",{ref:re.setFloating,"data-radix-popper-content-wrapper":"",style:{...ge,transform:oe?ge.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:_n,"--radix-popper-transform-origin":[(a=Se.transformOrigin)===null||a===void 0?void 0:a.x,(l=Se.transformOrigin)===null||l===void 0?void 0:l.y].join(" ")},dir:e.dir},b.createElement(Jq,{scope:u,placedSide:De,onArrowChange:N,arrowX:ct,arrowY:Fe,shouldHideArrow:qn},b.createElement(ze.div,Q({"data-side":De,"data-align":et},I,{ref:R,style:{...I.style,animation:oe?void 0:"none",opacity:(c=Se.hide)!==null&&c!==void 0&&c.referenceHidden?0:void 0}}))))});function tZ(e){return e!==null}const nZ=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,[y,f]=G$(a),m={start:"0%",center:"50%",end:"100%"}[f],S=((r=(o=c.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+h/2,w=((s=(i=c.arrow)===null||i===void 0?void 0:i.y)!==null&&s!==void 0?s:0)+p/2;let x="",C="";return y==="bottom"?(x=d?m:`${S}px`,C=`${-p}px`):y==="top"?(x=d?m:`${S}px`,C=`${l.floating.height+p}px`):y==="right"?(x=`${-p}px`,C=d?m:`${w}px`):y==="left"&&(x=`${l.floating.width+p}px`,C=d?m:`${w}px`),{data:{x,y:C}}}});function G$(e){const[n,t="center"]=e.split("-");return[n,t]}const Iw=qq,Y$=Qq,X$=eZ,Hm="rovingFocusGroup.onEntryFocus",rZ={bubbles:!1,cancelable:!0},_w="RovingFocusGroup",[Q0,q$,oZ]=Mf(_w),[sZ,Z$]=so(_w,[oZ]),[iZ,aZ]=sZ(_w),lZ=b.forwardRef((e,n)=>b.createElement(Q0.Provider,{scope:e.__scopeRovingFocusGroup},b.createElement(Q0.Slot,{scope:e.__scopeRovingFocusGroup},b.createElement(cZ,Q({},e,{ref:n}))))),cZ=b.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,...u}=e,d=b.useRef(null),h=Ge(n,d),p=ww(s),[y=null,f]=Ns({prop:i,defaultProp:a,onChange:l}),[m,S]=b.useState(!1),w=Jt(c),x=q$(t),C=b.useRef(!1),[P,k]=b.useState(0);return b.useEffect(()=>{const I=d.current;if(I)return I.addEventListener(Hm,w),()=>I.removeEventListener(Hm,w)},[w]),b.createElement(iZ,{scope:t,orientation:r,dir:p,loop:o,currentTabStopId:y,onItemFocus:b.useCallback(I=>f(I),[f]),onItemShiftTab:b.useCallback(()=>S(!0),[]),onFocusableItemAdd:b.useCallback(()=>k(I=>I+1),[]),onFocusableItemRemove:b.useCallback(()=>k(I=>I-1),[])},b.createElement(ze.div,Q({tabIndex:m||P===0?-1:0,"data-orientation":r},u,{ref:h,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{C.current=!0}),onFocus:se(e.onFocus,I=>{const _=!C.current;if(I.target===I.currentTarget&&_&&!m){const $=new CustomEvent(Hm,rZ);if(I.currentTarget.dispatchEvent($),!$.defaultPrevented){const T=x().filter(z=>z.focusable),R=T.find(z=>z.active),L=T.find(z=>z.id===y),D=[R,L,...T].filter(Boolean).map(z=>z.ref.current);Q$(D)}}C.current=!1}),onBlur:se(e.onBlur,()=>S(!1))})))}),uZ="RovingFocusGroupItem",dZ=b.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=To(),l=s||a,c=aZ(uZ,t),u=c.currentTabStopId===l,d=q$(t),{onFocusableItemAdd:h,onFocusableItemRemove:p}=c;return b.useEffect(()=>{if(r)return h(),()=>p()},[r,h,p]),b.createElement(Q0.ItemSlot,{scope:t,id:l,focusable:r,active:o},b.createElement(ze.span,Q({tabIndex:u?0:-1,"data-orientation":c.orientation},i,{ref:n,onMouseDown:se(e.onMouseDown,y=>{r?c.onItemFocus(l):y.preventDefault()}),onFocus:se(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){c.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const f=fZ(y,c.orientation,c.dir);if(f!==void 0){y.preventDefault();let S=d().filter(w=>w.focusable).map(w=>w.ref.current);if(f==="last")S.reverse();else if(f==="prev"||f==="next"){f==="prev"&&S.reverse();const w=S.indexOf(y.currentTarget);S=c.loop?gZ(S,w+1):S.slice(w+1)}setTimeout(()=>Q$(S))}})})))}),hZ={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 fZ(e,n,t){const r=pZ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return hZ[r]}function Q$(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function gZ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const mZ=lZ,yZ=dZ,J0=["Enter"," "],vZ=["ArrowDown","PageUp","Home"],J$=["ArrowUp","PageDown","End"],SZ=[...vZ,...J$],wZ={ltr:[...J0,"ArrowRight"],rtl:[...J0,"ArrowLeft"]},xZ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Kf="Menu",[Xc,bZ,CZ]=Mf(Kf),[Ti,Wf]=so(Kf,[CZ,Vf,Z$]),Gf=Vf(),e3=Z$(),[t3,zs]=Ti(Kf),[PZ,ku]=Ti(Kf),EZ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Gf(n),[l,c]=b.useState(null),u=b.useRef(!1),d=Jt(s),h=ww(o);return b.useEffect(()=>{const p=()=>{u.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>u.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),b.createElement(Iw,a,b.createElement(t3,{scope:n,open:t,onOpenChange:d,content:l,onContentChange:c},b.createElement(PZ,{scope:n,onClose:b.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:h,modal:i},r)))},n3=b.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=Gf(t);return b.createElement(Y$,Q({},o,r,{ref:n}))}),r3="MenuPortal",[kZ,o3]=Ti(r3,{forceMount:void 0}),IZ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=zs(r3,n);return b.createElement(kZ,{scope:n,forceMount:t},b.createElement(jr,{present:t||s.open},b.createElement(Of,{asChild:!0,container:o},r)))},Ar="MenuContent",[_Z,Tw]=Ti(Ar),TZ=b.forwardRef((e,n)=>{const t=o3(Ar,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=zs(Ar,e.__scopeMenu),i=ku(Ar,e.__scopeMenu);return b.createElement(Xc.Provider,{scope:e.__scopeMenu},b.createElement(jr,{present:r||s.open},b.createElement(Xc.Slot,{scope:e.__scopeMenu},i.modal?b.createElement($Z,Q({},o,{ref:n})):b.createElement(MZ,Q({},o,{ref:n})))))}),$Z=b.forwardRef((e,n)=>{const t=zs(Ar,e.__scopeMenu),r=b.useRef(null),o=Ge(n,r);return b.useEffect(()=>{const s=r.current;if(s)return dw(s)},[]),b.createElement($w,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)}))}),MZ=b.forwardRef((e,n)=>{const t=zs(Ar,e.__scopeMenu);return b.createElement($w,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),$w=b.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:y,...f}=e,m=zs(Ar,t),S=ku(Ar,t),w=Gf(t),x=e3(t),C=bZ(t),[P,k]=b.useState(null),I=b.useRef(null),_=Ge(n,I,m.onContentChange),$=b.useRef(0),T=b.useRef(""),R=b.useRef(0),L=b.useRef(null),N=b.useRef("right"),D=b.useRef(0),z=y?uw:b.Fragment,F=y?{as:mi,allowPinchZoom:!0}:void 0,W=U=>{var V,X;const re=T.current+U,ge=C().filter(Ee=>!Ee.disabled),Ce=document.activeElement,oe=(V=ge.find(Ee=>Ee.ref.current===Ce))===null||V===void 0?void 0:V.textValue,Se=ge.map(Ee=>Ee.textValue),De=KZ(Se,re,oe),et=(X=ge.find(Ee=>Ee.textValue===De))===null||X===void 0?void 0:X.ref.current;(function Ee(ct){T.current=ct,window.clearTimeout($.current),ct!==""&&($.current=window.setTimeout(()=>Ee(""),1e3))})(re),et&&setTimeout(()=>et.focus())};b.useEffect(()=>()=>window.clearTimeout($.current),[]),cw();const H=b.useCallback(U=>{var V,X;return N.current===((V=L.current)===null||V===void 0?void 0:V.side)&&GZ(U,(X=L.current)===null||X===void 0?void 0:X.area)},[]);return b.createElement(_Z,{scope:t,searchRef:T,onItemEnter:b.useCallback(U=>{H(U)&&U.preventDefault()},[H]),onItemLeave:b.useCallback(U=>{var V;H(U)||((V=I.current)===null||V===void 0||V.focus(),k(null))},[H]),onTriggerLeave:b.useCallback(U=>{H(U)&&U.preventDefault()},[H]),pointerGraceTimerRef:R,onPointerGraceIntentChange:b.useCallback(U=>{L.current=U},[])},b.createElement(z,F,b.createElement(lw,{asChild:!0,trapped:o,onMountAutoFocus:se(s,U=>{var V;U.preventDefault(),(V=I.current)===null||V===void 0||V.focus()}),onUnmountAutoFocus:i},b.createElement(Af,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:p},b.createElement(mZ,Q({asChild:!0},x,{dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:P,onCurrentTabStopIdChange:k,onEntryFocus:se(l,U=>{S.isUsingKeyboardRef.current||U.preventDefault()})}),b.createElement(X$,Q({role:"menu","aria-orientation":"vertical","data-state":u3(m.open),"data-radix-menu-content":"",dir:S.dir},w,f,{ref:_,style:{outline:"none",...f.style},onKeyDown:se(f.onKeyDown,U=>{const X=U.target.closest("[data-radix-menu-content]")===U.currentTarget,re=U.ctrlKey||U.altKey||U.metaKey,ge=U.key.length===1;X&&(U.key==="Tab"&&U.preventDefault(),!re&&ge&&W(U.key));const Ce=I.current;if(U.target!==Ce||!SZ.includes(U.key))return;U.preventDefault();const Se=C().filter(De=>!De.disabled).map(De=>De.ref.current);J$.includes(U.key)&&Se.reverse(),HZ(Se)}),onBlur:se(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout($.current),T.current="")}),onPointerMove:se(e.onPointerMove,qc(U=>{const V=U.target,X=D.current!==U.clientX;if(U.currentTarget.contains(V)&&X){const re=U.clientX>D.current?"right":"left";N.current=re,D.current=U.clientX}}))})))))))}),AZ=b.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return b.createElement(ze.div,Q({role:"group"},r,{ref:n}))}),ev="MenuItem",_C="menu.itemSelect",s3=b.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=b.useRef(null),i=ku(ev,e.__scopeMenu),a=Tw(ev,e.__scopeMenu),l=Ge(n,s),c=b.useRef(!1),u=()=>{const d=s.current;if(!t&&d){const h=new CustomEvent(_C,{bubbles:!0,cancelable:!0});d.addEventListener(_C,p=>r==null?void 0:r(p),{once:!0}),sw(d,h),h.defaultPrevented?c.current=!1:i.onClose()}};return b.createElement(i3,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===" "||J0.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),i3=b.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=Tw(ev,t),a=e3(t),l=b.useRef(null),c=Ge(n,l),[u,d]=b.useState(!1),[h,p]=b.useState("");return b.useEffect(()=>{const y=l.current;if(y){var f;p(((f=y.textContent)!==null&&f!==void 0?f:"").trim())}},[s.children]),b.createElement(Xc.ItemSlot,{scope:t,disabled:r,textValue:o??h},b.createElement(yZ,Q({asChild:!0},a,{focusable:!r}),b.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,qc(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus())})),onPointerLeave:se(e.onPointerLeave,qc(y=>i.onItemLeave(y))),onFocus:se(e.onFocus,()=>d(!0)),onBlur:se(e.onBlur,()=>d(!1))}))))}),OZ=b.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return b.createElement(DZ,{scope:e.__scopeMenu,checked:t},b.createElement(s3,Q({role:"menuitemcheckbox","aria-checked":Kp(t)?"mixed":t},o,{ref:n,"data-state":d3(t),onSelect:se(o.onSelect,()=>r==null?void 0:r(Kp(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),RZ="MenuRadioGroup";Ti(RZ,{value:void 0,onValueChange:()=>{}});const a3="MenuItemIndicator",[DZ,jZ]=Ti(a3,{checked:!1}),LZ=b.forwardRef((e,n)=>{const{__scopeMenu:t,forceMount:r,...o}=e,s=jZ(a3,t);return b.createElement(jr,{present:r||Kp(s.checked)||s.checked===!0},b.createElement(ze.span,Q({},o,{ref:n,"data-state":d3(s.checked)})))}),l3="MenuSub",[NZ,c3]=Ti(l3),zZ=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=zs(l3,n),i=Gf(n),[a,l]=b.useState(null),[c,u]=b.useState(null),d=Jt(o);return b.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),b.createElement(Iw,i,b.createElement(t3,{scope:n,open:r,onOpenChange:d,content:c,onContentChange:u},b.createElement(NZ,{scope:n,contentId:To(),triggerId:To(),trigger:a,onTriggerChange:l},t)))},jd="MenuSubTrigger",FZ=b.forwardRef((e,n)=>{const t=zs(jd,e.__scopeMenu),r=ku(jd,e.__scopeMenu),o=c3(jd,e.__scopeMenu),s=Tw(jd,e.__scopeMenu),i=b.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=b.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return b.useEffect(()=>u,[u]),b.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),b.createElement(n3,Q({asChild:!0},c),b.createElement(i3,Q({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":u3(t.open)},e,{ref:$f(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,qc(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,qc(d=>{var h;u();const p=(h=t.content)===null||h===void 0?void 0:h.getBoundingClientRect();if(p){var y;const f=(y=t.content)===null||y===void 0?void 0:y.dataset.side,m=f==="right",S=m?-5:5,w=p[m?"left":"right"],x=p[m?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+S,y:d.clientY},{x:w,y:p.top},{x,y:p.top},{x,y:p.bottom},{x:w,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===" ")&&wZ[r.dir].includes(d.key)){var p;t.onOpenChange(!0),(p=t.content)===null||p===void 0||p.focus(),d.preventDefault()}})})))}),BZ="MenuSubContent",UZ=b.forwardRef((e,n)=>{const t=o3(Ar,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=zs(Ar,e.__scopeMenu),i=ku(Ar,e.__scopeMenu),a=c3(BZ,e.__scopeMenu),l=b.useRef(null),c=Ge(n,l);return b.createElement(Xc.Provider,{scope:e.__scopeMenu},b.createElement(jr,{present:r||s.open},b.createElement(Xc.Slot,{scope:e.__scopeMenu},b.createElement($w,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=xZ[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 u3(e){return e?"open":"closed"}function Kp(e){return e==="indeterminate"}function d3(e){return Kp(e)?"indeterminate":e?"checked":"unchecked"}function HZ(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function VZ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function KZ(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=VZ(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 WZ(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 GZ(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return WZ(t,n)}function qc(e){return n=>n.pointerType==="mouse"?e(n):void 0}const h3=EZ,p3=n3,f3=IZ,g3=TZ,m3=AZ,y3=s3,v3=OZ,YZ=LZ,S3=zZ,w3=FZ,x3=UZ,b3="DropdownMenu",[XZ,lte]=so(b3,[Wf]),Lr=Wf(),[qZ,C3]=XZ(b3),ZZ=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=Lr(n),c=b.useRef(null),[u=!1,d]=Ns({prop:o,defaultProp:s,onChange:i});return b.createElement(qZ,{scope:n,triggerId:To(),triggerRef:c,contentId:To(),open:u,onOpenChange:d,onOpenToggle:b.useCallback(()=>d(h=>!h),[d]),modal:a},b.createElement(h3,Q({},l,{open:u,onOpenChange:d,dir:r,modal:a}),t))},QZ="DropdownMenuTrigger",JZ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=C3(QZ,t),i=Lr(t);return b.createElement(p3,Q({asChild:!0},i),b.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:$f(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())})})))}),eQ=e=>{const{__scopeDropdownMenu:n,...t}=e,r=Lr(n);return b.createElement(f3,Q({},r,t))},tQ="DropdownMenuContent",nQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=C3(tQ,t),s=Lr(t),i=b.useRef(!1);return b.createElement(g3,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)"}}))}),rQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Lr(t);return b.createElement(m3,Q({},o,r,{ref:n}))}),oQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Lr(t);return b.createElement(y3,Q({},o,r,{ref:n}))}),sQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Lr(t);return b.createElement(v3,Q({},o,r,{ref:n}))}),iQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Lr(t);return b.createElement(YZ,Q({},o,r,{ref:n}))}),aQ=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=Lr(n),[a=!1,l]=Ns({prop:r,defaultProp:s,onChange:o});return b.createElement(S3,Q({},i,{open:a,onOpenChange:l}),t)},lQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Lr(t);return b.createElement(w3,Q({},o,r,{ref:n}))}),cQ=b.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Lr(t);return b.createElement(x3,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)"}}))}),P3=ZZ,Zc=JZ,Mw=eQ,E3=nQ,uQ=rQ,Qi=oQ,k3=sQ,dQ=iQ,hQ=aQ,pQ=lQ,fQ=cQ;function $i(e,n){const t=K(),r=b.useRef(!1),o=al(),s=b.useRef(0),i=b.useCallback(l=>{const c=Date.now();c-s.current<50||(s.current=c,r.current=l,t.batch(()=>{l?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(u=>!u.startsWith(e))}),n==null||n(l)}))},[t,e,n]),a=Y("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return b.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),t.addOpenMenu(e)),()=>{r.current&&(t.deleteOpenMenu(e),t.getOpenMenus().forEach(l=>{l.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),t.deleteOpenMenu(l))}),r.current=!1)}),[t,e,o]),[a,i]}function _s({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=$i(e);return g.jsx(P3,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function Iu({children:e,"data-testid":n}){return g.jsx(Zc,{dir:"ltr","data-testid":n,asChild:!0,onTouchEnd:t=>Ie(t),children:e})}function Ts({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=tn();return g.jsx(Mw,{container:s,children:g.jsx(E3,{className:"tlui-menu",align:n,sideOffset:t,side:e,alignOffset:r,collisionPadding:4,children:o})})}function Aw({id:e,children:n}){const[t,r]=$i(e);return g.jsx(hQ,{open:t,onOpenChange:r,children:n})}function Ow({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(ae,{type:"menu",className:"tlui-menu__submenu__trigger",label:e,icon:"chevron-right"})})}function Rw({alignOffset:e=0,sideOffset:n=5,children:t}){const r=tn();return g.jsx(Mw,{container:r,children:g.jsx(fQ,{className:"tlui-menu tlui-menu__submenu__content",alignOffset:e,sideOffset:n,collisionPadding:4,children:t})})}function $o({children:e,size:n="medium"}){return g.jsx(uQ,{dir:"ltr",className:"tlui-menu__group","data-size":n,children:e})}function Nn({noClose:e,...n}){return g.jsx(Qi,{dir:"ltr",asChild:!0,onClick:e||n.isChecked!==void 0?Ie:void 0,children:g.jsx(ae,{...n})})}function I3({children:e,onSelect:n,...t}){return g.jsxs(k3,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",onSelect:r=>{n==null||n(r),Ie(r)},...t,children:[g.jsx(Hn,{small:!0,icon:t.checked?"check":"checkbox-empty"}),e]})}function gQ({children:e,onSelect:n,...t}){return g.jsxs(k3,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",onSelect:r=>{n==null||n(r),Ie(r)},...t,children:[g.jsx("div",{className:"tlui-button__checkbox__indicator",children:g.jsx(dQ,{dir:"ltr",children:g.jsx(Hn,{icon:"check",small:!0})})}),e]})}let TC=0;function mQ(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)TC++,t[o]={id:We("box"+TC),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}const yQ=b.memo(function({renderDebugMenuItems:n}){const t=be();return g.jsxs("div",{className:"tlui-debug-panel",children:[g.jsx(vQ,{}),g.jsx(SQ,{}),g.jsxs(_s,{id:"debug",children:[g.jsx(Iu,{children:g.jsx(ae,{type:"icon",icon:"dots-horizontal",title:t("debug-panel.more")})}),g.jsx(Ts,{side:"top",align:"end",alignOffset:0,children:g.jsx(wQ,{renderDebugMenuItems:n})})]})]})}),vQ=Re(function(){const n=K();return g.jsx("div",{className:"tlui-debug-panel__current-state",children:n.getPath()})}),SQ=function(){const n=K(),t=Y("rendering shapes count",()=>n.getRenderingShapes().length,[n]);return g.jsxs("div",{children:[t," Shapes"]})},wQ=Re(function({renderDebugMenuItems:n}){const t=K(),{addToast:r}=io(),{addDialog:o}=_i(),[s,i]=b.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs($o,{children:[g.jsx(Nn,{type:"menu",onClick:()=>{r({id:Ne(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0}),r({id:Ne(),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:Ne(),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(Nn,{type:"menu",onClick:()=>{o({component:({onClose:a})=>g.jsx(bQ,{displayDontShowAgain:!0,onCancel:()=>{a()},onContinue:()=>{a()}}),onClose:()=>{}})},label:"Show dialog"}),g.jsx(Nn,{type:"menu",onClick:()=>mQ(t,100),label:"Create 100 shapes"}),g.jsx(Nn,{type:"menu",onClick:()=>{function a({children:h}){let p=0;if(!h.length)return 0;for(const y of[...h])p++,p+=a(y);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(Nn,{type:"menu",onClick:()=>{i(!0)},label:"Throw error"}),g.jsx(Nn,{type:"menu",onClick:()=>{kP()},label:"Hard reset"})]}),g.jsxs($o,{children:[g.jsx(Nl,{flag:He.debugSvg}),g.jsx(Nl,{flag:He.forceSrgb}),g.jsx(Nl,{flag:He.debugGeometry}),g.jsx(Nl,{flag:He.hideShapes})]}),g.jsx($o,{children:Object.values(XO).map(a=>g.jsx(Nl,{flag:a},a.name))}),n==null?void 0:n()]})});function xQ({label:e,value:n,onChange:t}){return g.jsx(I3,{title:e,checked:n,onSelect:()=>t(!n),children:g.jsx("span",{className:"tlui-button__label",draggable:!1,children:e})})}const Nl=Re(function({flag:n,onChange:t}){return g.jsx(xQ,{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 bQ({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=b.useState(!1);return g.jsxs(g.Fragment,{children:[g.jsxs(Nf,{children:[g.jsx(zf,{children:e}),g.jsx(Ff,{})]}),g.jsx(Wc,{style:{maxWidth:350},children:n}),g.jsxs(hw,{className:"tlui-dialog__footer__actions",children:[o&&g.jsx(ae,{type:"normal",onClick:()=>l(!a),iconLeft:a?"check":"checkbox-empty",style:{marginRight:"auto"},children:"Don't show again"}),g.jsx(ae,{type:"normal",onClick:s,children:t}),g.jsx(ae,{type:"primary",onClick:async()=>i(),children:r})]})]})}const CQ=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=_i(),o=tn(),s=b.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return g.jsx(qY,{onOpenChange:s,defaultOpen:!0,children:g.jsx(ZY,{container:o,children:g.jsx(QY,{dir:"ltr",className:"tlui-dialog__overlay",children:g.jsx(JY,{dir:"ltr",className:"tlui-dialog__content",children:g.jsx(n,{onClose:()=>s(!1)})})})})})};function PQ(){const{dialogs:e}=_i();return g.jsx(g.Fragment,{children:e.map(n=>g.jsx(CQ,{...n},n.id))})}const EQ=ne.memo(PQ);function kQ(){const e=K(),n=Y("follow",()=>e.getInstanceState().followingUserId,[e]);return n?g.jsx(IQ,{userId:n}):null}function IQ({userId:e}){const n=WP(e);return n?g.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function _3(){const e=K(),{languages:n,currentLanguage:t}=k$(),r=b.useCallback(o=>e.user.updateUserPreferences({locale:o}),[e]);return g.jsxs(Aw,{id:"help menu language",children:[g.jsx(Ow,{label:"menu.language","data-direction":"left"}),g.jsx(Rw,{sideOffset:-4,children:g.jsx($o,{children:n.map(({locale:o,label:s})=>g.jsx(gQ,{title:o,checked:o===t,onSelect:()=>r(o),children:g.jsx("span",{className:"tlui-button__label",children:s})},o))})})]})}const _Q=b.memo(function(){const n=tn(),t=be(),[r,o]=$i("help menu");return g.jsx("div",{className:"tlui-help-menu",children:g.jsxs(P3,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[g.jsx(Zc,{asChild:!0,dir:"ltr",children:g.jsx(ae,{type:"help",className:"tlui-button",smallIcon:!0,title:t("help-menu.title"),icon:"question-mark"})}),g.jsx(Mw,{container:n,children:g.jsx(E3,{className:"tlui-menu",side:"top",sideOffset:8,align:"end",alignOffset:0,collisionPadding:4,children:g.jsx(TQ,{})})})]})})});function TQ(){const e=GX(),n=pr();function t(r){if(!r||n&&!r.readonlyOk)return null;switch(r.type){case"custom":{if(r.id==="LANGUAGE_MENU")return g.jsx(_3,{},"item");break}case"group":return g.jsx($o,{size:"small",children:r.children.map(t)},r.id);case"submenu":return g.jsxs(Aw,{id:`help menu ${r.id}`,children:[g.jsx(Ow,{label:r.label}),g.jsx(Rw,{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(Nn,{type:"menu",kbd:s,label:i,onClick:()=>a("help-menu"),iconLeft:l},o)}}}return g.jsx(g.Fragment,{children:e.map(t)})}const T3="Popover",[$3,cte]=so(T3,[Vf]),Dw=Vf(),[$Q,ul]=$3(T3),MQ=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Dw(n),l=b.useRef(null),[c,u]=b.useState(!1),[d=!1,h]=Ns({prop:r,defaultProp:o,onChange:s});return b.createElement(Iw,a,b.createElement($Q,{scope:n,contentId:To(),triggerRef:l,open:d,onOpenChange:h,onOpenToggle:b.useCallback(()=>h(p=>!p),[h]),hasCustomAnchor:c,onCustomAnchorAdd:b.useCallback(()=>u(!0),[]),onCustomAnchorRemove:b.useCallback(()=>u(!1),[]),modal:i},t))},AQ="PopoverTrigger",OQ=b.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ul(AQ,t),s=Dw(t),i=Ge(n,o.triggerRef),a=b.createElement(ze.button,Q({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":O3(o.open)},r,{ref:i,onClick:se(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:b.createElement(Y$,Q({asChild:!0},s),a)}),M3="PopoverPortal",[RQ,DQ]=$3(M3,{forceMount:void 0}),jQ=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=ul(M3,n);return b.createElement(RQ,{scope:n,forceMount:t},b.createElement(jr,{present:t||s.open},b.createElement(Of,{asChild:!0,container:o},r)))},Qc="PopoverContent",LQ=b.forwardRef((e,n)=>{const t=DQ(Qc,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=ul(Qc,e.__scopePopover);return b.createElement(jr,{present:r||s.open},s.modal?b.createElement(NQ,Q({},o,{ref:n})):b.createElement(zQ,Q({},o,{ref:n})))}),NQ=b.forwardRef((e,n)=>{const t=ul(Qc,e.__scopePopover),r=b.useRef(null),o=Ge(n,r),s=b.useRef(!1);return b.useEffect(()=>{const i=r.current;if(i)return dw(i)},[]),b.createElement(uw,{as:mi,allowPinchZoom:!0},b.createElement(A3,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=b.forwardRef((e,n)=>{const t=ul(Qc,e.__scopePopover),r=b.useRef(!1),o=b.useRef(!1);return b.createElement(A3,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()}}))}),A3=b.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=ul(Qc,t),p=Dw(t);return cw(),b.createElement(lw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},b.createElement(Af,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>h.onOpenChange(!1)},b.createElement(X$,Q({"data-state":O3(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 O3(e){return e?"open":"closed"}const FQ=MQ,BQ=OQ,R3=jQ,D3=LQ,jw=({id:e,children:n,onOpenChange:t,open:r})=>{const[o,s]=$i(e,t);return g.jsx(FQ,{onOpenChange:s,open:r||o,children:g.jsx("div",{className:"tlui-popover",children:n})})},Lw=({children:e,disabled:n,"data-testid":t})=>g.jsx(BQ,{"data-testid":t,disabled:n,asChild:!0,dir:"ltr",children:e}),j3=({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0})=>{const s=tn();return g.jsx(R3,{container:s,children:g.jsx(D3,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})},L3=b.memo(function(){const n=be(),t=tn(),r=zX(),o=pr();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(ae,{"data-testid":`menu-item.${i.id}`,icon:l,type:"icon",title:c?u?`${n(c)} ${to(u)}`:`${n(c)}`:u?`${to(u)}`:"",onClick:()=>d("actions-menu"),disabled:i.disabled},a)}}}return g.jsxs(jw,{id:"actions-menu",children:[g.jsx(Lw,{children:g.jsx(ae,{className:"tlui-menu__trigger","data-testid":"main.action-menu",icon:"dots-vertical",title:n("actions-menu.title"),type:"icon",smallIcon:!0})}),g.jsx(R3,{container:t,children:g.jsx(D3,{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)})})})]})}),N3=Re(function(){const n=K(),t=nn(),r=be(),o=t.duplicate;return g.jsx(ae,{icon:o.icon,type:"icon",onClick:()=>o.onSelect("quick-actions"),disabled:!(n.isIn("select")&&n.getSelectedShapeIds().length>0),title:`${r(o.label)} ${to(o.kbd)}`,smallIcon:!0})}),UQ=b.memo(function(){const n=be();return g.jsxs(_s,{id:"main menu",children:[g.jsx(Iu,{children:g.jsx(ae,{type:"icon",className:"tlui-menu__trigger","data-testid":"main.menu",title:n("menu.title"),icon:"menu",smallIcon:!0})}),g.jsx(Ts,{alignOffset:0,sideOffset:6,children:g.jsx(HQ,{})})]})});function HQ(){const e=K(),n=be(),t=XX(),r=fr(),o=pr();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(_3,{},"item"):null;case"group":return o&&!a.readonlyOk?null:g.jsx($o,{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(Aw,{id:`main menu ${l?l.id+" ":""}${a.id}`,children:[g.jsx(Ow,{label:a.label,"data-testid":`menu-item.${a.id}`}),g.jsx(Rw,{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:y,kbd:f}=a.actionItem,m=h??p,S=m?n(m):void 0;return d?g.jsxs(I3,{onSelect:()=>y("menu"),title:S||"",checked:a.checked,disabled:a.disabled,children:[S&&g.jsx("span",{className:"tlui-button__label",children:S}),f&&g.jsx(jf,{children:f})]},u):g.jsx(Nn,{type:"menu","data-testid":`menu-item.${a.id}`,kbd:f,label:m,onClick:()=>y("menu"),disabled:a.disabled},u)}}}return g.jsx(g.Fragment,{children:t.map(i=>s(e,i,null,0))})}const VQ=function({name:n,id:t,isCurrentPage:r}){const o=K(),s=b.useRef(null),i=b.useCallback(l=>{o.renamePage(t,l||"New Page",{ephemeral:!0})},[o,t]),a=b.useCallback(l=>{o.mark("rename page"),o.renamePage(t,l||"New Page",{ephemeral:!1})},[o,t]);return g.jsx(pw,{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})},tv=(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=yo(i.index):!i&&a?o=w8(s[0].index):o=ec(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},$C=Re(function({index:n,listSize:t,item:r,onRename:o}){const s=K(),i=be(),a=s.getPages(),l=b.useCallback(()=>{s.mark("creating page");const h=Mo.createId();s.duplicatePage(r.id,h)},[s,r]),c=b.useCallback(()=>{tv(s,r.id,n,n-1)},[s,r,n]),u=b.useCallback(()=>{tv(s,r.id,n,n+1)},[s,r,n]),d=b.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return g.jsxs(_s,{id:`page item submenu ${n}`,children:[g.jsx(Iu,{children:g.jsx(ae,{type:"icon",title:i("page-menu.submenu.title"),icon:"dots-vertical"})}),g.jsxs(Ts,{alignOffset:0,children:[g.jsxs($o,{children:[o&&g.jsx(Qi,{dir:"ltr",onSelect:o,asChild:!0,children:g.jsx(ae,{type:"menu",label:"page-menu.submenu.rename"})}),g.jsx(Qi,{dir:"ltr",onSelect:l,disabled:a.length>=ep,asChild:!0,children:g.jsx(ae,{type:"menu",label:"page-menu.submenu.duplicate-page"})}),n>0&&g.jsx(Qi,{dir:"ltr",onSelect:c,asChild:!0,children:g.jsx(ae,{type:"menu",label:"page-menu.submenu.move-up"})}),n<t-1&&g.jsx(Qi,{dir:"ltr",onSelect:u,asChild:!0,children:g.jsx(ae,{type:"menu",label:"page-menu.submenu.move-down"})})]}),t>1&&g.jsx($o,{children:g.jsx(Qi,{dir:"ltr",onSelect:d,asChild:!0,children:g.jsx(ae,{type:"menu",label:"page-menu.submenu.delete"})})})]})]})}),KQ=function(){const n=K(),t=be(),r=fr(),o=b.useCallback(()=>m(!1),[]),[s,i]=$i("page-menu",o),a=36,l=b.useRef(null),c=Y("pages",()=>n.getPages(),[n]),u=Y("currentPage",()=>n.getCurrentPage(),[n]),d=Y("currentPageId",()=>n.getCurrentPageId(),[n]),h=pr(),p=Y("maxPageCountReached",()=>n.getPages().length>=ep,[n]),y=Y("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[f,m]=b.useState(!1),S=b.useCallback(()=>{h||m(T=>!T)},[h]),w=b.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[x,C]=b.useState(Object.fromEntries(c.map((T,R)=>[T.id,{y:R*a,offsetY:0,isSelected:!1}])));b.useLayoutEffect(()=>{C(Object.fromEntries(c.map((T,R)=>[T.id,{y:R*a,offsetY:0,isSelected:!1}])))},[a,c]),b.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const R=l.current;if(!R)return;const L=T.offsetTop,N=R.scrollTop;L<N&&R.scrollTo({top:L});const D=L+a,z=R.scrollTop+R.offsetHeight;D>z&&R.scrollTo({top:D-R.offsetHeight})}})},[a,d,s]);const P=b.useCallback(T=>{const{clientY:R,currentTarget:L}=T,{dataset:{id:N,index:D}}=L;if(!N||!D)return;const z=w.current;su(T.currentTarget,T),z.status="pointing",z.pointing={id:N,index:+D};const W=x[N].y;z.startY=R,z.startIndex=Math.max(0,Math.min(Math.round(W/a),c.length-1))},[a,c.length,x]),k=b.useCallback(T=>{const R=w.current;if(R.status==="pointing"){const{clientY:L}=T,N=L-R.startY;Math.abs(N)>5&&(R.status="dragging")}if(R.status==="dragging"){const{clientY:L}=T,N=L-R.startY,D=x[R.pointing.id],{startIndex:z,pointing:F}=R,W=D.y+N,H=Math.max(0,Math.min(Math.round(W/a),c.length-1)),U={...x};if(U[F.id]={y:D.y,offsetY:N,isSelected:!0},H!==R.dragIndex){R.dragIndex=H;for(let V=0;V<c.length;V++){const X=c[V];if(X.id===R.pointing.id)continue;let{y:re}=U[X.id];H===z?re=V*a:H<z?H<=V&&V<z?re=(V+1)*a:re=V*a:H>z&&(H>=V&&V>z?re=(V-1)*a:re=V*a),re!==U[X.id].y&&(U[X.id]={y:re,offsetY:0,isSelected:!0})}}C(U)}},[a,c,x]),I=b.useCallback(T=>{const R=w.current;if(R.status==="dragging"){const{id:L,index:N}=R.pointing;tv(n,L,N,R.dragIndex)}iu(T.currentTarget,T),R.status="idle"},[n]),_=b.useCallback(T=>{const R=w.current;T.key==="Escape"&&(R.status==="dragging"&&C(Object.fromEntries(c.map((L,N)=>[L.id,{y:N*a,offsetY:0,isSelected:!1}]))),R.status="idle")},[a,c]),$=b.useCallback(()=>{h||n.batch(()=>{n.mark("creating page");const T=Mo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),m(!0)})},[n,t,h]);return g.jsxs(jw,{id:"pages",onOpenChange:i,open:s,children:[g.jsx(Lw,{children:g.jsx(ae,{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(j3,{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(ae,{type:"icon","data-testid":"page-menu.edit",title:t(f?"page-menu.edit-done":"page-menu.edit-start"),icon:f?"check":"edit",onClick:S}),g.jsx(ae,{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:$})]})]}),g.jsx("div",{className:"tlui-page-menu__list tlui-menu__group",style:{height:a*c.length+4},ref:l,children:c.map((T,R)=>{const L=x[T.id]??{position:R*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:R,transform:`translate(0px, ${L.y+L.offsetY}px)`},children:[g.jsx(ae,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",icon:"drag-handle-dots",onPointerDown:P,onPointerUp:I,onPointerMove:k,onKeyDown:_,"data-id":T.id,"data-index":R}),r<5&&y?g.jsx(ae,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const N=window.prompt("Rename page",T.name);N&&N!==T.name&&n.renamePage(T.id,N)},onDoubleClick:S,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(VQ,{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($C,{index:R,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(ae,{type:"normal",className:"tlui-page-menu__item__button tlui-page-menu__item__button__checkbox",onClick:()=>n.setCurrentPage(T.id),onDoubleClick:S,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(Hn,{icon:"check"})}),g.jsx("span",{children:T.name})]}),!h&&g.jsx("div",{className:"tlui-page_menu__item__submenu",children:g.jsx($C,{index:R,item:T,listSize:c.length,onRename:()=>{if(n.environment.isIos){const N=window.prompt("Rename page",T.name);N&&N!==T.name&&n.renamePage(T.id,N)}else n.batch(()=>{m(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})},z3=b.memo(function(){const n=be(),t=_$(),o=nn().redo;return g.jsx(ae,{"data-testid":"main.redo",icon:o.icon,type:"icon",title:`${n(o.label)} ${to(o.kbd)}`,disabled:!t,onClick:()=>o.onSelect("quick-actions"),smallIcon:!0})}),F3=Re(function(){const n=K(),t=nn(),r=be(),o=t.delete;return pr()?null:g.jsx(ae,{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)} ${to(o.kbd)}`,smallIcon:!0})}),B3=b.memo(function(){const n=be(),t=T$(),o=nn().undo;return g.jsx(ae,{"data-testid":"main.undo",icon:o.icon,type:"icon",title:`${n(o.label)} ${to(o.kbd)}`,disabled:!t,onClick:()=>o.onSelect("quick-actions"),smallIcon:!0})}),WQ=Re(function(){const n=K(),t=fr(),r=pr();return g.jsx("div",{className:"tlui-menu-zone",children:g.jsxs("div",{className:"tlui-buttons__horizontal",children:[g.jsx(UQ,{}),g.jsx(KQ,{}),t>=6&&!r&&!n.isInAny("hand","zoom")&&g.jsxs(g.Fragment,{children:[g.jsx(B3,{}),g.jsx(z3,{}),g.jsx(F3,{}),g.jsx(N3,{}),g.jsx(L3,{})]})]})})});function GQ(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 pc{constructor(n){v(this,"dpr",1);v(this,"colors",{shapeFill:"rgba(144, 144, 144, .1)",selectFill:"#2f80ed",viewportFill:"rgba(144, 144, 144, .1)"});v(this,"id",Ne());v(this,"cvs",null);v(this,"pageBounds",[]);v(this,"collaborators",[]);v(this,"canvasScreenBounds",new le);v(this,"canvasPageBounds",new le);v(this,"contentPageBounds",new le);v(this,"contentScreenBounds",new le);v(this,"originPagePoint",new E);v(this,"originPageCenter",new E);v(this,"isInViewport",!1);v(this,"debug",!1);v(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)});v(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});v(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}});v(this,"getPagePoint",(n,t)=>{const{contentPageBounds:r,contentScreenBounds:o,canvasPageBounds:s}=this,{x:i,y:a}=this.getScreenPoint(n,t);return new E(s.minX+i*r.width/o.width,s.minY+a*r.height/o.height,1)});v(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,y=((c==null?void 0:c.maxY)??0)+u.height/2,f=Math.max(0,d+u.width-a),m=Math.max(0,-(h-u.width-a)),S=Math.max(0,p+u.height-l),w=Math.max(0,-(y-u.height-l)),x=Math.max(0,f-m),C=Math.max(0,m-f),P=Math.max(0,S-w),k=Math.max(0,w-S);x&&x>C?a+=x/2:C&&(a-=C/2),P&&P>k?l+=P/2:k&&(l-=k/2),a=Hr(a,d,h),l=Hr(l,p,y)}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 E(a,l)});v(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,y=a.height/i.height;h.translate((l-a.width)/2,(c-a.height)/2),h.scale(p,y),h.translate(-i.minX,-i.minY);const f=8/p,m=8/p,S=1/p,w=1/p,x=f/4,C=m/4,P=new Path2D,k=new Path2D,{shapeFill:I,selectFill:_,viewportFill:$}=this.colors;let T;for(let z=0,F=t.length;z<F;z++)T=t[z],pc.roundedRect(u.includes(T.id)?k:P,T.minX,T.minY,T.width,T.height,Hr(f,S,T.width/x),Hr(m,w,T.height/C));if(h.fillStyle=I,h.fill(P),h.fillStyle=_,h.fill(k),this.debug){const z=le.Common(t),{minX:F,minY:W,width:H,height:U}=z;h.strokeStyle="green",h.lineWidth=2/p,h.strokeRect(F+1/p,W+1/y,H-2/p,U-2/y)}{const{brush:z}=r.getInstanceState();if(z){const{x:F,y:W,w:H,h:U}=z;h.beginPath(),pc.sharpRect(h,F,W,H,U),h.closePath(),h.fillStyle=$,h.fill()}}{const{minX:z,minY:F,width:W,height:H}=d;h.beginPath();const U=12/p,V=12/p;pc.roundedRect(h,z,F,W,H,Math.min(W/4,U),Math.min(H/4,V)),h.closePath(),h.fillStyle=$,h.fill(),this.debug&&(h.strokeStyle="orange",h.strokeRect(z+1/p,F+1/y,W-2/p,H-2/y))}const R=2.5/p,L=2.5/y,N=r.getCurrentPageId();let D;for(let z=0;z<this.collaborators.length;z++)D=this.collaborators[z],D.currentPageId===N&&(h.beginPath(),h.ellipse(Hr(D.cursor.x,s.minX+R,s.maxX-R),Hr(D.cursor.y,s.minY+L,s.maxY-L),5/p,5/y,0,0,Ae),h.fillStyle=D.color,h.fill());if(this.debug){h.lineWidth=2/p;{const{minX:z,minY:F,width:W,height:H}=i;h.strokeStyle="red",h.strokeRect(z+1/p,F+1/y,W-2/p,H-2/y)}{const{minX:z,minY:F,width:W,height:H}=s;h.strokeStyle="blue",h.strokeRect(z+1/p,F+1/y,W-2/p,H-2/y)}}});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 YQ({shapeFill:e,selectFill:n,viewportFill:t}){const r=K(),o=b.useRef(null),s=b.useRef(!1),i=nf(),a=rP("dpr",()=>r.getInstanceState().devicePixelRatio,[r]),l=b.useMemo(()=>r.store.query.records("instance_presence"),[r]),c=b.useMemo(()=>new pc(r),[r]);b.useEffect(()=>{const y=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(y)}},[r,n,e,t,c,i]);const u=b.useCallback(y=>{if(!r.getCurrentPageShapeIds().size)return;const f=c.minimapScreenPointToPagePoint(y.clientX,y.clientY,!1,!1),m=c.minimapScreenPointToPagePoint(y.clientX,y.clientY,!1,!0);c.originPagePoint.setTo(m),c.originPageCenter.setTo(r.getViewportPageBounds().center),r.centerOnPoint(f,{duration:wo})},[r,c]),d=b.useCallback(y=>{const f=y.currentTarget;if(su(f,y),!r.getCurrentPageShapeIds().size)return;s.current=!0,c.isInViewport=!1;const m=c.minimapScreenPointToPagePoint(y.clientX,y.clientY,!1,!1),S=c.minimapScreenPointToPagePoint(y.clientX,y.clientY,!1,!0),w=r.getViewportPageBounds();if(c.isInViewport=w.containsPoint(S),c.isInViewport)c.originPagePoint.setTo(S),c.originPageCenter.setTo(w.center);else{const C=E.Sub(w.center,w.point),P=E.Add(m,C);c.originPagePoint.setTo(P),c.originPageCenter.setTo(m),r.centerOnPoint(m,{duration:wo})}function x(C){f&&iu(f,C),s.current=!1,document.body.removeEventListener("pointerup",x)}document.body.addEventListener("pointerup",x)},[r,c]),h=b.useCallback(y=>{const f=c.minimapScreenPointToPagePoint(y.clientX,y.clientY,y.shiftKey,!0);if(s.current){if(c.isInViewport){const x=c.originPagePoint.clone().sub(c.originPageCenter);r.centerOnPoint(E.Sub(f,x));return}r.centerOnPoint(f)}const m=c.getPagePoint(y.clientX,y.clientY),S=r.pageToScreen(m),w={type:"pointer",target:"canvas",name:"pointer_move",...Sn(y),point:S,isPen:r.getInstanceState().isPenMode};r.dispatch(w)},[r,c]),p=b.useCallback(y=>{const f=zP(y);r.dispatch({type:"wheel",name:"wheel",delta:f,point:new E(y.clientX,y.clientY),shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey})},[r]);return ri("update when dpr changes",()=>{const y=a.get();c.setDpr(y);const f=o.current,m=f.getBoundingClientRect(),S=m.width*y,w=m.height*y;f.width=S,f.height=w,c.canvasScreenBounds.set(m.x,m.y,S,w),c.cvs=o.current},[a,c]),ri("minimap render when pagebounds or collaborators changes",()=>{const y=r.getCurrentPageShapeIds(),f=r.getCurrentPageBounds(),m=r.getViewportPageBounds();a.get(),c.contentPageBounds=f?le.Expand(f,m):m,c.updateContentScreenBounds();const S=[];y.forEach(w=>{let x=r.getShapePageBounds(w);if(!x)return;const C=r.getShapeMask(w);if(C){const P=Ey(C,x.corners);if(!P)return;x=le.FromPoints(P)}x&&(x.id=w,S.push(x))}),c.pageBounds=S,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 Vm=Re(function(){const n=K(),t=be(),r=fr(),o=n.getZoomLevel(),s=n.getCurrentPageShapeIds().size>0,i=n.getSelectedShapeIds().length>0,a=n.getZoomLevel()===1,l=b.useCallback(()=>{n.resetZoom(n.getViewportScreenCenter(),{duration:wo})},[n]);return g.jsxs(_s,{id:"zoom",children:[g.jsx(Iu,{children:g.jsx(ae,{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(Ts,{side:"top",align:"start",alignOffset:0,children:g.jsxs($o,{children:[g.jsx(zl,{action:"zoom-in","data-testid":"minimap.zoom-menu.zoom-in",noClose:!0}),g.jsx(zl,{action:"zoom-out","data-testid":"minimap.zoom-menu.zoom-out",noClose:!0}),g.jsx(zl,{action:"zoom-to-100","data-testid":"minimap.zoom-menu.zoom-to-100",noClose:!0,disabled:a}),g.jsx(zl,{action:"zoom-to-fit",disabled:!s,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0}),g.jsx(zl,{action:"zoom-to-selection",disabled:!i,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})]})})]})});function zl(e){const{action:n,disabled:t=!1,noClose:r=!1}=e,o=nn();return g.jsx(Nn,{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 XQ=b.memo(function(){const n=nn(),t=be(),r=fr(),[o,s]=GQ("minimap",!0),i=b.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(Vm,{}):o?g.jsxs(g.Fragment,{children:[g.jsx(Vm,{}),g.jsx(ae,{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(ae,{type:"icon",icon:"minus","data-testid":"minimap.zoom-out",title:`${t(n["zoom-out"].label)} ${to(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone")}),g.jsx(Vm,{}),g.jsx(ae,{type:"icon",icon:"plus","data-testid":"minimap.zoom-in",title:`${t(n["zoom-in"].label)} ${to(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone")}),g.jsx(ae,{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(YQ,{viewportFill:"--color-muted-1",selectFill:"--color-selected",shapeFill:"--color-text-3"})]})}),qQ=Re(function(){const t=K().getInstanceState().isPenMode,r=nn();if(!t)return null;const o=r["exit-pen-mode"];return g.jsx(ae,{type:"normal",label:o.label,iconLeft:o.icon,onClick:()=>o.onSelect("helper-buttons")})}),ZQ=Re(function(){const n=K(),t=nn();if(!n.getInstanceState().followingUserId)return null;const r=t["stop-following"];return g.jsx(ae,{type:"normal",label:r.label,iconLeft:r.icon,onClick:()=>r.onSelect("people-menu")})}),QQ=[cr,li,Ma,Jr];function U3(){const e=K();return Y("getRelevantStyles",()=>{var r;const n=new ky(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 QQ)n.applyValue(o,e.getStyleForNextShape(o));return n.size===0&&!t?null:{styles:n,opacity:e.getSharedOpacity()}},[e])}function JQ(e){const{uiType:n,items:t,title:r,style:o,value:s,onValueChange:i}=e,a=K(),l=be(),c=b.useRef(!1),{handleButtonClick:u,handleButtonPointerDown:d,handleButtonPointerEnter:h,handleButtonPointerUp:p}=b.useMemo(()=>{const f=()=>{c.current=!1,window.removeEventListener("pointerup",f)};return{handleButtonClick:C=>{const{id:P}=C.currentTarget.dataset;s.type==="shared"&&s.value===P||(a.mark("point picker item"),i(o,P,!1))},handleButtonPointerDown:C=>{const{id:P}=C.currentTarget.dataset;a.mark("point picker item"),i(o,P,!0),c.current=!0,window.addEventListener("pointerup",f)},handleButtonPointerEnter:C=>{if(!c.current)return;const{id:P}=C.currentTarget.dataset;i(o,P,!0)},handleButtonPointerUp:C=>{const{id:P}=C.currentTarget.dataset;i(o,P,!1)}}},[s,a,i,o]),y=Y("theme",()=>kn({isDarkMode:a.user.getIsDarkMode()}),[a]);return g.jsx("div",{className:pe("tlui-buttons__grid"),children:t.map(f=>g.jsx(ae,{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:pe("tlui-button-grid__button"),style:o===cr?{color:y[f.value].solid}:void 0,onPointerEnter:h,onPointerDown:d,onPointerUp:p,onClick:u,icon:f.icon},f.value))})}const va=b.memo(JQ);function H3(e,[n,t]){return Math.min(t,Math.max(n,e))}function eJ(e){const n=b.useRef({value:e,previous:e});return b.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}const V3=["PageUp","PageDown"],K3=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],W3={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},_u="Slider",[nv,tJ,nJ]=Mf(_u),[G3,ute]=so(_u,[nJ]),[rJ,Yf]=G3(_u),oJ=b.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,...y}=e,[f,m]=b.useState(null),S=Ge(n,D=>m(D)),w=b.useRef(new Set),x=b.useRef(0),C=i==="horizontal",P=f?!!f.closest("form"):!0,k=C?sJ:iJ,[I=[],_]=Ns({prop:u,defaultProp:c,onChange:D=>{var z;(z=[...w.current][x.current])===null||z===void 0||z.focus(),d(D)}}),$=b.useRef(I);function T(D){const z=gJ(I,D);N(D,z)}function R(D){N(D,x.current)}function L(){const D=$.current[x.current];I[x.current]!==D&&h(I)}function N(D,z,{commit:F}={commit:!1}){const W=SJ(s),H=wJ(Math.round((D-r)/s)*s+r,W),U=H3(H,[r,o]);_((V=[])=>{const X=pJ(V,U,z);if(vJ(X,l*s)){x.current=X.indexOf(U);const re=String(X)!==String(V);return re&&F&&h(X),re?X:V}else return V})}return b.createElement(rJ,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:x,thumbs:w.current,values:I,orientation:i},b.createElement(nv.Provider,{scope:e.__scopeSlider},b.createElement(nv.Slot,{scope:e.__scopeSlider},b.createElement(k,Q({"aria-disabled":a,"data-disabled":a?"":void 0},y,{ref:S,onPointerDown:se(y.onPointerDown,()=>{a||($.current=I)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:T,onSlideMove:a?void 0:R,onSlideEnd:a?void 0:L,onHomeKeyDown:()=>!a&&N(r,0,{commit:!0}),onEndKeyDown:()=>!a&&N(o,I.length-1,{commit:!0}),onStepKeyDown:({event:D,direction:z})=>{if(!a){const H=V3.includes(D.key)||D.shiftKey&&K3.includes(D.key)?10:1,U=x.current,V=I[U],X=s*H*z;N(V+X,U,{commit:!0})}}})))),P&&I.map((D,z)=>b.createElement(hJ,{key:z,name:t?t+(I.length>1?"[]":""):void 0,value:D})))}),[Y3,X3]=G3(_u,{startEdge:"left",endEdge:"right",size:"width",direction:1}),sJ=b.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[d,h]=b.useState(null),p=Ge(n,x=>h(x)),y=b.useRef(),f=ww(o),m=f==="ltr",S=m&&!s||!m&&s;function w(x){const C=y.current||d.getBoundingClientRect(),P=[0,C.width],I=Nw(P,S?[t,r]:[r,t]);return y.current=C,I(x-C.left)}return b.createElement(Y3,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width"},b.createElement(q3,Q({dir:f,"data-orientation":"horizontal"},u,{ref:p,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:x=>{const C=w(x.clientX);i==null||i(C)},onSlideMove:x=>{const C=w(x.clientX);a==null||a(C)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:x=>{const P=W3[S?"from-left":"from-right"].includes(x.key);c==null||c({event:x,direction:P?-1:1})}})))}),iJ=b.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=b.useRef(null),d=Ge(n,u),h=b.useRef(),p=!o;function y(f){const m=h.current||u.current.getBoundingClientRect(),S=[0,m.height],x=Nw(S,p?[r,t]:[t,r]);return h.current=m,x(f-m.top)}return b.createElement(Y3,{scope:e.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1},b.createElement(q3,Q({"data-orientation":"vertical"},c,{ref:d,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:f=>{const m=y(f.clientY);s==null||s(m)},onSlideMove:f=>{const m=y(f.clientY);i==null||i(m)},onSlideEnd:()=>{h.current=void 0,a==null||a()},onStepKeyDown:f=>{const S=W3[p?"from-bottom":"from-top"].includes(f.key);l==null||l({event:f,direction:S?-1:1})}})))}),q3=b.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=Yf(_u,t);return b.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()):V3.concat(K3).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))})}))}),aJ="SliderTrack",lJ=b.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Yf(aJ,t);return b.createElement(ze.span,Q({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),MC="SliderRange",cJ=b.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Yf(MC,t),s=X3(MC,t),i=b.useRef(null),a=Ge(n,i),l=o.values.length,c=o.values.map(h=>Z3(h,o.min,o.max)),u=l>1?Math.min(...c):0,d=100-Math.max(...c);return b.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+"%"}}))}),AC="SliderThumb",uJ=b.forwardRef((e,n)=>{const t=tJ(e.__scopeSlider),[r,o]=b.useState(null),s=Ge(n,a=>o(a)),i=b.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return b.createElement(dJ,Q({},e,{ref:s,index:i}))}),dJ=b.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,s=Yf(AC,t),i=X3(AC,t),[a,l]=b.useState(null),c=Ge(n,m=>l(m)),u=U$(a),d=s.values[r],h=d===void 0?0:Z3(d,s.min,s.max),p=fJ(r,s.values.length),y=u==null?void 0:u[i.size],f=y?mJ(y,h,i.direction):0;return b.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),b.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${h}% + ${f}px)`}},b.createElement(nv.ItemSlot,{scope:e.__scopeSlider},b.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})}))))}),hJ=e=>{const{value:n,...t}=e,r=b.useRef(null),o=eJ(n);return b.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]),b.createElement("input",Q({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function pJ(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function Z3(e,n,t){const s=100/(t-n)*(e-n);return H3(s,[0,100])}function fJ(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function gJ(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 mJ(e,n,t){const r=e/2,s=Nw([0,50],[0,r]);return(r-s(n)*t)*t}function yJ(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function vJ(e,n){if(n>0){const t=yJ(e);return Math.min(...t)>=n}return!0}function Nw(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 SJ(e){return(String(e).split(".")[1]||"").length}function wJ(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const xJ=oJ,bJ=lJ,CJ=cJ,PJ=uJ,EJ=b.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=K(),l=be(),c=b.useCallback(h=>{i(h[0],!0)},[i]),u=b.useCallback(()=>{a.mark("click slider")},[a]),d=b.useCallback(()=>{o&&i(o,!1)},[o,i]);return g.jsx("div",{className:"tlui-slider__container",children:g.jsxs(xJ,{"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(bJ,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&g.jsx(CJ,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&g.jsx(PJ,{className:"tlui-slider__thumb",dir:"ltr"})]})})}),kJ=b.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(),y=b.useMemo(()=>{var m;return((m=i.find(S=>u.type==="shared"&&u.value===S.value))==null?void 0:m.icon)??"mixed"},[i,u]),f=b.useMemo(()=>{var m;return((m=a.find(S=>d.type==="shared"&&d.value===S.value))==null?void 0:m.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(_s,{id:`style panel ${t} A`,children:[g.jsx(Zc,{asChild:!0,onTouchEnd:m=>Ie(m),children:g.jsx(ae,{type:"icon","data-testid":`style.${t}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${u.value}`)),icon:y,invertIcon:!0,smallIcon:!0})}),g.jsx(Ts,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:g.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>g.jsx(Nn,{type:"icon",title:p(o)+" — "+p(`${t}-style.${m.value}`),"data-testid":`style.${t}.${m.value}`,icon:m.icon,onClick:()=>h(l,m.value,!1),invertIcon:!0},m.value))})})]}),g.jsxs(_s,{id:`style panel ${r}`,children:[g.jsx(Zc,{asChild:!0,onTouchEnd:m=>Ie(m),children:g.jsx(ae,{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(Ts,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:g.jsx("div",{className:"tlui-buttons__grid",children:a.map(m=>g.jsx(Nn,{type:"icon",title:p(s)+" — "+p(`${r}-style.${m.value}`),"data-testid":`style.${r}.${m.value}`,icon:m.icon,onClick:()=>h(c,m.value,!1)},m.value))})})]})]})]})}),zw=b.memo(function({id:n,label:t,uiType:r,style:o,items:s,type:i,value:a,onValueChange:l}){const c=be(),u=b.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(_s,{id:`style panel ${n}`,children:[g.jsx(Zc,{asChild:!0,onTouchEnd:d=>Ie(d),children:g.jsx(ae,{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(Ts,{side:"left",align:"center",alignOffset:0,children:g.jsx("div",{className:"tlui-buttons__grid",children:s.map(d=>g.jsx(Nn,{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))})})]})}),Er={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"}]},Q3=function({isMobile:n}){const t=K(),r=U3(),o=b.useCallback(()=>{n||t.updateInstanceState({isChangingStyle:!1})},[t,n]);if(!r)return null;const{styles:s,opacity:i}=r,a=s.get(Yr),l=s.get(Yh),c=s.get(Gh),u=s.get(qh),d=s.get(Qr),h=a===void 0,p=l===void 0&&c===void 0,y=u===void 0,f=d===void 0;return g.jsxs("div",{className:"tlui-style-panel","data-ismobile":n,onPointerLeave:o,children:[g.jsx(IJ,{styles:s,opacity:i}),!f&&g.jsx(_J,{styles:s}),!(h&&p&&y)&&g.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[g.jsx(TJ,{styles:s}),g.jsx(MJ,{styles:s}),g.jsx($J,{styles:s})]})]})};function Tu(){const e=K();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 Fl=[.1,.25,.5,.75,1];function IJ({styles:e,opacity:n}){const t=K(),r=be(),o=Tu(),s=ne.useCallback((h,p)=>{const y=Fl[h];t.batch(()=>{t.isIn("select")&&t.setOpacityForSelectedShapes(y,{ephemeral:p}),t.setOpacityForNextShapes(y,{ephemeral:p}),t.updateInstanceState({isChangingStyle:!0})})},[t]),i=e.get(cr),a=e.get(Ma),l=e.get(li),c=e.get(Jr),u=a!==void 0||l!==void 0||c!==void 0,d=n.type==="mixed"?-1:Fl.indexOf(t5(Fl,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:cr,items:Er.color,value:i,onValueChange:o}),n===void 0?null:g.jsx(EJ,{"data-testid":"style.opacity",value:d>=0?d:Fl.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:s,steps:Fl.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:Er.fill,value:a,onValueChange:o}),l===void 0?null:g.jsx(va,{title:r("style-panel.dash"),uiType:"dash",style:li,items:Er.dash,value:l,onValueChange:o}),c===void 0?null:g.jsx(va,{title:r("style-panel.size"),uiType:"size",style:Jr,items:Er.size,value:c,onValueChange:o})]})]})}function _J({styles:e}){const n=be(),t=Tu(),r=e.get(Qr),o=e.get(yc),s=e.get(Xh);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:Qr,items:Er.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:yc,items:Er.horizontalAlign,value:o,onValueChange:t}),g.jsx("div",{className:"tlui-style-panel__row__extra-button",children:s===void 0?g.jsx(ae,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",icon:"vertical-align-center",disabled:!0}):g.jsx(zw,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:Xh,items:Er.verticalAlign,value:s,onValueChange:t})})]})]})}function TJ({styles:e}){const n=Tu(),t=e.get(Yr);return t===void 0?null:g.jsx(zw,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:Yr,items:Er.geo,value:t,onValueChange:n})}function $J({styles:e}){const n=Tu(),t=e.get(qh);return t===void 0?null:g.jsx(zw,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:qh,items:Er.spline,value:t,onValueChange:n})}function MJ({styles:e}){const n=Tu(),t=e.get(Yh),r=e.get(Gh);return!t||!r?null:g.jsx(kJ,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Gh,itemsA:Er.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Yh,itemsB:Er.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}function AJ({toast:e}){const{removeToast:n}=io(),t=be(),r=s=>{s||n(e.id)},o=e.actions&&e.actions.length>0;return g.jsxs(MG,{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(Hn,{icon:e.icon})}),g.jsxs("div",{className:"tlui-toast__main",children:[g.jsxs("div",{className:"tlui-toast__content",children:[e.title&&g.jsx(AG,{className:"tlui-toast__title",children:e.title}),e.description&&g.jsx(OG,{className:"tlui-toast__description",children:e.description})]}),e.actions&&g.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((s,i)=>g.jsx(RG,{altText:s.label,asChild:!0,onClick:s.onClick,children:g.jsx(ae,{type:s.type,children:s.label})},i)),g.jsx(sC,{asChild:!0,children:g.jsx(ae,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:e.closeLabel??t("toast.close")})})]})]}),!o&&g.jsx(sC,{asChild:!0,children:g.jsx(ae,{type:"normal",className:"tlui-toast__close",children:e.closeLabel??t("toast.close")})})]})}function OJ(){const{toasts:e}=io();return g.jsx(g.Fragment,{children:e.map(n=>g.jsx(AJ,{toast:n},n.id))})}const RJ=b.memo(OJ);function DJ(){const{toasts:e}=io(),[n,t]=b.useState(!1);return b.useEffect(()=>{let r=!1;return e.length?t(!0):setTimeout(()=>{r||t(!1)},1e3),()=>{r=!0}},[e.length,t]),n?g.jsx(fG,{className:"tlui-toast__viewport"}):null}function jJ(){const e=K(),n=be(),t=U3(),r=t==null?void 0:t.styles.get(cr),o=kn({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=Y("isHandOrEraserToolActive",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=b.useCallback(l=>{l||e.updateInstanceState({isChangingStyle:!1})},[e]);return g.jsxs(jw,{id:"style menu",onOpenChange:a,children:[g.jsx(Lw,{disabled:i,children:g.jsx(ae,{type:"tool","data-testid":"mobile.styles",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),children:g.jsx(Hn,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),g.jsx(j3,{side:"top",align:"end",children:g.jsx(Q3,{isMobile:!0})})]})}const LJ=["select","hand","draw","eraser","text","zoom","laser","highlight"];function NJ({activeToolId:e}){const n=K(),t=fr(),r=be(),o=Y("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||LJ.includes(e)?null:g.jsx(ae,{type:"normal",title:r("action.toggle-tool-lock"),className:pe("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<5}),icon:o?"lock":"unlock",onClick:()=>n.updateInstanceState({isToolLocked:!o}),smallIcon:!0})}const zJ=b.memo(function(){const n=K(),t=be(),r=fr(),o=ne.useRef(void 0),s=pr(),i=ZX(),a=i.find(m=>m.toolItem.id==="laser"),l=Y("current tool id",()=>n.getCurrentToolId(),[n]),c=Y("geo",()=>n.getSharedStyles().getAsKnownValue(Yr),[n]),u=!s,d=m=>m.label?`${t(m.label)} ${m.kbd?to(m.kbd):""}`:"",h=i.find(m=>Zi(m.toolItem,l,c)),{itemsInPanel:p,itemsInDropdown:y,dropdownFirstItem:f}=ne.useMemo(()=>{const m=[],S=[];let w;const x=Math.min(8,5+r);for(let C=4;C<i.length;C++){const P=i[C];C<x?m.push(P):(P===h&&(w=P),S.push(P))}return w||(o.current||(o.current=S[0]),w=o.current,S.includes(w)||(w=S[0])),o.current=w,S.length<=2&&(m.push(...S),S.length=0),{itemsInPanel:m,itemsInDropdown:S,dropdownFirstItem:w}},[i,h,r]);return 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&&!(l==="hand"||l==="zoom")&&g.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[g.jsx(B3,{}),g.jsx(z3,{}),g.jsx(F3,{}),g.jsx(N3,{}),g.jsx(L3,{})]}),g.jsx(NJ,{activeToolId:l})]}),g.jsxs("div",{className:pe("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<5}),children:[i.slice(0,2).map(({toolItem:m})=>g.jsx(Bl,{item:m,title:d(m),isSelected:Zi(m,l,c)},m.id)),s&&a&&g.jsx(Bl,{item:a.toolItem,title:d(a.toolItem),isSelected:Zi(a.toolItem,l,c)},a.toolItem.id),u&&g.jsxs(g.Fragment,{children:[i.slice(2,4).map(({toolItem:m})=>g.jsx(Bl,{item:m,title:d(m),isSelected:Zi(m,l,c)},m.id)),p.map(({toolItem:m})=>g.jsx(Bl,{item:m,title:d(m),isSelected:Zi(m,l,c)},m.id)),y.length?g.jsxs(g.Fragment,{children:[g.jsx(Bl,{item:f.toolItem,title:d(f.toolItem),isSelected:Zi(f.toolItem,l,c)},f.toolItem.id),g.jsxs(_s,{id:"toolbar overflow",modal:!1,children:[g.jsx(Iu,{children:g.jsx(ae,{className:"tlui-toolbar__overflow",icon:"chevron-up",type:"tool","data-testid":"tools.more",title:t("tool-panel.more")})}),g.jsx(Ts,{side:"top",align:"center",children:g.jsx(FJ,{toolbarItems:y})})]})]}):null]})]})]}),r<5&&!s&&g.jsx("div",{className:"tlui-toolbar__tools",children:g.jsx(jJ,{})})]})})}),FJ=Re(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(Nn,{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?to(s):""}`:"",icon:l},r))})});function Bl({item:e,title:n,isSelected:t}){var r;return g.jsx(ae,{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=>{Ie(o),e.onSelect("toolbar")}})}const Zi=(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 BJ(){const e=K(),{addToast:n}=io();b.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 Km=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Wm(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function Ul(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.deachEvent&&e.deachEvent("on".concat(n),t)}function J3(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 eM(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 UJ(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 Jc={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,"-":Km?173:189,"=":Km?61:187,";":Km?59:186,"'":222,"[":219,"]":221,"\\":220},ro={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},rv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},$t={16:!1,18:!1,17:!1,91:!1},it={};for(let e=1;e<20;e++)Jc["f".concat(e)]=111+e;let Ue=[],fc=null,tM="all";const mo=new Map,$u=e=>Jc[e.toLowerCase()]||ro[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),HJ=e=>Object.keys(Jc).find(n=>Jc[n]===e),VJ=e=>Object.keys(ro).find(n=>ro[n]===e);function nM(e){tM=e||"all"}function eu(){return tM||"all"}function KJ(){return Ue.slice(0)}function WJ(){return Ue.map(e=>HJ(e)||VJ(e)||String.fromCharCode(e))}function GJ(){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=>$u(a))})})}),e}function YJ(e){const n=e.target||e.srcElement,{tagName:t}=n;let r=!0;return(n.isContentEditable||(t==="INPUT"||t==="TEXTAREA"||t==="SELECT")&&!n.readOnly)&&(r=!1),r}function XJ(e){return typeof e=="string"&&(e=$u(e)),Ue.indexOf(e)!==-1}function qJ(e,n){let t,r;e||(e=eu());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 Fw(a)}):r++;eu()===e&&nM(n||"all")}function ZJ(e){let n=e.keyCode||e.which||e.charCode;const t=Ue.indexOf(n);if(t>=0&&Ue.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&Ue.splice(0,Ue.length),(n===93||n===224)&&(n=91),n in $t){$t[n]=!1;for(const r in ro)ro[r]===n&&(kr[r]=!1)}}function rM(e){if(typeof e>"u")Object.keys(it).forEach(o=>{Array.isArray(it[o])&&it[o].forEach(s=>Ld(s)),delete it[o]}),Fw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Ld(o)});else if(typeof e=="object")e.key&&Ld(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=""),Ld({key:e,scope:o,method:s,splitKey:"+"})}}const Ld=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;eM(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":$u(c);if(!it[u])return;t||(t=eu());const d=l>1?J3(ro,a):[],h=[];it[u]=it[u].filter(p=>{const f=(r?p.method===r:!0)&&p.scope===t&&UJ(p.mods,d);return f&&h.push(p.element),!f}),h.forEach(p=>Fw(p))})};function OC(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 $t)Object.prototype.hasOwnProperty.call($t,s)&&(!$t[s]&&n.mods.indexOf(+s)>-1||$t[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!$t[16]&&!$t[18]&&!$t[17]&&!$t[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(Ue),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function RC(e,n){const t=it["*"];let r=e.keyCode||e.which||e.charCode;if(!kr.filter.call(this,e))return;if((r===93||r===224)&&(r=91),Ue.indexOf(r)===-1&&r!==229&&Ue.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=rv[a];e[a]&&Ue.indexOf(l)===-1?Ue.push(l):!e[a]&&Ue.indexOf(l)>-1?Ue.splice(Ue.indexOf(l),1):a==="metaKey"&&e[a]&&Ue.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(Ue=Ue.slice(Ue.indexOf(l))))}),r in $t){$t[r]=!0;for(const a in ro)ro[a]===r&&(kr[a]=!0);if(!t)return}for(const a in $t)Object.prototype.hasOwnProperty.call($t,a)&&($t[a]=e[rv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Ue.indexOf(17)===-1&&Ue.push(17),Ue.indexOf(18)===-1&&Ue.push(18),$t[17]=!0,$t[18]=!0);const o=eu();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)&&OC(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($u(u[h]));d.sort().join("")===Ue.sort().join("")&&OC(e,l,o,n)}}function kr(e,n,t){Ue=[];const r=eM(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&&rM(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=J3(ro,e)),e=e[e.length-1],e=e==="*"?"*":$u(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(!mo.has(i)){const p=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return RC(f,i)},y=function(){let f=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;RC(f,i),ZJ(f)};mo.set(i,{keydownListener:p,keyupListenr:y,capture:d}),Wm(i,"keydown",p,d),Wm(i,"keyup",y,d)}if(!fc){const p=()=>{Ue=[]};fc={listener:p,capture:d},Wm(window,"focus",p,d)}}}function QJ(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 Fw(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}=mo.get(e)||{};r&&o&&(Ul(e,"keyup",o,s),Ul(e,"keydown",r,s),mo.delete(e))}if((n.length<=0||mo.size<=0)&&(Object.keys(mo).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=mo.get(o)||{};s&&i&&(Ul(o,"keyup",i,a),Ul(o,"keydown",s,a),mo.delete(o))}),mo.clear(),Object.keys(it).forEach(o=>delete it[o]),fc)){const{listener:o,capture:s}=fc;Ul(window,"focus",o,s),fc=null}}const Gm={getPressedKeyString:WJ,setScope:nM,getScope:eu,deleteScope:qJ,getPressedKeyCodes:KJ,getAllKeyCodes:GJ,isPressed:XJ,filter:YJ,trigger:QJ,unbind:rM,keyMap:Jc,modifier:ro,modifierMap:rv};for(const e in Gm)Object.prototype.hasOwnProperty.call(Gm,e)&&(kr[e]=Gm[e]);if(typeof window<"u"){const e=window.hotkeys;kr.noConflict=n=>(n&&window.hotkeys===kr&&(window.hotkeys=e),kr),window.hotkeys=kr}const DC=["copy","cut","paste","asset"];function JJ(){const e=K(),n=pr(),t=nn(),r=Sw(),o=Y("is focused",()=>e.getInstanceState().isFocused,[e]);b.useEffect(()=>{if(!o)return;const s=e.getContainer();kr.setScope(e.store.id);const i=(l,c)=>{kr(l,{element:s,scope:e.store.id},c)},a=()=>e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError();for(const l of Object.values(t))l.kbd&&(n&&!l.readonlyOk||DC.includes(l.id)||i(jC(l.kbd),c=>{a()||(Ie(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&e.getInstanceState().isReadonly||DC.includes(l.id)||i(jC(l.kbd),c=>{a()||(Ie(c),l.onSelect("kbd"))});return()=>{kr.deleteScope(e.store.id)}},[t,r,n,e,o])}function jC(e){return eee(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 eee(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}const tee=ne.memo(function({shareZone:n,topZone:t,renderDebugMenuItems:r,children:o,hideUi:s,...i}){return g.jsx(nq,{...i,children:g.jsx(nee,{hideUi:s,shareZone:n,topZone:t,renderDebugMenuItems:r,children:o})})}),nee=ne.memo(function({children:n,hideUi:t,...r}){return g.jsxs(g.Fragment,{children:[n,t?null:g.jsx(ree,{...r})]})}),ree=ne.memo(function({shareZone:n,topZone:t,renderDebugMenuItems:r}){const o=K(),s=be(),i=fr(),a=Y("isReadonlyMode",()=>o.getInstanceState().isReadonly,[o]),l=Y("focus",()=>o.getInstanceState().isFocusMode,[o]),c=Y("debug",()=>o.getInstanceState().isDebugMode,[o]);JJ(),xX(),BJ();const{"toggle-focus-mode":u}=nn();return g.jsx(TT,{children:g.jsxs("div",{className:pe("tlui-layout",{"tlui-layout__mobile":i<5}),"data-breakpoint":i,children:[l?g.jsx("div",{className:"tlui-layout__top",children:g.jsx(ae,{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(WQ,{}),g.jsxs("div",{className:"tlui-helper-buttons",children:[g.jsx(qQ,{}),g.jsx(oq,{}),g.jsx(ZQ,{})]})]}),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(Q3,{})})]})]}),g.jsxs("div",{className:"tlui-layout__bottom",children:[g.jsxs("div",{className:"tlui-layout__bottom__main",children:[g.jsx(XQ,{}),g.jsx(zJ,{}),i>=4&&g.jsx(_Q,{})]}),c&&g.jsx(yQ,{renderDebugMenuItems:r??null})]})]}),g.jsx(RJ,{}),g.jsx(EQ,{}),g.jsx(DJ,{}),g.jsx(kQ,{})]})})}),oM="ContextMenu",[oee,dte]=so(oM,[Wf]),ao=Wf(),[see,sM]=oee(oM),iee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=b.useState(!1),l=ao(n),c=Jt(r),u=b.useCallback(d=>{a(d),c(d)},[c]);return b.createElement(see,{scope:n,open:i,onOpenChange:u,modal:s},b.createElement(h3,Q({},l,{dir:o,open:i,onOpenChange:u,modal:s}),t))},aee="ContextMenuTrigger",lee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=sM(aee,t),i=ao(t),a=b.useRef({x:0,y:0}),l=b.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=b.useRef(0),u=b.useCallback(()=>window.clearTimeout(c.current),[]),d=h=>{a.current={x:h.clientX,y:h.clientY},s.onOpenChange(!0)};return b.useEffect(()=>u,[u]),b.useEffect(()=>void(r&&u()),[r,u]),b.createElement(b.Fragment,null,b.createElement(p3,Q({},i,{virtualRef:l})),b.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,Nd(h=>{u(),c.current=window.setTimeout(()=>d(h),700)})),onPointerMove:r?e.onPointerMove:se(e.onPointerMove,Nd(u)),onPointerCancel:r?e.onPointerCancel:se(e.onPointerCancel,Nd(u)),onPointerUp:r?e.onPointerUp:se(e.onPointerUp,Nd(u))})))}),cee=e=>{const{__scopeContextMenu:n,...t}=e,r=ao(n);return b.createElement(f3,Q({},r,t))},uee="ContextMenuContent",dee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=sM(uee,t),s=ao(t),i=b.useRef(!1);return b.createElement(g3,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)"}}))}),hee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=ao(t);return b.createElement(m3,Q({},o,r,{ref:n}))}),pee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=ao(t);return b.createElement(y3,Q({},o,r,{ref:n}))}),fee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=ao(t);return b.createElement(v3,Q({},o,r,{ref:n}))}),gee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=ao(n),[a,l]=Ns({prop:o,defaultProp:s,onChange:r});return b.createElement(S3,Q({},i,{open:a,onOpenChange:l}),t)},mee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=ao(t);return b.createElement(w3,Q({},o,r,{ref:n}))}),yee=b.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=ao(t);return b.createElement(x3,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 Nd(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const vee=iee,See=lee,ov=cee,wee=dee,sv=hee,iv=pee,xee=fee,iM=gee,aM=mee,lM=yee,bee=Re(function(){const n=K(),t=tn(),r=n.getPages(),o=n.getCurrentPageId(),s=be(),{addToast:i}=io();return g.jsxs(iM,{children:[g.jsx(aM,{dir:"ltr",asChild:!0,children:g.jsx(ae,{type:"menu",label:"context-menu.move-to-page","data-testid":"menu-item.move-to-page",icon:"chevron-right"})}),g.jsx(ov,{container:t,children:g.jsxs(lM,{className:"tlui-menu",sideOffset:-4,collisionPadding:4,children:[g.jsx(sv,{dir:"ltr",className:"tlui-menu__group","data-testid":"menu-item.pages",children:r.map(a=>g.jsx(iv,{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(ae,{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(sv,{dir:"ltr",className:"tlui-menu__group","data-testid":"menu-item.new-page",children:g.jsx(iv,{onSelect:()=>{const a=Mo.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(ae,{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")]})})]})}),Cee=function({children:n}){const t=K(),r=C$(),o=b.useCallback(d=>{if(d){if(t.getInstanceState().isCoarsePointer){const h=t.getSelectedShapes(),{inputs:{currentPagePoint:p}}=t,y=t.getShapesAtPoint(p);if(!t.getSelectedShapes().length||!y.some(f=>h.includes(f))){const f=y.filter(m=>t.isShapeOrAncestorLocked(m));f.length&&t.select(...f.map(m=>m.id))}}}else{const h=t.getOnlySelectedShape();h&&t.isShapeOrAncestorLocked(h)&&t.setSelectedShapes([])}},[t]),[s,i]=$i("context menu",o),a=pr(),l=r.length===0||a&&r.every(d=>!d.readonlyOk),u=!Y("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t])||l;return g.jsxs(vee,{dir:"ltr",onOpenChange:i,modal:!1,children:[g.jsx(See,{onContextMenu:u?Ie:void 0,dir:"ltr",disabled:u,children:n}),s&&g.jsx(Pee,{})]})},Pee=b.forwardRef(function(){const n=K(),t=be(),r=C$(),[o,s]=$i("context menu sub"),i=pr(),a=fr(),l=tn(),[c,u]=b.useState(!1);function d(h,p,y,f){if(!p||i&&!p.readonlyOk)return null;switch(p.type){case"custom":{switch(p.id){case"MOVE_TO_PAGE_MENU":return g.jsx(bee,{},p.id)}break}case"group":return g.jsx(sv,{dir:"ltr",className:pe("tlui-menu__group",{"tlui-menu__group__small":(y==null?void 0:y.type)==="submenu"}),"data-testid":`menu-item.${p.id}`,children:p.children.map(m=>d(h,m,p,f+1))},p.id);case"submenu":return g.jsxs(iM,{onOpenChange:s,children:[g.jsx(aM,{dir:"ltr",disabled:p.disabled,asChild:!0,children:g.jsx(ae,{type:"menu",label:p.label,"data-testid":`menu-item.${p.id}`,icon:"chevron-right"})}),g.jsx(ov,{container:l,children:g.jsx(lM,{className:"tlui-menu",sideOffset:-4,collisionPadding:4,children:p.children.map(m=>d(h,m,p,f+1))})})]},p.id);case"item":{if(i&&!p.readonlyOk)return null;const{id:m,checkbox:S,contextMenuLabel:w,label:x,onSelect:C,kbd:P,icon:k}=p.actionItem,I=w??x,_=I?t(I):void 0;return S?g.jsxs(xee,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",disabled:p.disabled,onSelect:$=>{C("context-menu"),Ie($)},title:_||void 0,checked:p.checked,children:[g.jsx(Hn,{small:!0,icon:p.checked?"check":"checkbox-empty"}),_&&g.jsx("span",{className:"tlui-button__label",draggable:!1,children:_}),P&&g.jsx(jf,{children:P})]},m):g.jsx(iv,{dir:"ltr",asChild:!0,children:g.jsx(ae,{type:"menu","data-testid":`menu-item.${m}`,kbd:P,label:I,disabled:p.disabled,iconLeft:a<3&&f>2?k:void 0,onClick:()=>{c?u(!1):C("context-menu")}})},m)}}}return g.jsx(ov,{container:l,children:g.jsx(wee,{className:"tlui-menu scrollable",alignOffset:-4,collisionPadding:4,onContextMenu:Ie,children:r.map(h=>d(n,h,null,0))})})}),zd=(e,n)=>{const[t,r]=b.useState(2);return b.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},y=new FontFace(e,`url(${o})`,p);return y.load().then(()=>{h||(document.fonts.add(y),r(0))}).catch(f=>{h||(console.error(f),r(1))}),y.$$_url=o,y.$$_fontface=`
|
|
309
|
+
@font-face {
|
|
310
|
+
font-family: ${y.family};
|
|
311
|
+
font-stretch: ${y.stretch};
|
|
312
|
+
font-weight: ${y.weight};
|
|
313
|
+
font-style: ${y.style};
|
|
314
|
+
src: url("${o}") format("woff2")
|
|
315
|
+
}`,()=>{document.fonts.delete(y),h=!0}},[e,n]),t};function Eee(e){return{draw:{url:e.fonts.draw},serif:{url:e.fonts.serif},sansSerif:{url:e.fonts.sansSerif},monospace:{url:e.fonts.monospace}}}function kee(e){const n=b.useMemo(()=>Eee(e),[e]),t=[zd("tldraw_draw",n.draw),zd("tldraw_serif",n.serif),zd("tldraw_sans",n.sansSerif),zd("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Iee(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,...a}=e,l=sL(a.components??{}),c=Cx(a.shapeUtils??[]),u=Cx(a.tools??[]),d={initialState:"select",...a,components:b.useMemo(()=>({Scribble:vb,CollaboratorScribble:vb,SelectionForeground:fU,SelectionBackground:hU,Handles:iU,HoveredShapeIndicator:aU,...l}),[l]),shapeUtils:b.useMemo(()=>[...IV,...c],[c]),tools:b.useMemo(()=>[...BV,...iH,...u],[u])},h=DG(a.assetUrls),{done:p,error:y}=kee(h);return y?g.jsx(tL,{children:"Could not load assets. Please refresh the page."}):p?g.jsx(Zj,{...d,children:g.jsxs(tee,{...d,children:[g.jsx(Cee,{children:g.jsx(Av,{})}),g.jsx(_ee,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),n]})}):g.jsx(wE,{children:"Loading assets..."})}function _ee({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=K(),i=Tee(a=>{const l=[];return l.push(..._V(a)),GU(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 b.useLayoutEffect(()=>{if(s)return i==null?void 0:i(s)},[s,i]),null}function Tee(e){const n=b.useRef();return b.useLayoutEffect(()=>{n.current=e}),b.useDebugValue(e),b.useCallback((...t)=>{const r=n.current;return oi(r,"fn does not exist"),r(...t)},[])}const $ee=1,Mee=Pe({tldrawFileFormatVersion:E5,schema:Pe({schemaVersion:Bu,storeVersion:Bu,recordVersions:Sy(me,Pe({version:Bu,subTypeVersions:Sy(me,Bu).optional(),subTypeKey:me.optional()}))}),records:ln(Pe({id:me,typeName:me}).allowUnknownProperties())});function Aee(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function Oee({json:e,schema:n}){let t;try{t=Mee.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),Aee(t))return Ks.err({type:"v1File",data:t})}catch{}return Ks.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>$ee)return Ks.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 Ks.err({type:"invalidRecords",cause:o})}if(r.type==="error")return Ks.err({type:"migrationFailed",reason:r.reason});try{return Ks.ok(mE({initialData:r.value,schema:n}))}catch(o){return Ks.err({type:"invalidRecords",cause:o})}}function Ree(){const[e,n]=b.useState(null),[t,r]=b.useState(null),[o,s]=b.useState(null);b.useEffect(()=>{const a=(l,c="svg")=>{n(c),r(l)};window.tldrawExportFile=a},[]),b.useEffect(()=>{if(o&&e&&t){console.log(`tldraw is exporting to ${e}`);try{Dee(o,t)}catch(a){console.error(`error parsing and loading data: ${String(a)}`)}f$(o,[],e,{}).then(()=>{console.log("exported data successfully")}).catch(a=>{console.error(`error exporting data: ${a}`)})}},[o,t,e]);const i=a=>{console.log("tldraw is ready"),s(a)};return g.jsx("div",{style:{inset:0,position:"fixed"},children:g.jsx(Iee,{assetUrls:LA(),onMount:i})})}function Dee(e,n){const t=Oee({json:n,schema:e.store.schema});if(!t.ok)throw new Error(String(t.error));nr(()=>{const{isFocused:r}=e.getInstanceState();e.store.clear();const[o,s]=jee(t.value.allRecords(),a=>a.typeName==="shape");e.store.put(s,"initialize"),e.store.put(o,"initialize"),e.history.clear(),e.updateViewportScreenBounds();const i=e.getCurrentPageBounds();i&&e.zoomToBounds(i,1),e.updateInstanceState({isFocused:r})})}function jee(e,n){const t=[],r=[];for(const o of e)n(o)?t.push(o):r.push(o);return[t,r]}var av={},LC=il;av.createRoot=LC.createRoot,av.hydrateRoot=LC.hydrateRoot;av.createRoot(document.querySelector("#root")).render(g.jsx(ne.StrictMode,{children:g.jsx(Ree,{})}));
|