@kitschpatrol/tldraw-cli 4.6.6 → 4.6.7
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 +4 -4
- package/dist/lib/index.js +3 -3
- package/dist/tldraw/assets/index-DpW5WlPZ.js +327 -0
- package/dist/tldraw/assets/index-lYfYBaQA.css +1 -0
- package/dist/tldraw/index.html +2 -2
- package/dist/tldraw/translations/main.json +6 -0
- package/package.json +3 -3
- package/dist/tldraw/assets/index-CY4X3CGC.css +0 -1
- package/dist/tldraw/assets/index-D1ZVSU0Y.js +0 -327
|
@@ -1,327 +0,0 @@
|
|
|
1
|
-
var YL=Object.defineProperty;var XL=(e,n,t)=>n in e?YL(e,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[n]=t;var g=(e,n,t)=>XL(e,typeof n!="symbol"?n+"":n,t);function qL(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 sn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var iE={exports:{}},kf={},aE={exports:{}},ve={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Cu=Symbol.for("react.element"),ZL=Symbol.for("react.portal"),QL=Symbol.for("react.fragment"),JL=Symbol.for("react.strict_mode"),e$=Symbol.for("react.profiler"),t$=Symbol.for("react.provider"),n$=Symbol.for("react.context"),r$=Symbol.for("react.forward_ref"),o$=Symbol.for("react.suspense"),s$=Symbol.for("react.memo"),i$=Symbol.for("react.lazy"),Ib=Symbol.iterator;function a$(e){return e===null||typeof e!="object"?null:(e=Ib&&e[Ib]||e["@@iterator"],typeof e=="function"?e:null)}var lE={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},cE=Object.assign,uE={};function Il(e,n,t){this.props=e,this.context=n,this.refs=uE,this.updater=t||lE}Il.prototype.isReactComponent={};Il.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")};Il.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function dE(){}dE.prototype=Il.prototype;function Jv(e,n,t){this.props=e,this.context=n,this.refs=uE,this.updater=t||lE}var ex=Jv.prototype=new dE;ex.constructor=Jv;cE(ex,Il.prototype);ex.isPureReactComponent=!0;var Eb=Array.isArray,hE=Object.prototype.hasOwnProperty,tx={current:null},pE={key:!0,ref:!0,__self:!0,__source:!0};function fE(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)hE.call(n,r)&&!pE.hasOwnProperty(r)&&(o[r]=n[r]);var a=arguments.length-2;if(a===1)o.children=t;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];o.children=l}if(e&&e.defaultProps)for(r in a=e.defaultProps,a)o[r]===void 0&&(o[r]=a[r]);return{$$typeof:Cu,type:e,key:s,ref:i,props:o,_owner:tx.current}}function l$(e,n){return{$$typeof:Cu,type:e.type,key:n,ref:e.ref,props:e.props,_owner:e._owner}}function nx(e){return typeof e=="object"&&e!==null&&e.$$typeof===Cu}function c$(e){var n={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(t){return n[t]})}var kb=/\/+/g;function Ug(e,n){return typeof e=="object"&&e!==null&&e.key!=null?c$(""+e.key):n.toString(36)}function dh(e,n,t,r,o){var s=typeof e;(s==="undefined"||s==="boolean")&&(e=null);var i=!1;if(e===null)i=!0;else switch(s){case"string":case"number":i=!0;break;case"object":switch(e.$$typeof){case Cu:case ZL:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+Ug(i,0):r,Eb(o)?(t="",e!=null&&(t=e.replace(kb,"$&/")+"/"),dh(o,n,t,"",function(c){return c})):o!=null&&(nx(o)&&(o=l$(o,t+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(kb,"$&/")+"/")+e)),n.push(o)),1;if(i=0,r=r===""?".":r+":",Eb(e))for(var a=0;a<e.length;a++){s=e[a];var l=r+Ug(s,a);i+=dh(s,n,t,l,o)}else if(l=a$(e),typeof l=="function")for(e=l.call(e),a=0;!(s=e.next()).done;)s=s.value,l=r+Ug(s,a++),i+=dh(s,n,t,l,o);else if(s==="object")throw n=String(e),Error("Objects are not valid as a React child (found: "+(n==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":n)+"). If you meant to render a collection of children, use an array instead.");return i}function ld(e,n,t){if(e==null)return e;var r=[],o=0;return dh(e,r,"","",function(s){return n.call(t,s,o++)}),r}function u$(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 Sn={current:null},hh={transition:null},d$={ReactCurrentDispatcher:Sn,ReactCurrentBatchConfig:hh,ReactCurrentOwner:tx};function gE(){throw Error("act(...) is not supported in production builds of React.")}ve.Children={map:ld,forEach:function(e,n,t){ld(e,function(){n.apply(this,arguments)},t)},count:function(e){var n=0;return ld(e,function(){n++}),n},toArray:function(e){return ld(e,function(n){return n})||[]},only:function(e){if(!nx(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};ve.Component=Il;ve.Fragment=QL;ve.Profiler=e$;ve.PureComponent=Jv;ve.StrictMode=JL;ve.Suspense=o$;ve.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=d$;ve.act=gE;ve.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=cE({},e.props),o=e.key,s=e.ref,i=e._owner;if(n!=null){if(n.ref!==void 0&&(s=n.ref,i=tx.current),n.key!==void 0&&(o=""+n.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in n)hE.call(n,l)&&!pE.hasOwnProperty(l)&&(r[l]=n[l]===void 0&&a!==void 0?a[l]:n[l])}var l=arguments.length-2;if(l===1)r.children=t;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:Cu,type:e.type,key:o,ref:s,props:r,_owner:i}};ve.createContext=function(e){return e={$$typeof:n$,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:t$,_context:e},e.Consumer=e};ve.createElement=fE;ve.createFactory=function(e){var n=fE.bind(null,e);return n.type=e,n};ve.createRef=function(){return{current:null}};ve.forwardRef=function(e){return{$$typeof:r$,render:e}};ve.isValidElement=nx;ve.lazy=function(e){return{$$typeof:i$,_payload:{_status:-1,_result:e},_init:u$}};ve.memo=function(e,n){return{$$typeof:s$,type:e,compare:n===void 0?null:n}};ve.startTransition=function(e){var n=hh.transition;hh.transition={};try{e()}finally{hh.transition=n}};ve.unstable_act=gE;ve.useCallback=function(e,n){return Sn.current.useCallback(e,n)};ve.useContext=function(e){return Sn.current.useContext(e)};ve.useDebugValue=function(){};ve.useDeferredValue=function(e){return Sn.current.useDeferredValue(e)};ve.useEffect=function(e,n){return Sn.current.useEffect(e,n)};ve.useId=function(){return Sn.current.useId()};ve.useImperativeHandle=function(e,n,t){return Sn.current.useImperativeHandle(e,n,t)};ve.useInsertionEffect=function(e,n){return Sn.current.useInsertionEffect(e,n)};ve.useLayoutEffect=function(e,n){return Sn.current.useLayoutEffect(e,n)};ve.useMemo=function(e,n){return Sn.current.useMemo(e,n)};ve.useReducer=function(e,n,t){return Sn.current.useReducer(e,n,t)};ve.useRef=function(e){return Sn.current.useRef(e)};ve.useState=function(e){return Sn.current.useState(e)};ve.useSyncExternalStore=function(e,n,t){return Sn.current.useSyncExternalStore(e,n,t)};ve.useTransition=function(){return Sn.current.useTransition()};ve.version="18.3.1";aE.exports=ve;var P=aE.exports;const xe=ei(P),h$=qL({__proto__:null,default:xe},[P]);/**
|
|
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 p$=P,f$=Symbol.for("react.element"),g$=Symbol.for("react.fragment"),m$=Object.prototype.hasOwnProperty,y$=p$.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,S$={key:!0,ref:!0,__self:!0,__source:!0};function mE(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)m$.call(n,r)&&!S$.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:f$,type:e,key:s,ref:i,props:o,_owner:y$.current}}kf.Fragment=g$;kf.jsx=mE;kf.jsxs=mE;iE.exports=kf;var d=iE.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 v$(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 Gl=function(e){return e&&e.Math===Math&&e},Bn=Gl(typeof globalThis=="object"&&globalThis)||Gl(typeof window=="object"&&window)||Gl(typeof self=="object"&&self)||Gl(typeof sn=="object"&&sn)||Gl(typeof sn=="object"&&sn)||function(){return this}()||Function("return this")(),rx={},vn=function(e){try{return!!e()}catch{return!0}},x$=vn,ti=!x$(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),w$=vn,_f=!w$(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),b$=_f,cd=Function.prototype.call,rs=b$?cd.bind(cd):function(){return cd.apply(cd,arguments)},yE={},SE={}.propertyIsEnumerable,vE=Object.getOwnPropertyDescriptor,P$=vE&&!SE.call({1:2},1);yE.f=P$?function(n){var t=vE(this,n);return!!t&&t.enumerable}:SE;var xE=function(e,n){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:n}},wE=_f,bE=Function.prototype,qy=bE.call,C$=wE&&bE.bind.bind(qy,qy),Dt=wE?C$:function(e){return function(){return qy.apply(e,arguments)}},PE=Dt,I$=PE({}.toString),E$=PE("".slice),El=function(e){return E$(I$(e),8,-1)},k$=Dt,_$=vn,T$=El,Hg=Object,M$=k$("".split),A$=_$(function(){return!Hg("z").propertyIsEnumerable(0)})?function(e){return T$(e)==="String"?M$(e,""):Hg(e)}:Hg,Tf=function(e){return e==null},j$=Tf,O$=TypeError,kl=function(e){if(j$(e))throw new O$("Can't call method on "+e);return e},D$=A$,R$=kl,Mf=function(e){return D$(R$(e))},Kg=typeof document=="object"&&document.all,xn=typeof Kg>"u"&&Kg!==void 0?function(e){return typeof e=="function"||e===Kg}:function(e){return typeof e=="function"},L$=xn,ta=function(e){return typeof e=="object"?e!==null:L$(e)},Wg=Bn,$$=xn,F$=function(e){return $$(e)?e:void 0},Af=function(e,n){return arguments.length<2?F$(Wg[e]):Wg[e]&&Wg[e][n]},N$=Dt,CE=N$({}.isPrototypeOf),z$=typeof navigator<"u"&&String(navigator.userAgent)||"",IE=Bn,Gg=z$,_b=IE.process,Tb=IE.Deno,Mb=_b&&_b.versions||Tb&&Tb.version,Ab=Mb&&Mb.v8,Lr,fp;Ab&&(Lr=Ab.split("."),fp=Lr[0]>0&&Lr[0]<4?1:+(Lr[0]+Lr[1]));!fp&&Gg&&(Lr=Gg.match(/Edge\/(\d+)/),(!Lr||Lr[1]>=74)&&(Lr=Gg.match(/Chrome\/(\d+)/),Lr&&(fp=+Lr[1])));var B$=fp,jb=B$,U$=vn,H$=Bn,K$=H$.String,EE=!!Object.getOwnPropertySymbols&&!U$(function(){var e=Symbol("symbol detection");return!K$(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&jb&&jb<41}),W$=EE,kE=W$&&!Symbol.sham&&typeof Symbol.iterator=="symbol",G$=Af,V$=xn,Y$=CE,X$=kE,q$=Object,_E=X$?function(e){return typeof e=="symbol"}:function(e){var n=G$("Symbol");return V$(n)&&Y$(n.prototype,q$(e))},Z$=String,Q$=function(e){try{return Z$(e)}catch{return"Object"}},J$=xn,eF=Q$,tF=TypeError,ox=function(e){if(J$(e))return e;throw new tF(eF(e)+" is not a function")},nF=ox,rF=Tf,sx=function(e,n){var t=e[n];return rF(t)?void 0:nF(t)},Vg=rs,Yg=xn,Xg=ta,oF=TypeError,sF=function(e,n){var t,r;if(n==="string"&&Yg(t=e.toString)&&!Xg(r=Vg(t,e))||Yg(t=e.valueOf)&&!Xg(r=Vg(t,e))||n!=="string"&&Yg(t=e.toString)&&!Xg(r=Vg(t,e)))return r;throw new oF("Can't convert object to primitive value")},TE={exports:{}},Ob=Bn,iF=Object.defineProperty,ix=function(e,n){try{iF(Ob,e,{value:n,configurable:!0,writable:!0})}catch{Ob[e]=n}return n},aF=Bn,lF=ix,Db="__core-js_shared__",Rb=TE.exports=aF[Db]||lF(Db,{});(Rb.versions||(Rb.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 ax=TE.exports,Lb=ax,lx=function(e,n){return Lb[e]||(Lb[e]=n||{})},cF=kl,uF=Object,Iu=function(e){return uF(cF(e))},dF=Dt,hF=Iu,pF=dF({}.hasOwnProperty),ni=Object.hasOwn||function(n,t){return pF(hF(n),t)},fF=Dt,gF=0,mF=Math.random(),yF=fF(1 .toString),ME=function(e){return"Symbol("+(e===void 0?"":e)+")_"+yF(++gF+mF,36)},SF=Bn,vF=lx,$b=ni,xF=ME,wF=EE,bF=kE,Ea=SF.Symbol,qg=vF("wks"),PF=bF?Ea.for||Ea:Ea&&Ea.withoutSetter||xF,os=function(e){return $b(qg,e)||(qg[e]=wF&&$b(Ea,e)?Ea[e]:PF("Symbol."+e)),qg[e]},CF=rs,Fb=ta,Nb=_E,IF=sx,EF=sF,kF=os,_F=TypeError,TF=kF("toPrimitive"),MF=function(e,n){if(!Fb(e)||Nb(e))return e;var t=IF(e,TF),r;if(t){if(n===void 0&&(n="default"),r=CF(t,e,n),!Fb(r)||Nb(r))return r;throw new _F("Can't convert object to primitive value")}return n===void 0&&(n="number"),EF(e,n)},AF=MF,jF=_E,AE=function(e){var n=AF(e,"string");return jF(n)?n:n+""},OF=Bn,zb=ta,Zy=OF.document,DF=zb(Zy)&&zb(Zy.createElement),jE=function(e){return DF?Zy.createElement(e):{}},RF=ti,LF=vn,$F=jE,OE=!RF&&!LF(function(){return Object.defineProperty($F("div"),"a",{get:function(){return 7}}).a!==7}),FF=ti,NF=rs,zF=yE,BF=xE,UF=Mf,HF=AE,KF=ni,WF=OE,Bb=Object.getOwnPropertyDescriptor;rx.f=FF?Bb:function(n,t){if(n=UF(n),t=HF(t),WF)try{return Bb(n,t)}catch{}if(KF(n,t))return BF(!NF(zF.f,n,t),n[t])};var _l={},GF=ti,VF=vn,DE=GF&&VF(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),YF=ta,XF=String,qF=TypeError,na=function(e){if(YF(e))return e;throw new qF(XF(e)+" is not an object")},ZF=ti,QF=OE,JF=DE,ud=na,Ub=AE,eN=TypeError,Zg=Object.defineProperty,tN=Object.getOwnPropertyDescriptor,Qg="enumerable",Jg="configurable",em="writable";_l.f=ZF?JF?function(n,t,r){if(ud(n),t=Ub(t),ud(r),typeof n=="function"&&t==="prototype"&&"value"in r&&em in r&&!r[em]){var o=tN(n,t);o&&o[em]&&(n[t]=r.value,r={configurable:Jg in r?r[Jg]:o[Jg],enumerable:Qg in r?r[Qg]:o[Qg],writable:!1})}return Zg(n,t,r)}:Zg:function(n,t,r){if(ud(n),t=Ub(t),ud(r),QF)try{return Zg(n,t,r)}catch{}if("get"in r||"set"in r)throw new eN("Accessors not supported");return"value"in r&&(n[t]=r.value),n};var nN=ti,rN=_l,oN=xE,cx=nN?function(e,n,t){return rN.f(e,n,oN(1,t))}:function(e,n,t){return e[n]=t,e},RE={exports:{}},Qy=ti,sN=ni,LE=Function.prototype,iN=Qy&&Object.getOwnPropertyDescriptor,ux=sN(LE,"name"),aN=ux&&(function(){}).name==="something",lN=ux&&(!Qy||Qy&&iN(LE,"name").configurable),cN={EXISTS:ux,PROPER:aN,CONFIGURABLE:lN},uN=Dt,dN=xn,Jy=ax,hN=uN(Function.toString);dN(Jy.inspectSource)||(Jy.inspectSource=function(e){return hN(e)});var $E=Jy.inspectSource,pN=Bn,fN=xn,Hb=pN.WeakMap,gN=fN(Hb)&&/native code/.test(String(Hb)),mN=lx,yN=ME,Kb=mN("keys"),FE=function(e){return Kb[e]||(Kb[e]=yN(e))},dx={},SN=gN,NE=Bn,vN=ta,xN=cx,tm=ni,nm=ax,wN=FE,bN=dx,Wb="Object already initialized",eS=NE.TypeError,PN=NE.WeakMap,gp,Kc,mp,CN=function(e){return mp(e)?Kc(e):gp(e,{})},IN=function(e){return function(n){var t;if(!vN(n)||(t=Kc(n)).type!==e)throw new eS("Incompatible receiver, "+e+" required");return t}};if(SN||nm.state){var eo=nm.state||(nm.state=new PN);eo.get=eo.get,eo.has=eo.has,eo.set=eo.set,gp=function(e,n){if(eo.has(e))throw new eS(Wb);return n.facade=e,eo.set(e,n),n},Kc=function(e){return eo.get(e)||{}},mp=function(e){return eo.has(e)}}else{var da=wN("state");bN[da]=!0,gp=function(e,n){if(tm(e,da))throw new eS(Wb);return n.facade=e,xN(e,da,n),n},Kc=function(e){return tm(e,da)?e[da]:{}},mp=function(e){return tm(e,da)}}var zE={set:gp,get:Kc,has:mp,enforce:CN,getterFor:IN},hx=Dt,EN=vn,kN=xn,dd=ni,tS=ti,_N=cN.CONFIGURABLE,TN=$E,BE=zE,MN=BE.enforce,AN=BE.get,Gb=String,ph=Object.defineProperty,jN=hx("".slice),ON=hx("".replace),DN=hx([].join),RN=tS&&!EN(function(){return ph(function(){},"length",{value:8}).length!==8}),LN=String(String).split("String"),$N=RE.exports=function(e,n,t){jN(Gb(n),0,7)==="Symbol("&&(n="["+ON(Gb(n),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),t&&t.getter&&(n="get "+n),t&&t.setter&&(n="set "+n),(!dd(e,"name")||_N&&e.name!==n)&&(tS?ph(e,"name",{value:n,configurable:!0}):e.name=n),RN&&t&&dd(t,"arity")&&e.length!==t.arity&&ph(e,"length",{value:t.arity});try{t&&dd(t,"constructor")&&t.constructor?tS&&ph(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=MN(e);return dd(r,"source")||(r.source=DN(LN,typeof n=="string"?n:"")),e};Function.prototype.toString=$N(function(){return kN(this)&&AN(this).source||TN(this)},"toString");var FN=RE.exports,NN=xn,zN=_l,BN=FN,UN=ix,UE=function(e,n,t,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:n;if(NN(t)&&BN(t,s,r),r.global)o?e[n]=t:UN(n,t);else{try{r.unsafe?e[n]&&(o=!0):delete e[n]}catch{}o?e[n]=t:zN.f(e,n,{value:t,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},HE={},HN=Math.ceil,KN=Math.floor,WN=Math.trunc||function(n){var t=+n;return(t>0?KN:HN)(t)},GN=WN,ra=function(e){var n=+e;return n!==n||n===0?0:GN(n)},VN=ra,YN=Math.max,XN=Math.min,qN=function(e,n){var t=VN(e);return t<0?YN(t+n,0):XN(t,n)},ZN=ra,QN=Math.min,KE=function(e){var n=ZN(e);return n>0?QN(n,9007199254740991):0},JN=KE,Eu=function(e){return JN(e.length)},ez=Mf,tz=qN,nz=Eu,Vb=function(e){return function(n,t,r){var o=ez(n),s=nz(o);if(s===0)return!e&&-1;var i=tz(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}},rz={includes:Vb(!0),indexOf:Vb(!1)},oz=Dt,rm=ni,sz=Mf,iz=rz.indexOf,az=dx,Yb=oz([].push),WE=function(e,n){var t=sz(e),r=0,o=[],s;for(s in t)!rm(az,s)&&rm(t,s)&&Yb(o,s);for(;n.length>r;)rm(t,s=n[r++])&&(~iz(o,s)||Yb(o,s));return o},px=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],lz=WE,cz=px,uz=cz.concat("length","prototype");HE.f=Object.getOwnPropertyNames||function(n){return lz(n,uz)};var GE={};GE.f=Object.getOwnPropertySymbols;var dz=Af,hz=Dt,pz=HE,fz=GE,gz=na,mz=hz([].concat),yz=dz("Reflect","ownKeys")||function(n){var t=pz.f(gz(n)),r=fz.f;return r?mz(t,r(n)):t},Xb=ni,Sz=yz,vz=rx,xz=_l,wz=function(e,n,t){for(var r=Sz(n),o=xz.f,s=vz.f,i=0;i<r.length;i++){var a=r[i];!Xb(e,a)&&!(t&&Xb(t,a))&&o(e,a,s(n,a))}},bz=vn,Pz=xn,Cz=/#|\.prototype\./,ku=function(e,n){var t=Ez[Iz(e)];return t===_z?!0:t===kz?!1:Pz(n)?bz(n):!!n},Iz=ku.normalize=function(e){return String(e).replace(Cz,".").toLowerCase()},Ez=ku.data={},kz=ku.NATIVE="N",_z=ku.POLYFILL="P",Tz=ku,hd=Bn,Mz=rx.f,Az=cx,jz=UE,Oz=ix,Dz=wz,Rz=Tz,Tl=function(e,n){var t=e.target,r=e.global,o=e.stat,s,i,a,l,c,u;if(r?i=hd:o?i=hd[t]||Oz(t,{}):i=hd[t]&&hd[t].prototype,i)for(a in n){if(c=n[a],e.dontCallGetSet?(u=Mz(i,a),l=u&&u.value):l=i[a],s=Rz(r?a:t+(o?".":"#")+a,e.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;Dz(c,l)}(e.sham||l&&l.sham)&&Az(c,"sham",!0),jz(i,a,c,e)}},VE={},Lz=WE,$z=px,Fz=Object.keys||function(n){return Lz(n,$z)},Nz=ti,zz=DE,Bz=_l,Uz=na,Hz=Mf,Kz=Fz;VE.f=Nz&&!zz?Object.defineProperties:function(n,t){Uz(n);for(var r=Hz(t),o=Kz(t),s=o.length,i=0,a;s>i;)Bz.f(n,a=o[i++],r[a]);return n};var Wz=Af,Gz=Wz("document","documentElement"),Vz=na,Yz=VE,qb=px,Xz=dx,qz=Gz,Zz=jE,Qz=FE,Zb=">",Qb="<",nS="prototype",rS="script",YE=Qz("IE_PROTO"),om=function(){},XE=function(e){return Qb+rS+Zb+e+Qb+"/"+rS+Zb},Jb=function(e){e.write(XE("")),e.close();var n=e.parentWindow.Object;return e=null,n},Jz=function(){var e=Zz("iframe"),n="java"+rS+":",t;return e.style.display="none",qz.appendChild(e),e.src=String(n),t=e.contentWindow.document,t.open(),t.write(XE("document.F=Object")),t.close(),t.F},pd,fh=function(){try{pd=new ActiveXObject("htmlfile")}catch{}fh=typeof document<"u"?document.domain&&pd?Jb(pd):Jz():Jb(pd);for(var e=qb.length;e--;)delete fh[nS][qb[e]];return fh()};Xz[YE]=!0;var qE=Object.create||function(n,t){var r;return n!==null?(om[nS]=Vz(n),r=new om,om[nS]=null,r[YE]=n):r=fh(),t===void 0?r:Yz.f(r,t)},e3=os,t3=qE,n3=_l.f,oS=e3("unscopables"),sS=Array.prototype;sS[oS]===void 0&&n3(sS,oS,{configurable:!0,value:t3(null)});var fx=function(e){sS[oS][e]=!0},r3=Tl,o3=Iu,s3=Eu,i3=ra,a3=fx;r3({target:"Array",proto:!0},{at:function(n){var t=o3(this),r=s3(t),o=i3(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:t[s]}});a3("at");var l3=Bn,c3=Dt,_u=function(e,n){return c3(l3[e].prototype[n])},u3=_u;u3("Array","at");var d3=El,ZE=Array.isArray||function(n){return d3(n)==="Array"},h3=TypeError,p3=9007199254740991,f3=function(e){if(e>p3)throw h3("Maximum allowed index exceeded");return e},g3=El,m3=Dt,y3=function(e){if(g3(e)==="Function")return m3(e)},e1=y3,S3=ox,v3=_f,x3=e1(e1.bind),w3=function(e,n){return S3(e),n===void 0?e:v3?x3(e,n):function(){return e.apply(n,arguments)}},b3=ZE,P3=Eu,C3=f3,I3=w3,QE=function(e,n,t,r,o,s,i,a){for(var l=o,c=0,u=i?I3(i,a):!1,h,p;c<r;)c in t&&(h=u?u(t[c],c,n):t[c],s>0&&b3(h)?(p=P3(h),l=QE(e,n,h,p,l,s-1)-1):(C3(l+1),e[l]=h),l++),c++;return l},JE=QE,E3=os,k3=E3("toStringTag"),ek={};ek[k3]="z";var _3=String(ek)==="[object z]",T3=_3,M3=xn,gh=El,A3=os,j3=A3("toStringTag"),O3=Object,D3=gh(function(){return arguments}())==="Arguments",R3=function(e,n){try{return e[n]}catch{}},tk=T3?gh:function(e){var n,t,r;return e===void 0?"Undefined":e===null?"Null":typeof(t=R3(n=O3(e),j3))=="string"?t:D3?gh(n):(r=gh(n))==="Object"&&M3(n.callee)?"Arguments":r},L3=Dt,$3=vn,nk=xn,F3=tk,N3=Af,z3=$E,rk=function(){},ok=N3("Reflect","construct"),gx=/^\s*(?:class|function)\b/,B3=L3(gx.exec),U3=!gx.test(rk),Vl=function(n){if(!nk(n))return!1;try{return ok(rk,[],n),!0}catch{return!1}},sk=function(n){if(!nk(n))return!1;switch(F3(n)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return U3||!!B3(gx,z3(n))}catch{return!0}};sk.sham=!0;var H3=!ok||$3(function(){var e;return Vl(Vl.call)||!Vl(Object)||!Vl(function(){e=!0})||e})?sk:Vl,t1=ZE,K3=H3,W3=ta,G3=os,V3=G3("species"),n1=Array,Y3=function(e){var n;return t1(e)&&(n=e.constructor,K3(n)&&(n===n1||t1(n.prototype))?n=void 0:W3(n)&&(n=n[V3],n===null&&(n=void 0))),n===void 0?n1:n},X3=Y3,ik=function(e,n){return new(X3(e))(n===0?0:n)},q3=Tl,Z3=JE,Q3=ox,J3=Iu,eB=Eu,tB=ik;q3({target:"Array",proto:!0},{flatMap:function(n){var t=J3(this),r=eB(t),o;return Q3(n),o=tB(t,0),o.length=Z3(o,t,t,r,0,1,n,arguments.length>1?arguments[1]:void 0),o}});var nB=fx;nB("flatMap");var rB=_u;rB("Array","flatMap");var oB=Tl,sB=JE,iB=Iu,aB=Eu,lB=ra,cB=ik;oB({target:"Array",proto:!0},{flat:function(){var n=arguments.length?arguments[0]:void 0,t=iB(this),r=aB(t),o=cB(t,0);return o.length=sB(o,t,t,r,0,n===void 0?1:lB(n)),o}});var uB=fx;uB("flat");var dB=_u;dB("Array","flat");var hB=tk,pB=String,Tu=function(e){if(hB(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return pB(e)},fB=Tl,gB=Dt,mB=kl,yB=ra,SB=Tu,vB=vn,xB=gB("".charAt),wB=vB(function(){return"𠮷".at(-2)!=="\uD842"});fB({target:"String",proto:!0,forced:wB},{at:function(n){var t=SB(mB(this)),r=t.length,o=yB(n),s=o>=0?o:r+o;return s<0||s>=r?void 0:xB(t,s)}});var bB=_u;bB("String","at");var PB=na,ak=function(){var e=PB(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},mx=vn,CB=Bn,yx=CB.RegExp,Sx=mx(function(){var e=yx("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),IB=Sx||mx(function(){return!yx("a","y").sticky}),EB=Sx||mx(function(){var e=yx("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),kB={BROKEN_CARET:EB,MISSED_STICKY:IB,UNSUPPORTED_Y:Sx},_B=vn,TB=Bn,MB=TB.RegExp,AB=_B(function(){var e=MB(".","s");return!(e.dotAll&&e.test(`
|
|
18
|
-
`)&&e.flags==="s")}),jB=vn,OB=Bn,DB=OB.RegExp,RB=jB(function(){var e=DB("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),ka=rs,jf=Dt,LB=Tu,$B=ak,FB=kB,NB=lx,zB=qE,BB=zE.get,UB=AB,HB=RB,KB=NB("native-string-replace",String.prototype.replace),yp=RegExp.prototype.exec,iS=yp,WB=jf("".charAt),GB=jf("".indexOf),VB=jf("".replace),sm=jf("".slice),aS=function(){var e=/a/,n=/b*/g;return ka(yp,e,"a"),ka(yp,n,"a"),e.lastIndex!==0||n.lastIndex!==0}(),lk=FB.BROKEN_CARET,lS=/()??/.exec("")[1]!==void 0,YB=aS||lS||lk||UB||HB;YB&&(iS=function(n){var t=this,r=BB(t),o=LB(n),s=r.raw,i,a,l,c,u,h,p;if(s)return s.lastIndex=t.lastIndex,i=ka(iS,s,o),t.lastIndex=s.lastIndex,i;var f=r.groups,S=lk&&t.sticky,m=ka($B,t),x=t.source,y=0,v=o;if(S&&(m=VB(m,"y",""),GB(m,"g")===-1&&(m+="g"),v=sm(o,t.lastIndex),t.lastIndex>0&&(!t.multiline||t.multiline&&WB(o,t.lastIndex-1)!==`
|
|
19
|
-
`)&&(x="(?: "+x+")",v=" "+v,y++),a=new RegExp("^(?:"+x+")",m)),lS&&(a=new RegExp("^"+x+"$(?!\\s)",m)),aS&&(l=t.lastIndex),c=ka(yp,S?a:t,v),S?c?(c.input=sm(c.input,y),c[0]=sm(c[0],y),c.index=t.lastIndex,t.lastIndex+=c[0].length):t.lastIndex=0:aS&&c&&(t.lastIndex=t.global?c.index+c[0].length:l),lS&&c&&c.length>1&&ka(KB,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&f)for(c.groups=h=zB(null),u=0;u<f.length;u++)p=f[u],h[p[0]]=c[p[1]];return c});var vx=iS,XB=Tl,r1=vx;XB({target:"RegExp",proto:!0,forced:/./.exec!==r1},{exec:r1});var qB=_f,ck=Function.prototype,o1=ck.apply,s1=ck.call,ZB=typeof Reflect=="object"&&Reflect.apply||(qB?s1.bind(o1):function(){return s1.apply(o1,arguments)}),i1=rs,a1=UE,QB=vx,l1=vn,uk=os,JB=cx,e5=uk("species"),im=RegExp.prototype,t5=function(e,n,t,r){var o=uk(e),s=!l1(function(){var c={};return c[o]=function(){return 7},""[e](c)!==7}),i=s&&!l1(function(){var c=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[e5]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return c=!0,null},u[o](""),!c});if(!s||!i||t){var a=/./[o],l=n(o,""[e],function(c,u,h,p,f){var S=u.exec;return S===QB||S===im.exec?s&&!f?{done:!0,value:i1(a,u,h,p)}:{done:!0,value:i1(c,h,u,p)}:{done:!1}});a1(String.prototype,e,l[0]),a1(im,o,l[1])}r&&JB(im[o],"sham",!0)},xx=Dt,n5=ra,r5=Tu,o5=kl,s5=xx("".charAt),c1=xx("".charCodeAt),i5=xx("".slice),u1=function(e){return function(n,t){var r=r5(o5(n)),o=n5(t),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=c1(r,o),i<55296||i>56319||o+1===s||(a=c1(r,o+1))<56320||a>57343?e?s5(r,o):i:e?i5(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},a5={codeAt:u1(!1),charAt:u1(!0)},l5=a5.charAt,c5=function(e,n,t){return n+(t?l5(e,n).length:1)},wx=Dt,u5=Iu,d5=Math.floor,am=wx("".charAt),h5=wx("".replace),lm=wx("".slice),p5=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,f5=/\$([$&'`]|\d{1,2})/g,dk=function(e,n,t,r,o,s){var i=t+e.length,a=r.length,l=f5;return o!==void 0&&(o=u5(o),l=p5),h5(s,l,function(c,u){var h;switch(am(u,0)){case"$":return"$";case"&":return e;case"`":return lm(n,0,t);case"'":return lm(n,i);case"<":h=o[lm(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=d5(p/10);return f===0?c:f<=a?r[f-1]===void 0?am(u,1):r[f-1]+am(u,1):c}h=r[p-1]}return h===void 0?"":h})},d1=rs,g5=na,m5=xn,y5=El,S5=vx,v5=TypeError,x5=function(e,n){var t=e.exec;if(m5(t)){var r=d1(t,e,n);return r!==null&&g5(r),r}if(y5(e)==="RegExp")return d1(S5,e,n);throw new v5("RegExp#exec called on incompatible receiver")},w5=ZB,h1=rs,Of=Dt,b5=t5,P5=vn,C5=na,I5=xn,E5=Tf,k5=ra,_5=KE,ha=Tu,T5=kl,M5=c5,A5=sx,j5=dk,O5=x5,D5=os,cS=D5("replace"),R5=Math.max,L5=Math.min,$5=Of([].concat),cm=Of([].push),p1=Of("".indexOf),f1=Of("".slice),F5=function(e){return e===void 0?e:String(e)},N5=function(){return"a".replace(/./,"$0")==="$0"}(),g1=function(){return/./[cS]?/./[cS]("a","$0")==="":!1}(),z5=!P5(function(){var e=/./;return e.exec=function(){var n=[];return n.groups={a:"7"},n},"".replace(e,"$<a>")!=="7"});b5("replace",function(e,n,t){var r=g1?"$":"$0";return[function(s,i){var a=T5(this),l=E5(s)?void 0:A5(s,cS);return l?h1(l,s,a,i):h1(n,ha(a),s,i)},function(o,s){var i=C5(this),a=ha(o);if(typeof s=="string"&&p1(s,r)===-1&&p1(s,"$<")===-1){var l=t(n,i,a,s);if(l.done)return l.value}var c=I5(s);c||(s=ha(s));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var p=[],f;f=O5(i,a),!(f===null||(cm(p,f),!u));){var S=ha(f[0]);S===""&&(i.lastIndex=M5(a,_5(i.lastIndex),h))}for(var m="",x=0,y=0;y<p.length;y++){f=p[y];for(var v=ha(f[0]),b=R5(L5(k5(f.index),a.length),0),E=[],I,C=1;C<f.length;C++)cm(E,F5(f[C]));var k=f.groups;if(c){var T=$5([v],E,b,a);k!==void 0&&cm(T,k),I=ha(w5(s,void 0,T))}else I=j5(v,a,b,E,k,s);b>=x&&(m+=f1(a,x,b)+I,x=b+v.length)}return m+f1(a,x)}]},!z5||!N5||g1);var B5=ta,U5=El,H5=os,K5=H5("match"),W5=function(e){var n;return B5(e)&&((n=e[K5])!==void 0?!!n:U5(e)==="RegExp")},G5=rs,V5=ni,Y5=CE,X5=ak,m1=RegExp.prototype,q5=function(e){var n=e.flags;return n===void 0&&!("flags"in m1)&&!V5(e,"flags")&&Y5(m1,e)?G5(X5,e):n},Z5=Tl,Q5=rs,bx=Dt,y1=kl,J5=xn,eU=Tf,tU=W5,Yl=Tu,nU=sx,rU=q5,oU=dk,sU=os,iU=sU("replace"),aU=TypeError,um=bx("".indexOf);bx("".replace);var S1=bx("".slice),lU=Math.max;Z5({target:"String",proto:!0},{replaceAll:function(n,t){var r=y1(this),o,s,i,a,l,c,u,h,p,f=0,S=0,m="";if(!eU(n)){if(o=tU(n),o&&(s=Yl(y1(rU(n))),!~um(s,"g")))throw new aU("`.replaceAll` does not allow non-global regexes");if(i=nU(n,iU),i)return Q5(i,n,r,t)}for(a=Yl(r),l=Yl(n),c=J5(t),c||(t=Yl(t)),u=l.length,h=lU(1,u),f=um(a,l);f!==-1;)p=c?Yl(t(l,f,a)):oU(l,a,f,[],void 0,t),m+=S1(a,S,f)+p,S=f+u,f=f+h>a.length?-1:um(a,l,f+h);return S<a.length&&(m+=S1(a,S)),m}});var cU=_u;cU("String","replaceAll");class mh{constructor(n){g(this,"nextValue");g(this,"diff");this.previousValue=n}get(){var r,o,s,i;const n=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,t=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(n===0&&t===0))return{value:this.nextValue,diff:this.diff}}_add(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(n),this.diff??(this.diff={}),t?(r=this.diff.removed)==null||r.delete(n):((o=this.diff).added??(o.added=new Set),this.diff.added.add(n))}add(n){var o,s,i;const t=this.previousValue.has(n);if(t)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(n))?this._add(n,t):void 0;(i=this.nextValue)!=null&&i.has(n)||this._add(n,t)}_remove(n,t){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(n),this.diff??(this.diff={}),t?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(n)):(o=this.diff.added)==null||o.delete(n)}remove(n){var o,s,i,a;const t=this.previousValue.has(n);if(!t)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(n))?this._remove(n,t):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(n)||this._remove(n,t)}}var hk="Expected a function",v1=NaN,uU="[object Symbol]",dU=/^\s+|\s+$/g,hU=/^[-+]0x[0-9a-f]+$/i,pU=/^0b[01]+$/i,fU=/^0o[0-7]+$/i,gU=parseInt,mU=typeof sn=="object"&&sn&&sn.Object===Object&&sn,yU=typeof self=="object"&&self&&self.Object===Object&&self,SU=mU||yU||Function("return this")(),vU=Object.prototype,xU=vU.toString,wU=Math.max,bU=Math.min,dm=function(){return SU.Date.now()};function PU(e,n,t){var r,o,s,i,a,l,c=0,u=!1,h=!1,p=!0;if(typeof e!="function")throw new TypeError(hk);n=x1(n)||0,Sp(t)&&(u=!!t.leading,h="maxWait"in t,s=h?wU(x1(t.maxWait)||0,n):s,p="trailing"in t?!!t.trailing:p);function f(C){var k=r,T=o;return r=o=void 0,c=C,i=e.apply(T,k),i}function S(C){return c=C,a=setTimeout(y,n),u?f(C):i}function m(C){var k=C-l,T=C-c,O=n-k;return h?bU(O,s-T):O}function x(C){var k=C-l,T=C-c;return l===void 0||k>=n||k<0||h&&T>=s}function y(){var C=dm();if(x(C))return v(C);a=setTimeout(y,m(C))}function v(C){return a=void 0,p&&r?f(C):(r=o=void 0,i)}function b(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function E(){return a===void 0?i:v(dm())}function I(){var C=dm(),k=x(C);if(r=arguments,o=this,l=C,k){if(a===void 0)return S(l);if(h)return a=setTimeout(y,n),f(l)}return a===void 0&&(a=setTimeout(y,n)),i}return I.cancel=b,I.flush=E,I}function CU(e,n,t){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(hk);return Sp(t)&&(r="leading"in t?!!t.leading:r,o="trailing"in t?!!t.trailing:o),PU(e,n,{leading:r,maxWait:n,trailing:o})}function Sp(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function IU(e){return!!e&&typeof e=="object"}function EU(e){return typeof e=="symbol"||IU(e)&&xU.call(e)==uU}function x1(e){if(typeof e=="number")return e;if(EU(e))return v1;if(Sp(e)){var n=typeof e.valueOf=="function"?e.valueOf():e;e=Sp(n)?n+"":n}if(typeof e!="string")return e===0?e:+e;e=e.replace(dU,"");var t=pU.test(e);return t||fU.test(e)?gU(e.slice(2),t?2:8):hU.test(e)?v1:+e}var kU=CU;const pk=ei(kU);var _U=200,Px="__lodash_hash_undefined__",TU=1/0,MU="[object Function]",AU="[object GeneratorFunction]",jU=/[\\^$.*+?()[\]{}|]/g,OU=/^\[object .+?Constructor\]$/,DU=typeof sn=="object"&&sn&&sn.Object===Object&&sn,RU=typeof self=="object"&&self&&self.Object===Object&&self,Cx=DU||RU||Function("return this")();function LU(e,n){var t=e?e.length:0;return!!t&&FU(e,n,0)>-1}function $U(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 FU(e,n,t){if(n!==n)return $U(e,NU,t);for(var r=t-1,o=e.length;++r<o;)if(e[r]===n)return r;return-1}function NU(e){return e!==e}function zU(e,n){return e.has(n)}function BU(e,n){return e==null?void 0:e[n]}function UU(e){var n=!1;if(e!=null&&typeof e.toString!="function")try{n=!!(e+"")}catch{}return n}function fk(e){var n=-1,t=Array(e.size);return e.forEach(function(r){t[++n]=r}),t}var HU=Array.prototype,KU=Function.prototype,gk=Object.prototype,hm=Cx["__core-js_shared__"],w1=function(){var e=/[^.]+$/.exec(hm&&hm.keys&&hm.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),mk=KU.toString,Ix=gk.hasOwnProperty,WU=gk.toString,GU=RegExp("^"+mk.call(Ix).replace(jU,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),VU=HU.splice,YU=Ex(Cx,"Map"),pm=Ex(Cx,"Set"),Wc=Ex(Object,"create");function Li(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 XU(){this.__data__=Wc?Wc(null):{}}function qU(e){return this.has(e)&&delete this.__data__[e]}function ZU(e){var n=this.__data__;if(Wc){var t=n[e];return t===Px?void 0:t}return Ix.call(n,e)?n[e]:void 0}function QU(e){var n=this.__data__;return Wc?n[e]!==void 0:Ix.call(n,e)}function JU(e,n){var t=this.__data__;return t[e]=Wc&&n===void 0?Px:n,this}Li.prototype.clear=XU;Li.prototype.delete=qU;Li.prototype.get=ZU;Li.prototype.has=QU;Li.prototype.set=JU;function Ml(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 e4(){this.__data__=[]}function t4(e){var n=this.__data__,t=Df(n,e);if(t<0)return!1;var r=n.length-1;return t==r?n.pop():VU.call(n,t,1),!0}function n4(e){var n=this.__data__,t=Df(n,e);return t<0?void 0:n[t][1]}function r4(e){return Df(this.__data__,e)>-1}function o4(e,n){var t=this.__data__,r=Df(t,e);return r<0?t.push([e,n]):t[r][1]=n,this}Ml.prototype.clear=e4;Ml.prototype.delete=t4;Ml.prototype.get=n4;Ml.prototype.has=r4;Ml.prototype.set=o4;function Al(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 s4(){this.__data__={hash:new Li,map:new(YU||Ml),string:new Li}}function i4(e){return Rf(this,e).delete(e)}function a4(e){return Rf(this,e).get(e)}function l4(e){return Rf(this,e).has(e)}function c4(e,n){return Rf(this,e).set(e,n),this}Al.prototype.clear=s4;Al.prototype.delete=i4;Al.prototype.get=a4;Al.prototype.has=l4;Al.prototype.set=c4;function vp(e){var n=-1,t=e?e.length:0;for(this.__data__=new Al;++n<t;)this.add(e[n])}function u4(e){return this.__data__.set(e,Px),this}function d4(e){return this.__data__.has(e)}vp.prototype.add=vp.prototype.push=u4;vp.prototype.has=d4;function Df(e,n){for(var t=e.length;t--;)if(v4(e[t][0],n))return t;return-1}function h4(e){if(!yk(e)||m4(e))return!1;var n=x4(e)||UU(e)?GU:OU;return n.test(y4(e))}function p4(e,n,t){var r=-1,o=LU,s=e.length,i=!0,a=[],l=a;if(s>=_U){var c=f4(e);if(c)return fk(c);i=!1,o=zU,l=new vp}else l=a;e:for(;++r<s;){var u=e[r],h=u;if(u=u!==0?u:0,i&&h===h){for(var p=l.length;p--;)if(l[p]===h)continue e;a.push(u)}else o(l,h,t)||(l!==a&&l.push(h),a.push(u))}return a}var f4=pm&&1/fk(new pm([,-0]))[1]==TU?function(e){return new pm(e)}:w4;function Rf(e,n){var t=e.__data__;return g4(n)?t[typeof n=="string"?"string":"hash"]:t.map}function Ex(e,n){var t=BU(e,n);return h4(t)?t:void 0}function g4(e){var n=typeof e;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?e!=="__proto__":e===null}function m4(e){return!!w1&&w1 in e}function y4(e){if(e!=null){try{return mk.call(e)}catch{}try{return e+""}catch{}}return""}function S4(e){return e&&e.length?p4(e):[]}function v4(e,n){return e===n||e!==e&&n!==n}function x4(e){var n=yk(e)?WU.call(e):"";return n==MU||n==AU}function yk(e){var n=typeof e;return!!e&&(n=="object"||n=="function")}function w4(){}var b4=S4;const P4=ei(b4),mc={Good:"#40C057",Mid:"#FFC078",Poor:"#E03131"},C4=mc.Good;class Sk{constructor(){g(this,"startTime",0);g(this,"name","");g(this,"frames",0);g(this,"started",!1);g(this,"frame",null);g(this,"recordFrame",()=>{this.frames++,this.started&&(this.frame=requestAnimationFrame(this.recordFrame))})}start(n){this.name=n,this.frames=0,this.started=!0,this.frame!==null&&cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(this.recordFrame),this.startTime=performance.now()}stop(){this.started=!1,this.frame!==null&&cancelAnimationFrame(this.frame);const n=(performance.now()-this.startTime)/1e3,t=n===0?0:Math.floor(this.frames/n),r=t>55?mc.Good:t>30?mc.Mid:mc.Poor,o=r===mc.Mid?"black":"white",s=this.name[0].toUpperCase()+this.name.slice(1);console.debug(`%cPerf%c ${s} %c${t}%c fps`,`color: white; background: ${C4};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 kx(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 me(e){return e.filter(n=>n!=null)}function Nt(e){return e[e.length-1]}function I4(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 E4(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(){g(this,"items",new WeakMap)}get(n,t){return this.items.has(n)||this.items.set(n,t(n)),this.items.get(n)}}function vk(e){const n=(...t)=>{try{return e(...t)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,n),r}};return n}const xp=()=>{},gn={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function an(e,n){const t=n&&e&&typeof e=="object"&&n in e?e[n]:e;throw new Error(`Unknown switch case ${t}`)}const st=vk((e,n)=>{if(!e)throw new Error(n||"Assertion Error")}),yr=vk((e,n)=>{if(e==null)throw new Error(n??"value must be defined");return e});function xk(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 b1=new WeakMap;function _x(e,n){if(typeof e!="object"||e===null)return;let t=b1.get(e);t||(t={tags:{},extras:{}},b1.set(e,t)),n.tags&&(t.tags={...t.tags,...n.tags}),n.extras&&(t.extras={...t.extras,...n.extras})}async function So(e,n){return window.fetch(e,{referrerPolicy:"strict-origin-when-cross-origin",...n})}const il=(e,n)=>{const t=new window.Image(e,n);return t.referrerPolicy="strict-origin-when-cross-origin",t};class Ai{static async dataUrlToArrayBuffer(n){return So(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 uS(e){let n=0;for(let t=0;t<e.length;t++)n=(n<<5)-n+e.charCodeAt(t),n|=0;return n+""}function k4(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 _4(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,l,c=1024){if(!i)return-1;i=new RegExp(i,"g");const u=i.source.length,h=new TextDecoder,p=s.length;if(typeof l>"u"&&(l=p),a>=p||l<=0||a>=l)return-1;s=s.subarray(a,l);let f=-1,S=0,m=0,x="";e:for(;S<s.length;){const y=S+c,v=s.subarray(S,y),b=h.decode(v,{stream:!0}),E=x+b;let I,C=-1;for(;(I=i.exec(E))!==null;){C=I.index-x.length,f=m+C;break e}S=y,m+=b.length;const k=C>-1?C+u:b.length-u;x=b.slice(k)}return f>=0&&(f+=a>=0?a:p+a),f}const o=r(n,"IDAT",12);return o>=12?r(n,"acTL",8,o)>=8:!1}const T4=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 P1(e,n){let t=0;for(;e[n+t];)t+=e[n+t]+1;return t+1}function M4(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function A4(e){const n=new Uint8Array(e);let t,r,o=0,s=0;if(!M4(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+=P1(n,o+1)+1;break;case 33:o+=2,o+=P1(n,o);break;case 59:o=n.length;break;default:o=n.length;break}return s>1}let dS=[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"&&(dS=new Int32Array(dS));/*!
|
|
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 j4=(e,n)=>{let t=~~n^-1;for(let r=0;r<e.length;r++)t=dS[(t^e[r])&255]^t>>>8;return t^-1},C1=4,I1=4;class so{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(!so.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=so.getChunkType(n,t);if(i==="IDAT"&&r[i]){t+=s+C1+I1;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:t+4,size:s},t+=s+C1+I1}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 so.readChunks(n)[t]}static setPhysChunk(n,t=1,r){let o=46,s=0;const i=so.findChunk(n,"pHYs");i&&(o=i.start,s=i.size);const a=so.findChunk(n,"IDAT");a&&(o=a.start,s=0);const l=new ArrayBuffer(21),c=new DataView(l);c.setUint32(0,9),c.setUint8(4,112),c.setUint8(5,72),c.setUint8(6,89),c.setUint8(7,115);const u=2835.5;c.setInt32(8,u*t),c.setInt32(12,u*t),c.setInt8(16,1);const h=new Uint8Array(l.slice(4,17));c.setInt32(17,j4(h));const p=n.buffer.slice(0,o),f=n.buffer.slice(o+s);return new Blob([p,l,f],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 O4(e){return!e||e.length<12?!1:e[8]===87&&e[9]===69&&e[10]===66&&e[11]===80}function D4(e){const n=new Uint8Array(e);return!O4(n)||!n||n.length<21?!1:(n[20]>>1&1)===1}const wk=Object.freeze(["image/svg+xml"]),bk=Object.freeze(["image/jpeg","image/png","image/webp"]),Pk=Object.freeze(["image/gif","image/apng","image/avif"]),Tx=Object.freeze([...bk,...wk,...Pk]),Ck=Object.freeze(["video/mp4","video/webm","video/quicktime"]),R4=[...Tx,...Ck].join(",");class lo{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=il();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 lo.usingObjectURL(n,async t=>{const r=await lo.loadVideo(t);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(n){const t=await lo.usingObjectURL(n,lo.loadImage);try{if(n.type==="image/png"){const r=new DataView(await n.arrayBuffer());if(so.isPng(r,0)){const o=so.findChunk(r,"pHYs");if(o){const s=so.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"?A4(await n.arrayBuffer()):n.type==="image/avif"?T4(await n.arrayBuffer()):n.type==="image/webp"?D4(await n.arrayBuffer()):n.type==="image/apng"?_4(await n.arrayBuffer()):!1}static isAnimatedImageType(n){return Pk.includes(n||"")}static isStaticImageType(n){return bk.includes(n||"")}static isVectorImageType(n){return wk.includes(n||"")}static isImageType(n){return Tx.includes(n)}static async usingObjectURL(n,t){const r=URL.createObjectURL(n);try{return await t(r)}finally{URL.revokeObjectURL(r)}}}function fd(e,n,t){return e+(n-e)*t}function Gr(e=""){let n=0,t=0,r=0,o=0;function s(){const i=n^n<<11;return n=t,t=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)n^=e.charCodeAt(i)|0,s();return s}function al(e,n,t,r=!1){const[o,s]=n,[i,a]=t,l=i+(e-o)/(s-o)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function po(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function jn(e,n){if(po(e,n))return e[n]}function E1(e){return Object.keys(e)}function gt(e){return Object.values(e)}function Ln(e){return Object.entries(e)}function Ik(e){return Object.fromEntries(e)}function _c(e,n){const t={};let r=!1;for(const[o,s]of Ln(e))n(o,s)?t[o]=s:r=!0;return r?t:e}function Mu(e,n){const t={};for(const[r,o]of Ln(e)){const s=n(r,o);t[r]=s}return t}function Ek(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 Zn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",kk="a0",_k="A00000000000000000000000000";function Tk(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 Mk(e){if(e.length!==Tk(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function k1(e){if(e===void 0)throw Error("n is undefined")}function _1(e){Mk(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=Zn.indexOf(t[o])+1;s===Zn.length?t[o]="0":(t[o]=Zn.charAt(s),r=!1)}if(r){if(n==="Z")return"a0";if(n==="z")return;const o=String.fromCharCode(n.charCodeAt(0)+1);return o>"a"?t.push("0"):t.pop(),o+t.join("")}else return n+t.join("")}function L4(e){Mk(e);const[n,...t]=e.split("");let r=!0;for(let o=t.length-1;r&&o>=0;o--){const s=Zn.indexOf(t[o])-1;s===-1?t[o]=Zn.slice(-1):(t[o]=Zn.charAt(s),r=!1)}if(r){if(n==="a")return"Z"+Zn.slice(-1);if(n==="A")return;const o=String.fromCharCode(n.charCodeAt(0)-1);return o<"Z"?t.push(Zn.slice(-1)):t.pop(),o+t.join("")}else return n+t.join("")}function _a(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)+_a(e.slice(o),n.slice(o))}const t=e?Zn.indexOf(e.charAt(0)):0,r=n!==void 0?Zn.indexOf(n.charAt(0)):Zn.length;if(r-t>1){const o=Math.round(.5*(t+r));return Zn.charAt(o)}else return n&&n.length>1?n.slice(0,1):Zn.charAt(t)+_a(e.slice(1),void 0)}function yc(e){const n=Tk(e.charAt(0));if(n>e.length)throw new Error("invalid index: "+e);return e.slice(0,n)}function hS(e){if(e===_k)throw new Error("invalid index: "+e);const n=yc(e);if(e.slice(n.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function pa(e,n){if(e!==void 0&&hS(e),n!==void 0&&hS(n),e!==void 0&&n!==void 0&&e>=n)throw new Error(e+" >= "+n);if(e===void 0&&n===void 0)return kk;if(e===void 0){if(n===void 0)throw Error("b is undefined");const a=yc(n),l=n.slice(a.length);if(a===_k)return a+_a("",l);if(a<n)return a;const c=L4(a);return k1(c),c}if(n===void 0){const a=yc(e),l=e.slice(a.length),c=_1(a);return c===void 0?a+_a(l,void 0):c}const t=yc(e),r=e.slice(t.length),o=yc(n),s=n.slice(o.length);if(t===o)return t+_a(r,s);const i=_1(t);return k1(i),i<n?i:t+_a(r,void 0)}function Ks(e,n,t){if(t===0)return[];if(t===1)return[pa(e,n)];if(n===void 0){let s=pa(e,n);const i=[s];for(let a=0;a<t-1;a++)s=pa(s,n),i.push(s);return i}if(e===void 0){let s=pa(e,n);const i=[s];for(let a=0;a<t-1;a++)s=pa(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(t/2),o=pa(e,n);return[...Ks(e,o,r),o,...Ks(o,n,t-r-1)]}const $4=kk;function F4(e){hS(e)}function ll(e,n,t){return Ks(e,n,t)}function fm(e,n){return Ks(e,void 0,n)}function Gc(e,n){return Ks(e,n,1)[0]}function $o(e){return Ks(e,void 0,1)[0]}function N4(e){return Ks(void 0,e,1)[0]}function Vc(e,n="a1"){return[n,...Ks(n,void 0,e)]}function on(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function z4(e,n){return e.id>n.id?1:-1}function Mx(e){try{return localStorage.getItem(e)}catch{return null}}function Ax(e,n){try{localStorage.setItem(e,n)}catch{}}function B4(){try{localStorage.clear()}catch{}}function Ak(e){try{return sessionStorage.getItem(e)}catch{return null}}function jx(e,n){try{sessionStorage.setItem(e,n)}catch{}}function jk(e){try{sessionStorage.removeItem(e)}catch{}}function U4(){try{sessionStorage.clear()}catch{}}const H4=()=>typeof process<"u"&&!1,Ta=[],K4=60,yh=Math.ceil(1e3/K4);let Xl,gm=0,pS=0;const W4=()=>{const e=Ta.splice(0,Ta.length);for(const n of e)n()};function Ok(){if(Xl)return;const e=Date.now(),n=e-pS;if(gm+n<yh){Xl=requestAnimationFrame(()=>{Xl=void 0,Ok()});return}Xl=requestAnimationFrame(()=>{Xl=void 0,pS=e,gm=Math.min(gm+n-yh,yh*10),W4()})}let T1=!1;function Dk(e){return H4()?(e(),()=>{}):(Ta.includes(e)||(Ta.push(e),T1||(T1=!0,pS=Date.now()-yh-1),Ok()),()=>{const n=Ta.indexOf(e);n>-1&&Ta.splice(n,1)})}class G4{constructor(){g(this,"timeouts",[]);g(this,"intervals",[]);g(this,"rafs",[])}setTimeout(n,t,...r){const o=window.setTimeout(n,t,r);return this.timeouts.push(o),o}setInterval(n,t,...r){const o=window.setInterval(n,t,r);return this.intervals.push(o),o}requestAnimationFrame(n){const t=window.requestAnimationFrame(n);return this.rafs.push(t),t}dispose(){this.timeouts.forEach(n=>clearTimeout(n)),this.intervals.forEach(n=>clearInterval(n)),this.rafs.forEach(n=>cancelAnimationFrame(n)),this.timeouts.length=0,this.intervals.length=0,this.rafs.length=0}}function V4(e){return e!==null}function Y4(){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 Rk=Y4(),rt=Rk[0];Rk[1];const X4=Object.getPrototypeOf(rt({}));let Au=(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 Lf{constructor(n,t){g(this,"createDefaultProperties");g(this,"validator");g(this,"ephemeralKeys");g(this,"ephemeralKeySet");g(this,"scope");g(this,"isInstance",n=>(n==null?void 0:n.typeName)===this.typeName);this.typeName=n,this.createDefaultProperties=t.createDefaultProperties,this.validator=t.validator??{validate:o=>o},this.scope=t.scope??"document",this.ephemeralKeys=t.ephemeralKeys;const r=new Set;if(t.ephemeralKeys)for(const[o,s]of Ln(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{...rt(n),id:this.createId()}}createId(n){return this.typeName+":"+(n??Au())}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 Lf(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 Io(e,n){return new Lf(e,{createDefaultProperties:()=>({}),validator:n.validator,scope:n.scope,ephemeralKeys:n.ephemeralKeys})}function wp(){return{added:{},updated:{},removed:{}}}function fS(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 Lk(e){return Object.keys(e.added).length===0&&Object.keys(e.updated).length===0&&Object.keys(e.removed).length===0}function Ox(e){const n={added:{},removed:{},updated:{}};return Tc(n,e),n}function Tc(e,n){for(const t of n){for(const[r,o]of Ln(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 Ln(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 Ln(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 $k(e){return e&&typeof e=="object"&&"parents"in e}function Fk(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 bp=(e,n)=>{if(e.children.remove(n)&&e.children.isEmpty&&$k(e))for(let t=0,r=e.parents.length;t<r;t++)bp(e.parents[t],e)},Dx=(e,n)=>{if(e.children.add(n)&&$k(e))for(let t=0,r=e.parents.length;t<r;t++)Dx(e.parents[t],e)};function Nk(e,n){return e===n||Object.is(e,n)||!!(e&&n&&typeof e.equals=="function"&&e.equals(n))}function ri(e,n){const t=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[t]??(r[t]=n()),r[t]}const Ho=ri("empty_array",()=>Object.freeze([])),M1=8;class Pp{constructor(){g(this,"arraySize",0);g(this,"array",Array(M1));g(this,"set",null)}get isEmpty(){if(this.array)return this.arraySize===0;if(this.set)return this.set.size===0;throw new Error("no set or array")}add(n){if(this.array)return this.array.indexOf(n)!==-1?!1:this.arraySize<M1?(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 Jn=Symbol.for("com.tldraw.state/RESET_VALUE");class zk{constructor(n){g(this,"index",0);g(this,"buffer");this.capacity=n,this.buffer=new Array(n)}pushEntry(n,t,r){if(r!==void 0){if(r===Jn){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 Jn;const[l,c]=a;if(s===0&&n>=c)return[];if(l<=n&&n<c){const u=s+1,h=new Array(u);for(let p=0;p<u;p++)h[p]=o[(i+p)%r][2];return h}}return Jn}}class q4{constructor(n,t){g(this,"offset",0);g(this,"maybeRemoved");this.below=n,this.child=t}}const tt=ri("capture",()=>({stack:null}));function mm(e){const n=tt.stack;tt.stack=null;try{return e()}finally{tt.stack=n}}function Bk(e){tt.stack=new q4(tt.stack,e),e.parentSet.clear()}function Uk(){const e=tt.stack;if(tt.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)||bp(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)||bp(t,e.child)}}function Cp(e){if(tt.stack){if(tt.stack.child.parentSet.has(e))return;if(tt.stack.child.parentSet.add(e),tt.stack.child.isActivelyListening&&Dx(e,tt.stack.child),tt.stack.offset<tt.stack.child.parents.length){const t=tt.stack.child.parents[tt.stack.offset];t!==e&&(tt.stack.maybeRemoved?tt.stack.maybeRemoved.push(t):tt.stack.maybeRemoved=[t])}tt.stack.child.parents[tt.stack.offset]=e,tt.stack.child.parentEpochs[tt.stack.offset]=e.lastChangedEpoch,tt.stack.offset++}}const ks=-1;class Z4{constructor(n,t,r){g(this,"_isActivelyListening",!1);g(this,"lastTraversedEpoch",ks);g(this,"lastReactedEpoch",ks);g(this,"_scheduleCount",0);g(this,"parentSet",new Pp);g(this,"parentEpochs",[]);g(this,"parents",[]);g(this,"_scheduleEffect");g(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=n,this.runEffect=t,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==kn()){if(this.parents.length&&!Fk(this)){this.lastReactedEpoch=kn();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++)Dx(this.parents[n],this)}detach(){this._isActivelyListening=!1;for(let n=0,t=this.parents.length;n<t;n++)bp(this.parents[n],this)}execute(){try{Bk(this);const n=kn(),t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=n,t}finally{Uk()}}}const jl=ri("EffectScheduler",()=>Z4);function oa(e,n,t){const r=new jl(e,n,t);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function Q4(e,n,t){const r=new jl(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 J4{constructor(n){g(this,"initialAtomValues",new Map);this.parent=n}get isRoot(){return this.parent===null}commit(){this.isRoot?Hk(this.initialAtomValues.keys()):this.initialAtomValues.forEach((n,t)=>{this.parent.initialAtomValues.has(t)||this.parent.initialAtomValues.set(t,n)})}abort(){ze.globalEpoch++,this.initialAtomValues.forEach((n,t)=>{var r;t.set(n),(r=t.historyBuffer)==null||r.clear()}),this.commit()}}const ze=ri("transactions",()=>({globalEpoch:ks+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:ks+1}));function e8(){return ze.reactionEpoch}function kn(){return ze.globalEpoch}function t8(){return ze.globalIsReacting}function Rx(e,n){n.lastTraversedEpoch!==ze.globalEpoch&&(n.lastTraversedEpoch=ze.globalEpoch,n instanceof jl?e.add(n):n.children.visit(t=>Rx(e,t)))}function Hk(e){var n;if(ze.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{ze.globalIsReacting=!0,ze.reactionEpoch=ze.globalEpoch;const t=new Set;for(const o of e)o.children.visit(s=>Rx(t,s));for(const o of t)o.maybeScheduleEffect();let r=0;for(;(n=ze.cleanupReactors)!=null&&n.size;){if(r++>1e3)throw new Error("Reaction update depth limit exceeded");const o=ze.cleanupReactors;ze.cleanupReactors=null;for(const s of o)s.maybeScheduleEffect()}}finally{ze.cleanupReactors=null,ze.globalIsReacting=!1}}function n8(e,n){if(ze.globalIsReacting){const t=ze.cleanupReactors??(ze.cleanupReactors=new Set);e.children.visit(r=>Rx(t,r))}else ze.currentTransaction?ze.currentTransaction.initialAtomValues.has(e)||ze.currentTransaction.initialAtomValues.set(e,n):Hk([e])}function r8(){ze.globalEpoch++}function o8(e){const n=new J4(ze.currentTransaction);ze.currentTransaction=n;try{let t,r=!1;try{t=e(()=>r=!0)}catch(o){throw n.abort(),o}return r?n.abort():n.commit(),t}finally{ze.currentTransaction=ze.currentTransaction.parent}}function js(e){return ze.currentTransaction?e():o8(e)}class s8{constructor(n,t,r){g(this,"isEqual");g(this,"computeDiff");g(this,"lastChangedEpoch",kn());g(this,"children",new Pp);g(this,"historyBuffer");this.name=n,this.current=t,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new zk(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(n){return this.current}get(){return Cp(this),this.current}set(n,t){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,n))??Nk(this.current,n))return this.current;r8(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,kn(),t??((s=this.computeDiff)==null?void 0:s.call(this,this.current,n,this.lastChangedEpoch,kn()))??Jn),this.lastChangedEpoch=kn();const r=this.current;return this.current=n,n8(this,r),n}update(n){return this.set(n(this.current))}getDiffSince(n){var t;return Cp(this),n>=this.lastChangedEpoch?Ho:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Jn}}const i8=ri("Atom",()=>s8);function Mt(e,n,t){return new i8(e,n,t)}let A1=!1;function a8(){A1||(A1=!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 Sc=Symbol.for("com.tldraw.state/UNINITIALIZED"),ji=e=>e===Sc,gS=ri("WithDiff",()=>class{constructor(n,t){this.value=n,this.diff=t}});function vc(e,n){return new gS(e,n)}class l8{constructor(n,t,r){g(this,"lastChangedEpoch",ks);g(this,"lastTraversedEpoch",ks);g(this,"lastCheckedEpoch",ks);g(this,"parentSet",new Pp);g(this,"parents",[]);g(this,"parentEpochs",[]);g(this,"children",new Pp);g(this,"historyBuffer");g(this,"state",Sc);g(this,"error",null);g(this,"computeDiff");g(this,"isEqual");this.name=n,this.derive=t,r!=null&&r.historyLength&&(this.historyBuffer=new zk(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??Nk}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(n){var o;const t=this.lastChangedEpoch===ks,r=kn();if(!t&&(this.lastCheckedEpoch===r||this.isActivelyListening&&t8()&&this.lastTraversedEpoch<e8()||!Fk(this)))if(this.lastCheckedEpoch=r,this.error){if(n)return this.state;throw this.error.thrownValue}else return this.state;try{Bk(this);const s=this.derive(this.state,this.lastCheckedEpoch),i=s instanceof gS?s.value:s,a=this.state===Sc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=s instanceof gS?s.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,kn(),l??((o=this.computeDiff)==null?void 0:o.call(this,this.state,i,this.lastCheckedEpoch,kn()))??Jn)}this.lastChangedEpoch=kn(),this.state=i}return this.error=null,this.lastCheckedEpoch=kn(),this.state}catch(s){if(this.state!==Sc&&(this.state=Sc,this.lastChangedEpoch=kn()),this.lastCheckedEpoch=kn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:s},!n)throw s;return this.state}finally{Uk()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Cp(this)}}getDiffSince(n){var t;return this.__unsafe__getWithoutCapture(!0),Cp(this),n>=this.lastChangedEpoch?Ho:((t=this.historyBuffer)==null?void 0:t.getChangesSince(n))??Jn}}const Lx=ri("Computed",()=>l8);function c8(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 Lx(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[d8]=!0,r}function j1(e={},n,t,r){return r.get?(a8(),u8(e,n,t,r)):c8(e,n,t,r)}function u8(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 Lx(t,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const d8="@@__isComputedMethod__@@";function V(){if(arguments.length===1){const e=arguments[0];return(n,t,r)=>j1(e,n,t,r)}else return typeof arguments[0]=="string"?new Lx(arguments[0],arguments[1],arguments[2]):j1(void 0,arguments[0],arguments[1],arguments[2])}const Kk=1,h8=ri("apiVersion",()=>Kk);if(h8!==Kk)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function $f(e,n){const t=xe.useRef(n);t.current=n;const[r,o,s]=xe.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new jl(`useStateTracking(${e})`,()=>{var u;return(u=t.current)==null?void 0:u.call(t)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[e]);return xe.useSyncExternalStore(o,s,s),xe.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const O1={apply(e,n,t){return $f(e.displayName??e.name??"tracked(???)",()=>e.apply(n,t))}},p8=Symbol.for("react.memo"),f8=Symbol.for("react.forward_ref");function ar(e){let n=null;const t=e.$$typeof;return t===p8&&(e=e.type,n=e.compare),t===f8?P.memo(P.forwardRef(new Proxy(e.render,O1))):P.memo(new Proxy(e,O1),n)}function g8(){const e=arguments[0],n=arguments[1],t=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return P.useMemo(()=>V(`useComputed(${e})`,n,t),r)}function Os(e,n,t=Ho){P.useEffect(()=>{const r=new jl(e,n);return r.attach(),r.execute(),()=>{r.detach()}},t)}function G(){const e=arguments,n=e.length===3?e[2]:[e[0]],t=e.length===3?e[0]:`useValue(${e[0].name})`,r=P.useRef(!0);r.current=!0;const o=P.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}=P.useMemo(()=>({subscribe:a=>oa(`useValue(${t})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return P.useSyncExternalStore(s,i,i)}finally{r.current=!1}}var Ip={exports:{}};Ip.exports;(function(e,n){var t=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",p="[object Error]",f="[object Function]",S="[object GeneratorFunction]",m="[object Map]",x="[object Number]",y="[object Null]",v="[object Object]",b="[object Promise]",E="[object Proxy]",I="[object RegExp]",C="[object Set]",k="[object String]",T="[object Symbol]",O="[object Undefined]",_="[object WeakMap]",A="[object ArrayBuffer]",L="[object DataView]",j="[object Float32Array]",R="[object Float64Array]",F="[object Int8Array]",W="[object Int16Array]",K="[object Int32Array]",z="[object Uint8Array]",U="[object Uint8ClampedArray]",X="[object Uint16Array]",J="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,ye=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,ae={};ae[j]=ae[R]=ae[F]=ae[W]=ae[K]=ae[z]=ae[U]=ae[X]=ae[J]=!0,ae[a]=ae[l]=ae[A]=ae[u]=ae[L]=ae[h]=ae[p]=ae[f]=ae[m]=ae[x]=ae[v]=ae[I]=ae[C]=ae[k]=ae[_]=!1;var Ue=typeof sn=="object"&&sn&&sn.Object===Object&&sn,je=typeof self=="object"&&self&&self.Object===Object&&self,et=Ue||je||Function("return this")(),Ae=n&&!n.nodeType&&n,at=Ae&&!0&&e&&!e.nodeType&&e,Ne=at&&at.exports===Ae,Wn=Ne&&Ue.process,Rt=function(){try{return Wn&&Wn.binding&&Wn.binding("util")}catch{}}(),Cn=Rt&&Rt.isTypedArray;function St(M,$){for(var Y=-1,ee=M==null?0:M.length,Xe=0,fe=[];++Y<ee;){var ft=M[Y];$(ft,Y,M)&&(fe[Xe++]=ft)}return fe}function Xt(M,$){for(var Y=-1,ee=$.length,Xe=M.length;++Y<ee;)M[Xe+Y]=$[Y];return M}function _o(M,$){for(var Y=-1,ee=M==null?0:M.length;++Y<ee;)if($(M[Y],Y,M))return!0;return!1}function Bl(M,$){for(var Y=-1,ee=Array(M);++Y<M;)ee[Y]=$(Y);return ee}function ds(M){return function($){return M($)}}function HR(M,$){return M.has($)}function KR(M,$){return M==null?void 0:M[$]}function WR(M){var $=-1,Y=Array(M.size);return M.forEach(function(ee,Xe){Y[++$]=[Xe,ee]}),Y}function GR(M,$){return function(Y){return M($(Y))}}function VR(M){var $=-1,Y=Array(M.size);return M.forEach(function(ee){Y[++$]=ee}),Y}var YR=Array.prototype,XR=Function.prototype,ed=Object.prototype,Rg=et["__core-js_shared__"],ab=XR.toString,Jr=ed.hasOwnProperty,lb=function(){var M=/[^.]+$/.exec(Rg&&Rg.keys&&Rg.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),cb=ed.toString,qR=RegExp("^"+ab.call(Jr).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),ub=Ne?et.Buffer:void 0,td=et.Symbol,db=et.Uint8Array,hb=ed.propertyIsEnumerable,ZR=YR.splice,fi=td?td.toStringTag:void 0,pb=Object.getOwnPropertySymbols,QR=ub?ub.isBuffer:void 0,JR=GR(Object.keys,Object),Lg=ua(et,"DataView"),Ul=ua(et,"Map"),$g=ua(et,"Promise"),Fg=ua(et,"Set"),Ng=ua(et,"WeakMap"),Hl=ua(Object,"create"),eL=yi(Lg),tL=yi(Ul),nL=yi($g),rL=yi(Fg),oL=yi(Ng),fb=td?td.prototype:void 0,zg=fb?fb.valueOf:void 0;function gi(M){var $=-1,Y=M==null?0:M.length;for(this.clear();++$<Y;){var ee=M[$];this.set(ee[0],ee[1])}}function sL(){this.__data__=Hl?Hl(null):{},this.size=0}function iL(M){var $=this.has(M)&&delete this.__data__[M];return this.size-=$?1:0,$}function aL(M){var $=this.__data__;if(Hl){var Y=$[M];return Y===r?void 0:Y}return Jr.call($,M)?$[M]:void 0}function lL(M){var $=this.__data__;return Hl?$[M]!==void 0:Jr.call($,M)}function cL(M,$){var Y=this.__data__;return this.size+=this.has(M)?0:1,Y[M]=Hl&&$===void 0?r:$,this}gi.prototype.clear=sL,gi.prototype.delete=iL,gi.prototype.get=aL,gi.prototype.has=lL,gi.prototype.set=cL;function To(M){var $=-1,Y=M==null?0:M.length;for(this.clear();++$<Y;){var ee=M[$];this.set(ee[0],ee[1])}}function uL(){this.__data__=[],this.size=0}function dL(M){var $=this.__data__,Y=rd($,M);if(Y<0)return!1;var ee=$.length-1;return Y==ee?$.pop():ZR.call($,Y,1),--this.size,!0}function hL(M){var $=this.__data__,Y=rd($,M);return Y<0?void 0:$[Y][1]}function pL(M){return rd(this.__data__,M)>-1}function fL(M,$){var Y=this.__data__,ee=rd(Y,M);return ee<0?(++this.size,Y.push([M,$])):Y[ee][1]=$,this}To.prototype.clear=uL,To.prototype.delete=dL,To.prototype.get=hL,To.prototype.has=pL,To.prototype.set=fL;function mi(M){var $=-1,Y=M==null?0:M.length;for(this.clear();++$<Y;){var ee=M[$];this.set(ee[0],ee[1])}}function gL(){this.size=0,this.__data__={hash:new gi,map:new(Ul||To),string:new gi}}function mL(M){var $=od(this,M).delete(M);return this.size-=$?1:0,$}function yL(M){return od(this,M).get(M)}function SL(M){return od(this,M).has(M)}function vL(M,$){var Y=od(this,M),ee=Y.size;return Y.set(M,$),this.size+=Y.size==ee?0:1,this}mi.prototype.clear=gL,mi.prototype.delete=mL,mi.prototype.get=yL,mi.prototype.has=SL,mi.prototype.set=vL;function nd(M){var $=-1,Y=M==null?0:M.length;for(this.__data__=new mi;++$<Y;)this.add(M[$])}function xL(M){return this.__data__.set(M,r),this}function wL(M){return this.__data__.has(M)}nd.prototype.add=nd.prototype.push=xL,nd.prototype.has=wL;function hs(M){var $=this.__data__=new To(M);this.size=$.size}function bL(){this.__data__=new To,this.size=0}function PL(M){var $=this.__data__,Y=$.delete(M);return this.size=$.size,Y}function CL(M){return this.__data__.get(M)}function IL(M){return this.__data__.has(M)}function EL(M,$){var Y=this.__data__;if(Y instanceof To){var ee=Y.__data__;if(!Ul||ee.length<t-1)return ee.push([M,$]),this.size=++Y.size,this;Y=this.__data__=new mi(ee)}return Y.set(M,$),this.size=Y.size,this}hs.prototype.clear=bL,hs.prototype.delete=PL,hs.prototype.get=CL,hs.prototype.has=IL,hs.prototype.set=EL;function kL(M,$){var Y=sd(M),ee=!Y&&UL(M),Xe=!Y&&!ee&&Bg(M),fe=!Y&&!ee&&!Xe&&Pb(M),ft=Y||ee||Xe||fe,kt=ft?Bl(M.length,String):[],Lt=kt.length;for(var lt in M)Jr.call(M,lt)&&!(ft&&(lt=="length"||Xe&&(lt=="offset"||lt=="parent")||fe&&(lt=="buffer"||lt=="byteLength"||lt=="byteOffset")||$L(lt,Lt)))&&kt.push(lt);return kt}function rd(M,$){for(var Y=M.length;Y--;)if(vb(M[Y][0],$))return Y;return-1}function _L(M,$,Y){var ee=$(M);return sd(M)?ee:Xt(ee,Y(M))}function Kl(M){return M==null?M===void 0?O:y:fi&&fi in Object(M)?RL(M):BL(M)}function gb(M){return Wl(M)&&Kl(M)==a}function mb(M,$,Y,ee,Xe){return M===$?!0:M==null||$==null||!Wl(M)&&!Wl($)?M!==M&&$!==$:TL(M,$,Y,ee,mb,Xe)}function TL(M,$,Y,ee,Xe,fe){var ft=sd(M),kt=sd($),Lt=ft?l:ps(M),lt=kt?l:ps($);Lt=Lt==a?v:Lt,lt=lt==a?v:lt;var Gn=Lt==v,Mr=lt==v,qt=Lt==lt;if(qt&&Bg(M)){if(!Bg($))return!1;ft=!0,Gn=!1}if(qt&&!Gn)return fe||(fe=new hs),ft||Pb(M)?yb(M,$,Y,ee,Xe,fe):OL(M,$,Lt,Y,ee,Xe,fe);if(!(Y&o)){var hr=Gn&&Jr.call(M,"__wrapped__"),pr=Mr&&Jr.call($,"__wrapped__");if(hr||pr){var fs=hr?M.value():M,Mo=pr?$.value():$;return fe||(fe=new hs),Xe(fs,Mo,Y,ee,fe)}}return qt?(fe||(fe=new hs),DL(M,$,Y,ee,Xe,fe)):!1}function ML(M){if(!bb(M)||NL(M))return!1;var $=xb(M)?qR:ye;return $.test(yi(M))}function AL(M){return Wl(M)&&wb(M.length)&&!!ae[Kl(M)]}function jL(M){if(!zL(M))return JR(M);var $=[];for(var Y in Object(M))Jr.call(M,Y)&&Y!="constructor"&&$.push(Y);return $}function yb(M,$,Y,ee,Xe,fe){var ft=Y&o,kt=M.length,Lt=$.length;if(kt!=Lt&&!(ft&&Lt>kt))return!1;var lt=fe.get(M);if(lt&&fe.get($))return lt==$;var Gn=-1,Mr=!0,qt=Y&s?new nd:void 0;for(fe.set(M,$),fe.set($,M);++Gn<kt;){var hr=M[Gn],pr=$[Gn];if(ee)var fs=ft?ee(pr,hr,Gn,$,M,fe):ee(hr,pr,Gn,M,$,fe);if(fs!==void 0){if(fs)continue;Mr=!1;break}if(qt){if(!_o($,function(Mo,Si){if(!HR(qt,Si)&&(hr===Mo||Xe(hr,Mo,Y,ee,fe)))return qt.push(Si)})){Mr=!1;break}}else if(!(hr===pr||Xe(hr,pr,Y,ee,fe))){Mr=!1;break}}return fe.delete(M),fe.delete($),Mr}function OL(M,$,Y,ee,Xe,fe,ft){switch(Y){case L:if(M.byteLength!=$.byteLength||M.byteOffset!=$.byteOffset)return!1;M=M.buffer,$=$.buffer;case A:return!(M.byteLength!=$.byteLength||!fe(new db(M),new db($)));case u:case h:case x:return vb(+M,+$);case p:return M.name==$.name&&M.message==$.message;case I:case k:return M==$+"";case m:var kt=WR;case C:var Lt=ee&o;if(kt||(kt=VR),M.size!=$.size&&!Lt)return!1;var lt=ft.get(M);if(lt)return lt==$;ee|=s,ft.set(M,$);var Gn=yb(kt(M),kt($),ee,Xe,fe,ft);return ft.delete(M),Gn;case T:if(zg)return zg.call(M)==zg.call($)}return!1}function DL(M,$,Y,ee,Xe,fe){var ft=Y&o,kt=Sb(M),Lt=kt.length,lt=Sb($),Gn=lt.length;if(Lt!=Gn&&!ft)return!1;for(var Mr=Lt;Mr--;){var qt=kt[Mr];if(!(ft?qt in $:Jr.call($,qt)))return!1}var hr=fe.get(M);if(hr&&fe.get($))return hr==$;var pr=!0;fe.set(M,$),fe.set($,M);for(var fs=ft;++Mr<Lt;){qt=kt[Mr];var Mo=M[qt],Si=$[qt];if(ee)var Cb=ft?ee(Si,Mo,qt,$,M,fe):ee(Mo,Si,qt,M,$,fe);if(!(Cb===void 0?Mo===Si||Xe(Mo,Si,Y,ee,fe):Cb)){pr=!1;break}fs||(fs=qt=="constructor")}if(pr&&!fs){var id=M.constructor,ad=$.constructor;id!=ad&&"constructor"in M&&"constructor"in $&&!(typeof id=="function"&&id instanceof id&&typeof ad=="function"&&ad instanceof ad)&&(pr=!1)}return fe.delete(M),fe.delete($),pr}function Sb(M){return _L(M,WL,LL)}function od(M,$){var Y=M.__data__;return FL($)?Y[typeof $=="string"?"string":"hash"]:Y.map}function ua(M,$){var Y=KR(M,$);return ML(Y)?Y:void 0}function RL(M){var $=Jr.call(M,fi),Y=M[fi];try{M[fi]=void 0;var ee=!0}catch{}var Xe=cb.call(M);return ee&&($?M[fi]=Y:delete M[fi]),Xe}var LL=pb?function(M){return M==null?[]:(M=Object(M),St(pb(M),function($){return hb.call(M,$)}))}:GL,ps=Kl;(Lg&&ps(new Lg(new ArrayBuffer(1)))!=L||Ul&&ps(new Ul)!=m||$g&&ps($g.resolve())!=b||Fg&&ps(new Fg)!=C||Ng&&ps(new Ng)!=_)&&(ps=function(M){var $=Kl(M),Y=$==v?M.constructor:void 0,ee=Y?yi(Y):"";if(ee)switch(ee){case eL:return L;case tL:return m;case nL:return b;case rL:return C;case oL:return _}return $});function $L(M,$){return $=$??i,!!$&&(typeof M=="number"||Me.test(M))&&M>-1&&M%1==0&&M<$}function FL(M){var $=typeof M;return $=="string"||$=="number"||$=="symbol"||$=="boolean"?M!=="__proto__":M===null}function NL(M){return!!lb&&lb in M}function zL(M){var $=M&&M.constructor,Y=typeof $=="function"&&$.prototype||ed;return M===Y}function BL(M){return cb.call(M)}function yi(M){if(M!=null){try{return ab.call(M)}catch{}try{return M+""}catch{}}return""}function vb(M,$){return M===$||M!==M&&$!==$}var UL=gb(function(){return arguments}())?gb:function(M){return Wl(M)&&Jr.call(M,"callee")&&!hb.call(M,"callee")},sd=Array.isArray;function HL(M){return M!=null&&wb(M.length)&&!xb(M)}var Bg=QR||VL;function KL(M,$){return mb(M,$)}function xb(M){if(!bb(M))return!1;var $=Kl(M);return $==f||$==S||$==c||$==E}function wb(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=i}function bb(M){var $=typeof M;return M!=null&&($=="object"||$=="function")}function Wl(M){return M!=null&&typeof M=="object"}var Pb=Cn?ds(Cn):AL;function WL(M){return HL(M)?kL(M):jL(M)}function GL(){return[]}function VL(){return!1}e.exports=KL})(Ip,Ip.exports);var m8=Ip.exports;const y8=ei(m8);function S8(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 v8(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 D1(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 R1(e,n,t){const r=Object.fromEntries(Object.keys(t).map(o=>[o,new Set]));for(const[o,s]of Object.entries(t))if("eq"in s){const a=e.index(n,o).get().get(s.eq);if(a)for(const l of a)r[o].add(l)}else if("neq"in s){const i=e.index(n,o);for(const[a,l]of i.get())if(a!==s.neq)for(const c of l)r[o].add(c)}else if("gt"in s){const i=e.index(n,o);for(const[a,l]of i.get())if(a>s.gt)for(const c of l)r[o].add(c)}return S8(Object.values(r))}class x8{constructor(n,t){g(this,"indexCache",new Map);g(this,"historyCache",new Map);this.atoms=n,this.history=t}filterHistory(n){if(this.historyCache.has(n))return this.historyCache.get(n);const t=V("filterHistory:"+n,(r,o)=>{if(ji(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Jn)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of s){for(const h of gt(u.added))if(h.typeName===n)if(i.removed[h.id]){const p=i.removed[h.id];delete i.removed[h.id],l--,p!==h&&(i.updated[h.id]=[p,h],c++)}else i.added[h.id]=h,a++;for(const[h,p]of gt(u.updated))p.typeName===n&&(i.added[p.id]?i.added[p.id]=p:i.updated[p.id]?i.updated[p.id]=[i.updated[p.id][0],p]:(i.updated[p.id]=[h,p],c++));for(const h of gt(u.removed))h.typeName===n&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?vc(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 gt(this.atoms.get())){const a=i.get();if(a.typeName===n){const l=a[t];s.has(l)||s.set(l,new Set),s.get(l).add(a.id)}}return s};return V("index:"+n+":"+t,(s,i)=>{if(ji(s))return o();const a=r.getDiffSince(i);if(a===Jn)return o();const l=new Map,c=(f,S)=>{let m=l.get(f);m||(m=new mh(s.get(f)??new Set)),m.add(S),l.set(f,m)},u=(f,S)=>{let m=l.get(f);m||(m=new mh(s.get(f)??new Set)),m.remove(S),l.set(f,m)};for(const f of a){for(const S of gt(f.added))if(S.typeName===n){const m=S[t];c(m,S.id)}for(const[S,m]of gt(f.updated))if(m.typeName===n){const x=S[t],y=m[t];x!==y&&(u(x,m.id),c(y,m.id))}for(const S of gt(f.removed))if(S.typeName===n){const m=S[t];u(m,S.id)}}let h,p;for(const[f,S]of l){const m=S.get();m&&(h||(h=new Map(s)),p||(p=new Map),m.value.size===0?h.delete(f):h.set(f,m.value),p.set(f,m.diff))}return h&&p?vc(h,p):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 l=t();return Object.keys(l).length===0?new Set(gt(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===n?u.id:[]})):R1(this,n,l)},i=l=>{const c=s(),u=v8(l,c);return u?vc(c,u):l},a=V("ids_query:"+r,t,{isEqual:y8});return V("query:"+r,(l,c)=>{const u=a.get();if(ji(l))return s();if(c<a.lastChangedEpoch)return i(l);const h=o.getDiffSince(c);if(h===Jn)return i(l);const p=new mh(l);for(const S of h){for(const m of gt(S.added))m.typeName===n&&D1(u,m)&&p.add(m.id);for(const[m,x]of gt(S.updated))x.typeName===n&&(D1(u,x)?p.add(x.id):p.remove(x.id));for(const m of gt(S.removed))m.typeName===n&&p.remove(m.id)}const f=p.get();return f?vc(f.value,f.diff):l},{historyLength:50})}exec(n,t){const r=R1(this,n,t);if(r.size===0)return Ho;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class w8{constructor(n){g(this,"_beforeCreateHandlers",{});g(this,"_afterCreateHandlers",{});g(this,"_beforeChangeHandlers",{});g(this,"_afterChangeHandlers",{});g(this,"_beforeDeleteHandlers",{});g(this,"_afterDeleteHandlers",{});g(this,"_operationCompleteHandlers",[]);g(this,"_isEnabled",!0);this.store=n}isEnabled(){return this._isEnabled}setIsEnabled(n){this._isEnabled=n}handleBeforeCreate(n,t){if(!this._isEnabled)return n;const r=this._beforeCreateHandlers[n.typeName];if(r){let o=n;for(const s of r)o=s(o,t);return o}return n}handleAfterCreate(n,t){if(!this._isEnabled)return;const r=this._afterCreateHandlers[n.typeName];if(r)for(const o of r)o(n,t)}handleBeforeChange(n,t,r){if(!this._isEnabled)return t;const o=this._beforeChangeHandlers[t.typeName];if(o){let s=t;for(const i of o)s=i(n,s,r);return s}return t}handleAfterChange(n,t,r){if(!this._isEnabled)return;const o=this._afterChangeHandlers[t.typeName];if(o)for(const s of o)s(n,t,r)}handleBeforeDelete(n,t){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[n.typeName];if(r){for(const o of r)if(o(n,t)===!1)return!1}return!0}handleAfterDelete(n,t){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[n.typeName];if(r)for(const o of r)o(n,t)}handleOperationComplete(n){if(this._isEnabled)for(const t of this._operationCompleteHandlers)t(n)}register(n){const t=[];for(const[r,o]of Object.entries(n))o!=null&&o.beforeCreate&&t.push(this.registerBeforeCreateHandler(r,o.beforeCreate)),o!=null&&o.afterCreate&&t.push(this.registerAfterCreateHandler(r,o.afterCreate)),o!=null&&o.beforeChange&&t.push(this.registerBeforeChangeHandler(r,o.beforeChange)),o!=null&&o.afterChange&&t.push(this.registerAfterChangeHandler(r,o.afterChange)),o!=null&&o.beforeDelete&&t.push(this.registerBeforeDeleteHandler(r,o.beforeDelete)),o!=null&&o.afterDelete&&t.push(this.registerAfterDeleteHandler(r,o.afterDelete));return()=>{for(const r of t)r()}}registerBeforeCreateHandler(n,t){return this._beforeCreateHandlers[n]||(this._beforeCreateHandlers[n]=[]),this._beforeCreateHandlers[n].push(t),()=>vi(this._beforeCreateHandlers[n],t)}registerAfterCreateHandler(n,t){return this._afterCreateHandlers[n]||(this._afterCreateHandlers[n]=[]),this._afterCreateHandlers[n].push(t),()=>vi(this._afterCreateHandlers[n],t)}registerBeforeChangeHandler(n,t){return this._beforeChangeHandlers[n]||(this._beforeChangeHandlers[n]=[]),this._beforeChangeHandlers[n].push(t),()=>vi(this._beforeChangeHandlers[n],t)}registerAfterChangeHandler(n,t){return this._afterChangeHandlers[n]||(this._afterChangeHandlers[n]=[]),this._afterChangeHandlers[n].push(t),()=>vi(this._afterChangeHandlers[n],t)}registerBeforeDeleteHandler(n,t){return this._beforeDeleteHandlers[n]||(this._beforeDeleteHandlers[n]=[]),this._beforeDeleteHandlers[n].push(t),()=>vi(this._beforeDeleteHandlers[n],t)}registerAfterDeleteHandler(n,t){return this._afterDeleteHandlers[n]||(this._afterDeleteHandlers[n]=[]),this._afterDeleteHandlers[n].push(t),()=>vi(this._afterDeleteHandlers[n],t)}registerOperationCompleteHandler(n){return this._operationCompleteHandlers.push(n),()=>vi(this._operationCompleteHandlers,n)}}function vi(e,n){const t=e.indexOf(n);t>=0&&e.splice(t,1)}class $x{constructor(n){g(this,"id");g(this,"atoms",Mt("store_atoms",{}));g(this,"history",Mt("history",0,{historyLength:1e3}));g(this,"query",new x8(this.atoms,this.history));g(this,"listeners",new Set);g(this,"historyAccumulator",new P8);g(this,"historyReactor");g(this,"cancelHistoryReactor",()=>{});g(this,"schema");g(this,"props");g(this,"scopedTypes");g(this,"sideEffects",new w8(this));g(this,"put",(n,t)=>{this.atomic(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.isMergingRemoteChanges?"remote":"user";for(let u=0,h=n.length;u<h;u++){a=n[u];const p=(i??s)[a.id];if(p){const f=p.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(f,a,c),this.schema.validateRecord(this,a,t??"updateRecord",f)===f)continue;p.set(a),l=!0;const m=p.__unsafe__getWithoutCapture();r[a.id]=[f,m],this.addDiffForAfterEvent(f,m)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!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),l&&this.updateHistory({added:o,updated:r,removed:{}})})});g(this,"remove",n=>{this.atomic(()=>{const t=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const s of n){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&t.add(s)}let o;this.atoms.update(s=>{let i;for(const a of n){if(t.has(a)||!(a in s))continue;i||(i={...s}),o||(o={}),delete i[a];const l=s[a].get();o[a]=l,this.addDiffForAfterEvent(l,null)}return i??s}),o&&this.updateHistory({added:{},updated:{},removed:o})})});g(this,"get",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.get()});g(this,"unsafeGetWithoutCapture",n=>{var t;return(t=this.atoms.get()[n])==null?void 0:t.__unsafe__getWithoutCapture()});g(this,"serialize",(n="document")=>{const t={};for(const[r,o]of Ln(this.atoms.get())){const s=o.get();(n==="all"||this.scopedTypes[n].has(s.typeName))&&(t[r]=s)}return t});g(this,"allRecords",()=>gt(this.atoms.get()).map(n=>n.get()));g(this,"clear",()=>{this.remove(E1(this.atoms.get()))});g(this,"update",(n,t)=>{const r=this.atoms.get()[n];if(!r){console.error(`Record ${n} not found. This is probably an error`);return}this.put([t(r.__unsafe__getWithoutCapture())])});g(this,"has",n=>!!this.atoms.get()[n]);g(this,"listen",(n,t)=>{this._flushHistory();const r={onHistory:n,filters:{source:(t==null?void 0:t.source)??"all",scope:(t==null?void 0:t.scope)??"all"}};return this.listeners.add(r),this.historyReactor.scheduler.isActivelyListening||this.historyReactor.start(),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}});g(this,"isMergingRemoteChanges",!1);g(this,"mergeRemoteChanges",n=>{if(this.isMergingRemoteChanges)return n();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,js(n)}finally{this.isMergingRemoteChanges=!1}});g(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()}}});g(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()}}});g(this,"_integrityChecker");g(this,"_isPossiblyCorrupted",!1);g(this,"pendingAfterEvents",null);g(this,"_isInAtomicOp",!1);const{initialData:t,schema:r,id:o}=n;this.id=o??Au(),this.schema=r,this.props=n.props,t&&this.atoms.set(Ik(Ln(t).map(([s,i])=>[s,Mt("atom:"+s,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=Q4("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:s=>this.cancelHistoryReactor=Dk(s)}),this.scopedTypes={document:new Set(gt(this.schema.types).filter(s=>s.scope==="document").map(s=>s.typeName)),session:new Set(gt(this.schema.types).filter(s=>s.scope==="session").map(s=>s.typeName)),presence:new Set(gt(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:l}of this.listeners)if(!(l.source!=="all"&&l.source!==r))if(l.scope!=="all")if(l.scope==="document"){if(s??(s=this.filterChangesByScope(t,"document")),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(o??(o=this.filterChangesByScope(t,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(t,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:t,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(n,t){const r={added:_c(n.added,(o,s)=>this.scopedTypes[t].has(s.typeName)),updated:_c(n.updated,(o,s)=>this.scopedTypes[t].has(s[1].typeName)),removed:_c(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 js(n),Ox(t)}finally{r()}}applyDiff(n,{runCallbacks:t=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const o=gt(n.added);for(const[i,a]of gt(n.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){o.push(a);continue}let u=null;for(const[h,p]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(p,jn(c,h))||(u||(u={...c}),u[h]=p);u&&o.push(u)}else o.push(a)}const s=E1(n.removed);o.length&&this.put(o),s.length&&this.remove(s)},t)}ensureStoreIsUsable(){this.atomic(()=>{var n;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(n=this._integrityChecker)==null||n.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(n,t){if(st(this.pendingAfterEvents,"must be in event operation"),n===t||(n&&t&&st(n.id===t.id),!n&&!t))return;const r=(n||t).id,o=this.pendingAfterEvents.get(r);o?o.after=t:this.pendingAfterEvents.set(r,{before:n,after:t})}flushAtomicCallbacks(){let n=0;const t=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(n++,n>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:o,after:s}of r.values())o&&s?this.sideEffects.handleAfterChange(o,s,t):o&&!s?this.sideEffects.handleAfterDelete(o,t):!o&&s&&this.sideEffects.handleAfterCreate(s,t);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(t)}}}atomic(n,t=!0){return js(()=>{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 b8(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:Ox(o.map(s=>s.changes))}))}class P8{constructor(){g(this,"_history",[]);g(this,"_interceptors",new Set)}addInterceptor(n){return this._interceptors.add(n),()=>{this._interceptors.delete(n)}}add(n){this._history.push(n);for(const t of this._interceptors)t(n)}flush(){const n=b8(this._history);return this._history=[],n}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function C8(e,n,t){const r=new Yo;return{get(o,s){return r.get(o,()=>(o instanceof $x?o:o.store).createComputedCache(e,l=>n(o,l),t)).get(s)}}}function I8(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 Ya({sequence:e,sequenceId:n,retroactive:t=!0}){const r={sequenceId:n,retroactive:t,sequence:I8(e)};return Wk(r),r}function Un(e,n){return Object.fromEntries(Ln(n).map(([t,r])=>[t,`${e}/${r}`]))}function lr(e){const n=e.sequenceId;return Ya({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 E8(e){const n=new Map(e.map(s=>[s.id,s])),t=new Set,r=[];function o(s){st(!t.has(s.id),`Circular dependency in migrations: ${s.id}`),t.add(s.id);const{version:i,sequenceId:a}=Ep(s.id),l=n.get(`${a}/${i-1}`);if(l&&o(l),s.dependsOn)for(const c of s.dependsOn){const u=n.get(c);u&&o(u)}n.delete(s.id),r.push(s)}for(const s of n.values())o(s);return r}function Ep(e){const[n,t]=e.split("/");return{sequenceId:n,version:parseInt(t)}}function L1(e,n){n&&st(e.startsWith(n+"/"),`Every migration in sequence '${n}' must have an id starting with '${n}/'. Got invalid id: '${e}'`),st(e.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${e}'`)}function Wk(e){if(st(!e.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${e.sequenceId}`),st(e.sequenceId.length,"sequenceId must be a non-empty string"),e.sequence.length===0)return;L1(e.sequence[0].id,e.sequenceId);let n=Ep(e.sequence[0].id).version;st(n===1,`Expected the first migrationId to be '${e.sequenceId}/1' but got '${e.sequence[0].id}'`);for(let t=1;t<e.sequence.length;t++){const r=e.sequence[t].id;L1(r,e.sequenceId);const o=Ep(r).version;st(o===n+1,`Migration id numbers must increase in increments of 1, expected ${e.sequenceId}/${n+1} but got '${e.sequence[t].id}'`),n=o}}var 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 k8(e){if(e.schemaVersion>2||e.schemaVersion<1)return gn.err("Bad schema version");if(e.schemaVersion===2)return gn.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 gn.ok(n)}class Fx{constructor(n,t){g(this,"migrations",{});g(this,"sortedMigrations");var o;this.types=n,this.options=t;for(const s of t.migrations??[])st(!this.migrations[s.sequenceId],`Duplicate migration sequenceId ${s.sequenceId}`),Wk(s),this.migrations[s.sequenceId]=s;const r=Object.values(this.migrations).flatMap(s=>s.sequence);this.sortedMigrations=E8(r);for(const s of this.sortedMigrations)if((o=s.dependsOn)!=null&&o.length)for(const i of s.dependsOn){const a=r.find(l=>l.id===i);st(a,`Migration '${s.id}' depends on missing migration '${i}'`)}}static create(n,t){return new Fx(n,t??{})}validateRecord(n,t,r,o){try{const s=jn(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=k8(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 gn.ok([]);const s=new Set;for(const i of o){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)s.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return gn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))s.add(u.id)}return gn.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=rt(n);try{for(const i of s){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(n):!0))continue;const l=i[r](n);l&&(n=rt(l))}}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=rt(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 c=s.up(a);c&&(t[i]=rt(c))}else if(s.scope==="store"){const i=s.up(t);i&&(t=rt(i))}else an(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?Ep(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=jn(this.types,n);return st(t,"record type does not exists"),t}}function _8(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 Pe extends Error{constructor(t,r=[]){const o=_8(r),s=t.split(`
|
|
47
|
-
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
48
|
-
`);super(r?`At ${o}: ${s}`:s);g(this,"name","ValidationError");this.rawMessage=t,this.path=r}}function $n(e,n){try{return n()}catch(t){throw t instanceof Pe?new Pe(t.rawMessage,[e,...t.path]):new Pe(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:an(n)}}class wn{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 D8(this)}optional(){return Vk(this)}refine(n){return new wn(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=>($n(`(check ${n})`,()=>t(r)),r)):this.refine(r=>(n(r),r))}}class T8 extends wn{constructor(n){super(t=>{const r=$1.validate(t);for(let o=0;o<r.length;o++)$n(o,()=>n.validate(r[o]));return r},(t,r)=>{if(!n.validateUsingKnownGoodVersion)return this.validate(r);const o=$1.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,$n(i,()=>n.validate(a));continue}if(Object.is(t[i],a))continue;const l=$n(i,()=>n.validateUsingKnownGoodVersion(t[i],a));Object.is(l,t[i])||(s=!0)}return s?r:t}),this.itemValidator=n}nonEmpty(){return this.check(n=>{if(n.length===0)throw new Pe("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(n=>{if(n.length<=1)throw new Pe("Expected an array with length greater than 1")})}}class kp extends wn{constructor(n,t=!1){super(r=>{if(typeof r!="object"||r===null)throw new Pe(`Expected object, got ${Ws(r)}`);for(const[o,s]of Object.entries(n))$n(o,()=>{s.validate(jn(r,o))});if(!t){for(const o of Object.keys(r))if(!po(n,o))throw new Pe("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Pe(`Expected object, got ${Ws(o)}`);let s=!1;for(const[i,a]of Object.entries(n)){const l=jn(r,i),c=jn(o,i);if(Object.is(l,c))continue;const u=$n(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(s=!0)}if(!t){for(const i of Object.keys(o))if(!po(n,i))throw new Pe("Unexpected property",[i])}for(const i of Object.keys(r))if(!po(o,i)){s=!0;break}return s?o:r}),this.config=n,this.shouldAllowUnknownProperties=t}allowUnknownProperties(){return new kp(this.config,!0)}extend(n){return new kp({...this.config,...n})}}class Ff extends wn{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):$n(`(${n} = ${a})`,()=>i.validate(s))},(s,i)=>{this.expectObject(i),this.expectObject(s);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):jn(s,n)!==jn(i,n)?$n(`(${n} = ${l})`,()=>a.validate(i)):$n(`(${n} = ${l})`,()=>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 Pe(`Expected an object, got ${Ws(n)}`,[])}getMatchingSchemaAndVariant(n){const t=jn(n,this.key);if(!this.useNumberKeys&&typeof t!="string")throw new Pe(`Expected a string for key "${this.key}", got ${Ws(t)}`);if(this.useNumberKeys&&!Number.isFinite(Number(t)))throw new Pe(`Expected a number for key "${this.key}", got "${t}"`);return{matchingSchema:po(this.config,t)?this.config[t]:void 0,variant:t}}validateUnknownVariants(n){return new Ff(this.key,this.config,n,this.useNumberKeys)}}class M8 extends wn{constructor(n,t){super(r=>{if(typeof r!="object"||r===null)throw new Pe(`Expected object, got ${Ws(r)}`);for(const[o,s]of Object.entries(r))$n(o,()=>{n.validate(o),t.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Pe(`Expected object, got ${Ws(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!po(r,i)){s=!0,$n(i,()=>{n.validate(i),t.validate(a)});continue}const l=jn(r,i),c=a;if(Object.is(l,c))continue;const u=$n(i,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(l,c):t.validate(c));Object.is(u,l)||(s=!0)}for(const i of Object.keys(r))if(!po(o,i)){s=!0;break}return s?o:r}),this.keyValidator=n,this.valueValidator=t}}function Nx(e){return new wn(n=>{if(typeof n!==e)throw new Pe(`Expected ${e}, got ${Ws(n)}`);return n})}const A8=new wn(e=>e),pe=Nx("string"),de=Nx("number").check(e=>{if(Number.isNaN(e))throw new Pe("Expected a number, got NaN");if(!Number.isFinite(e))throw new Pe(`Expected a finite number, got ${e}`)}),_p=de.check(e=>{if(e<0)throw new Pe(`Expected a positive number, got ${e}`)}),Ct=de.check(e=>{if(e<=0)throw new Pe(`Expected a non-zero positive number, got ${e}`)}),Gk=de.check(e=>{if(!Number.isInteger(e))throw new Pe(`Expected an integer, got ${e}`)}),Sh=Gk.check(e=>{if(e<0)throw new Pe(`Expected a positive integer, got ${e}`)}),j8=Gk.check(e=>{if(e<=0)throw new Pe(`Expected a non-zero positive integer, got ${e}`)}),we=Nx("boolean");function ln(e){return new wn(n=>{if(n!==e)throw new Pe(`Expected ${e}, got ${JSON.stringify(n)}`);return e})}const $1=new wn(e=>{if(!Array.isArray(e))throw new Pe(`Expected an array, got ${Ws(e)}`);return e});function zt(e){return new T8(e)}function Se(e){return new kp(e)}function mS(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===X4)}function yS(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(yS):mS(e)?Object.values(e).every(yS):!1}const Bt=new wn(e=>{if(yS(e))return e;throw new Pe(`Expected json serializable value, got ${typeof e}`)},(e,n)=>{if(Array.isArray(e)&&Array.isArray(n)){let t=e.length!==n.length;for(let r=0;r<n.length;r++){if(r>=e.length){t=!0,Bt.validate(n[r]);continue}const o=e[r],s=n[r];if(Object.is(o,s))continue;const i=Bt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(t=!0)}return t?n:e}else if(mS(e)&&mS(n)){let t=!1;for(const r of Object.keys(n)){if(!po(e,r)){t=!0,Bt.validate(n[r]);continue}const o=e[r],s=n[r];if(Object.is(o,s))continue;const i=Bt.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(t=!0)}for(const r of Object.keys(e))if(!po(n,r)){t=!0;break}return t?n:e}else return Bt.validate(n)});function Tp(e,n){return new M8(e,n)}function zx(e,n){return new Ff(e,n,(t,r)=>{throw new Pe(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!1)}function O8(e,n){return new Ff(e,n,(t,r)=>{throw new Pe(`Expected one of ${Object.keys(n).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])},!0)}function Eo(e,n){return new wn(t=>$n(e,()=>n.validate(t)),(t,r)=>$n(e,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(t,r):n.validate(r)))}function Nf(e){return new wn(n=>{if(!e.has(n)){const t=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Pe(`Expected ${t}, got ${n}`)}return n})}function Vk(e){return new wn(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 D8(e){return new wn(n=>n===null?null:e.validate(n),(n,t)=>t===null?null:e.validateUsingKnownGoodVersion&&n!==null?e.validateUsingKnownGoodVersion(n,t):e.validate(t))}function zf(...e){return Nf(new Set(e))}function Yk(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Pe(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Pe(`Expected a valid url, got ${JSON.stringify(e)}`)}}const R8=new Set(["http:","https:","mailto:"]),or=pe.check(e=>{if(e==="")return;const n=Yk(e);if(!R8.has(n.protocol.toLowerCase()))throw new Pe(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),L8=new Set(["http:","https:","data:","asset:"]),$i=pe.check(e=>{if(e==="")return;const n=Yk(e);if(!L8.has(n.protocol.toLowerCase()))throw new Pe(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),Bx=pe.refine(e=>{try{return F4(e),e}catch{throw new Pe(`Expected an index key, got ${JSON.stringify(e)}`)}});function er(e){return pe.refine(n=>{if(!n.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return n})}const Bf=er("asset");function Ux(e,n){return Se({id:Bf,typeName:ln("asset"),type:ln(e),props:n,meta:Bt})}const Fi=Se({x:de,y:de,z:de.optional()}),Mc=Se({x:de,y:de,w:de,h:de}),Xk=de.check(e=>{if(e<0||e>1)throw new Pe("Opacity must be between 0 and 1")}),$8=pe.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),mr=er("shape");function F8(e,n,t){return Se({id:mr,typeName:ln("shape"),x:de,y:de,rotation:de,index:Bx,parentId:$8,type:ln(e),isLocked:we,opacity:Xk,props:n?Se(n):Bt,meta:t?Se(t):Bt})}const N8=er("binding");function z8(e,n,t){return Se({id:N8,typeName:ln("binding"),type:ln(e),fromId:mr,toId:mr,props:n?Se(n):Bt,meta:t?Se(t):Bt})}Un("com.tldraw.binding",{});lr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Oi(e){return`binding:${Au()}`}function B8(e){return Io("binding",{scope:"document",validator:Eo("binding",zx("type",Mu(e,(n,{props:t,meta:r})=>z8(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=A8}=t;return new Yt(n,r,o)}static defineEnum(n,t){const{defaultValue:r,values:o}=t;return new U8(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 U8 extends Yt{constructor(n,t,r){super(n,t,zf(...r)),this.values=r}}const gd=Un("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),H8=lr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:gd.AddIsLocked,up:e=>{e.isLocked=!1},down:e=>{delete e.isLocked}},{id:gd.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:gd.AddMeta,up:e=>{e.meta={}}},{id:gd.AddWhite,up:e=>{},down:e=>{e.props.color==="white"&&(e.props.color="black")}}]});function Ma(e){return e?e.typeName==="shape":!1}function _n(e){return e?e.startsWith("shape:"):!1}function $e(e){return`shape:${e??Au()}`}function qk(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 Vr(e,n){return Mu(n,(t,r)=>`com.tldraw.shape.${e}/${r}`)}function K8(e){return Io("shape",{scope:"document",validator:Eo("shape",zx("type",Mu(e,(n,{props:t,meta:r})=>F8(n,t,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function F1(e,n){const t=[];for(const[r,{migrations:o}]of Object.entries(n)){const s=`com.tldraw.${e}.${r}`;o?"sequenceId"in o?(st(s===o.sequenceId,`sequenceId mismatch for ${r} ${Lf} migrations. Expected '${s}', got '${o.sequenceId}'`),t.push(o)):"sequence"in o?t.push(Ya({sequenceId:s,retroactive:!1,sequence:o.sequence.map(i=>"id"in i?Zk(e,r,i):i)})):t.push(Ya({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 l=o.migrators[i].up(a);if(l)return l},down:a=>{const l=o.migrators[i].down(a);if(l)return l}}))})):t.push(Ya({sequenceId:s,retroactive:!1,sequence:[]}))}return t}function Zk(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 Qk=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],Mp={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?Mp.darkMode:Mp.lightMode}const sr=Yt.defineEnum("tldraw:color",{defaultValue:"black",values:Qk}),Jk=Yt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:Qk}),Ni=Yt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),zi=Yt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),vo=Yt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),e_={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},xo=Yt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),t_=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Ap=Yt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:t_}),jp=Yt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:t_}),n_={labelColor:Jk,color:sr,fill:zi,dash:Ni,size:xo,arrowheadStart:Ap,arrowheadEnd:jp,font:vo,start:Fi,end:Fi,bend:de,text:pe,labelPosition:de,scale:Ct},Pa=Vr("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function md(e){return Zk("shape","arrow",e)}const r_=Ya({sequenceId:"com.tldraw.shape.arrow",sequence:[md({id:Pa.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"}),md({id:Pa.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)}}),md({id:Pa.AddLabelPosition,up:e=>{e.labelPosition=.5},down:e=>{delete e.labelPosition}}),{id:Pa.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=Oi(),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=Oi(),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}}},md({id:Pa.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}})]}),o_={terminal:zf("start","end"),normalizedAnchor:Fi,isExact:we,isPrecise:we},s_={sequence:[{dependsOn:[Pa.ExtractBindings]}]},W8=Eo("camera",Se({typeName:ln("camera"),id:er("camera"),x:de,y:de,z:de,meta:Bt})),G8=Un("com.tldraw.camera",{AddMeta:1}),V8=lr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:G8.AddMeta,up:e=>{e.meta={}}}]}),co=Io("camera",{validator:W8,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),Y8=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"]),i_=Nf(Y8),X8=Se({type:i_,rotation:de}),q8=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),Z8=Nf(q8),Q8=new Set(["starting","paused","active","stopping"]),a_=Se({id:pe,points:zt(Fi),size:_p,color:Z8,opacity:de,state:Nf(Q8),delay:de,shrink:de,taper:we}),Yc=er("page"),J8=Eo("page",Se({typeName:ln("page"),id:Yc,name:pe,index:Bx,meta:Bt})),e6=Un("com.tldraw.page",{AddMeta:1}),t6=lr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:e6.AddMeta,up:e=>{e.meta={}}}]}),Xo=Io("page",{validator:J8,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function En(e){return Xo.isId(e)}const n6={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},l_=e=>e?_c(e,n=>n6[n]):null;er("instance");function r6(e){const n={};for(const[r,o]of e)n[r]=Vk(o);const t=Eo("instance",Se({typeName:ln("instance"),id:er("instance"),currentPageId:Yc,followingUserId:pe.nullable(),brush:Mc.nullable(),opacityForNextShape:Xk,stylesForNextShape:Se(n),cursor:X8,scribbles:zt(a_),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:Mc,insets:zt(we),zoomBrush:Mc.nullable(),isPenMode:we,isGridMode:we,chatMessage:pe,isChatting:we,highlightedUserIds:zt(pe),isFocused:we,devicePixelRatio:de,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:zt(pe),isChangingStyle:we,isReadonly:we,meta:Bt,duplicateProps:Se({shapeIds:zt(er("shape")),offset:Se({x:de,y:de})}).nullable()}));return Io("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=Un("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}),o6=lr({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})}]}),mn="instance:instance",s6=Eo("instance_page_state",Se({typeName:ln("instance_page_state"),id:er("instance_page_state"),pageId:Yc,selectedShapeIds:zt(mr),hintingShapeIds:zt(mr),erasingShapeIds:zt(mr),hoveredShapeId:mr.nullable(),editingShapeId:mr.nullable(),croppingShapeId:mr.nullable(),focusedGroupId:mr.nullable(),meta:Bt})),ql=Un("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),i6=lr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:ql.AddCroppingId,up(e){e.croppingShapeId=null}},{id:ql.RemoveInstanceIdAndCameraId,up(e){delete e.instanceId,delete e.cameraId}},{id:ql.AddMeta,up:e=>{e.meta={}}},{id:ql.RenameProperties,up:e=>{},down:e=>{}},{id:ql.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}}]}),Fr=Io("instance_page_state",{validator:s6,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:{}})),a6=Eo("pointer",Se({typeName:ln("pointer"),id:er("pointer"),x:de,y:de,lastActivityTimestamp:de,meta:Bt})),l6=Un("com.tldraw.pointer",{AddMeta:1}),c6=lr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:l6.AddMeta,up:e=>{e.meta={}}}]}),Hx=Io("pointer",{validator:a6,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Op=Hx.createId("pointer"),u6=Eo("instance_presence",Se({typeName:ln("instance_presence"),id:er("instance_presence"),userId:pe,userName:pe,lastActivityTimestamp:de,followingUserId:pe.nullable(),cursor:Se({x:de,y:de,type:i_,rotation:de}),color:pe,camera:Se({x:de,y:de,z:de}),screenBounds:Mc,selectedShapeIds:zt(er("shape")),currentPageId:er("page"),brush:Mc.nullable(),scribbles:zt(a_),chatMessage:pe,meta:Bt})),Zl=Un("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5}),d6=lr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Zl.AddScribbleDelay,up:e=>{e.scribble!==null&&(e.scribble.delay=0)}},{id:Zl.RemoveInstanceId,up:e=>{delete e.instanceId}},{id:Zl.AddChatMessage,up:e=>{e.chatMessage=""}},{id:Zl.AddMeta,up:e=>{e.meta={}}},{id:Zl.RenameSelectedShapeIds,up:e=>{}}]}),h6=Io("instance_presence",{validator:u6,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:{}})),p6=Eo("document",Se({typeName:ln("document"),id:ln("document:document"),gridSize:de,name:pe,meta:Bt})),N1=Un("com.tldraw.document",{AddName:1,AddMeta:2}),f6=lr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:N1.AddName,up:e=>{e.name=""},down:e=>{delete e.name}},{id:N1.AddMeta,up:e=>{e.meta={}}}]}),Kx=Io("document",{validator:p6,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),SS=Kx.createId("document");function g6(e,n){return e.index<n.index?-1:e.index>n.index?1:0}function z1(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const m6=({error:e,phase:n,record:t,recordBefore:r})=>{throw _x(e,{tags:{origin:"store.validateRecord",storePhase:n,isExistingValidationIssue:n==="initialize"},extras:{recordBefore:r?z1(rt(r)):void 0,recordAfter:z1(rt(t))}}),e};function y6(){return[Xo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function S6(e){const n=e.query.ids("page"),t=()=>{if(!e.has(SS))return e.put([Kx.create({id:SS,name:e.props.defaultName})]),t();if(!e.has(Op))return e.put([Hx.create({id:Op})]),t();const r=n.get();if(r.size===0)return e.put(y6()),t();const o=()=>[...r].map(l=>e.get(l)).sort(g6)[0].id,s=e.get(mn);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),t()}else return e.put([e.schema.types.instance.create({id:mn,currentPageId:o(),exportBackground:!0})]),t();const i=new Set,a=new Set;for(const l of r){const c=Fr.createId(l);e.has(c)||i.add(c);const u=co.createId(l);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(l=>Fr.create({id:l,pageId:Fr.parseId(l)}))),a.size>0&&e.put([...a].map(l=>co.create({id:l})))};return t}const v6=Ux("bookmark",Se({title:pe,description:pe,image:pe,favicon:pe,src:$i.nullable()})),B1=Un("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),x6=lr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:e=>e.type==="bookmark",sequence:[{id:B1.MakeUrlsValid,up:e=>{$i.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:B1.AddFavicon,up:e=>{$i.isValid(e.props.favicon)||(e.props.favicon="")},down:e=>{delete e.props.favicon}}]}),w6=Ux("image",Se({w:de,h:de,fileSize:de,name:pe,isAnimated:we,mimeType:pe.nullable(),src:$i.nullable()})),yd=Un("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),b6=lr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:e=>e.type==="image",sequence:[{id:yd.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:yd.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:yd.MakeUrlsValid,up:e=>{$i.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:yd.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),P6=Ux("video",Se({w:de,h:de,fileSize:de,name:pe,isAnimated:we,mimeType:pe.nullable(),src:$i.nullable()})),Sd=Un("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4}),C6=lr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:e=>e.type==="video",sequence:[{id:Sd.AddIsAnimated,up:e=>{e.props.isAnimated=!1},down:e=>{delete e.props.isAnimated}},{id:Sd.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:Sd.MakeUrlsValid,up:e=>{$i.isValid(e.props.src)||(e.props.src="")},down:e=>{}},{id:Sd.AddFileSize,up:e=>{e.props.fileSize=-1},down:e=>{delete e.props.fileSize}}]}),I6=Eo("asset",zx("type",{image:w6,video:P6,bookmark:v6})),E6=Un("com.tldraw.asset",{AddMeta:1}),k6=lr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:E6.AddMeta,up:e=>{e.meta={}}}]}),Ci=Io("asset",{validator:I6,scope:"document"}).withDefaultProperties(()=>({meta:{}})),c_={w:Ct,h:Ct,assetId:Bf.nullable(),url:or},U1=Vr("bookmark",{NullAssetId:1,MakeUrlsValid:2}),u_={sequence:[{id:U1.NullAssetId,up:e=>{e.assetId===void 0&&(e.assetId=null)},down:"retired"},{id:U1.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}}]},d_=Se({type:zf("free","straight"),points:zt(Fi)}),h_={color:sr,fill:zi,dash:Ni,size:xo,segments:zt(d_),isComplete:we,isClosed:we,isPen:we,scale:Ct},H1=Vr("draw",{AddInPen:1,AddScale:2}),p_={sequence:[{id:H1.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:H1.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]};var _6={};const K1=/(^\/r\/[^/]+\/?$)/,Oe=e=>{try{return new URL(e)}catch{return}},ju=[{type:"tldraw",title:"tldraw",hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,overridePermissions:{"allow-top-navigation":!0},toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(K1))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(K1))return e}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!e.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${e}`},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/?$/)){const t=n.searchParams.get("url");if(t)return t}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:e=>{if(e.includes("/maps/")){const n=e.match(/@(.*),(.*),(.*)z/);let t;if(n){const[,r,o,s]=n;t=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${_6.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${o}&zoom=${s}`}else t="";return t}},fromEmbedUrl:e=>{const n=Oe(e);if(!n)return;if(n.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&n.searchParams.has("center")&&n.searchParams.get("zoom")){const r=n.searchParams.get("zoom"),[o,s]=n.searchParams.get("center").split(",");return`https://www.google.com/maps/@${o},${s},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/v\/(.+)\/?/);if(t)return`https://www.val.town/embed/${t[1]}`},fromEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/embed\/(.+)\/?/);if(t)return`https://www.val.town/v/${t[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/s\/([^/]+)\/?/);if(t)return`https://codesandbox.io/embed/${t[1]}`},fromEmbedUrl:e=>{const n=Oe(e),t=n&&n.pathname.match(/\/embed\/([^/]+)\/?/);if(t)return`https://codesandbox.io/s/${t[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:e=>{const n=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o,s]=t;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:e=>{const n=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,t=e.match(n);if(t){const[r,o]=t;return`https://scratch.mit.edu/projects/embed/${o}`}},fromEmbedUrl:e=>{const n=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,t=e.match(n);if(t){const[r,o]=t;return`https://scratch.mit.edu/projects/${o}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Oe(e);if(!n)return;const t=n.hostname.replace(/^www./,"");if(t==="youtu.be")return`https://www.youtube.com/embed/${n.pathname.split("/").filter(Boolean)[0]}`;if((t==="youtube.com"||t==="m.youtube.com")&&n.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${n.searchParams.get("v")}`},fromEmbedUrl:e=>{const n=Oe(e);if(!n)return;if(n.hostname.replace(/^www./,"")==="youtube.com"){const r=n.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:e=>{const n=Oe(e),t=n==null?void 0:n.searchParams.get("cid");if(n!=null&&n.pathname.match(/\/calendar\/u\/0/)&&t){n.pathname="/calendar/embed";const r=Array.from(n.searchParams.keys());for(const o of r)n.searchParams.delete(o);return n.searchParams.set("src",t),n.href}},fromEmbedUrl:e=>{const n=Oe(e),t=n==null?void 0:n.searchParams.get("src");if(n!=null&&n.pathname.match(/\/calendar\/embed/)&&t){n.pathname="/calendar/u/0";const r=Array.from(n.searchParams.keys());for(const o of r)n.searchParams.delete(o);return n.searchParams.set("cid",t),n.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:e=>{const n=Oe(e);if(n!=null&&n.pathname.match(/^\/presentation/)&&(n!=null&&n.pathname.match(/\/pub\/?$/))){n.pathname=n.pathname.replace(/\/pub$/,"/embed");const t=Array.from(n.searchParams.keys());for(const r of t)n.searchParams.delete(r);return n.href}},fromEmbedUrl:e=>{const n=Oe(e);if(n!=null&&n.pathname.match(/^\/presentation/)&&(n!=null&&n.pathname.match(/\/embed\/?$/))){n.pathname=n.pathname.replace(/\/embed$/,"/pub");const t=Array.from(n.searchParams.keys());for(const r of t)n.searchParams.delete(r);return n.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/\/@([^/]+)\/([^/]+)/)&&n.searchParams.has("embed"))return n.searchParams.delete("embed"),n.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/map\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/map\//))return n.pathname=n.pathname.replace(/^\/embed/,""),n.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/(artist|album)\//))return n.origin+"/embed"+n.pathname},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/(artist|album)\//))return n.origin+n.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="vimeo.com"&&n.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+n.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="player.vimeo.com"){const t=n.pathname.match(/^\/video\/([^/]+)\/?$/);if(t)return"https://vimeo.com/"+t[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.hash.match(/#room=/))return e}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${n.origin}/embed${n.pathname}?cell=*`;if(n&&n.pathname.match(/^\/d\/([^/]+)\/?$/)){const t=n.pathname.replace(/^\/d/,"");return`${n.origin}/embed${t}?cell=*`}},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${n.origin}${n.pathname.replace("/embed","")}#cell-*`;if(n&&n.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${n.origin}${n.pathname.replace("/embed","/d")}#cell-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="www.desmos.com"&&n.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&n.search===""&&n.hash==="")return`${e}?embed`},fromEmbedUrl:e=>{const n=Oe(e);if(n&&n.hostname==="www.desmos.com"&&n.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&n.search==="?embed"&&n.hash==="")return e.replace("?embed","")}}],T6={"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},f_={w:Ct,h:Ct,url:pe},vd=Vr("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),g_={sequence:[{id:vd.GenOriginalUrlInEmbed,up:e=>{try{const n=e.url,t=new URL(n).host.replace("www.","");let r;for(const o of ju)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:vd.RemoveDoesResize,up:e=>{delete e.doesResize},down:"retired"},{id:vd.RemoveTmpOldUrl,up:e=>{delete e.tmpOldUrl},down:"retired"},{id:vd.RemovePermissionOverrides,up:e=>{delete e.overridePermissions},down:"retired"}]},m_={w:Ct,h:Ct,name:pe},y_={sequence:[]},Dp=Yt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Rp=Yt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Nr=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"]}),S_={geo:Nr,labelColor:Jk,color:sr,fill:zi,dash:Ni,size:xo,font:vo,align:Dp,verticalAlign:Rp,url:or,w:Ct,h:Ct,growY:_p,text:pe,scale:Ct},Ao=Vr("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),v_={sequence:[{id:Ao.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:Ao.AddLabelColor,up:e=>{e.labelColor="black"},down:"retired"},{id:Ao.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:Ao.AddCheckBox,up:e=>{},down:"retired"},{id:Ao.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:Ao.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:Ao.AddCloud,up:e=>{},down:"retired"},{id:Ao.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}},{id:Ao.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},x_={},w_={sequence:[]},b_={color:sr,size:xo,segments:zt(d_),isComplete:we,isPen:we,scale:Ct},M6=Vr("highlight",{AddScale:1}),P_={sequence:[{id:M6.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},A6=Se({topLeft:Fi,bottomRight:Fi}),C_={w:Ct,h:Ct,playing:we,url:or,assetId:Bf.nullable(),crop:A6.nullable()},ym=Vr("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3}),I_={sequence:[{id:ym.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:ym.AddCropProp,up:e=>{e.crop=null},down:e=>{delete e.crop}},{id:ym.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}}]},Lp=Yt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),j6=Se({id:pe,index:Bx,x:de,y:de}),E_={color:sr,dash:Ni,size:xo,spline:Lp,points:Tp(pe,j6),scale:Ct},Ql=Vr("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),k_={sequence:[{id:Ql.AddSnapHandles,up:e=>{for(const n of Object.values(e.handles))n.canSnap=!0},down:"retired"},{id:Ql.RemoveExtraHandleProps,up:e=>{e.handles=Ik(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(on);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:Ql.HandlesToPoints,up:e=>{const n=Object.entries(e.handles).map(([t,{x:r,y:o}])=>({x:r,y:o,index:t})).sort(on);e.points=n.map(({x:t,y:r})=>({x:t,y:r})),delete e.handles},down:e=>{const n=Vc(e.points.length);e.handles=Object.fromEntries(e.points.map((t,r)=>[n[r],{x:t.x,y:t.y}])),delete e.points}},{id:Ql.PointIndexIds,up:e=>{const n=Vc(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(on);e.points=n.map(({x:t,y:r})=>({x:t,y:r}))}},{id:Ql.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},__={color:sr,size:xo,font:vo,fontSizeAdjustment:_p,align:Dp,verticalAlign:Rp,growY:_p,url:or,text:pe,scale:Ct},xi=Vr("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7}),T_={sequence:[{id:xi.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:xi.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:xi.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:xi.AddVerticalAlign,up:e=>{e.verticalAlign="middle"},down:"retired"},{id:xi.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}},{id:xi.AddFontSizeAdjustment,up:e=>{e.fontSizeAdjustment=0},down:e=>{delete e.fontSizeAdjustment}},{id:xi.AddScale,up:e=>{e.scale=1},down:e=>{delete e.scale}}]},vS=Yt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),M_={color:sr,size:xo,font:vo,textAlign:vS,w:Ct,text:pe,scale:Ct,autoSize:we},W1=Vr("text",{RemoveJustify:1,AddTextAlign:2}),A_={sequence:[{id:W1.RemoveJustify,up:e=>{e.align==="justify"&&(e.align="start")},down:"retired"},{id:W1.AddTextAlign,up:e=>{e.textAlign=e.align,delete e.align},down:e=>{e.align=e.textAlign,delete e.textAlign}}]},j_={w:Ct,h:Ct,time:de,playing:we,url:or,assetId:Bf.nullable()},G1=Vr("video",{AddUrlProp:1,MakeUrlsValid:2}),O_={sequence:[{id:G1.AddUrlProp,up:e=>{e.url=""},down:"retired"},{id:G1.MakeUrlsValid,up:e=>{or.isValid(e.url)||(e.url="")},down:e=>{}}]},xd=Un("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),O6=Ya({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:xd.RemoveCodeAndIconShapeTypes,scope:"store",up:e=>{for(const[n,t]of Ln(e))t.typeName==="shape"&&(t.type==="icon"||t.type==="code")&&delete e[n]}},{id:xd.AddInstancePresenceType,scope:"store",up(e){}},{id:xd.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:e=>{for(const[n,t]of Ln(e))t.typeName.match(/^(user|user_presence)$/)&&delete e[n]}},{id:xd.RemoveUserDocument,scope:"store",up:e=>{for(const[n,t]of Ln(e))t.typeName.match("user_document")&&delete e[n]}}]}),D6={arrow:{migrations:r_,props:n_},bookmark:{migrations:u_,props:c_},draw:{migrations:p_,props:h_},embed:{migrations:g_,props:f_},frame:{migrations:y_,props:m_},geo:{migrations:v_,props:S_},group:{migrations:w_,props:x_},highlight:{migrations:P_,props:b_},image:{migrations:I_,props:C_},line:{migrations:k_,props:E_},note:{migrations:T_,props:__},text:{migrations:A_,props:M_},video:{migrations:O_,props:j_}},R6={arrow:{migrations:s_,props:o_}};function L6({shapes:e=D6,bindings:n=R6,migrations:t}={}){const r=new Map;for(const a of gt(e))for(const l of qk(a.props??{}).keys()){if(r.has(l.id)&&r.get(l.id)!==l)throw new Error(`Multiple StyleProp instances with the same id: ${l.id}`);r.set(l.id,l)}const o=K8(e),s=B8(n),i=r6(r);return Fx.create({asset:Ci,binding:s,camera:co,document:Kx,instance:i,instance_page_state:Fr,page:Xo,instance_presence:h6,pointer:Hx,shape:o},{migrations:[O6,k6,V8,f6,o6,i6,t6,d6,c6,H8,x6,b6,C6,...F1("shape",e),...F1("binding",n),...t??[]],onValidationFailure:m6,createIntegrityChecker:S6})}const Xc=[{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 $6(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return F6(e)}function F6(e){for(const n of e){const t=N6(n);if(t)return t}return"en"}const V1={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function N6(e){const n=Xc.find(o=>o.locale===e.toLowerCase());if(n)return n.locale;const[t,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Xc.find(s=>s.locale===t);if(o)return o.locale}return t in V1?V1[t]:null}var D_={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})()})(D_);var z6=D_.exports;const ce=ei(z6),B6={error:null};class R_ extends P.Component{constructor(){super(...arguments);g(this,"state",B6)}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 d.jsx(r,{error:t})}return this.props.children}}function qc({children:e,fallback:n,...t}){return n===null?d.jsx(d.Fragment,{children:e}):d.jsx(R_,{fallback:n,...t,children:e})}const Uf=xe.createContext(null);function B(){const e=xe.useContext(Uf);if(!e)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return e}function U6(){return d.jsx("div",{className:"tl-background"})}function Ol(e,n,t,r,o,s){P.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 w{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 w(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=w.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 w.Dpr(this,n)}cpr(n){return w.Cpr(this,n)}len2(){return w.Len2(this)}len(){return w.Len(this)}pry(n){return w.Pry(this,n)}per(){const{x:n,y:t}=this;return this.x=t,this.y=-n,this}uni(){return w.Uni(this)}tan(n){return w.Tan(this,n)}dist(n){return w.Dist(this,n)}distanceToLineSegment(n,t){return w.DistanceToLineSegment(n,t,this)}slope(n){return w.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 w.Angle(this,n)}toAngle(){return w.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 w.Equals(this,n)}equalsXY(n,t){return w.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 w.ToFixed(this)}toString(){return w.ToString(w.ToFixed(this))}toJson(){return w.ToJson(this)}toArray(){return w.ToArray(this)}static Add(n,t){return new w(n.x+t.x,n.y+t.y)}static AddXY(n,t,r){return new w(n.x+t,n.y+r)}static Sub(n,t){return new w(n.x-t.x,n.y-t.y)}static SubXY(n,t,r){return new w(n.x-t,n.y-r)}static AddScalar(n,t){return new w(n.x+t,n.y+t)}static SubScalar(n,t){return new w(n.x-t,n.y-t)}static Div(n,t){return new w(n.x/t,n.y/t)}static Mul(n,t){return new w(n.x*t,n.y*t)}static DivV(n,t){return new w(n.x/t.x,n.y/t.y)}static MulV(n,t){return new w(n.x*t.x,n.y*t.y)}static Neg(n){return new w(-n.x,-n.y)}static Per(n){return new w(n.y,-n.x)}static Abs(n){return new w(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 w(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 w.Dpr(n,t)/w.Len(t)}static Uni(n){return w.Div(n,w.Len(n))}static Tan(n,t){return w.Uni(w.Sub(n,t))}static Min(n,t){return new w(Math.min(n.x,t.x),Math.min(n.y,t.y))}static Max(n,t){return new w(Math.max(n.x,t.x),Math.max(n.y,t.y))}static From({x:n,y:t,z:r=1}){return new w(n,t,r)}static FromArray(n){return new w(n[0],n[1])}static Rot(n,t=0){const r=Math.sin(t),o=Math.cos(t);return new w(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 w(t.x+(o*a-s*i),t.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(n,t,r){return w.Mul(t,w.Sub(r,n).pry(t)).add(n)}static NearestPointOnLineSegment(n,t,r,o=!0){if(w.Equals(n,r)||w.Equals(t,r))return w.From(r);const s=w.Tan(t,n),i=w.Add(n,w.Mul(s,w.Sub(r,n).pry(s)));if(o){if(i.x<Math.min(n.x,t.x))return w.Cast(n.x<t.x?n:t);if(i.x>Math.max(n.x,t.x))return w.Cast(n.x>t.x?n:t);if(i.y<Math.min(n.y,t.y))return w.Cast(n.y<t.y?n:t);if(i.y>Math.max(n.y,t.y))return w.Cast(n.y>t.y?n:t)}return i}static DistanceToLineThroughPoint(n,t,r){return w.Dist(r,w.NearestPointOnLineThroughPoint(n,t,r))}static DistanceToLineSegment(n,t,r,o=!0){return w.Dist(r,w.NearestPointOnLineSegment(n,t,r,o))}static Snap(n,t=1){return new w(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}static Cast(n){return n instanceof w?n:w.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 w.Sub(t,n).mul(r).add(n)}static Med(n,t){return new w((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=w.Len(n);return new w(t*n.x/r,t*n.y/r)}static ScaleWithOrigin(n,t,r){return w.Sub(n,r).mul(t).add(r)}static ToFixed(n){return new w(Fo(n.x),Fo(n.y))}static ToInt(n){return new w(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 w.Add(n,w.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 w(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 w(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 w(Math.min(Math.max(n.x,t)),Math.min(Math.max(n.y,t))):new w(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=w.Lrp(n,t,i);a.z=Math.min(1,.5+Math.abs(.5-H6(i))*.65),o.push(a)}return o}static SnapToGrid(n,t=8){return new w(Math.round(n.x/t)*t,Math.round(n.y/t)*t)}}const H6=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ie(e){return`${N(e.x)},${N(e.y)} `}function Tn(e,n){return`${N((e.x+n.x)/2)},${N((e.y+n.y)/2)} `}const ke=Math.PI,Ge=ke/2,Re=ke*2,K6=Math.sin;function _t(e,n,t){return Math.max(n,typeof t<"u"?Math.min(e,t):e)}function wd(e,n=1e10){return e?Math.round(e*n)/n:0}function Ds(e,n,t=1e-6){return Math.abs(e-n)<=t}function L_(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 Rs(e){return e=e%Re,e<0?e=e+Re:e===0&&(e=0),e}function Ou(e,n){return e=Rs(e),n=Rs(n),e>n&&(n+=Re),n-e}function $_(e,n){return Re-Ou(e,n)}function vh(e,n){const t=(n-e)%Re;return 2*t%Re-t}function xS(e){return(Re+e)%Re}function $p(e,n){const t=Re/n;let r=Math.floor((xS(e)+t/2)/t)*t%Re;return r<ke&&(r+=Re),r>ke&&(r-=Re),r}function F_(e,n){return e===n||Ds(e%(Math.PI/2)-n%(Math.PI/2),0)}function W6(e){return e*ke/180}function G6(e){return e*180/ke}function Bi(e,n,t){return new w(e.x,e.y).add(w.FromAngle(t,n))}function Sm(e,n,t){const r=e/2,o=n/2,s=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let S=0;S<t;S++){const m=Re/t,x=-Ge+S*m,y=r+r*Math.cos(x),v=o+o*Math.sin(x);y<i&&(i=y),v<l&&(l=v),y>a&&(a=y),v>c&&(c=v),s.push(new w(y,v))}const u=a-i,h=c-l,p=e-u,f=n-h;if(p!==0||f!==0)for(let S=0;S<s.length;S++){const m=s[S];m.x=(m.x-i)/u*e,m.y=(m.y-l)/h*n}return s}function Jl(e,n,t,r){return e<r&&t<n}function Or(e,n,t,r){const o=Math.max(e,t),s=Math.min(n,r);return o<=s?[o,s]:null}function Y1(e,n,t){return(n.x-e.x)*(t.y-e.y)-(t.x-e.x)*(n.y-e.y)}function tr(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],w.Dist(e,r)+w.Dist(e,o)===w.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&Y1(r,o,e)>0&&(t+=1):o.y<=e.y&&Y1(r,o,e)<0&&(t-=1)}return t!==0}function N(e){return Math.round(e*1e4)/1e4}function Fo(e){return Math.round(e*100)/100}const X1=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function Cs(e,n,t){return t<0?Ou(e,n):$_(e,n)}function wS(e,n,t,r){let o;if(Math.abs(e)>ke){o=vh(n,r);const s=vh(r,t);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=vh(n,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function V6(e,n,t,r){const o=2*((n-e)%Re)%Re-(n-e)%Re;return r?(Re-Math.abs(o))*(t?1:-1):o}function Wx(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 w(((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 Y6(e,n,t,r,o){if(t===null)return[w.From(e),w.From(n)];const s=[],i=w.Angle(t,e),a=w.Angle(t,n),l=Ou(i,a);for(let c=0;c<o;c++){const u=c/(o-1),h=i+l*u,p=Bi(t,r,h);s.push(p)}return s}const vm=({brush:e,color:n,opacity:t,className:r})=>{const o=P.useRef(null);Ol(o,e.x,e.y);const s=N(Math.max(1,e.w)),i=N(Math.max(1,e.h));return d.jsx("svg",{className:"tl-overlays__item",ref:o,children:n?d.jsxs("g",{className:"tl-brush",opacity:t,children:[d.jsx("rect",{width:s,height:i,fill:n,opacity:.75}),d.jsx("rect",{width:s,height:i,fill:"none",stroke:n,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},q1={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Z1={onResolveAsset:async e=>(e==null?void 0:e.props.src)||""},xm={duration:0,easing:At.easeInOutCubic},Q1={CAMERA_MOVE:-10},X6=["top","right","bottom","left"],J1=0,Gx=2,bd=1,eP=5,q6=128;var wm={};const Z6={},N_=In("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),xt={logPreventDefaults:In("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:In("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:In("logElementRemoves",{defaults:{all:!1}}),debugSvg:In("debugSvg",{defaults:{all:!1}}),showFps:In("showFps",{defaults:{all:!1}}),measurePerformance:In("measurePerformance",{defaults:{all:!1}}),throwToBlob:In("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:In("reconnectOnPing",{defaults:{all:!1}}),debugCursors:In("debugCursors",{defaults:{all:!1}}),forceSrgb:In("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:In("debugGeometry",{defaults:{all:!1}}),hideShapes:In("hideShapes",{defaults:{all:!1}}),editOnType:In("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;oa("element removal logging",()=>{xt.logElementRemoves.get()?Element.prototype.removeChild=function(n){return console.warn("[tldraw] removing child:",n),e.call(this,n)}:Element.prototype.removeChild=e})}function In(e,{defaults:n,shouldStoreForSession:t=!0}){return Q6({name:e,defaults:n,shouldStoreForSession:t})}function Q6(e){const n=eH(e),t=e.shouldStoreForSession?J6(e.name):null,r=Mt(`debug:${e.name}`,t??n);return typeof window<"u"&&(e.shouldStoreForSession&&oa(`debug:${e.name}`,()=>{const o=r.get();o===n?jk(`tldraw_debug:${e.name}`):jx(`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 J6(e){try{return JSON.parse(Ak(`tldraw_debug:${e}`)??"null")}catch{return null}}function bm(e){try{return e()}catch{return null}}function eH(e){switch(bm(()=>wm.TLDRAW_ENV)??bm(()=>wm.VERCEL_PUBLIC_TLDRAW_ENV)??bm(()=>wm.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 Fp(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return Fp(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ee(e){e.preventDefault(),xt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function Du(e,n){if(e.setPointerCapture(n.pointerId),xt.logPointerCaptures.get()){const t=N_.get();t.set(e,(t.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,n)}}function Ru(e,n){if(e.hasPointerCapture(n.pointerId)&&(e.releasePointerCapture(n.pointerId),xt.logPointerCaptures.get())){const t=N_.get();t.get(e)===1?t.delete(e):t.has(e)?t.set(e,t.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,n)}}const Ht=e=>e.stopPropagation(),Jt=(e,n,t)=>{e&&e.style.setProperty(n,t)};function On(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 tH(){const e=B();return P.useMemo(function(){let r,o;function s(m){if(!m.isKilled){if(m.button===Gx){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...On(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(Du(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...On(m)}))}}function i(m){m.isKilled||m.clientX===r&&m.clientY===o||(r=m.clientX,o=m.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...On(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,o=m.clientY,Ru(m.currentTarget,m),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...On(m)}))}function l(m){if(m.isKilled||e.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const x=m.pointerType==="mouse"||m.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!0:null})}function c(m){if(m.isKilled||e.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const x=m.pointerType==="mouse"||m.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:x?!1:null})}function u(m){m.isKilled=!0,Ee(m)}function h(m){m.isKilled=!0,m.target instanceof HTMLElement&&m.target.tagName!=="A"&&m.target.tagName!=="TEXTAREA"&&!(e.getEditingShape()&&m.target.className.includes("tl-text-content"))&&Ee(m)}function p(m){Ee(m)}async function f(m){var y,v;if(Ee(m),!((v=(y=m.dataTransfer)==null?void 0:y.files)!=null&&v.length))return;const x=Array.from(m.dataTransfer.files);await e.putExternalContent({type:"files",files:x,point:e.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function S(m){Ht(m)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:h,onClick:S}},[e])}function nH(){const e=B();P.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 z_=P.createContext(null);function rH({container:e,children:n}){return d.jsx(z_.Provider,{value:e,children:n})}function un(){return yr(P.useContext(z_),"useContainer used outside of <Tldraw />")}function oH(){const e=B(),n=un(),t=G("isFocused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=l=>{l.type==="change"&&o()};i.addEventListener?i.addEventListener("change",o):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",o):i.removeListener&&i.removeListener(a)},e.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return o(),()=>{r==null||r()}},[e]),P.useEffect(()=>{if(!t)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!Pd()&&Ee(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Ee(a);return}break}case"Tab":{if(Pd()||e.getIsMenuOpen())return;break}case",":return;case"Escape":{if((e.getEditingShape()||e.getSelectedShapeIds().length>0)&&a.preventDefault(),e.getOpenMenus().length>0)return;e.inputs.keys.has("Escape")||(e.inputs.keys.add("Escape"),e.cancel(),e.focus());return}default:if(Pd()||e.getIsMenuOpen())return}const l={type:"keyboard",name:a.repeat?"key_repeat":"key_down",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)},o=a=>{if(a.isKilled||(a.isKilled=!0,Pd()||e.getIsMenuOpen())||a.key===",")return;const l={type:"keyboard",name:"key_up",key:a.key,code:a.code,shiftKey:a.shiftKey,altKey:a.altKey,ctrlKey:a.metaKey||a.ctrlKey};e.dispatch(l)};function s(a){var l,c;if(n.contains(a.target)){const u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+h>e.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),Ee(a))}}const i=a=>{n.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ee(a)};return n.addEventListener("touchstart",s,{passive:!1}),n.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ee),document.addEventListener("gesturechange",Ee),document.addEventListener("gestureend",Ee),n.addEventListener("keydown",r),n.addEventListener("keyup",o),()=>{n.removeEventListener("touchstart",s),n.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ee),document.removeEventListener("gesturechange",Ee),document.removeEventListener("gestureend",Ee),n.removeEventListener("keydown",r),n.removeEventListener("keyup",o)}},[e,n,t])}const sH=["input","select","button","textarea"];function Pd(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||sH.indexOf(e.tagName.toLowerCase())>-1))}const iH=["textarea","input"];function aH(e){const n=B();P.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(iH.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||n.isIn("select.editing_shape"))return;Ee(o)}};return t.addEventListener("touchstart",r),t.addEventListener("touchend",r),()=>{t.removeEventListener("touchstart",r),t.removeEventListener("touchend",r)}},[n,e])}function lH(e,n,t){return Math.max(n,Math.min(e,t))}const Ut={toVector(e,n){return e===void 0&&(e=n),Array.isArray(e)?e:[e,e]},add(e,n){return[e[0]+n[0],e[1]+n[1]]},sub(e,n){return[e[0]-n[0],e[1]-n[1]]},addTo(e,n){e[0]+=n[0],e[1]+=n[1]},subTo(e,n){e[0]-=n[0],e[1]-=n[1]}};function tP(e,n,t){return n===0||Math.abs(n)===1/0?Math.pow(e,t*5):e*n*t/(n+t*e)}function nP(e,n,t,r=.15){return r===0?lH(e,n,t):e<n?-tP(n-e,t-n,r)+n:e>t?+tP(e-t,t-n,r)+t:e}function cH(e,[n,t],[r,o]){const[[s,i],[a,l]]=e;return[nP(n,s,i,r),nP(t,a,l,o)]}function uH(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 dH(e){var n=uH(e,"string");return typeof n=="symbol"?n:String(n)}function tn(e,n,t){return n=dH(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function rP(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?rP(Object(t),!0).forEach(function(r){tn(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):rP(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}const B_={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 oP(e){return e?e[0].toUpperCase()+e.slice(1):""}const hH=["enter","leave"];function pH(e=!1,n){return e&&!hH.includes(n)}function fH(e,n="",t=!1){const r=B_[e],o=r&&r[n]||n;return"on"+oP(e)+oP(o)+(pH(t,o)?"Capture":"")}const gH=["gotpointercapture","lostpointercapture"];function mH(e){let n=e.substring(2).toLowerCase();const t=!!~n.indexOf("passive");t&&(n=n.replace("passive",""));const r=gH.includes(n)?"capturecapture":"capture",o=!!~n.indexOf(r);return o&&(n=n.replace("capture","")),{device:n,capture:o,passive:t}}function yH(e,n=""){const t=B_[e],r=t&&t[n]||n;return e+r}function U_(e){return"touches"in e}function SH(e){return U_(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function vH(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 bS(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 xH(e){return vH(e).map(n=>n.identifier)}function sP(e,n){const[t,r]=Array.from(e.touches).filter(o=>n.includes(o.identifier));return bS(t,r)}const iP=40,aP=800;function H_(e){let{deltaX:n,deltaY:t,deltaMode:r}=e;return r===1?(n*=iP,t*=iP):r===2&&(n*=aP,t*=aP),[n,t]}function wH(e){const n={};if("buttons"in e&&(n.buttons=e.buttons),"shiftKey"in e){const{shiftKey:t,altKey:r,metaKey:o,ctrlKey:s}=e;Object.assign(n,{shiftKey:t,altKey:r,metaKey:o,ctrlKey:s})}return n}function Np(e,...n){return typeof e=="function"?e(...n):e}function bH(){}function PH(...e){return e.length===0?bH:e.length===1?e[0]:function(){let n;for(const t of e)n=t.apply(this,arguments)||n;return n}}function lP(e,n){return Object.assign({},n,e||{})}const CH=32;class K_{constructor(n,t,r){this.ctrl=n,this.args=t,this.key=r,this.state||(this.state={},this.computeValues([0,0]),this.computeInitial(),this.init&&this.init(),this.reset())}get state(){return this.ctrl.state[this.key]}set state(n){this.ctrl.state[this.key]=n}get shared(){return this.ctrl.state.shared}get eventStore(){return this.ctrl.gestureEventStores[this.key]}get timeoutStore(){return this.ctrl.gestureTimeoutStores[this.key]}get config(){return this.ctrl.config[this.key]}get sharedConfig(){return this.ctrl.config.shared}get handler(){return this.ctrl.handlers[this.key]}reset(){const{state:n,shared:t,ingKey:r,args:o}=this;t[r]=n._active=n.active=n._blocked=n._force=!1,n._step=[!1,!1],n.intentional=!1,n._movement=[0,0],n._distance=[0,0],n._direction=[0,0],n._delta=[0,0],n._bounds=[[-1/0,1/0],[-1/0,1/0]],n.args=o,n.axis=void 0,n.memo=void 0,n.elapsedTime=n.timeDelta=0,n.direction=[0,0],n.distance=[0,0],n.overflow=[0,0],n._movementBound=[!1,!1],n.velocity=[0,0],n.movement=[0,0],n.delta=[0,0],n.timeStamp=0}start(n){const t=this.state,r=this.config;t._active||(this.reset(),this.computeInitial(),t._active=!0,t.target=n.target,t.currentTarget=n.currentTarget,t.lastOffset=r.from?Np(r.from,t):t.offset,t.offset=t.lastOffset,t.startTime=t.timeStamp=n.timeStamp)}computeValues(n){const t=this.state;t._values=n,t.values=this.config.transform(n)}computeInitial(){const n=this.state;n._initial=n._values,n.initial=n.values}compute(n){const{state:t,config:r,shared:o}=this;t.args=this.args;let s=0;if(n&&(t.event=n,r.preventDefault&&n.cancelable&&t.event.preventDefault(),t.type=n.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,wH(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);Ut.addTo(t._distance,C)}this.axisIntent&&this.axisIntent(n);const[i,a]=t._movement,[l,c]=r.threshold,{_step:u,values:h}=t;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),t.intentional=u[0]!==!1||u[1]!==!1,!t.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[C,k]=h;p[0]=u[0]!==!1?C-u[0]:0,p[1]=u[1]!==!1?k-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!t._blocked&&this.restrictToAxis(p);const f=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=Np(r.bounds,t)),this.setup&&this.setup()),t.movement=p,this.computeOffset()));const[m,x]=t.offset,[[y,v],[b,E]]=t._bounds;t.overflow=[m<y?-1:m>v?1:0,x<b?-1:x>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=cH(t._bounds,t.offset,I),t.delta=Ut.sub(t.offset,f),this.computeMovement(),S&&(!t.last||s>CH)){t.delta=Ut.sub(t.offset,f);const C=t.delta.map(Math.abs);Ut.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 IH([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 EH extends K_{constructor(...n){super(...n),tn(this,"aliasKey","xy")}reset(){super.reset(),this.state.axis=void 0}init(){this.state.offset=[0,0],this.state.lastOffset=[0,0]}computeOffset(){this.state.offset=Ut.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Ut.sub(this.state.offset,this.state.lastOffset)}axisIntent(n){const t=this.state,r=this.config;if(!t.axis&&n){const o=typeof r.axisThreshold=="object"?r.axisThreshold[SH(n)]:r.axisThreshold;t.axis=IH(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 kH=e=>e,cP=.15,W_={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[cP,cP];case!1:return[0,0];default:return Ut.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return Ut.toVector(e)},transform(e,n,t){const r=e||t.shared.transform;return this.hasCustomTransform=!!r,r||kH},threshold(e){return Ut.toVector(e,0)}},_H=0,Lu=ut(ut({},W_),{},{axis(e,n,{axis:t}){if(this.lockDirection=t==="lock",!this.lockDirection)return t},axisThreshold(e=_H){return e},bounds(e={}){if(typeof e=="function")return s=>Lu.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]]}}),$u=typeof window<"u"&&window.document&&window.document.createElement;function G_(){return $u&&"ontouchstart"in window}function TH(){return G_()||$u&&window.navigator.maxTouchPoints>1}function MH(){return $u&&"onpointerdown"in window}function AH(){return $u&&"exitPointerLock"in window.document}function jH(){try{return"constructor"in GestureEvent}catch{return!1}}const Sr={isBrowser:$u,gesture:jH(),touch:G_(),touchscreen:TH(),pointer:MH(),pointerLock:AH()},OH=250,DH=180,RH=.5,LH=50,$H=250,FH=10,uP={mouse:0,touch:0,pen:8};ut(ut({},Lu),{},{device(e,n,{pointer:{touch:t=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&Sr.pointerLock,Sr.touch&&t?"touch":this.pointerLock?"mouse":Sr.pointer&&!o?"pointer":Sr.touch?"touch":"mouse"},preventScrollAxis(e,n,{preventScroll:t}){if(this.preventScrollDelay=typeof t=="number"?t:t||t===void 0&&e?OH:void 0,!(!Sr.touchscreen||t===!1))return e||(t!==void 0?"y":void 0)},pointerCapture(e,n,{pointer:{capture:t=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&t},threshold(e,n,{filterTaps:t=!1,tapsThreshold:r=3,axis:o=void 0}){const s=Ut.toVector(e,t?r:o?1:0);return this.filterTaps=t,this.tapsThreshold=r,s},swipe({velocity:e=RH,distance:n=LH,duration:t=$H}={}){return{velocity:this.transform(Ut.toVector(e)),distance:this.transform(Ut.toVector(n)),duration:t}},delay(e=0){switch(e){case!0:return DH;case!1:return 0;default:return e}},axisThreshold(e){return e?ut(ut({},uP),e):uP},keyboardDisplacement(e=FH){return e}});function V_(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 NH=30,zH=100;class BH extends K_{constructor(...n){super(...n),tn(this,"ingKey","pinching"),tn(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const n=this.state;n._touchIds=[],n.canceled=!1,n.cancel=this.cancel.bind(this),n.turns=0}computeOffset(){const{type:n,movement:t,lastOffset:r}=this.state;n==="wheel"?this.state.offset=Ut.add(t,r):this.state.offset=[(1+t[0])*r[0],t[1]+r[1]]}computeMovement(){const{offset:n,lastOffset:t}=this.state;this.state.movement=[n[0]/t[0],n[1]-t[1]]}axisIntent(){const n=this.state,[t,r]=n._movement;if(!n.axis){const o=Math.abs(t)*NH-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=sP(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=bS(...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=sP(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=bS(...Array.from(t.values()));r&&this.pinchMove(n,r)}pinchMove(n,t){const r=this.state,o=r._values[1],s=t.angle-o;let i=0;Math.abs(s)>270&&(i+=Math.sign(s)),this.computeValues([t.distance,t.angle-360*i]),r.origin=t.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(n),this.emit()}touchEnd(n){this.ctrl.setEventIds(n),this.state._active&&this.state._touchIds.some(t=>!this.ctrl.touchIds.has(t))&&(this.state._active=!1,this.compute(n),this.emit())}pointerEnd(n){const t=this.state;this.ctrl.setEventIds(n);try{n.target.releasePointerCapture(n.pointerId)}catch{}t._pointerEvents.has(n.pointerId)&&t._pointerEvents.delete(n.pointerId),t._active&&t._pointerEvents.size<2&&(t._active=!1,this.compute(n),this.emit())}gestureStart(n){n.cancelable&&n.preventDefault();const t=this.state;t._active||(this.start(n),this.computeValues([n.scale,n.rotation]),t.origin=[n.clientX,n.clientY],this.compute(n),this.emit())}gestureMove(n){if(n.cancelable&&n.preventDefault(),!this.state._active)return;const t=this.state;this.computeValues([n.scale,n.rotation]),t.origin=[n.clientX,n.clientY];const r=t._movement;t._movement=[n.scale-1,n.rotation],t._delta=Ut.sub(t._movement,r),this.compute(n),this.emit()}gestureEnd(n){this.state._active&&(this.state._active=!1,this.compute(n),this.emit())}wheel(n){const t=this.config.modifierKey;t&&(Array.isArray(t)?!t.find(r=>n[r]):!n[t])||(this.state._active?this.wheelChange(n):this.wheelStart(n),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(n){this.start(n),this.wheelChange(n)}wheelChange(n){"uv"in n||n.cancelable&&n.preventDefault();const r=this.state;r._delta=[-H_(n)[1]/zH*r.offset[0],0],Ut.addTo(r._movement,r._delta),V_(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 UH=ut(ut({},W_),{},{device(e,n,{shared:t,pointer:{touch:r=!1}={}}){if(t.target&&!Sr.touch&&Sr.gesture)return"gesture";if(Sr.touch&&r)return"touch";if(Sr.touchscreen){if(Sr.pointer)return"pointer";if(Sr.touch)return"touch"}},bounds(e,n,{scaleBounds:t={},angleBounds:r={}}){const o=i=>{const a=lP(Np(t,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=lP(Np(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof t!="function"&&typeof r!="function"?[o(),s()]:i=>[o(i),s(i)]},threshold(e,n,t){return this.lockDirection=t.axis==="lock",Ut.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});ut(ut({},Lu),{},{mouseOnly:(e=!0)=>e});class HH extends EH{constructor(...n){super(...n),tn(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=H_(n),Ut.addTo(t._movement,t._delta),V_(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 KH=Lu;ut(ut({},Lu),{},{mouseOnly:(e=!0)=>e});const Vx=new Map,PS=new Map;function WH(e){Vx.set(e.key,e.engine),PS.set(e.key,e.resolver)}const GH={key:"pinch",engine:BH,resolver:UH},VH={key:"wheel",engine:HH,resolver:KH};function YH(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 XH(e,n){if(e==null)return{};var t=YH(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 qH={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=Sr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:n=!1}={}){return{passive:e,capture:n}},transform(e){return e}},ZH=["target","eventOptions","window","enabled","transform"];function xh(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]=xh(e[r],o);break;case"boolean":o&&(t[r]=e[r]);break}return t}function QH(e,n,t={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=XH(r,ZH);if(t.shared=xh({target:o,eventOptions:s,window:i,enabled:a,transform:l},qH),n){const u=PS.get(n);t[n]=xh(ut({shared:t.shared},c),u)}else for(const u in c){const h=PS.get(u);h&&(t[u]=xh(ut({shared:t.shared},c[u]),h))}return t}class Y_{constructor(n,t){tn(this,"_listeners",new Set),this._ctrl=n,this._gestureKey=t}add(n,t,r,o,s){const i=this._listeners,a=yH(t,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ut(ut({},l),s);n.addEventListener(a,o,c);const u=()=>{n.removeEventListener(a,o,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(n=>n()),this._listeners.clear()}}class JH{constructor(){tn(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 e9{constructor(n){tn(this,"gestures",new Set),tn(this,"_targetEventStore",new Y_(this)),tn(this,"gestureEventStores",{}),tn(this,"gestureTimeoutStores",{}),tn(this,"handlers",{}),tn(this,"config",{}),tn(this,"pointerIds",new Set),tn(this,"touchIds",new Set),tn(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),t9(this,n)}setEventIds(n){if(U_(n))return this.touchIds=new Set(xH(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=QH(n,t,this.config)}clean(){this._targetEventStore.clean();for(const n of this.gestures)this.gestureEventStores[n].clean(),this.gestureTimeoutStores[n].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...n){const t=this.config.shared,r={};let o;if(!(t.target&&(o=t.target(),!o))){if(t.enabled){for(const i of this.gestures){const a=this.config[i],l=dP(r,a.eventOptions,!!o);if(a.enabled){const c=Vx.get(i);new c(this,n,i).bind(l)}}const s=dP(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]=PH(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=mH(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function fa(e,n){e.gestures.add(n),e.gestureEventStores[n]=new Y_(e,n),e.gestureTimeoutStores[n]=new JH}function t9(e,n){n.drag&&fa(e,"drag"),n.wheel&&fa(e,"wheel"),n.scroll&&fa(e,"scroll"),n.move&&fa(e,"move"),n.pinch&&fa(e,"pinch"),n.hover&&fa(e,"hover")}const dP=(e,n,t)=>(r,o,s,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:n.capture,h=(c=i.passive)!==null&&c!==void 0?c:n.passive;let p=a?r:fH(r,o,u);t&&h&&(p+="Passive"),e[p]=e[p]||[],e[p].push(s)},n9=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function r9(e){const n={},t={},r=new Set;for(let o in e)n9.test(o)?(r.add(RegExp.lastMatch),t[o]=e[o]):n[o]=e[o];return[t,n,r]}function ga(e,n,t,r,o,s){if(!e.has(t)||!Vx.has(r))return;const i=t+"Start",a=t+"End",l=c=>{let u;return c.first&&i in n&&n[i](c),t in n&&(u=n[t](c)),c.last&&a in n&&n[a](c),u};o[r]=l,s[r]=s[r]||{}}function o9(e,n){const[t,r,o]=r9(e),s={};return ga(o,t,"onDrag","drag",s,n),ga(o,t,"onWheel","wheel",s,n),ga(o,t,"onScroll","scroll",s,n),ga(o,t,"onPinch","pinch",s,n),ga(o,t,"onMove","move",s,n),ga(o,t,"onHover","hover",s,n),{handlers:s,config:n,nativeHandlers:r}}function s9(e,n={},t,r){const o=xe.useMemo(()=>new e9(e),[]);if(o.applyHandlers(e,r),o.applyConfig(n,t),xe.useEffect(o.effect.bind(o)),xe.useEffect(()=>o.clean.bind(o),[]),n.target===void 0)return o.bind.bind(o)}function i9(e){return e.forEach(WH),function(t,r){const{handlers:o,nativeHandlers:s,config:i}=o9(t,r||{});return s9(o,i,void 0,s)}}const hP=10,a9=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function X_(e){let{deltaY:n,deltaX:t}=e,r=0;return e.ctrlKey||e.altKey||e.metaKey?r=(Math.abs(n)>hP?hP*Math.sign(n):n)/100:e.shiftKey&&!a9&&(t=n,n=0),{x:-t,y:-n,z:-r}}const l9=i9([VH,GH]);let ma;const c9=e=>ma===void 0?(ma=e,!1):e-ma>120&&e-ma<160?(ma=e,!0):(ma=e,!1);function u9(e){const n=B(),t=P.useMemo(()=>{let r="not sure";const o=({event:m})=>{if(!n.getInstanceState().isFocused||(r="not sure",c9(Date.now())))return;const x=n.getEditingShapeId();if(x){const b=n.getShape(x);if(b&&n.getShapeUtil(b).canScroll(b)){const I=n.getShapePageBounds(x);if(I!=null&&I.containsPoint(n.inputs.currentPagePoint))return}}Ee(m),Ht(m);const y=X_(m);if(y.x===0&&y.y===0)return;const v={type:"wheel",name:"wheel",delta:y,point:new w(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey};n.dispatch(v)};let s=1,i=1,a=1,l=0;const c=new w,u=new w,h=m=>{const x=e.current;r="not sure";const{event:y,origin:v,da:b}=m;y instanceof WheelEvent||(y.target===x||x!=null&&x.contains(y.target))&&(u.x=v[0],u.y=v[1],c.x=v[0],c.y=v[1],s=b[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}))},p=m=>{if(m&&(r="zooming"),r==="zooming")return;const x=Math.abs(l-s),y=w.Dist(c,u);switch(r){case"not sure":{x>24?r="zooming":y>16&&(r="panning");break}case"panning":{x>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:h,onPinchEnd:m=>{const x=e.current,{event:y,origin:v,offset:b}=m;if(y instanceof WheelEvent||!(y.target===x||x!=null&&x.contains(y.target)))return;const E=b[0];r="not sure",n.timers.requestAnimationFrame(()=>{n.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:E},delta:{x:v[0],y:v[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey})})},onPinch:m=>{const x=e.current,{event:y,origin:v,offset:b,da:E}=m;if(y instanceof WheelEvent||!(y.target===x||x!=null&&x.contains(y.target)))return;const I=m.type==="gesturechange"||m.type==="gestureend";l=E[0];const C=v[0]-u.x,k=v[1]-u.y;switch(u.x=v[0],u.y=v[1],p(I),r){case"zooming":{a=b[0],n.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:C,y:k},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:k},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey});break}}}}},[n,e]);l9(t,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[n.getZoomLevel(),0],scaleBounds:()=>({from:n.getZoomLevel(),max:8,min:.05})}})}function Pm(e,n,t){const r=e.getShape(n),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===t)}}function d9(e,n){const t=B();return P.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Fp(l.currentTarget);Du(c,l);const{shape:u,handle:h}=Pm(t,e,n);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...On(l)})};let o,s;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===o&&l.clientY===s)return;o=l.clientX,s=l.clientY;const{shape:c,handle:u}=Pm(t,e,n);u&&t.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...On(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Fp(l.currentTarget);Ru(c,l);const{shape:u,handle:h}=Pm(t,e,n);h&&t.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...On(l)})}}},[t,e,n])}const Qe=class Qe{constructor(n=0,t=0,r=0,o=0){g(this,"x",0);g(this,"y",0);g(this,"w",0);g(this,"h",0);this.x=n,this.y=t,this.w=r,this.h=o}get point(){return new w(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 w(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 w(this.minX,this.minY),new w(this.maxX,this.minY),new w(this.maxX,this.maxY),new w(this.minX,this.maxY)]}get cornersAndCenter(){return[new w(this.minX,this.minY),new w(this.maxX,this.minY),new w(this.maxX,this.maxY),new w(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 w(this.w,this.h)}toFixed(){return this.x=wd(this.x),this.y=wd(this.y),this.w=wd(this.w),this.h=wd(this.h),this}setTo(n){return this.x=n.x,this.y=n.y,this.w=n.w,this.h=n.h,this}set(n=0,t=0,r=0,o=0){return this.x=n,this.y=t,this.w=r,this.h=o,this}expand(n){const t=Math.min(this.minX,n.minX),r=Math.min(this.minY,n.minY),o=Math.max(this.maxX,n.maxX),s=Math.max(this.maxY,n.maxY);return this.x=t,this.y=r,this.w=o-t,this.h=s-r,this}expandBy(n){return this.x-=n,this.y-=n,this.w+=n*2,this.h+=n*2,this}scale(n){return this.x/=n,this.y/=n,this.w/=n,this.h/=n,this}clone(){const{x:n,y:t,w:r,h:o}=this;return new Qe(n,t,r,o)}translate(n){return this.x+=n.x,this.y+=n.y,this}snapToGrid(n){const t=Math.round(this.minX/n)*n,r=Math.round(this.minY/n)*n,o=Math.round(this.maxX/n)*n,s=Math.round(this.maxY/n)*n;this.minX=t,this.minY=r,this.width=Math.max(1,o-t),this.height=Math.max(1,s-r)}collides(n){return Qe.Collides(this,n)}contains(n){return Qe.Contains(this,n)}includes(n){return Qe.Includes(this,n)}containsPoint(n,t=0){return Qe.ContainsPoint(this,n,t)}getHandlePoint(n){switch(n){case"top_left":return new w(this.minX,this.minY);case"top_right":return new w(this.maxX,this.minY);case"bottom_left":return new w(this.minX,this.maxY);case"bottom_right":return new w(this.maxX,this.maxY);case"top":return new w(this.midX,this.minY);case"right":return new w(this.maxX,this.midY);case"bottom":return new w(this.midX,this.maxY);case"left":return new w(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(n,t,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:h}=this;switch(n){case"left":case"top_left":case"bottom_left":{l+=t;break}case"right":case"top_right":case"bottom_right":{u+=t;break}}switch(n){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{h+=r;break}}const p=(u-l)/(i-o),f=(h-c)/(a-s),S=p<0,m=f<0;if(S){const x=u;u=l,l=x}if(m){const x=h;h=c,c=x}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(h-c)}union(n){const t=Math.min(this.minX,n.x),r=Math.min(this.minY,n.y),o=Math.max(this.maxX,n.w+n.x),s=Math.max(this.maxY,n.h+n.y);return this.x=t,this.y=r,this.width=o-t,this.height=s-r,this}static From(n){return new Qe(n.x,n.y,n.w,n.h)}static FromCenter(n,t){return new Qe(n.x-t.x/2,n.y-t.y/2,t.x,t.y)}static FromPoints(n){if(n.length===0)return new Qe;let t=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,l=n.length;a<l;a++)i=n[a],t=Math.min(i.x,t),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new Qe(t,r,o-t,s-r)}static Expand(n,t){const r=Math.min(t.minX,n.minX),o=Math.min(t.minY,n.minY),s=Math.max(t.maxX,n.maxX),i=Math.max(t.maxY,n.maxY);return new Qe(r,o,s-r,i-o)}static ExpandBy(n,t){return new Qe(n.minX-t,n.minY-t,n.width+t*2,n.height+t*2)}static Resize(n,t,r,o,s=!1){const{minX:i,minY:a,maxX:l,maxY:c}=n;let{minX:u,minY:h,maxX:p,maxY:f}=n;switch(t){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(t){case"top":case"top_left":case"top_right":{h+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const S=(p-u)/(l-i),m=(f-h)/(c-a),x=S<0,y=m<0;if(s){const b=(l-i)/(c-a),E=Math.abs(p-u),I=Math.abs(f-h),C=E*(m<0?1:-1)*(1/b),k=I*(S<0?1:-1)*b,T=b<E/I;switch(t){case"top_left":{T?h=f+C:u=p+k;break}case"top_right":{T?h=f+C:p=u-k;break}case"bottom_right":{T?f=h-C:p=u-k;break}case"bottom_left":{T?f=h-C:u=p+k;break}case"bottom":case"top":{const O=(u+p)/2,_=I*b;u=O-_/2,p=O+_/2;break}case"left":case"right":{const O=(h+f)/2,_=E/b;h=O-_/2,f=O+_/2;break}}}if(x){const b=p;p=u,u=b}if(y){const b=f;f=h,h=b}const v=new Qe(u,h,Math.abs(p-u),Math.abs(f-h));return{box:v,scaleX:+(v.width/n.width*(S>0?1:-1)).toFixed(5),scaleY:+(v.height/n.height*(m>0?1:-1)).toFixed(5)}}equals(n){return Qe.Equals(this,n)}static Equals(n,t){return t.x===n.x&&t.y===n.y&&t.w===n.w&&t.h===n.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(n){return new Qe(n.x,n.y,Math.max(1,n.w),Math.max(1,n.h))}};g(Qe,"Collides",(n,t)=>!(n.maxX<t.minX||n.minX>t.maxX||n.maxY<t.minY||n.minY>t.maxY)),g(Qe,"Contains",(n,t)=>n.minX<t.minX&&n.minY<t.minY&&n.maxY>t.maxY&&n.maxX>t.maxX),g(Qe,"Includes",(n,t)=>Qe.Collides(n,t)||Qe.Contains(n,t)),g(Qe,"ContainsPoint",(n,t,r=0)=>!(t.x<n.minX-r||t.y<n.minY-r||t.x>n.maxX+r||t.y>n.maxY+r)),g(Qe,"Common",n=>{let t=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<n.length;i++){const a=n[i];t=Math.min(t,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new Qe(t,r,o-t,s-r)}),g(Qe,"Sides",(n,t=0)=>{const{corners:r}=n;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let Z=Qe;function h9(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 p9(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 f9(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function g9(e){const n=B();P.useLayoutEffect(()=>{let t=new Z;function r(){const c=e.current;if(!c)return null;const u=c.getBoundingClientRect(),h=new Z(u.left||u.x,u.top||u.y,Math.max(u.width,1),Math.max(u.height,1));t.equals(h)||(n.updateViewportScreenBounds(h),t=h)}r();const o=pk(r,200,{trailing:!0}),s=n.timers.setInterval(o,1e3);window.addEventListener("resize",o);const i=new ResizeObserver(c=>{c[0].contentRect&&o()}),a=e.current;let l=null;return a&&(i.observe(a),l=m9(a),l.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),l==null||l.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 m9=e=>{let n=e.parentElement;for(;n;){if(n===document.body)return document;const{overflowY:t}=window.getComputedStyle(n);if(n.scrollHeight>n.clientHeight&&(t==="auto"||t==="scroll"||t==="overlay"))return n;n=n.parentElement}return document},De=class De{constructor(n,t,r,o,s,i){g(this,"a",1);g(this,"b",0);g(this,"c",0);g(this,"d",1);g(this,"e",0);g(this,"f",0);this.a=n,this.b=t,this.c=r,this.d=o,this.e=s,this.f=i}equals(n){return this===n||this.a===n.a&&this.b===n.b&&this.c===n.c&&this.d===n.d&&this.e===n.e&&this.f===n.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(n){const t=n,{a:r,b:o,c:s,d:i,e:a,f:l}=this;return this.a=r*t.a+s*t.b,this.c=r*t.c+s*t.d,this.e=r*t.e+s*t.f+a,this.b=o*t.a+i*t.b,this.d=o*t.c+i*t.d,this.f=o*t.e+i*t.f+l,this}rotate(n,t,r){return n===0?this:t===void 0?this.multiply(De.Rotate(n)):this.translate(t,r).multiply(De.Rotate(n)).translate(-t,-r)}translate(n,t){return this.multiply(De.Translate(n,t))}scale(n,t){return this.multiply(De.Scale(n,t))}invert(){const{a:n,b:t,c:r,d:o,e:s,f:i}=this,a=n*o-t*r;return this.a=o/a,this.b=t/-a,this.c=r/-a,this.d=n/a,this.e=(o*s-r*i)/-a,this.f=(t*s-n*i)/a,this}applyToPoint(n){return De.applyToPoint(this,n)}applyToPoints(n){return De.applyToPoints(this,n)}rotation(){return De.Rotation(this)}point(){return De.Point(this)}decomposed(){return De.Decompose(this)}toCssString(){return De.toCssString(this)}setTo(n){return Object.assign(this,n),this}decompose(){return De.Decompose(this)}clone(){return new De(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new De(1,0,0,1,0,0)}static Translate(n,t){return new De(1,0,0,1,n,t)}static Rotate(n,t,r){if(n===0)return De.Identity();const o=Math.cos(n),s=Math.sin(n),i=new De(o,s,-s,o,0,0);return t===void 0?i:De.Compose(De.Translate(t,r),i,De.Translate(-t,-r))}static Multiply(n,t){return{a:n.a*t.a+n.c*t.b,c:n.a*t.c+n.c*t.d,e:n.a*t.e+n.c*t.f+n.e,b:n.b*t.a+n.d*t.b,d:n.b*t.c+n.d*t.d,f:n.b*t.e+n.d*t.f+n.f}}static Inverse(n){const t=n.a*n.d-n.b*n.c;return{a:n.d/t,b:n.b/-t,c:n.c/-t,d:n.a/t,e:(n.d*n.e-n.c*n.f)/-t,f:(n.b*n.e-n.a*n.f)/t}}static Absolute(n){const t=n.a*n.d-n.b*n.c;return{a:n.d/t,b:n.b/-t,c:n.c/-t,d:n.a/t,e:(n.d*n.e-n.c*n.f)/t,f:(n.b*n.e-n.a*n.f)/-t}}static Compose(...n){const t=De.Identity();for(let r=0,o=n.length;r<o;r++)t.multiply(n[r]);return t}static Point(n){return new w(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=Ge+Math.acos(n.b/r)*(n.d>0?-1:1)}else t=0;return xS(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=Ge+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:xS(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(${N(n.a)}, ${N(n.b)}, ${N(n.c)}, ${N(n.d)}, ${N(n.e)}, ${N(n.f)})`}static applyToPoint(n,t){return new w(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 w(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 Z(n.e+t.minX,n.f+t.minY,t.width,t.height)}static From(n){return new De(n.a,n.b,n.c,n.d,n.e,n.f)}static Cast(n){return n instanceof De?n:De.From(n)}};g(De,"Scale",(n,t,r,o)=>{const s=new De(n,0,0,t,0,0);return r===void 0?s:De.Compose(De.Translate(r,o),s,De.Translate(-r,-o))});let oe=De;function q_(e,n){return n===0?e:q_(n,e%n)}function Z_(e){const n=e.toString().split(".")[1];if(!n)return 1;const t=Math.pow(10,n.length),r=parseInt(n,10);return t/q_(r,t)}class oi{constructor(n){g(this,"isFilled",!1);g(this,"isClosed",!0);g(this,"isLabel",!1);g(this,"debugColor");g(this,"ignore");g(this,"_vertices");g(this,"_bounds");g(this,"_area");g(this,"_length");this.isFilled=n.isFilled,this.isClosed=n.isClosed,this.isLabel=n.isLabel??!1,this.debugColor=n.debugColor,this.ignore=n.ignore}hitTestPoint(n,t=0,r=!1){return this.isClosed&&(this.isFilled||r)&&tr(n,this.vertices)?!0:w.Dist2(n,this.nearestPoint(n))<=t*t}distanceToPoint(n,t=!1){return n.dist(this.nearestPoint(n))*(this.isClosed&&(this.isFilled||t)&&tr(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,l;for(let c=0;c<r.length;c++)a=r[c],l=w.NearestPointOnLineSegment(n,t,a,!0),i=w.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&tr(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,l;for(let c=0;c<r.length;c++)a=r[c],l=w.NearestPointOnLineSegment(n,t,a,!0),i=w.Dist2(a,l),i<s&&(s=i,o=l);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 Z.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+=w.Dist2(r,t),r=t;return Math.sqrt(o)}}class Hr extends oi{constructor(t){super({...t,isClosed:!0,isFilled:!1});g(this,"children",[]);g(this,"ignoredChildren",[]);for(const r of t.children)r.ignore?this.ignoredChildren.push(r):this.children.push(r);if(this.children.length===0)throw Error("Group2d must have at least one child")}getVertices(){return this.children.filter(t=>!t.isLabel).flatMap(t=>t.vertices)}nearestPoint(t){let r=1/0,o;const{children:s}=this;if(s.length===0)throw Error("no children");let i,a;for(const l of s)i=l.nearestPoint(t),a=w.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=Z.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],l=i.dist(a),c=r[(o+1)%s],u=i.dist(c),h=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/u);t+=`M${h.x},${h.y} L${p.x},${p.y} L${f.x},${f.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 y9(e=!0){const[n,t]=P.useState(0),r=B();P.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const S9=ar(function({showStroke:n=!0,showVertices:t=!0,showClosestPointOnOutline:r=!0}){const o=B();y9(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return d.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=o.getShape(l.id);if(c.type==="group")return null;const u=o.getShapeGeometry(c),h=o.getShapePageTransform(c),p=o.getPointInShapeSpace(c,a),f=u.nearestPoint(p),S=u.distanceToPoint(p,!0),m=Math.abs(S)*s,x=S<0,{vertices:y}=u;return d.jsxs("g",{transform:h.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[n&&d.jsx("g",{stroke:u.debugColor??"red",opacity:"1",strokeWidth:2/s,fill:"none",children:d.jsx(Q_,{geometry:u})}),t&&y.map((v,b)=>d.jsx("circle",{cx:v.x,cy:v.y,r:2/s,fill:`hsl(${al(b,[0,y.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:1/s},`v${b}`)),r&&m<150&&d.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-m/150,stroke:x?"goldenrod":"dodgerblue",strokeWidth:2/s})]},l.id+"_outline")})})});function Q_({geometry:e}){return e instanceof Hr?d.jsx(d.Fragment,{children:[...e.children,...e.ignoredChildren].map((n,t)=>d.jsx(Q_,{geometry:n},t))}):d.jsx("path",{d:e.toSimpleSvgPath()})}function J_(e){return P4(e)}function v9(){const e=B(),n=g8("userIds",()=>J_(e.getCollaborators().map(t=>t.userId)).sort(),{isEqual:(t,r)=>{var o;return t.join(",")===((o=r.join)==null?void 0:o.call(r,","))}},[e]);return G(n)}function eT(e){const n=B();return G(`latestPresence:${e}`,()=>n.getCollaborators().find(r=>r.userId===e),[n,e])??null}const x9=ar(function(){const n=v9();return d.jsx(d.Fragment,{children:n.map(t=>d.jsx(w9,{collaboratorId:t},t))})}),w9=ar(function({collaboratorId:n}){const t=B(),r=eT(n),o=P9(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 d.jsx(b9,{latestPresence:r})}),b9=ar(function({latestPresence:n}){const t=B(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=it(),l=t.getZoomLevel(),c=t.getViewportPageBounds(),{userId:u,chatMessage:h,brush:p,scribbles:f,selectedShapeIds:S,userName:m,cursor:x,color:y}=n,v=!(x.x<c.minX-12/l||x.y<c.minY-16/l||x.x>c.maxX-12/l||x.y>c.maxY-16/l);return d.jsxs(d.Fragment,{children:[p&&r?d.jsx(r,{className:"tl-collaborator__brush",brush:p,color:y,opacity:.1},u+"_brush"):null,v&&s?d.jsx(s,{className:"tl-collaborator__cursor",point:x,color:y,zoom:l,name:m!=="New User"?m:null,chatMessage:h},u+"_cursor"):i?d.jsx(i,{className:"tl-collaborator__cursor-hint",point:x,color:y,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&f.length?d.jsx(d.Fragment,{children:f.map(b=>d.jsx(o,{className:"tl-collaborator__scribble",scribble:b,color:y,zoom:l,opacity:b.color==="laser"?.5:.1},u+"_scribble_"+b.id))}):null,a&&S.map(b=>d.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:b,color:y,opacity:.5},u+"_"+b))]})});function pP(e,n){return n>e.options.collaboratorInactiveTimeoutMs?"inactive":n>e.options.collaboratorIdleTimeoutMs?"idle":"active"}function P9(e,n){const t=P.useRef((n==null?void 0:n.lastActivityTimestamp)??-1),[r,o]=P.useState(()=>pP(e,Date.now()-t.current));return P.useEffect(()=>{const s=e.timers.setInterval(()=>{o(pP(e,Date.now()-t.current))},e.options.collaboratorCheckIntervalMs);return()=>clearInterval(s)},[e]),n&&(t.current=n.lastActivityTimestamp),r}const tT=P.memo(function({id:n,shape:t,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const l=B(),{ShapeErrorFallback:c}=it(),u=P.useRef(null),h=P.useRef(null),p=P.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Os("set shape stuff",()=>{const m=l.getShape(n);if(!m)return;const x=p.current,y=l.getShapeClipPath(n)??"none";y!==x.clipPath&&(Jt(u.current,"clip-path",y),Jt(h.current,"clip-path",y),x.clipPath=y);const v=l.getShapePageTransform(n),b=oe.toCssString(v),E=l.getShapeGeometry(m).bounds;b!==x.transform&&(Jt(u.current,"transform",b),Jt(h.current,"transform",b),x.transform=b);const I=E.w%a,C=E.h%a,k=I===0?E.w:E.w+(a-I),T=C===0?E.h:E.h+(a-C);(k!==x.width||T!==x.height)&&(Jt(u.current,"width",Math.max(k,a)+"px"),Jt(u.current,"height",Math.max(T,a)+"px"),Jt(h.current,"width",Math.max(k,a)+"px"),Jt(h.current,"height",Math.max(T,a)+"px"),x.width=k,x.height=T)},[l]),Os("set opacity and z-index",()=>{const m=u.current,x=h.current;Jt(m,"opacity",i),Jt(x,"opacity",i),Jt(m,"z-index",o),Jt(x,"z-index",s)},[i,o,s]),Os("set display",()=>{if(!l.getShape(n))return;const y=l.getCulledShapes().has(n);y!==p.current.isCulled&&(Jt(u.current,"display",y?"none":"block"),Jt(h.current,"display",y?"none":"block"),p.current.isCulled=y)},[l]);const f=P.useCallback(m=>l.annotateError(m,{origin:"shape",willCrashApp:!1}),[l]);if(!t)return null;const S="fill"in t.props&&t.props.fill!=="none";return d.jsxs(d.Fragment,{children:[r.backgroundComponent&&d.jsx("div",{ref:h,className:"tl-shape tl-shape-background","data-shape-type":t.type,draggable:!1,children:d.jsx(qc,{fallback:c,onError:f,children:d.jsx(I9,{shape:t,util:r})})}),d.jsx("div",{ref:u,className:"tl-shape","data-shape-type":t.type,"data-shape-is-filled":S,draggable:!1,children:d.jsx(qc,{fallback:c,onError:f,children:d.jsx(C9,{shape:t,util:r})})})]})}),C9=P.memo(function({shape:n,util:t}){return $f("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),I9=P.memo(function({shape:n,util:t}){return $f("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 E9({className:e}){const n=B(),{Background:t,SvgDefs:r}=it(),o=P.useRef(null),s=P.useRef(null),i=P.useRef(null),a=un();g9(o),oH(),nH(),u9(o),aH(o);const l=P.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Os("position layers",function(){const{x:y,y:v,z:b}=n.getCamera();if(l.current.allowTextOutline&&n.environment.isSafari&&(a.style.setProperty("--tl-text-outline","none"),l.current.allowTextOutline=!1),l.current.allowTextOutline&&b<n.options.textShadowLod!==l.current.lodDisableTextOutline){const C=b<n.options.textShadowLod;a.style.setProperty("--tl-text-outline",C?"none":"var(--tl-text-outline-reference)"),l.current.lodDisableTextOutline=C}const E=b>=1?al(b,[1,8],[.125,.5],!0):al(b,[.1,1],[-2,.125],!0),I=`scale(${N(b)}) translate(${N(y+E)}px,${N(v+E)}px)`;Jt(s.current,"transform",I),Jt(i.current,"transform",I)},[n,a]);const c=tH(),u=G("shapeSvgDefs",()=>{const x=new Map;for(const y of gt(n.shapeUtils)){if(!y)return;const v=y.getCanvasSvgDefs();for(const{key:b,component:E}of v)x.has(b)||x.set(b,d.jsx(E,{},b))}return[...x.values()]},[n]),h=G("debug_shapes",()=>xt.hideShapes.get(),[xt]),p=G("debug_svg",()=>xt.debugSvg.get(),[xt]),f=G("debug_geometry",()=>xt.debugGeometry.get(),[xt]),S=G("isEditingAnything",()=>n.getEditingShapeId()!==null,[n]),m=G("isSelectingAnything",()=>!!n.getSelectedShapeIds().length,[n]);return d.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":S,"data-isselectinganything":m,className:ce("tl-canvas",e),"data-testid":"canvas",...c,children:[d.jsx("svg",{className:"tl-svg-context",children:d.jsxs("defs",{children:[u,d.jsx(z9,{}),d.jsx(B9,{}),r&&d.jsx(r,{})]})}),t&&d.jsx("div",{className:"tl-background__wrapper",children:d.jsx(t,{})}),d.jsx(k9,{}),d.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[d.jsx(W9,{}),d.jsx(K9,{}),h?null:p?d.jsx(R9,{}):d.jsx($9,{})]}),d.jsx("div",{className:"tl-overlays",children:d.jsxs("div",{ref:i,className:"tl-html-layer",children:[f?d.jsx(S9,{}):null,d.jsx(j9,{}),d.jsx(T9,{}),d.jsx(_9,{}),d.jsx(M9,{}),d.jsx(F9,{}),d.jsx(N9,{}),d.jsx(A9,{}),d.jsx(H9,{}),d.jsx(x9,{})]})}),d.jsx(G9,{})]})}function k9(){const e=B(),n=G("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:t,y:r,z:o}=G("camera",()=>e.getCamera(),[e]),s=G("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=it();return i&&s?d.jsx(i,{x:t,y:r,z:o,size:n}):null}function _9(){const e=B(),n=G("scribbles",()=>e.getInstanceState().scribbles,[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=it();return r&&n.length?d.jsx(d.Fragment,{children:n.map(o=>d.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:t},o.id))}):null}function T9(){const e=B(),n=G("brush",()=>e.getInstanceState().brush,[e]),{Brush:t}=it();return t&&n?d.jsx(t,{className:"tl-user-brush",brush:n}):null}function M9(){const e=B(),n=G("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:t}=it();return t&&n?d.jsx(t,{className:"tl-user-brush tl-zoom-brush",brush:n}):null}function A9(){const e=B(),n=G("snapLines",()=>e.snaps.getIndicators(),[e]),t=G("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=it();return r&&n.length>0?d.jsx(d.Fragment,{children:n.map(o=>d.jsx(r,{className:"tl-user-snapline",line:o,zoom:t},o.id))}):null}function j9(){const e=B(),n=G("handles shapeIdWithHandles",()=>{const{isReadonly:t,isChangingStyle:r}=e.getInstanceState();if(t||r)return!1;const o=e.getOnlySelectedShape();return!o||!e.getShapeHandles(o)?!1:o.id},[e]);return n?d.jsx(O9,{shapeId:n}):null}function O9({shapeId:e}){const n=B(),{Handles:t}=it(),r=G("zoomLevel",()=>n.getZoomLevel(),[n]),o=G("coarse pointer",()=>n.getInstanceState().isCoarsePointer,[n]),s=G("handles transform",()=>n.getShapePageTransform(e),[n,e]),i=G("handles",()=>{const a=n.getShapeHandles(e);if(!a)return null;const l=(o?n.options.coarseHandleRadius:n.options.handleRadius)/r*2;return a.filter(c=>c.type!=="virtual"||!a.some(u=>u!==c&&u.type==="vertex"&&w.Dist(c,u)<l)).sort(c=>c.type==="vertex"?1:-1)},[n,r,o,e]);return!t||!i||!s?null:d.jsx(t,{children:d.jsx("g",{transform:oe.toCssString(s),children:i.map(a=>d.jsx(D9,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function D9({shapeId:e,handle:n,zoom:t,isCoarse:r}){const o=d9(e,n.id),{Handle:s}=it();return s?d.jsx("g",{"aria-label":"handle",transform:`translate(${n.x}, ${n.y})`,...o,children:d.jsx(s,{shapeId:e,handle:n,zoom:t,isCoarse:r})}):null}function R9(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>Z_(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return d.jsx(d.Fragment,{children:n.map(r=>d.jsxs(P.Fragment,{children:[d.jsx(tT,{...r,dprMultiple:t}),d.jsx(U9,{id:r.id})]},r.id+"_fragment"))})}function L9(){const e=B(),n=P.useRef(new Set);return Os("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 $9(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=G("dpr multiple",()=>Z_(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return d.jsxs(d.Fragment,{children:[n.map(r=>d.jsx(tT,{...r,dprMultiple:t},r.id+"_shape")),e.environment.isSafari&&d.jsx(L9,{})]})}function F9(){const e=B(),n=G("rendering shapes",()=>e.getRenderingShapes(),[e]),t=P.useRef(new Set),r=G("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 l of a)i.add(l);if(e.isInAny("select.idle","select.editing_shape")){const l=e.getInstanceState();if(l.isHoveringCanvas&&!l.isCoarsePointer){const c=e.getHoveredShapeId();c&&i.add(c)}}}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}=it();return o?d.jsx(d.Fragment,{children:n.map(({id:s})=>d.jsx(o,{shapeId:s,hidden:!r.has(s)},s+"_indicator"))}):null}function N9(){const e=B(),{ShapeIndicator:n}=it(),t=G("hinting shape ids",()=>kx(e.getHintingShapeIds()),[e]);return!t.length||!n?null:d.jsx(d.Fragment,{children:t.map(r=>d.jsx(n,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))})}function z9(){return d.jsxs("g",{id:"cursor",children:[d.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),d.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),d.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[d.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),d.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function B9(){return d.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function U9({id:e}){const n=B(),[t,r]=P.useState(null),o=G("is in root",()=>{const s=n.getShape(e);return(s==null?void 0:s.parentId)===n.getCurrentPageId()},[n,e]);return P.useEffect(()=>{if(!o)return;let s=null;const i=oa("shape to svg",async()=>{const a=Math.random();s=a;const c=n.isShapeOfType(e,"frame")?0:10;let u=n.getShapePageBounds(e);if(!u)return;u=u.clone().expandBy(c);const h=await n.getSvgString([e],{padding:c,background:n.getInstanceState().exportBackground});if(s!==a||!h)return;const p=`data:image/svg+xml;utf8,${encodeURIComponent(h.svg)}`;r({src:p,bounds:u})});return()=>{s=null,i()}},[n,e,o]),!o||!t?null:d.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 H9(){const e=B(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=it();return!t||!r?null:d.jsx(r,{bounds:t,rotation:n})}function K9(){const e=B(),n=G("selection rotation",()=>e.getSelectionRotation(),[e]),t=G("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=it();return!t||!r?null:d.jsx(r,{bounds:t,rotation:n})}function W9(){const{OnTheCanvas:e}=it();return e?d.jsx(e,{}):null}function G9(){const e=B(),n=G("camera state",()=>e.getCameraState(),[e]);return d.jsx("div",{className:ce("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":n==="idle"})})}function V9({className:e,zoom:n,point:t,color:r,viewport:o,opacity:s=1}){const i=P.useRef(null);return Ol(i,_t(t.x,o.minX+5/n,o.maxX-5/n),_t(t.y,o.minY+5/n,o.maxY-5/n),1/n,w.Angle(o.center,t)),d.jsxs("svg",{ref:i,className:ce("tl-overlays__item",e),children:[d.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),d.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const fP=P.memo(function({className:n,zoom:t,point:r,color:o,name:s,chatMessage:i}){const a=P.useRef(null);return Ol(a,r==null?void 0:r.x,r==null?void 0:r.y,1/t),r?d.jsxs("div",{ref:a,className:ce("tl-overlays__item",n),children:[d.jsx("svg",{className:"tl-cursor",children:d.jsx("use",{href:"#cursor",color:o})}),i?d.jsxs(d.Fragment,{children:[s&&d.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),d.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&d.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function Y9({x:e,y:n,z:t,size:r}){const o=B(),{gridSteps:s}=o.options;return d.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[d.jsx("defs",{children:s.map(({min:i,mid:a,step:l},c)=>{const u=l*r*t,h=.5+e*t,p=.5+n*t,f=h>0?h%u:u+h%u,S=p>0?p%u:u+p%u,m=t<a?al(t,[i,a],[0,1]):1;return d.jsx("pattern",{id:`grid-${l}`,width:u,height:u,patternUnits:"userSpaceOnUse",children:d.jsx("circle",{className:"tl-grid-dot",cx:f,cy:S,r:1,opacity:m})},`grid-pattern-${c}`)})}),s.map(({step:i},a)=>d.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${i})`},`grid-rect-${a}`))]})}function X9({handle:e,isCoarse:n,className:t,zoom:r}){const o=B(),s=(n?o.options.coarseHandleRadius:o.options.handleRadius)/r;if(e.type==="clone"){const a=3/r,l=`M0,${-a} A${a},${a} 0 0,1 0,${a}`,c=X6.indexOf(e.id);return d.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,t),children:[d.jsx("circle",{className:"tl-handle__bg",r:s}),d.jsx("path",{className:"tl-handle__fg",d:l,transform:`rotate(${-90+90*c})`})]})}const i=(e.type==="create"&&n?3:4)/Math.max(r,.25);return d.jsxs("g",{className:ce(`tl-handle tl-handle__${e.type}`,t),children:[d.jsx("circle",{className:"tl-handle__bg",r:s}),d.jsx("circle",{className:"tl-handle__fg",r:i})]})}const q9=({children:e})=>d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}),Z9=()=>{const{Spinner:e}=it();return d.jsx(Zw,{children:e?d.jsx(e,{}):null})};function Yx(e,n=!0){const t=e.length;if(t<2)return"";let r=e[0],o=e[1];if(t===2)return`M${Ie(r)}L${Ie(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i],o=e[i+1],s+=Tn(r,o);return n?`M${Tn(e[0],e[1])}Q${Ie(e[1])}${Tn(e[1],e[2])}T${s}${Tn(e[t-1],e[0])}${Tn(e[0],e[1])}Z`:`M${Ie(e[0])}Q${Ie(e[1])}${Tn(e[1],e[2])}${e.length>3?"T":""}${s}L${Ie(e[t-1])}`}function gP({scribble:e,zoom:n,color:t,opacity:r,className:o}){return e.points.length?d.jsx("svg",{className:o&&ce("tl-overlays__item",o),children:d.jsx("path",{className:"tl-scribble",d:Yx(e.points,!1),stroke:t??`var(--color-${e.color})`,fill:"none",strokeWidth:8/n,opacity:r??e.opacity})}):null}function nT({bounds:e,rotation:n}){const t=P.useRef(null);return Ol(t,e.x,e.y,1,n),P.useLayoutEffect(()=>{const r=t.current;r&&(r.style.width=N(Math.max(1,e.width))+"px",r.style.height=N(Math.max(1,e.height))+"px")},[e.width,e.height]),d.jsx("div",{ref:t,className:"tl-selection__bg",draggable:!1})}function Q9({bounds:e,rotation:n}){const t=B(),r=P.useRef(null),o=G("only selected shape",()=>t.getOnlySelectedShape(),[t]),s=o?t.getShapeUtil(o).expandSelectionOutlinePx(o):0;return Ol(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(),d.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsx("rect",{className:ce("tl-selection__fg__outline"),width:N(e.width),height:N(e.height)})})}const J9=()=>d.jsx("div",{className:"tl-shape-error-boundary"}),e7=({shape:e,util:n})=>$f("Indicator: "+e.type,()=>n.indicator(n.editor.store.unsafeGetWithoutCapture(e.id))),t7=({editor:e,id:n})=>{const t=G("shape for indicator",()=>e.store.get(n),[e,n]),{ShapeIndicatorErrorFallback:r}=it();return!t||t.isLocked?null:d.jsx(qc,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:d.jsx(e7,{shape:t,util:e.getShapeUtil(t)},t.id)})},mP=P.memo(function({shapeId:n,className:t,color:r,hidden:o,opacity:s}){const i=B(),a=P.useRef(null);return Os("indicator transform",()=>{const l=a.current;if(!l)return;const c=i.getShapePageTransform(n);c&&l.style.setProperty("transform",c.toCssString())},[i,n]),P.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",o?"none":"block")},[o]),d.jsx("svg",{ref:a,className:ce("tl-overlays__item",t),children:d.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:d.jsx(t7,{editor:i,id:n})})})}),n7=()=>d.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function r7({points:e,zoom:n}){const t=2.5/n,r=e.reduce((p,f)=>Math.min(p,f.x),1/0),o=e.reduce((p,f)=>Math.max(p,f.x),-1/0),s=e.reduce((p,f)=>Math.min(p,f.y),1/0),i=e.reduce((p,f)=>Math.max(p,f.y),-1/0),a=e.some(p=>p.x===r&&p.y===s);let l,c,u,h;return a?(l=r,c=s,u=o,h=i):(l=r,c=i,u=o,h=s),d.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[d.jsx("line",{x1:l,y1:c,x2:u,y2:h}),e.map((p,f)=>d.jsx("g",{transform:`translate(${p.x},${p.y})`,children:d.jsx("path",{className:"tl-snap-point",d:`M ${-t},${-t} L ${t},${t} M ${-t},${t} L ${t},${-t}`})},f))]})}function o7({gaps:e,direction:n,zoom:t}){const r=3.5/t;let o=[-1/0,1/0],s=null;const i=n==="horizontal";for(const l of e){if(s=Or(o[0],o[1],i?l.startEdge[0].y:l.startEdge[0].x,i?l.startEdge[1].y:l.startEdge[1].x),s)o=s;else continue;if(s=Or(o[0],o[1],i?l.endEdge[0].y:l.endEdge[0].x,i?l.endEdge[1].y:l.endEdge[1].x),s)o=s;else continue}if(o===null)return null;const a=(o[0]+o[1])/2;return d.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:l,endEdge:c},u)=>d.jsx(P.Fragment,{children:i?d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),d.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),d.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),d.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):d.jsxs(d.Fragment,{children:[d.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),d.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),d.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),d.jsx("line",{x1:a-r,y1:(l[0].y+c[0].y)/2,x2:a+r,y2:(l[0].y+c[0].y)/2})]})},u))})}function s7({className:e,line:n,zoom:t}){return d.jsx("svg",{className:ce("tl-overlays__item",e),children:n.type==="points"?d.jsx(r7,{...n,zoom:t}):n.type==="gaps"?d.jsx(o7,{...n,zoom:t}):null})}function Xx(){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const i7=()=>null;function rT(e,n){const t=P.useRef(e);return n(e,t.current)?t.current:(t.current=e,e)}function Ac(e){return rT(e,E4)}function qx(e){return rT(e,Ek)}const oT=P.createContext(null);function a7({overrides:e={},children:n}){const t=qx(e);return d.jsx(oT.Provider,{value:P.useMemo(()=>({Background:U6,SvgDefs:i7,Brush:vm,ZoomBrush:vm,CollaboratorBrush:vm,Cursor:fP,CollaboratorCursor:fP,CollaboratorHint:V9,CollaboratorShapeIndicator:mP,Grid:Y9,Scribble:gP,SnapIndicator:s7,Handles:q9,Handle:X9,CollaboratorScribble:gP,ErrorFallback:iT,ShapeErrorFallback:J9,ShapeIndicatorErrorFallback:n7,Spinner:Xx,SelectionBackground:nT,SelectionForeground:Q9,ShapeIndicator:mP,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:E9,LoadingScreen:Z9,...t}),[t]),children:n})}function it(){const e=P.useContext(oT);if(!e)throw new Error("useEditorComponents must be used inside of <EditorComponentsProvider />");return e}const Zx={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 sT(){Zx.hardReset()}function l7(){Zx.refreshPage()}const c7="https://github.com/tldraw/tldraw/issues/new",iT=({error:e,editor:n})=>{const t=P.useRef(null),[r,o]=P.useState(!1),[s,i]=P.useState(!1),[a,l]=P.useState(!1);let c=null;try{c=it().Canvas??null}catch{}const u=e instanceof Error?e.message:String(e),h=e instanceof Error?e.stack:null,p=G("isDarkMode",()=>{try{if(n)return n.user.getIsDarkMode()}catch{}return null},[n]),[f,S]=P.useState(null);P.useLayoutEffect(()=>{var I;p!==null&&S(p);let b=(I=t.current)==null?void 0:I.parentElement,E=!1;for(;b;){if(b.classList.contains("tl-theme__dark")||b.classList.contains("tl-theme__light")){E=!0;break}b=b.parentElement}if(E){S(null);return}S(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),P.useEffect(()=>{if(s){const b=n==null?void 0:n.timers.setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(b)}},[s,n]);const m=()=>{const b=document.createElement("textarea");b.value=h??u,document.body.appendChild(b),b.select(),document.execCommand("copy"),b.remove(),i(!0)},x=()=>{l7()},y=async()=>{sT()},v=new URL(c7);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
|
|
57
|
-
|
|
58
|
-
\`\`\`js
|
|
59
|
-
${h??u}
|
|
60
|
-
\`\`\`
|
|
61
|
-
|
|
62
|
-
My browser: ${navigator.userAgent}`),d.jsxs("div",{ref:t,className:ce("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[d.jsx("div",{className:"tl-error-boundary__overlay"}),n&&d.jsx(R_,{onError:xp,fallback:()=>null,children:d.jsx(Uf.Provider,{value:n,children:d.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?d.jsx(c,{}):null})})}),d.jsx("div",{className:ce("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Are you sure?"}),d.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),d.jsx("button",{className:"tl-error-boundary__reset",onClick:y,children:"Reset data"})]})]}):d.jsxs(d.Fragment,{children:[d.jsx("h2",{children:"Something's gone wrong."}),d.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",d.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",d.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&d.jsxs(d.Fragment,{children:["Message:",d.jsx("h4",{children:d.jsx("code",{children:u})}),"Stack trace:",d.jsxs("div",{className:"tl-error-boundary__content__error",children:[d.jsx("pre",{children:d.jsx("code",{children:h??u})}),d.jsx("button",{onClick:m,children:s?"Copied!":"Copy"})]})]}),d.jsxs("div",{className:"tl-error-boundary__content__actions",children:[d.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),d.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[d.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),d.jsx("button",{className:"tl-error-boundary__refresh",onClick:x,children:"Refresh Page"})]})]})]})})]})};function ot(){return Au()}const aT="TLDRAW_USER_DATA_v3",lT=Se({id:pe,name:pe.nullable().optional(),locale:pe.nullable().optional(),color:pe.nullable().optional(),colorScheme:zf("light","dark","system").optional(),animationSpeed:de.nullable().optional(),edgeScrollSpeed:de.nullable().optional(),isSnapMode:we.nullable().optional(),isWrapMode:we.nullable().optional(),isDynamicSizeMode:we.nullable().optional()}),xs={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5,AddDynamicSizeMode:6,AllowSystemColorScheme:7},Qx=Math.max(...Object.values(xs));function u7(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=Qx}const yP=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function d7(){return yP[Math.floor(Math.random()*yP.length)]}function h7(){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:$6(),color:d7(),edgeScrollSpeed:1,animationSpeed:h7()?0:1,isSnapMode:!1,isWrapMode:!1,isDynamicSizeMode:!1});function Cm(){return{id:ot()}}function cT(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return Cm();const n=rt(e);u7(n);try{return lT.validate(n.user)}catch{return Cm()}}function p7(){const e=JSON.parse(Mx(aT)||"null")??null;return cT(e)}const Zc=Mt("globalUserData",null);function f7(){Ax(aT,JSON.stringify({version:Qx,user:Zc.get()}))}function g7(e){lT.validate(e),Zc.set(e),f7(),y7()}const m7=typeof process<"u"&&!1,Xa=typeof BroadcastChannel<"u"&&!m7?new BroadcastChannel("tldraw-user-sync"):null;Xa==null||Xa.addEventListener("message",e=>{const n=e.data;(n==null?void 0:n.type)===dT&&(n==null?void 0:n.origin)!==uT()&&Zc.set(cT(n.data))});let Im=null;function uT(){return Im===null&&(Im=ot()),Im}const dT="tldraw-user-preferences-change";function y7(){Xa==null||Xa.postMessage({type:dT,origin:uT(),data:{user:hT(),version:Qx}})}function hT(){let e=Zc.get();return e||(e=p7(),Zc.set(e)),e}function pT(e={}){return{derivePresenceState:e.derivePresenceState??(()=>V("presence",()=>null)),userPreferences:e.userPreferences??V("userPreferences",()=>hT()),setUserPreferences:e.setUserPreferences??g7}}var fT={exports:{}};(function(e){var n=Object.prototype.hasOwnProperty,t="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(t=!1));function o(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,h,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,h||l,p),S=t?t+c:c;return l._events[S]?l._events[S].fn?l._events[S]=[l._events[S],f]:l._events[S].push(f):(l._events[S]=f,l._eventsCount++),l}function i(l,c){--l._eventsCount===0?l._events=new r:delete l._events[c]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var c=[],u,h;if(this._eventsCount===0)return c;for(h in u=this._events)n.call(u,h)&&c.push(t?h.slice(1):h);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=t?t+c:c,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var p=0,f=h.length,S=new Array(f);p<f;p++)S[p]=h[p].fn;return S},a.prototype.listenerCount=function(c){var u=t?t+c:c,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(c,u,h,p,f,S){var m=t?t+c:c;if(!this._events[m])return!1;var x=this._events[m],y=arguments.length,v,b;if(x.fn){switch(x.once&&this.removeListener(c,x.fn,void 0,!0),y){case 1:return x.fn.call(x.context),!0;case 2:return x.fn.call(x.context,u),!0;case 3:return x.fn.call(x.context,u,h),!0;case 4:return x.fn.call(x.context,u,h,p),!0;case 5:return x.fn.call(x.context,u,h,p,f),!0;case 6:return x.fn.call(x.context,u,h,p,f,S),!0}for(b=1,v=new Array(y-1);b<y;b++)v[b-1]=arguments[b];x.fn.apply(x.context,v)}else{var E=x.length,I;for(b=0;b<E;b++)switch(x[b].once&&this.removeListener(c,x[b].fn,void 0,!0),y){case 1:x[b].fn.call(x[b].context);break;case 2:x[b].fn.call(x[b].context,u);break;case 3:x[b].fn.call(x[b].context,u,h);break;case 4:x[b].fn.call(x[b].context,u,h,p);break;default:if(!v)for(I=1,v=new Array(y-1);I<y;I++)v[I-1]=arguments[I];x[b].fn.apply(x[b].context,v)}}return!0},a.prototype.on=function(c,u,h){return s(this,c,u,h,!1)},a.prototype.once=function(c,u,h){return s(this,c,u,h,!0)},a.prototype.removeListener=function(c,u,h,p){var f=t?t+c:c;if(!this._events[f])return this;if(!u)return i(this,f),this;var S=this._events[f];if(S.fn)S.fn===u&&(!p||S.once)&&(!h||S.context===h)&&i(this,f);else{for(var m=0,x=[],y=S.length;m<y;m++)(S[m].fn!==u||p&&!S[m].once||h&&S[m].context!==h)&&x.push(S[m]);x.length?this._events[f]=x.length===1?x[0]:x:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=t?t+c:c,this._events[u]&&i(this,u)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=t,a.EventEmitter=a,e.exports=a})(fT);var S7=fT.exports;const v7=ei(S7);var gT={exports:{}},cr={},mT={exports:{}},yT={};/**
|
|
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(z,U){var X=z.length;z.push(U);e:for(;0<X;){var J=X-1>>>1,le=z[J];if(0<o(le,U))z[J]=U,z[X]=le,X=J;else break e}}function t(z){return z.length===0?null:z[0]}function r(z){if(z.length===0)return null;var U=z[0],X=z.pop();if(X!==U){z[0]=X;e:for(var J=0,le=z.length,ye=le>>>1;J<ye;){var Me=2*(J+1)-1,ae=z[Me],Ue=Me+1,je=z[Ue];if(0>o(ae,X))Ue<le&&0>o(je,ae)?(z[J]=je,z[Ue]=X,J=Ue):(z[J]=ae,z[Me]=X,J=Me);else if(Ue<le&&0>o(je,X))z[J]=je,z[Ue]=X,J=Ue;else break e}}return U}function o(z,U){var X=z.sortIndex-U.sortIndex;return X!==0?X:z.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,h=null,p=3,f=!1,S=!1,m=!1,x=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 b(z){for(var U=t(c);U!==null;){if(U.callback===null)r(c);else if(U.startTime<=z)r(c),U.sortIndex=U.expirationTime,n(l,U);else break;U=t(c)}}function E(z){if(m=!1,b(z),!S)if(t(l)!==null)S=!0,W(I);else{var U=t(c);U!==null&&K(E,U.startTime-z)}}function I(z,U){S=!1,m&&(m=!1,y(T),T=-1),f=!0;var X=p;try{for(b(U),h=t(l);h!==null&&(!(h.expirationTime>U)||z&&!A());){var J=h.callback;if(typeof J=="function"){h.callback=null,p=h.priorityLevel;var le=J(h.expirationTime<=U);U=e.unstable_now(),typeof le=="function"?h.callback=le:h===t(l)&&r(l),b(U)}else r(l);h=t(l)}if(h!==null)var ye=!0;else{var Me=t(c);Me!==null&&K(E,Me.startTime-U),ye=!1}return ye}finally{h=null,p=X,f=!1}}var C=!1,k=null,T=-1,O=5,_=-1;function A(){return!(e.unstable_now()-_<O)}function L(){if(k!==null){var z=e.unstable_now();_=z;var U=!0;try{U=k(!0,z)}finally{U?j():(C=!1,k=null)}}else C=!1}var j;if(typeof v=="function")j=function(){v(L)};else if(typeof MessageChannel<"u"){var R=new MessageChannel,F=R.port2;R.port1.onmessage=L,j=function(){F.postMessage(null)}}else j=function(){x(L,0)};function W(z){k=z,C||(C=!0,j())}function K(z,U){T=x(function(){z(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(z){z.callback=null},e.unstable_continueExecution=function(){S||f||(S=!0,W(I))},e.unstable_forceFrameRate=function(z){0>z||125<z?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):O=0<z?Math.floor(1e3/z):5},e.unstable_getCurrentPriorityLevel=function(){return p},e.unstable_getFirstCallbackNode=function(){return t(l)},e.unstable_next=function(z){switch(p){case 1:case 2:case 3:var U=3;break;default:U=p}var X=p;p=U;try{return z()}finally{p=X}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(z,U){switch(z){case 1:case 2:case 3:case 4:case 5:break;default:z=3}var X=p;p=z;try{return U()}finally{p=X}},e.unstable_scheduleCallback=function(z,U,X){var J=e.unstable_now();switch(typeof X=="object"&&X!==null?(X=X.delay,X=typeof X=="number"&&0<X?J+X:J):X=J,z){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=X+le,z={id:u++,callback:U,priorityLevel:z,startTime:X,expirationTime:le,sortIndex:-1},X>J?(z.sortIndex=X,n(c,z),t(l)===null&&z===t(c)&&(m?(y(T),T=-1):m=!0,K(E,X-J))):(z.sortIndex=le,n(l,z),S||f||(S=!0,W(I))),z},e.unstable_shouldYield=A,e.unstable_wrapCallback=function(z){var U=p;return function(){var X=p;p=U;try{return z.apply(this,arguments)}finally{p=X}}}})(yT);mT.exports=yT;var x7=mT.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 w7=P,ir=x7;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 ST=new Set,Qc={};function sa(e,n){cl(e,n),cl(e+"Capture",n)}function cl(e,n){for(Qc[e]=n,e=0;e<n.length;e++)ST.add(n[e])}var qo=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),CS=Object.prototype.hasOwnProperty,b7=/^[: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]*$/,SP={},vP={};function P7(e){return CS.call(vP,e)?!0:CS.call(SP,e)?!1:b7.test(e)?vP[e]=!0:(SP[e]=!0,!1)}function C7(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 I7(e,n,t,r){if(n===null||typeof n>"u"||C7(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 bn(e,n,t,r,o,s,i){this.acceptsBooleans=n===2||n===3||n===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=t,this.propertyName=e,this.type=n,this.sanitizeURL=s,this.removeEmptyString=i}var Gt={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Gt[e]=new bn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var n=e[0];Gt[n]=new bn(n,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Gt[e]=new bn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Gt[e]=new bn(e,2,!1,e,null,!1,!1)});"allowFullScreen async autoFocus autoPlay controls default defer disabled disablePictureInPicture disableRemotePlayback formNoValidate hidden loop noModule noValidate open playsInline readOnly required reversed scoped seamless itemScope".split(" ").forEach(function(e){Gt[e]=new bn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Gt[e]=new bn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Gt[e]=new bn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Gt[e]=new bn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Gt[e]=new bn(e,5,!1,e.toLowerCase(),null,!1,!1)});var Jx=/[\-:]([a-z])/g;function ew(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(Jx,ew);Gt[n]=new bn(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(Jx,ew);Gt[n]=new bn(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(Jx,ew);Gt[n]=new bn(n,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Gt[e]=new bn(e,1,!1,e.toLowerCase(),null,!1,!1)});Gt.xlinkHref=new bn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Gt[e]=new bn(e,1,!1,e.toLowerCase(),null,!0,!0)});function tw(e,n,t,r){var o=Gt.hasOwnProperty(n)?Gt[n]:null;(o!==null?o.type!==0:r||!(2<n.length)||n[0]!=="o"&&n[0]!=="O"||n[1]!=="n"&&n[1]!=="N")&&(I7(n,t,o,r)&&(t=null),r||o===null?P7(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=w7.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,Cd=Symbol.for("react.element"),Aa=Symbol.for("react.portal"),ja=Symbol.for("react.fragment"),nw=Symbol.for("react.strict_mode"),IS=Symbol.for("react.profiler"),vT=Symbol.for("react.provider"),xT=Symbol.for("react.context"),rw=Symbol.for("react.forward_ref"),ES=Symbol.for("react.suspense"),kS=Symbol.for("react.suspense_list"),ow=Symbol.for("react.memo"),bs=Symbol.for("react.lazy"),wT=Symbol.for("react.offscreen"),xP=Symbol.iterator;function ec(e){return e===null||typeof e!="object"?null:(e=xP&&e[xP]||e["@@iterator"],typeof e=="function"?e:null)}var pt=Object.assign,Em;function xc(e){if(Em===void 0)try{throw Error()}catch(t){var n=t.stack.trim().match(/\n( *(at )?)/);Em=n&&n[1]||""}return`
|
|
79
|
-
`+Em+e}var km=!1;function _m(e,n){if(!e||km)return"";km=!0;var t=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(n)if(n=function(){throw Error()},Object.defineProperty(n.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(n,[])}catch(c){var r=c}Reflect.construct(e,[],n)}else{try{n.call()}catch(c){r=c}e.call(n.prototype)}else{try{throw Error()}catch(c){r=c}e()}}catch(c){if(c&&r&&typeof c.stack=="string"){for(var o=c.stack.split(`
|
|
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 l=`
|
|
82
|
-
`+o[i].replace(" at new "," at ");return e.displayName&&l.includes("<anonymous>")&&(l=l.replace("<anonymous>",e.displayName)),l}while(1<=i&&0<=a);break}}}finally{km=!1,Error.prepareStackTrace=t}return(e=e?e.displayName||e.name:"")?xc(e):""}function E7(e){switch(e.tag){case 5:return xc(e.type);case 16:return xc("Lazy");case 13:return xc("Suspense");case 19:return xc("SuspenseList");case 0:case 2:case 15:return e=_m(e.type,!1),e;case 11:return e=_m(e.type.render,!1),e;case 1:return e=_m(e.type,!0),e;default:return""}}function _S(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 ja:return"Fragment";case Aa:return"Portal";case IS:return"Profiler";case nw:return"StrictMode";case ES:return"Suspense";case kS:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case xT:return(e.displayName||"Context")+".Consumer";case vT:return(e._context.displayName||"Context")+".Provider";case rw:var n=e.render;return e=e.displayName,e||(e=n.displayName||n.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case ow:return n=e.displayName||null,n!==null?n:_S(e.type)||"Memo";case bs:n=e._payload,e=e._init;try{return _S(e(n))}catch{}}return null}function k7(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 _S(n);case 8:return n===nw?"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 bT(e){var n=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(n==="checkbox"||n==="radio")}function _7(e){var n=bT(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 Id(e){e._valueTracker||(e._valueTracker=_7(e))}function PT(e){if(!e)return!1;var n=e._valueTracker;if(!n)return!0;var t=n.getValue(),r="";return e&&(r=bT(e)?e.checked?"true":"false":e.value),e=r,e!==t?(n.setValue(e),!0):!1}function zp(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 TS(e,n){var t=n.checked;return pt({},n,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:t??e._wrapperState.initialChecked})}function wP(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 CT(e,n){n=n.checked,n!=null&&tw(e,"checked",n,!1)}function MS(e,n){CT(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")?AS(e,n.type,t):n.hasOwnProperty("defaultValue")&&AS(e,n.type,Gs(n.defaultValue)),n.checked==null&&n.defaultChecked!=null&&(e.defaultChecked=!!n.defaultChecked)}function bP(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 AS(e,n,t){(n!=="number"||zp(e.ownerDocument)!==e)&&(t==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+t&&(e.defaultValue=""+t))}var wc=Array.isArray;function qa(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 jS(e,n){if(n.dangerouslySetInnerHTML!=null)throw Error(q(91));return pt({},n,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function PP(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(wc(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 CP(e){var n=e.textContent;n===e._wrapperState.initialValue&&n!==""&&n!==null&&(e.value=n)}function ET(e){switch(e){case"svg":return"http://www.w3.org/2000/svg";case"math":return"http://www.w3.org/1998/Math/MathML";default:return"http://www.w3.org/1999/xhtml"}}function OS(e,n){return e==null||e==="http://www.w3.org/1999/xhtml"?ET(n):e==="http://www.w3.org/2000/svg"&&n==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var Ed,kT=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(Ed=Ed||document.createElement("div"),Ed.innerHTML="<svg>"+n.valueOf().toString()+"</svg>",n=Ed.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;n.firstChild;)e.appendChild(n.firstChild)}});function Jc(e,n){if(n){var t=e.firstChild;if(t&&t===e.lastChild&&t.nodeType===3){t.nodeValue=n;return}}e.textContent=n}var jc={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},T7=["Webkit","ms","Moz","O"];Object.keys(jc).forEach(function(e){T7.forEach(function(n){n=n+e.charAt(0).toUpperCase()+e.substring(1),jc[n]=jc[e]})});function _T(e,n,t){return n==null||typeof n=="boolean"||n===""?"":t||typeof n!="number"||n===0||jc.hasOwnProperty(e)&&jc[e]?(""+n).trim():n+"px"}function TT(e,n){e=e.style;for(var t in n)if(n.hasOwnProperty(t)){var r=t.indexOf("--")===0,o=_T(t,n[t],r);t==="float"&&(t="cssFloat"),r?e.setProperty(t,o):e[t]=o}}var M7=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 DS(e,n){if(n){if(M7[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 RS(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 LS=null;function sw(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var $S=null,Za=null,Qa=null;function IP(e){if(e=zu(e)){if(typeof $S!="function")throw Error(q(280));var n=e.stateNode;n&&(n=Vf(n),$S(e.stateNode,e.type,n))}}function MT(e){Za?Qa?Qa.push(e):Qa=[e]:Za=e}function AT(){if(Za){var e=Za,n=Qa;if(Qa=Za=null,IP(e),n)for(e=0;e<n.length;e++)IP(n[e])}}function jT(e,n){return e(n)}function OT(){}var Tm=!1;function DT(e,n,t){if(Tm)return e(n,t);Tm=!0;try{return jT(e,n,t)}finally{Tm=!1,(Za!==null||Qa!==null)&&(OT(),AT())}}function eu(e,n){var t=e.stateNode;if(t===null)return null;var r=Vf(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 FS=!1;if(qo)try{var tc={};Object.defineProperty(tc,"passive",{get:function(){FS=!0}}),window.addEventListener("test",tc,tc),window.removeEventListener("test",tc,tc)}catch{FS=!1}function A7(e,n,t,r,o,s,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{n.apply(t,c)}catch(u){this.onError(u)}}var Oc=!1,Bp=null,Up=!1,NS=null,j7={onError:function(e){Oc=!0,Bp=e}};function O7(e,n,t,r,o,s,i,a,l){Oc=!1,Bp=null,A7.apply(j7,arguments)}function D7(e,n,t,r,o,s,i,a,l){if(O7.apply(this,arguments),Oc){if(Oc){var c=Bp;Oc=!1,Bp=null}else throw Error(q(198));Up||(Up=!0,NS=c)}}function ia(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 RT(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 EP(e){if(ia(e)!==e)throw Error(q(188))}function R7(e){var n=e.alternate;if(!n){if(n=ia(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 EP(o),e;if(s===r)return EP(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 LT(e){return e=R7(e),e!==null?$T(e):null}function $T(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var n=$T(e);if(n!==null)return n;e=e.sibling}return null}var FT=ir.unstable_scheduleCallback,kP=ir.unstable_cancelCallback,L7=ir.unstable_shouldYield,$7=ir.unstable_requestPaint,wt=ir.unstable_now,F7=ir.unstable_getCurrentPriorityLevel,iw=ir.unstable_ImmediatePriority,NT=ir.unstable_UserBlockingPriority,Hp=ir.unstable_NormalPriority,N7=ir.unstable_LowPriority,zT=ir.unstable_IdlePriority,Hf=null,fo=null;function z7(e){if(fo&&typeof fo.onCommitFiberRoot=="function")try{fo.onCommitFiberRoot(Hf,e,void 0,(e.current.flags&128)===128)}catch{}}var zr=Math.clz32?Math.clz32:H7,B7=Math.log,U7=Math.LN2;function H7(e){return e>>>=0,e===0?32:31-(B7(e)/U7|0)|0}var kd=64,_d=4194304;function bc(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 Kp(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=bc(a):(s&=i,s!==0&&(r=bc(s)))}else i=t&~o,i!==0?r=bc(i):s!==0&&(r=bc(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-zr(n),o=1<<t,r|=e[t],n&=~o;return r}function K7(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 W7(e,n){for(var t=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-zr(s),a=1<<i,l=o[i];l===-1?(!(a&t)||a&r)&&(o[i]=K7(a,n)):l<=n&&(e.expiredLanes|=a),s&=~a}}function zS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function BT(){var e=kd;return kd<<=1,!(kd&4194240)&&(kd=64),e}function Mm(e){for(var n=[],t=0;31>t;t++)n.push(e);return n}function Fu(e,n,t){e.pendingLanes|=n,n!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,n=31-zr(n),e[n]=t}function G7(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-zr(t),s=1<<o;n[o]=0,r[o]=-1,e[o]=-1,t&=~s}}function aw(e,n){var t=e.entangledLanes|=n;for(e=e.entanglements;t;){var r=31-zr(t),o=1<<r;o&n|e[r]&n&&(e[r]|=n),t&=~o}}var Fe=0;function UT(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var HT,lw,KT,WT,GT,BS=!1,Td=[],Ls=null,$s=null,Fs=null,tu=new Map,nu=new Map,Is=[],V7="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 _P(e,n){switch(e){case"focusin":case"focusout":Ls=null;break;case"dragenter":case"dragleave":$s=null;break;case"mouseover":case"mouseout":Fs=null;break;case"pointerover":case"pointerout":tu.delete(n.pointerId);break;case"gotpointercapture":case"lostpointercapture":nu.delete(n.pointerId)}}function nc(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=zu(n),n!==null&&lw(n)),e):(e.eventSystemFlags|=r,n=e.targetContainers,o!==null&&n.indexOf(o)===-1&&n.push(o),e)}function Y7(e,n,t,r,o){switch(n){case"focusin":return Ls=nc(Ls,e,n,t,r,o),!0;case"dragenter":return $s=nc($s,e,n,t,r,o),!0;case"mouseover":return Fs=nc(Fs,e,n,t,r,o),!0;case"pointerover":var s=o.pointerId;return tu.set(s,nc(tu.get(s)||null,e,n,t,r,o)),!0;case"gotpointercapture":return s=o.pointerId,nu.set(s,nc(nu.get(s)||null,e,n,t,r,o)),!0}return!1}function VT(e){var n=Ii(e.target);if(n!==null){var t=ia(n);if(t!==null){if(n=t.tag,n===13){if(n=RT(t),n!==null){e.blockedOn=n,GT(e.priority,function(){KT(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 wh(e){if(e.blockedOn!==null)return!1;for(var n=e.targetContainers;0<n.length;){var t=US(e.domEventName,e.eventSystemFlags,n[0],e.nativeEvent);if(t===null){t=e.nativeEvent;var r=new t.constructor(t.type,t);LS=r,t.target.dispatchEvent(r),LS=null}else return n=zu(t),n!==null&&lw(n),e.blockedOn=t,!1;n.shift()}return!0}function TP(e,n,t){wh(e)&&t.delete(n)}function X7(){BS=!1,Ls!==null&&wh(Ls)&&(Ls=null),$s!==null&&wh($s)&&($s=null),Fs!==null&&wh(Fs)&&(Fs=null),tu.forEach(TP),nu.forEach(TP)}function rc(e,n){e.blockedOn===n&&(e.blockedOn=null,BS||(BS=!0,ir.unstable_scheduleCallback(ir.unstable_NormalPriority,X7)))}function ru(e){function n(o){return rc(o,e)}if(0<Td.length){rc(Td[0],e);for(var t=1;t<Td.length;t++){var r=Td[t];r.blockedOn===e&&(r.blockedOn=null)}}for(Ls!==null&&rc(Ls,e),$s!==null&&rc($s,e),Fs!==null&&rc(Fs,e),tu.forEach(n),nu.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);)VT(t),t.blockedOn===null&&Is.shift()}var Ja=is.ReactCurrentBatchConfig,Wp=!0;function q7(e,n,t,r){var o=Fe,s=Ja.transition;Ja.transition=null;try{Fe=1,cw(e,n,t,r)}finally{Fe=o,Ja.transition=s}}function Z7(e,n,t,r){var o=Fe,s=Ja.transition;Ja.transition=null;try{Fe=4,cw(e,n,t,r)}finally{Fe=o,Ja.transition=s}}function cw(e,n,t,r){if(Wp){var o=US(e,n,t,r);if(o===null)zm(e,n,r,Gp,t),_P(e,r);else if(Y7(o,e,n,t,r))r.stopPropagation();else if(_P(e,r),n&4&&-1<V7.indexOf(e)){for(;o!==null;){var s=zu(o);if(s!==null&&HT(s),s=US(e,n,t,r),s===null&&zm(e,n,r,Gp,t),s===o)break;o=s}o!==null&&r.stopPropagation()}else zm(e,n,r,null,t)}}var Gp=null;function US(e,n,t,r){if(Gp=null,e=sw(r),e=Ii(e),e!==null)if(n=ia(e),n===null)e=null;else if(t=n.tag,t===13){if(e=RT(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 Gp=e,null}function YT(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(F7()){case iw:return 1;case NT:return 4;case Hp:case N7:return 16;case zT:return 536870912;default:return 16}default:return 16}}var _s=null,uw=null,bh=null;function XT(){if(bh)return bh;var e,n=uw,t=n.length,r,o="value"in _s?_s.value:_s.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 bh=o.slice(e,1<r?1-r:void 0)}function Ph(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 Md(){return!0}function MP(){return!1}function ur(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)?Md:MP,this.isPropagationStopped=MP,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=Md)},stopPropagation:function(){var t=this.nativeEvent;t&&(t.stopPropagation?t.stopPropagation():typeof t.cancelBubble!="unknown"&&(t.cancelBubble=!0),this.isPropagationStopped=Md)},persist:function(){},isPersistent:Md}),n}var Dl={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},dw=ur(Dl),Nu=pt({},Dl,{view:0,detail:0}),Q7=ur(Nu),Am,jm,oc,Kf=pt({},Nu,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:hw,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!==oc&&(oc&&e.type==="mousemove"?(Am=e.screenX-oc.screenX,jm=e.screenY-oc.screenY):jm=Am=0,oc=e),Am)},movementY:function(e){return"movementY"in e?e.movementY:jm}}),AP=ur(Kf),J7=pt({},Kf,{dataTransfer:0}),eK=ur(J7),tK=pt({},Nu,{relatedTarget:0}),Om=ur(tK),nK=pt({},Dl,{animationName:0,elapsedTime:0,pseudoElement:0}),rK=ur(nK),oK=pt({},Dl,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),sK=ur(oK),iK=pt({},Dl,{data:0}),jP=ur(iK),aK={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},lK={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"},cK={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function uK(e){var n=this.nativeEvent;return n.getModifierState?n.getModifierState(e):(e=cK[e])?!!n[e]:!1}function hw(){return uK}var dK=pt({},Nu,{key:function(e){if(e.key){var n=aK[e.key]||e.key;if(n!=="Unidentified")return n}return e.type==="keypress"?(e=Ph(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?lK[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:hw,charCode:function(e){return e.type==="keypress"?Ph(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?Ph(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),hK=ur(dK),pK=pt({},Kf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),OP=ur(pK),fK=pt({},Nu,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:hw}),gK=ur(fK),mK=pt({},Dl,{propertyName:0,elapsedTime:0,pseudoElement:0}),yK=ur(mK),SK=pt({},Kf,{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}),vK=ur(SK),xK=[9,13,27,32],pw=qo&&"CompositionEvent"in window,Dc=null;qo&&"documentMode"in document&&(Dc=document.documentMode);var wK=qo&&"TextEvent"in window&&!Dc,qT=qo&&(!pw||Dc&&8<Dc&&11>=Dc),DP=" ",RP=!1;function ZT(e,n){switch(e){case"keyup":return xK.indexOf(n.keyCode)!==-1;case"keydown":return n.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function QT(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var Oa=!1;function bK(e,n){switch(e){case"compositionend":return QT(n);case"keypress":return n.which!==32?null:(RP=!0,DP);case"textInput":return e=n.data,e===DP&&RP?null:e;default:return null}}function PK(e,n){if(Oa)return e==="compositionend"||!pw&&ZT(e,n)?(e=XT(),bh=uw=_s=null,Oa=!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 qT&&n.locale!=="ko"?null:n.data;default:return null}}var CK={color:!0,date:!0,datetime:!0,"datetime-local":!0,email:!0,month:!0,number:!0,password:!0,range:!0,search:!0,tel:!0,text:!0,time:!0,url:!0,week:!0};function LP(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n==="input"?!!CK[e.type]:n==="textarea"}function JT(e,n,t,r){MT(r),n=Vp(n,"onChange"),0<n.length&&(t=new dw("onChange","change",null,t,r),e.push({event:t,listeners:n}))}var Rc=null,ou=null;function IK(e){uM(e,0)}function Wf(e){var n=La(e);if(PT(n))return e}function EK(e,n){if(e==="change")return n}var eM=!1;if(qo){var Dm;if(qo){var Rm="oninput"in document;if(!Rm){var $P=document.createElement("div");$P.setAttribute("oninput","return;"),Rm=typeof $P.oninput=="function"}Dm=Rm}else Dm=!1;eM=Dm&&(!document.documentMode||9<document.documentMode)}function FP(){Rc&&(Rc.detachEvent("onpropertychange",tM),ou=Rc=null)}function tM(e){if(e.propertyName==="value"&&Wf(ou)){var n=[];JT(n,ou,e,sw(e)),DT(IK,n)}}function kK(e,n,t){e==="focusin"?(FP(),Rc=n,ou=t,Rc.attachEvent("onpropertychange",tM)):e==="focusout"&&FP()}function _K(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return Wf(ou)}function TK(e,n){if(e==="click")return Wf(n)}function MK(e,n){if(e==="input"||e==="change")return Wf(n)}function AK(e,n){return e===n&&(e!==0||1/e===1/n)||e!==e&&n!==n}var Kr=typeof Object.is=="function"?Object.is:AK;function su(e,n){if(Kr(e,n))return!0;if(typeof e!="object"||e===null||typeof n!="object"||n===null)return!1;var t=Object.keys(e),r=Object.keys(n);if(t.length!==r.length)return!1;for(r=0;r<t.length;r++){var o=t[r];if(!CS.call(n,o)||!Kr(e[o],n[o]))return!1}return!0}function NP(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function zP(e,n){var t=NP(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=NP(t)}}function nM(e,n){return e&&n?e===n?!0:e&&e.nodeType===3?!1:n&&n.nodeType===3?nM(e,n.parentNode):"contains"in e?e.contains(n):e.compareDocumentPosition?!!(e.compareDocumentPosition(n)&16):!1:!1}function rM(){for(var e=window,n=zp();n instanceof e.HTMLIFrameElement;){try{var t=typeof n.contentWindow.location.href=="string"}catch{t=!1}if(t)e=n.contentWindow;else break;n=zp(e.document)}return n}function fw(e){var n=e&&e.nodeName&&e.nodeName.toLowerCase();return n&&(n==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||n==="textarea"||e.contentEditable==="true")}function jK(e){var n=rM(),t=e.focusedElem,r=e.selectionRange;if(n!==t&&t&&t.ownerDocument&&nM(t.ownerDocument.documentElement,t)){if(r!==null&&fw(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=zP(t,s);var i=zP(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 OK=qo&&"documentMode"in document&&11>=document.documentMode,Da=null,HS=null,Lc=null,KS=!1;function BP(e,n,t){var r=t.window===t?t.document:t.nodeType===9?t:t.ownerDocument;KS||Da==null||Da!==zp(r)||(r=Da,"selectionStart"in r&&fw(r)?r={start:r.selectionStart,end:r.selectionEnd}:(r=(r.ownerDocument&&r.ownerDocument.defaultView||window).getSelection(),r={anchorNode:r.anchorNode,anchorOffset:r.anchorOffset,focusNode:r.focusNode,focusOffset:r.focusOffset}),Lc&&su(Lc,r)||(Lc=r,r=Vp(HS,"onSelect"),0<r.length&&(n=new dw("onSelect","select",null,n,t),e.push({event:n,listeners:r}),n.target=Da)))}function Ad(e,n){var t={};return t[e.toLowerCase()]=n.toLowerCase(),t["Webkit"+e]="webkit"+n,t["Moz"+e]="moz"+n,t}var Ra={animationend:Ad("Animation","AnimationEnd"),animationiteration:Ad("Animation","AnimationIteration"),animationstart:Ad("Animation","AnimationStart"),transitionend:Ad("Transition","TransitionEnd")},Lm={},oM={};qo&&(oM=document.createElement("div").style,"AnimationEvent"in window||(delete Ra.animationend.animation,delete Ra.animationiteration.animation,delete Ra.animationstart.animation),"TransitionEvent"in window||delete Ra.transitionend.transition);function Gf(e){if(Lm[e])return Lm[e];if(!Ra[e])return e;var n=Ra[e],t;for(t in n)if(n.hasOwnProperty(t)&&t in oM)return Lm[e]=n[t];return e}var sM=Gf("animationend"),iM=Gf("animationiteration"),aM=Gf("animationstart"),lM=Gf("transitionend"),cM=new Map,UP="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 si(e,n){cM.set(e,n),sa(n,[e])}for(var $m=0;$m<UP.length;$m++){var Fm=UP[$m],DK=Fm.toLowerCase(),RK=Fm[0].toUpperCase()+Fm.slice(1);si(DK,"on"+RK)}si(sM,"onAnimationEnd");si(iM,"onAnimationIteration");si(aM,"onAnimationStart");si("dblclick","onDoubleClick");si("focusin","onFocus");si("focusout","onBlur");si(lM,"onTransitionEnd");cl("onMouseEnter",["mouseout","mouseover"]);cl("onMouseLeave",["mouseout","mouseover"]);cl("onPointerEnter",["pointerout","pointerover"]);cl("onPointerLeave",["pointerout","pointerover"]);sa("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));sa("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));sa("onBeforeInput",["compositionend","keypress","textInput","paste"]);sa("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));sa("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var Pc="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(" "),LK=new Set("cancel close invalid load scroll toggle".split(" ").concat(Pc));function HP(e,n,t){var r=e.type||"unknown-event";e.currentTarget=t,D7(r,n,void 0,e),e.currentTarget=null}function uM(e,n){n=(n&4)!==0;for(var t=0;t<e.length;t++){var r=e[t],o=r.event;r=r.listeners;e:{var s=void 0;if(n)for(var i=r.length-1;0<=i;i--){var a=r[i],l=a.instance,c=a.currentTarget;if(a=a.listener,l!==s&&o.isPropagationStopped())break e;HP(o,a,c),s=l}else for(i=0;i<r.length;i++){if(a=r[i],l=a.instance,c=a.currentTarget,a=a.listener,l!==s&&o.isPropagationStopped())break e;HP(o,a,c),s=l}}}if(Up)throw e=NS,Up=!1,NS=null,e}function Ze(e,n){var t=n[XS];t===void 0&&(t=n[XS]=new Set);var r=e+"__bubble";t.has(r)||(dM(n,e,2,!1),t.add(r))}function Nm(e,n,t){var r=0;n&&(r|=4),dM(t,e,r,n)}var jd="_reactListening"+Math.random().toString(36).slice(2);function iu(e){if(!e[jd]){e[jd]=!0,ST.forEach(function(t){t!=="selectionchange"&&(LK.has(t)||Nm(t,!1,e),Nm(t,!0,e))});var n=e.nodeType===9?e:e.ownerDocument;n===null||n[jd]||(n[jd]=!0,Nm("selectionchange",!1,n))}}function dM(e,n,t,r){switch(YT(n)){case 1:var o=q7;break;case 4:o=Z7;break;default:o=cw}t=o.bind(null,n,t,e),o=void 0,!FS||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 zm(e,n,t,r,o){var s=r;if(!(n&1)&&!(n&2)&&r!==null)e:for(;;){if(r===null)return;var i=r.tag;if(i===3||i===4){var a=r.stateNode.containerInfo;if(a===o||a.nodeType===8&&a.parentNode===o)break;if(i===4)for(i=r.return;i!==null;){var l=i.tag;if((l===3||l===4)&&(l=i.stateNode.containerInfo,l===o||l.nodeType===8&&l.parentNode===o))return;i=i.return}for(;a!==null;){if(i=Ii(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}DT(function(){var c=s,u=sw(t),h=[];e:{var p=cM.get(e);if(p!==void 0){var f=dw,S=e;switch(e){case"keypress":if(Ph(t)===0)break e;case"keydown":case"keyup":f=hK;break;case"focusin":S="focus",f=Om;break;case"focusout":S="blur",f=Om;break;case"beforeblur":case"afterblur":f=Om;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":f=AP;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=eK;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=gK;break;case sM:case iM:case aM:f=rK;break;case lM:f=yK;break;case"scroll":f=Q7;break;case"wheel":f=vK;break;case"copy":case"cut":case"paste":f=sK;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=OP}var m=(n&4)!==0,x=!m&&e==="scroll",y=m?p!==null?p+"Capture":null:p;m=[];for(var v=c,b;v!==null;){b=v;var E=b.stateNode;if(b.tag===5&&E!==null&&(b=E,y!==null&&(E=eu(v,y),E!=null&&m.push(au(v,E,b)))),x)break;v=v.return}0<m.length&&(p=new f(p,S,null,t,u),h.push({event:p,listeners:m}))}}if(!(n&7)){e:{if(p=e==="mouseover"||e==="pointerover",f=e==="mouseout"||e==="pointerout",p&&t!==LS&&(S=t.relatedTarget||t.fromElement)&&(Ii(S)||S[Zo]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(S=t.relatedTarget||t.toElement,f=c,S=S?Ii(S):null,S!==null&&(x=ia(S),S!==x||S.tag!==5&&S.tag!==6)&&(S=null)):(f=null,S=c),f!==S)){if(m=AP,E="onMouseLeave",y="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(m=OP,E="onPointerLeave",y="onPointerEnter",v="pointer"),x=f==null?p:La(f),b=S==null?p:La(S),p=new m(E,v+"leave",f,t,u),p.target=x,p.relatedTarget=b,E=null,Ii(u)===c&&(m=new m(y,v+"enter",S,t,u),m.target=b,m.relatedTarget=x,E=m),x=E,f&&S)t:{for(m=f,y=S,v=0,b=m;b;b=ya(b))v++;for(b=0,E=y;E;E=ya(E))b++;for(;0<v-b;)m=ya(m),v--;for(;0<b-v;)y=ya(y),b--;for(;v--;){if(m===y||y!==null&&m===y.alternate)break t;m=ya(m),y=ya(y)}m=null}else m=null;f!==null&&KP(h,p,f,m,!1),S!==null&&x!==null&&KP(h,x,S,m,!0)}}e:{if(p=c?La(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var I=EK;else if(LP(p))if(eM)I=MK;else{I=_K;var C=kK}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(I=TK);if(I&&(I=I(e,c))){JT(h,I,t,u);break e}C&&C(e,p,c),e==="focusout"&&(C=p._wrapperState)&&C.controlled&&p.type==="number"&&AS(p,"number",p.value)}switch(C=c?La(c):window,e){case"focusin":(LP(C)||C.contentEditable==="true")&&(Da=C,HS=c,Lc=null);break;case"focusout":Lc=HS=Da=null;break;case"mousedown":KS=!0;break;case"contextmenu":case"mouseup":case"dragend":KS=!1,BP(h,t,u);break;case"selectionchange":if(OK)break;case"keydown":case"keyup":BP(h,t,u)}var k;if(pw)e:{switch(e){case"compositionstart":var T="onCompositionStart";break e;case"compositionend":T="onCompositionEnd";break e;case"compositionupdate":T="onCompositionUpdate";break e}T=void 0}else Oa?ZT(e,t)&&(T="onCompositionEnd"):e==="keydown"&&t.keyCode===229&&(T="onCompositionStart");T&&(qT&&t.locale!=="ko"&&(Oa||T!=="onCompositionStart"?T==="onCompositionEnd"&&Oa&&(k=XT()):(_s=u,uw="value"in _s?_s.value:_s.textContent,Oa=!0)),C=Vp(c,T),0<C.length&&(T=new jP(T,e,null,t,u),h.push({event:T,listeners:C}),k?T.data=k:(k=QT(t),k!==null&&(T.data=k)))),(k=wK?bK(e,t):PK(e,t))&&(c=Vp(c,"onBeforeInput"),0<c.length&&(u=new jP("onBeforeInput","beforeinput",null,t,u),h.push({event:u,listeners:c}),u.data=k))}uM(h,n)})}function au(e,n,t){return{instance:e,listener:n,currentTarget:t}}function Vp(e,n){for(var t=n+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=eu(e,t),s!=null&&r.unshift(au(e,s,o)),s=eu(e,n),s!=null&&r.push(au(e,s,o))),e=e.return}return r}function ya(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function KP(e,n,t,r,o){for(var s=n._reactName,i=[];t!==null&&t!==r;){var a=t,l=a.alternate,c=a.stateNode;if(l!==null&&l===r)break;a.tag===5&&c!==null&&(a=c,o?(l=eu(t,s),l!=null&&i.unshift(au(t,l,a))):o||(l=eu(t,s),l!=null&&i.push(au(t,l,a)))),t=t.return}i.length!==0&&e.push({event:n,listeners:i})}var $K=/\r\n?/g,FK=/\u0000|\uFFFD/g;function WP(e){return(typeof e=="string"?e:""+e).replace($K,`
|
|
83
|
-
`).replace(FK,"")}function Od(e,n,t){if(n=WP(n),WP(e)!==n&&t)throw Error(q(425))}function Yp(){}var WS=null,GS=null;function VS(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 YS=typeof setTimeout=="function"?setTimeout:void 0,NK=typeof clearTimeout=="function"?clearTimeout:void 0,GP=typeof Promise=="function"?Promise:void 0,zK=typeof queueMicrotask=="function"?queueMicrotask:typeof GP<"u"?function(e){return GP.resolve(null).then(e).catch(BK)}:YS;function BK(e){setTimeout(function(){throw e})}function Bm(e,n){var t=n,r=0;do{var o=t.nextSibling;if(e.removeChild(t),o&&o.nodeType===8)if(t=o.data,t==="/$"){if(r===0){e.removeChild(o),ru(n);return}r--}else t!=="$"&&t!=="$?"&&t!=="$!"||r++;t=o}while(t);ru(n)}function Ns(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 VP(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 Rl=Math.random().toString(36).slice(2),io="__reactFiber$"+Rl,lu="__reactProps$"+Rl,Zo="__reactContainer$"+Rl,XS="__reactEvents$"+Rl,UK="__reactListeners$"+Rl,HK="__reactHandles$"+Rl;function Ii(e){var n=e[io];if(n)return n;for(var t=e.parentNode;t;){if(n=t[Zo]||t[io]){if(t=n.alternate,n.child!==null||t!==null&&t.child!==null)for(e=VP(e);e!==null;){if(t=e[io])return t;e=VP(e)}return n}e=t,t=e.parentNode}return null}function zu(e){return e=e[io]||e[Zo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function La(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(q(33))}function Vf(e){return e[lu]||null}var qS=[],$a=-1;function ii(e){return{current:e}}function Je(e){0>$a||(e.current=qS[$a],qS[$a]=null,$a--)}function Ve(e,n){$a++,qS[$a]=e.current,e.current=n}var Vs={},cn=ii(Vs),Fn=ii(!1),Ui=Vs;function ul(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 Nn(e){return e=e.childContextTypes,e!=null}function Xp(){Je(Fn),Je(cn)}function YP(e,n,t){if(cn.current!==Vs)throw Error(q(168));Ve(cn,n),Ve(Fn,t)}function hM(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,k7(e)||"Unknown",o));return pt({},t,r)}function qp(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Vs,Ui=cn.current,Ve(cn,e),Ve(Fn,Fn.current),!0}function XP(e,n,t){var r=e.stateNode;if(!r)throw Error(q(169));t?(e=hM(e,n,Ui),r.__reactInternalMemoizedMergedChildContext=e,Je(Fn),Je(cn),Ve(cn,e)):Je(Fn),Ve(Fn,t)}var Lo=null,Yf=!1,Um=!1;function pM(e){Lo===null?Lo=[e]:Lo.push(e)}function KK(e){Yf=!0,pM(e)}function ai(){if(!Um&&Lo!==null){Um=!0;var e=0,n=Fe;try{var t=Lo;for(Fe=1;e<t.length;e++){var r=t[e];do r=r(!0);while(r!==null)}Lo=null,Yf=!1}catch(o){throw Lo!==null&&(Lo=Lo.slice(e+1)),FT(iw,ai),o}finally{Fe=n,Um=!1}}return null}var Fa=[],Na=0,Zp=null,Qp=0,vr=[],xr=0,Hi=null,No=1,zo="";function wi(e,n){Fa[Na++]=Qp,Fa[Na++]=Zp,Zp=e,Qp=n}function fM(e,n,t){vr[xr++]=No,vr[xr++]=zo,vr[xr++]=Hi,Hi=e;var r=No;e=zo;var o=32-zr(r)-1;r&=~(1<<o),t+=1;var s=32-zr(n)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,No=1<<32-zr(n)+o|t<<o|r,zo=s+e}else No=1<<s|t<<o|r,zo=e}function gw(e){e.return!==null&&(wi(e,1),fM(e,1,0))}function mw(e){for(;e===Zp;)Zp=Fa[--Na],Fa[Na]=null,Qp=Fa[--Na],Fa[Na]=null;for(;e===Hi;)Hi=vr[--xr],vr[xr]=null,zo=vr[--xr],vr[xr]=null,No=vr[--xr],vr[xr]=null}var nr=null,Qn=null,nt=!1,$r=null;function gM(e,n){var t=wr(5,null,null,0);t.elementType="DELETED",t.stateNode=n,t.return=e,n=e.deletions,n===null?(e.deletions=[t],e.flags|=16):n.push(t)}function qP(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,nr=e,Qn=Ns(n.firstChild),!0):!1;case 6:return n=e.pendingProps===""||n.nodeType!==3?null:n,n!==null?(e.stateNode=n,nr=e,Qn=null,!0):!1;case 13:return n=n.nodeType!==8?null:n,n!==null?(t=Hi!==null?{id:No,overflow:zo}:null,e.memoizedState={dehydrated:n,treeContext:t,retryLane:1073741824},t=wr(18,null,null,0),t.stateNode=n,t.return=e,e.child=t,nr=e,Qn=null,!0):!1;default:return!1}}function ZS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function QS(e){if(nt){var n=Qn;if(n){var t=n;if(!qP(e,n)){if(ZS(e))throw Error(q(418));n=Ns(t.nextSibling);var r=nr;n&&qP(e,n)?gM(r,t):(e.flags=e.flags&-4097|2,nt=!1,nr=e)}}else{if(ZS(e))throw Error(q(418));e.flags=e.flags&-4097|2,nt=!1,nr=e}}}function ZP(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;nr=e}function Dd(e){if(e!==nr)return!1;if(!nt)return ZP(e),nt=!0,!1;var n;if((n=e.tag!==3)&&!(n=e.tag!==5)&&(n=e.type,n=n!=="head"&&n!=="body"&&!VS(e.type,e.memoizedProps)),n&&(n=Qn)){if(ZS(e))throw mM(),Error(q(418));for(;n;)gM(e,n),n=Ns(n.nextSibling)}if(ZP(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=Ns(e.nextSibling);break e}n--}else t!=="$"&&t!=="$!"&&t!=="$?"||n++}e=e.nextSibling}Qn=null}}else Qn=nr?Ns(e.stateNode.nextSibling):null;return!0}function mM(){for(var e=Qn;e;)e=Ns(e.nextSibling)}function dl(){Qn=nr=null,nt=!1}function yw(e){$r===null?$r=[e]:$r.push(e)}var WK=is.ReactCurrentBatchConfig;function sc(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 Rd(e,n){throw e=Object.prototype.toString.call(n),Error(q(31,e==="[object Object]"?"object with keys {"+Object.keys(n).join(", ")+"}":e))}function QP(e){var n=e._init;return n(e._payload)}function yM(e){function n(y,v){if(e){var b=y.deletions;b===null?(y.deletions=[v],y.flags|=16):b.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,b){return y.index=b,e?(b=y.alternate,b!==null?(b=b.index,b<v?(y.flags|=2,v):b):(y.flags|=2,v)):(y.flags|=1048576,v)}function i(y){return e&&y.alternate===null&&(y.flags|=2),y}function a(y,v,b,E){return v===null||v.tag!==6?(v=Xm(b,y.mode,E),v.return=y,v):(v=o(v,b),v.return=y,v)}function l(y,v,b,E){var I=b.type;return I===ja?u(y,v,b.props.children,E,b.key):v!==null&&(v.elementType===I||typeof I=="object"&&I!==null&&I.$$typeof===bs&&QP(I)===v.type)?(E=o(v,b.props),E.ref=sc(y,v,b),E.return=y,E):(E=Mh(b.type,b.key,b.props,null,y.mode,E),E.ref=sc(y,v,b),E.return=y,E)}function c(y,v,b,E){return v===null||v.tag!==4||v.stateNode.containerInfo!==b.containerInfo||v.stateNode.implementation!==b.implementation?(v=qm(b,y.mode,E),v.return=y,v):(v=o(v,b.children||[]),v.return=y,v)}function u(y,v,b,E,I){return v===null||v.tag!==7?(v=Ri(b,y.mode,E,I),v.return=y,v):(v=o(v,b),v.return=y,v)}function h(y,v,b){if(typeof v=="string"&&v!==""||typeof v=="number")return v=Xm(""+v,y.mode,b),v.return=y,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case Cd:return b=Mh(v.type,v.key,v.props,null,y.mode,b),b.ref=sc(y,null,v),b.return=y,b;case Aa:return v=qm(v,y.mode,b),v.return=y,v;case bs:var E=v._init;return h(y,E(v._payload),b)}if(wc(v)||ec(v))return v=Ri(v,y.mode,b,null),v.return=y,v;Rd(y,v)}return null}function p(y,v,b,E){var I=v!==null?v.key:null;if(typeof b=="string"&&b!==""||typeof b=="number")return I!==null?null:a(y,v,""+b,E);if(typeof b=="object"&&b!==null){switch(b.$$typeof){case Cd:return b.key===I?l(y,v,b,E):null;case Aa:return b.key===I?c(y,v,b,E):null;case bs:return I=b._init,p(y,v,I(b._payload),E)}if(wc(b)||ec(b))return I!==null?null:u(y,v,b,E,null);Rd(y,b)}return null}function f(y,v,b,E,I){if(typeof E=="string"&&E!==""||typeof E=="number")return y=y.get(b)||null,a(v,y,""+E,I);if(typeof E=="object"&&E!==null){switch(E.$$typeof){case Cd:return y=y.get(E.key===null?b:E.key)||null,l(v,y,E,I);case Aa:return y=y.get(E.key===null?b:E.key)||null,c(v,y,E,I);case bs:var C=E._init;return f(y,v,b,C(E._payload),I)}if(wc(E)||ec(E))return y=y.get(b)||null,u(v,y,E,I,null);Rd(v,E)}return null}function S(y,v,b,E){for(var I=null,C=null,k=v,T=v=0,O=null;k!==null&&T<b.length;T++){k.index>T?(O=k,k=null):O=k.sibling;var _=p(y,k,b[T],E);if(_===null){k===null&&(k=O);break}e&&k&&_.alternate===null&&n(y,k),v=s(_,v,T),C===null?I=_:C.sibling=_,C=_,k=O}if(T===b.length)return t(y,k),nt&&wi(y,T),I;if(k===null){for(;T<b.length;T++)k=h(y,b[T],E),k!==null&&(v=s(k,v,T),C===null?I=k:C.sibling=k,C=k);return nt&&wi(y,T),I}for(k=r(y,k);T<b.length;T++)O=f(k,y,T,b[T],E),O!==null&&(e&&O.alternate!==null&&k.delete(O.key===null?T:O.key),v=s(O,v,T),C===null?I=O:C.sibling=O,C=O);return e&&k.forEach(function(A){return n(y,A)}),nt&&wi(y,T),I}function m(y,v,b,E){var I=ec(b);if(typeof I!="function")throw Error(q(150));if(b=I.call(b),b==null)throw Error(q(151));for(var C=I=null,k=v,T=v=0,O=null,_=b.next();k!==null&&!_.done;T++,_=b.next()){k.index>T?(O=k,k=null):O=k.sibling;var A=p(y,k,_.value,E);if(A===null){k===null&&(k=O);break}e&&k&&A.alternate===null&&n(y,k),v=s(A,v,T),C===null?I=A:C.sibling=A,C=A,k=O}if(_.done)return t(y,k),nt&&wi(y,T),I;if(k===null){for(;!_.done;T++,_=b.next())_=h(y,_.value,E),_!==null&&(v=s(_,v,T),C===null?I=_:C.sibling=_,C=_);return nt&&wi(y,T),I}for(k=r(y,k);!_.done;T++,_=b.next())_=f(k,y,T,_.value,E),_!==null&&(e&&_.alternate!==null&&k.delete(_.key===null?T:_.key),v=s(_,v,T),C===null?I=_:C.sibling=_,C=_);return e&&k.forEach(function(L){return n(y,L)}),nt&&wi(y,T),I}function x(y,v,b,E){if(typeof b=="object"&&b!==null&&b.type===ja&&b.key===null&&(b=b.props.children),typeof b=="object"&&b!==null){switch(b.$$typeof){case Cd:e:{for(var I=b.key,C=v;C!==null;){if(C.key===I){if(I=b.type,I===ja){if(C.tag===7){t(y,C.sibling),v=o(C,b.props.children),v.return=y,y=v;break e}}else if(C.elementType===I||typeof I=="object"&&I!==null&&I.$$typeof===bs&&QP(I)===C.type){t(y,C.sibling),v=o(C,b.props),v.ref=sc(y,C,b),v.return=y,y=v;break e}t(y,C);break}else n(y,C);C=C.sibling}b.type===ja?(v=Ri(b.props.children,y.mode,E,b.key),v.return=y,y=v):(E=Mh(b.type,b.key,b.props,null,y.mode,E),E.ref=sc(y,v,b),E.return=y,y=E)}return i(y);case Aa:e:{for(C=b.key;v!==null;){if(v.key===C)if(v.tag===4&&v.stateNode.containerInfo===b.containerInfo&&v.stateNode.implementation===b.implementation){t(y,v.sibling),v=o(v,b.children||[]),v.return=y,y=v;break e}else{t(y,v);break}else n(y,v);v=v.sibling}v=qm(b,y.mode,E),v.return=y,y=v}return i(y);case bs:return C=b._init,x(y,v,C(b._payload),E)}if(wc(b))return S(y,v,b,E);if(ec(b))return m(y,v,b,E);Rd(y,b)}return typeof b=="string"&&b!==""||typeof b=="number"?(b=""+b,v!==null&&v.tag===6?(t(y,v.sibling),v=o(v,b),v.return=y,y=v):(t(y,v),v=Xm(b,y.mode,E),v.return=y,y=v),i(y)):t(y,v)}return x}var hl=yM(!0),SM=yM(!1),Jp=ii(null),ef=null,za=null,Sw=null;function vw(){Sw=za=ef=null}function xw(e){var n=Jp.current;Je(Jp),e._currentValue=n}function JS(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 el(e,n){ef=e,Sw=za=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&n&&(Dn=!0),e.firstContext=null)}function Ir(e){var n=e._currentValue;if(Sw!==e)if(e={context:e,memoizedValue:n,next:null},za===null){if(ef===null)throw Error(q(308));za=e,ef.dependencies={lanes:0,firstContext:e}}else za=za.next=e;return n}var Ei=null;function ww(e){Ei===null?Ei=[e]:Ei.push(e)}function vM(e,n,t,r){var o=n.interleaved;return o===null?(t.next=t,ww(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 bw(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function xM(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 zs(e,n,t){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,_e&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,ww(r)):(n.next=o.next,o.next=n),r.interleaved=n,Qo(e,t)}function Ch(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,aw(e,t)}}function JP(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 tf(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 l=a,c=l.next;l.next=null,i===null?s=c:i.next=c,i=l;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=c:a.next=c,u.lastBaseUpdate=l))}if(s!==null){var h=o.baseState;i=0,u=c=l=null,a=s;do{var p=a.lane,f=a.eventTime;if((r&p)===p){u!==null&&(u=u.next={eventTime:f,lane:0,tag:a.tag,payload:a.payload,callback:a.callback,next:null});e:{var S=e,m=a;switch(p=n,f=t,m.tag){case 1:if(S=m.payload,typeof S=="function"){h=S.call(f,h,p);break e}h=S;break e;case 3:S.flags=S.flags&-65537|128;case 0:if(S=m.payload,p=typeof S=="function"?S.call(f,h,p):S,p==null)break e;h=pt({},h,p);break e;case 2:Ps=!0}}a.callback!==null&&a.lane!==0&&(e.flags|=64,p=o.effects,p===null?o.effects=[a]:p.push(a))}else f={eventTime:f,lane:p,tag:a.tag,payload:a.payload,callback:a.callback,next:null},u===null?(c=u=f,l=h):u=u.next=f,i|=p;if(a=a.next,a===null){if(a=o.shared.pending,a===null)break;p=a,a=p.next,p.next=null,o.lastBaseUpdate=p,o.shared.pending=null}}while(!0);if(u===null&&(l=h),o.baseState=l,o.firstBaseUpdate=c,o.lastBaseUpdate=u,n=o.shared.interleaved,n!==null){o=n;do i|=o.lane,o=o.next;while(o!==n)}else s===null&&(o.shared.lanes=0);Wi|=i,e.lanes=i,e.memoizedState=h}}function eC(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 Bu={},go=ii(Bu),cu=ii(Bu),uu=ii(Bu);function ki(e){if(e===Bu)throw Error(q(174));return e}function Pw(e,n){switch(Ve(uu,n),Ve(cu,e),Ve(go,Bu),e=n.nodeType,e){case 9:case 11:n=(n=n.documentElement)?n.namespaceURI:OS(null,"");break;default:e=e===8?n.parentNode:n,n=e.namespaceURI||null,e=e.tagName,n=OS(n,e)}Je(go),Ve(go,n)}function pl(){Je(go),Je(cu),Je(uu)}function wM(e){ki(uu.current);var n=ki(go.current),t=OS(n,e.type);n!==t&&(Ve(cu,e),Ve(go,t))}function Cw(e){cu.current===e&&(Je(go),Je(cu))}var ct=ii(0);function nf(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 Hm=[];function Iw(){for(var e=0;e<Hm.length;e++)Hm[e]._workInProgressVersionPrimary=null;Hm.length=0}var Ih=is.ReactCurrentDispatcher,Km=is.ReactCurrentBatchConfig,Ki=0,ht=null,It=null,Tt=null,rf=!1,$c=!1,du=0,GK=0;function Zt(){throw Error(q(321))}function Ew(e,n){if(n===null)return!1;for(var t=0;t<n.length&&t<e.length;t++)if(!Kr(e[t],n[t]))return!1;return!0}function kw(e,n,t,r,o,s){if(Ki=s,ht=n,n.memoizedState=null,n.updateQueue=null,n.lanes=0,Ih.current=e===null||e.memoizedState===null?qK:ZK,e=t(r,o),$c){s=0;do{if($c=!1,du=0,25<=s)throw Error(q(301));s+=1,Tt=It=null,n.updateQueue=null,Ih.current=QK,e=t(r,o)}while($c)}if(Ih.current=of,n=It!==null&&It.next!==null,Ki=0,Tt=It=ht=null,rf=!1,n)throw Error(q(300));return e}function _w(){var e=du!==0;return du=0,e}function no(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Tt===null?ht.memoizedState=Tt=e:Tt=Tt.next=e,Tt}function Er(){if(It===null){var e=ht.alternate;e=e!==null?e.memoizedState:null}else e=It.next;var n=Tt===null?ht.memoizedState:Tt.next;if(n!==null)Tt=n,It=e;else{if(e===null)throw Error(q(310));It=e,e={memoizedState:It.memoizedState,baseState:It.baseState,baseQueue:It.baseQueue,queue:It.queue,next:null},Tt===null?ht.memoizedState=Tt=e:Tt=Tt.next=e}return Tt}function hu(e,n){return typeof n=="function"?n(e):n}function Wm(e){var n=Er(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=It,o=r.baseQueue,s=t.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,t.pending=null}if(o!==null){s=o.next,r=r.baseState;var a=i=null,l=null,c=s;do{var u=c.lane;if((Ki&u)===u)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:e(r,c.action);else{var h={lane:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=h,i=r):l=l.next=h,ht.lanes|=u,Wi|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Kr(r,n.memoizedState)||(Dn=!0),n.memoizedState=r,n.baseState=i,n.baseQueue=l,t.lastRenderedState=r}if(e=t.interleaved,e!==null){o=e;do s=o.lane,ht.lanes|=s,Wi|=s,o=o.next;while(o!==e)}else o===null&&(t.lanes=0);return[n.memoizedState,t.dispatch]}function Gm(e){var n=Er(),t=n.queue;if(t===null)throw Error(q(311));t.lastRenderedReducer=e;var r=t.dispatch,o=t.pending,s=n.memoizedState;if(o!==null){t.pending=null;var i=o=o.next;do s=e(s,i.action),i=i.next;while(i!==o);Kr(s,n.memoizedState)||(Dn=!0),n.memoizedState=s,n.baseQueue===null&&(n.baseState=s),t.lastRenderedState=s}return[s,r]}function bM(){}function PM(e,n){var t=ht,r=Er(),o=n(),s=!Kr(r.memoizedState,o);if(s&&(r.memoizedState=o,Dn=!0),r=r.queue,Tw(EM.bind(null,t,r,e),[e]),r.getSnapshot!==n||s||Tt!==null&&Tt.memoizedState.tag&1){if(t.flags|=2048,pu(9,IM.bind(null,t,r,o,n),void 0,null),Ot===null)throw Error(q(349));Ki&30||CM(t,n,o)}return o}function CM(e,n,t){e.flags|=16384,e={getSnapshot:n,value:t},n=ht.updateQueue,n===null?(n={lastEffect:null,stores:null},ht.updateQueue=n,n.stores=[e]):(t=n.stores,t===null?n.stores=[e]:t.push(e))}function IM(e,n,t,r){n.value=t,n.getSnapshot=r,kM(n)&&_M(e)}function EM(e,n,t){return t(function(){kM(n)&&_M(e)})}function kM(e){var n=e.getSnapshot;e=e.value;try{var t=n();return!Kr(e,t)}catch{return!0}}function _M(e){var n=Qo(e,1);n!==null&&Br(n,e,1,-1)}function tC(e){var n=no();return typeof e=="function"&&(e=e()),n.memoizedState=n.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:hu,lastRenderedState:e},n.queue=e,e=e.dispatch=XK.bind(null,ht,e),[n.memoizedState,e]}function pu(e,n,t,r){return e={tag:e,create:n,destroy:t,deps:r,next:null},n=ht.updateQueue,n===null?(n={lastEffect:null,stores:null},ht.updateQueue=n,n.lastEffect=e.next=e):(t=n.lastEffect,t===null?n.lastEffect=e.next=e:(r=t.next,t.next=e,e.next=r,n.lastEffect=e)),e}function TM(){return Er().memoizedState}function Eh(e,n,t,r){var o=no();ht.flags|=e,o.memoizedState=pu(1|n,t,void 0,r===void 0?null:r)}function Xf(e,n,t,r){var o=Er();r=r===void 0?null:r;var s=void 0;if(It!==null){var i=It.memoizedState;if(s=i.destroy,r!==null&&Ew(r,i.deps)){o.memoizedState=pu(n,t,s,r);return}}ht.flags|=e,o.memoizedState=pu(1|n,t,s,r)}function nC(e,n){return Eh(8390656,8,e,n)}function Tw(e,n){return Xf(2048,8,e,n)}function MM(e,n){return Xf(4,2,e,n)}function AM(e,n){return Xf(4,4,e,n)}function jM(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 OM(e,n,t){return t=t!=null?t.concat([e]):null,Xf(4,4,jM.bind(null,n,e),t)}function Mw(){}function DM(e,n){var t=Er();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&Ew(n,r[1])?r[0]:(t.memoizedState=[e,n],e)}function RM(e,n){var t=Er();n=n===void 0?null:n;var r=t.memoizedState;return r!==null&&n!==null&&Ew(n,r[1])?r[0]:(e=e(),t.memoizedState=[e,n],e)}function LM(e,n,t){return Ki&21?(Kr(t,n)||(t=BT(),ht.lanes|=t,Wi|=t,e.baseState=!0),n):(e.baseState&&(e.baseState=!1,Dn=!0),e.memoizedState=t)}function VK(e,n){var t=Fe;Fe=t!==0&&4>t?t:4,e(!0);var r=Km.transition;Km.transition={};try{e(!1),n()}finally{Fe=t,Km.transition=r}}function $M(){return Er().memoizedState}function YK(e,n,t){var r=Us(e);if(t={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null},FM(e))NM(n,t);else if(t=vM(e,n,t,r),t!==null){var o=yn();Br(t,e,r,o),zM(t,n,r)}}function XK(e,n,t){var r=Us(e),o={lane:r,action:t,hasEagerState:!1,eagerState:null,next:null};if(FM(e))NM(n,o);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=n.lastRenderedReducer,s!==null))try{var i=n.lastRenderedState,a=s(i,t);if(o.hasEagerState=!0,o.eagerState=a,Kr(a,i)){var l=n.interleaved;l===null?(o.next=o,ww(n)):(o.next=l.next,l.next=o),n.interleaved=o;return}}catch{}finally{}t=vM(e,n,o,r),t!==null&&(o=yn(),Br(t,e,r,o),zM(t,n,r))}}function FM(e){var n=e.alternate;return e===ht||n!==null&&n===ht}function NM(e,n){$c=rf=!0;var t=e.pending;t===null?n.next=n:(n.next=t.next,t.next=n),e.pending=n}function zM(e,n,t){if(t&4194240){var r=n.lanes;r&=e.pendingLanes,t|=r,n.lanes=t,aw(e,t)}}var of={readContext:Ir,useCallback:Zt,useContext:Zt,useEffect:Zt,useImperativeHandle:Zt,useInsertionEffect:Zt,useLayoutEffect:Zt,useMemo:Zt,useReducer:Zt,useRef:Zt,useState:Zt,useDebugValue:Zt,useDeferredValue:Zt,useTransition:Zt,useMutableSource:Zt,useSyncExternalStore:Zt,useId:Zt,unstable_isNewReconciler:!1},qK={readContext:Ir,useCallback:function(e,n){return no().memoizedState=[e,n===void 0?null:n],e},useContext:Ir,useEffect:nC,useImperativeHandle:function(e,n,t){return t=t!=null?t.concat([e]):null,Eh(4194308,4,jM.bind(null,n,e),t)},useLayoutEffect:function(e,n){return Eh(4194308,4,e,n)},useInsertionEffect:function(e,n){return Eh(4,2,e,n)},useMemo:function(e,n){var t=no();return n=n===void 0?null:n,e=e(),t.memoizedState=[e,n],e},useReducer:function(e,n,t){var r=no();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=YK.bind(null,ht,e),[r.memoizedState,e]},useRef:function(e){var n=no();return e={current:e},n.memoizedState=e},useState:tC,useDebugValue:Mw,useDeferredValue:function(e){return no().memoizedState=e},useTransition:function(){var e=tC(!1),n=e[0];return e=VK.bind(null,e[1]),no().memoizedState=e,[n,e]},useMutableSource:function(){},useSyncExternalStore:function(e,n,t){var r=ht,o=no();if(nt){if(t===void 0)throw Error(q(407));t=t()}else{if(t=n(),Ot===null)throw Error(q(349));Ki&30||CM(r,n,t)}o.memoizedState=t;var s={value:t,getSnapshot:n};return o.queue=s,nC(EM.bind(null,r,s,e),[e]),r.flags|=2048,pu(9,IM.bind(null,r,s,t,n),void 0,null),t},useId:function(){var e=no(),n=Ot.identifierPrefix;if(nt){var t=zo,r=No;t=(r&~(1<<32-zr(r)-1)).toString(32)+t,n=":"+n+"R"+t,t=du++,0<t&&(n+="H"+t.toString(32)),n+=":"}else t=GK++,n=":"+n+"r"+t.toString(32)+":";return e.memoizedState=n},unstable_isNewReconciler:!1},ZK={readContext:Ir,useCallback:DM,useContext:Ir,useEffect:Tw,useImperativeHandle:OM,useInsertionEffect:MM,useLayoutEffect:AM,useMemo:RM,useReducer:Wm,useRef:TM,useState:function(){return Wm(hu)},useDebugValue:Mw,useDeferredValue:function(e){var n=Er();return LM(n,It.memoizedState,e)},useTransition:function(){var e=Wm(hu)[0],n=Er().memoizedState;return[e,n]},useMutableSource:bM,useSyncExternalStore:PM,useId:$M,unstable_isNewReconciler:!1},QK={readContext:Ir,useCallback:DM,useContext:Ir,useEffect:Tw,useImperativeHandle:OM,useInsertionEffect:MM,useLayoutEffect:AM,useMemo:RM,useReducer:Gm,useRef:TM,useState:function(){return Gm(hu)},useDebugValue:Mw,useDeferredValue:function(e){var n=Er();return It===null?n.memoizedState=e:LM(n,It.memoizedState,e)},useTransition:function(){var e=Gm(hu)[0],n=Er().memoizedState;return[e,n]},useMutableSource:bM,useSyncExternalStore:PM,useId:$M,unstable_isNewReconciler:!1};function jr(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 ev(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 qf={isMounted:function(e){return(e=e._reactInternals)?ia(e)===e:!1},enqueueSetState:function(e,n,t){e=e._reactInternals;var r=yn(),o=Us(e),s=Ko(r,o);s.payload=n,t!=null&&(s.callback=t),n=zs(e,s,o),n!==null&&(Br(n,e,o,r),Ch(n,e,o))},enqueueReplaceState:function(e,n,t){e=e._reactInternals;var r=yn(),o=Us(e),s=Ko(r,o);s.tag=1,s.payload=n,t!=null&&(s.callback=t),n=zs(e,s,o),n!==null&&(Br(n,e,o,r),Ch(n,e,o))},enqueueForceUpdate:function(e,n){e=e._reactInternals;var t=yn(),r=Us(e),o=Ko(t,r);o.tag=2,n!=null&&(o.callback=n),n=zs(e,o,r),n!==null&&(Br(n,e,r,t),Ch(n,e,r))}};function rC(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?!su(t,r)||!su(o,s):!0}function BM(e,n,t){var r=!1,o=Vs,s=n.contextType;return typeof s=="object"&&s!==null?s=Ir(s):(o=Nn(n)?Ui:cn.current,r=n.contextTypes,s=(r=r!=null)?ul(e,o):Vs),n=new n(t,s),e.memoizedState=n.state!==null&&n.state!==void 0?n.state:null,n.updater=qf,e.stateNode=n,n._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),n}function oC(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&&qf.enqueueReplaceState(n,n.state,null)}function tv(e,n,t,r){var o=e.stateNode;o.props=t,o.state=e.memoizedState,o.refs={},bw(e);var s=n.contextType;typeof s=="object"&&s!==null?o.context=Ir(s):(s=Nn(n)?Ui:cn.current,o.context=ul(e,s)),o.state=e.memoizedState,s=n.getDerivedStateFromProps,typeof s=="function"&&(ev(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&&qf.enqueueReplaceState(o,o.state,null),tf(e,t,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function fl(e,n){try{var t="",r=n;do t+=E7(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 Vm(e,n,t){return{value:e,source:null,stack:t??null,digest:n??null}}function nv(e,n){try{console.error(n.value)}catch(t){setTimeout(function(){throw t})}}var JK=typeof WeakMap=="function"?WeakMap:Map;function UM(e,n,t){t=Ko(-1,t),t.tag=3,t.payload={element:null};var r=n.value;return t.callback=function(){af||(af=!0,hv=r),nv(e,n)},t}function HM(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(){nv(e,n)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(t.callback=function(){nv(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 sC(e,n,t){var r=e.pingCache;if(r===null){r=e.pingCache=new JK;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=pW.bind(null,e,n,t),n.then(e,e))}function iC(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 aC(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,zs(t,n,1))),t.lanes|=1),e)}var eW=is.ReactCurrentOwner,Dn=!1;function fn(e,n,t,r){n.child=e===null?SM(n,null,t,r):hl(n,e.child,t,r)}function lC(e,n,t,r,o){t=t.render;var s=n.ref;return el(n,o),r=kw(e,n,t,r,s,o),t=_w(),e!==null&&!Dn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Jo(e,n,o)):(nt&&t&&gw(n),n.flags|=1,fn(e,n,r,o),n.child)}function cC(e,n,t,r,o){if(e===null){var s=t.type;return typeof s=="function"&&!Fw(s)&&s.defaultProps===void 0&&t.compare===null&&t.defaultProps===void 0?(n.tag=15,n.type=s,KM(e,n,s,r,o)):(e=Mh(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:su,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 KM(e,n,t,r,o){if(e!==null){var s=e.memoizedProps;if(su(s,r)&&e.ref===n.ref)if(Dn=!1,n.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(Dn=!0);else return n.lanes=e.lanes,Jo(e,n,o)}return rv(e,n,t,r,o)}function WM(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},Ve(Ua,Xn),Xn|=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,Ve(Ua,Xn),Xn|=e,null;n.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:t,Ve(Ua,Xn),Xn|=r}else s!==null?(r=s.baseLanes|t,n.memoizedState=null):r=t,Ve(Ua,Xn),Xn|=r;return fn(e,n,o,t),n.child}function GM(e,n){var t=n.ref;(e===null&&t!==null||e!==null&&e.ref!==t)&&(n.flags|=512,n.flags|=2097152)}function rv(e,n,t,r,o){var s=Nn(t)?Ui:cn.current;return s=ul(n,s),el(n,o),t=kw(e,n,t,r,s,o),r=_w(),e!==null&&!Dn?(n.updateQueue=e.updateQueue,n.flags&=-2053,e.lanes&=~o,Jo(e,n,o)):(nt&&r&&gw(n),n.flags|=1,fn(e,n,t,o),n.child)}function uC(e,n,t,r,o){if(Nn(t)){var s=!0;qp(n)}else s=!1;if(el(n,o),n.stateNode===null)kh(e,n),BM(n,t,r),tv(n,t,r,o),r=!0;else if(e===null){var i=n.stateNode,a=n.memoizedProps;i.props=a;var l=i.context,c=t.contextType;typeof c=="object"&&c!==null?c=Ir(c):(c=Nn(t)?Ui:cn.current,c=ul(n,c));var u=t.getDerivedStateFromProps,h=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";h||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&oC(n,i,r,c),Ps=!1;var p=n.memoizedState;i.state=p,tf(n,r,i,o),l=n.memoizedState,a!==r||p!==l||Fn.current||Ps?(typeof u=="function"&&(ev(n,t,u,r),l=n.memoizedState),(a=Ps||rC(n,t,a,r,p,l,c))?(h||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(n.flags|=4194308)):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),n.memoizedProps=r,n.memoizedState=l),i.props=r,i.state=l,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(n.flags|=4194308),r=!1)}else{i=n.stateNode,xM(e,n),a=n.memoizedProps,c=n.type===n.elementType?a:jr(n.type,a),i.props=c,h=n.pendingProps,p=i.context,l=t.contextType,typeof l=="object"&&l!==null?l=Ir(l):(l=Nn(t)?Ui:cn.current,l=ul(n,l));var f=t.getDerivedStateFromProps;(u=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==h||p!==l)&&oC(n,i,r,l),Ps=!1,p=n.memoizedState,i.state=p,tf(n,r,i,o);var S=n.memoizedState;a!==h||p!==S||Fn.current||Ps?(typeof f=="function"&&(ev(n,t,f,r),S=n.memoizedState),(c=Ps||rC(n,t,c,r,p,S,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,S,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,S,l)),typeof i.componentDidUpdate=="function"&&(n.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(n.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=1024),n.memoizedProps=r,n.memoizedState=S),i.props=r,i.state=S,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(n.flags|=1024),r=!1)}return ov(e,n,t,r,s,o)}function ov(e,n,t,r,o,s){GM(e,n);var i=(n.flags&128)!==0;if(!r&&!i)return o&&XP(n,t,!1),Jo(e,n,s);r=n.stateNode,eW.current=n;var a=i&&typeof t.getDerivedStateFromError!="function"?null:r.render();return n.flags|=1,e!==null&&i?(n.child=hl(n,e.child,null,s),n.child=hl(n,null,a,s)):fn(e,n,a,s),n.memoizedState=r.state,o&&XP(n,t,!0),n.child}function VM(e){var n=e.stateNode;n.pendingContext?YP(e,n.pendingContext,n.pendingContext!==n.context):n.context&&YP(e,n.context,!1),Pw(e,n.containerInfo)}function dC(e,n,t,r,o){return dl(),yw(o),n.flags|=256,fn(e,n,t,r),n.child}var sv={dehydrated:null,treeContext:null,retryLane:0};function iv(e){return{baseLanes:e,cachePool:null,transitions:null}}function YM(e,n,t){var r=n.pendingProps,o=ct.current,s=!1,i=(n.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(s=!0,n.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ve(ct,o&1),e===null)return QS(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=Jf(i,r,0,null),e=Ri(e,r,t,null),s.return=n,e.return=n,s.sibling=e,n.child=s,n.child.memoizedState=iv(t),n.memoizedState=sv,e):Aw(n,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return tW(e,n,i,r,a,o,t);if(s){s=r.fallback,i=n.mode,o=e.child,a=o.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&n.child!==o?(r=n.child,r.childLanes=0,r.pendingProps=l,n.deletions=null):(r=Hs(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Hs(a,s):(s=Ri(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?iv(t):{baseLanes:i.baseLanes|t,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~t,n.memoizedState=sv,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 Aw(e,n){return n=Jf({mode:"visible",children:n},e.mode,0,null),n.return=e,e.child=n}function Ld(e,n,t,r){return r!==null&&yw(r),hl(n,e.child,null,t),e=Aw(n,n.pendingProps.children),e.flags|=2,n.memoizedState=null,e}function tW(e,n,t,r,o,s,i){if(t)return n.flags&256?(n.flags&=-257,r=Vm(Error(q(422))),Ld(e,n,i,r)):n.memoizedState!==null?(n.child=e.child,n.flags|=128,null):(s=r.fallback,o=n.mode,r=Jf({mode:"visible",children:r.children},o,0,null),s=Ri(s,o,i,null),s.flags|=2,r.return=n,s.return=n,r.sibling=s,n.child=r,n.mode&1&&hl(n,e.child,null,i),n.child.memoizedState=iv(i),n.memoizedState=sv,s);if(!(n.mode&1))return Ld(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=Vm(s,r,void 0),Ld(e,n,i,r)}if(a=(i&e.childLanes)!==0,Dn||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),Br(r,e,o,-1))}return $w(),r=Vm(Error(q(421))),Ld(e,n,i,r)}return o.data==="$?"?(n.flags|=128,n.child=e.child,n=fW.bind(null,e),o._reactRetry=n,null):(e=s.treeContext,Qn=Ns(o.nextSibling),nr=n,nt=!0,$r=null,e!==null&&(vr[xr++]=No,vr[xr++]=zo,vr[xr++]=Hi,No=e.id,zo=e.overflow,Hi=n),n=Aw(n,r.children),n.flags|=4096,n)}function hC(e,n,t){e.lanes|=n;var r=e.alternate;r!==null&&(r.lanes|=n),JS(e.return,n,t)}function Ym(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 XM(e,n,t){var r=n.pendingProps,o=r.revealOrder,s=r.tail;if(fn(e,n,r.children,t),r=ct.current,r&2)r=r&1|2,n.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=n.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&hC(e,t,n);else if(e.tag===19)hC(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(Ve(ct,r),!(n.mode&1))n.memoizedState=null;else switch(o){case"forwards":for(t=n.child,o=null;t!==null;)e=t.alternate,e!==null&&nf(e)===null&&(o=t),t=t.sibling;t=o,t===null?(o=n.child,n.child=null):(o=t.sibling,t.sibling=null),Ym(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&&nf(e)===null){n.child=o;break}e=o.sibling,o.sibling=t,t=o,o=e}Ym(n,!0,t,null,s);break;case"together":Ym(n,!1,null,null,void 0);break;default:n.memoizedState=null}return n.child}function kh(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),Wi|=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 nW(e,n,t){switch(n.tag){case 3:VM(n),dl();break;case 5:wM(n);break;case 1:Nn(n.type)&&qp(n);break;case 4:Pw(n,n.stateNode.containerInfo);break;case 10:var r=n.type._context,o=n.memoizedProps.value;Ve(Jp,r._currentValue),r._currentValue=o;break;case 13:if(r=n.memoizedState,r!==null)return r.dehydrated!==null?(Ve(ct,ct.current&1),n.flags|=128,null):t&n.child.childLanes?YM(e,n,t):(Ve(ct,ct.current&1),e=Jo(e,n,t),e!==null?e.sibling:null);Ve(ct,ct.current&1);break;case 19:if(r=(t&n.childLanes)!==0,e.flags&128){if(r)return XM(e,n,t);n.flags|=128}if(o=n.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ve(ct,ct.current),r)break;return null;case 22:case 23:return n.lanes=0,WM(e,n,t)}return Jo(e,n,t)}var qM,av,ZM,QM;qM=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}};av=function(){};ZM=function(e,n,t,r){var o=e.memoizedProps;if(o!==r){e=n.stateNode,ki(go.current);var s=null;switch(t){case"input":o=TS(e,o),r=TS(e,r),s=[];break;case"select":o=pt({},o,{value:void 0}),r=pt({},r,{value:void 0}),s=[];break;case"textarea":o=jS(e,o),r=jS(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Yp)}DS(t,r);var i;t=null;for(c in o)if(!r.hasOwnProperty(c)&&o.hasOwnProperty(c)&&o[c]!=null)if(c==="style"){var a=o[c];for(i in a)a.hasOwnProperty(i)&&(t||(t={}),t[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Qc.hasOwnProperty(c)?s||(s=[]):(s=s||[]).push(c,null));for(c in r){var l=r[c];if(a=o!=null?o[c]:void 0,r.hasOwnProperty(c)&&l!==a&&(l!=null||a!=null))if(c==="style")if(a){for(i in a)!a.hasOwnProperty(i)||l&&l.hasOwnProperty(i)||(t||(t={}),t[i]="");for(i in l)l.hasOwnProperty(i)&&a[i]!==l[i]&&(t||(t={}),t[i]=l[i])}else t||(s||(s=[]),s.push(c,t)),t=l;else c==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,a=a?a.__html:void 0,l!=null&&a!==l&&(s=s||[]).push(c,l)):c==="children"?typeof l!="string"&&typeof l!="number"||(s=s||[]).push(c,""+l):c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&(Qc.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&Ze("scroll",e),s||a===l||(s=[])):(s=s||[]).push(c,l))}t&&(s=s||[]).push("style",t);var c=s;(n.updateQueue=c)&&(n.flags|=4)}};QM=function(e,n,t,r){t!==r&&(n.flags|=4)};function ic(e,n){if(!nt)switch(e.tailMode){case"hidden":n=e.tail;for(var t=null;n!==null;)n.alternate!==null&&(t=n),n=n.sibling;t===null?e.tail=null:t.sibling=null;break;case"collapsed":t=e.tail;for(var r=null;t!==null;)t.alternate!==null&&(r=t),t=t.sibling;r===null?n||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Qt(e){var n=e.alternate!==null&&e.alternate.child===e.child,t=0,r=0;if(n)for(var o=e.child;o!==null;)t|=o.lanes|o.childLanes,r|=o.subtreeFlags&14680064,r|=o.flags&14680064,o.return=e,o=o.sibling;else for(o=e.child;o!==null;)t|=o.lanes|o.childLanes,r|=o.subtreeFlags,r|=o.flags,o.return=e,o=o.sibling;return e.subtreeFlags|=r,e.childLanes=t,n}function rW(e,n,t){var r=n.pendingProps;switch(mw(n),n.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Qt(n),null;case 1:return Nn(n.type)&&Xp(),Qt(n),null;case 3:return r=n.stateNode,pl(),Je(Fn),Je(cn),Iw(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(Dd(n)?n.flags|=4:e===null||e.memoizedState.isDehydrated&&!(n.flags&256)||(n.flags|=1024,$r!==null&&(gv($r),$r=null))),av(e,n),Qt(n),null;case 5:Cw(n);var o=ki(uu.current);if(t=n.type,e!==null&&n.stateNode!=null)ZM(e,n,t,r,o),e.ref!==n.ref&&(n.flags|=512,n.flags|=2097152);else{if(!r){if(n.stateNode===null)throw Error(q(166));return Qt(n),null}if(e=ki(go.current),Dd(n)){r=n.stateNode,t=n.type;var s=n.memoizedProps;switch(r[io]=n,r[lu]=s,e=(n.mode&1)!==0,t){case"dialog":Ze("cancel",r),Ze("close",r);break;case"iframe":case"object":case"embed":Ze("load",r);break;case"video":case"audio":for(o=0;o<Pc.length;o++)Ze(Pc[o],r);break;case"source":Ze("error",r);break;case"img":case"image":case"link":Ze("error",r),Ze("load",r);break;case"details":Ze("toggle",r);break;case"input":wP(r,s),Ze("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Ze("invalid",r);break;case"textarea":PP(r,s),Ze("invalid",r)}DS(t,s),o=null;for(var i in s)if(s.hasOwnProperty(i)){var a=s[i];i==="children"?typeof a=="string"?r.textContent!==a&&(s.suppressHydrationWarning!==!0&&Od(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&Od(r.textContent,a,e),o=["children",""+a]):Qc.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Ze("scroll",r)}switch(t){case"input":Id(r),bP(r,s,!0);break;case"textarea":Id(r),CP(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Yp)}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=ET(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[io]=n,e[lu]=r,qM(e,n,!1,!1),n.stateNode=e;e:{switch(i=RS(t,r),t){case"dialog":Ze("cancel",e),Ze("close",e),o=r;break;case"iframe":case"object":case"embed":Ze("load",e),o=r;break;case"video":case"audio":for(o=0;o<Pc.length;o++)Ze(Pc[o],e);o=r;break;case"source":Ze("error",e),o=r;break;case"img":case"image":case"link":Ze("error",e),Ze("load",e),o=r;break;case"details":Ze("toggle",e),o=r;break;case"input":wP(e,r),o=TS(e,r),Ze("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=pt({},r,{value:void 0}),Ze("invalid",e);break;case"textarea":PP(e,r),o=jS(e,r),Ze("invalid",e);break;default:o=r}DS(t,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?TT(e,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&kT(e,l)):s==="children"?typeof l=="string"?(t!=="textarea"||l!=="")&&Jc(e,l):typeof l=="number"&&Jc(e,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Qc.hasOwnProperty(s)?l!=null&&s==="onScroll"&&Ze("scroll",e):l!=null&&tw(e,s,l,i))}switch(t){case"input":Id(e),bP(e,r,!1);break;case"textarea":Id(e),CP(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?qa(e,!!r.multiple,s,!1):r.defaultValue!=null&&qa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Yp)}switch(t){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(n.flags|=4)}n.ref!==null&&(n.flags|=512,n.flags|=2097152)}return Qt(n),null;case 6:if(e&&n.stateNode!=null)QM(e,n,e.memoizedProps,r);else{if(typeof r!="string"&&n.stateNode===null)throw Error(q(166));if(t=ki(uu.current),ki(go.current),Dd(n)){if(r=n.stateNode,t=n.memoizedProps,r[io]=n,(s=r.nodeValue!==t)&&(e=nr,e!==null))switch(e.tag){case 3:Od(r.nodeValue,t,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&Od(r.nodeValue,t,(e.mode&1)!==0)}s&&(n.flags|=4)}else r=(t.nodeType===9?t:t.ownerDocument).createTextNode(r),r[io]=n,n.stateNode=r}return Qt(n),null;case 13:if(Je(ct),r=n.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(nt&&Qn!==null&&n.mode&1&&!(n.flags&128))mM(),dl(),n.flags|=98560,s=!1;else if(s=Dd(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[io]=n}else dl(),!(n.flags&128)&&(n.memoizedState=null),n.flags|=4;Qt(n),s=!1}else $r!==null&&(gv($r),$r=null),s=!0;if(!s)return n.flags&65536?n:null}return n.flags&128?(n.lanes=t,n):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(n.child.flags|=8192,n.mode&1&&(e===null||ct.current&1?Et===0&&(Et=3):$w())),n.updateQueue!==null&&(n.flags|=4),Qt(n),null);case 4:return pl(),av(e,n),e===null&&iu(n.stateNode.containerInfo),Qt(n),null;case 10:return xw(n.type._context),Qt(n),null;case 17:return Nn(n.type)&&Xp(),Qt(n),null;case 19:if(Je(ct),s=n.memoizedState,s===null)return Qt(n),null;if(r=(n.flags&128)!==0,i=s.rendering,i===null)if(r)ic(s,!1);else{if(Et!==0||e!==null&&e.flags&128)for(e=n.child;e!==null;){if(i=nf(e),i!==null){for(n.flags|=128,ic(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 Ve(ct,ct.current&1|2),n.child}e=e.sibling}s.tail!==null&&wt()>gl&&(n.flags|=128,r=!0,ic(s,!1),n.lanes=4194304)}else{if(!r)if(e=nf(i),e!==null){if(n.flags|=128,r=!0,t=e.updateQueue,t!==null&&(n.updateQueue=t,n.flags|=4),ic(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!nt)return Qt(n),null}else 2*wt()-s.renderingStartTime>gl&&t!==1073741824&&(n.flags|=128,r=!0,ic(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=wt(),n.sibling=null,t=ct.current,Ve(ct,r?t&1|2:t&1),n):(Qt(n),null);case 22:case 23:return Lw(),r=n.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(n.flags|=8192),r&&n.mode&1?Xn&1073741824&&(Qt(n),n.subtreeFlags&6&&(n.flags|=8192)):Qt(n),null;case 24:return null;case 25:return null}throw Error(q(156,n.tag))}function oW(e,n){switch(mw(n),n.tag){case 1:return Nn(n.type)&&Xp(),e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 3:return pl(),Je(Fn),Je(cn),Iw(),e=n.flags,e&65536&&!(e&128)?(n.flags=e&-65537|128,n):null;case 5:return Cw(n),null;case 13:if(Je(ct),e=n.memoizedState,e!==null&&e.dehydrated!==null){if(n.alternate===null)throw Error(q(340));dl()}return e=n.flags,e&65536?(n.flags=e&-65537|128,n):null;case 19:return Je(ct),null;case 4:return pl(),null;case 10:return xw(n.type._context),null;case 22:case 23:return Lw(),null;case 24:return null;default:return null}}var $d=!1,rn=!1,sW=typeof WeakSet=="function"?WeakSet:Set,te=null;function Ba(e,n){var t=e.ref;if(t!==null)if(typeof t=="function")try{t(null)}catch(r){mt(e,n,r)}else t.current=null}function lv(e,n,t){try{t()}catch(r){mt(e,n,r)}}var pC=!1;function iW(e,n){if(WS=Wp,e=rM(),fw(e)){if("selectionStart"in e)var t={start:e.selectionStart,end:e.selectionEnd};else e:{t=(t=e.ownerDocument)&&t.defaultView||window;var r=t.getSelection&&t.getSelection();if(r&&r.rangeCount!==0){t=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{t.nodeType,s.nodeType}catch{t=null;break e}var i=0,a=-1,l=-1,c=0,u=0,h=e,p=null;t:for(;;){for(var f;h!==t||o!==0&&h.nodeType!==3||(a=i+o),h!==s||r!==0&&h.nodeType!==3||(l=i+r),h.nodeType===3&&(i+=h.nodeValue.length),(f=h.firstChild)!==null;)p=h,h=f;for(;;){if(h===e)break t;if(p===t&&++c===o&&(a=i),p===s&&++u===r&&(l=i),(f=h.nextSibling)!==null)break;h=p,p=h.parentNode}h=f}t=a===-1||l===-1?null:{start:a,end:l}}else t=null}t=t||{start:0,end:0}}else t=null;for(GS={focusedElem:e,selectionRange:t},Wp=!1,te=n;te!==null;)if(n=te,e=n.child,(n.subtreeFlags&1028)!==0&&e!==null)e.return=n,te=e;else for(;te!==null;){n=te;try{var S=n.alternate;if(n.flags&1024)switch(n.tag){case 0:case 11:case 15:break;case 1:if(S!==null){var m=S.memoizedProps,x=S.memoizedState,y=n.stateNode,v=y.getSnapshotBeforeUpdate(n.elementType===n.type?m:jr(n.type,m),x);y.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var b=n.stateNode.containerInfo;b.nodeType===1?b.textContent="":b.nodeType===9&&b.documentElement&&b.removeChild(b.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(q(163))}}catch(E){mt(n,n.return,E)}if(e=n.sibling,e!==null){e.return=n.return,te=e;break}te=n.return}return S=pC,pC=!1,S}function Fc(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&&lv(n,t,s)}o=o.next}while(o!==r)}}function Zf(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 cv(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 JM(e){var n=e.alternate;n!==null&&(e.alternate=null,JM(n)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(n=e.stateNode,n!==null&&(delete n[io],delete n[lu],delete n[XS],delete n[UK],delete n[HK])),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 e2(e){return e.tag===5||e.tag===3||e.tag===4}function fC(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||e2(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 uv(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=Yp));else if(r!==4&&(e=e.child,e!==null))for(uv(e,n,t),e=e.sibling;e!==null;)uv(e,n,t),e=e.sibling}function dv(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(dv(e,n,t),e=e.sibling;e!==null;)dv(e,n,t),e=e.sibling}var $t=null,Dr=!1;function ms(e,n,t){for(t=t.child;t!==null;)t2(e,n,t),t=t.sibling}function t2(e,n,t){if(fo&&typeof fo.onCommitFiberUnmount=="function")try{fo.onCommitFiberUnmount(Hf,t)}catch{}switch(t.tag){case 5:rn||Ba(t,n);case 6:var r=$t,o=Dr;$t=null,ms(e,n,t),$t=r,Dr=o,$t!==null&&(Dr?(e=$t,t=t.stateNode,e.nodeType===8?e.parentNode.removeChild(t):e.removeChild(t)):$t.removeChild(t.stateNode));break;case 18:$t!==null&&(Dr?(e=$t,t=t.stateNode,e.nodeType===8?Bm(e.parentNode,t):e.nodeType===1&&Bm(e,t),ru(e)):Bm($t,t.stateNode));break;case 4:r=$t,o=Dr,$t=t.stateNode.containerInfo,Dr=!0,ms(e,n,t),$t=r,Dr=o;break;case 0:case 11:case 14:case 15:if(!rn&&(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)&&lv(t,n,i),o=o.next}while(o!==r)}ms(e,n,t);break;case 1:if(!rn&&(Ba(t,n),r=t.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=t.memoizedProps,r.state=t.memoizedState,r.componentWillUnmount()}catch(a){mt(t,n,a)}ms(e,n,t);break;case 21:ms(e,n,t);break;case 22:t.mode&1?(rn=(r=rn)||t.memoizedState!==null,ms(e,n,t),rn=r):ms(e,n,t);break;default:ms(e,n,t)}}function gC(e){var n=e.updateQueue;if(n!==null){e.updateQueue=null;var t=e.stateNode;t===null&&(t=e.stateNode=new sW),n.forEach(function(r){var o=gW.bind(null,e,r);t.has(r)||(t.add(r),r.then(o,o))})}}function Ar(e,n){var t=n.deletions;if(t!==null)for(var r=0;r<t.length;r++){var o=t[r];try{var s=e,i=n,a=i;e:for(;a!==null;){switch(a.tag){case 5:$t=a.stateNode,Dr=!1;break e;case 3:$t=a.stateNode.containerInfo,Dr=!0;break e;case 4:$t=a.stateNode.containerInfo,Dr=!0;break e}a=a.return}if($t===null)throw Error(q(160));t2(s,i,o),$t=null,Dr=!1;var l=o.alternate;l!==null&&(l.return=null),o.return=null}catch(c){mt(o,n,c)}}if(n.subtreeFlags&12854)for(n=n.child;n!==null;)n2(n,e),n=n.sibling}function n2(e,n){var t=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Ar(n,e),to(e),r&4){try{Fc(3,e,e.return),Zf(3,e)}catch(m){mt(e,e.return,m)}try{Fc(5,e,e.return)}catch(m){mt(e,e.return,m)}}break;case 1:Ar(n,e),to(e),r&512&&t!==null&&Ba(t,t.return);break;case 5:if(Ar(n,e),to(e),r&512&&t!==null&&Ba(t,t.return),e.flags&32){var o=e.stateNode;try{Jc(o,"")}catch(m){mt(e,e.return,m)}}if(r&4&&(o=e.stateNode,o!=null)){var s=e.memoizedProps,i=t!==null?t.memoizedProps:s,a=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&CT(o,s),RS(a,i);var c=RS(a,s);for(i=0;i<l.length;i+=2){var u=l[i],h=l[i+1];u==="style"?TT(o,h):u==="dangerouslySetInnerHTML"?kT(o,h):u==="children"?Jc(o,h):tw(o,u,h,c)}switch(a){case"input":MS(o,s);break;case"textarea":IT(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?qa(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?qa(o,!!s.multiple,s.defaultValue,!0):qa(o,!!s.multiple,s.multiple?[]:"",!1))}o[lu]=s}catch(m){mt(e,e.return,m)}}break;case 6:if(Ar(n,e),to(e),r&4){if(e.stateNode===null)throw Error(q(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(m){mt(e,e.return,m)}}break;case 3:if(Ar(n,e),to(e),r&4&&t!==null&&t.memoizedState.isDehydrated)try{ru(n.containerInfo)}catch(m){mt(e,e.return,m)}break;case 4:Ar(n,e),to(e);break;case 13:Ar(n,e),to(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(Dw=wt())),r&4&&gC(e);break;case 22:if(u=t!==null&&t.memoizedState!==null,e.mode&1?(rn=(c=rn)||u,Ar(n,e),rn=c):Ar(n,e),to(e),r&8192){if(c=e.memoizedState!==null,(e.stateNode.isHidden=c)&&!u&&e.mode&1)for(te=e,u=e.child;u!==null;){for(h=te=u;te!==null;){switch(p=te,f=p.child,p.tag){case 0:case 11:case 14:case 15:Fc(4,p,p.return);break;case 1:Ba(p,p.return);var S=p.stateNode;if(typeof S.componentWillUnmount=="function"){r=p,t=p.return;try{n=r,S.props=n.memoizedProps,S.state=n.memoizedState,S.componentWillUnmount()}catch(m){mt(r,t,m)}}break;case 5:Ba(p,p.return);break;case 22:if(p.memoizedState!==null){yC(h);continue}}f!==null?(f.return=p,te=f):yC(h)}u=u.sibling}e:for(u=null,h=e;;){if(h.tag===5){if(u===null){u=h;try{o=h.stateNode,c?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=h.stateNode,l=h.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=_T("display",i))}catch(m){mt(e,e.return,m)}}}else if(h.tag===6){if(u===null)try{h.stateNode.nodeValue=c?"":h.memoizedProps}catch(m){mt(e,e.return,m)}}else if((h.tag!==22&&h.tag!==23||h.memoizedState===null||h===e)&&h.child!==null){h.child.return=h,h=h.child;continue}if(h===e)break e;for(;h.sibling===null;){if(h.return===null||h.return===e)break e;u===h&&(u=null),h=h.return}u===h&&(u=null),h.sibling.return=h.return,h=h.sibling}}break;case 19:Ar(n,e),to(e),r&4&&gC(e);break;case 21:break;default:Ar(n,e),to(e)}}function to(e){var n=e.flags;if(n&2){try{e:{for(var t=e.return;t!==null;){if(e2(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&&(Jc(o,""),r.flags&=-33);var s=fC(e);dv(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=fC(e);uv(e,a,i);break;default:throw Error(q(161))}}catch(l){mt(e,e.return,l)}e.flags&=-3}n&4096&&(e.flags&=-4097)}function aW(e,n,t){te=e,r2(e)}function r2(e,n,t){for(var r=(e.mode&1)!==0;te!==null;){var o=te,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||$d;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||rn;a=$d;var c=rn;if($d=i,(rn=l)&&!c)for(te=o;te!==null;)i=te,l=i.child,i.tag===22&&i.memoizedState!==null?SC(o):l!==null?(l.return=i,te=l):SC(o);for(;s!==null;)te=s,r2(s),s=s.sibling;te=o,$d=a,rn=c}mC(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,te=s):mC(e)}}function mC(e){for(;te!==null;){var n=te;if(n.flags&8772){var t=n.alternate;try{if(n.flags&8772)switch(n.tag){case 0:case 11:case 15:rn||Zf(5,n);break;case 1:var r=n.stateNode;if(n.flags&4&&!rn)if(t===null)r.componentDidMount();else{var o=n.elementType===n.type?t.memoizedProps:jr(n.type,t.memoizedProps);r.componentDidUpdate(o,t.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=n.updateQueue;s!==null&&eC(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}eC(n,i,t)}break;case 5:var a=n.stateNode;if(t===null&&n.flags&4){t=a;var l=n.memoizedProps;switch(n.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&t.focus();break;case"img":l.src&&(t.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(n.memoizedState===null){var c=n.alternate;if(c!==null){var u=c.memoizedState;if(u!==null){var h=u.dehydrated;h!==null&&ru(h)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(q(163))}rn||n.flags&512&&cv(n)}catch(p){mt(n,n.return,p)}}if(n===e){te=null;break}if(t=n.sibling,t!==null){t.return=n.return,te=t;break}te=n.return}}function yC(e){for(;te!==null;){var n=te;if(n===e){te=null;break}var t=n.sibling;if(t!==null){t.return=n.return,te=t;break}te=n.return}}function SC(e){for(;te!==null;){var n=te;try{switch(n.tag){case 0:case 11:case 15:var t=n.return;try{Zf(4,n)}catch(l){mt(n,t,l)}break;case 1:var r=n.stateNode;if(typeof r.componentDidMount=="function"){var o=n.return;try{r.componentDidMount()}catch(l){mt(n,o,l)}}var s=n.return;try{cv(n)}catch(l){mt(n,s,l)}break;case 5:var i=n.return;try{cv(n)}catch(l){mt(n,i,l)}}}catch(l){mt(n,n.return,l)}if(n===e){te=null;break}var a=n.sibling;if(a!==null){a.return=n.return,te=a;break}te=n.return}}var lW=Math.ceil,sf=is.ReactCurrentDispatcher,jw=is.ReactCurrentOwner,Pr=is.ReactCurrentBatchConfig,_e=0,Ot=null,Pt=null,Kt=0,Xn=0,Ua=ii(0),Et=0,fu=null,Wi=0,Qf=0,Ow=0,Nc=null,Mn=null,Dw=0,gl=1/0,Do=null,af=!1,hv=null,Bs=null,Fd=!1,Ts=null,lf=0,zc=0,pv=null,_h=-1,Th=0;function yn(){return _e&6?wt():_h!==-1?_h:_h=wt()}function Us(e){return e.mode&1?_e&2&&Kt!==0?Kt&-Kt:WK.transition!==null?(Th===0&&(Th=BT()),Th):(e=Fe,e!==0||(e=window.event,e=e===void 0?16:YT(e.type)),e):1}function Br(e,n,t,r){if(50<zc)throw zc=0,pv=null,Error(q(185));Fu(e,t,r),(!(_e&2)||e!==Ot)&&(e===Ot&&(!(_e&2)&&(Qf|=t),Et===4&&Es(e,Kt)),zn(e,r),t===1&&_e===0&&!(n.mode&1)&&(gl=wt()+500,Yf&&ai()))}function zn(e,n){var t=e.callbackNode;W7(e,n);var r=Kp(e,e===Ot?Kt:0);if(r===0)t!==null&&kP(t),e.callbackNode=null,e.callbackPriority=0;else if(n=r&-r,e.callbackPriority!==n){if(t!=null&&kP(t),n===1)e.tag===0?KK(vC.bind(null,e)):pM(vC.bind(null,e)),zK(function(){!(_e&6)&&ai()}),t=null;else{switch(UT(r)){case 1:t=iw;break;case 4:t=NT;break;case 16:t=Hp;break;case 536870912:t=zT;break;default:t=Hp}t=d2(t,o2.bind(null,e))}e.callbackPriority=n,e.callbackNode=t}}function o2(e,n){if(_h=-1,Th=0,_e&6)throw Error(q(327));var t=e.callbackNode;if(tl()&&e.callbackNode!==t)return null;var r=Kp(e,e===Ot?Kt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||n)n=cf(e,r);else{n=r;var o=_e;_e|=2;var s=i2();(Ot!==e||Kt!==n)&&(Do=null,gl=wt()+500,Di(e,n));do try{dW();break}catch(a){s2(e,a)}while(!0);vw(),sf.current=s,_e=o,Pt!==null?n=0:(Ot=null,Kt=0,n=Et)}if(n!==0){if(n===2&&(o=zS(e),o!==0&&(r=o,n=fv(e,o))),n===1)throw t=fu,Di(e,0),Es(e,r),zn(e,wt()),t;if(n===6)Es(e,r);else{if(o=e.current.alternate,!(r&30)&&!cW(o)&&(n=cf(e,r),n===2&&(s=zS(e),s!==0&&(r=s,n=fv(e,s))),n===1))throw t=fu,Di(e,0),Es(e,r),zn(e,wt()),t;switch(e.finishedWork=o,e.finishedLanes=r,n){case 0:case 1:throw Error(q(345));case 2:bi(e,Mn,Do);break;case 3:if(Es(e,r),(r&130023424)===r&&(n=Dw+500-wt(),10<n)){if(Kp(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){yn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=YS(bi.bind(null,e,Mn,Do),n);break}bi(e,Mn,Do);break;case 4:if(Es(e,r),(r&4194240)===r)break;for(n=e.eventTimes,o=-1;0<r;){var i=31-zr(r);s=1<<i,i=n[i],i>o&&(o=i),r&=~s}if(r=o,r=wt()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*lW(r/1960))-r,10<r){e.timeoutHandle=YS(bi.bind(null,e,Mn,Do),r);break}bi(e,Mn,Do);break;case 5:bi(e,Mn,Do);break;default:throw Error(q(329))}}}return zn(e,wt()),e.callbackNode===t?o2.bind(null,e):null}function fv(e,n){var t=Nc;return e.current.memoizedState.isDehydrated&&(Di(e,n).flags|=256),e=cf(e,n),e!==2&&(n=Mn,Mn=t,n!==null&&gv(n)),e}function gv(e){Mn===null?Mn=e:Mn.push.apply(Mn,e)}function cW(e){for(var n=e;;){if(n.flags&16384){var t=n.updateQueue;if(t!==null&&(t=t.stores,t!==null))for(var r=0;r<t.length;r++){var o=t[r],s=o.getSnapshot;o=o.value;try{if(!Kr(s(),o))return!1}catch{return!1}}}if(t=n.child,n.subtreeFlags&16384&&t!==null)t.return=n,n=t;else{if(n===e)break;for(;n.sibling===null;){if(n.return===null||n.return===e)return!0;n=n.return}n.sibling.return=n.return,n=n.sibling}}return!0}function Es(e,n){for(n&=~Ow,n&=~Qf,e.suspendedLanes|=n,e.pingedLanes&=~n,e=e.expirationTimes;0<n;){var t=31-zr(n),r=1<<t;e[t]=-1,n&=~r}}function vC(e){if(_e&6)throw Error(q(327));tl();var n=Kp(e,0);if(!(n&1))return zn(e,wt()),null;var t=cf(e,n);if(e.tag!==0&&t===2){var r=zS(e);r!==0&&(n=r,t=fv(e,r))}if(t===1)throw t=fu,Di(e,0),Es(e,n),zn(e,wt()),t;if(t===6)throw Error(q(345));return e.finishedWork=e.current.alternate,e.finishedLanes=n,bi(e,Mn,Do),zn(e,wt()),null}function Rw(e,n){var t=_e;_e|=1;try{return e(n)}finally{_e=t,_e===0&&(gl=wt()+500,Yf&&ai())}}function Gi(e){Ts!==null&&Ts.tag===0&&!(_e&6)&&tl();var n=_e;_e|=1;var t=Pr.transition,r=Fe;try{if(Pr.transition=null,Fe=1,e)return e()}finally{Fe=r,Pr.transition=t,_e=n,!(_e&6)&&ai()}}function Lw(){Xn=Ua.current,Je(Ua)}function Di(e,n){e.finishedWork=null,e.finishedLanes=0;var t=e.timeoutHandle;if(t!==-1&&(e.timeoutHandle=-1,NK(t)),Pt!==null)for(t=Pt.return;t!==null;){var r=t;switch(mw(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Xp();break;case 3:pl(),Je(Fn),Je(cn),Iw();break;case 5:Cw(r);break;case 4:pl();break;case 13:Je(ct);break;case 19:Je(ct);break;case 10:xw(r.type._context);break;case 22:case 23:Lw()}t=t.return}if(Ot=e,Pt=e=Hs(e.current,null),Kt=Xn=n,Et=0,fu=null,Ow=Qf=Wi=0,Mn=Nc=null,Ei!==null){for(n=0;n<Ei.length;n++)if(t=Ei[n],r=t.interleaved,r!==null){t.interleaved=null;var o=r.next,s=t.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}t.pending=r}Ei=null}return e}function s2(e,n){do{var t=Pt;try{if(vw(),Ih.current=of,rf){for(var r=ht.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}rf=!1}if(Ki=0,Tt=It=ht=null,$c=!1,du=0,jw.current=null,t===null||t.return===null){Et=1,fu=n,Pt=null;break}e:{var s=e,i=t.return,a=t,l=n;if(n=Kt,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,u=a,h=u.tag;if(!(u.mode&1)&&(h===0||h===11||h===15)){var p=u.alternate;p?(u.updateQueue=p.updateQueue,u.memoizedState=p.memoizedState,u.lanes=p.lanes):(u.updateQueue=null,u.memoizedState=null)}var f=iC(i);if(f!==null){f.flags&=-257,aC(f,i,a,s,n),f.mode&1&&sC(s,c,n),n=f,l=c;var S=n.updateQueue;if(S===null){var m=new Set;m.add(l),n.updateQueue=m}else S.add(l);break e}else{if(!(n&1)){sC(s,c,n),$w();break e}l=Error(q(426))}}else if(nt&&a.mode&1){var x=iC(i);if(x!==null){!(x.flags&65536)&&(x.flags|=256),aC(x,i,a,s,n),yw(fl(l,a));break e}}s=l=fl(l,a),Et!==4&&(Et=2),Nc===null?Nc=[s]:Nc.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,n&=-n,s.lanes|=n;var y=UM(s,l,n);JP(s,y);break e;case 1:a=l;var v=s.type,b=s.stateNode;if(!(s.flags&128)&&(typeof v.getDerivedStateFromError=="function"||b!==null&&typeof b.componentDidCatch=="function"&&(Bs===null||!Bs.has(b)))){s.flags|=65536,n&=-n,s.lanes|=n;var E=HM(s,a,n);JP(s,E);break e}}s=s.return}while(s!==null)}l2(t)}catch(I){n=I,Pt===t&&t!==null&&(Pt=t=t.return);continue}break}while(!0)}function i2(){var e=sf.current;return sf.current=of,e===null?of:e}function $w(){(Et===0||Et===3||Et===2)&&(Et=4),Ot===null||!(Wi&268435455)&&!(Qf&268435455)||Es(Ot,Kt)}function cf(e,n){var t=_e;_e|=2;var r=i2();(Ot!==e||Kt!==n)&&(Do=null,Di(e,n));do try{uW();break}catch(o){s2(e,o)}while(!0);if(vw(),_e=t,sf.current=r,Pt!==null)throw Error(q(261));return Ot=null,Kt=0,Et}function uW(){for(;Pt!==null;)a2(Pt)}function dW(){for(;Pt!==null&&!L7();)a2(Pt)}function a2(e){var n=u2(e.alternate,e,Xn);e.memoizedProps=e.pendingProps,n===null?l2(e):Pt=n,jw.current=null}function l2(e){var n=e;do{var t=n.alternate;if(e=n.return,n.flags&32768){if(t=oW(t,n),t!==null){t.flags&=32767,Pt=t;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Et=6,Pt=null;return}}else if(t=rW(t,n,Xn),t!==null){Pt=t;return}if(n=n.sibling,n!==null){Pt=n;return}Pt=n=e}while(n!==null);Et===0&&(Et=5)}function bi(e,n,t){var r=Fe,o=Pr.transition;try{Pr.transition=null,Fe=1,hW(e,n,t,r)}finally{Pr.transition=o,Fe=r}return null}function hW(e,n,t,r){do tl();while(Ts!==null);if(_e&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(G7(e,s),e===Ot&&(Pt=Ot=null,Kt=0),!(t.subtreeFlags&2064)&&!(t.flags&2064)||Fd||(Fd=!0,d2(Hp,function(){return tl(),null})),s=(t.flags&15990)!==0,t.subtreeFlags&15990||s){s=Pr.transition,Pr.transition=null;var i=Fe;Fe=1;var a=_e;_e|=4,jw.current=null,iW(e,t),n2(t,e),jK(GS),Wp=!!WS,GS=WS=null,e.current=t,aW(t),$7(),_e=a,Fe=i,Pr.transition=s}else e.current=t;if(Fd&&(Fd=!1,Ts=e,lf=o),s=e.pendingLanes,s===0&&(Bs=null),z7(t.stateNode),zn(e,wt()),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(af)throw af=!1,e=hv,hv=null,e;return lf&1&&e.tag!==0&&tl(),s=e.pendingLanes,s&1?e===pv?zc++:(zc=0,pv=e):zc=0,ai(),null}function tl(){if(Ts!==null){var e=UT(lf),n=Pr.transition,t=Fe;try{if(Pr.transition=null,Fe=16>e?16:e,Ts===null)var r=!1;else{if(e=Ts,Ts=null,lf=0,_e&6)throw Error(q(331));var o=_e;for(_e|=4,te=e.current;te!==null;){var s=te,i=s.child;if(te.flags&16){var a=s.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(te=c;te!==null;){var u=te;switch(u.tag){case 0:case 11:case 15:Fc(8,u,s)}var h=u.child;if(h!==null)h.return=u,te=h;else for(;te!==null;){u=te;var p=u.sibling,f=u.return;if(JM(u),u===c){te=null;break}if(p!==null){p.return=f,te=p;break}te=f}}}var S=s.alternate;if(S!==null){var m=S.child;if(m!==null){S.child=null;do{var x=m.sibling;m.sibling=null,m=x}while(m!==null)}}te=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,te=i;else e:for(;te!==null;){if(s=te,s.flags&2048)switch(s.tag){case 0:case 11:case 15:Fc(9,s,s.return)}var y=s.sibling;if(y!==null){y.return=s.return,te=y;break e}te=s.return}}var v=e.current;for(te=v;te!==null;){i=te;var b=i.child;if(i.subtreeFlags&2064&&b!==null)b.return=i,te=b;else e:for(i=v;te!==null;){if(a=te,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:Zf(9,a)}}catch(I){mt(a,a.return,I)}if(a===i){te=null;break e}var E=a.sibling;if(E!==null){E.return=a.return,te=E;break e}te=a.return}}if(_e=o,ai(),fo&&typeof fo.onPostCommitFiberRoot=="function")try{fo.onPostCommitFiberRoot(Hf,e)}catch{}r=!0}return r}finally{Fe=t,Pr.transition=n}}return!1}function xC(e,n,t){n=fl(t,n),n=UM(e,n,1),e=zs(e,n,1),n=yn(),e!==null&&(Fu(e,1,n),zn(e,n))}function mt(e,n,t){if(e.tag===3)xC(e,e,t);else for(;n!==null;){if(n.tag===3){xC(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=fl(t,e),e=HM(n,e,1),n=zs(n,e,1),e=yn(),n!==null&&(Fu(n,1,e),zn(n,e));break}}n=n.return}}function pW(e,n,t){var r=e.pingCache;r!==null&&r.delete(n),n=yn(),e.pingedLanes|=e.suspendedLanes&t,Ot===e&&(Kt&t)===t&&(Et===4||Et===3&&(Kt&130023424)===Kt&&500>wt()-Dw?Di(e,0):Ow|=t),zn(e,n)}function c2(e,n){n===0&&(e.mode&1?(n=_d,_d<<=1,!(_d&130023424)&&(_d=4194304)):n=1);var t=yn();e=Qo(e,n),e!==null&&(Fu(e,n,t),zn(e,t))}function fW(e){var n=e.memoizedState,t=0;n!==null&&(t=n.retryLane),c2(e,t)}function gW(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),c2(e,t)}var u2;u2=function(e,n,t){if(e!==null)if(e.memoizedProps!==n.pendingProps||Fn.current)Dn=!0;else{if(!(e.lanes&t)&&!(n.flags&128))return Dn=!1,nW(e,n,t);Dn=!!(e.flags&131072)}else Dn=!1,nt&&n.flags&1048576&&fM(n,Qp,n.index);switch(n.lanes=0,n.tag){case 2:var r=n.type;kh(e,n),e=n.pendingProps;var o=ul(n,cn.current);el(n,t),o=kw(null,n,r,e,o,t);var s=_w();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,Nn(r)?(s=!0,qp(n)):s=!1,n.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,bw(n),o.updater=qf,n.stateNode=o,o._reactInternals=n,tv(n,r,e,t),n=ov(null,n,r,!0,s,t)):(n.tag=0,nt&&s&&gw(n),fn(null,n,o,t),n=n.child),n;case 16:r=n.elementType;e:{switch(kh(e,n),e=n.pendingProps,o=r._init,r=o(r._payload),n.type=r,o=n.tag=yW(r),e=jr(r,e),o){case 0:n=rv(null,n,r,e,t);break e;case 1:n=uC(null,n,r,e,t);break e;case 11:n=lC(null,n,r,e,t);break e;case 14:n=cC(null,n,r,jr(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:jr(r,o),rv(e,n,r,o,t);case 1:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),uC(e,n,r,o,t);case 3:e:{if(VM(n),e===null)throw Error(q(387));r=n.pendingProps,s=n.memoizedState,o=s.element,xM(e,n),tf(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=fl(Error(q(423)),n),n=dC(e,n,r,t,o);break e}else if(r!==o){o=fl(Error(q(424)),n),n=dC(e,n,r,t,o);break e}else for(Qn=Ns(n.stateNode.containerInfo.firstChild),nr=n,nt=!0,$r=null,t=SM(n,null,r,t),n.child=t;t;)t.flags=t.flags&-3|4096,t=t.sibling;else{if(dl(),r===o){n=Jo(e,n,t);break e}fn(e,n,r,t)}n=n.child}return n;case 5:return wM(n),e===null&&QS(n),r=n.type,o=n.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,VS(r,o)?i=null:s!==null&&VS(r,s)&&(n.flags|=32),GM(e,n),fn(e,n,i,t),n.child;case 6:return e===null&&QS(n),null;case 13:return YM(e,n,t);case 4:return Pw(n,n.stateNode.containerInfo),r=n.pendingProps,e===null?n.child=hl(n,null,r,t):fn(e,n,r,t),n.child;case 11:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),lC(e,n,r,o,t);case 7:return fn(e,n,n.pendingProps,t),n.child;case 8:return fn(e,n,n.pendingProps.children,t),n.child;case 12:return fn(e,n,n.pendingProps.children,t),n.child;case 10:e:{if(r=n.type._context,o=n.pendingProps,s=n.memoizedProps,i=o.value,Ve(Jp,r._currentValue),r._currentValue=i,s!==null)if(Kr(s.value,i)){if(s.children===o.children&&!Fn.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 l=a.firstContext;l!==null;){if(l.context===r){if(s.tag===1){l=Ko(-1,t&-t),l.tag=2;var c=s.updateQueue;if(c!==null){c=c.shared;var u=c.pending;u===null?l.next=l:(l.next=u.next,u.next=l),c.pending=l}}s.lanes|=t,l=s.alternate,l!==null&&(l.lanes|=t),JS(s.return,t,n),a.lanes|=t;break}l=l.next}}else if(s.tag===10)i=s.type===n.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(q(341));i.lanes|=t,a=i.alternate,a!==null&&(a.lanes|=t),JS(i,t,n),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===n){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}fn(e,n,o.children,t),n=n.child}return n;case 9:return o=n.type,r=n.pendingProps.children,el(n,t),o=Ir(o),r=r(o),n.flags|=1,fn(e,n,r,t),n.child;case 14:return r=n.type,o=jr(r,n.pendingProps),o=jr(r.type,o),cC(e,n,r,o,t);case 15:return KM(e,n,n.type,n.pendingProps,t);case 17:return r=n.type,o=n.pendingProps,o=n.elementType===r?o:jr(r,o),kh(e,n),n.tag=1,Nn(r)?(e=!0,qp(n)):e=!1,el(n,t),BM(n,r,o),tv(n,r,o,t),ov(null,n,r,!0,e,t);case 19:return XM(e,n,t);case 22:return WM(e,n,t)}throw Error(q(156,n.tag))};function d2(e,n){return FT(e,n)}function mW(e,n,t,r){this.tag=e,this.key=t,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=n,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function wr(e,n,t,r){return new mW(e,n,t,r)}function Fw(e){return e=e.prototype,!(!e||!e.isReactComponent)}function yW(e){if(typeof e=="function")return Fw(e)?1:0;if(e!=null){if(e=e.$$typeof,e===rw)return 11;if(e===ow)return 14}return 2}function Hs(e,n){var t=e.alternate;return t===null?(t=wr(e.tag,n,e.key,e.mode),t.elementType=e.elementType,t.type=e.type,t.stateNode=e.stateNode,t.alternate=e,e.alternate=t):(t.pendingProps=n,t.type=e.type,t.flags=0,t.subtreeFlags=0,t.deletions=null),t.flags=e.flags&14680064,t.childLanes=e.childLanes,t.lanes=e.lanes,t.child=e.child,t.memoizedProps=e.memoizedProps,t.memoizedState=e.memoizedState,t.updateQueue=e.updateQueue,n=e.dependencies,t.dependencies=n===null?null:{lanes:n.lanes,firstContext:n.firstContext},t.sibling=e.sibling,t.index=e.index,t.ref=e.ref,t}function Mh(e,n,t,r,o,s){var i=2;if(r=e,typeof e=="function")Fw(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case ja:return Ri(t.children,o,s,n);case nw:i=8,o|=8;break;case IS:return e=wr(12,t,n,o|2),e.elementType=IS,e.lanes=s,e;case ES:return e=wr(13,t,n,o),e.elementType=ES,e.lanes=s,e;case kS:return e=wr(19,t,n,o),e.elementType=kS,e.lanes=s,e;case wT:return Jf(t,o,s,n);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case vT:i=10;break e;case xT:i=9;break e;case rw:i=11;break e;case ow:i=14;break e;case bs:i=16,r=null;break e}throw Error(q(130,e==null?e:typeof e,""))}return n=wr(i,t,n,o),n.elementType=e,n.type=r,n.lanes=s,n}function Ri(e,n,t,r){return e=wr(7,e,r,n),e.lanes=t,e}function Jf(e,n,t,r){return e=wr(22,e,r,n),e.elementType=wT,e.lanes=t,e.stateNode={isHidden:!1},e}function Xm(e,n,t){return e=wr(6,e,null,n),e.lanes=t,e}function qm(e,n,t){return n=wr(4,e.children!==null?e.children:[],e.key,n),n.lanes=t,n.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},n}function SW(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=Mm(0),this.expirationTimes=Mm(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Mm(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function Nw(e,n,t,r,o,s,i,a,l){return e=new SW(e,n,t,a,l),n===1?(n=1,s===!0&&(n|=8)):n=0,s=wr(3,null,null,n),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:t,cache:null,transitions:null,pendingSuspenseBoundaries:null},bw(s),e}function vW(e,n,t){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:Aa,key:r==null?null:""+r,children:e,containerInfo:n,implementation:t}}function h2(e){if(!e)return Vs;e=e._reactInternals;e:{if(ia(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(Nn(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(Nn(t))return hM(e,t,n)}return n}function p2(e,n,t,r,o,s,i,a,l){return e=Nw(t,r,!0,e,o,s,i,a,l),e.context=h2(null),t=e.current,r=yn(),o=Us(t),s=Ko(r,o),s.callback=n??null,zs(t,s,o),e.current.lanes=o,Fu(e,o,r),zn(e,r),e}function eg(e,n,t,r){var o=n.current,s=yn(),i=Us(o);return t=h2(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=zs(o,n,i),e!==null&&(Br(e,o,i,s),Ch(e,o,i)),i}function uf(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 wC(e,n){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var t=e.retryLane;e.retryLane=t!==0&&t<n?t:n}}function zw(e,n){wC(e,n),(e=e.alternate)&&wC(e,n)}function xW(){return null}var f2=typeof reportError=="function"?reportError:function(e){console.error(e)};function Bw(e){this._internalRoot=e}tg.prototype.render=Bw.prototype.render=function(e){var n=this._internalRoot;if(n===null)throw Error(q(409));eg(e,n,null,null)};tg.prototype.unmount=Bw.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var n=e.containerInfo;Gi(function(){eg(null,e,null,null)}),n[Zo]=null}};function tg(e){this._internalRoot=e}tg.prototype.unstable_scheduleHydration=function(e){if(e){var n=WT();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&&VT(e)}};function Uw(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function ng(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function bC(){}function wW(e,n,t,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=uf(i);s.call(c)}}var i=p2(n,r,e,0,null,!1,!1,"",bC);return e._reactRootContainer=i,e[Zo]=i.current,iu(e.nodeType===8?e.parentNode:e),Gi(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=uf(l);a.call(c)}}var l=Nw(e,0,!1,null,null,!1,!1,"",bC);return e._reactRootContainer=l,e[Zo]=l.current,iu(e.nodeType===8?e.parentNode:e),Gi(function(){eg(n,l,t,r)}),l}function rg(e,n,t,r,o){var s=t._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var l=uf(i);a.call(l)}}eg(n,i,e,o)}else i=wW(t,n,e,o,r);return uf(i)}HT=function(e){switch(e.tag){case 3:var n=e.stateNode;if(n.current.memoizedState.isDehydrated){var t=bc(n.pendingLanes);t!==0&&(aw(n,t|1),zn(n,wt()),!(_e&6)&&(gl=wt()+500,ai()))}break;case 13:Gi(function(){var r=Qo(e,1);if(r!==null){var o=yn();Br(r,e,1,o)}}),zw(e,1)}};lw=function(e){if(e.tag===13){var n=Qo(e,134217728);if(n!==null){var t=yn();Br(n,e,134217728,t)}zw(e,134217728)}};KT=function(e){if(e.tag===13){var n=Us(e),t=Qo(e,n);if(t!==null){var r=yn();Br(t,e,n,r)}zw(e,n)}};WT=function(){return Fe};GT=function(e,n){var t=Fe;try{return Fe=e,n()}finally{Fe=t}};$S=function(e,n,t){switch(n){case"input":if(MS(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=Vf(r);if(!o)throw Error(q(90));PT(r),MS(r,o)}}}break;case"textarea":IT(e,t);break;case"select":n=t.value,n!=null&&qa(e,!!t.multiple,n,!1)}};jT=Rw;OT=Gi;var bW={usingClientEntryPoint:!1,Events:[zu,La,Vf,MT,AT,Rw]},ac={findFiberByHostInstance:Ii,bundleType:0,version:"18.3.1",rendererPackageName:"react-dom"},PW={bundleType:ac.bundleType,version:ac.version,rendererPackageName:ac.rendererPackageName,rendererConfig:ac.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=LT(e),e===null?null:e.stateNode},findFiberByHostInstance:ac.findFiberByHostInstance||xW,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 Nd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Nd.isDisabled&&Nd.supportsFiber)try{Hf=Nd.inject(PW),fo=Nd}catch{}}cr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=bW;cr.createPortal=function(e,n){var t=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Uw(n))throw Error(q(200));return vW(e,n,null,t)};cr.createRoot=function(e,n){if(!Uw(e))throw Error(q(299));var t=!1,r="",o=f2;return n!=null&&(n.unstable_strictMode===!0&&(t=!0),n.identifierPrefix!==void 0&&(r=n.identifierPrefix),n.onRecoverableError!==void 0&&(o=n.onRecoverableError)),n=Nw(e,1,!1,null,null,t,!1,r,o),e[Zo]=n.current,iu(e.nodeType===8?e.parentNode:e),new Bw(n)};cr.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var n=e._reactInternals;if(n===void 0)throw typeof e.render=="function"?Error(q(188)):(e=Object.keys(e).join(","),Error(q(268,e)));return e=LT(n),e=e===null?null:e.stateNode,e};cr.flushSync=function(e){return Gi(e)};cr.hydrate=function(e,n,t){if(!ng(n))throw Error(q(200));return rg(null,e,n,!0,t)};cr.hydrateRoot=function(e,n,t){if(!Uw(e))throw Error(q(405));var r=t!=null&&t.hydratedSources||null,o=!1,s="",i=f2;if(t!=null&&(t.unstable_strictMode===!0&&(o=!0),t.identifierPrefix!==void 0&&(s=t.identifierPrefix),t.onRecoverableError!==void 0&&(i=t.onRecoverableError)),n=p2(n,null,e,1,t??null,o,!1,s,i),e[Zo]=n.current,iu(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 tg(n)};cr.render=function(e,n,t){if(!ng(n))throw Error(q(200));return rg(null,e,n,!1,t)};cr.unmountComponentAtNode=function(e){if(!ng(e))throw Error(q(40));return e._reactRootContainer?(Gi(function(){rg(null,null,e,!1,function(){e._reactRootContainer=null,e[Zo]=null})}),!0):!1};cr.unstable_batchedUpdates=Rw;cr.unstable_renderSubtreeIntoContainer=function(e,n,t,r){if(!ng(t))throw Error(q(200));if(e==null||e._reactInternals===void 0)throw Error(q(38));return rg(e,n,t,!1,r)};cr.version="18.3.1-next-f1338f8080-20240426";function g2(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(g2)}catch(e){console.error(e)}}g2(),gT.exports=cr;var aa=gT.exports;const CW=ei(aa);var mv={},m2,PC=aa;m2=mv.createRoot=PC.createRoot,mv.hydrateRoot=PC.hydrateRoot;const nl="TLDRAW_TAB_ID_v2",mo=globalThis.window;function IW(){return mo?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(mo.navigator.platform)||mo.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const df=mo?mo[nl]??Ak(nl)??"TLDRAW_INSTANCE_STATE_V1_"+ot():"<error>";mo&&(mo[nl]=df,IW()?jx(nl,df):jk(nl));mo==null||mo.addEventListener("beforeunload",()=>{jx(nl,df)});const y2={Initial:0},og=Math.max(...Object.values(y2));function EW(e){e.version<y2.Initial,e.version=og}const S2=Se({version:de,currentPageId:Yc,isFocusMode:we,exportBackground:we,isDebugMode:we,isToolLocked:we,isGridMode:we,pageStates:zt(Se({pageId:Yc,camera:Se({x:de,y:de,z:de}),selectedShapeIds:zt(mr),focusedGroupId:mr.nullable()}))});function kW(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!==og&&(e=rt(e),EW(e));try{return S2.validate(e)}catch(n){return console.warn(n),null}}function v2(e){const n=e.query.ids("page");return V("sessionStateSnapshot",()=>{const t=e.get(mn);if(!t)return null;const r=[...n.get()];return{version:og,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(Fr.createId(o)),i=e.get(co.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 x2(e,n){const t=kW(n);if(!t)return;const r=e.schema.types.instance.create({id:mn,...l_(e.get(mn)),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([co.create({id:co.createId(s.pageId),x:s.camera.x,y:s.camera.y,z:s.camera.z}),Fr.create({id:Fr.createId(s.pageId),pageId:s.pageId,selectedShapeIds:s.selectedShapeIds,focusedGroupId:s.focusedGroupId})]);e.put([r]),e.ensureStoreIsUsable()})}function _W(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!==mn)[0];if(!t)return null;const r={version:og,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 S2.validate(r),r}catch{return null}}function w2(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:_c(o.value,(s,{typeName:i})=>e.scopedTypes.document.has(i))}}else t=n;const r=l_(e.get(mn));e.atomic(()=>{t.document&&e.loadStoreSnapshot(t.document),r&&e.update(mn,o=>({...o,...r})),t.session&&x2(e,t.session)})}const TW=new Yo;function MW(e){const t=TW.get(e,v2).get();if(!t)throw new Error("Session state is not ready yet");return{document:e.getStoreSnapshot(),session:t}}function b2(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 d.jsx("svg",{...t,className:ce("tl-svg-container",n),children:e})}function Hw(e,n,t,r){const o=e.x-t.x,s=e.y-t.y,i=r.x-t.x,a=r.y-t.y,l=n.x-e.x,c=n.y-e.y,u=i*s-a*o,h=l*s-c*o,p=a*l-i*c;if(u===0||h===0||p===0)return null;if(p!==0){const f=u/p,S=h/p;if(0<=f&&f<=1&&0<=S&&S<=1)return w.AddXY(e,f*l,f*c)}return null}function Uu(e,n,t,r){const o=(n.x-e.x)*(n.x-e.x)+(n.y-e.y)*(n.y-e.y),s=2*((n.x-e.x)*(e.x-t.x)+(n.y-e.y)*(e.y-t.y)),i=t.x*t.x+t.y*t.y+e.x*e.x+e.y*e.y-2*(t.x*e.x+t.y*e.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-s+l)/(2*o),u=(-s-l)/(2*o);if((c<0||c>1)&&(u<0||u>1))return null;const h=[];return 0<=c&&c<=1&&h.push(w.Lrp(e,n,c)),0<=u&&u<=1&&h.push(w.Lrp(e,n,u)),h.length===0?null:h}function AW(e,n,t){const r=[];let o;for(let s=0,i=t.length-1;s<i;s++)o=Hw(e,n,t[s],t[s+1]),o&&r.push(o);return r.length===0?null:r}function Kw(e,n,t){const r=[];let o;for(let s=1,i=t.length;s<i+1;s++)o=Hw(e,n,t[s-1],t[s%t.length]),o&&r.push(o);return r.length===0?null:r}function jW(e,n,t,r){let o=t.x-e.x,s=t.y-e.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+n*n)/(2*i),l=Math.sqrt(n*n-a*a);return o/=i,s/=i,[new w(e.x+o*a-s*l,e.y+s*a+o*l),new w(e.x+o*a+s*l,e.y+s*a-o*l)]}function yv(e,n,t){const r=[];let o,s,i;for(let a=0,l=t.length;a<l;a++)o=t[a],s=t[(a+1)%t.length],i=Uu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function CC(e,n,t){const r=[];let o,s,i;for(let a=1,l=t.length;a<l;a++)o=t[a-1],s=t[a],i=Uu(o,s,e,n),i&&r.push(...i);return r.length===0?null:r}function zd(e,n,t){return(t.y-e.y)*(n.x-e.x)>(n.y-e.y)*(t.x-e.x)}function Ww(e,n,t,r){return zd(e,t,r)!==zd(n,t,r)&&zd(e,n,t)!==zd(e,n,r)}function IC(e,n){const t=new Map;let r,o,s,i;for(let a=0,l=e.length;a<l;a++)if(r=e[a],tr(r,n)){const c=Zm(r);t.has(c)||t.set(c,r)}for(let a=0,l=n.length;a<l;a++)if(r=n[a],tr(r,e)){const c=Zm(r);t.has(c)||t.set(c,r)}for(let a=0,l=e.length;a<l;a++){r=e[a],o=e[(a+1)%e.length];for(let c=0,u=n.length;c<u;c++){s=n[c],i=n[(c+1)%n.length];const h=Hw(r,o,s,i);if(h!==null){const p=Zm(h);t.has(p)||t.set(p,h)}}}return t.size===0?null:OW([...t.values()])}function Zm(e){return`${e.x},${e.y}`}function OW(e){const n=w.Average(e);return e.sort((t,r)=>w.Angle(n,t)-w.Angle(n,r))}function P2(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let l=0,c=n.length;l<c;l++)if(o=n[l],s=n[(l+1)%c],Ww(t,r,o,s))return!0}return!1}function DW(e,n){let t,r,o,s;for(let i=0,a=e.length;i<a;i++){t=e[i],r=e[(i+1)%a];for(let l=1,c=n.length;l<c;l++)if(o=n[l-1],s=n[l],Ww(t,r,o,s))return!0}return!1}class Bo extends oi{constructor(t){super({...t,isClosed:!1,isFilled:!1});g(this,"start");g(this,"end");g(this,"d");g(this,"u");g(this,"ul");const{start:r,end:o}=t;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}getLength(){return this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(t){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=w.Sub(t,r).dpr(s)/i,l=r.x+s.x*a;if(l<Math.min(r.x,o.x))return r.x<o.x?r:o;if(l>Math.max(r.x,o.x))return r.x>o.x?r:o;const c=r.y+s.y*a;return c<Math.min(r.y,o.y)?r.y<o.y?r:o:c>Math.max(r.y,o.y)?r.y>o.y?r:o:new w(l,c)}hitTestLineSegment(t,r,o=0){return Ww(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 Ll extends oi{constructor(t){super({isClosed:!1,isFilled:!1,...t});g(this,"points");g(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:t}=this;for(let r=0,o=t.length-1;r<o;r++){const s=t[r],i=t[r+1];this._segments.push(new 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 l=0;l<r.length;l++)i=r[l].nearestPoint(t),a=w.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 vt extends Ll{constructor(n){super({...n}),this.isClosed=!0}}class es extends vt{constructor(t){const{x:r=0,y:o=0,width:s,height:i}=t;super({...t,points:[new w(r,o),new w(r+s,o),new w(r+s,o+i),new w(r,o+i)]});g(this,"x");g(this,"y");g(this,"w");g(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new Z(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 Ur{constructor(n){g(this,"canSnap",()=>!0);g(this,"canScroll",()=>!1);g(this,"canEdit",()=>!1);g(this,"canResize",()=>!0);g(this,"canEditInReadOnly",()=>!1);g(this,"canCrop",()=>!1);g(this,"canBeLaidOut",()=>!0);g(this,"hideResizeHandles",()=>!1);g(this,"hideRotateHandle",()=>!1);g(this,"hideSelectionBoundsBg",()=>!1);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"isAspectRatioLocked",()=>!1);g(this,"onBeforeCreate");g(this,"onBeforeUpdate");g(this,"onDragShapesOver");g(this,"onDragShapesOut");g(this,"onDropShapesOver");g(this,"onResizeStart");g(this,"onResize");g(this,"onResizeEnd");g(this,"onTranslateStart");g(this,"onTranslate");g(this,"onTranslateEnd");g(this,"onHandleDrag");g(this,"onRotateStart");g(this,"onRotate");g(this,"onRotateEnd");g(this,"onBindingChange");g(this,"onChildrenChange");g(this,"onDoubleClickHandle");g(this,"onDoubleClickEdge");g(this,"onDoubleClick");g(this,"onClick");g(this,"onEditEnd");this.editor=n}canBind(n){return!0}providesBackgroundForChildren(n){return!1}canReceiveNewChildrenOfType(n,t){return!1}canDropShapes(n,t){return!1}expandSelectionOutlinePx(n){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(n){return{}}getHandleSnapGeometry(n){return{}}}g(Ur,"props"),g(Ur,"migrations"),g(Ur,"type");function RW(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=t;let c=0,u=0,h=1,p=0,f=0;switch(l){case"dashed":{h=1,c=Math.min(n*a,e/4);break}case"dotted":{h=100,c=n/h;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=c/2,f+=c/2):s==="skip"&&(e-=c,f-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),u=Math.floor(e/c/(2*h)),u-=u%o,u<3&&l==="dashed"?e/n<5?(c=e,u=1,p=0):(c=e*.333,p=e*.333):(u=Math.max(u,3),c=e/u/(2*h),r?(f=c/2,p=(e-u*c)/u):p=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}function EC({bounds:e,className:n}){const t=B(),r=G("zoom level",()=>t.getZoomLevel(),[t]);return d.jsx("g",{className:n,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=RW(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return d.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class Ah extends Ur{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"canBind",()=>!1);g(this,"onChildrenChange",t=>{const r=this.editor.getSortedChildIdsForParent(t.id);if(r.length===0){this.editor.getCurrentPageState().focusedGroupId===t.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([t.id]);return}else if(r.length===1){this.editor.getCurrentPageState().focusedGroupId===t.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(r,t.parentId),this.editor.deleteShapes([t.id]);return}})}getDefaultProps(){return{}}getGeometry(t){const r=this.editor.getSortedChildIdsForParent(t.id);return r.length===0?new es({width:1,height:1,isFilled:!1}):new Hr({children:r.map(o=>{const s=this.editor.getShape(o),i=this.editor.getShapeGeometry(o),a=this.editor.getShapeLocalTransform(s).applyToPoints(i.vertices);return i.isClosed?new vt({points:a,isFilled:!0}):new Ll({points:a})})})}component(t){const r=this.editor.getErasingShapeIds().includes(t.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(l=>l!==t.id&&this.editor.isShapeOfType(this.editor.getShape(l),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==t.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(t).bounds;return d.jsx(Ys,{id:t.id,children:d.jsx(EC,{className:"tl-group",bounds:a})})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return d.jsx(EC,{className:"",bounds:r})}}g(Ah,"type","group"),g(Ah,"props",x_),g(Ah,"migrations",w_);const C2=[Ah],LW=new Set(C2.map(e=>e.type));function I2(e){const n=[...C2],t=new Set;for(const r of e){if(LW.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 $W={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 kC(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 an(e)}}class FW{constructor(n){g(this,"map");this.map=new Map(n)}get(n){return this.map.get(n)}getAsKnownValue(n){const t=this.get(n);if(t&&t.type!=="mixed")return t.value}get size(){return this.map.size}equals(n){if(this.size!==n.size)return!1;const t=new Set;for(const[r,o]of this){if(!kC(o,n.get(r)))return!1;t.add(r)}for(const[r,o]of n)if(!t.has(r)&&!kC(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 Sv extends FW{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:an(r,"type")}}}function NW(e,n,t){return So(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],n,{type:t})})}function zW(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 Bd(e,n,t){if(t.length===0)return[];const r=new Map;for(const s of me(t.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:me(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})=>BW(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>UW(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>HW(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>KW(s,i,o));break}}return o}function BW(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=ll(o,s,e.size);t.push(...Array.from(e.values()).sort(on).map((a,l)=>({...a,index:i[l]})))}}function UW(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=ll(o,s,e.size);t.push(...Array.from(e.values()).sort(on).map((a,l)=>({...a,index:i[l]})))}}function HW(e,n,t){var s;const r=n.length;if(e.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(n[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=o;ll(n[i].index,(s=n[i+1])==null?void 0:s.index,i-l).forEach((c,u)=>t.push({...n[l+u],index:c})),o={name:"skipping"};break}}}}function KW(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;ll((s=n[i-1])==null?void 0:s.index,n[i].index,o.selectIndex-i).forEach((l,c)=>{t.push({...n[i+c+1],index:l})}),o={name:"skipping"};break}}}}function E2({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:rt(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function jh({delta:e,editor:n,snapshot:t,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=t;n.updateShapes(s.map(({shape:a,initialPagePoint:l})=>{const c=_n(a.parentId)?n.getShapePageTransform(a.parentId):oe.Identity(),u=w.RotWith(l,o,e),h=oe.applyToPoint(oe.Inverse(c),u),p=Rs(a.rotation+e);return{id:a.id,type:a.type,x:h.x,y:h.y,rotation:p}}));const i=[];s.forEach(({shape:a})=>{var h,p,f;const l=n.getShape(a.id);if(!l)return;const c=n.getShapeUtil(a);if(r==="start"||r==="one-off"){const S=(h=c.onRotateStart)==null?void 0:h.call(c,a);S&&i.push(S)}const u=(p=c.onRotate)==null?void 0:p.call(c,a,l);if(u&&i.push(u),r==="end"||r==="one-off"){const S=(f=c.onRotateEnd)==null?void 0:f.call(c,a,l);S&&i.push(S)}}),i.length>0&&n.updateShapes(i)}const WW=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:l,toId:c}=a,u=i.get(l);u?u.push(a):i.set(l,[a]);const h=i.get(c);h?h.push(a):i.set(c,[a])}return i}return V("arrowBindingsIndex",(s,i)=>{if(ji(s))return o();const a=s,l=t.getDiffSince(i);if(l===Jn)return o();let c;function u(f){c??(c=new Map(a));const S=c.get(f.fromId),m=S==null?void 0:S.filter(v=>v.id!==f.id);m!=null&&m.length?c.set(f.fromId,m):c.delete(f.fromId);const x=c.get(f.toId),y=x==null?void 0:x.filter(v=>v.id!==f.id);y!=null&&y.length?c.set(f.toId,y):c.delete(f.toId)}function h(f){c??(c=new Map(a));let S=c.get(f);return S?S===a.get(f)&&(S=S.slice(0),c.set(f,S)):(S=[],c.set(f,S)),S}function p(f){h(f.fromId).push(f),h(f.toId).push(f)}for(const f of l){for(const S of gt(f.added))p(S);for(const[S,m]of gt(f.updated))u(S),p(m);for(const S of gt(f.removed))u(S)}return c??a})};function GW(e,n,t){const r=e.getShapeMaskedPageBounds(n);return r===void 0?!0:!t.includes(r)}const VW=e=>{function n(t){const r=t.getCurrentPageShapeIds(),o=t.getViewportPageBounds(),s=new Set;return r.forEach(i=>{GW(t,i,o)&&s.add(i)}),s}return V("getCulledShapes",t=>{if(ji(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})},YW=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(on),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return V("parentsToChildrenWithIndexes",(o,s)=>{if(ji(o))return r();const i=t.getDiffSince(s);if(i===Jn)return r();if(i.length===0)return o;let a=null;const l=h=>{a||(a={...o}),a[h]?a[h]===o[h]&&(a[h]=[...a[h]]):a[h]=[]},c=new Set;let u;for(let h=0,p=i.length;h<p;h++){u=i[h];for(const f of Object.values(u.added))Ma(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,S]of Object.values(u.updated))if(Ma(S)&&Ma(f)){if(f.parentId!==S.parentId)l(f.parentId),l(S.parentId),a[f.parentId].splice(a[f.parentId].indexOf(S.id),1),a[S.parentId].push(S.id),c.add(a[S.parentId]);else if(f.index!==S.index){l(S.parentId);const m=a[S.parentId].indexOf(S.id);a[S.parentId][m]=S.id,c.add(a[S.parentId])}}for(const f of Object.values(u.removed))Ma(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const h of c){const p=me(h.map(f=>e.get(f)));p.sort(on),h.splice(0,h.length,...p.map(f=>f.id))}return a??o})},Qm=(e,n,t)=>{for(;!En(t.parentId);){const r=e.get(t.parentId);if(!r)return!1;t=r}return t.parentId===n},XW=(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=>Qm(e,s,e.get(i))))}return V("_shapeIdsInCurrentPage",(s,i)=>{if(ji(s))return o();const a=n();if(a!==r)return o();const l=e.history.getDiffSince(i);if(l===Jn)return o();const c=new mh(s);for(const h of l){for(const p of Object.values(h.added))Ma(p)&&Qm(e,a,p)&&c.add(p.id);for(const[p,f]of Object.values(h.updated))Ma(f)&&(Qm(e,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(h.removed))_n(p)&&c.remove(p)}const u=c.get();return u?vc(u.value,u.diff):s})},k2=P.createContext(null);function qW({context:e,editor:n,children:t}){return d.jsx(Uf.Provider,{value:n,children:d.jsx(k2.Provider,{value:e,children:t})})}function _2(){const e=P.useContext(k2);return e?{isDarkMode:e.isDarkMode}:null}async function ZW(e,n,t={}){var I,C;const r=typeof n[0]=="string"?n:n.map(k=>k.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,l=t.darkMode??e.user.getIsDarkMode(),c=ss({isDarkMode:l}),u=e.getShapeAndDescendantIds(r),h=e.getUnorderedRenderingShapes(!1).filter(({id:k})=>u.has(k));let p=null;if(t.bounds)p=t.bounds;else for(const{id:k}of h){const T=e.getShapeMaskedPageBounds(k);T&&(p?p.union(T):p=T.clone())}if(!p)return;const f=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;f||p.expandBy(i);const S=p.width*o,m=p.height*o;try{(C=(I=document.body).focus)==null||C.call(I)}catch{}const x=[],y=new Map,v={isDarkMode:l,addExportDef:k=>{if(y.has(k.key))return;const T=(async()=>{const O=await k.getElement();O&&x.push(d.jsx(P.Fragment,{children:O},x.length))})();y.set(k.key,T)}},b=(await Promise.all(h.map(async({id:k,opacity:T,index:O,backgroundIndex:_})=>{var z,U;if(k===f)return[];const A=e.getShape(k);if(e.isShapeOfType(A,"group"))return[];const L=e.getShapeUtil(A);let j=await((z=L.toSvg)==null?void 0:z.call(L,A,v)),R=await((U=L.toBackgroundSvg)==null?void 0:U.call(L,A,v));if(!j&&!R){const X=e.getShapePageBounds(A);j=d.jsx("rect",{width:X.w,height:X.h,fill:c.solid,stroke:c.grey.pattern,strokeWidth:1})}let F=e.getShapePageTransform(A).toCssString();"scale"in A.props&&A.props.scale!==1&&(F=`${F} scale(${A.props.scale}, ${A.props.scale})`),j&&(j=d.jsx("g",{transform:F,opacity:T,children:j},A.id)),R&&(R=d.jsx("g",{transform:F,opacity:T,children:R},`bg_${A.id}`));const W=e.getShapeMask(A.id);if(W){const X=`mask_${A.id.replace(":","_")}`;x.push(d.jsx("clipPath",{id:X,children:d.jsx("path",{d:`M${W.map(({x:J,y:le})=>`${J},${le}`).join("L")}Z`})},x.length)),j&&(j=d.jsx("g",{clipPath:`url(#${X})`,children:j},A.id)),R&&(R=d.jsx("g",{clipPath:`url(#${X})`,children:R},`bg_${A.id}`))}const K=[];return j&&K.push({zIndex:O,element:j}),R&&K.push({zIndex:_,element:R}),K}))).flat();return await Promise.all(y.values()),{jsx:d.jsx(qW,{editor:e,context:v,children:d.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:S,height:m,viewBox:`${p.minX} ${p.minY} ${p.width} ${p.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?f?c.solid:c.background:"transparent"},children:[d.jsx("defs",{children:x}),b.sort((k,T)=>k.zIndex-T.zIndex).map(({element:k})=>k)]})}),width:S,height:m}}const QW=40;class JW{constructor(n){g(this,"_clickId","");g(this,"_clickTimeout");g(this,"_clickScreenPoint");g(this,"_previousScreenPoint");g(this,"_getClickTimeout",(n,t=ot())=>{this._clickId=t,clearTimeout(this._clickTimeout),this._clickTimeout=this.editor.timers.setTimeout(()=>{if(this._clickState===n&&this._clickId===t){switch(this._clickState){case"pendingTriple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"double_click",phase:"settle"});break}case"pendingQuadruple":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"triple_click",phase:"settle"});break}case"pendingOverflow":{this.editor.dispatch({...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"settle"});break}}this._clickState="idle"}},n==="idle"||n==="pendingDouble"?this.editor.options.doubleClickDurationMs:this.editor.options.multiClickDurationMs)});g(this,"_clickState","idle");g(this,"lastPointerInfo",{});g(this,"handlePointerEvent",n=>{switch(n.name){case"pointer_down":{if(!this._clickState)return n;switch(this._clickScreenPoint=w.From(n.point),this._previousScreenPoint&&w.Dist2(this._previousScreenPoint,this._clickScreenPoint)>QW**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=w.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&&w.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?this.editor.options.coarseDragDistanceSquared:this.editor.options.dragDistanceSquared)&&this.cancelDoubleClickTimeout(),n}return n});g(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});this.editor=n}get clickState(){return this._clickState}}class eG{constructor(n){g(this,"_isEdgeScrolling",!1);g(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,l=r?i.options.coarsePointerWidth:0,c=n-l,u=n+l,h=o?0:a,p=s?t:t-a;return c<h?Math.min(1,(h-c)/a):u>p?-Math.min(1,(u-p)/a):0}getEdgeScroll(){const{editor:n}=this,{inputs:{currentScreenPoint:{x:t,y:r}}}=n,o=n.getViewportScreenBounds(),{isCoarsePointer:s,insets:[i,a,l,c]}=n.getInstanceState(),u=this.getEdgeProximityFactors(t,o.w,s,c,a),h=this.getEdgeProximityFactors(r,o.h,s,i,l);return{x:u,y:h}}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,l=a*n.x*o/i,c=a*n.y*s/i,{x:u,y:h,z:p}=t.getCamera();t.setCamera(new w(u+l,h+c,p))}}class tG{constructor(n){g(this,"isSafari");g(this,"isIos");g(this,"isChromeForIos");g(this,"isFirefox");g(this,"isAndroid");this.editor=n,typeof window<"u"&&"navigator"in window?(this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),this.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),this.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),this.isFirefox=/firefox/i.test(navigator.userAgent),this.isAndroid=/android/i.test(navigator.userAgent)):(this.isSafari=!1,this.isIos=!1,this.isChromeForIos=!1,this.isFirefox=!1,this.isAndroid=!1)}}class nG{constructor(n,t){g(this,"disposeSideEffectListener");this.editor=n,this.disposeSideEffectListener=n.sideEffects.registerAfterChangeHandler("instance",(o,s)=>{o.isFocused!==s.isFocused&&(s.isFocused?this.focus():this.blur(),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 lc(e){return oG}class rG{constructor(){g(this,"length",0);g(this,"head",null);g(this,"tail",this)}push(n){return new Gw(n,this)}toArray(){return Ho}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const oG=new rG;class Gw{constructor(n,t){g(this,"length");this.head=n,this.tail=t,this.length=t.length+1}push(n){return new Gw(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 sG{constructor(n){g(this,"store");g(this,"dispose");g(this,"state","recording");g(this,"pendingDiff",new aG);g(this,"stacks",Mt("HistoryManager.stacks",{undos:lc(),redos:lc()},{isEqual:(n,t)=>n.undos===t.undos&&n.redos===t.redos}));g(this,"annotateError");g(this,"onBatchComplete",()=>{});g(this,"_isInBatch",!1);g(this,"batch",(n,t)=>{const r=this.state;r!=="paused"&&(t!=null&&t.history)&&(this.state=iG[t.history]);try{if(this._isInBatch)return n(),this;this._isInBatch=!0;try{js(()=>{n(),this.onBatchComplete()})}catch(o){throw this.annotateError(o),o}finally{this._isInBatch=!1}return this}finally{this.state=r}});g(this,"_undo",({pushToRedoStack:n,toMark:t=void 0})=>{var o;const r=this.state;this.state="paused";try{let{undos:s,redos:i}=this.stacks.get();const a=this.pendingDiff.clear(),l=Lk(a),c=fS(a);n&&!l&&(i=i.push({type:"diff",diff:a}));let u=!1;if(l)for(;((o=s.head)==null?void 0:o.type)==="stop";){const h=s.head;if(s=s.tail,n&&(i=i.push(h)),h.id===t){u=!0;break}}if(!u)e:for(;s.head;){const h=s.head;switch(s=s.tail,n&&(i=i.push(h)),h.type){case"diff":Tc(c,[fS(h.diff)]);break;case"stop":if(!t||h.id===t)break e;break;default:an(h)}}this.store.applyDiff(c,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:s,redos:i})}finally{this.state=r}return this});g(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));g(this,"redo",()=>{var t;const n=this.state;this.state="paused";try{this.flushPendingDiff();let{undos:r,redos:o}=this.stacks.get();if(o.length===0)return this;for(;((t=o.head)==null?void 0:t.type)==="stop";)r=r.push(o.head),o=o.tail;const s=wp();for(;o.head;){const i=o.head;if(r=r.push(i),o=o.tail,i.type==="diff")Tc(s,[i.diff]);else break}this.store.applyDiff(s,{ignoreEphemeralKeys:!0}),this.store.ensureStoreIsUsable(),this.stacks.set({undos:r,redos:o})}finally{this.state=n}return this});g(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));g(this,"bailToMark",n=>(this._undo({pushToRedoStack:!1,toMark:n}),this));g(this,"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=wp();return Tc(o,r.reverse()),this.stacks.update(({redos:i})=>({undos:t.push({type:"diff",diff:o}),redos:i})),this});g(this,"mark",(n=ot())=>(js(()=>{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??xp,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:lc()}));break;case"recordingPreserveRedoStack":this.pendingDiff.apply(t.changes);break;case"paused":break;default:an(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:lc(),redos:lc()}),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 iG={record:"recording","record-preserveRedoStack":"recordingPreserveRedoStack",ignore:"paused"};class aG{constructor(){g(this,"diff",wp());g(this,"isEmptyAtom",Mt("PendingDiff.isEmpty",!0))}clear(){const n=this.diff;return this.diff=wp(),this.isEmptyAtom.set(!0),n}isEmpty(){return this.isEmptyAtom.get()}apply(n){Tc(this.diff,[n]),this.isEmptyAtom.set(Lk(this.diff))}debug(){return{diff:this.diff,isEmpty:this.isEmpty()}}}class lG{constructor(n){g(this,"scribbleItems",new Map);g(this,"state","paused");g(this,"addScribble",(n,t=ot())=>{const r={id:t,scribble:{id:t,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...n,state:"starting"},timeoutMs:0,delayRemaining:n.delay??0,prev:null,next:null};return this.scribbleItems.set(t,r),r});g(this,"stop",n=>{const t=this.scribbleItems.get(n);if(!t)throw Error(`Scribble with id ${n} not found`);return t.delayRemaining=Math.min(t.delayRemaining,200),t.scribble.state="stopping",t});g(this,"addPoint",(n,t,r)=>{const o=this.scribbleItems.get(n);if(!o)throw Error(`Scribble with id ${n} not found`);const{prev:s}=o,i={x:t,y:r,z:.5};return(!s||w.Dist(s,i)>=1)&&(o.next=i),o});g(this,"tick",n=>{this.scribbleItems.size!==0&&this.editor.batch(()=>{this.scribbleItems.forEach(t=>{if(t.scribble.state==="starting"){const{next:l,prev:c}=t;l&&l!==c&&(t.prev=l,t.scribble.points.push(l)),t.scribble.points.length>8&&(t.scribble.state="active");return}t.delayRemaining>0&&(t.delayRemaining=Math.max(0,t.delayRemaining-n)),t.timeoutMs+=n,t.timeoutMs>=16&&(t.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=t;switch(a.state){case"active":{i&&i!==s?(t.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():t.delayRemaining=a.delay);break}case"stopping":{if(t.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(t.id);return}a.shrink&&(a.size=Math.max(1,a.size*(1-a.shrink))),a.points.shift()}break}}}),this.editor.updateInstanceState({scribbles:Array.from(this.scribbleItems.values()).map(({scribble:t})=>({...t,points:[...t.points]})).slice(-5)})})});this.editor=n}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}}var cG=Object.defineProperty,uG=Object.getOwnPropertyDescriptor,sg=(e,n,t,r)=>{for(var o=uG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&cG(n,t,o),o};const ue=e=>Math.round(e*10**8)/10**8;function Oo(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)&&Or(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));if(s.length===0)return[];const i=new Set;return s.forEach(a=>{const l=r==="forward"?a.endNode.id:a.startNode.id;if(!i.has(l)){i.add(l);const c=Oo(e,l,t,r,Or(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function dG(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 Hu{constructor(n){g(this,"editor");this.manager=n,this.editor=n.editor}getSnapPointsCache(){const{editor:n}=this;return n.store.createComputedCache("snapPoints",t=>{const r=n.getShapePageTransform(t.id);if(!r)return;const s=n.getShapeUtil(t).getBoundsSnapGeometry(t).points??n.getShapeGeometry(t).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:l,y:c}=oe.applyToPoint(r,i);return{x:l,y:c,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:yr(this.editor.getShapePageBounds(n))}))}getVisibleGaps(){const n=[],t=[];let r,o;const s=this.getSnappableGapNodes().sort((a,l)=>a.pageBounds.minX-l.pageBounds.minX);for(let a=0;a<s.length;a++){r=s[a];for(let l=a+1;l<s.length;l++)o=s[l],r.pageBounds.maxX<o.pageBounds.minX&&Jl(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&n.push({startNode:r,endNode:o,startEdge:[new w(r.pageBounds.maxX,r.pageBounds.minY),new w(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new w(o.pageBounds.minX,o.pageBounds.minY),new w(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Or(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)})}const i=s.sort((a,l)=>a.pageBounds.minY-l.pageBounds.minY);for(let a=0;a<i.length;a++){r=i[a];for(let l=a+1;l<i.length;l++)o=i[l],r.pageBounds.maxY<o.pageBounds.minY&&Jl(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&t.push({startNode:r,endNode:o,startEdge:[new w(r.pageBounds.minX,r.pageBounds.maxY),new w(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new w(o.pageBounds.minX,o.pageBounds.minY),new w(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Or(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 x,y;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=t.clone().translate(o),l=r.map(({x:v,y:b},E)=>({id:"selection:"+E,x:v+o.x,y:b+o.y})),c=i,u=[],h=[],p=new w(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const f=new w(n==="x"?0:((x=u[0])==null?void 0:x.nudge)??0,n==="y"?0:((y=h[0])==null?void 0:y.nudge)??0);p.x=0,p.y=0,u.length=0,h.length=0,l.forEach(v=>{v.x+=f.x,v.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:h,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h,minOffset:p});const S=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:h}),m=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:h});return this.manager.setIndicators([...m,...S]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:n,dragDelta:t,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var k,T;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=Z.Resize(n,r,s?t.x*2:t.x,s?t.y*2:t.y,o);let u=r;l<0&&(u=p9(u)),c<0&&(u=h9(u)),s&&(a.center=n.center);const h=u==="top"||u==="bottom",p=u==="left"||u==="right",f=_C(u,a),S=this.getSnappablePoints(),m=[],x=[],y=new w(i,i);this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:x,otherNodeSnapPoints:S,selectionSnapPoints:f});const v=new w(h?0:((k=m[0])==null?void 0:k.nudge)??0,p?0:((T=x[0])==null?void 0:T.nudge)??0);if(o&&f9(u)&&v.len()!==0){const O=m.length&&x.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":m.length?"x":"y",_=n.aspectRatio;O==="x"?(x.length=0,v.y=v.x/_,(u==="bottom_left"||u==="top_right")&&(v.y=-v.y)):(m.length=0,v.x=v.y*_,(u==="bottom_left"||u==="top_right")&&(v.x=-v.x))}const b=w.Add(t,v),{box:E}=Z.Resize(n,r,s?b.x*2:b.x,s?b.y*2:b.y,o);s&&(E.center=n.center);const I=_C("any",E);m.length=0,x.length=0,y.x=0,y.y=0,this.collectPointSnaps({minOffset:y,nearestSnapsX:m,nearestSnapsY:x,otherNodeSnapPoints:S,selectionSnapPoints:I});const C=this.getPointSnapLines({nearestSnapsX:m,nearestSnapsY:x});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 l=w.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);ue(c)<=ue(r.x)&&(ue(c)<ue(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),ue(u)<=ue(r.y)&&(ue(u)<ue(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:n,minOffset:t,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!Jl(a.breadthIntersection[0],a.breadthIntersection[1],n.minY,n.maxY))continue;const c=a.startEdge[0].x+a.length/2-n.center.x;if(a.length>n.width&&ue(Math.abs(c))<=ue(t.x)){ue(Math.abs(c))<ue(t.x)&&(r.length=0),t.x=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},v=r.find(({type:E})=>E==="gap_center"),b=v&&Or(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&b?r[r.indexOf(v)]=y:(!v||!b)&&r.push(y)}const h=a.startNode.pageBounds.minX-a.length,p=n.maxX,f=h-p;ue(Math.abs(f))<=ue(t.x)&&(ue(Math.abs(f))<ue(t.x)&&(r.length=0),t.x=Math.abs(f),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:f}));const S=a.endNode.pageBounds.maxX+a.length,m=n.minX,x=S-m;ue(Math.abs(x))<=ue(t.x)&&(ue(Math.abs(x))<ue(t.x)&&(r.length=0),t.x=Math.abs(x),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:x}))}for(const a of i){if(!Jl(a.breadthIntersection[0],a.breadthIntersection[1],n.minX,n.maxX))continue;const c=a.startEdge[0].y+a.length/2-n.center.y;if(a.length>n.height&&ue(Math.abs(c))<=ue(t.y)){ue(Math.abs(c))<ue(t.y)&&(o.length=0),t.y=Math.abs(c);const y={type:"gap_center",gap:a,nudge:c},v=o.find(({type:E})=>E==="gap_center"),b=v&&Jl(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&b?o[o.indexOf(v)]=y:(!v||!b)&&o.push(y);continue}const h=a.startNode.pageBounds.minY-a.length,p=n.maxY,f=h-p;ue(Math.abs(f))<=ue(t.y)&&(ue(Math.abs(f))<ue(t.y)&&(o.length=0),t.y=Math.abs(f),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:f}));const S=a.endNode.pageBounds.maxY+a.length,m=n.minY,x=S-m;ue(Math.abs(x))<=ue(t.y)&&(ue(Math.abs(x))<ue(t.y)&&(o.length=0),t.y=Math.abs(x),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:x}))}}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:ot(),type:"points",points:kx(s.map(i=>w.From(i.otherPoint)).concat(s.map(i=>w.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:n,nearestSnapsX:t,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:n.sides[0],right:n.sides[1],bottom:[n.corners[3],n.corners[2]],left:[n.corners[0],n.corners[3]]},a=[];if(t.length>0)for(const l of t){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:f,endEdge:S}}=l;switch(l.type){case"gap_center":{const m=(f-n.width)/2,x=Or(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:[...Oo(s,h.id,m,"backward",x),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:S},...Oo(s,p.id,m,"forward",x)]});break}case"gap_duplicate":{const m=Or(c[0],c[1],n.minY,n.maxY);a.push({type:"gaps",direction:"horizontal",id:ot(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(x=>x.clone().addXY(-h.pageBounds.width,0))},{startEdge:u,endEdge:S},...Oo(s,p.id,f,"forward",m)]:[...Oo(s,h.id,f,"backward",m),{startEdge:u,endEdge:S},{startEdge:S.map(x=>x.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:h,endNode:p,length:f,endEdge:S}}=l;switch(l.type){case"gap_center":{const m=(f-n.height)/2,x=Or(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:[...Oo(o,h.id,m,"backward",x),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:S},...Oo(o,l.gap.endNode.id,m,"forward",x)]});break}case"gap_duplicate":{const m=Or(c[0],c[1],n.minX,n.maxX);a.push({type:"gaps",direction:"vertical",id:ot(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(x=>x.clone().addXY(0,-h.pageBounds.height))},{startEdge:u,endEdge:S},...Oo(o,p.id,f,"forward",m)]:[...Oo(o,h.id,f,"backward",m),{startEdge:u,endEdge:S},{startEdge:S.map(x=>x.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return dG(a),a}}sg([V],Hu.prototype,"getSnapPointsCache");sg([V],Hu.prototype,"getSnappablePoints");sg([V],Hu.prototype,"getSnappableGapNodes");sg([V],Hu.prototype,"getVisibleGaps");function _C(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 hG=Object.defineProperty,pG=Object.getOwnPropertyDescriptor,fG=(e,n,t,r)=>{for(var o=pG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&hG(n,t,o),o};const gG=()=>null,mG=()=>[];class T2{constructor(n){g(this,"editor");this.manager=n,this.editor=n.editor}getSnapGeometryCache(){const{editor:n}=this;return n.store.createComputedCache("handle snap geometry",t=>{const r=n.getShapeUtil(t).getHandleSnapGeometry(t);return{outline:r.outline===void 0?n.getShapeGeometry(t):r.outline,points:r.points??[],getSelfSnapOutline:r.getSelfSnapOutline??gG,getSelfSnapPoints:r.getSelfSnapPoints??mG}})}*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=yr(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 l=yr(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*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 c of this.iterateSnapPointsInPageSpace(n,t))w.DistMin(r,c,s)&&(s=w.Dist(r,c),i=c);if(i)return i;let a=o,l=null;for(const{shapeId:c,outline:u}of this.iterateSnapOutlines(n,t)){const h=yr(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=u.nearestPoint(p),S=h.applyToPoint(f);w.DistMin(r,S,a)&&(a=w.Dist(r,S),l=S)}return l||null}snapHandle({currentShapeId:n,handle:t}){const o=yr(this.editor.getShapePageTransform(n)).applyToPoint(t),s=this.getHandleSnapPosition({currentShapeId:n,handle:t,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:ot(),type:"points",points:[s]}]),{nudge:w.Sub(s,o)}):null}}fG([V],T2.prototype,"getSnapGeometryCache");var yG=Object.defineProperty,SG=Object.getOwnPropertyDescriptor,Vw=(e,n,t,r)=>{for(var o=SG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&yG(n,t,o),o};class ig{constructor(n){g(this,"shapeBounds");g(this,"handles");g(this,"_snapIndicators",Mt("snapLines",void 0));this.editor=n,this.shapeBounds=new Hu(this),this.handles=new T2(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(_n(i)){const l=n.getShape(i);l&&n.isShapeOfType(l,"frame")&&o.add(i)}const a=n.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=n.getShape(l);if(!c||!n.getShapeUtil(c).canSnap(c))continue;const h=n.getShapePageBounds(l);if(h&&t.includes(h)){if(n.isShapeOfType(c,"group")){s(l);continue}o.add(l)}}};return s(this.getCurrentCommonAncestor()??n.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Vw([V],ig.prototype,"getSnapThreshold");Vw([V],ig.prototype,"getSnappableShapes");Vw([V],ig.prototype,"getCurrentCommonAncestor");const vG=/\r?\n|\r/g;function TC(e){return e.replace(vG,`
|
|
86
|
-
`).split(`
|
|
87
|
-
`).map(n=>n||" ").join(`
|
|
88
|
-
`)}const xG={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},wG=/\s/;class bG{constructor(n){g(this,"baseElm");g(this,"measureText",(n,t)=>{var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","auto"),r.style.setProperty("unicode-bidi","plaintext"),r.style.setProperty("font-family",t.fontFamily),r.style.setProperty("font-style",t.fontStyle),r.style.setProperty("font-weight",t.fontWeight),r.style.setProperty("font-size",t.fontSize+"px"),r.style.setProperty("line-height",t.lineHeight*t.fontSize+"px"),r.style.setProperty("max-width",t.maxWidth===null?null:t.maxWidth+"px"),r.style.setProperty("min-width",t.minWidth===null?null:t.minWidth+"px"),r.style.setProperty("padding",t.padding),r.style.setProperty("overflow-wrap",t.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=TC(n);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}});this.editor=n;const t=this.editor.getContainer(),r=document.createElement("div");r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,t.appendChild(r),this.baseElm=r,n.disposables.add(()=>{r.remove()})}measureElementTextNodeSpans(n,{shouldTruncateToFirstLine:t=!1}={}){const r=[],o=n.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,l=n.childNodes[0];let c=0,u=null,h=null,p=0,f=0,S=!1;for(const m of n.childNodes)if(m.nodeType===Node.TEXT_NODE)for(const x of m.textContent??""){a.setStart(l,c),a.setEnd(l,c+x.length);const y=a.getClientRects(),v=y[y.length-1],b=v.top+i,E=v.left+s,I=v.right+s,C=E<f,k=wG.test(x);if(k!==h||b!==p||!u){if(u){if(t&&b!==p){S=!0;break}r.push(u)}u={box:{x:E,y:b,w:v.width,h:v.height},text:x},f=E}else C&&(u.box.x=E),u.box.w=C?u.box.w+v.width:I-u.box.x,u.text+=x;x===`
|
|
89
|
-
`&&(f=0),h=k,p=b,c+=x.length}return u&&r.push(u),{spans:r,didTruncate:S}}measureTextSpans(n,t){var c;if(n==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(t.width-t.padding*2);r.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",xG[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=TC(n);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(t.overflow==="truncate-ellipsis"&&l){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const h=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=h[h.length-1];return h.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,t.width-t.padding-u),y:p.box.y,w:u,h:p.box.h}}),h}return r.remove(),a}}const MC=(typeof process<"u",Dk);class PG{constructor(n){g(this,"cancelRaf");g(this,"isPaused",!0);g(this,"now",0);g(this,"start",()=>{var n;this.isPaused=!1,(n=this.cancelRaf)==null||n.call(this),this.cancelRaf=MC(this.tick),this.now=Date.now()});g(this,"tick",()=>{if(this.isPaused)return;const n=Date.now(),t=n-this.now;this.now=n,this.updatePointerVelocity(t),this.editor.emit("frame",t),this.editor.emit("tick",t),this.cancelRaf=MC(this.tick)});g(this,"dispose",()=>{var n;this.isPaused=!0,(n=this.cancelRaf)==null||n.call(this)});g(this,"prevPoint",new w);g(this,"updatePointerVelocity",n=>{const{prevPoint:t,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(n===0)return;const s=w.Sub(r,t);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new w(0,0),l=o.clone().lrp(a.mul(i/n),.5);Math.abs(l.x)<.01&&(l.x=0),Math.abs(l.y)<.01&&(l.y=0),o.equals(l)||(this.editor.inputs.pointerVelocity=l)});this.editor=n,this.editor.disposables.add(this.dispose),this.start()}}var CG=Object.defineProperty,IG=Object.getOwnPropertyDescriptor,Yr=(e,n,t,r)=>{for(var o=IG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&CG(n,t,o),o};class _r{constructor(n,t){g(this,"systemColorScheme",Mt("systemColorScheme","light"));g(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}}Yr([V],_r.prototype,"getUserPreferences");Yr([V],_r.prototype,"getIsDarkMode");Yr([V],_r.prototype,"getEdgeScrollSpeed");Yr([V],_r.prototype,"getAnimationSpeed");Yr([V],_r.prototype,"getId");Yr([V],_r.prototype,"getName");Yr([V],_r.prototype,"getLocale");Yr([V],_r.prototype,"getColor");Yr([V],_r.prototype,"getIsSnapMode");Yr([V],_r.prototype,"getIsWrapMode");Yr([V],_r.prototype,"getIsDynamicResizeMode");const EG={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"},kG=["brushing","cropping","dragging","dragging_handle","drawing","erasing","lasering","resizing","rotating","scribble_brushing","translating"];class se{constructor(n,t){g(this,"performanceTracker");g(this,"id");g(this,"type");g(this,"shapeType");g(this,"initial");g(this,"children");g(this,"parent");g(this,"_path");g(this,"_current");g(this,"_isActive");g(this,"transition",(n,t={})=>{var s;const r=n.split(".");let o=this;for(let i=0;i<r.length;i++){const a=r[i],l=o.getCurrent(),c=(s=o.children)==null?void 0:s[a];if(!c)throw Error(`${o.id} - no child state exists with the id ${a}.`);if((l==null?void 0:l.id)!==c.id&&(l==null||l.exit(t,a),o._current.set(c),c.enter(t,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;o=c}return this});g(this,"handleEvent",n=>{var o;const t=EG[n.name],r=this._current.__unsafe__getWithoutCapture();(o=this[t])==null||o.call(this,n),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(n)});g(this,"enter",(n,t)=>{var r;if(xt.measurePerformance.get()&&kG.includes(this.id)&&this.performanceTracker.start(this.id),this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,n,t),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(n,t)}});g(this,"exit",(n,t)=>{var r,o;xt.measurePerformance.get()&&this.performanceTracker.isStarted()&&this.performanceTracker.stop(),this._isActive.set(!1),(r=this.onExit)==null||r.call(this,n,t),this.getIsActive()||(o=this.getCurrent())==null||o.exit(n,t)});g(this,"_currentToolIdMask",Mt("curent tool id mask",void 0));g(this,"onWheel");g(this,"onPointerDown");g(this,"onPointerMove");g(this,"onLongPress");g(this,"onPointerUp");g(this,"onDoubleClick");g(this,"onTripleClick");g(this,"onQuadrupleClick");g(this,"onRightClick");g(this,"onMiddleClick");g(this,"onKeyDown");g(this,"onKeyUp");g(this,"onKeyRepeat");g(this,"onCancel");g(this,"onComplete");g(this,"onInterrupt");g(this,"onTick");g(this,"onEnter");g(this,"onExit");this.editor=n;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=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 Sk}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(n){this._currentToolIdMask.set(n)}}g(se,"id"),g(se,"initial"),g(se,"children");class Oh extends se{constructor(){super(...arguments);g(this,"onKeyDown",t=>{var r;switch(t.code){case"KeyZ":{if(!(t.shiftKey||t.ctrlKey)){const o=this.getCurrent();o&&((r=o.getCurrent())==null?void 0:r.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...t,onInteractionEnd:o.id})}break}}})}}g(Oh,"id","root"),g(Oh,"initial",""),g(Oh,"children",()=>[]);var _G=Object.defineProperty,TG=Object.getOwnPropertyDescriptor,ne=(e,n,t,r)=>{for(var o=TG(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&_G(n,t,o),o};class Q extends v7{constructor({store:t,user:r,shapeUtils:o,bindingUtils:s,tools:i,getContainer:a,cameraOptions:l,assetOptions:c,initialState:u,autoFocus:h,inferDarkMode:p,options:f}){super();g(this,"options");g(this,"store");g(this,"root");g(this,"disposables",new Set);g(this,"isDisposed",!1);g(this,"_tickManager");g(this,"snaps");g(this,"timers");g(this,"user");g(this,"textMeasure");g(this,"environment");g(this,"scribbles");g(this,"sideEffects");g(this,"edgeScrollManager");g(this,"focusManager");g(this,"getContainer");g(this,"shapeUtils");g(this,"styleProps");g(this,"bindingUtils");g(this,"history");g(this,"_crashingError",null);g(this,"_updateInstanceState",(t,r)=>{this.batch(()=>{this.store.put([{...this.getInstanceState(),...t}])},r)});g(this,"_isChangingStyleTimeout",-1);g(this,"setCursor",t=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...t}}),this));g(this,"_updateCurrentPageState",(t,r)=>{this.batch(()=>{this.store.update(t.id??this.getCurrentPageState().id,o=>({...o,...t}))},{history:"ignore",...r})});g(this,"_cameraOptions",Mt("camera options",q1));g(this,"_viewportAnimation",null);g(this,"_willSetInitialBounds",!0);g(this,"_isLockedOnFollowingUser",Mt("isLockedOnFollowingUser",!1));g(this,"_cameraState",Mt("camera state","idle"));g(this,"_cameraStateTimeoutRemaining",0);g(this,"_decayCameraStateTimeout",t=>{this._cameraStateTimeoutRemaining-=t,!(this._cameraStateTimeoutRemaining>0)&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"))});g(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=this.options.cameraMovingTimeoutMs,this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});g(this,"_currentPageShapeIds");g(this,"_assetOptions",Mt("asset options",Z1));g(this,"_parentIdsToChildIds");g(this,"animatingShapes",new Map);g(this,"_updateShapes",t=>{this.getInstanceState().isReadonly||this.batch(()=>{var i,a;const r=[];let o,s;for(let l=0,c=t.length;l<c;l++){const u=t[l];u&&(o=this.getShape(u.id),o&&(s=jo(o,u),s!==o&&(s=((a=(i=this.getShapeUtil(o)).onBeforeUpdate)==null?void 0:a.call(i,o,s))??s,r.push(s))))}this.store.put(r)})});g(this,"externalAssetContentHandlers",{file:null,url:null});g(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});g(this,"inputs",{originPagePoint:new w,originScreenPoint:new w,previousPagePoint:new w,previousScreenPoint:new w,currentPagePoint:new w,currentScreenPoint:new w,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 w});g(this,"_clickManager",new JW(this));g(this,"_prevCursor","default");g(this,"_shiftKeyTimeout",-1);g(this,"_setShiftKeyTimeout",()=>{this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ShiftLeft"})});g(this,"_altKeyTimeout",-1);g(this,"_setAltKeyTimeout",()=>{this.inputs.altKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Alt",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"AltLeft"})});g(this,"_ctrlKeyTimeout",-1);g(this,"_setCtrlKeyTimeout",()=>{this.inputs.ctrlKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Ctrl",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ControlLeft"})});g(this,"_restoreToolId","select");g(this,"_pinchStart",1);g(this,"_didPinch",!1);g(this,"_selectedShapeIdsAtPointerDown",[]);g(this,"_longPressTimeout",-1);g(this,"capturedPointerId",null);g(this,"performanceTracker");g(this,"performanceTrackerTimeout",-1);g(this,"dispatch",t=>(this._pendingEventsForNextTick.push(t),t.type==="pointer"&&t.name==="pointer_move"||t.type==="wheel"||t.type==="pinch"||this._flushEventsForTick(0),this));g(this,"_pendingEventsForNextTick",[]);g(this,"_flushEventForTick",t=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=t;if(t.type==="misc"){(t.name==="cancel"||t.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}))),this.root.handleEvent(t);return}t.shiftKey?(clearTimeout(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!t.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=this.timers.setTimeout(this._setShiftKeyTimeout,150)),t.altKey?(clearTimeout(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!t.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=this.timers.setTimeout(this._setAltKeyTimeout,150)),t.ctrlKey?(clearTimeout(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!t.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=this.timers.setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,currentPagePoint:i}=r;r.isPointing||(r.isDragging=!1);const a=this.store.unsafeGetWithoutCapture(mn),l=this.store.get(this._getCurrentPageStateId()),c=this._cameraOptions.__unsafe__getWithoutCapture();switch(o){case"pinch":{if(c.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=[...l.selectedShapeIds]),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:u=1},delta:{x:h,y:p}}=t,{x:f,y:S}=w.SubXY(t.point,a.screenBounds.x,a.screenBounds.y);this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:m,y:x,z:y}=mm(()=>this.getCamera()),{panSpeed:v,zoomSpeed:b}=c;this._setCamera(new w(m+h*v/y-f/y+f/(u*b),x+p*v/y-S/y+S/(u*b),u*b),{immediate:!0});return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:u}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,u.length>0&&this.once("tick",()=>{this._didPinch||this.setSelectedShapes(u)}));return}}}case"wheel":{if(c.isLocked)return;if(this._updateInputsFromEvent(t),!this.getIsMenuOpen()){const{panSpeed:u,zoomSpeed:h,wheelBehavior:p}=c;if(p!=="none"){this.stopCameraAnimation(),a.followingUserId&&this.stopFollowingUser();const{x:f,y:S,z:m}=mm(()=>this.getCamera()),{x,y,z:v=0}=t.delta;let b=p;switch(r.ctrlKey&&(b=p==="pan"?"zoom":"pan"),b){case"zoom":{const{x:E,y:I}=this.inputs.currentScreenPoint;let C=v;p==="zoom"&&(Math.abs(y)>10?C=10*Math.sign(y)/100:C=y/100);const k=m+(C??0)*h*m;this._setCamera(new w(f+(E/k-E)-(E/m-E),S+(I/k-I)-(I/m-I),k),{immediate:!0}),this.maybeTrackPerformance("Zooming");return}case"pan":{this._setCamera(new w(f+x*u/m,S+y*u/m,m),{immediate:!0}),this.maybeTrackPerformance("Panning");return}}}}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(t);const{isPen:u}=t,{isPenMode:h}=a;switch(t.name){case"pointer_down":{if(h&&!u)return;if(this.clearOpenMenus(),this.inputs.isPanning||(this._longPressTimeout=this.timers.setTimeout(()=>{this.dispatch({...t,point:this.inputs.currentScreenPoint,name:"long_press"})},this.options.longPressDurationMs)),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),t.button===J1&&(this.capturedPointerId=t.pointerId),r.buttons.add(t.button),r.isPointing=!0,r.isDragging=!1,!h&&u&&this.updateInstanceState({isPenMode:!0}),t.button===eP?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):t.button===bd&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,clearTimeout(this._longPressTimeout)),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;break}case"pointer_move":{if(!u&&h)return;const{x:p,y:f,z:S}=mm(()=>this.getCamera());if(this.inputs.isPanning&&this.inputs.isPointing){const{currentScreenPoint:m,previousScreenPoint:x}=this.inputs,{panSpeed:y}=c,v=w.Sub(m,x);this.setCamera(new w(p+v.x*y/S,f+v.y*y/S,S),{immediate:!0}),this.maybeTrackPerformance("Panning");return}r.isPointing&&!r.isDragging&&w.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&&!u)return;if(this.capturedPointerId===t.pointerId&&(this.capturedPointerId=null,t.button=0),r.isPanning){r.keys.has("Space")||(r.isPanning=!1);const p=this.inputs.pointerVelocity,f=Math.min(2,p.len());switch(t.button){case J1:{this.setCursor({type:"grab",rotation:0});break}case bd:this.inputs.keys.has(" ")?this.setCursor({type:"grab",rotation:0}):this.setCursor({type:this._prevCursor,rotation:0})}f>0&&this.slideCamera({speed:f,direction:p})}else t.button===eP&&(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(bd)||(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0})));break}}break}}if(t.type==="pointer"){t.button===bd?t.name="middle_click":t.button===Gx&&(t.name="right_click");const{isPenMode:u}=this.store.unsafeGetWithoutCapture(mn);if(t.isPen===u){const h=this._clickManager.handlePointerEvent(t);if(t.name!==h.name){this.root.handleEvent(t),this.emit("event",t),this.root.handleEvent(h),this.emit("event",h);return}}}return this.root.handleEvent(t),this.emit("event",t),this});this.options={...$W,...f},this.store=t,this.disposables.add(this.store.dispose.bind(this.store)),this.history=new sG({store:t,annotateError:_=>{this.annotateError(_,{origin:"history.batch",willCrashApp:!0}),this.crash(_)}}),this.snaps=new ig(this),this.timers=new G4,this.disposables.add(this.timers.dispose.bind(this.timers)),this._cameraOptions.set({...q1,...l}),this._assetOptions.set({...Z1,...c}),this.user=new _r(r??pT(),p??!1),this.getContainer=a??(()=>document.body),this.textMeasure=new bG(this),this._tickManager=new PG(this);class S extends Oh{}g(S,"initial",u??""),this.root=new S(this),this.root.children={};const m=I2(o),x={},y={},v=new Map;for(const _ of m){const A=new _(this);x[_.type]=A;const L=qk(_.props??{});y[_.type]=L;for(const j of L.keys())if(!v.has(j.id))v.set(j.id,j);else if(v.get(j.id)!==j)throw Error(`Multiple style props with id "${j.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=x,this.styleProps=y;const b=b2(s),E={};for(const _ of b){const A=new _(this);E[_.type]=A}this.bindingUtils=E;for(const _ of[...i]){if(po(this.root.children,_.id))throw Error(`Can't override tool with id "${_.id}"`);this.root.children[_.id]=new _(this,this.root)}this.environment=new tG(this),this.scribbles=new lG(this);const I=(_,A)=>{let L=null;const j=_.selectedShapeIds.filter(W=>!A.has(W));j.length!==_.selectedShapeIds.length&&(L||(L={..._}),L.selectedShapeIds=j);const R=_.erasingShapeIds.filter(W=>!A.has(W));R.length!==_.erasingShapeIds.length&&(L||(L={..._}),L.erasingShapeIds=R),_.hoveredShapeId&&A.has(_.hoveredShapeId)&&(L||(L={..._}),L.hoveredShapeId=null),_.editingShapeId&&A.has(_.editingShapeId)&&(L||(L={..._}),L.editingShapeId=null);const F=_.hintingShapeIds.filter(W=>!A.has(W));return F.length!==_.hintingShapeIds.length&&(L||(L={..._}),L.hintingShapeIds=F),_.focusedGroupId&&A.has(_.focusedGroupId)&&(L||(L={..._}),L.focusedGroupId=null),L};this.sideEffects=this.store.sideEffects;let C=new Map;const k=new Set,T=new Set;let O=new Set;if(this.disposables.add(this.sideEffects.registerOperationCompleteHandler(()=>{var _,A,L,j;k.clear();for(const R of T){T.delete(R);const F=this.getShape(R);if(!F)continue;const W=this.getShapeUtil(F),K=(_=W.onChildrenChange)==null?void 0:_.call(W,F);K!=null&&K.length&&this.updateShapes(K)}if(O.size){const R=O;O=new Set;for(const F of R){const W=this.getBindingUtil(F);(A=W.onOperationComplete)==null||A.call(W)}}if(C.size){const R=C;C=new Map;for(const F of R.values())(j=(L=this.getBindingUtil(F.binding)).onAfterDelete)==null||j.call(L,F)}this.emit("update")})),this.disposables.add(this.sideEffects.register({shape:{afterChange:(_,A)=>{var L,j,R,F;for(const W of this.getBindingsInvolvingShape(A))O.add(W.type),W.fromId===A.id&&((j=(L=this.getBindingUtil(W)).onAfterChangeFromShape)==null||j.call(L,{binding:W,shapeBefore:_,shapeAfter:A})),W.toId===A.id&&((F=(R=this.getBindingUtil(W)).onAfterChangeToShape)==null||F.call(R,{binding:W,shapeBefore:_,shapeAfter:A}));if(_.parentId!==A.parentId){const W=K=>{var U,X,J,le;const z=this.getShape(K);if(z)for(const ye of this.getBindingsInvolvingShape(z))O.add(ye.type),ye.fromId===z.id&&((X=(U=this.getBindingUtil(ye)).onAfterChangeFromShape)==null||X.call(U,{binding:ye,shapeBefore:z,shapeAfter:z})),ye.toId===z.id&&((le=(J=this.getBindingUtil(ye)).onAfterChangeToShape)==null||le.call(J,{binding:ye,shapeBefore:z,shapeAfter:z}))};W(A.id),this.visitDescendants(A.id,W)}if(_.parentId!==A.parentId&&En(A.parentId)){const W=new Set([_.id]);this.visitDescendants(_.id,K=>{W.add(K)});for(const K of this.getPageStates()){if(K.pageId===A.parentId)continue;const z=I(K,W);z&&this.store.put([z])}}_.parentId&&_n(_.parentId)&&T.add(_.parentId),A.parentId!==_.parentId&&_n(A.parentId)&&T.add(A.parentId)},beforeDelete:_=>{var R,F,W,K;if(k.has(_.id))return;_.parentId&&_n(_.parentId)&&T.add(_.parentId),k.add(_.id);const A=[];for(const z of this.getBindingsInvolvingShape(_)){O.add(z.type),A.push(z.id);const U=this.getBindingUtil(z);z.fromId===_.id?((R=U.onBeforeIsolateToShape)==null||R.call(U,{binding:z,removedShape:_}),(F=U.onBeforeDeleteFromShape)==null||F.call(U,{binding:z,shape:_})):((W=U.onBeforeIsolateFromShape)==null||W.call(U,{binding:z,removedShape:_}),(K=U.onBeforeDeleteToShape)==null||K.call(U,{binding:z,shape:_}))}A.length&&this.deleteBindings(A);const L=new Set([_.id]),j=me(this.getPageStates().map(z=>I(z,L)));j.length&&this.store.put(j)}},binding:{beforeCreate:_=>{var L,j;const A=(j=(L=this.getBindingUtil(_)).onBeforeCreate)==null?void 0:j.call(L,{binding:_});return A||_},afterCreate:_=>{var A,L;O.add(_.type),(L=(A=this.getBindingUtil(_)).onAfterCreate)==null||L.call(A,{binding:_})},beforeChange:(_,A)=>{var j,R;const L=(R=(j=this.getBindingUtil(A)).onBeforeChange)==null?void 0:R.call(j,{bindingBefore:_,bindingAfter:A});return L||A},afterChange:(_,A)=>{var L,j;O.add(A.type),(j=(L=this.getBindingUtil(A)).onAfterChange)==null||j.call(L,{bindingBefore:_,bindingAfter:A})},beforeDelete:_=>{var A,L;(L=(A=this.getBindingUtil(_)).onBeforeDelete)==null||L.call(A,{binding:_})},afterDelete:_=>{var A,L;(L=(A=this.getBindingUtil(_)).onAfterDelete)==null||L.call(A,{binding:_}),O.add(_.type)}},page:{afterCreate:_=>{const A=co.createId(_.id),L=Fr.createId(_.id);this.store.has(A)||this.store.put([co.create({id:A})]),this.store.has(L)||this.store.put([Fr.create({id:L,pageId:_.id})])},afterDelete:(_,A)=>{var R,F;if(((R=this.getInstanceState())==null?void 0:R.currentPageId)===_.id){const W=(F=this.getPages().find(K=>K.id!==_.id))==null?void 0:F.id;W?this.store.put([{...this.getInstanceState(),currentPageId:W}]):A==="user"&&this.store.ensureStoreIsUsable()}const L=co.createId(_.id),j=Fr.createId(_.id);this.store.remove([L,j])}},instance:{afterChange:(_,A,L)=>{var j;if(!this.store.has(A.currentPageId)){const R=this.store.has(_.currentPageId)?_.currentPageId:(j=this.getPages()[0])==null?void 0:j.id;R?this.store.update(A.id,F=>({...F,currentPageId:R})):L==="user"&&this.store.ensureStoreIsUsable()}}},instance_page_state:{afterChange:(_,A)=>{if((_==null?void 0:_.selectedShapeIds)!==(A==null?void 0:A.selectedShapeIds)){const L=A.selectedShapeIds.filter(R=>{var W,K;let F=(W=this.getShape(R))==null?void 0:W.parentId;for(;_n(F);){if(A.selectedShapeIds.includes(F))return!1;F=(K=this.getShape(F))==null?void 0:K.parentId}return!0});let j=null;if(L.length>0){const R=this.findCommonAncestor(me(L.map(F=>this.getShape(F))),F=>this.isShapeOfType(F,"group"));R&&(j=R)}else A!=null&&A.focusedGroupId&&(j=A.focusedGroupId);(L.length!==A.selectedShapeIds.length||j!==A.focusedGroupId)&&this.store.put([{...A,selectedShapeIds:L,focusedGroupId:j??null}])}}}})),this._currentPageShapeIds=XW(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=YW(this.store),this.disposables.add(this.store.listen(_=>{this.emit("change",_)})),this.disposables.add(this.history.dispose),this.history.ignore(()=>{this.store.ensureStoreIsUsable(),this._updateCurrentPageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]})}),u&&this.root.children[u]===void 0)throw Error(`No state found for initialState "${u}".`);this.root.enter(void 0,"initial"),this.edgeScrollManager=new eG(this),this.focusManager=new nG(this,h),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 Sk}dispose(){this.disposables.forEach(t=>t()),this.disposables.clear(),this.isDisposed=!0}getShapeUtil(t){const r=typeof t=="string"?t:t.type,o=jn(this.shapeUtils,r);return st(o,`No shape util found for type "${r}"`),o}getBindingUtil(t){const r=typeof t=="string"?t:t.type,o=jn(this.bindingUtils,r);return st(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 _x(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(SS)}updateDocumentSettings(t){return this.history.ignore(()=>{this.store.put([{...this.getDocumentSettings(),...t}])}),this}getInstanceState(){return this.store.get(mn)}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 Fr.createId(this.getCurrentPageId())}updateCurrentPageState(t,r){return this._updateCurrentPageState(t,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:t}=this.getCurrentPageState();return me(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:Z.Common(me(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=Z.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 Z(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 me(t.map(r=>this.getShape(r)))}setHintingShapes(t){const r=typeof t[0]=="string"?t:t.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:kx(r)},{history:"ignore"}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const t=this.getErasingShapeIds();return me(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 co.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(p=>p.userId===t);if(!r)return null;const{w:o,h:s}=r.screenBounds,{x:i,y:a,z:l}=r.camera,c=new Z(-i,-a,o/l,s/l),u=this.getViewportScreenBounds().clone(),h=u.width/u.height;return u.width=c.width,u.height=u.width/h,u.height<c.height&&(u.height=c.height,u.width=u.height*h),u.center=c.center,u}getCameraForFollowing(){const t=this.getViewportPageBoundsForFollowing();return t?{x:-t.x,y:-t.y,z:this.getViewportScreenBounds().w/t.width}:null}getZoomLevel(){return this.getCamera().z}getInitialZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.initialZoom==="default")return 1;const{zx:r,zy:o}=jC(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 an(t.constraints.initialZoom)}}getBaseZoom(){const t=this.getCameraOptions();if(!t.constraints||t.constraints.baseZoom==="default")return 1;const{zx:r,zy:o}=jC(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 an(t.constraints.baseZoom)}}getCameraOptions(){return this._cameraOptions.get()}setCameraOptions(t){var o;const r=rt({...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 l=this.getCameraOptions(),c=l.zoomSteps[0],u=Nt(l.zoomSteps),h=this.getViewportScreenBounds();if(l.constraints){const{constraints:p}=l,f=Math.min(p.padding.y,h.w/2),S=Math.min(p.padding.x,h.h/2),m=Z.From(l.constraints.bounds),x=(h.w-S*2)/m.w,y=(h.h-f*2)/m.h,v=this.getBaseZoom(),b=u*v,E=c*v;if(r!=null&&r.reset&&(a=this.getInitialZoom()),a<E||a>b){const{x:j,y:R,z:F}=o,W=-j+h.w/F/2,K=-R+h.h/F/2;a=_t(a,E,b);const z=-j+h.w/a/2,U=-R+h.h/a/2;s=j+z-W,i=R+U-K}const I=S/a-m.x,C=f/a-m.y,k=(h.w-S*2)/a-m.w,T=(h.h-f*2)/a-m.h,O=I+k*p.origin.x,_=C+T*p.origin.y,A=typeof p.behavior=="string"?p.behavior:p.behavior.x,L=typeof p.behavior=="string"?p.behavior:p.behavior.y;if(r!=null&&r.reset)s=O,i=_;else{switch(A){case"fixed":{s=O;break}case"contain":{a<x?s=O:s=_t(s,I+k,I);break}case"inside":{a<x?s=_t(s,I,(h.w-S)/a-m.w):s=_t(s,I+k,I);break}case"outside":{s=_t(s,S/a-m.w,(h.w-S)/a);break}case"free":break;default:throw an(A)}switch(L){case"fixed":{i=_;break}case"contain":{a<y?i=_:i=_t(i,C+T,C);break}case"inside":{a<y?i=_t(i,C,(h.h-f)/a-m.h):i=_t(i,C+T,C);break}case"outside":{i=_t(i,f/a-m.h,(h.h-f)/a);break}case"free":break;default:throw an(L)}}}else if(a>u||a<c){const{x:p,y:f,z:S}=o;a=_t(a,c,u),s=p+(-p+h.w/a/2)-(-p+h.w/S/2),i=f+(-f+h.h/a/2)-(-f+h.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 l={...o,x:s,y:i,z:a};this.history.ignore(()=>{this.store.put([l])});const{currentScreenPoint:c,currentPagePoint:u}=this.inputs,{screenBounds:h}=this.store.unsafeGetWithoutCapture(mn);if(c.x/a-s!==u.x||c.y/a-i!==u.y){const p={type:"pointer",target:"canvas",name:"pointer_move",point:w.AddXY(c,h.x,h.y),pointerId:Q1.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(p):this.dispatch(p)}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=w.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:l}=this.getViewportScreenBounds();this._animateToViewport(new Z(-i.x,-i.y,a/i.z,l/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 w(-(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=Z.Common(me(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:l,z:c}=i,{x:u,y:h}=t;let p=1;if(s){const f=this.getInitialZoom();c!==f&&(p=f)}return this.setCamera(new w(a+(u/p-u)-(u/c-u),l+(h/p-h)-(h/c-h),p),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 l=this.getBaseZoom();let c=Nt(a)*l;for(let u=1;u<a.length;u++){const h=a[u-1]*l,p=a[u]*l;if(!(p-i<=(p-h)/2)){c=p;break}}this.setCamera(new w(o+(t.x/c-t.x)-(t.x/i-t.x),s+(t.y/c-t.y)-(t.y/i-t.y),c),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:l}=this.getCamera();let c=o[0]*s;for(let u=o.length-1;u>0;u--){const h=o[u-1]*s,p=o[u]*s;if(!(p-l>=(p-h)/2)){c=h;break}}this.setCamera(new w(i+(t.x/c-t.x)-(t.x/l-t.x),a+(t.y/c-t.y)-(t.y/l-t.y),c),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(q6,s.width*.28),a=this.getBaseZoom(),l=o.zoomSteps[0],c=Nt(o.zoomSteps);let u=_t(Math.min((s.width-i)/t.w,(s.height-i)/t.h),l*a,c*a);return(r==null?void 0:r.targetZoom)!==void 0&&(u=Math.min(r.targetZoom,u)),this.setCamera(new w(-t.x+(s.width-t.w*u)/2/u,-t.y+(s.height-t.h*u)/2/u,u),r),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(t){if(!this._viewportAnimation)return;this._viewportAnimation.elapsed+=t;const{elapsed:r,easing:o,duration:s,start:i,end:a}=this._viewportAnimation;if(r>s){this.off("tick",this._animateViewport),this._viewportAnimation=null,this._setCamera(new w(-a.x,-a.y,this.getViewportScreenBounds().width/a.width));return}const l=s-r,c=o(1-l/s),u=i.minX+(a.minX-i.minX)*c,h=i.minY+(a.minY-i.minY)*c,p=i.maxX+(a.maxX-i.maxX)*c;this._setCamera(new w(-u,-h,this.getViewportScreenBounds().width/(p-u)),{force:!0})}_animateToViewport(t,r={animation:xm}){const{animation:o,...s}=r;if(!o)return;const{duration:i=0,easing:a=At.easeInOutCubic}=o,l=this.user.getAnimationSpeed(),c=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),i===0||l===0?this._setCamera(new w(-t.x,-t.y,this.getViewportScreenBounds().width/t.width),{...s}):(this._viewportAnimation={elapsed:0,duration:i/l,easing:a,start:c.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 l=Math.min(o,1);const c=()=>{this.off("tick",u),this.off("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=h=>{const{x:p,y:f,z:S}=this.getCamera(),m=w.Mul(i,l*h/S);l*=1-s,l<a?c():this._setCamera(new w(p+m.x,f+m.y,S))};return this.on("tick",u),this}zoomToUser(t,r={animation:{duration:500}}){const o=this.getCollaborators().find(s=>s.userId===t);return o?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const s=o.currentPageId===this.getCurrentPageId();s||this.setCurrentPage(o.currentPageId),r&&r.animation&&!s&&(r.animation=void 0),this.centerOnPoint(o.cursor,r);const{highlightedUserIds:i}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...i,t]}),this.timers.setTimeout(()=>{const a=[...this.getInstanceState().highlightedUserIds],l=a.indexOf(t);l<0||(a.splice(l,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,!Ds(document.body.scrollWidth,t.maxX,1),!Ds(document.body.scrollHeight,t.maxY,1),t.minX!==0],{screenBounds:s,insets:i}=this.getInstanceState();if(t.equals(s)&&o.every((l,c)=>l===i[c]))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 l=this.getViewportPageBounds().center;this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this.centerOnPoint(l)}else this.updateInstanceState({screenBounds:t.toJson(),insets:o}),this._setCamera(w.From({...this.getCamera()}));return this._tickCameraState(),this}getViewportScreenBounds(){const{x:t,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new Z(t,r,o,s)}getViewportScreenCenter(){const t=this.getViewportScreenBounds();return new w(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 Z(-o,-s,t/i,r/i)}screenToPage(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(mn),{x:o,y:s,z:i=1}=this.getCamera();return new w((t.x-r.x)/i-o,(t.y-r.y)/i-s,t.z??.5)}pageToScreen(t){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(mn),{x:o,y:s,z:i=1}=this.getCamera();return new w((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 w((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 js(()=>{this.updateInstanceState({followingUserId:t},{history:"ignore"});const i=oa("update current page",()=>{const c=s.get();if(!c){this.stopFollowingUser();return}c.currentPageId!==this.getCurrentPageId()&&this.getPage(c.currentPageId)&&this.history.ignore(()=>{this.store.put([{...this.getInstanceState(),currentPageId:c.currentPageId}]),this._isLockedOnFollowingUser.set(!0)})}),a=()=>{i(),this._isLockedOnFollowingUser.set(!1),this.off("frame",l),this.off("stop-following",a)},l=()=>{if(!s.get()){this.stopFollowingUser();return}if(this._isLockedOnFollowingUser.get())return;const u=this.user.getAnimationSpeed();if(u===0){this._isLockedOnFollowingUser.set(!0);return}const h=this.getViewportPageBoundsForFollowing();if(!h){this.stopFollowingUser();return}const p=this.getViewportPageBounds(),f=Math.abs(h.minX-p.minX)+Math.abs(h.maxX-p.maxX),S=Math.abs(h.minY-p.minY)+Math.abs(h.maxY-p.maxY);if(f<this.options.followChaseViewportSnap&&S<this.options.followChaseViewportSnap){this._isLockedOnFollowingUser.set(!0);return}const m=_t(u*.5,.1,.8),x=new Z(fd(p.minX,h.minX,m),fd(p.minY,h.minY,m),fd(p.width,h.width,m),fd(p.height,h.height,m)),y=new w(-x.x,-x.y,this.getViewportScreenBounds().width/x.width);this.stopCameraAnimation(),this._setCamera(y)};this.once("stop-following",a),this.addListener("frame",l),l()}),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=(c,u,h)=>{const p=this.getShape(c);if(!p)return;u*=p.opacity;let f=!1;const S=this.getShapeUtil(p);t&&(f=!h&&i.includes(c),f&&(u*=.32)),r.push({id:c,shape:p,util:S,index:o,backgroundIndex:s,opacity:u}),o+=1,s+=1;const m=this.getSortedChildIdsForParent(c);if(!m.length)return;let x=null;S.providesBackgroundForChildren(p)&&(x=s,s=o,o+=this.options.maxShapesPerPage);for(const y of m)a(y,u,h||f);x!==null&&(s=x)},l=t?[this.getCurrentPage()]:this.getPages();for(const c of l)for(const u of this.getSortedChildIdsForParent(c.id))a(u,1,!1);return r}getCameraState(){return this._cameraState.get()}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort(z4)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(on)}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=zW(t.name??"Page 1",r.map(a=>a.name));let s=t.index;(!s||r.some(a=>a.index===s))&&(s=$o(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(l=>l.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 u;const l=this.getPages(),c=Gc(s.index,(u=l[l.indexOf(s)+1])==null?void 0:u.index);if(this.createPage({name:s.name+" Copy",id:r,index:c}),this.setCurrentPage(r),this.setCamera(i),a)return this.putContentOntoCurrentPage(a)}),this}renamePage(t,r){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,l=Math.max(.125,(h=>Math.pow(2,Math.ceil(Math.log2(h))))(s||1)),c="connection"in navigator?navigator.connection.effectiveType:null,u=this.getInstanceState().devicePixelRatio;return await this._assetOptions.get().onResolveAsset(o,{screenScale:s||1,steppedScreenScale:l,dpr:u,networkEffectiveType:c,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(En(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||En(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?Z.FromPoints(oe.applyToPoints(r,this.getShapeGeometry(t).vertices)):new Z})}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(En(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=IC(s,i);return a?a.map(w.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,l)=>a&&w.Equals(a,o[l])))return r.clone();const i=IC(o,s);return i?Z.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(En(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(En(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(t,r){const o=typeof t=="string"?t:t==null?void 0:t.id,s=o&&this.getShape(o);return s?s.parentId===r?!0:this.hasAncestor(this.getShapeParent(s),r):!1}findCommonAncestor(t,r){var c;if(t.length===0)return;const o=typeof t[0]=="string"?t:t.map(u=>u.id),s=me(o.map(u=>this.getShape(u)));if(s.length===1){const u=s[0].parentId;return En(u)?void 0:r?(c=this.findShapeAncestor(s[0],r))==null?void 0:c.id:u}const[i,...a]=s;let l=this.getShapeParent(i);for(;l;){if(r&&!r(l)){l=this.getShapeParent(l);continue}if(a.every(u=>this.hasAncestor(u,l.id)))return l.id;l=this.getShapeParent(l)}}isShapeOrAncestorLocked(t){const r=typeof t=="string"?this.getShape(t):t;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}_notVisibleShapes(){return VW(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:l=!1,hitLabels:c=!1,hitInside:u=!1,hitFrameInside:h=!1}=r;let p=1/0,f=null,S=1/0,m=null;const x=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(y=>{if(y.isLocked&&!l||this.isShapeOfType(y,"group"))return!1;const v=this.getShapeMask(y);return v&&!tr(t,v)?!1:i?i(y):!0});for(let y=x.length-1;y>=0;y--){const v=x[y],b=this.getShapeGeometry(v),E=b instanceof Hr,I=this.getPointInShapeSpace(v,t);if((this.isShapeOfType(v,"arrow")||this.isShapeOfType(v,"geo")&&v.props.fill==="none")&&v.props.text.trim()){for(const k of b.children)if(k.isLabel&&k.isPointInBounds(I))return v}if(this.isShapeOfType(v,"frame")){const k=b.distanceToPoint(I,u);if(Math.abs(k)<=a)return m||v;if(b.hitTestPoint(I,0,!0))return m||f||(h?v:void 0);continue}let C;if(E){let k=1/0;for(const T of b.children){if(T.isLabel&&!c)continue;const O=T.distanceToPoint(I,u);O<k&&(k=O)}C=k}else a===0&&(b.bounds.w<1||b.bounds.h<1)||b.bounds.containsPoint(I,a)?C=b.distanceToPoint(I,u):C=1/0;if(b.isClosed){if(C<=a){if(b.isFilled||E&&b.children[0].isFilled)return m||v;if(this.getShapePageBounds(v).contains(s))continue;if(Math.abs(C)<a)Math.abs(C)<S&&(S=Math.abs(C),m=v);else if(!m){const{area:k}=b;k<p&&(p=k,f=v)}}}else if(C<this.options.hitTestMargin/o)return v}return m||f||void 0}getShapesAtPoint(t,r={}){return this.getCurrentPageShapes().filter(o=>this.isPointInShape(o,t,r))}isPointInShape(t,r,o={}){const{hitInside:s=!1,margin:i=0}=o,a=typeof t=="string"?t:t.id,l=this.getShapeMask(a);return l&&!tr(r,l)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(t,r),i,s)}getPointInShapeSpace(t,r){const o=typeof t=="string"?t:t.id;return this._getShapePageTransformCache().get(o).clone().invert().applyToPoint(r)}getPointInParentSpace(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);if(!s)return new w(0,0);if(En(s.parentId))return w.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):w.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++)M2(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(_n(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||!_n(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 En(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=En(r)?oe.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const u=me(this.getSortedChildIdsForParent(r).map(S=>this.getShape(S)));if(o){const S=u.find(m=>m.index===o);if(S){const m=u[u.indexOf(S)+1];m?c=ll(o,m.index,s.length):c=fm(o,s.length)}else{const m=u.sort(on).find(x=>x.index>o);m?c=ll(o,m.index,s.length):c=fm(o,s.length)}}else{const S=u.length&&u[u.length-1];c=S?fm(S.index,s.length):Vc(s.length)}const h=a.clone().invert(),p=me(s.map(S=>this.getShape(S))),f=p.filter(S=>S.isLocked);f.length&&this.updateShapes(f.map(({id:S,type:m})=>({id:S,type:m,isLocked:!1})));for(let S=0;S<p.length;S++){const m=p[S],x=this.getShapePageTransform(m);if(!x)continue;const y=x.point();if(!y)continue;const v=h.applyToPoint(y),b=x.rotation()-l;i.push({id:m.id,type:m.type,parentId:r,x:v.x,y:v.y,rotation:b,index:c[S],isLocked:m.isLocked})}return this.updateShapes(i),this}getHighestIndexForParent(t){const r=typeof t=="string"?t:t.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const s=this.getShape(o[o.length-1]);return $o(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(on))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(l=>l.id===i.id||this.hasAncestor(i,l.id)))continue;const a=this.getShapeMaskedPageBounds(i.id);if(a&&a.containsPoint(t)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,t),0,!0))return i}}getOutermostSelectableShape(t,r){const o=typeof t=="string"?t:t.id,s=this.getShape(o);let i=s,a=s;const l=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(l==null?void 0:l.id)!==a.id&&!this.hasAncestor(l,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((l==null?void 0:l.id)===a.id)break;a=this.getShapeParent(a)}return i}_getBindingsIndexCache(){const t=WW(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 l=this.getBindingUtil(o.type).getDefaultProps(),c=this.store.schema.types.binding.create({...o,id:o.id??Oi(),props:{...l,...o.props}});r.push(c)}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=jo(s,o);if(i===s)continue;const a=this.getShape(i.fromId),l=this.getShape(i.toId);!a||!l||this.canBindShapes({fromShape:a,toShape:l,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 l=this.getBinding(a);if(!l)continue;const c=this.getBindingUtil(l);(s=c.onBeforeIsolateFromShape)==null||s.call(c,{binding:l,removedShape:this.getShape(l.toId)}),(i=c.onBeforeIsolateToShape)==null||i.call(c,{binding:l,removedShape:this.getShape(l.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,l={fromShapeType:s,toShapeType:i,bindingType:a};return s===i?this.getShapeUtil(s).canBind(l):this.getShapeUtil(s).canBind(l)&&this.getShapeUtil(i).canBind(l)}rotateShapesBy(t,r){if((typeof t[0]=="string"?t:t.map(i=>i.id)).length<=0)return this;const s=E2({editor:this});return s?(jh({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(t,r){var i,a,l;let o=t;const s=this.getShapeUtil(t);return o=jo(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=jo(o,{id:t.id,type:t.type,x:r.x,y:r.y}),o=jo(o,((a=s.onTranslate)==null?void 0:a.call(s,t,o))??void 0),o=jo(o,((l=s.onTranslateEnd)==null?void 0:l.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),l=w.From(r),c=this.getShapeParentTransform(a);c&&l.rot(-c.rotation()),s.push(this.getChangesToTranslateShape(a,l.add(a)))}return this.updateShapes(s),this}duplicateShapes(t,r){return this.history.batch(()=>{const o=typeof t[0]=="string"?t:t.map(p=>p.id);if(o.length<=0)return this;const s=new Set(o),i=this.getShapeAndDescendantIds(o),a=[...i].reverse(),l=new Map;for(const p of i)l.set(p,$e());const{shapesToCreate:c,bindingsToCreate:u}=AC(this,i,p=>{const f=[];for(const m of p){const x=this.getBinding(m);if(!x)continue;const y=Oi();f.push({...x,id:y,fromId:yr(l.get(x.fromId)),toId:yr(l.get(x.toId))})}const S=[];for(const m of a){const x=yr(l.get(m)),y=this.getShape(m);if(!y)continue;let v=0,b=0;if(r&&s.has(m)){const _=this.getShapeParentTransform(y),A=new w(r.x,r.y).rot(-_.rotation());v=A.x,b=A.y}const E=y.parentId,I=this.getSortedChildIdsForParent(E),C=I.indexOf(y.id),k=I[C+1],T=k?this.getShape(k):null,O=T?Gc(y.index,T.index):$o(y.index);S.push({...y,id:x,x:y.x+v,y:y.y+b,index:O,parentId:l.get(y.parentId)??y.parentId})}return{shapesToCreate:S,bindingsToCreate:f}});if(c.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage){Ud(this);return}if(this.createShapes(c),this.createBindings(u),this.setSelectedShapes(me(o.map(p=>l.get(p)))),r!==void 0){const p=this.getSelectionPageBounds(),f=this.getViewportPageBounds();p&&!f.contains(p)&&this.centerOnPoint(p.center,{animation:{duration:this.options.animationMediumMs}})}}),this}moveShapesToPage(t,r){const o=typeof t[0]=="string"?t:t.map(l=>l.id);if(o.length===0)return this;if(this.getInstanceState().isReadonly)return this;const s=this.getCurrentPageId();if(r===s)return this;if(!this.store.has(r))return this;const i=this.getContentFromCurrentPage(o);if(!i)return this;if(this.getPageShapeIds(r).size+i.shapes.length>this.options.maxShapesPerPage)return Ud(this,r),this;const a=this.getCamera().z;return this.history.batch(()=>{this.deleteShapes(o),this.setCurrentPage(r),this.setFocusedGroup(null),this.selectNone(),this.putContentOntoCurrentPage(i,{select:!0,preserveIds:!0,preservePosition:!0}),this.setCamera({...this.getCamera(),z:a}),this.centerOnPoint(this.getSelectionRotatedPageBounds().center)}),this}toggleLock(t){const r=typeof t[0]=="string"?t:t.map(a=>a.id);if(this.getInstanceState().isReadonly||r.length===0)return this;let o=!0,s=!0;const i=[];for(const a of r){const l=this.getShape(a);l&&(i.push(l),l.isLocked?s=!1:o=!1)}return this.batch(()=>{s?(this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0}))),this.setSelectedShapes([])):o?this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!1}))):this.updateShapes(i.map(a=>({id:a.id,type:a.type,isLocked:!0})))}),this}sendToBack(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Bd(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Bd(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Bd(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(t){const r=typeof t[0]=="string"?t:t.map(s=>s.id),o=Bd(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=me(o.map(a=>this.getShape(a)));if(!s.length)return this;s=me(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(l=>this.getShape(l)):a).flat());const i=Z.Common(me(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const l=this.getShapeGeometry(a).bounds,c=this.getShapePageTransform(a.id);c&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:l,initialPageTransform:c,initialShape:a,mode:"scale_shape",isAspectRatioLocked:this.getShapeUtil(a).isAspectRatioLocked(a),scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(t,r,o){const s=typeof t[0]=="string"?t:t.map(x=>x.id);if(this.getInstanceState().isReadonly)return this;const i=s.map(x=>this.getShape(x)).filter(x=>x?this.getShapeUtil(x).canBeLaidOut(x):!1),a=i.length;if(o===0&&a<3||a<2)return this;const l=Object.fromEntries(i.map(x=>[x.id,this.getShapePageBounds(x)]));let c,u,h,p;r==="horizontal"?(c="x",u="minX",h="maxX",p="width"):(c="y",u="minY",h="maxY",p="height");let f;if(o===0){const x=[];i.sort((v,b)=>l[v.id][u]-l[b.id][u]);for(let v=0;v<a-1;v++){const b=i[v],E=i[v+1],I=l[b.id],k=l[E.id][u]-I[h],T=x.find(O=>O.gap===k);T?T.count++:x.push({gap:k,count:1})}let y=0;x.forEach(v=>{v.count>y&&(y=v.count,f=v.gap)}),y===1&&(f=Math.max(0,x.reduce((v,b)=>v+b.gap*b.count,0)/(a-1)))}else f=o;const S=[];let m=l[i[0].id][h];return i.forEach((x,y)=>{var C,k;if(y===0)return;const v={x:0,y:0};v[c]=m+f-l[x.id][c];const b=this.getShapeParent(x),E=b?w.Rot(v,-this.getShapePageTransform(b).decompose().rotation):v,I=(k=(C=this.getShapeUtil(x)).onTranslateStart)==null?void 0:k.call(C,x);S.push(I?{...I,[c]:x[c]+E[c]}:{id:x.id,type:x.type,[c]:x[c]+E[c]}),m+=l[x.id][p]+f}),this.updateShapes(S),this}packShapes(t,r){var k,T;const o=typeof t[0]=="string"?t:t.map(O=>O.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=o.map(O=>this.getShape(O)).filter(O=>O?this.getShapeUtil(O).canBeLaidOut(O):!1),i={},a={};let l,c,u=0;for(let O=0;O<s.length;O++)l=s[O],c=this.getShapePageBounds(l),i[l.id]=c,a[l.id]=c.clone(),u+=c.width*c.height;const h=Z.Common(me(Object.values(i))),p=h.width;s.sort((O,_)=>i[_.id].height-i[O.id].height);const f=Math.max(Math.ceil(Math.sqrt(u/.95)),p),S=[new Z(h.x,h.y,f,1/0)];let m=0,x=0,y,v;for(let O=0;O<s.length;O++){l=s[O],c=a[l.id];for(let _=S.length-1;_>=0;_--)if(y=S[_],!(c.width>y.width||c.height>y.height)){c.x=y.x,c.y=y.y,x=Math.max(x,c.maxY),m=Math.max(m,c.maxX),c.width===y.width&&c.height===y.height?(v=S.pop(),_<S.length&&(S[_]=v)):c.height===y.height?(y.x+=c.width+r,y.width-=c.width+r):c.width===y.width?(y.y+=c.height+r,y.height-=c.height+r):(S.push(new Z(y.x+(c.width+r),y.y,y.width-(c.width+r),c.height)),y.y+=c.height+r,y.height-=c.height+r);break}}const b=Z.Common(Object.values(a)),E=w.Sub(h.center,b.center);let I;const C=[];for(let O=0;O<s.length;O++){l=s[O],c=i[l.id],I=a[l.id];const _=w.Sub(I.point,c.point).add(E),A=this.getShapeParentTransform(l);A&&_.rot(-A.rotation());const L={id:l.id,type:l.type,x:l.x+_.x,y:l.y+_.y},j=(T=(k=this.getShapeUtil(l)).onTranslateStart)==null?void 0:T.call(k,{...l,...L});j?C.push({...L,...j}):C.push(L)}return C.length&&this.updateShapes(C),this}alignShapes(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=me(o.map(c=>this.getShape(c))),i=Object.fromEntries(s.map(c=>[c.id,this.getShapePageBounds(c)])),a=Z.Common(me(Object.values(i))),l=[];return s.forEach(c=>{const u=i[c.id];if(!u)return;const h={x:0,y:0};switch(r){case"top":{h.y=a.minY-u.minY;break}case"center-vertical":{h.y=a.midY-u.minY-u.height/2;break}case"bottom":{h.y=a.maxY-u.minY-u.height;break}case"left":{h.x=a.minX-u.minX;break}case"center-horizontal":{h.x=a.midX-u.minX-u.width/2;break}case"right":{h.x=a.maxX-u.minX-u.width;break}}const p=this.getShapeParent(c),f=p?w.Rot(h,-this.getShapePageTransform(p).decompose().rotation):h;l.push(this.getChangesToTranslateShape(c,w.Add(c,f)))}),this.updateShapes(l),this}distributeShapes(t,r){const o=typeof t[0]=="string"?t:t.map(b=>b.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=me(o.map(b=>this.getShape(b))),a=Object.fromEntries(i.map(b=>[b.id,this.getShapePageBounds(b)]));let l,c,u,h,p;r==="horizontal"?(l="x",c="minX",u="maxX",h="midX",p="width"):(l="y",c="minY",u="maxY",h="midY",p="height");const f=[],S=i.sort((b,E)=>a[b.id][c]-a[E.id][c])[0],m=i.sort((b,E)=>a[E.id][u]-a[b.id][u])[0],x=a[S.id][h],y=(a[m.id][h]-x)/(s-1),v=x+y;return i.filter(b=>b!==S&&b!==m).sort((b,E)=>a[b.id][h]-a[E.id][h]).forEach((b,E)=>{const I={x:0,y:0};I[l]=v+y*E-a[b.id][p]/2-a[b.id][l];const C=this.getShapeParent(b),k=C?w.Rot(I,-this.getShapePageTransform(C).rotation()):I;f.push(this.getChangesToTranslateShape(b,w.Add(b,k)))}),this.updateShapes(f),this}stretchShapes(t,r){const o=typeof t[0]=="string"?t:t.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=me(o.map(c=>this.getShape(c))),i=Object.fromEntries(o.map(c=>[c,this.getShapeGeometry(c).bounds])),a=Object.fromEntries(o.map(c=>[c,this.getShapePageBounds(c)])),l=Z.Common(me(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const c of s){if(this.getShapePageTransform(c).rotation()%Re)continue;const h=i[c.id],p=a[c.id],f=new w(0,l.minY-p.minY),S=this.getShapeParentTransform(c);S&&f.rot(-S.rotation());const{x:m,y:x}=w.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:m,y:x}]);const y=new w(1,l.height/p.height);this.resizeShape(c.id,y,{initialBounds:h,scaleOrigin:new w(p.center.x,l.minY),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const c of s){const u=i[c.id],h=a[c.id];if(this.getShapePageTransform(c).rotation()%Re)continue;const f=new w(l.minX-h.minX,0),S=this.getShapeParentTransform(c);S&&f.rot(-S.rotation());const{x:m,y:x}=w.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:m,y:x}]);const y=new w(l.width/h.width,1);this.resizeShape(c.id,y,{initialBounds:u,scaleOrigin:new w(l.minX,h.center.y),isAspectRatioLocked:this.getShapeUtil(c).isAspectRatioLocked(c),scaleAxisRotation:0})}});break}}return this}resizeShape(t,r,o={}){var S,m,x;const s=typeof t=="string"?t:t.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new w(1,r.y)),Number.isFinite(r.y)||(r=new w(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 l=o.initialPageTransform?oe.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!l)return this;const c=l.rotation();if(c==null)return this;const u=o.scaleAxisRotation??c,h=o.initialBounds??this.getShapeGeometry(s).bounds;if(!h)return this;const p=o.isAspectRatioLocked??this.getShapeUtil(i).isAspectRatioLocked(i);if(!F_(c,u))return this._resizeUnalignedShape(s,r,{...o,initialBounds:h,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:l,isAspectRatioLocked:p,initialShape:i});const f=this.getShapeUtil(i);if(p&&(Math.abs(r.x)>Math.abs(r.y)?r=new w(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new w(Math.sign(r.x)*Math.abs(r.y),r.y)),f.onResize&&f.canResize(i)){const y=this._scalePagePoint(oe.applyToPoint(l,new w(0,0)),a,r,u),v=this.getPointInParentSpace(i.id,y),b=new w(r.x,r.y),E=Ds((c-u)%Math.PI,0);b.x=E?r.x:r.y,b.y=E?r.y:r.x;const I=oe.applyToPoint(l,new w),{x:C,y:k}=this.getPointInParentSpace(i.id,I);let T=i;o.skipStartAndEndCallbacks||(T=jo(i,((m=f.onResizeStart)==null?void 0:m.call(f,i))??void 0)),T=jo(T,{id:s,type:i.type,x:v.x,y:v.y,...f.onResize({...i,x:C,y:k},{newPoint:v,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:b.x,scaleY:b.y,initialBounds:h,initialShape:i})}),o.skipStartAndEndCallbacks||(T=jo(T,((x=f.onResizeEnd)==null?void 0:x.call(f,i,T))??void 0)),this.updateShapes([T])}else{const y=oe.applyToPoint(l,h.center),v=this._scalePagePoint(y,a,r,u),b=this.getPointInParentSpace(i.id,y),E=this.getPointInParentSpace(i.id,v),I=w.Sub(E,b);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=w.RotWith(t,r,-s).sub(r),a=w.MulV(i,o);return w.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(t,r,o){const{type:s}=o.initialShape,i=new w(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),l=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),c=this.getShapePageBounds(t),u=this.getShapePageTransform(t),h=c.center,p=u.point();if(!h||!p)return this;const f=w.Sub(l,h),S=w.Add(p,f),{x:m,y:x}=this.getPointInParentSpace(t,S);return this.updateShapes([{id:t,type:s,x:m,y:x}]),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 Ud(this),this;const s=this.getFocusedGroupId();return this.batch(()=>{var h,p;const i=this.getCurrentPageShapesSorted(),a=t.map(f=>{if(f.id||(f={id:$e(),...f}),!f.parentId||!(this.store.has(f.parentId)||t.some(S=>S.id===f.parentId))){let S=this.getFocusedGroupId();for(let x=i.length-1;x>=0;x--){const y=i[x];if(this.getShapeUtil(y).canReceiveNewChildrenOfType(y,f.type)&&this.isPointInShape(y,{x:f.x??0,y:f.y??0},{margin:0,hitInside:!0})){S=y.id;break}}const m=f.parentId;if(S===f.id&&(S=s),S!==m&&(f={...f},f.parentId=S,_n(S))){const x=this.getPointInShapeSpace(this.getShape(S),{x:f.x??0,y:f.y??0});f.x=x.x,f.y=x.y,f.rotation=-this.getShapePageTransform(S).rotation()+(f.rotation??0)}}return f}),l=new Map,c=[],{opacityForNextShape:u}=this.getInstanceState();for(const f of a){const S=this.getShapeUtil(f);let m=f.index;if(!m){const b=f.parentId??s;l.has(b)||l.set(b,this.getHighestIndexForParent(b)),m=l.get(b),l.set(b,$o(m))}const x=S.getDefaultProps();for(const[b,E]of this.styleProps[f.type])x[E]=this.getStyleForNextShape(b);let y=this.store.schema.types.shape.create({...f,index:m,opacity:f.opacity??u,parentId:f.parentId??s,props:"props"in f?{...x,...f.props}:x});if(y.index===void 0)throw Error("no index!");const v=(p=(h=this.getShapeUtil(y)).onBeforeCreate)==null?void 0:p.call(h,y);v&&(y=v),c.push(y)}c.forEach(f=>{f.meta={...this.getInitialMetaForShape(f),...f.meta}}),this.store.put(c)})}animateShape(t,r={animation:xm}){return this.animateShapes([t],r)}animateShapes(t,r={animation:xm}){if(!r.animation)return this;const{duration:o=500,easing:s=At.linear}=r.animation,i=ot();let a=o,l;const c=[];let u,h;for(let S=0,m=t.length;S<m;S++){if(u=t[S],!u)continue;h={partial:u,values:[]};const x=this.getShape(u.id);if(x){for(const y of["x","y","rotation"])u[y]!==void 0&&x[y]!==u[y]&&h.values.push({prop:y,from:x[y],to:u[y]});c.push(h),this.animatingShapes.set(x.id,i)}}let p;const f=S=>{if(a-=S,a<0){const{animatingShapes:v}=this,b=t.filter(E=>E&&v.get(E.id)===i);b.length&&this.updateShapes(b),this.off("tick",f);return}l=s(1-a/o);const{animatingShapes:m}=this,x=[];let y;for(let v=0,b=c.length;v<b;v++)p=c[v],y=m.get(p.partial.id),y===i&&x.push({id:p.partial.id,type:p.partial.type,...p.values.reduce((E,{prop:I,from:C,to:k})=>(E[I]=C+(k-C)*l,E),{})});this._updateShapes(x)};return this.on("tick",f),this}groupShapes(t,r={}){var m;const{groupId:o=$e(),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(x=>x.id);if(i.length<=1)return this;const a=me(this._getUnlockedShapeIds(i).map(x=>this.getShape(x))),l=a.sort(on).map(x=>x.id),c=Z.Common(me(a.map(x=>this.getShapePageBounds(x)))),{x:u,y:h}=c.point,p=this.findCommonAncestor(a)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const f=a.filter(x=>x.parentId===p).sort(on),S=(m=f[f.length-1])==null?void 0:m.index;return this.batch(()=>{this.createShapes([{id:o,type:"group",parentId:p,index:S,x:u,y:h,opacity:1,props:{}}]),this.reparentShapes(l,o),s&&this.select(o)}),this}ungroupShapes(t,r={}){const{select:o=!0}=r,s=typeof t[0]=="string"?t:t.map(l=>l.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 me(s.map(l=>this.getShape(l))).forEach(l=>{this.isShapeOfType(l,"group")?a.push(l):i.add(l.id)}),a.length===0?this:(this.batch(()=>{let l;for(let c=0,u=a.length;c<u;c++){l=a[c];const h=this.getSortedChildIdsForParent(l.id);for(let p=0,f=h.length;p<f;p++)i.add(h[p]);this.reparentShapes(h,l.parentId,l.index)}this.deleteShapes(a.map(c=>c.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,jn(t.props,s))}_getSelectionSharedStyles(){const t=this.getSelectedShapes(),r=new Sv;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 jn(t.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const t=this.root.getCurrent(),r=new Sv;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 l of a)s(this.getShape(l))}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 l=this.getSortedChildIdsForParent(a.id);for(const c of l)i(this.getShape(c))}else{const l=this.getShapeUtil(a),c=this.styleProps[a.type].get(t);if(c){const u={id:a.id,type:a.type,props:{[c]:r}};s.push({util:l,originalShape:a,updatePartial:u})}}};for(const a of o)i(a);this.updateShapes(s.map(({updatePartial:a})=>a))}return this}registerExternalAssetHandler(t,r){return this.externalAssetContentHandlers[t]=r,this}async getAssetForExternalContent(t){var r,o;return await((o=(r=this.externalAssetContentHandlers)[t.type])==null?void 0:o.call(r,t))}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 AC(this,o,s=>{const i=[];for(const h of s){const p=this.getBinding(h);p&&i.push(p)}const a=[],l=[];for(const h of o){const p=this.getShape(h);if(!p)continue;if(!o.has(p.parentId)){const S=this.getShapePageTransform(p.id),m=S.point();l.push({...p,x:m.x,y:m.y,rotation:S.rotation(),parentId:this.getCurrentPageId()}),a.push(p.id)}else l.push(p)}const c=[],u=new Set;for(const h of l){if(!("assetId"in h.props))continue;const p=h.props.assetId;if(!p||u.has(p))continue;u.add(p);const f=this.getAsset(p);f&&c.push(f)}return{schema:this.store.schema.serialize(),shapes:l,rootShapeIds:a,bindings:i,assets:c}})}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=rt(o),l=await this._assetOptions.get().onResolveAsset(o,{screenScale:1,steppedScreenScale:1,dpr:1,networkEffectiveType:null,shouldResolveToOriginalImage:!0});a.props.src=await Ai.blobToDataUrl(await So(l).then(c=>c.blob())),r.push(a)}else r.push(o)})),t.assets=r,t}putContentOntoCurrentPage(t,r={}){var A,L;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 l=this.getCurrentPageId(),{rootShapeIds:c}=t,u=[],h=[],p=[],f={store:{...Object.fromEntries(t.assets.map(j=>[j.id,j])),...Object.fromEntries(t.shapes.map(j=>[j.id,j])),...Object.fromEntries(((A=t.bindings)==null?void 0:A.map(j=>[j.id,j]))??[])},schema:t.schema},S=this.store.schema.migrateStoreSnapshot(f);if(S.type==="error")throw Error("Could not put content: could not migrate content");for(const j of Object.values(S.value))switch(j.typeName){case"asset":{u.push(j);break}case"shape":{h.push(j);break}case"binding":{p.push(j);break}}const m=new Map(s?h.map(j=>[j.id,j.id]):h.map(j=>[j.id,$e()])),x=new Map(s?p.map(j=>[j.id,j.id]):p.map(j=>[j.id,Oi()]));let y=this.getCurrentPageId(),v=1/0,b=[];for(const j of this.getSelectedShapes()){if(v===0)break;const R=this.isShapeOfType(j,"frame"),F=this.getShapeAncestors(j);R&&F.push(j);const W=R?F.length+1:F.length;if(W<v)v=W,b=F,y=R?j.id:j.parentId;else if(W===v){if(b.length!==F.length)throw Error(`Ancestors: ${b.length} !== ${F.length}`);if(b.length===0){y=l;break}else{y=l;for(let K=0;K<b.length&&F[K]===b[K];K++)y=F[K].id}}}let E=!1;if(!En(y)){const j=this.getShape(y);if(j){if(!this.getViewportPageBounds().includes(this.getShapePageBounds(j)))y=l;else if(c.length===1){const R=h.find(F=>F.id===c[0]);this.isShapeOfType(j,"frame")&&this.isShapeOfType(R,"frame")&&R.props.w===(j==null?void 0:j.props.w)&&R.props.h===(j==null?void 0:j.props.h)&&(E=!0)}}else y=l}E||(E=m.has(y)),E&&(y=this.getShape(y).parentId);let I=this.getHighestIndexForParent(y);const C=[],k=h.map(j=>{const R=m.get(j.id),F={...j,id:R};return c.includes(j.id)&&(F.parentId=l,C.push(F)),m.has(F.parentId)?F.parentId=m.get(j.parentId):(c.push(F.id),F.index=I,I=$o(I)),F});if(k.length+this.getCurrentPageShapeIds().size>this.options.maxShapesPerPage)return Ud(this),this;const T=p.map(j=>({...j,id:yr(x.get(j.id)),fromId:yr(m.get(j.fromId)),toId:yr(m.get(j.toId))})),O=[],_=[];for(const j of u)this.store.has(j.id)||((j.type==="image"||j.type==="video")&&((L=j.props.src)!=null&&L.startsWith("data:image"))&&(_.push(rt(j)),j.props.src=null),O.push(j));return Promise.allSettled(_.map(async j=>{const R=await NW(j.props.src,j.props.name,j.props.mimeType??"image/png"),F=await this.getAssetForExternalContent({type:"file",file:R});if(!F){this.deleteAssets([j.id]);return}this.updateAssets([{...F,id:j.id}])})),this.batch(()=>{O.length>0&&this.createAssets(O),this.createShapes(k),this.createBindings(T),o&&this.select(...C.map(K=>K.id)),y!==l&&this.reparentShapes(C.map(K=>K.id),y);const j=k.map(K=>this.getShape(K.id)),R=Z.Common(j.map(K=>this.getShapePageBounds(K)));if(a===void 0)if(En(y)){const K=this.getViewportPageBounds();i||K.includes(Z.From(R))?a=R.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(z=>this.isShapeOfType(z,"frame")&&z.props.w===K.props.w&&z.props.h===K.props.h);)a.x+=R.w+16}const F=Z.Common(me(C.map(({id:K})=>this.getShapePageBounds(K)))).center,W=w.Sub(a,F);this.updateShapes(C.map(({id:K})=>{const z=this.getShape(K),U=this.getShapeParentTransform(K).decompose().rotation,X=w.Rot(W,-U);return{id:z.id,type:z.type,x:z.x+X.x,y:z.y+X.y}}))}),this}async getSvgElement(t,r={}){const o=await ZW(this,t,r);if(!o)return;const s=document.createDocumentFragment(),i=m2(s);aa.flushSync(()=>{i.render(o.jsx)});const a=s.firstElementChild;return st(a instanceof SVGSVGElement,"Expected an SVG element"),i.unmount(),{svg:a,width:o.width,height:o.height}}async getSvgString(t,r={}){const o=await this.getSvgElement(t,r);return o?{svg:new XMLSerializer().serializeToString(o.svg),width:o.width,height:o.height}:void 0}async getSvg(t,r={}){const o=await this.getSvgElement(t,r);if(o)return o.svg}_updateInputsFromEvent(t){const{pointerVelocity:r,previousScreenPoint:o,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:l}=this.store.unsafeGetWithoutCapture(mn),{x:c,y:u,z:h}=this.store.unsafeGetWithoutCapture(this.getCameraId()),p=t.point.x-l.x,f=t.point.y-l.y,S=t.point.z??.5;o.setTo(i),s.setTo(a),i.set(p,f);const m=p/h-c,x=f/h-u;isFinite(m)&&isFinite(x)&&a.set(m,x,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:Op,typeName:"pointer",x:a.x,y:a.y,lastActivityTimestamp:t.type==="pointer"&&t.pointerId===Q1.CAMERA_MOVE?((y=this.store.unsafeGetWithoutCapture(Op))==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 MW(this.store)}loadSnapshot(t){return w2(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){xt.measurePerformance.get()&&(this.performanceTracker.isStarted()?clearTimeout(this.performanceTrackerTimeout):this.performanceTracker.start(t),this.performanceTrackerTimeout=this.timers.setTimeout(()=>{this.performanceTracker.stop()},50))}}ne([V],Q.prototype,"getCanUndo");ne([V],Q.prototype,"getCanRedo");ne([V],Q.prototype,"getPath");ne([V],Q.prototype,"getCurrentTool");ne([V],Q.prototype,"getCurrentToolId");ne([V],Q.prototype,"getDocumentSettings");ne([V],Q.prototype,"getInstanceState");ne([V],Q.prototype,"getOpenMenus");ne([V],Q.prototype,"getIsMenuOpen");ne([V],Q.prototype,"getPageStates");ne([V],Q.prototype,"_getPageStatesQuery");ne([V],Q.prototype,"getCurrentPageState");ne([V],Q.prototype,"_getCurrentPageStateId");ne([V],Q.prototype,"getSelectedShapeIds");ne([V],Q.prototype,"getSelectedShapes");ne([V],Q.prototype,"getOnlySelectedShapeId");ne([V],Q.prototype,"getOnlySelectedShape");ne([V],Q.prototype,"getSelectionPageBounds");ne([V],Q.prototype,"getSelectionRotation");ne([V],Q.prototype,"getSelectionRotatedPageBounds");ne([V],Q.prototype,"getSelectionRotatedScreenBounds");ne([V],Q.prototype,"getFocusedGroupId");ne([V],Q.prototype,"getFocusedGroup");ne([V],Q.prototype,"getEditingShapeId");ne([V],Q.prototype,"getEditingShape");ne([V],Q.prototype,"getHoveredShapeId");ne([V],Q.prototype,"getHoveredShape");ne([V],Q.prototype,"getHintingShapeIds");ne([V],Q.prototype,"getHintingShape");ne([V],Q.prototype,"getErasingShapeIds");ne([V],Q.prototype,"getErasingShapes");ne([V],Q.prototype,"getCameraId");ne([V],Q.prototype,"getCamera");ne([V],Q.prototype,"getViewportPageBoundsForFollowing");ne([V],Q.prototype,"getCameraForFollowing");ne([V],Q.prototype,"getZoomLevel");ne([V],Q.prototype,"getViewportScreenBounds");ne([V],Q.prototype,"getViewportScreenCenter");ne([V],Q.prototype,"getViewportPageBounds");ne([V],Q.prototype,"_getCollaboratorsQuery");ne([V],Q.prototype,"getCollaborators");ne([V],Q.prototype,"getCollaboratorsOnCurrentPage");ne([V],Q.prototype,"getRenderingShapes");ne([V],Q.prototype,"_getAllPagesQuery");ne([V],Q.prototype,"getPages");ne([V],Q.prototype,"getCurrentPageId");ne([V],Q.prototype,"getCurrentPageShapeIdsSorted");ne([V],Q.prototype,"_getAllAssetsQuery");ne([V],Q.prototype,"_getShapeGeometryCache");ne([V],Q.prototype,"_getShapeHandlesCache");ne([V],Q.prototype,"_getShapePageTransformCache");ne([V],Q.prototype,"_getShapePageBoundsCache");ne([V],Q.prototype,"_getShapeClipPathCache");ne([V],Q.prototype,"_getShapeMaskCache");ne([V],Q.prototype,"_getShapeMaskedPageBoundsCache");ne([V],Q.prototype,"_notVisibleShapes");ne([V],Q.prototype,"getCulledShapes");ne([V],Q.prototype,"getCurrentPageBounds");ne([V],Q.prototype,"getCurrentPageShapes");ne([V],Q.prototype,"getCurrentPageShapesSorted");ne([V],Q.prototype,"getCurrentPageRenderingShapesSorted");ne([V],Q.prototype,"_getBindingsIndexCache");ne([V],Q.prototype,"_getSelectionSharedStyles");ne([V({isEqual:(e,n)=>e.equals(n)})],Q.prototype,"getSharedStyles");ne([V],Q.prototype,"getSharedOpacity");ne([V],Q.prototype,"getIsFocused");function Ud(e,n=e.getCurrentPageId()){const t=e.getPage(n).name;e.emit("max-shapes",{name:t,pageId:n,count:e.options.maxShapesPerPage})}function jo(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[l,c]of Object.entries(a))c!==void 0&&(t[i][l]=c);continue}t[i]=a}}return t||e}function M2(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++)M2(e,o[s],t)}function AC(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 c of e.getBindingsInvolvingShape(a)){const u=n.has(c.fromId),h=n.has(c.toId);if(u&&h){s.add(c.id);continue}(!u||!h)&&i.add(c.id)}e.deleteBindings([...i],{isolateShapes:!0});try{r=gn.ok(t(s))}catch(a){r=gn.err(a)}});e.store.applyDiff(fS(o))}),r.ok)return r.value;throw r.error}function jC(e,n){if(!n.constraints)throw Error("Should have constraints here");const{padding:{x:t,y:r}}=n.constraints,o=e.getViewportScreenBounds(),s=Z.From(n.constraints.bounds),i=(o.w-t*2)/s.w,a=(o.h-r*2)/s.h;return{zx:i,zy:a}}function Ku(){const e=B(),n=_2();return G("isDarkMode",()=>(n==null?void 0:n.isDarkMode)??e.user.getIsDarkMode(),[n,e])}const OC="<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'/>",DC="<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'/>",Hd='<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),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,h=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${h}' 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 MG=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],AG={none:()=>"none","ew-resize":(e,n,t)=>ys(DC,e,0,n,t),"ns-resize":(e,n,t)=>ys(DC,e,90,n,t),"nesw-resize":(e,n,t)=>ys(OC,e,0,n,t),"nwse-resize":(e,n,t)=>ys(OC,e,90,n,t),"nwse-rotate":(e,n,t)=>ys(Hd,e,0,n,t),"nesw-rotate":(e,n,t)=>ys(Hd,e,90,n,t),"senw-rotate":(e,n,t)=>ys(Hd,e,180,n,t),"swne-rotate":(e,n,t)=>ys(Hd,e,270,n,t)};function Vn(e,n=0,t="black"){return AG[e](G6(n),!1,t)}function jG(){const e=B(),n=un(),t=Ku();Os("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(MG.includes(r)){n.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}n.style.setProperty("--tl-cursor",Vn(r,o,t?"white":"black"))},[e,n,t])}function OG(){const e=B(),n=un(),t=Ku(),r=G(xt.forceSrgb);xe.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 Yw(e){const n=P.useRef();return P.useLayoutEffect(()=>{n.current=e}),P.useDebugValue(e),P.useCallback((...t)=>{const r=n.current;return st(r,"fn does not exist"),r(...t)},[])}function DG(){const[e,n]=P.useState(0);P.useEffect(()=>n(t=>t+1),[])}function RG(){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 LG(){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 $G=(e,n)=>n.some(t=>e instanceof t);let RC,LC;function FG(){return RC||(RC=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function NG(){return LC||(LC=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const A2=new WeakMap,vv=new WeakMap,j2=new WeakMap,Jm=new WeakMap,Xw=new WeakMap;function zG(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&&A2.set(t,e)}).catch(()=>{}),Xw.set(n,e),n}function BG(e){if(vv.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)});vv.set(e,n)}let xv={get(e,n,t){if(e instanceof IDBTransaction){if(n==="done")return vv.get(e);if(n==="objectStoreNames")return e.objectStoreNames||j2.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 UG(e){xv=e(xv)}function HG(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(n,...t){const r=e.call(ey(this),n,...t);return j2.set(r,n.sort?n.sort():[n]),Wo(r)}:NG().includes(e)?function(...n){return e.apply(ey(this),n),Wo(A2.get(this))}:function(...n){return Wo(e.apply(ey(this),n))}}function KG(e){return typeof e=="function"?HG(e):(e instanceof IDBTransaction&&BG(e),$G(e,FG())?new Proxy(e,xv):e)}function Wo(e){if(e instanceof IDBRequest)return zG(e);if(Jm.has(e))return Jm.get(e);const n=KG(e);return n!==e&&(Jm.set(e,n),Xw.set(n,e)),n}const ey=e=>Xw.get(e);function O2(e,n,{blocked:t,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,n),a=Wo(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Wo(i.result),l.oldVersion,l.newVersion,Wo(i.transaction),l)}),t&&i.addEventListener("blocked",l=>t(l.oldVersion,l.newVersion,l)),a.then(l=>{s&&l.addEventListener("close",()=>s()),o&&l.addEventListener("versionchange",c=>o(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function WG(e,{blocked:n}={}){const t=indexedDB.deleteDatabase(e);return n&&t.addEventListener("blocked",r=>n(r.oldVersion,r)),Wo(t).then(()=>{})}const GG=["get","getKey","getAll","getAllKeys","count"],VG=["put","add","delete","clear"],ty=new Map;function $C(e,n){if(!(e instanceof IDBDatabase&&!(n in e)&&typeof n=="string"))return;if(ty.get(n))return ty.get(n);const t=n.replace(/FromIndex$/,""),r=n!==t,o=VG.includes(t);if(!(t in(r?IDBIndex:IDBObjectStore).prototype)||!(o||GG.includes(t)))return;const s=async function(i,...a){const l=this.transaction(i,o?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[t](...a),o&&l.done]))[0]};return ty.set(n,s),s}UG(e=>({...e,get:(n,t,r)=>$C(n,t)||e.get(n,t,r),has:(n,t)=>!!$C(n,t)||e.has(n,t)}));const ag="TLDRAW_DOCUMENT_v2",D2="TLDRAW_DB_NAME_INDEX_v2",Le={Records:"records",Schema:"schema",SessionState:"session_state"};async function lg(e,n){QG(e);const t=await O2(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 YG({persistenceKey:e,sessionId:n,didCancel:t}){const r=ag+e;if(qw().includes(r))return await ZG({persistenceKey:e,didCancel:t}),await lg(r,async o=>{var h,p;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),l=s.objectStore(Le.SessionState);let c=n?(h=await l.get(n))==null?void 0:h.snapshot:null;c||(c=(p=(await l.getAll()).sort((S,m)=>S.updatedAt-m.updatedAt).pop())==null?void 0:p.snapshot);const u={records:await i.getAll(),schema:await a.get(Le.Schema),sessionStateSnapshot:c};if(t!=null&&t()){s.abort();return}return await s.done,u})}async function XG({persistenceKey:e,schema:n,changes:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=ag+e;await lg(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),u=l.objectStore(Le.Schema),h=l.objectStore(Le.SessionState);for(const[p,f]of Object.entries(t.added))await c.put(f,p);for(const[p,f]of Object.values(t.updated))await c.put(f,f.id);for(const p of Object.keys(t.removed))await c.delete(p);if(u.put(n.serialize(),Le.Schema),o&&r?h.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function qG({persistenceKey:e,schema:n,snapshot:t,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=ag+e;await lg(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),u=l.objectStore(Le.Schema),h=l.objectStore(Le.SessionState);await c.clear();for(const[p,f]of Object.entries(t))await c.put(f,p);if(u.put(n.serialize(),Le.Schema),o&&r?h.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function ZG({persistenceKey:e,didCancel:n}){await lg(ag+e,async t=>{const r=t.transaction([Le.SessionState],"readwrite"),o=r.objectStore(Le.SessionState),s=(await o.getAll()).sort((a,l)=>a.updatedAt-l.updatedAt);if(s.length<10){await r.done;return}const i=s.slice(0,s.length-10);for(const{id:a}of i)await o.delete(a);if(n!=null&&n())return r.abort();await r.done})}function qw(){const e=JSON.parse(Mx(D2)||"[]")??[];return Array.isArray(e)?e:[]}function QG(e){const n=new Set(qw());n.add(e),Ax(D2,JSON.stringify([...n]))}const JG=350,eV=1e4,FC=Symbol("UPDATE_INSTANCE_STATE"),tV=e=>e;class nV{constructor(n){g(this,"onmessage")}postMessage(n){}close(){}}const rV=typeof BroadcastChannel>"u"?nV:BroadcastChannel;class oV{constructor(n,{persistenceKey:t,sessionId:r=df,onLoad:o,onLoadError:s},i=new rV(`tldraw-tab-sync-${t}`)){g(this,"disposables",new Set);g(this,"diffQueue",[]);g(this,"didDispose",!1);g(this,"shouldDoFullDBWrite",!0);g(this,"isReloading",!1);g(this,"persistenceKey");g(this,"sessionId");g(this,"serializedSchema");g(this,"isDebugging",!1);g(this,"documentTypes");g(this,"$sessionStateSnapshot");g(this,"initTime",Date.now());g(this,"isPersisting",!1);g(this,"didLastWriteError",!1);g(this,"scheduledPersistTimeout",null);this.store=n,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=t,this.sessionId=r,this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=v2(this.store),this.disposables.add(n.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(tV({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(FC),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 YG({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){t(o),LG(),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??_W(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&&x2(this.store,s)}this.channel.onmessage=({data:o})=>{var a,l;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,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}s.type==="diff"&&(this.debug("applying diff"),js(()=>{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?eV:JG))}persistIfNeeded(){this.debug("persistIfNeeded",{isPersisting:this.isPersisting,isReloading:this.isReloading,shouldDoFullDBWrite:this.shouldDoFullDBWrite,diffQueueLength:this.diffQueue.length,storeIsPossiblyCorrupt:this.store.isPossiblyCorrupted()}),this.scheduledPersistTimeout&&(clearTimeout(this.scheduledPersistTimeout),this.scheduledPersistTimeout=null),!this.isPersisting&&(this.isReloading||this.store.isPossiblyCorrupted()||(this.shouldDoFullDBWrite||this.diffQueue.length>0)&&this.doPersist())}async doPersist(){st(!this.isPersisting,"persist already in progress"),this.isPersisting=!0,this.debug("doPersist start");const n=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await qG({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const t=Ox(n.filter(r=>r!==FC));await XG({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),RG(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function R2({initialData:e,defaultName:n="",id:t,...r}={}){const o="schema"in r&&r.schema?r.schema:L6({shapes:"shapeUtils"in r&&r.shapeUtils?NC(I2(r.shapeUtils)):void 0,bindings:"bindingUtils"in r&&r.bindingUtils?NC(b2(r.bindingUtils)):void 0,migrations:"migrations"in r?r.migrations:void 0});return new $x({id:t,schema:o,initialData:e,props:{defaultName:n}})}function NC(e){return Object.fromEntries(e.map(n=>[n.type,{props:n.props,migrations:n.migrations}]))}function zC(e){const n=R2(e);return e.snapshot&&w2(n,e.snapshot),{store:n,opts:e}}function L2(e){const[n,t]=P.useState(()=>zC(e));if(!Ek(n.opts,e)){const r=zC(e);return t(r),r.store}return n.store}function sV({persistenceKey:e,sessionId:n,...t}){const[r,o]=P.useState(null),s=L2(t);return P.useEffect(()=>{const i=ot();if(!e){o({id:i,storeWithStatus:{status:"not-synced",store:s}});return}o({id:i,storeWithStatus:{status:"loading"}});const a=c=>{o(u=>(u==null?void 0:u.id)===i?{id:i,storeWithStatus:c}:u)},l=new oV(s,{sessionId:n,persistenceKey:e,onLoad(){a({store:s,status:"synced-local"})},onLoadError(c){a({status:"error",error:c})}});return()=>{o(c=>(c==null?void 0:c.id)===i?null:c),l.close()}},[e,s,n]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}function iV(){const e=B(),n=un();P.useEffect(()=>{const t=s=>n.style.setProperty("--tl-zoom",s.toString()),r=xk(t,100),o=new jl("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?t(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach(),r.cancel()}},[e,n])}const aV=[],lV=[],cV=[],uV=P.memo(function({store:n,components:t,className:r,user:o,...s}){const[i,a]=xe.useState(null),l=P.useMemo(()=>o??pT(),[o]),c=(t==null?void 0:t.ErrorFallback)===void 0?iT:t==null?void 0:t.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??aV,bindingUtils:s.bindingUtils??lV,tools:s.tools??cV,components:t};return d.jsx("div",{ref:a,draggable:!1,className:ce("tl-container tl-theme__light",r),onPointerDown:Ht,tabIndex:-1,children:d.jsx(qc,{fallback:c,onError:h=>_x(h,{tags:{origin:"react.tldraw-before-app"}}),children:i&&d.jsx(rH,{container:i,children:d.jsx(a7,{overrides:t,children:n?n instanceof $x?d.jsx(F2,{...u,store:n,user:l}):d.jsx($2,{...u,store:n,user:l}):d.jsx(dV,{...u,store:n,user:l})})})})})});function dV(e){const{defaultName:n,snapshot:t,initialData:r,shapeUtils:o,bindingUtils:s,persistenceKey:i,sessionId:a,user:l}=e,c=sV({shapeUtils:o,bindingUtils:s,initialData:r,persistenceKey:i,sessionId:a,defaultName:n,snapshot:t});return d.jsx($2,{...e,store:c,user:l})}const $2=P.memo(function({store:n,user:t,...r}){const o=un();P.useLayoutEffect(()=>{t.userPreferences.get().colorScheme==="dark"&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,t]);const{LoadingScreen:s}=it();switch(n.status){case"error":throw n.error;case"loading":return s?d.jsx(s,{}):null}return d.jsx(F2,{...r,store:n.store,user:t})});function F2({onMount:e,children:n,store:t,tools:r,shapeUtils:o,bindingUtils:s,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,assetOptions:h,options:p}){const{ErrorFallback:f}=it(),S=un(),m=P.useRef(null),[x,y]=P.useState(null),v=m.current;x!==v&&y(v);const[b]=P.useState(l);P.useLayoutEffect(()=>{const C=new Q({store:t,shapeUtils:o,bindingUtils:s,tools:r,getContainer:()=>S,user:i,initialState:a,autoFocus:b,inferDarkMode:c,cameraOptions:u,assetOptions:h,options:p});return m.current=C,y(C),()=>{C.dispose()}},[S,o,s,r,t,i,a,b,c,u,h,p]);const E=P.useSyncExternalStore(P.useCallback(C=>v?(v.on("crash",C),()=>v.off("crash",C)):()=>{},[v]),()=>(v==null?void 0:v.getCrashingError())??null),{Canvas:I}=it();return v?d.jsx(qc,{fallback:f,onError:C=>v.annotateError(C,{origin:"react.tldraw",willCrashApp:!0}),children:E?d.jsx(pV,{crashingError:E}):d.jsx(Uf.Provider,{value:v,children:d.jsx(hV,{onMount:e,children:n??(I?d.jsx(I,{}):null)})})}):null}function hV({children:e,onMount:n}){return iV(),jG(),OG(),DG(),fV(n),d.jsx(d.Fragment,{children:e})}function pV({crashingError:e}){throw e}function Zw({children:e}){return d.jsx("div",{className:"tl-loading",children:e})}function N2({children:e}){return d.jsx("div",{className:"tl-loading",children:e})}function fV(e){const n=B(),t=Yw(r=>{let o;return r.history.ignore(()=>{o=e==null?void 0:e(r),r.emit("mount")}),window.tldrawReady=!0,o});xe.useLayoutEffect(()=>{if(n)return t==null?void 0:t(n)},[n,t])}function Vi({children:e,className:n="",...t}){return d.jsx("div",{...t,className:ce("tl-html-container",n),children:e})}class Dh{constructor(n){this.editor=n}}g(Dh,"props"),g(Dh,"migrations"),g(Dh,"type");function z2(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=t;let h=e.props.w*s,p=e.props.h*i;const f=new w(0,0);if(h>0){if(h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:S,y:m}=f.rot(e.rotation).add(r);return{x:S,y:m,props:{w:Math.min(l,h),h:Math.min(u,p)}}}class $l extends Ur{constructor(){super(...arguments);g(this,"onResize",(t,r)=>z2(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 My;let gV=(My=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(My,"id","idle"),My);var Ay;let mV=(Ay=class extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"wasFocusedOnEnter",!1);g(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});g(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=$e();this.markId=`creating:${s}`,this.editor.mark(this.markId),this.editor.createShapes([{id:s,type:o,x:r.x,y:r.y,props:{w:1,h:1}}]).select(s),this.editor.setCurrentTool("select.resizing",{...t,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:this.parent.onCreate})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:t}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;this.editor.mark(this.markId);const r=this.parent.shapeType,o=$e();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 l=new w(i/2,a/2),c=this.editor.getShapeParentTransform(s);c&&l.rot(-c.rotation());let u=1;this.editor.user.getIsDynamicResizeMode()&&(u=1/this.editor.getZoomLevel(),i*=u,a*=u,l.mul(u));const h=rt(s);h.x=s.x-l.x,h.y=s.y-l.y,h.props.w=i,h.props.h=a,"scale"in s.props&&(h.props.scale=u),this.editor.updateShape(h),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},g(Ay,"id","pointing"),Ay);class Rh extends se{constructor(){super(...arguments);g(this,"onCreate")}}g(Rh,"id","box"),g(Rh,"initial","idle"),g(Rh,"children",()=>[gV,mV]);function cg(e){const n=B();return G("isEditing",()=>n.getEditingShapeId()===e,[n,e])}function yV(){return P.useId().replace(/:/g,"_")}function ro(e){const n=B();return P.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===Gx){n.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...On(c)});return}if(c.button!==0)return;const u=Fp(c.currentTarget);function h(){u.removeEventListener("pointerup",h),Ru(u,c)}Du(u,c),u.addEventListener("pointerup",h),n.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...On(c)}),Ht(c)};let s,i;function a(c){c.isKilled||c.button===0&&(c.clientX===s&&c.clientY===i||(s=c.clientX,i=c.clientY,n.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...On(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&n.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...On(c)})}}},[n,e])}const SV=20,vV=8;function Qw(e,n=SV){return Math.max(vV,Math.ceil(e/n))}class Ha extends oi{constructor(t){super({...t,isFilled:!1,isClosed:!1});g(this,"_center");g(this,"radius");g(this,"start");g(this,"end");g(this,"largeArcFlag");g(this,"sweepFlag");g(this,"measure");g(this,"angleStart");g(this,"angleEnd");const{center:r,sweepFlag:o,largeArcFlag:s,start:i,end:a}=t;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=w.Angle(r,i),this.angleEnd=w.Angle(r,a),this.radius=w.Dist(r,i),this.measure=V6(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:l,end:c}=this,u=wS(o,a,i,r.angle(t));if(u<=0)return l;if(u>=1)return c;const h=r.clone().add(t.clone().sub(r).uni().mul(s));let p,f=1/0,S;for(const m of[l,c,h])S=w.Dist2(t,m),S<f&&(p=m,f=S);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(t,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:l}=this,c=Uu(t,r,o,s);return c===null?!1:c.some(u=>{const h=wS(i,a,l,o.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:t,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let l=0,c=Qw(Math.abs(o));l<c+1;l++){const u=l/c*r,h=i+u;a.push(Bi(t,s,h))}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 Jw extends oi{constructor(t){super({isClosed:!0,...t});g(this,"_center");g(this,"radius");g(this,"x");g(this,"y");this.config=t;const{x:r=0,y:o=0,radius:s}=t;this.x=r,this.y=o,this._center=new w(s+r,s+o),this.radius=s}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:t,radius:r}=this,o=Re*r,s=[];for(let i=0,a=Qw(o);i<a;i++){const l=i/a*Re;s.push(Bi(t,r,l))}return s}nearestPoint(t){const{_center:r,radius:o}=this;return r.equals(t)?w.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 Uu(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 nn extends Ll{constructor(t){const{start:r,cp1:o,cp2:s,end:i}=t;super({...t,points:[r,i]});g(this,"a");g(this,"b");g(this,"c");g(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const t=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;t.push(new w((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*o.x+3*(1-c)*(c*c)*s.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*o.y+3*(1-c)*(c*c)*s.y+c*c*c*i.y))}return t}midPoint(){return nn.GetAtT(this,.5)}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(t),s=w.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 w((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=nn.GetAtT(this,i/t),s+=w.Dist(o,r),o=r;return s}}class xV extends oi{constructor(t){super({...t,isClosed:!1,isFilled:!1});g(this,"points");g(this,"_segments");const{points:r}=t;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:t}=this,r=t.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?t[0]:t[i-1],l=t[i],c=t[i+1],u=i===o?c:t[i+2],h=l,p=i===0?a:new w(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),f=i===o?c:new w(c.x-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),S=c;this._segments.push(new nn({start:h,cp1:p,cp2:f,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=w.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 wV extends oi{constructor(t){super({...t,isClosed:!0});g(this,"w");g(this,"h");g(this,"_edges");this.config=t;const{width:r,height:o}=t;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:t}=this;this._edges=[];for(let r=0,o=t.length;r<o;r++){const s=t[r],i=t[(r+1)%o];this._edges.push(new 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))),l=Qw(a),c=Re/l,u=Math.cos(c),h=Math.sin(c);let p=0,f=1,S=0,m=1;const x=Array(l);for(let y=0;y<l;y++)x[y]=new w(o+o*f,s+s*p),S=h*f+u*p,m=u*f-h*p,p=S,f=m;return x}nearestPoint(t){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(t),s=w.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 Z(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 L_(i,a)}getSvgPathData(t=!1){const{w:r,h:o}=this,s=r/2,i=o/2,a=Math.max(0,s),l=Math.max(0,i);return`${t?`M${s-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class bV extends oi{constructor(t){super({...t,isClosed:!0});g(this,"w");g(this,"h");g(this,"a");g(this,"b");g(this,"c");g(this,"d");this.config=t;const{width:r,height:o}=t;if(this.w=r,this.h=o,o>r){const s=r/2;this.a=new Ha({start:new w(0,s),end:new w(r,s),center:new w(r/2,s),sweepFlag:1,largeArcFlag:1}),this.b=new Bo({start:new w(r,s),end:new w(r,o-s)}),this.c=new Ha({start:new w(r,o-s),end:new w(0,o-s),center:new w(r/2,o-s),sweepFlag:1,largeArcFlag:1}),this.d=new Bo({start:new w(0,o-s),end:new w(0,s)})}else{const s=o/2;this.a=new Ha({start:new w(s,o),end:new w(s,0),center:new w(s,s),sweepFlag:1,largeArcFlag:1}),this.b=new Bo({start:new w(s,0),end:new w(r-s,0)}),this.c=new Ha({start:new w(r-s,0),end:new w(r-s,o),center:new w(r-s,s),sweepFlag:1,largeArcFlag:1}),this.d=new Bo({start:new w(r-s,o),end:new w(s,o)})}}nearestPoint(t){let r,o=1/0,s,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(t),s=w.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(l=>l.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 Z(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 PV({shouldReload:e=!0}={}){U4(),await Promise.all(qw().map(n=>WG(n))),B4(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=PV);function CV(e,n="_blank"){Zx.openWindow(e,n)}const B2="TLDRAW_ASSET_STORE_v1",ml={Assets:"assets"};async function U2(e,n){const t=await O2(e,1,{upgrade(r){r.objectStoreNames.contains(ml.Assets)||r.createObjectStore(ml.Assets)}});try{return await n(t)}finally{t.close()}}async function IV({persistenceKey:e,assetId:n}){const t=B2+e;return await U2(t,async r=>await r.transaction([ml.Assets],"readwrite").objectStore(ml.Assets).get(n))}async function EV({persistenceKey:e,assetId:n,blob:t}){const r=B2+e;await U2(r,async o=>{const s=o.transaction([ml.Assets],"readwrite");await s.objectStore(ml.Assets).put(t,n),await s.done})}function kV({children:e}){const n=B();return G("shouldDisplayHandles",()=>{if(n.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(n.isInAny("select.editing_shape")){const r=n.getOnlySelectedShape();return r&&n.isShapeOfType(r,"note")}return!1},[n])?d.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:_V}=Math,rl=_V+1e-4;function H2(e,n={}){const{size:t=16,smoothing:r=.5}=n;if(e.length===0||t<=0)return{left:[],right:[]};const o=e[0],s=e[e.length-1],i=s.runningLength,a=Math.pow(t*r,2),l=[],c=[];let u=e[0].vector,h=e[0].point,p=h,f=h,S=p,m=!1,x;for(let y=0;y<e.length;y++){x=e[y];const{point:v,vector:b}=e[y],E=x.vector.dpr(u),I=(y<e.length-1?e[y+1]:e[y]).vector,C=y<e.length-1?I.dpr(x.vector):1,k=E<0&&!m,T=C!==null&&C<.2;if(k||T){if(C>-.62&&i-x.runningLength>x.radius){const _=u.clone().mul(x.radius);u.clone().cpr(I)<0?(f=w.Add(v,_),S=w.Sub(v,_)):(f=w.Sub(v,_),S=w.Add(v,_)),l.push(f),c.push(S)}else{const _=u.clone().mul(x.radius).per(),A=w.Sub(x.input,_);for(let L=1/13,j=0;j<1;j+=L)f=w.RotWith(A,x.input,rl*j),l.push(f),S=w.RotWith(A,x.input,rl+rl*-j),c.push(S)}h=f,p=S,T&&(m=!0);continue}if(m=!1,x===o||x===s){const _=w.Per(b).mul(x.radius);l.push(w.Sub(v,_)),c.push(w.Add(v,_));continue}const O=w.Lrp(I,b,C).per().mul(x.radius);f=w.Sub(v,O),(y<=1||w.Dist2(h,f)>a)&&(l.push(f),h=f),S=w.Add(v,O),(y<=1||w.Dist2(p,S)>a)&&(c.push(S),p=S),u=b}return{left:l,right:c}}function e0(e,n={}){const{size:t=16,start:r={},end:o={},last:s=!1}=n,{cap:i=!0}=r,{cap:a=!0}=o;if(e.length===0||t<=0)return[];const l=e[0],c=e[e.length-1],u=c.runningLength,h=r.taper===!1?0:r.taper===!0?Math.max(t,u):r.taper,p=o.taper===!1?0:o.taper===!0?Math.max(t,u):o.taper,{left:f,right:S}=H2(e,n),m=l.point,x=e.length>1?e[e.length-1].point:w.AddXY(l.point,1,1);if(e.length===1&&(!(h||p)||s)){const E=w.Add(m,w.Sub(m,x).uni().per().mul(-l.radius)),I=[];for(let C=1/13,k=C;k<=1;k+=C)I.push(w.RotWith(E,m,rl*2*k));return I}const y=[];if(!(h||p&&e.length===1))if(i)for(let E=1/8,I=E;I<=1;I+=E){const C=w.RotWith(S[0],m,rl*I);y.push(C)}else{const E=w.Sub(f[0],S[0]),I=w.Mul(E,.5),C=w.Mul(E,.51);y.push(w.Sub(m,I),w.Sub(m,C),w.Add(m,C),w.Add(m,I))}const v=[],b=c.vector.clone().per().neg();if(p||h&&e.length===1)v.push(x);else if(a){const E=w.Add(x,w.Mul(b,c.radius));for(let I=1/29,C=I;C<1;C+=I)v.push(w.RotWith(E,x,rl*3*C))}else v.push(w.Add(x,w.Mul(b,c.radius)),w.Add(x,w.Mul(b,c.radius*.99)),w.Sub(x,w.Mul(b,c.radius*.99)),w.Sub(x,w.Mul(b,c.radius)));return f.concat(v,S.reverse(),y)}const TV=.025,MV=.01;function wo(e,n={}){var x;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(w.From),a=0;if(!o){let y=i[0];for(;y&&!(y.z>=TV);)i.shift(),y=i[0]}if(!o){let y=i[i.length-1];for(;y&&!(y.z>=MV);)i.pop(),y=i[i.length-1]}if(i.length===0)return[{point:w.From(e[0]),input:w.From(e[0]),pressure:o?.5:.15,vector:new w(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(w.Dist2(l,i[0])>(r/3)**2);)i[0].z=Math.max(i[0].z,l.z),i.splice(1,1),l=i[1];const c=i.pop();for(l=i[i.length-1];l&&!(w.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=n.last||!n.simulatePressure||i.length>1&&w.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 b=w.Lrp(i[0],y,v/4);b.z=(i[0].z+(y.z-i[0].z))*v/4,i.push(b)}}const h=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new w(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=h[0],S,m;u&&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(f.point,1-s),!f.point.equals(S)&&(m=w.Dist(S,f.point),p+=m,!(y<4&&p<r)&&(f={input:i[y],point:S,pressure:o?.5:i[y].z,vector:w.Sub(f.point,S).uni(),distance:m,runningLength:p,radius:1},h.push(f)));if((x=h[1])!=null&&x.vector&&(h[0].vector=h[1].vector.clone()),p<1){const y=Math.max(.5,...h.map(v=>v.pressure));h.forEach(v=>v.pressure=y)}return h}const{min:Ss}=Math,ny=.275;function ug(e,n){const{size:t=16,thinning:r=.5,simulatePressure:o=!0,easing:s=x=>x,start:i={},end:a={}}=n,{easing:l=At.easeOutQuad}=i,{easing:c=At.easeOutCubic}=a,u=e[e.length-1].runningLength;let h,p=e[0].pressure,f;if(!o&&u<t){const x=e.reduce((y,v)=>Math.max(y,v.pressure),.5);return e.forEach(y=>{y.pressure=x,y.radius=t*s(.5-r*(.5-y.pressure))}),e}else{let x;for(let y=0,v=e.length;y<v&&(f=e[y],!(f.runningLength>t*5));y++){const b=Ss(1,f.distance/t);if(o){const E=Ss(1,1-b);x=Ss(1,p+(E-p)*(b*ny))}else x=Ss(1,p+(f.pressure-p)*.5);p=p+(x-p)*.5}for(let y=0;y<e.length;y++){if(f=e[y],r){let{pressure:v}=f;const b=Ss(1,f.distance/t);if(o){const E=Ss(1,1-b);v=Ss(1,p+(E-p)*(b*ny))}else v=Ss(1,p+(v-p)*(b*ny));f.radius=t*s(.5-r*(.5-v)),p=v}else f.radius=t/2;h===void 0&&(h=f.radius)}}const S=i.taper===!1?0:i.taper===!0?Math.max(t,u):i.taper,m=a.taper===!1?0:a.taper===!0?Math.max(t,u):a.taper;if(S||m)for(let x=0;x<e.length;x++){f=e[x];const{runningLength:y}=f,v=y<S?l(y/S):1,b=u-y<m?c((u-y)/m):1;f.radius=Math.max(.01,f.radius*Math.min(v,b))}return e}function AV(e,n={}){return e0(ug(wo(e,n),n),n)}function BC({scribble:e,zoom:n,color:t,opacity:r,className:o}){if(!e.points.length)return null;const s=AV(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:l,y:c}=e.points[e.points.length-1];i=`M ${l-a},${c} a ${a},${a} 0 1,0 ${a*2},0 a ${a},${a} 0 1,0 ${-a*2},0`}else i=Yx(s);return d.jsx("svg",{className:o&&ce("tl-overlays__item",o),children:d.jsx("path",{className:"tl-scribble",d:i,fill:t??`var(--color-${e.color})`,opacity:r??e.opacity})})}const jV=({bounds:e,rotation:n})=>{const t=B();return G("should display",()=>t.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[t])?d.jsx(nT,{bounds:e,rotation:n}):null};function as(){const e=B();return G("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function OV({size:e,width:n,height:t,hideAlternateHandles:r}){const o=N(e/3),s=o/2;return d.jsxs("svg",{className:"tl-overlays__item",children:[d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
98
|
-
${N(0-s)},${N(e)}
|
|
99
|
-
${N(0-s)},${N(0-s)}
|
|
100
|
-
${N(e)},${N(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(n/2-e),y1:N(0-s),x2:N(n/2+e),y2:N(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
101
|
-
${N(n-e)},${N(0-s)}
|
|
102
|
-
${N(n+s)},${N(0-s)}
|
|
103
|
-
${N(n+s)},${N(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(n+s),y1:N(t/2-e),x2:N(n+s),y2:N(t/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),d.jsx("polyline",{className:"tl-corner-crop-handle",points:`
|
|
104
|
-
${N(n+s)},${N(t-e)}
|
|
105
|
-
${N(n+s)},${N(t+s)}
|
|
106
|
-
${N(n-e)},${N(t+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(n/2-e),y1:N(t+s),x2:N(n/2+e),y2:N(t+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),d.jsx("polyline",{className:ce("tl-corner-crop-handle",{"tl-hidden":r}),points:`
|
|
107
|
-
${N(0+e)},${N(t+s)}
|
|
108
|
-
${N(0-s)},${N(t+s)}
|
|
109
|
-
${N(0-s)},${N(t-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),d.jsx("line",{className:ce("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:N(0-s),y1:N(t/2-e),x2:N(0-s),y2:N(t/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const DV=ar(function({bounds:n,rotation:t}){const r=B(),o=P.useRef(null),s=as(),i=ro("top"),a=ro("right"),l=ro("bottom"),c=ro("left"),u=ro("top_left"),h=ro("top_right"),p=ro("bottom_right"),f=ro("bottom_left"),S=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",m=r.getInstanceState().isCoarsePointer,x=r.getOnlySelectedShape(),y=x&&r.isShapeOrAncestorLocked(x),v=x?r.getShapeUtil(x).expandSelectionOutlinePx(x):0;if(Ol(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 b=r.getZoomLevel(),E=r.getInstanceState().isChangingStyle,I=n.width,C=n.height,k=8/b,T=I<k*2,O=C<k*2,_=I<k*4,A=C<k*4,L=I<k*5,j=C<k*5,R=m?1.75:1,F=6/b*R,W=(_?F/2:F)*(R*.75),K=(A?F/2:F)*(R*.75),z=(x?!r.getShapeUtil(x).hideSelectionBoundsFg(x):!0)&&!E;let U=z&&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")||z&&r.isIn("select.resizing")&&x&&r.isShapeOfType(x,"text");x&&U&&r.environment.isFirefox&&r.isShapeOfType(x,"embed")&&(U=!1);const X=r.isInAny("select.crop.idle","select.crop.pointing_crop","select.crop.pointing_crop_handle")&&!E&&!s,J=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!E&&!s,le=!m&&!(T||O)&&(J||X)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!y,ye=m&&(!_||!A)&&(J||X)&&(x?!r.getShapeUtil(x).hideRotateHandle(x):!0)&&!y,Me=J&&(x?r.getShapeUtil(x).canResize(x)&&!r.getShapeUtil(x).hideResizeHandles(x):!0)&&!X&&!y,ae=T||O,Ue=T&&O,je=L||j,et=Me||X,Ae=!le,at=!J||!ye,Ne=!J||!et,Wn=!J||!et||ae,Rt=!J||!et||ae,Cn=!J||!et||Ue&&!X;let St=!0,Xt=!0;if(X)St=je,Xt=je;else if(Me){St=ae||Ue||m;const ds=m&&x&&x.type==="text";Xt=St&&!ds}const _o=Math.min(24/b,C-K*3),Bl=J&&m&&x&&r.isShapeOfType(x,"text")&&_o*b>=4;return d.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:d.jsxs("g",{ref:o,children:[U&&d.jsx("rect",{className:"tl-selection__fg__outline",width:N(I),height:N(C)}),d.jsx(Kd,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:F,corner:"top_left_rotate",cursor:S?Vn("nwse-rotate",t):void 0,isHidden:Ae}),d.jsx(Kd,{"data-testid":"selection.rotate.top-right",cx:I+F*3,cy:0,targetSize:F,corner:"top_right_rotate",cursor:S?Vn("nesw-rotate",t):void 0,isHidden:Ae}),d.jsx(Kd,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:C+F*3,targetSize:F,corner:"bottom_left_rotate",cursor:S?Vn("swne-rotate",t):void 0,isHidden:Ae}),d.jsx(Kd,{"data-testid":"selection.rotate.bottom-right",cx:I+F*3,cy:C+F*3,targetSize:F,corner:"bottom_right_rotate",cursor:S?Vn("senw-rotate",t):void 0,isHidden:Ae}),d.jsx(LV,{"data-testid":"selection.rotate.mobile",cx:_?-F*1.5:I/2,cy:_?C/2:-F*1.5,size:k,isHidden:at}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":St}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:N(0-(A?K*2:K)),width:N(I),height:N(Math.max(1,K*2)),style:S?{cursor:Vn("ns-resize",t)}:void 0,...i}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Xt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:N(I-(_?0:W)),y:0,height:N(C),width:N(Math.max(1,W*2)),style:S?{cursor:Vn("ew-resize",t)}:void 0,...a}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":St}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:N(C-(A?0:K)),width:N(I),height:N(Math.max(1,K*2)),style:S?{cursor:Vn("ns-resize",t)}:void 0,...l}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Xt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:N(0-(_?W*2:W)),y:0,height:N(C),width:N(Math.max(1,W*2)),style:S?{cursor:Vn("ew-resize",t)}:void 0,...c}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Ne}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:N(0-(_?W*2:W*1.5)),y:N(0-(A?K*2:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Vn("nwse-resize",t)}:void 0,...u}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Wn}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:N(I-(_?0:W*1.5)),y:N(0-(A?K*2:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Vn("nesw-resize",t)}:void 0,...h}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Cn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:N(I-(_?W:W*1.5)),y:N(C-(A?K:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Vn("nwse-resize",t)}:void 0,...p}),d.jsx("rect",{className:ce("tl-transparent",{"tl-hidden":Rt}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:N(0-(_?W*3:W*1.5)),y:N(C-(A?0:K*1.5)),width:N(W*3),height:N(K*3),style:S?{cursor:Vn("nesw-resize",t)}:void 0,...f}),Me&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.resize.top-left",className:ce("tl-corner-handle",{"tl-hidden":Ne}),"aria-label":"top_left handle",x:N(0-k/2),y:N(0-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.top-right",className:ce("tl-corner-handle",{"tl-hidden":Wn}),"aria-label":"top_right handle",x:N(I-k/2),y:N(0-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ce("tl-corner-handle",{"tl-hidden":Cn}),"aria-label":"bottom_right handle",x:N(I-k/2),y:N(C-k/2),width:N(k),height:N(k)}),d.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ce("tl-corner-handle",{"tl-hidden":Rt}),"aria-label":"bottom_left handle",x:N(0-k/2),y:N(C-k/2),width:N(k),height:N(k)})]}),Bl&&d.jsxs(d.Fragment,{children:[d.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:N(0-k/4),y:N(C/2-_o/2),rx:k/4,width:N(k/2),height:N(_o)}),d.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:k/4,x:N(I-k/4),y:N(C/2-_o/2),width:N(k/2),height:N(_o)})]}),X&&d.jsx(OV,{size:k,width:I,height:C,hideAlternateHandles:je})]})})}),Kd=function({cx:n,cy:t,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=ro(o);return d.jsx("rect",{className:ce("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:N(n-r*3),y:N(t-r*3),width:N(Math.max(1,r*3)),height:N(Math.max(1,r*3)),cursor:s,...l})},RV=Math.sqrt(Math.PI),LV=function({cx:n,cy:t,size:r,isHidden:o,"data-testid":s}){const i=ro("mobile_rotate"),a=B(),l=G("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return d.jsxs("g",{children:[d.jsx("circle",{"data-testid":s,pointerEvents:"all",className:ce("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:n,cy:t,r:c,...i}),d.jsx("circle",{className:ce("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:n,cy:t,r:r/RV})]})};function wv(e,n,t){const{arrowheadStart:r,arrowheadEnd:o}=n.props,s=Ka(e,n,t),i=s.start.clone(),a=s.end.clone(),l=w.Med(i,a);if(w.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:l,isValid:!1,length:0};const c=w.Sub(a,i).uni(),u=hf(e,n,"start"),h=hf(e,n,"end"),p=e.getShapePageTransform(n);UC(a,s.start,p,h),UC(i,s.end,p,u);let f=0,S=0,m=0,x=0,y=Wa*n.props.scale;const v=u&&h&&u.shape===h.shape,b=u&&h?t0(e,u.shape.id,h.shape.id):"safe";b==="safe"&&u&&h&&!v&&!u.isExact&&!h.isExact&&(h.didIntersect&&!u.didIntersect?u.isClosed&&i.setTo(a.clone().add(c.clone().mul(Wa*n.props.scale))):h.didIntersect||h.isClosed&&a.setTo(i.clone().sub(c.clone().mul(Wa*n.props.scale))));const E=w.Sub(a,i),I=w.Len(E)?E.uni():w.From(E),C=!w.Equals(I,c);v||(b!=="start-contains-end"&&u&&r!=="none"&&!u.isExact&&(m=Ms[n.props.size]/2+("size"in u.shape.props?Ms[u.shape.props.size]/2:0),f=(pf+m)*n.props.scale,y+=m*n.props.scale),b!=="end-contains-start"&&h&&o!=="none"&&!h.isExact&&(x=Ms[n.props.size]/2+("size"in h.shape.props?Ms[h.shape.props.size]/2:0),S=(pf+x)*n.props.scale,y+=x*n.props.scale));const k=i.clone().add(I.clone().mul(f*(C?-1:1))),T=a.clone().sub(I.clone().mul(S*(C?-1:1)));w.DistMin(k,T,y)&&(f!==0&&S!==0?(f*=-1.5,S*=-1.5):f!==0?f*=-1:S!==0&&(S*=-1)),i.add(I.clone().mul(f*(C?-1:1))),a.sub(I.clone().mul(S*(C?-1:1))),C?(u&&h&&a.setTo(w.Add(i,I.clone().mul(-Wa*n.props.scale))),l.setTo(w.Med(s.start,s.end))):l.setTo(w.Med(i,a));const O=w.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:l,isValid:O>0,length:O}}function UC(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),l=r.isClosed,u=(l?Kw:AW)(i,a,r.outline);let h;if(u!==null&&(h=u.sort((S,m)=>w.Dist2(S,i)-w.Dist2(m,i))[0]??(l?void 0:a)),h===void 0)return;const p=oe.applyToPoint(r.transform,h),f=oe.applyToPoint(oe.Inverse(t),p);e.setTo(f),r.didIntersect=!0}function $V(e,n,t){const{arrowheadEnd:r,arrowheadStart:o}=n.props,s=n.props.bend;if(Math.abs(s)>Math.abs(n.props.bend*(UV*n.props.scale)))return wv(e,n,t);const i=Ka(e,n,t),a=w.Med(i.start,i.end),l=w.Sub(i.end,i.start),c=w.Len(l)?l.uni():w.From(l),u=w.Add(a,c.per().mul(-s)),h=hf(e,n,"start"),p=hf(e,n,"end"),f=i.start.clone(),S=i.end.clone(),m=u.clone();if(w.Equals(f,S))return{bindings:t,isStraight:!0,start:{handle:f,point:f,arrowhead:n.props.arrowheadStart},end:{handle:S,point:S,arrowhead:n.props.arrowheadEnd},middle:m,isValid:!1,length:0};const x=n.props.bend<0,y=x?Ou:$_,v=HC(f,S,m),b=w.Angle(v.center,f),E=w.Angle(v.center,S),I=y(b,E);if(v.length===0||v.size===0||!X1(v.length)||!X1(v.size))return wv(e,n,t);const C=f.clone(),k=S.clone(),T=m.clone(),O=e.getShapePageTransform(n);let _=0,A=0,L=Wa*n.props.scale;if(h&&!h.isExact){const X=oe.applyToPoint(O,C),J=oe.applyToPoint(O,v.center),le=oe.applyToPoint(O,k),ye=oe.Inverse(h.transform),Me=oe.applyToPoint(ye,X),ae=oe.applyToPoint(ye,J),Ue=oe.applyToPoint(ye,le),{isClosed:je}=h,et=je?yv:CC;let Ae,at=et(ae,v.radius,h.outline);if(at){const Ne=ae.angle(Me),Wn=ae.angle(Ue),Rt=y(Ne,Wn);at=at.filter(St=>y(Ne,ae.angle(St))<=Rt);const Cn=Rt*.25;at.sort(je?(St,Xt)=>Math.abs(y(Ne,ae.angle(St))-Cn)<Math.abs(y(Ne,ae.angle(Xt))-Cn)?-1:1:(St,Xt)=>y(Ne,ae.angle(St))<y(Ne,ae.angle(Xt))?-1:1),Ae=at[0]??(je?void 0:Me)}else Ae=je?void 0:Me;if(Ae&&(C.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(h.transform,Ae))),h.didIntersect=!0,o!=="none")){const Ne=Ms[n.props.size]/2+("size"in h.shape.props?Ms[h.shape.props.size]/2:0);_=(pf+Ne)*n.props.scale,L+=Ne*n.props.scale}}if(p&&!p.isExact){const X=oe.applyToPoint(O,C),J=oe.applyToPoint(O,k),le=oe.applyToPoint(O,v.center),ye=oe.Inverse(p.transform),Me=oe.applyToPoint(ye,X),ae=oe.applyToPoint(ye,le),Ue=oe.applyToPoint(ye,J),je=p.isClosed,et=je?yv:CC;let Ae,at=et(ae,v.radius,p.outline);if(at){const Ne=ae.angle(Me),Wn=ae.angle(Ue),Rt=y(Ne,Wn),Cn=Rt*.75;at=at.filter(St=>y(Ne,ae.angle(St))<=Rt),at.sort(je?(St,Xt)=>Math.abs(y(Ne,ae.angle(St))-Cn)<Math.abs(y(Ne,ae.angle(Xt))-Cn)?-1:1:(St,Xt)=>y(Ne,ae.angle(St))<y(Ne,ae.angle(Xt))?-1:1),at[0]?Ae=at[0]:Ae=je?void 0:Ue}else Ae=je?void 0:Ue;if(Ae&&(k.setTo(e.getPointInShapeSpace(n,oe.applyToPoint(p.transform,Ae))),p.didIntersect=!0,r!=="none")){const Ne=Ms[n.props.size]/2+("size"in p.shape.props?Ms[p.shape.props.size]/2:0);A=(pf+Ne)*n.props.scale,L+=Ne*n.props.scale}}let j=w.Angle(v.center,C),R=w.Angle(v.center,k),F=y(j,R),W=F*v.radius;const K=C.clone(),z=k.clone();if(_!==0&&K.setTo(v.center).add(w.FromAngle(j+F*(_/W*(x?1:-1))).mul(v.radius)),A!==0&&z.setTo(v.center).add(w.FromAngle(R+F*(A/W*(x?-1:1))).mul(v.radius)),w.DistMin(K,z,L)&&(_!==0&&A!==0?(_*=-1.5,A*=-1.5):_!==0?_*=-2:A!==0&&(A*=-2)),_!==0&&C.setTo(v.center).add(w.FromAngle(j+F*(_/W*(x?1:-1))).mul(v.radius)),A!==0&&k.setTo(v.center).add(w.FromAngle(R+F*(A/W*(x?-1:1))).mul(v.radius)),h&&p&&!h.isExact&&!p.isExact){j=w.Angle(v.center,C),R=w.Angle(v.center,k),F=y(j,R),W=F*v.radius;const X=t0(e,h.shape.id,p.shape.id);X==="double-bound"&&W<30?(C.setTo(f),k.setTo(S),T.setTo(m)):X==="safe"&&(h&&!h.didIntersect&&C.setTo(f),(p&&!p.didIntersect||y(b,j)>y(b,R))&&k.setTo(v.center).add(w.FromAngle(j+F*(Math.min(.9,Wa*n.props.scale/W)*(x?1:-1))).mul(v.radius)))}FV(v.center,v.radius,C,k,T,I,x),C.equals(k)&&(C.setTo(T.clone().addXY(1,1)),k.setTo(T.clone().subXY(1,1))),f.setTo(C),S.setTo(k),m.setTo(T);const U=HC(f,S,m);return{bindings:t,isStraight:!1,start:{point:f,handle:i.start,arrowhead:n.props.arrowheadStart},end:{point:S,handle:i.end,arrowhead:n.props.arrowheadEnd},middle:m,handleArc:v,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function HC(e,n,t){const r=Wx(e,n,t),o=w.Dist(r,e),s=+w.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,l=((t.y-e.y)**2+(t.x-e.x)**2)**.5,c=Math.acos((a*a+l*l-i*i)/(2*a*l))*2,u=+(ke>c),h=(Re-c)*(s?1:-1),p=h*o;return{center:r,radius:o,size:h,length:p,largeArcFlag:u,sweepFlag:s}}function FV(e,n,t,r,o,s,i){const a=w.Angle(e,t),l=w.Angle(e,r);let c=Ou(a,l);if(i||(c=Re-c),o.setTo(e).add(w.FromAngle(a+c*(.5*(i?1:-1))).mul(n)),c>s){o.rotWith(e,ke);const u=r.clone();r.setTo(t),t.setTo(u)}}const NV=8;function zV(e){return Math.abs(e.props.bend)<NV*e.props.scale}function hf(e,n,t){const r=e.getBindingsFromShape(n,"arrow").find(l=>l.props.terminal===t);if(!r)return;const o=e.getShape(r.toId);if(!o)return;const s=e.getShapePageTransform(o),i=e.getShapeGeometry(o),a=i instanceof Hr?i.children[0].vertices:i.vertices;return{shape:o,transform:s,isClosed:i.isClosed,isExact:r.props.isExact,didIntersect:!1,outline:a}}function KC(e,n,t,r){const o=e.getShape(t.toId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=w.Add(s,w.MulV(t.props.isPrecise||r?t.props.normalizedAnchor:{x:.5,y:.5},i)),l=oe.applyToPoint(e.getShapePageTransform(o),a);return oe.applyToPoint(oe.Inverse(n),l)}else return new w(0,0)}function An(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 BV=C8("arrow info",(e,n)=>{const t=An(e,n);return zV(n)?wv(e,n,t):$V(e,n,t)});function uo(e,n){const t=typeof n=="string"?n:n.id;return BV.get(e,t)}function Ka(e,n,t){var a,l;const r=e.getShapePageTransform(n),o=t0(e,(a=t.start)==null?void 0:a.toId,(l=t.end)==null?void 0:l.toId),s=t.start?KC(e,r,t.start,o==="double-bound"||o==="start-contains-end"):w.From(n.props.start),i=t.end?KC(e,r,t.end,o==="double-bound"||o==="end-contains-start"):w.From(n.props.end);return{start:s,end:i}}function cc(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(l=>l.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 Lh(e,n,t){const r=e.getBindingsFromShape(n,"arrow").filter(o=>o.props.terminal===t);e.deleteBindings(r)}const Wa=10,pf=10,UV=10,Ms={s:2,m:3.5,l:5,xl:10};function t0(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 $h extends Dh{getDefaultProps(){return{isPrecise:!1,isExact:!1,normalizedAnchor:{x:.5,y:.5}}}onAfterCreate({binding:n}){ry(this.editor,this.editor.getShape(n.fromId))}onAfterChange({bindingAfter:n}){ry(this.editor,this.editor.getShape(n.fromId))}onAfterChangeFromShape({shapeAfter:n}){ry(this.editor,n)}onAfterChangeToShape({binding:n}){K2(this.editor,n.fromId)}onBeforeIsolateFromShape({binding:n}){const t=this.editor.getShape(n.fromId);t&&ff({editor:this.editor,arrow:t,terminal:n.props.terminal})}}g($h,"type","arrow"),g($h,"props",o_),g($h,"migrations",s_);function K2(e,n){var x;const t=e.getShape(n);if(!t)return;const r=An(e,t),{start:o,end:s}=r,i=o?e.getShape(o.toId):void 0,a=s?e.getShape(s.toId):void 0,l=e.getAncestorPageId(t);if(!l)return;let c;if(i&&a)c=e.findCommonAncestor([i,a])??l;else if(i||a){const y=(x=i||a)==null?void 0:x.parentId;y&&y===t.parentId?c=t.parentId:c=l}else return;c&&c!==t.parentId&&e.reparentShapes([n],c);const u=e.getShape(n);if(!u)throw Error("no reparented arrow");const h=e.getShapeNearestSibling(u,i),p=e.getShapeNearestSibling(u,a);let f;if(h&&p)f=h.index>p.index?h:p;else if(h&&!p)f=h;else if(p&&!h)f=p;else return;let S;const m=e.getSortedChildIdsForParent(f.parentId).map(y=>e.getShape(y)).filter(y=>y.index>f.index);if(m.length){const y=m.find(v=>v.type!=="arrow");if(u.index>f.index&&(!y||u.index<y.index))return;S=Gc(f.index,m[0].index)}else S=$o(f.index);S!==u.index&&e.updateShapes([{id:n,type:"arrow",index:S}])}function ry(e,n){const t=An(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)&&ff({editor:e,arrow:n,terminal:r,unbind:!0})}K2(e,n.id)}function ff({editor:e,arrow:n,terminal:t,unbind:r=!1,useHandle:o=!1}){const s=uo(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,l=t==="start"?i:a,c={id:n.id,type:"arrow",props:{[t]:{x:l.x,y:l.y},bend:n.props.bend}};if(!s.isStraight){const u=t==="start"?i:s.start.handle,h=t==="end"?a:s.end.handle,p=w.Med(u,h),f=w.Sub(u,h).per().uni().mul(s.handleArc.radius*2*Math.sign(n.props.bend)),S=Uu(s.handleArc.center,w.Add(p,f),s.handleArc.center,s.handleArc.radius);st((S==null?void 0:S.length)===1);const m=w.Dist(p,S[0])*Math.sign(n.props.bend);Ds(m,c.props.bend)||(c.props.bend=m)}e.updateShape(c),r&&Lh(e,n,t)}const W2=[$h],Wt={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},jt={s:2,m:3.5,l:5,xl:10},yl={s:18,m:24,l:36,xl:44},Go={s:18,m:22,l:26,xl:32},HV={s:18,m:20,l:24,xl:28},yo={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},KV=20,WV=4.25,Rr=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 GV(e,n){var t=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(t!=null){var r,o,s,i,a=[],l=!0,c=!1;try{if(s=(t=t.call(e)).next,n===0){if(Object(t)!==t)return;l=!1}else for(;!(l=(r=s.call(t)).done)&&(a.push(r.value),a.length!==n);l=!0);}catch(u){c=!0,o=u}finally{try{if(!l&&t.return!=null&&(i=t.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function WC(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 Yn(e){for(var n=1;n<arguments.length;n++){var t=arguments[n]!=null?arguments[n]:{};n%2?WC(Object(t),!0).forEach(function(r){VV(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):WC(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function VV(e,n,t){return n=nY(n),n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function YV(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 XV(e,n){if(e==null)return{};var t=YV(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 GC(e,n){return ZV(e)||GV(e,n)||G2(e,n)||eY()}function Wd(e){return qV(e)||QV(e)||G2(e)||JV()}function qV(e){if(Array.isArray(e))return bv(e)}function ZV(e){if(Array.isArray(e))return e}function QV(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function G2(e,n){if(e){if(typeof e=="string")return bv(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 bv(e,n)}}function bv(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 JV(){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 eY(){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 tY(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 nY(e){var n=tY(e,"string");return typeof n=="symbol"?n:String(n)}function Bc(e){var n=e.sizes.shift(),t=Math.max(Math.ceil(n[0]),1),r=Math.max(Math.ceil(n[1]),1),o=[t-1,r-1,1,1],s=Date.now(),i=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope,a,l;i?(a=new OffscreenCanvas(1,1),l=new OffscreenCanvas(t,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,l=document.createElement("canvas"),l.width=t,l.height=r);var c=a.getContext("2d"),u=l.getContext("2d");u&&(u.fillRect.apply(u,o),c.drawImage(l,t-1,r-1,1,1,0,0,1,1));var h=c&&c.getImageData(0,0,1,1).data[3]!==0,p=Date.now()-s;return[a,l].forEach(function(f){f.height=0,f.width=0}),i?(postMessage({width:t,height:r,benchmark:p,isTestPass:h}),!h&&e.sizes.length&&Bc(e)):h?e.onSuccess(t,r,p):(e.onError(t,r,p),e.sizes.length&&Bc(e)),h}var oy={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]},rY=["onError","onSuccess"],Ga={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},uc={};function sy(e){var n=e.width===e.height,t=e.height===1,r=e.width===1,o=[];if(!e.width||!e.height)e.sizes.forEach(function(u){var h=n||t?u:1,p=n||r?u:1;o.push([h,p])});else for(var s=e.min||Ga.min,i=e.step||Ga.step,a=Math.max(e.width,e.height);a>=s;){var l=n||t?a:1,c=n||r?a:1;o.push([l,c]),a-=i}return o}function Gd(e){var n=window&&"HTMLCanvasElement"in window,t=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=XV(e,rY),a=null;if(!n)return!1;if(e.useWorker&&t){var l=`
|
|
118
|
-
var canvasTest = `.concat(Bc.toString(),`;
|
|
119
|
-
onmessage = function(e) {
|
|
120
|
-
canvasTest(e.data);
|
|
121
|
-
};
|
|
122
|
-
`),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(h){var p=h.data,f=p.width,S=p.height,m=p.benchmark,x=p.isTestPass;x?(uc[r].onSuccess(f,S,m),delete uc[r]):uc[r].onError(f,S,m)}}if(e.usePromise)return new Promise(function(h,p){var f=Yn(Yn({},e),{},{onError:function(y,v,b){var E;if(e.sizes.length===0)E=!0;else{var I=e.sizes.slice(-1),C=GC(I,1),k=GC(C[0],2),T=k[0],O=k[1];E=y===T&&v===O}o(y,v,b),E&&p({width:y,height:v,benchmark:b})},onSuccess:function(y,v,b){s(y,v,b),h({width:y,height:v,benchmark:b})}});if(a){var S=f.onError,m=f.onSuccess;uc[r]={onError:S,onSuccess:m},a.postMessage(i)}else Bc(f)});if(a)uc[r]={onError:o,onSuccess:s},a.postMessage(i);else return Bc(e)}var iy={maxArea:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=sy({width:n.max,height:n.max,min:n.min,step:n.step,sizes:Wd(oy.area)}),r=Yn(Yn(Yn({},Ga),n),{},{sizes:t});return Gd(r)},maxHeight:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=sy({width:1,height:n.max,min:n.min,step:n.step,sizes:Wd(oy.height)}),r=Yn(Yn(Yn({},Ga),n),{},{sizes:t});return Gd(r)},maxWidth:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=sy({width:n.max,height:1,min:n.min,step:n.step,sizes:Wd(oy.width)}),r=Yn(Yn(Yn({},Ga),n),{},{sizes:t});return Gd(r)},test:function(){var n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t=Yn(Yn({},Ga),n);return t.sizes=Wd(t.sizes),t.width&&t.height&&(t.sizes=[[t.width,t.height]]),Gd(t)}};let ay=null;function oY(){return ay||(ay=sY()),ay}async function sY(){const e=await iy.maxWidth({usePromise:!0}),n=await iy.maxHeight({usePromise:!0}),t=await iy.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:n.height,maxArea:t.width*t.height}}const VC=8192,iY=4096*4096;async function aY(e,n){if(e<=VC&&n<=VC&&e*n<=iY)return[e,n];const{maxWidth:t,maxHeight:r,maxArea:o}=await oY(),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 lY(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 cY(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function uY(e){const n=new URL(e).host.replace("www.","");for(const t of ju)if(V2(t.hostnames,n)){const r=t.fromEmbedUrl(e);if(r)return{definition:t,url:r,embedUrl:e}}}const dY=e=>e.split("*").map(n=>cY(n)).join(".+"),V2=(e,n)=>!!e.find(t=>{const r=new RegExp(dY(t));return n.match(r)});function hY(e){const n=new URL(e).host.replace("www.","");for(const t of ju)if(V2(t.hostnames,n)){const r=t.toEmbedUrl(e);if(r)return{definition:t,embedUrl:r,url:e}}}function Y2(e){return hY(e)??uY(e)}function As(e){try{return Y2(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 Va=" ",pn=class pn{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)||pn.insertTextFirefox(n,t),o===r.body?n.blur():o instanceof HTMLElement&&o!==n&&o.focus()}static set(n,t){n.select(),pn.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=pn.getSelection(n);pn.insert(n,t+i+(r??t)),n.selectionStart=(o||0)+t.length,n.selectionEnd=(s||0)+t.length}static replace(n,t,r){let o=0;n.value.replace(t,(...s)=>{const i=o+s[s.length-2],a=s[0].length;n.selectionStart=i,n.selectionEnd=i+a;const l=typeof r=="string"?r:r(...s);return pn.insert(n,l),n.selectionStart=i,o+=l.length-a,l})}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 l=o.lastIndexOf(`
|
|
128
|
-
`,t-1)+1,c=n.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${Va}`),h=u.length-c.length;n.setSelectionRange(l,r-1),pn.insert(n,u),n.setSelectionRange(t+1,r+h)}else pn.insert(n,Va)}static unindent(n){const{selectionStart:t,selectionEnd:r,value:o}=n,s=o.lastIndexOf(`
|
|
129
|
-
`,t-1)+1,i=pn.findLineEnd(o,r),a=n.value.slice(s,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;n.setSelectionRange(s,i),pn.insert(n,l);const u=/\t| {1,2}/.exec(o.slice(s,t)),h=u?u[0].length:0,p=t-h;n.setSelectionRange(t-h,Math.max(p,r-c))}static indentCE(n){var l;const t=window.getSelection(),r=n.innerText,o=Vd(n)??0,s=Vd(n)??0,i=r.slice(o,s),a=(l=/\n/g.exec(i))==null?void 0:l.length;if(a&&a>0){const c=r.lastIndexOf(`
|
|
130
|
-
`,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${Va}`).length-u.length;t&&t.setBaseAndExtent(n,o+1,n,s+p)}else{const c=window.getSelection();n.innerText=r.slice(0,o)+Va+r.slice(o),c==null||c.setBaseAndExtent(n,o+1,n,o+2)}}static unindentCE(n){const t=window.getSelection(),r=n.innerText,o=Vd(n)??0,s=Vd(n)??0,i=r.lastIndexOf(`
|
|
131
|
-
`,o-1)+1,a=pn.findLineEnd(r,s),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=l.length-c.length;if(t){t.setBaseAndExtent(n,i,n,a);const h=/\t| {1,2}/.exec(r.slice(i,o)),p=h?h[0].length:0,f=o-p;t.setBaseAndExtent(n,o-p,n,Math.max(f,s-u))}}static normalizeText(n){return n.replace(pn.fixNewLines,`
|
|
132
|
-
`)}static normalizeTextForDom(n){return n.replace(pn.fixNewLines,`
|
|
133
|
-
`).split(`
|
|
134
|
-
`).map(t=>t||" ").join(`
|
|
135
|
-
`)}};g(pn,"fixNewLines",/\r?\n|\r/g);let Sl=pn;function Vd(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 pY=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function X2(e){return pY.test(e)}function fY(e){return e.replace(/\t/g,Va)}function gY(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 mY(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function yY(e){return mY(gY(fY(e)))}function SY(e,{maxImageDimension:n,maxAssetSize:t,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i},a){e.registerExternalAssetHandler("file",async({file:l})=>{const c=l.name;let u=l;const h=r.includes(u.type),p=o.includes(u.type);st(h||p,`File type not allowed: ${u.type}`),st(u.size<=t,`File size too big: ${(u.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),u.type==="video/quicktime"&&(u=new Blob([u],{type:"video/mp4"}));let f=h?await lo.getImageSize(u):await lo.getVideoSize(u);const S=await lo.isAnimated(u)||p,m=await k4(await u.arrayBuffer());if(isFinite(n)){const v=lY(f,{w:n,h:n});f!==v&&lo.isStaticImageType(u.type)&&(f=v)}const x=Ci.createId(m),y={id:x,type:h?"image":"video",typeName:"asset",props:{name:c,src:"",w:f.w,h:f.h,fileSize:u.size,mimeType:u.type,isAnimated:S}};return a?(y.props.src=x,await EV({persistenceKey:a,assetId:x,blob:u})):y.props.src=await Ai.blobToDataUrl(u),Ci.create(y)}),e.registerExternalAssetHandler("url",async({url:l})=>{var u,h,p,f,S;let c;try{const x=await(await So(l,{method:"GET",mode:"no-cors"})).text(),y=new DOMParser().parseFromString(x,"text/html");c={image:((u=y.head.querySelector('meta[property="og:image"]'))==null?void 0:u.getAttribute("content"))??"",favicon:((h=y.head.querySelector('link[rel="apple-touch-icon"]'))==null?void 0:h.getAttribute("href"))??((p=y.head.querySelector('link[rel="icon"]'))==null?void 0:p.getAttribute("href"))??"",title:((f=y.head.querySelector('meta[property="og:title"]'))==null?void 0:f.getAttribute("content"))??l,description:((S=y.head.querySelector('meta[property="og:description"]'))==null?void 0:S.getAttribute("content"))??""},c.image.startsWith("/")&&(c.image=new URL(c.image,l).href),c.favicon.startsWith("/")&&(c.favicon=new URL(c.favicon,l).href)}catch(m){console.error(m),s.addToast({title:i("assets.url.failed"),severity:"error"}),c={image:"",favicon:"",title:"",description:""}}return{id:Ci.createId(uS(l)),typeName:"asset",type:"bookmark",props:{src:l,description:c.description,image:c.image,favicon:c.favicon,title:c.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:l,text:c})=>{const u=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=new DOMParser().parseFromString(c,"image/svg+xml").querySelector("svg");if(!h)throw new Error("No <svg/> element present");let p=parseFloat(h.getAttribute("width")||"0"),f=parseFloat(h.getAttribute("height")||"0");if(!(p&&f)){document.body.appendChild(h);const m=h.getBoundingClientRect();document.body.removeChild(h),p=m.width,f=m.height}const S=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});if(!S)throw Error("Could not create an asset");YC(e,[S],u)}),e.registerExternalContentHandler("embed",({point:l,url:c,embed:u})=>{const h=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),{width:p,height:f}=u,S=$e(),m={id:S,type:"embed",x:h.x-(p||450)/2,y:h.y-(f||450)/2,props:{w:p,h:f,url:c}};e.createShapes([m]).select(S)}),e.registerExternalContentHandler("files",async({point:l,files:c})=>{const u=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=new w(u.x,u.y),p=[];await Promise.all(c.map(async(f,S)=>{if(f.size>t)return console.warn(`File size too big: ${(f.size/1024).toFixed()}kb > ${(t/1024).toFixed()}kb`),null;if(!f.type)throw new Error("No mime type");if(!r.concat(o).includes(f.type))return console.warn(`${f.name} not loaded - Extension not allowed.`),null;try{const m=await e.getAssetForExternalContent({type:"file",file:f});if(!m)throw Error("Could not create an asset");p[S]=m}catch(m){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(m),null}})),YC(e,me(p),h)}),e.registerExternalContentHandler("text",async({point:l,text:c})=>{const u=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),h=e.getShapeUtil("text").getDefaultProps(),p=yY(c),f=e.getOnlySelectedShape();if(f&&"text"in f.props){e.updateShapes([{id:f.id,type:f.type,props:{text:p}}]);return}let S,m,x,y="middle";const v=p.split(`
|
|
138
|
-
`).length>1,b=X2(p);v&&(y=v?b?"end":"start":"middle");const E=e.textMeasure.measureText(p,{...Wt,fontFamily:yo[h.font],fontSize:yl[h.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(p,{...Wt,fontFamily:yo[h.font],fontSize:yl[h.size],maxWidth:I});S=C.w,m=C.h,x=!1,y=b?"end":"start"}else S=E.w,m=E.h,x=!0;u.y-m/2<e.getViewportPageBounds().minY+40&&(u.y=e.getViewportPageBounds().minY+40+m/2),e.createShapes([{id:$e(),type:"text",x:u.x-S/2,y:u.y-m/2,props:{text:p,textAlign:y,autoSize:x,w:S}}])}),e.registerExternalContentHandler("url",async({point:l,url:c})=>{const u=As(c);if(u)return e.putExternalContent({type:"embed",url:u.url,point:l,embed:u.definition});const h=l??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageBounds().center),p=Ci.createId(uS(c)),f=vY(e,c,h);let S=e.getAsset(p),m=!1;if(!S){m=!0;try{const x=await e.getAssetForExternalContent({type:"url",url:c});if(!x)throw Error("Could not create an asset");S=x}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{m&&e.createAssets([S]),e.updateShapes([{id:f.id,type:f.type,props:{assetId:S.id}}])})})}async function YC(e,n,t){if(!n.length)return[];const r=w.From(t),o=[];for(let s=0;s<n.length;s++){const i=n[s];switch(i.type){case"bookmark":{o.push({id:$e(),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:$e(),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:$e(),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)),q2(e,t)}),o.map(s=>s.id)}function q2(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=w.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 vY(e,n,t){const r={id:$e(),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),q2(e,t)}),e.getShape(r.id)}const xY=new Yo,wY=e=>async n=>!n||!n.props.src?null:e&&n.props.src.startsWith("asset:")?await xY.get(n,async()=>await bY(e,n.id)):n.type==="video"?n.props.src:n.type!=="image"?null:n.props.src;async function bY(e,n){const t=await IV({assetId:n,persistenceKey:e});return t?URL.createObjectURL(t):null}var jy;let PY=(jy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")});g(this,"onKeyUp",t=>{var r;if(t.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const o=this.editor.getOnlySelectedShape();o&&this.editor.getShapeUtil(o).canEdit(o)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(o.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...t,target:"shape",shape:o}))}})}},g(jy,"id","idle"),jy);var Oy;let CY=(Oy=class extends se{constructor(){super(...arguments);g(this,"shape");g(this,"markId","");g(this,"onEnter",()=>{this.didTimeout=!1;const t=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.canBindShapes({fromShape:"arrow",toShape:r,binding:"arrow"}),margin:0,hitInside:!0,renderingOnly:!0});t?this.editor.setHintingShapes([t.id]):this.createArrowShape(),this.startPreciseTimeout()});g(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});g(this,"onPointerMove",()=>{if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:{id:"end",type:"vertex",index:"a3",x:0,y:0},isCreating:!0,onInteractionEnd:"arrow"})}});g(this,"onPointerUp",()=>{this.cancel()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()});g(this,"preciseTimeout",-1);g(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u;const{originPagePoint:t}=this.editor.inputs,r=$e();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,l=s.find(h=>h.id==="start"),c=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});c&&this.editor.updateShapes([c]),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,l=r.find(u=>u.id==="start"),c=(o=i.onHandleDrag)==null?void 0:o.call(i,t,{handle:{...l,x:0,y:0},isPrecise:this.didTimeout,initial:a});c&&this.editor.updateShapes([c])}{const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=this.editor.getPointInShapeSpace(t,this.editor.inputs.currentPagePoint),c=r.find(h=>h.id==="end"),u=(s=i.onHandleDrag)==null?void 0:s.call(i,this.editor.getShape(t),{handle:{...c,x:l.x,y:l.y},isPrecise:!1,initial:a});u&&this.editor.updateShapes([u])}this.shape=this.editor.getShape(t.id)}startPreciseTimeout(){this.preciseTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},g(Oy,"id","pointing"),Oy);class Fh extends se{constructor(){super(...arguments);g(this,"shapeType","arrow")}}g(Fh,"id","arrow"),g(Fh,"initial","idle"),g(Fh,"children",()=>[PY,CY]);class n0 extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"initialShape");g(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");g(this,"util",this.editor.getShapeUtil(this.shapeType));g(this,"isPen",!1);g(this,"isPenOrStylus",!1);g(this,"segmentMode","free");g(this,"didJustShiftClickToExtendPreviousShapeLine",!1);g(this,"pagePointWhereCurrentSegmentChanged",{});g(this,"pagePointWhereNextSegmentChanged",null);g(this,"lastRecordedPoint",{});g(this,"mergeNextPoint",!1);g(this,"currentLineLength",0);g(this,"canDraw",!1);g(this,"markId",null);g(this,"onEnter",t=>{this.markId=null,this.info=t,this.canDraw=!this.editor.getIsMenuOpen(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()});g(this,"onPointerMove",()=>{const{inputs:t}=this.editor;if(this.isPen&&!t.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&t.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(this.isPenOrStylus?w.Dist(t.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=t.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateDrawingShape())});g(this,"onKeyDown",t=>{if(t.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateDrawingShape()});g(this,"onKeyUp",t=>{if(t.key==="Shift")switch(this.editor.snaps.clearIndicators(),this.segmentMode){case"straight":{this.segmentMode="starting_free",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_straight":{this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";break}}this.updateDrawingShape()});g(this,"onExit",()=>{this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())})}canClose(){return this.shapeType!=="highlight"}getIsClosed(t,r){if(!this.canClose())return!1;const o=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&&w.DistMin(s,a,o*2)}startShape(){const{inputs:{originPagePoint:t,isPen:r}}=this.editor;this.markId="draw start "+ot(),this.editor.mark(this.markId);const{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 l=Nt(a.props.segments);if(!l)throw Error("Expected a previous segment!");const c=Nt(l.points);if(!c)throw Error("Expected a previous point!");const{x:u,y:h}=this.editor.getPointInShapeSpace(a,t).toFixed(),p={type:this.segmentMode,points:[{x:c.x,y:c.y,z:+s.toFixed(2)},{x:u,y:h,z:+s.toFixed(2)}]},f=oe.applyToPoint(this.editor.getShapePageTransform(a.id),c);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const S=[...a.props.segments,p];this.currentLineLength<jt[a.props.size]*4&&(this.currentLineLength=this.getLineLength(S));const m={id:a.id,type:this.shapeType,props:{segments:S}};this.canClose()&&(m.props.isClosed=this.getIsClosed(S,a.props.size)),this.editor.updateShapes([m]);return}}this.pagePointWhereCurrentSegmentChanged=t.clone();const i=$e();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:l,y:c,z:u}=this.editor.getPointInShapeSpace(i,r.currentPagePoint).toFixed(),h=this.isPenOrStylus?+(r.currentPagePoint.z*1.25).toFixed(2):.5,p={x:l,y:c,z:h};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:f}=this;if(f===null)throw Error("We should have a point where the segment changed");if(w.Dist2(f,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const m=Nt(a);if(!m)throw Error("Expected a previous segment!");const x=Nt(m.points);if(!x)throw Error("Expected a previous last point!");let y;const v=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(m.type==="straight"){this.currentLineLength+=w.Dist(x,v),y={type:"straight",points:[{...x},v]};const E=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=oe.applyToPoint(E,x)}else y={type:"straight",points:[v,p]};const b={id:o,type:this.shapeType,props:{segments:[...a,y]}};this.canClose()&&(b.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([b])}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:f}=this;if(f===null)throw Error("We should have a point where the segment changed");if(w.Dist2(f,r.currentPagePoint)>this.editor.options.dragDistanceSquared){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const m=a.slice(),x=m[m.length-1],y=Nt(x.points);if(!y)throw Error("No previous point!");const v={type:"free",points:[...w.PointsBetween(y,p,6).map(I=>({x:Fo(I.x),y:Fo(I.y),z:Fo(I.z)}))]},b=[...m,v];this.currentLineLength<jt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(b));const E={id:o,type:this.shapeType,props:{segments:b}};this.canClose()&&(E.props.isClosed=this.getIsClosed(b,s)),this.editor.updateShapes([E])}break}case"straight":{const f=a.slice(),S=f[f.length-1],{pagePointWhereCurrentSegmentChanged:m}=this,{ctrlKey:x,currentPagePoint:y}=this.editor.inputs;if(!m)throw Error("We should have a point where the segment changed");let v,b=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(b=!x,this.didJustShiftClickToExtendPreviousShapeLine=!1):b=!x;let E=this.editor.getPointInShapeSpace(i,y).toFixed().toJson(),I=!1,C;if((this.editor.user.getIsSnapMode()?!x:x)&&f.length>2){let O,_=8/this.editor.getZoomLevel();for(let A=0,L=a.length-2;A<L;A++){const j=a[A];if(!j)break;if(j.type==="free")continue;const R=j.points[0],F=Nt(j.points);if(!(R&&F))continue;const W=w.NearestPointOnLineSegment(R,F,E);if(w.DistMin(W,E,_)){O=W.toFixed().toJson(),_=w.Dist(W,E),C=j;break}}O&&(I=!0,E=O)}if(I&&C){const O=this.editor.getShapePageTransform(i),_=C.points[0],A=Nt(C.points);if(!A)throw Error("Expected a last point!");const L=oe.applyToPoint(O,_),j=oe.applyToPoint(O,A),R=oe.applyToPoint(O,E);this.editor.snaps.setIndicators([{id:ot(),type:"points",points:[L,R,j]}])}else{if(this.editor.snaps.clearIndicators(),b){const O=w.Angle(m,y),A=$p(O,24)-O;v=w.RotWith(y,m,A)}else v=y;E=this.editor.getPointInShapeSpace(i,v).toFixed().toJson()}this.currentLineLength+=w.Dist(S.points[0],E),f[f.length-1]={...S,type:"straight",points:[S.points[0],E]};const T={id:o,type:this.shapeType,props:{segments:f}};this.canClose()&&(T.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([T]);break}case"free":{const f=a.slice(),S=f[f.length-1],m=[...S.points];if(m.length&&this.mergeNextPoint){const{z:y}=m[m.length-1];m[m.length-1]={x:p.x,y:p.y,z:y?Math.max(y,p.z):p.z}}else this.currentLineLength+=w.Dist(m[m.length-1],p),m.push(p);f[f.length-1]={...S,points:m},this.currentLineLength<jt[i.props.size]*4&&(this.currentLineLength=this.getLineLength(f));const x={id:o,type:this.shapeType,props:{segments:f}};if(this.canClose()&&(x.props.isClosed=this.getIsClosed(f,s)),this.editor.updateShapes([x]),m.length>this.editor.options.maxPointsPerDrawShape){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const y=$e(),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?+(u*1.25).toFixed():.5}]}]}}]),this.initialShape=rt(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+=w.Dist2(a,i)}return Math.sqrt(r)}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:t}=this;t&&(this.editor.updateShapes([{id:t.id,type:t.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}g(n0,"id","drawing");var Dy;let Z2=(Dy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("drawing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Dy,"id","idle"),Dy);class Nh extends se{constructor(){super(...arguments);g(this,"shapeType","draw");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Nh,"id","draw"),g(Nh,"initial","idle"),g(Nh,"children",()=>[Z2,n0]);class Pv extends Rh{constructor(){super(...arguments);g(this,"shapeType","frame");g(this,"onCreate",t=>{if(!t)return;const r=this.editor.getShapePageBounds(t),o=[],s=this.editor.getShapeAncestors(t).map(i=>i.id);this.editor.getSortedChildIdsForParent(t.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===t.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&IY(a,s,t)&&o.push(a.id)}),this.editor.reparentShapes(o,t.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}g(Pv,"id","frame"),g(Pv,"initial","idle");function IY(e,n,t){return n.includes(e.id)?!1:e.parentId===t.parentId}var Ry;let EY=(Ry=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onKeyUp",t=>{var r;if(t.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const o=this.editor.getOnlySelectedShape();o&&this.editor.getShapeUtil(o).canEdit(o)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(o.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...t,target:"shape",shape:o}))}});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Ry,"id","idle"),Ry);var Ly;let kY=(Ly=class extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onPointerUp",()=>{this.complete()});g(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=$e();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(Nr),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"})}});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:t}=this.editor.inputs,r=$e();this.markId=`creating:${r}`,this.editor.mark(this.markId);const o=this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1,s=this.editor.getStyleForNextShape(Nr),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(Nr),scale:o,...i}}]);const a=this.editor.getShape(r);if(!a)return;const{w:l,h:c}=a.props,u=new w(l/2,c/2).mul(o),h=this.editor.getShapeParentTransform(a);h&&u.rot(-h.rotation()),this.editor.select(r),this.editor.updateShape({id:a.id,type:"geo",x:a.x-u.x,y:a.y-u.y,props:{geo:this.editor.getStyleForNextShape(Nr),w:l*o,h:c*o}}),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},g(Ly,"id","pointing"),Ly);class zh extends se{constructor(){super(...arguments);g(this,"shapeType","geo")}}g(zh,"id","geo"),g(zh,"initial","idle"),g(zh,"children",()=>[EY,kY]);class Bh extends se{constructor(){super(...arguments);g(this,"shapeType","highlight");g(this,"onExit",()=>{const t=this.children.drawing;t.initialShape=void 0})}}g(Bh,"id","highlight"),g(Bh,"initial","idle"),g(Bh,"children",()=>[Z2,n0]);var $y;let _Y=($y=class extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"onEnter",t=>{this.shapeId=t.shapeId,this.editor.setCursor({type:"cross",rotation:0})});g(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g($y,"id","idle"),$y);const XC=2;var Fy;let TY=(Fy=class extends se{constructor(){super(...arguments);g(this,"shape",{});g(this,"markId");g(this,"onEnter",t=>{const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=t.shapeId&&this.editor.getShape(t.shapeId);if(s&&r.shiftKey){this.markId=`creating:${s.id}`,this.editor.mark(this.markId),this.shape=s;const i=this.editor.getShapeHandles(this.shape);if(!i)return;const a=i.filter(f=>f.type==="vertex").sort(on),l=a[a.length-1],c=a[a.length-2],u=oe.applyToPoint(this.editor.getShapeParentTransform(this.shape),new w(this.shape.x,this.shape.y)),h=w.Sub(o,u).addXY(.1,.1),p=rt(this.shape.props.points);if(w.DistMin(l,c,XC)||w.DistMin(h,l,XC))p[l.id]={id:l.id,index:l.index,x:h.x,y:h.y};else{const f=$o(l.index);p[f]={id:f,index:f,x:h.x,y:h.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=$e();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)}});g(this,"onPointerMove",()=>{if(this.shape&&this.editor.inputs.isDragging){const t=this.editor.getShapeHandles(this.shape);if(!t)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Nt(t);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()})}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}},g(Fy,"id","pointing"),Fy);class Uh extends se{constructor(){super(...arguments);g(this,"shapeType","line")}}g(Uh,"id","line"),g(Uh,"initial","idle"),g(Uh,"children",()=>[_Y,TY]);var Ny;let MY=(Ny=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Ny,"id","idle"),Ny);function Ke(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=Q2(e,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=e.getShapeUtil(s),l=me(i.map(c=>e.getShape(c)));(o=a.onDragShapesOut)==null||o.call(a,s,l)}}function Q2(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 l of t){const c=e.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}o??(o=e.getShapeGeometry(n)),s??(s=e.getShapePageTransform(n)),i??(i=s.applyToPoints(o.vertices));const u=e.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:h,isClosed:p}=e.getShapeGeometry(l);if(!h.some(f=>tr(f,u))){if(p){if(P2(u,h))continue}else if(DW(u,h))continue;a.push(l)}}return a}function gf(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}),J2(e)}const AY=16;function J2(e){const n=e.getSelectionPageBounds(),t=e.getViewportPageBounds();if(n&&!t.contains(n)){const r=n.clone().expandBy(AY/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 _i=20,jY=0,Be=200,dg=new w(Be/2,Be/2),eA=10,OY=[[["a1"],new w(Be*.5,Be*-.5-_i)],[["a2"],new w(Be*1.5+_i,Be*.5)],[["a3"],new w(Be*.5,Be*1.5+_i)],[["a4"],new w(Be*-.5-_i,Be*.5)]];function DY(e){if(e===1)return OY;const n=Be*e,t=_i*e;return[[["a1"],new w(n*.5,n*-.5-t)],[["a2"],new w(n*1.5+t,n*.5)],[["a3"],new w(n*.5,n*1.5+t)],[["a4"],new w(n*-.5-t,n*.5)]]}function tA(e,n,t,r,o){return Object.fromEntries(DY(o).map(([s,i],a)=>{const l=i.clone();return a===0&&r?l.y-=r:a===2&&t&&(l.y+=t),[s,l.rot(n).add(e)]}))}function nA(e,n,t,r){const o=new Set(e.getSelectedShapeIds()),s=(Be+_i+r)**2,i=new Map,a=[];for(const u of e.getCurrentPageShapes()){if(!e.isShapeOfType(u,"note")||t!==u.props.scale||o.has(u.id))continue;const h=e.getShapePageTransform(u.id);n===h.rotation()&&(i.set(u,e.getShapePageBounds(u).center),a.push(...Object.values(tA(h.point(),n,u.props.growY,r,t))))}const l=a.length;let c;for(const[u,h]of i)for(let p=0;p<l;p++)c=a[p],c&&(w.Dist2(h,c)>s||e.isPointInShape(u,c)&&(a[p]=void 0));return me(a)}function rA(e,n,t,r,o=!1){let s;const i=e.getCurrentPageShapesSorted(),a=(Be+_i**2)**n.props.scale;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==n.id){const u=e.getShapePageBounds(c);if(u&&w.Dist2(u.center,t)<a&&e.isPointInShape(c,t)){s=c;break}}}if(e.complete(),!s||o){e.mark("creating note shape");const l=$e();e.createShape({id:l,type:"note",x:t.x,y:t.y,rotation:r,opacity:n.opacity,props:{...n.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const c=e.getShape(l);if(!c)return;const u=e.getPointInParentSpace(c,w.Sub(t,w.Rot(dg.clone().mul(c.props.scale),r)));e.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=e.getShape(l)}return J2(e),s}var zy;let RY=(zy=class extends se{constructor(){super(...arguments);g(this,"dragged",!1);g(this,"info",{});g(this,"wasFocusedOnEnter",!1);g(this,"markId","");g(this,"shape",{});g(this,"onEnter",()=>{const{editor:t}=this;if(this.wasFocusedOnEnter=!t.getIsMenuOpen(),this.wasFocusedOnEnter){const r=$e();this.markId=`creating:${r}`,t.mark(this.markId);const o=this.editor.inputs.originPagePoint.clone(),s=qC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=ZC(this.editor,r,o)}});g(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=$e(),o=this.editor.inputs.originPagePoint.clone(),s=qC(this.editor,o,this.editor.user.getIsDynamicResizeMode()?1/this.editor.getZoomLevel():1);s&&o.sub(s),this.shape=ZC(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...t,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()})}complete(){this.wasFocusedOnEnter&&(this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape})))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},g(zy,"id","pointing"),zy);function qC(e,n,t){let r=eA/e.getZoomLevel(),o;for(const s of nA(e,0,t,0)){const i=w.Sub(n,s),a=i.len();a<r&&(r=a,o=i)}return o}function ZC(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 Hh extends se{constructor(){super(...arguments);g(this,"shapeType","note")}}g(Hh,"id","note"),g(Hh,"initial","idle"),g(Hh,"children",()=>[MY,RY]);function LY(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=pk(LY,32);var By;let $Y=(By=class extends se{constructor(){super(...arguments);g(this,"onPointerMove",t=>{switch(t.target){case"shape":case"canvas":Uo(this.editor)}});g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});g(this,"onExit",()=>{Uo.cancel()});g(this,"onKeyDown",t=>{var r;if(t.key==="Enter"){if(this.editor.getInstanceState().isReadonly)return null;const o=this.editor.getOnlySelectedShape();o&&this.editor.getShapeUtil(o).canEdit(o)&&(this.editor.setCurrentTool("select"),this.editor.setEditingShape(o.id),(r=this.editor.root.getCurrent())==null||r.transition("editing_shape",{...t,target:"shape",shape:o}))}});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(By,"id","idle"),By);var Uy;let FY=(Uy=class extends se{constructor(){super(...arguments);g(this,"shape");g(this,"markId","");g(this,"onExit",()=>{this.editor.setHintingShapes([])});g(this,"onPointerMove",t=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,o=$e();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")}})}});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.cancel()});g(this,"onCancel",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}complete(){var s;this.editor.mark("creating text shape");const t=$e(),{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 w;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,_n(s.parentId)){const l=this.editor.getShapeParentTransform(s);a.rot(-l.rotation())}return this.editor.updateShape({...s,x:s.x+a.x,y:s.y+a.y}),s}},g(Uy,"id","pointing"),Uy);class Kh extends se{constructor(){super(...arguments);g(this,"shapeType","text")}}g(Kh,"id","text"),g(Kh,"initial","idle"),g(Kh,"children",()=>[$Y,FY]);const NY=[Kh,Nh,zh,Hh,Uh,Pv,Fh,Bh];function Tr(){return ss({isDarkMode:Ku()})}function vl(e){return{key:`${vo.id}:${e}`,getElement:async()=>{const n=zY(e);if(!n)return null;const t=n.$$_url,r=n.$$_fontface;if(!t||!r)return null;const o=await(await So(t)).blob(),s=await Ai.blobToDataUrl(o),i=r.replace(t,s);return d.jsx("style",{children:i})}}}function zY(e){const n=e_[e];for(const t of document.fonts)if(n.includes(t.family))return t;return null}function r0(e){return{key:`${vo.id}:${e}`,getElement:async()=>e!=="pattern"?null:d.jsx(BY,{})}}function BY(){const e=Tr(),n=8/12;return d.jsxs(d.Fragment,{children:[d.jsxs("mask",{id:"hash_pattern_mask",children:[d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),d.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[d.jsx("line",{x1:n*1,y1:n*3,x2:n*3,y2:n*1}),d.jsx("line",{x1:n*5,y1:n*7,x2:n*7,y2:n*5}),d.jsx("line",{x1:n*9,y1:n*11,x2:n*11,y2:n*9})]})]}),d.jsx("pattern",{id:mf(1,e.id),width:"8",height:"8",patternUnits:"userSpaceOnUse",children:d.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function o0(){return{key:`${vo.id}:pattern`,component:WY}}const Cc=8,QC=(e,n,t)=>new Promise((r,o)=>{const s=Cc*n*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=t?Mp.darkMode.solid:Mp.lightMode.solid,a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*n*e;const l=8/12,c=u=>u*n*e;a.beginPath(),a.moveTo(c(l*1),c(l*3)),a.lineTo(c(l*3),c(l*1)),a.moveTo(c(l*5),c(l*7)),a.lineTo(c(l*7),c(l*5)),a.moveTo(c(l*9),c(l*11)),a.lineTo(c(l*11),c(l*9)),a.stroke(),i.toBlob(u=>{!u||xt.throwToBlob.get()?o():r(u)})}),JC=(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 ly=null;function UY(){return ly||(ly={white:JC([1,1],e=>{e.fillStyle="#f8f9fa",e.fillRect(0,0,1,1)}),black:JC([1,1],e=>{e.fillStyle="#212529",e.fillRect(0,0,1,1)})}),ly}function oA(e){return Math.ceil(Math.log2(Math.max(1,e)))}function mf(e,n){const t=oA(e);return`tldraw_hash_pattern_${n}_${t}`}function sA(e){const n=[],r=oA(e);for(let o=0;o<=r;o++)n.push(Math.pow(2,o));return n}function HY(e){const n=UY();return sA(e).flatMap(t=>[{zoom:t,url:n.white,theme:"light"},{zoom:t,url:n.black,theme:"dark"}])}function KY(){const e=B(),n=G("devicePixelRatio",()=>e.getInstanceState().devicePixelRatio,[e]),t=G("maxZoom",()=>Math.ceil(Nt(e.getCameraOptions().zoomSteps)),[e]),[r,o]=P.useState(!1),[s,i]=P.useState(()=>HY(t));return P.useEffect(()=>{const l=Promise.all(sA(t).flatMap(u=>[QC(n,u,!1).then(h=>({zoom:u,theme:"light",url:URL.createObjectURL(h)})),QC(n,u,!0).then(h=>({zoom:u,theme:"dark",url:URL.createObjectURL(h)}))]));let c=!1;return l.then(u=>{c||(i(u),o(!0))}),()=>{c=!0,o(!1),l.then(u=>{for(const{url:h}of u)URL.revokeObjectURL(h)})}},[n,t]),{defs:d.jsx(d.Fragment,{children:s.map(l=>{const c=mf(l.zoom,l.theme);return d.jsx("pattern",{id:c,width:Cc,height:Cc,patternUnits:"userSpaceOnUse",children:d.jsx("image",{href:l.url,width:Cc,height:Cc})},c)})}),isReady:r}}function WY(){const e=B(),n=P.useRef(null),{defs:t,isReady:r}=KY();return P.useEffect(()=>{if(r&&e.environment.isSafari){const o=iA(n.current);o&&e.timers.requestAnimationFrame(()=>{o.style.display="none",e.timers.requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),d.jsx("g",{ref:n,"data-testid":r?"ready-pattern-fill-defs":void 0,children:t})}function iA(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?iA(e.parentElement):null}const en=xe.memo(function({theme:n,d:t,color:r,fill:o,scale:s}){switch(o){case"none":return null;case"solid":return d.jsx("path",{fill:n[r].semi,d:t});case"semi":return d.jsx("path",{fill:n.solid,d:t});case"fill":return d.jsx("path",{fill:n[r].fill,d:t});case"pattern":return d.jsx(GY,{theme:n,color:r,fill:o,d:t,scale:s})}});function GY({d:e,color:n,theme:t}){const r=B(),o=_2(),s=G("zoomLevel",()=>r.getZoomLevel(),[r]),i=r.getZoomLevel()<=.18;return d.jsxs(d.Fragment,{children:[d.jsx("path",{fill:t[n].pattern,d:e}),d.jsx("path",{fill:o?`url(#${mf(1,t.id)})`:i?t[n].semi:`url(#${mf(s,t.id)})`,d:e})]})}function VY(e){return e.replace(/\s/g," ")}function Cv(e,n,t){const{padding:r=0}=t;if(n.length===0)return null;const o=Z.From(n[0].box);for(const{box:c}of n)o.union(c);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 l=[];for(const{text:c,box:u}of n)a!==null&&u.y>a&&l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
|
|
139
|
-
`},l.length)),l.push(d.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,unicodeBidi:"plaintext",children:VY(c)},l.length)),a=u.y;return d.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:l})}function YY(e,n,t,r){if((e==="start-legacy"||e==="end-legacy")&&t.length!==0){const o=Z.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 XY(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function hg({fontSize:e,font:n,align:t,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=B(),u=Tr(),h={fontSize:e,fontFamily:e_[n],textAlign:t,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Wt.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:s,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(o,h),f=YY(t,a,p,i.width);f&&(h.offsetX=f),h.offsetX+=i.x,h.offsetY+=i.y;const S=Cv(c,p,h);let m=null;return l&&(h.fill=u.background,h.stroke=u.background,h.strokeWidth=2,m=Cv(c,p,h)),d.jsxs(d.Fragment,{children:[m,S]})}const qY=P.forwardRef(function({isEditing:n,text:t,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return d.jsx("textarea",{ref:c,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:Ht,onContextMenu:n?Ht:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:Ee})});function ZY(e,n,t){const r=B(),o=P.useRef(null),s=G("isEditing",()=>r.getEditingShapeId()===e,[r]),i=G("isEditingAnything",()=>!!r.getEditingShapeId(),[r]);P.useEffect(()=>{function u({shapeId:h}){var p;h===e&&((p=o.current)==null||p.select())}return r.on("select-all-text",u),()=>{r.off("select-all-text",u)}},[r,e,s]),P.useEffect(()=>{var u,h,p,f;s&&(document.activeElement!==o.current&&((u=o.current)==null||u.focus()),r.getInstanceState().isCoarsePointer&&((h=o.current)==null||h.select()),r.environment.isSafari&&((p=o.current)==null||p.blur(),(f=o.current)==null||f.focus()))},[r,s]);const a=P.useCallback(u=>{if(r.getEditingShapeId()===e)switch(u.key){case"Enter":{(u.ctrlKey||u.metaKey)&&r.complete();break}}},[r,e]),l=P.useCallback(u=>{if(r.getEditingShapeId()!==e)return;let h=Sl.normalizeText(u.currentTarget.value);const p=h.replace(/\t/g,Va);if(p!==h){const f=u.currentTarget.selectionStart;u.currentTarget.value=p,u.currentTarget.selectionStart=f+(p.length-h.length),u.currentTarget.selectionEnd=f+(p.length-h.length),h=p}r.updateShape({id:e,type:n,props:{text:h}})},[r,e,n]),c=P.useCallback(u=>{r.dispatch({...On(u),type:"pointer",name:"pointer_down",target:"shape",shape:r.getShape(e)}),Ht(u)},[r,e]);return{rInput:o,handleFocus:xp,handleBlur:xp,handleKeyDown:a,handleChange:l,handleInputPointerDown:c,handleDoubleClick:Ht,isEmpty:t.trim().length===0,isEditing:s,isEditingAnything:i}}const pg=xe.memo(function({id:n,type:t,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:h,padding:p=0,onKeyDown:f,classNamePrefix:S,style:m,textWidth:x,textHeight:y}){const{rInput:v,isEmpty:b,isEditing:E,isEditingAnything:I,...C}=ZY(n,t,r),[k,T]=P.useState(r);P.useEffect(()=>{E||T(r)},[E,r]);const O=Sl.normalizeTextForDom(r),_=O.length>0,A=XY(l);if(!E&&!_)return null;const L=S||"tl-text";return d.jsx("div",{className:`${L}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!b,"data-isediting":E,"data-iseditinganything":I,"data-textwrap":!!u,"data-isselected":h,style:{justifyContent:l==="middle"||A?"center":l,alignItems:c==="middle"?"center":c,padding:p,...m},children:d.jsxs("div",{className:`${L}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:Math.floor(i*a)+"px",minHeight:Math.floor(i*a)+"px",minWidth:Math.ceil(x||0),color:o,width:x?Math.ceil(x):void 0,height:y?Math.ceil(y):void 0},children:[d.jsx("div",{className:`${L} tl-text tl-text-content`,dir:"auto",children:O.split(`
|
|
140
|
-
`).map((j,R)=>d.jsx("div",{dir:"auto",children:j},R))}),(I||h)&&d.jsx(qY,{ref:v,text:r,isEditing:E,...C,handleKeyDown:f??C.handleKeyDown},k)]})})});function oo(e,n,t={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=t;let c=0,u=0,h=1,p=0,f=0;switch(l){case"dashed":{h=1,c=Math.min(n*a,e/4);break}case"dotted":{h=100,c=n/h;break}default:return{strokeDasharray:"none",strokeDashoffset:"none"}}return r||(s==="outset"?(e+=c/2,f+=c/2):s==="skip"&&(e-=c,f-=c),i==="outset"?e+=c/2:i==="skip"&&(e-=c)),u=Math.floor(e/c/(2*h)),u-=u%o,u<3&&l==="dashed"?e/n<4?(c=e,u=1,p=0):(c=e*(1/3),p=e*(1/3)):(c=e/u/(2*h),r?(f=c/2,p=(e-u*c)/u):p=(e-u*c)/Math.max(1,u-1)),{strokeDasharray:[c,p].join(" "),strokeDashoffset:f.toString()}}const eI=new WeakMap;function s0(e,n){const t=eI.get(n);if(t)return t;const r=uo(e,n);let o=0,s=0;const i=r.isStraight?new Bo({start:w.From(r.start.point),end:w.From(r.end.point)}):new Ha({center:w.Cast(r.handleArc.center),start:w.Cast(r.start.point),end:w.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(n.props.text.trim()){const l=i.bounds,c=Iv(n),{w:u,h}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:yo[n.props.font],fontSize:c,maxWidth:null});if(o=u,s=h,l.width>l.height){o=Math.max(Math.min(u,64),Math.min(l.width-64,u));const{w:p,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:yo[n.props.font],fontSize:c,maxWidth:o});o=p,s=f}if(o>16*c){o=16*c;const{w:p,h:f}=e.textMeasure.measureText(n.props.text,{...Wt,fontFamily:yo[n.props.font],fontSize:c,maxWidth:o});o=p,s=f}}const a=new w(o,s).addScalar(WV*2*n.props.scale);return eI.set(n,a),a}function aA(e){const n=jt[e.props.size];return(KV+(n-jt.s)*2+(n===jt.xl?20:0))*e.props.scale}function QY(e,n,t){const r=s0(e,n),o=aA(n),s=w.Nudge(t.start.point,t.end.point,o),i=w.Nudge(t.end.point,t.start.point,o),a=Kw(s,i,Z.FromCenter(t.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;w.Dist2(l,s)>w.Dist2(c,s)&&([c,l]=a);const u=s.add(w.Sub(t.middle,l)),h=i.add(w.Sub(t.middle,c)),p=w.Dist(t.start.point,u)/t.length,f=w.Dist(t.start.point,h)/t.length;return{start:p,end:f}}function JY(e,n,t){const r=s0(e,n),o=aA(n),s=Math.sign(n.props.bend),i=o/t.handleArc.radius*s,a=w.Angle(t.bodyArc.center,t.start.point)-i,l=w.Angle(t.bodyArc.center,t.end.point)+i,c=Bi(t.bodyArc.center,t.bodyArc.radius,a),u=Bi(t.bodyArc.center,t.bodyArc.radius,l),h=[],p=tI(t.bodyArc.center,t.bodyArc.radius,a,l,s,Z.FromCenter(c,r).corners);h.push(new vt({points:Z.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=tI(t.bodyArc.center,t.bodyArc.radius,a,l,s,Z.FromCenter(u,r).corners);h.push(new vt({points:Z.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const k of[...p??[],...f??[],c,u])h.push(new Jw({x:k.x-3,y:k.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const S=(p&&nI(t.start.point,p))??t.middle,m=(f&&nI(t.end.point,f))??t.middle,x=w.Angle(t.bodyArc.center,t.start.point),y=w.Angle(t.bodyArc.center,t.end.point),v=w.Angle(t.bodyArc.center,S),b=w.Angle(t.bodyArc.center,m);if(Cs(x,v,s)>Cs(x,b,s))return{start:.5,end:.5,dbg:h};const E=Cs(x,y,s),I=Cs(x,v,s)/E,C=Cs(x,b,s)/E;return{start:I,end:C,dbg:h}}function Wh(e,n){let t;const r=[],o=uo(e,n),s=!!o.bindings.start,i=!!o.bindings.end,a=o.start.arrowhead!=="none",l=o.end.arrowhead!=="none";if(o.isStraight){const u=QY(e,n,o);let h=_t(n.props.labelPosition,a||s?u.start:0,l||i?u.end:1);h=h>=.48&&h<=.52?.5:h,t=w.Lrp(o.start.point,o.end.point,h)}else{const u=JY(e,n,o);u.dbg&&r.push(...u.dbg);let h=_t(n.props.labelPosition,a||s?u.start:0,l||i?u.end:1);h=h>=.48&&h<=.52?.5:h;const p=eX(w.Angle(o.bodyArc.center,o.start.point),w.Angle(o.bodyArc.center,o.end.point),Math.sign(n.props.bend),h);t=Bi(o.bodyArc.center,o.bodyArc.radius,p)}const c=s0(e,n);return{box:Z.FromCenter(t,c),debugGeom:r}}function tI(e,n,t,r,o,s){const i=yv(e,n,s),a=Cs(t,r,o);return i==null?void 0:i.filter(l=>{const c=Cs(t,w.Angle(e,l),o);return c>=0&&c<=a})}function nI(e,n){let t=null,r=-1/0;for(const o of n){const s=w.Dist2(e,o);s>r&&(t=o,r=s)}return t}function eX(e,n,t,r){const o=Cs(e,n,t);return e+o*r*t*-1}function Iv(e){return HV[e.props.size]*e.props.scale}function tX(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?w.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,t*3),t);let a;if(e.isStraight)a=w.Nudge(r,o,i);else{const l=jW(r,i,e.handleArc.center,e.handleArc.radius);a=n==="end"?e.handleArc.sweepFlag?l[0]:l[1]:e.handleArc.sweepFlag?l[1]:l[0]}return w.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function nX({point:e,int:n}){const t=w.RotWith(n,e,ke/6),r=w.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function rX({point:e,int:n}){const t=w.RotWith(n,e,ke/6),r=w.RotWith(n,e,-ke/6);return`M ${t.x} ${t.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function oX({point:e,int:n}){const t=w.Sub(n,e).div(2),r=w.Add(e,w.Rot(t,Ge)),o=w.Sub(e,w.Rot(t,Ge));return`M ${r.x} ${r.y} L ${n.x} ${n.y} L ${o.x} ${o.y} Z`}function sX({point:e,int:n}){const t=w.Lrp(e,n,.45),r=w.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 iX({point:e,int:n}){const t=w.Lrp(e,n,.75),r=w.RotWith(t,e,ke/4),o=w.RotWith(t,e,-ke/4),s=w.Lrp(r,o,.5);return s.add(w.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function aX({int:e,point:n}){const t=w.Lrp(n,e,.85),r=w.Sub(t,n).div(2),o=w.Add(n,w.Rot(r,Ge)),s=w.Sub(n,w.Rot(r,Ge)),i=w.Add(t,w.Rot(r,Ge)),a=w.Sub(t,w.Rot(r,Ge));return`M ${o.x} ${o.y} L ${i.x} ${i.y} L ${a.x} ${a.y} L ${s.x} ${s.y} Z`}function lX({int:e,point:n}){const t=w.Sub(e,n).div(2),r=w.Add(n,w.Rot(t,Ge)),o=w.Sub(n,w.Rot(t,Ge));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function yf(e,n,t){const r=n==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=tX(e,n,t);if(o){switch(r){case"bar":return lX(o);case"square":return aX(o);case"diamond":return iX(o);case"dot":return sX(o);case"inverted":return oX(o);case"arrow":return nX(o);case"triangle":return rX(o)}return""}}function cX(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 lA(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 cA(e,n){return`M${e.x},${e.y}L${n.x},${n.y}`}function uX(e){return cA(e.start.handle,e.end.handle)}function uA(e){return cA(e.start.point,e.end.point)}let dX=0;class Gh extends Ur{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"canSnap",()=>!1);g(this,"hideResizeHandles",()=>!0);g(this,"hideRotateHandle",()=>!0);g(this,"hideSelectionBoundsBg",()=>!0);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"canBeLaidOut",t=>{const r=An(this.editor,t);return!r.start&&!r.end});g(this,"onHandleDrag",(t,{handle:r,isPrecise:o})=>{const s=r.id,i=An(this.editor,t);if(s==="middle"){const{start:C,end:k}=Ka(this.editor,t,i),T=w.Sub(k,C),O=w.Per(T),_=w.Med(k,C),A=w.Sub(_,O),L=w.Add(_,O),j=w.NearestPointOnLineSegment(A,L,r,!1);let R=w.Dist(j,_);return w.Clockwise(j,k,_)&&(R*=-1),{id:t.id,type:t.type,props:{bend:R}}}const a={id:t.id,type:"arrow",props:{}},l=i[s],u=i[s==="start"?"end":"start"];if(this.editor.inputs.ctrlKey)return Lh(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const h=this.editor.getShapePageTransform(t.id).applyToPoint(r),p=this.editor.getShapeAtPoint(h,{hitInside:!0,hitFrameInside:!0,margin:0,filter:C=>!C.isLocked&&this.editor.canBindShapes({fromShape:t,toShape:C,binding:"arrow"})});if(!p)return Lh(this.editor,t,s),a.props[s]={x:r.x,y:r.y},a;const f=this.editor.getShapeGeometry(p),S=Z.ZeroFix(f.bounds),x=this.editor.getShapePageTransform(a.id).applyToPoint(r),y=this.editor.getPointInShapeSpace(p,x);let v=o;v||(!l||l&&p.id!==l.toId)&&(v=this.editor.inputs.pointerVelocity.len()<.5),o||(f.isClosed||(v=!0),u&&p.id===u.toId&&u.props.isPrecise&&(v=!0));const b={x:(y.x-S.minX)/S.width,y:(y.y-S.minY)/S.height};v&&w.Dist(y,S.center)<Math.max(4,Math.min(Math.min(S.width,S.height)*.15,16))/this.editor.getZoomLevel()&&(b.x=.5,b.y=.5);const E={terminal:s,normalizedAnchor:b,isPrecise:v,isExact:this.editor.inputs.altKey};cc(this.editor,t,p.id,E),this.editor.setHintingShapes([p.id]);const I=An(this.editor,t);return I.start&&I.end&&I.start.toId===I.end.toId&&w.Equals(I.start.props.normalizedAnchor,I.end.props.normalizedAnchor)&&cc(this.editor,t,I.end.toId,{...I.end.props,normalizedAnchor:{x:I.end.props.normalizedAnchor.x+.05,y:I.end.props.normalizedAnchor.y}}),a});g(this,"onTranslateStart",t=>{const r=An(this.editor,t),o=Ka(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)))){oI.set(t,{pagePosition:s.applyToPoint(t),terminalBindings:Mu(o,(a,l)=>{const c=r[a];return c?{binding:c,shapePosition:l,pagePosition:s.applyToPoint(l)}:null})}),r.start&&(ff({editor:this.editor,arrow:t,terminal:"start",useHandle:!0}),t=this.editor.getShape(t.id)),r.end&&ff({editor:this.editor,arrow:t,terminal:"end",useHandle:!0});for(const a of["start","end"]){const l=r[a];l&&this.editor.updateBinding({...l,props:{...l.props,isPrecise:!0}})}}});g(this,"onTranslate",(t,r)=>{const o=oI.get(t);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=w.Sub(s.applyToPoint(r),o.pagePosition);for(const a of Object.values(o.terminalBindings)){if(!a)continue;const l=w.Add(a.pagePosition,w.Mul(i,.5)),c=this.editor.getShapeAtPoint(l,{hitInside:!0,hitFrameInside:!0,margin:0,filter:u=>!u.isLocked&&this.editor.canBindShapes({fromShape:r,toShape:u,binding:"arrow"})});if((c==null?void 0:c.id)===a.binding.toId){const u=Z.ZeroFix(this.editor.getShapeGeometry(c).bounds),h=this.editor.getPointInShapeSpace(c,l),p={x:(h.x-u.minX)/u.width,y:(h.y-u.minY)/u.height};cc(this.editor,r,c.id,{...a.binding.props,normalizedAnchor:p,isPrecise:!0})}else Lh(this.editor,r,a.binding.props.terminal)}});g(this,"_resizeInitialBindings",new Yo);g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=this._resizeInitialBindings.get(t,()=>An(this.editor,t)),a=Ka(this.editor,t,i),{start:l,end:c}=rt(t.props);let{bend:u}=t.props;i.start||(l.x=a.start.x*o,l.y=a.start.y*s),i.end||(c.x=a.end.x*o,c.y=a.end.y*s);const h=Math.abs(o),p=Math.abs(s),f=i!=null&&i.start?w.From(i.start.props.normalizedAnchor):null,S=i!=null&&i.end?w.From(i.end.props.normalizedAnchor):null;return o<0&&s>=0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.x=1-f.x),S&&(S.x=1-S.x)):o>=0&&s<0?(u!==0&&(u*=-1,u*=Math.max(h,p)),f&&(f.y=1-f.y),S&&(S.y=1-S.y)):o>=0&&s>=0?u!==0&&(u*=Math.max(h,p)):o<0&&s<0&&(u!==0&&(u*=Math.max(h,p)),f&&(f.x=1-f.x,f.y=1-f.y),S&&(S.x=1-S.x,S.y=1-S.y)),i.start&&f&&cc(this.editor,t,i.start.toId,{...i.start.props,normalizedAnchor:f.toJson()}),i.end&&S&&cc(this.editor,t,i.end.toId,{...i.end.props,normalizedAnchor:S.toJson()}),{props:{start:l,end:c,bend:u}}});g(this,"onDoubleClickHandle",(t,r)=>{switch(r.id){case"start":return{id:t.id,type:t.type,props:{...t.props,arrowheadStart:t.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:t.id,type:t.type,props:{...t.props,arrowheadEnd:t.props.arrowheadEnd==="none"?"arrow":"none"}}}});g(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}canBind({toShapeType:t}){return t!=="arrow"}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{x:0,y:0},end:{x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw",scale:1}}getGeometry(t){const r=uo(this.editor,t),o=[],s=r.isStraight?new Bo({start:w.From(r.start.point),end:w.From(r.end.point)}):new Ha({center:w.Cast(r.handleArc.center),start:w.Cast(r.start.point),end:w.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(t.props.text.trim()){const a=Wh(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 Hr({children:[...i?[s,i]:[s],...o]})}getHandles(t){const r=uo(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=Tr(),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=uo(this.editor,t);if(!(i!=null&&i.isValid))return null;const a=Wh(this.editor,t),l=t.id===this.editor.getOnlySelectedShapeId(),u=this.editor.getEditingShapeId()===t.id||t.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(Ys,{id:t.id,style:{minWidth:50,minHeight:50},children:d.jsx(rI,{shape:t,shouldDisplayHandles:s&&(o==null?void 0:o.id)===t.id})}),u&&d.jsx(pg,{id:t.id,classNamePrefix:"tl-arrow",type:"arrow",font:t.props.font,fontSize:Iv(t),lineHeight:Wt.lineHeight,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:r[t.props.labelColor].solid,textWidth:a.box.w,isSelected:l,padding:0,style:{transform:`translate(${a.box.center.x}px, ${a.box.center.y}px)`}})]})}indicator(t){const r=cg(t.id),o=uo(this.editor,t);if(!o)return null;const{start:s,end:i}=Ka(this.editor,t,o==null?void 0:o.bindings),a=this.editor.getShapeGeometry(t),l=a.bounds,c=t.props.text.trim()?a.children[1]:null;if(w.Equals(s,i))return null;const u=jt[t.props.size]*t.props.scale,h=o.start.arrowhead&&yf(o,"start",u),p=o.end.arrowhead&&yf(o,"end",u),f=o.isStraight?uA(o):lA(o),S=h&&o.start.arrowhead!=="arrow"||p&&o.end.arrowhead!=="arrow"||!!c,m=(t.id+"_clip").replace(":","_");return r&&c?d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5*t.props.scale,ry:3.5*t.props.scale}):d.jsxs("g",{children:[S&&d.jsx("defs",{children:d.jsxs("mask",{id:m,children:[d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.w+200,height:l.h+200,fill:"white"}),c&&d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,fill:"black",rx:3.5*t.props.scale,ry:3.5*t.props.scale}),h&&d.jsx("path",{d:h,fill:o.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&d.jsx("path",{d:p,fill:o.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{...S?{mask:`url(#${m})`}:void 0,children:[S&&d.jsx("rect",{x:l.minX-100,y:l.minY-100,width:l.width+200,height:l.height+200,opacity:0}),d.jsx("path",{d:f})]}),h&&d.jsx("path",{d:h}),p&&d.jsx("path",{d:p}),c&&d.jsx("rect",{x:N(c.x),y:N(c.y),width:c.w,height:c.h,rx:3.5,ry:3.5})]})}toSvg(t,r){r.addExportDef(r0(t.props.fill)),t.props.text&&r.addExportDef(vl(t.props.font));const o=ss(r),s=1/t.props.scale;return d.jsxs("g",{transform:`scale(${s})`,children:[d.jsx(rI,{shape:t,shouldDisplayHandles:!1}),d.jsx(hg,{fontSize:Iv(t),font:t.props.font,align:"middle",verticalAlign:"middle",text:t.props.text,labelColor:o[t.props.labelColor].solid,bounds:Wh(this.editor,t).box,padding:4*t.props.scale})]})}getCanvasSvgDefs(){return[o0(),{key:"arrow:dot",component:pX},{key:"arrow:cross",component:fX}]}}g(Gh,"type","arrow"),g(Gh,"props",n_),g(Gh,"migrations",r_);function hX(e,n){const t=uo(e,n);return t.isStraight?w.Dist(t.start.handle,t.end.handle):Math.abs(t.handleArc.length)}const rI=ar(function({shape:n,shouldDisplayHandles:t}){const r=B(),o=Tr(),s=uo(r,n),i=Z.ZeroFix(r.getShapeGeometry(n).bounds),a=An(r,n),l=xe.useMemo(()=>r.environment.isSafari?dX+=1:0,[n]);if(!(s!=null&&s.isValid))return null;const c=jt[n.props.size]*n.props.scale,u=s.start.arrowhead&&yf(s,"start",c),h=s.end.arrowhead&&yf(s,"end",c),p=s.isStraight?uA(s):lA(s);let f=null;if(t){const E=2/r.getZoomLevel(),{strokeDasharray:I,strokeDashoffset:C}=oo(hX(r,n),E,{end:"skip",start:"skip",lengthRatio:2.5});f=a.start||a.end?d.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?uX(s):cX(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:m}=oo(s.isStraight?s.length:Math.abs(s.bodyArc.length),c,{style:n.props.dash}),x=Wh(r,n),y=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),v=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),b=(n.id+"_clip_"+l).replace(":","_");return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsxs("mask",{id:b,children:[d.jsx("rect",{x:N(-100+i.minX),y:N(-100+i.minY),width:N(i.width+200),height:N(i.height+200),fill:"white"}),n.props.text.trim()&&d.jsx("rect",{x:x.box.x,y:x.box.y,width:x.box.w,height:x.box.h,fill:"black",rx:4,ry:4}),u&&y&&d.jsx("path",{d:u,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),h&&v&&d.jsx("path",{d:h,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),d.jsxs("g",{fill:"none",stroke:o[n.props.color].solid,strokeWidth:c,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[f,d.jsxs("g",{mask:`url(#${b})`,children:[d.jsx("rect",{x:N(i.minX-100),y:N(i.minY-100),width:N(i.width+200),height:N(i.height+200),opacity:0}),d.jsx("path",{d:p,strokeDasharray:S,strokeDashoffset:m})]}),u&&y&&n.props.fill!=="none"&&d.jsx(en,{theme:o,d:u,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),h&&v&&n.props.fill!=="none"&&d.jsx(en,{theme:o,d:h,color:n.props.color,fill:n.props.fill,scale:n.props.scale}),u&&d.jsx("path",{d:u}),h&&d.jsx("path",{d:h})]})]})}),oI=new WeakMap;function pX(){return d.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:d.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function fX(){return d.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[d.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),d.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const sI="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 xl({url:e,zoomLevel:n}){return d.jsx("a",{className:ce("tl-hyperlink-button",{"tl-hyperlink-button__hidden":n<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:Ht,onPointerUp:Ht,title:e,draggable:!1,children:d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${sI}") center 100% / 100% no-repeat`,WebkitMask:`url("${sI}") center 100% / 100% no-repeat`}})})}const iI="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",gX=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function i0(e){return gX.map(t=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=t,l=new w(r,o),{x:c,y:u}=l.rot(-e);return`${c}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}const mX=300,dA=320,yX=46,SX=101;class Vh extends $l{constructor(){super(...arguments);g(this,"canResize",()=>!1);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"onBeforeCreate",t=>aI(this.editor,t));g(this,"onBeforeUpdate",(t,r)=>{if(t.props.url!==r.props.url)if(or.isValid(r.props.url))xX(this.editor,r);else return{...r,props:{...r.props,url:t.props.url}};if(t.props.assetId!==r.props.assetId)return aI(this.editor,r)})}getDefaultProps(){return{url:"",w:mX,h:dA,assetId:null}}component(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):null,o=this.editor.getShapePageTransform(t).rotation(),s=vX(t);return d.jsx(Vi,{children:d.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:i0(o)},children:[(!r||r.props.image)&&d.jsxs("div",{className:"tl-bookmark__image_container",children:[r?d.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)||""}):d.jsx("div",{className:"tl-bookmark__placeholder"}),(r==null?void 0:r.props.image)&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]}),d.jsxs("div",{className:"tl-bookmark__copy_container",children:[r!=null&&r.props.title?d.jsx("h2",{className:"tl-bookmark__heading",children:r.props.title}):null,r!=null&&r.props.description&&(r!=null&&r.props.image)?d.jsx("p",{className:"tl-bookmark__description",children:r.props.description}):null,d.jsxs("a",{className:"tl-bookmark__link",href:t.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:Ht,onPointerUp:Ht,onClick:Ht,children:[r!=null&&r.props.favicon?d.jsx("img",{className:"tl-bookmark__favicon",src:r==null?void 0:r.props.favicon,referrerPolicy:"strict-origin-when-cross-origin",alt:`favicon of ${s}`}):d.jsx("div",{className:"tl-hyperlink__icon",style:{mask:`url("${iI}") center 100% / 100% no-repeat`,WebkitMask:`url("${iI}") center 100% / 100% no-repeat`}}),d.jsx("span",{children:s})]})]})]})})}indicator(t){return d.jsx("rect",{width:N(t.props.w),height:N(t.props.h),rx:"6",ry:"6"})}}g(Vh,"type","bookmark"),g(Vh,"props",c_),g(Vh,"migrations",u_);function aI(e,n){const t=n.props.assetId?e.getAsset(n.props.assetId):null;let r=dA;return t&&(t.props.image||(t.props.title?r=SX:r=yX)),{...n,props:{...n.props,h:r}}}const vX=e=>{try{return new URL(e.props.url).hostname.replace(/^www\./,"")}catch{return e.props.url}};function xX(e,n){const{url:t}=n.props,r=Ci.createId(uS(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}}]),wX(e,n))}const wX=xk(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 Yi(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${Ie(r)}L${Ie(o)}`;let s="";for(let i=2,a=t-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=Tn(r,o);return n?`M${Tn(e[0].point,e[1].point)}Q${Ie(e[1].point)}${Tn(e[1].point,e[2].point)}T${s}${Tn(e[t-1].point,e[0].point)}${Tn(e[0].point,e[1].point)}Z`:`M${Ie(e[0].point)}Q${Ie(e[1].point)}${Tn(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Ie(e[t-1].point)}`}function bX(e,n={}){const{start:t={},end:r={}}=n,{cap:o=!0}=t,{cap:s=!0}=r;st(!t.taper&&!r.taper,"cap taper not supported here"),st(!t.easing&&!r.easing,"cap easing not supported here"),st(o&&s,"cap must be true");const i=wo(e,n);ug(i,n);const a=PX(i);let l="";for(const c of a)l+=IX(c,n);return l}function PX(e){if(e.length<=2)return[e];const n=[];let t=[e[0]],r=w.Sub(e[1].point,e[0].point).uni(),o,s,i,a,l;for(let c=1,u=e.length;c<u-1;c++){if(i=e[c-1],a=e[c],l=e[c+1],o=w.Sub(l.point,a.point).uni(),s=w.Dpr(r,o),r=o,s<-.8){const h={...a,point:a.input};t.push(h),n.push(cy(t)),t=[h];continue}if(t.push(a),!(s>.7)&&(w.Dist2(i.point,a.point)+w.Dist2(a.point,l.point))/((i.radius+a.radius+l.radius)/3)**2<1.5){t.push(a),n.push(cy(t)),t=[a];continue}}return t.push(e[e.length-1]),n.push(cy(t)),n}function cy(e){const n=e[0];let t;for(;e.length>2&&(t=e[1],w.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],w.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:w.Sub(e[0].point,e[1].point).uni()},e[e.length-1]={...e[e.length-1],vector:w.Sub(e[e.length-2].point,e[e.length-1].point).uni()}),e}function CX(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 IX(e,n={}){if(e.length===0)return"";if(e.length===1)return CX(e[0].point.x,e[0].point.y,e[0].radius);const{left:t,right:r}=H2(e,n);r.reverse();let o=`M${Ie(t[0])}T`;for(let s=1;s<t.length;s++)o+=Tn(t[s-1],t[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),l=w.Add(s.point,w.Mul(a,i)),c=w.Add(s.point,w.Mul(a,-i));o+=`${Ie(l)}A${N(i)},${N(i)} 0 0 1 ${Ie(c)}T`}for(let s=1;s<r.length;s++)o+=Tn(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),l=w.Add(s.point,w.Mul(a,i)),c=w.Add(s.point,w.Mul(a,-i));o+=`${Ie(l)}A${N(i)},${N(i)} 0 0 1 ${Ie(c)}Z`}return o}const EX=e=>e*.65+K6(e*ke/2)*.35,kX=e=>({size:e,thinning:.5,streamline:al(e,[9,16],[.64,.74],!0),smoothing:.62,easing:At.easeOutSine,simulatePressure:!0}),_X=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:EX}),lI=e=>({size:e,thinning:0,streamline:al(e,[9,16],[.68,.74],!0),smoothing:.62,simulatePressure:!1,easing:At.linear}),TX=e=>({size:e,thinning:0,streamline:.62,smoothing:.62,simulatePressure:!1,easing:At.linear});function a0({strokeWidth:e,showAsComplete:n}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:At.easeOutSine,last:n}}function Ev(e,n,t,r){const o=e.isComplete||t;return r?e.isPen?{...TX(n),last:o}:{...lI(n),last:o}:e.dash==="draw"?e.isPen?{..._X(n),last:o}:{...kX(n),last:o}:{...lI(n),last:o}}function wl(e){const n=[];for(const t of e)if(t.type==="free"||t.points.length<2)n.push(...t.points.map(w.Cast));else{const r=Math.max(4,Math.floor(w.Dist(t.points[0],t.points[1])/16));n.push(...w.PointsBetween(t.points[0],t.points[1],r))}return n}function MX(e,n){return{draw:"none",solid:"none",dotted:`0.1 ${n*2}`,dashed:`${n*2} ${n*2}`}[e.props.dash]}class Yh extends Ur{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>uy(t));g(this,"hideRotateHandle",t=>uy(t));g(this,"hideSelectionBoundsFg",t=>uy(t));g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:Fo(o*l),y:Fo(s*c),z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1,scale:1}}getGeometry(t){const r=wl(t.props.segments),o=(jt[t.props.size]+1)*t.props.scale;if(t.props.segments.length===1){const i=Z.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new Jw({x:-o,y:-o,radius:o,isFilled:!0})}const s=wo(r,Ev(t.props,o,t.props.isPen,!0)).map(i=>i.point);return t.props.isClosed?new vt({points:s,isFilled:t.props.fill!=="none"}):new Ll({points:s})}component(t){return d.jsx(Ys,{id:t.id,children:d.jsx(cI,{shape:t,zoomLevel:this.editor.getZoomLevel()})})}indicator(t){var h;const r=wl(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+=Gr(t.id)()*(o/6));const a=t.props.isComplete||((h=Nt(t.props.segments))==null?void 0:h.type)==="straight",l=Ev(t.props,o,a,!0),c=wo(r,l),u=c.length>1?Yi(c,t.props.isClosed):hA(r[0],o);return d.jsx("path",{d:u})}toSvg(t,r){r.addExportDef(r0(t.props.fill));const o=1/t.props.scale;return d.jsx("g",{transform:`scale(${o})`,children:d.jsx(cI,{shape:t,zoomLevel:1})})}getCanvasSvgDefs(){return[o0()]}expandSelectionOutlinePx(t){const r=t.props.dash==="draw"?1.6:1;return jt[t.props.size]*r/2*t.props.scale}}g(Yh,"type","draw"),g(Yh,"props",h_),g(Yh,"migrations",p_);function hA(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 uy(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function cI({shape:e,zoomLevel:n}){var h;const t=Tr(),r=wl(e.props.segments),o=e.props.isComplete||((h=Nt(e.props.segments))==null?void 0:h.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+=Gr(e.id)()*(s/6));const a=Ev(e.props,s,o,i);if(!i&&e.props.dash==="draw")return d.jsxs(d.Fragment,{children:[e.props.isClosed&&e.props.fill&&r.length>1?d.jsx(en,{d:Yi(wo(r,a),e.props.isClosed),theme:t,color:e.props.color,fill:e.props.isClosed?e.props.fill:"none",scale:e.props.scale}):null,d.jsx("path",{d:bX(r,a),strokeLinecap:"round",fill:t[e.props.color].solid})]});const l=wo(r,a),c=l.length<2,u=c?hA(r[0],0):Yi(l,e.props.isClosed);return d.jsxs(d.Fragment,{children:[d.jsx(en,{d:u,theme:t,color:e.props.color,fill:c||e.props.isClosed?e.props.fill:"none",scale:e.props.scale}),d.jsx("path",{d:u,strokeLinecap:"round",fill:c?t[e.props.color].solid:"none",stroke:t[e.props.color].solid,strokeWidth:s,strokeDasharray:c?"none":MX(e,s),strokeDashoffset:"0"})]})}function AX(e,n,t={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=n,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=t;let h=e.props.w*s,p=e.props.h*i;const f=new w(0,0);if(h>0){if(h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=h-a;break}case"top":case"bottom":{f.x=(h-a)/2;break}default:f.x=0}h=a}}else if(f.x=h,h=-h,h<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-h;break}default:f.x=-a}h=a}if(p>0){if(p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=p-c;break}case"right":case"left":{f.y=(p-c)/2;break}default:f.y=0}p=c}}else if(f.y=p,p=-p,p<c){switch(o){case"top_left":case"top":case"top_right":{f.y=-p;break}default:f.y=-c}p=c}const{x:S,y:m}=f.rot(e.rotation).add(r);return{x:S,y:m,props:{w:Math.min(l,h),h:Math.min(u,p)}}}const jX=e=>Object.entries(e).filter(([n,t])=>t).map(([n])=>n).join(" ");class Xh extends $l{constructor(){super(...arguments);g(this,"hideSelectionBoundsFg",t=>!this.canResize(t));g(this,"canEdit",()=>!0);g(this,"canResize",t=>{var r,o;return!!((o=(r=As(t.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});g(this,"canEditInReadOnly",()=>!0);g(this,"isAspectRatioLocked",t=>{const r=As(t.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});g(this,"onResize",(t,r)=>{const o=this.isAspectRatioLocked(t),s=As(t.props.url);let i=(s==null?void 0:s.definition.minWidth)??200,a=(s==null?void 0:s.definition.minHeight)??200;if(o){const l=t.props.w/t.props.h;l>1?i*=l:a/=l}return AX(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=cg(t.id),a=P.useMemo(()=>Y2(s),[s]),l=G("is hovering",()=>{const{editingShapeId:f,hoveredShapeId:S}=this.editor.getCurrentPageState();if(f&&S!==f){const m=this.editor.getShape(f);if(m&&this.editor.isShapeOfType(m,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(t).rotation(),u=i||l;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 f=a.url.split("/").pop();if(!f)throw Error("No gist id!");return d.jsx(Vi,{className:"tl-embed-container",id:t.id,children:d.jsx(OX,{id:f,width:N(r),height:N(o),isInteractive:u,pageRotation:c})})}const p=jX({...T6,...(a==null?void 0:a.definition.overridePermissions)??{}});return d.jsx(Vi,{className:"tl-embed-container",id:t.id,children:a!=null&&a.definition?d.jsx("iframe",{className:"tl-embed",sandbox:p,src:a.embedUrl,width:N(r),height:N(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:i0(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(t){const r=P.useMemo(()=>As(t.props.url),[t.props.url]);return d.jsx("rect",{width:N(t.props.w),height:N(t.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}g(Xh,"type","embed"),g(Xh,"props",f_),g(Xh,"migrations",g_);function OX({id:e,file:n,isInteractive:t,width:r,height:o,style:s,pageRotation:i}){return d.jsx("iframe",{className:"tl-embed",draggable:!1,width:N(r),height:N(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:t?"all":"none",zIndex:t?"":"-1",boxShadow:i0(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 DX=P.forwardRef(({id:e,name:n,isEditing:t},r)=>{const o=B(),s=P.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Ht(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=P.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&o.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,o]),a=P.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&o.updateShapes([{id:e,type:"frame",props:{name:h}}])},[e,o]);return d.jsxs("div",{className:`tl-frame-label ${t?"tl-frame-label__editing":""}`,children:[d.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}),pA(n,"Frame")+""]})}),RX=function({id:n,name:t,width:r,height:o}){const s=B(),i=G("shape rotation",()=>Rs(s.getShapePageTransform(n).rotation()),[s,n]),a=cg(n),l=P.useRef(null),c=P.useCallback(S=>{const m=On(S);s.getEditingShapeId()!==n&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(n),...m}),S.preventDefault())},[s,n]);P.useEffect(()=>{const S=l.current;S&&a&&(S.focus(),S.select())},[l,a]);const h=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(h)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${N(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${N(r)}px, ${N(o)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${N(o)}px) rotate(270deg)`;break}return d.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(p==="top"||p==="bottom"?r:o)}px + var(--space-5))`,bottom:"100%",transform:`${f} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},onPointerDown:c,children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(DX,{ref:l,id:n,name:t,isEditing:a})})})};function pA(e,n){return e.match(/^\s*$/)?n:e}class qh extends $l{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"canReceiveNewChildrenOfType",(t,r)=>!t.isLocked);g(this,"canDropShapes",(t,r)=>!t.isLocked);g(this,"onDragShapesOver",(t,r)=>{r.every(o=>o.parentId===t.id)||this.editor.reparentShapes(r,t.id)});g(this,"onDragShapesOut",(t,r)=>{const o=this.editor.getShape(t.parentId);o&&this.editor.isShapeOfType(o,"group")?this.editor.reparentShapes(r,o.id):this.editor.reparentShapes(r,this.editor.getCurrentPageId())});g(this,"onResize",(t,r)=>z2(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=Tr(),s=G("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 d.jsxs(d.Fragment,{children:[d.jsx(Ys,{children:d.jsx("rect",{className:ce("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:d.jsx(RX,{id:t.id,name:t.props.name,width:r.width,height:r.height})]})}toSvg(t,r){const o=ss({isDarkMode:r.isDarkMode}),a=((Rs(this.editor.getShapePageTransform(t.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4,l=Math.floor(a);let c;switch(l){case 0:c="";break;case 3:c=`translate(${N(t.props.w)}, 0) rotate(90)`;break;case 2:c=`translate(${N(t.props.w)}, ${N(t.props.h)}) rotate(180)`;break;case 1:c=`translate(0, ${N(t.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const u={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:t.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle"},h=this.editor.textMeasure.measureTextSpans(pA(t.props.name,"Frame")+"",u),p=h[0],f=Nt(h),S=f.box.w+f.box.x-p.box.x,m=Cv(this.editor,h,{offsetY:-u.height-2,...u});return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:t.props.w,height:t.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:c,children:[d.jsx("rect",{x:-8,y:-u.height-4,width:S+16,height:u.height,fill:o.background,rx:4,ry:4}),m]})]})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds;return d.jsx("rect",{width:N(r.width),height:N(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}g(qh,"type","frame"),g(qh,"props",m_),g(qh,"migrations",y_);function uI(e,n){return e>n?(ke*(n/2)+(e-n))*2:(ke*(e/2)+(n-e))*2}function fA(e,n){return l0(e,n).map((t,r)=>t.getSvgPathData(r===0)).join(" ")+" Z"}function LX(e,n,t,r){const o=e/4,s=n/4,i=Gr(r),a=t*.75,l=v=>v.addXY(i()*a,i()*a),c=new w(e/2,n),u=new w(0,s*1.2),h=new w(e/2,s*.9),p=new w(e,s*1.2),f=l(new w(e/2,n)),S=l(new w(0,s*1.2)),m=l(new w(e/2,s*.9)),x=l(new w(e,s*1.2));return[new nn({start:c,cp1:new w(o*1.5,s*3),cp2:new w(0,s*2.5),end:u}),new nn({start:u,cp1:new w(0,-s*.32),cp2:new w(o*1.85,-s*.32),end:h}),new nn({start:h,cp1:new w(o*2.15,-s*.32),cp2:new w(e,-s*.32),end:p}),new nn({start:p,cp1:new w(e,s*2.5),cp2:new w(o*2.5,s*3),end:f}),new nn({start:f,cp1:new w(o*1.5,s*3),cp2:new w(0,s*2.5),end:S}),new nn({start:S,cp1:new w(0,-s*.32),cp2:new w(o*1.85,-s*.32),end:m}),new nn({start:m,cp1:new w(o*2.15,-s*.32),cp2:new w(e,-s*.32),end:x}),new nn({start:x,cp1:new w(e,s*2.5),cp2:new w(o*2.5,s*3),end:c})].map((v,b)=>v.getSvgPathData(b===0)).join(" ")+" Z"}function l0(e,n){const t=e/4,r=n/4;return[new nn({start:new w(e/2,n),cp1:new w(t*1.5,r*3),cp2:new w(0,r*2.5),end:new w(0,r*1.2)}),new nn({start:new w(0,r*1.2),cp1:new w(0,-r*.32),cp2:new w(t*1.85,-r*.32),end:new w(e/2,r*.9)}),new nn({start:new w(e/2,r*.9),cp1:new w(t*2.15,-r*.32),cp2:new w(e,-r*.32),end:new w(e,r*1.2)}),new nn({start:new w(e,r*1.2),cp1:new w(e,r*2.5),cp2:new w(t*2.5,r*3),end:new w(e/2,n)})]}function $X(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function FX(e,n,t,r){const o=Gr(e),s=n/2,i=t/2,a=L_(s,i),l=[],c=Re*o(),u=Re+Ge/2+Math.abs(o())*Ge,h=Math.max(16,a/10);for(let p=0;p<h;p++){const f=p/(h-1),S=c+f*u,m=Math.cos(S),x=Math.sin(S);l.push(new w(s*m+n*.5+.05*o(),i*x+t/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?At.easeInOutSine(f):At.easeInExpo(f)))/2)))}return wo(l,$X(r))}function NX(e,n,t,r){return Yi(FX(e,n,t,r))}function kv(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+=`${Ie(r)}L${Ie(o)}Q${Ie(s)}`;return n+=`${Ie(e[0])}`,n}function _v(e,n,t,r,o){const s=[],i=Gr(e);let a=n[0],l;const c=n.length;for(let u=0,h=c*o;u<h;u++){l=w.AddXY(n[(u+1)%c],i()*t,i()*t);const p=w.Sub(l,a),f=w.Len(p),S=w.Div(p,f).mul(Math.min(f/4,r));s.push(w.Add(a,S),w.Add(l,S.neg()),l),a=l}return s}function zX(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 w(r,0),delta:new w(1,0)},{type:"arc",center:new w(e-r,r),startAngle:-ke/2},{type:"straight",start:new w(e-r,n),delta:new w(-1,0)},{type:"arc",center:new w(r,r),startAngle:ke/2}]:[{type:"straight",start:new w(e,r),delta:new w(0,1)},{type:"arc",center:new w(r,n-r),startAngle:0},{type:"straight",start:new w(0,n-r),delta:new w(0,-1)},{type:"arc",center:new w(r,r),startAngle:ke}];let l=0;const c=[];for(let u=0;u<t;u++){const h=a[0];h.type==="straight"?c.push(w.Add(h.start,w.Mul(h.delta,l))):c.push(Bi(h.center,r,h.startAngle+l/r)),l+=i;let p=h.type==="straight"?o:ke*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?o:ke*r}return c}const BX={s:50,m:70,l:100,xl:130},UX=.2;function fg(e,n,t,r){const o=Gr(t),s=uI(e,n),i=Math.max(Math.ceil(s/BX[r]),6,Math.ceil(s/Math.min(e,n))),a=s/i*UX,l=Math.max(e-a*2,1),c=Math.max(n-a*2,1),h=uI(l,c)/i,p=(e-l)/2,f=(n-c)/2,S=zX(l,c,i).map(b=>b.addXY(p,f)),m=e<20?0:a*.3,x=n<20?0:a*.3,y=S.slice(0);for(let b=0;b<Math.floor(i/2);b++)y[b]=w.AddXY(y[b],o()*m,o()*x),y[i-b-1]=w.AddXY(y[i-b-1],o()*m,o()*x);const v=[];for(let b=0;b<y.length;b++){const E=b===y.length-1?0:b+1,I=y[b],C=y[E],k=S[b],T=S[E],O=w.Dist(k,T),_=h-O,L=w.Dist(I,C)/O,j=(Math.max(p,f)+_)*L,R=w.Lrp(k,T,.5).add(w.Sub(T,k).uni().per().mul(j));R.x<0?R.x=0:R.x>e&&(R.x=e),R.y<0?R.y=0:R.y>n&&(R.y=n);const F=Wx(I,C,R),W=w.Dist(F||w.Average([I,C]),I);v.push({leftPoint:I,rightPoint:C,arcPoint:R,center:F,radius:W})}return v}function HX(e,n,t,r){const o=[],s=fg(e,n,t,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of s)o.push(...Y6(l,c,i,a,10));return o}function Tv(e,n,t,r){const o=fg(e,n,t,r);let s=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:i,rightPoint:a,radius:l,center:c}of o){if(c===null){s+=` L${a.toFixed()}`;continue}const u=w.Clockwise(i,a,c)?"0":"1";s+=` A${N(l)},${N(l)} 0 ${u},1 ${a.toFixed()}`}return s+=" Z",s}const KX={s:.5,m:.7,l:.9,xl:1.6};function WX(e,n,t,r){const o=Gr(t),s=KX[r],i=fg(e,n,t,r),c=i.reduce((f,S)=>f+w.Dist2(S.leftPoint,S.rightPoint),0)/i.length>(s*15)**2?f=>f.addXY(o()*s*2,o()*s*2):f=>f;let u=`M${i[0].leftPoint.toFixed()}`,h=c(i[0].leftPoint),p=`M${h.toFixed()}`;for(const{leftPoint:f,center:S,rightPoint:m,radius:x,arcPoint:y}of i){if(S===null){u+=` L${m.toFixed()}`;const k=c(m);p+=` L${k.toFixed()}`,h=k;continue}const v=w.Clockwise(f,m,S)?"0":"1";u+=` A${N(x)},${N(x)} 0 ${v},1 ${m.toFixed()}`;const b=c(m),E=c(y),I=Wx(h,b,E);if(!Number.isFinite(I.x)||!Number.isFinite(I.y)){p+=` L${b.toFixed()}`,h=b;continue}const C=Math.abs(w.Dist(I,h));p+=` A${N(C)},${N(C)} 0 ${v},1 ${b.toFixed()}`,h=b}return u+p+" Z"}function Mv(e,n){switch(e.geo){case"x-box":return GX(e.w,e.h,n,e.dash);case"check-box":return VX(e.w,e.h);default:return}}function GX(e,n,t,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new w(0,0),new w(e/2,n/2)],[new w(e,n),new w(e/2,n/2)],[new w(0,n),new w(e/2,n/2)],[new w(e,0),new w(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 w(s(t*o),i(t*o)),new w(s(e-t*o),i(n-t*o))],[new w(s(t*o),i(n-t*o)),new w(s(e-t*o),i(t*o))]]}function VX(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 w(s(r+t*.25),i(o+t*.52)),new w(s(r+t*.45),i(o+t*.82))],[new w(s(r+t*.45),i(o+t*.82)),new w(s(r+t*.82),i(o+t*.22))]]}function dI({shape:e,shouldScale:n}){const t=n?e.props.scale:1,r=B(),o=Tr(),{id:s,props:i}=e,{w:a,color:l,fill:c,dash:u,growY:h,size:p}=i,f=jt[p]*t,S=i.h+h;switch(i.geo){case"cloud":if(u==="solid"){const m=Tv(a,S,s,p);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("path",{d:m,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else if(u==="draw"){const m=WX(a,S,s,p);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("path",{d:m,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else{const m=Tv(a,S,s,p),x=fg(a,S,s,p);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("g",{strokeWidth:f,stroke:o[l].solid,fill:"none",pointerEvents:"all",children:x.map(({leftPoint:y,rightPoint:v,center:b,radius:E},I)=>{const C=b?E*Rs(Rs(w.Angle(b,v))-Rs(w.Angle(b,y))):w.Dist(y,v),{strokeDasharray:k,strokeDashoffset:T}=oo(C,f,{style:u,start:"outset",end:"outset"});return d.jsx("path",{d:b?`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:k,strokeDashoffset:T},I)})})]})}case"ellipse":{const m=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=m.getSvgPathData(!0);if(u==="dashed"||u==="dotted"){const y=m.length,{strokeDasharray:v,strokeDashoffset:b}=oo(y<64?y*2:y,f,{style:u,snap:4,closed:!0});return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),d.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:v,strokeDashoffset:b})]})}else{const v=(n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),d.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}}case"oval":{const m=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=m.getSvgPathData(!0);if(u==="dashed"||u==="dotted"){const y=m.getLength(),{strokeDasharray:v,strokeDashoffset:b}=oo(y<64?y*2:y,f,{style:u,snap:4,start:"outset",end:"outset",closed:!0});return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),d.jsx("path",{d:x,strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:v,strokeDashoffset:b})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:x,color:l,fill:c,scale:t}),d.jsx("path",{d:x,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}case"heart":if(u==="dashed"||u==="dotted"||u==="solid"){const m=fA(a,S),x=l0(a,S);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),x.map((y,v)=>{const{strokeDasharray:b,strokeDashoffset:E}=oo(y.length,f,{style:u,snap:1,start:"outset",end:"outset",closed:!0});return d.jsx("path",{d:y.getSvgPathData(),strokeWidth:f,fill:"none",stroke:o[l].solid,strokeDasharray:b,strokeDashoffset:E,pointerEvents:"all"},`curve_${v}`)})]})}else{const m=LX(a,S,f,e.id);return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:m,color:l,fill:c,scale:t}),d.jsx("path",{d:m,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}default:{const m=n?r.getShapeGeometry(e):r.getShapeUtil(e).getGeometry(e),x=m instanceof Hr?m.children[0].vertices:m.vertices,y=Mv(e.props,f);if(u==="solid"){let v="M"+x[0]+"L"+x.slice(1)+"Z";if(y)for(const[b,E]of y)v+=`M${b.x},${b.y}L${E.x},${E.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),d.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}else if(u==="dashed"||u==="dotted"){const v="M"+x[0]+"L"+x.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:v,color:l,fill:c,scale:t}),d.jsxs("g",{strokeWidth:f,stroke:o[l].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(x.length)).map((b,E)=>{const I=w.ToFixed(x[E]),C=w.ToFixed(x[(E+1)%x.length]),k=w.Dist(I,C),{strokeDasharray:T,strokeDashoffset:O}=oo(k,f,{style:u,start:"outset",end:"outset"});return d.jsx("line",{x1:I.x,y1:I.y,x2:C.x,y2:C.y,strokeDasharray:T,strokeDashoffset:O},E)}),y&&y.map(([b,E],I)=>{const C=w.Dist(b,E),{strokeDasharray:k,strokeDashoffset:T}=oo(C,f,{style:u,start:"skip",end:"skip",snap:u==="dotted"?4:void 0});return d.jsx("path",{d:`M${b.x},${b.y}L${E.x},${E.y}`,stroke:o[l].solid,strokeWidth:f,fill:"none",strokeDasharray:k,strokeDashoffset:T},`line_fg_${I}`)})]})]})}else if(u==="draw"){let v=kv(_v(s,x,f/3,f*2,2));if(y)for(const[E,I]of y)v+=`M${E.toFixed()}L${I.toFixed()}`;const b=kv(_v(s,x,0,f*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(en,{theme:o,d:b,color:l,fill:c,scale:t}),d.jsx("path",{d:v,stroke:o[l].solid,strokeWidth:f,fill:"none"})]})}}}}const fr=17*3;class Zh extends $l{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});g(this,"onResize",(t,{handle:r,newPoint:o,scaleX:s,scaleY:i,initialShape:a})=>{let l=a.props.w*s,c=(a.props.h+a.props.growY)*i,u=0,h=0;if(t.props.text.trim()){let m=Math.max(Math.abs(l),fr),x=Math.max(Math.abs(c),fr);m<fr&&x===fr&&(m=fr),m===fr&&x<fr&&(x=fr);const y=Yd(this.editor,{...t,props:{...t.props,w:m,h:x}}),v=Math.max(Math.abs(l),y.w)*Math.sign(l),b=Math.max(Math.abs(c),y.h)*Math.sign(c);u=Math.abs(v)-Math.abs(l),h=Math.abs(b)-Math.abs(c),l=v,c=b}const p=new w(0,0);s<0&&(p.x+=l),(r==="left"||r==="top_left"||r==="bottom_left")&&(p.x+=s<0?u:-u),i<0&&(p.y+=c),(r==="top"||r==="top_left"||r==="top_right")&&(p.y+=i<0?h:-h);const{x:f,y:S}=p.rot(t.rotation).add(o);return{x:f,y:S,props:{w:Math.max(Math.abs(l),1),h:Math.max(Math.abs(c),1),growY:0}}});g(this,"onBeforeCreate",t=>{if(!t.props.text)return t.props.growY?{...t,props:{...t.props,growY:0}}:void 0;const r=t.props.h,o=Yd(this.editor,t).h;let s=null;if(o>r?s=o-r:t.props.growY&&(s=0),s!==null)return{...t,props:{...t.props,growY:s}}});g(this,"onBeforeUpdate",(t,r)=>{const o=t.props.text,s=r.props.text;if(o===s&&t.props.font===r.props.font&&t.props.size===r.props.size)return;if(o&&!s)return{...r,props:{...r.props,growY:0}};const i=t.props.w,a=t.props.h,l=Yd(this.editor,r),c=l.w,u=l.h;if(!o&&s&&s.length===1){let p=Math.max(i,c),f=Math.max(a,u);return t.props.w<fr&&t.props.h<fr&&(p=Math.max(p,fr),f=Math.max(f,fr),p=Math.max(p,f),f=Math.max(p,f)),{...r,props:{...r.props,w:p,h:f,growY:0}}}let h=null;if(u>a?h=u-a:t.props.growY&&(h=0),h!==null)return{...r,props:{...r.props,growY:h,w:Math.max(r.props.w,c)}};if(c>t.props.w)return{...r,props:{...r.props,w:c}}});g(this,"onDoubleClick",t=>{if(this.editor.inputs.altKey)switch(t.props.geo){case"rectangle":return{...t,props:{geo:"check-box"}};case"check-box":return{...t,props:{geo:"rectangle"}}}})}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:"",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,l=t.props.fill!=="none";let c;switch(t.props.geo){case"cloud":{c=new vt({points:HX(r,o,t.id,t.props.size),isFilled:l});break}case"triangle":{c=new vt({points:[new w(s,0),new w(r,o),new w(0,o)],isFilled:l});break}case"diamond":{c=new vt({points:[new w(s,0),new w(r,i),new w(s,o),new w(0,i)],isFilled:l});break}case"pentagon":{c=new vt({points:Sm(r,o,5),isFilled:l});break}case"hexagon":{c=new vt({points:Sm(r,o,6),isFilled:l});break}case"octagon":{c=new vt({points:Sm(r,o,8),isFilled:l});break}case"ellipse":{c=new wV({width:r,height:o,isFilled:l});break}case"oval":{c=new bV({width:r,height:o,isFilled:l});break}case"star":{const v=Re/5/2,b=Math.floor(5/4)*2,E=5*2-b,I=0,C=Math.floor(5/2)*2,k=Math.cos(-Ge+b*v)*r/2,T=Math.cos(-Ge+E*v)*r/2,O=Math.sin(-Ge+I*v)*o/2,_=Math.sin(-Ge+C*v)*o/2,A=r-Math.abs(k-T),L=o-Math.abs(_-O),j=r/2+T-(r/2-k),R=o/2+O-(o/2-_),F=1,W=(r-j)/2,K=(o-R)/2,z=(r+A)/2,U=(o+L)/2,X=z*F/2,J=U*F/2;c=new vt({points:Array.from(Array(5*2)).map((le,ye)=>{const Me=-Ge+ye*v;return new w(W+(ye%2?X:z)*Math.cos(Me),K+(ye%2?J:U)*Math.sin(Me))}),isFilled:l});break}case"rhombus":{const y=Math.min(r*.38,o*.38);c=new vt({points:[new w(y,0),new w(r,0),new w(r-y,o),new w(0,o)],isFilled:l});break}case"rhombus-2":{const y=Math.min(r*.38,o*.38);c=new vt({points:[new w(0,0),new w(r-y,0),new w(r,o),new w(y,o)],isFilled:l});break}case"trapezoid":{const y=Math.min(r*.38,o*.38);c=new vt({points:[new w(y,0),new w(r-y,0),new w(r,o),new w(0,o)],isFilled:l});break}case"arrow-right":{const y=Math.min(r,o)*.38,v=o*.16;c=new vt({points:[new w(0,v),new w(r-y,v),new w(r-y,0),new w(r,o/2),new w(r-y,o),new w(r-y,o-v),new w(0,o-v)],isFilled:l});break}case"arrow-left":{const y=Math.min(r,o)*.38,v=o*.16;c=new vt({points:[new w(y,0),new w(y,v),new w(r,v),new w(r,o-v),new w(y,o-v),new w(y,o),new w(0,o/2)],isFilled:l});break}case"arrow-up":{const y=r*.16,v=Math.min(r,o)*.38;c=new vt({points:[new w(r/2,0),new w(r,v),new w(r-y,v),new w(r-y,o),new w(y,o),new w(y,v),new w(0,v)],isFilled:l});break}case"arrow-down":{const y=r*.16,v=Math.min(r,o)*.38;c=new vt({points:[new w(y,0),new w(r-y,0),new w(r-y,o-v),new w(r,o-v),new w(r/2,o),new w(0,o-v),new w(y,o-v)],isFilled:l});break}case"check-box":case"x-box":case"rectangle":{c=new es({width:r,height:o,isFilled:l});break}case"heart":{const v=l0(r,o).reduce((b,E)=>(b.push(...E.vertices),b),[]);c=new vt({points:v,isFilled:l});break}default:an(t.props.geo)}const u=Yd(this.editor,t),h=Math.min(100,r/2),p=Math.min(Go[t.props.size]*t.props.scale*Wt.lineHeight+Rr*2,o/2),f=Math.min(r,Math.max(u.w,Math.min(h,Math.max(1,r-8)))),S=Math.min(o,Math.max(u.h,Math.min(p,Math.max(1,r-8)))),m=Mv(t.props,a),x=m?m.map(y=>new Ll({points:y})):[];return new Hr({children:[c,new es({x:t.props.align==="start"?0:t.props.align==="end"?r-f:(r-f)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?o-S:(o-S)/2,width:f,height:S,isFilled:!0,isLabel:!0}),...x]})}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:an(t.props.geo)}}component(t){const{id:r,type:o,props:s}=t,{fill:i,font:a,align:l,verticalAlign:c,size:u,text:h}=s,p=t.id===this.editor.getOnlySelectedShapeId(),f=Tr(),m=this.editor.getEditingShapeId()!==null||t.props.text;return d.jsxs(d.Fragment,{children:[d.jsx(Ys,{id:r,children:d.jsx(dI,{shape:t,shouldScale:!0})}),m&&d.jsx(Vi,{style:{overflow:"hidden",width:t.props.w,height:t.props.h+s.growY},children:d.jsx(pg,{id:r,type:o,font:a,fontSize:Go[u]*t.props.scale,lineHeight:Wt.lineHeight,padding:16*t.props.scale,fill:i,align:l,verticalAlign:c,text:h,isSelected:p,labelColor:f[s.labelColor].solid,wrap:!0})}),t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{id:r,props:o}=t,{w:s,size:i}=o,a=o.h+o.growY,l=jt[i],c=this.editor.getShapeGeometry(t);switch(o.geo){case"ellipse":return o.dash==="draw"?d.jsx("path",{d:NX(r,s,a,l)}):d.jsx("path",{d:c.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:fA(s,a)});case"oval":return d.jsx("path",{d:c.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:Tv(s,a,r,i)});default:{const u=this.editor.getShapeGeometry(t),h=u instanceof Hr?u.children[0].vertices:u.vertices;let p;if(o.dash==="draw"){const S=_v(r,h,0,l*2*t.props.scale,1);p=kv(S)}else p="M"+h[0]+"L"+h.slice(1)+"Z";const f=Mv(t.props,l);if(f)for(const[S,m]of f)p+=`M${S.x},${S.y}L${m.x},${m.y}`;return d.jsx("path",{d:p})}}}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(r0(s.fill));let i;if(s.text){r.addExportDef(vl(s.font));const a=ss(r),l=new Z(0,0,s.w,s.h+s.growY);i=d.jsx(hg,{fontSize:Go[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:a[s.labelColor].solid,bounds:l,padding:16})}return d.jsxs(d.Fragment,{children:[d.jsx(dI,{shouldScale:!1,shape:o}),i]})}getCanvasSvgDefs(){return[o0()]}}g(Zh,"type","geo"),g(Zh,"props",S_),g(Zh,"migrations",v_);function Yd(e,n){const t=n.props.text;if(!t)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Wt,fontFamily:yo[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,{...Wt,fontFamily:yo[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-Rr*2))});return{w:s.w+Rr*2,h:s.h+Rr*2}}function YX(){const[e,n]=P.useState(!1);return P.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");n(r&&o.matches);const s=()=>n(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),G(xt.forceSrgb)||!e?"srgb":"p3"}const hI=.35,pI=.82;class Qh extends Ur{constructor(){super(...arguments);g(this,"hideResizeHandles",t=>Xd(t));g(this,"hideRotateHandle",t=>Xd(t));g(this,"hideSelectionBoundsFg",t=>Xd(t));g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of t.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:o*l,y:s*c,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(t){const r=Pi(t);if(Xd(t))return new Jw({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=fI(t,r,!0),i=a0({strokeWidth:s,showAsComplete:!0});return ug(o,i),new vt({points:e0(o,i),isFilled:!0})}component(t){const r=dy(this.editor,t),o=Pi(t);return d.jsx(Ys,{id:t.id,children:d.jsx(qd,{shape:t,forceSolid:r,strokeWidth:o,opacity:hI})})}backgroundComponent(t){const r=dy(this.editor,t),o=Pi(t);return d.jsx(Ys,{id:t.id,children:d.jsx(qd,{shape:t,forceSolid:r,strokeWidth:o,opacity:pI})})}indicator(t){const r=dy(this.editor,t),o=Pi(t),{strokePoints:s,sw:i}=fI(t,o,r),a=wl(t.props.segments);let l;return s.length<2?l=qX(a[0],i):l=Yi(s,!1),d.jsx("path",{d:l})}toSvg(t){const r=Pi(t),o=r<1.5,s=1/t.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(qd,{forceSolid:o,strokeWidth:r,shape:t,opacity:hI})})}toBackgroundSvg(t){const r=Pi(t),o=r<1.5,s=1/t.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(qd,{forceSolid:o,strokeWidth:r,shape:t,opacity:pI})})}}g(Qh,"type","highlight"),g(Qh,"props",b_),g(Qh,"migrations",P_);function XX(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 qX(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 fI(e,n,t){var l;const r=wl(e.props.segments),o=e.props.isComplete||((l=Nt(e.props.segments))==null?void 0:l.type)==="straight";let s=n;!t&&!e.props.isPen&&r.length===1&&(s+=Gr(e.id)()*(n/6));const i=a0({strokeWidth:s,showAsComplete:o});return{strokePoints:wo(r,i),sw:s}}function Pi(e){return yl[e.props.size]*1.12*e.props.scale}function Xd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function qd({strokeWidth:e,forceSolid:n,shape:t,opacity:r}){var p;const o=Tr(),s=wl(t.props.segments);let i=e;!n&&!t.props.isPen&&s.length===1&&(i+=Gr(t.id)()*(i/6));const a=a0({strokeWidth:i,showAsComplete:t.props.isComplete||((p=Nt(t.props.segments))==null?void 0:p.type)==="straight"}),l=wo(s,a),c=l.length>1?Yi(l,!1):XX(t.props.segments[0].points[0]),u=YX(),h=o[t.props.color].highlight[u];return d.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function dy(e,n){return G("forceSolid",()=>{const t=Pi(n),r=e.getZoomLevel();return t/r<1.5},[e])}function gA(){return d.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:[d.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),d.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),d.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function mA(e,n,t){const r=B(),[o,s]=P.useState(null),i=n?r.getAsset(n):null,l=r.getCulledShapes().has(e),c=i&&"w"in i.props?t/i.props.w:1,u=G("zoom level",()=>r.getZoomLevel()*c,[r,c]);return P.useEffect(()=>{if(l)return;let h=!1;const p=r.timers.setTimeout(async()=>{const f=await r.resolveAssetUrl(n,{screenScale:u});h||s(f)},500);return()=>{clearTimeout(p),h=!0}},[n,i==null?void 0:i.props.src,l,u,r]),{asset:i,url:o}}function yA(){const[e,n]=P.useState(!1);return P.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 ZX(e){const t=await(await So(e)).blob();return Ai.blobToDataUrl(t)}class Jh extends $l{constructor(){super(...arguments);g(this,"isAspectRatioLocked",()=>!0);g(this,"canCrop",()=>!0);g(this,"onDoubleClick",t=>{const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;!r||!(r.props.src&&this.isAnimated(t))||this.editor.updateShapes([{type:"image",id:t.id,props:{playing:!t.props.playing}}])});g(this,"onDoubleClickEdge",t=>{const r=t.props;if(!r||this.editor.getCroppingShapeId()!==t.id)return;const o=rt(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 w(o.topLeft.x*s,o.topLeft.y*i).rot(t.rotation),l={id:t.id,type:t.type,x:t.x-a.x,y:t.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([l])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}isAnimated(t){const r=t.props.assetId?this.editor.getAsset(t.props.assetId):void 0;return r?"mimeType"in r.props&&lo.isAnimatedImageType(r==null?void 0:r.props.mimeType)||"isAnimated"in r.props&&r.props.isAnimated:!1}component(t){var m;const r=this.editor.getCroppingShapeId()===t.id,o=yA(),[s,i]=P.useState(""),[a,l]=P.useState(""),c=t.id===this.editor.getOnlySelectedShapeId(),{asset:u,url:h}=mA(t.id,t.props.assetId,t.props.w);if(P.useEffect(()=>{if(h){let x=!1;const y=il();return y.onload=()=>{x||l(h)},y.src=h,()=>{x=!0}}},[h,t]),P.useEffect(()=>{if(h&&this.isAnimated(t)){let x=!1;const y=il();return y.onload=()=>{if(x)return;const v=document.createElement("canvas");v.width=y.width,v.height=y.height;const b=v.getContext("2d");b&&(b.drawImage(y,0,0),i(v.toDataURL()),l(h))},y.crossOrigin="anonymous",y.src=h,()=>{x=!0}}},[o,h,t]),(u==null?void 0:u.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const p=c&&r&&this.editor.isIn("select.crop"),f=o&&(((m=u==null?void 0:u.props.mimeType)==null?void 0:m.includes("video"))||this.isAnimated(t)),S=gI(t);return u!=null&&u.props.src?a?d.jsxs(d.Fragment,{children:[p&&d.jsx("div",{style:S,children:d.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(t)?"anonymous":void 0,src:!t.props.playing||f?s:a,referrerPolicy:"strict-origin-when-cross-origin",style:{opacity:.1},draggable:!1})}),d.jsxs(Vi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h},children:[d.jsxs("div",{className:"tl-image-container",style:S,children:[d.jsx("img",{className:"tl-image",crossOrigin:this.isAnimated(t)?"anonymous":void 0,src:!t.props.playing||f?s:a,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1}),this.isAnimated(t)&&!t.props.playing&&d.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):null:d.jsxs(Vi,{id:t.id,style:{overflow:"hidden",width:t.props.w,height:t.props.h,color:"var(--color-text-3)",backgroundColor:u?"transparent":"var(--color-low)",border:u?"none":"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:"tl-image-container",style:S,children:u?null:d.jsx(gA,{})}),"url"in t.props&&t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){return this.editor.getCroppingShapeId()===t.id?null:d.jsx("rect",{width:N(t.props.w),height:N(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 ZX(o)||"");const s=gI(t),i=t.props.crop;if(s.transform&&i){const{transform:a,width:l,height:c}=s,u=(i.bottomRight.x-i.topLeft.x)*l,h=(i.bottomRight.y-i.topLeft.y)*c,p=[new w(0,0),new w(u,0),new w(u,h),new w(0,h)],f=`cropClipPath_${t.id.replace(":","_")}`;return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:f,children:d.jsx("polygon",{points:p.map(S=>`${S.x},${S.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${f})`,children:d.jsx("image",{href:o,width:l,height:c,style:{transform:a}})})]})}else return d.jsx("image",{href:o,width:t.props.w,height:t.props.h})}}g(Jh,"type","image"),g(Jh,"props",C_),g(Jh,"migrations",I_);function gI(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 SA(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function vA(e,n,t){const r=n.vertices,o=SA(t);return wo(r,o)}function QX(e,n,t){const r=SA(t);return e0(ug(vA(e,n,t),r),r)}function JX(e,n,t){const r=QX(e,n,t);return Yx(r)}function eq(e,n,t){if(e.props.dash==="draw"){const r=vA(e,n,t);return Yi(r)}return n.getSvgPathData()}function xA(e,n,t){let r=`M ${Ie(n[0])}L`,o=`M ${Ie(n[0])}L`;const s=t/3,i=t*2,a=Gr(e);let l=n[0],c,u=n[0],h;const p=n.length;for(let f=0,S=p-1;f<S;f++){c=n[f+1],h=w.AddXY(n[f+1],a()*s,a()*s);const m=w.Sub(c,l),x=w.Len(m),y=w.Div(m,x).mul(Math.min(x/4,i)),v=w.Add(l,y),b=w.Add(c,y.neg()),E=w.Sub(h,u),I=w.Len(E),C=w.Div(E,I).mul(Math.min(I/4,i)),k=w.Add(u,C),T=w.Add(h,C.neg());f===S-1?(r+=`${Ie(v)}L ${Ie(c)}`,o+=`${Ie(k)}L ${Ie(h)}`):(r+=`${Ie(v)}L ${Ie(b)}Q ${Ie(c)}`,o+=`${Ie(k)}L ${Ie(T)}Q ${Ie(h)}`,l=c,u=h)}return[r,r+o]}const tq=new Yo;class ep extends Ur{constructor(){super(...arguments);g(this,"hideResizeHandles",()=>!0);g(this,"hideRotateHandle",()=>!0);g(this,"hideSelectionBoundsFg",()=>!0);g(this,"hideSelectionBoundsBg",()=>!0);g(this,"onResize",(t,r)=>{const{scaleX:o,scaleY:s}=r;return{props:{points:Mu(t.props.points,(i,{id:a,index:l,x:c,y:u})=>({id:a,index:l,x:c*o,y:u*s}))}}});g(this,"onHandleDrag",(t,{handle:r})=>{if(r.type==="vertex")return{...t,props:{...t.props,points:{...t.props.points,[r.id]:{id:r.id,index:r.index,x:r.x,y:r.y}}}}})}getDefaultProps(){const[t,r]=Vc(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 Ic(t)}getHandles(t){return tq.get(t.props,()=>{const r=Ic(t),o=Av(t),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=Gc(o[i].index,o[i+1].index),c=r.segments[i].midPoint();s.push({id:a,type:"create",index:a,x:c.x,y:c.y,canSnap:!0})}return s.sort(on)})}component(t){return d.jsx(Ys,{id:t.id,children:d.jsx(mI,{shape:t})})}indicator(t){const r=jt[t.props.size]*t.props.scale,o=Ic(t),{dash:s}=t.props;let i;if(t.props.spline==="line"){const a=o.points;if(s==="solid"||s==="dotted"||s==="dashed")i="M"+a[0]+"L"+a.slice(1);else{const[l]=xA(t.id,a,r);i=l}}else i=eq(t,o,r);return d.jsx("path",{d:i})}toSvg(t){return d.jsx(mI,{shouldScale:!0,shape:t})}getHandleSnapGeometry(t){const r=Av(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(w.From)},getSelfSnapOutline:o=>{const s=this.getHandles(t).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),i=Ic(t).segments.filter((a,l)=>l!==s-1&&l!==s);return i.length?new Hr({children:i}):null}}}}g(ep,"type","line"),g(ep,"props",E_),g(ep,"migrations",k_);function Av(e){return Object.values(e.props.points).sort(on)}function Ic(e){const n=Av(e).map(w.From);switch(e.props.spline){case"cubic":return new xV({points:n});case"line":return new Ll({points:n})}}function mI({shape:e,shouldScale:n=!1}){const t=Tr(),r=Ic(e),{dash:o,color:s,size:i}=e.props,a=1/e.props.scale,l=n?a:1,c=jt[i]*e.props.scale;if(e.props.spline==="line"){if(o==="solid"){const u=r.points,h="M"+u[0]+"L"+u.slice(1);return d.jsx("path",{d:h,stroke:t[s].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:t[s].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((u,h)=>{const{strokeDasharray:p,strokeDashoffset:f}=oo(u.length,c,{style:o,start:h>0?"outset":"none",end:h<r.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:p,strokeDashoffset:f,d:u.getSvgPathData(!0),fill:"none"},h)})});if(o==="draw"){const u=r.points,[h,p]=xA(e.id,u,c);return d.jsx("path",{d:p,stroke:t[s].solid,strokeWidth:c,fill:"none",transform:`scale(${l})`})}}if(e.props.spline==="cubic"){const u=r.getSvgPathData();if(o==="solid")return d.jsx("path",{strokeWidth:c,stroke:t[s].solid,fill:"none",d:u,transform:`scale(${l})`});if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:t[s].solid,strokeWidth:c,transform:`scale(${l})`,children:r.segments.map((h,p)=>{const{strokeDasharray:f,strokeDashoffset:S}=oo(h.length,c,{style:o,start:p>0?"outset":"none",end:p<r.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:f,strokeDashoffset:S,d:h.getSvgPathData(),fill:"none"},p)})});if(o==="draw")return d.jsx("path",{d:JX(e,r,c),strokeWidth:1,stroke:t[s].solid,fill:t[s].solid,transform:`scale(${l})`})}}const wA=P.createContext(null);function nq({assetUrls:e,children:n}){return P.useEffect(()=>{for(const t of Object.values(e.icons)){const r=il();r.src=t,r.decode()}for(const t of Object.values(e.embedIcons)){const r=il();r.src=t,r.decode()}},[e]),d.jsx(wA.Provider,{value:e,children:n})}function c0(){const e=P.useContext(wA);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const jv={"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","theme.dark":"Dark","theme.light":"Light","theme.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.theme":"Theme","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..."},rq=new Set(["ar","fa","he","ur","ku"]),Sa={locale:"en",label:"English",messages:jv,dir:"ltr"};async function oq(e,n){if(!(await So(n.translations.en)).ok)return console.warn("No main translations found."),Sa;if(e==="en")return Sa;const r=Xc.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),Sa;const s=await(await So(n.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),Sa;const i=[];for(const a in Sa.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:rq.has(r.locale)?"rtl":"ltr",messages:{...Sa.messages,...s}}}const bA=P.createContext(null);function PA(){const e=P.useContext(bA);if(!e)throw new Error("useCurrentTranslation must be used inside of <TldrawUiContextProvider />");return e}const sq=ar(function({overrides:n,children:t}){const o=B().user.getLocale(),s=c0(),[i,a]=P.useState(()=>n&&n.en?{locale:"en",label:"English",dir:"ltr",messages:{...jv,...n.en}}:{locale:"en",label:"English",dir:"ltr",messages:jv});return P.useEffect(()=>{let l=!1;async function c(){const u=await oq(o,s);u&&!l&&(n&&n[o]?a({...u,messages:{...u.messages,...n[o]}}):a(u))}return c(),()=>{l=!0}},[s,o,n]),d.jsx(bA.Provider,{value:i,children:t})});function Te(){const e=PA();return P.useCallback(function(t){return e.messages[t]??t},[e])}class tp extends Ur{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"hideResizeHandles",()=>!0);g(this,"hideSelectionBoundsFg",()=>!1);g(this,"onBeforeCreate",t=>yI(this.editor,t));g(this,"onBeforeUpdate",(t,r)=>{if(!(t.props.text===r.props.text&&t.props.font===r.props.font&&t.props.size===r.props.size))return yI(this.editor,r)});g(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t;s.trimEnd()!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(t){const{labelHeight:r,labelWidth:o}=CA(this.editor,t),{scale:s}=t.props,i=r*s,a=o*s,l=Be*s,c=Zd(t);return new Hr({children:[new es({width:l,height:c,isFilled:!0}),new es({x:t.props.align==="start"?0:t.props.align==="end"?l-a:(l-a)/2,y:t.props.verticalAlign==="start"?0:t.props.verticalAlign==="end"?c-i:(c-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=Zd(t),a=Be*r,l=jY/s*r;return s*r<.5?[{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l}]:[{id:"top",index:"a1",type:"clone",x:a/2,y:-l},{id:"right",index:"a2",type:"clone",x:a+l,y:i/2},{id:"bottom",index:"a3",type:"clone",x:a/2,y:i+l},{id:"left",index:"a4",type:"clone",x:-l,y:i/2}]}component(t){const{id:r,type:o,props:{scale:s,color:i,font:a,size:l,align:c,text:u,verticalAlign:h,fontSizeAdjustment:p}}=t,f=lq(r),S=Tr(),m=Be*s,x=Zd(t),y=G("shape rotation",()=>{var E;return((E=this.editor.getShapePageTransform(r))==null?void 0:E.rotation())??0},[this.editor]),v=G("zoom",()=>this.editor.getZoomLevel()<.35/s,[s,this.editor]),b=t.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:r,className:"tl-note__container",style:{width:m,height:x,backgroundColor:S[i].note.fill,borderBottom:v?`${3*s}px solid rgb(15, 23, 31, .2)`:"none",boxShadow:v?"none":cq(t.id,y,s)},children:d.jsx(pg,{id:r,type:o,font:a,fontSize:(p||Go[l])*s,lineHeight:Wt.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:b,labelColor:S[i].note.text,wrap:!0,padding:16*s,onKeyDown:f})}),"url"in t.props&&t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(t){const{scale:r}=t.props;return d.jsx("rect",{rx:r,width:N(Be*r),height:N(Zd(t))})}toSvg(t,r){r.addExportDef(vl(t.props.font)),t.props.text&&r.addExportDef(vl(t.props.font));const o=ss({isDarkMode:r.isDarkMode}),s=uq(t);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:Be-10,height:s.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:Be,height:s.h,fill:o[t.props.color].note.fill}),d.jsx(hg,{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})]})}}g(tp,"type","note"),g(tp,"props",__),g(tp,"migrations",T_);function yI(e,n){const{labelHeight:t,fontSizeAdjustment:r}=CA(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 iq(e,n){const{text:t}=n.props;if(!t)return{labelHeight:Go[n.props.size]*Wt.lineHeight+Rr*2,labelWidth:100,fontSizeAdjustment:0};const r=Go[n.props.size];let o=0,s=0,i=Be,a=Be;const l=1;do{o=Math.min(r,r-s);const c=e.textMeasure.measureText(t,{...Wt,fontFamily:yo[n.props.font],fontSize:o,maxWidth:Be-Rr*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Rr*2,a=c.w+Rr*2,o<=14){const u=e.textMeasure.measureText(t,{...Wt,fontFamily:yo[n.props.font],fontSize:o,maxWidth:Be-Rr*2-l});i=u.h+Rr*2,a=u.w+Rr*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const aq=new Yo;function CA(e,n){return aq.get(n,()=>iq(e,n))}function lq(e){const n=B(),t=PA();return P.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),l=a.rotation(),c=!!(t.dir==="rtl"||X2(o.props.text)),u=(Be+n.options.adjacentShapeMargin+(i&&!r.shiftKey?o.props.growY:0))*o.props.scale,h=new w(s?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(dg.clone().mul(o.props.scale)).rot(l).add(a.point()),p=rA(n,o,h,l);p&&(n.mark("editing adjacent shape"),gf(n,p,!0))}},[e,n,t.dir])}function Zd(e){return(Be+e.props.growY)*e.props.scale}function cq(e,n,t){const r=Gr(e),o=Math.abs(r())+.5,s=Math.cos(n),i=5*t,a=4*t,l=6*t,c=7*t;return`0px ${i-o}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
157
|
-
0px ${(a+o*c)*Math.max(0,s)}px ${l+o*c}px -${a+o*l}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 uq(e){return new Z(0,0,Be,Be+e.props.growY)}function dq(e,{initialBounds:n,scaleX:t,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(t),Math.abs(r))),i=new w(0,0);t<0&&(i.x=-(n.width*s)),r<0&&(i.y=-(n.height*s));const{x:a,y:l}=w.Add(o,i.rot(e.rotation));return{x:a,y:l,props:{scale:s*e.props.scale}}}const hq=new Yo;class np extends Ur{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"isAspectRatioLocked",()=>!0);g(this,"onResize",(t,r)=>{const{newPoint:o,initialBounds:s,initialShape:i,scaleX:a,handle:l}=r;if(r.mode==="scale_shape"||l!=="right"&&l!=="left")return{id:t.id,type:t.type,...dq(t,r)};{const c=Math.max(1,Math.abs(s.width*a)),{x:u,y:h}=a<0?w.Sub(o,w.FromAngle(t.rotation).mul(c)):o;return{id:t.id,type:t.type,x:u,y:h,props:{w:c/i.props.scale,autoSize:!1}}}});g(this,"onEditEnd",t=>{const{id:r,type:o,props:{text:s}}=t,i=t.props.text.trimEnd();i.length===0?this.editor.deleteShapes([t.id]):i!==t.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});g(this,"onBeforeUpdate",(t,r)=>{if(!r.props.autoSize)return;const o=t.props.size!==r.props.size||t.props.textAlign!==r.props.textAlign||t.props.font!==r.props.font||t.props.scale!==1&&r.props.scale===1,s=t.props.text!==r.props.text;if(!o&&!s)return;const i=this.getMinDimensions(t),a=SI(this.editor,r.props),l=i.width*t.props.scale,c=i.height*t.props.scale,u=a.width*r.props.scale,h=a.height*r.props.scale;let p;switch(r.props.textAlign){case"middle":{p=new w((u-l)/2,s?0:(h-c)/2);break}case"end":{p=new w(u-l,s?0:(h-c)/2);break}default:{if(s)break;p=new w(0,(h-c)/2);break}}if(p){p.rot(r.rotation);const{x:f,y:S}=r;return{...r,x:f-p.x,y:S-p.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(t){return hq.get(t.props,r=>SI(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:l,textAlign:c}}=t,{width:u,height:h}=this.getMinDimensions(t),p=t.id===this.editor.getOnlySelectedShapeId(),f=Tr(),S=pq(r);return d.jsx(pg,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:yl[s],lineHeight:Wt.lineHeight,align:c,verticalAlign:"middle",text:i,labelColor:f[a].solid,isSelected:p,textWidth:u,textHeight:h,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0,onKeyDown:S})}indicator(t){const r=this.editor.getShapeGeometry(t).bounds,o=B();return t.props.autoSize&&o.getEditingShapeId()===t.id?null:d.jsx("rect",{width:N(r.width),height:N(r.height)})}toSvg(t,r){r.addExportDef(vl(t.props.font)),t.props.text&&r.addExportDef(vl(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 d.jsx(hg,{fontSize:yl[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 Z(0,0,s,i),padding:0})}}g(np,"type","text"),g(np,"props",M_),g(np,"migrations",A_);function SI(e,n){const{font:t,text:r,autoSize:o,size:s,w:i}=n,a=o?16:Math.max(16,i),l=yl[s],c=o?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...Wt,fontFamily:yo[t],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function pq(e){const n=B();return P.useCallback(t=>{if(n.getEditingShapeId()===e)switch(t.key){case"Enter":{(t.ctrlKey||t.metaKey)&&n.complete();break}case"Tab":{Ee(t),t.shiftKey?Sl.unindent(t.currentTarget):Sl.indent(t.currentTarget);break}}},[n,e])}class rp extends $l{constructor(){super(...arguments);g(this,"canEdit",()=>!0);g(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(t){const{editor:r}=this,o=r.getShapeGeometry(t).bounds.w*r.getZoomLevel()>=110,{asset:s,url:i}=mA(t.id,t.props.assetId,t.props.w),{time:a,playing:l}=t.props,c=cg(t.id),u=yA(),h=P.useRef(null),p=P.useCallback(v=>{const b=v.currentTarget;b&&r.updateShapes([{type:"video",id:t.id,props:{playing:!0,time:b.currentTime}}])},[t.id,r]),f=P.useCallback(v=>{const b=v.currentTarget;b&&r.updateShapes([{type:"video",id:t.id,props:{playing:!1,time:b.currentTime}}])},[t.id,r]),S=P.useCallback(v=>{const b=v.currentTarget;b&&c&&r.updateShapes([{type:"video",id:t.id,props:{time:b.currentTime}}])},[c,t.id,r]),[m,x]=P.useState(!1),y=P.useCallback(v=>{const b=v.currentTarget;b&&(a!==b.currentTime&&(b.currentTime=a),l||b.pause(),x(!0))},[l,a]);return P.useEffect(()=>{const v=h.current;v&&(m&&!c&&a!==v.currentTime&&(v.currentTime=a),c&&document.activeElement!==v&&v.focus())},[c,m,a]),P.useEffect(()=>{if(u){const v=h.current;if(!v)return;v.pause(),v.currentTime=0}},[h,u]),d.jsxs(d.Fragment,{children:[d.jsx(Vi,{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:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?i?d.jsx("video",{ref:h,style:c?{pointerEvents:"all"}:void 0,className:`tl-video tl-video-shape-${t.id.split(":")[1]}`,width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:c&&o,onPlay:p,onPause:f,onTimeUpdate:S,onLoadedData:y,hidden:!m,children:d.jsx("source",{src:i})}):null:d.jsx(gA,{})})})}),"url"in t.props&&t.props.url&&d.jsx(xl,{url:t.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(t){return d.jsx("rect",{width:N(t.props.w),height:N(t.props.h)})}toSvg(t){return d.jsx("image",{href:fq(t.id),width:t.props.w,height:t.props.h})}}g(rp,"type","video"),g(rp,"props",j_),g(rp,"migrations",O_);function fq(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 IA=[np,Vh,Yh,Zh,tp,ep,qh,Gh,Qh,Xh,Jh,rp];function gq(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 EA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"scribbleId","id");g(this,"markId","");g(this,"excludedShapeIds",new Set);g(this,"onEnter",t=>{this.markId="erase scribble begin",this.editor.mark(this.markId),this.info=t;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>{if(this.editor.isShapeOrAncestorLocked(s))return!0;if(this.editor.isShapeOfType(s,"group")||this.editor.isShapeOfType(s,"frame")){const i=this.editor.getPointInShapeSpace(s,r);return this.editor.getShapeGeometry(s).bounds.containsPoint(i)}return!1}).map(s=>s.id));const o=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=o.id,this.update()});g(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()})}update(){const{editor:t,excludedShapeIds:r}=this,o=t.getErasingShapeIds(),s=t.getZoomLevel(),i=t.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=t;this.pushPointToScribble();const c=new Set(o),u=this.editor.options.hitTestMargin/s;for(const h of i){if(t.isShapeOfType(h,"group"))continue;const p=t.getShapeMask(h.id);if(p&&!tr(a,p))continue;const f=t.getShapeGeometry(h),S=t.getShapePageTransform(h);if(!f||!S)continue;const m=S.clone().invert(),x=m.applyToPoint(l),y=m.applyToPoint(a),{bounds:v}=f;v.minX-u>Math.max(x.x,y.x)||v.minY-u>Math.max(x.y,y.y)||v.maxX+u<Math.min(x.x,y.x)||v.maxY+u<Math.min(x.y,y.y)||f.hitTestLineSegment(x,y,u)&&c.add(t.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:t}=this;t.deleteShapes(t.getCurrentPageState().erasingShapeIds),t.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:t}=this;t.setErasingShapes([]),t.bailToMark(this.markId),this.parent.transition("idle",this.info)}}g(EA,"id","erasing");var Hy;let mq=(Hy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Hy,"id","idle"),Hy);var Ky;let yq=(Ky=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{const t=this.editor.getZoomLevel(),r=this.editor.getCurrentPageShapesSorted(),{inputs:{currentPagePoint:o}}=this.editor,s=new Set,i=s.size;for(let a=r.length,l=a-1;l>=0;l--){const c=r[l];if(!(this.editor.isShapeOrAncestorLocked(c)||this.editor.isShapeOfType(c,"group"))&&this.editor.isPointInShape(c,o,{hitInside:!1,margin:this.editor.options.hitTestMargin/t})){const u=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(u,"frame")&&s.size>i)break;s.add(u.id)}}this.editor.setErasingShapes([...s])});g(this,"onLongPress",t=>{this.startErasing(t)});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startErasing(t)});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.cancel()})}startErasing(t){this.parent.transition("erasing",t)}complete(){const t=this.editor.getErasingShapeIds();t.length&&(this.editor.mark("erase end"),this.editor.deleteShapes(t)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},g(Ky,"id","pointing"),Ky);class op extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(op,"id","eraser"),g(op,"initial","idle"),g(op,"children",()=>[mq,yq,EA]);class kA extends se{constructor(){super(...arguments);g(this,"initialCamera",new w);g(this,"onEnter",()=>{this.initialCamera=w.From(this.editor.getCamera()),this.update()});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.parent.transition("idle")});g(this,"onComplete",()=>{this.complete()})}update(){const{initialCamera:t,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=w.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")}}g(kA,"id","dragging");var Wy;let Sq=(Wy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});g(this,"onPointerDown",t=>{this.parent.transition("pointing",t)});g(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},g(Wy,"id","idle"),Wy);var Gy;let vq=(Gy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})});g(this,"onLongPress",()=>{this.startDragging()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startDragging()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.complete()})}startDragging(){this.parent.transition("dragging")}complete(){this.parent.transition("idle")}},g(Gy,"id","pointing"),Gy);class sp extends se{constructor(){super(...arguments);g(this,"onDoubleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{animation:{duration:220,easing:At.easeOutQuint}})}});g(this,"onTripleClick",t=>{if(t.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{animation:{duration:320,easing:At.easeOutQuint}})}});g(this,"onQuadrupleClick",t=>{if(t.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:o}}=this.editor;r===1?this.editor.zoomToFit({animation:{duration:400,easing:At.easeOutQuint}}):this.editor.resetZoom(o,{animation:{duration:320,easing:At.easeOutQuint}})}})}}g(sp,"id","hand"),g(sp,"initial","idle"),g(sp,"children",()=>[Sq,vq,kA]);var Vy;let xq=(Vy=class extends se{constructor(){super(...arguments);g(this,"onPointerDown",t=>{this.parent.transition("lasering",t)})}},g(Vy,"id","idle"),Vy);class _A extends se{constructor(){super(...arguments);g(this,"scribbleId","id");g(this,"onEnter",()=>{const t=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:1200,shrink:.05,taper:!0});this.scribbleId=t.id,this.pushPointToScribble()});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.pushPointToScribble()});g(this,"onPointerUp",()=>{this.complete()});g(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}g(_A,"id","lasering");class ip extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}g(ip,"id","laser"),g(ip,"initial","idle"),g(ip,"children",()=>[xq,_A]);class TA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"initialSelectedShapeIds",[]);g(this,"excludedShapeIds",new Set);g(this,"isWrapMode",!1);g(this,"initialStartShape",null);g(this,"onEnter",t=>{const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",t);return}this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>this.editor.isShapeOfType(s,"group")||this.editor.isShapeOrAncestorLocked(s)).map(s=>s.id)),this.info=t,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.hitTestShapes()});g(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});g(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});g(this,"onPointerMove",()=>{this.hitTestShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",t=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",t)});g(this,"onKeyDown",t=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",t):this.hitTestShapes()});g(this,"onKeyUp",()=>{this.hitTestShapes()});g(this,"onInterrupt",()=>{this.editor.updateInstanceState({brush:null})})}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:t,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=t,c=new Set(a?this.initialSelectedShapeIds:[]),u=o?!l:l,h=Z.FromPoints([s,i]),{corners:p}=h;let f,S,m,x,y,v;const b=t.getCurrentPageShapes(),E=t.getCurrentPageId();e:for(let k=0,T=b.length;k<T;k++){if(m=b[k],r.has(m.id)||c.has(m.id)||(x=t.getShapePageBounds(m),!x))continue e;if(h.contains(x)){this.handleHit(m,i,E,c,p);continue e}if(u||t.isShapeOfType(m,"frame"))continue e;if(h.collides(x)){if(y=t.getShapePageTransform(m),!y)continue e;v=y.clone().invert().applyToPoints(p);const O=t.getShapeGeometry(m);t:for(let _=0;_<4;_++)if(f=v[_],S=v[(_+1)%4],O.hitTestLineSegment(f,S,0)){this.handleHit(m,i,E,c,p);break t}}}t.getInstanceState().isCoarsePointer;const I=t.getInstanceState().brush;(!I||!h.equals(I))&&t.updateInstanceState({brush:{...h.toJson()}});const C=t.getSelectedShapeIds();(C.length!==c.size||C.some(k=>!c.has(k)))&&t.setSelectedShapes(Array.from(c))}handleHit(t,r,o,s,i){if(t.parentId===o){s.add(t.id);return}const a=this.editor.getOutermostSelectableShape(t),l=this.editor.getShapeMask(a.id);l&&!P2(l,i)&&!tr(r,l)||s.add(a.id)}}g(TA,"id","brushing");const bl={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 MA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t,this.updateCursor()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startResizing()});g(this,"onLongPress",()=>{this.startResizing()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const t=this.editor.getSelectedShapes(),r=bl[this.info.handle];this.editor.setCursor({type:r,rotation:t.length===1?this.editor.getSelectionRotation():0})}startResizing(){this.editor.getInstanceState().isReadonly||this.parent.transition("resizing",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}g(MA,"id","pointing_resize_handle");const gr=8;class u0 extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","");g(this,"snapshot",{});g(this,"onEnter",t=>{this.info=t,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=bl[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),l=i.clone().sub(a).rot(-t.rotation),c=s.crop??this.getDefaultCrop(),u=rt(c),h=new w(t.x,t.y),p=new w(0,0),f=1/(c.bottomRight.x-c.topLeft.x)*s.w,S=1/(c.bottomRight.y-c.topLeft.y)*s.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(S<gr)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/S,S*(u.bottomRight.y-u.topLeft.y)<gr?(u.topLeft.y=u.bottomRight.y-gr/S,p.y=(u.topLeft.y-c.topLeft.y)*S):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-c.topLeft.y)*S):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(S<gr)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/S),S*(u.bottomRight.y-u.topLeft.y)<gr&&(u.bottomRight.y=u.topLeft.y+gr/S);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<gr)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<gr?(u.topLeft.x=u.bottomRight.x-gr/f,p.x=(u.topLeft.x-c.topLeft.x)*f):u.topLeft.x<=0?(u.topLeft.x=0,p.x=(u.topLeft.x-c.topLeft.x)*f):p.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(f<gr)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<gr&&(u.bottomRight.x=u.topLeft.x+gr/f);break}}if(!m)return;h.add(p.rot(t.rotation));const x={id:t.id,type:t.type,x:h.x,y:h.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*f,h:(u.bottomRight.y-u.topLeft.y)*S}};this.editor.updateShapes([x]),this.updateCursor()}complete(){this.updateShapes(),Ke(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=w.RotWith(s.getHandlePoint(this.info.handle),s.point,t),a=w.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}g(u0,"id","cropping");function d0(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 AA(e,n,t){if(!n)throw Error("Needs to translate a cropped shape!");const{crop:r}=n.props;if(!r)return;const o=e.inputs.shiftKey?Math.abs(t.x)<Math.abs(t.y)?"x":"y":null;o==="x"?t.x=0:o==="y"&&(t.y=0),t.rot(-n.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*n.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*n.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=rt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-t.x/s)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-t.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:n.id,type:n.type,props:{crop:c}}}var Yy;let wq=(Yy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.editor.setCursor({type:"default",rotation:0});const t=this.editor.getOnlySelectedShape();t&&this.editor.setCroppingShape(t.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});g(this,"onPointerDown",t=>{var r;if(!this.editor.getIsMenuOpen()){if(t.ctrlKey){this.cancel(),this.editor.root.handleEvent(t);return}switch(t.target){case"canvas":{const o=d0(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...t,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(t);break}case"shape":{if(t.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",t);return}else(r=this.editor.getShapeUtil(t.shape))!=null&&r.canCrop(t.shape)?(this.editor.setCroppingShape(t.shape.id),this.editor.setSelectedShapes([t.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",t)):(this.cancel(),this.editor.root.handleEvent(t));break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...t,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...t,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}});g(this,"onDoubleClick",t=>{var i;if(this.editor.inputs.shiftKey||t.phase!=="up")return;const r=this.editor.getCroppingShapeId();if(!r)return;const o=this.editor.getShape(r);if(!o)return;const s=this.editor.getShapeUtil(o);if(s){if(t.target==="selection"){(i=s.onDoubleClickEdge)==null||i.call(s,o);return}this.cancel(),this.editor.root.handleEvent(t)}});g(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});g(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});g(this,"onKeyUp",t=>{switch(t.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}})}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 w(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 w(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=AA(this.editor,i,s);a&&(t||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},g(Yy,"id","idle"),Yy);class jA extends se{constructor(){super(...arguments);g(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",t)});g(this,"onPointerUp",t=>{this.editor.setCurrentTool("select.crop.idle",t)})}}g(jA,"id","pointing_crop");class h0 extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=bl[this.info.handle];this.editor.setCursor({type:o,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});g(this,"onLongPress",()=>{this.startCropping()});g(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}g(h0,"id","pointing_crop_handle");class OA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","translating crop");g(this,"snapshot",{});g(this,"onEnter",t=>{this.info=t,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onKeyDown",t=>{switch(t.key){case"Alt":case"Shift":{this.updateShapes();return}}});g(this,"onKeyUp",t=>{switch(t.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}})}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){const t=this.snapshot.shape;if(!t)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=AA(this.editor,t,s);i&&this.editor.updateShapes([i])}}g(OA,"id","translating_crop");class ap extends se{constructor(){super(...arguments);g(this,"markId","");g(this,"onEnter",()=>{this.didCancel=!1,this.markId=this.editor.history.mark()});g(this,"didCancel",!1);g(this,"onExit",()=>{this.didCancel?this.editor.bailToMark(this.markId):this.editor.history.squashToMark(this.markId)});g(this,"onCancel",()=>{this.didCancel=!0})}}g(ap,"id","crop"),g(ap,"initial","idle"),g(ap,"children",()=>[wq,OA,jA,h0,u0]);class DA extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"initialHandle",{});g(this,"initialAdjacentHandle",null);g(this,"initialPagePoint",{});g(this,"markId","");g(this,"initialPageTransform");g(this,"initialPageRotation");g(this,"info",{});g(this,"isPrecise",!1);g(this,"isPreciseId",null);g(this,"pointingId",null);g(this,"onEnter",t=>{const{shape:r,isCreating:o,handle:s}=t;if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.shapeId=r.id,this.markId=o?`creating:${r.id}`:"dragging handle",o||this.editor.mark(this.markId),this.initialHandle=rt(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 c=this.editor.getShapeHandles(r).find(u=>u.index===s.index);this.initialHandle=rt(c)}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(on),a=i.findIndex(l=>l.id===t.handle.id);this.initialAdjacentHandle=null;for(let l=a+1;l<i.length;l++){const c=i[l];if(c.type==="vertex"&&c.id!=="middle"&&c.id!==t.handle.id){this.initialAdjacentHandle=c;break}}if(!this.initialAdjacentHandle)for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="vertex"&&c.id!=="middle"&&c.id!==t.handle.id){this.initialAdjacentHandle=c;break}}if(this.editor.isShapeOfType(r,"arrow")){const l=An(this.editor,r)[t.handle.id];this.isPrecise=!1,l?(this.editor.setHintingShapes([l.toId]),this.isPrecise=l.props.isPrecise,this.isPrecise?this.isPreciseId=l.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)});g(this,"exactTimeout",-1);g(this,"onPointerMove",()=>{this.update()});g(this,"onKeyDown",()=>{this.update()});g(this,"onKeyUp",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.update(),this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),Ke(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 k;const{editor:t,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:p,ctrlKey:f,altKey:S,pointerVelocity:m}}=t,x=this.info.shape,y=t.getShape(r);if(!y)return;const v=t.getShapeUtil(y);let b=h.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const T=w.Angle(a,b),_=$p(T,24)-T;b=w.RotWith(b,a,_)}t.snaps.clearIndicators();let E={...s,x:b.x,y:b.y};if(s.canSnap&&(c?!f:f)){if(!t.getShapePageTransform(y.id))throw Error("Expected a page transform");const O=u.handles.snapHandle({currentShapeId:r,handle:E});O&&(O.nudge.rot(-t.getShapeParentTransform(y).rotation()),b.add(O.nudge),E={...s,x:b.x,y:b.y})}const I=(k=v.onHandleDrag)==null?void 0:k.call(v,y,{handle:E,isPrecise:this.isPrecise||S,initial:x}),C={id:y.id,type:y.type,...I};if(s.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const T=An(t,y)[s.id];T?l[0]!==T.toId&&(t.setHintingShapes([T.toId]),this.pointingId=T.toId,this.isPrecise=m.len()<.5||S,this.isPreciseId=this.isPrecise?T.toId:null,this.resetExactTimeout()):l.length>0&&(t.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}I&&t.updateShapes([C])}}g(DA,"id","dragging_handle");function RA(e){return e.isLabel?[e]:e instanceof Hr?e.children.filter(n=>n.isLabel):[]}class LA extends se{constructor(){super(...arguments);g(this,"hitShapeForPointerUp",null);g(this,"onEnter",()=>{const t=this.editor.getEditingShape();if(!t)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Uo(this.editor),this.editor.select(t)});g(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)});g(this,"onPointerMove",t=>{if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly||this.hitShapeForPointerUp.isLocked)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}}});g(this,"onPointerDown",t=>{switch(this.hitShapeForPointerUp=null,t.target){case"canvas":{const r=d0(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=RA(s),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(o,"text")&&o.props.text.trim()==="";if(a&&!l){const c=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint);if(a.bounds.containsPoint(c,0)&&a.hitTestPoint(c)){if(r.id===o.id)return;this.hitShapeForPointerUp=r,this.editor.mark("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===o.id)this.editor.isShapeOfType(r,"frame")&&this.editor.setEditingShape(null);else{this.parent.transition("pointing_shape",t);return}return}break}}this.parent.transition("idle",t),this.editor.root.handleEvent(t)});g(this,"onPointerUp",t=>{const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const o=this.editor.getShapeUtil(r);if(!r.isLocked){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)}});g(this,"onComplete",t=>{this.parent.transition("idle",t)});g(this,"onCancel",t=>{this.parent.transition("idle",t)})}}g(LA,"id","editing_shape");function vI(e){const n=e.getOnlySelectedShape();return!!(n&&!e.isShapeOrAncestorLocked(n)&&e.getShapeUtil(n).canCrop(n))}function Sf(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(_n(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const bq=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Xy;let Pq=(Xy=class extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Uo(this.editor),this.editor.setCursor({type:"default",rotation:0})});g(this,"onExit",()=>{Uo.cancel()});g(this,"onPointerMove",()=>{Uo(this.editor)});g(this,"onPointerDown",t=>{if(this.editor.getIsMenuOpen())return;const r=t.ctrlKey&&vI(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=d0(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))&&xI(this.editor,a)){this.onPointerDown({...t,target:"selection"});return}this.parent.transition("pointing_canvas",t);break}case"shape":{const{shape:o}=t;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",t);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",t);break}this.parent.transition("pointing_shape",t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",t):this.parent.transition("pointing_handle",t);break}case"selection":{switch(t.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.parent.transition("pointing_rotate_handle",t);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("crop.pointing_crop_handle",t):this.parent.transition("pointing_resize_handle",t);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...t,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",t)}}break}}});g(this,"onDoubleClick",t=>{var r,o,s,i;if(!(this.editor.inputs.shiftKey||t.phase!=="up"))switch(t.target){case"canvas":{const a=this.editor.getHoveredShape(),l=a&&!this.editor.isShapeOfType(a,"group")?a:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),c=this.editor.getFocusedGroupId();if(l){if(this.editor.isShapeOfType(l,"group")){Sf(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){Sf(this.editor);return}}this.onDoubleClick({...t,shape:l,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(t);break}case"selection":{if(this.editor.getInstanceState().isReadonly)break;const a=this.editor.getOnlySelectedShape();if(a){const l=this.editor.getShapeUtil(a);if(!this.canInteractWithShapeInReadOnly(a))return;if(t.handle==="right"||t.handle==="left"||t.handle==="top"||t.handle==="bottom"){const c=(r=l.onDoubleClickEdge)==null?void 0:r.call(l,a);if(c){this.editor.mark("double click edge"),this.editor.updateShapes([c]),Ke(this.editor,[a.id]);return}}if(l.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,l=this.editor.getShapeUtil(a);if(a.type!=="video"&&a.type!=="embed"&&this.editor.getInstanceState().isReadonly)break;if(l.onDoubleClick){const c=(o=l.onDoubleClick)==null?void 0:o.call(l,a);if(c){this.editor.updateShapes([c]);return}else if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.editor.mark("select and crop"),this.editor.select((s=t.shape)==null?void 0:s.id),this.parent.transition("crop",t);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,t,!0):this.handleDoubleClickOnCanvas(t);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:l}=t,c=this.editor.getShapeUtil(a),u=(i=c.onDoubleClickHandle)==null?void 0:i.call(c,a,l);u?this.editor.updateShapes([u]):this.shouldStartEditingShape(a)&&this.startEditingShape(a,t,!0)}}});g(this,"onRightClick",t=>{switch(t.target){case"canvas":{const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...t,shape:o,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),i=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:a}}=this.editor;if((s.length>1||i&&!this.editor.getShapeUtil(i).hideSelectionBoundsBg(i))&&xI(this.editor,a)){this.onRightClick({...t,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=t,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));r.includes(s.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});g(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});g(this,"onKeyDown",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(xt.editOnType.get()&&!bq.includes(t.key)&&!t.altKey&&!t.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...t,target:"shape",shape:r},!0);return}}});g(this,"onKeyRepeat",t=>{switch(t.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});g(this,"onKeyUp",t=>{switch(t.code){case"Enter":{const r=this.editor.getSelectedShapes();if(r.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(r.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const o=this.editor.getOnlySelectedShape();if(o&&this.shouldStartEditingShape(o)){this.startEditingShape(o,{...t,target:"shape",shape:o},!0);return}vI(this.editor)&&this.parent.transition("crop",t);break}}});g(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}shouldStartEditingShape(t=this.editor.getOnlySelectedShape()){return!t||this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||!this.canInteractWithShapeInReadOnly(t)?!1:this.editor.getShapeUtil(t).canEdit(t)}startEditingShape(t,r,o){this.editor.isShapeOrAncestorLocked(t)&&t.type!=="embed"||(this.editor.mark("editing shape"),gf(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&&tr(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(t){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=$e(),{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 w(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 w(0,0)))return;t||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*Eq:i:o?Cq:Iq,l=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(l,s.mul(a)),Ke(this.editor,l)}canInteractWithShapeInReadOnly(t){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(t).canEditInReadOnly(t))}},g(Xy,"id","idle"),Xy);const Cq=10,Iq=1,Eq=5;function xI(e,n){const t=e.getSelectionRotatedPageBounds();if(!t)return!1;const r=e.getSelectionRotation();return r?tr(n,t.corners.map(o=>w.RotWith(o,t.point,r))):t.containsPoint(n)}class $A extends se{constructor(){super(...arguments);g(this,"shapeId","");g(this,"markId","");g(this,"wasAlreadySelected",!1);g(this,"didDrag",!1);g(this,"info",{});g(this,"onEnter",t=>{const{shape:r}=t;this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.shapeId=r.id,this.didDrag=!1,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const s=this.editor.getShapeGeometry(r).children[1];if(!s)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=w.Sub(s.center,a),this.markId="label-drag start",this.editor.mark(this.markId),this.editor.setSelectedShapes([this.shapeId])});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});g(this,"_labelDragOffset",new w(0,0));g(this,"onPointerMove",()=>{const{isDragging:t}=this.editor.inputs;if(!t)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=uo(this.editor,r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(w.Add(a,this._labelDragOffset));let c;if(o.isStraight){const u=w.Dist(o.start.point,o.end.point);c=1-w.Dist(o.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:p,angleStart:f}=s.children[0];c=wS(h,f,p,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})});g(this,"onPointerUp",()=>{const t=this.editor.getShape(this.shapeId);t&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(t.id),this.editor.setCurrentTool("select.editing_shape")))});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}g($A,"id","pointing_arrow_label");class FA extends se{constructor(){super(...arguments);g(this,"onEnter",()=>{const{inputs:t}=this.editor;t.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",t)});g(this,"onPointerUp",()=>{Sf(this.editor),this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}g(FA,"id","pointing_canvas");class NA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t;const{shape:r}=t;if(this.editor.isShapeOfType(r,"arrow")){const o=An(this.editor,r)[t.handle.id];o&&this.editor.setHintingShapes([o.toId])}this.editor.setCursor({type:"grabbing",rotation:0})});g(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerUp",()=>{const{shape:t,handle:r}=this.info;if(this.editor.isShapeOfType(t,"note")){const{editor:o}=this,s=wI(o,t,r,!1);if(s){gf(o,s,!0);return}}this.parent.transition("idle",this.info)});g(this,"onPointerMove",()=>{const{editor:t}=this;t.inputs.isDragging&&this.startDraggingHandle()});g(this,"onLongPress",()=>{this.startDraggingHandle()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startDraggingHandle(){const{editor:t}=this;if(t.getInstanceState().isReadonly)return;const{shape:r,handle:o}=this.info;if(t.isShapeOfType(r,"note")){const s=wI(t,r,o,!0);if(s){const i=t.getPointInParentSpace(s,t.inputs.originPagePoint).sub(w.Rot(dg.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:()=>{gf(t,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}g(NA,"id","pointing_handle");function wI(e,n,t,r){const o=e.getShapePageTransform(n.id),s=o.point(),i=o.rotation(),l=tA(s,i,n.props.growY,0,n.props.scale)[t.index];if(l)return rA(e,n,l,i,r)}class zA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.info=t,this.updateCursor()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startRotating()});g(this,"onLongPress",()=>{this.startRotating()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:bl[this.info.handle],rotation:this.editor.getSelectionRotation()})}startRotating(){this.editor.getInstanceState().isReadonly||this.parent.transition("rotating",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}g(zA,"id","pointing_rotate_handle");class BA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerUp",t=>{Sf(this.editor),this.parent.transition("idle",t)});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});g(this,"onLongPress",t=>{this.startTranslating(t)});g(this,"onDoubleClick",t=>{var s,i;const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(o){this.parent.transition("idle"),(i=(s=this.parent).onDoubleClick)==null||i.call(s,{...t,target:"shape",shape:this.editor.getShape(o)});return}});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",t)}cancel(){this.parent.transition("idle")}}g(BA,"id","pointing_selection");class UA extends se{constructor(){super(...arguments);g(this,"hitShape",{});g(this,"hitShapeForPointerUp",{});g(this,"isDoubleClick",!1);g(this,"didSelectOnEnter",!1);g(this,"onEnter",t=>{const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:l}}=this.editor;this.hitShape=t.shape,this.isDoubleClick=!1;const c=this.editor.getOutermostSelectableShape(t.shape),u=this.editor.findShapeAncestor(c,h=>r.includes(h.id));if(this.editor.getShapeUtil(t.shape).onClick||c.id===s||r.includes(c.id)||u||r.length>1&&(o!=null&&o.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=c;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(c.id)||(this.editor.mark("shift selecting shape"),this.editor.setSelectedShapes([...r,c.id]))):(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([c.id]))});g(this,"onPointerUp",t=>{var u;const r=this.editor.getSelectedShapeIds(),o=this.editor.getFocusedGroupId(),s=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i,shiftKey:a}}=this.editor,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/s,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const p=(u=h.onClick)==null?void 0:u.call(h,c);if(p){this.editor.mark("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",t);return}}if(c.id===o){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",t);return}}if(!this.didSelectOnEnter){const h=this.editor.getOutermostSelectableShape(l,p=>!r.includes(p.id));if(r.includes(h.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),f=RA(p),S=f.length===1?f[0]:void 0;if(S){const m=this.editor.getPointInShapeSpace(c,i);if(S.bounds.containsPoint(m,0)&&S.hitTestPoint(m)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(c.id);const x=this.editor.getShapeUtil(c);this.editor.getInstanceState().isReadonly&&!x.canEditInReadOnly(c)||(this.editor.setEditingShape(c.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick&&this.editor.emit("select-all-text",{shapeId:c.id}))});return}}}this.editor.mark("selecting on pointer up"),this.editor.select(c.id)}else this.editor.mark("selecting on pointer up"),this.editor.select(c);else if(a){const p=this.editor.getShapeAncestors(h);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(f=>!p.find(S=>S.id===f)),h.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",t)});g(this,"onDoubleClick",()=>{this.isDoubleClick=!0});g(this,"onPointerMove",t=>{this.editor.inputs.isDragging&&this.startTranslating(t)});g(this,"onLongPress",t=>{this.startTranslating(t)});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.cancel()});g(this,"onInterrupt",()=>{this.cancel()})}startTranslating(t){this.editor.getInstanceState().isReadonly||(this.editor.focus(),this.parent.transition("translating",t))}cancel(){this.parent.transition("idle")}}g(UA,"id","pointing_shape");class HA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"markId","");g(this,"didHoldCommand",!1);g(this,"creationCursorOffset",{x:0,y:0});g(this,"snapshot",{});g(this,"onEnter",t=>{const{isCreating:r=!1,creationCursorOffset:o={x:0,y:0}}=t;this.info=t,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),r?(this.markId=`creating:${this.editor.getOnlySelectedShape().id}`,this.editor.setCursor({type:"cross",rotation:0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});g(this,"onTick",({elapsed:t})=>{const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(t)});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onKeyDown",()=>{this.updateShapes()});g(this,"onKeyUp",()=>{this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()});g(this,"_createSnapshot",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=w.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=w.Sub(o,i),l=new Map,c=[];t.forEach(h=>{const p=this.editor.getShape(h);if(p){if(p.type==="frame"&&c.push({id:h,children:me(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&t.length===1)return;this.editor.visitDescendants(p.id,f=>{const S=this.editor.getShape(f);if(S&&(l.set(S.id,this._createShapeSnapshot(S)),this.editor.isShapeOfType(S,"frame")))return!1})}});const u=![...l.values()].some(h=>!F_(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:t,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});g(this,"_createShapeSnapshot",t=>{const r=this.editor.getShapePageTransform(t),o=this.editor.getShapeUtil(t);return{shape:t,bounds:this.editor.getShapeGeometry(t).bounds,pageTransform:r,pageRotation:oe.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(t)}})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var t,r;if(Ke(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 l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onResizeEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:t,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(s.size===1){const T=[...s.values()][0];this.editor.isShapeOfType(T.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),S=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:T}=this.editor.getDocumentSettings();f.snapToGrid(T)}const m=this.info.handle,x=bI(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ge===0){const{nudge:T}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:w.Sub(f,S),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:bI(m,c),isAspectRatioLocked:h,isResizingFromCenter:t});f.add(T)}const v=w.RotWith(t?i.center:i.getHandlePoint(x),i.point,c),b=w.Sub(f,v).rot(-c),E=w.Sub(S,v).rot(-c),I=w.DivV(b,E);Number.isFinite(I.x)||(I.x=1),Number.isFinite(I.y)||(I.y=1);const C=m==="top"||m==="bottom",k=m==="left"||m==="right";h?k?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),k&&(I.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:I.x<0,isFlippedY:I.y<0,rotation:c});for(const T of s.keys()){const O=s.get(T);this.editor.resizeShape(T,I,{initialShape:O.shape,initialBounds:O.bounds,initialPageTransform:O.pageTransform,dragHandle:m,mode:l.length===1&&T===l[0]?"resize_bounds":"scale_shape",scaleOrigin:v,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:T,children:O}of o){if(!O.length)continue;const _=s.get(T).shape,A=this.editor.getShape(T);if(!(_&&A))continue;const L=A.x-_.x,j=A.y-_.y,R=new w(L,j).rot(-_.rotation);if(R.x!==0||R.y!==0)for(const F of O)this.editor.updateShape({id:F.id,type:F.type,x:F.x-R.x,y:F.y-R.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:T}of o)if(T.length)for(const O of T)this.editor.updateShape({id:O.id,type:O.type,x:O.x,y:O.y})}}updateCursor({dragHandle:t,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(t){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}}g(HA,"id","resizing");const hy=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function bI(e,n){n=n%Re;const t=Math.round(n/(ke/4)),r=hy.indexOf(e);return hy[(r+t)%hy.length]}const PI=Math.PI/180;class KA extends se{constructor(){super(...arguments);g(this,"snapshot",{});g(this,"info",{});g(this,"markId","");g(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=E2({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});jh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:bl[this.info.handle],rotation:o+this.snapshot.initialSelectionRotation})});g(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});g(this,"onPointerMove",()=>{this.update()});g(this,"onKeyDown",()=>{this.update()});g(this,"onKeyUp",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"update",()=>{const t=this._getRotationFromPointerPosition({snapToNearestDegree:!1});jh({editor:this.editor,delta:t,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:bl[this.info.handle],rotation:t+this.snapshot.initialSelectionRotation})});g(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});g(this,"complete",()=>{jh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ke(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:l}=this.snapshot;if(!o)return l;const u=o.center.clone().rotWith(o.point,r).angle(i)-a;let h=l+u;if(s)h=$p(h,24);else if(t&&(h=Math.round(h/PI)*PI,this.editor.getInstanceState().isCoarsePointer)){const p=$p(h,4),f=vh(h,p);Math.abs(f)<W6(5)&&(h=p)}return h-l}}g(KA,"id","rotating");class WA extends se{constructor(){super(...arguments);g(this,"hits",new Set);g(this,"size",0);g(this,"scribbleId","id");g(this,"initialSelectedShapeIds",new Set);g(this,"newlySelectedShapeIds",new Set);g(this,"onEnter",()=>{this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const t=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=t.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})});g(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});g(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});g(this,"onPointerUp",()=>{this.complete()});g(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});g(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});g(this,"onCancel",()=>{this.cancel()});g(this,"onComplete",()=>{this.complete()});g(this,"pushPointToScribble",()=>{const{x:t,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,t,r)})}updateScribbleSelection(t){const{editor:r}=this,o=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;t&&this.pushPointToScribble();const h=o;let p,f,S,m;const x=0;for(let b=0,E=h.length;b<E;b++){if(p=h[b],r.isShapeOfType(p,"group")||c.has(p.id)||r.isShapeOrAncestorLocked(p)||(f=r.getShapeGeometry(p),r.isShapeOfType(p,"frame")&&f.bounds.containsPoint(r.getPointInShapeSpace(p,i))))continue;const I=r.getShapePageTransform(p);if(!f||!I)continue;const C=I.clone().invert();S=C.applyToPoint(a),m=C.applyToPoint(l);const{bounds:k}=f;if(!(k.minX-x>Math.max(S.x,m.x)||k.minY-x>Math.max(S.y,m.y)||k.maxX+x<Math.min(S.x,m.x)||k.maxY+x<Math.min(S.y,m.y))&&f.hitTestLineSegment(S,m,x)){const T=this.editor.getOutermostSelectableShape(p),O=this.editor.getShapeMask(T.id);if(O&&Kw(a,l,O)!==null&&!tr(l,O))continue;c.add(T.id)}}const y=r.getSelectedShapeIds(),v=new Set(s?[...c,...u]:[...c]);(y.length!==v.size||y.some(b=>!v.has(b)))&&this.editor.setSelectedShapes(Array.from(v))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}g(WA,"id","scribble_brushing");const kq=20,_q=100;class Tq{constructor(n){g(this,"prevDroppingShapeId",null);g(this,"droppingNodeTimer",null);g(this,"first",!0);g(this,"dispose",()=>{this.clear()});this.editor=n,n.disposables.add(this.dispose)}updateDroppingNode(n,t){var r;this.first&&(this.editor.setHintingShapes(n.map(o=>this.editor.findShapeAncestor(o,s=>s.type!=="group")).filter(o=>o)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,n))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(n,kq,t):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(n,_q,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 l,c,u,h,p;t=me(t.map(f=>this.editor.getShape(f.id)));const o=((l=this.editor.getDroppingOverShape(n,t))==null?void 0:l.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(t);return}const{prevDroppingShapeId:s}=this,i=s&&this.editor.getShape(s),a=o&&this.editor.getShape(o);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,t)),a&&((p=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(h,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&&Q2(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 GA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"selectionSnapshot",{});g(this,"snapshot",{});g(this,"markId","");g(this,"isCloning",!1);g(this,"isCreating",!1);g(this,"onCreate",()=>{});g(this,"dragAndDropManager",new Tq(this.editor));g(this,"onEnter",t=>{var s;const{isCreating:r=!1,onCreate:o=()=>{}}=t;if(!((s=this.editor.getSelectedShapeIds())!=null&&s.length)){this.parent.transition("idle");return}if(this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.isCreating=r,this.onCreate=o,r?this.markId=`creating:${this.editor.getOnlySelectedShape().id}`:(this.markId="translating",this.editor.mark(this.markId)),this.isCloning=!1,this.info=t,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=CI(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()});g(this,"onTick",({elapsed:t})=>{const{editor:r}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),r.edgeScrollManager.updateEdgeScrolling(t)});g(this,"onPointerMove",()=>{this.updateShapes()});g(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});g(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onComplete",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()});g(this,"updateParentTransforms",()=>{const{editor:t,snapshot:{shapeSnapshots:r}}=this;r.forEach(o=>{const s=t.getShape(o.shape.id);if(!s)return null;const i=En(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=CI(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),Ke(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=w.Average(t.map(i=>this.editor.getShapePageTransform(i.id).point())),s=w.Sub(o,this.selectionSnapshot.averagePagePoint);w.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 l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslateEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:t}=this;this.dragAndDropManager.updateDroppingNode(t.movingShapes,this.updateParentTransforms),Mq({editor:this.editor,snapshot:t});const{movingShapes:r}=t,o=[];r.forEach(s=>{var c;const i=this.editor.getShape(s.id),a=this.editor.getShapeUtil(s),l=(c=a.onTranslate)==null?void 0:c.call(a,s,i);l&&o.push(l)}),o.length>0&&this.editor.updateShapes(o)}}g(GA,"id","translating");function CI(e){var h;const n=[],t=[],r=e.getSelectedShapeIds(),o=me(r.map(p=>{const f=e.getShape(p);if(!f)return null;n.push(f);const S=e.getShapePageTransform(p),m=S.point(),x=S.rotation();t.push(m);const y=Xo.isId(f.parentId)?null:oe.Inverse(e.getShapePageTransform(f.parentId));return{shape:f,pagePoint:m,pageRotation:x,parentTransform:y}})),s=e.getOnlySelectedShape();let i=[];if(s)i=e.snaps.shapeBounds.getSnapPoints(s.id);else{const p=e.getSelectionPageBounds();p&&(i=p.cornersAndCenter.map((f,S)=>({id:"selection:"+S,x:f.x,y:f.y})))}let a,l;const{originPagePoint:c}=e.inputs,u=o.filter(p=>e.isShapeOfType(p.shape,"note")&&e.isPointInShape(p.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const p=e.getCurrentPageShapesSorted();l=(h=u.map(f=>({snapshot:f,index:p.findIndex(S=>S.id===f.shape.id)})).sort((f,S)=>S.index-f.index)[0])==null?void 0:h.snapshot}return l&&(a=nA(e,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:w.Average(t),movingShapes:n,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function Mq({editor:e,snapshot:n}){const{inputs:t}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=n,c=e.getInstanceState().isGridMode,u=e.getDocumentSettings().gridSize,h=w.Sub(t.currentPagePoint,t.originPagePoint),p=e.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;if(p==="x"?h.x=0:p==="y"&&(h.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!t.ctrlKey:t.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:x}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});h.add(x)}else if(r&&o){const{scale:x}=r.shape.props,y=r.pagePoint.clone().add(h).add(dg.clone().mul(x).rot(r.pageRotation));let v=eA/e.getZoomLevel(),b=new w(0,0);for(const E of o){const I=w.Sub(y,E),C=I.len();C<v&&(v=C,b=I)}h.sub(b)}const S=w.Add(l,h);c&&!t.ctrlKey&&S.snapToGrid(u);const m=w.Sub(S,l);e.updateShapes(me(a.map(({shape:x,pagePoint:y,parentTransform:v})=>{const b=w.Add(y,m),E=v?oe.applyToPoint(v,b):b;return{id:x.id,type:x.type,x:E.x,y:E.y}})))}class lp extends se{constructor(){super(...arguments);g(this,"reactor");g(this,"cleanUpDuplicateProps",()=>{const t=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);t.length===o.size&&t.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})});g(this,"onEnter",()=>{this.reactor=oa("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(t){typeof process<"u",console.error(t)}})});g(this,"onExit",()=>{var t;(t=this.reactor)==null||t.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}g(lp,"id","select"),g(lp,"initial","idle"),g(lp,"children",()=>[ap,u0,Pq,FA,UA,GA,TA,WA,h0,BA,MA,LA,HA,KA,zA,$A,NA,DA]);class VA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}g(VA,"id","idle");class YA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t});g(this,"onPointerUp",()=>{this.complete()});g(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});g(this,"onCancel",()=>{this.cancel()})}complete(){const{currentScreenPoint:t}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(t,{animation:{duration:220}}):this.editor.zoomIn(t,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}g(YA,"id","pointing");class XA extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"zoomBrush",new Z);g(this,"onEnter",t=>{this.info=t,this.update()});g(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});g(this,"onPointerMove",()=>{this.update()});g(this,"onPointerUp",()=>{this.complete()});g(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:t,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.FromPoints([t,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:t}=this,r=8/this.editor.getZoomLevel();if(t.width<r&&t.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{animation:{duration:220}}):this.editor.zoomIn(o,{animation:{duration:220}})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(t,{targetZoom:o,animation:{duration:220}})}this.parent.transition("idle",this.info)}}g(XA,"id","zoom_brushing");class cp extends se{constructor(){super(...arguments);g(this,"info",{});g(this,"onEnter",t=>{this.info=t,this.parent.setCurrentToolIdMask(t.onInteractionEnd),this.updateCursor()});g(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)});g(this,"onKeyDown",()=>{this.updateCursor()});g(this,"onKeyUp",t=>{this.updateCursor(),t.code==="KeyZ"&&this.complete()});g(this,"onInterrupt",()=>{this.complete()})}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}g(cp,"id","zoom"),g(cp,"initial","idle"),g(cp,"children",()=>[VA,XA,YA]);const Aq=[op,sp,ip,cp,lp];function re(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 jq(e,n){typeof e=="function"?e(n):e!=null&&(e.current=n)}function gg(...e){return n=>e.forEach(t=>jq(t,n))}function Ye(...e){return P.useCallback(gg(...e),e)}function Oq(e,n){const t=P.createContext(n);function r(s){const{children:i,...a}=s,l=P.useMemo(()=>a,Object.values(a));return d.jsx(t.Provider,{value:l,children:i})}function o(s){const i=P.useContext(t);if(i)return i;if(n!==void 0)return n;throw new Error(`\`${s}\` must be used within \`${e}\``)}return r.displayName=e+"Provider",[r,o]}function ko(e,n=[]){let t=[];function r(s,i){const a=P.createContext(i),l=t.length;t=[...t,i];function c(h){const{scope:p,children:f,...S}=h,m=(p==null?void 0:p[e][l])||a,x=P.useMemo(()=>S,Object.values(S));return d.jsx(m.Provider,{value:x,children:f})}function u(h,p){const f=(p==null?void 0:p[e][l])||a,S=P.useContext(f);if(S)return S;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,u]}const o=()=>{const s=t.map(i=>P.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return P.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,Dq(o,...n)]}function Dq(...e){const n=e[0];if(e.length===1)return n;const t=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(s)[`__scope${c}`];return{...a,...h}},{});return P.useMemo(()=>({[`__scope${n.scopeName}`]:i}),[i])}};return t.scopeName=n.scopeName,t}var Xs=globalThis!=null&&globalThis.document?P.useLayoutEffect:()=>{},Rq=h$.useId||(()=>{}),Lq=0;function Vo(e){const[n,t]=P.useState(Rq());return Xs(()=>{e||t(r=>r??String(Lq++))},[e]),e||(n?`radix-${n}`:"")}function Vt(e){const n=P.useRef(e);return P.useEffect(()=>{n.current=e}),P.useMemo(()=>(...t)=>{var r;return(r=n.current)==null?void 0:r.call(n,...t)},[])}function li({prop:e,defaultProp:n,onChange:t=()=>{}}){const[r,o]=$q({defaultProp:n,onChange:t}),s=e!==void 0,i=s?e:r,a=Vt(t),l=P.useCallback(c=>{if(s){const h=typeof c=="function"?c(e):c;h!==e&&a(h)}else o(c)},[s,e,o,a]);return[i,l]}function $q({defaultProp:e,onChange:n}){const t=P.useState(e),[r]=t,o=P.useRef(r),s=Vt(n);return P.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),t}var Xi=P.forwardRef((e,n)=>{const{children:t,...r}=e,o=P.Children.toArray(t),s=o.find(Nq);if(s){const i=s.props.children,a=o.map(l=>l===s?P.Children.count(i)>1?P.Children.only(null):P.isValidElement(i)?i.props.children:null:l);return d.jsx(Ov,{...r,ref:n,children:P.isValidElement(i)?P.cloneElement(i,void 0,a):null})}return d.jsx(Ov,{...r,ref:n,children:t})});Xi.displayName="Slot";var Ov=P.forwardRef((e,n)=>{const{children:t,...r}=e;if(P.isValidElement(t)){const o=Bq(t);return P.cloneElement(t,{...zq(r,t.props),ref:n?gg(n,o):o})}return P.Children.count(t)>1?P.Children.only(null):null});Ov.displayName="SlotClone";var Fq=({children:e})=>d.jsx(d.Fragment,{children:e});function Nq(e){return P.isValidElement(e)&&e.type===Fq}function zq(e,n){const t={...n};for(const r in n){const o=e[r],s=n[r];/^on[A-Z]/.test(r)?o&&s?t[r]=(...a)=>{s(...a),o(...a)}:o&&(t[r]=o):r==="style"?t[r]={...o,...s}:r==="className"&&(t[r]=[o,s].filter(Boolean).join(" "))}return{...e,...t}}function Bq(e){var r,o;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,t=n&&"isReactWarning"in n&&n.isReactWarning;return t?e.ref:(n=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,t=n&&"isReactWarning"in n&&n.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}var Uq=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ce=Uq.reduce((e,n)=>{const t=P.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?Xi:n;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(a,{...i,ref:o})});return t.displayName=`Primitive.${n}`,{...e,[n]:t}},{});function p0(e,n){e&&aa.flushSync(()=>e.dispatchEvent(n))}function Hq(e,n=globalThis==null?void 0:globalThis.document){const t=Vt(e);P.useEffect(()=>{const r=o=>{o.key==="Escape"&&t(o)};return n.addEventListener("keydown",r,{capture:!0}),()=>n.removeEventListener("keydown",r,{capture:!0})},[t,n])}var Kq="DismissableLayer",Dv="dismissableLayer.update",Wq="dismissableLayer.pointerDownOutside",Gq="dismissableLayer.focusOutside",II,qA=P.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Wu=P.forwardRef((e,n)=>{const{disableOutsidePointerEvents:t=!1,onEscapeKeyDown:r,onPointerDownOutside:o,onFocusOutside:s,onInteractOutside:i,onDismiss:a,...l}=e,c=P.useContext(qA),[u,h]=P.useState(null),p=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,f]=P.useState({}),S=Ye(n,k=>h(k)),m=Array.from(c.layers),[x]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=m.indexOf(x),v=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,E=v>=y,I=Yq(k=>{const T=k.target,O=[...c.branches].some(_=>_.contains(T));!E||O||(o==null||o(k),i==null||i(k),k.defaultPrevented||a==null||a())},p),C=Xq(k=>{const T=k.target;[...c.branches].some(_=>_.contains(T))||(s==null||s(k),i==null||i(k),k.defaultPrevented||a==null||a())},p);return Hq(k=>{v===c.layers.size-1&&(r==null||r(k),!k.defaultPrevented&&a&&(k.preventDefault(),a()))},p),P.useEffect(()=>{if(u)return t&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(II=p.body.style.pointerEvents,p.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),EI(),()=>{t&&c.layersWithOutsidePointerEventsDisabled.size===1&&(p.body.style.pointerEvents=II)}},[u,p,t,c]),P.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),EI())},[u,c]),P.useEffect(()=>{const k=()=>f({});return document.addEventListener(Dv,k),()=>document.removeEventListener(Dv,k)},[]),d.jsx(Ce.div,{...l,ref:S,style:{pointerEvents:b?E?"auto":"none":void 0,...e.style},onFocusCapture:re(e.onFocusCapture,C.onFocusCapture),onBlurCapture:re(e.onBlurCapture,C.onBlurCapture),onPointerDownCapture:re(e.onPointerDownCapture,I.onPointerDownCapture)})});Wu.displayName=Kq;var Vq="DismissableLayerBranch",ZA=P.forwardRef((e,n)=>{const t=P.useContext(qA),r=P.useRef(null),o=Ye(n,r);return P.useEffect(()=>{const s=r.current;if(s)return t.branches.add(s),()=>{t.branches.delete(s)}},[t.branches]),d.jsx(Ce.div,{...e,ref:o})});ZA.displayName=Vq;function Yq(e,n=globalThis==null?void 0:globalThis.document){const t=Vt(e),r=P.useRef(!1),o=P.useRef(()=>{});return P.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let l=function(){QA(Wq,t,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(n.removeEventListener("click",o.current),o.current=l,n.addEventListener("click",o.current,{once:!0})):l()}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 Xq(e,n=globalThis==null?void 0:globalThis.document){const t=Vt(e),r=P.useRef(!1);return P.useEffect(()=>{const o=s=>{s.target&&!r.current&&QA(Gq,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 EI(){const e=new CustomEvent(Dv);document.dispatchEvent(e)}function QA(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?p0(o,s):o.dispatchEvent(s)}var qq=Wu,Zq=ZA,py="focusScope.autoFocusOnMount",fy="focusScope.autoFocusOnUnmount",kI={bubbles:!1,cancelable:!0},Qq="FocusScope",mg=P.forwardRef((e,n)=>{const{loop:t=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=P.useState(null),c=Vt(o),u=Vt(s),h=P.useRef(null),p=Ye(n,m=>l(m)),f=P.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;P.useEffect(()=>{if(r){let m=function(b){if(f.paused||!a)return;const E=b.target;a.contains(E)?h.current=E:ws(h.current,{select:!0})},x=function(b){if(f.paused||!a)return;const E=b.relatedTarget;E!==null&&(a.contains(E)||ws(h.current,{select:!0}))},y=function(b){if(document.activeElement===document.body)for(const I of b)I.removedNodes.length>0&&ws(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",x);const v=new MutationObserver(y);return a&&v.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",x),v.disconnect()}}},[r,a,f.paused]),P.useEffect(()=>{if(a){TI.add(f);const m=document.activeElement;if(!a.contains(m)){const y=new CustomEvent(py,kI);a.addEventListener(py,c),a.dispatchEvent(y),y.defaultPrevented||(Jq(oZ(JA(a)),{select:!0}),document.activeElement===m&&ws(a))}return()=>{a.removeEventListener(py,c),setTimeout(()=>{const y=new CustomEvent(fy,kI);a.addEventListener(fy,u),a.dispatchEvent(y),y.defaultPrevented||ws(m??document.body,{select:!0}),a.removeEventListener(fy,u),TI.remove(f)},0)}}},[a,c,u,f]);const S=P.useCallback(m=>{if(!t&&!r||f.paused)return;const x=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,y=document.activeElement;if(x&&y){const v=m.currentTarget,[b,E]=eZ(v);b&&E?!m.shiftKey&&y===E?(m.preventDefault(),t&&ws(b,{select:!0})):m.shiftKey&&y===b&&(m.preventDefault(),t&&ws(E,{select:!0})):y===v&&m.preventDefault()}},[t,r,f.paused]);return d.jsx(Ce.div,{tabIndex:-1,...i,ref:p,onKeyDown:S})});mg.displayName=Qq;function Jq(e,{select:n=!1}={}){const t=document.activeElement;for(const r of e)if(ws(r,{select:n}),document.activeElement!==t)return}function eZ(e){const n=JA(e),t=_I(n,e),r=_I(n.reverse(),e);return[t,r]}function JA(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 _I(e,n){for(const t of e)if(!tZ(t,{upTo:n}))return t}function tZ(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 nZ(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&&nZ(e)&&n&&e.select()}}var TI=rZ();function rZ(){let e=[];return{add(n){const t=e[0];n!==t&&(t==null||t.pause()),e=MI(e,n),e.unshift(n)},remove(n){var t;e=MI(e,n),(t=e[0])==null||t.resume()}}}function MI(e,n){const t=[...e],r=t.indexOf(n);return r!==-1&&t.splice(r,1),t}function oZ(e){return e.filter(n=>n.tagName!=="A")}var sZ="Portal",Gu=P.forwardRef((e,n)=>{var a;const{container:t,...r}=e,[o,s]=P.useState(!1);Xs(()=>s(!0),[]);const i=t||o&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?CW.createPortal(d.jsx(Ce.div,{...r,ref:n}),i):null});Gu.displayName=sZ;function iZ(e,n){return P.useReducer((t,r)=>n[t][r]??t,e)}var Xr=e=>{const{present:n,children:t}=e,r=aZ(n),o=typeof t=="function"?t({present:r.isPresent}):P.Children.only(t),s=Ye(r.ref,lZ(o));return typeof t=="function"||r.isPresent?P.cloneElement(o,{ref:s}):null};Xr.displayName="Presence";function aZ(e){const[n,t]=P.useState(),r=P.useRef({}),o=P.useRef(e),s=P.useRef("none"),i=e?"mounted":"unmounted",[a,l]=iZ(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return P.useEffect(()=>{const c=Qd(r.current);s.current=a==="mounted"?c:"none"},[a]),Xs(()=>{const c=r.current,u=o.current;if(u!==e){const p=s.current,f=Qd(c);e?l("MOUNT"):f==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&p!==f?"ANIMATION_OUT":"UNMOUNT"),o.current=e}},[e,l]),Xs(()=>{if(n){const c=h=>{const f=Qd(r.current).includes(h.animationName);h.target===n&&f&&aa.flushSync(()=>l("ANIMATION_END"))},u=h=>{h.target===n&&(s.current=Qd(r.current))};return n.addEventListener("animationstart",u),n.addEventListener("animationcancel",c),n.addEventListener("animationend",c),()=>{n.removeEventListener("animationstart",u),n.removeEventListener("animationcancel",c),n.removeEventListener("animationend",c)}}else l("ANIMATION_END")},[n,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:P.useCallback(c=>{c&&(r.current=getComputedStyle(c)),t(c)},[])}}function Qd(e){return(e==null?void 0:e.animationName)||"none"}function lZ(e){var r,o;let n=(r=Object.getOwnPropertyDescriptor(e.props,"ref"))==null?void 0:r.get,t=n&&"isReactWarning"in n&&n.isReactWarning;return t?e.ref:(n=(o=Object.getOwnPropertyDescriptor(e,"ref"))==null?void 0:o.get,t=n&&"isReactWarning"in n&&n.isReactWarning,t?e.props.ref:e.props.ref||e.ref)}var gy=0;function f0(){P.useEffect(()=>{const e=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",e[0]??AI()),document.body.insertAdjacentElement("beforeend",e[1]??AI()),gy++,()=>{gy===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(n=>n.remove()),gy--}},[])}function AI(){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 ao=function(){return ao=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},ao.apply(this,arguments)};function ej(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 cZ(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 up="right-scroll-bar-position",dp="width-before-scroll-bar",uZ="with-scroll-bars-hidden",dZ="--removed-body-scroll-bar-size";function my(e,n){return typeof e=="function"?e(n):e&&(e.current=n),e}function hZ(e,n){var t=P.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 pZ=typeof window<"u"?P.useLayoutEffect:P.useEffect,jI=new WeakMap;function fZ(e,n){var t=hZ(null,function(r){return e.forEach(function(o){return my(o,r)})});return pZ(function(){var r=jI.get(t);if(r){var o=new Set(r),s=new Set(e),i=t.current;o.forEach(function(a){s.has(a)||my(a,null)}),s.forEach(function(a){o.has(a)||my(a,i)})}jI.set(t,e)},[e]),t}function gZ(e){return e}function mZ(e,n){n===void 0&&(n=gZ);var t=[],r=!1,o={read:function(){if(r)throw new Error("Sidecar: could not `read` from an `assigned` medium. `read` could be used only with `useMedium`.");return t.length?t[t.length-1]:e},useMedium:function(s){var i=n(s,r);return t.push(i),function(){t=t.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;t.length;){var i=t;t=[],i.forEach(s)}t={push:function(a){return s(a)},filter:function(){return t}}},assignMedium:function(s){r=!0;var i=[];if(t.length){var a=t;t=[],a.forEach(s),i=t}var l=function(){var u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),t={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),t}}}};return o}function yZ(e){e===void 0&&(e={});var n=mZ(null);return n.options=ao({async:!0,ssr:!1},e),n}var tj=function(e){var n=e.sideCar,t=ej(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 P.createElement(r,ao({},t))};tj.isSideCarExport=!0;function SZ(e,n){return e.useMedium(n),tj}var nj=yZ(),yy=function(){},yg=P.forwardRef(function(e,n){var t=P.useRef(null),r=P.useState({onScrollCapture:yy,onWheelCapture:yy,onTouchMoveCapture:yy}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,h=e.shards,p=e.sideCar,f=e.noIsolation,S=e.inert,m=e.allowPinchZoom,x=e.as,y=x===void 0?"div":x,v=e.gapMode,b=ej(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),E=p,I=fZ([t,n]),C=ao(ao({},b),o);return P.createElement(P.Fragment,null,u&&P.createElement(E,{sideCar:nj,removeScrollBar:c,shards:h,noIsolation:f,inert:S,setCallbacks:s,allowPinchZoom:!!m,lockRef:t,gapMode:v}),i?P.cloneElement(P.Children.only(a),ao(ao({},C),{ref:I})):P.createElement(y,ao({},C,{className:l,ref:I}),a))});yg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};yg.classNames={fullWidth:dp,zeroRight:up};var vZ=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function xZ(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var n=vZ();return n&&e.setAttribute("nonce",n),e}function wZ(e,n){e.styleSheet?e.styleSheet.cssText=n:e.appendChild(document.createTextNode(n))}function bZ(e){var n=document.head||document.getElementsByTagName("head")[0];n.appendChild(e)}var PZ=function(){var e=0,n=null;return{add:function(t){e==0&&(n=xZ())&&(wZ(n,t),bZ(n)),e++},remove:function(){e--,!e&&n&&(n.parentNode&&n.parentNode.removeChild(n),n=null)}}},CZ=function(){var e=PZ();return function(n,t){P.useEffect(function(){return e.add(n),function(){e.remove()}},[n&&t])}},rj=function(){var e=CZ(),n=function(t){var r=t.styles,o=t.dynamic;return e(r,o),null};return n},IZ={left:0,top:0,right:0,gap:0},Sy=function(e){return parseInt(e||"",10)||0},EZ=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[Sy(t),Sy(r),Sy(o)]},kZ=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return IZ;var n=EZ(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])}},_Z=rj(),ol="data-scroll-locked",TZ=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(uZ,` {
|
|
160
|
-
overflow: hidden `).concat(r,`;
|
|
161
|
-
padding-right: `).concat(a,"px ").concat(r,`;
|
|
162
|
-
}
|
|
163
|
-
body[`).concat(ol,`] {
|
|
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(up,` {
|
|
177
|
-
right: `).concat(a,"px ").concat(r,`;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
.`).concat(dp,` {
|
|
181
|
-
margin-right: `).concat(a,"px ").concat(r,`;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
.`).concat(up," .").concat(up,` {
|
|
185
|
-
right: 0 `).concat(r,`;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.`).concat(dp," .").concat(dp,` {
|
|
189
|
-
margin-right: 0 `).concat(r,`;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
body[`).concat(ol,`] {
|
|
193
|
-
`).concat(dZ,": ").concat(a,`px;
|
|
194
|
-
}
|
|
195
|
-
`)},OI=function(){var e=parseInt(document.body.getAttribute(ol)||"0",10);return isFinite(e)?e:0},MZ=function(){P.useEffect(function(){return document.body.setAttribute(ol,(OI()+1).toString()),function(){var e=OI()-1;e<=0?document.body.removeAttribute(ol):document.body.setAttribute(ol,e.toString())}},[])},AZ=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;MZ();var s=P.useMemo(function(){return kZ(o)},[o]);return P.createElement(_Z,{styles:TZ(s,!n,o,t?"":"!important")})},Rv=!1;if(typeof window<"u")try{var Jd=Object.defineProperty({},"passive",{get:function(){return Rv=!0,!0}});window.addEventListener("test",Jd,Jd),window.removeEventListener("test",Jd,Jd)}catch{Rv=!1}var va=Rv?{passive:!1}:!1,jZ=function(e){return e.tagName==="TEXTAREA"},oj=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!jZ(e)&&t[n]==="visible")},OZ=function(e){return oj(e,"overflowY")},DZ=function(e){return oj(e,"overflowX")},DI=function(e,n){var t=n.ownerDocument,r=n;do{typeof ShadowRoot<"u"&&r instanceof ShadowRoot&&(r=r.host);var o=sj(e,r);if(o){var s=ij(e,r),i=s[1],a=s[2];if(i>a)return!0}r=r.parentNode}while(r&&r!==t.body);return!1},RZ=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},LZ=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},sj=function(e,n){return e==="v"?OZ(n):DZ(n)},ij=function(e,n){return e==="v"?RZ(n):LZ(n)},$Z=function(e,n){return e==="h"&&n==="rtl"?-1:1},FZ=function(e,n,t,r,o){var s=$Z(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,l=n.contains(a),c=!1,u=i>0,h=0,p=0;do{var f=ij(e,a),S=f[0],m=f[1],x=f[2],y=m-x-s*S;(S||y)&&sj(e,a)&&(h+=y,p+=S),a instanceof ShadowRoot?a=a.host:a=a.parentNode}while(!l&&a!==document.body||l&&(n.contains(a)||n===a));return(u&&(Math.abs(h)<1||!o)||!u&&(Math.abs(p)<1||!o))&&(c=!0),c},eh=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},RI=function(e){return[e.deltaX,e.deltaY]},LI=function(e){return e&&"current"in e?e.current:e},NZ=function(e,n){return e[0]===n[0]&&e[1]===n[1]},zZ=function(e){return`
|
|
196
|
-
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
197
|
-
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
198
|
-
`)},BZ=0,xa=[];function UZ(e){var n=P.useRef([]),t=P.useRef([0,0]),r=P.useRef(),o=P.useState(BZ++)[0],s=P.useState(rj)[0],i=P.useRef(e);P.useEffect(function(){i.current=e},[e]),P.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var m=cZ([e.lockRef.current],(e.shards||[]).map(LI),!0).filter(Boolean);return m.forEach(function(x){return x.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),m.forEach(function(x){return x.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=P.useCallback(function(m,x){if("touches"in m&&m.touches.length===2)return!i.current.allowPinchZoom;var y=eh(m),v=t.current,b="deltaX"in m?m.deltaX:v[0]-y[0],E="deltaY"in m?m.deltaY:v[1]-y[1],I,C=m.target,k=Math.abs(b)>Math.abs(E)?"h":"v";if("touches"in m&&k==="h"&&C.type==="range")return!1;var T=DI(k,C);if(!T)return!0;if(T?I=k:(I=k==="v"?"h":"v",T=DI(k,C)),!T)return!1;if(!r.current&&"changedTouches"in m&&(b||E)&&(r.current=I),!I)return!0;var O=r.current||I;return FZ(O,x,m,O==="h"?b:E,!0)},[]),l=P.useCallback(function(m){var x=m;if(!(!xa.length||xa[xa.length-1]!==s)){var y="deltaY"in x?RI(x):eh(x),v=n.current.filter(function(I){return I.name===x.type&&(I.target===x.target||x.target===I.shadowParent)&&NZ(I.delta,y)})[0];if(v&&v.should){x.cancelable&&x.preventDefault();return}if(!v){var b=(i.current.shards||[]).map(LI).filter(Boolean).filter(function(I){return I.contains(x.target)}),E=b.length>0?a(x,b[0]):!i.current.noIsolation;E&&x.cancelable&&x.preventDefault()}}},[]),c=P.useCallback(function(m,x,y,v){var b={name:m,delta:x,target:y,should:v,shadowParent:HZ(y)};n.current.push(b),setTimeout(function(){n.current=n.current.filter(function(E){return E!==b})},1)},[]),u=P.useCallback(function(m){t.current=eh(m),r.current=void 0},[]),h=P.useCallback(function(m){c(m.type,RI(m),m.target,a(m,e.lockRef.current))},[]),p=P.useCallback(function(m){c(m.type,eh(m),m.target,a(m,e.lockRef.current))},[]);P.useEffect(function(){return xa.push(s),e.setCallbacks({onScrollCapture:h,onWheelCapture:h,onTouchMoveCapture:p}),document.addEventListener("wheel",l,va),document.addEventListener("touchmove",l,va),document.addEventListener("touchstart",u,va),function(){xa=xa.filter(function(m){return m!==s}),document.removeEventListener("wheel",l,va),document.removeEventListener("touchmove",l,va),document.removeEventListener("touchstart",u,va)}},[]);var f=e.removeScrollBar,S=e.inert;return P.createElement(P.Fragment,null,S?P.createElement(s,{styles:zZ(o)}):null,f?P.createElement(AZ,{gapMode:e.gapMode}):null)}function HZ(e){for(var n=null;e!==null;)e instanceof ShadowRoot&&(n=e.host,e=e.host),e=e.parentNode;return n}const KZ=SZ(nj,UZ);var Sg=P.forwardRef(function(e,n){return P.createElement(yg,ao({},e,{ref:n,sideCar:KZ}))});Sg.classNames=yg.classNames;var WZ=function(e){if(typeof document>"u")return null;var n=Array.isArray(e)?e[0]:e;return n.ownerDocument.body},wa=new WeakMap,th=new WeakMap,nh={},vy=0,aj=function(e){return e&&(e.host||aj(e.parentNode))},GZ=function(e,n){return n.map(function(t){if(e.contains(t))return t;var r=aj(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})},VZ=function(e,n,t,r){var o=GZ(n,Array.isArray(e)?e:[e]);nh[t]||(nh[t]=new WeakMap);var s=nh[t],i=[],a=new Set,l=new Set(o),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};o.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(p){if(a.has(p))u(p);else try{var f=p.getAttribute(r),S=f!==null&&f!=="false",m=(wa.get(p)||0)+1,x=(s.get(p)||0)+1;wa.set(p,m),s.set(p,x),i.push(p),m===1&&S&&th.set(p,!0),x===1&&p.setAttribute(t,"true"),S||p.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",p,y)}})};return u(n),a.clear(),vy++,function(){i.forEach(function(h){var p=wa.get(h)-1,f=s.get(h)-1;wa.set(h,p),s.set(h,f),p||(th.has(h)||h.removeAttribute(r),th.delete(h)),f||h.removeAttribute(t)}),vy--,vy||(wa=new WeakMap,wa=new WeakMap,th=new WeakMap,nh={})}},g0=function(e,n,t){t===void 0&&(t="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=WZ(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),VZ(r,o,t,"aria-hidden")):function(){return null}},m0="Dialog",[lj,Wie]=ko(m0),[YZ,qr]=lj(m0),cj=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=P.useRef(null),l=P.useRef(null),[c=!1,u]=li({prop:r,defaultProp:o,onChange:s});return d.jsx(YZ,{scope:n,triggerRef:a,contentRef:l,contentId:Vo(),titleId:Vo(),descriptionId:Vo(),open:c,onOpenChange:u,onOpenToggle:P.useCallback(()=>u(h=>!h),[u]),modal:i,children:t})};cj.displayName=m0;var uj="DialogTrigger",XZ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(uj,t),s=Ye(n,o.triggerRef);return d.jsx(Ce.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":v0(o.open),...r,ref:s,onClick:re(e.onClick,o.onOpenToggle)})});XZ.displayName=uj;var y0="DialogPortal",[qZ,dj]=lj(y0,{forceMount:void 0}),hj=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=qr(y0,n);return d.jsx(qZ,{scope:n,forceMount:t,children:P.Children.map(r,i=>d.jsx(Xr,{present:t||s.open,children:d.jsx(Gu,{asChild:!0,container:o,children:i})}))})};hj.displayName=y0;var vf="DialogOverlay",pj=P.forwardRef((e,n)=>{const t=dj(vf,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=qr(vf,e.__scopeDialog);return s.modal?d.jsx(Xr,{present:r||s.open,children:d.jsx(ZZ,{...o,ref:n})}):null});pj.displayName=vf;var ZZ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(vf,t);return d.jsx(Sg,{as:Xi,allowPinchZoom:!0,shards:[o.contentRef],children:d.jsx(Ce.div,{"data-state":v0(o.open),...r,ref:n,style:{pointerEvents:"auto",...r.style}})})}),qi="DialogContent",fj=P.forwardRef((e,n)=>{const t=dj(qi,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=qr(qi,e.__scopeDialog);return d.jsx(Xr,{present:r||s.open,children:s.modal?d.jsx(QZ,{...o,ref:n}):d.jsx(JZ,{...o,ref:n})})});fj.displayName=qi;var QZ=P.forwardRef((e,n)=>{const t=qr(qi,e.__scopeDialog),r=P.useRef(null),o=Ye(n,t.contentRef,r);return P.useEffect(()=>{const s=r.current;if(s)return g0(s)},[]),d.jsx(gj,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:re(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)==null||i.focus()}),onPointerDownOutside:re(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:re(e.onFocusOutside,s=>s.preventDefault())})}),JZ=P.forwardRef((e,n)=>{const t=qr(qi,e.__scopeDialog),r=P.useRef(!1),o=P.useRef(!1);return d.jsx(gj,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=t.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),gj=P.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=qr(qi,t),l=P.useRef(null),c=Ye(n,l);return f0(),d.jsxs(d.Fragment,{children:[d.jsx(mg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Wu,{role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":v0(a.open),...i,ref:c,onDismiss:()=>a.onOpenChange(!1)})}),d.jsxs(d.Fragment,{children:[d.jsx(tQ,{titleId:a.titleId}),d.jsx(rQ,{contentRef:l,descriptionId:a.descriptionId})]})]})}),S0="DialogTitle",mj=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(S0,t);return d.jsx(Ce.h2,{id:o.titleId,...r,ref:n})});mj.displayName=S0;var yj="DialogDescription",eQ=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(yj,t);return d.jsx(Ce.p,{id:o.descriptionId,...r,ref:n})});eQ.displayName=yj;var Sj="DialogClose",vj=P.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=qr(Sj,t);return d.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,()=>o.onOpenChange(!1))})});vj.displayName=Sj;function v0(e){return e?"open":"closed"}var xj="DialogTitleWarning",[Gie,wj]=Oq(xj,{contentName:qi,titleName:S0,docsSlug:"dialog"}),tQ=({titleId:e})=>{const n=wj(xj),t=`\`${n.contentName}\` requires a \`${n.titleName}\` for the component to be accessible for screen reader users.
|
|
199
|
-
|
|
200
|
-
If you want to hide the \`${n.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
201
|
-
|
|
202
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${n.docsSlug}`;return P.useEffect(()=>{e&&(document.getElementById(e)||console.error(t))},[t,e]),null},nQ="DialogDescriptionWarning",rQ=({contentRef:e,descriptionId:n})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${wj(nQ).contentName}}.`;return P.useEffect(()=>{var s;const o=(s=e.current)==null?void 0:s.getAttribute("aria-describedby");n&&o&&(document.getElementById(n)||console.warn(r))},[r,e,n]),null},oQ=cj,sQ=hj,iQ=pj,aQ=fj;const bj=()=>{},Pj=P.createContext(null);function lQ({onEvent:e,children:n}){return d.jsx(Pj.Provider,{value:e??bj,children:n})}function Zr(){return P.useContext(Pj)??bj}const Cj=P.createContext(null);function cQ({children:e}){const n=B(),t=Zr(),[r,o]=P.useState([]),s=P.useCallback(c=>{const u=c.id??ot();return o(h=>[...h.filter(p=>p.id!==c.id),{...c,id:u}]),t("open-menu",{source:"dialog",id:u}),n.addOpenMenu(u),u},[n,t]),i=P.useCallback((c,u)=>(o(h=>h.map(p=>p.id===c?{...p,...u}:p)),t("open-menu",{source:"dialog",id:c}),n.addOpenMenu(c),c),[n,t]),a=P.useCallback(c=>(o(u=>u.filter(h=>{var p;return h.id===c?((p=h.onClose)==null||p.call(h),!1):!0})),t("close-menu",{source:"dialog",id:c}),n.deleteOpenMenu(c),c),[n,t]),l=P.useCallback(()=>{o(c=>(c.forEach(u=>{var h;(h=u.onClose)==null||h.call(u),t("close-menu",{source:"dialog",id:u.id}),n.deleteOpenMenu(u.id)}),[]))},[n,t]);return d.jsx(Cj.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function la(){const e=P.useContext(Cj);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const uQ=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=la(),o=un(),s=P.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return d.jsx(oQ,{onOpenChange:s,defaultOpen:!0,children:d.jsx(sQ,{container:o,children:d.jsx(iQ,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:d.jsx(aQ,{dir:"ltr",className:"tlui-dialog__content",children:d.jsx(n,{onClose:()=>s(!1)})})})})})};function dQ(){const{dialogs:e}=la();return d.jsx(d.Fragment,{children:e.map(n=>d.jsx(uQ,{...n},n.id))})}const hQ=xe.memo(dQ);function pQ(){const e=B(),n=G("follow",()=>e.getInstanceState().followingUserId,[e]);return n?d.jsx(fQ,{userId:n}):null}function fQ({userId:e}){const n=eT(e);return n?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function vg(e){const n=e+"CollectionProvider",[t,r]=ko(n),[o,s]=t(n,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:S,children:m}=f,x=xe.useRef(null),y=xe.useRef(new Map).current;return d.jsx(o,{scope:S,itemMap:y,collectionRef:x,children:m})};i.displayName=n;const a=e+"CollectionSlot",l=xe.forwardRef((f,S)=>{const{scope:m,children:x}=f,y=s(a,m),v=Ye(S,y.collectionRef);return d.jsx(Xi,{ref:v,children:x})});l.displayName=a;const c=e+"CollectionItemSlot",u="data-radix-collection-item",h=xe.forwardRef((f,S)=>{const{scope:m,children:x,...y}=f,v=xe.useRef(null),b=Ye(S,v),E=s(c,m);return xe.useEffect(()=>(E.itemMap.set(v,{ref:v,...y}),()=>void E.itemMap.delete(v))),d.jsx(Xi,{[u]:"",ref:b,children:x})});h.displayName=c;function p(f){const S=s(e+"CollectionConsumer",f);return xe.useCallback(()=>{const x=S.collectionRef.current;if(!x)return[];const y=Array.from(x.querySelectorAll(`[${u}]`));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:l,ItemSlot:h},p,r]}var gQ="VisuallyHidden",x0=P.forwardRef((e,n)=>d.jsx(Ce.span,{...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}}));x0.displayName=gQ;var w0="ToastProvider",[b0,mQ,yQ]=vg("Toast"),[Ij,Vie]=ko("Toast",[yQ]),[SQ,xg]=Ij(w0),Ej=e=>{const{__scopeToast:n,label:t="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=P.useState(null),[c,u]=P.useState(0),h=P.useRef(!1),p=P.useRef(!1);return t.trim()||console.error(`Invalid prop \`label\` supplied to \`${w0}\`. Expected non-empty \`string\`.`),d.jsx(b0.Provider,{scope:n,children:d.jsx(SQ,{scope:n,label:t,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:P.useCallback(()=>u(f=>f+1),[]),onToastRemove:P.useCallback(()=>u(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:p,children:i})})};Ej.displayName=w0;var kj="ToastViewport",vQ=["F8"],Lv="toast.viewportPause",$v="toast.viewportResume",_j=P.forwardRef((e,n)=>{const{__scopeToast:t,hotkey:r=vQ,label:o="Notifications ({hotkey})",...s}=e,i=xg(kj,t),a=mQ(t),l=P.useRef(null),c=P.useRef(null),u=P.useRef(null),h=P.useRef(null),p=Ye(n,h,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),S=i.toastCount>0;P.useEffect(()=>{const x=y=>{var b;r.every(E=>y[E]||y.code===E)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",x),()=>document.removeEventListener("keydown",x)},[r]),P.useEffect(()=>{const x=l.current,y=h.current;if(S&&x&&y){const v=()=>{if(!i.isClosePausedRef.current){const C=new CustomEvent(Lv);y.dispatchEvent(C),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const C=new CustomEvent($v);y.dispatchEvent(C),i.isClosePausedRef.current=!1}},E=C=>{!x.contains(C.relatedTarget)&&b()},I=()=>{x.contains(document.activeElement)||b()};return x.addEventListener("focusin",v),x.addEventListener("focusout",E),x.addEventListener("pointermove",v),x.addEventListener("pointerleave",I),window.addEventListener("blur",v),window.addEventListener("focus",b),()=>{x.removeEventListener("focusin",v),x.removeEventListener("focusout",E),x.removeEventListener("pointermove",v),x.removeEventListener("pointerleave",I),window.removeEventListener("blur",v),window.removeEventListener("focus",b)}}},[S,i.isClosePausedRef]);const m=P.useCallback(({tabbingDirection:x})=>{const v=a().map(b=>{const E=b.ref.current,I=[E,...jQ(E)];return x==="forwards"?I:I.reverse()});return(x==="forwards"?v.reverse():v).flat()},[a]);return P.useEffect(()=>{const x=h.current;if(x){const y=v=>{var I,C,k;const b=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!b){const T=document.activeElement,O=v.shiftKey;if(v.target===x&&O){(I=c.current)==null||I.focus();return}const L=m({tabbingDirection:O?"backwards":"forwards"}),j=L.findIndex(R=>R===T);xy(L.slice(j+1))?v.preventDefault():O?(C=c.current)==null||C.focus():(k=u.current)==null||k.focus()}};return x.addEventListener("keydown",y),()=>x.removeEventListener("keydown",y)}},[a,m]),d.jsxs(Zq,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:S?void 0:"none"},children:[S&&d.jsx(Fv,{ref:c,onFocusFromOutsideViewport:()=>{const x=m({tabbingDirection:"forwards"});xy(x)}}),d.jsx(b0.Slot,{scope:t,children:d.jsx(Ce.ol,{tabIndex:-1,...s,ref:p})}),S&&d.jsx(Fv,{ref:u,onFocusFromOutsideViewport:()=>{const x=m({tabbingDirection:"backwards"});xy(x)}})]})});_j.displayName=kj;var Tj="ToastFocusProxy",Fv=P.forwardRef((e,n)=>{const{__scopeToast:t,onFocusFromOutsideViewport:r,...o}=e,s=xg(Tj,t);return d.jsx(x0,{"aria-hidden":!0,tabIndex:0,...o,ref:n,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=s.viewport)!=null&&c.contains(a))&&r()}})});Fv.displayName=Tj;var wg="Toast",xQ="toast.swipeStart",wQ="toast.swipeMove",bQ="toast.swipeCancel",PQ="toast.swipeEnd",Mj=P.forwardRef((e,n)=>{const{forceMount:t,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,l]=li({prop:r,defaultProp:o,onChange:s});return d.jsx(Xr,{present:t||a,children:d.jsx(EQ,{open:a,...i,ref:n,onClose:()=>l(!1),onPause:Vt(e.onPause),onResume:Vt(e.onResume),onSwipeStart:re(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:re(e.onSwipeMove,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:re(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:re(e.onSwipeEnd,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});Mj.displayName=wg;var[CQ,IQ]=Ij(wg,{onClose(){}}),EQ=P.forwardRef((e,n)=>{const{__scopeToast:t,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:p,onSwipeEnd:f,...S}=e,m=xg(wg,t),[x,y]=P.useState(null),v=Ye(n,R=>y(R)),b=P.useRef(null),E=P.useRef(null),I=o||m.duration,C=P.useRef(0),k=P.useRef(I),T=P.useRef(0),{onToastAdd:O,onToastRemove:_}=m,A=Vt(()=>{var F;(x==null?void 0:x.contains(document.activeElement))&&((F=m.viewport)==null||F.focus()),i()}),L=P.useCallback(R=>{!R||R===1/0||(window.clearTimeout(T.current),C.current=new Date().getTime(),T.current=window.setTimeout(A,R))},[A]);P.useEffect(()=>{const R=m.viewport;if(R){const F=()=>{L(k.current),c==null||c()},W=()=>{const K=new Date().getTime()-C.current;k.current=k.current-K,window.clearTimeout(T.current),l==null||l()};return R.addEventListener(Lv,W),R.addEventListener($v,F),()=>{R.removeEventListener(Lv,W),R.removeEventListener($v,F)}}},[m.viewport,I,l,c,L]),P.useEffect(()=>{s&&!m.isClosePausedRef.current&&L(I)},[s,I,m.isClosePausedRef,L]),P.useEffect(()=>(O(),()=>_()),[O,_]);const j=P.useMemo(()=>x?$j(x):null,[x]);return m.viewport?d.jsxs(d.Fragment,{children:[j&&d.jsx(kQ,{__scopeToast:t,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:j}),d.jsx(CQ,{scope:t,onClose:A,children:aa.createPortal(d.jsx(b0.ItemSlot,{scope:t,children:d.jsx(qq,{asChild:!0,onEscapeKeyDown:re(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||A(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ce.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":m.swipeDirection,...S,ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:re(e.onKeyDown,R=>{R.key==="Escape"&&(a==null||a(R.nativeEvent),R.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,A()))}),onPointerDown:re(e.onPointerDown,R=>{R.button===0&&(b.current={x:R.clientX,y:R.clientY})}),onPointerMove:re(e.onPointerMove,R=>{if(!b.current)return;const F=R.clientX-b.current.x,W=R.clientY-b.current.y,K=!!E.current,z=["left","right"].includes(m.swipeDirection),U=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,X=z?U(0,F):0,J=z?0:U(0,W),le=R.pointerType==="touch"?10:2,ye={x:X,y:J},Me={originalEvent:R,delta:ye};K?(E.current=ye,rh(wQ,h,Me,{discrete:!1})):$I(ye,m.swipeDirection,le)?(E.current=ye,rh(xQ,u,Me,{discrete:!1}),R.target.setPointerCapture(R.pointerId)):(Math.abs(F)>le||Math.abs(W)>le)&&(b.current=null)}),onPointerUp:re(e.onPointerUp,R=>{const F=E.current,W=R.target;if(W.hasPointerCapture(R.pointerId)&&W.releasePointerCapture(R.pointerId),E.current=null,b.current=null,F){const K=R.currentTarget,z={originalEvent:R,delta:F};$I(F,m.swipeDirection,m.swipeThreshold)?rh(PQ,f,z,{discrete:!0}):rh(bQ,p,z,{discrete:!0}),K.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),kQ=e=>{const{__scopeToast:n,children:t,...r}=e,o=xg(wg,n),[s,i]=P.useState(!1),[a,l]=P.useState(!1);return MQ(()=>i(!0)),P.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(Gu,{asChild:!0,children:d.jsx(x0,{...r,children:s&&d.jsxs(d.Fragment,{children:[o.label," ",t]})})})},_Q="ToastTitle",Aj=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return d.jsx(Ce.div,{...r,ref:n})});Aj.displayName=_Q;var TQ="ToastDescription",jj=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e;return d.jsx(Ce.div,{...r,ref:n})});jj.displayName=TQ;var Oj="ToastAction",Dj=P.forwardRef((e,n)=>{const{altText:t,...r}=e;return t.trim()?d.jsx(Lj,{altText:t,asChild:!0,children:d.jsx(P0,{...r,ref:n})}):(console.error(`Invalid prop \`altText\` supplied to \`${Oj}\`. Expected non-empty \`string\`.`),null)});Dj.displayName=Oj;var Rj="ToastClose",P0=P.forwardRef((e,n)=>{const{__scopeToast:t,...r}=e,o=IQ(Rj,t);return d.jsx(Lj,{asChild:!0,children:d.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,o.onClose)})})});P0.displayName=Rj;var Lj=P.forwardRef((e,n)=>{const{__scopeToast:t,altText:r,...o}=e;return d.jsx(Ce.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...o,ref:n})});function $j(e){const n=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&n.push(r.textContent),AQ(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(...$j(r))}}),n}function rh(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?p0(o,s):o.dispatchEvent(s)}var $I=(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 MQ(e=()=>{}){const n=Vt(e);Xs(()=>{let t=0,r=0;return t=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(n)),()=>{window.cancelAnimationFrame(t),window.cancelAnimationFrame(r)}},[n])}function AQ(e){return e.nodeType===e.ELEMENT_NODE}function jQ(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 xy(e){const n=document.activeElement;return e.some(t=>t===n?!0:(t.focus(),document.activeElement!==n))}var OQ=Mj,DQ=Aj,RQ=jj,LQ=Dj,FI=P0;const Fj=P.createContext(null);function $Q({children:e}){const[n,t]=P.useState([]),r=P.useCallback(i=>{const a=i.id??ot();return t(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=P.useCallback(i=>(t(a=>a.filter(l=>l.id!==i)),i),[]),s=P.useCallback(()=>{t(()=>[])},[]);return d.jsx(Ej,{children:d.jsx(Fj.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})})}function Qr(){const e=P.useContext(Fj);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const he=P.forwardRef(function({children:n,disabled:t,type:r,...o},s){return d.jsx("button",{ref:s,type:"button",draggable:!1,disabled:t,...o,className:ce("tlui-button",`tlui-button__${r}`,o.className),children:n})});function bt({children:e}){return d.jsx("span",{className:"tlui-button__label",children:e})}const qs=P.memo(function({small:n,invertIcon:t,icon:r,color:o,className:s,...i}){const a=c0(),l=a.icons[r]??a.icons["question-mark-circle"],c=P.useRef(null);return P.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?d.jsx("div",{className:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":n},s)}):d.jsx("div",{...i,ref:c,className:ce("tlui-icon",{"tlui-icon__small":n},s),style:{color:o,mask:`url(${l}) center 100% / 100% no-repeat`,transform:t?"scale(-1, 1)":void 0}})}),FQ={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function NQ({toast:e}){const{removeToast:n}=Qr(),t=Te(),r=i=>{i||n(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&FQ[e.severity];return d.jsxs(OQ,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&d.jsx("div",{className:"tlui-toast__icon",children:d.jsx(qs,{icon:s})}),d.jsxs("div",{className:"tlui-toast__main",children:[d.jsxs("div",{className:"tlui-toast__content",children:[e.title&&d.jsx(DQ,{className:"tlui-toast__title",children:e.title}),e.description&&d.jsx(RQ,{className:"tlui-toast__description",children:e.description})]}),e.actions&&d.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>d.jsx(LQ,{altText:i.label,asChild:!0,onClick:i.onClick,children:d.jsx(he,{type:i.type,children:d.jsx(bt,{children:i.label})})},a)),d.jsx(FI,{asChild:!0,children:d.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:d.jsx(bt,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&d.jsx(FI,{asChild:!0,children:d.jsx(he,{type:"normal",className:"tlui-toast__close",children:d.jsx(bt,{children:e.closeLabel??t("toast.close")})})})]})}function zQ(){const{toasts:e}=Qr();return d.jsx(d.Fragment,{children:e.map(n=>d.jsx(NQ,{toast:n},n.id))})}const BQ=P.memo(zQ);function UQ(){const e=B(),{toasts:n}=Qr(),[t,r]=P.useState(!1);return P.useEffect(()=>{let o=-1;return n.length?r(!0):o=e.timers.setTimeout(()=>{r(!1)},1e3),()=>{clearTimeout(o)}},[n.length,r,e]),t?d.jsx(_j,{className:"tlui-toast__viewport"}):null}function be({icon:e,small:n,invertIcon:t}){return d.jsx(qs,{className:"tlui-button__icon",icon:e,small:n,invertIcon:t})}const wy=[0,390,428,468,580,640,840,1023];var yt=(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))(yt||{});const HQ="2.3.0",KQ="https://cdn.tldraw.com";function Ti(){return`${KQ}/${HQ}`}let Nv={fonts:{draw:`${Ti()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${Ti()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${Ti()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${Ti()}/fonts/IBMPlexMono-Medium.woff2`}};function Nj(e){return P.useMemo(()=>e?{fonts:{...Nv.fonts,...e==null?void 0:e.fonts}}:Nv,[e])}const WQ=["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 dc={...Nv,icons:Object.fromEntries(WQ.map(e=>[e,`${Ti()}/icons/icon/${e}.svg`])),translations:Object.fromEntries(Xc.map(e=>[e.locale,`${Ti()}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(ju.map(e=>[e.type,`${Ti()}/embed-icons/${e.type}.png`]))};function GQ(e){return e?{fonts:Object.assign({...dc.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...dc.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...dc.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...dc.translations},{...e==null?void 0:e.translations})}:dc}function bg({className:e,children:n}){return d.jsx("div",{className:ce("tlui-dialog__header",e),children:n})}function Pg({className:e,children:n}){return d.jsx(mj,{dir:"ltr",className:ce("tlui-dialog__header__title",e),children:n})}function Cg(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(vj,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(he,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:d.jsx(be,{small:!0,icon:"cross-2"})})})})}function gu({className:e,children:n,style:t}){return d.jsx("div",{className:ce("tlui-dialog__body",e),style:t,children:n})}function C0({className:e,children:n}){return d.jsx("div",{className:ce("tlui-dialog__footer",e),children:n})}const I0=P.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoSelect:s=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:p,onBlur:f,shouldManuallyMaintainScrollPositionWhenFocused:S=!1,children:m,value:x},y){const v=B(),b=P.useRef(null);P.useImperativeHandle(y,()=>b.current);const E=Te(),I=P.useRef(a??""),C=P.useRef(a??""),[k,T]=P.useState(!1),O=P.useCallback(j=>{T(!0);const R=j.currentTarget;C.current=R.value,v.timers.requestAnimationFrame(()=>{s&&R.select()}),p==null||p()},[s,p,v.timers]),_=P.useCallback(j=>{const R=j.currentTarget.value;C.current=R,u==null||u(R)},[u]),A=P.useCallback(j=>{switch(j.key){case"Enter":{j.currentTarget.blur(),Ht(j),c==null||c(j.currentTarget.value);break}case"Escape":{j.currentTarget.value=I.current,j.currentTarget.blur(),Ht(j),h==null||h(j.currentTarget.value);break}}},[c,h]),L=P.useCallback(j=>{T(!1);const R=j.currentTarget.value;f==null||f(R)},[f]);return P.useEffect(()=>{if(!v.environment.isIos)return;const j=window.visualViewport;if(k&&S&&j){const R=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return j.addEventListener("resize",R),j.addEventListener("scroll",R),v.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{j.removeEventListener("resize",R),j.removeEventListener("scroll",R)}}},[v,k,S]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,t&&d.jsx("label",{children:E(t)}),o&&d.jsx(qs,{icon:o,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:ce("tlui-input",n),type:"text",defaultValue:a,onKeyUp:A,onChange:_,onFocus:O,onBlur:L,autoFocus:i,placeholder:l,value:x}),r&&d.jsx(qs,{icon:r,small:!!t})]})}),zj=ar(function({onClose:n}){const t=B(),r=Te(),o=c0(),[s,i]=P.useState(null),[a,l]=P.useState(""),[c,u]=P.useState(null),[h,p]=P.useState(!1),f=P.useRef(-1);return d.jsxs(d.Fragment,{children:[d.jsxs(bg,{children:[d.jsx(Pg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),d.jsx(Cg,{})]}),s?d.jsxs(d.Fragment,{children:[d.jsxs(gu,{className:"tlui-embed-dialog__enter",children:[d.jsx(I0,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autoFocus:!0,onValueChange:S=>{l(S);const m=As(S);u(m&&m.definition.type===s.type?m:null),p(!1),clearTimeout(f.current),f.current=t.timers.setTimeout(()=>p(!m),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(qs,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(C0,{className:"tlui-dialog__footer__actions",children:[d.jsx(he,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(bt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(he,{type:"normal",onClick:n,children:d.jsx(bt,{children:r("embed-dialog.cancel")})}),d.jsx(he,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageBounds().center,embed:c.definition}),n())},children:d.jsx(bt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(gu,{className:"tlui-embed-dialog__list",children:ju.map(S=>d.jsxs(he,{type:"menu",onClick:()=>i(S),children:[d.jsx(bt,{children:S.title}),d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[S.type]})`}})]},S.type))})})]})});function Bj(){const e=B(),n=P.useRef();return P.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept=R4,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]),P.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}const Uj=P.createContext(null);function VQ({overrides:e,children:n}){const t=B(),r=Zr(),{addDialog:o}=la(),s=Bj(),i=P.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){t.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){t.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){t.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){t.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...Nr.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){t.batch(()=>{t.setStyleForNextShapes(Nr,c),t.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){t.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){t.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){t.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){t.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){t.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){t.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"dot",onSelect(c){o({component:zj}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){t.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];a.push();const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(t,l,{insertMedia:s}):l},[e,t,r,s,o]);return d.jsx(Uj.Provider,{value:i,children:n})}function Ig(){const e=P.useContext(Uj);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const Hj=xe.createContext(null);function YQ({forceMobile:e=!1,children:n}){const t=B(),r=G("breakpoint",()=>{const{width:o}=t.getViewportScreenBounds(),s=e?yt.MOBILE_SM:wy.length-1;for(let i=0;i<s;i++)if(o>wy[i]&&o<=wy[i+1])return i;return s},[t]);return d.jsx(Hj.Provider,{value:r,children:n})}function Hn(){const e=P.useContext(Hj);if(e===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return e}function XQ(){const{addToast:e,removeToast:n,clearToasts:t}=Qr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=la(),l=Hn()<yt.TABLET_SM,c=Te();return P.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,e,o,t,c,s,n,i,l])}function qQ(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of Ln(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 Kj(e){return P.useMemo(()=>e,e)}function ZQ(e){const n=Kj(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of Ln(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function QQ(e){const n=XQ(),t=Kj(e==null?[]:Array.isArray(e)?e:[e]);return P.useMemo(()=>qQ(t,n),[t,n])}function JQ(e,n){const t=me(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 eJ=50;function tJ(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=me(o.map(f=>e.getShape(f)));if(!s.length)return;const i=Z.FromPoints(s.flatMap(f=>{const S=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(S.vertices)})),{padding:a=eJ}=t,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,h=a-i.minY;if(u===0&&h===0&&r.props.w===l&&r.props.h===c)return;const p=new w(u,h).rot(r.rotation);e.batch(()=>{const f=o.map(S=>{const m=e.getShape(S);return{id:m.id,type:m.type,x:m.x+u,y:m.y+h}});f.push({id:r.id,type:r.type,x:r.x-p.x,y:r.y-p.y,props:{w:l,h:c}}),e.updateShapes(f)})}function NI(e){return or.isValid(e)?{isValid:!0,hasProtocol:!0}:or.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const nJ=ar(function({onClose:n}){const r=B().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(rJ,{onClose:n,selectedShape:r}):null}),rJ=ar(function({onClose:n,selectedShape:t}){const r=B(),o=Te(),s=P.useRef(null);P.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var S;return(S=s.current)==null?void 0:S.focus()})},[r]);const i=P.useRef(t.props.url),[a,l]=P.useState(()=>{const S=NI(t.props.url),m=S.isValid===!0?S.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=P.useCallback(S=>{const m=S.replace(/https?:\/\/(https?:\/\/)/,(v,b)=>b),x=NI(m),y=x.isValid===!0?x.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:y,valid:x.isValid})},[]),u=P.useCallback(()=>{const S=r.getOnlySelectedShape();S&&(r.updateShapes([{id:S.id,type:S.type,props:{url:""}}]),n())},[r,n]),h=P.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]),p=P.useCallback(()=>{n()},[n]);if(!t)return n(),null;const f=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(bg,{children:[d.jsx(Pg,{children:o("edit-link-dialog.title")}),d.jsx(Cg,{})]}),d.jsx(gu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(I0,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:p}),d.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),d.jsxs(C0,{className:"tlui-dialog__footer__actions",children:[d.jsx(he,{type:"normal",onClick:p,onTouchEnd:p,children:d.jsx(bt,{children:o("edit-link-dialog.cancel")})}),f?d.jsx(he,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(bt,{children:o("edit-link-dialog.clear")})}):d.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(bt,{children:o("edit-link-dialog.save")})})]})]})});var E0={exports:{}};E0.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),h=0,p=c.length;h<p;h++){var f=c.charCodeAt(h);u[h*2]=f>>>8,u[h*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(f){p.push(t(f))}),a.decompress(p.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,u){if(l==null)return"";var h,p,f={},S={},m="",x="",y="",v=2,b=3,E=2,I=[],C=0,k=0,T;for(T=0;T<l.length;T+=1)if(m=l.charAt(T),Object.prototype.hasOwnProperty.call(f,m)||(f[m]=b++,S[m]=!0),x=y+m,Object.prototype.hasOwnProperty.call(f,x))y=x;else{if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(h=0;h<E;h++)C=C<<1,k==c-1?(k=0,I.push(u(C)),C=0):k++;for(p=y.charCodeAt(0),h=0;h<8;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1}else{for(p=1,h=0;h<E;h++)C=C<<1|p,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=0;for(p=y.charCodeAt(0),h=0;h<16;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete S[y]}else for(p=f[y],h=0;h<E;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++),f[x]=b++,y=String(m)}if(y!==""){if(Object.prototype.hasOwnProperty.call(S,y)){if(y.charCodeAt(0)<256){for(h=0;h<E;h++)C=C<<1,k==c-1?(k=0,I.push(u(C)),C=0):k++;for(p=y.charCodeAt(0),h=0;h<8;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1}else{for(p=1,h=0;h<E;h++)C=C<<1|p,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=0;for(p=y.charCodeAt(0),h=0;h<16;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1}v--,v==0&&(v=Math.pow(2,E),E++),delete S[y]}else for(p=f[y],h=0;h<E;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1;v--,v==0&&(v=Math.pow(2,E),E++)}for(p=2,h=0;h<E;h++)C=C<<1|p&1,k==c-1?(k=0,I.push(u(C)),C=0):k++,p=p>>1;for(;;)if(C=C<<1,k==c-1){I.push(u(C));break}else k++;return I.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],p=4,f=4,S=3,m="",x=[],y,v,b,E,I,C,k,T={val:u(0),position:c,index:1};for(y=0;y<3;y+=1)h[y]=y;for(b=0,I=Math.pow(2,2),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;switch(b){case 0:for(b=0,I=Math.pow(2,8),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;k=t(b);break;case 1:for(b=0,I=Math.pow(2,16),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;k=t(b);break;case 2:return""}for(h[3]=k,v=k,x.push(k);;){if(T.index>l)return"";for(b=0,I=Math.pow(2,S),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;switch(k=b){case 0:for(b=0,I=Math.pow(2,8),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;h[f++]=t(b),k=f-1,p--;break;case 1:for(b=0,I=Math.pow(2,16),C=1;C!=I;)E=T.val&T.position,T.position>>=1,T.position==0&&(T.position=c,T.val=u(T.index++)),b|=(E>0?1:0)*C,C<<=1;h[f++]=t(b),k=f-1,p--;break;case 2:return x.join("")}if(p==0&&(p=Math.pow(2,S),S++),h[k])m=h[k];else if(k===f)m=v+v.charAt(0);else return null;x.push(m),h[f++]=v+m.charAt(0),p--,v=m,p==0&&(p=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})})(E0);var oJ=E0.exports;const Wj=ei(oJ);async function sJ(e,n,t){var y,v,b;const{elements:r,files:o}=n,s={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(E=>{if(c.set(E.id,$e()),E.boundElements!==null)for(const I of E.boundElements)I.type==="text"&&h.add(I.id)});let p=$4;for(const E of r){if(h.has(E.id))continue;const I=c.get(E.id),C={id:I,typeName:"shape",parentId:l,index:p,x:E.x,y:E.y,rotation:0,isLocked:E.locked,opacity:iJ(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]):u.push(I),E.type){case"rectangle":case"ellipse":case"diamond":{let k="",T="middle";if(E.boundElements!==null){for(const _ of E.boundElements)if(_.type==="text"){const A=r.find(L=>L.id===_.id);A&&(k=A.text,T=hJ[A.textAlign])}}const O=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:oh[E.strokeWidth]??"draw",color:hc[O]??"black",text:k,align:T,dash:sh(E),fill:gJ(E)}});break}case"freedraw":{s.shapes.push({...C,type:"draw",props:{dash:sh(E),size:oh[E.strokeWidth],color:hc[E.strokeColor]??"black",segments:[{type:"free",points:E.points.map(([k,T,O=.5])=>({x:k,y:T,z:O}))}]}});break}case"line":{if(E.points.slice().length<2)break;const T=Vc(E.points.length);s.shapes.push({...C,type:"line",props:{dash:sh(E),size:oh[E.strokeWidth],color:hc[E.strokeColor]??"black",spline:E.roundness?"cubic":"line",points:{...Object.fromEntries(E.points.map(([O,_],A)=>{const L=T[A];return[L,{id:L,index:L,x:O,y:_}]}))}}});break}case"arrow":{let k="";if(E.boundElements!==null){for(const L of E.boundElements)if(L.type==="text"){const j=r.find(R=>R.id===L.id);j&&(k=j.text)}}const T=E.points[0],O=E.points[E.points.length-1],_=c.get((v=E.startBinding)==null?void 0:v.elementId),A=c.get((b=E.endBinding)==null?void 0:b.elementId);s.shapes.push({...C,type:"arrow",props:{text:k,bend:fJ(E,T,O),dash:sh(E),size:oh[E.strokeWidth]??"m",color:hc[E.strokeColor]??"black",start:{x:T[0],y:T[1]},end:{x:O[0],y:O[1]},arrowheadEnd:zI[E.endArrowhead]??"none",arrowheadStart:zI[E.startArrowhead]??"none"}}),_&&s.bindings.push({id:Oi(),typeName:"binding",type:"arrow",fromId:I,toId:_,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),A&&s.bindings.push({id:Oi(),typeName:"binding",type:"arrow",fromId:I,toId:A,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:k,scale:T}=lJ(E.fontSize);s.shapes.push({...C,type:"text",props:{size:k,scale:T,font:cJ[E.fontFamily]??"draw",color:hc[E.strokeColor]??"black",text:E.text,textAlign:pJ[E.textAlign]}});break}case"image":{const k=o[E.fileId];if(!k)break;const T=Ci.createId();s.assets.push({id:T,typeName:"asset",type:"image",props:{w:E.width,h:E.height,fileSize:k.size,name:E.id??"Untitled",isAnimated:!1,mimeType:k.mimeType,src:k.dataURL},meta:{}}),s.shapes.push({...C,type:"image",props:{w:E.width,h:E.height,assetId:T}})}}p=$o(p)}const f=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:f,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&&_n(I.parentId)&&u.push(I.parentId)}for(const[E,I]of a)e.select(E),e.rotateShapesBy([E],I);const S=me(u.map(E=>e.getShape(E))),m=Z.Common(S.map(E=>e.getShapePageBounds(E))),x=e.getViewportPageBounds().center;e.updateShapes(S.map(E=>{const I={x:(E.x??0)-(m.x+m.w/2),y:(E.y??0)-(m.y+m.h/2)};return{id:E.id,type:E.type,x:x.x+I.x,y:x.y+I.y}})),e.setSelectedShapes(u)}const iJ=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},oh={1:"s",2:"m",3:"l",4:"xl"},aJ={16:"s",20:"m",28:"l",36:"xl"};function lJ(e){const n=aJ[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 cJ={1:"draw",2:"sans",3:"mono"},hc={"#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"},uJ={solid:"draw",dashed:"dashed",dotted:"dotted"},dJ={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},hJ={left:"start",center:"middle",right:"end"},pJ={left:"start",center:"middle",right:"end"},zI={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function fJ(e,n,t){let r=0;if(e.points.length>2){const o=new w(n[0],n[1]),s=new w(t[0],t[1]),i=new w(e.points[1][0],e.points[1][1]),a=w.Sub(s,o),l=w.Per(a),c=w.Med(s,o),u=w.Sub(c,l),h=w.Add(c,l),p=w.NearestPointOnLineSegment(u,h,i,!1);r=w.Dist(p,c),w.Clockwise(p,s,c)&&(r*=-1)}return r}const sh=e=>{let n=uJ[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},gJ=e=>e.backgroundColor==="transparent"?"none":dJ[e.fillStyle]??"solid";async function Gj(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await So(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 mJ(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 zv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await So(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),Gj(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 yJ(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const SJ=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},vJ=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 J_(n)},xJ=e=>/^<svg/.test(e),wJ=["input","select","textarea"];function by(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||wJ.indexOf(n.tagName.toLowerCase())>-1)}const bJ=e=>e.types.find(n=>n.match(/^image\//)),Py=(e,n,t,r)=>{const o=vJ(n);if(o)for(const s of o)zv(e,s,t);else SJ(n)?zv(e,n,t):xJ(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}))},PJ=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}}Yj(e,r,t)},Vj=async(e,n,t)=>{const r=[];for(const o of n){if(bJ(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 Ai.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Ai.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Ai.blobToText(s)})()})}return await Yj(e,r,t)};async function Yj(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 Gj(e,i,t)}const o=await Promise.all(n.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=Wj.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(h);if(p.type!=="application/tldraw"&&i({type:"error",data:p,reason:`found tldraw data comment but JSON was of a different type: ${p.type}`}),typeof p.data=="string"){i({type:"error",data:p,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:p.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){mJ(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){sJ(e,s.data,t);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");Py(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){Py(e,yJ(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){zv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){Py(e,s.data,t,o);return}}const xf=async e=>{var r;const n=await e.resolveAssetsInContent(e.getContentFromCurrentPage(e.getSelectedShapeIds()));if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=Wj.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(V4);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<div data-tldraw>${t}</div>`],{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(`<div data-tldraw>${t}</div>`)}};function CJ(){const e=B(),n=Zr(),t=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await xf(e),n("copy",{source:i}))},[e,n]),r=P.useCallback(async function(i){e.getSelectedShapeIds().length!==0&&(await xf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=P.useCallback(async function(i,a,l){e.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(Vj(e,i,l),n("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[e,n]);return{copy:t,cut:r,paste:o}}function IJ(){const e=B(),n=Zr(),t=G("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!t)return;const r=async l=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||by(e)||(Ee(l),await xf(e),n("copy",{source:"kbd"}))};async function o(l){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||by(e)||(Ee(l),await xf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,e.timers.requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){Ht(l);return}e.getEditingShapeId()!==null||by(e)||(l.clipboardData&&!e.inputs.shiftKey?PJ(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&Vj(e,c,e.inputs.currentPagePoint)}),Ee(l),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 Xj(e,n,t){const{type:r,quality:o,scale:s,width:i,height:a}=t;let[l,c]=await aY(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,h=URL.createObjectURL(new Blob([n],{type:"image/svg+xml"})),p=await new Promise(S=>{const m=il();m.crossOrigin="anonymous",m.onload=async()=>{e.environment.isSafari&&await new Promise(v=>e.timers.setTimeout(v,250));const x=document.createElement("canvas"),y=x.getContext("2d");x.width=l,x.height=c,y.imageSmoothingEnabled=!0,y.imageSmoothingQuality="high",y.drawImage(m,0,0,l,c),URL.revokeObjectURL(h),S(x)},m.onerror=()=>{S(null)},m.src=h});if(!p)return null;const f=await new Promise(S=>p.toBlob(m=>{(!m||xt.throwToBlob.get())&&S(null),S(m)},"image/"+r,o));if(!f)return null;if(r==="png"){const S=new DataView(await f.arrayBuffer());return so.setPhysChunk(S,u,{type:"image/"+r})}else return f}async function qj(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 Bv(e,n,t,r={}){var o;switch(t){case"svg":return(o=await qj(e,n,r))==null?void 0:o.svg;case"json":{const s=await e.resolveAssetsInContent(e.getContentFromCurrentPage(n));return JSON.stringify(s)}default:an(t)}}async function Zj({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await Bv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await Bv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await qj(e,n,r);if(!o)throw new Error("Could not construct image.");const s=await Xj(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:an(t)}}const EJ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function kJ(e,n,t,r={}){return{blobPromise:Zj({editor:e,ids:n,format:t,opts:r}),mimeType:EJ[t]}}function _J(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}=kJ(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 TJ(async()=>Bv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:an(t)}}async function TJ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}function MJ(){const e=B(),{addToast:n}=Qr(),t=Te();return P.useCallback((r,o="svg")=>{_J(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 AJ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${BI()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${BI()}`}r+=`.${t}`;const s=await Zj({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});jJ(i)}function BI(){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 jJ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function OJ(){const e=B(),{addToast:n}=Qr(),t=Te();return P.useCallback((r,o="png",s)=>{AJ(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 DJ(e,n,t){const r=me(n.map(a=>{const l=e.getShape(a);if(!(!l||e.getShapeUtil(l.type).toSvg===void 0))return l}));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(l=>({shape:l,bounds:e.getShapeMaskedPageBounds(l).clone().expandBy(t)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){o[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of o)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||o.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>e.getShapeMaskedPageBounds(l)));o.push({shapes:r,bounds:a})}const s=e.options.flattenImageBoundsPadding;for(const a of o){t!==void 0&&a.bounds.expandBy(-t);const l=await e.getSvgString(a.shapes,{padding:s});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),u=await e.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return js(()=>{for(const a of o){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=e.findCommonAncestor(u)??e.getCurrentPageId();if(!h)continue;let p="a1";for(const y of u)if(y.parentId===h){y.index>p&&(p=y.index);break}let f,S,m;if(_n(h)){const y=e.getShape(h);if(!y)continue;const v=e.getPointInShapeSpace(y,{x:c.x,y:c.y});m=e.getShapePageTransform(h).rotation(),v.sub(new w(s,s).rot(-m)),f=v.x,S=v.y}else f=c.x-s,S=c.y-s,m=0;e.deleteShapes(u),e.createAssets([{...l,id:l.id}]);const x=$e();e.createShape({id:x,type:"image",index:p,parentId:h,x:f,y:S,rotation:-m,props:{assetId:l.id,w:c.w+s*2,h:c.h+s*2}}),i.push(x)}}),i}function RJ(){const e=B(),n=P.useRef(null),t=P.useRef(null);return P.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-${ot()}`;o.className=a,s.innerHTML=`
|
|
203
|
-
.${a} {
|
|
204
|
-
display: none;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
.${a} svg {
|
|
208
|
-
max-width: 100%;
|
|
209
|
-
height: 100%;
|
|
210
|
-
display: block;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
@media print {
|
|
214
|
-
html, body {
|
|
215
|
-
min-height: 100%;
|
|
216
|
-
height: 100%;
|
|
217
|
-
margin: 0;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
body {
|
|
221
|
-
position: relative;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
body > * {
|
|
225
|
-
display: none;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
.tldraw__editor {
|
|
229
|
-
display: none;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
.${a} {
|
|
233
|
-
display: block !important;
|
|
234
|
-
background: white;
|
|
235
|
-
min-height: 100%;
|
|
236
|
-
height: 100%;
|
|
237
|
-
max-width: 100%;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
.${a}__item {
|
|
241
|
-
padding: 10mm;
|
|
242
|
-
display: flex;
|
|
243
|
-
min-height: 100%;
|
|
244
|
-
flex-direction: column;
|
|
245
|
-
page-break-after: always;
|
|
246
|
-
position: relative;
|
|
247
|
-
overflow: hidden;
|
|
248
|
-
height: 100%;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
.${a}__item__main {
|
|
252
|
-
flex: 1;
|
|
253
|
-
display: flex;
|
|
254
|
-
align-items: center;
|
|
255
|
-
justify-content: center;
|
|
256
|
-
max-height: 100%;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
.${a}__item__header {
|
|
260
|
-
display: none;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
.${a}__item__footer {
|
|
264
|
-
display: none;
|
|
265
|
-
text-align: right;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
.${a}__item__footer__hide {
|
|
269
|
-
display: none;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
`;const l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{e.once("tick",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(y,v,b){try{o.innerHTML+=`<div class="${a}__item">
|
|
276
|
-
<div class="${a}__item__header">
|
|
277
|
-
${y.replace(/</g,"<").replace(/>/g,">")}
|
|
278
|
-
</div>
|
|
279
|
-
<div class="${a}__item__main">
|
|
280
|
-
${b}
|
|
281
|
-
</div>
|
|
282
|
-
<div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
|
|
283
|
-
${v??""}
|
|
284
|
-
</div>
|
|
285
|
-
</div>`}catch(E){console.error(E)}}function h(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=e.getSelectedShapeIds(),f=e.getCurrentPageId(),S=e.getPages(),x={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const y=await e.getSvgString(p,x);if(y){const v=S.find(b=>b.id===f);u(`tldraw — ${v==null?void 0:v.name}`,null,y.svg),h()}}else{const y=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(y.id),x);v&&(u(`tldraw — ${y.name}`,null,v.svg),h())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const Qj=P.createContext(null);function LJ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function ba(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function $J({overrides:e,children:n}){const t=B(),{addDialog:r,clearDialogs:o}=la(),{clearToasts:s}=Qr(),i=Te(),a=Bj(),l=RJ(),{cut:c,copy:u,paste:h}=CJ(),p=MJ(),f=OJ(),S=i("document.default-name"),m=Zr(),x=P.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=LJ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(I){v()&&(y()||(m("edit-link",{source:I}),t.mark("edit-link"),r({component:nJ})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(I){m("insert-embed",{source:I}),r({component:zj})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(I){m("insert-media",{source:I}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(I){m("undo",{source:I}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(I){m("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&&(m("export-as",{format:"svg",source:I}),f(C,"svg",ba(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&&(m("export-as",{format:"png",source:I}),f(C,"png",ba(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&&(m("export-as",{format:"json",source:I}),f(C,"json",ba(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&&(m("export-all-as",{format:"svg",source:I}),f(Array.from(t.getCurrentPageShapeIds()),"svg",ba(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&&(m("export-all-as",{format:"png",source:I}),f(C,"png",ba(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&&(m("export-all-as",{format:"json",source:I}),f(C,"json",ba(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&&(m("copy-as",{format:"svg",source:I}),p(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&&(m("copy-as",{format:"png",source:I}),p(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&&(m("copy-as",{format:"json",source:I}),p(C,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(I){if(!v()||y())return;m("toggle-auto-size",{source:I}),t.mark("toggling auto size");const C=t.getSelectedShapes().filter(k=>t.isShapeOfType(k,"text")&&k.props.autoSize===!1);t.updateShapes(C.map(k=>({id:k.id,type:k.type,props:{...k.props,w:8,autoSize:!0}}))),Ke(t,C.map(k=>k.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(I){m("open-embed-link",{source:I});const C=t.getSelectedShapeIds(),k="No embed shapes selected";if(C.length!==1){console.error(k);return}const T=t.getShape(C[0]);if(!T||!t.isShapeOfType(T,"embed")){console.error(k);return}CV(T.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(I){var C,k;if(((C=t.root.getCurrent())==null?void 0:C.id)!=="zoom"&&(m("zoom-tool",{source:I}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const T=t.root.getCurrent();T&&((k=T.getCurrent())==null?void 0:k.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:T.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(I){v()&&(y()||t.batch(()=>{m("convert-to-bookmark",{source:I});const C=t.getSelectedShapes(),k=[],T=[];for(const O of C){if(!O||!t.isShapeOfType(O,"embed")||!O.props.url)continue;const _=new w(O.x,O.y);_.rot(-O.rotation),_.add(new w(O.props.w/2-300/2,O.props.h/2-320/2)),_.rot(O.rotation);const A={id:$e(),type:"bookmark",rotation:O.rotation,x:_.x,y:_.y,opacity:1,props:{url:O.props.url}};k.push(A),T.push(O.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(T),t.createShapes(k)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(I){v()&&(y()||(m("convert-to-embed",{source:I}),t.batch(()=>{const C=t.getSelectedShapeIds(),k=me(C.map(_=>t.getShape(_))),T=[],O=[];for(const _ of k){if(!t.isShapeOfType(_,"bookmark"))continue;const{url:A}=_.props,L=As(_.props.url);if(!L||!L.definition)continue;const{width:j,height:R}=L.definition,F=new w(_.x,_.y);F.rot(-_.rotation),F.add(new w(_.props.w/2-j/2,_.props.h/2-R/2)),F.rot(_.rotation);const W={id:$e(),type:"embed",x:F.x,y:F.y,rotation:_.rotation,props:{url:A,w:j,h:R}};T.push(W),O.push(_.id)}t.mark("convert shapes to embed"),t.deleteShapes(O),t.createShapes(T)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(I){if(!v()||y())return;m("duplicate-shapes",{source:I});const C=t.getInstanceState();let k,T;if(C.duplicateProps)k=C.duplicateProps.shapeIds,T=C.duplicateProps.offset;else{k=t.getSelectedShapeIds();const O=Z.Common(me(k.map(_=>t.getShapePageBounds(_))));T=t.getCameraOptions().isLocked?{x:20,y:20}:{x:O.width+20,y:0}}t.mark("duplicate shapes"),t.duplicateShapes(k,T),C.duplicateProps&&t.updateInstanceState({duplicateProps:{...C.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(I){v()&&(y()||(m("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;m("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;m("remove-frame",{source:I});const C=t.getSelectedShapes();C.length>0&&C.every(k=>t.isShapeOfType(k,"frame"))&&(t.mark("remove-frame"),JQ(t,C.map(k=>k.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(I){if(!v())return;m("fit-frame-to-content",{source:I});const C=t.getOnlySelectedShape();C&&t.isShapeOfType(C,"frame")&&(t.mark("fit-frame-to-content"),tJ(t,C.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(I){if(!v()||y())return;m("align-shapes",{operation:"left",source:I}),t.mark("align left");const C=t.getSelectedShapeIds();t.alignShapes(C,"left"),Ke(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;m("align-shapes",{operation:"center-horizontal",source:I}),t.mark("align center horizontal");const C=t.getSelectedShapeIds();t.alignShapes(C,"center-horizontal"),Ke(t,C)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(I){if(!v()||y())return;m("align-shapes",{operation:"right",source:I}),t.mark("align right");const C=t.getSelectedShapeIds();t.alignShapes(C,"right"),Ke(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;m("align-shapes",{operation:"center-vertical",source:I}),t.mark("align center vertical");const C=t.getSelectedShapeIds();t.alignShapes(C,"center-vertical"),Ke(t,C)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(I){if(!v()||y())return;m("align-shapes",{operation:"top",source:I}),t.mark("align top");const C=t.getSelectedShapeIds();t.alignShapes(C,"top"),Ke(t,C)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(I){if(!v()||y())return;m("align-shapes",{operation:"bottom",source:I}),t.mark("align bottom");const C=t.getSelectedShapeIds();t.alignShapes(C,"bottom"),Ke(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;m("distribute-shapes",{operation:"horizontal",source:I}),t.mark("distribute horizontal");const C=t.getSelectedShapeIds();t.distributeShapes(C,"horizontal"),Ke(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;m("distribute-shapes",{operation:"vertical",source:I}),t.mark("distribute vertical");const C=t.getSelectedShapeIds();t.distributeShapes(C,"vertical"),Ke(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;m("stretch-shapes",{operation:"horizontal",source:I}),t.mark("stretch horizontal");const C=t.getSelectedShapeIds();t.stretchShapes(C,"horizontal"),Ke(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;m("stretch-shapes",{operation:"vertical",source:I}),t.mark("stretch vertical");const C=t.getSelectedShapeIds();t.stretchShapes(C,"vertical"),Ke(t,C)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(I){if(!v()||y())return;m("flip-shapes",{operation:"horizontal",source:I}),t.mark("flip horizontal");const C=t.getSelectedShapeIds();t.flipShapes(C,"horizontal"),Ke(t,C)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(I){if(!v()||y())return;m("flip-shapes",{operation:"vertical",source:I}),t.mark("flip vertical");const C=t.getSelectedShapeIds();t.flipShapes(C,"vertical"),Ke(t,C)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(I){if(!v()||y())return;m("pack-shapes",{source:I}),t.mark("pack");const C=t.getSelectedShapeIds();t.packShapes(C,t.options.adjacentShapeMargin),Ke(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;m("stack-shapes",{operation:"vertical",source:I}),t.mark("stack-vertical");const C=t.getSelectedShapeIds();t.stackShapes(C,"vertical",16),Ke(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;m("stack-shapes",{operation:"horizontal",source:I}),t.mark("stack-horizontal");const C=t.getSelectedShapeIds();t.stackShapes(C,"horizontal",16),Ke(t,C)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(I){v()&&(y()||(m("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()||(m("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()||(m("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()||(m("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"),c(I)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(I){v()&&(y()||u(I))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(I){var C;(C=navigator.clipboard)==null||C.read().then(k=>{h(k,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()||(m("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()||(m("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()||(m("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;m("rotate-cw",{source:I}),t.mark("rotate-cw");const C=t.getSelectionRotation()%(Ge/2),k=Ds(C,0)||Ds(C,Ge/2),T=t.getSelectedShapeIds();t.rotateShapesBy(T,Ge/2-(k?0:C)),Ke(t,T)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(I){if(!v()||y())return;m("rotate-ccw",{source:I}),t.mark("rotate-ccw");const C=t.getSelectionRotation()%(Ge/2),k=Ds(C,0),T=t.getSelectedShapeIds();t.rotateShapesBy(T,k?-(Ge/2):-C),Ke(t,T)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(I){m("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){m("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){m("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){m("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()||(m("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){m("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";m("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){m("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){m("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){m("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){m("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){m("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){m("toggle-tool-lock",{source:I}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(I){m("unlock-all",{source:I});const C=[];for(const k of t.getCurrentPageShapes())k.isLocked&&C.push({id:k.id,type:k.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(()=>{m("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){m("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){m("toggle-debug-mode",{source:I}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(I){m("print",{source:I}),l()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(I){m("exit-pen-mode",{source:I}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(I){m("stop-following",{source:I}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(I){m("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"),m("toggle-lock",{source:I}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(I){const C=Xo.createId(),k=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:i("page-menu.new-page-initial-name"),id:C}),t.moveShapesToPage(k,C)}),m("new-page",{source:I})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(I){const C=sr;t.batch(()=>{t.mark("change-color"),t.isIn("select")&&t.setStyleForSelectedShapes(C,"white"),t.setStyleForNextShapes(C,"white")}),m("set-style",{source:I,id:C.id,value:"white"})}},{id:"select-fill-fill",label:"fill-style.fill",kbd:"?f",onSelect(I){const C=zi;t.batch(()=>{t.mark("change-fill"),t.isIn("select")&&t.setStyleForSelectedShapes(C,"fill"),t.setStyleForNextShapes(C,"fill")}),m("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"),m("flatten-to-image",{source:I});const k=await DJ(t,C,t.options.flattenImageBoundsExpand);k!=null&&k.length&&t.setSelectedShapes(k)}}]);return e?e(t,E,void 0):E},[t,m,e,r,a,f,p,c,u,h,o,s,l,i,S]);return d.jsx(Qj.Provider,{value:x,children:n})}function ie(){const e=P.useContext(Qj);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function mu(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const FJ=["top","right","bottom","left"],ho=Math.min,qn=Math.max,wf=Math.round,ih=Math.floor,Zs=e=>({x:e,y:e}),NJ={left:"right",right:"left",bottom:"top",top:"bottom"},zJ={start:"end",end:"start"};function Uv(e,n,t){return qn(e,ho(n,t))}function ts(e,n){return typeof e=="function"?e(n):e}function ns(e){return e.split("-")[0]}function Fl(e){return e.split("-")[1]}function k0(e){return e==="x"?"y":"x"}function _0(e){return e==="y"?"height":"width"}function Qs(e){return["top","bottom"].includes(ns(e))?"y":"x"}function T0(e){return k0(Qs(e))}function BJ(e,n,t){t===void 0&&(t=!1);const r=Fl(e),o=T0(e),s=_0(o);let i=o==="x"?r===(t?"end":"start")?"right":"left":r==="start"?"bottom":"top";return n.reference[s]>n.floating[s]&&(i=bf(i)),[i,bf(i)]}function UJ(e){const n=bf(e);return[Hv(e),n,Hv(n)]}function Hv(e){return e.replace(/start|end/g,n=>zJ[n])}function HJ(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 KJ(e,n,t,r){const o=Fl(e);let s=HJ(ns(e),t==="start",r);return o&&(s=s.map(i=>i+"-"+o),n&&(s=s.concat(s.map(Hv)))),s}function bf(e){return e.replace(/left|right|bottom|top/g,n=>NJ[n])}function WJ(e){return{top:0,right:0,bottom:0,left:0,...e}}function Jj(e){return typeof e!="number"?WJ(e):{top:e,right:e,bottom:e,left:e}}function Pf(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 UI(e,n,t){let{reference:r,floating:o}=e;const s=Qs(n),i=T0(n),a=_0(i),l=ns(n),c=s==="y",u=r.x+r.width/2-o.width/2,h=r.y+r.height/2-o.height/2,p=r[a]/2-o[a]/2;let f;switch(l){case"top":f={x:u,y:r.y-o.height};break;case"bottom":f={x:u,y:r.y+r.height};break;case"right":f={x:r.x+r.width,y:h};break;case"left":f={x:r.x-o.width,y:h};break;default:f={x:r.x,y:r.y}}switch(Fl(n)){case"start":f[i]-=p*(t&&c?-1:1);break;case"end":f[i]+=p*(t&&c?-1:1);break}return f}const GJ=async(e,n,t)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=t,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(n));let c=await i.getElementRects({reference:e,floating:n,strategy:o}),{x:u,y:h}=UI(c,r,l),p=r,f={},S=0;for(let m=0;m<a.length;m++){const{name:x,fn:y}=a[m],{x:v,y:b,data:E,reset:I}=await y({x:u,y:h,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:n}});u=v??u,h=b??h,f={...f,[x]:{...f[x],...E}},I&&S<=50&&(S++,typeof I=="object"&&(I.placement&&(p=I.placement),I.rects&&(c=I.rects===!0?await i.getElementRects({reference:e,floating:n,strategy:o}):I.rects),{x:u,y:h}=UI(c,p,l)),m=-1)}return{x:u,y:h,placement:p,strategy:o,middlewareData:f}};async function yu(e,n){var t;n===void 0&&(n={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:p=!1,padding:f=0}=ts(n,e),S=Jj(f),x=a[p?h==="floating"?"reference":"floating":h],y=Pf(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(x)))==null||t?x:x.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),v=h==="floating"?{x:r,y:o,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),E=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},I=Pf(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:b,strategy:l}):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 VJ=e=>({name:"arrow",options:e,async fn(n){const{x:t,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=n,{element:c,padding:u=0}=ts(e,n)||{};if(c==null)return{};const h=Jj(u),p={x:t,y:r},f=T0(o),S=_0(f),m=await i.getDimensions(c),x=f==="y",y=x?"top":"left",v=x?"bottom":"right",b=x?"clientHeight":"clientWidth",E=s.reference[S]+s.reference[f]-p[f]-s.floating[S],I=p[f]-s.reference[f],C=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let k=C?C[b]:0;(!k||!await(i.isElement==null?void 0:i.isElement(C)))&&(k=a.floating[b]||s.floating[S]);const T=E/2-I/2,O=k/2-m[S]/2-1,_=ho(h[y],O),A=ho(h[v],O),L=_,j=k-m[S]-A,R=k/2-m[S]/2+T,F=Uv(L,R,j),W=!l.arrow&&Fl(o)!=null&&R!==F&&s.reference[S]/2-(R<L?_:A)-m[S]/2<0,K=W?R<L?R-L:R-j:0;return{[f]:p[f]+K,data:{[f]:F,centerOffset:R-F-K,...W&&{alignmentOffset:K}},reset:W}}}),YJ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(n){var t,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=n,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:S="none",flipAlignment:m=!0,...x}=ts(e,n);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const y=ns(o),v=Qs(a),b=ns(a)===a,E=await(l.isRTL==null?void 0:l.isRTL(c.floating)),I=p||(b||!m?[bf(a)]:UJ(a)),C=S!=="none";!p&&C&&I.push(...KJ(a,m,S,E));const k=[a,...I],T=await yu(n,x),O=[];let _=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&O.push(T[y]),h){const R=BJ(o,i,E);O.push(T[R[0]],T[R[1]])}if(_=[..._,{placement:o,overflows:O}],!O.every(R=>R<=0)){var A,L;const R=(((A=s.flip)==null?void 0:A.index)||0)+1,F=k[R];if(F)return{data:{index:R,overflows:_},reset:{placement:F}};let W=(L=_.filter(K=>K.overflows[0]<=0).sort((K,z)=>K.overflows[1]-z.overflows[1])[0])==null?void 0:L.placement;if(!W)switch(f){case"bestFit":{var j;const K=(j=_.filter(z=>{if(C){const U=Qs(z.placement);return U===v||U==="y"}return!0}).map(z=>[z.placement,z.overflows.filter(U=>U>0).reduce((U,X)=>U+X,0)]).sort((z,U)=>z[1]-U[1])[0])==null?void 0:j[0];K&&(W=K);break}case"initialPlacement":W=a;break}if(o!==W)return{reset:{placement:W}}}return{}}}};function HI(e,n){return{top:e.top-n.height,right:e.right-n.width,bottom:e.bottom-n.height,left:e.left-n.width}}function KI(e){return FJ.some(n=>e[n]>=0)}const XJ=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 yu(n,{...o,elementContext:"reference"}),i=HI(s,t.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:KI(i)}}}case"escaped":{const s=await yu(n,{...o,altBoundary:!0}),i=HI(s,t.floating);return{data:{escapedOffsets:i,escaped:KI(i)}}}default:return{}}}}};async function qJ(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=Fl(t),l=Qs(t)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,h=ts(n,e);let{mainAxis:p,crossAxis:f,alignmentAxis:S}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...h};return a&&typeof S=="number"&&(f=a==="end"?S*-1:S),l?{x:f*u,y:p*c}:{x:p*c,y:f*u}}const ZJ=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(n){var t,r;const{x:o,y:s,placement:i,middlewareData:a}=n,l=await qJ(n,e);return i===((t=a.offset)==null?void 0:t.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},QJ=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:x=>{let{x:y,y:v}=x;return{x:y,y:v}}},...l}=ts(e,n),c={x:t,y:r},u=await yu(n,l),h=Qs(ns(o)),p=k0(h);let f=c[p],S=c[h];if(s){const x=p==="y"?"top":"left",y=p==="y"?"bottom":"right",v=f+u[x],b=f-u[y];f=Uv(v,f,b)}if(i){const x=h==="y"?"top":"left",y=h==="y"?"bottom":"right",v=S+u[x],b=S-u[y];S=Uv(v,S,b)}const m=a.fn({...n,[p]:f,[h]:S});return{...m,data:{x:m.x-t,y:m.y-r}}}}},JJ=function(e){return e===void 0&&(e={}),{options:e,fn(n){const{x:t,y:r,placement:o,rects:s,middlewareData:i}=n,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=ts(e,n),u={x:t,y:r},h=Qs(o),p=k0(h);let f=u[p],S=u[h];const m=ts(a,n),x=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=p==="y"?"height":"width",E=s.reference[p]-s.floating[b]+x.mainAxis,I=s.reference[p]+s.reference[b]-x.mainAxis;f<E?f=E:f>I&&(f=I)}if(c){var y,v;const b=p==="y"?"width":"height",E=["top","left"].includes(ns(o)),I=s.reference[h]-s.floating[b]+(E&&((y=i.offset)==null?void 0:y[h])||0)+(E?0:x.crossAxis),C=s.reference[h]+s.reference[b]+(E?0:((v=i.offset)==null?void 0:v[h])||0)-(E?x.crossAxis:0);S<I?S=I:S>C&&(S=C)}return{[p]:f,[h]:S}}}},eee=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),l=await yu(n,a),c=ns(t),u=Fl(t),h=Qs(t)==="y",{width:p,height:f}=r.floating;let S,m;c==="top"||c==="bottom"?(S=c,m=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(m=c,S=u==="end"?"top":"bottom");const x=f-l.top-l.bottom,y=p-l.left-l.right,v=ho(f-l[S],x),b=ho(p-l[m],y),E=!n.middlewareData.shift;let I=v,C=b;if(h?C=u||E?ho(b,y):y:I=u||E?ho(v,x):x,E&&!u){const T=qn(l.left,0),O=qn(l.right,0),_=qn(l.top,0),A=qn(l.bottom,0);h?C=p-2*(T!==0||O!==0?T+O:qn(l.left,l.right)):I=f-2*(_!==0||A!==0?_+A:qn(l.top,l.bottom))}await i({...n,availableWidth:C,availableHeight:I});const k=await o.getDimensions(s.floating);return p!==k.width||f!==k.height?{reset:{rects:!0}}:{}}}};function Nl(e){return eO(e)?(e.nodeName||"").toLowerCase():"#document"}function rr(e){var n;return(e==null||(n=e.ownerDocument)==null?void 0:n.defaultView)||window}function ls(e){var n;return(n=(eO(e)?e.ownerDocument:e.document)||window.document)==null?void 0:n.documentElement}function eO(e){return e instanceof Node||e instanceof rr(e).Node}function bo(e){return e instanceof Element||e instanceof rr(e).Element}function Po(e){return e instanceof HTMLElement||e instanceof rr(e).HTMLElement}function WI(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof rr(e).ShadowRoot}function Vu(e){const{overflow:n,overflowX:t,overflowY:r,display:o}=Wr(e);return/auto|scroll|overlay|hidden|clip/.test(n+r+t)&&!["inline","contents"].includes(o)}function tee(e){return["table","td","th"].includes(Nl(e))}function Eg(e){return[":popover-open",":modal"].some(n=>{try{return e.matches(n)}catch{return!1}})}function M0(e){const n=A0(),t=Wr(e);return t.transform!=="none"||t.perspective!=="none"||(t.containerType?t.containerType!=="normal":!1)||!n&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!n&&(t.filter?t.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(t.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(t.contain||"").includes(r))}function nee(e){let n=Js(e);for(;Po(n)&&!Pl(n);){if(Eg(n))return null;if(M0(n))return n;n=Js(n)}return null}function A0(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Pl(e){return["html","body","#document"].includes(Nl(e))}function Wr(e){return rr(e).getComputedStyle(e)}function kg(e){return bo(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function Js(e){if(Nl(e)==="html")return e;const n=e.assignedSlot||e.parentNode||WI(e)&&e.host||ls(e);return WI(n)?n.host:n}function tO(e){const n=Js(e);return Pl(n)?e.ownerDocument?e.ownerDocument.body:e.body:Po(n)&&Vu(n)?n:tO(n)}function Su(e,n,t){var r;n===void 0&&(n=[]),t===void 0&&(t=!0);const o=tO(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=rr(o);return s?n.concat(i,i.visualViewport||[],Vu(o)?o:[],i.frameElement&&t?Su(i.frameElement):[]):n.concat(o,Su(o,[],t))}function nO(e){const n=Wr(e);let t=parseFloat(n.width)||0,r=parseFloat(n.height)||0;const o=Po(e),s=o?e.offsetWidth:t,i=o?e.offsetHeight:r,a=wf(t)!==s||wf(r)!==i;return a&&(t=s,r=i),{width:t,height:r,$:a}}function j0(e){return bo(e)?e:e.contextElement}function sl(e){const n=j0(e);if(!Po(n))return Zs(1);const t=n.getBoundingClientRect(),{width:r,height:o,$:s}=nO(n);let i=(s?wf(t.width):t.width)/r,a=(s?wf(t.height):t.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const ree=Zs(0);function rO(e){const n=rr(e);return!A0()||!n.visualViewport?ree:{x:n.visualViewport.offsetLeft,y:n.visualViewport.offsetTop}}function oee(e,n,t){return n===void 0&&(n=!1),!t||n&&t!==rr(e)?!1:n}function Zi(e,n,t,r){n===void 0&&(n=!1),t===void 0&&(t=!1);const o=e.getBoundingClientRect(),s=j0(e);let i=Zs(1);n&&(r?bo(r)&&(i=sl(r)):i=sl(e));const a=oee(s,t,r)?rO(s):Zs(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,h=o.height/i.y;if(s){const p=rr(s),f=r&&bo(r)?rr(r):r;let S=p,m=S.frameElement;for(;m&&r&&f!==S;){const x=sl(m),y=m.getBoundingClientRect(),v=Wr(m),b=y.left+(m.clientLeft+parseFloat(v.paddingLeft))*x.x,E=y.top+(m.clientTop+parseFloat(v.paddingTop))*x.y;l*=x.x,c*=x.y,u*=x.x,h*=x.y,l+=b,c+=E,S=rr(m),m=S.frameElement}}return Pf({width:u,height:h,x:l,y:c})}function see(e){let{elements:n,rect:t,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=ls(r),a=n?Eg(n.floating):!1;if(r===i||a&&s)return t;let l={scrollLeft:0,scrollTop:0},c=Zs(1);const u=Zs(0),h=Po(r);if((h||!h&&!s)&&((Nl(r)!=="body"||Vu(i))&&(l=kg(r)),Po(r))){const p=Zi(r);c=sl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}return{width:t.width*c.x,height:t.height*c.y,x:t.x*c.x-l.scrollLeft*c.x+u.x,y:t.y*c.y-l.scrollTop*c.y+u.y}}function iee(e){return Array.from(e.getClientRects())}function oO(e){return Zi(ls(e)).left+kg(e).scrollLeft}function aee(e){const n=ls(e),t=kg(e),r=e.ownerDocument.body,o=qn(n.scrollWidth,n.clientWidth,r.scrollWidth,r.clientWidth),s=qn(n.scrollHeight,n.clientHeight,r.scrollHeight,r.clientHeight);let i=-t.scrollLeft+oO(e);const a=-t.scrollTop;return Wr(r).direction==="rtl"&&(i+=qn(n.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function lee(e,n){const t=rr(e),r=ls(e),o=t.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const c=A0();(!c||c&&n==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function cee(e,n){const t=Zi(e,!0,n==="fixed"),r=t.top+e.clientTop,o=t.left+e.clientLeft,s=Po(e)?sl(e):Zs(1),i=e.clientWidth*s.x,a=e.clientHeight*s.y,l=o*s.x,c=r*s.y;return{width:i,height:a,x:l,y:c}}function GI(e,n,t){let r;if(n==="viewport")r=lee(e,t);else if(n==="document")r=aee(ls(e));else if(bo(n))r=cee(n,t);else{const o=rO(e);r={...n,x:n.x-o.x,y:n.y-o.y}}return Pf(r)}function sO(e,n){const t=Js(e);return t===n||!bo(t)||Pl(t)?!1:Wr(t).position==="fixed"||sO(t,n)}function uee(e,n){const t=n.get(e);if(t)return t;let r=Su(e,[],!1).filter(a=>bo(a)&&Nl(a)!=="body"),o=null;const s=Wr(e).position==="fixed";let i=s?Js(e):e;for(;bo(i)&&!Pl(i);){const a=Wr(i),l=M0(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Vu(i)&&!l&&sO(e,i))?r=r.filter(u=>u!==i):o=a,i=Js(i)}return n.set(e,r),r}function dee(e){let{element:n,boundary:t,rootBoundary:r,strategy:o}=e;const i=[...t==="clippingAncestors"?Eg(n)?[]:uee(n,this._c):[].concat(t),r],a=i[0],l=i.reduce((c,u)=>{const h=GI(n,u,o);return c.top=qn(h.top,c.top),c.right=ho(h.right,c.right),c.bottom=ho(h.bottom,c.bottom),c.left=qn(h.left,c.left),c},GI(n,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function hee(e){const{width:n,height:t}=nO(e);return{width:n,height:t}}function pee(e,n,t){const r=Po(n),o=ls(n),s=t==="fixed",i=Zi(e,!0,s,n);let a={scrollLeft:0,scrollTop:0};const l=Zs(0);if(r||!r&&!s)if((Nl(n)!=="body"||Vu(o))&&(a=kg(n)),r){const h=Zi(n,!0,s,n);l.x=h.x+n.clientLeft,l.y=h.y+n.clientTop}else o&&(l.x=oO(o));const c=i.left+a.scrollLeft-l.x,u=i.top+a.scrollTop-l.y;return{x:c,y:u,width:i.width,height:i.height}}function Cy(e){return Wr(e).position==="static"}function VI(e,n){return!Po(e)||Wr(e).position==="fixed"?null:n?n(e):e.offsetParent}function iO(e,n){const t=rr(e);if(Eg(e))return t;if(!Po(e)){let o=Js(e);for(;o&&!Pl(o);){if(bo(o)&&!Cy(o))return o;o=Js(o)}return t}let r=VI(e,n);for(;r&&tee(r)&&Cy(r);)r=VI(r,n);return r&&Pl(r)&&Cy(r)&&!M0(r)?t:r||nee(e)||t}const fee=async function(e){const n=this.getOffsetParent||iO,t=this.getDimensions,r=await t(e.floating);return{reference:pee(e.reference,await n(e.floating),e.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function gee(e){return Wr(e).direction==="rtl"}const mee={convertOffsetParentRelativeRectToViewportRelativeRect:see,getDocumentElement:ls,getClippingRect:dee,getOffsetParent:iO,getElementRects:fee,getClientRects:iee,getDimensions:hee,getScale:sl,isElement:bo,isRTL:gee};function yee(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,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const{left:c,top:u,width:h,height:p}=e.getBoundingClientRect();if(a||n(),!h||!p)return;const f=ih(u),S=ih(o.clientWidth-(c+h)),m=ih(o.clientHeight-(u+p)),x=ih(c),v={rootMargin:-f+"px "+-S+"px "+-m+"px "+-x+"px",threshold:qn(0,ho(1,l))||1};let b=!0;function E(I){const C=I[0].intersectionRatio;if(C!==l){if(!b)return i();C?i(!1,C):r=setTimeout(()=>{i(!1,1e-7)},1e3)}b=!1}try{t=new IntersectionObserver(E,{...v,root:o.ownerDocument})}catch{t=new IntersectionObserver(E,v)}t.observe(e)}return i(!0),s}function See(e,n,t,r){r===void 0&&(r={});const{ancestorScroll:o=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=j0(e),u=o||s?[...c?Su(c):[],...Su(n)]:[];u.forEach(y=>{o&&y.addEventListener("scroll",t,{passive:!0}),s&&y.addEventListener("resize",t)});const h=c&&a?yee(c,t):null;let p=-1,f=null;i&&(f=new ResizeObserver(y=>{let[v]=y;v&&v.target===c&&f&&(f.unobserve(n),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=f)==null||b.observe(n)})),t()}),c&&!l&&f.observe(c),f.observe(n));let S,m=l?Zi(e):null;l&&x();function x(){const y=Zi(e);m&&(y.x!==m.x||y.y!==m.y||y.width!==m.width||y.height!==m.height)&&t(),m=y,S=requestAnimationFrame(x)}return t(),()=>{var y;u.forEach(v=>{o&&v.removeEventListener("scroll",t),s&&v.removeEventListener("resize",t)}),h==null||h(),(y=f)==null||y.disconnect(),f=null,l&&cancelAnimationFrame(S)}}const vee=ZJ,xee=QJ,wee=YJ,bee=eee,Pee=XJ,YI=VJ,Cee=JJ,Iee=(e,n,t)=>{const r=new Map,o={platform:mee,...t},s={...o.platform,_c:r};return GJ(e,n,{...o,platform:s})};var hp=typeof document<"u"?P.useLayoutEffect:P.useEffect;function Cf(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(!Cf(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)&&!Cf(e[s],n[s]))return!1}return!0}return e!==e&&n!==n}function aO(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function XI(e,n){const t=aO(e);return Math.round(n*t)/t}function qI(e){const n=P.useRef(e);return hp(()=>{n.current=e}),n}function Eee(e){e===void 0&&(e={});const{placement:n="bottom",strategy:t="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[u,h]=P.useState({x:0,y:0,strategy:t,placement:n,middlewareData:{},isPositioned:!1}),[p,f]=P.useState(r);Cf(p,r)||f(r);const[S,m]=P.useState(null),[x,y]=P.useState(null),v=P.useCallback(K=>{K!==C.current&&(C.current=K,m(K))},[]),b=P.useCallback(K=>{K!==k.current&&(k.current=K,y(K))},[]),E=s||S,I=i||x,C=P.useRef(null),k=P.useRef(null),T=P.useRef(u),O=l!=null,_=qI(l),A=qI(o),L=P.useCallback(()=>{if(!C.current||!k.current)return;const K={placement:n,strategy:t,middleware:p};A.current&&(K.platform=A.current),Iee(C.current,k.current,K).then(z=>{const U={...z,isPositioned:!0};j.current&&!Cf(T.current,U)&&(T.current=U,aa.flushSync(()=>{h(U)}))})},[p,n,t,A]);hp(()=>{c===!1&&T.current.isPositioned&&(T.current.isPositioned=!1,h(K=>({...K,isPositioned:!1})))},[c]);const j=P.useRef(!1);hp(()=>(j.current=!0,()=>{j.current=!1}),[]),hp(()=>{if(E&&(C.current=E),I&&(k.current=I),E&&I){if(_.current)return _.current(E,I,L);L()}},[E,I,L,_,O]);const R=P.useMemo(()=>({reference:C,floating:k,setReference:v,setFloating:b}),[v,b]),F=P.useMemo(()=>({reference:E,floating:I}),[E,I]),W=P.useMemo(()=>{const K={position:t,left:0,top:0};if(!F.floating)return K;const z=XI(F.floating,u.x),U=XI(F.floating,u.y);return a?{...K,transform:"translate("+z+"px, "+U+"px)",...aO(F.floating)>=1.5&&{willChange:"transform"}}:{position:t,left:z,top:U}},[t,a,F.floating,u.x,u.y]);return P.useMemo(()=>({...u,update:L,refs:R,elements:F,floatingStyles:W}),[u,L,R,F,W])}const kee=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?YI({element:r.current,padding:o}).fn(t):{}:r?YI({element:r,padding:o}).fn(t):{}}}},_ee=(e,n)=>({...vee(e),options:[e,n]}),Tee=(e,n)=>({...xee(e),options:[e,n]}),Mee=(e,n)=>({...Cee(e),options:[e,n]}),Aee=(e,n)=>({...wee(e),options:[e,n]}),jee=(e,n)=>({...bee(e),options:[e,n]}),Oee=(e,n)=>({...Pee(e),options:[e,n]}),Dee=(e,n)=>({...kee(e),options:[e,n]});var Ree="Arrow",lO=P.forwardRef((e,n)=>{const{children:t,width:r=10,height:o=5,...s}=e;return d.jsx(Ce.svg,{...s,ref:n,width:r,height:o,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:e.asChild?t:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});lO.displayName=Ree;var Lee=lO;function cO(e){const[n,t]=P.useState(void 0);return Xs(()=>{if(e){t({width:e.offsetWidth,height:e.offsetHeight});const r=new ResizeObserver(o=>{if(!Array.isArray(o)||!o.length)return;const s=o[0];let i,a;if("borderBoxSize"in s){const l=s.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=e.offsetWidth,a=e.offsetHeight;t({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else t(void 0)},[e]),n}var O0="Popper",[uO,_g]=ko(O0),[$ee,dO]=uO(O0),hO=e=>{const{__scopePopper:n,children:t}=e,[r,o]=P.useState(null);return d.jsx($ee,{scope:n,anchor:r,onAnchorChange:o,children:t})};hO.displayName=O0;var pO="PopperAnchor",fO=P.forwardRef((e,n)=>{const{__scopePopper:t,virtualRef:r,...o}=e,s=dO(pO,t),i=P.useRef(null),a=Ye(n,i);return P.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ce.div,{...o,ref:a})});fO.displayName=pO;var D0="PopperContent",[Fee,Nee]=uO(D0),gO=P.forwardRef((e,n)=>{var je,et,Ae,at,Ne,Wn;const{__scopePopper:t,side:r="bottom",sideOffset:o=0,align:s="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:p=!1,updatePositionStrategy:f="optimized",onPlaced:S,...m}=e,x=dO(D0,t),[y,v]=P.useState(null),b=Ye(n,Rt=>v(Rt)),[E,I]=P.useState(null),C=cO(E),k=(C==null?void 0:C.width)??0,T=(C==null?void 0:C.height)??0,O=r+(s!=="center"?"-"+s:""),_=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},A=Array.isArray(c)?c:[c],L=A.length>0,j={padding:_,boundary:A.filter(Bee),altBoundary:L},{refs:R,floatingStyles:F,placement:W,isPositioned:K,middlewareData:z}=Eee({strategy:"fixed",placement:O,whileElementsMounted:(...Rt)=>See(...Rt,{animationFrame:f==="always"}),elements:{reference:x.anchor},middleware:[_ee({mainAxis:o+T,alignmentAxis:i}),l&&Tee({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Mee():void 0,...j}),l&&Aee({...j}),jee({...j,apply:({elements:Rt,rects:Cn,availableWidth:St,availableHeight:Xt})=>{const{width:_o,height:Bl}=Cn.reference,ds=Rt.floating.style;ds.setProperty("--radix-popper-available-width",`${St}px`),ds.setProperty("--radix-popper-available-height",`${Xt}px`),ds.setProperty("--radix-popper-anchor-width",`${_o}px`),ds.setProperty("--radix-popper-anchor-height",`${Bl}px`)}}),E&&Dee({element:E,padding:a}),Uee({arrowWidth:k,arrowHeight:T}),p&&Oee({strategy:"referenceHidden",...j})]}),[U,X]=SO(W),J=Vt(S);Xs(()=>{K&&(J==null||J())},[K,J]);const le=(je=z.arrow)==null?void 0:je.x,ye=(et=z.arrow)==null?void 0:et.y,Me=((Ae=z.arrow)==null?void 0:Ae.centerOffset)!==0,[ae,Ue]=P.useState();return Xs(()=>{y&&Ue(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:R.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:K?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:ae,"--radix-popper-transform-origin":[(at=z.transformOrigin)==null?void 0:at.x,(Ne=z.transformOrigin)==null?void 0:Ne.y].join(" "),...((Wn=z.hide)==null?void 0:Wn.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:e.dir,children:d.jsx(Fee,{scope:t,placedSide:U,onArrowChange:I,arrowX:le,arrowY:ye,shouldHideArrow:Me,children:d.jsx(Ce.div,{"data-side":U,"data-align":X,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});gO.displayName=D0;var mO="PopperArrow",zee={top:"bottom",right:"left",bottom:"top",left:"right"},yO=P.forwardRef(function(n,t){const{__scopePopper:r,...o}=n,s=Nee(mO,r),i=zee[s.placedSide];return d.jsx("span",{ref:s.onArrowChange,style:{position:"absolute",left:s.arrowX,top:s.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[s.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[s.placedSide],visibility:s.shouldHideArrow?"hidden":void 0},children:d.jsx(Lee,{...o,ref:t,style:{...o.style,display:"block"}})})});yO.displayName=mO;function Bee(e){return e!==null}var Uee=e=>({name:"transformOrigin",options:e,fn(n){var x,y,v;const{placement:t,rects:r,middlewareData:o}=n,i=((x=o.arrow)==null?void 0:x.centerOffset)!==0,a=i?0:e.arrowWidth,l=i?0:e.arrowHeight,[c,u]=SO(t),h={start:"0%",center:"50%",end:"100%"}[u],p=(((y=o.arrow)==null?void 0:y.x)??0)+a/2,f=(((v=o.arrow)==null?void 0:v.y)??0)+l/2;let S="",m="";return c==="bottom"?(S=i?h:`${p}px`,m=`${-l}px`):c==="top"?(S=i?h:`${p}px`,m=`${r.floating.height+l}px`):c==="right"?(S=`${-l}px`,m=i?h:`${f}px`):c==="left"&&(S=`${r.floating.width+l}px`,m=i?h:`${f}px`),{data:{x:S,y:m}}}});function SO(e){const[n,t="center"]=e.split("-");return[n,t]}var R0=hO,L0=fO,vO=gO,xO=yO,$0="Popover",[wO,Yie]=ko($0,[_g]),Yu=_g(),[Hee,ci]=wO($0),bO=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Yu(n),l=P.useRef(null),[c,u]=P.useState(!1),[h=!1,p]=li({prop:r,defaultProp:o,onChange:s});return d.jsx(R0,{...a,children:d.jsx(Hee,{scope:n,contentId:Vo(),triggerRef:l,open:h,onOpenChange:p,onOpenToggle:P.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:c,onCustomAnchorAdd:P.useCallback(()=>u(!0),[]),onCustomAnchorRemove:P.useCallback(()=>u(!1),[]),modal:i,children:t})})};bO.displayName=$0;var PO="PopoverAnchor",Kee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(PO,t),s=Yu(t),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=o;return P.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(L0,{...s,...r,ref:n})});Kee.displayName=PO;var CO="PopoverTrigger",IO=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(CO,t),s=Yu(t),i=Ye(n,o.triggerRef),a=d.jsx(Ce.button,{type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":MO(o.open),...r,ref:i,onClick:re(e.onClick,o.onOpenToggle)});return o.hasCustomAnchor?a:d.jsx(L0,{asChild:!0,...s,children:a})});IO.displayName=CO;var F0="PopoverPortal",[Wee,Gee]=wO(F0,{forceMount:void 0}),EO=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=ci(F0,n);return d.jsx(Wee,{scope:n,forceMount:t,children:d.jsx(Xr,{present:t||s.open,children:d.jsx(Gu,{asChild:!0,container:o,children:r})})})};EO.displayName=F0;var Cl="PopoverContent",kO=P.forwardRef((e,n)=>{const t=Gee(Cl,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=ci(Cl,e.__scopePopover);return d.jsx(Xr,{present:r||s.open,children:s.modal?d.jsx(Vee,{...o,ref:n}):d.jsx(Yee,{...o,ref:n})})});kO.displayName=Cl;var Vee=P.forwardRef((e,n)=>{const t=ci(Cl,e.__scopePopover),r=P.useRef(null),o=Ye(n,r),s=P.useRef(!1);return P.useEffect(()=>{const i=r.current;if(i)return g0(i)},[]),d.jsx(Sg,{as:Xi,allowPinchZoom:!0,children:d.jsx(_O,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:re(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)==null||a.focus()}),onPointerDownOutside:re(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:re(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),Yee=P.forwardRef((e,n)=>{const t=ci(Cl,e.__scopePopover),r=P.useRef(!1),o=P.useRef(!1);return d.jsx(_O,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i,a;(i=e.onCloseAutoFocus)==null||i.call(e,s),s.defaultPrevented||(r.current||(a=t.triggerRef.current)==null||a.focus(),s.preventDefault()),r.current=!1,o.current=!1},onInteractOutside:s=>{var l,c;(l=e.onInteractOutside)==null||l.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const i=s.target;((c=t.triggerRef.current)==null?void 0:c.contains(i))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}})}),_O=P.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=e,p=ci(Cl,t),f=Yu(t);return f0(),d.jsx(mg,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s,children:d.jsx(Wu,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1),children:d.jsx(vO,{"data-state":MO(p.open),role:"dialog",id:p.contentId,...f,...h,ref:n,style:{...h.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)"}})})})}),TO="PopoverClose",Xee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=ci(TO,t);return d.jsx(Ce.button,{type:"button",...r,ref:n,onClick:re(e.onClick,()=>o.onOpenChange(!1))})});Xee.displayName=TO;var qee="PopoverArrow",Zee=P.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Yu(t);return d.jsx(xO,{...o,...r,ref:n})});Zee.displayName=qee;function MO(e){return e?"open":"closed"}var Qee=bO,Jee=IO,ete=EO,tte=kO;function ui(e,n){const t=B(),r=P.useRef(!1),o=Zr(),s=P.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(l=>!l.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=G("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return P.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 N0({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=ui(e,t);return d.jsx(Qee,{onOpenChange:s,open:r||o,children:d.jsx("div",{className:"tlui-popover",children:n})})}function z0({children:e}){return d.jsx(Jee,{asChild:!0,dir:"ltr",children:e})}function B0({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=un();return d.jsx(ete,{container:s,children:d.jsx(tte,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const AO=P.createContext(null);function Tg(){const e=P.useContext(AO);if(!e)throw new Error("useTldrawUiMenuContext must be used within a TldrawUiMenuContextProvider");return e}function kr({type:e,sourceId:n,children:t}){return d.jsx(AO.Provider,{value:{type:e,sourceId:n},children:t})}function nte(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>{if(!r)return!1;if(e.isShapeOfType(r,"arrow")){const o=An(e,r);if(o.start||o.end)return!1}return!0})}const jO=()=>{const e=B();return G("threeStackableItems",()=>nte(e).length>2,[e])},cs=()=>{const e=B();return G("isInSelectState",()=>e.isIn("select"),[e])},OO=()=>{const e=B();return G("allow group",()=>{const n=e.getSelectedShapes();if(n.length<2)return!1;for(const t of n)if(e.isShapeOfType(t,"arrow")){const r=An(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])},DO=()=>{const e=B();return G("allowUngroup",()=>e.getSelectedShapeIds().some(n=>{var t;return((t=e.getShape(n))==null?void 0:t.type)==="group"}),[e])},rte=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function ote(e,n){const t=B();return G("selectedShapes",()=>t.getSelectedShapes().length>=e,[t,e,n])}function Pn(e,n){const t=B();return G("selectedShapes",()=>{const r=t.getSelectedShapes().filter(o=>!t.isShapeOrAncestorLocked(o)).length;return e===void 0?r:r>=e},[t])}function ste(){const e=B();return G("showAutoSizeToggle",()=>{const n=e.getSelectedShapes();return n.length===1&&e.isShapeOfType(n[0],"text")&&n[0].props.autoSize===!1},[e])}function RO(){const e=B();return G("hasLinkShapeSelected",()=>{const n=e.getOnlySelectedShape();return!!(n&&n.type!=="embed"&&"url"in n.props&&!n.isLocked)},[e])}function ite(){const e=B();return G("onlyFlippableShape",()=>{const n=e.getOnlySelectedShape();return n&&(e.isShapeOfType(n,"group")||e.isShapeOfType(n,"arrow")||e.isShapeOfType(n,"line")||e.isShapeOfType(n,"draw"))},[e])}function LO(){const e=B();return G("useCanRedo",()=>e.getCanRedo(),[e])}function $O(){const e=B();return G("useCanUndo",()=>e.getCanUndo(),[e])}var ate=P.createContext(void 0);function U0(e){const n=P.useContext(ate);return e||n||"ltr"}var Iy="rovingFocusGroup.onEntryFocus",lte={bubbles:!1,cancelable:!0},Mg="RovingFocusGroup",[Kv,FO,cte]=vg(Mg),[ute,NO]=ko(Mg,[cte]),[dte,hte]=ute(Mg),zO=P.forwardRef((e,n)=>d.jsx(Kv.Provider,{scope:e.__scopeRovingFocusGroup,children:d.jsx(Kv.Slot,{scope:e.__scopeRovingFocusGroup,children:d.jsx(pte,{...e,ref:n})})}));zO.displayName=Mg;var pte=P.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=e,p=P.useRef(null),f=Ye(n,p),S=U0(s),[m=null,x]=li({prop:i,defaultProp:a,onChange:l}),[y,v]=P.useState(!1),b=Vt(c),E=FO(t),I=P.useRef(!1),[C,k]=P.useState(0);return P.useEffect(()=>{const T=p.current;if(T)return T.addEventListener(Iy,b),()=>T.removeEventListener(Iy,b)},[b]),d.jsx(dte,{scope:t,orientation:r,dir:S,loop:o,currentTabStopId:m,onItemFocus:P.useCallback(T=>x(T),[x]),onItemShiftTab:P.useCallback(()=>v(!0),[]),onFocusableItemAdd:P.useCallback(()=>k(T=>T+1),[]),onFocusableItemRemove:P.useCallback(()=>k(T=>T-1),[]),children:d.jsx(Ce.div,{tabIndex:y||C===0?-1:0,"data-orientation":r,...h,ref:f,style:{outline:"none",...e.style},onMouseDown:re(e.onMouseDown,()=>{I.current=!0}),onFocus:re(e.onFocus,T=>{const O=!I.current;if(T.target===T.currentTarget&&O&&!y){const _=new CustomEvent(Iy,lte);if(T.currentTarget.dispatchEvent(_),!_.defaultPrevented){const A=E().filter(W=>W.focusable),L=A.find(W=>W.active),j=A.find(W=>W.id===m),F=[L,j,...A].filter(Boolean).map(W=>W.ref.current);HO(F,u)}}I.current=!1}),onBlur:re(e.onBlur,()=>v(!1))})})}),BO="RovingFocusGroupItem",UO=P.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Vo(),l=s||a,c=hte(BO,t),u=c.currentTabStopId===l,h=FO(t),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return P.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),d.jsx(Kv.ItemSlot,{scope:t,id:l,focusable:r,active:o,children:d.jsx(Ce.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:n,onMouseDown:re(e.onMouseDown,S=>{r?c.onItemFocus(l):S.preventDefault()}),onFocus:re(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:re(e.onKeyDown,S=>{if(S.key==="Tab"&&S.shiftKey){c.onItemShiftTab();return}if(S.target!==S.currentTarget)return;const m=mte(S,c.orientation,c.dir);if(m!==void 0){if(S.metaKey||S.ctrlKey||S.altKey||S.shiftKey)return;S.preventDefault();let y=h().filter(v=>v.focusable).map(v=>v.ref.current);if(m==="last")y.reverse();else if(m==="prev"||m==="next"){m==="prev"&&y.reverse();const v=y.indexOf(S.currentTarget);y=c.loop?yte(y,v+1):y.slice(v+1)}setTimeout(()=>HO(y))}})})})});UO.displayName=BO;var fte={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function gte(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function mte(e,n,t){const r=gte(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return fte[r]}function HO(e,n=!1){const t=document.activeElement;for(const r of e)if(r===t||(r.focus({preventScroll:n}),document.activeElement!==t))return}function yte(e,n){return e.map((t,r)=>e[(n+r)%e.length])}var Ste=zO,vte=UO,Wv=["Enter"," "],xte=["ArrowDown","PageUp","Home"],KO=["ArrowUp","PageDown","End"],wte=[...xte,...KO],bte={ltr:[...Wv,"ArrowRight"],rtl:[...Wv,"ArrowLeft"]},Pte={ltr:["ArrowLeft"],rtl:["ArrowRight"]},Xu="Menu",[vu,Cte,Ite]=vg(Xu),[ca,Ag]=ko(Xu,[Ite,_g,NO]),qu=_g(),WO=NO(),[GO,di]=ca(Xu),[Ete,Zu]=ca(Xu),VO=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=qu(n),[l,c]=P.useState(null),u=P.useRef(!1),h=Vt(s),p=U0(o);return P.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",S,{capture:!0,once:!0}),document.addEventListener("pointermove",S,{capture:!0,once:!0})},S=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",S,{capture:!0}),document.removeEventListener("pointermove",S,{capture:!0})}},[]),d.jsx(R0,{...a,children:d.jsx(GO,{scope:n,open:t,onOpenChange:h,content:l,onContentChange:c,children:d.jsx(Ete,{scope:n,onClose:P.useCallback(()=>h(!1),[h]),isUsingKeyboardRef:u,dir:p,modal:i,children:r})})})};VO.displayName=Xu;var kte="MenuAnchor",H0=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=qu(t);return d.jsx(L0,{...o,...r,ref:n})});H0.displayName=kte;var K0="MenuPortal",[_te,YO]=ca(K0,{forceMount:void 0}),XO=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=di(K0,n);return d.jsx(_te,{scope:n,forceMount:t,children:d.jsx(Xr,{present:t||s.open,children:d.jsx(Gu,{asChild:!0,container:o,children:r})})})};XO.displayName=K0;var Cr="MenuContent",[Tte,W0]=ca(Cr),qO=P.forwardRef((e,n)=>{const t=YO(Cr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=di(Cr,e.__scopeMenu),i=Zu(Cr,e.__scopeMenu);return d.jsx(vu.Provider,{scope:e.__scopeMenu,children:d.jsx(Xr,{present:r||s.open,children:d.jsx(vu.Slot,{scope:e.__scopeMenu,children:i.modal?d.jsx(Mte,{...o,ref:n}):d.jsx(Ate,{...o,ref:n})})})})}),Mte=P.forwardRef((e,n)=>{const t=di(Cr,e.__scopeMenu),r=P.useRef(null),o=Ye(n,r);return P.useEffect(()=>{const s=r.current;if(s)return g0(s)},[]),d.jsx(G0,{...e,ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:re(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)})}),Ate=P.forwardRef((e,n)=>{const t=di(Cr,e.__scopeMenu);return d.jsx(G0,{...e,ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)})}),G0=P.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,disableOutsideScroll:S,...m}=e,x=di(Cr,t),y=Zu(Cr,t),v=qu(t),b=WO(t),E=Cte(t),[I,C]=P.useState(null),k=P.useRef(null),T=Ye(n,k,x.onContentChange),O=P.useRef(0),_=P.useRef(""),A=P.useRef(0),L=P.useRef(null),j=P.useRef("right"),R=P.useRef(0),F=S?Sg:P.Fragment,W=S?{as:Xi,allowPinchZoom:!0}:void 0,K=U=>{var je,et;const X=_.current+U,J=E().filter(Ae=>!Ae.disabled),le=document.activeElement,ye=(je=J.find(Ae=>Ae.ref.current===le))==null?void 0:je.textValue,Me=J.map(Ae=>Ae.textValue),ae=Hte(Me,X,ye),Ue=(et=J.find(Ae=>Ae.textValue===ae))==null?void 0:et.ref.current;(function Ae(at){_.current=at,window.clearTimeout(O.current),at!==""&&(O.current=window.setTimeout(()=>Ae(""),1e3))})(X),Ue&&setTimeout(()=>Ue.focus())};P.useEffect(()=>()=>window.clearTimeout(O.current),[]),f0();const z=P.useCallback(U=>{var J,le;return j.current===((J=L.current)==null?void 0:J.side)&&Wte(U,(le=L.current)==null?void 0:le.area)},[]);return d.jsx(Tte,{scope:t,searchRef:_,onItemEnter:P.useCallback(U=>{z(U)&&U.preventDefault()},[z]),onItemLeave:P.useCallback(U=>{var X;z(U)||((X=k.current)==null||X.focus(),C(null))},[z]),onTriggerLeave:P.useCallback(U=>{z(U)&&U.preventDefault()},[z]),pointerGraceTimerRef:A,onPointerGraceIntentChange:P.useCallback(U=>{L.current=U},[]),children:d.jsx(F,{...W,children:d.jsx(mg,{asChild:!0,trapped:o,onMountAutoFocus:re(s,U=>{var X;U.preventDefault(),(X=k.current)==null||X.focus({preventScroll:!0})}),onUnmountAutoFocus:i,children:d.jsx(Wu,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:h,onInteractOutside:p,onDismiss:f,children:d.jsx(Ste,{asChild:!0,...b,dir:y.dir,orientation:"vertical",loop:r,currentTabStopId:I,onCurrentTabStopIdChange:C,onEntryFocus:re(l,U=>{y.isUsingKeyboardRef.current||U.preventDefault()}),preventScrollOnEntryFocus:!0,children:d.jsx(vO,{role:"menu","aria-orientation":"vertical","data-state":pD(x.open),"data-radix-menu-content":"",dir:y.dir,...v,...m,ref:T,style:{outline:"none",...m.style},onKeyDown:re(m.onKeyDown,U=>{const J=U.target.closest("[data-radix-menu-content]")===U.currentTarget,le=U.ctrlKey||U.altKey||U.metaKey,ye=U.key.length===1;J&&(U.key==="Tab"&&U.preventDefault(),!le&&ye&&K(U.key));const Me=k.current;if(U.target!==Me||!wte.includes(U.key))return;U.preventDefault();const Ue=E().filter(je=>!je.disabled).map(je=>je.ref.current);KO.includes(U.key)&&Ue.reverse(),Bte(Ue)}),onBlur:re(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout(O.current),_.current="")}),onPointerMove:re(e.onPointerMove,xu(U=>{const X=U.target,J=R.current!==U.clientX;if(U.currentTarget.contains(X)&&J){const le=U.clientX>R.current?"right":"left";j.current=le,R.current=U.clientX}}))})})})})})})});qO.displayName=Cr;var jte="MenuGroup",V0=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return d.jsx(Ce.div,{role:"group",...r,ref:n})});V0.displayName=jte;var Ote="MenuLabel",ZO=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return d.jsx(Ce.div,{...r,ref:n})});ZO.displayName=Ote;var If="MenuItem",ZI="menu.itemSelect",jg=P.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=P.useRef(null),i=Zu(If,e.__scopeMenu),a=W0(If,e.__scopeMenu),l=Ye(n,s),c=P.useRef(!1),u=()=>{const h=s.current;if(!t&&h){const p=new CustomEvent(ZI,{bubbles:!0,cancelable:!0});h.addEventListener(ZI,f=>r==null?void 0:r(f),{once:!0}),p0(h,p),p.defaultPrevented?c.current=!1:i.onClose()}};return d.jsx(QO,{...o,ref:l,disabled:t,onClick:re(e.onClick,u),onPointerDown:h=>{var p;(p=e.onPointerDown)==null||p.call(e,h),c.current=!0},onPointerUp:re(e.onPointerUp,h=>{var p;c.current||(p=h.currentTarget)==null||p.click()}),onKeyDown:re(e.onKeyDown,h=>{const p=a.searchRef.current!=="";t||p&&h.key===" "||Wv.includes(h.key)&&(h.currentTarget.click(),h.preventDefault())})})});jg.displayName=If;var QO=P.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=W0(If,t),a=WO(t),l=P.useRef(null),c=Ye(n,l),[u,h]=P.useState(!1),[p,f]=P.useState("");return P.useEffect(()=>{const S=l.current;S&&f((S.textContent??"").trim())},[s.children]),d.jsx(vu.ItemSlot,{scope:t,disabled:r,textValue:o??p,children:d.jsx(vte,{asChild:!0,...a,focusable:!r,children:d.jsx(Ce.div,{role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0,...s,ref:c,onPointerMove:re(e.onPointerMove,xu(S=>{r?i.onItemLeave(S):(i.onItemEnter(S),S.defaultPrevented||S.currentTarget.focus({preventScroll:!0}))})),onPointerLeave:re(e.onPointerLeave,xu(S=>i.onItemLeave(S))),onFocus:re(e.onFocus,()=>h(!0)),onBlur:re(e.onBlur,()=>h(!1))})})})}),Dte="MenuCheckboxItem",JO=P.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return d.jsx(oD,{scope:e.__scopeMenu,checked:t,children:d.jsx(jg,{role:"menuitemcheckbox","aria-checked":Ef(t)?"mixed":t,...o,ref:n,"data-state":q0(t),onSelect:re(o.onSelect,()=>r==null?void 0:r(Ef(t)?!0:!t),{checkForDefaultPrevented:!1})})})});JO.displayName=Dte;var eD="MenuRadioGroup",[Rte,Lte]=ca(eD,{value:void 0,onValueChange:()=>{}}),tD=P.forwardRef((e,n)=>{const{value:t,onValueChange:r,...o}=e,s=Vt(r);return d.jsx(Rte,{scope:e.__scopeMenu,value:t,onValueChange:s,children:d.jsx(V0,{...o,ref:n})})});tD.displayName=eD;var nD="MenuRadioItem",rD=P.forwardRef((e,n)=>{const{value:t,...r}=e,o=Lte(nD,e.__scopeMenu),s=t===o.value;return d.jsx(oD,{scope:e.__scopeMenu,checked:s,children:d.jsx(jg,{role:"menuitemradio","aria-checked":s,...r,ref:n,"data-state":q0(s),onSelect:re(r.onSelect,()=>{var i;return(i=o.onValueChange)==null?void 0:i.call(o,t)},{checkForDefaultPrevented:!1})})})});rD.displayName=nD;var Y0="MenuItemIndicator",[oD,$te]=ca(Y0,{checked:!1}),sD=P.forwardRef((e,n)=>{const{__scopeMenu:t,forceMount:r,...o}=e,s=$te(Y0,t);return d.jsx(Xr,{present:r||Ef(s.checked)||s.checked===!0,children:d.jsx(Ce.span,{...o,ref:n,"data-state":q0(s.checked)})})});sD.displayName=Y0;var Fte="MenuSeparator",iD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return d.jsx(Ce.div,{role:"separator","aria-orientation":"horizontal",...r,ref:n})});iD.displayName=Fte;var Nte="MenuArrow",aD=P.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=qu(t);return d.jsx(xO,{...o,...r,ref:n})});aD.displayName=Nte;var X0="MenuSub",[zte,lD]=ca(X0),cD=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=di(X0,n),i=qu(n),[a,l]=P.useState(null),[c,u]=P.useState(null),h=Vt(o);return P.useEffect(()=>(s.open===!1&&h(!1),()=>h(!1)),[s.open,h]),d.jsx(R0,{...i,children:d.jsx(GO,{scope:n,open:r,onOpenChange:h,content:c,onContentChange:u,children:d.jsx(zte,{scope:n,contentId:Vo(),triggerId:Vo(),trigger:a,onTriggerChange:l,children:t})})})};cD.displayName=X0;var Ec="MenuSubTrigger",uD=P.forwardRef((e,n)=>{const t=di(Ec,e.__scopeMenu),r=Zu(Ec,e.__scopeMenu),o=lD(Ec,e.__scopeMenu),s=W0(Ec,e.__scopeMenu),i=P.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=P.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return P.useEffect(()=>u,[u]),P.useEffect(()=>{const h=a.current;return()=>{window.clearTimeout(h),l(null)}},[a,l]),d.jsx(H0,{asChild:!0,...c,children:d.jsx(QO,{id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":pD(t.open),...e,ref:gg(n,o.onTriggerChange),onClick:h=>{var p;(p=e.onClick)==null||p.call(e,h),!(e.disabled||h.defaultPrevented)&&(h.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:re(e.onPointerMove,xu(h=>{s.onItemEnter(h),!h.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:re(e.onPointerLeave,xu(h=>{var f,S;u();const p=(f=t.content)==null?void 0:f.getBoundingClientRect();if(p){const m=(S=t.content)==null?void 0:S.dataset.side,x=m==="right",y=x?-5:5,v=p[x?"left":"right"],b=p[x?"right":"left"];s.onPointerGraceIntentChange({area:[{x:h.clientX+y,y:h.clientY},{x:v,y:p.top},{x:b,y:p.top},{x:b,y:p.bottom},{x:v,y:p.bottom}],side:m}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(h),h.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:re(e.onKeyDown,h=>{var f;const p=s.searchRef.current!=="";e.disabled||p&&h.key===" "||bte[r.dir].includes(h.key)&&(t.onOpenChange(!0),(f=t.content)==null||f.focus(),h.preventDefault())})})})});uD.displayName=Ec;var dD="MenuSubContent",hD=P.forwardRef((e,n)=>{const t=YO(Cr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=di(Cr,e.__scopeMenu),i=Zu(Cr,e.__scopeMenu),a=lD(dD,e.__scopeMenu),l=P.useRef(null),c=Ye(n,l);return d.jsx(vu.Provider,{scope:e.__scopeMenu,children:d.jsx(Xr,{present:r||s.open,children:d.jsx(vu.Slot,{scope:e.__scopeMenu,children:d.jsx(G0,{id:a.contentId,"aria-labelledby":a.triggerId,...o,ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var h;i.isUsingKeyboardRef.current&&((h=l.current)==null||h.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:re(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:re(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:re(e.onKeyDown,u=>{var f;const h=u.currentTarget.contains(u.target),p=Pte[i.dir].includes(u.key);h&&p&&(s.onOpenChange(!1),(f=a.trigger)==null||f.focus(),u.preventDefault())})})})})})});hD.displayName=dD;function pD(e){return e?"open":"closed"}function Ef(e){return e==="indeterminate"}function q0(e){return Ef(e)?"indeterminate":e?"checked":"unchecked"}function Bte(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function Ute(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function Hte(e,n,t){const o=n.length>1&&Array.from(n).every(c=>c===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=Ute(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==t));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==t?l:void 0}function Kte(e,n){const{x:t,y:r}=e;let o=!1;for(let s=0,i=n.length-1;s<n.length;i=s++){const a=n[s].x,l=n[s].y,c=n[i].x,u=n[i].y;l>r!=u>r&&t<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function Wte(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return Kte(t,n)}function xu(e){return n=>n.pointerType==="mouse"?e(n):void 0}var fD=VO,gD=H0,mD=XO,yD=qO,SD=V0,vD=ZO,xD=jg,wD=JO,bD=tD,PD=rD,CD=sD,ID=iD,ED=aD,kD=cD,_D=uD,TD=hD,Z0="ContextMenu",[Gte,Xie]=ko(Z0,[Ag]),dn=Ag(),[Vte,MD]=Gte(Z0),AD=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=P.useState(!1),l=dn(n),c=Vt(r),u=P.useCallback(h=>{a(h),c(h)},[c]);return d.jsx(Vte,{scope:n,open:i,onOpenChange:u,modal:s,children:d.jsx(fD,{...l,dir:o,open:i,onOpenChange:u,modal:s,children:t})})};AD.displayName=Z0;var jD="ContextMenuTrigger",OD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=MD(jD,t),i=dn(t),a=P.useRef({x:0,y:0}),l=P.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=P.useRef(0),u=P.useCallback(()=>window.clearTimeout(c.current),[]),h=p=>{a.current={x:p.clientX,y:p.clientY},s.onOpenChange(!0)};return P.useEffect(()=>u,[u]),P.useEffect(()=>void(r&&u()),[r,u]),d.jsxs(d.Fragment,{children:[d.jsx(gD,{...i,virtualRef:l}),d.jsx(Ce.span,{"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,...o,ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:re(e.onContextMenu,p=>{u(),h(p),p.preventDefault()}),onPointerDown:r?e.onPointerDown:re(e.onPointerDown,ah(p=>{u(),c.current=window.setTimeout(()=>h(p),700)})),onPointerMove:r?e.onPointerMove:re(e.onPointerMove,ah(u)),onPointerCancel:r?e.onPointerCancel:re(e.onPointerCancel,ah(u)),onPointerUp:r?e.onPointerUp:re(e.onPointerUp,ah(u))})]})});OD.displayName=jD;var Yte="ContextMenuPortal",Q0=e=>{const{__scopeContextMenu:n,...t}=e,r=dn(n);return d.jsx(mD,{...r,...t})};Q0.displayName=Yte;var DD="ContextMenuContent",RD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=MD(DD,t),s=dn(t),i=P.useRef(!1);return d.jsx(yD,{...s,...r,ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)==null||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)==null||l.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});RD.displayName=DD;var Xte="ContextMenuGroup",LD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(SD,{...o,...r,ref:n})});LD.displayName=Xte;var qte="ContextMenuLabel",Zte=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(vD,{...o,...r,ref:n})});Zte.displayName=qte;var Qte="ContextMenuItem",$D=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(xD,{...o,...r,ref:n})});$D.displayName=Qte;var Jte="ContextMenuCheckboxItem",FD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(wD,{...o,...r,ref:n})});FD.displayName=Jte;var ene="ContextMenuRadioGroup",tne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(bD,{...o,...r,ref:n})});tne.displayName=ene;var nne="ContextMenuRadioItem",rne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(PD,{...o,...r,ref:n})});rne.displayName=nne;var one="ContextMenuItemIndicator",sne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(CD,{...o,...r,ref:n})});sne.displayName=one;var ine="ContextMenuSeparator",ane=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(ID,{...o,...r,ref:n})});ane.displayName=ine;var lne="ContextMenuArrow",cne=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(ED,{...o,...r,ref:n})});cne.displayName=lne;var une="ContextMenuSub",ND=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=dn(n),[a,l]=li({prop:o,defaultProp:s,onChange:r});return d.jsx(kD,{...i,open:a,onOpenChange:l,children:t})};ND.displayName=une;var dne="ContextMenuSubTrigger",zD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(_D,{...o,...r,ref:n})});zD.displayName=dne;var hne="ContextMenuSubContent",BD=P.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=dn(t);return d.jsx(TD,{...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)"}})});BD.displayName=hne;function ah(e){return n=>n.pointerType!=="mouse"?e(n):void 0}var pne=AD,fne=OD,gne=Q0,mne=RD,yne=FD;const UD=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,Sne=UD?"⌘":"Ctrl",vne=UD?"⌥":"Alt";function HD(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,Sne).replace(/\?/g,vne).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function Gv(e){return"— "+HD(e).join(" ")}function xne(e){return d.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:d.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[d.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),d.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:d.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}var J0="DropdownMenu",[wne,qie]=ko(J0,[Ag]),hn=Ag(),[bne,KD]=wne(J0),WD=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=hn(n),c=P.useRef(null),[u=!1,h]=li({prop:o,defaultProp:s,onChange:i});return d.jsx(bne,{scope:n,triggerId:Vo(),triggerRef:c,contentId:Vo(),open:u,onOpenChange:h,onOpenToggle:P.useCallback(()=>h(p=>!p),[h]),modal:a,children:d.jsx(fD,{...l,open:u,onOpenChange:h,dir:r,modal:a,children:t})})};WD.displayName=J0;var GD="DropdownMenuTrigger",VD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=KD(GD,t),i=hn(t);return d.jsx(gD,{asChild:!0,...i,children:d.jsx(Ce.button,{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:gg(n,s.triggerRef),onPointerDown:re(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:re(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})})});VD.displayName=GD;var Pne="DropdownMenuPortal",YD=e=>{const{__scopeDropdownMenu:n,...t}=e,r=hn(n);return d.jsx(mD,{...r,...t})};YD.displayName=Pne;var XD="DropdownMenuContent",qD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=KD(XD,t),s=hn(t),i=P.useRef(!1);return d.jsx(yD,{id:o.contentId,"aria-labelledby":o.triggerId,...s,...r,ref:n,onCloseAutoFocus:re(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)==null||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:re(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}})});qD.displayName=XD;var Cne="DropdownMenuGroup",ZD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(SD,{...o,...r,ref:n})});ZD.displayName=Cne;var Ine="DropdownMenuLabel",Ene=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(vD,{...o,...r,ref:n})});Ene.displayName=Ine;var kne="DropdownMenuItem",QD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(xD,{...o,...r,ref:n})});QD.displayName=kne;var _ne="DropdownMenuCheckboxItem",JD=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(wD,{...o,...r,ref:n})});JD.displayName=_ne;var Tne="DropdownMenuRadioGroup",Mne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(bD,{...o,...r,ref:n})});Mne.displayName=Tne;var Ane="DropdownMenuRadioItem",jne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(PD,{...o,...r,ref:n})});jne.displayName=Ane;var One="DropdownMenuItemIndicator",Dne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(CD,{...o,...r,ref:n})});Dne.displayName=One;var Rne="DropdownMenuSeparator",Lne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(ID,{...o,...r,ref:n})});Lne.displayName=Rne;var $ne="DropdownMenuArrow",Fne=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(ED,{...o,...r,ref:n})});Fne.displayName=$ne;var Nne=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=hn(n),[a=!1,l]=li({prop:r,defaultProp:s,onChange:o});return d.jsx(kD,{...i,open:a,onOpenChange:l,children:t})},zne="DropdownMenuSubTrigger",eR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(_D,{...o,...r,ref:n})});eR.displayName=zne;var Bne="DropdownMenuSubContent",tR=P.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=hn(t);return d.jsx(TD,{...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)"}})});tR.displayName=Bne;var eb=WD,tb=VD,Og=YD,nb=qD,Une=ZD,Hne=QD,Kne=JD,Wne=Nne,Gne=eR,Vne=tR;function Qi({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=ui(e);return d.jsx(eb,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function Ji({children:e,...n}){return d.jsx(tb,{dir:"ltr",asChild:!0,onTouchEnd:t=>Ee(t),...n,children:e})}function ea({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=un();return d.jsx(Og,{container:s,children:d.jsx(nb,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function Yne({id:e,children:n}){const[t,r]=ui(e);return d.jsx(Wne,{open:t,onOpenChange:r,children:n})}function Xne({id:e,label:n,title:t,disabled:r}){return d.jsx(Gne,{dir:"ltr",asChild:!0,disabled:r,children:d.jsxs(he,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[d.jsx(bt,{children:n}),d.jsx(be,{icon:"chevron-right",small:!0})]})})}function qne({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=un();return d.jsx(Og,{container:s,children:d.jsx(Vne,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function Zne({children:e}){return d.jsx(Une,{dir:"ltr",className:"tlui-menu__group",children:e})}function wu({noClose:e,children:n}){return d.jsx(Hne,{dir:"ltr",asChild:!0,onClick:e?Ee:void 0,children:n})}function Uc({children:e,visibleOnMobileLayout:n=!1}){const t=Hn();return!n&&t<yt.MOBILE?null:d.jsx("kbd",{className:"tlui-kbd",children:HD(e).map((r,o)=>d.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:l,isSelected:c}){const{type:u,sourceId:h}=Tg(),p=Te(),[f,S]=P.useState(!1);if(as()&&!t)return null;const x=mu(s,u),y=o?Gv(o):void 0,v=x?p(x):void 0,b=v&&y?`${v} ${y}`:v;switch(u){case"menu":return d.jsx(wu,{children:d.jsxs(he,{type:"menu","data-testid":`${h}.${r}`,disabled:e,title:b,onClick:E=>{l&&Ee(E),f?S(!1):a(h)},children:[d.jsx(bt,{children:v}),o&&d.jsx(Uc,{children:o})]})});case"context-menu":return e?null:d.jsxs($D,{dir:"ltr",title:b,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${h}.${r}`,onSelect:E=>{l&&Ee(E),f?S(!1):a(h)},children:[d.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&d.jsx(Uc,{children:o}),n&&d.jsx(xne,{})]});case"panel":return d.jsxs(he,{"data-testid":`${h}.${r}`,type:"menu",title:b,disabled:e,onClick:()=>a(h),children:[d.jsx(bt,{children:v}),i&&d.jsx(be,{icon:i})]});case"small-icons":case"icons":return d.jsx(he,{"data-testid":`${h}.${r}`,type:"icon",title:b,disabled:e,onClick:()=>a(h),children:d.jsx(be,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return o?d.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${h}.${r}`,children:[d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),d.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:d.jsx(Uc,{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 d.jsxs(he,{type:"low",onClick:()=>a(h),children:[d.jsx(be,{icon:i}),d.jsx(bt,{children:v})]});case"toolbar":return d.jsx(he,{type:"tool","data-testid":`tools.${r}`,"aria-label":x,"data-value":r,onClick:()=>a("toolbar"),title:b,onTouchStart:E=>{Ee(E),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:d.jsx(be,{icon:i})});case"toolbar-overflow":return d.jsx(wu,{"aria-label":s,children:d.jsx(he,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:b,role:"radio","aria-checked":c?"true":"false","data-value":r,children:d.jsx(be,{icon:i})})});default:throw an(u)}}function Qne(){return d.jsxs(d.Fragment,{children:[d.jsx(Jne,{}),d.jsx(ere,{}),d.jsx(tre,{}),d.jsx(nre,{}),d.jsx(rre,{}),d.jsx(ire,{}),d.jsx(are,{}),d.jsx(lre,{})]})}function Jne(){const e=ie(),n=Pn(2),t=cs(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["align-left"],disabled:!r}),d.jsx(H,{...e["align-center-horizontal"],disabled:!r}),d.jsx(H,{...e["align-right"],disabled:!r}),d.jsx(H,{...e["stretch-horizontal"],disabled:!r}),d.jsx(H,{...e["align-top"],disabled:!r}),d.jsx(H,{...e["align-center-vertical"],disabled:!r}),d.jsx(H,{...e["align-bottom"],disabled:!r}),d.jsx(H,{...e["stretch-vertical"],disabled:!r})]})}function ere(){const e=ie(),n=Pn(3),t=cs(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["distribute-horizontal"],disabled:!r}),d.jsx(H,{...e["distribute-vertical"],disabled:!r})]})}function tre(){const e=ie(),n=jO(),t=cs(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["stack-horizontal"],disabled:!r}),d.jsx(H,{...e["stack-vertical"],disabled:!r})]})}function nre(){const e=ie(),n=Pn(1),t=cs(),r=n&&t;return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["send-to-back"],disabled:!r}),d.jsx(H,{...e["send-backward"],disabled:!r}),d.jsx(H,{...e["bring-forward"],disabled:!r}),d.jsx(H,{...e["bring-to-front"],disabled:!r})]})}function rre(){return Hn()<yt.TABLET_SM?d.jsx(ore,{}):d.jsx(sre,{})}function ore(){const e=ie(),n=B(),t=G("zoom is 1",()=>n.getZoomLevel()===1,[n]);return d.jsx(H,{...e["zoom-to-100"],disabled:t})}function sre(){const e=ie(),n=Pn(1),t=cs(),r=n&&t;return d.jsx(H,{...e["rotate-ccw"],disabled:!r})}function ire(){const e=ie(),n=Pn(1),t=cs(),r=n&&t;return d.jsx(H,{...e["rotate-cw"],disabled:!r})}function are(){const e=ie(),n=RO(),t=cs(),r=n&&t;return d.jsx(H,{...e["edit-link"],disabled:!r})}function lre(){const e=OO(),n=DO();return e?d.jsx(QI,{}):n?d.jsx(cre,{}):d.jsx(QI,{})}function QI(){const e=ie(),n=Pn(2),t=cs(),r=n&&t;return d.jsx(H,{...e.group,disabled:!r})}function cre(){const e=ie();return d.jsx(H,{...e.ungroup})}const ure=P.memo(function({children:n}){const t=Te(),r=Hn(),o=as(),s=B(),i=G("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??d.jsx(Qne,{});if(!(o&&!i))return d.jsxs(N0,{id:"actions-menu",children:[d.jsx(z0,{children:d.jsx(he,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(B0,{side:r>=yt.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(kr,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function dr({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,toggle:s=!1,disabled:i=!1,checked:a=!1}){const{type:l,sourceId:c}=Tg(),u=as(),h=Te();if(u&&!r)return null;const p=mu(t,l),f=p?h(p):void 0;switch(l){case"menu":return d.jsxs(Kne,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:f,onSelect:S=>{o==null||o(c),Ee(S)},disabled:i,checked:a,children:[d.jsx(qs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),n&&d.jsx(Uc,{children:n})]});case"context-menu":return d.jsxs(yne,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:f,onSelect:S=>{o(c),Ee(S)},disabled:i,checked:a,children:[d.jsx(qs,{small:!0,icon:s?a?"toggle-on":"toggle-off":a?"check":"none"}),f&&d.jsx("span",{className:"tlui-button__label",draggable:!1,children:f}),n&&d.jsx(Uc,{children:n})]},e);default:return null}}function ge({id:e,label:n,children:t}){const{type:r,sourceId:o}=Tg(),s=Te(),i=mu(n,r),a=i?s(i):void 0;switch(r){case"panel":return d.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return d.jsx(Zne,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return d.jsx(LD,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return d.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[d.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),d.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function Kn({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=Tg(),a=un(),l=Te(),c=t?typeof t=="string"?t:t[s]??t.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return d.jsxs(Yne,{id:`${i}-sub.${e}`,children:[d.jsx(Xne,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:n,label:u,title:u}),d.jsx(qne,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:d.jsxs(dre,{id:`${i}-sub.${e}`,children:[d.jsx(zD,{dir:"ltr",disabled:n,asChild:!0,children:d.jsxs(he,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[d.jsx(bt,{children:u}),d.jsx(be,{icon:"chevron-right",small:!0})]})}),d.jsx(Q0,{container:a,children:d.jsx(BD,{"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 dre({id:e,children:n}){const[t,r]=ui(e);return d.jsx(ND,{open:t,onOpenChange:r,children:n})}function nR(){const e=ie();return ste()?d.jsx(H,{...e["toggle-auto-size"]}):null}function rR(){const e=ie();return RO()?d.jsx(H,{...e["edit-link"]}):null}function hre(){const e=ie();return Pn(1)?d.jsx(H,{...e.duplicate}):null}function oR(){const e=ie(),n=B();return G("should display flatten option",()=>{if(n.getSelectedShapeIds().length===0)return!1;const o=n.getOnlySelectedShape();return!(o&&n.isShapeOfType(o,"image"))},[n])?d.jsx(H,{...e["flatten-to-image"]}):null}function sR(){const e=ie();return OO()?d.jsx(H,{...e.group}):null}function iR(){const e=ie();return DO()?d.jsx(H,{...e.ungroup}):null}function aR(){const e=B(),n=ie();return G("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?d.jsx(H,{...n["remove-frame"]}):null}function lR(){const e=B(),n=ie();return G("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?d.jsx(H,{...n["fit-frame-to-content"]}):null}function cR(){const e=B(),n=ie();return G("selected shapes",()=>e.getSelectedShapes().length>0,[e])?d.jsx(H,{...n["toggle-lock"]}):null}function rb(){const e=ie(),n=B(),t=G("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return d.jsx(dr,{...e["toggle-transparent"],checked:t,toggle:!0})}function pre(){const e=B(),n=ie(),t=G("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return d.jsx(H,{...n["unlock-all"],disabled:!t})}function uR(){const e=B(),n=G("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=ie();return d.jsx(H,{...t["zoom-to-100"],noClose:!0,disabled:n})}function dR(){const e=B(),n=G("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=ie();return d.jsx(H,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function hR(){const e=B(),n=G("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=ie();return d.jsx(H,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function pR(){return d.jsxs(ge,{id:"clipboard",children:[d.jsx(gre,{}),d.jsx(mre,{}),d.jsx(yre,{}),d.jsx(hre,{}),d.jsx(Sre,{})]})}function fre(){var r;const e=B(),n=ie(),t=G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return d.jsxs(Kn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[d.jsxs(ge,{id:"copy-as-group",children:[d.jsx(H,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&d.jsx(H,{...n["copy-as-png"]}),d.jsx(H,{...n["copy-as-json"]})]}),d.jsx(ge,{id:"copy-as-bg",children:d.jsx(rb,{})})]})}function gre(){const e=ie(),n=Pn(1);return d.jsx(H,{...e.cut,disabled:!n})}function mre(){const e=ie(),n=ote(1);return d.jsx(H,{...e.copy,disabled:!n})}function yre(){const e=ie(),n=rte;return d.jsx(H,{...e.paste,disabled:!n})}function fR(){const e=B(),n=ie();return G("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?d.jsxs(ge,{id:"conversions",children:[d.jsx(fre,{}),d.jsxs(Kn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(ge,{id:"export-as-group",children:[d.jsx(H,{...n["export-as-svg"]}),d.jsx(H,{...n["export-as-png"]}),d.jsx(H,{...n["export-as-json"]})]}),d.jsx(ge,{id:"export-as-bg",children:d.jsx(rb,{})})]})]}):null}function gR(){const e=ie(),n=B(),t=G("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return d.jsx(H,{...e["select-all"],disabled:!t})}function Sre(){const e=ie(),n=Pn(1);return d.jsx(H,{...e.delete,disabled:!n})}function vre(){return d.jsxs(Kn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(sR,{}),d.jsx(iR,{}),d.jsx(oR,{}),d.jsx(rR,{}),d.jsx(lR,{}),d.jsx(aR,{}),d.jsx(yR,{}),d.jsx(mR,{}),d.jsx(nR,{}),d.jsx(cR,{})]})}function xre(){const e=Pn(2),n=ite(),t=ie();return e||n?d.jsxs(Kn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&d.jsxs(ge,{id:"align",children:[d.jsx(H,{...t["align-left"]}),d.jsx(H,{...t["align-center-horizontal"]}),d.jsx(H,{...t["align-right"]}),d.jsx(H,{...t["align-top"]}),d.jsx(H,{...t["align-center-vertical"]}),d.jsx(H,{...t["align-bottom"]})]}),d.jsx(wre,{}),e&&d.jsxs(ge,{id:"stretch",children:[d.jsx(H,{...t["stretch-horizontal"]}),d.jsx(H,{...t["stretch-vertical"]})]}),(e||n)&&d.jsxs(ge,{id:"flip",children:[d.jsx(H,{...t["flip-horizontal"]}),d.jsx(H,{...t["flip-vertical"]})]}),d.jsx(bre,{})]}):null}function wre(){const e=ie();return Pn(3)?d.jsxs(ge,{id:"distribute",children:[d.jsx(H,{...e["distribute-horizontal"]}),d.jsx(H,{...e["distribute-vertical"]})]}):null}function bre(){const e=ie(),n=Pn(2),t=jO();return n?d.jsxs(ge,{id:"order",children:[d.jsx(H,{...e.pack}),t&&d.jsx(H,{...e["stack-horizontal"]}),t&&d.jsx(H,{...e["stack-vertical"]})]}):null}function Pre(){const e=ie();return Pn(1)?d.jsx(Kn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ge,{id:"reorder",children:[d.jsx(H,{...e["bring-to-front"]}),d.jsx(H,{...e["bring-forward"]}),d.jsx(H,{...e["send-backward"]}),d.jsx(H,{...e["send-to-back"]})]})}):null}function Cre(){const e=B(),n=G("pages",()=>e.getPages(),[e]),t=G("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Qr(),o=ie(),s=Zr();return Pn(1)?d.jsxs(Kn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ge,{id:"pages",children:n.map(a=>d.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 l=e.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(ge,{id:"new-page",children:d.jsx(H,{...o["new-page"]})})]}):null}function mR(){const e=B(),n=ie();return G("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?d.jsx(H,{...n["convert-to-bookmark"]}):null}function yR(){const e=B(),n=ie();return G("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&As(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?d.jsx(H,{...n["convert-to-embed"]}):null}function Ire(){const e=ie(),n=B(),t=G("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return d.jsx(dr,{...e["toggle-snap-mode"],checked:t})}function Ere(){const e=ie(),n=B(),t=G("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return d.jsx(dr,{...e["toggle-tool-lock"],checked:t})}function kre(){const e=ie(),n=B(),t=G("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return d.jsx(dr,{...e["toggle-grid"],checked:t})}function _re(){const e=ie(),n=B(),t=G("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return d.jsx(dr,{...e["toggle-wrap-mode"],checked:t})}function Tre(){const e=ie(),n=B(),t=G("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return d.jsx(dr,{...e["toggle-focus-mode"],checked:t})}function Mre(){const e=ie(),n=B(),t=G("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return d.jsx(dr,{...e["toggle-edge-scrolling"],checked:t===1})}function Are(){const e=ie(),n=B(),t=G("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return d.jsx(dr,{...e["toggle-reduce-motion"],checked:t===0})}function jre(){const e=ie(),n=B(),t=G("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return d.jsx(dr,{...e["toggle-debug-mode"],checked:t})}function Ore(){const e=ie(),n=B(),t=G("dynamic resize",()=>n.user.getIsDynamicResizeMode(),[n]);return d.jsx(dr,{...e["toggle-dynamic-size-mode"],checked:t})}function Dre(){const e=B();return G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?d.jsxs(d.Fragment,{children:[d.jsxs(ge,{id:"modify",children:[d.jsx(vre,{}),d.jsx(xre,{}),d.jsx(Pre,{}),d.jsx(Cre,{})]}),d.jsx(pR,{}),d.jsx(fR,{}),d.jsx(ge,{id:"select-all",children:d.jsx(gR,{})})]}):null}const Rre=P.memo(function({children:n}){const t=B(),{Canvas:r}=it(),o=P.useCallback(c=>{if(c){if(t.getInstanceState().isCoarsePointer){const u=t.getSelectedShapes(),{inputs:{currentPagePoint:h}}=t,p=t.getShapesAtPoint(h);if(!t.getSelectedShapes().length||!p.some(f=>u.includes(f))){const f=p.filter(S=>t.isShapeOrAncestorLocked(S));f.length&&t.select(...f.map(S=>S.id))}}}else{const u=t.getOnlySelectedShape();u&&t.isShapeOrAncestorLocked(u)&&t.setSelectedShapes([])}},[t]),s=un(),[i,a]=ui("context menu",o),l=n??d.jsx(Dre,{});return d.jsxs(pne,{dir:"ltr",onOpenChange:a,modal:!1,children:[d.jsx(fne,{onContextMenu:void 0,dir:"ltr",children:r?d.jsx(r,{}):null}),i&&d.jsx(gne,{container:s,children:d.jsx(mne,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ee,children:d.jsx(kr,{type:"context-menu",sourceId:"context-menu",children:l})})})]})});function Vv({checked:e}){return d.jsx(qs,{icon:e?"check":"none",className:"tlui-button__icon",small:!0})}function Lre(){const e=B(),{addToast:n}=Qr(),{addDialog:t}=la(),[r,o]=xe.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ge,{id:"items",children:[d.jsx(H,{id:"add-toast",onSelect:()=>{n({id:ot(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),n({id:ot(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"info",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),n({id:ot(),title:"Something maybe bad happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"warning",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),n({id:ot(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),d.jsx(H,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>d.jsx(Nre,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),d.jsx(H,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>zre(e,100)}),d.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})(),d.jsx(H,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),d.jsx(H,{id:"hard-reset",onSelect:sT,label:"Hard reset"})]}),d.jsxs(ge,{id:"flags",children:[d.jsx($re,{}),d.jsx(Fre,{})]})]})}function $re(){const e=Object.values(xt);return e.length?d.jsx(Kn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ge,{id:"debug flags",children:e.map(n=>d.jsx(SR,{flag:n},n.name))})}):null}function Fre(){const e=Object.values(Z6);return e.length?d.jsx(Kn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ge,{id:"feature flags",children:e.map(n=>d.jsx(SR,{flag:n},n.name))})}):null}function Nre({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=xe.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(bg,{children:[d.jsx(Pg,{children:e}),d.jsx(Cg,{})]}),d.jsx(gu,{style:{maxWidth:350},children:n}),d.jsxs(C0,{className:"tlui-dialog__footer__actions",children:[o&&d.jsxs(he,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(Vv,{checked:a}),d.jsx(bt,{children:"Don’t show again"})]}),d.jsx(he,{type:"normal",onClick:s,children:d.jsx(bt,{children:t})}),d.jsx(he,{type:"primary",onClick:async()=>i(),children:d.jsx(bt,{children:r})})]})]})}const SR=ar(function({flag:n,onChange:t}){const r=n.get();return d.jsx(dr,{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 JI=0;function zre(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)JI++,t[o]={id:$e("box"+JI),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function Bre({children:e}){const n=e??d.jsx(Lre,{});return d.jsxs(Qi,{id:"debug",children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(ea,{side:"top",align:"end",alignOffset:0,children:d.jsx(kr,{type:"menu",sourceId:"debug-panel",children:n})})]})}const Ure=P.memo(function(){const{DebugMenu:n}=pi();return d.jsxs("div",{className:"tlui-debug-panel",children:[d.jsx(Kre,{}),d.jsx(Wre,{}),n&&d.jsx(n,{})]})});function Hre(e=!0){const[n,t]=P.useState(0),r=B();P.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const Kre=ar(function(){Hre();const n=B(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),s=t==="select.idle"||!t.includes("select.")?r:o,i=s&&t.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${w.ToInt(n.getPointInShapeSpace(s,n.inputs.currentPagePoint))}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${w.ToInt(n.inputs.originPagePoint)}] → [${w.ToInt(n.inputs.currentPagePoint)}] = ${w.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return d.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function Wre(){const e=B(),n=G("show_fps",()=>xt.showFps.get(),[xt]),t=P.useRef(null);return P.useEffect(()=>{if(!n)return;const r=250;let o=0,s=-1,i=performance.now(),a=0,l=0,c=!1;function u(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>o&&(o=h);const p=o*.75;(h<p&&!c||h>=p&&c)&&(c=!c),t.current.innerHTML=`FPS ${h.toString()}`,t.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}s=e.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(s)}},[n,e]),n?d.jsx("div",{ref:t}):null}function vR(){const e=B(),n=Zr(),t=G("locale",()=>e.user.getLocale(),[e]);return d.jsx(Kn,{id:"help menu language",label:"menu.language",children:d.jsx(ge,{id:"languages",children:Xc.map(({locale:r,label:o})=>d.jsx(dr,{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 Gre(){return d.jsxs(d.Fragment,{children:[d.jsx(vR,{}),d.jsx(Vre,{})]})}function Vre(){const{KeyboardShortcutsDialog:e}=pi(),{addDialog:n}=la();return e?d.jsx(H,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const Yre=P.memo(function({children:n}){const t=Te(),r=Hn(),o=n??d.jsx(Gre,{});return r<yt.MOBILE?null:d.jsx("div",{className:"tlui-help-menu",children:d.jsxs(Qi,{id:"help menu",children:[d.jsx(Ji,{children:d.jsx(he,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(be,{icon:"question-mark",small:!0})})}),d.jsx(ea,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(kr,{type:"menu",sourceId:"help-menu",children:o})})]})})});function Xre(){const e=B(),n=ie(),[t,r]=P.useState(!1),o=P.useRef(!1);return Os("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?d.jsx(H,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function qre(){const e=B(),n=ie();return G("is pen mode",()=>e.getInstanceState().isPenMode,[e])?d.jsx(H,{...n["exit-pen-mode"]}):null}function Zre(){const e=B(),n=ie();return G("is following user",()=>!!e.getInstanceState().followingUserId,[e])?d.jsx(H,{...n["stop-following"]}):null}function Qre(){return d.jsxs(d.Fragment,{children:[d.jsx(qre,{}),d.jsx(Xre,{}),d.jsx(Zre,{})]})}function Jre({children:e}){const n=e??d.jsx(Qre,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(kr,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}function eoe(){const e=ie(),n=Ig();return d.jsxs(d.Fragment,{children:[d.jsxs(ge,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(H,{...e["toggle-tool-lock"]}),d.jsx(H,{...e["insert-media"]}),d.jsx(H,{...n.select}),d.jsx(H,{...n.draw}),d.jsx(H,{...n.eraser}),d.jsx(H,{...n.hand}),d.jsx(H,{...n.rectangle}),d.jsx(H,{...n.ellipse}),d.jsx(H,{...n.arrow}),d.jsx(H,{...n.line}),d.jsx(H,{...n.text}),d.jsx(H,{...n.frame}),d.jsx(H,{...n.note}),d.jsx(H,{...n.laser})]}),d.jsxs(ge,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(H,{...e["toggle-dark-mode"]}),d.jsx(H,{...e["toggle-focus-mode"]}),d.jsx(H,{...e["toggle-grid"]})]}),d.jsxs(ge,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(H,{...e.undo}),d.jsx(H,{...e.redo}),d.jsx(H,{...e.cut}),d.jsx(H,{...e.copy}),d.jsx(H,{...e.paste}),d.jsx(H,{...e["select-all"]}),d.jsx(H,{...e.delete}),d.jsx(H,{...e.duplicate})]}),d.jsxs(ge,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(H,{...e["zoom-in"]}),d.jsx(H,{...e["zoom-out"]}),d.jsx(H,{...e["zoom-to-100"]}),d.jsx(H,{...e["zoom-to-fit"]}),d.jsx(H,{...e["zoom-to-selection"]})]}),d.jsxs(ge,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(H,{...e["bring-to-front"]}),d.jsx(H,{...e["bring-forward"]}),d.jsx(H,{...e["send-backward"]}),d.jsx(H,{...e["send-to-back"]}),d.jsx(H,{...e.group}),d.jsx(H,{...e.ungroup}),d.jsx(H,{...e["flip-horizontal"]}),d.jsx(H,{...e["flip-vertical"]}),d.jsx(H,{...e["align-top"]}),d.jsx(H,{...e["align-center-vertical"]}),d.jsx(H,{...e["align-bottom"]}),d.jsx(H,{...e["align-left"]}),d.jsx(H,{...e["align-center-horizontal"]}),d.jsx(H,{...e["align-right"]})]})]})}const toe=P.memo(function({children:n}){const t=Te(),r=Hn(),o=n??d.jsx(eoe,{});return d.jsxs(d.Fragment,{children:[d.jsxs(bg,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(Pg,{children:t("shortcuts-dialog.title")}),d.jsx(Cg,{})]}),d.jsx(gu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=yt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=yt.TABLET}),children:d.jsx(kr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})}),noe=[{colorScheme:"light",label:"theme.light"},{colorScheme:"dark",label:"theme.dark"},{colorScheme:"system",label:"theme.system"}];function roe(){const e=B(),n=Zr(),t=G("colorScheme",()=>e.user.getUserPreferences().colorScheme,[e]);return d.jsx(Kn,{id:"help menu color-scheme",label:"menu.theme",children:d.jsx(ge,{id:"languages",children:noe.map(({colorScheme:r,label:o})=>d.jsx(dr,{id:`color-scheme-${r}`,label:o,checked:r===t,onSelect:()=>{e.user.updateUserPreferences({colorScheme:r}),n("color-scheme",{source:"menu",value:r})}},r))})})}function ooe(){return d.jsxs(d.Fragment,{children:[d.jsx(ioe,{}),d.jsx(uoe,{}),d.jsx(soe,{}),d.jsx(doe,{}),d.jsx(hoe,{})]})}function soe(){const e=ie();return d.jsxs(Kn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(ge,{id:"export-all-as-group",children:[d.jsx(H,{...e["export-all-as-svg"]}),d.jsx(H,{...e["export-all-as-png"]}),d.jsx(H,{...e["export-all-as-json"]})]}),d.jsx(ge,{id:"export-all-as-bg",children:d.jsx(rb,{})})]})}function ioe(){const e=B(),n=G("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return d.jsxs(Kn,{id:"edit",label:"menu.edit",disabled:!n,children:[d.jsx(coe,{}),d.jsx(pR,{}),d.jsx(fR,{}),d.jsx(aoe,{}),d.jsx(loe,{}),d.jsx(ge,{id:"select-all",children:d.jsx(gR,{})})]})}function aoe(){return d.jsxs(ge,{id:"misc",children:[d.jsx(sR,{}),d.jsx(iR,{}),d.jsx(rR,{}),d.jsx(nR,{}),d.jsx(aR,{}),d.jsx(lR,{}),d.jsx(yR,{}),d.jsx(mR,{}),d.jsx(oR,{})]})}function loe(){return d.jsxs(ge,{id:"lock",children:[d.jsx(cR,{}),d.jsx(pre,{})]})}function coe(){const e=ie(),n=$O(),t=LO();return d.jsxs(ge,{id:"undo-redo",children:[d.jsx(H,{...e.undo,disabled:!n}),d.jsx(H,{...e.redo,disabled:!t})]})}function uoe(){const e=ie();return d.jsx(Kn,{id:"view",label:"menu.view",children:d.jsxs(ge,{id:"view-actions",children:[d.jsx(H,{...e["zoom-in"]}),d.jsx(H,{...e["zoom-out"]}),d.jsx(uR,{}),d.jsx(dR,{}),d.jsx(hR,{})]})})}function doe(){const e=ie();return d.jsxs(ge,{id:"extras",children:[d.jsx(H,{...e["insert-embed"]}),d.jsx(H,{...e["insert-media"]})]})}function hoe(){return d.jsx(ge,{id:"preferences",children:d.jsxs(Kn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ge,{id:"preferences-actions",children:[d.jsx(Ire,{}),d.jsx(Ere,{}),d.jsx(kre,{}),d.jsx(_re,{}),d.jsx(Tre,{}),d.jsx(Mre,{}),d.jsx(Are,{}),d.jsx(Ore,{}),d.jsx(jre,{})]}),d.jsx(ge,{id:"color-scheme",children:d.jsx(roe,{})}),d.jsx(ge,{id:"language",children:d.jsx(vR,{})})]})})}const poe=P.memo(function({children:n}){const t=un(),[r,o]=ui("main menu"),s=Te(),i=n??d.jsx(ooe,{});return d.jsxs(eb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(tb,{asChild:!0,dir:"ltr",children:d.jsx(he,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:d.jsx(be,{icon:"menu",small:!0})})}),d.jsx(Og,{container:t,children:d.jsx(nb,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(kr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),foe=P.memo(function(){const n=Hn(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=pi();return!t&&!s&&n<6?null:d.jsx("div",{className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&d.jsx(t,{}),s&&d.jsx(s,{}),n<6?null:d.jsxs(d.Fragment,{children:[r&&d.jsx(r,{}),o&&d.jsx(o,{})]})]})})}),Ey={};function pc(e){if(Ey[e])return Ey[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 Ey[e]=a,a}const pp=10,xR=4*6*pp+12+4*12;function Ca(e,{center:n,radius:t,numArcSegments:r=20,startAngle:o=0,endAngle:s=Re,offset:i=0}){const a=(s-o)/r;let l=i;for(let c=o;c<s;c+=a)e[l++]=n.x,e[l++]=n.y,e[l++]=n.x+Math.cos(c)*t,e[l++]=n.y+Math.sin(c)*t,e[l++]=n.x+Math.cos(c+a)*t,e[l++]=n.y+Math.sin(c+a)*t;return e}function Ia(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 goe(e,n,t){const r=pp;t=Math.min(t,Math.min(n.w,n.h)/2);const o=Z.ExpandBy(n,-t);if(o.w<=0||o.h<=0)return Ca(e,{center:n.center,radius:t,numArcSegments:pp*4}),pp*4*6;let s=0;return Ia(e,s,o.minX,o.minY,o.w,o.h),s+=12,Ia(e,s,o.minX,n.minY,o.w,t),s+=12,Ia(e,s,o.maxX,o.minY,t,o.h),s+=12,Ia(e,s,o.minX,o.maxY,o.w,t),s+=12,Ia(e,s,n.minX,o.minY,t,o.h),s+=12,Ca(e,{numArcSegments:r,offset:s,center:o.point,radius:t,startAngle:ke,endAngle:ke*1.5}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,new w(o.w,0)),radius:t,startAngle:ke*1.5,endAngle:Re}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,o.size),radius:t,startAngle:0,endAngle:Ge}),s+=r*6,Ca(e,{numArcSegments:r,offset:s,center:w.Add(o.point,new w(0,o.h)),radius:t,startAngle:Ge,endAngle:ke}),xR}function moe(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
|
|
286
|
-
precision mediump float;
|
|
287
|
-
|
|
288
|
-
in vec2 shapeVertexPosition;
|
|
289
|
-
|
|
290
|
-
uniform vec4 canvasPageBounds;
|
|
291
|
-
|
|
292
|
-
// taken (with thanks) from
|
|
293
|
-
// https://webglfundamentals.org/webgl/lessons/webgl-2d-matrices.html
|
|
294
|
-
void main() {
|
|
295
|
-
// convert the position from pixels to 0.0 to 1.0
|
|
296
|
-
vec2 zeroToOne = (shapeVertexPosition - canvasPageBounds.xy) / canvasPageBounds.zw;
|
|
297
|
-
|
|
298
|
-
// convert from 0->1 to 0->2
|
|
299
|
-
vec2 zeroToTwo = zeroToOne * 2.0;
|
|
300
|
-
|
|
301
|
-
// convert from 0->2 to -1->+1 (clipspace)
|
|
302
|
-
vec2 clipSpace = zeroToTwo - 1.0;
|
|
303
|
-
|
|
304
|
-
gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1);
|
|
305
|
-
}`,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
|
|
306
|
-
precision mediump float;
|
|
307
|
-
|
|
308
|
-
uniform vec4 fillColor;
|
|
309
|
-
out vec4 outputColor;
|
|
310
|
-
|
|
311
|
-
void main() {
|
|
312
|
-
outputColor = fillColor;
|
|
313
|
-
}`,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 l=n.getUniformLocation(i,"canvasPageBounds"),c=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:lh(n,1024),unselectedShapes:lh(n,4096),viewport:lh(n,xR),collaborators:lh(n,1024),prepareTriangles(p,f){n.bindBuffer(n.ARRAY_BUFFER,p.buffer),n.bufferData(n.ARRAY_BUFFER,p.vertices,n.STATIC_DRAW,0,f),n.enableVertexAttribArray(a),n.vertexAttribPointer(a,2,n.FLOAT,!1,0,0)},drawTrianglesTransparently(p){n.enable(n.BLEND),n.blendFunc(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA),n.drawArrays(n.TRIANGLES,0,p/2),n.disable(n.BLEND)},drawTriangles(p){n.drawArrays(n.TRIANGLES,0,p/2)},setFillColor(p){n.uniform4fv(c,p)},setCanvasPageBounds(p){n.uniform4fv(l,p)}}}function lh(e,n){const t=e.createBuffer();if(!t)throw new Error("Failed to create buffer");return{buffer:t,vertices:new Float32Array(n)}}function eE(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 yoe=Object.defineProperty,Soe=Object.getOwnPropertyDescriptor,hi=(e,n,t,r)=>{for(var o=Soe(n,t),s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=i(n,t,o)||o);return o&&yoe(n,t,o),o};class us{constructor(n,t,r){g(this,"disposables",[]);g(this,"close",()=>this.disposables.forEach(n=>n()));g(this,"gl");g(this,"shapeGeometryCache");g(this,"colors");g(this,"id",ot());g(this,"canvasBoundingClientRect",Mt("canvasBoundingClientRect",new Z));g(this,"originPagePoint",new w);g(this,"originPageCenter",new w);g(this,"isInViewport",!1);g(this,"getMinimapPagePoint",(n,t)=>{const r=this.getCanvasPageBounds(),o=this.getCanvasScreenBounds();let s=n-o.x,i=t-o.y;return s*=r.width/o.width,i*=r.height/o.height,s+=r.minX,i+=r.minY,new w(s,i,1)});g(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(n,t);if(o){const c=this.editor.getCurrentPageBounds()??new Z,u=c.minX-i.width/2,h=c.maxX+i.width/2,p=c.minY-i.height/2,f=c.maxY+i.height/2,S=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),x=Math.max(0,p+i.height-l),y=Math.max(0,-(f-i.height-l));a+=(S-m)/2,l+=(x-y)/2,a=_t(a,u,h),l=_t(l,p,f)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new w(a,l)});g(this,"render",()=>{const n=this.gl.context,t=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=t.x,this.elem.height=t.y,n.viewport(0,0,t.x,t.y),n.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),n.clear(n.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),o=this.colors;let s=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const p=h.length;r.has(u)?(eE(this.gl.selectedShapes,s,h),s+=p):(eE(this.gl.unselectedShapes,i,h),i+=p)}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=moe(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 Ia(i,0,s.x,s.y,s.w,s.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),oa("minimap render",this.render))}_getColors(){const n=getComputedStyle(this.editor.getContainer());return{shapeFill:pc(n.getPropertyValue("--color-text-3").trim()),selectFill:pc(n.getPropertyValue("--color-selected").trim()),viewportFill:pc(n.getPropertyValue("--color-muted-1").trim()),background:pc(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?Z.Expand(t,n):n}getContentScreenBounds(){const n=this.getContentPageBounds(),t=this.editor.pageToScreen(n.point),r=this.editor.pageToScreen(new w(n.maxX,n.maxY));return new Z(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 Z(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 w(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 Z(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=goe(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:l}of n)Ca(s,{center:w.From(l),radius:3*a,offset:i,numArcSegments:t}),i+=r;this.gl.prepareTriangles(this.gl.collaborators,o),i=0;for(const{color:l}of n)this.gl.setFillColor(pc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}hi([V],us.prototype,"getDpr");hi([V],us.prototype,"getContentPageBounds");hi([V],us.prototype,"getContentScreenBounds");hi([V],us.prototype,"getCanvasSize");hi([V],us.prototype,"getCanvasClientPosition");hi([V],us.prototype,"getCanvasPageBounds");hi([V],us.prototype,"getZoom");hi([V],us.prototype,"getCanvasPageBoundsArray");function voe(){const e=B(),n=un(),t=P.useRef(null),r=P.useRef(!1),o=P.useRef();P.useEffect(()=>{try{const u=new us(e,t.current,n);return o.current=u,o.current.close}catch(u){e.annotateError(u,{origin:"minimap",willCrashApp:!1}),e.timers.setTimeout(()=>{throw u})}},[e,n]);const s=P.useCallback(u=>{if(!e.getCurrentPageShapeIds().size||!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.originPagePoint.setTo(p),o.current.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(h,{animation:{duration:e.options.animationMediumMs}})},[e]),i=P.useCallback(u=>{if(!o.current)return;const h=u.currentTarget;if(Du(h,u),!e.getCurrentPageShapeIds().size)return;r.current=!0,o.current.isInViewport=!1;const p=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=e.getViewportPageBounds(),S=o.current.getContentPageBounds();if(new Z(S.x-f.width/2,S.y-f.height/2,S.width+f.width,S.height+f.height).containsPoint(p)&&!f.containsPoint(p)){o.current.isInViewport=f.containsPoint(p);const y=w.Sub(f.center,f.point),v=w.Add(p,y);o.current.originPagePoint.setTo(v),o.current.originPageCenter.setTo(p),e.centerOnPoint(p,{animation:{duration:e.options.animationMediumMs}})}else{const y=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);o.current.isInViewport=f.containsPoint(y),o.current.originPagePoint.setTo(y),o.current.originPageCenter.setTo(f.center)}function x(y){h&&Ru(h,y),r.current=!1,document.body.removeEventListener("pointerup",x)}document.body.addEventListener("pointerup",x)},[e]),a=P.useCallback(u=>{if(!o.current)return;const h=o.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(o.current.isInViewport){const m=o.current.originPagePoint.clone().sub(o.current.originPageCenter);e.centerOnPoint(w.Sub(h,m));return}e.centerOnPoint(h)}const p=o.current.getMinimapPagePoint(u.clientX,u.clientY),f=e.pageToScreen(p),S={type:"pointer",target:"canvas",name:"pointer_move",...On(u),point:f,isPen:e.getInstanceState().isPenMode};e.dispatch(S)},[e]),l=P.useCallback(u=>{const h=X_(u);e.dispatch({type:"wheel",name:"wheel",delta:h,point:new w(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey})},[e]),c=Ku();return P.useEffect(()=>{e.timers.setTimeout(()=>{var u,h;(u=o.current)==null||u.updateColors(),(h=o.current)==null||h.render()})},[c,e]),d.jsx("div",{className:"tlui-minimap",children:d.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:s,onPointerMove:a,onPointerDown:i,onWheel:l})})}function xoe(e,n){const[t,r]=xe.useState(n);xe.useLayoutEffect(()=>{const s=Mx(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=xe.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return Ax(e,JSON.stringify(a)),a})},[e]);return[t,o]}const woe=P.memo(function(){const n=ie(),t=Te(),r=Hn(),[o,s]=xoe("minimap",!0),i=P.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=pi();return r<yt.MOBILE?null:d.jsxs("div",{className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<yt.TABLET?d.jsx(a,{}):o?d.jsxs(d.Fragment,{children:[a&&d.jsx(a,{}),l&&d.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(he,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(mu(n["zoom-out"].label))} ${Gv(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"minus"})}),a&&d.jsx(a,{}),d.jsx(he,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(mu(n["zoom-in"].label))} ${Gv(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"plus"})}),l&&d.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=yt.TABLET&&!o&&d.jsx(l,{})]})}),boe=function({name:n,id:t,isCurrentPage:r}){const o=B(),s=P.useRef(null),i=P.useCallback(()=>{o.mark("rename page")},[o]),a=P.useCallback(l=>{o.renamePage(t,l||"New Page")},[o,t]);return d.jsx(I0,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:n,onValueChange:a,onFocus:i,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},Yv=(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=$o(i.index):!i&&a?o=N4(s[0].index):o=Gc(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},tE=ar(function({index:n,listSize:t,item:r,onRename:o}){const s=B(),i=Te(),a=s.getPages(),l=P.useCallback(()=>{s.mark("creating page");const p=Xo.createId();s.duplicatePage(r.id,p)},[s,r]),c=P.useCallback(()=>{Yv(s,r.id,n,n-1)},[s,r,n]),u=P.useCallback(()=>{Yv(s,r.id,n,n+1)},[s,r,n]),h=P.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return d.jsxs(Qi,{id:`page item submenu ${n}`,children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical"})})}),d.jsx(ea,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(kr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ge,{id:"modify",children:[o&&d.jsx(H,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),d.jsx(H,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:a.length>=s.options.maxPages}),n>0&&d.jsx(H,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),n<t-1&&d.jsx(H,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),t>1&&d.jsx(ge,{id:"delete",children:d.jsx(H,{id:"delete",onSelect:h,label:"page-menu.submenu.delete"})})]})})]})}),Poe=P.memo(function(){const n=B(),t=Te(),r=Hn(),o=P.useCallback(()=>x(!1),[]),[s,i]=ui("page-menu",o),a=36,l=P.useRef(null),c=G("pages",()=>n.getPages(),[n]),u=G("currentPage",()=>n.getCurrentPage(),[n]),h=G("currentPageId",()=>n.getCurrentPageId(),[n]),p=as(),f=G("maxPageCountReached",()=>n.getPages().length>=n.options.maxPages,[n]),S=G("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[m,x]=P.useState(!1),y=P.useCallback(()=>{p||x(_=>!_)},[p]),v=P.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[b,E]=P.useState(Object.fromEntries(c.map((_,A)=>[_.id,{y:A*a,offsetY:0,isSelected:!1}])));P.useLayoutEffect(()=>{E(Object.fromEntries(c.map((_,A)=>[_.id,{y:A*a,offsetY:0,isSelected:!1}])))},[a,c]),P.useEffect(()=>{s&&n.timers.requestAnimationFrame(()=>{const _=document.querySelector(`[data-testid="page-menu-item-${h}"]`);if(_){const A=l.current;if(!A)return;const L=_.offsetTop,j=A.scrollTop;L<j&&A.scrollTo({top:L});const R=L+a,F=A.scrollTop+A.offsetHeight;R>F&&A.scrollTo({top:R-A.offsetHeight})}})},[a,h,s,n]);const I=P.useCallback(_=>{const{clientY:A,currentTarget:L}=_,{dataset:{id:j,index:R}}=L;if(!j||!R)return;const F=v.current;Du(_.currentTarget,_),F.status="pointing",F.pointing={id:j,index:+R};const K=b[j].y;F.startY=A,F.startIndex=Math.max(0,Math.min(Math.round(K/a),c.length-1))},[a,c.length,b]),C=P.useCallback(_=>{const A=v.current;if(A.status==="pointing"){const{clientY:L}=_,j=L-A.startY;Math.abs(j)>5&&(A.status="dragging")}if(A.status==="dragging"){const{clientY:L}=_,j=L-A.startY,R=b[A.pointing.id],{startIndex:F,pointing:W}=A,K=R.y+j,z=Math.max(0,Math.min(Math.round(K/a),c.length-1)),U={...b};if(U[W.id]={y:R.y,offsetY:j,isSelected:!0},z!==A.dragIndex){A.dragIndex=z;for(let X=0;X<c.length;X++){const J=c[X];if(J.id===A.pointing.id)continue;let{y:le}=U[J.id];z===F?le=X*a:z<F?z<=X&&X<F?le=(X+1)*a:le=X*a:z>F&&(z>=X&&X>F?le=(X-1)*a:le=X*a),le!==U[J.id].y&&(U[J.id]={y:le,offsetY:0,isSelected:!0})}}E(U)}},[a,c,b]),k=P.useCallback(_=>{const A=v.current;if(A.status==="dragging"){const{id:L,index:j}=A.pointing;Yv(n,L,j,A.dragIndex)}Ru(_.currentTarget,_),A.status="idle"},[n]),T=P.useCallback(_=>{const A=v.current;_.key==="Escape"&&(A.status==="dragging"&&E(Object.fromEntries(c.map((L,j)=>[L.id,{y:j*a,offsetY:0,isSelected:!1}]))),A.status="idle")},[a,c]),O=P.useCallback(()=>{p||n.batch(()=>{n.mark("creating page");const _=Xo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:_}),n.setCurrentPage(_),x(!0)})},[n,t,p]);return d.jsxs(N0,{id:"pages",onOpenChange:i,open:s,children:[d.jsx(z0,{"data-testid":"main.page-menu",children:d.jsxs(he,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:u.name}),d.jsx(be,{icon:"chevron-down",small:!0})]})}),d.jsx(B0,{side:"bottom",align:"start",sideOffset:6,children:d.jsxs("div",{className:"tlui-page-menu__wrapper",children:[d.jsxs("div",{className:"tlui-page-menu__header",children:[d.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!p&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(he,{type:"icon","data-testid":"page-menu.edit",title:t(m?"page-menu.edit-done":"page-menu.edit-start"),onClick:y,children:d.jsx(be,{icon:m?"check":"edit"})}),d.jsx(he,{type:"icon","data-testid":"page-menu.create",title:t(f?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:f,onClick:O,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*c.length+4},ref:l,children:c.map((_,A)=>{const L=b[_.id]??{position:A*40,offsetY:0};return m?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:_.id===u.id?888:A,transform:`translate(0px, ${L.y+L.offsetY}px)`},children:[d.jsx(he,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:I,onPointerUp:k,onPointerMove:C,onKeyDown:T,"data-id":_.id,"data-index":A,children:d.jsx(be,{icon:"drag-handle-dots"})}),r<yt.TABLET_SM&&S?d.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const j=window.prompt("Rename page",_.name);j&&j!==_.name&&n.renamePage(_.id,j)},onDoubleClick:y,children:[d.jsx(Vv,{checked:_.id===u.id}),d.jsx(bt,{children:_.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:d.jsx(boe,{id:_.id,name:_.name,isCurrentPage:_.id===u.id})}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":m,children:d.jsx(tE,{index:A,item:_,listSize:c.length})})]},_.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(_.id),onDoubleClick:y,title:t("page-menu.go-to-page"),children:[d.jsx(Vv,{checked:_.id===u.id}),d.jsx(bt,{children:_.name})]}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(tE,{index:A,item:_,listSize:c.length,onRename:()=>{if(n.environment.isIos){const j=window.prompt("Rename page",_.name);j&&j!==_.name&&n.renamePage(_.id,j)}else n.batch(()=>{x(!0),n.setCurrentPage(_.id)})}})})]},_.id)})})]})})]})});function Coe(){const e=ie(),n=B(),t=$O(),r=LO(),o=Pn(1),s=as(),i=G("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]),a=cs(),l=o&&a;if(!(s&&!i))return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e.undo,disabled:!t}),d.jsx(H,{...e.redo,disabled:!r}),d.jsx(H,{...e.delete,disabled:!l}),d.jsx(H,{...e.duplicate,disabled:!l})]})}const Ioe=P.memo(function({children:n}){const t=n??d.jsx(Coe,{});return d.jsx(kr,{type:"small-icons",sourceId:"quick-actions",children:t})}),Eoe=Object.freeze([sr,Ni,zi,xo]);function wR(e=Eoe){const n=B();return G("getRelevantStyles",()=>{var s;const t=new Sv(n.getSharedStyles()),r=!!((s=n.root.getCurrent())!=null&&s.shapeType),o=n.isIn("select")&&n.getSelectedShapeIds().length>0;if(t.size===0&&n.isIn("select")&&n.getSelectedShapeIds().length===0)for(const i of e)t.applyValue(i,n.getStyleForNextShape(i));return r||o||t.size>0?t:null},[n])}const br={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Mi=P.memo(function(n){const{uiType:t,items:r,title:o,style:s,value:i,onValueChange:a,theme:l}=n,c=B(),u=Te(),h=P.useRef(!1),p=P.useRef(null),{handleButtonClick:f,handleButtonPointerDown:S,handleButtonPointerEnter:m,handleButtonPointerUp:x}=P.useMemo(()=>{const y=()=>{h.current=!1,window.removeEventListener("pointerup",y);const C=p.current;C&&["TEXTAREA","INPUT"].includes(C.nodeName)&&C.focus(),p.current=null};return{handleButtonClick:C=>{const{id:k}=C.currentTarget.dataset;i.type==="shared"&&i.value===k||(c.mark("point picker item"),a(s,k))},handleButtonPointerDown:C=>{const{id:k}=C.currentTarget.dataset;c.mark("point picker item"),a(s,k),h.current=!0,p.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:C=>{if(!h.current)return;const{id:k}=C.currentTarget.dataset;a(s,k)},handleButtonPointerUp:C=>{const{id:k}=C.currentTarget.dataset;i.type==="shared"&&i.value===k||a(s,k)}}},[i,c,a,s]);return d.jsx("div",{"data-testid":`style.${t}`,className:ce("tlui-buttons__grid"),children:r.map(y=>d.jsx(he,{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+" — "+u(`${t}-style.${y.value}`),className:ce("tlui-button-grid__button"),style:s===sr?{color:l[y.value].solid}:void 0,onPointerEnter:m,onPointerDown:S,onPointerUp:x,onClick:f,children:d.jsx(be,{icon:y.icon})},y.value))})});function bR(e,[n,t]){return Math.min(t,Math.max(n,e))}function koe(e){const n=P.useRef({value:e,previous:e});return P.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}var PR=["PageUp","PageDown"],CR=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],IR={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},zl="Slider",[Xv,_oe,Toe]=vg(zl),[ER,Zie]=ko(zl,[Toe]),[Moe,Dg]=ER(zl),kR=P.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...S}=e,m=P.useRef(new Set),x=P.useRef(0),v=i==="horizontal"?Aoe:joe,[b=[],E]=li({prop:u,defaultProp:c,onChange:_=>{var L;(L=[...m.current][x.current])==null||L.focus(),h(_)}}),I=P.useRef(b);function C(_){const A=$oe(b,_);O(_,A)}function k(_){O(_,x.current)}function T(){const _=I.current[x.current];b[x.current]!==_&&p(b)}function O(_,A,{commit:L}={commit:!1}){const j=Boe(s),R=Uoe(Math.round((_-r)/s)*s+r,j),F=bR(R,[r,o]);E((W=[])=>{const K=Roe(W,F,A);if(zoe(K,l*s)){x.current=K.indexOf(F);const z=String(K)!==String(W);return z&&L&&p(K),z?K:W}else return W})}return d.jsx(Moe,{scope:e.__scopeSlider,name:t,disabled:a,min:r,max:o,valueIndexToChangeRef:x,thumbs:m.current,values:b,orientation:i,children:d.jsx(Xv.Provider,{scope:e.__scopeSlider,children:d.jsx(Xv.Slot,{scope:e.__scopeSlider,children:d.jsx(v,{"aria-disabled":a,"data-disabled":a?"":void 0,...S,ref:n,onPointerDown:re(S.onPointerDown,()=>{a||(I.current=b)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:C,onSlideMove:a?void 0:k,onSlideEnd:a?void 0:T,onHomeKeyDown:()=>!a&&O(r,0,{commit:!0}),onEndKeyDown:()=>!a&&O(o,b.length-1,{commit:!0}),onStepKeyDown:({event:_,direction:A})=>{if(!a){const R=PR.includes(_.key)||_.shiftKey&&CR.includes(_.key)?10:1,F=x.current,W=b[F],K=s*R*A;O(W+K,F,{commit:!0})}}})})})})});kR.displayName=zl;var[_R,TR]=ER(zl,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Aoe=P.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[h,p]=P.useState(null),f=Ye(n,b=>p(b)),S=P.useRef(),m=U0(o),x=m==="ltr",y=x&&!s||!x&&s;function v(b){const E=S.current||h.getBoundingClientRect(),I=[0,E.width],k=ob(I,y?[t,r]:[r,t]);return S.current=E,k(b-E.left)}return d.jsx(_R,{scope:e.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:d.jsx(MR,{dir:m,"data-orientation":"horizontal",...u,ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const E=v(b.clientX);i==null||i(E)},onSlideMove:b=>{const E=v(b.clientX);a==null||a(E)},onSlideEnd:()=>{S.current=void 0,l==null||l()},onStepKeyDown:b=>{const I=IR[y?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:I?-1:1})}})})}),joe=P.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=P.useRef(null),h=Ye(n,u),p=P.useRef(),f=!o;function S(m){const x=p.current||u.current.getBoundingClientRect(),y=[0,x.height],b=ob(y,f?[r,t]:[t,r]);return p.current=x,b(m-x.top)}return d.jsx(_R,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1,children:d.jsx(MR,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const x=S(m.clientY);s==null||s(x)},onSlideMove:m=>{const x=S(m.clientY);i==null||i(x)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:m=>{const y=IR[f?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:y?-1:1})}})})}),MR=P.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=Dg(zl,t);return d.jsx(Ce.span,{...c,ref:n,onKeyDown:re(e.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):PR.concat(CR).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:re(e.onPointerDown,h=>{const p=h.target;p.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(p)?p.focus():r(h)}),onPointerMove:re(e.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&o(h)}),onPointerUp:re(e.onPointerUp,h=>{const p=h.target;p.hasPointerCapture(h.pointerId)&&(p.releasePointerCapture(h.pointerId),s(h))})})}),AR="SliderTrack",jR=P.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Dg(AR,t);return d.jsx(Ce.span,{"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation,...r,ref:n})});jR.displayName=AR;var qv="SliderRange",OR=P.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=Dg(qv,t),s=TR(qv,t),i=P.useRef(null),a=Ye(n,i),l=o.values.length,c=o.values.map(p=>RR(p,o.min,o.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ce.span,{"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0,...r,ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:h+"%"}})});OR.displayName=qv;var Zv="SliderThumb",DR=P.forwardRef((e,n)=>{const t=_oe(e.__scopeSlider),[r,o]=P.useState(null),s=Ye(n,a=>o(a)),i=P.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return d.jsx(Ooe,{...e,ref:s,index:i})}),Ooe=P.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,name:o,...s}=e,i=Dg(Zv,t),a=TR(Zv,t),[l,c]=P.useState(null),u=Ye(n,v=>c(v)),h=l?!!l.closest("form"):!0,p=cO(l),f=i.values[r],S=f===void 0?0:RR(f,i.min,i.max),m=Loe(r,i.values.length),x=p==null?void 0:p[a.size],y=x?Foe(x,S,a.direction):0;return P.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${S}% + ${y}px)`},children:[d.jsx(Xv.ItemSlot,{scope:e.__scopeSlider,children:d.jsx(Ce.span,{role:"slider","aria-label":e["aria-label"]||m,"aria-valuemin":i.min,"aria-valuenow":f,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...s,ref:u,style:f===void 0?{display:"none"}:e.style,onFocus:re(e.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(Doe,{name:o??(i.name?i.name+(i.values.length>1?"[]":""):void 0),value:f},r)]})});DR.displayName=Zv;var Doe=e=>{const{value:n,...t}=e,r=P.useRef(null),o=koe(n);return P.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&l){const c=new Event("input",{bubbles:!0});l.call(s,n),s.dispatchEvent(c)}},[o,n]),d.jsx("input",{style:{display:"none"},...t,ref:r,defaultValue:n})};function Roe(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function RR(e,n,t){const s=100/(t-n)*(e-n);return bR(s,[0,100])}function Loe(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function $oe(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 Foe(e,n,t){const r=e/2,s=ob([0,50],[0,r]);return(r-s(n)*t)*t}function Noe(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function zoe(e,n){if(n>0){const t=Noe(e);return Math.min(...t)>=n}return!0}function ob(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 Boe(e){return(String(e).split(".")[1]||"").length}function Uoe(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}var Hoe=kR,Koe=jR,Woe=OR,Goe=DR;const Voe=P.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=B(),l=Te(),c=P.useCallback(p=>{i(p[0])},[i]),u=P.useCallback(()=>{a.mark("click slider")},[a]),h=P.useCallback(()=>{o&&i(o)},[o,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(Hoe,{"data-testid":n["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:h,title:t+" — "+l(s),children:[d.jsx(Koe,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&d.jsx(Woe,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&d.jsx(Goe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Yoe({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const p=Te(),f=P.useMemo(()=>{var m;return((m=s.find(x=>c.type==="shared"&&c.value===x.value))==null?void 0:m.icon)??"mixed"},[s,c]),S=P.useMemo(()=>{var m;return((m=i.find(x=>u.type==="shared"&&u.value===x.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:p(e),className:"tlui-style-panel__double-select-picker-label",children:p(e)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(Qi,{id:`style panel ${n} A`,children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon","data-testid":`style.${n}`,title:p(r)+" — "+(c===null||c.type==="mixed"?p("style-panel.mixed"):p(`${n}-style.${c.value}`)),children:d.jsx(be,{icon:f,small:!0,invertIcon:!0})})}),d.jsx(ea,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:s.map((m,x)=>d.jsx(wu,{"data-testid":`style.${n}.${m.value}`,children:d.jsx(he,{type:"icon",onClick:()=>h(a,m.value),title:`${p(r)} — ${p(`${n}-style.${m.value}`)}`,children:d.jsx(be,{icon:m.icon,invertIcon:!0})},m.value)},x))})})]}),d.jsxs(Qi,{id:`style panel ${t}`,children:[d.jsx(Ji,{children:d.jsx(he,{type:"icon","data-testid":`style.${t}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${u.value}`)),children:d.jsx(be,{icon:S,small:!0})})}),d.jsx(ea,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(wu,{children:d.jsx(he,{type:"icon",title:`${p(o)} — ${p(`${t}-style.${m.value}`)}`,"data-testid":`style.${t}.${m.value}`,onClick:()=>h(l,m.value),children:d.jsx(be,{icon:m.icon})})},m.value))})})]})]})]})}const Xoe=P.memo(Yoe);function qoe({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Te(),c=B(),u=P.useMemo(()=>{var f;return(f=o.find(S=>i.type==="shared"&&S.value===i.value))==null?void 0:f.icon},[o,i]),h=i.type==="mixed"?l("style-panel.mixed"):l(`${t}-style.${i.value}`),p=n?l(n):"";return d.jsxs(Qi,{id:`style panel ${e}`,children:[d.jsx(Ji,{children:d.jsxs(he,{type:s,"data-testid":`style.${t}`,title:h,children:[d.jsx(bt,{children:p}),d.jsx(be,{icon:u??"mixed"})]})}),d.jsx(ea,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>d.jsx(wu,{children:d.jsx(he,{type:"icon","data-testid":`style.${t}.${f.value}`,title:l(`${t}-style.${f.value}`),onClick:()=>{c.mark("select style dropdown item"),a(r,f.value)},children:d.jsx(be,{icon:f.icon})})},f.value))})})]})}const sb=P.memo(qoe);function Zoe({styles:e}){const n=Ku();if(!e)return null;const t=e.get(Nr),r=e.get(jp),o=e.get(Ap),s=e.get(Lp),i=e.get(vo),a=t===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,h=ss({isDarkMode:n});return d.jsxs(d.Fragment,{children:[d.jsx(Qoe,{theme:h,styles:e}),!u&&d.jsx(Joe,{theme:h,styles:e}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx(ese,{styles:e}),d.jsx(nse,{styles:e}),d.jsx(tse,{styles:e})]})]})}function Qu(){const e=B(),n=Zr();return xe.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 Qoe({styles:e,theme:n}){const t=Te(),r=B(),o=Qu(),s=e.get(sr),i=e.get(zi),a=e.get(Ni),l=e.get(xo),c=i!==void 0||a!==void 0||l!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:d.jsx(Mi,{title:t("style-panel.color"),uiType:"color",style:sr,items:br.color,value:s,onValueChange:o,theme:n}),d.jsx(rse,{})]}),c&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:d.jsx(Mi,{title:t("style-panel.fill"),uiType:"fill",style:zi,items:br.fill,value:i,onValueChange:o,theme:n}),a===void 0?null:d.jsx(Mi,{title:t("style-panel.dash"),uiType:"dash",style:Ni,items:br.dash,value:a,onValueChange:o,theme:n}),l===void 0?null:d.jsx(Mi,{title:t("style-panel.size"),uiType:"size",style:xo,items:br.size,value:l,onValueChange:(u,h)=>{o(u,h);const p=r.getSelectedShapeIds();p.length>0&&Ke(r,p)},theme:n})]})]})}function Joe({theme:e,styles:n}){const t=Te(),r=Qu(),o=n.get(vo),s=n.get(vS),i=n.get(Dp),a=n.get(Rp);return o===void 0&&i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:d.jsx(Mi,{title:t("style-panel.font"),uiType:"font",style:vo,items:br.font,value:o,onValueChange:r,theme:e}),s===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Mi,{title:t("style-panel.align"),uiType:"align",style:vS,items:br.textAlign,value:s,onValueChange:r,theme:e}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),i===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Mi,{title:t("style-panel.align"),uiType:"align",style:Dp,items:br.horizontalAlign,value:i,onValueChange:r,theme:e}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:a===void 0?d.jsx(he,{type:"icon",title:t("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(sb,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:Rp,items:br.verticalAlign,value:a,onValueChange:r})})]})]})}function ese({styles:e}){const n=Qu(),t=e.get(Nr);return t===void 0?null:d.jsx(sb,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:Nr,items:br.geo,value:t,onValueChange:n})}function tse({styles:e}){const n=Qu(),t=e.get(Lp);return t===void 0?null:d.jsx(sb,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:Lp,items:br.spline,value:t,onValueChange:n})}function nse({styles:e}){const n=Qu(),t=e.get(jp),r=e.get(Ap);return!t||!r?null:d.jsx(Xoe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Ap,itemsA:br.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:jp,itemsB:br.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const fc=[.1,.25,.5,.75,1];function rse(){const e=B(),n=G("opacity",()=>e.getSharedOpacity(),[e]),t=Zr(),r=Te(),o=xe.useCallback(i=>{const a=fc[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:fc.indexOf(I4(fc,i=>Math.abs(i-n.value)));return d.jsx(Voe,{"data-testid":"style.opacity",value:s>=0?s:fc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:fc.length-1,title:r("style-panel.opacity")})}const ose=P.memo(function({isMobile:n,children:t}){const r=B(),o=wR(),s=P.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1})},[r,n]),i=t??d.jsx(Zoe,{styles:o});return d.jsx("div",{className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})});function sse(){const e=B(),n=Te(),t=wR(),r=t==null?void 0:t.get(sr),o=ss({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=G("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=P.useCallback(c=>{c||e.updateInstanceState({isChangingStyle:!1})},[e]),{StylePanel:l}=pi();return l?d.jsxs(N0,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(z0,{children:d.jsx(he,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),disabled:i,children:d.jsx(be,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),d.jsx(B0,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function ise(){return d.jsxs(d.Fragment,{children:[d.jsx(lse,{}),d.jsx(cse,{}),d.jsx(use,{}),d.jsx(dse,{}),d.jsx(hse,{}),d.jsx(pse,{}),d.jsx(fse,{}),d.jsx(gse,{}),d.jsx(mse,{}),d.jsx(yse,{}),d.jsx(vse,{}),d.jsx(Sse,{}),d.jsx(bse,{}),d.jsx(Ise,{}),d.jsx(xse,{}),d.jsx(Cse,{}),d.jsx(Pse,{}),d.jsx(wse,{}),d.jsx(Ese,{}),d.jsx(kse,{}),d.jsx(_se,{}),d.jsx(Tse,{}),d.jsx(Mse,{}),d.jsx(Ase,{}),d.jsx(jse,{}),d.jsx(Ose,{}),d.jsx(Rse,{}),d.jsx(Dse,{})]})}function ase(e){var r;const n=B(),t=(r=e.meta)==null?void 0:r.geo;return G("is tool selected",()=>{const o=n.getCurrentToolId(),s=n.getSharedStyles().getAsKnownValue(Nr);return t?o==="geo"&&s===t:o===e.id},[n,e.id,t])}function He({tool:e}){const n=Ig(),t=ase(n[e]);return d.jsx(H,{...n[e],isSelected:t})}function lse(){return d.jsx(He,{tool:"select"})}function cse(){return d.jsx(He,{tool:"hand"})}function use(){return d.jsx(He,{tool:"draw"})}function dse(){return d.jsx(He,{tool:"eraser"})}function hse(){return d.jsx(He,{tool:"arrow"})}function pse(){return d.jsx(He,{tool:"text"})}function fse(){return d.jsx(He,{tool:"note"})}function gse(){const e=Ig();return d.jsx(H,{...e.asset})}function mse(){return d.jsx(He,{tool:"rectangle"})}function yse(){return d.jsx(He,{tool:"ellipse"})}function Sse(){return d.jsx(He,{tool:"diamond"})}function vse(){return d.jsx(He,{tool:"triangle"})}function xse(){return d.jsx(He,{tool:"rhombus"})}function wse(){return d.jsx(He,{tool:"heart"})}function bse(){return d.jsx(He,{tool:"hexagon"})}function Pse(){return d.jsx(He,{tool:"cloud"})}function Cse(){return d.jsx(He,{tool:"star"})}function Ise(){return d.jsx(He,{tool:"oval"})}function Ese(){return d.jsx(He,{tool:"x-box"})}function kse(){return d.jsx(He,{tool:"check-box"})}function _se(){return d.jsx(He,{tool:"arrow-left"})}function Tse(){return d.jsx(He,{tool:"arrow-up"})}function Mse(){return d.jsx(He,{tool:"arrow-down"})}function Ase(){return d.jsx(He,{tool:"arrow-right"})}function jse(){return d.jsx(He,{tool:"line"})}function Ose(){return d.jsx(He,{tool:"highlight"})}function Dse(){return d.jsx(He,{tool:"frame"})}function Rse(){return d.jsx(He,{tool:"laser"})}const ky=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function _y(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function gc(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function LR(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 $R(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 Lse(e,n){const t=e.length>=n.length?e:n,r=e.length>=n.length?n:e;let o=!0;for(let s=0;s<t.length;s++)r.indexOf(t[s])===-1&&(o=!1);return o}const bu={backspace:8,"⌫":8,tab:9,clear:12,enter:13,"↩":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"⇪":20,",":188,".":190,"/":191,"`":192,"-":ky?173:189,"=":ky?61:187,";":ky?59:186,"'":222,"[":219,"]":221,"\\":220},Co={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Qv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Ft={16:!1,18:!1,17:!1,91:!1},dt={};for(let e=1;e<20;e++)bu["f".concat(e)]=111+e;let We=[],Hc=null,FR="all";const Ro=new Map,Ju=e=>bu[e.toLowerCase()]||Co[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),$se=e=>Object.keys(bu).find(n=>bu[n]===e),Fse=e=>Object.keys(Co).find(n=>Co[n]===e);function NR(e){FR=e||"all"}function Pu(){return FR||"all"}function Nse(){return We.slice(0)}function zse(){return We.map(e=>$se(e)||Fse(e)||String.fromCharCode(e))}function Bse(){const e=[];return Object.keys(dt).forEach(n=>{dt[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=>Ju(a))})})}),e}function Use(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 Hse(e){return typeof e=="string"&&(e=Ju(e)),We.indexOf(e)!==-1}function Kse(e,n){let t,r;e||(e=Pu());for(const o in dt)if(Object.prototype.hasOwnProperty.call(dt,o))for(t=dt[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return ib(a)}):r++;Pu()===e&&NR(n||"all")}function Wse(e){let n=e.keyCode||e.which||e.charCode;const t=We.indexOf(n);if(t>=0&&We.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&We.splice(0,We.length),(n===93||n===224)&&(n=91),n in Ft){Ft[n]=!1;for(const r in Co)Co[r]===n&&(Rn[r]=!1)}}function zR(e){if(typeof e>"u")Object.keys(dt).forEach(o=>{Array.isArray(dt[o])&&dt[o].forEach(s=>ch(s)),delete dt[o]}),ib(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&ch(o)});else if(typeof e=="object")e.key&&ch(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=""),ch({key:e,scope:o,method:s,splitKey:"+"})}}const ch=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;$R(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Ju(c);if(!dt[u])return;t||(t=Pu());const h=l>1?LR(Co,a):[],p=[];dt[u]=dt[u].filter(f=>{const m=(r?f.method===r:!0)&&f.scope===t&&Lse(f.mods,h);return m&&p.push(f.element),!m}),p.forEach(f=>ib(f))})};function nE(e,n,t,r){if(n.element!==r)return;let o;if(n.scope===t||n.scope==="all"){o=n.mods.length>0;for(const s in Ft)Object.prototype.hasOwnProperty.call(Ft,s)&&(!Ft[s]&&n.mods.indexOf(+s)>-1||Ft[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!Ft[16]&&!Ft[18]&&!Ft[17]&&!Ft[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(We),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function rE(e,n){const t=dt["*"];let r=e.keyCode||e.which||e.charCode;if(!Rn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),We.indexOf(r)===-1&&r!==229&&We.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=Qv[a];e[a]&&We.indexOf(l)===-1?We.push(l):!e[a]&&We.indexOf(l)>-1?We.splice(We.indexOf(l),1):a==="metaKey"&&e[a]&&We.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(We=We.slice(We.indexOf(l))))}),r in Ft){Ft[r]=!0;for(const a in Co)Co[a]===r&&(Rn[a]=!0);if(!t)return}for(const a in Ft)Object.prototype.hasOwnProperty.call(Ft,a)&&(Ft[a]=e[Qv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(We.indexOf(17)===-1&&We.push(17),We.indexOf(18)===-1&&We.push(18),Ft[17]=!0,Ft[18]=!0);const o=Pu();if(t)for(let a=0;a<t.length;a++)t[a].scope===o&&(e.type==="keydown"&&t[a].keydown||e.type==="keyup"&&t[a].keyup)&&nE(e,t[a],o,n);if(!(r in dt))return;const s=dt[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let p=0;p<u.length;p++)h.push(Ju(u[p]));h.sort().join("")===We.sort().join("")&&nE(e,l,o,n)}}function Rn(e,n,t){We=[];const r=$R(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,p=!1;for(t===void 0&&typeof n=="function"&&(t=n),Object.prototype.toString.call(n)==="[object Object]"&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(l=n.keyup),n.keydown!==void 0&&(c=n.keydown),n.capture!==void 0&&(h=n.capture),typeof n.splitKey=="string"&&(u=n.splitKey),n.single===!0&&(p=!0)),typeof n=="string"&&(s=n),p&&zR(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=LR(Co,e)),e=e[e.length-1],e=e==="*"?"*":Ju(e),e in dt||(dt[e]=[]),dt[e].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!Ro.has(i)){const f=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return rE(m,i)},S=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;rE(m,i),Wse(m)};Ro.set(i,{keydownListener:f,keyupListenr:S,capture:h}),_y(i,"keydown",f,h),_y(i,"keyup",S,h)}if(!Hc){const f=()=>{We=[]};Hc={listener:f,capture:h},_y(window,"focus",f,h)}}}function Gse(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(dt).forEach(t=>{dt[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function ib(e){const n=Object.values(dt).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=Ro.get(e)||{};r&&o&&(gc(e,"keyup",o,s),gc(e,"keydown",r,s),Ro.delete(e))}if((n.length<=0||Ro.size<=0)&&(Object.keys(Ro).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=Ro.get(o)||{};s&&i&&(gc(o,"keyup",i,a),gc(o,"keydown",s,a),Ro.delete(o))}),Ro.clear(),Object.keys(dt).forEach(o=>delete dt[o]),Hc)){const{listener:o,capture:s}=Hc;gc(window,"focus",o,s),Hc=null}}const Ty={getPressedKeyString:zse,setScope:NR,getScope:Pu,deleteScope:Kse,getPressedKeyCodes:Nse,getAllKeyCodes:Bse,isPressed:Hse,filter:Use,trigger:Gse,unbind:zR,keyMap:bu,modifier:Co,modifierMap:Qv};for(const e in Ty)Object.prototype.hasOwnProperty.call(Ty,e)&&(Rn[e]=Ty[e]);if(typeof window<"u"){const e=window.hotkeys;Rn.noConflict=n=>(n&&window.hotkeys===Rn&&(window.hotkeys=e),Rn),window.hotkeys=Rn}const oE=["copy","cut","paste","asset"];function Vse(){const e=B(),n=as(),t=ie(),r=Ig(),o=G("is focused",()=>e.getInstanceState().isFocused,[e]);P.useEffect(()=>{if(!o)return;const s=new Array,i=(l,c)=>{Rn(l,{element:document.body},c),s.push(()=>{Rn.unbind(l,c)})},a=(l,c)=>{Rn(l,{element:document.body,keyup:!0,keydown:!1},c),s.push(()=>{Rn.unbind(l,c)})};for(const l of Object.values(t))l.kbd&&(n&&!l.readonlyOk||oE.includes(l.id)||i(sE(l.kbd),c=>{kc(e)||(Ee(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&e.getInstanceState().isReadonly||oE.includes(l.id)||i(sE(l.kbd),c=>{kc(e)||(Ee(c),l.onSelect("kbd"))});return i(",",l=>{if(kc(e)||e.inputs.keys.has("Comma"))return;Ee(l),e.focus(),e.inputs.keys.add("Comma");const{x:c,y:u,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),a(",",l=>{if(kc(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{s.forEach(l=>l())}},[t,r,n,e,o])}function sE(e){return Yse(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 Yse(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 kc(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const Xse=P.createContext(!1);function qse({children:e}){const n=B(),t=yV(),r=Hn(),o=Te(),s=Math.min(8,5+r),[i,a]=P.useState(0),l=P.useRef(null),[c,u]=P.useState(null),h=P.useMemo(()=>{const f=c?`:not([data-value="${c}"])`:"";return`
|
|
314
|
-
#${t}_main > *:nth-child(n + ${s+(c?1:2)})${f} {
|
|
315
|
-
display: none;
|
|
316
|
-
}
|
|
317
|
-
#${t}_more > *:nth-child(-n + ${s}) {
|
|
318
|
-
display: none;
|
|
319
|
-
}
|
|
320
|
-
`},[c,t,s]),p=Yw(()=>{if(!l.current)return;const f=Array.from(l.current.children);a(f.length),f.findIndex(x=>x.getAttribute("data-value")===c)<=s&&u(null);const m=Array.from(l.current.children).findIndex(x=>x.getAttribute("aria-checked")==="true");m!==-1&&m>=s&&u(f[m].getAttribute("data-value"))});return P.useLayoutEffect(()=>{p()}),P.useLayoutEffect(()=>{if(!l.current)return;const f=new MutationObserver(p);return f.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{f.disconnect()}},[p]),P.useEffect(()=>{const f=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[S,m]of f)Rn(S,x=>{var b;if(kc(n))return;Ee(x);const v=Array.from(((b=l.current)==null?void 0:b.children)??[]).filter(E=>!(E instanceof HTMLElement)||E.tagName.toLowerCase()!=="button"?!1:!!(E.offsetWidth||E.offsetHeight))[m];v&&v.click()});return()=>{Rn.unbind("1,2,3,4,5,6,7,8,9,0")}},[n]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<yt.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${t}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(kr,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s+1&&d.jsx(Xse.Provider,{value:!0,children:d.jsxs(Qi,{id:"toolbar overflow",modal:!1,children:[d.jsx(Ji,{children:d.jsx(he,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(be,{icon:"chevron-up"})})}),d.jsx(ea,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${t}_more`,children:d.jsx(kr,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const Zse=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Qse({activeToolId:e}){const n=B(),t=Hn(),r=Te(),o=G("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||Zse.includes(e)?null:d.jsx(he,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ce("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<yt.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:d.jsx(be,{icon:o?"lock":"unlock",small:!0})})}const Jse=P.memo(function({children:n}){const t=B(),r=Hn(),o=as(),s=G("current tool id",()=>t.getCurrentToolId(),[t]),{ActionsMenu:i,QuickActions:a}=pi();return d.jsx("div",{className:"tlui-toolbar",children:d.jsxs("div",{className:"tlui-toolbar__inner",children:[d.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&d.jsxs("div",{className:"tlui-toolbar__extras",children:[r<yt.TABLET&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&d.jsx(a,{}),i&&d.jsx(i,{})]}),d.jsx(Qse,{activeToolId:s})]}),d.jsx(qse,{children:n??d.jsx(ise,{})})]}),r<yt.TABLET_SM&&!o&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(sse,{})})]})})});function eie(){const e=ie();return d.jsxs(d.Fragment,{children:[d.jsx(H,{...e["zoom-in"],noClose:!0}),d.jsx(H,{...e["zoom-out"],noClose:!0}),d.jsx(uR,{}),d.jsx(dR,{}),d.jsx(hR,{})]})}const tie=P.memo(function({children:n}){const t=un(),[r,o]=ui("zoom menu"),s=n??d.jsx(eie,{});return d.jsxs(eb,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[d.jsx(tb,{asChild:!0,dir:"ltr",children:d.jsx(nie,{})}),d.jsx(Og,{container:t,children:d.jsx(nb,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(kr,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),nie=P.forwardRef(function(n,t){const r=B(),o=Hn(),s=G("zoom",()=>r.getZoomLevel(),[r]),i=Te(),a=P.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(he,{ref:t,...n,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<yt.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<yt.MOBILE?"zoom-in":void 0,children:o<yt.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),BR=P.createContext(null);function rie({overrides:e={},children:n}){const t=qx(e);return d.jsx(BR.Provider,{value:P.useMemo(()=>({ContextMenu:Rre,ActionsMenu:ure,HelpMenu:Yre,ZoomMenu:tie,MainMenu:poe,Minimap:voe,StylePanel:ose,PageMenu:Poe,NavigationPanel:woe,Toolbar:Jse,KeyboardShortcutsDialog:toe,QuickActions:Ioe,HelperButtons:Jre,DebugPanel:Ure,DebugMenu:Bre,MenuPanel:foe,...t}),[t]),children:n})}function pi(){const e=P.useContext(BR);if(!e)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return e}function oie({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return d.jsx(nq,{assetUrls:GQ(t),children:d.jsx(sq,{overrides:ZQ(e),children:d.jsx(lQ,{onEvent:r,children:d.jsx($Q,{children:d.jsx(cQ,{children:d.jsx(YQ,{forceMobile:o,children:d.jsx(rie,{overrides:n,children:d.jsx(sie,{overrides:e,children:s})})})})})})})})}function sie({overrides:e,children:n}){const t=QQ(e);return d.jsx($J,{overrides:t.actions,children:d.jsx(VQ,{overrides:t.tools,children:n})})}function iie(){const e=B(),{addToast:n}=Qr();P.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 aie=xe.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return d.jsx(oie,{...s,components:o,children:d.jsx(lie,{hideUi:r,renderDebugMenuItems:n,children:t})})}),lie=xe.memo(function({children:n,hideUi:t,...r}){return d.jsxs(d.Fragment,{children:[n,t?null:d.jsx(uie,{...r}),d.jsx(cie,{})]})});function cie(){const{InFrontOfTheCanvas:e}=it();return e?d.jsx("div",{className:"tl-front",children:d.jsx(e,{})}):null}const uie=xe.memo(function(){const n=B(),t=Te(),r=Hn(),o=as(),s=G("focus",()=>n.getInstanceState().isFocusMode,[n]),i=G("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:p,NavigationPanel:f,HelperButtons:S,DebugPanel:m}=pi();Vse(),IJ(),iie();const{"toggle-focus-mode":x}=ie();return d.jsxs("div",{className:ce("tlui-layout",{"tlui-layout__mobile":r<yt.TABLET_SM}),"data-breakpoint":r,children:[s?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(he,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>x.onSelect("menu"),children:d.jsx(be,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),S&&d.jsx(S,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=yt.TABLET_SM&&!o&&d.jsx(u,{})]})]}),d.jsxs("div",{className:"tlui-layout__bottom",children:[d.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&d.jsx(f,{}),h&&d.jsx(h,{}),p&&d.jsx(p,{})]}),i&&m&&d.jsx(m,{})]})]}),d.jsx(BQ,{}),d.jsx(hQ,{}),d.jsx(UQ,{}),d.jsx(pQ,{})]})});async function die(e,n){const{url:t,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=n,h={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(e,`url(${t})`,h);return await p.load(),document.fonts.add(p),p.$$_url=t,p.$$_fontface=`
|
|
321
|
-
@font-face {
|
|
322
|
-
font-family: ${p.family};
|
|
323
|
-
font-stretch: ${p.stretch};
|
|
324
|
-
font-weight: ${p.weight};
|
|
325
|
-
font-style: ${p.style};
|
|
326
|
-
src: url("${t}") format("${u}")
|
|
327
|
-
}`,p}const uh=(e,n)=>{const[t,r]=P.useState(2);return P.useEffect(()=>{let o=!1;return r(2),die(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function hie(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 UR(e){const n=P.useMemo(()=>hie(e),[e]),t=[uh("tldraw_draw",n.draw),uh("tldraw_serif",n.serif),uh("tldraw_sans",n.sansSerif),uh("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function pie(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],...h}=e,p=qx(a),f=P.useMemo(()=>({Scribble:BC,CollaboratorScribble:BC,SelectionForeground:DV,SelectionBackground:jV,Handles:kV,...p}),[p]),S=Ac(l),m=P.useMemo(()=>[...IA,...S],[S]),x=Ac(c),y=P.useMemo(()=>[...W2,...x],[x]),v=Ac(u),b=P.useMemo(()=>[...Aq,...NY,...v],[v]),E="persistenceKey"in h?h.persistenceKey:void 0,I=Nj(h.assetUrls),C=P.useMemo(()=>({onResolveAsset:wY(E),...h.assetOptions}),[E,h.assetOptions]),{done:k,error:T}=UR(I);return T?d.jsx(N2,{children:"Could not load assets. Please refresh the page."}):k?d.jsx(uV,{initialState:"select",...h,components:f,shapeUtils:m,bindingUtils:y,tools:b,assetOptions:C,children:d.jsxs(aie,{...h,components:f,children:[d.jsx(fie,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,persistenceKey:E,onMount:i}),n]})}):d.jsx(Zw,{children:d.jsx(Xx,{})})}function fie({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=Tx,acceptedVideoMimeTypes:r=Ck,onMount:o,persistenceKey:s}){const i=B(),a=Qr(),l=Te(),c=Yw(p=>{const f=[];return f.push(...gq(p)),SY(p,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:a,msg:l},s),f.push(o==null?void 0:o(p)),()=>{f.forEach(S=>S==null?void 0:S())}});P.useLayoutEffect(()=>{if(i)return c==null?void 0:c(i)},[i,c]);const{Canvas:u}=it(),{ContextMenu:h}=pi();return h?d.jsx(h,{}):u?d.jsx(u,{}):null}P.memo(function(n){const[t,r]=P.useState(null),[o,s]=P.useState(null),i=Ac(n.shapeUtils??[]),a=P.useMemo(()=>[...IA,...i],[i]),l=Ac(n.bindingUtils??[]),c=P.useMemo(()=>[...W2,...l],[l]),u=L2({snapshot:n.snapshot,shapeUtils:a}),h=Nj(),{done:p,error:f}=UR(h),{pageId:S,bounds:m,scale:x,background:y,padding:v,darkMode:b,preserveAspectRatio:E,format:I="svg"}=n;return P.useLayoutEffect(()=>{if(!o||!u||!p)return;let C=!1;const k=document.createElement("div");o.appendChild(k),o.classList.add("tl-container","tl-theme__light");const T=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>k});S&&T.setCurrentPage(S);const O=T.getCurrentPageShapeIds();async function _(){const A=await T.getSvgString([...O],{bounds:m,scale:x,background:y,padding:v,darkMode:b,preserveAspectRatio:E});if(A&&!C){if(I==="svg"){if(!C){const L=new Blob([A.svg],{type:"image/svg+xml"}),j=URL.createObjectURL(L);r(j)}}else if(I==="png"){const L=await Xj(T,A.svg,{type:I,quality:1,scale:2,width:A.width,height:A.height});if(L&&!C){const j=URL.createObjectURL(L);r(j)}}}T.dispose()}return _(),()=>{C=!0}},[I,o,u,a,c,S,m,x,y,v,b,E,p,f]),f?d.jsx(N2,{children:"Could not load assets."}):p?d.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&d.jsx("img",{src:t,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):d.jsx(Zw,{children:d.jsx(Xx,{})})});const gie=1,mie=Se({schemaVersion:ln(1),storeVersion:Sh,recordVersions:Tp(pe,Se({version:Sh,subTypeVersions:Tp(pe,Sh).optional(),subTypeKey:pe.optional()}))}),yie=Se({schemaVersion:ln(2),sequences:Tp(pe,Sh)}),Sie=Se({tldrawFileFormatVersion:j8,schema:O8("schemaVersion",{1:mie,2:yie}),records:zt(Se({id:pe,typeName:pe}).allowUnknownProperties())});function vie(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function xie({json:e,schema:n}){let t;try{t=Sie.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),vie(t))return gn.err({type:"v1File",data:t})}catch{}return gn.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>gie)return gn.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=wie(t.records),s=Object.fromEntries(o.map(i=>[i.id,i]));r=n.migrateStoreSnapshot({store:s,schema:t.schema})}catch(o){return gn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return gn.err({type:"migrationFailed",reason:r.reason});try{return gn.ok(R2({initialData:r.value,schema:n}))}catch(o){return gn.err({type:"invalidRecords",cause:o})}}function wie(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 bie(){const[e,n]=P.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=xie({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 d.jsx("div",{style:{inset:0,position:"fixed"},children:d.jsx(pie,{assetUrls:v$(),onMount:t,store:e})})}mv.createRoot(document.querySelector("#root")).render(d.jsx(xe.StrictMode,{children:d.jsx(bie,{})}));
|