@kitschpatrol/tldraw-cli 4.6.4 → 4.6.6
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 +9 -9
- package/dist/lib/index.js +7 -7
- package/dist/lib/tldraw-open.d.ts +0 -1
- package/dist/tldraw/assets/index-D1ZVSU0Y.js +327 -0
- package/dist/tldraw/index.html +1 -1
- package/dist/tldraw/translations/main.json +4 -4
- package/package.json +7 -7
- package/dist/tldraw/assets/index-DNvBYIp4.js +0 -323
|
@@ -1,323 +0,0 @@
|
|
|
1
|
-
var hD=Object.defineProperty;var fD=(e,n,t)=>n in e?hD(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var m=(e,n,t)=>fD(e,typeof n!="symbol"?n+"":n,t);function pD(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 on=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Qs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var BI={exports:{}},wp={},UI={exports:{}},we={};/**
|
|
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 Cd=Symbol.for("react.element"),gD=Symbol.for("react.portal"),mD=Symbol.for("react.fragment"),yD=Symbol.for("react.strict_mode"),SD=Symbol.for("react.profiler"),vD=Symbol.for("react.provider"),xD=Symbol.for("react.context"),wD=Symbol.for("react.forward_ref"),bD=Symbol.for("react.suspense"),PD=Symbol.for("react.memo"),CD=Symbol.for("react.lazy"),rb=Symbol.iterator;function ID(e){return e===null||typeof e!="object"?null:(e=rb&&e[rb]||e["@@iterator"],typeof e=="function"?e:null)}var HI={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},KI=Object.assign,WI={};function bc(e,n,t){this.props=e,this.context=n,this.refs=WI,this.updater=t||HI}bc.prototype.isReactComponent={};bc.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")};bc.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function GI(){}GI.prototype=bc.prototype;function Yv(e,n,t){this.props=e,this.context=n,this.refs=WI,this.updater=t||HI}var Xv=Yv.prototype=new GI;Xv.constructor=Yv;KI(Xv,bc.prototype);Xv.isPureReactComponent=!0;var ob=Array.isArray,VI=Object.prototype.hasOwnProperty,qv={current:null},YI={key:!0,ref:!0,__self:!0,__source:!0};function XI(e,n,t){var r,o={},s=null,i=null;if(n!=null)for(r in n.ref!==void 0&&(i=n.ref),n.key!==void 0&&(s=""+n.key),n)VI.call(n,r)&&!YI.hasOwnProperty(r)&&(o[r]=n[r]);var a=arguments.length-2;if(a===1)o.children=t;else if(1<a){for(var c=Array(a),l=0;l<a;l++)c[l]=arguments[l+2];o.children=c}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Cd,type:e,key:s,ref:i,props:o,_owner:qv.current}}function ED(e,n){return{$$typeof:Cd,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function Zv(e){return typeof e=="object"&&e!==null&&e.$$typeof===Cd}function _D(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var sb=/\/+/g;function Lg(e,n){return typeof e=="object"&&e!==null&&e.key!=null?_D(""+e.key):n.toString(36)}function ch(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 Cd:case gD:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+Lg(i,0):r,ob(o)?(t="",e!=null&&(t=e.replace(sb,"$&/")+"/"),ch(o,n,t,"",function(l){return l})):o!=null&&(Zv(o)&&(o=ED(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(sb,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",ob(e))for(var a=0;a<e.length;a++){s=e[a];var c=r+Lg(s,a);i+=ch(s,n,t,c,o)}else if(c=ID(e),typeof c=="function")for(e=c.call(e),a=0;!(s=e.next()).done;)s=s.value,c=r+Lg(s,a++),i+=ch(s,n,t,c,o);else if(s==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return i}function ou(e,n,t){if(e==null)return e;var r=[],o=0;return ch(e,r,"","",function(s){return n.call(t,s,o++)}),r}function kD(e){if(e._status===-1){var n=e._result;n=n(),n.then(function(t){(e._status===0||e._status===-1)&&(e._status=1,e._result=t)},function(t){(e._status===0||e._status===-1)&&(e._status=2,e._result=t)}),e._status===-1&&(e._status=0,e._result=n)}if(e._status===1)return e._result.default;throw e._result}var mn={current:null},lh={transition:null},TD={ReactCurrentDispatcher:mn,ReactCurrentBatchConfig:lh,ReactCurrentOwner:qv};function qI(){throw Error("act(...) is not supported in production builds of React.")}we.Children={map:ou,forEach:function(e,n,t){ou(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return ou(e,function(){n++}),n},toArray:function(e){return ou(e,function(n){return n})||[]},only:function(e){if(!Zv(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};we.Component=bc;we.Fragment=mD;we.Profiler=SD;we.PureComponent=Yv;we.StrictMode=yD;we.Suspense=bD;we.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=TD;we.act=qI;we.cloneElement=function(e,n,t){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=KI({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=qv.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(c in n)VI.call(n,c)&&!YI.hasOwnProperty(c)&&(r[c]=n[c]===void 0&&a!==void 0?a[c]:n[c])}var c=arguments.length-2;if(c===1)r.children=t;else if(1<c){a=Array(c);for(var l=0;l<c;l++)a[l]=arguments[l+2];r.children=a}return{$$typeof:Cd,type:e.type,key:o,ref:s,props:r,_owner:i}};we.createContext=function(e){return e={$$typeof:xD,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:vD,_context:e},e.Consumer=e};we.createElement=XI;we.createFactory=function(e){var n=XI.bind(null,e);return n.type=e,n};we.createRef=function(){return{current:null}};we.forwardRef=function(e){return{$$typeof:wD,render:e}};we.isValidElement=Zv;we.lazy=function(e){return{$$typeof:CD,_payload:{_status:-1,_result:e},_init:kD}};we.memo=function(e,n){return{$$typeof:PD,type:e,compare:n===void 0?null:n}};we.startTransition=function(e){var n=lh.transition;lh.transition={};try{e()}finally{lh.transition=n}};we.unstable_act=qI;we.useCallback=function(e,n){return mn.current.useCallback(e,n)};we.useContext=function(e){return mn.current.useContext(e)};we.useDebugValue=function(){};we.useDeferredValue=function(e){return mn.current.useDeferredValue(e)};we.useEffect=function(e,n){return mn.current.useEffect(e,n)};we.useId=function(){return mn.current.useId()};we.useImperativeHandle=function(e,n,t){return mn.current.useImperativeHandle(e,n,t)};we.useInsertionEffect=function(e,n){return mn.current.useInsertionEffect(e,n)};we.useLayoutEffect=function(e,n){return mn.current.useLayoutEffect(e,n)};we.useMemo=function(e,n){return mn.current.useMemo(e,n)};we.useReducer=function(e,n,t){return mn.current.useReducer(e,n,t)};we.useRef=function(e){return mn.current.useRef(e)};we.useState=function(e){return mn.current.useState(e)};we.useSyncExternalStore=function(e,n,t){return mn.current.useSyncExternalStore(e,n,t)};we.useTransition=function(){return mn.current.useTransition()};we.version="18.3.1";UI.exports=we;var x=UI.exports;const ve=Qs(x),$D=pD({__proto__:null,default:ve},[x]);/**
|
|
10
|
-
* @license React
|
|
11
|
-
* react-jsx-runtime.production.min.js
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var MD=x,AD=Symbol.for("react.element"),jD=Symbol.for("react.fragment"),OD=Object.prototype.hasOwnProperty,DD=MD.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,RD={key:!0,ref:!0,__self:!0,__source:!0};function ZI(e,n,t){var r,o={},s=null,i=null;t!==void 0&&(s=""+t),n.key!==void 0&&(s=""+n.key),n.ref!==void 0&&(i=n.ref);for(r in n)OD.call(n,r)&&!RD.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:AD,type:e,key:s,ref:i,props:o,_owner:DD.current}}wp.Fragment=jD;wp.jsx=ZI;wp.jsxs=ZI;BI.exports=wp;var h=BI.exports;function D(e,n={}){const t=typeof e=="string"?e:e.src;if(typeof n=="function")return n(t);const{baseUrl:r=""}=n;return t.startsWith("data:")||t.match(/^https?:\/\//)?t:`${r.replace(/\/$/,"")}/${t.replace(/^\.?\//,"")}`}function LD(e){return{fonts:{monospace:D("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:D("./fonts/IBMPlexSans-Medium.woff2",e),serif:D("./fonts/IBMPlexSerif-Medium.woff2",e),draw:D("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom":D("./icons/icon/align-bottom.svg",e),"align-center-horizontal":D("./icons/icon/align-center-horizontal.svg",e),"align-center-vertical":D("./icons/icon/align-center-vertical.svg",e),"align-left":D("./icons/icon/align-left.svg",e),"align-right":D("./icons/icon/align-right.svg",e),"align-top":D("./icons/icon/align-top.svg",e),"arrow-left":D("./icons/icon/arrow-left.svg",e),"arrowhead-arrow":D("./icons/icon/arrowhead-arrow.svg",e),"arrowhead-bar":D("./icons/icon/arrowhead-bar.svg",e),"arrowhead-diamond":D("./icons/icon/arrowhead-diamond.svg",e),"arrowhead-dot":D("./icons/icon/arrowhead-dot.svg",e),"arrowhead-none":D("./icons/icon/arrowhead-none.svg",e),"arrowhead-square":D("./icons/icon/arrowhead-square.svg",e),"arrowhead-triangle-inverted":D("./icons/icon/arrowhead-triangle-inverted.svg",e),"arrowhead-triangle":D("./icons/icon/arrowhead-triangle.svg",e),blob:D("./icons/icon/blob.svg",e),"bring-forward":D("./icons/icon/bring-forward.svg",e),"bring-to-front":D("./icons/icon/bring-to-front.svg",e),broken:D("./icons/icon/broken.svg",e),"check-circle":D("./icons/icon/check-circle.svg",e),check:D("./icons/icon/check.svg",e),"chevron-down":D("./icons/icon/chevron-down.svg",e),"chevron-left":D("./icons/icon/chevron-left.svg",e),"chevron-right":D("./icons/icon/chevron-right.svg",e),"chevron-up":D("./icons/icon/chevron-up.svg",e),"chevrons-ne":D("./icons/icon/chevrons-ne.svg",e),"chevrons-sw":D("./icons/icon/chevrons-sw.svg",e),"clipboard-copied":D("./icons/icon/clipboard-copied.svg",e),"clipboard-copy":D("./icons/icon/clipboard-copy.svg",e),color:D("./icons/icon/color.svg",e),"cross-2":D("./icons/icon/cross-2.svg",e),"cross-circle":D("./icons/icon/cross-circle.svg",e),"dash-dashed":D("./icons/icon/dash-dashed.svg",e),"dash-dotted":D("./icons/icon/dash-dotted.svg",e),"dash-draw":D("./icons/icon/dash-draw.svg",e),"dash-solid":D("./icons/icon/dash-solid.svg",e),disconnected:D("./icons/icon/disconnected.svg",e),discord:D("./icons/icon/discord.svg",e),"distribute-horizontal":D("./icons/icon/distribute-horizontal.svg",e),"distribute-vertical":D("./icons/icon/distribute-vertical.svg",e),dot:D("./icons/icon/dot.svg",e),"dots-horizontal":D("./icons/icon/dots-horizontal.svg",e),"dots-vertical":D("./icons/icon/dots-vertical.svg",e),"drag-handle-dots":D("./icons/icon/drag-handle-dots.svg",e),duplicate:D("./icons/icon/duplicate.svg",e),edit:D("./icons/icon/edit.svg",e),"external-link":D("./icons/icon/external-link.svg",e),"fill-fill":D("./icons/icon/fill-fill.svg",e),"fill-none":D("./icons/icon/fill-none.svg",e),"fill-pattern":D("./icons/icon/fill-pattern.svg",e),"fill-semi":D("./icons/icon/fill-semi.svg",e),"fill-solid":D("./icons/icon/fill-solid.svg",e),follow:D("./icons/icon/follow.svg",e),following:D("./icons/icon/following.svg",e),"font-draw":D("./icons/icon/font-draw.svg",e),"font-mono":D("./icons/icon/font-mono.svg",e),"font-sans":D("./icons/icon/font-sans.svg",e),"font-serif":D("./icons/icon/font-serif.svg",e),"geo-arrow-down":D("./icons/icon/geo-arrow-down.svg",e),"geo-arrow-left":D("./icons/icon/geo-arrow-left.svg",e),"geo-arrow-right":D("./icons/icon/geo-arrow-right.svg",e),"geo-arrow-up":D("./icons/icon/geo-arrow-up.svg",e),"geo-check-box":D("./icons/icon/geo-check-box.svg",e),"geo-cloud":D("./icons/icon/geo-cloud.svg",e),"geo-diamond":D("./icons/icon/geo-diamond.svg",e),"geo-ellipse":D("./icons/icon/geo-ellipse.svg",e),"geo-heart":D("./icons/icon/geo-heart.svg",e),"geo-hexagon":D("./icons/icon/geo-hexagon.svg",e),"geo-octagon":D("./icons/icon/geo-octagon.svg",e),"geo-oval":D("./icons/icon/geo-oval.svg",e),"geo-pentagon":D("./icons/icon/geo-pentagon.svg",e),"geo-rectangle":D("./icons/icon/geo-rectangle.svg",e),"geo-rhombus-2":D("./icons/icon/geo-rhombus-2.svg",e),"geo-rhombus":D("./icons/icon/geo-rhombus.svg",e),"geo-star":D("./icons/icon/geo-star.svg",e),"geo-trapezoid":D("./icons/icon/geo-trapezoid.svg",e),"geo-triangle":D("./icons/icon/geo-triangle.svg",e),"geo-x-box":D("./icons/icon/geo-x-box.svg",e),github:D("./icons/icon/github.svg",e),group:D("./icons/icon/group.svg",e),"horizontal-align-end":D("./icons/icon/horizontal-align-end.svg",e),"horizontal-align-middle":D("./icons/icon/horizontal-align-middle.svg",e),"horizontal-align-start":D("./icons/icon/horizontal-align-start.svg",e),"info-circle":D("./icons/icon/info-circle.svg",e),leading:D("./icons/icon/leading.svg",e),link:D("./icons/icon/link.svg",e),lock:D("./icons/icon/lock.svg",e),menu:D("./icons/icon/menu.svg",e),minus:D("./icons/icon/minus.svg",e),mixed:D("./icons/icon/mixed.svg",e),pack:D("./icons/icon/pack.svg",e),plus:D("./icons/icon/plus.svg",e),"question-mark-circle":D("./icons/icon/question-mark-circle.svg",e),"question-mark":D("./icons/icon/question-mark.svg",e),redo:D("./icons/icon/redo.svg",e),"reset-zoom":D("./icons/icon/reset-zoom.svg",e),"rotate-ccw":D("./icons/icon/rotate-ccw.svg",e),"rotate-cw":D("./icons/icon/rotate-cw.svg",e),"send-backward":D("./icons/icon/send-backward.svg",e),"send-to-back":D("./icons/icon/send-to-back.svg",e),"share-1":D("./icons/icon/share-1.svg",e),"size-extra-large":D("./icons/icon/size-extra-large.svg",e),"size-large":D("./icons/icon/size-large.svg",e),"size-medium":D("./icons/icon/size-medium.svg",e),"size-small":D("./icons/icon/size-small.svg",e),"spline-cubic":D("./icons/icon/spline-cubic.svg",e),"spline-line":D("./icons/icon/spline-line.svg",e),"stack-horizontal":D("./icons/icon/stack-horizontal.svg",e),"stack-vertical":D("./icons/icon/stack-vertical.svg",e),"stretch-horizontal":D("./icons/icon/stretch-horizontal.svg",e),"stretch-vertical":D("./icons/icon/stretch-vertical.svg",e),"text-align-center":D("./icons/icon/text-align-center.svg",e),"text-align-left":D("./icons/icon/text-align-left.svg",e),"text-align-right":D("./icons/icon/text-align-right.svg",e),"toggle-off":D("./icons/icon/toggle-off.svg",e),"toggle-on":D("./icons/icon/toggle-on.svg",e),"tool-arrow":D("./icons/icon/tool-arrow.svg",e),"tool-eraser":D("./icons/icon/tool-eraser.svg",e),"tool-frame":D("./icons/icon/tool-frame.svg",e),"tool-hand":D("./icons/icon/tool-hand.svg",e),"tool-highlight":D("./icons/icon/tool-highlight.svg",e),"tool-laser":D("./icons/icon/tool-laser.svg",e),"tool-line":D("./icons/icon/tool-line.svg",e),"tool-media":D("./icons/icon/tool-media.svg",e),"tool-note":D("./icons/icon/tool-note.svg",e),"tool-pencil":D("./icons/icon/tool-pencil.svg",e),"tool-pointer":D("./icons/icon/tool-pointer.svg",e),"tool-screenshot":D("./icons/icon/tool-screenshot.svg",e),"tool-text":D("./icons/icon/tool-text.svg",e),trash:D("./icons/icon/trash.svg",e),twitter:D("./icons/icon/twitter.svg",e),undo:D("./icons/icon/undo.svg",e),ungroup:D("./icons/icon/ungroup.svg",e),unlock:D("./icons/icon/unlock.svg",e),"vertical-align-end":D("./icons/icon/vertical-align-end.svg",e),"vertical-align-middle":D("./icons/icon/vertical-align-middle.svg",e),"vertical-align-start":D("./icons/icon/vertical-align-start.svg",e),"warning-triangle":D("./icons/icon/warning-triangle.svg",e),"zoom-in":D("./icons/icon/zoom-in.svg",e),"zoom-out":D("./icons/icon/zoom-out.svg",e)},translations:{ar:D("./translations/ar.json",e),ca:D("./translations/ca.json",e),cs:D("./translations/cs.json",e),da:D("./translations/da.json",e),de:D("./translations/de.json",e),en:D("./translations/en.json",e),es:D("./translations/es.json",e),fa:D("./translations/fa.json",e),fi:D("./translations/fi.json",e),fr:D("./translations/fr.json",e),gl:D("./translations/gl.json",e),he:D("./translations/he.json",e),"hi-in":D("./translations/hi-in.json",e),hr:D("./translations/hr.json",e),hu:D("./translations/hu.json",e),id:D("./translations/id.json",e),it:D("./translations/it.json",e),ja:D("./translations/ja.json",e),"ko-kr":D("./translations/ko-kr.json",e),ku:D("./translations/ku.json",e),languages:D("./translations/languages.json",e),main:D("./translations/main.json",e),my:D("./translations/my.json",e),ne:D("./translations/ne.json",e),no:D("./translations/no.json",e),pl:D("./translations/pl.json",e),"pt-br":D("./translations/pt-br.json",e),"pt-pt":D("./translations/pt-pt.json",e),ro:D("./translations/ro.json",e),ru:D("./translations/ru.json",e),sl:D("./translations/sl.json",e),sv:D("./translations/sv.json",e),te:D("./translations/te.json",e),th:D("./translations/th.json",e),tr:D("./translations/tr.json",e),uk:D("./translations/uk.json",e),vi:D("./translations/vi.json",e),"zh-cn":D("./translations/zh-cn.json",e),"zh-tw":D("./translations/zh-tw.json",e)},embedIcons:{codepen:D("./embed-icons/codepen.png",e),codesandbox:D("./embed-icons/codesandbox.png",e),desmos:D("./embed-icons/desmos.png",e),excalidraw:D("./embed-icons/excalidraw.png",e),felt:D("./embed-icons/felt.png",e),figma:D("./embed-icons/figma.png",e),github_gist:D("./embed-icons/github_gist.png",e),google_calendar:D("./embed-icons/google_calendar.png",e),google_maps:D("./embed-icons/google_maps.png",e),google_slides:D("./embed-icons/google_slides.png",e),observable:D("./embed-icons/observable.png",e),replit:D("./embed-icons/replit.png",e),scratch:D("./embed-icons/scratch.png",e),spotify:D("./embed-icons/spotify.png",e),tldraw:D("./embed-icons/tldraw.png",e),val_town:D("./embed-icons/val_town.png",e),vimeo:D("./embed-icons/vimeo.png",e),youtube:D("./embed-icons/youtube.png",e)}}}var Wc=function(e){return e&&e.Math===Math&&e},Fn=Wc(typeof globalThis=="object"&&globalThis)||Wc(typeof window=="object"&&window)||Wc(typeof self=="object"&&self)||Wc(typeof on=="object"&&on)||Wc(typeof on=="object"&&on)||function(){return this}()||Function("return this")(),Qv={},yn=function(e){try{return!!e()}catch{return!0}},FD=yn,Js=!FD(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),zD=yn,bp=!zD(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),ND=bp,su=Function.prototype.call,rs=ND?su.bind(su):function(){return su.apply(su,arguments)},QI={},JI={}.propertyIsEnumerable,eE=Object.getOwnPropertyDescriptor,BD=eE&&!JI.call({1:2},1);QI.f=BD?function(n){var t=eE(this,n);return!!t&&t.enumerable}:JI;var tE=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},nE=bp,rE=Function.prototype,Wy=rE.call,UD=nE&&rE.bind.bind(Wy,Wy),Dt=nE?UD:function(e){return function(){return Wy.apply(e,arguments)}},oE=Dt,HD=oE({}.toString),KD=oE("".slice),Pc=function(e){return KD(HD(e),8,-1)},WD=Dt,GD=yn,VD=Pc,Fg=Object,YD=WD("".split),XD=GD(function(){return!Fg("z").propertyIsEnumerable(0)})?function(e){return VD(e)==="String"?YD(e,""):Fg(e)}:Fg,Pp=function(e){return e==null},qD=Pp,ZD=TypeError,Cc=function(e){if(qD(e))throw new ZD("Can't call method on "+e);return e},QD=XD,JD=Cc,Cp=function(e){return QD(JD(e))},zg=typeof document=="object"&&document.all,Sn=typeof zg>"u"&&zg!==void 0?function(e){return typeof e=="function"||e===zg}:function(e){return typeof e=="function"},eR=Sn,Qi=function(e){return typeof e=="object"?e!==null:eR(e)},Ng=Fn,tR=Sn,nR=function(e){return tR(e)?e:void 0},Ip=function(e,n){return arguments.length<2?nR(Ng[e]):Ng[e]&&Ng[e][n]},rR=Dt,sE=rR({}.isPrototypeOf),oR=typeof navigator<"u"&&String(navigator.userAgent)||"",iE=Fn,Bg=oR,ib=iE.process,ab=iE.Deno,cb=ib&&ib.versions||ab&&ab.version,lb=cb&&cb.v8,Or,hf;lb&&(Or=lb.split("."),hf=Or[0]>0&&Or[0]<4?1:+(Or[0]+Or[1]));!hf&&Bg&&(Or=Bg.match(/Edge\/(\d+)/),(!Or||Or[1]>=74)&&(Or=Bg.match(/Chrome\/(\d+)/),Or&&(hf=+Or[1])));var sR=hf,db=sR,iR=yn,aR=Fn,cR=aR.String,aE=!!Object.getOwnPropertySymbols&&!iR(function(){var e=Symbol("symbol detection");return!cR(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&db&&db<41}),lR=aE,cE=lR&&!Symbol.sham&&typeof Symbol.iterator=="symbol",dR=Ip,uR=Sn,hR=sE,fR=cE,pR=Object,lE=fR?function(e){return typeof e=="symbol"}:function(e){var n=dR("Symbol");return uR(n)&&hR(n.prototype,pR(e))},gR=String,mR=function(e){try{return gR(e)}catch{return"Object"}},yR=Sn,SR=mR,vR=TypeError,Jv=function(e){if(yR(e))return e;throw new vR(SR(e)+" is not a function")},xR=Jv,wR=Pp,e0=function(e,n){var t=e[n];return wR(t)?void 0:xR(t)},Ug=rs,Hg=Sn,Kg=Qi,bR=TypeError,PR=function(e,n){var t,r;if(n==="string"&&Hg(t=e.toString)&&!Kg(r=Ug(t,e))||Hg(t=e.valueOf)&&!Kg(r=Ug(t,e))||n!=="string"&&Hg(t=e.toString)&&!Kg(r=Ug(t,e)))return r;throw new bR("Can't convert object to primitive value")},dE={exports:{}},ub=Fn,CR=Object.defineProperty,t0=function(e,n){try{CR(ub,e,{value:n,configurable:!0,writable:!0})}catch{ub[e]=n}return n},IR=Fn,ER=t0,hb="__core-js_shared__",fb=dE.exports=IR[hb]||ER(hb,{});(fb.versions||(fb.versions=[])).push({version:"3.37.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.37.1/LICENSE",source:"https://github.com/zloirock/core-js"});var n0=dE.exports,pb=n0,r0=function(e,n){return pb[e]||(pb[e]=n||{})},_R=Cc,kR=Object,Id=function(e){return kR(_R(e))},TR=Dt,$R=Id,MR=TR({}.hasOwnProperty),ei=Object.hasOwn||function(n,t){return MR($R(n),t)},AR=Dt,jR=0,OR=Math.random(),DR=AR(1 .toString),uE=function(e){return"Symbol("+(e===void 0?"":e)+")_"+DR(++jR+OR,36)},RR=Fn,LR=r0,gb=ei,FR=uE,zR=aE,NR=cE,Ca=RR.Symbol,Wg=LR("wks"),BR=NR?Ca.for||Ca:Ca&&Ca.withoutSetter||FR,os=function(e){return gb(Wg,e)||(Wg[e]=zR&&gb(Ca,e)?Ca[e]:BR("Symbol."+e)),Wg[e]},UR=rs,mb=Qi,yb=lE,HR=e0,KR=PR,WR=os,GR=TypeError,VR=WR("toPrimitive"),YR=function(e,n){if(!mb(e)||yb(e))return e;var t=HR(e,VR),r;if(t){if(n===void 0&&(n="default"),r=UR(t,e,n),!mb(r)||yb(r))return r;throw new GR("Can't convert object to primitive value")}return n===void 0&&(n="number"),KR(e,n)},XR=YR,qR=lE,hE=function(e){var n=XR(e,"string");return qR(n)?n:n+""},ZR=Fn,Sb=Qi,Gy=ZR.document,QR=Sb(Gy)&&Sb(Gy.createElement),fE=function(e){return QR?Gy.createElement(e):{}},JR=Js,e3=yn,t3=fE,pE=!JR&&!e3(function(){return Object.defineProperty(t3("div"),"a",{get:function(){return 7}}).a!==7}),n3=Js,r3=rs,o3=QI,s3=tE,i3=Cp,a3=hE,c3=ei,l3=pE,vb=Object.getOwnPropertyDescriptor;Qv.f=n3?vb:function(n,t){if(n=i3(n),t=a3(t),l3)try{return vb(n,t)}catch{}if(c3(n,t))return s3(!r3(o3.f,n,t),n[t])};var Ic={},d3=Js,u3=yn,gE=d3&&u3(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),h3=Qi,f3=String,p3=TypeError,Ji=function(e){if(h3(e))return e;throw new p3(f3(e)+" is not an object")},g3=Js,m3=pE,y3=gE,iu=Ji,xb=hE,S3=TypeError,Gg=Object.defineProperty,v3=Object.getOwnPropertyDescriptor,Vg="enumerable",Yg="configurable",Xg="writable";Ic.f=g3?y3?function(n,t,r){if(iu(n),t=xb(t),iu(r),typeof n=="function"&&t==="prototype"&&"value"in r&&Xg in r&&!r[Xg]){var o=v3(n,t);o&&o[Xg]&&(n[t]=r.value,r={configurable:Yg in r?r[Yg]:o[Yg],enumerable:Vg in r?r[Vg]:o[Vg],writable:!1})}return Gg(n,t,r)}:Gg:function(n,t,r){if(iu(n),t=xb(t),iu(r),m3)try{return Gg(n,t,r)}catch{}if("get"in r||"set"in r)throw new S3("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var x3=Js,w3=Ic,b3=tE,o0=x3?function(e,n,t){return w3.f(e,n,b3(1,t))}:function(e,n,t){return e[n]=t,e},mE={exports:{}},Vy=Js,P3=ei,yE=Function.prototype,C3=Vy&&Object.getOwnPropertyDescriptor,s0=P3(yE,"name"),I3=s0&&(function(){}).name==="something",E3=s0&&(!Vy||Vy&&C3(yE,"name").configurable),_3={EXISTS:s0,PROPER:I3,CONFIGURABLE:E3},k3=Dt,T3=Sn,Yy=n0,$3=k3(Function.toString);T3(Yy.inspectSource)||(Yy.inspectSource=function(e){return $3(e)});var SE=Yy.inspectSource,M3=Fn,A3=Sn,wb=M3.WeakMap,j3=A3(wb)&&/native code/.test(String(wb)),O3=r0,D3=uE,bb=O3("keys"),vE=function(e){return bb[e]||(bb[e]=D3(e))},i0={},R3=j3,xE=Fn,L3=Qi,F3=o0,qg=ei,Zg=n0,z3=vE,N3=i0,Pb="Object already initialized",Xy=xE.TypeError,B3=xE.WeakMap,ff,Ul,pf,U3=function(e){return pf(e)?Ul(e):ff(e,{})},H3=function(e){return function(n){var t;if(!L3(n)||(t=Ul(n)).type!==e)throw new Xy("Incompatible receiver, "+e+" required");return t}};if(R3||Zg.state){var Zr=Zg.state||(Zg.state=new B3);Zr.get=Zr.get,Zr.has=Zr.has,Zr.set=Zr.set,ff=function(e,n){if(Zr.has(e))throw new Xy(Pb);return n.facade=e,Zr.set(e,n),n},Ul=function(e){return Zr.get(e)||{}},pf=function(e){return Zr.has(e)}}else{var la=z3("state");N3[la]=!0,ff=function(e,n){if(qg(e,la))throw new Xy(Pb);return n.facade=e,F3(e,la,n),n},Ul=function(e){return qg(e,la)?e[la]:{}},pf=function(e){return qg(e,la)}}var wE={set:ff,get:Ul,has:pf,enforce:U3,getterFor:H3},a0=Dt,K3=yn,W3=Sn,au=ei,qy=Js,G3=_3.CONFIGURABLE,V3=SE,bE=wE,Y3=bE.enforce,X3=bE.get,Cb=String,dh=Object.defineProperty,q3=a0("".slice),Z3=a0("".replace),Q3=a0([].join),J3=qy&&!K3(function(){return dh(function(){},"length",{value:8}).length!==8}),eL=String(String).split("String"),tL=mE.exports=function(e,n,t){q3(Cb(n),0,7)==="Symbol("&&(n="["+Z3(Cb(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!au(e,"name")||G3&&e.name!==n)&&(qy?dh(e,"name",{value:n,configurable:!0}):e.name=n),J3&&t&&au(t,"arity")&&e.length!==t.arity&&dh(e,"length",{value:t.arity});try{t&&au(t,"constructor")&&t.constructor?qy&&dh(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=Y3(e);return au(r,"source")||(r.source=Q3(eL,typeof n=="string"?n:"")),e};Function.prototype.toString=tL(function(){return W3(this)&&X3(this).source||V3(this)},"toString");var nL=mE.exports,rL=Sn,oL=Ic,sL=nL,iL=t0,PE=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(rL(t)&&sL(t,s,r),r.global)o?e[n]=t:iL(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:oL.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},CE={},aL=Math.ceil,cL=Math.floor,lL=Math.trunc||function(n){var t=+n;return(t>0?cL:aL)(t)},dL=lL,ea=function(e){var n=+e;return n!==n||n===0?0:dL(n)},uL=ea,hL=Math.max,fL=Math.min,pL=function(e,n){var t=uL(e);return t<0?hL(t+n,0):fL(t,n)},gL=ea,mL=Math.min,IE=function(e){var n=gL(e);return n>0?mL(n,9007199254740991):0},yL=IE,Ed=function(e){return yL(e.length)},SL=Cp,vL=pL,xL=Ed,Ib=function(e){return function(n,t,r){var o=SL(n),s=xL(o);if(s===0)return!e&&-1;var i=vL(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}},wL={includes:Ib(!0),indexOf:Ib(!1)},bL=Dt,Qg=ei,PL=Cp,CL=wL.indexOf,IL=i0,Eb=bL([].push),EE=function(e,n){var t=PL(e),r=0,o=[],s;for(s in t)!Qg(IL,s)&&Qg(t,s)&&Eb(o,s);for(;n.length>r;)Qg(t,s=n[r++])&&(~CL(o,s)||Eb(o,s));return o},c0=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],EL=EE,_L=c0,kL=_L.concat("length","prototype");CE.f=Object.getOwnPropertyNames||function(n){return EL(n,kL)};var _E={};_E.f=Object.getOwnPropertySymbols;var TL=Ip,$L=Dt,ML=CE,AL=_E,jL=Ji,OL=$L([].concat),DL=TL("Reflect","ownKeys")||function(n){var t=ML.f(jL(n)),r=AL.f;return r?OL(t,r(n)):t},_b=ei,RL=DL,LL=Qv,FL=Ic,zL=function(e,n,t){for(var r=RL(n),o=FL.f,s=LL.f,i=0;i<r.length;i++){var a=r[i];!_b(e,a)&&!(t&&_b(t,a))&&o(e,a,s(n,a))}},NL=yn,BL=Sn,UL=/#|\.prototype\./,_d=function(e,n){var t=KL[HL(e)];return t===GL?!0:t===WL?!1:BL(n)?NL(n):!!n},HL=_d.normalize=function(e){return String(e).replace(UL,".").toLowerCase()},KL=_d.data={},WL=_d.NATIVE="N",GL=_d.POLYFILL="P",VL=_d,cu=Fn,YL=Qv.f,XL=o0,qL=PE,ZL=t0,QL=zL,JL=VL,Ec=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,c,l,d;if(r?i=cu:o?i=cu[t]||ZL(t,{}):i=cu[t]&&cu[t].prototype,i)for(a in n){if(l=n[a],e.dontCallGetSet?(d=YL(i,a),c=d&&d.value):c=i[a],s=JL(r?a:t+(o?".":"#")+a,e.forced),!s&&c!==void 0){if(typeof l==typeof c)continue;QL(l,c)}(e.sham||c&&c.sham)&&XL(l,"sham",!0),qL(i,a,l,e)}},kE={},eF=EE,tF=c0,nF=Object.keys||function(n){return eF(n,tF)},rF=Js,oF=gE,sF=Ic,iF=Ji,aF=Cp,cF=nF;kE.f=rF&&!oF?Object.defineProperties:function(n,t){iF(n);for(var r=aF(t),o=cF(t),s=o.length,i=0,a;s>i;)sF.f(n,a=o[i++],r[a]);return n};var lF=Ip,dF=lF("document","documentElement"),uF=Ji,hF=kE,kb=c0,fF=i0,pF=dF,gF=fE,mF=vE,Tb=">",$b="<",Zy="prototype",Qy="script",TE=mF("IE_PROTO"),Jg=function(){},$E=function(e){return $b+Qy+Tb+e+$b+"/"+Qy+Tb},Mb=function(e){e.write($E("")),e.close();var n=e.parentWindow.Object;return e=null,n},yF=function(){var e=gF("iframe"),n="java"+Qy+":",t;return e.style.display="none",pF.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write($E("document.F=Object")),t.close(),t.F},lu,uh=function(){try{lu=new ActiveXObject("htmlfile")}catch{}uh=typeof document<"u"?document.domain&&lu?Mb(lu):yF():Mb(lu);for(var e=kb.length;e--;)delete uh[Zy][kb[e]];return uh()};fF[TE]=!0;var ME=Object.create||function(n,t){var r;return n!==null?(Jg[Zy]=uF(n),r=new Jg,Jg[Zy]=null,r[TE]=n):r=uh(),t===void 0?r:hF.f(r,t)},SF=os,vF=ME,xF=Ic.f,Jy=SF("unscopables"),eS=Array.prototype;eS[Jy]===void 0&&xF(eS,Jy,{configurable:!0,value:vF(null)});var l0=function(e){eS[Jy][e]=!0},wF=Ec,bF=Id,PF=Ed,CF=ea,IF=l0;wF({target:"Array",proto:!0},{at:function(n){var t=bF(this),r=PF(t),o=CF(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});IF("at");var EF=Fn,_F=Dt,kd=function(e,n){return _F(EF[e].prototype[n])},kF=kd;kF("Array","at");var TF=Pc,AE=Array.isArray||function(n){return TF(n)==="Array"},$F=TypeError,MF=9007199254740991,AF=function(e){if(e>MF)throw $F("Maximum allowed index exceeded");return e},jF=Pc,OF=Dt,DF=function(e){if(jF(e)==="Function")return OF(e)},Ab=DF,RF=Jv,LF=bp,FF=Ab(Ab.bind),zF=function(e,n){return RF(e),n===void 0?e:LF?FF(e,n):function(){return e.apply(n,arguments)}},NF=AE,BF=Ed,UF=AF,HF=zF,jE=function(e,n,t,r,o,s,i,a){for(var c=o,l=0,d=i?HF(i,a):!1,u,f;l<r;)l in t&&(u=d?d(t[l],l,n):t[l],s>0&&NF(u)?(f=BF(u),c=jE(e,n,u,f,c,s-1)-1):(UF(c+1),e[c]=u),c++),l++;return c},OE=jE,KF=os,WF=KF("toStringTag"),DE={};DE[WF]="z";var GF=String(DE)==="[object z]",VF=GF,YF=Sn,hh=Pc,XF=os,qF=XF("toStringTag"),ZF=Object,QF=hh(function(){return arguments}())==="Arguments",JF=function(e,n){try{return e[n]}catch{}},RE=VF?hh:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=JF(n=ZF(e),qF))=="string"?t:QF?hh(n):(r=hh(n))==="Object"&&YF(n.callee)?"Arguments":r},e5=Dt,t5=yn,LE=Sn,n5=RE,r5=Ip,o5=SE,FE=function(){},zE=r5("Reflect","construct"),d0=/^\s*(?:class|function)\b/,s5=e5(d0.exec),i5=!d0.test(FE),Gc=function(n){if(!LE(n))return!1;try{return zE(FE,[],n),!0}catch{return!1}},NE=function(n){if(!LE(n))return!1;switch(n5(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return i5||!!s5(d0,o5(n))}catch{return!0}};NE.sham=!0;var a5=!zE||t5(function(){var e;return Gc(Gc.call)||!Gc(Object)||!Gc(function(){e=!0})||e})?NE:Gc,jb=AE,c5=a5,l5=Qi,d5=os,u5=d5("species"),Ob=Array,h5=function(e){var n;return jb(e)&&(n=e.constructor,c5(n)&&(n===Ob||jb(n.prototype))?n=void 0:l5(n)&&(n=n[u5],n===null&&(n=void 0))),n===void 0?Ob:n},f5=h5,BE=function(e,n){return new(f5(e))(n===0?0:n)},p5=Ec,g5=OE,m5=Jv,y5=Id,S5=Ed,v5=BE;p5({target:"Array",proto:!0},{flatMap:function(n){var t=y5(this),r=S5(t),o;return m5(n),o=v5(t,0),o.length=g5(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var x5=l0;x5("flatMap");var w5=kd;w5("Array","flatMap");var b5=Ec,P5=OE,C5=Id,I5=Ed,E5=ea,_5=BE;b5({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=C5(this),r=I5(t),o=_5(t,0);return o.length=P5(o,t,t,r,0,n===void 0?1:E5(n)),o}});var k5=l0;k5("flat");var T5=kd;T5("Array","flat");var $5=RE,M5=String,Td=function(e){if($5(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return M5(e)},A5=Ec,j5=Dt,O5=Cc,D5=ea,R5=Td,L5=yn,F5=j5("".charAt),z5=L5(function(){return"𠮷".at(-2)!=="\uD842"});A5({target:"String",proto:!0,forced:z5},{at:function(n){var t=R5(O5(this)),r=t.length,o=D5(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:F5(t,s)}});var N5=kd;N5("String","at");var B5=Ji,UE=function(){var e=B5(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},u0=yn,U5=Fn,h0=U5.RegExp,f0=u0(function(){var e=h0("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),H5=f0||u0(function(){return!h0("a","y").sticky}),K5=f0||u0(function(){var e=h0("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),W5={BROKEN_CARET:K5,MISSED_STICKY:H5,UNSUPPORTED_Y:f0},G5=yn,V5=Fn,Y5=V5.RegExp,X5=G5(function(){var e=Y5(".","s");return!(e.dotAll&&e.test(`
|
|
18
|
-
`)&&e.flags==="s")}),q5=yn,Z5=Fn,Q5=Z5.RegExp,J5=q5(function(){var e=Q5("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),Ia=rs,Ep=Dt,e6=Td,t6=UE,n6=W5,r6=r0,o6=ME,s6=wE.get,i6=X5,a6=J5,c6=r6("native-string-replace",String.prototype.replace),gf=RegExp.prototype.exec,tS=gf,l6=Ep("".charAt),d6=Ep("".indexOf),u6=Ep("".replace),em=Ep("".slice),nS=function(){var e=/a/,n=/b*/g;return Ia(gf,e,"a"),Ia(gf,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),HE=n6.BROKEN_CARET,rS=/()??/.exec("")[1]!==void 0,h6=nS||rS||HE||i6||a6;h6&&(tS=function(n){var t=this,r=s6(t),o=e6(n),s=r.raw,i,a,c,l,d,u,f;if(s)return s.lastIndex=t.lastIndex,i=Ia(tS,s,o),t.lastIndex=s.lastIndex,i;var p=r.groups,S=HE&&t.sticky,g=Ia(t6,t),w=t.source,y=0,v=o;if(S&&(g=u6(g,"y",""),d6(g,"g")===-1&&(g+="g"),v=em(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&l6(o,t.lastIndex-1)!==`
|
|
19
|
-
`)&&(w="(?: "+w+")",v=" "+v,y++),a=new RegExp("^(?:"+w+")",g)),rS&&(a=new RegExp("^"+w+"$(?!\\s)",g)),nS&&(c=t.lastIndex),l=Ia(gf,S?a:t,v),S?l?(l.input=em(l.input,y),l[0]=em(l[0],y),l.index=t.lastIndex,t.lastIndex+=l[0].length):t.lastIndex=0:nS&&l&&(t.lastIndex=t.global?l.index+l[0].length:c),rS&&l&&l.length>1&&Ia(c6,l[0],a,function(){for(d=1;d<arguments.length-2;d++)arguments[d]===void 0&&(l[d]=void 0)}),l&&p)for(l.groups=u=o6(null),d=0;d<p.length;d++)f=p[d],u[f[0]]=l[f[1]];return l});var p0=tS,f6=Ec,Db=p0;f6({target:"RegExp",proto:!0,forced:/./.exec!==Db},{exec:Db});var p6=bp,KE=Function.prototype,Rb=KE.apply,Lb=KE.call,g6=typeof Reflect=="object"&&Reflect.apply||(p6?Lb.bind(Rb):function(){return Lb.apply(Rb,arguments)}),Fb=rs,zb=PE,m6=p0,Nb=yn,WE=os,y6=o0,S6=WE("species"),tm=RegExp.prototype,v6=function(e,n,t,r){var o=WE(e),s=!Nb(function(){var l={};return l[o]=function(){return 7},""[e](l)!==7}),i=s&&!Nb(function(){var l=!1,d=/a/;return e==="split"&&(d={},d.constructor={},d.constructor[S6]=function(){return d},d.flags="",d[o]=/./[o]),d.exec=function(){return l=!0,null},d[o](""),!l});if(!s||!i||t){var a=/./[o],c=n(o,""[e],function(l,d,u,f,p){var S=d.exec;return S===m6||S===tm.exec?s&&!p?{done:!0,value:Fb(a,d,u,f)}:{done:!0,value:Fb(l,u,d,f)}:{done:!1}});zb(String.prototype,e,c[0]),zb(tm,o,c[1])}r&&y6(tm[o],"sham",!0)},g0=Dt,x6=ea,w6=Td,b6=Cc,P6=g0("".charAt),Bb=g0("".charCodeAt),C6=g0("".slice),Ub=function(e){return function(n,t){var r=w6(b6(n)),o=x6(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=Bb(r,o),i<55296||i>56319||o+1===s||(a=Bb(r,o+1))<56320||a>57343?e?P6(r,o):i:e?C6(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},I6={codeAt:Ub(!1),charAt:Ub(!0)},E6=I6.charAt,_6=function(e,n,t){return n+(t?E6(e,n).length:1)},m0=Dt,k6=Id,T6=Math.floor,nm=m0("".charAt),$6=m0("".replace),rm=m0("".slice),M6=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,A6=/\$([$&'`]|\d{1,2})/g,GE=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,c=A6;return o!==void 0&&(o=k6(o),c=M6),$6(s,c,function(l,d){var u;switch(nm(d,0)){case"$":return"$";case"&":return e;case"`":return rm(n,0,t);case"'":return rm(n,i);case"<":u=o[rm(d,1,-1)];break;default:var f=+d;if(f===0)return l;if(f>a){var p=T6(f/10);return p===0?l:p<=a?r[p-1]===void 0?nm(d,1):r[p-1]+nm(d,1):l}u=r[f-1]}return u===void 0?"":u})},Hb=rs,j6=Ji,O6=Sn,D6=Pc,R6=p0,L6=TypeError,F6=function(e,n){var t=e.exec;if(O6(t)){var r=Hb(t,e,n);return r!==null&&j6(r),r}if(D6(e)==="RegExp")return Hb(R6,e,n);throw new L6("RegExp#exec called on incompatible receiver")},z6=g6,Kb=rs,_p=Dt,N6=v6,B6=yn,U6=Ji,H6=Sn,K6=Pp,W6=ea,G6=IE,da=Td,V6=Cc,Y6=_6,X6=e0,q6=GE,Z6=F6,Q6=os,oS=Q6("replace"),J6=Math.max,ez=Math.min,tz=_p([].concat),om=_p([].push),Wb=_p("".indexOf),Gb=_p("".slice),nz=function(e){return e===void 0?e:String(e)},rz=function(){return"a".replace(/./,"$0")==="$0"}(),Vb=function(){return/./[oS]?/./[oS]("a","$0")==="":!1}(),oz=!B6(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});N6("replace",function(e,n,t){var r=Vb?"$":"$0";return[function(s,i){var a=V6(this),c=K6(s)?void 0:X6(s,oS);return c?Kb(c,s,a,i):Kb(n,da(a),s,i)},function(o,s){var i=U6(this),a=da(o);if(typeof s=="string"&&Wb(s,r)===-1&&Wb(s,"$<")===-1){var c=t(n,i,a,s);if(c.done)return c.value}var l=H6(s);l||(s=da(s));var d=i.global,u;d&&(u=i.unicode,i.lastIndex=0);for(var f=[],p;p=Z6(i,a),!(p===null||(om(f,p),!d));){var S=da(p[0]);S===""&&(i.lastIndex=Y6(a,G6(i.lastIndex),u))}for(var g="",w=0,y=0;y<f.length;y++){p=f[y];for(var v=da(p[0]),P=J6(ez(W6(p.index),a.length),0),E=[],I,C=1;C<p.length;C++)om(E,nz(p[C]));var _=p.groups;if(l){var k=tz([v],E,P,a);_!==void 0&&om(k,_),I=da(z6(s,void 0,k))}else I=q6(v,a,P,E,_,s);P>=w&&(g+=Gb(a,w,P)+I,w=P+v.length)}return g+Gb(a,w)}]},!oz||!rz||Vb);var sz=Qi,iz=Pc,az=os,cz=az("match"),lz=function(e){var n;return sz(e)&&((n=e[cz])!==void 0?!!n:iz(e)==="RegExp")},dz=rs,uz=ei,hz=sE,fz=UE,Yb=RegExp.prototype,pz=function(e){var n=e.flags;return n===void 0&&!("flags"in Yb)&&!uz(e,"flags")&&hz(Yb,e)?dz(fz,e):n},gz=Ec,mz=rs,y0=Dt,Xb=Cc,yz=Sn,Sz=Pp,vz=lz,Vc=Td,xz=e0,wz=pz,bz=GE,Pz=os,Cz=Pz("replace"),Iz=TypeError,sm=y0("".indexOf);y0("".replace);var qb=y0("".slice),Ez=Math.max;gz({target:"String",proto:!0},{replaceAll:function(n,t){var r=Xb(this),o,s,i,a,c,l,d,u,f,p=0,S=0,g="";if(!Sz(n)){if(o=vz(n),o&&(s=Vc(Xb(wz(n))),!~sm(s,"g")))throw new Iz("`.replaceAll` does not allow non-global regexes");if(i=xz(n,Cz),i)return mz(i,n,r,t)}for(a=Vc(r),c=Vc(n),l=yz(t),l||(t=Vc(t)),d=c.length,u=Ez(1,d),p=sm(a,c);p!==-1;)f=l?Vc(t(c,p,a)):bz(c,a,p,[],void 0,t),g+=qb(a,S,p)+f,S=p+d,p=p+u>a.length?-1:sm(a,c,p+u);return S<a.length&&(g+=qb(a,S)),g}});var _z=kd;_z("String","replaceAll");class fh{constructor(n){m(this,"nextValue");m(this,"diff");this.previousValue=n}get(){var r,o,s,i;const n=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,t=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(n===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(n),this.diff??(this.diff={}),t?(r=this.diff.removed)==null||r.delete(n):((o=this.diff).added??(o.added=new Set),this.diff.added.add(n))}add(n){var o,s,i;const t=this.previousValue.has(n);if(t)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(n))?this._add(n,t):void 0;(i=this.nextValue)!=null&&i.has(n)||this._add(n,t)}_remove(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(n),this.diff??(this.diff={}),t?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(n)):(o=this.diff.added)==null||o.delete(n)}remove(n){var o,s,i,a;const t=this.previousValue.has(n);if(!t)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(n))?this._remove(n,t):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(n)||this._remove(n,t)}}var VE="Expected a function",Zb=NaN,kz="[object Symbol]",Tz=/^\s+|\s+$/g,$z=/^[-+]0x[0-9a-f]+$/i,Mz=/^0b[01]+$/i,Az=/^0o[0-7]+$/i,jz=parseInt,Oz=typeof on=="object"&&on&&on.Object===Object&&on,Dz=typeof self=="object"&&self&&self.Object===Object&&self,Rz=Oz||Dz||Function("return this")(),Lz=Object.prototype,Fz=Lz.toString,zz=Math.max,Nz=Math.min,im=function(){return Rz.Date.now()};function Bz(e,n,t){var r,o,s,i,a,c,l=0,d=!1,u=!1,f=!0;if(typeof e!="function")throw new TypeError(VE);n=Qb(n)||0,mf(t)&&(d=!!t.leading,u="maxWait"in t,s=u?zz(Qb(t.maxWait)||0,n):s,f="trailing"in t?!!t.trailing:f);function p(C){var _=r,k=o;return r=o=void 0,l=C,i=e.apply(k,_),i}function S(C){return l=C,a=setTimeout(y,n),d?p(C):i}function g(C){var _=C-c,k=C-l,j=n-_;return u?Nz(j,s-k):j}function w(C){var _=C-c,k=C-l;return c===void 0||_>=n||_<0||u&&k>=s}function y(){var C=im();if(w(C))return v(C);a=setTimeout(y,g(C))}function v(C){return a=void 0,f&&r?p(C):(r=o=void 0,i)}function P(){a!==void 0&&clearTimeout(a),l=0,r=c=o=a=void 0}function E(){return a===void 0?i:v(im())}function I(){var C=im(),_=w(C);if(r=arguments,o=this,c=C,_){if(a===void 0)return S(c);if(u)return a=setTimeout(y,n),p(c)}return a===void 0&&(a=setTimeout(y,n)),i}return I.cancel=P,I.flush=E,I}function Uz(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(VE);return mf(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),Bz(e,n,{leading:r,maxWait:n,trailing:o})}function mf(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function Hz(e){return!!e&&typeof e=="object"}function Kz(e){return typeof e=="symbol"||Hz(e)&&Fz.call(e)==kz}function Qb(e){if(typeof e=="number")return e;if(Kz(e))return Zb;if(mf(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=mf(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(Tz,"");var t=Mz.test(e);return t||Az.test(e)?jz(e.slice(2),t?2:8):$z.test(e)?Zb:+e}var Wz=Uz;const YE=Qs(Wz);var Gz=200,S0="__lodash_hash_undefined__",Vz=1/0,Yz="[object Function]",Xz="[object GeneratorFunction]",qz=/[\\^$.*+?()[\]{}|]/g,Zz=/^\[object .+?Constructor\]$/,Qz=typeof on=="object"&&on&&on.Object===Object&&on,Jz=typeof self=="object"&&self&&self.Object===Object&&self,v0=Qz||Jz||Function("return this")();function eN(e,n){var t=e?e.length:0;return!!t&&nN(e,n,0)>-1}function tN(e,n,t,r){for(var o=e.length,s=t+-1;++s<o;)if(n(e[s],s,e))return s;return-1}function nN(e,n,t){if(n!==n)return tN(e,rN,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function rN(e){return e!==e}function oN(e,n){return e.has(n)}function sN(e,n){return e==null?void 0:e[n]}function iN(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function XE(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var aN=Array.prototype,cN=Function.prototype,qE=Object.prototype,am=v0["__core-js_shared__"],Jb=function(){var e=/[^.]+$/.exec(am&&am.keys&&am.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),ZE=cN.toString,x0=qE.hasOwnProperty,lN=qE.toString,dN=RegExp("^"+ZE.call(x0).replace(qz,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),uN=aN.splice,hN=w0(v0,"Map"),cm=w0(v0,"Set"),Hl=w0(Object,"create");function ji(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 fN(){this.__data__=Hl?Hl(null):{}}function pN(e){return this.has(e)&&delete this.__data__[e]}function gN(e){var n=this.__data__;if(Hl){var t=n[e];return t===S0?void 0:t}return x0.call(n,e)?n[e]:void 0}function mN(e){var n=this.__data__;return Hl?n[e]!==void 0:x0.call(n,e)}function yN(e,n){var t=this.__data__;return t[e]=Hl&&n===void 0?S0:n,this}ji.prototype.clear=fN;ji.prototype.delete=pN;ji.prototype.get=gN;ji.prototype.has=mN;ji.prototype.set=yN;function _c(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 SN(){this.__data__=[]}function vN(e){var n=this.__data__,t=kp(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():uN.call(n,t,1),!0}function xN(e){var n=this.__data__,t=kp(n,e);return t<0?void 0:n[t][1]}function wN(e){return kp(this.__data__,e)>-1}function bN(e,n){var t=this.__data__,r=kp(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}_c.prototype.clear=SN;_c.prototype.delete=vN;_c.prototype.get=xN;_c.prototype.has=wN;_c.prototype.set=bN;function kc(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 PN(){this.__data__={hash:new ji,map:new(hN||_c),string:new ji}}function CN(e){return Tp(this,e).delete(e)}function IN(e){return Tp(this,e).get(e)}function EN(e){return Tp(this,e).has(e)}function _N(e,n){return Tp(this,e).set(e,n),this}kc.prototype.clear=PN;kc.prototype.delete=CN;kc.prototype.get=IN;kc.prototype.has=EN;kc.prototype.set=_N;function yf(e){var n=-1,t=e?e.length:0;for(this.__data__=new kc;++n<t;)this.add(e[n])}function kN(e){return this.__data__.set(e,S0),this}function TN(e){return this.__data__.has(e)}yf.prototype.add=yf.prototype.push=kN;yf.prototype.has=TN;function kp(e,n){for(var t=e.length;t--;)if(LN(e[t][0],n))return t;return-1}function $N(e){if(!QE(e)||ON(e))return!1;var n=FN(e)||iN(e)?dN:Zz;return n.test(DN(e))}function MN(e,n,t){var r=-1,o=eN,s=e.length,i=!0,a=[],c=a;if(s>=Gz){var l=AN(e);if(l)return XE(l);i=!1,o=oN,c=new yf}else c=a;e:for(;++r<s;){var d=e[r],u=d;if(d=d!==0?d:0,i&&u===u){for(var f=c.length;f--;)if(c[f]===u)continue e;a.push(d)}else o(c,u,t)||(c!==a&&c.push(u),a.push(d))}return a}var AN=cm&&1/XE(new cm([,-0]))[1]==Vz?function(e){return new cm(e)}:zN;function Tp(e,n){var t=e.__data__;return jN(n)?t[typeof n=="string"?"string":"hash"]:t.map}function w0(e,n){var t=sN(e,n);return $N(t)?t:void 0}function jN(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function ON(e){return!!Jb&&Jb in e}function DN(e){if(e!=null){try{return ZE.call(e)}catch{}try{return e+""}catch{}}return""}function RN(e){return e&&e.length?MN(e):[]}function LN(e,n){return e===n||e!==e&&n!==n}function FN(e){var n=QE(e)?lN.call(e):"";return n==Yz||n==Xz}function QE(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function zN(){}var NN=RN;const BN=Qs(NN),gl={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},UN=gl.Good;class JE{constructor(){m(this,"startTime",0);m(this,"name","");m(this,"frames",0);m(this,"started",!1);m(this,"frame",null);m(this,"recordFrame",()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))})}start(n){this.name=n,this.frames=0,this.started=!0,this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,this.frame!==null&&cancelAnimationFrame(this.frame);const n=(performance.now()-this.startTime)/1e3,t=n===0?0:Math.floor(this.frames/n),r=t>55?gl.Good:t>30?gl.Mid:gl.Poor,o=r===gl.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${UN};padding: 2px;border-radius: 3px;`,"font-weight: normal",`font-weight: bold; padding: 2px; background: ${r};color: ${o};`,"font-weight: normal")}isStarted(){return this.started}}function b0(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 Se(e){return e.filter(n=>n!=null)}function Nt(e){return e[e.length-1]}function HN(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 KN(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return!1;return!0}class Yo{constructor(){m(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}}function e_(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const Sf=()=>{},fn={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function sn(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const it=e_((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),mr=e_((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function t_(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 e1=new WeakMap;function P0(e,n){if(typeof e!="object"||e===null)return;let t=e1.get(e);t||(t={tags:{},extras:{}},e1.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}async function go(e,n){return window.fetch(e,{referrerPolicy:"strict-origin-when-cross-origin",...n})}const oc=(e,n)=>{const t=new window.Image(e,n);return t.referrerPolicy="strict-origin-when-cross-origin",t};class ki{static async dataUrlToArrayBuffer(n){return go(n).then(function(t){return t.arrayBuffer()})}static async blobToDataUrl(n){return await new Promise((t,r)=>{if(n){const o=new FileReader;o.onload=()=>t(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsDataURL(n)}})}static async blobToText(n){return await new Promise((t,r)=>{if(n){const o=new FileReader;o.onload=()=>t(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsText(n)}})}}function sS(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function WN(e){const n=new DataView(e);let t=0;for(let r=0;r<n.byteLength;r++)t=(t<<5)-t+n.getUint8(r),t|=0;return t+""}/*!
|
|
20
|
-
* MIT License: https://github.com/vHeemstra/is-apng/blob/main/license
|
|
21
|
-
* Copyright (c) Philip van Heemstra
|
|
22
|
-
*/function GN(e){const n=new Uint8Array(e);if(!n||!(typeof Buffer<"u"&&Buffer.isBuffer(n)||n instanceof Uint8Array)||n.length<16||!(n[0]===137&&n[1]===80&&n[2]===78&&n[3]===71&&n[4]===13&&n[5]===10&&n[6]===26&&n[7]===10))return!1;function r(s,i,a,c,l=1024){if(!i)return-1;i=new RegExp(i,"g");const d=i.source.length,u=new TextDecoder,f=s.length;if(typeof c>"u"&&(c=f),a>=f||c<=0||a>=c)return-1;s=s.subarray(a,c);let p=-1,S=0,g=0,w="";e:for(;S<s.length;){const y=S+l,v=s.subarray(S,y),P=u.decode(v,{stream:!0}),E=w+P;let I,C=-1;for(;(I=i.exec(E))!==null;){C=I.index-w.length,p=g+C;break e}S=y,g+=P.length;const _=C>-1?C+d:P.length-d;w=P.slice(_)}return p>=0&&(p+=a>=0?a:f+a),p}const o=r(n,"IDAT",12);return o>=12?r(n,"acTL",8,o)>=8:!1}const VN=e=>new Uint8Array(e)[3]===44;/*!
|
|
23
|
-
* MIT License
|
|
24
|
-
* Modified code originally from <https://github.com/qzb/is-animated>
|
|
25
|
-
* Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
|
|
26
|
-
*/function t1(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function YN(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function XN(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!YN(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+=t1(n,o+1)+1;break;case 33:o+=2,o+=t1(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}let iS=[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"&&(iS=new Int32Array(iS));/*!
|
|
27
|
-
* MIT License: https://github.com/alexgorbatchev/crc/blob/master/LICENSE
|
|
28
|
-
* Copyright: 2014 Alex Gorbatchev
|
|
29
|
-
* Code: crc32, https://github.com/alexgorbatchev/crc/blob/master/src/calculators/crc32.ts
|
|
30
|
-
*/const qN=(e,n)=>{let t=~~n^-1;for(let r=0;r<e.length;r++)t=iS[(t^e[r])&255]^t>>>8;return t^-1},n1=4,r1=4;class no{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(!no.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=no.getChunkType(n,t);if(i==="IDAT"&&r[i]){t+=s+n1+r1;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+n1+r1}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 no.readChunks(n)[t]}static setPhysChunk(n,t=1,r){let o=46,s=0;const i=no.findChunk(n,"pHYs");i&&(o=i.start,s=i.size);const a=no.findChunk(n,"IDAT");a&&(o=a.start,s=0);const c=new ArrayBuffer(21),l=new DataView(c);l.setUint32(0,9),l.setUint8(4,112),l.setUint8(5,72),l.setUint8(6,89),l.setUint8(7,115);const d=2835.5;l.setInt32(8,d*t),l.setInt32(12,d*t),l.setInt8(16,1);const u=new Uint8Array(c.slice(4,17));l.setInt32(17,qN(u));const f=n.buffer.slice(0,o),p=n.buffer.slice(o+s);return new Blob([f,c,p],r)}}/*!
|
|
31
|
-
* MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
|
|
32
|
-
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
33
|
-
*/function ZN(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function QN(e){const n=new Uint8Array(e);return!ZN(n)||!n||n.length<21?!1:(n[20]>>1&1)===1}const n_=Object.freeze(["image/svg+xml"]),r_=Object.freeze(["image/jpeg","image/png","image/webp"]),o_=Object.freeze(["image/gif","image/apng","image/avif"]),C0=Object.freeze([...r_,...n_,...o_]),s_=Object.freeze(["video/mp4","video/webm","video/quicktime"]),JN=[...C0,...s_].join(",");class so{static loadVideo(n){return new Promise((t,r)=>{const o=document.createElement("video");o.onloadeddata=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load video"))},o.crossOrigin="anonymous",o.src=n})}static loadImage(n){return new Promise((t,r)=>{const o=oc();o.onload=()=>t(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.referrerPolicy="strict-origin-when-cross-origin",o.src=n})}static async getVideoSize(n){return so.usingObjectURL(n,async t=>{const r=await so.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await so.usingObjectURL(n,so.loadImage);try{if(n.type==="image/png"){const r=new DataView(await n.arrayBuffer());if(no.isPng(r,0)){const o=no.findChunk(r,"pHYs");if(o){const s=no.parsePhys(r,o.dataOffset);if(s.unit===0&&s.ppux===s.ppuy){const i=Math.max(s.ppux/2834.5,1);return{w:Math.round(t.naturalWidth/i),h:Math.round(t.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:t.naturalWidth,h:t.naturalHeight}}return{w:t.naturalWidth,h:t.naturalHeight}}static async isAnimated(n){return n.type==="image/gif"?XN(await n.arrayBuffer()):n.type==="image/avif"?VN(await n.arrayBuffer()):n.type==="image/webp"?QN(await n.arrayBuffer()):n.type==="image/apng"?GN(await n.arrayBuffer()):!1}static isAnimatedImageType(n){return o_.includes(n||"")}static isStaticImageType(n){return r_.includes(n||"")}static isVectorImageType(n){return n_.includes(n||"")}static isImageType(n){return C0.includes(n)}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function du(e,n,t){return e+(n-e)*t}function Wr(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 sc(e,n,t,r=!1){const[o,s]=n,[i,a]=t,c=i+(e-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(c,a),i):Math.max(Math.min(c,i),a):c}function lo(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function Tn(e,n){if(lo(e,n))return e[n]}function o1(e){return Object.keys(e)}function yt(e){return Object.values(e)}function jn(e){return Object.entries(e)}function i_(e){return Object.fromEntries(e)}function El(e,n){const t={};let r=!1;for(const[o,s]of jn(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function $d(e,n){const t={};for(const[r,o]of jn(e)){const s=n(r,o);t[r]=s}return t}function a_(e,n){if(e===n)return!0;const t=new Set(Object.keys(e)),r=new Set(Object.keys(n));if(t.size!==r.size)return!1;for(const o of t)if(!r.has(o)||!Object.is(e[o],n[o]))return!1;return!0}const Xn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",c_="a0",l_="A00000000000000000000000000";function d_(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 u_(e){if(e.length!==d_(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function s1(e){if(e===void 0)throw Error("n is undefined")}function i1(e){u_(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=Xn.indexOf(t[o])+1;s===Xn.length?t[o]="0":(t[o]=Xn.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 e4(e){u_(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=Xn.indexOf(t[o])-1;s===-1?t[o]=Xn.slice(-1):(t[o]=Xn.charAt(s),r=!1)}if(r){if(n==="a")return"Z"+Xn.slice(-1);if(n==="A")return;const o=String.fromCharCode(n.charCodeAt(0)-1);return o<"Z"?t.push(Xn.slice(-1)):t.pop(),o+t.join("")}else return n+t.join("")}function Ea(e,n){if(n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e.slice(-1)==="0"||n&&n.slice(-1)==="0")throw new Error("trailing zero");if(n){let o=0;for(;(e.charAt(o)||"0")===n.charAt(o);)o++;if(o>0)return n.slice(0,o)+Ea(e.slice(o),n.slice(o))}const t=e?Xn.indexOf(e.charAt(0)):0,r=n!==void 0?Xn.indexOf(n.charAt(0)):Xn.length;if(r-t>1){const o=Math.round(.5*(t+r));return Xn.charAt(o)}else return n&&n.length>1?n.slice(0,1):Xn.charAt(t)+Ea(e.slice(1),void 0)}function ml(e){const n=d_(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function aS(e){if(e===l_)throw new Error("invalid index: "+e);const n=ml(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function ua(e,n){if(e!==void 0&&aS(e),n!==void 0&&aS(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return c_;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=ml(n),c=n.slice(a.length);if(a===l_)return a+Ea("",c);if(a<n)return a;const l=e4(a);return s1(l),l}if(n===void 0){const a=ml(e),c=e.slice(a.length),l=i1(a);return l===void 0?a+Ea(c,void 0):l}const t=ml(e),r=e.slice(t.length),o=ml(n),s=n.slice(o.length);if(t===o)return t+Ea(r,s);const i=i1(t);return s1(i),i<n?i:t+Ea(r,void 0)}function Ks(e,n,t){if(t===0)return[];if(t===1)return[ua(e,n)];if(n===void 0){let s=ua(e,n);const i=[s];for(let a=0;a<t-1;a++)s=ua(s,n),i.push(s);return i}if(e===void 0){let s=ua(e,n);const i=[s];for(let a=0;a<t-1;a++)s=ua(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=ua(e,n);return[...Ks(e,o,r),o,...Ks(o,n,t-r-1)]}const t4=c_;function n4(e){aS(e)}function ic(e,n,t){return Ks(e,n,t)}function lm(e,n){return Ks(e,void 0,n)}function Kl(e,n){return Ks(e,n,1)[0]}function Lo(e){return Ks(e,void 0,1)[0]}function r4(e){return Ks(void 0,e,1)[0]}function Wl(e,n="a1"){return[n,...Ks(n,void 0,e)]}function rn(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function o4(e,n){return e.id>n.id?1:-1}function I0(e){try{return localStorage.getItem(e)}catch{return null}}function E0(e,n){try{localStorage.setItem(e,n)}catch{}}function s4(){try{localStorage.clear()}catch{}}function h_(e){try{return sessionStorage.getItem(e)}catch{return null}}function _0(e,n){try{sessionStorage.setItem(e,n)}catch{}}function f_(e){try{sessionStorage.removeItem(e)}catch{}}function i4(){try{sessionStorage.clear()}catch{}}const a4=()=>typeof process<"u"&&!1,_a=[],c4=60,ph=Math.ceil(1e3/c4);let Yc,dm=0,cS=0;const l4=()=>{const e=_a.splice(0,_a.length);for(const n of e)n()};function p_(){if(Yc)return;const e=Date.now(),n=e-cS;if(dm+n<ph){Yc=requestAnimationFrame(()=>{Yc=void 0,p_()});return}Yc=requestAnimationFrame(()=>{Yc=void 0,cS=e,dm=Math.min(dm+n-ph,ph*10),l4()})}let a1=!1;function g_(e){return a4()?(e(),()=>{}):(_a.includes(e)||(_a.push(e),a1||(a1=!0,cS=Date.now()-ph-1),p_()),()=>{const n=_a.indexOf(e);n>-1&&_a.splice(n,1)})}class d4{constructor(){m(this,"timeouts",[]);m(this,"intervals",[]);m(this,"rafs",[])}setTimeout(n,t,...r){const o=window.setTimeout(n,t,r);return this.timeouts.push(o),o}setInterval(n,t,...r){const o=window.setInterval(n,t,r);return this.intervals.push(o),o}requestAnimationFrame(n){const t=window.requestAnimationFrame(n);return this.rafs.push(t),t}dispose(){this.timeouts.forEach(n=>clearTimeout(n)),this.intervals.forEach(n=>clearInterval(n)),this.rafs.forEach(n=>cancelAnimationFrame(n)),this.timeouts.length=0,this.intervals.length=0,this.rafs.length=0}}function u4(e){return e!==null}function h4(){return typeof globalThis<"u"&&globalThis.structuredClone?[globalThis.structuredClone,!0]:typeof global<"u"&&global.structuredClone?[global.structuredClone,!0]:typeof window<"u"&&window.structuredClone?[window.structuredClone,!0]:[e=>e&&JSON.parse(JSON.stringify(e)),!1]}const m_=h4(),ot=m_[0];m_[1];const f4=Object.getPrototypeOf(ot({}));let Md=(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 $p{constructor(n,t){m(this,"createDefaultProperties");m(this,"validator");m(this,"ephemeralKeys");m(this,"ephemeralKeySet");m(this,"scope");m(this,"isInstance",n=>(n==null?void 0:n.typeName)===this.typeName);this.typeName=n,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:o=>o},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const r=new Set;if(t.ephemeralKeys)for(const[o,s]of jn(t.ephemeralKeys))s&&r.add(o);this.ephemeralKeySet=r}create(n){const t={...this.createDefaultProperties(),id:this.createId()};for(const[r,o]of Object.entries(n))o!==void 0&&(t[r]=o);return t.typeName=this.typeName,t}clone(n){return{...ot(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??Md())}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 $p(this.typeName,{createDefaultProperties:n,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(n,t){return t&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(t,n):this.validator.validate(n)}}function bo(e,n){return new $p(e,{createDefaultProperties:()=>({}),validator:n.validator,scope:n.scope,ephemeralKeys:n.ephemeralKeys})}function vf(){return{added:{},updated:{},removed:{}}}function lS(e){const n={added:e.removed,removed:e.added,updated:{}};for(const[t,r]of Object.values(e.updated))n.updated[t.id]=[r,t];return n}function y_(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function k0(e){const n={added:{},removed:{},updated:{}};return _l(n,e),n}function _l(e,n){for(const t of n){for(const[r,o]of jn(t.added))if(e.removed[r]){const s=e.removed[r];delete e.removed[r],s!==o&&(e.updated[r]=[s,o])}else e.added[r]=o;for(const[r,[o,s]]of jn(t.updated)){if(e.added[r]){e.added[r]=s,delete e.updated[r],delete e.removed[r];continue}if(e.updated[r]){e.updated[r]=[e.updated[r][0],s],delete e.removed[r];continue}e.updated[r]=t.updated[r],delete e.removed[r]}for(const[r,o]of jn(t.removed))e.added[r]?delete e.added[r]:e.updated[r]?(e.removed[r]=e.updated[r][0],delete e.updated[r]):e.removed[r]=o}}function S_(e){return e&&typeof e=="object"&&"parents"in e}function v_(e){for(let n=0,t=e.parents.length;n<t;n++)if(e.parents[n].__unsafe__getWithoutCapture(!0),e.parents[n].lastChangedEpoch!==e.parentEpochs[n])return!0;return!1}const xf=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&S_(e))for(let t=0,r=e.parents.length;t<r;t++)xf(e.parents[t],e)},T0=(e,n)=>{if(e.children.add(n)&&S_(e))for(let t=0,r=e.parents.length;t<r;t++)T0(e.parents[t],e)};function x_(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function ti(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const Ho=ti("empty_array",()=>Object.freeze([])),c1=8;class wf{constructor(){m(this,"arraySize",0);m(this,"array",Array(c1));m(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<c1?(this.array[this.arraySize]=n,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(n),!0);if(this.set)return this.set.has(n)?!1:(this.set.add(n),!0);throw new Error("no set or array")}remove(n){if(this.array){const t=this.array.indexOf(n);return t===-1?!1:(this.array[t]=void 0,this.arraySize--,t!==this.arraySize&&(this.array[t]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(n)?(this.set.delete(n),!0):!1;throw new Error("no set or array")}visit(n){if(this.array){for(let t=0;t<this.arraySize;t++){const r=this.array[t];typeof r<"u"&&n(r)}return}if(this.set){this.set.forEach(n);return}throw new Error("no set or array")}has(n){return this.array?this.array.indexOf(n)!==-1:this.set.has(n)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}const Zn=Symbol.for("com.tldraw.state/RESET_VALUE");class w_{constructor(n){m(this,"index",0);m(this,"buffer");this.capacity=n,this.buffer=new Array(n)}pushEntry(n,t,r){if(r!==void 0){if(r===Zn){this.clear();return}this.buffer[this.index]=[n,t,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(n){const{index:t,capacity:r,buffer:o}=this;for(let s=0;s<r;s++){const i=(t-1+r-s)%r,a=o[i];if(!a)return Zn;const[c,l]=a;if(s===0&&n>=l)return[];if(c<=n&&n<l){const d=s+1,u=new Array(d);for(let f=0;f<d;f++)u[f]=o[(i+f)%r][2];return u}}return Zn}}class p4{constructor(n,t){m(this,"offset",0);m(this,"maybeRemoved");this.below=n,this.child=t}}const nt=ti("capture",()=>({stack:null}));function um(e){const n=nt.stack;nt.stack=null;try{return e()}finally{nt.stack=n}}function b_(e){nt.stack=new p4(nt.stack,e),e.parentSet.clear()}function P_(){const e=nt.stack;if(nt.stack=e.below,e.offset<e.child.parents.length){for(let n=e.offset;n<e.child.parents.length;n++){const t=e.child.parents[n];e.child.parentSet.has(t)||xf(t,e.child)}e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset}if(e.maybeRemoved)for(let n=0;n<e.maybeRemoved.length;n++){const t=e.maybeRemoved[n];e.child.parentSet.has(t)||xf(t,e.child)}}function bf(e){if(nt.stack){if(nt.stack.child.parentSet.has(e))return;if(nt.stack.child.parentSet.add(e),nt.stack.child.isActivelyListening&&T0(e,nt.stack.child),nt.stack.offset<nt.stack.child.parents.length){const t=nt.stack.child.parents[nt.stack.offset];t!==e&&(nt.stack.maybeRemoved?nt.stack.maybeRemoved.push(t):nt.stack.maybeRemoved=[t])}nt.stack.child.parents[nt.stack.offset]=e,nt.stack.child.parentEpochs[nt.stack.offset]=e.lastChangedEpoch,nt.stack.offset++}}const _s=-1;class g4{constructor(n,t,r){m(this,"_isActivelyListening",!1);m(this,"lastTraversedEpoch",_s);m(this,"lastReactedEpoch",_s);m(this,"_scheduleCount",0);m(this,"parentSet",new wf);m(this,"parentEpochs",[]);m(this,"parents",[]);m(this,"_scheduleEffect");m(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=n,this.runEffect=t,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==Cn()){if(this.parents.length&&!v_(this)){this.lastReactedEpoch=Cn();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let n=0,t=this.parents.length;n<t;n++)T0(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)xf(this.parents[n],this)}execute(){try{b_(this);const n=Cn(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=n,t}finally{P_()}}}const Tc=ti("EffectScheduler",()=>g4);function ta(e,n,t){const r=new Tc(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function m4(e,n,t){const r=new Tc(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 y4{constructor(n){m(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){this.isRoot?C_(this.initialAtomValues.keys()):this.initialAtomValues.forEach((n,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,n)})}abort(){Ne.globalEpoch++,this.initialAtomValues.forEach((n,t)=>{var r;t.set(n),(r=t.historyBuffer)==null||r.clear()}),this.commit()}}const Ne=ti("transactions",()=>({globalEpoch:_s+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:_s+1}));function S4(){return Ne.reactionEpoch}function Cn(){return Ne.globalEpoch}function v4(){return Ne.globalIsReacting}function $0(e,n){n.lastTraversedEpoch!==Ne.globalEpoch&&(n.lastTraversedEpoch=Ne.globalEpoch,n instanceof Tc?e.add(n):n.children.visit(t=>$0(e,t)))}function C_(e){var n;if(Ne.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{Ne.globalIsReacting=!0,Ne.reactionEpoch=Ne.globalEpoch;const t=new Set;for(const o of e)o.children.visit(s=>$0(t,s));for(const o of t)o.maybeScheduleEffect();let r=0;for(;(n=Ne.cleanupReactors)!=null&&n.size;){if(r++>1e3)throw new Error("Reaction update depth limit exceeded");const o=Ne.cleanupReactors;Ne.cleanupReactors=null;for(const s of o)s.maybeScheduleEffect()}}finally{Ne.cleanupReactors=null,Ne.globalIsReacting=!1}}function x4(e,n){if(Ne.globalIsReacting){const t=Ne.cleanupReactors??(Ne.cleanupReactors=new Set);e.children.visit(r=>$0(t,r))}else Ne.currentTransaction?Ne.currentTransaction.initialAtomValues.has(e)||Ne.currentTransaction.initialAtomValues.set(e,n):C_([e])}function w4(){Ne.globalEpoch++}function b4(e){const n=new y4(Ne.currentTransaction);Ne.currentTransaction=n;try{let t,r=!1;try{t=e(()=>r=!0)}catch(o){throw n.abort(),o}return r?n.abort():n.commit(),t}finally{Ne.currentTransaction=Ne.currentTransaction.parent}}function As(e){return Ne.currentTransaction?e():b4(e)}class P4{constructor(n,t,r){m(this,"isEqual");m(this,"computeDiff");m(this,"lastChangedEpoch",Cn());m(this,"children",new wf);m(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new w_(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(n){return this.current}get(){return bf(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??x_(this.current,n))return this.current;w4(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,Cn(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,Cn()))??Zn),this.lastChangedEpoch=Cn();const r=this.current;return this.current=n,x4(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return bf(this),n>=this.lastChangedEpoch?Ho:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Zn}}const C4=ti("Atom",()=>P4);function Mt(e,n,t){return new C4(e,n,t)}let l1=!1;function I4(){l1||(l1=!0,console.warn(`Using \`@computed\` as a decorator for getters is deprecated and will be removed in the near future. Please refactor to use \`@computed\` as a decorator for methods.
|
|
34
|
-
|
|
35
|
-
// Before
|
|
36
|
-
@computed
|
|
37
|
-
get foo() {
|
|
38
|
-
return 'foo'
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// After
|
|
42
|
-
@computed
|
|
43
|
-
getFoo() {
|
|
44
|
-
return 'foo'
|
|
45
|
-
}
|
|
46
|
-
`))}const yl=Symbol.for("com.tldraw.state/UNINITIALIZED"),Ti=e=>e===yl,dS=ti("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function Sl(e,n){return new dS(e,n)}class E4{constructor(n,t,r){m(this,"lastChangedEpoch",_s);m(this,"lastTraversedEpoch",_s);m(this,"lastCheckedEpoch",_s);m(this,"parentSet",new wf);m(this,"parents",[]);m(this,"parentEpochs",[]);m(this,"children",new wf);m(this,"historyBuffer");m(this,"state",yl);m(this,"error",null);m(this,"computeDiff");m(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new w_(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??x_}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(n){var o;const t=this.lastChangedEpoch===_s,r=Cn();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&v4()&&this.lastTraversedEpoch<S4()||!v_(this)))if(this.lastCheckedEpoch=r,this.error){if(n)return this.state;throw this.error.thrownValue}else return this.state;try{b_(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof dS?s.value:s,a=this.state===yl;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const c=s instanceof dS?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,Cn(),c??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,Cn()))??Zn)}this.lastChangedEpoch=Cn(),this.state=i}return this.error=null,this.lastCheckedEpoch=Cn(),this.state}catch(s){if(this.state!==yl&&(this.state=yl,this.lastChangedEpoch=Cn()),this.lastCheckedEpoch=Cn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!n)throw s;return this.state}finally{P_()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{bf(this)}}getDiffSince(n){var t;return this.__unsafe__getWithoutCapture(!0),bf(this),n>=this.lastChangedEpoch?Ho:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Zn}}const M0=ti("Computed",()=>E4);function _4(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 M0(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[T4]=!0,r}function d1(e={},n,t,r){return r.get?(I4(),k4(e,n,t,r)):_4(e,n,t,r)}function k4(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 M0(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const T4="@@__isComputedMethod__@@";function V(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>d1(e,n,t,r)}else return typeof arguments[0]=="string"?new M0(arguments[0],arguments[1],arguments[2]):d1(void 0,arguments[0],arguments[1],arguments[2])}const I_=1,$4=ti("apiVersion",()=>I_);if($4!==I_)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function Mp(e,n){const t=ve.useRef(n);t.current=n;const[r,o,s]=ve.useMemo(()=>{let i=null;const a=d=>(i=d,()=>{i=null}),c=new Tc(`useStateTracking(${e})`,()=>{var d;return(d=t.current)==null?void 0:d.call(t)},{scheduleEffect(){i==null||i()}});return[c,a,()=>c.scheduleCount]},[e]);return ve.useSyncExternalStore(o,s,s),ve.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const u1={apply(e,n,t){return Mp(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},M4=Symbol.for("react.memo"),A4=Symbol.for("react.forward_ref");function sr(e){let n=null;const t=e.$$typeof;return t===M4&&(e=e.type,n=e.compare),t===A4?x.memo(x.forwardRef(new Proxy(e.render,u1))):x.memo(new Proxy(e,u1),n)}function j4(){const e=arguments[0],n=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return x.useMemo(()=>V(`useComputed(${e})`,n,t),r)}function js(e,n,t=Ho){x.useEffect(()=>{const r=new Tc(e,n);return r.attach(),r.execute(),()=>{r.detach()}},t)}function W(){const e=arguments,n=e.length===3?e[2]:[e[0]],t=e.length===3?e[0]:`useValue(${e[0].name})`,r=x.useRef(!0);r.current=!0;const o=x.useMemo(()=>e.length===1?e[0]:V(t,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),n);try{const{subscribe:s,getSnapshot:i}=x.useMemo(()=>({subscribe:a=>ta(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return x.useSyncExternalStore(s,i,i)}finally{r.current=!1}}var Pf={exports:{}};Pf.exports;(function(e,n){var t=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",c="[object Array]",l="[object AsyncFunction]",d="[object Boolean]",u="[object Date]",f="[object Error]",p="[object Function]",S="[object GeneratorFunction]",g="[object Map]",w="[object Number]",y="[object Null]",v="[object Object]",P="[object Promise]",E="[object Proxy]",I="[object RegExp]",C="[object Set]",_="[object String]",k="[object Symbol]",j="[object Undefined]",T="[object WeakMap]",M="[object ArrayBuffer]",R="[object DataView]",A="[object Float32Array]",O="[object Float64Array]",L="[object Int8Array]",G="[object Int16Array]",K="[object Int32Array]",B="[object Uint8Array]",U="[object Uint8ClampedArray]",Y="[object Uint16Array]",Q="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,ge=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,ce={};ce[A]=ce[O]=ce[L]=ce[G]=ce[K]=ce[B]=ce[U]=ce[Y]=ce[Q]=!0,ce[a]=ce[c]=ce[M]=ce[d]=ce[R]=ce[u]=ce[f]=ce[p]=ce[g]=ce[w]=ce[v]=ce[I]=ce[C]=ce[_]=ce[T]=!1;var Ae=typeof on=="object"&&on&&on.Object===Object&&on,Re=typeof self=="object"&&self&&self.Object===Object&&self,ct=Ae||Re||Function("return this")(),Ie=n&&!n.nodeType&&n,gt=Ie&&!0&&e&&!e.nodeType&&e,Ue=gt&>.exports===Ie,dr=Ue&&Ae.process,Un=function(){try{return dr&&dr.binding&&dr.binding("util")}catch{}}(),Hn=Un&&Un.isTypedArray;function qe($,F){for(var X=-1,te=$==null?0:$.length,Ze=0,me=[];++X<te;){var mt=$[X];F(mt,X,$)&&(me[Ze++]=mt)}return me}function Rt($,F){for(var X=-1,te=F.length,Ze=$.length;++X<te;)$[Ze+X]=F[X];return $}function ko($,F){for(var X=-1,te=$==null?0:$.length;++X<te;)if(F($[X],X,$))return!0;return!1}function zc($,F){for(var X=-1,te=Array($);++X<$;)te[X]=F(X);return te}function Nc($){return function(F){return $(F)}}function Tg($,F){return $.has(F)}function aa($,F){return $==null?void 0:$[F]}function lO($){var F=-1,X=Array($.size);return $.forEach(function(te,Ze){X[++F]=[Ze,te]}),X}function dO($,F){return function(X){return $(F(X))}}function uO($){var F=-1,X=Array($.size);return $.forEach(function(te){X[++F]=te}),X}var hO=Array.prototype,fO=Function.prototype,qd=Object.prototype,$g=ct["__core-js_shared__"],zw=fO.toString,qr=qd.hasOwnProperty,Nw=function(){var $=/[^.]+$/.exec($g&&$g.keys&&$g.keys.IE_PROTO||"");return $?"Symbol(src)_1."+$:""}(),Bw=qd.toString,pO=RegExp("^"+zw.call(qr).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Uw=Ue?ct.Buffer:void 0,Zd=ct.Symbol,Hw=ct.Uint8Array,Kw=qd.propertyIsEnumerable,gO=hO.splice,ui=Zd?Zd.toStringTag:void 0,Ww=Object.getOwnPropertySymbols,mO=Uw?Uw.isBuffer:void 0,yO=dO(Object.keys,Object),Mg=ca(ct,"DataView"),Bc=ca(ct,"Map"),Ag=ca(ct,"Promise"),jg=ca(ct,"Set"),Og=ca(ct,"WeakMap"),Uc=ca(Object,"create"),SO=pi(Mg),vO=pi(Bc),xO=pi(Ag),wO=pi(jg),bO=pi(Og),Gw=Zd?Zd.prototype:void 0,Dg=Gw?Gw.valueOf:void 0;function hi($){var F=-1,X=$==null?0:$.length;for(this.clear();++F<X;){var te=$[F];this.set(te[0],te[1])}}function PO(){this.__data__=Uc?Uc(null):{},this.size=0}function CO($){var F=this.has($)&&delete this.__data__[$];return this.size-=F?1:0,F}function IO($){var F=this.__data__;if(Uc){var X=F[$];return X===r?void 0:X}return qr.call(F,$)?F[$]:void 0}function EO($){var F=this.__data__;return Uc?F[$]!==void 0:qr.call(F,$)}function _O($,F){var X=this.__data__;return this.size+=this.has($)?0:1,X[$]=Uc&&F===void 0?r:F,this}hi.prototype.clear=PO,hi.prototype.delete=CO,hi.prototype.get=IO,hi.prototype.has=EO,hi.prototype.set=_O;function To($){var F=-1,X=$==null?0:$.length;for(this.clear();++F<X;){var te=$[F];this.set(te[0],te[1])}}function kO(){this.__data__=[],this.size=0}function TO($){var F=this.__data__,X=Jd(F,$);if(X<0)return!1;var te=F.length-1;return X==te?F.pop():gO.call(F,X,1),--this.size,!0}function $O($){var F=this.__data__,X=Jd(F,$);return X<0?void 0:F[X][1]}function MO($){return Jd(this.__data__,$)>-1}function AO($,F){var X=this.__data__,te=Jd(X,$);return te<0?(++this.size,X.push([$,F])):X[te][1]=F,this}To.prototype.clear=kO,To.prototype.delete=TO,To.prototype.get=$O,To.prototype.has=MO,To.prototype.set=AO;function fi($){var F=-1,X=$==null?0:$.length;for(this.clear();++F<X;){var te=$[F];this.set(te[0],te[1])}}function jO(){this.size=0,this.__data__={hash:new hi,map:new(Bc||To),string:new hi}}function OO($){var F=eu(this,$).delete($);return this.size-=F?1:0,F}function DO($){return eu(this,$).get($)}function RO($){return eu(this,$).has($)}function LO($,F){var X=eu(this,$),te=X.size;return X.set($,F),this.size+=X.size==te?0:1,this}fi.prototype.clear=jO,fi.prototype.delete=OO,fi.prototype.get=DO,fi.prototype.has=RO,fi.prototype.set=LO;function Qd($){var F=-1,X=$==null?0:$.length;for(this.__data__=new fi;++F<X;)this.add($[F])}function FO($){return this.__data__.set($,r),this}function zO($){return this.__data__.has($)}Qd.prototype.add=Qd.prototype.push=FO,Qd.prototype.has=zO;function hs($){var F=this.__data__=new To($);this.size=F.size}function NO(){this.__data__=new To,this.size=0}function BO($){var F=this.__data__,X=F.delete($);return this.size=F.size,X}function UO($){return this.__data__.get($)}function HO($){return this.__data__.has($)}function KO($,F){var X=this.__data__;if(X instanceof To){var te=X.__data__;if(!Bc||te.length<t-1)return te.push([$,F]),this.size=++X.size,this;X=this.__data__=new fi(te)}return X.set($,F),this.size=X.size,this}hs.prototype.clear=NO,hs.prototype.delete=BO,hs.prototype.get=UO,hs.prototype.has=HO,hs.prototype.set=KO;function WO($,F){var X=tu($),te=!X&&iD($),Ze=!X&&!te&&Rg($),me=!X&&!te&&!Ze&&tb($),mt=X||te||Ze||me,kt=mt?zc($.length,String):[],Lt=kt.length;for(var lt in $)qr.call($,lt)&&!(mt&&(lt=="length"||Ze&&(lt=="offset"||lt=="parent")||me&&(lt=="buffer"||lt=="byteLength"||lt=="byteOffset")||tD(lt,Lt)))&&kt.push(lt);return kt}function Jd($,F){for(var X=$.length;X--;)if(Zw($[X][0],F))return X;return-1}function GO($,F,X){var te=F($);return tu($)?te:Rt(te,X($))}function Hc($){return $==null?$===void 0?j:y:ui&&ui in Object($)?JO($):sD($)}function Vw($){return Kc($)&&Hc($)==a}function Yw($,F,X,te,Ze){return $===F?!0:$==null||F==null||!Kc($)&&!Kc(F)?$!==$&&F!==F:VO($,F,X,te,Yw,Ze)}function VO($,F,X,te,Ze,me){var mt=tu($),kt=tu(F),Lt=mt?c:fs($),lt=kt?c:fs(F);Lt=Lt==a?v:Lt,lt=lt==a?v:lt;var Kn=Lt==v,kr=lt==v,Xt=Lt==lt;if(Xt&&Rg($)){if(!Rg(F))return!1;mt=!0,Kn=!1}if(Xt&&!Kn)return me||(me=new hs),mt||tb($)?Xw($,F,X,te,Ze,me):ZO($,F,Lt,X,te,Ze,me);if(!(X&o)){var ur=Kn&&qr.call($,"__wrapped__"),hr=kr&&qr.call(F,"__wrapped__");if(ur||hr){var ps=ur?$.value():$,$o=hr?F.value():F;return me||(me=new hs),Ze(ps,$o,X,te,me)}}return Xt?(me||(me=new hs),QO($,F,X,te,Ze,me)):!1}function YO($){if(!eb($)||rD($))return!1;var F=Qw($)?pO:ge;return F.test(pi($))}function XO($){return Kc($)&&Jw($.length)&&!!ce[Hc($)]}function qO($){if(!oD($))return yO($);var F=[];for(var X in Object($))qr.call($,X)&&X!="constructor"&&F.push(X);return F}function Xw($,F,X,te,Ze,me){var mt=X&o,kt=$.length,Lt=F.length;if(kt!=Lt&&!(mt&&Lt>kt))return!1;var lt=me.get($);if(lt&&me.get(F))return lt==F;var Kn=-1,kr=!0,Xt=X&s?new Qd:void 0;for(me.set($,F),me.set(F,$);++Kn<kt;){var ur=$[Kn],hr=F[Kn];if(te)var ps=mt?te(hr,ur,Kn,F,$,me):te(ur,hr,Kn,$,F,me);if(ps!==void 0){if(ps)continue;kr=!1;break}if(Xt){if(!ko(F,function($o,gi){if(!Tg(Xt,gi)&&(ur===$o||Ze(ur,$o,X,te,me)))return Xt.push(gi)})){kr=!1;break}}else if(!(ur===hr||Ze(ur,hr,X,te,me))){kr=!1;break}}return me.delete($),me.delete(F),kr}function ZO($,F,X,te,Ze,me,mt){switch(X){case R:if($.byteLength!=F.byteLength||$.byteOffset!=F.byteOffset)return!1;$=$.buffer,F=F.buffer;case M:return!($.byteLength!=F.byteLength||!me(new Hw($),new Hw(F)));case d:case u:case w:return Zw(+$,+F);case f:return $.name==F.name&&$.message==F.message;case I:case _:return $==F+"";case g:var kt=lO;case C:var Lt=te&o;if(kt||(kt=uO),$.size!=F.size&&!Lt)return!1;var lt=mt.get($);if(lt)return lt==F;te|=s,mt.set($,F);var Kn=Xw(kt($),kt(F),te,Ze,me,mt);return mt.delete($),Kn;case k:if(Dg)return Dg.call($)==Dg.call(F)}return!1}function QO($,F,X,te,Ze,me){var mt=X&o,kt=qw($),Lt=kt.length,lt=qw(F),Kn=lt.length;if(Lt!=Kn&&!mt)return!1;for(var kr=Lt;kr--;){var Xt=kt[kr];if(!(mt?Xt in F:qr.call(F,Xt)))return!1}var ur=me.get($);if(ur&&me.get(F))return ur==F;var hr=!0;me.set($,F),me.set(F,$);for(var ps=mt;++kr<Lt;){Xt=kt[kr];var $o=$[Xt],gi=F[Xt];if(te)var nb=mt?te(gi,$o,Xt,F,$,me):te($o,gi,Xt,$,F,me);if(!(nb===void 0?$o===gi||Ze($o,gi,X,te,me):nb)){hr=!1;break}ps||(ps=Xt=="constructor")}if(hr&&!ps){var nu=$.constructor,ru=F.constructor;nu!=ru&&"constructor"in $&&"constructor"in F&&!(typeof nu=="function"&&nu instanceof nu&&typeof ru=="function"&&ru instanceof ru)&&(hr=!1)}return me.delete($),me.delete(F),hr}function qw($){return GO($,lD,eD)}function eu($,F){var X=$.__data__;return nD(F)?X[typeof F=="string"?"string":"hash"]:X.map}function ca($,F){var X=aa($,F);return YO(X)?X:void 0}function JO($){var F=qr.call($,ui),X=$[ui];try{$[ui]=void 0;var te=!0}catch{}var Ze=Bw.call($);return te&&(F?$[ui]=X:delete $[ui]),Ze}var eD=Ww?function($){return $==null?[]:($=Object($),qe(Ww($),function(F){return Kw.call($,F)}))}:dD,fs=Hc;(Mg&&fs(new Mg(new ArrayBuffer(1)))!=R||Bc&&fs(new Bc)!=g||Ag&&fs(Ag.resolve())!=P||jg&&fs(new jg)!=C||Og&&fs(new Og)!=T)&&(fs=function($){var F=Hc($),X=F==v?$.constructor:void 0,te=X?pi(X):"";if(te)switch(te){case SO:return R;case vO:return g;case xO:return P;case wO:return C;case bO:return T}return F});function tD($,F){return F=F??i,!!F&&(typeof $=="number"||Me.test($))&&$>-1&&$%1==0&&$<F}function nD($){var F=typeof $;return F=="string"||F=="number"||F=="symbol"||F=="boolean"?$!=="__proto__":$===null}function rD($){return!!Nw&&Nw in $}function oD($){var F=$&&$.constructor,X=typeof F=="function"&&F.prototype||qd;return $===X}function sD($){return Bw.call($)}function pi($){if($!=null){try{return zw.call($)}catch{}try{return $+""}catch{}}return""}function Zw($,F){return $===F||$!==$&&F!==F}var iD=Vw(function(){return arguments}())?Vw:function($){return Kc($)&&qr.call($,"callee")&&!Kw.call($,"callee")},tu=Array.isArray;function aD($){return $!=null&&Jw($.length)&&!Qw($)}var Rg=mO||uD;function cD($,F){return Yw($,F)}function Qw($){if(!eb($))return!1;var F=Hc($);return F==p||F==S||F==l||F==E}function Jw($){return typeof $=="number"&&$>-1&&$%1==0&&$<=i}function eb($){var F=typeof $;return $!=null&&(F=="object"||F=="function")}function Kc($){return $!=null&&typeof $=="object"}var tb=Hn?Nc(Hn):XO;function lD($){return aD($)?WO($):qO($)}function dD(){return[]}function uD(){return!1}e.exports=cD})(Pf,Pf.exports);var O4=Pf.exports;const D4=Qs(O4);function R4(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 L4(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 h1(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 f1(e,n,t){const r=Object.fromEntries(Object.keys(t).map(o=>[o,new Set]));for(const[o,s]of Object.entries(t))if("eq"in s){const a=e.index(n,o).get().get(s.eq);if(a)for(const c of a)r[o].add(c)}else if("neq"in s){const i=e.index(n,o);for(const[a,c]of i.get())if(a!==s.neq)for(const l of c)r[o].add(l)}else if("gt"in s){const i=e.index(n,o);for(const[a,c]of i.get())if(a>s.gt)for(const l of c)r[o].add(l)}return R4(Object.values(r))}class F4{constructor(n,t){m(this,"indexCache",new Map);m(this,"historyCache",new Map);this.atoms=n,this.history=t}filterHistory(n){if(this.historyCache.has(n))return this.historyCache.get(n);const t=V("filterHistory:"+n,(r,o)=>{if(Ti(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Zn)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,c=0,l=0;for(const d of s){for(const u of yt(d.added))if(u.typeName===n)if(i.removed[u.id]){const f=i.removed[u.id];delete i.removed[u.id],c--,f!==u&&(i.updated[u.id]=[f,u],l++)}else i.added[u.id]=u,a++;for(const[u,f]of yt(d.updated))f.typeName===n&&(i.added[f.id]?i.added[f.id]=f:i.updated[f.id]?i.updated[f.id]=[i.updated[f.id][0],f]:(i.updated[f.id]=[u,f],l++));for(const u of yt(d.removed))u.typeName===n&&(i.added[u.id]?(delete i.added[u.id],a--):i.updated[u.id]?(i.removed[u.id]=i.updated[u.id][0],delete i.updated[u.id],l--,c++):(i.removed[u.id]=u,c++))}return a||c||l?Sl(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(n,t),t}index(n,t){const r=n+":"+t;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(n,t);return this.indexCache.set(r,o),o}__uncached_createIndex(n,t){const r=this.filterHistory(n),o=()=>{r.get();const s=new Map;for(const i of yt(this.atoms.get())){const a=i.get();if(a.typeName===n){const c=a[t];s.has(c)||s.set(c,new Set),s.get(c).add(a.id)}}return s};return V("index:"+n+":"+t,(s,i)=>{if(Ti(s))return o();const a=r.getDiffSince(i);if(a===Zn)return o();const c=new Map,l=(p,S)=>{let g=c.get(p);g||(g=new fh(s.get(p)??new Set)),g.add(S),c.set(p,g)},d=(p,S)=>{let g=c.get(p);g||(g=new fh(s.get(p)??new Set)),g.remove(S),c.set(p,g)};for(const p of a){for(const S of yt(p.added))if(S.typeName===n){const g=S[t];l(g,S.id)}for(const[S,g]of yt(p.updated))if(g.typeName===n){const w=S[t],y=g[t];w!==y&&(d(w,g.id),l(y,g.id))}for(const S of yt(p.removed))if(S.typeName===n){const g=S[t];d(g,S.id)}}let u,f;for(const[p,S]of c){const g=S.get();g&&(u||(u=new Map(s)),f||(f=new Map),g.value.size===0?u.delete(p):u.set(p,g.value),f.set(p,g.diff))}return u&&f?Sl(u,f):s},{historyLength:100})}record(n,t=()=>({}),r="record:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,r);return V(r,()=>{var s;for(const i of o.get())return(s=this.atoms.get()[i])==null?void 0:s.get()})}records(n,t=()=>({}),r="records:"+n+(t?":"+t.toString():"")){const o=this.ids(n,t,"ids:"+r);return V(r,()=>[...o.get()].map(s=>{const i=this.atoms.get()[s];if(!i)throw new Error("no atom found for record id: "+s);return i.get()}))}ids(n,t=()=>({}),r="ids:"+n+(t?":"+t.toString():"")){const o=this.filterHistory(n),s=()=>{o.get();const c=t();return Object.keys(c).length===0?new Set(yt(this.atoms.get()).flatMap(l=>{const d=l.get();return d.typeName===n?d.id:[]})):f1(this,n,c)},i=c=>{const l=s(),d=L4(c,l);return d?Sl(l,d):c},a=V("ids_query:"+r,t,{isEqual:D4});return V("query:"+r,(c,l)=>{const d=a.get();if(Ti(c))return s();if(l<a.lastChangedEpoch)return i(c);const u=o.getDiffSince(l);if(u===Zn)return i(c);const f=new fh(c);for(const S of u){for(const g of yt(S.added))g.typeName===n&&h1(d,g)&&f.add(g.id);for(const[g,w]of yt(S.updated))w.typeName===n&&(h1(d,w)?f.add(w.id):f.remove(w.id));for(const g of yt(S.removed))g.typeName===n&&f.remove(g.id)}const p=f.get();return p?Sl(p.value,p.diff):c},{historyLength:50})}exec(n,t){const r=f1(this,n,t);if(r.size===0)return Ho;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class z4{constructor(n){m(this,"_beforeCreateHandlers",{});m(this,"_afterCreateHandlers",{});m(this,"_beforeChangeHandlers",{});m(this,"_afterChangeHandlers",{});m(this,"_beforeDeleteHandlers",{});m(this,"_afterDeleteHandlers",{});m(this,"_operationCompleteHandlers",[]);m(this,"_isEnabled",!0);this.store=n}isEnabled(){return this._isEnabled}setIsEnabled(n){this._isEnabled=n}handleBeforeCreate(n,t){if(!this._isEnabled)return n;const r=this._beforeCreateHandlers[n.typeName];if(r){let o=n;for(const s of r)o=s(o,t);return o}return n}handleAfterCreate(n,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[n.typeName];if(r)for(const o of r)o(n,t)}handleBeforeChange(n,t,r){if(!this._isEnabled)return t;const o=this._beforeChangeHandlers[t.typeName];if(o){let s=t;for(const i of o)s=i(n,s,r);return s}return t}handleAfterChange(n,t,r){if(!this._isEnabled)return;const o=this._afterChangeHandlers[t.typeName];if(o)for(const s of o)s(n,t,r)}handleBeforeDelete(n,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[n.typeName];if(r){for(const o of r)if(o(n,t)===!1)return!1}return!0}handleAfterDelete(n,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[n.typeName];if(r)for(const o of r)o(n,t)}handleOperationComplete(n){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(n)}register(n){const t=[];for(const[r,o]of Object.entries(n))o!=null&&o.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,o.beforeCreate)),o!=null&&o.afterCreate&&t.push(this.registerAfterCreateHandler(r,o.afterCreate)),o!=null&&o.beforeChange&&t.push(this.registerBeforeChangeHandler(r,o.beforeChange)),o!=null&&o.afterChange&&t.push(this.registerAfterChangeHandler(r,o.afterChange)),o!=null&&o.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,o.beforeDelete)),o!=null&&o.afterDelete&&t.push(this.registerAfterDeleteHandler(r,o.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(n,t){return this._beforeCreateHandlers[n]||(this._beforeCreateHandlers[n]=[]),this._beforeCreateHandlers[n].push(t),()=>mi(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>mi(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>mi(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>mi(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>mi(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>mi(this._afterDeleteHandlers[n],t)}registerOperationCompleteHandler(n){return this._operationCompleteHandlers.push(n),()=>mi(this._operationCompleteHandlers,n)}}function mi(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}class A0{constructor(n){m(this,"id");m(this,"atoms",Mt("store_atoms",{}));m(this,"history",Mt("history",0,{historyLength:1e3}));m(this,"query",new F4(this.atoms,this.history));m(this,"listeners",new Set);m(this,"historyAccumulator",new B4);m(this,"historyReactor");m(this,"cancelHistoryReactor",()=>{});m(this,"schema");m(this,"props");m(this,"scopedTypes");m(this,"sideEffects",new z4(this));m(this,"put",(n,t)=>{this.atomic(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,c=!1;const l=this.isMergingRemoteChanges?"remote":"user";for(let d=0,u=n.length;d<u;d++){a=n[d];const f=(i??s)[a.id];if(f){const p=f.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(p,a,l),this.schema.validateRecord(this,a,t??"updateRecord",p)===p)continue;f.set(a),c=!0;const g=f.__unsafe__getWithoutCapture();r[a.id]=[p,g],this.addDiffForAfterEvent(p,g)}else a=this.sideEffects.handleBeforeCreate(a,l),c=!0,a=this.schema.validateRecord(this,a,t??"createRecord",null),o[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...s}),i[a.id]=Mt("atom:"+a.id,a)}i&&this.atoms.set(i),c&&this.updateHistory({added:o,updated:r,removed:{}})})});m(this,"remove",n=>{this.atomic(()=>{const t=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const s of n){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&t.add(s)}let o;this.atoms.update(s=>{let i;for(const a of n){if(t.has(a)||!(a in s))continue;i||(i={...s}),o||(o={}),delete i[a];const c=s[a].get();o[a]=c,this.addDiffForAfterEvent(c,null)}return i??s}),o&&this.updateHistory({added:{},updated:{},removed:o})})});m(this,"get",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.get()});m(this,"unsafeGetWithoutCapture",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.__unsafe__getWithoutCapture()});m(this,"serialize",(n="document")=>{const t={};for(const[r,o]of jn(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});m(this,"allRecords",()=>yt(this.atoms.get()).map(n=>n.get()));m(this,"clear",()=>{this.remove(o1(this.atoms.get()))});m(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())])});m(this,"has",n=>!!this.atoms.get()[n]);m(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()}});m(this,"isMergingRemoteChanges",!1);m(this,"mergeRemoteChanges",n=>{if(this.isMergingRemoteChanges)return n();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,As(n)}finally{this.isMergingRemoteChanges=!1}});m(this,"createComputedCache",(n,t,r)=>{const o=new Yo;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?V(i.name+":equals",()=>i.get(),{isEqual:r}):i;return V(n+":"+s,()=>t(a.get()))}).get()}}});m(this,"createSelectedComputedCache",(n,t,r)=>{const o=new Yo;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=V(n+":"+s+":selector",()=>t(i.get()));return V(n+":"+s,()=>r(a.get()))}).get()}}});m(this,"_integrityChecker");m(this,"_isPossiblyCorrupted",!1);m(this,"pendingAfterEvents",null);m(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:o}=n;this.id=o??Md(),this.schema=r,this.props=n.props,t&&this.atoms.set(i_(jn(t).map(([s,i])=>[s,Mt("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=m4("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=g_(s)}),this.scopedTypes={document:new Set(yt(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(yt(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(yt(this.schema.types).filter(s=>s.scope==="presence").map(s=>s.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const n=this.historyAccumulator.flush();for(const{changes:t,source:r}of n){let o=null,s=null,i=null;for(const{onHistory:a,filters:c}of this.listeners)if(!(c.source!=="all"&&c.source!==r))if(c.scope!=="all")if(c.scope==="document"){if(s??(s=this.filterChangesByScope(t,"document")),!s)continue;a({changes:s,source:r})}else if(c.scope==="session"){if(o??(o=this.filterChangesByScope(t,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(t,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(n,t){const r={added:El(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:El(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:El(n.removed,(o,s)=>this.scopedTypes[t].has(s.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(n){this.historyAccumulator.add({changes:n,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,n)}validate(n){this.allRecords().forEach(t=>this.schema.validateRecord(this,t,n,null))}getStoreSnapshot(n="document"){return{store:this.serialize(n),schema:this.schema.serialize()}}getSnapshot(n="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(n)}migrateSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);return{store:t.value,schema:this.schema.serialize()}}loadStoreSnapshot(n){const t=this.schema.migrateStoreSnapshot(n);if(t.type==="error")throw new Error(`Failed to migrate snapshot: ${t.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(t.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(n){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(n)}extractingChanges(n){const t=[],r=this.historyAccumulator.addInterceptor(o=>t.push(o.changes));try{return As(n),k0(t)}finally{r()}}applyDiff(n,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=yt(n.added);for(const[i,a]of yt(n.updated)){const c=this.schema.getType(a.typeName);if(r&&c.ephemeralKeySet.size){const l=this.get(a.id);if(!l){o.push(a);continue}let d=null;for(const[u,f]of Object.entries(a))c.ephemeralKeySet.has(u)||Object.is(f,Tn(l,u))||(d||(d={...l}),d[u]=f);d&&o.push(d)}else o.push(a)}const s=o1(n.removed);o.length&&this.put(o),s.length&&this.remove(s)},t)}ensureStoreIsUsable(){this.atomic(()=>{var n;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(n=this._integrityChecker)==null||n.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(n,t){if(it(this.pendingAfterEvents,"must be in event operation"),n===t||(n&&t&&it(n.id===t.id),!n&&!t))return;const r=(n||t).id,o=this.pendingAfterEvents.get(r);o?o.after=t:this.pendingAfterEvents.set(r,{before:n,after:t})}flushAtomicCallbacks(){let n=0;const t=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(n++,n>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:o,after:s}of r.values())o&&s?this.sideEffects.handleAfterChange(o,s,t):o&&!s?this.sideEffects.handleAfterDelete(o,t):!o&&s&&this.sideEffects.handleAfterCreate(s,t);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(t)}}}atomic(n,t=!0){return As(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),n();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(t??r),this._isInAtomicOp=!0;try{const o=n();return this.flushAtomicCallbacks(),o}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1}})}addHistoryInterceptor(n){return this.historyAccumulator.addInterceptor(t=>n(t,this.isMergingRemoteChanges?"remote":"user"))}}function N4(e){if(e.length===0)return[];const n=[];let t=[e[0]],r;for(let o=1,s=e.length;o<s;o++)r=e[o],t[0].source!==r.source&&(n.push(t),t=[]),t.push(r);return n.push(t),n.map(o=>({source:o[0].source,changes:k0(o.map(s=>s.changes))}))}class B4{constructor(){m(this,"_history",[]);m(this,"_interceptors",new Set)}addInterceptor(n){return this._interceptors.add(n),()=>{this._interceptors.delete(n)}}add(n){this._history.push(n);for(const t of this._interceptors)t(n)}flush(){const n=N4(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function U4(e,n,t){const r=new Yo;return{get(o,s){return r.get(o,()=>(o instanceof A0?o:o.store).createComputedCache(e,c=>n(o,c),t)).get(s)}}}function H4(e){const n=[];for(let t=e.length-1;t>=0;t--){const r=e[t];if("id"in r)n.unshift(r);else{const o=r.dependsOn,s=n[0];s&&(n[0]={...s,dependsOn:o.concat(s.dependsOn??[])})}}return n}function Ga({sequence:e,sequenceId:n,retroactive:t=!0}){const r={sequenceId:n,retroactive:t,sequence:H4(e)};return E_(r),r}function zn(e,n){return Object.fromEntries(jn(n).map(([t,r])=>[t,`${e}/${r}`]))}function ir(e){const n=e.sequenceId;return Ga({sequenceId:n,retroactive:e.retroactive??!0,sequence:e.sequence.map(t=>"id"in t?{...t,scope:"record",filter:r=>{var o,s;return r.typeName===e.recordType&&(((o=t.filter)==null?void 0:o.call(t,r))??!0)&&(((s=e.filter)==null?void 0:s.call(e,r))??!0)}}:t)})}function K4(e){const n=new Map(e.map(s=>[s.id,s])),t=new Set,r=[];function o(s){it(!t.has(s.id),`Circular dependency in migrations: ${s.id}`),t.add(s.id);const{version:i,sequenceId:a}=Cf(s.id),c=n.get(`${a}/${i-1}`);if(c&&o(c),s.dependsOn)for(const l of s.dependsOn){const d=n.get(l);d&&o(d)}n.delete(s.id),r.push(s)}for(const s of n.values())o(s);return r}function Cf(e){const[n,t]=e.split("/");return{sequenceId:n,version:parseInt(t)}}function p1(e,n){n&&it(e.startsWith(n+"/"),`Every migration in sequence '${n}' must have an id starting with '${n}/'. Got invalid id: '${e}'`),it(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function E_(e){if(it(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),it(e.sequenceId.length,"sequenceId must be a non-empty string"),e.sequence.length===0)return;p1(e.sequence[0].id,e.sequenceId);let n=Cf(e.sequence[0].id).version;it(n===1,`Expected the first migrationId to be '${e.sequenceId}/1' but got '${e.sequence[0].id}'`);for(let t=1;t<e.sequence.length;t++){const r=e.sequence[t].id;p1(r,e.sequenceId);const o=Cf(r).version;it(o===n+1,`Migration id numbers must increase in increments of 1, expected ${e.sequenceId}/${n+1} but got '${e.sequence[t].id}'`),n=o}}var vs=(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))(vs||{});function W4(e){if(e.schemaVersion>2||e.schemaVersion<1)return fn.err("Bad schema version");if(e.schemaVersion===2)return fn.ok(e);const n={schemaVersion:2,sequences:{}};for(const[t,r]of Object.entries(e.recordVersions))if(n.sequences[`com.tldraw.${t}`]=r.version,"subTypeKey"in r)for(const[o,s]of Object.entries(r.subTypeVersions))n.sequences[`com.tldraw.${t}.${o}`]=s;return fn.ok(n)}class j0{constructor(n,t){m(this,"migrations",{});m(this,"sortedMigrations");var o;this.types=n,this.options=t;for(const s of t.migrations??[])it(!this.migrations[s.sequenceId],`Duplicate migration sequenceId ${s.sequenceId}`),E_(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=K4(r);for(const s of this.sortedMigrations)if((o=s.dependsOn)!=null&&o.length)for(const i of s.dependsOn){const a=r.find(c=>c.id===i);it(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(n,t){return new j0(n,t??{})}validateRecord(n,t,r,o){try{const s=Tn(this.types,t.typeName);if(!s)throw new Error(`Missing definition for record type ${t.typeName}`);return s.validate(t,o??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:n,record:t,phase:r,recordBefore:o,error:s});throw s}}getMigrationsSince(n){const t=W4(n);if(!t.ok)return t;const r=t.value,o=new Set(Object.keys(r.sequences).filter(i=>this.migrations[i]));for(const i in this.migrations)r.sequences[i]===void 0&&this.migrations[i].retroactive&&o.add(i);if(o.size===0)return fn.ok([]);const s=new Set;for(const i of o){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const d of this.migrations[i].sequence)s.add(d.id);continue}const c=`${i}/${a}`,l=this.migrations[i].sequence.findIndex(d=>d.id===c);if(l===-1)return fn.err("Incompatible schema?");for(const d of this.migrations[i].sequence.slice(l+1))s.add(d.id)}return fn.ok(this.sortedMigrations.filter(({id:i})=>s.has(i)))}migratePersistedRecord(n,t,r="up"){const o=this.getMigrationsSince(t);if(!o.ok)return console.error("Error migrating record",o.error),{type:"error",reason:vs.MigrationError};let s=o.value;if(s.length===0)return{type:"success",value:n};if(s.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?vs.TargetVersionTooOld:vs.TargetVersionTooNew};if(r==="down"){if(!s.every(i=>i.down))return{type:"error",reason:vs.TargetVersionTooOld};s=s.slice().reverse()}n=ot(n);try{for(const i of s){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(n):!0))continue;const c=i[r](n);c&&(n=ot(c))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:vs.MigrationError}}return{type:"success",value:n}}migrateStoreSnapshot(n){let{store:t}=n;const r=this.getMigrationsSince(n.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:vs.MigrationError};const o=r.value;if(o.length===0)return{type:"success",value:t};t=ot(t);try{for(const s of o)if(s.scope==="record")for(const[i,a]of Object.entries(t)){if(!(s.filter?s.filter(a):!0))continue;const l=s.up(a);l&&(t[i]=ot(l))}else if(s.scope==="store"){const i=s.up(t);i&&(t=ot(i))}else sn(s)}catch(s){return console.error("Error migrating store",s),{type:"error",reason:vs.MigrationError}}return{type:"success",value:t}}createIntegrityChecker(n){var t,r;return((r=(t=this.options).createIntegrityChecker)==null?void 0:r.call(t,n))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:n,sequence:t})=>[n,t.length?Cf(t.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:n})=>[n,0]))}}getType(n){const t=Tn(this.types,n);return it(t,"record type does not exists"),t}}function G4(e){if(!e.length)return null;let n="";for(const t of e)typeof t=="number"?n+=`.${t}`:t.startsWith("(")?n.endsWith(")")?n=`${n.slice(0,-1)}, ${t.slice(1)}`:n+=t:n+=`.${t}`;return n=n.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),n.startsWith(".")?n.slice(1):n}class Ce extends Error{constructor(t,r=[]){const o=G4(r),s=t.split(`
|
|
47
|
-
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
48
|
-
`);super(r?`At ${o}: ${s}`:s);m(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function On(e,n){try{return n()}catch(t){throw t instanceof Ce?new Ce(t.rawMessage,[e,...t.path]):new Ce(t.toString(),[e])}}function Ws(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const n=typeof e;switch(n){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${n}`;case"object":return`an ${n}`;case"undefined":return"undefined";default:sn(n)}}class vn{constructor(n,t){this.validationFn=n,this.validateUsingKnownGoodVersionFn=t}validate(n){return this.validationFn(n)}validateUsingKnownGoodVersion(n,t){return Object.is(n,t)?n:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(n,t):this.validate(t)}isValid(n){try{return this.validate(n),!0}catch{return!1}}nullable(){return Q4(this)}optional(){return k_(this)}refine(n){return new vn(t=>n(this.validate(t)),(t,r)=>{const o=this.validateUsingKnownGoodVersion(t,r);return Object.is(t,o)?t:n(o)})}check(n,t){return typeof n=="string"?this.refine(r=>(On(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class V4 extends vn{constructor(n){super(t=>{const r=g1.validate(t);for(let o=0;o<r.length;o++)On(o,()=>n.validate(r[o]));return r},(t,r)=>{if(!n.validateUsingKnownGoodVersion)return this.validate(r);const o=g1.validate(r);let s=t.length!==o.length;for(let i=0;i<o.length;i++){const a=o[i];if(i>=t.length){s=!0,On(i,()=>n.validate(a));continue}if(Object.is(t[i],a))continue;const c=On(i,()=>n.validateUsingKnownGoodVersion(t[i],a));Object.is(c,t[i])||(s=!0)}return s?r:t}),this.itemValidator=n}nonEmpty(){return this.check(n=>{if(n.length===0)throw new Ce("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new Ce("Expected an array with length greater than 1")})}}class If extends vn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Ws(r)}`);for(const[o,s]of Object.entries(n))On(o,()=>{s.validate(Tn(r,o))});if(!t){for(const o of Object.keys(r))if(!lo(n,o))throw new Ce("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Ws(o)}`);let s=!1;for(const[i,a]of Object.entries(n)){const c=Tn(r,i),l=Tn(o,i);if(Object.is(c,l))continue;const d=On(i,()=>{const u=a;return u.validateUsingKnownGoodVersion?u.validateUsingKnownGoodVersion(c,l):u.validate(l)});Object.is(d,c)||(s=!0)}if(!t){for(const i of Object.keys(o))if(!lo(n,i))throw new Ce("Unexpected property",[i])}for(const i of Object.keys(r))if(!lo(o,i)){s=!0;break}return s?o:r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new If(this.config,!0)}extend(n){return new If({...this.config,...n})}}class Ap extends vn{constructor(n,t,r,o){super(s=>{this.expectObject(s);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(s);return i===void 0?this.unknownValueValidation(s,a):On(`(${n} = ${a})`,()=>i.validate(s))},(s,i)=>{this.expectObject(i),this.expectObject(s);const{matchingSchema:a,variant:c}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,c):Tn(s,n)!==Tn(i,n)?On(`(${n} = ${c})`,()=>a.validate(i)):On(`(${n} = ${c})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(s,i):a.validate(i))}),this.key=n,this.config=t,this.unknownValueValidation=r,this.useNumberKeys=o}expectObject(n){if(typeof n!="object"||n===null)throw new Ce(`Expected an object, got ${Ws(n)}`,[])}getMatchingSchemaAndVariant(n){const t=Tn(n,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new Ce(`Expected a string for key "${this.key}", got ${Ws(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new Ce(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:lo(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(n){return new Ap(this.key,this.config,n,this.useNumberKeys)}}class Y4 extends vn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Ce(`Expected object, got ${Ws(r)}`);for(const[o,s]of Object.entries(r))On(o,()=>{n.validate(o),t.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ce(`Expected object, got ${Ws(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!lo(r,i)){s=!0,On(i,()=>{n.validate(i),t.validate(a)});continue}const c=Tn(r,i),l=a;if(Object.is(c,l))continue;const d=On(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(c,l):t.validate(l));Object.is(d,c)||(s=!0)}for(const i of Object.keys(r))if(!lo(o,i)){s=!0;break}return s?o:r}),this.keyValidator=n,this.valueValidator=t}}function O0(e){return new vn(n=>{if(typeof n!==e)throw new Ce(`Expected ${e}, got ${Ws(n)}`);return n})}const X4=new vn(e=>e),pe=O0("string"),he=O0("number").check(e=>{if(Number.isNaN(e))throw new Ce("Expected a number, got NaN");if(!Number.isFinite(e))throw new Ce(`Expected a finite number, got ${e}`)}),Ef=he.check(e=>{if(e<0)throw new Ce(`Expected a positive number, got ${e}`)}),It=he.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive number, got ${e}`)}),__=he.check(e=>{if(!Number.isInteger(e))throw new Ce(`Expected an integer, got ${e}`)}),gh=__.check(e=>{if(e<0)throw new Ce(`Expected a positive integer, got ${e}`)}),q4=__.check(e=>{if(e<=0)throw new Ce(`Expected a non-zero positive integer, got ${e}`)}),be=O0("boolean");function an(e){return new vn(n=>{if(n!==e)throw new Ce(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const g1=new vn(e=>{if(!Array.isArray(e))throw new Ce(`Expected an array, got ${Ws(e)}`);return e});function Bt(e){return new V4(e)}function xe(e){return new If(e)}function uS(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===f4)}function hS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(hS):uS(e)?Object.values(e).every(hS):!1}const Ut=new vn(e=>{if(hS(e))return e;throw new Ce(`Expected json serializable value, got ${typeof e}`)},(e,n)=>{if(Array.isArray(e)&&Array.isArray(n)){let t=e.length!==n.length;for(let r=0;r<n.length;r++){if(r>=e.length){t=!0,Ut.validate(n[r]);continue}const o=e[r],s=n[r];if(Object.is(o,s))continue;const i=Ut.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(t=!0)}return t?n:e}else if(uS(e)&&uS(n)){let t=!1;for(const r of Object.keys(n)){if(!lo(e,r)){t=!0,Ut.validate(n[r]);continue}const o=e[r],s=n[r];if(Object.is(o,s))continue;const i=Ut.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(t=!0)}for(const r of Object.keys(e))if(!lo(n,r)){t=!0;break}return t?n:e}else return Ut.validate(n)});function _f(e,n){return new Y4(e,n)}function D0(e,n){return new Ap(e,n,(t,r)=>{throw new Ce(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function Z4(e,n){return new Ap(e,n,(t,r)=>{throw new Ce(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function Po(e,n){return new vn(t=>On(e,()=>n.validate(t)),(t,r)=>On(e,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(t,r):n.validate(r)))}function jp(e){return new vn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Ce(`Expected ${t}, got ${n}`)}return n})}function k_(e){return new vn(n=>{if(n!==void 0)return e.validate(n)},(n,t)=>{if(!(n===void 0&&t===void 0)&&t!==void 0)return e.validateUsingKnownGoodVersion&&n!==void 0?e.validateUsingKnownGoodVersion(n,t):e.validate(t)})}function Q4(e){return new vn(n=>n===null?null:e.validate(n),(n,t)=>t===null?null:e.validateUsingKnownGoodVersion&&n!==null?e.validateUsingKnownGoodVersion(n,t):e.validate(t))}function Op(...e){return jp(new Set(e))}function T_(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Ce(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Ce(`Expected a valid url, got ${JSON.stringify(e)}`)}}const J4=new Set(["http:","https:","mailto:"]),nr=pe.check(e=>{if(e==="")return;const n=T_(e);if(!J4.has(n.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),e8=new Set(["http:","https:","data:","asset:"]),Oi=pe.check(e=>{if(e==="")return;const n=T_(e);if(!e8.has(n.protocol.toLowerCase()))throw new Ce(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),R0=pe.refine(e=>{try{return n4(e),e}catch{throw new Ce(`Expected an index key, got ${JSON.stringify(e)}`)}});function Qn(e){return pe.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const Dp=Qn("asset");function L0(e,n){return xe({id:Dp,typeName:an("asset"),type:an(e),props:n,meta:Ut})}const Di=xe({x:he,y:he,z:he.optional()}),kl=xe({x:he,y:he,w:he,h:he}),$_=he.check(e=>{if(e<0||e>1)throw new Ce("Opacity must be between 0 and 1")}),t8=pe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),gr=Qn("shape");function n8(e,n,t){return xe({id:gr,typeName:an("shape"),x:he,y:he,rotation:he,index:R0,parentId:t8,type:an(e),isLocked:be,opacity:$_,props:n?xe(n):Ut,meta:t?xe(t):Ut})}const r8=Qn("binding");function o8(e,n,t){return xe({id:r8,typeName:an("binding"),type:an(e),fromId:gr,toId:gr,props:n?xe(n):Ut,meta:t?xe(t):Ut})}zn("com.tldraw.binding",{});ir({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function $i(e){return`binding:${Md()}`}function s8(e){return bo("binding",{scope:"document",validator:Po("binding",D0("type",$d(e,(n,{props:t,meta:r})=>o8(n,t,r))))}).withDefaultProperties(()=>({meta:{}}))}class Yt{constructor(n,t,r){this.id=n,this.defaultValue=t,this.type=r}static define(n,t){const{defaultValue:r,type:o=X4}=t;return new Yt(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new i8(n,r,o)}validate(n){return this.type.validate(n)}validateUsingKnownGoodVersion(n,t){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(n,t):this.validate(t)}}class i8 extends Yt{constructor(n,t,r){super(n,t,Op(...r)),this.values=r}}const uu=zn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),a8=ir({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:uu.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:uu.HoistOpacity,up:e=>{e.opacity=Number(e.props.opacity??"1"),delete e.props.opacity},down:e=>{const n=e.opacity;delete e.opacity,e.props.opacity=n<.175?"0.1":n<.375?"0.25":n<.625?"0.5":n<.875?"0.75":"1"}},{id:uu.AddMeta,up:e=>{e.meta={}}},{id:uu.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function ka(e){return e?e.typeName==="shape":!1}function In(e){return e?e.startsWith("shape:"):!1}function Fe(e){return`shape:${e??Md()}`}function M_(e){const n=new Map;for(const[t,r]of Object.entries(e))if(r instanceof Yt){if(n.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);n.set(r,t)}return n}function Gr(e,n){return $d(n,(t,r)=>`com.tldraw.shape.${e}/${r}`)}function c8(e){return bo("shape",{scope:"document",validator:Po("shape",D0("type",$d(e,(n,{props:t,meta:r})=>n8(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function m1(e,n){const t=[];for(const[r,{migrations:o}]of Object.entries(n)){const s=`com.tldraw.${e}.${r}`;o?"sequenceId"in o?(it(s===o.sequenceId,`sequenceId mismatch for ${r} ${$p} migrations. Expected '${s}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o?t.push(Ga({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?A_(e,r,i):i)})):t.push(Ga({sequenceId:s,retroactive:!1,sequence:Object.keys(o.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${s}/${i}`,scope:"record",filter:a=>a.typeName===e&&a.type===r,up:a=>{const c=o.migrators[i].up(a);if(c)return c},down:a=>{const c=o.migrators[i].down(a);if(c)return c}}))})):t.push(Ga({sequenceId:s,retroactive:!1,sequence:[]}))}return t}function A_(e,n,t){return{id:t.id,dependsOn:t.dependsOn,scope:"record",filter:r=>r.typeName===e&&r.type===n,up:r=>{const o=t.up(r.props);o&&(r.props=o)},down:typeof t.down=="function"?r=>{const o=t.down(r.props);o&&(r.props=o)}:void 0}}const j_=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],kf={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",fill:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",fill:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",fill:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",fill:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",fill:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",fill:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",fill:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",fill:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",fill:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",fill:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",fill:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",fill:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function ss(e){return e.isDarkMode?kf.darkMode:kf.lightMode}const rr=Yt.defineEnum("tldraw:color",{defaultValue:"black",values:j_}),O_=Yt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:j_}),Ri=Yt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Li=Yt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),mo=Yt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),D_={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},yo=Yt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),R_=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Tf=Yt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:R_}),$f=Yt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:R_}),L_={labelColor:O_,color:rr,fill:Li,dash:Ri,size:yo,arrowheadStart:Tf,arrowheadEnd:$f,font:mo,start:Di,end:Di,bend:he,text:pe,labelPosition:he,scale:It},wa=Gr("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function hu(e){return A_("shape","arrow",e)}const F_=Ga({sequenceId:"com.tldraw.shape.arrow",sequence:[hu({id:wa.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),hu({id:wa.AddIsPrecise,up:({start:e,end:n})=>{e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5)),n.type==="binding"&&(n.isPrecise=!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5))},down:({start:e,end:n})=>{e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise),n.type==="binding"&&(n.isPrecise||(n.normalizedAnchor={x:.5,y:.5}),delete n.isPrecise)}}),hu({id:wa.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:wa.ExtractBindings,scope:"store",up:e=>{const n=Object.values(e).filter(t=>t.typeName==="shape"&&t.type==="arrow");for(const t of n){const{start:r,end:o}=t.props;if(r.type==="binding"){const s=$i(),i={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};e[s]=i,t.props.start={x:0,y:0}}else delete t.props.start.type;if(o.type==="binding"){const s=$i(),i={typeName:"binding",id:s,type:"arrow",fromId:t.id,toId:o.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:o.normalizedAnchor,isExact:o.isExact,isPrecise:o.isPrecise}};e[s]=i,t.props.end={x:0,y:0}}else delete t.props.end.type}}},hu({id:wa.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}})]}),z_={terminal:Op("start","end"),normalizedAnchor:Di,isExact:be,isPrecise:be},N_={sequence:[{dependsOn:[wa.ExtractBindings]}]},l8=Po("camera",xe({typeName:an("camera"),id:Qn("camera"),x:he,y:he,z:he,meta:Ut})),d8=zn("com.tldraw.camera",{AddMeta:1}),u8=ir({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:d8.AddMeta,up:e=>{e.meta={}}}]}),io=bo("camera",{validator:l8,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),h8=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"]),B_=jp(h8),f8=xe({type:B_,rotation:he}),p8=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),g8=jp(p8),m8=new Set(["starting","paused","active","stopping"]),U_=xe({id:pe,points:Bt(Di),size:Ef,color:g8,opacity:he,state:jp(m8),delay:he,shrink:he,taper:be}),Gl=Qn("page"),y8=Po("page",xe({typeName:an("page"),id:Gl,name:pe,index:R0,meta:Ut})),S8=zn("com.tldraw.page",{AddMeta:1}),v8=ir({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:S8.AddMeta,up:e=>{e.meta={}}}]}),Xo=bo("page",{validator:y8,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Pn(e){return Xo.isId(e)}const x8={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1},H_=e=>e?El(e,n=>x8[n]):null;Qn("instance");function w8(e){const n={};for(const[r,o]of e)n[r]=k_(o);const t=Po("instance",xe({typeName:an("instance"),id:Qn("instance"),currentPageId:Gl,followingUserId:pe.nullable(),brush:kl.nullable(),opacityForNextShape:$_,stylesForNextShape:xe(n),cursor:f8,scribbles:Bt(U_),isFocusMode:be,isDebugMode:be,isToolLocked:be,exportBackground:be,screenBounds:kl,insets:Bt(be),zoomBrush:kl.nullable(),isPenMode:be,isGridMode:be,chatMessage:pe,isChatting:be,highlightedUserIds:Bt(pe),isFocused:be,devicePixelRatio:he,isCoarsePointer:be,isHoveringCanvas:be.nullable(),openMenus:Bt(pe),isChangingStyle:be,isReadonly:be,meta:Ut,duplicateProps:xe({shapeIds:Bt(Qn("shape")),offset:xe({x:he,y:he})}).nullable()}));return bo("instance",{validator:t,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const Qe=zn("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25}),b8=ir({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:Qe.AddTransparentExportBgs,up:e=>({...e,exportBackground:!0})},{id:Qe.RemoveDialog,up:({dialog:e,...n})=>n},{id:Qe.AddToolLockMode,up:e=>({...e,isToolLocked:!1})},{id:Qe.RemoveExtraPropsForNextShape,up:({propsForNextShape:e,...n})=>({...n,propsForNextShape:Object.fromEntries(Object.entries(e).filter(([t])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(t)))})},{id:Qe.AddLabelColor,up:({propsForNextShape:e,...n})=>({...n,propsForNextShape:{...e,labelColor:"black"}})},{id:Qe.AddFollowingUserId,up:e=>({...e,followingUserId:null})},{id:Qe.RemoveAlignJustify,up:e=>{let n=e.propsForNextShape.align;return n==="justify"&&(n="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:n}}}},{id:Qe.AddZoom,up:e=>({...e,zoomBrush:null})},{id:Qe.AddVerticalAlign,up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}})},{id:Qe.AddScribbleDelay,up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e}},{id:Qe.RemoveUserId,up:({userId:e,...n})=>n},{id:Qe.AddIsPenModeAndIsGridMode,up:e=>({...e,isPenMode:!1,isGridMode:!1})},{id:Qe.HoistOpacity,up:({propsForNextShape:{opacity:e,...n},...t})=>({...t,opacityForNextShape:Number(e??"1"),propsForNextShape:n})},{id:Qe.AddChat,up:e=>({...e,chatMessage:"",isChatting:!1})},{id:Qe.AddHighlightedUserIds,up:e=>({...e,highlightedUserIds:[]})},{id:Qe.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:e,...n})=>({...n,stylesForNextShape:{}})},{id:Qe.AddMeta,up:e=>({...e,meta:{}})},{id:Qe.RemoveCursorColor,up:e=>{const{color:n,...t}=e.cursor;return{...e,cursor:t}}},{id:Qe.AddLonelyProperties,up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:Qe.ReadOnlyReadonly,up:({isReadOnly:e,...n})=>({...n,isReadonly:e})},{id:Qe.AddHoveringCanvas,up:e=>({...e,isHoveringCanvas:null})},{id:Qe.AddScribbles,up:({scribble:e,...n})=>({...n,scribbles:[]})},{id:Qe.AddInset,up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...n})=>({...n})},{id:Qe.AddDuplicateProps,up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...n})=>({...n})},{id:Qe.RemoveCanMoveCamera,up:({canMoveCamera:e,...n})=>({...n}),down:e=>({...e,canMoveCamera:!0})}]}),pn="instance:instance",P8=Po("instance_page_state",xe({typeName:an("instance_page_state"),id:Qn("instance_page_state"),pageId:Gl,selectedShapeIds:Bt(gr),hintingShapeIds:Bt(gr),erasingShapeIds:Bt(gr),hoveredShapeId:gr.nullable(),editingShapeId:gr.nullable(),croppingShapeId:gr.nullable(),focusedGroupId:gr.nullable(),meta:Ut})),Xc=zn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),C8=ir({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:Xc.AddCroppingId,up(e){e.croppingShapeId=null}},{id:Xc.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:Xc.AddMeta,up:e=>{e.meta={}}},{id:Xc.RenameProperties,up:e=>{},down:e=>{}},{id:Xc.RenamePropertiesAgain,up:e=>{e.selectedShapeIds=e.selectedIds,delete e.selectedIds,e.hintingShapeIds=e.hintingIds,delete e.hintingIds,e.erasingShapeIds=e.erasingIds,delete e.erasingIds,e.hoveredShapeId=e.hoveredId,delete e.hoveredId,e.editingShapeId=e.editingId,delete e.editingId,e.croppingShapeId=e.croppingShapeId??e.croppingId??null,delete e.croppingId,e.focusedGroupId=e.focusLayerId,delete e.focusLayerId},down:e=>{e.selectedIds=e.selectedShapeIds,delete e.selectedShapeIds,e.hintingIds=e.hintingShapeIds,delete e.hintingShapeIds,e.erasingIds=e.erasingShapeIds,delete e.erasingShapeIds,e.hoveredId=e.hoveredShapeId,delete e.hoveredShapeId,e.editingId=e.editingShapeId,delete e.editingShapeId,e.croppingId=e.croppingShapeId,delete e.croppingShapeId,e.focusLayerId=e.focusedGroupId,delete e.focusedGroupId}}]}),Rr=bo("instance_page_state",{validator:P8,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!1,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),I8=Po("pointer",xe({typeName:an("pointer"),id:Qn("pointer"),x:he,y:he,lastActivityTimestamp:he,meta:Ut})),E8=zn("com.tldraw.pointer",{AddMeta:1}),_8=ir({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:E8.AddMeta,up:e=>{e.meta={}}}]}),F0=bo("pointer",{validator:I8,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Mf=F0.createId("pointer"),k8=Po("instance_presence",xe({typeName:an("instance_presence"),id:Qn("instance_presence"),userId:pe,userName:pe,lastActivityTimestamp:he,followingUserId:pe.nullable(),cursor:xe({x:he,y:he,type:B_,rotation:he}),color:pe,camera:xe({x:he,y:he,z:he}),screenBounds:kl,selectedShapeIds:Bt(Qn("shape")),currentPageId:Qn("page"),brush:kl.nullable(),scribbles:Bt(U_),chatMessage:pe,meta:Ut})),qc=zn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),T8=ir({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:qc.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:qc.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:qc.AddChatMessage,up:e=>{e.chatMessage=""}},{id:qc.AddMeta,up:e=>{e.meta={}}},{id:qc.RenameSelectedShapeIds,up:e=>{}}]}),$8=bo("instance_presence",{validator:k8,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:{}})),M8=Po("document",xe({typeName:an("document"),id:an("document:document"),gridSize:he,name:pe,meta:Ut})),y1=zn("com.tldraw.document",{AddName:1,AddMeta:2}),A8=ir({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:y1.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:y1.AddMeta,up:e=>{e.meta={}}}]}),z0=bo("document",{validator:M8,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),fS=z0.createId("document");function j8(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function S1(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const O8=({error:e,phase:n,record:t,recordBefore:r})=>{throw P0(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?S1(ot(r)):void 0,recordAfter:S1(ot(t))}}),e};function D8(){return[Xo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function R8(e){const n=e.query.ids("page"),t=()=>{if(!e.has(fS))return e.put([z0.create({id:fS,name:e.props.defaultName})]),t();if(!e.has(Mf))return e.put([F0.create({id:Mf})]),t();const r=n.get();if(r.size===0)return e.put(D8()),t();const o=()=>[...r].map(c=>e.get(c)).sort(j8)[0].id,s=e.get(pn);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:pn,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const c of r){const l=Rr.createId(c);e.has(l)||i.add(l);const d=io.createId(c);e.has(d)||a.add(d)}i.size>0&&e.put([...i].map(c=>Rr.create({id:c,pageId:Rr.parseId(c)}))),a.size>0&&e.put([...a].map(c=>io.create({id:c})))};return t}const L8=L0("bookmark",xe({title:pe,description:pe,image:pe,favicon:pe,src:Oi.nullable()})),v1=zn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),F8=ir({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:v1.MakeUrlsValid,up:e=>{Oi.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:v1.AddFavicon,up:e=>{Oi.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),z8=L0("image",xe({w:he,h:he,fileSize:he,name:pe,isAnimated:be,mimeType:pe.nullable(),src:Oi.nullable()})),fu=zn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),N8=ir({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:fu.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:fu.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:fu.MakeUrlsValid,up:e=>{Oi.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:fu.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),B8=L0("video",xe({w:he,h:he,fileSize:he,name:pe,isAnimated:be,mimeType:pe.nullable(),src:Oi.nullable()})),pu=zn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),U8=ir({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:pu.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:pu.RenameWidthHeight,up:e=>{e.props.w=e.props.width,e.props.h=e.props.height,delete e.props.width,delete e.props.height},down:e=>{e.props.width=e.props.w,e.props.height=e.props.h,delete e.props.w,delete e.props.h}},{id:pu.MakeUrlsValid,up:e=>{Oi.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:pu.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),H8=Po("asset",D0("type",{image:z8,video:B8,bookmark:L8})),K8=zn("com.tldraw.asset",{AddMeta:1}),W8=ir({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:K8.AddMeta,up:e=>{e.meta={}}}]}),wi=bo("asset",{validator:H8,scope:"document"}).withDefaultProperties(()=>({meta:{}})),K_={w:It,h:It,assetId:Dp.nullable(),url:nr},x1=Gr("bookmark",{NullAssetId:1,MakeUrlsValid:2}),W_={sequence:[{id:x1.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:"retired"},{id:x1.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},G_=xe({type:Op("free","straight"),points:Bt(Di)}),V_={color:rr,fill:Li,dash:Ri,size:yo,segments:Bt(G_),isComplete:be,isClosed:be,isPen:be,scale:It},w1=Gr("draw",{AddInPen:1,AddScale:2}),Y_={sequence:[{id:w1.AddInPen,up:e=>{const{points:n}=e.segments[0];if(n.length===0){e.isPen=!1;return}let t=!(n[0].z===0||n[0].z===.5);n[1]&&(t=t&&!(n[1].z===0||n[1].z===.5)),e.isPen=t},down:"retired"},{id:w1.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]};var G8={};const b1=/(^\/r\/[^/]+\/?$)/,je=e=>{try{return new URL(e)}catch{return}},Ad=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:e=>{const n=je(e);if(n&&n.pathname.match(b1))return e},fromEmbedUrl:e=>{const n=je(e);if(n&&n.pathname.match(b1))return e}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!e.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${e}`},fromEmbedUrl:e=>{const n=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,overridePermissions:{"allow-presentation":!0},toEmbedUrl:e=>{if(e.includes("/maps/")){const n=e.match(/@(.*),(.*),(.*)z/);let t;if(n){const[,r,o,s]=n;t=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${G8.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,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,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,toEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:e=>{const n=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,t=e.match(n);if(t){const[r,o]=t;return`https://scratch.mit.edu/projects/embed/${o}`}},fromEmbedUrl:e=>{const n=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o]=t;return`https://scratch.mit.edu/projects/${o}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=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,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},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,overridePermissions:{"allow-popups-to-escape-sandbox":!0},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,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,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,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,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,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,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,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-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:e=>{const n=je(e);if(n&&n.hostname==="www.desmos.com"&&n.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&n.search===""&&n.hash==="")return`${e}?embed`},fromEmbedUrl:e=>{const n=je(e);if(n&&n.hostname==="www.desmos.com"&&n.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&n.search==="?embed"&&n.hash==="")return e.replace("?embed","")}}],V8={"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},X_={w:It,h:It,url:pe},gu=Gr("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),q_={sequence:[{id:gu.GenOriginalUrlInEmbed,up:e=>{try{const n=e.url,t=new URL(n).host.replace("www.","");let r;for(const o of Ad)if(o.hostnames.includes(t))try{r=o.fromEmbedUrl(n)}catch(s){console.warn(s)}e.tmpOldUrl=e.url,e.url=r??""}catch{e.url="",e.tmpOldUrl=e.url}},down:"retired"},{id:gu.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:gu.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:gu.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},Z_={w:It,h:It,name:pe},Q_={sequence:[]},Af=Yt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),jf=Yt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Lr=Yt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),J_={geo:Lr,labelColor:O_,color:rr,fill:Li,dash:Ri,size:yo,font:mo,align:Af,verticalAlign:jf,url:nr,w:It,h:It,growY:Ef,text:pe,scale:It},Mo=Gr("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),ek={sequence:[{id:Mo.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Mo.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:Mo.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:Mo.AddCheckBox,up:e=>{},down:"retired"},{id:Mo.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:Mo.MigrateLegacyAlign,up:e=>{let n;switch(e.align){case"start":n="start-legacy";break;case"end":n="end-legacy";break;default:n="middle-legacy";break}e.align=n},down:"retired"},{id:Mo.AddCloud,up:e=>{},down:"retired"},{id:Mo.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}},{id:Mo.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},tk={},nk={sequence:[]},rk={color:rr,size:yo,segments:Bt(G_),isComplete:be,isPen:be,scale:It},Y8=Gr("highlight",{AddScale:1}),ok={sequence:[{id:Y8.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},X8=xe({topLeft:Di,bottomRight:Di}),sk={w:It,h:It,playing:be,url:nr,assetId:Dp.nullable(),crop:X8.nullable()},hm=Gr("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3}),ik={sequence:[{id:hm.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:hm.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:hm.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},Of=Yt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),q8=xe({id:pe,index:R0,x:he,y:he}),ak={color:rr,dash:Ri,size:yo,spline:Of,points:_f(pe,q8),scale:It},Zc=Gr("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),ck={sequence:[{id:Zc.AddSnapHandles,up:e=>{for(const n of Object.values(e.handles))n.canSnap=!0},down:"retired"},{id:Zc.RemoveExtraHandleProps,up:e=>{e.handles=i_(Object.values(e.handles).map(n=>[n.index,{x:n.x,y:n.y}]))},down:e=>{const n=Object.entries(e.handles).map(([t,r])=>({index:t,...r})).sort(rn);e.handles=Object.fromEntries(n.map((t,r)=>{const o=r===0?"start":r===n.length-1?"end":`handle:${t.index}`;return[o,{id:o,type:"vertex",canBind:!1,canSnap:!0,index:t.index,x:t.x,y:t.y}]}))}},{id:Zc.HandlesToPoints,up:e=>{const n=Object.entries(e.handles).map(([t,{x:r,y:o}])=>({x:r,y:o,index:t})).sort(rn);e.points=n.map(({x:t,y:r})=>({x:t,y:r})),delete e.handles},down:e=>{const n=Wl(e.points.length);e.handles=Object.fromEntries(e.points.map((t,r)=>[n[r],{x:t.x,y:t.y}])),delete e.points}},{id:Zc.PointIndexIds,up:e=>{const n=Wl(e.points.length);e.points=Object.fromEntries(e.points.map((t,r)=>{const o=n[r];return[o,{id:o,index:o,x:t.x,y:t.y}]}))},down:e=>{const n=Object.values(e.points).sort(rn);e.points=n.map(({x:t,y:r})=>({x:t,y:r}))}},{id:Zc.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},lk={color:rr,size:yo,font:mo,fontSizeAdjustment:Ef,align:Af,verticalAlign:jf,growY:Ef,url:nr,text:pe,scale:It},yi=Gr("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),dk={sequence:[{id:yi.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:yi.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:yi.MigrateLegacyAlign,up:e=>{switch(e.align){case"start":e.align="start-legacy";return;case"end":e.align="end-legacy";return;default:e.align="middle-legacy";return}},down:"retired"},{id:yi.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:yi.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}},{id:yi.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}},{id:yi.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},pS=Yt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),uk={color:rr,size:yo,font:mo,textAlign:pS,w:It,text:pe,scale:It,autoSize:be},P1=Gr("text",{RemoveJustify:1,AddTextAlign:2}),hk={sequence:[{id:P1.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:P1.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},fk={w:It,h:It,time:he,playing:be,url:nr,assetId:Dp.nullable()},C1=Gr("video",{AddUrlProp:1,MakeUrlsValid:2}),pk={sequence:[{id:C1.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:C1.MakeUrlsValid,up:e=>{nr.isValid(e.url)||(e.url="")},down:e=>{}}]},mu=zn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),Z8=Ga({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:mu.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[n,t]of jn(e))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete e[n]}},{id:mu.AddInstancePresenceType,scope:"store",up(e){}},{id:mu.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[n,t]of jn(e))t.typeName.match(/^(user|user_presence)$/)&&delete e[n]}},{id:mu.RemoveUserDocument,scope:"store",up:e=>{for(const[n,t]of jn(e))t.typeName.match("user_document")&&delete e[n]}}]}),Q8={arrow:{migrations:F_,props:L_},bookmark:{migrations:W_,props:K_},draw:{migrations:Y_,props:V_},embed:{migrations:q_,props:X_},frame:{migrations:Q_,props:Z_},geo:{migrations:ek,props:J_},group:{migrations:nk,props:tk},highlight:{migrations:ok,props:rk},image:{migrations:ik,props:sk},line:{migrations:ck,props:ak},note:{migrations:dk,props:lk},text:{migrations:hk,props:uk},video:{migrations:pk,props:fk}},J8={arrow:{migrations:N_,props:z_}};function e7({shapes:e=Q8,bindings:n=J8,migrations:t}={}){const r=new Map;for(const a of yt(e))for(const c of M_(a.props??{}).keys()){if(r.has(c.id)&&r.get(c.id)!==c)throw new Error(`Multiple StyleProp instances with the same id: ${c.id}`);r.set(c.id,c)}const o=c8(e),s=s8(n),i=w8(r);return j0.create({asset:wi,binding:s,camera:io,document:z0,instance:i,instance_page_state:Rr,page:Xo,instance_presence:$8,pointer:F0,shape:o},{migrations:[Z8,W8,u8,A8,b8,C8,v8,T8,_8,a8,F8,N8,U8,...m1("shape",e),...m1("binding",n),...t??[]],onValidationFailure:O8,createIntegrityChecker:R8})}const Vl=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"fi",label:"Suomi"},{locale:"sv",label:"Svenska"},{locale:"vi",label:"Tiếng Việt"},{locale:"tr",label:"Türkçe"},{locale:"uk",label:"Ukrainian"},{locale:"he",label:"עברית"},{locale:"ar",label:"عربي"},{locale:"fa",label:"فارسی"},{locale:"ku",label:"کوردی"},{locale:"ne",label:"नेपाली"},{locale:"hi-in",label:"हिन्दी"},{locale:"te",label:"తెలుగు"},{locale:"th",label:"ภาษาไทย"},{locale:"my",label:"မြန်မာစာ"},{locale:"ko-kr",label:"한국어"},{locale:"ja",label:"日本語"},{locale:"zh-cn",label:"简体中文"},{locale:"zh-tw",label:"繁體中文 (台灣)"}];function t7(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return n7(e)}function n7(e){for(const n of e){const t=r7(n);if(t)return t}return"en"}const I1={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function r7(e){const n=Vl.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Vl.find(s=>s.locale===t);if(o)return o.locale}return t in I1?I1[t]:null}var gk={exports:{}};/*!
|
|
49
|
-
Copyright (c) 2018 Jed Watson.
|
|
50
|
-
Licensed under the MIT License (MIT), see
|
|
51
|
-
http://jedwatson.github.io/classnames
|
|
52
|
-
*/(function(e){(function(){var n={}.hasOwnProperty;function t(){for(var s="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(s=o(s,r(a)))}return s}function r(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return t.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var i="";for(var a in s)n.call(s,a)&&s[a]&&(i=o(i,a));return i}function o(s,i){return i?s?s+" "+i:s+i:s}e.exports?(t.default=t,e.exports=t):window.classNames=t})()})(gk);var o7=gk.exports;const de=Qs(o7),s7={error:null};class mk extends x.Component{constructor(){super(...arguments);m(this,"state",s7)}static getDerivedStateFromError(t){return{error:t}}componentDidCatch(t){var r,o;(o=(r=this.props).onError)==null||o.call(r,t)}render(){const{error:t}=this.state;if(t!==null){const{fallback:r}=this.props;return h.jsx(r,{error:t})}return this.props.children}}function Yl({children:e,fallback:n,...t}){return n===null?h.jsx(h.Fragment,{children:e}):h.jsx(mk,{fallback:n,...t,children:e})}const Rp=ve.createContext(null);function N(){const e=ve.useContext(Rp);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function i7(){return h.jsx("div",{className:"tl-background"})}function $c(e,n,t,r,o,s){x.useLayoutEffect(()=>{const i=e.current;if(!i||n===void 0)return;let a=`translate(${n}px, ${t}px)`;r!==void 0&&(a+=` scale(${r})`),o!==void 0&&(a+=` rotate(${o}rad)`),s&&(a+=` translate(${s.x}px, ${s.y}px)`),i.style.transform=a})}const At={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>--e*e*e+1,easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1- --e*e*e*e,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-8*--e*e*e*e,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1+--e*e*e*e*e,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e<=0?0:Math.pow(2,10*e-10),easeOutExpo:e=>e>=1?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>e<=0?0:e>=1?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2};class b{constructor(n=0,t=0,r=1){this.x=n,this.y=t,this.z=r}get pressure(){return this.z}set(n=this.x,t=this.y,r=this.z){return this.x=n,this.y=t,this.z=r,this}setTo({x:n=0,y:t=0,z:r=1}){return this.x=n,this.y=t,this.z=r,this}rot(n){if(n===0)return this;const{x:t,y:r}=this,o=Math.sin(n),s=Math.cos(n);return this.x=t*s-r*o,this.y=t*o+r*s,this}rotWith(n,t){if(t===0)return this;const r=this.x-n.x,o=this.y-n.y,s=Math.sin(t),i=Math.cos(t);return this.x=n.x+(r*i-o*s),this.y=n.y+(r*s+o*i),this}clone(){const{x:n,y:t,z:r}=this;return new b(n,t,r)}sub(n){return this.x-=n.x,this.y-=n.y,this}subXY(n,t){return this.x-=n,this.y-=t,this}subScalar(n){return this.x-=n,this.y-=n,this}add(n){return this.x+=n.x,this.y+=n.y,this}addXY(n,t){return this.x+=n,this.y+=t,this}addScalar(n){return this.x+=n,this.y+=n,this}clamp(n,t){return this.x=Math.max(this.x,n),this.y=Math.max(this.y,n),t!==void 0&&(this.x=Math.min(this.x,t),this.y=Math.min(this.y,t)),this}div(n){return this.x/=n,this.y/=n,this}divV(n){return this.x/=n.x,this.y/=n.y,this}mul(n){return this.x*=n,this.y*=n,this}mulV(n){return this.x*=n.x,this.y*=n.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(n,t){const r=b.Tan(n,this);return this.add(r.mul(t))}neg(){return this.x*=-1,this.y*=-1,this}cross(n){return this.x=this.y*n.z-this.z*n.y,this.y=this.z*n.x-this.x*n.z,this}dpr(n){return b.Dpr(this,n)}cpr(n){return b.Cpr(this,n)}len2(){return b.Len2(this)}len(){return b.Len(this)}pry(n){return b.Pry(this,n)}per(){const{x:n,y:t}=this;return this.x=t,this.y=-n,this}uni(){return b.Uni(this)}tan(n){return b.Tan(this,n)}dist(n){return b.Dist(this,n)}distanceToLineSegment(n,t){return b.DistanceToLineSegment(n,t,this)}slope(n){return b.Slope(this,n)}snapToGrid(n){return this.x=Math.round(this.x/n)*n,this.y=Math.round(this.y/n)*n,this}angle(n){return b.Angle(this,n)}toAngle(){return b.ToAngle(this)}lrp(n,t){return this.x=this.x+(n.x-this.x)*t,this.y=this.y+(n.y-this.y)*t,this}equals(n){return b.Equals(this,n)}equalsXY(n,t){return b.EqualsXY(this,n,t)}norm(){const n=this.len();return this.x=n===0?0:this.x/n,this.y=n===0?0:this.y/n,this}toFixed(){return b.ToFixed(this)}toString(){return b.ToString(b.ToFixed(this))}toJson(){return b.ToJson(this)}toArray(){return b.ToArray(this)}static Add(n,t){return new b(n.x+t.x,n.y+t.y)}static AddXY(n,t,r){return new b(n.x+t,n.y+r)}static Sub(n,t){return new b(n.x-t.x,n.y-t.y)}static SubXY(n,t,r){return new b(n.x-t,n.y-r)}static AddScalar(n,t){return new b(n.x+t,n.y+t)}static SubScalar(n,t){return new b(n.x-t,n.y-t)}static Div(n,t){return new b(n.x/t,n.y/t)}static Mul(n,t){return new b(n.x*t,n.y*t)}static DivV(n,t){return new b(n.x/t.x,n.y/t.y)}static MulV(n,t){return new b(n.x*t.x,n.y*t.y)}static Neg(n){return new b(-n.x,-n.y)}static Per(n){return new b(n.y,-n.x)}static Abs(n){return new b(Math.abs(n.x),Math.abs(n.y))}static Dist(n,t){return((n.y-t.y)**2+(n.x-t.x)**2)**.5}static DistMin(n,t,r){return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)<r**2}static Dist2(n,t){return(n.x-t.x)*(n.x-t.x)+(n.y-t.y)*(n.y-t.y)}static Dpr(n,t){return n.x*t.x+n.y*t.y}static Cross(n,t){return new b(n.y*t.z-n.z*t.y,n.z*t.x-n.x*t.z)}static Cpr(n,t){return n.x*t.y-t.x*n.y}static Len2(n){return n.x*n.x+n.y*n.y}static Len(n){return(n.x*n.x+n.y*n.y)**.5}static Pry(n,t){return b.Dpr(n,t)/b.Len(t)}static Uni(n){return b.Div(n,b.Len(n))}static Tan(n,t){return b.Uni(b.Sub(n,t))}static Min(n,t){return new b(Math.min(n.x,t.x),Math.min(n.y,t.y))}static Max(n,t){return new b(Math.max(n.x,t.x),Math.max(n.y,t.y))}static From({x:n,y:t,z:r=1}){return new b(n,t,r)}static FromArray(n){return new b(n[0],n[1])}static Rot(n,t=0){const r=Math.sin(t),o=Math.cos(t);return new b(n.x*o-n.y*r,n.x*r+n.y*o)}static RotWith(n,t,r){const o=n.x-t.x,s=n.y-t.y,i=Math.sin(r),a=Math.cos(r);return new b(t.x+(o*a-s*i),t.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(n,t,r){return b.Mul(t,b.Sub(r,n).pry(t)).add(n)}static NearestPointOnLineSegment(n,t,r,o=!0){if(b.Equals(n,r)||b.Equals(t,r))return b.From(r);const s=b.Tan(t,n),i=b.Add(n,b.Mul(s,b.Sub(r,n).pry(s)));if(o){if(i.x<Math.min(n.x,t.x))return b.Cast(n.x<t.x?n:t);if(i.x>Math.max(n.x,t.x))return b.Cast(n.x>t.x?n:t);if(i.y<Math.min(n.y,t.y))return b.Cast(n.y<t.y?n:t);if(i.y>Math.max(n.y,t.y))return b.Cast(n.y>t.y?n:t)}return i}static DistanceToLineThroughPoint(n,t,r){return b.Dist(r,b.NearestPointOnLineThroughPoint(n,t,r))}static DistanceToLineSegment(n,t,r,o=!0){return b.Dist(r,b.NearestPointOnLineSegment(n,t,r,o))}static Snap(n,t=1){return new b(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}static Cast(n){return n instanceof b?n:b.From(n)}static Slope(n,t){return n.x===t.y?NaN:(n.y-t.y)/(n.x-t.x)}static IsNaN(n){return isNaN(n.x)||isNaN(n.y)}static Angle(n,t){return Math.atan2(t.y-n.y,t.x-n.x)}static Lrp(n,t,r){return b.Sub(t,n).mul(r).add(n)}static Med(n,t){return new b((n.x+t.x)/2,(n.y+t.y)/2)}static Equals(n,t){return Math.abs(n.x-t.x)<1e-4&&Math.abs(n.y-t.y)<1e-4}static EqualsXY(n,t,r){return n.x===t&&n.y===r}static Clockwise(n,t,r){return(r.x-n.x)*(t.y-n.y)-(t.x-n.x)*(r.y-n.y)<0}static Rescale(n,t){const r=b.Len(n);return new b(t*n.x/r,t*n.y/r)}static ScaleWithOrigin(n,t,r){return b.Sub(n,r).mul(t).add(r)}static ToFixed(n){return new b(Fo(n.x),Fo(n.y))}static ToInt(n){return new b(parseInt(n.x.toFixed(0)),parseInt(n.y.toFixed(0)),parseInt((n.z??0).toFixed(0)))}static ToCss(n){return`${n.x},${n.y}`}static Nudge(n,t,r){return b.Add(n,b.Tan(t,n).mul(r))}static ToString(n){return`${n.x}, ${n.y}`}static ToAngle(n){let t=Math.atan2(n.y,n.x);return t<0&&(t+=Math.PI*2),t}static FromAngle(n,t=1){return new b(Math.cos(n)*t,Math.sin(n)*t)}static ToArray(n){return[n.x,n.y,n.z]}static ToJson(n){const{x:t,y:r,z:o}=n;return{x:t,y:r,z:o}}static Average(n){const t=n.length,r=new b(0,0);if(t===0)return r;for(let o=0;o<t;o++)r.add(n[o]);return r.div(t)}static Clamp(n,t,r){return r===void 0?new b(Math.min(Math.max(n.x,t)),Math.min(Math.max(n.y,t))):new b(Math.min(Math.max(n.x,t),r),Math.min(Math.max(n.y,t),r))}static PointsBetween(n,t,r=6){const o=[];for(let s=0;s<r;s++){const i=At.easeInQuad(s/(r-1)),a=b.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-a7(i))*.65),o.push(a)}return o}static SnapToGrid(n,t=8){return new b(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}}const a7=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ee(e){return`${z(e.x)},${z(e.y)} `}function En(e,n){return`${z((e.x+n.x)/2)},${z((e.y+n.y)/2)} `}const ke=Math.PI,Ve=ke/2,De=ke*2,c7=Math.sin;function Tt(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function yu(e,n=1e10){return e?Math.round(e*n)/n:0}function Os(e,n,t=1e-6){return Math.abs(e-n)<=t}function yk(e,n){const t=Math.pow(e-n,2)/Math.pow(e+n,2);return ke*(e+n)*(1+3*t/(10+Math.sqrt(4-3*t)))}function Ds(e){return e=e%De,e<0?e=e+De:e===0&&(e=0),e}function jd(e,n){return e=Ds(e),n=Ds(n),e>n&&(n+=De),n-e}function Sk(e,n){return De-jd(e,n)}function mh(e,n){const t=(n-e)%De;return 2*t%De-t}function gS(e){return(De+e)%De}function Df(e,n){const t=De/n;let r=Math.floor((gS(e)+t/2)/t)*t%De;return r<ke&&(r+=De),r>ke&&(r-=De),r}function vk(e,n){return e===n||Os(e%(Math.PI/2)-n%(Math.PI/2),0)}function l7(e){return e*ke/180}function d7(e){return e*180/ke}function Fi(e,n,t){return new b(e.x,e.y).add(b.FromAngle(t,n))}function fm(e,n,t){const r=e/2,o=n/2,s=[];let i=1/0,a=-1/0,c=1/0,l=-1/0;for(let S=0;S<t;S++){const g=De/t,w=-Ve+S*g,y=r+r*Math.cos(w),v=o+o*Math.sin(w);y<i&&(i=y),v<c&&(c=v),y>a&&(a=y),v>l&&(l=v),s.push(new b(y,v))}const d=a-i,u=l-c,f=e-d,p=n-u;if(f!==0||p!==0)for(let S=0;S<s.length;S++){const g=s[S];g.x=(g.x-i)/d*e,g.y=(g.y-c)/u*n}return s}function Qc(e,n,t,r){return e<r&&t<n}function Mr(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function E1(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function Jn(e,n){let t=0,r,o;for(let s=0;s<n.length;s++){if(r=n[s],r.x===e.x&&r.y===e.y||(o=n[(s+1)%n.length],b.Dist(e,r)+b.Dist(e,o)===b.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&E1(r,o,e)>0&&(t+=1):o.y<=e.y&&E1(r,o,e)<0&&(t-=1)}return t!==0}function z(e){return Math.round(e*1e4)/1e4}function Fo(e){return Math.round(e*100)/100}const _1=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function Cs(e,n,t){return t<0?jd(e,n):Sk(e,n)}function mS(e,n,t,r){let o;if(Math.abs(e)>ke){o=mh(n,r);const s=mh(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=mh(n,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function u7(e,n,t,r){const o=2*((n-e)%De)%De-(n-e)%De;return r?(De-Math.abs(o))*(t?1:-1):o}function N0(e,n,t){const r=-2*(e.x*(n.y-t.y)-e.y*(n.x-t.x)+n.x*t.y-t.x*n.y);return new b(((e.x*e.x+e.y*e.y)*(t.y-n.y)+(n.x*n.x+n.y*n.y)*(e.y-t.y)+(t.x*t.x+t.y*t.y)*(n.y-e.y))/r,((e.x*e.x+e.y*e.y)*(n.x-t.x)+(n.x*n.x+n.y*n.y)*(t.x-e.x)+(t.x*t.x+t.y*t.y)*(e.x-n.x))/r)}function h7(e,n,t,r,o){if(t===null)return[b.From(e),b.From(n)];const s=[],i=b.Angle(t,e),a=b.Angle(t,n),c=jd(i,a);for(let l=0;l<o;l++){const d=l/(o-1),u=i+c*d,f=Fi(t,r,u);s.push(f)}return s}const pm=({brush:e,color:n,opacity:t,className:r})=>{const o=x.useRef(null);$c(o,e.x,e.y);const s=z(Math.max(1,e.w)),i=z(Math.max(1,e.h));return h.jsx("svg",{className:"tl-overlays__item",ref:o,children:n?h.jsxs("g",{className:"tl-brush",opacity:t,children:[h.jsx("rect",{width:s,height:i,fill:n,opacity:.75}),h.jsx("rect",{width:s,height:i,fill:"none",stroke:n,opacity:.1})]}):h.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},k1={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},T1={onResolveAsset:async e=>(e==null?void 0:e.props.src)||""},gm={duration:0,easing:At.easeInOutCubic},$1={CAMERA_MOVE:-10},f7=["top","right","bottom","left"],M1=0,B0=2,Su=1,A1=5,p7=128;var mm={};const g7={},xk=bn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),wt={logPreventDefaults:bn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:bn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:bn("logElementRemoves",{defaults:{all:!1}}),debugSvg:bn("debugSvg",{defaults:{all:!1}}),showFps:bn("showFps",{defaults:{all:!1}}),measurePerformance:bn("measurePerformance",{defaults:{all:!1}}),throwToBlob:bn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:bn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:bn("debugCursors",{defaults:{all:!1}}),forceSrgb:bn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:bn("debugGeometry",{defaults:{all:!1}}),hideShapes:bn("hideShapes",{defaults:{all:!1}}),editOnType:bn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;ta("element removal logging",()=>{wt.logElementRemoves.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function bn(e,{defaults:n,shouldStoreForSession:t=!0}){return m7({name:e,defaults:n,shouldStoreForSession:t})}function m7(e){const n=S7(e),t=e.shouldStoreForSession?y7(e.name):null,r=Mt(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&ta(`debug:${e.name}`,()=>{const o=r.get();o===n?f_(`tldraw_debug:${e.name}`):_0(`tldraw_debug:${e.name}`,JSON.stringify(o))}),Object.defineProperty(window,`tldraw${e.name.replace(/^[a-z]/,o=>o.toUpperCase())}`,{get(){return r.get()},set(o){r.set(o)},configurable:!0})),Object.assign(r,e)}function y7(e){try{return JSON.parse(h_(`tldraw_debug:${e}`)??"null")}catch{return null}}function ym(e){try{return e()}catch{return null}}function S7(e){switch(ym(()=>mm.TLDRAW_ENV)??ym(()=>mm.VERCEL_PUBLIC_TLDRAW_ENV)??ym(()=>mm.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 Rf(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return Rf(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function _e(e){e.preventDefault(),wt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Od(e,n){if(e.setPointerCapture(n.pointerId),wt.logPointerCaptures.get()){const t=xk.get();t.set(e,(t.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,n)}}function Dd(e,n){if(e.hasPointerCapture(n.pointerId)&&(e.releasePointerCapture(n.pointerId),wt.logPointerCaptures.get())){const t=xk.get();t.get(e)===1?t.delete(e):t.has(e)?t.set(e,t.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,n)}}const Kt=e=>e.stopPropagation(),Qt=(e,n,t)=>{e&&e.style.setProperty(n,t)};function $n(e){return e.isKilled=!0,{point:{x:e.clientX,y:e.clientY,z:e.pressure},shiftKey:e.shiftKey,altKey:e.altKey,ctrlKey:e.metaKey||e.ctrlKey,pointerId:e.pointerId,button:e.button,isPen:e.pointerType==="pen"}}function v7(){const e=N();return x.useMemo(function(){let r,o;function s(g){if(!g.isKilled){if(g.button===B0){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...$n(g)});return}g.button!==0&&g.button!==1&&g.button!==5||(Od(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...$n(g)}))}}function i(g){g.isKilled||g.clientX===r&&g.clientY===o||(r=g.clientX,o=g.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...$n(g)}))}function a(g){g.isKilled||g.button!==0&&g.button!==1&&g.button!==2&&g.button!==5||(r=g.clientX,o=g.clientY,Dd(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...$n(g)}))}function c(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const w=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!0:null})}function l(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const w=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!1:null})}function d(g){g.isKilled=!0,_e(g)}function u(g){g.isKilled=!0,g.target instanceof HTMLElement&&g.target.tagName!=="A"&&g.target.tagName!=="TEXTAREA"&&!(e.getEditingShape()&&g.target.className.includes("tl-text-content"))&&_e(g)}function f(g){_e(g)}async function p(g){var y,v;if(_e(g),!((v=(y=g.dataTransfer)==null?void 0:y.files)!=null&&v.length))return;const w=Array.from(g.dataTransfer.files);await e.putExternalContent({type:"files",files:w,point:e.screenToPage({x:g.clientX,y:g.clientY}),ignoreParent:!1})}function S(g){Kt(g)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:c,onPointerLeave:l,onDragOver:f,onDrop:p,onTouchStart:d,onTouchEnd:u,onClick:S}},[e])}function x7(){const e=N();x.useEffect(()=>{let n=e.getInstanceState().isCoarsePointer;const t=i=>{const a=i.pointerType!=="mouse";n!==a&&(n=a,e.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",t,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),o=e.environment.isFirefox&&!e.environment.isAndroid&&!e.environment.isIos,s=()=>{const i=o?!1:r.matches;n===i&&(n=i,e.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",s),s()),()=>{window.removeEventListener("pointerdown",t,{capture:!0}),r&&r.removeEventListener("change",s)}},[e])}const wk=x.createContext(null);function w7({container:e,children:n}){return h.jsx(wk.Provider,{value:e,children:n})}function dn(){return mr(x.useContext(wk),"useContainer used outside of <Tldraw />")}function b7(){const e=N(),n=dn(),t=W("isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=c=>{c.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},e.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[e]),x.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!vu()&&_e(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){_e(a);return}break}case"Tab":{if(vu()||e.getIsMenuOpen())return;break}case",":return;case"Escape":{if((e.getEditingShape()||e.getSelectedShapeIds().length>0)&&a.preventDefault(),e.getOpenMenus().length>0)return;e.inputs.keys.has("Escape")||(e.inputs.keys.add("Escape"),e.cancel(),e.focus());return}default:if(vu()||e.getIsMenuOpen())return}const c={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(c)},o=a=>{if(a.isKilled||(a.isKilled=!0,vu()||e.getIsMenuOpen())||a.key===",")return;const c={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(c)};function s(a){var c,l;if(n.contains(a.target)){const d=a.touches[0].pageX,u=a.touches[0].radiusX||0;(d-u<10||d+u>e.getViewportScreenBounds().width-10)&&(((c=a.target)==null?void 0:c.tagName)==="BUTTON"&&((l=a.target)==null||l.click()),_e(a))}}const i=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&_e(a)};return n.addEventListener("touchstart",s,{passive:!1}),n.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",_e),document.addEventListener("gesturechange",_e),document.addEventListener("gestureend",_e),n.addEventListener("keydown",r),n.addEventListener("keyup",o),()=>{n.removeEventListener("touchstart",s),n.removeEventListener("wheel",i),document.removeEventListener("gesturestart",_e),document.removeEventListener("gesturechange",_e),document.removeEventListener("gestureend",_e),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const P7=["input","select","button","textarea"];function vu(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||P7.indexOf(e.tagName.toLowerCase())>-1))}const C7=["textarea","input"];function I7(e){const n=N();x.useEffect(()=>{const t=e.current;if(!t)return;const r=o=>{var s;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:i}=o;if(C7.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||n.isIn("select.editing_shape"))return;_e(o)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[n,e])}function E7(e,n,t){return Math.max(n,Math.min(e,t))}const Ht={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 j1(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function O1(e,n,t,r=.15){return r===0?E7(e,n,t):e<n?-j1(n-e,t-n,r)+n:e>t?+j1(e-t,t-n,r)+t:e}function _7(e,[n,t],[r,o]){const[[s,i],[a,c]]=e;return[O1(n,s,i,r),O1(t,a,c,o)]}function k7(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 T7(e){var n=k7(e,"string");return typeof n=="symbol"?n:String(n)}function en(e,n,t){return n=T7(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function D1(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),t.push.apply(t,r)}return t}function ut(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?D1(Object(t),!0).forEach(function(r){en(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):D1(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const bk={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 R1(e){return e?e[0].toUpperCase()+e.slice(1):""}const $7=["enter","leave"];function M7(e=!1,n){return e&&!$7.includes(n)}function A7(e,n="",t=!1){const r=bk[e],o=r&&r[n]||n;return"on"+R1(e)+R1(o)+(M7(t,o)?"Capture":"")}const j7=["gotpointercapture","lostpointercapture"];function O7(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=j7.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function D7(e,n=""){const t=bk[e],r=t&&t[n]||n;return e+r}function Pk(e){return"touches"in e}function R7(e){return Pk(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function L7(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 yS(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 F7(e){return L7(e).map(n=>n.identifier)}function L1(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return yS(t,r)}const F1=40,z1=800;function Ck(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=F1,t*=F1):r===2&&(n*=z1,t*=z1),[n,t]}function z7(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 Lf(e,...n){return typeof e=="function"?e(...n):e}function N7(){}function B7(...e){return e.length===0?N7:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function N1(e,n){return Object.assign({},n,e||{})}const U7=32;class Ik{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?Lf(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,z7(n)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=n.timeStamp-t.timeStamp,t.timeStamp=n.timeStamp,t.elapsedTime=t.timeStamp-t.startTime),t._active){const C=t._delta.map(Math.abs);Ht.addTo(t._distance,C)}this.axisIntent&&this.axisIntent(n);const[i,a]=t._movement,[c,l]=r.threshold,{_step:d,values:u}=t;if(r.hasCustomTransform?(d[0]===!1&&(d[0]=Math.abs(i)>=c&&u[0]),d[1]===!1&&(d[1]=Math.abs(a)>=l&&u[1])):(d[0]===!1&&(d[0]=Math.abs(i)>=c&&Math.sign(i)*c),d[1]===!1&&(d[1]=Math.abs(a)>=l&&Math.sign(a)*l)),t.intentional=d[0]!==!1||d[1]!==!1,!t.intentional)return;const f=[0,0];if(r.hasCustomTransform){const[C,_]=u;f[0]=d[0]!==!1?C-d[0]:0,f[1]=d[1]!==!1?_-d[1]:0}else f[0]=d[0]!==!1?i-d[0]:0,f[1]=d[1]!==!1?a-d[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(f);const p=t.offset,S=t._active&&!t._blocked||t.active;S&&(t.first=t._active&&!t.active,t.last=!t._active&&t.active,t.active=o[this.ingKey]=t._active,n&&(t.first&&("bounds"in r&&(t._bounds=Lf(r.bounds,t)),this.setup&&this.setup()),t.movement=f,this.computeOffset()));const[g,w]=t.offset,[[y,v],[P,E]]=t._bounds;t.overflow=[g<y?-1:g>v?1:0,w<P?-1:w>E?1:0],t._movementBound[0]=t.overflow[0]?t._movementBound[0]===!1?t._movement[0]:t._movementBound[0]:!1,t._movementBound[1]=t.overflow[1]?t._movementBound[1]===!1?t._movement[1]:t._movementBound[1]:!1;const I=t._active?r.rubberband||[0,0]:[0,0];if(t.offset=_7(t._bounds,t.offset,I),t.delta=Ht.sub(t.offset,p),this.computeMovement(),S&&(!t.last||s>U7)){t.delta=Ht.sub(t.offset,p);const C=t.delta.map(Math.abs);Ht.addTo(t.distance,C),t.direction=t.delta.map(Math.sign),t._direction=t._delta.map(Math.sign),!t.first&&s>0&&(t.velocity=[C[0]/s,C[1]/s],t.timeDelta=s)}}emit(){const n=this.state,t=this.shared,r=this.config;if(n._active||this.clean(),(n._blocked||!n.intentional)&&!n._force&&!r.triggerAllEvents)return;const o=this.handler(ut(ut(ut({},t),n),{},{[this.aliasKey]:n.values}));o!==void 0&&(n.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function H7([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 K7 extends Ik{constructor(...n){super(...n),en(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=Ht.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Ht.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[R7(n)]:r.axisThreshold;t.axis=H7(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 W7=e=>e,B1=.15,Ek={enabled(e=!0){return e},eventOptions(e,n,t){return ut(ut({},t.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[B1,B1];case!1:return[0,0];default:return Ht.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return Ht.toVector(e)},transform(e,n,t){const r=e||t.shared.transform;return this.hasCustomTransform=!!r,r||W7},threshold(e){return Ht.toVector(e,0)}},G7=0,Rd=ut(ut({},Ek),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=G7){return e},bounds(e={}){if(typeof e=="function")return s=>Rd.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]]}}),Ld=typeof window<"u"&&window.document&&window.document.createElement;function _k(){return Ld&&"ontouchstart"in window}function V7(){return _k()||Ld&&window.navigator.maxTouchPoints>1}function Y7(){return Ld&&"onpointerdown"in window}function X7(){return Ld&&"exitPointerLock"in window.document}function q7(){try{return"constructor"in GestureEvent}catch{return!1}}const yr={isBrowser:Ld,gesture:q7(),touch:_k(),touchscreen:V7(),pointer:Y7(),pointerLock:X7()},Z7=250,Q7=180,J7=.5,eB=50,tB=250,nB=10,U1={mouse:0,touch:0,pen:8};ut(ut({},Rd),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&yr.pointerLock,yr.touch&&t?"touch":this.pointerLock?"mouse":yr.pointer&&!o?"pointer":yr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?Z7:void 0,!(!yr.touchscreen||t===!1))return e||(t!==void 0?"y":void 0)},pointerCapture(e,n,{pointer:{capture:t=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&t},threshold(e,n,{filterTaps:t=!1,tapsThreshold:r=3,axis:o=void 0}){const s=Ht.toVector(e,t?r:o?1:0);return this.filterTaps=t,this.tapsThreshold=r,s},swipe({velocity:e=J7,distance:n=eB,duration:t=tB}={}){return{velocity:this.transform(Ht.toVector(e)),distance:this.transform(Ht.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return Q7;case!1:return 0;default:return e}},axisThreshold(e){return e?ut(ut({},U1),e):U1},keyboardDisplacement(e=nB){return e}});function kk(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 rB=30,oB=100;class sB extends Ik{constructor(...n){super(...n),en(this,"ingKey","pinching"),en(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=Ht.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)*rB-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=L1(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=yS(...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=L1(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=yS(...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=Ht.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=[-Ck(n)[1]/oB*r.offset[0],0],Ht.addTo(r._movement,r._delta),kk(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 iB=ut(ut({},Ek),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!yr.touch&&yr.gesture)return"gesture";if(yr.touch&&r)return"touch";if(yr.touchscreen){if(yr.pointer)return"pointer";if(yr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=i=>{const a=N1(Lf(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=N1(Lf(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",Ht.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});ut(ut({},Rd),{},{mouseOnly:(e=!0)=>e});class aB extends K7{constructor(...n){super(...n),en(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=Ck(n),Ht.addTo(t._movement,t._delta),kk(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 cB=Rd;ut(ut({},Rd),{},{mouseOnly:(e=!0)=>e});const U0=new Map,SS=new Map;function lB(e){U0.set(e.key,e.engine),SS.set(e.key,e.resolver)}const dB={key:"pinch",engine:sB,resolver:iB},uB={key:"wheel",engine:aB,resolver:cB};function hB(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 fB(e,n){if(e==null)return{};var t=hB(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 pB={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=yr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},gB=["target","eventOptions","window","enabled","transform"];function yh(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]=yh(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function mB(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:c}=r,l=fB(r,gB);if(t.shared=yh({target:o,eventOptions:s,window:i,enabled:a,transform:c},pB),n){const d=SS.get(n);t[n]=yh(ut({shared:t.shared},l),d)}else for(const d in l){const u=SS.get(d);u&&(t[d]=yh(ut({shared:t.shared},l[d]),u))}return t}class Tk{constructor(n,t){en(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,s){const i=this._listeners,a=D7(t,r),c=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},l=ut(ut({},c),s);n.addEventListener(a,o,l);const d=()=>{n.removeEventListener(a,o,l),i.delete(d)};return i.add(d),d}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class yB{constructor(){en(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 SB{constructor(n){en(this,"gestures",new Set),en(this,"_targetEventStore",new Tk(this)),en(this,"gestureEventStores",{}),en(this,"gestureTimeoutStores",{}),en(this,"handlers",{}),en(this,"config",{}),en(this,"pointerIds",new Set),en(this,"touchIds",new Set),en(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),vB(this,n)}setEventIds(n){if(Pk(n))return this.touchIds=new Set(F7(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=mB(n,t,this.config)}clean(){this._targetEventStore.clean();for(const n of this.gestures)this.gestureEventStores[n].clean(),this.gestureTimeoutStores[n].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...n){const t=this.config.shared,r={};let o;if(!(t.target&&(o=t.target(),!o))){if(t.enabled){for(const i of this.gestures){const a=this.config[i],c=H1(r,a.eventOptions,!!o);if(a.enabled){const l=U0.get(i);new l(this,n,i).bind(c)}}const s=H1(r,t.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](ut(ut({},this.state.shared),{},{event:a,args:n})),void 0,!0)}for(const s in r)r[s]=B7(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:c}=O7(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:c})}}}}function ha(e,n){e.gestures.add(n),e.gestureEventStores[n]=new Tk(e,n),e.gestureTimeoutStores[n]=new yB}function vB(e,n){n.drag&&ha(e,"drag"),n.wheel&&ha(e,"wheel"),n.scroll&&ha(e,"scroll"),n.move&&ha(e,"move"),n.pinch&&ha(e,"pinch"),n.hover&&ha(e,"hover")}const H1=(e,n,t)=>(r,o,s,i={},a=!1)=>{var c,l;const d=(c=i.capture)!==null&&c!==void 0?c:n.capture,u=(l=i.passive)!==null&&l!==void 0?l:n.passive;let f=a?r:A7(r,o,d);t&&u&&(f+="Passive"),e[f]=e[f]||[],e[f].push(s)},xB=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function wB(e){const n={},t={},r=new Set;for(let o in e)xB.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function fa(e,n,t,r,o,s){if(!e.has(t)||!U0.has(r))return;const i=t+"Start",a=t+"End",c=l=>{let d;return l.first&&i in n&&n[i](l),t in n&&(d=n[t](l)),l.last&&a in n&&n[a](l),d};o[r]=c,s[r]=s[r]||{}}function bB(e,n){const[t,r,o]=wB(e),s={};return fa(o,t,"onDrag","drag",s,n),fa(o,t,"onWheel","wheel",s,n),fa(o,t,"onScroll","scroll",s,n),fa(o,t,"onPinch","pinch",s,n),fa(o,t,"onMove","move",s,n),fa(o,t,"onHover","hover",s,n),{handlers:s,config:n,nativeHandlers:r}}function PB(e,n={},t,r){const o=ve.useMemo(()=>new SB(e),[]);if(o.applyHandlers(e,r),o.applyConfig(n,t),ve.useEffect(o.effect.bind(o)),ve.useEffect(()=>o.clean.bind(o),[]),n.target===void 0)return o.bind.bind(o)}function CB(e){return e.forEach(lB),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=bB(t,r||{});return PB(o,i,void 0,s)}}const K1=10,IB=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function $k(e){let{deltaY:n,deltaX:t}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(n)>K1?K1*Math.sign(n):n)/100:e.shiftKey&&!IB&&(t=n,n=0),{x:-t,y:-n,z:-r}}const EB=CB([uB,dB]);let pa;const _B=e=>pa===void 0?(pa=e,!1):e-pa>120&&e-pa<160?(pa=e,!0):(pa=e,!1);function kB(e){const n=N(),t=x.useMemo(()=>{let r="not sure";const o=({event:g})=>{if(!n.getInstanceState().isFocused||(r="not sure",_B(Date.now())))return;const w=n.getEditingShapeId();if(w){const P=n.getShape(w);if(P&&n.getShapeUtil(P).canScroll(P)){const I=n.getShapePageBounds(w);if(I!=null&&I.containsPoint(n.inputs.currentPagePoint))return}}_e(g),Kt(g);const y=$k(g);if(y.x===0&&y.y===0)return;const v={type:"wheel",name:"wheel",delta:y,point:new b(g.clientX,g.clientY),shiftKey:g.shiftKey,altKey:g.altKey,ctrlKey:g.metaKey||g.ctrlKey};n.dispatch(v)};let s=1,i=1,a=1,c=0;const l=new b,d=new b,u=g=>{const w=e.current;r="not sure";const{event:y,origin:v,da:P}=g;y instanceof WheelEvent||(y.target===w||w!=null&&w.contains(y.target))&&(d.x=v[0],d.y=v[1],l.x=v[0],l.y=v[1],s=P[0],i=n.getZoomLevel(),n.dispatch({type:"pinch",name:"pinch_start",point:{x:v[0],y:v[1],z:n.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey}))},f=g=>{if(g&&(r="zooming"),r==="zooming")return;const w=Math.abs(c-s),y=b.Dist(l,d);switch(r){case"not sure":{w>24?r="zooming":y>16&&(r="panning");break}case"panning":{w>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:u,onPinchEnd:g=>{const w=e.current,{event:y,origin:v,offset:P}=g;if(y instanceof WheelEvent||!(y.target===w||w!=null&&w.contains(y.target)))return;const E=P[0];r="not sure",n.timers.requestAnimationFrame(()=>{n.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:E},delta:{x:v[0],y:v[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey})})},onPinch:g=>{const w=e.current,{event:y,origin:v,offset:P,da:E}=g;if(y instanceof WheelEvent||!(y.target===w||w!=null&&w.contains(y.target)))return;const I=g.type==="gesturechange"||g.type==="gestureend";c=E[0];const C=v[0]-d.x,_=v[1]-d.y;switch(d.x=v[0],d.y=v[1],f(I),r){case"zooming":{a=P[0],n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:C,y:_},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}case"panning":{n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:C,y:_},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}}}}},[n,e]);EB(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function Sm(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function TB(e,n){const t=N();return x.useMemo(()=>{const r=c=>{if(c.isKilled)return;const l=Rf(c.currentTarget);Od(l,c);const{shape:d,handle:u}=Sm(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:d,name:"pointer_down",...$n(c)})};let o,s;return{onPointerDown:r,onPointerMove:c=>{if(c.isKilled||c.clientX===o&&c.clientY===s)return;o=c.clientX,s=c.clientY;const{shape:l,handle:d}=Sm(t,e,n);d&&t.dispatch({type:"pointer",target:"handle",handle:d,shape:l,name:"pointer_move",...$n(c)})},onPointerUp:c=>{if(c.isKilled)return;const l=Rf(c.currentTarget);Dd(l,c);const{shape:d,handle:u}=Sm(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:d,name:"pointer_up",...$n(c)})}}},[t,e,n])}const et=class et{constructor(n=0,t=0,r=0,o=0){m(this,"x",0);m(this,"y",0);m(this,"w",0);m(this,"h",0);this.x=n,this.y=t,this.w=r,this.h=o}get point(){return new b(this.x,this.y)}set point(n){this.x=n.x,this.y=n.y}get minX(){return this.x}set minX(n){this.x=n}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(n){this.y=n}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get width(){return this.w}set width(n){this.w=n}get height(){return this.h}set height(n){this.h=n}get aspectRatio(){return this.width/this.height}get center(){return new b(this.midX,this.midY)}set center(n){this.minX=n.x-this.width/2,this.minY=n.y-this.height/2}get corners(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY)]}get cornersAndCenter(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY),this.center]}get sides(){const{corners:n}=this;return[[n[0],n[1]],[n[1],n[2]],[n[2],n[3]],[n[3],n[0]]]}get size(){return new b(this.w,this.h)}toFixed(){return this.x=yu(this.x),this.y=yu(this.y),this.w=yu(this.w),this.h=yu(this.h),this}setTo(n){return this.x=n.x,this.y=n.y,this.w=n.w,this.h=n.h,this}set(n=0,t=0,r=0,o=0){return this.x=n,this.y=t,this.w=r,this.h=o,this}expand(n){const t=Math.min(this.minX,n.minX),r=Math.min(this.minY,n.minY),o=Math.max(this.maxX,n.maxX),s=Math.max(this.maxY,n.maxY);return this.x=t,this.y=r,this.w=o-t,this.h=s-r,this}expandBy(n){return this.x-=n,this.y-=n,this.w+=n*2,this.h+=n*2,this}scale(n){return this.x/=n,this.y/=n,this.w/=n,this.h/=n,this}clone(){const{x:n,y:t,w:r,h:o}=this;return new et(n,t,r,o)}translate(n){return this.x+=n.x,this.y+=n.y,this}snapToGrid(n){const t=Math.round(this.minX/n)*n,r=Math.round(this.minY/n)*n,o=Math.round(this.maxX/n)*n,s=Math.round(this.maxY/n)*n;this.minX=t,this.minY=r,this.width=Math.max(1,o-t),this.height=Math.max(1,s-r)}collides(n){return et.Collides(this,n)}contains(n){return et.Contains(this,n)}includes(n){return et.Includes(this,n)}containsPoint(n,t=0){return et.ContainsPoint(this,n,t)}getHandlePoint(n){switch(n){case"top_left":return new b(this.minX,this.minY);case"top_right":return new b(this.maxX,this.minY);case"bottom_left":return new b(this.minX,this.maxY);case"bottom_right":return new b(this.maxX,this.maxY);case"top":return new b(this.midX,this.minY);case"right":return new b(this.maxX,this.midY);case"bottom":return new b(this.midX,this.maxY);case"left":return new b(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(n,t,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:c,minY:l,maxX:d,maxY:u}=this;switch(n){case"left":case"top_left":case"bottom_left":{c+=t;break}case"right":case"top_right":case"bottom_right":{d+=t;break}}switch(n){case"top":case"top_left":case"top_right":{l+=r;break}case"bottom":case"bottom_left":case"bottom_right":{u+=r;break}}const f=(d-c)/(i-o),p=(u-l)/(a-s),S=f<0,g=p<0;if(S){const w=d;d=c,c=w}if(g){const w=u;u=l,l=w}this.minX=c,this.minY=l,this.width=Math.abs(d-c),this.height=Math.abs(u-l)}union(n){const t=Math.min(this.minX,n.x),r=Math.min(this.minY,n.y),o=Math.max(this.maxX,n.w+n.x),s=Math.max(this.maxY,n.h+n.y);return this.x=t,this.y=r,this.width=o-t,this.height=s-r,this}static From(n){return new et(n.x,n.y,n.w,n.h)}static FromCenter(n,t){return new et(n.x-t.x/2,n.y-t.y/2,t.x,t.y)}static FromPoints(n){if(n.length===0)return new et;let t=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,c=n.length;a<c;a++)i=n[a],t=Math.min(i.x,t),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new et(t,r,o-t,s-r)}static Expand(n,t){const r=Math.min(t.minX,n.minX),o=Math.min(t.minY,n.minY),s=Math.max(t.maxX,n.maxX),i=Math.max(t.maxY,n.maxY);return new et(r,o,s-r,i-o)}static ExpandBy(n,t){return new et(n.minX-t,n.minY-t,n.width+t*2,n.height+t*2)}static Resize(n,t,r,o,s=!1){const{minX:i,minY:a,maxX:c,maxY:l}=n;let{minX:d,minY:u,maxX:f,maxY:p}=n;switch(t){case"left":case"top_left":case"bottom_left":{d+=r;break}case"right":case"top_right":case"bottom_right":{f+=r;break}}switch(t){case"top":case"top_left":case"top_right":{u+=o;break}case"bottom":case"bottom_left":case"bottom_right":{p+=o;break}}const S=(f-d)/(c-i),g=(p-u)/(l-a),w=S<0,y=g<0;if(s){const P=(c-i)/(l-a),E=Math.abs(f-d),I=Math.abs(p-u),C=E*(g<0?1:-1)*(1/P),_=I*(S<0?1:-1)*P,k=P<E/I;switch(t){case"top_left":{k?u=p+C:d=f+_;break}case"top_right":{k?u=p+C:f=d-_;break}case"bottom_right":{k?p=u-C:f=d-_;break}case"bottom_left":{k?p=u-C:d=f+_;break}case"bottom":case"top":{const j=(d+f)/2,T=I*P;d=j-T/2,f=j+T/2;break}case"left":case"right":{const j=(u+p)/2,T=E/P;u=j-T/2,p=j+T/2;break}}}if(w){const P=f;f=d,d=P}if(y){const P=p;p=u,u=P}const v=new et(d,u,Math.abs(f-d),Math.abs(p-u));return{box:v,scaleX:+(v.width/n.width*(S>0?1:-1)).toFixed(5),scaleY:+(v.height/n.height*(g>0?1:-1)).toFixed(5)}}equals(n){return et.Equals(this,n)}static Equals(n,t){return t.x===n.x&&t.y===n.y&&t.w===n.w&&t.h===n.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(n){return new et(n.x,n.y,Math.max(1,n.w),Math.max(1,n.h))}};m(et,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),m(et,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),m(et,"Includes",(n,t)=>et.Collides(n,t)||et.Contains(n,t)),m(et,"ContainsPoint",(n,t,r=0)=>!(t.x<n.minX-r||t.y<n.minY-r||t.x>n.maxX+r||t.y>n.maxY+r)),m(et,"Common",n=>{let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<n.length;i++){const a=n[i];t=Math.min(t,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new et(t,r,o-t,s-r)}),m(et,"Sides",(n,t=0)=>{const{corners:r}=n;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let J=et;function $B(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 MB(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 AB(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function jB(e){const n=N();x.useLayoutEffect(()=>{let t=new J;function r(){const l=e.current;if(!l)return null;const d=l.getBoundingClientRect(),u=new J(d.left||d.x,d.top||d.y,Math.max(d.width,1),Math.max(d.height,1));t.equals(u)||(n.updateViewportScreenBounds(u),t=u)}r();const o=YE(r,200,{trailing:!0}),s=n.timers.setInterval(o,1e3);window.addEventListener("resize",o);const i=new ResizeObserver(l=>{l[0].contentRect&&o()}),a=e.current;let c=null;return a&&(i.observe(a),c=OB(a),c.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),c==null||c.removeEventListener("scroll",o),o.cancel()}},[n,e])}/*!
|
|
53
|
-
* Author: excalidraw
|
|
54
|
-
* MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
|
|
55
|
-
* https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
|
|
56
|
-
*/const OB=e=>{let n=e.parentElement;for(;n;){if(n===document.body)return document;const{overflowY:t}=window.getComputedStyle(n);if(n.scrollHeight>n.clientHeight&&(t==="auto"||t==="scroll"||t==="overlay"))return n;n=n.parentElement}return document},Oe=class Oe{constructor(n,t,r,o,s,i){m(this,"a",1);m(this,"b",0);m(this,"c",0);m(this,"d",1);m(this,"e",0);m(this,"f",0);this.a=n,this.b=t,this.c=r,this.d=o,this.e=s,this.f=i}equals(n){return this===n||this.a===n.a&&this.b===n.b&&this.c===n.c&&this.d===n.d&&this.e===n.e&&this.f===n.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(n){const t=n,{a:r,b:o,c:s,d:i,e:a,f:c}=this;return this.a=r*t.a+s*t.b,this.c=r*t.c+s*t.d,this.e=r*t.e+s*t.f+a,this.b=o*t.a+i*t.b,this.d=o*t.c+i*t.d,this.f=o*t.e+i*t.f+c,this}rotate(n,t,r){return n===0?this:t===void 0?this.multiply(Oe.Rotate(n)):this.translate(t,r).multiply(Oe.Rotate(n)).translate(-t,-r)}translate(n,t){return this.multiply(Oe.Translate(n,t))}scale(n,t){return this.multiply(Oe.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 Oe.applyToPoint(this,n)}applyToPoints(n){return Oe.applyToPoints(this,n)}rotation(){return Oe.Rotation(this)}point(){return Oe.Point(this)}decomposed(){return Oe.Decompose(this)}toCssString(){return Oe.toCssString(this)}setTo(n){return Object.assign(this,n),this}decompose(){return Oe.Decompose(this)}clone(){return new Oe(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new Oe(1,0,0,1,0,0)}static Translate(n,t){return new Oe(1,0,0,1,n,t)}static Rotate(n,t,r){if(n===0)return Oe.Identity();const o=Math.cos(n),s=Math.sin(n),i=new Oe(o,s,-s,o,0,0);return t===void 0?i:Oe.Compose(Oe.Translate(t,r),i,Oe.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=Oe.Identity();for(let r=0,o=n.length;r<o;r++)t.multiply(n[r]);return t}static Point(n){return new b(n.e,n.f)}static Rotation(n){let t;if(n.a!==0||n.c!==0){const r=(n.a*n.a+n.c*n.c)**.5;t=Math.acos(n.a/r)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const r=(n.b*n.b+n.d*n.d)**.5;t=Ve+Math.acos(n.b/r)*(n.d>0?-1:1)}else t=0;return gS(t)}static Decompose(n){let t,r,o;if(n.a!==0||n.c!==0){const s=(n.a*n.a+n.c*n.c)**.5;t=s,r=(n.a*n.d-n.b*n.c)/s,o=Math.acos(n.a/s)*(n.c>0?-1:1)}else if(n.b!==0||n.d!==0){const s=(n.b*n.b+n.d*n.d)**.5;t=(n.a*n.d-n.b*n.c)/s,r=s,o=Ve+Math.acos(n.b/s)*(n.d>0?-1:1)}else t=0,r=0,o=0;return{x:n.e,y:n.f,scaleX:t,scaleY:r,rotation:gS(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(${z(n.a)}, ${z(n.b)}, ${z(n.c)}, ${z(n.d)}, ${z(n.e)}, ${z(n.f)})`}static applyToPoint(n,t){return new b(n.a*t.x+n.c*t.y+n.e,n.b*t.x+n.d*t.y+n.f,t.z)}static applyToXY(n,t,r){return[n.a*t+n.c*r+n.e,n.b*t+n.d*r+n.f]}static applyToPoints(n,t){return t.map(r=>new b(n.a*r.x+n.c*r.y+n.e,n.b*r.x+n.d*r.y+n.f,r.z))}static applyToBounds(n,t){return new J(n.e+t.minX,n.f+t.minY,t.width,t.height)}static From(n){return new Oe(n.a,n.b,n.c,n.d,n.e,n.f)}static Cast(n){return n instanceof Oe?n:Oe.From(n)}};m(Oe,"Scale",(n,t,r,o)=>{const s=new Oe(n,0,0,t,0,0);return r===void 0?s:Oe.Compose(Oe.Translate(r,o),s,Oe.Translate(-r,-o))});let oe=Oe;function Mk(e,n){return n===0?e:Mk(n,e%n)}function Ak(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/Mk(r,t)}class ni{constructor(n){m(this,"isFilled",!1);m(this,"isClosed",!0);m(this,"isLabel",!1);m(this,"debugColor");m(this,"ignore");m(this,"_vertices");m(this,"_bounds");m(this,"_area");m(this,"_length");this.isFilled=n.isFilled,this.isClosed=n.isClosed,this.isLabel=n.isLabel??!1,this.debugColor=n.debugColor,this.ignore=n.ignore}hitTestPoint(n,t=0,r=!1){return this.isClosed&&(this.isFilled||r)&&Jn(n,this.vertices)?!0:b.Dist2(n,this.nearestPoint(n))<=t*t}distanceToPoint(n,t=!1){return n.dist(this.nearestPoint(n))*(this.isClosed&&(this.isFilled||t)&&Jn(n,this.vertices)?-1:1)}distanceToLineSegment(n,t){if(n.equals(t))return this.distanceToPoint(n);const{vertices:r}=this;let o,s=1/0,i,a,c;for(let l=0;l<r.length;l++)a=r[l],c=b.NearestPointOnLineSegment(n,t,a,!0),i=b.Dist2(a,c),i<s&&(s=i,o=c);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Jn(o,this.vertices)?-s:s}hitTestLineSegment(n,t,r=0){return this.distanceToLineSegment(n,t)<=r}nearestPointOnLineSegment(n,t){const{vertices:r}=this;let o,s=1/0,i,a,c;for(let l=0;l<r.length;l++)a=r[l],c=b.NearestPointOnLineSegment(n,t,a,!0),i=b.Dist2(a,c),i<s&&(s=i,o=c);if(!o)throw Error("nearest point not found");return o}isPointInBounds(n,t=0){const{bounds:r}=this;return!(n.x<r.minX-t||n.y<r.minY-t||n.x>r.maxX+t||n.y>r.maxY+t)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return J.FromPoints(this.vertices)}get bounds(){return this._bounds||(this._bounds=this.getBounds()),this._bounds}get center(){return this.bounds.center}get area(){return this._area||(this._area=this.getArea()),this._area}getArea(){if(!this.isClosed)return 0;const{vertices:n}=this;let t=0;for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];t+=s.x*i.y-i.x*s.y}return t/2}toSimpleSvgPath(){let n="";const{vertices:t}=this,r=t.length;if(r===0)return n;n+=`M${t[0].x},${t[0].y}`;for(let o=1;o<r;o++)n+=`L${t[o].x},${t[o].y}`;return this.isClosed&&(n+="Z"),n}get length(){return this._length?this._length:(this._length=this.getLength(),this._length)}getLength(){const{vertices:n}=this;let t,r=n[0],o=0;for(let s=1;s<n.length;s++)t=n[s],o+=b.Dist2(r,t),r=t;return Math.sqrt(o)}}class Ur extends ni{constructor(t){super({...t,isClosed:!0,isFilled:!1});m(this,"children",[]);m(this,"ignoredChildren",[]);for(const r of t.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(t=>!t.isLabel).flatMap(t=>t.vertices)}nearestPoint(t){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");let i,a;for(const c of s)i=c.nearestPoint(t),a=b.Dist2(i,t),a<r&&(r=a,o=i);if(!o)throw Error("nearest point not found");return o}distanceToPoint(t,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(t,r||s>0)))}hitTestPoint(t,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(t,r,o))}hitTestLineSegment(t,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(t,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let t="";for(const o of this.children)t+=o.toSimpleSvgPath();const r=J.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],c=i.dist(a),l=r[(o+1)%s],d=i.dist(l),u=i.clone().lrp(a,4/c),f=i,p=i.clone().lrp(l,4/d);t+=`M${u.x},${u.y} L${f.x},${f.y} L${p.x},${p.y} `}return t}getLength(){return this.children.reduce((t,r)=>r.isLabel?t:t+r.length,0)}getSvgPathData(){return this.children.map((t,r)=>t.isLabel?"":t.getSvgPathData(r===0)).join(" ")}}function DB(e=!0){const[n,t]=x.useState(0),r=N();x.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const RB=sr(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=N();DB(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return h.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(c=>{const l=o.getShape(c.id);if(l.type==="group")return null;const d=o.getShapeGeometry(l),u=o.getShapePageTransform(l),f=o.getPointInShapeSpace(l,a),p=d.nearestPoint(f),S=d.distanceToPoint(f,!0),g=Math.abs(S)*s,w=S<0,{vertices:y}=d;return h.jsxs("g",{transform:u.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&h.jsx("g",{stroke:d.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:h.jsx(jk,{geometry:d})}),t&&y.map((v,P)=>h.jsx("circle",{cx:v.x,cy:v.y,r:2/s,fill:`hsl(${sc(P,[0,y.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${P}`)),r&&g<150&&h.jsx("line",{x1:p.x,y1:p.y,x2:f.x,y2:f.y,opacity:1-g/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:2/s})]},c.id+"_outline")})})});function jk({geometry:e}){return e instanceof Ur?h.jsx(h.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>h.jsx(jk,{geometry:n},t))}):h.jsx("path",{d:e.toSimpleSvgPath()})}function Ok(e){return BN(e)}function LB(){const e=N(),n=j4("userIds",()=>Ok(e.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>{var o;return t.join(",")===((o=r.join)==null?void 0:o.call(r,","))}},[e]);return W(n)}function Dk(e){const n=N();return W(`latestPresence:${e}`,()=>n.getCollaborators().find(r=>r.userId===e),[n,e])??null}const FB=sr(function(){const n=LB();return h.jsx(h.Fragment,{children:n.map(t=>h.jsx(zB,{collaboratorId:t},t))})}),zB=sr(function({collaboratorId:n}){const t=N(),r=Dk(n),o=BB(t,r);if(!(r&&r.currentPageId===t.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:s,highlightedUserIds:i}=t.getInstanceState();if(!(s===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=t.getInstanceState();if(r.followingUserId===t.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return h.jsx(NB,{latestPresence:r})}),NB=sr(function({latestPresence:n}){const t=N(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=at(),c=t.getZoomLevel(),l=t.getViewportPageBounds(),{userId:d,chatMessage:u,brush:f,scribbles:p,selectedShapeIds:S,userName:g,cursor:w,color:y}=n,v=!(w.x<l.minX-12/c||w.y<l.minY-16/c||w.x>l.maxX-12/c||w.y>l.maxY-16/c);return h.jsxs(h.Fragment,{children:[f&&r?h.jsx(r,{className:"tl-collaborator__brush",brush:f,color:y,opacity:.1},d+"_brush"):null,v&&s?h.jsx(s,{className:"tl-collaborator__cursor",point:w,color:y,zoom:c,name:g!=="New User"?g:null,chatMessage:u},d+"_cursor"):i?h.jsx(i,{className:"tl-collaborator__cursor-hint",point:w,color:y,zoom:c,viewport:l},d+"_cursor_hint"):null,o&&p.length?h.jsx(h.Fragment,{children:p.map(P=>h.jsx(o,{className:"tl-collaborator__scribble",scribble:P,color:y,zoom:c,opacity:P.color==="laser"?.5:.1},d+"_scribble_"+P.id))}):null,a&&S.map(P=>h.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:P,color:y,opacity:.5},d+"_"+P))]})});function W1(e,n){return n>e.options.collaboratorInactiveTimeoutMs?"inactive":n>e.options.collaboratorIdleTimeoutMs?"idle":"active"}function BB(e,n){const t=x.useRef((n==null?void 0:n.lastActivityTimestamp)??-1),[r,o]=x.useState(()=>W1(e,Date.now()-t.current));return x.useEffect(()=>{const s=e.timers.setInterval(()=>{o(W1(e,Date.now()-t.current))},e.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[e]),n&&(t.current=n.lastActivityTimestamp),r}const Rk=x.memo(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const c=N(),{ShapeErrorFallback:l}=at(),d=x.useRef(null),u=x.useRef(null),f=x.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});js("set shape stuff",()=>{const g=c.getShape(n);if(!g)return;const w=f.current,y=c.getShapeClipPath(n)??"none";y!==w.clipPath&&(Qt(d.current,"clip-path",y),Qt(u.current,"clip-path",y),w.clipPath=y);const v=c.getShapePageTransform(n),P=oe.toCssString(v),E=c.getShapeGeometry(g).bounds;P!==w.transform&&(Qt(d.current,"transform",P),Qt(u.current,"transform",P),w.transform=P);const I=E.w%a,C=E.h%a,_=I===0?E.w:E.w+(a-I),k=C===0?E.h:E.h+(a-C);(_!==w.width||k!==w.height)&&(Qt(d.current,"width",Math.max(_,a)+"px"),Qt(d.current,"height",Math.max(k,a)+"px"),Qt(u.current,"width",Math.max(_,a)+"px"),Qt(u.current,"height",Math.max(k,a)+"px"),w.width=_,w.height=k)},[c]),js("set opacity and z-index",()=>{const g=d.current,w=u.current;Qt(g,"opacity",i),Qt(w,"opacity",i),Qt(g,"z-index",o),Qt(w,"z-index",s)},[i,o,s]),js("set display",()=>{if(!c.getShape(n))return;const y=c.getCulledShapes().has(n);y!==f.current.isCulled&&(Qt(d.current,"display",y?"none":"block"),Qt(u.current,"display",y?"none":"block"),f.current.isCulled=y)},[c]);const p=x.useCallback(g=>c.annotateError(g,{origin:"shape",willCrashApp:!1}),[c]);if(!t)return null;const S="fill"in t.props&&t.props.fill!=="none";return h.jsxs(h.Fragment,{children:[r.backgroundComponent&&h.jsx("div",{ref:u,className:"tl-shape tl-shape-background","data-shape-type":t.type,draggable:!1,children:h.jsx(Yl,{fallback:l,onError:p,children:h.jsx(HB,{shape:t,util:r})})}),h.jsx("div",{ref:d,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":S,draggable:!1,children:h.jsx(Yl,{fallback:l,onError:p,children:h.jsx(UB,{shape:t,util:r})})})]})}),UB=x.memo(function({shape:n,util:t}){return Mp("InnerShape:"+n.type,()=>t.component(t.editor.store.unsafeGetWithoutCapture(n.id)))},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta),HB=x.memo(function({shape:n,util:t}){return Mp("InnerShape:"+n.type,()=>{var r;return(r=t.backgroundComponent)==null?void 0:r.call(t,t.editor.store.unsafeGetWithoutCapture(n.id))})},(e,n)=>e.shape.props===n.shape.props&&e.shape.meta===n.shape.meta);function KB({className:e}){const n=N(),{Background:t,SvgDefs:r}=at(),o=x.useRef(null),s=x.useRef(null),i=x.useRef(null),a=dn();jB(o),b7(),x7(),kB(o),I7(o);const c=x.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});js("position layers",function(){const{x:y,y:v,z:P}=n.getCamera();if(c.current.allowTextOutline&&n.environment.isSafari&&(a.style.setProperty("--tl-text-outline","none"),c.current.allowTextOutline=!1),c.current.allowTextOutline&&P<n.options.textShadowLod!==c.current.lodDisableTextOutline){const C=P<n.options.textShadowLod;a.style.setProperty("--tl-text-outline",C?"none":"var(--tl-text-outline-reference)"),c.current.lodDisableTextOutline=C}const E=P>=1?sc(P,[1,8],[.125,.5],!0):sc(P,[.1,1],[-2,.125],!0),I=`scale(${z(P)}) translate(${z(y+E)}px,${z(v+E)}px)`;Qt(s.current,"transform",I),Qt(i.current,"transform",I)},[n,a]);const l=v7(),d=W("shapeSvgDefs",()=>{const w=new Map;for(const y of yt(n.shapeUtils)){if(!y)return;const v=y.getCanvasSvgDefs();for(const{key:P,component:E}of v)w.has(P)||w.set(P,h.jsx(E,{},P))}return[...w.values()]},[n]),u=W("debug_shapes",()=>wt.hideShapes.get(),[wt]),f=W("debug_svg",()=>wt.debugSvg.get(),[wt]),p=W("debug_geometry",()=>wt.debugGeometry.get(),[wt]),S=W("isEditingAnything",()=>n.getEditingShapeId()!==null,[n]),g=W("isSelectingAnything",()=>!!n.getSelectedShapeIds().length,[n]);return h.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":S,"data-isselectinganything":g,className:de("tl-canvas",e),"data-testid":"canvas",...l,children:[h.jsx("svg",{className:"tl-svg-context",children:h.jsxs("defs",{children:[d,h.jsx(oU,{}),h.jsx(sU,{}),r&&h.jsx(r,{})]})}),t&&h.jsx("div",{className:"tl-background__wrapper",children:h.jsx(t,{})}),h.jsx(WB,{}),h.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[h.jsx(lU,{}),h.jsx(cU,{}),u?null:f?h.jsx(JB,{}):h.jsx(tU,{})]}),h.jsx("div",{className:"tl-overlays",children:h.jsxs("div",{ref:i,className:"tl-html-layer",children:[p?h.jsx(RB,{}):null,h.jsx(qB,{}),h.jsx(VB,{}),h.jsx(GB,{}),h.jsx(YB,{}),h.jsx(nU,{}),h.jsx(rU,{}),h.jsx(XB,{}),h.jsx(aU,{}),h.jsx(FB,{})]})}),h.jsx(dU,{})]})}function WB(){const e=N(),n=W("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=W("camera",()=>e.getCamera(),[e]),s=W("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=at();return i&&s?h.jsx(i,{x:t,y:r,z:o,size:n}):null}function GB(){const e=N(),n=W("scribbles",()=>e.getInstanceState().scribbles,[e]),t=W("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=at();return r&&n.length?h.jsx(h.Fragment,{children:n.map(o=>h.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:t},o.id))}):null}function VB(){const e=N(),n=W("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=at();return t&&n?h.jsx(t,{className:"tl-user-brush",brush:n}):null}function YB(){const e=N(),n=W("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=at();return t&&n?h.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function XB(){const e=N(),n=W("snapLines",()=>e.snaps.getIndicators(),[e]),t=W("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=at();return r&&n.length>0?h.jsx(h.Fragment,{children:n.map(o=>h.jsx(r,{className:"tl-user-snapline",line:o,zoom:t},o.id))}):null}function qB(){const e=N(),n=W("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=e.getInstanceState();if(t||r)return!1;const o=e.getOnlySelectedShape();return!o||!e.getShapeHandles(o)?!1:o.id},[e]);return n?h.jsx(ZB,{shapeId:n}):null}function ZB({shapeId:e}){const n=N(),{Handles:t}=at(),r=W("zoomLevel",()=>n.getZoomLevel(),[n]),o=W("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),s=W("handles transform",()=>n.getShapePageTransform(e),[n,e]),i=W("handles",()=>{const a=n.getShapeHandles(e);if(!a)return null;const c=(o?n.options.coarseHandleRadius:n.options.handleRadius)/r*2;return a.filter(l=>l.type!=="virtual"||!a.some(d=>d!==l&&d.type==="vertex"&&b.Dist(l,d)<c)).sort(l=>l.type==="vertex"?1:-1)},[n,r,o,e]);return!t||!i||!s?null:h.jsx(t,{children:h.jsx("g",{transform:oe.toCssString(s),children:i.map(a=>h.jsx(QB,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function QB({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=TB(e,n.id),{Handle:s}=at();return s?h.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:h.jsx(s,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function JB(){const e=N(),n=W("rendering shapes",()=>e.getRenderingShapes(),[e]),t=W("dpr multiple",()=>Ak(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsx(h.Fragment,{children:n.map(r=>h.jsxs(x.Fragment,{children:[h.jsx(Rk,{...r,dprMultiple:t}),h.jsx(iU,{id:r.id})]},r.id+"_fragment"))})}function eU(){const e=N(),n=x.useRef(new Set);return js("reflow for culled shapes",()=>{const t=e.getCulledShapes();if(n.current.size===t.size&&[...t].every(o=>n.current.has(o)))return;n.current=t;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[e]),null}function tU(){const e=N(),n=W("rendering shapes",()=>e.getRenderingShapes(),[e]),t=W("dpr multiple",()=>Ak(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsxs(h.Fragment,{children:[n.map(r=>h.jsx(Rk,{...r,dprMultiple:t},r.id+"_shape")),e.environment.isSafari&&h.jsx(eU,{})]})}function nU(){const e=N(),n=W("rendering shapes",()=>e.getRenderingShapes(),[e]),t=x.useRef(new Set),r=W("should display selected ids",()=>{const s=t.current,i=new Set;if(e.isInAny("select.idle","select.brushing","select.scribble_brushing","select.editing_shape","select.pointing_shape","select.pointing_selection","select.pointing_handle")&&!e.getInstanceState().isChangingStyle){const a=e.getSelectedShapeIds();for(const c of a)i.add(c);if(e.isInAny("select.idle","select.editing_shape")){const c=e.getInstanceState();if(c.isHoveringCanvas&&!c.isCoarsePointer){const l=e.getHoveredShapeId();l&&i.add(l)}}}if(s.size!==i.size)return t.current=i,i;for(const a of i)if(!s.has(a))return t.current=i,i;return s},[e]),{ShapeIndicator:o}=at();return o?h.jsx(h.Fragment,{children:n.map(({id:s})=>h.jsx(o,{shapeId:s,hidden:!r.has(s)},s+"_indicator"))}):null}function rU(){const e=N(),{ShapeIndicator:n}=at(),t=W("hinting shape ids",()=>b0(e.getHintingShapeIds()),[e]);return!t.length||!n?null:h.jsx(h.Fragment,{children:t.map(r=>h.jsx(n,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))})}function oU(){return h.jsxs("g",{id:"cursor",children:[h.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),h.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function sU(){return h.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function iU({id:e}){const n=N(),[t,r]=x.useState(null),o=W("is in root",()=>{const s=n.getShape(e);return(s==null?void 0:s.parentId)===n.getCurrentPageId()},[n,e]);return x.useEffect(()=>{if(!o)return;let s=null;const i=ta("shape to svg",async()=>{const a=Math.random();s=a;const l=n.isShapeOfType(e,"frame")?0:10;let d=n.getShapePageBounds(e);if(!d)return;d=d.clone().expandBy(l);const u=await n.getSvgString([e],{padding:l,background:n.getInstanceState().exportBackground});if(s!==a||!u)return;const f=`data:image/svg+xml;utf8,${encodeURIComponent(u.svg)}`;r({src:f,bounds:d})});return()=>{s=null,i()}},[n,e,o]),!o||!t?null:h.jsx("img",{src:t.src,width:t.bounds.width,height:t.bounds.height,referrerPolicy:"no-referrer",style:{position:"absolute",top:0,left:0,transform:`translate(${t.bounds.x}px, ${t.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function aU(){const e=N(),n=W("selection rotation",()=>e.getSelectionRotation(),[e]),t=W("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=at();return!t||!r?null:h.jsx(r,{bounds:t,rotation:n})}function cU(){const e=N(),n=W("selection rotation",()=>e.getSelectionRotation(),[e]),t=W("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=at();return!t||!r?null:h.jsx(r,{bounds:t,rotation:n})}function lU(){const{OnTheCanvas:e}=at();return e?h.jsx(e,{}):null}function dU(){const e=N(),n=W("camera state",()=>e.getCameraState(),[e]);return h.jsx("div",{className:de("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":n==="idle"})})}function uU({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1}){const i=x.useRef(null);return $c(i,Tt(t.x,o.minX+5/n,o.maxX-5/n),Tt(t.y,o.minY+5/n,o.maxY-5/n),1/n,b.Angle(o.center,t)),h.jsxs("svg",{ref:i,className:de("tl-overlays__item",e),children:[h.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),h.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const G1=x.memo(function({className:n,zoom:t,point:r,color:o,name:s,chatMessage:i}){const a=x.useRef(null);return $c(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t),r?h.jsxs("div",{ref:a,className:de("tl-overlays__item",n),children:[h.jsx("svg",{className:"tl-cursor",children:h.jsx("use",{href:"#cursor",color:o})}),i?h.jsxs(h.Fragment,{children:[s&&h.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),h.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&h.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function hU({x:e,y:n,z:t,size:r}){const o=N(),{gridSteps:s}=o.options;return h.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("defs",{children:s.map(({min:i,mid:a,step:c},l)=>{const d=c*r*t,u=.5+e*t,f=.5+n*t,p=u>0?u%d:d+u%d,S=f>0?f%d:d+f%d,g=t<a?sc(t,[i,a],[0,1]):1;return h.jsx("pattern",{id:`grid-${c}`,width:d,height:d,patternUnits:"userSpaceOnUse",children:h.jsx("circle",{className:"tl-grid-dot",cx:p,cy:S,r:1,opacity:g})},`grid-pattern-${l}`)})}),s.map(({step:i},a)=>h.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${i})`},`grid-rect-${a}`))]})}function fU({handle:e,isCoarse:n,className:t,zoom:r}){const o=N(),s=(n?o.options.coarseHandleRadius:o.options.handleRadius)/r;if(e.type==="clone"){const a=3/r,c=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,l=f7.indexOf(e.id);return h.jsxs("g",{className:de(`tl-handle tl-handle__${e.type}`,t),children:[h.jsx("circle",{className:"tl-handle__bg",r:s}),h.jsx("path",{className:"tl-handle__fg",d:c,transform:`rotate(${-90+90*l})`})]})}const i=(e.type==="create"&&n?3:4)/Math.max(r,.25);return h.jsxs("g",{className:de(`tl-handle tl-handle__${e.type}`,t),children:[h.jsx("circle",{className:"tl-handle__bg",r:s}),h.jsx("circle",{className:"tl-handle__fg",r:i})]})}const pU=({children:e})=>h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),gU=()=>{const{Spinner:e}=at();return h.jsx(Gx,{children:e?h.jsx(e,{}):null})};function H0(e,n=!0){const t=e.length;if(t<2)return"";let r=e[0],o=e[1];if(t===2)return`M${Ee(r)}L${Ee(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i],o=e[i+1],s+=En(r,o);return n?`M${En(e[0],e[1])}Q${Ee(e[1])}${En(e[1],e[2])}T${s}${En(e[t-1],e[0])}${En(e[0],e[1])}Z`:`M${Ee(e[0])}Q${Ee(e[1])}${En(e[1],e[2])}${e.length>3?"T":""}${s}L${Ee(e[t-1])}`}function V1({scribble:e,zoom:n,color:t,opacity:r,className:o}){return e.points.length?h.jsx("svg",{className:o&&de("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:H0(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null}function Lk({bounds:e,rotation:n}){const t=x.useRef(null);return $c(t,e.x,e.y,1,n),x.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=z(Math.max(1,e.width))+"px",r.style.height=z(Math.max(1,e.height))+"px")},[e.width,e.height]),h.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function mU({bounds:e,rotation:n}){const t=N(),r=x.useRef(null),o=W("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return $c(r,e==null?void 0:e.x,e==null?void 0:e.y,1,n,{x:-s,y:-s}),e=e.clone().expandBy(s).zeroFix(),h.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsx("rect",{className:de("tl-selection__fg__outline"),width:z(e.width),height:z(e.height)})})}const yU=()=>h.jsx("div",{className:"tl-shape-error-boundary"}),SU=({shape:e,util:n})=>Mp("Indicator: "+e.type,()=>n.indicator(n.editor.store.unsafeGetWithoutCapture(e.id))),vU=({editor:e,id:n})=>{const t=W("shape for indicator",()=>e.store.get(n),[e,n]),{ShapeIndicatorErrorFallback:r}=at();return!t||t.isLocked?null:h.jsx(Yl,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:h.jsx(SU,{shape:t,util:e.getShapeUtil(t)},t.id)})},Y1=x.memo(function({shapeId:n,className:t,color:r,hidden:o,opacity:s}){const i=N(),a=x.useRef(null);return js("indicator transform",()=>{const c=a.current;if(!c)return;const l=i.getShapePageTransform(n);l&&c.style.setProperty("transform",l.toCssString())},[i,n]),x.useLayoutEffect(()=>{const c=a.current;c&&c.style.setProperty("display",o?"none":"block")},[o]),h.jsx("svg",{ref:a,className:de("tl-overlays__item",t),children:h.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:h.jsx(vU,{editor:i,id:n})})})}),xU=()=>h.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function wU({points:e,zoom:n}){const t=2.5/n,r=e.reduce((f,p)=>Math.min(f,p.x),1/0),o=e.reduce((f,p)=>Math.max(f,p.x),-1/0),s=e.reduce((f,p)=>Math.min(f,p.y),1/0),i=e.reduce((f,p)=>Math.max(f,p.y),-1/0),a=e.some(f=>f.x===r&&f.y===s);let c,l,d,u;return a?(c=r,l=s,d=o,u=i):(c=r,l=i,d=o,u=s),h.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[h.jsx("line",{x1:c,y1:l,x2:d,y2:u}),e.map((f,p)=>h.jsx("g",{transform:`translate(${f.x},${f.y})`,children:h.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},p))]})}function bU({gaps:e,direction:n,zoom:t}){const r=3.5/t;let o=[-1/0,1/0],s=null;const i=n==="horizontal";for(const c of e){if(s=Mr(o[0],o[1],i?c.startEdge[0].y:c.startEdge[0].x,i?c.startEdge[1].y:c.startEdge[1].x),s)o=s;else continue;if(s=Mr(o[0],o[1],i?c.endEdge[0].y:c.endEdge[0].x,i?c.endEdge[1].y:c.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return h.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:c,endEdge:l},d)=>h.jsx(x.Fragment,{children:i?h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),h.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),h.jsx("line",{x1:c[0].x,y1:a,x2:l[0].x,y2:a}),h.jsx("line",{x1:(c[0].x+l[0].x)/2,y1:a-r,x2:(c[0].x+l[0].x)/2,y2:a+r})]}):h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),h.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),h.jsx("line",{x1:a,y1:c[0].y,x2:a,y2:l[0].y}),h.jsx("line",{x1:a-r,y1:(c[0].y+l[0].y)/2,x2:a+r,y2:(c[0].y+l[0].y)/2})]})},d))})}function PU({className:e,line:n,zoom:t}){return h.jsx("svg",{className:de("tl-overlays__item",e),children:n.type==="points"?h.jsx(wU,{...n,zoom:t}):n.type==="gaps"?h.jsx(bU,{...n,zoom:t}):null})}function K0(){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const CU=()=>null;function Fk(e,n){const t=x.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Tl(e){return Fk(e,KN)}function W0(e){return Fk(e,a_)}const zk=x.createContext(null);function IU({overrides:e={},children:n}){const t=W0(e);return h.jsx(zk.Provider,{value:x.useMemo(()=>({Background:i7,SvgDefs:CU,Brush:pm,ZoomBrush:pm,CollaboratorBrush:pm,Cursor:G1,CollaboratorCursor:G1,CollaboratorHint:uU,CollaboratorShapeIndicator:Y1,Grid:hU,Scribble:V1,SnapIndicator:PU,Handles:pU,Handle:fU,CollaboratorScribble:V1,ErrorFallback:Bk,ShapeErrorFallback:yU,ShapeIndicatorErrorFallback:xU,Spinner:K0,SelectionBackground:Lk,SelectionForeground:mU,ShapeIndicator:Y1,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:KB,LoadingScreen:gU,...t}),[t]),children:n})}function at(){const e=x.useContext(zk);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const G0={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 Nk(){G0.hardReset()}function EU(){G0.refreshPage()}const _U="https://github.com/tldraw/tldraw/issues/new",Bk=({error:e,editor:n})=>{const t=x.useRef(null),[r,o]=x.useState(!1),[s,i]=x.useState(!1),[a,c]=x.useState(!1);let l=null;try{l=at().Canvas??null}catch{}const d=e instanceof Error?e.message:String(e),u=e instanceof Error?e.stack:null,f=W("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[p,S]=x.useState(null);x.useLayoutEffect(()=>{var I;f!==null&&S(f);let P=(I=t.current)==null?void 0:I.parentElement,E=!1;for(;P;){if(P.classList.contains("tl-theme__dark")||P.classList.contains("tl-theme__light")){E=!0;break}P=P.parentElement}if(E){S(null);return}S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[f]),x.useEffect(()=>{if(s){const P=n==null?void 0:n.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(P)}},[s,n]);const g=()=>{const P=document.createElement("textarea");P.value=u??d,document.body.appendChild(P),P.select(),document.execCommand("copy"),P.remove(),i(!0)},w=()=>{EU()},y=async()=>{Nk()},v=new URL(_U);return v.searchParams.set("title",d),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
57
|
-
|
|
58
|
-
\`\`\`js
|
|
59
|
-
${u??d}
|
|
60
|
-
\`\`\`
|
|
61
|
-
|
|
62
|
-
My browser: ${navigator.userAgent}`),h.jsxs("div",{ref:t,className:de("tl-container tl-error-boundary",p===null?"":p?"tl-theme__dark":"tl-theme__light"),children:[h.jsx("div",{className:"tl-error-boundary__overlay"}),n&&h.jsx(mk,{onError:Sf,fallback:()=>null,children:h.jsx(Rp.Provider,{value:n,children:h.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:l?h.jsx(l,{}):null})})}),h.jsx("div",{className:de("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Are you sure?"}),h.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>c(!1),children:"Cancel"}),h.jsx("button",{className:"tl-error-boundary__reset",onClick:y,children:"Reset data"})]})]}):h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Something's gone wrong."}),h.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",h.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",h.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&h.jsxs(h.Fragment,{children:["Message:",h.jsx("h4",{children:h.jsx("code",{children:d})}),"Stack trace:",h.jsxs("div",{className:"tl-error-boundary__content__error",children:[h.jsx("pre",{children:h.jsx("code",{children:u??d})}),h.jsx("button",{onClick:g,children:s?"Copied!":"Copy"})]})]}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),h.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[h.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>c(!0),children:"Reset data"}),h.jsx("button",{className:"tl-error-boundary__refresh",onClick:w,children:"Refresh Page"})]})]})]})})]})};function st(){return Md()}const Uk="TLDRAW_USER_DATA_v3",Hk=xe({id:pe,name:pe.nullable().optional(),locale:pe.nullable().optional(),color:pe.nullable().optional(),colorScheme:Op("light","dark","system").optional(),animationSpeed:he.nullable().optional(),edgeScrollSpeed:he.nullable().optional(),isSnapMode:be.nullable().optional(),isWrapMode:be.nullable().optional(),isDynamicSizeMode:be.nullable().optional()}),xs={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7},V0=Math.max(...Object.values(xs));function kU(e){e.version<xs.AddAnimationSpeed&&(e.user.animationSpeed=1),e.version<xs.AddIsSnapMode&&(e.user.isSnapMode=!1),e.version<xs.MakeFieldsNullable,e.version<xs.AddEdgeScrollSpeed&&(e.user.edgeScrollSpeed=1),e.version<xs.AddExcalidrawSelectMode&&(e.user.isWrapMode=!1),e.version<xs.AllowSystemColorScheme&&(e.user.isDarkMode===!0?e.user.colorScheme="dark":e.user.isDarkMode===!1&&(e.user.colorScheme="light"),delete e.user.isDarkMode),e.version<xs.AddDynamicSizeMode&&(e.user.isDynamicSizeMode=!1),e.version=V0}const X1=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function TU(){return X1[Math.floor(Math.random()*X1.length)]}function $U(){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 gs=Object.freeze({name:"New User",locale:t7(),color:TU(),edgeScrollSpeed:1,animationSpeed:$U()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1});function vm(){return{id:st()}}function Kk(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return vm();const n=ot(e);kU(n);try{return Hk.validate(n.user)}catch{return vm()}}function MU(){const e=JSON.parse(I0(Uk)||"null")??null;return Kk(e)}const Xl=Mt("globalUserData",null);function AU(){E0(Uk,JSON.stringify({version:V0,user:Xl.get()}))}function jU(e){Hk.validate(e),Xl.set(e),AU(),DU()}const OU=typeof process<"u"&&!1,Va=typeof BroadcastChannel<"u"&&!OU?new BroadcastChannel("tldraw-user-sync"):null;Va==null||Va.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===Gk&&(n==null?void 0:n.origin)!==Wk()&&Xl.set(Kk(n.data))});let xm=null;function Wk(){return xm===null&&(xm=st()),xm}const Gk="tldraw-user-preferences-change";function DU(){Va==null||Va.postMessage({type:Gk,origin:Wk(),data:{user:Vk(),version:V0}})}function Vk(){let e=Xl.get();return e||(e=MU(),Xl.set(e)),e}function Yk(e={}){return{derivePresenceState:e.derivePresenceState??(()=>V("presence",()=>null)),userPreferences:e.userPreferences??V("userPreferences",()=>Vk()),setUserPreferences:e.setUserPreferences??jU}}var Xk={exports:{}};(function(e){var n=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function o(c,l,d){this.fn=c,this.context=l,this.once=d||!1}function s(c,l,d,u,f){if(typeof d!="function")throw new TypeError("The listener must be a function");var p=new o(d,u||c,f),S=t?t+l:l;return c._events[S]?c._events[S].fn?c._events[S]=[c._events[S],p]:c._events[S].push(p):(c._events[S]=p,c._eventsCount++),c}function i(c,l){--c._eventsCount===0?c._events=new r:delete c._events[l]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var l=[],d,u;if(this._eventsCount===0)return l;for(u in d=this._events)n.call(d,u)&&l.push(t?u.slice(1):u);return Object.getOwnPropertySymbols?l.concat(Object.getOwnPropertySymbols(d)):l},a.prototype.listeners=function(l){var d=t?t+l:l,u=this._events[d];if(!u)return[];if(u.fn)return[u.fn];for(var f=0,p=u.length,S=new Array(p);f<p;f++)S[f]=u[f].fn;return S},a.prototype.listenerCount=function(l){var d=t?t+l:l,u=this._events[d];return u?u.fn?1:u.length:0},a.prototype.emit=function(l,d,u,f,p,S){var g=t?t+l:l;if(!this._events[g])return!1;var w=this._events[g],y=arguments.length,v,P;if(w.fn){switch(w.once&&this.removeListener(l,w.fn,void 0,!0),y){case 1:return w.fn.call(w.context),!0;case 2:return w.fn.call(w.context,d),!0;case 3:return w.fn.call(w.context,d,u),!0;case 4:return w.fn.call(w.context,d,u,f),!0;case 5:return w.fn.call(w.context,d,u,f,p),!0;case 6:return w.fn.call(w.context,d,u,f,p,S),!0}for(P=1,v=new Array(y-1);P<y;P++)v[P-1]=arguments[P];w.fn.apply(w.context,v)}else{var E=w.length,I;for(P=0;P<E;P++)switch(w[P].once&&this.removeListener(l,w[P].fn,void 0,!0),y){case 1:w[P].fn.call(w[P].context);break;case 2:w[P].fn.call(w[P].context,d);break;case 3:w[P].fn.call(w[P].context,d,u);break;case 4:w[P].fn.call(w[P].context,d,u,f);break;default:if(!v)for(I=1,v=new Array(y-1);I<y;I++)v[I-1]=arguments[I];w[P].fn.apply(w[P].context,v)}}return!0},a.prototype.on=function(l,d,u){return s(this,l,d,u,!1)},a.prototype.once=function(l,d,u){return s(this,l,d,u,!0)},a.prototype.removeListener=function(l,d,u,f){var p=t?t+l:l;if(!this._events[p])return this;if(!d)return i(this,p),this;var S=this._events[p];if(S.fn)S.fn===d&&(!f||S.once)&&(!u||S.context===u)&&i(this,p);else{for(var g=0,w=[],y=S.length;g<y;g++)(S[g].fn!==d||f&&!S[g].once||u&&S[g].context!==u)&&w.push(S[g]);w.length?this._events[p]=w.length===1?w[0]:w:i(this,p)}return this},a.prototype.removeAllListeners=function(l){var d;return l?(d=t?t+l:l,this._events[d]&&i(this,d)):(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})(Xk);var RU=Xk.exports;const LU=Qs(RU);var qk={exports:{}},ar={},Zk={exports:{}},Qk={};/**
|
|
63
|
-
* @license React
|
|
64
|
-
* scheduler.production.min.js
|
|
65
|
-
*
|
|
66
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
67
|
-
*
|
|
68
|
-
* This source code is licensed under the MIT license found in the
|
|
69
|
-
* LICENSE file in the root directory of this source tree.
|
|
70
|
-
*/(function(e){function n(B,U){var Y=B.length;B.push(U);e:for(;0<Y;){var Q=Y-1>>>1,le=B[Q];if(0<o(le,U))B[Q]=U,B[Y]=le,Y=Q;else break e}}function t(B){return B.length===0?null:B[0]}function r(B){if(B.length===0)return null;var U=B[0],Y=B.pop();if(Y!==U){B[0]=Y;e:for(var Q=0,le=B.length,ge=le>>>1;Q<ge;){var Me=2*(Q+1)-1,ce=B[Me],Ae=Me+1,Re=B[Ae];if(0>o(ce,Y))Ae<le&&0>o(Re,ce)?(B[Q]=Re,B[Ae]=Y,Q=Ae):(B[Q]=ce,B[Me]=Y,Q=Me);else if(Ae<le&&0>o(Re,Y))B[Q]=Re,B[Ae]=Y,Q=Ae;else break e}}return U}function o(B,U){var Y=B.sortIndex-U.sortIndex;return Y!==0?Y:B.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var c=[],l=[],d=1,u=null,f=3,p=!1,S=!1,g=!1,w=typeof setTimeout=="function"?setTimeout:null,y=typeof clearTimeout=="function"?clearTimeout:null,v=typeof setImmediate<"u"?setImmediate:null;typeof navigator<"u"&&navigator.scheduling!==void 0&&navigator.scheduling.isInputPending!==void 0&&navigator.scheduling.isInputPending.bind(navigator.scheduling);function P(B){for(var U=t(l);U!==null;){if(U.callback===null)r(l);else if(U.startTime<=B)r(l),U.sortIndex=U.expirationTime,n(c,U);else break;U=t(l)}}function E(B){if(g=!1,P(B),!S)if(t(c)!==null)S=!0,G(I);else{var U=t(l);U!==null&&K(E,U.startTime-B)}}function I(B,U){S=!1,g&&(g=!1,y(k),k=-1),p=!0;var Y=f;try{for(P(U),u=t(c);u!==null&&(!(u.expirationTime>U)||B&&!M());){var Q=u.callback;if(typeof Q=="function"){u.callback=null,f=u.priorityLevel;var le=Q(u.expirationTime<=U);U=e.unstable_now(),typeof le=="function"?u.callback=le:u===t(c)&&r(c),P(U)}else r(c);u=t(c)}if(u!==null)var ge=!0;else{var Me=t(l);Me!==null&&K(E,Me.startTime-U),ge=!1}return ge}finally{u=null,f=Y,p=!1}}var C=!1,_=null,k=-1,j=5,T=-1;function M(){return!(e.unstable_now()-T<j)}function R(){if(_!==null){var B=e.unstable_now();T=B;var U=!0;try{U=_(!0,B)}finally{U?A():(C=!1,_=null)}}else C=!1}var A;if(typeof v=="function")A=function(){v(R)};else if(typeof MessageChannel<"u"){var O=new MessageChannel,L=O.port2;O.port1.onmessage=R,A=function(){L.postMessage(null)}}else A=function(){w(R,0)};function G(B){_=B,C||(C=!0,A())}function K(B,U){k=w(function(){B(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(B){B.callback=null},e.unstable_continueExecution=function(){S||p||(S=!0,G(I))},e.unstable_forceFrameRate=function(B){0>B||125<B?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):j=0<B?Math.floor(1e3/B):5},e.unstable_getCurrentPriorityLevel=function(){return f},e.unstable_getFirstCallbackNode=function(){return t(c)},e.unstable_next=function(B){switch(f){case 1:case 2:case 3:var U=3;break;default:U=f}var Y=f;f=U;try{return B()}finally{f=Y}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(B,U){switch(B){case 1:case 2:case 3:case 4:case 5:break;default:B=3}var Y=f;f=B;try{return U()}finally{f=Y}},e.unstable_scheduleCallback=function(B,U,Y){var Q=e.unstable_now();switch(typeof Y=="object"&&Y!==null?(Y=Y.delay,Y=typeof Y=="number"&&0<Y?Q+Y:Q):Y=Q,B){case 1:var le=-1;break;case 2:le=250;break;case 5:le=1073741823;break;case 4:le=1e4;break;default:le=5e3}return le=Y+le,B={id:d++,callback:U,priorityLevel:B,startTime:Y,expirationTime:le,sortIndex:-1},Y>Q?(B.sortIndex=Y,n(l,B),t(c)===null&&B===t(l)&&(g?(y(k),k=-1):g=!0,K(E,Y-Q))):(B.sortIndex=le,n(c,B),S||p||(S=!0,G(I))),B},e.unstable_shouldYield=M,e.unstable_wrapCallback=function(B){var U=f;return function(){var Y=f;f=U;try{return B.apply(this,arguments)}finally{f=Y}}}})(Qk);Zk.exports=Qk;var FU=Zk.exports;/**
|
|
71
|
-
* @license React
|
|
72
|
-
* react-dom.production.min.js
|
|
73
|
-
*
|
|
74
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
75
|
-
*
|
|
76
|
-
* This source code is licensed under the MIT license found in the
|
|
77
|
-
* LICENSE file in the root directory of this source tree.
|
|
78
|
-
*/var zU=x,or=FU;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 Jk=new Set,ql={};function na(e,n){ac(e,n),ac(e+"Capture",n)}function ac(e,n){for(ql[e]=n,e=0;e<n.length;e++)Jk.add(n[e])}var qo=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),vS=Object.prototype.hasOwnProperty,NU=/^[: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]*$/,q1={},Z1={};function BU(e){return vS.call(Z1,e)?!0:vS.call(q1,e)?!1:NU.test(e)?Z1[e]=!0:(q1[e]=!0,!1)}function UU(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 HU(e,n,t,r){if(n===null||typeof n>"u"||UU(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 xn(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 Vt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Vt[e]=new xn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Vt[n]=new xn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Vt[e]=new xn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Vt[e]=new xn(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){Vt[e]=new xn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Vt[e]=new xn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Vt[e]=new xn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Vt[e]=new xn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Vt[e]=new xn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Y0=/[\-:]([a-z])/g;function X0(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(Y0,X0);Vt[n]=new xn(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(Y0,X0);Vt[n]=new xn(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(Y0,X0);Vt[n]=new xn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Vt[e]=new xn(e,1,!1,e.toLowerCase(),null,!1,!1)});Vt.xlinkHref=new xn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Vt[e]=new xn(e,1,!1,e.toLowerCase(),null,!0,!0)});function q0(e,n,t,r){var o=Vt.hasOwnProperty(n)?Vt[n]:null;(o!==null?o.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(HU(n,t,o,r)&&(t=null),r||o===null?BU(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 is=zU.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,xu=Symbol.for("react.element"),Ta=Symbol.for("react.portal"),$a=Symbol.for("react.fragment"),Z0=Symbol.for("react.strict_mode"),xS=Symbol.for("react.profiler"),eT=Symbol.for("react.provider"),tT=Symbol.for("react.context"),Q0=Symbol.for("react.forward_ref"),wS=Symbol.for("react.suspense"),bS=Symbol.for("react.suspense_list"),J0=Symbol.for("react.memo"),bs=Symbol.for("react.lazy"),nT=Symbol.for("react.offscreen"),Q1=Symbol.iterator;function Jc(e){return e===null||typeof e!="object"?null:(e=Q1&&e[Q1]||e["@@iterator"],typeof e=="function"?e:null)}var pt=Object.assign,wm;function vl(e){if(wm===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);wm=n&&n[1]||""}return`
|
|
79
|
-
`+wm+e}var bm=!1;function Pm(e,n){if(!e||bm)return"";bm=!0;var t=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(l){var r=l}Reflect.construct(e,[],n)}else{try{n.call()}catch(l){r=l}e.call(n.prototype)}else{try{throw Error()}catch(l){r=l}e()}}catch(l){if(l&&r&&typeof l.stack=="string"){for(var o=l.stack.split(`
|
|
80
|
-
`),s=r.stack.split(`
|
|
81
|
-
`),i=o.length-1,a=s.length-1;1<=i&&0<=a&&o[i]!==s[a];)a--;for(;1<=i&&0<=a;i--,a--)if(o[i]!==s[a]){if(i!==1||a!==1)do if(i--,a--,0>a||o[i]!==s[a]){var c=`
|
|
82
|
-
`+o[i].replace(" at new "," at ");return e.displayName&&c.includes("<anonymous>")&&(c=c.replace("<anonymous>",e.displayName)),c}while(1<=i&&0<=a);break}}}finally{bm=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?vl(e):""}function KU(e){switch(e.tag){case 5:return vl(e.type);case 16:return vl("Lazy");case 13:return vl("Suspense");case 19:return vl("SuspenseList");case 0:case 2:case 15:return e=Pm(e.type,!1),e;case 11:return e=Pm(e.type.render,!1),e;case 1:return e=Pm(e.type,!0),e;default:return""}}function PS(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 $a:return"Fragment";case Ta:return"Portal";case xS:return"Profiler";case Z0:return"StrictMode";case wS:return"Suspense";case bS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case tT:return(e.displayName||"Context")+".Consumer";case eT:return(e._context.displayName||"Context")+".Provider";case Q0:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case J0:return n=e.displayName||null,n!==null?n:PS(e.type)||"Memo";case bs:n=e._payload,e=e._init;try{return PS(e(n))}catch{}}return null}function WU(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 PS(n);case 8:return n===Z0?"StrictMode":"Mode";case 22:return"Offscreen";case 12:return"Profiler";case 21:return"Scope";case 13:return"Suspense";case 19:return"SuspenseList";case 25:return"TracingMarker";case 1:case 0:case 17:case 2:case 14:case 15:if(typeof n=="function")return n.displayName||n.name||null;if(typeof n=="string")return n}return null}function Gs(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function rT(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function GU(e){var n=rT(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 wu(e){e._valueTracker||(e._valueTracker=GU(e))}function oT(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=rT(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function Ff(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 CS(e,n){var t=n.checked;return pt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function J1(e,n){var t=n.defaultValue==null?"":n.defaultValue,r=n.checked!=null?n.checked:n.defaultChecked;t=Gs(n.value!=null?n.value:t),e._wrapperState={initialChecked:r,initialValue:t,controlled:n.type==="checkbox"||n.type==="radio"?n.checked!=null:n.value!=null}}function sT(e,n){n=n.checked,n!=null&&q0(e,"checked",n,!1)}function IS(e,n){sT(e,n);var t=Gs(n.value),r=n.type;if(t!=null)r==="number"?(t===0&&e.value===""||e.value!=t)&&(e.value=""+t):e.value!==""+t&&(e.value=""+t);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}n.hasOwnProperty("value")?ES(e,n.type,t):n.hasOwnProperty("defaultValue")&&ES(e,n.type,Gs(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function eP(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 ES(e,n,t){(n!=="number"||Ff(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var xl=Array.isArray;function Ya(e,n,t,r){if(e=e.options,n){n={};for(var o=0;o<t.length;o++)n["$"+t[o]]=!0;for(t=0;t<e.length;t++)o=n.hasOwnProperty("$"+e[t].value),e[t].selected!==o&&(e[t].selected=o),o&&r&&(e[t].defaultSelected=!0)}else{for(t=""+Gs(t),n=null,o=0;o<e.length;o++){if(e[o].value===t){e[o].selected=!0,r&&(e[o].defaultSelected=!0);return}n!==null||e[o].disabled||(n=e[o])}n!==null&&(n.selected=!0)}}function _S(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return pt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function tP(e,n){var t=n.value;if(t==null){if(t=n.children,n=n.defaultValue,t!=null){if(n!=null)throw Error(q(92));if(xl(t)){if(1<t.length)throw Error(q(93));t=t[0]}n=t}n==null&&(n=""),t=n}e._wrapperState={initialValue:Gs(t)}}function iT(e,n){var t=Gs(n.value),r=Gs(n.defaultValue);t!=null&&(t=""+t,t!==e.value&&(e.value=t),n.defaultValue==null&&e.defaultValue!==t&&(e.defaultValue=t)),r!=null&&(e.defaultValue=""+r)}function nP(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function aT(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 kS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?aT(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var bu,cT=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(bu=bu||document.createElement("div"),bu.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=bu.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Zl(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var $l={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},VU=["Webkit","ms","Moz","O"];Object.keys($l).forEach(function(e){VU.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),$l[n]=$l[e]})});function lT(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||$l.hasOwnProperty(e)&&$l[e]?(""+n).trim():n+"px"}function dT(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=lT(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var YU=pt({menuitem:!0},{area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,keygen:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0});function TS(e,n){if(n){if(YU[e]&&(n.children!=null||n.dangerouslySetInnerHTML!=null))throw Error(q(137,e));if(n.dangerouslySetInnerHTML!=null){if(n.children!=null)throw Error(q(60));if(typeof n.dangerouslySetInnerHTML!="object"||!("__html"in n.dangerouslySetInnerHTML))throw Error(q(61))}if(n.style!=null&&typeof n.style!="object")throw Error(q(62))}}function $S(e,n){if(e.indexOf("-")===-1)return typeof n.is=="string";switch(e){case"annotation-xml":case"color-profile":case"font-face":case"font-face-src":case"font-face-uri":case"font-face-format":case"font-face-name":case"missing-glyph":return!1;default:return!0}}var MS=null;function ex(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var AS=null,Xa=null,qa=null;function rP(e){if(e=Nd(e)){if(typeof AS!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Bp(n),AS(e.stateNode,e.type,n))}}function uT(e){Xa?qa?qa.push(e):qa=[e]:Xa=e}function hT(){if(Xa){var e=Xa,n=qa;if(qa=Xa=null,rP(e),n)for(e=0;e<n.length;e++)rP(n[e])}}function fT(e,n){return e(n)}function pT(){}var Cm=!1;function gT(e,n,t){if(Cm)return e(n,t);Cm=!0;try{return fT(e,n,t)}finally{Cm=!1,(Xa!==null||qa!==null)&&(pT(),hT())}}function Ql(e,n){var t=e.stateNode;if(t===null)return null;var r=Bp(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 jS=!1;if(qo)try{var el={};Object.defineProperty(el,"passive",{get:function(){jS=!0}}),window.addEventListener("test",el,el),window.removeEventListener("test",el,el)}catch{jS=!1}function XU(e,n,t,r,o,s,i,a,c){var l=Array.prototype.slice.call(arguments,3);try{n.apply(t,l)}catch(d){this.onError(d)}}var Ml=!1,zf=null,Nf=!1,OS=null,qU={onError:function(e){Ml=!0,zf=e}};function ZU(e,n,t,r,o,s,i,a,c){Ml=!1,zf=null,XU.apply(qU,arguments)}function QU(e,n,t,r,o,s,i,a,c){if(ZU.apply(this,arguments),Ml){if(Ml){var l=zf;Ml=!1,zf=null}else throw Error(q(198));Nf||(Nf=!0,OS=l)}}function ra(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 mT(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 oP(e){if(ra(e)!==e)throw Error(q(188))}function JU(e){var n=e.alternate;if(!n){if(n=ra(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 oP(o),e;if(s===r)return oP(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 yT(e){return e=JU(e),e!==null?ST(e):null}function ST(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=ST(e);if(n!==null)return n;e=e.sibling}return null}var vT=or.unstable_scheduleCallback,sP=or.unstable_cancelCallback,e9=or.unstable_shouldYield,t9=or.unstable_requestPaint,bt=or.unstable_now,n9=or.unstable_getCurrentPriorityLevel,tx=or.unstable_ImmediatePriority,xT=or.unstable_UserBlockingPriority,Bf=or.unstable_NormalPriority,r9=or.unstable_LowPriority,wT=or.unstable_IdlePriority,Lp=null,uo=null;function o9(e){if(uo&&typeof uo.onCommitFiberRoot=="function")try{uo.onCommitFiberRoot(Lp,e,void 0,(e.current.flags&128)===128)}catch{}}var Fr=Math.clz32?Math.clz32:a9,s9=Math.log,i9=Math.LN2;function a9(e){return e>>>=0,e===0?32:31-(s9(e)/i9|0)|0}var Pu=64,Cu=4194304;function wl(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 Uf(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=wl(a):(s&=i,s!==0&&(r=wl(s)))}else i=t&~o,i!==0?r=wl(i):s!==0&&(r=wl(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-Fr(n),o=1<<t,r|=e[t],n&=~o;return r}function c9(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 l9(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-Fr(s),a=1<<i,c=o[i];c===-1?(!(a&t)||a&r)&&(o[i]=c9(a,n)):c<=n&&(e.expiredLanes|=a),s&=~a}}function DS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function bT(){var e=Pu;return Pu<<=1,!(Pu&4194240)&&(Pu=64),e}function Im(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function Fd(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-Fr(n),e[n]=t}function d9(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-Fr(t),s=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~s}}function nx(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-Fr(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var ze=0;function PT(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var CT,rx,IT,ET,_T,RS=!1,Iu=[],Rs=null,Ls=null,Fs=null,Jl=new Map,ed=new Map,Is=[],u9="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 iP(e,n){switch(e){case"focusin":case"focusout":Rs=null;break;case"dragenter":case"dragleave":Ls=null;break;case"mouseover":case"mouseout":Fs=null;break;case"pointerover":case"pointerout":Jl.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":ed.delete(n.pointerId)}}function tl(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=Nd(n),n!==null&&rx(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function h9(e,n,t,r,o){switch(n){case"focusin":return Rs=tl(Rs,e,n,t,r,o),!0;case"dragenter":return Ls=tl(Ls,e,n,t,r,o),!0;case"mouseover":return Fs=tl(Fs,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return Jl.set(s,tl(Jl.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,ed.set(s,tl(ed.get(s)||null,e,n,t,r,o)),!0}return!1}function kT(e){var n=bi(e.target);if(n!==null){var t=ra(n);if(t!==null){if(n=t.tag,n===13){if(n=mT(t),n!==null){e.blockedOn=n,_T(e.priority,function(){IT(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 Sh(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=LS(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);MS=r,t.target.dispatchEvent(r),MS=null}else return n=Nd(t),n!==null&&rx(n),e.blockedOn=t,!1;n.shift()}return!0}function aP(e,n,t){Sh(e)&&t.delete(n)}function f9(){RS=!1,Rs!==null&&Sh(Rs)&&(Rs=null),Ls!==null&&Sh(Ls)&&(Ls=null),Fs!==null&&Sh(Fs)&&(Fs=null),Jl.forEach(aP),ed.forEach(aP)}function nl(e,n){e.blockedOn===n&&(e.blockedOn=null,RS||(RS=!0,or.unstable_scheduleCallback(or.unstable_NormalPriority,f9)))}function td(e){function n(o){return nl(o,e)}if(0<Iu.length){nl(Iu[0],e);for(var t=1;t<Iu.length;t++){var r=Iu[t];r.blockedOn===e&&(r.blockedOn=null)}}for(Rs!==null&&nl(Rs,e),Ls!==null&&nl(Ls,e),Fs!==null&&nl(Fs,e),Jl.forEach(n),ed.forEach(n),t=0;t<Is.length;t++)r=Is[t],r.blockedOn===e&&(r.blockedOn=null);for(;0<Is.length&&(t=Is[0],t.blockedOn===null);)kT(t),t.blockedOn===null&&Is.shift()}var Za=is.ReactCurrentBatchConfig,Hf=!0;function p9(e,n,t,r){var o=ze,s=Za.transition;Za.transition=null;try{ze=1,ox(e,n,t,r)}finally{ze=o,Za.transition=s}}function g9(e,n,t,r){var o=ze,s=Za.transition;Za.transition=null;try{ze=4,ox(e,n,t,r)}finally{ze=o,Za.transition=s}}function ox(e,n,t,r){if(Hf){var o=LS(e,n,t,r);if(o===null)Dm(e,n,r,Kf,t),iP(e,r);else if(h9(o,e,n,t,r))r.stopPropagation();else if(iP(e,r),n&4&&-1<u9.indexOf(e)){for(;o!==null;){var s=Nd(o);if(s!==null&&CT(s),s=LS(e,n,t,r),s===null&&Dm(e,n,r,Kf,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else Dm(e,n,r,null,t)}}var Kf=null;function LS(e,n,t,r){if(Kf=null,e=ex(r),e=bi(e),e!==null)if(n=ra(e),n===null)e=null;else if(t=n.tag,t===13){if(e=mT(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 Kf=e,null}function TT(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(n9()){case tx:return 1;case xT:return 4;case Bf:case r9:return 16;case wT:return 536870912;default:return 16}default:return 16}}var ks=null,sx=null,vh=null;function $T(){if(vh)return vh;var e,n=sx,t=n.length,r,o="value"in ks?ks.value:ks.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 vh=o.slice(e,1<r?1-r:void 0)}function xh(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 Eu(){return!0}function cP(){return!1}function cr(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)?Eu:cP,this.isPropagationStopped=cP,this}return pt(n.prototype,{preventDefault:function(){this.defaultPrevented=!0;var t=this.nativeEvent;t&&(t.preventDefault?t.preventDefault():typeof t.returnValue!="unknown"&&(t.returnValue=!1),this.isDefaultPrevented=Eu)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=Eu)},persist:function(){},isPersistent:Eu}),n}var Mc={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},ix=cr(Mc),zd=pt({},Mc,{view:0,detail:0}),m9=cr(zd),Em,_m,rl,Fp=pt({},zd,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:ax,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!==rl&&(rl&&e.type==="mousemove"?(Em=e.screenX-rl.screenX,_m=e.screenY-rl.screenY):_m=Em=0,rl=e),Em)},movementY:function(e){return"movementY"in e?e.movementY:_m}}),lP=cr(Fp),y9=pt({},Fp,{dataTransfer:0}),S9=cr(y9),v9=pt({},zd,{relatedTarget:0}),km=cr(v9),x9=pt({},Mc,{animationName:0,elapsedTime:0,pseudoElement:0}),w9=cr(x9),b9=pt({},Mc,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),P9=cr(b9),C9=pt({},Mc,{data:0}),dP=cr(C9),I9={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},E9={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"},_9={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function k9(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=_9[e])?!!n[e]:!1}function ax(){return k9}var T9=pt({},zd,{key:function(e){if(e.key){var n=I9[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=xh(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?E9[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:ax,charCode:function(e){return e.type==="keypress"?xh(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?xh(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),$9=cr(T9),M9=pt({},Fp,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),uP=cr(M9),A9=pt({},zd,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:ax}),j9=cr(A9),O9=pt({},Mc,{propertyName:0,elapsedTime:0,pseudoElement:0}),D9=cr(O9),R9=pt({},Fp,{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}),L9=cr(R9),F9=[9,13,27,32],cx=qo&&"CompositionEvent"in window,Al=null;qo&&"documentMode"in document&&(Al=document.documentMode);var z9=qo&&"TextEvent"in window&&!Al,MT=qo&&(!cx||Al&&8<Al&&11>=Al),hP=" ",fP=!1;function AT(e,n){switch(e){case"keyup":return F9.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function jT(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Ma=!1;function N9(e,n){switch(e){case"compositionend":return jT(n);case"keypress":return n.which!==32?null:(fP=!0,hP);case"textInput":return e=n.data,e===hP&&fP?null:e;default:return null}}function B9(e,n){if(Ma)return e==="compositionend"||!cx&&AT(e,n)?(e=$T(),vh=sx=ks=null,Ma=!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 MT&&n.locale!=="ko"?null:n.data;default:return null}}var U9={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 pP(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!U9[e.type]:n==="textarea"}function OT(e,n,t,r){uT(r),n=Wf(n,"onChange"),0<n.length&&(t=new ix("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var jl=null,nd=null;function H9(e){WT(e,0)}function zp(e){var n=Oa(e);if(oT(n))return e}function K9(e,n){if(e==="change")return n}var DT=!1;if(qo){var Tm;if(qo){var $m="oninput"in document;if(!$m){var gP=document.createElement("div");gP.setAttribute("oninput","return;"),$m=typeof gP.oninput=="function"}Tm=$m}else Tm=!1;DT=Tm&&(!document.documentMode||9<document.documentMode)}function mP(){jl&&(jl.detachEvent("onpropertychange",RT),nd=jl=null)}function RT(e){if(e.propertyName==="value"&&zp(nd)){var n=[];OT(n,nd,e,ex(e)),gT(H9,n)}}function W9(e,n,t){e==="focusin"?(mP(),jl=n,nd=t,jl.attachEvent("onpropertychange",RT)):e==="focusout"&&mP()}function G9(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return zp(nd)}function V9(e,n){if(e==="click")return zp(n)}function Y9(e,n){if(e==="input"||e==="change")return zp(n)}function X9(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Hr=typeof Object.is=="function"?Object.is:X9;function rd(e,n){if(Hr(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(!vS.call(n,o)||!Hr(e[o],n[o]))return!1}return!0}function yP(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function SP(e,n){var t=yP(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=yP(t)}}function LT(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?LT(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function FT(){for(var e=window,n=Ff();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=Ff(e.document)}return n}function lx(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 q9(e){var n=FT(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&<(t.ownerDocument.documentElement,t)){if(r!==null&&lx(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=SP(t,s);var i=SP(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 Z9=qo&&"documentMode"in document&&11>=document.documentMode,Aa=null,FS=null,Ol=null,zS=!1;function vP(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;zS||Aa==null||Aa!==Ff(r)||(r=Aa,"selectionStart"in r&&lx(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}),Ol&&rd(Ol,r)||(Ol=r,r=Wf(FS,"onSelect"),0<r.length&&(n=new ix("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=Aa)))}function _u(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var ja={animationend:_u("Animation","AnimationEnd"),animationiteration:_u("Animation","AnimationIteration"),animationstart:_u("Animation","AnimationStart"),transitionend:_u("Transition","TransitionEnd")},Mm={},zT={};qo&&(zT=document.createElement("div").style,"AnimationEvent"in window||(delete ja.animationend.animation,delete ja.animationiteration.animation,delete ja.animationstart.animation),"TransitionEvent"in window||delete ja.transitionend.transition);function Np(e){if(Mm[e])return Mm[e];if(!ja[e])return e;var n=ja[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in zT)return Mm[e]=n[t];return e}var NT=Np("animationend"),BT=Np("animationiteration"),UT=Np("animationstart"),HT=Np("transitionend"),KT=new Map,xP="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 ri(e,n){KT.set(e,n),na(n,[e])}for(var Am=0;Am<xP.length;Am++){var jm=xP[Am],Q9=jm.toLowerCase(),J9=jm[0].toUpperCase()+jm.slice(1);ri(Q9,"on"+J9)}ri(NT,"onAnimationEnd");ri(BT,"onAnimationIteration");ri(UT,"onAnimationStart");ri("dblclick","onDoubleClick");ri("focusin","onFocus");ri("focusout","onBlur");ri(HT,"onTransitionEnd");ac("onMouseEnter",["mouseout","mouseover"]);ac("onMouseLeave",["mouseout","mouseover"]);ac("onPointerEnter",["pointerout","pointerover"]);ac("onPointerLeave",["pointerout","pointerover"]);na("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));na("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));na("onBeforeInput",["compositionend","keypress","textInput","paste"]);na("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));na("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));na("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var bl="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(" "),eH=new Set("cancel close invalid load scroll toggle".split(" ").concat(bl));function wP(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,QU(r,n,void 0,e),e.currentTarget=null}function WT(e,n){n=(n&4)!==0;for(var t=0;t<e.length;t++){var r=e[t],o=r.event;r=r.listeners;e:{var s=void 0;if(n)for(var i=r.length-1;0<=i;i--){var a=r[i],c=a.instance,l=a.currentTarget;if(a=a.listener,c!==s&&o.isPropagationStopped())break e;wP(o,a,l),s=c}else for(i=0;i<r.length;i++){if(a=r[i],c=a.instance,l=a.currentTarget,a=a.listener,c!==s&&o.isPropagationStopped())break e;wP(o,a,l),s=c}}}if(Nf)throw e=OS,Nf=!1,OS=null,e}function Je(e,n){var t=n[KS];t===void 0&&(t=n[KS]=new Set);var r=e+"__bubble";t.has(r)||(GT(n,e,2,!1),t.add(r))}function Om(e,n,t){var r=0;n&&(r|=4),GT(t,e,r,n)}var ku="_reactListening"+Math.random().toString(36).slice(2);function od(e){if(!e[ku]){e[ku]=!0,Jk.forEach(function(t){t!=="selectionchange"&&(eH.has(t)||Om(t,!1,e),Om(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[ku]||(n[ku]=!0,Om("selectionchange",!1,n))}}function GT(e,n,t,r){switch(TT(n)){case 1:var o=p9;break;case 4:o=g9;break;default:o=ox}t=o.bind(null,n,t,e),o=void 0,!jS||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 Dm(e,n,t,r,o){var s=r;if(!(n&1)&&!(n&2)&&r!==null)e:for(;;){if(r===null)return;var i=r.tag;if(i===3||i===4){var a=r.stateNode.containerInfo;if(a===o||a.nodeType===8&&a.parentNode===o)break;if(i===4)for(i=r.return;i!==null;){var c=i.tag;if((c===3||c===4)&&(c=i.stateNode.containerInfo,c===o||c.nodeType===8&&c.parentNode===o))return;i=i.return}for(;a!==null;){if(i=bi(a),i===null)return;if(c=i.tag,c===5||c===6){r=s=i;continue e}a=a.parentNode}}r=r.return}gT(function(){var l=s,d=ex(t),u=[];e:{var f=KT.get(e);if(f!==void 0){var p=ix,S=e;switch(e){case"keypress":if(xh(t)===0)break e;case"keydown":case"keyup":p=$9;break;case"focusin":S="focus",p=km;break;case"focusout":S="blur",p=km;break;case"beforeblur":case"afterblur":p=km;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=lP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":p=S9;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":p=j9;break;case NT:case BT:case UT:p=w9;break;case HT:p=D9;break;case"scroll":p=m9;break;case"wheel":p=L9;break;case"copy":case"cut":case"paste":p=P9;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":p=uP}var g=(n&4)!==0,w=!g&&e==="scroll",y=g?f!==null?f+"Capture":null:f;g=[];for(var v=l,P;v!==null;){P=v;var E=P.stateNode;if(P.tag===5&&E!==null&&(P=E,y!==null&&(E=Ql(v,y),E!=null&&g.push(sd(v,E,P)))),w)break;v=v.return}0<g.length&&(f=new p(f,S,null,t,d),u.push({event:f,listeners:g}))}}if(!(n&7)){e:{if(f=e==="mouseover"||e==="pointerover",p=e==="mouseout"||e==="pointerout",f&&t!==MS&&(S=t.relatedTarget||t.fromElement)&&(bi(S)||S[Zo]))break e;if((p||f)&&(f=d.window===d?d:(f=d.ownerDocument)?f.defaultView||f.parentWindow:window,p?(S=t.relatedTarget||t.toElement,p=l,S=S?bi(S):null,S!==null&&(w=ra(S),S!==w||S.tag!==5&&S.tag!==6)&&(S=null)):(p=null,S=l),p!==S)){if(g=lP,E="onMouseLeave",y="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(g=uP,E="onPointerLeave",y="onPointerEnter",v="pointer"),w=p==null?f:Oa(p),P=S==null?f:Oa(S),f=new g(E,v+"leave",p,t,d),f.target=w,f.relatedTarget=P,E=null,bi(d)===l&&(g=new g(y,v+"enter",S,t,d),g.target=P,g.relatedTarget=w,E=g),w=E,p&&S)t:{for(g=p,y=S,v=0,P=g;P;P=ga(P))v++;for(P=0,E=y;E;E=ga(E))P++;for(;0<v-P;)g=ga(g),v--;for(;0<P-v;)y=ga(y),P--;for(;v--;){if(g===y||y!==null&&g===y.alternate)break t;g=ga(g),y=ga(y)}g=null}else g=null;p!==null&&bP(u,f,p,g,!1),S!==null&&w!==null&&bP(u,w,S,g,!0)}}e:{if(f=l?Oa(l):window,p=f.nodeName&&f.nodeName.toLowerCase(),p==="select"||p==="input"&&f.type==="file")var I=K9;else if(pP(f))if(DT)I=Y9;else{I=G9;var C=W9}else(p=f.nodeName)&&p.toLowerCase()==="input"&&(f.type==="checkbox"||f.type==="radio")&&(I=V9);if(I&&(I=I(e,l))){OT(u,I,t,d);break e}C&&C(e,f,l),e==="focusout"&&(C=f._wrapperState)&&C.controlled&&f.type==="number"&&ES(f,"number",f.value)}switch(C=l?Oa(l):window,e){case"focusin":(pP(C)||C.contentEditable==="true")&&(Aa=C,FS=l,Ol=null);break;case"focusout":Ol=FS=Aa=null;break;case"mousedown":zS=!0;break;case"contextmenu":case"mouseup":case"dragend":zS=!1,vP(u,t,d);break;case"selectionchange":if(Z9)break;case"keydown":case"keyup":vP(u,t,d)}var _;if(cx)e:{switch(e){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else Ma?AT(e,t)&&(k="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(k="onCompositionStart");k&&(MT&&t.locale!=="ko"&&(Ma||k!=="onCompositionStart"?k==="onCompositionEnd"&&Ma&&(_=$T()):(ks=d,sx="value"in ks?ks.value:ks.textContent,Ma=!0)),C=Wf(l,k),0<C.length&&(k=new dP(k,e,null,t,d),u.push({event:k,listeners:C}),_?k.data=_:(_=jT(t),_!==null&&(k.data=_)))),(_=z9?N9(e,t):B9(e,t))&&(l=Wf(l,"onBeforeInput"),0<l.length&&(d=new dP("onBeforeInput","beforeinput",null,t,d),u.push({event:d,listeners:l}),d.data=_))}WT(u,n)})}function sd(e,n,t){return{instance:e,listener:n,currentTarget:t}}function Wf(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=Ql(e,t),s!=null&&r.unshift(sd(e,s,o)),s=Ql(e,n),s!=null&&r.push(sd(e,s,o))),e=e.return}return r}function ga(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function bP(e,n,t,r,o){for(var s=n._reactName,i=[];t!==null&&t!==r;){var a=t,c=a.alternate,l=a.stateNode;if(c!==null&&c===r)break;a.tag===5&&l!==null&&(a=l,o?(c=Ql(t,s),c!=null&&i.unshift(sd(t,c,a))):o||(c=Ql(t,s),c!=null&&i.push(sd(t,c,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var tH=/\r\n?/g,nH=/\u0000|\uFFFD/g;function PP(e){return(typeof e=="string"?e:""+e).replace(tH,`
|
|
83
|
-
`).replace(nH,"")}function Tu(e,n,t){if(n=PP(n),PP(e)!==n&&t)throw Error(q(425))}function Gf(){}var NS=null,BS=null;function US(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 HS=typeof setTimeout=="function"?setTimeout:void 0,rH=typeof clearTimeout=="function"?clearTimeout:void 0,CP=typeof Promise=="function"?Promise:void 0,oH=typeof queueMicrotask=="function"?queueMicrotask:typeof CP<"u"?function(e){return CP.resolve(null).then(e).catch(sH)}:HS;function sH(e){setTimeout(function(){throw e})}function Rm(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),td(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);td(n)}function zs(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 IP(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 Ac=Math.random().toString(36).slice(2),ro="__reactFiber$"+Ac,id="__reactProps$"+Ac,Zo="__reactContainer$"+Ac,KS="__reactEvents$"+Ac,iH="__reactListeners$"+Ac,aH="__reactHandles$"+Ac;function bi(e){var n=e[ro];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Zo]||t[ro]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=IP(e);e!==null;){if(t=e[ro])return t;e=IP(e)}return n}e=t,t=e.parentNode}return null}function Nd(e){return e=e[ro]||e[Zo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Oa(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Bp(e){return e[id]||null}var WS=[],Da=-1;function oi(e){return{current:e}}function tt(e){0>Da||(e.current=WS[Da],WS[Da]=null,Da--)}function Ye(e,n){Da++,WS[Da]=e.current,e.current=n}var Vs={},cn=oi(Vs),Dn=oi(!1),zi=Vs;function cc(e,n){var t=e.type.contextTypes;if(!t)return Vs;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===n)return r.__reactInternalMemoizedMaskedChildContext;var o={},s;for(s in t)o[s]=n[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=n,e.__reactInternalMemoizedMaskedChildContext=o),o}function Rn(e){return e=e.childContextTypes,e!=null}function Vf(){tt(Dn),tt(cn)}function EP(e,n,t){if(cn.current!==Vs)throw Error(q(168));Ye(cn,n),Ye(Dn,t)}function VT(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,WU(e)||"Unknown",o));return pt({},t,r)}function Yf(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Vs,zi=cn.current,Ye(cn,e),Ye(Dn,Dn.current),!0}function _P(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=VT(e,n,zi),r.__reactInternalMemoizedMergedChildContext=e,tt(Dn),tt(cn),Ye(cn,e)):tt(Dn),Ye(Dn,t)}var Ro=null,Up=!1,Lm=!1;function YT(e){Ro===null?Ro=[e]:Ro.push(e)}function cH(e){Up=!0,YT(e)}function si(){if(!Lm&&Ro!==null){Lm=!0;var e=0,n=ze;try{var t=Ro;for(ze=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}Ro=null,Up=!1}catch(o){throw Ro!==null&&(Ro=Ro.slice(e+1)),vT(tx,si),o}finally{ze=n,Lm=!1}}return null}var Ra=[],La=0,Xf=null,qf=0,Sr=[],vr=0,Ni=null,zo=1,No="";function Si(e,n){Ra[La++]=qf,Ra[La++]=Xf,Xf=e,qf=n}function XT(e,n,t){Sr[vr++]=zo,Sr[vr++]=No,Sr[vr++]=Ni,Ni=e;var r=zo;e=No;var o=32-Fr(r)-1;r&=~(1<<o),t+=1;var s=32-Fr(n)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,zo=1<<32-Fr(n)+o|t<<o|r,No=s+e}else zo=1<<s|t<<o|r,No=e}function dx(e){e.return!==null&&(Si(e,1),XT(e,1,0))}function ux(e){for(;e===Xf;)Xf=Ra[--La],Ra[La]=null,qf=Ra[--La],Ra[La]=null;for(;e===Ni;)Ni=Sr[--vr],Sr[vr]=null,No=Sr[--vr],Sr[vr]=null,zo=Sr[--vr],Sr[vr]=null}var er=null,qn=null,rt=!1,Dr=null;function qT(e,n){var t=xr(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 kP(e,n){switch(e.tag){case 5:var t=e.type;return n=n.nodeType!==1||t.toLowerCase()!==n.nodeName.toLowerCase()?null:n,n!==null?(e.stateNode=n,er=e,qn=zs(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,er=e,qn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=Ni!==null?{id:zo,overflow:No}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=xr(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,er=e,qn=null,!0):!1;default:return!1}}function GS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function VS(e){if(rt){var n=qn;if(n){var t=n;if(!kP(e,n)){if(GS(e))throw Error(q(418));n=zs(t.nextSibling);var r=er;n&&kP(e,n)?qT(r,t):(e.flags=e.flags&-4097|2,rt=!1,er=e)}}else{if(GS(e))throw Error(q(418));e.flags=e.flags&-4097|2,rt=!1,er=e}}}function TP(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;er=e}function $u(e){if(e!==er)return!1;if(!rt)return TP(e),rt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!US(e.type,e.memoizedProps)),n&&(n=qn)){if(GS(e))throw ZT(),Error(q(418));for(;n;)qT(e,n),n=zs(n.nextSibling)}if(TP(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(q(317));e:{for(e=e.nextSibling,n=0;e;){if(e.nodeType===8){var t=e.data;if(t==="/$"){if(n===0){qn=zs(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}qn=null}}else qn=er?zs(e.stateNode.nextSibling):null;return!0}function ZT(){for(var e=qn;e;)e=zs(e.nextSibling)}function lc(){qn=er=null,rt=!1}function hx(e){Dr===null?Dr=[e]:Dr.push(e)}var lH=is.ReactCurrentBatchConfig;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;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 Mu(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function $P(e){var n=e._init;return n(e._payload)}function QT(e){function n(y,v){if(e){var P=y.deletions;P===null?(y.deletions=[v],y.flags|=16):P.push(v)}}function t(y,v){if(!e)return null;for(;v!==null;)n(y,v),v=v.sibling;return null}function r(y,v){for(y=new Map;v!==null;)v.key!==null?y.set(v.key,v):y.set(v.index,v),v=v.sibling;return y}function o(y,v){return y=Hs(y,v),y.index=0,y.sibling=null,y}function s(y,v,P){return y.index=P,e?(P=y.alternate,P!==null?(P=P.index,P<v?(y.flags|=2,v):P):(y.flags|=2,v)):(y.flags|=1048576,v)}function i(y){return e&&y.alternate===null&&(y.flags|=2),y}function a(y,v,P,E){return v===null||v.tag!==6?(v=Km(P,y.mode,E),v.return=y,v):(v=o(v,P),v.return=y,v)}function c(y,v,P,E){var I=P.type;return I===$a?d(y,v,P.props.children,E,P.key):v!==null&&(v.elementType===I||typeof I=="object"&&I!==null&&I.$$typeof===bs&&$P(I)===v.type)?(E=o(v,P.props),E.ref=ol(y,v,P),E.return=y,E):(E=_h(P.type,P.key,P.props,null,y.mode,E),E.ref=ol(y,v,P),E.return=y,E)}function l(y,v,P,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==P.containerInfo||v.stateNode.implementation!==P.implementation?(v=Wm(P,y.mode,E),v.return=y,v):(v=o(v,P.children||[]),v.return=y,v)}function d(y,v,P,E,I){return v===null||v.tag!==7?(v=Ai(P,y.mode,E,I),v.return=y,v):(v=o(v,P),v.return=y,v)}function u(y,v,P){if(typeof v=="string"&&v!==""||typeof v=="number")return v=Km(""+v,y.mode,P),v.return=y,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case xu:return P=_h(v.type,v.key,v.props,null,y.mode,P),P.ref=ol(y,null,v),P.return=y,P;case Ta:return v=Wm(v,y.mode,P),v.return=y,v;case bs:var E=v._init;return u(y,E(v._payload),P)}if(xl(v)||Jc(v))return v=Ai(v,y.mode,P,null),v.return=y,v;Mu(y,v)}return null}function f(y,v,P,E){var I=v!==null?v.key:null;if(typeof P=="string"&&P!==""||typeof P=="number")return I!==null?null:a(y,v,""+P,E);if(typeof P=="object"&&P!==null){switch(P.$$typeof){case xu:return P.key===I?c(y,v,P,E):null;case Ta:return P.key===I?l(y,v,P,E):null;case bs:return I=P._init,f(y,v,I(P._payload),E)}if(xl(P)||Jc(P))return I!==null?null:d(y,v,P,E,null);Mu(y,P)}return null}function p(y,v,P,E,I){if(typeof E=="string"&&E!==""||typeof E=="number")return y=y.get(P)||null,a(v,y,""+E,I);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case xu:return y=y.get(E.key===null?P:E.key)||null,c(v,y,E,I);case Ta:return y=y.get(E.key===null?P:E.key)||null,l(v,y,E,I);case bs:var C=E._init;return p(y,v,P,C(E._payload),I)}if(xl(E)||Jc(E))return y=y.get(P)||null,d(v,y,E,I,null);Mu(v,E)}return null}function S(y,v,P,E){for(var I=null,C=null,_=v,k=v=0,j=null;_!==null&&k<P.length;k++){_.index>k?(j=_,_=null):j=_.sibling;var T=f(y,_,P[k],E);if(T===null){_===null&&(_=j);break}e&&_&&T.alternate===null&&n(y,_),v=s(T,v,k),C===null?I=T:C.sibling=T,C=T,_=j}if(k===P.length)return t(y,_),rt&&Si(y,k),I;if(_===null){for(;k<P.length;k++)_=u(y,P[k],E),_!==null&&(v=s(_,v,k),C===null?I=_:C.sibling=_,C=_);return rt&&Si(y,k),I}for(_=r(y,_);k<P.length;k++)j=p(_,y,k,P[k],E),j!==null&&(e&&j.alternate!==null&&_.delete(j.key===null?k:j.key),v=s(j,v,k),C===null?I=j:C.sibling=j,C=j);return e&&_.forEach(function(M){return n(y,M)}),rt&&Si(y,k),I}function g(y,v,P,E){var I=Jc(P);if(typeof I!="function")throw Error(q(150));if(P=I.call(P),P==null)throw Error(q(151));for(var C=I=null,_=v,k=v=0,j=null,T=P.next();_!==null&&!T.done;k++,T=P.next()){_.index>k?(j=_,_=null):j=_.sibling;var M=f(y,_,T.value,E);if(M===null){_===null&&(_=j);break}e&&_&&M.alternate===null&&n(y,_),v=s(M,v,k),C===null?I=M:C.sibling=M,C=M,_=j}if(T.done)return t(y,_),rt&&Si(y,k),I;if(_===null){for(;!T.done;k++,T=P.next())T=u(y,T.value,E),T!==null&&(v=s(T,v,k),C===null?I=T:C.sibling=T,C=T);return rt&&Si(y,k),I}for(_=r(y,_);!T.done;k++,T=P.next())T=p(_,y,k,T.value,E),T!==null&&(e&&T.alternate!==null&&_.delete(T.key===null?k:T.key),v=s(T,v,k),C===null?I=T:C.sibling=T,C=T);return e&&_.forEach(function(R){return n(y,R)}),rt&&Si(y,k),I}function w(y,v,P,E){if(typeof P=="object"&&P!==null&&P.type===$a&&P.key===null&&(P=P.props.children),typeof P=="object"&&P!==null){switch(P.$$typeof){case xu:e:{for(var I=P.key,C=v;C!==null;){if(C.key===I){if(I=P.type,I===$a){if(C.tag===7){t(y,C.sibling),v=o(C,P.props.children),v.return=y,y=v;break e}}else if(C.elementType===I||typeof I=="object"&&I!==null&&I.$$typeof===bs&&$P(I)===C.type){t(y,C.sibling),v=o(C,P.props),v.ref=ol(y,C,P),v.return=y,y=v;break e}t(y,C);break}else n(y,C);C=C.sibling}P.type===$a?(v=Ai(P.props.children,y.mode,E,P.key),v.return=y,y=v):(E=_h(P.type,P.key,P.props,null,y.mode,E),E.ref=ol(y,v,P),E.return=y,y=E)}return i(y);case Ta:e:{for(C=P.key;v!==null;){if(v.key===C)if(v.tag===4&&v.stateNode.containerInfo===P.containerInfo&&v.stateNode.implementation===P.implementation){t(y,v.sibling),v=o(v,P.children||[]),v.return=y,y=v;break e}else{t(y,v);break}else n(y,v);v=v.sibling}v=Wm(P,y.mode,E),v.return=y,y=v}return i(y);case bs:return C=P._init,w(y,v,C(P._payload),E)}if(xl(P))return S(y,v,P,E);if(Jc(P))return g(y,v,P,E);Mu(y,P)}return typeof P=="string"&&P!==""||typeof P=="number"?(P=""+P,v!==null&&v.tag===6?(t(y,v.sibling),v=o(v,P),v.return=y,y=v):(t(y,v),v=Km(P,y.mode,E),v.return=y,y=v),i(y)):t(y,v)}return w}var dc=QT(!0),JT=QT(!1),Zf=oi(null),Qf=null,Fa=null,fx=null;function px(){fx=Fa=Qf=null}function gx(e){var n=Zf.current;tt(Zf),e._currentValue=n}function YS(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 Qa(e,n){Qf=e,fx=Fa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(Mn=!0),e.firstContext=null)}function Pr(e){var n=e._currentValue;if(fx!==e)if(e={context:e,memoizedValue:n,next:null},Fa===null){if(Qf===null)throw Error(q(308));Fa=e,Qf.dependencies={lanes:0,firstContext:e}}else Fa=Fa.next=e;return n}var Pi=null;function mx(e){Pi===null?Pi=[e]:Pi.push(e)}function e2(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,mx(n)):(t.next=o.next,o.next=t),n.interleaved=t,Qo(e,r)}function Qo(e,n){e.lanes|=n;var t=e.alternate;for(t!==null&&(t.lanes|=n),t=e,e=e.return;e!==null;)e.childLanes|=n,t=e.alternate,t!==null&&(t.childLanes|=n),t=e,e=e.return;return t.tag===3?t.stateNode:null}var Ps=!1;function yx(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function t2(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 Ko(e,n){return{eventTime:e,lane:n,tag:0,payload:null,callback:null,next:null}}function Ns(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Te&2){var o=r.pending;return o===null?n.next=n:(n.next=o.next,o.next=n),r.pending=n,Qo(e,t)}return o=r.interleaved,o===null?(n.next=n,mx(r)):(n.next=o.next,o.next=n),r.interleaved=n,Qo(e,t)}function wh(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,nx(e,t)}}function MP(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 Jf(e,n,t,r){var o=e.updateQueue;Ps=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var c=a,l=c.next;c.next=null,i===null?s=l:i.next=l,i=c;var d=e.alternate;d!==null&&(d=d.updateQueue,a=d.lastBaseUpdate,a!==i&&(a===null?d.firstBaseUpdate=l:a.next=l,d.lastBaseUpdate=c))}if(s!==null){var u=o.baseState;i=0,d=l=c=null,a=s;do{var f=a.lane,p=a.eventTime;if((r&f)===f){d!==null&&(d=d.next={eventTime:p,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var S=e,g=a;switch(f=n,p=t,g.tag){case 1:if(S=g.payload,typeof S=="function"){u=S.call(p,u,f);break e}u=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=g.payload,f=typeof S=="function"?S.call(p,u,f):S,f==null)break e;u=pt({},u,f);break e;case 2:Ps=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,f=o.effects,f===null?o.effects=[a]:f.push(a))}else p={eventTime:p,lane:f,tag:a.tag,payload:a.payload,callback:a.callback,next:null},d===null?(l=d=p,c=u):d=d.next=p,i|=f;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;f=a,a=f.next,f.next=null,o.lastBaseUpdate=f,o.shared.pending=null}}while(!0);if(d===null&&(c=u),o.baseState=c,o.firstBaseUpdate=l,o.lastBaseUpdate=d,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);Ui|=i,e.lanes=i,e.memoizedState=u}}function AP(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 Bd={},ho=oi(Bd),ad=oi(Bd),cd=oi(Bd);function Ci(e){if(e===Bd)throw Error(q(174));return e}function Sx(e,n){switch(Ye(cd,n),Ye(ad,e),Ye(ho,Bd),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:kS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=kS(n,e)}tt(ho),Ye(ho,n)}function uc(){tt(ho),tt(ad),tt(cd)}function n2(e){Ci(cd.current);var n=Ci(ho.current),t=kS(n,e.type);n!==t&&(Ye(ad,e),Ye(ho,t))}function vx(e){ad.current===e&&(tt(ho),tt(ad))}var dt=oi(0);function ep(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 Fm=[];function xx(){for(var e=0;e<Fm.length;e++)Fm[e]._workInProgressVersionPrimary=null;Fm.length=0}var bh=is.ReactCurrentDispatcher,zm=is.ReactCurrentBatchConfig,Bi=0,ft=null,Et=null,$t=null,tp=!1,Dl=!1,ld=0,dH=0;function qt(){throw Error(q(321))}function wx(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Hr(e[t],n[t]))return!1;return!0}function bx(e,n,t,r,o,s){if(Bi=s,ft=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,bh.current=e===null||e.memoizedState===null?pH:gH,e=t(r,o),Dl){s=0;do{if(Dl=!1,ld=0,25<=s)throw Error(q(301));s+=1,$t=Et=null,n.updateQueue=null,bh.current=mH,e=t(r,o)}while(Dl)}if(bh.current=np,n=Et!==null&&Et.next!==null,Bi=0,$t=Et=ft=null,tp=!1,n)throw Error(q(300));return e}function Px(){var e=ld!==0;return ld=0,e}function Jr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return $t===null?ft.memoizedState=$t=e:$t=$t.next=e,$t}function Cr(){if(Et===null){var e=ft.alternate;e=e!==null?e.memoizedState:null}else e=Et.next;var n=$t===null?ft.memoizedState:$t.next;if(n!==null)$t=n,Et=e;else{if(e===null)throw Error(q(310));Et=e,e={memoizedState:Et.memoizedState,baseState:Et.baseState,baseQueue:Et.baseQueue,queue:Et.queue,next:null},$t===null?ft.memoizedState=$t=e:$t=$t.next=e}return $t}function dd(e,n){return typeof n=="function"?n(e):n}function Nm(e){var n=Cr(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=Et,o=r.baseQueue,s=t.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,t.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,c=null,l=s;do{var d=l.lane;if((Bi&d)===d)c!==null&&(c=c.next={lane:0,action:l.action,hasEagerState:l.hasEagerState,eagerState:l.eagerState,next:null}),r=l.hasEagerState?l.eagerState:e(r,l.action);else{var u={lane:d,action:l.action,hasEagerState:l.hasEagerState,eagerState:l.eagerState,next:null};c===null?(a=c=u,i=r):c=c.next=u,ft.lanes|=d,Ui|=d}l=l.next}while(l!==null&&l!==s);c===null?i=r:c.next=a,Hr(r,n.memoizedState)||(Mn=!0),n.memoizedState=r,n.baseState=i,n.baseQueue=c,t.lastRenderedState=r}if(e=t.interleaved,e!==null){o=e;do s=o.lane,ft.lanes|=s,Ui|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function Bm(e){var n=Cr(),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);Hr(s,n.memoizedState)||(Mn=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function r2(){}function o2(e,n){var t=ft,r=Cr(),o=n(),s=!Hr(r.memoizedState,o);if(s&&(r.memoizedState=o,Mn=!0),r=r.queue,Cx(a2.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||$t!==null&&$t.memoizedState.tag&1){if(t.flags|=2048,ud(9,i2.bind(null,t,r,o,n),void 0,null),Ot===null)throw Error(q(349));Bi&30||s2(t,n,o)}return o}function s2(e,n,t){e.flags|=16384,e={getSnapshot:n,value:t},n=ft.updateQueue,n===null?(n={lastEffect:null,stores:null},ft.updateQueue=n,n.stores=[e]):(t=n.stores,t===null?n.stores=[e]:t.push(e))}function i2(e,n,t,r){n.value=t,n.getSnapshot=r,c2(n)&&l2(e)}function a2(e,n,t){return t(function(){c2(n)&&l2(e)})}function c2(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Hr(e,t)}catch{return!0}}function l2(e){var n=Qo(e,1);n!==null&&zr(n,e,1,-1)}function jP(e){var n=Jr();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:dd,lastRenderedState:e},n.queue=e,e=e.dispatch=fH.bind(null,ft,e),[n.memoizedState,e]}function ud(e,n,t,r){return e={tag:e,create:n,destroy:t,deps:r,next:null},n=ft.updateQueue,n===null?(n={lastEffect:null,stores:null},ft.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 d2(){return Cr().memoizedState}function Ph(e,n,t,r){var o=Jr();ft.flags|=e,o.memoizedState=ud(1|n,t,void 0,r===void 0?null:r)}function Hp(e,n,t,r){var o=Cr();r=r===void 0?null:r;var s=void 0;if(Et!==null){var i=Et.memoizedState;if(s=i.destroy,r!==null&&wx(r,i.deps)){o.memoizedState=ud(n,t,s,r);return}}ft.flags|=e,o.memoizedState=ud(1|n,t,s,r)}function OP(e,n){return Ph(8390656,8,e,n)}function Cx(e,n){return Hp(2048,8,e,n)}function u2(e,n){return Hp(4,2,e,n)}function h2(e,n){return Hp(4,4,e,n)}function f2(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 p2(e,n,t){return t=t!=null?t.concat([e]):null,Hp(4,4,f2.bind(null,n,e),t)}function Ix(){}function g2(e,n){var t=Cr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&wx(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function m2(e,n){var t=Cr();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&wx(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function y2(e,n,t){return Bi&21?(Hr(t,n)||(t=bT(),ft.lanes|=t,Ui|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,Mn=!0),e.memoizedState=t)}function uH(e,n){var t=ze;ze=t!==0&&4>t?t:4,e(!0);var r=zm.transition;zm.transition={};try{e(!1),n()}finally{ze=t,zm.transition=r}}function S2(){return Cr().memoizedState}function hH(e,n,t){var r=Us(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},v2(e))x2(n,t);else if(t=e2(e,n,t,r),t!==null){var o=gn();zr(t,e,r,o),w2(t,n,r)}}function fH(e,n,t){var r=Us(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(v2(e))x2(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,Hr(a,i)){var c=n.interleaved;c===null?(o.next=o,mx(n)):(o.next=c.next,c.next=o),n.interleaved=o;return}}catch{}finally{}t=e2(e,n,o,r),t!==null&&(o=gn(),zr(t,e,r,o),w2(t,n,r))}}function v2(e){var n=e.alternate;return e===ft||n!==null&&n===ft}function x2(e,n){Dl=tp=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function w2(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,nx(e,t)}}var np={readContext:Pr,useCallback:qt,useContext:qt,useEffect:qt,useImperativeHandle:qt,useInsertionEffect:qt,useLayoutEffect:qt,useMemo:qt,useReducer:qt,useRef:qt,useState:qt,useDebugValue:qt,useDeferredValue:qt,useTransition:qt,useMutableSource:qt,useSyncExternalStore:qt,useId:qt,unstable_isNewReconciler:!1},pH={readContext:Pr,useCallback:function(e,n){return Jr().memoizedState=[e,n===void 0?null:n],e},useContext:Pr,useEffect:OP,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,Ph(4194308,4,f2.bind(null,n,e),t)},useLayoutEffect:function(e,n){return Ph(4194308,4,e,n)},useInsertionEffect:function(e,n){return Ph(4,2,e,n)},useMemo:function(e,n){var t=Jr();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=Jr();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=hH.bind(null,ft,e),[r.memoizedState,e]},useRef:function(e){var n=Jr();return e={current:e},n.memoizedState=e},useState:jP,useDebugValue:Ix,useDeferredValue:function(e){return Jr().memoizedState=e},useTransition:function(){var e=jP(!1),n=e[0];return e=uH.bind(null,e[1]),Jr().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=ft,o=Jr();if(rt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),Ot===null)throw Error(q(349));Bi&30||s2(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,OP(a2.bind(null,r,s,e),[e]),r.flags|=2048,ud(9,i2.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=Jr(),n=Ot.identifierPrefix;if(rt){var t=No,r=zo;t=(r&~(1<<32-Fr(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=ld++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=dH++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},gH={readContext:Pr,useCallback:g2,useContext:Pr,useEffect:Cx,useImperativeHandle:p2,useInsertionEffect:u2,useLayoutEffect:h2,useMemo:m2,useReducer:Nm,useRef:d2,useState:function(){return Nm(dd)},useDebugValue:Ix,useDeferredValue:function(e){var n=Cr();return y2(n,Et.memoizedState,e)},useTransition:function(){var e=Nm(dd)[0],n=Cr().memoizedState;return[e,n]},useMutableSource:r2,useSyncExternalStore:o2,useId:S2,unstable_isNewReconciler:!1},mH={readContext:Pr,useCallback:g2,useContext:Pr,useEffect:Cx,useImperativeHandle:p2,useInsertionEffect:u2,useLayoutEffect:h2,useMemo:m2,useReducer:Bm,useRef:d2,useState:function(){return Bm(dd)},useDebugValue:Ix,useDeferredValue:function(e){var n=Cr();return Et===null?n.memoizedState=e:y2(n,Et.memoizedState,e)},useTransition:function(){var e=Bm(dd)[0],n=Cr().memoizedState;return[e,n]},useMutableSource:r2,useSyncExternalStore:o2,useId:S2,unstable_isNewReconciler:!1};function $r(e,n){if(e&&e.defaultProps){n=pt({},n),e=e.defaultProps;for(var t in e)n[t]===void 0&&(n[t]=e[t]);return n}return n}function XS(e,n,t,r){n=e.memoizedState,t=t(r,n),t=t==null?n:pt({},n,t),e.memoizedState=t,e.lanes===0&&(e.updateQueue.baseState=t)}var Kp={isMounted:function(e){return(e=e._reactInternals)?ra(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=gn(),o=Us(e),s=Ko(r,o);s.payload=n,t!=null&&(s.callback=t),n=Ns(e,s,o),n!==null&&(zr(n,e,o,r),wh(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=gn(),o=Us(e),s=Ko(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=Ns(e,s,o),n!==null&&(zr(n,e,o,r),wh(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=gn(),r=Us(e),o=Ko(t,r);o.tag=2,n!=null&&(o.callback=n),n=Ns(e,o,r),n!==null&&(zr(n,e,r,t),wh(n,e,r))}};function DP(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?!rd(t,r)||!rd(o,s):!0}function b2(e,n,t){var r=!1,o=Vs,s=n.contextType;return typeof s=="object"&&s!==null?s=Pr(s):(o=Rn(n)?zi:cn.current,r=n.contextTypes,s=(r=r!=null)?cc(e,o):Vs),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=Kp,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function RP(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&&Kp.enqueueReplaceState(n,n.state,null)}function qS(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs={},yx(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=Pr(s):(s=Rn(n)?zi:cn.current,o.context=cc(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(XS(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&&Kp.enqueueReplaceState(o,o.state,null),Jf(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function hc(e,n){try{var t="",r=n;do t+=KU(r),r=r.return;while(r);var o=t}catch(s){o=`
|
|
84
|
-
Error generating stack: `+s.message+`
|
|
85
|
-
`+s.stack}return{value:e,source:n,stack:o,digest:null}}function Um(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function ZS(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var yH=typeof WeakMap=="function"?WeakMap:Map;function P2(e,n,t){t=Ko(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){op||(op=!0,av=r),ZS(e,n)},t}function C2(e,n,t){t=Ko(-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(){ZS(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){ZS(e,n),typeof r!="function"&&(Bs===null?Bs=new Set([this]):Bs.add(this));var i=n.stack;this.componentDidCatch(n.value,{componentStack:i!==null?i:""})}),t}function LP(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new yH;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=MH.bind(null,e,n,t),n.then(e,e))}function FP(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 zP(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=Ko(-1,1),n.tag=2,Ns(t,n,1))),t.lanes|=1),e)}var SH=is.ReactCurrentOwner,Mn=!1;function hn(e,n,t,r){n.child=e===null?JT(n,null,t,r):dc(n,e.child,t,r)}function NP(e,n,t,r,o){t=t.render;var s=n.ref;return Qa(n,o),r=bx(e,n,t,r,s,o),t=Px(),e!==null&&!Mn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Jo(e,n,o)):(rt&&t&&dx(n),n.flags|=1,hn(e,n,r,o),n.child)}function BP(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!jx(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,I2(e,n,s,r,o)):(e=_h(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:rd,t(i,r)&&e.ref===n.ref)return Jo(e,n,o)}return n.flags|=1,e=Hs(s,r),e.ref=n.ref,e.return=n,n.child=e}function I2(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(rd(s,r)&&e.ref===n.ref)if(Mn=!1,n.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(Mn=!0);else return n.lanes=e.lanes,Jo(e,n,o)}return QS(e,n,t,r,o)}function E2(e,n,t){var r=n.pendingProps,o=r.children,s=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(n.mode&1))n.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ye(Na,Vn),Vn|=t;else{if(!(t&1073741824))return e=s!==null?s.baseLanes|t:t,n.lanes=n.childLanes=1073741824,n.memoizedState={baseLanes:e,cachePool:null,transitions:null},n.updateQueue=null,Ye(Na,Vn),Vn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ye(Na,Vn),Vn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ye(Na,Vn),Vn|=r;return hn(e,n,o,t),n.child}function _2(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function QS(e,n,t,r,o){var s=Rn(t)?zi:cn.current;return s=cc(n,s),Qa(n,o),t=bx(e,n,t,r,s,o),r=Px(),e!==null&&!Mn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Jo(e,n,o)):(rt&&r&&dx(n),n.flags|=1,hn(e,n,t,o),n.child)}function UP(e,n,t,r,o){if(Rn(t)){var s=!0;Yf(n)}else s=!1;if(Qa(n,o),n.stateNode===null)Ch(e,n),b2(n,t,r),qS(n,t,r,o),r=!0;else if(e===null){var i=n.stateNode,a=n.memoizedProps;i.props=a;var c=i.context,l=t.contextType;typeof l=="object"&&l!==null?l=Pr(l):(l=Rn(t)?zi:cn.current,l=cc(n,l));var d=t.getDerivedStateFromProps,u=typeof d=="function"||typeof i.getSnapshotBeforeUpdate=="function";u||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||c!==l)&&RP(n,i,r,l),Ps=!1;var f=n.memoizedState;i.state=f,Jf(n,r,i,o),c=n.memoizedState,a!==r||f!==c||Dn.current||Ps?(typeof d=="function"&&(XS(n,t,d,r),c=n.memoizedState),(a=Ps||DP(n,t,a,r,f,c,l))?(u||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(n.flags|=4194308)):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=c),i.props=r,i.state=c,i.context=l,r=a):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{i=n.stateNode,t2(e,n),a=n.memoizedProps,l=n.type===n.elementType?a:$r(n.type,a),i.props=l,u=n.pendingProps,f=i.context,c=t.contextType,typeof c=="object"&&c!==null?c=Pr(c):(c=Rn(t)?zi:cn.current,c=cc(n,c));var p=t.getDerivedStateFromProps;(d=typeof p=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==u||f!==c)&&RP(n,i,r,c),Ps=!1,f=n.memoizedState,i.state=f,Jf(n,r,i,o);var S=n.memoizedState;a!==u||f!==S||Dn.current||Ps?(typeof p=="function"&&(XS(n,t,p,r),S=n.memoizedState),(l=Ps||DP(n,t,l,r,f,S,c)||!1)?(d||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,S,c),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,S,c)),typeof i.componentDidUpdate=="function"&&(n.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=S),i.props=r,i.state=S,i.context=c,r=l):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&f===e.memoizedState||(n.flags|=1024),r=!1)}return JS(e,n,t,r,s,o)}function JS(e,n,t,r,o,s){_2(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&_P(n,t,!1),Jo(e,n,s);r=n.stateNode,SH.current=n;var a=i&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&i?(n.child=dc(n,e.child,null,s),n.child=dc(n,null,a,s)):hn(e,n,a,s),n.memoizedState=r.state,o&&_P(n,t,!0),n.child}function k2(e){var n=e.stateNode;n.pendingContext?EP(e,n.pendingContext,n.pendingContext!==n.context):n.context&&EP(e,n.context,!1),Sx(e,n.containerInfo)}function HP(e,n,t,r,o){return lc(),hx(o),n.flags|=256,hn(e,n,t,r),n.child}var ev={dehydrated:null,treeContext:null,retryLane:0};function tv(e){return{baseLanes:e,cachePool:null,transitions:null}}function T2(e,n,t){var r=n.pendingProps,o=dt.current,s=!1,i=(n.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(s=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ye(dt,o&1),e===null)return VS(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=Vp(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=tv(t),n.memoizedState=ev,e):Ex(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return vH(e,n,i,r,a,o,t);if(s){s=r.fallback,i=n.mode,o=e.child,a=o.sibling;var c={mode:"hidden",children:r.children};return!(i&1)&&n.child!==o?(r=n.child,r.childLanes=0,r.pendingProps=c,n.deletions=null):(r=Hs(o,c),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Hs(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?tv(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=ev,r}return s=e.child,e=s.sibling,r=Hs(s,{mode:"visible",children:r.children}),!(n.mode&1)&&(r.lanes=t),r.return=n,r.sibling=null,e!==null&&(t=n.deletions,t===null?(n.deletions=[e],n.flags|=16):t.push(e)),n.child=r,n.memoizedState=null,r}function Ex(e,n){return n=Vp({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Au(e,n,t,r){return r!==null&&hx(r),dc(n,e.child,null,t),e=Ex(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function vH(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=Um(Error(q(422))),Au(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=Vp({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&&dc(n,e.child,null,i),n.child.memoizedState=tv(i),n.memoizedState=ev,s);if(!(n.mode&1))return Au(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=Um(s,r,void 0),Au(e,n,i,r)}if(a=(i&e.childLanes)!==0,Mn||a){if(r=Ot,r!==null){switch(i&-i){case 4:o=2;break;case 16:o=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:o=32;break;case 536870912:o=268435456;break;default:o=0}o=o&(r.suspendedLanes|i)?0:o,o!==0&&o!==s.retryLane&&(s.retryLane=o,Qo(e,o),zr(r,e,o,-1))}return Ax(),r=Um(Error(q(421))),Au(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=AH.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,qn=zs(o.nextSibling),er=n,rt=!0,Dr=null,e!==null&&(Sr[vr++]=zo,Sr[vr++]=No,Sr[vr++]=Ni,zo=e.id,No=e.overflow,Ni=n),n=Ex(n,r.children),n.flags|=4096,n)}function KP(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),YS(e.return,n,t)}function Hm(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 $2(e,n,t){var r=n.pendingProps,o=r.revealOrder,s=r.tail;if(hn(e,n,r.children,t),r=dt.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&&KP(e,t,n);else if(e.tag===19)KP(e,t,n);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===n)break e;for(;e.sibling===null;){if(e.return===null||e.return===n)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Ye(dt,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&&ep(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),Hm(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&&ep(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}Hm(n,!0,t,null,s);break;case"together":Hm(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function Ch(e,n){!(n.mode&1)&&e!==null&&(e.alternate=null,n.alternate=null,n.flags|=2)}function Jo(e,n,t){if(e!==null&&(n.dependencies=e.dependencies),Ui|=n.lanes,!(t&n.childLanes))return null;if(e!==null&&n.child!==e.child)throw Error(q(153));if(n.child!==null){for(e=n.child,t=Hs(e,e.pendingProps),n.child=t,t.return=n;e.sibling!==null;)e=e.sibling,t=t.sibling=Hs(e,e.pendingProps),t.return=n;t.sibling=null}return n.child}function xH(e,n,t){switch(n.tag){case 3:k2(n),lc();break;case 5:n2(n);break;case 1:Rn(n.type)&&Yf(n);break;case 4:Sx(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ye(Zf,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ye(dt,dt.current&1),n.flags|=128,null):t&n.child.childLanes?T2(e,n,t):(Ye(dt,dt.current&1),e=Jo(e,n,t),e!==null?e.sibling:null);Ye(dt,dt.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return $2(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ye(dt,dt.current),r)break;return null;case 22:case 23:return n.lanes=0,E2(e,n,t)}return Jo(e,n,t)}var M2,nv,A2,j2;M2=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}};nv=function(){};A2=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,Ci(ho.current);var s=null;switch(t){case"input":o=CS(e,o),r=CS(e,r),s=[];break;case"select":o=pt({},o,{value:void 0}),r=pt({},r,{value:void 0}),s=[];break;case"textarea":o=_S(e,o),r=_S(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Gf)}TS(t,r);var i;t=null;for(l in o)if(!r.hasOwnProperty(l)&&o.hasOwnProperty(l)&&o[l]!=null)if(l==="style"){var a=o[l];for(i in a)a.hasOwnProperty(i)&&(t||(t={}),t[i]="")}else l!=="dangerouslySetInnerHTML"&&l!=="children"&&l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&l!=="autoFocus"&&(ql.hasOwnProperty(l)?s||(s=[]):(s=s||[]).push(l,null));for(l in r){var c=r[l];if(a=o!=null?o[l]:void 0,r.hasOwnProperty(l)&&c!==a&&(c!=null||a!=null))if(l==="style")if(a){for(i in a)!a.hasOwnProperty(i)||c&&c.hasOwnProperty(i)||(t||(t={}),t[i]="");for(i in c)c.hasOwnProperty(i)&&a[i]!==c[i]&&(t||(t={}),t[i]=c[i])}else t||(s||(s=[]),s.push(l,t)),t=c;else l==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,a=a?a.__html:void 0,c!=null&&a!==c&&(s=s||[]).push(l,c)):l==="children"?typeof c!="string"&&typeof c!="number"||(s=s||[]).push(l,""+c):l!=="suppressContentEditableWarning"&&l!=="suppressHydrationWarning"&&(ql.hasOwnProperty(l)?(c!=null&&l==="onScroll"&&Je("scroll",e),s||a===c||(s=[])):(s=s||[]).push(l,c))}t&&(s=s||[]).push("style",t);var l=s;(n.updateQueue=l)&&(n.flags|=4)}};j2=function(e,n,t,r){t!==r&&(n.flags|=4)};function sl(e,n){if(!rt)switch(e.tailMode){case"hidden":n=e.tail;for(var t=null;n!==null;)n.alternate!==null&&(t=n),n=n.sibling;t===null?e.tail=null:t.sibling=null;break;case"collapsed":t=e.tail;for(var r=null;t!==null;)t.alternate!==null&&(r=t),t=t.sibling;r===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Zt(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 wH(e,n,t){var r=n.pendingProps;switch(ux(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Zt(n),null;case 1:return Rn(n.type)&&Vf(),Zt(n),null;case 3:return r=n.stateNode,uc(),tt(Dn),tt(cn),xx(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&($u(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,Dr!==null&&(dv(Dr),Dr=null))),nv(e,n),Zt(n),null;case 5:vx(n);var o=Ci(cd.current);if(t=n.type,e!==null&&n.stateNode!=null)A2(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 Zt(n),null}if(e=Ci(ho.current),$u(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[ro]=n,r[id]=s,e=(n.mode&1)!==0,t){case"dialog":Je("cancel",r),Je("close",r);break;case"iframe":case"object":case"embed":Je("load",r);break;case"video":case"audio":for(o=0;o<bl.length;o++)Je(bl[o],r);break;case"source":Je("error",r);break;case"img":case"image":case"link":Je("error",r),Je("load",r);break;case"details":Je("toggle",r);break;case"input":J1(r,s),Je("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Je("invalid",r);break;case"textarea":tP(r,s),Je("invalid",r)}TS(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&&Tu(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Tu(r.textContent,a,e),o=["children",""+a]):ql.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Je("scroll",r)}switch(t){case"input":wu(r),eP(r,s,!0);break;case"textarea":wu(r),nP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Gf)}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=aT(t)),e==="http://www.w3.org/1999/xhtml"?t==="script"?(e=i.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(t,{is:r.is}):(e=i.createElement(t),t==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,t),e[ro]=n,e[id]=r,M2(e,n,!1,!1),n.stateNode=e;e:{switch(i=$S(t,r),t){case"dialog":Je("cancel",e),Je("close",e),o=r;break;case"iframe":case"object":case"embed":Je("load",e),o=r;break;case"video":case"audio":for(o=0;o<bl.length;o++)Je(bl[o],e);o=r;break;case"source":Je("error",e),o=r;break;case"img":case"image":case"link":Je("error",e),Je("load",e),o=r;break;case"details":Je("toggle",e),o=r;break;case"input":J1(e,r),o=CS(e,r),Je("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=pt({},r,{value:void 0}),Je("invalid",e);break;case"textarea":tP(e,r),o=_S(e,r),Je("invalid",e);break;default:o=r}TS(t,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var c=a[s];s==="style"?dT(e,c):s==="dangerouslySetInnerHTML"?(c=c?c.__html:void 0,c!=null&&cT(e,c)):s==="children"?typeof c=="string"?(t!=="textarea"||c!=="")&&Zl(e,c):typeof c=="number"&&Zl(e,""+c):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(ql.hasOwnProperty(s)?c!=null&&s==="onScroll"&&Je("scroll",e):c!=null&&q0(e,s,c,i))}switch(t){case"input":wu(e),eP(e,r,!1);break;case"textarea":wu(e),nP(e);break;case"option":r.value!=null&&e.setAttribute("value",""+Gs(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?Ya(e,!!r.multiple,s,!1):r.defaultValue!=null&&Ya(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Gf)}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 Zt(n),null;case 6:if(e&&n.stateNode!=null)j2(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=Ci(cd.current),Ci(ho.current),$u(n)){if(r=n.stateNode,t=n.memoizedProps,r[ro]=n,(s=r.nodeValue!==t)&&(e=er,e!==null))switch(e.tag){case 3:Tu(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Tu(r.nodeValue,t,(e.mode&1)!==0)}s&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[ro]=n,n.stateNode=r}return Zt(n),null;case 13:if(tt(dt),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(rt&&qn!==null&&n.mode&1&&!(n.flags&128))ZT(),lc(),n.flags|=98560,s=!1;else if(s=$u(n),r!==null&&r.dehydrated!==null){if(e===null){if(!s)throw Error(q(318));if(s=n.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(q(317));s[ro]=n}else lc(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Zt(n),s=!1}else Dr!==null&&(dv(Dr),Dr=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||dt.current&1?_t===0&&(_t=3):Ax())),n.updateQueue!==null&&(n.flags|=4),Zt(n),null);case 4:return uc(),nv(e,n),e===null&&od(n.stateNode.containerInfo),Zt(n),null;case 10:return gx(n.type._context),Zt(n),null;case 17:return Rn(n.type)&&Vf(),Zt(n),null;case 19:if(tt(dt),s=n.memoizedState,s===null)return Zt(n),null;if(r=(n.flags&128)!==0,i=s.rendering,i===null)if(r)sl(s,!1);else{if(_t!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=ep(e),i!==null){for(n.flags|=128,sl(s,!1),r=i.updateQueue,r!==null&&(n.updateQueue=r,n.flags|=4),n.subtreeFlags=0,r=t,t=n.child;t!==null;)s=t,e=r,s.flags&=14680066,i=s.alternate,i===null?(s.childLanes=0,s.lanes=e,s.child=null,s.subtreeFlags=0,s.memoizedProps=null,s.memoizedState=null,s.updateQueue=null,s.dependencies=null,s.stateNode=null):(s.childLanes=i.childLanes,s.lanes=i.lanes,s.child=i.child,s.subtreeFlags=0,s.deletions=null,s.memoizedProps=i.memoizedProps,s.memoizedState=i.memoizedState,s.updateQueue=i.updateQueue,s.type=i.type,e=i.dependencies,s.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),t=t.sibling;return Ye(dt,dt.current&1|2),n.child}e=e.sibling}s.tail!==null&&bt()>fc&&(n.flags|=128,r=!0,sl(s,!1),n.lanes=4194304)}else{if(!r)if(e=ep(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),sl(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!rt)return Zt(n),null}else 2*bt()-s.renderingStartTime>fc&&t!==1073741824&&(n.flags|=128,r=!0,sl(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=bt(),n.sibling=null,t=dt.current,Ye(dt,r?t&1|2:t&1),n):(Zt(n),null);case 22:case 23:return Mx(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Vn&1073741824&&(Zt(n),n.subtreeFlags&6&&(n.flags|=8192)):Zt(n),null;case 24:return null;case 25:return null}throw Error(q(156,n.tag))}function bH(e,n){switch(ux(n),n.tag){case 1:return Rn(n.type)&&Vf(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return uc(),tt(Dn),tt(cn),xx(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return vx(n),null;case 13:if(tt(dt),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));lc()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return tt(dt),null;case 4:return uc(),null;case 10:return gx(n.type._context),null;case 22:case 23:return Mx(),null;case 24:return null;default:return null}}var ju=!1,nn=!1,PH=typeof WeakSet=="function"?WeakSet:Set,ne=null;function za(e,n){var t=e.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){St(e,n,r)}else t.current=null}function rv(e,n,t){try{t()}catch(r){St(e,n,r)}}var WP=!1;function CH(e,n){if(NS=Hf,e=FT(),lx(e)){if("selectionStart"in e)var t={start:e.selectionStart,end:e.selectionEnd};else e:{t=(t=e.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{t.nodeType,s.nodeType}catch{t=null;break e}var i=0,a=-1,c=-1,l=0,d=0,u=e,f=null;t:for(;;){for(var p;u!==t||o!==0&&u.nodeType!==3||(a=i+o),u!==s||r!==0&&u.nodeType!==3||(c=i+r),u.nodeType===3&&(i+=u.nodeValue.length),(p=u.firstChild)!==null;)f=u,u=p;for(;;){if(u===e)break t;if(f===t&&++l===o&&(a=i),f===s&&++d===r&&(c=i),(p=u.nextSibling)!==null)break;u=f,f=u.parentNode}u=p}t=a===-1||c===-1?null:{start:a,end:c}}else t=null}t=t||{start:0,end:0}}else t=null;for(BS={focusedElem:e,selectionRange:t},Hf=!1,ne=n;ne!==null;)if(n=ne,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,ne=e;else for(;ne!==null;){n=ne;try{var S=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var g=S.memoizedProps,w=S.memoizedState,y=n.stateNode,v=y.getSnapshotBeforeUpdate(n.elementType===n.type?g:$r(n.type,g),w);y.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var P=n.stateNode.containerInfo;P.nodeType===1?P.textContent="":P.nodeType===9&&P.documentElement&&P.removeChild(P.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(q(163))}}catch(E){St(n,n.return,E)}if(e=n.sibling,e!==null){e.return=n.return,ne=e;break}ne=n.return}return S=WP,WP=!1,S}function Rl(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&&rv(n,t,s)}o=o.next}while(o!==r)}}function Wp(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 ov(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 O2(e){var n=e.alternate;n!==null&&(e.alternate=null,O2(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[ro],delete n[id],delete n[KS],delete n[iH],delete n[aH])),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 D2(e){return e.tag===5||e.tag===3||e.tag===4}function GP(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||D2(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 sv(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=Gf));else if(r!==4&&(e=e.child,e!==null))for(sv(e,n,t),e=e.sibling;e!==null;)sv(e,n,t),e=e.sibling}function iv(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(iv(e,n,t),e=e.sibling;e!==null;)iv(e,n,t),e=e.sibling}var Ft=null,Ar=!1;function ms(e,n,t){for(t=t.child;t!==null;)R2(e,n,t),t=t.sibling}function R2(e,n,t){if(uo&&typeof uo.onCommitFiberUnmount=="function")try{uo.onCommitFiberUnmount(Lp,t)}catch{}switch(t.tag){case 5:nn||za(t,n);case 6:var r=Ft,o=Ar;Ft=null,ms(e,n,t),Ft=r,Ar=o,Ft!==null&&(Ar?(e=Ft,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):Ft.removeChild(t.stateNode));break;case 18:Ft!==null&&(Ar?(e=Ft,t=t.stateNode,e.nodeType===8?Rm(e.parentNode,t):e.nodeType===1&&Rm(e,t),td(e)):Rm(Ft,t.stateNode));break;case 4:r=Ft,o=Ar,Ft=t.stateNode.containerInfo,Ar=!0,ms(e,n,t),Ft=r,Ar=o;break;case 0:case 11:case 14:case 15:if(!nn&&(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)&&rv(t,n,i),o=o.next}while(o!==r)}ms(e,n,t);break;case 1:if(!nn&&(za(t,n),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(a){St(t,n,a)}ms(e,n,t);break;case 21:ms(e,n,t);break;case 22:t.mode&1?(nn=(r=nn)||t.memoizedState!==null,ms(e,n,t),nn=r):ms(e,n,t);break;default:ms(e,n,t)}}function VP(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new PH),n.forEach(function(r){var o=jH.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function Tr(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var s=e,i=n,a=i;e:for(;a!==null;){switch(a.tag){case 5:Ft=a.stateNode,Ar=!1;break e;case 3:Ft=a.stateNode.containerInfo,Ar=!0;break e;case 4:Ft=a.stateNode.containerInfo,Ar=!0;break e}a=a.return}if(Ft===null)throw Error(q(160));R2(s,i,o),Ft=null,Ar=!1;var c=o.alternate;c!==null&&(c.return=null),o.return=null}catch(l){St(o,n,l)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)L2(n,e),n=n.sibling}function L2(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Tr(n,e),Qr(e),r&4){try{Rl(3,e,e.return),Wp(3,e)}catch(g){St(e,e.return,g)}try{Rl(5,e,e.return)}catch(g){St(e,e.return,g)}}break;case 1:Tr(n,e),Qr(e),r&512&&t!==null&&za(t,t.return);break;case 5:if(Tr(n,e),Qr(e),r&512&&t!==null&&za(t,t.return),e.flags&32){var o=e.stateNode;try{Zl(o,"")}catch(g){St(e,e.return,g)}}if(r&4&&(o=e.stateNode,o!=null)){var s=e.memoizedProps,i=t!==null?t.memoizedProps:s,a=e.type,c=e.updateQueue;if(e.updateQueue=null,c!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&sT(o,s),$S(a,i);var l=$S(a,s);for(i=0;i<c.length;i+=2){var d=c[i],u=c[i+1];d==="style"?dT(o,u):d==="dangerouslySetInnerHTML"?cT(o,u):d==="children"?Zl(o,u):q0(o,d,u,l)}switch(a){case"input":IS(o,s);break;case"textarea":iT(o,s);break;case"select":var f=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var p=s.value;p!=null?Ya(o,!!s.multiple,p,!1):f!==!!s.multiple&&(s.defaultValue!=null?Ya(o,!!s.multiple,s.defaultValue,!0):Ya(o,!!s.multiple,s.multiple?[]:"",!1))}o[id]=s}catch(g){St(e,e.return,g)}}break;case 6:if(Tr(n,e),Qr(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(g){St(e,e.return,g)}}break;case 3:if(Tr(n,e),Qr(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{td(n.containerInfo)}catch(g){St(e,e.return,g)}break;case 4:Tr(n,e),Qr(e);break;case 13:Tr(n,e),Qr(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(Tx=bt())),r&4&&VP(e);break;case 22:if(d=t!==null&&t.memoizedState!==null,e.mode&1?(nn=(l=nn)||d,Tr(n,e),nn=l):Tr(n,e),Qr(e),r&8192){if(l=e.memoizedState!==null,(e.stateNode.isHidden=l)&&!d&&e.mode&1)for(ne=e,d=e.child;d!==null;){for(u=ne=d;ne!==null;){switch(f=ne,p=f.child,f.tag){case 0:case 11:case 14:case 15:Rl(4,f,f.return);break;case 1:za(f,f.return);var S=f.stateNode;if(typeof S.componentWillUnmount=="function"){r=f,t=f.return;try{n=r,S.props=n.memoizedProps,S.state=n.memoizedState,S.componentWillUnmount()}catch(g){St(r,t,g)}}break;case 5:za(f,f.return);break;case 22:if(f.memoizedState!==null){XP(u);continue}}p!==null?(p.return=f,ne=p):XP(u)}d=d.sibling}e:for(d=null,u=e;;){if(u.tag===5){if(d===null){d=u;try{o=u.stateNode,l?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=u.stateNode,c=u.memoizedProps.style,i=c!=null&&c.hasOwnProperty("display")?c.display:null,a.style.display=lT("display",i))}catch(g){St(e,e.return,g)}}}else if(u.tag===6){if(d===null)try{u.stateNode.nodeValue=l?"":u.memoizedProps}catch(g){St(e,e.return,g)}}else if((u.tag!==22&&u.tag!==23||u.memoizedState===null||u===e)&&u.child!==null){u.child.return=u,u=u.child;continue}if(u===e)break e;for(;u.sibling===null;){if(u.return===null||u.return===e)break e;d===u&&(d=null),u=u.return}d===u&&(d=null),u.sibling.return=u.return,u=u.sibling}}break;case 19:Tr(n,e),Qr(e),r&4&&VP(e);break;case 21:break;default:Tr(n,e),Qr(e)}}function Qr(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(D2(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&&(Zl(o,""),r.flags&=-33);var s=GP(e);iv(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=GP(e);sv(e,a,i);break;default:throw Error(q(161))}}catch(c){St(e,e.return,c)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function IH(e,n,t){ne=e,F2(e)}function F2(e,n,t){for(var r=(e.mode&1)!==0;ne!==null;){var o=ne,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||ju;if(!i){var a=o.alternate,c=a!==null&&a.memoizedState!==null||nn;a=ju;var l=nn;if(ju=i,(nn=c)&&!l)for(ne=o;ne!==null;)i=ne,c=i.child,i.tag===22&&i.memoizedState!==null?qP(o):c!==null?(c.return=i,ne=c):qP(o);for(;s!==null;)ne=s,F2(s),s=s.sibling;ne=o,ju=a,nn=l}YP(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,ne=s):YP(e)}}function YP(e){for(;ne!==null;){var n=ne;if(n.flags&8772){var t=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:nn||Wp(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!nn)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:$r(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&AP(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}AP(n,i,t)}break;case 5:var a=n.stateNode;if(t===null&&n.flags&4){t=a;var c=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":c.autoFocus&&t.focus();break;case"img":c.src&&(t.src=c.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var l=n.alternate;if(l!==null){var d=l.memoizedState;if(d!==null){var u=d.dehydrated;u!==null&&td(u)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}nn||n.flags&512&&ov(n)}catch(f){St(n,n.return,f)}}if(n===e){ne=null;break}if(t=n.sibling,t!==null){t.return=n.return,ne=t;break}ne=n.return}}function XP(e){for(;ne!==null;){var n=ne;if(n===e){ne=null;break}var t=n.sibling;if(t!==null){t.return=n.return,ne=t;break}ne=n.return}}function qP(e){for(;ne!==null;){var n=ne;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{Wp(4,n)}catch(c){St(n,t,c)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var o=n.return;try{r.componentDidMount()}catch(c){St(n,o,c)}}var s=n.return;try{ov(n)}catch(c){St(n,s,c)}break;case 5:var i=n.return;try{ov(n)}catch(c){St(n,i,c)}}}catch(c){St(n,n.return,c)}if(n===e){ne=null;break}var a=n.sibling;if(a!==null){a.return=n.return,ne=a;break}ne=n.return}}var EH=Math.ceil,rp=is.ReactCurrentDispatcher,_x=is.ReactCurrentOwner,br=is.ReactCurrentBatchConfig,Te=0,Ot=null,Ct=null,Wt=0,Vn=0,Na=oi(0),_t=0,hd=null,Ui=0,Gp=0,kx=0,Ll=null,_n=null,Tx=0,fc=1/0,Oo=null,op=!1,av=null,Bs=null,Ou=!1,Ts=null,sp=0,Fl=0,cv=null,Ih=-1,Eh=0;function gn(){return Te&6?bt():Ih!==-1?Ih:Ih=bt()}function Us(e){return e.mode&1?Te&2&&Wt!==0?Wt&-Wt:lH.transition!==null?(Eh===0&&(Eh=bT()),Eh):(e=ze,e!==0||(e=window.event,e=e===void 0?16:TT(e.type)),e):1}function zr(e,n,t,r){if(50<Fl)throw Fl=0,cv=null,Error(q(185));Fd(e,t,r),(!(Te&2)||e!==Ot)&&(e===Ot&&(!(Te&2)&&(Gp|=t),_t===4&&Es(e,Wt)),Ln(e,r),t===1&&Te===0&&!(n.mode&1)&&(fc=bt()+500,Up&&si()))}function Ln(e,n){var t=e.callbackNode;l9(e,n);var r=Uf(e,e===Ot?Wt:0);if(r===0)t!==null&&sP(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&sP(t),n===1)e.tag===0?cH(ZP.bind(null,e)):YT(ZP.bind(null,e)),oH(function(){!(Te&6)&&si()}),t=null;else{switch(PT(r)){case 1:t=tx;break;case 4:t=xT;break;case 16:t=Bf;break;case 536870912:t=wT;break;default:t=Bf}t=G2(t,z2.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function z2(e,n){if(Ih=-1,Eh=0,Te&6)throw Error(q(327));var t=e.callbackNode;if(Ja()&&e.callbackNode!==t)return null;var r=Uf(e,e===Ot?Wt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=ip(e,r);else{n=r;var o=Te;Te|=2;var s=B2();(Ot!==e||Wt!==n)&&(Oo=null,fc=bt()+500,Mi(e,n));do try{TH();break}catch(a){N2(e,a)}while(!0);px(),rp.current=s,Te=o,Ct!==null?n=0:(Ot=null,Wt=0,n=_t)}if(n!==0){if(n===2&&(o=DS(e),o!==0&&(r=o,n=lv(e,o))),n===1)throw t=hd,Mi(e,0),Es(e,r),Ln(e,bt()),t;if(n===6)Es(e,r);else{if(o=e.current.alternate,!(r&30)&&!_H(o)&&(n=ip(e,r),n===2&&(s=DS(e),s!==0&&(r=s,n=lv(e,s))),n===1))throw t=hd,Mi(e,0),Es(e,r),Ln(e,bt()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:vi(e,_n,Oo);break;case 3:if(Es(e,r),(r&130023424)===r&&(n=Tx+500-bt(),10<n)){if(Uf(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){gn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=HS(vi.bind(null,e,_n,Oo),n);break}vi(e,_n,Oo);break;case 4:if(Es(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var i=31-Fr(r);s=1<<i,i=n[i],i>o&&(o=i),r&=~s}if(r=o,r=bt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*EH(r/1960))-r,10<r){e.timeoutHandle=HS(vi.bind(null,e,_n,Oo),r);break}vi(e,_n,Oo);break;case 5:vi(e,_n,Oo);break;default:throw Error(q(329))}}}return Ln(e,bt()),e.callbackNode===t?z2.bind(null,e):null}function lv(e,n){var t=Ll;return e.current.memoizedState.isDehydrated&&(Mi(e,n).flags|=256),e=ip(e,n),e!==2&&(n=_n,_n=t,n!==null&&dv(n)),e}function dv(e){_n===null?_n=e:_n.push.apply(_n,e)}function _H(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(!Hr(s(),o))return!1}catch{return!1}}}if(t=n.child,n.subtreeFlags&16384&&t!==null)t.return=n,n=t;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Es(e,n){for(n&=~kx,n&=~Gp,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-Fr(n),r=1<<t;e[t]=-1,n&=~r}}function ZP(e){if(Te&6)throw Error(q(327));Ja();var n=Uf(e,0);if(!(n&1))return Ln(e,bt()),null;var t=ip(e,n);if(e.tag!==0&&t===2){var r=DS(e);r!==0&&(n=r,t=lv(e,r))}if(t===1)throw t=hd,Mi(e,0),Es(e,n),Ln(e,bt()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,vi(e,_n,Oo),Ln(e,bt()),null}function $x(e,n){var t=Te;Te|=1;try{return e(n)}finally{Te=t,Te===0&&(fc=bt()+500,Up&&si())}}function Hi(e){Ts!==null&&Ts.tag===0&&!(Te&6)&&Ja();var n=Te;Te|=1;var t=br.transition,r=ze;try{if(br.transition=null,ze=1,e)return e()}finally{ze=r,br.transition=t,Te=n,!(Te&6)&&si()}}function Mx(){Vn=Na.current,tt(Na)}function Mi(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,rH(t)),Ct!==null)for(t=Ct.return;t!==null;){var r=t;switch(ux(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Vf();break;case 3:uc(),tt(Dn),tt(cn),xx();break;case 5:vx(r);break;case 4:uc();break;case 13:tt(dt);break;case 19:tt(dt);break;case 10:gx(r.type._context);break;case 22:case 23:Mx()}t=t.return}if(Ot=e,Ct=e=Hs(e.current,null),Wt=Vn=n,_t=0,hd=null,kx=Gp=Ui=0,_n=Ll=null,Pi!==null){for(n=0;n<Pi.length;n++)if(t=Pi[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}Pi=null}return e}function N2(e,n){do{var t=Ct;try{if(px(),bh.current=np,tp){for(var r=ft.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}tp=!1}if(Bi=0,$t=Et=ft=null,Dl=!1,ld=0,_x.current=null,t===null||t.return===null){_t=1,hd=n,Ct=null;break}e:{var s=e,i=t.return,a=t,c=n;if(n=Wt,a.flags|=32768,c!==null&&typeof c=="object"&&typeof c.then=="function"){var l=c,d=a,u=d.tag;if(!(d.mode&1)&&(u===0||u===11||u===15)){var f=d.alternate;f?(d.updateQueue=f.updateQueue,d.memoizedState=f.memoizedState,d.lanes=f.lanes):(d.updateQueue=null,d.memoizedState=null)}var p=FP(i);if(p!==null){p.flags&=-257,zP(p,i,a,s,n),p.mode&1&&LP(s,l,n),n=p,c=l;var S=n.updateQueue;if(S===null){var g=new Set;g.add(c),n.updateQueue=g}else S.add(c);break e}else{if(!(n&1)){LP(s,l,n),Ax();break e}c=Error(q(426))}}else if(rt&&a.mode&1){var w=FP(i);if(w!==null){!(w.flags&65536)&&(w.flags|=256),zP(w,i,a,s,n),hx(hc(c,a));break e}}s=c=hc(c,a),_t!==4&&(_t=2),Ll===null?Ll=[s]:Ll.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var y=P2(s,c,n);MP(s,y);break e;case 1:a=c;var v=s.type,P=s.stateNode;if(!(s.flags&128)&&(typeof v.getDerivedStateFromError=="function"||P!==null&&typeof P.componentDidCatch=="function"&&(Bs===null||!Bs.has(P)))){s.flags|=65536,n&=-n,s.lanes|=n;var E=C2(s,a,n);MP(s,E);break e}}s=s.return}while(s!==null)}H2(t)}catch(I){n=I,Ct===t&&t!==null&&(Ct=t=t.return);continue}break}while(!0)}function B2(){var e=rp.current;return rp.current=np,e===null?np:e}function Ax(){(_t===0||_t===3||_t===2)&&(_t=4),Ot===null||!(Ui&268435455)&&!(Gp&268435455)||Es(Ot,Wt)}function ip(e,n){var t=Te;Te|=2;var r=B2();(Ot!==e||Wt!==n)&&(Oo=null,Mi(e,n));do try{kH();break}catch(o){N2(e,o)}while(!0);if(px(),Te=t,rp.current=r,Ct!==null)throw Error(q(261));return Ot=null,Wt=0,_t}function kH(){for(;Ct!==null;)U2(Ct)}function TH(){for(;Ct!==null&&!e9();)U2(Ct)}function U2(e){var n=W2(e.alternate,e,Vn);e.memoizedProps=e.pendingProps,n===null?H2(e):Ct=n,_x.current=null}function H2(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=bH(t,n),t!==null){t.flags&=32767,Ct=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{_t=6,Ct=null;return}}else if(t=wH(t,n,Vn),t!==null){Ct=t;return}if(n=n.sibling,n!==null){Ct=n;return}Ct=n=e}while(n!==null);_t===0&&(_t=5)}function vi(e,n,t){var r=ze,o=br.transition;try{br.transition=null,ze=1,$H(e,n,t,r)}finally{br.transition=o,ze=r}return null}function $H(e,n,t,r){do Ja();while(Ts!==null);if(Te&6)throw Error(q(327));t=e.finishedWork;var o=e.finishedLanes;if(t===null)return null;if(e.finishedWork=null,e.finishedLanes=0,t===e.current)throw Error(q(177));e.callbackNode=null,e.callbackPriority=0;var s=t.lanes|t.childLanes;if(d9(e,s),e===Ot&&(Ct=Ot=null,Wt=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||Ou||(Ou=!0,G2(Bf,function(){return Ja(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=br.transition,br.transition=null;var i=ze;ze=1;var a=Te;Te|=4,_x.current=null,CH(e,t),L2(t,e),q9(BS),Hf=!!NS,BS=NS=null,e.current=t,IH(t),t9(),Te=a,ze=i,br.transition=s}else e.current=t;if(Ou&&(Ou=!1,Ts=e,sp=o),s=e.pendingLanes,s===0&&(Bs=null),o9(t.stateNode),Ln(e,bt()),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(op)throw op=!1,e=av,av=null,e;return sp&1&&e.tag!==0&&Ja(),s=e.pendingLanes,s&1?e===cv?Fl++:(Fl=0,cv=e):Fl=0,si(),null}function Ja(){if(Ts!==null){var e=PT(sp),n=br.transition,t=ze;try{if(br.transition=null,ze=16>e?16:e,Ts===null)var r=!1;else{if(e=Ts,Ts=null,sp=0,Te&6)throw Error(q(331));var o=Te;for(Te|=4,ne=e.current;ne!==null;){var s=ne,i=s.child;if(ne.flags&16){var a=s.deletions;if(a!==null){for(var c=0;c<a.length;c++){var l=a[c];for(ne=l;ne!==null;){var d=ne;switch(d.tag){case 0:case 11:case 15:Rl(8,d,s)}var u=d.child;if(u!==null)u.return=d,ne=u;else for(;ne!==null;){d=ne;var f=d.sibling,p=d.return;if(O2(d),d===l){ne=null;break}if(f!==null){f.return=p,ne=f;break}ne=p}}}var S=s.alternate;if(S!==null){var g=S.child;if(g!==null){S.child=null;do{var w=g.sibling;g.sibling=null,g=w}while(g!==null)}}ne=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,ne=i;else e:for(;ne!==null;){if(s=ne,s.flags&2048)switch(s.tag){case 0:case 11:case 15:Rl(9,s,s.return)}var y=s.sibling;if(y!==null){y.return=s.return,ne=y;break e}ne=s.return}}var v=e.current;for(ne=v;ne!==null;){i=ne;var P=i.child;if(i.subtreeFlags&2064&&P!==null)P.return=i,ne=P;else e:for(i=v;ne!==null;){if(a=ne,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:Wp(9,a)}}catch(I){St(a,a.return,I)}if(a===i){ne=null;break e}var E=a.sibling;if(E!==null){E.return=a.return,ne=E;break e}ne=a.return}}if(Te=o,si(),uo&&typeof uo.onPostCommitFiberRoot=="function")try{uo.onPostCommitFiberRoot(Lp,e)}catch{}r=!0}return r}finally{ze=t,br.transition=n}}return!1}function QP(e,n,t){n=hc(t,n),n=P2(e,n,1),e=Ns(e,n,1),n=gn(),e!==null&&(Fd(e,1,n),Ln(e,n))}function St(e,n,t){if(e.tag===3)QP(e,e,t);else for(;n!==null;){if(n.tag===3){QP(n,e,t);break}else if(n.tag===1){var r=n.stateNode;if(typeof n.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(Bs===null||!Bs.has(r))){e=hc(t,e),e=C2(n,e,1),n=Ns(n,e,1),e=gn(),n!==null&&(Fd(n,1,e),Ln(n,e));break}}n=n.return}}function MH(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=gn(),e.pingedLanes|=e.suspendedLanes&t,Ot===e&&(Wt&t)===t&&(_t===4||_t===3&&(Wt&130023424)===Wt&&500>bt()-Tx?Mi(e,0):kx|=t),Ln(e,n)}function K2(e,n){n===0&&(e.mode&1?(n=Cu,Cu<<=1,!(Cu&130023424)&&(Cu=4194304)):n=1);var t=gn();e=Qo(e,n),e!==null&&(Fd(e,n,t),Ln(e,t))}function AH(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),K2(e,t)}function jH(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),K2(e,t)}var W2;W2=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||Dn.current)Mn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return Mn=!1,xH(e,n,t);Mn=!!(e.flags&131072)}else Mn=!1,rt&&n.flags&1048576&&XT(n,qf,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;Ch(e,n),e=n.pendingProps;var o=cc(n,cn.current);Qa(n,t),o=bx(null,n,r,e,o,t);var s=Px();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,Rn(r)?(s=!0,Yf(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,yx(n),o.updater=Kp,n.stateNode=o,o._reactInternals=n,qS(n,r,e,t),n=JS(null,n,r,!0,s,t)):(n.tag=0,rt&&s&&dx(n),hn(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(Ch(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=DH(r),e=$r(r,e),o){case 0:n=QS(null,n,r,e,t);break e;case 1:n=UP(null,n,r,e,t);break e;case 11:n=NP(null,n,r,e,t);break e;case 14:n=BP(null,n,r,$r(r.type,e),t);break e}throw Error(q(306,r,""))}return n;case 0:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),QS(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),UP(e,n,r,o,t);case 3:e:{if(k2(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,t2(e,n),Jf(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=hc(Error(q(423)),n),n=HP(e,n,r,t,o);break e}else if(r!==o){o=hc(Error(q(424)),n),n=HP(e,n,r,t,o);break e}else for(qn=zs(n.stateNode.containerInfo.firstChild),er=n,rt=!0,Dr=null,t=JT(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(lc(),r===o){n=Jo(e,n,t);break e}hn(e,n,r,t)}n=n.child}return n;case 5:return n2(n),e===null&&VS(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,US(r,o)?i=null:s!==null&&US(r,s)&&(n.flags|=32),_2(e,n),hn(e,n,i,t),n.child;case 6:return e===null&&VS(n),null;case 13:return T2(e,n,t);case 4:return Sx(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=dc(n,null,r,t):hn(e,n,r,t),n.child;case 11:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),NP(e,n,r,o,t);case 7:return hn(e,n,n.pendingProps,t),n.child;case 8:return hn(e,n,n.pendingProps.children,t),n.child;case 12:return hn(e,n,n.pendingProps.children,t),n.child;case 10:e:{if(r=n.type._context,o=n.pendingProps,s=n.memoizedProps,i=o.value,Ye(Zf,r._currentValue),r._currentValue=i,s!==null)if(Hr(s.value,i)){if(s.children===o.children&&!Dn.current){n=Jo(e,n,t);break e}}else for(s=n.child,s!==null&&(s.return=n);s!==null;){var a=s.dependencies;if(a!==null){i=s.child;for(var c=a.firstContext;c!==null;){if(c.context===r){if(s.tag===1){c=Ko(-1,t&-t),c.tag=2;var l=s.updateQueue;if(l!==null){l=l.shared;var d=l.pending;d===null?c.next=c:(c.next=d.next,d.next=c),l.pending=c}}s.lanes|=t,c=s.alternate,c!==null&&(c.lanes|=t),YS(s.return,t,n),a.lanes|=t;break}c=c.next}}else if(s.tag===10)i=s.type===n.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(q(341));i.lanes|=t,a=i.alternate,a!==null&&(a.lanes|=t),YS(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}hn(e,n,o.children,t),n=n.child}return n;case 9:return o=n.type,r=n.pendingProps.children,Qa(n,t),o=Pr(o),r=r(o),n.flags|=1,hn(e,n,r,t),n.child;case 14:return r=n.type,o=$r(r,n.pendingProps),o=$r(r.type,o),BP(e,n,r,o,t);case 15:return I2(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:$r(r,o),Ch(e,n),n.tag=1,Rn(r)?(e=!0,Yf(n)):e=!1,Qa(n,t),b2(n,r,o),qS(n,r,o,t),JS(null,n,r,!0,e,t);case 19:return $2(e,n,t);case 22:return E2(e,n,t)}throw Error(q(156,n.tag))};function G2(e,n){return vT(e,n)}function OH(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 xr(e,n,t,r){return new OH(e,n,t,r)}function jx(e){return e=e.prototype,!(!e||!e.isReactComponent)}function DH(e){if(typeof e=="function")return jx(e)?1:0;if(e!=null){if(e=e.$$typeof,e===Q0)return 11;if(e===J0)return 14}return 2}function Hs(e,n){var t=e.alternate;return t===null?(t=xr(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 _h(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")jx(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case $a:return Ai(t.children,o,s,n);case Z0:i=8,o|=8;break;case xS:return e=xr(12,t,n,o|2),e.elementType=xS,e.lanes=s,e;case wS:return e=xr(13,t,n,o),e.elementType=wS,e.lanes=s,e;case bS:return e=xr(19,t,n,o),e.elementType=bS,e.lanes=s,e;case nT:return Vp(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case eT:i=10;break e;case tT:i=9;break e;case Q0:i=11;break e;case J0:i=14;break e;case bs:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=xr(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function Ai(e,n,t,r){return e=xr(7,e,r,n),e.lanes=t,e}function Vp(e,n,t,r){return e=xr(22,e,r,n),e.elementType=nT,e.lanes=t,e.stateNode={isHidden:!1},e}function Km(e,n,t){return e=xr(6,e,null,n),e.lanes=t,e}function Wm(e,n,t){return n=xr(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function RH(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=Im(0),this.expirationTimes=Im(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Im(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function Ox(e,n,t,r,o,s,i,a,c){return e=new RH(e,n,t,a,c),n===1?(n=1,s===!0&&(n|=8)):n=0,s=xr(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},yx(s),e}function LH(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Ta,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function V2(e){if(!e)return Vs;e=e._reactInternals;e:{if(ra(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(Rn(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(Rn(t))return VT(e,t,n)}return n}function Y2(e,n,t,r,o,s,i,a,c){return e=Ox(t,r,!0,e,o,s,i,a,c),e.context=V2(null),t=e.current,r=gn(),o=Us(t),s=Ko(r,o),s.callback=n??null,Ns(t,s,o),e.current.lanes=o,Fd(e,o,r),Ln(e,r),e}function Yp(e,n,t,r){var o=n.current,s=gn(),i=Us(o);return t=V2(t),n.context===null?n.context=t:n.pendingContext=t,n=Ko(s,i),n.payload={element:e},r=r===void 0?null:r,r!==null&&(n.callback=r),e=Ns(o,n,i),e!==null&&(zr(e,o,i,s),wh(e,o,i)),i}function ap(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 JP(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function Dx(e,n){JP(e,n),(e=e.alternate)&&JP(e,n)}function FH(){return null}var X2=typeof reportError=="function"?reportError:function(e){console.error(e)};function Rx(e){this._internalRoot=e}Xp.prototype.render=Rx.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));Yp(e,n,null,null)};Xp.prototype.unmount=Rx.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Hi(function(){Yp(null,e,null,null)}),n[Zo]=null}};function Xp(e){this._internalRoot=e}Xp.prototype.unstable_scheduleHydration=function(e){if(e){var n=ET();e={blockedOn:null,target:e,priority:n};for(var t=0;t<Is.length&&n!==0&&n<Is[t].priority;t++);Is.splice(t,0,e),t===0&&kT(e)}};function Lx(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function qp(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function eC(){}function zH(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var l=ap(i);s.call(l)}}var i=Y2(n,r,e,0,null,!1,!1,"",eC);return e._reactRootContainer=i,e[Zo]=i.current,od(e.nodeType===8?e.parentNode:e),Hi(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var l=ap(c);a.call(l)}}var c=Ox(e,0,!1,null,null,!1,!1,"",eC);return e._reactRootContainer=c,e[Zo]=c.current,od(e.nodeType===8?e.parentNode:e),Hi(function(){Yp(n,c,t,r)}),c}function Zp(e,n,t,r,o){var s=t._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var c=ap(i);a.call(c)}}Yp(n,i,e,o)}else i=zH(t,n,e,o,r);return ap(i)}CT=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=wl(n.pendingLanes);t!==0&&(nx(n,t|1),Ln(n,bt()),!(Te&6)&&(fc=bt()+500,si()))}break;case 13:Hi(function(){var r=Qo(e,1);if(r!==null){var o=gn();zr(r,e,1,o)}}),Dx(e,1)}};rx=function(e){if(e.tag===13){var n=Qo(e,134217728);if(n!==null){var t=gn();zr(n,e,134217728,t)}Dx(e,134217728)}};IT=function(e){if(e.tag===13){var n=Us(e),t=Qo(e,n);if(t!==null){var r=gn();zr(t,e,n,r)}Dx(e,n)}};ET=function(){return ze};_T=function(e,n){var t=ze;try{return ze=e,n()}finally{ze=t}};AS=function(e,n,t){switch(n){case"input":if(IS(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=Bp(r);if(!o)throw Error(q(90));oT(r),IS(r,o)}}}break;case"textarea":iT(e,t);break;case"select":n=t.value,n!=null&&Ya(e,!!t.multiple,n,!1)}};fT=$x;pT=Hi;var NH={usingClientEntryPoint:!1,Events:[Nd,Oa,Bp,uT,hT,$x]},il={findFiberByHostInstance:bi,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},BH={bundleType:il.bundleType,version:il.version,rendererPackageName:il.rendererPackageName,rendererConfig:il.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:is.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=yT(e),e===null?null:e.stateNode},findFiberByHostInstance:il.findFiberByHostInstance||FH,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.3.1-next-f1338f8080-20240426"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var Du=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Du.isDisabled&&Du.supportsFiber)try{Lp=Du.inject(BH),uo=Du}catch{}}ar.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=NH;ar.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Lx(n))throw Error(q(200));return LH(e,n,null,t)};ar.createRoot=function(e,n){if(!Lx(e))throw Error(q(299));var t=!1,r="",o=X2;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=Ox(e,1,!1,null,null,t,!1,r,o),e[Zo]=n.current,od(e.nodeType===8?e.parentNode:e),new Rx(n)};ar.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(q(188)):(e=Object.keys(e).join(","),Error(q(268,e)));return e=yT(n),e=e===null?null:e.stateNode,e};ar.flushSync=function(e){return Hi(e)};ar.hydrate=function(e,n,t){if(!qp(n))throw Error(q(200));return Zp(null,e,n,!0,t)};ar.hydrateRoot=function(e,n,t){if(!Lx(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=X2;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=Y2(n,null,e,1,t??null,o,!1,s,i),e[Zo]=n.current,od(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 Xp(n)};ar.render=function(e,n,t){if(!qp(n))throw Error(q(200));return Zp(null,e,n,!1,t)};ar.unmountComponentAtNode=function(e){if(!qp(e))throw Error(q(40));return e._reactRootContainer?(Hi(function(){Zp(null,null,e,!1,function(){e._reactRootContainer=null,e[Zo]=null})}),!0):!1};ar.unstable_batchedUpdates=$x;ar.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!qp(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return Zp(e,n,t,!1,r)};ar.version="18.3.1-next-f1338f8080-20240426";function q2(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(q2)}catch(e){console.error(e)}}q2(),qk.exports=ar;var oa=qk.exports;const UH=Qs(oa);var uv={},Z2,tC=oa;Z2=uv.createRoot=tC.createRoot,uv.hydrateRoot=tC.hydrateRoot;const ec="TLDRAW_TAB_ID_v2",fo=globalThis.window;function HH(){return fo?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(fo.navigator.platform)||fo.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const cp=fo?fo[ec]??h_(ec)??"TLDRAW_INSTANCE_STATE_V1_"+st():"<error>";fo&&(fo[ec]=cp,HH()?_0(ec,cp):f_(ec));fo==null||fo.addEventListener("beforeunload",()=>{_0(ec,cp)});const Q2={Initial:0},Qp=Math.max(...Object.values(Q2));function KH(e){e.version<Q2.Initial,e.version=Qp}const J2=xe({version:he,currentPageId:Gl,isFocusMode:be,exportBackground:be,isDebugMode:be,isToolLocked:be,isGridMode:be,pageStates:Bt(xe({pageId:Gl,camera:xe({x:he,y:he,z:he}),selectedShapeIds:Bt(gr),focusedGroupId:gr.nullable()}))});function WH(e){if(!e||typeof e!="object")return console.warn("Invalid instance state"),null;if(!("version"in e)||typeof e.version!="number")return console.warn("No version in instance state"),null;e.version!==Qp&&(e=ot(e),KH(e));try{return J2.validate(e)}catch(n){return console.warn(n),null}}function e$(e){const n=e.query.ids("page");return V("sessionStateSnapshot",()=>{const t=e.get(pn);if(!t)return null;const r=[...n.get()];return{version:Qp,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(Rr.createId(o)),i=e.get(io.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 t$(e,n){const t=WH(n);if(!t)return;const r=e.schema.types.instance.create({id:pn,...H_(e.get(pn)),currentPageId:t.currentPageId,isDebugMode:t.isDebugMode,isFocusMode:t.isFocusMode,isToolLocked:t.isToolLocked,isGridMode:t.isGridMode,exportBackground:t.exportBackground}),o=e.allRecords().filter(s=>s.typeName==="instance_page_state"||s.typeName==="camera");e.atomic(()=>{e.remove(o.map(s=>s.id));for(const s of t.pageStates)e.put([io.create({id:io.createId(s.pageId),x:s.camera.x,y:s.camera.y,z:s.camera.z}),Rr.create({id:Rr.createId(s.pageId),pageId:s.pageId,selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId})]);e.put([r]),e.ensureStoreIsUsable()})}function GH(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!==pn)[0];if(!t)return null;const r={version:Qp,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 J2.validate(r),r}catch{return null}}function n$(e,n){let t={};if("store"in n){const o=e.schema.migrateStoreSnapshot(n);if(o.type!=="success")throw new Error("Failed to migrate store snapshot: "+o.reason);t.document={schema:e.schema.serialize(),store:El(o.value,(s,{typeName:i})=>e.scopedTypes.document.has(i))}}else t=n;const r=H_(e.get(pn));e.atomic(()=>{t.document&&e.loadStoreSnapshot(t.document),r&&e.update(pn,o=>({...o,...r})),t.session&&t$(e,t.session)})}const VH=new Yo;function YH(e){const t=VH.get(e,e$).get();if(!t)throw new Error("Session state is not ready yet");return{document:e.getStoreSnapshot(),session:t}}function r$(e){const n=[],t=new Set;for(const r of e){if(t.has(r.type))throw new Error(`Binding type "${r.type}" is defined more than once`);n.push(r),t.add(r.type)}return n}function Ys({children:e,className:n="",...t}){return h.jsx("svg",{...t,className:de("tl-svg-container",n),children:e})}function Fx(e,n,t,r){const o=e.x-t.x,s=e.y-t.y,i=r.x-t.x,a=r.y-t.y,c=n.x-e.x,l=n.y-e.y,d=i*s-a*o,u=c*s-l*o,f=a*c-i*l;if(d===0||u===0||f===0)return null;if(f!==0){const p=d/f,S=u/f;if(0<=p&&p<=1&&0<=S&&S<=1)return b.AddXY(e,p*c,p*l)}return null}function Ud(e,n,t,r){const o=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),s=2*((n.x-e.x)*(e.x-t.x)+(n.y-e.y)*(e.y-t.y)),i=t.x*t.x+t.y*t.y+e.x*e.x+e.y*e.y-2*(t.x*e.x+t.y*e.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const c=Math.sqrt(a),l=(-s+c)/(2*o),d=(-s-c)/(2*o);if((l<0||l>1)&&(d<0||d>1))return null;const u=[];return 0<=l&&l<=1&&u.push(b.Lrp(e,n,l)),0<=d&&d<=1&&u.push(b.Lrp(e,n,d)),u.length===0?null:u}function XH(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=Fx(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function zx(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=Fx(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function qH(e,n,t,r){let o=t.x-e.x,s=t.y-e.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+n*n)/(2*i),c=Math.sqrt(n*n-a*a);return o/=i,s/=i,[new b(e.x+o*a-s*c,e.y+s*a+o*c),new b(e.x+o*a+s*c,e.y+s*a-o*c)]}function hv(e,n,t){const r=[];let o,s,i;for(let a=0,c=t.length;a<c;a++)o=t[a],s=t[(a+1)%t.length],i=Ud(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function nC(e,n,t){const r=[];let o,s,i;for(let a=1,c=t.length;a<c;a++)o=t[a-1],s=t[a],i=Ud(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function Ru(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function Nx(e,n,t,r){return Ru(e,t,r)!==Ru(n,t,r)&&Ru(e,n,t)!==Ru(e,n,r)}function rC(e,n){const t=new Map;let r,o,s,i;for(let a=0,c=e.length;a<c;a++)if(r=e[a],Jn(r,n)){const l=Gm(r);t.has(l)||t.set(l,r)}for(let a=0,c=n.length;a<c;a++)if(r=n[a],Jn(r,e)){const l=Gm(r);t.has(l)||t.set(l,r)}for(let a=0,c=e.length;a<c;a++){r=e[a],o=e[(a+1)%e.length];for(let l=0,d=n.length;l<d;l++){s=n[l],i=n[(l+1)%n.length];const u=Fx(r,o,s,i);if(u!==null){const f=Gm(u);t.has(f)||t.set(f,u)}}}return t.size===0?null:ZH([...t.values()])}function Gm(e){return`${e.x},${e.y}`}function ZH(e){const n=b.Average(e);return e.sort((t,r)=>b.Angle(n,t)-b.Angle(n,r))}function o$(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let c=0,l=n.length;c<l;c++)if(o=n[c],s=n[(c+1)%l],Nx(t,r,o,s))return!0}return!1}function QH(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let c=1,l=n.length;c<l;c++)if(o=n[c-1],s=n[c],Nx(t,r,o,s))return!0}return!1}class Bo extends ni{constructor(t){super({...t,isClosed:!1,isFilled:!1});m(this,"start");m(this,"end");m(this,"d");m(this,"u");m(this,"ul");const{start:r,end:o}=t;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}getLength(){return this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(t){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=b.Sub(t,r).dpr(s)/i,c=r.x+s.x*a;if(c<Math.min(r.x,o.x))return r.x<o.x?r:o;if(c>Math.max(r.x,o.x))return r.x>o.x?r:o;const l=r.y+s.y*a;return l<Math.min(r.y,o.y)?r.y<o.y?r:o:l>Math.max(r.y,o.y)?r.y>o.y?r:o:new b(c,l)}hitTestLineSegment(t,r,o=0){return Nx(t,r,this.start,this.end)||this.distanceToLineSegment(t,r)<=o}getSvgPathData(t=!0){const{start:r,end:o}=this;return`${t?`M${r.toFixed()}`:""} L${o.toFixed()}`}}class jc extends ni{constructor(t){super({isClosed:!1,isFilled:!1,...t});m(this,"points");m(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:t}=this;for(let r=0,o=t.length-1;r<o;r++){const s=t[r],i=t[r+1];this._segments.push(new Bo({start:s,end:i}))}this.isClosed&&this._segments.push(new Bo({start:t[t.length-1],end:t[0]}))}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){return this.points}nearestPoint(t){const{segments:r}=this;let o=this.points[0],s=1/0,i,a;for(let c=0;c<r.length;c++)i=r[c].nearestPoint(t),a=b.Dist2(i,t),a<s&&(o=i,s=a);if(!o)throw Error("nearest point not found");return o}hitTestLineSegment(t,r,o=0){const{segments:s}=this;for(let i=0,a=s.length;i<a;i++)if(s[i].hitTestLineSegment(t,r,o))return!0;return!1}getSvgPathData(){const{vertices:t}=this;return t.length<2?"":t.reduce((r,o,s)=>s===0?`M ${o.x} ${o.y}`:`${r} L ${o.x} ${o.y}`,"")}}class xt extends jc{constructor(n){super({...n}),this.isClosed=!0}}class es extends xt{constructor(t){const{x:r=0,y:o=0,width:s,height:i}=t;super({...t,points:[new b(r,o),new b(r+s,o),new b(r+s,o+i),new b(r,o+i)]});m(this,"x");m(this,"y");m(this,"w");m(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new J(this.x,this.y,this.w,this.h)}getSvgPathData(){const{x:t,y:r,w:o,h:s}=this;return`M${t},${r} h${o} v${s} h-${o}z`}}class Nr{constructor(n){m(this,"canSnap",()=>!0);m(this,"canScroll",()=>!1);m(this,"canEdit",()=>!1);m(this,"canResize",()=>!0);m(this,"canEditInReadOnly",()=>!1);m(this,"canCrop",()=>!1);m(this,"canBeLaidOut",()=>!0);m(this,"hideResizeHandles",()=>!1);m(this,"hideRotateHandle",()=>!1);m(this,"hideSelectionBoundsBg",()=>!1);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"isAspectRatioLocked",()=>!1);m(this,"onBeforeCreate");m(this,"onBeforeUpdate");m(this,"onDragShapesOver");m(this,"onDragShapesOut");m(this,"onDropShapesOver");m(this,"onResizeStart");m(this,"onResize");m(this,"onResizeEnd");m(this,"onTranslateStart");m(this,"onTranslate");m(this,"onTranslateEnd");m(this,"onHandleDrag");m(this,"onRotateStart");m(this,"onRotate");m(this,"onRotateEnd");m(this,"onBindingChange");m(this,"onChildrenChange");m(this,"onDoubleClickHandle");m(this,"onDoubleClickEdge");m(this,"onDoubleClick");m(this,"onClick");m(this,"onEditEnd");this.editor=n}canBind(n){return!0}providesBackgroundForChildren(n){return!1}canReceiveNewChildrenOfType(n,t){return!1}canDropShapes(n,t){return!1}expandSelectionOutlinePx(n){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(n){return{}}getHandleSnapGeometry(n){return{}}}m(Nr,"props"),m(Nr,"migrations"),m(Nr,"type");function JH(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:c="dashed"}=t;let l=0,d=0,u=1,f=0,p=0;switch(c){case"dashed":{u=1,l=Math.min(n*a,e/4);break}case"dotted":{u=100,l=n/u;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=l/2,p+=l/2):s==="skip"&&(e-=l,p-=l),i==="outset"?e+=l/2:i==="skip"&&(e-=l)),d=Math.floor(e/l/(2*u)),d-=d%o,d<3&&c==="dashed"?e/n<5?(l=e,d=1,f=0):(l=e*.333,f=e*.333):(d=Math.max(d,3),l=e/d/(2*u),r?(p=l/2,f=(e-d*l)/d):f=(e-d*l)/Math.max(1,d-1)),{strokeDasharray:[l,f].join(" "),strokeDashoffset:p.toString()}}function oC({bounds:e,className:n}){const t=N(),r=W("zoom level",()=>t.getZoomLevel(),[t]);return h.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=JH(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return h.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class kh extends Nr{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"canBind",()=>!1);m(this,"onChildrenChange",t=>{const r=this.editor.getSortedChildIdsForParent(t.id);if(r.length===0){this.editor.getCurrentPageState().focusedGroupId===t.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([t.id]);return}else if(r.length===1){this.editor.getCurrentPageState().focusedGroupId===t.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(r,t.parentId),this.editor.deleteShapes([t.id]);return}})}getDefaultProps(){return{}}getGeometry(t){const r=this.editor.getSortedChildIdsForParent(t.id);return r.length===0?new es({width:1,height:1,isFilled:!1}):new Ur({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 xt({points:a,isFilled:!0}):new jc({points:a})})})}component(t){const r=this.editor.getErasingShapeIds().includes(t.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(c=>c!==t.id&&this.editor.isShapeOfType(this.editor.getShape(c),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==t.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(t).bounds;return h.jsx(Ys,{id:t.id,children:h.jsx(oC,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return h.jsx(oC,{className:"",bounds:r})}}m(kh,"type","group"),m(kh,"props",tk),m(kh,"migrations",nk);const s$=[kh],eK=new Set(s$.map(e=>e.type));function i$(e){const n=[...s$],t=new Set;for(const r of e){if(eK.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(t.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);n.push(r),t.add(r.type)}return n}const tK={maxShapesPerPage:4e3,maxPages:40,animationMediumMs:320,followChaseViewportSnap:2,doubleClickDurationMs:450,multiClickDurationMs:200,coarseDragDistanceSquared:36,dragDistanceSquared:16,defaultSvgPadding:32,cameraSlideFriction:.09,maxPointsPerDrawShape:500,gridSteps:[{min:-1,mid:.15,step:64},{min:.05,mid:.375,step:16},{min:.15,mid:1,step:4},{min:.7,mid:2.5,step:1}],collaboratorInactiveTimeoutMs:6e4,collaboratorIdleTimeoutMs:3e3,collaboratorCheckIntervalMs:1200,cameraMovingTimeoutMs:64,hitTestMargin:8,edgeScrollDelay:200,edgeScrollEaseDuration:200,edgeScrollSpeed:25,edgeScrollDistance:8,coarsePointerWidth:12,coarseHandleRadius:20,handleRadius:12,longPressDurationMs:500,textShadowLod:.35,adjacentShapeMargin:10,flattenImageBoundsExpand:64,flattenImageBoundsPadding:16};function sC(e,n){if(!n)return!1;switch(e.type){case"mixed":return n.type==="mixed";case"shared":return n.type==="shared"&&e.value===n.value;default:throw sn(e)}}class nK{constructor(n){m(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(!sC(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!sC(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 fv extends nK{set(n,t){this.map.set(n,t)}applyValue(n,t){const r=this.get(n);if(!r){this.set(n,{type:"shared",value:t});return}switch(r.type){case"mixed":return;case"shared":r.value!==t&&this.set(n,{type:"mixed"});return;default:sn(r,"type")}}}function rK(e,n,t){return go(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function oK(e,n){var o;let t=e;const r=new Set(n);for(;r.has(t);)t=(o=/^.*(\d+)$/.exec(t))!=null&&o[1]?t.replace(/(\d+)(?=\D?)$/,s=>(+s+1).toString()):`${t} 1`;return t}function Lu(e,n,t){if(t.length===0)return[];const r=new Map;for(const s of Se(t.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:Se(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})=>sK(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>iK(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>aK(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>cK(s,i,o));break}}return o}function sK(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=ic(o,s,e.size);t.push(...Array.from(e.values()).sort(rn).map((a,c)=>({...a,index:i[c]})))}}function iK(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=ic(o,s,e.size);t.push(...Array.from(e.values()).sort(rn).map((a,c)=>({...a,index:i[c]})))}}function aK(e,n,t){var s;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(n[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:c}=o;ic(n[i].index,(s=n[i+1])==null?void 0:s.index,i-c).forEach((l,d)=>t.push({...n[c+d],index:l})),o={name:"skipping"};break}}}}function cK(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;ic((s=n[i-1])==null?void 0:s.index,n[i].index,o.selectIndex-i).forEach((c,l)=>{t.push({...n[i+l+1],index:c})}),o={name:"skipping"};break}}}}function a$({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:ot(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function Th({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:c})=>{const l=In(a.parentId)?n.getShapePageTransform(a.parentId):oe.Identity(),d=b.RotWith(c,o,e),u=oe.applyToPoint(oe.Inverse(l),d),f=Ds(a.rotation+e);return{id:a.id,type:a.type,x:u.x,y:u.y,rotation:f}}));const i=[];s.forEach(({shape:a})=>{var u,f,p;const c=n.getShape(a.id);if(!c)return;const l=n.getShapeUtil(a);if(r==="start"||r==="one-off"){const S=(u=l.onRotateStart)==null?void 0:u.call(l,a);S&&i.push(S)}const d=(f=l.onRotate)==null?void 0:f.call(l,a,c);if(d&&i.push(d),r==="end"||r==="one-off"){const S=(p=l.onRotateEnd)==null?void 0:p.call(l,a,c);S&&i.push(S)}}),i.length>0&&n.updateShapes(i)}const lK=e=>{const{store:n}=e,t=n.query.filterHistory("binding"),r=n.query.records("binding");function o(){const s=r.get(),i=new Map;for(const a of s){const{fromId:c,toId:l}=a,d=i.get(c);d?d.push(a):i.set(c,[a]);const u=i.get(l);u?u.push(a):i.set(l,[a])}return i}return V("arrowBindingsIndex",(s,i)=>{if(Ti(s))return o();const a=s,c=t.getDiffSince(i);if(c===Zn)return o();let l;function d(p){l??(l=new Map(a));const S=l.get(p.fromId),g=S==null?void 0:S.filter(v=>v.id!==p.id);g!=null&&g.length?l.set(p.fromId,g):l.delete(p.fromId);const w=l.get(p.toId),y=w==null?void 0:w.filter(v=>v.id!==p.id);y!=null&&y.length?l.set(p.toId,y):l.delete(p.toId)}function u(p){l??(l=new Map(a));let S=l.get(p);return S?S===a.get(p)&&(S=S.slice(0),l.set(p,S)):(S=[],l.set(p,S)),S}function f(p){u(p.fromId).push(p),u(p.toId).push(p)}for(const p of c){for(const S of yt(p.added))f(S);for(const[S,g]of yt(p.updated))d(S),f(g);for(const S of yt(p.removed))d(S)}return l??a})};function dK(e,n,t){const r=e.getShapeMaskedPageBounds(n);return r===void 0?!0:!t.includes(r)}const uK=e=>{function n(t){const r=t.getCurrentPageShapeIds(),o=t.getViewportPageBounds(),s=new Set;return r.forEach(i=>{dK(t,i,o)&&s.add(i)}),s}return V("getCulledShapes",t=>{if(Ti(t))return n(e);const r=n(e);if(t.size!==r.size)return r;for(const o of t)if(!r.has(o))return r;return t})},hK=e=>{const n=e.query.ids("shape"),t=e.query.filterHistory("shape");function r(){const o={},s=n.get(),i=Array(s.size);return s.forEach(a=>i.push(e.get(a))),i.sort(rn),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return V("parentsToChildrenWithIndexes",(o,s)=>{if(Ti(o))return r();const i=t.getDiffSince(s);if(i===Zn)return r();if(i.length===0)return o;let a=null;const c=u=>{a||(a={...o}),a[u]?a[u]===o[u]&&(a[u]=[...a[u]]):a[u]=[]},l=new Set;let d;for(let u=0,f=i.length;u<f;u++){d=i[u];for(const p of Object.values(d.added))ka(p)&&(c(p.parentId),a[p.parentId].push(p.id),l.add(a[p.parentId]));for(const[p,S]of Object.values(d.updated))if(ka(S)&&ka(p)){if(p.parentId!==S.parentId)c(p.parentId),c(S.parentId),a[p.parentId].splice(a[p.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),l.add(a[S.parentId]);else if(p.index!==S.index){c(S.parentId);const g=a[S.parentId].indexOf(S.id);a[S.parentId][g]=S.id,l.add(a[S.parentId])}}for(const p of Object.values(d.removed))ka(p)&&(c(p.parentId),a[p.parentId].splice(a[p.parentId].indexOf(p.id),1))}for(const u of l){const f=Se(u.map(p=>e.get(p)));f.sort(rn),u.splice(0,u.length,...f.map(p=>p.id))}return a??o})},Vm=(e,n,t)=>{for(;!Pn(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},fK=(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=>Vm(e,s,e.get(i))))}return V("_shapeIdsInCurrentPage",(s,i)=>{if(Ti(s))return o();const a=n();if(a!==r)return o();const c=e.history.getDiffSince(i);if(c===Zn)return o();const l=new fh(s);for(const u of c){for(const f of Object.values(u.added))ka(f)&&Vm(e,a,f)&&l.add(f.id);for(const[f,p]of Object.values(u.updated))ka(p)&&(Vm(e,a,p)?l.add(p.id):l.remove(p.id));for(const f of Object.keys(u.removed))In(f)&&l.remove(f)}const d=l.get();return d?Sl(d.value,d.diff):s})},c$=x.createContext(null);function pK({context:e,editor:n,children:t}){return h.jsx(Rp.Provider,{value:n,children:h.jsx(c$.Provider,{value:e,children:t})})}function l$(){const e=x.useContext(c$);return e?{isDarkMode:e.isDarkMode}:null}async function gK(e,n,t={}){var I,C;const r=typeof n[0]=="string"?n:n.map(_=>_.id);if(r.length===0)return;if(!window.document)throw Error("No document");const{scale:o=1,background:s=!1,padding:i=e.options.defaultSvgPadding,preserveAspectRatio:a=!1}=t,c=t.darkMode??e.user.getIsDarkMode(),l=ss({isDarkMode:c}),d=e.getShapeAndDescendantIds(r),u=e.getUnorderedRenderingShapes(!1).filter(({id:_})=>d.has(_));let f=null;if(t.bounds)f=t.bounds;else for(const{id:_}of u){const k=e.getShapeMaskedPageBounds(_);k&&(f?f.union(k):f=k.clone())}if(!f)return;const p=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;p||f.expandBy(i);const S=f.width*o,g=f.height*o;try{(C=(I=document.body).focus)==null||C.call(I)}catch{}const w=[],y=new Map,v={isDarkMode:c,addExportDef:_=>{if(y.has(_.key))return;const k=(async()=>{const j=await _.getElement();j&&w.push(h.jsx(x.Fragment,{children:j},w.length))})();y.set(_.key,k)}},P=(await Promise.all(u.map(async({id:_,opacity:k,index:j,backgroundIndex:T})=>{var B,U;if(_===p)return[];const M=e.getShape(_);if(e.isShapeOfType(M,"group"))return[];const R=e.getShapeUtil(M);let A=await((B=R.toSvg)==null?void 0:B.call(R,M,v)),O=await((U=R.toBackgroundSvg)==null?void 0:U.call(R,M,v));if(!A&&!O){const Y=e.getShapePageBounds(M);A=h.jsx("rect",{width:Y.w,height:Y.h,fill:l.solid,stroke:l.grey.pattern,strokeWidth:1})}let L=e.getShapePageTransform(M).toCssString();"scale"in M.props&&M.props.scale!==1&&(L=`${L} scale(${M.props.scale}, ${M.props.scale})`),A&&(A=h.jsx("g",{transform:L,opacity:k,children:A},M.id)),O&&(O=h.jsx("g",{transform:L,opacity:k,children:O},`bg_${M.id}`));const G=e.getShapeMask(M.id);if(G){const Y=`mask_${M.id.replace(":","_")}`;w.push(h.jsx("clipPath",{id:Y,children:h.jsx("path",{d:`M${G.map(({x:Q,y:le})=>`${Q},${le}`).join("L")}Z`})},w.length)),A&&(A=h.jsx("g",{clipPath:`url(#${Y})`,children:A},M.id)),O&&(O=h.jsx("g",{clipPath:`url(#${Y})`,children:O},`bg_${M.id}`))}const K=[];return A&&K.push({zIndex:j,element:A}),O&&K.push({zIndex:T,element:O}),K}))).flat();return await Promise.all(y.values()),{jsx:h.jsx(pK,{editor:e,context:v,children:h.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:S,height:g,viewBox:`${f.minX} ${f.minY} ${f.width} ${f.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?p?l.solid:l.background:"transparent"},children:[h.jsx("defs",{children:w}),P.sort((_,k)=>_.zIndex-k.zIndex).map(({element:_})=>_)]})}),width:S,height:g}}const mK=40;class yK{constructor(n){m(this,"_clickId","");m(this,"_clickTimeout");m(this,"_clickScreenPoint");m(this,"_previousScreenPoint");m(this,"_getClickTimeout",(n,t=st())=>{this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===n&&this._clickId===t){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},n==="idle"||n==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)});m(this,"_clickState","idle");m(this,"lastPointerInfo",{});m(this,"handlePointerEvent",n=>{switch(n.name){case"pointer_down":{if(!this._clickState)return n;switch(this._clickScreenPoint=b.From(n.point),this._previousScreenPoint&&b.Dist2(this._previousScreenPoint,this._clickScreenPoint)>mK**2&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=n,this._clickState){case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...n,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...n,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...n,type:"click",name:"quadruple_click",phase:"down"};case"idle":{this._clickState="pendingDouble";break}case"pendingOverflow":{this._clickState="overflow";break}}return this._clickTimeout=this._getClickTimeout(this._clickState),n}case"pointer_up":{if(!this._clickState)return n;switch(this._clickScreenPoint=b.From(n.point),this._clickState){case"pendingTriple":return{...this.lastPointerInfo,type:"click",name:"double_click",phase:"up"};case"pendingQuadruple":return{...this.lastPointerInfo,type:"click",name:"triple_click",phase:"up"};case"pendingOverflow":return{...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"up"}}return n}case"pointer_move":return this._clickState!=="idle"&&this._clickScreenPoint&&b.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),n}return n});m(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});this.editor=n}get clickState(){return this._clickState}}class SK{constructor(n){m(this,"_isEdgeScrolling",!1);m(this,"_edgeScrollDuration",-1);this.editor=n}updateEdgeScrolling(n){const{editor:t}=this,r=this.getEdgeScroll();if(r.x===0&&r.y===0)this._isEdgeScrolling&&(this._isEdgeScrolling=!1,this._edgeScrollDuration=0);else if(this._isEdgeScrolling||(this._isEdgeScrolling=!0,this._edgeScrollDuration=0),this._edgeScrollDuration+=n,this._edgeScrollDuration>t.options.edgeScrollDelay){const o=t.options.edgeScrollEaseDuration>0?At.easeInCubic(Math.min(1,this._edgeScrollDuration/(t.options.edgeScrollDelay+t.options.edgeScrollEaseDuration))):1;this.moveCameraWhenCloseToEdge({x:r.x*o,y:r.y*o})}}getEdgeProximityFactors(n,t,r,o,s){const{editor:i}=this,a=i.options.edgeScrollDistance,c=r?i.options.coarsePointerWidth:0,l=n-c,d=n+c,u=o?0:a,f=s?t:t-a;return l<u?Math.min(1,(u-l)/a):d>f?-Math.min(1,(d-f)/a):0}getEdgeScroll(){const{editor:n}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=n,o=n.getViewportScreenBounds(),{isCoarsePointer:s,insets:[i,a,c,l]}=n.getInstanceState(),d=this.getEdgeProximityFactors(t,o.w,s,l,a),u=this.getEdgeProximityFactors(r,o.h,s,i,c);return{x:d,y:u}}moveCameraWhenCloseToEdge(n){const{editor:t}=this;if(!t.inputs.isDragging||t.inputs.isPanning||t.getCameraOptions().isLocked||n.x===0&&n.y===0)return;const r=t.getViewportScreenBounds(),o=r.w<1e3?.612:1,s=r.h<1e3?.612:1,i=t.getZoomLevel(),a=t.user.getEdgeScrollSpeed()*t.options.edgeScrollSpeed,c=a*n.x*o/i,l=a*n.y*s/i,{x:d,y:u,z:f}=t.getCamera();t.setCamera(new b(d+c,u+l,f))}}class vK{constructor(n){m(this,"isSafari");m(this,"isIos");m(this,"isChromeForIos");m(this,"isFirefox");m(this,"isAndroid");this.editor=n,typeof window<"u"&&"navigator"in window?(this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),this.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),this.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),this.isFirefox=/firefox/i.test(navigator.userAgent),this.isAndroid=/android/i.test(navigator.userAgent)):(this.isSafari=!1,this.isIos=!1,this.isChromeForIos=!1,this.isFirefox=!1,this.isAndroid=!1)}}class xK{constructor(n,t){m(this,"disposeSideEffectListener");this.editor=n,this.disposeSideEffectListener=n.sideEffects.registerAfterChangeHandler("instance",(o,s)=>{o.isFocused!==s.isFocused&&(s.isFocused?this.focus():this.blur(),this.updateContainerClass())});const r=n.getInstanceState().isFocused;t!==r&&n.updateInstanceState({isFocused:!!t}),this.updateContainerClass()}updateContainerClass(){const n=this.editor.getContainer();this.editor.getInstanceState().isFocused?n.classList.add("tl-container__focused"):n.classList.remove("tl-container__focused")}focus(){this.editor.getContainer().focus()}blur(){this.editor.complete(),this.editor.getContainer().blur()}dispose(){var n;(n=this.disposeSideEffectListener)==null||n.call(this)}}function al(e){return bK}class wK{constructor(){m(this,"length",0);m(this,"head",null);m(this,"tail",this)}push(n){return new Bx(n,this)}toArray(){return Ho}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const bK=new wK;class Bx{constructor(n,t){m(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Bx(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 PK{constructor(n){m(this,"store");m(this,"dispose");m(this,"state","recording");m(this,"pendingDiff",new IK);m(this,"stacks",Mt("HistoryManager.stacks",{undos:al(),redos:al()},{isEqual:(n,t)=>n.undos===t.undos&&n.redos===t.redos}));m(this,"annotateError");m(this,"onBatchComplete",()=>{});m(this,"_isInBatch",!1);m(this,"batch",(n,t)=>{const r=this.state;r!=="paused"&&(t!=null&&t.history)&&(this.state=CK[t.history]);try{if(this._isInBatch)return n(),this;this._isInBatch=!0;try{As(()=>{n(),this.onBatchComplete()})}catch(o){throw this.annotateError(o),o}finally{this._isInBatch=!1}return this}finally{this.state=r}});m(this,"_undo",({pushToRedoStack:n,toMark:t=void 0})=>{var o;const r=this.state;this.state="paused";try{let{undos:s,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),c=y_(a),l=lS(a);n&&!c&&(i=i.push({type:"diff",diff:a}));let d=!1;if(c)for(;((o=s.head)==null?void 0:o.type)==="stop";){const u=s.head;if(s=s.tail,n&&(i=i.push(u)),u.id===t){d=!0;break}}if(!d)e:for(;s.head;){const u=s.head;switch(s=s.tail,n&&(i=i.push(u)),u.type){case"diff":_l(l,[lS(u.diff)]);break;case"stop":if(!t||u.id===t)break e;break;default:sn(u)}}this.store.applyDiff(l,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:s,redos:i})}finally{this.state=r}return this});m(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));m(this,"redo",()=>{var t;const n=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:o}=this.stacks.get();if(o.length===0)return this;for(;((t=o.head)==null?void 0:t.type)==="stop";)r=r.push(o.head),o=o.tail;const s=vf();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")_l(s,[i.diff]);else break}this.store.applyDiff(s,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:o})}finally{this.state=n}return this});m(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));m(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));m(this,"squashToMark",n=>{var s;let t=this.stacks.get().undos;const r=[];for(;t.head&&!(t.head.type==="stop"&&t.head.id===n);)t.head.type==="diff"&&r.push(t.head.diff),t=t.tail;if(!t.head||((s=t.head)==null?void 0:s.id)!==n)return console.error("Could not find mark to squash to: ",n),this;if(r.length===0)return this;const o=vf();return _l(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:t.push({type:"diff",diff:o}),redos:i})),this});m(this,"mark",(n=st())=>(As(()=>{this.flushPendingDiff(),this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"stop",id:n}),redos:r}))}),n));this.store=n.store,this.annotateError=n.annotateError??Sf,this.dispose=this.store.addHistoryInterceptor((t,r)=>{if(r==="user")switch(this.state){case"recording":this.pendingDiff.apply(t.changes),this.stacks.update(({undos:o})=>({undos:o,redos:al()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:sn(this.state)}})}flushPendingDiff(){if(this.pendingDiff.isEmpty())return;const n=this.pendingDiff.clear();this.stacks.update(({undos:t,redos:r})=>({undos:t.push({type:"diff",diff:n}),redos:r}))}getNumUndos(){return this.stacks.get().undos.length+(this.pendingDiff.isEmpty()?0:1)}getNumRedos(){return this.stacks.get().redos.length}ignore(n){return this.batch(n,{history:"ignore"})}clear(){this.stacks.set({undos:al(),redos:al()}),this.pendingDiff.clear()}debug(){const{undos:n,redos:t}=this.stacks.get();return{undos:n.toArray(),redos:t.toArray(),pendingDiff:this.pendingDiff.debug(),state:this.state}}}const CK={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class IK{constructor(){m(this,"diff",vf());m(this,"isEmptyAtom",Mt("PendingDiff.isEmpty",!0))}clear(){const n=this.diff;return this.diff=vf(),this.isEmptyAtom.set(!0),n}isEmpty(){return this.isEmptyAtom.get()}apply(n){_l(this.diff,[n]),this.isEmptyAtom.set(y_(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class EK{constructor(n){m(this,"scribbleItems",new Map);m(this,"state","paused");m(this,"addScribble",(n,t=st())=>{const r={id:t,scribble:{id:t,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...n,state:"starting"},timeoutMs:0,delayRemaining:n.delay??0,prev:null,next:null};return this.scribbleItems.set(t,r),r});m(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});m(this,"addPoint",(n,t,r)=>{const o=this.scribbleItems.get(n);if(!o)throw Error(`Scribble with id ${n} not found`);const{prev:s}=o,i={x:t,y:r,z:.5};return(!s||b.Dist(s,i)>=1)&&(o.next=i),o});m(this,"tick",n=>{this.scribbleItems.size!==0&&this.editor.batch(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:c,prev:l}=t;c&&c!==l&&(t.prev=c,t.scribble.points.push(c)),t.scribble.points.length>8&&(t.scribble.state="active");return}t.delayRemaining>0&&(t.delayRemaining=Math.max(0,t.delayRemaining-n)),t.timeoutMs+=n,t.timeoutMs>=16&&(t.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=t;switch(a.state){case"active":{i&&i!==s?(t.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(t.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:t})=>({...t,points:[...t.points]})).slice(-5)})})});this.editor=n}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}}var _K=Object.defineProperty,kK=Object.getOwnPropertyDescriptor,Jp=(e,n,t,r)=>{for(var o=kK(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&_K(n,t,o),o};const ue=e=>Math.round(e*10**8)/10**8;function jo(e,n,t,r,o){const s=e.filter(a=>(r==="forward"?a.startNode.id===n:a.endNode.id===n)&&ue(a.length)===ue(t)&&Mr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const c=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(c)){i.add(c);const l=jo(e,c,t,r,Mr(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...l)}}),s}function TK(e){e.sort((n,t)=>t.gaps.length-n.gaps.length);for(let n=e.length-1;n>0;n--){const t=e[n];for(let r=n-1;r>=0;r--){const o=e[r];if(o.direction===t.direction&&t.gaps.every(s=>o.gaps.some(i=>ue(s.startEdge[0].x)===ue(i.startEdge[0].x)&&ue(s.startEdge[0].y)===ue(i.startEdge[0].y)&&ue(s.startEdge[1].x)===ue(i.startEdge[1].x)&&ue(s.startEdge[1].y)===ue(i.startEdge[1].y))&&o.gaps.some(i=>ue(s.endEdge[0].x)===ue(i.endEdge[0].x)&&ue(s.endEdge[0].y)===ue(i.endEdge[0].y)&&ue(s.endEdge[1].x)===ue(i.endEdge[1].x)&&ue(s.endEdge[1].y)===ue(i.endEdge[1].y)))){e.splice(n,1);break}}}}class Hd{constructor(n){m(this,"editor");this.manager=n,this.editor=n.editor}getSnapPointsCache(){const{editor:n}=this;return n.store.createComputedCache("snapPoints",t=>{const r=n.getShapePageTransform(t.id);if(!r)return;const s=n.getShapeUtil(t).getBoundsSnapGeometry(t).points??n.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:c,y:l}=oe.applyToPoint(r,i);return{x:c,y:l,id:`${t.id}:${a}`}})})}getSnapPoints(n){return this.getSnapPointsCache().get(n)??[]}getSnappablePoints(){const n=this.getSnapPointsCache(),t=this.manager.getSnappableShapes(),r=[];for(const o of t){const s=n.get(o);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),n=>({id:n,pageBounds:mr(this.editor.getShapePageBounds(n))}))}getVisibleGaps(){const n=[],t=[];let r,o;const s=this.getSnappableGapNodes().sort((a,c)=>a.pageBounds.minX-c.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let c=a+1;c<s.length;c++)o=s[c],r.pageBounds.maxX<o.pageBounds.minX&&Qc(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&n.push({startNode:r,endNode:o,startEdge:[new b(r.pageBounds.maxX,r.pageBounds.minY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(o.pageBounds.minX,o.pageBounds.minY),new b(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Mr(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,c)=>a.pageBounds.minY-c.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let c=a+1;c<i.length;c++)o=i[c],r.pageBounds.maxY<o.pageBounds.minY&&Qc(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&t.push({startNode:r,endNode:o,startEdge:[new b(r.pageBounds.minX,r.pageBounds.maxY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(o.pageBounds.minX,o.pageBounds.minY),new b(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Mr(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:n,vertical:t}}snapTranslateShapes({lockedAxis:n,initialSelectionPageBounds:t,initialSelectionSnapPoints:r,dragDelta:o}){var w,y;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(o),c=r.map(({x:v,y:P},E)=>({id:"selection:"+E,x:v+o.x,y:P+o.y})),l=i,d=[],u=[],f=new b(s,s);this.collectPointSnaps({minOffset:f,nearestSnapsX:d,nearestSnapsY:u,otherNodeSnapPoints:l,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:u,minOffset:f});const p=new b(n==="x"?0:((w=d[0])==null?void 0:w.nudge)??0,n==="y"?0:((y=u[0])==null?void 0:y.nudge)??0);f.x=0,f.y=0,d.length=0,u.length=0,c.forEach(v=>{v.x+=p.x,v.y+=p.y}),a.translate(p),this.collectPointSnaps({minOffset:f,nearestSnapsX:d,nearestSnapsY:u,otherNodeSnapPoints:l,selectionSnapPoints:c}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:u,minOffset:f});const S=this.getPointSnapLines({nearestSnapsX:d,nearestSnapsY:u}),g=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:d,nearestSnapsY:u});return this.manager.setIndicators([...g,...S]),{nudge:p}}snapResizeShapes({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var _,k;const i=this.manager.getSnapThreshold(),{box:a,scaleX:c,scaleY:l}=J.Resize(n,r,s?t.x*2:t.x,s?t.y*2:t.y,o);let d=r;c<0&&(d=MB(d)),l<0&&(d=$B(d)),s&&(a.center=n.center);const u=d==="top"||d==="bottom",f=d==="left"||d==="right",p=iC(d,a),S=this.getSnappablePoints(),g=[],w=[],y=new b(i,i);this.collectPointSnaps({minOffset:y,nearestSnapsX:g,nearestSnapsY:w,otherNodeSnapPoints:S,selectionSnapPoints:p});const v=new b(u?0:((_=g[0])==null?void 0:_.nudge)??0,f?0:((k=w[0])==null?void 0:k.nudge)??0);if(o&&AB(d)&&v.len()!==0){const j=g.length&&w.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":g.length?"x":"y",T=n.aspectRatio;j==="x"?(w.length=0,v.y=v.x/T,(d==="bottom_left"||d==="top_right")&&(v.y=-v.y)):(g.length=0,v.x=v.y*T,(d==="bottom_left"||d==="top_right")&&(v.x=-v.x))}const P=b.Add(t,v),{box:E}=J.Resize(n,r,s?P.x*2:P.x,s?P.y*2:P.y,o);s&&(E.center=n.center);const I=iC("any",E);g.length=0,w.length=0,y.x=0,y.y=0,this.collectPointSnaps({minOffset:y,nearestSnapsX:g,nearestSnapsY:w,otherNodeSnapPoints:S,selectionSnapPoints:I});const C=this.getPointSnapLines({nearestSnapsX:g,nearestSnapsY:w});return this.manager.setIndicators([...C]),{nudge:v}}collectPointSnaps({selectionSnapPoints:n,otherNodeSnapPoints:t,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of n)for(const a of t){const c=b.Sub(i,a),l=Math.abs(c.x),d=Math.abs(c.y);ue(l)<=ue(r.x)&&(ue(l)<ue(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=l),ue(d)<=ue(r.y)&&(ue(d)<ue(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=d)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!Qc(a.breadthIntersection[0],a.breadthIntersection[1],n.minY,n.maxY))continue;const l=a.startEdge[0].x+a.length/2-n.center.x;if(a.length>n.width&&ue(Math.abs(l))<=ue(t.x)){ue(Math.abs(l))<ue(t.x)&&(r.length=0),t.x=Math.abs(l);const y={type:"gap_center",gap:a,nudge:l},v=r.find(({type:E})=>E==="gap_center"),P=v&&Mr(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&P?r[r.indexOf(v)]=y:(!v||!P)&&r.push(y)}const u=a.startNode.pageBounds.minX-a.length,f=n.maxX,p=u-f;ue(Math.abs(p))<=ue(t.x)&&(ue(Math.abs(p))<ue(t.x)&&(r.length=0),t.x=Math.abs(p),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:p}));const S=a.endNode.pageBounds.maxX+a.length,g=n.minX,w=S-g;ue(Math.abs(w))<=ue(t.x)&&(ue(Math.abs(w))<ue(t.x)&&(r.length=0),t.x=Math.abs(w),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:w}))}for(const a of i){if(!Qc(a.breadthIntersection[0],a.breadthIntersection[1],n.minX,n.maxX))continue;const l=a.startEdge[0].y+a.length/2-n.center.y;if(a.length>n.height&&ue(Math.abs(l))<=ue(t.y)){ue(Math.abs(l))<ue(t.y)&&(o.length=0),t.y=Math.abs(l);const y={type:"gap_center",gap:a,nudge:l},v=o.find(({type:E})=>E==="gap_center"),P=v&&Qc(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&P?o[o.indexOf(v)]=y:(!v||!P)&&o.push(y);continue}const u=a.startNode.pageBounds.minY-a.length,f=n.maxY,p=u-f;ue(Math.abs(p))<=ue(t.y)&&(ue(Math.abs(p))<ue(t.y)&&(o.length=0),t.y=Math.abs(p),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:p}));const S=a.endNode.pageBounds.maxY+a.length,g=n.minY,w=S-g;ue(Math.abs(w))<=ue(t.y)&&(ue(Math.abs(w))<ue(t.y)&&(o.length=0),t.y=Math.abs(w),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:w}))}}getPointSnapLines({nearestSnapsX:n,nearestSnapsY:t}){const r={},o={};if(n.length>0){for(const s of n)if(s.type==="points"){const i=ue(s.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(s.points)}}if(t.length>0){for(const s of t)if(s.type==="points"){const i=ue(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:st(),type:"points",points:b0(s.map(i=>b.From(i.otherPoint)).concat(s.map(i=>b.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:n,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:n.sides[0],right:n.sides[1],bottom:[n.corners[3],n.corners[2]],left:[n.corners[0],n.corners[3]]},a=[];if(t.length>0)for(const c of t){if(c.type==="points")continue;const{gap:{breadthIntersection:l,startEdge:d,startNode:u,endNode:f,length:p,endEdge:S}}=c;switch(c.type){case"gap_center":{const g=(p-n.width)/2,w=Mr(l[0],l[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:st(),gaps:[...jo(s,u.id,g,"backward",w),{startEdge:d,endEdge:i.left},{startEdge:i.right,endEdge:S},...jo(s,f.id,g,"forward",w)]});break}case"gap_duplicate":{const g=Mr(l[0],l[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:st(),gaps:c.protrusionDirection==="left"?[{startEdge:i.right,endEdge:d.map(w=>w.clone().addXY(-u.pageBounds.width,0))},{startEdge:d,endEdge:S},...jo(s,f.id,p,"forward",g)]:[...jo(s,u.id,p,"backward",g),{startEdge:d,endEdge:S},{startEdge:S.map(w=>w.clone().addXY(c.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const c of r){if(c.type==="points")continue;const{gap:{breadthIntersection:l,startEdge:d,startNode:u,endNode:f,length:p,endEdge:S}}=c;switch(c.type){case"gap_center":{const g=(p-n.height)/2,w=Mr(l[0],l[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:st(),gaps:[...jo(o,u.id,g,"backward",w),{startEdge:d,endEdge:i.top},{startEdge:i.bottom,endEdge:S},...jo(o,c.gap.endNode.id,g,"forward",w)]});break}case"gap_duplicate":{const g=Mr(l[0],l[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:st(),gaps:c.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:d.map(w=>w.clone().addXY(0,-u.pageBounds.height))},{startEdge:d,endEdge:S},...jo(o,f.id,p,"forward",g)]:[...jo(o,u.id,p,"backward",g),{startEdge:d,endEdge:S},{startEdge:S.map(w=>w.clone().addXY(0,f.pageBounds.height)),endEdge:i.top}]})}break}}return TK(a),a}}Jp([V],Hd.prototype,"getSnapPointsCache");Jp([V],Hd.prototype,"getSnappablePoints");Jp([V],Hd.prototype,"getSnappableGapNodes");Jp([V],Hd.prototype,"getVisibleGaps");function iC(e,n){const{minX:t,maxX:r,minY:o,maxY:s}=n,i=[];switch(e){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:t,y:o})}switch(e){case"top":case"right":case"top_right":case"any":i.push({id:"top_right",handle:"top_right",x:r,y:o})}switch(e){case"bottom":case"right":case"bottom_right":case"any":i.push({id:"bottom_right",handle:"bottom_right",x:r,y:s})}switch(e){case"bottom":case"left":case"bottom_left":case"any":i.push({id:"bottom_left",handle:"bottom_left",x:t,y:s})}return i}var $K=Object.defineProperty,MK=Object.getOwnPropertyDescriptor,AK=(e,n,t,r)=>{for(var o=MK(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&$K(n,t,o),o};const jK=()=>null,OK=()=>[];class d${constructor(n){m(this,"editor");this.manager=n,this.editor=n.editor}getSnapGeometryCache(){const{editor:n}=this;return n.store.createComputedCache("handle snap geometry",t=>{const r=n.getShapeUtil(t).getHandleSnapGeometry(t);return{outline:r.outline===void 0?n.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:r.getSelfSnapOutline??jK,getSelfSnapPoints:r.getSelfSnapPoints??OK}})}*iterateSnapPointsInPageSpace(n,t){var o,s;const r=(o=this.getSnapGeometryCache().get(n))==null?void 0:o.getSelfSnapPoints(t);if(r&&r.length){const i=mr(this.editor.getShapePageTransform(n));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===n)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.points;if(!a||!a.length)continue;const c=mr(this.editor.getShapePageTransform(i));for(const l of a)yield c.applyToPoint(l)}}*iterateSnapOutlines(n,t){var o,s;const r=(o=this.getSnapGeometryCache().get(n))==null?void 0:o.getSelfSnapOutline(t);r&&(yield{shapeId:n,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===n)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:r}){const o=this.manager.getSnapThreshold();let s=o,i=null;for(const l of this.iterateSnapPointsInPageSpace(n,t))b.DistMin(r,l,s)&&(s=b.Dist(r,l),i=l);if(i)return i;let a=o,c=null;for(const{shapeId:l,outline:d}of this.iterateSnapOutlines(n,t)){const u=mr(this.editor.getShapePageTransform(l)),f=this.editor.getPointInShapeSpace(l,r),p=d.nearestPoint(f),S=u.applyToPoint(p);b.DistMin(r,S,a)&&(a=b.Dist(r,S),c=S)}return c||null}snapHandle({currentShapeId:n,handle:t}){const o=mr(this.editor.getShapePageTransform(n)).applyToPoint(t),s=this.getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:st(),type:"points",points:[s]}]),{nudge:b.Sub(s,o)}):null}}AK([V],d$.prototype,"getSnapGeometryCache");var DK=Object.defineProperty,RK=Object.getOwnPropertyDescriptor,Ux=(e,n,t,r)=>{for(var o=RK(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&DK(n,t,o),o};class eg{constructor(n){m(this,"shapeBounds");m(this,"handles");m(this,"_snapIndicators",Mt("snapLines",void 0));this.editor=n,this.shapeBounds=new Hd(this),this.handles=new d$(this)}getIndicators(){return this._snapIndicators.get()??Ho}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(n){this._snapIndicators.set(n)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:n}=this,t=n.getViewportPageBounds(),r=n.getSelectedShapeIds(),o=new Set,s=i=>{if(In(i)){const c=n.getShape(i);c&&n.isShapeOfType(c,"frame")&&o.add(i)}const a=n.getSortedChildIdsForParent(i);for(const c of a){if(r.includes(c))continue;const l=n.getShape(c);if(!l||!n.getShapeUtil(l).canSnap(l))continue;const u=n.getShapePageBounds(c);if(u&&t.includes(u)){if(n.isShapeOfType(l,"group")){s(c);continue}o.add(c)}}};return s(this.getCurrentCommonAncestor()??n.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Ux([V],eg.prototype,"getSnapThreshold");Ux([V],eg.prototype,"getSnappableShapes");Ux([V],eg.prototype,"getCurrentCommonAncestor");const LK=/\r?\n|\r/g;function aC(e){return e.replace(LK,`
|
|
86
|
-
`).split(`
|
|
87
|
-
`).map(n=>n||" ").join(`
|
|
88
|
-
`)}const FK={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},zK=/\s/;class NK{constructor(n){m(this,"baseElm");m(this,"measureText",(n,t)=>{var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",t.fontFamily),r.style.setProperty("font-style",t.fontStyle),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("font-size",t.fontSize+"px"),r.style.setProperty("line-height",t.lineHeight*t.fontSize+"px"),r.style.setProperty("max-width",t.maxWidth===null?null:t.maxWidth+"px"),r.style.setProperty("min-width",t.minWidth===null?null:t.minWidth+"px"),r.style.setProperty("padding",t.padding),r.style.setProperty("overflow-wrap",t.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=aC(n);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}});var o;this.editor=n;const t=this.editor.getContainer();(o=t.querySelector("#tldraw_text_measure"))==null||o.remove();const r=document.createElement("div");r.id="tldraw_text_measure",r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,t.appendChild(r),this.baseElm=r}measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:t=!1}={}){const r=[],o=n.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,c=n.childNodes[0];let l=0,d=null,u=null,f=0,p=0,S=!1;for(const g of n.childNodes)if(g.nodeType===Node.TEXT_NODE)for(const w of g.textContent??""){a.setStart(c,l),a.setEnd(c,l+w.length);const y=a.getClientRects(),v=y[y.length-1],P=v.top+i,E=v.left+s,I=v.right+s,C=E<p,_=zK.test(w);if(_!==u||P!==f||!d){if(d){if(t&&P!==f){S=!0;break}r.push(d)}d={box:{x:E,y:P,w:v.width,h:v.height},text:w},p=E}else C&&(d.box.x=E),d.box.w=C?d.box.w+v.width:I-d.box.x,d.text+=w;w===`
|
|
89
|
-
`&&(p=0),u=_,f=P,l+=w.length}return d&&r.push(d),{spans:r,didTruncate:S}}measureTextSpans(n,t){var l;if(n==="")return[];const r=(l=this.baseElm)==null?void 0:l.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(t.width-t.padding*2);r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("font-size",`${t.fontSize}px`),r.style.setProperty("font-family",t.fontFamily),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("line-height",`${t.lineHeight*t.fontSize}px`),r.style.setProperty("text-align",FK[t.textAlign]);const s=t.overflow==="truncate-ellipsis"||t.overflow==="truncate-clip";s&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=aC(n);r.textContent=i;const{spans:a,didTruncate:c}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(t.overflow==="truncate-ellipsis"&&c){r.textContent="…";const d=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-d}px`),r.textContent=i;const u=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,f=u[u.length-1];return u.push({text:"…",box:{x:Math.min(f.box.x+f.box.w,t.width-t.padding-d),y:f.box.y,w:d,h:f.box.h}}),u}return r.remove(),a}}const cC=(typeof process<"u",g_);class BK{constructor(n){m(this,"cancelRaf");m(this,"isPaused",!0);m(this,"now",0);m(this,"start",()=>{var n;this.isPaused=!1,(n=this.cancelRaf)==null||n.call(this),this.cancelRaf=cC(this.tick),this.now=Date.now()});m(this,"tick",()=>{if(this.isPaused)return;const n=Date.now(),t=n-this.now;this.now=n,this.updatePointerVelocity(t),this.editor.emit("frame",t),this.editor.emit("tick",t),this.cancelRaf=cC(this.tick)});m(this,"dispose",()=>{var n;this.isPaused=!0,(n=this.cancelRaf)==null||n.call(this)});m(this,"prevPoint",new b);m(this,"updatePointerVelocity",n=>{const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(n===0)return;const s=b.Sub(r,t);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new b(0,0),c=o.clone().lrp(a.mul(i/n),.5);Math.abs(c.x)<.01&&(c.x=0),Math.abs(c.y)<.01&&(c.y=0),o.equals(c)||(this.editor.inputs.pointerVelocity=c)});this.editor=n,this.editor.disposables.add(this.dispose),this.start()}}var UK=Object.defineProperty,HK=Object.getOwnPropertyDescriptor,Vr=(e,n,t,r)=>{for(var o=HK(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&UK(n,t,o),o};class Er{constructor(n,t){m(this,"systemColorScheme",Mt("systemColorScheme","light"));m(this,"updateUserPreferences",n=>{this.user.setUserPreferences({...this.user.userPreferences.get(),...n})});var r;if(this.user=n,this.inferDarkMode=t,window){const o=(r=window.matchMedia)==null?void 0:r.call(window,"(prefers-color-scheme: dark)");o!=null&&o.matches&&this.systemColorScheme.set("dark"),o==null||o.addEventListener("change",s=>{s.matches?this.systemColorScheme.set("dark"):this.systemColorScheme.set("light")})}}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),colorScheme:this.user.userPreferences.get().colorScheme,isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode(),isDynamicResizeMode:this.getIsDynamicResizeMode()}}getIsDarkMode(){switch(this.user.userPreferences.get().colorScheme){case"dark":return!0;case"light":return!1;case"system":return this.systemColorScheme.get()==="dark";default:return this.inferDarkMode?this.systemColorScheme.get()==="dark":!1}}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??gs.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??gs.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??gs.name}getLocale(){return this.user.userPreferences.get().locale??gs.locale}getColor(){return this.user.userPreferences.get().color??gs.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??gs.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??gs.isWrapMode}getIsDynamicResizeMode(){return this.user.userPreferences.get().isDynamicSizeMode??gs.isDynamicSizeMode}}Vr([V],Er.prototype,"getUserPreferences");Vr([V],Er.prototype,"getIsDarkMode");Vr([V],Er.prototype,"getEdgeScrollSpeed");Vr([V],Er.prototype,"getAnimationSpeed");Vr([V],Er.prototype,"getId");Vr([V],Er.prototype,"getName");Vr([V],Er.prototype,"getLocale");Vr([V],Er.prototype,"getColor");Vr([V],Er.prototype,"getIsSnapMode");Vr([V],Er.prototype,"getIsWrapMode");Vr([V],Er.prototype,"getIsDynamicResizeMode");const KK={wheel:"onWheel",pointer_down:"onPointerDown",pointer_move:"onPointerMove",long_press:"onLongPress",pointer_up:"onPointerUp",right_click:"onRightClick",middle_click:"onMiddleClick",key_down:"onKeyDown",key_up:"onKeyUp",key_repeat:"onKeyRepeat",cancel:"onCancel",complete:"onComplete",interrupt:"onInterrupt",double_click:"onDoubleClick",triple_click:"onTripleClick",quadruple_click:"onQuadrupleClick",tick:"onTick"},WK=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class se{constructor(n,t){m(this,"performanceTracker");m(this,"id");m(this,"type");m(this,"shapeType");m(this,"initial");m(this,"children");m(this,"parent");m(this,"_path");m(this,"_current");m(this,"_isActive");m(this,"transition",(n,t={})=>{var s;const r=n.split(".");let o=this;for(let i=0;i<r.length;i++){const a=r[i],c=o.getCurrent(),l=(s=o.children)==null?void 0:s[a];if(!l)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((c==null?void 0:c.id)!==l.id&&(c==null||c.exit(t,a),o._current.set(l),l.enter(t,(c==null?void 0:c.id)||"initial"),!l.getIsActive()))break;o=l}return this});m(this,"handleEvent",n=>{var o;const t=KK[n.name],r=this._current.__unsafe__getWithoutCapture();(o=this[t])==null||o.call(this,n),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(n)});m(this,"enter",(n,t)=>{var r;if(wt.measurePerformance.get()&&WK.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,n,t),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(n,t)}});m(this,"exit",(n,t)=>{var r,o;wt.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,n,t),this.getIsActive()||(o=this.getCurrent())==null||o.exit(n,t)});m(this,"_currentToolIdMask",Mt("curent tool id mask",void 0));m(this,"onWheel");m(this,"onPointerDown");m(this,"onPointerMove");m(this,"onLongPress");m(this,"onPointerUp");m(this,"onDoubleClick");m(this,"onTripleClick");m(this,"onQuadrupleClick");m(this,"onRightClick");m(this,"onMiddleClick");m(this,"onKeyDown");m(this,"onKeyUp");m(this,"onKeyRepeat");m(this,"onCancel");m(this,"onComplete");m(this,"onInterrupt");m(this,"onTick");m(this,"onEnter");m(this,"onExit");this.editor=n;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=Mt("toolIsActive"+this.id,!1),this._current=Mt("toolState"+this.id,void 0),this._path=V("toolPath"+this.id,()=>{const i=this.getCurrent();return this.id+(i?`.${i.getPath()}`:"")}),this.parent=t??{},this.parent?o&&s?(this.type="branch",this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&s&&(this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial]))),this.performanceTracker=new JE}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)}}m(se,"id"),m(se,"initial"),m(se,"children");class $h extends se{constructor(){super(...arguments);m(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}}})}}m($h,"id","root"),m($h,"initial",""),m($h,"children",()=>[]);var GK=Object.defineProperty,VK=Object.getOwnPropertyDescriptor,re=(e,n,t,r)=>{for(var o=VK(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&GK(n,t,o),o};class ee extends LU{constructor({store:t,user:r,shapeUtils:o,bindingUtils:s,tools:i,getContainer:a,cameraOptions:c,assetOptions:l,initialState:d,autoFocus:u,inferDarkMode:f,options:p}){super();m(this,"options");m(this,"store");m(this,"root");m(this,"disposables",new Set);m(this,"isDisposed",!1);m(this,"_tickManager");m(this,"snaps");m(this,"timers");m(this,"user");m(this,"textMeasure");m(this,"environment");m(this,"scribbles");m(this,"sideEffects");m(this,"edgeScrollManager");m(this,"focusManager");m(this,"getContainer");m(this,"shapeUtils");m(this,"styleProps");m(this,"bindingUtils");m(this,"history");m(this,"_crashingError",null);m(this,"_updateInstanceState",(t,r)=>{this.batch(()=>{this.store.put([{...this.getInstanceState(),...t}])},r)});m(this,"_isChangingStyleTimeout",-1);m(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}}),this));m(this,"_updateCurrentPageState",(t,r)=>{this.batch(()=>{this.store.update(t.id??this.getCurrentPageState().id,o=>({...o,...t}))},{history:"ignore",...r})});m(this,"_cameraOptions",Mt("camera options",k1));m(this,"_viewportAnimation",null);m(this,"_willSetInitialBounds",!0);m(this,"_isLockedOnFollowingUser",Mt("isLockedOnFollowingUser",!1));m(this,"_cameraState",Mt("camera state","idle"));m(this,"_cameraStateTimeoutRemaining",0);m(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))});m(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});m(this,"_currentPageShapeIds");m(this,"_assetOptions",Mt("asset options",T1));m(this,"_parentIdsToChildIds");m(this,"animatingShapes",new Map);m(this,"_updateShapes",t=>{this.getInstanceState().isReadonly||this.batch(()=>{var i,a;const r=[];let o,s;for(let c=0,l=t.length;c<l;c++){const d=t[c];d&&(o=this.getShape(d.id),o&&(s=Ao(o,d),s!==o&&(s=((a=(i=this.getShapeUtil(o)).onBeforeUpdate)==null?void 0:a.call(i,o,s))??s,r.push(s))))}this.store.put(r)})});m(this,"externalAssetContentHandlers",{file:null,url:null});m(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});m(this,"inputs",{originPagePoint:new b,originScreenPoint:new b,previousPagePoint:new b,previousScreenPoint:new b,currentPagePoint:new b,currentScreenPoint:new b,keys:new Set,buttons:new Set,isPen:!1,shiftKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,pointerVelocity:new b});m(this,"_clickManager",new yK(this));m(this,"_prevCursor","default");m(this,"_shiftKeyTimeout",-1);m(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"})});m(this,"_altKeyTimeout",-1);m(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"})});m(this,"_ctrlKeyTimeout",-1);m(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"})});m(this,"_restoreToolId","select");m(this,"_pinchStart",1);m(this,"_didPinch",!1);m(this,"_selectedShapeIdsAtPointerDown",[]);m(this,"_longPressTimeout",-1);m(this,"capturedPointerId",null);m(this,"performanceTracker");m(this,"performanceTrackerTimeout",-1);m(this,"dispatch",t=>(this._pendingEventsForNextTick.push(t),t.type==="pointer"&&t.name==="pointer_move"||t.type==="wheel"||t.type==="pinch"||this._flushEventsForTick(0),this));m(this,"_pendingEventsForNextTick",[]);m(this,"_flushEventForTick",t=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=t;if(t.type==="misc"){(t.name==="cancel"||t.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(t);return}t.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!t.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),t.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!t.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),t.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!t.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,currentPagePoint:i}=r;r.isPointing||(r.isDragging=!1);const a=this.store.unsafeGetWithoutCapture(pn),c=this.store.get(this._getCurrentPageStateId()),l=this._cameraOptions.__unsafe__getWithoutCapture();switch(o){case"pinch":{if(l.isLocked)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(t),t.name){case"pinch_start":{if(r.isPinching)return;r.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=[...c.selectedShapeIds]),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:d=1},delta:{x:u,y:f}}=t,{x:p,y:S}=b.SubXY(t.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:g,y:w,z:y}=um(()=>this.getCamera()),{panSpeed:v,zoomSpeed:P}=l;this._setCamera(new b(g+u*v/y-p/y+p/(d*P),w+f*v/y-S/y+S/(d*P),d*P),{immediate:!0});return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:d}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,d.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(d)}));return}}}case"wheel":{if(l.isLocked)return;if(this._updateInputsFromEvent(t),!this.getIsMenuOpen()){const{panSpeed:d,zoomSpeed:u,wheelBehavior:f}=l;if(f!=="none"){this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:p,y:S,z:g}=um(()=>this.getCamera()),{x:w,y,z:v=0}=t.delta;let P=f;switch(r.ctrlKey&&(P=f==="pan"?"zoom":"pan"),P){case"zoom":{const{x:E,y:I}=this.inputs.currentScreenPoint;let C=v;f==="zoom"&&(Math.abs(y)>10?C=10*Math.sign(y)/100:C=y/100);const _=g+(C??0)*u*g;this._setCamera(new b(p+(E/_-E)-(E/g-E),S+(I/_-I)-(I/g-I),_),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new b(p+w*d/g,S+y*d/g,g),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(t);const{isPen:d}=t,{isPenMode:u}=a;switch(t.name){case"pointer_down":{if(u&&!d)return;if(this.clearOpenMenus(),this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{this.dispatch({...t,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),t.button===M1&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,!u&&d&&this.updateInstanceState({isPenMode:!0}),t.button===A1?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===Su&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!d&&u)return;const{x:f,y:p,z:S}=um(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:g,previousScreenPoint:w}=this.inputs,{panSpeed:y}=l,v=b.Sub(g,w);this.setCamera(new b(f+v.x*y/S,p+v.y*y/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&b.Dist2(s,i)*this.getZoomLevel()>(a.isCoarsePointer?this.options.coarseDragDistanceSquared:this.options.dragDistanceSquared)/S&&(r.isDragging=!0,clearTimeout(this._longPressTimeout));break}case"pointer_up":{if(r.isDragging=!1,r.isPointing=!1,clearTimeout(this._longPressTimeout),r.buttons.delete(t.button),this.getIsMenuOpen()||a.isPenMode&&!d)return;if(this.capturedPointerId===t.pointerId&&(this.capturedPointerId=null,t.button=0),r.isPanning){r.keys.has("Space")||(r.isPanning=!1);const f=this.inputs.pointerVelocity,p=Math.min(2,f.len());switch(t.button){case M1:{this.setCursor({type:"grab",rotation:0});break}case Su:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}p>0&&this.slideCamera({speed:p,direction:f})}else t.button===A1&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(t.key==="ShiftRight"&&(t.key="ShiftLeft"),t.key==="AltRight"&&(t.key="AltLeft"),t.code==="ControlRight"&&(t.code="ControlLeft"),t.name){case"key_down":{r.keys.add(t.code),t.code==="Space"&&!t.ctrlKey&&(this.inputs.isPanning||(this._prevCursor=a.cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout),this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0}));break}case"key_up":{r.keys.delete(t.code),t.code==="Space"&&(this.inputs.buttons.has(Su)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(t.type==="pointer"){t.button===Su?t.name="middle_click":t.button===B0&&(t.name="right_click");const{isPenMode:d}=this.store.unsafeGetWithoutCapture(pn);if(t.isPen===d){const u=this._clickManager.handlePointerEvent(t);if(t.name!==u.name){this.root.handleEvent(t),this.emit("event",t),this.root.handleEvent(u),this.emit("event",u);return}}}return this.root.handleEvent(t),this.emit("event",t),this});this.options={...tK,...p},this.store=t,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new PK({store:t,annotateError:T=>{this.annotateError(T,{origin:"history.batch",willCrashApp:!0}),this.crash(T)}}),this.snaps=new eg(this),this.timers=new d4,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...k1,...c}),this._assetOptions.set({...T1,...l}),this.user=new Er(r??Yk(),f??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new NK(this),this._tickManager=new BK(this);class S extends $h{}m(S,"initial",d??""),this.root=new S(this),this.root.children={};const g=i$(o),w={},y={},v=new Map;for(const T of g){const M=new T(this);w[T.type]=M;const R=M_(T.props??{});y[T.type]=R;for(const A of R.keys())if(!v.has(A.id))v.set(A.id,A);else if(v.get(A.id)!==A)throw Error(`Multiple style props with id "${A.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=w,this.styleProps=y;const P=r$(s),E={};for(const T of P){const M=new T(this);E[T.type]=M}this.bindingUtils=E;for(const T of[...i]){if(lo(this.root.children,T.id))throw Error(`Can't override tool with id "${T.id}"`);this.root.children[T.id]=new T(this,this.root)}this.environment=new vK(this),this.scribbles=new EK(this);const I=(T,M)=>{let R=null;const A=T.selectedShapeIds.filter(G=>!M.has(G));A.length!==T.selectedShapeIds.length&&(R||(R={...T}),R.selectedShapeIds=A);const O=T.erasingShapeIds.filter(G=>!M.has(G));O.length!==T.erasingShapeIds.length&&(R||(R={...T}),R.erasingShapeIds=O),T.hoveredShapeId&&M.has(T.hoveredShapeId)&&(R||(R={...T}),R.hoveredShapeId=null),T.editingShapeId&&M.has(T.editingShapeId)&&(R||(R={...T}),R.editingShapeId=null);const L=T.hintingShapeIds.filter(G=>!M.has(G));return L.length!==T.hintingShapeIds.length&&(R||(R={...T}),R.hintingShapeIds=L),T.focusedGroupId&&M.has(T.focusedGroupId)&&(R||(R={...T}),R.focusedGroupId=null),R};this.sideEffects=this.store.sideEffects;let C=new Map;const _=new Set,k=new Set;let j=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var T,M,R,A;_.clear();for(const O of k){k.delete(O);const L=this.getShape(O);if(!L)continue;const G=this.getShapeUtil(L),K=(T=G.onChildrenChange)==null?void 0:T.call(G,L);K!=null&&K.length&&this.updateShapes(K)}if(j.size){const O=j;j=new Set;for(const L of O){const G=this.getBindingUtil(L);(M=G.onOperationComplete)==null||M.call(G)}}if(C.size){const O=C;C=new Map;for(const L of O.values())(A=(R=this.getBindingUtil(L.binding)).onAfterDelete)==null||A.call(R,L)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(T,M)=>{var R,A,O,L;for(const G of this.getBindingsInvolvingShape(M))j.add(G.type),G.fromId===M.id&&((A=(R=this.getBindingUtil(G)).onAfterChangeFromShape)==null||A.call(R,{binding:G,shapeBefore:T,shapeAfter:M})),G.toId===M.id&&((L=(O=this.getBindingUtil(G)).onAfterChangeToShape)==null||L.call(O,{binding:G,shapeBefore:T,shapeAfter:M}));if(T.parentId!==M.parentId){const G=K=>{var U,Y,Q,le;const B=this.getShape(K);if(B)for(const ge of this.getBindingsInvolvingShape(B))j.add(ge.type),ge.fromId===B.id&&((Y=(U=this.getBindingUtil(ge)).onAfterChangeFromShape)==null||Y.call(U,{binding:ge,shapeBefore:B,shapeAfter:B})),ge.toId===B.id&&((le=(Q=this.getBindingUtil(ge)).onAfterChangeToShape)==null||le.call(Q,{binding:ge,shapeBefore:B,shapeAfter:B}))};G(M.id),this.visitDescendants(M.id,G)}if(T.parentId!==M.parentId&&Pn(M.parentId)){const G=new Set([T.id]);this.visitDescendants(T.id,K=>{G.add(K)});for(const K of this.getPageStates()){if(K.pageId===M.parentId)continue;const B=I(K,G);B&&this.store.put([B])}}T.parentId&&In(T.parentId)&&k.add(T.parentId),M.parentId!==T.parentId&&In(M.parentId)&&k.add(M.parentId)},beforeDelete:T=>{var O,L,G,K;if(_.has(T.id))return;T.parentId&&In(T.parentId)&&k.add(T.parentId),_.add(T.id);const M=[];for(const B of this.getBindingsInvolvingShape(T)){j.add(B.type),M.push(B.id);const U=this.getBindingUtil(B);B.fromId===T.id?((O=U.onBeforeIsolateToShape)==null||O.call(U,{binding:B,removedShape:T}),(L=U.onBeforeDeleteFromShape)==null||L.call(U,{binding:B,shape:T})):((G=U.onBeforeIsolateFromShape)==null||G.call(U,{binding:B,removedShape:T}),(K=U.onBeforeDeleteToShape)==null||K.call(U,{binding:B,shape:T}))}M.length&&this.deleteBindings(M);const R=new Set([T.id]),A=Se(this.getPageStates().map(B=>I(B,R)));A.length&&this.store.put(A)}},binding:{beforeCreate:T=>{var R,A;const M=(A=(R=this.getBindingUtil(T)).onBeforeCreate)==null?void 0:A.call(R,{binding:T});return M||T},afterCreate:T=>{var M,R;j.add(T.type),(R=(M=this.getBindingUtil(T)).onAfterCreate)==null||R.call(M,{binding:T})},beforeChange:(T,M)=>{var A,O;const R=(O=(A=this.getBindingUtil(M)).onBeforeChange)==null?void 0:O.call(A,{bindingBefore:T,bindingAfter:M});return R||M},afterChange:(T,M)=>{var R,A;j.add(M.type),(A=(R=this.getBindingUtil(M)).onAfterChange)==null||A.call(R,{bindingBefore:T,bindingAfter:M})},beforeDelete:T=>{var M,R;(R=(M=this.getBindingUtil(T)).onBeforeDelete)==null||R.call(M,{binding:T})},afterDelete:T=>{var M,R;(R=(M=this.getBindingUtil(T)).onAfterDelete)==null||R.call(M,{binding:T}),j.add(T.type)}},page:{afterCreate:T=>{const M=io.createId(T.id),R=Rr.createId(T.id);this.store.has(M)||this.store.put([io.create({id:M})]),this.store.has(R)||this.store.put([Rr.create({id:R,pageId:T.id})])},afterDelete:(T,M)=>{var O,L;if(((O=this.getInstanceState())==null?void 0:O.currentPageId)===T.id){const G=(L=this.getPages().find(K=>K.id!==T.id))==null?void 0:L.id;G?this.store.put([{...this.getInstanceState(),currentPageId:G}]):M==="user"&&this.store.ensureStoreIsUsable()}const R=io.createId(T.id),A=Rr.createId(T.id);this.store.remove([R,A])}},instance:{afterChange:(T,M,R)=>{var A;if(!this.store.has(M.currentPageId)){const O=this.store.has(T.currentPageId)?T.currentPageId:(A=this.getPages()[0])==null?void 0:A.id;O?this.store.update(M.id,L=>({...L,currentPageId:O})):R==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(T,M)=>{if((T==null?void 0:T.selectedShapeIds)!==(M==null?void 0:M.selectedShapeIds)){const R=M.selectedShapeIds.filter(O=>{var G,K;let L=(G=this.getShape(O))==null?void 0:G.parentId;for(;In(L);){if(M.selectedShapeIds.includes(L))return!1;L=(K=this.getShape(L))==null?void 0:K.parentId}return!0});let A=null;if(R.length>0){const O=this.findCommonAncestor(Se(R.map(L=>this.getShape(L))),L=>this.isShapeOfType(L,"group"));O&&(A=O)}else M!=null&&M.focusedGroupId&&(A=M.focusedGroupId);(R.length!==M.selectedShapeIds.length||A!==M.focusedGroupId)&&this.store.put([{...M,selectedShapeIds:R,focusedGroupId:A??null}])}}}})),this._currentPageShapeIds=fK(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=hK(this.store),this.disposables.add(this.store.listen(T=>{this.emit("change",T)})),this.disposables.add(this.history.dispose),this.history.ignore(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})}),d&&this.root.children[d]===void 0)throw Error(`No state found for initialState "${d}".`);this.root.enter(void 0,"initial"),this.edgeScrollManager=new SK(this),this.focusManager=new xK(this,u),this.disposables.add(this.focusManager.dispose.bind(this.focusManager)),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.on("tick",this._flushEventsForTick),this.timers.requestAnimationFrame(()=>{this._tickManager.start()}),this.performanceTracker=new JE}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=Tn(this.shapeUtils,r);return it(o,`No shape util found for type "${r}"`),o}getBindingUtil(t){const r=typeof t=="string"?t:t.type,o=Tn(this.bindingUtils,r);return it(o,`No binding util found for type "${r}"`),o}undo(){return this._flushEventsForTick(0),this.complete(),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.complete(),this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(t){return this.history.mark(t),this}bail(){return this.history.bail(),this}bailToMark(t){return this.history.bailToMark(t),this}batch(t,r){return this.history.batch(t,r),this}annotateError(t,{origin:r,willCrashApp:o,tags:s,extras:i}){const a=this.createErrorAnnotations(r,o);return P0(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(fS)}updateDocumentSettings(t){return this.history.ignore(()=>{this.store.put([{...this.getDocumentSettings(),...t}])}),this}getInstanceState(){return this.store.get(pn)}updateInstanceState(t,r){return this._updateInstanceState(t,{history:"ignore",...r}),t.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),t.isChangingStyle===!0&&(this._isChangingStyleTimeout=this.timers.setTimeout(()=>{this._updateInstanceState({isChangingStyle:!1},{history:"ignore"})},2e3))),this}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(t){const r=new Set(this.getOpenMenus());return r.has(t)||(r.add(t),this.updateInstanceState({openMenus:[...r]})),this}deleteOpenMenu(t){const r=new Set(this.getOpenMenus());return r.has(t)&&(r.delete(t),this.updateInstanceState({openMenus:[...r]})),this}clearOpenMenus(){return this.getOpenMenus().length&&this.updateInstanceState({openMenus:[]}),this}getIsMenuOpen(){return this.getOpenMenus().length>0}getPageStates(){return this._getPageStatesQuery().get()}_getPageStatesQuery(){return this.store.query.records("instance_page_state")}getCurrentPageState(){return this.store.get(this._getCurrentPageStateId())}_getCurrentPageStateId(){return Rr.createId(this.getCurrentPageId())}updateCurrentPageState(t,r){return this._updateCurrentPageState(t,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:t}=this.getCurrentPageState();return Se(t.map(r=>this.store.get(r)))}setSelectedShapes(t){return this.batch(()=>{const r=t.map(i=>typeof i=="string"?i:i.id),{selectedShapeIds:o}=this.getCurrentPageState(),s=new Set(o);if(r.length===s.size&&r.every(i=>s.has(i)))return null;this.store.put([{...this.getCurrentPageState(),selectedShapeIds:r}])},{history:"record-preserveRedoStack"})}isAncestorSelected(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null,o=this.getShape(r);if(!o)return!1;const s=this.getSelectedShapeIds();return!!this.findShapeAncestor(o,i=>s.includes(i.id))}select(...t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.setSelectedShapes(r),this}deselect(...t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=this.getSelectedShapeIds();return o.length>0&&r.length>0&&this.setSelectedShapes(o.filter(s=>!r.includes(s))),this}selectAll(){const t=this.getSortedChildIdsForParent(this.getCurrentPageId());return t.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(t)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var t;return((t=this.getOnlySelectedShape())==null?void 0:t.id)??null}getOnlySelectedShape(){const t=this.getSelectedShapes();return t.length===1?t[0]:null}getSelectionPageBounds(){const t=this.getCurrentPageState().selectedShapeIds;return t.length===0?null:J.Common(Se(t.map(r=>this.getShapePageBounds(r))))}getSelectionRotation(){const t=this.getSelectedShapeIds();let r=!1,o=0;for(let s=0,i=t.length;s<i;s++){const a=this.getShapePageTransform(t[s]);if(a)if(r){if(a.rotation()!==o)return 0}else r=!0,o=a.rotation()}return o}getSelectionRotatedPageBounds(){const t=this.getSelectedShapeIds();if(t.length===0)return;const r=this.getSelectionRotation();if(r===0)return this.getSelectionPageBounds();if(t.length===1){const s=this.getShapeGeometry(t[0]).bounds.clone(),i=this.getShapePageTransform(t[0]);return s.point=i.applyToPoint(s.point),s}const o=J.FromPoints(this.getSelectedShapeIds().flatMap(s=>{const i=this.getShapePageTransform(s);return i?i.applyToPoints(this.getShapeGeometry(s).bounds.corners):[]}).map(s=>s.rot(-r)));return o.point=o.point.rot(r),o}getSelectionRotatedScreenBounds(){const t=this.getSelectionRotatedPageBounds();if(!t)return;const{x:r,y:o}=this.pageToScreen(t.point),s=this.getZoomLevel();return new J(r,o,t.width*s,t.height*s)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const t=this.getFocusedGroupId();return t?this.getShape(t):void 0}setFocusedGroup(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==null){const o=this.getShape(r);if(!o)throw Error(`Editor.setFocusedGroup: Shape with id ${r} does not exist`);if(!this.isShapeOfType(o,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${o.type}`)}return r===this.getFocusedGroupId()?this:this.batch(()=>{this.store.update(this.getCurrentPageState().id,o=>({...o,focusedGroupId:r}))},{history:"record-preserveRedoStack"})}popFocusedGroupId(){const t=this.getFocusedGroup();if(t){const r=this.findShapeAncestor(t,o=>this.isShapeOfType(o,"group"));this.setFocusedGroup((r==null?void 0:r.id)??null),this.select(t.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const t=this.getEditingShapeId();return t?this.getShape(t):void 0}setEditingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==this.getEditingShapeId()){if(r){const o=this.getShape(r);if(o&&this.getShapeUtil(o).canEdit(o))return this._updateCurrentPageState({editingShapeId:r}),this}this._updateCurrentPageState({editingShapeId:null})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const t=this.getHoveredShapeId();return t?this.getShape(t):void 0}setHoveredShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;return r===this.getHoveredShapeId()?this:(this.updateCurrentPageState({hoveredShapeId:r},{history:"ignore"}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const t=this.getHintingShapeIds();return Se(t.map(r=>this.getShape(r)))}setHintingShapes(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:b0(r)},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const t=this.getErasingShapeIds();return Se(t.map(r=>this.getShape(r)))}setErasingShapes(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id);r.sort();const o=this.getErasingShapeIds();return this.history.ignore(()=>{if(r.length===o.length){for(let s=0;s<r.length;s++)if(r[s]!==o[s]){this._updateCurrentPageState({erasingShapeIds:r});break}}else this._updateCurrentPageState({erasingShapeIds:r})}),this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(t){const r=typeof t=="string"?t:(t==null?void 0:t.id)??null;if(r!==this.getCroppingShapeId())if(!r)this.updateCurrentPageState({croppingShapeId:null});else{const o=this.getShape(r),s=this.getShapeUtil(o);o&&s.canCrop(o)&&this.updateCurrentPageState({croppingShapeId:r})}return this}getCameraId(){return io.createId(this.getCurrentPageId())}getCamera(){const t=this.store.get(this.getCameraId());if(this._isLockedOnFollowingUser.get()){const r=this.getCameraForFollowing();if(r)return{...t,...r}}return t}getViewportPageBoundsForFollowing(){const t=this.getInstanceState().followingUserId;if(!t)return null;const r=this.getCollaborators().find(f=>f.userId===t);if(!r)return null;const{w:o,h:s}=r.screenBounds,{x:i,y:a,z:c}=r.camera,l=new J(-i,-a,o/c,s/c),d=this.getViewportScreenBounds().clone(),u=d.width/d.height;return d.width=l.width,d.height=d.width/u,d.height<l.height&&(d.height=l.height,d.width=d.height*u),d.center=l.center,d}getCameraForFollowing(){const t=this.getViewportPageBoundsForFollowing();return t?{x:-t.x,y:-t.y,z:this.getViewportScreenBounds().w/t.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.initialZoom==="default")return 1;const{zx:r,zy:o}=dC(this,t);switch(t.constraints.initialZoom){case"fit-min":return Math.max(r,o);case"fit-max":return Math.min(r,o);case"fit-x":return r;case"fit-y":return o;case"fit-min-100":return Math.min(1,Math.max(r,o));case"fit-max-100":return Math.min(1,Math.min(r,o));case"fit-x-100":return Math.min(1,r);case"fit-y-100":return Math.min(1,o);default:throw sn(t.constraints.initialZoom)}}getBaseZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.baseZoom==="default")return 1;const{zx:r,zy:o}=dC(this,t);switch(t.constraints.baseZoom){case"fit-min":return Math.max(r,o);case"fit-max":return Math.min(r,o);case"fit-x":return r;case"fit-y":return o;case"fit-min-100":return Math.min(1,Math.max(r,o));case"fit-max-100":return Math.min(1,Math.min(r,o));case"fit-x-100":return Math.min(1,r);case"fit-y-100":return Math.min(1,o);default:throw sn(t.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(t){var o;const r=ot({...this._cameraOptions.__unsafe__getWithoutCapture(),...t});return((o=r.zoomSteps)==null?void 0:o.length)<1&&(r.zoomSteps=[1]),this._cameraOptions.set(r),this}getConstrainedCamera(t,r){const o=this.getCamera();let{x:s,y:i,z:a=o.z}=t;if(!(r!=null&&r.force)){const c=this.getCameraOptions(),l=c.zoomSteps[0],d=Nt(c.zoomSteps),u=this.getViewportScreenBounds();if(c.constraints){const{constraints:f}=c,p=Math.min(f.padding.y,u.w/2),S=Math.min(f.padding.x,u.h/2),g=J.From(c.constraints.bounds),w=(u.w-S*2)/g.w,y=(u.h-p*2)/g.h,v=this.getBaseZoom(),P=d*v,E=l*v;if(r!=null&&r.reset&&(a=this.getInitialZoom()),a<E||a>P){const{x:A,y:O,z:L}=o,G=-A+u.w/L/2,K=-O+u.h/L/2;a=Tt(a,E,P);const B=-A+u.w/a/2,U=-O+u.h/a/2;s=A+B-G,i=O+U-K}const I=S/a-g.x,C=p/a-g.y,_=(u.w-S*2)/a-g.w,k=(u.h-p*2)/a-g.h,j=I+_*f.origin.x,T=C+k*f.origin.y,M=typeof f.behavior=="string"?f.behavior:f.behavior.x,R=typeof f.behavior=="string"?f.behavior:f.behavior.y;if(r!=null&&r.reset)s=j,i=T;else{switch(M){case"fixed":{s=j;break}case"contain":{a<w?s=j:s=Tt(s,I+_,I);break}case"inside":{a<w?s=Tt(s,I,(u.w-S)/a-g.w):s=Tt(s,I+_,I);break}case"outside":{s=Tt(s,S/a-g.w,(u.w-S)/a);break}case"free":break;default:throw sn(M)}switch(R){case"fixed":{i=T;break}case"contain":{a<y?i=T:i=Tt(i,C+k,C);break}case"inside":{a<y?i=Tt(i,C,(u.h-p)/a-g.h):i=Tt(i,C+k,C);break}case"outside":{i=Tt(i,p/a-g.h,(u.h-p)/a);break}case"free":break;default:throw sn(R)}}}else if(a>d||a<l){const{x:f,y:p,z:S}=o;a=Tt(a,l,d),s=f+(-f+u.w/a/2)-(-f+u.w/S/2),i=p+(-p+u.h/a/2)-(-p+u.h/S/2)}}return{x:s,y:i,z:a}}_setCamera(t,r){const o=this.getCamera(),{x:s,y:i,z:a}=this.getConstrainedCamera(t,r);return o.x===s&&o.y===i&&o.z===a?this:(this.batch(()=>{const c={...o,x:s,y:i,z:a};this.history.ignore(()=>{this.store.put([c])});const{currentScreenPoint:l,currentPagePoint:d}=this.inputs,{screenBounds:u}=this.store.unsafeGetWithoutCapture(pn);if(l.x/a-s!==d.x||l.y/a-i!==d.y){const f={type:"pointer",target:"canvas",name:"pointer_move",point:b.AddXY(l,u.x,u.y),pointerId:$1.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1};r!=null&&r.immediate?this._flushEventForTick(f):this.dispatch(f)}this._tickCameraState()}),this)}setCamera(t,r){const{isLocked:o}=this._cameraOptions.__unsafe__getWithoutCapture();if(o&&!(r!=null&&r.force))return this;this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser();const s=b.Cast(t);Number.isFinite(s.x)||(s.x=0),Number.isFinite(s.y)||(s.y=0),(s.z===void 0||!Number.isFinite(s.z))&&(t.z=this.getZoomLevel());const i=this.getConstrainedCamera(s,r);if(r!=null&&r.animation){const{width:a,height:c}=this.getViewportScreenBounds();this._animateToViewport(new J(-i.x,-i.y,a/i.z,c/i.z),r)}else this._setCamera(i,{...r,force:!0});return this}centerOnPoint(t,r){if(this.getCameraOptions().isLocked)return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera(new b(-(t.x-o/2),-(t.y-s/2),this.getCamera().z),r),this}zoomToFit(t){const r=[...this.getCurrentPageShapeIds()];if(r.length<=0)return this;const o=J.Common(Se(r.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(o,t),this}resetZoom(t=this.getViewportScreenCenter(),r){const{isLocked:o,constraints:s}=this.getCameraOptions();if(o)return this;const i=this.getCamera(),{x:a,y:c,z:l}=i,{x:d,y:u}=t;let f=1;if(s){const p=this.getInitialZoom();l!==p&&(f=p)}return this.setCamera(new b(a+(d/f-d)-(d/l-d),c+(u/f-u)-(u/l-u),f),r),this}zoomIn(t=this.getViewportScreenCenter(),r){if(this.getCameraOptions().isLocked)return this;const{x:o,y:s,z:i}=this.getCamera(),{zoomSteps:a}=this.getCameraOptions();if(a!==null&&a.length>1){const c=this.getBaseZoom();let l=Nt(a)*c;for(let d=1;d<a.length;d++){const u=a[d-1]*c,f=a[d]*c;if(!(f-i<=(f-u)/2)){l=f;break}}this.setCamera(new b(o+(t.x/l-t.x)-(t.x/i-t.x),s+(t.y/l-t.y)-(t.y/i-t.y),l),r)}return this}zoomOut(t=this.getViewportScreenCenter(),r){if(this.getCameraOptions().isLocked)return this;const{zoomSteps:o}=this.getCameraOptions();if(o!==null&&o.length>1){const s=this.getBaseZoom(),{x:i,y:a,z:c}=this.getCamera();let l=o[0]*s;for(let d=o.length-1;d>0;d--){const u=o[d-1]*s,f=o[d]*s;if(!(f-c>=(f-u)/2)){l=u;break}}this.setCamera(new b(i+(t.x/l-t.x)-(t.x/c-t.x),a+(t.y/l-t.y)-(t.y/c-t.y),l),r)}return this}zoomToSelection(t){if(this.getCameraOptions().isLocked)return this;const r=this.getSelectionPageBounds();return r&&this.zoomToBounds(r,{targetZoom:Math.max(1,this.getZoomLevel()),...t}),this}zoomToBounds(t,r){const o=this._cameraOptions.__unsafe__getWithoutCapture();if(o.isLocked)return this;const s=this.getViewportScreenBounds(),i=(r==null?void 0:r.inset)??Math.min(p7,s.width*.28),a=this.getBaseZoom(),c=o.zoomSteps[0],l=Nt(o.zoomSteps);let d=Tt(Math.min((s.width-i)/t.w,(s.height-i)/t.h),c*a,l*a);return(r==null?void 0:r.targetZoom)!==void 0&&(d=Math.min(r.targetZoom,d)),this.setCamera(new b(-t.x+(s.width-t.w*d)/2/d,-t.y+(s.height-t.h*d)/2/d,d),r),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(t){if(!this._viewportAnimation)return;this._viewportAnimation.elapsed+=t;const{elapsed:r,easing:o,duration:s,start:i,end:a}=this._viewportAnimation;if(r>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new b(-a.x,-a.y,this.getViewportScreenBounds().width/a.width));return}const c=s-r,l=o(1-c/s),d=i.minX+(a.minX-i.minX)*l,u=i.minY+(a.minY-i.minY)*l,f=i.maxX+(a.maxX-i.maxX)*l;this._setCamera(new b(-d,-u,this.getViewportScreenBounds().width/(f-d)),{force:!0})}_animateToViewport(t,r={animation:gm}){const{animation:o,...s}=r;if(!o)return;const{duration:i=0,easing:a=At.easeInOutCubic}=o,c=this.user.getAnimationSpeed(),l=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||c===0?this._setCamera(new b(-t.x,-t.y,this.getViewportScreenBounds().width/t.width),{...s}):(this._viewportAnimation={elapsed:0,duration:i/c,easing:a,start:l.clone(),end:t.clone()},this.once("stop-camera-animation",()=>{this.off("tick",this._animateViewport),this._viewportAnimation=null}),this.on("tick",this._animateViewport),this)}slideCamera(t={}){if(this.getCameraOptions().isLocked)return this;if(this.user.getAnimationSpeed()===0)return this;this.stopCameraAnimation();const{speed:o,friction:s=this.options.cameraSlideFriction,direction:i,speedThreshold:a=.01}=t;let c=Math.min(o,1);const l=()=>{this.off("tick",d),this.off("stop-camera-animation",l)};this.once("stop-camera-animation",l);const d=u=>{const{x:f,y:p,z:S}=this.getCamera(),g=b.Mul(i,c*u/S);c*=1-s,c<a?l():this._setCamera(new b(f+g.x,p+g.y,S))};return this.on("tick",d),this}zoomToUser(t,r={animation:{duration:500}}){const o=this.getCollaborators().find(s=>s.userId===t);return o?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const s=o.currentPageId===this.getCurrentPageId();s||this.setCurrentPage(o.currentPageId),r&&r.animation&&!s&&(r.animation=void 0),this.centerOnPoint(o.cursor,r);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,t]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],c=a.indexOf(t);c<0||(a.splice(c,1),this.updateInstanceState({highlightedUserIds:a}))},this.options.collaboratorIdleTimeoutMs)}),this):this}updateViewportScreenBounds(t,r=!1){t.width=Math.max(t.width,1),t.height=Math.max(t.height,1);const o=[t.minY!==0,!Os(document.body.scrollWidth,t.maxX,1),!Os(document.body.scrollHeight,t.maxY,1),t.minX!==0],{screenBounds:s,insets:i}=this.getInstanceState();if(t.equals(s)&&o.every((c,l)=>c===i[l]))return this;const{_willSetInitialBounds:a}=this;if(this._willSetInitialBounds=!1,a)this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.setCamera(this.getCamera());else if(r&&!this.getInstanceState().followingUserId){const c=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.centerOnPoint(c)}else this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this._setCamera(b.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:t,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new J(t,r,o,s)}getViewportScreenCenter(){const t=this.getViewportScreenBounds();return new b(t.midX-t.minX,t.midY-t.minY)}getViewportPageBounds(){const{w:t,h:r}=this.getViewportScreenBounds(),{x:o,y:s,z:i}=this.getCamera();return new J(-o,-s,t/i,r/i)}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(pn),{x:o,y:s,z:i=1}=this.getCamera();return new b((t.x-r.x)/i-o,(t.y-r.y)/i-s,t.z??.5)}pageToScreen(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(pn),{x:o,y:s,z:i=1}=this.getCamera();return new b((t.x+o)*i+r.x,(t.y+s)*i+r.y,t.z??.5)}pageToViewport(t){const{x:r,y:o,z:s=1}=this.getCamera();return new b((t.x+r)*s,(t.y+o)*s,t.z??.5)}_getCollaboratorsQuery(){return this.store.query.records("instance_presence",()=>({userId:{neq:this.user.getId()}}))}getCollaborators(){const t=this._getCollaboratorsQuery().get();return t.length?[...new Set(t.map(o=>o.userId))].sort().map(o=>t.filter(i=>i.userId===o).sort((i,a)=>a.lastActivityTimestamp-i.lastActivityTimestamp)[0]):Ho}getCollaboratorsOnCurrentPage(){const t=this.getCurrentPageId();return this.getCollaborators().filter(r=>r.currentPageId===t)}startFollowingUser(t){this.stopFollowingUser();const r=this._getCollaboratorsQuery().get().filter(i=>i.userId===t);if(!r.length)return console.warn("User not found"),this;const o=this.user.getId();if(o||console.warn("You should set the userId for the current instance before following a user"),r.some(i=>i.followingUserId===o))return this;const s=V("latestLeaderPresence",()=>this.getCollaborators().find(i=>i.userId===t));return As(()=>{this.updateInstanceState({followingUserId:t},{history:"ignore"});const i=ta("update current page",()=>{const l=s.get();if(!l){this.stopFollowingUser();return}l.currentPageId!==this.getCurrentPageId()&&this.getPage(l.currentPageId)&&this.history.ignore(()=>{this.store.put([{...this.getInstanceState(),currentPageId:l.currentPageId}]),this._isLockedOnFollowingUser.set(!0)})}),a=()=>{i(),this._isLockedOnFollowingUser.set(!1),this.off("frame",c),this.off("stop-following",a)},c=()=>{if(!s.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const d=this.user.getAnimationSpeed();if(d===0){this._isLockedOnFollowingUser.set(!0);return}const u=this.getViewportPageBoundsForFollowing();if(!u){this.stopFollowingUser();return}const f=this.getViewportPageBounds(),p=Math.abs(u.minX-f.minX)+Math.abs(u.maxX-f.maxX),S=Math.abs(u.minY-f.minY)+Math.abs(u.maxY-f.maxY);if(p<this.options.followChaseViewportSnap&&S<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const g=Tt(d*.5,.1,.8),w=new J(du(f.minX,u.minX,g),du(f.minY,u.minY,g),du(f.width,u.width,g),du(f.height,u.height,g)),y=new b(-w.x,-w.y,this.getViewportScreenBounds().width/w.width);this.stopCameraAnimation(),this._setCamera(y)};this.once("stop-following",a),this.addListener("frame",c),c()}),this}stopFollowingUser(){return this.history.ignore(()=>{this.store.put([this.getCamera()]),this._isLockedOnFollowingUser.set(!1),this.updateInstanceState({followingUserId:null}),this.emit("stop-following")}),this}getUnorderedRenderingShapes(t){const r=[];let o=this.options.maxShapesPerPage*2,s=this.options.maxShapesPerPage;const i=this.getErasingShapeIds(),a=(l,d,u)=>{const f=this.getShape(l);if(!f)return;d*=f.opacity;let p=!1;const S=this.getShapeUtil(f);t&&(p=!u&&i.includes(l),p&&(d*=.32)),r.push({id:l,shape:f,util:S,index:o,backgroundIndex:s,opacity:d}),o+=1,s+=1;const g=this.getSortedChildIdsForParent(l);if(!g.length)return;let w=null;S.providesBackgroundForChildren(f)&&(w=s,s=o,o+=this.options.maxShapesPerPage);for(const y of g)a(y,d,u||p);w!==null&&(s=w)},c=t?[this.getCurrentPage()]:this.getPages();for(const l of c)for(const d of this.getSortedChildIdsForParent(l.id))a(d,1,!1);return r}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(o4)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(rn)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(t){return this.store.get(typeof t=="string"?t:t.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getCurrentPageShapeIdsSorted(){return Array.from(this.getCurrentPageShapeIds()).sort()}getPageShapeIds(t){const r=typeof t=="string"?t:t.id,o=this.store.query.exec("shape",{parentId:{eq:r}});return this.getShapeAndDescendantIds(o.map(s=>s.id))}setCurrentPage(t){const r=typeof t=="string"?t:t.id;return this.store.has(r)?(this.stopFollowingUser(),this.complete(),this.batch(()=>this.store.put([{...this.getInstanceState(),currentPageId:r}]),{history:"record-preserveRedoStack"})):(console.error("Tried to set the current page id to a page that doesn't exist."),this)}updatePage(t){return this.getInstanceState().isReadonly?this:this.getPage(t.id)?this.batch(()=>this.store.update(t.id,o=>({...o,...t}))):this}createPage(t){return this.history.batch(()=>{if(this.getInstanceState().isReadonly||this.getPages().length>=this.options.maxPages)return;const r=this.getPages(),o=oK(t.name??"Page 1",r.map(a=>a.name));let s=t.index;(!s||r.some(a=>a.index===s))&&(s=Lo(r[r.length-1].index));const i=Xo.create({meta:{},...t,name:o,index:s});this.store.put([i])}),this}deletePage(t){const r=typeof t=="string"?t:t.id;return this.batch(()=>{if(this.getInstanceState().isReadonly)return;const o=this.getPages();if(o.length===1)return;const s=this.getPage(r);if(s){if(r===this.getCurrentPageId()){const i=o.findIndex(c=>c.id===r),a=o[i-1]??o[i+1];this.setCurrentPage(a.id)}this.store.remove([s.id])}}),this}duplicatePage(t,r=Xo.createId()){if(this.getPages().length>=this.options.maxPages)return this;const o=typeof t=="string"?t:t.id,s=this.getPage(o);if(!s)return this;const i={...this.getCamera()},a=this.getContentFromCurrentPage(this.getSortedChildIdsForParent(s.id));return this.batch(()=>{var d;const c=this.getPages(),l=Kl(s.index,(d=c[c.indexOf(s)+1])==null?void 0:d.index);if(this.createPage({name:s.name+" Copy",id:r,index:l}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(t,r){const o=typeof t=="string"?t:t.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:o,name:r}),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:(this.history.ignore(()=>this.store.put(t)),this)}updateAssets(t){return this.getInstanceState().isReadonly?this:t.length<=0?this:(this.history.ignore(()=>{this.store.put(t.map(r=>({...this.store.get(r.id),...r})))}),this)}deleteAssets(t){if(this.getInstanceState().isReadonly)return this;const r=typeof t[0]=="string"?t:t.map(o=>o.id);return r.length<=0?this:(this.history.ignore(()=>this.store.remove(r)),this)}getAsset(t){return this.store.get(typeof t=="string"?t:t.id)}async resolveAssetUrl(t,r){if(!t)return"";const o=this.getAsset(t);if(!o)return"";const{screenScale:s,shouldResolveToOriginalImage:i}=r,c=Math.max(.125,(u=>Math.pow(2,Math.ceil(Math.log2(u))))(s||1)),l="connection"in navigator?navigator.connection.effectiveType:null,d=this.getInstanceState().devicePixelRatio;return await this._assetOptions.get().onResolveAsset(o,{screenScale:s||1,steppedScreenScale:c,dpr:d,networkEffectiveType:l,shouldResolveToOriginalImage:i})}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",t=>this.getShapeUtil(t).getGeometry(t),(t,r)=>t.props===r.props)}getShapeGeometry(t){return this._getShapeGeometryCache().get(typeof t=="string"?t:t.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",t=>{var r,o;return(o=(r=this.getShapeUtil(t)).getHandles)==null?void 0:o.call(r,t)})}getShapeHandles(t){return this._getShapeHandlesCache().get(typeof t=="string"?t:t.id)}getShapeLocalTransform(t){const r=typeof t=="string"?t:t.id,o=this.getShape(r);if(!o)throw Error("Editor.getTransform: shape not found");return oe.Identity().translate(o.x,o.y).rotate(o.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",t=>{if(Pn(t.parentId))return this.getShapeLocalTransform(t);const r=this._getShapePageTransformCache().get(t.parentId)??oe.Identity();return oe.Compose(r,this.getShapeLocalTransform(t))})}getShapeParentTransform(t){const r=typeof t=="string"?t:t.id,o=this.getShape(r);return!o||Pn(o.parentId)?oe.Identity():this._getShapePageTransformCache().get(o.parentId)??oe.Identity()}getShapePageTransform(t){const r=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(r)??oe.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",t=>{const r=this._getShapePageTransformCache().get(t.id);return r?J.FromPoints(oe.applyToPoints(r,this.getShapeGeometry(t).vertices)):new J})}getShapePageBounds(t){return this._getShapePageBoundsCache().get(typeof t=="string"?t:t.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",t=>{const r=this._getShapeMaskCache().get(t.id);if(!r)return;if(r.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const o=this._getShapePageTransformCache().get(t.id);return o?`polygon(${oe.applyToPoints(oe.Inverse(o),r).map(i=>`${i.x}px ${i.y}px`).join(",")})`:void 0})}getShapeClipPath(t){return this._getShapeClipPathCache().get(typeof t=="string"?t:t.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",t=>{if(Pn(t.parentId))return;const r=this.getShapeAncestors(t.id).filter(s=>this.isShapeOfType(s,"frame"));return r.length===0?void 0:r.map(s=>this._getShapePageTransformCache().get(s.id).applyToPoints(this.getShapeGeometry(s).vertices)).reduce((s,i)=>{if(!(i&&s))return;const a=rC(s,i);return a?a.map(b.Cast):[]})})}getShapeMask(t){return this._getShapeMaskCache().get(typeof t=="string"?t:t.id)}getShapeMaskedPageBounds(t){return typeof t!="string"&&(t=t.id),this._getShapeMaskedPageBoundsCache().get(t)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",t=>{const r=this._getShapePageBoundsCache().get(t.id);if(!r)return;const o=this._getShapeMaskCache().get(t.id);if(o){if(o.length===0)return;const{corners:s}=r;if(s.every((a,c)=>a&&b.Equals(a,o[c])))return r.clone();const i=rC(o,s);return i?J.FromPoints(i):void 0}return r})}getShapeAncestors(t,r=[]){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return r;const i=s.parentId;if(Pn(i))return r.reverse(),r;const a=this.store.get(i);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return;const i=s.parentId;if(Pn(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(t,r){const o=typeof t=="string"?t:t==null?void 0:t.id,s=o&&this.getShape(o);return s?s.parentId===r?!0:this.hasAncestor(this.getShapeParent(s),r):!1}findCommonAncestor(t,r){var l;if(t.length===0)return;const o=typeof t[0]=="string"?t:t.map(d=>d.id),s=Se(o.map(d=>this.getShape(d)));if(s.length===1){const d=s[0].parentId;return Pn(d)?void 0:r?(l=this.findShapeAncestor(s[0],r))==null?void 0:l.id:d}const[i,...a]=s;let c=this.getShapeParent(i);for(;c;){if(r&&!r(c)){c=this.getShapeParent(c);continue}if(a.every(d=>this.hasAncestor(d,c.id)))return c.id;c=this.getShapeParent(c)}}isShapeOrAncestorLocked(t){const r=typeof t=="string"?this.getShape(t):t;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}_notVisibleShapes(){return uK(this)}getCulledShapes(){const t=this._notVisibleShapes().get(),r=this.getSelectedShapeIds(),o=this.getEditingShapeId(),s=new Set(t);return o&&s.delete(o),r.forEach(i=>{s.delete(i)}),s}getCurrentPageBounds(){let t;return this.getCurrentPageShapeIdsSorted().forEach(r=>{const o=this.getShapeMaskedPageBounds(r);o&&(t?t=t.expand(o):t=o.clone())}),t}getSelectedShapeAtPoint(t){const r=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(o=>o.type!=="group"&&r.includes(o.id)).reverse().find(o=>this.isPointInShape(o,t,{hitInside:!0,margin:0}))}getShapeAtPoint(t,r={}){const o=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:i,margin:a=0,hitLocked:c=!1,hitLabels:l=!1,hitInside:d=!1,hitFrameInside:u=!1}=r;let f=1/0,p=null,S=1/0,g=null;const w=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(y=>{if(y.isLocked&&!c||this.isShapeOfType(y,"group"))return!1;const v=this.getShapeMask(y);return v&&!Jn(t,v)?!1:i?i(y):!0});for(let y=w.length-1;y>=0;y--){const v=w[y],P=this.getShapeGeometry(v),E=P instanceof Ur,I=this.getPointInShapeSpace(v,t);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const _ of P.children)if(_.isLabel&&_.isPointInBounds(I))return v}if(this.isShapeOfType(v,"frame")){const _=P.distanceToPoint(I,d);if(Math.abs(_)<=a)return g||v;if(P.hitTestPoint(I,0,!0))return g||p||(u?v:void 0);continue}let C;if(E){let _=1/0;for(const k of P.children){if(k.isLabel&&!l)continue;const j=k.distanceToPoint(I,d);j<_&&(_=j)}C=_}else a===0&&(P.bounds.w<1||P.bounds.h<1)||P.bounds.containsPoint(I,a)?C=P.distanceToPoint(I,d):C=1/0;if(P.isClosed){if(C<=a){if(P.isFilled||E&&P.children[0].isFilled)return g||v;if(this.getShapePageBounds(v).contains(s))continue;if(Math.abs(C)<a)Math.abs(C)<S&&(S=Math.abs(C),g=v);else if(!g){const{area:_}=P;_<f&&(f=_,p=v)}}}else if(C<this.options.hitTestMargin/o)return v}return g||p||void 0}getShapesAtPoint(t,r={}){return this.getCurrentPageShapes().filter(o=>this.isPointInShape(o,t,r))}isPointInShape(t,r,o={}){const{hitInside:s=!1,margin:i=0}=o,a=typeof t=="string"?t:t.id,c=this.getShapeMask(a);return c&&!Jn(r,c)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(t,r),i,s)}getPointInShapeSpace(t,r){const o=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(o).clone().invert().applyToPoint(r)}getPointInParentSpace(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return new b(0,0);if(Pn(s.parentId))return b.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):b.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),t=>this.store.get(t))}getCurrentPageShapesSorted(){const t=[],r=this.getSortedChildIdsForParent(this.getCurrentPageId());for(let o=0,s=r.length;o<s;o++)u$(this,r[o],t);return t}getCurrentPageRenderingShapesSorted(){const t=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:r})=>!t.has(r))}isShapeOfType(t,r){const o=typeof t=="string"?this.getShape(t):t;return o?o.type===r:!1}getShape(t){const r=typeof t=="string"?t:t.id;if(In(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||!In(o.parentId)))return this.store.get(o.parentId)}getShapeNearestSibling(t,r){return r?r.parentId===t.parentId?r:this.findShapeAncestor(r,s=>s.parentId===t.parentId):void 0}isShapeInPage(t,r=this.getCurrentPageId()){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return!1;let i=!1;if(s.parentId===r)i=!0;else{let a=this.getShape(s.parentId);e:for(;a;){if(a.parentId===r){i=!0;break e}a=this.getShape(a.parentId)}}return i}getAncestorPageId(t){const r=typeof t=="string"?t:t==null?void 0:t.id,o=r&&this.getShape(r);if(o)return Pn(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(S=>S.id);if(s.length===0)return this;const i=[],a=Pn(r)?oe.Identity():this.getShapePageTransform(r),c=a.rotation();let l=[];const d=Se(this.getSortedChildIdsForParent(r).map(S=>this.getShape(S)));if(o){const S=d.find(g=>g.index===o);if(S){const g=d[d.indexOf(S)+1];g?l=ic(o,g.index,s.length):l=lm(o,s.length)}else{const g=d.sort(rn).find(w=>w.index>o);g?l=ic(o,g.index,s.length):l=lm(o,s.length)}}else{const S=d.length&&d[d.length-1];l=S?lm(S.index,s.length):Wl(s.length)}const u=a.clone().invert(),f=Se(s.map(S=>this.getShape(S))),p=f.filter(S=>S.isLocked);p.length&&this.updateShapes(p.map(({id:S,type:g})=>({id:S,type:g,isLocked:!1})));for(let S=0;S<f.length;S++){const g=f[S],w=this.getShapePageTransform(g);if(!w)continue;const y=w.point();if(!y)continue;const v=u.applyToPoint(y),P=w.rotation()-c;i.push({id:g.id,type:g.type,parentId:r,x:v.x,y:v.y,rotation:P,index:l[S],isLocked:g.isLocked})}return this.updateShapes(i),this}getHighestIndexForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const s=this.getShape(o[o.length-1]);return Lo(s.index)}getSortedChildIdsForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];return o||Ho}visitDescendants(t,r){const o=typeof t=="string"?t:t.id,s=this.getSortedChildIdsForParent(o);for(const i of s)r(i)!==!1&&this.visitDescendants(i,r);return this}getShapeAndDescendantIds(t){const r=new Set;for(const o of t.map(s=>this.getShape(s)).sort(rn))r.add(o.id),this.visitDescendants(o,s=>{r.add(s)});return r}getDroppingOverShape(t,r=[]){const o=this.getCurrentPageShapesSorted();for(let s=o.length-1;s>=0;s--){const i=o[s];if(this.getSelectedShapeIds().includes(i.id)||!this.getShapeUtil(i).canDropShapes(i,r)||r.find(c=>c.id===i.id||this.hasAncestor(i,c.id)))continue;const a=this.getShapeMaskedPageBounds(i.id);if(a&&a.containsPoint(t)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,t),0,!0))return i}}getOutermostSelectableShape(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);let i=s,a=s;const c=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(c==null?void 0:c.id)!==a.id&&!this.hasAncestor(c,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((c==null?void 0:c.id)===a.id)break;a=this.getShapeParent(a)}return i}_getBindingsIndexCache(){const t=lK(this);return this.store.createComputedCache("bindingsIndex",r=>t.get().get(r.id))}getBinding(t){return this.store.get(t)}getBindingsFromShape(t,r){const o=typeof t=="string"?t:t.id;return this.getBindingsInvolvingShape(o).filter(s=>s.fromId===o&&s.type===r)}getBindingsToShape(t,r){const o=typeof t=="string"?t:t.id;return this.getBindingsInvolvingShape(o).filter(s=>s.toId===o&&s.type===r)}getBindingsInvolvingShape(t,r){const o=typeof t=="string"?t:t.id,s=this._getBindingsIndexCache().get(o)??Ho;return r?s.filter(i=>i.type===r):s}createBindings(t){const r=[];for(const o of t){const s=this.getShape(o.fromId),i=this.getShape(o.toId);if(!s||!i||!this.canBindShapes({fromShape:s,toShape:i,binding:o}))continue;const c=this.getBindingUtil(o.type).getDefaultProps(),l=this.store.schema.types.binding.create({...o,id:o.id??$i(),props:{...c,...o.props}});r.push(l)}return this.store.put(r),this}createBinding(t){return this.createBindings([t])}updateBindings(t){const r=[];for(const o of t){if(!o)continue;const s=this.getBinding(o.id);if(!s)continue;const i=Ao(s,o);if(i===s)continue;const a=this.getShape(i.fromId),c=this.getShape(i.toId);!a||!c||this.canBindShapes({fromShape:a,toShape:c,binding:i})&&r.push(i)}return this.store.put(r),this}updateBinding(t){return this.updateBindings([t])}deleteBindings(t,{isolateShapes:r=!1}={}){const o=t.map(s=>typeof s=="string"?s:s.id);return r?this.store.atomic(()=>{var s,i;for(const a of o){const c=this.getBinding(a);if(!c)continue;const l=this.getBindingUtil(c);(s=l.onBeforeIsolateFromShape)==null||s.call(l,{binding:c,removedShape:this.getShape(c.toId)}),(i=l.onBeforeIsolateToShape)==null||i.call(l,{binding:c,removedShape:this.getShape(c.fromId)}),this.store.remove([a])}}):this.store.remove(o),this}deleteBinding(t,r){return this.deleteBindings([t],r)}canBindShapes({fromShape:t,toShape:r,binding:o}){const s=typeof t=="string"?t:t.type,i=typeof r=="string"?r:r.type,a=typeof o=="string"?o:o.type,c={fromShapeType:s,toShapeType:i,bindingType:a};return s===i?this.getShapeUtil(s).canBind(c):this.getShapeUtil(s).canBind(c)&&this.getShapeUtil(i).canBind(c)}rotateShapesBy(t,r){if((typeof t[0]=="string"?t:t.map(i=>i.id)).length<=0)return this;const s=a$({editor:this});return s?(Th({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(t,r){var i,a,c;let o=t;const s=this.getShapeUtil(t);return o=Ao(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=Ao(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=Ao(o,((a=s.onTranslate)==null?void 0:a.call(s,t,o))??void 0),o=Ao(o,((c=s.onTranslateEnd)==null?void 0:c.call(s,t,o))??void 0),o}nudgeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(i=>i.id);if(o.length<=0)return this;const s=[];for(const i of o){const a=this.getShape(i),c=b.From(r),l=this.getShapeParentTransform(a);l&&c.rot(-l.rotation()),s.push(this.getChangesToTranslateShape(a,c.add(a)))}return this.updateShapes(s),this}duplicateShapes(t,r){return this.history.batch(()=>{const o=typeof t[0]=="string"?t:t.map(f=>f.id);if(o.length<=0)return this;const s=new Set(o),i=this.getShapeAndDescendantIds(o),a=[...i].reverse(),c=new Map;for(const f of i)c.set(f,Fe());const{shapesToCreate:l,bindingsToCreate:d}=lC(this,i,f=>{const p=[];for(const g of f){const w=this.getBinding(g);if(!w)continue;const y=$i();p.push({...w,id:y,fromId:mr(c.get(w.fromId)),toId:mr(c.get(w.toId))})}const S=[];for(const g of a){const w=mr(c.get(g)),y=this.getShape(g);if(!y)continue;let v=0,P=0;if(r&&s.has(g)){const T=this.getShapeParentTransform(y),M=new b(r.x,r.y).rot(-T.rotation());v=M.x,P=M.y}const E=y.parentId,I=this.getSortedChildIdsForParent(E),C=I.indexOf(y.id),_=I[C+1],k=_?this.getShape(_):null,j=k?Kl(y.index,k.index):Lo(y.index);S.push({...y,id:w,x:y.x+v,y:y.y+P,index:j,parentId:c.get(y.parentId)??y.parentId})}return{shapesToCreate:S,bindingsToCreate:p}});if(l.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Fu(this);return}if(this.createShapes(l),this.createBindings(d),this.setSelectedShapes(Se(o.map(f=>c.get(f)))),r!==void 0){const f=this.getSelectionPageBounds(),p=this.getViewportPageBounds();f&&!p.contains(f)&&this.centerOnPoint(f.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(o.length===0)return this;if(this.getInstanceState().isReadonly)return this;const s=this.getCurrentPageId();if(r===s)return this;if(!this.store.has(r))return this;const i=this.getContentFromCurrentPage(o);if(!i)return this;if(this.getPageShapeIds(r).size+i.shapes.length>this.options.maxShapesPerPage)return Fu(this,r),this;const a=this.getCamera().z;return this.history.batch(()=>{this.deleteShapes(o),this.setCurrentPage(r),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(i,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:a}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(t){const r=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly||r.length===0)return this;let o=!0,s=!0;const i=[];for(const a of r){const c=this.getShape(a);c&&(i.push(c),c.isLocked?s=!1:o=!1)}return this.batch(()=>{s?(this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):o?this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Lu(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Lu(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Lu(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Lu(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=Se(o.map(a=>this.getShape(a)));if(!s.length)return this;s=Se(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(c=>this.getShape(c)):a).flat());const i=J.Common(Se(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const c=this.getShapeGeometry(a).bounds,l=this.getShapePageTransform(a.id);l&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:c,initialPageTransform:l,initialShape:a,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(a).isAspectRatioLocked(a),scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(w=>w.id);if(this.getInstanceState().isReadonly)return this;const i=s.map(w=>this.getShape(w)).filter(w=>w?this.getShapeUtil(w).canBeLaidOut(w):!1),a=i.length;if(o===0&&a<3||a<2)return this;const c=Object.fromEntries(i.map(w=>[w.id,this.getShapePageBounds(w)]));let l,d,u,f;r==="horizontal"?(l="x",d="minX",u="maxX",f="width"):(l="y",d="minY",u="maxY",f="height");let p;if(o===0){const w=[];i.sort((v,P)=>c[v.id][d]-c[P.id][d]);for(let v=0;v<a-1;v++){const P=i[v],E=i[v+1],I=c[P.id],_=c[E.id][d]-I[u],k=w.find(j=>j.gap===_);k?k.count++:w.push({gap:_,count:1})}let y=0;w.forEach(v=>{v.count>y&&(y=v.count,p=v.gap)}),y===1&&(p=Math.max(0,w.reduce((v,P)=>v+P.gap*P.count,0)/(a-1)))}else p=o;const S=[];let g=c[i[0].id][u];return i.forEach((w,y)=>{var C,_;if(y===0)return;const v={x:0,y:0};v[l]=g+p-c[w.id][l];const P=this.getShapeParent(w),E=P?b.Rot(v,-this.getShapePageTransform(P).decompose().rotation):v,I=(_=(C=this.getShapeUtil(w)).onTranslateStart)==null?void 0:_.call(C,w);S.push(I?{...I,[l]:w[l]+E[l]}:{id:w.id,type:w.type,[l]:w[l]+E[l]}),g+=c[w.id][f]+p}),this.updateShapes(S),this}packShapes(t,r){var _,k;const o=typeof t[0]=="string"?t:t.map(j=>j.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=o.map(j=>this.getShape(j)).filter(j=>j?this.getShapeUtil(j).canBeLaidOut(j):!1),i={},a={};let c,l,d=0;for(let j=0;j<s.length;j++)c=s[j],l=this.getShapePageBounds(c),i[c.id]=l,a[c.id]=l.clone(),d+=l.width*l.height;const u=J.Common(Se(Object.values(i))),f=u.width;s.sort((j,T)=>i[T.id].height-i[j.id].height);const p=Math.max(Math.ceil(Math.sqrt(d/.95)),f),S=[new J(u.x,u.y,p,1/0)];let g=0,w=0,y,v;for(let j=0;j<s.length;j++){c=s[j],l=a[c.id];for(let T=S.length-1;T>=0;T--)if(y=S[T],!(l.width>y.width||l.height>y.height)){l.x=y.x,l.y=y.y,w=Math.max(w,l.maxY),g=Math.max(g,l.maxX),l.width===y.width&&l.height===y.height?(v=S.pop(),T<S.length&&(S[T]=v)):l.height===y.height?(y.x+=l.width+r,y.width-=l.width+r):l.width===y.width?(y.y+=l.height+r,y.height-=l.height+r):(S.push(new J(y.x+(l.width+r),y.y,y.width-(l.width+r),l.height)),y.y+=l.height+r,y.height-=l.height+r);break}}const P=J.Common(Object.values(a)),E=b.Sub(u.center,P.center);let I;const C=[];for(let j=0;j<s.length;j++){c=s[j],l=i[c.id],I=a[c.id];const T=b.Sub(I.point,l.point).add(E),M=this.getShapeParentTransform(c);M&&T.rot(-M.rotation());const R={id:c.id,type:c.type,x:c.x+T.x,y:c.y+T.y},A=(k=(_=this.getShapeUtil(c)).onTranslateStart)==null?void 0:k.call(_,{...c,...R});A?C.push({...R,...A}):C.push(R)}return C.length&&this.updateShapes(C),this}alignShapes(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=Se(o.map(l=>this.getShape(l))),i=Object.fromEntries(s.map(l=>[l.id,this.getShapePageBounds(l)])),a=J.Common(Se(Object.values(i))),c=[];return s.forEach(l=>{const d=i[l.id];if(!d)return;const u={x:0,y:0};switch(r){case"top":{u.y=a.minY-d.minY;break}case"center-vertical":{u.y=a.midY-d.minY-d.height/2;break}case"bottom":{u.y=a.maxY-d.minY-d.height;break}case"left":{u.x=a.minX-d.minX;break}case"center-horizontal":{u.x=a.midX-d.minX-d.width/2;break}case"right":{u.x=a.maxX-d.minX-d.width;break}}const f=this.getShapeParent(l),p=f?b.Rot(u,-this.getShapePageTransform(f).decompose().rotation):u;c.push(this.getChangesToTranslateShape(l,b.Add(l,p)))}),this.updateShapes(c),this}distributeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(P=>P.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=Se(o.map(P=>this.getShape(P))),a=Object.fromEntries(i.map(P=>[P.id,this.getShapePageBounds(P)]));let c,l,d,u,f;r==="horizontal"?(c="x",l="minX",d="maxX",u="midX",f="width"):(c="y",l="minY",d="maxY",u="midY",f="height");const p=[],S=i.sort((P,E)=>a[P.id][l]-a[E.id][l])[0],g=i.sort((P,E)=>a[E.id][d]-a[P.id][d])[0],w=a[S.id][u],y=(a[g.id][u]-w)/(s-1),v=w+y;return i.filter(P=>P!==S&&P!==g).sort((P,E)=>a[P.id][u]-a[E.id][u]).forEach((P,E)=>{const I={x:0,y:0};I[c]=v+y*E-a[P.id][f]/2-a[P.id][c];const C=this.getShapeParent(P),_=C?b.Rot(I,-this.getShapePageTransform(C).rotation()):I;p.push(this.getChangesToTranslateShape(P,b.Add(P,_)))}),this.updateShapes(p),this}stretchShapes(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=Se(o.map(l=>this.getShape(l))),i=Object.fromEntries(o.map(l=>[l,this.getShapeGeometry(l).bounds])),a=Object.fromEntries(o.map(l=>[l,this.getShapePageBounds(l)])),c=J.Common(Se(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const l of s){if(this.getShapePageTransform(l).rotation()%De)continue;const u=i[l.id],f=a[l.id],p=new b(0,c.minY-f.minY),S=this.getShapeParentTransform(l);S&&p.rot(-S.rotation());const{x:g,y:w}=b.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:w}]);const y=new b(1,c.height/f.height);this.resizeShape(l.id,y,{initialBounds:u,scaleOrigin:new b(f.center.x,c.minY),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const l of s){const d=i[l.id],u=a[l.id];if(this.getShapePageTransform(l).rotation()%De)continue;const p=new b(c.minX-u.minX,0),S=this.getShapeParentTransform(l);S&&p.rot(-S.rotation());const{x:g,y:w}=b.Add(p,l);this.updateShapes([{id:l.id,type:l.type,x:g,y:w}]);const y=new b(c.width/u.width,1);this.resizeShape(l.id,y,{initialBounds:d,scaleOrigin:new b(c.minX,u.center.y),isAspectRatioLocked:this.getShapeUtil(l).isAspectRatioLocked(l),scaleAxisRotation:0})}});break}}return this}resizeShape(t,r,o={}){var S,g,w;const s=typeof t=="string"?t:t.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new b(1,r.y)),Number.isFinite(r.y)||(r=new b(r.x,1));const i=o.initialShape??this.getShape(s);if(!i)return this;const a=o.scaleOrigin??((S=this.getShapePageBounds(s))==null?void 0:S.center);if(!a)return this;const c=o.initialPageTransform?oe.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!c)return this;const l=c.rotation();if(l==null)return this;const d=o.scaleAxisRotation??l,u=o.initialBounds??this.getShapeGeometry(s).bounds;if(!u)return this;const f=o.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!vk(l,d))return this._resizeUnalignedShape(s,r,{...o,initialBounds:u,scaleOrigin:a,scaleAxisRotation:d,initialPageTransform:c,isAspectRatioLocked:f,initialShape:i});const p=this.getShapeUtil(i);if(f&&(Math.abs(r.x)>Math.abs(r.y)?r=new b(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new b(Math.sign(r.x)*Math.abs(r.y),r.y)),p.onResize&&p.canResize(i)){const y=this._scalePagePoint(oe.applyToPoint(c,new b(0,0)),a,r,d),v=this.getPointInParentSpace(i.id,y),P=new b(r.x,r.y),E=Os((l-d)%Math.PI,0);P.x=E?r.x:r.y,P.y=E?r.y:r.x;const I=oe.applyToPoint(c,new b),{x:C,y:_}=this.getPointInParentSpace(i.id,I);let k=i;o.skipStartAndEndCallbacks||(k=Ao(i,((g=p.onResizeStart)==null?void 0:g.call(p,i))??void 0)),k=Ao(k,{id:s,type:i.type,x:v.x,y:v.y,...p.onResize({...i,x:C,y:_},{newPoint:v,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:P.x,scaleY:P.y,initialBounds:u,initialShape:i})}),o.skipStartAndEndCallbacks||(k=Ao(k,((w=p.onResizeEnd)==null?void 0:w.call(p,i,k))??void 0)),this.updateShapes([k])}else{const y=oe.applyToPoint(c,u.center),v=this._scalePagePoint(y,a,r,d),P=this.getPointInParentSpace(i.id,y),E=this.getPointInParentSpace(i.id,v),I=b.Sub(E,P);this.updateShapes([{id:s,type:i.type,x:i.x+I.x,y:i.y+I.y}])}return this}_scalePagePoint(t,r,o,s){const i=b.RotWith(t,r,-s).sub(r),a=b.MulV(i,o);return b.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(t,r,o){const{type:s}=o.initialShape,i=new b(r.x,r.y);if(Math.abs(r.x)>Math.abs(r.y)?i.x=Math.sign(r.x)*Math.abs(r.y):i.y=Math.sign(r.y)*Math.abs(r.x),this.resizeShape(t,i,{initialShape:o.initialShape,initialBounds:o.initialBounds,isAspectRatioLocked:o.isAspectRatioLocked}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:y}=oe.Decompose(o.initialPageTransform);y-=2*y,this.updateShapes([{id:t,type:s,rotation:y}])}const a=oe.applyToPoint(o.initialPageTransform,o.initialBounds.center),c=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),l=this.getShapePageBounds(t),d=this.getShapePageTransform(t),u=l.center,f=d.point();if(!u||!f)return this;const p=b.Sub(c,u),S=b.Add(f,p),{x:g,y:w}=this.getPointInParentSpace(t,S);return this.updateShapes([{id:t,type:s,x:g,y:w}]),this}getInitialMetaForShape(t){return{}}createShape(t){return this.createShapes([t]),this}createShapes(t){if(!Array.isArray(t))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");if(this.getInstanceState().isReadonly)return this;if(t.length<=0)return this;const r=this.getCurrentPageShapeIds();if(t.length+r.size>this.options.maxShapesPerPage)return Fu(this),this;const s=this.getFocusedGroupId();return this.batch(()=>{var u,f;const i=this.getCurrentPageShapesSorted(),a=t.map(p=>{if(p.id||(p={id:Fe(),...p}),!p.parentId||!(this.store.has(p.parentId)||t.some(S=>S.id===p.parentId))){let S=this.getFocusedGroupId();for(let w=i.length-1;w>=0;w--){const y=i[w];if(this.getShapeUtil(y).canReceiveNewChildrenOfType(y,p.type)&&this.isPointInShape(y,{x:p.x??0,y:p.y??0},{margin:0,hitInside:!0})){S=y.id;break}}const g=p.parentId;if(S===p.id&&(S=s),S!==g&&(p={...p},p.parentId=S,In(S))){const w=this.getPointInShapeSpace(this.getShape(S),{x:p.x??0,y:p.y??0});p.x=w.x,p.y=w.y,p.rotation=-this.getShapePageTransform(S).rotation()+(p.rotation??0)}}return p}),c=new Map,l=[],{opacityForNextShape:d}=this.getInstanceState();for(const p of a){const S=this.getShapeUtil(p);let g=p.index;if(!g){const P=p.parentId??s;c.has(P)||c.set(P,this.getHighestIndexForParent(P)),g=c.get(P),c.set(P,Lo(g))}const w=S.getDefaultProps();for(const[P,E]of this.styleProps[p.type])w[E]=this.getStyleForNextShape(P);let y=this.store.schema.types.shape.create({...p,index:g,opacity:p.opacity??d,parentId:p.parentId??s,props:"props"in p?{...w,...p.props}:w});if(y.index===void 0)throw Error("no index!");const v=(f=(u=this.getShapeUtil(y)).onBeforeCreate)==null?void 0:f.call(u,y);v&&(y=v),l.push(y)}l.forEach(p=>{p.meta={...this.getInitialMetaForShape(p),...p.meta}}),this.store.put(l)})}animateShape(t,r={animation:gm}){return this.animateShapes([t],r)}animateShapes(t,r={animation:gm}){if(!r.animation)return this;const{duration:o=500,easing:s=At.linear}=r.animation,i=st();let a=o,c;const l=[];let d,u;for(let S=0,g=t.length;S<g;S++){if(d=t[S],!d)continue;u={partial:d,values:[]};const w=this.getShape(d.id);if(w){for(const y of["x","y","rotation"])d[y]!==void 0&&w[y]!==d[y]&&u.values.push({prop:y,from:w[y],to:d[y]});l.push(u),this.animatingShapes.set(w.id,i)}}let f;const p=S=>{if(a-=S,a<0){const{animatingShapes:v}=this,P=t.filter(E=>E&&v.get(E.id)===i);P.length&&this.updateShapes(P),this.off("tick",p);return}c=s(1-a/o);const{animatingShapes:g}=this,w=[];let y;for(let v=0,P=l.length;v<P;v++)f=l[v],y=g.get(f.partial.id),y===i&&w.push({id:f.partial.id,type:f.partial.type,...f.values.reduce((E,{prop:I,from:C,to:_})=>(E[I]=C+(_-C)*c,E),{})});this._updateShapes(w)};return this.on("tick",p),this}groupShapes(t,r={}){var g;const{groupId:o=Fe(),select:s=!0}=r;if(!Array.isArray(t))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const i=typeof t[0]=="string"?t:t.map(w=>w.id);if(i.length<=1)return this;const a=Se(this._getUnlockedShapeIds(i).map(w=>this.getShape(w))),c=a.sort(rn).map(w=>w.id),l=J.Common(Se(a.map(w=>this.getShapePageBounds(w)))),{x:d,y:u}=l.point,f=this.findCommonAncestor(a)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const p=a.filter(w=>w.parentId===f).sort(rn),S=(g=p[p.length-1])==null?void 0:g.index;return this.batch(()=>{this.createShapes([{id:o,type:"group",parentId:f,index:S,x:d,y:u,opacity:1,props:{}}]),this.reparentShapes(c,o),s&&this.select(o)}),this}ungroupShapes(t,r={}){const{select:o=!0}=r,s=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(s.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const i=new Set,a=[];return Se(s.map(c=>this.getShape(c))).forEach(c=>{this.isShapeOfType(c,"group")?a.push(c):i.add(c.id)}),a.length===0?this:(this.batch(()=>{let c;for(let l=0,d=a.length;l<d;l++){c=a[l];const u=this.getSortedChildIdsForParent(c.id);for(let f=0,p=u.length;f<p;f++)i.add(u[f]);this.reparentShapes(u,c.parentId,c.index)}this.deleteShapes(a.map(l=>l.id)),o&&this.select(...i)}),this)}updateShape(t){return this.updateShapes([t]),this}updateShapes(t){const r=Array(t.length);for(let o=0,s=t.length;o<s;o++){const i=t[o];if(!i)continue;const a=this.getShape(i.id);a&&(this.isShapeOrAncestorLocked(a)&&!Object.hasOwn(i,"isLocked")||(this.animatingShapes.delete(i.id),r.push(i)))}return this._updateShapes(r),this}_getUnlockedShapeIds(t){return t.filter(r=>{var o;return!((o=this.getShape(r))!=null&&o.isLocked)})}deleteShapes(t){if(!Array.isArray(t))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");const r=this._getUnlockedShapeIds(typeof t[0]=="string"?t:t.map(i=>i.id));if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;const o=new Set(r);for(const i of r)this.visitDescendants(i,a=>{o.add(a)});const s=[...o];return this.batch(()=>this.store.remove(s))}deleteShape(t){return this.deleteShapes([typeof t=="string"?t:t.id]),this}_extractSharedStyles(t,r){if(this.isShapeOfType(t,"group")){const o=this._parentIdsToChildIds.get()[t.id];if(!o)return;for(let s=0,i=o.length;s<i;s++)this._extractSharedStyles(this.getShape(o[s]),r)}else for(const[o,s]of this.styleProps[t.type])r.applyValue(o,Tn(t.props,s))}_getSelectionSharedStyles(){const t=this.getSelectedShapes(),r=new fv;for(const o of t)this._extractSharedStyles(o,r);return r}getStyleForNextShape(t){const r=this.getInstanceState().stylesForNextShape[t.id];return r===void 0?t.defaultValue:r}getShapeStyleIfExists(t,r){const o=this.styleProps[t.type].get(r);if(o!==void 0)return Tn(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const t=this.root.getCurrent(),r=new fv;if(!t)return r;if(t.shapeType)for(const o of this.styleProps[t.shapeType].keys())r.applyValue(o,this.getStyleForNextShape(o));return r}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const t=[],r=s=>{const i=this.getShape(s);if(i)if(this.isShapeOfType(i,"group"))for(const a of this.getSortedChildIdsForParent(i.id))r(a);else t.push(i)};for(const s of this.getSelectedShapeIds())r(s);let o=null;for(const s of t)if(o===null)o=s.opacity;else if(o!==s.opacity)return{type:"mixed"};if(o!==null)return{type:"shared",value:o}}return{type:"shared",value:this.getInstanceState().opacityForNextShape}}setOpacityForNextShapes(t,r){return this.updateInstanceState({opacityForNextShape:t},r),this}setOpacityForSelectedShapes(t){const r=this.getSelectedShapes();if(r.length>0){const o=[],s=i=>{if(this.isShapeOfType(i,"group")){const a=this.getSortedChildIdsForParent(i);for(const c of a)s(this.getShape(c))}else o.push(i)};for(const i of r)s(i);this.updateShapes(o.map(i=>({id:i.id,type:i.type,opacity:t})))}return this}setStyleForNextShapes(t,r,o){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[t.id]:r}},o),this}setStyleForSelectedShapes(t,r){const o=this.getSelectedShapes();if(o.length>0){const s=[],i=a=>{if(this.isShapeOfType(a,"group")){const c=this.getSortedChildIdsForParent(a.id);for(const l of c)i(this.getShape(l))}else{const c=this.getShapeUtil(a),l=this.styleProps[a.type].get(t);if(l){const d={id:a.id,type:a.type,props:{[l]:r}};s.push({util:c,originalShape:a,updatePartial:d})}}};for(const a of o)i(a);this.updateShapes(s.map(({updatePartial:a})=>a))}return this}registerExternalAssetHandler(t,r){return this.externalAssetContentHandlers[t]=r,this}async getAssetForExternalContent(t){var r,o;return await((o=(r=this.externalAssetContentHandlers)[t.type])==null?void 0:o.call(r,t))}hasExternalAssetHandler(t){return!!this.externalAssetContentHandlers[t]}registerExternalContentHandler(t,r){return this.externalContentHandlers[t]=r,this}async putExternalContent(t){var r,o;return(o=(r=this.externalContentHandlers)[t.type])==null?void 0:o.call(r,t)}getContentFromCurrentPage(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id);if(!r||r.length===0)return;const o=this.getShapeAndDescendantIds(r);return lC(this,o,s=>{const i=[];for(const u of s){const f=this.getBinding(u);f&&i.push(f)}const a=[],c=[];for(const u of o){const f=this.getShape(u);if(!f)continue;if(!o.has(f.parentId)){const S=this.getShapePageTransform(f.id),g=S.point();c.push({...f,x:g.x,y:g.y,rotation:S.rotation(),parentId:this.getCurrentPageId()}),a.push(f.id)}else c.push(f)}const l=[],d=new Set;for(const u of c){if(!("assetId"in u.props))continue;const f=u.props.assetId;if(!f||d.has(f))continue;d.add(f);const p=this.getAsset(f);p&&l.push(p)}return{schema:this.store.schema.serialize(),shapes:c,rootShapeIds:a,bindings:i,assets:l}})}async resolveAssetsInContent(t){if(!t)return;const r=[];return await Promise.allSettled(t.assets.map(async o=>{var s,i;if((o.type==="image"||o.type==="video")&&!((s=o.props.src)!=null&&s.startsWith("data:image"))&&!((i=o.props.src)!=null&&i.startsWith("http"))){const a=ot(o),c=await this._assetOptions.get().onResolveAsset(o,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginalImage:!0});a.props.src=await ki.blobToDataUrl(await go(c).then(l=>l.blob())),r.push(a)}else r.push(o)})),t.assets=r,t}putContentOntoCurrentPage(t,r={}){var M,R;if(this.getInstanceState().isReadonly)return this;if(!t.schema)throw Error(`Could not put content:
|
|
90
|
-
content is missing a schema.`);const{select:o=!1,preserveIds:s=!1,preservePosition:i=!1}=r;let{point:a=void 0}=r;const c=this.getCurrentPageId(),{rootShapeIds:l}=t,d=[],u=[],f=[],p={store:{...Object.fromEntries(t.assets.map(A=>[A.id,A])),...Object.fromEntries(t.shapes.map(A=>[A.id,A])),...Object.fromEntries(((M=t.bindings)==null?void 0:M.map(A=>[A.id,A]))??[])},schema:t.schema},S=this.store.schema.migrateStoreSnapshot(p);if(S.type==="error")throw Error("Could not put content: could not migrate content");for(const A of Object.values(S.value))switch(A.typeName){case"asset":{d.push(A);break}case"shape":{u.push(A);break}case"binding":{f.push(A);break}}const g=new Map(s?u.map(A=>[A.id,A.id]):u.map(A=>[A.id,Fe()])),w=new Map(s?f.map(A=>[A.id,A.id]):f.map(A=>[A.id,$i()]));let y=this.getCurrentPageId(),v=1/0,P=[];for(const A of this.getSelectedShapes()){if(v===0)break;const O=this.isShapeOfType(A,"frame"),L=this.getShapeAncestors(A);O&&L.push(A);const G=O?L.length+1:L.length;if(G<v)v=G,P=L,y=O?A.id:A.parentId;else if(G===v){if(P.length!==L.length)throw Error(`Ancestors: ${P.length} !== ${L.length}`);if(P.length===0){y=c;break}else{y=c;for(let K=0;K<P.length&&L[K]===P[K];K++)y=L[K].id}}}let E=!1;if(!Pn(y)){const A=this.getShape(y);if(A){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(A)))y=c;else if(l.length===1){const O=u.find(L=>L.id===l[0]);this.isShapeOfType(A,"frame")&&this.isShapeOfType(O,"frame")&&O.props.w===(A==null?void 0:A.props.w)&&O.props.h===(A==null?void 0:A.props.h)&&(E=!0)}}else y=c}E||(E=g.has(y)),E&&(y=this.getShape(y).parentId);let I=this.getHighestIndexForParent(y);const C=[],_=u.map(A=>{const O=g.get(A.id),L={...A,id:O};return l.includes(A.id)&&(L.parentId=c,C.push(L)),g.has(L.parentId)?L.parentId=g.get(A.parentId):(l.push(L.id),L.index=I,I=Lo(I)),L});if(_.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Fu(this),this;const k=f.map(A=>({...A,id:mr(w.get(A.id)),fromId:mr(g.get(A.fromId)),toId:mr(g.get(A.toId))})),j=[],T=[];for(const A of d)this.store.has(A.id)||((A.type==="image"||A.type==="video")&&((R=A.props.src)!=null&&R.startsWith("data:image"))&&(T.push(ot(A)),A.props.src=null),j.push(A));return Promise.allSettled(T.map(async A=>{const O=await rK(A.props.src,A.props.name,A.props.mimeType??"image/png"),L=await this.getAssetForExternalContent({type:"file",file:O});if(!L){this.deleteAssets([A.id]);return}this.updateAssets([{...L,id:A.id}])})),this.batch(()=>{j.length>0&&this.createAssets(j),this.createShapes(_),this.createBindings(k),o&&this.select(...C.map(K=>K.id)),y!==c&&this.reparentShapes(C.map(K=>K.id),y);const A=_.map(K=>this.getShape(K.id)),O=J.Common(A.map(K=>this.getShapePageBounds(K)));if(a===void 0)if(Pn(y)){const K=this.getViewportPageBounds();i||K.includes(J.From(O))?a=O.center:a=K.center}else{const K=this.getShape(y);a=oe.applyToPoint(this.getShapePageTransform(K),this.getShapeGeometry(K).bounds.center)}if(C.length===1){const K=C[0];if(this.isShapeOfType(K,"frame"))for(;this.getShapesAtPoint(a).some(B=>this.isShapeOfType(B,"frame")&&B.props.w===K.props.w&&B.props.h===K.props.h);)a.x+=O.w+16}const L=J.Common(Se(C.map(({id:K})=>this.getShapePageBounds(K)))).center,G=b.Sub(a,L);this.updateShapes(C.map(({id:K})=>{const B=this.getShape(K),U=this.getShapeParentTransform(K).decompose().rotation,Y=b.Rot(G,-U);return{id:B.id,type:B.type,x:B.x+Y.x,y:B.y+Y.y}}))}),this}async getSvgElement(t,r={}){const o=await gK(this,t,r);if(!o)return;const s=document.createDocumentFragment(),i=Z2(s);oa.flushSync(()=>{i.render(o.jsx)});const a=s.firstElementChild;return it(a instanceof SVGSVGElement,"Expected an SVG element"),i.unmount(),{svg:a,width:o.width,height:o.height}}async getSvgString(t,r={}){const o=await this.getSvgElement(t,r);return o?{svg:new XMLSerializer().serializeToString(o.svg),width:o.width,height:o.height}:void 0}async getSvg(t,r={}){const o=await this.getSvgElement(t,r);if(o)return o.svg}_updateInputsFromEvent(t){const{pointerVelocity:r,previousScreenPoint:o,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:c}=this.store.unsafeGetWithoutCapture(pn),{x:l,y:d,z:u}=this.store.unsafeGetWithoutCapture(this.getCameraId()),f=t.point.x-c.x,p=t.point.y-c.y,S=t.point.z??.5;o.setTo(i),s.setTo(a),i.set(f,p);const g=f/u-l,w=p/u-d;isFinite(g)&&isFinite(w)&&a.set(g,w,S),this.inputs.isPen=t.type==="pointer"&&t.isPen,(t.name==="pointer_down"||this.inputs.isPinching)&&(r.set(0,0),this.inputs.originScreenPoint.setTo(i),this.inputs.originPagePoint.setTo(a)),this.history.ignore(()=>{var y;this.store.put([{id:Mf,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===$1.CAMERA_MOVE?((y=this.store.unsafeGetWithoutCapture(Mf))==null?void 0:y.lastActivityTimestamp)??this._tickManager.now:this._tickManager.now,meta:{}}])})}cancel(){return this.dispatch({type:"misc",name:"cancel"}),this}interrupt(){return this.dispatch({type:"misc",name:"interrupt"}),this}complete(){return this.dispatch({type:"misc",name:"complete"}),this}focus({focusContainer:t=!0}={}){return t&&this.focusManager.focus(),this.updateInstanceState({isFocused:!0}),this}blur({blurContainer:t=!0}={}){return this.getIsFocused()?(t?this.focusManager.blur():this.complete(),this.updateInstanceState({isFocused:!1}),this):this}getIsFocused(){return this.getInstanceState().isFocused}getSnapshot(){return YH(this.store)}loadSnapshot(t){return n$(this.store,t),this}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_flushEventsForTick(t){this.batch(()=>{if(this._pendingEventsForNextTick.length>0){const r=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const o of r)this._flushEventForTick(o)}t>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:t}),this.scribbles.tick(t)})}maybeTrackPerformance(t){wt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(t),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}re([V],ee.prototype,"getCanUndo");re([V],ee.prototype,"getCanRedo");re([V],ee.prototype,"getPath");re([V],ee.prototype,"getCurrentTool");re([V],ee.prototype,"getCurrentToolId");re([V],ee.prototype,"getDocumentSettings");re([V],ee.prototype,"getInstanceState");re([V],ee.prototype,"getOpenMenus");re([V],ee.prototype,"getIsMenuOpen");re([V],ee.prototype,"getPageStates");re([V],ee.prototype,"_getPageStatesQuery");re([V],ee.prototype,"getCurrentPageState");re([V],ee.prototype,"_getCurrentPageStateId");re([V],ee.prototype,"getSelectedShapeIds");re([V],ee.prototype,"getSelectedShapes");re([V],ee.prototype,"getOnlySelectedShapeId");re([V],ee.prototype,"getOnlySelectedShape");re([V],ee.prototype,"getSelectionPageBounds");re([V],ee.prototype,"getSelectionRotation");re([V],ee.prototype,"getSelectionRotatedPageBounds");re([V],ee.prototype,"getSelectionRotatedScreenBounds");re([V],ee.prototype,"getFocusedGroupId");re([V],ee.prototype,"getFocusedGroup");re([V],ee.prototype,"getEditingShapeId");re([V],ee.prototype,"getEditingShape");re([V],ee.prototype,"getHoveredShapeId");re([V],ee.prototype,"getHoveredShape");re([V],ee.prototype,"getHintingShapeIds");re([V],ee.prototype,"getHintingShape");re([V],ee.prototype,"getErasingShapeIds");re([V],ee.prototype,"getErasingShapes");re([V],ee.prototype,"getCameraId");re([V],ee.prototype,"getCamera");re([V],ee.prototype,"getViewportPageBoundsForFollowing");re([V],ee.prototype,"getCameraForFollowing");re([V],ee.prototype,"getZoomLevel");re([V],ee.prototype,"getViewportScreenBounds");re([V],ee.prototype,"getViewportScreenCenter");re([V],ee.prototype,"getViewportPageBounds");re([V],ee.prototype,"_getCollaboratorsQuery");re([V],ee.prototype,"getCollaborators");re([V],ee.prototype,"getCollaboratorsOnCurrentPage");re([V],ee.prototype,"getRenderingShapes");re([V],ee.prototype,"_getAllPagesQuery");re([V],ee.prototype,"getPages");re([V],ee.prototype,"getCurrentPageId");re([V],ee.prototype,"getCurrentPageShapeIdsSorted");re([V],ee.prototype,"_getAllAssetsQuery");re([V],ee.prototype,"_getShapeGeometryCache");re([V],ee.prototype,"_getShapeHandlesCache");re([V],ee.prototype,"_getShapePageTransformCache");re([V],ee.prototype,"_getShapePageBoundsCache");re([V],ee.prototype,"_getShapeClipPathCache");re([V],ee.prototype,"_getShapeMaskCache");re([V],ee.prototype,"_getShapeMaskedPageBoundsCache");re([V],ee.prototype,"_notVisibleShapes");re([V],ee.prototype,"getCulledShapes");re([V],ee.prototype,"getCurrentPageBounds");re([V],ee.prototype,"getCurrentPageShapes");re([V],ee.prototype,"getCurrentPageShapesSorted");re([V],ee.prototype,"getCurrentPageRenderingShapesSorted");re([V],ee.prototype,"_getBindingsIndexCache");re([V],ee.prototype,"_getSelectionSharedStyles");re([V({isEqual:(e,n)=>e.equals(n)})],ee.prototype,"getSharedStyles");re([V],ee.prototype,"getSharedOpacity");re([V],ee.prototype,"getIsFocused");function Fu(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:e.options.maxShapesPerPage})}function Ao(e,n){if(!n)return e;let t=null;const r=Object.entries(n);for(let o=0,s=r.length;o<s;o++){const[i,a]=r[o];if(a!==void 0&&!(i==="id"||i==="type"||i==="typeName")&&a!==e[i]){if(t||(t={...e}),i==="props"||i==="meta"){t[i]={...e[i]};for(const[c,l]of Object.entries(a))l!==void 0&&(t[i][c]=l);continue}t[i]=a}}return t||e}function u$(e,n,t){const r=e.getShape(n);if(!r)return;t.push(r);const o=e.getSortedChildIdsForParent(n);for(let s=0,i=o.length;s<i;s++)u$(e,o[s],t)}function lC(e,n,t){let r;if(e.history.ignore(()=>{const o=e.store.extractingChanges(()=>{const s=new Set,i=new Set;for(const a of n)if(e.getShape(a))for(const l of e.getBindingsInvolvingShape(a)){const d=n.has(l.fromId),u=n.has(l.toId);if(d&&u){s.add(l.id);continue}(!d||!u)&&i.add(l.id)}e.deleteBindings([...i],{isolateShapes:!0});try{r=fn.ok(t(s))}catch(a){r=fn.err(a)}});e.store.applyDiff(lS(o))}),r.ok)return r.value;throw r.error}function dC(e,n){if(!n.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=n.constraints,o=e.getViewportScreenBounds(),s=J.From(n.constraints.bounds),i=(o.w-t*2)/s.w,a=(o.h-r*2)/s.h;return{zx:i,zy:a}}function Kd(){const e=N(),n=l$();return W("isDarkMode",()=>(n==null?void 0:n.isDarkMode)??e.user.getIsDarkMode(),[n,e])}const uC="<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'/>",hC="<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'/>",zu='<path d="M22.4789 9.45728L25.9935 12.9942L22.4789 16.5283V14.1032C18.126 14.1502 14.6071 17.6737 14.5675 22.0283H17.05L13.513 25.543L9.97889 22.0283H12.5674C12.6071 16.5691 17.0214 12.1503 22.4789 12.1031L22.4789 9.45728Z" fill="black"/><path fill-rule="evenodd" clip-rule="evenodd" d="M21.4789 7.03223L27.4035 12.9945L21.4789 18.9521V15.1868C18.4798 15.6549 16.1113 18.0273 15.649 21.0284H19.475L13.5128 26.953L7.55519 21.0284H11.6189C12.1243 15.8155 16.2679 11.6677 21.4789 11.1559L21.4789 7.03223ZM22.4789 12.1031C17.0214 12.1503 12.6071 16.5691 12.5674 22.0284H9.97889L13.513 25.543L17.05 22.0284H14.5675C14.5705 21.6896 14.5947 21.3558 14.6386 21.0284C15.1157 17.4741 17.9266 14.6592 21.4789 14.1761C21.8063 14.1316 22.1401 14.1069 22.4789 14.1032V16.5284L25.9935 12.9942L22.4789 9.45729L22.4789 12.1031Z" fill="white"/>';function ys(e,n,t,r,o,s=16,i=16){const a=(-t-n)*(ke/180),c=Math.sin(a),l=Math.cos(a),d=1*l-1*c,u=1*c+1*l;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${d}' dy='${u}' 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 YK=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],XK={none:()=>"none","ew-resize":(e,n,t)=>ys(hC,e,0,n,t),"ns-resize":(e,n,t)=>ys(hC,e,90,n,t),"nesw-resize":(e,n,t)=>ys(uC,e,0,n,t),"nwse-resize":(e,n,t)=>ys(uC,e,90,n,t),"nwse-rotate":(e,n,t)=>ys(zu,e,0,n,t),"nesw-rotate":(e,n,t)=>ys(zu,e,90,n,t),"senw-rotate":(e,n,t)=>ys(zu,e,180,n,t),"swne-rotate":(e,n,t)=>ys(zu,e,270,n,t)};function Wn(e,n=0,t="black"){return XK[e](d7(n),!1,t)}function qK(){const e=N(),n=dn(),t=Kd();js("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(YK.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Wn(r,o,t?"white":"black"))},[e,n,t])}function ZK(){const e=N(),n=dn(),t=Kd(),r=W(wt.forceSrgb);ve.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 Hx(e){const n=x.useRef();return x.useLayoutEffect(()=>{n.current=e}),x.useDebugValue(e),x.useCallback((...t)=>{const r=n.current;return it(r,"fn does not exist"),r(...t)},[])}function QK(){const[e,n]=x.useState(0);x.useEffect(()=>n(t=>t+1),[])}function JK(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
|
|
91
|
-
|
|
92
|
-
Keep seeing this message?
|
|
93
|
-
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
|
|
94
|
-
• If your hard disk is full, try clearing up some space and then reload the page.`)}function eW(){window.alert(`Oops! We could not access your browser's storage—and the app won't work correctly without that. We now need to reload the page and try again.
|
|
95
|
-
|
|
96
|
-
Keep seeing this message?
|
|
97
|
-
• If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const tW=(e,n)=>n.some(t=>e instanceof t);let fC,pC;function nW(){return fC||(fC=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function rW(){return pC||(pC=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const h$=new WeakMap,pv=new WeakMap,f$=new WeakMap,Ym=new WeakMap,Kx=new WeakMap;function oW(e){const n=new Promise((t,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{t(Wo(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return n.then(t=>{t instanceof IDBCursor&&h$.set(t,e)}).catch(()=>{}),Kx.set(n,e),n}function sW(e){if(pv.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)});pv.set(e,n)}let gv={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return pv.get(e);if(n==="objectStoreNames")return e.objectStoreNames||f$.get(e);if(n==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Wo(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 iW(e){gv=e(gv)}function aW(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(Xm(this),n,...t);return f$.set(r,n.sort?n.sort():[n]),Wo(r)}:rW().includes(e)?function(...n){return e.apply(Xm(this),n),Wo(h$.get(this))}:function(...n){return Wo(e.apply(Xm(this),n))}}function cW(e){return typeof e=="function"?aW(e):(e instanceof IDBTransaction&&sW(e),tW(e,nW())?new Proxy(e,gv):e)}function Wo(e){if(e instanceof IDBRequest)return oW(e);if(Ym.has(e))return Ym.get(e);const n=cW(e);return n!==e&&(Ym.set(e,n),Kx.set(n,e)),n}const Xm=e=>Kx.get(e);function p$(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=Wo(i);return r&&i.addEventListener("upgradeneeded",c=>{r(Wo(i.result),c.oldVersion,c.newVersion,Wo(i.transaction),c)}),t&&i.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),a.then(c=>{s&&c.addEventListener("close",()=>s()),o&&c.addEventListener("versionchange",l=>o(l.oldVersion,l.newVersion,l))}).catch(()=>{}),a}function lW(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),Wo(t).then(()=>{})}const dW=["get","getKey","getAll","getAllKeys","count"],uW=["put","add","delete","clear"],qm=new Map;function gC(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(qm.get(n))return qm.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=uW.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||dW.includes(t)))return;const s=async function(i,...a){const c=this.transaction(i,o?"readwrite":"readonly");let l=c.store;return r&&(l=l.index(a.shift())),(await Promise.all([l[t](...a),o&&c.done]))[0]};return qm.set(n,s),s}iW(e=>({...e,get:(n,t,r)=>gC(n,t)||e.get(n,t,r),has:(n,t)=>!!gC(n,t)||e.has(n,t)}));const tg="TLDRAW_DOCUMENT_v2",g$="TLDRAW_DB_NAME_INDEX_v2",Le={Records:"records",Schema:"schema",SessionState:"session_state"};async function ng(e,n){mW(e);const t=await p$(e,3,{upgrade(r){r.objectStoreNames.contains(Le.Records)||r.createObjectStore(Le.Records),r.objectStoreNames.contains(Le.Schema)||r.createObjectStore(Le.Schema),r.objectStoreNames.contains(Le.SessionState)||r.createObjectStore(Le.SessionState)}});try{return await n(t)}finally{t.close()}}async function hW({persistenceKey:e,sessionId:n,didCancel:t}){const r=tg+e;if(Wx().includes(r))return await gW({persistenceKey:e,didCancel:t}),await ng(r,async o=>{var u,f;if(t!=null&&t())return;const s=o.transaction([Le.Records,Le.Schema,Le.SessionState],"readonly"),i=s.objectStore(Le.Records),a=s.objectStore(Le.Schema),c=s.objectStore(Le.SessionState);let l=n?(u=await c.get(n))==null?void 0:u.snapshot:null;l||(l=(f=(await c.getAll()).sort((S,g)=>S.updatedAt-g.updatedAt).pop())==null?void 0:f.snapshot);const d={records:await i.getAll(),schema:await a.get(Le.Schema),sessionStateSnapshot:l};if(t!=null&&t()){s.abort();return}return await s.done,d})}async function fW({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=tg+e;await ng(i,async a=>{const c=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),l=c.objectStore(Le.Records),d=c.objectStore(Le.Schema),u=c.objectStore(Le.SessionState);for(const[f,p]of Object.entries(t.added))await l.put(p,f);for(const[f,p]of Object.values(t.updated))await l.put(p,p.id);for(const f of Object.keys(t.removed))await l.delete(f);if(d.put(n.serialize(),Le.Schema),o&&r?u.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return c.abort();await c.done})}async function pW({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=tg+e;await ng(i,async a=>{const c=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),l=c.objectStore(Le.Records),d=c.objectStore(Le.Schema),u=c.objectStore(Le.SessionState);await l.clear();for(const[f,p]of Object.entries(t))await l.put(p,f);if(d.put(n.serialize(),Le.Schema),o&&r?u.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return c.abort();await c.done})}async function gW({persistenceKey:e,didCancel:n}){await ng(tg+e,async t=>{const r=t.transaction([Le.SessionState],"readwrite"),o=r.objectStore(Le.SessionState),s=(await o.getAll()).sort((a,c)=>a.updatedAt-c.updatedAt);if(s.length<10){await r.done;return}const i=s.slice(0,s.length-10);for(const{id:a}of i)await o.delete(a);if(n!=null&&n())return r.abort();await r.done})}function Wx(){const e=JSON.parse(I0(g$)||"[]")??[];return Array.isArray(e)?e:[]}function mW(e){const n=new Set(Wx());n.add(e),E0(g$,JSON.stringify([...n]))}const yW=350,SW=1e4,mC=Symbol("UPDATE_INSTANCE_STATE"),vW=e=>e;class xW{constructor(n){m(this,"onmessage")}postMessage(n){}close(){}}const wW=typeof BroadcastChannel>"u"?xW:BroadcastChannel;class bW{constructor(n,{persistenceKey:t,sessionId:r=cp,onLoad:o,onLoadError:s},i=new wW(`tldraw-tab-sync-${t}`)){m(this,"disposables",new Set);m(this,"diffQueue",[]);m(this,"didDispose",!1);m(this,"shouldDoFullDBWrite",!0);m(this,"isReloading",!1);m(this,"persistenceKey");m(this,"sessionId");m(this,"serializedSchema");m(this,"isDebugging",!1);m(this,"documentTypes");m(this,"$sessionStateSnapshot");m(this,"initTime",Date.now());m(this,"isPersisting",!1);m(this,"didLastWriteError",!1);m(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=e$(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(vW({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(mC),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 hW({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),eW(),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??GH(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&&t$(this.store,s)}this.channel.onmessage=({data:o})=>{var a,c;this.debug("got message",o);const s=o,i=this.store.schema.getMigrationsSince(s.schema);if(i.ok){if(i.value.length>0){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}}else{if(Date.now()-this.initTime<5e3){t(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(c=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||c.call(a);return}s.type==="diff"&&(this.debug("applying diff"),As(()=>{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?SW:yW))}persistIfNeeded(){this.debug("persistIfNeeded",{isPersisting:this.isPersisting,isReloading:this.isReloading,shouldDoFullDBWrite:this.shouldDoFullDBWrite,diffQueueLength:this.diffQueue.length,storeIsPossiblyCorrupt:this.store.isPossiblyCorrupted()}),this.scheduledPersistTimeout&&(clearTimeout(this.scheduledPersistTimeout),this.scheduledPersistTimeout=null),!this.isPersisting&&(this.isReloading||this.store.isPossiblyCorrupted()||(this.shouldDoFullDBWrite||this.diffQueue.length>0)&&this.doPersist())}async doPersist(){it(!this.isPersisting,"persist already in progress"),this.isPersisting=!0,this.debug("doPersist start");const n=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await pW({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=k0(n.filter(r=>r!==mC));await fW({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),JK(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function m$({initialData:e,defaultName:n="",id:t,...r}={}){const o="schema"in r&&r.schema?r.schema:e7({shapes:"shapeUtils"in r&&r.shapeUtils?yC(i$(r.shapeUtils)):void 0,bindings:"bindingUtils"in r&&r.bindingUtils?yC(r$(r.bindingUtils)):void 0,migrations:"migrations"in r?r.migrations:void 0});return new A0({id:t,schema:o,initialData:e,props:{defaultName:n}})}function yC(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function SC(e){const n=m$(e);return e.snapshot&&n$(n,e.snapshot),{store:n,opts:e}}function y$(e){const[n,t]=x.useState(()=>SC(e));if(!a_(n.opts,e)){const r=SC(e);return t(r),r.store}return n.store}function PW({persistenceKey:e,sessionId:n,...t}){const[r,o]=x.useState(null),s=y$(t);return x.useEffect(()=>{const i=st();if(!e){o({id:i,storeWithStatus:{status:"not-synced",store:s}});return}o({id:i,storeWithStatus:{status:"loading"}});const a=l=>{o(d=>(d==null?void 0:d.id)===i?{id:i,storeWithStatus:l}:d)},c=new bW(s,{sessionId:n,persistenceKey:e,onLoad(){a({store:s,status:"synced-local"})},onLoadError(l){a({status:"error",error:l})}});return()=>{o(l=>(l==null?void 0:l.id)===i?null:l),c.close()}},[e,s,n]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}function CW(){const e=N(),n=dn();x.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=t_(t,100),o=new Tc("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[e,n])}const IW=[],EW=[],_W=[],kW=x.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=ve.useState(null),c=x.useMemo(()=>o??Yk(),[o]),l=(t==null?void 0:t.ErrorFallback)===void 0?Bk:t==null?void 0:t.ErrorFallback,d={...s,shapeUtils:s.shapeUtils??IW,bindingUtils:s.bindingUtils??EW,tools:s.tools??_W,components:t};return h.jsx("div",{ref:a,draggable:!1,className:de("tl-container tl-theme__light",r),onPointerDown:Kt,tabIndex:-1,children:h.jsx(Yl,{fallback:l,onError:u=>P0(u,{tags:{origin:"react.tldraw-before-app"}}),children:i&&h.jsx(w7,{container:i,children:h.jsx(IU,{overrides:t,children:n?n instanceof A0?h.jsx(v$,{...d,store:n,user:c}):h.jsx(S$,{...d,store:n,user:c}):h.jsx(TW,{...d,store:n,user:c})})})})})});function TW(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:c}=e,l=PW({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:n,snapshot:t});return h.jsx(S$,{...e,store:l,user:c})}const S$=x.memo(function({store:n,user:t,...r}){const o=dn();x.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,t]);const{LoadingScreen:s}=at();switch(n.status){case"error":throw n.error;case"loading":return s?h.jsx(s,{}):null}return h.jsx(v$,{...r,store:n.store,user:t})});function v$({onMount:e,children:n,store:t,tools:r,shapeUtils:o,bindingUtils:s,user:i,initialState:a,autoFocus:c=!0,inferDarkMode:l,cameraOptions:d,assetOptions:u,options:f}){const{ErrorFallback:p}=at(),S=dn(),[g,w]=x.useState(null),[y]=x.useState(c);x.useLayoutEffect(()=>{const E=new ee({store:t,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>S,user:i,initialState:a,autoFocus:y,inferDarkMode:l,cameraOptions:d,assetOptions:u,options:f});return w(E),()=>{E.dispose()}},[S,o,s,r,t,i,a,y,l,d,u,f]);const v=x.useSyncExternalStore(x.useCallback(E=>g?(g.on("crash",E),()=>g.off("crash",E)):()=>{},[g]),()=>(g==null?void 0:g.getCrashingError())??null),{Canvas:P}=at();return g?h.jsx(Yl,{fallback:p,onError:E=>g.annotateError(E,{origin:"react.tldraw",willCrashApp:!0}),children:v?h.jsx(MW,{crashingError:v}):h.jsx(Rp.Provider,{value:g,children:h.jsx($W,{onMount:e,children:n??(P?h.jsx(P,{}):null)})})}):null}function $W({children:e,onMount:n}){return CW(),qK(),ZK(),QK(),AW(n),h.jsx(h.Fragment,{children:e})}function MW({crashingError:e}){throw e}function Gx({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function x$({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function AW(e){const n=N(),t=Hx(r=>{let o;return r.history.ignore(()=>{o=e==null?void 0:e(r),r.emit("mount")}),window.tldrawReady=!0,o});ve.useLayoutEffect(()=>{if(n)return t==null?void 0:t(n)},[n,t])}function Ki({children:e,className:n="",...t}){return h.jsx("div",{...t,className:de("tl-html-container",n),children:e})}class Mh{constructor(n){this.editor=n}}m(Mh,"props"),m(Mh,"migrations"),m(Mh,"type");function w$(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:d=1/0}=t;let u=e.props.w*s,f=e.props.h*i;const p=new b(0,0);if(u>0){if(u<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=u-a;break}case"top":case"bottom":{p.x=(u-a)/2;break}default:p.x=0}u=a}}else if(p.x=u,u=-u,u<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=-u;break}default:p.x=-a}u=a}if(f>0){if(f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=f-l;break}case"right":case"left":{p.y=(f-l)/2;break}default:p.y=0}f=l}}else if(p.y=f,f=-f,f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-l}f=l}const{x:S,y:g}=p.rot(e.rotation).add(r);return{x:S,y:g,props:{w:Math.min(c,u),h:Math.min(d,f)}}}class Oc extends Nr{constructor(){super(...arguments);m(this,"onResize",(t,r)=>w$(t,r))}getGeometry(t){return new es({width:t.props.w,height:t.props.h,isFilled:!0})}getHandleSnapGeometry(t){return{points:this.getGeometry(t).bounds.cornersAndCenter}}}var Iy;let jW=(Iy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Iy,"id","idle"),Iy);var Ey;let OW=(Ey=class extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"wasFocusedOnEnter",!1);m(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=Fe();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})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(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=Fe();this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:r,x:t.x,y:t.y}]);const s=this.editor.getShape(o);if(!s){this.cancel();return}let{w:i,h:a}=s.props;const c=new b(i/2,a/2),l=this.editor.getShapeParentTransform(s);l&&c.rot(-l.rotation());let d=1;this.editor.user.getIsDynamicResizeMode()&&(d=1/this.editor.getZoomLevel(),i*=d,a*=d,c.mul(d));const u=ot(s);u.x=s.x-c.x,u.y=s.y-c.y,u.props.w=i,u.props.h=a,"scale"in s.props&&(u.props.scale=d),this.editor.updateShape(u),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},m(Ey,"id","pointing"),Ey);class Ah extends se{constructor(){super(...arguments);m(this,"onCreate")}}m(Ah,"id","box"),m(Ah,"initial","idle"),m(Ah,"children",()=>[jW,OW]);function rg(e){const n=N();return W("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function DW(){return x.useId().replace(/:/g,"_")}function eo(e){const n=N();return x.useMemo(function(){const o=l=>{if(l.isKilled)return;if(l.button===B0){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...$n(l)});return}if(l.button!==0)return;const d=Rf(l.currentTarget);function u(){d.removeEventListener("pointerup",u),Dd(d,l)}Od(d,l),d.addEventListener("pointerup",u),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...$n(l)}),Kt(l)};let s,i;function a(l){l.isKilled||l.button===0&&(l.clientX===s&&l.clientY===i||(s=l.clientX,i=l.clientY,n.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...$n(l)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:l=>{l.isKilled||l.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...$n(l)})}}},[n,e])}const RW=20,LW=8;function Vx(e,n=RW){return Math.max(LW,Math.ceil(e/n))}class Ba extends ni{constructor(t){super({...t,isFilled:!1,isClosed:!1});m(this,"_center");m(this,"radius");m(this,"start");m(this,"end");m(this,"largeArcFlag");m(this,"sweepFlag");m(this,"measure");m(this,"angleStart");m(this,"angleEnd");const{center:r,sweepFlag:o,largeArcFlag:s,start:i,end:a}=t;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=b.Angle(r,i),this.angleEnd=b.Angle(r,a),this.radius=b.Dist(r,i),this.measure=u7(this.angleStart,this.angleEnd,o,s),this.start=i,this.end=a,this.sweepFlag=o,this.largeArcFlag=s,this._center=r}nearestPoint(t){const{_center:r,measure:o,radius:s,angleEnd:i,angleStart:a,start:c,end:l}=this,d=mS(o,a,i,r.angle(t));if(d<=0)return c;if(d>=1)return l;const u=r.clone().add(t.clone().sub(r).uni().mul(s));let f,p=1/0,S;for(const g of[c,l,u])S=b.Dist2(t,g),S<p&&(f=g,p=S);if(!f)throw Error("nearest point not found");return f}hitTestLineSegment(t,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:c}=this,l=Ud(t,r,o,s);return l===null?!1:l.some(d=>{const u=mS(i,a,c,o.angle(d));return u>=0&&u<=1})}getVertices(){const{_center:t,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let c=0,l=Vx(Math.abs(o));c<l+1;c++){const d=c/l*r,u=i+d;a.push(Fi(t,s,u))}return a}getSvgPathData(t=!0){const{start:r,end:o,radius:s,largeArcFlag:i,sweepFlag:a}=this;return`${t?`M${r.toFixed()}`:""} A${s} ${s} 0 ${i} ${a} ${o.toFixed()}`}getLength(){return this.measure*this.radius}}class Yx extends ni{constructor(t){super({isClosed:!0,...t});m(this,"_center");m(this,"radius");m(this,"x");m(this,"y");this.config=t;const{x:r=0,y:o=0,radius:s}=t;this.x=r,this.y=o,this._center=new b(s+r,s+o),this.radius=s}getBounds(){return new J(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,o=De*r,s=[];for(let i=0,a=Vx(o);i<a;i++){const c=i/a*De;s.push(Fi(t,r,c))}return s}nearestPoint(t){const{_center:r,radius:o}=this;return r.equals(t)?b.AddXY(r,o,0):r.clone().add(t.clone().sub(r).uni().mul(o))}hitTestLineSegment(t,r,o=0){const{_center:s,radius:i}=this;return Ud(t,r,s,i+o)!==null}getSvgPathData(){const{_center:t,radius:r}=this;return`M${t.x+r},${t.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class tn extends jc{constructor(t){const{start:r,cp1:o,cp2:s,end:i}=t;super({...t,points:[r,i]});m(this,"a");m(this,"b");m(this,"c");m(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const t=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,c=10;a<=c;a++){const l=a/c;t.push(new b((1-l)*(1-l)*(1-l)*r.x+3*((1-l)*(1-l))*l*o.x+3*(1-l)*(l*l)*s.x+l*l*l*i.x,(1-l)*(1-l)*(1-l)*r.y+3*((1-l)*(1-l))*l*o.y+3*(1-l)*(l*l)*s.y+l*l*l*i.y))}return t}midPoint(){return tn.GetAtT(this,.5)}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(t),s=b.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}getSvgPathData(t=!0){const{a:r,b:o,c:s,d:i}=this;return`${t?`M ${r.toFixed()} `:""} C${o.toFixed()} ${s.toFixed()} ${i.toFixed()}`}static GetAtT(t,r){const{a:o,b:s,c:i,d:a}=t;return new b((1-r)*(1-r)*(1-r)*o.x+3*((1-r)*(1-r))*r*s.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*o.y+3*((1-r)*(1-r))*r*s.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(t=32){let r,o=this.a,s=0;for(let i=1;i<=t;i++)r=tn.GetAtT(this,i/t),s+=b.Dist(o,r),o=r;return s}}class FW extends ni{constructor(t){super({...t,isClosed:!1,isFilled:!1});m(this,"points");m(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:t}=this,r=t.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?t[0]:t[i-1],c=t[i],l=t[i+1],d=i===o?l:t[i+2],u=c,f=i===0?a:new b(c.x+(l.x-a.x)/6*s,c.y+(l.y-a.y)/6*s),p=i===o?l:new b(l.x-(d.x-c.x)/6*s,l.y-(d.y-c.y)/6*s),S=l;this._segments.push(new tn({start:u,cp1:f,cp2:p,end:S}))}}return this._segments}getLength(){return this.segments.reduce((t,r)=>t+r.length,0)}getVertices(){const t=this.segments.reduce((r,o)=>r.concat(o.vertices),[]);return t.push(this.points[this.points.length-1]),t}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(t),s=b.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.segments.some(o=>o.hitTestLineSegment(t,r))}getSvgPathData(){let t=this.segments.reduce((r,o,s)=>r+o.getSvgPathData(s===0),"");return this.isClosed&&(t+="Z"),t}}class zW extends ni{constructor(t){super({...t,isClosed:!0});m(this,"w");m(this,"h");m(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 Bo({start:s,end:i}))}}return this._edges}getVertices(){const t=Math.max(1,this.w),r=Math.max(1,this.h),o=t/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=ke*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),c=Vx(a),l=De/c,d=Math.cos(l),u=Math.sin(l);let f=0,p=1,S=0,g=1;const w=Array(c);for(let y=0;y<c;y++)w[y]=new b(o+o*p,s+s*f),S=u*p+d*f,g=d*p-u*f,f=S,p=g;return w}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(t),s=b.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){return this.edges.some(o=>o.hitTestLineSegment(t,r))}getBounds(){return new J(0,0,this.w,this.h)}getLength(){const{w:t,h:r}=this,o=t/2,s=r/2,i=Math.max(0,o),a=Math.max(0,s);return yk(i,a)}getSvgPathData(t=!1){const{w:r,h:o}=this,s=r/2,i=o/2,a=Math.max(0,s),c=Math.max(0,i);return`${t?`M${s-a},${i}`:""} a${a},${c},0,1,1,${a*2},0a${a},${c},0,1,1,-${a*2},0`}}class NW extends ni{constructor(t){super({...t,isClosed:!0});m(this,"w");m(this,"h");m(this,"a");m(this,"b");m(this,"c");m(this,"d");this.config=t;const{width:r,height:o}=t;if(this.w=r,this.h=o,o>r){const s=r/2;this.a=new Ba({start:new b(0,s),end:new b(r,s),center:new b(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new Bo({start:new b(r,s),end:new b(r,o-s)}),this.c=new Ba({start:new b(r,o-s),end:new b(0,o-s),center:new b(r/2,o-s),sweepFlag:1,largeArcFlag:1}),this.d=new Bo({start:new b(0,o-s),end:new b(0,s)})}else{const s=o/2;this.a=new Ba({start:new b(s,o),end:new b(s,0),center:new b(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new Bo({start:new b(s,0),end:new b(r-s,0)}),this.c=new Ba({start:new b(r-s,0),end:new b(r-s,o),center:new b(r-s,s),sweepFlag:1,largeArcFlag:1}),this.d=new Bo({start:new b(r-s,o),end:new b(s,o)})}}nearestPoint(t){let r,o=1/0,s,i;const{a,b:c,c:l,d}=this;for(const u of[a,c,l,d])i=u.nearestPoint(t),s=b.Dist2(i,t),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(t,r){const{a:o,b:s,c:i,d:a}=this;return[o,s,i,a].some(c=>c.hitTestLineSegment(t,r))}getVertices(){const{a:t,b:r,c:o,d:s}=this;return[t,r,o,s].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new J(0,0,this.w,this.h)}getLength(){const{h:t,w:r}=this;return t>r?(ke*(r/2)+(t-r))*2:(ke*(t/2)+(r-t))*2}getSvgPathData(){const{a:t,b:r,c:o,d:s}=this;return[t,r,o,s].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function BW({shouldReload:e=!0}={}){i4(),await Promise.all(Wx().map(n=>lW(n))),s4(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=BW);function UW(e,n="_blank"){G0.openWindow(e,n)}const b$="TLDRAW_ASSET_STORE_v1",pc={Assets:"assets"};async function P$(e,n){const t=await p$(e,1,{upgrade(r){r.objectStoreNames.contains(pc.Assets)||r.createObjectStore(pc.Assets)}});try{return await n(t)}finally{t.close()}}async function HW({persistenceKey:e,assetId:n}){const t=b$+e;return await P$(t,async r=>await r.transaction([pc.Assets],"readwrite").objectStore(pc.Assets).get(n))}async function KW({persistenceKey:e,assetId:n,blob:t}){const r=b$+e;await P$(r,async o=>{const s=o.transaction([pc.Assets],"readwrite");await s.objectStore(pc.Assets).put(t,n),await s.done})}function WW({children:e}){const n=N();return W("shouldDisplayHandles",()=>{if(n.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(n.isInAny("select.editing_shape")){const r=n.getOnlySelectedShape();return r&&n.isShapeOfType(r,"note")}return!1},[n])?h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:GW}=Math,tc=GW+1e-4;function C$(e,n={}){const{size:t=16,smoothing:r=.5}=n;if(e.length===0||t<=0)return{left:[],right:[]};const o=e[0],s=e[e.length-1],i=s.runningLength,a=Math.pow(t*r,2),c=[],l=[];let d=e[0].vector,u=e[0].point,f=u,p=u,S=f,g=!1,w;for(let y=0;y<e.length;y++){w=e[y];const{point:v,vector:P}=e[y],E=w.vector.dpr(d),I=(y<e.length-1?e[y+1]:e[y]).vector,C=y<e.length-1?I.dpr(w.vector):1,_=E<0&&!g,k=C!==null&&C<.2;if(_||k){if(C>-.62&&i-w.runningLength>w.radius){const T=d.clone().mul(w.radius);d.clone().cpr(I)<0?(p=b.Add(v,T),S=b.Sub(v,T)):(p=b.Sub(v,T),S=b.Add(v,T)),c.push(p),l.push(S)}else{const T=d.clone().mul(w.radius).per(),M=b.Sub(w.input,T);for(let R=1/13,A=0;A<1;A+=R)p=b.RotWith(M,w.input,tc*A),c.push(p),S=b.RotWith(M,w.input,tc+tc*-A),l.push(S)}u=p,f=S,k&&(g=!0);continue}if(g=!1,w===o||w===s){const T=b.Per(P).mul(w.radius);c.push(b.Sub(v,T)),l.push(b.Add(v,T));continue}const j=b.Lrp(I,P,C).per().mul(w.radius);p=b.Sub(v,j),(y<=1||b.Dist2(u,p)>a)&&(c.push(p),u=p),S=b.Add(v,j),(y<=1||b.Dist2(f,S)>a)&&(l.push(S),f=S),d=P}return{left:c,right:l}}function Xx(e,n={}){const{size:t=16,start:r={},end:o={},last:s=!1}=n,{cap:i=!0}=r,{cap:a=!0}=o;if(e.length===0||t<=0)return[];const c=e[0],l=e[e.length-1],d=l.runningLength,u=r.taper===!1?0:r.taper===!0?Math.max(t,d):r.taper,f=o.taper===!1?0:o.taper===!0?Math.max(t,d):o.taper,{left:p,right:S}=C$(e,n),g=c.point,w=e.length>1?e[e.length-1].point:b.AddXY(c.point,1,1);if(e.length===1&&(!(u||f)||s)){const E=b.Add(g,b.Sub(g,w).uni().per().mul(-c.radius)),I=[];for(let C=1/13,_=C;_<=1;_+=C)I.push(b.RotWith(E,g,tc*2*_));return I}const y=[];if(!(u||f&&e.length===1))if(i)for(let E=1/8,I=E;I<=1;I+=E){const C=b.RotWith(S[0],g,tc*I);y.push(C)}else{const E=b.Sub(p[0],S[0]),I=b.Mul(E,.5),C=b.Mul(E,.51);y.push(b.Sub(g,I),b.Sub(g,C),b.Add(g,C),b.Add(g,I))}const v=[],P=l.vector.clone().per().neg();if(f||u&&e.length===1)v.push(w);else if(a){const E=b.Add(w,b.Mul(P,l.radius));for(let I=1/29,C=I;C<1;C+=I)v.push(b.RotWith(E,w,tc*3*C))}else v.push(b.Add(w,b.Mul(P,l.radius)),b.Add(w,b.Mul(P,l.radius*.99)),b.Sub(w,b.Mul(P,l.radius*.99)),b.Sub(w,b.Mul(P,l.radius)));return p.concat(v,S.reverse(),y)}const VW=.025,YW=.01;function So(e,n={}){var w;const{streamline:t=.5,size:r=16,simulatePressure:o=!1}=n;if(e.length===0)return[];const s=.15+(1-t)*.85;let i=e.map(b.From),a=0;if(!o){let y=i[0];for(;y&&!(y.z>=VW);)i.shift(),y=i[0]}if(!o){let y=i[i.length-1];for(;y&&!(y.z>=YW);)i.pop(),y=i[i.length-1]}if(i.length===0)return[{point:b.From(e[0]),input:b.From(e[0]),pressure:o?.5:.15,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let c=i[1];for(;c&&!(b.Dist2(c,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,c.z),i.splice(1,1),c=i[1];const l=i.pop();for(c=i[i.length-1];c&&!(b.Dist2(c,l)>(r/3)**2);)i.pop(),c=i[i.length-1],a++;i.push(l);const d=n.last||!n.simulatePressure||i.length>1&&b.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&n.simulatePressure){const y=i[1];i=i.slice(0,-1);for(let v=1;v<5;v++){const P=b.Lrp(i[0],y,v/4);P.z=(i[0].z+(y.z-i[0].z))*v/4,i.push(P)}}const u=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let f=0,p=u[0],S,g;d&&t>0&&i.push(i[i.length-1].clone());for(let y=1,v=i.length;y<v;y++)S=!s||n.last&&y===v-1?i[y].clone():i[y].clone().lrp(p.point,1-s),!p.point.equals(S)&&(g=b.Dist(S,p.point),f+=g,!(y<4&&f<r)&&(p={input:i[y],point:S,pressure:o?.5:i[y].z,vector:b.Sub(p.point,S).uni(),distance:g,runningLength:f,radius:1},u.push(p)));if((w=u[1])!=null&&w.vector&&(u[0].vector=u[1].vector.clone()),f<1){const y=Math.max(.5,...u.map(v=>v.pressure));u.forEach(v=>v.pressure=y)}return u}const{min:Ss}=Math,Zm=.275;function og(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=w=>w,start:i={},end:a={}}=n,{easing:c=At.easeOutQuad}=i,{easing:l=At.easeOutCubic}=a,d=e[e.length-1].runningLength;let u,f=e[0].pressure,p;if(!o&&d<t){const w=e.reduce((y,v)=>Math.max(y,v.pressure),.5);return e.forEach(y=>{y.pressure=w,y.radius=t*s(.5-r*(.5-y.pressure))}),e}else{let w;for(let y=0,v=e.length;y<v&&(p=e[y],!(p.runningLength>t*5));y++){const P=Ss(1,p.distance/t);if(o){const E=Ss(1,1-P);w=Ss(1,f+(E-f)*(P*Zm))}else w=Ss(1,f+(p.pressure-f)*.5);f=f+(w-f)*.5}for(let y=0;y<e.length;y++){if(p=e[y],r){let{pressure:v}=p;const P=Ss(1,p.distance/t);if(o){const E=Ss(1,1-P);v=Ss(1,f+(E-f)*(P*Zm))}else v=Ss(1,f+(v-f)*(P*Zm));p.radius=t*s(.5-r*(.5-v)),f=v}else p.radius=t/2;u===void 0&&(u=p.radius)}}const S=i.taper===!1?0:i.taper===!0?Math.max(t,d):i.taper,g=a.taper===!1?0:a.taper===!0?Math.max(t,d):a.taper;if(S||g)for(let w=0;w<e.length;w++){p=e[w];const{runningLength:y}=p,v=y<S?c(y/S):1,P=d-y<g?l((d-y)/g):1;p.radius=Math.max(.01,p.radius*Math.min(v,P))}return e}function XW(e,n={}){return Xx(og(So(e,n),n),n)}function vC({scribble:e,zoom:n,color:t,opacity:r,className:o}){if(!e.points.length)return null;const s=XW(e.points,{size:e.size/n,start:{taper:e.taper,easing:At.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=e.size/n/2,{x:c,y:l}=e.points[e.points.length-1];i=`M ${c-a},${l} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=H0(s);return h.jsx("svg",{className:o&&de("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})}const qW=({bounds:e,rotation:n})=>{const t=N();return W("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?h.jsx(Lk,{bounds:e,rotation:n}):null};function as(){const e=N();return W("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function ZW({size:e,width:n,height:t,hideAlternateHandles:r}){const o=z(e/3),s=o/2;return h.jsxs("svg",{className:"tl-overlays__item",children:[h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
98
|
-
${z(0-s)},${z(e)}
|
|
99
|
-
${z(0-s)},${z(0-s)}
|
|
100
|
-
${z(e)},${z(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),h.jsx("line",{className:de("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:z(n/2-e),y1:z(0-s),x2:z(n/2+e),y2:z(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),h.jsx("polyline",{className:de("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
101
|
-
${z(n-e)},${z(0-s)}
|
|
102
|
-
${z(n+s)},${z(0-s)}
|
|
103
|
-
${z(n+s)},${z(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),h.jsx("line",{className:de("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:z(n+s),y1:z(t/2-e),x2:z(n+s),y2:z(t/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
104
|
-
${z(n+s)},${z(t-e)}
|
|
105
|
-
${z(n+s)},${z(t+s)}
|
|
106
|
-
${z(n-e)},${z(t+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),h.jsx("line",{className:de("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:z(n/2-e),y1:z(t+s),x2:z(n/2+e),y2:z(t+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),h.jsx("polyline",{className:de("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
107
|
-
${z(0+e)},${z(t+s)}
|
|
108
|
-
${z(0-s)},${z(t+s)}
|
|
109
|
-
${z(0-s)},${z(t-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),h.jsx("line",{className:de("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:z(0-s),y1:z(t/2-e),x2:z(0-s),y2:z(t/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const QW=sr(function({bounds:n,rotation:t}){const r=N(),o=x.useRef(null),s=as(),i=eo("top"),a=eo("right"),c=eo("bottom"),l=eo("left"),d=eo("top_left"),u=eo("top_right"),f=eo("bottom_right"),p=eo("bottom_left"),S=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",g=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),y=w&&r.isShapeOrAncestorLocked(w),v=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0;if($c(o,n==null?void 0:n.x,n==null?void 0:n.y,1,r.getSelectionRotation(),{x:-v,y:-v}),!n)return null;n=n.clone().expandBy(v).zeroFix();const P=r.getZoomLevel(),E=r.getInstanceState().isChangingStyle,I=n.width,C=n.height,_=8/P,k=I<_*2,j=C<_*2,T=I<_*4,M=C<_*4,R=I<_*5,A=C<_*5,O=g?1.75:1,L=6/P*O,G=(T?L/2:L)*(O*.75),K=(M?L/2:L)*(O*.75),B=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!E;let U=B&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle","select.pointing_resize_handle")||B&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&U&&r.environment.isFirefox&&r.isShapeOfType(w,"embed")&&(U=!1);const Y=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!E&&!s,Q=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!E&&!s,le=!g&&!(k||j)&&(Q||Y)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!y,ge=g&&(!T||!M)&&(Q||Y)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!y,Me=Q&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!Y&&!y,ce=k||j,Ae=k&&j,Re=R||A,ct=Me||Y,Ie=!le,gt=!Q||!ge,Ue=!Q||!ct,dr=!Q||!ct||ce,Un=!Q||!ct||ce,Hn=!Q||!ct||Ae&&!Y;let qe=!0,Rt=!0;if(Y)qe=Re,Rt=Re;else if(Me){qe=ce||Ae||g;const Nc=g&&w&&w.type==="text";Rt=qe&&!Nc}const ko=Math.min(24/P,C-K*3),zc=Q&&g&&w&&r.isShapeOfType(w,"text")&&ko*P>=4;return h.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsxs("g",{ref:o,children:[U&&h.jsx("rect",{className:"tl-selection__fg__outline",width:z(I),height:z(C)}),h.jsx(Nu,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:L,corner:"top_left_rotate",cursor:S?Wn("nwse-rotate",t):void 0,isHidden:Ie}),h.jsx(Nu,{"data-testid":"selection.rotate.top-right",cx:I+L*3,cy:0,targetSize:L,corner:"top_right_rotate",cursor:S?Wn("nesw-rotate",t):void 0,isHidden:Ie}),h.jsx(Nu,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:C+L*3,targetSize:L,corner:"bottom_left_rotate",cursor:S?Wn("swne-rotate",t):void 0,isHidden:Ie}),h.jsx(Nu,{"data-testid":"selection.rotate.bottom-right",cx:I+L*3,cy:C+L*3,targetSize:L,corner:"bottom_right_rotate",cursor:S?Wn("senw-rotate",t):void 0,isHidden:Ie}),h.jsx(eG,{"data-testid":"selection.rotate.mobile",cx:T?-L*1.5:I/2,cy:T?C/2:-L*1.5,size:_,isHidden:gt}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:z(0-(M?K*2:K)),width:z(I),height:z(Math.max(1,K*2)),style:S?{cursor:Wn("ns-resize",t)}:void 0,...i}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":Rt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:z(I-(T?0:G)),y:0,height:z(C),width:z(Math.max(1,G*2)),style:S?{cursor:Wn("ew-resize",t)}:void 0,...a}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:z(C-(M?0:K)),width:z(I),height:z(Math.max(1,K*2)),style:S?{cursor:Wn("ns-resize",t)}:void 0,...c}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":Rt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:z(0-(T?G*2:G)),y:0,height:z(C),width:z(Math.max(1,G*2)),style:S?{cursor:Wn("ew-resize",t)}:void 0,...l}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":Ue}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:z(0-(T?G*2:G*1.5)),y:z(0-(M?K*2:K*1.5)),width:z(G*3),height:z(K*3),style:S?{cursor:Wn("nwse-resize",t)}:void 0,...d}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":dr}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:z(I-(T?0:G*1.5)),y:z(0-(M?K*2:K*1.5)),width:z(G*3),height:z(K*3),style:S?{cursor:Wn("nesw-resize",t)}:void 0,...u}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":Hn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:z(I-(T?G:G*1.5)),y:z(C-(M?K:K*1.5)),width:z(G*3),height:z(K*3),style:S?{cursor:Wn("nwse-resize",t)}:void 0,...f}),h.jsx("rect",{className:de("tl-transparent",{"tl-hidden":Un}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:z(0-(T?G*3:G*1.5)),y:z(C-(M?0:K*1.5)),width:z(G*3),height:z(K*3),style:S?{cursor:Wn("nesw-resize",t)}:void 0,...p}),Me&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.resize.top-left",className:de("tl-corner-handle",{"tl-hidden":Ue}),"aria-label":"top_left handle",x:z(0-_/2),y:z(0-_/2),width:z(_),height:z(_)}),h.jsx("rect",{"data-testid":"selection.resize.top-right",className:de("tl-corner-handle",{"tl-hidden":dr}),"aria-label":"top_right handle",x:z(I-_/2),y:z(0-_/2),width:z(_),height:z(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:de("tl-corner-handle",{"tl-hidden":Hn}),"aria-label":"bottom_right handle",x:z(I-_/2),y:z(C-_/2),width:z(_),height:z(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:de("tl-corner-handle",{"tl-hidden":Un}),"aria-label":"bottom_left handle",x:z(0-_/2),y:z(C-_/2),width:z(_),height:z(_)})]}),zc&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:z(0-_/4),y:z(C/2-ko/2),rx:_/4,width:z(_/2),height:z(ko)}),h.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:_/4,x:z(I-_/4),y:z(C/2-ko/2),width:z(_/2),height:z(ko)})]}),Y&&h.jsx(ZW,{size:_,width:I,height:C,hideAlternateHandles:Re})]})})}),Nu=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const c=eo(o);return h.jsx("rect",{className:de("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:z(n-r*3),y:z(t-r*3),width:z(Math.max(1,r*3)),height:z(Math.max(1,r*3)),cursor:s,...c})},JW=Math.sqrt(Math.PI),eG=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=eo("mobile_rotate"),a=N(),c=W("zoom level",()=>a.getZoomLevel(),[a]),l=Math.max(14*(1/c),20/Math.max(1,c));return h.jsxs("g",{children:[h.jsx("circle",{"data-testid":s,pointerEvents:"all",className:de("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:l,...i}),h.jsx("circle",{className:de("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/JW})]})};function mv(e,n,t){const{arrowheadStart:r,arrowheadEnd:o}=n.props,s=Ua(e,n,t),i=s.start.clone(),a=s.end.clone(),c=b.Med(i,a);if(b.Equals(i,a))return{bindings:t,isStraight:!0,start:{handle:i,point:i,arrowhead:n.props.arrowheadStart},end:{handle:a,point:a,arrowhead:n.props.arrowheadEnd},middle:c,isValid:!1,length:0};const l=b.Sub(a,i).uni(),d=lp(e,n,"start"),u=lp(e,n,"end"),f=e.getShapePageTransform(n);xC(a,s.start,f,u),xC(i,s.end,f,d);let p=0,S=0,g=0,w=0,y=Ha*n.props.scale;const v=d&&u&&d.shape===u.shape,P=d&&u?qx(e,d.shape.id,u.shape.id):"safe";P==="safe"&&d&&u&&!v&&!d.isExact&&!u.isExact&&(u.didIntersect&&!d.didIntersect?d.isClosed&&i.setTo(a.clone().add(l.clone().mul(Ha*n.props.scale))):u.didIntersect||u.isClosed&&a.setTo(i.clone().sub(l.clone().mul(Ha*n.props.scale))));const E=b.Sub(a,i),I=b.Len(E)?E.uni():b.From(E),C=!b.Equals(I,l);v||(P!=="start-contains-end"&&d&&r!=="none"&&!d.isExact&&(g=$s[n.props.size]/2+("size"in d.shape.props?$s[d.shape.props.size]/2:0),p=(dp+g)*n.props.scale,y+=g*n.props.scale),P!=="end-contains-start"&&u&&o!=="none"&&!u.isExact&&(w=$s[n.props.size]/2+("size"in u.shape.props?$s[u.shape.props.size]/2:0),S=(dp+w)*n.props.scale,y+=w*n.props.scale));const _=i.clone().add(I.clone().mul(p*(C?-1:1))),k=a.clone().sub(I.clone().mul(S*(C?-1:1)));b.DistMin(_,k,y)&&(p!==0&&S!==0?(p*=-1.5,S*=-1.5):p!==0?p*=-1:S!==0&&(S*=-1)),i.add(I.clone().mul(p*(C?-1:1))),a.sub(I.clone().mul(S*(C?-1:1))),C?(d&&u&&a.setTo(b.Add(i,I.clone().mul(-Ha*n.props.scale))),c.setTo(b.Med(s.start,s.end))):c.setTo(b.Med(i,a));const j=b.Dist(i,a);return{bindings:t,isStraight:!0,start:{handle:s.start,point:i,arrowhead:n.props.arrowheadStart},end:{handle:s.end,point:a,arrowhead:n.props.arrowheadEnd},middle:c,isValid:j>0,length:j}}function xC(e,n,t,r){if(r===void 0||r.isExact)return;const o=oe.applyToPoint(t,n),s=oe.applyToPoint(t,e),i=oe.applyToPoint(oe.Inverse(r.transform),o),a=oe.applyToPoint(oe.Inverse(r.transform),s),c=r.isClosed,d=(c?zx:XH)(i,a,r.outline);let u;if(d!==null&&(u=d.sort((S,g)=>b.Dist2(S,i)-b.Dist2(g,i))[0]??(c?void 0:a)),u===void 0)return;const f=oe.applyToPoint(r.transform,u),p=oe.applyToPoint(oe.Inverse(t),f);e.setTo(p),r.didIntersect=!0}function tG(e,n,t){const{arrowheadEnd:r,arrowheadStart:o}=n.props,s=n.props.bend;if(Math.abs(s)>Math.abs(n.props.bend*(iG*n.props.scale)))return mv(e,n,t);const i=Ua(e,n,t),a=b.Med(i.start,i.end),c=b.Sub(i.end,i.start),l=b.Len(c)?c.uni():b.From(c),d=b.Add(a,l.per().mul(-s)),u=lp(e,n,"start"),f=lp(e,n,"end"),p=i.start.clone(),S=i.end.clone(),g=d.clone();if(b.Equals(p,S))return{bindings:t,isStraight:!0,start:{handle:p,point:p,arrowhead:n.props.arrowheadStart},end:{handle:S,point:S,arrowhead:n.props.arrowheadEnd},middle:g,isValid:!1,length:0};const w=n.props.bend<0,y=w?jd:Sk,v=wC(p,S,g),P=b.Angle(v.center,p),E=b.Angle(v.center,S),I=y(P,E);if(v.length===0||v.size===0||!_1(v.length)||!_1(v.size))return mv(e,n,t);const C=p.clone(),_=S.clone(),k=g.clone(),j=e.getShapePageTransform(n);let T=0,M=0,R=Ha*n.props.scale;if(u&&!u.isExact){const Y=oe.applyToPoint(j,C),Q=oe.applyToPoint(j,v.center),le=oe.applyToPoint(j,_),ge=oe.Inverse(u.transform),Me=oe.applyToPoint(ge,Y),ce=oe.applyToPoint(ge,Q),Ae=oe.applyToPoint(ge,le),{isClosed:Re}=u,ct=Re?hv:nC;let Ie,gt=ct(ce,v.radius,u.outline);if(gt){const Ue=ce.angle(Me),dr=ce.angle(Ae),Un=y(Ue,dr);gt=gt.filter(qe=>y(Ue,ce.angle(qe))<=Un);const Hn=Un*.25;gt.sort(Re?(qe,Rt)=>Math.abs(y(Ue,ce.angle(qe))-Hn)<Math.abs(y(Ue,ce.angle(Rt))-Hn)?-1:1:(qe,Rt)=>y(Ue,ce.angle(qe))<y(Ue,ce.angle(Rt))?-1:1),Ie=gt[0]??(Re?void 0:Me)}else Ie=Re?void 0:Me;if(Ie&&(C.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(u.transform,Ie))),u.didIntersect=!0,o!=="none")){const Ue=$s[n.props.size]/2+("size"in u.shape.props?$s[u.shape.props.size]/2:0);T=(dp+Ue)*n.props.scale,R+=Ue*n.props.scale}}if(f&&!f.isExact){const Y=oe.applyToPoint(j,C),Q=oe.applyToPoint(j,_),le=oe.applyToPoint(j,v.center),ge=oe.Inverse(f.transform),Me=oe.applyToPoint(ge,Y),ce=oe.applyToPoint(ge,le),Ae=oe.applyToPoint(ge,Q),Re=f.isClosed,ct=Re?hv:nC;let Ie,gt=ct(ce,v.radius,f.outline);if(gt){const Ue=ce.angle(Me),dr=ce.angle(Ae),Un=y(Ue,dr),Hn=Un*.75;gt=gt.filter(qe=>y(Ue,ce.angle(qe))<=Un),gt.sort(Re?(qe,Rt)=>Math.abs(y(Ue,ce.angle(qe))-Hn)<Math.abs(y(Ue,ce.angle(Rt))-Hn)?-1:1:(qe,Rt)=>y(Ue,ce.angle(qe))<y(Ue,ce.angle(Rt))?-1:1),gt[0]?Ie=gt[0]:Ie=Re?void 0:Ae}else Ie=Re?void 0:Ae;if(Ie&&(_.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(f.transform,Ie))),f.didIntersect=!0,r!=="none")){const Ue=$s[n.props.size]/2+("size"in f.shape.props?$s[f.shape.props.size]/2:0);M=(dp+Ue)*n.props.scale,R+=Ue*n.props.scale}}let A=b.Angle(v.center,C),O=b.Angle(v.center,_),L=y(A,O),G=L*v.radius;const K=C.clone(),B=_.clone();if(T!==0&&K.setTo(v.center).add(b.FromAngle(A+L*(T/G*(w?1:-1))).mul(v.radius)),M!==0&&B.setTo(v.center).add(b.FromAngle(O+L*(M/G*(w?-1:1))).mul(v.radius)),b.DistMin(K,B,R)&&(T!==0&&M!==0?(T*=-1.5,M*=-1.5):T!==0?T*=-2:M!==0&&(M*=-2)),T!==0&&C.setTo(v.center).add(b.FromAngle(A+L*(T/G*(w?1:-1))).mul(v.radius)),M!==0&&_.setTo(v.center).add(b.FromAngle(O+L*(M/G*(w?-1:1))).mul(v.radius)),u&&f&&!u.isExact&&!f.isExact){A=b.Angle(v.center,C),O=b.Angle(v.center,_),L=y(A,O),G=L*v.radius;const Y=qx(e,u.shape.id,f.shape.id);Y==="double-bound"&&G<30?(C.setTo(p),_.setTo(S),k.setTo(g)):Y==="safe"&&(u&&!u.didIntersect&&C.setTo(p),(f&&!f.didIntersect||y(P,A)>y(P,O))&&_.setTo(v.center).add(b.FromAngle(A+L*(Math.min(.9,Ha*n.props.scale/G)*(w?1:-1))).mul(v.radius)))}nG(v.center,v.radius,C,_,k,I,w),C.equals(_)&&(C.setTo(k.clone().addXY(1,1)),_.setTo(k.clone().subXY(1,1))),p.setTo(C),S.setTo(_),g.setTo(k);const U=wC(p,S,g);return{bindings:t,isStraight:!1,start:{point:p,handle:i.start,arrowhead:n.props.arrowheadStart},end:{point:S,handle:i.end,arrowhead:n.props.arrowheadEnd},middle:g,handleArc:v,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function wC(e,n,t){const r=N0(e,n,t),o=b.Dist(r,e),s=+b.Clockwise(e,t,n),i=((e.y-n.y)**2+(e.x-n.x)**2)**.5,a=((n.y-t.y)**2+(n.x-t.x)**2)**.5,c=((t.y-e.y)**2+(t.x-e.x)**2)**.5,l=Math.acos((a*a+c*c-i*i)/(2*a*c))*2,d=+(ke>l),u=(De-l)*(s?1:-1),f=u*o;return{center:r,radius:o,size:u,length:f,largeArcFlag:d,sweepFlag:s}}function nG(e,n,t,r,o,s,i){const a=b.Angle(e,t),c=b.Angle(e,r);let l=jd(a,c);if(i||(l=De-l),o.setTo(e).add(b.FromAngle(a+l*(.5*(i?1:-1))).mul(n)),l>s){o.rotWith(e,ke);const d=r.clone();r.setTo(t),t.setTo(d)}}const rG=8;function oG(e){return Math.abs(e.props.bend)<rG*e.props.scale}function lp(e,n,t){const r=e.getBindingsFromShape(n,"arrow").find(c=>c.props.terminal===t);if(!r)return;const o=e.getShape(r.toId);if(!o)return;const s=e.getShapePageTransform(o),i=e.getShapeGeometry(o),a=i instanceof Ur?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function bC(e,n,t,r){const o=e.getShape(t.toId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=b.Add(s,b.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},i)),c=oe.applyToPoint(e.getShapePageTransform(o),a);return oe.applyToPoint(oe.Inverse(n),c)}else return new b(0,0)}function kn(e,n){const t=e.getBindingsFromShape(n,"arrow");return{start:t.find(r=>r.props.terminal==="start"),end:t.find(r=>r.props.terminal==="end")}}const sG=U4("arrow info",(e,n)=>{const t=kn(e,n);return oG(n)?mv(e,n,t):tG(e,n,t)});function ao(e,n){const t=typeof n=="string"?n:n.id;return sG.get(e,t)}function Ua(e,n,t){var a,c;const r=e.getShapePageTransform(n),o=qx(e,(a=t.start)==null?void 0:a.toId,(c=t.end)==null?void 0:c.toId),s=t.start?bC(e,r,t.start,o==="double-bound"||o==="start-contains-end"):b.From(n.props.start),i=t.end?bC(e,r,t.end,o==="double-bound"||o==="end-contains-start"):b.From(n.props.end);return{start:s,end:i}}function cl(e,n,t,r){const o=typeof n=="string"?n:n.id,s=typeof t=="string"?t:t.id,i=e.getBindingsFromShape(o,"arrow").filter(c=>c.props.terminal===r.terminal);i.length>1&&e.deleteBindings(i.slice(1));const a=i[0];a?e.updateBinding({...a,toId:s,props:r}):e.createBinding({type:"arrow",fromId:o,toId:s,props:r})}function jh(e,n,t){const r=e.getBindingsFromShape(n,"arrow").filter(o=>o.props.terminal===t);e.deleteBindings(r)}const Ha=10,dp=10,iG=10,$s={s:2,m:3.5,l:5,xl:10};function qx(e,n,t){if(!n||!t)return"safe";if(n===t)return"double-bound";const r=e.getShapePageBounds(n),o=e.getShapePageBounds(t);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}class Oh extends Mh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:n}){Qm(this.editor,this.editor.getShape(n.fromId))}onAfterChange({bindingAfter:n}){Qm(this.editor,this.editor.getShape(n.fromId))}onAfterChangeFromShape({shapeAfter:n}){Qm(this.editor,n)}onAfterChangeToShape({binding:n}){I$(this.editor,n.fromId)}onBeforeIsolateFromShape({binding:n}){const t=this.editor.getShape(n.fromId);t&&up({editor:this.editor,arrow:t,terminal:n.props.terminal})}}m(Oh,"type","arrow"),m(Oh,"props",z_),m(Oh,"migrations",N_);function I$(e,n){var w;const t=e.getShape(n);if(!t)return;const r=kn(e,t),{start:o,end:s}=r,i=o?e.getShape(o.toId):void 0,a=s?e.getShape(s.toId):void 0,c=e.getAncestorPageId(t);if(!c)return;let l;if(i&&a)l=e.findCommonAncestor([i,a])??c;else if(i||a){const y=(w=i||a)==null?void 0:w.parentId;y&&y===t.parentId?l=t.parentId:l=c}else return;l&&l!==t.parentId&&e.reparentShapes([n],l);const d=e.getShape(n);if(!d)throw Error("no reparented arrow");const u=e.getShapeNearestSibling(d,i),f=e.getShapeNearestSibling(d,a);let p;if(u&&f)p=u.index>f.index?u:f;else if(u&&!f)p=u;else if(f&&!u)p=f;else return;let S;const g=e.getSortedChildIdsForParent(p.parentId).map(y=>e.getShape(y)).filter(y=>y.index>p.index);if(g.length){const y=g.find(v=>v.type!=="arrow");if(d.index>p.index&&(!y||d.index<y.index))return;S=Kl(p.index,g[0].index)}else S=Lo(p.index);S!==d.index&&e.updateShapes([{id:n,type:"arrow",index:S}])}function Qm(e,n){const t=kn(e,n);for(const r of["start","end"]){const o=t[r];if(!o)continue;const s=e.getShape(o.toId),i=e.getAncestorPageId(n)===e.getAncestorPageId(s);(!s||!i)&&up({editor:e,arrow:n,terminal:r,unbind:!0})}I$(e,n.id)}function up({editor:e,arrow:n,terminal:t,unbind:r=!1,useHandle:o=!1}){const s=ao(e,n);if(!s)throw new Error("expected arrow info");const i=o?s.start.handle:s.start.point,a=o?s.end.handle:s.end.point,c=t==="start"?i:a,l={id:n.id,type:"arrow",props:{[t]:{x:c.x,y:c.y},bend:n.props.bend}};if(!s.isStraight){const d=t==="start"?i:s.start.handle,u=t==="end"?a:s.end.handle,f=b.Med(d,u),p=b.Sub(d,u).per().uni().mul(s.handleArc.radius*2*Math.sign(n.props.bend)),S=Ud(s.handleArc.center,b.Add(f,p),s.handleArc.center,s.handleArc.radius);it((S==null?void 0:S.length)===1);const g=b.Dist(f,S[0])*Math.sign(n.props.bend);Os(g,l.props.bend)||(l.props.bend=g)}e.updateShape(l),r&&jh(e,n,t)}const E$=[Oh],Gt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},jt={s:2,m:3.5,l:5,xl:10},gc={s:18,m:24,l:36,xl:44},Go={s:18,m:22,l:26,xl:32},aG={s:18,m:20,l:24,xl:28},po={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},cG=20,lG=4.25,jr=16;/*!
|
|
110
|
-
* canvas-size
|
|
111
|
-
* v1.2.6
|
|
112
|
-
* https://github.com/jhildenbiddle/canvas-size
|
|
113
|
-
* (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
|
|
114
|
-
* MIT license
|
|
115
|
-
*/function dG(e,n){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var r,o,s,i,a=[],c=!0,l=!1;try{if(s=(t=t.call(e)).next,n===0){if(Object(t)!==t)return;c=!1}else for(;!(c=(r=s.call(t)).done)&&(a.push(r.value),a.length!==n);c=!0);}catch(d){l=!0,o=d}finally{try{if(!c&&t.return!=null&&(i=t.return(),Object(i)!==i))return}finally{if(l)throw o}}return a}}function PC(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 Gn(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?PC(Object(t),!0).forEach(function(r){uG(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):PC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function uG(e,n,t){return n=xG(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function hG(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 fG(e,n){if(e==null)return{};var t=hG(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 CC(e,n){return gG(e)||dG(e,n)||_$(e,n)||SG()}function Bu(e){return pG(e)||mG(e)||_$(e)||yG()}function pG(e){if(Array.isArray(e))return yv(e)}function gG(e){if(Array.isArray(e))return e}function mG(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function _$(e,n){if(e){if(typeof e=="string")return yv(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 yv(e,n)}}function yv(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 yG(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
|
|
116
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function SG(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
|
|
117
|
-
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function vG(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 xG(e){var n=vG(e,"string");return typeof n=="symbol"?n:String(n)}function zl(e){var n=e.sizes.shift(),t=Math.max(Math.ceil(n[0]),1),r=Math.max(Math.ceil(n[1]),1),o=[t-1,r-1,1,1],s=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,c;i?(a=new OffscreenCanvas(1,1),c=new OffscreenCanvas(t,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,c=document.createElement("canvas"),c.width=t,c.height=r);var l=a.getContext("2d"),d=c.getContext("2d");d&&(d.fillRect.apply(d,o),l.drawImage(c,t-1,r-1,1,1,0,0,1,1));var u=l&&l.getImageData(0,0,1,1).data[3]!==0,f=Date.now()-s;return[a,c].forEach(function(p){p.height=0,p.width=0}),i?(postMessage({width:t,height:r,benchmark:f,isTestPass:u}),!u&&e.sizes.length&&zl(e)):u?e.onSuccess(t,r,f):(e.onError(t,r,f),e.sizes.length&&zl(e)),u}var Jm={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]},wG=["onError","onSuccess"],Ka={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},ll={};function ey(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(d){var u=n||t?d:1,f=n||r?d:1;o.push([u,f])});else for(var s=e.min||Ka.min,i=e.step||Ka.step,a=Math.max(e.width,e.height);a>=s;){var c=n||t?a:1,l=n||r?a:1;o.push([c,l]),a-=i}return o}function Uu(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=fG(e,wG),a=null;if(!n)return!1;if(e.useWorker&&t){var c=`
|
|
118
|
-
var canvasTest = `.concat(zl.toString(),`;
|
|
119
|
-
onmessage = function(e) {
|
|
120
|
-
canvasTest(e.data);
|
|
121
|
-
};
|
|
122
|
-
`),l=new Blob([c],{type:"application/javascript"}),d=URL.createObjectURL(l);a=new Worker(d),URL.revokeObjectURL(d),a.onmessage=function(u){var f=u.data,p=f.width,S=f.height,g=f.benchmark,w=f.isTestPass;w?(ll[r].onSuccess(p,S,g),delete ll[r]):ll[r].onError(p,S,g)}}if(e.usePromise)return new Promise(function(u,f){var p=Gn(Gn({},e),{},{onError:function(y,v,P){var E;if(e.sizes.length===0)E=!0;else{var I=e.sizes.slice(-1),C=CC(I,1),_=CC(C[0],2),k=_[0],j=_[1];E=y===k&&v===j}o(y,v,P),E&&f({width:y,height:v,benchmark:P})},onSuccess:function(y,v,P){s(y,v,P),u({width:y,height:v,benchmark:P})}});if(a){var S=p.onError,g=p.onSuccess;ll[r]={onError:S,onSuccess:g},a.postMessage(i)}else zl(p)});if(a)ll[r]={onError:o,onSuccess:s},a.postMessage(i);else return zl(e)}var ty={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ey({width:n.max,height:n.max,min:n.min,step:n.step,sizes:Bu(Jm.area)}),r=Gn(Gn(Gn({},Ka),n),{},{sizes:t});return Uu(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ey({width:1,height:n.max,min:n.min,step:n.step,sizes:Bu(Jm.height)}),r=Gn(Gn(Gn({},Ka),n),{},{sizes:t});return Uu(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=ey({width:n.max,height:1,min:n.min,step:n.step,sizes:Bu(Jm.width)}),r=Gn(Gn(Gn({},Ka),n),{},{sizes:t});return Uu(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Gn(Gn({},Ka),n);return t.sizes=Bu(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),Uu(t)}};let ny=null;function bG(){return ny||(ny=PG()),ny}async function PG(){const e=await ty.maxWidth({usePromise:!0}),n=await ty.maxHeight({usePromise:!0}),t=await ty.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const IC=8192,CG=4096*4096;async function IG(e,n){if(e<=IC&&n<=IC&&e*n<=CG)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await bG(),s=e/n;if(e>t&&(e=t,n=e/s),n>r&&(n=r,e=n*s),e*n>o){const i=Math.sqrt(o/(e*n));e*=i,n*=i}return[e,n]}function EG(e,n){const t=e.w/n.w,r=e.h/n.h;return t<=1&&r<=1?e:t>r?{w:e.w/t,h:e.h/t}:{w:e.w/r,h:e.h/r}}function _G(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function kG(e){const n=new URL(e).host.replace("www.","");for(const t of Ad)if(k$(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const TG=e=>e.split("*").map(n=>_G(n)).join(".+"),k$=(e,n)=>!!e.find(t=>{const r=new RegExp(TG(t));return n.match(r)});function $G(e){const n=new URL(e).host.replace("www.","");for(const t of Ad)if(k$(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function T$(e){return $G(e)??kG(e)}function Ms(e){try{return T$(e)}catch(n){console.error(n)}}/*!
|
|
123
|
-
* MIT License
|
|
124
|
-
* Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
|
|
125
|
-
* Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
|
|
126
|
-
*/const Wa=" ",un=class un{static insertTextFirefox(n,t){n.setRangeText(t,n.selectionStart||0,n.selectionEnd||0,"end"),n.dispatchEvent(new InputEvent("input",{data:t,inputType:"insertText",isComposing:!1}))}static insert(n,t){const r=n.ownerDocument,o=r.activeElement;o!==n&&n.focus(),r.execCommand("insertText",!1,t)||un.insertTextFirefox(n,t),o===r.body?n.blur():o instanceof HTMLElement&&o!==n&&o.focus()}static set(n,t){n.select(),un.insert(n,t)}static getSelection(n){const{selectionStart:t,selectionEnd:r}=n;return n.value.slice(t||void 0,r||void 0)}static wrapSelection(n,t,r){const{selectionStart:o,selectionEnd:s}=n,i=un.getSelection(n);un.insert(n,t+i+(r??t)),n.selectionStart=(o||0)+t.length,n.selectionEnd=(s||0)+t.length}static replace(n,t,r){let o=0;n.value.replace(t,(...s)=>{const i=o+s[s.length-2],a=s[0].length;n.selectionStart=i,n.selectionEnd=i+a;const c=typeof r=="string"?r:r(...s);return un.insert(n,c),n.selectionStart=i,o+=c.length-a,c})}static findLineEnd(n,t){const r=n.lastIndexOf(`
|
|
127
|
-
`,t-1)+1;return n.charAt(r)!==" "?t:r+1}static indent(n){var a;const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.slice(t,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const c=o.lastIndexOf(`
|
|
128
|
-
`,t-1)+1,l=n.value.slice(c,r-1),d=l.replace(/^|\n/g,`$&${Wa}`),u=d.length-l.length;n.setSelectionRange(c,r-1),un.insert(n,d),n.setSelectionRange(t+1,r+u)}else un.insert(n,Wa)}static unindent(n){const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.lastIndexOf(`
|
|
129
|
-
`,t-1)+1,i=un.findLineEnd(o,r),a=n.value.slice(s,i),c=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),l=a.length-c.length;n.setSelectionRange(s,i),un.insert(n,c);const d=/\t| {1,2}/.exec(o.slice(s,t)),u=d?d[0].length:0,f=t-u;n.setSelectionRange(t-u,Math.max(f,r-l))}static indentCE(n){var c;const t=window.getSelection(),r=n.innerText,o=Hu(n)??0,s=Hu(n)??0,i=r.slice(o,s),a=(c=/\n/g.exec(i))==null?void 0:c.length;if(a&&a>0){const l=r.lastIndexOf(`
|
|
130
|
-
`,o-1)+1,d=r.slice(l,s-1),f=d.replace(/^|\n/g,`$&${Wa}`).length-d.length;t&&t.setBaseAndExtent(n,o+1,n,s+f)}else{const l=window.getSelection();n.innerText=r.slice(0,o)+Wa+r.slice(o),l==null||l.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=Hu(n)??0,s=Hu(n)??0,i=r.lastIndexOf(`
|
|
131
|
-
`,o-1)+1,a=un.findLineEnd(r,s),c=r.slice(i,a),l=c.replace(/(^|\n)(\t| {1,2})/g,"$1"),d=c.length-l.length;if(t){t.setBaseAndExtent(n,i,n,a);const u=/\t| {1,2}/.exec(r.slice(i,o)),f=u?u[0].length:0,p=o-f;t.setBaseAndExtent(n,o-f,n,Math.max(p,s-d))}}static normalizeText(n){return n.replace(un.fixNewLines,`
|
|
132
|
-
`)}static normalizeTextForDom(n){return n.replace(un.fixNewLines,`
|
|
133
|
-
`).split(`
|
|
134
|
-
`).map(t=>t||" ").join(`
|
|
135
|
-
`)}};m(un,"fixNewLines",/\r?\n|\r/g);let mc=un;function Hu(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 MG=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function $$(e){return MG.test(e)}function AG(e){return e.replace(/\t/g,Wa)}function jG(e){const n=e.split(`
|
|
136
|
-
`);for(;n[0]&&n[0].trim().length===0;)n.shift();let t=1/0;for(const r of n)if(r.trim().length>0){const o=r.length-r.trimStart().length;t=Math.min(t,o)}return n.map(r=>r.slice(t)).join(`
|
|
137
|
-
`)}function OG(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function DG(e){return OG(jG(AG(e)))}function RG(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i},a){e.registerExternalAssetHandler("file",async({file:c})=>{const l=c.name;let d=c;const u=r.includes(d.type),f=o.includes(d.type);it(u||f,`File type not allowed: ${d.type}`),it(d.size<=t,`File size too big: ${(d.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),d.type==="video/quicktime"&&(d=new Blob([d],{type:"video/mp4"}));let p=u?await so.getImageSize(d):await so.getVideoSize(d);const S=await so.isAnimated(d)||f,g=await WN(await d.arrayBuffer());if(isFinite(n)){const v=EG(p,{w:n,h:n});p!==v&&so.isStaticImageType(d.type)&&(p=v)}const w=wi.createId(g),y={id:w,type:u?"image":"video",typeName:"asset",props:{name:l,src:"",w:p.w,h:p.h,fileSize:d.size,mimeType:d.type,isAnimated:S}};return a?(y.props.src=w,await KW({persistenceKey:a,assetId:w,blob:d})):y.props.src=await ki.blobToDataUrl(d),wi.create(y)}),e.registerExternalAssetHandler("url",async({url:c})=>{var d,u,f,p,S;let l;try{const w=await(await go(c,{method:"GET",mode:"no-cors"})).text(),y=new DOMParser().parseFromString(w,"text/html");l={image:((d=y.head.querySelector('meta[property="og:image"]'))==null?void 0:d.getAttribute("content"))??"",favicon:((u=y.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:u.getAttribute("href"))??((f=y.head.querySelector('link[rel="icon"]'))==null?void 0:f.getAttribute("href"))??"",title:((p=y.head.querySelector('meta[property="og:title"]'))==null?void 0:p.getAttribute("content"))??c,description:((S=y.head.querySelector('meta[property="og:description"]'))==null?void 0:S.getAttribute("content"))??""},l.image.startsWith("/")&&(l.image=new URL(l.image,c).href),l.favicon.startsWith("/")&&(l.favicon=new URL(l.favicon,c).href)}catch(g){console.error(g),s.addToast({title:i("assets.url.failed"),severity:"error"}),l={image:"",favicon:"",title:"",description:""}}return{id:wi.createId(sS(c)),typeName:"asset",type:"bookmark",props:{src:c,description:l.description,image:l.image,favicon:l.favicon,title:l.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:c,text:l})=>{const d=c??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=new DOMParser().parseFromString(l,"image/svg+xml").querySelector("svg");if(!u)throw new Error("No <svg/> element present");let f=parseFloat(u.getAttribute("width")||"0"),p=parseFloat(u.getAttribute("height")||"0");if(!(f&&p)){document.body.appendChild(u);const g=u.getBoundingClientRect();document.body.removeChild(u),f=g.width,p=g.height}const S=await e.getAssetForExternalContent({type:"file",file:new File([l],"asset.svg",{type:"image/svg+xml"})});if(!S)throw Error("Could not create an asset");EC(e,[S],d)}),e.registerExternalContentHandler("embed",({point:c,url:l,embed:d})=>{const u=c??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),{width:f,height:p}=d,S=Fe(),g={id:S,type:"embed",x:u.x-(f||450)/2,y:u.y-(p||450)/2,props:{w:f,h:p,url:l}};e.createShapes([g]).select(S)}),e.registerExternalContentHandler("files",async({point:c,files:l})=>{const d=c??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=new b(d.x,d.y),f=[];await Promise.all(l.map(async(p,S)=>{if(p.size>t)return console.warn(`File size too big: ${(p.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),null;if(!p.type)throw new Error("No mime type");if(!r.concat(o).includes(p.type))return console.warn(`${p.name} not loaded - Extension not allowed.`),null;try{const g=await e.getAssetForExternalContent({type:"file",file:p});if(!g)throw Error("Could not create an asset");f[S]=g}catch(g){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(g),null}})),EC(e,Se(f),u)}),e.registerExternalContentHandler("text",async({point:c,text:l})=>{const d=c??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),u=e.getShapeUtil("text").getDefaultProps(),f=DG(l),p=e.getOnlySelectedShape();if(p&&"text"in p.props){e.updateShapes([{id:p.id,type:p.type,props:{text:f}}]);return}let S,g,w,y="middle";const v=f.split(`
|
|
138
|
-
`).length>1,P=$$(f);v&&(y=v?P?"end":"start":"middle");const E=e.textMeasure.measureText(f,{...Gt,fontFamily:po[u.font],fontSize:gc[u.size],maxWidth:null}),I=Math.min(v?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(E.w>I){const C=e.textMeasure.measureText(f,{...Gt,fontFamily:po[u.font],fontSize:gc[u.size],maxWidth:I});S=C.w,g=C.h,w=!1,y=P?"end":"start"}else S=E.w,g=E.h,w=!0;d.y-g/2<e.getViewportPageBounds().minY+40&&(d.y=e.getViewportPageBounds().minY+40+g/2),e.createShapes([{id:Fe(),type:"text",x:d.x-S/2,y:d.y-g/2,props:{text:f,textAlign:y,autoSize:w,w:S}}])}),e.registerExternalContentHandler("url",async({point:c,url:l})=>{const d=Ms(l);if(d)return e.putExternalContent({type:"embed",url:d.url,point:c,embed:d.definition});const u=c??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),f=wi.createId(sS(l)),p=LG(e,l,u);let S=e.getAsset(f),g=!1;if(!S){g=!0;try{const w=await e.getAssetForExternalContent({type:"url",url:l});if(!w)throw Error("Could not create an asset");S=w}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{g&&e.createAssets([S]),e.updateShapes([{id:p.id,type:p.type,props:{assetId:S.id}}])})})}async function EC(e,n,t){if(!n.length)return[];const r=b.From(t),o=[];for(let s=0;s<n.length;s++){const i=n[s];switch(i.type){case"bookmark":{o.push({id:Fe(),type:"bookmark",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,url:i.props.src}}),r.x+=300;break}case"image":{o.push({id:Fe(),type:"image",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w;break}case"video":o.push({id:Fe(),type:"video",x:r.x,y:r.y,opacity:1,props:{assetId:i.id,w:i.props.w,h:i.props.h}}),r.x+=i.props.w}}return e.batch(()=>{const s=n.filter(i=>!e.getAsset(i.id));s.length&&e.createAssets(s),e.createShapes(o).select(...o.map(i=>i.id)),M$(e,t)}),o.map(s=>s.id)}function M$(e,n){const t=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const o=r.center.sub(n);e.updateShapes(e.getSelectedShapes().map(s=>{const i=e.getShapeParentTransform(s).decompose().rotation,a=b.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!t.contains(r)&&e.zoomToSelection()}function LG(e,n,t){const r={id:Fe(),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),M$(e,t)}),e.getShape(r.id)}const FG=new Yo,zG=e=>async n=>!n||!n.props.src?null:e&&n.props.src.startsWith("asset:")?await FG.get(n,async()=>await NG(e,n.id)):n.type==="video"?n.props.src:n.type!=="image"?null:n.props.src;async function NG(e,n){const t=await HW({assetId:n,persistenceKey:e});return t?URL.createObjectURL(t):null}var _y;let BG=(_y=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")});m(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}))}})}},m(_y,"id","idle"),_y);var ky;let UG=(ky=class extends se{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onEnter",()=>{this.didTimeout=!1;const t=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});t?this.editor.setHintingShapes([t.id]):this.createArrowShape(),this.startPreciseTimeout()});m(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});m(this,"onPointerMove",()=>{if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,onInteractionEnd:"arrow"})}});m(this,"onPointerUp",()=>{this.cancel()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()});m(this,"preciseTimeout",-1);m(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var d;const{originPagePoint:t}=this.editor.inputs,r=Fe();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShape({id:r,type:"arrow",x:t.x,y:t.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=s.find(u=>u.id==="start"),l=(d=i.onHandleDrag)==null?void 0:d.call(i,o,{handle:{...c,x:0,y:0},isPrecise:!0,initial:a});l&&this.editor.updateShapes([l]),this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var o,s;const t=this.shape;if(!t)throw Error("expected shape");const r=this.editor.getShapeHandles(t);if(!r)throw Error("expected handles for arrow");{const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=r.find(d=>d.id==="start"),l=(o=i.onHandleDrag)==null?void 0:o.call(i,t,{handle:{...c,x:0,y:0},isPrecise:this.didTimeout,initial:a});l&&this.editor.updateShapes([l])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,c=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),l=r.find(u=>u.id==="end"),d=(s=i.onHandleDrag)==null?void 0:s.call(i,this.editor.getShape(t),{handle:{...l,x:c.x,y:c.y},isPrecise:!1,initial:a});d&&this.editor.updateShapes([d])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},m(ky,"id","pointing"),ky);class Dh extends se{constructor(){super(...arguments);m(this,"shapeType","arrow")}}m(Dh,"id","arrow"),m(Dh,"initial","idle"),m(Dh,"children",()=>[BG,UG]);class Zx extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"initialShape");m(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");m(this,"util",this.editor.getShapeUtil(this.shapeType));m(this,"isPen",!1);m(this,"isPenOrStylus",!1);m(this,"segmentMode","free");m(this,"didJustShiftClickToExtendPreviousShapeLine",!1);m(this,"pagePointWhereCurrentSegmentChanged",{});m(this,"pagePointWhereNextSegmentChanged",null);m(this,"lastRecordedPoint",{});m(this,"mergeNextPoint",!1);m(this,"currentLineLength",0);m(this,"canDraw",!1);m(this,"markId",null);m(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()});m(this,"onPointerMove",()=>{const{inputs:t}=this.editor;if(this.isPen&&!t.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&t.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(this.isPenOrStylus?b.Dist(t.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=t.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())});m(this,"onKeyDown",t=>{if(t.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()});m(this,"onKeyUp",t=>{if(t.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()});m(this,"onExit",()=>{this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(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=jt[r],s=t[0].points[0],i=t[t.length-1],a=i.points[i.points.length-1];return s!==a&&this.currentLineLength>o*4&&b.DistMin(s,a,o*2)}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+st(),this.editor.mark(this.markId);const{z:o=.5}=this.info.point;this.isPen=r,this.isPenOrStylus=r||o>0&&o<.5||o>.5&&o<1;const s=this.isPenOrStylus?o*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=t.clone(),this.initialShape){const a=this.editor.getShape(this.initialShape.id);if(a&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const c=Nt(a.props.segments);if(!c)throw Error("Expected a previous segment!");const l=Nt(c.points);if(!l)throw Error("Expected a previous point!");const{x:d,y:u}=this.editor.getPointInShapeSpace(a,t).toFixed(),f={type:this.segmentMode,points:[{x:l.x,y:l.y,z:+s.toFixed(2)},{x:d,y:u,z:+s.toFixed(2)}]},p=oe.applyToPoint(this.editor.getShapePageTransform(a.id),l);this.pagePointWhereCurrentSegmentChanged=p,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,f];this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const g={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(g.props.isClosed=this.getIsClosed(S,a.props.size)),this.editor.updateShapes([g]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const i=Fe();this.editor.createShapes([{id:i,type:this.shapeType,x:t.x,y:t.y,props:{isPen:this.isPenOrStylus,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+s.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(i)}updateDrawingShape(){const{initialShape:t}=this,{inputs:r}=this.editor;if(!t)return;const{id:o,props:{size:s}}=t,i=this.editor.getShape(o);if(!i)return;const{segments:a}=i.props,{x:c,y:l,z:d}=this.editor.getPointInShapeSpace(i,r.currentPagePoint).toFixed(),u=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,f={x:c,y:l,z:u};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(b.Dist2(p,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const g=Nt(a);if(!g)throw Error("Expected a previous segment!");const w=Nt(g.points);if(!w)throw Error("Expected a previous last point!");let y;const v=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(g.type==="straight"){this.currentLineLength+=b.Dist(w,v),y={type:"straight",points:[{...w},v]};const E=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(E,w)}else y={type:"straight",points:[v,f]};const P={id:o,type:this.shapeType,props:{segments:[...a,y]}};this.canClose()&&(P.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([P])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(b.Dist2(p,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const g=a.slice(),w=g[g.length-1],y=Nt(w.points);if(!y)throw Error("No previous point!");const v={type:"free",points:[...b.PointsBetween(y,f,6).map(I=>({x:Fo(I.x),y:Fo(I.y),z:Fo(I.z)}))]},P=[...g,v];this.currentLineLength<jt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(P));const E={id:o,type:this.shapeType,props:{segments:P}};this.canClose()&&(E.props.isClosed=this.getIsClosed(P,s)),this.editor.updateShapes([E])}break}case"straight":{const p=a.slice(),S=p[p.length-1],{pagePointWhereCurrentSegmentChanged:g}=this,{ctrlKey:w,currentPagePoint:y}=this.editor.inputs;if(!g)throw Error("We should have a point where the segment changed");let v,P=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(P=!w,this.didJustShiftClickToExtendPreviousShapeLine=!1):P=!w;let E=this.editor.getPointInShapeSpace(i,y).toFixed().toJson(),I=!1,C;if((this.editor.user.getIsSnapMode()?!w:w)&&p.length>2){let j,T=8/this.editor.getZoomLevel();for(let M=0,R=a.length-2;M<R;M++){const A=a[M];if(!A)break;if(A.type==="free")continue;const O=A.points[0],L=Nt(A.points);if(!(O&&L))continue;const G=b.NearestPointOnLineSegment(O,L,E);if(b.DistMin(G,E,T)){j=G.toFixed().toJson(),T=b.Dist(G,E),C=A;break}}j&&(I=!0,E=j)}if(I&&C){const j=this.editor.getShapePageTransform(i),T=C.points[0],M=Nt(C.points);if(!M)throw Error("Expected a last point!");const R=oe.applyToPoint(j,T),A=oe.applyToPoint(j,M),O=oe.applyToPoint(j,E);this.editor.snaps.setIndicators([{id:st(),type:"points",points:[R,O,A]}])}else{if(this.editor.snaps.clearIndicators(),P){const j=b.Angle(g,y),M=Df(j,24)-j;v=b.RotWith(y,g,M)}else v=y;E=this.editor.getPointInShapeSpace(i,v).toFixed().toJson()}this.currentLineLength+=b.Dist(S.points[0],E),p[p.length-1]={...S,type:"straight",points:[S.points[0],E]};const k={id:o,type:this.shapeType,props:{segments:p}};this.canClose()&&(k.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([k]);break}case"free":{const p=a.slice(),S=p[p.length-1],g=[...S.points];if(g.length&&this.mergeNextPoint){const{z:y}=g[g.length-1];g[g.length-1]={x:f.x,y:f.y,z:y?Math.max(y,f.z):f.z}}else this.currentLineLength+=b.Dist(g[g.length-1],f),g.push(f);p[p.length-1]={...S,points:g},this.currentLineLength<jt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(p));const w={id:o,type:this.shapeType,props:{segments:p}};if(this.canClose()&&(w.props.isClosed=this.getIsClosed(p,s)),this.editor.updateShapes([w]),g.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const y=Fe(),v=this.editor.getShape(o).props;this.editor.createShapes([{id:y,type:this.shapeType,x:Fo(r.currentPagePoint.x),y:Fo(r.currentPagePoint.y),props:{isPen:this.isPenOrStylus,scale:v.scale,segments:[{type:"free",points:[{x:0,y:0,z:this.isPenOrStylus?+(d*1.25).toFixed():.5}]}]}}]),this.initialShape=ot(this.editor.getShape(y)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(t){let r=0;for(const o of t)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=b.Dist2(a,i)}return Math.sqrt(r)}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:t}=this;t&&(this.editor.updateShapes([{id:t.id,type:t.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}m(Zx,"id","drawing");var Ty;let A$=(Ty=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("drawing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ty,"id","idle"),Ty);class Rh extends se{constructor(){super(...arguments);m(this,"shapeType","draw");m(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}m(Rh,"id","draw"),m(Rh,"initial","idle"),m(Rh,"children",()=>[A$,Zx]);class Sv extends Ah{constructor(){super(...arguments);m(this,"shapeType","frame");m(this,"onCreate",t=>{if(!t)return;const r=this.editor.getShapePageBounds(t),o=[],s=this.editor.getShapeAncestors(t).map(i=>i.id);this.editor.getSortedChildIdsForParent(t.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===t.id||a.isLocked)return;const c=this.editor.getShapePageBounds(a);c&&r.contains(c)&&HG(a,s,t)&&o.push(a.id)}),this.editor.reparentShapes(o,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}m(Sv,"id","frame"),m(Sv,"initial","idle");function HG(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var $y;let KG=($y=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(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}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m($y,"id","idle"),$y);var My;let WG=(My=class extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=Fe();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(Lr),scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]).select(o).setCurrentTool("select.resizing",{...t,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:t}=this.editor.inputs,r=Fe();this.markId=`creating:${r}`,this.editor.mark(this.markId);const o=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(Lr),i=s==="star"?{w:200,h:190}:s==="cloud"?{w:300,h:180}:{w:200,h:200};this.editor.createShapes([{id:r,type:"geo",x:t.x,y:t.y,props:{geo:this.editor.getStyleForNextShape(Lr),scale:o,...i}}]);const a=this.editor.getShape(r);if(!a)return;const{w:c,h:l}=a.props,d=new b(c/2,l/2).mul(o),u=this.editor.getShapeParentTransform(a);u&&d.rot(-u.rotation()),this.editor.select(r),this.editor.updateShape({id:a.id,type:"geo",x:a.x-d.x,y:a.y-d.y,props:{geo:this.editor.getStyleForNextShape(Lr),w:c*o,h:l*o}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},m(My,"id","pointing"),My);class Lh extends se{constructor(){super(...arguments);m(this,"shapeType","geo")}}m(Lh,"id","geo"),m(Lh,"initial","idle"),m(Lh,"children",()=>[KG,WG]);class Fh extends se{constructor(){super(...arguments);m(this,"shapeType","highlight");m(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}m(Fh,"id","highlight"),m(Fh,"initial","idle"),m(Fh,"children",()=>[A$,Zx]);var Ay;let GG=(Ay=class extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"onEnter",t=>{this.shapeId=t.shapeId,this.editor.setCursor({type:"cross",rotation:0})});m(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ay,"id","idle"),Ay);const _C=2;var jy;let VG=(jy=class extends se{constructor(){super(...arguments);m(this,"shape",{});m(this,"markId");m(this,"onEnter",t=>{const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=t.shapeId&&this.editor.getShape(t.shapeId);if(s&&r.shiftKey){this.markId=`creating:${s.id}`,this.editor.mark(this.markId),this.shape=s;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(p=>p.type==="vertex").sort(rn),c=a[a.length-1],l=a[a.length-2],d=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new b(this.shape.x,this.shape.y)),u=b.Sub(o,d).addXY(.1,.1),f=ot(this.shape.props.points);if(b.DistMin(c,l,_C)||b.DistMin(u,c,_C))f[c.id]={id:c.id,index:c.index,x:u.x,y:u.y};else{const p=Lo(c.index);f[p]={id:p,index:p,x:u.x,y:u.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:f}}])}else{const i=Fe();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y,props:{scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});m(this,"onPointerMove",()=>{if(this.shape&&this.editor.inputs.isDragging){const t=this.editor.getShapeHandles(this.shape);if(!t)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Nt(t);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()})}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}},m(jy,"id","pointing"),jy);class zh extends se{constructor(){super(...arguments);m(this,"shapeType","line")}}m(zh,"id","line"),m(zh,"initial","idle"),m(zh,"children",()=>[GG,VG]);var Oy;let YG=(Oy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Oy,"id","idle"),Oy);function We(e,n){var o;const t=new Set;for(const s of n){const i=e.getShape(s);if(!i)continue;e.getShapeUtil(i).onDragShapesOut&&t.add(i);const a=e.getShape(i.parentId);a&&e.getShapeUtil(a).onDragShapesOut&&t.add(a)}const r=new Map;for(const s of t){const i=j$(e,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=e.getShapeUtil(s),c=Se(i.map(l=>e.getShape(l)));(o=a.onDragShapesOut)==null||o.call(a,s,c)}}function j$(e,n){const t=e.getSortedChildIdsForParent(n.id);if(t.length===0)return[];const r=e.getShapePageBounds(n);if(!r)return[];let o,s,i;const a=[];for(const c of t){const l=e.getShapePageBounds(c);if(!l)continue;if(!r.includes(l)){a.push(c);continue}o??(o=e.getShapeGeometry(n)),s??(s=e.getShapePageTransform(n)),i??(i=s.applyToPoints(o.vertices));const d=e.getShapePageTransform(c).clone().invert().applyToPoints(i),{vertices:u,isClosed:f}=e.getShapeGeometry(c);if(!u.some(p=>Jn(p,d))){if(f){if(o$(d,u))continue}else if(QH(d,u))continue;a.push(c)}}return a}function hp(e,n,t=!1){e.select(n),e.setEditingShape(n),e.setCurrentTool("select.editing_shape",{target:"shape",shape:n}),t&&e.emit("select-all-text",{shapeId:n.id}),O$(e)}const XG=16;function O$(e){const n=e.getSelectionPageBounds(),t=e.getViewportPageBounds();if(n&&!t.contains(n)){const r=n.clone().expandBy(XG/e.getZoomLevel()).expand(t),o=t.clone().translate({x:(r.center.x-t.center.x)*2,y:(r.center.y-t.center.y)*2});e.zoomToBounds(o,{animation:{duration:e.options.animationMediumMs},inset:0})}}const Ii=20,qG=0,Be=200,sg=new b(Be/2,Be/2),D$=10,ZG=[[["a1"],new b(Be*.5,Be*-.5-Ii)],[["a2"],new b(Be*1.5+Ii,Be*.5)],[["a3"],new b(Be*.5,Be*1.5+Ii)],[["a4"],new b(Be*-.5-Ii,Be*.5)]];function QG(e){if(e===1)return ZG;const n=Be*e,t=Ii*e;return[[["a1"],new b(n*.5,n*-.5-t)],[["a2"],new b(n*1.5+t,n*.5)],[["a3"],new b(n*.5,n*1.5+t)],[["a4"],new b(n*-.5-t,n*.5)]]}function R$(e,n,t,r,o){return Object.fromEntries(QG(o).map(([s,i],a)=>{const c=i.clone();return a===0&&r?c.y-=r:a===2&&t&&(c.y+=t),[s,c.rot(n).add(e)]}))}function L$(e,n,t,r){const o=new Set(e.getSelectedShapeIds()),s=(Be+Ii+r)**2,i=new Map,a=[];for(const d of e.getCurrentPageShapes()){if(!e.isShapeOfType(d,"note")||t!==d.props.scale||o.has(d.id))continue;const u=e.getShapePageTransform(d.id);n===u.rotation()&&(i.set(d,e.getShapePageBounds(d).center),a.push(...Object.values(R$(u.point(),n,d.props.growY,r,t))))}const c=a.length;let l;for(const[d,u]of i)for(let f=0;f<c;f++)l=a[f],l&&(b.Dist2(u,l)>s||e.isPointInShape(d,l)&&(a[f]=void 0));return Se(a)}function F$(e,n,t,r,o=!1){let s;const i=e.getCurrentPageShapesSorted(),a=(Be+Ii**2)**n.props.scale;for(let c=i.length-1;c>=0;c--){const l=i[c];if(l.type==="note"&&l.id!==n.id){const d=e.getShapePageBounds(l);if(d&&b.Dist2(d.center,t)<a&&e.isPointInShape(l,t)){s=l;break}}}if(e.complete(),!s||o){e.mark("creating note shape");const c=Fe();e.createShape({id:c,type:"note",x:t.x,y:t.y,rotation:r,opacity:n.opacity,props:{...n.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const l=e.getShape(c);if(!l)return;const d=e.getPointInParentSpace(l,b.Sub(t,b.Rot(sg.clone().mul(l.props.scale),r)));e.updateShape({id:c,type:"note",x:d.x,y:d.y}),s=e.getShape(c)}return O$(e),s}var Dy;let JG=(Dy=class extends se{constructor(){super(...arguments);m(this,"dragged",!1);m(this,"info",{});m(this,"wasFocusedOnEnter",!1);m(this,"markId","");m(this,"shape",{});m(this,"onEnter",()=>{const{editor:t}=this;if(this.wasFocusedOnEnter=!t.getIsMenuOpen(),this.wasFocusedOnEnter){const r=Fe();this.markId=`creating:${r}`,t.mark(this.markId);const o=this.editor.inputs.originPagePoint.clone(),s=kC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=TC(this.editor,r,o)}});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=Fe(),o=this.editor.inputs.originPagePoint.clone(),s=kC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=TC(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...t,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(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)}},m(Dy,"id","pointing"),Dy);function kC(e,n,t){let r=D$/e.getZoomLevel(),o;for(const s of L$(e,0,t,0)){const i=b.Sub(n,s),a=i.len();a<r&&(r=a,o=i)}return o}function TC(e,n,t){e.createShape({id:n,type:"note",x:t.x,y:t.y,props:{scale:e.user.getIsDynamicResizeMode()?1/e.getZoomLevel():1}}).select(n);const r=e.getShape(n),o=e.getShapeGeometry(r).bounds;return e.updateShapes([{id:n,type:"note",x:r.x-o.width/2,y:r.y-o.height/2}]),e.getShape(n)}class Nh extends se{constructor(){super(...arguments);m(this,"shapeType","note")}}m(Nh,"id","note"),m(Nh,"initial","idle"),m(Nh,"children",()=>[YG,JG]);function eV(e){const n=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),renderingOnly:!0});if(!n)return e.setHoveredShape(null);let t;const r=e.getOutermostSelectableShape(n);return r===n||r.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(r.id)?t=n:t=r,e.setHoveredShape(t.id)}const Uo=YE(eV,32);var Ry;let tV=(Ry=class extends se{constructor(){super(...arguments);m(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Uo(this.editor)}});m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onExit",()=>{Uo.cancel()});m(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}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ry,"id","idle"),Ry);var Ly;let nV=(Ly=class extends se{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onExit",()=>{this.editor.setHintingShapes([])});m(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,o=Fe();this.markId=`creating:${o}`,this.editor.mark(this.markId);const s=this.createTextShape(o,r,!1);if(!s){this.cancel();return}this.shape=this.editor.getShape(s),this.editor.select(o),this.editor.setCurrentTool("select.resizing",{...t,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:18,y:1},onInteractionEnd:"text",onCreate:()=>{this.editor.setEditingShape(s.id),this.editor.setCurrentTool("select.editing_shape")}})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.cancel()});m(this,"onCancel",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){var s;this.editor.mark("creating text shape");const t=Fe(),{currentPagePoint:r}=this.editor.inputs;this.createTextShape(t,r,!0)&&(this.editor.select(t),this.editor.setEditingShape(t),this.editor.setCurrentTool("select"),(s=this.editor.root.getCurrent())==null||s.transition("editing_shape"))}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}createTextShape(t,r,o){this.editor.createShape({id:t,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:o,w:20,scale:this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1}});const s=this.editor.getShape(t);if(!s){this.cancel();return}const i=this.editor.getShapePageBounds(s),a=new b;if(o)switch(s.props.textAlign){case"start":{a.x=0;break}case"middle":{a.x=-i.width/2;break}case"end":{a.x=-i.width;break}}else a.x=0;if(a.y=-i.height/2,In(s.parentId)){const c=this.editor.getShapeParentTransform(s);a.rot(-c.rotation())}return this.editor.updateShape({...s,x:s.x+a.x,y:s.y+a.y}),s}},m(Ly,"id","pointing"),Ly);class Bh extends se{constructor(){super(...arguments);m(this,"shapeType","text")}}m(Bh,"id","text"),m(Bh,"initial","idle"),m(Bh,"children",()=>[tV,nV]);const rV=[Bh,Rh,Lh,Nh,zh,Sv,Dh,Fh];function _r(){return ss({isDarkMode:Kd()})}function yc(e){return{key:`${mo.id}:${e}`,getElement:async()=>{const n=oV(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await go(t)).blob(),s=await ki.blobToDataUrl(o),i=r.replace(t,s);return h.jsx("style",{children:i})}}}function oV(e){const n=D_[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function Qx(e){return{key:`${mo.id}:${e}`,getElement:async()=>e!=="pattern"?null:h.jsx(sV,{})}}function sV(){const e=_r(),n=8/12;return h.jsxs(h.Fragment,{children:[h.jsxs("mask",{id:"hash_pattern_mask",children:[h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),h.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[h.jsx("line",{x1:n*1,y1:n*3,x2:n*3,y2:n*1}),h.jsx("line",{x1:n*5,y1:n*7,x2:n*7,y2:n*5}),h.jsx("line",{x1:n*9,y1:n*11,x2:n*11,y2:n*9})]})]}),h.jsx("pattern",{id:fp(1,e.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function Jx(){return{key:`${mo.id}:pattern`,component:lV}}const Pl=8,$C=(e,n,t)=>new Promise((r,o)=>{const s=Pl*n*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?kf.darkMode.solid:kf.lightMode.solid,a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*n*e;const c=8/12,l=d=>d*n*e;a.beginPath(),a.moveTo(l(c*1),l(c*3)),a.lineTo(l(c*3),l(c*1)),a.moveTo(l(c*5),l(c*7)),a.lineTo(l(c*7),l(c*5)),a.moveTo(l(c*9),l(c*11)),a.lineTo(l(c*11),l(c*9)),a.stroke(),i.toBlob(d=>{!d||wt.throwToBlob.get()?o():r(d)})}),MC=(e,n)=>{const t=document.createElement("canvas");t.width=e[0],t.height=e[1];const r=t.getContext("2d");return r?(n(r),t.toDataURL()):""};let ry=null;function iV(){return ry||(ry={white:MC([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:MC([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),ry}function z$(e){return Math.ceil(Math.log2(Math.max(1,e)))}function fp(e,n){const t=z$(e);return`tldraw_hash_pattern_${n}_${t}`}function N$(e){const n=[],r=z$(e);for(let o=0;o<=r;o++)n.push(Math.pow(2,o));return n}function aV(e){const n=iV();return N$(e).flatMap(t=>[{zoom:t,url:n.white,theme:"light"},{zoom:t,url:n.black,theme:"dark"}])}function cV(){const e=N(),n=W("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),t=W("maxZoom",()=>Math.ceil(Nt(e.getCameraOptions().zoomSteps)),[e]),[r,o]=x.useState(!1),[s,i]=x.useState(()=>aV(t));return x.useEffect(()=>{const c=Promise.all(N$(t).flatMap(d=>[$C(n,d,!1).then(u=>({zoom:d,theme:"light",url:URL.createObjectURL(u)})),$C(n,d,!0).then(u=>({zoom:d,theme:"dark",url:URL.createObjectURL(u)}))]));let l=!1;return c.then(d=>{l||(i(d),o(!0))}),()=>{l=!0,o(!1),c.then(d=>{for(const{url:u}of d)URL.revokeObjectURL(u)})}},[n,t]),{defs:h.jsx(h.Fragment,{children:s.map(c=>{const l=fp(c.zoom,c.theme);return h.jsx("pattern",{id:l,width:Pl,height:Pl,patternUnits:"userSpaceOnUse",children:h.jsx("image",{href:c.url,width:Pl,height:Pl})},l)})}),isReady:r}}function lV(){const e=N(),n=x.useRef(null),{defs:t,isReady:r}=cV();return x.useEffect(()=>{if(r&&e.environment.isSafari){const o=B$(n.current);o&&e.timers.requestAnimationFrame(()=>{o.style.display="none",e.timers.requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),h.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function B$(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?B$(e.parentElement):null}const Jt=ve.memo(function({theme:n,d:t,color:r,fill:o,scale:s}){switch(o){case"none":return null;case"solid":return h.jsx("path",{fill:n[r].semi,d:t});case"semi":return h.jsx("path",{fill:n.solid,d:t});case"fill":return h.jsx("path",{fill:n[r].fill,d:t});case"pattern":return h.jsx(dV,{theme:n,color:r,fill:o,d:t,scale:s})}});function dV({d:e,color:n,theme:t}){const r=N(),o=l$(),s=W("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return h.jsxs(h.Fragment,{children:[h.jsx("path",{fill:t[n].pattern,d:e}),h.jsx("path",{fill:o?`url(#${fp(1,t.id)})`:i?t[n].semi:`url(#${fp(s,t.id)})`,d:e})]})}function uV(e){return e.replace(/\s/g," ")}function vv(e,n,t){const{padding:r=0}=t;if(n.length===0)return null;const o=J.From(n[0].box);for(const{box:l}of n)o.union(l);const s=r+(t.offsetX??0),i=(t.offsetY??0)+t.fontSize/2+(t.verticalTextAlign==="start"?r:t.verticalTextAlign==="end"?t.height-r-o.height:(Math.ceil(t.height)-o.height)/2);let a=null;const c=[];for(const{text:l,box:d}of n)a!==null&&d.y>a&&c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:d.y+i,children:`
|
|
139
|
-
`},c.length)),c.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:d.x+s,y:d.y+i,unicodeBidi:"plaintext",children:uV(l)},c.length)),a=d.y;return h.jsx("text",{fontSize:t.fontSize,fontFamily:t.fontFamily,fontStyle:t.fontFamily,fontWeight:t.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:t.stroke,strokeWidth:t.strokeWidth,fill:t.fill,children:c})}function hV(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=J.From(t[0].box);for(const{box:s}of t)o.union(s);if(e==="start-legacy")return(r-2*n-o.width)/2;if(e==="end-legacy")return-(r-2*n-o.width)/2}}function fV(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function ig({fontSize:e,font:n,align:t,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:c=!0}){const l=N(),d=_r(),u={fontSize:e,fontFamily:D_[n],textAlign:t,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Gt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:s,stroke:void 0,strokeWidth:void 0},f=l.textMeasure.measureTextSpans(o,u),p=hV(t,a,f,i.width);p&&(u.offsetX=p),u.offsetX+=i.x,u.offsetY+=i.y;const S=vv(l,f,u);let g=null;return c&&(u.fill=d.background,u.stroke=d.background,u.strokeWidth=2,g=vv(l,f,u)),h.jsxs(h.Fragment,{children:[g,S]})}const pV=x.forwardRef(function({isEditing:n,text:t,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:c},l){return h.jsx("textarea",{ref:l,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!n,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:t,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:Kt,onContextMenu:n?Kt:void 0,onPointerDown:a,onDoubleClick:c,onDragStart:_e})});function gV(e,n,t){const r=N(),o=x.useRef(null),s=W("isEditing",()=>r.getEditingShapeId()===e,[r]),i=W("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);x.useEffect(()=>{function d({shapeId:u}){var f;u===e&&((f=o.current)==null||f.select())}return r.on("select-all-text",d),()=>{r.off("select-all-text",d)}},[r,e,s]),x.useEffect(()=>{var d,u,f,p;s&&(document.activeElement!==o.current&&((d=o.current)==null||d.focus()),r.getInstanceState().isCoarsePointer&&((u=o.current)==null||u.select()),r.environment.isSafari&&((f=o.current)==null||f.blur(),(p=o.current)==null||p.focus()))},[r,s]);const a=x.useCallback(d=>{if(r.getEditingShapeId()===e)switch(d.key){case"Enter":{(d.ctrlKey||d.metaKey)&&r.complete();break}}},[r,e]),c=x.useCallback(d=>{if(r.getEditingShapeId()!==e)return;let u=mc.normalizeText(d.currentTarget.value);const f=u.replace(/\t/g,Wa);if(f!==u){const p=d.currentTarget.selectionStart;d.currentTarget.value=f,d.currentTarget.selectionStart=p+(f.length-u.length),d.currentTarget.selectionEnd=p+(f.length-u.length),u=f}r.updateShape({id:e,type:n,props:{text:u}})},[r,e,n]),l=x.useCallback(d=>{r.dispatch({...$n(d),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Kt(d)},[r,e]);return{rInput:o,handleFocus:Sf,handleBlur:Sf,handleKeyDown:a,handleChange:c,handleInputPointerDown:l,handleDoubleClick:Kt,isEmpty:t.trim().length===0,isEditing:s,isEditingAnything:i}}const ag=ve.memo(function({id:n,type:t,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:c,verticalAlign:l,wrap:d,isSelected:u,padding:f=0,onKeyDown:p,classNamePrefix:S,style:g,textWidth:w,textHeight:y}){const{rInput:v,isEmpty:P,isEditing:E,isEditingAnything:I,...C}=gV(n,t,r),[_,k]=x.useState(r);x.useEffect(()=>{E||k(r)},[E,r]);const j=mc.normalizeTextForDom(r),T=j.length>0,M=fV(c);if(!E&&!T)return null;const R=S||"tl-text";return h.jsx("div",{className:`${R}-label tl-text-wrapper`,"data-font":s,"data-align":c,"data-hastext":!P,"data-isediting":E,"data-iseditinganything":I,"data-textwrap":!!d,"data-isselected":u,style:{justifyContent:c==="middle"||M?"center":c,alignItems:l==="middle"?"center":l,padding:f,...g},children:h.jsxs("div",{className:`${R}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(w||0),color:o,width:w?Math.ceil(w):void 0,height:y?Math.ceil(y):void 0},children:[h.jsx("div",{className:`${R} tl-text tl-text-content`,dir:"auto",children:j.split(`
|
|
140
|
-
`).map((A,O)=>h.jsx("div",{dir:"auto",children:A},O))}),(I||u)&&h.jsx(pV,{ref:v,text:r,isEditing:E,...C,handleKeyDown:p??C.handleKeyDown},_)]})})});function to(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:c="dashed"}=t;let l=0,d=0,u=1,f=0,p=0;switch(c){case"dashed":{u=1,l=Math.min(n*a,e/4);break}case"dotted":{u=100,l=n/u;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=l/2,p+=l/2):s==="skip"&&(e-=l,p-=l),i==="outset"?e+=l/2:i==="skip"&&(e-=l)),d=Math.floor(e/l/(2*u)),d-=d%o,d<3&&c==="dashed"?e/n<4?(l=e,d=1,f=0):(l=e*(1/3),f=e*(1/3)):(l=e/d/(2*u),r?(p=l/2,f=(e-d*l)/d):f=(e-d*l)/Math.max(1,d-1)),{strokeDasharray:[l,f].join(" "),strokeDashoffset:p.toString()}}const AC=new WeakMap;function ew(e,n){const t=AC.get(n);if(t)return t;const r=ao(e,n);let o=0,s=0;const i=r.isStraight?new Bo({start:b.From(r.start.point),end:b.From(r.end.point)}):new Ba({center:b.Cast(r.handleArc.center),start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(n.props.text.trim()){const c=i.bounds,l=xv(n),{w:d,h:u}=e.textMeasure.measureText(n.props.text,{...Gt,fontFamily:po[n.props.font],fontSize:l,maxWidth:null});if(o=d,s=u,c.width>c.height){o=Math.max(Math.min(d,64),Math.min(c.width-64,d));const{w:f,h:p}=e.textMeasure.measureText(n.props.text,{...Gt,fontFamily:po[n.props.font],fontSize:l,maxWidth:o});o=f,s=p}if(o>16*l){o=16*l;const{w:f,h:p}=e.textMeasure.measureText(n.props.text,{...Gt,fontFamily:po[n.props.font],fontSize:l,maxWidth:o});o=f,s=p}}const a=new b(o,s).addScalar(lG*2*n.props.scale);return AC.set(n,a),a}function U$(e){const n=jt[e.props.size];return(cG+(n-jt.s)*2+(n===jt.xl?20:0))*e.props.scale}function mV(e,n,t){const r=ew(e,n),o=U$(n),s=b.Nudge(t.start.point,t.end.point,o),i=b.Nudge(t.end.point,t.start.point,o),a=zx(s,i,J.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[c,l]=a;b.Dist2(c,s)>b.Dist2(l,s)&&([l,c]=a);const d=s.add(b.Sub(t.middle,c)),u=i.add(b.Sub(t.middle,l)),f=b.Dist(t.start.point,d)/t.length,p=b.Dist(t.start.point,u)/t.length;return{start:f,end:p}}function yV(e,n,t){const r=ew(e,n),o=U$(n),s=Math.sign(n.props.bend),i=o/t.handleArc.radius*s,a=b.Angle(t.bodyArc.center,t.start.point)-i,c=b.Angle(t.bodyArc.center,t.end.point)+i,l=Fi(t.bodyArc.center,t.bodyArc.radius,a),d=Fi(t.bodyArc.center,t.bodyArc.radius,c),u=[],f=jC(t.bodyArc.center,t.bodyArc.radius,a,c,s,J.FromCenter(l,r).corners);u.push(new xt({points:J.FromCenter(l,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const p=jC(t.bodyArc.center,t.bodyArc.radius,a,c,s,J.FromCenter(d,r).corners);u.push(new xt({points:J.FromCenter(d,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const _ of[...f??[],...p??[],l,d])u.push(new Yx({x:_.x-3,y:_.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const S=(f&&OC(t.start.point,f))??t.middle,g=(p&&OC(t.end.point,p))??t.middle,w=b.Angle(t.bodyArc.center,t.start.point),y=b.Angle(t.bodyArc.center,t.end.point),v=b.Angle(t.bodyArc.center,S),P=b.Angle(t.bodyArc.center,g);if(Cs(w,v,s)>Cs(w,P,s))return{start:.5,end:.5,dbg:u};const E=Cs(w,y,s),I=Cs(w,v,s)/E,C=Cs(w,P,s)/E;return{start:I,end:C,dbg:u}}function Uh(e,n){let t;const r=[],o=ao(e,n),s=!!o.bindings.start,i=!!o.bindings.end,a=o.start.arrowhead!=="none",c=o.end.arrowhead!=="none";if(o.isStraight){const d=mV(e,n,o);let u=Tt(n.props.labelPosition,a||s?d.start:0,c||i?d.end:1);u=u>=.48&&u<=.52?.5:u,t=b.Lrp(o.start.point,o.end.point,u)}else{const d=yV(e,n,o);d.dbg&&r.push(...d.dbg);let u=Tt(n.props.labelPosition,a||s?d.start:0,c||i?d.end:1);u=u>=.48&&u<=.52?.5:u;const f=SV(b.Angle(o.bodyArc.center,o.start.point),b.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),u);t=Fi(o.bodyArc.center,o.bodyArc.radius,f)}const l=ew(e,n);return{box:J.FromCenter(t,l),debugGeom:r}}function jC(e,n,t,r,o,s){const i=hv(e,n,s),a=Cs(t,r,o);return i==null?void 0:i.filter(c=>{const l=Cs(t,b.Angle(e,c),o);return l>=0&&l<=a})}function OC(e,n){let t=null,r=-1/0;for(const o of n){const s=b.Dist2(e,o);s>r&&(t=o,r=s)}return t}function SV(e,n,t,r){const o=Cs(e,n,t);return e+o*r*t*-1}function xv(e){return aG[e.props.size]*e.props.scale}function vV(e,n,t){const r=n==="end"?e.end.point:e.start.point,o=n==="end"?e.start.point:e.end.point,s=e.isStraight?b.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,t*3),t);let a;if(e.isStraight)a=b.Nudge(r,o,i);else{const c=qH(r,i,e.handleArc.center,e.handleArc.radius);a=n==="end"?e.handleArc.sweepFlag?c[0]:c[1]:e.handleArc.sweepFlag?c[1]:c[0]}return b.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function xV({point:e,int:n}){const t=b.RotWith(n,e,ke/6),r=b.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function wV({point:e,int:n}){const t=b.RotWith(n,e,ke/6),r=b.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function bV({point:e,int:n}){const t=b.Sub(n,e).div(2),r=b.Add(e,b.Rot(t,Ve)),o=b.Sub(e,b.Rot(t,Ve));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function PV({point:e,int:n}){const t=b.Lrp(e,n,.45),r=b.Dist(t,e);return`M ${t.x-r},${t.y}
|
|
141
|
-
a ${r},${r} 0 1,0 ${r*2},0
|
|
142
|
-
a ${r},${r} 0 1,0 -${r*2},0 `}function CV({point:e,int:n}){const t=b.Lrp(e,n,.75),r=b.RotWith(t,e,ke/4),o=b.RotWith(t,e,-ke/4),s=b.Lrp(r,o,.5);return s.add(b.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function IV({int:e,point:n}){const t=b.Lrp(n,e,.85),r=b.Sub(t,n).div(2),o=b.Add(n,b.Rot(r,Ve)),s=b.Sub(n,b.Rot(r,Ve)),i=b.Add(t,b.Rot(r,Ve)),a=b.Sub(t,b.Rot(r,Ve));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function EV({int:e,point:n}){const t=b.Sub(e,n).div(2),r=b.Add(n,b.Rot(t,Ve)),o=b.Sub(n,b.Rot(t,Ve));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function pp(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=vV(e,n,t);if(o){switch(r){case"bar":return EV(o);case"square":return IV(o);case"diamond":return CV(o);case"dot":return PV(o);case"inverted":return bV(o);case"arrow":return xV(o);case"triangle":return wV(o)}return""}}function _V(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 H$(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 K$(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function kV(e){return K$(e.start.handle,e.end.handle)}function W$(e){return K$(e.start.point,e.end.point)}let TV=0;class Hh extends Nr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"canSnap",()=>!1);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"canBeLaidOut",t=>{const r=kn(this.editor,t);return!r.start&&!r.end});m(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const s=r.id,i=kn(this.editor,t);if(s==="middle"){const{start:C,end:_}=Ua(this.editor,t,i),k=b.Sub(_,C),j=b.Per(k),T=b.Med(_,C),M=b.Sub(T,j),R=b.Add(T,j),A=b.NearestPointOnLineSegment(M,R,r,!1);let O=b.Dist(A,T);return b.Clockwise(A,_,T)&&(O*=-1),{id:t.id,type:t.type,props:{bend:O}}}const a={id:t.id,type:"arrow",props:{}},c=i[s],d=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return jh(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const u=this.editor.getShapePageTransform(t.id).applyToPoint(r),f=this.editor.getShapeAtPoint(u,{hitInside:!0,hitFrameInside:!0,margin:0,filter:C=>!C.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:C,binding:"arrow"})});if(!f)return jh(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const p=this.editor.getShapeGeometry(f),S=J.ZeroFix(p.bounds),w=this.editor.getShapePageTransform(a.id).applyToPoint(r),y=this.editor.getPointInShapeSpace(f,w);let v=o;v||(!c||c&&f.id!==c.toId)&&(v=this.editor.inputs.pointerVelocity.len()<.5),o||(p.isClosed||(v=!0),d&&f.id===d.toId&&d.props.isPrecise&&(v=!0));const P={x:(y.x-S.minX)/S.width,y:(y.y-S.minY)/S.height};v&&b.Dist(y,S.center)<Math.max(4,Math.min(Math.min(S.width,S.height)*.15,16))/this.editor.getZoomLevel()&&(P.x=.5,P.y=.5);const E={terminal:s,normalizedAnchor:P,isPrecise:v,isExact:this.editor.inputs.altKey};cl(this.editor,t,f.id,E),this.editor.setHintingShapes([f.id]);const I=kn(this.editor,t);return I.start&&I.end&&I.start.toId===I.end.toId&&b.Equals(I.start.props.normalizedAnchor,I.end.props.normalizedAnchor)&&cl(this.editor,t,I.end.toId,{...I.end.props,normalizedAnchor:{x:I.end.props.normalizedAnchor.x+.05,y:I.end.props.normalizedAnchor.y}}),a});m(this,"onTranslateStart",t=>{const r=kn(this.editor,t),o=Ua(this.editor,t,r),s=this.editor.getShapePageTransform(t.id),i=this.editor.getSelectedShapeIds();if(!(r.start&&(i.includes(r.start.toId)||this.editor.isAncestorSelected(r.start.toId))||r.end&&(i.includes(r.end.toId)||this.editor.isAncestorSelected(r.end.toId)))){RC.set(t,{pagePosition:s.applyToPoint(t),terminalBindings:$d(o,(a,c)=>{const l=r[a];return l?{binding:l,shapePosition:c,pagePosition:s.applyToPoint(c)}:null})}),r.start&&(up({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&up({editor:this.editor,arrow:t,terminal:"end",useHandle:!0});for(const a of["start","end"]){const c=r[a];c&&this.editor.updateBinding({...c,props:{...c.props,isPrecise:!0}})}}});m(this,"onTranslate",(t,r)=>{const o=RC.get(t);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=b.Sub(s.applyToPoint(r),o.pagePosition);for(const a of Object.values(o.terminalBindings)){if(!a)continue;const c=b.Add(a.pagePosition,b.Mul(i,.5)),l=this.editor.getShapeAtPoint(c,{hitInside:!0,hitFrameInside:!0,margin:0,filter:d=>!d.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:d,binding:"arrow"})});if((l==null?void 0:l.id)===a.binding.toId){const d=J.ZeroFix(this.editor.getShapeGeometry(l).bounds),u=this.editor.getPointInShapeSpace(l,c),f={x:(u.x-d.minX)/d.width,y:(u.y-d.minY)/d.height};cl(this.editor,r,l.id,{...a.binding.props,normalizedAnchor:f,isPrecise:!0})}else jh(this.editor,r,a.binding.props.terminal)}});m(this,"_resizeInitialBindings",new Yo);m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(t,()=>kn(this.editor,t)),a=Ua(this.editor,t,i),{start:c,end:l}=ot(t.props);let{bend:d}=t.props;i.start||(c.x=a.start.x*o,c.y=a.start.y*s),i.end||(l.x=a.end.x*o,l.y=a.end.y*s);const u=Math.abs(o),f=Math.abs(s),p=i!=null&&i.start?b.From(i.start.props.normalizedAnchor):null,S=i!=null&&i.end?b.From(i.end.props.normalizedAnchor):null;return o<0&&s>=0?(d!==0&&(d*=-1,d*=Math.max(u,f)),p&&(p.x=1-p.x),S&&(S.x=1-S.x)):o>=0&&s<0?(d!==0&&(d*=-1,d*=Math.max(u,f)),p&&(p.y=1-p.y),S&&(S.y=1-S.y)):o>=0&&s>=0?d!==0&&(d*=Math.max(u,f)):o<0&&s<0&&(d!==0&&(d*=Math.max(u,f)),p&&(p.x=1-p.x,p.y=1-p.y),S&&(S.x=1-S.x,S.y=1-S.y)),i.start&&p&&cl(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:p.toJson()}),i.end&&S&&cl(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:S.toJson()}),{props:{start:c,end:l,bend:d}}});m(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"}}}});m(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}canBind({toShapeType:t}){return t!=="arrow"}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw",scale:1}}getGeometry(t){const r=ao(this.editor,t),o=[],s=r.isStraight?new Bo({start:b.From(r.start.point),end:b.From(r.end.point)}):new Ba({center:b.Cast(r.handleArc.center),start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(t.props.text.trim()){const a=Uh(this.editor,t);o.push(...a.debugGeom),i=new es({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Ur({children:[...i?[s,i]:[s],...o]})}getHandles(t){const r=ao(this.editor,t);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y}].filter(Boolean)}component(t){const r=_r(),o=this.editor.getOnlySelectedShape(),s=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,i=ao(this.editor,t);if(!(i!=null&&i.isValid))return null;const a=Uh(this.editor,t),c=t.id===this.editor.getOnlySelectedShapeId(),d=this.editor.getEditingShapeId()===t.id||t.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(Ys,{id:t.id,style:{minWidth:50,minHeight:50},children:h.jsx(DC,{shape:t,shouldDisplayHandles:s&&(o==null?void 0:o.id)===t.id})}),d&&h.jsx(ag,{id:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:xv(t),lineHeight:Gt.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w,isSelected:c,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(t){const r=rg(t.id),o=ao(this.editor,t);if(!o)return null;const{start:s,end:i}=Ua(this.editor,t,o==null?void 0:o.bindings),a=this.editor.getShapeGeometry(t),c=a.bounds,l=t.props.text.trim()?a.children[1]:null;if(b.Equals(s,i))return null;const d=jt[t.props.size]*t.props.scale,u=o.start.arrowhead&&pp(o,"start",d),f=o.end.arrowhead&&pp(o,"end",d),p=o.isStraight?W$(o):H$(o),S=u&&o.start.arrowhead!=="arrow"||f&&o.end.arrowhead!=="arrow"||!!l,g=(t.id+"_clip").replace(":","_");return r&&l?h.jsx("rect",{x:z(l.x),y:z(l.y),width:l.w,height:l.h,rx:3.5*t.props.scale,ry:3.5*t.props.scale}):h.jsxs("g",{children:[S&&h.jsx("defs",{children:h.jsxs("mask",{id:g,children:[h.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.w+200,height:c.h+200,fill:"white"}),l&&h.jsx("rect",{x:z(l.x),y:z(l.y),width:l.w,height:l.h,fill:"black",rx:3.5*t.props.scale,ry:3.5*t.props.scale}),u&&h.jsx("path",{d:u,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),f&&h.jsx("path",{d:f,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{...S?{mask:`url(#${g})`}:void 0,children:[S&&h.jsx("rect",{x:c.minX-100,y:c.minY-100,width:c.width+200,height:c.height+200,opacity:0}),h.jsx("path",{d:p})]}),u&&h.jsx("path",{d:u}),f&&h.jsx("path",{d:f}),l&&h.jsx("rect",{x:z(l.x),y:z(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5})]})}toSvg(t,r){r.addExportDef(Qx(t.props.fill)),t.props.text&&r.addExportDef(yc(t.props.font));const o=ss(r),s=1/t.props.scale;return h.jsxs("g",{transform:`scale(${s})`,children:[h.jsx(DC,{shape:t,shouldDisplayHandles:!1}),h.jsx(ig,{fontSize:xv(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:o[t.props.labelColor].solid,bounds:Uh(this.editor,t).box,padding:4*t.props.scale})]})}getCanvasSvgDefs(){return[Jx(),{key:"arrow:dot",component:MV},{key:"arrow:cross",component:AV}]}}m(Hh,"type","arrow"),m(Hh,"props",L_),m(Hh,"migrations",F_);function $V(e,n){const t=ao(e,n);return t.isStraight?b.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const DC=sr(function({shape:n,shouldDisplayHandles:t}){const r=N(),o=_r(),s=ao(r,n),i=J.ZeroFix(r.getShapeGeometry(n).bounds),a=kn(r,n),c=ve.useMemo(()=>r.environment.isSafari?TV+=1:0,[n]);if(!(s!=null&&s.isValid))return null;const l=jt[n.props.size]*n.props.scale,d=s.start.arrowhead&&pp(s,"start",l),u=s.end.arrowhead&&pp(s,"end",l),f=s.isStraight?W$(s):H$(s);let p=null;if(t){const E=2/r.getZoomLevel(),{strokeDasharray:I,strokeDashoffset:C}=to($V(r,n),E,{end:"skip",start:"skip",lengthRatio:2.5});p=a.start||a.end?h.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?kV(s):_V(s),strokeDasharray:I,strokeDashoffset:C,strokeWidth:E,markerStart:a.start?a.start.props.isExact?"":a.start.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:a.end?a.end.props.isExact?"":a.end.props.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:S,strokeDashoffset:g}=to(s.isStraight?s.length:Math.abs(s.bodyArc.length),l,{style:n.props.dash}),w=Uh(r,n),y=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),v=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),P=(n.id+"_clip_"+c).replace(":","_");return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsxs("mask",{id:P,children:[h.jsx("rect",{x:z(-100+i.minX),y:z(-100+i.minY),width:z(i.width+200),height:z(i.height+200),fill:"white"}),n.props.text.trim()&&h.jsx("rect",{x:w.box.x,y:w.box.y,width:w.box.w,height:w.box.h,fill:"black",rx:4,ry:4}),d&&y&&h.jsx("path",{d,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),u&&v&&h.jsx("path",{d:u,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{fill:"none",stroke:o[n.props.color].solid,strokeWidth:l,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[p,h.jsxs("g",{mask:`url(#${P})`,children:[h.jsx("rect",{x:z(i.minX-100),y:z(i.minY-100),width:z(i.width+200),height:z(i.height+200),opacity:0}),h.jsx("path",{d:f,strokeDasharray:S,strokeDashoffset:g})]}),d&&y&&n.props.fill!=="none"&&h.jsx(Jt,{theme:o,d,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),u&&v&&n.props.fill!=="none"&&h.jsx(Jt,{theme:o,d:u,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),d&&h.jsx("path",{d}),u&&h.jsx("path",{d:u})]})]})}),RC=new WeakMap;function MV(){return h.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:h.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function AV(){return h.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[h.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),h.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const LC="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 Sc({url:e,zoomLevel:n}){return h.jsx("a",{className:de("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Kt,onPointerUp:Kt,title:e,draggable:!1,children:h.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${LC}") center 100% / 100% no-repeat`,WebkitMask:`url("${LC}") center 100% / 100% no-repeat`}})})}const FC="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",jV=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function tw(e){return jV.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,c=new b(r,o),{x:l,y:d}=c.rot(-e);return`${l}px ${d}px ${s}px ${i}px ${a}`}).join(", ")}const OV=300,G$=320,DV=46,RV=101;class Kh extends Oc{constructor(){super(...arguments);m(this,"canResize",()=>!1);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"onBeforeCreate",t=>zC(this.editor,t));m(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(nr.isValid(r.props.url))FV(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}};if(t.props.assetId!==r.props.assetId)return zC(this.editor,r)})}getDefaultProps(){return{url:"",w:OV,h:G$,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),s=LV(t);return h.jsx(Ki,{children:h.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:tw(o)},children:[(!r||r.props.image)&&h.jsxs("div",{className:"tl-bookmark__image_container",children:[r?h.jsx("img",{className:"tl-bookmark__image",draggable:!1,referrerPolicy:"strict-origin-when-cross-origin",src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):h.jsx("div",{className:"tl-bookmark__placeholder"}),(r==null?void 0:r.props.image)&&h.jsx(Sc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),h.jsxs("div",{className:"tl-bookmark__copy_container",children:[r!=null&&r.props.title?h.jsx("h2",{className:"tl-bookmark__heading",children:r.props.title}):null,r!=null&&r.props.description&&(r!=null&&r.props.image)?h.jsx("p",{className:"tl-bookmark__description",children:r.props.description}):null,h.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Kt,onPointerUp:Kt,onClick:Kt,children:[r!=null&&r.props.favicon?h.jsx("img",{className:"tl-bookmark__favicon",src:r==null?void 0:r.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",alt:`favicon of ${s}`}):h.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${FC}") center 100% / 100% no-repeat`,WebkitMask:`url("${FC}") center 100% / 100% no-repeat`}}),h.jsx("span",{children:s})]})]})]})})}indicator(t){return h.jsx("rect",{width:z(t.props.w),height:z(t.props.h),rx:"6",ry:"6"})}}m(Kh,"type","bookmark"),m(Kh,"props",K_),m(Kh,"migrations",W_);function zC(e,n){const t=n.props.assetId?e.getAsset(n.props.assetId):null;let r=G$;return t&&(t.props.image||(t.props.title?r=RV:r=DV)),{...n,props:{...n.props,h:r}}}const LV=e=>{try{return new URL(e.props.url).hostname.replace(/^www\./,"")}catch{return e.props.url}};function FV(e,n){const{url:t}=n.props,r=wi.createId(sS(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}}]),zV(e,n))}const zV=t_(async(e,n)=>{if(e.isDisposed)return;const{url:t}=n.props,r=await e.getAssetForExternalContent({type:"url",url:t});r&&e.batch(()=>{e.createAssets([r]),e.updateShapes([{id:n.id,type:n.type,props:{assetId:r.id}}])})},500);function Wi(e,n=!1){const t=e.length;if(t<2)return"";let r=e[0].point,o=e[1].point;if(t===2)return`M${Ee(r)}L${Ee(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=En(r,o);return n?`M${En(e[0].point,e[1].point)}Q${Ee(e[1].point)}${En(e[1].point,e[2].point)}T${s}${En(e[t-1].point,e[0].point)}${En(e[0].point,e[1].point)}Z`:`M${Ee(e[0].point)}Q${Ee(e[1].point)}${En(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Ee(e[t-1].point)}`}function NV(e,n={}){const{start:t={},end:r={}}=n,{cap:o=!0}=t,{cap:s=!0}=r;it(!t.taper&&!r.taper,"cap taper not supported here"),it(!t.easing&&!r.easing,"cap easing not supported here"),it(o&&s,"cap must be true");const i=So(e,n);og(i,n);const a=BV(i);let c="";for(const l of a)c+=HV(l,n);return c}function BV(e){if(e.length<=2)return[e];const n=[];let t=[e[0]],r=b.Sub(e[1].point,e[0].point).uni(),o,s,i,a,c;for(let l=1,d=e.length;l<d-1;l++){if(i=e[l-1],a=e[l],c=e[l+1],o=b.Sub(c.point,a.point).uni(),s=b.Dpr(r,o),r=o,s<-.8){const u={...a,point:a.input};t.push(u),n.push(oy(t)),t=[u];continue}if(t.push(a),!(s>.7)&&(b.Dist2(i.point,a.point)+b.Dist2(a.point,c.point))/((i.radius+a.radius+c.radius)/3)**2<1.5){t.push(a),n.push(oy(t)),t=[a];continue}}return t.push(e[e.length-1]),n.push(oy(t)),n}function oy(e){const n=e[0];let t;for(;e.length>2&&(t=e[1],b.Dist2(n.point,t.point)<((n.radius+t.radius)/2*.5)**2);)e.splice(1,1);const r=e[e.length-1];let o;for(;e.length>2&&(o=e[e.length-2],b.Dist2(r.point,o.point)<((r.radius+o.radius)/2*.5)**2);)e.splice(e.length-2,1);return e.length>1&&(e[0]={...e[0],vector:b.Sub(e[0].point,e[1].point).uni()},e[e.length-1]={...e[e.length-1],vector:b.Sub(e[e.length-2].point,e[e.length-1].point).uni()}),e}function UV(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 HV(e,n={}){if(e.length===0)return"";if(e.length===1)return UV(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=C$(e,n);r.reverse();let o=`M${Ee(t[0])}T`;for(let s=1;s<t.length;s++)o+=En(t[s-1],t[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),c=b.Add(s.point,b.Mul(a,i)),l=b.Add(s.point,b.Mul(a,-i));o+=`${Ee(c)}A${z(i)},${z(i)} 0 0 1 ${Ee(l)}T`}for(let s=1;s<r.length;s++)o+=En(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),c=b.Add(s.point,b.Mul(a,i)),l=b.Add(s.point,b.Mul(a,-i));o+=`${Ee(c)}A${z(i)},${z(i)} 0 0 1 ${Ee(l)}Z`}return o}const KV=e=>e*.65+c7(e*ke/2)*.35,WV=e=>({size:e,thinning:.5,streamline:sc(e,[9,16],[.64,.74],!0),smoothing:.62,easing:At.easeOutSine,simulatePressure:!0}),GV=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:KV}),NC=e=>({size:e,thinning:0,streamline:sc(e,[9,16],[.68,.74],!0),smoothing:.62,simulatePressure:!1,easing:At.linear}),VV=e=>({size:e,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:At.linear});function nw({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:At.easeOutSine,last:n}}function wv(e,n,t,r){const o=e.isComplete||t;return r?e.isPen?{...VV(n),last:o}:{...NC(n),last:o}:e.dash==="draw"?e.isPen?{...GV(n),last:o}:{...WV(n),last:o}:{...NC(n),last:o}}function vc(e){const n=[];for(const t of e)if(t.type==="free"||t.points.length<2)n.push(...t.points.map(b.Cast));else{const r=Math.max(4,Math.floor(b.Dist(t.points[0],t.points[1])/16));n.push(...b.PointsBetween(t.points[0],t.points[1],r))}return n}function YV(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class Wh extends Nr{constructor(){super(...arguments);m(this,"hideResizeHandles",t=>sy(t));m(this,"hideRotateHandle",t=>sy(t));m(this,"hideSelectionBoundsFg",t=>sy(t));m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:c,y:l,z:d})=>({x:Fo(o*c),y:Fo(s*l),z:d}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(t){const r=vc(t.props.segments),o=(jt[t.props.size]+1)*t.props.scale;if(t.props.segments.length===1){const i=J.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new Yx({x:-o,y:-o,radius:o,isFilled:!0})}const s=So(r,wv(t.props,o,t.props.isPen,!0)).map(i=>i.point);return t.props.isClosed?new xt({points:s,isFilled:t.props.fill!=="none"}):new jc({points:s})}component(t){return h.jsx(Ys,{id:t.id,children:h.jsx(BC,{shape:t,zoomLevel:this.editor.getZoomLevel()})})}indicator(t){var u;const r=vc(t.props.segments);let o=(jt[t.props.size]+1)*t.props.scale;const s=this.editor.getZoomLevel();!(s<.5&&s<1.5/o)&&!t.props.isPen&&t.props.dash==="draw"&&r.length===1&&(o+=Wr(t.id)()*(o/6));const a=t.props.isComplete||((u=Nt(t.props.segments))==null?void 0:u.type)==="straight",c=wv(t.props,o,a,!0),l=So(r,c),d=l.length>1?Wi(l,t.props.isClosed):V$(r[0],o);return h.jsx("path",{d})}toSvg(t,r){r.addExportDef(Qx(t.props.fill));const o=1/t.props.scale;return h.jsx("g",{transform:`scale(${o})`,children:h.jsx(BC,{shape:t,zoomLevel:1})})}getCanvasSvgDefs(){return[Jx()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return jt[t.props.size]*r/2*t.props.scale}}m(Wh,"type","draw"),m(Wh,"props",V_),m(Wh,"migrations",Y_);function V$(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 sy(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function BC({shape:e,zoomLevel:n}){var u;const t=_r(),r=vc(e.props.segments),o=e.props.isComplete||((u=Nt(e.props.segments))==null?void 0:u.type)==="straight";let s=(jt[e.props.size]+1)*e.props.scale;const i=n<.5&&n<1.5/s;!i&&!e.props.isPen&&e.props.dash==="draw"&&r.length===1&&(s+=Wr(e.id)()*(s/6));const a=wv(e.props,s,o,i);if(!i&&e.props.dash==="draw")return h.jsxs(h.Fragment,{children:[e.props.isClosed&&e.props.fill&&r.length>1?h.jsx(Jt,{d:Wi(So(r,a),e.props.isClosed),theme:t,color:e.props.color,fill:e.props.isClosed?e.props.fill:"none",scale:e.props.scale}):null,h.jsx("path",{d:NV(r,a),strokeLinecap:"round",fill:t[e.props.color].solid})]});const c=So(r,a),l=c.length<2,d=l?V$(r[0],0):Wi(c,e.props.isClosed);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{d,theme:t,color:e.props.color,fill:l||e.props.isClosed?e.props.fill:"none",scale:e.props.scale}),h.jsx("path",{d,strokeLinecap:"round",fill:l?t[e.props.color].solid:"none",stroke:t[e.props.color].solid,strokeWidth:s,strokeDasharray:l?"none":YV(e,s),strokeDashoffset:"0"})]})}function XV(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:c=1/0,minHeight:l=1,maxHeight:d=1/0}=t;let u=e.props.w*s,f=e.props.h*i;const p=new b(0,0);if(u>0){if(u<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=u-a;break}case"top":case"bottom":{p.x=(u-a)/2;break}default:p.x=0}u=a}}else if(p.x=u,u=-u,u<a){switch(o){case"top_left":case"left":case"bottom_left":{p.x=-u;break}default:p.x=-a}u=a}if(f>0){if(f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=f-l;break}case"right":case"left":{p.y=(f-l)/2;break}default:p.y=0}f=l}}else if(p.y=f,f=-f,f<l){switch(o){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-l}f=l}const{x:S,y:g}=p.rot(e.rotation).add(r);return{x:S,y:g,props:{w:Math.min(c,u),h:Math.min(d,f)}}}const qV=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class Gh extends Oc{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",t=>!this.canResize(t));m(this,"canEdit",()=>!0);m(this,"canResize",t=>{var r,o;return!!((o=(r=Ms(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});m(this,"canEditInReadOnly",()=>!0);m(this,"isAspectRatioLocked",t=>{const r=Ms(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});m(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=Ms(t.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const c=t.props.w/t.props.h;c>1?i*=c:a/=c}return XV(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=rg(t.id),a=x.useMemo(()=>T$(s),[s]),c=W("is hovering",()=>{const{editingShapeId:p,hoveredShapeId:S}=this.editor.getCurrentPageState();if(p&&S!==p){const g=this.editor.getShape(p);if(g&&this.editor.isShapeOfType(g,"embed"))return!0}return!1},[]),l=this.editor.getShapePageTransform(t).rotation(),d=i||c;if(typeof window<"u"&&(window!==window.top||window.self!==window.parent)&&(a==null?void 0:a.definition.type)==="tldraw")return null;if((a==null?void 0:a.definition.type)==="github_gist"){const p=a.url.split("/").pop();if(!p)throw Error("No gist id!");return h.jsx(Ki,{className:"tl-embed-container",id:t.id,children:h.jsx(ZV,{id:p,width:z(r),height:z(o),isInteractive:d,pageRotation:l})})}const f=qV({...V8,...(a==null?void 0:a.definition.overridePermissions)??{}});return h.jsx(Ki,{className:"tl-embed-container",id:t.id,children:a!=null&&a.definition?h.jsx("iframe",{className:"tl-embed",sandbox:f,src:a.embedUrl,width:z(r),height:z(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:d?"auto":"none",zIndex:d?"":"-1",boxShadow:tw(l),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(t){const r=x.useMemo(()=>Ms(t.props.url),[t.props.url]);return h.jsx("rect",{width:z(t.props.w),height:z(t.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}m(Gh,"type","embed"),m(Gh,"props",X_),m(Gh,"migrations",q_);function ZV({id:e,file:n,isInteractive:t,width:r,height:o,style:s,pageRotation:i}){return h.jsx("iframe",{className:"tl-embed",draggable:!1,width:z(r),height:z(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:t?"all":"none",zIndex:t?"":"-1",boxShadow:tw(i)},srcDoc:`
|
|
143
|
-
<html>
|
|
144
|
-
<head>
|
|
145
|
-
<base target="_blank">
|
|
146
|
-
</head>
|
|
147
|
-
<body>
|
|
148
|
-
<script src=${`https://gist.github.com/${e}.js${n?`?file=${n}`:""}`}><\/script>
|
|
149
|
-
<style type="text/css">
|
|
150
|
-
* { margin: 0px; }
|
|
151
|
-
table { height: 100%; background-color: red; }
|
|
152
|
-
.gist { background-color: none; height: 100%; }
|
|
153
|
-
.gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
|
|
154
|
-
</style>
|
|
155
|
-
</body>
|
|
156
|
-
</html>`})}const QV=x.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=N(),s=x.useCallback(c=>{c.key==="Enter"&&!c.nativeEvent.isComposing&&(Kt(c),c.currentTarget.blur(),o.setEditingShape(null))},[o]),i=x.useCallback(c=>{const l=o.getShape(e);if(!l)return;const d=l.props.name,u=c.currentTarget.value.trim();d!==u&&o.updateShapes([{id:e,type:"frame",props:{name:u}}])},[e,o]),a=x.useCallback(c=>{const l=o.getShape(e);if(!l)return;const d=l.props.name,u=c.currentTarget.value;d!==u&&o.updateShapes([{id:e,type:"frame",props:{name:u}}])},[e,o]);return h.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[h.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:t?void 0:"none"},value:n,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),Y$(n,"Frame")+""]})}),JV=function({id:n,name:t,width:r,height:o}){const s=N(),i=W("shape rotation",()=>Ds(s.getShapePageTransform(n).rotation()),[s,n]),a=rg(n),c=x.useRef(null),l=x.useCallback(S=>{const g=$n(S);s.getEditingShapeId()!==n&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...g}),S.preventDefault())},[s,n]);x.useEffect(()=>{const S=c.current;S&&a&&(S.focus(),S.select())},[c,a]);const u=((i+Math.PI/4)*(2/Math.PI)+4)%4,f=["top","left","bottom","right"][Math.floor(u)];let p;switch(f){case"top":p="";break;case"right":p=`translate(${z(r)}px, 0px) rotate(90deg)`;break;case"bottom":p=`translate(${z(r)}px, ${z(o)}px) rotate(180deg)`;break;case"left":p=`translate(0px, ${z(o)}px) rotate(270deg)`;break}return h.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(f==="top"||f==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${p} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:l,children:h.jsx("div",{className:"tl-frame-heading-hit-area",children:h.jsx(QV,{ref:c,id:n,name:t,isEditing:a})})})};function Y$(e,n){return e.match(/^\s*$/)?n:e}class Vh extends Oc{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"canReceiveNewChildrenOfType",(t,r)=>!t.isLocked);m(this,"canDropShapes",(t,r)=>!t.isLocked);m(this,"onDragShapesOver",(t,r)=>{r.every(o=>o.parentId===t.id)||this.editor.reparentShapes(r,t.id)});m(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())});m(this,"onResize",(t,r)=>w$(t,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(t){return new es({width:t.props.w,height:t.props.h,isFilled:!1})}component(t){const r=this.editor.getShapeGeometry(t).bounds,o=_r(),s=W("is creating this shape",()=>{const i=this.editor.getStateDescendant("select.resizing");if(!i||!i.getIsActive())return!1;const a=i==null?void 0:i.info;return a?a.isCreating&&this.editor.getOnlySelectedShapeId()===t.id:!1},[t.id]);return h.jsxs(h.Fragment,{children:[h.jsx(Ys,{children:h.jsx("rect",{className:de("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:h.jsx(JV,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t,r){const o=ss({isDarkMode:r.isDarkMode}),a=((Ds(this.editor.getShapePageTransform(t.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,c=Math.floor(a);let l;switch(c){case 0:l="";break;case 3:l=`translate(${z(t.props.w)}, 0) rotate(90)`;break;case 2:l=`translate(${z(t.props.w)}, ${z(t.props.h)}) rotate(180)`;break;case 1:l=`translate(0, ${z(t.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}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"},u=this.editor.textMeasure.measureTextSpans(Y$(t.props.name,"Frame")+"",d),f=u[0],p=Nt(u),S=p.box.w+p.box.x-f.box.x,g=vv(this.editor,u,{offsetY:-d.height-2,...d});return h.jsxs(h.Fragment,{children:[h.jsx("rect",{width:t.props.w,height:t.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),h.jsxs("g",{transform:l,children:[h.jsx("rect",{x:-8,y:-d.height-4,width:S+16,height:d.height,fill:o.background,rx:4,ry:4}),g]})]})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return h.jsx("rect",{width:z(r.width),height:z(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}m(Vh,"type","frame"),m(Vh,"props",Z_),m(Vh,"migrations",Q_);function UC(e,n){return e>n?(ke*(n/2)+(e-n))*2:(ke*(e/2)+(n-e))*2}function X$(e,n){return rw(e,n).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function eY(e,n,t,r){const o=e/4,s=n/4,i=Wr(r),a=t*.75,c=v=>v.addXY(i()*a,i()*a),l=new b(e/2,n),d=new b(0,s*1.2),u=new b(e/2,s*.9),f=new b(e,s*1.2),p=c(new b(e/2,n)),S=c(new b(0,s*1.2)),g=c(new b(e/2,s*.9)),w=c(new b(e,s*1.2));return[new tn({start:l,cp1:new b(o*1.5,s*3),cp2:new b(0,s*2.5),end:d}),new tn({start:d,cp1:new b(0,-s*.32),cp2:new b(o*1.85,-s*.32),end:u}),new tn({start:u,cp1:new b(o*2.15,-s*.32),cp2:new b(e,-s*.32),end:f}),new tn({start:f,cp1:new b(e,s*2.5),cp2:new b(o*2.5,s*3),end:p}),new tn({start:p,cp1:new b(o*1.5,s*3),cp2:new b(0,s*2.5),end:S}),new tn({start:S,cp1:new b(0,-s*.32),cp2:new b(o*1.85,-s*.32),end:g}),new tn({start:g,cp1:new b(o*2.15,-s*.32),cp2:new b(e,-s*.32),end:w}),new tn({start:w,cp1:new b(e,s*2.5),cp2:new b(o*2.5,s*3),end:l})].map((v,P)=>v.getSvgPathData(P===0)).join(" ")+" Z"}function rw(e,n){const t=e/4,r=n/4;return[new tn({start:new b(e/2,n),cp1:new b(t*1.5,r*3),cp2:new b(0,r*2.5),end:new b(0,r*1.2)}),new tn({start:new b(0,r*1.2),cp1:new b(0,-r*.32),cp2:new b(t*1.85,-r*.32),end:new b(e/2,r*.9)}),new tn({start:new b(e/2,r*.9),cp1:new b(t*2.15,-r*.32),cp2:new b(e,-r*.32),end:new b(e,r*1.2)}),new tn({start:new b(e,r*1.2),cp1:new b(e,r*2.5),cp2:new b(t*2.5,r*3),end:new b(e/2,n)})]}function tY(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function nY(e,n,t,r){const o=Wr(e),s=n/2,i=t/2,a=yk(s,i),c=[],l=De*o(),d=De+Ve/2+Math.abs(o())*Ve,u=Math.max(16,a/10);for(let f=0;f<u;f++){const p=f/(u-1),S=l+p*d,g=Math.cos(S),w=Math.sin(S);c.push(new b(s*g+n*.5+.05*o(),i*w+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?At.easeInOutSine(p):At.easeInExpo(p)))/2)))}return So(c,tY(r))}function rY(e,n,t,r){return Wi(nY(e,n,t,r))}function bv(e){let n="M";const t=e.length;let r,o,s;for(let i=0,a=t;i<a;i+=3)r=e[i],o=e[i+1],s=e[i+2],n+=`${Ee(r)}L${Ee(o)}Q${Ee(s)}`;return n+=`${Ee(e[0])}`,n}function Pv(e,n,t,r,o){const s=[],i=Wr(e);let a=n[0],c;const l=n.length;for(let d=0,u=l*o;d<u;d++){c=b.AddXY(n[(d+1)%l],i()*t,i()*t);const f=b.Sub(c,a),p=b.Len(f),S=b.Div(f,p).mul(Math.min(p/4,r));s.push(b.Add(a,S),b.Add(c,S.neg()),c),a=c}return s}function oY(e,n,t){const r=Math.min(e,n)/2,o=Math.max(e,n)-r*2,i=(Math.PI*(r*2)+2*o)/t,a=e>n?[{type:"straight",start:new b(r,0),delta:new b(1,0)},{type:"arc",center:new b(e-r,r),startAngle:-ke/2},{type:"straight",start:new b(e-r,n),delta:new b(-1,0)},{type:"arc",center:new b(r,r),startAngle:ke/2}]:[{type:"straight",start:new b(e,r),delta:new b(0,1)},{type:"arc",center:new b(r,n-r),startAngle:0},{type:"straight",start:new b(0,n-r),delta:new b(0,-1)},{type:"arc",center:new b(r,r),startAngle:ke}];let c=0;const l=[];for(let d=0;d<t;d++){const u=a[0];u.type==="straight"?l.push(b.Add(u.start,b.Mul(u.delta,c))):l.push(Fi(u.center,r,u.startAngle+c/r)),c+=i;let f=u.type==="straight"?o:ke*r;for(;c>f;)c-=f,a.push(a.shift()),f=a[0].type==="straight"?o:ke*r}return l}const sY={s:50,m:70,l:100,xl:130},iY=.2;function cg(e,n,t,r){const o=Wr(t),s=UC(e,n),i=Math.max(Math.ceil(s/sY[r]),6,Math.ceil(s/Math.min(e,n))),a=s/i*iY,c=Math.max(e-a*2,1),l=Math.max(n-a*2,1),u=UC(c,l)/i,f=(e-c)/2,p=(n-l)/2,S=oY(c,l,i).map(P=>P.addXY(f,p)),g=e<20?0:a*.3,w=n<20?0:a*.3,y=S.slice(0);for(let P=0;P<Math.floor(i/2);P++)y[P]=b.AddXY(y[P],o()*g,o()*w),y[i-P-1]=b.AddXY(y[i-P-1],o()*g,o()*w);const v=[];for(let P=0;P<y.length;P++){const E=P===y.length-1?0:P+1,I=y[P],C=y[E],_=S[P],k=S[E],j=b.Dist(_,k),T=u-j,R=b.Dist(I,C)/j,A=(Math.max(f,p)+T)*R,O=b.Lrp(_,k,.5).add(b.Sub(k,_).uni().per().mul(A));O.x<0?O.x=0:O.x>e&&(O.x=e),O.y<0?O.y=0:O.y>n&&(O.y=n);const L=N0(I,C,O),G=b.Dist(L||b.Average([I,C]),I);v.push({leftPoint:I,rightPoint:C,arcPoint:O,center:L,radius:G})}return v}function aY(e,n,t,r){const o=[],s=cg(e,n,t,r);for(const{center:i,radius:a,leftPoint:c,rightPoint:l}of s)o.push(...h7(c,l,i,a,10));return o}function Cv(e,n,t,r){const o=cg(e,n,t,r);let s=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:i,rightPoint:a,radius:c,center:l}of o){if(l===null){s+=` L${a.toFixed()}`;continue}const d=b.Clockwise(i,a,l)?"0":"1";s+=` A${z(c)},${z(c)} 0 ${d},1 ${a.toFixed()}`}return s+=" Z",s}const cY={s:.5,m:.7,l:.9,xl:1.6};function lY(e,n,t,r){const o=Wr(t),s=cY[r],i=cg(e,n,t,r),l=i.reduce((p,S)=>p+b.Dist2(S.leftPoint,S.rightPoint),0)/i.length>(s*15)**2?p=>p.addXY(o()*s*2,o()*s*2):p=>p;let d=`M${i[0].leftPoint.toFixed()}`,u=l(i[0].leftPoint),f=`M${u.toFixed()}`;for(const{leftPoint:p,center:S,rightPoint:g,radius:w,arcPoint:y}of i){if(S===null){d+=` L${g.toFixed()}`;const _=l(g);f+=` L${_.toFixed()}`,u=_;continue}const v=b.Clockwise(p,g,S)?"0":"1";d+=` A${z(w)},${z(w)} 0 ${v},1 ${g.toFixed()}`;const P=l(g),E=l(y),I=N0(u,P,E);if(!Number.isFinite(I.x)||!Number.isFinite(I.y)){f+=` L${P.toFixed()}`,u=P;continue}const C=Math.abs(b.Dist(I,u));f+=` A${z(C)},${z(C)} 0 ${v},1 ${P.toFixed()}`,u=P}return d+f+" Z"}function Iv(e,n){switch(e.geo){case"x-box":return dY(e.w,e.h,n,e.dash);case"check-box":return uY(e.w,e.h);default:return}}function dY(e,n,t,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new b(0,0),new b(e/2,n/2)],[new b(e,n),new b(e/2,n/2)],[new b(0,n),new b(e/2,n/2)],[new b(e,0),new b(e/2,n/2)]];const s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(n,a));return[[new b(s(t*o),i(t*o)),new b(s(e-t*o),i(n-t*o))],[new b(s(t*o),i(n-t*o)),new b(s(e-t*o),i(t*o))]]}function uY(e,n){const t=Math.min(e,n)*.82,r=(e-t)/2,o=(n-t)/2,s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(n,a));return[[new b(s(r+t*.25),i(o+t*.52)),new b(s(r+t*.45),i(o+t*.82))],[new b(s(r+t*.45),i(o+t*.82)),new b(s(r+t*.82),i(o+t*.22))]]}function HC({shape:e,shouldScale:n}){const t=n?e.props.scale:1,r=N(),o=_r(),{id:s,props:i}=e,{w:a,color:c,fill:l,dash:d,growY:u,size:f}=i,p=jt[f]*t,S=i.h+u;switch(i.geo){case"cloud":if(d==="solid"){const g=Cv(a,S,s,f);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:g,color:c,fill:l,scale:t}),h.jsx("path",{d:g,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}else if(d==="draw"){const g=lY(a,S,s,f);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:g,color:c,fill:l,scale:t}),h.jsx("path",{d:g,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}else{const g=Cv(a,S,s,f),w=cg(a,S,s,f);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:g,color:c,fill:l,scale:t}),h.jsx("g",{strokeWidth:p,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:w.map(({leftPoint:y,rightPoint:v,center:P,radius:E},I)=>{const C=P?E*Ds(Ds(b.Angle(P,v))-Ds(b.Angle(P,y))):b.Dist(y,v),{strokeDasharray:_,strokeDashoffset:k}=to(C,p,{style:d,start:"outset",end:"outset"});return h.jsx("path",{d:P?`M${y.x},${y.y}A${E},${E},0,0,1,${v.x},${v.y}`:`M${y.x},${y.y}L${v.x},${v.y}`,strokeDasharray:_,strokeDashoffset:k},I)})})]})}case"ellipse":{const g=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),w=g.getSvgPathData(!0);if(d==="dashed"||d==="dotted"){const y=g.length,{strokeDasharray:v,strokeDashoffset:P}=to(y<64?y*2:y,p,{style:d,snap:4,closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:w,color:c,fill:l,scale:t}),h.jsx("path",{d:w,strokeWidth:p,fill:"none",stroke:o[c].solid,strokeDasharray:v,strokeDashoffset:P})]})}else{const v=(n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e)).getSvgPathData(!0);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:v,color:c,fill:l,scale:t}),h.jsx("path",{d:v,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}}case"oval":{const g=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),w=g.getSvgPathData(!0);if(d==="dashed"||d==="dotted"){const y=g.getLength(),{strokeDasharray:v,strokeDashoffset:P}=to(y<64?y*2:y,p,{style:d,snap:4,start:"outset",end:"outset",closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:w,color:c,fill:l,scale:t}),h.jsx("path",{d:w,strokeWidth:p,fill:"none",stroke:o[c].solid,strokeDasharray:v,strokeDashoffset:P})]})}else return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:w,color:c,fill:l,scale:t}),h.jsx("path",{d:w,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}case"heart":if(d==="dashed"||d==="dotted"||d==="solid"){const g=X$(a,S),w=rw(a,S);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:g,color:c,fill:l,scale:t}),w.map((y,v)=>{const{strokeDasharray:P,strokeDashoffset:E}=to(y.length,p,{style:d,snap:1,start:"outset",end:"outset",closed:!0});return h.jsx("path",{d:y.getSvgPathData(),strokeWidth:p,fill:"none",stroke:o[c].solid,strokeDasharray:P,strokeDashoffset:E,pointerEvents:"all"},`curve_${v}`)})]})}else{const g=eY(a,S,p,e.id);return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:g,color:c,fill:l,scale:t}),h.jsx("path",{d:g,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}default:{const g=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),w=g instanceof Ur?g.children[0].vertices:g.vertices,y=Iv(e.props,p);if(d==="solid"){let v="M"+w[0]+"L"+w.slice(1)+"Z";if(y)for(const[P,E]of y)v+=`M${P.x},${P.y}L${E.x},${E.y}`;return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:v,color:c,fill:l,scale:t}),h.jsx("path",{d:v,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}else if(d==="dashed"||d==="dotted"){const v="M"+w[0]+"L"+w.slice(1)+"Z";return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:v,color:c,fill:l,scale:t}),h.jsxs("g",{strokeWidth:p,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(w.length)).map((P,E)=>{const I=b.ToFixed(w[E]),C=b.ToFixed(w[(E+1)%w.length]),_=b.Dist(I,C),{strokeDasharray:k,strokeDashoffset:j}=to(_,p,{style:d,start:"outset",end:"outset"});return h.jsx("line",{x1:I.x,y1:I.y,x2:C.x,y2:C.y,strokeDasharray:k,strokeDashoffset:j},E)}),y&&y.map(([P,E],I)=>{const C=b.Dist(P,E),{strokeDasharray:_,strokeDashoffset:k}=to(C,p,{style:d,start:"skip",end:"skip",snap:d==="dotted"?4:void 0});return h.jsx("path",{d:`M${P.x},${P.y}L${E.x},${E.y}`,stroke:o[c].solid,strokeWidth:p,fill:"none",strokeDasharray:_,strokeDashoffset:k},`line_fg_${I}`)})]})]})}else if(d==="draw"){let v=bv(Pv(s,w,p/3,p*2,2));if(y)for(const[E,I]of y)v+=`M${E.toFixed()}L${I.toFixed()}`;const P=bv(Pv(s,w,0,p*2,1));return h.jsxs(h.Fragment,{children:[h.jsx(Jt,{theme:o,d:P,color:c,fill:l,scale:t}),h.jsx("path",{d:v,stroke:o[c].solid,strokeWidth:p,fill:"none"})]})}}}}const fr=17*3;class Yh extends Oc{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(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()}}])});m(this,"onResize",(t,{handle:r,newPoint:o,scaleX:s,scaleY:i,initialShape:a})=>{let c=a.props.w*s,l=(a.props.h+a.props.growY)*i,d=0,u=0;if(t.props.text.trim()){let g=Math.max(Math.abs(c),fr),w=Math.max(Math.abs(l),fr);g<fr&&w===fr&&(g=fr),g===fr&&w<fr&&(w=fr);const y=Ku(this.editor,{...t,props:{...t.props,w:g,h:w}}),v=Math.max(Math.abs(c),y.w)*Math.sign(c),P=Math.max(Math.abs(l),y.h)*Math.sign(l);d=Math.abs(v)-Math.abs(c),u=Math.abs(P)-Math.abs(l),c=v,l=P}const f=new b(0,0);s<0&&(f.x+=c),(r==="left"||r==="top_left"||r==="bottom_left")&&(f.x+=s<0?d:-d),i<0&&(f.y+=l),(r==="top"||r==="top_left"||r==="top_right")&&(f.y+=i<0?u:-u);const{x:p,y:S}=f.rot(t.rotation).add(o);return{x:p,y:S,props:{w:Math.max(Math.abs(c),1),h:Math.max(Math.abs(l),1),growY:0}}});m(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=Ku(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}}});m(this,"onBeforeUpdate",(t,r)=>{const o=t.props.text,s=r.props.text;if(o===s&&t.props.font===r.props.font&&t.props.size===r.props.size)return;if(o&&!s)return{...r,props:{...r.props,growY:0}};const i=t.props.w,a=t.props.h,c=Ku(this.editor,r),l=c.w,d=c.h;if(!o&&s&&s.length===1){let f=Math.max(i,l),p=Math.max(a,d);return t.props.w<fr&&t.props.h<fr&&(f=Math.max(f,fr),p=Math.max(p,fr),f=Math.max(f,p),p=Math.max(f,p)),{...r,props:{...r.props,w:f,h:p,growY:0}}}let u=null;if(d>a?u=d-a:t.props.growY&&(u=0),u!==null)return{...r,props:{...r.props,growY:u,w:Math.max(r.props.w,l)}};if(l>t.props.w)return{...r,props:{...r.props,w:l}}});m(this,"onDoubleClick",t=>{if(this.editor.inputs.altKey)switch(t.props.geo){case"rectangle":return{...t,props:{geo:"check-box"}};case"check-box":return{...t,props:{geo:"rectangle"}}}})}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:"",scale:1}}getGeometry(t){const r=Math.max(1,t.props.w),o=Math.max(1,t.props.h+t.props.growY),s=r/2,i=o/2,a=jt[t.props.size]*t.props.scale,c=t.props.fill!=="none";let l;switch(t.props.geo){case"cloud":{l=new xt({points:aY(r,o,t.id,t.props.size),isFilled:c});break}case"triangle":{l=new xt({points:[new b(s,0),new b(r,o),new b(0,o)],isFilled:c});break}case"diamond":{l=new xt({points:[new b(s,0),new b(r,i),new b(s,o),new b(0,i)],isFilled:c});break}case"pentagon":{l=new xt({points:fm(r,o,5),isFilled:c});break}case"hexagon":{l=new xt({points:fm(r,o,6),isFilled:c});break}case"octagon":{l=new xt({points:fm(r,o,8),isFilled:c});break}case"ellipse":{l=new zW({width:r,height:o,isFilled:c});break}case"oval":{l=new NW({width:r,height:o,isFilled:c});break}case"star":{const v=De/5/2,P=Math.floor(5/4)*2,E=5*2-P,I=0,C=Math.floor(5/2)*2,_=Math.cos(-Ve+P*v)*r/2,k=Math.cos(-Ve+E*v)*r/2,j=Math.sin(-Ve+I*v)*o/2,T=Math.sin(-Ve+C*v)*o/2,M=r-Math.abs(_-k),R=o-Math.abs(T-j),A=r/2+k-(r/2-_),O=o/2+j-(o/2-T),L=1,G=(r-A)/2,K=(o-O)/2,B=(r+M)/2,U=(o+R)/2,Y=B*L/2,Q=U*L/2;l=new xt({points:Array.from(Array(5*2)).map((le,ge)=>{const Me=-Ve+ge*v;return new b(G+(ge%2?Y:B)*Math.cos(Me),K+(ge%2?Q:U)*Math.sin(Me))}),isFilled:c});break}case"rhombus":{const y=Math.min(r*.38,o*.38);l=new xt({points:[new b(y,0),new b(r,0),new b(r-y,o),new b(0,o)],isFilled:c});break}case"rhombus-2":{const y=Math.min(r*.38,o*.38);l=new xt({points:[new b(0,0),new b(r-y,0),new b(r,o),new b(y,o)],isFilled:c});break}case"trapezoid":{const y=Math.min(r*.38,o*.38);l=new xt({points:[new b(y,0),new b(r-y,0),new b(r,o),new b(0,o)],isFilled:c});break}case"arrow-right":{const y=Math.min(r,o)*.38,v=o*.16;l=new xt({points:[new b(0,v),new b(r-y,v),new b(r-y,0),new b(r,o/2),new b(r-y,o),new b(r-y,o-v),new b(0,o-v)],isFilled:c});break}case"arrow-left":{const y=Math.min(r,o)*.38,v=o*.16;l=new xt({points:[new b(y,0),new b(y,v),new b(r,v),new b(r,o-v),new b(y,o-v),new b(y,o),new b(0,o/2)],isFilled:c});break}case"arrow-up":{const y=r*.16,v=Math.min(r,o)*.38;l=new xt({points:[new b(r/2,0),new b(r,v),new b(r-y,v),new b(r-y,o),new b(y,o),new b(y,v),new b(0,v)],isFilled:c});break}case"arrow-down":{const y=r*.16,v=Math.min(r,o)*.38;l=new xt({points:[new b(y,0),new b(r-y,0),new b(r-y,o-v),new b(r,o-v),new b(r/2,o),new b(0,o-v),new b(y,o-v)],isFilled:c});break}case"check-box":case"x-box":case"rectangle":{l=new es({width:r,height:o,isFilled:c});break}case"heart":{const v=rw(r,o).reduce((P,E)=>(P.push(...E.vertices),P),[]);l=new xt({points:v,isFilled:c});break}default:sn(t.props.geo)}const d=Ku(this.editor,t),u=Math.min(100,r/2),f=Math.min(Go[t.props.size]*t.props.scale*Gt.lineHeight+jr*2,o/2),p=Math.min(r,Math.max(d.w,Math.min(u,Math.max(1,r-8)))),S=Math.min(o,Math.max(d.h,Math.min(f,Math.max(1,r-8)))),g=Iv(t.props,a),w=g?g.map(y=>new jc({points:y})):[];return new Ur({children:[l,new es({x:t.props.align==="start"?0:t.props.align==="end"?r-p:(r-p)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?o-S:(o-S)/2,width:p,height:S,isFilled:!0,isLabel:!0}),...w]})}getHandleSnapGeometry(t){const r=this.getGeometry(t),o=r.children[0];switch(t.props.geo){case"arrow-down":case"arrow-left":case"arrow-right":case"arrow-up":case"check-box":case"diamond":case"hexagon":case"octagon":case"pentagon":case"rectangle":case"rhombus":case"rhombus-2":case"star":case"trapezoid":case"triangle":case"x-box":return{outline:o,points:[...o.getVertices(),r.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:o,points:[r.bounds.center]};default:sn(t.props.geo)}}component(t){const{id:r,type:o,props:s}=t,{fill:i,font:a,align:c,verticalAlign:l,size:d,text:u}=s,f=t.id===this.editor.getOnlySelectedShapeId(),p=_r(),g=this.editor.getEditingShapeId()!==null||t.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(Ys,{id:r,children:h.jsx(HC,{shape:t,shouldScale:!0})}),g&&h.jsx(Ki,{style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:h.jsx(ag,{id:r,type:o,font:a,fontSize:Go[d]*t.props.scale,lineHeight:Gt.lineHeight,padding:16*t.props.scale,fill:i,align:c,verticalAlign:l,text:u,isSelected:f,labelColor:p[s.labelColor].solid,wrap:!0})}),t.props.url&&h.jsx(Sc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{id:r,props:o}=t,{w:s,size:i}=o,a=o.h+o.growY,c=jt[i],l=this.editor.getShapeGeometry(t);switch(o.geo){case"ellipse":return o.dash==="draw"?h.jsx("path",{d:rY(r,s,a,c)}):h.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return h.jsx("path",{d:X$(s,a)});case"oval":return h.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return h.jsx("path",{d:Cv(s,a,r,i)});default:{const d=this.editor.getShapeGeometry(t),u=d instanceof Ur?d.children[0].vertices:d.vertices;let f;if(o.dash==="draw"){const S=Pv(r,u,0,c*2*t.props.scale,1);f=bv(S)}else f="M"+u[0]+"L"+u.slice(1)+"Z";const p=Iv(t.props,c);if(p)for(const[S,g]of p)f+=`M${S.x},${S.y}L${g.x},${g.y}`;return h.jsx("path",{d:f})}}}toSvg(t,r){const o={...t,props:{...t.props,w:t.props.w/t.props.scale,h:t.props.h/t.props.scale}},s=o.props;r.addExportDef(Qx(s.fill));let i;if(s.text){r.addExportDef(yc(s.font));const a=ss(r),c=new J(0,0,s.w,s.h+s.growY);i=h.jsx(ig,{fontSize:Go[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:a[s.labelColor].solid,bounds:c,padding:16})}return h.jsxs(h.Fragment,{children:[h.jsx(HC,{shouldScale:!1,shape:o}),i]})}getCanvasSvgDefs(){return[Jx()]}}m(Yh,"type","geo"),m(Yh,"props",J_),m(Yh,"migrations",ek);function Ku(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Gt,fontFamily:po[n.props.font],fontSize:Go[n.props.size]*n.props.scale,maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(t,{...Gt,fontFamily:po[n.props.font],fontSize:Go[n.props.size]*n.props.scale,minWidth:r.w,maxWidth:Math.max(0,Math.ceil(r.w+o[n.props.size]),Math.ceil(n.props.w-jr*2))});return{w:s.w+jr*2,h:s.h+jr*2}}function hY(){const[e,n]=x.useState(!1);return x.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");n(r&&o.matches);const s=()=>n(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),W(wt.forceSrgb)||!e?"srgb":"p3"}const KC=.35,WC=.82;class Xh extends Nr{constructor(){super(...arguments);m(this,"hideResizeHandles",t=>Wu(t));m(this,"hideRotateHandle",t=>Wu(t));m(this,"hideSelectionBoundsFg",t=>Wu(t));m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:c,y:l,z:d})=>({x:o*c,y:s*l,z:d}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=xi(t);if(Wu(t))return new Yx({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=GC(t,r,!0),i=nw({strokeWidth:s,showAsComplete:!0});return og(o,i),new xt({points:Xx(o,i),isFilled:!0})}component(t){const r=iy(this.editor,t),o=xi(t);return h.jsx(Ys,{id:t.id,children:h.jsx(Gu,{shape:t,forceSolid:r,strokeWidth:o,opacity:KC})})}backgroundComponent(t){const r=iy(this.editor,t),o=xi(t);return h.jsx(Ys,{id:t.id,children:h.jsx(Gu,{shape:t,forceSolid:r,strokeWidth:o,opacity:WC})})}indicator(t){const r=iy(this.editor,t),o=xi(t),{strokePoints:s,sw:i}=GC(t,o,r),a=vc(t.props.segments);let c;return s.length<2?c=pY(a[0],i):c=Wi(s,!1),h.jsx("path",{d:c})}toSvg(t){const r=xi(t),o=r<1.5,s=1/t.props.scale;return h.jsx("g",{transform:`scale(${s})`,children:h.jsx(Gu,{forceSolid:o,strokeWidth:r,shape:t,opacity:KC})})}toBackgroundSvg(t){const r=xi(t),o=r<1.5,s=1/t.props.scale;return h.jsx("g",{transform:`scale(${s})`,children:h.jsx(Gu,{forceSolid:o,strokeWidth:r,shape:t,opacity:WC})})}}m(Xh,"type","highlight"),m(Xh,"props",rk),m(Xh,"migrations",ok);function fY(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 pY(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 GC(e,n,t){var c;const r=vc(e.props.segments),o=e.props.isComplete||((c=Nt(e.props.segments))==null?void 0:c.type)==="straight";let s=n;!t&&!e.props.isPen&&r.length===1&&(s+=Wr(e.id)()*(n/6));const i=nw({strokeWidth:s,showAsComplete:o});return{strokePoints:So(r,i),sw:s}}function xi(e){return gc[e.props.size]*1.12*e.props.scale}function Wu(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function Gu({strokeWidth:e,forceSolid:n,shape:t,opacity:r}){var f;const o=_r(),s=vc(t.props.segments);let i=e;!n&&!t.props.isPen&&s.length===1&&(i+=Wr(t.id)()*(i/6));const a=nw({strokeWidth:i,showAsComplete:t.props.isComplete||((f=Nt(t.props.segments))==null?void 0:f.type)==="straight"}),c=So(s,a),l=c.length>1?Wi(c,!1):fY(t.props.segments[0].points[0]),d=hY(),u=o[t.props.color].highlight[d];return h.jsx("path",{d:l,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:u,strokeWidth:i,opacity:r})}function iy(e,n){return W("forceSolid",()=>{const t=xi(n),r=e.getZoomLevel();return t/r<1.5},[e])}function q$(){return h.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),h.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),h.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function Z$(e,n,t){const r=N(),[o,s]=x.useState(null),i=n?r.getAsset(n):null,c=r.getCulledShapes().has(e),l=i&&"w"in i.props?t/i.props.w:1,d=W("zoom level",()=>r.getZoomLevel()*l,[r,l]);return x.useEffect(()=>{if(c)return;let u=!1;const f=r.timers.setTimeout(async()=>{const p=await r.resolveAssetUrl(n,{screenScale:d});u||s(p)},500);return()=>{clearTimeout(f),u=!0}},[n,i==null?void 0:i.props.src,c,d,r]),{asset:i,url:o}}function Q$(){const[e,n]=x.useState(!1);return x.useEffect(()=>{const t=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{n(t.matches)};return r(),t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),e}async function gY(e){const t=await(await go(e)).blob();return ki.blobToDataUrl(t)}class qh extends Oc{constructor(){super(...arguments);m(this,"isAspectRatioLocked",()=>!0);m(this,"canCrop",()=>!0);m(this,"onDoubleClick",t=>{const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;!r||!(r.props.src&&this.isAnimated(t))||this.editor.updateShapes([{type:"image",id:t.id,props:{playing:!t.props.playing}}])});m(this,"onDoubleClickEdge",t=>{const r=t.props;if(!r||this.editor.getCroppingShapeId()!==t.id)return;const o=ot(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},s=1/(o.bottomRight.x-o.topLeft.x)*t.props.w,i=1/(o.bottomRight.y-o.topLeft.y)*t.props.h,a=new b(o.topLeft.x*s,o.topLeft.y*i).rot(t.rotation),c={id:t.id,type:t.type,x:t.x-a.x,y:t.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([c])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}isAnimated(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;return r?"mimeType"in r.props&&so.isAnimatedImageType(r==null?void 0:r.props.mimeType)||"isAnimated"in r.props&&r.props.isAnimated:!1}component(t){var g;const r=this.editor.getCroppingShapeId()===t.id,o=Q$(),[s,i]=x.useState(""),[a,c]=x.useState(""),l=t.id===this.editor.getOnlySelectedShapeId(),{asset:d,url:u}=Z$(t.id,t.props.assetId,t.props.w);if(x.useEffect(()=>{if(u){let w=!1;const y=oc();return y.onload=()=>{w||c(u)},y.src=u,()=>{w=!0}}},[u,t]),x.useEffect(()=>{if(u&&this.isAnimated(t)){let w=!1;const y=oc();return y.onload=()=>{if(w)return;const v=document.createElement("canvas");v.width=y.width,v.height=y.height;const P=v.getContext("2d");P&&(P.drawImage(y,0,0),i(v.toDataURL()),c(u))},y.crossOrigin="anonymous",y.src=u,()=>{w=!0}}},[o,u,t]),(d==null?void 0:d.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const f=l&&r&&this.editor.isIn("select.crop"),p=o&&(((g=d==null?void 0:d.props.mimeType)==null?void 0:g.includes("video"))||this.isAnimated(t)),S=VC(t);return d!=null&&d.props.src?a?h.jsxs(h.Fragment,{children:[f&&h.jsx("div",{style:S,children:h.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(t)?"anonymous":void 0,src:!t.props.playing||p?s:a,referrerPolicy:"strict-origin-when-cross-origin",style:{opacity:.1},draggable:!1})}),h.jsxs(Ki,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h},children:[h.jsxs("div",{className:"tl-image-container",style:S,children:[h.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(t)?"anonymous":void 0,src:!t.props.playing||p?s:a,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1}),this.isAnimated(t)&&!t.props.playing&&h.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),t.props.url&&h.jsx(Sc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):null:h.jsxs(Ki,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h,color:"var(--color-text-3)",backgroundColor:d?"transparent":"var(--color-low)",border:d?"none":"1px solid var(--color-low-border)"},children:[h.jsx("div",{className:"tl-image-container",style:S,children:d?null:h.jsx(q$,{})}),"url"in t.props&&t.props.url&&h.jsx(Sc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return this.editor.getCroppingShapeId()===t.id?null:h.jsx("rect",{width:z(t.props.w),height:z(t.props.h)})}async toSvg(t){if(!t.props.assetId||!this.editor.getAsset(t.props.assetId))return null;let o=await this.editor.resolveAssetUrl(t.props.assetId,{shouldResolveToOriginalImage:!0});if(!o)return null;(o.startsWith("blob:")||o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await gY(o)||"");const s=VC(t),i=t.props.crop;if(s.transform&&i){const{transform:a,width:c,height:l}=s,d=(i.bottomRight.x-i.topLeft.x)*c,u=(i.bottomRight.y-i.topLeft.y)*l,f=[new b(0,0),new b(d,0),new b(d,u),new b(0,u)],p=`cropClipPath_${t.id.replace(":","_")}`;return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsx("clipPath",{id:p,children:h.jsx("polygon",{points:f.map(S=>`${S.x},${S.y}`).join(" ")})})}),h.jsx("g",{clipPath:`url(#${p})`,children:h.jsx("image",{href:o,width:c,height:l,style:{transform:a}})})]})}else return h.jsx("image",{href:o,width:t.props.w,height:t.props.h})}}m(qh,"type","image"),m(qh,"props",sk),m(qh,"migrations",ik);function VC(e){const n=e.props.crop,t=n==null?void 0:n.topLeft;if(!t)return{width:e.props.w,height:e.props.h};const r=1/(n.bottomRight.x-n.topLeft.x)*e.props.w,o=1/(n.bottomRight.y-n.topLeft.y)*e.props.h,s=-t.x*r,i=-t.y*o;return{transform:`translate(${s}px, ${i}px)`,width:r,height:o}}function J$(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function eM(e,n,t){const r=n.vertices,o=J$(t);return So(r,o)}function mY(e,n,t){const r=J$(t);return Xx(og(eM(e,n,t),r),r)}function yY(e,n,t){const r=mY(e,n,t);return H0(r)}function SY(e,n,t){if(e.props.dash==="draw"){const r=eM(e,n,t);return Wi(r)}return n.getSvgPathData()}function tM(e,n,t){let r=`M ${Ee(n[0])}L`,o=`M ${Ee(n[0])}L`;const s=t/3,i=t*2,a=Wr(e);let c=n[0],l,d=n[0],u;const f=n.length;for(let p=0,S=f-1;p<S;p++){l=n[p+1],u=b.AddXY(n[p+1],a()*s,a()*s);const g=b.Sub(l,c),w=b.Len(g),y=b.Div(g,w).mul(Math.min(w/4,i)),v=b.Add(c,y),P=b.Add(l,y.neg()),E=b.Sub(u,d),I=b.Len(E),C=b.Div(E,I).mul(Math.min(I/4,i)),_=b.Add(d,C),k=b.Add(u,C.neg());p===S-1?(r+=`${Ee(v)}L ${Ee(l)}`,o+=`${Ee(_)}L ${Ee(u)}`):(r+=`${Ee(v)}L ${Ee(P)}Q ${Ee(l)}`,o+=`${Ee(_)}L ${Ee(k)}Q ${Ee(u)}`,c=l,d=u)}return[r,r+o]}const vY=new Yo;class Zh extends Nr{constructor(){super(...arguments);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r;return{props:{points:$d(t.props.points,(i,{id:a,index:c,x:l,y:d})=>({id:a,index:c,x:l*o,y:d*s}))}}});m(this,"onHandleDrag",(t,{handle:r})=>{if(r.type==="vertex")return{...t,props:{...t.props,points:{...t.props.points,[r.id]:{id:r.id,index:r.index,x:r.x,y:r.y}}}}})}getDefaultProps(){const[t,r]=Wl(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[t]:{id:t,index:t,x:0,y:0},[r]:{id:r,index:r,x:.1,y:.1}},scale:1}}getGeometry(t){return Cl(t)}getHandles(t){return vY.get(t.props,()=>{const r=Cl(t),o=Ev(t),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=Kl(o[i].index,o[i+1].index),l=r.segments[i].midPoint();s.push({id:a,type:"create",index:a,x:l.x,y:l.y,canSnap:!0})}return s.sort(rn)})}component(t){return h.jsx(Ys,{id:t.id,children:h.jsx(YC,{shape:t})})}indicator(t){const r=jt[t.props.size]*t.props.scale,o=Cl(t),{dash:s}=t.props;let i;if(t.props.spline==="line"){const a=o.points;if(s==="solid"||s==="dotted"||s==="dashed")i="M"+a[0]+"L"+a.slice(1);else{const[c]=tM(t.id,a,r);i=c}}else i=SY(t,o,r);return h.jsx("path",{d:i})}toSvg(t){return h.jsx(YC,{shouldScale:!0,shape:t})}getHandleSnapGeometry(t){const r=Ev(t);return{points:r,getSelfSnapPoints:o=>{const s=this.getHandles(t).filter(i=>i.type==="vertex").findIndex(i=>i.id===o.id);return r.filter((i,a)=>Math.abs(a-s)>1).map(b.From)},getSelfSnapOutline:o=>{const s=this.getHandles(t).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),i=Cl(t).segments.filter((a,c)=>c!==s-1&&c!==s);return i.length?new Ur({children:i}):null}}}}m(Zh,"type","line"),m(Zh,"props",ak),m(Zh,"migrations",ck);function Ev(e){return Object.values(e.props.points).sort(rn)}function Cl(e){const n=Ev(e).map(b.From);switch(e.props.spline){case"cubic":return new FW({points:n});case"line":return new jc({points:n})}}function YC({shape:e,shouldScale:n=!1}){const t=_r(),r=Cl(e),{dash:o,color:s,size:i}=e.props,a=1/e.props.scale,c=n?a:1,l=jt[i]*e.props.scale;if(e.props.spline==="line"){if(o==="solid"){const d=r.points,u="M"+d[0]+"L"+d.slice(1);return h.jsx("path",{d:u,stroke:t[s].solid,strokeWidth:l,fill:"none",transform:`scale(${c})`})}if(o==="dashed"||o==="dotted")return h.jsx("g",{stroke:t[s].solid,strokeWidth:l,transform:`scale(${c})`,children:r.segments.map((d,u)=>{const{strokeDasharray:f,strokeDashoffset:p}=to(d.length,l,{style:o,start:u>0?"outset":"none",end:u<r.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:f,strokeDashoffset:p,d:d.getSvgPathData(!0),fill:"none"},u)})});if(o==="draw"){const d=r.points,[u,f]=tM(e.id,d,l);return h.jsx("path",{d:f,stroke:t[s].solid,strokeWidth:l,fill:"none",transform:`scale(${c})`})}}if(e.props.spline==="cubic"){const d=r.getSvgPathData();if(o==="solid")return h.jsx("path",{strokeWidth:l,stroke:t[s].solid,fill:"none",d,transform:`scale(${c})`});if(o==="dashed"||o==="dotted")return h.jsx("g",{stroke:t[s].solid,strokeWidth:l,transform:`scale(${c})`,children:r.segments.map((u,f)=>{const{strokeDasharray:p,strokeDashoffset:S}=to(u.length,l,{style:o,start:f>0?"outset":"none",end:f<r.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:p,strokeDashoffset:S,d:u.getSvgPathData(),fill:"none"},f)})});if(o==="draw")return h.jsx("path",{d:yY(e,r,l),strokeWidth:1,stroke:t[s].solid,fill:t[s].solid,transform:`scale(${c})`})}}const nM=x.createContext(null);function xY({assetUrls:e,children:n}){return x.useEffect(()=>{for(const t of Object.values(e.icons)){const r=oc();r.src=t,r.decode()}for(const t of Object.values(e.embedIcons)){const r=oc();r.src=t,r.decode()}},[e]),h.jsx(nM.Provider,{value:e,children:n})}function ow(){const e=x.useContext(nM);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const _v={"action.convert-to-bookmark":"Convert to Bookmark","action.convert-to-embed":"Convert to Embed","action.open-embed-link":"Open link","action.align-bottom":"Align bottom","action.align-center-horizontal":"Align horizontally","action.align-center-vertical":"Align vertically","action.align-center-horizontal.short":"Align H","action.align-center-vertical.short":"Align V","action.align-left":"Align left","action.align-right":"Align right","action.align-top":"Align top","action.back-to-content":"Back to content","action.bring-forward":"Bring forward","action.bring-to-front":"Bring to front","action.copy-as-json.short":"JSON","action.copy-as-json":"Copy as JSON","action.copy-as-png.short":"PNG","action.copy-as-png":"Copy as PNG","action.copy-as-svg.short":"SVG","action.copy-as-svg":"Copy as SVG","action.copy":"Copy","action.cut":"Cut","action.delete":"Delete","action.unlock-all":"Unlock all","action.distribute-horizontal":"Distribute horizontally","action.distribute-vertical":"Distribute vertically","action.distribute-horizontal.short":"Distribute H","action.distribute-vertical.short":"Distribute V","action.duplicate":"Duplicate","action.edit-link":"Edit link","action.exit-pen-mode":"Exit pen mode","action.export-as-json.short":"JSON","action.export-as-json":"Export as JSON","action.export-as-png.short":"PNG","action.export-as-png":"Export as PNG","action.export-as-svg.short":"SVG","action.export-as-svg":"Export as SVG","action.export-all-as-json.short":"JSON","action.export-all-as-json":"Export as JSON","action.export-all-as-png.short":"PNG","action.export-all-as-png":"Export as PNG","action.export-all-as-svg.short":"SVG","action.export-all-as-svg":"Export as SVG","action.fit-frame-to-content":"Fit to content","action.flip-horizontal":"Flip horizontally","action.flip-vertical":"Flip vertically","action.flip-horizontal.short":"Flip H","action.flip-vertical.short":"Flip V","action.fork-project":"Fork this project","action.fork-project-on-tldraw":"Fork project on tldraw","action.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-dynamic-size-mode.menu":"Dynamic size","action.toggle-dynamic-size-mode":"Toggle dynamic size","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.flatten-to-image":"Flatten","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","color-scheme.dark":"Dark","color-scheme.light":"Light","color-scheme.system":"System","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","fill-style.fill":"Fill","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","menu.title":"Menu","menu.color-scheme":"Color scheme","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","context-menu.edit":"Edit","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy editor link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy viewer link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to access this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","share-menu.creating-project":"Creating the new project…","share-menu.copied":"Copied link","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},wY=new Set(["ar","fa","he","ur","ku"]),ma={locale:"en",label:"English",messages:_v,dir:"ltr"};async function bY(e,n){if(!(await go(n.translations.en)).ok)return console.warn("No main translations found."),ma;if(e==="en")return ma;const r=Vl.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),ma;const s=await(await go(n.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),ma;const i=[];for(const a in ma.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:wY.has(r.locale)?"rtl":"ltr",messages:{...ma.messages,...s}}}const rM=x.createContext(null);function oM(){const e=x.useContext(rM);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const PY=sr(function({overrides:n,children:t}){const o=N().user.getLocale(),s=ow(),[i,a]=x.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{..._v,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:_v});return x.useEffect(()=>{let c=!1;async function l(){const d=await bY(o,s);d&&!c&&(n&&n[o]?a({...d,messages:{...d.messages,...n[o]}}):a(d))}return l(),()=>{c=!0}},[s,o,n]),h.jsx(rM.Provider,{value:i,children:t})});function $e(){const e=oM();return x.useCallback(function(t){return e.messages[t]??t},[e])}class Qh extends Nr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"hideResizeHandles",()=>!0);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"onBeforeCreate",t=>XC(this.editor,t));m(this,"onBeforeUpdate",(t,r)=>{if(!(t.props.text===r.props.text&&t.props.font===r.props.font&&t.props.size===r.props.size))return XC(this.editor,r)});m(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(t){const{labelHeight:r,labelWidth:o}=sM(this.editor,t),{scale:s}=t.props,i=r*s,a=o*s,c=Be*s,l=Vu(t);return new Ur({children:[new es({width:c,height:l,isFilled:!0}),new es({x:t.props.align==="start"?0:t.props.align==="end"?c-a:(c-a)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?l-i:(l-i)/2,width:a,height:i,isFilled:!0,isLabel:!0})]})}getHandles(t){const{scale:r}=t.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const s=this.editor.getZoomLevel();if(s*r<.25)return[];const i=Vu(t),a=Be*r,c=qG/s*r;return s*r<.5?[{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+c}]:[{id:"top",index:"a1",type:"clone",x:a/2,y:-c},{id:"right",index:"a2",type:"clone",x:a+c,y:i/2},{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+c},{id:"left",index:"a4",type:"clone",x:-c,y:i/2}]}component(t){const{id:r,type:o,props:{scale:s,color:i,font:a,size:c,align:l,text:d,verticalAlign:u,fontSizeAdjustment:f}}=t,p=EY(r),S=_r(),g=Be*s,w=Vu(t),y=W("shape rotation",()=>{var E;return((E=this.editor.getShapePageTransform(r))==null?void 0:E.rotation())??0},[this.editor]),v=W("zoom",()=>this.editor.getZoomLevel()<.35/s,[s,this.editor]),P=t.id===this.editor.getOnlySelectedShapeId();return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:r,className:"tl-note__container",style:{width:g,height:w,backgroundColor:S[i].note.fill,borderBottom:v?`${3*s}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:v?"none":_Y(t.id,y,s)},children:h.jsx(ag,{id:r,type:o,font:a,fontSize:(f||Go[c])*s,lineHeight:Gt.lineHeight,align:l,verticalAlign:u,text:d,isNote:!0,isSelected:P,labelColor:S[i].note.text,wrap:!0,padding:16*s,onKeyDown:p})}),"url"in t.props&&t.props.url&&h.jsx(Sc,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{scale:r}=t.props;return h.jsx("rect",{rx:r,width:z(Be*r),height:z(Vu(t))})}toSvg(t,r){r.addExportDef(yc(t.props.font)),t.props.text&&r.addExportDef(yc(t.props.font));const o=ss({isDarkMode:r.isDarkMode}),s=kY(t);return h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:5,y:5,rx:1,width:Be-10,height:s.h,fill:"rgba(0,0,0,.1)"}),h.jsx("rect",{rx:1,width:Be,height:s.h,fill:o[t.props.color].note.fill}),h.jsx(ig,{fontSize:t.props.fontSizeAdjustment||Go[t.props.size],font:t.props.font,align:t.props.align,verticalAlign:t.props.verticalAlign,text:t.props.text,labelColor:o[t.props.color].note.text,bounds:s,stroke:!1})]})}}m(Qh,"type","note"),m(Qh,"props",lk),m(Qh,"migrations",dk);function XC(e,n){const{labelHeight:t,fontSizeAdjustment:r}=sM(e,n),o=Math.max(0,t-Be);if(o!==n.props.growY||r!==n.props.fontSizeAdjustment)return{...n,props:{...n.props,growY:o,fontSizeAdjustment:r}}}function CY(e,n){const{text:t}=n.props;if(!t)return{labelHeight:Go[n.props.size]*Gt.lineHeight+jr*2,labelWidth:100,fontSizeAdjustment:0};const r=Go[n.props.size];let o=0,s=0,i=Be,a=Be;const c=1;do{o=Math.min(r,r-s);const l=e.textMeasure.measureText(t,{...Gt,fontFamily:po[n.props.font],fontSize:o,maxWidth:Be-jr*2-c,disableOverflowWrapBreaking:!0});if(i=l.h+jr*2,a=l.w+jr*2,o<=14){const d=e.textMeasure.measureText(t,{...Gt,fontFamily:po[n.props.font],fontSize:o,maxWidth:Be-jr*2-c});i=d.h+jr*2,a=d.w+jr*2;break}if(l.scrollWidth.toFixed(0)===l.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const IY=new Yo;function sM(e,n){return IY.get(n,()=>CY(e,n))}function EY(e){const n=N(),t=oM();return x.useCallback(r=>{const o=n.getShape(e);if(!o)return;const s=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(s||i){r.preventDefault();const a=n.getShapePageTransform(e),c=a.rotation(),l=!!(t.dir==="rtl"||$$(o.props.text)),d=(Be+n.options.adjacentShapeMargin+(i&&!r.shiftKey?o.props.growY:0))*o.props.scale,u=new b(s?r.shiftKey!=l?-1:1:0,i?r.shiftKey?-1:1:0).mul(d).add(sg.clone().mul(o.props.scale)).rot(c).add(a.point()),f=F$(n,o,u,c);f&&(n.mark("editing adjacent shape"),hp(n,f,!0))}},[e,n,t.dir])}function Vu(e){return(Be+e.props.growY)*e.props.scale}function _Y(e,n,t){const r=Wr(e),o=Math.abs(r())+.5,s=Math.cos(n),i=5*t,a=4*t,c=6*t,l=7*t;return`0px ${i-o}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
157
|
-
0px ${(a+o*l)*Math.max(0,s)}px ${c+o*l}px -${a+o*c}px rgba(15, 23, 31, ${(.3+o*.1).toFixed(2)}),
|
|
158
|
-
0px ${48*t}px ${10*t}px -${10*t}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+s)/2)).toFixed(2)})`}function kY(e){return new J(0,0,Be,Be+e.props.growY)}function TY(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),i=new b(0,0);t<0&&(i.x=-(n.width*s)),r<0&&(i.y=-(n.height*s));const{x:a,y:c}=b.Add(o,i.rot(e.rotation));return{x:a,y:c,props:{scale:s*e.props.scale}}}const $Y=new Yo;class Jh extends Nr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0);m(this,"onResize",(t,r)=>{const{newPoint:o,initialBounds:s,initialShape:i,scaleX:a,handle:c}=r;if(r.mode==="scale_shape"||c!=="right"&&c!=="left")return{id:t.id,type:t.type,...TY(t,r)};{const l=Math.max(1,Math.abs(s.width*a)),{x:d,y:u}=a<0?b.Sub(o,b.FromAngle(t.rotation).mul(l)):o;return{id:t.id,type:t.type,x:d,y:u,props:{w:l/i.props.scale,autoSize:!1}}}});m(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()}}])});m(this,"onBeforeUpdate",(t,r)=>{if(!r.props.autoSize)return;const o=t.props.size!==r.props.size||t.props.textAlign!==r.props.textAlign||t.props.font!==r.props.font||t.props.scale!==1&&r.props.scale===1,s=t.props.text!==r.props.text;if(!o&&!s)return;const i=this.getMinDimensions(t),a=qC(this.editor,r.props),c=i.width*t.props.scale,l=i.height*t.props.scale,d=a.width*r.props.scale,u=a.height*r.props.scale;let f;switch(r.props.textAlign){case"middle":{f=new b((d-c)/2,s?0:(u-l)/2);break}case"end":{f=new b(d-c,s?0:(u-l)/2);break}default:{if(s)break;f=new b(0,(u-l)/2);break}}if(f){f.rot(r.rotation);const{x:p,y:S}=r;return{...r,x:p-f.x,y:S-f.y,props:{...r.props,w:d}}}else return{...r,props:{...r.props,w:d}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(t){return $Y.get(t.props,r=>qC(this.editor,r))}getGeometry(t){const{scale:r}=t.props,{width:o,height:s}=this.getMinDimensions(t);return new es({width:o*r,height:s*r,isFilled:!0,isLabel:!0})}component(t){const{id:r,props:{font:o,size:s,text:i,color:a,scale:c,textAlign:l}}=t,{width:d,height:u}=this.getMinDimensions(t),f=t.id===this.editor.getOnlySelectedShapeId(),p=_r(),S=MY(r);return h.jsx(ag,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:gc[s],lineHeight:Gt.lineHeight,align:l,verticalAlign:"middle",text:i,labelColor:p[a].solid,isSelected:f,textWidth:d,textHeight:u,style:{transform:`scale(${c})`,transformOrigin:"top left"},wrap:!0,onKeyDown:S})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=N();return t.props.autoSize&&o.getEditingShapeId()===t.id?null:h.jsx("rect",{width:z(r.width),height:z(r.height)})}toSvg(t,r){r.addExportDef(yc(t.props.font)),t.props.text&&r.addExportDef(yc(t.props.font));const o=this.editor.getShapeGeometry(t).bounds,s=o.width/(t.props.scale??1),i=o.height/(t.props.scale??1),a=ss(r);return h.jsx(ig,{fontSize:gc[t.props.size],font:t.props.font,align:t.props.textAlign,verticalAlign:"middle",text:t.props.text,labelColor:a[t.props.color].solid,bounds:new J(0,0,s,i),padding:0})}}m(Jh,"type","text"),m(Jh,"props",uk),m(Jh,"migrations",hk);function qC(e,n){const{font:t,text:r,autoSize:o,size:s,w:i}=n,a=o?16:Math.max(16,i),c=gc[s],l=o?null:Math.floor(Math.max(a,i)),d=e.textMeasure.measureText(r,{...Gt,fontFamily:po[t],fontSize:c,maxWidth:l});return o&&(d.w+=1),{width:Math.max(a,d.w),height:Math.max(c,d.h)}}function MY(e){const n=N();return x.useCallback(t=>{if(n.getEditingShapeId()===e)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&n.complete();break}case"Tab":{_e(t),t.shiftKey?mc.unindent(t.currentTarget):mc.indent(t.currentTarget);break}}},[n,e])}class ef extends Oc{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(t){const{editor:r}=this,o=r.getShapeGeometry(t).bounds.w*r.getZoomLevel()>=110,{asset:s,url:i}=Z$(t.id,t.props.assetId,t.props.w),{time:a,playing:c}=t.props,l=rg(t.id),d=Q$(),u=x.useRef(null),f=x.useCallback(v=>{const P=v.currentTarget;P&&r.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:P.currentTime}}])},[t.id,r]),p=x.useCallback(v=>{const P=v.currentTarget;P&&r.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:P.currentTime}}])},[t.id,r]),S=x.useCallback(v=>{const P=v.currentTarget;P&&l&&r.updateShapes([{type:"video",id:t.id,props:{time:P.currentTime}}])},[l,t.id,r]),[g,w]=x.useState(!1),y=x.useCallback(v=>{const P=v.currentTarget;P&&(a!==P.currentTime&&(P.currentTime=a),c||P.pause(),w(!0))},[c,a]);return x.useEffect(()=>{const v=u.current;v&&(g&&!l&&a!==v.currentTime&&(v.currentTime=a),l&&document.activeElement!==v&&v.focus())},[l,g,a]),x.useEffect(()=>{if(d){const v=u.current;if(!v)return;v.pause(),v.currentTime=0}},[u,d]),h.jsxs(h.Fragment,{children:[h.jsx(Ki,{id:t.id,style:{color:"var(--color-text-3)",backgroundColor:s?"transparent":"var(--color-low)",border:s?"none":"1px solid var(--color-low-border)"},children:h.jsx("div",{className:"tl-counter-scaled",children:h.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?i?h.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:f,onPause:p,onTimeUpdate:S,onLoadedData:y,hidden:!g,children:h.jsx("source",{src:i})}):null:h.jsx(q$,{})})})}),"url"in t.props&&t.props.url&&h.jsx(Sc,{url:t.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(t){return h.jsx("rect",{width:z(t.props.w),height:z(t.props.h)})}toSvg(t){return h.jsx("image",{href:AY(t.id),width:t.props.w,height:t.props.h})}}m(ef,"type","video"),m(ef,"props",fk),m(ef,"migrations",pk);function AY(e){const n=e.split(":")[1],t=document.querySelector(`.tl-video-shape-${n}`);if(t){const r=document.createElement("canvas");return r.width=t.videoWidth,r.height=t.videoHeight,r.getContext("2d").drawImage(t,0,0),r.toDataURL("image/png")}else throw new Error("Video with not found when attempting serialization.")}const iM=[Jh,Kh,Wh,Yh,Qh,Zh,Vh,Hh,Xh,Gh,qh,ef];function jY(e){return[e.sideEffects.registerAfterChangeHandler("instance_page_state",(n,t)=>{if(n.croppingShapeId!==t.croppingShapeId){const r=e.isIn("select.crop");!n.croppingShapeId&&t.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):n.croppingShapeId&&!t.croppingShapeId&&r&&e.setCurrentTool("select.idle")}n.editingShapeId!==t.editingShapeId&&(!n.editingShapeId&&t.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):n.editingShapeId&&!t.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))})]}class aM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"scribbleId","id");m(this,"markId","");m(this,"excludedShapeIds",new Set);m(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()});m(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}update(){const{editor:t,excludedShapeIds:r}=this,o=t.getErasingShapeIds(),s=t.getZoomLevel(),i=t.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:c}}=t;this.pushPointToScribble();const l=new Set(o),d=this.editor.options.hitTestMargin/s;for(const u of i){if(t.isShapeOfType(u,"group"))continue;const f=t.getShapeMask(u.id);if(f&&!Jn(a,f))continue;const p=t.getShapeGeometry(u),S=t.getShapePageTransform(u);if(!p||!S)continue;const g=S.clone().invert(),w=g.applyToPoint(c),y=g.applyToPoint(a),{bounds:v}=p;v.minX-d>Math.max(w.x,y.x)||v.minY-d>Math.max(w.y,y.y)||v.maxX+d<Math.min(w.x,y.x)||v.maxY+d<Math.min(w.y,y.y)||p.hitTestLineSegment(w,y,d)&&l.add(t.getOutermostSelectableShape(u).id)}this.editor.setErasingShapes([...l].filter(u=>!r.has(u)))}complete(){const{editor:t}=this;t.deleteShapes(t.getCurrentPageState().erasingShapeIds),t.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:t}=this;t.setErasingShapes([]),t.bailToMark(this.markId),this.parent.transition("idle",this.info)}}m(aM,"id","erasing");var Fy;let OY=(Fy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Fy,"id","idle"),Fy);var zy;let DY=(zy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{const t=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:o}}=this.editor,s=new Set,i=s.size;for(let a=r.length,c=a-1;c>=0;c--){const l=r[c];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,o,{hitInside:!1,margin:this.editor.options.hitTestMargin/t})){const d=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(d,"frame")&&s.size>i)break;s.add(d.id)}}this.editor.setErasingShapes([...s])});m(this,"onLongPress",t=>{this.startErasing(t)});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startErasing(t)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}startErasing(t){this.parent.transition("erasing",t)}complete(){const t=this.editor.getErasingShapeIds();t.length&&(this.editor.mark("erase end"),this.editor.deleteShapes(t)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},m(zy,"id","pointing"),zy);class tf extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(tf,"id","eraser"),m(tf,"initial","idle"),m(tf,"children",()=>[OY,DY,aM]);class cM extends se{constructor(){super(...arguments);m(this,"initialCamera",new b);m(this,"onEnter",()=>{this.initialCamera=b.From(this.editor.getCamera()),this.update()});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.parent.transition("idle")});m(this,"onComplete",()=>{this.complete()})}update(){const{initialCamera:t,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=b.Sub(o,s).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(t.clone().add(i))}complete(){const{editor:t}=this,{pointerVelocity:r}=t.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r}),this.parent.transition("idle")}}m(cM,"id","dragging");var Ny;let RY=(Ny=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});m(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(Ny,"id","idle"),Ny);var By;let LY=(By=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})});m(this,"onLongPress",()=>{this.startDragging()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startDragging()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.complete()})}startDragging(){this.parent.transition("dragging")}complete(){this.parent.transition("idle")}},m(By,"id","pointing"),By);class nf extends se{constructor(){super(...arguments);m(this,"onDoubleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{animation:{duration:220,easing:At.easeOutQuint}})}});m(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:At.easeOutQuint}})}});m(this,"onQuadrupleClick",t=>{if(t.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:o}}=this.editor;r===1?this.editor.zoomToFit({animation:{duration:400,easing:At.easeOutQuint}}):this.editor.resetZoom(o,{animation:{duration:320,easing:At.easeOutQuint}})}})}}m(nf,"id","hand"),m(nf,"initial","idle"),m(nf,"children",()=>[RY,LY,cM]);var Uy;let FY=(Uy=class extends se{constructor(){super(...arguments);m(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},m(Uy,"id","idle"),Uy);class lM extends se{constructor(){super(...arguments);m(this,"scribbleId","id");m(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()});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.pushPointToScribble()});m(this,"onPointerUp",()=>{this.complete()});m(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}m(lM,"id","lasering");class rf extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(rf,"id","laser"),m(rf,"initial","idle"),m(rf,"children",()=>[FY,lM]);class dM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"initialSelectedShapeIds",[]);m(this,"excludedShapeIds",new Set);m(this,"isWrapMode",!1);m(this,"initialStartShape",null);m(this,"onEnter",t=>{const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",t);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=t,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.hitTestShapes()});m(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});m(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});m(this,"onPointerMove",()=>{this.hitTestShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",t=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",t)});m(this,"onKeyDown",t=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()});m(this,"onKeyUp",()=>{this.hitTestShapes()});m(this,"onInterrupt",()=>{this.editor.updateInstanceState({brush:null})})}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:t,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:c}}=t,l=new Set(a?this.initialSelectedShapeIds:[]),d=o?!c:c,u=J.FromPoints([s,i]),{corners:f}=u;let p,S,g,w,y,v;const P=t.getCurrentPageShapes(),E=t.getCurrentPageId();e:for(let _=0,k=P.length;_<k;_++){if(g=P[_],r.has(g.id)||l.has(g.id)||(w=t.getShapePageBounds(g),!w))continue e;if(u.contains(w)){this.handleHit(g,i,E,l,f);continue e}if(d||t.isShapeOfType(g,"frame"))continue e;if(u.collides(w)){if(y=t.getShapePageTransform(g),!y)continue e;v=y.clone().invert().applyToPoints(f);const j=t.getShapeGeometry(g);t:for(let T=0;T<4;T++)if(p=v[T],S=v[(T+1)%4],j.hitTestLineSegment(p,S,0)){this.handleHit(g,i,E,l,f);break t}}}t.getInstanceState().isCoarsePointer;const I=t.getInstanceState().brush;(!I||!u.equals(I))&&t.updateInstanceState({brush:{...u.toJson()}});const C=t.getSelectedShapeIds();(C.length!==l.size||C.some(_=>!l.has(_)))&&t.setSelectedShapes(Array.from(l))}handleHit(t,r,o,s,i){if(t.parentId===o){s.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),c=this.editor.getShapeMask(a.id);c&&!o$(c,i)&&!Jn(r,c)||s.add(a.id)}}m(dM,"id","brushing");const xc={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 uM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t,this.updateCursor()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startResizing()});m(this,"onLongPress",()=>{this.startResizing()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const t=this.editor.getSelectedShapes(),r=xc[this.info.handle];this.editor.setCursor({type:r,rotation:t.length===1?this.editor.getSelectionRotation():0})}startResizing(){this.editor.getInstanceState().isReadonly||this.parent.transition("resizing",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}m(uM,"id","pointing_resize_handle");const pr=8;class sw extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"snapshot",{});m(this,"onEnter",t=>{this.info=t,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=xc[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}updateShapes(){const{shape:t,cursorHandleOffset:r}=this.snapshot;if(!t||!this.editor.getShapeUtil("image"))return;const s=t.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),c=i.clone().sub(a).rot(-t.rotation),l=s.crop??this.getDefaultCrop(),d=ot(l),u=new b(t.x,t.y),f=new b(0,0),p=1/(l.bottomRight.x-l.topLeft.x)*s.w,S=1/(l.bottomRight.y-l.topLeft.y)*s.h;let g=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(S<pr)break;g=!0,d.topLeft.y=d.topLeft.y+c.y/S,S*(d.bottomRight.y-d.topLeft.y)<pr?(d.topLeft.y=d.bottomRight.y-pr/S,f.y=(d.topLeft.y-l.topLeft.y)*S):d.topLeft.y<=0?(d.topLeft.y=0,f.y=(d.topLeft.y-l.topLeft.y)*S):f.y=c.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(S<pr)break;g=!0,d.bottomRight.y=Math.min(1,d.bottomRight.y+c.y/S),S*(d.bottomRight.y-d.topLeft.y)<pr&&(d.bottomRight.y=d.topLeft.y+pr/S);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<pr)break;g=!0,d.topLeft.x=d.topLeft.x+c.x/p,p*(d.bottomRight.x-d.topLeft.x)<pr?(d.topLeft.x=d.bottomRight.x-pr/p,f.x=(d.topLeft.x-l.topLeft.x)*p):d.topLeft.x<=0?(d.topLeft.x=0,f.x=(d.topLeft.x-l.topLeft.x)*p):f.x=c.x;break}case"right":case"top_right":case"bottom_right":{if(p<pr)break;g=!0,d.bottomRight.x=Math.min(1,d.bottomRight.x+c.x/p),p*(d.bottomRight.x-d.topLeft.x)<pr&&(d.bottomRight.x=d.topLeft.x+pr/p);break}}if(!g)return;u.add(f.rot(t.rotation));const w={id:t.id,type:t.type,x:u.x,y:u.y,props:{crop:d,w:(d.bottomRight.x-d.topLeft.x)*p,h:(d.bottomRight.y-d.topLeft.y)*S}};this.editor.updateShapes([w]),this.updateCursor()}complete(){this.updateShapes(),We(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const t=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(s.getHandlePoint(this.info.handle),s.point,t),a=b.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}m(sw,"id","cropping");function iw(e,n=!1){const t=e.getZoomLevel(),{inputs:{currentPagePoint:r}}=e;return e.getShapeAtPoint(r,{hitInside:!1,hitLabels:n,margin:e.options.hitTestMargin/t,renderingOnly:!0})??e.getSelectedShapeAtPoint(r)}function hM(e,n,t){if(!n)throw Error("Needs to translate a cropped shape!");const{crop:r}=n.props;if(!r)return;const o=e.inputs.shiftKey?Math.abs(t.x)<Math.abs(t.y)?"x":"y":null;o==="x"?t.x=0:o==="y"&&(t.y=0),t.rot(-n.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*n.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*n.props.h,a=r.bottomRight.y-r.topLeft.y,c=r.bottomRight.x-r.topLeft.x,l=ot(r);return l.topLeft.x=Math.min(1-c,Math.max(0,l.topLeft.x-t.x/s)),l.topLeft.y=Math.min(1-a,Math.max(0,l.topLeft.y-t.y/i)),l.bottomRight.x=l.topLeft.x+c,l.bottomRight.y=l.topLeft.y+a,{id:n.id,type:n.type,props:{crop:l}}}var Hy;let zY=(Hy=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const t=this.editor.getOnlySelectedShape();t&&this.editor.setCroppingShape(t.id)});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});m(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});m(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=iw(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...t,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(t);break}case"shape":{if(t.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",t);return}else(r=this.editor.getShapeUtil(t.shape))!=null&&r.canCrop(t.shape)?(this.editor.setCroppingShape(t.shape.id),this.editor.setSelectedShapes([t.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",t)):(this.cancel(),this.editor.root.handleEvent(t));break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...t,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...t,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}});m(this,"onDoubleClick",t=>{var i;if(this.editor.inputs.shiftKey||t.phase!=="up")return;const r=this.editor.getCroppingShapeId();if(!r)return;const o=this.editor.getShape(r);if(!o)return;const s=this.editor.getShapeUtil(o);if(s){if(t.target==="selection"){(i=s.onDoubleClickEdge)==null||i.call(s,o);return}this.cancel(),this.editor.root.handleEvent(t)}});m(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});m(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});m(this,"onKeyUp",t=>{switch(t.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new b(0,0);if(r.has("ArrowLeft")&&(s.x+=1),r.has("ArrowRight")&&(s.x-=1),r.has("ArrowUp")&&(s.y+=1),r.has("ArrowDown")&&(s.y-=1),s.equals(new b(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=hM(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},m(Hy,"id","idle"),Hy);class fM extends se{constructor(){super(...arguments);m(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",t)});m(this,"onPointerUp",t=>{this.editor.setCurrentTool("select.crop.idle",t)})}}m(fM,"id","pointing_crop");class aw extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=xc[this.info.handle];this.editor.setCursor({type:o,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});m(this,"onLongPress",()=>{this.startCropping()});m(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}m(aw,"id","pointing_crop_handle");class pM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","translating crop");m(this,"snapshot",{});m(this,"onEnter",t=>{this.info=t,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onKeyDown",t=>{switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}});m(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=hM(this.editor,t,s);i&&this.editor.updateShapes([i])}}m(pM,"id","translating_crop");class of extends se{constructor(){super(...arguments);m(this,"markId","");m(this,"onEnter",()=>{this.didCancel=!1,this.markId=this.editor.history.mark()});m(this,"didCancel",!1);m(this,"onExit",()=>{this.didCancel?this.editor.bailToMark(this.markId):this.editor.history.squashToMark(this.markId)});m(this,"onCancel",()=>{this.didCancel=!0})}}m(of,"id","crop"),m(of,"initial","idle"),m(of,"children",()=>[zY,pM,fM,aw,sw]);class gM extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"initialHandle",{});m(this,"initialAdjacentHandle",null);m(this,"initialPagePoint",{});m(this,"markId","");m(this,"initialPageTransform");m(this,"initialPageRotation");m(this,"info",{});m(this,"isPrecise",!1);m(this,"isPreciseId",null);m(this,"pointingId",null);m(this,"onEnter",t=>{const{shape:r,isCreating:o,handle:s}=t;if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.shapeId=r.id,this.markId=o?`creating:${r.id}`:"dragging handle",o||this.editor.mark(this.markId),this.initialHandle=ot(s),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[s.index]:{id:s.index,index:s.index,x:s.x,y:s.y}}}});const l=this.editor.getShapeHandles(r).find(d=>d.index===s.index);this.initialHandle=ot(l)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:o?"cross":"grabbing",rotation:0});const i=this.editor.getShapeHandles(r).sort(rn),a=i.findIndex(c=>c.id===t.handle.id);this.initialAdjacentHandle=null;for(let c=a+1;c<i.length;c++){const l=i[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==t.handle.id){this.initialAdjacentHandle=l;break}}if(!this.initialAdjacentHandle)for(let c=i.length-1;c>=0;c--){const l=i[c];if(l.type==="vertex"&&l.id!=="middle"&&l.id!==t.handle.id){this.initialAdjacentHandle=l;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=kn(this.editor,r)[t.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)});m(this,"exactTimeout",-1);m(this,"onPointerMove",()=>{this.update()});m(this,"onKeyDown",()=>{this.update()});m(this,"onKeyUp",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.update(),this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),We(this.editor,[this.shapeId]);const{onInteractionEnd:t}=this.info;if(this.editor.getInstanceState().isToolLocked&&t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:t}=this.info;if(t){this.editor.setCurrentTool(t,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var _;const{editor:t,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,c=this.editor.getHintingShapeIds(),l=this.editor.user.getIsSnapMode(),{snaps:d,inputs:{currentPagePoint:u,shiftKey:f,ctrlKey:p,altKey:S,pointerVelocity:g}}=t,w=this.info.shape,y=t.getShape(r);if(!y)return;const v=t.getShapeUtil(y);let P=u.clone().sub(o).rot(-i).add(s);if(f&&a&&s.id!=="middle"){const k=b.Angle(a,P),T=Df(k,24)-k;P=b.RotWith(P,a,T)}t.snaps.clearIndicators();let E={...s,x:P.x,y:P.y};if(s.canSnap&&(l?!p:p)){if(!t.getShapePageTransform(y.id))throw Error("Expected a page transform");const j=d.handles.snapHandle({currentShapeId:r,handle:E});j&&(j.nudge.rot(-t.getShapeParentTransform(y).rotation()),P.add(j.nudge),E={...s,x:P.x,y:P.y})}const I=(_=v.onHandleDrag)==null?void 0:_.call(v,y,{handle:E,isPrecise:this.isPrecise||S,initial:w}),C={id:y.id,type:y.type,...I};if(s.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const k=kn(t,y)[s.id];k?c[0]!==k.toId&&(t.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=g.len()<.5||S,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):c.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}I&&t.updateShapes([C])}}m(gM,"id","dragging_handle");function mM(e){return e.isLabel?[e]:e instanceof Ur?e.children.filter(n=>n.isLabel):[]}class yM extends se{constructor(){super(...arguments);m(this,"hitShapeForPointerUp",null);m(this,"onEnter",()=>{const t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Uo(this.editor),this.editor.select(t)});m(this,"onExit",()=>{var s;const{editingShapeId:t}=this.editor.getCurrentPageState();if(!t)return;this.editor.setEditingShape(null),Uo.cancel();const r=this.editor.getShape(t),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r)});m(this,"onPointerMove",t=>{if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",t),this.hitShapeForPointerUp=null;return}switch(t.target){case"shape":case"canvas":{Uo(this.editor);return}}});m(this,"onPointerDown",t=>{switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=iw(this.editor,!0);if(r){this.onPointerDown({...t,shape:r,target:"shape"});return}break}case"shape":{const{shape:r}=t,o=this.editor.getEditingShape();if(!o)throw Error("Expected an editing shape!");const s=this.editor.getShapeUtil(r).getGeometry(r),i=mM(s),a=i.length===1?i[0]:void 0,c=this.editor.isShapeOfType(o,"text")&&o.props.text.trim()==="";if(a&&!c){const l=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(l,0)&&a.hitTestPoint(l)){if(r.id===o.id)return;this.hitShapeForPointerUp=r,this.editor.mark("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===o.id)this.editor.isShapeOfType(r,"frame")&&this.editor.setEditingShape(null);else{this.parent.transition("pointing_shape",t);return}return}break}}this.parent.transition("idle",t),this.editor.root.handleEvent(t)});m(this,"onPointerUp",t=>{const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const o=this.editor.getShapeUtil(r);if(this.editor.getInstanceState().isReadonly&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",t);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),Uo(this.editor)});m(this,"onComplete",t=>{this.parent.transition("idle",t)});m(this,"onCancel",t=>{this.parent.transition("idle",t)})}}m(yM,"id","editing_shape");function ZC(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function gp(e){const n=e.getSelectedShapeIds(),{shiftKey:t,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin:e.options.hitTestMargin/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(s){const i=e.getOutermostSelectableShape(s);if(t&&!r)e.cancelDoubleClick(),n.includes(i.id)?(e.mark("deselecting shape"),e.deselect(i)):(e.mark("shift selecting shape"),e.setSelectedShapes([...n,i.id]));else{let a;i===s||i.id===e.getFocusedGroupId()||n.includes(i.id)?a=s:a=i,a&&!n.includes(a.id)&&(e.mark("selecting shape"),e.select(a.id))}}else{if(t)return;{n.length>0&&(e.mark("selecting none"),e.selectNone());const i=e.getFocusedGroupId();if(In(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const NY=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Ky;let BY=(Ky=class extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Uo(this.editor),this.editor.setCursor({type:"default",rotation:0})});m(this,"onExit",()=>{Uo.cancel()});m(this,"onPointerMove",()=>{Uo(this.editor)});m(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&ZC(this.editor);if(t.ctrlKey&&!r){if(t.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(t.shape)){this.parent.transition("pointing_shape",t);return}this.parent.transition("brushing",t);return}switch(t.target){case"canvas":{const o=iw(this.editor);if(o&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&QC(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{const{shape:o}=t;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",t);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",t);break}this.parent.transition("pointing_shape",t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",t):this.parent.transition("pointing_handle",t);break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",t);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("crop.pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",t)}}break}}});m(this,"onDoubleClick",t=>{var r,o,s,i;if(!(this.editor.inputs.shiftKey||t.phase!=="up"))switch(t.target){case"canvas":{const a=this.editor.getHoveredShape(),c=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(c){if(this.editor.isShapeOfType(c,"group")){gp(this.editor);return}else{const d=this.editor.getShape(c.parentId);if(d&&this.editor.isShapeOfType(d,"group")&&!(l&&d.id===l)){gp(this.editor);return}}this.onDoubleClick({...t,shape:c,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(t);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const c=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(t.handle==="right"||t.handle==="left"||t.handle==="top"||t.handle==="bottom"){const l=(r=c.onDoubleClickEdge)==null?void 0:r.call(c,a);if(l){this.editor.mark("double click edge"),this.editor.updateShapes([l]),We(this.editor,[a.id]);return}}if(c.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",t);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}break}case"shape":{const{shape:a}=t,c=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(c.onDoubleClick){const l=(o=c.onDoubleClick)==null?void 0:o.call(c,a);if(l){this.editor.updateShapes([l]);return}else if(c.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((s=t.shape)==null?void 0:s.id),this.parent.transition("crop",t);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,t,!0):this.handleDoubleClickOnCanvas(t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:c}=t,l=this.editor.getShapeUtil(a),d=(i=l.onDoubleClickHandle)==null?void 0:i.call(l,a,c);d?this.editor.updateShapes([d]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}}});m(this,"onRightClick",t=>{switch(t.target){case"canvas":{const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...t,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&QC(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=t,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));r.includes(s.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});m(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});m(this,"onKeyDown",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(wt.editOnType.get()&&!NY.includes(t.key)&&!t.altKey&&!t.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...t,target:"shape",shape:r},!0);return}}});m(this,"onKeyRepeat",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});m(this,"onKeyUp",t=>{switch(t.code){case"Enter":{const r=this.editor.getSelectedShapes();if(r.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(r.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const o=this.editor.getOnlySelectedShape();if(o&&this.shouldStartEditingShape(o)){this.startEditingShape(o,{...t,target:"shape",shape:o},!0);return}ZC(this.editor)&&this.parent.transition("crop",t);break}}});m(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}shouldStartEditingShape(t=this.editor.getOnlySelectedShape()){return!t||this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||!this.canInteractWithShapeInReadOnly(t)?!1:this.editor.getShapeUtil(t).canEdit(t)}startEditingShape(t,r,o){this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||(this.editor.mark("editing shape"),hp(this.editor,t,o),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(t){if(!t)return!1;const r=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(t,"arrow")){const o=this.editor.getShapeGeometry(t).children[1];if(o&&Jn(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(t){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=Fe(),{x:o,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:r,type:"text",x:o,y:s,props:{text:"",autoSize:!0}}]);const i=this.editor.getShape(r);if(!i)return;const a=this.editor.getShapeUtil(i);this.editor.getInstanceState().isReadonly&&!a.canEditInReadOnly(i)||(this.editor.setEditingShape(r),this.editor.select(r),this.parent.transition("editing_shape",t))}nudgeSelectedShapes(t=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new b(0,0);if(r.has("ArrowLeft")&&(s.x-=1),r.has("ArrowRight")&&(s.x+=1),r.has("ArrowUp")&&(s.y-=1),r.has("ArrowDown")&&(s.y+=1),s.equals(new b(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*KY:i:o?UY:HY,c=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(c,s.mul(a)),We(this.editor,c)}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},m(Ky,"id","idle"),Ky);const UY=10,HY=1,KY=5;function QC(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?Jn(n,t.corners.map(o=>b.RotWith(o,t.point,r))):t.containsPoint(n)}class SM extends se{constructor(){super(...arguments);m(this,"shapeId","");m(this,"markId","");m(this,"wasAlreadySelected",!1);m(this,"didDrag",!1);m(this,"info",{});m(this,"onEnter",t=>{const{shape:r}=t;this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.shapeId=r.id,this.didDrag=!1,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const s=this.editor.getShapeGeometry(r).children[1];if(!s)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=b.Sub(s.center,a),this.markId="label-drag start",this.editor.mark(this.markId),this.editor.setSelectedShapes([this.shapeId])});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});m(this,"_labelDragOffset",new b(0,0));m(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;if(!t)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=ao(this.editor,r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),c=i.nearestPoint(b.Add(a,this._labelDragOffset));let l;if(o.isStraight){const d=b.Dist(o.start.point,o.end.point);l=1-b.Dist(o.end.point,c)/d}else{const{_center:d,measure:u,angleEnd:f,angleStart:p}=s.children[0];l=mS(u,p,f,d.angle(c))}isNaN(l)&&(l=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:l}})});m(this,"onPointerUp",()=>{const t=this.editor.getShape(this.shapeId);t&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(t.id),this.editor.setCurrentTool("select.editing_shape")))});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}m(SM,"id","pointing_arrow_label");class vM extends se{constructor(){super(...arguments);m(this,"onEnter",()=>{const{inputs:t}=this.editor;t.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",t)});m(this,"onPointerUp",()=>{gp(this.editor),this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}m(vM,"id","pointing_canvas");class xM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const o=kn(this.editor,r)[t.handle.id];o&&this.editor.setHintingShapes([o.toId])}this.editor.setCursor({type:"grabbing",rotation:0})});m(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})});m(this,"onPointerUp",()=>{const{shape:t,handle:r}=this.info;if(this.editor.isShapeOfType(t,"note")){const{editor:o}=this,s=JC(o,t,r,!1);if(s){hp(o,s,!0);return}}this.parent.transition("idle",this.info)});m(this,"onPointerMove",()=>{const{editor:t}=this;t.inputs.isDragging&&this.startDraggingHandle()});m(this,"onLongPress",()=>{this.startDraggingHandle()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startDraggingHandle(){const{editor:t}=this;if(t.getInstanceState().isReadonly)return;const{shape:r,handle:o}=this.info;if(t.isShapeOfType(r,"note")){const s=JC(t,r,o,!0);if(s){const i=t.getPointInParentSpace(s,t.inputs.originPagePoint).sub(b.Rot(sg.clone().mul(r.props.scale),s.rotation));t.updateShape({...s,x:i.x,y:i.y}),t.setHoveredShape(s.id).select(s.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:t.getShape(s),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{hp(t,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}m(xM,"id","pointing_handle");function JC(e,n,t,r){const o=e.getShapePageTransform(n.id),s=o.point(),i=o.rotation(),c=R$(s,i,n.props.growY,0,n.props.scale)[t.index];if(c)return F$(e,n,c,i,r)}class wM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startRotating()});m(this,"onLongPress",()=>{this.startRotating()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:xc[this.info.handle],rotation:this.editor.getSelectionRotation()})}startRotating(){this.editor.getInstanceState().isReadonly||this.parent.transition("rotating",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}m(wM,"id","pointing_rotate_handle");class bM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t});m(this,"onPointerUp",t=>{gp(this.editor),this.parent.transition("idle",t)});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});m(this,"onLongPress",t=>{this.startTranslating(t)});m(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}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",t)}cancel(){this.parent.transition("idle")}}m(bM,"id","pointing_selection");class PM extends se{constructor(){super(...arguments);m(this,"hitShape",{});m(this,"hitShapeForPointerUp",{});m(this,"isDoubleClick",!1);m(this,"didSelectOnEnter",!1);m(this,"onEnter",t=>{const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:c}}=this.editor;this.hitShape=t.shape,this.isDoubleClick=!1;const l=this.editor.getOutermostSelectableShape(t.shape),d=this.editor.findShapeAncestor(l,u=>r.includes(u.id));if(this.editor.getShapeUtil(t.shape).onClick||l.id===s||r.includes(l.id)||d||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=l;return}this.didSelectOnEnter=!0,a&&!c?(this.editor.cancelDoubleClick(),r.includes(l.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,l.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([l.id]))});m(this,"onPointerUp",t=>{var d;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,c=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/s,hitInside:!0,renderingOnly:!0})??this.hitShape,l=c?this.editor.getOutermostSelectableShape(c):this.hitShapeForPointerUp;if(l){const u=this.editor.getShapeUtil(l);if(u.onClick){const f=(d=u.onClick)==null?void 0:d.call(u,l);if(f){this.editor.mark("shape on click"),this.editor.updateShapes([f]),this.parent.transition("idle",t);return}}if(l.id===o){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",t);return}}if(!this.didSelectOnEnter){const u=this.editor.getOutermostSelectableShape(c,f=>!r.includes(f.id));if(r.includes(u.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(l);else if(r.includes(l.id)){if(r.length===1){const f=this.editor.getShapeUtil(l).getGeometry(l),p=mM(f),S=p.length===1?p[0]:void 0;if(S){const g=this.editor.getPointInShapeSpace(l,i);if(S.bounds.containsPoint(g,0)&&S.hitTestPoint(g)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(l.id);const w=this.editor.getShapeUtil(l);this.editor.getInstanceState().isReadonly&&!w.canEditInReadOnly(l)||(this.editor.setEditingShape(l.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:l.id}))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(l.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(l);else if(a){const f=this.editor.getShapeAncestors(u);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(p=>!f.find(S=>S.id===p)),u.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([u.id])}this.parent.transition("idle",t)});m(this,"onDoubleClick",()=>{this.isDoubleClick=!0});m(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});m(this,"onLongPress",t=>{this.startTranslating(t)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||(this.editor.focus(),this.parent.transition("translating",t))}cancel(){this.parent.transition("idle")}}m(PM,"id","pointing_shape");class CM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"didHoldCommand",!1);m(this,"creationCursorOffset",{x:0,y:0});m(this,"snapshot",{});m(this,"onEnter",t=>{const{isCreating:r=!1,creationCursorOffset:o={x:0,y:0}}=t;this.info=t,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),r?(this.markId=`creating:${this.editor.getOnlySelectedShape().id}`,this.editor.setCursor({type:"cross",rotation:0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});m(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onKeyDown",()=>{this.updateShapes()});m(this,"onKeyUp",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()});m(this,"_createSnapshot",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=b.Sub(o,i),c=new Map,l=[];t.forEach(u=>{const f=this.editor.getShape(u);if(f){if(f.type==="frame"&&l.push({id:u,children:Se(this.editor.getSortedChildIdsForParent(f).map(p=>this.editor.getShape(p)))}),c.set(f.id,this._createShapeSnapshot(f)),this.editor.isShapeOfType(f,"frame")&&t.length===1)return;this.editor.visitDescendants(f.id,p=>{const S=this.editor.getShape(p);if(S&&(c.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const d=![...c.values()].some(u=>!vk(u.pageRotation,r)||u.isAspectRatioLocked);return{shapeSnapshots:c,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:d,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:l}});m(this,"_createShapeSnapshot",t=>{const r=this.editor.getShapePageTransform(t),o=this.editor.getShapeUtil(t);return{shape:t,bounds:this.editor.getShapeGeometry(t).bounds,pageTransform:r,pageRotation:oe.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(t)}})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var t,r;if(We(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(t=this.info).onCreate)==null||r.call(t,this.editor.getOnlySelectedShape());return}if(this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd){this.editor.setCurrentTool(this.info.onInteractionEnd,{});return}this.parent.transition("idle")}handleResizeStart(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:o})=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onResizeStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:t}=this.snapshot,r=[];t.forEach(({shape:o})=>{var c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onResizeEnd)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:c,selectionRotation:l,canShapesDeform:d}=this.snapshot;let u=r||!d;if(s.size===1){const k=[...s.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(u=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:f}=this.editor.inputs,p=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),S=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!f){const{gridSize:k}=this.editor.getDocumentSettings();p.snapToGrid(k)}const g=this.info.handle,w=eI(g,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!f:f)&&l%Ve===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:b.Sub(p,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:eI(g,l),isAspectRatioLocked:u,isResizingFromCenter:t});p.add(k)}const v=b.RotWith(t?i.center:i.getHandlePoint(w),i.point,l),P=b.Sub(p,v).rot(-l),E=b.Sub(S,v).rot(-l),I=b.DivV(P,E);Number.isFinite(I.x)||(I.x=1),Number.isFinite(I.y)||(I.y=1);const C=g==="top"||g==="bottom",_=g==="left"||g==="right";u?_?I.y=Math.abs(I.x):C?I.x=Math.abs(I.y):Math.abs(I.x)>Math.abs(I.y)?I.y=Math.abs(I.x)*(I.y<0?-1:1):I.x=Math.abs(I.y)*(I.x<0?-1:1):(C&&(I.x=1),_&&(I.y=1)),this.info.isCreating||this.updateCursor({dragHandle:g,isFlippedX:I.x<0,isFlippedY:I.y<0,rotation:l});for(const k of s.keys()){const j=s.get(k);this.editor.resizeShape(k,I,{initialShape:j.shape,initialBounds:j.bounds,initialPageTransform:j.pageTransform,dragHandle:g,mode:c.length===1&&k===c[0]?"resize_bounds":"scale_shape",scaleOrigin:v,isAspectRatioLocked:u,scaleAxisRotation:l,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:j}of o){if(!j.length)continue;const T=s.get(k).shape,M=this.editor.getShape(k);if(!(T&&M))continue;const R=M.x-T.x,A=M.y-T.y,O=new b(R,A).rot(-T.rotation);if(O.x!==0||O.y!==0)for(const L of j)this.editor.updateShape({id:L.id,type:L.type,x:L.x-O.x,y:L.y-O.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of o)if(k.length)for(const j of k)this.editor.updateShape({id:j.id,type:j.type,x:j.x,y:j.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)}}m(CM,"id","resizing");const ay=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function eI(e,n){n=n%De;const t=Math.round(n/(ke/4)),r=ay.indexOf(e);return ay[(r+t)%ay.length]}const tI=Math.PI/180;class IM extends se{constructor(){super(...arguments);m(this,"snapshot",{});m(this,"info",{});m(this,"markId","");m(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=a$({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Th({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:xc[this.info.handle],rotation:o+this.snapshot.initialSelectionRotation})});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});m(this,"onPointerMove",()=>{this.update()});m(this,"onKeyDown",()=>{this.update()});m(this,"onKeyUp",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"update",()=>{const t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});Th({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:xc[this.info.handle],rotation:t+this.snapshot.initialSelectionRotation})});m(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});m(this,"complete",()=>{Th({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),We(this.editor,this.snapshot.shapeSnapshots.map(t=>t.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)})}_getRotationFromPointerPosition({snapToNearestDegree:t}){const r=this.editor.getSelectionRotation(),o=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:s,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:c}=this.snapshot;if(!o)return c;const d=o.center.clone().rotWith(o.point,r).angle(i)-a;let u=c+d;if(s)u=Df(u,24);else if(t&&(u=Math.round(u/tI)*tI,this.editor.getInstanceState().isCoarsePointer)){const f=Df(u,4),p=mh(u,f);Math.abs(p)<l7(5)&&(u=f)}return u-c}}m(IM,"id","rotating");class EM extends se{constructor(){super(...arguments);m(this,"hits",new Set);m(this,"size",0);m(this,"scribbleId","id");m(this,"initialSelectedShapeIds",new Set);m(this,"newlySelectedShapeIds",new Set);m(this,"onEnter",()=>{this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const t=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=t.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});m(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)})}updateScribbleSelection(t){const{editor:r}=this,o=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:c}}=this.editor,{newlySelectedShapeIds:l,initialSelectedShapeIds:d}=this;t&&this.pushPointToScribble();const u=o;let f,p,S,g;const w=0;for(let P=0,E=u.length;P<E;P++){if(f=u[P],r.isShapeOfType(f,"group")||l.has(f.id)||r.isShapeOrAncestorLocked(f)||(p=r.getShapeGeometry(f),r.isShapeOfType(f,"frame")&&p.bounds.containsPoint(r.getPointInShapeSpace(f,i))))continue;const I=r.getShapePageTransform(f);if(!p||!I)continue;const C=I.clone().invert();S=C.applyToPoint(a),g=C.applyToPoint(c);const{bounds:_}=p;if(!(_.minX-w>Math.max(S.x,g.x)||_.minY-w>Math.max(S.y,g.y)||_.maxX+w<Math.min(S.x,g.x)||_.maxY+w<Math.min(S.y,g.y))&&p.hitTestLineSegment(S,g,w)){const k=this.editor.getOutermostSelectableShape(f),j=this.editor.getShapeMask(k.id);if(j&&zx(a,c,j)!==null&&!Jn(c,j))continue;l.add(k.id)}}const y=r.getSelectedShapeIds(),v=new Set(s?[...l,...d]:[...l]);(y.length!==v.size||y.some(P=>!v.has(P)))&&this.editor.setSelectedShapes(Array.from(v))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}m(EM,"id","scribble_brushing");const WY=20,GY=100;class VY{constructor(n){m(this,"prevDroppingShapeId",null);m(this,"droppingNodeTimer",null);m(this,"first",!0);m(this,"dispose",()=>{this.clear()});this.editor=n,n.disposables.add(this.dispose)}updateDroppingNode(n,t){var r;this.first&&(this.editor.setHintingShapes(n.map(o=>this.editor.findShapeAncestor(o,s=>s.type!=="group")).filter(o=>o)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,n))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(n,WY,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(n,GY,t))}setDragTimer(n,t,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,n,r)}),this.droppingNodeTimer=null},t)}handleDrag(n,t,r){var c,l,d,u,f;t=Se(t.map(p=>this.editor.getShape(p.id)));const o=((c=this.editor.getDroppingOverShape(n,t))==null?void 0:c.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(t);return}const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);i&&((d=(l=this.editor.getShapeUtil(i)).onDragShapesOut)==null||d.call(l,i,t)),a&&((f=(u=this.editor.getShapeUtil(a)).onDragShapesOver)==null||f.call(u,a,t)),this.hintParents(t),r==null||r(),this.prevDroppingShapeId=o}hintParents(n){const t=new Map;for(const o of n){const s=this.editor.findShapeAncestor(o,i=>i.type!=="group");s&&(t.has(s.id)||t.set(s.id,[]),t.get(s.id).push(o.id))}const r=[];for(const[o,s]of t){const i=this.editor.getShape(o);i&&j$(this.editor,i).length<s.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(n){var r,o;const{prevDroppingShapeId:t}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,n),t){const s=this.editor.getShape(t);if(!s)return;(o=(r=this.editor.getShapeUtil(s)).onDropShapesOver)==null||o.call(r,s,n)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class _M extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"selectionSnapshot",{});m(this,"snapshot",{});m(this,"markId","");m(this,"isCloning",!1);m(this,"isCreating",!1);m(this,"onCreate",()=>{});m(this,"dragAndDropManager",new VY(this.editor));m(this,"onEnter",t=>{var s;const{isCreating:r=!1,onCreate:o=()=>{}}=t;if(!((s=this.editor.getSelectedShapeIds())!=null&&s.length)){this.parent.transition("idle");return}if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.isCreating=r,this.onCreate=o,r?this.markId=`creating:${this.editor.getOnlySelectedShape().id}`:(this.markId="translating",this.editor.mark(this.markId)),this.isCloning=!1,this.info=t,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=nI(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()});m(this,"onTick",({elapsed:t})=>{const{editor:r}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),r.edgeScrollManager.updateEdgeScrolling(t)});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});m(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"updateParentTransforms",()=>{const{editor:t,snapshot:{shapeSnapshots:r}}=this;r.forEach(o=>{const s=t.getShape(o.shape.id);if(!s)return null;const i=Pn(s.parentId)?null:oe.Inverse(t.getShapePageTransform(s.parentId));o.parentTransform=i})})}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=nI(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId="translating",this.editor.mark(this.markId),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){var t;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),We(this.editor,this.snapshot.movingShapes.map(r=>r.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(t=this.onCreate)==null||t.call(this,this.editor.getOnlySelectedShape()):this.parent.transition("idle")}cancel(){this.reset(),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.parent.transition("idle",this.info)}handleStart(){const{movingShapes:t}=this.snapshot,r=[];t.forEach(o=>{var a;const s=this.editor.getShapeUtil(o),i=(a=s.onTranslateStart)==null?void 0:a.call(s,o);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:t}=this.snapshot;if(this.isCloning&&t.length>0){const o=b.Average(t.map(i=>this.editor.getShapePageTransform(i.id).point())),s=b.Sub(o,this.selectionSnapshot.averagePagePoint);b.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:t.map(i=>i.id),offset:{x:s.x,y:s.y}}})}const r=[];t.forEach(o=>{var c;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(c=i.onTranslateEnd)==null?void 0:c.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:t}=this;this.dragAndDropManager.updateDroppingNode(t.movingShapes,this.updateParentTransforms),YY({editor:this.editor,snapshot:t});const{movingShapes:r}=t,o=[];r.forEach(s=>{var l;const i=this.editor.getShape(s.id),a=this.editor.getShapeUtil(s),c=(l=a.onTranslate)==null?void 0:l.call(a,s,i);c&&o.push(c)}),o.length>0&&this.editor.updateShapes(o)}}m(_M,"id","translating");function nI(e){var u;const n=[],t=[],r=e.getSelectedShapeIds(),o=Se(r.map(f=>{const p=e.getShape(f);if(!p)return null;n.push(p);const S=e.getShapePageTransform(f),g=S.point(),w=S.rotation();t.push(g);const y=Xo.isId(p.parentId)?null:oe.Inverse(e.getShapePageTransform(p.parentId));return{shape:p,pagePoint:g,pageRotation:w,parentTransform:y}})),s=e.getOnlySelectedShape();let i=[];if(s)i=e.snaps.shapeBounds.getSnapPoints(s.id);else{const f=e.getSelectionPageBounds();f&&(i=f.cornersAndCenter.map((p,S)=>({id:"selection:"+S,x:p.x,y:p.y})))}let a,c;const{originPagePoint:l}=e.inputs,d=o.filter(f=>e.isShapeOfType(f.shape,"note")&&e.isPointInShape(f.shape,l));if(d.length!==0)if(d.length===1)c=d[0];else{const f=e.getCurrentPageShapesSorted();c=(u=d.map(p=>({snapshot:p,index:f.findIndex(S=>S.id===p.shape.id)})).sort((p,S)=>S.index-p.index)[0])==null?void 0:u.snapshot}return c&&(a=L$(e,c.pageRotation,c.shape.props.scale,c.shape.props.growY??0)),{averagePagePoint:b.Average(t),movingShapes:n,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:c}}function YY({editor:e,snapshot:n}){const{inputs:t}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:c}=n,l=e.getInstanceState().isGridMode,d=e.getDocumentSettings().gridSize,u=b.Sub(t.currentPagePoint,t.originPagePoint),f=e.inputs.shiftKey?Math.abs(u.x)<Math.abs(u.y)?"x":"y":null;if(f==="x"?u.x=0:f==="y"&&(u.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:w}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:u,initialSelectionPageBounds:s,lockedAxis:f,initialSelectionSnapPoints:i});u.add(w)}else if(r&&o){const{scale:w}=r.shape.props,y=r.pagePoint.clone().add(u).add(sg.clone().mul(w).rot(r.pageRotation));let v=D$/e.getZoomLevel(),P=new b(0,0);for(const E of o){const I=b.Sub(y,E),C=I.len();C<v&&(v=C,P=I)}u.sub(P)}const S=b.Add(c,u);l&&!t.ctrlKey&&S.snapToGrid(d);const g=b.Sub(S,c);e.updateShapes(Se(a.map(({shape:w,pagePoint:y,parentTransform:v})=>{const P=b.Add(y,g),E=v?oe.applyToPoint(v,P):P;return{id:w.id,type:w.type,x:E.x,y:E.y}})))}class sf extends se{constructor(){super(...arguments);m(this,"reactor");m(this,"cleanUpDuplicateProps",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);t.length===o.size&&t.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})});m(this,"onEnter",()=>{this.reactor=ta("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(t){typeof process<"u",console.error(t)}})});m(this,"onExit",()=>{var t;(t=this.reactor)==null||t.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}m(sf,"id","select"),m(sf,"initial","idle"),m(sf,"children",()=>[of,sw,BY,vM,PM,_M,dM,EM,aw,bM,uM,yM,CM,IM,wM,SM,xM,gM]);class kM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t});m(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}m(kM,"id","idle");class TM extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t});m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});m(this,"onCancel",()=>{this.cancel()})}complete(){const{currentScreenPoint:t}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(t,{animation:{duration:220}}):this.editor.zoomIn(t,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}m(TM,"id","pointing");class $M extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"zoomBrush",new J);m(this,"onEnter",t=>{this.info=t,this.update()});m(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:t,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(J.FromPoints([t,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:t}=this,r=8/this.editor.getZoomLevel();if(t.width<r&&t.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{animation:{duration:220}}):this.editor.zoomIn(o,{animation:{duration:220}})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(t,{targetZoom:o,animation:{duration:220}})}this.parent.transition("idle",this.info)}}m($M,"id","zoom_brushing");class af extends se{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onKeyDown",()=>{this.updateCursor()});m(this,"onKeyUp",t=>{this.updateCursor(),t.code==="KeyZ"&&this.complete()});m(this,"onInterrupt",()=>{this.complete()})}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}m(af,"id","zoom"),m(af,"initial","idle"),m(af,"children",()=>[kM,$M,TM]);const XY=[tf,nf,rf,af,sf];function Z(){return Z=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},Z.apply(null,arguments)}function ie(e,n,{checkForDefaultPrevented:t=!0}={}){return function(o){if(e==null||e(o),t===!1||!o.defaultPrevented)return n==null?void 0:n(o)}}function qY(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function lg(...e){return n=>e.forEach(t=>qY(t,n))}function Xe(...e){return x.useCallback(lg(...e),e)}function Co(e,n=[]){let t=[];function r(s,i){const a=x.createContext(i),c=t.length;t=[...t,i];function l(u){const{scope:f,children:p,...S}=u,g=(f==null?void 0:f[e][c])||a,w=x.useMemo(()=>S,Object.values(S));return x.createElement(g.Provider,{value:w},p)}function d(u,f){const p=(f==null?void 0:f[e][c])||a,S=x.useContext(p);if(S)return S;if(i!==void 0)return i;throw new Error(`\`${u}\` must be used within \`${s}\``)}return l.displayName=s+"Provider",[l,d]}const o=()=>{const s=t.map(i=>x.createContext(i));return function(a){const c=(a==null?void 0:a[e])||s;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:c}}),[a,c])}};return o.scopeName=e,[r,ZY(o,...n)]}function ZY(...e){const n=e[0];if(e.length===1)return n;const t=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:c,scopeName:l})=>{const u=c(s)[`__scope${l}`];return{...a,...u}},{});return x.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return t.scopeName=n.scopeName,t}const Gi=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{},QY=$D.useId||(()=>{});let JY=0;function Vo(e){const[n,t]=x.useState(QY());return Gi(()=>{e||t(r=>r??String(JY++))},[e]),e||(n?`radix-${n}`:"")}function ln(e){const n=x.useRef(e);return x.useEffect(()=>{n.current=e}),x.useMemo(()=>(...t)=>{var r;return(r=n.current)===null||r===void 0?void 0:r.call(n,...t)},[])}function ii({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=eX({defaultProp:n,onChange:t}),s=e!==void 0,i=s?e:r,a=ln(t),c=x.useCallback(l=>{if(s){const u=typeof l=="function"?l(e):l;u!==e&&a(u)}else o(l)},[s,e,o,a]);return[i,c]}function eX({defaultProp:e,onChange:n}){const t=x.useState(e),[r]=t,o=x.useRef(r),s=ln(n);return x.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),t}const Vi=x.forwardRef((e,n)=>{const{children:t,...r}=e,o=x.Children.toArray(t),s=o.find(nX);if(s){const i=s.props.children,a=o.map(c=>c===s?x.Children.count(i)>1?x.Children.only(null):x.isValidElement(i)?i.props.children:null:c);return x.createElement(kv,Z({},r,{ref:n}),x.isValidElement(i)?x.cloneElement(i,void 0,a):null)}return x.createElement(kv,Z({},r,{ref:n}),t)});Vi.displayName="Slot";const kv=x.forwardRef((e,n)=>{const{children:t,...r}=e;return x.isValidElement(t)?x.cloneElement(t,{...rX(r,t.props),ref:n?lg(n,t.ref):t.ref}):x.Children.count(t)>1?x.Children.only(null):null});kv.displayName="SlotClone";const tX=({children:e})=>x.createElement(x.Fragment,null,e);function nX(e){return x.isValidElement(e)&&e.type===tX}function rX(e,n){const t={...n};for(const r in n){const o=e[r],s=n[r];/^on[A-Z]/.test(r)?o&&s?t[r]=(...a)=>{s(...a),o(...a)}:o&&(t[r]=o):r==="style"?t[r]={...o,...s}:r==="className"&&(t[r]=[o,s].filter(Boolean).join(" "))}return{...e,...t}}const oX=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],He=oX.reduce((e,n)=>{const t=x.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?Vi:n;return x.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),x.createElement(a,Z({},i,{ref:o}))});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function cw(e,n){e&&oa.flushSync(()=>e.dispatchEvent(n))}function sX(e,n=globalThis==null?void 0:globalThis.document){const t=ln(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r),()=>n.removeEventListener("keydown",r)},[t,n])}const Tv="dismissableLayer.update",iX="dismissableLayer.pointerDownOutside",aX="dismissableLayer.focusOutside";let rI;const MM=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),dg=x.forwardRef((e,n)=>{var t;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:a,onDismiss:c,...l}=e,d=x.useContext(MM),[u,f]=x.useState(null),p=(t=u==null?void 0:u.ownerDocument)!==null&&t!==void 0?t:globalThis==null?void 0:globalThis.document,[,S]=x.useState({}),g=Xe(n,k=>f(k)),w=Array.from(d.layers),[y]=[...d.layersWithOutsidePointerEventsDisabled].slice(-1),v=w.indexOf(y),P=u?w.indexOf(u):-1,E=d.layersWithOutsidePointerEventsDisabled.size>0,I=P>=v,C=lX(k=>{const j=k.target,T=[...d.branches].some(M=>M.contains(j));!I||T||(s==null||s(k),a==null||a(k),k.defaultPrevented||c==null||c())},p),_=dX(k=>{const j=k.target;[...d.branches].some(M=>M.contains(j))||(i==null||i(k),a==null||a(k),k.defaultPrevented||c==null||c())},p);return sX(k=>{P===d.layers.size-1&&(o==null||o(k),!k.defaultPrevented&&c&&(k.preventDefault(),c()))},p),x.useEffect(()=>{if(u)return r&&(d.layersWithOutsidePointerEventsDisabled.size===0&&(rI=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),d.layersWithOutsidePointerEventsDisabled.add(u)),d.layers.add(u),oI(),()=>{r&&d.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=rI)}},[u,p,r,d]),x.useEffect(()=>()=>{u&&(d.layers.delete(u),d.layersWithOutsidePointerEventsDisabled.delete(u),oI())},[u,d]),x.useEffect(()=>{const k=()=>S({});return document.addEventListener(Tv,k),()=>document.removeEventListener(Tv,k)},[]),x.createElement(He.div,Z({},l,{ref:g,style:{pointerEvents:E?I?"auto":"none":void 0,...e.style},onFocusCapture:ie(e.onFocusCapture,_.onFocusCapture),onBlurCapture:ie(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:ie(e.onPointerDownCapture,C.onPointerDownCapture)}))}),cX=x.forwardRef((e,n)=>{const t=x.useContext(MM),r=x.useRef(null),o=Xe(n,r);return x.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),x.createElement(He.div,Z({},e,{ref:o}))});function lX(e,n=globalThis==null?void 0:globalThis.document){const t=ln(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let d=function(){AM(iX,t,l,{discrete:!0})};var c=d;const l={originalEvent:a};a.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=d,n.addEventListener("click",o.current,{once:!0})):d()}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 dX(e,n=globalThis==null?void 0:globalThis.document){const t=ln(e),r=x.useRef(!1);return x.useEffect(()=>{const o=s=>{s.target&&!r.current&&AM(aX,t,{originalEvent:s},{discrete:!1})};return n.addEventListener("focusin",o),()=>n.removeEventListener("focusin",o)},[n,t]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function oI(){const e=new CustomEvent(Tv);document.dispatchEvent(e)}function AM(e,n,t,{discrete:r}){const o=t.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?cw(o,s):o.dispatchEvent(s)}const uX=dg,hX=cX,cy="focusScope.autoFocusOnMount",ly="focusScope.autoFocusOnUnmount",sI={bubbles:!1,cancelable:!0},lw=x.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,c]=x.useState(null),l=ln(o),d=ln(s),u=x.useRef(null),f=Xe(n,g=>c(g)),p=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let v=function(C){if(p.paused||!a)return;const _=C.target;a.contains(_)?u.current=_:ws(u.current,{select:!0})},P=function(C){if(p.paused||!a)return;const _=C.relatedTarget;_!==null&&(a.contains(_)||ws(u.current,{select:!0}))},E=function(C){if(document.activeElement===document.body)for(const k of C)k.removedNodes.length>0&&ws(a)};var g=v,w=P,y=E;document.addEventListener("focusin",v),document.addEventListener("focusout",P);const I=new MutationObserver(E);return a&&I.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",P),I.disconnect()}}},[r,a,p.paused]),x.useEffect(()=>{if(a){aI.add(p);const g=document.activeElement;if(!a.contains(g)){const y=new CustomEvent(cy,sI);a.addEventListener(cy,l),a.dispatchEvent(y),y.defaultPrevented||(fX(SX(jM(a)),{select:!0}),document.activeElement===g&&ws(a))}return()=>{a.removeEventListener(cy,l),setTimeout(()=>{const y=new CustomEvent(ly,sI);a.addEventListener(ly,d),a.dispatchEvent(y),y.defaultPrevented||ws(g??document.body,{select:!0}),a.removeEventListener(ly,d),aI.remove(p)},0)}}},[a,l,d,p]);const S=x.useCallback(g=>{if(!t&&!r||p.paused)return;const w=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,y=document.activeElement;if(w&&y){const v=g.currentTarget,[P,E]=pX(v);P&&E?!g.shiftKey&&y===E?(g.preventDefault(),t&&ws(P,{select:!0})):g.shiftKey&&y===P&&(g.preventDefault(),t&&ws(E,{select:!0})):y===v&&g.preventDefault()}},[t,r,p.paused]);return x.createElement(He.div,Z({tabIndex:-1},i,{ref:f,onKeyDown:S}))});function fX(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(ws(r,{select:n}),document.activeElement!==t)return}function pX(e){const n=jM(e),t=iI(n,e),r=iI(n.reverse(),e);return[t,r]}function jM(e){const n=[],t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const o=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||o?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;t.nextNode();)n.push(t.currentNode);return n}function iI(e,n){for(const t of e)if(!gX(t,{upTo:n}))return t}function gX(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 mX(e){return e instanceof HTMLInputElement&&"select"in e}function ws(e,{select:n=!1}={}){if(e&&e.focus){const t=document.activeElement;e.focus({preventScroll:!0}),e!==t&&mX(e)&&n&&e.select()}}const aI=yX();function yX(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=cI(e,n),e.unshift(n)},remove(n){var t;e=cI(e,n),(t=e[0])===null||t===void 0||t.resume()}}}function cI(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function SX(e){return e.filter(n=>n.tagName!=="A")}const ug=x.forwardRef((e,n)=>{var t;const{container:r=globalThis==null||(t=globalThis.document)===null||t===void 0?void 0:t.body,...o}=e;return r?UH.createPortal(x.createElement(He.div,Z({},o,{ref:n})),r):null});function vX(e,n){return x.useReducer((t,r)=>{const o=n[t][r];return o??t},e)}const Io=e=>{const{present:n,children:t}=e,r=xX(n),o=typeof t=="function"?t({present:r.isPresent}):x.Children.only(t),s=Xe(r.ref,o.ref);return typeof t=="function"||r.isPresent?x.cloneElement(o,{ref:s}):null};Io.displayName="Presence";function xX(e){const[n,t]=x.useState(),r=x.useRef({}),o=x.useRef(e),s=x.useRef("none"),i=e?"mounted":"unmounted",[a,c]=vX(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const l=Yu(r.current);s.current=a==="mounted"?l:"none"},[a]),Gi(()=>{const l=r.current,d=o.current;if(d!==e){const f=s.current,p=Yu(l);e?c("MOUNT"):p==="none"||(l==null?void 0:l.display)==="none"?c("UNMOUNT"):c(d&&f!==p?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,c]),Gi(()=>{if(n){const l=u=>{const p=Yu(r.current).includes(u.animationName);u.target===n&&p&&oa.flushSync(()=>c("ANIMATION_END"))},d=u=>{u.target===n&&(s.current=Yu(r.current))};return n.addEventListener("animationstart",d),n.addEventListener("animationcancel",l),n.addEventListener("animationend",l),()=>{n.removeEventListener("animationstart",d),n.removeEventListener("animationcancel",l),n.removeEventListener("animationend",l)}}else c("ANIMATION_END")},[n,c]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:x.useCallback(l=>{l&&(r.current=getComputedStyle(l)),t(l)},[])}}function Yu(e){return(e==null?void 0:e.animationName)||"none"}let dy=0;function dw(){x.useEffect(()=>{var e,n;const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",(e=t[0])!==null&&e!==void 0?e:lI()),document.body.insertAdjacentElement("beforeend",(n=t[1])!==null&&n!==void 0?n:lI()),dy++,()=>{dy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),dy--}},[])}function lI(){const e=document.createElement("span");return e.setAttribute("data-radix-focus-guard",""),e.tabIndex=0,e.style.cssText="outline: none; opacity: 0; position: fixed; pointer-events: none",e}var oo=function(){return oo=Object.assign||function(n){for(var t,r=1,o=arguments.length;r<o;r++){t=arguments[r];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[s]=t[s])}return n},oo.apply(this,arguments)};function OM(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 wX(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 cf="right-scroll-bar-position",lf="width-before-scroll-bar",bX="with-scroll-bars-hidden",PX="--removed-body-scroll-bar-size";function uy(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function CX(e,n){var t=x.useState(function(){return{value:e,callback:n,facade:{get current(){return t.value},set current(r){var o=t.value;o!==r&&(t.value=r,t.callback(r,o))}}}})[0];return t.callback=n,t.facade}var IX=typeof window<"u"?x.useLayoutEffect:x.useEffect,dI=new WeakMap;function EX(e,n){var t=CX(null,function(r){return e.forEach(function(o){return uy(o,r)})});return IX(function(){var r=dI.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||uy(a,null)}),s.forEach(function(a){o.has(a)||uy(a,i)})}dI.set(t,e)},[e]),t}function _X(e){return e}function kX(e,n){n===void 0&&(n=_X);var t=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return t.length?t[t.length-1]:e},useMedium:function(s){var i=n(s,r);return t.push(i),function(){t=t.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;t.length;){var i=t;t=[],i.forEach(s)}t={push:function(a){return s(a)},filter:function(){return t}}},assignMedium:function(s){r=!0;var i=[];if(t.length){var a=t;t=[],a.forEach(s),i=t}var c=function(){var d=i;i=[],d.forEach(s)},l=function(){return Promise.resolve().then(c)};l(),t={push:function(d){i.push(d),l()},filter:function(d){return i=i.filter(d),t}}}};return o}function TX(e){e===void 0&&(e={});var n=kX(null);return n.options=oo({async:!0,ssr:!1},e),n}var DM=function(e){var n=e.sideCar,t=OM(e,["sideCar"]);if(!n)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=n.read();if(!r)throw new Error("Sidecar medium not found");return x.createElement(r,oo({},t))};DM.isSideCarExport=!0;function $X(e,n){return e.useMedium(n),DM}var RM=TX(),hy=function(){},hg=x.forwardRef(function(e,n){var t=x.useRef(null),r=x.useState({onScrollCapture:hy,onWheelCapture:hy,onTouchMoveCapture:hy}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,c=e.className,l=e.removeScrollBar,d=e.enabled,u=e.shards,f=e.sideCar,p=e.noIsolation,S=e.inert,g=e.allowPinchZoom,w=e.as,y=w===void 0?"div":w,v=OM(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),P=f,E=EX([t,n]),I=oo(oo({},v),o);return x.createElement(x.Fragment,null,d&&x.createElement(P,{sideCar:RM,removeScrollBar:l,shards:u,noIsolation:p,inert:S,setCallbacks:s,allowPinchZoom:!!g,lockRef:t}),i?x.cloneElement(x.Children.only(a),oo(oo({},I),{ref:E})):x.createElement(y,oo({},I,{className:c,ref:E}),a))});hg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};hg.classNames={fullWidth:lf,zeroRight:cf};var MX=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function AX(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=MX();return n&&e.setAttribute("nonce",n),e}function jX(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function OX(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var DX=function(){var e=0,n=null;return{add:function(t){e==0&&(n=AX())&&(jX(n,t),OX(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},RX=function(){var e=DX();return function(n,t){x.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},LM=function(){var e=RX(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},LX={left:0,top:0,right:0,gap:0},fy=function(e){return parseInt(e||"",10)||0},FX=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[fy(t),fy(r),fy(o)]},zX=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return LX;var n=FX(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])}},NX=LM(),nc="data-scroll-locked",BX=function(e,n,t,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return t===void 0&&(t="margin"),`
|
|
159
|
-
.`.concat(bX,` {
|
|
160
|
-
overflow: hidden `).concat(r,`;
|
|
161
|
-
padding-right: `).concat(a,"px ").concat(r,`;
|
|
162
|
-
}
|
|
163
|
-
body[`).concat(nc,`] {
|
|
164
|
-
overflow: hidden `).concat(r,`;
|
|
165
|
-
overscroll-behavior: contain;
|
|
166
|
-
`).concat([n&&"position: relative ".concat(r,";"),t==="margin"&&`
|
|
167
|
-
padding-left: `.concat(o,`px;
|
|
168
|
-
padding-top: `).concat(s,`px;
|
|
169
|
-
padding-right: `).concat(i,`px;
|
|
170
|
-
margin-left:0;
|
|
171
|
-
margin-top:0;
|
|
172
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
173
|
-
`),t==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
.`).concat(cf,` {
|
|
177
|
-
right: `).concat(a,"px ").concat(r,`;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.`).concat(lf,` {
|
|
181
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
.`).concat(cf," .").concat(cf,` {
|
|
185
|
-
right: 0 `).concat(r,`;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.`).concat(lf," .").concat(lf,` {
|
|
189
|
-
margin-right: 0 `).concat(r,`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
body[`).concat(nc,`] {
|
|
193
|
-
`).concat(PX,": ").concat(a,`px;
|
|
194
|
-
}
|
|
195
|
-
`)},uI=function(){var e=parseInt(document.body.getAttribute(nc)||"0",10);return isFinite(e)?e:0},UX=function(){x.useEffect(function(){return document.body.setAttribute(nc,(uI()+1).toString()),function(){var e=uI()-1;e<=0?document.body.removeAttribute(nc):document.body.setAttribute(nc,e.toString())}},[])},HX=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;UX();var s=x.useMemo(function(){return zX(o)},[o]);return x.createElement(NX,{styles:BX(s,!n,o,t?"":"!important")})},$v=!1;if(typeof window<"u")try{var Xu=Object.defineProperty({},"passive",{get:function(){return $v=!0,!0}});window.addEventListener("test",Xu,Xu),window.removeEventListener("test",Xu,Xu)}catch{$v=!1}var ya=$v?{passive:!1}:!1,KX=function(e){return e.tagName==="TEXTAREA"},FM=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!KX(e)&&t[n]==="visible")},WX=function(e){return FM(e,"overflowY")},GX=function(e){return FM(e,"overflowX")},hI=function(e,n){var t=n;do{typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&(t=t.host);var r=zM(e,t);if(r){var o=NM(e,t),s=o[1],i=o[2];if(s>i)return!0}t=t.parentNode}while(t&&t!==document.body);return!1},VX=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},YX=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},zM=function(e,n){return e==="v"?WX(n):GX(n)},NM=function(e,n){return e==="v"?VX(n):YX(n)},XX=function(e,n){return e==="h"&&n==="rtl"?-1:1},qX=function(e,n,t,r,o){var s=XX(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,c=n.contains(a),l=!1,d=i>0,u=0,f=0;do{var p=NM(e,a),S=p[0],g=p[1],w=p[2],y=g-w-s*S;(S||y)&&zM(e,a)&&(u+=y,f+=S),a=a.parentNode}while(!c&&a!==document.body||c&&(n.contains(a)||n===a));return(d&&(u===0||!o)||!d&&(f===0||!o))&&(l=!0),l},qu=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},fI=function(e){return[e.deltaX,e.deltaY]},pI=function(e){return e&&"current"in e?e.current:e},ZX=function(e,n){return e[0]===n[0]&&e[1]===n[1]},QX=function(e){return`
|
|
196
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
197
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
198
|
-
`)},JX=0,Sa=[];function eq(e){var n=x.useRef([]),t=x.useRef([0,0]),r=x.useRef(),o=x.useState(JX++)[0],s=x.useState(function(){return LM()})[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=wX([e.lockRef.current],(e.shards||[]).map(pI),!0).filter(Boolean);return g.forEach(function(w){return w.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(g,w){if("touches"in g&&g.touches.length===2)return!i.current.allowPinchZoom;var y=qu(g),v=t.current,P="deltaX"in g?g.deltaX:v[0]-y[0],E="deltaY"in g?g.deltaY:v[1]-y[1],I,C=g.target,_=Math.abs(P)>Math.abs(E)?"h":"v";if("touches"in g&&_==="h"&&C.type==="range")return!1;var k=hI(_,C);if(!k)return!0;if(k?I=_:(I=_==="v"?"h":"v",k=hI(_,C)),!k)return!1;if(!r.current&&"changedTouches"in g&&(P||E)&&(r.current=I),!I)return!0;var j=r.current||I;return qX(j,w,g,j==="h"?P:E,!0)},[]),c=x.useCallback(function(g){var w=g;if(!(!Sa.length||Sa[Sa.length-1]!==s)){var y="deltaY"in w?fI(w):qu(w),v=n.current.filter(function(I){return I.name===w.type&&I.target===w.target&&ZX(I.delta,y)})[0];if(v&&v.should){w.cancelable&&w.preventDefault();return}if(!v){var P=(i.current.shards||[]).map(pI).filter(Boolean).filter(function(I){return I.contains(w.target)}),E=P.length>0?a(w,P[0]):!i.current.noIsolation;E&&w.cancelable&&w.preventDefault()}}},[]),l=x.useCallback(function(g,w,y,v){var P={name:g,delta:w,target:y,should:v};n.current.push(P),setTimeout(function(){n.current=n.current.filter(function(E){return E!==P})},1)},[]),d=x.useCallback(function(g){t.current=qu(g),r.current=void 0},[]),u=x.useCallback(function(g){l(g.type,fI(g),g.target,a(g,e.lockRef.current))},[]),f=x.useCallback(function(g){l(g.type,qu(g),g.target,a(g,e.lockRef.current))},[]);x.useEffect(function(){return Sa.push(s),e.setCallbacks({onScrollCapture:u,onWheelCapture:u,onTouchMoveCapture:f}),document.addEventListener("wheel",c,ya),document.addEventListener("touchmove",c,ya),document.addEventListener("touchstart",d,ya),function(){Sa=Sa.filter(function(g){return g!==s}),document.removeEventListener("wheel",c,ya),document.removeEventListener("touchmove",c,ya),document.removeEventListener("touchstart",d,ya)}},[]);var p=e.removeScrollBar,S=e.inert;return x.createElement(x.Fragment,null,S?x.createElement(s,{styles:QX(o)}):null,p?x.createElement(HX,{gapMode:"margin"}):null)}const tq=$X(RM,eq);var fg=x.forwardRef(function(e,n){return x.createElement(hg,oo({},e,{ref:n,sideCar:tq}))});fg.classNames=hg.classNames;var nq=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},va=new WeakMap,Zu=new WeakMap,Qu={},py=0,BM=function(e){return e&&(e.host||BM(e.parentNode))},rq=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=BM(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})},oq=function(e,n,t,r){var o=rq(n,Array.isArray(e)?e:[e]);Qu[t]||(Qu[t]=new WeakMap);var s=Qu[t],i=[],a=new Set,c=new Set(o),l=function(u){!u||a.has(u)||(a.add(u),l(u.parentNode))};o.forEach(l);var d=function(u){!u||c.has(u)||Array.prototype.forEach.call(u.children,function(f){if(a.has(f))d(f);else try{var p=f.getAttribute(r),S=p!==null&&p!=="false",g=(va.get(f)||0)+1,w=(s.get(f)||0)+1;va.set(f,g),s.set(f,w),i.push(f),g===1&&S&&Zu.set(f,!0),w===1&&f.setAttribute(t,"true"),S||f.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",f,y)}})};return d(n),a.clear(),py++,function(){i.forEach(function(u){var f=va.get(u)-1,p=s.get(u)-1;va.set(u,f),s.set(u,p),f||(Zu.has(u)||u.removeAttribute(r),Zu.delete(u)),p||u.removeAttribute(t)}),py--,py||(va=new WeakMap,va=new WeakMap,Zu=new WeakMap,Qu={})}},uw=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=nq(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),oq(r,o,t,"aria-hidden")):function(){return null}};const UM="Dialog",[HM,cse]=Co(UM),[sq,cs]=HM(UM),iq=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),c=x.useRef(null),[l=!1,d]=ii({prop:r,defaultProp:o,onChange:s});return x.createElement(sq,{scope:n,triggerRef:a,contentRef:c,contentId:Vo(),titleId:Vo(),descriptionId:Vo(),open:l,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(u=>!u),[d]),modal:i},t)},KM="DialogPortal",[aq,WM]=HM(KM,{forceMount:void 0}),cq=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=cs(KM,n);return x.createElement(aq,{scope:n,forceMount:t},x.Children.map(r,i=>x.createElement(Io,{present:t||s.open},x.createElement(ug,{asChild:!0,container:o},i))))},Mv="DialogOverlay",lq=x.forwardRef((e,n)=>{const t=WM(Mv,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=cs(Mv,e.__scopeDialog);return s.modal?x.createElement(Io,{present:r||s.open},x.createElement(dq,Z({},o,{ref:n}))):null}),dq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=cs(Mv,t);return x.createElement(fg,{as:Vi,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(He.div,Z({"data-state":VM(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),fd="DialogContent",uq=x.forwardRef((e,n)=>{const t=WM(fd,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=cs(fd,e.__scopeDialog);return x.createElement(Io,{present:r||s.open},s.modal?x.createElement(hq,Z({},o,{ref:n})):x.createElement(fq,Z({},o,{ref:n})))}),hq=x.forwardRef((e,n)=>{const t=cs(fd,e.__scopeDialog),r=x.useRef(null),o=Xe(n,t.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return uw(s)},[]),x.createElement(GM,Z({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ie(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:ie(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault())}))}),fq=x.forwardRef((e,n)=>{const t=cs(fd,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(GM,Z({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),GM=x.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=cs(fd,t),c=x.useRef(null),l=Xe(n,c);return dw(),x.createElement(x.Fragment,null,x.createElement(lw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(dg,Z({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":VM(a.open)},i,{ref:l,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),pq="DialogTitle",gq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=cs(pq,t);return x.createElement(He.h2,Z({id:o.titleId},r,{ref:n}))});const mq="DialogClose",yq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=cs(mq,t);return x.createElement(He.button,Z({type:"button"},r,{ref:n,onClick:ie(e.onClick,()=>o.onOpenChange(!1))}))});function VM(e){return e?"open":"closed"}const Sq=iq,vq=cq,xq=lq,wq=uq,YM=()=>{},XM=x.createContext(null);function bq({onEvent:e,children:n}){return h.jsx(XM.Provider,{value:e??YM,children:n})}function Yr(){return x.useContext(XM)??YM}const qM=x.createContext(null);function Pq({children:e}){const n=N(),t=Yr(),[r,o]=x.useState([]),s=x.useCallback(l=>{const d=l.id??st();return o(u=>[...u.filter(f=>f.id!==l.id),{...l,id:d}]),t("open-menu",{source:"dialog",id:d}),n.addOpenMenu(d),d},[n,t]),i=x.useCallback((l,d)=>(o(u=>u.map(f=>f.id===l?{...f,...d}:f)),t("open-menu",{source:"dialog",id:l}),n.addOpenMenu(l),l),[n,t]),a=x.useCallback(l=>(o(d=>d.filter(u=>{var f;return u.id===l?((f=u.onClose)==null||f.call(u),!1):!0})),t("close-menu",{source:"dialog",id:l}),n.deleteOpenMenu(l),l),[n,t]),c=x.useCallback(()=>{o(l=>(l.forEach(d=>{var u;(u=d.onClose)==null||u.call(d),t("close-menu",{source:"dialog",id:d.id}),n.deleteOpenMenu(d.id)}),[]))},[n,t]);return h.jsx(qM.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:c,updateDialog:i},children:e})}function sa(){const e=x.useContext(qM);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const Cq=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=sa(),o=dn(),s=x.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return h.jsx(Sq,{onOpenChange:s,defaultOpen:!0,children:h.jsx(vq,{container:o,children:h.jsx(xq,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:h.jsx(wq,{dir:"ltr",className:"tlui-dialog__content",children:h.jsx(n,{onClose:()=>s(!1)})})})})})};function Iq(){const{dialogs:e}=sa();return h.jsx(h.Fragment,{children:e.map(n=>h.jsx(Cq,{...n},n.id))})}const Eq=ve.memo(Iq);function _q(){const e=N(),n=W("follow",()=>e.getInstanceState().followingUserId,[e]);return n?h.jsx(kq,{userId:n}):null}function kq({userId:e}){const n=Dk(e);return n?h.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function pg(e){const n=e+"CollectionProvider",[t,r]=Co(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:S,children:g}=p,w=ve.useRef(null),y=ve.useRef(new Map).current;return ve.createElement(o,{scope:S,itemMap:y,collectionRef:w},g)},a=e+"CollectionSlot",c=ve.forwardRef((p,S)=>{const{scope:g,children:w}=p,y=s(a,g),v=Xe(S,y.collectionRef);return ve.createElement(Vi,{ref:v},w)}),l=e+"CollectionItemSlot",d="data-radix-collection-item",u=ve.forwardRef((p,S)=>{const{scope:g,children:w,...y}=p,v=ve.useRef(null),P=Xe(S,v),E=s(l,g);return ve.useEffect(()=>(E.itemMap.set(v,{ref:v,...y}),()=>void E.itemMap.delete(v))),ve.createElement(Vi,{[d]:"",ref:P},w)});function f(p){const S=s(e+"CollectionConsumer",p);return ve.useCallback(()=>{const w=S.collectionRef.current;if(!w)return[];const y=Array.from(w.querySelectorAll(`[${d}]`));return Array.from(S.itemMap.values()).sort((E,I)=>y.indexOf(E.ref.current)-y.indexOf(I.ref.current))},[S.collectionRef,S.itemMap])}return[{Provider:i,Slot:c,ItemSlot:u},f,r]}const ZM=x.forwardRef((e,n)=>x.createElement(He.span,Z({},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}}))),QM="ToastProvider",[hw,Tq,$q]=pg("Toast"),[JM,lse]=Co("Toast",[$q]),[Mq,gg]=JM(QM),eA=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,c]=x.useState(null),[l,d]=x.useState(0),u=x.useRef(!1),f=x.useRef(!1);return x.createElement(hw.Provider,{scope:n},x.createElement(Mq,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:l,viewport:a,onViewportChange:c,onToastAdd:x.useCallback(()=>d(p=>p+1),[]),onToastRemove:x.useCallback(()=>d(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:u,isClosePausedRef:f},i))};eA.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const n=`Invalid prop \`label\` supplied to \`${QM}\`. Expected non-empty \`string\`.`;return new Error(n)}return null}};const Aq="ToastViewport",jq=["F8"],Av="toast.viewportPause",jv="toast.viewportResume",Oq=x.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=jq,label:o="Notifications ({hotkey})",...s}=e,i=gg(Aq,t),a=Tq(t),c=x.useRef(null),l=x.useRef(null),d=x.useRef(null),u=x.useRef(null),f=Xe(n,u,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=i.toastCount>0;x.useEffect(()=>{const w=y=>{var v;r.every(E=>y[E]||y.code===E)&&((v=u.current)===null||v===void 0||v.focus())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[r]),x.useEffect(()=>{const w=c.current,y=u.current;if(S&&w&&y){const v=()=>{if(!i.isClosePausedRef.current){const C=new CustomEvent(Av);y.dispatchEvent(C),i.isClosePausedRef.current=!0}},P=()=>{if(i.isClosePausedRef.current){const C=new CustomEvent(jv);y.dispatchEvent(C),i.isClosePausedRef.current=!1}},E=C=>{!w.contains(C.relatedTarget)&&P()},I=()=>{w.contains(document.activeElement)||P()};return w.addEventListener("focusin",v),w.addEventListener("focusout",E),w.addEventListener("pointermove",v),w.addEventListener("pointerleave",I),window.addEventListener("blur",v),window.addEventListener("focus",P),()=>{w.removeEventListener("focusin",v),w.removeEventListener("focusout",E),w.removeEventListener("pointermove",v),w.removeEventListener("pointerleave",I),window.removeEventListener("blur",v),window.removeEventListener("focus",P)}}},[S,i.isClosePausedRef]);const g=x.useCallback(({tabbingDirection:w})=>{const v=a().map(P=>{const E=P.ref.current,I=[E,...qq(E)];return w==="forwards"?I:I.reverse()});return(w==="forwards"?v.reverse():v).flat()},[a]);return x.useEffect(()=>{const w=u.current;if(w){const y=v=>{const P=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!P){const k=document.activeElement,j=v.shiftKey;if(v.target===w&&j){var I;(I=l.current)===null||I===void 0||I.focus();return}const R=g({tabbingDirection:j?"backwards":"forwards"}),A=R.findIndex(O=>O===k);if(gy(R.slice(A+1)))v.preventDefault();else{var C,_;j?(C=l.current)===null||C===void 0||C.focus():(_=d.current)===null||_===void 0||_.focus()}}};return w.addEventListener("keydown",y),()=>w.removeEventListener("keydown",y)}},[a,g]),x.createElement(hX,{ref:c,role:"region","aria-label":o.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:S?void 0:"none"}},S&&x.createElement(gI,{ref:l,onFocusFromOutsideViewport:()=>{const w=g({tabbingDirection:"forwards"});gy(w)}}),x.createElement(hw.Slot,{scope:t},x.createElement(He.ol,Z({tabIndex:-1},s,{ref:f}))),S&&x.createElement(gI,{ref:d,onFocusFromOutsideViewport:()=>{const w=g({tabbingDirection:"backwards"});gy(w)}}))}),Dq="ToastFocusProxy",gI=x.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=gg(Dq,t);return x.createElement(ZM,Z({"aria-hidden":!0,tabIndex:0},o,{ref:n,style:{position:"fixed"},onFocus:i=>{var a;const c=i.relatedTarget;!((a=s.viewport)!==null&&a!==void 0&&a.contains(c))&&r()}}))}),mg="Toast",Rq="toast.swipeStart",Lq="toast.swipeMove",Fq="toast.swipeCancel",zq="toast.swipeEnd",Nq=x.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,c]=ii({prop:r,defaultProp:o,onChange:s});return x.createElement(Io,{present:t||a},x.createElement(tA,Z({open:a},i,{ref:n,onClose:()=>c(!1),onPause:ln(e.onPause),onResume:ln(e.onResume),onSwipeStart:ie(e.onSwipeStart,l=>{l.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:ie(e.onSwipeMove,l=>{const{x:d,y:u}=l.detail.delta;l.currentTarget.setAttribute("data-swipe","move"),l.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${d}px`),l.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${u}px`)}),onSwipeCancel:ie(e.onSwipeCancel,l=>{l.currentTarget.setAttribute("data-swipe","cancel"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),l.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:ie(e.onSwipeEnd,l=>{const{x:d,y:u}=l.detail.delta;l.currentTarget.setAttribute("data-swipe","end"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),l.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),l.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${d}px`),l.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${u}px`),c(!1)})})))}),[Bq,Uq]=JM(mg,{onClose(){}}),tA=x.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:c,onResume:l,onSwipeStart:d,onSwipeMove:u,onSwipeCancel:f,onSwipeEnd:p,...S}=e,g=gg(mg,t),[w,y]=x.useState(null),v=Xe(n,O=>y(O)),P=x.useRef(null),E=x.useRef(null),I=o||g.duration,C=x.useRef(0),_=x.useRef(I),k=x.useRef(0),{onToastAdd:j,onToastRemove:T}=g,M=ln(()=>{var O;(w==null?void 0:w.contains(document.activeElement))&&((O=g.viewport)===null||O===void 0||O.focus()),i()}),R=x.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),C.current=new Date().getTime(),k.current=window.setTimeout(M,O))},[M]);x.useEffect(()=>{const O=g.viewport;if(O){const L=()=>{R(_.current),l==null||l()},G=()=>{const K=new Date().getTime()-C.current;_.current=_.current-K,window.clearTimeout(k.current),c==null||c()};return O.addEventListener(Av,G),O.addEventListener(jv,L),()=>{O.removeEventListener(Av,G),O.removeEventListener(jv,L)}}},[g.viewport,I,c,l,R]),x.useEffect(()=>{s&&!g.isClosePausedRef.current&&R(I)},[s,I,g.isClosePausedRef,R]),x.useEffect(()=>(j(),()=>T()),[j,T]);const A=x.useMemo(()=>w?sA(w):null,[w]);return g.viewport?x.createElement(x.Fragment,null,A&&x.createElement(Hq,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},A),x.createElement(Bq,{scope:t,onClose:M},oa.createPortal(x.createElement(hw.ItemSlot,{scope:t},x.createElement(uX,{asChild:!0,onEscapeKeyDown:ie(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||M(),g.isFocusedToastEscapeKeyDownRef.current=!1})},x.createElement(He.li,Z({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection},S,{ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:ie(e.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,M()))}),onPointerDown:ie(e.onPointerDown,O=>{O.button===0&&(P.current={x:O.clientX,y:O.clientY})}),onPointerMove:ie(e.onPointerMove,O=>{if(!P.current)return;const L=O.clientX-P.current.x,G=O.clientY-P.current.y,K=!!E.current,B=["left","right"].includes(g.swipeDirection),U=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,Y=B?U(0,L):0,Q=B?0:U(0,G),le=O.pointerType==="touch"?10:2,ge={x:Y,y:Q},Me={originalEvent:O,delta:ge};K?(E.current=ge,Ju(Lq,u,Me,{discrete:!1})):mI(ge,g.swipeDirection,le)?(E.current=ge,Ju(Rq,d,Me,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(L)>le||Math.abs(G)>le)&&(P.current=null)}),onPointerUp:ie(e.onPointerUp,O=>{const L=E.current,G=O.target;if(G.hasPointerCapture(O.pointerId)&&G.releasePointerCapture(O.pointerId),E.current=null,P.current=null,L){const K=O.currentTarget,B={originalEvent:O,delta:L};mI(L,g.swipeDirection,g.swipeThreshold)?Ju(zq,p,B,{discrete:!0}):Ju(Fq,f,B,{discrete:!0}),K.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})))),g.viewport))):null});tA.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const n=`Invalid prop \`type\` supplied to \`${mg}\`. Expected \`foreground | background\`.`;return new Error(n)}return null}};const Hq=e=>{const{__scopeToast:n,children:t,...r}=e,o=gg(mg,n),[s,i]=x.useState(!1),[a,c]=x.useState(!1);return Yq(()=>i(!0)),x.useEffect(()=>{const l=window.setTimeout(()=>c(!0),1e3);return()=>window.clearTimeout(l)},[]),a?null:x.createElement(ug,{asChild:!0},x.createElement(ZM,r,s&&x.createElement(x.Fragment,null,o.label," ",t)))},Kq=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return x.createElement(He.div,Z({},r,{ref:n}))}),Wq=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return x.createElement(He.div,Z({},r,{ref:n}))}),Gq="ToastAction",nA=x.forwardRef((e,n)=>{const{altText:t,...r}=e;return t?x.createElement(oA,{altText:t,asChild:!0},x.createElement(rA,Z({},r,{ref:n}))):null});nA.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${Gq}\``)}};const Vq="ToastClose",rA=x.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=Uq(Vq,t);return x.createElement(oA,{asChild:!0},x.createElement(He.button,Z({type:"button"},r,{ref:n,onClick:ie(e.onClick,o.onClose)})))}),oA=x.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return x.createElement(He.div,Z({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0},o,{ref:n}))});function sA(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),Xq(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(...sA(r))}}),n}function Ju(e,n,t,{discrete:r}){const o=t.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:t});n&&o.addEventListener(e,n,{once:!0}),r?cw(o,s):o.dispatchEvent(s)}const mI=(e,n,t=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return n==="left"||n==="right"?s&&r>t:!s&&o>t};function Yq(e=()=>{}){const n=ln(e);Gi(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function Xq(e){return e.nodeType===e.ELEMENT_NODE}function qq(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 gy(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}const Zq=Nq,Qq=Kq,Jq=Wq,eZ=nA,yI=rA,iA=x.createContext(null);function tZ({children:e}){const[n,t]=x.useState([]),r=x.useCallback(i=>{const a=i.id??st();return t(c=>[...c.filter(l=>l.id!==i.id),{...i,id:a}]),a},[]),o=x.useCallback(i=>(t(a=>a.filter(c=>c.id!==i)),i),[]),s=x.useCallback(()=>{t(()=>[])},[]);return h.jsx(eA,{children:h.jsx(iA.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})})}function Xr(){const e=x.useContext(iA);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const fe=x.forwardRef(function({children:n,disabled:t,type:r,...o},s){return h.jsx("button",{ref:s,type:"button",draggable:!1,disabled:t,...o,className:de("tlui-button",`tlui-button__${r}`,o.className),children:n})});function Pt({children:e}){return h.jsx("span",{className:"tlui-button__label",children:e})}const Xs=x.memo(function({small:n,invertIcon:t,icon:r,color:o,className:s,...i}){const a=ow(),c=a.icons[r]??a.icons["question-mark-circle"],l=x.useRef(null);return x.useLayoutEffect(()=>{c||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),l!=null&&l.current&&(l.current.style.webkitMask=`url(${c}) center 100% / 100% no-repeat`)},[l,c,r]),r==="none"?h.jsx("div",{className:de("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":n},s)}):h.jsx("div",{...i,ref:l,className:de("tlui-icon",{"tlui-icon__small":n},s),style:{color:o,mask:`url(${c}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})}),nZ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function rZ({toast:e}){const{removeToast:n}=Xr(),t=$e(),r=i=>{i||n(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&nZ[e.severity];return h.jsxs(Zq,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&h.jsx("div",{className:"tlui-toast__icon",children:h.jsx(Xs,{icon:s})}),h.jsxs("div",{className:"tlui-toast__main",children:[h.jsxs("div",{className:"tlui-toast__content",children:[e.title&&h.jsx(Qq,{className:"tlui-toast__title",children:e.title}),e.description&&h.jsx(Jq,{className:"tlui-toast__description",children:e.description})]}),e.actions&&h.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>h.jsx(eZ,{altText:i.label,asChild:!0,onClick:i.onClick,children:h.jsx(fe,{type:i.type,children:h.jsx(Pt,{children:i.label})})},a)),h.jsx(yI,{asChild:!0,children:h.jsx(fe,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:h.jsx(Pt,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&h.jsx(yI,{asChild:!0,children:h.jsx(fe,{type:"normal",className:"tlui-toast__close",children:h.jsx(Pt,{children:e.closeLabel??t("toast.close")})})})]})}function oZ(){const{toasts:e}=Xr();return h.jsx(h.Fragment,{children:e.map(n=>h.jsx(rZ,{toast:n},n.id))})}const sZ=x.memo(oZ);function iZ(){const e=N(),{toasts:n}=Xr(),[t,r]=x.useState(!1);return x.useEffect(()=>{let o=-1;return n.length?r(!0):o=e.timers.setTimeout(()=>{r(!1)},1e3),()=>{clearTimeout(o)}},[n.length,r,e]),t?h.jsx(Oq,{className:"tlui-toast__viewport"}):null}function Pe({icon:e,small:n,invertIcon:t}){return h.jsx(Xs,{className:"tlui-button__icon",icon:e,small:n,invertIcon:t})}const my=[0,390,428,468,580,640,840,1023];var vt=(e=>(e[e.ZERO=0]="ZERO",e[e.MOBILE_XXS=1]="MOBILE_XXS",e[e.MOBILE_XS=2]="MOBILE_XS",e[e.MOBILE_SM=3]="MOBILE_SM",e[e.MOBILE=4]="MOBILE",e[e.TABLET_SM=5]="TABLET_SM",e[e.TABLET=6]="TABLET",e[e.DESKTOP=7]="DESKTOP",e))(vt||{});const aZ="2.3.0-canary.fef462bd67aa",cZ="https://cdn.tldraw.com";function Ei(){return`${cZ}/${aZ}`}let Ov={fonts:{draw:`${Ei()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Ei()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Ei()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Ei()}/fonts/IBMPlexMono-Medium.woff2`}};function aA(e){return x.useMemo(()=>e?{fonts:{...Ov.fonts,...e==null?void 0:e.fonts}}:Ov,[e])}const lZ=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bring-forward","bring-to-front","broken","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","color","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","leading","link","lock","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","stretch-horizontal","stretch-vertical","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let dl={...Ov,icons:Object.fromEntries(lZ.map(e=>[e,`${Ei()}/icons/icon/${e}.svg`])),translations:Object.fromEntries(Vl.map(e=>[e.locale,`${Ei()}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Ad.map(e=>[e.type,`${Ei()}/embed-icons/${e.type}.png`]))};function dZ(e){return e?{fonts:Object.assign({...dl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...dl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...dl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...dl.translations},{...e==null?void 0:e.translations})}:dl}function yg({className:e,children:n}){return h.jsx("div",{className:de("tlui-dialog__header",e),children:n})}function Sg({className:e,children:n}){return h.jsx(gq,{dir:"ltr",className:de("tlui-dialog__header__title",e),children:n})}function vg(){return h.jsx("div",{className:"tlui-dialog__header__close",children:h.jsx(yq,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:h.jsx(fe,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:h.jsx(Pe,{small:!0,icon:"cross-2"})})})})}function pd({className:e,children:n,style:t}){return h.jsx("div",{className:de("tlui-dialog__body",e),style:t,children:n})}function fw({className:e,children:n}){return h.jsx("div",{className:de("tlui-dialog__footer",e),children:n})}const pw=x.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:c,onComplete:l,onValueChange:d,onCancel:u,onFocus:f,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:S=!1,children:g,value:w},y){const v=N(),P=x.useRef(null);x.useImperativeHandle(y,()=>P.current);const E=$e(),I=x.useRef(a??""),C=x.useRef(a??""),[_,k]=x.useState(!1),j=x.useCallback(A=>{k(!0);const O=A.currentTarget;C.current=O.value,v.timers.requestAnimationFrame(()=>{s&&O.select()}),f==null||f()},[s,f,v.timers]),T=x.useCallback(A=>{const O=A.currentTarget.value;C.current=O,d==null||d(O)},[d]),M=x.useCallback(A=>{switch(A.key){case"Enter":{A.currentTarget.blur(),Kt(A),l==null||l(A.currentTarget.value);break}case"Escape":{A.currentTarget.value=I.current,A.currentTarget.blur(),Kt(A),u==null||u(A.currentTarget.value);break}}},[l,u]),R=x.useCallback(A=>{k(!1);const O=A.currentTarget.value;p==null||p(O)},[p]);return x.useEffect(()=>{if(!v.environment.isIos)return;const A=window.visualViewport;if(_&&S&&A){const O=()=>{var L;(L=P.current)==null||L.scrollIntoView({block:"center"})};return A.addEventListener("resize",O),A.addEventListener("scroll",O),v.timers.requestAnimationFrame(()=>{var L;(L=P.current)==null||L.scrollIntoView({block:"center"})}),()=>{A.removeEventListener("resize",O),A.removeEventListener("scroll",O)}}},[v,_,S]),h.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[g,t&&h.jsx("label",{children:E(t)}),o&&h.jsx(Xs,{icon:o,className:"tlui-icon-left",small:!0}),h.jsx("input",{ref:P,className:de("tlui-input",n),type:"text",defaultValue:a,onKeyUp:M,onChange:T,onFocus:j,onBlur:R,autoFocus:i,placeholder:c,value:w}),r&&h.jsx(Xs,{icon:r,small:!!t})]})}),cA=sr(function({onClose:n}){const t=N(),r=$e(),o=ow(),[s,i]=x.useState(null),[a,c]=x.useState(""),[l,d]=x.useState(null),[u,f]=x.useState(!1),p=x.useRef(-1);return h.jsxs(h.Fragment,{children:[h.jsxs(yg,{children:[h.jsx(Sg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),h.jsx(vg,{})]}),s?h.jsxs(h.Fragment,{children:[h.jsxs(pd,{className:"tlui-embed-dialog__enter",children:[h.jsx(pw,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:S=>{c(S);const g=Ms(S);d(g&&g.definition.type===s.type?g:null),f(!1),clearTimeout(p.current),p.current=t.timers.setTimeout(()=>f(!g),320)}}),a===""?h.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[h.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&h.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",h.jsx(Xs,{icon:"external-link",small:!0})]})]}):h.jsx("div",{className:"tlui-embed-dialog__warning",children:u?r("embed-dialog.invalid-url"):" "})]}),h.jsxs(fw,{className:"tlui-dialog__footer__actions",children:[h.jsx(fe,{type:"normal",onClick:()=>{i(null),d(null),c("")},children:h.jsx(Pt,{children:r("embed-dialog.back")})}),h.jsx("div",{className:"tlui-embed__spacer"}),h.jsx(fe,{type:"normal",onClick:n,children:h.jsx(Pt,{children:r("embed-dialog.cancel")})}),h.jsx(fe,{type:"primary",disabled:!l,onClick:()=>{l&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:l.definition}),n())},children:h.jsx(Pt,{children:r("embed-dialog.create")})})]})]}):h.jsx(h.Fragment,{children:h.jsx(pd,{className:"tlui-embed-dialog__list",children:Ad.map(S=>h.jsxs(fe,{type:"menu",onClick:()=>i(S),children:[h.jsx(Pt,{children:S.title}),h.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[S.type]})`}})]},S.type))})})]})});function lA(){const e=N(),n=x.useRef();return x.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept=JN,t.multiple=!0,n.current=t;async function r(o){const s=o.target.files;!s||s.length===0||(e.mark("insert media"),await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),t.value="")}return t.addEventListener("change",r),()=>{n.current=void 0,t.removeEventListener("change",r)}},[e]),x.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}const dA=x.createContext(null);function uZ({overrides:e,children:n}){const t=N(),r=Yr(),{addDialog:o}=sa(),s=lA(),i=x.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(l){t.setCurrentTool("select"),r("select-tool",{source:l,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(l){t.setCurrentTool("hand"),r("select-tool",{source:l,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(l){t.setCurrentTool("eraser"),r("select-tool",{source:l,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(l){t.setCurrentTool("draw"),r("select-tool",{source:l,id:"draw"})}},...[...Lr.values].map(l=>({id:l,label:`tool.${l}`,meta:{geo:l},kbd:l==="rectangle"?"r":l==="ellipse"?"o":void 0,icon:"geo-"+l,onSelect(d){t.batch(()=>{t.setStyleForNextShapes(Lr,l),t.setCurrentTool("geo"),r("select-tool",{source:d,id:`geo-${l}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(l){t.setCurrentTool("arrow"),r("select-tool",{source:l,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(l){t.setCurrentTool("line"),r("select-tool",{source:l,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(l){t.setCurrentTool("frame"),r("select-tool",{source:l,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(l){t.setCurrentTool("text"),r("select-tool",{source:l,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(l){s(),r("select-tool",{source:l,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(l){t.setCurrentTool("note"),r("select-tool",{source:l,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(l){t.setCurrentTool("laser"),r("select-tool",{source:l,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(l){o({component:cA}),r("select-tool",{source:l,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(l){t.setCurrentTool("highlight"),r("select-tool",{source:l,id:"highlight"})}}];a.push();const c=Object.fromEntries(a.map(l=>[l.id,l]));return e?e(t,c,{insertMedia:s}):c},[e,t,r,s,o]);return h.jsx(dA.Provider,{value:i,children:n})}function xg(){const e=x.useContext(dA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const uA=ve.createContext(null);function hZ({forceMobile:e=!1,children:n}){const t=N(),r=W("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?vt.MOBILE_SM:my.length-1;for(let i=0;i<s;i++)if(o>my[i]&&o<=my[i+1])return i;return s},[t]);return h.jsx(uA.Provider,{value:r,children:n})}function Nn(){const e=x.useContext(uA);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function fZ(){const{addToast:e,removeToast:n,clearToasts:t}=Xr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=sa(),c=Nn()<vt.TABLET_SM,l=$e();return x.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:l,isMobile:c}),[r,e,o,t,l,s,n,i,c])}function pZ(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of jn(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,n));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...n,...s}));return o},translations:t}}function hA(e){return x.useMemo(()=>e,e)}function gZ(e){const n=hA(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of jn(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function mZ(e){const n=fZ(),t=hA(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>pZ(t,n),[t,n])}function yZ(e,n){const t=Se(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 SZ=50;function vZ(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=Se(o.map(p=>e.getShape(p)));if(!s.length)return;const i=J.FromPoints(s.flatMap(p=>{const S=e.getShapeGeometry(p.id);return e.getShapeLocalTransform(p).applyToPoints(S.vertices)})),{padding:a=SZ}=t,c=i.w+2*a,l=i.h+2*a,d=a-i.minX,u=a-i.minY;if(d===0&&u===0&&r.props.w===c&&r.props.h===l)return;const f=new b(d,u).rot(r.rotation);e.batch(()=>{const p=o.map(S=>{const g=e.getShape(S);return{id:g.id,type:g.type,x:g.x+d,y:g.y+u}});p.push({id:r.id,type:r.type,x:r.x-f.x,y:r.y-f.y,props:{w:c,h:l}}),e.updateShapes(p)})}function SI(e){return nr.isValid(e)?{isValid:!0,hasProtocol:!0}:nr.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const xZ=sr(function({onClose:n}){const r=N().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?h.jsx(wZ,{onClose:n,selectedShape:r}):null}),wZ=sr(function({onClose:n,selectedShape:t}){const r=N(),o=$e(),s=x.useRef(null);x.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=s.current)==null?void 0:S.focus()})},[r]);const i=x.useRef(t.props.url),[a,c]=x.useState(()=>{const S=SI(t.props.url),g=S.isValid===!0?S.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:g,safe:g,valid:!0}}),l=x.useCallback(S=>{const g=S.replace(/https?:\/\/(https?:\/\/)/,(v,P)=>P),w=SI(g),y=w.isValid===!0?w.hasProtocol?g:"https://"+g:"https://";c({actual:g,safe:y,valid:w.isValid})},[]),d=x.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),n())},[r,n]),u=x.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(S&&"url"in S.props&&S.props.url!==a.safe&&r.updateShapes([{id:S.id,type:S.type,props:{url:a.safe}}]),n())},[r,n,a]),f=x.useCallback(()=>{n()},[n]);if(!t)return n(),null;const p=i.current&&!a.valid;return h.jsxs(h.Fragment,{children:[h.jsxs(yg,{children:[h.jsx(Sg,{children:o("edit-link-dialog.title")}),h.jsx(vg,{})]}),h.jsx(pd,{children:h.jsxs("div",{className:"tlui-edit-link-dialog",children:[h.jsx(pw,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:l,onComplete:u,onCancel:f}),h.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),h.jsxs(fw,{className:"tlui-dialog__footer__actions",children:[h.jsx(fe,{type:"normal",onClick:f,onTouchEnd:f,children:h.jsx(Pt,{children:o("edit-link-dialog.cancel")})}),p?h.jsx(fe,{type:"danger",onTouchEnd:d,onClick:d,children:h.jsx(Pt,{children:o("edit-link-dialog.clear")})}):h.jsx(fe,{type:"primary",disabled:!a.valid,onTouchEnd:u,onClick:u,children:h.jsx(Pt,{children:o("edit-link-dialog.save")})})]})]})});var gw={exports:{}};gw.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(c,l){if(!s[c]){s[c]={};for(var d=0;d<c.length;d++)s[c][c.charAt(d)]=d}return s[c][l]}var a={compressToBase64:function(c){if(c==null)return"";var l=a._compress(c,6,function(d){return r.charAt(d)});switch(l.length%4){default:case 0:return l;case 1:return l+"===";case 2:return l+"==";case 3:return l+"="}},decompressFromBase64:function(c){return c==null?"":c==""?null:a._decompress(c.length,32,function(l){return i(r,c.charAt(l))})},compressToUTF16:function(c){return c==null?"":a._compress(c,15,function(l){return t(l+32)})+" "},decompressFromUTF16:function(c){return c==null?"":c==""?null:a._decompress(c.length,16384,function(l){return c.charCodeAt(l)-32})},compressToUint8Array:function(c){for(var l=a.compress(c),d=new Uint8Array(l.length*2),u=0,f=l.length;u<f;u++){var p=l.charCodeAt(u);d[u*2]=p>>>8,d[u*2+1]=p%256}return d},decompressFromUint8Array:function(c){if(c==null)return a.decompress(c);for(var l=new Array(c.length/2),d=0,u=l.length;d<u;d++)l[d]=c[d*2]*256+c[d*2+1];var f=[];return l.forEach(function(p){f.push(t(p))}),a.decompress(f.join(""))},compressToEncodedURIComponent:function(c){return c==null?"":a._compress(c,6,function(l){return o.charAt(l)})},decompressFromEncodedURIComponent:function(c){return c==null?"":c==""?null:(c=c.replace(/ /g,"+"),a._decompress(c.length,32,function(l){return i(o,c.charAt(l))}))},compress:function(c){return a._compress(c,16,function(l){return t(l)})},_compress:function(c,l,d){if(c==null)return"";var u,f,p={},S={},g="",w="",y="",v=2,P=3,E=2,I=[],C=0,_=0,k;for(k=0;k<c.length;k+=1)if(g=c.charAt(k),Object.prototype.hasOwnProperty.call(p,g)||(p[g]=P++,S[g]=!0),w=y+g,Object.prototype.hasOwnProperty.call(p,w))y=w;else{if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(u=0;u<E;u++)C=C<<1,_==l-1?(_=0,I.push(d(C)),C=0):_++;for(f=y.charCodeAt(0),u=0;u<8;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1}else{for(f=1,u=0;u<E;u++)C=C<<1|f,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=0;for(f=y.charCodeAt(0),u=0;u<16;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete S[y]}else for(f=p[y],u=0;u<E;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1;v--,v==0&&(v=Math.pow(2,E),E++),p[w]=P++,y=String(g)}if(y!==""){if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(u=0;u<E;u++)C=C<<1,_==l-1?(_=0,I.push(d(C)),C=0):_++;for(f=y.charCodeAt(0),u=0;u<8;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1}else{for(f=1,u=0;u<E;u++)C=C<<1|f,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=0;for(f=y.charCodeAt(0),u=0;u<16;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete S[y]}else for(f=p[y],u=0;u<E;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1;v--,v==0&&(v=Math.pow(2,E),E++)}for(f=2,u=0;u<E;u++)C=C<<1|f&1,_==l-1?(_=0,I.push(d(C)),C=0):_++,f=f>>1;for(;;)if(C=C<<1,_==l-1){I.push(d(C));break}else _++;return I.join("")},decompress:function(c){return c==null?"":c==""?null:a._decompress(c.length,32768,function(l){return c.charCodeAt(l)})},_decompress:function(c,l,d){var u=[],f=4,p=4,S=3,g="",w=[],y,v,P,E,I,C,_,k={val:d(0),position:l,index:1};for(y=0;y<3;y+=1)u[y]=y;for(P=0,I=Math.pow(2,2),C=1;C!=I;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=d(k.index++)),P|=(E>0?1:0)*C,C<<=1;switch(P){case 0:for(P=0,I=Math.pow(2,8),C=1;C!=I;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=d(k.index++)),P|=(E>0?1:0)*C,C<<=1;_=t(P);break;case 1:for(P=0,I=Math.pow(2,16),C=1;C!=I;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=d(k.index++)),P|=(E>0?1:0)*C,C<<=1;_=t(P);break;case 2:return""}for(u[3]=_,v=_,w.push(_);;){if(k.index>c)return"";for(P=0,I=Math.pow(2,S),C=1;C!=I;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=d(k.index++)),P|=(E>0?1:0)*C,C<<=1;switch(_=P){case 0:for(P=0,I=Math.pow(2,8),C=1;C!=I;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=d(k.index++)),P|=(E>0?1:0)*C,C<<=1;u[p++]=t(P),_=p-1,f--;break;case 1:for(P=0,I=Math.pow(2,16),C=1;C!=I;)E=k.val&k.position,k.position>>=1,k.position==0&&(k.position=l,k.val=d(k.index++)),P|=(E>0?1:0)*C,C<<=1;u[p++]=t(P),_=p-1,f--;break;case 2:return w.join("")}if(f==0&&(f=Math.pow(2,S),S++),u[_])g=u[_];else if(_===p)g=v+v.charAt(0);else return null;w.push(g),u[p++]=v+g.charAt(0),f--,v=g,f==0&&(f=Math.pow(2,S),S++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(gw);var bZ=gw.exports;const fA=Qs(bZ);async function PZ(e,n,t){var y,v,P;const{elements:r,files:o}=n,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,c=e.getCurrentPageId(),l=new Map,d=[],u=new Set;r.forEach(E=>{if(l.set(E.id,Fe()),E.boundElements!==null)for(const I of E.boundElements)I.type==="text"&&u.add(I.id)});let f=t4;for(const E of r){if(u.has(E.id))continue;const I=l.get(E.id),C={id:I,typeName:"shape",parentId:c,index:f,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:CZ(E.opacity),meta:{}};switch(E.angle!==0&&a.set(I,E.angle),E.groupIds&&E.groupIds.length>0?i.has(E.groupIds[0])?(y=i.get(E.groupIds[0]))==null||y.push(I):i.set(E.groupIds[0],[I]):d.push(I),E.type){case"rectangle":case"ellipse":case"diamond":{let _="",k="middle";if(E.boundElements!==null){for(const T of E.boundElements)if(T.type==="text"){const M=r.find(R=>R.id===T.id);M&&(_=M.text,k=$Z[M.textAlign])}}const j=E.backgroundColor==="transparent"?E.strokeColor:E.backgroundColor;s.shapes.push({...C,type:"geo",props:{geo:E.type,url:E.link??"",w:E.width,h:E.height,size:eh[E.strokeWidth]??"draw",color:ul[j]??"black",text:_,align:k,dash:th(E),fill:jZ(E)}});break}case"freedraw":{s.shapes.push({...C,type:"draw",props:{dash:th(E),size:eh[E.strokeWidth],color:ul[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([_,k,j=.5])=>({x:_,y:k,z:j}))}]}});break}case"line":{if(E.points.slice().length<2)break;const k=Wl(E.points.length);s.shapes.push({...C,type:"line",props:{dash:th(E),size:eh[E.strokeWidth],color:ul[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([j,T],M)=>{const R=k[M];return[R,{id:R,index:R,x:j,y:T}]}))}}});break}case"arrow":{let _="";if(E.boundElements!==null){for(const R of E.boundElements)if(R.type==="text"){const A=r.find(O=>O.id===R.id);A&&(_=A.text)}}const k=E.points[0],j=E.points[E.points.length-1],T=l.get((v=E.startBinding)==null?void 0:v.elementId),M=l.get((P=E.endBinding)==null?void 0:P.elementId);s.shapes.push({...C,type:"arrow",props:{text:_,bend:AZ(E,k,j),dash:th(E),size:eh[E.strokeWidth]??"m",color:ul[E.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:j[0],y:j[1]},arrowheadEnd:vI[E.endArrowhead]??"none",arrowheadStart:vI[E.startArrowhead]??"none"}}),T&&s.bindings.push({id:$i(),typeName:"binding",type:"arrow",fromId:I,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),M&&s.bindings.push({id:$i(),typeName:"binding",type:"arrow",fromId:I,toId:M,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:_,scale:k}=EZ(E.fontSize);s.shapes.push({...C,type:"text",props:{size:_,scale:k,font:_Z[E.fontFamily]??"draw",color:ul[E.strokeColor]??"black",text:E.text,textAlign:MZ[E.textAlign]}});break}case"image":{const _=o[E.fileId];if(!_)break;const k=wi.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:E.width,h:E.height,fileSize:_.size,name:E.id??"Untitled",isAnimated:!1,mimeType:_.mimeType,src:_.dataURL},meta:{}}),s.shapes.push({...C,type:"image",props:{w:E.width,h:E.height,assetId:k}})}}f=Lo(f)}const p=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:p,select:!1,preserveIds:!0});for(const E of i.values())if(E.length>1){e.groupShapes(E);const I=e.getShape(E[0]);I!=null&&I.parentId&&In(I.parentId)&&d.push(I.parentId)}for(const[E,I]of a)e.select(E),e.rotateShapesBy([E],I);const S=Se(d.map(E=>e.getShape(E))),g=J.Common(S.map(E=>e.getShapePageBounds(E))),w=e.getViewportPageBounds().center;e.updateShapes(S.map(E=>{const I={x:(E.x??0)-(g.x+g.w/2),y:(E.y??0)-(g.y+g.h/2)};return{id:E.id,type:E.type,x:w.x+I.x,y:w.y+I.y}})),e.setSelectedShapes(d)}const CZ=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},eh={1:"s",2:"m",3:"l",4:"xl"},IZ={16:"s",20:"m",28:"l",36:"xl"};function EZ(e){const n=IZ[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 _Z={1:"draw",2:"sans",3:"mono"},ul={"#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"},kZ={solid:"draw",dashed:"dashed",dotted:"dotted"},TZ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},$Z={left:"start",center:"middle",right:"end"},MZ={left:"start",center:"middle",right:"end"},vI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function AZ(e,n,t){let r=0;if(e.points.length>2){const o=new b(n[0],n[1]),s=new b(t[0],t[1]),i=new b(e.points[1][0],e.points[1][1]),a=b.Sub(s,o),c=b.Per(a),l=b.Med(s,o),d=b.Sub(l,c),u=b.Add(l,c),f=b.NearestPointOnLineSegment(d,u,i,!1);r=b.Dist(f,l),b.Clockwise(f,s,l)&&(r*=-1)}return r}const th=e=>{let n=kZ[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},jZ=e=>e.backgroundColor==="transparent"?"none":TZ[e.fillStyle]??"solid";async function pA(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await go(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 OZ(e,n,t){const r=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(n,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0}),e.timers.setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1})},150))}async function Dv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await go(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),pA(e,[n]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:t,url:n,sources:r})}function DZ(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const RZ=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},LZ=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 Ok(n)},FZ=e=>/^<svg/.test(e),zZ=["input","select","textarea"];function yy(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||zZ.indexOf(n.tagName.toLowerCase())>-1)}const NZ=e=>e.types.find(n=>n.match(/^image\//)),Sy=(e,n,t,r)=>{const o=LZ(n);if(o)for(const s of o)Dv(e,s,t);else RZ(n)?Dv(e,n,t):FZ(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}))},BZ=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}}mA(e,r,t)},gA=async(e,n,t)=>{const r=[];for(const o of n){if(NZ(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const s=await o.getType("text/html");return await ki.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await ki.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await ki.blobToText(s)})()})}return await mA(e,r,t)};async function mA(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 pA(e,i,t)}const o=await Promise.all(n.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(c=>{var d;const l=(d=c.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:d[1];if(l)try{const u=fA.decompressFromBase64(l);if(u===null){i({type:"error",data:u,reason:"found tldraw data comment but could not parse base64"});return}else{const f=JSON.parse(u);if(f.type!=="application/tldraw"&&i({type:"error",data:f,reason:`found tldraw data comment but JSON was of a different type: ${f.type}`}),typeof f.data=="string"){i({type:"error",data:f,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:f.data});return}}catch{i({type:"error",data:l,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:c,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:c,subtype:"url"});return}try{const u=JSON.parse(c);if(u.type==="excalidraw/clipboard"){i({type:"excalidraw",data:u});return}else{i({type:"text",data:c,subtype:"json"});return}}catch{i({type:"text",data:c,subtype:"text"});return}}i({type:"error",data:c,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){OZ(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){PZ(e,s.data,t);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(l=>l.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const l=a.firstElementChild.getAttribute("href");Sy(e,l,t,o);return}if(!o.some(l=>l.type==="text"&&l.subtype!=="html")&&s.data.trim()){Sy(e,DZ(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){Dv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){Sy(e,s.data,t,o);return}}const mp=async e=>{var r;const n=await e.resolveAssetsInContent(e.getContentFromCurrentPage(e.getSelectedShapeIds()));if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=fA.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(u4);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 UZ(){const e=N(),n=Yr(),t=x.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await mp(e),n("copy",{source:i}))},[e,n]),r=x.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await mp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=x.useCallback(async function(i,a,c){e.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(gA(e,i,c),n("paste",{source:"menu"})):navigator.clipboard.read().then(l=>{o(l,a,c)}))},[e,n]);return{copy:t,cut:r,paste:o}}function HZ(){const e=N(),n=Yr(),t=W("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!t)return;const r=async c=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||yy(e)||(_e(c),await mp(e),n("copy",{source:"kbd"}))};async function o(c){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||yy(e)||(_e(c),await mp(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=c=>{c.button===1&&(s=!0,e.timers.requestAnimationFrame(()=>{s=!1}))},a=c=>{if(s){Kt(c);return}e.getEditingShapeId()!==null||yy(e)||(c.clipboardData&&!e.inputs.shiftKey?BZ(e,c.clipboardData):navigator.clipboard.read().then(l=>{Array.isArray(l)&&l[0]instanceof ClipboardItem&&gA(e,l,e.inputs.currentPagePoint)}),_e(c),n("paste",{source:"kbd"}))};return document.addEventListener("copy",r),document.addEventListener("cut",o),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[e,n,t])}async function yA(e,n,t){const{type:r,quality:o,scale:s,width:i,height:a}=t;let[c,l]=await IG(i*s,a*s);c=Math.floor(c),l=Math.floor(l);const d=c/i,u=URL.createObjectURL(new Blob([n],{type:"image/svg+xml"})),f=await new Promise(S=>{const g=oc();g.crossOrigin="anonymous",g.onload=async()=>{e.environment.isSafari&&await new Promise(v=>e.timers.setTimeout(v,250));const w=document.createElement("canvas"),y=w.getContext("2d");w.width=c,w.height=l,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(g,0,0,c,l),URL.revokeObjectURL(u),S(w)},g.onerror=()=>{S(null)},g.src=u});if(!f)return null;const p=await new Promise(S=>f.toBlob(g=>{(!g||wt.throwToBlob.get())&&S(null),S(g)},"image/"+r,o));if(!p)return null;if(r==="png"){const S=new DataView(await p.arrayBuffer());return no.setPhysChunk(S,d,{type:"image/"+r})}else return p}async function SA(e,n,t){const r=await e.getSvgString(n!=null&&n.length?n:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...t});if(!r)throw new Error("Could not construct SVG.");return r}async function Rv(e,n,t,r={}){var o;switch(t){case"svg":return(o=await SA(e,n,r))==null?void 0:o.svg;case"json":{const s=await e.resolveAssetsInContent(e.getContentFromCurrentPage(n));return JSON.stringify(s)}default:sn(t)}}async function vA({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await Rv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Rv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await SA(e,n,r);if(!o)throw new Error("Could not construct image.");const s=await yA(e,o.svg,{type:t,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:sn(t)}}const KZ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function WZ(e,n,t,r={}){return{blobPromise:vA({editor:e,ids:n,format:t,opts:r}),mimeType:KZ[t]}}function GZ(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}=WZ(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 VZ(async()=>Rv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:sn(t)}}async function VZ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}function YZ(){const e=N(),{addToast:n}=Xr(),t=$e();return x.useCallback((r,o="svg")=>{GZ(e,r,o).catch(()=>{n({id:"copy-fail",severity:"warning",title:t("toast.error.copy-fail.title"),description:t("toast.error.copy-fail.desc")})})},[e,n,t])}async function XZ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${xI()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${xI()}`}r+=`.${t}`;const s=await vA({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});qZ(i)}function xI(){const e=new Date,n=String(e.getFullYear()).slice(2),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return`${n}-${t}-${r} ${o}.${s}.${i}`}function qZ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function ZZ(){const e=N(),{addToast:n}=Xr(),t=$e();return x.useCallback((r,o="png",s)=>{XZ(e,r,o,s,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),n({id:"export-fail",title:t("toast.error.export-fail.title"),description:t("toast.error.export-fail.desc"),severity:"error"})})},[e,n,t])}async function QZ(e,n,t){const r=Se(n.map(a=>{const c=e.getShape(a);if(!(!c||e.getShapeUtil(c.type).toSvg===void 0))return c}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||e.isShapeOfType(a,"image"))return}const o=[];if(t!==void 0){const a=r.map(c=>({shape:c,bounds:e.getShapeMaskedPageBounds(c).clone().expandBy(t)}));for(let c=0;c<a.length;c++){const l=a[c];if(c===0){o[0]={shapes:[l.shape],bounds:l.bounds};continue}let d=!1;for(const u of o)if(u.bounds.includes(l.bounds)){u.shapes.push(l.shape),u.bounds.expand(l.bounds),d=!0;break}d||o.push({shapes:[l.shape],bounds:l.bounds})}}else{const a=J.Common(r.map(c=>e.getShapeMaskedPageBounds(c)));o.push({shapes:r,bounds:a})}const s=e.options.flattenImageBoundsPadding;for(const a of o){t!==void 0&&a.bounds.expandBy(-t);const c=await e.getSvgString(a.shapes,{padding:s});if(!(c!=null&&c.svg))continue;const l=new Blob([c.svg],{type:"image/svg+xml"}),d=await e.getAssetForExternalContent({type:"file",file:new File([l],"asset.svg",{type:"image/svg+xml"})});d&&(a.asset=d)}const i=[];return As(()=>{for(const a of o){const{asset:c,bounds:l,shapes:d}=a;if(!c)continue;const u=e.findCommonAncestor(d)??e.getCurrentPageId();if(!u)continue;let f="a1";for(const y of d)if(y.parentId===u){y.index>f&&(f=y.index);break}let p,S,g;if(In(u)){const y=e.getShape(u);if(!y)continue;const v=e.getPointInShapeSpace(y,{x:l.x,y:l.y});g=e.getShapePageTransform(u).rotation(),v.sub(new b(s,s).rot(-g)),p=v.x,S=v.y}else p=l.x-s,S=l.y-s,g=0;e.deleteShapes(d),e.createAssets([{...c,id:c.id}]);const w=Fe();e.createShape({id:w,type:"image",index:f,parentId:u,x:p,y:S,rotation:-g,props:{assetId:c.id,w:l.w+s*2,h:l.h+s*2}}),i.push(w)}}),i}function JZ(){const e=N(),n=x.useRef(null),t=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(y,v)=>{y&&(y.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),y&&document.body.contains(y)&&document.body.removeChild(y)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${st()}`;o.className=a,s.innerHTML=`
|
|
199
|
-
.${a} {
|
|
200
|
-
display: none;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.${a} svg {
|
|
204
|
-
max-width: 100%;
|
|
205
|
-
height: 100%;
|
|
206
|
-
display: block;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
@media print {
|
|
210
|
-
html, body {
|
|
211
|
-
min-height: 100%;
|
|
212
|
-
height: 100%;
|
|
213
|
-
margin: 0;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
body {
|
|
217
|
-
position: relative;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
body > * {
|
|
221
|
-
display: none;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
.tldraw__editor {
|
|
225
|
-
display: none;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
.${a} {
|
|
229
|
-
display: block !important;
|
|
230
|
-
background: white;
|
|
231
|
-
min-height: 100%;
|
|
232
|
-
height: 100%;
|
|
233
|
-
max-width: 100%;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
.${a}__item {
|
|
237
|
-
padding: 10mm;
|
|
238
|
-
display: flex;
|
|
239
|
-
min-height: 100%;
|
|
240
|
-
flex-direction: column;
|
|
241
|
-
page-break-after: always;
|
|
242
|
-
position: relative;
|
|
243
|
-
overflow: hidden;
|
|
244
|
-
height: 100%;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
.${a}__item__main {
|
|
248
|
-
flex: 1;
|
|
249
|
-
display: flex;
|
|
250
|
-
align-items: center;
|
|
251
|
-
justify-content: center;
|
|
252
|
-
max-height: 100%;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
.${a}__item__header {
|
|
256
|
-
display: none;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
.${a}__item__footer {
|
|
260
|
-
display: none;
|
|
261
|
-
text-align: right;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
.${a}__item__footer__hide {
|
|
265
|
-
display: none;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
`;const c=()=>{document.head.appendChild(s),document.body.appendChild(o)},l=()=>{e.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",c),window.addEventListener("afterprint",l);function d(y,v,P){try{o.innerHTML+=`<div class="${a}__item">
|
|
272
|
-
<div class="${a}__item__header">
|
|
273
|
-
${y.replace(/</g,"<").replace(/>/g,">")}
|
|
274
|
-
</div>
|
|
275
|
-
<div class="${a}__item__main">
|
|
276
|
-
${P}
|
|
277
|
-
</div>
|
|
278
|
-
<div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
|
|
279
|
-
${v??""}
|
|
280
|
-
</div>
|
|
281
|
-
</div>`}catch(E){console.error(E)}}function u(){e.environment.isChromeForIos?(c(),window.print()):e.environment.isSafari?(c(),document.execCommand("print",!1)):window.print()}const f=e.getSelectedShapeIds(),p=e.getCurrentPageId(),S=e.getPages(),w={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const y=await e.getSvgString(f,w);if(y){const v=S.find(P=>P.id===p);d(`tldraw — ${v==null?void 0:v.name}`,null,y.svg),u()}}else{const y=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(y.id),w);v&&(d(`tldraw — ${y.name}`,null,v.svg),u())}window.removeEventListener("beforeprint",c),window.removeEventListener("afterprint",l)},[e])}const xA=x.createContext(null);function eQ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function xa(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function tQ({overrides:e,children:n}){const t=N(),{addDialog:r,clearDialogs:o}=sa(),{clearToasts:s}=Xr(),i=$e(),a=lA(),c=JZ(),{cut:l,copy:d,paste:u}=UZ(),f=YZ(),p=ZZ(),S=i("document.default-name"),g=Yr(),w=x.useMemo(()=>{function y(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function v(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const E=eQ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(I){v()&&(y()||(g("edit-link",{source:I}),t.mark("edit-link"),r({component:xZ})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(I){g("insert-embed",{source:I}),r({component:cA})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(I){g("insert-media",{source:I}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(I){g("undo",{source:I}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(I){g("redo",{source:I}),t.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-as",{format:"svg",source:I}),p(C,"svg",xa(t,S)))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-as",{format:"png",source:I}),p(C,"png",xa(t,S)))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-as",{format:"json",source:I}),p(C,"json",xa(t,S)))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("export-all-as",{format:"svg",source:I}),p(Array.from(t.getCurrentPageShapeIds()),"svg",xa(t,S)))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(I){const C=Array.from(t.getCurrentPageShapeIds().values());C.length!==0&&(g("export-all-as",{format:"png",source:I}),p(C,"png",xa(t,S)))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(I){const C=Array.from(t.getCurrentPageShapeIds().values());C.length!==0&&(g("export-all-as",{format:"json",source:I}),p(C,"json",xa(t,S)))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("copy-as",{format:"svg",source:I}),f(C,"svg"))}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("copy-as",{format:"png",source:I}),f(C,"png"))}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(I){let C=t.getSelectedShapeIds();C.length===0&&(C=Array.from(t.getCurrentPageShapeIds().values())),C.length!==0&&(g("copy-as",{format:"json",source:I}),f(C,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(I){if(!v()||y())return;g("toggle-auto-size",{source:I}),t.mark("toggling auto size");const C=t.getSelectedShapes().filter(_=>t.isShapeOfType(_,"text")&&_.props.autoSize===!1);t.updateShapes(C.map(_=>({id:_.id,type:_.type,props:{..._.props,w:8,autoSize:!0}}))),We(t,C.map(_=>_.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(I){g("open-embed-link",{source:I});const C=t.getSelectedShapeIds(),_="No embed shapes selected";if(C.length!==1){console.error(_);return}const k=t.getShape(C[0]);if(!k||!t.isShapeOfType(k,"embed")){console.error(_);return}UW(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(I){var C,_;if(((C=t.root.getCurrent())==null?void 0:C.id)!=="zoom"&&(g("zoom-tool",{source:I}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const k=t.root.getCurrent();k&&((_=k.getCurrent())==null?void 0:_.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(I){v()&&(y()||t.batch(()=>{g("convert-to-bookmark",{source:I});const C=t.getSelectedShapes(),_=[],k=[];for(const j of C){if(!j||!t.isShapeOfType(j,"embed")||!j.props.url)continue;const T=new b(j.x,j.y);T.rot(-j.rotation),T.add(new b(j.props.w/2-300/2,j.props.h/2-320/2)),T.rot(j.rotation);const M={id:Fe(),type:"bookmark",rotation:j.rotation,x:T.x,y:T.y,opacity:1,props:{url:j.props.url}};_.push(M),k.push(j.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(k),t.createShapes(_)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(I){v()&&(y()||(g("convert-to-embed",{source:I}),t.batch(()=>{const C=t.getSelectedShapeIds(),_=Se(C.map(T=>t.getShape(T))),k=[],j=[];for(const T of _){if(!t.isShapeOfType(T,"bookmark"))continue;const{url:M}=T.props,R=Ms(T.props.url);if(!R||!R.definition)continue;const{width:A,height:O}=R.definition,L=new b(T.x,T.y);L.rot(-T.rotation),L.add(new b(T.props.w/2-A/2,T.props.h/2-O/2)),L.rot(T.rotation);const G={id:Fe(),type:"embed",x:L.x,y:L.y,rotation:T.rotation,props:{url:M,w:A,h:O}};k.push(G),j.push(T.id)}t.mark("convert shapes to embed"),t.deleteShapes(j),t.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(I){if(!v()||y())return;g("duplicate-shapes",{source:I});const C=t.getInstanceState();let _,k;if(C.duplicateProps)_=C.duplicateProps.shapeIds,k=C.duplicateProps.offset;else{_=t.getSelectedShapeIds();const j=J.Common(Se(_.map(T=>t.getShapePageBounds(T))));k=t.getCameraOptions().isLocked?{x:20,y:20}:{x:j.width+20,y:0}}t.mark("duplicate shapes"),t.duplicateShapes(_,k),C.duplicateProps&&t.updateInstanceState({duplicateProps:{...C.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(I){v()&&(y()||(g("ungroup-shapes",{source:I}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(I){if(!v()||y())return;g("group-shapes",{source:I});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",onSelect(I){if(!v())return;g("remove-frame",{source:I});const C=t.getSelectedShapes();C.length>0&&C.every(_=>t.isShapeOfType(_,"frame"))&&(t.mark("remove-frame"),yZ(t,C.map(_=>_.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(I){if(!v())return;g("fit-frame-to-content",{source:I});const C=t.getOnlySelectedShape();C&&t.isShapeOfType(C,"frame")&&(t.mark("fit-frame-to-content"),vZ(t,C.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"left",source:I}),t.mark("align left");const C=t.getSelectedShapeIds();t.alignShapes(C,"left"),We(t,C)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"center-horizontal",source:I}),t.mark("align center horizontal");const C=t.getSelectedShapeIds();t.alignShapes(C,"center-horizontal"),We(t,C)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"right",source:I}),t.mark("align right");const C=t.getSelectedShapeIds();t.alignShapes(C,"right"),We(t,C)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"center-vertical",source:I}),t.mark("align center vertical");const C=t.getSelectedShapeIds();t.alignShapes(C,"center-vertical"),We(t,C)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"top",source:I}),t.mark("align top");const C=t.getSelectedShapeIds();t.alignShapes(C,"top"),We(t,C)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(I){if(!v()||y())return;g("align-shapes",{operation:"bottom",source:I}),t.mark("align bottom");const C=t.getSelectedShapeIds();t.alignShapes(C,"bottom"),We(t,C)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(I){if(!v()||y())return;g("distribute-shapes",{operation:"horizontal",source:I}),t.mark("distribute horizontal");const C=t.getSelectedShapeIds();t.distributeShapes(C,"horizontal"),We(t,C)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(I){if(!v()||y())return;g("distribute-shapes",{operation:"vertical",source:I}),t.mark("distribute vertical");const C=t.getSelectedShapeIds();t.distributeShapes(C,"vertical"),We(t,C)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(I){if(!v()||y())return;g("stretch-shapes",{operation:"horizontal",source:I}),t.mark("stretch horizontal");const C=t.getSelectedShapeIds();t.stretchShapes(C,"horizontal"),We(t,C)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(I){if(!v()||y())return;g("stretch-shapes",{operation:"vertical",source:I}),t.mark("stretch vertical");const C=t.getSelectedShapeIds();t.stretchShapes(C,"vertical"),We(t,C)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(I){if(!v()||y())return;g("flip-shapes",{operation:"horizontal",source:I}),t.mark("flip horizontal");const C=t.getSelectedShapeIds();t.flipShapes(C,"horizontal"),We(t,C)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(I){if(!v()||y())return;g("flip-shapes",{operation:"vertical",source:I}),t.mark("flip vertical");const C=t.getSelectedShapeIds();t.flipShapes(C,"vertical"),We(t,C)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(I){if(!v()||y())return;g("pack-shapes",{source:I}),t.mark("pack");const C=t.getSelectedShapeIds();t.packShapes(C,t.options.adjacentShapeMargin),We(t,C)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(I){if(!v()||y())return;g("stack-shapes",{operation:"vertical",source:I}),t.mark("stack-vertical");const C=t.getSelectedShapeIds();t.stackShapes(C,"vertical",16),We(t,C)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(I){if(!v()||y())return;g("stack-shapes",{operation:"horizontal",source:I}),t.mark("stack-horizontal");const C=t.getSelectedShapeIds();t.stackShapes(C,"horizontal",16),We(t,C)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"toFront",source:I}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"forward",source:I}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"backward",source:I}),t.mark("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(I){v()&&(y()||(g("reorder-shapes",{operation:"toBack",source:I}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(I){v()&&(y()||(t.mark("cut"),l(I)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(I){v()&&(y()||d(I))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(I){var C;(C=navigator.clipboard)==null||C.read().then(_=>{u(_,I,I==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(I){t.batch(()=>{y()||(g("select-all-shapes",{source:I}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(I){v()&&(y()||(g("select-none-shapes",{source:I}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(I){v()&&(y()||(g("delete-shapes",{source:I}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(I){if(!v()||y())return;g("rotate-cw",{source:I}),t.mark("rotate-cw");const C=t.getSelectionRotation()%(Ve/2),_=Os(C,0)||Os(C,Ve/2),k=t.getSelectedShapeIds();t.rotateShapesBy(k,Ve/2-(_?0:C)),We(t,k)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(I){if(!v()||y())return;g("rotate-ccw",{source:I}),t.mark("rotate-ccw");const C=t.getSelectionRotation()%(Ve/2),_=Os(C,0),k=t.getSelectedShapeIds();t.rotateShapesBy(k,_?-(Ve/2):-C),We(t,k)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(I){g("zoom-in",{source:I}),t.zoomIn(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(I){g("zoom-out",{source:I}),t.zoomOut(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(I){g("reset-zoom",{source:I}),t.resetZoom(void 0,{animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(I){g("zoom-to-fit",{source:I}),t.zoomToFit({animation:{duration:t.options.animationMediumMs}})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(I){v()&&(y()||(g("zoom-to-selection",{source:I}),t.zoomToSelection({animation:{duration:t.options.animationMediumMs}})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(I){g("toggle-snap-mode",{source:I}),t.user.updateUserPreferences({isSnapMode:!t.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(I){const C=t.user.getIsDarkMode()?"light":"dark";g("color-scheme",{source:I,value:C}),t.user.updateUserPreferences({colorScheme:C})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(I){g("toggle-wrap-mode",{source:I}),t.user.updateUserPreferences({isWrapMode:!t.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-dynamic-size-mode",label:{default:"action.toggle-dynamic-size-mode",menu:"action.toggle-dynamic-size-mode.menu"},readonlyOk:!1,onSelect(I){g("toggle-dynamic-size-mode",{source:I}),t.user.updateUserPreferences({isDynamicSizeMode:!t.user.getIsDynamicResizeMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(I){g("toggle-reduce-motion",{source:I}),t.user.updateUserPreferences({animationSpeed:t.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(I){g("toggle-edge-scrolling",{source:I}),t.user.updateUserPreferences({edgeScrollSpeed:t.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(I){g("toggle-transparent",{source:I}),t.updateInstanceState({exportBackground:!t.getInstanceState().exportBackground})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(I){g("toggle-tool-lock",{source:I}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(I){g("unlock-all",{source:I});const C=[];for(const _ of t.getCurrentPageShapes())_.isLocked&&C.push({id:_.id,type:_.type,isLocked:!1});C.length>0&&t.updateShapes(C)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(I){t.timers.requestAnimationFrame(()=>{t.batch(()=>{g("toggle-focus-mode",{source:I}),o(),s(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(I){g("toggle-grid-mode",{source:I}),t.updateInstanceState({isGridMode:!t.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(I){g("toggle-debug-mode",{source:I}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(I){g("print",{source:I}),c()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(I){g("exit-pen-mode",{source:I}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(I){g("stop-following",{source:I}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(I){g("zoom-to-content",{source:I});const C=t.getSelectionPageBounds()??t.getCurrentPageBounds();C&&t.zoomToBounds(C,{targetZoom:Math.min(1,t.getZoomLevel()),animation:{duration:220}})}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(I){t.mark("locking"),g("toggle-lock",{source:I}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(I){const C=Xo.createId(),_=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:i("page-menu.new-page-initial-name"),id:C}),t.moveShapesToPage(_,C)}),g("new-page",{source:I})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(I){const C=rr;t.batch(()=>{t.mark("change-color"),t.isIn("select")&&t.setStyleForSelectedShapes(C,"white"),t.setStyleForNextShapes(C,"white")}),g("set-style",{source:I,id:C.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(I){const C=Li;t.batch(()=>{t.mark("change-fill"),t.isIn("select")&&t.setStyleForSelectedShapes(C,"fill"),t.setStyleForNextShapes(C,"fill")}),g("set-style",{source:I,id:C.id,value:"fill"})}},{id:"flatten-to-image",label:"action.flatten-to-image",kbd:"!f",onSelect:async I=>{const C=t.getSelectedShapeIds();if(C.length===0)return;t.mark("flattening to image"),g("flatten-to-image",{source:I});const _=await QZ(t,C,t.options.flattenImageBoundsExpand);_!=null&&_.length&&t.setSelectedShapes(_)}}]);return e?e(t,E,void 0):E},[t,g,e,r,a,p,f,l,d,u,o,s,c,i,S]);return h.jsx(xA.Provider,{value:w,children:n})}function ae(){const e=x.useContext(xA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function gd(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const nQ=["top","right","bottom","left"],co=Math.min,Yn=Math.max,yp=Math.round,nh=Math.floor,qs=e=>({x:e,y:e}),rQ={left:"right",right:"left",bottom:"top",top:"bottom"},oQ={start:"end",end:"start"};function Lv(e,n,t){return Yn(e,co(n,t))}function ts(e,n){return typeof e=="function"?e(n):e}function ns(e){return e.split("-")[0]}function Dc(e){return e.split("-")[1]}function mw(e){return e==="x"?"y":"x"}function yw(e){return e==="y"?"height":"width"}function Rc(e){return["top","bottom"].includes(ns(e))?"y":"x"}function Sw(e){return mw(Rc(e))}function sQ(e,n,t){t===void 0&&(t=!1);const r=Dc(e),o=Sw(e),s=yw(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=Sp(i)),[i,Sp(i)]}function iQ(e){const n=Sp(e);return[Fv(e),n,Fv(n)]}function Fv(e){return e.replace(/start|end/g,n=>oQ[n])}function aQ(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 cQ(e,n,t,r){const o=Dc(e);let s=aQ(ns(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(Fv)))),s}function Sp(e){return e.replace(/left|right|bottom|top/g,n=>rQ[n])}function lQ(e){return{top:0,right:0,bottom:0,left:0,...e}}function wA(e){return typeof e!="number"?lQ(e):{top:e,right:e,bottom:e,left:e}}function vp(e){const{x:n,y:t,width:r,height:o}=e;return{width:r,height:o,top:t,left:n,right:n+r,bottom:t+o,x:n,y:t}}function wI(e,n,t){let{reference:r,floating:o}=e;const s=Rc(n),i=Sw(n),a=yw(i),c=ns(n),l=s==="y",d=r.x+r.width/2-o.width/2,u=r.y+r.height/2-o.height/2,f=r[a]/2-o[a]/2;let p;switch(c){case"top":p={x:d,y:r.y-o.height};break;case"bottom":p={x:d,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:u};break;case"left":p={x:r.x-o.width,y:u};break;default:p={x:r.x,y:r.y}}switch(Dc(n)){case"start":p[i]-=f*(t&&l?-1:1);break;case"end":p[i]+=f*(t&&l?-1:1);break}return p}const dQ=async(e,n,t)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=t,a=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(n));let l=await i.getElementRects({reference:e,floating:n,strategy:o}),{x:d,y:u}=wI(l,r,c),f=r,p={},S=0;for(let g=0;g<a.length;g++){const{name:w,fn:y}=a[g],{x:v,y:P,data:E,reset:I}=await y({x:d,y:u,initialPlacement:r,placement:f,strategy:o,middlewareData:p,rects:l,platform:i,elements:{reference:e,floating:n}});d=v??d,u=P??u,p={...p,[w]:{...p[w],...E}},I&&S<=50&&(S++,typeof I=="object"&&(I.placement&&(f=I.placement),I.rects&&(l=I.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):I.rects),{x:d,y:u}=wI(l,f,c)),g=-1)}return{x:d,y:u,placement:f,strategy:o,middlewareData:p}};async function md(e,n){var t;n===void 0&&(n={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:c}=e,{boundary:l="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:f=!1,padding:p=0}=ts(n,e),S=wA(p),w=a[f?u==="floating"?"reference":"floating":u],y=vp(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(w)))==null||t?w:w.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:l,rootBoundary:d,strategy:c})),v=u==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,P=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(P))?await(s.getScale==null?void 0:s.getScale(P))||{x:1,y:1}:{x:1,y:1},I=vp(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:P,strategy:c}):v);return{top:(y.top-I.top+S.top)/E.y,bottom:(I.bottom-y.bottom+S.bottom)/E.y,left:(y.left-I.left+S.left)/E.x,right:(I.right-y.right+S.right)/E.x}}const uQ=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:c}=n,{element:l,padding:d=0}=ts(e,n)||{};if(l==null)return{};const u=wA(d),f={x:t,y:r},p=Sw(o),S=yw(p),g=await i.getDimensions(l),w=p==="y",y=w?"top":"left",v=w?"bottom":"right",P=w?"clientHeight":"clientWidth",E=s.reference[S]+s.reference[p]-f[p]-s.floating[S],I=f[p]-s.reference[p],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(l));let _=C?C[P]:0;(!_||!await(i.isElement==null?void 0:i.isElement(C)))&&(_=a.floating[P]||s.floating[S]);const k=E/2-I/2,j=_/2-g[S]/2-1,T=co(u[y],j),M=co(u[v],j),R=T,A=_-g[S]-M,O=_/2-g[S]/2+k,L=Lv(R,O,A),G=!c.arrow&&Dc(o)!=null&&O!==L&&s.reference[S]/2-(O<R?T:M)-g[S]/2<0,K=G?O<R?O-R:O-A:0;return{[p]:f[p]+K,data:{[p]:L,centerOffset:O-L-K,...G&&{alignmentOffset:K}},reset:G}}}),hQ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var t,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:c,elements:l}=n,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:g=!0,...w}=ts(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const y=ns(o),v=ns(a)===a,P=await(c.isRTL==null?void 0:c.isRTL(l.floating)),E=f||(v||!g?[Sp(a)]:iQ(a));!f&&S!=="none"&&E.push(...cQ(a,g,S,P));const I=[a,...E],C=await md(n,w),_=[];let k=((r=s.flip)==null?void 0:r.overflows)||[];if(d&&_.push(C[y]),u){const R=sQ(o,i,P);_.push(C[R[0]],C[R[1]])}if(k=[...k,{placement:o,overflows:_}],!_.every(R=>R<=0)){var j,T;const R=(((j=s.flip)==null?void 0:j.index)||0)+1,A=I[R];if(A)return{data:{index:R,overflows:k},reset:{placement:A}};let O=(T=k.filter(L=>L.overflows[0]<=0).sort((L,G)=>L.overflows[1]-G.overflows[1])[0])==null?void 0:T.placement;if(!O)switch(p){case"bestFit":{var M;const L=(M=k.map(G=>[G.placement,G.overflows.filter(K=>K>0).reduce((K,B)=>K+B,0)]).sort((G,K)=>G[1]-K[1])[0])==null?void 0:M[0];L&&(O=L);break}case"initialPlacement":O=a;break}if(o!==O)return{reset:{placement:O}}}return{}}}};function bI(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function PI(e){return nQ.some(n=>e[n]>=0)}const fQ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(n){const{rects:t}=n,{strategy:r="referenceHidden",...o}=ts(e,n);switch(r){case"referenceHidden":{const s=await md(n,{...o,elementContext:"reference"}),i=bI(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:PI(i)}}}case"escaped":{const s=await md(n,{...o,altBoundary:!0}),i=bI(s,t.floating);return{data:{escapedOffsets:i,escaped:PI(i)}}}default:return{}}}}};async function pQ(e,n){const{placement:t,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=ns(t),a=Dc(t),c=Rc(t)==="y",l=["left","top"].includes(i)?-1:1,d=s&&c?-1:1,u=ts(n,e);let{mainAxis:f,crossAxis:p,alignmentAxis:S}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...u};return a&&typeof S=="number"&&(p=a==="end"?S*-1:S),c?{x:p*d,y:f*l}:{x:f*l,y:p*d}}const gQ=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var t,r;const{x:o,y:s,placement:i,middlewareData:a}=n,c=await pQ(n,e);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+c.x,y:s+c.y,data:{...c,placement:i}}}}},mQ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(n){const{x:t,y:r,placement:o}=n,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:w=>{let{x:y,y:v}=w;return{x:y,y:v}}},...c}=ts(e,n),l={x:t,y:r},d=await md(n,c),u=Rc(ns(o)),f=mw(u);let p=l[f],S=l[u];if(s){const w=f==="y"?"top":"left",y=f==="y"?"bottom":"right",v=p+d[w],P=p-d[y];p=Lv(v,p,P)}if(i){const w=u==="y"?"top":"left",y=u==="y"?"bottom":"right",v=S+d[w],P=S-d[y];S=Lv(v,S,P)}const g=a.fn({...n,[f]:p,[u]:S});return{...g,data:{x:g.x-t,y:g.y-r}}}}},yQ=function(e){return e===void 0&&(e={}),{options:e,fn(n){const{x:t,y:r,placement:o,rects:s,middlewareData:i}=n,{offset:a=0,mainAxis:c=!0,crossAxis:l=!0}=ts(e,n),d={x:t,y:r},u=Rc(o),f=mw(u);let p=d[f],S=d[u];const g=ts(a,n),w=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(c){const P=f==="y"?"height":"width",E=s.reference[f]-s.floating[P]+w.mainAxis,I=s.reference[f]+s.reference[P]-w.mainAxis;p<E?p=E:p>I&&(p=I)}if(l){var y,v;const P=f==="y"?"width":"height",E=["top","left"].includes(ns(o)),I=s.reference[u]-s.floating[P]+(E&&((y=i.offset)==null?void 0:y[u])||0)+(E?0:w.crossAxis),C=s.reference[u]+s.reference[P]+(E?0:((v=i.offset)==null?void 0:v[u])||0)-(E?w.crossAxis:0);S<I?S=I:S>C&&(S=C)}return{[f]:p,[u]:S}}}},SQ=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}=ts(e,n),c=await md(n,a),l=ns(t),d=Dc(t),u=Rc(t)==="y",{width:f,height:p}=r.floating;let S,g;l==="top"||l==="bottom"?(S=l,g=d===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(g=l,S=d==="end"?"top":"bottom");const w=p-c.top-c.bottom,y=f-c.left-c.right,v=co(p-c[S],w),P=co(f-c[g],y),E=!n.middlewareData.shift;let I=v,C=P;if(u?C=d||E?co(P,y):y:I=d||E?co(v,w):w,E&&!d){const k=Yn(c.left,0),j=Yn(c.right,0),T=Yn(c.top,0),M=Yn(c.bottom,0);u?C=f-2*(k!==0||j!==0?k+j:Yn(c.left,c.right)):I=p-2*(T!==0||M!==0?T+M:Yn(c.top,c.bottom))}await i({...n,availableWidth:C,availableHeight:I});const _=await o.getDimensions(s.floating);return f!==_.width||p!==_.height?{reset:{rects:!0}}:{}}}};function Lc(e){return bA(e)?(e.nodeName||"").toLowerCase():"#document"}function tr(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function ls(e){var n;return(n=(bA(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function bA(e){return e instanceof Node||e instanceof tr(e).Node}function vo(e){return e instanceof Element||e instanceof tr(e).Element}function xo(e){return e instanceof HTMLElement||e instanceof tr(e).HTMLElement}function CI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof tr(e).ShadowRoot}function Wd(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=Kr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function vQ(e){return["table","td","th"].includes(Lc(e))}function vw(e){const n=xw(),t=Kr(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 xQ(e){let n=Zs(e);for(;xo(n)&&!wc(n);){if(vw(n))return n;n=Zs(n)}return null}function xw(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function wc(e){return["html","body","#document"].includes(Lc(e))}function Kr(e){return tr(e).getComputedStyle(e)}function wg(e){return vo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Zs(e){if(Lc(e)==="html")return e;const n=e.assignedSlot||e.parentNode||CI(e)&&e.host||ls(e);return CI(n)?n.host:n}function PA(e){const n=Zs(e);return wc(n)?e.ownerDocument?e.ownerDocument.body:e.body:xo(n)&&Wd(n)?n:PA(n)}function yd(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=PA(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=tr(o);return s?n.concat(i,i.visualViewport||[],Wd(o)?o:[],i.frameElement&&t?yd(i.frameElement):[]):n.concat(o,yd(o,[],t))}function CA(e){const n=Kr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=xo(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=yp(t)!==s||yp(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function ww(e){return vo(e)?e:e.contextElement}function rc(e){const n=ww(e);if(!xo(n))return qs(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=CA(n);let i=(s?yp(t.width):t.width)/r,a=(s?yp(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const wQ=qs(0);function IA(e){const n=tr(e);return!xw()||!n.visualViewport?wQ:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function bQ(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==tr(e)?!1:n}function Yi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=ww(e);let i=qs(1);n&&(r?vo(r)&&(i=rc(r)):i=rc(e));const a=bQ(s,t,r)?IA(s):qs(0);let c=(o.left+a.x)/i.x,l=(o.top+a.y)/i.y,d=o.width/i.x,u=o.height/i.y;if(s){const f=tr(s),p=r&&vo(r)?tr(r):r;let S=f,g=S.frameElement;for(;g&&r&&p!==S;){const w=rc(g),y=g.getBoundingClientRect(),v=Kr(g),P=y.left+(g.clientLeft+parseFloat(v.paddingLeft))*w.x,E=y.top+(g.clientTop+parseFloat(v.paddingTop))*w.y;c*=w.x,l*=w.y,d*=w.x,u*=w.y,c+=P,l+=E,S=tr(g),g=S.frameElement}}return vp({width:d,height:u,x:c,y:l})}const PQ=[":popover-open",":modal"];function bw(e){return PQ.some(n=>{try{return e.matches(n)}catch{return!1}})}function CQ(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=ls(r),a=n?bw(n.floating):!1;if(r===i||a&&s)return t;let c={scrollLeft:0,scrollTop:0},l=qs(1);const d=qs(0),u=xo(r);if((u||!u&&!s)&&((Lc(r)!=="body"||Wd(i))&&(c=wg(r)),xo(r))){const f=Yi(r);l=rc(r),d.x=f.x+r.clientLeft,d.y=f.y+r.clientTop}return{width:t.width*l.x,height:t.height*l.y,x:t.x*l.x-c.scrollLeft*l.x+d.x,y:t.y*l.y-c.scrollTop*l.y+d.y}}function IQ(e){return Array.from(e.getClientRects())}function EA(e){return Yi(ls(e)).left+wg(e).scrollLeft}function EQ(e){const n=ls(e),t=wg(e),r=e.ownerDocument.body,o=Yn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=Yn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+EA(e);const a=-t.scrollTop;return Kr(r).direction==="rtl"&&(i+=Yn(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function _Q(e,n){const t=tr(e),r=ls(e),o=t.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,c=0;if(o){s=o.width,i=o.height;const l=xw();(!l||l&&n==="fixed")&&(a=o.offsetLeft,c=o.offsetTop)}return{width:s,height:i,x:a,y:c}}function kQ(e,n){const t=Yi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=xo(e)?rc(e):qs(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,c=o*s.x,l=r*s.y;return{width:i,height:a,x:c,y:l}}function II(e,n,t){let r;if(n==="viewport")r=_Q(e,t);else if(n==="document")r=EQ(ls(e));else if(vo(n))r=kQ(n,t);else{const o=IA(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return vp(r)}function _A(e,n){const t=Zs(e);return t===n||!vo(t)||wc(t)?!1:Kr(t).position==="fixed"||_A(t,n)}function TQ(e,n){const t=n.get(e);if(t)return t;let r=yd(e,[],!1).filter(a=>vo(a)&&Lc(a)!=="body"),o=null;const s=Kr(e).position==="fixed";let i=s?Zs(e):e;for(;vo(i)&&!wc(i);){const a=Kr(i),c=vw(i);!c&&a.position==="fixed"&&(o=null),(s?!c&&!o:!c&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Wd(i)&&!c&&_A(e,i))?r=r.filter(d=>d!==i):o=a,i=Zs(i)}return n.set(e,r),r}function $Q(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?bw(n)?[]:TQ(n,this._c):[].concat(t),r],a=i[0],c=i.reduce((l,d)=>{const u=II(n,d,o);return l.top=Yn(u.top,l.top),l.right=co(u.right,l.right),l.bottom=co(u.bottom,l.bottom),l.left=Yn(u.left,l.left),l},II(n,a,o));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function MQ(e){const{width:n,height:t}=CA(e);return{width:n,height:t}}function AQ(e,n,t){const r=xo(n),o=ls(n),s=t==="fixed",i=Yi(e,!0,s,n);let a={scrollLeft:0,scrollTop:0};const c=qs(0);if(r||!r&&!s)if((Lc(n)!=="body"||Wd(o))&&(a=wg(n)),r){const u=Yi(n,!0,s,n);c.x=u.x+n.clientLeft,c.y=u.y+n.clientTop}else o&&(c.x=EA(o));const l=i.left+a.scrollLeft-c.x,d=i.top+a.scrollTop-c.y;return{x:l,y:d,width:i.width,height:i.height}}function vy(e){return Kr(e).position==="static"}function EI(e,n){return!xo(e)||Kr(e).position==="fixed"?null:n?n(e):e.offsetParent}function kA(e,n){const t=tr(e);if(bw(e))return t;if(!xo(e)){let o=Zs(e);for(;o&&!wc(o);){if(vo(o)&&!vy(o))return o;o=Zs(o)}return t}let r=EI(e,n);for(;r&&vQ(r)&&vy(r);)r=EI(r,n);return r&&wc(r)&&vy(r)&&!vw(r)?t:r||xQ(e)||t}const jQ=async function(e){const n=this.getOffsetParent||kA,t=this.getDimensions,r=await t(e.floating);return{reference:AQ(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function OQ(e){return Kr(e).direction==="rtl"}const DQ={convertOffsetParentRelativeRectToViewportRelativeRect:CQ,getDocumentElement:ls,getClippingRect:$Q,getOffsetParent:kA,getElementRects:jQ,getClientRects:IQ,getDimensions:MQ,getScale:rc,isElement:vo,isRTL:OQ};function RQ(e,n){let t=null,r;const o=ls(e);function s(){var a;clearTimeout(r),(a=t)==null||a.disconnect(),t=null}function i(a,c){a===void 0&&(a=!1),c===void 0&&(c=1),s();const{left:l,top:d,width:u,height:f}=e.getBoundingClientRect();if(a||n(),!u||!f)return;const p=nh(d),S=nh(o.clientWidth-(l+u)),g=nh(o.clientHeight-(d+f)),w=nh(l),v={rootMargin:-p+"px "+-S+"px "+-g+"px "+-w+"px",threshold:Yn(0,co(1,c))||1};let P=!0;function E(I){const C=I[0].intersectionRatio;if(C!==c){if(!P)return i();C?i(!1,C):r=setTimeout(()=>{i(!1,1e-7)},1e3)}P=!1}try{t=new IntersectionObserver(E,{...v,root:o.ownerDocument})}catch{t=new IntersectionObserver(E,v)}t.observe(e)}return i(!0),s}function LQ(e,n,t,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:c=!1}=r,l=ww(e),d=o||s?[...l?yd(l):[],...yd(n)]:[];d.forEach(y=>{o&&y.addEventListener("scroll",t,{passive:!0}),s&&y.addEventListener("resize",t)});const u=l&&a?RQ(l,t):null;let f=-1,p=null;i&&(p=new ResizeObserver(y=>{let[v]=y;v&&v.target===l&&p&&(p.unobserve(n),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var P;(P=p)==null||P.observe(n)})),t()}),l&&!c&&p.observe(l),p.observe(n));let S,g=c?Yi(e):null;c&&w();function w(){const y=Yi(e);g&&(y.x!==g.x||y.y!==g.y||y.width!==g.width||y.height!==g.height)&&t(),g=y,S=requestAnimationFrame(w)}return t(),()=>{var y;d.forEach(v=>{o&&v.removeEventListener("scroll",t),s&&v.removeEventListener("resize",t)}),u==null||u(),(y=p)==null||y.disconnect(),p=null,c&&cancelAnimationFrame(S)}}const FQ=gQ,zQ=mQ,NQ=hQ,BQ=SQ,UQ=fQ,_I=uQ,HQ=yQ,KQ=(e,n,t)=>{const r=new Map,o={platform:DQ,...t},s={...o.platform,_c:r};return dQ(e,n,{...o,platform:s})};var df=typeof document<"u"?x.useLayoutEffect:x.useEffect;function xp(e,n){if(e===n)return!0;if(typeof e!=typeof n)return!1;if(typeof e=="function"&&e.toString()===n.toString())return!0;let t,r,o;if(e&&n&&typeof e=="object"){if(Array.isArray(e)){if(t=e.length,t!==n.length)return!1;for(r=t;r--!==0;)if(!xp(e[r],n[r]))return!1;return!0}if(o=Object.keys(e),t=o.length,t!==Object.keys(n).length)return!1;for(r=t;r--!==0;)if(!{}.hasOwnProperty.call(n,o[r]))return!1;for(r=t;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!xp(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function TA(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function kI(e,n){const t=TA(e);return Math.round(n*t)/t}function TI(e){const n=x.useRef(e);return df(()=>{n.current=e}),n}function WQ(e){e===void 0&&(e={});const{placement:n="bottom",strategy:t="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:c,open:l}=e,[d,u]=x.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[f,p]=x.useState(r);xp(f,r)||p(r);const[S,g]=x.useState(null),[w,y]=x.useState(null),v=x.useCallback(K=>{K!==C.current&&(C.current=K,g(K))},[]),P=x.useCallback(K=>{K!==_.current&&(_.current=K,y(K))},[]),E=s||S,I=i||w,C=x.useRef(null),_=x.useRef(null),k=x.useRef(d),j=c!=null,T=TI(c),M=TI(o),R=x.useCallback(()=>{if(!C.current||!_.current)return;const K={placement:n,strategy:t,middleware:f};M.current&&(K.platform=M.current),KQ(C.current,_.current,K).then(B=>{const U={...B,isPositioned:!0};A.current&&!xp(k.current,U)&&(k.current=U,oa.flushSync(()=>{u(U)}))})},[f,n,t,M]);df(()=>{l===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,u(K=>({...K,isPositioned:!1})))},[l]);const A=x.useRef(!1);df(()=>(A.current=!0,()=>{A.current=!1}),[]),df(()=>{if(E&&(C.current=E),I&&(_.current=I),E&&I){if(T.current)return T.current(E,I,R);R()}},[E,I,R,T,j]);const O=x.useMemo(()=>({reference:C,floating:_,setReference:v,setFloating:P}),[v,P]),L=x.useMemo(()=>({reference:E,floating:I}),[E,I]),G=x.useMemo(()=>{const K={position:t,left:0,top:0};if(!L.floating)return K;const B=kI(L.floating,d.x),U=kI(L.floating,d.y);return a?{...K,transform:"translate("+B+"px, "+U+"px)",...TA(L.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:B,top:U}},[t,a,L.floating,d.x,d.y]);return x.useMemo(()=>({...d,update:R,refs:O,elements:L,floatingStyles:G}),[d,R,O,L,G])}const 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?_I({element:r.current,padding:o}).fn(t):{}:r?_I({element:r,padding:o}).fn(t):{}}}},VQ=(e,n)=>({...FQ(e),options:[e,n]}),YQ=(e,n)=>({...zQ(e),options:[e,n]}),XQ=(e,n)=>({...HQ(e),options:[e,n]}),qQ=(e,n)=>({...NQ(e),options:[e,n]}),ZQ=(e,n)=>({...BQ(e),options:[e,n]}),QQ=(e,n)=>({...UQ(e),options:[e,n]}),JQ=(e,n)=>({...GQ(e),options:[e,n]});function $A(e){const[n,t]=x.useState(void 0);return Gi(()=>{if(e){t({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const c=s.borderBoxSize,l=Array.isArray(c)?c[0]:c;i=l.inlineSize,a=l.blockSize}else i=e.offsetWidth,a=e.offsetHeight;t({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else t(void 0)},[e]),n}const MA="Popper",[AA,bg]=Co(MA),[eJ,jA]=AA(MA),tJ=e=>{const{__scopePopper:n,children:t}=e,[r,o]=x.useState(null);return x.createElement(eJ,{scope:n,anchor:r,onAnchorChange:o},t)},nJ="PopperAnchor",rJ=x.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=jA(nJ,t),i=x.useRef(null),a=Xe(n,i);return x.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:x.createElement(He.div,Z({},o,{ref:a}))}),OA="PopperContent",[oJ,dse]=AA(OA),sJ=x.forwardRef((e,n)=>{var t,r,o,s,i,a,c,l;const{__scopePopper:d,side:u="bottom",sideOffset:f=0,align:p="center",alignOffset:S=0,arrowPadding:g=0,avoidCollisions:w=!0,collisionBoundary:y=[],collisionPadding:v=0,sticky:P="partial",hideWhenDetached:E=!1,updatePositionStrategy:I="optimized",onPlaced:C,..._}=e,k=jA(OA,d),[j,T]=x.useState(null),M=Xe(n,qe=>T(qe)),[R,A]=x.useState(null),O=$A(R),L=(t=O==null?void 0:O.width)!==null&&t!==void 0?t:0,G=(r=O==null?void 0:O.height)!==null&&r!==void 0?r:0,K=u+(p!=="center"?"-"+p:""),B=typeof v=="number"?v:{top:0,right:0,bottom:0,left:0,...v},U=Array.isArray(y)?y:[y],Y=U.length>0,Q={padding:B,boundary:U.filter(iJ),altBoundary:Y},{refs:le,floatingStyles:ge,placement:Me,isPositioned:ce,middlewareData:Ae}=WQ({strategy:"fixed",placement:K,whileElementsMounted:(...qe)=>LQ(...qe,{animationFrame:I==="always"}),elements:{reference:k.anchor},middleware:[VQ({mainAxis:f+G,alignmentAxis:S}),w&&YQ({mainAxis:!0,crossAxis:!1,limiter:P==="partial"?XQ():void 0,...Q}),w&&qQ({...Q}),ZQ({...Q,apply:({elements:qe,rects:Rt,availableWidth:ko,availableHeight:zc})=>{const{width:Nc,height:Tg}=Rt.reference,aa=qe.floating.style;aa.setProperty("--radix-popper-available-width",`${ko}px`),aa.setProperty("--radix-popper-available-height",`${zc}px`),aa.setProperty("--radix-popper-anchor-width",`${Nc}px`),aa.setProperty("--radix-popper-anchor-height",`${Tg}px`)}}),R&&JQ({element:R,padding:g}),aJ({arrowWidth:L,arrowHeight:G}),E&&QQ({strategy:"referenceHidden",...Q})]}),[Re,ct]=DA(Me),Ie=ln(C);Gi(()=>{ce&&(Ie==null||Ie())},[ce,Ie]);const gt=(o=Ae.arrow)===null||o===void 0?void 0:o.x,Ue=(s=Ae.arrow)===null||s===void 0?void 0:s.y,dr=((i=Ae.arrow)===null||i===void 0?void 0:i.centerOffset)!==0,[Un,Hn]=x.useState();return Gi(()=>{j&&Hn(window.getComputedStyle(j).zIndex)},[j]),x.createElement("div",{ref:le.setFloating,"data-radix-popper-content-wrapper":"",style:{...ge,transform:ce?ge.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Un,"--radix-popper-transform-origin":[(a=Ae.transformOrigin)===null||a===void 0?void 0:a.x,(c=Ae.transformOrigin)===null||c===void 0?void 0:c.y].join(" ")},dir:e.dir},x.createElement(oJ,{scope:d,placedSide:Re,onArrowChange:A,arrowX:gt,arrowY:Ue,shouldHideArrow:dr},x.createElement(He.div,Z({"data-side":Re,"data-align":ct},_,{ref:M,style:{..._.style,animation:ce?void 0:"none",opacity:(l=Ae.hide)!==null&&l!==void 0&&l.referenceHidden?0:void 0}}))))});function iJ(e){return e!==null}const aJ=e=>({name:"transformOrigin",options:e,fn(n){var t,r,o,s,i;const{placement:a,rects:c,middlewareData:l}=n,u=((t=l.arrow)===null||t===void 0?void 0:t.centerOffset)!==0,f=u?0:e.arrowWidth,p=u?0:e.arrowHeight,[S,g]=DA(a),w={start:"0%",center:"50%",end:"100%"}[g],y=((r=(o=l.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+f/2,v=((s=(i=l.arrow)===null||i===void 0?void 0:i.y)!==null&&s!==void 0?s:0)+p/2;let P="",E="";return S==="bottom"?(P=u?w:`${y}px`,E=`${-p}px`):S==="top"?(P=u?w:`${y}px`,E=`${c.floating.height+p}px`):S==="right"?(P=`${-p}px`,E=u?w:`${v}px`):S==="left"&&(P=`${c.floating.width+p}px`,E=u?w:`${v}px`),{data:{x:P,y:E}}}});function DA(e){const[n,t="center"]=e.split("-");return[n,t]}const Pw=tJ,RA=rJ,LA=sJ,FA="Popover",[zA,use]=Co(FA,[bg]),Cw=bg(),[cJ,Fc]=zA(FA),lJ=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Cw(n),c=x.useRef(null),[l,d]=x.useState(!1),[u=!1,f]=ii({prop:r,defaultProp:o,onChange:s});return x.createElement(Pw,a,x.createElement(cJ,{scope:n,contentId:Vo(),triggerRef:c,open:u,onOpenChange:f,onOpenToggle:x.useCallback(()=>f(p=>!p),[f]),hasCustomAnchor:l,onCustomAnchorAdd:x.useCallback(()=>d(!0),[]),onCustomAnchorRemove:x.useCallback(()=>d(!1),[]),modal:i},t))},dJ="PopoverTrigger",uJ=x.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Fc(dJ,t),s=Cw(t),i=Xe(n,o.triggerRef),a=x.createElement(He.button,Z({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":UA(o.open)},r,{ref:i,onClick:ie(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(RA,Z({asChild:!0},s),a)}),NA="PopoverPortal",[hJ,fJ]=zA(NA,{forceMount:void 0}),pJ=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=Fc(NA,n);return x.createElement(hJ,{scope:n,forceMount:t},x.createElement(Io,{present:t||s.open},x.createElement(ug,{asChild:!0,container:o},r)))},Sd="PopoverContent",gJ=x.forwardRef((e,n)=>{const t=fJ(Sd,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=Fc(Sd,e.__scopePopover);return x.createElement(Io,{present:r||s.open},s.modal?x.createElement(mJ,Z({},o,{ref:n})):x.createElement(yJ,Z({},o,{ref:n})))}),mJ=x.forwardRef((e,n)=>{const t=Fc(Sd,e.__scopePopover),r=x.useRef(null),o=Xe(n,r),s=x.useRef(!1);return x.useEffect(()=>{const i=r.current;if(i)return uw(i)},[]),x.createElement(fg,{as:Vi,allowPinchZoom:!0},x.createElement(BA,Z({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:ie(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:ie(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,c=a.button===0&&a.ctrlKey===!0,l=a.button===2||c;s.current=l},{checkForDefaultPrevented:!1}),onFocusOutside:ie(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),yJ=x.forwardRef((e,n)=>{const t=Fc(Sd,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(BA,Z({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const c=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(c))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),BA=x.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onInteractOutside:d,...u}=e,f=Fc(Sd,t),p=Cw(t);return dw(),x.createElement(lw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(dg,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:d,onEscapeKeyDown:a,onPointerDownOutside:c,onFocusOutside:l,onDismiss:()=>f.onOpenChange(!1)},x.createElement(LA,Z({"data-state":UA(f.open),role:"dialog",id:f.contentId},p,u,{ref:n,style:{...u.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 UA(e){return e?"open":"closed"}const SJ=lJ,vJ=uJ,xJ=pJ,wJ=gJ;function ai(e,n){const t=N(),r=x.useRef(!1),o=Yr(),s=x.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(c=>!c.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=W("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return x.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),t.addOpenMenu(e)),()=>{r.current&&(t.deleteOpenMenu(e),t.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),t.deleteOpenMenu(a))}),r.current=!1)}),[t,e,o]),[i,s]}function Iw({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=ai(e,t);return h.jsx(SJ,{onOpenChange:s,open:r||o,children:h.jsx("div",{className:"tlui-popover",children:n})})}function Ew({children:e}){return h.jsx(vJ,{asChild:!0,dir:"ltr",children:e})}function _w({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=dn();return h.jsx(xJ,{container:s,children:h.jsx(wJ,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const HA=x.createContext(null);function Pg(){const e=x.useContext(HA);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function Ir({type:e,sourceId:n,children:t}){return h.jsx(HA.Provider,{value:{type:e,sourceId:n},children:t})}function bJ(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const o=kn(e,r);if(o.start||o.end)return!1}return!0})}const KA=()=>{const e=N();return W("threeStackableItems",()=>bJ(e).length>2,[e])},ds=()=>{const e=N();return W("isInSelectState",()=>e.isIn("select"),[e])},WA=()=>{const e=N();return W("allow group",()=>{const n=e.getSelectedShapes();if(n.length<2)return!1;for(const t of n)if(e.isShapeOfType(t,"arrow")){const r=kn(e,t);if(r.start&&!n.some(o=>o.id===r.start.toId)||r.end&&!n.some(o=>o.id===r.end.toId))return!1}return!0},[e])},GA=()=>{const e=N();return W("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},PJ=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function CJ(e,n){const t=N();return W("selectedShapes",()=>t.getSelectedShapes().length>=e,[t,e,n])}function wn(e,n){const t=N();return W("selectedShapes",()=>{const r=t.getSelectedShapes().filter(o=>!t.isShapeOrAncestorLocked(o)).length;return e===void 0?r:r>=e},[t])}function IJ(){const e=N();return W("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}function VA(){const e=N();return W("hasLinkShapeSelected",()=>{const n=e.getOnlySelectedShape();return!!(n&&n.type!=="embed"&&"url"in n.props&&!n.isLocked)},[e])}function EJ(){const e=N();return W("onlyFlippableShape",()=>{const n=e.getOnlySelectedShape();return n&&(e.isShapeOfType(n,"group")||e.isShapeOfType(n,"arrow")||e.isShapeOfType(n,"line")||e.isShapeOfType(n,"draw"))},[e])}function YA(){const e=N();return W("useCanRedo",()=>e.getCanRedo(),[e])}function XA(){const e=N();return W("useCanUndo",()=>e.getCanUndo(),[e])}const _J=x.createContext(void 0);function kw(e){const n=x.useContext(_J);return e||n||"ltr"}const xy="rovingFocusGroup.onEntryFocus",kJ={bubbles:!1,cancelable:!0},Tw="RovingFocusGroup",[zv,qA,TJ]=pg(Tw),[$J,ZA]=Co(Tw,[TJ]),[MJ,AJ]=$J(Tw),jJ=x.forwardRef((e,n)=>x.createElement(zv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(zv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(OJ,Z({},e,{ref:n}))))),OJ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:c,onEntryFocus:l,...d}=e,u=x.useRef(null),f=Xe(n,u),p=kw(s),[S=null,g]=ii({prop:i,defaultProp:a,onChange:c}),[w,y]=x.useState(!1),v=ln(l),P=qA(t),E=x.useRef(!1),[I,C]=x.useState(0);return x.useEffect(()=>{const _=u.current;if(_)return _.addEventListener(xy,v),()=>_.removeEventListener(xy,v)},[v]),x.createElement(MJ,{scope:t,orientation:r,dir:p,loop:o,currentTabStopId:S,onItemFocus:x.useCallback(_=>g(_),[g]),onItemShiftTab:x.useCallback(()=>y(!0),[]),onFocusableItemAdd:x.useCallback(()=>C(_=>_+1),[]),onFocusableItemRemove:x.useCallback(()=>C(_=>_-1),[])},x.createElement(He.div,Z({tabIndex:w||I===0?-1:0,"data-orientation":r},d,{ref:f,style:{outline:"none",...e.style},onMouseDown:ie(e.onMouseDown,()=>{E.current=!0}),onFocus:ie(e.onFocus,_=>{const k=!E.current;if(_.target===_.currentTarget&&k&&!w){const j=new CustomEvent(xy,kJ);if(_.currentTarget.dispatchEvent(j),!j.defaultPrevented){const T=P().filter(L=>L.focusable),M=T.find(L=>L.active),R=T.find(L=>L.id===S),O=[M,R,...T].filter(Boolean).map(L=>L.ref.current);QA(O)}}E.current=!1}),onBlur:ie(e.onBlur,()=>y(!1))})))}),DJ="RovingFocusGroupItem",RJ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Vo(),c=s||a,l=AJ(DJ,t),d=l.currentTabStopId===c,u=qA(t),{onFocusableItemAdd:f,onFocusableItemRemove:p}=l;return x.useEffect(()=>{if(r)return f(),()=>p()},[r,f,p]),x.createElement(zv.ItemSlot,{scope:t,id:c,focusable:r,active:o},x.createElement(He.span,Z({tabIndex:d?0:-1,"data-orientation":l.orientation},i,{ref:n,onMouseDown:ie(e.onMouseDown,S=>{r?l.onItemFocus(c):S.preventDefault()}),onFocus:ie(e.onFocus,()=>l.onItemFocus(c)),onKeyDown:ie(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){l.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const g=zJ(S,l.orientation,l.dir);if(g!==void 0){S.preventDefault();let y=u().filter(v=>v.focusable).map(v=>v.ref.current);if(g==="last")y.reverse();else if(g==="prev"||g==="next"){g==="prev"&&y.reverse();const v=y.indexOf(S.currentTarget);y=l.loop?NJ(y,v+1):y.slice(v+1)}setTimeout(()=>QA(y))}})})))}),LJ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function FJ(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function zJ(e,n,t){const r=FJ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return LJ[r]}function QA(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function NJ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const BJ=jJ,UJ=RJ,Nv=["Enter"," "],HJ=["ArrowDown","PageUp","Home"],JA=["ArrowUp","PageDown","End"],KJ=[...HJ,...JA],WJ={ltr:[...Nv,"ArrowRight"],rtl:[...Nv,"ArrowLeft"]},GJ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Cg="Menu",[vd,VJ,YJ]=pg(Cg),[ia,Ig]=Co(Cg,[YJ,bg,ZA]),Eg=bg(),ej=ZA(),[tj,ci]=ia(Cg),[XJ,Gd]=ia(Cg),qJ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=Eg(n),[c,l]=x.useState(null),d=x.useRef(!1),u=ln(s),f=kw(o);return x.useEffect(()=>{const p=()=>{d.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>d.current=!1;return document.addEventListener("keydown",p,{capture:!0}),()=>{document.removeEventListener("keydown",p,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),x.createElement(Pw,a,x.createElement(tj,{scope:n,open:t,onOpenChange:u,content:c,onContentChange:l},x.createElement(XJ,{scope:n,onClose:x.useCallback(()=>u(!1),[u]),isUsingKeyboardRef:d,dir:f,modal:i},r)))},nj=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=Eg(t);return x.createElement(RA,Z({},o,r,{ref:n}))}),rj="MenuPortal",[ZJ,oj]=ia(rj,{forceMount:void 0}),QJ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=ci(rj,n);return x.createElement(ZJ,{scope:n,forceMount:t},x.createElement(Io,{present:t||s.open},x.createElement(ug,{asChild:!0,container:o},r)))},Br="MenuContent",[JJ,$w]=ia(Br),eee=x.forwardRef((e,n)=>{const t=oj(Br,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=ci(Br,e.__scopeMenu),i=Gd(Br,e.__scopeMenu);return x.createElement(vd.Provider,{scope:e.__scopeMenu},x.createElement(Io,{present:r||s.open},x.createElement(vd.Slot,{scope:e.__scopeMenu},i.modal?x.createElement(tee,Z({},o,{ref:n})):x.createElement(nee,Z({},o,{ref:n})))))}),tee=x.forwardRef((e,n)=>{const t=ci(Br,e.__scopeMenu),r=x.useRef(null),o=Xe(n,r);return x.useEffect(()=>{const s=r.current;if(s)return uw(s)},[]),x.createElement(Mw,Z({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:ie(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)}))}),nee=x.forwardRef((e,n)=>{const t=ci(Br,e.__scopeMenu);return x.createElement(Mw,Z({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),Mw=x.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:c,onEscapeKeyDown:l,onPointerDownOutside:d,onFocusOutside:u,onInteractOutside:f,onDismiss:p,disableOutsideScroll:S,...g}=e,w=ci(Br,t),y=Gd(Br,t),v=Eg(t),P=ej(t),E=VJ(t),[I,C]=x.useState(null),_=x.useRef(null),k=Xe(n,_,w.onContentChange),j=x.useRef(0),T=x.useRef(""),M=x.useRef(0),R=x.useRef(null),A=x.useRef("right"),O=x.useRef(0),L=S?fg:x.Fragment,G=S?{as:Vi,allowPinchZoom:!0}:void 0,K=U=>{var Y,Q;const le=T.current+U,ge=E().filter(Ie=>!Ie.disabled),Me=document.activeElement,ce=(Y=ge.find(Ie=>Ie.ref.current===Me))===null||Y===void 0?void 0:Y.textValue,Ae=ge.map(Ie=>Ie.textValue),Re=mee(Ae,le,ce),ct=(Q=ge.find(Ie=>Ie.textValue===Re))===null||Q===void 0?void 0:Q.ref.current;(function Ie(gt){T.current=gt,window.clearTimeout(j.current),gt!==""&&(j.current=window.setTimeout(()=>Ie(""),1e3))})(le),ct&&setTimeout(()=>ct.focus())};x.useEffect(()=>()=>window.clearTimeout(j.current),[]),dw();const B=x.useCallback(U=>{var Y,Q;return A.current===((Y=R.current)===null||Y===void 0?void 0:Y.side)&&See(U,(Q=R.current)===null||Q===void 0?void 0:Q.area)},[]);return x.createElement(JJ,{scope:t,searchRef:T,onItemEnter:x.useCallback(U=>{B(U)&&U.preventDefault()},[B]),onItemLeave:x.useCallback(U=>{var Y;B(U)||((Y=_.current)===null||Y===void 0||Y.focus(),C(null))},[B]),onTriggerLeave:x.useCallback(U=>{B(U)&&U.preventDefault()},[B]),pointerGraceTimerRef:M,onPointerGraceIntentChange:x.useCallback(U=>{R.current=U},[])},x.createElement(L,G,x.createElement(lw,{asChild:!0,trapped:o,onMountAutoFocus:ie(s,U=>{var Y;U.preventDefault(),(Y=_.current)===null||Y===void 0||Y.focus()}),onUnmountAutoFocus:i},x.createElement(dg,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:l,onPointerDownOutside:d,onFocusOutside:u,onInteractOutside:f,onDismiss:p},x.createElement(BJ,Z({asChild:!0},P,{dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:C,onEntryFocus:ie(c,U=>{y.isUsingKeyboardRef.current||U.preventDefault()})}),x.createElement(LA,Z({role:"menu","aria-orientation":"vertical","data-state":lj(w.open),"data-radix-menu-content":"",dir:y.dir},v,g,{ref:k,style:{outline:"none",...g.style},onKeyDown:ie(g.onKeyDown,U=>{const Q=U.target.closest("[data-radix-menu-content]")===U.currentTarget,le=U.ctrlKey||U.altKey||U.metaKey,ge=U.key.length===1;Q&&(U.key==="Tab"&&U.preventDefault(),!le&&ge&&K(U.key));const Me=_.current;if(U.target!==Me||!KJ.includes(U.key))return;U.preventDefault();const Ae=E().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);JA.includes(U.key)&&Ae.reverse(),pee(Ae)}),onBlur:ie(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(j.current),T.current="")}),onPointerMove:ie(e.onPointerMove,xd(U=>{const Y=U.target,Q=O.current!==U.clientX;if(U.currentTarget.contains(Y)&&Q){const le=U.clientX>O.current?"right":"left";A.current=le,O.current=U.clientX}}))})))))))}),ree=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return x.createElement(He.div,Z({role:"group"},r,{ref:n}))}),Bv="MenuItem",$I="menu.itemSelect",sj=x.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=x.useRef(null),i=Gd(Bv,e.__scopeMenu),a=$w(Bv,e.__scopeMenu),c=Xe(n,s),l=x.useRef(!1),d=()=>{const u=s.current;if(!t&&u){const f=new CustomEvent($I,{bubbles:!0,cancelable:!0});u.addEventListener($I,p=>r==null?void 0:r(p),{once:!0}),cw(u,f),f.defaultPrevented?l.current=!1:i.onClose()}};return x.createElement(ij,Z({},o,{ref:c,disabled:t,onClick:ie(e.onClick,d),onPointerDown:u=>{var f;(f=e.onPointerDown)===null||f===void 0||f.call(e,u),l.current=!0},onPointerUp:ie(e.onPointerUp,u=>{var f;l.current||(f=u.currentTarget)===null||f===void 0||f.click()}),onKeyDown:ie(e.onKeyDown,u=>{const f=a.searchRef.current!=="";t||f&&u.key===" "||Nv.includes(u.key)&&(u.currentTarget.click(),u.preventDefault())})}))}),ij=x.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=$w(Bv,t),a=ej(t),c=x.useRef(null),l=Xe(n,c),[d,u]=x.useState(!1),[f,p]=x.useState("");return x.useEffect(()=>{const S=c.current;if(S){var g;p(((g=S.textContent)!==null&&g!==void 0?g:"").trim())}},[s.children]),x.createElement(vd.ItemSlot,{scope:t,disabled:r,textValue:o??f},x.createElement(UJ,Z({asChild:!0},a,{focusable:!r}),x.createElement(He.div,Z({role:"menuitem","data-highlighted":d?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:l,onPointerMove:ie(e.onPointerMove,xd(S=>{r?i.onItemLeave(S):(i.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus())})),onPointerLeave:ie(e.onPointerLeave,xd(S=>i.onItemLeave(S))),onFocus:ie(e.onFocus,()=>u(!0)),onBlur:ie(e.onBlur,()=>u(!1))}))))}),oee=x.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return x.createElement(aee,{scope:e.__scopeMenu,checked:t},x.createElement(sj,Z({role:"menuitemcheckbox","aria-checked":Uv(t)?"mixed":t},o,{ref:n,"data-state":fee(t),onSelect:ie(o.onSelect,()=>r==null?void 0:r(Uv(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),see="MenuRadioGroup";ia(see,{value:void 0,onValueChange:()=>{}});const iee="MenuItemIndicator",[aee,hse]=ia(iee,{checked:!1}),aj="MenuSub",[cee,cj]=ia(aj),lee=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=ci(aj,n),i=Eg(n),[a,c]=x.useState(null),[l,d]=x.useState(null),u=ln(o);return x.useEffect(()=>(s.open===!1&&u(!1),()=>u(!1)),[s.open,u]),x.createElement(Pw,i,x.createElement(tj,{scope:n,open:r,onOpenChange:u,content:l,onContentChange:d},x.createElement(cee,{scope:n,contentId:Vo(),triggerId:Vo(),trigger:a,onTriggerChange:c},t)))},rh="MenuSubTrigger",dee=x.forwardRef((e,n)=>{const t=ci(rh,e.__scopeMenu),r=Gd(rh,e.__scopeMenu),o=cj(rh,e.__scopeMenu),s=$w(rh,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:c}=s,l={__scopeMenu:e.__scopeMenu},d=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>d,[d]),x.useEffect(()=>{const u=a.current;return()=>{window.clearTimeout(u),c(null)}},[a,c]),x.createElement(nj,Z({asChild:!0},l),x.createElement(ij,Z({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":lj(t.open)},e,{ref:lg(n,o.onTriggerChange),onClick:u=>{var f;(f=e.onClick)===null||f===void 0||f.call(e,u),!(e.disabled||u.defaultPrevented)&&(u.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:ie(e.onPointerMove,xd(u=>{s.onItemEnter(u),!u.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),d()},100))})),onPointerLeave:ie(e.onPointerLeave,xd(u=>{var f;d();const p=(f=t.content)===null||f===void 0?void 0:f.getBoundingClientRect();if(p){var S;const g=(S=t.content)===null||S===void 0?void 0:S.dataset.side,w=g==="right",y=w?-5:5,v=p[w?"left":"right"],P=p[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:u.clientX+y,y:u.clientY},{x:v,y:p.top},{x:P,y:p.top},{x:P,y:p.bottom},{x:v,y:p.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(u),u.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:ie(e.onKeyDown,u=>{const f=s.searchRef.current!=="";if(!(e.disabled||f&&u.key===" ")&&WJ[r.dir].includes(u.key)){var p;t.onOpenChange(!0),(p=t.content)===null||p===void 0||p.focus(),u.preventDefault()}})})))}),uee="MenuSubContent",hee=x.forwardRef((e,n)=>{const t=oj(Br,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=ci(Br,e.__scopeMenu),i=Gd(Br,e.__scopeMenu),a=cj(uee,e.__scopeMenu),c=x.useRef(null),l=Xe(n,c);return x.createElement(vd.Provider,{scope:e.__scopeMenu},x.createElement(Io,{present:r||s.open},x.createElement(vd.Slot,{scope:e.__scopeMenu},x.createElement(Mw,Z({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:l,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:d=>{var u;i.isUsingKeyboardRef.current&&((u=c.current)===null||u===void 0||u.focus()),d.preventDefault()},onCloseAutoFocus:d=>d.preventDefault(),onFocusOutside:ie(e.onFocusOutside,d=>{d.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:ie(e.onEscapeKeyDown,d=>{i.onClose(),d.preventDefault()}),onKeyDown:ie(e.onKeyDown,d=>{const u=d.currentTarget.contains(d.target),f=GJ[i.dir].includes(d.key);if(u&&f){var p;s.onOpenChange(!1),(p=a.trigger)===null||p===void 0||p.focus(),d.preventDefault()}})})))))});function lj(e){return e?"open":"closed"}function Uv(e){return e==="indeterminate"}function fee(e){return Uv(e)?"indeterminate":e?"checked":"unchecked"}function pee(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function gee(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function mee(e,n,t){const o=n.length>1&&Array.from(n).every(l=>l===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=gee(e,Math.max(s,0));o.length===1&&(i=i.filter(l=>l!==t));const c=i.find(l=>l.toLowerCase().startsWith(o.toLowerCase()));return c!==t?c:void 0}function yee(e,n){const{x:t,y:r}=e;let o=!1;for(let s=0,i=n.length-1;s<n.length;i=s++){const a=n[s].x,c=n[s].y,l=n[i].x,d=n[i].y;c>r!=d>r&&t<(l-a)*(r-c)/(d-c)+a&&(o=!o)}return o}function See(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return yee(t,n)}function xd(e){return n=>n.pointerType==="mouse"?e(n):void 0}const dj=qJ,uj=nj,hj=QJ,fj=eee,pj=ree,gj=sj,mj=oee,yj=lee,Sj=dee,vj=hee,xj="ContextMenu",[vee,fse]=Co(xj,[Ig]),Eo=Ig(),[xee,wj]=vee(xj),wee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=x.useState(!1),c=Eo(n),l=ln(r),d=x.useCallback(u=>{a(u),l(u)},[l]);return x.createElement(xee,{scope:n,open:i,onOpenChange:d,modal:s},x.createElement(dj,Z({},c,{dir:o,open:i,onOpenChange:d,modal:s}),t))},bee="ContextMenuTrigger",Pee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=wj(bee,t),i=Eo(t),a=x.useRef({x:0,y:0}),c=x.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),l=x.useRef(0),d=x.useCallback(()=>window.clearTimeout(l.current),[]),u=f=>{a.current={x:f.clientX,y:f.clientY},s.onOpenChange(!0)};return x.useEffect(()=>d,[d]),x.useEffect(()=>void(r&&d()),[r,d]),x.createElement(x.Fragment,null,x.createElement(uj,Z({},i,{virtualRef:c})),x.createElement(He.span,Z({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:ie(e.onContextMenu,f=>{d(),u(f),f.preventDefault()}),onPointerDown:r?e.onPointerDown:ie(e.onPointerDown,oh(f=>{d(),l.current=window.setTimeout(()=>u(f),700)})),onPointerMove:r?e.onPointerMove:ie(e.onPointerMove,oh(d)),onPointerCancel:r?e.onPointerCancel:ie(e.onPointerCancel,oh(d)),onPointerUp:r?e.onPointerUp:ie(e.onPointerUp,oh(d))})))}),bj=e=>{const{__scopeContextMenu:n,...t}=e,r=Eo(n);return x.createElement(hj,Z({},r,t))},Cee="ContextMenuContent",Iee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=wj(Cee,t),s=Eo(t),i=x.useRef(!1);return x.createElement(fj,Z({},s,r,{ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var c;(c=e.onCloseAutoFocus)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var c;(c=e.onInteractOutside)===null||c===void 0||c.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),Eee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Eo(t);return x.createElement(pj,Z({},o,r,{ref:n}))}),_ee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Eo(t);return x.createElement(gj,Z({},o,r,{ref:n}))}),kee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Eo(t);return x.createElement(mj,Z({},o,r,{ref:n}))}),Tee=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=Eo(n),[a,c]=ii({prop:o,defaultProp:s,onChange:r});return x.createElement(yj,Z({},i,{open:a,onOpenChange:c}),t)},$ee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Eo(t);return x.createElement(Sj,Z({},o,r,{ref:n}))}),Mee=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=Eo(t);return x.createElement(vj,Z({},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 oh(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const Aee=wee,jee=Pee,Oee=bj,Dee=Iee,Ree=kee,Pj=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Lee=Pj?"⌘":"Ctrl",Fee=Pj?"⌥":"Alt";function Cj(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,Lee).replace(/\?/g,Fee).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Hv(e){return"— "+Cj(e).join(" ")}function zee(e){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const Ij="DropdownMenu",[Nee,pse]=Co(Ij,[Ig]),_o=Ig(),[Bee,Ej]=Nee(Ij),Uee=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,c=_o(n),l=x.useRef(null),[d=!1,u]=ii({prop:o,defaultProp:s,onChange:i});return x.createElement(Bee,{scope:n,triggerId:Vo(),triggerRef:l,contentId:Vo(),open:d,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(f=>!f),[u]),modal:a},x.createElement(dj,Z({},c,{open:d,onOpenChange:u,dir:r,modal:a}),t))},Hee="DropdownMenuTrigger",Kee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=Ej(Hee,t),i=_o(t);return x.createElement(uj,Z({asChild:!0},i),x.createElement(He.button,Z({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:lg(n,s.triggerRef),onPointerDown:ie(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:ie(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),Wee=e=>{const{__scopeDropdownMenu:n,...t}=e,r=_o(n);return x.createElement(hj,Z({},r,t))},Gee="DropdownMenuContent",Vee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=Ej(Gee,t),s=_o(t),i=x.useRef(!1);return x.createElement(fj,Z({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:n,onCloseAutoFocus:ie(e.onCloseAutoFocus,a=>{var c;i.current||(c=o.triggerRef.current)===null||c===void 0||c.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:ie(e.onInteractOutside,a=>{const c=a.detail.originalEvent,l=c.button===0&&c.ctrlKey===!0,d=c.button===2||l;(!o.modal||d)&&(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)"}}))}),Yee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=_o(t);return x.createElement(pj,Z({},o,r,{ref:n}))}),Xee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=_o(t);return x.createElement(gj,Z({},o,r,{ref:n}))}),qee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=_o(t);return x.createElement(mj,Z({},o,r,{ref:n}))}),Zee=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=_o(n),[a=!1,c]=ii({prop:r,defaultProp:s,onChange:o});return x.createElement(yj,Z({},i,{open:a,onOpenChange:c}),t)},Qee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=_o(t);return x.createElement(Sj,Z({},o,r,{ref:n}))}),Jee=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=_o(t);return x.createElement(vj,Z({},o,r,{ref:n,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),Aw=Uee,jw=Kee,_g=Wee,Ow=Vee,ete=Yee,tte=Xee,nte=qee,rte=Zee,ote=Qee,ste=Jee;function Xi({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=ai(e);return h.jsx(Aw,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function qi({children:e,...n}){return h.jsx(jw,{dir:"ltr",asChild:!0,onTouchEnd:t=>_e(t),...n,children:e})}function Zi({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=dn();return h.jsx(_g,{container:s,children:h.jsx(Ow,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function ite({id:e,children:n}){const[t,r]=ai(e);return h.jsx(rte,{open:t,onOpenChange:r,children:n})}function ate({id:e,label:n,title:t,disabled:r}){return h.jsx(ote,{dir:"ltr",asChild:!0,disabled:r,children:h.jsxs(fe,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[h.jsx(Pt,{children:n}),h.jsx(Pe,{icon:"chevron-right",small:!0})]})})}function cte({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=dn();return h.jsx(_g,{container:s,children:h.jsx(ste,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function lte({children:e}){return h.jsx(ete,{dir:"ltr",className:"tlui-menu__group",children:e})}function wd({noClose:e,children:n}){return h.jsx(tte,{dir:"ltr",asChild:!0,onClick:e?_e:void 0,children:n})}function Nl({children:e,visibleOnMobileLayout:n=!1}){const t=Nn();return!n&&t<vt.MOBILE?null:h.jsx("kbd",{className:"tlui-kbd",children:Cj(e).map((r,o)=>h.jsx("span",{children:r},o))})}function H({disabled:e=!1,spinner:n=!1,readonlyOk:t=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:c,isSelected:l}){const{type:d,sourceId:u}=Pg(),f=$e(),[p,S]=x.useState(!1);if(as()&&!t)return null;const w=gd(s,d),y=o?Hv(o):void 0,v=w?f(w):void 0,P=v&&y?`${v} ${y}`:v;switch(d){case"menu":return h.jsx(wd,{children:h.jsxs(fe,{type:"menu","data-testid":`${u}.${r}`,disabled:e,title:P,onClick:E=>{c&&_e(E),p?S(!1):a(u)},children:[h.jsx(Pt,{children:v}),o&&h.jsx(Nl,{children:o})]})});case"context-menu":return e?null:h.jsxs(_ee,{dir:"ltr",title:P,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${u}.${r}`,onSelect:E=>{c&&_e(E),p?S(!1):a(u)},children:[h.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&h.jsx(Nl,{children:o}),n&&h.jsx(zee,{})]});case"panel":return h.jsxs(fe,{"data-testid":`${u}.${r}`,type:"menu",title:P,disabled:e,onClick:()=>a(u),children:[h.jsx(Pt,{children:v}),i&&h.jsx(Pe,{icon:i})]});case"small-icons":case"icons":return h.jsx(fe,{"data-testid":`${u}.${r}`,type:"icon",title:P,disabled:e,onClick:()=>a(u),children:h.jsx(Pe,{icon:i,small:d==="small-icons"})});case"keyboard-shortcuts":return o?h.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${u}.${r}`,children:[h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:h.jsx(Nl,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return h.jsxs(fe,{type:"low",onClick:()=>a(u),children:[h.jsx(Pe,{icon:i}),h.jsx(Pt,{children:v})]});case"toolbar":return h.jsx(fe,{type:"tool","data-testid":`tools.${r}`,"aria-label":w,"data-value":r,onClick:()=>a("toolbar"),title:P,onTouchStart:E=>{_e(E),a("toolbar")},role:"radio","aria-checked":l?"true":"false",children:h.jsx(Pe,{icon:i})});case"toolbar-overflow":return h.jsx(wd,{"aria-label":s,children:h.jsx(fe,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:P,role:"radio","aria-checked":l?"true":"false","data-value":r,children:h.jsx(Pe,{icon:i})})});default:throw sn(d)}}function dte(){return h.jsxs(h.Fragment,{children:[h.jsx(ute,{}),h.jsx(hte,{}),h.jsx(fte,{}),h.jsx(pte,{}),h.jsx(gte,{}),h.jsx(Ste,{}),h.jsx(vte,{}),h.jsx(xte,{})]})}function ute(){const e=ae(),n=wn(2),t=ds(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(H,{...e["align-left"],disabled:!r}),h.jsx(H,{...e["align-center-horizontal"],disabled:!r}),h.jsx(H,{...e["align-right"],disabled:!r}),h.jsx(H,{...e["stretch-horizontal"],disabled:!r}),h.jsx(H,{...e["align-top"],disabled:!r}),h.jsx(H,{...e["align-center-vertical"],disabled:!r}),h.jsx(H,{...e["align-bottom"],disabled:!r}),h.jsx(H,{...e["stretch-vertical"],disabled:!r})]})}function hte(){const e=ae(),n=wn(3),t=ds(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(H,{...e["distribute-horizontal"],disabled:!r}),h.jsx(H,{...e["distribute-vertical"],disabled:!r})]})}function fte(){const e=ae(),n=KA(),t=ds(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(H,{...e["stack-horizontal"],disabled:!r}),h.jsx(H,{...e["stack-vertical"],disabled:!r})]})}function pte(){const e=ae(),n=wn(1),t=ds(),r=n&&t;return h.jsxs(h.Fragment,{children:[h.jsx(H,{...e["send-to-back"],disabled:!r}),h.jsx(H,{...e["send-backward"],disabled:!r}),h.jsx(H,{...e["bring-forward"],disabled:!r}),h.jsx(H,{...e["bring-to-front"],disabled:!r})]})}function gte(){return Nn()<vt.TABLET_SM?h.jsx(mte,{}):h.jsx(yte,{})}function mte(){const e=ae(),n=N(),t=W("zoom is 1",()=>n.getZoomLevel()===1,[n]);return h.jsx(H,{...e["zoom-to-100"],disabled:t})}function yte(){const e=ae(),n=wn(1),t=ds(),r=n&&t;return h.jsx(H,{...e["rotate-ccw"],disabled:!r})}function Ste(){const e=ae(),n=wn(1),t=ds(),r=n&&t;return h.jsx(H,{...e["rotate-cw"],disabled:!r})}function vte(){const e=ae(),n=VA(),t=ds(),r=n&&t;return h.jsx(H,{...e["edit-link"],disabled:!r})}function xte(){const e=WA(),n=GA();return e?h.jsx(MI,{}):n?h.jsx(wte,{}):h.jsx(MI,{})}function MI(){const e=ae(),n=wn(2),t=ds(),r=n&&t;return h.jsx(H,{...e.group,disabled:!r})}function wte(){const e=ae();return h.jsx(H,{...e.ungroup})}const bte=x.memo(function({children:n}){const t=$e(),r=Nn(),o=as(),s=N(),i=W("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??h.jsx(dte,{});if(!(o&&!i))return h.jsxs(Iw,{id:"actions-menu",children:[h.jsx(Ew,{children:h.jsx(fe,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:h.jsx(Pe,{icon:"dots-vertical",small:!0})})}),h.jsx(_w,{side:r>=vt.TABLET?"bottom":"top",sideOffset:6,children:h.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:h.jsx(Ir,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function lr({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:c,sourceId:l}=Pg(),d=as(),u=$e();if(d&&!r)return null;const f=gd(t,c),p=f?u(f):void 0;switch(c){case"menu":return h.jsxs(nte,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:p,onSelect:S=>{o==null||o(l),_e(S)},disabled:i,checked:a,children:[h.jsx(Xs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),n&&h.jsx(Nl,{children:n})]});case"context-menu":return h.jsxs(Ree,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:p,onSelect:S=>{o(l),_e(S)},disabled:i,checked:a,children:[h.jsx(Xs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),n&&h.jsx(Nl,{children:n})]},e);default:return null}}function ye({id:e,label:n,children:t}){const{type:r,sourceId:o}=Pg(),s=$e(),i=gd(n,r),a=i?s(i):void 0;switch(r){case"panel":return h.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return h.jsx(lte,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return h.jsx(Eee,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return h.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[h.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),h.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function Bn({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=Pg(),a=dn(),c=$e(),l=t?typeof t=="string"?t:t[s]??t.default:void 0,d=l?c(l):void 0;switch(s){case"menu":return h.jsxs(ite,{id:`${i}-sub.${e}`,children:[h.jsx(ate,{id:`${i}-sub.${d?d.toLowerCase()+"-button":""}`,disabled:n,label:d,title:d}),h.jsx(cte,{id:`${i}-sub.${d?d.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:h.jsxs(Pte,{id:`${i}-sub.${e}`,children:[h.jsx($ee,{dir:"ltr",disabled:n,asChild:!0,children:h.jsxs(fe,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[h.jsx(Pt,{children:d}),h.jsx(Pe,{icon:"chevron-right",small:!0})]})}),h.jsx(bj,{container:a,children:h.jsx(Mee,{"data-testid":`${i}-sub-content.${e}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function Pte({id:e,children:n}){const[t,r]=ai(e);return h.jsx(Tee,{open:t,onOpenChange:r,children:n})}function _j(){const e=ae();return IJ()?h.jsx(H,{...e["toggle-auto-size"]}):null}function kj(){const e=ae();return VA()?h.jsx(H,{...e["edit-link"]}):null}function Cte(){const e=ae();return wn(1)?h.jsx(H,{...e.duplicate}):null}function Tj(){const e=ae(),n=N();return W("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const o=n.getOnlySelectedShape();return!(o&&n.isShapeOfType(o,"image"))},[n])?h.jsx(H,{...e["flatten-to-image"]}):null}function $j(){const e=ae();return WA()?h.jsx(H,{...e.group}):null}function Mj(){const e=ae();return GA()?h.jsx(H,{...e.ungroup}):null}function Aj(){const e=N(),n=ae();return W("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?h.jsx(H,{...n["remove-frame"]}):null}function jj(){const e=N(),n=ae();return W("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?h.jsx(H,{...n["fit-frame-to-content"]}):null}function Oj(){const e=N(),n=ae();return W("selected shapes",()=>e.getSelectedShapes().length>0,[e])?h.jsx(H,{...n["toggle-lock"]}):null}function Dw(){const e=ae(),n=N(),t=W("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return h.jsx(lr,{...e["toggle-transparent"],checked:t,toggle:!0})}function Ite(){const e=N(),n=ae(),t=W("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsx(H,{...n["unlock-all"],disabled:!t})}function Dj(){const e=N(),n=W("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=ae();return h.jsx(H,{...t["zoom-to-100"],noClose:!0,disabled:n})}function Rj(){const e=N(),n=W("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=ae();return h.jsx(H,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function Lj(){const e=N(),n=W("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=ae();return h.jsx(H,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function Fj(){return h.jsxs(ye,{id:"clipboard",children:[h.jsx(_te,{}),h.jsx(kte,{}),h.jsx(Tte,{}),h.jsx(Cte,{}),h.jsx($te,{})]})}function Ete(){var r;const e=N(),n=ae(),t=W("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsxs(Bn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[h.jsxs(ye,{id:"copy-as-group",children:[h.jsx(H,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&h.jsx(H,{...n["copy-as-png"]}),h.jsx(H,{...n["copy-as-json"]})]}),h.jsx(ye,{id:"copy-as-bg",children:h.jsx(Dw,{})})]})}function _te(){const e=ae(),n=wn(1);return h.jsx(H,{...e.cut,disabled:!n})}function kte(){const e=ae(),n=CJ(1);return h.jsx(H,{...e.copy,disabled:!n})}function Tte(){const e=ae(),n=PJ;return h.jsx(H,{...e.paste,disabled:!n})}function zj(){const e=N(),n=ae();return W("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?h.jsxs(ye,{id:"conversions",children:[h.jsx(Ete,{}),h.jsxs(Bn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[h.jsxs(ye,{id:"export-as-group",children:[h.jsx(H,{...n["export-as-svg"]}),h.jsx(H,{...n["export-as-png"]}),h.jsx(H,{...n["export-as-json"]})]}),h.jsx(ye,{id:"export-as-bg",children:h.jsx(Dw,{})})]})]}):null}function Nj(){const e=ae(),n=N(),t=W("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return h.jsx(H,{...e["select-all"],disabled:!t})}function $te(){const e=ae(),n=wn(1);return h.jsx(H,{...e.delete,disabled:!n})}function Mte(){return h.jsxs(Bn,{id:"edit",label:"context-menu.edit",size:"small",children:[h.jsx($j,{}),h.jsx(Mj,{}),h.jsx(Tj,{}),h.jsx(kj,{}),h.jsx(jj,{}),h.jsx(Aj,{}),h.jsx(Uj,{}),h.jsx(Bj,{}),h.jsx(_j,{}),h.jsx(Oj,{})]})}function Ate(){const e=wn(2),n=EJ(),t=ae();return e||n?h.jsxs(Bn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&h.jsxs(ye,{id:"align",children:[h.jsx(H,{...t["align-left"]}),h.jsx(H,{...t["align-center-horizontal"]}),h.jsx(H,{...t["align-right"]}),h.jsx(H,{...t["align-top"]}),h.jsx(H,{...t["align-center-vertical"]}),h.jsx(H,{...t["align-bottom"]})]}),h.jsx(jte,{}),e&&h.jsxs(ye,{id:"stretch",children:[h.jsx(H,{...t["stretch-horizontal"]}),h.jsx(H,{...t["stretch-vertical"]})]}),(e||n)&&h.jsxs(ye,{id:"flip",children:[h.jsx(H,{...t["flip-horizontal"]}),h.jsx(H,{...t["flip-vertical"]})]}),h.jsx(Ote,{})]}):null}function jte(){const e=ae();return wn(3)?h.jsxs(ye,{id:"distribute",children:[h.jsx(H,{...e["distribute-horizontal"]}),h.jsx(H,{...e["distribute-vertical"]})]}):null}function Ote(){const e=ae(),n=wn(2),t=KA();return n?h.jsxs(ye,{id:"order",children:[h.jsx(H,{...e.pack}),t&&h.jsx(H,{...e["stack-horizontal"]}),t&&h.jsx(H,{...e["stack-vertical"]})]}):null}function Dte(){const e=ae();return wn(1)?h.jsx(Bn,{id:"reorder",label:"context-menu.reorder",size:"small",children:h.jsxs(ye,{id:"reorder",children:[h.jsx(H,{...e["bring-to-front"]}),h.jsx(H,{...e["bring-forward"]}),h.jsx(H,{...e["send-backward"]}),h.jsx(H,{...e["send-to-back"]})]})}):null}function Rte(){const e=N(),n=W("pages",()=>e.getPages(),[e]),t=W("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Xr(),o=ae(),s=Yr();return wn(1)?h.jsxs(Bn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[h.jsx(ye,{id:"pages",children:n.map(a=>h.jsx(H,{id:a.id,disabled:t===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const c=e.getPage(a.id);c&&r({title:"Changed Page",description:`Moved to ${c.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),h.jsx(ye,{id:"new-page",children:h.jsx(H,{...o["new-page"]})})]}):null}function Bj(){const e=N(),n=ae();return W("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(H,{...n["convert-to-bookmark"]}):null}function Uj(){const e=N(),n=ae();return W("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&Ms(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(H,{...n["convert-to-embed"]}):null}function Lte(){const e=ae(),n=N(),t=W("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return h.jsx(lr,{...e["toggle-snap-mode"],checked:t})}function Fte(){const e=ae(),n=N(),t=W("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return h.jsx(lr,{...e["toggle-tool-lock"],checked:t})}function zte(){const e=ae(),n=N(),t=W("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return h.jsx(lr,{...e["toggle-grid"],checked:t})}function Nte(){const e=ae(),n=N(),t=W("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return h.jsx(lr,{...e["toggle-wrap-mode"],checked:t})}function Bte(){const e=ae(),n=N(),t=W("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return h.jsx(lr,{...e["toggle-focus-mode"],checked:t})}function Ute(){const e=ae(),n=N(),t=W("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return h.jsx(lr,{...e["toggle-edge-scrolling"],checked:t===1})}function Hte(){const e=ae(),n=N(),t=W("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return h.jsx(lr,{...e["toggle-reduce-motion"],checked:t===0})}function Kte(){const e=ae(),n=N(),t=W("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return h.jsx(lr,{...e["toggle-debug-mode"],checked:t})}function Wte(){const e=ae(),n=N(),t=W("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return h.jsx(lr,{...e["toggle-dynamic-size-mode"],checked:t})}function Gte(){const e=N();return W("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?h.jsxs(h.Fragment,{children:[h.jsxs(ye,{id:"modify",children:[h.jsx(Mte,{}),h.jsx(Ate,{}),h.jsx(Dte,{}),h.jsx(Rte,{})]}),h.jsx(Fj,{}),h.jsx(zj,{}),h.jsx(ye,{id:"select-all",children:h.jsx(Nj,{})})]}):null}const Vte=x.memo(function({children:n}){const t=N(),{Canvas:r}=at(),o=x.useCallback(l=>{if(l){if(t.getInstanceState().isCoarsePointer){const d=t.getSelectedShapes(),{inputs:{currentPagePoint:u}}=t,f=t.getShapesAtPoint(u);if(!t.getSelectedShapes().length||!f.some(p=>d.includes(p))){const p=f.filter(S=>t.isShapeOrAncestorLocked(S));p.length&&t.select(...p.map(S=>S.id))}}}else{const d=t.getOnlySelectedShape();d&&t.isShapeOrAncestorLocked(d)&&t.setSelectedShapes([])}},[t]),s=dn(),[i,a]=ai("context menu",o),c=n??h.jsx(Gte,{});return h.jsxs(Aee,{dir:"ltr",onOpenChange:a,modal:!1,children:[h.jsx(jee,{onContextMenu:void 0,dir:"ltr",children:r?h.jsx(r,{}):null}),i&&h.jsx(Oee,{container:s,children:h.jsx(Dee,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:_e,children:h.jsx(Ir,{type:"context-menu",sourceId:"context-menu",children:c})})})]})});function Kv({checked:e}){return h.jsx(Xs,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function Yte(){const e=N(),{addToast:n}=Xr(),{addDialog:t}=sa(),[r,o]=ve.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(ye,{id:"items",children:[h.jsx(H,{id:"add-toast",onSelect:()=>{n({id:st(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),n({id:st(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"info",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),n({id:st(),title:"Something maybe bad happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"warning",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),n({id:st(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),h.jsx(H,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>h.jsx(Zte,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),h.jsx(H,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>Qte(e,100)}),h.jsx(H,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const s=e.getSelectedShapes(),i=s.length===0?e.getRenderingShapes():s;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),h.jsx(H,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),h.jsx(H,{id:"hard-reset",onSelect:Nk,label:"Hard reset"})]}),h.jsxs(ye,{id:"flags",children:[h.jsx(Xte,{}),h.jsx(qte,{})]})]})}function Xte(){const e=Object.values(wt);return e.length?h.jsx(Bn,{id:"debug flags",label:"Debug Flags",children:h.jsx(ye,{id:"debug flags",children:e.map(n=>h.jsx(Hj,{flag:n},n.name))})}):null}function qte(){const e=Object.values(g7);return e.length?h.jsx(Bn,{id:"feature flags",label:"Feature Flags",children:h.jsx(ye,{id:"feature flags",children:e.map(n=>h.jsx(Hj,{flag:n},n.name))})}):null}function Zte({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,c]=ve.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(yg,{children:[h.jsx(Sg,{children:e}),h.jsx(vg,{})]}),h.jsx(pd,{style:{maxWidth:350},children:n}),h.jsxs(fw,{className:"tlui-dialog__footer__actions",children:[o&&h.jsxs(fe,{type:"normal",onClick:()=>c(!a),style:{marginRight:"auto"},children:[h.jsx(Kv,{checked:a}),h.jsx(Pt,{children:"Don’t show again"})]}),h.jsx(fe,{type:"normal",onClick:s,children:h.jsx(Pt,{children:t})}),h.jsx(fe,{type:"primary",onClick:async()=>i(),children:h.jsx(Pt,{children:r})})]})]})}const Hj=sr(function({flag:n,onChange:t}){const r=n.get();return h.jsx(lr,{id:n.name,title:n.name,label:n.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{n.set(!r),t==null||t(!r)}})});let AI=0;function Qte(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)AI++,t[o]={id:Fe("box"+AI),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function Jte({children:e}){const n=e??h.jsx(Yte,{});return h.jsxs(Xi,{id:"debug",children:[h.jsx(qi,{children:h.jsx(fe,{type:"icon",title:"Debug menu",children:h.jsx(Pe,{icon:"dots-horizontal"})})}),h.jsx(Zi,{side:"top",align:"end",alignOffset:0,children:h.jsx(Ir,{type:"menu",sourceId:"debug-panel",children:n})})]})}const ene=x.memo(function(){const{DebugMenu:n}=di();return h.jsxs("div",{className:"tlui-debug-panel",children:[h.jsx(nne,{}),h.jsx(rne,{}),n&&h.jsx(n,{})]})});function tne(e=!0){const[n,t]=x.useState(0),r=N();x.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const nne=sr(function(){tne();const n=N(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),s=t==="select.idle"||!t.includes("select.")?r:o,i=s&&t.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${b.ToInt(n.getPointInShapeSpace(s,n.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${b.ToInt(n.inputs.originPagePoint)}] → [${b.ToInt(n.inputs.currentPagePoint)}] = ${b.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return h.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function rne(){const e=N(),n=W("show_fps",()=>wt.showFps.get(),[wt]),t=x.useRef(null);return x.useEffect(()=>{if(!n)return;const r=250;let o=0,s=-1,i=performance.now(),a=0,c=0,l=!1;function d(){if(c++,a=performance.now()-i,a>r){const u=Math.round(c*(r/a)*(1e3/r));u>o&&(o=u);const f=o*.75;(u<f&&!l||u>=f&&l)&&(l=!l),t.current.innerHTML=`FPS ${u.toString()}`,t.current.className="tlui-debug-panel__fps"+(l?" tlui-debug-panel__fps__slow":""),a-=r,c=0,i=performance.now()}s=e.timers.requestAnimationFrame(d)}return d(),()=>{cancelAnimationFrame(s)}},[n,e]),n?h.jsx("div",{ref:t}):null}function Kj(){const e=N(),n=Yr(),t=W("locale",()=>e.user.getLocale(),[e]);return h.jsx(Bn,{id:"help menu language",label:"menu.language",children:h.jsx(ye,{id:"languages",children:Vl.map(({locale:r,label:o})=>h.jsx(lr,{id:`language-${r}`,title:r,label:o,checked:r===t,onSelect:()=>{e.user.updateUserPreferences({locale:r}),n("change-language",{source:"menu",locale:r})}},r))})})}function one(){return h.jsxs(h.Fragment,{children:[h.jsx(Kj,{}),h.jsx(sne,{})]})}function sne(){const{KeyboardShortcutsDialog:e}=di(),{addDialog:n}=sa();return e?h.jsx(H,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const ine=x.memo(function({children:n}){const t=$e(),r=Nn(),o=n??h.jsx(one,{});return r<vt.MOBILE?null:h.jsx("div",{className:"tlui-help-menu",children:h.jsxs(Xi,{id:"help menu",children:[h.jsx(qi,{children:h.jsx(fe,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:h.jsx(Pe,{icon:"question-mark",small:!0})})}),h.jsx(Zi,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:h.jsx(Ir,{type:"menu",sourceId:"help-menu",children:o})})]})})});function ane(){const e=N(),n=ae(),[t,r]=x.useState(!1),o=x.useRef(!1);return js("toggle showback to content",()=>{const s=o.current,i=e.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===e.getCulledShapes().size),s!==a&&(r(a),o.current=a)},[e]),t?h.jsx(H,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function cne(){const e=N(),n=ae();return W("is pen mode",()=>e.getInstanceState().isPenMode,[e])?h.jsx(H,{...n["exit-pen-mode"]}):null}function lne(){const e=N(),n=ae();return W("is following user",()=>!!e.getInstanceState().followingUserId,[e])?h.jsx(H,{...n["stop-following"]}):null}function dne(){return h.jsxs(h.Fragment,{children:[h.jsx(cne,{}),h.jsx(ane,{}),h.jsx(lne,{})]})}function une({children:e}){const n=e??h.jsx(dne,{});return h.jsx("div",{className:"tlui-helper-buttons",children:h.jsx(Ir,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}function hne(){const e=ae(),n=xg();return h.jsxs(h.Fragment,{children:[h.jsxs(ye,{label:"shortcuts-dialog.tools",id:"tools",children:[h.jsx(H,{...e["toggle-tool-lock"]}),h.jsx(H,{...e["insert-media"]}),h.jsx(H,{...n.select}),h.jsx(H,{...n.draw}),h.jsx(H,{...n.eraser}),h.jsx(H,{...n.hand}),h.jsx(H,{...n.rectangle}),h.jsx(H,{...n.ellipse}),h.jsx(H,{...n.arrow}),h.jsx(H,{...n.line}),h.jsx(H,{...n.text}),h.jsx(H,{...n.frame}),h.jsx(H,{...n.note}),h.jsx(H,{...n.laser})]}),h.jsxs(ye,{label:"shortcuts-dialog.preferences",id:"preferences",children:[h.jsx(H,{...e["toggle-dark-mode"]}),h.jsx(H,{...e["toggle-focus-mode"]}),h.jsx(H,{...e["toggle-grid"]})]}),h.jsxs(ye,{label:"shortcuts-dialog.edit",id:"edit",children:[h.jsx(H,{...e.undo}),h.jsx(H,{...e.redo}),h.jsx(H,{...e.cut}),h.jsx(H,{...e.copy}),h.jsx(H,{...e.paste}),h.jsx(H,{...e["select-all"]}),h.jsx(H,{...e.delete}),h.jsx(H,{...e.duplicate})]}),h.jsxs(ye,{label:"shortcuts-dialog.view",id:"view",children:[h.jsx(H,{...e["zoom-in"]}),h.jsx(H,{...e["zoom-out"]}),h.jsx(H,{...e["zoom-to-100"]}),h.jsx(H,{...e["zoom-to-fit"]}),h.jsx(H,{...e["zoom-to-selection"]})]}),h.jsxs(ye,{label:"shortcuts-dialog.transform",id:"transform",children:[h.jsx(H,{...e["bring-to-front"]}),h.jsx(H,{...e["bring-forward"]}),h.jsx(H,{...e["send-backward"]}),h.jsx(H,{...e["send-to-back"]}),h.jsx(H,{...e.group}),h.jsx(H,{...e.ungroup}),h.jsx(H,{...e["flip-horizontal"]}),h.jsx(H,{...e["flip-vertical"]}),h.jsx(H,{...e["align-top"]}),h.jsx(H,{...e["align-center-vertical"]}),h.jsx(H,{...e["align-bottom"]}),h.jsx(H,{...e["align-left"]}),h.jsx(H,{...e["align-center-horizontal"]}),h.jsx(H,{...e["align-right"]})]})]})}const fne=x.memo(function({children:n}){const t=$e(),r=Nn(),o=n??h.jsx(hne,{});return h.jsxs(h.Fragment,{children:[h.jsxs(yg,{className:"tlui-shortcuts-dialog__header",children:[h.jsx(Sg,{children:t("shortcuts-dialog.title")}),h.jsx(vg,{})]}),h.jsx(pd,{className:de("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=vt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=vt.TABLET}),children:h.jsx(Ir,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),h.jsx("div",{className:"tlui-dialog__scrim"})]})}),pne=[{colorScheme:"light",label:"color-scheme.light"},{colorScheme:"dark",label:"color-scheme.dark"},{colorScheme:"system",label:"color-scheme.system"}];function gne(){const e=N(),n=Yr(),t=W("colorScheme",()=>e.user.getUserPreferences().colorScheme,[e]);return h.jsx(Bn,{id:"help menu color-scheme",label:"menu.color-scheme",children:h.jsx(ye,{id:"languages",children:pne.map(({colorScheme:r,label:o})=>h.jsx(lr,{id:`color-scheme-${r}`,label:o,checked:r===t,onSelect:()=>{e.user.updateUserPreferences({colorScheme:r}),n("color-scheme",{source:"menu",value:r})}},r))})})}function mne(){return h.jsxs(h.Fragment,{children:[h.jsx(Sne,{}),h.jsx(bne,{}),h.jsx(yne,{}),h.jsx(Pne,{}),h.jsx(Cne,{})]})}function yne(){const e=ae();return h.jsxs(Bn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[h.jsxs(ye,{id:"export-all-as-group",children:[h.jsx(H,{...e["export-all-as-svg"]}),h.jsx(H,{...e["export-all-as-png"]}),h.jsx(H,{...e["export-all-as-json"]})]}),h.jsx(ye,{id:"export-all-as-bg",children:h.jsx(Dw,{})})]})}function Sne(){const e=N(),n=W("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return h.jsxs(Bn,{id:"edit",label:"menu.edit",disabled:!n,children:[h.jsx(wne,{}),h.jsx(Fj,{}),h.jsx(zj,{}),h.jsx(vne,{}),h.jsx(xne,{}),h.jsx(ye,{id:"select-all",children:h.jsx(Nj,{})})]})}function vne(){return h.jsxs(ye,{id:"misc",children:[h.jsx($j,{}),h.jsx(Mj,{}),h.jsx(kj,{}),h.jsx(_j,{}),h.jsx(Aj,{}),h.jsx(jj,{}),h.jsx(Uj,{}),h.jsx(Bj,{}),h.jsx(Tj,{})]})}function xne(){return h.jsxs(ye,{id:"lock",children:[h.jsx(Oj,{}),h.jsx(Ite,{})]})}function wne(){const e=ae(),n=XA(),t=YA();return h.jsxs(ye,{id:"undo-redo",children:[h.jsx(H,{...e.undo,disabled:!n}),h.jsx(H,{...e.redo,disabled:!t})]})}function bne(){const e=ae();return h.jsx(Bn,{id:"view",label:"menu.view",children:h.jsxs(ye,{id:"view-actions",children:[h.jsx(H,{...e["zoom-in"]}),h.jsx(H,{...e["zoom-out"]}),h.jsx(Dj,{}),h.jsx(Rj,{}),h.jsx(Lj,{})]})})}function Pne(){const e=ae();return h.jsxs(ye,{id:"extras",children:[h.jsx(H,{...e["insert-embed"]}),h.jsx(H,{...e["insert-media"]})]})}function Cne(){return h.jsx(ye,{id:"preferences",children:h.jsxs(Bn,{id:"preferences",label:"menu.preferences",children:[h.jsxs(ye,{id:"preferences-actions",children:[h.jsx(Lte,{}),h.jsx(Fte,{}),h.jsx(zte,{}),h.jsx(Nte,{}),h.jsx(Bte,{}),h.jsx(Ute,{}),h.jsx(Hte,{}),h.jsx(Wte,{}),h.jsx(Kte,{})]}),h.jsx(ye,{id:"color-scheme",children:h.jsx(gne,{})}),h.jsx(ye,{id:"language",children:h.jsx(Kj,{})})]})})}const Ine=x.memo(function({children:n}){const t=dn(),[r,o]=ai("main menu"),s=$e(),i=n??h.jsx(mne,{});return h.jsxs(Aw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(jw,{asChild:!0,dir:"ltr",children:h.jsx(fe,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:h.jsx(Pe,{icon:"menu",small:!0})})}),h.jsx(_g,{container:t,children:h.jsx(Ow,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:h.jsx(Ir,{type:"menu",sourceId:"main-menu",children:i})})})]})}),Ene=x.memo(function(){const n=Nn(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=di();return!t&&!s&&n<6?null:h.jsx("div",{className:"tlui-menu-zone",children:h.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&h.jsx(t,{}),s&&h.jsx(s,{}),n<6?null:h.jsxs(h.Fragment,{children:[r&&h.jsx(r,{}),o&&h.jsx(o,{})]})]})})}),wy={};function hl(e){if(wy[e])return wy[e];const t=document.createElement("canvas").getContext("2d");t.fillStyle=e,t.fillRect(0,0,1,1);const[r,o,s,i]=t.getImageData(0,0,1,1).data,a=new Float32Array([r/255,o/255,s/255,i/255]);return wy[e]=a,a}const uf=10,Wj=4*6*uf+12+4*12;function ba(e,{center:n,radius:t,numArcSegments:r=20,startAngle:o=0,endAngle:s=De,offset:i=0}){const a=(s-o)/r;let c=i;for(let l=o;l<s;l+=a)e[c++]=n.x,e[c++]=n.y,e[c++]=n.x+Math.cos(l)*t,e[c++]=n.y+Math.sin(l)*t,e[c++]=n.x+Math.cos(l+a)*t,e[c++]=n.y+Math.sin(l+a)*t;return e}function Pa(e,n,t,r,o,s){e[n++]=t,e[n++]=r,e[n++]=t,e[n++]=r+s,e[n++]=t+o,e[n++]=r,e[n++]=t+o,e[n++]=r,e[n++]=t,e[n++]=r+s,e[n++]=t+o,e[n++]=r+s}function _ne(e,n,t){const r=uf;t=Math.min(t,Math.min(n.w,n.h)/2);const o=J.ExpandBy(n,-t);if(o.w<=0||o.h<=0)return ba(e,{center:n.center,radius:t,numArcSegments:uf*4}),uf*4*6;let s=0;return Pa(e,s,o.minX,o.minY,o.w,o.h),s+=12,Pa(e,s,o.minX,n.minY,o.w,t),s+=12,Pa(e,s,o.maxX,o.minY,t,o.h),s+=12,Pa(e,s,o.minX,o.maxY,o.w,t),s+=12,Pa(e,s,n.minX,o.minY,t,o.h),s+=12,ba(e,{numArcSegments:r,offset:s,center:o.point,radius:t,startAngle:ke,endAngle:ke*1.5}),s+=r*6,ba(e,{numArcSegments:r,offset:s,center:b.Add(o.point,new b(o.w,0)),radius:t,startAngle:ke*1.5,endAngle:De}),s+=r*6,ba(e,{numArcSegments:r,offset:s,center:b.Add(o.point,o.size),radius:t,startAngle:0,endAngle:Ve}),s+=r*6,ba(e,{numArcSegments:r,offset:s,center:b.Add(o.point,new b(0,o.h)),radius:t,startAngle:Ve,endAngle:ke}),Wj}function kne(e){if(!e)throw new Error("Canvas element not found");const n=e.getContext("webgl2",{premultipliedAlpha:!1});if(!n)throw new Error("Failed to get webgl2 context");const t=`#version 300 es
|
|
282
|
-
precision mediump float;
|
|
283
|
-
|
|
284
|
-
in vec2 shapeVertexPosition;
|
|
285
|
-
|
|
286
|
-
uniform vec4 canvasPageBounds;
|
|
287
|
-
|
|
288
|
-
// taken (with thanks) from
|
|
289
|
-
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
|
|
290
|
-
void main() {
|
|
291
|
-
// convert the position from pixels to 0.0 to 1.0
|
|
292
|
-
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
|
|
293
|
-
|
|
294
|
-
// convert from 0->1 to 0->2
|
|
295
|
-
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
296
|
-
|
|
297
|
-
// convert from 0->2 to -1->+1 (clipspace)
|
|
298
|
-
vec2 clipSpace = zeroToTwo - 1.0;
|
|
299
|
-
|
|
300
|
-
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
301
|
-
}`,r=n.createShader(n.VERTEX_SHADER);if(!r)throw new Error("Failed to create vertex shader");if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS))throw new Error("Failed to compile vertex shader");const o=`#version 300 es
|
|
302
|
-
precision mediump float;
|
|
303
|
-
|
|
304
|
-
uniform vec4 fillColor;
|
|
305
|
-
out vec4 outputColor;
|
|
306
|
-
|
|
307
|
-
void main() {
|
|
308
|
-
outputColor = fillColor;
|
|
309
|
-
}`,s=n.createShader(n.FRAGMENT_SHADER);if(!s)throw new Error("Failed to create fragment shader");if(n.shaderSource(s,o),n.compileShader(s),!n.getShaderParameter(s,n.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=n.createProgram();if(!i)throw new Error("Failed to create program");if(n.attachShader(i,r),n.attachShader(i,s),n.linkProgram(i),!n.getProgramParameter(i,n.LINK_STATUS))throw new Error("Failed to link program");n.useProgram(i);const a=n.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");n.enableVertexAttribArray(a);const c=n.getUniformLocation(i,"canvasPageBounds"),l=n.getUniformLocation(i,"fillColor");if(!n.createBuffer())throw new Error("Failed to create buffer");if(!n.createBuffer())throw new Error("Failed to create buffer");return{context:n,selectedShapes:sh(n,1024),unselectedShapes:sh(n,4096),viewport:sh(n,Wj),collaborators:sh(n,1024),prepareTriangles(f,p){n.bindBuffer(n.ARRAY_BUFFER,f.buffer),n.bufferData(n.ARRAY_BUFFER,f.vertices,n.STATIC_DRAW,0,p),n.enableVertexAttribArray(a),n.vertexAttribPointer(a,2,n.FLOAT,!1,0,0)},drawTrianglesTransparently(f){n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.drawArrays(n.TRIANGLES,0,f/2),n.disable(n.BLEND)},drawTriangles(f){n.drawArrays(n.TRIANGLES,0,f/2)},setFillColor(f){n.uniform4fv(l,f)},setCanvasPageBounds(f){n.uniform4fv(c,f)}}}function sh(e,n){const t=e.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(n)}}function jI(e,n,t){let r=e.vertices.length;for(;r<n+t.length;)r*=2;if(r!=e.vertices.length){const o=new Float32Array(r);o.set(e.vertices),e.vertices=o}e.vertices.set(t,n)}var Tne=Object.defineProperty,$ne=Object.getOwnPropertyDescriptor,li=(e,n,t,r)=>{for(var o=$ne(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&Tne(n,t,o),o};class us{constructor(n,t,r){m(this,"disposables",[]);m(this,"close",()=>this.disposables.forEach(n=>n()));m(this,"gl");m(this,"shapeGeometryCache");m(this,"colors");m(this,"id",st());m(this,"canvasBoundingClientRect",Mt("canvasBoundingClientRect",new J));m(this,"originPagePoint",new b);m(this,"originPageCenter",new b);m(this,"isInViewport",!1);m(this,"getMinimapPagePoint",(n,t)=>{const r=this.getCanvasPageBounds(),o=this.getCanvasScreenBounds();let s=n-o.x,i=t-o.y;return s*=r.width/o.width,i*=r.height/o.height,s+=r.minX,i+=r.minY,new b(s,i,1)});m(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:c}=this.getMinimapPagePoint(n,t);if(o){const l=this.editor.getCurrentPageBounds()??new J,d=l.minX-i.width/2,u=l.maxX+i.width/2,f=l.minY-i.height/2,p=l.maxY+i.height/2,S=Math.max(0,d+i.width-a),g=Math.max(0,-(u-i.width-a)),w=Math.max(0,f+i.height-c),y=Math.max(0,-(p-i.height-c));a+=(S-g)/2,c+=(w-y)/2,a=Tt(a,d,u),c=Tt(c,f,p)}if(r){const{originPagePoint:l}=this,d=Math.abs(a-l.x),u=Math.abs(c-l.y);d>u?c=l.y:a=l.x}return new b(a,c)});m(this,"render",()=>{const n=this.gl.context,t=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=t.x,this.elem.height=t.y,n.viewport(0,0,t.x,t.y),n.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),n.clear(n.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),o=this.colors;let s=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let c=0,l=a.length;c<l;c++){const d=a[c],u=this.shapeGeometryCache.get(d);if(!u)continue;const f=u.length;r.has(d)?(jI(this.gl.selectedShapes,s,u),s+=f):(jI(this.gl.unselectedShapes,i,u),i+=f)}this.drawShapes(this.gl.unselectedShapes,i,o.shapeFill),this.drawShapes(this.gl.selectedShapes,s,o.selectFill),this.drawViewport(),this.drawCollaborators()});this.editor=n,this.elem=t,this.container=r,this.gl=kne(t),this.shapeGeometryCache=n.store.createComputedCache("webgl-geometry",o=>{const s=n.getShapeMaskedPageBounds(o.id);if(!s)return null;const i=new Float32Array(12);return Pa(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),ta("minimap render",this.render))}_getColors(){const n=getComputedStyle(this.editor.getContainer());return{shapeFill:hl(n.getPropertyValue("--color-text-3").trim()),selectFill:hl(n.getPropertyValue("--color-selected").trim()),viewportFill:hl(n.getPropertyValue("--color-muted-1").trim()),background:hl(n.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const n=this.editor.getViewportPageBounds(),t=this.editor.getCurrentPageBounds();return t?J.Expand(t,n):n}getContentScreenBounds(){const n=this.getContentPageBounds(),t=this.editor.pageToScreen(n.point),r=this.editor.pageToScreen(new b(n.maxX,n.maxY));return new J(t.x,t.y,r.x-t.x,r.y-t.y)}_getCanvasBoundingRect(){const{x:n,y:t,width:r,height:o}=this.elem.getBoundingClientRect();return new J(n,t,r,o)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const n=new ResizeObserver(()=>{const t=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(t)});return n.observe(this.elem),n.observe(this.container),()=>n.disconnect()}getCanvasSize(){const n=this.canvasBoundingClientRect.get(),t=this.getDpr();return new b(n.width*t,n.height*t)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const n=this.getCanvasScreenBounds(),t=this.getContentPageBounds(),r=n.width/n.height;let o=t.width,s=o/r;s<t.height&&(s=t.height,o=s*r);const i=new J(0,0,o,s);return i.center=t.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:n,y:t,w:r,h:o}=this.getCanvasPageBounds();return new Float32Array([n,t,r,o])}drawShapes(n,t,r){this.gl.prepareTriangles(n,t),this.gl.setFillColor(r),this.gl.drawTriangles(t)}drawViewport(){const n=this.editor.getViewportPageBounds(),t=_ne(this.gl.viewport.vertices,n,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,t),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(t),this.editor.environment.isSafari&&(this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t),this.gl.drawTrianglesTransparently(t))}drawCollaborators(){const n=this.editor.getCollaboratorsOnCurrentPage();if(!n.length)return;const t=20,r=t*6,o=r*n.length;this.gl.collaborators.vertices.length<o&&(this.gl.collaborators.vertices=new Float32Array(o));const s=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:c}of n)ba(s,{center:b.From(c),radius:3*a,offset:i,numArcSegments:t}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,o),i=0;for(const{color:c}of n)this.gl.setFillColor(hl(c)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}li([V],us.prototype,"getDpr");li([V],us.prototype,"getContentPageBounds");li([V],us.prototype,"getContentScreenBounds");li([V],us.prototype,"getCanvasSize");li([V],us.prototype,"getCanvasClientPosition");li([V],us.prototype,"getCanvasPageBounds");li([V],us.prototype,"getZoom");li([V],us.prototype,"getCanvasPageBoundsArray");function Mne(){const e=N(),n=dn(),t=x.useRef(null),r=x.useRef(!1),o=x.useRef();x.useEffect(()=>{try{const d=new us(e,t.current,n);return o.current=d,o.current.close}catch(d){e.annotateError(d,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw d})}},[e,n]);const s=x.useCallback(d=>{if(!e.getCurrentPageShapeIds().size||!o.current)return;const u=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),f=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);o.current.originPagePoint.setTo(f),o.current.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(u,{animation:{duration:e.options.animationMediumMs}})},[e]),i=x.useCallback(d=>{if(!o.current)return;const u=d.currentTarget;if(Od(u,d),!e.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const f=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),p=e.getViewportPageBounds(),S=o.current.getContentPageBounds();if(new J(S.x-p.width/2,S.y-p.height/2,S.width+p.width,S.height+p.height).containsPoint(f)&&!p.containsPoint(f)){o.current.isInViewport=p.containsPoint(f);const y=b.Sub(p.center,p.point),v=b.Add(f,y);o.current.originPagePoint.setTo(v),o.current.originPageCenter.setTo(f),e.centerOnPoint(f,{animation:{duration:e.options.animationMediumMs}})}else{const y=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);o.current.isInViewport=p.containsPoint(y),o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(p.center)}function w(y){u&&Dd(u,y),r.current=!1,document.body.removeEventListener("pointerup",w)}document.body.addEventListener("pointerup",w)},[e]),a=x.useCallback(d=>{if(!o.current)return;const u=o.current.minimapScreenPointToPagePoint(d.clientX,d.clientY,d.shiftKey,!0);if(r.current){if(o.current.isInViewport){const g=o.current.originPagePoint.clone().sub(o.current.originPageCenter);e.centerOnPoint(b.Sub(u,g));return}e.centerOnPoint(u)}const f=o.current.getMinimapPagePoint(d.clientX,d.clientY),p=e.pageToScreen(f),S={type:"pointer",target:"canvas",name:"pointer_move",...$n(d),point:p,isPen:e.getInstanceState().isPenMode};e.dispatch(S)},[e]),c=x.useCallback(d=>{const u=$k(d);e.dispatch({type:"wheel",name:"wheel",delta:u,point:new b(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey})},[e]),l=Kd();return x.useEffect(()=>{e.timers.setTimeout(()=>{var d,u;(d=o.current)==null||d.updateColors(),(u=o.current)==null||u.render()})},[l,e]),h.jsx("div",{className:"tlui-minimap",children:h.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:s,onPointerMove:a,onPointerDown:i,onWheel:c})})}function Ane(e,n){const[t,r]=ve.useState(n);ve.useLayoutEffect(()=>{const s=I0(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=ve.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return E0(e,JSON.stringify(a)),a})},[e]);return[t,o]}const jne=x.memo(function(){const n=ae(),t=$e(),r=Nn(),[o,s]=Ane("minimap",!0),i=x.useCallback(()=>{s(l=>!l)},[s]),{ZoomMenu:a,Minimap:c}=di();return r<vt.MOBILE?null:h.jsxs("div",{className:"tlui-navigation-panel",children:[h.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<vt.TABLET?h.jsx(a,{}):o?h.jsxs(h.Fragment,{children:[a&&h.jsx(a,{}),c&&h.jsx(fe,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):h.jsxs(h.Fragment,{children:[h.jsx(fe,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(gd(n["zoom-out"].label))} ${Hv(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:h.jsx(Pe,{icon:"minus"})}),a&&h.jsx(a,{}),h.jsx(fe,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(gd(n["zoom-in"].label))} ${Hv(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:h.jsx(Pe,{icon:"plus"})}),c&&h.jsx(fe,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(Pe,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=vt.TABLET&&!o&&h.jsx(c,{})]})}),One=function({name:n,id:t,isCurrentPage:r}){const o=N(),s=x.useRef(null),i=x.useCallback(()=>{o.mark("rename page")},[o]),a=x.useCallback(c=>{o.renamePage(t,c||"New Page")},[o,t]);return h.jsx(pw,{className:"tlui-page-menu__item__input",ref:c=>s.current=c,defaultValue:n,onValueChange:a,onFocus:i,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},Wv=(e,n,t,r)=>{let o;const s=e.getPages(),i=t>r?s[r-1]:s[r],a=t>r?s[r]:s[r+1];i&&!a?o=Lo(i.index):!i&&a?o=r4(s[0].index):o=Kl(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},OI=sr(function({index:n,listSize:t,item:r,onRename:o}){const s=N(),i=$e(),a=s.getPages(),c=x.useCallback(()=>{s.mark("creating page");const f=Xo.createId();s.duplicatePage(r.id,f)},[s,r]),l=x.useCallback(()=>{Wv(s,r.id,n,n-1)},[s,r,n]),d=x.useCallback(()=>{Wv(s,r.id,n,n+1)},[s,r,n]),u=x.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return h.jsxs(Xi,{id:`page item submenu ${n}`,children:[h.jsx(qi,{children:h.jsx(fe,{type:"icon",title:i("page-menu.submenu.title"),children:h.jsx(Pe,{icon:"dots-vertical"})})}),h.jsx(Zi,{alignOffset:0,side:"right",sideOffset:-4,children:h.jsxs(Ir,{type:"menu",sourceId:"page-menu",children:[h.jsxs(ye,{id:"modify",children:[o&&h.jsx(H,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),h.jsx(H,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=s.options.maxPages}),n>0&&h.jsx(H,{id:"move-up",onSelect:l,label:"page-menu.submenu.move-up"}),n<t-1&&h.jsx(H,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:d})]}),t>1&&h.jsx(ye,{id:"delete",children:h.jsx(H,{id:"delete",onSelect:u,label:"page-menu.submenu.delete"})})]})})]})}),Dne=x.memo(function(){const n=N(),t=$e(),r=Nn(),o=x.useCallback(()=>w(!1),[]),[s,i]=ai("page-menu",o),a=36,c=x.useRef(null),l=W("pages",()=>n.getPages(),[n]),d=W("currentPage",()=>n.getCurrentPage(),[n]),u=W("currentPageId",()=>n.getCurrentPageId(),[n]),f=as(),p=W("maxPageCountReached",()=>n.getPages().length>=n.options.maxPages,[n]),S=W("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[g,w]=x.useState(!1),y=x.useCallback(()=>{f||w(T=>!T)},[f]),v=x.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,E]=x.useState(Object.fromEntries(l.map((T,M)=>[T.id,{y:M*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{E(Object.fromEntries(l.map((T,M)=>[T.id,{y:M*a,offsetY:0,isSelected:!1}])))},[a,l]),x.useEffect(()=>{s&&n.timers.requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${u}"]`);if(T){const M=c.current;if(!M)return;const R=T.offsetTop,A=M.scrollTop;R<A&&M.scrollTo({top:R});const O=R+a,L=M.scrollTop+M.offsetHeight;O>L&&M.scrollTo({top:O-M.offsetHeight})}})},[a,u,s,n]);const I=x.useCallback(T=>{const{clientY:M,currentTarget:R}=T,{dataset:{id:A,index:O}}=R;if(!A||!O)return;const L=v.current;Od(T.currentTarget,T),L.status="pointing",L.pointing={id:A,index:+O};const K=P[A].y;L.startY=M,L.startIndex=Math.max(0,Math.min(Math.round(K/a),l.length-1))},[a,l.length,P]),C=x.useCallback(T=>{const M=v.current;if(M.status==="pointing"){const{clientY:R}=T,A=R-M.startY;Math.abs(A)>5&&(M.status="dragging")}if(M.status==="dragging"){const{clientY:R}=T,A=R-M.startY,O=P[M.pointing.id],{startIndex:L,pointing:G}=M,K=O.y+A,B=Math.max(0,Math.min(Math.round(K/a),l.length-1)),U={...P};if(U[G.id]={y:O.y,offsetY:A,isSelected:!0},B!==M.dragIndex){M.dragIndex=B;for(let Y=0;Y<l.length;Y++){const Q=l[Y];if(Q.id===M.pointing.id)continue;let{y:le}=U[Q.id];B===L?le=Y*a:B<L?B<=Y&&Y<L?le=(Y+1)*a:le=Y*a:B>L&&(B>=Y&&Y>L?le=(Y-1)*a:le=Y*a),le!==U[Q.id].y&&(U[Q.id]={y:le,offsetY:0,isSelected:!0})}}E(U)}},[a,l,P]),_=x.useCallback(T=>{const M=v.current;if(M.status==="dragging"){const{id:R,index:A}=M.pointing;Wv(n,R,A,M.dragIndex)}Dd(T.currentTarget,T),M.status="idle"},[n]),k=x.useCallback(T=>{const M=v.current;T.key==="Escape"&&(M.status==="dragging"&&E(Object.fromEntries(l.map((R,A)=>[R.id,{y:A*a,offsetY:0,isSelected:!1}]))),M.status="idle")},[a,l]),j=x.useCallback(()=>{f||n.batch(()=>{n.mark("creating page");const T=Xo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),w(!0)})},[n,t,f]);return h.jsxs(Iw,{id:"pages",onOpenChange:i,open:s,children:[h.jsx(Ew,{"data-testid":"main.page-menu",children:h.jsxs(fe,{type:"menu",title:d.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[h.jsx("div",{className:"tlui-page-menu__name",children:d.name}),h.jsx(Pe,{icon:"chevron-down",small:!0})]})}),h.jsx(_w,{side:"bottom",align:"start",sideOffset:6,children:h.jsxs("div",{className:"tlui-page-menu__wrapper",children:[h.jsxs("div",{className:"tlui-page-menu__header",children:[h.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!f&&h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsx(fe,{type:"icon","data-testid":"page-menu.edit",title:t(g?"page-menu.edit-done":"page-menu.edit-start"),onClick:y,children:h.jsx(Pe,{icon:g?"check":"edit"})}),h.jsx(fe,{type:"icon","data-testid":"page-menu.create",title:t(p?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:p,onClick:j,children:h.jsx(Pe,{icon:"plus"})})]})]}),h.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*l.length+4},ref:c,children:l.map((T,M)=>{const R=P[T.id]??{position:M*40,offsetY:0};return g?h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===d.id?888:M,transform:`translate(0px, ${R.y+R.offsetY}px)`},children:[h.jsx(fe,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:I,onPointerUp:_,onPointerMove:C,onKeyDown:k,"data-id":T.id,"data-index":M,children:h.jsx(Pe,{icon:"drag-handle-dots"})}),r<vt.TABLET_SM&&S?h.jsxs(fe,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const A=window.prompt("Rename page",T.name);A&&A!==T.name&&n.renamePage(T.id,A)},onDoubleClick:y,children:[h.jsx(Kv,{checked:T.id===d.id}),h.jsx(Pt,{children:T.name})]}):h.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:h.jsx(One,{id:T.id,name:T.name,isCurrentPage:T.id===d.id})}),!f&&h.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":g,children:h.jsx(OI,{index:M,item:T,listSize:l.length})})]},T.id+"_editing"):h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[h.jsxs(fe,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(T.id),onDoubleClick:y,title:t("page-menu.go-to-page"),children:[h.jsx(Kv,{checked:T.id===d.id}),h.jsx(Pt,{children:T.name})]}),!f&&h.jsx("div",{className:"tlui-page_menu__item__submenu",children:h.jsx(OI,{index:M,item:T,listSize:l.length,onRename:()=>{if(n.environment.isIos){const A=window.prompt("Rename page",T.name);A&&A!==T.name&&n.renamePage(T.id,A)}else n.batch(()=>{w(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function Rne(){const e=ae(),n=N(),t=XA(),r=YA(),o=wn(1),s=as(),i=W("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]),a=ds(),c=o&&a;if(!(s&&!i))return h.jsxs(h.Fragment,{children:[h.jsx(H,{...e.undo,disabled:!t}),h.jsx(H,{...e.redo,disabled:!r}),h.jsx(H,{...e.delete,disabled:!c}),h.jsx(H,{...e.duplicate,disabled:!c})]})}const Lne=x.memo(function({children:n}){const t=n??h.jsx(Rne,{});return h.jsx(Ir,{type:"small-icons",sourceId:"quick-actions",children:t})}),Fne=Object.freeze([rr,Ri,Li,yo]);function Gj(e=Fne){const n=N();return W("getRelevantStyles",()=>{var s;const t=new fv(n.getSharedStyles()),r=!!((s=n.root.getCurrent())!=null&&s.shapeType),o=n.isIn("select")&&n.getSelectedShapeIds().length>0;if(t.size===0&&n.isIn("select")&&n.getSelectedShapeIds().length===0)for(const i of e)t.applyValue(i,n.getStyleForNextShape(i));return r||o||t.size>0?t:null},[n])}const wr={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},_i=x.memo(function(n){const{uiType:t,items:r,title:o,style:s,value:i,onValueChange:a,theme:c}=n,l=N(),d=$e(),u=x.useRef(!1),f=x.useRef(null),{handleButtonClick:p,handleButtonPointerDown:S,handleButtonPointerEnter:g,handleButtonPointerUp:w}=x.useMemo(()=>{const y=()=>{u.current=!1,window.removeEventListener("pointerup",y);const C=f.current;C&&["TEXTAREA","INPUT"].includes(C.nodeName)&&C.focus(),f.current=null};return{handleButtonClick:C=>{const{id:_}=C.currentTarget.dataset;i.type==="shared"&&i.value===_||(l.mark("point picker item"),a(s,_))},handleButtonPointerDown:C=>{const{id:_}=C.currentTarget.dataset;l.mark("point picker item"),a(s,_),u.current=!0,f.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:C=>{if(!u.current)return;const{id:_}=C.currentTarget.dataset;a(s,_)},handleButtonPointerUp:C=>{const{id:_}=C.currentTarget.dataset;i.type==="shared"&&i.value===_||a(s,_)}}},[i,l,a,s]);return h.jsx("div",{"data-testid":`style.${t}`,className:de("tlui-buttons__grid"),children:r.map(y=>h.jsx(fe,{type:"icon","data-id":y.value,"data-testid":`style.${t}.${y.value}`,"aria-label":y.value,"data-state":i.type==="shared"&&i.value===y.value?"hinted":void 0,title:o+" — "+d(`${t}-style.${y.value}`),className:de("tlui-button-grid__button"),style:s===rr?{color:c[y.value].solid}:void 0,onPointerEnter:g,onPointerDown:S,onPointerUp:w,onClick:p,children:h.jsx(Pe,{icon:y.icon})},y.value))})});function Vj(e,[n,t]){return Math.min(t,Math.max(n,e))}function zne(e){const n=x.useRef({value:e,previous:e});return x.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}const Yj=["PageUp","PageDown"],Xj=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],qj={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Vd="Slider",[Gv,Nne,Bne]=pg(Vd),[Zj,gse]=Co(Vd,[Bne]),[Une,kg]=Zj(Vd),Hne=x.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:c=0,defaultValue:l=[r],value:d,onValueChange:u=()=>{},onValueCommit:f=()=>{},inverted:p=!1,...S}=e,[g,w]=x.useState(null),y=Xe(n,O=>w(O)),v=x.useRef(new Set),P=x.useRef(0),E=i==="horizontal",I=g?!!g.closest("form"):!0,C=E?Kne:Wne,[_=[],k]=ii({prop:d,defaultProp:l,onChange:O=>{var L;(L=[...v.current][P.current])===null||L===void 0||L.focus(),u(O)}}),j=x.useRef(_);function T(O){const L=ere(_,O);A(O,L)}function M(O){A(O,P.current)}function R(){const O=j.current[P.current];_[P.current]!==O&&f(_)}function A(O,L,{commit:G}={commit:!1}){const K=ore(s),B=sre(Math.round((O-r)/s)*s+r,K),U=Vj(B,[r,o]);k((Y=[])=>{const Q=Qne(Y,U,L);if(rre(Q,c*s)){P.current=Q.indexOf(U);const le=String(Q)!==String(Y);return le&&G&&f(Q),le?Q:Y}else return Y})}return x.createElement(Une,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:P,thumbs:v.current,values:_,orientation:i},x.createElement(Gv.Provider,{scope:e.__scopeSlider},x.createElement(Gv.Slot,{scope:e.__scopeSlider},x.createElement(C,Z({"aria-disabled":a,"data-disabled":a?"":void 0},S,{ref:y,onPointerDown:ie(S.onPointerDown,()=>{a||(j.current=_)}),min:r,max:o,inverted:p,onSlideStart:a?void 0:T,onSlideMove:a?void 0:M,onSlideEnd:a?void 0:R,onHomeKeyDown:()=>!a&&A(r,0,{commit:!0}),onEndKeyDown:()=>!a&&A(o,_.length-1,{commit:!0}),onStepKeyDown:({event:O,direction:L})=>{if(!a){const B=Yj.includes(O.key)||O.shiftKey&&Xj.includes(O.key)?10:1,U=P.current,Y=_[U],Q=s*B*L;A(Y+Q,U,{commit:!0})}}})))),I&&_.map((O,L)=>x.createElement(Zne,{key:L,name:t?t+(_.length>1?"[]":""):void 0,value:O})))}),[Qj,Jj]=Zj(Vd,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Kne=x.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:c,onStepKeyDown:l,...d}=e,[u,f]=x.useState(null),p=Xe(n,P=>f(P)),S=x.useRef(),g=kw(o),w=g==="ltr",y=w&&!s||!w&&s;function v(P){const E=S.current||u.getBoundingClientRect(),I=[0,E.width],_=Rw(I,y?[t,r]:[r,t]);return S.current=E,_(P-E.left)}return x.createElement(Qj,{scope:e.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width"},x.createElement(eO,Z({dir:g,"data-orientation":"horizontal"},d,{ref:p,style:{...d.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:P=>{const E=v(P.clientX);i==null||i(E)},onSlideMove:P=>{const E=v(P.clientX);a==null||a(E)},onSlideEnd:()=>{S.current=void 0,c==null||c()},onStepKeyDown:P=>{const I=qj[y?"from-left":"from-right"].includes(P.key);l==null||l({event:P,direction:I?-1:1})}})))}),Wne=x.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:c,...l}=e,d=x.useRef(null),u=Xe(n,d),f=x.useRef(),p=!o;function S(g){const w=f.current||d.current.getBoundingClientRect(),y=[0,w.height],P=Rw(y,p?[r,t]:[t,r]);return f.current=w,P(g-w.top)}return x.createElement(Qj,{scope:e.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1},x.createElement(eO,Z({"data-orientation":"vertical"},l,{ref:u,style:{...l.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const w=S(g.clientY);s==null||s(w)},onSlideMove:g=>{const w=S(g.clientY);i==null||i(w)},onSlideEnd:()=>{f.current=void 0,a==null||a()},onStepKeyDown:g=>{const y=qj[p?"from-bottom":"from-top"].includes(g.key);c==null||c({event:g,direction:y?-1:1})}})))}),eO=x.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:c,...l}=e,d=kg(Vd,t);return x.createElement(He.span,Z({},l,{ref:n,onKeyDown:ie(e.onKeyDown,u=>{u.key==="Home"?(i(u),u.preventDefault()):u.key==="End"?(a(u),u.preventDefault()):Yj.concat(Xj).includes(u.key)&&(c(u),u.preventDefault())}),onPointerDown:ie(e.onPointerDown,u=>{const f=u.target;f.setPointerCapture(u.pointerId),u.preventDefault(),d.thumbs.has(f)?f.focus():r(u)}),onPointerMove:ie(e.onPointerMove,u=>{u.target.hasPointerCapture(u.pointerId)&&o(u)}),onPointerUp:ie(e.onPointerUp,u=>{const f=u.target;f.hasPointerCapture(u.pointerId)&&(f.releasePointerCapture(u.pointerId),s(u))})}))}),Gne="SliderTrack",Vne=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=kg(Gne,t);return x.createElement(He.span,Z({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),DI="SliderRange",Yne=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=kg(DI,t),s=Jj(DI,t),i=x.useRef(null),a=Xe(n,i),c=o.values.length,l=o.values.map(f=>tO(f,o.min,o.max)),d=c>1?Math.min(...l):0,u=100-Math.max(...l);return x.createElement(He.span,Z({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:d+"%",[s.endEdge]:u+"%"}}))}),RI="SliderThumb",Xne=x.forwardRef((e,n)=>{const t=Nne(e.__scopeSlider),[r,o]=x.useState(null),s=Xe(n,a=>o(a)),i=x.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return x.createElement(qne,Z({},e,{ref:s,index:i}))}),qne=x.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,s=kg(RI,t),i=Jj(RI,t),[a,c]=x.useState(null),l=Xe(n,w=>c(w)),d=$A(a),u=s.values[r],f=u===void 0?0:tO(u,s.min,s.max),p=Jne(r,s.values.length),S=d==null?void 0:d[i.size],g=S?tre(S,f,i.direction):0;return x.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${f}% + ${g}px)`}},x.createElement(Gv.ItemSlot,{scope:e.__scopeSlider},x.createElement(He.span,Z({role:"slider","aria-label":e["aria-label"]||p,"aria-valuemin":s.min,"aria-valuenow":u,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:l,style:u===void 0?{display:"none"}:e.style,onFocus:ie(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),Zne=e=>{const{value:n,...t}=e,r=x.useRef(null),o=zne(n);return x.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,c=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&c){const l=new Event("input",{bubbles:!0});c.call(s,n),s.dispatchEvent(l)}},[o,n]),x.createElement("input",Z({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function Qne(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function tO(e,n,t){const s=100/(t-n)*(e-n);return Vj(s,[0,100])}function Jne(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function ere(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 tre(e,n,t){const r=e/2,s=Rw([0,50],[0,r]);return(r-s(n)*t)*t}function nre(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function rre(e,n){if(n>0){const t=nre(e);return Math.min(...t)>=n}return!0}function Rw(e,n){return t=>{if(e[0]===e[1]||n[0]===n[1])return n[0];const r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-e[0])}}function ore(e){return(String(e).split(".")[1]||"").length}function sre(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const ire=Hne,are=Vne,cre=Yne,lre=Xne,dre=x.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=N(),c=$e(),l=x.useCallback(f=>{i(f[0])},[i]),d=x.useCallback(()=>{a.mark("click slider")},[a]),u=x.useCallback(()=>{o&&i(o)},[o,i]);return h.jsx("div",{className:"tlui-slider__container",children:h.jsxs(ire,{"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:d,onValueChange:l,onPointerUp:u,title:t+" — "+c(s),children:[h.jsx(are,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&h.jsx(cre,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&h.jsx(lre,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function ure({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:c,valueA:l,valueB:d,onValueChange:u}){const f=$e(),p=x.useMemo(()=>{var g;return((g=s.find(w=>l.type==="shared"&&l.value===w.value))==null?void 0:g.icon)??"mixed"},[s,l]),S=x.useMemo(()=>{var g;return((g=i.find(w=>d.type==="shared"&&d.value===w.value))==null?void 0:g.icon)??"mixed"},[i,d]);return l===void 0&&d===void 0?null:h.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[h.jsx("div",{title:f(e),className:"tlui-style-panel__double-select-picker-label",children:f(e)}),h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsxs(Xi,{id:`style panel ${n} A`,children:[h.jsx(qi,{children:h.jsx(fe,{type:"icon","data-testid":`style.${n}`,title:f(r)+" — "+(l===null||l.type==="mixed"?f("style-panel.mixed"):f(`${n}-style.${l.value}`)),children:h.jsx(Pe,{icon:p,small:!0,invertIcon:!0})})}),h.jsx(Zi,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,w)=>h.jsx(wd,{"data-testid":`style.${n}.${g.value}`,children:h.jsx(fe,{type:"icon",onClick:()=>u(a,g.value),title:`${f(r)} — ${f(`${n}-style.${g.value}`)}`,children:h.jsx(Pe,{icon:g.icon,invertIcon:!0})},g.value)},w))})})]}),h.jsxs(Xi,{id:`style panel ${t}`,children:[h.jsx(qi,{children:h.jsx(fe,{type:"icon","data-testid":`style.${t}`,title:f(o)+" — "+(d===null||d.type==="mixed"?f("style-panel.mixed"):f(`${t}-style.${d.value}`)),children:h.jsx(Pe,{icon:S,small:!0})})}),h.jsx(Zi,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>h.jsx(wd,{children:h.jsx(fe,{type:"icon",title:`${f(o)} — ${f(`${t}-style.${g.value}`)}`,"data-testid":`style.${t}.${g.value}`,onClick:()=>u(c,g.value),children:h.jsx(Pe,{icon:g.icon})})},g.value))})})]})]})]})}const hre=x.memo(ure);function fre({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const c=$e(),l=N(),d=x.useMemo(()=>{var p;return(p=o.find(S=>i.type==="shared"&&S.value===i.value))==null?void 0:p.icon},[o,i]),u=i.type==="mixed"?c("style-panel.mixed"):c(`${t}-style.${i.value}`),f=n?c(n):"";return h.jsxs(Xi,{id:`style panel ${e}`,children:[h.jsx(qi,{children:h.jsxs(fe,{type:s,"data-testid":`style.${t}`,title:u,children:[h.jsx(Pt,{children:f}),h.jsx(Pe,{icon:d??"mixed"})]})}),h.jsx(Zi,{side:"left",align:"center",alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:o.map(p=>h.jsx(wd,{children:h.jsx(fe,{type:"icon","data-testid":`style.${t}.${p.value}`,title:c(`${t}-style.${p.value}`),onClick:()=>{l.mark("select style dropdown item"),a(r,p.value)},children:h.jsx(Pe,{icon:p.icon})})},p.value))})})]})}const Lw=x.memo(fre);function pre({styles:e}){const n=Kd();if(!e)return null;const t=e.get(Lr),r=e.get($f),o=e.get(Tf),s=e.get(Of),i=e.get(mo),a=t===void 0,c=r===void 0&&o===void 0,l=s===void 0,d=i===void 0,u=ss({isDarkMode:n});return h.jsxs(h.Fragment,{children:[h.jsx(gre,{theme:u,styles:e}),!d&&h.jsx(mre,{theme:u,styles:e}),!(a&&c&&l)&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[h.jsx(yre,{styles:e}),h.jsx(vre,{styles:e}),h.jsx(Sre,{styles:e})]})]})}function Yd(){const e=N(),n=Yr();return ve.useMemo(()=>function(r,o){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,o),e.setStyleForNextShapes(r,o),e.updateInstanceState({isChangingStyle:!0})}),n("set-style",{source:"style-panel",id:r.id,value:o})},[e,n])}function gre({styles:e,theme:n}){const t=$e(),r=N(),o=Yd(),s=e.get(rr),i=e.get(Li),a=e.get(Ri),c=e.get(yo),l=i!==void 0||a!==void 0||c!==void 0;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:h.jsx(_i,{title:t("style-panel.color"),uiType:"color",style:rr,items:wr.color,value:s,onValueChange:o,theme:n}),h.jsx(xre,{})]}),l&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:h.jsx(_i,{title:t("style-panel.fill"),uiType:"fill",style:Li,items:wr.fill,value:i,onValueChange:o,theme:n}),a===void 0?null:h.jsx(_i,{title:t("style-panel.dash"),uiType:"dash",style:Ri,items:wr.dash,value:a,onValueChange:o,theme:n}),c===void 0?null:h.jsx(_i,{title:t("style-panel.size"),uiType:"size",style:yo,items:wr.size,value:c,onValueChange:(d,u)=>{o(d,u);const f=r.getSelectedShapeIds();f.length>0&&We(r,f)},theme:n})]})]})}function mre({theme:e,styles:n}){const t=$e(),r=Yd(),o=n.get(mo),s=n.get(pS),i=n.get(Af),a=n.get(jf);return o===void 0&&i===void 0?null:h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:h.jsx(_i,{title:t("style-panel.font"),uiType:"font",style:mo,items:wr.font,value:o,onValueChange:r,theme:e}),s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(_i,{title:t("style-panel.align"),uiType:"align",style:pS,items:wr.textAlign,value:s,onValueChange:r,theme:e}),h.jsx("div",{className:"tlui-style-panel__row__extra-button",children:h.jsx(fe,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:h.jsx(Pe,{icon:"vertical-align-middle"})})})]}),i===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(_i,{title:t("style-panel.align"),uiType:"align",style:Af,items:wr.horizontalAlign,value:i,onValueChange:r,theme:e}),h.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?h.jsx(fe,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:h.jsx(Pe,{icon:"vertical-align-middle"})}):h.jsx(Lw,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:jf,items:wr.verticalAlign,value:a,onValueChange:r})})]})]})}function yre({styles:e}){const n=Yd(),t=e.get(Lr);return t===void 0?null:h.jsx(Lw,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:Lr,items:wr.geo,value:t,onValueChange:n})}function Sre({styles:e}){const n=Yd(),t=e.get(Of);return t===void 0?null:h.jsx(Lw,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:Of,items:wr.spline,value:t,onValueChange:n})}function vre({styles:e}){const n=Yd(),t=e.get($f),r=e.get(Tf);return!t||!r?null:h.jsx(hre,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Tf,itemsA:wr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:$f,itemsB:wr.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const fl=[.1,.25,.5,.75,1];function xre(){const e=N(),n=W("opacity",()=>e.getSharedOpacity(),[e]),t=Yr(),r=$e(),o=ve.useCallback(i=>{const a=fl[i];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(a),e.setOpacityForNextShapes(a),e.updateInstanceState({isChangingStyle:!0})}),t("set-style",{source:"style-panel",id:"opacity",value:i})},[e,t]);if(n===void 0)return null;const s=n.type==="mixed"?-1:fl.indexOf(HN(fl,i=>Math.abs(i-n.value)));return h.jsx(dre,{"data-testid":"style.opacity",value:s>=0?s:fl.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:fl.length-1,title:r("style-panel.opacity")})}const wre=x.memo(function({isMobile:n,children:t}){const r=N(),o=Gj(),s=x.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1})},[r,n]),i=t??h.jsx(pre,{styles:o});return h.jsx("div",{className:de("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})});function bre(){const e=N(),n=$e(),t=Gj(),r=t==null?void 0:t.get(rr),o=ss({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=W("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(l=>{l||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:c}=di();return c?h.jsxs(Iw,{id:"mobile style menu",onOpenChange:a,children:[h.jsx(Ew,{children:h.jsx(fe,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),disabled:i,children:h.jsx(Pe,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),h.jsx(_w,{side:"top",align:"end",children:c&&h.jsx(c,{isMobile:!0})})]}):null}function Pre(){return h.jsxs(h.Fragment,{children:[h.jsx(Ire,{}),h.jsx(Ere,{}),h.jsx(_re,{}),h.jsx(kre,{}),h.jsx(Tre,{}),h.jsx($re,{}),h.jsx(Mre,{}),h.jsx(Are,{}),h.jsx(jre,{}),h.jsx(Ore,{}),h.jsx(Rre,{}),h.jsx(Dre,{}),h.jsx(zre,{}),h.jsx(Ure,{}),h.jsx(Lre,{}),h.jsx(Bre,{}),h.jsx(Nre,{}),h.jsx(Fre,{}),h.jsx(Hre,{}),h.jsx(Kre,{}),h.jsx(Wre,{}),h.jsx(Gre,{}),h.jsx(Vre,{}),h.jsx(Yre,{}),h.jsx(Xre,{}),h.jsx(qre,{}),h.jsx(Qre,{}),h.jsx(Zre,{})]})}function Cre(e){var r;const n=N(),t=(r=e.meta)==null?void 0:r.geo;return W("is tool selected",()=>{const o=n.getCurrentToolId(),s=n.getSharedStyles().getAsKnownValue(Lr);return t?o==="geo"&&s===t:o===e.id},[n,e.id,t])}function Ke({tool:e}){const n=xg(),t=Cre(n[e]);return h.jsx(H,{...n[e],isSelected:t})}function Ire(){return h.jsx(Ke,{tool:"select"})}function Ere(){return h.jsx(Ke,{tool:"hand"})}function _re(){return h.jsx(Ke,{tool:"draw"})}function kre(){return h.jsx(Ke,{tool:"eraser"})}function Tre(){return h.jsx(Ke,{tool:"arrow"})}function $re(){return h.jsx(Ke,{tool:"text"})}function Mre(){return h.jsx(Ke,{tool:"note"})}function Are(){const e=xg();return h.jsx(H,{...e.asset})}function jre(){return h.jsx(Ke,{tool:"rectangle"})}function Ore(){return h.jsx(Ke,{tool:"ellipse"})}function Dre(){return h.jsx(Ke,{tool:"diamond"})}function Rre(){return h.jsx(Ke,{tool:"triangle"})}function Lre(){return h.jsx(Ke,{tool:"rhombus"})}function Fre(){return h.jsx(Ke,{tool:"heart"})}function zre(){return h.jsx(Ke,{tool:"hexagon"})}function Nre(){return h.jsx(Ke,{tool:"cloud"})}function Bre(){return h.jsx(Ke,{tool:"star"})}function Ure(){return h.jsx(Ke,{tool:"oval"})}function Hre(){return h.jsx(Ke,{tool:"x-box"})}function Kre(){return h.jsx(Ke,{tool:"check-box"})}function Wre(){return h.jsx(Ke,{tool:"arrow-left"})}function Gre(){return h.jsx(Ke,{tool:"arrow-up"})}function Vre(){return h.jsx(Ke,{tool:"arrow-down"})}function Yre(){return h.jsx(Ke,{tool:"arrow-right"})}function Xre(){return h.jsx(Ke,{tool:"line"})}function qre(){return h.jsx(Ke,{tool:"highlight"})}function Zre(){return h.jsx(Ke,{tool:"frame"})}function Qre(){return h.jsx(Ke,{tool:"laser"})}const by=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function Py(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function pl(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function nO(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 rO(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 Jre(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 bd={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,"-":by?173:189,"=":by?61:187,";":by?59:186,"'":222,"[":219,"]":221,"\\":220},wo={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Vv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},zt={16:!1,18:!1,17:!1,91:!1},ht={};for(let e=1;e<20;e++)bd["f".concat(e)]=111+e;let Ge=[],Bl=null,oO="all";const Do=new Map,Xd=e=>bd[e.toLowerCase()]||wo[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),eoe=e=>Object.keys(bd).find(n=>bd[n]===e),toe=e=>Object.keys(wo).find(n=>wo[n]===e);function sO(e){oO=e||"all"}function Pd(){return oO||"all"}function noe(){return Ge.slice(0)}function roe(){return Ge.map(e=>eoe(e)||toe(e)||String.fromCharCode(e))}function ooe(){const e=[];return Object.keys(ht).forEach(n=>{ht[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=>Xd(a))})})}),e}function soe(e){const n=e.target||e.srcElement,{tagName:t}=n;let r=!0;const o=t==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(n.type);return(n.isContentEditable||(o||t==="TEXTAREA"||t==="SELECT")&&!n.readOnly)&&(r=!1),r}function ioe(e){return typeof e=="string"&&(e=Xd(e)),Ge.indexOf(e)!==-1}function aoe(e,n){let t,r;e||(e=Pd());for(const o in ht)if(Object.prototype.hasOwnProperty.call(ht,o))for(t=ht[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return Fw(a)}):r++;Pd()===e&&sO(n||"all")}function coe(e){let n=e.keyCode||e.which||e.charCode;const t=Ge.indexOf(n);if(t>=0&&Ge.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&Ge.splice(0,Ge.length),(n===93||n===224)&&(n=91),n in zt){zt[n]=!1;for(const r in wo)wo[r]===n&&(An[r]=!1)}}function iO(e){if(typeof e>"u")Object.keys(ht).forEach(o=>{Array.isArray(ht[o])&&ht[o].forEach(s=>ih(s)),delete ht[o]}),Fw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&ih(o)});else if(typeof e=="object")e.key&&ih(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=""),ih({key:e,scope:o,method:s,splitKey:"+"})}}const ih=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;rO(n).forEach(i=>{const a=i.split(o),c=a.length,l=a[c-1],d=l==="*"?"*":Xd(l);if(!ht[d])return;t||(t=Pd());const u=c>1?nO(wo,a):[],f=[];ht[d]=ht[d].filter(p=>{const g=(r?p.method===r:!0)&&p.scope===t&&Jre(p.mods,u);return g&&f.push(p.element),!g}),f.forEach(p=>Fw(p))})};function LI(e,n,t,r){if(n.element!==r)return;let o;if(n.scope===t||n.scope==="all"){o=n.mods.length>0;for(const s in zt)Object.prototype.hasOwnProperty.call(zt,s)&&(!zt[s]&&n.mods.indexOf(+s)>-1||zt[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!zt[16]&&!zt[18]&&!zt[17]&&!zt[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(Ge),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function FI(e,n){const t=ht["*"];let r=e.keyCode||e.which||e.charCode;if(!An.filter.call(this,e))return;if((r===93||r===224)&&(r=91),Ge.indexOf(r)===-1&&r!==229&&Ge.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const c=Vv[a];e[a]&&Ge.indexOf(c)===-1?Ge.push(c):!e[a]&&Ge.indexOf(c)>-1?Ge.splice(Ge.indexOf(c),1):a==="metaKey"&&e[a]&&Ge.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(Ge=Ge.slice(Ge.indexOf(c))))}),r in zt){zt[r]=!0;for(const a in wo)wo[a]===r&&(An[a]=!0);if(!t)return}for(const a in zt)Object.prototype.hasOwnProperty.call(zt,a)&&(zt[a]=e[Vv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(Ge.indexOf(17)===-1&&Ge.push(17),Ge.indexOf(18)===-1&&Ge.push(18),zt[17]=!0,zt[18]=!0);const o=Pd();if(t)for(let a=0;a<t.length;a++)t[a].scope===o&&(e.type==="keydown"&&t[a].keydown||e.type==="keyup"&&t[a].keyup)&&LI(e,t[a],o,n);if(!(r in ht))return;const s=ht[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const c=s[a],{splitKey:l}=c,d=c.key.split(l),u=[];for(let f=0;f<d.length;f++)u.push(Xd(d[f]));u.sort().join("")===Ge.sort().join("")&&LI(e,c,o,n)}}function An(e,n,t){Ge=[];const r=rO(e);let o=[],s="all",i=document,a=0,c=!1,l=!0,d="+",u=!1,f=!1;for(t===void 0&&typeof n=="function"&&(t=n),Object.prototype.toString.call(n)==="[object Object]"&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(c=n.keyup),n.keydown!==void 0&&(l=n.keydown),n.capture!==void 0&&(u=n.capture),typeof n.splitKey=="string"&&(d=n.splitKey),n.single===!0&&(f=!0)),typeof n=="string"&&(s=n),f&&iO(e,s);a<r.length;a++)e=r[a].split(d),o=[],e.length>1&&(o=nO(wo,e)),e=e[e.length-1],e=e==="*"?"*":Xd(e),e in ht||(ht[e]=[]),ht[e].push({keyup:c,keydown:l,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:d,element:i});if(typeof i<"u"&&window){if(!Do.has(i)){const p=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return FI(g,i)},S=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;FI(g,i),coe(g)};Do.set(i,{keydownListener:p,keyupListenr:S,capture:u}),Py(i,"keydown",p,u),Py(i,"keyup",S,u)}if(!Bl){const p=()=>{Ge=[]};Bl={listener:p,capture:u},Py(window,"focus",p,u)}}}function loe(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ht).forEach(t=>{ht[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function Fw(e){const n=Object.values(ht).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=Do.get(e)||{};r&&o&&(pl(e,"keyup",o,s),pl(e,"keydown",r,s),Do.delete(e))}if((n.length<=0||Do.size<=0)&&(Object.keys(Do).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=Do.get(o)||{};s&&i&&(pl(o,"keyup",i,a),pl(o,"keydown",s,a),Do.delete(o))}),Do.clear(),Object.keys(ht).forEach(o=>delete ht[o]),Bl)){const{listener:o,capture:s}=Bl;pl(window,"focus",o,s),Bl=null}}const Cy={getPressedKeyString:roe,setScope:sO,getScope:Pd,deleteScope:aoe,getPressedKeyCodes:noe,getAllKeyCodes:ooe,isPressed:ioe,filter:soe,trigger:loe,unbind:iO,keyMap:bd,modifier:wo,modifierMap:Vv};for(const e in Cy)Object.prototype.hasOwnProperty.call(Cy,e)&&(An[e]=Cy[e]);if(typeof window<"u"){const e=window.hotkeys;An.noConflict=n=>(n&&window.hotkeys===An&&(window.hotkeys=e),An),window.hotkeys=An}const zI=["copy","cut","paste","asset"];function doe(){const e=N(),n=as(),t=ae(),r=xg(),o=W("is focused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!o)return;const s=new Array,i=(c,l)=>{An(c,{element:document.body},l),s.push(()=>{An.unbind(c,l)})},a=(c,l)=>{An(c,{element:document.body,keyup:!0,keydown:!1},l),s.push(()=>{An.unbind(c,l)})};for(const c of Object.values(t))c.kbd&&(n&&!c.readonlyOk||zI.includes(c.id)||i(NI(c.kbd),l=>{Il(e)||(_e(l),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&e.getInstanceState().isReadonly||zI.includes(c.id)||i(NI(c.kbd),l=>{Il(e)||(_e(l),c.onSelect("kbd"))});return i(",",c=>{if(Il(e)||e.inputs.keys.has("Comma"))return;_e(c),e.focus(),e.inputs.keys.add("Comma");const{x:l,y:d,z:u}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_down",point:{x:l,y:d,z:u},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),a(",",c=>{if(Il(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:l,y:d,z:u}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_up",point:{x:l,y:d,z:u},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),()=>{s.forEach(c=>c())}},[t,r,n,e,o])}function NI(e){return uoe(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 uoe(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 Il(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const hoe=x.createContext(!1);function foe({children:e}){const n=N(),t=DW(),r=Nn(),o=$e(),s=Math.min(8,5+r),[i,a]=x.useState(0),c=x.useRef(null),[l,d]=x.useState(null),u=x.useMemo(()=>{const p=l?`:not([data-value="${l}"])`:"";return`
|
|
310
|
-
#${t}_main > *:nth-child(n + ${s+(l?1:2)})${p} {
|
|
311
|
-
display: none;
|
|
312
|
-
}
|
|
313
|
-
#${t}_more > *:nth-child(-n + ${s}) {
|
|
314
|
-
display: none;
|
|
315
|
-
}
|
|
316
|
-
`},[l,t,s]),f=Hx(()=>{if(!c.current)return;const p=Array.from(c.current.children);a(p.length),p.findIndex(w=>w.getAttribute("data-value")===l)<=s&&d(null);const g=Array.from(c.current.children).findIndex(w=>w.getAttribute("aria-checked")==="true");g!==-1&&g>=s&&d(p[g].getAttribute("data-value"))});return x.useLayoutEffect(()=>{f()}),x.useLayoutEffect(()=>{if(!c.current)return;const p=new MutationObserver(f);return p.observe(c.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{p.disconnect()}},[f]),x.useEffect(()=>{const p=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[S,g]of p)An(S,w=>{var P;if(Il(n))return;_e(w);const v=Array.from(((P=c.current)==null?void 0:P.children)??[]).filter(E=>!(E instanceof HTMLElement)||E.tagName.toLowerCase()!=="button"?!1:!!(E.offsetWidth||E.offsetHeight))[g];v&&v.click()});return()=>{An.unbind("1,2,3,4,5,6,7,8,9,0")}},[n]),h.jsxs(h.Fragment,{children:[h.jsx("style",{children:u}),h.jsxs("div",{className:de("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<vt.TABLET_SM}),role:"radiogroup",children:[h.jsx("div",{id:`${t}_main`,ref:c,className:"tlui-toolbar__tools__list",children:h.jsx(Ir,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s+1&&h.jsx(hoe.Provider,{value:!0,children:h.jsxs(Xi,{id:"toolbar overflow",modal:!1,children:[h.jsx(qi,{children:h.jsx(fe,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:h.jsx(Pe,{icon:"chevron-up"})})}),h.jsx(Zi,{side:"top",align:"center",children:h.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:h.jsx(Ir,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const poe=["select","hand","draw","eraser","text","zoom","laser","highlight"];function goe({activeToolId:e}){const n=N(),t=Nn(),r=$e(),o=W("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||poe.includes(e)?null:h.jsx(fe,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:de("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<vt.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:h.jsx(Pe,{icon:o?"lock":"unlock",small:!0})})}const moe=x.memo(function({children:n}){const t=N(),r=Nn(),o=as(),s=W("current tool id",()=>t.getCurrentToolId(),[t]),{ActionsMenu:i,QuickActions:a}=di();return h.jsx("div",{className:"tlui-toolbar",children:h.jsxs("div",{className:"tlui-toolbar__inner",children:[h.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&h.jsxs("div",{className:"tlui-toolbar__extras",children:[r<vt.TABLET&&h.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&h.jsx(a,{}),i&&h.jsx(i,{})]}),h.jsx(goe,{activeToolId:s})]}),h.jsx(foe,{children:n??h.jsx(Pre,{})})]}),r<vt.TABLET_SM&&!o&&h.jsx("div",{className:"tlui-toolbar__tools",children:h.jsx(bre,{})})]})})});function yoe(){const e=ae();return h.jsxs(h.Fragment,{children:[h.jsx(H,{...e["zoom-in"],noClose:!0}),h.jsx(H,{...e["zoom-out"],noClose:!0}),h.jsx(Dj,{}),h.jsx(Rj,{}),h.jsx(Lj,{})]})}const Soe=x.memo(function({children:n}){const t=dn(),[r,o]=ai("zoom menu"),s=n??h.jsx(yoe,{});return h.jsxs(Aw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(jw,{asChild:!0,dir:"ltr",children:h.jsx(voe,{})}),h.jsx(_g,{container:t,children:h.jsx(Ow,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:h.jsx(Ir,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),voe=x.forwardRef(function(n,t){const r=N(),o=Nn(),s=W("zoom",()=>r.getZoomLevel(),[r]),i=$e(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return h.jsx(fe,{ref:t,...n,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<vt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<vt.MOBILE?"zoom-in":void 0,children:o<vt.MOBILE?null:h.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),aO=x.createContext(null);function xoe({overrides:e={},children:n}){const t=W0(e);return h.jsx(aO.Provider,{value:x.useMemo(()=>({ContextMenu:Vte,ActionsMenu:bte,HelpMenu:ine,ZoomMenu:Soe,MainMenu:Ine,Minimap:Mne,StylePanel:wre,PageMenu:Dne,NavigationPanel:jne,Toolbar:moe,KeyboardShortcutsDialog:fne,QuickActions:Lne,HelperButtons:une,DebugPanel:ene,DebugMenu:Jte,MenuPanel:Ene,...t}),[t]),children:n})}function di(){const e=x.useContext(aO);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function woe({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return h.jsx(xY,{assetUrls:dZ(t),children:h.jsx(PY,{overrides:gZ(e),children:h.jsx(bq,{onEvent:r,children:h.jsx(tZ,{children:h.jsx(Pq,{children:h.jsx(hZ,{forceMobile:o,children:h.jsx(xoe,{overrides:n,children:h.jsx(boe,{overrides:e,children:s})})})})})})})})}function boe({overrides:e,children:n}){const t=mZ(e);return h.jsx(tQ,{overrides:t.actions,children:h.jsx(uZ,{overrides:t.tools,children:n})})}function Poe(){const e=N(),{addToast:n}=Xr();x.useEffect(()=>{function t({name:r,count:o}){n({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${o}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return e.addListener("max-shapes",t),()=>{e.removeListener("max-shapes",t)}},[e,n])}const Coe=ve.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return h.jsx(woe,{...s,components:o,children:h.jsx(Ioe,{hideUi:r,renderDebugMenuItems:n,children:t})})}),Ioe=ve.memo(function({children:n,hideUi:t,...r}){return h.jsxs(h.Fragment,{children:[n,t?null:h.jsx(_oe,{...r}),h.jsx(Eoe,{})]})});function Eoe(){const{InFrontOfTheCanvas:e}=at();return e?h.jsx("div",{className:"tl-front",children:h.jsx(e,{})}):null}const _oe=ve.memo(function(){const n=N(),t=$e(),r=Nn(),o=as(),s=W("focus",()=>n.getInstanceState().isFocusMode,[n]),i=W("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:c,MenuPanel:l,StylePanel:d,Toolbar:u,HelpMenu:f,NavigationPanel:p,HelperButtons:S,DebugPanel:g}=di();doe(),HZ(),Poe();const{"toggle-focus-mode":w}=ae();return h.jsxs("div",{className:de("tlui-layout",{"tlui-layout__mobile":r<vt.TABLET_SM}),"data-breakpoint":r,children:[s?h.jsx("div",{className:"tlui-layout__top",children:h.jsx(fe,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>w.onSelect("menu"),children:h.jsx(Pe,{icon:"dot"})})}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"tlui-layout__top",children:[h.jsxs("div",{className:"tlui-layout__top__left",children:[l&&h.jsx(l,{}),S&&h.jsx(S,{})]}),h.jsx("div",{className:"tlui-layout__top__center",children:c&&h.jsx(c,{})}),h.jsxs("div",{className:"tlui-layout__top__right",children:[a&&h.jsx(a,{}),d&&r>=vt.TABLET_SM&&!o&&h.jsx(d,{})]})]}),h.jsxs("div",{className:"tlui-layout__bottom",children:[h.jsxs("div",{className:"tlui-layout__bottom__main",children:[p&&h.jsx(p,{}),u&&h.jsx(u,{}),f&&h.jsx(f,{})]}),i&&g&&h.jsx(g,{})]})]}),h.jsx(sZ,{}),h.jsx(Eq,{}),h.jsx(iZ,{}),h.jsx(_q,{})]})});async function koe(e,n){const{url:t,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:c,variant:l,format:d}=n,u={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:c,variant:l},f=new FontFace(e,`url(${t})`,u);return await f.load(),document.fonts.add(f),f.$$_url=t,f.$$_fontface=`
|
|
317
|
-
@font-face {
|
|
318
|
-
font-family: ${f.family};
|
|
319
|
-
font-stretch: ${f.stretch};
|
|
320
|
-
font-weight: ${f.weight};
|
|
321
|
-
font-style: ${f.style};
|
|
322
|
-
src: url("${t}") format("${d}")
|
|
323
|
-
}`,f}const ah=(e,n)=>{const[t,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),koe(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function Toe(e){return{draw:{url:e.fonts.draw,format:e.fonts.draw.split(".").pop()},serif:{url:e.fonts.serif,format:e.fonts.serif.split(".").pop()},sansSerif:{url:e.fonts.sansSerif,format:e.fonts.sansSerif.split(".").pop()},monospace:{url:e.fonts.monospace,format:e.fonts.monospace.split(".").pop()}}}function cO(e){const n=x.useMemo(()=>Toe(e),[e]),t=[ah("tldraw_draw",n.draw),ah("tldraw_serif",n.serif),ah("tldraw_sans",n.sansSerif),ah("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function $oe(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:c=[],bindingUtils:l=[],tools:d=[],...u}=e,f=W0(a),p=x.useMemo(()=>({Scribble:vC,CollaboratorScribble:vC,SelectionForeground:QW,SelectionBackground:qW,Handles:WW,...f}),[f]),S=Tl(c),g=x.useMemo(()=>[...iM,...S],[S]),w=Tl(l),y=x.useMemo(()=>[...E$,...w],[w]),v=Tl(d),P=x.useMemo(()=>[...XY,...rV,...v],[v]),E="persistenceKey"in u?u.persistenceKey:void 0,I=aA(u.assetUrls),C=x.useMemo(()=>({onResolveAsset:zG(E),...u.assetOptions}),[E,u.assetOptions]),{done:_,error:k}=cO(I);return k?h.jsx(x$,{children:"Could not load assets. Please refresh the page."}):_?h.jsx(kW,{initialState:"select",...u,components:p,shapeUtils:g,bindingUtils:y,tools:P,assetOptions:C,children:h.jsxs(Coe,{...u,components:p,children:[h.jsx(Moe,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,persistenceKey:E,onMount:i}),n]})}):h.jsx(Gx,{children:h.jsx(K0,{})})}function Moe({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=C0,acceptedVideoMimeTypes:r=s_,onMount:o,persistenceKey:s}){const i=N(),a=Xr(),c=$e(),l=Hx(f=>{const p=[];return p.push(...jY(f)),RG(f,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:a,msg:c},s),p.push(o==null?void 0:o(f)),()=>{p.forEach(S=>S==null?void 0:S())}});x.useLayoutEffect(()=>{if(i)return l==null?void 0:l(i)},[i,l]);const{Canvas:d}=at(),{ContextMenu:u}=di();return u?h.jsx(u,{}):d?h.jsx(d,{}):null}x.memo(function(n){const[t,r]=x.useState(null),[o,s]=x.useState(null),i=Tl(n.shapeUtils??[]),a=x.useMemo(()=>[...iM,...i],[i]),c=Tl(n.bindingUtils??[]),l=x.useMemo(()=>[...E$,...c],[c]),d=y$({snapshot:n.snapshot,shapeUtils:a}),u=aA(),{done:f,error:p}=cO(u),{pageId:S,bounds:g,scale:w,background:y,padding:v,darkMode:P,preserveAspectRatio:E,format:I="svg"}=n;return x.useLayoutEffect(()=>{if(!o||!d||!f)return;let C=!1;const _=document.createElement("div");o.appendChild(_),o.classList.add("tl-container","tl-theme__light");const k=new ee({store:d,shapeUtils:a,bindingUtils:l,tools:[],getContainer:()=>_});S&&k.setCurrentPage(S);const j=k.getCurrentPageShapeIds();async function T(){const M=await k.getSvgString([...j],{bounds:g,scale:w,background:y,padding:v,darkMode:P,preserveAspectRatio:E});if(M&&!C){if(I==="svg"){if(!C){const R=new Blob([M.svg],{type:"image/svg+xml"}),A=URL.createObjectURL(R);r(A)}}else if(I==="png"){const R=await yA(k,M.svg,{type:I,quality:1,scale:2,width:M.width,height:M.height});if(R&&!C){const A=URL.createObjectURL(R);r(A)}}}k.dispose()}return T(),()=>{C=!0}},[I,o,d,a,l,S,g,w,y,v,P,E,f,p]),p?h.jsx(x$,{children:"Could not load assets."}):f?h.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&h.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):h.jsx(Gx,{children:h.jsx(K0,{})})});const Aoe=1,joe=xe({schemaVersion:an(1),storeVersion:gh,recordVersions:_f(pe,xe({version:gh,subTypeVersions:_f(pe,gh).optional(),subTypeKey:pe.optional()}))}),Ooe=xe({schemaVersion:an(2),sequences:_f(pe,gh)}),Doe=xe({tldrawFileFormatVersion:q4,schema:Z4("schemaVersion",{1:joe,2:Ooe}),records:Bt(xe({id:pe,typeName:pe}).allowUnknownProperties())});function Roe(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function Loe({json:e,schema:n}){let t;try{t=Doe.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),Roe(t))return fn.err({type:"v1File",data:t})}catch{}return fn.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>Aoe)return fn.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=Foe(t.records),s=Object.fromEntries(o.map(i=>[i.id,i]));r=n.migrateStoreSnapshot({store:s,schema:t.schema})}catch(o){return fn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return fn.err({type:"migrationFailed",reason:r.reason});try{return fn.ok(m$({initialData:r.value,schema:n}))}catch(o){return fn.err({type:"invalidRecords",cause:o})}}function Foe(e){const n=new Set;for(const t of e)t.typeName==="shape"&&"assetId"in t.props&&t.props.assetId&&n.add(t.props.assetId);return e.filter(t=>t.typeName!=="asset"||n.has(t.id))}function zoe(){const[e,n]=x.useState();function t(r){window.editor=r,e===void 0?fetch("/tldr-data").then(async o=>{if(!o.ok){console.log(`No tldr data to load from local endpoint (${o.status})`);return}return o.text()}).then(o=>{if(o===void 0)return;const s=Loe({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),n(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.zoomToFit(),r.clearOpenMenus())}return h.jsx("div",{style:{inset:0,position:"fixed"},children:h.jsx($oe,{assetUrls:LD(),onMount:t,store:e})})}uv.createRoot(document.querySelector("#root")).render(h.jsx(ve.StrictMode,{children:h.jsx(zoe,{})}));
|