@kitschpatrol/tldraw-cli 4.5.2 → 4.5.3

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.
Files changed (47) hide show
  1. package/bin/cli.js +207 -234
  2. package/dist/.DS_Store +0 -0
  3. package/dist/lib/index.js +206 -232
  4. package/dist/tldraw/assets/index-BPAGcmPl.js +337 -0
  5. package/dist/tldraw/assets/index-BlBRI8VA.css +1 -0
  6. package/dist/tldraw/embed-icons/desmos.png +0 -0
  7. package/dist/tldraw/icons/icon/broken.svg +1 -0
  8. package/dist/tldraw/icons/icon/check-circle.svg +1 -1
  9. package/dist/tldraw/icons/icon/chevron-left.svg +1 -1
  10. package/dist/tldraw/icons/icon/chevron-right.svg +1 -1
  11. package/dist/tldraw/icons/icon/cross-circle.svg +1 -1
  12. package/dist/tldraw/icons/icon/dash-dashed.svg +1 -1
  13. package/dist/tldraw/icons/icon/disconnected.svg +1 -0
  14. package/dist/tldraw/icons/icon/geo-check-box.svg +1 -1
  15. package/dist/tldraw/icons/icon/geo-hexagon.svg +1 -1
  16. package/dist/tldraw/icons/icon/geo-octagon.svg +1 -1
  17. package/dist/tldraw/icons/icon/geo-pentagon.svg +1 -1
  18. package/dist/tldraw/icons/icon/geo-rectangle.svg +1 -1
  19. package/dist/tldraw/icons/icon/geo-rhombus-2.svg +1 -1
  20. package/dist/tldraw/icons/icon/geo-rhombus.svg +1 -1
  21. package/dist/tldraw/icons/icon/geo-star.svg +1 -1
  22. package/dist/tldraw/icons/icon/geo-trapezoid.svg +1 -1
  23. package/dist/tldraw/icons/icon/geo-x-box.svg +1 -1
  24. package/dist/tldraw/icons/icon/horizontal-align-end.svg +1 -0
  25. package/dist/tldraw/icons/icon/horizontal-align-middle.svg +1 -0
  26. package/dist/tldraw/icons/icon/horizontal-align-start.svg +1 -0
  27. package/dist/tldraw/icons/icon/icon-names.json +9 -40
  28. package/dist/tldraw/icons/icon/pack.svg +1 -1
  29. package/dist/tldraw/icons/icon/reset-zoom.svg +1 -1
  30. package/dist/tldraw/icons/icon/toggle-off.svg +1 -0
  31. package/dist/tldraw/icons/icon/toggle-on.svg +1 -0
  32. package/dist/tldraw/icons/icon/tool-screenshot.svg +1 -0
  33. package/dist/tldraw/icons/icon/vertical-align-middle.svg +1 -0
  34. package/dist/tldraw/icons/icon/warning-triangle.svg +1 -1
  35. package/dist/tldraw/icons/icon/zoom-in.svg +1 -1
  36. package/dist/tldraw/icons/icon/zoom-out.svg +1 -1
  37. package/dist/tldraw/index.html +2 -2
  38. package/dist/tldraw/translations/fr.json +85 -8
  39. package/dist/tldraw/translations/hu.json +0 -1
  40. package/dist/tldraw/translations/id.json +373 -0
  41. package/dist/tldraw/translations/ko-kr.json +14 -0
  42. package/dist/tldraw/translations/languages.json +4 -0
  43. package/dist/tldraw/translations/main.json +2 -1
  44. package/dist/tldraw/translations/sl.json +15 -0
  45. package/package.json +17 -17
  46. package/dist/tldraw/assets/index-DppooZ8M.css +0 -1
  47. package/dist/tldraw/assets/index-PoulvjiY.js +0 -307
@@ -1,307 +0,0 @@
1
- var MO=Object.defineProperty;var AO=(e,t,n)=>t in e?MO(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>(AO(e,typeof t!="symbol"?t+"":t,n),n);function jO(e,t){for(var n=0;n<t.length;n++){const r=t[n];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 t=document.createElement("link").relList;if(t&&t.supports&&t.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 n(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=n(o);fetch(o.href,s)}})();var tn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ll(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var hI={exports:{}},lf={},pI={exports:{}},we={};/**
2
- * @license React
3
- * react.production.min.js
4
- *
5
- * Copyright (c) Facebook, Inc. and its affiliates.
6
- *
7
- * This source code is licensed under the MIT license found in the
8
- * LICENSE file in the root directory of this source tree.
9
- */var xu=Symbol.for("react.element"),OO=Symbol.for("react.portal"),DO=Symbol.for("react.fragment"),RO=Symbol.for("react.strict_mode"),LO=Symbol.for("react.profiler"),FO=Symbol.for("react.provider"),NO=Symbol.for("react.context"),zO=Symbol.for("react.forward_ref"),BO=Symbol.for("react.suspense"),UO=Symbol.for("react.memo"),HO=Symbol.for("react.lazy"),Mw=Symbol.iterator;function KO(e){return e===null||typeof e!="object"?null:(e=Mw&&e[Mw]||e["@@iterator"],typeof e=="function"?e:null)}var fI={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},gI=Object.assign,mI={};function cl(e,t,n){this.props=e,this.context=t,this.refs=mI,this.updater=n||fI}cl.prototype.isReactComponent={};cl.prototype.setState=function(e,t){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,t,"setState")};cl.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")};function yI(){}yI.prototype=cl.prototype;function Tv(e,t,n){this.props=e,this.context=t,this.refs=mI,this.updater=n||fI}var $v=Tv.prototype=new yI;$v.constructor=Tv;gI($v,cl.prototype);$v.isPureReactComponent=!0;var Aw=Array.isArray,SI=Object.prototype.hasOwnProperty,Mv={current:null},vI={key:!0,ref:!0,__self:!0,__source:!0};function xI(e,t,n){var r,o={},s=null,i=null;if(t!=null)for(r in t.ref!==void 0&&(i=t.ref),t.key!==void 0&&(s=""+t.key),t)SI.call(t,r)&&!vI.hasOwnProperty(r)&&(o[r]=t[r]);var a=arguments.length-2;if(a===1)o.children=n;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:xu,type:e,key:s,ref:i,props:o,_owner:Mv.current}}function VO(e,t){return{$$typeof:xu,type:e.type,key:t,ref:e.ref,props:e.props,_owner:e._owner}}function Av(e){return typeof e=="object"&&e!==null&&e.$$typeof===xu}function WO(e){var t={"=":"=0",":":"=2"};return"$"+e.replace(/[=:]/g,function(n){return t[n]})}var jw=/\/+/g;function bg(e,t){return typeof e=="object"&&e!==null&&e.key!=null?WO(""+e.key):t.toString(36)}function Jd(e,t,n,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 xu:case OO:i=!0}}if(i)return i=e,o=o(i),e=r===""?"."+bg(i,0):r,Aw(o)?(n="",e!=null&&(n=e.replace(jw,"$&/")+"/"),Jd(o,t,n,"",function(c){return c})):o!=null&&(Av(o)&&(o=VO(o,n+(!o.key||i&&i.key===o.key?"":(""+o.key).replace(jw,"$&/")+"/")+e)),t.push(o)),1;if(i=0,r=r===""?".":r+":",Aw(e))for(var a=0;a<e.length;a++){s=e[a];var l=r+bg(s,a);i+=Jd(s,t,n,l,o)}else if(l=KO(e),typeof l=="function")for(e=l.call(e),a=0;!(s=e.next()).done;)s=s.value,l=r+bg(s,a++),i+=Jd(s,t,n,l,o);else if(s==="object")throw t=String(e),Error("Objects are not valid as a React child (found: "+(t==="[object Object]"?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.");return i}function qu(e,t,n){if(e==null)return e;var r=[],o=0;return Jd(e,r,"","",function(s){return t.call(n,s,o++)}),r}function GO(e){if(e._status===-1){var t=e._result;t=t(),t.then(function(n){(e._status===0||e._status===-1)&&(e._status=1,e._result=n)},function(n){(e._status===0||e._status===-1)&&(e._status=2,e._result=n)}),e._status===-1&&(e._status=0,e._result=t)}if(e._status===1)return e._result.default;throw e._result}var fn={current:null},eh={transition:null},YO={ReactCurrentDispatcher:fn,ReactCurrentBatchConfig:eh,ReactCurrentOwner:Mv};we.Children={map:qu,forEach:function(e,t,n){qu(e,function(){t.apply(this,arguments)},n)},count:function(e){var t=0;return qu(e,function(){t++}),t},toArray:function(e){return qu(e,function(t){return t})||[]},only:function(e){if(!Av(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};we.Component=cl;we.Fragment=DO;we.Profiler=LO;we.PureComponent=Tv;we.StrictMode=RO;we.Suspense=BO;we.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=YO;we.cloneElement=function(e,t,n){if(e==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+e+".");var r=gI({},e.props),o=e.key,s=e.ref,i=e._owner;if(t!=null){if(t.ref!==void 0&&(s=t.ref,i=Mv.current),t.key!==void 0&&(o=""+t.key),e.type&&e.type.defaultProps)var a=e.type.defaultProps;for(l in t)SI.call(t,l)&&!vI.hasOwnProperty(l)&&(r[l]=t[l]===void 0&&a!==void 0?a[l]:t[l])}var l=arguments.length-2;if(l===1)r.children=n;else if(1<l){a=Array(l);for(var c=0;c<l;c++)a[c]=arguments[c+2];r.children=a}return{$$typeof:xu,type:e.type,key:o,ref:s,props:r,_owner:i}};we.createContext=function(e){return e={$$typeof:NO,_currentValue:e,_currentValue2:e,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},e.Provider={$$typeof:FO,_context:e},e.Consumer=e};we.createElement=xI;we.createFactory=function(e){var t=xI.bind(null,e);return t.type=e,t};we.createRef=function(){return{current:null}};we.forwardRef=function(e){return{$$typeof:zO,render:e}};we.isValidElement=Av;we.lazy=function(e){return{$$typeof:HO,_payload:{_status:-1,_result:e},_init:GO}};we.memo=function(e,t){return{$$typeof:UO,type:e,compare:t===void 0?null:t}};we.startTransition=function(e){var t=eh.transition;eh.transition={};try{e()}finally{eh.transition=t}};we.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.")};we.useCallback=function(e,t){return fn.current.useCallback(e,t)};we.useContext=function(e){return fn.current.useContext(e)};we.useDebugValue=function(){};we.useDeferredValue=function(e){return fn.current.useDeferredValue(e)};we.useEffect=function(e,t){return fn.current.useEffect(e,t)};we.useId=function(){return fn.current.useId()};we.useImperativeHandle=function(e,t,n){return fn.current.useImperativeHandle(e,t,n)};we.useInsertionEffect=function(e,t){return fn.current.useInsertionEffect(e,t)};we.useLayoutEffect=function(e,t){return fn.current.useLayoutEffect(e,t)};we.useMemo=function(e,t){return fn.current.useMemo(e,t)};we.useReducer=function(e,t,n){return fn.current.useReducer(e,t,n)};we.useRef=function(e){return fn.current.useRef(e)};we.useState=function(e){return fn.current.useState(e)};we.useSyncExternalStore=function(e,t,n){return fn.current.useSyncExternalStore(e,t,n)};we.useTransition=function(){return fn.current.useTransition()};we.version="18.2.0";pI.exports=we;var x=pI.exports;const Se=ll(x),XO=jO({__proto__:null,default:Se},[x]);/**
10
- * @license React
11
- * react-jsx-runtime.production.min.js
12
- *
13
- * Copyright (c) Facebook, Inc. and its affiliates.
14
- *
15
- * This source code is licensed under the MIT license found in the
16
- * LICENSE file in the root directory of this source tree.
17
- */var qO=x,ZO=Symbol.for("react.element"),QO=Symbol.for("react.fragment"),JO=Object.prototype.hasOwnProperty,eD=qO.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,tD={key:!0,ref:!0,__self:!0,__source:!0};function wI(e,t,n){var r,o={},s=null,i=null;n!==void 0&&(s=""+n),t.key!==void 0&&(s=""+t.key),t.ref!==void 0&&(i=t.ref);for(r in t)JO.call(t,r)&&!tD.hasOwnProperty(r)&&(o[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps,t)o[r]===void 0&&(o[r]=t[r]);return{$$typeof:ZO,type:e,key:s,ref:i,props:o,_owner:eD.current}}lf.Fragment=QO;lf.jsx=wI;lf.jsxs=wI;hI.exports=lf;var h=hI.exports;function A(e,t={}){const n=typeof e=="string"?e:e.src;if(typeof t=="function")return t(n);const{baseUrl:r=""}=t;return n.startsWith("data:")||n.match(/^https?:\/\//)?n:`${r.replace(/\/$/,"")}/${n.replace(/^\.?\//,"")}`}function nD(e){return{fonts:{monospace:A("./fonts/IBMPlexMono-Medium.woff2",e),sansSerif:A("./fonts/IBMPlexSans-Medium.woff2",e),serif:A("./fonts/IBMPlexSerif-Medium.woff2",e),draw:A("./fonts/Shantell_Sans-Tldrawish.woff2",e)},icons:{"align-bottom-center":A("./icons/icon/align-bottom-center.svg",e),"align-bottom-left":A("./icons/icon/align-bottom-left.svg",e),"align-bottom-right":A("./icons/icon/align-bottom-right.svg",e),"align-bottom":A("./icons/icon/align-bottom.svg",e),"align-center-center":A("./icons/icon/align-center-center.svg",e),"align-center-horizontal":A("./icons/icon/align-center-horizontal.svg",e),"align-center-left":A("./icons/icon/align-center-left.svg",e),"align-center-right":A("./icons/icon/align-center-right.svg",e),"align-center-vertical":A("./icons/icon/align-center-vertical.svg",e),"align-left":A("./icons/icon/align-left.svg",e),"align-right":A("./icons/icon/align-right.svg",e),"align-top-center":A("./icons/icon/align-top-center.svg",e),"align-top-left":A("./icons/icon/align-top-left.svg",e),"align-top-right":A("./icons/icon/align-top-right.svg",e),"align-top":A("./icons/icon/align-top.svg",e),"arrow-left":A("./icons/icon/arrow-left.svg",e),"arrowhead-arrow":A("./icons/icon/arrowhead-arrow.svg",e),"arrowhead-bar":A("./icons/icon/arrowhead-bar.svg",e),"arrowhead-diamond":A("./icons/icon/arrowhead-diamond.svg",e),"arrowhead-dot":A("./icons/icon/arrowhead-dot.svg",e),"arrowhead-none":A("./icons/icon/arrowhead-none.svg",e),"arrowhead-square":A("./icons/icon/arrowhead-square.svg",e),"arrowhead-triangle-inverted":A("./icons/icon/arrowhead-triangle-inverted.svg",e),"arrowhead-triangle":A("./icons/icon/arrowhead-triangle.svg",e),"aspect-ratio":A("./icons/icon/aspect-ratio.svg",e),avatar:A("./icons/icon/avatar.svg",e),blob:A("./icons/icon/blob.svg",e),"bring-forward":A("./icons/icon/bring-forward.svg",e),"bring-to-front":A("./icons/icon/bring-to-front.svg",e),"check-circle":A("./icons/icon/check-circle.svg",e),check:A("./icons/icon/check.svg",e),"checkbox-checked":A("./icons/icon/checkbox-checked.svg",e),"checkbox-empty":A("./icons/icon/checkbox-empty.svg",e),"chevron-down":A("./icons/icon/chevron-down.svg",e),"chevron-left":A("./icons/icon/chevron-left.svg",e),"chevron-right":A("./icons/icon/chevron-right.svg",e),"chevron-up":A("./icons/icon/chevron-up.svg",e),"chevrons-ne":A("./icons/icon/chevrons-ne.svg",e),"chevrons-sw":A("./icons/icon/chevrons-sw.svg",e),"clipboard-copied":A("./icons/icon/clipboard-copied.svg",e),"clipboard-copy":A("./icons/icon/clipboard-copy.svg",e),code:A("./icons/icon/code.svg",e),collab:A("./icons/icon/collab.svg",e),color:A("./icons/icon/color.svg",e),comment:A("./icons/icon/comment.svg",e),"cross-2":A("./icons/icon/cross-2.svg",e),"cross-circle":A("./icons/icon/cross-circle.svg",e),cross:A("./icons/icon/cross.svg",e),"dash-dashed":A("./icons/icon/dash-dashed.svg",e),"dash-dotted":A("./icons/icon/dash-dotted.svg",e),"dash-draw":A("./icons/icon/dash-draw.svg",e),"dash-solid":A("./icons/icon/dash-solid.svg",e),discord:A("./icons/icon/discord.svg",e),"distribute-horizontal":A("./icons/icon/distribute-horizontal.svg",e),"distribute-vertical":A("./icons/icon/distribute-vertical.svg",e),dot:A("./icons/icon/dot.svg",e),"dots-horizontal":A("./icons/icon/dots-horizontal.svg",e),"dots-vertical":A("./icons/icon/dots-vertical.svg",e),"drag-handle-dots":A("./icons/icon/drag-handle-dots.svg",e),duplicate:A("./icons/icon/duplicate.svg",e),edit:A("./icons/icon/edit.svg",e),error:A("./icons/icon/error.svg",e),"external-link":A("./icons/icon/external-link.svg",e),file:A("./icons/icon/file.svg",e),"fill-none":A("./icons/icon/fill-none.svg",e),"fill-pattern":A("./icons/icon/fill-pattern.svg",e),"fill-semi":A("./icons/icon/fill-semi.svg",e),"fill-solid":A("./icons/icon/fill-solid.svg",e),follow:A("./icons/icon/follow.svg",e),following:A("./icons/icon/following.svg",e),"font-draw":A("./icons/icon/font-draw.svg",e),"font-mono":A("./icons/icon/font-mono.svg",e),"font-sans":A("./icons/icon/font-sans.svg",e),"font-serif":A("./icons/icon/font-serif.svg",e),"geo-arrow-down":A("./icons/icon/geo-arrow-down.svg",e),"geo-arrow-left":A("./icons/icon/geo-arrow-left.svg",e),"geo-arrow-right":A("./icons/icon/geo-arrow-right.svg",e),"geo-arrow-up":A("./icons/icon/geo-arrow-up.svg",e),"geo-check-box":A("./icons/icon/geo-check-box.svg",e),"geo-cloud":A("./icons/icon/geo-cloud.svg",e),"geo-diamond":A("./icons/icon/geo-diamond.svg",e),"geo-ellipse":A("./icons/icon/geo-ellipse.svg",e),"geo-hexagon":A("./icons/icon/geo-hexagon.svg",e),"geo-octagon":A("./icons/icon/geo-octagon.svg",e),"geo-oval":A("./icons/icon/geo-oval.svg",e),"geo-pentagon":A("./icons/icon/geo-pentagon.svg",e),"geo-rectangle":A("./icons/icon/geo-rectangle.svg",e),"geo-rhombus-2":A("./icons/icon/geo-rhombus-2.svg",e),"geo-rhombus":A("./icons/icon/geo-rhombus.svg",e),"geo-star":A("./icons/icon/geo-star.svg",e),"geo-trapezoid":A("./icons/icon/geo-trapezoid.svg",e),"geo-triangle":A("./icons/icon/geo-triangle.svg",e),"geo-x-box":A("./icons/icon/geo-x-box.svg",e),github:A("./icons/icon/github.svg",e),group:A("./icons/icon/group.svg",e),hidden:A("./icons/icon/hidden.svg",e),image:A("./icons/icon/image.svg",e),"info-circle":A("./icons/icon/info-circle.svg",e),leading:A("./icons/icon/leading.svg",e),link:A("./icons/icon/link.svg",e),"lock-small":A("./icons/icon/lock-small.svg",e),lock:A("./icons/icon/lock.svg",e),menu:A("./icons/icon/menu.svg",e),minus:A("./icons/icon/minus.svg",e),mixed:A("./icons/icon/mixed.svg",e),pack:A("./icons/icon/pack.svg",e),page:A("./icons/icon/page.svg",e),plus:A("./icons/icon/plus.svg",e),"question-mark-circle":A("./icons/icon/question-mark-circle.svg",e),"question-mark":A("./icons/icon/question-mark.svg",e),redo:A("./icons/icon/redo.svg",e),"reset-zoom":A("./icons/icon/reset-zoom.svg",e),"rotate-ccw":A("./icons/icon/rotate-ccw.svg",e),"rotate-cw":A("./icons/icon/rotate-cw.svg",e),ruler:A("./icons/icon/ruler.svg",e),search:A("./icons/icon/search.svg",e),"send-backward":A("./icons/icon/send-backward.svg",e),"send-to-back":A("./icons/icon/send-to-back.svg",e),"settings-horizontal":A("./icons/icon/settings-horizontal.svg",e),"settings-vertical-1":A("./icons/icon/settings-vertical-1.svg",e),"settings-vertical":A("./icons/icon/settings-vertical.svg",e),"share-1":A("./icons/icon/share-1.svg",e),"share-2":A("./icons/icon/share-2.svg",e),"size-extra-large":A("./icons/icon/size-extra-large.svg",e),"size-large":A("./icons/icon/size-large.svg",e),"size-medium":A("./icons/icon/size-medium.svg",e),"size-small":A("./icons/icon/size-small.svg",e),"spline-cubic":A("./icons/icon/spline-cubic.svg",e),"spline-line":A("./icons/icon/spline-line.svg",e),"stack-horizontal":A("./icons/icon/stack-horizontal.svg",e),"stack-vertical":A("./icons/icon/stack-vertical.svg",e),"status-offline":A("./icons/icon/status-offline.svg",e),"status-online":A("./icons/icon/status-online.svg",e),"stretch-horizontal":A("./icons/icon/stretch-horizontal.svg",e),"stretch-vertical":A("./icons/icon/stretch-vertical.svg",e),"text-align-center":A("./icons/icon/text-align-center.svg",e),"text-align-justify":A("./icons/icon/text-align-justify.svg",e),"text-align-left":A("./icons/icon/text-align-left.svg",e),"text-align-right":A("./icons/icon/text-align-right.svg",e),"tool-arrow":A("./icons/icon/tool-arrow.svg",e),"tool-embed":A("./icons/icon/tool-embed.svg",e),"tool-eraser":A("./icons/icon/tool-eraser.svg",e),"tool-frame":A("./icons/icon/tool-frame.svg",e),"tool-hand":A("./icons/icon/tool-hand.svg",e),"tool-highlight":A("./icons/icon/tool-highlight.svg",e),"tool-laser":A("./icons/icon/tool-laser.svg",e),"tool-line":A("./icons/icon/tool-line.svg",e),"tool-media":A("./icons/icon/tool-media.svg",e),"tool-note":A("./icons/icon/tool-note.svg",e),"tool-pencil":A("./icons/icon/tool-pencil.svg",e),"tool-pointer":A("./icons/icon/tool-pointer.svg",e),"tool-text":A("./icons/icon/tool-text.svg",e),trash:A("./icons/icon/trash.svg",e),"triangle-down":A("./icons/icon/triangle-down.svg",e),"triangle-up":A("./icons/icon/triangle-up.svg",e),twitter:A("./icons/icon/twitter.svg",e),undo:A("./icons/icon/undo.svg",e),ungroup:A("./icons/icon/ungroup.svg",e),"unlock-small":A("./icons/icon/unlock-small.svg",e),unlock:A("./icons/icon/unlock.svg",e),"vertical-align-center":A("./icons/icon/vertical-align-center.svg",e),"vertical-align-end":A("./icons/icon/vertical-align-end.svg",e),"vertical-align-start":A("./icons/icon/vertical-align-start.svg",e),visible:A("./icons/icon/visible.svg",e),"warning-triangle":A("./icons/icon/warning-triangle.svg",e),"zoom-in":A("./icons/icon/zoom-in.svg",e),"zoom-out":A("./icons/icon/zoom-out.svg",e)},translations:{ar:A("./translations/ar.json",e),ca:A("./translations/ca.json",e),cs:A("./translations/cs.json",e),da:A("./translations/da.json",e),de:A("./translations/de.json",e),en:A("./translations/en.json",e),es:A("./translations/es.json",e),fa:A("./translations/fa.json",e),fi:A("./translations/fi.json",e),fr:A("./translations/fr.json",e),gl:A("./translations/gl.json",e),he:A("./translations/he.json",e),"hi-in":A("./translations/hi-in.json",e),hr:A("./translations/hr.json",e),hu:A("./translations/hu.json",e),it:A("./translations/it.json",e),ja:A("./translations/ja.json",e),"ko-kr":A("./translations/ko-kr.json",e),ku:A("./translations/ku.json",e),languages:A("./translations/languages.json",e),main:A("./translations/main.json",e),my:A("./translations/my.json",e),ne:A("./translations/ne.json",e),no:A("./translations/no.json",e),pl:A("./translations/pl.json",e),"pt-br":A("./translations/pt-br.json",e),"pt-pt":A("./translations/pt-pt.json",e),ro:A("./translations/ro.json",e),ru:A("./translations/ru.json",e),sl:A("./translations/sl.json",e),sv:A("./translations/sv.json",e),te:A("./translations/te.json",e),th:A("./translations/th.json",e),tr:A("./translations/tr.json",e),uk:A("./translations/uk.json",e),vi:A("./translations/vi.json",e),"zh-cn":A("./translations/zh-cn.json",e),"zh-tw":A("./translations/zh-tw.json",e)},embedIcons:{codepen:A("./embed-icons/codepen.png",e),codesandbox:A("./embed-icons/codesandbox.png",e),excalidraw:A("./embed-icons/excalidraw.png",e),felt:A("./embed-icons/felt.png",e),figma:A("./embed-icons/figma.png",e),github_gist:A("./embed-icons/github_gist.png",e),google_calendar:A("./embed-icons/google_calendar.png",e),google_maps:A("./embed-icons/google_maps.png",e),google_slides:A("./embed-icons/google_slides.png",e),observable:A("./embed-icons/observable.png",e),replit:A("./embed-icons/replit.png",e),scratch:A("./embed-icons/scratch.png",e),spotify:A("./embed-icons/spotify.png",e),tldraw:A("./embed-icons/tldraw.png",e),val_town:A("./embed-icons/val_town.png",e),vimeo:A("./embed-icons/vimeo.png",e),youtube:A("./embed-icons/youtube.png",e)}}}async function rD(e,t){const{url:n,style:r="normal",weight:o="500",display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=t,d={style:r,weight:o,display:s,featureSettings:i,stretch:a,unicodeRange:l,variant:c},p=new FontFace(e,`url(${n})`,d);return await p.load(),document.fonts.add(p),p.$$_url=n,p.$$_fontface=`
18
- @font-face {
19
- font-family: ${p.family};
20
- font-stretch: ${p.stretch};
21
- font-weight: ${p.weight};
22
- font-style: ${p.style};
23
- src: url("${n}") format("${u}")
24
- }`,p}function bI(e){return e&&typeof e=="object"&&"parents"in e}function PI(e){for(let t=0,n=e.parents.length;t<n;t++)if(e.parents[t].__unsafe__getWithoutCapture(!0),e.parents[t].lastChangedEpoch!==e.parentEpochs[t])return!0;return!1}const Qh=(e,t)=>{if(e.children.remove(t)&&e.children.isEmpty&&bI(e))for(let n=0,r=e.parents.length;n<r;n++)Qh(e.parents[n],e)},jv=(e,t)=>{if(e.children.add(t)&&bI(e))for(let n=0,r=e.parents.length;n<r;n++)jv(e.parents[n],e)};function CI(e,t){return e===t||Object.is(e,t)||!!(e&&t&&typeof e.equals=="function"&&e.equals(t))}function zs(e,t){const n=Symbol.for(`com.tldraw.state/${e}`),r=globalThis;return r[n]??(r[n]=t()),r[n]}const $s=zs("empty_array",()=>Object.freeze([])),Ow=8;class II{constructor(){m(this,"arraySize",0);m(this,"array",Array(Ow));m(this,"set",null)}get isEmpty(){if(this.array)return this.arraySize===0;if(this.set)return this.set.size===0;throw new Error("no set or array")}add(t){if(this.array)return this.array.indexOf(t)!==-1?!1:this.arraySize<Ow?(this.array[this.arraySize]=t,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(t),!0);if(this.set)return this.set.has(t)?!1:(this.set.add(t),!0);throw new Error("no set or array")}remove(t){if(this.array){const n=this.array.indexOf(t);return n===-1?!1:(this.array[n]=void 0,this.arraySize--,n!==this.arraySize&&(this.array[n]=this.array[this.arraySize],this.array[this.arraySize]=void 0),!0)}if(this.set)return this.set.has(t)?(this.set.delete(t),!0):!1;throw new Error("no set or array")}visit(t){if(this.array){for(let n=0;n<this.arraySize;n++){const r=this.array[n];typeof r<"u"&&t(r)}return}if(this.set){this.set.forEach(t);return}throw new Error("no set or array")}}const Tn=Symbol.for("com.tldraw.state/RESET_VALUE");class EI{constructor(t){m(this,"index",0);m(this,"buffer");this.capacity=t,this.buffer=new Array(t)}pushEntry(t,n,r){if(r!==void 0){if(r===Tn){this.clear();return}this.buffer[this.index]=[t,n,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(t){const{index:n,capacity:r,buffer:o}=this;for(let s=0;s<r;s++){const i=(n-1+r-s)%r,a=o[i];if(!a)return Tn;const[l,c]=a;if(s===0&&t>=c)return[];if(l<=t&&t<c){const u=s+1,d=new Array(u);for(let p=0;p<u;p++)d[p]=o[(i+p)%r][2];return d}}return Tn}}class oD{constructor(t,n){m(this,"offset",0);m(this,"numNewParents",0);m(this,"maybeRemoved");this.below=t,this.child=n}}const tt=zs("capture",()=>({stack:null}));function _I(e){tt.stack=new oD(tt.stack,e)}function kI(){var n;const e=tt.stack;if(tt.stack=e.below,e.numNewParents>0||e.offset!==e.child.parents.length){for(let r=e.offset;r<e.child.parents.length;r++){const o=e.child.parents[r];e.child.parents.indexOf(o)>=e.offset&&Qh(o,e.child)}if(e.child.parents.length=e.offset,e.child.parentEpochs.length=e.offset,(n=tt.stack)!=null&&n.maybeRemoved)for(let r=0;r<tt.stack.maybeRemoved.length;r++){const o=tt.stack.maybeRemoved[r];e.child.parents.indexOf(o)===-1&&Qh(o,e.child)}}}function Jh(e){if(tt.stack){const t=tt.stack.child.parents.indexOf(e);if(t<0&&(tt.stack.numNewParents++,tt.stack.child.isActivelyListening&&jv(e,tt.stack.child)),t<0||t>=tt.stack.offset){if(t!==tt.stack.offset&&t>0){const n=tt.stack.child.parents[tt.stack.offset];tt.stack.maybeRemoved?tt.stack.maybeRemoved.indexOf(n)===-1&&tt.stack.maybeRemoved.push(n):tt.stack.maybeRemoved=[n]}tt.stack.child.parents[tt.stack.offset]=e,tt.stack.child.parentEpochs[tt.stack.offset]=e.lastChangedEpoch,tt.stack.offset++}}}const ui=-1;class sD{constructor(t,n,r){m(this,"_isActivelyListening",!1);m(this,"lastTraversedEpoch",ui);m(this,"lastReactedEpoch",ui);m(this,"_scheduleCount",0);m(this,"parentEpochs",[]);m(this,"parents",[]);m(this,"_scheduleEffect");m(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=t,this.runEffect=n,this._scheduleEffect=r==null?void 0:r.scheduleEffect}get isActivelyListening(){return this._isActivelyListening}get scheduleCount(){return this._scheduleCount}maybeScheduleEffect(){if(this._isActivelyListening&&this.lastReactedEpoch!==dn()){if(this.parents.length&&!PI(this)){this.lastReactedEpoch=dn();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let t=0,n=this.parents.length;t<n;t++)jv(this.parents[t],this)}detach(){this._isActivelyListening=!1;for(let t=0,n=this.parents.length;t<n;t++)Qh(this.parents[t],this)}execute(){try{_I(this);const t=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=dn(),t}finally{kI()}}}const ul=zs("EffectScheduler",()=>sD);function wu(e,t,n){const r=new ul(e,t,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function iD(e,t,n){const r=new ul(e,t,n);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 aD{constructor(t){m(this,"initialAtomValues",new Map);this.parent=t}get isRoot(){return this.parent===null}commit(){if(this.isRoot){const t=this.initialAtomValues;this.initialAtomValues=new Map,TI(t.keys())}else this.initialAtomValues.forEach((t,n)=>{this.parent.initialAtomValues.has(n)||this.parent.initialAtomValues.set(n,t)})}abort(){Jt.globalEpoch++,this.initialAtomValues.forEach((t,n)=>{var r;n.set(t),(r=n.historyBuffer)==null||r.clear()}),this.commit()}}const Jt=zs("transactions",()=>({globalEpoch:ui+1,globalIsReacting:!1,currentTransaction:null}));function dn(){return Jt.globalEpoch}function TI(e){if(Jt.globalIsReacting)throw new Error("cannot change atoms during reaction cycle");try{Jt.globalIsReacting=!0;const t=new Set,n=r=>{r.lastTraversedEpoch!==Jt.globalEpoch&&(r.lastTraversedEpoch=Jt.globalEpoch,r instanceof ul?t.add(r):r.children.visit(n))};for(const r of e)r.children.visit(n);for(const r of t)r.maybeScheduleEffect()}finally{Jt.globalIsReacting=!1}}function lD(e,t){Jt.currentTransaction?Jt.currentTransaction.initialAtomValues.has(e)||Jt.currentTransaction.initialAtomValues.set(e,t):TI([e])}function cD(){Jt.globalEpoch++}function uD(e){const t=new aD(Jt.currentTransaction);Jt.currentTransaction=t;try{let n=!1;const r=e(()=>n=!0);return n?t.abort():t.commit(),r}catch(n){throw t.abort(),n}finally{Jt.currentTransaction=Jt.currentTransaction.parent}}function Tr(e){return Jt.currentTransaction?e():uD(e)}class dD{constructor(t,n,r){m(this,"isEqual");m(this,"computeDiff");m(this,"lastChangedEpoch",dn());m(this,"children",new II);m(this,"historyBuffer");this.name=t,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new EI(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(t){return this.current}get(){return Jh(this),this.current}set(t,n){var o,s;if(((o=this.isEqual)==null?void 0:o.call(this,this.current,t))??CI(this.current,t))return this.current;cD(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,dn(),n??((s=this.computeDiff)==null?void 0:s.call(this,this.current,t,this.lastChangedEpoch,dn()))??Tn),this.lastChangedEpoch=dn();const r=this.current;return this.current=t,lD(this,r),t}update(t){return this.set(t(this.current))}getDiffSince(t){var n;return Jh(this),t>=this.lastChangedEpoch?$s:((n=this.historyBuffer)==null?void 0:n.getChangesSince(t))??Tn}}const hD=zs("Atom",()=>dD);function In(e,t,n){return new hD(e,t,n)}let Dw=!1;function pD(){Dw||(Dw=!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.
25
-
26
- // Before
27
- @computed
28
- get foo() {
29
- return 'foo'
30
- }
31
-
32
- // After
33
- @computed
34
- getFoo() {
35
- return 'foo'
36
- }
37
- `))}const rc=Symbol.for("com.tldraw.state/UNINITIALIZED"),Si=e=>e===rc,Ey=zs("WithDiff",()=>class{constructor(t,n){this.value=t,this.diff=n}});function oc(e,t){return new Ey(e,t)}class fD{constructor(t,n,r){m(this,"lastChangedEpoch",ui);m(this,"lastTraversedEpoch",ui);m(this,"lastCheckedEpoch",ui);m(this,"parents",[]);m(this,"parentEpochs",[]);m(this,"children",new II);m(this,"historyBuffer");m(this,"state",rc);m(this,"error",null);m(this,"computeDiff");m(this,"isEqual");this.name=t,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new EI(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??CI}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(t){var r;if(!(this.lastChangedEpoch===ui)&&(this.lastCheckedEpoch===dn()||!PI(this)))if(this.lastCheckedEpoch=dn(),this.error){if(t)return this.state;throw this.error.thrownValue}else return this.state;try{_I(this);const o=this.derive(this.state,this.lastCheckedEpoch),s=o instanceof Ey?o.value:o,i=this.state===rc;if(i||!this.isEqual(s,this.state)){if(this.historyBuffer&&!i){const a=o instanceof Ey?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,dn(),a??((r=this.computeDiff)==null?void 0:r.call(this,this.state,s,this.lastCheckedEpoch,dn()))??Tn)}this.lastChangedEpoch=dn(),this.state=s}return this.error=null,this.lastCheckedEpoch=dn(),this.state}catch(o){if(this.state!==rc&&(this.state=rc,this.lastChangedEpoch=dn()),this.lastCheckedEpoch=dn(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!t)throw o;return this.state}finally{kI()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{Jh(this)}}getDiffSince(t){var n;return this.__unsafe__getWithoutCapture(!0),Jh(this),t>=this.lastChangedEpoch?$s:((n=this.historyBuffer)==null?void 0:n.getChangesSince(t))??Tn}}const Ov=zs("Computed",()=>fD);function gD(e={},t,n,r){const o=r.value,s=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[s];return i||(i=new Ov(n,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[yD]=!0,r}function Rw(e={},t,n,r){return r.get?(pD(),mD(e,t,n,r)):gD(e,t,n,r)}function mD(e={},t,n,r){const o=r.get,s=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[s];return i||(i=new Ov(n,o.bind(this),e),Object.defineProperty(this,s,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}const yD="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const e=arguments[0];return(t,n,r)=>Rw(e,t,n,r)}else return typeof arguments[0]=="string"?new Ov(arguments[0],arguments[1],arguments[2]):Rw(void 0,arguments[0],arguments[1],arguments[2])}const $I=1,SD=zs("apiVersion",()=>$I);if(SD!==$I)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");function cf(e,t){const n=Se.useRef(t);n.current=t;const[r,o,s]=Se.useMemo(()=>{let i=null;const a=u=>(i=u,()=>{i=null}),l=new ul(`useStateTracking(${e})`,()=>{var u;return(u=n.current)==null?void 0:u.call(n)},{scheduleEffect(){i==null||i()}});return[l,a,()=>l.scheduleCount]},[e]);return Se.useSyncExternalStore(o,s,s),Se.useEffect(()=>(r.attach(),r.maybeScheduleEffect(),()=>{r.detach()}),[r]),r.execute()}const Lw={apply(e,t,n){return cf(e.displayName??e.name??"tracked(???)",()=>e.apply(t,n))}},vD=Symbol.for("react.memo"),xD=Symbol.for("react.forward_ref");function tr(e){let t=null;const n=e.$$typeof;return n===vD&&(e=e.type,t=e.compare),n===xD?x.memo(x.forwardRef(new Proxy(e.render,Lw))):x.memo(new Proxy(e,Lw),t)}function MI(){const e=arguments[0],t=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return x.useMemo(()=>G(`useComputed(${e})`,t,n),r)}function Mo(e,t,n=$s){x.useEffect(()=>{const r=new ul(e,t);return r.attach(),r.execute(),()=>{r.detach()}},n)}function K(){const e=arguments,t=e.length===3?e[2]:[e[0]],n=e.length===3?e[0]:`useValue(${e[0].name})`,r=x.useRef(!0);r.current=!0;const o=x.useMemo(()=>e.length===1?e[0]:G(n,()=>{if(r.current)return e[1]();try{return e[1]()}catch{return{}}}),t);try{const{subscribe:s,getSnapshot:i}=x.useMemo(()=>({subscribe:a=>wu(`useValue(${n})`,()=>{o.get(),a()}),getSnapshot:()=>o.get()}),[o]);return x.useSyncExternalStore(s,i,i)}finally{r.current=!1}}class th{constructor(t){m(this,"nextValue");m(this,"diff");this.previousValue=t}get(){var r,o,s,i;const t=((o=(r=this.diff)==null?void 0:r.removed)==null?void 0:o.size)??0,n=((i=(s=this.diff)==null?void 0:s.added)==null?void 0:i.size)??0;if(!(t===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(t,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(t),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(t):((o=this.diff).added??(o.added=new Set),this.diff.added.add(t))}add(t){var o,s,i;const n=this.previousValue.has(t);if(n)return((s=(o=this.diff)==null?void 0:o.removed)==null?void 0:s.has(t))?this._add(t,n):void 0;(i=this.nextValue)!=null&&i.has(t)||this._add(t,n)}_remove(t,n){var r,o;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(t),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(t)):(o=this.diff.added)==null||o.delete(t)}remove(t){var o,s,i,a;const n=this.previousValue.has(t);if(!n)return((s=(o=this.diff)==null?void 0:o.added)==null?void 0:s.has(t))?this._remove(t,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(t)||this._remove(t,n)}}function ep(e,t){const n=[];e:for(const r of e){for(const o of n)if(t?t(r,o):r===o)continue e;n.push(r)}return n}function fe(e){return e.filter(t=>t!=null)}function Vn(e){return e[e.length-1]}function wD(e,t){let n,r=1/0;for(const o of e){const s=t(o);s<r&&(n=o,r=s)}return n}function bD(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function PD(e,t){let n,r;return function(...o){return n||(n=!0,setTimeout(()=>n=!1,t),r=e(...o)),r}}function AI(e){const t=(...n)=>{try{return e(...n)}catch(r){throw r instanceof Error&&Error.captureStackTrace&&Error.captureStackTrace(r,t),r}};return t}const ri={ok(e){return{ok:!0,value:e}},err(e){return{ok:!1,error:e}}};function Bs(e,t){const n=t&&e&&typeof e=="object"&&t in e?e[t]:e;throw new Error(`Unknown switch case ${n}`)}const Ao=AI((e,t)=>{if(!e)throw new Error(t||"Assertion Error")}),di=AI((e,t)=>{if(e==null)throw new Error(t??"value must be defined");return e});function jI(e,t){let n;const r=(...o)=>(n||(n={},n.promise=new Promise((s,i)=>{n.resolve=s,n.reject=i})),clearTimeout(n.timeout),n.latestArgs=o,n.timeout=setTimeout(()=>{const s=n;n=void 0;try{s.resolve(e(...s.latestArgs))}catch(i){s.reject(i)}},t),n.promise);return r.cancel=()=>{n&&clearTimeout(n.timeout)},r}const Fw=new WeakMap;function Dv(e,t){if(typeof e!="object"||e===null)return;let n=Fw.get(e);n||(n={tags:{},extras:{}},Fw.set(e,n)),t.tags&&(n.tags={...n.tags,...t.tags}),t.extras&&(n.extras={...n.extras,...t.extras})}class Aa{static async dataUrlToArrayBuffer(t){return fetch(t).then(function(n){return n.arrayBuffer()})}static async blobToDataUrl(t){return await new Promise((n,r)=>{if(t){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsDataURL(t)}})}static async blobToText(t){return await new Promise((n,r)=>{if(t){const o=new FileReader;o.onload=()=>n(o.result),o.onerror=s=>r(s),o.onabort=s=>r(s),o.readAsText(t)}})}}function _y(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n),t|=0;return t+""}function CD(e){const t=new DataView(e);let n=0;for(let r=0;r<t.byteLength;r++)n=(n<<5)-n+t.getUint8(r),n|=0;return n+""}let ky=[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"&&(ky=new Int32Array(ky));const ID=(e,t)=>{let n=t===0?0:~~t^-1;for(let r=0;r<e.length;r++)n=ky[(n^e[r])&255]^n>>>8;return n^-1},Nw=4,zw=4;class Gr{static isPng(t,n){return t.getUint8(n+0)===137&&t.getUint8(n+1)===80&&t.getUint8(n+2)===78&&t.getUint8(n+3)===71&&t.getUint8(n+4)===13&&t.getUint8(n+5)===10&&t.getUint8(n+6)===26&&t.getUint8(n+7)===10}static getChunkType(t,n){return[String.fromCharCode(t.getUint8(n)),String.fromCharCode(t.getUint8(n+1)),String.fromCharCode(t.getUint8(n+2)),String.fromCharCode(t.getUint8(n+3))].join("")}static readChunks(t,n=0){const r={};if(!Gr.isPng(t,n))throw new Error("Not a PNG");for(n+=8;n<=t.buffer.byteLength;){const o=n,s=t.getInt32(n);n+=4;const i=Gr.getChunkType(t,n);if(i==="IDAT"&&r[i]){n+=s+Nw+zw;continue}if(i==="IEND")break;r[i]={start:o,dataOffset:n+4,size:s},n+=s+Nw+zw}return r}static parsePhys(t,n){return{ppux:t.getUint32(n),ppuy:t.getUint32(n+4),unit:t.getUint8(n+4)}}static findChunk(t,n){return Gr.readChunks(t)[n]}static setPhysChunk(t,n=1,r){let o=46,s=0;const i=Gr.findChunk(t,"pHYs");i&&(o=i.start,s=i.size);const a=Gr.findChunk(t,"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*n),c.setInt32(12,u*n),c.setInt8(16,1);const d=new Uint8Array(l.slice(4,17));c.setInt32(17,ID(d));const p=t.buffer.slice(0,o),f=t.buffer.slice(o+s);return new Blob([p,l,f],r)}}class ko{static loadVideo(t){return new Promise((n,r)=>{const o=document.createElement("video");o.onloadeddata=()=>n(o),o.onerror=s=>{console.error(s),r(new Error("Could not load video"))},o.crossOrigin="anonymous",o.src=t})}static loadImage(t){return new Promise((n,r)=>{const o=new Image;o.onload=()=>n(o),o.onerror=s=>{console.error(s),r(new Error("Could not load image"))},o.crossOrigin="anonymous",o.src=t})}static async getVideoSize(t){return ko.usingObjectURL(t,async n=>{const r=await ko.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(t){const n=await ko.usingObjectURL(t,ko.loadImage);try{if(t.type==="image/png"){const r=new DataView(await t.arrayBuffer());if(Gr.isPng(r,0)){const o=Gr.findChunk(r,"pHYs");if(o){const s=Gr.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(n.naturalWidth/i),h:Math.round(n.naturalHeight/i)}}}}}}catch(r){return console.error(r),{w:n.naturalWidth,h:n.naturalHeight}}return{w:n.naturalWidth,h:n.naturalHeight}}static async usingObjectURL(t,n){const r=URL.createObjectURL(t);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function Us(e=""){let t=0,n=0,r=0,o=0;function s(){const i=t^t<<11;return t=n,n=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)t^=e.charCodeAt(i)|0,s();return s}function tp(e,t,n,r=!1){const[o,s]=t,[i,a]=n,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 Qr(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function pr(e,t){if(Qr(e,t))return e[t]}function Bw(e){return Object.keys(e)}function at(e){return Object.values(e)}function Jr(e){return Object.entries(e)}function Rv(e){return Object.fromEntries(e)}function Pg(e,t){const n={};let r=!1;for(const[o,s]of Jr(e))t(o,s)?n[o]=s:r=!0;return r?n:e}function np(e,t){const n={};for(const[r,o]of Jr(e)){const s=t(r,o);n[r]=s}return n}function OI(e,t){if(e===t)return!0;const n=new Set(Object.keys(e)),r=new Set(Object.keys(t));if(n.size!==r.size)return!1;for(const o of n)if(!r.has(o)||!Object.is(e[o],t[o]))return!1;return!0}const Gn="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",DI="a0",RI="A00000000000000000000000000";function LI(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 FI(e){if(e.length!==LI(e.charAt(0)))throw new Error("invalid integer part of index key: "+e)}function Uw(e){if(e===void 0)throw Error("n is undefined")}function Hw(e){FI(e);const[t,...n]=e.split("");let r=!0;for(let o=n.length-1;r&&o>=0;o--){const s=Gn.indexOf(n[o])+1;s===Gn.length?n[o]="0":(n[o]=Gn.charAt(s),r=!1)}if(r){if(t==="Z")return"a0";if(t==="z")return;const o=String.fromCharCode(t.charCodeAt(0)+1);return o>"a"?n.push("0"):n.pop(),o+n.join("")}else return t+n.join("")}function ED(e){FI(e);const[t,...n]=e.split("");let r=!0;for(let o=n.length-1;r&&o>=0;o--){const s=Gn.indexOf(n[o])-1;s===-1?n[o]=Gn.slice(-1):(n[o]=Gn.charAt(s),r=!1)}if(r){if(t==="a")return"Z"+Gn.slice(-1);if(t==="A")return;const o=String.fromCharCode(t.charCodeAt(0)-1);return o<"Z"?n.push(Gn.slice(-1)):n.pop(),o+n.join("")}else return t+n.join("")}function ha(e,t){if(t!==void 0&&e>=t)throw new Error(e+" >= "+t);if(e.slice(-1)==="0"||t&&t.slice(-1)==="0")throw new Error("trailing zero");if(t){let o=0;for(;(e.charAt(o)||"0")===t.charAt(o);)o++;if(o>0)return t.slice(0,o)+ha(e.slice(o),t.slice(o))}const n=e?Gn.indexOf(e.charAt(0)):0,r=t!==void 0?Gn.indexOf(t.charAt(0)):Gn.length;if(r-n>1){const o=Math.round(.5*(n+r));return Gn.charAt(o)}else return t&&t.length>1?t.slice(0,1):Gn.charAt(n)+ha(e.slice(1),void 0)}function sc(e){const t=LI(e.charAt(0));if(t>e.length)throw new Error("invalid index: "+e);return e.slice(0,t)}function Ty(e){if(e===RI)throw new Error("invalid index: "+e);const t=sc(e);if(e.slice(t.length).slice(-1)==="0")throw new Error("invalid index: "+e)}function Xi(e,t){if(e!==void 0&&Ty(e),t!==void 0&&Ty(t),e!==void 0&&t!==void 0&&e>=t)throw new Error(e+" >= "+t);if(e===void 0&&t===void 0)return DI;if(e===void 0){if(t===void 0)throw Error("b is undefined");const a=sc(t),l=t.slice(a.length);if(a===RI)return a+ha("",l);if(a<t)return a;const c=ED(a);return Uw(c),c}if(t===void 0){const a=sc(e),l=e.slice(a.length),c=Hw(a);return c===void 0?a+ha(l,void 0):c}const n=sc(e),r=e.slice(n.length),o=sc(t),s=t.slice(o.length);if(n===o)return n+ha(r,s);const i=Hw(n);return Uw(i),i<t?i:n+ha(r,void 0)}function Ms(e,t,n){if(n===0)return[];if(n===1)return[Xi(e,t)];if(t===void 0){let s=Xi(e,t);const i=[s];for(let a=0;a<n-1;a++)s=Xi(s,t),i.push(s);return i}if(e===void 0){let s=Xi(e,t);const i=[s];for(let a=0;a<n-1;a++)s=Xi(e,s),i.push(s);return i.reverse(),i}const r=Math.floor(n/2),o=Xi(e,t);return[...Ms(e,o,r),o,...Ms(o,t,n-r-1)]}const _D=DI;function kD(e){Ty(e)}function Wa(e,t,n){return Ms(e,t,n)}function Cg(e,t){return Ms(e,void 0,t)}function fc(e,t){return Ms(e,t,1)[0]}function Eo(e){return Ms(e,void 0,1)[0]}function TD(e){return Ms(void 0,e,1)[0]}function Ac(e,t="a1"){return[t,...Ms(t,void 0,e)]}function Lt(e,t){return e.index<t.index?-1:e.index>t.index?1:0}function $D(e,t){return e.id>t.id?1:-1}function Lv(e){try{return localStorage.getItem(e)}catch{return null}}function Fv(e,t){try{localStorage.setItem(e,t)}catch{}}function MD(){try{localStorage.clear()}catch{}}function NI(e){try{return sessionStorage.getItem(e)}catch{return null}}function Nv(e,t){try{sessionStorage.setItem(e,t)}catch{}}function zI(e){try{sessionStorage.removeItem(e)}catch{}}function AD(){try{sessionStorage.clear()}catch{}}const jD=()=>typeof process<"u"&&!1,pa=[],OD=60,nh=Math.ceil(1e3/OD);let Al,Ig=0,$y=0;const DD=()=>{const e=pa.splice(0,pa.length);for(const t of e)t()};function BI(){if(Al)return;const e=Date.now(),t=e-$y;if(Ig+t<nh){Al=requestAnimationFrame(()=>{Al=void 0,BI()});return}Al=requestAnimationFrame(()=>{Al=void 0,$y=e,Ig=Math.min(Ig+t-nh,nh*10),DD()})}let Kw=!1;function UI(e){return jD()?(e(),()=>{}):(pa.includes(e)||(pa.push(e),Kw||(Kw=!0,$y=Date.now()-nh-1),BI()),()=>{const t=pa.indexOf(e);t>-1&&pa.splice(t,1)})}function RD(e){return e!==null}function LD(){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 HI=LD(),vt=HI[0];HI[1];const FD=Object.getPrototypeOf(vt({}));let uf=(e=21)=>crypto.getRandomValues(new Uint8Array(e)).reduce((t,n)=>(n&=63,n<36?t+=n.toString(36):n<62?t+=(n-26).toString(36).toUpperCase():n>62?t+="-":t+="_",t),"");class zv{constructor(t,n){m(this,"createDefaultProperties");m(this,"migrations");m(this,"validator");m(this,"scope");m(this,"isInstance",t=>(t==null?void 0:t.typeName)===this.typeName);this.typeName=t,this.createDefaultProperties=n.createDefaultProperties,this.migrations=n.migrations,this.validator=n.validator??{validate:r=>r},this.scope=n.scope??"document"}create(t){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,o]of Object.entries(t))o!==void 0&&(n[r]=o);return n.typeName=this.typeName,n}clone(t){return{...vt(t),id:this.createId()}}createId(t){return this.typeName+":"+(t??uf())}createCustomId(t){return this.typeName+":"+t}parseId(t){if(!this.isId(t))throw new Error(`ID "${t}" is not a valid ID for type "${this.typeName}"`);return t.slice(this.typeName.length+1)}isId(t){if(!t)return!1;for(let n=0;n<this.typeName.length;n++)if(t[n]!==this.typeName[n])return!1;return t[this.typeName.length]===":"}withDefaultProperties(t){return new zv(this.typeName,{createDefaultProperties:t,migrations:this.migrations,validator:this.validator,scope:this.scope})}validate(t,n){return n&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(n,t):this.validator.validate(t)}}function Yo(e,t){return new zv(e,{createDefaultProperties:()=>({}),migrations:t.migrations??{currentVersion:0,firstVersion:0,migrators:{}},validator:t.validator,scope:t.scope})}class Vw{constructor(){m(this,"items",new WeakMap)}get(t,n){return this.items.has(t)||this.items.set(t,n(t)),this.items.get(t)}}var rp={exports:{}};rp.exports;(function(e,t){var n=200,r="__lodash_hash_undefined__",o=1,s=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",d="[object Date]",p="[object Error]",f="[object Function]",y="[object GeneratorFunction]",g="[object Map]",w="[object Number]",S="[object Null]",v="[object Object]",C="[object Promise]",I="[object Proxy]",P="[object RegExp]",E="[object Set]",_="[object String]",k="[object Symbol]",$="[object Undefined]",T="[object WeakMap]",j="[object ArrayBuffer]",L="[object DataView]",N="[object Float32Array]",F="[object Float64Array]",B="[object Int8Array]",q="[object Int16Array]",Q="[object Int32Array]",V="[object Uint8Array]",U="[object Uint8ClampedArray]",H="[object Uint16Array]",Z="[object Uint32Array]",ce=/[\\^$.*+?()[\]{}|]/g,be=/^\[object .+?Constructor\]$/,ke=/^(?:0|[1-9]\d*)$/,ae={};ae[N]=ae[F]=ae[B]=ae[q]=ae[Q]=ae[V]=ae[U]=ae[H]=ae[Z]=!0,ae[a]=ae[l]=ae[j]=ae[u]=ae[L]=ae[d]=ae[p]=ae[f]=ae[g]=ae[w]=ae[v]=ae[P]=ae[E]=ae[_]=ae[T]=!1;var Te=typeof tn=="object"&&tn&&tn.Object===Object&&tn,Re=typeof self=="object"&&self&&self.Object===Object&&self,st=Te||Re||Function("return this")(),Pe=t&&!t.nodeType&&t,ft=Pe&&!0&&e&&!e.nodeType&&e,He=ft&&ft.exports===Pe,or=He&&Te.process,Fn=function(){try{return or&&or.binding&&or.binding("util")}catch{}}(),Nn=Fn&&Fn.isTypedArray;function qe(M,D){for(var W=-1,J=M==null?0:M.length,Ze=0,ge=[];++W<J;){var gt=M[W];D(gt,W,M)&&(ge[Ze++]=gt)}return ge}function jt(M,D){for(var W=-1,J=D.length,Ze=M.length;++W<J;)M[Ze+W]=D[W];return M}function yo(M,D){for(var W=-1,J=M==null?0:M.length;++W<J;)if(D(M[W],W,M))return!0;return!1}function El(M,D){for(var W=-1,J=Array(M);++W<M;)J[W]=D(W);return J}function _l(M){return function(D){return M(D)}}function fg(M,D){return M.has(D)}function Gi(M,D){return M==null?void 0:M[D]}function kj(M){var D=-1,W=Array(M.size);return M.forEach(function(J,Ze){W[++D]=[Ze,J]}),W}function Tj(M,D){return function(W){return M(D(W))}}function $j(M){var D=-1,W=Array(M.size);return M.forEach(function(J){W[++D]=J}),W}var Mj=Array.prototype,Aj=Function.prototype,Uu=Object.prototype,gg=st["__core-js_shared__"],pw=Aj.toString,Ur=Uu.hasOwnProperty,fw=function(){var M=/[^.]+$/.exec(gg&&gg.keys&&gg.keys.IE_PROTO||"");return M?"Symbol(src)_1."+M:""}(),gw=Uu.toString,jj=RegExp("^"+pw.call(Ur).replace(ce,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),mw=He?st.Buffer:void 0,Hu=st.Symbol,yw=st.Uint8Array,Sw=Uu.propertyIsEnumerable,Oj=Mj.splice,Qs=Hu?Hu.toStringTag:void 0,vw=Object.getOwnPropertySymbols,Dj=mw?mw.isBuffer:void 0,Rj=Tj(Object.keys,Object),mg=Yi(st,"DataView"),kl=Yi(st,"Map"),yg=Yi(st,"Promise"),Sg=Yi(st,"Set"),vg=Yi(st,"WeakMap"),Tl=Yi(Object,"create"),Lj=ti(mg),Fj=ti(kl),Nj=ti(yg),zj=ti(Sg),Bj=ti(vg),xw=Hu?Hu.prototype:void 0,xg=xw?xw.valueOf:void 0;function Js(M){var D=-1,W=M==null?0:M.length;for(this.clear();++D<W;){var J=M[D];this.set(J[0],J[1])}}function Uj(){this.__data__=Tl?Tl(null):{},this.size=0}function Hj(M){var D=this.has(M)&&delete this.__data__[M];return this.size-=D?1:0,D}function Kj(M){var D=this.__data__;if(Tl){var W=D[M];return W===r?void 0:W}return Ur.call(D,M)?D[M]:void 0}function Vj(M){var D=this.__data__;return Tl?D[M]!==void 0:Ur.call(D,M)}function Wj(M,D){var W=this.__data__;return this.size+=this.has(M)?0:1,W[M]=Tl&&D===void 0?r:D,this}Js.prototype.clear=Uj,Js.prototype.delete=Hj,Js.prototype.get=Kj,Js.prototype.has=Vj,Js.prototype.set=Wj;function So(M){var D=-1,W=M==null?0:M.length;for(this.clear();++D<W;){var J=M[D];this.set(J[0],J[1])}}function Gj(){this.__data__=[],this.size=0}function Yj(M){var D=this.__data__,W=Vu(D,M);if(W<0)return!1;var J=D.length-1;return W==J?D.pop():Oj.call(D,W,1),--this.size,!0}function Xj(M){var D=this.__data__,W=Vu(D,M);return W<0?void 0:D[W][1]}function qj(M){return Vu(this.__data__,M)>-1}function Zj(M,D){var W=this.__data__,J=Vu(W,M);return J<0?(++this.size,W.push([M,D])):W[J][1]=D,this}So.prototype.clear=Gj,So.prototype.delete=Yj,So.prototype.get=Xj,So.prototype.has=qj,So.prototype.set=Zj;function ei(M){var D=-1,W=M==null?0:M.length;for(this.clear();++D<W;){var J=M[D];this.set(J[0],J[1])}}function Qj(){this.size=0,this.__data__={hash:new Js,map:new(kl||So),string:new Js}}function Jj(M){var D=Wu(this,M).delete(M);return this.size-=D?1:0,D}function eO(M){return Wu(this,M).get(M)}function tO(M){return Wu(this,M).has(M)}function nO(M,D){var W=Wu(this,M),J=W.size;return W.set(M,D),this.size+=W.size==J?0:1,this}ei.prototype.clear=Qj,ei.prototype.delete=Jj,ei.prototype.get=eO,ei.prototype.has=tO,ei.prototype.set=nO;function Ku(M){var D=-1,W=M==null?0:M.length;for(this.__data__=new ei;++D<W;)this.add(M[D])}function rO(M){return this.__data__.set(M,r),this}function oO(M){return this.__data__.has(M)}Ku.prototype.add=Ku.prototype.push=rO,Ku.prototype.has=oO;function rs(M){var D=this.__data__=new So(M);this.size=D.size}function sO(){this.__data__=new So,this.size=0}function iO(M){var D=this.__data__,W=D.delete(M);return this.size=D.size,W}function aO(M){return this.__data__.get(M)}function lO(M){return this.__data__.has(M)}function cO(M,D){var W=this.__data__;if(W instanceof So){var J=W.__data__;if(!kl||J.length<n-1)return J.push([M,D]),this.size=++W.size,this;W=this.__data__=new ei(J)}return W.set(M,D),this.size=W.size,this}rs.prototype.clear=sO,rs.prototype.delete=iO,rs.prototype.get=aO,rs.prototype.has=lO,rs.prototype.set=cO;function uO(M,D){var W=Gu(M),J=!W&&IO(M),Ze=!W&&!J&&wg(M),ge=!W&&!J&&!Ze&&Tw(M),gt=W||J||Ze||ge,_t=gt?El(M.length,String):[],Ot=_t.length;for(var it in M)(D||Ur.call(M,it))&&!(gt&&(it=="length"||Ze&&(it=="offset"||it=="parent")||ge&&(it=="buffer"||it=="byteLength"||it=="byteOffset")||xO(it,Ot)))&&_t.push(it);return _t}function Vu(M,D){for(var W=M.length;W--;)if(Iw(M[W][0],D))return W;return-1}function dO(M,D,W){var J=D(M);return Gu(M)?J:jt(J,W(M))}function $l(M){return M==null?M===void 0?$:S:Qs&&Qs in Object(M)?SO(M):CO(M)}function ww(M){return Ml(M)&&$l(M)==a}function bw(M,D,W,J,Ze){return M===D?!0:M==null||D==null||!Ml(M)&&!Ml(D)?M!==M&&D!==D:hO(M,D,W,J,bw,Ze)}function hO(M,D,W,J,Ze,ge){var gt=Gu(M),_t=Gu(D),Ot=gt?l:os(M),it=_t?l:os(D);Ot=Ot==a?v:Ot,it=it==a?v:it;var zn=Ot==v,br=it==v,Kt=Ot==it;if(Kt&&wg(M)){if(!wg(D))return!1;gt=!0,zn=!1}if(Kt&&!zn)return ge||(ge=new rs),gt||Tw(M)?Pw(M,D,W,J,Ze,ge):mO(M,D,Ot,W,J,Ze,ge);if(!(W&o)){var sr=zn&&Ur.call(M,"__wrapped__"),ir=br&&Ur.call(D,"__wrapped__");if(sr||ir){var ss=sr?M.value():M,vo=ir?D.value():D;return ge||(ge=new rs),Ze(ss,vo,W,J,ge)}}return Kt?(ge||(ge=new rs),yO(M,D,W,J,Ze,ge)):!1}function pO(M){if(!kw(M)||bO(M))return!1;var D=Ew(M)?jj:be;return D.test(ti(M))}function fO(M){return Ml(M)&&_w(M.length)&&!!ae[$l(M)]}function gO(M){if(!PO(M))return Rj(M);var D=[];for(var W in Object(M))Ur.call(M,W)&&W!="constructor"&&D.push(W);return D}function Pw(M,D,W,J,Ze,ge){var gt=W&o,_t=M.length,Ot=D.length;if(_t!=Ot&&!(gt&&Ot>_t))return!1;var it=ge.get(M);if(it&&ge.get(D))return it==D;var zn=-1,br=!0,Kt=W&s?new Ku:void 0;for(ge.set(M,D),ge.set(D,M);++zn<_t;){var sr=M[zn],ir=D[zn];if(J)var ss=gt?J(ir,sr,zn,D,M,ge):J(sr,ir,zn,M,D,ge);if(ss!==void 0){if(ss)continue;br=!1;break}if(Kt){if(!yo(D,function(vo,ni){if(!fg(Kt,ni)&&(sr===vo||Ze(sr,vo,W,J,ge)))return Kt.push(ni)})){br=!1;break}}else if(!(sr===ir||Ze(sr,ir,W,J,ge))){br=!1;break}}return ge.delete(M),ge.delete(D),br}function mO(M,D,W,J,Ze,ge,gt){switch(W){case L:if(M.byteLength!=D.byteLength||M.byteOffset!=D.byteOffset)return!1;M=M.buffer,D=D.buffer;case j:return!(M.byteLength!=D.byteLength||!ge(new yw(M),new yw(D)));case u:case d:case w:return Iw(+M,+D);case p:return M.name==D.name&&M.message==D.message;case P:case _:return M==D+"";case g:var _t=kj;case E:var Ot=J&o;if(_t||(_t=$j),M.size!=D.size&&!Ot)return!1;var it=gt.get(M);if(it)return it==D;J|=s,gt.set(M,D);var zn=Pw(_t(M),_t(D),J,Ze,ge,gt);return gt.delete(M),zn;case k:if(xg)return xg.call(M)==xg.call(D)}return!1}function yO(M,D,W,J,Ze,ge){var gt=W&o,_t=Cw(M),Ot=_t.length,it=Cw(D),zn=it.length;if(Ot!=zn&&!gt)return!1;for(var br=Ot;br--;){var Kt=_t[br];if(!(gt?Kt in D:Ur.call(D,Kt)))return!1}var sr=ge.get(M);if(sr&&ge.get(D))return sr==D;var ir=!0;ge.set(M,D),ge.set(D,M);for(var ss=gt;++br<Ot;){Kt=_t[br];var vo=M[Kt],ni=D[Kt];if(J)var $w=gt?J(ni,vo,Kt,D,M,ge):J(vo,ni,Kt,M,D,ge);if(!($w===void 0?vo===ni||Ze(vo,ni,W,J,ge):$w)){ir=!1;break}ss||(ss=Kt=="constructor")}if(ir&&!ss){var Yu=M.constructor,Xu=D.constructor;Yu!=Xu&&"constructor"in M&&"constructor"in D&&!(typeof Yu=="function"&&Yu instanceof Yu&&typeof Xu=="function"&&Xu instanceof Xu)&&(ir=!1)}return ge.delete(M),ge.delete(D),ir}function Cw(M){return dO(M,kO,vO)}function Wu(M,D){var W=M.__data__;return wO(D)?W[typeof D=="string"?"string":"hash"]:W.map}function Yi(M,D){var W=Gi(M,D);return pO(W)?W:void 0}function SO(M){var D=Ur.call(M,Qs),W=M[Qs];try{M[Qs]=void 0;var J=!0}catch{}var Ze=gw.call(M);return J&&(D?M[Qs]=W:delete M[Qs]),Ze}var vO=vw?function(M){return M==null?[]:(M=Object(M),qe(vw(M),function(D){return Sw.call(M,D)}))}:TO,os=$l;(mg&&os(new mg(new ArrayBuffer(1)))!=L||kl&&os(new kl)!=g||yg&&os(yg.resolve())!=C||Sg&&os(new Sg)!=E||vg&&os(new vg)!=T)&&(os=function(M){var D=$l(M),W=D==v?M.constructor:void 0,J=W?ti(W):"";if(J)switch(J){case Lj:return L;case Fj:return g;case Nj:return C;case zj:return E;case Bj:return T}return D});function xO(M,D){return D=D??i,!!D&&(typeof M=="number"||ke.test(M))&&M>-1&&M%1==0&&M<D}function wO(M){var D=typeof M;return D=="string"||D=="number"||D=="symbol"||D=="boolean"?M!=="__proto__":M===null}function bO(M){return!!fw&&fw in M}function PO(M){var D=M&&M.constructor,W=typeof D=="function"&&D.prototype||Uu;return M===W}function CO(M){return gw.call(M)}function ti(M){if(M!=null){try{return pw.call(M)}catch{}try{return M+""}catch{}}return""}function Iw(M,D){return M===D||M!==M&&D!==D}var IO=ww(function(){return arguments}())?ww:function(M){return Ml(M)&&Ur.call(M,"callee")&&!Sw.call(M,"callee")},Gu=Array.isArray;function EO(M){return M!=null&&_w(M.length)&&!Ew(M)}var wg=Dj||$O;function _O(M,D){return bw(M,D)}function Ew(M){if(!kw(M))return!1;var D=$l(M);return D==f||D==y||D==c||D==I}function _w(M){return typeof M=="number"&&M>-1&&M%1==0&&M<=i}function kw(M){var D=typeof M;return M!=null&&(D=="object"||D=="function")}function Ml(M){return M!=null&&typeof M=="object"}var Tw=Nn?_l(Nn):fO;function kO(M){return EO(M)?uO(M):gO(M)}function TO(){return[]}function $O(){return!1}e.exports=_O})(rp,rp.exports);var ND=rp.exports;const zD=ll(ND);function BD(e){if(e.length===0)return new Set;const t=e[0],n=e.slice(1),r=new Set;for(const o of t)n.every(s=>s.has(o))&&r.add(o);return r}function UD(e,t){const n={};for(const r of t)e.has(r)||(n.added??(n.added=new Set),n.added.add(r));for(const r of e)t.has(r)||(n.removed??(n.removed=new Set),n.removed.add(r));return n.added||n.removed?n:void 0}function Ww(e,t){for(const[n,r]of Object.entries(e)){const o=r,s=t[n];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 Gw(e,t,n){const r=Object.fromEntries(Object.keys(n).map(o=>[o,new Set]));for(const[o,s]of Object.entries(n))if("eq"in s){const a=e.index(t,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(t,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(t,o);for(const[a,l]of i.get())if(a>s.gt)for(const c of l)r[o].add(c)}return BD(Object.values(r))}class HD{constructor(t,n){m(this,"indexCache",new Map);m(this,"historyCache",new Map);this.atoms=t,this.history=n}filterHistory(t){if(this.historyCache.has(t))return this.historyCache.get(t);const n=G("filterHistory:"+t,(r,o)=>{if(Si(r))return this.history.get();const s=this.history.getDiffSince(o);if(s===Tn)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of s){for(const d of at(u.added))if(d.typeName===t)if(i.removed[d.id]){const p=i.removed[d.id];delete i.removed[d.id],l--,p!==d&&(i.updated[d.id]=[p,d],c++)}else i.added[d.id]=d,a++;for(const[d,p]of at(u.updated))p.typeName===t&&(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]=[d,p],c++));for(const d of at(u.removed))d.typeName===t&&(i.added[d.id]?(delete i.added[d.id],a--):i.updated[d.id]?(i.removed[d.id]=i.updated[d.id][0],delete i.updated[d.id],c--,l++):(i.removed[d.id]=d,l++))}return a||l||c?oc(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(t,n),n}index(t,n){const r=t+":"+n;if(this.indexCache.has(r))return this.indexCache.get(r);const o=this.__uncached_createIndex(t,n);return this.indexCache.set(r,o),o}__uncached_createIndex(t,n){const r=this.filterHistory(t),o=()=>{r.get();const s=new Map;for(const i of at(this.atoms.get())){const a=i.get();if(a.typeName===t){const l=a[n];s.has(l)||s.set(l,new Set),s.get(l).add(a.id)}}return s};return G("index:"+t+":"+n,(s,i)=>{if(Si(s))return o();const a=r.getDiffSince(i);if(a===Tn)return o();const l=new Map,c=(f,y)=>{let g=l.get(f);g||(g=new th(s.get(f)??new Set)),g.add(y),l.set(f,g)},u=(f,y)=>{let g=l.get(f);g||(g=new th(s.get(f)??new Set)),g.remove(y),l.set(f,g)};for(const f of a){for(const y of at(f.added))if(y.typeName===t){const g=y[n];c(g,y.id)}for(const[y,g]of at(f.updated))if(g.typeName===t){const w=y[n],S=g[n];w!==S&&(u(w,g.id),c(S,g.id))}for(const y of at(f.removed))if(y.typeName===t){const g=y[n];u(g,y.id)}}let d,p;for(const[f,y]of l){const g=y.get();g&&(d||(d=new Map(s)),p||(p=new Map),g.value.size===0?d.delete(f):d.set(f,g.value),p.set(f,g.diff))}return d&&p?oc(d,p):s},{historyLength:100})}record(t,n=()=>({}),r="record:"+t+(n?":"+n.toString():"")){const o=this.ids(t,n,r);return G(r,()=>{var s;for(const i of o.get())return(s=this.atoms.get()[i])==null?void 0:s.get()})}records(t,n=()=>({}),r="records:"+t+(n?":"+n.toString():"")){const o=this.ids(t,n,"ids:"+r);return G(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(t,n=()=>({}),r="ids:"+t+(n?":"+n.toString():"")){const o=this.filterHistory(t),s=()=>{o.get();const l=n();return Object.keys(l).length===0?new Set(at(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===t?u.id:[]})):Gw(this,t,l)},i=l=>{const c=s(),u=UD(l,c);return u?oc(c,u):l},a=G("ids_query:"+r,n,{isEqual:zD});return G("query:"+r,(l,c)=>{const u=a.get();if(Si(l))return s();if(c<a.lastChangedEpoch)return i(l);const d=o.getDiffSince(c);if(d===Tn)return i(l);const p=new th(l);for(const y of d){for(const g of at(y.added))g.typeName===t&&Ww(u,g)&&p.add(g.id);for(const[g,w]of at(y.updated))w.typeName===t&&(Ww(u,w)?p.add(w.id):p.remove(w.id));for(const g of at(y.removed))g.typeName===t&&p.remove(g.id)}const f=p.get();return f?oc(f.value,f.diff):l},{historyLength:50})}exec(t,n){const r=Gw(this,t,n);if(r.size===0)return $s;const o=this.atoms.get();return[...r].map(s=>o[s].get())}}class KI{constructor(t){m(this,"id",uf());m(this,"atoms",In("store_atoms",{}));m(this,"history",In("history",0,{historyLength:1e3}));m(this,"query",new HD(this.atoms,this.history));m(this,"listeners",new Set);m(this,"historyAccumulator",new VD);m(this,"historyReactor");m(this,"schema");m(this,"props");m(this,"scopedTypes");m(this,"onBeforeCreate");m(this,"onAfterCreate");m(this,"onBeforeChange");m(this,"onAfterChange");m(this,"onBeforeDelete");m(this,"onAfterDelete");m(this,"_runCallbacks",!0);m(this,"put",(t,n)=>{Tr(()=>{const r={},o={},s=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.onBeforeCreate&&this._runCallbacks?this.onBeforeCreate:null,u=this.onBeforeChange&&this._runCallbacks?this.onBeforeChange:null,d=this.isMergingRemoteChanges?"remote":"user";for(let p=0,f=t.length;p<f;p++){a=t[p];const y=(i??s)[a.id];if(y){const g=y.__unsafe__getWithoutCapture();if(u&&(a=u(g,a,d)),this.schema.validateRecord(this,a,n??"updateRecord",g)===g)continue;y.set(a),l=!0,r[a.id]=[g,y.__unsafe__getWithoutCapture()]}else c&&(a=c(a,d)),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),o[a.id]=a,i||(i={...s}),i[a.id]=In("atom:"+a.id,a)}if(i&&this.atoms.set(i),!!l&&(this.updateHistory({added:o,updated:r,removed:{}}),this._runCallbacks)){const{onAfterCreate:p,onAfterChange:f}=this;p&&Object.values(o).forEach(y=>{p(y,d)}),f&&Object.values(r).forEach(([y,g])=>{f(y,g,d)})}})});m(this,"remove",t=>{Tr(()=>{const n=[],r=this.isMergingRemoteChanges?"remote":"user";if(this.onBeforeDelete&&this._runCallbacks)for(const s of t){const i=this.atoms.__unsafe__getWithoutCapture()[s];i&&this.onBeforeDelete(i.get(),r)===!1&&n.push(s)}let o;if(this.atoms.update(s=>{let i;for(const a of t)n.includes(a)||a in s&&(i||(i={...s}),o||(o={}),delete i[a],o[a]=s[a].get());return i??s}),!!o&&(this.updateHistory({added:{},updated:{},removed:o}),this.onAfterDelete&&this._runCallbacks)){let s;for(let i=0,a=t.length;i<a;i++)s=o[t[i]],s&&this.onAfterDelete(s,r)}})});m(this,"get",t=>{var n;return(n=this.atoms.get()[t])==null?void 0:n.get()});m(this,"unsafeGetWithoutCapture",t=>{var n;return(n=this.atoms.get()[t])==null?void 0:n.__unsafe__getWithoutCapture()});m(this,"serialize",(t="document")=>{const n={};for(const[r,o]of Jr(this.atoms.get())){const s=o.get();(t==="all"||this.scopedTypes[t].has(s.typeName))&&(n[r]=s)}return n});m(this,"allRecords",()=>at(this.atoms.get()).map(t=>t.get()));m(this,"clear",()=>{this.remove(Bw(this.atoms.get()))});m(this,"update",(t,n)=>{const r=this.atoms.get()[t];if(!r){console.error(`Record ${t} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])});m(this,"has",t=>!!this.atoms.get()[t]);m(this,"listen",(t,n)=>{this._flushHistory();const r={onHistory:t,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.listeners.add(r),this.historyReactor.scheduler.isActivelyListening||this.historyReactor.start(),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}});m(this,"isMergingRemoteChanges",!1);m(this,"mergeRemoteChanges",t=>{if(this.isMergingRemoteChanges)return t();try{this.isMergingRemoteChanges=!0,Tr(t)}finally{this.isMergingRemoteChanges=!1}});m(this,"createComputedCache",(t,n,r)=>{const o=new Vw;return{get:s=>{const i=this.atoms.get()[s];if(i)return o.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(t+":"+s,()=>n(a.get()))}).get()}}});m(this,"createSelectedComputedCache",(t,n,r)=>{const o=new Vw;return{get:s=>{const i=this.atoms.get()[s];if(!i)return;const a=G(t+":"+s+":selector",()=>n(i.get()));return o.get(i,()=>G(t+":"+s,()=>r(a.get()))).get()}}});m(this,"getRecordType",t=>{const n=this.schema.types[t.typeName];if(!n)throw new Error(`Record type ${t.typeName} not found`);return n});m(this,"_integrityChecker");m(this,"_isPossiblyCorrupted",!1);const{initialData:n,schema:r}=t;this.schema=r,this.props=t.props,n&&this.atoms.set(Rv(Jr(n).map(([o,s])=>[o,In("atom:"+o,this.schema.validateRecord(this,s,"initialize",null))]))),this.historyReactor=iD("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>UI(o)}),this.scopedTypes={document:new Set(at(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(at(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(at(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}_flushHistory(){if(this.historyAccumulator.hasChanges()){const t=this.historyAccumulator.flush();for(const{changes:n,source:r}of t){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(n,"document")),!s)continue;a({changes:s,source:r})}else if(l.scope==="session"){if(o??(o=this.filterChangesByScope(n,"session")),!o)continue;a({changes:o,source:r})}else{if(i??(i=this.filterChangesByScope(n,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:n,source:r})}}}filterChangesByScope(t,n){const r={added:Pg(t.added,(o,s)=>this.scopedTypes[n].has(s.typeName)),updated:Pg(t.updated,(o,s)=>this.scopedTypes[n].has(s[1].typeName)),removed:Pg(t.removed,(o,s)=>this.scopedTypes[n].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(t){this.historyAccumulator.add({changes:t,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,t)}validate(t){this.allRecords().forEach(n=>this.schema.validateRecord(this,n,t,null))}getSnapshot(t="document"){return{store:this.serialize(t),schema:this.schema.serialize()}}migrateSnapshot(t){const n=this.schema.migrateStoreSnapshot(t);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);return{store:n.value,schema:this.schema.serialize()}}loadSnapshot(t){const n=this.schema.migrateStoreSnapshot(t);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);Tr(()=>{this.clear(),this.put(Object.values(n.value)),this.ensureStoreIsUsable()})}extractingChanges(t){const n=[],r=this.historyAccumulator.intercepting(o=>n.push(o.changes));try{return Tr(t),df(n)}finally{r()}}applyDiff(t,n=!0){const r=this._runCallbacks;try{this._runCallbacks=n,Tr(()=>{const o=at(t.added).concat(at(t.updated).map(([i,a])=>a)),s=Bw(t.removed);o.length&&this.put(o),s.length&&this.remove(s)})}finally{this._runCallbacks=r}}ensureStoreIsUsable(){var t;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(t=this._integrityChecker)==null||t.call(this)}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}}function df(e){const t={added:{},removed:{},updated:{}};for(const n of e){for(const[r,o]of Jr(n.added))if(t.removed[r]){const s=t.removed[r];delete t.removed[r],s!==o&&(t.updated[r]=[s,o])}else t.added[r]=o;for(const[r,[o,s]]of Jr(n.updated)){if(t.added[r]){t.added[r]=s,delete t.updated[r],delete t.removed[r];continue}if(t.updated[r]){t.updated[r]=[t.updated[r][0],s],delete t.removed[r];continue}t.updated[r]=n.updated[r],delete t.removed[r]}for(const[r,o]of Jr(n.removed))t.added[r]?delete t.added[r]:t.updated[r]?(t.removed[r]=t.updated[r][0],delete t.updated[r]):t.removed[r]=o}return t}function KD(e){if(e.length===0)return[];const t=[];let n=[e[0]],r;for(let o=1,s=e.length;o<s;o++)r=e[o],n[0].source!==r.source&&(t.push(n),n=[]),n.push(r);return t.push(n),t.map(o=>({source:o[0].source,changes:df(o.map(s=>s.changes))}))}class VD{constructor(){m(this,"_history",[]);m(this,"_interceptors",new Set)}intercepting(t){return this._interceptors.add(t),()=>{this._interceptors.delete(t)}}add(t){this._history.push(t);for(const n of this._interceptors)n(t)}flush(){const t=KD(this._history);return this._history=[],t}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function WD(e){return typeof e=="object"&&e!==null&&"id"in e&&"typeName"in e}function Oe(e){const{currentVersion:t,firstVersion:n,migrators:r={},subTypeKey:o,subTypeMigrations:s}=e;if(typeof t=="number"&&typeof n=="number"){if(t===n)throw Error("Current version is equal to initial version.");if(t<n)throw Error("Current version is lower than initial version.")}return{firstVersion:n??0,currentVersion:t??0,migrators:r,subTypeKey:o,subTypeMigrations:s}}var ic=(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))(ic||{});function Zu({record:e,migrations:t,fromVersion:n,toVersion:r}){let o=n;if(!WD(e))throw new Error("[migrateRecord] object is not a record");const{typeName:s,id:i,...a}=e;let l=a;for(;o<r;){const c=o+1,u=t.migrators[c];if(!u)return{type:"error",reason:"target-version-too-new"};l=u.up(l),o=c}for(;o>r;){const c=o-1,u=t.migrators[o];if(!u)return{type:"error",reason:"target-version-too-old"};l=u.down(l),o=c}return{type:"success",value:{...l,id:i,typeName:s}}}function Bv({value:e,migrations:t,fromVersion:n,toVersion:r}){let o=n;for(;o<r;){const s=o+1,i=t.migrators[s];if(!i)return{type:"error",reason:"target-version-too-new"};e=i.up(e),o=s}for(;o>r;){const s=o-1,i=t.migrators[o];if(!i)return{type:"error",reason:"target-version-too-old"};e=i.down(e),o=s}return{type:"success",value:e}}class Uv{constructor(t,n){this.types=t,this.options=n}static create(t,n){return new Uv(t,n??{})}get currentStoreVersion(){var t;return((t=this.options.snapshotMigrations)==null?void 0:t.currentVersion)??0}validateRecord(t,n,r,o){try{const s=pr(this.types,n.typeName);if(!s)throw new Error(`Missing definition for record type ${n.typeName}`);return s.validate(n,o??void 0)}catch(s){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:t,record:n,phase:r,recordBefore:o,error:s});throw s}}migratePersistedRecord(t,n,r="up"){var d;const o=pr(this.types,t.typeName),s=n.recordVersions[t.typeName];if(!s||!o)return{type:"error",reason:ic.UnknownType};const i=o.migrations.currentVersion,a=s.version;if(i!==a){const p=Zu(r==="up"?{record:t,migrations:o.migrations,fromVersion:a,toVersion:i}:{record:t,migrations:o.migrations,fromVersion:i,toVersion:a});if(p.type==="error")return p;t=p.value}if(!o.migrations.subTypeKey)return{type:"success",value:t};const l=(d=o.migrations.subTypeMigrations)==null?void 0:d[t[o.migrations.subTypeKey]],c="subTypeVersions"in s?s.subTypeVersions[t[o.migrations.subTypeKey]]:void 0;if(l===void 0)return{type:"error",reason:ic.UnrecognizedSubtype};if(c===void 0)return{type:"error",reason:ic.IncompatibleSubtype};const u=Zu(r==="up"?{record:t,migrations:l,fromVersion:c,toVersion:l.currentVersion}:{record:t,migrations:l,fromVersion:l.currentVersion,toVersion:c});return u.type==="error"?u:{type:"success",value:u.value}}migrateStoreSnapshot(t){let{store:n}=t;const r=this.options.snapshotMigrations;if(!r)return{type:"success",value:n};const o=r.currentVersion,s=t.schema.storeVersion??0;if(o<s)return{type:"error",reason:ic.TargetVersionTooOld};if(o>s){const a=Bv({value:n,migrations:r,fromVersion:s,toVersion:o});if(a.type==="error")return a;n=a.value}const i=[];for(const a of at(n)){const l=this.migratePersistedRecord(a,t.schema);if(l.type==="error")return l;l.value&&l.value!==a&&i.push(l.value)}if(i.length){n={...n};for(const a of i)n[a.id]=a}return{type:"success",value:n}}createIntegrityChecker(t){var n,r;return((r=(n=this.options).createIntegrityChecker)==null?void 0:r.call(n,t))??void 0}serialize(){var t;return{schemaVersion:1,storeVersion:((t=this.options.snapshotMigrations)==null?void 0:t.currentVersion)??0,recordVersions:Object.fromEntries(at(this.types).map(n=>[n.typeName,n.migrations.subTypeKey&&n.migrations.subTypeMigrations?{version:n.migrations.currentVersion,subTypeKey:n.migrations.subTypeKey,subTypeVersions:n.migrations.subTypeMigrations?Object.fromEntries(Object.entries(n.migrations.subTypeMigrations).map(([r,o])=>[r,o.currentVersion])):void 0}:{version:n.migrations.currentVersion}]))}}serializeEarliestVersion(){var t;return{schemaVersion:1,storeVersion:((t=this.options.snapshotMigrations)==null?void 0:t.firstVersion)??0,recordVersions:Object.fromEntries(at(this.types).map(n=>[n.typeName,n.migrations.subTypeKey&&n.migrations.subTypeMigrations?{version:n.migrations.firstVersion,subTypeKey:n.migrations.subTypeKey,subTypeVersions:n.migrations.subTypeMigrations?Object.fromEntries(Object.entries(n.migrations.subTypeMigrations).map(([r,o])=>[r,o.firstVersion])):void 0}:{version:n.migrations.firstVersion}]))}}}const GD=(e,t)=>{if(e.schemaVersion>t.schemaVersion)return 1;if(e.schemaVersion<t.schemaVersion)return-1;if(e.storeVersion>t.storeVersion)return 1;if(e.storeVersion<t.storeVersion)return-1;for(const n of Object.keys(e.recordVersions)){const r=e.recordVersions[n],o=t.recordVersions[n];if(r.version>o.version)return 1;if(r.version<o.version)return-1;if("subTypeVersions"in r&&!("subTypeVersions"in o))return 1;if(!("subTypeVersions"in r)&&"subTypeVersions"in o)return-1;if(!(!("subTypeVersions"in r)||!("subTypeVersions"in o)))for(const s of Object.keys(r.subTypeVersions)){const i=r.subTypeVersions[s],a=o.subTypeVersions[s];if(i>a)return 1;if(i<a)return-1}}return 0};function YD(e){if(!e.length)return null;let t="";for(const n of e)typeof n=="number"?t+=`.${n}`:n.startsWith("(")?t.endsWith(")")?t=`${t.slice(0,-1)}, ${n.slice(1)}`:t+=n:t+=`.${n}`;return t=t.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),t.startsWith(".")?t.slice(1):t}class Ee extends Error{constructor(n,r=[]){const o=YD(r),s=n.split(`
38
- `).map((i,a)=>a===0?i:` ${i}`).join(`
39
- `);super(r?`At ${o}: ${s}`:s);m(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function $n(e,t){try{return t()}catch(n){throw n instanceof Ee?new Ee(n.rawMessage,[e,...n.path]):new Ee(n.toString(),[e])}}function As(e){if(e===null)return"null";if(Array.isArray(e))return"an array";const t=typeof e;switch(t){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${t}`;case"object":return`an ${t}`;case"undefined":return"undefined";default:Bs(t)}}class gn{constructor(t,n){this.validationFn=t,this.validateUsingKnownGoodVersionFn=n}validate(t){return this.validationFn(t)}validateUsingKnownGoodVersion(t,n){return Object.is(t,n)?t:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(t,n):this.validate(n)}isValid(t){try{return this.validate(t),!0}catch{return!1}}nullable(){return JD(this)}optional(){return WI(this)}refine(t){return new gn(n=>t(this.validate(n)),(n,r)=>{const o=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,o)?n:t(o)})}check(t,n){return typeof t=="string"?this.refine(r=>($n(`(check ${t})`,()=>n(r)),r)):this.refine(r=>(t(r),r))}}class XD extends gn{constructor(t){super(n=>{const r=Yw.validate(n);for(let o=0;o<r.length;o++)$n(o,()=>t.validate(r[o]));return r},(n,r)=>{if(!t.validateUsingKnownGoodVersion)return this.validate(r);const o=Yw.validate(r);let s=n.length!==o.length;for(let i=0;i<o.length;i++){const a=o[i];if(i>=n.length){s=!0,$n(i,()=>t.validate(a));continue}if(Object.is(n[i],a))continue;const l=$n(i,()=>t.validateUsingKnownGoodVersion(n[i],a));Object.is(l,n[i])||(s=!0)}return s?r:n}),this.itemValidator=t}nonEmpty(){return this.check(t=>{if(t.length===0)throw new Ee("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(t=>{if(t.length<=1)throw new Ee("Expected an array with length greater than 1")})}}class op extends gn{constructor(t,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Ee(`Expected object, got ${As(r)}`);for(const[o,s]of Object.entries(t))$n(o,()=>{s.validate(pr(r,o))});if(!n){for(const o of Object.keys(r))if(!Qr(t,o))throw new Ee("Unexpected property",[o])}return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ee(`Expected object, got ${As(o)}`);let s=!1;for(const[i,a]of Object.entries(t)){const l=pr(r,i),c=pr(o,i);if(Object.is(l,c))continue;const u=$n(i,()=>{const d=a;return d.validateUsingKnownGoodVersion?d.validateUsingKnownGoodVersion(l,c):d.validate(c)});Object.is(u,l)||(s=!0)}if(!n){for(const i of Object.keys(o))if(!Qr(t,i))throw new Ee("Unexpected property",[i])}for(const i of Object.keys(r))if(!Qr(o,i)){s=!0;break}return s?o:r}),this.config=t,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new op(this.config,!0)}extend(t){return new op({...this.config,...t})}}class Hv extends gn{constructor(t,n,r){super(o=>{this.expectObject(o);const{matchingSchema:s,variant:i}=this.getMatchingSchemaAndVariant(o);return s===void 0?this.unknownValueValidation(o,i):$n(`(${t} = ${i})`,()=>s.validate(o))},(o,s)=>{this.expectObject(s),this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(s);return i===void 0?this.unknownValueValidation(s,a):pr(o,t)!==pr(s,t)?$n(`(${t} = ${a})`,()=>i.validate(s)):$n(`(${t} = ${a})`,()=>i.validateUsingKnownGoodVersion?i.validateUsingKnownGoodVersion(o,s):i.validate(s))}),this.key=t,this.config=n,this.unknownValueValidation=r}expectObject(t){if(typeof t!="object"||t===null)throw new Ee(`Expected an object, got ${As(t)}`,[])}getMatchingSchemaAndVariant(t){const n=pr(t,this.key);if(typeof n!="string")throw new Ee(`Expected a string for key "${this.key}", got ${As(n)}`);return{matchingSchema:Qr(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(t){return new Hv(this.key,this.config,t)}}class qD extends gn{constructor(t,n){super(r=>{if(typeof r!="object"||r===null)throw new Ee(`Expected object, got ${As(r)}`);for(const[o,s]of Object.entries(r))$n(o,()=>{t.validate(o),n.validate(s)});return r},(r,o)=>{if(typeof o!="object"||o===null)throw new Ee(`Expected object, got ${As(o)}`);let s=!1;for(const[i,a]of Object.entries(o)){if(!Qr(r,i)){s=!0,$n(i,()=>{t.validate(i),n.validate(a)});continue}const l=pr(r,i),c=a;if(Object.is(l,c))continue;const u=$n(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(s=!0)}for(const i of Object.keys(r))if(!Qr(o,i)){s=!0;break}return s?o:r}),this.keyValidator=t,this.valueValidator=n}}function Kv(e){return new gn(t=>{if(typeof t!==e)throw new Ee(`Expected ${e}, got ${As(t)}`);return t})}const ZD=new gn(e=>e),me=Kv("string"),he=Kv("number").check(e=>{if(Number.isNaN(e))throw new Ee("Expected a number, got NaN");if(!Number.isFinite(e))throw new Ee(`Expected a finite number, got ${e}`)}),sp=he.check(e=>{if(e<0)throw new Ee(`Expected a positive number, got ${e}`)}),On=he.check(e=>{if(e<=0)throw new Ee(`Expected a non-zero positive number, got ${e}`)}),VI=he.check(e=>{if(!Number.isInteger(e))throw new Ee(`Expected an integer, got ${e}`)}),Qu=VI.check(e=>{if(e<0)throw new Ee(`Expected a positive integer, got ${e}`)}),QD=VI.check(e=>{if(e<=0)throw new Ee(`Expected a non-zero positive integer, got ${e}`)}),ve=Kv("boolean");function Dn(e){return new gn(t=>{if(t!==e)throw new Ee(`Expected ${e}, got ${JSON.stringify(t)}`);return e})}const Yw=new gn(e=>{if(!Array.isArray(e))throw new Ee(`Expected an array, got ${As(e)}`);return e});function Nt(e){return new XD(e)}function xe(e){return new op(e)}function My(e){return typeof e=="object"&&e!==null&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null||Object.getPrototypeOf(e)===FD)}function Ay(e){return e===null||typeof e=="number"||typeof e=="string"||typeof e=="boolean"?!0:Array.isArray(e)?e.every(Ay):My(e)?Object.values(e).every(Ay):!1}const hn=new gn(e=>{if(Ay(e))return e;throw new Ee(`Expected json serializable value, got ${typeof e}`)},(e,t)=>{if(Array.isArray(e)&&Array.isArray(t)){let n=e.length!==t.length;for(let r=0;r<t.length;r++){if(r>=e.length){n=!0,hn.validate(t[r]);continue}const o=e[r],s=t[r];if(Object.is(o,s))continue;const i=hn.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}return n?t:e}else if(My(e)&&My(t)){let n=!1;for(const r of Object.keys(t)){if(!Qr(e,r)){n=!0,hn.validate(t[r]);continue}const o=e[r],s=t[r];if(Object.is(o,s))continue;const i=hn.validateUsingKnownGoodVersion(o,s);Object.is(i,o)||(n=!0)}for(const r of Object.keys(e))if(!Qr(t,r)){n=!0;break}return n?t:e}else return hn.validate(t)});function jy(e,t){return new qD(e,t)}function Vv(e,t){return new Hv(e,t,(n,r)=>{throw new Ee(`Expected one of ${Object.keys(t).map(o=>JSON.stringify(o)).join(" or ")}, got ${JSON.stringify(r)}`,[e])})}function Xo(e,t){return new gn(n=>$n(e,()=>t.validate(n)),(n,r)=>$n(e,()=>t.validateUsingKnownGoodVersion?t.validateUsingKnownGoodVersion(n,r):t.validate(r)))}function hf(e){return new gn(t=>{if(!e.has(t)){const n=Array.from(e,r=>JSON.stringify(r)).join(" or ");throw new Ee(`Expected ${n}, got ${t}`)}return t})}function WI(e){return new gn(t=>{if(t!==void 0)return e.validate(t)},(t,n)=>{if(!(t===void 0&&n===void 0)&&n!==void 0)return e.validateUsingKnownGoodVersion&&t!==void 0?e.validateUsingKnownGoodVersion(t,n):e.validate(n)})}function JD(e){return new gn(t=>t===null?null:e.validate(t),(t,n)=>n===null?null:e.validateUsingKnownGoodVersion&&t!==null?e.validateUsingKnownGoodVersion(t,n):e.validate(n))}function GI(...e){return hf(new Set(e))}function YI(e){try{return new URL(e)}catch{if(e.startsWith("/")||e.startsWith("./"))try{return new URL(e,"http://example.com")}catch{throw new Ee(`Expected a valid url, got ${JSON.stringify(e)}`)}throw new Ee(`Expected a valid url, got ${JSON.stringify(e)}`)}}const eR=new Set(["http:","https:","mailto:"]),Qn=me.check(e=>{if(e==="")return;const t=YI(e);if(!eR.has(t.protocol.toLowerCase()))throw new Ee(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),tR=new Set(["http:","https:","data:"]),dl=me.check(e=>{if(e==="")return;const t=YI(e);if(!tR.has(t.protocol.toLowerCase()))throw new Ee(`Expected a valid url, got ${JSON.stringify(e)} (invalid protocol)`)}),Wv=me.refine(e=>{try{return kD(e),e}catch{throw new Ee(`Expected an index key, got ${JSON.stringify(e)}`)}});function fr(e){return me.refine(t=>{if(!t.startsWith(`${e}:`))throw new Error(`${e} ID must start with "${e}:"`);return t})}const pf=fr("asset");function Gv(e,t){return xe({id:pf,typeName:Dn("asset"),type:Dn(e),props:t,meta:hn})}const nR=Xo("camera",xe({typeName:Dn("camera"),id:fr("camera"),x:he,y:he,z:he,meta:hn})),Xw={AddMeta:1},rR=Oe({currentVersion:Xw.AddMeta,migrators:{[Xw.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})}}}),qt=Yo("camera",{validator:nR,migrations:rR,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),jc=xe({x:he,y:he,z:he.optional()}),gc=xe({x:he,y:he,w:he,h:he}),oR=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"]),XI=hf(oR),sR=xe({type:XI,rotation:he}),qI=he.check(e=>{if(e<0||e>1)throw new Ee("Opacity must be between 0 and 1")}),iR=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),aR=hf(iR),lR=new Set(["starting","paused","active","stopping"]),ZI=xe({id:me,points:Nt(jc),size:sp,color:aR,opacity:he,state:hf(lR),delay:he,shrink:he,taper:ve}),Oc=fr("page"),cR=Xo("page",xe({typeName:Dn("page"),id:Oc,name:me,index:Wv,meta:hn})),qw={AddMeta:1},uR=Oe({currentVersion:qw.AddMeta,migrators:{[qw.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})}}}),Lo=Yo("page",{validator:cR,migrations:uR,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function xn(e){return Lo.isId(e)}fr("instance");function dR(e){const t={};for(const[r,o]of e)t[r]=WI(o);const n=Xo("instance",xe({typeName:Dn("instance"),id:fr("instance"),currentPageId:Oc,followingUserId:me.nullable(),brush:gc.nullable(),opacityForNextShape:qI,stylesForNextShape:xe(t),cursor:sR,scribbles:Nt(ZI),isFocusMode:ve,isDebugMode:ve,isToolLocked:ve,exportBackground:ve,screenBounds:gc,insets:Nt(ve),zoomBrush:gc.nullable(),isPenMode:ve,isGridMode:ve,chatMessage:me,isChatting:ve,highlightedUserIds:Nt(me),canMoveCamera:ve,isFocused:ve,devicePixelRatio:he,isCoarsePointer:ve,isHoveringCanvas:ve.nullable(),openMenus:Nt(me),isChangingStyle:ve,isReadonly:ve,meta:hn,duplicateProps:xe({shapeIds:Nt(fr("shape")),offset:xe({x:he,y:he})}).nullable()}));return Yo("instance",{migrations:hR,validator:n,scope:"session"}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],canMoveCamera:!0,isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const Qe={AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24},hR=Oe({currentVersion:Qe.AddDuplicateProps,migrators:{[Qe.AddTransparentExportBgs]:{up:e=>({...e,exportBackground:!0}),down:({exportBackground:e,...t})=>t},[Qe.RemoveDialog]:{up:({dialog:e,...t})=>t,down:e=>({...e,dialog:null})},[Qe.AddToolLockMode]:{up:e=>({...e,isToolLocked:!1}),down:({isToolLocked:e,...t})=>t},[Qe.RemoveExtraPropsForNextShape]:{up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:Object.fromEntries(Object.entries(e).filter(([n])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(n)))}),down:e=>e},[Qe.AddLabelColor]:{up:({propsForNextShape:e,...t})=>({...t,propsForNextShape:{...e,labelColor:"black"}}),down:e=>{const{labelColor:t,...n}=e.propsForNextShape;return{...e,propsForNextShape:{...n}}}},[Qe.AddFollowingUserId]:{up:e=>({...e,followingUserId:null}),down:({followingUserId:e,...t})=>t},[Qe.RemoveAlignJustify]:{up:e=>{let t=e.propsForNextShape.align;return t==="justify"&&(t="start"),{...e,propsForNextShape:{...e.propsForNextShape,align:t}}},down:e=>({...e})},[Qe.AddZoom]:{up:e=>({...e,zoomBrush:null}),down:({zoomBrush:e,...t})=>t},[Qe.AddVerticalAlign]:{up:e=>({...e,propsForNextShape:{...e.propsForNextShape,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:t,...n}=e.propsForNextShape;return{...e,propsForNextShape:n}}},[Qe.AddScribbleDelay]:{up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e},down:e=>{if(e.scribble!==null){const{delay:t,...n}=e.scribble;return{...e,scribble:n}}return{...e}}},[Qe.RemoveUserId]:{up:({userId:e,...t})=>t,down:e=>({...e,userId:"user:none"})},[Qe.AddIsPenModeAndIsGridMode]:{up:e=>({...e,isPenMode:!1,isGridMode:!1}),down:({isPenMode:e,isGridMode:t,...n})=>n},[Qe.HoistOpacity]:{up:({propsForNextShape:{opacity:e,...t},...n})=>({...n,opacityForNextShape:Number(e??"1"),propsForNextShape:t}),down:({opacityForNextShape:e,...t})=>({...t,propsForNextShape:{...t.propsForNextShape,opacity:e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}})},[Qe.AddChat]:{up:e=>({...e,chatMessage:"",isChatting:!1}),down:({chatMessage:e,isChatting:t,...n})=>n},[Qe.AddHighlightedUserIds]:{up:e=>({...e,highlightedUserIds:[]}),down:({highlightedUserIds:e,...t})=>t},[Qe.ReplacePropsForNextShapeWithStylesForNextShape]:{up:({propsForNextShape:e,...t})=>({...t,stylesForNextShape:{}}),down:({stylesForNextShape:e,...t})=>({...t,propsForNextShape:{color:"black",labelColor:"black",dash:"draw",fill:"none",size:"m",icon:"file",font:"draw",align:"middle",verticalAlign:"middle",geo:"rectangle",arrowheadStart:"none",arrowheadEnd:"arrow",spline:"line"}})},[Qe.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})},[Qe.RemoveCursorColor]:{up:e=>{const{color:t,...n}=e.cursor;return{...e,cursor:n}},down:e=>({...e,cursor:{...e.cursor,color:"black"}})},[Qe.AddLonelyProperties]:{up:e=>({...e,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1}),down:({canMoveCamera:e,isFocused:t,devicePixelRatio:n,isCoarsePointer:r,openMenus:o,isChangingStyle:s,isReadOnly:i,...a})=>({...a})},[Qe.ReadOnlyReadonly]:{up:({isReadOnly:e,...t})=>({...t,isReadonly:e}),down:({isReadonly:e,...t})=>({...t,isReadOnly:e})},[Qe.AddHoveringCanvas]:{up:e=>({...e,isHoveringCanvas:null}),down:({isHoveringCanvas:e,...t})=>({...t})},[Qe.AddScribbles]:{up:({scribble:e,...t})=>({...t,scribbles:[]}),down:({scribbles:e,...t})=>({...t,scribble:null})},[Qe.AddInset]:{up:e=>({...e,insets:[!1,!1,!1,!1]}),down:({insets:e,...t})=>({...t})},[Qe.AddDuplicateProps]:{up:e=>({...e,duplicateProps:null}),down:({duplicateProps:e,...t})=>({...t})}}}),en="instance:instance",pR=me.refine(e=>{if(!e.startsWith("page:")&&!e.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return e}),Ir=fr("shape");function fR(e,t,n){return xe({id:Ir,typeName:Dn("shape"),x:he,y:he,rotation:he,index:Wv,parentId:pR,type:Dn(e),isLocked:ve,opacity:qI,props:t?xe(t):hn,meta:n?xe(n):hn})}const gR=Xo("instance_page_state",xe({typeName:Dn("instance_page_state"),id:fr("instance_page_state"),pageId:Oc,selectedShapeIds:Nt(Ir),hintingShapeIds:Nt(Ir),erasingShapeIds:Nt(Ir),hoveredShapeId:Ir.nullable(),editingShapeId:Ir.nullable(),croppingShapeId:Ir.nullable(),focusedGroupId:Ir.nullable(),meta:hn})),qi={AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5},mR=Oe({currentVersion:qi.RenamePropertiesAgain,migrators:{[qi.AddCroppingId]:{up(e){return{...e,croppingShapeId:null}},down({croppingShapeId:e,...t}){return t}},[qi.RemoveInstanceIdAndCameraId]:{up({instanceId:e,cameraId:t,...n}){return n},down(e){return{...e,instanceId:en,cameraId:qt.createId("void")}}},[qi.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})},[qi.RenameProperties]:{up:e=>{const{selectedShapeIds:t,hintingShapeIds:n,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}=e;return{selectedShapeIds:t,hintingShapeIds:n,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}},down:e=>{const{selectedShapeIds:t,hintingShapeIds:n,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}=e;return{selectedShapeIds:t,hintingShapeIds:n,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}}},[qi.RenamePropertiesAgain]:{up:e=>{const{selectedIds:t,hintingIds:n,erasingIds:r,hoveredId:o,editingId:s,croppingShapeId:i,croppingId:a,focusLayerId:l,...c}=e;return{...c,selectedShapeIds:t,hintingShapeIds:n,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i??a??null,focusedGroupId:l}},down:e=>{const{selectedShapeIds:t,hintingShapeIds:n,erasingShapeIds:r,hoveredShapeId:o,editingShapeId:s,croppingShapeId:i,focusedGroupId:a,...l}=e;return{...l,selectedIds:t,hintingIds:n,erasingIds:r,hoveredId:o,editingId:s,croppingId:i,focusLayerId:a}}}}}),Zt=Yo("instance_page_state",{migrations:mR,validator:gR,scope:"session"}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),yR=Xo("pointer",xe({typeName:Dn("pointer"),id:fr("pointer"),x:he,y:he,lastActivityTimestamp:he,meta:hn})),Zw={AddMeta:1},SR=Oe({currentVersion:Zw.AddMeta,migrators:{[Zw.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})}}}),Yv=Yo("pointer",{validator:yR,migrations:SR,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),ip=Yv.createId("pointer"),vR=Xo("instance_presence",xe({typeName:Dn("instance_presence"),id:fr("instance_presence"),userId:me,userName:me,lastActivityTimestamp:he,followingUserId:me.nullable(),cursor:xe({x:he,y:he,type:XI,rotation:he}),color:me,camera:xe({x:he,y:he,z:he}),screenBounds:gc,selectedShapeIds:Nt(fr("shape")),currentPageId:fr("page"),brush:gc.nullable(),scribbles:Nt(ZI),chatMessage:me,meta:hn})),Zi={AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5},xR=Oe({currentVersion:Zi.RenameSelectedShapeIds,migrators:{[Zi.AddScribbleDelay]:{up:e=>e.scribble!==null?{...e,scribble:{...e.scribble,delay:0}}:{...e},down:e=>{if(e.scribble!==null){const{delay:t,...n}=e.scribble;return{...e,scribble:n}}return{...e}}},[Zi.RemoveInstanceId]:{up:({instanceId:e,...t})=>t,down:e=>({...e,instanceId:en})},[Zi.AddChatMessage]:{up:e=>({...e,chatMessage:""}),down:({chatMessage:e,...t})=>t},[Zi.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})},[Zi.RenameSelectedShapeIds]:{up:e=>{const{selectedShapeIds:t,...n}=e;return{selectedShapeIds:t,...n}},down:e=>{const{selectedShapeIds:t,...n}=e;return{selectedShapeIds:t,...n}}}}}),wR=Yo("instance_presence",{migrations:xR,validator:vR,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:{}})),bR=Xo("document",xe({typeName:Dn("document"),id:Dn("document:document"),gridSize:he,name:me,meta:hn})),Eg={AddName:1,AddMeta:2},PR=Oe({currentVersion:Eg.AddMeta,migrators:{[Eg.AddName]:{up:e=>({...e,name:""}),down:({name:e,...t})=>t},[Eg.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})}}}),Xv=Yo("document",{migrations:PR,validator:bR,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),Oy=Xv.createId("document");function CR(e,t){return e.index<t.index?-1:e.index>t.index?1:0}function Qw(e){e.typeName==="asset"&&("src"in e&&(e.src="<redacted>"),"src"in e.props&&(e.props.src="<redacted>"))}const IR=({error:e,phase:t,record:n,recordBefore:r})=>{throw Dv(e,{tags:{origin:"store.validateRecord",storePhase:t,isExistingValidationIssue:t==="initialize"},extras:{recordBefore:r?Qw(vt(r)):void 0,recordAfter:Qw(vt(n))}}),e};function ER(){return[Lo.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function _R(e){const t=e.query.ids("page"),n=()=>{if(!e.has(Oy))return e.put([Xv.create({id:Oy,name:e.props.defaultName})]),n();if(!e.has(ip))return e.put([Yv.create({id:ip})]),n();const r=t.get();if(r.size===0)return e.put(ER()),n();const o=()=>[...r].map(l=>e.get(l)).sort(CR)[0].id,s=e.get(en);if(s){if(!r.has(s.currentPageId))return e.put([{...s,currentPageId:o()}]),n()}else return e.put([e.schema.types.instance.create({id:en,currentPageId:o(),exportBackground:!0})]),n();const i=new Set,a=new Set;for(const l of r){const c=Zt.createId(l);e.has(c)||i.add(c);const u=qt.createId(l);e.has(u)||a.add(u)}i.size>0&&e.put([...i].map(l=>Zt.create({id:l,pageId:Zt.parseId(l)}))),a.size>0&&e.put([...a].map(l=>qt.create({id:l})))};return n}const kR=Gv("bookmark",xe({title:me,description:me,image:me,src:dl.nullable()})),Jw={MakeUrlsValid:1},TR=Oe({currentVersion:Jw.MakeUrlsValid,migrators:{[Jw.MakeUrlsValid]:{up:e=>{const t=e.props.src;return t&&!dl.isValid(t)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),$R=Gv("image",xe({w:he,h:he,name:me,isAnimated:ve,mimeType:me.nullable(),src:dl.nullable()})),Ju={AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3},MR=Oe({currentVersion:Ju.MakeUrlsValid,migrators:{[Ju.AddIsAnimated]:{up:e=>({...e,props:{...e.props,isAnimated:!1}}),down:e=>{const{isAnimated:t,...n}=e.props;return{...e,props:n}}},[Ju.RenameWidthHeight]:{up:e=>{const{width:t,height:n,...r}=e.props;return{...e,props:{w:t,h:n,...r}}},down:e=>{const{w:t,h:n,...r}=e.props;return{...e,props:{width:t,height:n,...r}}}},[Ju.MakeUrlsValid]:{up:e=>{const t=e.props.src;return t&&!dl.isValid(t)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),AR=Gv("video",xe({w:he,h:he,name:me,isAnimated:ve,mimeType:me.nullable(),src:dl.nullable()})),ed={AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3},jR=Oe({currentVersion:ed.MakeUrlsValid,migrators:{[ed.AddIsAnimated]:{up:e=>({...e,props:{...e.props,isAnimated:!1}}),down:e=>{const{isAnimated:t,...n}=e.props;return{...e,props:n}}},[ed.RenameWidthHeight]:{up:e=>{const{width:t,height:n,...r}=e.props;return{...e,props:{w:t,h:n,...r}}},down:e=>{const{w:t,h:n,...r}=e.props;return{...e,props:{width:t,height:n,...r}}}},[ed.MakeUrlsValid]:{up:e=>{const t=e.props.src;return t&&!dl.isValid(t)?{...e,props:{...e.props,src:""}}:e},down:e=>e}}}),OR=Xo("asset",Vv("type",{image:$R,video:AR,bookmark:kR})),eb={AddMeta:1},DR=Oe({subTypeKey:"type",subTypeMigrations:{image:MR,video:jR,bookmark:TR},currentVersion:eb.AddMeta,migrators:{[eb.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})}}}),hi=Yo("asset",{migrations:DR,validator:OR,scope:"document"}).withDefaultProperties(()=>({meta:{}}));class an{constructor(t,n,r){this.id=t,this.defaultValue=n,this.type=r}static define(t,n){const{defaultValue:r,type:o=ZD}=n;return new an(t,r,o)}static defineEnum(t,n){const{defaultValue:r,values:o}=n;return new RR(t,r,o)}validate(t){return this.type.validate(t)}validateUsingKnownGoodVersion(t,n){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(t,n):this.validate(n)}}class RR extends an{constructor(t,n,r){super(t,n,GI(...r)),this.values=r}}const jl={AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4},_g=Oe({currentVersion:jl.AddWhite,migrators:{[jl.AddIsLocked]:{up:e=>({...e,isLocked:!1}),down:e=>{const{isLocked:t,...n}=e;return{...n}}},[jl.HoistOpacity]:{up:({props:{opacity:e,...t},...n})=>({...n,opacity:Number(e??"1"),props:t}),down:({opacity:e,...t})=>({...t,props:{...t.props,opacity:e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}})},[jl.AddMeta]:{up:e=>({...e,meta:{}}),down:({meta:e,...t})=>({...t})},[jl.AddWhite]:{up:e=>({...e}),down:e=>({...e,props:{...e.props,color:e.props.color==="white"?"black":e.props.color}})}}});function ms(e){return e?e.typeName==="shape":!1}function wn(e){return e?e.startsWith("shape:"):!1}function Be(e){return`shape:${e??uf()}`}function QI(e){const t=new Map;for(const[n,r]of Object.entries(e))if(r instanceof an){if(t.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);t.set(r,n)}return t}function LR(e){return Yo("shape",{migrations:Oe({currentVersion:_g.currentVersion,firstVersion:_g.firstVersion,migrators:_g.migrators,subTypeKey:"type",subTypeMigrations:np(e,(t,n)=>n.migrations??Oe({}))}),scope:"document",validator:Xo("shape",Vv("type",np(e,(t,{props:n,meta:r})=>fR(t,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}const JI=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],ap={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4263eb",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#adb5bd",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:"#4dabf7",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:"#40c057",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:"#ff8787",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:"#e599f7",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#f76707",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#ffc078",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 8%)",solid:"#010403",black:{solid:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4263eb",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function qo(e){return e.isDarkMode?ap.darkMode:ap.lightMode}const Jn=an.defineEnum("tldraw:color",{defaultValue:"black",values:JI}),eE=an.defineEnum("tldraw:labelColor",{defaultValue:"black",values:JI}),wi=an.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),Ga=an.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern"]}),so=an.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),tE={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},io=an.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),nE=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],lp=an.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:nE}),cp=an.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:nE}),tb=Vv("type",{binding:xe({type:Dn("binding"),boundShapeId:Ir,normalizedAnchor:jc,isExact:ve,isPrecise:ve}),point:xe({type:Dn("point"),x:he,y:he})}),rE={labelColor:eE,color:Jn,fill:Ga,dash:wi,size:io,arrowheadStart:lp,arrowheadEnd:cp,font:so,start:tb,end:tb,bend:he,text:me,labelPosition:he},td={AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3},oE=Oe({currentVersion:td.AddLabelPosition,migrators:{[td.AddLabelColor]:{up:e=>({...e,props:{...e.props,labelColor:"black"}}),down:e=>{const{labelColor:t,...n}=e.props;return{...e,props:n}}},[td.AddIsPrecise]:{up:e=>{const{start:t,end:n}=e.props;return{...e,props:{...e.props,start:t.type==="binding"?{...t,isPrecise:!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5)}:t,end:n.type==="binding"?{...n,isPrecise:!(n.normalizedAnchor.x===.5&&n.normalizedAnchor.y===.5)}:n}}},down:e=>{const{start:t,end:n}=e.props,r={...t},o={...n};return r.type==="binding"&&(r.isPrecise||(r.normalizedAnchor={x:.5,y:.5}),delete r.isPrecise),o.type==="binding"&&(o.isPrecise||(o.normalizedAnchor={x:.5,y:.5}),delete o.isPrecise),{...e,props:{...e.props,start:r,end:o}}}},[td.AddLabelPosition]:{up:e=>({...e,props:{...e.props,labelPosition:.5}}),down:e=>{const{labelPosition:t,...n}=e.props;return{...e,props:n}}}}}),sE={w:On,h:On,assetId:pf.nullable(),url:Qn},kg={NullAssetId:1,MakeUrlsValid:2},iE=Oe({currentVersion:kg.MakeUrlsValid,migrators:{[kg.NullAssetId]:{up:e=>e.props.assetId===void 0?{...e,props:{...e.props,assetId:null}}:e,down:e=>{if(e.props.assetId===null){const{assetId:t,...n}=e.props;return{...e,props:n}}return e}},[kg.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Qn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),aE=xe({type:GI("free","straight"),points:Nt(jc)}),lE={color:Jn,fill:Ga,dash:wi,size:io,segments:Nt(aE),isComplete:ve,isClosed:ve,isPen:ve},nb={AddInPen:1},cE=Oe({currentVersion:nb.AddInPen,migrators:{[nb.AddInPen]:{up:e=>{const{points:t}=e.props.segments[0];if(t.length===0)return{...e,props:{...e.props,isPen:!1}};let n=!(t[0].z===0||t[0].z===.5);return t[1]&&(n=n&&!(t[1].z===0||t[1].z===.5)),{...e,props:{...e.props,isPen:n}}},down:e=>{const{isPen:t,...n}=e.props;return{...e,props:{...n}}}}}});var FR={};const rb=/(^\/r\/[^/]+\/?$)/,ze=e=>{try{return new URL(e)}catch{return}},Ya=[{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 t=ze(e);if(t&&t.pathname.match(rb))return e},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(rb))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 t=ze(e);if(t&&t.pathname.match(/^\/embed\/?$/)){const n=t.searchParams.get("url");if(n)return n}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{if(e.includes("/maps/")){const t=e.match(/@(.*),(.*),(.*)z/);let n;if(t){const[,r,o,s]=t;n=`https://${new URL(e).host.replace("www.","")}/maps/embed/v1/view?key=${FR.NEXT_PUBLIC_GC_API_KEY}&center=${r},${o}&zoom=${s}`}else n="";return n}},fromEmbedUrl:e=>{const t=ze(e);if(!t)return;if(t.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&t.searchParams.has("center")&&t.searchParams.get("zoom")){const r=t.searchParams.get("zoom"),[o,s]=t.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 t=ze(e),n=t&&t.pathname.match(/\/v\/([^/]+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:e=>{const t=ze(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{type:"codesandbox",title:"CodeSandbox",hostnames:["codesandbox.io"],minWidth:300,minHeight:300,width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=ze(e),n=t&&t.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:e=>{const t=ze(e),n=t&&t.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{type:"codepen",title:"Codepen",hostnames:["codepen.io"],minWidth:300,minHeight:300,width:520,height:400,doesResize:!0,toEmbedUrl:e=>{const t=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,n=e.match(t);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/embed/${s}`}},fromEmbedUrl:e=>{const t=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=e.match(t);if(n){const[r,o,s]=n;return`https://codepen.io/${o}/pen/${s}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:e=>{const t=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,n=e.match(t);if(n){const[r,o]=n;return`https://scratch.mit.edu/projects/embed/${o}`}},fromEmbedUrl:e=>{const t=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=e.match(t);if(n){const[r,o]=n;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},isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=ze(e);if(!t)return;const n=t.hostname.replace(/^www./,"");if(n==="youtu.be")return`https://www.youtube.com/embed/${t.pathname.split("/").filter(Boolean)[0]}`;if((n==="youtube.com"||n==="m.youtube.com")&&t.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${t.searchParams.get("v")}`},fromEmbedUrl:e=>{const t=ze(e);if(!t)return;if(t.hostname.replace(/^www./,"")==="youtube.com"){const r=t.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",toEmbedUrl:e=>{const t=ze(e),n=t==null?void 0:t.searchParams.get("cid");if(t!=null&&t.pathname.match(/\/calendar\/u\/0/)&&n){t.pathname="/calendar/embed";const r=Array.from(t.searchParams.keys());for(const o of r)t.searchParams.delete(o);return t.searchParams.set("src",n),t.href}},fromEmbedUrl:e=>{const t=ze(e),n=t==null?void 0:t.searchParams.get("src");if(t!=null&&t.pathname.match(/\/calendar\/embed/)&&n){t.pathname="/calendar/u/0";const r=Array.from(t.searchParams.keys());for(const o of r)t.searchParams.delete(o);return t.searchParams.set("cid",n),t.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,toEmbedUrl:e=>{const t=ze(e);if(t!=null&&t.pathname.match(/^\/presentation/)&&(t!=null&&t.pathname.match(/\/pub\/?$/))){t.pathname=t.pathname.replace(/\/pub$/,"/embed");const n=Array.from(t.searchParams.keys());for(const r of n)t.searchParams.delete(r);return t.href}},fromEmbedUrl:e=>{const t=ze(e);if(t!=null&&t.pathname.match(/^\/presentation/)&&(t!=null&&t.pathname.match(/\/embed\/?$/))){t.pathname=t.pathname.replace(/\/embed$/,"/pub");const n=Array.from(t.searchParams.keys());for(const r of n)t.searchParams.delete(r);return t.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/\/([^/]+)\/([^/]+)/))return e.split("/").pop()?e:void 0},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.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 t=ze(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${e}?embed=true`},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/\/@([^/]+)\/([^/]+)/)&&t.searchParams.has("embed"))return t.searchParams.delete("embed"),t.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/^\/map\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/^\/embed\/map\//))return t.pathname=t.pathname.replace(/^\/embed/,""),t.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/^\/(artist|album)\//))return t.origin+"/embed"+t.pathname},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/^\/embed\/(artist|album)\//))return t.origin+t.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=ze(e);if(t&&t.hostname==="vimeo.com"&&t.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+t.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.hostname==="player.vimeo.com"){const n=t.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{type:"excalidraw",title:"Excalidraw",hostnames:["excalidraw.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:e=>{const t=ze(e);if(t&&t.hash.match(/#room=/))return e},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.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 t=ze(e);if(t&&t.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}/embed${t.pathname}?cell=*`;if(t&&t.pathname.match(/^\/d\/([^/]+)\/?$/)){const n=t.pathname.replace(/^\/d/,"");return`${t.origin}/embed${n}?cell=*`}},fromEmbedUrl:e=>{const t=ze(e);if(t&&t.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${t.origin}${t.pathname.replace("/embed","")}#cell-*`;if(t&&t.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${t.origin}${t.pathname.replace("/embed","/d")}#cell-*`}}],NR={"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},uE={w:On,h:On,url:me},Ol={GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4},dE=Oe({currentVersion:Ol.RemovePermissionOverrides,migrators:{[Ol.GenOriginalUrlInEmbed]:{up:e=>{const t=e.props.url,n=new URL(t).host.replace("www.","");let r;for(const o of Ya)if(o.hostnames.includes(n))try{r=o.fromEmbedUrl(t)}catch(s){console.warn(s)}return{...e,props:{...e.props,tmpOldUrl:e.props.url,url:r??""}}},down:e=>{let t=e.props.tmpOldUrl;if(!t||t===""){const o=e.props.url,s=new URL(o).host.replace("www.","");for(const i of Ya)if(i.hostnames.includes(s))try{t=i.toEmbedUrl(o)}catch(a){console.warn(a)}}const{tmpOldUrl:n,...r}=e.props;return{...e,props:{...r,url:t??""}}}},[Ol.RemoveDoesResize]:{up:e=>{const{doesResize:t,...n}=e.props;return{...e,props:{...n}}},down:e=>({...e,props:{...e.props,doesResize:!0}})},[Ol.RemoveTmpOldUrl]:{up:e=>{const{tmpOldUrl:t,...n}=e.props;return{...e,props:{...n}}},down:e=>({...e,props:{...e.props}})},[Ol.RemovePermissionOverrides]:{up:e=>{const{overridePermissions:t,...n}=e.props;return{...e,props:{...n}}},down:e=>({...e,props:{...e.props}})}}}),hE={w:On,h:On,name:me},pE=Oe({}),Dc=an.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),up=an.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),eo=an.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"]}),fE={geo:eo,labelColor:eE,color:Jn,fill:Ga,dash:wi,size:io,font:so,align:Dc,verticalAlign:up,url:Qn,w:On,h:On,growY:sp,text:me},xo={AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8},gE=Oe({currentVersion:xo.MakeUrlsValid,migrators:{[xo.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:t,...n}=e.props;return{...e,props:n}}},[xo.AddLabelColor]:{up:e=>({...e,props:{...e.props,labelColor:"black"}}),down:e=>{const{labelColor:t,...n}=e.props;return{...e,props:n}}},[xo.RemoveJustify]:{up:e=>{let t=e.props.align;return t==="justify"&&(t="start"),{...e,props:{...e.props,align:t}}},down:e=>({...e})},[xo.AddCheckBox]:{up:e=>({...e}),down:e=>({...e,props:{...e.props,geo:e.props.geo==="check-box"?"rectangle":e.props.geo}})},[xo.AddVerticalAlign]:{up:e=>({...e,props:{...e.props,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:t,...n}=e.props;return{...e,props:n}}},[xo.MigrateLegacyAlign]:{up:e=>{let t;switch(e.props.align){case"start":t="start-legacy";break;case"end":t="end-legacy";break;default:t="middle-legacy";break}return{...e,props:{...e.props,align:t}}},down:e=>{let t;switch(e.props.align){case"start-legacy":t="start";break;case"end-legacy":t="end";break;case"middle-legacy":t="middle";break;default:t=e.props.align}return{...e,props:{...e.props,align:t}}}},[xo.AddCloud]:{up:e=>e,down:e=>{if(e.props.geo==="cloud")return{...e,props:{...e.props,geo:"rectangle"}}}},[xo.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Qn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),mE={},yE=Oe({}),SE={color:Jn,size:io,segments:Nt(aE),isComplete:ve,isPen:ve},vE=Oe({}),zR=xe({topLeft:jc,bottomRight:jc}),xE={w:On,h:On,playing:ve,url:Qn,assetId:pf.nullable(),crop:zR.nullable()},nd={AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3},wE=Oe({currentVersion:nd.MakeUrlsValid,migrators:{[nd.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:t,...n}=e.props;return{...e,props:n}}},[nd.AddCropProp]:{up:e=>({...e,props:{...e.props,crop:null}}),down:e=>{const{crop:t,...n}=e.props;return{...e,props:n}}},[nd.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Qn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),dp=an.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),BR=xe({id:me,index:Wv,x:he,y:he}),bE={color:Jn,dash:wi,size:io,spline:dp,points:jy(me,BR)},Dl={AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4},PE=Oe({currentVersion:Dl.PointIndexIds,migrators:{[Dl.AddSnapHandles]:{up:e=>{const t=vt(e.props.handles);for(const n in t)t[n].canSnap=!0;return{...e,props:{...e.props,handles:t}}},down:e=>{const t=vt(e.props.handles);for(const n in t)delete t[n].canSnap;return{...e,props:{...e.props,handles:t}}}},[Dl.RemoveExtraHandleProps]:{up:e=>({...e,props:{...e.props,handles:Rv(Object.values(e.props.handles).map(t=>[t.index,{x:t.x,y:t.y}]))}}),down:e=>{const t=Object.entries(e.props.handles).map(([n,r])=>({index:n,...r})).sort(Lt);return{...e,props:{...e.props,handles:Object.fromEntries(t.map((n,r)=>{const o=r===0?"start":r===t.length-1?"end":`handle:${n.index}`;return[o,{id:o,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}}}},[Dl.HandlesToPoints]:{up:e=>{const{handles:t,...n}=e.props,r=Object.entries(t).map(([o,{x:s,y:i}])=>({x:s,y:i,index:o})).sort(Lt);return{...e,props:{...n,points:r.map(({x:o,y:s})=>({x:o,y:s}))}}},down:e=>{const{points:t,...n}=e.props,r=Ac(t.length);return{...e,props:{...n,handles:Object.fromEntries(t.map((o,s)=>[r[s],{x:o.x,y:o.y}]))}}}},[Dl.PointIndexIds]:{up:e=>{const{points:t,...n}=e.props,r=Ac(t.length);return{...e,props:{...n,points:Object.fromEntries(t.map((o,s)=>{const i=r[s];return[i,{id:i,index:i,x:o.x,y:o.y}]}))}}},down:e=>{const t=Object.values(e.props.points).sort(Lt);return{...e,props:{...e.props,points:t.map(({x:n,y:r})=>({x:n,y:r}))}}}}}}),CE={color:Jn,size:io,fontSizeAdjustment:sp,font:so,align:Dc,verticalAlign:up,growY:sp,url:Qn,text:me},oi={AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6},IE=Oe({currentVersion:oi.AddFontSizeAdjustment,migrators:{[oi.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:t,...n}=e.props;return{...e,props:n}}},[oi.RemoveJustify]:{up:e=>{let t=e.props.align;return t==="justify"&&(t="start"),{...e,props:{...e.props,align:t}}},down:e=>({...e})},[oi.MigrateLegacyAlign]:{up:e=>{let t;switch(e.props.align){case"start":t="start-legacy";break;case"end":t="end-legacy";break;default:t="middle-legacy";break}return{...e,props:{...e.props,align:t}}},down:e=>{let t;switch(e.props.align){case"start-legacy":t="start";break;case"end-legacy":t="end";break;case"middle-legacy":t="middle";break;default:t=e.props.align}return{...e,props:{...e.props,align:t}}}},[oi.AddVerticalAlign]:{up:e=>({...e,props:{...e.props,verticalAlign:"middle"}}),down:e=>{const{verticalAlign:t,...n}=e.props;return{...e,props:n}}},[oi.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Qn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e},[oi.AddFontSizeAdjustment]:{up:e=>({...e,props:{...e.props,fontSizeAdjustment:0}}),down:e=>{const{fontSizeAdjustment:t,...n}=e.props;return{...e,props:n}}}}}),EE={color:Jn,size:io,font:so,align:Dc,w:On,text:me,scale:On,autoSize:ve},ob={RemoveJustify:1},_E=Oe({currentVersion:ob.RemoveJustify,migrators:{[ob.RemoveJustify]:{up:e=>{let t=e.props.align;return t==="justify"&&(t="start"),{...e,props:{...e.props,align:t}}},down:e=>({...e})}}}),kE={w:On,h:On,time:he,playing:ve,url:Qn,assetId:pf.nullable()},Tg={AddUrlProp:1,MakeUrlsValid:2},TE=Oe({currentVersion:Tg.MakeUrlsValid,migrators:{[Tg.AddUrlProp]:{up:e=>({...e,props:{...e.props,url:""}}),down:e=>{const{url:t,...n}=e.props;return{...e,props:n}}},[Tg.MakeUrlsValid]:{up:e=>e.props.url!==""&&!Qn.isValid(e.props.url)?{...e,props:{...e.props,url:""}}:e,down:e=>e}}}),Rl={RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4},UR=Oe({currentVersion:Rl.RemoveUserDocument,migrators:{[Rl.RemoveCodeAndIconShapeTypes]:{up:e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>n.typeName!=="shape"||n.type!=="icon"&&n.type!=="code")),down:e=>e},[Rl.AddInstancePresenceType]:{up:e=>e,down:e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>n.typeName!=="instance_presence"))},[Rl.RemoveTLUserAndPresenceAndAddPointer]:{up:e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>!n.typeName.match(/^(user|user_presence)$/))),down:e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>n.typeName!=="pointer"))},[Rl.RemoveUserDocument]:{up:e=>Object.fromEntries(Object.entries(e).filter(([t,n])=>!n.typeName.match("user_document"))),down:e=>e}}}),HR={arrow:{migrations:oE,props:rE},bookmark:{migrations:iE,props:sE},draw:{migrations:cE,props:lE},embed:{migrations:dE,props:uE},frame:{migrations:pE,props:hE},geo:{migrations:gE,props:fE},group:{migrations:yE,props:mE},highlight:{migrations:vE,props:SE},image:{migrations:wE,props:xE},line:{migrations:PE,props:bE},note:{migrations:IE,props:CE},text:{migrations:_E,props:EE},video:{migrations:TE,props:kE}};function KR({shapes:e=HR}={}){const t=new Map;for(const o of at(e))for(const s of QI(o.props??{}).keys()){if(t.has(s.id)&&t.get(s.id)!==s)throw new Error(`Multiple StyleProp instances with the same id: ${s.id}`);t.set(s.id,s)}const n=LR(e),r=dR(t);return Uv.create({asset:hi,camera:qt,document:Xv,instance:r,instance_page_state:Zt,page:Lo,shape:n,instance_presence:wR,pointer:Yv},{snapshotMigrations:UR,onValidationFailure:IR,createIntegrityChecker:_R})}const Rc=[{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 VR(){const e=typeof window<"u"?window.navigator.languages??["en"]:["en"];return WR(e)}function WR(e){for(const t of e){const n=GR(t);if(n)return n}return"en"}const sb={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function GR(e){const t=Rc.find(o=>o.locale===e.toLowerCase());if(t)return t.locale;const[n,r]=e.split(/[-_]/).map(o=>o.toLowerCase());if(r){const o=Rc.find(s=>s.locale===n);if(o)return o.locale}return n in sb?sb[n]:null}var $E={exports:{}};/*!
40
- Copyright (c) 2018 Jed Watson.
41
- Licensed under the MIT License (MIT), see
42
- http://jedwatson.github.io/classnames
43
- */(function(e){(function(){var t={}.hasOwnProperty;function n(){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 n.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)t.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?(n.default=n,e.exports=n):window.classNames=n})()})($E);var YR=$E.exports;const ue=ll(YR),XR={error:null};class ME extends x.Component{constructor(){super(...arguments);m(this,"state",XR)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,o;(o=(r=this.props).onError)==null||o.call(r,n)}render(){const{error:n}=this.state;if(n!==null){const{fallback:r}=this.props;return h.jsx(r,{error:n})}return this.props.children}}function Lc({children:e,fallback:t,...n}){return t===null?h.jsx(h.Fragment,{children:e}):h.jsx(ME,{fallback:t,...n,children:e})}const ff=Se.createContext({});function z(){return Se.useContext(ff)}function qR(){return h.jsx("div",{className:"tl-background"})}function hl(e,t,n,r,o,s){x.useLayoutEffect(()=>{const i=e.current;if(!i||t===void 0)return;let a=`translate(${t}px, ${n}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 nn={linear:e=>e,easeInQuad:e=>e*e,easeOutQuad:e=>e*(2-e),easeInOutQuad:e=>e<.5?2*e*e:-1+(4-2*e)*e,easeInCubic:e=>e*e*e,easeOutCubic:e=>--e*e*e+1,easeInOutCubic:e=>e<.5?4*e*e*e:(e-1)*(2*e-2)*(2*e-2)+1,easeInQuart:e=>e*e*e*e,easeOutQuart:e=>1- --e*e*e*e,easeInOutQuart:e=>e<.5?8*e*e*e*e:1-8*--e*e*e*e,easeInQuint:e=>e*e*e*e*e,easeOutQuint:e=>1+--e*e*e*e*e,easeInOutQuint:e=>e<.5?16*e*e*e*e*e:1+16*--e*e*e*e*e,easeInSine:e=>1-Math.cos(e*Math.PI/2),easeOutSine:e=>Math.sin(e*Math.PI/2),easeInOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,easeInExpo:e=>e<=0?0:Math.pow(2,10*e-10),easeOutExpo:e=>e>=1?1:1-Math.pow(2,-10*e),easeInOutExpo:e=>e<=0?0:e>=1?1:e<.5?Math.pow(2,20*e-10)/2:(2-Math.pow(2,-20*e+10))/2};class b{constructor(t=0,n=0,r=1){this.x=t,this.y=n,this.z=r}get pressure(){return this.z}set(t=this.x,n=this.y,r=this.z){return this.x=t,this.y=n,this.z=r,this}setTo({x:t=0,y:n=0,z:r=1}){return this.x=t,this.y=n,this.z=r,this}rot(t){if(t===0)return this;const{x:n,y:r}=this,o=Math.sin(t),s=Math.cos(t);return this.x=n*s-r*o,this.y=n*o+r*s,this}rotWith(t,n){if(n===0)return this;const r=this.x-t.x,o=this.y-t.y,s=Math.sin(n),i=Math.cos(n);return this.x=t.x+(r*i-o*s),this.y=t.y+(r*s+o*i),this}clone(){const{x:t,y:n,z:r}=this;return new b(t,n,r)}sub(t){return this.x-=t.x,this.y-=t.y,this}subXY(t,n){return this.x-=t,this.y-=n,this}subScalar(t){return this.x-=t,this.y-=t,this}add(t){return this.x+=t.x,this.y+=t.y,this}addXY(t,n){return this.x+=t,this.y+=n,this}addScalar(t){return this.x+=t,this.y+=t,this}clamp(t,n){return this.x=Math.max(this.x,t),this.y=Math.max(this.y,t),n!==void 0&&(this.x=Math.min(this.x,n),this.y=Math.min(this.y,n)),this}div(t){return this.x/=t,this.y/=t,this}divV(t){return this.x/=t.x,this.y/=t.y,this}mul(t){return this.x*=t,this.y*=t,this}mulV(t){return this.x*=t.x,this.y*=t.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(t,n){const r=b.Tan(t,this);return this.add(r.mul(n))}neg(){return this.x*=-1,this.y*=-1,this}cross(t){return this.x=this.y*t.z-this.z*t.y,this.y=this.z*t.x-this.x*t.z,this}dpr(t){return b.Dpr(this,t)}cpr(t){return b.Cpr(this,t)}len2(){return b.Len2(this)}len(){return b.Len(this)}pry(t){return b.Pry(this,t)}per(){const{x:t,y:n}=this;return this.x=n,this.y=-t,this}uni(){return b.Uni(this)}tan(t){return b.Tan(this,t)}dist(t){return b.Dist(this,t)}distanceToLineSegment(t,n){return b.DistanceToLineSegment(t,n,this)}slope(t){return b.Slope(this,t)}snapToGrid(t){return this.x=Math.round(this.x/t)*t,this.y=Math.round(this.y/t)*t,this}angle(t){return b.Angle(this,t)}toAngle(){return b.ToAngle(this)}lrp(t,n){return this.x=this.x+(t.x-this.x)*n,this.y=this.y+(t.y-this.y)*n,this}equals(t){return b.Equals(this,t)}equalsXY(t,n){return b.EqualsXY(this,t,n)}norm(){const t=this.len();return this.x=t===0?0:this.x/t,this.y=t===0?0:this.y/t,this}toFixed(){return b.ToFixed(this)}toString(){return b.ToString(b.ToFixed(this))}toJson(){return b.ToJson(this)}toArray(){return b.ToArray(this)}static Add(t,n){return new b(t.x+n.x,t.y+n.y)}static AddXY(t,n,r){return new b(t.x+n,t.y+r)}static Sub(t,n){return new b(t.x-n.x,t.y-n.y)}static SubXY(t,n,r){return new b(t.x-n,t.y-r)}static AddScalar(t,n){return new b(t.x+n,t.y+n)}static SubScalar(t,n){return new b(t.x-n,t.y-n)}static Div(t,n){return new b(t.x/n,t.y/n)}static Mul(t,n){return new b(t.x*n,t.y*n)}static DivV(t,n){return new b(t.x/n.x,t.y/n.y)}static MulV(t,n){return new b(t.x*n.x,t.y*n.y)}static Neg(t){return new b(-t.x,-t.y)}static Per(t){return new b(t.y,-t.x)}static Abs(t){return new b(Math.abs(t.x),Math.abs(t.y))}static Dist(t,n){return Math.hypot(t.y-n.y,t.x-n.x)}static DistMin(t,n,r){return(t.x-n.x)*(t.x-n.x)+(t.y-n.y)*(t.y-n.y)<r**2}static Dist2(t,n){return(t.x-n.x)*(t.x-n.x)+(t.y-n.y)*(t.y-n.y)}static Dpr(t,n){return t.x*n.x+t.y*n.y}static Cross(t,n){return new b(t.y*n.z-t.z*n.y,t.z*n.x-t.x*n.z)}static Cpr(t,n){return t.x*n.y-n.x*t.y}static Len2(t){return t.x*t.x+t.y*t.y}static Len(t){return Math.hypot(t.x,t.y)}static Pry(t,n){return b.Dpr(t,n)/b.Len(n)}static Uni(t){return b.Div(t,b.Len(t))}static Tan(t,n){return b.Uni(b.Sub(t,n))}static Min(t,n){return new b(Math.min(t.x,n.x),Math.min(t.y,n.y))}static Max(t,n){return new b(Math.max(t.x,n.x),Math.max(t.y,n.y))}static From({x:t,y:n,z:r=1}){return new b(t,n,r)}static FromArray(t){return new b(t[0],t[1])}static Rot(t,n=0){const r=Math.sin(n),o=Math.cos(n);return new b(t.x*o-t.y*r,t.x*r+t.y*o)}static RotWith(t,n,r){const o=t.x-n.x,s=t.y-n.y,i=Math.sin(r),a=Math.cos(r);return new b(n.x+(o*a-s*i),n.y+(o*i+s*a))}static NearestPointOnLineThroughPoint(t,n,r){return b.Mul(n,b.Sub(r,t).pry(n)).add(t)}static NearestPointOnLineSegment(t,n,r,o=!0){if(b.Equals(t,r)||b.Equals(n,r))return b.From(r);const s=b.Tan(n,t),i=b.Add(t,b.Mul(s,b.Sub(r,t).pry(s)));if(o){if(i.x<Math.min(t.x,n.x))return b.Cast(t.x<n.x?t:n);if(i.x>Math.max(t.x,n.x))return b.Cast(t.x>n.x?t:n);if(i.y<Math.min(t.y,n.y))return b.Cast(t.y<n.y?t:n);if(i.y>Math.max(t.y,n.y))return b.Cast(t.y>n.y?t:n)}return i}static DistanceToLineThroughPoint(t,n,r){return b.Dist(r,b.NearestPointOnLineThroughPoint(t,n,r))}static DistanceToLineSegment(t,n,r,o=!0){return b.Dist(r,b.NearestPointOnLineSegment(t,n,r,o))}static Snap(t,n=1){return new b(Math.round(t.x/n)*n,Math.round(t.y/n)*n)}static Cast(t){return t instanceof b?t:b.From(t)}static Slope(t,n){return t.x===n.y?NaN:(t.y-n.y)/(t.x-n.x)}static IsNaN(t){return isNaN(t.x)||isNaN(t.y)}static Angle(t,n){return Math.atan2(n.y-t.y,n.x-t.x)}static Lrp(t,n,r){return b.Sub(n,t).mul(r).add(t)}static Med(t,n){return new b((t.x+n.x)/2,(t.y+n.y)/2)}static Equals(t,n){return Math.abs(t.x-n.x)<1e-4&&Math.abs(t.y-n.y)<1e-4}static EqualsXY(t,n,r){return t.x===n&&t.y===r}static Clockwise(t,n,r){return(r.x-t.x)*(n.y-t.y)-(n.x-t.x)*(r.y-t.y)<0}static Rescale(t,n){const r=b.Len(t);return new b(n*t.x/r,n*t.y/r)}static ScaleWithOrigin(t,n,r){return b.Sub(t,r).mul(n).add(r)}static ToFixed(t,n=2){return new b(+t.x.toFixed(n),+t.y.toFixed(n),+t.z.toFixed(n))}static Nudge(t,n,r){return b.Add(t,b.Tan(n,t).mul(r))}static ToString(t){return`${t.x}, ${t.y}`}static ToAngle(t){let n=Math.atan2(t.y,t.x);return n<0&&(n+=Math.PI*2),n}static FromAngle(t,n=1){return new b(Math.cos(t)*n,Math.sin(t)*n)}static ToArray(t){return[t.x,t.y,t.z]}static ToJson(t){const{x:n,y:r,z:o}=t;return{x:n,y:r,z:o}}static Average(t){const n=t.length,r=new b(0,0);if(n===0)return r;for(let o=0;o<n;o++)r.add(t[o]);return r.div(n)}static Clamp(t,n,r){return r===void 0?new b(Math.min(Math.max(t.x,n)),Math.min(Math.max(t.y,n))):new b(Math.min(Math.max(t.x,n),r),Math.min(Math.max(t.y,n),r))}static PointsBetween(t,n,r=6){const o=[];for(let s=0;s<r;s++){const i=nn.easeInQuad(s/(r-1)),a=b.Lrp(t,n,i);a.z=Math.min(1,.5+Math.abs(.5-ZR(i))*.65),o.push(a)}return o}static SnapToGrid(t,n=8){return new b(Math.round(t.x/n)*n,Math.round(t.y/n)*n)}}const ZR=e=>e<.5?2*e*e:-1+(4-2*e)*e;function Ft(e){return`${O(e.x)},${O(e.y)} `}function Pn(e,t){return`${O((e.x+t.x)/2)},${O((e.y+t.y)/2)} `}const je=Math.PI,Ge=je/2,Fe=je*2,QR=Math.sin;function Zr(e,t,n){return Math.max(t,typeof n<"u"?Math.min(e,n):e)}function rd(e,t=1e10){return e?Math.round(e*t)/t:0}function mc(e,t,n=1e-6){return Math.abs(e-t)<=n}function hp(e,t){const n=Math.pow(e-t,2)/Math.pow(e+t,2);return je*(e+t)*(1+3*n/(10+Math.sqrt(4-3*n)))}function ws(e){return e=e%Fe,e<0?e=e+Fe:e===0&&(e=0),e}function bu(e,t){return e=ws(e),t=ws(t),e>t&&(t+=Fe),t-e}function AE(e,t){return Fe-bu(e,t)}function yc(e,t){const n=(t-e)%Fe;return 2*n%Fe-n}function Dy(e){return(Fe+e)%Fe}function pp(e,t){const n=Fe/t;let r=Math.floor((Dy(e)+n/2)/n)*n%Fe;return r<je&&(r+=Fe),r>je&&(r-=Fe),r}function jE(e,t){return e===t||mc(e%(Math.PI/2)-t%(Math.PI/2),0)}function JR(e){return e*je/180}function e3(e){return e*180/je}function bi(e,t,n){return new b(e.x,e.y).add(b.FromAngle(n,t))}function $g(e,t,n){const r=e/2,o=t/2,s=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let y=0;y<n;y++){const g=Fe/n,w=-Ge+y*g,S=r+r*Math.cos(w),v=o+o*Math.sin(w);S<i&&(i=S),v<l&&(l=v),S>a&&(a=S),v>c&&(c=v),s.push(new b(S,v))}const u=a-i,d=c-l,p=e-u,f=t-d;if(p!==0||f!==0)for(let y=0;y<s.length;y++){const g=s[y];g.x=(g.x-i)/u*e,g.y=(g.y-l)/d*t}return s}function Ll(e,t,n,r){return e<r&&n<t}function Er(e,t,n,r){const o=Math.max(e,n),s=Math.min(t,r);return o<=s?[o,s]:null}function ib(e,t,n){return(t.x-e.x)*(n.y-e.y)-(n.x-e.x)*(t.y-e.y)}function Xn(e,t){let n=0,r,o;for(let s=0;s<t.length;s++){if(r=t[s],r.x===e.x&&r.y===e.y||(o=t[(s+1)%t.length],b.Dist(e,r)+b.Dist(e,o)===b.Dist(r,o)))return!0;r.y<=e.y?o.y>e.y&&ib(r,o,e)>0&&(n+=1):o.y<=e.y&&ib(r,o,e)<0&&(n-=1)}return n!==0}function O(e){return Math.round(e*1e4)/1e4}function fp(e){return Math.round(e*100)/100}const ab=e=>Math.abs(e)<Number.MAX_SAFE_INTEGER;function hs(e,t,n){return n<0?bu(e,t):AE(e,t)}function Ry(e,t,n,r){let o;if(Math.abs(e)>je){o=yc(t,r);const s=yc(r,n);return Math.abs(o)<Math.abs(s)?o/e:(e-s)/e}else{o=yc(t,r);const s=o/e;return Math.sign(o)!==Math.sign(e)?Math.abs(s)>.5?1:0:s}}function t3(e,t,n,r){const o=2*((t-e)%Fe)%Fe-(t-e)%Fe;return r?(Fe-Math.abs(o))*(n?1:-1):o}const od=({brush:e,color:t,opacity:n,className:r})=>{const o=x.useRef(null);hl(o,e.x,e.y);const s=O(Math.max(1,e.w)),i=O(Math.max(1,e.h));return h.jsx("svg",{className:"tl-overlays__item",ref:o,children:t?h.jsxs("g",{className:"tl-brush",opacity:n,children:[h.jsx("rect",{width:s,height:i,fill:t,opacity:.75}),h.jsx("rect",{width:s,height:i,fill:"none",stroke:t,opacity:.1})]}):h.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:s,height:i})})},bo=2e3,gp=40,Yr=320,Qi=[.1,.25,.5,1,2,4,8],Fl=.1,ps=8,n3=.5,r3=.1,o3=.2,s3=.005,i3=.05,a3=450,l3=200,Ly=36,Fc=16,c3=32,Xa={};for(let e=1;e<=Math.ceil(ps);e++)Xa[e+"_dark"]=`hash_pattern_zoom_${e}_dark`,Xa[e+"_light"]=`hash_pattern_zoom_${e}_light`;const u3={duration:0,easing:nn.easeInOutCubic},rh=.09,lb=[{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}],d3=6e4,OE=3e3,h3=1200,cb={CAMERA_MOVE:-10},p3=64,Fo=8,f3=20,g3=8,m3=12,DE=20,RE=12,y3=["top","right","bottom","left"],S3=500,ub=.35;var Mg={};const v3={},LE=Bn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),Tt={logPreventDefaults:Bn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Bn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Bn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Bn("debugSvg",{defaults:{all:!1}}),showFps:Bn("showFps",{defaults:{all:!1}}),throwToBlob:Bn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Bn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Bn("debugCursors",{defaults:{all:!1}}),forceSrgb:Bn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Bn("debugGeometry",{defaults:{all:!1}}),hideShapes:Bn("hideShapes",{defaults:{all:!1}}),editOnType:Bn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const e=Element.prototype.removeChild;wu("element removal logging",()=>{Tt.logElementRemoves.get()?Element.prototype.removeChild=function(t){return console.warn("[tldraw] removing child:",t),e.call(this,t)}:Element.prototype.removeChild=e})}function Bn(e,{defaults:t,shouldStoreForSession:n=!0}){return x3({name:e,defaults:t,shouldStoreForSession:n})}function x3(e){const t=b3(e),n=e.shouldStoreForSession?w3(e.name):null,r=In(`debug:${e.name}`,n??t);return typeof window<"u"&&(e.shouldStoreForSession&&wu(`debug:${e.name}`,()=>{const o=r.get();o===t?zI(`tldraw_debug:${e.name}`):Nv(`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 w3(e){try{return JSON.parse(NI(`tldraw_debug:${e}`)??"null")}catch{return null}}function Ag(e){try{return e()}catch{return null}}function b3(e){switch(Ag(()=>Mg.TLDRAW_ENV)??Ag(()=>Mg.VERCEL_PUBLIC_TLDRAW_ENV)??Ag(()=>Mg.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 mp(e){if(e instanceof HTMLElement)return e;if(e.parentElement)return mp(e.parentElement);throw Error("Could not find a parent element of an HTML type!")}function Ae(e){e.preventDefault(),Tt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",e)}function pl(e,t){if(e.setPointerCapture(t.pointerId),Tt.logPointerCaptures.get()){const n=LE.get();n.set(e,(n.get(e)??0)+1),console.warn("setPointerCapture called on element:",e,t)}}function Pu(e,t){if(e.hasPointerCapture(t.pointerId)&&(e.releasePointerCapture(t.pointerId),Tt.logPointerCaptures.get())){const n=LE.get();n.get(e)===1?n.delete(e):n.has(e)?n.set(e,n.get(e)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",e,t)}}const rn=e=>e.stopPropagation(),Gt=(e,t,n)=>{e&&e.style.setProperty(t,n)};function En(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 P3(){const e=z();return x.useMemo(function(){let r,o;function s(g){if(!g.isKilled){if(g.button===2){e.dispatch({type:"pointer",target:"canvas",name:"right_click",...En(g)});return}g.button!==0&&g.button!==1&&g.button!==5||(pl(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...En(g)}),e.getOpenMenus().length>0&&(e.updateInstanceState({openMenus:[]}),document.body.click(),e.getContainer().focus()))}}function i(g){g.isKilled||g.clientX===r&&g.clientY===o||(r=g.clientX,o=g.clientY,e.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...En(g)}))}function a(g){g.isKilled||g.button!==0&&g.button!==1&&g.button!==2&&g.button!==5||(r=g.clientX,o=g.clientY,Pu(g.currentTarget,g),e.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...En(g)}))}function l(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const w=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!0:null})}function c(g){if(g.isKilled||e.getInstanceState().isPenMode&&g.pointerType!=="pen")return;const w=g.pointerType==="mouse"||g.pointerType==="pen";e.updateInstanceState({isHoveringCanvas:w?!1:null})}function u(g){g.isKilled=!0,document.body.click(),Ae(g)}function d(g){g.isKilled=!0,g.target.tagName!=="A"&&g.target.tagName!=="TEXTAREA"&&!(e.getEditingShape()&&g.target.className.includes("tl-text-content"))&&Ae(g)}function p(g){Ae(g)}async function f(g){var S,v;if(Ae(g),!((v=(S=g.dataTransfer)==null?void 0:S.files)!=null&&v.length))return;const w=Array.from(g.dataTransfer.files);await e.putExternalContent({type:"files",files:w,point:e.screenToPage({x:g.clientX,y:g.clientY}),ignoreParent:!1})}function y(g){rn(g)}return{onPointerDown:s,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:p,onDrop:f,onTouchStart:u,onTouchEnd:d,onClick:y}},[e])}function C3(){const e=z();x.useEffect(()=>{if(e.environment.isFirefox&&!e.environment.isAndroid&&!e.environment.isIos){e.updateInstanceState({isCoarsePointer:!1});return}if(window.matchMedia){const t=window.matchMedia("(pointer: coarse)"),n=()=>{e.updateInstanceState({isCoarsePointer:!!t.matches})};if(n(),t)return t.addEventListener("change",n),()=>t.removeEventListener("change",n)}},[e])}const FE=x.createContext(null);function I3({container:e,children:t}){return h.jsx(FE.Provider,{value:e,children:t})}function ln(){return di(x.useContext(FE),"useContainer used outside of <Tldraw />")}function E3(){const e=z(),t=ln(),n=K("isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(typeof matchMedia===void 0)return;let r=null;const o=()=>{r!=null&&r();const s=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(s),a=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]),x.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(e.isIn("zoom")||!e.getPath().endsWith(".idle"))&&!sd()&&Ae(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){Ae(a);return}break}case"Tab":{if(sd()||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(),t.focus());return}default:if(sd()||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,sd()||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(t.contains(a.target)){const u=a.touches[0].pageX,d=a.touches[0].radiusX||0;(u-d<10||u+d>e.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),Ae(a))}}const i=a=>{t.contains(a.target)&&(a.ctrlKey||a.metaKey)&&Ae(a)};return t.addEventListener("touchstart",s,{passive:!1}),t.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",Ae),document.addEventListener("gesturechange",Ae),document.addEventListener("gestureend",Ae),t.addEventListener("keydown",r),t.addEventListener("keyup",o),()=>{t.removeEventListener("touchstart",s),t.removeEventListener("wheel",i),document.removeEventListener("gesturestart",Ae),document.removeEventListener("gesturechange",Ae),document.removeEventListener("gestureend",Ae),t.removeEventListener("keydown",r),t.removeEventListener("keyup",o)}},[e,t,n])}const _3=["input","select","button","textarea"];function sd(){const{activeElement:e}=document;return!!(e&&(e.getAttribute("contenteditable")||_3.indexOf(e.tagName.toLowerCase())>-1))}const k3=["textarea","input"];function T3(e){const t=z();x.useEffect(()=>{const n=e.current;if(!n)return;const r=o=>{var s;if(o instanceof PointerEvent&&o.pointerType==="pen"){o.isKilled=!0;const{target:i}=o;if(k3.includes((s=i.tagName)==null?void 0:s.toLocaleLowerCase())||t.isIn("select.editing_shape"))return;Ae(o)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[t,e])}function $3(e,t,n){return Math.max(t,Math.min(e,n))}const zt={toVector(e,t){return e===void 0&&(e=t),Array.isArray(e)?e:[e,e]},add(e,t){return[e[0]+t[0],e[1]+t[1]]},sub(e,t){return[e[0]-t[0],e[1]-t[1]]},addTo(e,t){e[0]+=t[0],e[1]+=t[1]},subTo(e,t){e[0]-=t[0],e[1]-=t[1]}};function db(e,t,n){return t===0||Math.abs(t)===1/0?Math.pow(e,n*5):e*t*n/(t+n*e)}function hb(e,t,n,r=.15){return r===0?$3(e,t,n):e<t?-db(t-e,n-t,r)+t:e>n?+db(e-n,n-t,r)+n:e}function M3(e,[t,n],[r,o]){const[[s,i],[a,l]]=e;return[hb(t,s,i,r),hb(n,a,l,o)]}function A3(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function j3(e){var t=A3(e,"string");return typeof t=="symbol"?t:String(t)}function Xt(e,t,n){return t=j3(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function pb(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function ct(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?pb(Object(n),!0).forEach(function(r){Xt(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):pb(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}const NE={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 fb(e){return e?e[0].toUpperCase()+e.slice(1):""}const O3=["enter","leave"];function D3(e=!1,t){return e&&!O3.includes(t)}function R3(e,t="",n=!1){const r=NE[e],o=r&&r[t]||t;return"on"+fb(e)+fb(o)+(D3(n,o)?"Capture":"")}const L3=["gotpointercapture","lostpointercapture"];function F3(e){let t=e.substring(2).toLowerCase();const n=!!~t.indexOf("passive");n&&(t=t.replace("passive",""));const r=L3.includes(t)?"capturecapture":"capture",o=!!~t.indexOf(r);return o&&(t=t.replace("capture","")),{device:t,capture:o,passive:n}}function N3(e,t=""){const n=NE[e],r=n&&n[t]||t;return e+r}function zE(e){return"touches"in e}function z3(e){return zE(e)?"touch":"pointerType"in e?e.pointerType:"mouse"}function B3(e){return Array.from(e.touches).filter(t=>{var n,r;return t.target===e.currentTarget||((n=e.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,t.target))})}function Fy(e,t){try{const n=t.clientX-e.clientX,r=t.clientY-e.clientY,o=(t.clientX+e.clientX)/2,s=(t.clientY+e.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[o,s]}}catch{}return null}function U3(e){return B3(e).map(t=>t.identifier)}function gb(e,t){const[n,r]=Array.from(e.touches).filter(o=>t.includes(o.identifier));return Fy(n,r)}const mb=40,yb=800;function BE(e){let{deltaX:t,deltaY:n,deltaMode:r}=e;return r===1?(t*=mb,n*=mb):r===2&&(t*=yb,n*=yb),[t,n]}function H3(e){const t={};if("buttons"in e&&(t.buttons=e.buttons),"shiftKey"in e){const{shiftKey:n,altKey:r,metaKey:o,ctrlKey:s}=e;Object.assign(t,{shiftKey:n,altKey:r,metaKey:o,ctrlKey:s})}return t}function yp(e,...t){return typeof e=="function"?e(...t):e}function K3(){}function V3(...e){return e.length===0?K3:e.length===1?e[0]:function(){let t;for(const n of e)t=n.apply(this,arguments)||t;return t}}function Sb(e,t){return Object.assign({},t,e||{})}const W3=32;class UE{constructor(t,n,r){this.ctrl=t,this.args=n,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(t){this.ctrl.state[this.key]=t}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:t,shared:n,ingKey:r,args:o}=this;n[r]=t._active=t.active=t._blocked=t._force=!1,t._step=[!1,!1],t.intentional=!1,t._movement=[0,0],t._distance=[0,0],t._direction=[0,0],t._delta=[0,0],t._bounds=[[-1/0,1/0],[-1/0,1/0]],t.args=o,t.axis=void 0,t.memo=void 0,t.elapsedTime=t.timeDelta=0,t.direction=[0,0],t.distance=[0,0],t.overflow=[0,0],t._movementBound=[!1,!1],t.velocity=[0,0],t.movement=[0,0],t.delta=[0,0],t.timeStamp=0}start(t){const n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=t.target,n.currentTarget=t.currentTarget,n.lastOffset=r.from?yp(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=t.timeStamp)}computeValues(t){const n=this.state;n._values=t,n.values=this.config.transform(t)}computeInitial(){const t=this.state;t._initial=t._values,t.initial=t.values}compute(t){const{state:n,config:r,shared:o}=this;n.args=this.args;let s=0;if(t&&(n.event=t,r.preventDefault&&t.cancelable&&n.event.preventDefault(),n.type=t.type,o.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,o.locked=!!document.pointerLockElement,Object.assign(o,H3(t)),o.down=o.pressed=o.buttons%2===1||o.touches>0,s=t.timeStamp-n.timeStamp,n.timeStamp=t.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const E=n._delta.map(Math.abs);zt.addTo(n._distance,E)}this.axisIntent&&this.axisIntent(t);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:d}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&d[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&d[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const p=[0,0];if(r.hasCustomTransform){const[E,_]=d;p[0]=u[0]!==!1?E-u[0]:0,p[1]=u[1]!==!1?_-u[1]:0}else p[0]=u[0]!==!1?i-u[0]:0,p[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(p);const f=n.offset,y=n._active&&!n._blocked||n.active;y&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=o[this.ingKey]=n._active,t&&(n.first&&("bounds"in r&&(n._bounds=yp(r.bounds,n)),this.setup&&this.setup()),n.movement=p,this.computeOffset()));const[g,w]=n.offset,[[S,v],[C,I]]=n._bounds;n.overflow=[g<S?-1:g>v?1:0,w<C?-1:w>I?1:0],n._movementBound[0]=n.overflow[0]?n._movementBound[0]===!1?n._movement[0]:n._movementBound[0]:!1,n._movementBound[1]=n.overflow[1]?n._movementBound[1]===!1?n._movement[1]:n._movementBound[1]:!1;const P=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=M3(n._bounds,n.offset,P),n.delta=zt.sub(n.offset,f),this.computeMovement(),y&&(!n.last||s>W3)){n.delta=zt.sub(n.offset,f);const E=n.delta.map(Math.abs);zt.addTo(n.distance,E),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&s>0&&(n.velocity=[E[0]/s,E[1]/s],n.timeDelta=s)}}emit(){const t=this.state,n=this.shared,r=this.config;if(t._active||this.clean(),(t._blocked||!t.intentional)&&!t._force&&!r.triggerAllEvents)return;const o=this.handler(ct(ct(ct({},n),t),{},{[this.aliasKey]:t.values}));o!==void 0&&(t.memo=o)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function G3([e,t],n){const r=Math.abs(e),o=Math.abs(t);if(r>o&&r>n)return"x";if(o>r&&o>n)return"y"}class Y3 extends UE{constructor(...t){super(...t),Xt(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=zt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=zt.sub(this.state.offset,this.state.lastOffset)}axisIntent(t){const n=this.state,r=this.config;if(!n.axis&&t){const o=typeof r.axisThreshold=="object"?r.axisThreshold[z3(t)]:r.axisThreshold;n.axis=G3(n._movement,o)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.axis}restrictToAxis(t){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":t[1]=0;break;case"y":t[0]=0;break}}}const X3=e=>e,vb=.15,HE={enabled(e=!0){return e},eventOptions(e,t,n){return ct(ct({},n.shared.eventOptions),e)},preventDefault(e=!1){return e},triggerAllEvents(e=!1){return e},rubberband(e=0){switch(e){case!0:return[vb,vb];case!1:return[0,0];default:return zt.toVector(e)}},from(e){if(typeof e=="function")return e;if(e!=null)return zt.toVector(e)},transform(e,t,n){const r=e||n.shared.transform;return this.hasCustomTransform=!!r,r||X3},threshold(e){return zt.toVector(e,0)}},q3=0,Cu=ct(ct({},HE),{},{axis(e,t,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(e=q3){return e},bounds(e={}){if(typeof e=="function")return s=>Cu.bounds(e(s));if("current"in e)return()=>e.current;if(typeof HTMLElement=="function"&&e instanceof HTMLElement)return e;const{left:t=-1/0,right:n=1/0,top:r=-1/0,bottom:o=1/0}=e;return[[t,n],[r,o]]}}),Iu=typeof window<"u"&&window.document&&window.document.createElement;function KE(){return Iu&&"ontouchstart"in window}function Z3(){return KE()||Iu&&window.navigator.maxTouchPoints>1}function Q3(){return Iu&&"onpointerdown"in window}function J3(){return Iu&&"exitPointerLock"in window.document}function eL(){try{return"constructor"in GestureEvent}catch{return!1}}const cr={isBrowser:Iu,gesture:eL(),touch:KE(),touchscreen:Z3(),pointer:Q3(),pointerLock:J3()},tL=250,nL=180,rL=.5,oL=50,sL=250,iL=10,xb={mouse:0,touch:0,pen:8};ct(ct({},Cu),{},{device(e,t,{pointer:{touch:n=!1,lock:r=!1,mouse:o=!1}={}}){return this.pointerLock=r&&cr.pointerLock,cr.touch&&n?"touch":this.pointerLock?"mouse":cr.pointer&&!o?"pointer":cr.touch?"touch":"mouse"},preventScrollAxis(e,t,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&e?tL:void 0,!(!cr.touchscreen||n===!1))return e||(n!==void 0?"y":void 0)},pointerCapture(e,t,{pointer:{capture:n=!0,buttons:r=1,keys:o=!0}={}}){return this.pointerButtons=r,this.keys=o,!this.pointerLock&&this.device==="pointer"&&n},threshold(e,t,{filterTaps:n=!1,tapsThreshold:r=3,axis:o=void 0}){const s=zt.toVector(e,n?r:o?1:0);return this.filterTaps=n,this.tapsThreshold=r,s},swipe({velocity:e=rL,distance:t=oL,duration:n=sL}={}){return{velocity:this.transform(zt.toVector(e)),distance:this.transform(zt.toVector(t)),duration:n}},delay(e=0){switch(e){case!0:return nL;case!1:return 0;default:return e}},axisThreshold(e){return e?ct(ct({},xb),e):xb},keyboardDisplacement(e=iL){return e}});function VE(e){const[t,n]=e.overflow,[r,o]=e._delta,[s,i]=e._direction;(t<0&&r>0&&s<0||t>0&&r<0&&s>0)&&(e._movement[0]=e._movementBound[0]),(n<0&&o>0&&i<0||n>0&&o<0&&i>0)&&(e._movement[1]=e._movementBound[1])}const aL=30,lL=100;class cL extends UE{constructor(...t){super(...t),Xt(this,"ingKey","pinching"),Xt(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const t=this.state;t._touchIds=[],t.canceled=!1,t.cancel=this.cancel.bind(this),t.turns=0}computeOffset(){const{type:t,movement:n,lastOffset:r}=this.state;t==="wheel"?this.state.offset=zt.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:t,lastOffset:n}=this.state;this.state.movement=[t[0]/n[0],t[1]-n[1]]}axisIntent(){const t=this.state,[n,r]=t._movement;if(!t.axis){const o=Math.abs(n)*aL-Math.abs(r);o<0?t.axis="angle":o>0&&(t.axis="scale")}}restrictToAxis(t){this.config.lockDirection&&(this.state.axis==="scale"?t[1]=0:this.state.axis==="angle"&&(t[0]=0))}cancel(){const t=this.state;t.canceled||setTimeout(()=>{t.canceled=!0,t._active=!1,this.compute(),this.emit()},0)}touchStart(t){this.ctrl.setEventIds(t);const n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(s=>r.has(s))||r.size<2)return;this.start(t),n._touchIds=Array.from(r).slice(0,2);const o=gb(t,n._touchIds);o&&this.pinchStart(t,o)}pointerStart(t){if(t.buttons!=null&&t.buttons%2!==1)return;this.ctrl.setEventIds(t),t.target.setPointerCapture(t.pointerId);const n=this.state,r=n._pointerEvents,o=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>o.has(i))||(r.size<2&&r.set(t.pointerId,t),n._pointerEvents.size<2))return;this.start(t);const s=Fy(...Array.from(r.values()));s&&this.pinchStart(t,s)}pinchStart(t,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(t),this.emit()}touchMove(t){if(!this.state._active)return;const n=gb(t,this.state._touchIds);n&&this.pinchMove(t,n)}pointerMove(t){const n=this.state._pointerEvents;if(n.has(t.pointerId)&&n.set(t.pointerId,t),!this.state._active)return;const r=Fy(...Array.from(n.values()));r&&this.pinchMove(t,r)}pinchMove(t,n){const r=this.state,o=r._values[1],s=n.angle-o;let i=0;Math.abs(s)>270&&(i+=Math.sign(s)),this.computeValues([n.distance,n.angle-360*i]),r.origin=n.origin,r.turns=i,r._movement=[r._values[0]/r._initial[0]-1,r._values[1]-r._initial[1]],this.compute(t),this.emit()}touchEnd(t){this.ctrl.setEventIds(t),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(t),this.emit())}pointerEnd(t){const n=this.state;this.ctrl.setEventIds(t);try{t.target.releasePointerCapture(t.pointerId)}catch{}n._pointerEvents.has(t.pointerId)&&n._pointerEvents.delete(t.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(t),this.emit())}gestureStart(t){t.cancelable&&t.preventDefault();const n=this.state;n._active||(this.start(t),this.computeValues([t.scale,t.rotation]),n.origin=[t.clientX,t.clientY],this.compute(t),this.emit())}gestureMove(t){if(t.cancelable&&t.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([t.scale,t.rotation]),n.origin=[t.clientX,t.clientY];const r=n._movement;n._movement=[t.scale-1,t.rotation],n._delta=zt.sub(n._movement,r),this.compute(t),this.emit()}gestureEnd(t){this.state._active&&(this.state._active=!1,this.compute(t),this.emit())}wheel(t){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>t[r]):!t[n])||(this.state._active?this.wheelChange(t):this.wheelStart(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(t){this.start(t),this.wheelChange(t)}wheelChange(t){"uv"in t||t.cancelable&&t.preventDefault();const r=this.state;r._delta=[-BE(t)[1]/lL*r.offset[0],0],zt.addTo(r._movement,r._delta),VE(r),this.state.origin=[t.clientX,t.clientY],this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){const n=this.config.device;n&&(t(n,"start",this[n+"Start"].bind(this)),t(n,"change",this[n+"Move"].bind(this)),t(n,"end",this[n+"End"].bind(this)),t(n,"cancel",this[n+"End"].bind(this)),t("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&t("wheel","",this.wheel.bind(this),{passive:!1})}}const uL=ct(ct({},HE),{},{device(e,t,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!cr.touch&&cr.gesture)return"gesture";if(cr.touch&&r)return"touch";if(cr.touchscreen){if(cr.pointer)return"pointer";if(cr.touch)return"touch"}},bounds(e,t,{scaleBounds:n={},angleBounds:r={}}){const o=i=>{const a=Sb(yp(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},s=i=>{const a=Sb(yp(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[o(),s()]:i=>[o(i),s(i)]},threshold(e,t,n){return this.lockDirection=n.axis==="lock",zt.toVector(e,this.lockDirection?[.1,3]:0)},modifierKey(e){return e===void 0?"ctrlKey":e},pinchOnWheel(e=!0){return e}});ct(ct({},Cu),{},{mouseOnly:(e=!0)=>e});class dL extends Y3{constructor(...t){super(...t),Xt(this,"ingKey","wheeling")}wheel(t){this.state._active||this.start(t),this.wheelChange(t),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(t){const n=this.state;n._delta=BE(t),zt.addTo(n._movement,n._delta),VE(n),this.compute(t),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(t){t("wheel","",this.wheel.bind(this))}}const hL=Cu;ct(ct({},Cu),{},{mouseOnly:(e=!0)=>e});const qv=new Map,Ny=new Map;function pL(e){qv.set(e.key,e.engine),Ny.set(e.key,e.resolver)}const fL={key:"pinch",engine:cL,resolver:uL},gL={key:"wheel",engine:dL,resolver:hL};function mL(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function yL(e,t){if(e==null)return{};var n=mL(e,t),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}const SL={target(e){if(e)return()=>"current"in e?e.current:e},enabled(e=!0){return e},window(e=cr.isBrowser?window:void 0){return e},eventOptions({passive:e=!0,capture:t=!1}={}){return{passive:e,capture:t}},transform(e){return e}},vL=["target","eventOptions","window","enabled","transform"];function oh(e={},t){const n={};for(const[r,o]of Object.entries(t))switch(typeof o){case"function":n[r]=o.call(n,e[r],r,e);break;case"object":n[r]=oh(e[r],o);break;case"boolean":o&&(n[r]=e[r]);break}return n}function xL(e,t,n={}){const r=e,{target:o,eventOptions:s,window:i,enabled:a,transform:l}=r,c=yL(r,vL);if(n.shared=oh({target:o,eventOptions:s,window:i,enabled:a,transform:l},SL),t){const u=Ny.get(t);n[t]=oh(ct({shared:n.shared},c),u)}else for(const u in c){const d=Ny.get(u);d&&(n[u]=oh(ct({shared:n.shared},c[u]),d))}return n}class WE{constructor(t,n){Xt(this,"_listeners",new Set),this._ctrl=t,this._gestureKey=n}add(t,n,r,o,s){const i=this._listeners,a=N3(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ct(ct({},l),s);t.addEventListener(a,o,c);const u=()=>{t.removeEventListener(a,o,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(t=>t()),this._listeners.clear()}}class wL{constructor(){Xt(this,"_timeouts",new Map)}add(t,n,r=140,...o){this.remove(t),this._timeouts.set(t,window.setTimeout(n,r,...o))}remove(t){const n=this._timeouts.get(t);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(t=>void window.clearTimeout(t)),this._timeouts.clear()}}class bL{constructor(t){Xt(this,"gestures",new Set),Xt(this,"_targetEventStore",new WE(this)),Xt(this,"gestureEventStores",{}),Xt(this,"gestureTimeoutStores",{}),Xt(this,"handlers",{}),Xt(this,"config",{}),Xt(this,"pointerIds",new Set),Xt(this,"touchIds",new Set),Xt(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),PL(this,t)}setEventIds(t){if(zE(t))return this.touchIds=new Set(U3(t)),this.touchIds;if("pointerId"in t)return t.type==="pointerup"||t.type==="pointercancel"?this.pointerIds.delete(t.pointerId):t.type==="pointerdown"&&this.pointerIds.add(t.pointerId),this.pointerIds}applyHandlers(t,n){this.handlers=t,this.nativeHandlers=n}applyConfig(t,n){this.config=xL(t,n,this.config)}clean(){this._targetEventStore.clean();for(const t of this.gestures)this.gestureEventStores[t].clean(),this.gestureTimeoutStores[t].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...t){const n=this.config.shared,r={};let o;if(!(n.target&&(o=n.target(),!o))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=wb(r,a.eventOptions,!!o);if(a.enabled){const c=qv.get(i);new c(this,t,i).bind(l)}}const s=wb(r,n.eventOptions,!!o);for(const i in this.nativeHandlers)s(i,"",a=>this.nativeHandlers[i](ct(ct({},this.state.shared),{},{event:a,args:t})),void 0,!0)}for(const s in r)r[s]=V3(...r[s]);if(!o)return r;for(const s in r){const{device:i,capture:a,passive:l}=F3(s);this._targetEventStore.add(o,i,"",r[s],{capture:a,passive:l})}}}}function Ji(e,t){e.gestures.add(t),e.gestureEventStores[t]=new WE(e,t),e.gestureTimeoutStores[t]=new wL}function PL(e,t){t.drag&&Ji(e,"drag"),t.wheel&&Ji(e,"wheel"),t.scroll&&Ji(e,"scroll"),t.move&&Ji(e,"move"),t.pinch&&Ji(e,"pinch"),t.hover&&Ji(e,"hover")}const wb=(e,t,n)=>(r,o,s,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:t.capture,d=(c=i.passive)!==null&&c!==void 0?c:t.passive;let p=a?r:R3(r,o,u);n&&d&&(p+="Passive"),e[p]=e[p]||[],e[p].push(s)},CL=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function IL(e){const t={},n={},r=new Set;for(let o in e)CL.test(o)?(r.add(RegExp.lastMatch),n[o]=e[o]):t[o]=e[o];return[n,t,r]}function ea(e,t,n,r,o,s){if(!e.has(n)||!qv.has(r))return;const i=n+"Start",a=n+"End",l=c=>{let u;return c.first&&i in t&&t[i](c),n in t&&(u=t[n](c)),c.last&&a in t&&t[a](c),u};o[r]=l,s[r]=s[r]||{}}function EL(e,t){const[n,r,o]=IL(e),s={};return ea(o,n,"onDrag","drag",s,t),ea(o,n,"onWheel","wheel",s,t),ea(o,n,"onScroll","scroll",s,t),ea(o,n,"onPinch","pinch",s,t),ea(o,n,"onMove","move",s,t),ea(o,n,"onHover","hover",s,t),{handlers:s,config:t,nativeHandlers:r}}function _L(e,t={},n,r){const o=Se.useMemo(()=>new bL(e),[]);if(o.applyHandlers(e,r),o.applyConfig(t,n),Se.useEffect(o.effect.bind(o)),Se.useEffect(()=>o.clean.bind(o),[]),t.target===void 0)return o.bind.bind(o)}function kL(e){return e.forEach(pL),function(n,r){const{handlers:o,nativeHandlers:s,config:i}=EL(n,r||{});return _L(o,i,void 0,s)}}const bb=10,TL=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function GE(e){let{deltaY:t,deltaX:n}=e,r=0;if(e.ctrlKey||e.altKey||e.metaKey){const o=Math.sign(e.deltaY),s=Math.abs(e.deltaY);let i=t;s>bb&&(i=bb*o),r=i/100}else e.shiftKey&&!TL&&(n=t,t=0);return{x:-n,y:-t,z:-r}}const $L=kL([gL,fL]);let ta;const ML=e=>ta===void 0?(ta=e,!1):e-ta>120&&e-ta<160?(ta=e,!0):(ta=e,!1);function AL(e){const t=z(),n=x.useMemo(()=>{let r="not sure";const o=({event:g})=>{if(!t.getInstanceState().isFocused||(r="not sure",ML(Date.now())))return;const w=t.getEditingShapeId();if(w){const C=t.getShape(w);if(C&&t.getShapeUtil(C).canScroll(C)){const P=t.getShapePageBounds(w);if(P!=null&&P.containsPoint(t.inputs.currentPagePoint))return}}Ae(g),rn(g);const S=GE(g);if(S.x===0&&S.y===0)return;const v={type:"wheel",name:"wheel",delta:S,point:new b(g.clientX,g.clientY),shiftKey:g.shiftKey,altKey:g.altKey,ctrlKey:g.metaKey||g.ctrlKey};t.dispatch(v)};let s=1,i=1,a=1,l=0;const c=new b,u=new b,d=g=>{const w=e.current;r="not sure";const{event:S,origin:v,da:C}=g;S instanceof WheelEvent||(S.target===w||w!=null&&w.contains(S.target))&&(u.x=v[0],u.y=v[1],c.x=v[0],c.y=v[1],s=C[0],i=t.getZoomLevel(),t.dispatch({type:"pinch",name:"pinch_start",point:{x:v[0],y:v[1],z:t.getZoomLevel()},delta:{x:0,y:0},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey}))},p=g=>{if(g&&(r="zooming"),r==="zooming")return;const w=Math.abs(l-s),S=b.Dist(c,u);switch(r){case"not sure":{w>24?r="zooming":S>16&&(r="panning");break}case"panning":{w>64&&(r="zooming");break}}};return{onWheel:o,onPinchStart:d,onPinchEnd:g=>{const w=e.current,{event:S,origin:v,offset:C}=g;if(S instanceof WheelEvent||!(S.target===w||w!=null&&w.contains(S.target)))return;const I=C[0];r="not sure",requestAnimationFrame(()=>{t.dispatch({type:"pinch",name:"pinch_end",point:{x:v[0],y:v[1],z:I},delta:{x:v[0],y:v[1]},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey})})},onPinch:g=>{const w=e.current,{event:S,origin:v,offset:C,da:I}=g;if(S instanceof WheelEvent||!(S.target===w||w!=null&&w.contains(S.target)))return;const P=g.type==="gesturechange"||g.type==="gestureend";l=I[0];const E=v[0]-u.x,_=v[1]-u.y;switch(u.x=v[0],u.y=v[1],p(P),r){case"zooming":{a=C[0],t.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:a},delta:{x:E,y:_},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}case"panning":{t.dispatch({type:"pinch",name:"pinch",point:{x:v[0],y:v[1],z:i},delta:{x:E,y:_},shiftKey:S.shiftKey,altKey:S.altKey,ctrlKey:S.metaKey||S.ctrlKey});break}}}}},[t,e]);$L(n,{target:e,eventOptions:{passive:!1},pinch:{from:()=>[t.getZoomLevel(),0],scaleBounds:()=>({from:t.getZoomLevel(),max:8,min:.05})}})}function jg(e,t,n){const r=e.getShape(t),o=e.getShapeHandles(r);return{shape:r,handle:o.find(s=>s.id===n)}}function jL(e,t){const n=z();return x.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=mp(l.currentTarget);pl(c,l);const{shape:u,handle:d}=jg(n,e,t);d&&n.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_down",...En(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}=jg(n,e,t);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...En(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=mp(l.currentTarget);Pu(c,l);const{shape:u,handle:d}=jg(n,e,t);d&&n.dispatch({type:"pointer",target:"handle",handle:d,shape:u,name:"pointer_up",...En(l)})}}},[n,e,t])}var YE="Expected a function",Pb=NaN,OL="[object Symbol]",DL=/^\s+|\s+$/g,RL=/^[-+]0x[0-9a-f]+$/i,LL=/^0b[01]+$/i,FL=/^0o[0-7]+$/i,NL=parseInt,zL=typeof tn=="object"&&tn&&tn.Object===Object&&tn,BL=typeof self=="object"&&self&&self.Object===Object&&self,UL=zL||BL||Function("return this")(),HL=Object.prototype,KL=HL.toString,VL=Math.max,WL=Math.min,Og=function(){return UL.Date.now()};function GL(e,t,n){var r,o,s,i,a,l,c=0,u=!1,d=!1,p=!0;if(typeof e!="function")throw new TypeError(YE);t=Cb(t)||0,Sp(n)&&(u=!!n.leading,d="maxWait"in n,s=d?VL(Cb(n.maxWait)||0,t):s,p="trailing"in n?!!n.trailing:p);function f(E){var _=r,k=o;return r=o=void 0,c=E,i=e.apply(k,_),i}function y(E){return c=E,a=setTimeout(S,t),u?f(E):i}function g(E){var _=E-l,k=E-c,$=t-_;return d?WL($,s-k):$}function w(E){var _=E-l,k=E-c;return l===void 0||_>=t||_<0||d&&k>=s}function S(){var E=Og();if(w(E))return v(E);a=setTimeout(S,g(E))}function v(E){return a=void 0,p&&r?f(E):(r=o=void 0,i)}function C(){a!==void 0&&clearTimeout(a),c=0,r=l=o=a=void 0}function I(){return a===void 0?i:v(Og())}function P(){var E=Og(),_=w(E);if(r=arguments,o=this,l=E,_){if(a===void 0)return y(l);if(d)return a=setTimeout(S,t),f(l)}return a===void 0&&(a=setTimeout(S,t)),i}return P.cancel=C,P.flush=I,P}function YL(e,t,n){var r=!0,o=!0;if(typeof e!="function")throw new TypeError(YE);return Sp(n)&&(r="leading"in n?!!n.leading:r,o="trailing"in n?!!n.trailing:o),GL(e,t,{leading:r,maxWait:t,trailing:o})}function Sp(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function XL(e){return!!e&&typeof e=="object"}function qL(e){return typeof e=="symbol"||XL(e)&&KL.call(e)==OL}function Cb(e){if(typeof e=="number")return e;if(qL(e))return Pb;if(Sp(e)){var t=typeof e.valueOf=="function"?e.valueOf():e;e=Sp(t)?t+"":t}if(typeof e!="string")return e===0?e:+e;e=e.replace(DL,"");var n=LL.test(e);return n||FL.test(e)?NL(e.slice(2),n?2:8):RL.test(e)?Pb:+e}var ZL=YL;const QL=ll(ZL),et=class et{constructor(t=0,n=0,r=0,o=0){m(this,"x",0);m(this,"y",0);m(this,"w",0);m(this,"h",0);this.x=t,this.y=n,this.w=r,this.h=o}get point(){return new b(this.x,this.y)}set point(t){this.x=t.x,this.y=t.y}get minX(){return this.x}set minX(t){this.x=t}get midX(){return this.x+this.w/2}get maxX(){return this.x+this.w}get minY(){return this.y}set minY(t){this.y=t}get midY(){return this.y+this.h/2}get maxY(){return this.y+this.h}get width(){return this.w}set width(t){this.w=t}get height(){return this.h}set height(t){this.h=t}get aspectRatio(){return this.width/this.height}get center(){return new b(this.midX,this.midY)}set center(t){this.minX=t.x-this.width/2,this.minY=t.y-this.height/2}get corners(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY)]}get cornersAndCenter(){return[new b(this.minX,this.minY),new b(this.maxX,this.minY),new b(this.maxX,this.maxY),new b(this.minX,this.maxY),this.center]}get sides(){const{corners:t}=this;return[[t[0],t[1]],[t[1],t[2]],[t[2],t[3]],[t[3],t[0]]]}get size(){return new b(this.w,this.h)}toFixed(){return this.x=rd(this.x),this.y=rd(this.y),this.w=rd(this.w),this.h=rd(this.h),this}setTo(t){return this.x=t.x,this.y=t.y,this.w=t.w,this.h=t.h,this}set(t=0,n=0,r=0,o=0){return this.x=t,this.y=n,this.w=r,this.h=o,this}expand(t){const n=Math.min(this.minX,t.minX),r=Math.min(this.minY,t.minY),o=Math.max(this.maxX,t.maxX),s=Math.max(this.maxY,t.maxY);return this.x=n,this.y=r,this.w=o-n,this.h=s-r,this}expandBy(t){return this.x-=t,this.y-=t,this.w+=t*2,this.h+=t*2,this}scale(t){return this.x/=t,this.y/=t,this.w/=t,this.h/=t,this}clone(){const{x:t,y:n,w:r,h:o}=this;return new et(t,n,r,o)}translate(t){return this.x+=t.x,this.y+=t.y,this}snapToGrid(t){const n=Math.round(this.minX/t)*t,r=Math.round(this.minY/t)*t,o=Math.round(this.maxX/t)*t,s=Math.round(this.maxY/t)*t;this.minX=n,this.minY=r,this.width=Math.max(1,o-n),this.height=Math.max(1,s-r)}collides(t){return et.Collides(this,t)}contains(t){return et.Contains(this,t)}includes(t){return et.Includes(this,t)}containsPoint(t,n=0){return et.ContainsPoint(this,t,n)}getHandlePoint(t){switch(t){case"top_left":return new b(this.minX,this.minY);case"top_right":return new b(this.maxX,this.minY);case"bottom_left":return new b(this.minX,this.maxY);case"bottom_right":return new b(this.maxX,this.maxY);case"top":return new b(this.midX,this.minY);case"right":return new b(this.maxX,this.midY);case"bottom":return new b(this.midX,this.maxY);case"left":return new b(this.minX,this.midY)}}toJson(){return{x:this.minX,y:this.minY,w:this.w,h:this.h}}resize(t,n,r){const{minX:o,minY:s,maxX:i,maxY:a}=this;let{minX:l,minY:c,maxX:u,maxY:d}=this;switch(t){case"left":case"top_left":case"bottom_left":{l+=n;break}case"right":case"top_right":case"bottom_right":{u+=n;break}}switch(t){case"top":case"top_left":case"top_right":{c+=r;break}case"bottom":case"bottom_left":case"bottom_right":{d+=r;break}}const p=(u-l)/(i-o),f=(d-c)/(a-s),y=p<0,g=f<0;if(y){const w=u;u=l,l=w}if(g){const w=d;d=c,c=w}this.minX=l,this.minY=c,this.width=Math.abs(u-l),this.height=Math.abs(d-c)}union(t){const n=Math.min(this.minX,t.x),r=Math.min(this.minY,t.y),o=Math.max(this.maxX,t.w+t.x),s=Math.max(this.maxY,t.h+t.y);return this.x=n,this.y=r,this.width=o-n,this.height=s-r,this}static From(t){return new et(t.x,t.y,t.w,t.h)}static FromCenter(t,n){return new et(t.x-n.x/2,t.y-n.y/2,n.x,n.y)}static FromPoints(t){if(t.length===0)return new et;let n=1/0,r=1/0,o=-1/0,s=-1/0,i;for(let a=0,l=t.length;a<l;a++)i=t[a],n=Math.min(i.x,n),r=Math.min(i.y,r),o=Math.max(i.x,o),s=Math.max(i.y,s);return new et(n,r,o-n,s-r)}static Expand(t,n){const r=Math.min(n.minX,t.minX),o=Math.min(n.minY,t.minY),s=Math.max(n.maxX,t.maxX),i=Math.max(n.maxY,t.maxY);return new et(r,o,s-r,i-o)}static ExpandBy(t,n){return new et(t.minX-n,t.minY-n,t.width+n*2,t.height+n*2)}static Resize(t,n,r,o,s=!1){const{minX:i,minY:a,maxX:l,maxY:c}=t;let{minX:u,minY:d,maxX:p,maxY:f}=t;switch(n){case"left":case"top_left":case"bottom_left":{u+=r;break}case"right":case"top_right":case"bottom_right":{p+=r;break}}switch(n){case"top":case"top_left":case"top_right":{d+=o;break}case"bottom":case"bottom_left":case"bottom_right":{f+=o;break}}const y=(p-u)/(l-i),g=(f-d)/(c-a),w=y<0,S=g<0;if(s){const C=(l-i)/(c-a),I=Math.abs(p-u),P=Math.abs(f-d),E=I*(g<0?1:-1)*(1/C),_=P*(y<0?1:-1)*C,k=C<I/P;switch(n){case"top_left":{k?d=f+E:u=p+_;break}case"top_right":{k?d=f+E:p=u-_;break}case"bottom_right":{k?f=d-E:p=u-_;break}case"bottom_left":{k?f=d-E:u=p+_;break}case"bottom":case"top":{const $=(u+p)/2,T=P*C;u=$-T/2,p=$+T/2;break}case"left":case"right":{const $=(d+f)/2,T=I/C;d=$-T/2,f=$+T/2;break}}}if(w){const C=p;p=u,u=C}if(S){const C=f;f=d,d=C}const v=new et(u,d,Math.abs(p-u),Math.abs(f-d));return{box:v,scaleX:+(v.width/t.width*(y>0?1:-1)).toFixed(5),scaleY:+(v.height/t.height*(g>0?1:-1)).toFixed(5)}}equals(t){return et.Equals(this,t)}static Equals(t,n){return n.x===t.x&&n.y===t.y&&n.w===t.w&&n.h===t.h}zeroFix(){return this.w=Math.max(1,this.w),this.h=Math.max(1,this.h),this}static ZeroFix(t){return new et(t.x,t.y,Math.max(1,t.w),Math.max(1,t.h))}};m(et,"Collides",(t,n)=>!(t.maxX<n.minX||t.minX>n.maxX||t.maxY<n.minY||t.minY>n.maxY)),m(et,"Contains",(t,n)=>t.minX<n.minX&&t.minY<n.minY&&t.maxY>n.maxY&&t.maxX>n.maxX),m(et,"Includes",(t,n)=>et.Collides(t,n)||et.Contains(t,n)),m(et,"ContainsPoint",(t,n,r=0)=>!(n.x<t.minX-r||n.y<t.minY-r||n.x>t.maxX+r||n.y>t.maxY+r)),m(et,"Common",t=>{let n=1/0,r=1/0,o=-1/0,s=-1/0;for(let i=0;i<t.length;i++){const a=t[i];n=Math.min(n,a.minX),r=Math.min(r,a.minY),o=Math.max(o,a.maxX),s=Math.max(s,a.maxY)}return new et(n,r,o-n,s-r)}),m(et,"Sides",(t,n=0)=>{const{corners:r}=t;return[[r[0],r[1]],[r[1],r[2]],[r[2],r[3]],[r[3],r[0]]]});let te=et;function JL(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 e5(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 t5(e){return e==="top_left"||e==="top_right"||e==="bottom_right"||e==="bottom_left"}function n5(e){const t=z();x.useLayoutEffect(()=>{let n=new te;function r(){const c=e.current;if(!c)return null;const u=c.getBoundingClientRect(),d=new te(u.left||u.x,u.top||u.y,Math.max(u.width,1),Math.max(u.height,1));n.equals(d)||(t.updateViewportScreenBounds(d),n=d)}r();const o=QL(r,200,{trailing:!0}),s=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=r5(a),l.addEventListener("scroll",o)),()=>{clearInterval(s),window.removeEventListener("resize",o),i.disconnect(),l==null||l.removeEventListener("scroll",o)}},[t,e])}/*!
44
- * Author: excalidraw
45
- * MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
46
- * https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
47
- */const r5=e=>{let t=e.parentElement;for(;t;){if(t===document.body)return document;const{overflowY:n}=window.getComputedStyle(t);if(t.scrollHeight>t.clientHeight&&(n==="auto"||n==="scroll"||n==="overlay"))return t;t=t.parentElement}return document},Me=class Me{constructor(t,n,r,o,s,i){m(this,"a",1);m(this,"b",0);m(this,"c",0);m(this,"d",1);m(this,"e",0);m(this,"f",0);this.a=t,this.b=n,this.c=r,this.d=o,this.e=s,this.f=i}equals(t){return this.a===t.a&&this.b===t.b&&this.c===t.c&&this.d===t.d&&this.e===t.e&&this.f===t.f}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this}multiply(t){const n=t,{a:r,b:o,c:s,d:i,e:a,f:l}=this;return this.a=r*n.a+s*n.b,this.c=r*n.c+s*n.d,this.e=r*n.e+s*n.f+a,this.b=o*n.a+i*n.b,this.d=o*n.c+i*n.d,this.f=o*n.e+i*n.f+l,this}rotate(t,n,r){return t===0?this:n===void 0?this.multiply(Me.Rotate(t)):this.translate(n,r).multiply(Me.Rotate(t)).translate(-n,-r)}translate(t,n){return this.multiply(Me.Translate(t,n))}scale(t,n){return this.multiply(Me.Scale(t,n))}invert(){const{a:t,b:n,c:r,d:o,e:s,f:i}=this,a=t*o-n*r;return this.a=o/a,this.b=n/-a,this.c=r/-a,this.d=t/a,this.e=(o*s-r*i)/-a,this.f=(n*s-t*i)/a,this}applyToPoint(t){return Me.applyToPoint(this,t)}applyToPoints(t){return Me.applyToPoints(this,t)}rotation(){return Me.Rotation(this)}point(){return Me.Point(this)}decomposed(){return Me.Decompose(this)}toCssString(){return Me.toCssString(this)}setTo(t){return Object.assign(this,t),this}decompose(){return Me.Decompose(this)}clone(){return new Me(this.a,this.b,this.c,this.d,this.e,this.f)}static Identity(){return new Me(1,0,0,1,0,0)}static Translate(t,n){return new Me(1,0,0,1,t,n)}static Rotate(t,n,r){if(t===0)return Me.Identity();const o=Math.cos(t),s=Math.sin(t),i=new Me(o,s,-s,o,0,0);return n===void 0?i:Me.Compose(Me.Translate(n,r),i,Me.Translate(-n,-r))}static Multiply(t,n){return{a:t.a*n.a+t.c*n.b,c:t.a*n.c+t.c*n.d,e:t.a*n.e+t.c*n.f+t.e,b:t.b*n.a+t.d*n.b,d:t.b*n.c+t.d*n.d,f:t.b*n.e+t.d*n.f+t.f}}static Inverse(t){const n=t.a*t.d-t.b*t.c;return{a:t.d/n,b:t.b/-n,c:t.c/-n,d:t.a/n,e:(t.d*t.e-t.c*t.f)/-n,f:(t.b*t.e-t.a*t.f)/n}}static Absolute(t){const n=t.a*t.d-t.b*t.c;return{a:t.d/n,b:t.b/-n,c:t.c/-n,d:t.a/n,e:(t.d*t.e-t.c*t.f)/n,f:(t.b*t.e-t.a*t.f)/-n}}static Compose(...t){const n=Me.Identity();for(let r=0,o=t.length;r<o;r++)n.multiply(t[r]);return n}static Point(t){return new b(t.e,t.f)}static Rotation(t){let n;if(t.a!==0||t.c!==0){const r=Math.hypot(t.a,t.c);n=Math.acos(t.a/r)*(t.c>0?-1:1)}else if(t.b!==0||t.d!==0){const r=Math.hypot(t.b,t.d);n=Ge+Math.acos(t.b/r)*(t.d>0?-1:1)}else n=0;return Dy(n)}static Decompose(t){let n,r,o;if(t.a!==0||t.c!==0){const s=Math.hypot(t.a,t.c);n=s,r=(t.a*t.d-t.b*t.c)/s,o=Math.acos(t.a/s)*(t.c>0?-1:1)}else if(t.b!==0||t.d!==0){const s=Math.hypot(t.b,t.d);n=(t.a*t.d-t.b*t.c)/s,r=s,o=Ge+Math.acos(t.b/s)*(t.d>0?-1:1)}else n=0,r=0,o=0;return{x:t.e,y:t.f,scaleX:n,scaleY:r,rotation:Dy(o)}}static Smooth(t,n=1e10){return t.a=Math.round(t.a*n)/n,t.b=Math.round(t.b*n)/n,t.c=Math.round(t.c*n)/n,t.d=Math.round(t.d*n)/n,t.e=Math.round(t.e*n)/n,t.f=Math.round(t.f*n)/n,t}static toCssString(t){return`matrix(${O(t.a)}, ${O(t.b)}, ${O(t.c)}, ${O(t.d)}, ${O(t.e)}, ${O(t.f)})`}static applyToPoint(t,n){return new b(t.a*n.x+t.c*n.y+t.e,t.b*n.x+t.d*n.y+t.f,n.z)}static applyToXY(t,n,r){return[t.a*n+t.c*r+t.e,t.b*n+t.d*r+t.f]}static applyToPoints(t,n){return n.map(r=>new b(t.a*r.x+t.c*r.y+t.e,t.b*r.x+t.d*r.y+t.f,r.z))}static applyToBounds(t,n){return new te(t.e+n.minX,t.f+n.minY,n.width,n.height)}static From(t){return new Me(t.a,t.b,t.c,t.d,t.e,t.f)}static Cast(t){return t instanceof Me?t:Me.From(t)}};m(Me,"Scale",(t,n,r,o)=>{const s=new Me(t,0,0,n,0,0);return r===void 0?s:Me.Compose(Me.Translate(r,o),s,Me.Translate(-r,-o))});let ne=Me;function XE(e,t){return t===0?e:XE(t,e%t)}function qE(e){const t=e.toString().split(".")[1];if(!t)return 1;const n=Math.pow(10,t.length),r=parseInt(t,10);return n/XE(r,n)}class Li{constructor(t){m(this,"isFilled",!1);m(this,"isClosed",!0);m(this,"isLabel",!1);m(this,"debugColor");m(this,"ignore");m(this,"_vertices");m(this,"_bounds");m(this,"_area");this.isFilled=t.isFilled,this.isClosed=t.isClosed,this.isLabel=t.isLabel??!1,this.debugColor=t.debugColor,this.ignore=t.ignore}hitTestPoint(t,n=0,r=!1){return this.isClosed&&(this.isFilled||r)&&Xn(t,this.vertices)?!0:b.Dist2(t,this.nearestPoint(t))<=n*n}distanceToPoint(t,n=!1){return t.dist(this.nearestPoint(t))*(this.isClosed&&(this.isFilled||n)&&Xn(t,this.vertices)?-1:1)}distanceToLineSegment(t,n){if(t.equals(n))return this.distanceToPoint(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=b.NearestPointOnLineSegment(t,n,a,!0),i=b.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return this.isClosed&&this.isFilled&&Xn(o,this.vertices)?-s:s}hitTestLineSegment(t,n,r=0){return this.distanceToLineSegment(t,n)<=r}nearestPointOnLineSegment(t,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=b.NearestPointOnLineSegment(t,n,a,!0),i=b.Dist2(a,l),i<s&&(s=i,o=l);if(!o)throw Error("nearest point not found");return o}isPointInBounds(t,n=0){const{bounds:r}=this;return!(t.x<r.minX-n||t.y<r.minY-n||t.x>r.maxX+n||t.y>r.maxY+n)}get vertices(){return this._vertices||(this._vertices=this.getVertices()),this._vertices}getBounds(){return te.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:t}=this;let n=0;for(let r=0,o=t.length;r<o;r++){const s=t[r],i=t[(r+1)%o];n+=s.x*i.y-i.x*s.y}return n/2}toSimpleSvgPath(){let t="";const{vertices:n}=this,r=n.length;if(r===0)return t;t+=`M${n[0].x},${n[0].y}`;for(let o=1;o<r;o++)t+=`L${n[o].x},${n[o].y}`;return this.isClosed&&(t+="Z"),t}}class Fr extends Li{constructor(n){super({...n,isClosed:!0,isFilled:!1});m(this,"children",[]);m(this,"ignoredChildren",[]);for(const r of n.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(n=>!n.isLabel).flatMap(n=>n.vertices)}nearestPoint(n){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(n),a=b.Dist2(i,n),a<r&&(r=a,o=i);if(!o)throw Error("nearest point not found");return o}distanceToPoint(n,r=!1){return Math.min(...this.children.map((o,s)=>o.distanceToPoint(n,r||s>0)))}hitTestPoint(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestPoint(n,r,o))}hitTestLineSegment(n,r,o){return!!this.children.filter(s=>!s.isLabel).find(s=>s.hitTestLineSegment(n,r,o))}getArea(){return this.children[0].area}toSimpleSvgPath(){let n="";for(const o of this.children)n+=o.toSimpleSvgPath();const r=te.FromPoints(this.vertices).corners;for(let o=0,s=r.length;o<s;o++){const i=r[o],a=r[(o-1+s)%s],l=i.dist(a),c=r[(o+1)%s],u=i.dist(c),d=i.clone().lrp(a,4/l),p=i,f=i.clone().lrp(c,4/u);n+=`M${d.x},${d.y} L${p.x},${p.y} L${f.x},${f.y} `}return n}}function o5(e=!0){const[t,n]=x.useState(0),r=z();x.useEffect(()=>{if(!e)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const s5=tr(function({showStroke:t=!0,showVertices:n=!0,showClosestPointOnOutline:r=!0}){const o=z();o5(r);const s=o.getZoomLevel(),i=o.getRenderingShapes(),{inputs:{currentPagePoint:a}}=o;return h.jsx("svg",{style:{position:"absolute",pointerEvents:"none",zIndex:999999999,top:0,left:0,overflow:"visible"},children:i.map(l=>{const c=o.getShape(l.id);if(c.type==="group")return null;const u=o.getShapeGeometry(c),d=o.getShapePageTransform(c),p=o.getPointInShapeSpace(c,a),f=u.nearestPoint(p),y=u.distanceToPoint(p,!0),g=Math.abs(y)*s,w=y<0,{vertices:S}=u;return h.jsxs("g",{transform:d.toCssString(),strokeLinecap:"round",strokeLinejoin:"round",children:[t&&h.jsx(ZE,{geometry:u}),n&&S.map((v,C)=>h.jsx("circle",{cx:v.x,cy:v.y,r:"2",fill:`hsl(${tp(C,[0,S.length-1],[120,200])}, 100%, 50%)`,stroke:"black",strokeWidth:"1"},`v${C}`)),r&&g<150&&h.jsx("line",{x1:f.x,y1:f.y,x2:p.x,y2:p.y,opacity:1-g/150,stroke:w?"goldenrod":"dodgerblue",strokeWidth:"2"})]},l.id+"_outline")})})});function ZE({geometry:e}){return e instanceof Fr?h.jsx(h.Fragment,{children:[...e.children,...e.ignoredChildren].map((t,n)=>h.jsx(ZE,{geometry:t},n))}):h.jsx("path",{stroke:e.debugColor??"red",strokeWidth:"2",fill:"none",opacity:"1",d:e.toSimpleSvgPath()})}var i5=200,Zv="__lodash_hash_undefined__",a5=1/0,l5="[object Function]",c5="[object GeneratorFunction]",u5=/[\\^$.*+?()[\]{}|]/g,d5=/^\[object .+?Constructor\]$/,h5=typeof tn=="object"&&tn&&tn.Object===Object&&tn,p5=typeof self=="object"&&self&&self.Object===Object&&self,Qv=h5||p5||Function("return this")();function f5(e,t){var n=e?e.length:0;return!!n&&y5(e,t,0)>-1}function g5(e,t,n){for(var r=-1,o=e?e.length:0;++r<o;)if(n(t,e[r]))return!0;return!1}function m5(e,t,n,r){for(var o=e.length,s=n+(r?1:-1);r?s--:++s<o;)if(t(e[s],s,e))return s;return-1}function y5(e,t,n){if(t!==t)return m5(e,S5,n);for(var r=n-1,o=e.length;++r<o;)if(e[r]===t)return r;return-1}function S5(e){return e!==e}function v5(e,t){return e.has(t)}function x5(e,t){return e==null?void 0:e[t]}function w5(e){var t=!1;if(e!=null&&typeof e.toString!="function")try{t=!!(e+"")}catch{}return t}function QE(e){var t=-1,n=Array(e.size);return e.forEach(function(r){n[++t]=r}),n}var b5=Array.prototype,P5=Function.prototype,JE=Object.prototype,Dg=Qv["__core-js_shared__"],Ib=function(){var e=/[^.]+$/.exec(Dg&&Dg.keys&&Dg.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),e_=P5.toString,Jv=JE.hasOwnProperty,C5=JE.toString,I5=RegExp("^"+e_.call(Jv).replace(u5,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),E5=b5.splice,_5=e0(Qv,"Map"),Rg=e0(Qv,"Set"),Nc=e0(Object,"create");function Pi(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function k5(){this.__data__=Nc?Nc(null):{}}function T5(e){return this.has(e)&&delete this.__data__[e]}function $5(e){var t=this.__data__;if(Nc){var n=t[e];return n===Zv?void 0:n}return Jv.call(t,e)?t[e]:void 0}function M5(e){var t=this.__data__;return Nc?t[e]!==void 0:Jv.call(t,e)}function A5(e,t){var n=this.__data__;return n[e]=Nc&&t===void 0?Zv:t,this}Pi.prototype.clear=k5;Pi.prototype.delete=T5;Pi.prototype.get=$5;Pi.prototype.has=M5;Pi.prototype.set=A5;function fl(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function j5(){this.__data__=[]}function O5(e){var t=this.__data__,n=gf(t,e);if(n<0)return!1;var r=t.length-1;return n==r?t.pop():E5.call(t,n,1),!0}function D5(e){var t=this.__data__,n=gf(t,e);return n<0?void 0:t[n][1]}function R5(e){return gf(this.__data__,e)>-1}function L5(e,t){var n=this.__data__,r=gf(n,e);return r<0?n.push([e,t]):n[r][1]=t,this}fl.prototype.clear=j5;fl.prototype.delete=O5;fl.prototype.get=D5;fl.prototype.has=R5;fl.prototype.set=L5;function gl(e){var t=-1,n=e?e.length:0;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}function F5(){this.__data__={hash:new Pi,map:new(_5||fl),string:new Pi}}function N5(e){return mf(this,e).delete(e)}function z5(e){return mf(this,e).get(e)}function B5(e){return mf(this,e).has(e)}function U5(e,t){return mf(this,e).set(e,t),this}gl.prototype.clear=F5;gl.prototype.delete=N5;gl.prototype.get=z5;gl.prototype.has=B5;gl.prototype.set=U5;function vp(e){var t=-1,n=e?e.length:0;for(this.__data__=new gl;++t<n;)this.add(e[t])}function H5(e){return this.__data__.set(e,Zv),this}function K5(e){return this.__data__.has(e)}vp.prototype.add=vp.prototype.push=H5;vp.prototype.has=K5;function gf(e,t){for(var n=e.length;n--;)if(Q5(e[n][0],t))return n;return-1}function V5(e){if(!t_(e)||X5(e))return!1;var t=J5(e)||w5(e)?I5:d5;return t.test(q5(e))}function W5(e,t,n){var r=-1,o=f5,s=e.length,i=!0,a=[],l=a;if(n)i=!1,o=g5;else if(s>=i5){var c=t?null:G5(e);if(c)return QE(c);i=!1,o=v5,l=new vp}else l=t?[]:a;e:for(;++r<s;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,i&&d===d){for(var p=l.length;p--;)if(l[p]===d)continue e;t&&l.push(d),a.push(u)}else o(l,d,n)||(l!==a&&l.push(d),a.push(u))}return a}var G5=Rg&&1/QE(new Rg([,-0]))[1]==a5?function(e){return new Rg(e)}:eF;function mf(e,t){var n=e.__data__;return Y5(t)?n[typeof t=="string"?"string":"hash"]:n.map}function e0(e,t){var n=x5(e,t);return V5(n)?n:void 0}function Y5(e){var t=typeof e;return t=="string"||t=="number"||t=="symbol"||t=="boolean"?e!=="__proto__":e===null}function X5(e){return!!Ib&&Ib in e}function q5(e){if(e!=null){try{return e_.call(e)}catch{}try{return e+""}catch{}}return""}function Z5(e){return e&&e.length?W5(e):[]}function Q5(e,t){return e===t||e!==e&&t!==t}function J5(e){var t=t_(e)?C5.call(e):"";return t==l5||t==c5}function t_(e){var t=typeof e;return!!e&&(t=="object"||t=="function")}function eF(){}var tF=Z5;const nF=ll(tF);function n_(e){return nF(e)}function rF(){const e=z(),t=x.useMemo(()=>e.store.query.records("instance_presence",()=>({userId:{neq:e.user.getId()}})),[e]),n=MI("userIds",()=>n_(t.get().map(r=>r.userId)).sort(),{isEqual:(r,o)=>{var s;return r.join(",")===((s=o.join)==null?void 0:s.call(o,","))}},[t]);return K(n)}function r_(e){const t=z(),n=x.useMemo(()=>t.store.query.records("instance_presence",()=>({userId:{eq:e}})),[t,e]);return K(`latestPresence:${e}`,()=>n.get().slice().sort((o,s)=>s.lastActivityTimestamp-o.lastActivityTimestamp)[0],[])??null}const oF=tr(function(){const t=rF();return h.jsx(h.Fragment,{children:t.map(n=>h.jsx(sF,{collaboratorId:n},n))})}),sF=tr(function({collaboratorId:t}){const n=z(),r=r_(t),o=aF(r);if(!(r&&r.currentPageId===n.getCurrentPageId()))return null;switch(o){case"inactive":{const{followingUserId:s,highlightedUserIds:i}=n.getInstanceState();if(!(s===r.userId||i.includes(r.userId)))return null;break}case"idle":{const{highlightedUserIds:s}=n.getInstanceState();if(r.followingUserId===n.user.getId()&&!(r.chatMessage||s.includes(r.userId)))return null;break}}return h.jsx(iF,{latestPresence:r})}),iF=tr(function({latestPresence:t}){const n=z(),{CollaboratorBrush:r,CollaboratorScribble:o,CollaboratorCursor:s,CollaboratorHint:i,CollaboratorShapeIndicator:a}=ht(),l=n.getZoomLevel(),c=n.getViewportPageBounds(),{userId:u,chatMessage:d,brush:p,scribbles:f,selectedShapeIds:y,userName:g,cursor:w,color:S}=t,v=!(w.x<c.minX-12/l||w.y<c.minY-16/l||w.x>c.maxX-12/l||w.y>c.maxY-16/l);return h.jsxs(h.Fragment,{children:[p&&r?h.jsx(r,{className:"tl-collaborator__brush",brush:p,color:S,opacity:.1},u+"_brush"):null,v&&s?h.jsx(s,{className:"tl-collaborator__cursor",point:w,color:S,zoom:l,name:g!=="New User"?g:null,chatMessage:d},u+"_cursor"):i?h.jsx(i,{className:"tl-collaborator__cursor-hint",point:w,color:S,zoom:l,viewport:c},u+"_cursor_hint"):null,o&&f.length?h.jsx(h.Fragment,{children:f.map(C=>h.jsx(o,{className:"tl-collaborator__scribble",scribble:C,color:S,zoom:l,opacity:C.color==="laser"?.5:.1},u+"_scribble_"+C.id))}):null,a&&y.map(C=>h.jsx(a,{className:"tl-collaborator__shape-indicator",shapeId:C,color:S,opacity:.5},u+"_"+C))]})});function Eb(e){return e>d3?"inactive":e>OE?"idle":"active"}function aF(e){const t=x.useRef((e==null?void 0:e.lastActivityTimestamp)??-1),[n,r]=x.useState(()=>Eb(Date.now()-t.current));return x.useEffect(()=>{const o=setInterval(()=>{r(Eb(Date.now()-t.current))},h3);return()=>clearInterval(o)},[]),e&&(t.current=e.lastActivityTimestamp),n}const o_=x.memo(function({id:t,shape:n,util:r,index:o,backgroundIndex:s,opacity:i,dprMultiple:a}){const l=z(),{ShapeErrorFallback:c}=ht(),u=x.useRef(null),d=x.useRef(null),p=x.useRef({transform:"",clipPath:"none",width:0,height:0,x:0,y:0,isCulled:!1});Mo("set shape stuff",()=>{const y=l.getShape(t);if(!y)return;const g=p.current,w=l.getShapeClipPath(t)??"none";w!==g.clipPath&&(Gt(u.current,"clip-path",w),Gt(d.current,"clip-path",w),g.clipPath=w);const S=l.getShapePageTransform(t),v=ne.toCssString(S),C=l.getShapeGeometry(y).bounds;v!==g.transform&&(Gt(u.current,"transform",v),Gt(d.current,"transform",v),g.transform=v);const I=C.w%a,P=C.h%a,E=I===0?C.w:C.w+(a-I),_=P===0?C.h:C.h+(a-P);(E!==g.width||_!==g.height)&&(Gt(u.current,"width",Math.max(E,a)+"px"),Gt(u.current,"height",Math.max(_,a)+"px"),Gt(d.current,"width",Math.max(E,a)+"px"),Gt(d.current,"height",Math.max(_,a)+"px"),g.width=E,g.height=_)},[l]),Mo("set opacity and z-index",()=>{const y=u.current,g=d.current;Gt(y,"opacity",i),Gt(g,"opacity",i),Gt(y,"z-index",o),Gt(g,"z-index",s)},[i,o,s]),Mo("set display",()=>{if(!l.getShape(t))return;const w=l.getCulledShapes().has(t);w!==p.current.isCulled&&(Gt(u.current,"display",w?"none":"block"),Gt(d.current,"display",w?"none":"block"),p.current.isCulled=w)},[l]);const f=x.useCallback(y=>l.annotateError(y,{origin:"shape",willCrashApp:!1}),[l]);return n?h.jsxs(h.Fragment,{children:[r.backgroundComponent&&h.jsx("div",{ref:d,className:"tl-shape tl-shape-background","data-shape-type":n.type,draggable:!1,children:h.jsx(Lc,{fallback:c,onError:f,children:h.jsx(cF,{shape:n,util:r})})}),h.jsx("div",{ref:u,className:"tl-shape","data-shape-type":n.type,draggable:!1,children:h.jsx(Lc,{fallback:c,onError:f,children:h.jsx(lF,{shape:n,util:r})})})]}):null}),lF=x.memo(function({shape:t,util:n}){return cf("InnerShape:"+t.type,()=>n.component(t))},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta),cF=x.memo(function({shape:t,util:n}){return cf("InnerShape:"+t.type,()=>{var r;return(r=n.backgroundComponent)==null?void 0:r.call(n,t)})},(e,t)=>e.shape.props===t.shape.props&&e.shape.meta===t.shape.meta);function uF({className:e}){const t=z(),{Background:n,SvgDefs:r}=ht(),o=x.useRef(null),s=x.useRef(null),i=x.useRef(null),a=ln();n5(o),E3(),C3(),AL(o),T3(o);const l=x.useRef({lodDisableTextOutline:!1,allowTextOutline:!0});Mo("position layers",function(){const{x:w,y:S,z:v}=t.getCamera();if(l.current.allowTextOutline&&t.environment.isSafari&&(a.style.setProperty("--tl-text-outline","none"),l.current.allowTextOutline=!1),l.current.allowTextOutline&&v<ub!==l.current.lodDisableTextOutline){const P=v<ub;a.style.setProperty("--tl-text-outline",P?"none":`0 var(--b) 0 var(--color-background), 0 var(--a) 0 var(--color-background),
48
- var(--b) var(--b) 0 var(--color-background), var(--a) var(--b) 0 var(--color-background),
49
- var(--a) var(--a) 0 var(--color-background), var(--b) var(--a) 0 var(--color-background)`),l.current.lodDisableTextOutline=P}const C=v>=1?tp(v,[1,8],[.125,.5],!0):tp(v,[.1,1],[-2,.125],!0),I=`scale(${O(v)}) translate(${O(w+C)}px,${O(S+C)}px)`;Gt(s.current,"transform",I),Gt(i.current,"transform",I)},[t,a]);const c=P3(),u=K("shapeSvgDefs",()=>{const g=new Map;for(const w of at(t.shapeUtils)){if(!w)return;const S=w.getCanvasSvgDefs();for(const{key:v,component:C}of S)g.has(v)||g.set(v,h.jsx(C,{},v))}return[...g.values()]},[t]),d=K("debug_shapes",()=>Tt.hideShapes.get(),[Tt]),p=K("debug_svg",()=>Tt.debugSvg.get(),[Tt]),f=K("debug_geometry",()=>Tt.debugGeometry.get(),[Tt]),y=K("isEditingAnything",()=>t.getEditingShapeId()!==null,[t]);return h.jsxs("div",{ref:o,draggable:!1,"data-iseditinganything":y,className:ue("tl-canvas",e),"data-testid":"canvas",...c,children:[h.jsx("svg",{className:"tl-svg-context",children:h.jsxs("defs",{children:[u,h.jsx(CF,{}),h.jsx(IF,{}),r&&h.jsx(r,{})]})}),n&&h.jsx("div",{className:"tl-background__wrapper",children:h.jsx(n,{})}),h.jsx(dF,{}),h.jsxs("div",{ref:s,className:"tl-html-layer tl-shapes",draggable:!1,children:[h.jsx(TF,{}),h.jsx(kF,{}),d?null:p?h.jsx(vF,{}):h.jsx(wF,{})]}),h.jsxs("div",{className:"tl-overlays",children:[h.jsxs("div",{ref:i,className:"tl-html-layer",children:[f?h.jsx(s5,{}):null,h.jsx(mF,{}),h.jsx(pF,{}),h.jsx(hF,{}),h.jsx(fF,{}),h.jsx(bF,{}),h.jsx(PF,{}),h.jsx(gF,{}),h.jsx(_F,{}),h.jsx(oF,{})]}),h.jsx($F,{})]}),h.jsx(MF,{})]})}function dF(){const e=z(),t=K("gridSize",()=>e.getDocumentSettings().gridSize,[e]),{x:n,y:r,z:o}=K("camera",()=>e.getCamera(),[e]),s=K("isGridMode",()=>e.getInstanceState().isGridMode,[e]),{Grid:i}=ht();return i&&s?h.jsx(i,{x:n,y:r,z:o,size:t}):null}function hF(){const e=z(),t=K("scribbles",()=>e.getInstanceState().scribbles,[e]),n=K("zoomLevel",()=>e.getZoomLevel(),[e]),{Scribble:r}=ht();return r&&t.length?h.jsx(h.Fragment,{children:t.map(o=>h.jsx(r,{className:"tl-user-scribble",scribble:o,zoom:n},o.id))}):null}function pF(){const e=z(),t=K("brush",()=>e.getInstanceState().brush,[e]),{Brush:n}=ht();return n&&t?h.jsx(n,{className:"tl-user-brush",brush:t}):null}function fF(){const e=z(),t=K("zoomBrush",()=>e.getInstanceState().zoomBrush,[e]),{ZoomBrush:n}=ht();return n&&t?h.jsx(n,{className:"tl-user-brush tl-zoom-brush",brush:t}):null}function gF(){const e=z(),t=K("snapLines",()=>e.snaps.getIndicators(),[e]),n=K("zoomLevel",()=>e.getZoomLevel(),[e]),{SnapIndicator:r}=ht();return r&&t.length>0?h.jsx(h.Fragment,{children:t.map(o=>h.jsx(r,{className:"tl-user-snapline",line:o,zoom:n},o.id))}):null}function mF(){const e=z(),t=K("handles shapeIdWithHandles",()=>{const{isReadonly:n,isChangingStyle:r}=e.getInstanceState();if(n||r)return!1;const o=e.getOnlySelectedShape();return!o||!e.getShapeHandles(o)?!1:o.id},[e]);return t?h.jsx(yF,{shapeId:t}):null}function yF({shapeId:e}){const t=z(),{Handles:n}=ht(),r=K("zoomLevel",()=>t.getZoomLevel(),[t]),o=K("coarse pointer",()=>t.getInstanceState().isCoarsePointer,[t]),s=K("handles transform",()=>t.getShapePageTransform(e),[t,e]),i=K("handles",()=>{const a=t.getShapeHandles(e);if(!a)return null;const l=(o?DE:RE)/r*2;return a.filter(c=>c.type!=="virtual"||!a.some(u=>u!==c&&u.type==="vertex"&&b.Dist(c,u)<l)).sort(c=>c.type==="vertex"?1:-1)},[t,r,o,e]);return!n||!i||!s?null:h.jsx(n,{children:h.jsx("g",{transform:ne.toCssString(s),children:i.map(a=>h.jsx(SF,{shapeId:e,handle:a,zoom:r,isCoarse:o},a.id))})})}function SF({shapeId:e,handle:t,zoom:n,isCoarse:r}){const o=jL(e,t.id),{Handle:s}=ht();return s?h.jsx("g",{"aria-label":"handle",transform:`translate(${t.x}, ${t.y})`,...o,children:h.jsx(s,{shapeId:e,handle:t,zoom:n,isCoarse:r})}):null}function vF(){const e=z(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=K("dpr multiple",()=>qE(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsx(h.Fragment,{children:t.map(r=>h.jsxs(x.Fragment,{children:[h.jsx(o_,{...r,dprMultiple:n}),h.jsx(EF,{id:r.id})]},r.id+"_fragment"))})}function xF(){const e=z(),t=x.useRef(new Set);return Mo("reflow for culled shapes",()=>{const n=e.getCulledShapes();if(t.current.size===n.size&&[...n].every(o=>t.current.has(o)))return;t.current=n;const r=document.getElementsByClassName("tl-canvas");r.length!==0&&r[0].offsetHeight},[e]),null}function wF(){const e=z(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=K("dpr multiple",()=>qE(Math.floor(e.getInstanceState().devicePixelRatio*100)/100),[e]);return h.jsxs(h.Fragment,{children:[t.map(r=>h.jsx(o_,{...r,dprMultiple:n},r.id+"_shape")),e.environment.isSafari&&h.jsx(xF,{})]})}function bF(){const e=z(),t=K("rendering shapes",()=>e.getRenderingShapes(),[e]),n=x.useRef(new Set),r=K("should display selected ids",()=>{const s=n.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 n.current=i,i;for(const a of i)if(!s.has(a))return n.current=i,i;return s},[e]),{ShapeIndicator:o}=ht();return o?h.jsx(h.Fragment,{children:t.map(({id:s})=>h.jsx(o,{shapeId:s,hidden:!r.has(s)},s+"_indicator"))}):null}function PF(){const e=z(),{ShapeIndicator:t}=ht(),n=K("hinting shape ids",()=>ep(e.getHintingShapeIds()),[e]);return!n.length||!t?null:h.jsx(h.Fragment,{children:n.map(r=>h.jsx(t,{className:"tl-user-indicator__hint",shapeId:r},r+"_hinting"))})}function CF(){return h.jsxs("g",{id:"cursor",children:[h.jsxs("g",{fill:"rgba(0,0,0,.2)",transform:"translate(-11,-11)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"white",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m12 24.4219v-16.015l11.591 11.619h-6.781l-.411.124z"}),h.jsx("path",{d:"m21.0845 25.0962-3.605 1.535-4.682-11.089 3.686-1.553z"})]}),h.jsxs("g",{fill:"currentColor",transform:"translate(-12,-12)",children:[h.jsx("path",{d:"m19.751 24.4155-1.844.774-3.1-7.374 1.841-.775z"}),h.jsx("path",{d:"m13 10.814v11.188l2.969-2.866.428-.139h4.768z"})]})]})}function IF(){return h.jsx("path",{id:"cursor_hint",fill:"currentColor",d:"M -2,-5 2,0 -2,5 Z"})}function EF({id:e}){const t=z(),[n,r]=x.useState(null),o=K("is in root",()=>{const s=t.getShape(e);return(s==null?void 0:s.parentId)===t.getCurrentPageId()},[t,e]);return x.useEffect(()=>{if(!o)return;let s=null;const i=wu("shape to svg",async()=>{const a=Math.random();s=a;const c=t.isShapeOfType(e,"frame")?0:10;let u=t.getShapePageBounds(e);if(!u)return;u=u.clone().expandBy(c);const d=await t.getSvgString([e],{padding:c,background:t.getInstanceState().exportBackground});if(s!==a||!d)return;const p=`data:image/svg+xml;utf8,${encodeURIComponent(d.svg)}`;r({src:p,bounds:u})});return()=>{s=null,i()}},[t,e,o]),!o||!n?null:h.jsx("img",{src:n.src,width:n.bounds.width,height:n.bounds.height,style:{position:"absolute",top:0,left:0,transform:`translate(${n.bounds.x}px, ${n.bounds.maxY+12}px)`,outline:"1px solid black",maxWidth:"none"}})}function _F(){const e=z(),t=K("selection rotation",()=>e.getSelectionRotation(),[e]),n=K("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionForeground:r}=ht();return!n||!r?null:h.jsx(r,{bounds:n,rotation:t})}function kF(){const e=z(),t=K("selection rotation",()=>e.getSelectionRotation(),[e]),n=K("selection bounds",()=>e.getSelectionRotatedPageBounds(),[e]),{SelectionBackground:r}=ht();return!n||!r?null:h.jsx(r,{bounds:n,rotation:t})}function TF(){const{OnTheCanvas:e}=ht();return e?h.jsx(e,{}):null}function $F(){const{InFrontOfTheCanvas:e}=ht();return e?h.jsx(e,{}):null}function MF(){const e=z(),t=K("camera state",()=>e.getCameraState(),[e]);return h.jsx("div",{className:ue("tl-hit-test-blocker",{"tl-hit-test-blocker__hidden":t==="idle"})})}function AF({className:e,zoom:t,point:n,color:r,viewport:o,opacity:s=1}){const i=x.useRef(null);return hl(i,Zr(n.x,o.minX+5/t,o.maxX-5/t),Zr(n.y,o.minY+5/t,o.maxY-5/t),1/t,b.Angle(o.center,n)),h.jsxs("svg",{ref:i,className:ue("tl-overlays__item",e),children:[h.jsx("use",{href:"#cursor_hint",color:r,strokeWidth:3,stroke:"var(--color-background)"}),h.jsx("use",{href:"#cursor_hint",color:r,opacity:s})]})}const _b=x.memo(function({className:t,zoom:n,point:r,color:o,name:s,chatMessage:i}){const a=x.useRef(null);return hl(a,r==null?void 0:r.x,r==null?void 0:r.y,1/n),r?h.jsxs("div",{ref:a,className:ue("tl-overlays__item",t),children:[h.jsx("svg",{className:"tl-cursor",children:h.jsx("use",{href:"#cursor",color:o})}),i?h.jsxs(h.Fragment,{children:[s&&h.jsx("div",{className:"tl-nametag-title",style:{color:o},children:s}),h.jsx("div",{className:"tl-nametag-chat",style:{backgroundColor:o},children:i})]}):s&&h.jsx("div",{className:"tl-nametag",style:{backgroundColor:o},children:s})]}):null});function jF({x:e,y:t,z:n,size:r}){return h.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg",children:[h.jsx("defs",{children:lb.map(({min:o,mid:s,step:i},a)=>{const l=i*r*n,c=.5+e*n,u=.5+t*n,d=c>0?c%l:l+c%l,p=u>0?u%l:l+u%l,f=n<s?tp(n,[o,s],[0,1]):1;return h.jsx("pattern",{id:`grid-${i}`,width:l,height:l,patternUnits:"userSpaceOnUse",children:h.jsx("circle",{className:"tl-grid-dot",cx:d,cy:p,r:1,opacity:f})},`grid-pattern-${a}`)})}),lb.map(({step:o},s)=>h.jsx("rect",{width:"100%",height:"100%",fill:`url(#grid-${o})`},`grid-rect-${s}`))]})}function OF({handle:e,isCoarse:t,className:n,zoom:r}){const o=(t?DE:RE)/r;if(e.type==="clone"){const i=3/Math.max(r,.35),a=`M0,${-i} A${i},${i} 0 0,1 0,${i}`,l=y3.indexOf(e.id);return h.jsxs("g",{className:ue(`tl-handle tl-handle__${e.type}`,n),children:[h.jsx("circle",{className:"tl-handle__bg",r:o}),h.jsx("path",{className:"tl-handle__fg",d:a,transform:`rotate(${-90+90*l})`})]})}const s=(e.type==="create"&&t?3:4)/Math.max(r,.35);return h.jsxs("g",{className:ue(`tl-handle tl-handle__${e.type}`,n),children:[h.jsx("circle",{className:"tl-handle__bg",r:o}),h.jsx("circle",{className:"tl-handle__fg",r:s})]})}const DF=({children:e})=>h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e});function t0(e,t=!0){const n=e.length;if(n<2)return"";let r=e[0],o=e[1];if(n===2)return`M${Ft(r)}L${Ft(o)}`;let s="";for(let i=2,a=n-1;i<a;i++)r=e[i],o=e[i+1],s+=Pn(r,o);return t?`M${Pn(e[0],e[1])}Q${Ft(e[1])}${Pn(e[1],e[2])}T${s}${Pn(e[n-1],e[0])}${Pn(e[0],e[1])}Z`:`M${Ft(e[0])}Q${Ft(e[1])}${Pn(e[1],e[2])}${e.length>3?"T":""}${s}L${Ft(e[n-1])}`}function kb({scribble:e,zoom:t,color:n,opacity:r,className:o}){return e.points.length?h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:t0(e.points,!1),stroke:n??`var(--color-${e.color})`,fill:"none",strokeWidth:8/t,opacity:r??e.opacity})}):null}function s_({bounds:e,rotation:t}){const n=x.useRef(null);return hl(n,e.x,e.y,1,t),x.useLayoutEffect(()=>{const r=n.current;r&&(r.style.width=O(Math.max(1,e.width))+"px",r.style.height=O(Math.max(1,e.height))+"px")},[e.width,e.height]),h.jsx("div",{ref:n,className:"tl-selection__bg",draggable:!1})}function RF({bounds:e,rotation:t}){const n=z(),r=x.useRef(null),o=K("only selected shape",()=>n.getOnlySelectedShape(),[n]),s=o?n.getShapeUtil(o).expandSelectionOutlinePx(o):0;return hl(r,e==null?void 0:e.x,e==null?void 0:e.y,1,t,{x:-s,y:-s}),e=e.clone().expandBy(s).zeroFix(),h.jsx("svg",{ref:r,className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsx("rect",{className:ue("tl-selection__fg__outline"),width:O(e.width),height:O(e.height)})})}const LF=()=>h.jsx("div",{className:"tl-shape-error-boundary"}),FF=({shape:e,util:t})=>cf("Indicator: "+e.type,()=>t.indicator(e)),NF=({editor:e,id:t})=>{const n=K("shape for indicator",()=>e.store.get(t),[e,t]),{ShapeIndicatorErrorFallback:r}=ht();return!n||n.isLocked?null:h.jsx(Lc,{fallback:r,onError:o=>e.annotateError(o,{origin:"react.shapeIndicator",willCrashApp:!1}),children:h.jsx(FF,{shape:n,util:e.getShapeUtil(n)},n.id)})},Tb=x.memo(function({shapeId:t,className:n,color:r,hidden:o,opacity:s}){const i=z(),a=x.useRef(null);return Mo("indicator transform",()=>{const l=a.current;if(!l)return;const c=i.getShapePageTransform(t);c&&l.style.setProperty("transform",c.toCssString())},[i,t]),x.useLayoutEffect(()=>{const l=a.current;l&&l.style.setProperty("display",o?"none":"block")},[o]),h.jsx("svg",{ref:a,className:ue("tl-overlays__item",n),children:h.jsx("g",{className:"tl-shape-indicator",stroke:r??"var(--color-selected)",opacity:s,children:h.jsx(NF,{editor:i,id:t})})})}),zF=()=>h.jsx("circle",{cx:4,cy:4,r:8,strokeWidth:"1",stroke:"red"});function BF({points:e,zoom:t}){const n=2.5/t,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,d;return a?(l=r,c=s,u=o,d=i):(l=r,c=i,u=o,d=s),h.jsxs("g",{className:"tl-snap-indicator",stroke:"lime",children:[h.jsx("line",{x1:l,y1:c,x2:u,y2:d}),e.map((p,f)=>h.jsx("g",{transform:`translate(${p.x},${p.y})`,children:h.jsx("path",{className:"tl-snap-point",d:`M ${-n},${-n} L ${n},${n} M ${-n},${n} L ${n},${-n}`})},f))]})}function UF({gaps:e,direction:t,zoom:n}){const r=3.5/n;let o=[-1/0,1/0],s=null;const i=t==="horizontal";for(const l of e){if(s=Er(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=Er(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 h.jsx("g",{className:"tl-snap-indicator",stroke:"cyan",children:e.map(({startEdge:l,endEdge:c},u)=>h.jsx(x.Fragment,{children:i?h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:l[0].x,y1:a-2*r,x2:l[1].x,y2:a+2*r}),h.jsx("line",{x1:c[0].x,y1:a-2*r,x2:c[1].x,y2:a+2*r}),h.jsx("line",{x1:l[0].x,y1:a,x2:c[0].x,y2:a}),h.jsx("line",{x1:(l[0].x+c[0].x)/2,y1:a-r,x2:(l[0].x+c[0].x)/2,y2:a+r})]}):h.jsxs(h.Fragment,{children:[h.jsx("line",{x1:a-2*r,y1:l[0].y,x2:a+2*r,y2:l[1].y}),h.jsx("line",{x1:a-2*r,y1:c[0].y,x2:a+2*r,y2:c[1].y}),h.jsx("line",{x1:a,y1:l[0].y,x2:a,y2:c[0].y}),h.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 HF({className:e,line:t,zoom:n}){return h.jsx("svg",{className:ue("tl-overlays__item",e),children:t.type==="points"?h.jsx(BF,{...t,zoom:n}):t.type==="gaps"?h.jsx(UF,{...t,zoom:n}):null})}function KF(){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"var(--color-text-1)"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"var(--color-text-1)",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const VF=()=>null;function i_(e,t){const n=x.useRef(e);return t(e,n.current)?n.current:(n.current=e,e)}function zy(e){return i_(e,bD)}function n0(e){return i_(e,OI)}const a_=x.createContext({});function WF({overrides:e={},children:t}){const n=n0(e);return h.jsx(a_.Provider,{value:x.useMemo(()=>({Background:qR,SvgDefs:VF,Brush:od,ZoomBrush:od,ScreenshotBrush:od,CollaboratorBrush:od,Cursor:_b,CollaboratorCursor:_b,CollaboratorHint:AF,CollaboratorShapeIndicator:Tb,Grid:jF,Scribble:kb,SnapIndicator:HF,Handles:DF,Handle:OF,CollaboratorScribble:kb,ErrorFallback:c_,ShapeErrorFallback:LF,ShapeIndicatorErrorFallback:zF,Spinner:KF,SelectionBackground:s_,SelectionForeground:RF,ShapeIndicator:Tb,OnTheCanvas:null,InFrontOfTheCanvas:null,Canvas:uF,...n}),[n]),children:t})}function ht(){return x.useContext(a_)}const r0={openWindow:(e,t)=>window.open(e,t,"noopener noreferrer"),refreshPage:()=>window.location.reload(),hardReset:async()=>{var e;return await((e=window.__tldraw__hardReset)==null?void 0:e.call(window))}};function l_(){r0.hardReset()}function GF(){r0.refreshPage()}const YF="https://github.com/tldraw/tldraw/issues/new";function XF(){}const c_=({error:e,editor:t})=>{const n=x.useRef(null),[r,o]=x.useState(!1),[s,i]=x.useState(!1),[a,l]=x.useState(!1),{Canvas:c}=ht(),u=e instanceof Error?e.message:String(e),d=e instanceof Error?e.stack:null,p=K("isDarkMode",()=>{try{if(t)return t.user.getIsDarkMode()}catch{}return null},[t]),[f,y]=x.useState(null);x.useLayoutEffect(()=>{var P;p!==null&&y(p);let C=(P=n.current)==null?void 0:P.parentElement,I=!1;for(;C;){if(C.classList.contains("tl-theme__dark")||C.classList.contains("tl-theme__light")){I=!0;break}C=C.parentElement}if(I){y(null);return}y(window.matchMedia("(prefers-color-scheme: dark)").matches)},[p]),x.useEffect(()=>{if(s){const C=setTimeout(()=>{i(!1)},2e3);return()=>clearTimeout(C)}},[s]);const g=()=>{const C=document.createElement("textarea");C.value=d??u,document.body.appendChild(C),C.select(),document.execCommand("copy"),C.remove(),i(!0)},w=()=>{GF()},S=async()=>{l_()},v=new URL(YF);return v.searchParams.set("title",u),v.searchParams.set("labels","bug"),v.searchParams.set("body",`Hey, I ran into an error while using tldraw:
50
-
51
- \`\`\`js
52
- ${d??u}
53
- \`\`\`
54
-
55
- My browser: ${navigator.userAgent}`),h.jsxs("div",{ref:n,className:ue("tl-container tl-error-boundary",f===null?"":f?"tl-theme__dark":"tl-theme__light"),children:[h.jsx("div",{className:"tl-error-boundary__overlay"}),t&&h.jsx(ME,{onError:XF,fallback:()=>null,children:h.jsx(ff.Provider,{value:t,children:h.jsx("div",{className:"tl-overlay tl-error-boundary__canvas",children:c?h.jsx(c,{}):null})})}),h.jsx("div",{className:ue("tl-modal","tl-error-boundary__content",{"tl-error-boundary__content__expanded":r&&!a}),children:a?h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Are you sure?"}),h.jsx("p",{children:"Resetting your data will delete your drawing and cannot be undone."}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>l(!1),children:"Cancel"}),h.jsx("button",{className:"tl-error-boundary__reset",onClick:S,children:"Reset data"})]})]}):h.jsxs(h.Fragment,{children:[h.jsx("h2",{children:"Something's gone wrong."}),h.jsxs("p",{children:["Sorry, we encountered an error. Please refresh the page to continue. If you keep seeing this error, you can ",h.jsx("a",{href:v.toString(),children:"create a GitHub issue"})," or"," ",h.jsx("a",{href:"https://discord.gg/Cq6cPsTfNy",children:"ask for help on Discord"}),"."]}),r&&h.jsxs(h.Fragment,{children:["Message:",h.jsx("h4",{children:h.jsx("code",{children:u})}),"Stack trace:",h.jsxs("div",{className:"tl-error-boundary__content__error",children:[h.jsx("pre",{children:h.jsx("code",{children:d??u})}),h.jsx("button",{onClick:g,children:s?"Copied!":"Copy"})]})]}),h.jsxs("div",{className:"tl-error-boundary__content__actions",children:[h.jsx("button",{onClick:()=>o(!r),children:r?"Hide details":"Show details"}),h.jsxs("div",{className:"tl-error-boundary__content__actions__group",children:[h.jsx("button",{className:"tl-error-boundary__reset",onClick:()=>l(!0),children:"Reset data"}),h.jsx("button",{className:"tl-error-boundary__refresh",onClick:w,children:"Refresh Page"})]})]})]})})]})};function nt(){return uf()}const u_="TLDRAW_USER_DATA_v3",d_=xe({id:me,name:me.nullable().optional(),locale:me.nullable().optional(),color:me.nullable().optional(),isDarkMode:ve.nullable().optional(),animationSpeed:he.nullable().optional(),edgeScrollSpeed:he.nullable().optional(),isSnapMode:ve.nullable().optional(),isWrapMode:ve.nullable().optional()}),na={AddAnimationSpeed:1,AddIsSnapMode:2,MakeFieldsNullable:3,AddEdgeScrollSpeed:4,AddExcalidrawSelectMode:5},xp=Oe({currentVersion:na.AddExcalidrawSelectMode,migrators:{[na.AddAnimationSpeed]:{up:e=>({...e,animationSpeed:1}),down:({animationSpeed:e,...t})=>t},[na.AddIsSnapMode]:{up:e=>({...e,isSnapMode:!1}),down:({isSnapMode:e,...t})=>t},[na.MakeFieldsNullable]:{up:e=>e,down:e=>({id:e.id,name:e.name??bn.name,locale:e.locale??bn.locale,color:e.color??bn.color,animationSpeed:e.animationSpeed??bn.animationSpeed,isDarkMode:e.isDarkMode??bn.isDarkMode,isSnapMode:e.isSnapMode??bn.isSnapMode,isWrapMode:e.isWrapMode??bn.isWrapMode})},[na.AddEdgeScrollSpeed]:{up:e=>({...e,edgeScrollSpeed:1}),down:({edgeScrollSpeed:e,...t})=>t},[na.AddExcalidrawSelectMode]:{up:e=>({...e,isWrapMode:!1}),down:({isWrapMode:e,...t})=>t}}}),$b=["#FF802B","#EC5E41","#F2555A","#F04F88","#E34BA9","#BD54C6","#9D5BD2","#7B66DC","#02B1CC","#11B3A3","#39B178","#55B467"];function qF(){return $b[Math.floor(Math.random()*$b.length)]}function ZF(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-color-scheme: dark)"))==null?void 0:t.matches)??!1}function QF(){var e,t;return typeof window>"u"?!1:((t=(e=window.matchMedia)==null?void 0:e.call(window,"(prefers-reduced-motion: reduce)"))==null?void 0:t.matches)??!1}const bn=Object.freeze({name:"New User",locale:VR(),color:qF(),isDarkMode:!1,edgeScrollSpeed:1,animationSpeed:QF()?0:1,isSnapMode:!1,isWrapMode:!1});function id(){return{id:nt()}}function h_(e){if(e===null||typeof e!="object"||!("version"in e)||!("user"in e)||typeof e.version!="number")return id();const t=Bv({value:e.user,fromVersion:e.version,toVersion:xp.currentVersion??0,migrations:xp});if(t.type==="error")return id();try{d_.validate(t.value)}catch{return id()}return t.value}function JF(){const e=JSON.parse(Lv(u_)||"null")??null;return h_(e)}const zc=In("globalUserData",null);function e6(){Fv(u_,JSON.stringify({version:xp.currentVersion,user:zc.get()}))}function t6(e){d_.validate(e),zc.set(e),e6(),r6()}const n6=typeof process<"u"&&!1,ja=typeof BroadcastChannel<"u"&&!n6?new BroadcastChannel("tldraw-user-sync"):null;ja==null||ja.addEventListener("message",e=>{const t=e.data;(t==null?void 0:t.type)===f_&&(t==null?void 0:t.origin)!==p_()&&zc.set(h_(t.data))});let Lg=null;function p_(){return Lg===null&&(Lg=nt()),Lg}const f_="tldraw-user-preferences-change";function r6(){ja==null||ja.postMessage({type:f_,origin:p_(),data:{user:g_(),version:xp.currentVersion}})}function g_(){let e=zc.get();return e||(e=JF(),zc.set(e)),e}function m_(e={}){return{derivePresenceState:e.derivePresenceState??(()=>G("presence",()=>null)),userPreferences:e.userPreferences??G("userPreferences",()=>g_()),setUserPreferences:e.setUserPreferences??t6}}var y_={exports:{}};(function(e){var t=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function o(l,c,u){this.fn=l,this.context=c,this.once=u||!1}function s(l,c,u,d,p){if(typeof u!="function")throw new TypeError("The listener must be a function");var f=new o(u,d||l,p),y=n?n+c:c;return l._events[y]?l._events[y].fn?l._events[y]=[l._events[y],f]:l._events[y].push(f):(l._events[y]=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,d;if(this._eventsCount===0)return c;for(d in u=this._events)t.call(u,d)&&c.push(n?d.slice(1):d);return Object.getOwnPropertySymbols?c.concat(Object.getOwnPropertySymbols(u)):c},a.prototype.listeners=function(c){var u=n?n+c:c,d=this._events[u];if(!d)return[];if(d.fn)return[d.fn];for(var p=0,f=d.length,y=new Array(f);p<f;p++)y[p]=d[p].fn;return y},a.prototype.listenerCount=function(c){var u=n?n+c:c,d=this._events[u];return d?d.fn?1:d.length:0},a.prototype.emit=function(c,u,d,p,f,y){var g=n?n+c:c;if(!this._events[g])return!1;var w=this._events[g],S=arguments.length,v,C;if(w.fn){switch(w.once&&this.removeListener(c,w.fn,void 0,!0),S){case 1:return w.fn.call(w.context),!0;case 2:return w.fn.call(w.context,u),!0;case 3:return w.fn.call(w.context,u,d),!0;case 4:return w.fn.call(w.context,u,d,p),!0;case 5:return w.fn.call(w.context,u,d,p,f),!0;case 6:return w.fn.call(w.context,u,d,p,f,y),!0}for(C=1,v=new Array(S-1);C<S;C++)v[C-1]=arguments[C];w.fn.apply(w.context,v)}else{var I=w.length,P;for(C=0;C<I;C++)switch(w[C].once&&this.removeListener(c,w[C].fn,void 0,!0),S){case 1:w[C].fn.call(w[C].context);break;case 2:w[C].fn.call(w[C].context,u);break;case 3:w[C].fn.call(w[C].context,u,d);break;case 4:w[C].fn.call(w[C].context,u,d,p);break;default:if(!v)for(P=1,v=new Array(S-1);P<S;P++)v[P-1]=arguments[P];w[C].fn.apply(w[C].context,v)}}return!0},a.prototype.on=function(c,u,d){return s(this,c,u,d,!1)},a.prototype.once=function(c,u,d){return s(this,c,u,d,!0)},a.prototype.removeListener=function(c,u,d,p){var f=n?n+c:c;if(!this._events[f])return this;if(!u)return i(this,f),this;var y=this._events[f];if(y.fn)y.fn===u&&(!p||y.once)&&(!d||y.context===d)&&i(this,f);else{for(var g=0,w=[],S=y.length;g<S;g++)(y[g].fn!==u||p&&!y[g].once||d&&y[g].context!==d)&&w.push(y[g]);w.length?this._events[f]=w.length===1?w[0]:w:i(this,f)}return this},a.prototype.removeAllListeners=function(c){var u;return c?(u=n?n+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=n,a.EventEmitter=a,e.exports=a})(y_);var o6=y_.exports,S_={exports:{}},nr={},v_={exports:{}},x_={};/**
56
- * @license React
57
- * scheduler.production.min.js
58
- *
59
- * Copyright (c) Facebook, Inc. and its affiliates.
60
- *
61
- * This source code is licensed under the MIT license found in the
62
- * LICENSE file in the root directory of this source tree.
63
- */(function(e){function t(V,U){var H=V.length;V.push(U);e:for(;0<H;){var Z=H-1>>>1,ce=V[Z];if(0<o(ce,U))V[Z]=U,V[H]=ce,H=Z;else break e}}function n(V){return V.length===0?null:V[0]}function r(V){if(V.length===0)return null;var U=V[0],H=V.pop();if(H!==U){V[0]=H;e:for(var Z=0,ce=V.length,be=ce>>>1;Z<be;){var ke=2*(Z+1)-1,ae=V[ke],Te=ke+1,Re=V[Te];if(0>o(ae,H))Te<ce&&0>o(Re,ae)?(V[Z]=Re,V[Te]=H,Z=Te):(V[Z]=ae,V[ke]=H,Z=ke);else if(Te<ce&&0>o(Re,H))V[Z]=Re,V[Te]=H,Z=Te;else break e}}return U}function o(V,U){var H=V.sortIndex-U.sortIndex;return H!==0?H:V.id-U.id}if(typeof performance=="object"&&typeof performance.now=="function"){var s=performance;e.unstable_now=function(){return s.now()}}else{var i=Date,a=i.now();e.unstable_now=function(){return i.now()-a}}var l=[],c=[],u=1,d=null,p=3,f=!1,y=!1,g=!1,w=typeof setTimeout=="function"?setTimeout:null,S=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 C(V){for(var U=n(c);U!==null;){if(U.callback===null)r(c);else if(U.startTime<=V)r(c),U.sortIndex=U.expirationTime,t(l,U);else break;U=n(c)}}function I(V){if(g=!1,C(V),!y)if(n(l)!==null)y=!0,q(P);else{var U=n(c);U!==null&&Q(I,U.startTime-V)}}function P(V,U){y=!1,g&&(g=!1,S(k),k=-1),f=!0;var H=p;try{for(C(U),d=n(l);d!==null&&(!(d.expirationTime>U)||V&&!j());){var Z=d.callback;if(typeof Z=="function"){d.callback=null,p=d.priorityLevel;var ce=Z(d.expirationTime<=U);U=e.unstable_now(),typeof ce=="function"?d.callback=ce:d===n(l)&&r(l),C(U)}else r(l);d=n(l)}if(d!==null)var be=!0;else{var ke=n(c);ke!==null&&Q(I,ke.startTime-U),be=!1}return be}finally{d=null,p=H,f=!1}}var E=!1,_=null,k=-1,$=5,T=-1;function j(){return!(e.unstable_now()-T<$)}function L(){if(_!==null){var V=e.unstable_now();T=V;var U=!0;try{U=_(!0,V)}finally{U?N():(E=!1,_=null)}}else E=!1}var N;if(typeof v=="function")N=function(){v(L)};else if(typeof MessageChannel<"u"){var F=new MessageChannel,B=F.port2;F.port1.onmessage=L,N=function(){B.postMessage(null)}}else N=function(){w(L,0)};function q(V){_=V,E||(E=!0,N())}function Q(V,U){k=w(function(){V(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(V){V.callback=null},e.unstable_continueExecution=function(){y||f||(y=!0,q(P))},e.unstable_forceFrameRate=function(V){0>V||125<V?console.error("forceFrameRate takes a positive int between 0 and 125, forcing frame rates higher than 125 fps is not supported"):$=0<V?Math.floor(1e3/V):5},e.unstable_getCurrentPriorityLevel=function(){return p},e.unstable_getFirstCallbackNode=function(){return n(l)},e.unstable_next=function(V){switch(p){case 1:case 2:case 3:var U=3;break;default:U=p}var H=p;p=U;try{return V()}finally{p=H}},e.unstable_pauseExecution=function(){},e.unstable_requestPaint=function(){},e.unstable_runWithPriority=function(V,U){switch(V){case 1:case 2:case 3:case 4:case 5:break;default:V=3}var H=p;p=V;try{return U()}finally{p=H}},e.unstable_scheduleCallback=function(V,U,H){var Z=e.unstable_now();switch(typeof H=="object"&&H!==null?(H=H.delay,H=typeof H=="number"&&0<H?Z+H:Z):H=Z,V){case 1:var ce=-1;break;case 2:ce=250;break;case 5:ce=1073741823;break;case 4:ce=1e4;break;default:ce=5e3}return ce=H+ce,V={id:u++,callback:U,priorityLevel:V,startTime:H,expirationTime:ce,sortIndex:-1},H>Z?(V.sortIndex=H,t(c,V),n(l)===null&&V===n(c)&&(g?(S(k),k=-1):g=!0,Q(I,H-Z))):(V.sortIndex=ce,t(l,V),y||f||(y=!0,q(P))),V},e.unstable_shouldYield=j,e.unstable_wrapCallback=function(V){var U=p;return function(){var H=p;p=U;try{return V.apply(this,arguments)}finally{p=H}}}})(x_);v_.exports=x_;var s6=v_.exports;/**
64
- * @license React
65
- * react-dom.production.min.js
66
- *
67
- * Copyright (c) Facebook, Inc. and its affiliates.
68
- *
69
- * This source code is licensed under the MIT license found in the
70
- * LICENSE file in the root directory of this source tree.
71
- */var w_=x,er=s6;function Y(e){for(var t="https://reactjs.org/docs/error-decoder.html?invariant="+e,n=1;n<arguments.length;n++)t+="&args[]="+encodeURIComponent(arguments[n]);return"Minified React error #"+e+"; visit "+t+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var b_=new Set,Bc={};function Fi(e,t){qa(e,t),qa(e+"Capture",t)}function qa(e,t){for(Bc[e]=t,e=0;e<t.length;e++)b_.add(t[e])}var No=!(typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"),By=Object.prototype.hasOwnProperty,i6=/^[: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]*$/,Mb={},Ab={};function a6(e){return By.call(Ab,e)?!0:By.call(Mb,e)?!1:i6.test(e)?Ab[e]=!0:(Mb[e]=!0,!1)}function l6(e,t,n,r){if(n!==null&&n.type===0)return!1;switch(typeof t){case"function":case"symbol":return!0;case"boolean":return r?!1:n!==null?!n.acceptsBooleans:(e=e.toLowerCase().slice(0,5),e!=="data-"&&e!=="aria-");default:return!1}}function c6(e,t,n,r){if(t===null||typeof t>"u"||l6(e,t,n,r))return!0;if(r)return!1;if(n!==null)switch(n.type){case 3:return!t;case 4:return t===!1;case 5:return isNaN(t);case 6:return isNaN(t)||1>t}return!1}function mn(e,t,n,r,o,s,i){this.acceptsBooleans=t===2||t===3||t===4,this.attributeName=r,this.attributeNamespace=o,this.mustUseProperty=n,this.propertyName=e,this.type=t,this.sanitizeURL=s,this.removeEmptyString=i}var Ht={};"children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ").forEach(function(e){Ht[e]=new mn(e,0,!1,e,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(e){var t=e[0];Ht[t]=new mn(t,1,!1,e[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(e){Ht[e]=new mn(e,2,!1,e.toLowerCase(),null,!1,!1)});["autoReverse","externalResourcesRequired","focusable","preserveAlpha"].forEach(function(e){Ht[e]=new mn(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){Ht[e]=new mn(e,3,!1,e.toLowerCase(),null,!1,!1)});["checked","multiple","muted","selected"].forEach(function(e){Ht[e]=new mn(e,3,!0,e,null,!1,!1)});["capture","download"].forEach(function(e){Ht[e]=new mn(e,4,!1,e,null,!1,!1)});["cols","rows","size","span"].forEach(function(e){Ht[e]=new mn(e,6,!1,e,null,!1,!1)});["rowSpan","start"].forEach(function(e){Ht[e]=new mn(e,5,!1,e.toLowerCase(),null,!1,!1)});var o0=/[\-:]([a-z])/g;function s0(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 t=e.replace(o0,s0);Ht[t]=new mn(t,1,!1,e,null,!1,!1)});"xlink:actuate xlink:arcrole xlink:role xlink:show xlink:title xlink:type".split(" ").forEach(function(e){var t=e.replace(o0,s0);Ht[t]=new mn(t,1,!1,e,"http://www.w3.org/1999/xlink",!1,!1)});["xml:base","xml:lang","xml:space"].forEach(function(e){var t=e.replace(o0,s0);Ht[t]=new mn(t,1,!1,e,"http://www.w3.org/XML/1998/namespace",!1,!1)});["tabIndex","crossOrigin"].forEach(function(e){Ht[e]=new mn(e,1,!1,e.toLowerCase(),null,!1,!1)});Ht.xlinkHref=new mn("xlinkHref",1,!1,"xlink:href","http://www.w3.org/1999/xlink",!0,!1);["src","href","action","formAction"].forEach(function(e){Ht[e]=new mn(e,1,!1,e.toLowerCase(),null,!0,!0)});function i0(e,t,n,r){var o=Ht.hasOwnProperty(t)?Ht[t]:null;(o!==null?o.type!==0:r||!(2<t.length)||t[0]!=="o"&&t[0]!=="O"||t[1]!=="n"&&t[1]!=="N")&&(c6(t,n,o,r)&&(n=null),r||o===null?a6(t)&&(n===null?e.removeAttribute(t):e.setAttribute(t,""+n)):o.mustUseProperty?e[o.propertyName]=n===null?o.type===3?!1:"":n:(t=o.attributeName,r=o.attributeNamespace,n===null?e.removeAttribute(t):(o=o.type,n=o===3||o===4&&n===!0?"":""+n,r?e.setAttributeNS(r,t,n):e.setAttribute(t,n))))}var Zo=w_.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ad=Symbol.for("react.element"),fa=Symbol.for("react.portal"),ga=Symbol.for("react.fragment"),a0=Symbol.for("react.strict_mode"),Uy=Symbol.for("react.profiler"),P_=Symbol.for("react.provider"),C_=Symbol.for("react.context"),l0=Symbol.for("react.forward_ref"),Hy=Symbol.for("react.suspense"),Ky=Symbol.for("react.suspense_list"),c0=Symbol.for("react.memo"),us=Symbol.for("react.lazy"),I_=Symbol.for("react.offscreen"),jb=Symbol.iterator;function Nl(e){return e===null||typeof e!="object"?null:(e=jb&&e[jb]||e["@@iterator"],typeof e=="function"?e:null)}var pt=Object.assign,Fg;function ac(e){if(Fg===void 0)try{throw Error()}catch(n){var t=n.stack.trim().match(/\n( *(at )?)/);Fg=t&&t[1]||""}return`
72
- `+Fg+e}var Ng=!1;function zg(e,t){if(!e||Ng)return"";Ng=!0;var n=Error.prepareStackTrace;Error.prepareStackTrace=void 0;try{if(t)if(t=function(){throw Error()},Object.defineProperty(t.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(t,[])}catch(c){var r=c}Reflect.construct(e,[],t)}else{try{t.call()}catch(c){r=c}e.call(t.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(`
73
- `),s=r.stack.split(`
74
- `),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=`
75
- `+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{Ng=!1,Error.prepareStackTrace=n}return(e=e?e.displayName||e.name:"")?ac(e):""}function u6(e){switch(e.tag){case 5:return ac(e.type);case 16:return ac("Lazy");case 13:return ac("Suspense");case 19:return ac("SuspenseList");case 0:case 2:case 15:return e=zg(e.type,!1),e;case 11:return e=zg(e.type.render,!1),e;case 1:return e=zg(e.type,!0),e;default:return""}}function Vy(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 ga:return"Fragment";case fa:return"Portal";case Uy:return"Profiler";case a0:return"StrictMode";case Hy:return"Suspense";case Ky:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case C_:return(e.displayName||"Context")+".Consumer";case P_:return(e._context.displayName||"Context")+".Provider";case l0:var t=e.render;return e=e.displayName,e||(e=t.displayName||t.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case c0:return t=e.displayName||null,t!==null?t:Vy(e.type)||"Memo";case us:t=e._payload,e=e._init;try{return Vy(e(t))}catch{}}return null}function d6(e){var t=e.type;switch(e.tag){case 24:return"Cache";case 9:return(t.displayName||"Context")+".Consumer";case 10:return(t._context.displayName||"Context")+".Provider";case 18:return"DehydratedFragment";case 11:return e=t.render,e=e.displayName||e.name||"",t.displayName||(e!==""?"ForwardRef("+e+")":"ForwardRef");case 7:return"Fragment";case 5:return t;case 4:return"Portal";case 3:return"Root";case 6:return"Text";case 16:return Vy(t);case 8:return t===a0?"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 t=="function")return t.displayName||t.name||null;if(typeof t=="string")return t}return null}function js(e){switch(typeof e){case"boolean":case"number":case"string":case"undefined":return e;case"object":return e;default:return""}}function E_(e){var t=e.type;return(e=e.nodeName)&&e.toLowerCase()==="input"&&(t==="checkbox"||t==="radio")}function h6(e){var t=E_(e)?"checked":"value",n=Object.getOwnPropertyDescriptor(e.constructor.prototype,t),r=""+e[t];if(!e.hasOwnProperty(t)&&typeof n<"u"&&typeof n.get=="function"&&typeof n.set=="function"){var o=n.get,s=n.set;return Object.defineProperty(e,t,{configurable:!0,get:function(){return o.call(this)},set:function(i){r=""+i,s.call(this,i)}}),Object.defineProperty(e,t,{enumerable:n.enumerable}),{getValue:function(){return r},setValue:function(i){r=""+i},stopTracking:function(){e._valueTracker=null,delete e[t]}}}}function ld(e){e._valueTracker||(e._valueTracker=h6(e))}function __(e){if(!e)return!1;var t=e._valueTracker;if(!t)return!0;var n=t.getValue(),r="";return e&&(r=E_(e)?e.checked?"true":"false":e.value),e=r,e!==n?(t.setValue(e),!0):!1}function wp(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 Wy(e,t){var n=t.checked;return pt({},t,{defaultChecked:void 0,defaultValue:void 0,value:void 0,checked:n??e._wrapperState.initialChecked})}function Ob(e,t){var n=t.defaultValue==null?"":t.defaultValue,r=t.checked!=null?t.checked:t.defaultChecked;n=js(t.value!=null?t.value:n),e._wrapperState={initialChecked:r,initialValue:n,controlled:t.type==="checkbox"||t.type==="radio"?t.checked!=null:t.value!=null}}function k_(e,t){t=t.checked,t!=null&&i0(e,"checked",t,!1)}function Gy(e,t){k_(e,t);var n=js(t.value),r=t.type;if(n!=null)r==="number"?(n===0&&e.value===""||e.value!=n)&&(e.value=""+n):e.value!==""+n&&(e.value=""+n);else if(r==="submit"||r==="reset"){e.removeAttribute("value");return}t.hasOwnProperty("value")?Yy(e,t.type,n):t.hasOwnProperty("defaultValue")&&Yy(e,t.type,js(t.defaultValue)),t.checked==null&&t.defaultChecked!=null&&(e.defaultChecked=!!t.defaultChecked)}function Db(e,t,n){if(t.hasOwnProperty("value")||t.hasOwnProperty("defaultValue")){var r=t.type;if(!(r!=="submit"&&r!=="reset"||t.value!==void 0&&t.value!==null))return;t=""+e._wrapperState.initialValue,n||t===e.value||(e.value=t),e.defaultValue=t}n=e.name,n!==""&&(e.name=""),e.defaultChecked=!!e._wrapperState.initialChecked,n!==""&&(e.name=n)}function Yy(e,t,n){(t!=="number"||wp(e.ownerDocument)!==e)&&(n==null?e.defaultValue=""+e._wrapperState.initialValue:e.defaultValue!==""+n&&(e.defaultValue=""+n))}var lc=Array.isArray;function Oa(e,t,n,r){if(e=e.options,t){t={};for(var o=0;o<n.length;o++)t["$"+n[o]]=!0;for(n=0;n<e.length;n++)o=t.hasOwnProperty("$"+e[n].value),e[n].selected!==o&&(e[n].selected=o),o&&r&&(e[n].defaultSelected=!0)}else{for(n=""+js(n),t=null,o=0;o<e.length;o++){if(e[o].value===n){e[o].selected=!0,r&&(e[o].defaultSelected=!0);return}t!==null||e[o].disabled||(t=e[o])}t!==null&&(t.selected=!0)}}function Xy(e,t){if(t.dangerouslySetInnerHTML!=null)throw Error(Y(91));return pt({},t,{value:void 0,defaultValue:void 0,children:""+e._wrapperState.initialValue})}function Rb(e,t){var n=t.value;if(n==null){if(n=t.children,t=t.defaultValue,n!=null){if(t!=null)throw Error(Y(92));if(lc(n)){if(1<n.length)throw Error(Y(93));n=n[0]}t=n}t==null&&(t=""),n=t}e._wrapperState={initialValue:js(n)}}function T_(e,t){var n=js(t.value),r=js(t.defaultValue);n!=null&&(n=""+n,n!==e.value&&(e.value=n),t.defaultValue==null&&e.defaultValue!==n&&(e.defaultValue=n)),r!=null&&(e.defaultValue=""+r)}function Lb(e){var t=e.textContent;t===e._wrapperState.initialValue&&t!==""&&t!==null&&(e.value=t)}function $_(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 qy(e,t){return e==null||e==="http://www.w3.org/1999/xhtml"?$_(t):e==="http://www.w3.org/2000/svg"&&t==="foreignObject"?"http://www.w3.org/1999/xhtml":e}var cd,M_=function(e){return typeof MSApp<"u"&&MSApp.execUnsafeLocalFunction?function(t,n,r,o){MSApp.execUnsafeLocalFunction(function(){return e(t,n,r,o)})}:e}(function(e,t){if(e.namespaceURI!=="http://www.w3.org/2000/svg"||"innerHTML"in e)e.innerHTML=t;else{for(cd=cd||document.createElement("div"),cd.innerHTML="<svg>"+t.valueOf().toString()+"</svg>",t=cd.firstChild;e.firstChild;)e.removeChild(e.firstChild);for(;t.firstChild;)e.appendChild(t.firstChild)}});function Uc(e,t){if(t){var n=e.firstChild;if(n&&n===e.lastChild&&n.nodeType===3){n.nodeValue=t;return}}e.textContent=t}var Sc={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},p6=["Webkit","ms","Moz","O"];Object.keys(Sc).forEach(function(e){p6.forEach(function(t){t=t+e.charAt(0).toUpperCase()+e.substring(1),Sc[t]=Sc[e]})});function A_(e,t,n){return t==null||typeof t=="boolean"||t===""?"":n||typeof t!="number"||t===0||Sc.hasOwnProperty(e)&&Sc[e]?(""+t).trim():t+"px"}function j_(e,t){e=e.style;for(var n in t)if(t.hasOwnProperty(n)){var r=n.indexOf("--")===0,o=A_(n,t[n],r);n==="float"&&(n="cssFloat"),r?e.setProperty(n,o):e[n]=o}}var f6=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 Zy(e,t){if(t){if(f6[e]&&(t.children!=null||t.dangerouslySetInnerHTML!=null))throw Error(Y(137,e));if(t.dangerouslySetInnerHTML!=null){if(t.children!=null)throw Error(Y(60));if(typeof t.dangerouslySetInnerHTML!="object"||!("__html"in t.dangerouslySetInnerHTML))throw Error(Y(61))}if(t.style!=null&&typeof t.style!="object")throw Error(Y(62))}}function Qy(e,t){if(e.indexOf("-")===-1)return typeof t.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 Jy=null;function u0(e){return e=e.target||e.srcElement||window,e.correspondingUseElement&&(e=e.correspondingUseElement),e.nodeType===3?e.parentNode:e}var eS=null,Da=null,Ra=null;function Fb(e){if(e=ku(e)){if(typeof eS!="function")throw Error(Y(280));var t=e.stateNode;t&&(t=wf(t),eS(e.stateNode,e.type,t))}}function O_(e){Da?Ra?Ra.push(e):Ra=[e]:Da=e}function D_(){if(Da){var e=Da,t=Ra;if(Ra=Da=null,Fb(e),t)for(e=0;e<t.length;e++)Fb(t[e])}}function R_(e,t){return e(t)}function L_(){}var Bg=!1;function F_(e,t,n){if(Bg)return e(t,n);Bg=!0;try{return R_(e,t,n)}finally{Bg=!1,(Da!==null||Ra!==null)&&(L_(),D_())}}function Hc(e,t){var n=e.stateNode;if(n===null)return null;var r=wf(n);if(r===null)return null;n=r[t];e:switch(t){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(n&&typeof n!="function")throw Error(Y(231,t,typeof n));return n}var tS=!1;if(No)try{var zl={};Object.defineProperty(zl,"passive",{get:function(){tS=!0}}),window.addEventListener("test",zl,zl),window.removeEventListener("test",zl,zl)}catch{tS=!1}function g6(e,t,n,r,o,s,i,a,l){var c=Array.prototype.slice.call(arguments,3);try{t.apply(n,c)}catch(u){this.onError(u)}}var vc=!1,bp=null,Pp=!1,nS=null,m6={onError:function(e){vc=!0,bp=e}};function y6(e,t,n,r,o,s,i,a,l){vc=!1,bp=null,g6.apply(m6,arguments)}function S6(e,t,n,r,o,s,i,a,l){if(y6.apply(this,arguments),vc){if(vc){var c=bp;vc=!1,bp=null}else throw Error(Y(198));Pp||(Pp=!0,nS=c)}}function Ni(e){var t=e,n=e;if(e.alternate)for(;t.return;)t=t.return;else{e=t;do t=e,t.flags&4098&&(n=t.return),e=t.return;while(e)}return t.tag===3?n:null}function N_(e){if(e.tag===13){var t=e.memoizedState;if(t===null&&(e=e.alternate,e!==null&&(t=e.memoizedState)),t!==null)return t.dehydrated}return null}function Nb(e){if(Ni(e)!==e)throw Error(Y(188))}function v6(e){var t=e.alternate;if(!t){if(t=Ni(e),t===null)throw Error(Y(188));return t!==e?null:e}for(var n=e,r=t;;){var o=n.return;if(o===null)break;var s=o.alternate;if(s===null){if(r=o.return,r!==null){n=r;continue}break}if(o.child===s.child){for(s=o.child;s;){if(s===n)return Nb(o),e;if(s===r)return Nb(o),t;s=s.sibling}throw Error(Y(188))}if(n.return!==r.return)n=o,r=s;else{for(var i=!1,a=o.child;a;){if(a===n){i=!0,n=o,r=s;break}if(a===r){i=!0,r=o,n=s;break}a=a.sibling}if(!i){for(a=s.child;a;){if(a===n){i=!0,n=s,r=o;break}if(a===r){i=!0,r=s,n=o;break}a=a.sibling}if(!i)throw Error(Y(189))}}if(n.alternate!==r)throw Error(Y(190))}if(n.tag!==3)throw Error(Y(188));return n.stateNode.current===n?e:t}function z_(e){return e=v6(e),e!==null?B_(e):null}function B_(e){if(e.tag===5||e.tag===6)return e;for(e=e.child;e!==null;){var t=B_(e);if(t!==null)return t;e=e.sibling}return null}var U_=er.unstable_scheduleCallback,zb=er.unstable_cancelCallback,x6=er.unstable_shouldYield,w6=er.unstable_requestPaint,St=er.unstable_now,b6=er.unstable_getCurrentPriorityLevel,d0=er.unstable_ImmediatePriority,H_=er.unstable_UserBlockingPriority,Cp=er.unstable_NormalPriority,P6=er.unstable_LowPriority,K_=er.unstable_IdlePriority,yf=null,to=null;function C6(e){if(to&&typeof to.onCommitFiberRoot=="function")try{to.onCommitFiberRoot(yf,e,void 0,(e.current.flags&128)===128)}catch{}}var Or=Math.clz32?Math.clz32:_6,I6=Math.log,E6=Math.LN2;function _6(e){return e>>>=0,e===0?32:31-(I6(e)/E6|0)|0}var ud=64,dd=4194304;function cc(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 Ip(e,t){var n=e.pendingLanes;if(n===0)return 0;var r=0,o=e.suspendedLanes,s=e.pingedLanes,i=n&268435455;if(i!==0){var a=i&~o;a!==0?r=cc(a):(s&=i,s!==0&&(r=cc(s)))}else i=n&~o,i!==0?r=cc(i):s!==0&&(r=cc(s));if(r===0)return 0;if(t!==0&&t!==r&&!(t&o)&&(o=r&-r,s=t&-t,o>=s||o===16&&(s&4194240)!==0))return t;if(r&4&&(r|=n&16),t=e.entangledLanes,t!==0)for(e=e.entanglements,t&=r;0<t;)n=31-Or(t),o=1<<n,r|=e[n],t&=~o;return r}function k6(e,t){switch(e){case 1:case 2:case 4:return t+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 t+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 T6(e,t){for(var n=e.suspendedLanes,r=e.pingedLanes,o=e.expirationTimes,s=e.pendingLanes;0<s;){var i=31-Or(s),a=1<<i,l=o[i];l===-1?(!(a&n)||a&r)&&(o[i]=k6(a,t)):l<=t&&(e.expiredLanes|=a),s&=~a}}function rS(e){return e=e.pendingLanes&-1073741825,e!==0?e:e&1073741824?1073741824:0}function V_(){var e=ud;return ud<<=1,!(ud&4194240)&&(ud=64),e}function Ug(e){for(var t=[],n=0;31>n;n++)t.push(e);return t}function Eu(e,t,n){e.pendingLanes|=t,t!==536870912&&(e.suspendedLanes=0,e.pingedLanes=0),e=e.eventTimes,t=31-Or(t),e[t]=n}function $6(e,t){var n=e.pendingLanes&~t;e.pendingLanes=t,e.suspendedLanes=0,e.pingedLanes=0,e.expiredLanes&=t,e.mutableReadLanes&=t,e.entangledLanes&=t,t=e.entanglements;var r=e.eventTimes;for(e=e.expirationTimes;0<n;){var o=31-Or(n),s=1<<o;t[o]=0,r[o]=-1,e[o]=-1,n&=~s}}function h0(e,t){var n=e.entangledLanes|=t;for(e=e.entanglements;n;){var r=31-Or(n),o=1<<r;o&t|e[r]&t&&(e[r]|=t),n&=~o}}var Ne=0;function W_(e){return e&=-e,1<e?4<e?e&268435455?16:536870912:4:1}var G_,p0,Y_,X_,q_,oS=!1,hd=[],bs=null,Ps=null,Cs=null,Kc=new Map,Vc=new Map,fs=[],M6="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 Bb(e,t){switch(e){case"focusin":case"focusout":bs=null;break;case"dragenter":case"dragleave":Ps=null;break;case"mouseover":case"mouseout":Cs=null;break;case"pointerover":case"pointerout":Kc.delete(t.pointerId);break;case"gotpointercapture":case"lostpointercapture":Vc.delete(t.pointerId)}}function Bl(e,t,n,r,o,s){return e===null||e.nativeEvent!==s?(e={blockedOn:t,domEventName:n,eventSystemFlags:r,nativeEvent:s,targetContainers:[o]},t!==null&&(t=ku(t),t!==null&&p0(t)),e):(e.eventSystemFlags|=r,t=e.targetContainers,o!==null&&t.indexOf(o)===-1&&t.push(o),e)}function A6(e,t,n,r,o){switch(t){case"focusin":return bs=Bl(bs,e,t,n,r,o),!0;case"dragenter":return Ps=Bl(Ps,e,t,n,r,o),!0;case"mouseover":return Cs=Bl(Cs,e,t,n,r,o),!0;case"pointerover":var s=o.pointerId;return Kc.set(s,Bl(Kc.get(s)||null,e,t,n,r,o)),!0;case"gotpointercapture":return s=o.pointerId,Vc.set(s,Bl(Vc.get(s)||null,e,t,n,r,o)),!0}return!1}function Z_(e){var t=pi(e.target);if(t!==null){var n=Ni(t);if(n!==null){if(t=n.tag,t===13){if(t=N_(n),t!==null){e.blockedOn=t,q_(e.priority,function(){Y_(n)});return}}else if(t===3&&n.stateNode.current.memoizedState.isDehydrated){e.blockedOn=n.tag===3?n.stateNode.containerInfo:null;return}}}e.blockedOn=null}function sh(e){if(e.blockedOn!==null)return!1;for(var t=e.targetContainers;0<t.length;){var n=sS(e.domEventName,e.eventSystemFlags,t[0],e.nativeEvent);if(n===null){n=e.nativeEvent;var r=new n.constructor(n.type,n);Jy=r,n.target.dispatchEvent(r),Jy=null}else return t=ku(n),t!==null&&p0(t),e.blockedOn=n,!1;t.shift()}return!0}function Ub(e,t,n){sh(e)&&n.delete(t)}function j6(){oS=!1,bs!==null&&sh(bs)&&(bs=null),Ps!==null&&sh(Ps)&&(Ps=null),Cs!==null&&sh(Cs)&&(Cs=null),Kc.forEach(Ub),Vc.forEach(Ub)}function Ul(e,t){e.blockedOn===t&&(e.blockedOn=null,oS||(oS=!0,er.unstable_scheduleCallback(er.unstable_NormalPriority,j6)))}function Wc(e){function t(o){return Ul(o,e)}if(0<hd.length){Ul(hd[0],e);for(var n=1;n<hd.length;n++){var r=hd[n];r.blockedOn===e&&(r.blockedOn=null)}}for(bs!==null&&Ul(bs,e),Ps!==null&&Ul(Ps,e),Cs!==null&&Ul(Cs,e),Kc.forEach(t),Vc.forEach(t),n=0;n<fs.length;n++)r=fs[n],r.blockedOn===e&&(r.blockedOn=null);for(;0<fs.length&&(n=fs[0],n.blockedOn===null);)Z_(n),n.blockedOn===null&&fs.shift()}var La=Zo.ReactCurrentBatchConfig,Ep=!0;function O6(e,t,n,r){var o=Ne,s=La.transition;La.transition=null;try{Ne=1,f0(e,t,n,r)}finally{Ne=o,La.transition=s}}function D6(e,t,n,r){var o=Ne,s=La.transition;La.transition=null;try{Ne=4,f0(e,t,n,r)}finally{Ne=o,La.transition=s}}function f0(e,t,n,r){if(Ep){var o=sS(e,t,n,r);if(o===null)Qg(e,t,r,_p,n),Bb(e,r);else if(A6(o,e,t,n,r))r.stopPropagation();else if(Bb(e,r),t&4&&-1<M6.indexOf(e)){for(;o!==null;){var s=ku(o);if(s!==null&&G_(s),s=sS(e,t,n,r),s===null&&Qg(e,t,r,_p,n),s===o)break;o=s}o!==null&&r.stopPropagation()}else Qg(e,t,r,null,n)}}var _p=null;function sS(e,t,n,r){if(_p=null,e=u0(r),e=pi(e),e!==null)if(t=Ni(e),t===null)e=null;else if(n=t.tag,n===13){if(e=N_(t),e!==null)return e;e=null}else if(n===3){if(t.stateNode.current.memoizedState.isDehydrated)return t.tag===3?t.stateNode.containerInfo:null;e=null}else t!==e&&(e=null);return _p=e,null}function Q_(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(b6()){case d0:return 1;case H_:return 4;case Cp:case P6:return 16;case K_:return 536870912;default:return 16}default:return 16}}var ys=null,g0=null,ih=null;function J_(){if(ih)return ih;var e,t=g0,n=t.length,r,o="value"in ys?ys.value:ys.textContent,s=o.length;for(e=0;e<n&&t[e]===o[e];e++);var i=n-e;for(r=1;r<=i&&t[n-r]===o[s-r];r++);return ih=o.slice(e,1<r?1-r:void 0)}function ah(e){var t=e.keyCode;return"charCode"in e?(e=e.charCode,e===0&&t===13&&(e=13)):e=t,e===10&&(e=13),32<=e||e===13?e:0}function pd(){return!0}function Hb(){return!1}function rr(e){function t(n,r,o,s,i){this._reactName=n,this._targetInst=o,this.type=r,this.nativeEvent=s,this.target=i,this.currentTarget=null;for(var a in e)e.hasOwnProperty(a)&&(n=e[a],this[a]=n?n(s):s[a]);return this.isDefaultPrevented=(s.defaultPrevented!=null?s.defaultPrevented:s.returnValue===!1)?pd:Hb,this.isPropagationStopped=Hb,this}return pt(t.prototype,{preventDefault:function(){this.defaultPrevented=!0;var n=this.nativeEvent;n&&(n.preventDefault?n.preventDefault():typeof n.returnValue!="unknown"&&(n.returnValue=!1),this.isDefaultPrevented=pd)},stopPropagation:function(){var n=this.nativeEvent;n&&(n.stopPropagation?n.stopPropagation():typeof n.cancelBubble!="unknown"&&(n.cancelBubble=!0),this.isPropagationStopped=pd)},persist:function(){},isPersistent:pd}),t}var ml={eventPhase:0,bubbles:0,cancelable:0,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:0,isTrusted:0},m0=rr(ml),_u=pt({},ml,{view:0,detail:0}),R6=rr(_u),Hg,Kg,Hl,Sf=pt({},_u,{screenX:0,screenY:0,clientX:0,clientY:0,pageX:0,pageY:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,getModifierState:y0,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!==Hl&&(Hl&&e.type==="mousemove"?(Hg=e.screenX-Hl.screenX,Kg=e.screenY-Hl.screenY):Kg=Hg=0,Hl=e),Hg)},movementY:function(e){return"movementY"in e?e.movementY:Kg}}),Kb=rr(Sf),L6=pt({},Sf,{dataTransfer:0}),F6=rr(L6),N6=pt({},_u,{relatedTarget:0}),Vg=rr(N6),z6=pt({},ml,{animationName:0,elapsedTime:0,pseudoElement:0}),B6=rr(z6),U6=pt({},ml,{clipboardData:function(e){return"clipboardData"in e?e.clipboardData:window.clipboardData}}),H6=rr(U6),K6=pt({},ml,{data:0}),Vb=rr(K6),V6={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"},W6={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"},G6={Alt:"altKey",Control:"ctrlKey",Meta:"metaKey",Shift:"shiftKey"};function Y6(e){var t=this.nativeEvent;return t.getModifierState?t.getModifierState(e):(e=G6[e])?!!t[e]:!1}function y0(){return Y6}var X6=pt({},_u,{key:function(e){if(e.key){var t=V6[e.key]||e.key;if(t!=="Unidentified")return t}return e.type==="keypress"?(e=ah(e),e===13?"Enter":String.fromCharCode(e)):e.type==="keydown"||e.type==="keyup"?W6[e.keyCode]||"Unidentified":""},code:0,location:0,ctrlKey:0,shiftKey:0,altKey:0,metaKey:0,repeat:0,locale:0,getModifierState:y0,charCode:function(e){return e.type==="keypress"?ah(e):0},keyCode:function(e){return e.type==="keydown"||e.type==="keyup"?e.keyCode:0},which:function(e){return e.type==="keypress"?ah(e):e.type==="keydown"||e.type==="keyup"?e.keyCode:0}}),q6=rr(X6),Z6=pt({},Sf,{pointerId:0,width:0,height:0,pressure:0,tangentialPressure:0,tiltX:0,tiltY:0,twist:0,pointerType:0,isPrimary:0}),Wb=rr(Z6),Q6=pt({},_u,{touches:0,targetTouches:0,changedTouches:0,altKey:0,metaKey:0,ctrlKey:0,shiftKey:0,getModifierState:y0}),J6=rr(Q6),eN=pt({},ml,{propertyName:0,elapsedTime:0,pseudoElement:0}),tN=rr(eN),nN=pt({},Sf,{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}),rN=rr(nN),oN=[9,13,27,32],S0=No&&"CompositionEvent"in window,xc=null;No&&"documentMode"in document&&(xc=document.documentMode);var sN=No&&"TextEvent"in window&&!xc,ek=No&&(!S0||xc&&8<xc&&11>=xc),Gb=" ",Yb=!1;function tk(e,t){switch(e){case"keyup":return oN.indexOf(t.keyCode)!==-1;case"keydown":return t.keyCode!==229;case"keypress":case"mousedown":case"focusout":return!0;default:return!1}}function nk(e){return e=e.detail,typeof e=="object"&&"data"in e?e.data:null}var ma=!1;function iN(e,t){switch(e){case"compositionend":return nk(t);case"keypress":return t.which!==32?null:(Yb=!0,Gb);case"textInput":return e=t.data,e===Gb&&Yb?null:e;default:return null}}function aN(e,t){if(ma)return e==="compositionend"||!S0&&tk(e,t)?(e=J_(),ih=g0=ys=null,ma=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1<t.char.length)return t.char;if(t.which)return String.fromCharCode(t.which)}return null;case"compositionend":return ek&&t.locale!=="ko"?null:t.data;default:return null}}var lN={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 Xb(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t==="input"?!!lN[e.type]:t==="textarea"}function rk(e,t,n,r){O_(r),t=kp(t,"onChange"),0<t.length&&(n=new m0("onChange","change",null,n,r),e.push({event:n,listeners:t}))}var wc=null,Gc=null;function cN(e){fk(e,0)}function vf(e){var t=va(e);if(__(t))return e}function uN(e,t){if(e==="change")return t}var ok=!1;if(No){var Wg;if(No){var Gg="oninput"in document;if(!Gg){var qb=document.createElement("div");qb.setAttribute("oninput","return;"),Gg=typeof qb.oninput=="function"}Wg=Gg}else Wg=!1;ok=Wg&&(!document.documentMode||9<document.documentMode)}function Zb(){wc&&(wc.detachEvent("onpropertychange",sk),Gc=wc=null)}function sk(e){if(e.propertyName==="value"&&vf(Gc)){var t=[];rk(t,Gc,e,u0(e)),F_(cN,t)}}function dN(e,t,n){e==="focusin"?(Zb(),wc=t,Gc=n,wc.attachEvent("onpropertychange",sk)):e==="focusout"&&Zb()}function hN(e){if(e==="selectionchange"||e==="keyup"||e==="keydown")return vf(Gc)}function pN(e,t){if(e==="click")return vf(t)}function fN(e,t){if(e==="input"||e==="change")return vf(t)}function gN(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var Nr=typeof Object.is=="function"?Object.is:gN;function Yc(e,t){if(Nr(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;var n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(r=0;r<n.length;r++){var o=n[r];if(!By.call(t,o)||!Nr(e[o],t[o]))return!1}return!0}function Qb(e){for(;e&&e.firstChild;)e=e.firstChild;return e}function Jb(e,t){var n=Qb(e);e=0;for(var r;n;){if(n.nodeType===3){if(r=e+n.textContent.length,e<=t&&r>=t)return{node:n,offset:t-e};e=r}e:{for(;n;){if(n.nextSibling){n=n.nextSibling;break e}n=n.parentNode}n=void 0}n=Qb(n)}}function ik(e,t){return e&&t?e===t?!0:e&&e.nodeType===3?!1:t&&t.nodeType===3?ik(e,t.parentNode):"contains"in e?e.contains(t):e.compareDocumentPosition?!!(e.compareDocumentPosition(t)&16):!1:!1}function ak(){for(var e=window,t=wp();t instanceof e.HTMLIFrameElement;){try{var n=typeof t.contentWindow.location.href=="string"}catch{n=!1}if(n)e=t.contentWindow;else break;t=wp(e.document)}return t}function v0(e){var t=e&&e.nodeName&&e.nodeName.toLowerCase();return t&&(t==="input"&&(e.type==="text"||e.type==="search"||e.type==="tel"||e.type==="url"||e.type==="password")||t==="textarea"||e.contentEditable==="true")}function mN(e){var t=ak(),n=e.focusedElem,r=e.selectionRange;if(t!==n&&n&&n.ownerDocument&&ik(n.ownerDocument.documentElement,n)){if(r!==null&&v0(n)){if(t=r.start,e=r.end,e===void 0&&(e=t),"selectionStart"in n)n.selectionStart=t,n.selectionEnd=Math.min(e,n.value.length);else if(e=(t=n.ownerDocument||document)&&t.defaultView||window,e.getSelection){e=e.getSelection();var o=n.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=Jb(n,s);var i=Jb(n,r);o&&i&&(e.rangeCount!==1||e.anchorNode!==o.node||e.anchorOffset!==o.offset||e.focusNode!==i.node||e.focusOffset!==i.offset)&&(t=t.createRange(),t.setStart(o.node,o.offset),e.removeAllRanges(),s>r?(e.addRange(t),e.extend(i.node,i.offset)):(t.setEnd(i.node,i.offset),e.addRange(t)))}}for(t=[],e=n;e=e.parentNode;)e.nodeType===1&&t.push({element:e,left:e.scrollLeft,top:e.scrollTop});for(typeof n.focus=="function"&&n.focus(),n=0;n<t.length;n++)e=t[n],e.element.scrollLeft=e.left,e.element.scrollTop=e.top}}var yN=No&&"documentMode"in document&&11>=document.documentMode,ya=null,iS=null,bc=null,aS=!1;function e1(e,t,n){var r=n.window===n?n.document:n.nodeType===9?n:n.ownerDocument;aS||ya==null||ya!==wp(r)||(r=ya,"selectionStart"in r&&v0(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}),bc&&Yc(bc,r)||(bc=r,r=kp(iS,"onSelect"),0<r.length&&(t=new m0("onSelect","select",null,t,n),e.push({event:t,listeners:r}),t.target=ya)))}function fd(e,t){var n={};return n[e.toLowerCase()]=t.toLowerCase(),n["Webkit"+e]="webkit"+t,n["Moz"+e]="moz"+t,n}var Sa={animationend:fd("Animation","AnimationEnd"),animationiteration:fd("Animation","AnimationIteration"),animationstart:fd("Animation","AnimationStart"),transitionend:fd("Transition","TransitionEnd")},Yg={},lk={};No&&(lk=document.createElement("div").style,"AnimationEvent"in window||(delete Sa.animationend.animation,delete Sa.animationiteration.animation,delete Sa.animationstart.animation),"TransitionEvent"in window||delete Sa.transitionend.transition);function xf(e){if(Yg[e])return Yg[e];if(!Sa[e])return e;var t=Sa[e],n;for(n in t)if(t.hasOwnProperty(n)&&n in lk)return Yg[e]=t[n];return e}var ck=xf("animationend"),uk=xf("animationiteration"),dk=xf("animationstart"),hk=xf("transitionend"),pk=new Map,t1="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 Hs(e,t){pk.set(e,t),Fi(t,[e])}for(var Xg=0;Xg<t1.length;Xg++){var qg=t1[Xg],SN=qg.toLowerCase(),vN=qg[0].toUpperCase()+qg.slice(1);Hs(SN,"on"+vN)}Hs(ck,"onAnimationEnd");Hs(uk,"onAnimationIteration");Hs(dk,"onAnimationStart");Hs("dblclick","onDoubleClick");Hs("focusin","onFocus");Hs("focusout","onBlur");Hs(hk,"onTransitionEnd");qa("onMouseEnter",["mouseout","mouseover"]);qa("onMouseLeave",["mouseout","mouseover"]);qa("onPointerEnter",["pointerout","pointerover"]);qa("onPointerLeave",["pointerout","pointerover"]);Fi("onChange","change click focusin focusout input keydown keyup selectionchange".split(" "));Fi("onSelect","focusout contextmenu dragend focusin keydown keyup mousedown mouseup selectionchange".split(" "));Fi("onBeforeInput",["compositionend","keypress","textInput","paste"]);Fi("onCompositionEnd","compositionend focusout keydown keypress keyup mousedown".split(" "));Fi("onCompositionStart","compositionstart focusout keydown keypress keyup mousedown".split(" "));Fi("onCompositionUpdate","compositionupdate focusout keydown keypress keyup mousedown".split(" "));var uc="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(" "),xN=new Set("cancel close invalid load scroll toggle".split(" ").concat(uc));function n1(e,t,n){var r=e.type||"unknown-event";e.currentTarget=n,S6(r,t,void 0,e),e.currentTarget=null}function fk(e,t){t=(t&4)!==0;for(var n=0;n<e.length;n++){var r=e[n],o=r.event;r=r.listeners;e:{var s=void 0;if(t)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;n1(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;n1(o,a,c),s=l}}}if(Pp)throw e=nS,Pp=!1,nS=null,e}function Je(e,t){var n=t[hS];n===void 0&&(n=t[hS]=new Set);var r=e+"__bubble";n.has(r)||(gk(t,e,2,!1),n.add(r))}function Zg(e,t,n){var r=0;t&&(r|=4),gk(n,e,r,t)}var gd="_reactListening"+Math.random().toString(36).slice(2);function Xc(e){if(!e[gd]){e[gd]=!0,b_.forEach(function(n){n!=="selectionchange"&&(xN.has(n)||Zg(n,!1,e),Zg(n,!0,e))});var t=e.nodeType===9?e:e.ownerDocument;t===null||t[gd]||(t[gd]=!0,Zg("selectionchange",!1,t))}}function gk(e,t,n,r){switch(Q_(t)){case 1:var o=O6;break;case 4:o=D6;break;default:o=f0}n=o.bind(null,t,n,e),o=void 0,!tS||t!=="touchstart"&&t!=="touchmove"&&t!=="wheel"||(o=!0),r?o!==void 0?e.addEventListener(t,n,{capture:!0,passive:o}):e.addEventListener(t,n,!0):o!==void 0?e.addEventListener(t,n,{passive:o}):e.addEventListener(t,n,!1)}function Qg(e,t,n,r,o){var s=r;if(!(t&1)&&!(t&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=pi(a),i===null)return;if(l=i.tag,l===5||l===6){r=s=i;continue e}a=a.parentNode}}r=r.return}F_(function(){var c=s,u=u0(n),d=[];e:{var p=pk.get(e);if(p!==void 0){var f=m0,y=e;switch(e){case"keypress":if(ah(n)===0)break e;case"keydown":case"keyup":f=q6;break;case"focusin":y="focus",f=Vg;break;case"focusout":y="blur",f=Vg;break;case"beforeblur":case"afterblur":f=Vg;break;case"click":if(n.button===2)break e;case"auxclick":case"dblclick":case"mousedown":case"mousemove":case"mouseup":case"mouseout":case"mouseover":case"contextmenu":f=Kb;break;case"drag":case"dragend":case"dragenter":case"dragexit":case"dragleave":case"dragover":case"dragstart":case"drop":f=F6;break;case"touchcancel":case"touchend":case"touchmove":case"touchstart":f=J6;break;case ck:case uk:case dk:f=B6;break;case hk:f=tN;break;case"scroll":f=R6;break;case"wheel":f=rN;break;case"copy":case"cut":case"paste":f=H6;break;case"gotpointercapture":case"lostpointercapture":case"pointercancel":case"pointerdown":case"pointermove":case"pointerout":case"pointerover":case"pointerup":f=Wb}var g=(t&4)!==0,w=!g&&e==="scroll",S=g?p!==null?p+"Capture":null:p;g=[];for(var v=c,C;v!==null;){C=v;var I=C.stateNode;if(C.tag===5&&I!==null&&(C=I,S!==null&&(I=Hc(v,S),I!=null&&g.push(qc(v,I,C)))),w)break;v=v.return}0<g.length&&(p=new f(p,y,null,n,u),d.push({event:p,listeners:g}))}}if(!(t&7)){e:{if(p=e==="mouseover"||e==="pointerover",f=e==="mouseout"||e==="pointerout",p&&n!==Jy&&(y=n.relatedTarget||n.fromElement)&&(pi(y)||y[zo]))break e;if((f||p)&&(p=u.window===u?u:(p=u.ownerDocument)?p.defaultView||p.parentWindow:window,f?(y=n.relatedTarget||n.toElement,f=c,y=y?pi(y):null,y!==null&&(w=Ni(y),y!==w||y.tag!==5&&y.tag!==6)&&(y=null)):(f=null,y=c),f!==y)){if(g=Kb,I="onMouseLeave",S="onMouseEnter",v="mouse",(e==="pointerout"||e==="pointerover")&&(g=Wb,I="onPointerLeave",S="onPointerEnter",v="pointer"),w=f==null?p:va(f),C=y==null?p:va(y),p=new g(I,v+"leave",f,n,u),p.target=w,p.relatedTarget=C,I=null,pi(u)===c&&(g=new g(S,v+"enter",y,n,u),g.target=C,g.relatedTarget=w,I=g),w=I,f&&y)t:{for(g=f,S=y,v=0,C=g;C;C=ra(C))v++;for(C=0,I=S;I;I=ra(I))C++;for(;0<v-C;)g=ra(g),v--;for(;0<C-v;)S=ra(S),C--;for(;v--;){if(g===S||S!==null&&g===S.alternate)break t;g=ra(g),S=ra(S)}g=null}else g=null;f!==null&&r1(d,p,f,g,!1),y!==null&&w!==null&&r1(d,w,y,g,!0)}}e:{if(p=c?va(c):window,f=p.nodeName&&p.nodeName.toLowerCase(),f==="select"||f==="input"&&p.type==="file")var P=uN;else if(Xb(p))if(ok)P=fN;else{P=hN;var E=dN}else(f=p.nodeName)&&f.toLowerCase()==="input"&&(p.type==="checkbox"||p.type==="radio")&&(P=pN);if(P&&(P=P(e,c))){rk(d,P,n,u);break e}E&&E(e,p,c),e==="focusout"&&(E=p._wrapperState)&&E.controlled&&p.type==="number"&&Yy(p,"number",p.value)}switch(E=c?va(c):window,e){case"focusin":(Xb(E)||E.contentEditable==="true")&&(ya=E,iS=c,bc=null);break;case"focusout":bc=iS=ya=null;break;case"mousedown":aS=!0;break;case"contextmenu":case"mouseup":case"dragend":aS=!1,e1(d,n,u);break;case"selectionchange":if(yN)break;case"keydown":case"keyup":e1(d,n,u)}var _;if(S0)e:{switch(e){case"compositionstart":var k="onCompositionStart";break e;case"compositionend":k="onCompositionEnd";break e;case"compositionupdate":k="onCompositionUpdate";break e}k=void 0}else ma?tk(e,n)&&(k="onCompositionEnd"):e==="keydown"&&n.keyCode===229&&(k="onCompositionStart");k&&(ek&&n.locale!=="ko"&&(ma||k!=="onCompositionStart"?k==="onCompositionEnd"&&ma&&(_=J_()):(ys=u,g0="value"in ys?ys.value:ys.textContent,ma=!0)),E=kp(c,k),0<E.length&&(k=new Vb(k,e,null,n,u),d.push({event:k,listeners:E}),_?k.data=_:(_=nk(n),_!==null&&(k.data=_)))),(_=sN?iN(e,n):aN(e,n))&&(c=kp(c,"onBeforeInput"),0<c.length&&(u=new Vb("onBeforeInput","beforeinput",null,n,u),d.push({event:u,listeners:c}),u.data=_))}fk(d,t)})}function qc(e,t,n){return{instance:e,listener:t,currentTarget:n}}function kp(e,t){for(var n=t+"Capture",r=[];e!==null;){var o=e,s=o.stateNode;o.tag===5&&s!==null&&(o=s,s=Hc(e,n),s!=null&&r.unshift(qc(e,s,o)),s=Hc(e,t),s!=null&&r.push(qc(e,s,o))),e=e.return}return r}function ra(e){if(e===null)return null;do e=e.return;while(e&&e.tag!==5);return e||null}function r1(e,t,n,r,o){for(var s=t._reactName,i=[];n!==null&&n!==r;){var a=n,l=a.alternate,c=a.stateNode;if(l!==null&&l===r)break;a.tag===5&&c!==null&&(a=c,o?(l=Hc(n,s),l!=null&&i.unshift(qc(n,l,a))):o||(l=Hc(n,s),l!=null&&i.push(qc(n,l,a)))),n=n.return}i.length!==0&&e.push({event:t,listeners:i})}var wN=/\r\n?/g,bN=/\u0000|\uFFFD/g;function o1(e){return(typeof e=="string"?e:""+e).replace(wN,`
76
- `).replace(bN,"")}function md(e,t,n){if(t=o1(t),o1(e)!==t&&n)throw Error(Y(425))}function Tp(){}var lS=null,cS=null;function uS(e,t){return e==="textarea"||e==="noscript"||typeof t.children=="string"||typeof t.children=="number"||typeof t.dangerouslySetInnerHTML=="object"&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var dS=typeof setTimeout=="function"?setTimeout:void 0,PN=typeof clearTimeout=="function"?clearTimeout:void 0,s1=typeof Promise=="function"?Promise:void 0,CN=typeof queueMicrotask=="function"?queueMicrotask:typeof s1<"u"?function(e){return s1.resolve(null).then(e).catch(IN)}:dS;function IN(e){setTimeout(function(){throw e})}function Jg(e,t){var n=t,r=0;do{var o=n.nextSibling;if(e.removeChild(n),o&&o.nodeType===8)if(n=o.data,n==="/$"){if(r===0){e.removeChild(o),Wc(t);return}r--}else n!=="$"&&n!=="$?"&&n!=="$!"||r++;n=o}while(n);Wc(t)}function Is(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t==="$"||t==="$!"||t==="$?")break;if(t==="/$")return null}}return e}function i1(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n==="$"||n==="$!"||n==="$?"){if(t===0)return e;t--}else n==="/$"&&t++}e=e.previousSibling}return null}var yl=Math.random().toString(36).slice(2),Xr="__reactFiber$"+yl,Zc="__reactProps$"+yl,zo="__reactContainer$"+yl,hS="__reactEvents$"+yl,EN="__reactListeners$"+yl,_N="__reactHandles$"+yl;function pi(e){var t=e[Xr];if(t)return t;for(var n=e.parentNode;n;){if(t=n[zo]||n[Xr]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=i1(e);e!==null;){if(n=e[Xr])return n;e=i1(e)}return t}e=n,n=e.parentNode}return null}function ku(e){return e=e[Xr]||e[zo],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function va(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(Y(33))}function wf(e){return e[Zc]||null}var pS=[],xa=-1;function Ks(e){return{current:e}}function rt(e){0>xa||(e.current=pS[xa],pS[xa]=null,xa--)}function Ye(e,t){xa++,pS[xa]=e.current,e.current=t}var Os={},on=Ks(Os),Mn=Ks(!1),Ci=Os;function Za(e,t){var n=e.type.contextTypes;if(!n)return Os;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var o={},s;for(s in n)o[s]=t[s];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=o),o}function An(e){return e=e.childContextTypes,e!=null}function $p(){rt(Mn),rt(on)}function a1(e,t,n){if(on.current!==Os)throw Error(Y(168));Ye(on,t),Ye(Mn,n)}function mk(e,t,n){var r=e.stateNode;if(t=t.childContextTypes,typeof r.getChildContext!="function")return n;r=r.getChildContext();for(var o in r)if(!(o in t))throw Error(Y(108,d6(e)||"Unknown",o));return pt({},n,r)}function Mp(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Os,Ci=on.current,Ye(on,e),Ye(Mn,Mn.current),!0}function l1(e,t,n){var r=e.stateNode;if(!r)throw Error(Y(169));n?(e=mk(e,t,Ci),r.__reactInternalMemoizedMergedChildContext=e,rt(Mn),rt(on),Ye(on,e)):rt(Mn),Ye(Mn,n)}var _o=null,bf=!1,em=!1;function yk(e){_o===null?_o=[e]:_o.push(e)}function kN(e){bf=!0,yk(e)}function Vs(){if(!em&&_o!==null){em=!0;var e=0,t=Ne;try{var n=_o;for(Ne=1;e<n.length;e++){var r=n[e];do r=r(!0);while(r!==null)}_o=null,bf=!1}catch(o){throw _o!==null&&(_o=_o.slice(e+1)),U_(d0,Vs),o}finally{Ne=t,em=!1}}return null}var wa=[],ba=0,Ap=null,jp=0,ur=[],dr=0,Ii=null,To=1,$o="";function ai(e,t){wa[ba++]=jp,wa[ba++]=Ap,Ap=e,jp=t}function Sk(e,t,n){ur[dr++]=To,ur[dr++]=$o,ur[dr++]=Ii,Ii=e;var r=To;e=$o;var o=32-Or(r)-1;r&=~(1<<o),n+=1;var s=32-Or(t)+o;if(30<s){var i=o-o%5;s=(r&(1<<i)-1).toString(32),r>>=i,o-=i,To=1<<32-Or(t)+o|n<<o|r,$o=s+e}else To=1<<s|n<<o|r,$o=e}function x0(e){e.return!==null&&(ai(e,1),Sk(e,1,0))}function w0(e){for(;e===Ap;)Ap=wa[--ba],wa[ba]=null,jp=wa[--ba],wa[ba]=null;for(;e===Ii;)Ii=ur[--dr],ur[dr]=null,$o=ur[--dr],ur[dr]=null,To=ur[--dr],ur[dr]=null}var qn=null,Yn=null,ot=!1,$r=null;function vk(e,t){var n=hr(5,null,null,0);n.elementType="DELETED",n.stateNode=t,n.return=e,t=e.deletions,t===null?(e.deletions=[n],e.flags|=16):t.push(n)}function c1(e,t){switch(e.tag){case 5:var n=e.type;return t=t.nodeType!==1||n.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null?(e.stateNode=t,qn=e,Yn=Is(t.firstChild),!0):!1;case 6:return t=e.pendingProps===""||t.nodeType!==3?null:t,t!==null?(e.stateNode=t,qn=e,Yn=null,!0):!1;case 13:return t=t.nodeType!==8?null:t,t!==null?(n=Ii!==null?{id:To,overflow:$o}:null,e.memoizedState={dehydrated:t,treeContext:n,retryLane:1073741824},n=hr(18,null,null,0),n.stateNode=t,n.return=e,e.child=n,qn=e,Yn=null,!0):!1;default:return!1}}function fS(e){return(e.mode&1)!==0&&(e.flags&128)===0}function gS(e){if(ot){var t=Yn;if(t){var n=t;if(!c1(e,t)){if(fS(e))throw Error(Y(418));t=Is(n.nextSibling);var r=qn;t&&c1(e,t)?vk(r,n):(e.flags=e.flags&-4097|2,ot=!1,qn=e)}}else{if(fS(e))throw Error(Y(418));e.flags=e.flags&-4097|2,ot=!1,qn=e}}}function u1(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;qn=e}function yd(e){if(e!==qn)return!1;if(!ot)return u1(e),ot=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!=="head"&&t!=="body"&&!uS(e.type,e.memoizedProps)),t&&(t=Yn)){if(fS(e))throw xk(),Error(Y(418));for(;t;)vk(e,t),t=Is(t.nextSibling)}if(u1(e),e.tag===13){if(e=e.memoizedState,e=e!==null?e.dehydrated:null,!e)throw Error(Y(317));e:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var n=e.data;if(n==="/$"){if(t===0){Yn=Is(e.nextSibling);break e}t--}else n!=="$"&&n!=="$!"&&n!=="$?"||t++}e=e.nextSibling}Yn=null}}else Yn=qn?Is(e.stateNode.nextSibling):null;return!0}function xk(){for(var e=Yn;e;)e=Is(e.nextSibling)}function Qa(){Yn=qn=null,ot=!1}function b0(e){$r===null?$r=[e]:$r.push(e)}var TN=Zo.ReactCurrentBatchConfig;function Cr(e,t){if(e&&e.defaultProps){t=pt({},t),e=e.defaultProps;for(var n in e)t[n]===void 0&&(t[n]=e[n]);return t}return t}var Op=Ks(null),Dp=null,Pa=null,P0=null;function C0(){P0=Pa=Dp=null}function I0(e){var t=Op.current;rt(Op),e._currentValue=t}function mS(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)!==t?(e.childLanes|=t,r!==null&&(r.childLanes|=t)):r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t),e===n)break;e=e.return}}function Fa(e,t){Dp=e,P0=Pa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&(e.lanes&t&&(_n=!0),e.firstContext=null)}function mr(e){var t=e._currentValue;if(P0!==e)if(e={context:e,memoizedValue:t,next:null},Pa===null){if(Dp===null)throw Error(Y(308));Pa=e,Dp.dependencies={lanes:0,firstContext:e}}else Pa=Pa.next=e;return t}var fi=null;function E0(e){fi===null?fi=[e]:fi.push(e)}function wk(e,t,n,r){var o=t.interleaved;return o===null?(n.next=n,E0(t)):(n.next=o.next,o.next=n),t.interleaved=n,Bo(e,r)}function Bo(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var ds=!1;function _0(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function bk(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function jo(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function Es(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Ce&2){var o=r.pending;return o===null?t.next=t:(t.next=o.next,o.next=t),r.pending=t,Bo(e,n)}return o=r.interleaved,o===null?(t.next=t,E0(r)):(t.next=o.next,o.next=t),r.interleaved=t,Bo(e,n)}function lh(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,(n&4194240)!==0)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,h0(e,n)}}function d1(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var o=null,s=null;if(n=n.firstBaseUpdate,n!==null){do{var i={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};s===null?o=s=i:s=s.next=i,n=n.next}while(n!==null);s===null?o=s=t:s=s.next=t}else o=s=t;n={baseState:r.baseState,firstBaseUpdate:o,lastBaseUpdate:s,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function Rp(e,t,n,r){var o=e.updateQueue;ds=!1;var s=o.firstBaseUpdate,i=o.lastBaseUpdate,a=o.shared.pending;if(a!==null){o.shared.pending=null;var l=a,c=l.next;l.next=null,i===null?s=c:i.next=c,i=l;var u=e.alternate;u!==null&&(u=u.updateQueue,a=u.lastBaseUpdate,a!==i&&(a===null?u.firstBaseUpdate=c:a.next=c,u.lastBaseUpdate=l))}if(s!==null){var d=o.baseState;i=0,u=c=l=null,a=s;do{var 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 y=e,g=a;switch(p=t,f=n,g.tag){case 1:if(y=g.payload,typeof y=="function"){d=y.call(f,d,p);break e}d=y;break e;case 3:y.flags=y.flags&-65537|128;case 0:if(y=g.payload,p=typeof y=="function"?y.call(f,d,p):y,p==null)break e;d=pt({},d,p);break e;case 2:ds=!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=d):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=d),o.baseState=l,o.firstBaseUpdate=c,o.lastBaseUpdate=u,t=o.shared.interleaved,t!==null){o=t;do i|=o.lane,o=o.next;while(o!==t)}else s===null&&(o.shared.lanes=0);_i|=i,e.lanes=i,e.memoizedState=d}}function h1(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var r=e[t],o=r.callback;if(o!==null){if(r.callback=null,r=n,typeof o!="function")throw Error(Y(191,o));o.call(r)}}}var Pk=new w_.Component().refs;function yS(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:pt({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Pf={isMounted:function(e){return(e=e._reactInternals)?Ni(e)===e:!1},enqueueSetState:function(e,t,n){e=e._reactInternals;var r=pn(),o=ks(e),s=jo(r,o);s.payload=t,n!=null&&(s.callback=n),t=Es(e,s,o),t!==null&&(Dr(t,e,o,r),lh(t,e,o))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=pn(),o=ks(e),s=jo(r,o);s.tag=1,s.payload=t,n!=null&&(s.callback=n),t=Es(e,s,o),t!==null&&(Dr(t,e,o,r),lh(t,e,o))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=pn(),r=ks(e),o=jo(n,r);o.tag=2,t!=null&&(o.callback=t),t=Es(e,o,r),t!==null&&(Dr(t,e,r,n),lh(t,e,r))}};function p1(e,t,n,r,o,s,i){return e=e.stateNode,typeof e.shouldComponentUpdate=="function"?e.shouldComponentUpdate(r,s,i):t.prototype&&t.prototype.isPureReactComponent?!Yc(n,r)||!Yc(o,s):!0}function Ck(e,t,n){var r=!1,o=Os,s=t.contextType;return typeof s=="object"&&s!==null?s=mr(s):(o=An(t)?Ci:on.current,r=t.contextTypes,s=(r=r!=null)?Za(e,o):Os),t=new t(n,s),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=Pf,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=o,e.__reactInternalMemoizedMaskedChildContext=s),t}function f1(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps=="function"&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps=="function"&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&Pf.enqueueReplaceState(t,t.state,null)}function SS(e,t,n,r){var o=e.stateNode;o.props=n,o.state=e.memoizedState,o.refs=Pk,_0(e);var s=t.contextType;typeof s=="object"&&s!==null?o.context=mr(s):(s=An(t)?Ci:on.current,o.context=Za(e,s)),o.state=e.memoizedState,s=t.getDerivedStateFromProps,typeof s=="function"&&(yS(e,t,s,n),o.state=e.memoizedState),typeof t.getDerivedStateFromProps=="function"||typeof o.getSnapshotBeforeUpdate=="function"||typeof o.UNSAFE_componentWillMount!="function"&&typeof o.componentWillMount!="function"||(t=o.state,typeof o.componentWillMount=="function"&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount=="function"&&o.UNSAFE_componentWillMount(),t!==o.state&&Pf.enqueueReplaceState(o,o.state,null),Rp(e,n,o,r),o.state=e.memoizedState),typeof o.componentDidMount=="function"&&(e.flags|=4194308)}function Kl(e,t,n){if(e=n.ref,e!==null&&typeof e!="function"&&typeof e!="object"){if(n._owner){if(n=n._owner,n){if(n.tag!==1)throw Error(Y(309));var r=n.stateNode}if(!r)throw Error(Y(147,e));var o=r,s=""+e;return t!==null&&t.ref!==null&&typeof t.ref=="function"&&t.ref._stringRef===s?t.ref:(t=function(i){var a=o.refs;a===Pk&&(a=o.refs={}),i===null?delete a[s]:a[s]=i},t._stringRef=s,t)}if(typeof e!="string")throw Error(Y(284));if(!n._owner)throw Error(Y(290,e))}return e}function Sd(e,t){throw e=Object.prototype.toString.call(t),Error(Y(31,e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e))}function g1(e){var t=e._init;return t(e._payload)}function Ik(e){function t(S,v){if(e){var C=S.deletions;C===null?(S.deletions=[v],S.flags|=16):C.push(v)}}function n(S,v){if(!e)return null;for(;v!==null;)t(S,v),v=v.sibling;return null}function r(S,v){for(S=new Map;v!==null;)v.key!==null?S.set(v.key,v):S.set(v.index,v),v=v.sibling;return S}function o(S,v){return S=Ts(S,v),S.index=0,S.sibling=null,S}function s(S,v,C){return S.index=C,e?(C=S.alternate,C!==null?(C=C.index,C<v?(S.flags|=2,v):C):(S.flags|=2,v)):(S.flags|=1048576,v)}function i(S){return e&&S.alternate===null&&(S.flags|=2),S}function a(S,v,C,I){return v===null||v.tag!==6?(v=am(C,S.mode,I),v.return=S,v):(v=o(v,C),v.return=S,v)}function l(S,v,C,I){var P=C.type;return P===ga?u(S,v,C.props.children,I,C.key):v!==null&&(v.elementType===P||typeof P=="object"&&P!==null&&P.$$typeof===us&&g1(P)===v.type)?(I=o(v,C.props),I.ref=Kl(S,v,C),I.return=S,I):(I=fh(C.type,C.key,C.props,null,S.mode,I),I.ref=Kl(S,v,C),I.return=S,I)}function c(S,v,C,I){return v===null||v.tag!==4||v.stateNode.containerInfo!==C.containerInfo||v.stateNode.implementation!==C.implementation?(v=lm(C,S.mode,I),v.return=S,v):(v=o(v,C.children||[]),v.return=S,v)}function u(S,v,C,I,P){return v===null||v.tag!==7?(v=xi(C,S.mode,I,P),v.return=S,v):(v=o(v,C),v.return=S,v)}function d(S,v,C){if(typeof v=="string"&&v!==""||typeof v=="number")return v=am(""+v,S.mode,C),v.return=S,v;if(typeof v=="object"&&v!==null){switch(v.$$typeof){case ad:return C=fh(v.type,v.key,v.props,null,S.mode,C),C.ref=Kl(S,null,v),C.return=S,C;case fa:return v=lm(v,S.mode,C),v.return=S,v;case us:var I=v._init;return d(S,I(v._payload),C)}if(lc(v)||Nl(v))return v=xi(v,S.mode,C,null),v.return=S,v;Sd(S,v)}return null}function p(S,v,C,I){var P=v!==null?v.key:null;if(typeof C=="string"&&C!==""||typeof C=="number")return P!==null?null:a(S,v,""+C,I);if(typeof C=="object"&&C!==null){switch(C.$$typeof){case ad:return C.key===P?l(S,v,C,I):null;case fa:return C.key===P?c(S,v,C,I):null;case us:return P=C._init,p(S,v,P(C._payload),I)}if(lc(C)||Nl(C))return P!==null?null:u(S,v,C,I,null);Sd(S,C)}return null}function f(S,v,C,I,P){if(typeof I=="string"&&I!==""||typeof I=="number")return S=S.get(C)||null,a(v,S,""+I,P);if(typeof I=="object"&&I!==null){switch(I.$$typeof){case ad:return S=S.get(I.key===null?C:I.key)||null,l(v,S,I,P);case fa:return S=S.get(I.key===null?C:I.key)||null,c(v,S,I,P);case us:var E=I._init;return f(S,v,C,E(I._payload),P)}if(lc(I)||Nl(I))return S=S.get(C)||null,u(v,S,I,P,null);Sd(v,I)}return null}function y(S,v,C,I){for(var P=null,E=null,_=v,k=v=0,$=null;_!==null&&k<C.length;k++){_.index>k?($=_,_=null):$=_.sibling;var T=p(S,_,C[k],I);if(T===null){_===null&&(_=$);break}e&&_&&T.alternate===null&&t(S,_),v=s(T,v,k),E===null?P=T:E.sibling=T,E=T,_=$}if(k===C.length)return n(S,_),ot&&ai(S,k),P;if(_===null){for(;k<C.length;k++)_=d(S,C[k],I),_!==null&&(v=s(_,v,k),E===null?P=_:E.sibling=_,E=_);return ot&&ai(S,k),P}for(_=r(S,_);k<C.length;k++)$=f(_,S,k,C[k],I),$!==null&&(e&&$.alternate!==null&&_.delete($.key===null?k:$.key),v=s($,v,k),E===null?P=$:E.sibling=$,E=$);return e&&_.forEach(function(j){return t(S,j)}),ot&&ai(S,k),P}function g(S,v,C,I){var P=Nl(C);if(typeof P!="function")throw Error(Y(150));if(C=P.call(C),C==null)throw Error(Y(151));for(var E=P=null,_=v,k=v=0,$=null,T=C.next();_!==null&&!T.done;k++,T=C.next()){_.index>k?($=_,_=null):$=_.sibling;var j=p(S,_,T.value,I);if(j===null){_===null&&(_=$);break}e&&_&&j.alternate===null&&t(S,_),v=s(j,v,k),E===null?P=j:E.sibling=j,E=j,_=$}if(T.done)return n(S,_),ot&&ai(S,k),P;if(_===null){for(;!T.done;k++,T=C.next())T=d(S,T.value,I),T!==null&&(v=s(T,v,k),E===null?P=T:E.sibling=T,E=T);return ot&&ai(S,k),P}for(_=r(S,_);!T.done;k++,T=C.next())T=f(_,S,k,T.value,I),T!==null&&(e&&T.alternate!==null&&_.delete(T.key===null?k:T.key),v=s(T,v,k),E===null?P=T:E.sibling=T,E=T);return e&&_.forEach(function(L){return t(S,L)}),ot&&ai(S,k),P}function w(S,v,C,I){if(typeof C=="object"&&C!==null&&C.type===ga&&C.key===null&&(C=C.props.children),typeof C=="object"&&C!==null){switch(C.$$typeof){case ad:e:{for(var P=C.key,E=v;E!==null;){if(E.key===P){if(P=C.type,P===ga){if(E.tag===7){n(S,E.sibling),v=o(E,C.props.children),v.return=S,S=v;break e}}else if(E.elementType===P||typeof P=="object"&&P!==null&&P.$$typeof===us&&g1(P)===E.type){n(S,E.sibling),v=o(E,C.props),v.ref=Kl(S,E,C),v.return=S,S=v;break e}n(S,E);break}else t(S,E);E=E.sibling}C.type===ga?(v=xi(C.props.children,S.mode,I,C.key),v.return=S,S=v):(I=fh(C.type,C.key,C.props,null,S.mode,I),I.ref=Kl(S,v,C),I.return=S,S=I)}return i(S);case fa:e:{for(E=C.key;v!==null;){if(v.key===E)if(v.tag===4&&v.stateNode.containerInfo===C.containerInfo&&v.stateNode.implementation===C.implementation){n(S,v.sibling),v=o(v,C.children||[]),v.return=S,S=v;break e}else{n(S,v);break}else t(S,v);v=v.sibling}v=lm(C,S.mode,I),v.return=S,S=v}return i(S);case us:return E=C._init,w(S,v,E(C._payload),I)}if(lc(C))return y(S,v,C,I);if(Nl(C))return g(S,v,C,I);Sd(S,C)}return typeof C=="string"&&C!==""||typeof C=="number"?(C=""+C,v!==null&&v.tag===6?(n(S,v.sibling),v=o(v,C),v.return=S,S=v):(n(S,v),v=am(C,S.mode,I),v.return=S,S=v),i(S)):n(S,v)}return w}var Ja=Ik(!0),Ek=Ik(!1),Tu={},no=Ks(Tu),Qc=Ks(Tu),Jc=Ks(Tu);function gi(e){if(e===Tu)throw Error(Y(174));return e}function k0(e,t){switch(Ye(Jc,t),Ye(Qc,e),Ye(no,Tu),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:qy(null,"");break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=qy(t,e)}rt(no),Ye(no,t)}function el(){rt(no),rt(Qc),rt(Jc)}function _k(e){gi(Jc.current);var t=gi(no.current),n=qy(t,e.type);t!==n&&(Ye(Qc,e),Ye(no,n))}function T0(e){Qc.current===e&&(rt(no),rt(Qc))}var lt=Ks(0);function Lp(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data==="$?"||n.data==="$!"))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var tm=[];function $0(){for(var e=0;e<tm.length;e++)tm[e]._workInProgressVersionPrimary=null;tm.length=0}var ch=Zo.ReactCurrentDispatcher,nm=Zo.ReactCurrentBatchConfig,Ei=0,dt=null,It=null,kt=null,Fp=!1,Pc=!1,eu=0,$N=0;function Vt(){throw Error(Y(321))}function M0(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!Nr(e[n],t[n]))return!1;return!0}function A0(e,t,n,r,o,s){if(Ei=s,dt=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,ch.current=e===null||e.memoizedState===null?ON:DN,e=n(r,o),Pc){s=0;do{if(Pc=!1,eu=0,25<=s)throw Error(Y(301));s+=1,kt=It=null,t.updateQueue=null,ch.current=RN,e=n(r,o)}while(Pc)}if(ch.current=Np,t=It!==null&&It.next!==null,Ei=0,kt=It=dt=null,Fp=!1,t)throw Error(Y(300));return e}function j0(){var e=eu!==0;return eu=0,e}function Vr(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return kt===null?dt.memoizedState=kt=e:kt=kt.next=e,kt}function yr(){if(It===null){var e=dt.alternate;e=e!==null?e.memoizedState:null}else e=It.next;var t=kt===null?dt.memoizedState:kt.next;if(t!==null)kt=t,It=e;else{if(e===null)throw Error(Y(310));It=e,e={memoizedState:It.memoizedState,baseState:It.baseState,baseQueue:It.baseQueue,queue:It.queue,next:null},kt===null?dt.memoizedState=kt=e:kt=kt.next=e}return kt}function tu(e,t){return typeof t=="function"?t(e):t}function rm(e){var t=yr(),n=t.queue;if(n===null)throw Error(Y(311));n.lastRenderedReducer=e;var r=It,o=r.baseQueue,s=n.pending;if(s!==null){if(o!==null){var i=o.next;o.next=s.next,s.next=i}r.baseQueue=o=s,n.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((Ei&u)===u)l!==null&&(l=l.next={lane:0,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null}),r=c.hasEagerState?c.eagerState:e(r,c.action);else{var d={lane:u,action:c.action,hasEagerState:c.hasEagerState,eagerState:c.eagerState,next:null};l===null?(a=l=d,i=r):l=l.next=d,dt.lanes|=u,_i|=u}c=c.next}while(c!==null&&c!==s);l===null?i=r:l.next=a,Nr(r,t.memoizedState)||(_n=!0),t.memoizedState=r,t.baseState=i,t.baseQueue=l,n.lastRenderedState=r}if(e=n.interleaved,e!==null){o=e;do s=o.lane,dt.lanes|=s,_i|=s,o=o.next;while(o!==e)}else o===null&&(n.lanes=0);return[t.memoizedState,n.dispatch]}function om(e){var t=yr(),n=t.queue;if(n===null)throw Error(Y(311));n.lastRenderedReducer=e;var r=n.dispatch,o=n.pending,s=t.memoizedState;if(o!==null){n.pending=null;var i=o=o.next;do s=e(s,i.action),i=i.next;while(i!==o);Nr(s,t.memoizedState)||(_n=!0),t.memoizedState=s,t.baseQueue===null&&(t.baseState=s),n.lastRenderedState=s}return[s,r]}function kk(){}function Tk(e,t){var n=dt,r=yr(),o=t(),s=!Nr(r.memoizedState,o);if(s&&(r.memoizedState=o,_n=!0),r=r.queue,O0(Ak.bind(null,n,r,e),[e]),r.getSnapshot!==t||s||kt!==null&&kt.memoizedState.tag&1){if(n.flags|=2048,nu(9,Mk.bind(null,n,r,o,t),void 0,null),Mt===null)throw Error(Y(349));Ei&30||$k(n,t,o)}return o}function $k(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=dt.updateQueue,t===null?(t={lastEffect:null,stores:null},dt.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function Mk(e,t,n,r){t.value=n,t.getSnapshot=r,jk(t)&&Ok(e)}function Ak(e,t,n){return n(function(){jk(t)&&Ok(e)})}function jk(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!Nr(e,n)}catch{return!0}}function Ok(e){var t=Bo(e,1);t!==null&&Dr(t,e,1,-1)}function m1(e){var t=Vr();return typeof e=="function"&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:tu,lastRenderedState:e},t.queue=e,e=e.dispatch=jN.bind(null,dt,e),[t.memoizedState,e]}function nu(e,t,n,r){return e={tag:e,create:t,destroy:n,deps:r,next:null},t=dt.updateQueue,t===null?(t={lastEffect:null,stores:null},dt.updateQueue=t,t.lastEffect=e.next=e):(n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e)),e}function Dk(){return yr().memoizedState}function uh(e,t,n,r){var o=Vr();dt.flags|=e,o.memoizedState=nu(1|t,n,void 0,r===void 0?null:r)}function Cf(e,t,n,r){var o=yr();r=r===void 0?null:r;var s=void 0;if(It!==null){var i=It.memoizedState;if(s=i.destroy,r!==null&&M0(r,i.deps)){o.memoizedState=nu(t,n,s,r);return}}dt.flags|=e,o.memoizedState=nu(1|t,n,s,r)}function y1(e,t){return uh(8390656,8,e,t)}function O0(e,t){return Cf(2048,8,e,t)}function Rk(e,t){return Cf(4,2,e,t)}function Lk(e,t){return Cf(4,4,e,t)}function Fk(e,t){if(typeof t=="function")return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function Nk(e,t,n){return n=n!=null?n.concat([e]):null,Cf(4,4,Fk.bind(null,t,e),n)}function D0(){}function zk(e,t){var n=yr();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&M0(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function Bk(e,t){var n=yr();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&M0(t,r[1])?r[0]:(e=e(),n.memoizedState=[e,t],e)}function Uk(e,t,n){return Ei&21?(Nr(n,t)||(n=V_(),dt.lanes|=n,_i|=n,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,_n=!0),e.memoizedState=n)}function MN(e,t){var n=Ne;Ne=n!==0&&4>n?n:4,e(!0);var r=nm.transition;nm.transition={};try{e(!1),t()}finally{Ne=n,nm.transition=r}}function Hk(){return yr().memoizedState}function AN(e,t,n){var r=ks(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},Kk(e))Vk(t,n);else if(n=wk(e,t,n,r),n!==null){var o=pn();Dr(n,e,r,o),Wk(n,t,r)}}function jN(e,t,n){var r=ks(e),o={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(Kk(e))Vk(t,o);else{var s=e.alternate;if(e.lanes===0&&(s===null||s.lanes===0)&&(s=t.lastRenderedReducer,s!==null))try{var i=t.lastRenderedState,a=s(i,n);if(o.hasEagerState=!0,o.eagerState=a,Nr(a,i)){var l=t.interleaved;l===null?(o.next=o,E0(t)):(o.next=l.next,l.next=o),t.interleaved=o;return}}catch{}finally{}n=wk(e,t,o,r),n!==null&&(o=pn(),Dr(n,e,r,o),Wk(n,t,r))}}function Kk(e){var t=e.alternate;return e===dt||t!==null&&t===dt}function Vk(e,t){Pc=Fp=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function Wk(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,h0(e,n)}}var Np={readContext:mr,useCallback:Vt,useContext:Vt,useEffect:Vt,useImperativeHandle:Vt,useInsertionEffect:Vt,useLayoutEffect:Vt,useMemo:Vt,useReducer:Vt,useRef:Vt,useState:Vt,useDebugValue:Vt,useDeferredValue:Vt,useTransition:Vt,useMutableSource:Vt,useSyncExternalStore:Vt,useId:Vt,unstable_isNewReconciler:!1},ON={readContext:mr,useCallback:function(e,t){return Vr().memoizedState=[e,t===void 0?null:t],e},useContext:mr,useEffect:y1,useImperativeHandle:function(e,t,n){return n=n!=null?n.concat([e]):null,uh(4194308,4,Fk.bind(null,t,e),n)},useLayoutEffect:function(e,t){return uh(4194308,4,e,t)},useInsertionEffect:function(e,t){return uh(4,2,e,t)},useMemo:function(e,t){var n=Vr();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Vr();return t=n!==void 0?n(t):t,r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=AN.bind(null,dt,e),[r.memoizedState,e]},useRef:function(e){var t=Vr();return e={current:e},t.memoizedState=e},useState:m1,useDebugValue:D0,useDeferredValue:function(e){return Vr().memoizedState=e},useTransition:function(){var e=m1(!1),t=e[0];return e=MN.bind(null,e[1]),Vr().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var r=dt,o=Vr();if(ot){if(n===void 0)throw Error(Y(407));n=n()}else{if(n=t(),Mt===null)throw Error(Y(349));Ei&30||$k(r,t,n)}o.memoizedState=n;var s={value:n,getSnapshot:t};return o.queue=s,y1(Ak.bind(null,r,s,e),[e]),r.flags|=2048,nu(9,Mk.bind(null,r,s,n,t),void 0,null),n},useId:function(){var e=Vr(),t=Mt.identifierPrefix;if(ot){var n=$o,r=To;n=(r&~(1<<32-Or(r)-1)).toString(32)+n,t=":"+t+"R"+n,n=eu++,0<n&&(t+="H"+n.toString(32)),t+=":"}else n=$N++,t=":"+t+"r"+n.toString(32)+":";return e.memoizedState=t},unstable_isNewReconciler:!1},DN={readContext:mr,useCallback:zk,useContext:mr,useEffect:O0,useImperativeHandle:Nk,useInsertionEffect:Rk,useLayoutEffect:Lk,useMemo:Bk,useReducer:rm,useRef:Dk,useState:function(){return rm(tu)},useDebugValue:D0,useDeferredValue:function(e){var t=yr();return Uk(t,It.memoizedState,e)},useTransition:function(){var e=rm(tu)[0],t=yr().memoizedState;return[e,t]},useMutableSource:kk,useSyncExternalStore:Tk,useId:Hk,unstable_isNewReconciler:!1},RN={readContext:mr,useCallback:zk,useContext:mr,useEffect:O0,useImperativeHandle:Nk,useInsertionEffect:Rk,useLayoutEffect:Lk,useMemo:Bk,useReducer:om,useRef:Dk,useState:function(){return om(tu)},useDebugValue:D0,useDeferredValue:function(e){var t=yr();return It===null?t.memoizedState=e:Uk(t,It.memoizedState,e)},useTransition:function(){var e=om(tu)[0],t=yr().memoizedState;return[e,t]},useMutableSource:kk,useSyncExternalStore:Tk,useId:Hk,unstable_isNewReconciler:!1};function tl(e,t){try{var n="",r=t;do n+=u6(r),r=r.return;while(r);var o=n}catch(s){o=`
77
- Error generating stack: `+s.message+`
78
- `+s.stack}return{value:e,source:t,stack:o,digest:null}}function sm(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function vS(e,t){try{console.error(t.value)}catch(n){setTimeout(function(){throw n})}}var LN=typeof WeakMap=="function"?WeakMap:Map;function Gk(e,t,n){n=jo(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){Bp||(Bp=!0,TS=r),vS(e,t)},n}function Yk(e,t,n){n=jo(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r=="function"){var o=t.value;n.payload=function(){return r(o)},n.callback=function(){vS(e,t)}}var s=e.stateNode;return s!==null&&typeof s.componentDidCatch=="function"&&(n.callback=function(){vS(e,t),typeof r!="function"&&(_s===null?_s=new Set([this]):_s.add(this));var i=t.stack;this.componentDidCatch(t.value,{componentStack:i!==null?i:""})}),n}function S1(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new LN;var o=new Set;r.set(t,o)}else o=r.get(t),o===void 0&&(o=new Set,r.set(t,o));o.has(n)||(o.add(n),e=ZN.bind(null,e,t,n),t.then(e,e))}function v1(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t!==null?t.dehydrated!==null:!0),t)return e;e=e.return}while(e!==null);return null}function x1(e,t,n,r,o){return e.mode&1?(e.flags|=65536,e.lanes=o,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=jo(-1,1),t.tag=2,Es(n,t,1))),n.lanes|=1),e)}var FN=Zo.ReactCurrentOwner,_n=!1;function un(e,t,n,r){t.child=e===null?Ek(t,null,n,r):Ja(t,e.child,n,r)}function w1(e,t,n,r,o){n=n.render;var s=t.ref;return Fa(t,o),r=A0(e,t,n,r,s,o),n=j0(),e!==null&&!_n?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~o,Uo(e,t,o)):(ot&&n&&x0(t),t.flags|=1,un(e,t,r,o),t.child)}function b1(e,t,n,r,o){if(e===null){var s=n.type;return typeof s=="function"&&!H0(s)&&s.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=s,Xk(e,t,s,r,o)):(e=fh(n.type,null,r,t,t.mode,o),e.ref=t.ref,e.return=t,t.child=e)}if(s=e.child,!(e.lanes&o)){var i=s.memoizedProps;if(n=n.compare,n=n!==null?n:Yc,n(i,r)&&e.ref===t.ref)return Uo(e,t,o)}return t.flags|=1,e=Ts(s,r),e.ref=t.ref,e.return=t,t.child=e}function Xk(e,t,n,r,o){if(e!==null){var s=e.memoizedProps;if(Yc(s,r)&&e.ref===t.ref)if(_n=!1,t.pendingProps=r=s,(e.lanes&o)!==0)e.flags&131072&&(_n=!0);else return t.lanes=e.lanes,Uo(e,t,o)}return xS(e,t,n,r,o)}function qk(e,t,n){var r=t.pendingProps,o=r.children,s=e!==null?e.memoizedState:null;if(r.mode==="hidden")if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ye(Ia,Kn),Kn|=n;else{if(!(n&1073741824))return e=s!==null?s.baseLanes|n:n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,Ye(Ia,Kn),Kn|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=s!==null?s.baseLanes:n,Ye(Ia,Kn),Kn|=r}else s!==null?(r=s.baseLanes|n,t.memoizedState=null):r=n,Ye(Ia,Kn),Kn|=r;return un(e,t,o,n),t.child}function Zk(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function xS(e,t,n,r,o){var s=An(n)?Ci:on.current;return s=Za(t,s),Fa(t,o),n=A0(e,t,n,r,s,o),r=j0(),e!==null&&!_n?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~o,Uo(e,t,o)):(ot&&r&&x0(t),t.flags|=1,un(e,t,n,o),t.child)}function P1(e,t,n,r,o){if(An(n)){var s=!0;Mp(t)}else s=!1;if(Fa(t,o),t.stateNode===null)dh(e,t),Ck(t,n,r),SS(t,n,r,o),r=!0;else if(e===null){var i=t.stateNode,a=t.memoizedProps;i.props=a;var l=i.context,c=n.contextType;typeof c=="object"&&c!==null?c=mr(c):(c=An(n)?Ci:on.current,c=Za(t,c));var u=n.getDerivedStateFromProps,d=typeof u=="function"||typeof i.getSnapshotBeforeUpdate=="function";d||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==r||l!==c)&&f1(t,i,r,c),ds=!1;var p=t.memoizedState;i.state=p,Rp(t,r,i,o),l=t.memoizedState,a!==r||p!==l||Mn.current||ds?(typeof u=="function"&&(yS(t,n,u,r),l=t.memoizedState),(a=ds||p1(t,n,a,r,p,l,c))?(d||typeof i.UNSAFE_componentWillMount!="function"&&typeof i.componentWillMount!="function"||(typeof i.componentWillMount=="function"&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount=="function"&&i.UNSAFE_componentWillMount()),typeof i.componentDidMount=="function"&&(t.flags|=4194308)):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=l),i.props=r,i.state=l,i.context=c,r=a):(typeof i.componentDidMount=="function"&&(t.flags|=4194308),r=!1)}else{i=t.stateNode,bk(e,t),a=t.memoizedProps,c=t.type===t.elementType?a:Cr(t.type,a),i.props=c,d=t.pendingProps,p=i.context,l=n.contextType,typeof l=="object"&&l!==null?l=mr(l):(l=An(n)?Ci:on.current,l=Za(t,l));var f=n.getDerivedStateFromProps;(u=typeof f=="function"||typeof i.getSnapshotBeforeUpdate=="function")||typeof i.UNSAFE_componentWillReceiveProps!="function"&&typeof i.componentWillReceiveProps!="function"||(a!==d||p!==l)&&f1(t,i,r,l),ds=!1,p=t.memoizedState,i.state=p,Rp(t,r,i,o);var y=t.memoizedState;a!==d||p!==y||Mn.current||ds?(typeof f=="function"&&(yS(t,n,f,r),y=t.memoizedState),(c=ds||p1(t,n,c,r,p,y,l)||!1)?(u||typeof i.UNSAFE_componentWillUpdate!="function"&&typeof i.componentWillUpdate!="function"||(typeof i.componentWillUpdate=="function"&&i.componentWillUpdate(r,y,l),typeof i.UNSAFE_componentWillUpdate=="function"&&i.UNSAFE_componentWillUpdate(r,y,l)),typeof i.componentDidUpdate=="function"&&(t.flags|=4),typeof i.getSnapshotBeforeUpdate=="function"&&(t.flags|=1024)):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=y),i.props=r,i.state=y,i.context=l,r=c):(typeof i.componentDidUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=4),typeof i.getSnapshotBeforeUpdate!="function"||a===e.memoizedProps&&p===e.memoizedState||(t.flags|=1024),r=!1)}return wS(e,t,n,r,s,o)}function wS(e,t,n,r,o,s){Zk(e,t);var i=(t.flags&128)!==0;if(!r&&!i)return o&&l1(t,n,!1),Uo(e,t,s);r=t.stateNode,FN.current=t;var a=i&&typeof n.getDerivedStateFromError!="function"?null:r.render();return t.flags|=1,e!==null&&i?(t.child=Ja(t,e.child,null,s),t.child=Ja(t,null,a,s)):un(e,t,a,s),t.memoizedState=r.state,o&&l1(t,n,!0),t.child}function Qk(e){var t=e.stateNode;t.pendingContext?a1(e,t.pendingContext,t.pendingContext!==t.context):t.context&&a1(e,t.context,!1),k0(e,t.containerInfo)}function C1(e,t,n,r,o){return Qa(),b0(o),t.flags|=256,un(e,t,n,r),t.child}var bS={dehydrated:null,treeContext:null,retryLane:0};function PS(e){return{baseLanes:e,cachePool:null,transitions:null}}function Jk(e,t,n){var r=t.pendingProps,o=lt.current,s=!1,i=(t.flags&128)!==0,a;if((a=i)||(a=e!==null&&e.memoizedState===null?!1:(o&2)!==0),a?(s=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(o|=1),Ye(lt,o&1),e===null)return gS(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.mode&1?e.data==="$!"?t.lanes=8:t.lanes=1073741824:t.lanes=1,null):(i=r.children,e=r.fallback,s?(r=t.mode,s=t.child,i={mode:"hidden",children:i},!(r&1)&&s!==null?(s.childLanes=0,s.pendingProps=i):s=_f(i,r,0,null),e=xi(e,r,n,null),s.return=t,e.return=t,s.sibling=e,t.child=s,t.child.memoizedState=PS(n),t.memoizedState=bS,e):R0(t,i));if(o=e.memoizedState,o!==null&&(a=o.dehydrated,a!==null))return NN(e,t,i,r,a,o,n);if(s){s=r.fallback,i=t.mode,o=e.child,a=o.sibling;var l={mode:"hidden",children:r.children};return!(i&1)&&t.child!==o?(r=t.child,r.childLanes=0,r.pendingProps=l,t.deletions=null):(r=Ts(o,l),r.subtreeFlags=o.subtreeFlags&14680064),a!==null?s=Ts(a,s):(s=xi(s,i,n,null),s.flags|=2),s.return=t,r.return=t,r.sibling=s,t.child=r,r=s,s=t.child,i=e.child.memoizedState,i=i===null?PS(n):{baseLanes:i.baseLanes|n,cachePool:null,transitions:i.transitions},s.memoizedState=i,s.childLanes=e.childLanes&~n,t.memoizedState=bS,r}return s=e.child,e=s.sibling,r=Ts(s,{mode:"visible",children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function R0(e,t){return t=_f({mode:"visible",children:t},e.mode,0,null),t.return=e,e.child=t}function vd(e,t,n,r){return r!==null&&b0(r),Ja(t,e.child,null,n),e=R0(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function NN(e,t,n,r,o,s,i){if(n)return t.flags&256?(t.flags&=-257,r=sm(Error(Y(422))),vd(e,t,i,r)):t.memoizedState!==null?(t.child=e.child,t.flags|=128,null):(s=r.fallback,o=t.mode,r=_f({mode:"visible",children:r.children},o,0,null),s=xi(s,o,i,null),s.flags|=2,r.return=t,s.return=t,r.sibling=s,t.child=r,t.mode&1&&Ja(t,e.child,null,i),t.child.memoizedState=PS(i),t.memoizedState=bS,s);if(!(t.mode&1))return vd(e,t,i,null);if(o.data==="$!"){if(r=o.nextSibling&&o.nextSibling.dataset,r)var a=r.dgst;return r=a,s=Error(Y(419)),r=sm(s,r,void 0),vd(e,t,i,r)}if(a=(i&e.childLanes)!==0,_n||a){if(r=Mt,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,Bo(e,o),Dr(r,e,o,-1))}return U0(),r=sm(Error(Y(421))),vd(e,t,i,r)}return o.data==="$?"?(t.flags|=128,t.child=e.child,t=QN.bind(null,e),o._reactRetry=t,null):(e=s.treeContext,Yn=Is(o.nextSibling),qn=t,ot=!0,$r=null,e!==null&&(ur[dr++]=To,ur[dr++]=$o,ur[dr++]=Ii,To=e.id,$o=e.overflow,Ii=t),t=R0(t,r.children),t.flags|=4096,t)}function I1(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),mS(e.return,t,n)}function im(e,t,n,r,o){var s=e.memoizedState;s===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:o}:(s.isBackwards=t,s.rendering=null,s.renderingStartTime=0,s.last=r,s.tail=n,s.tailMode=o)}function eT(e,t,n){var r=t.pendingProps,o=r.revealOrder,s=r.tail;if(un(e,t,r.children,n),r=lt.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)e:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&I1(e,n,t);else if(e.tag===19)I1(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break e;for(;e.sibling===null;){if(e.return===null||e.return===t)break e;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Ye(lt,r),!(t.mode&1))t.memoizedState=null;else switch(o){case"forwards":for(n=t.child,o=null;n!==null;)e=n.alternate,e!==null&&Lp(e)===null&&(o=n),n=n.sibling;n=o,n===null?(o=t.child,t.child=null):(o=n.sibling,n.sibling=null),im(t,!1,o,n,s);break;case"backwards":for(n=null,o=t.child,t.child=null;o!==null;){if(e=o.alternate,e!==null&&Lp(e)===null){t.child=o;break}e=o.sibling,o.sibling=n,n=o,o=e}im(t,!0,n,null,s);break;case"together":im(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function dh(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function Uo(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),_i|=t.lanes,!(n&t.childLanes))return null;if(e!==null&&t.child!==e.child)throw Error(Y(153));if(t.child!==null){for(e=t.child,n=Ts(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=Ts(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function zN(e,t,n){switch(t.tag){case 3:Qk(t),Qa();break;case 5:_k(t);break;case 1:An(t.type)&&Mp(t);break;case 4:k0(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,o=t.memoizedProps.value;Ye(Op,r._currentValue),r._currentValue=o;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated!==null?(Ye(lt,lt.current&1),t.flags|=128,null):n&t.child.childLanes?Jk(e,t,n):(Ye(lt,lt.current&1),e=Uo(e,t,n),e!==null?e.sibling:null);Ye(lt,lt.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return eT(e,t,n);t.flags|=128}if(o=t.memoizedState,o!==null&&(o.rendering=null,o.tail=null,o.lastEffect=null),Ye(lt,lt.current),r)break;return null;case 22:case 23:return t.lanes=0,qk(e,t,n)}return Uo(e,t,n)}var tT,CS,nT,rT;tT=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}};CS=function(){};nT=function(e,t,n,r){var o=e.memoizedProps;if(o!==r){e=t.stateNode,gi(no.current);var s=null;switch(n){case"input":o=Wy(e,o),r=Wy(e,r),s=[];break;case"select":o=pt({},o,{value:void 0}),r=pt({},r,{value:void 0}),s=[];break;case"textarea":o=Xy(e,o),r=Xy(e,r),s=[];break;default:typeof o.onClick!="function"&&typeof r.onClick=="function"&&(e.onclick=Tp)}Zy(n,r);var i;n=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)&&(n||(n={}),n[i]="")}else c!=="dangerouslySetInnerHTML"&&c!=="children"&&c!=="suppressContentEditableWarning"&&c!=="suppressHydrationWarning"&&c!=="autoFocus"&&(Bc.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)||(n||(n={}),n[i]="");for(i in l)l.hasOwnProperty(i)&&a[i]!==l[i]&&(n||(n={}),n[i]=l[i])}else n||(s||(s=[]),s.push(c,n)),n=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"&&(Bc.hasOwnProperty(c)?(l!=null&&c==="onScroll"&&Je("scroll",e),s||a===l||(s=[])):(s=s||[]).push(c,l))}n&&(s=s||[]).push("style",n);var c=s;(t.updateQueue=c)&&(t.flags|=4)}};rT=function(e,t,n,r){n!==r&&(t.flags|=4)};function Vl(e,t){if(!ot)switch(e.tailMode){case"hidden":t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case"collapsed":n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function Wt(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var o=e.child;o!==null;)n|=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;)n|=o.lanes|o.childLanes,r|=o.subtreeFlags,r|=o.flags,o.return=e,o=o.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function BN(e,t,n){var r=t.pendingProps;switch(w0(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return Wt(t),null;case 1:return An(t.type)&&$p(),Wt(t),null;case 3:return r=t.stateNode,el(),rt(Mn),rt(on),$0(),r.pendingContext&&(r.context=r.pendingContext,r.pendingContext=null),(e===null||e.child===null)&&(yd(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,$r!==null&&(AS($r),$r=null))),CS(e,t),Wt(t),null;case 5:T0(t);var o=gi(Jc.current);if(n=t.type,e!==null&&t.stateNode!=null)nT(e,t,n,r,o),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!r){if(t.stateNode===null)throw Error(Y(166));return Wt(t),null}if(e=gi(no.current),yd(t)){r=t.stateNode,n=t.type;var s=t.memoizedProps;switch(r[Xr]=t,r[Zc]=s,e=(t.mode&1)!==0,n){case"dialog":Je("cancel",r),Je("close",r);break;case"iframe":case"object":case"embed":Je("load",r);break;case"video":case"audio":for(o=0;o<uc.length;o++)Je(uc[o],r);break;case"source":Je("error",r);break;case"img":case"image":case"link":Je("error",r),Je("load",r);break;case"details":Je("toggle",r);break;case"input":Ob(r,s),Je("invalid",r);break;case"select":r._wrapperState={wasMultiple:!!s.multiple},Je("invalid",r);break;case"textarea":Rb(r,s),Je("invalid",r)}Zy(n,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&&md(r.textContent,a,e),o=["children",a]):typeof a=="number"&&r.textContent!==""+a&&(s.suppressHydrationWarning!==!0&&md(r.textContent,a,e),o=["children",""+a]):Bc.hasOwnProperty(i)&&a!=null&&i==="onScroll"&&Je("scroll",r)}switch(n){case"input":ld(r),Db(r,s,!0);break;case"textarea":ld(r),Lb(r);break;case"select":case"option":break;default:typeof s.onClick=="function"&&(r.onclick=Tp)}r=o,t.updateQueue=r,r!==null&&(t.flags|=4)}else{i=o.nodeType===9?o:o.ownerDocument,e==="http://www.w3.org/1999/xhtml"&&(e=$_(n)),e==="http://www.w3.org/1999/xhtml"?n==="script"?(e=i.createElement("div"),e.innerHTML="<script><\/script>",e=e.removeChild(e.firstChild)):typeof r.is=="string"?e=i.createElement(n,{is:r.is}):(e=i.createElement(n),n==="select"&&(i=e,r.multiple?i.multiple=!0:r.size&&(i.size=r.size))):e=i.createElementNS(e,n),e[Xr]=t,e[Zc]=r,tT(e,t,!1,!1),t.stateNode=e;e:{switch(i=Qy(n,r),n){case"dialog":Je("cancel",e),Je("close",e),o=r;break;case"iframe":case"object":case"embed":Je("load",e),o=r;break;case"video":case"audio":for(o=0;o<uc.length;o++)Je(uc[o],e);o=r;break;case"source":Je("error",e),o=r;break;case"img":case"image":case"link":Je("error",e),Je("load",e),o=r;break;case"details":Je("toggle",e),o=r;break;case"input":Ob(e,r),o=Wy(e,r),Je("invalid",e);break;case"option":o=r;break;case"select":e._wrapperState={wasMultiple:!!r.multiple},o=pt({},r,{value:void 0}),Je("invalid",e);break;case"textarea":Rb(e,r),o=Xy(e,r),Je("invalid",e);break;default:o=r}Zy(n,o),a=o;for(s in a)if(a.hasOwnProperty(s)){var l=a[s];s==="style"?j_(e,l):s==="dangerouslySetInnerHTML"?(l=l?l.__html:void 0,l!=null&&M_(e,l)):s==="children"?typeof l=="string"?(n!=="textarea"||l!=="")&&Uc(e,l):typeof l=="number"&&Uc(e,""+l):s!=="suppressContentEditableWarning"&&s!=="suppressHydrationWarning"&&s!=="autoFocus"&&(Bc.hasOwnProperty(s)?l!=null&&s==="onScroll"&&Je("scroll",e):l!=null&&i0(e,s,l,i))}switch(n){case"input":ld(e),Db(e,r,!1);break;case"textarea":ld(e),Lb(e);break;case"option":r.value!=null&&e.setAttribute("value",""+js(r.value));break;case"select":e.multiple=!!r.multiple,s=r.value,s!=null?Oa(e,!!r.multiple,s,!1):r.defaultValue!=null&&Oa(e,!!r.multiple,r.defaultValue,!0);break;default:typeof o.onClick=="function"&&(e.onclick=Tp)}switch(n){case"button":case"input":case"select":case"textarea":r=!!r.autoFocus;break e;case"img":r=!0;break e;default:r=!1}}r&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return Wt(t),null;case 6:if(e&&t.stateNode!=null)rT(e,t,e.memoizedProps,r);else{if(typeof r!="string"&&t.stateNode===null)throw Error(Y(166));if(n=gi(Jc.current),gi(no.current),yd(t)){if(r=t.stateNode,n=t.memoizedProps,r[Xr]=t,(s=r.nodeValue!==n)&&(e=qn,e!==null))switch(e.tag){case 3:md(r.nodeValue,n,(e.mode&1)!==0);break;case 5:e.memoizedProps.suppressHydrationWarning!==!0&&md(r.nodeValue,n,(e.mode&1)!==0)}s&&(t.flags|=4)}else r=(n.nodeType===9?n:n.ownerDocument).createTextNode(r),r[Xr]=t,t.stateNode=r}return Wt(t),null;case 13:if(rt(lt),r=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(ot&&Yn!==null&&t.mode&1&&!(t.flags&128))xk(),Qa(),t.flags|=98560,s=!1;else if(s=yd(t),r!==null&&r.dehydrated!==null){if(e===null){if(!s)throw Error(Y(318));if(s=t.memoizedState,s=s!==null?s.dehydrated:null,!s)throw Error(Y(317));s[Xr]=t}else Qa(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;Wt(t),s=!1}else $r!==null&&(AS($r),$r=null),s=!0;if(!s)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(r=r!==null,r!==(e!==null&&e.memoizedState!==null)&&r&&(t.child.flags|=8192,t.mode&1&&(e===null||lt.current&1?Et===0&&(Et=3):U0())),t.updateQueue!==null&&(t.flags|=4),Wt(t),null);case 4:return el(),CS(e,t),e===null&&Xc(t.stateNode.containerInfo),Wt(t),null;case 10:return I0(t.type._context),Wt(t),null;case 17:return An(t.type)&&$p(),Wt(t),null;case 19:if(rt(lt),s=t.memoizedState,s===null)return Wt(t),null;if(r=(t.flags&128)!==0,i=s.rendering,i===null)if(r)Vl(s,!1);else{if(Et!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(i=Lp(e),i!==null){for(t.flags|=128,Vl(s,!1),r=i.updateQueue,r!==null&&(t.updateQueue=r,t.flags|=4),t.subtreeFlags=0,r=n,n=t.child;n!==null;)s=n,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}),n=n.sibling;return Ye(lt,lt.current&1|2),t.child}e=e.sibling}s.tail!==null&&St()>nl&&(t.flags|=128,r=!0,Vl(s,!1),t.lanes=4194304)}else{if(!r)if(e=Lp(i),e!==null){if(t.flags|=128,r=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),Vl(s,!0),s.tail===null&&s.tailMode==="hidden"&&!i.alternate&&!ot)return Wt(t),null}else 2*St()-s.renderingStartTime>nl&&n!==1073741824&&(t.flags|=128,r=!0,Vl(s,!1),t.lanes=4194304);s.isBackwards?(i.sibling=t.child,t.child=i):(n=s.last,n!==null?n.sibling=i:t.child=i,s.last=i)}return s.tail!==null?(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=St(),t.sibling=null,n=lt.current,Ye(lt,r?n&1|2:n&1),t):(Wt(t),null);case 22:case 23:return B0(),r=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==r&&(t.flags|=8192),r&&t.mode&1?Kn&1073741824&&(Wt(t),t.subtreeFlags&6&&(t.flags|=8192)):Wt(t),null;case 24:return null;case 25:return null}throw Error(Y(156,t.tag))}function UN(e,t){switch(w0(t),t.tag){case 1:return An(t.type)&&$p(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return el(),rt(Mn),rt(on),$0(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return T0(t),null;case 13:if(rt(lt),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(Y(340));Qa()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return rt(lt),null;case 4:return el(),null;case 10:return I0(t.type._context),null;case 22:case 23:return B0(),null;case 24:return null;default:return null}}var xd=!1,Qt=!1,HN=typeof WeakSet=="function"?WeakSet:Set,ee=null;function Ca(e,t){var n=e.ref;if(n!==null)if(typeof n=="function")try{n(null)}catch(r){mt(e,t,r)}else n.current=null}function IS(e,t,n){try{n()}catch(r){mt(e,t,r)}}var E1=!1;function KN(e,t){if(lS=Ep,e=ak(),v0(e)){if("selectionStart"in e)var n={start:e.selectionStart,end:e.selectionEnd};else e:{n=(n=e.ownerDocument)&&n.defaultView||window;var r=n.getSelection&&n.getSelection();if(r&&r.rangeCount!==0){n=r.anchorNode;var o=r.anchorOffset,s=r.focusNode;r=r.focusOffset;try{n.nodeType,s.nodeType}catch{n=null;break e}var i=0,a=-1,l=-1,c=0,u=0,d=e,p=null;t:for(;;){for(var f;d!==n||o!==0&&d.nodeType!==3||(a=i+o),d!==s||r!==0&&d.nodeType!==3||(l=i+r),d.nodeType===3&&(i+=d.nodeValue.length),(f=d.firstChild)!==null;)p=d,d=f;for(;;){if(d===e)break t;if(p===n&&++c===o&&(a=i),p===s&&++u===r&&(l=i),(f=d.nextSibling)!==null)break;d=p,p=d.parentNode}d=f}n=a===-1||l===-1?null:{start:a,end:l}}else n=null}n=n||{start:0,end:0}}else n=null;for(cS={focusedElem:e,selectionRange:n},Ep=!1,ee=t;ee!==null;)if(t=ee,e=t.child,(t.subtreeFlags&1028)!==0&&e!==null)e.return=t,ee=e;else for(;ee!==null;){t=ee;try{var y=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(y!==null){var g=y.memoizedProps,w=y.memoizedState,S=t.stateNode,v=S.getSnapshotBeforeUpdate(t.elementType===t.type?g:Cr(t.type,g),w);S.__reactInternalSnapshotBeforeUpdate=v}break;case 3:var C=t.stateNode.containerInfo;C.nodeType===1?C.textContent="":C.nodeType===9&&C.documentElement&&C.removeChild(C.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(Y(163))}}catch(I){mt(t,t.return,I)}if(e=t.sibling,e!==null){e.return=t.return,ee=e;break}ee=t.return}return y=E1,E1=!1,y}function Cc(e,t,n){var r=t.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&&IS(t,n,s)}o=o.next}while(o!==r)}}function If(e,t){if(t=t.updateQueue,t=t!==null?t.lastEffect:null,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function ES(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t=="function"?t(e):t.current=e}}function oT(e){var t=e.alternate;t!==null&&(e.alternate=null,oT(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Xr],delete t[Zc],delete t[hS],delete t[EN],delete t[_N])),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 sT(e){return e.tag===5||e.tag===3||e.tag===4}function _1(e){e:for(;;){for(;e.sibling===null;){if(e.return===null||sT(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 _S(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=Tp));else if(r!==4&&(e=e.child,e!==null))for(_S(e,t,n),e=e.sibling;e!==null;)_S(e,t,n),e=e.sibling}function kS(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(kS(e,t,n),e=e.sibling;e!==null;)kS(e,t,n),e=e.sibling}var Dt=null,_r=!1;function is(e,t,n){for(n=n.child;n!==null;)iT(e,t,n),n=n.sibling}function iT(e,t,n){if(to&&typeof to.onCommitFiberUnmount=="function")try{to.onCommitFiberUnmount(yf,n)}catch{}switch(n.tag){case 5:Qt||Ca(n,t);case 6:var r=Dt,o=_r;Dt=null,is(e,t,n),Dt=r,_r=o,Dt!==null&&(_r?(e=Dt,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Dt.removeChild(n.stateNode));break;case 18:Dt!==null&&(_r?(e=Dt,n=n.stateNode,e.nodeType===8?Jg(e.parentNode,n):e.nodeType===1&&Jg(e,n),Wc(e)):Jg(Dt,n.stateNode));break;case 4:r=Dt,o=_r,Dt=n.stateNode.containerInfo,_r=!0,is(e,t,n),Dt=r,_r=o;break;case 0:case 11:case 14:case 15:if(!Qt&&(r=n.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)&&IS(n,t,i),o=o.next}while(o!==r)}is(e,t,n);break;case 1:if(!Qt&&(Ca(n,t),r=n.stateNode,typeof r.componentWillUnmount=="function"))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(a){mt(n,t,a)}is(e,t,n);break;case 21:is(e,t,n);break;case 22:n.mode&1?(Qt=(r=Qt)||n.memoizedState!==null,is(e,t,n),Qt=r):is(e,t,n);break;default:is(e,t,n)}}function k1(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new HN),t.forEach(function(r){var o=JN.bind(null,e,r);n.has(r)||(n.add(r),r.then(o,o))})}}function Pr(e,t){var n=t.deletions;if(n!==null)for(var r=0;r<n.length;r++){var o=n[r];try{var s=e,i=t,a=i;e:for(;a!==null;){switch(a.tag){case 5:Dt=a.stateNode,_r=!1;break e;case 3:Dt=a.stateNode.containerInfo,_r=!0;break e;case 4:Dt=a.stateNode.containerInfo,_r=!0;break e}a=a.return}if(Dt===null)throw Error(Y(160));iT(s,i,o),Dt=null,_r=!1;var l=o.alternate;l!==null&&(l.return=null),o.return=null}catch(c){mt(o,t,c)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)aT(t,e),t=t.sibling}function aT(e,t){var n=e.alternate,r=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Pr(t,e),Hr(e),r&4){try{Cc(3,e,e.return),If(3,e)}catch(g){mt(e,e.return,g)}try{Cc(5,e,e.return)}catch(g){mt(e,e.return,g)}}break;case 1:Pr(t,e),Hr(e),r&512&&n!==null&&Ca(n,n.return);break;case 5:if(Pr(t,e),Hr(e),r&512&&n!==null&&Ca(n,n.return),e.flags&32){var o=e.stateNode;try{Uc(o,"")}catch(g){mt(e,e.return,g)}}if(r&4&&(o=e.stateNode,o!=null)){var s=e.memoizedProps,i=n!==null?n.memoizedProps:s,a=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{a==="input"&&s.type==="radio"&&s.name!=null&&k_(o,s),Qy(a,i);var c=Qy(a,s);for(i=0;i<l.length;i+=2){var u=l[i],d=l[i+1];u==="style"?j_(o,d):u==="dangerouslySetInnerHTML"?M_(o,d):u==="children"?Uc(o,d):i0(o,u,d,c)}switch(a){case"input":Gy(o,s);break;case"textarea":T_(o,s);break;case"select":var p=o._wrapperState.wasMultiple;o._wrapperState.wasMultiple=!!s.multiple;var f=s.value;f!=null?Oa(o,!!s.multiple,f,!1):p!==!!s.multiple&&(s.defaultValue!=null?Oa(o,!!s.multiple,s.defaultValue,!0):Oa(o,!!s.multiple,s.multiple?[]:"",!1))}o[Zc]=s}catch(g){mt(e,e.return,g)}}break;case 6:if(Pr(t,e),Hr(e),r&4){if(e.stateNode===null)throw Error(Y(162));o=e.stateNode,s=e.memoizedProps;try{o.nodeValue=s}catch(g){mt(e,e.return,g)}}break;case 3:if(Pr(t,e),Hr(e),r&4&&n!==null&&n.memoizedState.isDehydrated)try{Wc(t.containerInfo)}catch(g){mt(e,e.return,g)}break;case 4:Pr(t,e),Hr(e);break;case 13:Pr(t,e),Hr(e),o=e.child,o.flags&8192&&(s=o.memoizedState!==null,o.stateNode.isHidden=s,!s||o.alternate!==null&&o.alternate.memoizedState!==null||(N0=St())),r&4&&k1(e);break;case 22:if(u=n!==null&&n.memoizedState!==null,e.mode&1?(Qt=(c=Qt)||u,Pr(t,e),Qt=c):Pr(t,e),Hr(e),r&8192){if(c=e.memoizedState!==null,(e.stateNode.isHidden=c)&&!u&&e.mode&1)for(ee=e,u=e.child;u!==null;){for(d=ee=u;ee!==null;){switch(p=ee,f=p.child,p.tag){case 0:case 11:case 14:case 15:Cc(4,p,p.return);break;case 1:Ca(p,p.return);var y=p.stateNode;if(typeof y.componentWillUnmount=="function"){r=p,n=p.return;try{t=r,y.props=t.memoizedProps,y.state=t.memoizedState,y.componentWillUnmount()}catch(g){mt(r,n,g)}}break;case 5:Ca(p,p.return);break;case 22:if(p.memoizedState!==null){$1(d);continue}}f!==null?(f.return=p,ee=f):$1(d)}u=u.sibling}e:for(u=null,d=e;;){if(d.tag===5){if(u===null){u=d;try{o=d.stateNode,c?(s=o.style,typeof s.setProperty=="function"?s.setProperty("display","none","important"):s.display="none"):(a=d.stateNode,l=d.memoizedProps.style,i=l!=null&&l.hasOwnProperty("display")?l.display:null,a.style.display=A_("display",i))}catch(g){mt(e,e.return,g)}}}else if(d.tag===6){if(u===null)try{d.stateNode.nodeValue=c?"":d.memoizedProps}catch(g){mt(e,e.return,g)}}else if((d.tag!==22&&d.tag!==23||d.memoizedState===null||d===e)&&d.child!==null){d.child.return=d,d=d.child;continue}if(d===e)break e;for(;d.sibling===null;){if(d.return===null||d.return===e)break e;u===d&&(u=null),d=d.return}u===d&&(u=null),d.sibling.return=d.return,d=d.sibling}}break;case 19:Pr(t,e),Hr(e),r&4&&k1(e);break;case 21:break;default:Pr(t,e),Hr(e)}}function Hr(e){var t=e.flags;if(t&2){try{e:{for(var n=e.return;n!==null;){if(sT(n)){var r=n;break e}n=n.return}throw Error(Y(160))}switch(r.tag){case 5:var o=r.stateNode;r.flags&32&&(Uc(o,""),r.flags&=-33);var s=_1(e);kS(e,s,o);break;case 3:case 4:var i=r.stateNode.containerInfo,a=_1(e);_S(e,a,i);break;default:throw Error(Y(161))}}catch(l){mt(e,e.return,l)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function VN(e,t,n){ee=e,lT(e)}function lT(e,t,n){for(var r=(e.mode&1)!==0;ee!==null;){var o=ee,s=o.child;if(o.tag===22&&r){var i=o.memoizedState!==null||xd;if(!i){var a=o.alternate,l=a!==null&&a.memoizedState!==null||Qt;a=xd;var c=Qt;if(xd=i,(Qt=l)&&!c)for(ee=o;ee!==null;)i=ee,l=i.child,i.tag===22&&i.memoizedState!==null?M1(o):l!==null?(l.return=i,ee=l):M1(o);for(;s!==null;)ee=s,lT(s),s=s.sibling;ee=o,xd=a,Qt=c}T1(e)}else o.subtreeFlags&8772&&s!==null?(s.return=o,ee=s):T1(e)}}function T1(e){for(;ee!==null;){var t=ee;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:Qt||If(5,t);break;case 1:var r=t.stateNode;if(t.flags&4&&!Qt)if(n===null)r.componentDidMount();else{var o=t.elementType===t.type?n.memoizedProps:Cr(t.type,n.memoizedProps);r.componentDidUpdate(o,n.memoizedState,r.__reactInternalSnapshotBeforeUpdate)}var s=t.updateQueue;s!==null&&h1(t,s,r);break;case 3:var i=t.updateQueue;if(i!==null){if(n=null,t.child!==null)switch(t.child.tag){case 5:n=t.child.stateNode;break;case 1:n=t.child.stateNode}h1(t,i,n)}break;case 5:var a=t.stateNode;if(n===null&&t.flags&4){n=a;var l=t.memoizedProps;switch(t.type){case"button":case"input":case"select":case"textarea":l.autoFocus&&n.focus();break;case"img":l.src&&(n.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var c=t.alternate;if(c!==null){var u=c.memoizedState;if(u!==null){var d=u.dehydrated;d!==null&&Wc(d)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(Y(163))}Qt||t.flags&512&&ES(t)}catch(p){mt(t,t.return,p)}}if(t===e){ee=null;break}if(n=t.sibling,n!==null){n.return=t.return,ee=n;break}ee=t.return}}function $1(e){for(;ee!==null;){var t=ee;if(t===e){ee=null;break}var n=t.sibling;if(n!==null){n.return=t.return,ee=n;break}ee=t.return}}function M1(e){for(;ee!==null;){var t=ee;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{If(4,t)}catch(l){mt(t,n,l)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount=="function"){var o=t.return;try{r.componentDidMount()}catch(l){mt(t,o,l)}}var s=t.return;try{ES(t)}catch(l){mt(t,s,l)}break;case 5:var i=t.return;try{ES(t)}catch(l){mt(t,i,l)}}}catch(l){mt(t,t.return,l)}if(t===e){ee=null;break}var a=t.sibling;if(a!==null){a.return=t.return,ee=a;break}ee=t.return}}var WN=Math.ceil,zp=Zo.ReactCurrentDispatcher,L0=Zo.ReactCurrentOwner,gr=Zo.ReactCurrentBatchConfig,Ce=0,Mt=null,Ct=null,Bt=0,Kn=0,Ia=Ks(0),Et=0,ru=null,_i=0,Ef=0,F0=0,Ic=null,Cn=null,N0=0,nl=1/0,Co=null,Bp=!1,TS=null,_s=null,wd=!1,Ss=null,Up=0,Ec=0,$S=null,hh=-1,ph=0;function pn(){return Ce&6?St():hh!==-1?hh:hh=St()}function ks(e){return e.mode&1?Ce&2&&Bt!==0?Bt&-Bt:TN.transition!==null?(ph===0&&(ph=V_()),ph):(e=Ne,e!==0||(e=window.event,e=e===void 0?16:Q_(e.type)),e):1}function Dr(e,t,n,r){if(50<Ec)throw Ec=0,$S=null,Error(Y(185));Eu(e,n,r),(!(Ce&2)||e!==Mt)&&(e===Mt&&(!(Ce&2)&&(Ef|=n),Et===4&&gs(e,Bt)),jn(e,r),n===1&&Ce===0&&!(t.mode&1)&&(nl=St()+500,bf&&Vs()))}function jn(e,t){var n=e.callbackNode;T6(e,t);var r=Ip(e,e===Mt?Bt:0);if(r===0)n!==null&&zb(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&zb(n),t===1)e.tag===0?kN(A1.bind(null,e)):yk(A1.bind(null,e)),CN(function(){!(Ce&6)&&Vs()}),n=null;else{switch(W_(r)){case 1:n=d0;break;case 4:n=H_;break;case 16:n=Cp;break;case 536870912:n=K_;break;default:n=Cp}n=mT(n,cT.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function cT(e,t){if(hh=-1,ph=0,Ce&6)throw Error(Y(327));var n=e.callbackNode;if(Na()&&e.callbackNode!==n)return null;var r=Ip(e,e===Mt?Bt:0);if(r===0)return null;if(r&30||r&e.expiredLanes||t)t=Hp(e,r);else{t=r;var o=Ce;Ce|=2;var s=dT();(Mt!==e||Bt!==t)&&(Co=null,nl=St()+500,vi(e,t));do try{XN();break}catch(a){uT(e,a)}while(!0);C0(),zp.current=s,Ce=o,Ct!==null?t=0:(Mt=null,Bt=0,t=Et)}if(t!==0){if(t===2&&(o=rS(e),o!==0&&(r=o,t=MS(e,o))),t===1)throw n=ru,vi(e,0),gs(e,r),jn(e,St()),n;if(t===6)gs(e,r);else{if(o=e.current.alternate,!(r&30)&&!GN(o)&&(t=Hp(e,r),t===2&&(s=rS(e),s!==0&&(r=s,t=MS(e,s))),t===1))throw n=ru,vi(e,0),gs(e,r),jn(e,St()),n;switch(e.finishedWork=o,e.finishedLanes=r,t){case 0:case 1:throw Error(Y(345));case 2:li(e,Cn,Co);break;case 3:if(gs(e,r),(r&130023424)===r&&(t=N0+500-St(),10<t)){if(Ip(e,0)!==0)break;if(o=e.suspendedLanes,(o&r)!==r){pn(),e.pingedLanes|=e.suspendedLanes&o;break}e.timeoutHandle=dS(li.bind(null,e,Cn,Co),t);break}li(e,Cn,Co);break;case 4:if(gs(e,r),(r&4194240)===r)break;for(t=e.eventTimes,o=-1;0<r;){var i=31-Or(r);s=1<<i,i=t[i],i>o&&(o=i),r&=~s}if(r=o,r=St()-r,r=(120>r?120:480>r?480:1080>r?1080:1920>r?1920:3e3>r?3e3:4320>r?4320:1960*WN(r/1960))-r,10<r){e.timeoutHandle=dS(li.bind(null,e,Cn,Co),r);break}li(e,Cn,Co);break;case 5:li(e,Cn,Co);break;default:throw Error(Y(329))}}}return jn(e,St()),e.callbackNode===n?cT.bind(null,e):null}function MS(e,t){var n=Ic;return e.current.memoizedState.isDehydrated&&(vi(e,t).flags|=256),e=Hp(e,t),e!==2&&(t=Cn,Cn=n,t!==null&&AS(t)),e}function AS(e){Cn===null?Cn=e:Cn.push.apply(Cn,e)}function GN(e){for(var t=e;;){if(t.flags&16384){var n=t.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var o=n[r],s=o.getSnapshot;o=o.value;try{if(!Nr(s(),o))return!1}catch{return!1}}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function gs(e,t){for(t&=~F0,t&=~Ef,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-Or(t),r=1<<n;e[n]=-1,t&=~r}}function A1(e){if(Ce&6)throw Error(Y(327));Na();var t=Ip(e,0);if(!(t&1))return jn(e,St()),null;var n=Hp(e,t);if(e.tag!==0&&n===2){var r=rS(e);r!==0&&(t=r,n=MS(e,r))}if(n===1)throw n=ru,vi(e,0),gs(e,t),jn(e,St()),n;if(n===6)throw Error(Y(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,li(e,Cn,Co),jn(e,St()),null}function z0(e,t){var n=Ce;Ce|=1;try{return e(t)}finally{Ce=n,Ce===0&&(nl=St()+500,bf&&Vs())}}function ki(e){Ss!==null&&Ss.tag===0&&!(Ce&6)&&Na();var t=Ce;Ce|=1;var n=gr.transition,r=Ne;try{if(gr.transition=null,Ne=1,e)return e()}finally{Ne=r,gr.transition=n,Ce=t,!(Ce&6)&&Vs()}}function B0(){Kn=Ia.current,rt(Ia)}function vi(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,PN(n)),Ct!==null)for(n=Ct.return;n!==null;){var r=n;switch(w0(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&$p();break;case 3:el(),rt(Mn),rt(on),$0();break;case 5:T0(r);break;case 4:el();break;case 13:rt(lt);break;case 19:rt(lt);break;case 10:I0(r.type._context);break;case 22:case 23:B0()}n=n.return}if(Mt=e,Ct=e=Ts(e.current,null),Bt=Kn=t,Et=0,ru=null,F0=Ef=_i=0,Cn=Ic=null,fi!==null){for(t=0;t<fi.length;t++)if(n=fi[t],r=n.interleaved,r!==null){n.interleaved=null;var o=r.next,s=n.pending;if(s!==null){var i=s.next;s.next=o,r.next=i}n.pending=r}fi=null}return e}function uT(e,t){do{var n=Ct;try{if(C0(),ch.current=Np,Fp){for(var r=dt.memoizedState;r!==null;){var o=r.queue;o!==null&&(o.pending=null),r=r.next}Fp=!1}if(Ei=0,kt=It=dt=null,Pc=!1,eu=0,L0.current=null,n===null||n.return===null){Et=1,ru=t,Ct=null;break}e:{var s=e,i=n.return,a=n,l=t;if(t=Bt,a.flags|=32768,l!==null&&typeof l=="object"&&typeof l.then=="function"){var c=l,u=a,d=u.tag;if(!(u.mode&1)&&(d===0||d===11||d===15)){var p=u.alternate;p?(u.updateQueue=p.updateQueue,u.memoizedState=p.memoizedState,u.lanes=p.lanes):(u.updateQueue=null,u.memoizedState=null)}var f=v1(i);if(f!==null){f.flags&=-257,x1(f,i,a,s,t),f.mode&1&&S1(s,c,t),t=f,l=c;var y=t.updateQueue;if(y===null){var g=new Set;g.add(l),t.updateQueue=g}else y.add(l);break e}else{if(!(t&1)){S1(s,c,t),U0();break e}l=Error(Y(426))}}else if(ot&&a.mode&1){var w=v1(i);if(w!==null){!(w.flags&65536)&&(w.flags|=256),x1(w,i,a,s,t),b0(tl(l,a));break e}}s=l=tl(l,a),Et!==4&&(Et=2),Ic===null?Ic=[s]:Ic.push(s),s=i;do{switch(s.tag){case 3:s.flags|=65536,t&=-t,s.lanes|=t;var S=Gk(s,l,t);d1(s,S);break e;case 1:a=l;var v=s.type,C=s.stateNode;if(!(s.flags&128)&&(typeof v.getDerivedStateFromError=="function"||C!==null&&typeof C.componentDidCatch=="function"&&(_s===null||!_s.has(C)))){s.flags|=65536,t&=-t,s.lanes|=t;var I=Yk(s,a,t);d1(s,I);break e}}s=s.return}while(s!==null)}pT(n)}catch(P){t=P,Ct===n&&n!==null&&(Ct=n=n.return);continue}break}while(!0)}function dT(){var e=zp.current;return zp.current=Np,e===null?Np:e}function U0(){(Et===0||Et===3||Et===2)&&(Et=4),Mt===null||!(_i&268435455)&&!(Ef&268435455)||gs(Mt,Bt)}function Hp(e,t){var n=Ce;Ce|=2;var r=dT();(Mt!==e||Bt!==t)&&(Co=null,vi(e,t));do try{YN();break}catch(o){uT(e,o)}while(!0);if(C0(),Ce=n,zp.current=r,Ct!==null)throw Error(Y(261));return Mt=null,Bt=0,Et}function YN(){for(;Ct!==null;)hT(Ct)}function XN(){for(;Ct!==null&&!x6();)hT(Ct)}function hT(e){var t=gT(e.alternate,e,Kn);e.memoizedProps=e.pendingProps,t===null?pT(e):Ct=t,L0.current=null}function pT(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=UN(n,t),n!==null){n.flags&=32767,Ct=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{Et=6,Ct=null;return}}else if(n=BN(n,t,Kn),n!==null){Ct=n;return}if(t=t.sibling,t!==null){Ct=t;return}Ct=t=e}while(t!==null);Et===0&&(Et=5)}function li(e,t,n){var r=Ne,o=gr.transition;try{gr.transition=null,Ne=1,qN(e,t,n,r)}finally{gr.transition=o,Ne=r}return null}function qN(e,t,n,r){do Na();while(Ss!==null);if(Ce&6)throw Error(Y(327));n=e.finishedWork;var o=e.finishedLanes;if(n===null)return null;if(e.finishedWork=null,e.finishedLanes=0,n===e.current)throw Error(Y(177));e.callbackNode=null,e.callbackPriority=0;var s=n.lanes|n.childLanes;if($6(e,s),e===Mt&&(Ct=Mt=null,Bt=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||wd||(wd=!0,mT(Cp,function(){return Na(),null})),s=(n.flags&15990)!==0,n.subtreeFlags&15990||s){s=gr.transition,gr.transition=null;var i=Ne;Ne=1;var a=Ce;Ce|=4,L0.current=null,KN(e,n),aT(n,e),mN(cS),Ep=!!lS,cS=lS=null,e.current=n,VN(n),w6(),Ce=a,Ne=i,gr.transition=s}else e.current=n;if(wd&&(wd=!1,Ss=e,Up=o),s=e.pendingLanes,s===0&&(_s=null),C6(n.stateNode),jn(e,St()),t!==null)for(r=e.onRecoverableError,n=0;n<t.length;n++)o=t[n],r(o.value,{componentStack:o.stack,digest:o.digest});if(Bp)throw Bp=!1,e=TS,TS=null,e;return Up&1&&e.tag!==0&&Na(),s=e.pendingLanes,s&1?e===$S?Ec++:(Ec=0,$S=e):Ec=0,Vs(),null}function Na(){if(Ss!==null){var e=W_(Up),t=gr.transition,n=Ne;try{if(gr.transition=null,Ne=16>e?16:e,Ss===null)var r=!1;else{if(e=Ss,Ss=null,Up=0,Ce&6)throw Error(Y(331));var o=Ce;for(Ce|=4,ee=e.current;ee!==null;){var s=ee,i=s.child;if(ee.flags&16){var a=s.deletions;if(a!==null){for(var l=0;l<a.length;l++){var c=a[l];for(ee=c;ee!==null;){var u=ee;switch(u.tag){case 0:case 11:case 15:Cc(8,u,s)}var d=u.child;if(d!==null)d.return=u,ee=d;else for(;ee!==null;){u=ee;var p=u.sibling,f=u.return;if(oT(u),u===c){ee=null;break}if(p!==null){p.return=f,ee=p;break}ee=f}}}var y=s.alternate;if(y!==null){var g=y.child;if(g!==null){y.child=null;do{var w=g.sibling;g.sibling=null,g=w}while(g!==null)}}ee=s}}if(s.subtreeFlags&2064&&i!==null)i.return=s,ee=i;else e:for(;ee!==null;){if(s=ee,s.flags&2048)switch(s.tag){case 0:case 11:case 15:Cc(9,s,s.return)}var S=s.sibling;if(S!==null){S.return=s.return,ee=S;break e}ee=s.return}}var v=e.current;for(ee=v;ee!==null;){i=ee;var C=i.child;if(i.subtreeFlags&2064&&C!==null)C.return=i,ee=C;else e:for(i=v;ee!==null;){if(a=ee,a.flags&2048)try{switch(a.tag){case 0:case 11:case 15:If(9,a)}}catch(P){mt(a,a.return,P)}if(a===i){ee=null;break e}var I=a.sibling;if(I!==null){I.return=a.return,ee=I;break e}ee=a.return}}if(Ce=o,Vs(),to&&typeof to.onPostCommitFiberRoot=="function")try{to.onPostCommitFiberRoot(yf,e)}catch{}r=!0}return r}finally{Ne=n,gr.transition=t}}return!1}function j1(e,t,n){t=tl(n,t),t=Gk(e,t,1),e=Es(e,t,1),t=pn(),e!==null&&(Eu(e,1,t),jn(e,t))}function mt(e,t,n){if(e.tag===3)j1(e,e,n);else for(;t!==null;){if(t.tag===3){j1(t,e,n);break}else if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError=="function"||typeof r.componentDidCatch=="function"&&(_s===null||!_s.has(r))){e=tl(n,e),e=Yk(t,e,1),t=Es(t,e,1),e=pn(),t!==null&&(Eu(t,1,e),jn(t,e));break}}t=t.return}}function ZN(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=pn(),e.pingedLanes|=e.suspendedLanes&n,Mt===e&&(Bt&n)===n&&(Et===4||Et===3&&(Bt&130023424)===Bt&&500>St()-N0?vi(e,0):F0|=n),jn(e,t)}function fT(e,t){t===0&&(e.mode&1?(t=dd,dd<<=1,!(dd&130023424)&&(dd=4194304)):t=1);var n=pn();e=Bo(e,t),e!==null&&(Eu(e,t,n),jn(e,n))}function QN(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),fT(e,n)}function JN(e,t){var n=0;switch(e.tag){case 13:var r=e.stateNode,o=e.memoizedState;o!==null&&(n=o.retryLane);break;case 19:r=e.stateNode;break;default:throw Error(Y(314))}r!==null&&r.delete(t),fT(e,n)}var gT;gT=function(e,t,n){if(e!==null)if(e.memoizedProps!==t.pendingProps||Mn.current)_n=!0;else{if(!(e.lanes&n)&&!(t.flags&128))return _n=!1,zN(e,t,n);_n=!!(e.flags&131072)}else _n=!1,ot&&t.flags&1048576&&Sk(t,jp,t.index);switch(t.lanes=0,t.tag){case 2:var r=t.type;dh(e,t),e=t.pendingProps;var o=Za(t,on.current);Fa(t,n),o=A0(null,t,r,e,o,n);var s=j0();return t.flags|=1,typeof o=="object"&&o!==null&&typeof o.render=="function"&&o.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,An(r)?(s=!0,Mp(t)):s=!1,t.memoizedState=o.state!==null&&o.state!==void 0?o.state:null,_0(t),o.updater=Pf,t.stateNode=o,o._reactInternals=t,SS(t,r,e,n),t=wS(null,t,r,!0,s,n)):(t.tag=0,ot&&s&&x0(t),un(null,t,o,n),t=t.child),t;case 16:r=t.elementType;e:{switch(dh(e,t),e=t.pendingProps,o=r._init,r=o(r._payload),t.type=r,o=t.tag=t4(r),e=Cr(r,e),o){case 0:t=xS(null,t,r,e,n);break e;case 1:t=P1(null,t,r,e,n);break e;case 11:t=w1(null,t,r,e,n);break e;case 14:t=b1(null,t,r,Cr(r.type,e),n);break e}throw Error(Y(306,r,""))}return t;case 0:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Cr(r,o),xS(e,t,r,o,n);case 1:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Cr(r,o),P1(e,t,r,o,n);case 3:e:{if(Qk(t),e===null)throw Error(Y(387));r=t.pendingProps,s=t.memoizedState,o=s.element,bk(e,t),Rp(t,r,null,n);var i=t.memoizedState;if(r=i.element,s.isDehydrated)if(s={element:r,isDehydrated:!1,cache:i.cache,pendingSuspenseBoundaries:i.pendingSuspenseBoundaries,transitions:i.transitions},t.updateQueue.baseState=s,t.memoizedState=s,t.flags&256){o=tl(Error(Y(423)),t),t=C1(e,t,r,n,o);break e}else if(r!==o){o=tl(Error(Y(424)),t),t=C1(e,t,r,n,o);break e}else for(Yn=Is(t.stateNode.containerInfo.firstChild),qn=t,ot=!0,$r=null,n=Ek(t,null,r,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling;else{if(Qa(),r===o){t=Uo(e,t,n);break e}un(e,t,r,n)}t=t.child}return t;case 5:return _k(t),e===null&&gS(t),r=t.type,o=t.pendingProps,s=e!==null?e.memoizedProps:null,i=o.children,uS(r,o)?i=null:s!==null&&uS(r,s)&&(t.flags|=32),Zk(e,t),un(e,t,i,n),t.child;case 6:return e===null&&gS(t),null;case 13:return Jk(e,t,n);case 4:return k0(t,t.stateNode.containerInfo),r=t.pendingProps,e===null?t.child=Ja(t,null,r,n):un(e,t,r,n),t.child;case 11:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Cr(r,o),w1(e,t,r,o,n);case 7:return un(e,t,t.pendingProps,n),t.child;case 8:return un(e,t,t.pendingProps.children,n),t.child;case 12:return un(e,t,t.pendingProps.children,n),t.child;case 10:e:{if(r=t.type._context,o=t.pendingProps,s=t.memoizedProps,i=o.value,Ye(Op,r._currentValue),r._currentValue=i,s!==null)if(Nr(s.value,i)){if(s.children===o.children&&!Mn.current){t=Uo(e,t,n);break e}}else for(s=t.child,s!==null&&(s.return=t);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=jo(-1,n&-n),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|=n,l=s.alternate,l!==null&&(l.lanes|=n),mS(s.return,n,t),a.lanes|=n;break}l=l.next}}else if(s.tag===10)i=s.type===t.type?null:s.child;else if(s.tag===18){if(i=s.return,i===null)throw Error(Y(341));i.lanes|=n,a=i.alternate,a!==null&&(a.lanes|=n),mS(i,n,t),i=s.sibling}else i=s.child;if(i!==null)i.return=s;else for(i=s;i!==null;){if(i===t){i=null;break}if(s=i.sibling,s!==null){s.return=i.return,i=s;break}i=i.return}s=i}un(e,t,o.children,n),t=t.child}return t;case 9:return o=t.type,r=t.pendingProps.children,Fa(t,n),o=mr(o),r=r(o),t.flags|=1,un(e,t,r,n),t.child;case 14:return r=t.type,o=Cr(r,t.pendingProps),o=Cr(r.type,o),b1(e,t,r,o,n);case 15:return Xk(e,t,t.type,t.pendingProps,n);case 17:return r=t.type,o=t.pendingProps,o=t.elementType===r?o:Cr(r,o),dh(e,t),t.tag=1,An(r)?(e=!0,Mp(t)):e=!1,Fa(t,n),Ck(t,r,o),SS(t,r,o,n),wS(null,t,r,!0,e,n);case 19:return eT(e,t,n);case 22:return qk(e,t,n)}throw Error(Y(156,t.tag))};function mT(e,t){return U_(e,t)}function e4(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,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 hr(e,t,n,r){return new e4(e,t,n,r)}function H0(e){return e=e.prototype,!(!e||!e.isReactComponent)}function t4(e){if(typeof e=="function")return H0(e)?1:0;if(e!=null){if(e=e.$$typeof,e===l0)return 11;if(e===c0)return 14}return 2}function Ts(e,t){var n=e.alternate;return n===null?(n=hr(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function fh(e,t,n,r,o,s){var i=2;if(r=e,typeof e=="function")H0(e)&&(i=1);else if(typeof e=="string")i=5;else e:switch(e){case ga:return xi(n.children,o,s,t);case a0:i=8,o|=8;break;case Uy:return e=hr(12,n,t,o|2),e.elementType=Uy,e.lanes=s,e;case Hy:return e=hr(13,n,t,o),e.elementType=Hy,e.lanes=s,e;case Ky:return e=hr(19,n,t,o),e.elementType=Ky,e.lanes=s,e;case I_:return _f(n,o,s,t);default:if(typeof e=="object"&&e!==null)switch(e.$$typeof){case P_:i=10;break e;case C_:i=9;break e;case l0:i=11;break e;case c0:i=14;break e;case us:i=16,r=null;break e}throw Error(Y(130,e==null?e:typeof e,""))}return t=hr(i,n,t,o),t.elementType=e,t.type=r,t.lanes=s,t}function xi(e,t,n,r){return e=hr(7,e,r,t),e.lanes=n,e}function _f(e,t,n,r){return e=hr(22,e,r,t),e.elementType=I_,e.lanes=n,e.stateNode={isHidden:!1},e}function am(e,t,n){return e=hr(6,e,null,t),e.lanes=n,e}function lm(e,t,n){return t=hr(4,e.children!==null?e.children:[],e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function n4(e,t,n,r,o){this.tag=t,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=Ug(0),this.expirationTimes=Ug(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Ug(0),this.identifierPrefix=r,this.onRecoverableError=o,this.mutableSourceEagerHydrationData=null}function K0(e,t,n,r,o,s,i,a,l){return e=new n4(e,t,n,a,l),t===1?(t=1,s===!0&&(t|=8)):t=0,s=hr(3,null,null,t),e.current=s,s.stateNode=e,s.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},_0(s),e}function r4(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:fa,key:r==null?null:""+r,children:e,containerInfo:t,implementation:n}}function yT(e){if(!e)return Os;e=e._reactInternals;e:{if(Ni(e)!==e||e.tag!==1)throw Error(Y(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break e;case 1:if(An(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break e}}t=t.return}while(t!==null);throw Error(Y(171))}if(e.tag===1){var n=e.type;if(An(n))return mk(e,n,t)}return t}function ST(e,t,n,r,o,s,i,a,l){return e=K0(n,r,!0,e,o,s,i,a,l),e.context=yT(null),n=e.current,r=pn(),o=ks(n),s=jo(r,o),s.callback=t??null,Es(n,s,o),e.current.lanes=o,Eu(e,o,r),jn(e,r),e}function kf(e,t,n,r){var o=t.current,s=pn(),i=ks(o);return n=yT(n),t.context===null?t.context=n:t.pendingContext=n,t=jo(s,i),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=Es(o,t,i),e!==null&&(Dr(e,o,i,s),lh(e,o,i)),i}function Kp(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 O1(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function V0(e,t){O1(e,t),(e=e.alternate)&&O1(e,t)}function o4(){return null}var vT=typeof reportError=="function"?reportError:function(e){console.error(e)};function W0(e){this._internalRoot=e}Tf.prototype.render=W0.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(Y(409));kf(e,t,null,null)};Tf.prototype.unmount=W0.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;ki(function(){kf(null,e,null,null)}),t[zo]=null}};function Tf(e){this._internalRoot=e}Tf.prototype.unstable_scheduleHydration=function(e){if(e){var t=X_();e={blockedOn:null,target:e,priority:t};for(var n=0;n<fs.length&&t!==0&&t<fs[n].priority;n++);fs.splice(n,0,e),n===0&&Z_(e)}};function G0(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function $f(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==" react-mount-point-unstable "))}function D1(){}function s4(e,t,n,r,o){if(o){if(typeof r=="function"){var s=r;r=function(){var c=Kp(i);s.call(c)}}var i=ST(t,r,e,0,null,!1,!1,"",D1);return e._reactRootContainer=i,e[zo]=i.current,Xc(e.nodeType===8?e.parentNode:e),ki(),i}for(;o=e.lastChild;)e.removeChild(o);if(typeof r=="function"){var a=r;r=function(){var c=Kp(l);a.call(c)}}var l=K0(e,0,!1,null,null,!1,!1,"",D1);return e._reactRootContainer=l,e[zo]=l.current,Xc(e.nodeType===8?e.parentNode:e),ki(function(){kf(t,l,n,r)}),l}function Mf(e,t,n,r,o){var s=n._reactRootContainer;if(s){var i=s;if(typeof o=="function"){var a=o;o=function(){var l=Kp(i);a.call(l)}}kf(t,i,e,o)}else i=s4(n,t,e,o,r);return Kp(i)}G_=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=cc(t.pendingLanes);n!==0&&(h0(t,n|1),jn(t,St()),!(Ce&6)&&(nl=St()+500,Vs()))}break;case 13:ki(function(){var r=Bo(e,1);if(r!==null){var o=pn();Dr(r,e,1,o)}}),V0(e,1)}};p0=function(e){if(e.tag===13){var t=Bo(e,134217728);if(t!==null){var n=pn();Dr(t,e,134217728,n)}V0(e,134217728)}};Y_=function(e){if(e.tag===13){var t=ks(e),n=Bo(e,t);if(n!==null){var r=pn();Dr(n,e,t,r)}V0(e,t)}};X_=function(){return Ne};q_=function(e,t){var n=Ne;try{return Ne=e,t()}finally{Ne=n}};eS=function(e,t,n){switch(t){case"input":if(Gy(e,n),t=n.name,n.type==="radio"&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll("input[name="+JSON.stringify(""+t)+'][type="radio"]'),t=0;t<n.length;t++){var r=n[t];if(r!==e&&r.form===e.form){var o=wf(r);if(!o)throw Error(Y(90));__(r),Gy(r,o)}}}break;case"textarea":T_(e,n);break;case"select":t=n.value,t!=null&&Oa(e,!!n.multiple,t,!1)}};R_=z0;L_=ki;var i4={usingClientEntryPoint:!1,Events:[ku,va,wf,O_,D_,z0]},Wl={findFiberByHostInstance:pi,bundleType:0,version:"18.2.0",rendererPackageName:"react-dom"},a4={bundleType:Wl.bundleType,version:Wl.version,rendererPackageName:Wl.rendererPackageName,rendererConfig:Wl.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:Zo.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=z_(e),e===null?null:e.stateNode},findFiberByHostInstance:Wl.findFiberByHostInstance||o4,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:"18.2.0-next-9e3b772b8-20220608"};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<"u"){var bd=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!bd.isDisabled&&bd.supportsFiber)try{yf=bd.inject(a4),to=bd}catch{}}nr.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=i4;nr.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!G0(t))throw Error(Y(200));return r4(e,t,null,n)};nr.createRoot=function(e,t){if(!G0(e))throw Error(Y(299));var n=!1,r="",o=vT;return t!=null&&(t.unstable_strictMode===!0&&(n=!0),t.identifierPrefix!==void 0&&(r=t.identifierPrefix),t.onRecoverableError!==void 0&&(o=t.onRecoverableError)),t=K0(e,1,!1,null,null,n,!1,r,o),e[zo]=t.current,Xc(e.nodeType===8?e.parentNode:e),new W0(t)};nr.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render=="function"?Error(Y(188)):(e=Object.keys(e).join(","),Error(Y(268,e)));return e=z_(t),e=e===null?null:e.stateNode,e};nr.flushSync=function(e){return ki(e)};nr.hydrate=function(e,t,n){if(!$f(t))throw Error(Y(200));return Mf(null,e,t,!0,n)};nr.hydrateRoot=function(e,t,n){if(!G0(e))throw Error(Y(405));var r=n!=null&&n.hydratedSources||null,o=!1,s="",i=vT;if(n!=null&&(n.unstable_strictMode===!0&&(o=!0),n.identifierPrefix!==void 0&&(s=n.identifierPrefix),n.onRecoverableError!==void 0&&(i=n.onRecoverableError)),t=ST(t,null,e,1,n??null,o,!1,s,i),e[zo]=t.current,Xc(e),r)for(e=0;e<r.length;e++)n=r[e],o=n._getVersion,o=o(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,o]:t.mutableSourceEagerHydrationData.push(n,o);return new Tf(t)};nr.render=function(e,t,n){if(!$f(t))throw Error(Y(200));return Mf(null,e,t,!1,n)};nr.unmountComponentAtNode=function(e){if(!$f(e))throw Error(Y(40));return e._reactRootContainer?(ki(function(){Mf(null,null,e,!1,function(){e._reactRootContainer=null,e[zo]=null})}),!0):!1};nr.unstable_batchedUpdates=z0;nr.unstable_renderSubtreeIntoContainer=function(e,t,n,r){if(!$f(n))throw Error(Y(200));if(e==null||e._reactInternals===void 0)throw Error(Y(38));return Mf(e,t,n,!1,r)};nr.version="18.2.0-next-9e3b772b8-20220608";function xT(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>"u"||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!="function"))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(xT)}catch(e){console.error(e)}}xT(),S_.exports=nr;var zi=S_.exports;const l4=ll(zi);var jS={},wT,R1=zi;wT=jS.createRoot=R1.createRoot,jS.hydrateRoot=R1.hydrateRoot;function Ds({children:e,className:t="",...n}){return h.jsx("svg",{...n,className:ue("tl-svg-container",t),children:e})}function Y0(e,t,n,r){const o=e.x-n.x,s=e.y-n.y,i=r.x-n.x,a=r.y-n.y,l=t.x-e.x,c=t.y-e.y,u=i*s-a*o,d=l*s-c*o,p=a*l-i*c;if(u===0||d===0||p===0)return null;if(p!==0){const f=u/p,y=d/p;if(0<=f&&f<=1&&0<=y&&y<=1)return b.AddXY(e,f*l,f*c)}return null}function Af(e,t,n,r){const o=(t.x-e.x)*(t.x-e.x)+(t.y-e.y)*(t.y-e.y),s=2*((t.x-e.x)*(e.x-n.x)+(t.y-e.y)*(e.y-n.y)),i=n.x*n.x+n.y*n.y+e.x*e.x+e.y*e.y-2*(n.x*e.x+n.y*e.y)-r*r,a=s*s-4*o*i;if(a<0||a===0)return null;const l=Math.sqrt(a),c=(-s+l)/(2*o),u=(-s-l)/(2*o);if((c<0||c>1)&&(u<0||u>1))return null;const d=[];return 0<=c&&c<=1&&d.push(b.Lrp(e,t,c)),0<=u&&u<=1&&d.push(b.Lrp(e,t,u)),d.length===0?null:d}function c4(e,t,n){const r=[];let o;for(let s=0,i=n.length-1;s<i;s++)o=Y0(e,t,n[s],n[s+1]),o&&r.push(o);return r.length===0?null:r}function X0(e,t,n){const r=[];let o;for(let s=1,i=n.length;s<i+1;s++)o=Y0(e,t,n[s-1],n[s%n.length]),o&&r.push(o);return r.length===0?null:r}function u4(e,t,n,r){let o=n.x-e.x,s=n.y-e.y;const i=Math.sqrt(o*o+s*s),a=(i*i-r*r+t*t)/(2*i),l=Math.sqrt(t*t-a*a);return o/=i,s/=i,[new b(e.x+o*a-s*l,e.y+s*a+o*l),new b(e.x+o*a+s*l,e.y+s*a-o*l)]}function OS(e,t,n){const r=[];let o,s,i;for(let a=0,l=n.length;a<l;a++)o=n[a],s=n[(a+1)%n.length],i=Af(o,s,e,t),i&&r.push(...i);return r.length===0?null:r}function L1(e,t,n){const r=[];let o,s,i;for(let a=1,l=n.length;a<l;a++)o=n[a-1],s=n[a],i=Af(o,s,e,t),i&&r.push(...i);return r.length===0?null:r}function Pd(e,t,n){return(n.y-e.y)*(t.x-e.x)>(t.y-e.y)*(n.x-e.x)}function q0(e,t,n,r){return Pd(e,n,r)!==Pd(t,n,r)&&Pd(e,t,n)!==Pd(e,t,r)}function DS(e,t){const n=new Map;let r,o,s,i;for(let a=0,l=e.length;a<l;a++)if(r=e[a],Xn(r,t)){const c=cm(r);n.has(c)||n.set(c,r)}for(let a=0,l=t.length;a<l;a++)if(r=t[a],Xn(r,e)){const c=cm(r);n.has(c)||n.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=t.length;c<u;c++){s=t[c],i=t[(c+1)%t.length];const d=Y0(r,o,s,i);if(d!==null){const p=cm(d);n.has(p)||n.set(p,d)}}}return n.size===0?null:d4([...n.values()])}function cm(e){return`${e.x},${e.y}`}function d4(e){const t=b.Average(e);return e.sort((n,r)=>b.Angle(t,n)-b.Angle(t,r))}function bT(e,t){let n,r,o,s;for(let i=0,a=e.length;i<a;i++){n=e[i],r=e[(i+1)%a];for(let l=0,c=t.length;l<c;l++)if(o=t[l],s=t[(l+1)%c],q0(n,r,o,s))return!0}return!1}function h4(e,t){let n,r,o,s;for(let i=0,a=e.length;i<a;i++){n=e[i],r=e[(i+1)%a];for(let l=1,c=t.length;l<c;l++)if(o=t[l-1],s=t[l],q0(n,r,o,s))return!0}return!1}class ou extends Li{constructor(n){super({...n,isClosed:!1,isFilled:!1});m(this,"start");m(this,"end");m(this,"d");m(this,"u");m(this,"ul");m(this,"_length");const{start:r,end:o}=n;this.start=r,this.end=o,this.d=r.clone().sub(o),this.u=this.d.clone().uni(),this.ul=this.u.len()}get length(){return this._length?this._length:this.d.len()}midPoint(){return this.start.lrp(this.end,.5)}getVertices(){return[this.start,this.end]}nearestPoint(n){const{start:r,end:o,u:s,ul:i}=this;if(i===0)return r;const a=b.Sub(n,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 b(l,c)}hitTestLineSegment(n,r,o=0){return q0(n,r,this.start,this.end)||this.distanceToLineSegment(n,r)<=o}}class Bi extends Li{constructor(n){super({isClosed:!1,isFilled:!1,...n});m(this,"points");m(this,"_segments");m(this,"_length");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{vertices:n}=this;for(let r=0,o=n.length-1;r<o;r++){const s=n[r],i=n[r+1];this._segments.push(new ou({start:s,end:i}))}this.isClosed&&this._segments.push(new ou({start:n[n.length-1],end:n[0]}))}return this._segments}get length(){return this._length||(this._length=this.segments.reduce((n,r)=>n+r.length,0)),this._length}getVertices(){return this.points}nearestPoint(n){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(n),a=b.Dist2(i,n),a<s&&(o=i,s=a);if(!o)throw Error("nearest point not found");return o}hitTestLineSegment(n,r,o=0){const{segments:s}=this;for(let i=0,a=s.length;i<a;i++)if(s[i].hitTestLineSegment(n,r,o))return!0;return!1}}class bt extends Bi{constructor(t){super({...t}),this.isClosed=!0}}class Ho extends bt{constructor(n){const{x:r=0,y:o=0,width:s,height:i}=n;super({...n,points:[new b(r,o),new b(r+s,o),new b(r+s,o+i),new b(r,o+i)]});m(this,"x");m(this,"y");m(this,"w");m(this,"h");this.x=r,this.y=o,this.w=s,this.h=i}getBounds(){return new te(this.x,this.y,this.w,this.h)}}class Rr{constructor(t){m(this,"canSnap",()=>!0);m(this,"canScroll",()=>!1);m(this,"canBind",(t,n)=>!0);m(this,"canEdit",()=>!1);m(this,"canResize",()=>!0);m(this,"canEditInReadOnly",()=>!1);m(this,"canCrop",()=>!1);m(this,"hideResizeHandles",()=>!1);m(this,"hideRotateHandle",()=>!1);m(this,"hideSelectionBoundsBg",()=>!1);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"isAspectRatioLocked",()=>!1);m(this,"onBeforeCreate");m(this,"onBeforeUpdate");m(this,"onDragShapesOver");m(this,"onDragShapesOut");m(this,"onDropShapesOver");m(this,"onResizeStart");m(this,"onResize");m(this,"onResizeEnd");m(this,"onTranslateStart");m(this,"onTranslate");m(this,"onTranslateEnd");m(this,"onHandleDrag");m(this,"onRotateStart");m(this,"onRotate");m(this,"onRotateEnd");m(this,"onBindingChange");m(this,"onChildrenChange");m(this,"onDoubleClickHandle");m(this,"onDoubleClickEdge");m(this,"onDoubleClick");m(this,"onClick");m(this,"onEditEnd");this.editor=t}providesBackgroundForChildren(t){return!1}canReceiveNewChildrenOfType(t,n){return!1}canDropShapes(t,n){return!1}expandSelectionOutlinePx(t){return 0}getCanvasSvgDefs(){return[]}getBoundsSnapGeometry(t){return{}}getHandleSnapGeometry(t){return{}}}m(Rr,"props"),m(Rr,"migrations"),m(Rr,"type");function p4(e,t,n={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=n;let c=0,u=0,d=1,p=0,f=0;switch(l){case"dashed":{d=1,c=Math.min(t*a,e/4);break}case"dotted":{d=100,c=t/d;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*d)),u-=u%o,u<3&&l==="dashed"?e/t<5?(c=e,u=1,p=0):(c=e*.333,p=e*.333):(u=Math.max(u,3),c=e/u/(2*d),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 F1({bounds:e,className:t}){const n=z(),r=K("zoom level",()=>n.getZoomLevel(),[n]);return h.jsx("g",{className:t,pointerEvents:"none",strokeLinecap:"round",strokeLinejoin:"round",children:e.sides.map((o,s)=>{const{strokeDasharray:i,strokeDashoffset:a}=p4(o[0].dist(o[1]),1/r,{style:"dashed",lengthRatio:4});return h.jsx("line",{x1:o[0].x,y1:o[0].y,x2:o[1].x,y2:o[1].y,strokeDasharray:i,strokeDashoffset:a},s)})})}class gh extends Rr{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"canBind",()=>!1);m(this,"onChildrenChange",n=>{const r=this.editor.getSortedChildIdsForParent(n.id);if(r.length===0){this.editor.getCurrentPageState().focusedGroupId===n.id&&this.editor.popFocusedGroupId(),this.editor.deleteShapes([n.id]);return}else if(r.length===1){this.editor.getCurrentPageState().focusedGroupId===n.id&&this.editor.popFocusedGroupId(),this.editor.reparentShapes(r,n.parentId),this.editor.deleteShapes([n.id]);return}})}getDefaultProps(){return{}}getGeometry(n){const r=this.editor.getSortedChildIdsForParent(n.id);return r.length===0?new Ho({width:1,height:1,isFilled:!1}):new Fr({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 bt({points:a,isFilled:!0}):new Bi({points:a})})})}component(n){const r=this.editor.getErasingShapeIds().includes(n.id),{hintingShapeIds:o}=this.editor.getCurrentPageState(),s=o.length>0&&o.some(l=>l!==n.id&&this.editor.isShapeOfType(this.editor.getShape(l),"group")),i=this.editor.getCurrentPageState().focusedGroupId!==n.id;if(!r&&(i||s))return null;const a=this.editor.getShapeGeometry(n).bounds;return h.jsx(Ds,{id:n.id,children:h.jsx(F1,{className:"tl-group",bounds:a})})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds;return h.jsx(F1,{className:"",bounds:r})}}m(gh,"type","group"),m(gh,"props",mE),m(gh,"migrations",yE);const PT=[gh],f4=new Set(PT.map(e=>e.type));function CT(e){const t=[...PT],n=new Set;for(const r of e){if(f4.has(r.type))throw new Error(`Shape type "${r.type}" is a core shapes type and cannot be overridden`);if(n.has(r.type))throw new Error(`Shape type "${r.type}" is defined more than once`);t.push(r),n.add(r.type)}return t}function N1(e,t){if(!t)return!1;switch(e.type){case"mixed":return t.type==="mixed";case"shared":return t.type==="shared"&&e.value===t.value;default:throw Bs(e)}}class g4{constructor(t){m(this,"map");this.map=new Map(t)}get(t){return this.map.get(t)}getAsKnownValue(t){const n=this.get(t);if(n&&n.type!=="mixed")return n.value}get size(){return this.map.size}equals(t){if(this.size!==t.size)return!1;const n=new Set;for(const[r,o]of this){if(!N1(o,t.get(r)))return!1;n.add(r)}for(const[r,o]of t)if(!n.has(r)&&!N1(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 RS extends g4{set(t,n){this.map.set(t,n)}applyValue(t,n){const r=this.get(t);if(!r){this.set(t,{type:"shared",value:n});return}switch(r.type){case"mixed":return;case"shared":r.value!==n&&this.set(t,{type:"mixed"});return;default:Bs(r,"type")}}}class jf{constructor(){m(this,"items",new WeakMap)}get(t,n){return this.items.has(t)||this.items.set(t,n(t)),this.items.get(t)}access(t){return this.items.get(t)}set(t,n){this.items.set(t,n)}has(t){return this.items.has(t)}invalidate(t){this.items.delete(t)}bust(){this.items=new WeakMap}}function m4(e,t,n){return fetch(e).then(function(r){return r.arrayBuffer()}).then(function(r){return new File([r],t,{type:n})})}function y4(e,t){var o;let n=e;const r=new Set(t);for(;r.has(n);)n=(o=/^.*(\d+)$/.exec(n))!=null&&o[1]?n.replace(/(\d+)(?=\D?)$/,s=>(+s+1).toString()):`${n} 1`;return n}function Cd(e,t,n){if(n.length===0)return[];const r=new Map;for(const s of fe(n.map(i=>e.getShape(i)))){const{parentId:i}=s;r.has(i)||r.set(i,{children:fe(e.getSortedChildIdsForParent(i).map(a=>e.getShape(a))),moving:new Set}),r.get(i).moving.add(s)}const o=[];switch(t){case"toBack":{r.forEach(({moving:s,children:i})=>S4(s,i,o));break}case"toFront":{r.forEach(({moving:s,children:i})=>v4(s,i,o));break}case"forward":{r.forEach(({moving:s,children:i})=>x4(s,i,o));break}case"backward":{r.forEach(({moving:s,children:i})=>w4(s,i,o));break}}return o}function S4(e,t,n){const r=t.length;if(e.size===r)return;let o,s;for(let i=0;i<r;i++){const a=t[i];if(e.has(a))o=a.index,e.delete(a);else{s=a.index;break}}if(e.size!==0){const i=Wa(o,s,e.size);n.push(...Array.from(e.values()).sort(Lt).map((a,l)=>({...a,index:i[l]})))}}function v4(e,t,n){const r=t.length;if(e.size===r)return;let o,s;for(let i=r-1;i>-1;i--){const a=t[i];if(e.has(a))s=a.index,e.delete(a);else{o=a.index;break}}if(e.size!==0){const i=Wa(o,s,e.size);n.push(...Array.from(e.values()).sort(Lt).map((a,l)=>({...a,index:i[l]})))}}function x4(e,t,n){var s;const r=t.length;if(e.size===r)return;let o={name:"skipping"};for(let i=0;i<r;i++){const a=e.has(t[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;const{selectIndex:l}=o;Wa(t[i].index,(s=t[i+1])==null?void 0:s.index,i-l).forEach((c,u)=>n.push({...t[l+u],index:c})),o={name:"skipping"};break}}}}function w4(e,t,n){var s;const r=t.length;if(e.size===r)return;let o={name:"skipping"};for(let i=r-1;i>-1;i--){const a=e.has(t[i]);switch(o.name){case"skipping":{if(!a)continue;o={name:"selecting",selectIndex:i};break}case"selecting":{if(a)continue;Wa((s=t[i-1])==null?void 0:s.index,t[i].index,o.selectIndex-i).forEach((l,c)=>{n.push({...t[i+c+1],index:l})}),o={name:"skipping"};break}}}}function IT({editor:e}){const t=e.getSelectedShapes(),n=e.getSelectionRotation(),r=e.getSelectionRotatedPageBounds(),{inputs:{originPagePoint:o}}=e;if(!r)return null;const s=r.center.clone().rotWith(r.point,n);return{selectionPageCenter:s,initialCursorAngle:s.angle(o),initialSelectionRotation:n,shapeSnapshots:t.map(i=>({shape:vt(i),initialPagePoint:e.getShapePageTransform(i.id).point()}))}}function mh({delta:e,editor:t,snapshot:n,stage:r}){const{selectionPageCenter:o,shapeSnapshots:s}=n;t.updateShapes(s.map(({shape:a,initialPagePoint:l})=>{const c=wn(a.parentId)?t.getShapePageTransform(a.parentId):ne.Identity(),u=b.RotWith(l,o,e),d=ne.applyToPoint(ne.Inverse(c),u),p=ws(a.rotation+e);return{id:a.id,type:a.type,x:d.x,y:d.y,rotation:p}}));const i=[];s.forEach(({shape:a})=>{var d,p,f;const l=t.getShape(a.id);if(!l)return;const c=t.getShapeUtil(a);if(r==="start"||r==="one-off"){const y=(d=c.onRotateStart)==null?void 0:d.call(c,a);y&&i.push(y)}const u=(p=c.onRotate)==null?void 0:p.call(c,a,l);if(u&&i.push(u),r==="end"||r==="one-off"){const y=(f=c.onRotateEnd)==null?void 0:f.call(c,a,l);y&&i.push(y)}}),i.length>0&&t.updateShapes(i)}const b4=e=>{const{store:t}=e,n=t.query.filterHistory("shape"),r=t.query.records("shape",()=>({type:{eq:"arrow"}}));function o(){const s=r.get(),i={};for(const a of s){const{start:l,end:c}=a.props;if(l.type==="binding"){const u=i[l.boundShapeId];u?u.push({arrowId:a.id,handleId:"start"}):i[l.boundShapeId]=[{arrowId:a.id,handleId:"start"}]}if(c.type==="binding"){const u=i[c.boundShapeId];u?u.push({arrowId:a.id,handleId:"end"}):i[c.boundShapeId]=[{arrowId:a.id,handleId:"end"}]}}return i}return G("arrowBindingsIndex",(s,i)=>{if(Si(s))return o();const a=s,l=n.getDiffSince(i);if(l===Tn)return o();let c;function u(f){c||(c={...a}),c[f]?c[f]===a[f]&&(c[f]=[...c[f]]):c[f]=[]}function d(f,y,g){u(f),c[f]=c[f].filter(w=>w.arrowId!==y||w.handleId!==g),c[f].length===0&&delete c[f]}function p(f,y,g){u(f),c[f].push({arrowId:y,handleId:g})}for(const f of l){for(const y of Object.values(f.added))if(e.isShapeOfType(y,"arrow")){const{start:g,end:w}=y.props;g.type==="binding"&&p(g.boundShapeId,y.id,"start"),w.type==="binding"&&p(w.boundShapeId,y.id,"end")}for(const[y,g]of Object.values(f.updated))if(!(!e.isShapeOfType(y,"arrow")||!e.isShapeOfType(g,"arrow")))for(const w of["start","end"]){const S=y.props[w],v=g.props[w];S.type==="binding"&&v.type==="point"?d(S.boundShapeId,y.id,w):S.type==="point"&&v.type==="binding"?p(v.boundShapeId,g.id,w):S.type==="binding"&&v.type==="binding"&&S.boundShapeId!==v.boundShapeId&&(d(S.boundShapeId,y.id,w),p(v.boundShapeId,g.id,w))}for(const y of Object.values(f.removed))if(e.isShapeOfType(y,"arrow")){const{start:g,end:w}=y.props;g.type==="binding"&&d(g.boundShapeId,y.id,"start"),w.type==="binding"&&d(w.boundShapeId,y.id,"end")}}return c??a})};function um(e,t,n){const r=e.getShapeMaskedPageBounds(t);return r===void 0?!0:!n.includes(r)}const P4=e=>{const t=Number.isFinite(e.renderingBoundsMargin),n=e.store.query.filterHistory("shape");let r=null,o;function s(i){const a=i.getCurrentPageShapeIds();r=i.getCurrentPageId();const l=i.getViewportPageBounds();o=l.clone();const c=new Set;return a.forEach(u=>{um(i,u,l)&&c.add(u)}),c}return G("getCulledShapes",(i,a)=>{if(!t)return new Set;if(Si(i))return s(e);const l=n.getDiffSince(a);if(l===Tn)return s(e);const c=e.getCurrentPageId();if(r!==c)return s(e);const u=e.getViewportPageBounds();if(!o||!u.equals(o))return s(e);let d=null;const p=y=>{i.has(y)||(d||(d=new Set(i)),d.add(y))},f=y=>{i.has(y)&&(d||(d=new Set(i)),d.delete(y))};for(const y of l){for(const g of Object.values(y.added))ms(g)&&um(e,g.id,u)&&p(g.id);for(const[g,w]of Object.values(y.updated))ms(w)&&(um(e,w.id,u)?p(w.id):f(w.id));for(const g of Object.keys(y.removed))wn(g)&&f(g)}return d??i})},C4=e=>{const t=e.query.ids("shape"),n=e.query.filterHistory("shape");function r(){const o={},s=t.get(),i=Array(s.size);return s.forEach(a=>i.push(e.get(a))),i.sort(Lt),i.forEach(a=>{o[a.parentId]||(o[a.parentId]=[]),o[a.parentId].push(a.id)}),o}return G("parentsToChildrenWithIndexes",(o,s)=>{if(Si(o))return r();const i=n.getDiffSince(s);if(i===Tn)return r();if(i.length===0)return o;let a=null;const l=d=>{a||(a={...o}),a[d]?a[d]===o[d]&&(a[d]=[...a[d]]):a[d]=[]},c=new Set;let u;for(let d=0,p=i.length;d<p;d++){u=i[d];for(const f of Object.values(u.added))ms(f)&&(l(f.parentId),a[f.parentId].push(f.id),c.add(a[f.parentId]));for(const[f,y]of Object.values(u.updated))if(ms(y)&&ms(f)){if(f.parentId!==y.parentId)l(f.parentId),l(y.parentId),a[f.parentId].splice(a[f.parentId].indexOf(y.id),1),a[y.parentId].push(y.id),c.add(a[y.parentId]);else if(f.index!==y.index){l(y.parentId);const g=a[y.parentId].indexOf(y.id);a[y.parentId][g]=y.id,c.add(a[y.parentId])}}for(const f of Object.values(u.removed))ms(f)&&(l(f.parentId),a[f.parentId].splice(a[f.parentId].indexOf(f.id),1))}for(const d of c){const p=fe(d.map(f=>e.get(f)));p.sort(Lt),d.splice(0,d.length,...p.map(f=>f.id))}return a??o})},dm=(e,t,n)=>{for(;!xn(n.parentId);){const r=e.get(n.parentId);if(!r)return!1;n=r}return n.parentId===t},I4=(e,t)=>{const n=e.query.ids("shape");let r=null;function o(){const s=t();return r=s,new Set([...n.get()].filter(i=>dm(e,s,e.get(i))))}return G("_shapeIdsInCurrentPage",(s,i)=>{if(Si(s))return o();const a=t();if(a!==r)return o();const l=e.history.getDiffSince(i);if(l===Tn)return o();const c=new th(s);for(const d of l){for(const p of Object.values(d.added))ms(p)&&dm(e,a,p)&&c.add(p.id);for(const[p,f]of Object.values(d.updated))ms(f)&&(dm(e,a,f)?c.add(f.id):c.remove(f.id));for(const p of Object.keys(d.removed))wn(p)&&c.remove(p)}const u=c.get();return u?oc(u.value,u.diff):s})},ET=x.createContext(null);function E4({context:e,editor:t,children:n}){return h.jsx(ff.Provider,{value:t,children:h.jsx(ET.Provider,{value:e,children:n})})}function _T(){const e=x.useContext(ET);return e?{isDarkMode:e.isDarkMode}:null}async function _4(e,t,n={}){var P,E;const r=typeof t[0]=="string"?t:t.map(_=>_.id);if(r.length===0)return;if(!window.document)throw Error("No document");const{scale:o=1,background:s=!1,padding:i=c3,preserveAspectRatio:a=!1}=n,l=n.darkMode??e.user.getIsDarkMode(),c=qo({isDarkMode:l}),u=e.getShapeAndDescendantIds(r),d=e.getUnorderedRenderingShapes(!1).filter(({id:_})=>u.has(_));let p=null;if(n.bounds)p=n.bounds;else for(const{id:_}of d){const k=e.getShapeMaskedPageBounds(_);k&&(p?p.union(k):p=k.clone())}if(!p)return;const f=r.length===1&&e.isShapeOfType(e.getShape(r[0]),"frame")?r[0]:null;f||p.expandBy(i);const y=p.width*o,g=p.height*o;try{(E=(P=document.body).focus)==null||E.call(P)}catch{}const w=[],S=new Map,v={isDarkMode:l,addExportDef:_=>{if(S.has(_.key))return;const k=(async()=>{const $=await _.getElement();$&&w.push(h.jsx(x.Fragment,{children:$},w.length))})();S.set(_.key,k)}},C=(await Promise.all(d.map(async({id:_,opacity:k,index:$,backgroundIndex:T})=>{var V,U;if(_===f)return[];const j=e.getShape(_);if(e.isShapeOfType(j,"group"))return[];const L=e.getShapeUtil(j);let N=await((V=L.toSvg)==null?void 0:V.call(L,j,v)),F=await((U=L.toBackgroundSvg)==null?void 0:U.call(L,j,v));if(!N&&!F){const H=e.getShapePageBounds(j);N=h.jsx("rect",{width:H.w,height:H.h,fill:c.solid,stroke:c.grey.pattern,strokeWidth:1})}let B=e.getShapePageTransform(j).toCssString();"scale"in j.props&&j.props.scale!==1&&(B=`${B} scale(${j.props.scale}, ${j.props.scale})`),N&&(N=h.jsx("g",{transform:B,opacity:k,children:N},j.id)),F&&(F=h.jsx("g",{transform:B,opacity:k,children:F},`bg_${j.id}`));const q=e.getShapeMask(j.id);if(q){const H=`mask_${j.id.replace(":","_")}`;w.push(h.jsx("clipPath",{id:H,children:h.jsx("path",{d:`M${q.map(({x:Z,y:ce})=>`${Z},${ce}`).join("L")}Z`})},w.length)),N&&(N=h.jsx("g",{clipPath:`url(#${H})`,children:N},j.id)),F&&(F=h.jsx("g",{clipPath:`url(#${H})`,children:F},`bg_${j.id}`))}const Q=[];return N&&Q.push({zIndex:$,element:N}),F&&Q.push({zIndex:T,element:F}),Q}))).flat();return await Promise.all(S.values()),{jsx:h.jsx(E4,{editor:e,context:v,children:h.jsxs("svg",{preserveAspectRatio:a||void 0,direction:"ltr",width:y,height:g,viewBox:`${p.minX} ${p.minY} ${p.width} ${p.height}`,strokeLinecap:"round",strokeLinejoin:"round",style:{backgroundColor:s?f?c.solid:c.background:"transparent"},children:[h.jsx("defs",{children:w}),C.sort((_,k)=>_.zIndex-k.zIndex).map(({element:_})=>_)]})}),width:y,height:g}}const k4=40;class T4{constructor(t){m(this,"_clickId","");m(this,"_clickTimeout");m(this,"_clickScreenPoint");m(this,"_previousScreenPoint");m(this,"_getClickTimeout",(t,n=nt())=>{this._clickId=n,clearTimeout(this._clickTimeout),this._clickTimeout=setTimeout(()=>{if(this._clickState===t&&this._clickId===n){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"}},t==="idle"||t==="pendingDouble"?a3:l3)});m(this,"_clickState","idle");m(this,"lastPointerInfo",{});m(this,"transformPointerDownEvent",t=>{if(!this._clickState)return t;switch(this._clickScreenPoint=b.From(t.point),this._previousScreenPoint&&this._previousScreenPoint.dist(this._clickScreenPoint)>k4&&(this._clickState="idle"),this._previousScreenPoint=this._clickScreenPoint,this.lastPointerInfo=t,this._clickState){case"idle":return this._clickState="pendingDouble",this._clickTimeout=this._getClickTimeout(this._clickState),t;case"pendingDouble":return this._clickState="pendingTriple",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"double_click",phase:"down"};case"pendingTriple":return this._clickState="pendingQuadruple",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"triple_click",phase:"down"};case"pendingQuadruple":return this._clickState="pendingOverflow",this._clickTimeout=this._getClickTimeout(this._clickState),{...t,type:"click",name:"quadruple_click",phase:"down"};case"pendingOverflow":return this._clickState="overflow",this._clickTimeout=this._getClickTimeout(this._clickState),t;default:return this._clickTimeout=this._getClickTimeout(this._clickState),t}});m(this,"transformPointerUpEvent",t=>{if(!this._clickState)return t;switch(this._clickScreenPoint=b.From(t.point),this._clickState){case"pendingTriple":return{...this.lastPointerInfo,type:"click",name:"double_click",phase:"up"};case"pendingQuadruple":return{...this.lastPointerInfo,type:"click",name:"triple_click",phase:"up"};case"pendingOverflow":return{...this.lastPointerInfo,type:"click",name:"quadruple_click",phase:"up"};default:return t}});m(this,"cancelDoubleClickTimeout",()=>{this._clickTimeout=clearTimeout(this._clickTimeout),this._clickState="idle"});m(this,"handleMove",()=>{this._clickState!=="idle"&&this._clickScreenPoint&&b.Dist2(this._clickScreenPoint,this.editor.inputs.currentScreenPoint)>(this.editor.getInstanceState().isCoarsePointer?Ly:Fc)&&this.cancelDoubleClickTimeout()});this.editor=t}get clickState(){return this._clickState}}class $4{constructor(t){m(this,"isSafari");m(this,"isIos");m(this,"isChromeForIos");m(this,"isFirefox");m(this,"isAndroid");this.editor=t,typeof window<"u"&&"navigator"in window?(this.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),this.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),this.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),this.isFirefox=/firefox/i.test(navigator.userAgent),this.isAndroid=/android/i.test(navigator.userAgent)):(this.isSafari=!1,this.isIos=!1,this.isChromeForIos=!1,this.isFirefox=!1,this.isAndroid=!1)}}function si(e){if(e){let t=z1;for(;e.length;)t=t.push(e.pop());return t}return z1}class M4{constructor(){m(this,"length",0);m(this,"head",null);m(this,"tail",this)}push(t){return new Z0(t,this)}toArray(){return $s}[Symbol.iterator](){return{next(){return{value:void 0,done:!0}}}}}const z1=new M4;class Z0{constructor(t,n){m(this,"length");this.head=t,this.tail=n,this.length=n.length+1}push(t){return new Z0(t,this)}toArray(){return Array.from(this)}[Symbol.iterator](){let t=this;return{next(){if(t.length){const n=t.head;return t=t.tail,{value:n,done:!1}}else return{value:void 0,done:!0}}}}}class A4{constructor(t,n){m(this,"_undos",In("HistoryManager.undos",si()));m(this,"_redos",In("HistoryManager.redos",si()));m(this,"_batchDepth",0);m(this,"onBatchComplete",()=>{});m(this,"_commands",{});m(this,"createCommand",(t,n,r)=>{if(this._commands[t])throw new Error(`Duplicate command: ${t}`);this._commands[t]=r;const o=(...s)=>{if(!this._batchDepth)return this.batch(()=>o(...s)),this.ctx;const i=n(...s);if(!i)return this.ctx;const{data:a,ephemeral:l,squashing:c,preservesRedoStack:u}=i;if(this.ignoringUpdates((d,p)=>(r.do(a),{undos:d,redos:p})),!l){const d=this._undos.get().head;c&&d&&d.type==="command"&&d.name===t&&d.preservesRedoStack===u?this._undos.update(p=>p.tail.push({...d,data:r.squash(d.data,a)})):this._undos.update(p=>p.push({type:"command",name:t,data:a,preservesRedoStack:u})),i.preservesRedoStack||this._redos.set(si()),this.ctx.emit("change-history",{reason:"push"})}return this.ctx};return o});m(this,"batch",t=>{try{this._batchDepth++,this._batchDepth===1?Tr(()=>{const n=this._undos.get().head;t(),n!==this._undos.get().head&&this.onBatchComplete()}):t()}catch(n){throw this.annotateError(n),n}finally{this._batchDepth--}return this});m(this,"ignoringUpdates",t=>{let n=this._undos.get(),r=this._redos.get();this._undos.set(si()),this._redos.set(si());try{({undos:n,redos:r}=Tr(()=>t(n,r)))}finally{this._undos.set(n),this._redos.set(r)}});m(this,"_undo",({pushToRedoStack:t,toMark:n=void 0})=>(this.ignoringUpdates((r,o)=>{var s;if(r.length===0)return{undos:r,redos:o};for(;((s=r.head)==null?void 0:s.type)==="STOP";){const i=r.head;if(r=r.tail,t&&(o=o.push(i)),i.id===n)return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o}}if(r.length===0)return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o};for(;r.head;){const i=r.head;if(r=r.tail,t&&(o=o.push(i)),i.type==="STOP"){if(i.onUndo&&(!n||i.id===n))return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o}}else this._commands[i.name].undo(i.data)}return this.ctx.emit("change-history",t?{reason:"undo"}:{reason:"bail",markId:n}),{undos:r,redos:o}}),this));m(this,"undo",()=>(this._undo({pushToRedoStack:!0}),this));m(this,"redo",()=>(this.ignoringUpdates((t,n)=>{var r;if(n.length===0)return{undos:t,redos:n};for(;((r=n.head)==null?void 0:r.type)==="STOP";)t=t.push(n.head),n=n.tail;if(n.length===0)return this.ctx.emit("change-history",{reason:"redo"}),{undos:t,redos:n};for(;n.head;){const o=n.head;if(t=t.push(n.head),n=n.tail,o.type==="STOP"){if(o.onRedo)break}else{const s=this._commands[o.name];s.redo?s.redo(o.data):s.do(o.data)}}return this.ctx.emit("change-history",{reason:"redo"}),{undos:t,redos:n}}),this));m(this,"bail",()=>(this._undo({pushToRedoStack:!1}),this));m(this,"bailToMark",t=>(this._undo({pushToRedoStack:!1,toMark:t}),this));m(this,"mark",(t=nt(),n=!0,r=!0)=>{const o=this._undos.get().head;return o&&o.type==="STOP"&&o.id===t&&o.onUndo===n&&o.onRedo===r?o.id:(this._undos.update(s=>s.push({type:"STOP",id:t,onUndo:n,onRedo:r})),this.ctx.emit("mark-history",{id:t}),t)});this.ctx=t,this.annotateError=n}getNumUndos(){return this._undos.get().length}getNumRedos(){return this._redos.get().length}clear(){this._undos.set(si()),this._redos.set(si())}}class j4{constructor(t){m(this,"scribbleItems",new Map);m(this,"state","paused");m(this,"addScribble",(t,n=nt())=>{const r={id:n,scribble:{id:n,size:20,color:"accent",opacity:.8,delay:0,points:[],shrink:.1,taper:!0,...t,state:"starting"},timeoutMs:0,delayRemaining:t.delay??0,prev:null,next:null};return this.scribbleItems.set(n,r),r});m(this,"stop",t=>{const n=this.scribbleItems.get(t);if(!n)throw Error(`Scribble with id ${t} not found`);return n.delayRemaining=Math.min(n.delayRemaining,200),n.scribble.state="stopping",n});m(this,"addPoint",(t,n,r)=>{const o=this.scribbleItems.get(t);if(!o)throw Error(`Scribble with id ${t} not found`);const{prev:s}=o,i={x:n,y:r,z:.5};return(!s||b.Dist(s,i)>=1)&&(o.next=i),o});m(this,"tick",t=>{this.scribbleItems.size!==0&&this.editor.batch(()=>{this.scribbleItems.forEach(n=>{if(n.scribble.state==="starting"){const{next:l,prev:c}=n;l&&l!==c&&(n.prev=l,n.scribble.points.push(l)),n.scribble.points.length>8&&(n.scribble.state="active");return}n.delayRemaining>0&&(n.delayRemaining=Math.max(0,n.delayRemaining-t)),n.timeoutMs+=t,n.timeoutMs>=16&&(n.timeoutMs=0);const{delayRemaining:r,timeoutMs:o,prev:s,next:i,scribble:a}=n;switch(a.state){case"active":{i&&i!==s?(n.prev=i,a.points.push(i),r===0&&a.points.length>8&&a.points.shift()):o===0&&(a.points.length>1?a.points.shift():n.delayRemaining=a.delay);break}case"stopping":{if(n.delayRemaining===0&&o===0){if(a.points.length===1){this.scribbleItems.delete(n.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:n})=>({...n,points:[...n.points]})).slice(-5)})})});this.editor=t}reset(){this.editor.updateInstanceState({scribbles:[]}),this.scribbleItems.clear()}}class O4{constructor(t){m(this,"_beforeCreateHandlers",{});m(this,"_afterCreateHandlers",{});m(this,"_beforeChangeHandlers",{});m(this,"_afterChangeHandlers",{});m(this,"_beforeDeleteHandlers",{});m(this,"_afterDeleteHandlers",{});m(this,"_batchCompleteHandlers",[]);this.editor=t,t.store.onBeforeCreate=(r,o)=>{const s=this._beforeCreateHandlers[r.typeName];if(s){let i=r;for(const a of s)i=a(i,o);return i}return r},t.store.onAfterCreate=(r,o)=>{const s=this._afterCreateHandlers[r.typeName];if(s)for(const i of s)i(r,o)},t.store.onBeforeChange=(r,o,s)=>{const i=this._beforeChangeHandlers[o.typeName];if(i){let a=o;for(const l of i)a=l(r,a,s);return a}return o};let n=0;t.store.onAfterChange=(r,o,s)=>{if(n++,n>1e3)console.error("[CleanupManager.onAfterChange] Maximum update depth exceeded, bailing out.");else{const i=this._afterChangeHandlers[o.typeName];if(i)for(const a of i)a(r,o,s)}n--},t.store.onBeforeDelete=(r,o)=>{const s=this._beforeDeleteHandlers[r.typeName];if(s){for(const i of s)if(i(r,o)===!1)return!1}},t.store.onAfterDelete=(r,o)=>{const s=this._afterDeleteHandlers[r.typeName];if(s)for(const i of s)i(r,o)},t.history.onBatchComplete=()=>{this._batchCompleteHandlers.forEach(r=>r())}}registerBeforeCreateHandler(t,n){return this._beforeCreateHandlers[t]||(this._beforeCreateHandlers[t]=[]),this._beforeCreateHandlers[t].push(n),()=>ii(this._beforeCreateHandlers[t],n)}registerAfterCreateHandler(t,n){return this._afterCreateHandlers[t]||(this._afterCreateHandlers[t]=[]),this._afterCreateHandlers[t].push(n),()=>ii(this._afterCreateHandlers[t],n)}registerBeforeChangeHandler(t,n){return this._beforeChangeHandlers[t]||(this._beforeChangeHandlers[t]=[]),this._beforeChangeHandlers[t].push(n),()=>ii(this._beforeChangeHandlers[t],n)}registerAfterChangeHandler(t,n){return this._afterChangeHandlers[t]||(this._afterChangeHandlers[t]=[]),this._afterChangeHandlers[t].push(n),()=>ii(this._afterChangeHandlers[t],n)}registerBeforeDeleteHandler(t,n){return this._beforeDeleteHandlers[t]||(this._beforeDeleteHandlers[t]=[]),this._beforeDeleteHandlers[t].push(n),()=>ii(this._beforeDeleteHandlers[t],n)}registerAfterDeleteHandler(t,n){return this._afterDeleteHandlers[t]||(this._afterDeleteHandlers[t]=[]),this._afterDeleteHandlers[t].push(n),()=>ii(this._afterDeleteHandlers[t],n)}registerBatchCompleteHandler(t){return this._batchCompleteHandlers.push(t),()=>ii(this._batchCompleteHandlers,t)}}function ii(e,t){const n=e.indexOf(t);n>=0&&e.splice(n,1)}var D4=Object.defineProperty,R4=Object.getOwnPropertyDescriptor,Of=(e,t,n,r)=>{for(var o=r>1?void 0:r?R4(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&D4(t,n,o),o};const de=e=>Math.round(e*10**8)/10**8;function Po(e,t,n,r,o){const s=e.filter(a=>(r==="forward"?a.startNode.id===t:a.endNode.id===t)&&de(a.length)===de(n)&&Er(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=Po(e,l,n,r,Er(a.breadthIntersection[0],a.breadthIntersection[1],o[0],o[1]));s.push(...c)}}),s}function L4(e){e.sort((t,n)=>n.gaps.length-t.gaps.length);for(let t=e.length-1;t>0;t--){const n=e[t];for(let r=t-1;r>=0;r--){const o=e[r];if(o.direction===n.direction&&n.gaps.every(s=>o.gaps.some(i=>de(s.startEdge[0].x)===de(i.startEdge[0].x)&&de(s.startEdge[0].y)===de(i.startEdge[0].y)&&de(s.startEdge[1].x)===de(i.startEdge[1].x)&&de(s.startEdge[1].y)===de(i.startEdge[1].y))&&o.gaps.some(i=>de(s.endEdge[0].x)===de(i.endEdge[0].x)&&de(s.endEdge[0].y)===de(i.endEdge[0].y)&&de(s.endEdge[1].x)===de(i.endEdge[1].x)&&de(s.endEdge[1].y)===de(i.endEdge[1].y)))){e.splice(t,1);break}}}}class $u{constructor(t){m(this,"editor");this.manager=t,this.editor=t.editor}getSnapPointsCache(){const{editor:t}=this;return t.store.createComputedCache("snapPoints",n=>{const r=t.getShapePageTransform(n.id);if(!r)return;const s=t.getShapeUtil(n).getBoundsSnapGeometry(n).points??t.getShapeGeometry(n).bounds.cornersAndCenter;if(!(!r||!s))return s.map((i,a)=>{const{x:l,y:c}=ne.applyToPoint(r,i);return{x:l,y:c,id:`${n.id}:${a}`}})})}getSnapPoints(t){return this.getSnapPointsCache().get(t)??[]}getSnappablePoints(){const t=this.getSnapPointsCache(),n=this.manager.getSnappableShapes(),r=[];for(const o of n){const s=t.get(o);s&&r.push(...s)}return r}getSnappableGapNodes(){return Array.from(this.manager.getSnappableShapes(),t=>({id:t,pageBounds:di(this.editor.getShapePageBounds(t))}))}getVisibleGaps(){const t=[],n=[];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&&Ll(r.pageBounds.minY,r.pageBounds.maxY,o.pageBounds.minY,o.pageBounds.maxY)&&t.push({startNode:r,endNode:o,startEdge:[new b(r.pageBounds.maxX,r.pageBounds.minY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(o.pageBounds.minX,o.pageBounds.minY),new b(o.pageBounds.minX,o.pageBounds.maxY)],length:o.pageBounds.minX-r.pageBounds.maxX,breadthIntersection:Er(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&&Ll(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)&&n.push({startNode:r,endNode:o,startEdge:[new b(r.pageBounds.minX,r.pageBounds.maxY),new b(r.pageBounds.maxX,r.pageBounds.maxY)],endEdge:[new b(o.pageBounds.minX,o.pageBounds.minY),new b(o.pageBounds.maxX,o.pageBounds.minY)],length:o.pageBounds.minY-r.pageBounds.maxY,breadthIntersection:Er(r.pageBounds.minX,r.pageBounds.maxX,o.pageBounds.minX,o.pageBounds.maxX)})}return{horizontal:t,vertical:n}}snapTranslateShapes({lockedAxis:t,initialSelectionPageBounds:n,initialSelectionSnapPoints:r,dragDelta:o}){var w,S;const s=this.manager.getSnapThreshold(),i=this.getSnappablePoints(),a=n.clone().translate(o),l=r.map(({x:v,y:C},I)=>({id:"selection:"+I,x:v+o.x,y:C+o.y})),c=i,u=[],d=[],p=new b(s,s);this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:p});const f=new b(t==="x"?0:((w=u[0])==null?void 0:w.nudge)??0,t==="y"?0:((S=d[0])==null?void 0:S.nudge)??0);p.x=0,p.y=0,u.length=0,d.length=0,l.forEach(v=>{v.x+=f.x,v.y+=f.y}),a.translate(f),this.collectPointSnaps({minOffset:p,nearestSnapsX:u,nearestSnapsY:d,otherNodeSnapPoints:c,selectionSnapPoints:l}),this.collectGapSnaps({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d,minOffset:p});const y=this.getPointSnapLines({nearestSnapsX:u,nearestSnapsY:d}),g=this.getGapSnapLines({selectionPageBounds:a,nearestSnapsX:u,nearestSnapsY:d});return this.manager.setIndicators([...g,...y]),{nudge:f}}snapResizeShapes({initialSelectionPageBounds:t,dragDelta:n,handle:r,isAspectRatioLocked:o,isResizingFromCenter:s}){var _,k;const i=this.manager.getSnapThreshold(),{box:a,scaleX:l,scaleY:c}=te.Resize(t,r,s?n.x*2:n.x,s?n.y*2:n.y,o);let u=r;l<0&&(u=e5(u)),c<0&&(u=JL(u)),s&&(a.center=t.center);const d=u==="top"||u==="bottom",p=u==="left"||u==="right",f=B1(u,a),y=this.getSnappablePoints(),g=[],w=[],S=new b(i,i);this.collectPointSnaps({minOffset:S,nearestSnapsX:g,nearestSnapsY:w,otherNodeSnapPoints:y,selectionSnapPoints:f});const v=new b(d?0:((_=g[0])==null?void 0:_.nudge)??0,p?0:((k=w[0])==null?void 0:k.nudge)??0);if(o&&t5(u)&&v.len()!==0){const $=g.length&&w.length?Math.abs(v.x)<Math.abs(v.y)?"x":"y":g.length?"x":"y",T=t.aspectRatio;$==="x"?(w.length=0,v.y=v.x/T,(u==="bottom_left"||u==="top_right")&&(v.y=-v.y)):(g.length=0,v.x=v.y*T,(u==="bottom_left"||u==="top_right")&&(v.x=-v.x))}const C=b.Add(n,v),{box:I}=te.Resize(t,r,s?C.x*2:C.x,s?C.y*2:C.y,o);s&&(I.center=t.center);const P=B1("any",I);g.length=0,w.length=0,S.x=0,S.y=0,this.collectPointSnaps({minOffset:S,nearestSnapsX:g,nearestSnapsY:w,otherNodeSnapPoints:y,selectionSnapPoints:P});const E=this.getPointSnapLines({nearestSnapsX:g,nearestSnapsY:w});return this.manager.setIndicators([...E]),{nudge:v}}collectPointSnaps({selectionSnapPoints:t,otherNodeSnapPoints:n,minOffset:r,nearestSnapsX:o,nearestSnapsY:s}){for(const i of t)for(const a of n){const l=b.Sub(i,a),c=Math.abs(l.x),u=Math.abs(l.y);de(c)<=de(r.x)&&(de(c)<de(r.x)&&(o.length=0),o.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.x-i.x}),r.x=c),de(u)<=de(r.y)&&(de(u)<de(r.y)&&(s.length=0),s.push({type:"points",points:{thisPoint:i,otherPoint:a},nudge:a.y-i.y}),r.y=u)}}collectGapSnaps({selectionPageBounds:t,minOffset:n,nearestSnapsX:r,nearestSnapsY:o}){const{horizontal:s,vertical:i}=this.getVisibleGaps();for(const a of s){if(!Ll(a.breadthIntersection[0],a.breadthIntersection[1],t.minY,t.maxY))continue;const c=a.startEdge[0].x+a.length/2-t.center.x;if(a.length>t.width&&de(Math.abs(c))<=de(n.x)){de(Math.abs(c))<de(n.x)&&(r.length=0),n.x=Math.abs(c);const S={type:"gap_center",gap:a,nudge:c},v=r.find(({type:I})=>I==="gap_center"),C=v&&Er(a.breadthIntersection[0],a.breadthIntersection[1],v.gap.breadthIntersection[0],v.gap.breadthIntersection[1]);v&&v.gap.length>a.length&&C?r[r.indexOf(v)]=S:(!v||!C)&&r.push(S)}const d=a.startNode.pageBounds.minX-a.length,p=t.maxX,f=d-p;de(Math.abs(f))<=de(n.x)&&(de(Math.abs(f))<de(n.x)&&(r.length=0),n.x=Math.abs(f),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"left",nudge:f}));const y=a.endNode.pageBounds.maxX+a.length,g=t.minX,w=y-g;de(Math.abs(w))<=de(n.x)&&(de(Math.abs(w))<de(n.x)&&(r.length=0),n.x=Math.abs(w),r.push({type:"gap_duplicate",gap:a,protrusionDirection:"right",nudge:w}))}for(const a of i){if(!Ll(a.breadthIntersection[0],a.breadthIntersection[1],t.minX,t.maxX))continue;const c=a.startEdge[0].y+a.length/2-t.center.y;if(a.length>t.height&&de(Math.abs(c))<=de(n.y)){de(Math.abs(c))<de(n.y)&&(o.length=0),n.y=Math.abs(c);const S={type:"gap_center",gap:a,nudge:c},v=o.find(({type:I})=>I==="gap_center"),C=v&&Ll(v.gap.breadthIntersection[0],v.gap.breadthIntersection[1],a.breadthIntersection[0],a.breadthIntersection[1]);v&&v.gap.length>a.length&&C?o[o.indexOf(v)]=S:(!v||!C)&&o.push(S);continue}const d=a.startNode.pageBounds.minY-a.length,p=t.maxY,f=d-p;de(Math.abs(f))<=de(n.y)&&(de(Math.abs(f))<de(n.y)&&(o.length=0),n.y=Math.abs(f),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"top",nudge:f}));const y=a.endNode.pageBounds.maxY+a.length,g=t.minY,w=y-g;de(Math.abs(w))<=de(n.y)&&(de(Math.abs(w))<de(n.y)&&(o.length=0),n.y=Math.abs(w),o.push({type:"gap_duplicate",gap:a,protrusionDirection:"bottom",nudge:w}))}}getPointSnapLines({nearestSnapsX:t,nearestSnapsY:n}){const r={},o={};if(t.length>0){for(const s of t)if(s.type==="points"){const i=de(s.points.otherPoint.x);r[i]||(r[i]=[]),r[i].push(s.points)}}if(n.length>0){for(const s of n)if(s.type==="points"){const i=de(s.points.otherPoint.y);o[i]||(o[i]=[]),o[i].push(s.points)}}return Object.values(r).concat(Object.values(o)).map(s=>({id:nt(),type:"points",points:ep(s.map(i=>b.From(i.otherPoint)).concat(s.map(i=>b.From(i.thisPoint))),(i,a)=>i.equals(a))}))}getGapSnapLines({selectionPageBounds:t,nearestSnapsX:n,nearestSnapsY:r}){const{vertical:o,horizontal:s}=this.getVisibleGaps(),i={top:t.sides[0],right:t.sides[1],bottom:[t.corners[3],t.corners[2]],left:[t.corners[0],t.corners[3]]},a=[];if(n.length>0)for(const l of n){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:d,endNode:p,length:f,endEdge:y}}=l;switch(l.type){case"gap_center":{const g=(f-t.width)/2,w=Er(c[0],c[1],t.minY,t.maxY);a.push({type:"gaps",direction:"horizontal",id:nt(),gaps:[...Po(s,d.id,g,"backward",w),{startEdge:u,endEdge:i.left},{startEdge:i.right,endEdge:y},...Po(s,p.id,g,"forward",w)]});break}case"gap_duplicate":{const g=Er(c[0],c[1],t.minY,t.maxY);a.push({type:"gaps",direction:"horizontal",id:nt(),gaps:l.protrusionDirection==="left"?[{startEdge:i.right,endEdge:u.map(w=>w.clone().addXY(-d.pageBounds.width,0))},{startEdge:u,endEdge:y},...Po(s,p.id,f,"forward",g)]:[...Po(s,d.id,f,"backward",g),{startEdge:u,endEdge:y},{startEdge:y.map(w=>w.clone().addXY(l.gap.endNode.pageBounds.width,0)),endEdge:i.left}]});break}}}if(r.length>0)for(const l of r){if(l.type==="points")continue;const{gap:{breadthIntersection:c,startEdge:u,startNode:d,endNode:p,length:f,endEdge:y}}=l;switch(l.type){case"gap_center":{const g=(f-t.height)/2,w=Er(c[0],c[1],t.minX,t.maxX);a.push({type:"gaps",direction:"vertical",id:nt(),gaps:[...Po(o,d.id,g,"backward",w),{startEdge:u,endEdge:i.top},{startEdge:i.bottom,endEdge:y},...Po(o,l.gap.endNode.id,g,"forward",w)]});break}case"gap_duplicate":{const g=Er(c[0],c[1],t.minX,t.maxX);a.push({type:"gaps",direction:"vertical",id:nt(),gaps:l.protrusionDirection==="top"?[{startEdge:i.bottom,endEdge:u.map(w=>w.clone().addXY(0,-d.pageBounds.height))},{startEdge:u,endEdge:y},...Po(o,p.id,f,"forward",g)]:[...Po(o,d.id,f,"backward",g),{startEdge:u,endEdge:y},{startEdge:y.map(w=>w.clone().addXY(0,p.pageBounds.height)),endEdge:i.top}]})}break}}return L4(a),a}}Of([G],$u.prototype,"getSnapPointsCache",1);Of([G],$u.prototype,"getSnappablePoints",1);Of([G],$u.prototype,"getSnappableGapNodes",1);Of([G],$u.prototype,"getVisibleGaps",1);function B1(e,t){const{minX:n,maxX:r,minY:o,maxY:s}=t,i=[];switch(e){case"top":case"left":case"top_left":case"any":i.push({id:"top_left",handle:"top_left",x:n,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:n,y:s})}return i}var F4=Object.defineProperty,N4=Object.getOwnPropertyDescriptor,z4=(e,t,n,r)=>{for(var o=r>1?void 0:r?N4(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&F4(t,n,o),o};const B4=()=>null,U4=()=>[];class kT{constructor(t){m(this,"editor");this.manager=t,this.editor=t.editor}getSnapGeometryCache(){const{editor:t}=this;return t.store.createComputedCache("handle snap geometry",n=>{const r=t.getShapeUtil(n).getHandleSnapGeometry(n);return{outline:r.outline===void 0?t.getShapeGeometry(n):r.outline,points:r.points??[],getSelfSnapOutline:r.getSelfSnapOutline??B4,getSelfSnapPoints:r.getSelfSnapPoints??U4}})}*iterateSnapPointsInPageSpace(t,n){var o,s;const r=(o=this.getSnapGeometryCache().get(t))==null?void 0:o.getSelfSnapPoints(n);if(r&&r.length){const i=di(this.editor.getShapePageTransform(t));for(const a of r)yield i.applyToPoint(a)}for(const i of this.manager.getSnappableShapes()){if(i===t)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.points;if(!a||!a.length)continue;const l=di(this.editor.getShapePageTransform(i));for(const c of a)yield l.applyToPoint(c)}}*iterateSnapOutlines(t,n){var o,s;const r=(o=this.getSnapGeometryCache().get(t))==null?void 0:o.getSelfSnapOutline(n);r&&(yield{shapeId:t,outline:r});for(const i of this.manager.getSnappableShapes()){if(i===t)continue;const a=(s=this.getSnapGeometryCache().get(i))==null?void 0:s.outline;a&&(yield{shapeId:i,outline:a})}}getHandleSnapPosition({currentShapeId:t,handle:n,handleInPageSpace:r}){const o=this.manager.getSnapThreshold();let s=o,i=null;for(const c of this.iterateSnapPointsInPageSpace(t,n))b.DistMin(r,c,s)&&(s=b.Dist(r,c),i=c);if(i)return i;let a=o,l=null;for(const{shapeId:c,outline:u}of this.iterateSnapOutlines(t,n)){const d=di(this.editor.getShapePageTransform(c)),p=this.editor.getPointInShapeSpace(c,r),f=u.nearestPoint(p),y=d.applyToPoint(f);b.DistMin(r,y,a)&&(a=b.Dist(r,y),l=y)}return l||null}snapHandle({currentShapeId:t,handle:n}){const o=di(this.editor.getShapePageTransform(t)).applyToPoint(n),s=this.getHandleSnapPosition({currentShapeId:t,handle:n,handleInPageSpace:o});return s?(this.manager.setIndicators([{id:nt(),type:"points",points:[s]}]),{nudge:b.Sub(s,o)}):null}}z4([G],kT.prototype,"getSnapGeometryCache",1);var H4=Object.defineProperty,K4=Object.getOwnPropertyDescriptor,Q0=(e,t,n,r)=>{for(var o=r>1?void 0:r?K4(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&H4(t,n,o),o};class Df{constructor(t){m(this,"shapeBounds");m(this,"handles");m(this,"_snapIndicators",In("snapLines",void 0));this.editor=t,this.shapeBounds=new $u(this),this.handles=new kT(this)}getIndicators(){return this._snapIndicators.get()??$s}clearIndicators(){this.getIndicators().length&&this._snapIndicators.set(void 0)}setIndicators(t){this._snapIndicators.set(t)}getSnapThreshold(){return 8/this.editor.getZoomLevel()}getSnappableShapes(){const{editor:t}=this,n=t.getRenderingBounds(),r=t.getSelectedShapeIds(),o=new Set,s=i=>{if(wn(i)){const l=t.getShape(i);l&&t.isShapeOfType(l,"frame")&&o.add(i)}const a=t.getSortedChildIdsForParent(i);for(const l of a){if(r.includes(l))continue;const c=t.getShape(l);if(!c||!t.getShapeUtil(c).canSnap(c))continue;const d=t.getShapePageBounds(l);if(d&&n.includes(d)){if(t.isShapeOfType(c,"group")){s(l);continue}o.add(l)}}};return s(this.getCurrentCommonAncestor()??t.getCurrentPageId()),o}getCurrentCommonAncestor(){return this.editor.findCommonAncestor(this.editor.getSelectedShapes())}}Q0([G],Df.prototype,"getSnapThreshold",1);Q0([G],Df.prototype,"getSnappableShapes",1);Q0([G],Df.prototype,"getCurrentCommonAncestor",1);const V4=/\r?\n|\r/g;function U1(e){return e.replace(V4,`
79
- `).split(`
80
- `).map(t=>t||" ").join(`
81
- `)}const W4={start:"left","start-legacy":"left",middle:"center","middle-legacy":"center",end:"right","end-legacy":"right"},G4=/\s/;class Y4{constructor(t){m(this,"baseElm");m(this,"measureText",(t,n)=>{var i;const r=(i=this.baseElm)==null?void 0:i.cloneNode();this.baseElm.insertAdjacentElement("afterend",r),r.setAttribute("dir","ltr"),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-style",n.fontStyle),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("font-size",n.fontSize+"px"),r.style.setProperty("line-height",n.lineHeight*n.fontSize+"px"),r.style.setProperty("max-width",n.maxWidth===null?null:n.maxWidth+"px"),r.style.setProperty("min-width",n.minWidth===null?null:n.minWidth+"px"),r.style.setProperty("padding",n.padding),r.style.setProperty("overflow-wrap",n.disableOverflowWrapBreaking?"normal":"break-word"),r.textContent=U1(t);const o=r.scrollWidth,s=r.getBoundingClientRect();return r.remove(),{x:0,y:0,w:s.width,h:s.height,scrollWidth:o}});var o;this.editor=t;const n=this.editor.getContainer();(o=n.querySelector("#tldraw_text_measure"))==null||o.remove();const r=document.createElement("div");r.id="tldraw_text_measure",r.classList.add("tl-text"),r.classList.add("tl-text-measure"),r.tabIndex=-1,n.appendChild(r),this.baseElm=r}measureElementTextNodeSpans(t,{shouldTruncateToFirstLine:n=!1}={}){const r=[],o=t.getBoundingClientRect(),s=-o.left,i=-o.top,a=new Range,l=t.childNodes[0];let c=0,u=null,d=null,p=0,f=!1;for(const y of t.childNodes)if(y.nodeType===Node.TEXT_NODE)for(const g of y.textContent??""){a.setStart(l,c),a.setEnd(l,c+g.length);const w=a.getClientRects(),S=w[w.length-1],v=S.top+i,C=S.left+s,I=S.right+s,P=G4.test(g);if(P!==d||v!==p||!u){if(u){if(n&&v!==p){f=!0;break}r.push(u)}u={box:{x:C,y:v,w:S.width,h:S.height},text:g}}else u.box.w=I-u.box.x,u.text+=g;d=P,p=v,c+=g.length}return u&&r.push(u),{spans:r,didTruncate:f}}measureTextSpans(t,n){var c;if(t==="")return[];const r=(c=this.baseElm)==null?void 0:c.cloneNode();this.baseElm.insertAdjacentElement("afterend",r);const o=Math.ceil(n.width-n.padding*2);r.style.setProperty("width",`${o}px`),r.style.setProperty("height","min-content"),r.style.setProperty("dir","ltr"),r.style.setProperty("font-size",`${n.fontSize}px`),r.style.setProperty("font-family",n.fontFamily),r.style.setProperty("font-weight",n.fontWeight),r.style.setProperty("line-height",`${n.lineHeight*n.fontSize}px`),r.style.setProperty("text-align",W4[n.textAlign]);const s=n.overflow==="truncate-ellipsis"||n.overflow==="truncate-clip";s&&(r.style.setProperty("overflow-wrap","anywhere"),r.style.setProperty("word-break","break-all"));const i=U1(t);r.textContent=i;const{spans:a,didTruncate:l}=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:s});if(n.overflow==="truncate-ellipsis"&&l){r.textContent="…";const u=Math.ceil(this.measureElementTextNodeSpans(r).spans[0].box.w);r.style.setProperty("width",`${o-u}px`),r.textContent=i;const d=this.measureElementTextNodeSpans(r,{shouldTruncateToFirstLine:!0}).spans,p=d[d.length-1];return d.push({text:"…",box:{x:Math.min(p.box.x+p.box.w,n.width-n.padding-u),y:p.box.y,w:u,h:p.box.h}}),d}return r.remove(),a}}const H1=(typeof process<"u",UI);class X4{constructor(t){m(this,"cancelRaf");m(this,"isPaused",!0);m(this,"now",0);m(this,"start",()=>{var t;this.isPaused=!1,(t=this.cancelRaf)==null||t.call(this),this.cancelRaf=H1(this.tick),this.now=Date.now()});m(this,"tick",()=>{if(this.isPaused)return;const t=Date.now(),n=t-this.now;this.now=t,this.updatePointerVelocity(n),this.editor.emit("frame",n),this.editor.emit("tick",n),this.cancelRaf=H1(this.tick)});m(this,"dispose",()=>{var t;this.isPaused=!0,(t=this.cancelRaf)==null||t.call(this)});m(this,"prevPoint",new b);m(this,"updatePointerVelocity",t=>{const{prevPoint:n,editor:{inputs:{currentScreenPoint:r,pointerVelocity:o}}}=this;if(t===0)return;const s=b.Sub(r,n);this.prevPoint=r.clone();const i=s.len(),a=i?s.div(i):new b(0,0),l=o.clone().lrp(a.mul(i/t),.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=t,this.editor.disposables.add(this.dispose),this.start()}}var q4=Object.defineProperty,Z4=Object.getOwnPropertyDescriptor,uo=(e,t,n,r)=>{for(var o=r>1?void 0:r?Z4(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&q4(t,n,o),o};class zr{constructor(t,n){m(this,"updateUserPreferences",t=>{this.user.setUserPreferences({...this.user.userPreferences.get(),...t})});this.user=t,this.inferDarkMode=n}getUserPreferences(){return{id:this.getId(),name:this.getName(),locale:this.getLocale(),color:this.getColor(),animationSpeed:this.getAnimationSpeed(),isSnapMode:this.getIsSnapMode(),isDarkMode:this.getIsDarkMode(),isWrapMode:this.getIsWrapMode()}}getIsDarkMode(){return this.user.userPreferences.get().isDarkMode??(this.inferDarkMode?ZF():!1)}getEdgeScrollSpeed(){return this.user.userPreferences.get().edgeScrollSpeed??bn.edgeScrollSpeed}getAnimationSpeed(){return this.user.userPreferences.get().animationSpeed??bn.animationSpeed}getId(){return this.user.userPreferences.get().id}getName(){return this.user.userPreferences.get().name??bn.name}getLocale(){return this.user.userPreferences.get().locale??bn.locale}getColor(){return this.user.userPreferences.get().color??bn.color}getIsSnapMode(){return this.user.userPreferences.get().isSnapMode??bn.isSnapMode}getIsWrapMode(){return this.user.userPreferences.get().isWrapMode??bn.isWrapMode}}uo([G],zr.prototype,"getUserPreferences",1);uo([G],zr.prototype,"getIsDarkMode",1);uo([G],zr.prototype,"getEdgeScrollSpeed",1);uo([G],zr.prototype,"getAnimationSpeed",1);uo([G],zr.prototype,"getId",1);uo([G],zr.prototype,"getName",1);uo([G],zr.prototype,"getLocale",1);uo([G],zr.prototype,"getColor",1);uo([G],zr.prototype,"getIsSnapMode",1);uo([G],zr.prototype,"getIsWrapMode",1);function Gl(e){return Math.abs(e.props.bend)<8}function Vp(e,t){if(t.type==="point")return;const n=e.getShape(t.boundShapeId),r=e.getShapePageTransform(n),o=e.getShapeGeometry(n),s=o instanceof Fr?o.children[0].vertices:o.vertices;return{shape:n,transform:r,isClosed:o.isClosed,isExact:t.isExact,didIntersect:!1,outline:s}}function K1(e,t,n,r){if(n.type==="point")return b.From(n);const o=e.getShape(n.boundShapeId);if(o){const{point:s,size:i}=e.getShapeGeometry(o).bounds,a=b.Add(s,b.MulV(n.isPrecise||r?n.normalizedAnchor:{x:.5,y:.5},i)),l=ne.applyToPoint(e.getShapePageTransform(o),a);return ne.applyToPoint(ne.Inverse(t),l)}else return new b(0,0)}function Ar(e,t){const n=e.getShapePageTransform(t);let r,o;t.props.start.type==="binding"&&t.props.end.type==="binding"&&(r=t.props.start.boundShapeId,o=t.props.end.boundShapeId);const s=J0(e,r,o),i=K1(e,n,t.props.start,s==="double-bound"||s==="start-contains-end"),a=K1(e,n,t.props.end,s==="double-bound"||s==="end-contains-start");return{start:i,end:a}}const Ea=10,Wp=10,Q4=10,vs={s:2,m:3.5,l:5,xl:10};function J0(e,t,n){if(!t||!n)return"safe";if(t===n)return"double-bound";const r=e.getShapePageBounds(t),o=e.getShapePageBounds(n);if(r&&o){if(r.contains(o))return"start-contains-end";if(o.contains(r))return"end-contains-start"}return"safe"}function _c(e,t){const{start:n,end:r,arrowheadStart:o,arrowheadEnd:s}=t.props,i=Ar(e,t),a=i.start.clone(),l=i.end.clone(),c=b.Med(a,l);if(b.Equals(a,l))return{isStraight:!0,start:{handle:a,point:a,arrowhead:t.props.arrowheadStart},end:{handle:l,point:l,arrowhead:t.props.arrowheadEnd},middle:c,isValid:!1,length:0};const u=b.Sub(l,a).uni(),d=Vp(e,n),p=Vp(e,r),f=e.getShapePageTransform(t);V1(l,i.start,f,p),V1(a,i.end,f,d);let y=0,g=0,w=0,S=0,v=Ea;const C=d&&p&&d.shape===p.shape,I=d&&p?J0(e,d.shape.id,p.shape.id):"safe";I==="safe"&&d&&p&&!C&&!d.isExact&&!p.isExact&&(p.didIntersect&&!d.didIntersect?d.isClosed&&a.setTo(l.clone().add(u.clone().mul(Ea))):p.didIntersect||p.isClosed&&l.setTo(a.clone().sub(u.clone().mul(Ea))));const P=b.Sub(l,a),E=b.Len(P)?P.uni():b.From(P),_=!b.Equals(E,u);C||(I!=="start-contains-end"&&d&&o!=="none"&&!d.isExact&&(w=vs[t.props.size]/2+("size"in d.shape.props?vs[d.shape.props.size]/2:0),y=Wp+w,v+=w),I!=="end-contains-start"&&p&&s!=="none"&&!p.isExact&&(S=vs[t.props.size]/2+("size"in p.shape.props?vs[p.shape.props.size]/2:0),g=Wp+S,v+=S));const k=a.clone().add(E.clone().mul(y*(_?-1:1))),$=l.clone().sub(E.clone().mul(g*(_?-1:1)));b.DistMin(k,$,v)&&(y!==0&&g!==0?(y*=-1.5,g*=-1.5):y!==0?y*=-1:g!==0&&(g*=-1)),a.add(E.clone().mul(y*(_?-1:1))),l.sub(E.clone().mul(g*(_?-1:1))),_?(d&&p&&l.setTo(b.Add(a,E.clone().mul(-Ea))),c.setTo(b.Med(i.start,i.end))):c.setTo(b.Med(a,l));const T=b.Dist(a,l);return{isStraight:!0,start:{handle:i.start,point:a,arrowhead:t.props.arrowheadStart},end:{handle:i.end,point:l,arrowhead:t.props.arrowheadEnd},middle:c,isValid:T>0,length:T}}function V1(e,t,n,r){if(r===void 0||r.isExact)return;const o=ne.applyToPoint(n,t),s=ne.applyToPoint(n,e),i=ne.applyToPoint(ne.Inverse(r.transform),o),a=ne.applyToPoint(ne.Inverse(r.transform),s),l=r.isClosed,u=(l?X0:c4)(i,a,r.outline);let d;if(u!==null&&(d=u.sort((y,g)=>b.Dist2(y,i)-b.Dist2(g,i))[0]??(l?void 0:a)),d===void 0)return;const p=ne.applyToPoint(r.transform,d),f=ne.applyToPoint(ne.Inverse(n),p);e.setTo(f),r.didIntersect=!0}function hm(e,t,n=0){const{arrowheadEnd:r,arrowheadStart:o}=t.props,s=t.props.bend+n;if(Math.abs(s)>Math.abs(t.props.bend*Q4))return _c(e,t);const i=Ar(e,t),a=b.Med(i.start,i.end),l=b.Sub(i.end,i.start),c=b.Len(l)?l.uni():b.From(l),u=b.Add(a,c.per().mul(-s)),d=Vp(e,t.props.start),p=Vp(e,t.props.end),f=i.start.clone(),y=i.end.clone(),g=u.clone();if(b.Equals(f,y))return{isStraight:!0,start:{handle:f,point:f,arrowhead:t.props.arrowheadStart},end:{handle:y,point:y,arrowhead:t.props.arrowheadEnd},middle:g,isValid:!1,length:0};const w=t.props.bend<0,S=w?bu:AE,v=W1(f,y,g),C=b.Angle(v.center,f),I=b.Angle(v.center,y),P=S(C,I);if(v.length===0||v.size===0||!ab(v.length)||!ab(v.size))return _c(e,t);const E=f.clone(),_=y.clone(),k=g.clone(),$=e.getShapePageTransform(t);let T=0,j=0,L=Ea;if(d&&!d.isExact){const H=ne.applyToPoint($,E),Z=ne.applyToPoint($,v.center),ce=ne.applyToPoint($,_),be=ne.Inverse(d.transform),ke=ne.applyToPoint(be,H),ae=ne.applyToPoint(be,Z),Te=ne.applyToPoint(be,ce),{isClosed:Re}=d,st=Re?OS:L1;let Pe,ft=st(ae,v.radius,d.outline);if(ft){const He=ae.angle(ke),or=ae.angle(Te),Fn=S(He,or);ft=ft.filter(qe=>S(He,ae.angle(qe))<=Fn);const Nn=Fn*.25;ft.sort(Re?(qe,jt)=>Math.abs(S(He,ae.angle(qe))-Nn)<Math.abs(S(He,ae.angle(jt))-Nn)?-1:1:(qe,jt)=>S(He,ae.angle(qe))<S(He,ae.angle(jt))?-1:1),Pe=ft[0]??(Re?void 0:ke)}else Pe=Re?void 0:ke;if(Pe&&(E.setTo(e.getPointInShapeSpace(t,ne.applyToPoint(d.transform,Pe))),d.didIntersect=!0,o!=="none")){const He=vs[t.props.size]/2+("size"in d.shape.props?vs[d.shape.props.size]/2:0);T=Wp+He,L+=He}}if(p&&!p.isExact){const H=ne.applyToPoint($,E),Z=ne.applyToPoint($,_),ce=ne.applyToPoint($,v.center),be=ne.Inverse(p.transform),ke=ne.applyToPoint(be,H),ae=ne.applyToPoint(be,ce),Te=ne.applyToPoint(be,Z),Re=p.isClosed,st=Re?OS:L1;let Pe,ft=st(ae,v.radius,p.outline);if(ft){const He=ae.angle(ke),or=ae.angle(Te),Fn=S(He,or),Nn=Fn*.75;ft=ft.filter(qe=>S(He,ae.angle(qe))<=Fn),ft.sort(Re?(qe,jt)=>Math.abs(S(He,ae.angle(qe))-Nn)<Math.abs(S(He,ae.angle(jt))-Nn)?-1:1:(qe,jt)=>S(He,ae.angle(qe))<S(He,ae.angle(jt))?-1:1),ft[0]?Pe=ft[0]:Pe=Re?void 0:Te}else Pe=Re?void 0:Te;if(Pe&&(_.setTo(e.getPointInShapeSpace(t,ne.applyToPoint(p.transform,Pe))),p.didIntersect=!0,r!=="none")){const He=vs[t.props.size]/2+("size"in p.shape.props?vs[p.shape.props.size]/2:0);j=Wp+He,L+=He}}let N=b.Angle(v.center,E),F=b.Angle(v.center,_),B=S(N,F),q=B*v.radius;const Q=E.clone(),V=_.clone();if(T!==0){const H=T/q*(w?1:-1),Z=b.FromAngle(N+B*H);Q.setTo(v.center).add(Z.mul(v.radius))}if(j!==0){const H=j/q*(w?-1:1),Z=b.FromAngle(F+B*H);V.setTo(v.center).add(Z.mul(v.radius))}if(b.DistMin(Q,V,L)&&(T!==0&&j!==0?(T*=-1.5,j*=-1.5):T!==0?T*=-2:j!==0&&(j*=-2)),T!==0){const H=T/q*(w?1:-1),Z=b.FromAngle(N+B*H);E.setTo(v.center).add(Z.mul(v.radius))}if(j!==0){const H=j/q*(w?-1:1),Z=b.FromAngle(F+B*H);_.setTo(v.center).add(Z.mul(v.radius))}if(d&&p&&!d.isExact&&!p.isExact){N=b.Angle(v.center,E),F=b.Angle(v.center,_),B=S(N,F),q=B*v.radius;const H=J0(e,d.shape.id,p.shape.id);if(H==="double-bound"&&q<30)E.setTo(f),_.setTo(y),k.setTo(g);else if(H==="safe"&&(d&&!d.didIntersect&&E.setTo(f),p&&!p.didIntersect||S(C,N)>S(C,F))){const Z=Math.min(.9,Ea/q)*(w?1:-1),ce=b.FromAngle(N+B*Z);_.setTo(v.center).add(ce.mul(v.radius))}}J4(v.center,v.radius,E,_,k,P,w),E.equals(_)&&(E.setTo(k.clone().addXY(1,1)),_.setTo(k.clone().subXY(1,1))),f.setTo(E),y.setTo(_),g.setTo(k);const U=W1(f,y,g);return{isStraight:!1,start:{point:f,handle:i.start,arrowhead:t.props.arrowheadStart},end:{point:y,handle:i.end,arrowhead:t.props.arrowheadEnd},middle:g,handleArc:v,bodyArc:U,isValid:U.length!==0&&isFinite(U.center.x)&&isFinite(U.center.y)}}function W1(e,t,n){const r=-2*(e.x*(t.y-n.y)-e.y*(t.x-n.x)+t.x*n.y-n.x*t.y),o={x:((e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y)+(n.x*n.x+n.y*n.y)*(t.y-e.y))/r,y:((e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x)+(n.x*n.x+n.y*n.y)*(e.x-t.x))/r},s=b.Dist(o,e),i=+b.Clockwise(e,n,t),a=Math.hypot(e.y-t.y,e.x-t.x),l=Math.hypot(t.y-n.y,t.x-n.x),c=Math.hypot(n.y-e.y,n.x-e.x),u=Math.acos((l*l+c*c-a*a)/(2*l*c))*2,d=+(je>u),p=(Fe-u)*(i?1:-1),f=p*s;return{center:o,radius:s,size:p,length:f,largeArcFlag:d,sweepFlag:i}}function J4(e,t,n,r,o,s,i){const a=b.Angle(e,n),l=b.Angle(e,r);let c=bu(a,l);i||(c=Fe-c);const u=.5*(i?1:-1),d=b.FromAngle(a+c*u);if(o.setTo(e).add(d.mul(t)),c>s){o.rotWith(e,je);const p=r.clone();r.setTo(n),n.setTo(p)}}const ez={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"};class re{constructor(t,n){m(this,"id");m(this,"type");m(this,"shapeType");m(this,"initial");m(this,"children");m(this,"parent");m(this,"_path");m(this,"_current");m(this,"_isActive");m(this,"transition",(t,n={})=>{var s;const r=t.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(n,a),o._current.set(c),c.enter(n,(l==null?void 0:l.id)||"initial"),!c.getIsActive()))break;o=c}return this});m(this,"handleEvent",t=>{var o;const n=ez[t.name],r=this._current.__unsafe__getWithoutCapture();(o=this[n])==null||o.call(this,t),this._isActive.__unsafe__getWithoutCapture()&&r&&r===this._current.__unsafe__getWithoutCapture()&&r.handleEvent(t)});m(this,"enter",(t,n)=>{var r;if(this._isActive.set(!0),(r=this.onEnter)==null||r.call(this,t,n),this.children&&this.initial&&this.getIsActive()){const o=this.children[this.initial];this._current.set(o),o.enter(t,n)}});m(this,"exit",(t,n)=>{var r,o;this._isActive.set(!1),(r=this.onExit)==null||r.call(this,t,n),this.getIsActive()||(o=this.getCurrent())==null||o.exit(t,n)});m(this,"_currentToolIdMask",In("curent tool id mask",void 0));m(this,"onWheel");m(this,"onPointerDown");m(this,"onPointerMove");m(this,"onLongPress");m(this,"onPointerUp");m(this,"onDoubleClick");m(this,"onTripleClick");m(this,"onQuadrupleClick");m(this,"onRightClick");m(this,"onMiddleClick");m(this,"onKeyDown");m(this,"onKeyUp");m(this,"onKeyRepeat");m(this,"onCancel");m(this,"onComplete");m(this,"onInterrupt");m(this,"onTick");m(this,"onEnter");m(this,"onExit");this.editor=t;const{id:r,children:o,initial:s}=this.constructor;this.id=r,this._isActive=In("toolIsActive"+this.id,!1),this._current=In("toolState"+this.id,void 0),this._path=G("toolPath"+this.id,()=>{const i=this.getCurrent();return this.id+(i?`.${i.getPath()}`:"")}),this.parent=n??{},this.parent?o&&s?(this.type="branch",this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])):this.type="leaf":(this.type="root",o&&s&&(this.initial=s,this.children=Object.fromEntries(o().map(i=>[i.id,new i(this.editor,this)])),this._current.set(this.children[this.initial])))}getPath(){return this._path.get()}getCurrent(){return this._current.get()}getIsActive(){return this._isActive.get()}getCurrentToolIdMask(){return this._currentToolIdMask.get()}setCurrentToolIdMask(t){this._currentToolIdMask.set(t)}}m(re,"id"),m(re,"initial"),m(re,"children");class yh extends re{constructor(){super(...arguments);m(this,"onKeyDown",n=>{var r;switch(n.code){case"KeyZ":{if(!(n.shiftKey||n.ctrlKey)){const o=this.getCurrent();o&&((r=o.getCurrent())==null?void 0:r.id)==="idle"&&this.children.zoom&&this.editor.setCurrentTool("zoom",{...n,onInteractionEnd:o.id})}break}}})}}m(yh,"id","root"),m(yh,"initial",""),m(yh,"children",()=>[]);var tz=Object.defineProperty,nz=Object.getOwnPropertyDescriptor,ie=(e,t,n,r)=>{for(var o=r>1?void 0:r?nz(t,n):t,s=e.length-1,i;s>=0;s--)(i=e[s])&&(o=(r?i(t,n,o):i(o))||o);return r&&o&&tz(t,n,o),o};class oe extends o6.EventEmitter{constructor({store:n,user:r,shapeUtils:o,tools:s,getContainer:i,initialState:a,inferDarkMode:l}){super();m(this,"store");m(this,"root");m(this,"disposables",new Set);m(this,"_tickManager");m(this,"snaps");m(this,"user");m(this,"textMeasure");m(this,"environment");m(this,"scribbles");m(this,"getContainer");m(this,"sideEffects");m(this,"shapeUtils");m(this,"styleProps");m(this,"history",new A4(this,n=>{this.annotateError(n,{origin:"history.batch",willCrashApp:!0}),this.crash(n)}));m(this,"_crashingError",null);m(this,"_updateInstanceState",this.history.createCommand("updateInstanceState",(n,r)=>{const o=this.store.get(this.getInstanceState().id),s={...o,...n};return{data:{prev:o,next:s},ephemeral:!1,squashing:!1,...r}},{do:({next:n})=>{this.store.put([n])},undo:({prev:n})=>{this.store.put([n])},squash({prev:n},{next:r}){return{prev:n,next:r}}}));m(this,"_isChangingStyleTimeout",-1);m(this,"setCursor",n=>(this.updateInstanceState({cursor:{...this.getInstanceState().cursor,...n}},{ephemeral:!0}),this));m(this,"_setInstancePageState",this.history.createCommand("setInstancePageState",(n,r)=>({data:{prev:this.store.get(n.id??this.getCurrentPageState().id),partial:n},...r}),{do:({prev:n,partial:r})=>{this.store.update(n.id,o=>({...o,...r}))},undo:({prev:n})=>{this.store.update(n.id,()=>n)}}));m(this,"_setSelectedShapes",this.history.createCommand("setSelectedShapes",(n,r)=>{const{selectedShapeIds:o}=this.getCurrentPageState(),s=new Set(o);return n.length===s.size&&n.every(i=>s.has(i))?null:{data:{selectedShapeIds:n,prevSelectedShapeIds:o},preservesRedoStack:!0,...r}},{do:({selectedShapeIds:n})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:n}])},undo:({prevSelectedShapeIds:n})=>{this.store.put([{...this.getCurrentPageState(),selectedShapeIds:n}])},squash({prevSelectedShapeIds:n},{selectedShapeIds:r}){return{selectedShapeIds:r,prevSelectedShapeIds:n}}}));m(this,"_setFocusedGroupId",this.history.createCommand("setFocusedGroupId",n=>{const r=this.getCurrentPageState().focusedGroupId;if(r!==n)return{data:{prev:r,next:n},preservesRedoStack:!0,squashing:!0}},{do:({next:n})=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},undo:({prev:n})=>{this.store.update(this.getCurrentPageState().id,r=>({...r,focusedGroupId:n}))},squash({prev:n},{next:r}){return{prev:n,next:r}}}));m(this,"_viewportAnimation",null);m(this,"_willSetInitialBounds",!0);m(this,"_wasInset",!1);m(this,"_cameraState",In("camera state","idle"));m(this,"_cameraStateTimeoutRemaining",0);m(this,"_lastUpdateRenderingBoundsTimestamp",Date.now());m(this,"_decayCameraStateTimeout",n=>{this._cameraStateTimeoutRemaining-=n,this._cameraStateTimeoutRemaining<=0&&(this.off("tick",this._decayCameraStateTimeout),this._cameraState.set("idle"),this.updateRenderingBounds())});m(this,"_tickCameraState",()=>{this._cameraStateTimeoutRemaining=p3;const n=Date.now();this._cameraState.__unsafe__getWithoutCapture()==="idle"&&(this._lastUpdateRenderingBoundsTimestamp=n,this._cameraState.set("moving"),this.on("tick",this._decayCameraStateTimeout))});m(this,"_renderingBounds",In("rendering viewport",new te));m(this,"renderingBoundsMargin",100);m(this,"_currentPageShapeIds");m(this,"_setCurrentPageId",this.history.createCommand("setCurrentPage",(n,r)=>{if(!this.store.has(n)){console.error("Tried to set the current page id to a page that doesn't exist.");return}return this.stopFollowingUser(),{data:{toId:n,fromId:this.getCurrentPageId()},squashing:!0,preservesRedoStack:!0,...r}},{do:({toId:n})=>{if(this.store.has(n)){if(!this.getPageStates().find(r=>r.pageId===n)){const r=qt.create({id:qt.createId(n)});this.store.put([r,Zt.create({id:Zt.createId(n),pageId:n})])}this.store.put([{...this.getInstanceState(),currentPageId:n}]),this.updateRenderingBounds()}},undo:({fromId:n})=>{this.store.has(n)&&(this.store.put([{...this.getInstanceState(),currentPageId:n}]),this.updateRenderingBounds())},squash:({fromId:n},{toId:r})=>({toId:r,fromId:n})}));m(this,"_updatePage",this.history.createCommand("updatePage",(n,r)=>{if(this.getInstanceState().isReadonly)return null;const o=this.getPage(n.id);return o?{data:{prev:o,partial:n},...r}:null},{do:({partial:n})=>{this.store.update(n.id,r=>({...r,...n}))},undo:({prev:n,partial:r})=>{this.store.update(r.id,()=>n)},squash(n,r){return{prev:{...n.prev,...r.prev},partial:r.partial}}}));m(this,"_createPage",this.history.createCommand("createPage",n=>{if(this.getInstanceState().isReadonly||this.getPages().length>=gp)return null;const r=this.getPages(),o=y4(n.name??"Page 1",r.map(c=>c.name));let s=n.index;(!s||r.some(c=>c.index===s))&&(s=Eo(r[r.length-1].index));const i=Lo.create({meta:{},...n,name:o,index:s}),a=qt.create({id:qt.createId(i.id)}),l=Zt.create({id:Zt.createId(i.id),pageId:i.id});return{data:{newPage:i,newTabPageState:l,newCamera:a}}},{do:({newPage:n,newTabPageState:r,newCamera:o})=>{this.store.put([n,o,r])},undo:({newPage:n,newTabPageState:r,newCamera:o})=>{this.getPages().length!==1&&this.store.remove([r.id,n.id,o.id])}}));m(this,"_deletePage",this.history.createCommand("delete_page",n=>{if(this.getInstanceState().isReadonly)return null;const r=this.getPages();if(r.length===1)return null;const o=this.getPage(n),s=this.getPageStates().filter(i=>i.pageId===n);if(!o)return null;if(n===this.getCurrentPageId()){const i=r.findIndex(l=>l.id===n),a=r[i-1]??r[i+1];this.setCurrentPage(a.id)}return{data:{id:n,deletedPage:o,deletedPageStates:s}}},{do:({deletedPage:n,deletedPageStates:r})=>{const o=this.getPages();if(o.length!==1){if(n.id===this.getCurrentPageId()){const s=o.findIndex(a=>a.id===n.id),i=o[s-1]??o[s+1];this.setCurrentPage(i.id)}this.store.remove(r.map(s=>s.id)),this.store.remove([n.id]),this.updateRenderingBounds()}},undo:({deletedPage:n,deletedPageStates:r})=>{this.store.put([n]),this.store.put(r),this.updateRenderingBounds()}}));m(this,"_createAssets",this.history.createCommand("createAssets",n=>this.getInstanceState().isReadonly||n.length<=0?null:{data:{assets:n}},{do:({assets:n})=>{this.store.put(n)},undo:({assets:n})=>{this.store.remove(n.map(r=>r.id))}}));m(this,"_updateAssets",this.history.createCommand("updateAssets",n=>this.getInstanceState().isReadonly||n.length<=0?void 0:{data:{snapshots:{},assets:n}},{do:({assets:n,snapshots:r})=>{this.store.put(n.map(o=>{const s=this.store.get(o.id);return r[o.id]=s,{...s,...o}}))},undo:({snapshots:n})=>{this.store.put(Object.values(n))}}));m(this,"_deleteAssets",this.history.createCommand("deleteAssets",n=>{if(this.getInstanceState().isReadonly||n.length<=0)return;const r=fe(n.map(o=>this.store.get(o)));return{data:{ids:n,prev:r}}},{do:({ids:n})=>{this.store.remove(n)},undo:({prev:n})=>{this.store.put(n)}}));m(this,"_parentIdsToChildIds");m(this,"_childIdsCache",new jf);m(this,"_createShapes",this.history.createCommand("createShapes",n=>{if(this.getInstanceState().isReadonly||n.length<=0)return null;const r=this.getCurrentPageShapeIds();if(n.length+r.size>bo){Id(this);return}return n.length===0?null:{data:{currentPageId:this.getCurrentPageId(),partials:n.map(s=>s.id?s:{...s,id:Be()})}}},{do:({partials:n})=>{var a,l;const r=this.getFocusedGroupId(),o=this.getCurrentPageShapesSorted();n=n.map(c=>{if(!c.parentId||!(this.store.has(c.parentId)||n.some(u=>u.id===c.parentId))){let u=this.getFocusedGroupId();for(let p=o.length-1;p>=0;p--){const f=o[p];if(this.getShapeUtil(f).canReceiveNewChildrenOfType(f,c.type)&&this.isPointInShape(f,{x:c.x??0,y:c.y??0},{margin:0,hitInside:!0})){u=f.id;break}}const d=c.parentId;if(u===c.id&&(u=r),u!==d&&(c={...c},c.parentId=u,wn(u))){const p=this.getPointInShapeSpace(this.getShape(u),{x:c.x??0,y:c.y??0});c.x=p.x,c.y=p.y,c.rotation=-this.getShapePageTransform(u).rotation()+(c.rotation??0)}}return c});const s=new Map,i=[];for(const c of n){const u=this.getShapeUtil(c);let d=c.index;if(!d){const g=c.parentId??r;s.has(g)||s.set(g,this.getHighestIndexForParent(g)),d=s.get(g),s.set(g,Eo(d))}const p=u.getDefaultProps();for(const[g,w]of this.styleProps[c.type])p[w]=this.getStyleForNextShape(g);let f=this.store.schema.types.shape.create({...c,index:d,opacity:c.opacity??this.getInstanceState().opacityForNextShape,parentId:c.parentId??r,props:"props"in c?{...p,...c.props}:p});if(f.index===void 0)throw Error("no index!");const y=(l=(a=this.getShapeUtil(f)).onBeforeCreate)==null?void 0:l.call(a,f);y&&(f=y),i.push(f)}i.forEach(c=>{c.meta={...this.getInitialMetaForShape(c),...c.meta}}),this.store.put(i)},undo:({partials:n})=>{this.store.remove(n.map(r=>r.id))}}));m(this,"animatingShapes",new Map);m(this,"_updateShapes",this.history.createCommand("updateShapes",(n,r)=>{if(this.getInstanceState().isReadonly)return null;const o={},s={};let i,a;for(let l=0,c=n.length;l<c;l++){const u=n[l];u&&(i=this.getShape(u.id),i&&(a=Yl(i,u),a!==i&&(o[i.id]=i,s[i.id]=a)))}return{data:{snapshots:o,updates:s},...r}},{do:({updates:n})=>{this.store.put(at(n).map(r=>{var s,i;const o=this.store.get(r.id);if(o){const a=(i=(s=this.getShapeUtil(r)).onBeforeUpdate)==null?void 0:i.call(s,o,r);if(a)return a}return r}))},undo:({snapshots:n})=>{this.store.put(Object.values(n))},squash(n,r){return{snapshots:{...r.snapshots,...n.snapshots},updates:{...n.updates,...r.updates}}}}));m(this,"_deleteShapes",this.history.createCommand("delete_shapes",n=>{if(this.getInstanceState().isReadonly||n.length===0)return null;const r=[...this.getCurrentPageState().selectedShapeIds],o=new Set(n);for(const c of n)this.visitDescendants(c,u=>{o.add(u)});const s=[...o],i=this._getArrowBindingsIndex().get(),a=fe(s.flatMap(c=>{const u=this.getShape(c),d=i[c];return d&&d.length>0?d.map(({arrowId:p})=>this.getShape(p)).concat(u):u})),l=r.filter(c=>!o.has(c));return{data:{deletedIds:s,snapshots:a,prevSelectedShapeIds:r,postSelectedShapeIds:l}}},{do:({deletedIds:n,postSelectedShapeIds:r})=>{this.store.remove(n),this.store.update(this.getCurrentPageState().id,o=>({...o,selectedShapeIds:r}))},undo:({snapshots:n,prevSelectedShapeIds:r})=>{this.store.put(n),this.store.update(this.getCurrentPageState().id,o=>({...o,selectedShapeIds:r}))}}));m(this,"externalAssetContentHandlers",{file:null,url:null});m(this,"externalContentHandlers",{text:null,files:null,embed:null,"svg-text":null,url:null});m(this,"inputs",{originPagePoint:new b,originScreenPoint:new b,previousPagePoint:new b,previousScreenPoint:new b,currentPagePoint:new b,currentScreenPoint:new b,keys:new Set,buttons:new Set,isPen:!1,shiftKey:!1,ctrlKey:!1,altKey:!1,isDragging:!1,isPointing:!1,isPinching:!1,isEditing:!1,isPanning:!1,pointerVelocity:new b});m(this,"_clickManager",new T4(this));m(this,"_prevCursor","default");m(this,"_shiftKeyTimeout",-1);m(this,"_setShiftKeyTimeout",()=>{this.inputs.shiftKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Shift",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ShiftLeft"})});m(this,"_altKeyTimeout",-1);m(this,"_setAltKeyTimeout",()=>{this.inputs.altKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Alt",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"AltLeft"})});m(this,"_ctrlKeyTimeout",-1);m(this,"_setCtrlKeyTimeout",()=>{this.inputs.ctrlKey=!1,this.dispatch({type:"keyboard",name:"key_up",key:"Ctrl",shiftKey:this.inputs.shiftKey,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,code:"ControlLeft"})});m(this,"_restoreToolId","select");m(this,"_pinchStart",1);m(this,"_didPinch",!1);m(this,"_selectedShapeIdsAtPointerDown",[]);m(this,"_longPressTimeout",-1);m(this,"capturedPointerId",null);m(this,"dispatch",n=>(this._pendingEventsForNextTick.push(n),n.type==="pointer"&&n.name==="pointer_move"||n.type==="wheel"||n.type==="pinch"||this._flushEventsForTick(0),this));m(this,"_pendingEventsForNextTick",[]);m(this,"_flushEventForTick",n=>{if(this.getCrashingError())return this;const{inputs:r}=this,{type:o}=n;if(n.type==="misc"){(n.name==="cancel"||n.name==="complete")&&(this.inputs.isDragging=!1,this.inputs.isPanning&&(this.inputs.isPanning=!1,this.updateInstanceState({cursor:{type:this._prevCursor,rotation:0}}))),this.root.handleEvent(n);return}n.shiftKey?(clearInterval(this._shiftKeyTimeout),this._shiftKeyTimeout=-1,r.shiftKey=!0):!n.shiftKey&&r.shiftKey&&this._shiftKeyTimeout===-1&&(this._shiftKeyTimeout=setTimeout(this._setShiftKeyTimeout,150)),n.altKey?(clearInterval(this._altKeyTimeout),this._altKeyTimeout=-1,r.altKey=!0):!n.altKey&&r.altKey&&this._altKeyTimeout===-1&&(this._altKeyTimeout=setTimeout(this._setAltKeyTimeout,150)),n.ctrlKey?(clearInterval(this._ctrlKeyTimeout),this._ctrlKeyTimeout=-1,r.ctrlKey=!0):!n.ctrlKey&&r.ctrlKey&&this._ctrlKeyTimeout===-1&&(this._ctrlKeyTimeout=setTimeout(this._setCtrlKeyTimeout,150));const{originPagePoint:s,originScreenPoint:i,currentPagePoint:a,currentScreenPoint:l}=r;switch(r.isPointing||(r.isDragging=!1),o){case"pinch":{if(!this.getInstanceState().canMoveCamera)return;switch(clearTimeout(this._longPressTimeout),this._updateInputsFromEvent(n),n.name){case"pinch_start":{if(r.isPinching)return;r.isEditing||(this._pinchStart=this.getCamera().z,this._selectedShapeIdsAtPointerDown.length||(this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds()),this._didPinch=!0,r.isPinching=!0,this.interrupt());return}case"pinch":{if(!r.isPinching)return;const{point:{z:c=1},delta:{x:u,y:d}}=n,{screenBounds:p}=this.store.unsafeGetWithoutCapture(en),{x:f,y}=b.SubXY(n.point,p.x,p.y),{x:g,y:w,z:S}=this.getCamera(),v=Math.min(ps,Math.max(Fl,c));this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this._setCamera({x:g+u/S-f/S+f/v,y:w+d/S-y/S+y/v,z:v},!0);return}case"pinch_end":{if(!r.isPinching)return this;r.isPinching=!1;const{_selectedShapeIdsAtPointerDown:c}=this;this.setSelectedShapes(this._selectedShapeIdsAtPointerDown,{squashing:!0}),this._selectedShapeIdsAtPointerDown=[],this._didPinch&&(this._didPinch=!1,this.once("tick",()=>{this._didPinch||this.setSelectedShapes(c,{squashing:!0})}));return}}}case"wheel":{if(!this.getInstanceState().canMoveCamera)return;if(this._updateInputsFromEvent(n),!this.getIsMenuOpen()){if(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),r.ctrlKey){const{x:p,y:f}=this.inputs.currentScreenPoint,{x:y,y:g,z:w}=this.getCamera(),S=Math.min(ps,Math.max(Fl,w+(n.delta.z??0)*w));this._setCamera({x:y+(p/S-p)-(p/w-p),y:g+(f/S-f)-(f/w-f),z:S},!0);return}const{x:c,y:u,z:d}=this.getCamera();this._setCamera({x:c+n.delta.x/d,y:u+n.delta.y/d,z:d},!0),!r.isDragging&&r.isPointing&&b.Dist2(s,a)>(this.getInstanceState().isCoarsePointer?Ly:Fc)/this.getZoomLevel()&&(clearTimeout(this._longPressTimeout),r.isDragging=!0)}break}case"pointer":{if(r.isPinching)return;this._updateInputsFromEvent(n);const{isPen:c}=n;switch(n.name){case"pointer_down":{if(this.clearOpenMenus(),this._longPressTimeout=setTimeout(()=>{this.dispatch({...n,name:"long_press"})},S3),this._selectedShapeIdsAtPointerDown=this.getSelectedShapeIds(),n.button===0&&(this.capturedPointerId=n.pointerId),r.buttons.add(n.button),r.isPointing=!0,r.isDragging=!1,this.getInstanceState().isPenMode){if(!c)return}else c&&this.updateInstanceState({isPenMode:!0});if(n.button===5?(this._restoreToolId=this.getCurrentToolId(),this.complete(),this.setCurrentTool("eraser")):n.button===1&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0),this.inputs.isPanning)return this.stopCameraAnimation(),this.setCursor({type:"grabbing",rotation:0}),this;i.setTo(l),s.setTo(a);break}case"pointer_move":{if(!c&&this.getInstanceState().isPenMode)return;if(this.inputs.isPanning&&this.inputs.isPointing){clearTimeout(this._longPressTimeout);const{currentScreenPoint:u,previousScreenPoint:d}=this.inputs;this.pan(b.Sub(u,d));return}!r.isDragging&&r.isPointing&&b.Dist2(s,a)>(this.getInstanceState().isCoarsePointer?Ly:Fc)/this.getZoomLevel()&&(clearTimeout(this._longPressTimeout),r.isDragging=!0);break}case"pointer_up":{if(r.buttons.delete(n.button),r.isPointing=!1,r.isDragging=!1,this.getIsMenuOpen()||!c&&this.getInstanceState().isPenMode)return;this.capturedPointerId===n.pointerId&&(this.capturedPointerId=null,n.button=0),r.isPanning?n.button===1?this.inputs.keys.has(" ")?(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:rh}),this.setCursor({type:"grab",rotation:0})):(r.isPanning=!1,this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:rh}),this.setCursor({type:this._prevCursor,rotation:0})):n.button===0&&(this.slideCamera({speed:Math.min(2,this.inputs.pointerVelocity.len()),direction:this.inputs.pointerVelocity,friction:rh}),this.setCursor({type:"grab",rotation:0})):n.button===5&&(this.complete(),this.setCurrentTool(this._restoreToolId));break}}break}case"keyboard":{switch(n.key==="ShiftRight"&&(n.key="ShiftLeft"),n.key==="AltRight"&&(n.key="AltLeft"),n.code==="ControlRight"&&(n.code="ControlLeft"),n.name){case"key_down":{r.keys.add(n.code),!n.ctrlKey&&n.code==="Space"&&(this.inputs.isPanning||(this._prevCursor=this.getInstanceState().cursor.type),this.inputs.isPanning=!0,this.setCursor({type:this.inputs.isPointing?"grabbing":"grab",rotation:0}));break}case"key_up":{r.keys.delete(n.code),n.code==="Space"&&!this.inputs.buttons.has(1)&&(this.inputs.isPanning=!1,this.setCursor({type:this._prevCursor,rotation:0}));break}}break}}if(n.type==="pointer"&&(n.button===1?n.name="middle_click":n.button===2&&(n.name="right_click"),n.isPen===this.getInstanceState().isPenMode))switch(n.name){case"pointer_down":{const c=this._clickManager.transformPointerDownEvent(n);if(n.name!==c.name){this.root.handleEvent(n),this.emit("event",n),this.root.handleEvent(c),this.emit("event",c);return}break}case"pointer_up":{clearTimeout(this._longPressTimeout);const c=this._clickManager.transformPointerUpEvent(n);if(n.name!==c.name){this.root.handleEvent(n),this.emit("event",n),this.root.handleEvent(c),this.emit("event",c);return}break}case"pointer_move":{this._clickManager.handleMove();break}}return this.root.handleEvent(n),this.emit("event",n),this});this.store=n,this.snaps=new Df(this),this.user=new zr(r??m_(),l??!1),this.getContainer=i??(()=>document.body),this.textMeasure=new Y4(this),this._tickManager=new X4(this);class c extends yh{}m(c,"initial",a??""),this.root=new c(this),this.root.children={};const u=CT(o),d=new Set(Object.keys(n.schema.types.shape.migrations.subTypeMigrations));for(const I of u){if(!d.has(I.type))throw Error(`Editor and store have different shapes: "${I.type}" was passed into the editor but not the schema`);d.delete(I.type)}if(d.size>0)throw Error(`Editor and store have different shapes: "${[...d][0]}" is present in the store schema but not provided to the editor`);const p={},f={},y=new Map;for(const I of u){const P=new I(this);p[I.type]=P;const E=QI(I.props??{});f[I.type]=E;for(const _ of E.keys())if(!y.has(_.id))y.set(_.id,_);else if(y.get(_.id)!==_)throw Error(`Multiple style props with id "${_.id}" in use. Style prop IDs must be unique.`)}this.shapeUtils=p,this.styleProps=f;for(const I of[...s]){if(Qr(this.root.children,I.id))throw Error(`Can't override tool with id "${I.id}"`);this.root.children[I.id]=new I(this,this.root)}this.environment=new $4(this),this.scribbles=new j4(this);const g=new Set,w=I=>{var V;const P=this.getShape(I);if(!P)return;const{start:E,end:_}=P.props,k=E.type==="binding"?this.getShape(E.boundShapeId):void 0,$=_.type==="binding"?this.getShape(_.boundShapeId):void 0,T=this.getAncestorPageId(P);if(!T)return;let j;if(k&&$)j=this.findCommonAncestor([k,$])??T;else if(k||$){const U=(V=k||$)==null?void 0:V.parentId;U&&U===P.parentId?j=P.parentId:j=T}else return;j&&j!==P.parentId&&this.reparentShapes([I],j);const L=this.getShape(I);if(!L)throw Error("no reparented arrow");const N=this.getShapeNearestSibling(L,k),F=this.getShapeNearestSibling(L,$);let B;if(N&&F)B=N.index>F.index?N:F;else if(N&&!F)B=N;else if(F&&!N)B=F;else return;let q;const Q=this.getSortedChildIdsForParent(B.parentId).map(U=>this.getShape(U)).filter(U=>U.index>B.index);if(Q.length){const U=Q.find(H=>H.type!=="arrow");if(L.index>B.index&&(!U||L.index<U.index))return;q=fc(B.index,Q[0].index)}else q=Eo(B.index);q!==L.index&&this.updateShapes([{id:I,type:"arrow",index:q}])},S=(I,P)=>{const{x:E,y:_}=Ar(this,I)[P];this.store.put([{...I,props:{...I.props,[P]:{type:"point",x:E,y:_}}}])},v=I=>{for(const P of["start","end"]){const E=I.props[P];if(E.type!=="binding")continue;const _=this.getShape(E.boundShapeId),k=this.getAncestorPageId(I)===this.getAncestorPageId(_);(!_||!k)&&S(I,P)}w(I.id)},C=(I,P)=>{let E=null;const _=I.selectedShapeIds.filter(T=>!P.has(T));_.length!==I.selectedShapeIds.length&&(E||(E={...I}),E.selectedShapeIds=_);const k=I.erasingShapeIds.filter(T=>!P.has(T));k.length!==I.erasingShapeIds.length&&(E||(E={...I}),E.erasingShapeIds=k),I.hoveredShapeId&&P.has(I.hoveredShapeId)&&(E||(E={...I}),E.hoveredShapeId=null),I.editingShapeId&&P.has(I.editingShapeId)&&(E||(E={...I}),E.editingShapeId=null);const $=I.hintingShapeIds.filter(T=>!P.has(T));return $.length!==I.hintingShapeIds.length&&(E||(E={...I}),E.hintingShapeIds=$),I.focusedGroupId&&P.has(I.focusedGroupId)&&(E||(E={...I}),E.focusedGroupId=null),E};if(this.sideEffects=new O4(this),this.sideEffects.registerBatchCompleteHandler(()=>{var I;for(const P of g){g.delete(P);const E=this.getShape(P);if(!E)continue;const _=this.getShapeUtil(E),k=(I=_.onChildrenChange)==null?void 0:I.call(_,E);k!=null&&k.length&&this.updateShapes(k,{squashing:!0})}this.emit("update")}),this.sideEffects.registerBeforeDeleteHandler("shape",I=>{I.parentId&&wn(I.parentId)&&g.add(I.parentId);const P=this._getArrowBindingsIndex().get()[I.id];if(P!=null&&P.length)for(const{arrowId:k,handleId:$}of P){const T=this.getShape(k);T&&S(T,$)}const E=new Set([I.id]),_=fe(this.getPageStates().map(k=>C(k,E)));_.length&&this.store.put(_)}),this.sideEffects.registerBeforeDeleteHandler("page",I=>{var k;if(this.getInstanceState().currentPageId!==I.id)return;const P=(k=this.getPages().find($=>$.id!==I.id))==null?void 0:k.id;if(!P)return;this.store.put([{...this.getInstanceState(),currentPageId:P}]);const E=qt.createId(I.id),_=Zt.createId(I.id);this.store.remove([E,_])}),this.sideEffects.registerAfterChangeHandler("shape",(I,P)=>{if(this.isShapeOfType(P,"arrow")&&v(P),I.parentId!==P.parentId){const E=_=>{const k=this._getArrowBindingsIndex().get()[_];if(k!=null&&k.length)for(const $ of k)w($.arrowId)};E(P.id),this.visitDescendants(P.id,E)}if(I.parentId!==P.parentId&&xn(P.parentId)){const E=new Set([I.id]);this.visitDescendants(I.id,_=>{E.add(_)});for(const _ of this.getPageStates()){if(_.pageId===P.parentId)continue;const k=C(_,E);k&&this.store.put([k])}}I.parentId&&wn(I.parentId)&&g.add(I.parentId),P.parentId!==I.parentId&&wn(P.parentId)&&g.add(P.parentId)}),this.sideEffects.registerAfterChangeHandler("instance_page_state",(I,P)=>{if((I==null?void 0:I.selectedShapeIds)!==(P==null?void 0:P.selectedShapeIds)){const E=P.selectedShapeIds.filter(k=>{var T,j;let $=(T=this.getShape(k))==null?void 0:T.parentId;for(;wn($);){if(P.selectedShapeIds.includes($))return!1;$=(j=this.getShape($))==null?void 0:j.parentId}return!0});let _=null;if(E.length>0){const k=this.findCommonAncestor(fe(E.map($=>this.getShape($))),$=>this.isShapeOfType($,"group"));k&&(_=k)}else P!=null&&P.focusedGroupId&&(_=P.focusedGroupId);(E.length!==P.selectedShapeIds.length||_!==P.focusedGroupId)&&this.store.put([{...P,selectedShapeIds:E,focusedGroupId:_??null}])}}),this.sideEffects.registerAfterCreateHandler("shape",I=>{this.isShapeOfType(I,"arrow")&&v(I)}),this.sideEffects.registerAfterCreateHandler("page",I=>{const P=qt.createId(I.id),E=Zt.createId(I.id);this.store.has(P)||this.store.put([qt.create({id:P})]),this.store.has(E)||this.store.put([Zt.create({id:E,pageId:I.id})])}),this._currentPageShapeIds=I4(this.store,()=>this.getCurrentPageId()),this._parentIdsToChildIds=C4(this.store),this.disposables.add(this.store.listen(I=>{this.emit("change",I)})),this.store.ensureStoreIsUsable(),this._setInstancePageState({editingShapeId:null,hoveredShapeId:null,erasingShapeIds:[]},{ephemeral:!0}),a&&this.root.children[a]===void 0)throw Error(`No state found for initialState "${a}".`);this.root.enter(void 0,"initial"),this.getInstanceState().followingUserId&&this.stopFollowingUser(),this.updateRenderingBounds(),this.on("tick",this._flushEventsForTick),requestAnimationFrame(()=>{this._tickManager.start()})}dispose(){this.disposables.forEach(n=>n()),this.disposables.clear()}getShapeUtil(n){const r=typeof n=="string"?n:n.type,o=pr(this.shapeUtils,r);return Ao(o,`No shape util found for type "${r}"`),o}undo(){return this._flushEventsForTick(0),this.history.undo(),this}getCanUndo(){return this.history.getNumUndos()>0}redo(){return this._flushEventsForTick(0),this.history.redo(),this}getCanRedo(){return this.history.getNumRedos()>0}mark(n,r,o){return this.history.mark(n,r,o),this}bail(){return this.history.bail(),this}bailToMark(n){return this.history.bailToMark(n),this}batch(n){return this.history.batch(n),this}_getArrowBindingsIndex(){return b4(this)}getArrowsBoundTo(n){return this._getArrowBindingsIndex().get()[n]||$s}getArrowInfoCache(){return this.store.createComputedCache("arrow infoCache",n=>Gl(n)?_c(this,n):hm(this,n))}getArrowInfo(n){const r=typeof n=="string"?n:n.id;return this.getArrowInfoCache().get(r)}annotateError(n,{origin:r,willCrashApp:o,tags:s,extras:i}){const a=this.createErrorAnnotations(r,o);return Dv(n,{tags:{...a.tags,...s},extras:{...a.extras,...i}}),o&&this.store.markAsPossiblyCorrupted(),this}createErrorAnnotations(n,r){try{const o=this.getEditingShapeId();return{tags:{origin:n,willCrashApp:r},extras:{activeStateNode:this.root.getPath(),selectedShapes:this.getSelectedShapes(),editingShape:o?this.getShape(o):void 0,inputs:this.inputs}}}catch{return{tags:{origin:n,willCrashApp:r},extras:{}}}}getCrashingError(){return this._crashingError}crash(n){return this._crashingError=n,this.store.markAsPossiblyCorrupted(),this.emit("crash",{error:n}),this}getPath(){return this.root.getPath().split("root.")[1]}isIn(n){const r=n.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(...n){return n.some(r=>this.isIn(r))}setCurrentTool(n,r={}){return this.root.transition(n,r),this}getCurrentTool(){return this.root.getCurrent()}getCurrentToolId(){const n=this.getCurrentTool();return n?n.getCurrentToolIdMask()??n.id:""}getStateDescendant(n){var s;const r=n.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(Oy)}updateDocumentSettings(n){return this.store.put([{...this.getDocumentSettings(),...n}]),this}getInstanceState(){return this.store.get(en)}updateInstanceState(n,r){return this._updateInstanceState(n,{ephemeral:!0,squashing:!0,...r}),n.isChangingStyle!==void 0&&(clearTimeout(this._isChangingStyleTimeout),n.isChangingStyle===!0&&(this._isChangingStyleTimeout=setTimeout(()=>{this.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},2e3))),this}getOpenMenus(){return this.getInstanceState().openMenus}addOpenMenu(n){const r=new Set(this.getOpenMenus());return r.has(n)||(r.add(n),this.updateInstanceState({openMenus:[...r]})),this}deleteOpenMenu(n){const r=new Set(this.getOpenMenus());return r.has(n)&&(r.delete(n),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 Zt.createId(this.getCurrentPageId())}updateCurrentPageState(n,r){return this._setInstancePageState(n,r),this}getSelectedShapeIds(){return this.getCurrentPageState().selectedShapeIds}getSelectedShapes(){const{selectedShapeIds:n}=this.getCurrentPageState();return fe(n.map(r=>this.store.get(r)))}setSelectedShapes(n,r){const o=n.map(s=>typeof s=="string"?s:s.id);return this._setSelectedShapes(o,r),this}select(...n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);return this.setSelectedShapes(r),this}deselect(...n){const r=typeof n[0]=="string"?n:n.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 n=this.getSortedChildIdsForParent(this.getCurrentPageId());return n.length<=0?this:(this.setSelectedShapes(this._getUnlockedShapeIds(n)),this)}selectNone(){return this.getSelectedShapeIds().length>0&&this.setSelectedShapes([]),this}getOnlySelectedShapeId(){var n;return((n=this.getOnlySelectedShape())==null?void 0:n.id)??null}getOnlySelectedShape(){const n=this.getSelectedShapes();return n.length===1?n[0]:null}getSelectionPageBounds(){const n=this.getCurrentPageState().selectedShapeIds;return n.length===0?null:te.Common(fe(n.map(r=>this.getShapePageBounds(r))))}getSelectionRotation(){const n=this.getSelectedShapeIds();let r=!1,o=0;for(let s=0,i=n.length;s<i;s++){const a=this.getShapePageTransform(n[s]);if(a)if(r){if(a.rotation()!==o)return 0}else r=!0,o=a.rotation()}return o}getSelectionRotatedPageBounds(){const n=this.getSelectedShapeIds();if(n.length===0)return;const r=this.getSelectionRotation();if(r===0)return this.getSelectionPageBounds();if(n.length===1){const s=this.getShapeGeometry(n[0]).bounds.clone(),i=this.getShapePageTransform(n[0]);return s.point=i.applyToPoint(s.point),s}const o=te.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 n=this.getSelectionRotatedPageBounds();if(!n)return;const{x:r,y:o}=this.pageToScreen(n.point),s=this.getZoomLevel();return new te(r,o,n.width*s,n.height*s)}getFocusedGroupId(){return this.getCurrentPageState().focusedGroupId??this.getCurrentPageId()}getFocusedGroup(){const n=this.getFocusedGroupId();return n?this.getShape(n):void 0}setFocusedGroup(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==null){const o=this.getShape(r);if(!o)throw Error(`Editor.setFocusedGroup: Shape with id ${r} does not exist`);if(!this.isShapeOfType(o,"group"))throw Error(`Editor.setFocusedGroup: Cannot set focused group to shape of type ${o.type}`)}return r===this.getFocusedGroupId()?this:(this._setFocusedGroupId(r),this)}popFocusedGroupId(){const n=this.getFocusedGroup();if(n){const r=this.findShapeAncestor(n,o=>this.isShapeOfType(o,"group"));this.setFocusedGroup((r==null?void 0:r.id)??null),this.select(n.id)}else this.setFocusedGroup(null),this.selectNone();return this}getEditingShapeId(){return this.getCurrentPageState().editingShapeId}getEditingShape(){const n=this.getEditingShapeId();return n?this.getShape(n):void 0}setEditingShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;if(r!==this.getEditingShapeId()){if(r){const o=this.getShape(r);if(o&&this.getShapeUtil(o).canEdit(o))return this._setInstancePageState({editingShapeId:r}),this}this._setInstancePageState({editingShapeId:null})}return this}getHoveredShapeId(){return this.getCurrentPageState().hoveredShapeId}getHoveredShape(){const n=this.getHoveredShapeId();return n?this.getShape(n):void 0}setHoveredShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.id)??null;return r===this.getHoveredShapeId()?this:(this.updateCurrentPageState({hoveredShapeId:r},{ephemeral:!0}),this)}getHintingShapeIds(){return this.getCurrentPageState().hintingShapeIds}getHintingShape(){const n=this.getHintingShapeIds();return fe(n.map(r=>this.getShape(r)))}setHintingShapes(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);return this.updateCurrentPageState({hintingShapeIds:ep(r)},{ephemeral:!0}),this}getErasingShapeIds(){return this.getCurrentPageState().erasingShapeIds}getErasingShapes(){const n=this.getErasingShapeIds();return fe(n.map(r=>this.getShape(r)))}setErasingShapes(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id);r.sort();const o=this.getErasingShapeIds();if(r.length===o.length){for(let s=0;s<r.length;s++)if(r[s]!==o[s]){this._setInstancePageState({erasingShapeIds:r},{ephemeral:!0});break}}else this._setInstancePageState({erasingShapeIds:r},{ephemeral:!0});return this}getCroppingShapeId(){return this.getCurrentPageState().croppingShapeId}setCroppingShape(n){const r=typeof n=="string"?n:(n==null?void 0:n.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 qt.createId(this.getCurrentPageId())}getCamera(){return this.store.get(this.getCameraId())}getZoomLevel(){return this.getCamera().z}_setCamera(n,r=!1){const o=this.getCamera();return o.x===n.x&&o.y===n.y&&o.z===n.z?this:(this.batch(()=>{const s={...o,...n};this.store.put([s]);const{currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:l}=this.store.unsafeGetWithoutCapture(en);if(i.x/s.z-s.x!==a.x||i.y/s.z-s.y!==a.y){const c={type:"pointer",target:"canvas",name:"pointer_move",point:b.AddXY(i,l.x,l.y),pointerId:cb.CAMERA_MOVE,ctrlKey:this.inputs.ctrlKey,altKey:this.inputs.altKey,shiftKey:this.inputs.shiftKey,button:0,isPen:this.getInstanceState().isPenMode??!1};r?this._flushEventForTick(c):this.dispatch(c)}this._tickCameraState()}),this)}setCamera(n,r){const o=Number.isFinite(n.x)?n.x:0,s=Number.isFinite(n.y)?n.y:0,i=Number.isFinite(n.z)?n.z:this.getZoomLevel();if(this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),r){const{width:a,height:l}=this.getViewportScreenBounds();return this._animateToViewport(new te(-o,-s,a/i,l/i),r)}else this._setCamera({x:o,y:s,z:i});return this}centerOnPoint(n,r){if(!this.getInstanceState().canMoveCamera)return this;const{width:o,height:s}=this.getViewportPageBounds();return this.setCamera({x:-(n.x-o/2),y:-(n.y-s/2),z:this.getCamera().z},r),this}zoomToContent(n={duration:220}){const r=this.getSelectionPageBounds()??this.getCurrentPageBounds();return r&&this.zoomToBounds(r,{targetZoom:Math.min(1,this.getZoomLevel()),...n}),this}zoomToFit(n){if(!this.getInstanceState().canMoveCamera)return this;const r=[...this.getCurrentPageShapeIds()];if(r.length<=0)return this;const o=te.Common(fe(r.map(s=>this.getShapePageBounds(s))));return this.zoomToBounds(o,n),this}resetZoom(n=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera(),{x:a,y:l}=n;return this.setCamera({x:o+(a/1-a)-(a/i-a),y:s+(l/1-l)-(l/i-l),z:1},r),this}zoomIn(n=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();let a=ps;for(let u=1;u<Qi.length;u++){const d=Qi[u-1],p=Qi[u];if(!(p-i<=(p-d)/2)){a=p;break}}const{x:l,y:c}=n;return this.setCamera({x:o+(l/a-l)-(l/i-l),y:s+(c/a-c)-(c/i-c),z:a},r),this}zoomOut(n=this.getViewportScreenCenter(),r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();let a=Fl;for(let u=Qi.length-1;u>0;u--){const d=Qi[u-1],p=Qi[u];if(!(p-i>=(p-d)/2)){a=d;break}}const{x:l,y:c}=n;return this.setCamera({x:o+(l/a-l)-(l/i-l),y:s+(c/a-c)-(c/i-c),z:a},r),this}zoomToSelection(n){if(!this.getInstanceState().canMoveCamera)return this;const r=this.getSelectionPageBounds();return r?(this.zoomToBounds(r,{targetZoom:Math.max(1,this.getZoomLevel()),...n}),this):this}panZoomIntoView(n,r){if(!this.getInstanceState().canMoveCamera)return this;if(n.length<=0)return this;const o=te.Common(fe(n.map(i=>this.getShapePageBounds(i)))),s=this.getViewportPageBounds();if(s.h<o.h||s.w<o.w)return this.zoomToBounds(o,{targetZoom:this.getCamera().z,...r}),this;{const i=this.getViewportPageBounds().clone().expandBy(-32/this.getZoomLevel());let a=0,l=0;i.maxY<o.maxY?l=i.maxY-o.maxY:i.minY>o.minY&&(l=i.minY-o.minY),i.maxX<o.maxX?a=i.maxX-o.maxX:i.minX>o.minX&&(a=i.minX-o.minX);const c=this.getCamera();this.setCamera({x:c.x+a,y:c.y+l,z:c.z},r)}return this}zoomToBounds(n,r){if(!this.getInstanceState().canMoveCamera)return this;const o=this.getViewportScreenBounds(),s=(r==null?void 0:r.inset)??Math.min(256,o.width*.28);let i=Zr(Math.min((o.width-s)/n.width,(o.height-s)/n.height),Fl,ps);return(r==null?void 0:r.targetZoom)!==void 0&&(i=Math.min(r.targetZoom,i)),this.setCamera({x:-n.minX+(o.width-n.width*i)/2/i,y:-n.minY+(o.height-n.height*i)/2/i,z:i},r),this}pan(n,r){if(!this.getInstanceState().canMoveCamera)return this;const{x:o,y:s,z:i}=this.getCamera();return this.setCamera({x:o+n.x/i,y:s+n.y/i,z:i},r),this._flushEventsForTick(0),this}stopCameraAnimation(){return this.emit("stop-camera-animation"),this}_animateViewport(n){if(!this._viewportAnimation)return;const r=()=>{this.removeListener("tick",this._animateViewport),this.removeListener("stop-camera-animation",r),this._viewportAnimation=null};this.once("stop-camera-animation",r),this._viewportAnimation.elapsed+=n;const{elapsed:o,easing:s,duration:i,start:a,end:l}=this._viewportAnimation;if(o>i){this._setCamera({x:-l.x,y:-l.y,z:this.getViewportScreenBounds().width/l.width}),r();return}const c=i-o,u=s(1-c/i),d=a.minX+(l.minX-a.minX)*u,p=a.minY+(l.minY-a.minY)*u,f=a.maxX+(l.maxX-a.maxX)*u;this._setCamera({x:-d,y:-p,z:this.getViewportScreenBounds().width/(f-d)})}_animateToViewport(n,r={}){const{duration:o=0,easing:s=nn.easeInOutCubic}=r,i=this.user.getAnimationSpeed(),a=this.getViewportPageBounds();return this.stopCameraAnimation(),this.getInstanceState().followingUserId&&this.stopFollowingUser(),o===0||i===0?this._setCamera({x:-n.x,y:-n.y,z:this.getViewportScreenBounds().width/n.width}):(this._viewportAnimation={elapsed:0,duration:o/i,easing:s,start:a.clone(),end:n.clone()},this.addListener("tick",this._animateViewport),this)}slideCamera(n={}){if(!this.getInstanceState().canMoveCamera)return this;if(this.stopCameraAnimation(),this.user.getAnimationSpeed()===0)return this;const{speed:o,friction:s,direction:i,speedThreshold:a=.01}=n;let l=Math.min(o,1);const c=()=>{this.removeListener("tick",u),this.removeListener("stop-camera-animation",c)};this.once("stop-camera-animation",c);const u=d=>{const{x:p,y:f,z:y}=this.getCamera(),g=b.Mul(i,l*d/y);l*=1-s,l<a?c():this._setCamera({x:p+g.x,y:f+g.y,z:y})};return this.addListener("tick",u),this}animateToUser(n){const o=[...this.store.query.records("instance_presence",()=>({userId:{eq:n}})).get()].sort((s,i)=>s.lastActivityTimestamp-i.lastActivityTimestamp).pop();return o?(this.batch(()=>{this.getInstanceState().followingUserId!==null&&this.stopFollowingUser();const s=o.currentPageId===this.getCurrentPageId();s||this.setCurrentPage(o.currentPageId);const i=s?{duration:500}:void 0;this.centerOnPoint(o.cursor,i);const{highlightedUserIds:a}=this.getInstanceState();this.updateInstanceState({highlightedUserIds:[...a,n]}),setTimeout(()=>{const l=[...this.getInstanceState().highlightedUserIds],c=l.indexOf(n);c<0||(l.splice(c,1),this.updateInstanceState({highlightedUserIds:l}))},OE)}),this):this}animateToShape(n,r=u3){if(!this.getInstanceState().canMoveCamera)return this;const o=this.getViewportScreenBounds().clone().expandBy(-32),s=o.width/o.height,i=this.getShapePageBounds(n);if(!i)return this;const a=i.width/i.height,l=i.clone(),c=i.width/o.width;return l.width+=(o.minX+o.maxX)*c,l.height+=(o.minY+o.maxY)*c,l.x-=o.minX*c,l.y-=o.minY*c,a>s?(l.height=i.width/s,l.y-=(l.height-i.height)/2):(l.width=i.height*s,l.x-=(l.width-i.width)/2),this._animateToViewport(l,r)}updateViewportScreenBounds(n,r=!1){n.width=Math.max(n.width,1),n.height=Math.max(n.height,1);const o=[n.minY!==0,document.body.scrollWidth!==n.maxX,document.body.scrollHeight!==n.maxY,n.minX!==0],s=n.equals(this.getViewportScreenBounds()),{_willSetInitialBounds:i}=this;if(s)this._willSetInitialBounds=!1;else if(i)this._willSetInitialBounds=!1,this.updateInstanceState({screenBounds:n.toJson(),insets:o},{squashing:!0,ephemeral:!0});else if(r&&!this.getInstanceState().followingUserId){const a=this.getViewportPageCenter();this.updateInstanceState({screenBounds:n.toJson(),insets:o},{squashing:!0,ephemeral:!0}),this.centerOnPoint(a)}else this.updateInstanceState({screenBounds:n.toJson(),insets:o},{squashing:!0,ephemeral:!0});return this._tickCameraState(),this.updateRenderingBounds(),this}getViewportScreenBounds(){const{x:n,y:r,w:o,h:s}=this.getInstanceState().screenBounds;return new te(n,r,o,s)}getViewportScreenCenter(){const n=this.getViewportScreenBounds();return new b(n.midX-n.minX,n.midY-n.minY)}getViewportPageBounds(){const{w:n,h:r}=this.getViewportScreenBounds(),{x:o,y:s,z:i}=this.getCamera();return new te(-o,-s,n/i,r/i)}getViewportPageCenter(){return this.getViewportPageBounds().center}screenToPage(n){const{screenBounds:r}=this.store.unsafeGetWithoutCapture(en),{x:o,y:s,z:i=1}=this.getCamera();return{x:(n.x-r.x)/i-o,y:(n.y-r.y)/i-s,z:n.z??.5}}pageToScreen(n){const r=this.getViewportScreenBounds(),{x:o,y:s,z:i=1}=this.getCamera();return{x:(n.x+o)*i+r.x,y:(n.y+s)*i+r.y,z:n.z??.5}}pageToViewport(n){const{x:r,y:o,z:s=1}=this.getCamera();return{x:(n.x+r)*s,y:(n.y+o)*s,z:n.z??.5}}startFollowingUser(n){const r=this.store.query.records("instance_presence",()=>({userId:{eq:n}})),o=this.user.getId();if(o||console.warn("You should set the userId for the current instance before following a user"),r.get().some(l=>l.followingUserId===o))return this;Tr(()=>{this.stopFollowingUser(),this.updateInstanceState({followingUserId:n},{ephemeral:!0})});const s=()=>{this.removeListener("frame",a),this.removeListener("stop-following",s)};let i=!1;const a=()=>{const l=[...r.get()].sort((N,F)=>N.lastActivityTimestamp-F.lastActivityTimestamp).pop();if(!l){this.stopFollowingUser();return}const c=l.currentPageId===this.getCurrentPageId(),u=c?n3:1;if(!c){this.stopFollowingUser(),this.setCurrentPage(l.currentPageId),this.startFollowingUser(n);return}const{center:d,width:p,height:f}=this.getViewportPageBounds(),y=te.From(l.screenBounds),g=y.width/l.camera.z,w=y.height/l.camera.z,S=new b(g/2-l.camera.x,w/2-l.camera.y),v=l.followingUserId===o,C=p+(g-p)*u,I=f+(w-f)*u,P=v?f/I:Math.min(p/C,f/I),E=Zr(this.getCamera().z*P,Fl,ps),_=this.getViewportScreenBounds().w/E,k=this.getViewportScreenBounds().h/E,$=S.sub(d),T=b.Add(d,b.Mul($,u)),j=b.Sub(T,d).len(),L=Math.abs(E-this.getCamera().z);if(j<r3&&L<s3){i=!0;return}i&&j<o3&&L<i3||(i=!1,this.stopCameraAnimation(),this._setCamera({x:-(T.x-_/2),y:-(T.y-k/2),z:E}))};return this.once("stop-following",s),this.addListener("frame",a),this}stopFollowingUser(){return this.updateInstanceState({followingUserId:null},{ephemeral:!0}),this.emit("stop-following"),this}getCameraState(){return this._cameraState.get()}getUnorderedRenderingShapes(n){const r=[];let o=bo*2,s=bo;const i=this.getErasingShapeIds(),a=(c,u,d)=>{const p=this.getShape(c);if(!p)return;u*=p.opacity;let f=!1;const y=this.getShapeUtil(p);n&&(f=!d&&i.includes(c),f&&(u*=.32)),r.push({id:c,shape:p,util:y,index:o,backgroundIndex:s,opacity:u}),o+=1,s+=1;const g=this.getSortedChildIdsForParent(c);if(!g.length)return;let w=null;y.providesBackgroundForChildren(p)&&(w=s,s=o,o+=bo);for(const S of g)a(S,u,d||f);w!==null&&(s=w)},l=n?[this.getCurrentPage()]:this.getPages();for(const c of l)for(const u of this.getSortedChildIdsForParent(c.id))a(u,1,!1);return r}getRenderingShapes(){return this.getUnorderedRenderingShapes(!0).sort($D)}getRenderingBounds(){return this._renderingBounds.get()}updateRenderingBounds(){const n=this.getViewportPageBounds();return n.equals(this._renderingBounds.__unsafe__getWithoutCapture())?this:(this._renderingBounds.set(n.clone()),this)}_getAllPagesQuery(){return this.store.query.records("page")}getPages(){return this._getAllPagesQuery().get().sort(Lt)}getCurrentPage(){return this.getPage(this.getCurrentPageId())}getCurrentPageId(){return this.getInstanceState().currentPageId}getPage(n){return this.store.get(typeof n=="string"?n:n.id)}getCurrentPageShapeIds(){return this._currentPageShapeIds.get()}getPageShapeIds(n){const r=typeof n=="string"?n:n.id,o=this.store.query.exec("shape",{parentId:{eq:r}});return this.getShapeAndDescendantIds(o.map(s=>s.id))}setCurrentPage(n,r){const o=typeof n=="string"?n:n.id;return this._setCurrentPageId(o,r),this}updatePage(n,r){return this._updatePage(n,r),this}createPage(n){return this._createPage(n),this}deletePage(n){const r=typeof n=="string"?n:n.id;return this._deletePage(r),this}duplicatePage(n,r=Lo.createId()){if(this.getPages().length>=gp)return this;const o=typeof n=="string"?n:n.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=fc(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(n,r,o){const s=typeof n=="string"?n:n.id;return this.getInstanceState().isReadonly?this:(this.updatePage({id:s,name:r},o),this)}_getAllAssetsQuery(){return this.store.query.records("asset")}getAssets(){return this._getAllAssetsQuery().get()}createAssets(n){return this._createAssets(n),this}updateAssets(n){return this._updateAssets(n),this}deleteAssets(n){const r=typeof n[0]=="string"?n:n.map(o=>o.id);return this._deleteAssets(r),this}getAsset(n){return this.store.get(typeof n=="string"?n:n.id)}_getShapeGeometryCache(){return this.store.createComputedCache("bounds",n=>this.getShapeUtil(n).getGeometry(n),(n,r)=>n.props===r.props)}getShapeGeometry(n){return this._getShapeGeometryCache().get(typeof n=="string"?n:n.id)}_getShapeHandlesCache(){return this.store.createComputedCache("handles",n=>{var r,o;return(o=(r=this.getShapeUtil(n)).getHandles)==null?void 0:o.call(r,n)})}getShapeHandles(n){return this._getShapeHandlesCache().get(typeof n=="string"?n:n.id)}getShapeLocalTransform(n){const r=typeof n=="string"?n:n.id,o=this.getShape(r);if(!o)throw Error("Editor.getTransform: shape not found");return ne.Identity().translate(o.x,o.y).rotate(o.rotation)}_getShapePageTransformCache(){return this.store.createComputedCache("pageTransformCache",n=>{if(xn(n.parentId))return this.getShapeLocalTransform(n);const r=this._getShapePageTransformCache().get(n.parentId)??ne.Identity();return ne.Compose(r,this.getShapeLocalTransform(n))})}getShapeParentTransform(n){const r=typeof n=="string"?n:n.id,o=this.getShape(r);return!o||xn(o.parentId)?ne.Identity():this._getShapePageTransformCache().get(o.parentId)??ne.Identity()}getShapePageTransform(n){const r=typeof n=="string"?n:this.getShape(n).id;return this._getShapePageTransformCache().get(r)??ne.Identity()}_getShapePageBoundsCache(){return this.store.createComputedCache("pageBoundsCache",n=>{const r=this._getShapePageTransformCache().get(n.id);return r?te.FromPoints(ne.applyToPoints(r,this.getShapeGeometry(n).vertices)):new te})}getShapePageBounds(n){return this._getShapePageBoundsCache().get(typeof n=="string"?n:n.id)}_getShapeClipPathCache(){return this.store.createComputedCache("clipPathCache",n=>{const r=this._getShapeMaskCache().get(n.id);if(!r)return;if(r.length===0)return"polygon(0px 0px, 0px 0px, 0px 0px)";const o=this._getShapePageTransformCache().get(n.id);return o?`polygon(${ne.applyToPoints(ne.Inverse(o),r).map(i=>`${i.x}px ${i.y}px`).join(",")})`:void 0})}getShapeClipPath(n){return this._getShapeClipPathCache().get(typeof n=="string"?n:n.id)}_getShapeMaskCache(){return this.store.createComputedCache("pageMaskCache",n=>{if(xn(n.parentId)||n.type==="note"||this.findShapeAncestor(n,s=>s.type==="note"))return;const r=this.getShapeAncestors(n.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=DS(s,i);return a?a.map(b.Cast):[]})})}getShapeMask(n){return this._getShapeMaskCache().get(typeof n=="string"?n:n.id)}getShapeMaskedPageBounds(n){return typeof n!="string"&&(n=n.id),this._getShapeMaskedPageBoundsCache().get(n)}_getShapeMaskedPageBoundsCache(){return this.store.createComputedCache("shapeMaskedPageBoundsCache",n=>{const r=this._getShapePageBoundsCache().get(n.id);if(!r)return;const o=this._getShapeMaskCache().get(n.id);if(o){if(o.length===0)return;const{corners:s}=r;if(s.every((a,l)=>a&&b.Equals(a,o[l])))return r.clone();const i=DS(o,s);return i?te.FromPoints(i):void 0}return r})}getShapeAncestors(n,r=[]){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return r;const i=s.parentId;if(xn(i))return r.reverse(),r;const a=this.store.get(i);return a?(r.push(a),this.getShapeAncestors(a,r)):r}findShapeAncestor(n,r){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return;const i=s.parentId;if(xn(i))return;const a=this.getShape(i);if(a)return r(a)?a:this.findShapeAncestor(a,r)}hasAncestor(n,r){const o=typeof n=="string"?n:n==null?void 0:n.id,s=o&&this.getShape(o);return s?s.parentId===r?!0:this.hasAncestor(this.getShapeParent(s),r):!1}findCommonAncestor(n,r){var c;if(n.length===0)return;const o=typeof n[0]=="string"?n:n.map(u=>u.id),s=fe(o.map(u=>this.getShape(u)));if(s.length===1){const u=s[0].parentId;return xn(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(n){const r=typeof n=="string"?this.getShape(n):n;return r===void 0?!1:r.isLocked?!0:this.isShapeOrAncestorLocked(this.getShapeParent(r))}_notVisibleShapes(){return P4(this)}getCulledShapes(){const n=this._notVisibleShapes().get(),r=this.getSelectedShapeIds(),o=this.getEditingShapeId(),s=new Set(n);return o&&s.delete(o),r.forEach(i=>{s.delete(i)}),s}getCurrentPageBounds(){let n;return this.getCurrentPageShapeIds().forEach(r=>{const o=this.getShapeMaskedPageBounds(r);o&&(n?n=n.expand(o):n=o.clone())}),n}getSelectedShapeAtPoint(n){const r=this.getSelectedShapeIds();return this.getCurrentPageShapesSorted().filter(o=>o.type!=="group"&&r.includes(o.id)).reverse().find(o=>this.isPointInShape(o,n,{hitInside:!0,margin:0}))}getShapeAtPoint(n,r={}){const o=this.getZoomLevel(),s=this.getViewportPageBounds(),{filter:i,margin:a=0,hitLabels:l=!1,hitInside:c=!1,hitFrameInside:u=!1}=r;let d=1/0,p=null,f=1/0,y=null;const g=(r.renderingOnly?this.getCurrentPageRenderingShapesSorted():this.getCurrentPageShapesSorted()).filter(w=>{if(this.isShapeOfType(w,"group"))return!1;const S=this.getShapeMask(w);return S&&!Xn(n,S)?!1:i?i(w):!0});for(let w=g.length-1;w>=0;w--){const S=g[w],v=this.getShapeGeometry(S),C=v instanceof Fr,I=this.getPointInShapeSpace(S,n);if((this.isShapeOfType(S,"arrow")||this.isShapeOfType(S,"geo")&&S.props.fill==="none")&&S.props.text.trim()){for(const E of v.children)if(E.isLabel&&E.isPointInBounds(I))return S}if(this.isShapeOfType(S,"frame")){const E=v.distanceToPoint(I,c);if(Math.abs(E)<=a)return y||S;if(v.hitTestPoint(I,0,!0))return y||p||(u?S:void 0);continue}let P;if(C){let E=1/0;for(const _ of v.children){if(_.isLabel&&!l)continue;const k=_.distanceToPoint(I,c);k<E&&(E=k)}P=E}else a===0&&(v.bounds.w<1||v.bounds.h<1)||v.bounds.containsPoint(I,a)?P=v.distanceToPoint(I,c):P=1/0;if(v.isClosed){if(P<=a){if(v.isFilled||C&&v.children[0].isFilled)return y||S;if(this.getShapePageBounds(S).contains(s))continue;if(Math.abs(P)<a)Math.abs(P)<f&&(f=Math.abs(P),y=S);else if(!y){const{area:E}=v;E<d&&(d=E,p=S)}}}else if(P<Fo/o)return S}return y||p||void 0}getShapesAtPoint(n,r={}){return this.getCurrentPageShapes().filter(o=>this.isPointInShape(o,n,r))}isPointInShape(n,r,o={}){const{hitInside:s=!1,margin:i=0}=o,a=typeof n=="string"?n:n.id,l=this.getShapeMask(a);return l&&!Xn(r,l)?!1:this.getShapeGeometry(a).hitTestPoint(this.getPointInShapeSpace(n,r),i,s)}getPointInShapeSpace(n,r){const o=typeof n=="string"?n:n.id;return this._getShapePageTransformCache().get(o).clone().invert().applyToPoint(r)}getPointInParentSpace(n,r){const o=typeof n=="string"?n:n.id,s=this.getShape(o);if(!s)return new b(0,0);if(xn(s.parentId))return b.From(r);const i=this.getShapePageTransform(s.parentId);return i?i.clone().invert().applyToPoint(r):b.From(r)}getCurrentPageShapes(){return Array.from(this.getCurrentPageShapeIds(),n=>this.store.get(n))}getCurrentPageShapesSorted(){const n=this.getCurrentPageShapes().sort(Lt),r=new Map,o=[],s=[];let i,a;for(let l=0,c=n.length;l<c;l++)i=n[l],a=this.getShape(i.parentId),a?(r.has(a.id)||r.set(a.id,[]),r.get(a.id).push(i)):s.push(i);for(let l=0,c=s.length;l<c;l++)TT(s[l],r,o);return o}getCurrentPageRenderingShapesSorted(){const n=this.getCulledShapes();return this.getCurrentPageShapesSorted().filter(({id:r})=>!n.has(r))}isShapeOfType(n,r){const o=typeof n=="string"?this.getShape(n):n;return o?o.type===r:!1}getShape(n){const r=typeof n=="string"?n:n.id;if(wn(r))return this.store.get(r)}getShapeParent(n){const r=typeof n=="string"?n:n==null?void 0:n.id;if(!r)return;const o=this.getShape(r);if(!(o===void 0||!wn(o.parentId)))return this.store.get(o.parentId)}getShapeNearestSibling(n,r){return r?r.parentId===n.parentId?r:this.findShapeAncestor(r,s=>s.parentId===n.parentId):void 0}isShapeInPage(n,r=this.getCurrentPageId()){const o=typeof n=="string"?n:n.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(n){const r=typeof n=="string"?n:n==null?void 0:n.id,o=r&&this.getShape(r);if(o)return xn(o.parentId)?o.parentId:this.getAncestorPageId(this.getShape(o.parentId))}reparentShapes(n,r,o){const s=typeof n[0]=="string"?n:n.map(y=>y.id);if(s.length===0)return this;const i=[],a=xn(r)?ne.Identity():this.getShapePageTransform(r),l=a.rotation();let c=[];const u=fe(this.getSortedChildIdsForParent(r).map(y=>this.getShape(y)));if(o){const y=u.find(g=>g.index===o);if(y){const g=u[u.indexOf(y)+1];g?c=Wa(o,g.index,s.length):c=Cg(o,s.length)}else{const g=u.sort(Lt).find(w=>w.index>o);g?c=Wa(o,g.index,s.length):c=Cg(o,s.length)}}else{const y=u.length&&u[u.length-1];c=y?Cg(y.index,s.length):Ac(s.length)}const d=a.clone().invert(),p=fe(s.map(y=>this.getShape(y))),f=p.filter(y=>y.isLocked);f.length&&this.updateShapes(f.map(({id:y,type:g})=>({id:y,type:g,isLocked:!1})));for(let y=0;y<p.length;y++){const g=p[y],w=this.getShapePageTransform(g);if(!w)continue;const S=w.point();if(!S)continue;const v=d.applyToPoint(S),C=w.rotation()-l;i.push({id:g.id,type:g.type,parentId:r,x:v.x,y:v.y,rotation:C,index:c[y],isLocked:g.isLocked})}return this.updateShapes(i),this}getHighestIndexForParent(n){const r=typeof n=="string"?n:n.id,o=this._parentIdsToChildIds.get()[r];if(!o||o.length===0)return"a1";const s=this.getShape(o[o.length-1]);return Eo(s.index)}getSortedChildIdsForParent(n){const r=typeof n=="string"?n:n.id,o=this._parentIdsToChildIds.get()[r];return o?this._childIdsCache.get(o,()=>o):$s}visitDescendants(n,r){const o=typeof n=="string"?n:n.id,s=this.getSortedChildIdsForParent(o);for(const i of s)r(i)!==!1&&this.visitDescendants(i,r);return this}getShapeAndDescendantIds(n){const r=new Set,o=[...n];for(;o.length>0;){const s=o.pop();if(!s)break;if(!r.has(s)){r.add(s);for(const i of this.getSortedChildIdsForParent(s))o.push(i)}}return r}getDroppingOverShape(n,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(n)&&this.getShapeGeometry(i).hitTestPoint(this.getPointInShapeSpace(i,n),0,!0))return i}}getOutermostSelectableShape(n,r){const o=typeof n=="string"?n:n.id,s=this.getShape(o);let i=s,a=s;const l=this.getFocusedGroup();for(;a;){if(this.isShapeOfType(a,"group")&&(l==null?void 0:l.id)!==a.id&&!this.hasAncestor(l,a.id)&&((r==null?void 0:r(a))??!0))i=a;else if((l==null?void 0:l.id)===a.id)break;a=this.getShapeParent(a)}return i}rotateShapesBy(n,r){if((typeof n[0]=="string"?n:n.map(i=>i.id)).length<=0)return this;const s=IT({editor:this});return s?(mh({delta:r,snapshot:s,editor:this,stage:"one-off"}),this):this}getChangesToTranslateShape(n,r){var i,a,l;let o=n;const s=this.getShapeUtil(n);return o=Yl(o,((i=s.onTranslateStart)==null?void 0:i.call(s,o))??void 0),o=Yl(o,{id:n.id,type:n.type,x:r.x,y:r.y}),o=Yl(o,((a=s.onTranslate)==null?void 0:a.call(s,n,o))??void 0),o=Yl(o,((l=s.onTranslateEnd)==null?void 0:l.call(s,n,o))??void 0),o}nudgeShapes(n,r,o){const s=typeof n[0]=="string"?n:n.map(a=>a.id);if(s.length<=0)return this;const i=[];for(const a of s){const l=this.getShape(a),c=b.From(r),u=this.getShapeParentTransform(l);u&&c.rot(-u.rotation()),i.push(this.getChangesToTranslateShape(l,c.add(l)))}return this.updateShapes(i,{squashing:!0,...o}),this}duplicateShapes(n,r){const o=typeof n[0]=="string"?n:n.map(u=>u.id);if(o.length<=0)return this;const s=new Set(o),i=[],a=[...o];for(;a.length>0;){const u=a.pop();if(!u)break;i.push(u),this.getSortedChildIdsForParent(u).forEach(d=>a.push(d))}i.reverse();const l=new Map(i.map(u=>[u,Be()])),c=fe(i.map(u=>{const d=this.getShape(u);if(!d)return null;const p=l.get(u);let f=0,y=0;if(r&&s.has(u)){const E=this.getShapeParentTransform(d),_=new b(r.x,r.y).rot(-E.rotation());f=_.x,y=_.y}const g=d.parentId??this.getCurrentPageId(),w=this.getSortedChildIdsForParent(g),S=w.indexOf(d.id),v=w[S+1],C=v?this.getShape(v):null,I=C?fc(d.index,C.index):Eo(d.index);let P=vt(d);if(this.isShapeOfType(d,"arrow")&&this.isShapeOfType(P,"arrow")){const E=this.getArrowInfo(d);let _,k;if(d.props.start.type==="binding"&&(_=l.get(d.props.start.boundShapeId),!_))if(E!=null&&E.isValid){const{x:T,y:j}=E.start.point;P.props.start={type:"point",x:T,y:j}}else{const{start:T}=Ar(this,d);P.props.start={type:"point",x:T.x,y:T.y}}if(d.props.end.type==="binding"&&(k=l.get(d.props.end.boundShapeId),!k))if(E!=null&&E.isValid){const{x:T,y:j}=E.end.point;P.props.end={type:"point",x:T,y:j}}else{const{end:T}=Ar(this,d);P.props.start={type:"point",x:T.x,y:T.y}}const $=Gl(P)?_c(this,P):hm(this,P);if(E!=null&&E.isValid&&($!=null&&$.isValid)&&!Gl(d)){const T=b.Med(E.start.handle,E.end.handle),j=b.Dist(E.middle,T),L=b.Dist($.middle,T);P.props.bend<0?P.props.bend+=L-j:P.props.bend-=L-j}P.props.start.type==="binding"&&_&&(P.props.start.boundShapeId=_),P.props.end.type==="binding"&&k&&(P.props.end.boundShapeId=k)}return P={...P,id:p,x:d.x+f,y:d.y+y,index:I},P}));return c.forEach(u=>{wn(u.parentId)&&l.has(u.parentId)&&(u.parentId=l.get(u.parentId))}),this.history.batch(()=>{const u=c.length+this.getCurrentPageShapeIds().size>bo;u&&Id(this);const d=u?c.slice(0,bo-this.getCurrentPageShapeIds().size):c,p=d.map(f=>f.id);if(this.createShapes(d),this.setSelectedShapes(p),r!==void 0){const f=this.getSelectionPageBounds(),y=this.getViewportPageBounds();f&&!y.contains(f)&&this.centerOnPoint(f.center,{duration:Yr})}}),this}moveShapesToPage(n,r){const o=typeof n[0]=="string"?n:n.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>bo)return Id(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(n){const r=typeof n[0]=="string"?n:n.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(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Cd(this,"toBack",r);return o&&this.updateShapes(o),this}sendBackward(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Cd(this,"backward",r);return o&&this.updateShapes(o),this}bringForward(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Cd(this,"forward",r);return o&&this.updateShapes(o),this}bringToFront(n){const r=typeof n[0]=="string"?n:n.map(s=>s.id),o=Cd(this,"toFront",r);return o&&this.updateShapes(o),this}flipShapes(n,r){const o=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;let s=fe(o.map(a=>this.getShape(a)));if(!s.length)return this;s=fe(s.map(a=>this.isShapeOfType(a,"group")?this.getSortedChildIdsForParent(a.id).map(l=>this.getShape(l)):a).flat());const i=te.Common(fe(s.map(a=>this.getShapePageBounds(a)))).center;return this.batch(()=>{for(const a of s){const l=this.getShapeGeometry(a).bounds,c=this.getShapePageTransform(a.id);c&&this.resizeShape(a.id,{x:r==="horizontal"?-1:1,y:r==="vertical"?-1:1},{initialBounds:l,initialPageTransform:c,initialShape:a,mode:"scale_shape",scaleOrigin:i,scaleAxisRotation:0})}}),this}stackShapes(n,r,o){const s=typeof n[0]=="string"?n:n.map(w=>w.id);if(this.getInstanceState().isReadonly)return this;const i=fe(s.map(w=>this.getShape(w)).filter(w=>!(!w||this.isShapeOfType(w,"arrow")&&(w.props.start.type==="binding"||w.props.end.type==="binding")))),a=i.length;if(o===0&&a<3||a<2)return this;const l=Object.fromEntries(i.map(w=>[w.id,this.getShapePageBounds(w)]));let c,u,d,p;r==="horizontal"?(c="x",u="minX",d="maxX",p="width"):(c="y",u="minY",d="maxY",p="height");let f;if(o===0){const w=[];i.sort((v,C)=>l[v.id][u]-l[C.id][u]);for(let v=0;v<a-1;v++){const C=i[v],I=i[v+1],P=l[C.id],_=l[I.id][u]-P[d],k=w.find($=>$.gap===_);k?k.count++:w.push({gap:_,count:1})}let S=0;w.forEach(v=>{v.count>S&&(S=v.count,f=v.gap)}),S===1&&(f=Math.max(0,w.reduce((v,C)=>v+C.gap*C.count,0)/(a-1)))}else f=o;const y=[];let g=l[i[0].id][d];return i.forEach((w,S)=>{var E,_;if(S===0)return;const v={x:0,y:0};v[c]=g+f-l[w.id][c];const C=this.getShapeParent(w),I=C?b.Rot(v,-this.getShapePageTransform(C).decompose().rotation):v,P=(_=(E=this.getShapeUtil(w)).onTranslateStart)==null?void 0:_.call(E,w);y.push(P?{...P,[c]:w[c]+I[c]}:{id:w.id,type:w.type,[c]:w[c]+I[c]}),g+=l[w.id][p]+f}),this.updateShapes(y),this}packShapes(n,r){var _,k;const o=typeof n[0]=="string"?n:n.map($=>$.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=fe(o.map($=>this.getShape($)).filter($=>!(!$||this.isShapeOfType($,"arrow")&&($.props.start.type==="binding"||$.props.end.type==="binding")))),i={},a={};let l,c,u=0;for(let $=0;$<s.length;$++)l=s[$],c=this.getShapePageBounds(l),i[l.id]=c,a[l.id]=c.clone(),u+=c.width*c.height;const d=te.Common(fe(Object.values(i))),p=d.width;s.sort(($,T)=>i[T.id].height-i[$.id].height);const f=Math.max(Math.ceil(Math.sqrt(u/.95)),p),y=[new te(d.x,d.y,f,1/0)];let g=0,w=0,S,v;for(let $=0;$<s.length;$++){l=s[$],c=a[l.id];for(let T=y.length-1;T>=0;T--)if(S=y[T],!(c.width>S.width||c.height>S.height)){c.x=S.x,c.y=S.y,w=Math.max(w,c.maxY),g=Math.max(g,c.maxX),c.width===S.width&&c.height===S.height?(v=y.pop(),T<y.length&&(y[T]=v)):c.height===S.height?(S.x+=c.width+r,S.width-=c.width+r):c.width===S.width?(S.y+=c.height+r,S.height-=c.height+r):(y.push(new te(S.x+(c.width+r),S.y,S.width-(c.width+r),c.height)),S.y+=c.height+r,S.height-=c.height+r);break}}const C=te.Common(Object.values(a)),I=b.Sub(d.center,C.center);let P;const E=[];for(let $=0;$<s.length;$++){l=s[$],c=i[l.id],P=a[l.id];const T=b.Sub(P.point,c.point).add(I),j=this.getShapeParentTransform(l);j&&T.rot(-j.rotation());const L={id:l.id,type:l.type,x:l.x+T.x,y:l.y+T.y},N=(k=(_=this.getShapeUtil(l)).onTranslateStart)==null?void 0:k.call(_,{...l,...L});N?E.push({...L,...N}):E.push(L)}return E.length&&this.updateShapes(E),this}alignShapes(n,r){const o=typeof n[0]=="string"?n:n.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=fe(o.map(c=>this.getShape(c))),i=Object.fromEntries(s.map(c=>[c.id,this.getShapePageBounds(c)])),a=te.Common(fe(Object.values(i))),l=[];return s.forEach(c=>{const u=i[c.id];if(!u)return;const d={x:0,y:0};switch(r){case"top":{d.y=a.minY-u.minY;break}case"center-vertical":{d.y=a.midY-u.minY-u.height/2;break}case"bottom":{d.y=a.maxY-u.minY-u.height;break}case"left":{d.x=a.minX-u.minX;break}case"center-horizontal":{d.x=a.midX-u.minX-u.width/2;break}case"right":{d.x=a.maxX-u.minX-u.width;break}}const p=this.getShapeParent(c),f=p?b.Rot(d,-this.getShapePageTransform(p).decompose().rotation):d;l.push(this.getChangesToTranslateShape(c,b.Add(c,f)))}),this.updateShapes(l),this}distributeShapes(n,r){const o=typeof n[0]=="string"?n:n.map(C=>C.id);if(this.getInstanceState().isReadonly)return this;if(o.length<3)return this;const s=o.length,i=fe(o.map(C=>this.getShape(C))),a=Object.fromEntries(i.map(C=>[C.id,this.getShapePageBounds(C)]));let l,c,u,d,p;r==="horizontal"?(l="x",c="minX",u="maxX",d="midX",p="width"):(l="y",c="minY",u="maxY",d="midY",p="height");const f=[],y=i.sort((C,I)=>a[C.id][c]-a[I.id][c])[0],g=i.sort((C,I)=>a[I.id][u]-a[C.id][u])[0],w=a[y.id][d],S=(a[g.id][d]-w)/(s-1),v=w+S;return i.filter(C=>C!==y&&C!==g).sort((C,I)=>a[C.id][d]-a[I.id][d]).forEach((C,I)=>{const P={x:0,y:0};P[l]=v+S*I-a[C.id][p]/2-a[C.id][l];const E=this.getShapeParent(C),_=E?b.Rot(P,-this.getShapePageTransform(E).rotation()):P;f.push(this.getChangesToTranslateShape(C,b.Add(C,_)))}),this.updateShapes(f),this}stretchShapes(n,r){const o=typeof n[0]=="string"?n:n.map(c=>c.id);if(this.getInstanceState().isReadonly)return this;if(o.length<2)return this;const s=fe(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=te.Common(fe(Object.values(a)));switch(r){case"vertical":{this.batch(()=>{for(const c of s){if(this.getShapePageTransform(c).rotation()%Fe)continue;const d=i[c.id],p=a[c.id],f=new b(0,l.minY-p.minY),y=this.getShapeParentTransform(c);y&&f.rot(-y.rotation());const{x:g,y:w}=b.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:g,y:w}],{squashing:!0});const S=new b(1,l.height/p.height);this.resizeShape(c.id,S,{initialBounds:d,scaleOrigin:new b(p.center.x,l.minY),scaleAxisRotation:0})}});break}case"horizontal":{this.batch(()=>{for(const c of s){const u=i[c.id],d=a[c.id];if(this.getShapePageTransform(c).rotation()%Fe)continue;const f=new b(l.minX-d.minX,0),y=this.getShapeParentTransform(c);y&&f.rot(-y.rotation());const{x:g,y:w}=b.Add(f,c);this.updateShapes([{id:c.id,type:c.type,x:g,y:w}],{squashing:!0});const S=new b(l.width/d.width,1);this.resizeShape(c.id,S,{initialBounds:u,scaleOrigin:new b(l.minX,d.center.y),scaleAxisRotation:0})}});break}}return this}resizeShape(n,r,o={}){var f;const s=typeof n=="string"?n:n.id;if(this.getInstanceState().isReadonly)return this;Number.isFinite(r.x)||(r=new b(1,r.y)),Number.isFinite(r.y)||(r=new b(r.x,1));const i=o.initialShape??this.getShape(s);if(!i)return this;const a=o.scaleOrigin??((f=this.getShapePageBounds(s))==null?void 0:f.center);if(!a)return this;const l=o.initialPageTransform?ne.Cast(o.initialPageTransform):this.getShapePageTransform(s);if(!l)return this;const c=l.rotation();if(c==null)return this;const u=o.scaleAxisRotation??c,d=o.initialBounds??this.getShapeGeometry(s).bounds;if(!d)return this;if(!jE(c,u))return this._resizeUnalignedShape(s,r,{...o,initialBounds:d,scaleOrigin:a,scaleAxisRotation:u,initialPageTransform:l,initialShape:i});const p=this.getShapeUtil(i);if(p.isAspectRatioLocked(i)&&(Math.abs(r.x)>Math.abs(r.y)?r=new b(r.x,Math.sign(r.y)*Math.abs(r.x)):r=new b(Math.sign(r.x)*Math.abs(r.y),r.y)),p.onResize&&p.canResize(i)){const y=this._scalePagePoint(ne.applyToPoint(l,new b(0,0)),a,r,u),g=this.getPointInParentSpace(i.id,y),w=new b(r.x,r.y),S=mc((c-u)%Math.PI,0);w.x=S?r.x:r.y,w.y=S?r.y:r.x;const v=ne.applyToPoint(l,new b),{x:C,y:I}=this.getPointInParentSpace(i.id,v);this.updateShapes([{id:s,type:i.type,x:g.x,y:g.y,...p.onResize({...i,x:C,y:I},{newPoint:g,handle:o.dragHandle??"bottom_right",mode:o.mode??"scale_shape",scaleX:w.x,scaleY:w.y,initialBounds:d,initialShape:i})}],{squashing:!0})}else{const y=ne.applyToPoint(l,d.center),g=this._scalePagePoint(y,a,r,u),w=this.getPointInParentSpace(i.id,y),S=this.getPointInParentSpace(i.id,g),v=b.Sub(S,w);this.updateShapes([{id:s,type:i.type,x:i.x+v.x,y:i.y+v.y}],{squashing:!0})}return this}_scalePagePoint(n,r,o,s){const i=b.RotWith(n,r,-s).sub(r),a=b.MulV(i,o);return b.Add(a,r).rotWith(r,s)}_resizeUnalignedShape(n,r,o){const{type:s}=o.initialShape,i=new b(r.x,r.y);if(Math.abs(r.x)>Math.abs(r.y)?i.x=Math.sign(r.x)*Math.abs(r.y):i.y=Math.sign(r.y)*Math.abs(r.x),this.resizeShape(n,i,{initialShape:o.initialShape,initialBounds:o.initialBounds}),Math.sign(r.x)*Math.sign(r.y)<0){let{rotation:S}=ne.Decompose(o.initialPageTransform);S-=2*S,this.updateShapes([{id:n,type:s,rotation:S}],{squashing:!0})}const a=ne.applyToPoint(o.initialPageTransform,o.initialBounds.center),l=this._scalePagePoint(a,o.scaleOrigin,r,o.scaleAxisRotation),c=this.getShapePageBounds(n),u=this.getShapePageTransform(n),d=c.center,p=u.point();if(!d||!p)return this;const f=b.Sub(l,d),y=b.Add(p,f),{x:g,y:w}=this.getPointInParentSpace(n,y);return this.updateShapes([{id:n,type:s,x:g,y:w}],{squashing:!0}),this}getInitialMetaForShape(n){return{}}createShape(n){return this._createShapes([n]),this}createShapes(n){if(!Array.isArray(n))throw Error("Editor.createShapes: must provide an array of shapes or shape partials");return this._createShapes(n),this}animateShape(n,r){return this.animateShapes([n],r)}animateShapes(n,r={}){const{duration:o=500,easing:s=nn.linear}=r,i=nt();let a=o,l;const c=[];let u,d;for(let y=0,g=n.length;y<g;y++){if(u=n[y],!u)continue;d={partial:u,values:[]};const w=this.getShape(u.id);if(w){for(const S of["x","y","rotation"])u[S]!==void 0&&w[S]!==u[S]&&d.values.push({prop:S,from:w[S],to:u[S]});c.push(d),this.animatingShapes.set(w.id,i)}}let p;const f=y=>{if(a-=y,a<0){const{animatingShapes:v}=this,C=n.filter(I=>I&&v.get(I.id)===i);C.length&&this.updateShapes(C,{squashing:!1}),this.removeListener("tick",f);return}l=s(1-a/o);const{animatingShapes:g}=this,w=[];let S;for(let v=0,C=c.length;v<C;v++)p=c[v],S=g.get(p.partial.id),S===i&&w.push({id:p.partial.id,type:p.partial.type,...p.values.reduce((I,{prop:P,from:E,to:_})=>(I[P]=E+(_-E)*l,I),{})});this._updateShapes(w,{squashing:!0})};return this.addListener("tick",f),this}groupShapes(n,r=Be()){var f;if(!Array.isArray(n))throw Error("Editor.groupShapes: must provide an array of shapes or shape ids");if(this.getInstanceState().isReadonly)return this;const o=typeof n[0]=="string"?n:n.map(y=>y.id);if(o.length<=1)return this;const s=fe(this._getUnlockedShapeIds(o).map(y=>this.getShape(y))),i=s.sort(Lt).map(y=>y.id),a=te.Common(fe(s.map(y=>this.getShapePageBounds(y)))),{x:l,y:c}=a.point,u=this.findCommonAncestor(s)??this.getCurrentPageId();if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const d=s.filter(y=>y.parentId===u).sort(Lt),p=(f=d[d.length-1])==null?void 0:f.index;return this.batch(()=>{this.createShapes([{id:r,type:"group",parentId:u,index:p,x:l,y:c,opacity:1,props:{}}]),this.reparentShapes(i,r),this.select(r)}),this}ungroupShapes(n){const r=typeof n[0]=="string"?n:n.map(a=>a.id);if(this.getInstanceState().isReadonly)return this;if(r.length===0)return this;if(this.getCurrentToolId()!=="select")return this;this.isIn("select.idle")||this.cancel();const o=new Set,s=fe(r.map(a=>this.getShape(a))),i=[];return s.forEach(a=>{this.isShapeOfType(a,"group")?i.push(a):o.add(a.id)}),i.length===0?this:(this.batch(()=>{let a;for(let l=0,c=i.length;l<c;l++){a=i[l];const u=this.getSortedChildIdsForParent(a.id);for(let d=0,p=u.length;d<p;d++)o.add(u[d]);this.reparentShapes(u,a.parentId,a.index)}this.deleteShapes(i.map(l=>l.id)),this.select(...o)}),this)}updateShape(n,r){return this.updateShapes([n],r),this}updateShapes(n,r){const o=Array(n.length);for(let s=0,i=n.length;s<i;s++){const a=n[s];if(!a)continue;const l=this.getShape(a.id);l&&(this.isShapeOrAncestorLocked(l)&&!Object.hasOwn(a,"isLocked")||(this.animatingShapes.delete(a.id),o.push(a)))}return this._updateShapes(o,r),this}_getUnlockedShapeIds(n){return n.filter(r=>{var o;return!((o=this.getShape(r))!=null&&o.isLocked)})}deleteShapes(n){if(!Array.isArray(n))throw Error("Editor.deleteShapes: must provide an array of shapes or shapeIds");return this._deleteShapes(this._getUnlockedShapeIds(typeof n[0]=="string"?n:n.map(r=>r.id))),this}deleteShape(n){return this.deleteShapes([typeof n=="string"?n:n.id]),this}_extractSharedStyles(n,r){if(this.isShapeOfType(n,"group")){const o=this._parentIdsToChildIds.get()[n.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[n.type])r.applyValue(o,pr(n.props,s))}_getSelectionSharedStyles(){const n=this.getSelectedShapes(),r=new RS;for(const o of n)this._extractSharedStyles(o,r);return r}getStyleForNextShape(n){const r=this.getInstanceState().stylesForNextShape[n.id];return r===void 0?n.defaultValue:r}getShapeStyleIfExists(n,r){const o=this.styleProps[n.type].get(r);if(o!==void 0)return pr(n.props,o)}getSharedStyles(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0)return this._getSelectionSharedStyles();const n=this.root.getCurrent(),r=new RS;if(!n)return r;if(n.shapeType)for(const o of this.styleProps[n.shapeType].keys())r.applyValue(o,this.getStyleForNextShape(o));return r}getSharedOpacity(){if(this.isIn("select")&&this.getSelectedShapeIds().length>0){const n=[],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 n.push(i)};for(const s of this.getSelectedShapeIds())r(s);let o=null;for(const s of n)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(n,r){return this.updateInstanceState({opacityForNextShape:n},r),this}setOpacityForSelectedShapes(n,r){const o=this.getSelectedShapes();if(o.length>0){const s=[],i=a=>{if(this.isShapeOfType(a,"group")){const l=this.getSortedChildIdsForParent(a);for(const c of l)i(this.getShape(c))}else s.push(a)};for(const a of o)i(a);this.updateShapes(s.map(a=>({id:a.id,type:a.type,opacity:n})),r)}return this}setStyleForNextShapes(n,r,o){const s=this.getInstanceState().stylesForNextShape;return this.updateInstanceState({stylesForNextShape:{...s,[n.id]:r}},o),this}setStyleForSelectedShapes(n,r,o){const s=this.getSelectedShapes();if(s.length>0){const i=[],a=l=>{if(this.isShapeOfType(l,"group")){const c=this.getSortedChildIdsForParent(l.id);for(const u of c)a(this.getShape(u))}else{const c=this.getShapeUtil(l),u=this.styleProps[l.type].get(n);if(u){const d={id:l.id,type:l.type,props:{[u]:r}};i.push({util:c,originalShape:l,updatePartial:d})}}};for(const l of s)a(l);this.updateShapes(i.map(({updatePartial:l})=>l),o)}return this}registerExternalAssetHandler(n,r){return this.externalAssetContentHandlers[n]=r,this}async getAssetForExternalContent(n){var r,o;return await((o=(r=this.externalAssetContentHandlers)[n.type])==null?void 0:o.call(r,n))}registerExternalContentHandler(n,r){return this.externalContentHandlers[n]=r,this}async putExternalContent(n){var r,o;return(o=(r=this.externalContentHandlers)[n.type])==null?void 0:o.call(r,n)}getContentFromCurrentPage(n){const r=typeof n[0]=="string"?n:n.map(l=>l.id);if(!r||r.length===0)return;const o={};let s=ep(r.map(l=>this.getShape(l)).sort(Lt).flatMap(l=>{const c=[l];return this.visitDescendants(l.id,u=>{c.push(this.getShape(u))}),c}));s=s.map(l=>{if(o[l.id]=this.getShapePageTransform(l.id),l=vt(l),this.isShapeOfType(l,"arrow")){const c=l.props.start.type==="binding"?l.props.start.boundShapeId:void 0,u=l.props.end.type==="binding"?l.props.end.boundShapeId:void 0,d=this.getArrowInfo(l);if(l.props.start.type==="binding"&&!s.some(f=>f.id===c))if(d!=null&&d.isValid){const{x:f,y}=d.start.point;l.props.start={type:"point",x:f,y}}else{const{start:f}=Ar(this,l);l.props.start={type:"point",x:f.x,y:f.y}}if(l.props.end.type==="binding"&&!s.some(f=>f.id===u))if(d!=null&&d.isValid){const{x:f,y}=d.end.point;l.props.end={type:"point",x:f,y}}else{const{end:f}=Ar(this,l);l.props.end={type:"point",x:f.x,y:f.y}}const p=Gl(l)?_c(this,l):hm(this,l);if(d!=null&&d.isValid&&(p!=null&&p.isValid)&&!Gl(l)){const f=b.Med(d.start.handle,d.end.handle),y=b.Dist(d.middle,f),g=b.Dist(p.middle,f);l.props.bend<0?l.props.bend+=g-y:l.props.bend-=g-y}return l}return l});const i=[];s.forEach(l=>{if(s.find(c=>c.id===l.parentId)===void 0){const c=this.getShapePageTransform(l.id),u=c.point(),d=c.rotation();l.x=u.x,l.y=u.y,l.rotation=d,l.parentId=this.getCurrentPageId(),i.push(l.id)}});const a=new Set;return s.forEach(l=>{"assetId"in l.props&&l.props.assetId!==null&&a.add(l.props.assetId)}),{shapes:s,rootShapeIds:i,schema:this.store.schema.serialize(),assets:fe(Array.from(a).map(l=>this.getAsset(l)))}}putContentOntoCurrentPage(n,r={}){var k;if(this.getInstanceState().isReadonly)return this;if(!n.schema)throw Error(`Could not put content:
82
- 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}=n,u=[],d=[],p={store:{...Object.fromEntries(n.assets.map($=>[$.id,$])),...Object.fromEntries(n.shapes.map($=>[$.id,$]))},schema:n.schema},f=this.store.schema.migrateStoreSnapshot(p);if(f.type==="error")throw Error("Could not put content: could not migrate content");for(const $ of Object.values(f.value))switch($.typeName){case"asset":{u.push($);break}case"shape":{d.push($);break}}const y=new Map(d.map($=>[$.id,Be()]));let g=this.getCurrentPageId(),w=1/0,S=[];for(const $ of this.getSelectedShapes()){if(w===0)break;const T=this.isShapeOfType($,"frame"),j=this.getShapeAncestors($);T&&j.push($);const L=T?j.length+1:j.length;if(L<w)w=L,S=j,g=T?$.id:$.parentId;else if(L===w){if(S.length!==j.length)throw Error(`Ancestors: ${S.length} !== ${j.length}`);if(S.length===0){g=l;break}else{g=l;for(let N=0;N<S.length&&j[N]===S[N];N++)g=j[N].id}}}let v=!1;if(!xn(g)){const $=this.getShape(g);if($){if(!this.getViewportPageBounds().includes(this.getShapePageBounds($)))g=l;else if(c.length===1){const T=d.find(j=>j.id===c[0]);this.isShapeOfType($,"frame")&&this.isShapeOfType(T,"frame")&&T.props.w===($==null?void 0:$.props.w)&&T.props.h===($==null?void 0:$.props.h)&&(v=!0)}}else g=l}v||(v=y.has(g)),v&&(g=this.getShape(g).parentId);let C=this.getHighestIndexForParent(g);const I=[],P=d.map($=>{let T;if(s)T=vt($),y.set($.id,$.id);else{const j=y.get($.id);T=vt({...$,id:j})}if(c.includes($.id)&&(T.parentId=l,I.push(T)),y.has(T.parentId)?T.parentId=y.get($.parentId):(c.push(T.id),T.index=C,C=Eo(C)),this.isShapeOfType(T,"arrow")){if(T.props.start.type==="binding"){const j=y.get(T.props.start.boundShapeId);T.props.start=j?{...T.props.start,boundShapeId:j}:{type:"point",x:0,y:0}}if(T.props.end.type==="binding"){const j=y.get(T.props.end.boundShapeId);T.props.end=j?{...T.props.end,boundShapeId:j}:{type:"point",x:0,y:0}}}return T});if(P.length+this.getCurrentPageShapeIds().size>bo)return Id(this),this;const E=[],_=[];for(const $ of u)this.store.has($.id)||(($.type==="image"||$.type==="video")&&((k=$.props.src)!=null&&k.startsWith("data:image"))&&(_.push(vt($)),$.props.src=null),E.push($));return Promise.allSettled(_.map(async $=>{const T=await m4($.props.src,$.props.name,$.props.mimeType??"image/png"),j=await this.getAssetForExternalContent({type:"file",file:T});if(!j){this.deleteAssets([$.id]);return}this.updateAssets([{...j,id:$.id}])})),this.batch(()=>{E.length>0&&this.createAssets(E),this.createShapes(P),o&&this.select(...I.map(N=>N.id)),g!==l&&this.reparentShapes(I.map(N=>N.id),g);const $=P.map(N=>this.getShape(N.id)),T=te.Common($.map(N=>this.getShapePageBounds(N)));if(a===void 0)if(xn(g)){const N=this.getViewportPageBounds();i||N.includes(te.From(T))?a=T.center:a=N.center}else{const N=this.getShape(g);a=ne.applyToPoint(this.getShapePageTransform(N),this.getShapeGeometry(N).bounds.center)}if(I.length===1){const N=I[0];if(this.isShapeOfType(N,"frame"))for(;this.getShapesAtPoint(a).some(F=>this.isShapeOfType(F,"frame")&&F.props.w===N.props.w&&F.props.h===N.props.h);)a.x+=T.w+16}const j=te.Common(fe(I.map(({id:N})=>this.getShapePageBounds(N)))).center,L=b.Sub(a,j);this.updateShapes(I.map(({id:N})=>{const F=this.getShape(N),B=this.getShapeParentTransform(N).decompose().rotation,q=b.Rot(L,-B);return{id:F.id,type:F.type,x:F.x+q.x,y:F.y+q.y}}))}),this}async getSvgElement(n,r={}){const o=await _4(this,n,r);if(!o)return;const s=document.createDocumentFragment(),i=wT(s);zi.flushSync(()=>{i.render(o.jsx)});const a=s.firstElementChild;return Ao(a instanceof SVGSVGElement,"Expected an SVG element"),i.unmount(),{svg:a,width:o.width,height:o.height}}async getSvgString(n,r={}){const o=await this.getSvgElement(n,r);return o?{svg:new XMLSerializer().serializeToString(o.svg),width:o.width,height:o.height}:void 0}async getSvg(n,r={}){const o=await this.getSvgElement(n,r);if(o)return o.svg}_updateInputsFromEvent(n){var g;const{pointerVelocity:r,previousScreenPoint:o,previousPagePoint:s,currentScreenPoint:i,currentPagePoint:a}=this.inputs,{screenBounds:l}=this.store.unsafeGetWithoutCapture(en),{x:c,y:u,z:d}=this.store.unsafeGetWithoutCapture(this.getCameraId()),p=n.point.x-l.x,f=n.point.y-l.y,y=n.point.z??.5;o.setTo(i),s.setTo(a),i.set(p,f),a.set(p/d-c,f/d-u,y),this.inputs.isPen=n.type==="pointer"&&n.isPen,(n.name==="pointer_down"||this.inputs.isPinching)&&r.set(0,0),this.store.put([{id:ip,typeName:"pointer",x:p,y:f,lastActivityTimestamp:n.type==="pointer"&&n.pointerId===cb.CAMERA_MOVE?((g=this.store.unsafeGetWithoutCapture(ip))==null?void 0:g.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}cancelDoubleClick(){this._clickManager.cancelDoubleClickTimeout()}_flushEventsForTick(n){this.batch(()=>{if(this._pendingEventsForNextTick.length>0){const r=[...this._pendingEventsForNextTick];this._pendingEventsForNextTick.length=0;for(const o of r)this._flushEventForTick(o)}n>0&&this.root.handleEvent({type:"misc",name:"tick",elapsed:n}),this.scribbles.tick(n)})}}ie([G],oe.prototype,"getCanUndo",1);ie([G],oe.prototype,"getCanRedo",1);ie([G],oe.prototype,"_getArrowBindingsIndex",1);ie([G],oe.prototype,"getArrowInfoCache",1);ie([G],oe.prototype,"getPath",1);ie([G],oe.prototype,"getCurrentTool",1);ie([G],oe.prototype,"getCurrentToolId",1);ie([G],oe.prototype,"getDocumentSettings",1);ie([G],oe.prototype,"getInstanceState",1);ie([G],oe.prototype,"getOpenMenus",1);ie([G],oe.prototype,"getIsMenuOpen",1);ie([G],oe.prototype,"getPageStates",1);ie([G],oe.prototype,"_getPageStatesQuery",1);ie([G],oe.prototype,"getCurrentPageState",1);ie([G],oe.prototype,"_getCurrentPageStateId",1);ie([G],oe.prototype,"getSelectedShapeIds",1);ie([G],oe.prototype,"getSelectedShapes",1);ie([G],oe.prototype,"getOnlySelectedShapeId",1);ie([G],oe.prototype,"getOnlySelectedShape",1);ie([G],oe.prototype,"getSelectionPageBounds",1);ie([G],oe.prototype,"getSelectionRotation",1);ie([G],oe.prototype,"getSelectionRotatedPageBounds",1);ie([G],oe.prototype,"getSelectionRotatedScreenBounds",1);ie([G],oe.prototype,"getFocusedGroupId",1);ie([G],oe.prototype,"getFocusedGroup",1);ie([G],oe.prototype,"getEditingShapeId",1);ie([G],oe.prototype,"getEditingShape",1);ie([G],oe.prototype,"getHoveredShapeId",1);ie([G],oe.prototype,"getHoveredShape",1);ie([G],oe.prototype,"getHintingShapeIds",1);ie([G],oe.prototype,"getHintingShape",1);ie([G],oe.prototype,"getErasingShapeIds",1);ie([G],oe.prototype,"getErasingShapes",1);ie([G],oe.prototype,"getCameraId",1);ie([G],oe.prototype,"getCamera",1);ie([G],oe.prototype,"getZoomLevel",1);ie([G],oe.prototype,"getViewportScreenBounds",1);ie([G],oe.prototype,"getViewportScreenCenter",1);ie([G],oe.prototype,"getViewportPageBounds",1);ie([G],oe.prototype,"getViewportPageCenter",1);ie([G],oe.prototype,"getRenderingShapes",1);ie([G],oe.prototype,"_getAllPagesQuery",1);ie([G],oe.prototype,"getPages",1);ie([G],oe.prototype,"getCurrentPageId",1);ie([G],oe.prototype,"_getAllAssetsQuery",1);ie([G],oe.prototype,"_getShapeGeometryCache",1);ie([G],oe.prototype,"_getShapeHandlesCache",1);ie([G],oe.prototype,"_getShapePageTransformCache",1);ie([G],oe.prototype,"_getShapePageBoundsCache",1);ie([G],oe.prototype,"_getShapeClipPathCache",1);ie([G],oe.prototype,"_getShapeMaskCache",1);ie([G],oe.prototype,"_getShapeMaskedPageBoundsCache",1);ie([G],oe.prototype,"_notVisibleShapes",1);ie([G],oe.prototype,"getCulledShapes",1);ie([G],oe.prototype,"getCurrentPageBounds",1);ie([G],oe.prototype,"getCurrentPageShapes",1);ie([G],oe.prototype,"getCurrentPageShapesSorted",1);ie([G],oe.prototype,"getCurrentPageRenderingShapesSorted",1);ie([G],oe.prototype,"_getSelectionSharedStyles",1);ie([G({isEqual:(e,t)=>e.equals(t)})],oe.prototype,"getSharedStyles",1);ie([G],oe.prototype,"getSharedOpacity",1);function Id(e,t=e.getCurrentPageId()){const n=e.getPage(t).name;e.emit("max-shapes",{name:n,pageId:t,count:bo})}function Yl(e,t){if(!t)return e;let n=null;const r=Object.entries(t);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(n||(n={...e}),i==="props"||i==="meta"){n[i]={...e[i]};for(const[l,c]of Object.entries(a))c!==void 0&&(n[i][l]=c);continue}n[i]=a}}return n||e}function TT(e,t,n){n.push(e);const r=t.get(e.id);if(r)for(let o=0,s=r.length;o<s;o++)TT(r[o],t,n)}function Mu(){const e=z(),t=_T();return K("isDarkMode",()=>(t==null?void 0:t.isDarkMode)??e.user.getIsDarkMode(),[t,e])}const G1="<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'/>",Y1="<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'/>",Ed='<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 as(e,t,n,r,o,s=16,i=16){const a=(-n-t)*(je/180),l=Math.sin(a),c=Math.cos(a),u=1*c-1*l,d=1*l+1*c;return`url("data:image/svg+xml,<svg height='32' width='32' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: ${o};'><defs><filter id='shadow' y='-40%' x='-40%' width='180px' height='180%' color-interpolation-filters='sRGB'><feDropShadow dx='${u}' dy='${d}' stdDeviation='1.2' flood-opacity='.5'/></filter></defs><g fill='none' transform='rotate(${t+n} 16 16)${r?" scale(-1,-1) translate(0, -32)":""}' filter='url(%23shadow)'>`+e.replaceAll('"',"'")+`</g></svg>") ${s} ${i}, pointer`}const rz=["default","pointer","cross","move","grab","grabbing","text","zoom-in","zoom-out"],oz={none:()=>"none","ew-resize":(e,t,n)=>as(Y1,e,0,t,n),"ns-resize":(e,t,n)=>as(Y1,e,90,t,n),"nesw-resize":(e,t,n)=>as(G1,e,0,t,n),"nwse-resize":(e,t,n)=>as(G1,e,90,t,n),"nwse-rotate":(e,t,n)=>as(Ed,e,0,t,n),"nesw-rotate":(e,t,n)=>as(Ed,e,90,t,n),"senw-rotate":(e,t,n)=>as(Ed,e,180,t,n),"swne-rotate":(e,t,n)=>as(Ed,e,270,t,n)};function Un(e,t=0,n="black"){return oz[e](e3(t),!1,n)}function sz(){const e=z(),t=ln(),n=Mu();Mo("useCursor",()=>{const{type:r,rotation:o}=e.getInstanceState().cursor;if(rz.includes(r)){t.style.setProperty("--tl-cursor",`var(--tl-cursor-${r})`);return}t.style.setProperty("--tl-cursor",Un(r,o,n?"white":"black"))},[e,t,n])}function iz(){const e=z(),t=ln(),n=Mu(),r=K(Tt.forceSrgb);Se.useEffect(()=>{n?(t.setAttribute("data-color-mode","dark"),t.classList.remove("tl-theme__light"),t.classList.add("tl-theme__dark")):(t.setAttribute("data-color-mode","light"),t.classList.remove("tl-theme__dark"),t.classList.add("tl-theme__light")),r?t.classList.add("tl-theme__force-sRGB"):t.classList.remove("tl-theme__force-sRGB")},[e,t,r,n])}function ex(e){const t=x.useRef();return x.useLayoutEffect(()=>{t.current=e}),x.useDebugValue(e),x.useCallback((...n)=>{const r=t.current;return Ao(r,"fn does not exist"),r(...n)},[])}function az(e){const t=z(),n=ln();x.useLayoutEffect(()=>{e?(t.getInstanceState().isFocused||t.updateInstanceState({isFocused:!0}),t.getContainer().focus()):t.getInstanceState().isFocused&&t.updateInstanceState({isFocused:!1})},[t,n,e])}function lz(){const[e,t]=x.useState(0);x.useEffect(()=>t(n=>n+1),[])}const za="TLDRAW_TAB_ID_v2",ro=globalThis.window;function cz(){return ro?["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(ro.navigator.platform)||ro.navigator.userAgent.includes("Mac")&&"ontouchend"in document:!1}const Gp=ro?ro[za]??NI(za)??"TLDRAW_INSTANCE_STATE_V1_"+nt():"<error>";ro&&(ro[za]=Gp,cz()?Nv(za,Gp):zI(za));ro==null||ro.addEventListener("beforeunload",()=>{Nv(za,Gp)});const uz={Initial:0},su=uz.Initial,$T=xe({version:he,currentPageId:Oc,isFocusMode:ve,exportBackground:ve,isDebugMode:ve,isToolLocked:ve,isGridMode:ve,pageStates:Nt(xe({pageId:Oc,camera:xe({x:he,y:he,z:he}),selectedShapeIds:Nt(Ir),focusedGroupId:Ir.nullable()}))}),dz=Oe({currentVersion:su});function hz(e){if(!e||typeof e!="object")return console.warn("Invalid instance state"),null;if(!("version"in e)||typeof e.version!="number")return console.warn("No version in instance state"),null;const t=Bv({value:e,fromVersion:e.version,toVersion:su,migrations:dz});if(t.type==="error")return console.warn(t.reason),null;const n={...t.value,version:su};try{$T.validate(n)}catch(r){return console.warn(r),null}return n}function pz(e){const t=e.query.ids("page");return G("sessionStateSnapshot",()=>{const n=e.get(en);if(!n)return null;const r=[...t.get()];return{version:su,currentPageId:n.currentPageId,exportBackground:n.exportBackground,isFocusMode:n.isFocusMode,isDebugMode:n.isDebugMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,pageStates:r.map(o=>{const s=e.get(Zt.createId(o)),i=e.get(qt.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 fz(e,t){const n=hz(t);if(!n)return;const r=e.allRecords().filter(i=>i.typeName==="instance_page_state"||i.typeName==="camera"),o={added:{},updated:{},removed:{...Rv(r.map(i=>[i.id,i]))}};e.has(en)&&(o.removed[en]=e.get(en));const s={removed:{},updated:{},added:{[en]:e.schema.types.instance.create({id:en,currentPageId:n.currentPageId,isDebugMode:n.isDebugMode,isFocusMode:n.isFocusMode,isToolLocked:n.isToolLocked,isGridMode:n.isGridMode,exportBackground:n.exportBackground})}};for(const i of n.pageStates){const a=qt.createId(i.pageId),l=Zt.createId(i.pageId);s.added[a]=qt.create({id:qt.createId(i.pageId),x:i.camera.x,y:i.camera.y,z:i.camera.z}),s.added[l]=Zt.create({id:Zt.createId(i.pageId),pageId:i.pageId,selectedShapeIds:i.selectedShapeIds,focusedGroupId:i.focusedGroupId})}Tr(()=>{e.applyDiff(df([o,s])),e.ensureStoreIsUsable()})}function gz(e){var o;const t=[];for(const s of Object.values(e))(o=s.typeName)!=null&&o.match(/^(instance.*|pointer|camera)$/)&&t.push(s);const n=t.filter(s=>s.typeName==="instance"&&s.id!==en)[0];if(!n)return null;const r={version:su,currentPageId:n.currentPageId,exportBackground:!!n.exportBackground,isFocusMode:!!n.isFocusMode,isDebugMode:!!n.isDebugMode,isToolLocked:!!n.isToolLocked,isGridMode:!1,pageStates:t.filter(s=>s.typeName==="instance_page_state"&&s.instanceId===n.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 $T.validate(r),r}catch{return null}}function mz(){window.alert(`Oops! We could not save changes to your browser's storage. We now need to reload the page and try again.
83
-
84
- Keep seeing this message?
85
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.
86
- • If your hard disk is full, try clearing up some space and then reload the page.`)}function yz(){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.
87
-
88
- Keep seeing this message?
89
- • If you're using tldraw in a private or "incognito" window, try loading tldraw in a regular window or in a different browser.`)}const Sz=(e,t)=>t.some(n=>e instanceof n);let X1,q1;function vz(){return X1||(X1=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function xz(){return q1||(q1=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const MT=new WeakMap,LS=new WeakMap,AT=new WeakMap,pm=new WeakMap,tx=new WeakMap;function wz(e){const t=new Promise((n,r)=>{const o=()=>{e.removeEventListener("success",s),e.removeEventListener("error",i)},s=()=>{n(Oo(e.result)),o()},i=()=>{r(e.error),o()};e.addEventListener("success",s),e.addEventListener("error",i)});return t.then(n=>{n instanceof IDBCursor&&MT.set(n,e)}).catch(()=>{}),tx.set(t,e),t}function bz(e){if(LS.has(e))return;const t=new Promise((n,r)=>{const o=()=>{e.removeEventListener("complete",s),e.removeEventListener("error",i),e.removeEventListener("abort",i)},s=()=>{n(),o()},i=()=>{r(e.error||new DOMException("AbortError","AbortError")),o()};e.addEventListener("complete",s),e.addEventListener("error",i),e.addEventListener("abort",i)});LS.set(e,t)}let FS={get(e,t,n){if(e instanceof IDBTransaction){if(t==="done")return LS.get(e);if(t==="objectStoreNames")return e.objectStoreNames||AT.get(e);if(t==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return Oo(e[t])},set(e,t,n){return e[t]=n,!0},has(e,t){return e instanceof IDBTransaction&&(t==="done"||t==="store")?!0:t in e}};function Pz(e){FS=e(FS)}function Cz(e){return e===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(t,...n){const r=e.call(fm(this),t,...n);return AT.set(r,t.sort?t.sort():[t]),Oo(r)}:xz().includes(e)?function(...t){return e.apply(fm(this),t),Oo(MT.get(this))}:function(...t){return Oo(e.apply(fm(this),t))}}function Iz(e){return typeof e=="function"?Cz(e):(e instanceof IDBTransaction&&bz(e),Sz(e,vz())?new Proxy(e,FS):e)}function Oo(e){if(e instanceof IDBRequest)return wz(e);if(pm.has(e))return pm.get(e);const t=Iz(e);return t!==e&&(pm.set(e,t),tx.set(t,e)),t}const fm=e=>tx.get(e);function Ez(e,t,{blocked:n,upgrade:r,blocking:o,terminated:s}={}){const i=indexedDB.open(e,t),a=Oo(i);return r&&i.addEventListener("upgradeneeded",l=>{r(Oo(i.result),l.oldVersion,l.newVersion,Oo(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(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 _z(e,{blocked:t}={}){const n=indexedDB.deleteDatabase(e);return t&&n.addEventListener("blocked",r=>t(r.oldVersion,r)),Oo(n).then(()=>{})}const kz=["get","getKey","getAll","getAllKeys","count"],Tz=["put","add","delete","clear"],gm=new Map;function Z1(e,t){if(!(e instanceof IDBDatabase&&!(t in e)&&typeof t=="string"))return;if(gm.get(t))return gm.get(t);const n=t.replace(/FromIndex$/,""),r=t!==n,o=Tz.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(o||kz.includes(n)))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[n](...a),o&&l.done]))[0]};return gm.set(t,s),s}Pz(e=>({...e,get:(t,n,r)=>Z1(t,n)||e.get(t,n,r),has:(t,n)=>!!Z1(t,n)||e.has(t,n)}));const Rf="TLDRAW_DOCUMENT_v2",jT="TLDRAW_DB_NAME_INDEX_v2",Le={Records:"records",Schema:"schema",SessionState:"session_state"};async function Lf(e,t){Oz(e);const n=await Ez(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 t(n)}finally{n.close()}}async function $z({persistenceKey:e,sessionId:t,didCancel:n}){const r=Rf+e;if(nx().includes(r))return await jz({persistenceKey:e,didCancel:n}),await Lf(r,async o=>{var d,p;if(n!=null&&n())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=t?(d=await l.get(t))==null?void 0:d.snapshot:null;c||(c=(p=(await l.getAll()).sort((y,g)=>y.updatedAt-g.updatedAt).pop())==null?void 0:p.snapshot);const u={records:await i.getAll(),schema:await a.get(Le.Schema),sessionStateSnapshot:c};if(n!=null&&n()){s.abort();return}return await s.done,u})}async function Mz({persistenceKey:e,schema:t,changes:n,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=Rf+e;await Lf(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),u=l.objectStore(Le.Schema),d=l.objectStore(Le.SessionState);for(const[p,f]of Object.entries(n.added))await c.put(f,p);for(const[p,f]of Object.values(n.updated))await c.put(f,f.id);for(const p of Object.keys(n.removed))await c.delete(p);if(u.put(t.serialize(),Le.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function Az({persistenceKey:e,schema:t,snapshot:n,sessionId:r,sessionStateSnapshot:o,didCancel:s}){const i=Rf+e;await Lf(i,async a=>{const l=a.transaction([Le.Records,Le.Schema,Le.SessionState],"readwrite"),c=l.objectStore(Le.Records),u=l.objectStore(Le.Schema),d=l.objectStore(Le.SessionState);await c.clear();for(const[p,f]of Object.entries(n))await c.put(f,p);if(u.put(t.serialize(),Le.Schema),o&&r?d.put({snapshot:o,updatedAt:Date.now(),id:r},r):(o||r)&&console.error("sessionStateSnapshot and instanceId must be provided together"),s!=null&&s())return l.abort();await l.done})}async function jz({persistenceKey:e,didCancel:t}){await Lf(Rf+e,async n=>{const r=n.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(t!=null&&t())return r.abort();await r.done})}function nx(){const e=JSON.parse(Lv(jT)||"[]")??[];return Array.isArray(e)?e:[]}function Oz(e){const t=new Set(nx());t.add(e),Fv(jT,JSON.stringify([...t]))}const Dz=350,Rz=1e4,Q1=Symbol("UPDATE_INSTANCE_STATE"),Lz=e=>e;class Fz{constructor(t){m(this,"onmessage")}postMessage(t){}close(){}}const Nz=typeof BroadcastChannel>"u"?Fz:BroadcastChannel;class zz{constructor(t,{persistenceKey:n,sessionId:r=Gp,onLoad:o,onLoadError:s},i=new Nz(`tldraw-tab-sync-${n}`)){m(this,"disposables",new Set);m(this,"diffQueue",[]);m(this,"didDispose",!1);m(this,"shouldDoFullDBWrite",!0);m(this,"isReloading",!1);m(this,"persistenceKey");m(this,"sessionId");m(this,"serializedSchema");m(this,"isDebugging",!1);m(this,"documentTypes");m(this,"$sessionStateSnapshot");m(this,"initTime",Date.now());m(this,"isPersisting",!1);m(this,"didLastWriteError",!1);m(this,"scheduledPersistTimeout",null);this.store=t,this.channel=i,typeof window<"u"&&(window.tlsync=this),this.persistenceKey=n,this.sessionId=r,this.serializedSchema=this.store.schema.serialize(),this.$sessionStateSnapshot=pz(this.store),this.disposables.add(t.listen(({changes:a})=>{this.diffQueue.push(a),this.channel.postMessage(Lz({type:"diff",storeId:this.store.id,changes:a,schema:this.serializedSchema})),this.schedulePersist()},{source:"user",scope:"document"})),this.disposables.add(t.listen(()=>{this.diffQueue.push(Q1),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(...t){this.isDebugging&&console.debug(...t)}async connect(t,n){this.debug("connecting");let r;try{r=await $z({persistenceKey:this.persistenceKey,sessionId:this.sessionId,didCancel:()=>this.didDispose})}catch(o){n(o),yz(),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??gz(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),n(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&&fz(this.store,s)}this.channel.onmessage=({data:o})=>{var a,l;this.debug("got message",o);const s=o,i=GD(this.serializedSchema,s.schema??this.store.schema.serializeEarliestVersion());if(i===-1){if(Date.now()-this.initTime<5e3){n(new Error("Schema mismatch, please close other tabs and reload the page"));return}this.debug("reloading"),this.isReloading=!0,(l=(a=window==null?void 0:window.location)==null?void 0:a.reload)==null||l.call(a);return}else if(i===1){this.debug("telling them to reload"),this.channel.postMessage({type:"announce",schema:this.serializedSchema}),this.shouldDoFullDBWrite=!0,this.persistIfNeeded();return}s.type==="diff"&&(this.debug("applying diff"),Tr(()=>{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()}),t(this)}catch(o){if(this.debug("error loading data from store",o),this.didDispose)return;n(o);return}}close(){this.debug("closing"),this.didDispose=!0,this.disposables.forEach(t=>t())}schedulePersist(){this.debug("schedulePersist",this.scheduledPersistTimeout),!this.scheduledPersistTimeout&&(this.scheduledPersistTimeout=setTimeout(()=>{this.scheduledPersistTimeout=null,this.persistIfNeeded()},this.didLastWriteError?Rz:Dz))}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(){Ao(!this.isPersisting,"persist already in progress"),this.isPersisting=!0,this.debug("doPersist start");const t=this.diffQueue;this.diffQueue=[];try{if(this.shouldDoFullDBWrite)this.shouldDoFullDBWrite=!1,await Az({persistenceKey:this.persistenceKey,schema:this.store.schema,snapshot:this.store.serialize(),didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()});else{const n=df(t.filter(r=>r!==Q1));await Mz({persistenceKey:this.persistenceKey,changes:n,schema:this.store.schema,didCancel:()=>this.didDispose,sessionId:this.sessionId,sessionStateSnapshot:this.$sessionStateSnapshot.get()})}this.didLastWriteError=!1}catch(n){this.shouldDoFullDBWrite=!0,this.didLastWriteError=!0,console.error("failed to store changes in indexed db",n),mz(),typeof window<"u"&&window.location.reload()}this.isPersisting=!1,this.debug("doPersist end"),this.schedulePersist()}}function OT({initialData:e,defaultName:t="",...n}){const r="schema"in n&&n.schema?n.schema:KR({shapes:Bz(CT("shapeUtils"in n&&n.shapeUtils?n.shapeUtils:[]))});return new KI({schema:r,initialData:e,props:{defaultName:t}})}function Bz(e){return Object.fromEntries(e.map(t=>[t.type,{props:t.props,migrations:t.migrations}]))}function J1(e){const t=OT(e);return e.snapshot&&t.loadSnapshot(e.snapshot),{store:t,opts:e}}function DT(e){const[t,n]=x.useState(()=>J1(e));if(!OI(t.opts,e)){const r=J1(e);return n(r),r.store}return t.store}function Uz({persistenceKey:e,sessionId:t,...n}){const[r,o]=x.useState(null),s=DT(n);return x.useEffect(()=>{const i=nt();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 zz(s,{sessionId:t,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,t]),(r==null?void 0:r.storeWithStatus)??{status:"loading"}}let RT=!1;if(typeof window<"u"){const e=window.navigator.userAgent,t=!!e.match(/iPad/i)||!!e.match(/iPhone/i),n=!!e.match(/WebKit/i);RT=t&&n&&!e.match(/CriOS/i)}function Hz(){const e=z();x.useEffect(()=>{if(!RT)return;function t(n){(n.target instanceof HTMLInputElement&&n.target.type==="text"||n.target instanceof HTMLTextAreaElement)&&e.complete()}return document.addEventListener("focusout",t),()=>document.removeEventListener("focusout",t)},[e])}function Kz(){const e=z(),t=ln();x.useEffect(()=>{const n=s=>t.style.setProperty("--tl-zoom",s.toString()),r=jI(n,100),o=new ul("useZoomCss",()=>{e.getCurrentPageShapeIds().size<300?n(e.getZoomLevel()):r(e.getZoomLevel())});return o.attach(),o.execute(),()=>{o.detach()}},[e,t])}const Vz=[],Wz=[],Gz=x.memo(function({store:t,components:n,className:r,user:o,...s}){const[i,a]=Se.useState(null),l=x.useMemo(()=>o??m_(),[o]),c=(n==null?void 0:n.ErrorFallback)===void 0?c_:n==null?void 0:n.ErrorFallback,u={...s,shapeUtils:s.shapeUtils??Vz,tools:s.tools??Wz,components:n};return h.jsx("div",{ref:a,draggable:!1,className:ue("tl-container tl-theme__light",r),onPointerDown:rn,tabIndex:-1,children:h.jsx(Lc,{fallback:c,onError:d=>Dv(d,{tags:{origin:"react.tldraw-before-app"}}),children:i&&h.jsx(I3,{container:i,children:h.jsx(WF,{overrides:n,children:t?t instanceof KI?h.jsx(FT,{...u,store:t,user:l}):h.jsx(LT,{...u,store:t,user:l}):h.jsx(Yz,{...u,store:t,user:l})})})})})});function Yz(e){const{defaultName:t,snapshot:n,initialData:r,shapeUtils:o,persistenceKey:s,sessionId:i,user:a}=e,l=Uz({shapeUtils:o,initialData:r,persistenceKey:s,sessionId:i,defaultName:t,snapshot:n});return h.jsx(LT,{...e,store:l,user:a})}const LT=x.memo(function({store:t,user:n,...r}){const o=ln();x.useLayoutEffect(()=>{n.userPreferences.get().isDarkMode&&(o.classList.remove("tl-theme__light"),o.classList.add("tl-theme__dark"))},[o,n]);const{LoadingScreen:s}=ht();switch(t.status){case"error":throw t.error;case"loading":return s?h.jsx(s,{}):null}return h.jsx(FT,{...r,store:t.store,user:n})});function FT({onMount:e,children:t,store:n,tools:r,shapeUtils:o,user:s,initialState:i,autoFocus:a=!0,inferDarkMode:l}){const{ErrorFallback:c}=ht(),u=ln(),[d,p]=x.useState(null);x.useLayoutEffect(()=>{const g=new oe({store:n,shapeUtils:o,tools:r,getContainer:()=>u,user:s,initialState:i,inferDarkMode:l});return p(g),()=>{g.dispose()}},[u,o,r,n,s,i,l]);const f=x.useSyncExternalStore(x.useCallback(g=>d?(d.on("crash",g),()=>d.off("crash",g)):()=>{},[d]),()=>(d==null?void 0:d.getCrashingError())??null),{Canvas:y}=ht();return d?h.jsx(Lc,{fallback:c,onError:g=>d.annotateError(g,{origin:"react.tldraw",willCrashApp:!0}),children:f?h.jsx(qz,{crashingError:f}):h.jsx(ff.Provider,{value:d,children:h.jsx(Xz,{autoFocus:a,onMount:e,children:t??(y?h.jsx(y,{}):null)})})}):null}function Xz({children:e,onMount:t,autoFocus:n}){return Kz(),sz(),iz(),Hz(),lz(),az(n),Zz(t),h.jsx(h.Fragment,{children:e})}function qz({crashingError:e}){throw e}function NT({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function zT({children:e}){return h.jsx("div",{className:"tl-loading",children:e})}function Zz(e){const t=z(),n=ex(r=>{const o=e==null?void 0:e(r);return r.emit("mount"),window.tldrawReady=!0,o});Se.useLayoutEffect(()=>{if(t)return n==null?void 0:n(t)},[t,n])}function Ti({children:e,className:t="",...n}){return h.jsx("div",{...n,className:ue("tl-html-container",t),children:e})}function BT(e,t,n={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=t,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let d=e.props.w*s,p=e.props.h*i;const f=new b(0,0);if(d>0){if(d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=d-a;break}case"top":case"bottom":{f.x=(d-a)/2;break}default:f.x=0}d=a}}else if(f.x=d,d=-d,d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-d;break}default:f.x=-a}d=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:y,y:g}=f.rot(e.rotation).add(r);return{x:y,y:g,props:{w:Math.min(l,d),h:Math.min(u,p)}}}class Sl extends Rr{constructor(){super(...arguments);m(this,"onResize",(n,r)=>BT(n,r))}getGeometry(n){return new Ho({width:n.props.w,height:n.props.h,isFilled:!0})}getHandleSnapGeometry(n){return{points:this.getGeometry(n).bounds.cornersAndCenter}}}var iy;let Qz=(iy=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(iy,"id","idle"),iy);var ay;let Jz=(ay=class extends re{constructor(){super(...arguments);m(this,"markId","");m(this,"wasFocusedOnEnter",!1);m(this,"onEnter",()=>{this.wasFocusedOnEnter=!this.editor.getIsMenuOpen()});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=this.parent.shapeType,s=Be();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",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:this.parent.onCreate})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:n}=this.editor.inputs;if(!this.wasFocusedOnEnter)return;this.editor.mark(this.markId);const r=this.parent.shapeType,o=Be();this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:r,x:n.x,y:n.y}]);const s=this.editor.getShape(o),{w:i,h:a}=this.editor.getShapeUtil(s).getDefaultProps(),l=new b(i/2,a/2),c=this.editor.getShapeParentTransform(s);c&&l.rot(-c.rotation()),this.editor.updateShapes([{id:o,type:r,x:s.x-l.x,y:s.y-l.y}]),this.editor.setSelectedShapes([o]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},m(ay,"id","pointing"),ay);class Sh extends re{constructor(){super(...arguments);m(this,"onCreate")}}m(Sh,"id","box"),m(Sh,"initial","idle"),m(Sh,"children",()=>[Qz,Jz]);function Ff(e){const t=z();return K("isEditing",()=>t.getEditingShapeId()===e,[t,e])}function e8(){return x.useId().replace(/:/g,"_")}function Wr(e){const t=z();return x.useMemo(function(){const o=c=>{if(c.isKilled)return;if(c.button===2){t.dispatch({type:"pointer",target:"selection",handle:e,name:"right_click",...En(c)});return}if(c.button!==0)return;const u=mp(c.currentTarget);function d(){u.removeEventListener("pointerup",d),Pu(u,c)}pl(u,c),u.addEventListener("pointerup",d),t.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:e,...En(c)}),rn(c)};let s,i;function a(c){c.isKilled||c.button===0&&(c.clientX===s&&c.clientY===i||(s=c.clientX,i=c.clientY,t.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:e,...En(c)})))}return{onPointerDown:o,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&t.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:e,...En(c)})}}},[t,e])}const t8=20,n8=8;function rx(e,t=t8){return Math.max(n8,Math.ceil(e/t))}class UT extends Li{constructor(n){super({...n,isFilled:!1,isClosed:!1});m(this,"_center");m(this,"radius");m(this,"start");m(this,"end");m(this,"measure");m(this,"length");m(this,"angleStart");m(this,"angleEnd");const{center:r,radius:o,sweepFlag:s,largeArcFlag:i,start:a,end:l}=n;if(a.equals(l))throw Error("Arc must have different start and end points.");this.angleStart=b.Angle(r,a),this.angleEnd=b.Angle(r,l),this.measure=t3(this.angleStart,this.angleEnd,s,i),this.length=this.measure*o,this.start=a,this.end=l,this._center=r,this.radius=o}nearestPoint(n){const{_center:r,measure:o,radius:s,angleEnd:i,angleStart:a,start:l,end:c}=this,u=Ry(o,a,i,r.angle(n));if(u<=0)return l;if(u>=1)return c;const d=r.clone().add(n.clone().sub(r).uni().mul(s));let p,f=1/0,y;for(const g of[l,c,d])y=b.Dist2(n,g),y<f&&(p=g,f=y);if(!p)throw Error("nearest point not found");return p}hitTestLineSegment(n,r){const{_center:o,radius:s,measure:i,angleStart:a,angleEnd:l}=this,c=Af(n,r,o,s);return c===null?!1:c.some(u=>{const d=Ry(i,a,l,o.angle(u));return d>=0&&d<=1})}getVertices(){const{_center:n,measure:r,length:o,radius:s,angleStart:i}=this,a=[];for(let l=0,c=rx(Math.abs(o));l<c+1;l++){const u=l/c*r,d=i+u;a.push(bi(n,s,d))}return a}}class ox extends Li{constructor(n){super({isClosed:!0,...n});m(this,"_center");m(this,"radius");m(this,"x");m(this,"y");this.config=n;const{x:r=0,y:o=0,radius:s}=n;this.x=r,this.y=o,this._center=new b(s+r,s+o),this.radius=s}getBounds(){return new te(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,o=Fe*r,s=[];for(let i=0,a=rx(o);i<a;i++){const l=i/a*Fe;s.push(bi(n,r,l))}return s}nearestPoint(n){const{_center:r,radius:o}=this;return r.equals(n)?b.AddXY(r,o,0):r.clone().add(n.clone().sub(r).uni().mul(o))}hitTestLineSegment(n,r,o=0){const{_center:s,radius:i}=this;return Af(n,r,s,i+o)!==null}}class r8 extends Bi{constructor(n){const{start:r,cp1:o,cp2:s,end:i}=n;super({...n,points:[r,i]});m(this,"a");m(this,"b");m(this,"c");m(this,"d");this.a=r,this.b=o,this.c=s,this.d=i}getVertices(){const n=[],{a:r,b:o,c:s,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;n.push(new b((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 n}midPoint(){return o8(this,.5)}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(n),s=b.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}}function o8(e,t){const{a:n,b:r,c:o,d:s}=e;return new b((1-t)*(1-t)*(1-t)*n.x+3*((1-t)*(1-t))*t*r.x+3*(1-t)*(t*t)*o.x+t*t*t*s.x,(1-t)*(1-t)*(1-t)*n.y+3*((1-t)*(1-t))*t*r.y+3*(1-t)*(t*t)*o.y+t*t*t*s.y)}class s8 extends Li{constructor(n){super({...n,isClosed:!1,isFilled:!1});m(this,"points");m(this,"_segments");m(this,"_length");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,o=r-2,s=1.25;for(let i=0;i<r-1;i++){const a=i===0?n[0]:n[i-1],l=n[i],c=n[i+1],u=i===o?c:n[i+2],d=l,p=i===0?a:new b(l.x+(c.x-a.x)/6*s,l.y+(c.y-a.y)/6*s),f=i===o?c:new b(c.x-(u.x-l.x)/6*s,c.y-(u.y-l.y)/6*s),y=c;this._segments.push(new r8({start:d,cp1:p,cp2:f,end:y}))}}return this._segments}get length(){return this._length||(this._length=this.segments.reduce((n,r)=>n+r.length,0)),this._length}getVertices(){const n=this.segments.reduce((r,o)=>r.concat(o.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.segments)i=a.nearestPoint(n),s=b.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(o=>o.hitTestLineSegment(n,r))}}class HT extends Li{constructor(n){super({...n,isClosed:!0});m(this,"w");m(this,"h");m(this,"_edges");this.config=n;const{width:r,height:o}=n;this.w=r,this.h=o}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,o=n.length;r<o;r++){const s=n[r],i=n[(r+1)%o];this._edges.push(new ou({start:s,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),o=n/2,s=r/2,i=Math.pow(o-s,2)/Math.pow(o+s,2),a=je*(o+s)*(1+3*i/(10+Math.sqrt(4-3*i))),l=rx(a),c=Fe/l,u=Math.cos(c),d=Math.sin(c);let p=0,f=1,y=0,g=1;const w=Array(l);for(let S=0;S<l;S++)w[S]=new b(o+o*f,s+s*p),y=d*f+u*p,g=u*f-d*p,p=y,f=g;return w}nearestPoint(n){let r,o=1/0,s,i;for(const a of this.edges)i=a.nearestPoint(n),s=b.Dist2(i,n),s<o&&(r=i,o=s);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(o=>o.hitTestLineSegment(n,r))}getBounds(){return new te(0,0,this.w,this.h)}}const wo=18;class i8 extends HT{constructor(t){super({...t}),this.config=t}getVertices(){const t=Math.max(1,this.w),n=Math.max(1,this.h),r=t/2,o=n/2,s=Array(wo);let i,a;if(n>t)for(let l=0;l<wo-1;l++)i=-je+je*l/(wo-2),a=je*l/(wo-2),s[l]=new b(r+r*Math.cos(i),r+r*Math.sin(i)),s[l+(wo-1)]=new b(r+r*Math.cos(a),n-r+r*Math.sin(a));else for(let l=0;l<wo-1;l++)i=-Ge+je*l/(wo-2),a=Ge+je*-l/(wo-2),s[l]=new b(t-o+o*Math.cos(i),n-o+o*Math.sin(i)),s[l+(wo-1)]=new b(o-o*Math.cos(a),n-o+o*Math.sin(a));return s}}function eP(e,t,n,r,o){const s=g3,i=n?m3:0,a=e-i,l=e+i,c=r?0:s,u=o?t:t-s;return a<c?Math.min(1,(c-a)/s):l>u?-Math.min(1,(l-u)/s):0}function sx(e){if(!e.inputs.isDragging||e.inputs.isPanning||!e.getInstanceState().canMoveCamera)return;const{inputs:{currentScreenPoint:{x:t,y:n}}}=e,r=e.getZoomLevel(),o=e.getViewportScreenBounds(),s=o.w<1e3?.612:1,i=o.h<1e3?.612:1,{isCoarsePointer:a,insets:[l,c,u,d]}=e.getInstanceState(),p=eP(t,o.w,a,d,c),f=eP(n,o.h,a,l,u);if(p===0&&f===0)return;const y=e.user.getEdgeScrollSpeed()*f3,g=y*p*s/r,w=y*f*i/r,S=e.getCamera();e.setCamera({x:S.x+g,y:S.y+w})}async function a8({shouldReload:e=!0}={}){AD(),await Promise.all(nx().map(t=>_z(t))),MD(),e&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=a8);function l8(e,t="_blank"){r0.openWindow(e,t)}var Xl=function(e){return e&&e.Math===Math&&e},Rn=Xl(typeof globalThis=="object"&&globalThis)||Xl(typeof window=="object"&&window)||Xl(typeof self=="object"&&self)||Xl(typeof tn=="object"&&tn)||Xl(typeof tn=="object"&&tn)||function(){return this}()||Function("return this")(),ix={},yn=function(e){try{return!!e()}catch{return!0}},c8=yn,Ws=!c8(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),u8=yn,Nf=!u8(function(){var e=(function(){}).bind();return typeof e!="function"||e.hasOwnProperty("prototype")}),d8=Nf,_d=Function.prototype.call,Qo=d8?_d.bind(_d):function(){return _d.apply(_d,arguments)},KT={},VT={}.propertyIsEnumerable,WT=Object.getOwnPropertyDescriptor,h8=WT&&!VT.call({1:2},1);KT.f=h8?function(t){var n=WT(this,t);return!!n&&n.enumerable}:VT;var GT=function(e,t){return{enumerable:!(e&1),configurable:!(e&2),writable:!(e&4),value:t}},YT=Nf,XT=Function.prototype,NS=XT.call,p8=YT&&XT.bind.bind(NS,NS),At=YT?p8:function(e){return function(){return NS.apply(e,arguments)}},qT=At,f8=qT({}.toString),g8=qT("".slice),vl=function(e){return g8(f8(e),8,-1)},m8=At,y8=yn,S8=vl,mm=Object,v8=m8("".split),x8=y8(function(){return!mm("z").propertyIsEnumerable(0)})?function(e){return S8(e)==="String"?v8(e,""):mm(e)}:mm,zf=function(e){return e==null},w8=zf,b8=TypeError,xl=function(e){if(w8(e))throw new b8("Can't call method on "+e);return e},P8=x8,C8=xl,Bf=function(e){return P8(C8(e))},ym=typeof document=="object"&&document.all,Sn=typeof ym>"u"&&ym!==void 0?function(e){return typeof e=="function"||e===ym}:function(e){return typeof e=="function"},I8=Sn,Ui=function(e){return typeof e=="object"?e!==null:I8(e)},Sm=Rn,E8=Sn,_8=function(e){return E8(e)?e:void 0},Uf=function(e,t){return arguments.length<2?_8(Sm[e]):Sm[e]&&Sm[e][t]},k8=At,ZT=k8({}.isPrototypeOf),T8=typeof navigator<"u"&&String(navigator.userAgent)||"",QT=Rn,vm=T8,tP=QT.process,nP=QT.Deno,rP=tP&&tP.versions||nP&&nP.version,oP=rP&&rP.v8,Mr,Yp;oP&&(Mr=oP.split("."),Yp=Mr[0]>0&&Mr[0]<4?1:+(Mr[0]+Mr[1]));!Yp&&vm&&(Mr=vm.match(/Edge\/(\d+)/),(!Mr||Mr[1]>=74)&&(Mr=vm.match(/Chrome\/(\d+)/),Mr&&(Yp=+Mr[1])));var $8=Yp,sP=$8,M8=yn,A8=Rn,j8=A8.String,JT=!!Object.getOwnPropertySymbols&&!M8(function(){var e=Symbol("symbol detection");return!j8(e)||!(Object(e)instanceof Symbol)||!Symbol.sham&&sP&&sP<41}),O8=JT,e2=O8&&!Symbol.sham&&typeof Symbol.iterator=="symbol",D8=Uf,R8=Sn,L8=ZT,F8=e2,N8=Object,t2=F8?function(e){return typeof e=="symbol"}:function(e){var t=D8("Symbol");return R8(t)&&L8(t.prototype,N8(e))},z8=String,B8=function(e){try{return z8(e)}catch{return"Object"}},U8=Sn,H8=B8,K8=TypeError,ax=function(e){if(U8(e))return e;throw new K8(H8(e)+" is not a function")},V8=ax,W8=zf,lx=function(e,t){var n=e[t];return W8(n)?void 0:V8(n)},xm=Qo,wm=Sn,bm=Ui,G8=TypeError,Y8=function(e,t){var n,r;if(t==="string"&&wm(n=e.toString)&&!bm(r=xm(n,e))||wm(n=e.valueOf)&&!bm(r=xm(n,e))||t!=="string"&&wm(n=e.toString)&&!bm(r=xm(n,e)))return r;throw new G8("Can't convert object to primitive value")},n2={exports:{}},iP=Rn,X8=Object.defineProperty,cx=function(e,t){try{X8(iP,e,{value:t,configurable:!0,writable:!0})}catch{iP[e]=t}return t},q8=Rn,Z8=cx,aP="__core-js_shared__",lP=n2.exports=q8[aP]||Z8(aP,{});(lP.versions||(lP.versions=[])).push({version:"3.36.1",mode:"global",copyright:"© 2014-2024 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.36.1/LICENSE",source:"https://github.com/zloirock/core-js"});var ux=n2.exports,cP=ux,dx=function(e,t){return cP[e]||(cP[e]=t||{})},Q8=xl,J8=Object,Au=function(e){return J8(Q8(e))},e7=At,t7=Au,n7=e7({}.hasOwnProperty),Gs=Object.hasOwn||function(t,n){return n7(t7(t),n)},r7=At,o7=0,s7=Math.random(),i7=r7(1 .toString),r2=function(e){return"Symbol("+(e===void 0?"":e)+")_"+i7(++o7+s7,36)},a7=Rn,l7=dx,uP=Gs,c7=r2,u7=JT,d7=e2,_a=a7.Symbol,Pm=l7("wks"),h7=d7?_a.for||_a:_a&&_a.withoutSetter||c7,Jo=function(e){return uP(Pm,e)||(Pm[e]=u7&&uP(_a,e)?_a[e]:h7("Symbol."+e)),Pm[e]},p7=Qo,dP=Ui,hP=t2,f7=lx,g7=Y8,m7=Jo,y7=TypeError,S7=m7("toPrimitive"),v7=function(e,t){if(!dP(e)||hP(e))return e;var n=f7(e,S7),r;if(n){if(t===void 0&&(t="default"),r=p7(n,e,t),!dP(r)||hP(r))return r;throw new y7("Can't convert object to primitive value")}return t===void 0&&(t="number"),g7(e,t)},x7=v7,w7=t2,o2=function(e){var t=x7(e,"string");return w7(t)?t:t+""},b7=Rn,pP=Ui,zS=b7.document,P7=pP(zS)&&pP(zS.createElement),s2=function(e){return P7?zS.createElement(e):{}},C7=Ws,I7=yn,E7=s2,i2=!C7&&!I7(function(){return Object.defineProperty(E7("div"),"a",{get:function(){return 7}}).a!==7}),_7=Ws,k7=Qo,T7=KT,$7=GT,M7=Bf,A7=o2,j7=Gs,O7=i2,fP=Object.getOwnPropertyDescriptor;ix.f=_7?fP:function(t,n){if(t=M7(t),n=A7(n),O7)try{return fP(t,n)}catch{}if(j7(t,n))return $7(!k7(T7.f,t,n),t[n])};var wl={},D7=Ws,R7=yn,a2=D7&&R7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),L7=Ui,F7=String,N7=TypeError,Hi=function(e){if(L7(e))return e;throw new N7(F7(e)+" is not an object")},z7=Ws,B7=i2,U7=a2,kd=Hi,gP=o2,H7=TypeError,Cm=Object.defineProperty,K7=Object.getOwnPropertyDescriptor,Im="enumerable",Em="configurable",_m="writable";wl.f=z7?U7?function(t,n,r){if(kd(t),n=gP(n),kd(r),typeof t=="function"&&n==="prototype"&&"value"in r&&_m in r&&!r[_m]){var o=K7(t,n);o&&o[_m]&&(t[n]=r.value,r={configurable:Em in r?r[Em]:o[Em],enumerable:Im in r?r[Im]:o[Im],writable:!1})}return Cm(t,n,r)}:Cm:function(t,n,r){if(kd(t),n=gP(n),kd(r),B7)try{return Cm(t,n,r)}catch{}if("get"in r||"set"in r)throw new H7("Accessors not supported");return"value"in r&&(t[n]=r.value),t};var V7=Ws,W7=wl,G7=GT,hx=V7?function(e,t,n){return W7.f(e,t,G7(1,n))}:function(e,t,n){return e[t]=n,e},l2={exports:{}},BS=Ws,Y7=Gs,c2=Function.prototype,X7=BS&&Object.getOwnPropertyDescriptor,px=Y7(c2,"name"),q7=px&&(function(){}).name==="something",Z7=px&&(!BS||BS&&X7(c2,"name").configurable),Q7={EXISTS:px,PROPER:q7,CONFIGURABLE:Z7},J7=At,eB=Sn,US=ux,tB=J7(Function.toString);eB(US.inspectSource)||(US.inspectSource=function(e){return tB(e)});var u2=US.inspectSource,nB=Rn,rB=Sn,mP=nB.WeakMap,oB=rB(mP)&&/native code/.test(String(mP)),sB=dx,iB=r2,yP=sB("keys"),d2=function(e){return yP[e]||(yP[e]=iB(e))},fx={},aB=oB,h2=Rn,lB=Ui,cB=hx,km=Gs,Tm=ux,uB=d2,dB=fx,SP="Object already initialized",HS=h2.TypeError,hB=h2.WeakMap,Xp,iu,qp,pB=function(e){return qp(e)?iu(e):Xp(e,{})},fB=function(e){return function(t){var n;if(!lB(t)||(n=iu(t)).type!==e)throw new HS("Incompatible receiver, "+e+" required");return n}};if(aB||Tm.state){var Kr=Tm.state||(Tm.state=new hB);Kr.get=Kr.get,Kr.has=Kr.has,Kr.set=Kr.set,Xp=function(e,t){if(Kr.has(e))throw new HS(SP);return t.facade=e,Kr.set(e,t),t},iu=function(e){return Kr.get(e)||{}},qp=function(e){return Kr.has(e)}}else{var oa=uB("state");dB[oa]=!0,Xp=function(e,t){if(km(e,oa))throw new HS(SP);return t.facade=e,cB(e,oa,t),t},iu=function(e){return km(e,oa)?e[oa]:{}},qp=function(e){return km(e,oa)}}var p2={set:Xp,get:iu,has:qp,enforce:pB,getterFor:fB},gx=At,gB=yn,mB=Sn,Td=Gs,KS=Ws,yB=Q7.CONFIGURABLE,SB=u2,f2=p2,vB=f2.enforce,xB=f2.get,vP=String,vh=Object.defineProperty,wB=gx("".slice),bB=gx("".replace),PB=gx([].join),CB=KS&&!gB(function(){return vh(function(){},"length",{value:8}).length!==8}),IB=String(String).split("String"),EB=l2.exports=function(e,t,n){wB(vP(t),0,7)==="Symbol("&&(t="["+bB(vP(t),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(t="get "+t),n&&n.setter&&(t="set "+t),(!Td(e,"name")||yB&&e.name!==t)&&(KS?vh(e,"name",{value:t,configurable:!0}):e.name=t),CB&&n&&Td(n,"arity")&&e.length!==n.arity&&vh(e,"length",{value:n.arity});try{n&&Td(n,"constructor")&&n.constructor?KS&&vh(e,"prototype",{writable:!1}):e.prototype&&(e.prototype=void 0)}catch{}var r=vB(e);return Td(r,"source")||(r.source=PB(IB,typeof t=="string"?t:"")),e};Function.prototype.toString=EB(function(){return mB(this)&&xB(this).source||SB(this)},"toString");var _B=l2.exports,kB=Sn,TB=wl,$B=_B,MB=cx,g2=function(e,t,n,r){r||(r={});var o=r.enumerable,s=r.name!==void 0?r.name:t;if(kB(n)&&$B(n,s,r),r.global)o?e[t]=n:MB(t,n);else{try{r.unsafe?e[t]&&(o=!0):delete e[t]}catch{}o?e[t]=n:TB.f(e,t,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return e},m2={},AB=Math.ceil,jB=Math.floor,OB=Math.trunc||function(t){var n=+t;return(n>0?jB:AB)(n)},DB=OB,Ki=function(e){var t=+e;return t!==t||t===0?0:DB(t)},RB=Ki,LB=Math.max,FB=Math.min,NB=function(e,t){var n=RB(e);return n<0?LB(n+t,0):FB(n,t)},zB=Ki,BB=Math.min,y2=function(e){var t=zB(e);return t>0?BB(t,9007199254740991):0},UB=y2,ju=function(e){return UB(e.length)},HB=Bf,KB=NB,VB=ju,xP=function(e){return function(t,n,r){var o=HB(t),s=VB(o);if(s===0)return!e&&-1;var i=KB(r,s),a;if(e&&n!==n){for(;s>i;)if(a=o[i++],a!==a)return!0}else for(;s>i;i++)if((e||i in o)&&o[i]===n)return e||i||0;return!e&&-1}},WB={includes:xP(!0),indexOf:xP(!1)},GB=At,$m=Gs,YB=Bf,XB=WB.indexOf,qB=fx,wP=GB([].push),S2=function(e,t){var n=YB(e),r=0,o=[],s;for(s in n)!$m(qB,s)&&$m(n,s)&&wP(o,s);for(;t.length>r;)$m(n,s=t[r++])&&(~XB(o,s)||wP(o,s));return o},mx=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],ZB=S2,QB=mx,JB=QB.concat("length","prototype");m2.f=Object.getOwnPropertyNames||function(t){return ZB(t,JB)};var v2={};v2.f=Object.getOwnPropertySymbols;var e9=Uf,t9=At,n9=m2,r9=v2,o9=Hi,s9=t9([].concat),i9=e9("Reflect","ownKeys")||function(t){var n=n9.f(o9(t)),r=r9.f;return r?s9(n,r(t)):n},bP=Gs,a9=i9,l9=ix,c9=wl,u9=function(e,t,n){for(var r=a9(t),o=c9.f,s=l9.f,i=0;i<r.length;i++){var a=r[i];!bP(e,a)&&!(n&&bP(n,a))&&o(e,a,s(t,a))}},d9=yn,h9=Sn,p9=/#|\.prototype\./,Ou=function(e,t){var n=g9[f9(e)];return n===y9?!0:n===m9?!1:h9(t)?d9(t):!!t},f9=Ou.normalize=function(e){return String(e).replace(p9,".").toLowerCase()},g9=Ou.data={},m9=Ou.NATIVE="N",y9=Ou.POLYFILL="P",S9=Ou,$d=Rn,v9=ix.f,x9=hx,w9=g2,b9=cx,P9=u9,C9=S9,bl=function(e,t){var n=e.target,r=e.global,o=e.stat,s,i,a,l,c,u;if(r?i=$d:o?i=$d[n]||b9(n,{}):i=$d[n]&&$d[n].prototype,i)for(a in t){if(c=t[a],e.dontCallGetSet?(u=v9(i,a),l=u&&u.value):l=i[a],s=C9(r?a:n+(o?".":"#")+a,e.forced),!s&&l!==void 0){if(typeof c==typeof l)continue;P9(c,l)}(e.sham||l&&l.sham)&&x9(c,"sham",!0),w9(i,a,c,e)}},x2={},I9=S2,E9=mx,_9=Object.keys||function(t){return I9(t,E9)},k9=Ws,T9=a2,$9=wl,M9=Hi,A9=Bf,j9=_9;x2.f=k9&&!T9?Object.defineProperties:function(t,n){M9(t);for(var r=A9(n),o=j9(n),s=o.length,i=0,a;s>i;)$9.f(t,a=o[i++],r[a]);return t};var O9=Uf,D9=O9("document","documentElement"),R9=Hi,L9=x2,PP=mx,F9=fx,N9=D9,z9=s2,B9=d2,CP=">",IP="<",VS="prototype",WS="script",w2=B9("IE_PROTO"),Mm=function(){},b2=function(e){return IP+WS+CP+e+IP+"/"+WS+CP},EP=function(e){e.write(b2("")),e.close();var t=e.parentWindow.Object;return e=null,t},U9=function(){var e=z9("iframe"),t="java"+WS+":",n;return e.style.display="none",N9.appendChild(e),e.src=String(t),n=e.contentWindow.document,n.open(),n.write(b2("document.F=Object")),n.close(),n.F},Md,xh=function(){try{Md=new ActiveXObject("htmlfile")}catch{}xh=typeof document<"u"?document.domain&&Md?EP(Md):U9():EP(Md);for(var e=PP.length;e--;)delete xh[VS][PP[e]];return xh()};F9[w2]=!0;var P2=Object.create||function(t,n){var r;return t!==null?(Mm[VS]=R9(t),r=new Mm,Mm[VS]=null,r[w2]=t):r=xh(),n===void 0?r:L9.f(r,n)},H9=Jo,K9=P2,V9=wl.f,GS=H9("unscopables"),YS=Array.prototype;YS[GS]===void 0&&V9(YS,GS,{configurable:!0,value:K9(null)});var yx=function(e){YS[GS][e]=!0},W9=bl,G9=Au,Y9=ju,X9=Ki,q9=yx;W9({target:"Array",proto:!0},{at:function(t){var n=G9(this),r=Y9(n),o=X9(t),s=o>=0?o:r+o;return s<0||s>=r?void 0:n[s]}});q9("at");var Z9=Rn,Q9=At,Du=function(e,t){return Q9(Z9[e].prototype[t])},J9=Du;J9("Array","at");var eU=vl,C2=Array.isArray||function(t){return eU(t)==="Array"},tU=TypeError,nU=9007199254740991,rU=function(e){if(e>nU)throw tU("Maximum allowed index exceeded");return e},oU=vl,sU=At,iU=function(e){if(oU(e)==="Function")return sU(e)},_P=iU,aU=ax,lU=Nf,cU=_P(_P.bind),uU=function(e,t){return aU(e),t===void 0?e:lU?cU(e,t):function(){return e.apply(t,arguments)}},dU=C2,hU=ju,pU=rU,fU=uU,I2=function(e,t,n,r,o,s,i,a){for(var l=o,c=0,u=i?fU(i,a):!1,d,p;c<r;)c in n&&(d=u?u(n[c],c,t):n[c],s>0&&dU(d)?(p=hU(d),l=I2(e,t,d,p,l,s-1)-1):(pU(l+1),e[l]=d),l++),c++;return l},E2=I2,gU=Jo,mU=gU("toStringTag"),_2={};_2[mU]="z";var yU=String(_2)==="[object z]",SU=yU,vU=Sn,wh=vl,xU=Jo,wU=xU("toStringTag"),bU=Object,PU=wh(function(){return arguments}())==="Arguments",CU=function(e,t){try{return e[t]}catch{}},k2=SU?wh:function(e){var t,n,r;return e===void 0?"Undefined":e===null?"Null":typeof(n=CU(t=bU(e),wU))=="string"?n:PU?wh(t):(r=wh(t))==="Object"&&vU(t.callee)?"Arguments":r},IU=At,EU=yn,T2=Sn,_U=k2,kU=Uf,TU=u2,$2=function(){},M2=kU("Reflect","construct"),Sx=/^\s*(?:class|function)\b/,$U=IU(Sx.exec),MU=!Sx.test($2),ql=function(t){if(!T2(t))return!1;try{return M2($2,[],t),!0}catch{return!1}},A2=function(t){if(!T2(t))return!1;switch(_U(t)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return MU||!!$U(Sx,TU(t))}catch{return!0}};A2.sham=!0;var AU=!M2||EU(function(){var e;return ql(ql.call)||!ql(Object)||!ql(function(){e=!0})||e})?A2:ql,kP=C2,jU=AU,OU=Ui,DU=Jo,RU=DU("species"),TP=Array,LU=function(e){var t;return kP(e)&&(t=e.constructor,jU(t)&&(t===TP||kP(t.prototype))?t=void 0:OU(t)&&(t=t[RU],t===null&&(t=void 0))),t===void 0?TP:t},FU=LU,j2=function(e,t){return new(FU(e))(t===0?0:t)},NU=bl,zU=E2,BU=ax,UU=Au,HU=ju,KU=j2;NU({target:"Array",proto:!0},{flatMap:function(t){var n=UU(this),r=HU(n),o;return BU(t),o=KU(n,0),o.length=zU(o,n,n,r,0,1,t,arguments.length>1?arguments[1]:void 0),o}});var VU=yx;VU("flatMap");var WU=Du;WU("Array","flatMap");var GU=bl,YU=E2,XU=Au,qU=ju,ZU=Ki,QU=j2;GU({target:"Array",proto:!0},{flat:function(){var t=arguments.length?arguments[0]:void 0,n=XU(this),r=qU(n),o=QU(n,0);return o.length=YU(o,n,n,r,0,t===void 0?1:ZU(t)),o}});var JU=yx;JU("flat");var eH=Du;eH("Array","flat");var tH=k2,nH=String,Ru=function(e){if(tH(e)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return nH(e)},rH=bl,oH=At,sH=xl,iH=Ki,aH=Ru,lH=yn,cH=oH("".charAt),uH=lH(function(){return"𠮷".at(-2)!=="\uD842"});rH({target:"String",proto:!0,forced:uH},{at:function(t){var n=aH(sH(this)),r=n.length,o=iH(t),s=o>=0?o:r+o;return s<0||s>=r?void 0:cH(n,s)}});var dH=Du;dH("String","at");var hH=Hi,O2=function(){var e=hH(this),t="";return e.hasIndices&&(t+="d"),e.global&&(t+="g"),e.ignoreCase&&(t+="i"),e.multiline&&(t+="m"),e.dotAll&&(t+="s"),e.unicode&&(t+="u"),e.unicodeSets&&(t+="v"),e.sticky&&(t+="y"),t},vx=yn,pH=Rn,xx=pH.RegExp,wx=vx(function(){var e=xx("a","y");return e.lastIndex=2,e.exec("abcd")!==null}),fH=wx||vx(function(){return!xx("a","y").sticky}),gH=wx||vx(function(){var e=xx("^r","gy");return e.lastIndex=2,e.exec("str")!==null}),mH={BROKEN_CARET:gH,MISSED_STICKY:fH,UNSUPPORTED_Y:wx},yH=yn,SH=Rn,vH=SH.RegExp,xH=yH(function(){var e=vH(".","s");return!(e.dotAll&&e.test(`
90
- `)&&e.flags==="s")}),wH=yn,bH=Rn,PH=bH.RegExp,CH=wH(function(){var e=PH("(?<a>b)","g");return e.exec("b").groups.a!=="b"||"b".replace(e,"$<a>c")!=="bc"}),ka=Qo,Hf=At,IH=Ru,EH=O2,_H=mH,kH=dx,TH=P2,$H=p2.get,MH=xH,AH=CH,jH=kH("native-string-replace",String.prototype.replace),Zp=RegExp.prototype.exec,XS=Zp,OH=Hf("".charAt),DH=Hf("".indexOf),RH=Hf("".replace),Am=Hf("".slice),qS=function(){var e=/a/,t=/b*/g;return ka(Zp,e,"a"),ka(Zp,t,"a"),e.lastIndex!==0||t.lastIndex!==0}(),D2=_H.BROKEN_CARET,ZS=/()??/.exec("")[1]!==void 0,LH=qS||ZS||D2||MH||AH;LH&&(XS=function(t){var n=this,r=$H(n),o=IH(t),s=r.raw,i,a,l,c,u,d,p;if(s)return s.lastIndex=n.lastIndex,i=ka(XS,s,o),n.lastIndex=s.lastIndex,i;var f=r.groups,y=D2&&n.sticky,g=ka(EH,n),w=n.source,S=0,v=o;if(y&&(g=RH(g,"y",""),DH(g,"g")===-1&&(g+="g"),v=Am(o,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&OH(o,n.lastIndex-1)!==`
91
- `)&&(w="(?: "+w+")",v=" "+v,S++),a=new RegExp("^(?:"+w+")",g)),ZS&&(a=new RegExp("^"+w+"$(?!\\s)",g)),qS&&(l=n.lastIndex),c=ka(Zp,y?a:n,v),y?c?(c.input=Am(c.input,S),c[0]=Am(c[0],S),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:qS&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),ZS&&c&&c.length>1&&ka(jH,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=d=TH(null),u=0;u<f.length;u++)p=f[u],d[p[0]]=c[p[1]];return c});var bx=XS,FH=bl,$P=bx;FH({target:"RegExp",proto:!0,forced:/./.exec!==$P},{exec:$P});var NH=Nf,R2=Function.prototype,MP=R2.apply,AP=R2.call,zH=typeof Reflect=="object"&&Reflect.apply||(NH?AP.bind(MP):function(){return AP.apply(MP,arguments)}),jP=Qo,OP=g2,BH=bx,DP=yn,L2=Jo,UH=hx,HH=L2("species"),jm=RegExp.prototype,KH=function(e,t,n,r){var o=L2(e),s=!DP(function(){var c={};return c[o]=function(){return 7},""[e](c)!==7}),i=s&&!DP(function(){var c=!1,u=/a/;return e==="split"&&(u={},u.constructor={},u.constructor[HH]=function(){return u},u.flags="",u[o]=/./[o]),u.exec=function(){return c=!0,null},u[o](""),!c});if(!s||!i||n){var a=/./[o],l=t(o,""[e],function(c,u,d,p,f){var y=u.exec;return y===BH||y===jm.exec?s&&!f?{done:!0,value:jP(a,u,d,p)}:{done:!0,value:jP(c,d,u,p)}:{done:!1}});OP(String.prototype,e,l[0]),OP(jm,o,l[1])}r&&UH(jm[o],"sham",!0)},Px=At,VH=Ki,WH=Ru,GH=xl,YH=Px("".charAt),RP=Px("".charCodeAt),XH=Px("".slice),LP=function(e){return function(t,n){var r=WH(GH(t)),o=VH(n),s=r.length,i,a;return o<0||o>=s?e?"":void 0:(i=RP(r,o),i<55296||i>56319||o+1===s||(a=RP(r,o+1))<56320||a>57343?e?YH(r,o):i:e?XH(r,o,o+2):(i-55296<<10)+(a-56320)+65536)}},qH={codeAt:LP(!1),charAt:LP(!0)},ZH=qH.charAt,QH=function(e,t,n){return t+(n?ZH(e,t).length:1)},Cx=At,JH=Au,eK=Math.floor,Om=Cx("".charAt),tK=Cx("".replace),Dm=Cx("".slice),nK=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,rK=/\$([$&'`]|\d{1,2})/g,F2=function(e,t,n,r,o,s){var i=n+e.length,a=r.length,l=rK;return o!==void 0&&(o=JH(o),l=nK),tK(s,l,function(c,u){var d;switch(Om(u,0)){case"$":return"$";case"&":return e;case"`":return Dm(t,0,n);case"'":return Dm(t,i);case"<":d=o[Dm(u,1,-1)];break;default:var p=+u;if(p===0)return c;if(p>a){var f=eK(p/10);return f===0?c:f<=a?r[f-1]===void 0?Om(u,1):r[f-1]+Om(u,1):c}d=r[p-1]}return d===void 0?"":d})},FP=Qo,oK=Hi,sK=Sn,iK=vl,aK=bx,lK=TypeError,cK=function(e,t){var n=e.exec;if(sK(n)){var r=FP(n,e,t);return r!==null&&oK(r),r}if(iK(e)==="RegExp")return FP(aK,e,t);throw new lK("RegExp#exec called on incompatible receiver")},uK=zH,NP=Qo,Kf=At,dK=KH,hK=yn,pK=Hi,fK=Sn,gK=zf,mK=Ki,yK=y2,sa=Ru,SK=xl,vK=QH,xK=lx,wK=F2,bK=cK,PK=Jo,QS=PK("replace"),CK=Math.max,IK=Math.min,EK=Kf([].concat),Rm=Kf([].push),zP=Kf("".indexOf),BP=Kf("".slice),_K=function(e){return e===void 0?e:String(e)},kK=function(){return"a".replace(/./,"$0")==="$0"}(),UP=function(){return/./[QS]?/./[QS]("a","$0")==="":!1}(),TK=!hK(function(){var e=/./;return e.exec=function(){var t=[];return t.groups={a:"7"},t},"".replace(e,"$<a>")!=="7"});dK("replace",function(e,t,n){var r=UP?"$":"$0";return[function(s,i){var a=SK(this),l=gK(s)?void 0:xK(s,QS);return l?NP(l,s,a,i):NP(t,sa(a),s,i)},function(o,s){var i=pK(this),a=sa(o);if(typeof s=="string"&&zP(s,r)===-1&&zP(s,"$<")===-1){var l=n(t,i,a,s);if(l.done)return l.value}var c=fK(s);c||(s=sa(s));var u=i.global,d;u&&(d=i.unicode,i.lastIndex=0);for(var p=[],f;f=bK(i,a),!(f===null||(Rm(p,f),!u));){var y=sa(f[0]);y===""&&(i.lastIndex=vK(a,yK(i.lastIndex),d))}for(var g="",w=0,S=0;S<p.length;S++){f=p[S];for(var v=sa(f[0]),C=CK(IK(mK(f.index),a.length),0),I=[],P,E=1;E<f.length;E++)Rm(I,_K(f[E]));var _=f.groups;if(c){var k=EK([v],I,C,a);_!==void 0&&Rm(k,_),P=sa(uK(s,void 0,k))}else P=wK(v,a,C,I,_,s);C>=w&&(g+=BP(a,w,C)+P,w=C+v.length)}return g+BP(a,w)}]},!TK||!kK||UP);var $K=Ui,MK=vl,AK=Jo,jK=AK("match"),OK=function(e){var t;return $K(e)&&((t=e[jK])!==void 0?!!t:MK(e)==="RegExp")},DK=Qo,RK=Gs,LK=ZT,FK=O2,HP=RegExp.prototype,NK=function(e){var t=e.flags;return t===void 0&&!("flags"in HP)&&!RK(e,"flags")&&LK(HP,e)?DK(FK,e):t},zK=bl,BK=Qo,Ix=At,KP=xl,UK=Sn,HK=zf,KK=OK,Zl=Ru,VK=lx,WK=NK,GK=F2,YK=Jo,XK=YK("replace"),qK=TypeError,Lm=Ix("".indexOf);Ix("".replace);var VP=Ix("".slice),ZK=Math.max;zK({target:"String",proto:!0},{replaceAll:function(t,n){var r=KP(this),o,s,i,a,l,c,u,d,p,f=0,y=0,g="";if(!HK(t)){if(o=KK(t),o&&(s=Zl(KP(WK(t))),!~Lm(s,"g")))throw new qK("`.replaceAll` does not allow non-global regexes");if(i=VK(t,XK),i)return BK(i,t,r,n)}for(a=Zl(r),l=Zl(t),c=UK(n),c||(n=Zl(n)),u=l.length,d=ZK(1,u),f=Lm(a,l);f!==-1;)p=c?Zl(n(l,f,a)):GK(l,a,f,[],void 0,n),g+=VP(a,y,f)+p,y=f+u,f=f+d>a.length?-1:Lm(a,l,f+d);return y<a.length&&(g+=VP(a,y)),g}});var QK=Du;QK("String","replaceAll");function JK(e){return e.getSelectedShapeIds().map(r=>e.getShape(r)).filter(r=>!(!r||e.isShapeOfType(r,"arrow")&&r.props.start.type==="binding"||e.isShapeOfType(r,"arrow")&&r.props.end.type==="binding"))}const N2=()=>{const e=z();return K("threeStackableItems",()=>JK(e).length>2,[e])},z2=()=>{const e=z();return K("allow group",()=>{const t=e.getSelectedShapes();if(t.length<2)return!1;for(const n of t)if(e.isShapeOfType(n,"arrow")){const{start:r,end:o}=n.props;if(r.type==="binding"&&!t.some(s=>s.id===r.boundShapeId)||o.type==="binding"&&!t.some(s=>s.id===o.boundShapeId))return!1}return!0},[e])},B2=()=>{const e=z();return K("allowUngroup",()=>e.getSelectedShapeIds().some(t=>{var n;return((n=e.getShape(t))==null?void 0:n.type)==="group"}),[e])},eV=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function tV(e,t){const n=z();return K("selectedShapes",()=>{const r=n.getSelectedShapes().length;return e===void 0?t===void 0?r:r<=t:t===void 0?r>=e:r>=e&&r<=t},[n,e,t])}function vn(e,t){const n=z();return K("selectedShapes",()=>{const r=n.getSelectedShapes().filter(o=>!n.isShapeOrAncestorLocked(o)).length;return e===void 0?t===void 0?r:r<=t:t===void 0?r>=e:r>=e&&r<=t},[n])}function nV(){const e=z();return K("showAutoSizeToggle",()=>{const t=e.getSelectedShapes();return t.length===1&&e.isShapeOfType(t[0],"text")&&t[0].props.autoSize===!1},[e])}function U2(){const e=z();return K("hasLinkShapeSelected",()=>{const t=e.getOnlySelectedShape();return!!(t&&t.type!=="embed"&&"url"in t.props&&!t.isLocked)},[e])}function rV(){const e=z();return K("onlyFlippableShape",()=>{const t=e.getOnlySelectedShape();return t&&(e.isShapeOfType(t,"group")||e.isShapeOfType(t,"arrow")||e.isShapeOfType(t,"line")||e.isShapeOfType(t,"draw"))},[e])}function H2(){const e=z();return K("useCanRedo",()=>e.getCanRedo(),[e])}function K2(){const e=z();return K("useCanUndo",()=>e.getCanUndo(),[e])}function oV({children:e}){const t=z();return K("shouldDisplayHandles",()=>{if(t.isInAny("select.idle","select.pointing_handle","select.pointing_shape"))return!0;if(t.isInAny("select.editing_shape")){const r=t.getOnlySelectedShape();return r&&t.isShapeOfType(r,"note")}return!1},[t])?h.jsx("svg",{className:"tl-user-handles tl-overlays__item",children:e}):null}const{PI:sV}=Math,Ba=sV+1e-4;function V2(e,t={}){const{size:n=16,smoothing:r=.5}=t;if(e.length===0||n<=0)return{left:[],right:[]};const o=e[0],s=e[e.length-1],i=s.runningLength,a=Math.pow(n*r,2),l=[],c=[];let u=e[0].vector,d=e[0].point,p=d,f=d,y=p,g=!1,w;for(let S=0;S<e.length;S++){w=e[S];const{point:v,vector:C}=e[S],I=w.vector.dpr(u),P=(S<e.length-1?e[S+1]:e[S]).vector,E=S<e.length-1?P.dpr(w.vector):1,_=I<0&&!g,k=E!==null&&E<.2;if(_||k){if(E>-.62&&i-w.runningLength>w.radius){const T=u.clone().mul(w.radius);u.clone().cpr(P)<0?(f=b.Add(v,T),y=b.Sub(v,T)):(f=b.Sub(v,T),y=b.Add(v,T)),l.push(f),c.push(y)}else{const T=u.clone().mul(w.radius).per(),j=b.Sub(w.input,T);for(let L=1/13,N=0;N<1;N+=L)f=b.RotWith(j,w.input,Ba*N),l.push(f),y=b.RotWith(j,w.input,Ba+Ba*-N),c.push(y)}d=f,p=y,k&&(g=!0);continue}if(g=!1,w===o||w===s){const T=b.Per(C).mul(w.radius);l.push(b.Sub(v,T)),c.push(b.Add(v,T));continue}const $=b.Lrp(P,C,E).per().mul(w.radius);f=b.Sub(v,$),(S<=1||b.Dist2(d,f)>a)&&(l.push(f),d=f),y=b.Add(v,$),(S<=1||b.Dist2(p,y)>a)&&(c.push(y),p=y),u=C}return{left:l,right:c}}function Ex(e,t={}){const{size:n=16,start:r={},end:o={},last:s=!1}=t,{cap:i=!0}=r,{cap:a=!0}=o;if(e.length===0||n<=0)return[];const l=e[0],c=e[e.length-1],u=c.runningLength,d=r.taper===!1?0:r.taper===!0?Math.max(n,u):r.taper,p=o.taper===!1?0:o.taper===!0?Math.max(n,u):o.taper,{left:f,right:y}=V2(e,t),g=l.point,w=e.length>1?e[e.length-1].point:b.AddXY(l.point,1,1);if(e.length===1&&(!(d||p)||s)){const I=b.Add(g,b.Sub(g,w).uni().per().mul(-l.radius)),P=[];for(let E=1/13,_=E;_<=1;_+=E)P.push(b.RotWith(I,g,Ba*2*_));return P}const S=[];if(!(d||p&&e.length===1))if(i)for(let I=1/8,P=I;P<=1;P+=I){const E=b.RotWith(y[0],g,Ba*P);S.push(E)}else{const I=b.Sub(f[0],y[0]),P=b.Mul(I,.5),E=b.Mul(I,.51);S.push(b.Sub(g,P),b.Sub(g,E),b.Add(g,E),b.Add(g,P))}const v=[],C=c.vector.clone().per().neg();if(p||d&&e.length===1)v.push(w);else if(a){const I=b.Add(w,b.Mul(C,c.radius));for(let P=1/29,E=P;E<1;E+=P)v.push(b.RotWith(I,w,Ba*3*E))}else v.push(b.Add(w,b.Mul(C,c.radius)),b.Add(w,b.Mul(C,c.radius*.99)),b.Sub(w,b.Mul(C,c.radius*.99)),b.Sub(w,b.Mul(C,c.radius)));return f.concat(v,y.reverse(),S)}const iV=.025,aV=.01;function ao(e,t={}){var w;const{streamline:n=.5,size:r=16,simulatePressure:o=!1}=t;if(e.length===0)return[];const s=.15+(1-n)*.85;let i=e.map(b.From),a=0;if(!o){let S=i[0];for(;S&&!(S.z>=iV);)i.shift(),S=i[0]}if(!o){let S=i[i.length-1];for(;S&&!(S.z>=aV);)i.pop(),S=i[i.length-1]}if(i.length===0)return[{point:b.From(e[0]),input:b.From(e[0]),pressure:o?.5:.15,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let l=i[1];for(;l&&!(b.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&&!(b.Dist2(l,c)>(r/3)**2);)i.pop(),l=i[i.length-1],a++;i.push(c);const u=t.last||!t.simulatePressure||i.length>1&&b.Dist2(i[i.length-1],i[i.length-2])<r**2||a>0;if(i.length===2&&t.simulatePressure){const S=i[1];i=i.slice(0,-1);for(let v=1;v<5;v++){const C=b.Lrp(i[0],S,v/4);C.z=(i[0].z+(S.z-i[0].z))*v/4,i.push(C)}}const d=[{point:i[0],input:i[0],pressure:o?.5:i[0].z,vector:new b(1,1),distance:0,runningLength:0,radius:1}];let p=0,f=d[0],y,g;u&&n>0&&i.push(i[i.length-1].clone());for(let S=1,v=i.length;S<v;S++)y=!s||t.last&&S===v-1?i[S].clone():i[S].clone().lrp(f.point,1-s),!f.point.equals(y)&&(g=b.Dist(y,f.point),p+=g,!(S<4&&p<r)&&(f={input:i[S],point:y,pressure:o?.5:i[S].z,vector:b.Sub(f.point,y).uni(),distance:g,runningLength:p,radius:1},d.push(f)));if((w=d[1])!=null&&w.vector&&(d[0].vector=d[1].vector.clone()),p<1){const S=Math.max(.5,...d.map(v=>v.pressure));d.forEach(v=>v.pressure=S)}return d}const{min:ls}=Math,Fm=.275;function Vf(e,t){const{size:n=16,thinning:r=.5,simulatePressure:o=!0,easing:s=w=>w,start:i={},end:a={}}=t,{easing:l=nn.easeOutQuad}=i,{easing:c=nn.easeOutCubic}=a,u=e[e.length-1].runningLength;let d,p=e[0].pressure,f;if(!o&&u<n){const w=e.reduce((S,v)=>Math.max(S,v.pressure),.5);return e.forEach(S=>{S.pressure=w,S.radius=n*s(.5-r*(.5-S.pressure))}),e}else{let w;for(let S=0,v=e.length;S<v&&(f=e[S],!(f.runningLength>n*5));S++){const C=ls(1,f.distance/n);if(o){const I=ls(1,1-C);w=ls(1,p+(I-p)*(C*Fm))}else w=ls(1,p+(f.pressure-p)*.5);p=p+(w-p)*.5}for(let S=0;S<e.length;S++){if(f=e[S],r){let{pressure:v}=f;const C=ls(1,f.distance/n);if(o){const I=ls(1,1-C);v=ls(1,p+(I-p)*(C*Fm))}else v=ls(1,p+(v-p)*(C*Fm));f.radius=n*s(.5-r*(.5-v)),p=v}else f.radius=n/2;d===void 0&&(d=f.radius)}}const y=i.taper===!1?0:i.taper===!0?Math.max(n,u):i.taper,g=a.taper===!1?0:a.taper===!0?Math.max(n,u):a.taper;if(y||g)for(let w=0;w<e.length;w++){f=e[w];const{runningLength:S}=f,v=S<y?l(S/y):1,C=u-S<g?c((u-S)/g):1;f.radius=Math.max(.01,f.radius*Math.min(v,C))}return e}function lV(e,t={}){return Ex(Vf(ao(e,t),t),t)}function WP({scribble:e,zoom:t,color:n,opacity:r,className:o}){if(!e.points.length)return null;const s=lV(e.points,{size:e.size/t,start:{taper:e.taper,easing:nn.linear},last:e.state==="stopping",simulatePressure:!1,streamline:.32});let i;if(s.length<4){const a=e.size/t/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=t0(s);return h.jsx("svg",{className:o&&ue("tl-overlays__item",o),children:h.jsx("path",{className:"tl-scribble",d:i,fill:n??`var(--color-${e.color})`,opacity:r??e.opacity})})}const cV=({bounds:e,rotation:t})=>{const n=z();return K("should display",()=>n.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_shape","select.pointing_selection","text.resizing"),[n])?h.jsx(s_,{bounds:e,rotation:t}):null};function es(){const e=z();return K("isReadonlyMode",()=>e.getInstanceState().isReadonly,[e])}function uV({size:e,width:t,height:n,hideAlternateHandles:r}){const o=O(e/3),s=o/2;return h.jsxs("svg",{className:"tl-overlays__item",children:[h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
92
- ${O(0-s)},${O(e)}
93
- ${O(0-s)},${O(0-s)}
94
- ${O(e)},${O(0-s)}`,strokeWidth:o,"data-testid":"selection.crop.top_left","aria-label":"top_left handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(t/2-e),y1:O(0-s),x2:O(t/2+e),y2:O(0-s),strokeWidth:o,"data-testid":"selection.crop.top","aria-label":"top handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
95
- ${O(t-e)},${O(0-s)}
96
- ${O(t+s)},${O(0-s)}
97
- ${O(t+s)},${O(e)}`,strokeWidth:o,"data-testid":"selection.crop.top_right","aria-label":"top_right handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(t+s),y1:O(n/2-e),x2:O(t+s),y2:O(n/2+e),strokeWidth:o,"data-testid":"selection.crop.right","aria-label":"right handle"}),h.jsx("polyline",{className:"tl-corner-crop-handle",points:`
98
- ${O(t+s)},${O(n-e)}
99
- ${O(t+s)},${O(n+s)}
100
- ${O(t-e)},${O(n+s)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_right","aria-label":"bottom_right handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(t/2-e),y1:O(n+s),x2:O(t/2+e),y2:O(n+s),strokeWidth:o,"data-testid":"selection.crop.bottom","aria-label":"bottom handle"}),h.jsx("polyline",{className:ue("tl-corner-crop-handle",{"tl-hidden":r}),points:`
101
- ${O(0+e)},${O(n+s)}
102
- ${O(0-s)},${O(n+s)}
103
- ${O(0-s)},${O(n-e)}`,strokeWidth:o,"data-testid":"selection.crop.bottom_left","aria-label":"bottom_left handle"}),h.jsx("line",{className:ue("tl-corner-crop-edge-handle",{"tl-hidden":r}),x1:O(0-s),y1:O(n/2-e),x2:O(0-s),y2:O(n/2+e),strokeWidth:o,"data-testid":"selection.crop.left","aria-label":"left handle"})]})}const dV=tr(function({bounds:t,rotation:n}){const r=z(),o=x.useRef(null),s=es(),i=Wr("top"),a=Wr("right"),l=Wr("bottom"),c=Wr("left"),u=Wr("top_left"),d=Wr("top_right"),p=Wr("bottom_right"),f=Wr("bottom_left"),y=!r.getIsMenuOpen()&&r.getInstanceState().cursor.type==="default",g=r.getInstanceState().isCoarsePointer,w=r.getOnlySelectedShape(),S=w&&r.isShapeOrAncestorLocked(w),v=w?r.getShapeUtil(w).expandSelectionOutlinePx(w):0;if(hl(o,t==null?void 0:t.x,t==null?void 0:t.y,1,r.getSelectionRotation(),{x:-v,y:-v}),!t)return null;t=t.clone().expandBy(v).zeroFix();const C=r.getZoomLevel(),I=r.getInstanceState().isChangingStyle,P=t.width,E=t.height,_=8/C,k=P<_*2,$=E<_*2,T=P<_*4,j=E<_*4,L=P<_*5,N=E<_*5,F=g?1.75:1,B=6/C*F,q=(T?B/2:B)*(F*.75),Q=(j?B/2:B)*(F*.75),V=(w?!r.getShapeUtil(w).hideSelectionBoundsFg(w):!0)&&!I;let U=V&&r.isInAny("select.idle","select.brushing","select.scribble_brushing","select.pointing_canvas","select.pointing_selection","select.pointing_shape","select.crop.idle","select.crop.pointing_crop","select.pointing_resize_handle","select.pointing_crop_handle")||V&&r.isIn("select.resizing")&&w&&r.isShapeOfType(w,"text");w&&U&&r.environment.isFirefox&&r.isShapeOfType(w,"embed")&&(U=!1);const H=r.isInAny("select.pointing_crop_handle","select.crop.idle","select.crop.pointing_crop")&&!I&&!s,Z=r.isInAny("select.idle","select.pointing_selection","select.pointing_shape","select.crop.idle")&&!I&&!s,ce=!g&&!(k||$)&&(Z||H)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!S,be=g&&(!T||!j)&&(Z||H)&&(w?!r.getShapeUtil(w).hideRotateHandle(w):!0)&&!S,ke=Z&&(w?r.getShapeUtil(w).canResize(w)&&!r.getShapeUtil(w).hideResizeHandles(w):!0)&&!H&&!S,ae=k||$,Te=k&&$,Re=L||N,st=ke||H,Pe=!ce,ft=!Z||!be,He=!Z||!st,or=!Z||!st||ae,Fn=!Z||!st||ae,Nn=!Z||!st||Te&&!H;let qe=!0,jt=!0;if(H)qe=Re,jt=Re;else if(ke){qe=ae||Te||g;const _l=g&&w&&w.type==="text";jt=qe&&!_l}const yo=Math.min(24/C,E-Q*3),El=Z&&g&&w&&r.isShapeOfType(w,"text")&&yo*C>=4;return h.jsx("svg",{className:"tl-overlays__item tl-selection__fg","data-testid":"selection-foreground",children:h.jsxs("g",{ref:o,children:[U&&h.jsx("rect",{className:"tl-selection__fg__outline",width:O(P),height:O(E)}),h.jsx(Ad,{"data-testid":"selection.rotate.top-left",cx:0,cy:0,targetSize:B,corner:"top_left_rotate",cursor:y?Un("nwse-rotate",n):void 0,isHidden:Pe}),h.jsx(Ad,{"data-testid":"selection.rotate.top-right",cx:P+B*3,cy:0,targetSize:B,corner:"top_right_rotate",cursor:y?Un("nesw-rotate",n):void 0,isHidden:Pe}),h.jsx(Ad,{"data-testid":"selection.rotate.bottom-left",cx:0,cy:E+B*3,targetSize:B,corner:"bottom_left_rotate",cursor:y?Un("swne-rotate",n):void 0,isHidden:Pe}),h.jsx(Ad,{"data-testid":"selection.rotate.bottom-right",cx:P+B*3,cy:E+B*3,targetSize:B,corner:"bottom_right_rotate",cursor:y?Un("senw-rotate",n):void 0,isHidden:Pe}),h.jsx(pV,{"data-testid":"selection.rotate.mobile",cx:T?-B*1.5:P/2,cy:T?E/2:-B*1.5,size:_,isHidden:ft}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.top","aria-label":"top target",pointerEvents:"all",x:0,y:O(0-(j?Q*2:Q)),width:O(P),height:O(Math.max(1,Q*2)),style:y?{cursor:Un("ns-resize",n)}:void 0,...i}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":jt}),"data-testid":"selection.resize.right","aria-label":"right target",pointerEvents:"all",x:O(P-(T?0:q)),y:0,height:O(E),width:O(Math.max(1,q*2)),style:y?{cursor:Un("ew-resize",n)}:void 0,...a}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":qe}),"data-testid":"selection.resize.bottom","aria-label":"bottom target",pointerEvents:"all",x:0,y:O(E-(j?0:Q)),width:O(P),height:O(Math.max(1,Q*2)),style:y?{cursor:Un("ns-resize",n)}:void 0,...l}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":jt}),"data-testid":"selection.resize.left","aria-label":"left target",pointerEvents:"all",x:O(0-(T?q*2:q)),y:0,height:O(E),width:O(Math.max(1,q*2)),style:y?{cursor:Un("ew-resize",n)}:void 0,...c}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":He}),"data-testid":"selection.target.top-left","aria-label":"top-left target",pointerEvents:"all",x:O(0-(T?q*2:q*1.5)),y:O(0-(j?Q*2:Q*1.5)),width:O(q*3),height:O(Q*3),style:y?{cursor:Un("nwse-resize",n)}:void 0,...u}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":or}),"data-testid":"selection.target.top-right","aria-label":"top-right target",pointerEvents:"all",x:O(P-(T?0:q*1.5)),y:O(0-(j?Q*2:Q*1.5)),width:O(q*3),height:O(Q*3),style:y?{cursor:Un("nesw-resize",n)}:void 0,...d}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Nn}),"data-testid":"selection.target.bottom-right","aria-label":"bottom-right target",pointerEvents:"all",x:O(P-(T?q:q*1.5)),y:O(E-(j?Q:Q*1.5)),width:O(q*3),height:O(Q*3),style:y?{cursor:Un("nwse-resize",n)}:void 0,...p}),h.jsx("rect",{className:ue("tl-transparent",{"tl-hidden":Fn}),"data-testid":"selection.target.bottom-left","aria-label":"bottom-left target",pointerEvents:"all",x:O(0-(T?q*3:q*1.5)),y:O(E-(j?0:Q*1.5)),width:O(q*3),height:O(Q*3),style:y?{cursor:Un("nesw-resize",n)}:void 0,...f}),ke&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.resize.top-left",className:ue("tl-corner-handle",{"tl-hidden":He}),"aria-label":"top_left handle",x:O(0-_/2),y:O(0-_/2),width:O(_),height:O(_)}),h.jsx("rect",{"data-testid":"selection.resize.top-right",className:ue("tl-corner-handle",{"tl-hidden":or}),"aria-label":"top_right handle",x:O(P-_/2),y:O(0-_/2),width:O(_),height:O(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-right",className:ue("tl-corner-handle",{"tl-hidden":Nn}),"aria-label":"bottom_right handle",x:O(P-_/2),y:O(E-_/2),width:O(_),height:O(_)}),h.jsx("rect",{"data-testid":"selection.resize.bottom-left",className:ue("tl-corner-handle",{"tl-hidden":Fn}),"aria-label":"bottom_left handle",x:O(0-_/2),y:O(E-_/2),width:O(_),height:O(_)})]}),El&&h.jsxs(h.Fragment,{children:[h.jsx("rect",{"data-testid":"selection.text-resize.left.handle",className:"tl-text-handle","aria-label":"bottom_left handle",x:O(0-_/4),y:O(E/2-yo/2),rx:_/4,width:O(_/2),height:O(yo)}),h.jsx("rect",{"data-testid":"selection.text-resize.right.handle",className:"tl-text-handle","aria-label":"bottom_left handle",rx:_/4,x:O(P-_/4),y:O(E/2-yo/2),width:O(_/2),height:O(yo)})]}),H&&h.jsx(uV,{size:_,width:P,height:E,hideAlternateHandles:Re})]})})}),Ad=function({cx:t,cy:n,targetSize:r,corner:o,cursor:s,isHidden:i,"data-testid":a}){const l=Wr(o);return h.jsx("rect",{className:ue("tl-transparent","tl-rotate-corner",{"tl-hidden":i}),"data-testid":a,"aria-label":`${o} target`,pointerEvents:"all",x:O(t-r*3),y:O(n-r*3),width:O(Math.max(1,r*3)),height:O(Math.max(1,r*3)),cursor:s,...l})},hV=Math.sqrt(Math.PI),pV=function({cx:t,cy:n,size:r,isHidden:o,"data-testid":s}){const i=Wr("mobile_rotate"),a=z(),l=K("zoom level",()=>a.getZoomLevel(),[a]),c=Math.max(14*(1/l),20/Math.max(1,l));return h.jsxs("g",{children:[h.jsx("circle",{"data-testid":s,pointerEvents:"all",className:ue("tl-transparent","tl-mobile-rotate__bg",{"tl-hidden":o}),cx:t,cy:n,r:c,...i}),h.jsx("circle",{className:ue("tl-mobile-rotate__fg",{"tl-hidden":o}),cx:t,cy:n,r:r/hV})]})},Ut={lineHeight:1.35,fontWeight:"normal",fontVariant:"normal",fontStyle:"normal",padding:"0px"},$t={s:2,m:3.5,l:5,xl:10},rl={s:18,m:24,l:36,xl:44},Do={s:18,m:22,l:26,xl:32},ci={s:18,m:20,l:24,xl:28},oo={draw:"var(--tl-font-draw)",sans:"var(--tl-font-sans)",serif:"var(--tl-font-serif)",mono:"var(--tl-font-mono)"},fV=20,gV=4.25,kr=16;/*!
104
- * canvas-size
105
- * v1.2.6
106
- * https://github.com/jhildenbiddle/canvas-size
107
- * (c) 2015-2023 John Hildenbiddle <http://hildenbiddle.com>
108
- * MIT license
109
- */function mV(e,t){var n=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(n!=null){var r,o,s,i,a=[],l=!0,c=!1;try{if(s=(n=n.call(e)).next,t===0){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=s.call(n)).done)&&(a.push(r.value),a.length!==t);l=!0);}catch(u){c=!0,o=u}finally{try{if(!l&&n.return!=null&&(i=n.return(),Object(i)!==i))return}finally{if(c)throw o}}return a}}function GP(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(o){return Object.getOwnPropertyDescriptor(e,o).enumerable})),n.push.apply(n,r)}return n}function Hn(e){for(var t=1;t<arguments.length;t++){var n=arguments[t]!=null?arguments[t]:{};t%2?GP(Object(n),!0).forEach(function(r){yV(e,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):GP(Object(n)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(n,r))})}return e}function yV(e,t,n){return t=EV(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function SV(e,t){if(e==null)return{};var n={},r=Object.keys(e),o,s;for(s=0;s<r.length;s++)o=r[s],!(t.indexOf(o)>=0)&&(n[o]=e[o]);return n}function vV(e,t){if(e==null)return{};var n=SV(e,t),r,o;if(Object.getOwnPropertySymbols){var s=Object.getOwnPropertySymbols(e);for(o=0;o<s.length;o++)r=s[o],!(t.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function YP(e,t){return wV(e)||mV(e,t)||W2(e,t)||CV()}function jd(e){return xV(e)||bV(e)||W2(e)||PV()}function xV(e){if(Array.isArray(e))return JS(e)}function wV(e){if(Array.isArray(e))return e}function bV(e){if(typeof Symbol<"u"&&e[Symbol.iterator]!=null||e["@@iterator"]!=null)return Array.from(e)}function W2(e,t){if(e){if(typeof e=="string")return JS(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);if(n==="Object"&&e.constructor&&(n=e.constructor.name),n==="Map"||n==="Set")return Array.from(e);if(n==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return JS(e,t)}}function JS(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function PV(){throw new TypeError(`Invalid attempt to spread non-iterable instance.
110
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function CV(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
111
- In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function IV(e,t){if(typeof e!="object"||e===null)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(t==="string"?String:Number)(e)}function EV(e){var t=IV(e,"string");return typeof t=="symbol"?t:String(t)}function kc(e){var t=e.sizes.shift(),n=Math.max(Math.ceil(t[0]),1),r=Math.max(Math.ceil(t[1]),1),o=[n-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(n,r)):(a=document.createElement("canvas"),a.width=1,a.height=1,l=document.createElement("canvas"),l.width=n,l.height=r);var c=a.getContext("2d"),u=l.getContext("2d");u&&(u.fillRect.apply(u,o),c.drawImage(l,n-1,r-1,1,1,0,0,1,1));var d=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:n,height:r,benchmark:p,isTestPass:d}),!d&&e.sizes.length&&kc(e)):d?e.onSuccess(n,r,p):(e.onError(n,r,p),e.sizes.length&&kc(e)),d}var Nm={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]},_V=["onError","onSuccess"],Ta={max:null,min:1,sizes:[],step:1024,usePromise:!1,useWorker:!1,onError:Function.prototype,onSuccess:Function.prototype},Ql={};function zm(e){var t=e.width===e.height,n=e.height===1,r=e.width===1,o=[];if(!e.width||!e.height)e.sizes.forEach(function(u){var d=t||n?u:1,p=t||r?u:1;o.push([d,p])});else for(var s=e.min||Ta.min,i=e.step||Ta.step,a=Math.max(e.width,e.height);a>=s;){var l=t||n?a:1,c=t||r?a:1;o.push([l,c]),a-=i}return o}function Od(e){var t=window&&"HTMLCanvasElement"in window,n=window&&"OffscreenCanvas"in window,r=Date.now(),o=e.onError,s=e.onSuccess,i=vV(e,_V),a=null;if(!t)return!1;if(e.useWorker&&n){var l=`
112
- var canvasTest = `.concat(kc.toString(),`;
113
- onmessage = function(e) {
114
- canvasTest(e.data);
115
- };
116
- `),c=new Blob([l],{type:"application/javascript"}),u=URL.createObjectURL(c);a=new Worker(u),URL.revokeObjectURL(u),a.onmessage=function(d){var p=d.data,f=p.width,y=p.height,g=p.benchmark,w=p.isTestPass;w?(Ql[r].onSuccess(f,y,g),delete Ql[r]):Ql[r].onError(f,y,g)}}if(e.usePromise)return new Promise(function(d,p){var f=Hn(Hn({},e),{},{onError:function(S,v,C){var I;if(e.sizes.length===0)I=!0;else{var P=e.sizes.slice(-1),E=YP(P,1),_=YP(E[0],2),k=_[0],$=_[1];I=S===k&&v===$}o(S,v,C),I&&p({width:S,height:v,benchmark:C})},onSuccess:function(S,v,C){s(S,v,C),d({width:S,height:v,benchmark:C})}});if(a){var y=f.onError,g=f.onSuccess;Ql[r]={onError:y,onSuccess:g},a.postMessage(i)}else kc(f)});if(a)Ql[r]={onError:o,onSuccess:s},a.postMessage(i);else return kc(e)}var Bm={maxArea:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=zm({width:t.max,height:t.max,min:t.min,step:t.step,sizes:jd(Nm.area)}),r=Hn(Hn(Hn({},Ta),t),{},{sizes:n});return Od(r)},maxHeight:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=zm({width:1,height:t.max,min:t.min,step:t.step,sizes:jd(Nm.height)}),r=Hn(Hn(Hn({},Ta),t),{},{sizes:n});return Od(r)},maxWidth:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=zm({width:t.max,height:1,min:t.min,step:t.step,sizes:jd(Nm.width)}),r=Hn(Hn(Hn({},Ta),t),{},{sizes:n});return Od(r)},test:function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},n=Hn(Hn({},Ta),t);return n.sizes=jd(n.sizes),n.width&&n.height&&(n.sizes=[[n.width,n.height]]),Od(n)}};let Um=null;function kV(){return Um||(Um=TV()),Um}async function TV(){const e=await Bm.maxWidth({usePromise:!0}),t=await Bm.maxHeight({usePromise:!0}),n=await Bm.maxArea({usePromise:!0});return{maxWidth:e.width,maxHeight:t.height,maxArea:n.width*n.height}}const XP=8192,$V=4096*4096;async function G2(e,t){if(e<=XP&&t<=XP&&e*t<=$V)return[e,t];const{maxWidth:n,maxHeight:r,maxArea:o}=await kV(),s=e/t;if(e>n&&(e=n,t=e/s),t>r&&(t=r,e=t*s),e*t>o){const i=Math.sqrt(o/(e*t));e*=i,t*=i}return[e,t]}/*!
117
- * MIT License
118
- * Modified code originally from <https://github.com/qzb/is-animated>
119
- * Copyright (c) 2016 Józef Sokołowski <j.k.sokolowski@gmail.com>
120
- */function qP(e,t){let n=0;for(;e[t+n];)n+=e[t+n]+1;return n+1}function MV(e){return new TextDecoder("ascii").decode(e.slice(0,3))==="GIF"}function AV(e){const t=new Uint8Array(e);let n,r,o=0,s=0;if(!MV(e))return!1;for(n=t[10]&128,r=t[10]&7,o+=6,o+=7,o+=n?3*Math.pow(2,r+1):0;s<2&&o<t.length;)switch(t[o]){case 44:s+=1,n=t[o+9]&128,r=t[o+9]&7,o+=10,o+=n?3*Math.pow(2,r+1):0,o+=qP(t,o+1)+1;break;case 33:o+=2,o+=qP(t,o);break;case 59:o=t.length;break;default:o=t.length;break}return s>1}function jV(e,t){const n=e.w/t.w,r=e.h/t.h;return n<=1&&r<=1?e:n>r?{w:e.w/n,h:e.h/n}:{w:e.w/r,h:e.h/r}}async function OV(e,t,n,r={}){const o=await ko.usingObjectURL(e,ko.loadImage),{type:s=e.type,quality:i=.92}=r,[a,l]=await G2(Math.min(t*2,o.naturalWidth),Math.min(n*2,o.naturalHeight)),c=document.createElement("canvas");c.width=a,c.height=l;const u=di(c.getContext("2d",{willReadFrequently:!0}),"Could not get canvas context");return u.imageSmoothingEnabled=!0,u.imageSmoothingQuality="high",u.drawImage(o,0,0,a,l),new Promise((d,p)=>{c.toBlob(f=>{f?d(f):p(new Error("Could not resize image"))},s,i)})}async function DV(e){return AV(await e.arrayBuffer())}function RV(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function LV(e){const t=new URL(e).host.replace("www.","");for(const n of Ya)if(Y2(n.hostnames,t)){const r=n.fromEmbedUrl(e);if(r)return{definition:n,url:r,embedUrl:e}}}const FV=e=>e.split("*").map(t=>RV(t)).join(".+"),Y2=(e,t)=>!!e.find(n=>{const r=new RegExp(FV(n));return t.match(r)});function NV(e){const t=new URL(e).host.replace("www.","");for(const n of Ya)if(Y2(n.hostnames,t)){const r=n.toEmbedUrl(e);if(r)return{definition:n,embedUrl:r,url:e}}}function X2(e){return NV(e)??LV(e)}function xs(e){try{return X2(e)}catch(t){console.error(t)}}/*!
121
- * MIT License
122
- * Adapted (mostly copied) the work of https://github.com/fregante/text-field-edit
123
- * Copyright (c) Federico Brigante <opensource@bfred.it> (bfred.it)
124
- */const $a=" ",cn=class cn{static insertTextFirefox(t,n){t.setRangeText(n,t.selectionStart||0,t.selectionEnd||0,"end"),t.dispatchEvent(new InputEvent("input",{data:n,inputType:"insertText",isComposing:!1}))}static insert(t,n){const r=t.ownerDocument,o=r.activeElement;o!==t&&t.focus(),r.execCommand("insertText",!1,n)||cn.insertTextFirefox(t,n),o===r.body?t.blur():o instanceof HTMLElement&&o!==t&&o.focus()}static set(t,n){t.select(),cn.insert(t,n)}static getSelection(t){const{selectionStart:n,selectionEnd:r}=t;return t.value.slice(n||void 0,r||void 0)}static wrapSelection(t,n,r){const{selectionStart:o,selectionEnd:s}=t,i=cn.getSelection(t);cn.insert(t,n+i+(r??n)),t.selectionStart=(o||0)+n.length,t.selectionEnd=(s||0)+n.length}static replace(t,n,r){let o=0;t.value.replace(n,(...s)=>{const i=o+s[s.length-2],a=s[0].length;t.selectionStart=i,t.selectionEnd=i+a;const l=typeof r=="string"?r:r(...s);return cn.insert(t,l),t.selectionStart=i,o+=l.length-a,l})}static findLineEnd(t,n){const r=t.lastIndexOf(`
125
- `,n-1)+1;return t.charAt(r)!==" "?n:r+1}static indent(t){var a;const{selectionStart:n,selectionEnd:r,value:o}=t,s=o.slice(n,r),i=(a=/\n/g.exec(s))==null?void 0:a.length;if(i&&i>0){const l=o.lastIndexOf(`
126
- `,n-1)+1,c=t.value.slice(l,r-1),u=c.replace(/^|\n/g,`$&${$a}`),d=u.length-c.length;t.setSelectionRange(l,r-1),cn.insert(t,u),t.setSelectionRange(n+1,r+d)}else cn.insert(t,$a)}static unindent(t){const{selectionStart:n,selectionEnd:r,value:o}=t,s=o.lastIndexOf(`
127
- `,n-1)+1,i=cn.findLineEnd(o,r),a=t.value.slice(s,i),l=a.replace(/(^|\n)(\t| {1,2})/g,"$1"),c=a.length-l.length;t.setSelectionRange(s,i),cn.insert(t,l);const u=/\t| {1,2}/.exec(o.slice(s,n)),d=u?u[0].length:0,p=n-d;t.setSelectionRange(n-d,Math.max(p,r-c))}static indentCE(t){var l;const n=window.getSelection(),r=t.innerText,o=Dd(t)??0,s=Dd(t)??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(`
128
- `,o-1)+1,u=r.slice(c,s-1),p=u.replace(/^|\n/g,`$&${$a}`).length-u.length;n&&n.setBaseAndExtent(t,o+1,t,s+p)}else{const c=window.getSelection();t.innerText=r.slice(0,o)+$a+r.slice(o),c==null||c.setBaseAndExtent(t,o+1,t,o+2)}}static unindentCE(t){const n=window.getSelection(),r=t.innerText,o=Dd(t)??0,s=Dd(t)??0,i=r.lastIndexOf(`
129
- `,o-1)+1,a=cn.findLineEnd(r,s),l=r.slice(i,a),c=l.replace(/(^|\n)(\t| {1,2})/g,"$1"),u=l.length-c.length;if(n){n.setBaseAndExtent(t,i,t,a);const d=/\t| {1,2}/.exec(r.slice(i,o)),p=d?d[0].length:0,f=o-p;n.setBaseAndExtent(t,o-p,t,Math.max(f,s-u))}}static normalizeText(t){return t.replace(cn.fixNewLines,`
130
- `)}static normalizeTextForDom(t){return t.replace(cn.fixNewLines,`
131
- `).split(`
132
- `).map(n=>n||" ").join(`
133
- `)}};m(cn,"fixNewLines",/\r?\n|\r/g);let Ua=cn;function Dd(e){if(typeof window.getSelection>"u")return;const t=window.getSelection();if(!t)return;let n=0;if(t.rangeCount!==0){const r=t.getRangeAt(0),o=r.cloneRange();o.selectNodeContents(e),o.setEnd(r.endContainer,r.endOffset),n=o.toString().length}return n}const zV=/[\u0590-\u05FF\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/;function q2(e){return zV.test(e)}function BV(e){return e.replace(/\t/g,$a)}function UV(e){const t=e.split(`
134
- `);for(;t[0]&&t[0].trim().length===0;)t.shift();let n=1/0;for(const r of t)if(r.trim().length>0){const o=r.length-r.trimStart().length;n=Math.min(n,o)}return t.map(r=>r.slice(n)).join(`
135
- `)}function HV(e){return e.replace(/[ \t]+$/gm,"").replace(/\n+$/,"")}function KV(e){return HV(UV(BV(e)))}const Tc=(e,t)=>e.length<=t?e:e.substring(0,t-3)+"...";function VV(e,{maxImageDimension:t,maxAssetSize:n,acceptedImageMimeTypes:r,acceptedVideoMimeTypes:o},{toasts:s,msg:i}){e.registerExternalAssetHandler("file",async({file:a})=>{const l=a.name;let c=a;const u=r.includes(c.type),d=o.includes(c.type);Ao(u||d,`File type not allowed: ${c.type}`),Ao(c.size<=n,`File size too big: ${(c.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`),c.type==="video/quicktime"&&(c=new Blob([c],{type:"video/mp4"}));let p=u?await ko.getImageSize(c):await ko.getVideoSize(c);const f=c.type==="image/gif"?await DV(c):d,y=await CD(await c.arrayBuffer());if(isFinite(t)){const S=jV(p,{w:t,h:t});p!==S&&(c.type==="image/jpeg"||c.type==="image/png")&&(p=S)}(c.type==="image/jpeg"||c.type==="image/png")&&(c=await OV(c,p.w,p.h,{type:c.type,quality:.92}));const g=hi.createId(y);return hi.create({id:g,type:u?"image":"video",typeName:"asset",props:{name:l,src:await Aa.blobToDataUrl(c),w:p.w,h:p.h,mimeType:c.type,isAnimated:f}})}),e.registerExternalAssetHandler("url",async({url:a})=>{var c,u,d;let l;try{const f=await(await fetch(a,{method:"GET",mode:"no-cors"})).text(),y=new DOMParser().parseFromString(f,"text/html");l={image:((c=y.head.querySelector('meta[property="og:image"]'))==null?void 0:c.getAttribute("content"))??"",title:((u=y.head.querySelector('meta[property="og:title"]'))==null?void 0:u.getAttribute("content"))??Tc(a,32),description:((d=y.head.querySelector('meta[property="og:description"]'))==null?void 0:d.getAttribute("content"))??""}}catch(p){console.error(p),s.addToast({title:i("assets.url.failed"),severity:"error"}),l={image:"",title:Tc(a,32),description:""}}return{id:hi.createId(_y(a)),typeName:"asset",type:"bookmark",props:{src:a,description:l.description,image:l.image,title:l.title},meta:{}}}),e.registerExternalContentHandler("svg-text",async({point:a,text:l})=>{const c=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),u=new DOMParser().parseFromString(l,"image/svg+xml").querySelector("svg");if(!u)throw new Error("No <svg/> element present");let d=parseFloat(u.getAttribute("width")||"0"),p=parseFloat(u.getAttribute("height")||"0");if(!(d&&p)){document.body.appendChild(u);const y=u.getBoundingClientRect();document.body.removeChild(u),d=y.width,p=y.height}const f=await e.getAssetForExternalContent({type:"file",file:new File([l],"asset.svg",{type:"image/svg+xml"})});if(!f)throw Error("Could not create an asset");ZP(e,[f],c)}),e.registerExternalContentHandler("embed",({point:a,url:l,embed:c})=>{const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),{width:d,height:p}=c,f=Be(),y={id:f,type:"embed",x:u.x-(d||450)/2,y:u.y-(p||450)/2,props:{w:d,h:p,url:l}};e.createShapes([y]).select(f)}),e.registerExternalContentHandler("files",async({point:a,files:l})=>{const c=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),u=new b(c.x,c.y),d=[];await Promise.all(l.map(async(p,f)=>{if(p.size>n)return console.warn(`File size too big: ${(p.size/1024).toFixed()}kb > ${(n/1024).toFixed()}kb`),null;if(!p.type)throw new Error("No mime type");if(!r.concat(o).includes(p.type))return console.warn(`${p.name} not loaded - Extension not allowed.`),null;try{const y=await e.getAssetForExternalContent({type:"file",file:p});if(!y)throw Error("Could not create an asset");d[f]=y}catch(y){return s.addToast({title:i("assets.files.upload-failed"),severity:"error"}),console.error(y),null}})),ZP(e,fe(d),u)}),e.registerExternalContentHandler("text",async({point:a,text:l})=>{const c=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),u=e.getShapeUtil("text").getDefaultProps(),d=KV(l),p=e.getOnlySelectedShape();if(p&&"text"in p.props){e.updateShapes([{id:p.id,type:p.type,props:{text:d}}]);return}let f,y,g,w="middle";const S=d.split(`
136
- `).length>1,v=q2(d);S&&(w=S?v?"end":"start":"middle");const C=e.textMeasure.measureText(d,{...Ut,fontFamily:oo[u.font],fontSize:rl[u.size],maxWidth:null}),I=Math.min(S?e.getViewportPageBounds().width*.9:920,Math.max(200,e.getViewportPageBounds().width*.9));if(C.w>I){const P=e.textMeasure.measureText(d,{...Ut,fontFamily:oo[u.font],fontSize:rl[u.size],maxWidth:I});f=P.w,y=P.h,g=!1,w=v?"end":"start"}else f=C.w,y=C.h,g=!0;c.y-y/2<e.getViewportPageBounds().minY+40&&(c.y=e.getViewportPageBounds().minY+40+y/2),e.createShapes([{id:Be(),type:"text",x:c.x-f/2,y:c.y-y/2,props:{text:d,align:w,autoSize:g,w:f}}])}),e.registerExternalContentHandler("url",async({point:a,url:l})=>{const c=xs(l);if(c)return e.putExternalContent({type:"embed",url:c.url,point:a,embed:c.definition});const u=a??(e.inputs.shiftKey?e.inputs.currentPagePoint:e.getViewportPageCenter()),d=hi.createId(_y(l)),p=WV(e,l,u);let f=e.getAsset(d),y=!1;if(!f){y=!0;try{const g=await e.getAssetForExternalContent({type:"url",url:l});if(!g)throw Error("Could not create an asset");f=g}catch{s.addToast({title:i("assets.url.failed"),severity:"error"});return}}e.batch(()=>{y&&e.createAssets([f]),e.updateShapes([{id:p.id,type:p.type,props:{assetId:f.id}}])})})}async function ZP(e,t,n){if(!t.length)return[];const r=b.From(n),o=[];for(const s of t)switch(s.type){case"bookmark":{o.push({id:Be(),type:"bookmark",x:r.x-150,y:r.y-160,opacity:1,props:{assetId:s.id,url:s.props.src}}),r.x+=300;break}case"image":{o.push({id:Be(),type:"image",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w;break}case"video":o.push({id:Be(),type:"video",x:r.x-s.props.w/2,y:r.y-s.props.h/2,opacity:1,props:{assetId:s.id,w:s.props.w,h:s.props.h}}),r.x+=s.props.w}return e.batch(()=>{const s=t.filter(i=>!e.getAsset(i.id));s.length&&e.createAssets(s),e.createShapes(o).select(...o.map(i=>i.id)),Z2(e,n)}),o.map(s=>s.id)}function Z2(e,t){const n=e.getViewportPageBounds();let r=e.getSelectionPageBounds();if(r){const o=r.center.sub(t);e.updateShapes(e.getSelectedShapes().map(s=>{const i=e.getShapeParentTransform(s).decompose().rotation,a=b.Rot(o,-i);return{id:s.id,type:s.type,x:s.x-a.x,y:s.y-a.y}}))}r=e.getSelectionPageBounds(),r&&!n.contains(r)&&e.zoomToSelection()}function WV(e,t,n){const r={id:Be(),type:"bookmark",x:n.x-150,y:n.y-160,opacity:1,props:{assetId:null,url:t}};return e.batch(()=>{e.createShapes([r]).select(r.id),Z2(e,n)}),e.getShape(r.id)}var ly;let GV=(ly=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")});m(this,"onKeyUp",n=>{var r;if(n.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",{...n,target:"shape",shape:o}))}})}},m(ly,"id","idle"),ly);var cy;let YV=(cy=class extends re{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onEnter",()=>{this.didTimeout=!1;const n=this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{filter:r=>!r.isLocked&&this.editor.getShapeUtil(r).canBind(r),margin:0,hitInside:!0,renderingOnly:!0});n?this.editor.setHintingShapes([n.id]):this.createArrowShape(),this.startPreciseTimeout()});m(this,"onExit",()=>{this.shape=void 0,this.editor.setHintingShapes([]),this.clearPreciseTimeout()});m(this,"onPointerMove",()=>{if(this.editor.inputs.isDragging){if(this.shape||this.createArrowShape(),!this.shape)throw Error("expected shape");this.updateArrowShapeEndHandle(),this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,handle:this.editor.getShapeHandles(this.shape).find(n=>n.id==="end"),isCreating:!0,onInteractionEnd:"arrow"})}});m(this,"onPointerUp",()=>{this.cancel()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()});m(this,"preciseTimeout",-1);m(this,"didTimeout",!1)}cancel(){this.shape&&this.editor.bailToMark(this.markId),this.editor.setHintingShapes([]),this.parent.transition("idle")}createArrowShape(){var u,d;const{originPagePoint:n}=this.editor.inputs,r=Be();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"arrow",x:n.x,y:n.y}]);const o=this.editor.getShape(r);if(!o)throw Error("expected shape");const s=this.editor.getShapeHandles(o);if(!s)throw Error("expected handles for arrow");const i=this.editor.getShapeUtil("arrow"),a=this.shape,l=s.find(p=>p.id==="start"),c=(u=i.onHandleDrag)==null?void 0:u.call(i,o,{handle:{...l,x:0,y:0},isPrecise:!0,initial:a});if(c){const p=(d=c.props)==null?void 0:d.start;(p==null?void 0:p.type)==="binding"&&this.editor.setHintingShapes([p.boundShapeId]),this.editor.updateShapes([c],{squashing:!0})}this.shape=this.editor.getShape(r),this.editor.select(r)}updateArrowShapeEndHandle(){var s,i,a;const n=this.shape;if(!n)throw Error("expected shape");const r=this.editor.getShapeHandles(n);if(!r)throw Error("expected handles for arrow");const o={...n,props:{...n.props,end:{...n.props.end,x:0,y:0}}};{const l=this.editor.getShapeUtil("arrow"),c=this.shape,u=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint),d=r.find(f=>f.id==="end"),p=(s=l.onHandleDrag)==null?void 0:s.call(l,o,{handle:{...d,x:u.x,y:u.y},isPrecise:!1,initial:c});if(p){const f=(i=p.props)==null?void 0:i.end;(f==null?void 0:f.type)==="binding"&&this.editor.setHintingShapes([f.boundShapeId]),this.editor.updateShapes([p],{squashing:!0})}}{const l=this.editor.getShapeUtil("arrow"),c=this.shape,u=r.find(p=>p.id==="start"),d=(a=l.onHandleDrag)==null?void 0:a.call(l,o,{handle:{...u,x:0,y:0},isPrecise:this.didTimeout,initial:c});d&&this.editor.updateShapes([d],{squashing:!0})}this.shape=this.editor.getShape(n.id)}startPreciseTimeout(){this.preciseTimeout=window.setTimeout(()=>{this.getIsActive()&&(this.didTimeout=!0)},320)}clearPreciseTimeout(){clearTimeout(this.preciseTimeout)}},m(cy,"id","pointing"),cy);class bh extends re{constructor(){super(...arguments);m(this,"shapeType","arrow")}}m(bh,"id","arrow"),m(bh,"initial","idle"),m(bh,"children",()=>[GV,YV]);class _x extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"initialShape");m(this,"shapeType",this.parent.id==="highlight"?"highlight":"draw");m(this,"util",this.editor.getShapeUtil(this.shapeType));m(this,"isPen",!1);m(this,"segmentMode","free");m(this,"didJustShiftClickToExtendPreviousShapeLine",!1);m(this,"pagePointWhereCurrentSegmentChanged",{});m(this,"pagePointWhereNextSegmentChanged",null);m(this,"lastRecordedPoint",{});m(this,"mergeNextPoint",!1);m(this,"currentLineLength",0);m(this,"canDraw",!1);m(this,"markId",null);m(this,"onEnter",n=>{this.markId=null,this.info=n,this.canDraw=!this.editor.getIsMenuOpen(),this.lastRecordedPoint=this.editor.inputs.currentPagePoint.clone(),this.canDraw&&this.startShape()});m(this,"onPointerMove",()=>{const{inputs:n}=this.editor;if(this.isPen!==n.isPen){if(this.markId){this.editor.bailToMark(this.markId),this.startShape();return}}else!this.canDraw&&n.isDragging&&(this.startShape(),this.canDraw=!0);this.canDraw&&(n.isPen?b.Dist(n.currentPagePoint,this.lastRecordedPoint)>=1/this.editor.getZoomLevel()?(this.lastRecordedPoint=n.currentPagePoint.clone(),this.mergeNextPoint=!1):this.mergeNextPoint=!0:this.mergeNextPoint=!1,this.updateShapes())});m(this,"onKeyDown",n=>{if(n.key==="Shift")switch(this.segmentMode){case"free":{this.segmentMode="starting_straight",this.pagePointWhereNextSegmentChanged=this.editor.inputs.currentPagePoint.clone();break}case"starting_free":this.segmentMode="starting_straight"}this.updateShapes()});m(this,"onKeyUp",n=>{if(n.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.updateShapes()});m(this,"onExit",()=>{this.editor.snaps.clearIndicators(),this.pagePointWhereCurrentSegmentChanged=this.editor.inputs.currentPagePoint.clone()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.editor.inputs.isDragging||(this.markId&&this.editor.bailToMark(this.markId),this.cancel())})}canClose(){return this.shapeType!=="highlight"}getIsClosed(n,r){if(!this.canClose())return!1;const o=$t[r],s=n[0].points[0],i=n[n.length-1],a=i.points[i.points.length-1];return s!==a&&this.currentLineLength>o*4&&b.DistMin(s,a,o*2)}startShape(){const{inputs:{originPagePoint:n,isPen:r}}=this.editor;this.markId="draw start "+nt(),this.editor.mark(this.markId),this.isPen=r;const o=this.isPen?this.info.point.z*1.25:.5;if(this.segmentMode=this.editor.inputs.shiftKey?"straight":"free",this.didJustShiftClickToExtendPreviousShapeLine=!1,this.lastRecordedPoint=n.clone(),this.initialShape){const i=this.editor.getShape(this.initialShape.id);if(i&&this.segmentMode==="straight"){this.didJustShiftClickToExtendPreviousShapeLine=!0;const a=Vn(i.props.segments);if(!a)throw Error("Expected a previous segment!");const l=Vn(a.points);if(!l)throw Error("Expected a previous point!");const{x:c,y:u}=this.editor.getPointInShapeSpace(i,n).toFixed(),d=this.isPen?this.info.point.z*1.25:.5,p={type:this.segmentMode,points:[{x:l.x,y:l.y,z:+d.toFixed(2)},{x:c,y:u,z:+d.toFixed(2)}]},f=ne.applyToPoint(this.editor.getShapePageTransform(i.id),l);this.pagePointWhereCurrentSegmentChanged=f,this.pagePointWhereNextSegmentChanged=null;const y=[...i.props.segments,p];this.currentLineLength<$t[i.props.size]*4&&(this.currentLineLength=this.getLineLength(y));const g={id:i.id,type:this.shapeType,props:{segments:y}};this.canClose()&&(g.props.isClosed=this.getIsClosed(y,i.props.size)),this.editor.updateShapes([g]);return}}this.pagePointWhereCurrentSegmentChanged=n.clone();const s=Be();this.editor.createShapes([{id:s,type:this.shapeType,x:n.x,y:n.y,props:{isPen:this.isPen,segments:[{type:this.segmentMode,points:[{x:0,y:0,z:+o.toFixed(2)}]}]}}]),this.currentLineLength=0,this.initialShape=this.editor.getShape(s)}updateShapes(){const{initialShape:n}=this,{inputs:r}=this.editor;if(!n)return;const{id:o,props:{size:s}}=n,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(),d={x:l,y:c,z:this.isPen?+(u*1.25).toFixed(2):.5};switch(this.segmentMode){case"starting_straight":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(b.Dist2(p,r.currentPagePoint)>Fc){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="straight";const y=Vn(a);if(!y)throw Error("Expected a previous segment!");const g=Vn(y.points);if(!g)throw Error("Expected a previous last point!");let w;const S=this.editor.getPointInShapeSpace(i,this.pagePointWhereCurrentSegmentChanged).toFixed().toJson();if(y.type==="straight"){this.currentLineLength+=b.Dist(g,S),w={type:"straight",points:[{...g},S]};const C=this.editor.getShapePageTransform(i);this.pagePointWhereCurrentSegmentChanged=ne.applyToPoint(C,g)}else w={type:"straight",points:[S,d]};const v={id:o,type:this.shapeType,props:{segments:[...a,w]}};this.canClose()&&(v.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([v],{squashing:!0})}break}case"starting_free":{const{pagePointWhereNextSegmentChanged:p}=this;if(p===null)throw Error("We should have a point where the segment changed");if(b.Dist2(p,r.currentPagePoint)>Fc){this.pagePointWhereCurrentSegmentChanged=this.pagePointWhereNextSegmentChanged.clone(),this.pagePointWhereNextSegmentChanged=null,this.segmentMode="free";const y=a.slice(),g=y[y.length-1],w=Vn(g.points);if(!w)throw Error("No previous point!");const S={type:"free",points:[...b.PointsBetween(w,d,6).map(I=>I.toFixed().toJson())]},v=[...y,S];this.currentLineLength<$t[i.props.size]*4&&(this.currentLineLength=this.getLineLength(v));const C={id:o,type:this.shapeType,props:{segments:v}};this.canClose()&&(C.props.isClosed=this.getIsClosed(v,s)),this.editor.updateShapes([C],{squashing:!0})}break}case"straight":{const p=a.slice(),f=p[p.length-1],{pagePointWhereCurrentSegmentChanged:y}=this,{ctrlKey:g,currentPagePoint:w}=this.editor.inputs;if(!y)throw Error("We should have a point where the segment changed");let S,v=!1;this.didJustShiftClickToExtendPreviousShapeLine?this.editor.inputs.isDragging&&(v=!g,this.didJustShiftClickToExtendPreviousShapeLine=!1):v=!g;let C=this.editor.getPointInShapeSpace(i,w).toFixed().toJson(),I=!1,P;if((this.editor.user.getIsSnapMode()?!g:g)&&p.length>2){let k,$=8/this.editor.getZoomLevel();for(let T=0,j=a.length-2;T<j;T++){const L=a[T];if(!L)break;if(L.type==="free")continue;const N=L.points[0],F=Vn(L.points);if(!(N&&F))continue;const B=b.NearestPointOnLineSegment(N,F,C);if(b.DistMin(B,C,$)){k=B.toFixed().toJson(),$=b.Dist(B,C),P=L;break}}k&&(I=!0,C=k)}if(I&&P){const k=this.editor.getShapePageTransform(i),$=P.points[0],T=Vn(P.points);if(!T)throw Error("Expected a last point!");const j=ne.applyToPoint(k,$),L=ne.applyToPoint(k,T),N=ne.applyToPoint(k,C);this.editor.snaps.setIndicators([{id:nt(),type:"points",points:[j,N,L]}])}else{if(this.editor.snaps.clearIndicators(),v){const k=b.Angle(y,w),T=pp(k,24)-k;S=b.RotWith(w,y,T)}else S=w;C=this.editor.getPointInShapeSpace(i,S).toFixed().toJson()}this.currentLineLength+=b.Dist(f.points[0],C),p[p.length-1]={...f,type:"straight",points:[f.points[0],C]};const _={id:o,type:this.shapeType,props:{segments:p}};this.canClose()&&(_.props.isClosed=this.getIsClosed(a,s)),this.editor.updateShapes([_],{squashing:!0});break}case"free":{const p=a.slice(),f=p[p.length-1],y=[...f.points];if(y.length&&this.mergeNextPoint){const{z:w}=y[y.length-1];y[y.length-1]={x:d.x,y:d.y,z:w?Math.max(w,d.z):d.z}}else this.currentLineLength+=b.Dist(y[y.length-1],d),y.push(d);p[p.length-1]={...f,points:y},this.currentLineLength<$t[i.props.size]*4&&(this.currentLineLength=this.getLineLength(p));const g={id:o,type:this.shapeType,props:{segments:p}};if(this.canClose()&&(g.props.isClosed=this.getIsClosed(p,s)),this.editor.updateShapes([g],{squashing:!0}),y.length>500){this.editor.updateShapes([{id:o,type:this.shapeType,props:{isComplete:!0}}]);const w=Be();this.editor.createShapes([{id:w,type:this.shapeType,x:fp(r.currentPagePoint.x),y:fp(r.currentPagePoint.y),props:{isPen:this.isPen,segments:[{type:"free",points:[{x:0,y:0,z:this.isPen?+(u*1.25).toFixed():.5}]}]}}]),this.initialShape=vt(this.editor.getShape(w)),this.mergeNextPoint=!1,this.lastRecordedPoint=r.currentPagePoint.clone(),this.currentLineLength=0}break}}}getLineLength(n){let r=0;for(const o of n)for(let s=0;s<o.points.length-1;s++){const i=o.points[s],a=o.points[s+1];r+=b.Dist2(a,i)}return Math.sqrt(r)}complete(){if(!this.canDraw){this.cancel();return}const{initialShape:n}=this;n&&(this.editor.updateShapes([{id:n.id,type:n.type,props:{isComplete:!0}}]),this.parent.transition("idle"))}cancel(){this.parent.transition("idle",this.info)}}m(_x,"id","drawing");var uy;let Q2=(uy=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("drawing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(uy,"id","idle"),uy);class Ph extends re{constructor(){super(...arguments);m(this,"shapeType","draw");m(this,"onExit",()=>{const n=this.children.drawing;n.initialShape=void 0})}}m(Ph,"id","draw"),m(Ph,"initial","idle"),m(Ph,"children",()=>[Q2,_x]);class ev extends Sh{constructor(){super(...arguments);m(this,"shapeType","frame");m(this,"onCreate",n=>{if(!n)return;const r=this.editor.getShapePageBounds(n),o=[],s=this.editor.getShapeAncestors(n).map(i=>i.id);this.editor.getSortedChildIdsForParent(n.parentId).map(i=>{const a=this.editor.getShape(i);if(!a||a.id===n.id||a.isLocked)return;const l=this.editor.getShapePageBounds(a);l&&r.contains(l)&&XV(a,s,n)&&o.push(a.id)}),this.editor.reparentShapes(o,n.id),this.editor.getInstanceState().isToolLocked?this.editor.setCurrentTool("frame"):this.editor.setCurrentTool("select.idle")})}}m(ev,"id","frame"),m(ev,"initial","idle");function XV(e,t,n){return t.includes(e.id)?!1:e.parentId===n.parentId}var dy;let qV=(dy=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onKeyUp",n=>{var r;if(n.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",{...n,target:"shape",shape:o}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(dy,"id","idle"),dy);var hy;let ZV=(hy=class extends re{constructor(){super(...arguments);m(this,"markId","");m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{originPagePoint:r}=this.editor.inputs,o=Be();this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"geo",x:r.x,y:r.y,props:{w:1,h:1,geo:this.editor.getStyleForNextShape(eo)}}]).select(o).setCurrentTool("select.resizing",{...n,target:"selection",handle:"bottom_right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"geo"})}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){const{originPagePoint:n}=this.editor.inputs,r=Be();this.markId=`creating:${r}`,this.editor.mark(this.markId),this.editor.createShapes([{id:r,type:"geo",x:n.x,y:n.y,props:{geo:this.editor.getStyleForNextShape(eo),w:1,h:1}}]);const o=this.editor.getShape(r);if(!o)return;const s=o.props.geo==="star"?new te(0,0,200,190):o.props.geo==="cloud"?new te(0,0,300,180):new te(0,0,200,200),i=s.center,a=this.editor.getShapeParentTransform(o);a&&i.rot(-a.rotation()),this.editor.select(r),this.editor.updateShapes([{id:o.id,type:"geo",x:o.x-i.x,y:o.y-i.y,props:{geo:this.editor.getStyleForNextShape(eo),w:s.width,h:s.height}}]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select",{})}cancel(){this.parent.transition("idle")}},m(hy,"id","pointing"),hy);class Ch extends re{constructor(){super(...arguments);m(this,"shapeType","geo")}}m(Ch,"id","geo"),m(Ch,"initial","idle"),m(Ch,"children",()=>[qV,ZV]);class Ih extends re{constructor(){super(...arguments);m(this,"shapeType","highlight");m(this,"onExit",()=>{const n=this.children.drawing;n.initialShape=void 0})}}m(Ih,"id","highlight"),m(Ih,"initial","idle"),m(Ih,"children",()=>[Q2,_x]);var py;let QV=(py=class extends re{constructor(){super(...arguments);m(this,"shapeId","");m(this,"onEnter",n=>{this.shapeId=n.shapeId,this.editor.setCursor({type:"cross",rotation:0})});m(this,"onPointerDown",()=>{this.parent.transition("pointing",{shapeId:this.shapeId})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(py,"id","idle"),py);const QP=2;var fy;let JV=(fy=class extends re{constructor(){super(...arguments);m(this,"shape",{});m(this,"markId");m(this,"onEnter",n=>{const{inputs:r}=this.editor,{currentPagePoint:o}=r;this.markId=void 0;const s=n.shapeId&&this.editor.getShape(n.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(Lt),l=a[a.length-1],c=a[a.length-2],u=ne.applyToPoint(this.editor.getShapeParentTransform(this.shape),new b(this.shape.x,this.shape.y)),d=b.Sub(o,u).addXY(.1,.1),p=vt(this.shape.props.points);if(b.DistMin(l,c,QP)||b.DistMin(d,l,QP))p[l.id]={id:l.id,index:l.index,x:d.x,y:d.y};else{const f=Eo(l.index);p[f]={id:f,index:f,x:d.x,y:d.y}}this.editor.updateShapes([{id:this.shape.id,type:this.shape.type,props:{points:p}}])}else{const i=Be();this.markId=`creating:${i}`,this.editor.mark(this.markId),this.editor.createShapes([{id:i,type:"line",x:o.x,y:o.y}]),this.editor.select(i),this.shape=this.editor.getShape(i)}});m(this,"onPointerMove",()=>{if(this.shape&&this.editor.inputs.isDragging){const n=this.editor.getShapeHandles(this.shape);if(!n)throw this.markId&&this.editor.bailToMark(this.markId),Error("No handles found");const r=Vn(n);this.editor.setCurrentTool("select.dragging_handle",{shape:this.shape,isCreating:!0,handle:{...r,x:r.x-.1,y:r.y-.1},onInteractionEnd:"line"})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.parent.transition("idle"),this.markId&&this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators()})}complete(){this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}cancel(){this.markId&&this.editor.bailToMark(this.markId),this.parent.transition("idle",{shapeId:this.shape.id}),this.editor.snaps.clearIndicators()}},m(fy,"id","pointing"),fy);class Eh extends re{constructor(){super(...arguments);m(this,"shapeType","line")}}m(Eh,"id","line"),m(Eh,"initial","idle"),m(Eh,"children",()=>[QV,JV]);var gy;let eW=(gy=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(gy,"id","idle"),gy);function Ve(e,t){var o;const n=new Set;for(const s of t){const i=e.getShape(s);if(!i)continue;e.getShapeUtil(i).onDragShapesOut&&n.add(i);const a=e.getShape(i.parentId);a&&e.getShapeUtil(a).onDragShapesOut&&n.add(a)}const r=new Map;for(const s of n){const i=J2(e,s);i.length&&r.set(s,i)}for(const[s,i]of r){const a=e.getShapeUtil(s),l=fe(i.map(c=>e.getShape(c)));(o=a.onDragShapesOut)==null||o.call(a,s,l)}}function J2(e,t){const n=e.getSortedChildIdsForParent(t.id);if(n.length===0)return[];const r=e.getShapePageBounds(t);if(!r)return[];let o,s,i;const a=[];for(const l of n){const c=e.getShapePageBounds(l);if(!c)continue;if(!r.includes(c)){a.push(l);continue}o??(o=e.getShapeGeometry(t)),s??(s=e.getShapePageTransform(t)),i??(i=s.applyToPoints(o.vertices));const u=e.getShapePageTransform(l).clone().invert().applyToPoints(i),{vertices:d,isClosed:p}=e.getShapeGeometry(l);if(!d.some(f=>Xn(f,u))){if(p){if(bT(u,d))continue}else if(h4(u,d))continue;a.push(l)}}return a}function Qp(e,t,n=!1){e.select(t),e.setEditingShape(t),e.setCurrentTool("select.editing_shape",{target:"shape",shape:t}),n&&e.emit("select-all-text",{shapeId:t.id}),e$(e)}const tW=16;function e$(e){const t=e.getSelectionPageBounds(),n=e.getViewportPageBounds();if(t&&!n.contains(t)){const r=t.clone().expandBy(tW/e.getZoomLevel()).expand(n),o=n.clone().translate({x:(r.center.x-n.center.x)*2,y:(r.center.y-n.center.y)*2});e.zoomToBounds(o,{duration:Yr,inset:0})}}const mi=20,nW=0,$e=200,kx={x:$e/2,y:$e/2},t$=10,rW=[new b($e*.5,$e*-.5-mi),new b($e*1.5+mi,$e*.5),new b($e*.5,$e*1.5+mi),new b($e*-.5-mi,$e*.5)];function n$(e,t,n,r){return rW.map((o,s)=>{const i=o.clone();return s===0&&r?i.y-=r:s===2&&n&&(i.y+=n),i.rot(t).add(e)})}function r$(e,t,n){const r=new Set(e.getSelectedShapeIds()),o=($e+mi+n)**2,s=new Map,i=[];for(const c of e.getCurrentPageShapes()){if(!e.isShapeOfType(c,"note")||r.has(c.id))continue;const u=e.getShapePageTransform(c.id);t===u.rotation()&&(s.set(c,e.getShapePageBounds(c).center),i.push(...n$(u.point(),t,c.props.growY,n)))}const a=i.length;let l;for(const[c,u]of s)for(let d=0;d<a;d++)l=i[d],l&&(b.Dist2(u,l)>o||e.isPointInShape(c,l)&&(i[d]=void 0));return fe(i)}function o$(e,t,n,r,o=!1){let s;const i=e.getCurrentPageShapesSorted(),a=$e+mi**2;for(let l=i.length-1;l>=0;l--){const c=i[l];if(c.type==="note"&&c.id!==t.id){const u=e.getShapePageBounds(c);if(u&&b.Dist2(u.center,n)<a&&e.isPointInShape(c,n)){s=c;break}}}if(e.complete(),!s||o){e.mark("creating note shape");const l=Be();e.createShape({id:l,type:"note",x:n.x,y:n.y,rotation:r,opacity:t.opacity,props:{...t.props,text:"",growY:0,fontSizeAdjustment:0,url:""}});const c=e.getShape(l),u=e.getPointInParentSpace(c,b.Sub(n,b.Rot(kx,r)));e.updateShape({id:l,type:"note",x:u.x,y:u.y}),s=e.getShape(l)}return e$(e),s}var my;let oW=(my=class extends re{constructor(){super(...arguments);m(this,"dragged",!1);m(this,"info",{});m(this,"wasFocusedOnEnter",!1);m(this,"markId","");m(this,"shape",{});m(this,"onEnter",()=>{const{editor:n}=this;if(this.wasFocusedOnEnter=!n.getIsMenuOpen(),this.wasFocusedOnEnter){const r=Be();this.markId=`creating:${r}`,n.mark(this.markId);const o=this.editor.inputs.originPagePoint.clone(),s=JP(this.editor,o);s&&o.sub(s),this.shape=eC(this.editor,r,o)}});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){if(!this.wasFocusedOnEnter){const r=Be(),o=this.editor.inputs.originPagePoint.clone(),s=JP(this.editor,o);s&&o.sub(s),this.shape=eC(this.editor,r,o)}this.editor.setCurrentTool("select.translating",{...n,target:"shape",shape:this.shape,onInteractionEnd:"note",isCreating:!0,onCreate:()=>{this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape")}})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()})}complete(){this.wasFocusedOnEnter&&(this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):(this.editor.setEditingShape(this.shape.id),this.editor.setCurrentTool("select.editing_shape",{...this.info,target:"shape",shape:this.shape})))}cancel(){this.editor.bailToMark(this.markId),this.parent.transition("idle",this.info)}},m(my,"id","pointing"),my);function JP(e,t){let n=t$/e.getZoomLevel(),r;for(const o of r$(e,0,0)){const s=b.Sub(t,o),i=s.len();i<n&&(n=i,r=s)}return r}function eC(e,t,n){e.createShape({id:t,type:"note",x:n.x,y:n.y}).select(t);const r=e.getShape(t),o=e.getShapeGeometry(r).bounds;return e.updateShapes([{id:t,type:"note",x:r.x-o.width/2,y:r.y-o.height/2}]),e.getShape(t)}class _h extends re{constructor(){super(...arguments);m(this,"shapeType","note")}}m(_h,"id","note"),m(_h,"initial","idle"),m(_h,"children",()=>[eW,oW]);function sW(e){const t=e.getShapeAtPoint(e.inputs.currentPagePoint,{hitInside:!1,hitLabels:!1,margin:Fo/e.getZoomLevel(),renderingOnly:!0});if(!t)return e.setHoveredShape(null);let n;const r=e.getOutermostSelectableShape(t);return r===t||r.id===e.getFocusedGroupId()||e.getSelectedShapeIds().includes(r.id)?n=t:n=r,e.setHoveredShape(n.id)}const Ha=PD(sW,32);var yy;let iW=(yy=class extends re{constructor(){super(...arguments);m(this,"onPointerMove",n=>{switch(n.target){case"shape":case"canvas":Ha(this.editor)}});m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})});m(this,"onKeyDown",n=>{var r;if(n.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",{...n,target:"shape",shape:o}))}});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(yy,"id","idle"),yy);var Sy;let aW=(Sy=class extends re{constructor(){super(...arguments);m(this,"shape");m(this,"markId","");m(this,"onExit",()=>{this.editor.setHintingShapes([])});m(this,"onPointerMove",n=>{if(this.editor.inputs.isDragging){const{inputs:{originPagePoint:r}}=this.editor,o=Be();if(this.markId=`creating:${o}`,this.editor.mark(this.markId),this.editor.createShapes([{id:o,type:"text",x:r.x,y:r.y,props:{text:"",autoSize:!1,w:20}}]),this.editor.select(o),this.shape=this.editor.getShape(o),!this.shape)return;const{shape:s}=this;this.editor.setCurrentTool("select.resizing",{...n,target:"selection",handle:"right",isCreating:!0,creationCursorOffset:{x:1,y:1},onInteractionEnd:"text",onCreate:()=>{this.editor.setEditingShape(s.id),this.editor.setCurrentTool("select.editing_shape")}})}});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.cancel()});m(this,"onCancel",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}complete(){var s;this.editor.mark("creating text shape");const n=Be(),{x:r,y:o}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:o,props:{text:"",autoSize:!0}}]).select(n),this.editor.setEditingShape(n),this.editor.setCurrentTool("select"),(s=this.editor.root.getCurrent())==null||s.transition("editing_shape")}cancel(){this.parent.transition("idle"),this.editor.bailToMark(this.markId)}},m(Sy,"id","pointing"),Sy);class kh extends re{constructor(){super(...arguments);m(this,"shapeType","text")}}m(kh,"id","text"),m(kh,"initial","idle"),m(kh,"children",()=>[iW,aW]);const lW=[kh,Ph,Ch,_h,Eh,ev,bh,Ih];function wt(){return qo({isDarkMode:Mu()})}const Pt=Se.memo(function({theme:t,d:n,color:r,fill:o}){switch(o){case"none":return null;case"solid":return h.jsx("path",{fill:t[r].semi,d:n});case"semi":return h.jsx("path",{fill:t.solid,d:n});case"pattern":return h.jsx(cW,{theme:t,color:r,fill:o,d:n})}}),cW=function({d:t,color:n,theme:r}){const o=z(),s=_T(),i=K("zoomLevel",()=>o.getZoomLevel(),[o]),a=Math.ceil(i),l=o.getZoomLevel()<=.18;return h.jsxs(h.Fragment,{children:[h.jsx("path",{fill:r[n].pattern,d:t}),h.jsx("path",{fill:s?`url(#${Xa[`1_${r.id}`]})`:l?r[n].semi:`url(#${Xa[`${a}_${r.id}`]})`,d:t})]})};function uW(e){return e.replace(/\s/g," ")}function tv(e,t,n){const{padding:r=0}=n;if(t.length===0)return null;const o=te.From(t[0].box);for(const{box:c}of t)o.union(c);const s=r+(n.offsetX??0),i=(n.offsetY??0)+n.fontSize/2+(n.verticalTextAlign==="start"?r:n.verticalTextAlign==="end"?n.height-r-o.height:(Math.ceil(n.height)-o.height)/2);let a=null;const l=[];for(const{text:c,box:u}of t)a!==null&&u.y>a&&l.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:s,y:u.y+i,children:`
137
- `},l.length)),l.push(h.jsx("tspan",{alignmentBaseline:"mathematical",x:u.x+s,y:u.y+i,children:uW(c)},l.length)),a=u.y;return h.jsx("text",{fontSize:n.fontSize,fontFamily:n.fontFamily,fontStyle:n.fontFamily,fontWeight:n.fontWeight,dominantBaseline:"mathematical",alignmentBaseline:"mathematical",stroke:n.stroke,strokeWidth:n.strokeWidth,fill:n.fill,children:l})}function dW(e,t,n,r){if((e==="start-legacy"||e==="end-legacy")&&n.length!==0){const o=te.From(n[0].box);for(const{box:s}of n)o.union(s);if(e==="start-legacy")return(r-2*t-o.width)/2;if(e==="end-legacy")return-(r-2*t-o.width)/2}}function hW(e){return e==="start-legacy"||e==="middle-legacy"||e==="end-legacy"}function Wf({fontSize:e,font:t,align:n,verticalAlign:r,text:o,labelColor:s,bounds:i,padding:a=16,stroke:l=!0}){const c=z(),u=wt(),d={fontSize:e,fontFamily:tE[t],textAlign:n,verticalTextAlign:r,width:Math.ceil(i.width),height:Math.ceil(i.height),padding:a,lineHeight:Ut.lineHeight,fontStyle:"normal",fontWeight:"normal",overflow:"wrap",offsetX:0,offsetY:0,fill:s,stroke:void 0,strokeWidth:void 0},p=c.textMeasure.measureTextSpans(o,d),f=dW(n,a,p,i.width);f&&(d.offsetX=f),d.offsetX+=i.x,d.offsetY+=i.y;const y=tv(c,p,d);let g=null;return l&&(d.fill=u.background,d.stroke=u.background,d.strokeWidth=2,g=tv(c,p,d)),h.jsxs(h.Fragment,{children:[g,y]})}function ol(e){return{key:`${so.id}:${e}`,getElement:async()=>{const t=pW(e);if(!t)return null;const n=t.$$_url,r=t.$$_fontface;if(!n||!r)return null;const o=await(await fetch(n)).blob(),s=await Aa.blobToDataUrl(o),i=r.replace(n,s);return h.jsx("style",{children:i})}}}function pW(e){const t=tE[e];for(const n of document.fonts)if(t.includes(n.family))return n;return null}function Tx(e){return{key:`${so.id}:${e}`,getElement:async()=>e!=="pattern"?null:h.jsx(fW,{})}}function fW(){const e=wt(),t=8/12;return h.jsxs(h.Fragment,{children:[h.jsxs("mask",{id:"hash_pattern_mask",children:[h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:"white"}),h.jsxs("g",{strokeLinecap:"round",stroke:"black",children:[h.jsx("line",{x1:t*1,y1:t*3,x2:t*3,y2:t*1}),h.jsx("line",{x1:t*5,y1:t*7,x2:t*7,y2:t*5}),h.jsx("line",{x1:t*9,y1:t*11,x2:t*11,y2:t*9})]})]}),h.jsx("pattern",{id:Xa[`1_${e.id}`],width:"8",height:"8",patternUnits:"userSpaceOnUse",children:h.jsx("rect",{x:"0",y:"0",width:"8",height:"8",fill:e.solid,mask:"url(#hash_pattern_mask)"})})]})}function $x(){return{key:`${so.id}:pattern`,component:yW}}const dc=8,tC=(e,t,n)=>new Promise((r,o)=>{const s=dc*t*e,i=document.createElement("canvas");i.width=s,i.height=s;const a=i.getContext("2d");if(!a)return;a.fillStyle=n?"#212529":"#f8f9fa",a.fillRect(0,0,s,s),a.globalCompositeOperation="destination-out",a.lineCap="round",a.lineWidth=1.25*t*e;const l=8/12,c=u=>u*t*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||Tt.throwToBlob.get()?o():r(u)})}),nC=(e,t)=>{const n=document.createElement("canvas");n.width=e[0],n.height=e[1];const r=n.getContext("2d");return r?(t(r),n.toDataURL()):""},gW=()=>{const e=[];for(let t=1;t<=Math.ceil(ps);t++){const n=nC([1,1],o=>{o.fillStyle=ap.lightMode.black.semi,o.fillRect(0,0,1,1)}),r=nC([1,1],o=>{o.fillStyle=ap.darkMode.black.semi,o.fillRect(0,0,1,1)});e.push({zoom:t,url:n,darkMode:!1}),e.push({zoom:t,url:r,darkMode:!0})}return e};function mW(){const t=z().getInstanceState().devicePixelRatio,[n,r]=x.useState(!1),o=x.useMemo(()=>gW(),[]),[s,i]=x.useState(o);return x.useEffect(()=>{const l=[];for(let u=1;u<=Math.ceil(ps);u++)l.push(tC(t,u,!1).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!1}))),l.push(tC(t,u,!0).then(d=>({zoom:u,url:URL.createObjectURL(d),darkMode:!0})));let c=!1;return Promise.all(l).then(u=>{c||(i(u),r(!0))}),()=>{c=!0,r(!1)}},[t]),{defs:h.jsx(h.Fragment,{children:s.map(l=>{const c=l.zoom+(l.darkMode?"_dark":"_light");return h.jsx("pattern",{id:Xa[c],width:dc,height:dc,patternUnits:"userSpaceOnUse",children:h.jsx("image",{href:l.url,width:dc,height:dc})},c)})}),isReady:n}}function yW(){const e=z(),t=x.useRef(null),{defs:n,isReady:r}=mW();return x.useEffect(()=>{if(r&&e.environment.isSafari){const o=s$(t.current);o&&requestAnimationFrame(()=>{o.style.display="none",requestAnimationFrame(()=>{o.style.display=""})})}},[e,r]),h.jsx("g",{ref:t,"data-testid":r?"ready-pattern-fill-defs":void 0,children:n})}function s$(e){return e.classList.contains("tl-html-layer")?e:e.parentElement?s$(e.parentElement):null}function Ko(e,t,n={}){const{closed:r=!1,snap:o=1,start:s="outset",end:i="outset",lengthRatio:a=2,style:l="dashed"}=n;let c=0,u=0,d=1,p=0,f=0;switch(l){case"dashed":{d=1,c=Math.min(t*a,e/4);break}case"dotted":{d=100,c=t/d;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*d)),u-=u%o,u<3&&l==="dashed"?e/t<5?(c=e,u=1,p=0):(c=e*.333,p=e*.333):(u=Math.max(u,3),c=e/u/(2*d),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 rC=new WeakMap;function Mx(e,t){const n=rC.get(t);if(n)return n;const r=e.getArrowInfo(t);let o=0,s=0;const i=r.isStraight?new ou({start:b.From(r.start.point),end:b.From(r.end.point)}):new UT({center:b.Cast(r.handleArc.center),radius:r.handleArc.radius,start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});if(t.props.text.trim()){const l=i.bounds,{w:c,h:u}=e.textMeasure.measureText(t.props.text,{...Ut,fontFamily:oo[t.props.font],fontSize:ci[t.props.size],maxWidth:null});if(o=c,s=u,l.width>l.height){o=Math.max(Math.min(c,64),Math.min(l.width-64,c));const{w:d,h:p}=e.textMeasure.measureText(t.props.text,{...Ut,fontFamily:oo[t.props.font],fontSize:ci[t.props.size],maxWidth:o});o=d,s=p}if(o>16*ci[t.props.size]){o=16*ci[t.props.size];const{w:d,h:p}=e.textMeasure.measureText(t.props.text,{...Ut,fontFamily:oo[t.props.font],fontSize:ci[t.props.size],maxWidth:o});o=d,s=p}}const a=new b(o,s).addScalar(gV*2);return rC.set(t,a),a}function i$(e,t){const n=$t[t.props.size];return fV+(n-$t.s)*2+(n===$t.xl?20:0)}function SW(e,t,n){const r=Mx(e,t),o=i$(e,t),s=b.Nudge(n.start.point,n.end.point,o),i=b.Nudge(n.end.point,n.start.point,o),a=X0(s,i,te.FromCenter(n.middle,r).corners);if(!a||a.length!==2)return{start:.5,end:.5};let[l,c]=a;b.Dist2(l,s)>b.Dist2(c,s)&&([c,l]=a);const u=s.add(b.Sub(n.middle,l)),d=i.add(b.Sub(n.middle,c)),p=b.Dist(n.start.point,u)/n.length,f=b.Dist(n.start.point,d)/n.length;return{start:p,end:f}}function vW(e,t,n){const r=Mx(e,t),o=i$(e,t),s=Math.sign(t.props.bend),i=o/n.handleArc.radius*s,a=b.Angle(n.bodyArc.center,n.start.point)-i,l=b.Angle(n.bodyArc.center,n.end.point)+i,c=bi(n.bodyArc.center,n.bodyArc.radius,a),u=bi(n.bodyArc.center,n.bodyArc.radius,l),d=[],p=oC(n.bodyArc.center,n.bodyArc.radius,a,l,s,te.FromCenter(c,r).corners);d.push(new bt({points:te.FromCenter(c,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));const f=oC(n.bodyArc.center,n.bodyArc.radius,a,l,s,te.FromCenter(u,r).corners);d.push(new bt({points:te.FromCenter(u,r).corners,debugColor:"lime",isFilled:!1,ignore:!0}));for(const _ of[...p??[],...f??[],c,u])d.push(new ox({x:_.x-3,y:_.y-3,radius:3,isFilled:!1,debugColor:"magenta",ignore:!0}));const y=(p&&sC(n.start.point,p))??n.middle,g=(f&&sC(n.end.point,f))??n.middle,w=b.Angle(n.bodyArc.center,n.start.point),S=b.Angle(n.bodyArc.center,n.end.point),v=b.Angle(n.bodyArc.center,y),C=b.Angle(n.bodyArc.center,g);if(hs(w,v,s)>hs(w,C,s))return{start:.5,end:.5,dbg:d};const I=hs(w,S,s),P=hs(w,v,s)/I,E=hs(w,C,s)/I;return{start:P,end:E,dbg:d}}function Th(e,t){let n;const r=[],o=e.getArrowInfo(t),s=o.start.arrowhead!=="none",i=o.end.arrowhead!=="none";if(o.isStraight){const l=SW(e,t,o);let c=Zr(t.props.labelPosition,s?l.start:0,i?l.end:1);c=c>=.48&&c<=.52?.5:c,n=b.Lrp(o.start.point,o.end.point,c)}else{const l=vW(e,t,o);l.dbg&&r.push(...l.dbg);let c=Zr(t.props.labelPosition,s?l.start:0,i?l.end:1);c=c>=.48&&c<=.52?.5:c;const u=xW(b.Angle(o.bodyArc.center,o.start.point),b.Angle(o.bodyArc.center,o.end.point),Math.sign(t.props.bend),c);n=bi(o.bodyArc.center,o.bodyArc.radius,u)}const a=Mx(e,t);return{box:te.FromCenter(n,a),debugGeom:r}}function oC(e,t,n,r,o,s){const i=OS(e,t,s),a=hs(n,r,o);return i==null?void 0:i.filter(l=>{const c=hs(n,b.Angle(e,l),o);return c>=0&&c<=a})}function sC(e,t){let n=null,r=-1/0;for(const o of t){const s=b.Dist2(e,o);s>r&&(n=o,r=s)}return n}function xW(e,t,n,r){const o=hs(e,t,n);return e+o*r*n*-1}function wW(e,t,n){const r=t==="end"?e.end.point:e.start.point,o=t==="end"?e.start.point:e.end.point,s=e.isStraight?b.Dist(o,r):Math.abs(e.bodyArc.length),i=Math.max(Math.min(s/5,n*3),n);let a;if(e.isStraight)a=b.Nudge(r,o,i);else{const l=u4(r,i,e.handleArc.center,e.handleArc.radius);a=t==="end"?e.handleArc.sweepFlag?l[0]:l[1]:e.handleArc.sweepFlag?l[1]:l[0]}return b.IsNaN(a)&&(a=e.start.point),{point:r,int:a}}function bW({point:e,int:t}){const n=b.RotWith(t,e,je/6),r=b.RotWith(t,e,-je/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${r.x} ${r.y}`}function PW({point:e,int:t}){const n=b.RotWith(t,e,je/6),r=b.RotWith(t,e,-je/6);return`M ${n.x} ${n.y} L ${e.x} ${e.y} L ${r.x} ${r.y} Z`}function CW({point:e,int:t}){const n=b.Sub(t,e).div(2),r=b.Add(e,b.Rot(n,Ge)),o=b.Sub(e,b.Rot(n,Ge));return`M ${r.x} ${r.y} L ${t.x} ${t.y} L ${o.x} ${o.y} Z`}function IW({point:e,int:t}){const n=b.Lrp(e,t,.45),r=b.Dist(n,e);return`M ${n.x-r},${n.y}
138
- a ${r},${r} 0 1,0 ${r*2},0
139
- a ${r},${r} 0 1,0 -${r*2},0 `}function EW({point:e,int:t}){const n=b.Lrp(e,t,.75),r=b.RotWith(n,e,je/4),o=b.RotWith(n,e,-je/4),s=b.Lrp(r,o,.5);return s.add(b.Sub(s,e)),`M ${s.x} ${s.y} L ${r.x} ${r.y} ${e.x} ${e.y} L ${o.x} ${o.y} Z`}function _W({int:e,point:t}){const n=b.Lrp(t,e,.85),r=b.Sub(n,t).div(2),o=b.Add(t,b.Rot(r,Ge)),s=b.Sub(t,b.Rot(r,Ge)),i=b.Add(n,b.Rot(r,Ge)),a=b.Sub(n,b.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 kW({int:e,point:t}){const n=b.Sub(e,t).div(2),r=b.Add(t,b.Rot(n,Ge)),o=b.Sub(t,b.Rot(n,Ge));return`M ${r.x} ${r.y} L ${o.x} ${o.y}`}function Jp(e,t,n){const r=t==="end"?e.end.arrowhead:e.start.arrowhead;if(r==="none")return;const o=wW(e,t,n);if(o){switch(r){case"bar":return kW(o);case"square":return _W(o);case"diamond":return EW(o);case"dot":return IW(o);case"inverted":return CW(o);case"arrow":return bW(o);case"triangle":return PW(o)}return""}}function TW(e){const{start:t,end:n,handleArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${t.handle.x},${t.handle.y} A${r} ${r} 0 ${o} ${s} ${n.handle.x},${n.handle.y}`}function a$(e){const{start:t,end:n,bodyArc:{radius:r,largeArcFlag:o,sweepFlag:s}}=e;return`M${t.point.x},${t.point.y} A${r} ${r} 0 ${o} ${s} ${n.point.x},${n.point.y}`}function l$(e,t){return`M${e.x},${e.y}L${t.x},${t.y}`}function $W(e){return l$(e.start.handle,e.end.handle)}function c$(e){return l$(e.start.point,e.end.point)}const MW=x.forwardRef(function({isEditing:t,text:n,handleFocus:r,handleChange:o,handleKeyDown:s,handleBlur:i,handleInputPointerDown:a,handleDoubleClick:l},c){return h.jsx("textarea",{ref:c,className:"tl-text tl-text-input",name:"text",tabIndex:-1,readOnly:!t,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",datatype:"wysiwyg",defaultValue:n,onFocus:r,onChange:o,onKeyDown:s,onBlur:i,onTouchEnd:rn,onContextMenu:t?rn:void 0,onPointerDown:a,onDoubleClick:l,onDragStart:Ae})});function AW(e,t,n,r={disableTab:!1}){const o=z(),s=x.useRef(null),i=K("isEditing",()=>o.getEditingShapeId()===e,[o]),a=K("isEditingAnything",()=>o.getEditingShapeId()!==null,[o]);x.useEffect(()=>{function y({shapeId:g}){if(g===e){const w=s.current;w&&(document.activeElement!==w&&w.focus(),w.select())}}return o.on("select-all-text",y),()=>{o.off("select-all-text",y)}},[o,e]);const l=x.useRef();x.useEffect(()=>{if(!i)return;const y=s.current;if(!y)return;document.activeElement!==y&&(y.focus(),o.getInstanceState().isCoarsePointer&&y.select());function g(){var S,v;const w=(S=window.getSelection)==null?void 0:S.call(window);if(w&&w.type!=="None"){const C=[];for(let I=0;I<w.rangeCount;I++)C.push((v=w.getRangeAt)==null?void 0:v.call(w,I));l.current=C}}return document.addEventListener("selectionchange",g),()=>{document.removeEventListener("selectionchange",g)}},[o,i]);const c=x.useCallback(()=>{const y=l.current;requestAnimationFrame(()=>{var S;const g=s.current,w=o.getEditingShapeId();if(w){if(g&&w===e&&(g.focus(),y&&y.length)){const v=window.getSelection();v&&y.forEach(C=>v.addRange(C))}}else(S=window.getSelection())==null||S.removeAllRanges()})},[o,e]),u=x.useCallback(y=>{if(o.getEditingShapeId()===e)switch(y.key){case"Enter":{(y.ctrlKey||y.metaKey)&&o.complete();break}case"Tab":{r.disableTab||(Ae(y),y.shiftKey?Ua.unindent(y.currentTarget):Ua.indent(y.currentTarget));break}}},[o,e,r.disableTab]),d=x.useCallback(y=>{if(o.getEditingShapeId()!==e)return;let g=Ua.normalizeText(y.currentTarget.value);const w=g.replace(/\t/g,$a);if(w!==g){const S=y.currentTarget.selectionStart;y.currentTarget.value=w,y.currentTarget.selectionStart=S+(w.length-g.length),y.currentTarget.selectionEnd=S+(w.length-g.length),g=w}o.updateShape({id:e,type:t,props:{text:g}})},[o,e,t]),p=x.useCallback(y=>{o.dispatch({...En(y),type:"pointer",name:"pointer_down",target:"shape",shape:o.getShape(e)}),rn(y),o.getEditingShapeId()!==e&&pl(y.currentTarget,y)},[o,e]);return{rInput:s,handleFocus:jW,handleBlur:c,handleKeyDown:u,handleChange:d,handleInputPointerDown:p,handleDoubleClick:rn,isEmpty:n.trim().length===0,isEditing:i,isEditingAnything:a}}function jW(){}const Gf=Se.memo(function({id:t,type:n,text:r,labelColor:o,font:s,fontSize:i,lineHeight:a,align:l,verticalAlign:c,wrap:u,isSelected:d,onKeyDown:p,classNamePrefix:f,style:y,disableTab:g=!1,textWidth:w,textHeight:S}){const{rInput:v,isEmpty:C,isEditing:I,isEditingAnything:P,...E}=AW(t,n,r,{disableTab:g}),[_,k]=x.useState(r);x.useEffect(()=>{I||k(r)},[I,r]);const $=Ua.normalizeTextForDom(r),T=$.length>0,j=hW(l);if(!I&&!T)return null;const L=f||"tl-text";return h.jsx("div",{className:`${L}-label tl-text-wrapper`,"data-font":s,"data-align":l,"data-hastext":!C,"data-isediting":I,"data-iseditinganything":P,"data-textwrap":!!u,"data-isselected":d,style:{justifyContent:l==="middle"||j?"center":l,alignItems:c==="middle"?"center":c,...y},children:h.jsxs("div",{className:`${L}-label__inner tl-text-content__wrapper`,style:{fontSize:i,lineHeight:i*a+"px",minHeight:a+32,minWidth:w||0,color:o,width:w,height:S},children:[h.jsx("div",{className:`${L} tl-text tl-text-content`,dir:"ltr",children:$}),(P||d)&&h.jsx(MW,{ref:v,text:r,isEditing:I,...E,handleKeyDown:p??E.handleKeyDown},_)]})})}),OW=x.memo(function({id:t,text:n,size:r,font:o,position:s,width:i,isSelected:a,labelColor:l}){const c=wt();return h.jsx(Gf,{id:t,classNamePrefix:"tl-arrow",type:"arrow",font:o,fontSize:ci[r],lineHeight:Ut.lineHeight,align:"middle",verticalAlign:"middle",text:n,labelColor:c[l].solid,textWidth:i,isSelected:a,disableTab:!0,style:{transform:`translate(${s.x}px, ${s.y}px)`}})});let DW=0;class $h extends Rr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"canBind",()=>!1);m(this,"canSnap",()=>!1);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"onHandleDrag",(n,{handle:r,isPrecise:o})=>{const s=r.id;if(s==="middle"){const{start:w,end:S}=Ar(this.editor,n),v=b.Sub(S,w),C=b.Per(v),I=b.Med(S,w),P=b.Sub(I,C),E=b.Add(I,C),_=b.NearestPointOnLineSegment(P,E,r,!1);let k=b.Dist(_,I);return b.Clockwise(_,S,I)&&(k*=-1),{id:n.id,type:n.type,props:{bend:k}}}const i=vt(n);if(this.editor.inputs.ctrlKey)return i.props[s]={type:"point",x:r.x,y:r.y},i;const a=this.editor.getShapePageTransform(n.id).applyToPoint(r),l=this.editor.getShapeAtPoint(a,{hitInside:!0,hitFrameInside:!0,margin:0,filter:w=>!w.isLocked&&this.editor.getShapeUtil(w).canBind(w)});if(!l)return i.props[s]={type:"point",x:r.x,y:r.y},i;const c=this.editor.getShapeGeometry(l),u=te.ZeroFix(c.bounds),p=this.editor.getShapePageTransform(i.id).applyToPoint(r),f=this.editor.getPointInShapeSpace(l,p);let y=o;if(!y){const w=i.props[s];(w.type==="point"||w.type==="binding"&&l.id!==w.boundShapeId)&&(y=this.editor.inputs.pointerVelocity.len()<.5)}if(!o){c.isClosed||(y=!0);const w=i.props[s==="start"?"end":"start"];w.type==="binding"&&l.id===w.boundShapeId&&w.isPrecise&&(y=!0)}const g={x:(f.x-u.minX)/u.width,y:(f.y-u.minY)/u.height};return y&&b.Dist(f,u.center)<Math.max(4,Math.min(Math.min(u.width,u.height)*.15,16))/this.editor.getZoomLevel()&&(g.x=.5,g.y=.5),i.props[s]={type:"binding",boundShapeId:l.id,normalizedAnchor:g,isPrecise:y,isExact:this.editor.inputs.altKey},i.props.start.type==="binding"&&i.props.end.type==="binding"&&i.props.start.boundShapeId===i.props.end.boundShapeId&&b.Equals(i.props.start.normalizedAnchor,i.props.end.normalizedAnchor)&&(i.props.end.normalizedAnchor.x+=.05),i});m(this,"onTranslateStart",n=>{const r=n.props.start.type==="binding"?n.props.start.boundShapeId:null,o=n.props.end.type==="binding"?n.props.end.boundShapeId:null,s=Ar(this.editor,n),i=this.editor.getShapePageTransform(n.id),a=this.editor.getSelectedShapeIds(),l=new Set;r&&(l.add(r),this.editor.getShapeAncestors(r).forEach(u=>l.add(u.id))),o&&(l.add(o),this.editor.getShapeAncestors(o).forEach(u=>l.add(u.id)));for(const u of a)if(l.has(u))return;let c=n;aC.set(n,{pagePosition:i.applyToPoint(n),terminalBindings:np(s,(u,d)=>{const p=n.props[u];return p.type!=="binding"?null:{binding:p,shapePosition:d,pagePosition:i.applyToPoint(d)}})});for(const u of["start","end"]){const d=n.props[u];d.type==="binding"&&(c={...n,props:{...n.props,[u]:{...d,isPrecise:!0}}})}return c});m(this,"onTranslate",(n,r)=>{const o=aC.get(n);if(!o)return;const s=this.editor.getShapePageTransform(r.id),i=b.Sub(s.applyToPoint(r),o.pagePosition);let a=r;for(const[l,c]of Jr(o.terminalBindings)){if(!c)continue;const u=b.Add(c.pagePosition,b.Mul(i,.5)),d=this.editor.getShapeAtPoint(u,{hitInside:!0,hitFrameInside:!0,margin:0,filter:p=>!p.isLocked&&this.editor.getShapeUtil(p).canBind(p)});if((d==null?void 0:d.id)===c.binding.boundShapeId){const p=te.ZeroFix(this.editor.getShapeGeometry(d).bounds),f=this.editor.getPointInShapeSpace(d,u),y={x:(f.x-p.minX)/p.width,y:(f.y-p.minY)/p.height};a={...a,props:{...a.props,[l]:{...c.binding,isPrecise:!0,normalizedAnchor:y}}}}else a={...a,props:{...a.props,[l]:{type:"point",x:c.shapePosition.x,y:c.shapePosition.y}}}}return a});m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r,i=Ar(this.editor,n),{start:a,end:l}=vt(n.props);let{bend:c}=n.props;a.type==="point"&&(a.x=i.start.x*o,a.y=i.start.y*s),l.type==="point"&&(l.x=i.end.x*o,l.y=i.end.y*s);const u=Math.abs(o),d=Math.abs(s);return o<0&&s>=0?(c!==0&&(c*=-1,c*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.x=1-a.normalizedAnchor.x),l.type==="binding"&&(l.normalizedAnchor.x=1-l.normalizedAnchor.x)):o>=0&&s<0?(c!==0&&(c*=-1,c*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.y=1-a.normalizedAnchor.y),l.type==="binding"&&(l.normalizedAnchor.y=1-l.normalizedAnchor.y)):o>=0&&s>=0?c!==0&&(c*=Math.max(u,d)):o<0&&s<0&&(c!==0&&(c*=Math.max(u,d)),a.type==="binding"&&(a.normalizedAnchor.x=1-a.normalizedAnchor.x,a.normalizedAnchor.y=1-a.normalizedAnchor.y),l.type==="binding"&&(l.normalizedAnchor.x=1-l.normalizedAnchor.x,l.normalizedAnchor.y=1-l.normalizedAnchor.y)),{props:{start:a,end:l,bend:c}}});m(this,"onDoubleClickHandle",(n,r)=>{switch(r.id){case"start":return{id:n.id,type:n.type,props:{...n.props,arrowheadStart:n.props.arrowheadStart==="none"?"arrow":"none"}};case"end":return{id:n.id,type:n.type,props:{...n.props,arrowheadEnd:n.props.arrowheadEnd==="none"?"arrow":"none"}}}});m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])})}getDefaultProps(){return{dash:"draw",size:"m",fill:"none",color:"black",labelColor:"black",bend:0,start:{type:"point",x:0,y:0},end:{type:"point",x:2,y:0},arrowheadStart:"none",arrowheadEnd:"arrow",text:"",labelPosition:.5,font:"draw"}}getGeometry(n){const r=this.editor.getArrowInfo(n),o=[],s=r.isStraight?new ou({start:b.From(r.start.point),end:b.From(r.end.point)}):new UT({center:b.Cast(r.handleArc.center),radius:r.handleArc.radius,start:b.Cast(r.start.point),end:b.Cast(r.end.point),sweepFlag:r.bodyArc.sweepFlag,largeArcFlag:r.bodyArc.largeArcFlag});let i;if(n.props.text.trim()){const a=Th(this.editor,n);o.push(...a.debugGeom),i=new Ho({x:a.box.x,y:a.box.y,width:a.box.w,height:a.box.h,isFilled:!0,isLabel:!0})}return new Fr({children:[...i?[s,i]:[s],...o]})}getHandles(n){const r=this.editor.getArrowInfo(n);return[{id:"start",type:"vertex",index:"a0",x:r.start.handle.x,y:r.start.handle.y,canBind:!0},{id:"middle",type:"virtual",index:"a2",x:r.middle.x,y:r.middle.y,canBind:!1},{id:"end",type:"vertex",index:"a3",x:r.end.handle.x,y:r.end.handle.y,canBind:!0}].filter(Boolean)}component(n){const r=this.editor.getOnlySelectedShape(),o=this.editor.isInAny("select.idle","select.pointing_handle","select.dragging_handle","select.translating","arrow.dragging")&&!this.editor.getInstanceState().isReadonly,s=this.editor.getArrowInfo(n);if(!(s!=null&&s.isValid))return null;const i=Th(this.editor,n),a=n.id===this.editor.getOnlySelectedShapeId(),c=this.editor.getEditingShapeId()===n.id||n.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(Ds,{id:n.id,style:{minWidth:50,minHeight:50},children:h.jsx(iC,{shape:n,shouldDisplayHandles:o&&r===n})}),c&&h.jsx(OW,{id:n.id,text:n.props.text,font:n.props.font,size:n.props.size,position:i.box.center,width:i.box.w,isSelected:a,labelColor:n.props.labelColor})]})}indicator(n){const{start:r,end:o}=Ar(this.editor,n),s=this.editor.getArrowInfo(n),i=this.editor.getShapeGeometry(n),a=i.bounds,l=n.props.text.trim()?i.children[1]:null,c=Ff(n.id);if(!s||b.Equals(r,o))return null;const u=$t[n.props.size],d=s.start.arrowhead&&Jp(s,"start",u),p=s.end.arrowhead&&Jp(s,"end",u),f=s.isStraight?c$(s):a$(s),y=d&&s.start.arrowhead!=="arrow"||p&&s.end.arrowhead!=="arrow"||!!l,g=(n.id+"_clip").replace(":","_");return c&&l?h.jsx("rect",{x:O(l.x),y:O(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5}):h.jsxs("g",{children:[y&&h.jsx("defs",{children:h.jsxs("mask",{id:g,children:[h.jsx("rect",{x:a.minX-100,y:a.minY-100,width:a.w+200,height:a.h+200,fill:"white"}),l&&h.jsx("rect",{x:O(l.x),y:O(l.y),width:l.w,height:l.h,fill:"black",rx:3.5,ry:3.5}),d&&h.jsx("path",{d,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),p&&h.jsx("path",{d:p,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{...y?{mask:`url(#${g})`}:void 0,children:[y&&h.jsx("rect",{x:a.minX-100,y:a.minY-100,width:a.width+200,height:a.height+200,opacity:0}),h.jsx("path",{d:f})]}),d&&h.jsx("path",{d}),p&&h.jsx("path",{d:p}),l&&h.jsx("rect",{x:O(l.x),y:O(l.y),width:l.w,height:l.h,rx:3.5,ry:3.5})]})}toSvg(n,r){r.addExportDef(Tx(n.props.fill)),n.props.text&&r.addExportDef(ol(n.props.font));const o=qo(r);return h.jsxs(h.Fragment,{children:[h.jsx(iC,{shape:n,shouldDisplayHandles:!1}),h.jsx(Wf,{fontSize:ci[n.props.size],font:n.props.font,align:"middle",verticalAlign:"middle",text:n.props.text,labelColor:o[n.props.labelColor].solid,bounds:Th(this.editor,n).box,padding:4})]})}getCanvasSvgDefs(){return[$x(),{key:"arrow:dot",component:LW},{key:"arrow:cross",component:FW}]}}m($h,"type","arrow"),m($h,"props",rE),m($h,"migrations",oE);function RW(e,t){const n=e.getArrowInfo(t);return n.isStraight?b.Dist(n.start.handle,n.end.handle):Math.abs(n.handleArc.length)}const iC=tr(function({shape:t,shouldDisplayHandles:n}){const r=z(),o=wt(),s=r.getArrowInfo(t),i=te.ZeroFix(r.getShapeGeometry(t).bounds),a=Se.useMemo(()=>r.environment.isSafari?DW+=1:0,[t]);if(!(s!=null&&s.isValid))return null;const l=$t[t.props.size],c=s.start.arrowhead&&Jp(s,"start",l),u=s.end.arrowhead&&Jp(s,"end",l),d=s.isStraight?c$(s):a$(s);let p=null;if(n){const{strokeDasharray:I,strokeDashoffset:P}=Ko(RW(r,t),2,{end:"skip",start:"skip",lengthRatio:2.5});p=t.props.start.type==="binding"||t.props.end.type==="binding"?h.jsx("path",{className:"tl-arrow-hint",d:s.isStraight?$W(s):TW(s),strokeDasharray:I,strokeDashoffset:P,strokeWidth:2,markerStart:t.props.start.type==="binding"?t.props.start.isExact?"":t.props.start.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",markerEnd:t.props.end.type==="binding"?t.props.end.isExact?"":t.props.end.isPrecise?"url(#arrowhead-cross)":"url(#arrowhead-dot)":"",opacity:.16}):null}const{strokeDasharray:f,strokeDashoffset:y}=Ko(s.isStraight?s.length:Math.abs(s.bodyArc.length),l,{style:t.props.dash}),g=Th(r,t),w=!(s.start.arrowhead==="none"||s.start.arrowhead==="arrow"),S=!(s.end.arrowhead==="none"||s.end.arrowhead==="arrow"),v=(t.id+"_clip_"+a).replace(":","_");return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsxs("mask",{id:v,children:[h.jsx("rect",{x:O(-100+i.minX),y:O(-100+i.minY),width:O(i.width+200),height:O(i.height+200),fill:"white"}),t.props.text.trim()&&h.jsx("rect",{x:g.box.x,y:g.box.y,width:g.box.w,height:g.box.h,fill:"black",rx:4,ry:4}),c&&w&&h.jsx("path",{d:c,fill:s.start.arrowhead==="arrow"?"none":"black",stroke:"none"}),u&&S&&h.jsx("path",{d:u,fill:s.end.arrowhead==="arrow"?"none":"black",stroke:"none"})]})}),h.jsxs("g",{fill:"none",stroke:o[t.props.color].solid,strokeWidth:l,strokeLinejoin:"round",strokeLinecap:"round",pointerEvents:"none",children:[p,h.jsxs("g",{mask:`url(#${v})`,children:[h.jsx("rect",{x:O(i.minX-100),y:O(i.minY-100),width:O(i.width+200),height:O(i.height+200),opacity:0}),h.jsx("path",{d,strokeDasharray:f,strokeDashoffset:y})]}),c&&w&&t.props.fill!=="none"&&h.jsx(Pt,{theme:o,d:c,color:t.props.color,fill:t.props.fill}),u&&S&&t.props.fill!=="none"&&h.jsx(Pt,{theme:o,d:u,color:t.props.color,fill:t.props.fill}),c&&h.jsx("path",{d:c}),u&&h.jsx("path",{d:u})]})]})}),aC=new WeakMap;function LW(){return h.jsx("marker",{id:"arrowhead-dot",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"0",children:h.jsx("circle",{cx:"3",cy:"3",r:"2",strokeDasharray:"100%"})})}function FW(){return h.jsxs("marker",{id:"arrowhead-cross",className:"tl-arrow-hint",refX:"3.0",refY:"3.0",orient:"auto",children:[h.jsx("line",{x1:"1.5",y1:"1.5",x2:"4.5",y2:"4.5",strokeDasharray:"100%"}),h.jsx("line",{x1:"1.5",y1:"4.5",x2:"4.5",y2:"1.5",strokeDasharray:"100%"})]})}const lC="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E";function sl({url:e,zoomLevel:t}){return h.jsx("a",{className:ue("tl-hyperlink-button",{"tl-hyperlink-button__hidden":t<.32}),href:e,target:"_blank",rel:"noopener noreferrer",onPointerDown:rn,onPointerUp:rn,title:e,draggable:!1,children:h.jsx("div",{className:"tl-hyperlink-button__icon",style:{mask:`url("${lC}") center 100% / 100% no-repeat`,WebkitMask:`url("${lC}") center 100% / 100% no-repeat`}})})}const NW=[{offsetX:0,offsetY:2,blur:4,spread:0,color:"#00000029"},{offsetX:0,offsetY:3,blur:6,spread:0,color:"#0000001f"}];function Ax(e){return NW.map(n=>{const{offsetX:r,offsetY:o,blur:s,spread:i,color:a}=n,l=new b(r,o),{x:c,y:u}=l.rot(-e);return`${c}px ${u}px ${s}px ${i}px ${a}`}).join(", ")}class Mh extends Sl{constructor(){super(...arguments);m(this,"canResize",()=>!1);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"onBeforeCreate",n=>{cC(this.editor,n)});m(this,"onBeforeUpdate",(n,r)=>{if(n.props.url!==r.props.url)if(Qn.isValid(r.props.url))cC(this.editor,r);else return{...r,props:{...r.props,url:n.props.url}}})}getDefaultProps(){return{url:"",w:300,h:320,assetId:null}}component(n){const r=n.props.assetId?this.editor.getAsset(n.props.assetId):null,o=this.editor.getShapePageTransform(n).rotation(),s=zW(n);return h.jsx(Ti,{children:h.jsxs("div",{className:"tl-bookmark__container",style:{boxShadow:Ax(o)},children:[h.jsxs("div",{className:"tl-bookmark__image_container",children:[r!=null&&r.props.image?h.jsx("img",{className:"tl-bookmark__image",draggable:!1,src:r==null?void 0:r.props.image,alt:(r==null?void 0:r.props.title)||""}):h.jsx("div",{className:"tl-bookmark__placeholder"}),h.jsx(sl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]}),h.jsxs("div",{className:"tl-bookmark__copy_container",children:[(r==null?void 0:r.props.title)&&h.jsx("h2",{className:"tl-bookmark__heading",children:Tc((r==null?void 0:r.props.title)||"",54)}),(r==null?void 0:r.props.description)&&h.jsx("p",{className:"tl-bookmark__description",children:Tc((r==null?void 0:r.props.description)||"",128)}),h.jsx("a",{className:"tl-bookmark__link",href:n.props.url||"",target:"_blank",rel:"noopener noreferrer",onPointerDown:rn,onPointerUp:rn,onClick:rn,children:Tc(s,45)})]})]})})}indicator(n){return h.jsx("rect",{width:O(n.props.w),height:O(n.props.h),rx:"6",ry:"6"})}}m(Mh,"type","bookmark"),m(Mh,"props",sE),m(Mh,"migrations",iE);const zW=e=>{try{const t=new URL(e.props.url),n=t.pathname.replace(/\/*$/,"");return`${t.hostname}${n}`}catch{return e.props.url}};function cC(e,t){const{url:n}=t.props,r=hi.createId(_y(n));e.getAsset(r)?t.props.assetId!==r&&e.updateShapes([{id:t.id,type:t.type,props:{assetId:r}}]):(e.updateShapes([{id:t.id,type:t.type,props:{assetId:null}}]),BW(e,t))}const BW=jI(async(e,t)=>{const{url:n}=t.props,r=await e.getAssetForExternalContent({type:"url",url:n});r&&e.batch(()=>{e.createAssets([r]),e.updateShapes([{id:t.id,type:t.type,props:{assetId:r.id}}])})},500);function $i(e,t=!1){const n=e.length;if(n<2)return"";let r=e[0].point,o=e[1].point;if(n===2)return`M${Ft(r)}L${Ft(o)}`;let s="";for(let i=2,a=n-1;i<a;i++)r=e[i].point,o=e[i+1].point,s+=Pn(r,o);return t?`M${Pn(e[0].point,e[1].point)}Q${Ft(e[1].point)}${Pn(e[1].point,e[2].point)}T${s}${Pn(e[n-1].point,e[0].point)}${Pn(e[0].point,e[1].point)}Z`:`M${Ft(e[0].point)}Q${Ft(e[1].point)}${Pn(e[1].point,e[2].point)}${e.length>3?"T":""}${s}L${Ft(e[n-1].point)}`}function UW(e,t={}){const{start:n={},end:r={}}=t,{cap:o=!0}=n,{cap:s=!0}=r;Ao(!n.taper&&!r.taper,"cap taper not supported here"),Ao(!n.easing&&!r.easing,"cap easing not supported here"),Ao(o&&s,"cap must be true");const i=ao(e,t);Vf(i,t);const a=HW(i);let l="";for(const c of a)l+=VW(c,t);return l}function HW(e){if(e.length<=2)return[e];const t=[];let n=[e[0]];for(let r=1;r<e.length-1;r++){const o=e[r-1],s=e[r],i=e[r+1],a=b.Angle(o.point,s.point),l=b.Angle(s.point,i.point),c=Math.abs(yc(a,l))/Math.PI;if(c>.8){const y={...s,point:s.input};n.push(y),t.push(Hm(n)),n=[y];continue}if(n.push(s),c<.25)continue;const u=(o.radius+s.radius+i.radius)/3,d=b.Dist(o.point,s.point)/u,p=b.Dist(s.point,i.point)/u;if(d+p<1.5){n.push(s),t.push(Hm(n)),n=[s];continue}}return n.push(e[e.length-1]),t.push(Hm(n)),t}function Hm(e){const t=e[0];for(;e.length>2;){const r=e[1],o=b.Dist(t.point,r.point),s=(t.radius+r.radius)/2;if(o<s*.5)e.splice(1,1);else break}const n=e[e.length-1];for(;e.length>2;){const r=e[e.length-2],o=b.Dist(n.point,r.point),s=(n.radius+r.radius)/2;if(o<s*.5)e.splice(e.length-2,1);else break}return e.length>1&&(e[0]={...e[0],vector:b.FromAngle(b.Angle(e[1].point,e[0].point))},e[e.length-1]={...e[e.length-1],vector:b.FromAngle(b.Angle(e[e.length-1].point,e[e.length-2].point))}),e}function KW(e,t,n){return"M "+e+" "+t+" m -"+n+", 0 a "+n+","+n+" 0 1,1 "+n*2+",0 a "+n+","+n+" 0 1,1 -"+n*2+",0"}function VW(e,t={}){if(e.length===0)return"";if(e.length===1)return KW(e[0].point.x,e[0].point.y,e[0].radius);const{left:n,right:r}=V2(e,t);r.reverse();let o=`M${Ft(n[0])}T`;for(let s=1;s<n.length;s++)o+=Pn(n[s-1],n[s]);{const s=e[e.length-1],i=s.radius,a=s.vector.clone().per().neg(),l=b.Add(s.point,b.Mul(a,i)),c=b.Add(s.point,b.Mul(a,-i));o+=`${Ft(l)}A${O(i)},${O(i)} 0 0 1 ${Ft(c)}T`}for(let s=1;s<r.length;s++)o+=Pn(r[s-1],r[s]);{const s=e[0],i=s.radius,a=s.vector.clone().per(),l=b.Add(s.point,b.Mul(a,i)),c=b.Add(s.point,b.Mul(a,-i));o+=`${Ft(l)}A${O(i)},${O(i)} 0 0 1 ${Ft(c)}Z`}return o}function au(){const e=z();return K("zoom",()=>e.getZoomLevel()<.35,[e])}const WW=e=>e*.65+QR(e*je/2)*.35,GW=e=>({size:1+e,thinning:.5,streamline:.62+(1+e)/8*.06,smoothing:.62,easing:nn.easeOutSine,simulatePressure:!0}),YW=e=>({size:1+e*1.2,thinning:.62,streamline:.62,smoothing:.62,simulatePressure:!1,easing:WW}),uC=e=>({size:1+e,thinning:0,streamline:.62+(1+e)/8*.06,smoothing:.62,simulatePressure:!1,easing:nn.linear});function nv({strokeWidth:e,showAsComplete:t}){return{size:1+e,thinning:0,streamline:.5,smoothing:.5,simulatePressure:!1,easing:nn.easeOutSine,last:t}}function rv(e,t,n,r){return{...r?uC(t):e.dash==="draw"?e.isPen?YW(t):GW(t):uC(t),last:e.isComplete||n}}function lu(e){const t=[];for(const n of e)if(n.type==="free"||n.points.length<2)t.push(...n.points.map(b.Cast));else{const r=Math.max(4,Math.floor(b.Dist(n.points[0],n.points[1])/16));t.push(...b.PointsBetween(n.points[0],n.points[1],r))}return t}function XW(e,t){return{draw:"none",solid:"none",dotted:`0.1 ${t*2}`,dashed:`${t*2} ${t*2}`}[e.props.dash]}class Ah extends Rr{constructor(){super(...arguments);m(this,"hideResizeHandles",n=>Km(n));m(this,"hideRotateHandle",n=>Km(n));m(this,"hideSelectionBoundsFg",n=>Km(n));m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of n.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:fp(o*l),y:fp(s*c),z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",fill:"none",dash:"draw",size:"m",isComplete:!1,isClosed:!1,isPen:!1}}getGeometry(n){const r=lu(n.props.segments),o=$t[n.props.size];if(n.props.segments.length===1){const i=te.FromPoints(r);if(i.width<o*2&&i.height<o*2)return new ox({x:-o,y:-o,radius:o,isFilled:!0})}const s=ao(r,rv(n.props,o,!0,!0)).map(i=>i.point);return n.props.isClosed?new bt({points:s,isFilled:n.props.fill!=="none"}):new Bi({points:s})}component(n){return h.jsx(Ds,{id:n.id,children:h.jsx(dC,{shape:n,forceSolid:au()})})}indicator(n){var d;const r=au(),o=$t[n.props.size],s=lu(n.props.segments);let i=o;!r&&!n.props.isPen&&n.props.dash==="draw"&&s.length===1&&(i+=Us(n.id)()*(o/6));const a=n.props.isComplete||((d=Vn(n.props.segments))==null?void 0:d.type)==="straight",l=rv(n.props,i,a,!0),c=ao(s,l),u=c.length>1?$i(c,n.props.isClosed):u$(s[0],i);return h.jsx("path",{d:u})}toSvg(n,r){return r.addExportDef(Tx(n.props.fill)),h.jsx(dC,{shape:n,forceSolid:!1})}getCanvasSvgDefs(){return[$x()]}expandSelectionOutlinePx(n){const r=n.props.dash==="draw"?1.6:1;return $t[n.props.size]*r/2}}m(Ah,"type","draw"),m(Ah,"props",lE),m(Ah,"migrations",cE);function u$(e,t){const n=(t+1)*.5;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function Km(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function dC({shape:e,forceSolid:t}){var d;const n=wt(),r=$t[e.props.size],o=lu(e.props.segments),s=e.props.isComplete||((d=Vn(e.props.segments))==null?void 0:d.type)==="straight";let i=r;!t&&!e.props.isPen&&e.props.dash==="draw"&&o.length===1&&(i+=Us(e.id)()*(r/6));const a=rv(e.props,i,s,t);if(!t&&e.props.dash==="draw")return h.jsxs(h.Fragment,{children:[e.props.isClosed&&e.props.fill&&o.length>1?h.jsx(Pt,{theme:n,fill:e.props.isClosed?e.props.fill:"none",color:e.props.color,d:$i(ao(o,a),e.props.isClosed)}):null,h.jsx("path",{d:UW(o,a),strokeLinecap:"round",fill:n[e.props.color].solid})]});const l=ao(o,a),c=l.length<2,u=c?u$(o[0],0):$i(l,e.props.isClosed);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:n,color:e.props.color,fill:c||e.props.isClosed?e.props.fill:"none",d:u}),h.jsx("path",{d:u,strokeLinecap:"round",fill:c?n[e.props.color].solid:"none",stroke:n[e.props.color].solid,strokeWidth:r,strokeDasharray:c?"none":XW(e,r),strokeDashoffset:"0"})]})}function qW(e,t,n={}){const{newPoint:r,handle:o,scaleX:s,scaleY:i}=t,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let d=e.props.w*s,p=e.props.h*i;const f=new b(0,0);if(d>0){if(d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=d-a;break}case"top":case"bottom":{f.x=(d-a)/2;break}default:f.x=0}d=a}}else if(f.x=d,d=-d,d<a){switch(o){case"top_left":case"left":case"bottom_left":{f.x=-d;break}default:f.x=-a}d=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:y,y:g}=f.rot(e.rotation).add(r);return{x:y,y:g,props:{w:Math.min(l,d),h:Math.min(u,p)}}}const ZW=e=>Object.entries(e).filter(([t,n])=>n).map(([t])=>t).join(" ");class jh extends Sl{constructor(){super(...arguments);m(this,"hideSelectionBoundsFg",n=>!this.canResize(n));m(this,"canEdit",()=>!0);m(this,"canResize",n=>{var r,o;return!!((o=(r=xs(n.props.url))==null?void 0:r.definition)!=null&&o.doesResize)});m(this,"canEditInReadOnly",()=>!0);m(this,"isAspectRatioLocked",n=>{const r=xs(n.props.url);return(r==null?void 0:r.definition.isAspectRatioLocked)??!1});m(this,"onResize",(n,r)=>{const o=this.isAspectRatioLocked(n),s=xs(n.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=n.props.w/n.props.h;l>1?i*=l:a/=l}return qW(n,r,{minWidth:i,minHeight:a})})}getDefaultProps(){return{w:300,h:300,url:""}}component(n){const{w:r,h:o,url:s}=n.props,i=Ff(n.id),a=x.useMemo(()=>X2(s),[s]),l=K("is hovering",()=>{const{editingShapeId:p,hoveredShapeId:f}=this.editor.getCurrentPageState();if(p&&f!==p){const y=this.editor.getShape(p);if(y&&this.editor.isShapeOfType(y,"embed"))return!0}return!1},[]),c=this.editor.getShapePageTransform(n).rotation(),u=i||l;if((a==null?void 0:a.definition.type)==="github_gist"){const p=a.url.split("/").pop();if(!p)throw Error("No gist id!");return h.jsx(Ti,{className:"tl-embed-container",id:n.id,children:h.jsx(QW,{id:p,width:O(r),height:O(o),isInteractive:u,pageRotation:c})})}const d=ZW({...NR,...(a==null?void 0:a.definition.overridePermissions)??{}});return h.jsx(Ti,{className:"tl-embed-container",id:n.id,children:a!=null&&a.definition?h.jsx("iframe",{className:"tl-embed",sandbox:d,src:a.embedUrl,width:O(r),height:O(o),draggable:!1,frameBorder:"0",referrerPolicy:"no-referrer-when-downgrade",style:{border:0,pointerEvents:u?"auto":"none",zIndex:u?"":"-1",boxShadow:Ax(c),borderRadius:(a==null?void 0:a.definition.overrideOutlineRadius)??8,background:a==null?void 0:a.definition.backgroundColor}}):null})}indicator(n){const r=x.useMemo(()=>xs(n.props.url),[n.props.url]);return h.jsx("rect",{width:O(n.props.w),height:O(n.props.h),rx:(r==null?void 0:r.definition.overrideOutlineRadius)??8,ry:(r==null?void 0:r.definition.overrideOutlineRadius)??8})}}m(jh,"type","embed"),m(jh,"props",uE),m(jh,"migrations",dE);function QW({id:e,file:t,isInteractive:n,width:r,height:o,style:s,pageRotation:i}){return h.jsx("iframe",{className:"tl-embed",draggable:!1,width:O(r),height:O(o),frameBorder:"0",scrolling:"no",seamless:!0,referrerPolicy:"no-referrer-when-downgrade",style:{...s,pointerEvents:n?"all":"none",zIndex:n?"":"-1",boxShadow:Ax(i)},srcDoc:`
140
- <html>
141
- <head>
142
- <base target="_blank">
143
- </head>
144
- <body>
145
- <script src=${`https://gist.github.com/${e}.js${t?`?file=${t}`:""}`}><\/script>
146
- <style type="text/css">
147
- * { margin: 0px; }
148
- table { height: 100%; background-color: red; }
149
- .gist { background-color: none; height: 100%; }
150
- .gist .gist-file { height: calc(100vh - 2px); padding: 0px; display: grid; grid-template-rows: 1fr auto; }
151
- </style>
152
- </body>
153
- </html>`})}const JW=x.forwardRef(({id:e,name:t,isEditing:n},r)=>{const o=z(),s=x.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(rn(l),l.currentTarget.blur(),o.setEditingShape(null))},[o]),i=x.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,d=l.currentTarget.value.trim();u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}],{squashing:!0})},[e,o]),a=x.useCallback(l=>{const c=o.getShape(e);if(!c)return;const u=c.props.name,d=l.currentTarget.value;u!==d&&o.updateShapes([{id:e,type:"frame",props:{name:d}}],{squashing:!0})},[e,o]);return h.jsxs("div",{className:`tl-frame-label ${n?"tl-frame-label__editing":""}`,children:[h.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:n?void 0:"none"},value:t,autoFocus:!0,onKeyDown:s,onBlur:i,onChange:a}),d$(t,"Frame")+"​"]})}),eG=function({id:t,name:n,width:r,height:o}){const s=z(),i=K("shape rotation",()=>ws(s.getShapePageTransform(t).rotation()),[s,t]),a=Ff(t),l=x.useRef(null),c=x.useCallback(y=>{const g=En(y);s.getEditingShapeId()!==t&&(s.dispatch({type:"pointer",name:"pointer_down",target:"shape",shape:s.getShape(t),...g}),y.preventDefault())},[s,t]);x.useEffect(()=>{const y=l.current;y&&a&&(y.focus(),y.select(),requestAnimationFrame(()=>{document.activeElement!==y&&(y.focus(),y.select())}))},[l,a]);const d=((i+Math.PI/4)*(2/Math.PI)+4)%4,p=["top","left","bottom","right"][Math.floor(d)];let f;switch(p){case"top":f="";break;case"right":f=`translate(${O(r)}px, 0px) rotate(90deg)`;break;case"bottom":f=`translate(${O(r)}px, ${O(o)}px) rotate(180deg)`;break;case"left":f=`translate(0px, ${O(o)}px) rotate(270deg)`;break}return h.jsx("div",{className:"tl-frame-heading",style:{overflow:a?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(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:h.jsx("div",{className:"tl-frame-heading-hit-area",children:h.jsx(JW,{ref:l,id:t,name:n,isEditing:a})})})};function d$(e,t){return e.match(/^\s*$/)?t:e}class Oh extends Sl{constructor(){super(...arguments);m(this,"canBind",()=>!0);m(this,"canEdit",()=>!0);m(this,"canReceiveNewChildrenOfType",(n,r)=>!n.isLocked);m(this,"canDropShapes",(n,r)=>!n.isLocked);m(this,"onDragShapesOver",(n,r)=>{r.every(o=>o.parentId===n.id)||this.editor.reparentShapes(r,n.id)});m(this,"onDragShapesOut",(n,r)=>{const o=this.editor.getShape(n.parentId);o&&this.editor.isShapeOfType(o,"group")?this.editor.reparentShapes(r,o.id):this.editor.reparentShapes(r,this.editor.getCurrentPageId())});m(this,"onResize",(n,r)=>BT(n,r))}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(n){return new Ho({width:n.props.w,height:n.props.h,isFilled:!1})}component(n){const r=this.editor.getShapeGeometry(n).bounds,o=wt(),s=K("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()===n.id:!1},[n.id]);return h.jsxs(h.Fragment,{children:[h.jsx(Ds,{children:h.jsx("rect",{className:ue("tl-frame__body",{"tl-frame__creating":s}),width:r.width,height:r.height,fill:o.solid,stroke:o.text})}),s?null:h.jsx(eG,{id:n.id,name:n.props.name,width:r.width,height:r.height})]})}toSvg(n,r){const o=qo({isDarkMode:r.isDarkMode}),a=((ws(this.editor.getShapePageTransform(n.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(${O(n.props.w)}, 0) rotate(90)`;break;case 2:c=`translate(${O(n.props.w)}, ${O(n.props.h)}) rotate(180)`;break;case 1:c=`translate(0, ${O(n.props.h)}) rotate(270)`;break;default:throw Error("labelSide out of bounds")}const u={fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:n.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle"},d=this.editor.textMeasure.measureTextSpans(d$(n.props.name,"Frame")+"​",u),p=d[0],f=Vn(d),y=f.box.w+f.box.x-p.box.x,g=tv(this.editor,d,{offsetY:-u.height-2,...u});return h.jsxs(h.Fragment,{children:[h.jsx("rect",{width:n.props.w,height:n.props.h,fill:o.solid,stroke:o.black.solid,strokeWidth:1,rx:1,ry:1}),h.jsxs("g",{transform:c,children:[h.jsx("rect",{x:-8,y:-u.height-4,width:y+16,height:u.height,fill:o.background,rx:4,ry:4}),g]})]})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds;return h.jsx("rect",{width:O(r.width),height:O(r.height),className:"tl-frame-indicator"})}providesBackgroundForChildren(){return!0}}m(Oh,"type","frame"),m(Oh,"props",hE),m(Oh,"migrations",pE);function Yt(e){return`${O(e.x)},${O(e.y)} `}function h$(e=""){let t=0,n=0,r=0,o=0;function s(){const i=t^t<<11;return t=n,n=r,r=o,o^=(o>>>19^i^i>>>8)>>>0,o/4294967296*2}for(let i=0;i<e.length+64;i++)t^=e.charCodeAt(i)|0,s();return s}function ov(e){let t="M";const n=e.length;let r,o,s;for(let i=0,a=n;i<a;i+=3)r=e[i],o=e[i+1],s=e[i+2],t+=`${Yt(r)}L${Yt(o)}Q${Yt(s)}`;return t+=`${Yt(e[0])}`,t}function sv(e,t,n,r,o){const s=[],i=h$(e);let a=t[0],l;const c=t.length;for(let u=0,d=c*o;u<d;u++){l=b.AddXY(t[(u+1)%c],i()*n,i()*n);const p=b.Sub(l,a),f=b.Len(p),y=b.Div(p,f).mul(Math.min(f/4,r));s.push(b.Add(a,y),b.Add(l,y.neg()),l),a=l}return s}function p$(e,t,n){let r=`M ${Yt(t[0])}L`,o=`M ${Yt(t[0])}L`;const s=n/3,i=n*2,a=h$(e);let l=t[0],c,u=t[0],d;const p=t.length;for(let f=0,y=p-1;f<y;f++){c=t[f+1],d=b.AddXY(t[f+1],a()*s,a()*s);const g=b.Sub(c,l),w=b.Len(g),S=b.Div(g,w).mul(Math.min(w/4,i)),v=b.Add(l,S),C=b.Add(c,S.neg()),I=b.Sub(d,u),P=b.Len(I),E=b.Div(I,P).mul(Math.min(P/4,i)),_=b.Add(u,E),k=b.Add(d,E.neg());f===y-1?(r+=`${Yt(v)}L ${Yt(c)}`,o+=`${Yt(_)}L ${Yt(d)}`):(r+=`${Yt(v)}L ${Yt(C)}Q ${Yt(c)}`,o+=`${Yt(_)}L ${Yt(k)}Q ${Yt(d)}`,l=c,u=d)}return[r,r+o]}function hC(e,t){const n=Math.min(e,t)/2,r=Math.max(e,t)-n*2;return Math.PI*(n*2)+2*r}function tG(e,t,n){const r=Math.min(e,t)/2,o=Math.max(e,t)-r*2,i=(Math.PI*(r*2)+2*o)/n,a=e>t?[{type:"straight",start:new b(r,0),delta:new b(1,0)},{type:"arc",center:new b(e-r,r),startAngle:-je/2},{type:"straight",start:new b(e-r,t),delta:new b(-1,0)},{type:"arc",center:new b(r,r),startAngle:je/2}]:[{type:"straight",start:new b(e,r),delta:new b(0,1)},{type:"arc",center:new b(r,t-r),startAngle:0},{type:"straight",start:new b(0,t-r),delta:new b(0,-1)},{type:"arc",center:new b(r,r),startAngle:je}];let l=0;const c=[];for(let u=0;u<n;u++){const d=a[0];d.type==="straight"?c.push(b.Add(d.start,b.Mul(d.delta,l))):c.push(bi(d.center,r,d.startAngle+l/r)),l+=i;let p=d.type==="straight"?o:je*r;for(;l>p;)l-=p,a.push(a.shift()),p=a[0].type==="straight"?o:je*r}return c}const nG=(e,t,n,r,o)=>{switch(e){case"s":return t;case"m":return n;case"l":return r;case"xl":return o}};function Yf(e,t,n,r){const o=Us(n),s=hC(e,t),i=Math.max(Math.ceil(s/nG(r,50,70,100,130)),6,Math.ceil(s/Math.min(e,t))),a=s/i*.2,l=Math.max(e-a*2,1),c=Math.max(t-a*2,1),u=(e-l)/2,d=(t-c)/2,p=hC(l,c)/i,f=tG(l,c,i).map(v=>v.addXY(u,d)),y=e<20?0:a*.3,g=t<20?0:a*.3,w=f.slice(0);for(let v=0;v<Math.floor(i/2);v++)w[v]=b.AddXY(w[v],o()*y,o()*g),w[i-v-1]=b.AddXY(w[i-v-1],o()*y,o()*g);const S=[];for(let v=0;v<w.length;v++){const C=v===w.length-1?0:v+1,I=w[v],P=w[C],E=f[v],_=f[C],k=b.Average([E,_]),$=b.Angle(E,_)-Math.PI/2,T=b.Dist(E,_),j=p-T,N=b.Dist(I,P)/T,F=(Math.max(u,d)+j)*N,B=b.Add(k,b.FromAngle($,F));B.x<0?B.x=0:B.x>e&&(B.x=e),B.y<0?B.y=0:B.y>t&&(B.y=t);const q=f$(I,P,B),Q=b.Dist(q||b.Average([I,P]),I);S.push({leftPoint:I,rightPoint:P,arcPoint:B,center:q,radius:Q})}return S}function f$(e,t,n){const r=e.x*(t.y-n.y)-e.y*(t.x-n.x)+t.x*n.y-n.x*t.y,o=(e.x*e.x+e.y*e.y)*(n.y-t.y)+(t.x*t.x+t.y*t.y)*(e.y-n.y)+(n.x*n.x+n.y*n.y)*(t.y-e.y),s=(e.x*e.x+e.y*e.y)*(t.x-n.x)+(t.x*t.x+t.y*t.y)*(n.x-e.x)+(n.x*n.x+n.y*n.y)*(e.x-t.x),i=-o/(2*r),a=-s/(2*r);return!Number.isFinite(i)||!Number.isFinite(a)?null:new b(i,a)}function rG(e,t,n,r){const o=[],s=Yf(e,t,n,r);for(const{center:i,radius:a,leftPoint:l,rightPoint:c}of s)o.push(...sG(l,c,i,a,10));return o}function jx(e,t,n,r){const o=Yf(e,t,n,r);let s=`M${O(o[0].leftPoint.x)},${O(o[0].leftPoint.y)}`;for(const{leftPoint:i,rightPoint:a,radius:l,center:c}of o){if(c===null){s+=` L${O(a.x)},${O(a.y)}`;continue}const u=g$(i,a,c)?"0":"1";s+=` A${O(l)},${O(l)} 0 ${u},1 ${O(a.x)},${O(a.y)}`}return s+=" Z",s}function oG(e,t,n,r){const o=Us(n),s=r==="s"?.5:r==="m"?.7:r==="l"?.9:1.6,i=y=>y+o()*s*2,a=Yf(e,t,n,r),u=a.reduce((y,g)=>y+b.Dist2(g.leftPoint,g.rightPoint),0)/a.length>(s*15)**2?y=>new b(i(y.x),i(y.y)):y=>y;let d=`M${O(a[0].leftPoint.x)},${O(a[0].leftPoint.y)}`,p=u(a[0].leftPoint),f=`M${O(p.x)},${O(p.y)}`;for(const{leftPoint:y,center:g,rightPoint:w,radius:S,arcPoint:v}of a){if(g===null){d+=` L${O(w.x)},${O(w.y)}`;const k=u(w);f+=` L${O(k.x)},${O(k.y)}`,p=k;continue}const C=g$(y,w,g)?"0":"1";d+=` A${O(S)},${O(S)} 0 ${C},1 ${O(w.x)},${O(w.y)}`;const I=u(w),P=u(v),E=f$(p,I,P);if(!E){f+=` L${O(I.x)},${O(I.y)}`,p=I;continue}const _=Math.abs(b.Dist(E,p));f+=` A${O(_)},${O(_)} 0 ${C},1 ${O(I.x)},${O(I.y)}`,p=I}return d+f+" Z"}function sG(e,t,n,r,o){if(n===null)return[b.From(e),b.From(t)];const s=[],i=b.Angle(n,e),a=b.Angle(n,t),l=bu(i,a);for(let c=0;c<o;c++){const u=c/(o-1),d=i+l*u,p=bi(n,r,d);s.push(p)}return s}function g$(e,t,n){return(t.x-e.x)*(n.y-e.y)-(t.y-e.y)*(n.x-e.x)>0}function iG(e){return{size:1+e,thinning:.25,end:{taper:e},start:{taper:e},streamline:0,smoothing:1,simulatePressure:!1}}function aG(e,t,n,r){const o=Us(e),s=t/2,i=n/2,a=hp(s,i),l=[],c=Fe*o(),u=Fe+Ge/2+Math.abs(o())*Ge,d=Math.max(16,a/10);for(let p=0;p<d;p++){const f=p/(d-1),y=c+f*u,g=Math.cos(y),w=Math.sin(y);l.push(new b(s*g+t*.5+.05*o(),i*w+n/2+.05*o(),Math.min(1,.5+Math.abs(.5-(o()>0?nn.easeInOutSine(f):nn.easeInExpo(f)))/2)))}return ao(l,iG(r))}function lG(e,t,n,r){return $i(aG(e,t,n,r))}function iv(e,t){switch(e.geo){case"x-box":return cG(e.w,e.h,t,e.dash);case"check-box":return uG(e.w,e.h);default:return}}function cG(e,t,n,r){const o=r==="draw"?.62:0;if(r==="dashed")return[[new b(0,0),new b(e/2,t/2)],[new b(e,t),new b(e/2,t/2)],[new b(0,t),new b(e/2,t/2)],[new b(e,0),new b(e/2,t/2)]];const s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(t,a));return[[new b(s(n*o),i(n*o)),new b(s(e-n*o),i(t-n*o))],[new b(s(n*o),i(t-n*o)),new b(s(e-n*o),i(n*o))]]}function uG(e,t){const n=Math.min(e,t)*.82,r=(e-n)/2,o=(t-n)/2,s=a=>Math.max(0,Math.min(e,a)),i=a=>Math.max(0,Math.min(t,a));return[[new b(s(r+n*.25),i(o+n*.52)),new b(s(r+n*.45),i(o+n*.82))],[new b(s(r+n*.45),i(o+n*.82)),new b(s(r+n*.82),i(o+n*.22))]]}const dG=x.memo(function({dash:t,fill:n,color:r,strokeWidth:o,w:s,h:i,id:a,size:l}){const c=wt(),u=jx(s,i,a,l),d=Yf(s,i,a,l);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:c,d:u,fill:n,color:r}),h.jsx("g",{strokeWidth:o,stroke:c[r].solid,fill:"none",pointerEvents:"all",children:d.map(({leftPoint:p,rightPoint:f,center:y,radius:g},w)=>{const S=y?g*ws(ws(b.Angle(y,f))-ws(b.Angle(y,p))):b.Dist(p,f),{strokeDasharray:v,strokeDashoffset:C}=Ko(S,o,{style:t,start:"outset",end:"outset"});return h.jsx("path",{d:y?`M${p.x},${p.y}A${g},${g},0,0,1,${f.x},${f.y}`:`M${p.x},${p.y}L${f.x},${f.y}`,strokeDasharray:v,strokeDashoffset:C},w)})})]})}),hG=x.memo(function({w:t,h:n,strokeWidth:r,dash:o,color:s,fill:i}){const a=wt(),l=t/2,c=n/2,u=Math.max(0,l),d=Math.max(0,c),p=hp(u,d),{strokeDasharray:f,strokeDashoffset:y}=Ko(p<64?p*2:p,r,{style:o,snap:4,closed:!0}),g=`M${l-u},${c}a${u},${d},0,1,1,${u*2},0a${u},${d},0,1,1,-${u*2},0`;return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:a,d:g,color:s,fill:i}),h.jsx("path",{d:g,strokeWidth:r,width:O(t),height:O(n),fill:"none",stroke:a[s].solid,strokeDasharray:f,strokeDashoffset:y,pointerEvents:"all"})]})});function pG(e,t){if(t>e){const r=e/2;return`
154
- M0,${r}
155
- a${r},${r},0,1,1,${r*2},0
156
- L${e},${t-r}
157
- a${r},${r},0,1,1,-${r*2},0
158
- Z`}const n=t/2;return`
159
- M${n},0
160
- L${e-n},0
161
- a${n},${n},0,1,1,0,${n*2}
162
- L${n},${t}
163
- a${n},${n},0,1,1,0,${-n*2}
164
- Z`}function fG(e,t){if(e>t){const r=t/2;return hp(r,r)+(e-r*2)*2}const n=e/2;return hp(n,n)+(t-n*2)*2}const gG=x.memo(function({w:t,h:n,strokeWidth:r,dash:o,color:s,fill:i}){const a=wt(),l=pG(t,n),c=fG(t,n),{strokeDasharray:u,strokeDashoffset:d}=Ko(c<64?c*2:c,r,{style:o,snap:4,start:"outset",end:"outset",closed:!0});return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:a,d:l,color:s,fill:i}),h.jsx("path",{d:l,strokeWidth:r,width:O(t),height:O(n),fill:"none",stroke:a[s].solid,strokeDasharray:u,strokeDashoffset:d,pointerEvents:"all"})]})}),mG=x.memo(function({dash:t,fill:n,color:r,strokeWidth:o,outline:s,lines:i}){const a=wt(),l="M"+s[0]+"L"+s.slice(1)+"Z";return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:a,d:l,fill:n,color:r}),h.jsxs("g",{strokeWidth:o,stroke:a[r].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(s.length)).map((c,u)=>{const d=s[u],p=s[(u+1)%s.length],f=b.Dist(d,p),{strokeDasharray:y,strokeDashoffset:g}=Ko(f,o,{style:t,start:"outset",end:"outset"});return h.jsx("line",{x1:d.x,y1:d.y,x2:p.x,y2:p.y,strokeDasharray:y,strokeDashoffset:g},u)}),i&&i.map(([c,u],d)=>{const p=b.Dist(c,u),{strokeDasharray:f,strokeDashoffset:y}=Ko(p,o,{style:t,start:"skip",end:"outset",snap:t==="dotted"?4:void 0});return h.jsx("path",{d:`M${c.x},${c.y}L${u.x},${u.y}`,stroke:a[r].solid,strokeWidth:o,fill:"none",strokeDasharray:f,strokeDashoffset:y},`line_fg_${d}`)})]})]})}),yG=x.memo(function({fill:t,color:n,strokeWidth:r,w:o,h:s,id:i,size:a}){const l=wt(),c=oG(o,s,i,a);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:l,d:c,fill:t,color:n}),h.jsx("path",{d:c,stroke:l[n].solid,strokeWidth:r,fill:"none"})]})}),SG=x.memo(function({id:t,outline:n,lines:r,fill:o,color:s,strokeWidth:i}){const a=wt(),l=sv(t,n,i/3,i*2,2);let c=ov(l);if(r)for(const[p,f]of r)c+=`M${p.x},${p.y}L${f.x},${f.y}`;const u=sv(t,n,0,i*2,1),d=ov(u);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d,fill:o,color:s,theme:a}),h.jsx("path",{d:c,stroke:a[s].solid,strokeWidth:i,fill:"none"})]})}),vG=x.memo(function({fill:t,color:n,strokeWidth:r,w:o,h:s,id:i,size:a}){const l=wt(),c=jx(o,s,i,a);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{theme:l,d:c,fill:t,color:n}),h.jsx("path",{d:c,stroke:l[n].solid,strokeWidth:r,fill:"none"})]})}),pC=x.memo(function({w:t,h:n,strokeWidth:r,fill:o,color:s}){const i=wt(),a=t/2,l=n/2,c=Math.max(0,a),u=Math.max(0,l),d=`M${a-c},${l}a${c},${u},0,1,1,${c*2},0a${c},${u},0,1,1,-${c*2},0`;return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d,color:s,fill:o,theme:i}),h.jsx("path",{d,stroke:i[s].solid,strokeWidth:r,fill:"none"})]})}),fC=x.memo(function({w:t,h:n,strokeWidth:r,fill:o,color:s}){const i=wt(),a=m$(t,n);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,color:s,fill:o,theme:i}),h.jsx("path",{d:a,stroke:i[s].solid,strokeWidth:r,fill:"none"})]})});function m$(e,t){let n;if(t>e){const r=e/2;n=`
165
- M0,${r}
166
- a${r},${r},0,1,1,${r*2},0
167
- L${e},${t-r}
168
- a${r},${r},0,1,1,-${r*2},0
169
- Z`}else{const r=t/2;n=`
170
- M${r},0
171
- L${e-r},0
172
- a${r},${r},0,1,1,0,${r*2}
173
- L${r},${t}
174
- a${r},${r},0,1,1,0,${-r*2}
175
- Z`}return n}const xG=x.memo(function({outline:t,lines:n,fill:r,color:o,strokeWidth:s}){const i=wt();let a="M"+t[0]+"L"+t.slice(1)+"Z";if(n)for(const[l,c]of n)a+=`M${l.x},${l.y}L${c.x},${c.y}`;return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:r,color:o,theme:i}),h.jsx("path",{d:a,stroke:i[o].solid,strokeWidth:s,fill:"none"})]})});function gC({shape:e}){const t=z(),{id:n,props:r}=e,{w:o,color:s,fill:i,dash:a,growY:l,size:c}=r,u=$t[c],d=r.h+l;switch(r.geo){case"cloud":{if(a==="solid")return h.jsx(vG,{color:s,fill:i,strokeWidth:u,w:o,h:d,id:n,size:c});if(a==="dashed"||a==="dotted")return h.jsx(dG,{color:s,fill:i,strokeWidth:u,w:o,h:d,id:n,size:c,dash:a});if(a==="draw")return h.jsx(yG,{color:s,fill:i,strokeWidth:u,w:o,h:d,id:n,size:c});break}case"ellipse":{if(a==="solid")return h.jsx(pC,{strokeWidth:u,w:o,h:d,color:s,fill:i});if(a==="dashed"||a==="dotted")return h.jsx(hG,{id:n,strokeWidth:u,w:o,h:d,dash:a,color:s,fill:i});if(a==="draw")return h.jsx(pC,{strokeWidth:u,w:o,h:d,color:s,fill:i});break}case"oval":{if(a==="solid")return h.jsx(fC,{strokeWidth:u,w:o,h:d,color:s,fill:i});if(a==="dashed"||a==="dotted")return h.jsx(gG,{id:n,strokeWidth:u,w:o,h:d,dash:a,color:s,fill:i});if(a==="draw")return h.jsx(fC,{strokeWidth:u,w:o,h:d,color:s,fill:i});break}default:{const p=t.getShapeGeometry(e),f=p instanceof Fr?p.children[0].vertices:p.vertices,y=iv(e.props,u);if(a==="solid")return h.jsx(xG,{fill:i,color:s,strokeWidth:u,outline:f,lines:y});if(a==="dashed"||a==="dotted")return h.jsx(mG,{dash:a,fill:i,color:s,strokeWidth:u,outline:f,lines:y});if(a==="draw")return h.jsx(SG,{id:n,fill:i,color:s,strokeWidth:u,outline:f,lines:y})}}}const ar=17*3;class Dh extends Sl{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});m(this,"onResize",(n,{handle:r,newPoint:o,scaleX:s,scaleY:i,initialShape:a})=>{let l=a.props.w*s,c=(a.props.h+a.props.growY)*i,u=0,d=0;if(n.props.text.trim()){let g=Math.max(Math.abs(l),ar),w=Math.max(Math.abs(c),ar);g<ar&&w===ar&&(g=ar),g===ar&&w<ar&&(w=ar);const S=Rd(this.editor,{...n,props:{...n.props,w:g,h:w}}),v=Math.max(Math.abs(l),S.w)*Math.sign(l),C=Math.max(Math.abs(c),S.h)*Math.sign(c);u=Math.abs(v)-Math.abs(l),d=Math.abs(C)-Math.abs(c),l=v,c=C}const p=new b(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?d:-d);const{x:f,y}=p.rot(n.rotation).add(o);return{x:f,y,props:{w:Math.max(Math.abs(l),1),h:Math.max(Math.abs(c),1),growY:0}}});m(this,"onBeforeCreate",n=>{if(!n.props.text)return n.props.growY?{...n,props:{...n.props,growY:0}}:void 0;const r=n.props.h,o=Rd(this.editor,n).h;let s=null;if(o>r?s=o-r:n.props.growY&&(s=0),s!==null)return{...n,props:{...n.props,growY:s}}});m(this,"onBeforeUpdate",(n,r)=>{const o=n.props.text,s=r.props.text;if(o===s&&n.props.font===r.props.font&&n.props.size===r.props.size)return;if(o&&!s)return{...r,props:{...r.props,growY:0}};const i=n.props.w,a=n.props.h,l=Rd(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 n.props.w<ar&&n.props.h<ar&&(p=Math.max(p,ar),f=Math.max(f,ar),p=Math.max(p,f),f=Math.max(p,f)),{...r,props:{...r.props,w:p,h:f,growY:0}}}let d=null;if(u>a?d=u-a:n.props.growY&&(d=0),d!==null)return{...r,props:{...r.props,growY:d,w:Math.max(r.props.w,c)}};if(c>n.props.w)return{...r,props:{...r.props,w:c}}});m(this,"onDoubleClick",n=>{if(this.editor.inputs.altKey)switch(n.props.geo){case"rectangle":return{...n,props:{geo:"check-box"}};case"check-box":return{...n,props:{geo:"rectangle"}}}})}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:""}}getGeometry(n){const r=Math.max(1,n.props.w),o=Math.max(1,n.props.h+n.props.growY),s=r/2,i=o/2,a=$t[n.props.size],l=n.props.fill!=="none";let c;switch(n.props.geo){case"cloud":{c=new bt({points:rG(r,o,n.id,n.props.size),isFilled:l});break}case"triangle":{c=new bt({points:[new b(s,0),new b(r,o),new b(0,o)],isFilled:l});break}case"diamond":{c=new bt({points:[new b(s,0),new b(r,i),new b(s,o),new b(0,i)],isFilled:l});break}case"pentagon":{c=new bt({points:$g(r,o,5),isFilled:l});break}case"hexagon":{c=new bt({points:$g(r,o,6),isFilled:l});break}case"octagon":{c=new bt({points:$g(r,o,8),isFilled:l});break}case"ellipse":{c=new HT({width:r,height:o,isFilled:l});break}case"oval":{c=new i8({width:r,height:o,isFilled:l});break}case"star":{const v=Fe/5/2,C=Math.floor(5/4)*2,I=5*2-C,P=0,E=Math.floor(5/2)*2,_=Math.cos(-Ge+C*v)*r/2,k=Math.cos(-Ge+I*v)*r/2,$=Math.sin(-Ge+P*v)*o/2,T=Math.sin(-Ge+E*v)*o/2,j=r-Math.abs(_-k),L=o-Math.abs(T-$),N=r/2+k-(r/2-_),F=o/2+$-(o/2-T),B=1,q=(r-N)/2,Q=(o-F)/2,V=(r+j)/2,U=(o+L)/2,H=V*B/2,Z=U*B/2;c=new bt({points:Array.from(Array(5*2)).map((ce,be)=>{const ke=-Ge+be*v;return new b(q+(be%2?H:V)*Math.cos(ke),Q+(be%2?Z:U)*Math.sin(ke))}),isFilled:l});break}case"rhombus":{const S=Math.min(r*.38,o*.38);c=new bt({points:[new b(S,0),new b(r,0),new b(r-S,o),new b(0,o)],isFilled:l});break}case"rhombus-2":{const S=Math.min(r*.38,o*.38);c=new bt({points:[new b(0,0),new b(r-S,0),new b(r,o),new b(S,o)],isFilled:l});break}case"trapezoid":{const S=Math.min(r*.38,o*.38);c=new bt({points:[new b(S,0),new b(r-S,0),new b(r,o),new b(0,o)],isFilled:l});break}case"arrow-right":{const S=Math.min(r,o)*.38,v=o*.16;c=new bt({points:[new b(0,v),new b(r-S,v),new b(r-S,0),new b(r,o/2),new b(r-S,o),new b(r-S,o-v),new b(0,o-v)],isFilled:l});break}case"arrow-left":{const S=Math.min(r,o)*.38,v=o*.16;c=new bt({points:[new b(S,0),new b(S,v),new b(r,v),new b(r,o-v),new b(S,o-v),new b(S,o),new b(0,o/2)],isFilled:l});break}case"arrow-up":{const S=r*.16,v=Math.min(r,o)*.38;c=new bt({points:[new b(r/2,0),new b(r,v),new b(r-S,v),new b(r-S,o),new b(S,o),new b(S,v),new b(0,v)],isFilled:l});break}case"arrow-down":{const S=r*.16,v=Math.min(r,o)*.38;c=new bt({points:[new b(S,0),new b(r-S,0),new b(r-S,o-v),new b(r,o-v),new b(r/2,o),new b(0,o-v),new b(S,o-v)],isFilled:l});break}case"check-box":case"x-box":case"rectangle":{c=new Ho({width:r,height:o,isFilled:l});break}}const u=Rd(this.editor,n),d=Math.min(100,r/2),p=Math.min(r,Math.max(u.w,Math.min(d,Math.max(1,r-8)))),f=Math.min(Do[n.props.size]*Ut.lineHeight+kr*2,o/2),y=Math.min(o,Math.max(u.h,Math.min(f,Math.max(1,r-8)))),g=iv(n.props,a),w=g?g.map(S=>new Bi({points:S})):[];return new Fr({children:[c,new Ho({x:n.props.align==="start"?0:n.props.align==="end"?r-p:(r-p)/2,y:n.props.verticalAlign==="start"?0:n.props.verticalAlign==="end"?o-y:(o-y)/2,width:p,height:y,isFilled:!0,isLabel:!0}),...w]})}getHandleSnapGeometry(n){const r=this.getGeometry(n),o=r.children[0];switch(n.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"oval":return{outline:o,points:[r.bounds.center]};default:Bs(n.props.geo)}}component(n){const{id:r,type:o,props:s}=n,{fill:i,font:a,align:l,verticalAlign:c,size:u,text:d}=s,p=n.id===this.editor.getOnlySelectedShapeId(),f=wt(),g=this.editor.getEditingShapeId()!==null||n.props.text;return h.jsxs(h.Fragment,{children:[h.jsx(Ds,{id:r,children:h.jsx(gC,{shape:n})}),g&&h.jsx(Ti,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h+s.growY},children:h.jsx(Gf,{id:r,type:o,font:a,fontSize:Do[u],lineHeight:Ut.lineHeight,fill:i,align:l,verticalAlign:c,text:d,isSelected:p,labelColor:f[s.labelColor].solid,disableTab:!0,wrap:!0})}),n.props.url&&h.jsx(sl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){const{id:r,props:o}=n,{w:s,size:i}=o,a=o.h+o.growY,l=$t[i];switch(o.geo){case"ellipse":return o.dash==="draw"?h.jsx("path",{d:lG(r,s,a,l)}):h.jsx("ellipse",{cx:s/2,cy:a/2,rx:s/2,ry:a/2});case"oval":return h.jsx("path",{d:m$(s,a)});case"cloud":return h.jsx("path",{d:jx(s,a,r,i)});default:{const c=this.editor.getShapeGeometry(n),u=c instanceof Fr?c.children[0].vertices:c.vertices;let d;if(o.dash==="draw"){const f=sv(r,u,0,l*2,1);d=ov(f)}else d="M"+u[0]+"L"+u.slice(1)+"Z";const p=iv(n.props,l);if(p)for(const[f,y]of p)d+=`M${f.x},${f.y}L${y.x},${y.y}`;return h.jsx("path",{d})}}}toSvg(n,r){const{props:o}=n;r.addExportDef(Tx(n.props.fill));let s;if(o.text){r.addExportDef(ol(n.props.font));const i=qo(r),a=this.editor.getShapeGeometry(n).bounds;s=h.jsx(Wf,{fontSize:Do[o.size],font:o.font,align:o.align,verticalAlign:o.verticalAlign,text:o.text,labelColor:i[o.labelColor].solid,bounds:a})}return h.jsxs(h.Fragment,{children:[h.jsx(gC,{shape:n}),s]})}getCanvasSvgDefs(){return[$x()]}}m(Dh,"type","geo"),m(Dh,"props",fE),m(Dh,"migrations",gE);function Rd(e,t){const n=t.props.text;if(!n)return{w:0,h:0};const r=e.textMeasure.measureText("w",{...Ut,fontFamily:oo[t.props.font],fontSize:Do[t.props.size],maxWidth:100}),o={s:2,m:3.5,l:5,xl:10},s=e.textMeasure.measureText(n,{...Ut,fontFamily:oo[t.props.font],fontSize:Do[t.props.size],minWidth:r.w,maxWidth:Math.max(0,Math.ceil(r.w+o[t.props.size]),Math.ceil(t.props.w-kr*2))});return{w:s.w+kr*2,h:s.h+kr*2}}function wG(){const[e,t]=x.useState(!1);return x.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),o=matchMedia("(color-gamut: p3)");t(r&&o.matches);const s=()=>t(r&&o.matches);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[]),K(Tt.forceSrgb)||!e?"srgb":"p3"}const mC=.35,yC=.82;class Rh extends Rr{constructor(){super(...arguments);m(this,"hideResizeHandles",n=>Fd(n));m(this,"hideRotateHandle",n=>Fd(n));m(this,"hideSelectionBoundsFg",n=>Fd(n));m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r,i=[];for(const a of n.props.segments)i.push({...a,points:a.points.map(({x:l,y:c,z:u})=>({x:o*l,y:s*c,z:u}))});return{props:{segments:i}}})}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1}}getGeometry(n){const r=ia(n);if(Fd(n))return new ox({x:-r/2,y:-r/2,radius:r/2,isFilled:!0});const{strokePoints:o,sw:s}=y$(n,r,!0),i=nv({strokeWidth:s,showAsComplete:!0});return Vf(o,i),new bt({points:Ex(o,i),isFilled:!0})}component(n){return h.jsx(Ds,{id:n.id,style:{opacity:mC},children:h.jsx(Ld,{strokeWidth:ia(n),shape:n})})}backgroundComponent(n){return h.jsx(Ds,{id:n.id,style:{opacity:yC},children:h.jsx(Ld,{strokeWidth:ia(n),shape:n})})}indicator(n){var d;const r=au(),o=ia(n),s=lu(n.props.segments);let i=o;!r&&!n.props.isPen&&s.length===1&&(i+=Us(n.id)()*(o/6));const a=n.props.isComplete||((d=Vn(n.props.segments))==null?void 0:d.type)==="straight",l=nv({strokeWidth:o,showAsComplete:a}),c=ao(s,l);let u;return c.length<2?u=PG(s[0],i):u=$i(c,!1),h.jsx("path",{d:u})}toSvg(n){return h.jsx(Ld,{strokeWidth:ia(n),shape:n,opacity:mC})}toBackgroundSvg(n){return h.jsx(Ld,{strokeWidth:ia(n),shape:n,opacity:yC})}}m(Rh,"type","highlight"),m(Rh,"props",SE),m(Rh,"migrations",vE);function bG(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 PG(e,t){const n=t/2;return`M ${e.x} ${e.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function y$(e,t,n){var l;const r=lu(e.props.segments),o=e.props.isComplete||((l=Vn(e.props.segments))==null?void 0:l.type)==="straight";let s=t;!n&&!e.props.isPen&&r.length===1&&(s+=Us(e.id)()*(t/6));const i=nv({strokeWidth:s,showAsComplete:o});return{strokePoints:ao(r,i),sw:s}}function CG(e,t,n){const{strokePoints:r,sw:o}=y$(e,t,n);return{solidStrokePath:r.length>1?$i(r,!1):bG(e.props.segments[0].points[0]),sw:o}}function Ld({strokeWidth:e,shape:t,opacity:n}){const r=wt(),o=au(),{solidStrokePath:s,sw:i}=CG(t,e,o),a=wG(),l=r[t.props.color].highlight[a];return h.jsx("path",{d:s,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:l,strokeWidth:i,opacity:n})}function ia(e){return rl[e.props.size]*1.12}function Fd(e){return e.props.segments.length===1&&e.props.segments[0].points.length<2}function S$(){return h.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[h.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),h.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),h.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function v$(){const[e,t]=x.useState(!1);return x.useEffect(()=>{const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{t(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}async function IG(e){const n=await(await fetch(e)).blob();return Aa.blobToDataUrl(n)}class Lh extends Sl{constructor(){super(...arguments);m(this,"isAspectRatioLocked",()=>!0);m(this,"canCrop",()=>!0);m(this,"onDoubleClick",n=>{const r=n.props.assetId?this.editor.getAsset(n.props.assetId):void 0;!r||!(r.props.src&&"mimeType"in r.props&&r.props.mimeType==="image/gif")||this.editor.updateShapes([{type:"image",id:n.id,props:{playing:!n.props.playing}}])});m(this,"onDoubleClickEdge",n=>{const r=n.props;if(!r||this.editor.getCroppingShapeId()!==n.id)return;const o=vt(r.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},s=1/(o.bottomRight.x-o.topLeft.x)*n.props.w,i=1/(o.bottomRight.y-o.topLeft.y)*n.props.h,a=new b(o.topLeft.x*s,o.topLeft.y*i).rot(n.rotation),l={id:n.id,type:n.type,x:n.x-a.x,y:n.y-a.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:i}};this.editor.updateShapes([l])})}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null}}component(n){var p,f;const r=this.editor.getCroppingShapeId()===n.id,o=v$(),[s,i]=x.useState(""),a=n.props.assetId?this.editor.getAsset(n.props.assetId):void 0,l=n.id===this.editor.getOnlySelectedShapeId();if(x.useEffect(()=>{if(a!=null&&a.props.src&&"mimeType"in a.props&&(a==null?void 0:a.props.mimeType)==="image/gif"){let y=!1;const g=a.props.src;if(!g)return;const w=new Image;return w.onload=()=>{if(y)return;const S=document.createElement("canvas");S.width=w.width,S.height=w.height;const v=S.getContext("2d");v&&(v.drawImage(w,0,0),i(S.toDataURL()))},w.crossOrigin="anonymous",w.src=g,()=>{y=!0}}},[o,a==null?void 0:a.props]),(a==null?void 0:a.type)==="bookmark")throw Error("Bookmark assets can't be rendered as images");const c=l&&r&&this.editor.isInAny("select.crop","select.cropping","select.pointing_crop_handle"),u=o&&(((p=a==null?void 0:a.props.mimeType)==null?void 0:p.includes("video"))||((f=a==null?void 0:a.props.mimeType)==null?void 0:f.includes("gif"))),d=SC(n);return a!=null&&a.props.src?h.jsxs(h.Fragment,{children:[c&&h.jsx("div",{style:d,children:h.jsx("div",{className:"tl-image",style:{opacity:.1,backgroundImage:`url(${!n.props.playing||u?s:a.props.src})`},draggable:!1})}),h.jsxs(Ti,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h},children:[h.jsxs("div",{className:"tl-image-container",style:d,children:[h.jsx("div",{className:"tl-image",style:{backgroundImage:`url(${!n.props.playing||u?s:a.props.src})`},draggable:!1}),a.props.isAnimated&&!n.props.playing&&h.jsx("div",{className:"tl-image__tg",children:"GIF"})]}),")",n.props.url&&h.jsx(sl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})]}):h.jsxs(Ti,{id:n.id,style:{overflow:"hidden",width:n.props.w,height:n.props.h,color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:[h.jsx("div",{className:"tl-image-container",style:d,children:a?null:h.jsx(S$,{})}),")","url"in n.props&&n.props.url&&h.jsx(sl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){return this.editor.getCroppingShapeId()===n.id?null:h.jsx("rect",{width:O(n.props.w),height:O(n.props.h)})}async toSvg(n){const r=n.props.assetId?this.editor.getAsset(n.props.assetId):null;if(!r)return null;let o=(r==null?void 0:r.props.src)||"";(o.startsWith("http")||o.startsWith("/")||o.startsWith("./"))&&(o=await IG(o)||"");const s=SC(n),i=n.props.crop;if(s.transform&&i){const{transform:a,width:l,height:c}=s,u=(i.bottomRight.x-i.topLeft.x)*l,d=(i.bottomRight.y-i.topLeft.y)*c,p=[new b(0,0),new b(u,0),new b(u,d),new b(0,d)],f=`cropClipPath_${n.id.replace(":","_")}`;return h.jsxs(h.Fragment,{children:[h.jsx("defs",{children:h.jsx("clipPath",{id:f,children:h.jsx("polygon",{points:p.map(y=>`${y.x},${y.y}`).join(" ")})})}),h.jsx("g",{clipPath:"url(#{cropClipId})",children:h.jsx("image",{href:o,width:l,height:c,style:{transform:a}})})]})}else return h.jsx("image",{href:o,width:n.props.w,height:n.props.h})}}m(Lh,"type","image"),m(Lh,"props",xE),m(Lh,"migrations",wE);function SC(e){const t=e.props.crop,n=t==null?void 0:t.topLeft;if(!n)return{width:e.props.w,height:e.props.h};const r=1/(t.bottomRight.x-t.topLeft.x)*e.props.w,o=1/(t.bottomRight.y-t.topLeft.y)*e.props.h,s=-n.x*r,i=-n.y*o;return{transform:`translate(${s}px, ${i}px)`,width:r,height:o}}function x$(e,t){const{start:n,end:r}=e;return t?`M${O(n.x)},${O(n.y)} L${O(r.x)},${O(r.y)} `:`${O(r.x)},${O(r.y)} `}function w$(e,t){const{a:n,b:r,c:o,d:s}=e;return b.Equals(n,s)?"":`${t?`M${O(n.x)},${O(n.y)}`:""}C${O(r.x)},${O(r.y)} ${O(o.x)},${O(o.y)} ${O(s.x)},${O(s.y)}`}function EG(e,t){let n=e.segments.reduce((r,o,s)=>r+w$(o,s===0),"");return t&&(n+="Z"),n}function _G(e,t){let n=e.segments.reduce((r,o,s)=>r+x$(o,s===0),"");return t&&(n+="Z"),n}function b$(e,t=!1){return e instanceof Bi?_G(e,t):EG(e,t)}function P$(e){return{size:e,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function C$(e,t,n){const r=t.vertices,o=P$(n);return ao(r,o)}function kG(e,t,n){const r=P$(n);return Ex(Vf(C$(e,t,n),r),r)}function TG(e,t,n){const r=kG(e,t,n);return t0(r)}function $G(e,t,n){if(e.props.dash==="draw"){const r=C$(e,t,n);return $i(r)}return b$(t)}const MG=new jf;class Fh extends Rr{constructor(){super(...arguments);m(this,"hideResizeHandles",()=>!0);m(this,"hideRotateHandle",()=>!0);m(this,"hideSelectionBoundsFg",()=>!0);m(this,"hideSelectionBoundsBg",()=>!0);m(this,"onResize",(n,r)=>{const{scaleX:o,scaleY:s}=r;return{props:{points:np(n.props.points,(i,{id:a,index:l,x:c,y:u})=>({id:a,index:l,x:c*o,y:u*s}))}}});m(this,"onHandleDrag",(n,{handle:r})=>{if(r.type==="vertex")return{...n,props:{...n.props,points:{...n.props.points,[r.id]:{id:r.id,index:r.index,x:r.x,y:r.y}}}}})}getDefaultProps(){const[n,r]=Ac(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[n]:{id:n,index:n,x:0,y:0},[r]:{id:r,index:r,x:.1,y:.1}}}}getGeometry(n){return hc(n)}getHandles(n){return MG.get(n.props,()=>{const r=hc(n),o=av(n),s=o.map(i=>({...i,id:i.index,type:"vertex",canSnap:!0}));for(let i=0;i<o.length-1;i++){const a=fc(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(Lt)})}component(n){return h.jsx(Ds,{id:n.id,children:h.jsx(vC,{shape:n})})}indicator(n){const r=$t[n.props.size],o=hc(n),{dash:s}=n.props;let i;if(n.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]=p$(n.id,a,r);i=l}}else i=$G(n,o,r);return h.jsx("path",{d:i})}toSvg(n){return h.jsx(vC,{shape:n})}getHandleSnapGeometry(n){const r=av(n);return{points:r,getSelfSnapPoints:o=>{const s=this.getHandles(n).filter(i=>i.type==="vertex").findIndex(i=>i.id===o.id);return r.filter((i,a)=>Math.abs(a-s)>1).map(b.From)},getSelfSnapOutline:o=>{const s=this.getHandles(n).filter(a=>a.type==="vertex").findIndex(a=>a.id===o.id),i=hc(n).segments.filter((a,l)=>l!==s-1&&l!==s);return i.length?new Fr({children:i}):null}}}}m(Fh,"type","line"),m(Fh,"props",bE),m(Fh,"migrations",PE);function av(e){return Object.values(e.props.points).sort(Lt)}function hc(e){const t=av(e).map(b.From);switch(e.props.spline){case"cubic":return new s8({points:t});case"line":return new Bi({points:t})}}function vC({shape:e}){const t=wt(),n=hc(e),r=$t[e.props.size],{dash:o,color:s}=e.props;if(e.props.spline==="line"){if(o==="solid"){const i=n.points,a="M"+i[0]+"L"+i.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:"none",color:s,theme:t}),h.jsx("path",{d:a,stroke:t[s].solid,strokeWidth:r,fill:"none"})]})}if(o==="dashed"||o==="dotted"){const i=n.points,a="M"+i[0]+"L"+i.slice(1);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:"none",color:s,theme:t}),h.jsx("g",{stroke:t[s].solid,strokeWidth:r,children:n.segments.map((l,c)=>{const{strokeDasharray:u,strokeDashoffset:d}=Ko(l.length,r,{style:o,start:c>0?"outset":"none",end:c<n.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:u,strokeDashoffset:d,d:x$(l,!0),fill:"none"},c)})})]})}if(o==="draw"){const i=n.points,[a,l]=p$(e.id,i,r);return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:a,fill:"none",color:s,theme:t}),h.jsx("path",{d:l,stroke:t[s].solid,strokeWidth:r,fill:"none"})]})}}if(e.props.spline==="cubic"){const i=b$(n);if(o==="solid")return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:i,fill:"none",color:s,theme:t}),h.jsx("path",{strokeWidth:r,stroke:t[s].solid,fill:"none",d:i})]});if(o==="dashed"||o==="dotted")return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:i,fill:"none",color:s,theme:t}),h.jsx("g",{stroke:t[s].solid,strokeWidth:r,children:n.segments.map((a,l)=>{const{strokeDasharray:c,strokeDashoffset:u}=Ko(a.length,r,{style:o,start:l>0?"outset":"none",end:l<n.segments.length-1?"outset":"none"});return h.jsx("path",{strokeDasharray:c,strokeDashoffset:u,d:w$(a,!0),fill:"none"},l)})})]});if(o==="draw")return h.jsxs(h.Fragment,{children:[h.jsx(Pt,{d:i,fill:"none",color:s,theme:t}),h.jsx("path",{d:TG(e,n,r),strokeWidth:1,stroke:t[s].solid,fill:t[s].solid})]})}}const I$=x.createContext(null);function AG({assetUrls:e,children:t}){return h.jsx(I$.Provider,{value:e,children:t})}function Ox(){const e=x.useContext(I$);if(!e)throw new Error("useAssetUrls must be used within an AssetUrlsProvider");return e}const lv={"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.group":"Group","action.insert-embed":"Insert embed","action.insert-media":"Upload media","action.leave-shared-project":"Leave shared project","action.new-project":"New project","action.new-shared-project":"New shared project","action.open-cursor-chat":"Cursor chat","action.open-file":"Open file","action.pack":"Pack","action.paste":"Paste","action.print":"Print","action.redo":"Redo","action.remove-frame":"Remove frame","action.rename":"Rename","action.rotate-ccw":"Rotate counterclockwise","action.rotate-cw":"Rotate clockwise","action.save-copy":"Save a copy","action.select-all":"Select all","action.select-none":"Select none","action.send-backward":"Send backward","action.send-to-back":"Send to back","action.share-project":"Share this project","action.stack-horizontal":"Stack horizontally","action.stack-vertical":"Stack vertically","action.stack-horizontal.short":"Stack H","action.stack-vertical.short":"Stack V","action.stop-following":"Stop following","action.stretch-horizontal":"Stretch horizontally","action.stretch-vertical":"Stretch vertically","action.stretch-horizontal.short":"Stretch H","action.stretch-vertical.short":"Stretch V","action.toggle-auto-size":"Toggle auto size","action.toggle-dark-mode.menu":"Dark mode","action.toggle-dark-mode":"Toggle dark mode","action.toggle-wrap-mode.menu":"Select on wrap","action.toggle-wrap-mode":"Toggle Select on wrap","action.toggle-reduce-motion.menu":"Reduce motion","action.toggle-reduce-motion":"Toggle reduce motion","action.toggle-edge-scrolling.menu":"Edge scrolling","action.toggle-edge-scrolling":"Toggle edge scrolling","action.toggle-debug-mode.menu":"Debug mode","action.toggle-debug-mode":"Toggle debug mode","action.toggle-focus-mode.menu":"Focus mode","action.toggle-focus-mode":"Toggle focus mode","action.toggle-grid.menu":"Show grid","action.toggle-grid":"Toggle grid","action.toggle-lock":"Toggle locked","action.toggle-snap-mode.menu":"Always snap","action.toggle-snap-mode":"Toggle always snap","action.toggle-tool-lock.menu":"Tool lock","action.toggle-tool-lock":"Toggle tool lock","action.toggle-transparent.context-menu":"Transparent","action.toggle-transparent.menu":"Transparent","action.toggle-transparent":"Toggle transparent background","action.undo":"Undo","action.ungroup":"Ungroup","action.zoom-in":"Zoom in","action.zoom-out":"Zoom out","action.zoom-to-100":"Zoom to 100%","action.zoom-to-fit":"Zoom to fit","action.zoom-to-selection":"Zoom to selection","assets.files.upload-failed":"Upload failed","assets.url.failed":"Couldn't load URL preview","color-style.white":"White","color-style.black":"Black","color-style.blue":"Blue","color-style.green":"Green","color-style.grey":"Grey","color-style.light-blue":"Light blue","color-style.light-green":"Light green","color-style.light-red":"Light red","color-style.light-violet":"Light violet","color-style.orange":"Orange","color-style.red":"Red","color-style.violet":"Violet","color-style.yellow":"Yellow","fill-style.none":"None","document.default-name":"Untitled","fill-style.semi":"Semi","fill-style.solid":"Solid","fill-style.pattern":"Pattern","dash-style.dashed":"Dashed","dash-style.dotted":"Dotted","dash-style.draw":"Draw","dash-style.solid":"Solid","size-style.s":"Small","size-style.m":"Medium","size-style.l":"Large","size-style.xl":"Extra large","opacity-style.0.1":"10%","opacity-style.0.25":"25%","opacity-style.0.5":"50%","opacity-style.0.75":"75%","opacity-style.1":"100%","font-style.draw":"Draw","font-style.sans":"Sans","font-style.serif":"Serif","font-style.mono":"Mono","align-style.start":"Start","align-style.middle":"Middle","align-style.end":"End","align-style.justify":"Justify","verticalAlign-style.start":"Top","verticalAlign-style.middle":"Middle","verticalAlign-style.end":"Bottom","geo-style.arrow-down":"Arrow down","geo-style.arrow-left":"Arrow left","geo-style.arrow-right":"Arrow right","geo-style.arrow-up":"Arrow up","geo-style.diamond":"Diamond","geo-style.ellipse":"Ellipse","geo-style.hexagon":"Hexagon","geo-style.octagon":"Octagon","geo-style.oval":"Oval","geo-style.cloud":"Cloud","geo-style.pentagon":"Pentagon","geo-style.rectangle":"Rectangle","geo-style.rhombus-2":"Rhombus 2","geo-style.rhombus":"Rhombus","geo-style.star":"Star","geo-style.trapezoid":"Trapezoid","geo-style.triangle":"Triangle","geo-style.x-box":"X box","geo-style.check-box":"Check box","arrowheadStart-style.none":"None","arrowheadStart-style.arrow":"Arrow","arrowheadStart-style.bar":"Bar","arrowheadStart-style.diamond":"Diamond","arrowheadStart-style.dot":"Dot","arrowheadStart-style.inverted":"Inverted","arrowheadStart-style.pipe":"Pipe","arrowheadStart-style.square":"Square","arrowheadStart-style.triangle":"Triangle","arrowheadEnd-style.none":"None","arrowheadEnd-style.arrow":"Arrow","arrowheadEnd-style.bar":"Bar","arrowheadEnd-style.diamond":"Diamond","arrowheadEnd-style.dot":"Dot","arrowheadEnd-style.inverted":"Inverted","arrowheadEnd-style.pipe":"Pipe","arrowheadEnd-style.square":"Square","arrowheadEnd-style.triangle":"Triangle","spline-style.line":"Line","spline-style.cubic":"Cubic","tool.select":"Select","tool.hand":"Hand","tool.draw":"Draw","tool.eraser":"Eraser","tool.arrow-down":"Arrow down","tool.arrow-left":"Arrow left","tool.arrow-right":"Arrow right","tool.arrow-up":"Arrow up","tool.arrow":"Arrow","tool.cloud":"Cloud","tool.diamond":"Diamond","tool.ellipse":"Ellipse","tool.hexagon":"Hexagon","tool.highlight":"Highlight","tool.line":"Line","tool.octagon":"Octagon","tool.oval":"Oval","tool.pentagon":"Pentagon","tool.rectangle":"Rectangle","tool.rhombus":"Rhombus","tool.star":"Star","tool.trapezoid":"Trapezoid","tool.triangle":"Triangle","tool.x-box":"X box","tool.check-box":"Check box","tool.asset":"Asset","tool.frame":"Frame","tool.note":"Note","tool.laser":"Laser","tool.embed":"Embed","tool.text":"Text","menu.title":"Menu","menu.copy-as":"Copy as","menu.edit":"Edit","menu.export-as":"Export as","menu.file":"File","menu.language":"Language","menu.preferences":"Preferences","menu.view":"View","context-menu.arrange":"Arrange","context-menu.copy-as":"Copy as","context-menu.export-as":"Export as","context-menu.export-all-as":"Export","context-menu.move-to-page":"Move to page","context-menu.reorder":"Reorder","page-menu.title":"Pages","page-menu.create-new-page":"Create new page","page-menu.max-page-count-reached":"Max pages reached","page-menu.new-page-initial-name":"Page 1","page-menu.edit-start":"Edit","page-menu.edit-done":"Done","page-menu.go-to-page":"Go to page","page-menu.submenu.rename":"Rename","page-menu.submenu.duplicate-page":"Duplicate","page-menu.submenu.title":"Menu","page-menu.submenu.move-down":"Move down","page-menu.submenu.move-up":"Move up","page-menu.submenu.delete":"Delete","share-menu.title":"Share","share-menu.save-note":"Download this project to your computer as a .tldr file.","share-menu.fork-note":"Create a new shared project based on this snapshot.","share-menu.share-project":"Share this project","share-menu.default-project-name":"Shared Project","share-menu.copy-link":"Copy share link","share-menu.readonly-link":"Read-only","share-menu.create-snapshot-link":"Copy snapshot link","share-menu.snapshot-link-note":"Capture and share this project as a read-only snapshot link.","share-menu.copy-readonly-link":"Copy read-only link","share-menu.offline-note":"Create a new shared project based on your current project.","share-menu.copy-link-note":"Anyone with the link will be able to view and edit this project.","share-menu.copy-readonly-link-note":"Anyone with the link will be able to view (but not edit) this project.","share-menu.project-too-large":"Sorry, this project can't be shared because it's too large. We're working on it!","share-menu.upload-failed":"Sorry, we couldn't upload your project at the moment. Please try again or let us know if the problem persists.","status.offline":"Offline","status.online":"Online","people-menu.title":"People","people-menu.change-name":"Change name","people-menu.change-color":"Change color","people-menu.follow":"Following","people-menu.following":"Following","people-menu.leading":"Following You","people-menu.user":"(You)","people-menu.invite":"Invite others","help-menu.title":"Help and resources","help-menu.about":"About","help-menu.discord":"Discord","help-menu.github":"GitHub","help-menu.keyboard-shortcuts":"Keyboard shortcuts","help-menu.twitter":"Twitter","actions-menu.title":"Actions","edit-link-dialog.title":"Edit link","edit-link-dialog.invalid-url":"A link must be a valid URL.","edit-link-dialog.detail":"Links will open in a new tab.","edit-link-dialog.url":"URL","edit-link-dialog.clear":"Clear","edit-link-dialog.save":"Continue","edit-link-dialog.cancel":"Cancel","embed-dialog.title":"Insert embed","embed-dialog.back":"Back","embed-dialog.create":"Create","embed-dialog.cancel":"Cancel","embed-dialog.url":"URL","embed-dialog.instruction":"Paste in the site's URL to create the embed.","embed-dialog.invalid-url":"We could not create an embed from that URL.","edit-pages-dialog.move-down":"Move down","edit-pages-dialog.move-up":"Move up","shortcuts-dialog.title":"Keyboard shortcuts","shortcuts-dialog.edit":"Edit","shortcuts-dialog.file":"File","shortcuts-dialog.preferences":"Preferences","shortcuts-dialog.tools":"Tools","shortcuts-dialog.transform":"Transform","shortcuts-dialog.view":"View","shortcuts-dialog.collaboration":"Collaboration","home-project-dialog.title":"Home project","home-project-dialog.description":"This is your local home project. It's just for you!","rename-project-dialog.title":"Rename project","rename-project-dialog.cancel":"Cancel","rename-project-dialog.rename":"Rename","home-project-dialog.ok":"Ok","style-panel.title":"Styles","style-panel.align":"Align","style-panel.vertical-align":"Vertical align","style-panel.position":"Position","style-panel.arrowheads":"Arrows","style-panel.arrowhead-start":"Start","style-panel.arrowhead-end":"End","style-panel.color":"Color","style-panel.dash":"Dash","style-panel.fill":"Fill","style-panel.font":"Font","style-panel.geo":"Shape","style-panel.mixed":"Mixed","style-panel.opacity":"Opacity","style-panel.size":"Size","style-panel.spline":"Spline","tool-panel.drawing":"Drawing","tool-panel.shapes":"Shapes","tool-panel.more":"More","debug-panel.more":"More","navigation-zone.toggle-minimap":"Toggle minimap","navigation-zone.zoom":"Zoom","focus-mode.toggle-focus-mode":"Toggle focus mode","toast.close":"Close","file-system.file-open-error.title":"Could not open file","file-system.file-open-error.not-a-tldraw-file":"The file you tried to open doesn't look like a tldraw file.","file-system.file-open-error.file-format-version-too-new":"The file you tried to open is from a newer version of tldraw. Please reload the page and try again.","file-system.file-open-error.generic-corrupted-file":"The file you tried to open is corrupted.","file-system.confirm-open.title":"Overwrite current project?","file-system.confirm-open.description":"Opening a file will replace your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-open.cancel":"Cancel","file-system.confirm-open.open":"Open file","file-system.confirm-open.dont-show-again":"Don't ask again","file-system.confirm-clear.title":"Clear current project?","file-system.confirm-clear.description":"Creating a new project will clear your current project and any unsaved changes will be lost. Are you sure you want to continue?","file-system.confirm-clear.cancel":"Cancel","file-system.confirm-clear.continue":"Continue","file-system.confirm-clear.dont-show-again":"Don't ask again","file-system.shared-document-file-open-error.title":"Could not open file","file-system.shared-document-file-open-error.description":"Opening files from shared projects is not supported.","sharing.confirm-leave.title":"Leave current project?","sharing.confirm-leave.description":"Are you sure you want to leave this shared project? You can return to it by navigating to its URL.","sharing.confirm-leave.cancel":"Cancel","sharing.confirm-leave.leave":"Leave","sharing.confirm-leave.dont-show-again":"Don't ask again","toast.error.export-fail.title":"Failed export","toast.error.export-fail.desc":"Failed to export image","toast.error.copy-fail.title":"Failed copy","toast.error.copy-fail.desc":"Failed to copy image","context.pages.new-page":"New page","vscode.file-open.desc":"We've updated this document to work with the current version of tldraw. If you'd like to keep the original version (which will work on old.tldraw.com), click below to create a backup.","vscode.file-open.open":"Continue","vscode.file-open.backup":"Backup","vscode.file-open.backup-saved":"Backup saved","vscode.file-open.backup-failed":"Backup failed: this is not a .tldr file.","vscode.file-open.dont-show-again":"Don't ask again","cursor-chat.type-to-chat":"Type to chat..."},jG=new Set(["ar","fa","he","ur","ku"]),aa={locale:"en",label:"English",messages:lv,dir:"ltr"};async function OG(e,t){if(!(await fetch(t.translations.en)).ok)return console.warn("No main translations found."),aa;if(e==="en")return aa;const r=Rc.find(a=>a.locale===e);if(!r)return console.warn(`No translation found for locale ${e}`),aa;const s=await(await fetch(t.translations[r.locale])).json();if(!s)return console.warn(`No messages found for locale ${e}`),aa;const i=[];for(const a in aa.messages)s[a]||i.push(a);return i.length>0,{locale:e,label:r.label,dir:jG.has(r.locale)?"rtl":"ltr",messages:{...aa.messages,...s}}}const E$=x.createContext({}),_$=()=>x.useContext(E$),DG=tr(function({overrides:t,children:n}){const o=z().user.getLocale(),s=Ox(),[i,a]=x.useState(()=>t&&t.en?{locale:"en",label:"English",dir:"ltr",messages:{...lv,...t.en}}:{locale:"en",label:"English",dir:"ltr",messages:lv});return x.useEffect(()=>{let l=!1;async function c(){const u=await OG(o,s);u&&!l&&(t&&t[o]?a({...u,messages:{...u.messages,...t[o]}}):a(u))}return c(),()=>{l=!0}},[s,o,t]),h.jsx(E$.Provider,{value:i,children:n})});function _e(){const e=_$();return x.useCallback(function(n){return e.messages[n]??n},[e])}class Nh extends Rr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"hideResizeHandles",()=>!0);m(this,"hideSelectionBoundsFg",()=>!1);m(this,"onBeforeCreate",n=>xC(this.editor,n));m(this,"onBeforeUpdate",(n,r)=>{if(!(n.props.text===r.props.text&&n.props.font===r.props.font&&n.props.size===r.props.size))return xC(this.editor,r)});m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n;s.trimEnd()!==n.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:""}}getGeometry(n){const r=Nd(n),{labelHeight:o,labelWidth:s}=k$(this.editor,n);return new Fr({children:[new Ho({width:$e,height:r,isFilled:!0}),new Ho({x:n.props.align==="start"?0:n.props.align==="end"?$e-s:($e-s)/2,y:n.props.verticalAlign==="start"?0:n.props.verticalAlign==="end"?r-o:(r-o)/2,width:s,height:o,isFilled:!0,isLabel:!0})]})}getHandles(n){const r=this.editor.getZoomLevel(),o=nW/r,s=Nd(n);return r<.25?[]:[{id:"top",index:"a1",type:"clone",x:$e/2,y:-o},{id:"right",index:"a2",type:"clone",x:$e+o,y:s/2},{id:"bottom",index:"a3",type:"clone",x:$e/2,y:s+o},{id:"left",index:"a4",type:"clone",x:-o,y:s/2}]}component(n){const{id:r,type:o,props:{color:s,font:i,size:a,align:l,text:c,verticalAlign:u,fontSizeAdjustment:d}}=n,p=FG(r),f=wt(),y=Nd(n),g=K("shape rotation",()=>{var v;return((v=this.editor.getShapePageTransform(r))==null?void 0:v.rotation())??0},[this.editor]),w=au(),S=n.id===this.editor.getOnlySelectedShapeId();return h.jsxs(h.Fragment,{children:[h.jsx("div",{id:r,className:"tl-note__container",style:{width:$e,height:y,backgroundColor:f[s].note.fill,borderBottom:w?"3px solid rgb(15, 23, 31, .2)":"none",boxShadow:w?"none":NG(n.id,g)},children:h.jsx(Gf,{id:r,type:o,font:i,fontSize:d||Do[a],lineHeight:Ut.lineHeight,align:l,verticalAlign:u,text:c,isNote:!0,isSelected:S,labelColor:f[s].note.text,disableTab:!0,wrap:!0,onKeyDown:p})}),"url"in n.props&&n.props.url&&h.jsx(sl,{url:n.props.url,zoomLevel:this.editor.getZoomLevel()})]})}indicator(n){return h.jsx("rect",{rx:"1",width:O($e),height:O(Nd(n))})}toSvg(n,r){r.addExportDef(ol(n.props.font)),n.props.text&&r.addExportDef(ol(n.props.font));const o=qo({isDarkMode:r.isDarkMode}),s=this.editor.getShapeGeometry(n).bounds;return h.jsxs(h.Fragment,{children:[h.jsx("rect",{x:5,y:5,rx:1,width:$e-10,height:s.h,fill:"rgba(0,0,0,.1)"}),h.jsx("rect",{rx:1,width:$e,height:s.h,fill:o[n.props.color].note.fill}),h.jsx(Wf,{fontSize:n.props.fontSizeAdjustment||Do[n.props.size],font:n.props.font,align:n.props.align,verticalAlign:n.props.verticalAlign,text:n.props.text,labelColor:o[n.props.color].note.text,bounds:s,stroke:!1})]})}}m(Nh,"type","note"),m(Nh,"props",CE),m(Nh,"migrations",IE);function xC(e,t){const{labelHeight:n,fontSizeAdjustment:r}=k$(e,t),o=Math.max(0,n-$e);if(o!==t.props.growY||r!==t.props.fontSizeAdjustment)return{...t,props:{...t.props,growY:o,fontSizeAdjustment:r}}}function RG(e,t){const n=t.props.text;if(!n)return{labelHeight:Do[t.props.size]*Ut.lineHeight+kr*2,labelWidth:100,fontSizeAdjustment:0};const r=Do[t.props.size];let o=0,s=0,i=$e,a=$e;do{o=Math.min(r,r-s);const l=e.textMeasure.measureText(n,{...Ut,fontFamily:oo[t.props.font],fontSize:o,maxWidth:$e-kr*2,disableOverflowWrapBreaking:!0});if(i=l.h+kr*2,a=l.w+kr*2,o<=14){const c=e.textMeasure.measureText(n,{...Ut,fontFamily:oo[t.props.font],fontSize:o,maxWidth:$e-kr*2});i=c.h+kr*2,a=c.w+kr*2;break}if(l.scrollWidth.toFixed(0)===l.w.toFixed(0))break}while(s++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:o}}const LG=new jf;function k$(e,t){return LG.get(t,()=>RG(e,t))}function FG(e){const t=z(),n=_$();return x.useCallback(r=>{const o=t.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=t.getShapePageTransform(e),l=a.rotation(),c=!!(n.dir==="rtl"||q2(o.props.text)),u=$e+mi+(i&&!r.shiftKey?o.props.growY:0),d=new b(s?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(kx).rot(l).add(a.point()),p=o$(t,o,d,l);p&&(t.mark("editing adjacent shape"),Qp(t,p,!0))}},[e,t,n.dir])}function Nd(e){return $e+e.props.growY}function NG(e,t){const n=Us(e),r=Math.abs(n())+.5,o=Math.cos(t);return`0px ${5-r}px 5px -5px rgba(15, 23, 31, .6),
176
- 0px ${(4+r*7)*Math.max(0,o)}px ${6+r*7}px -${4+r*6}px rgba(15, 23, 31, ${(.3+r*.1).toFixed(2)}),
177
- 0px 48px 10px -10px inset rgba(15, 23, 44, ${((.022+n()*.005)*((1+o)/2)).toFixed(2)})`}function zG(e,{initialBounds:t,scaleX:n,scaleY:r,newPoint:o}){const s=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new b(0,0);n<0&&(i.x=-(t.width*s)),r<0&&(i.y=-(t.height*s));const{x:a,y:l}=b.Add(o,i.rot(e.rotation));return{x:a,y:l,props:{scale:s*e.props.scale}}}const BG=new jf;class zh extends Rr{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0);m(this,"onResize",(n,r)=>{const{initialBounds:o,initialShape:s,scaleX:i,handle:a}=r;if(r.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:n.id,type:n.type,...zG(n,r)};{const l=o.width;let c=l*i;const u=new b(0,0);c=Math.max(1,Math.abs(c)),a==="left"?(u.x=l-c,i<0&&(u.x+=c)):i<0&&(u.x-=c);const{x:d,y:p}=u.rot(n.rotation).add(s);return{id:n.id,type:n.type,x:d,y:p,props:{w:c/s.props.scale,autoSize:!1}}}});m(this,"onBeforeCreate",n=>{if(!n.props.autoSize||n.props.text.trim())return;const r=this.getMinDimensions(n);return{...n,x:n.x-r.width/2,y:n.y-r.height/2}});m(this,"onEditEnd",n=>{const{id:r,type:o,props:{text:s}}=n,i=n.props.text.trimEnd();i.length===0?this.editor.deleteShapes([n.id]):i!==n.props.text&&this.editor.updateShapes([{id:r,type:o,props:{text:s.trimEnd()}}])});m(this,"onBeforeUpdate",(n,r)=>{if(!r.props.autoSize)return;const o=n.props.size!==r.props.size||n.props.align!==r.props.align||n.props.font!==r.props.font||n.props.scale!==1&&r.props.scale===1,s=n.props.text!==r.props.text;if(!o&&!s)return;const i=this.getMinDimensions(n),a=wC(this.editor,r.props),l=i.width*n.props.scale,c=i.height*n.props.scale,u=a.width*r.props.scale,d=a.height*r.props.scale;let p;switch(r.props.align){case"middle":{p=new b((u-l)/2,s?0:(d-c)/2);break}case"end":{p=new b(u-l,s?0:(d-c)/2);break}default:{if(s)break;p=new b(0,(d-c)/2);break}}if(p){p.rot(r.rotation);const{x:f,y}=r;return{...r,x:f-p.x,y:y-p.y,props:{...r.props,w:u}}}else return{...r,props:{...r.props,w:u}}});m(this,"onDoubleClickEdge",n=>{if(!n.props.autoSize)return{id:n.id,type:n.type,props:{autoSize:!0}};if(n.props.scale!==1)return{id:n.id,type:n.type,props:{scale:1}}})}getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",align:"middle",autoSize:!0,scale:1}}getMinDimensions(n){return BG.get(n.props,r=>wC(this.editor,r))}getGeometry(n){const{scale:r}=n.props,{width:o,height:s}=this.getMinDimensions(n);return new Ho({width:o*r,height:s*r,isFilled:!0,isLabel:!0})}component(n){const{id:r,props:{font:o,size:s,text:i,color:a,scale:l,align:c}}=n,{width:u,height:d}=this.getMinDimensions(n),p=n.id===this.editor.getOnlySelectedShapeId(),f=wt();return h.jsx(Gf,{id:r,classNamePrefix:"tl-text-shape",type:"text",font:o,fontSize:rl[s],lineHeight:Ut.lineHeight,align:c,verticalAlign:"middle",text:i,labelColor:f[a].solid,isSelected:p,textWidth:u,textHeight:d,style:{transform:`scale(${l})`,transformOrigin:"top left"},wrap:!0})}indicator(n){const r=this.editor.getShapeGeometry(n).bounds,o=z();return n.props.autoSize&&o.getEditingShapeId()===n.id?null:h.jsx("rect",{width:O(r.width),height:O(r.height)})}toSvg(n,r){r.addExportDef(ol(n.props.font)),n.props.text&&r.addExportDef(ol(n.props.font));const o=this.editor.getShapeGeometry(n).bounds,s=o.width/(n.props.scale??1),i=o.height/(n.props.scale??1),a=qo(r);return h.jsx(Wf,{fontSize:rl[n.props.size],font:n.props.font,align:n.props.align,verticalAlign:"middle",text:n.props.text,labelColor:a[n.props.color].solid,bounds:new te(0,0,s,i),padding:0})}}m(zh,"type","text"),m(zh,"props",EE),m(zh,"migrations",_E);function wC(e,t){const{font:n,text:r,autoSize:o,size:s,w:i}=t,a=o?16:Math.max(16,i),l=rl[s],c=o?null:Math.floor(Math.max(a,i)),u=e.textMeasure.measureText(r,{...Ut,fontFamily:oo[n],fontSize:l,maxWidth:c});return o&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}class Bh extends Sl{constructor(){super(...arguments);m(this,"canEdit",()=>!0);m(this,"isAspectRatioLocked",()=>!0)}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(n){const{editor:r}=this,o=r.getShapeGeometry(n).bounds.w*r.getZoomLevel()>=110,s=n.props.assetId?r.getAsset(n.props.assetId):null,{time:i,playing:a}=n.props,l=Ff(n.id),c=v$(),u=x.useRef(null),d=x.useCallback(S=>{const v=S.currentTarget;v&&r.updateShapes([{type:"video",id:n.id,props:{playing:!0,time:v.currentTime}}])},[n.id,r]),p=x.useCallback(S=>{const v=S.currentTarget;v&&r.updateShapes([{type:"video",id:n.id,props:{playing:!1,time:v.currentTime}}])},[n.id,r]),f=x.useCallback(S=>{const v=S.currentTarget;v&&l&&r.updateShapes([{type:"video",id:n.id,props:{time:v.currentTime}}])},[l,n.id,r]),[y,g]=x.useState(!1),w=x.useCallback(S=>{const v=S.currentTarget;v&&(i!==v.currentTime&&(v.currentTime=i),a||v.pause(),g(!0))},[a,i]);return x.useEffect(()=>{const S=u.current;S&&(y&&!l&&i!==S.currentTime&&(S.currentTime=i),l&&document.activeElement!==S&&S.focus())},[l,y,i]),x.useEffect(()=>{if(c){const S=u.current;if(!S)return;S.pause(),S.currentTime=0}},[u,c]),h.jsxs(h.Fragment,{children:[h.jsx(Ti,{id:n.id,style:{color:"var(--color-text-3)",backgroundColor:s?"transparent":"var(--color-low)",border:s?"none":"1px solid var(--color-low-border)"},children:h.jsx("div",{className:"tl-counter-scaled",children:h.jsx("div",{className:"tl-video-container",children:s!=null&&s.props.src?h.jsx("video",{ref:u,style:l?{pointerEvents:"all"}:void 0,className:`tl-video tl-video-shape-${n.id.split(":")[1]}`,width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:l&&o,onPlay:d,onPause:p,onTimeUpdate:f,onLoadedData:w,hidden:!y,children:h.jsx("source",{src:s.props.src})}):h.jsx(S$,{})})})}),"url"in n.props&&n.props.url&&h.jsx(sl,{url:n.props.url,zoomLevel:r.getZoomLevel()})]})}indicator(n){return h.jsx("rect",{width:O(n.props.w),height:O(n.props.h)})}toSvg(n){return h.jsx("image",{href:UG(n.id),width:n.props.w,height:n.props.h})}}m(Bh,"type","video"),m(Bh,"props",kE),m(Bh,"migrations",TE);function UG(e){const t=e.split(":")[1],n=document.querySelector(`.tl-video-shape-${t}`);if(n){const r=document.createElement("canvas");return r.width=n.videoWidth,r.height=n.videoHeight,r.getContext("2d").drawImage(n,0,0),r.toDataURL("image/png")}else throw new Error("Video with not found when attempting serialization.")}const T$=[zh,Mh,Ah,Dh,Nh,Fh,Oh,$h,Rh,jh,Lh,Bh];function HG(e){return[e.sideEffects.registerAfterChangeHandler("instance",(t,n)=>{t.isFocused!==n.isFocused&&(n.isFocused?e.getContainer().focus():(e.complete(),e.getContainer().blur()))}),e.sideEffects.registerAfterChangeHandler("instance_page_state",(t,n)=>{if(t.croppingShapeId!==n.croppingShapeId){const r=e.isInAny("select.crop","select.pointing_crop_handle","select.cropping");!t.croppingShapeId&&n.croppingShapeId?r||e.setCurrentTool("select.crop.idle"):t.croppingShapeId&&!n.croppingShapeId&&r&&e.setCurrentTool("select.idle")}t.editingShapeId!==n.editingShapeId&&(!t.editingShapeId&&n.editingShapeId?e.isIn("select.editing_shape")||e.setCurrentTool("select.editing_shape"):t.editingShapeId&&!n.editingShapeId&&e.isIn("select.editing_shape")&&e.setCurrentTool("select.idle"))})]}class $$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"scribbleId","id");m(this,"markId","");m(this,"excludedShapeIds",new Set);m(this,"onEnter",n=>{this.markId="erase scribble begin",this.editor.mark(this.markId),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(s=>{if(this.editor.isShapeOrAncestorLocked(s))return!0;if(this.editor.isShapeOfType(s,"group")||this.editor.isShapeOfType(s,"frame")){const i=this.editor.getPointInShapeSpace(s,r);return this.editor.getShapeGeometry(s).bounds.containsPoint(i)}return!1}).map(s=>s.id));const o=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=o.id,this.update()});m(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}update(){const{editor:n,excludedShapeIds:r}=this,o=n.getErasingShapeIds(),s=n.getZoomLevel(),i=n.getCurrentPageShapes(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(o),u=Fo/s;for(const d of i){if(n.isShapeOfType(d,"group"))continue;const p=n.getShapeMask(d.id);if(p&&!Xn(a,p))continue;const f=n.getShapeGeometry(d),y=n.getShapePageTransform(d);if(!f||!y)continue;const g=y.clone().invert(),w=g.applyToPoint(l),S=g.applyToPoint(a),{bounds:v}=f;v.minX-u>Math.max(w.x,S.x)||v.minY-u>Math.max(w.y,S.y)||v.maxX+u<Math.min(w.x,S.x)||v.maxY+u<Math.min(w.y,S.y)||f.hitTestLineSegment(w,S,u)&&c.add(n.getOutermostSelectableShape(d).id)}this.editor.setErasingShapes([...c].filter(d=>!r.has(d)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),n.setErasingShapes([]),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.setErasingShapes([]),n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}m($$,"id","erasing");var vy;let KG=(vy=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(vy,"id","idle"),vy);var xy;let VG=(xy=class extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{const n=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:Fo/n})){const u=this.editor.getOutermostSelectableShape(c);if(this.editor.isShapeOfType(u,"frame")&&s.size>i)break;s.add(u.id)}}this.editor.setErasingShapes([...s])});m(this,"onLongPress",n=>{this.startErasing(n)});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startErasing(n)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.cancel()})}startErasing(n){this.parent.transition("erasing",n)}complete(){const n=this.editor.getErasingShapeIds();n.length&&(this.editor.mark("erase end"),this.editor.deleteShapes(n)),this.editor.setErasingShapes([]),this.parent.transition("idle")}cancel(){this.editor.setErasingShapes([]),this.parent.transition("idle")}},m(xy,"id","pointing"),xy);class Uh extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(Uh,"id","eraser"),m(Uh,"initial","idle"),m(Uh,"children",()=>[KG,VG,$$]);class M$ extends re{constructor(){super(...arguments);m(this,"initialCamera",new b);m(this,"onEnter",()=>{this.initialCamera=b.From(this.editor.getCamera()),this.update()});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.parent.transition("idle")});m(this,"onComplete",()=>{this.complete()})}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:o,originScreenPoint:s}=r.inputs,i=b.Sub(o,s).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,o=Math.min(r.len(),2);o>.1&&this.editor.slideCamera({speed:o,direction:r,friction:rh}),this.parent.transition("idle")}}m(M$,"id","dragging");var wy;let WG=(wy=class extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"grab",rotation:0})});m(this,"onPointerDown",n=>{this.parent.transition("pointing",n)});m(this,"onCancel",()=>{this.editor.setCurrentTool("select")})}},m(wy,"id","idle"),wy);var by;let GG=(by=class extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.stopCameraAnimation(),this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});m(this,"onLongPress",()=>{this.startDragging()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startDragging()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.complete()})}startDragging(){this.parent.transition("dragging")}complete(){this.parent.transition("idle")}},m(by,"id","pointing"),by);class Hh extends re{constructor(){super(...arguments);m(this,"onDoubleClick",n=>{if(n.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomIn(r,{duration:220,easing:nn.easeOutQuint})}});m(this,"onTripleClick",n=>{if(n.phase==="settle"){const{currentScreenPoint:r}=this.editor.inputs;this.editor.zoomOut(r,{duration:320,easing:nn.easeOutQuint})}});m(this,"onQuadrupleClick",n=>{if(n.phase==="settle"){const r=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:o}}=this.editor;r===1?this.editor.zoomToFit({duration:400,easing:nn.easeOutQuint}):this.editor.resetZoom(o,{duration:320,easing:nn.easeOutQuint})}})}}m(Hh,"id","hand"),m(Hh,"initial","idle"),m(Hh,"children",()=>[WG,GG,M$]);var Py;let YG=(Py=class extends re{constructor(){super(...arguments);m(this,"onPointerDown",n=>{this.parent.transition("lasering",n)})}},m(Py,"id","idle"),Py);class A$ extends re{constructor(){super(...arguments);m(this,"scribbleId","id");m(this,"onEnter",()=>{const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:1200,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.pushPointToScribble()});m(this,"onPointerUp",()=>{this.complete()});m(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()})}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}m(A$,"id","lasering");class Kh extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.setCursor({type:"cross",rotation:0})})}}m(Kh,"id","laser"),m(Kh,"initial","idle"),m(Kh,"children",()=>[YG,A$]);class j$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"initialSelectedShapeIds",[]);m(this,"excludedShapeIds",new Set);m(this,"isWrapMode",!1);m(this,"initialStartShape",null);m(this,"onEnter",n=>{const{altKey:r,currentPagePoint:o}=this.editor.inputs;if(this.isWrapMode=this.editor.user.getIsWrapMode(),r){this.parent.transition("scribble_brushing",n);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=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(o)[0],this.hitTestShapes()});m(this,"onExit",()=>{this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})});m(this,"onTick",()=>{sx(this.editor)});m(this,"onPointerMove",()=>{this.hitTestShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",n=>{this.editor.setSelectedShapes(this.initialSelectedShapeIds,{squashing:!0}),this.parent.transition("idle",n)});m(this,"onKeyDown",n=>{this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()});m(this,"onKeyUp",()=>{this.hitTestShapes()});m(this,"onInterrupt",()=>{this.editor.updateInstanceState({brush:null})})}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:o}=this,{inputs:{originPagePoint:s,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=o?!l:l,d=te.FromPoints([s,i]),{corners:p}=d;let f,y,g,w,S,v;const C=n.getCurrentPageShapes(),I=n.getCurrentPageId();e:for(let _=0,k=C.length;_<k;_++){if(g=C[_],r.has(g.id)||c.has(g.id)||(w=n.getShapePageBounds(g),!w))continue e;if(d.contains(w)){this.handleHit(g,i,I,c,p);continue e}if(u||n.isShapeOfType(g,"frame"))continue e;if(d.collides(w)){if(S=n.getShapePageTransform(g),!S)continue e;v=S.clone().invert().applyToPoints(p);const $=n.getShapeGeometry(g);t:for(let T=0;T<4;T++)if(f=v[T],y=v[(T+1)%4],$.hitTestLineSegment(f,y,0)){this.handleHit(g,i,I,c,p);break t}}}n.getInstanceState().isCoarsePointer;const P=n.getInstanceState().brush;(!P||!d.equals(P))&&n.updateInstanceState({brush:{...d.toJson()}});const E=n.getSelectedShapeIds();(E.length!==c.size||E.some(_=>!c.has(_)))&&n.setSelectedShapes(Array.from(c),{squashing:!0})}handleHit(n,r,o,s,i){if(n.parentId===o){s.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),l=this.editor.getShapeMask(a.id);l&&!bT(l,i)&&!Xn(r,l)||s.add(a.id)}}m(j$,"id","brushing");function Dx(e){const t=e.getZoomLevel(),{inputs:{currentPagePoint:n}}=e;return e.getShapeAtPoint(n,{hitInside:!1,hitLabels:!1,margin:Fo/t,renderingOnly:!0})??e.getSelectedShapeAtPoint(n)}function O$(e,t,n){if(!t)throw Error("Needs to translate a cropped shape!");const{crop:r}=t.props;if(!r)return;const o=e.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;o==="x"?n.x=0:o==="y"&&(n.y=0),n.rot(-t.rotation);const s=1/(r.bottomRight.x-r.topLeft.x)*t.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*t.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=vt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-n.x/s)),c.topLeft.y=Math.min(1-a,Math.max(0,c.topLeft.y-n.y/i)),c.bottomRight.x=c.topLeft.x+l,c.bottomRight.y=c.topLeft.y+a,{id:t.id,type:t.type,props:{crop:c}}}var Cy;let XG=(Cy=class extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0});const n=this.editor.getOnlySelectedShape();this.editor.on("change-history",this.cleanupCroppingState),n&&(this.editor.mark("crop"),this.editor.setCroppingShape(n.id))});m(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.off("change-history",this.cleanupCroppingState)});m(this,"onCancel",()=>{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})});m(this,"onPointerDown",n=>{var r;if(!this.editor.getIsMenuOpen()){if(n.ctrlKey){this.cancel(),this.editor.root.handleEvent(n);return}switch(n.target){case"canvas":{const o=Dx(this.editor);if(o&&!this.editor.isShapeOfType(o,"group")){this.onPointerDown({...n,shape:o,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(n);break}case"shape":{if(n.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",n);return}else(r=this.editor.getShapeUtil(n.shape))!=null&&r.canCrop(n.shape)?(this.editor.setCroppingShape(n.shape.id),this.editor.setSelectedShapes([n.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",n)):(this.cancel(),this.editor.root.handleEvent(n));break}case"selection":{switch(n.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",{...n,onInteractionEnd:"select.crop"});break}case"top":case"right":case"bottom":case"left":{this.editor.setCurrentTool("select.pointing_crop_handle",{...n,onInteractionEnd:"select.crop"});break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.pointing_crop_handle",{...n,onInteractionEnd:"select.crop"});break}default:this.cancel()}break}}}});m(this,"onDoubleClick",n=>{var i;if(this.editor.inputs.shiftKey||n.phase!=="up")return;const r=this.editor.getCroppingShapeId();if(!r)return;const o=this.editor.getShape(r);if(!o)return;const s=this.editor.getShapeUtil(o);s&&n.target==="selection"&&((i=s.onDoubleClickEdge)==null||i.call(s,o))});m(this,"onKeyDown",()=>{this.nudgeCroppingImage(!1)});m(this,"onKeyRepeat",()=>{this.nudgeCroppingImage(!0)});m(this,"onKeyUp",n=>{switch(n.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}});m(this,"cleanupCroppingState",()=>{this.editor.getCroppingShapeId()||this.editor.setCurrentTool("select.idle",{})})}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(n=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new b(0,0);if(r.has("ArrowLeft")&&(s.x+=1),r.has("ArrowRight")&&(s.x-=1),r.has("ArrowUp")&&(s.y+=1),r.has("ArrowDown")&&(s.y-=1),s.equals(new b(0,0)))return;o&&s.mul(10);const i=this.editor.getShape(this.editor.getCroppingShapeId());if(!i)return;const a=O$(this.editor,i,s);a&&(n||this.editor.mark("translate crop"),this.editor.updateShapes([a]))}},m(Cy,"id","idle"),Cy);class D$ extends re{constructor(){super(...arguments);m(this,"onCancel",()=>{this.editor.setCurrentTool("select.crop.idle",{})});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",n)});m(this,"onPointerUp",n=>{this.editor.setCurrentTool("select.crop.idle",n)})}}m(D$,"id","pointing_crop");class R$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","translating crop");m(this,"snapshot",{});m(this,"onEnter",n=>{this.info=n,this.snapshot=this.createSnapshot(),this.editor.mark(this.markId),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()});m(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onKeyDown",n=>{switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}});m(this,"onKeyUp",n=>{switch(n.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 n=this.snapshot.shape;if(!n)return;const{originPagePoint:r,currentPagePoint:o}=this.editor.inputs,s=o.clone().sub(r),i=O$(this.editor,n,s);i&&this.editor.updateShapes([i],{squashing:!0})}}m(R$,"id","translating_crop");class Vh extends re{}m(Vh,"id","crop"),m(Vh,"initial","idle"),m(Vh,"children",()=>[XG,R$,D$]);const lr=8,il={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 L$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n,this.updateCursor()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startResizing()});m(this,"onLongPress",()=>{this.startResizing()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){const n=this.editor.getSelectedShapes(),r=il[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:n.length===1?this.editor.getSelectionRotation():0}})}startResizing(){this.editor.getInstanceState().isReadonly||this.parent.transition("resizing",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}m(L$,"id","pointing_resize_handle");class F$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"snapshot",{});m(this,"onEnter",n=>{this.info=n,this.markId="cropping",this.editor.mark(this.markId),this.snapshot=this.createSnapshot(),this.updateShapes()});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"getDefaultCrop",()=>({topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}))}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=il[this.info.handle];this.editor.updateInstanceState({cursor:{type:r,rotation:this.editor.getSelectionRotation()}})}updateShapes(){const{shape:n,cursorHandleOffset:r}=this.snapshot;if(!n||!this.editor.getShapeUtil("image"))return;const s=n.props,i=this.editor.inputs.currentPagePoint.clone().sub(r),a=this.editor.inputs.originPagePoint.clone().sub(r),l=i.clone().sub(a).rot(-n.rotation),c=s.crop??this.getDefaultCrop(),u=vt(c),d=new b(n.x,n.y),p=new b(0,0),f=1/(c.bottomRight.x-c.topLeft.x)*s.w,y=1/(c.bottomRight.y-c.topLeft.y)*s.h;let g=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(y<lr)break;g=!0,u.topLeft.y=u.topLeft.y+l.y/y,y*(u.bottomRight.y-u.topLeft.y)<lr?(u.topLeft.y=u.bottomRight.y-lr/y,p.y=(u.topLeft.y-c.topLeft.y)*y):u.topLeft.y<=0?(u.topLeft.y=0,p.y=(u.topLeft.y-c.topLeft.y)*y):p.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(y<lr)break;g=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/y),y*(u.bottomRight.y-u.topLeft.y)<lr&&(u.bottomRight.y=u.topLeft.y+lr/y);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(f<lr)break;g=!0,u.topLeft.x=u.topLeft.x+l.x/f,f*(u.bottomRight.x-u.topLeft.x)<lr?(u.topLeft.x=u.bottomRight.x-lr/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<lr)break;g=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/f),f*(u.bottomRight.x-u.topLeft.x)<lr&&(u.bottomRight.x=u.topLeft.x+lr/f);break}}if(!g)return;d.add(p.rot(n.rotation));const w={id:n.id,type:n.type,x:d.x,y:d.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*f,h:(u.bottomRight.y-u.topLeft.y)*y}};this.editor.updateShapes([w],{squashing:!0}),this.updateCursor()}complete(){this.updateShapes(),Ve(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}createSnapshot(){const n=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,o=this.editor.getOnlySelectedShape(),s=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(s.getHandlePoint(this.info.handle),s.point,n),a=b.Sub(r,i);return{shape:o,cursorHandleOffset:a}}}m(F$,"id","cropping");class N$ extends re{constructor(){super(...arguments);m(this,"shapeId","");m(this,"initialHandle",{});m(this,"initialAdjacentHandle",null);m(this,"initialPagePoint",{});m(this,"markId","");m(this,"initialPageTransform");m(this,"initialPageRotation");m(this,"info",{});m(this,"isPrecise",!1);m(this,"isPreciseId",null);m(this,"pointingId",null);m(this,"onEnter",n=>{const{shape:r,isCreating:o,handle:s}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId=o?`creating:${r.id}`:"dragging handle",o||this.editor.mark(this.markId),this.initialHandle=vt(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=vt(c)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.updateInstanceState({cursor:{type:o?"cross":"grabbing",rotation:0}},{ephemeral:!0});const i=this.editor.getShapeHandles(r).sort(Lt),a=i.findIndex(l=>l.id===n.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!==n.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!==n.handle.id){this.initialAdjacentHandle=c;break}}if(this.editor.isShapeOfType(r,"arrow")){const l=r.props[n.handle.id];this.isPrecise=!1,(l==null?void 0:l.type)==="binding"?(this.editor.setHintingShapes([l.boundShapeId]),this.isPrecise=l.isPrecise,this.isPrecise?this.isPreciseId=l.boundShapeId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)});m(this,"exactTimeout",-1);m(this,"onPointerMove",()=>{this.update()});m(this,"onKeyDown",()=>{this.update()});m(this,"onKeyUp",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.update(),this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})})}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}complete(){this.editor.snaps.clearIndicators(),Ve(this.editor,[this.shapeId]);const{onInteractionEnd:n}=this.info;if(this.editor.getInstanceState().isToolLocked&&n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();const{onInteractionEnd:n}=this.info;if(n){this.editor.setCurrentTool(n,{shapeId:this.shapeId});return}this.parent.transition("idle")}update(){var _;const{editor:n,shapeId:r,initialPagePoint:o}=this,{initialHandle:s,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:d,shiftKey:p,ctrlKey:f,altKey:y,pointerVelocity:g}}=n,w=this.info.shape,S=n.getShape(r);if(!S)return;const v=n.getShapeUtil(S);let C=d.clone().sub(o).rot(-i).add(s);if(p&&a&&s.id!=="middle"){const k=b.Angle(a,C),T=pp(k,24)-k;C=b.RotWith(C,a,T)}n.snaps.clearIndicators();let I={...s,x:C.x,y:C.y};if(s.canSnap&&(c?!f:f)){if(!n.getShapePageTransform(S.id))throw Error("Expected a page transform");const $=u.handles.snapHandle({currentShapeId:r,handle:I});$&&($.nudge.rot(-n.getShapeParentTransform(S).rotation()),C.add($.nudge),I={...s,x:C.x,y:C.y})}const P=(_=v.onHandleDrag)==null?void 0:_.call(v,S,{handle:I,isPrecise:this.isPrecise||y,initial:w}),E={...S,...P};if(s.canBind){const k=E.props[s.id];(k==null?void 0:k.type)==="binding"?l[0]!==k.boundShapeId&&(n.setHintingShapes([k.boundShapeId]),this.pointingId=k.boundShapeId,this.isPrecise=g.len()<.5||y,this.isPreciseId=this.isPrecise?k.boundShapeId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}P&&n.updateShapes([E],{squashing:!0})}}m(N$,"id","dragging_handle");function z$(e){return e.isLabel?[e]:e instanceof Fr?e.children.filter(t=>t.isLabel):[]}class B$ extends re{constructor(){super(...arguments);m(this,"hitShapeForPointerUp",null);m(this,"onEnter",()=>{const n=this.editor.getEditingShape();if(!n)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,Ha(this.editor),this.editor.select(n)});m(this,"onExit",()=>{var s;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null);const r=this.editor.getShape(n),o=this.editor.getShapeUtil(r);(s=o.onEditEnd)==null||s.call(o,r)});m(this,"onPointerMove",n=>{if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getInstanceState().isReadonly)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",n),this.hitShapeForPointerUp=null;return}switch(n.target){case"shape":case"canvas":{Ha(this.editor);return}}});m(this,"onPointerDown",n=>{switch(this.hitShapeForPointerUp=null,n.target){case"canvas":{const r=Dx(this.editor);if(r){this.onPointerDown({...n,shape:r,target:"shape"});return}break}case"shape":{const{shape:r}=n,o=this.editor.getEditingShape();if(!o)throw Error("Expected an editing shape!");const s=this.editor.getShapeUtil(r).getGeometry(r),i=z$(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),requestAnimationFrame(()=>{var u;return(u=window.getSelection())==null?void 0:u.removeAllRanges()});return}}else{if(r.id===o.id)this.editor.isShapeOfType(r,"frame")&&this.editor.setEditingShape(null);else{this.parent.transition("pointing_shape",n);return}return}break}}this.parent.transition("idle",n),this.editor.root.handleEvent(n)});m(this,"onPointerUp",n=>{const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const o=this.editor.getShapeUtil(r);if(this.editor.getInstanceState().isReadonly&&!o.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.getInstanceState().isCoarsePointer?(this.editor.setEditingShape(null),this.editor.setCurrentTool("select.idle")):(this.editor.setEditingShape(r.id),Ha(this.editor))});m(this,"onComplete",n=>{this.parent.transition("idle",n)});m(this,"onCancel",n=>{this.parent.transition("idle",n)})}}m(B$,"id","editing_shape");function bC(e){const t=e.getOnlySelectedShape();return!!(t&&!e.isShapeOrAncestorLocked(t)&&e.getShapeUtil(t).canCrop(t))}function ef(e){const t=e.getSelectedShapeIds(),{shiftKey:n,altKey:r,currentPagePoint:o}=e.inputs,s=e.getShapeAtPoint(o,{hitInside:!1,margin:Fo/e.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:i=>!i.isLocked});if(s){const i=e.getOutermostSelectableShape(s);if(n&&!r)e.cancelDoubleClick(),t.includes(i.id)?(e.mark("deselecting shape"),e.deselect(i)):(e.mark("shift selecting shape"),e.setSelectedShapes([...t,i.id]));else{let a;i===s||i.id===e.getFocusedGroupId()||t.includes(i.id)?a=s:a=i,a&&!t.includes(a.id)&&(e.mark("selecting shape"),e.select(a.id))}}else{if(n)return;{t.length>0&&(e.mark("selecting none"),e.selectNone());const i=e.getFocusedGroupId();if(wn(i)){const a=e.getShape(i);e.isPointInShape(a,o,{margin:0,hitInside:!0})||e.setFocusedGroup(null)}}}}const qG=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var Iy;let ZG=(Iy=class extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{this.parent.setCurrentToolIdMask(void 0),Ha(this.editor),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerMove",()=>{Ha(this.editor)});m(this,"onPointerDown",n=>{if(this.editor.getIsMenuOpen())return;const r=n.ctrlKey&&bC(this.editor);if(n.ctrlKey&&!r){if(n.target==="shape"&&this.isDarwin&&this.editor.inputs.keys.has("ControlLeft")&&!this.editor.isShapeOrAncestorLocked(n.shape)){this.parent.transition("pointing_shape",n);return}this.parent.transition("brushing",n);return}switch(n.target){case"canvas":{const o=Dx(this.editor);if(o&&!o.isLocked){this.onPointerDown({...n,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))&&PC(this.editor,a)){this.onPointerDown({...n,target:"selection"});return}this.parent.transition("pointing_canvas",n);break}case"shape":{const{shape:o}=n;if(this.isOverArrowLabelTest(o)){this.parent.transition("pointing_arrow_label",n);break}if(this.editor.isShapeOrAncestorLocked(o)){this.parent.transition("pointing_canvas",n);break}this.parent.transition("pointing_shape",n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",n):this.parent.transition("pointing_handle",n);break}case"selection":{switch(n.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",n);break}case"top":case"right":case"bottom":case"left":{r?this.parent.transition("pointing_crop_handle",n):this.parent.transition("pointing_resize_handle",n);break}case"top_left":case"top_right":case"bottom_left":case"bottom_right":{r?this.parent.transition("pointing_crop_handle",n):this.parent.transition("pointing_resize_handle",n);break}default:{const o=this.editor.getHoveredShape();if(o&&!this.editor.getSelectedShapeIds().includes(o.id)&&!o.isLocked){this.onPointerDown({...n,shape:o,target:"shape"});return}this.parent.transition("pointing_selection",n)}}break}}});m(this,"onDoubleClick",n=>{var r,o,s,i;if(!(this.editor.inputs.shiftKey||n.phase!=="up"))switch(n.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:Fo/this.editor.getZoomLevel(),hitInside:!1}),c=this.editor.getFocusedGroupId();if(l){if(this.editor.isShapeOfType(l,"group")){ef(this.editor);return}else{const u=this.editor.getShape(l.parentId);if(u&&this.editor.isShapeOfType(u,"group")&&!(c&&u.id===c)){ef(this.editor);return}}this.onDoubleClick({...n,shape:l,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(n);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(n.handle==="right"||n.handle==="left"||n.handle==="top"||n.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]),Ve(this.editor,[a.id]);return}}if(l.canCrop(a)&&!this.editor.isShapeOrAncestorLocked(a)){this.parent.transition("crop",n);return}this.shouldStartEditingShape(a)&&this.startEditingShape(a,n,!0)}break}case"shape":{const{shape:a}=n,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=n.shape)==null?void 0:s.id),this.parent.transition("crop",n);return}}this.shouldStartEditingShape(a)?this.startEditingShape(a,n,!0):this.handleDoubleClickOnCanvas(n);break}case"handle":{if(this.editor.getInstanceState().isReadonly)break;const{shape:a,handle:l}=n,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,n,!0)}}});m(this,"onRightClick",n=>{switch(n.target){case"canvas":{const r=this.editor.getHoveredShape(),o=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:Fo/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitFrameInside:!1,renderingOnly:!0});if(o){this.onRightClick({...n,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))&&PC(this.editor,a)){this.onRightClick({...n,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:r}=this.editor.getCurrentPageState(),{shape:o}=n,s=this.editor.getOutermostSelectableShape(o,i=>!r.includes(i.id));r.includes(s.id)||(this.editor.mark("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}});m(this,"onCancel",()=>{this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.mark("clearing selection"),this.editor.selectNone())});m(this,"onKeyDown",n=>{switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(Tt.editOnType.get()&&!qG.includes(n.key)&&!n.altKey&&!n.ctrlKey){const r=this.editor.getOnlySelectedShape();if(r&&this.editor.isShapeOfType(r,"note")&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...n,target:"shape",shape:r},!0);return}}});m(this,"onKeyRepeat",n=>{switch(n.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}});m(this,"onKeyUp",n=>{switch(n.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,{...n,target:"shape",shape:o},!0);return}bC(this.editor)&&this.parent.transition("crop",n);break}}});m(this,"isDarwin",window.navigator.userAgent.toLowerCase().indexOf("mac")>-1)}shouldStartEditingShape(n=this.editor.getOnlySelectedShape()){return!n||this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||!this.canInteractWithShapeInReadOnly(n)?!1:this.editor.getShapeUtil(n).canEdit(n)}startEditingShape(n,r,o){this.editor.isShapeOrAncestorLocked(n)&&n.type!=="embed"||(this.editor.mark("editing shape"),Qp(this.editor,n,o),this.parent.transition("editing_shape",r))}isOverArrowLabelTest(n){if(!n)return!1;const r=this.editor.getPointInShapeSpace(n,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(n,"arrow")){const o=this.editor.getShapeGeometry(n).children[1];if(o&&Xn(r,o.vertices))return!0}return!1}handleDoubleClickOnCanvas(n){if(this.editor.getInstanceState().isReadonly)return;this.editor.mark("creating text shape");const r=Be(),{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",n))}nudgeSelectedShapes(n=!1){const{editor:{inputs:{keys:r}}}=this,o=r.has("ShiftLeft"),s=new b(0,0);if(r.has("ArrowLeft")&&(s.x-=1),r.has("ArrowRight")&&(s.x+=1),r.has("ArrowUp")&&(s.y-=1),r.has("ArrowDown")&&(s.y+=1),s.equals(new b(0,0)))return;n||this.editor.mark("nudge shapes");const{gridSize:i}=this.editor.getDocumentSettings(),a=this.editor.getInstanceState().isGridMode?o?i*eY:i:o?QG:JG,l=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(l,s.mul(a)),Ve(this.editor,l)}canInteractWithShapeInReadOnly(n){return!!(!this.editor.getInstanceState().isReadonly||this.editor.getShapeUtil(n).canEditInReadOnly(n))}},m(Iy,"id","idle"),Iy);const QG=10,JG=1,eY=5;function PC(e,t){const n=e.getSelectionRotatedPageBounds();if(!n)return!1;const r=e.getSelectionRotation();return r?Xn(t,n.corners.map(o=>b.RotWith(o,n.point,r))):n.containsPoint(t)}class U$ extends re{constructor(){super(...arguments);m(this,"shapeId","");m(this,"markId","");m(this,"wasAlreadySelected",!1);m(this,"didDrag",!1);m(this,"info",{});m(this,"onEnter",n=>{const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const s=this.editor.getShapeGeometry(r).children[1];if(!s)throw Error(`Expected to find an arrow label geometry for shape: ${r.id}`);const{currentPagePoint:i}=this.editor.inputs,a=this.editor.getPointInShapeSpace(r,i);this._labelDragOffset=b.Sub(s.center,a),this.markId="label-drag start",this.editor.mark(this.markId),this.editor.setSelectedShapes([this.shapeId])});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"_labelDragOffset",new b(0,0));m(this,"onPointerMove",()=>{const{isDragging:n}=this.editor.inputs;if(!n)return;const r=this.editor.getShape(this.shapeId);if(!r)return;const o=this.editor.getArrowInfo(r),s=this.editor.getShapeGeometry(r),i=s.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(b.Add(a,this._labelDragOffset));let c;if(o.isStraight){const u=b.Dist2(o.start.point,o.end.point);c=1-b.Dist2(o.end.point,l)/u}else{const{_center:u,measure:d,angleEnd:p,angleStart:f}=s.children[0];c=Ry(d,f,p,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}},{squashing:!0})});m(this,"onPointerUp",()=>{const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}m(U$,"id","pointing_arrow_label");class H$ extends re{constructor(){super(...arguments);m(this,"onEnter",()=>{const{inputs:n}=this.editor;n.shiftKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.mark("selecting none"),this.editor.selectNone())});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.parent.transition("brushing",n)});m(this,"onPointerUp",()=>{ef(this.editor),this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onInterrupt",()=>{this.parent.transition("idle")})}complete(){this.parent.transition("idle")}}m(H$,"id","pointing_canvas");class K$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const o=il[this.info.handle];this.editor.updateInstanceState({cursor:{type:o,rotation:this.editor.getSelectionRotation()}}),this.editor.setCroppingShape(r.id)});m(this,"onExit",()=>{this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startCropping()});m(this,"onLongPress",()=>{this.startCropping()});m(this,"onPointerUp",()=>{this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startCropping(){this.editor.getInstanceState().isReadonly||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.parent.transition("idle"))}}m(K$,"id","pointing_crop_handle");class V$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const o=r.props[n.handle.id];(o==null?void 0:o.type)==="binding"&&this.editor.setHintingShapes([o.boundShapeId])}this.editor.updateInstanceState({cursor:{type:"grabbing",rotation:0}},{ephemeral:!0})});m(this,"onExit",()=>{this.editor.setHintingShapes([]),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerUp",()=>{const{shape:n,handle:r}=this.info;if(this.editor.isShapeOfType(n,"note")){const{editor:o}=this,s=CC(o,n,r,!1);if(s){Qp(o,s,!0);return}}this.parent.transition("idle",this.info)});m(this,"onPointerMove",()=>{const{editor:n}=this;n.inputs.isDragging&&this.startDraggingHandle()});m(this,"onLongPress",()=>{this.startDraggingHandle()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startDraggingHandle(){const{editor:n}=this;if(n.getInstanceState().isReadonly)return;const{shape:r,handle:o}=this.info;if(n.isShapeOfType(r,"note")){const s=CC(n,r,o,!0);if(s){const i=n.getPointInParentSpace(s,n.inputs.originPagePoint).sub(b.Rot(kx,s.rotation));n.updateShape({...s,x:i.x,y:i.y}),n.setHoveredShape(s.id).select(s.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(s),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{Qp(n,s,!0)}});return}}this.parent.transition("dragging_handle",this.info)}cancel(){this.parent.transition("idle")}}m(V$,"id","pointing_handle");function CC(e,t,n,r){const o=e.getShapePageTransform(t.id),s=o.point(),i=o.rotation(),a=n$(s,i,t.props.growY,0),l=e.getShapeHandles(t.id).findIndex(c=>c.id===n.id);if(a[l]){const c=a[l];return o$(e,t,c,i,r)}}class W$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0})});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.startRotating()});m(this,"onLongPress",()=>{this.startRotating()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}updateCursor(){this.editor.updateInstanceState({cursor:{type:il[this.info.handle],rotation:this.editor.getSelectionRotation()}})}startRotating(){this.editor.getInstanceState().isReadonly||this.parent.transition("rotating",this.info)}complete(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}}m(W$,"id","pointing_rotate_handle");class G$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n});m(this,"onPointerUp",n=>{ef(this.editor),this.parent.transition("idle",n)});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startTranslating(n)});m(this,"onLongPress",n=>{this.startTranslating(n)});m(this,"onDoubleClick",n=>{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,{...n,target:"shape",shape:this.editor.getShape(o)});return}});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(n){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",n)}cancel(){this.parent.transition("idle")}}m(G$,"id","pointing_selection");class Y$ extends re{constructor(){super(...arguments);m(this,"hitShape",{});m(this,"hitShapeForPointerUp",{});m(this,"isDoubleClick",!1);m(this,"didSelectOnEnter",!1);m(this,"onEnter",n=>{const r=this.editor.getSelectedShapeIds(),o=this.editor.getSelectionRotatedPageBounds(),s=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i,shiftKey:a,altKey:l}}=this.editor;this.hitShape=n.shape,this.isDoubleClick=!1;const c=this.editor.getOutermostSelectableShape(n.shape),u=this.editor.findShapeAncestor(c,d=>r.includes(d.id));if(this.editor.getShapeUtil(n.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]))});m(this,"onPointerUp",n=>{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:Fo/s,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const d=this.editor.getShapeUtil(c);if(d.onClick){const p=(u=d.onClick)==null?void 0:u.call(d,c);if(p){this.editor.mark("shape on click"),this.editor.updateShapes([p]),this.parent.transition("idle",n);return}}if(c.id===o){r.length>0?(this.editor.mark("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",n);return}}if(!this.didSelectOnEnter){const d=this.editor.getOutermostSelectableShape(l,p=>!r.includes(p.id));if(r.includes(d.id))if(a)this.editor.mark("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const p=this.editor.getShapeUtil(c).getGeometry(c),f=z$(p),y=f.length===1?f[0]:void 0;if(y){const g=this.editor.getPointInShapeSpace(c,i);if(y.bounds.containsPoint(g,0)&&y.hitTestPoint(g)){this.editor.batch(()=>{this.editor.mark("editing on pointer up"),this.editor.select(c.id);const w=this.editor.getShapeUtil(c);this.editor.getInstanceState().isReadonly&&!w.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(d);this.editor.mark("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(f=>!p.find(y=>y.id===f)),d.id])}else this.editor.mark("selecting on pointer up"),this.editor.setSelectedShapes([d.id])}this.parent.transition("idle",n)});m(this,"onDoubleClick",()=>{this.isDoubleClick=!0});m(this,"onPointerMove",n=>{this.editor.inputs.isDragging&&this.startTranslating(n)});m(this,"onLongPress",n=>{this.startTranslating(n)});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.cancel()});m(this,"onInterrupt",()=>{this.cancel()})}startTranslating(n){this.editor.getInstanceState().isReadonly||this.parent.transition("translating",n)}cancel(){this.parent.transition("idle")}}m(Y$,"id","pointing_shape");class X$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"markId","");m(this,"didHoldCommand",!1);m(this,"creationCursorOffset",{x:0,y:0});m(this,"snapshot",{});m(this,"onEnter",n=>{const{isCreating:r=!1,creationCursorOffset:o={x:0,y:0}}=n;this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),r?(this.markId=`creating:${this.editor.getOnlySelectedShape().id}`,this.editor.updateInstanceState({cursor:{type:"cross",rotation:0}},{ephemeral:!0})):(this.markId="starting resizing",this.editor.mark(this.markId)),this.handleResizeStart(),this.updateShapes()});m(this,"onTick",()=>{sx(this.editor)});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onKeyDown",()=>{this.updateShapes()});m(this,"onKeyUp",()=>{this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.editor.snaps.clearIndicators()});m(this,"_createSnapshot",()=>{const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:o}}=this.editor,s=this.editor.getSelectionRotatedPageBounds(),i=b.RotWith(s.getHandlePoint(this.info.handle),s.point,r),a=b.Sub(o,i),l=new Map,c=[];n.forEach(d=>{const p=this.editor.getShape(d);if(p){if(p.type==="frame"&&c.push({id:d,children:fe(this.editor.getSortedChildIdsForParent(p).map(f=>this.editor.getShape(f)))}),l.set(p.id,this._createShapeSnapshot(p)),this.editor.isShapeOfType(p,"frame")&&n.length===1)return;this.editor.visitDescendants(p.id,f=>{const y=this.editor.getShape(f);if(y&&(l.set(y.id,this._createShapeSnapshot(y)),this.editor.isShapeOfType(y,"frame")))return!1})}});const u=![...l.values()].some(d=>!jE(d.pageRotation,r)||d.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:s,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}});m(this,"_createShapeSnapshot",n=>{const r=this.editor.getShapePageTransform(n),o=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:ne.Decompose(r).rotation,isAspectRatioLocked:o.isAspectRatioLocked(n)}})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(Ve(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){(r=(n=this.info).onCreate)==null||r.call(n,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:n}=this.snapshot,r=[];n.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:n}=this.snapshot,r=[];n.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:n,shiftKey:r}=this.editor.inputs,{frames:o,shapeSnapshots:s,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot,d=r||!u,{ctrlKey:p}=this.editor.inputs,f=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),y=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!p){const{gridSize:k}=this.editor.getDocumentSettings();f.snapToGrid(k)}const g=this.info.handle,w=IC(g,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!p:p)&&c%Ge===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:b.Sub(f,y),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:IC(g,c),isAspectRatioLocked:d,isResizingFromCenter:n});f.add(k)}const v=b.RotWith(n?i.center:i.getHandlePoint(w),i.point,c),C=b.Sub(f,v).rot(-c),I=b.Sub(y,v).rot(-c),P=b.DivV(C,I);Number.isFinite(P.x)||(P.x=1),Number.isFinite(P.y)||(P.y=1);const E=g==="top"||g==="bottom",_=g==="left"||g==="right";d?_?P.y=Math.abs(P.x):E?P.x=Math.abs(P.y):Math.abs(P.x)>Math.abs(P.y)?P.y=Math.abs(P.x)*(P.y<0?-1:1):P.x=Math.abs(P.y)*(P.x<0?-1:1):(E&&(P.x=1),_&&(P.y=1)),this.info.isCreating||this.updateCursor({dragHandle:g,isFlippedX:P.x<0,isFlippedY:P.y<0,rotation:c});for(const k of s.keys()){const $=s.get(k);this.editor.resizeShape(k,P,{initialShape:$.shape,initialBounds:$.bounds,initialPageTransform:$.pageTransform,dragHandle:g,mode:l.length===1&&k===l[0]?"resize_bounds":"scale_shape",scaleOrigin:v,scaleAxisRotation:c})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:$}of o){if(!$.length)continue;const T=s.get(k).shape,j=this.editor.getShape(k);if(!(T&&j))continue;const L=j.x-T.x,N=j.y-T.y,F=new b(L,N).rot(-T.rotation);if(F.x!==0||F.y!==0)for(const B of $)this.editor.updateShape({id:B.id,type:B.type,x:B.x-F.x,y:B.y-F.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of o)if(k.length)for(const $ of k)this.editor.updateShape({id:$.id,type:$.type,x:$.x,y:$.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:o,rotation:s}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==o&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==o&&(i.type="nwse-resize");break}}i.rotation=s,this.editor.setCursor(i)}}m(X$,"id","resizing");const Vm=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function IC(e,t){t=t%Fe;const n=Math.round(t/(je/4)),r=Vm.indexOf(e);return Vm[(r+n)%Vm.length]}const EC=Math.PI/180;class q$ extends re{constructor(){super(...arguments);m(this,"snapshot",{});m(this,"info",{});m(this,"markId","");m(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId="rotate start",this.editor.mark(this.markId);const r=IT({editor:this.editor});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const o=this._getRotationFromPointerPosition({snapToNearestDegree:!1});mh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.updateInstanceState({cursor:{type:il[this.info.handle],rotation:o+this.snapshot.initialSelectionRotation}})});m(this,"onExit",()=>{this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}});m(this,"onPointerMove",()=>{this.update()});m(this,"onKeyDown",()=>{this.update()});m(this,"onKeyUp",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"update",()=>{const n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});mh({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.updateInstanceState({cursor:{type:il[this.info.handle],rotation:n+this.snapshot.initialSelectionRotation}})});m(this,"cancel",()=>{this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)});m(this,"complete",()=>{mh({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Ve(this.editor,this.snapshot.shapeSnapshots.map(n=>n.shape.id)),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)})}_getRotationFromPointerPosition({snapToNearestDegree:n}){const r=this.editor.getSelectionRotation(),o=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:s,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialSelectionRotation:l}=this.snapshot;if(!o)return l;const u=o.center.clone().rotWith(o.point,r).angle(i)-a;let d=l+u;if(s)d=pp(d,24);else if(n&&(d=Math.round(d/EC)*EC,this.editor.getInstanceState().isCoarsePointer)){const p=pp(d,4),f=yc(d,p);Math.abs(f)<JR(5)&&(d=p)}return d-l}}m(q$,"id","rotating");class Z$ extends re{constructor(){super(...arguments);m(this,"hits",new Set);m(this,"size",0);m(this,"scribbleId","id");m(this,"initialSelectedShapeIds",new Set);m(this,"newlySelectedShapeIds",new Set);m(this,"onEnter",()=>{this.initialSelectedShapeIds=new Set(this.editor.inputs.shiftKey?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();const n=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:.32,size:12});this.scribbleId=n.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})});m(this,"onExit",()=>{this.editor.scribbles.stop(this.scribbleId)});m(this,"onPointerMove",()=>{this.updateScribbleSelection(!0)});m(this,"onPointerUp",()=>{this.complete()});m(this,"onKeyDown",()=>{this.updateScribbleSelection(!1)});m(this,"onKeyUp",()=>{this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")});m(this,"onCancel",()=>{this.cancel()});m(this,"onComplete",()=>{this.complete()});m(this,"pushPointToScribble",()=>{const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)})}updateScribbleSelection(n){const{editor:r}=this,o=this.editor.getCurrentPageShapes(),{inputs:{shiftKey:s,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const d=o;let p,f,y,g;const w=0;for(let C=0,I=d.length;C<I;C++){if(p=d[C],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 P=r.getShapePageTransform(p);if(!f||!P)continue;const E=P.clone().invert();y=E.applyToPoint(a),g=E.applyToPoint(l);const{bounds:_}=f;if(!(_.minX-w>Math.max(y.x,g.x)||_.minY-w>Math.max(y.y,g.y)||_.maxX+w<Math.min(y.x,g.x)||_.maxY+w<Math.min(y.y,g.y))&&f.hitTestLineSegment(y,g,w)){const k=this.editor.getOutermostSelectableShape(p),$=this.editor.getShapeMask(k.id);if($&&X0(a,l,$)!==null&&!Xn(l,$))continue;c.add(k.id)}}const S=r.getSelectedShapeIds(),v=new Set(s?[...c,...u]:[...c]);(S.length!==v.size||S.some(C=>!v.has(C)))&&this.editor.setSelectedShapes(Array.from(v),{squashing:!0})}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds],{squashing:!0}),this.parent.transition("idle")}}m(Z$,"id","scribble_brushing");const tY=20,nY=100;class rY{constructor(t){m(this,"prevDroppingShapeId",null);m(this,"droppingNodeTimer",null);m(this,"first",!0);m(this,"dispose",()=>{this.clear()});this.editor=t,t.disposables.add(this.dispose)}updateDroppingNode(t,n){var r;this.first&&(this.editor.setHintingShapes(t.map(o=>this.editor.findShapeAncestor(o,s=>s.type!=="group")).filter(o=>o)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,t))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(t,tY,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearInterval(this.droppingNodeTimer),this.setDragTimer(t,nY,n))}setDragTimer(t,n,r){this.droppingNodeTimer=setTimeout(()=>{this.editor.batch(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,t,r)}),this.droppingNodeTimer=null},n)}handleDrag(t,n,r){var l,c,u,d,p;n=fe(n.map(f=>this.editor.getShape(f.id)));const o=((l=this.editor.getDroppingOverShape(t,n))==null?void 0:l.id)??null;if(o===this.prevDroppingShapeId){this.hintParents(n);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,n)),a&&((p=(d=this.editor.getShapeUtil(a)).onDragShapesOver)==null||p.call(d,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=o}hintParents(t){const n=new Map;for(const o of t){const s=this.editor.findShapeAncestor(o,i=>i.type!=="group");s&&(n.has(s.id)||n.set(s.id,[]),n.get(s.id).push(o.id))}const r=[];for(const[o,s]of n){const i=this.editor.getShape(o);i&&J2(this.editor,i).length<s.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(t){var r,o;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,t),n){const s=this.editor.getShape(n);if(!s)return;(o=(r=this.editor.getShapeUtil(s)).onDropShapesOver)==null||o.call(r,s,t)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearInterval(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}}class Q$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"selectionSnapshot",{});m(this,"snapshot",{});m(this,"markId","");m(this,"isCloning",!1);m(this,"isCreating",!1);m(this,"onCreate",()=>{});m(this,"dragAndDropManager",new rY(this.editor));m(this,"onEnter",n=>{const{isCreating:r=!1,onCreate:o=()=>{}}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.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=n,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=_C(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()});m(this,"onTick",()=>{this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),sx(this.editor)});m(this,"onPointerMove",()=>{this.updateShapes()});m(this,"onKeyDown",()=>{if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()});m(this,"onKeyUp",()=>{if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onComplete",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()});m(this,"updateParentTransforms",()=>{const{editor:n,snapshot:{shapeSnapshots:r}}=this;r.forEach(o=>{const s=n.getShape(o.shape.id);if(!s)return null;const i=xn(s.parentId)?null:ne.Inverse(n.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=_C(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 n;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),Ve(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?(n=this.onCreate)==null||n.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:n}=this.snapshot,r=[];n.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:n}=this.snapshot;if(this.isCloning&&n.length>0){const o=b.Average(n.map(i=>this.editor.getShapePageTransform(i.id).point())),s=b.Sub(o,this.selectionSnapshot.averagePagePoint);b.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:n.map(i=>i.id),offset:{x:s.x,y:s.y}}})}const r=[];n.forEach(o=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslateEnd)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}handleChange(){const{movingShapes:n}=this.snapshot,r=[];n.forEach(o=>{var l;const s=this.editor.getShape(o.id),i=this.editor.getShapeUtil(o),a=(l=i.onTranslate)==null?void 0:l.call(i,o,s);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{snapshot:n}=this;this.dragAndDropManager.updateDroppingNode(n.movingShapes,this.updateParentTransforms),oY({editor:this.editor,snapshot:n}),this.handleChange()}}m(Q$,"id","translating");function _C(e){var d;const t=[],n=[],r=e.getSelectedShapeIds(),o=fe(r.map(p=>{const f=e.getShape(p);if(!f)return null;t.push(f);const y=e.getShapePageTransform(p),g=y.point(),w=y.rotation();n.push(g);const S=Lo.isId(f.parentId)?null:ne.Inverse(e.getShapePageTransform(f.parentId));return{shape:f,pagePoint:g,pageRotation:w,parentTransform:S}})),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,y)=>({id:"selection:"+y,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=(d=u.map(f=>({snapshot:f,index:p.findIndex(y=>y.id===f.shape.id)})).sort((f,y)=>y.index-f.index)[0])==null?void 0:d.snapshot}return l&&(a=r$(e,l.pageRotation,l.shape.props.growY??0)),{averagePagePoint:b.Average(n),movingShapes:t,shapeSnapshots:o,initialPageBounds:e.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function oY({editor:e,snapshot:t}){const{inputs:n}=e,{noteSnapshot:r,noteAdjacentPositions:o,initialPageBounds:s,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=t,c=e.getInstanceState().isGridMode,u=e.getDocumentSettings().gridSize,d=b.Sub(n.currentPagePoint,n.originPagePoint),p=e.inputs.shiftKey?Math.abs(d.x)<Math.abs(d.y)?"x":"y":null;if(p==="x"?d.x=0:p==="y"&&(d.y=0),e.snaps.clearIndicators(),(e.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey)&&e.inputs.pointerVelocity.len()<.5){const{nudge:w}=e.snaps.shapeBounds.snapTranslateShapes({dragDelta:d,initialSelectionPageBounds:s,lockedAxis:p,initialSelectionSnapPoints:i});d.add(w)}else if(r&&o){let w=t$/e.getZoomLevel(),S=new b(0,0);const v=b.Add(b.Add(r.pagePoint,d),new b($e/2,$e/2).rot(r.pageRotation));for(const C of o){const I=b.Sub(v,C),P=I.len();P<w&&(w=P,S=I)}d.sub(S)}const y=b.Add(l,d);c&&!n.ctrlKey&&y.snapToGrid(u);const g=b.Sub(y,l);e.updateShapes(fe(a.map(({shape:w,pagePoint:S,parentTransform:v})=>{const C=b.Add(S,g),I=v?ne.applyToPoint(v,C):C;return{id:w.id,type:w.type,x:I.x,y:I.y}})),{squashing:!0})}class Wh extends re{constructor(){super(...arguments);m(this,"reactor");m(this,"cleanUpDuplicateProps",()=>{const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const o=new Set(r.duplicateProps.shapeIds);n.length===o.size&&n.every(s=>o.has(s))||this.editor.updateInstanceState({duplicateProps:null})});m(this,"onEnter",()=>{this.reactor=wu("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){typeof process<"u",console.error(n)}})});m(this,"onExit",()=>{var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)})}}m(Wh,"id","select"),m(Wh,"initial","idle"),m(Wh,"children",()=>[Vh,F$,ZG,H$,Y$,Q$,j$,Z$,K$,G$,L$,B$,X$,q$,W$,U$,V$,N$]);class J$ extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n});m(this,"onPointerDown",()=>{this.parent.transition("pointing",this.info)})}}m(J$,"id","idle");class eM extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n});m(this,"onPointerUp",()=>{this.complete()});m(this,"onPointerMove",()=>{this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)});m(this,"onCancel",()=>{this.cancel()})}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{duration:220}):this.editor.zoomIn(n,{duration:220}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}m(eM,"id","pointing");class tM extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"zoomBrush",new te);m(this,"onEnter",n=>{this.info=n,this.update()});m(this,"onExit",()=>{this.editor.updateInstanceState({zoomBrush:null})});m(this,"onPointerMove",()=>{this.update()});m(this,"onPointerUp",()=>{this.complete()});m(this,"onCancel",()=>{this.cancel()})}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(te.FromPoints([n,r])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){const{zoomBrush:n}=this,r=8/this.editor.getZoomLevel();if(n.width<r&&n.height<r){const o=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(o,{duration:220}):this.editor.zoomIn(o,{duration:220})}else{const o=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:o,duration:220})}this.parent.transition("idle",this.info)}}m(tM,"id","zoom_brushing");class Gh extends re{constructor(){super(...arguments);m(this,"info",{});m(this,"onEnter",n=>{this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()});m(this,"onExit",()=>{this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}},{ephemeral:!0}),this.parent.setCurrentToolIdMask(void 0)});m(this,"onKeyDown",()=>{this.updateCursor()});m(this,"onKeyUp",n=>{this.updateCursor(),n.code==="KeyZ"&&this.complete()});m(this,"onInterrupt",()=>{this.complete()})}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.updateInstanceState({cursor:{type:"zoom-out",rotation:0}},{ephemeral:!0}):this.editor.updateInstanceState({cursor:{type:"zoom-in",rotation:0}},{ephemeral:!0})}}m(Gh,"id","zoom"),m(Gh,"initial","idle"),m(Gh,"children",()=>[J$,tM,eM]);const sY=[Uh,Hh,Kh,Gh,Wh];function X(){return X=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},X.apply(this,arguments)}function se(e,t,{checkForDefaultPrevented:n=!0}={}){return function(o){if(e==null||e(o),n===!1||!o.defaultPrevented)return t==null?void 0:t(o)}}function iY(e,t){typeof e=="function"?e(t):e!=null&&(e.current=t)}function Xf(...e){return t=>e.forEach(n=>iY(n,t))}function Xe(...e){return x.useCallback(Xf(...e),e)}function ho(e,t=[]){let n=[];function r(s,i){const a=x.createContext(i),l=n.length;n=[...n,i];function c(d){const{scope:p,children:f,...y}=d,g=(p==null?void 0:p[e][l])||a,w=x.useMemo(()=>y,Object.values(y));return x.createElement(g.Provider,{value:w},f)}function u(d,p){const f=(p==null?void 0:p[e][l])||a,y=x.useContext(f);if(y)return y;if(i!==void 0)return i;throw new Error(`\`${d}\` must be used within \`${s}\``)}return c.displayName=s+"Provider",[c,u]}const o=()=>{const s=n.map(i=>x.createContext(i));return function(a){const l=(a==null?void 0:a[e])||s;return x.useMemo(()=>({[`__scope${e}`]:{...a,[e]:l}}),[a,l])}};return o.scopeName=e,[r,aY(o,...t)]}function aY(...e){const t=e[0];if(e.length===1)return t;const n=()=>{const r=e.map(o=>({useScope:o(),scopeName:o.scopeName}));return function(s){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const d=l(s)[`__scope${c}`];return{...a,...d}},{});return x.useMemo(()=>({[`__scope${t.scopeName}`]:i}),[i])}};return n.scopeName=t.scopeName,n}const Mi=x.forwardRef((e,t)=>{const{children:n,...r}=e,o=x.Children.toArray(n),s=o.find(cY);if(s){const i=s.props.children,a=o.map(l=>l===s?x.Children.count(i)>1?x.Children.only(null):x.isValidElement(i)?i.props.children:null:l);return x.createElement(cv,X({},r,{ref:t}),x.isValidElement(i)?x.cloneElement(i,void 0,a):null)}return x.createElement(cv,X({},r,{ref:t}),n)});Mi.displayName="Slot";const cv=x.forwardRef((e,t)=>{const{children:n,...r}=e;return x.isValidElement(n)?x.cloneElement(n,{...uY(r,n.props),ref:t?Xf(t,n.ref):n.ref}):x.Children.count(n)>1?x.Children.only(null):null});cv.displayName="SlotClone";const lY=({children:e})=>x.createElement(x.Fragment,null,e);function cY(e){return x.isValidElement(e)&&e.type===lY}function uY(e,t){const n={...t};for(const r in t){const o=e[r],s=t[r];/^on[A-Z]/.test(r)?o&&s?n[r]=(...a)=>{s(...a),o(...a)}:o&&(n[r]=o):r==="style"?n[r]={...o,...s}:r==="className"&&(n[r]=[o,s].filter(Boolean).join(" "))}return{...e,...n}}function qf(e){const t=e+"CollectionProvider",[n,r]=ho(t),[o,s]=n(t,{collectionRef:{current:null},itemMap:new Map}),i=f=>{const{scope:y,children:g}=f,w=Se.useRef(null),S=Se.useRef(new Map).current;return Se.createElement(o,{scope:y,itemMap:S,collectionRef:w},g)},a=e+"CollectionSlot",l=Se.forwardRef((f,y)=>{const{scope:g,children:w}=f,S=s(a,g),v=Xe(y,S.collectionRef);return Se.createElement(Mi,{ref:v},w)}),c=e+"CollectionItemSlot",u="data-radix-collection-item",d=Se.forwardRef((f,y)=>{const{scope:g,children:w,...S}=f,v=Se.useRef(null),C=Xe(y,v),I=s(c,g);return Se.useEffect(()=>(I.itemMap.set(v,{ref:v,...S}),()=>void I.itemMap.delete(v))),Se.createElement(Mi,{[u]:"",ref:C},w)});function p(f){const y=s(e+"CollectionConsumer",f);return Se.useCallback(()=>{const w=y.collectionRef.current;if(!w)return[];const S=Array.from(w.querySelectorAll(`[${u}]`));return Array.from(y.itemMap.values()).sort((I,P)=>S.indexOf(I.ref.current)-S.indexOf(P.ref.current))},[y.collectionRef,y.itemMap])}return[{Provider:i,Slot:l,ItemSlot:d},p,r]}const dY=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ke=dY.reduce((e,t)=>{const n=x.forwardRef((r,o)=>{const{asChild:s,...i}=r,a=s?Mi:t;return x.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),x.createElement(a,X({},i,{ref:o}))});return n.displayName=`Primitive.${t}`,{...e,[t]:n}},{});function Rx(e,t){e&&zi.flushSync(()=>e.dispatchEvent(t))}function sn(e){const t=x.useRef(e);return x.useEffect(()=>{t.current=e}),x.useMemo(()=>(...n)=>{var r;return(r=t.current)===null||r===void 0?void 0:r.call(t,...n)},[])}function hY(e,t=globalThis==null?void 0:globalThis.document){const n=sn(e);x.useEffect(()=>{const r=o=>{o.key==="Escape"&&n(o)};return t.addEventListener("keydown",r),()=>t.removeEventListener("keydown",r)},[n,t])}const uv="dismissableLayer.update",pY="dismissableLayer.pointerDownOutside",fY="dismissableLayer.focusOutside";let kC;const nM=x.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),Zf=x.forwardRef((e,t)=>{var n;const{disableOutsidePointerEvents:r=!1,onEscapeKeyDown:o,onPointerDownOutside:s,onFocusOutside:i,onInteractOutside:a,onDismiss:l,...c}=e,u=x.useContext(nM),[d,p]=x.useState(null),f=(n=d==null?void 0:d.ownerDocument)!==null&&n!==void 0?n:globalThis==null?void 0:globalThis.document,[,y]=x.useState({}),g=Xe(t,k=>p(k)),w=Array.from(u.layers),[S]=[...u.layersWithOutsidePointerEventsDisabled].slice(-1),v=w.indexOf(S),C=d?w.indexOf(d):-1,I=u.layersWithOutsidePointerEventsDisabled.size>0,P=C>=v,E=mY(k=>{const $=k.target,T=[...u.branches].some(j=>j.contains($));!P||T||(s==null||s(k),a==null||a(k),k.defaultPrevented||l==null||l())},f),_=yY(k=>{const $=k.target;[...u.branches].some(j=>j.contains($))||(i==null||i(k),a==null||a(k),k.defaultPrevented||l==null||l())},f);return hY(k=>{C===u.layers.size-1&&(o==null||o(k),!k.defaultPrevented&&l&&(k.preventDefault(),l()))},f),x.useEffect(()=>{if(d)return r&&(u.layersWithOutsidePointerEventsDisabled.size===0&&(kC=f.body.style.pointerEvents,f.body.style.pointerEvents="none"),u.layersWithOutsidePointerEventsDisabled.add(d)),u.layers.add(d),TC(),()=>{r&&u.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=kC)}},[d,f,r,u]),x.useEffect(()=>()=>{d&&(u.layers.delete(d),u.layersWithOutsidePointerEventsDisabled.delete(d),TC())},[d,u]),x.useEffect(()=>{const k=()=>y({});return document.addEventListener(uv,k),()=>document.removeEventListener(uv,k)},[]),x.createElement(Ke.div,X({},c,{ref:g,style:{pointerEvents:I?P?"auto":"none":void 0,...e.style},onFocusCapture:se(e.onFocusCapture,_.onFocusCapture),onBlurCapture:se(e.onBlurCapture,_.onBlurCapture),onPointerDownCapture:se(e.onPointerDownCapture,E.onPointerDownCapture)}))}),gY=x.forwardRef((e,t)=>{const n=x.useContext(nM),r=x.useRef(null),o=Xe(t,r);return x.useEffect(()=>{const s=r.current;if(s)return n.branches.add(s),()=>{n.branches.delete(s)}},[n.branches]),x.createElement(Ke.div,X({},e,{ref:o}))});function mY(e,t=globalThis==null?void 0:globalThis.document){const n=sn(e),r=x.useRef(!1),o=x.useRef(()=>{});return x.useEffect(()=>{const s=a=>{if(a.target&&!r.current){let u=function(){rM(pY,n,c,{discrete:!0})};var l=u;const c={originalEvent:a};a.pointerType==="touch"?(t.removeEventListener("click",o.current),o.current=u,t.addEventListener("click",o.current,{once:!0})):u()}else t.removeEventListener("click",o.current);r.current=!1},i=window.setTimeout(()=>{t.addEventListener("pointerdown",s)},0);return()=>{window.clearTimeout(i),t.removeEventListener("pointerdown",s),t.removeEventListener("click",o.current)}},[t,n]),{onPointerDownCapture:()=>r.current=!0}}function yY(e,t=globalThis==null?void 0:globalThis.document){const n=sn(e),r=x.useRef(!1);return x.useEffect(()=>{const o=s=>{s.target&&!r.current&&rM(fY,n,{originalEvent:s},{discrete:!1})};return t.addEventListener("focusin",o),()=>t.removeEventListener("focusin",o)},[t,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function TC(){const e=new CustomEvent(uv);document.dispatchEvent(e)}function rM(e,t,n,{discrete:r}){const o=n.originalEvent.target,s=new CustomEvent(e,{bubbles:!1,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Rx(o,s):o.dispatchEvent(s)}const SY=Zf,vY=gY,Qf=x.forwardRef((e,t)=>{var n;const{container:r=globalThis==null||(n=globalThis.document)===null||n===void 0?void 0:n.body,...o}=e;return r?l4.createPortal(x.createElement(Ke.div,X({},o,{ref:t})),r):null}),Ai=globalThis!=null&&globalThis.document?x.useLayoutEffect:()=>{};function xY(e,t){return x.useReducer((n,r)=>{const o=t[n][r];return o??n},e)}const po=e=>{const{present:t,children:n}=e,r=wY(t),o=typeof n=="function"?n({present:r.isPresent}):x.Children.only(n),s=Xe(r.ref,o.ref);return typeof n=="function"||r.isPresent?x.cloneElement(o,{ref:s}):null};po.displayName="Presence";function wY(e){const[t,n]=x.useState(),r=x.useRef({}),o=x.useRef(e),s=x.useRef("none"),i=e?"mounted":"unmounted",[a,l]=xY(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return x.useEffect(()=>{const c=zd(r.current);s.current=a==="mounted"?c:"none"},[a]),Ai(()=>{const c=r.current,u=o.current;if(u!==e){const p=s.current,f=zd(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]),Ai(()=>{if(t){const c=d=>{const f=zd(r.current).includes(d.animationName);d.target===t&&f&&zi.flushSync(()=>l("ANIMATION_END"))},u=d=>{d.target===t&&(s.current=zd(r.current))};return t.addEventListener("animationstart",u),t.addEventListener("animationcancel",c),t.addEventListener("animationend",c),()=>{t.removeEventListener("animationstart",u),t.removeEventListener("animationcancel",c),t.removeEventListener("animationend",c)}}else l("ANIMATION_END")},[t,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:x.useCallback(c=>{c&&(r.current=getComputedStyle(c)),n(c)},[])}}function zd(e){return(e==null?void 0:e.animationName)||"none"}function Ys({prop:e,defaultProp:t,onChange:n=()=>{}}){const[r,o]=bY({defaultProp:t,onChange:n}),s=e!==void 0,i=s?e:r,a=sn(n),l=x.useCallback(c=>{if(s){const d=typeof c=="function"?c(e):c;d!==e&&a(d)}else o(c)},[s,e,o,a]);return[i,l]}function bY({defaultProp:e,onChange:t}){const n=x.useState(e),[r]=n,o=x.useRef(r),s=sn(t);return x.useEffect(()=>{o.current!==r&&(s(r),o.current=r)},[r,o,s]),n}const oM=x.forwardRef((e,t)=>x.createElement(Ke.span,X({},e,{ref:t,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}}))),sM="ToastProvider",[Lx,PY,CY]=qf("Toast"),[iM,Hre]=ho("Toast",[CY]),[IY,Jf]=iM(sM),aM=e=>{const{__scopeToast:t,label:n="Notification",duration:r=5e3,swipeDirection:o="right",swipeThreshold:s=50,children:i}=e,[a,l]=x.useState(null),[c,u]=x.useState(0),d=x.useRef(!1),p=x.useRef(!1);return x.createElement(Lx.Provider,{scope:t},x.createElement(IY,{scope:t,label:n,duration:r,swipeDirection:o,swipeThreshold:s,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:x.useCallback(()=>u(f=>f+1),[]),onToastRemove:x.useCallback(()=>u(f=>f-1),[]),isFocusedToastEscapeKeyDownRef:d,isClosePausedRef:p},i))};aM.propTypes={label(e){if(e.label&&typeof e.label=="string"&&!e.label.trim()){const t=`Invalid prop \`label\` supplied to \`${sM}\`. Expected non-empty \`string\`.`;return new Error(t)}return null}};const EY="ToastViewport",_Y=["F8"],dv="toast.viewportPause",hv="toast.viewportResume",kY=x.forwardRef((e,t)=>{const{__scopeToast:n,hotkey:r=_Y,label:o="Notifications ({hotkey})",...s}=e,i=Jf(EY,n),a=PY(n),l=x.useRef(null),c=x.useRef(null),u=x.useRef(null),d=x.useRef(null),p=Xe(t,d,i.onViewportChange),f=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),y=i.toastCount>0;x.useEffect(()=>{const w=S=>{var v;r.every(I=>S[I]||S.code===I)&&((v=d.current)===null||v===void 0||v.focus())};return document.addEventListener("keydown",w),()=>document.removeEventListener("keydown",w)},[r]),x.useEffect(()=>{const w=l.current,S=d.current;if(y&&w&&S){const v=()=>{if(!i.isClosePausedRef.current){const E=new CustomEvent(dv);S.dispatchEvent(E),i.isClosePausedRef.current=!0}},C=()=>{if(i.isClosePausedRef.current){const E=new CustomEvent(hv);S.dispatchEvent(E),i.isClosePausedRef.current=!1}},I=E=>{!w.contains(E.relatedTarget)&&C()},P=()=>{w.contains(document.activeElement)||C()};return w.addEventListener("focusin",v),w.addEventListener("focusout",I),w.addEventListener("pointermove",v),w.addEventListener("pointerleave",P),window.addEventListener("blur",v),window.addEventListener("focus",C),()=>{w.removeEventListener("focusin",v),w.removeEventListener("focusout",I),w.removeEventListener("pointermove",v),w.removeEventListener("pointerleave",P),window.removeEventListener("blur",v),window.removeEventListener("focus",C)}}},[y,i.isClosePausedRef]);const g=x.useCallback(({tabbingDirection:w})=>{const v=a().map(C=>{const I=C.ref.current,P=[I,...KY(I)];return w==="forwards"?P:P.reverse()});return(w==="forwards"?v.reverse():v).flat()},[a]);return x.useEffect(()=>{const w=d.current;if(w){const S=v=>{const C=v.altKey||v.ctrlKey||v.metaKey;if(v.key==="Tab"&&!C){const k=document.activeElement,$=v.shiftKey;if(v.target===w&&$){var P;(P=c.current)===null||P===void 0||P.focus();return}const L=g({tabbingDirection:$?"backwards":"forwards"}),N=L.findIndex(F=>F===k);if(Wm(L.slice(N+1)))v.preventDefault();else{var E,_;$?(E=c.current)===null||E===void 0||E.focus():(_=u.current)===null||_===void 0||_.focus()}}};return w.addEventListener("keydown",S),()=>w.removeEventListener("keydown",S)}},[a,g]),x.createElement(vY,{ref:l,role:"region","aria-label":o.replace("{hotkey}",f),tabIndex:-1,style:{pointerEvents:y?void 0:"none"}},y&&x.createElement($C,{ref:c,onFocusFromOutsideViewport:()=>{const w=g({tabbingDirection:"forwards"});Wm(w)}}),x.createElement(Lx.Slot,{scope:n},x.createElement(Ke.ol,X({tabIndex:-1},s,{ref:p}))),y&&x.createElement($C,{ref:u,onFocusFromOutsideViewport:()=>{const w=g({tabbingDirection:"backwards"});Wm(w)}}))}),TY="ToastFocusProxy",$C=x.forwardRef((e,t)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...o}=e,s=Jf(TY,n);return x.createElement(oM,X({"aria-hidden":!0,tabIndex:0},o,{ref:t,style:{position:"fixed"},onFocus:i=>{var a;const l=i.relatedTarget;!((a=s.viewport)!==null&&a!==void 0&&a.contains(l))&&r()}}))}),eg="Toast",$Y="toast.swipeStart",MY="toast.swipeMove",AY="toast.swipeCancel",jY="toast.swipeEnd",OY=x.forwardRef((e,t)=>{const{forceMount:n,open:r,defaultOpen:o,onOpenChange:s,...i}=e,[a=!0,l]=Ys({prop:r,defaultProp:o,onChange:s});return x.createElement(po,{present:n||a},x.createElement(lM,X({open:a},i,{ref:t,onClose:()=>l(!1),onPause:sn(e.onPause),onResume:sn(e.onResume),onSwipeStart:se(e.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:se(e.onSwipeMove,c=>{const{x:u,y:d}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${d}px`)}),onSwipeCancel:se(e.onSwipeCancel,c=>{c.currentTarget.setAttribute("data-swipe","cancel"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-end-y")}),onSwipeEnd:se(e.onSwipeEnd,c=>{const{x:u,y:d}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${d}px`),l(!1)})})))}),[DY,RY]=iM(eg,{onClose(){}}),lM=x.forwardRef((e,t)=>{const{__scopeToast:n,type:r="foreground",duration:o,open:s,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:d,onSwipeCancel:p,onSwipeEnd:f,...y}=e,g=Jf(eg,n),[w,S]=x.useState(null),v=Xe(t,F=>S(F)),C=x.useRef(null),I=x.useRef(null),P=o||g.duration,E=x.useRef(0),_=x.useRef(P),k=x.useRef(0),{onToastAdd:$,onToastRemove:T}=g,j=sn(()=>{var F;(w==null?void 0:w.contains(document.activeElement))&&((F=g.viewport)===null||F===void 0||F.focus()),i()}),L=x.useCallback(F=>{!F||F===1/0||(window.clearTimeout(k.current),E.current=new Date().getTime(),k.current=window.setTimeout(j,F))},[j]);x.useEffect(()=>{const F=g.viewport;if(F){const B=()=>{L(_.current),c==null||c()},q=()=>{const Q=new Date().getTime()-E.current;_.current=_.current-Q,window.clearTimeout(k.current),l==null||l()};return F.addEventListener(dv,q),F.addEventListener(hv,B),()=>{F.removeEventListener(dv,q),F.removeEventListener(hv,B)}}},[g.viewport,P,l,c,L]),x.useEffect(()=>{s&&!g.isClosePausedRef.current&&L(P)},[s,P,g.isClosePausedRef,L]),x.useEffect(()=>($(),()=>T()),[$,T]);const N=x.useMemo(()=>w?hM(w):null,[w]);return g.viewport?x.createElement(x.Fragment,null,N&&x.createElement(LY,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0},N),x.createElement(DY,{scope:n,onClose:j},zi.createPortal(x.createElement(Lx.ItemSlot,{scope:n},x.createElement(SY,{asChild:!0,onEscapeKeyDown:se(a,()=>{g.isFocusedToastEscapeKeyDownRef.current||j(),g.isFocusedToastEscapeKeyDownRef.current=!1})},x.createElement(Ke.li,X({role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":s?"open":"closed","data-swipe-direction":g.swipeDirection},y,{ref:v,style:{userSelect:"none",touchAction:"none",...e.style},onKeyDown:se(e.onKeyDown,F=>{F.key==="Escape"&&(a==null||a(F.nativeEvent),F.nativeEvent.defaultPrevented||(g.isFocusedToastEscapeKeyDownRef.current=!0,j()))}),onPointerDown:se(e.onPointerDown,F=>{F.button===0&&(C.current={x:F.clientX,y:F.clientY})}),onPointerMove:se(e.onPointerMove,F=>{if(!C.current)return;const B=F.clientX-C.current.x,q=F.clientY-C.current.y,Q=!!I.current,V=["left","right"].includes(g.swipeDirection),U=["left","up"].includes(g.swipeDirection)?Math.min:Math.max,H=V?U(0,B):0,Z=V?0:U(0,q),ce=F.pointerType==="touch"?10:2,be={x:H,y:Z},ke={originalEvent:F,delta:be};Q?(I.current=be,Bd(MY,d,ke,{discrete:!1})):MC(be,g.swipeDirection,ce)?(I.current=be,Bd($Y,u,ke,{discrete:!1}),F.target.setPointerCapture(F.pointerId)):(Math.abs(B)>ce||Math.abs(q)>ce)&&(C.current=null)}),onPointerUp:se(e.onPointerUp,F=>{const B=I.current,q=F.target;if(q.hasPointerCapture(F.pointerId)&&q.releasePointerCapture(F.pointerId),I.current=null,C.current=null,B){const Q=F.currentTarget,V={originalEvent:F,delta:B};MC(B,g.swipeDirection,g.swipeThreshold)?Bd(jY,f,V,{discrete:!0}):Bd(AY,p,V,{discrete:!0}),Q.addEventListener("click",U=>U.preventDefault(),{once:!0})}})})))),g.viewport))):null});lM.propTypes={type(e){if(e.type&&!["foreground","background"].includes(e.type)){const t=`Invalid prop \`type\` supplied to \`${eg}\`. Expected \`foreground | background\`.`;return new Error(t)}return null}};const LY=e=>{const{__scopeToast:t,children:n,...r}=e,o=Jf(eg,t),[s,i]=x.useState(!1),[a,l]=x.useState(!1);return UY(()=>i(!0)),x.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:x.createElement(Qf,{asChild:!0},x.createElement(oM,r,s&&x.createElement(x.Fragment,null,o.label," ",n)))},FY=x.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return x.createElement(Ke.div,X({},r,{ref:t}))}),NY=x.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e;return x.createElement(Ke.div,X({},r,{ref:t}))}),zY="ToastAction",cM=x.forwardRef((e,t)=>{const{altText:n,...r}=e;return n?x.createElement(dM,{altText:n,asChild:!0},x.createElement(uM,X({},r,{ref:t}))):null});cM.propTypes={altText(e){return e.altText?null:new Error(`Missing prop \`altText\` expected on \`${zY}\``)}};const BY="ToastClose",uM=x.forwardRef((e,t)=>{const{__scopeToast:n,...r}=e,o=RY(BY,n);return x.createElement(dM,{asChild:!0},x.createElement(Ke.button,X({type:"button"},r,{ref:t,onClick:se(e.onClick,o.onClose)})))}),dM=x.forwardRef((e,t)=>{const{__scopeToast:n,altText:r,...o}=e;return x.createElement(Ke.div,X({"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0},o,{ref:t}))});function hM(e){const t=[];return Array.from(e.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&t.push(r.textContent),HY(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&&t.push(i)}else t.push(...hM(r))}}),t}function Bd(e,t,n,{discrete:r}){const o=n.originalEvent.currentTarget,s=new CustomEvent(e,{bubbles:!0,cancelable:!0,detail:n});t&&o.addEventListener(e,t,{once:!0}),r?Rx(o,s):o.dispatchEvent(s)}const MC=(e,t,n=0)=>{const r=Math.abs(e.x),o=Math.abs(e.y),s=r>o;return t==="left"||t==="right"?s&&r>n:!s&&o>n};function UY(e=()=>{}){const t=sn(e);Ai(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(t)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[t])}function HY(e){return e.nodeType===e.ELEMENT_NODE}function KY(e){const t=[],n=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(;n.nextNode();)t.push(n.currentNode);return t}function Wm(e){const t=document.activeElement;return e.some(n=>n===t?!0:(n.focus(),document.activeElement!==t))}const VY=OY,WY=FY,GY=NY,YY=cM,AC=uM,XY=XO.useId||(()=>{});let qY=0;function Ro(e){const[t,n]=x.useState(XY());return Ai(()=>{e||n(r=>r??String(qY++))},[e]),e||(t?`radix-${t}`:"")}const Gm="focusScope.autoFocusOnMount",Ym="focusScope.autoFocusOnUnmount",jC={bubbles:!1,cancelable:!0},Fx=x.forwardRef((e,t)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:o,onUnmountAutoFocus:s,...i}=e,[a,l]=x.useState(null),c=sn(o),u=sn(s),d=x.useRef(null),p=Xe(t,g=>l(g)),f=x.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;x.useEffect(()=>{if(r){let v=function(E){if(f.paused||!a)return;const _=E.target;a.contains(_)?d.current=_:cs(d.current,{select:!0})},C=function(E){if(f.paused||!a)return;const _=E.relatedTarget;_!==null&&(a.contains(_)||cs(d.current,{select:!0}))},I=function(E){if(document.activeElement===document.body)for(const k of E)k.removedNodes.length>0&&cs(a)};var g=v,w=C,S=I;document.addEventListener("focusin",v),document.addEventListener("focusout",C);const P=new MutationObserver(I);return a&&P.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",v),document.removeEventListener("focusout",C),P.disconnect()}}},[r,a,f.paused]),x.useEffect(()=>{if(a){DC.add(f);const g=document.activeElement;if(!a.contains(g)){const S=new CustomEvent(Gm,jC);a.addEventListener(Gm,c),a.dispatchEvent(S),S.defaultPrevented||(ZY(nX(pM(a)),{select:!0}),document.activeElement===g&&cs(a))}return()=>{a.removeEventListener(Gm,c),setTimeout(()=>{const S=new CustomEvent(Ym,jC);a.addEventListener(Ym,u),a.dispatchEvent(S),S.defaultPrevented||cs(g??document.body,{select:!0}),a.removeEventListener(Ym,u),DC.remove(f)},0)}}},[a,c,u,f]);const y=x.useCallback(g=>{if(!n&&!r||f.paused)return;const w=g.key==="Tab"&&!g.altKey&&!g.ctrlKey&&!g.metaKey,S=document.activeElement;if(w&&S){const v=g.currentTarget,[C,I]=QY(v);C&&I?!g.shiftKey&&S===I?(g.preventDefault(),n&&cs(C,{select:!0})):g.shiftKey&&S===C&&(g.preventDefault(),n&&cs(I,{select:!0})):S===v&&g.preventDefault()}},[n,r,f.paused]);return x.createElement(Ke.div,X({tabIndex:-1},i,{ref:p,onKeyDown:y}))});function ZY(e,{select:t=!1}={}){const n=document.activeElement;for(const r of e)if(cs(r,{select:t}),document.activeElement!==n)return}function QY(e){const t=pM(e),n=OC(t,e),r=OC(t.reverse(),e);return[n,r]}function pM(e){const t=[],n=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(;n.nextNode();)t.push(n.currentNode);return t}function OC(e,t){for(const n of e)if(!JY(n,{upTo:t}))return n}function JY(e,{upTo:t}){if(getComputedStyle(e).visibility==="hidden")return!0;for(;e;){if(t!==void 0&&e===t)return!1;if(getComputedStyle(e).display==="none")return!0;e=e.parentElement}return!1}function eX(e){return e instanceof HTMLInputElement&&"select"in e}function cs(e,{select:t=!1}={}){if(e&&e.focus){const n=document.activeElement;e.focus({preventScroll:!0}),e!==n&&eX(e)&&t&&e.select()}}const DC=tX();function tX(){let e=[];return{add(t){const n=e[0];t!==n&&(n==null||n.pause()),e=RC(e,t),e.unshift(t)},remove(t){var n;e=RC(e,t),(n=e[0])===null||n===void 0||n.resume()}}}function RC(e,t){const n=[...e],r=n.indexOf(t);return r!==-1&&n.splice(r,1),n}function nX(e){return e.filter(t=>t.tagName!=="A")}let Xm=0;function Nx(){x.useEffect(()=>{var e,t;const n=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",(e=n[0])!==null&&e!==void 0?e:LC()),document.body.insertAdjacentElement("beforeend",(t=n[1])!==null&&t!==void 0?t:LC()),Xm++,()=>{Xm===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(r=>r.remove()),Xm--}},[])}function LC(){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 qr=function(){return qr=Object.assign||function(t){for(var n,r=1,o=arguments.length;r<o;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(t[s]=n[s])}return t},qr.apply(this,arguments)};function fM(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]]);return n}function rX(e,t,n){if(n||arguments.length===2)for(var r=0,o=t.length,s;r<o;r++)(s||!(r in t))&&(s||(s=Array.prototype.slice.call(t,0,r)),s[r]=t[r]);return e.concat(s||Array.prototype.slice.call(t))}var Yh="right-scroll-bar-position",Xh="width-before-scroll-bar",oX="with-scroll-bars-hidden",sX="--removed-body-scroll-bar-size";function qm(e,t){return typeof e=="function"?e(t):e&&(e.current=t),e}function iX(e,t){var n=x.useState(function(){return{value:e,callback:t,facade:{get current(){return n.value},set current(r){var o=n.value;o!==r&&(n.value=r,n.callback(r,o))}}}})[0];return n.callback=t,n.facade}var aX=typeof window<"u"?x.useLayoutEffect:x.useEffect,FC=new WeakMap;function lX(e,t){var n=iX(t||null,function(r){return e.forEach(function(o){return qm(o,r)})});return aX(function(){var r=FC.get(n);if(r){var o=new Set(r),s=new Set(e),i=n.current;o.forEach(function(a){s.has(a)||qm(a,null)}),s.forEach(function(a){o.has(a)||qm(a,i)})}FC.set(n,e)},[e]),n}function cX(e){return e}function uX(e,t){t===void 0&&(t=cX);var n=[],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 n.length?n[n.length-1]:e},useMedium:function(s){var i=t(s,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(s){for(r=!0;n.length;){var i=n;n=[],i.forEach(s)}n={push:function(a){return s(a)},filter:function(){return n}}},assignMedium:function(s){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(s),i=n}var l=function(){var u=i;i=[],u.forEach(s)},c=function(){return Promise.resolve().then(l)};c(),n={push:function(u){i.push(u),c()},filter:function(u){return i=i.filter(u),n}}}};return o}function dX(e){e===void 0&&(e={});var t=uX(null);return t.options=qr({async:!0,ssr:!1},e),t}var gM=function(e){var t=e.sideCar,n=fM(e,["sideCar"]);if(!t)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=t.read();if(!r)throw new Error("Sidecar medium not found");return x.createElement(r,qr({},n))};gM.isSideCarExport=!0;function hX(e,t){return e.useMedium(t),gM}var mM=dX(),Zm=function(){},tg=x.forwardRef(function(e,t){var n=x.useRef(null),r=x.useState({onScrollCapture:Zm,onWheelCapture:Zm,onTouchMoveCapture:Zm}),o=r[0],s=r[1],i=e.forwardProps,a=e.children,l=e.className,c=e.removeScrollBar,u=e.enabled,d=e.shards,p=e.sideCar,f=e.noIsolation,y=e.inert,g=e.allowPinchZoom,w=e.as,S=w===void 0?"div":w,v=fM(e,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as"]),C=p,I=lX([n,t]),P=qr(qr({},v),o);return x.createElement(x.Fragment,null,u&&x.createElement(C,{sideCar:mM,removeScrollBar:c,shards:d,noIsolation:f,inert:y,setCallbacks:s,allowPinchZoom:!!g,lockRef:n}),i?x.cloneElement(x.Children.only(a),qr(qr({},P),{ref:I})):x.createElement(S,qr({},P,{className:l,ref:I}),a))});tg.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};tg.classNames={fullWidth:Xh,zeroRight:Yh};var pX=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function fX(){if(!document)return null;var e=document.createElement("style");e.type="text/css";var t=pX();return t&&e.setAttribute("nonce",t),e}function gX(e,t){e.styleSheet?e.styleSheet.cssText=t:e.appendChild(document.createTextNode(t))}function mX(e){var t=document.head||document.getElementsByTagName("head")[0];t.appendChild(e)}var yX=function(){var e=0,t=null;return{add:function(n){e==0&&(t=fX())&&(gX(t,n),mX(t)),e++},remove:function(){e--,!e&&t&&(t.parentNode&&t.parentNode.removeChild(t),t=null)}}},SX=function(){var e=yX();return function(t,n){x.useEffect(function(){return e.add(t),function(){e.remove()}},[t&&n])}},yM=function(){var e=SX(),t=function(n){var r=n.styles,o=n.dynamic;return e(r,o),null};return t},vX={left:0,top:0,right:0,gap:0},Qm=function(e){return parseInt(e||"",10)||0},xX=function(e){var t=window.getComputedStyle(document.body),n=t[e==="padding"?"paddingLeft":"marginLeft"],r=t[e==="padding"?"paddingTop":"marginTop"],o=t[e==="padding"?"paddingRight":"marginRight"];return[Qm(n),Qm(r),Qm(o)]},wX=function(e){if(e===void 0&&(e="margin"),typeof window>"u")return vX;var t=xX(e),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:t[0],top:t[1],right:t[2],gap:Math.max(0,r-n+t[2]-t[0])}},bX=yM(),Ka="data-scroll-locked",PX=function(e,t,n,r){var o=e.left,s=e.top,i=e.right,a=e.gap;return n===void 0&&(n="margin"),`
178
- .`.concat(oX,` {
179
- overflow: hidden `).concat(r,`;
180
- padding-right: `).concat(a,"px ").concat(r,`;
181
- }
182
- body[`).concat(Ka,`] {
183
- overflow: hidden `).concat(r,`;
184
- overscroll-behavior: contain;
185
- `).concat([t&&"position: relative ".concat(r,";"),n==="margin"&&`
186
- padding-left: `.concat(o,`px;
187
- padding-top: `).concat(s,`px;
188
- padding-right: `).concat(i,`px;
189
- margin-left:0;
190
- margin-top:0;
191
- margin-right: `).concat(a,"px ").concat(r,`;
192
- `),n==="padding"&&"padding-right: ".concat(a,"px ").concat(r,";")].filter(Boolean).join(""),`
193
- }
194
-
195
- .`).concat(Yh,` {
196
- right: `).concat(a,"px ").concat(r,`;
197
- }
198
-
199
- .`).concat(Xh,` {
200
- margin-right: `).concat(a,"px ").concat(r,`;
201
- }
202
-
203
- .`).concat(Yh," .").concat(Yh,` {
204
- right: 0 `).concat(r,`;
205
- }
206
-
207
- .`).concat(Xh," .").concat(Xh,` {
208
- margin-right: 0 `).concat(r,`;
209
- }
210
-
211
- body[`).concat(Ka,`] {
212
- `).concat(sX,": ").concat(a,`px;
213
- }
214
- `)},NC=function(){var e=parseInt(document.body.getAttribute(Ka)||"0",10);return isFinite(e)?e:0},CX=function(){x.useEffect(function(){return document.body.setAttribute(Ka,(NC()+1).toString()),function(){var e=NC()-1;e<=0?document.body.removeAttribute(Ka):document.body.setAttribute(Ka,e.toString())}},[])},IX=function(e){var t=e.noRelative,n=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r;CX();var s=x.useMemo(function(){return wX(o)},[o]);return x.createElement(bX,{styles:PX(s,!t,o,n?"":"!important")})},pv=!1;if(typeof window<"u")try{var Ud=Object.defineProperty({},"passive",{get:function(){return pv=!0,!0}});window.addEventListener("test",Ud,Ud),window.removeEventListener("test",Ud,Ud)}catch{pv=!1}var la=pv?{passive:!1}:!1,EX=function(e){return e.tagName==="TEXTAREA"},SM=function(e,t){var n=window.getComputedStyle(e);return n[t]!=="hidden"&&!(n.overflowY===n.overflowX&&!EX(e)&&n[t]==="visible")},_X=function(e){return SM(e,"overflowY")},kX=function(e){return SM(e,"overflowX")},zC=function(e,t){var n=t;do{typeof ShadowRoot<"u"&&n instanceof ShadowRoot&&(n=n.host);var r=vM(e,n);if(r){var o=xM(e,n),s=o[1],i=o[2];if(s>i)return!0}n=n.parentNode}while(n&&n!==document.body);return!1},TX=function(e){var t=e.scrollTop,n=e.scrollHeight,r=e.clientHeight;return[t,n,r]},$X=function(e){var t=e.scrollLeft,n=e.scrollWidth,r=e.clientWidth;return[t,n,r]},vM=function(e,t){return e==="v"?_X(t):kX(t)},xM=function(e,t){return e==="v"?TX(t):$X(t)},MX=function(e,t){return e==="h"&&t==="rtl"?-1:1},AX=function(e,t,n,r,o){var s=MX(e,window.getComputedStyle(t).direction),i=s*r,a=n.target,l=t.contains(a),c=!1,u=i>0,d=0,p=0;do{var f=xM(e,a),y=f[0],g=f[1],w=f[2],S=g-w-s*y;(y||S)&&vM(e,a)&&(d+=S,p+=y),a=a.parentNode}while(!l&&a!==document.body||l&&(t.contains(a)||t===a));return(u&&(o&&d===0||!o&&i>d)||!u&&(o&&p===0||!o&&-i>p))&&(c=!0),c},Hd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},BC=function(e){return[e.deltaX,e.deltaY]},UC=function(e){return e&&"current"in e?e.current:e},jX=function(e,t){return e[0]===t[0]&&e[1]===t[1]},OX=function(e){return`
215
- .block-interactivity-`.concat(e,` {pointer-events: none;}
216
- .allow-interactivity-`).concat(e,` {pointer-events: all;}
217
- `)},DX=0,ca=[];function RX(e){var t=x.useRef([]),n=x.useRef([0,0]),r=x.useRef(),o=x.useState(DX++)[0],s=x.useState(function(){return yM()})[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=rX([e.lockRef.current],(e.shards||[]).map(UC),!0).filter(Boolean);return g.forEach(function(w){return w.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(w){return w.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(g,w){if("touches"in g&&g.touches.length===2)return!i.current.allowPinchZoom;var S=Hd(g),v=n.current,C="deltaX"in g?g.deltaX:v[0]-S[0],I="deltaY"in g?g.deltaY:v[1]-S[1],P,E=g.target,_=Math.abs(C)>Math.abs(I)?"h":"v";if("touches"in g&&_==="h"&&E.type==="range")return!1;var k=zC(_,E);if(!k)return!0;if(k?P=_:(P=_==="v"?"h":"v",k=zC(_,E)),!k)return!1;if(!r.current&&"changedTouches"in g&&(C||I)&&(r.current=P),!P)return!0;var $=r.current||P;return AX($,w,g,$==="h"?C:I,!0)},[]),l=x.useCallback(function(g){var w=g;if(!(!ca.length||ca[ca.length-1]!==s)){var S="deltaY"in w?BC(w):Hd(w),v=t.current.filter(function(P){return P.name===w.type&&P.target===w.target&&jX(P.delta,S)})[0];if(v&&v.should){w.cancelable&&w.preventDefault();return}if(!v){var C=(i.current.shards||[]).map(UC).filter(Boolean).filter(function(P){return P.contains(w.target)}),I=C.length>0?a(w,C[0]):!i.current.noIsolation;I&&w.cancelable&&w.preventDefault()}}},[]),c=x.useCallback(function(g,w,S,v){var C={name:g,delta:w,target:S,should:v};t.current.push(C),setTimeout(function(){t.current=t.current.filter(function(I){return I!==C})},1)},[]),u=x.useCallback(function(g){n.current=Hd(g),r.current=void 0},[]),d=x.useCallback(function(g){c(g.type,BC(g),g.target,a(g,e.lockRef.current))},[]),p=x.useCallback(function(g){c(g.type,Hd(g),g.target,a(g,e.lockRef.current))},[]);x.useEffect(function(){return ca.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:p}),document.addEventListener("wheel",l,la),document.addEventListener("touchmove",l,la),document.addEventListener("touchstart",u,la),function(){ca=ca.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,la),document.removeEventListener("touchmove",l,la),document.removeEventListener("touchstart",u,la)}},[]);var f=e.removeScrollBar,y=e.inert;return x.createElement(x.Fragment,null,y?x.createElement(s,{styles:OX(o)}):null,f?x.createElement(IX,{gapMode:"margin"}):null)}const LX=hX(mM,RX);var wM=x.forwardRef(function(e,t){return x.createElement(tg,qr({},e,{ref:t,sideCar:LX}))});wM.classNames=tg.classNames;const zx=wM;var FX=function(e){if(typeof document>"u")return null;var t=Array.isArray(e)?e[0]:e;return t.ownerDocument.body},ua=new WeakMap,Kd=new WeakMap,Vd={},Jm=0,bM=function(e){return e&&(e.host||bM(e.parentNode))},NX=function(e,t){return t.map(function(n){if(e.contains(n))return n;var r=bM(n);return r&&e.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",e,". Doing nothing"),null)}).filter(function(n){return!!n})},zX=function(e,t,n,r){var o=NX(t,Array.isArray(e)?e:[e]);Vd[n]||(Vd[n]=new WeakMap);var s=Vd[n],i=[],a=new Set,l=new Set(o),c=function(d){!d||a.has(d)||(a.add(d),c(d.parentNode))};o.forEach(c);var u=function(d){!d||l.has(d)||Array.prototype.forEach.call(d.children,function(p){if(a.has(p))u(p);else try{var f=p.getAttribute(r),y=f!==null&&f!=="false",g=(ua.get(p)||0)+1,w=(s.get(p)||0)+1;ua.set(p,g),s.set(p,w),i.push(p),g===1&&y&&Kd.set(p,!0),w===1&&p.setAttribute(n,"true"),y||p.setAttribute(r,"true")}catch(S){console.error("aria-hidden: cannot operate on ",p,S)}})};return u(t),a.clear(),Jm++,function(){i.forEach(function(d){var p=ua.get(d)-1,f=s.get(d)-1;ua.set(d,p),s.set(d,f),p||(Kd.has(d)||d.removeAttribute(r),Kd.delete(d)),f||d.removeAttribute(n)}),Jm--,Jm||(ua=new WeakMap,ua=new WeakMap,Kd=new WeakMap,Vd={})}},Bx=function(e,t,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(e)?e:[e]),o=t||FX(e);return o?(r.push.apply(r,Array.from(o.querySelectorAll("[aria-live]"))),zX(r,o,n,"aria-hidden")):function(){return null}};const PM="Dialog",[CM,Kre]=ho(PM),[BX,ts]=CM(PM),UX=e=>{const{__scopeDialog:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),l=x.useRef(null),[c=!1,u]=Ys({prop:r,defaultProp:o,onChange:s});return x.createElement(BX,{scope:t,triggerRef:a,contentRef:l,contentId:Ro(),titleId:Ro(),descriptionId:Ro(),open:c,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(d=>!d),[u]),modal:i},n)},IM="DialogPortal",[HX,EM]=CM(IM,{forceMount:void 0}),KX=e=>{const{__scopeDialog:t,forceMount:n,children:r,container:o}=e,s=ts(IM,t);return x.createElement(HX,{scope:t,forceMount:n},x.Children.map(r,i=>x.createElement(po,{present:n||s.open},x.createElement(Qf,{asChild:!0,container:o},i))))},fv="DialogOverlay",VX=x.forwardRef((e,t)=>{const n=EM(fv,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ts(fv,e.__scopeDialog);return s.modal?x.createElement(po,{present:r||s.open},x.createElement(WX,X({},o,{ref:t}))):null}),WX=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ts(fv,n);return x.createElement(zx,{as:Mi,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(Ke.div,X({"data-state":kM(o.open)},r,{ref:t,style:{pointerEvents:"auto",...r.style}})))}),cu="DialogContent",GX=x.forwardRef((e,t)=>{const n=EM(cu,e.__scopeDialog),{forceMount:r=n.forceMount,...o}=e,s=ts(cu,e.__scopeDialog);return x.createElement(po,{present:r||s.open},s.modal?x.createElement(YX,X({},o,{ref:t})):x.createElement(XX,X({},o,{ref:t})))}),YX=x.forwardRef((e,t)=>{const n=ts(cu,e.__scopeDialog),r=x.useRef(null),o=Xe(t,n.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return Bx(s)},[]),x.createElement(_M,X({},e,{ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=n.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault())}))}),XX=x.forwardRef((e,t)=>{const n=ts(cu,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(_M,X({},e,{ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=n.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=n.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),_M=x.forwardRef((e,t)=>{const{__scopeDialog:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=ts(cu,n),l=x.useRef(null),c=Xe(t,l);return Nx(),x.createElement(x.Fragment,null,x.createElement(Fx,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(Zf,X({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":kM(a.open)},i,{ref:c,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),qX="DialogTitle",ZX=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ts(qX,n);return x.createElement(Ke.h2,X({id:o.titleId},r,{ref:t}))});const QX="DialogClose",JX=x.forwardRef((e,t)=>{const{__scopeDialog:n,...r}=e,o=ts(QX,n);return x.createElement(Ke.button,X({type:"button"},r,{ref:t,onClick:se(e.onClick,()=>o.onOpenChange(!1))}))});function kM(e){return e?"open":"closed"}const eq=UX,tq=KX,nq=VX,rq=GX,TM=()=>{},$M=x.createContext({});function oq({onEvent:e,children:t}){return h.jsx($M.Provider,{value:e??TM,children:t})}function fo(){return x.useContext($M)??TM}const MM=x.createContext({});function sq({children:e}){const t=z(),n=fo(),[r,o]=x.useState([]),s=x.useCallback(c=>{const u=c.id??nt();return o(d=>[...d.filter(p=>p.id!==c.id),{...c,id:u}]),n("open-menu",{source:"dialog",id:u}),t.addOpenMenu(u),u},[t,n]),i=x.useCallback((c,u)=>(o(d=>d.map(p=>p.id===c?{...p,...u}:p)),n("open-menu",{source:"dialog",id:c}),t.addOpenMenu(c),c),[t,n]),a=x.useCallback(c=>(o(u=>u.filter(d=>{var p;return d.id===c?((p=d.onClose)==null||p.call(d),!1):!0})),n("close-menu",{source:"dialog",id:c}),t.deleteOpenMenu(c),c),[t,n]),l=x.useCallback(()=>{o(c=>(c.forEach(u=>{var d;(d=u.onClose)==null||d.call(u),n("close-menu",{source:"dialog",id:u.id}),t.deleteOpenMenu(u.id)}),[]))},[t,n]);return h.jsx(MM.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function Vi(){const e=x.useContext(MM);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const iq=({id:e,component:t,onClose:n})=>{const{removeDialog:r}=Vi(),o=ln(),s=x.useCallback(i=>{if(!i){if(n)try{n()}catch(a){console.warn(a)}r(e)}},[e,n,r]);return h.jsx(eq,{onOpenChange:s,defaultOpen:!0,children:h.jsx(tq,{container:o,children:h.jsx(nq,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:h.jsx(rq,{dir:"ltr",className:"tlui-dialog__content",children:h.jsx(t,{onClose:()=>s(!1)})})})})})};function aq(){const{dialogs:e}=Vi();return h.jsx(h.Fragment,{children:e.map(t=>h.jsx(iq,{...t},t.id))})}const lq=Se.memo(aq);function cq(){const e=z(),t=K("follow",()=>e.getInstanceState().followingUserId,[e]);return t?h.jsx(uq,{userId:t}):null}function uq({userId:e}){const t=r_(e);return t?h.jsx("div",{className:"tlui-following-indicator",style:{borderColor:t.color}}):null}const AM=x.createContext({});function dq({children:e}){const[t,n]=x.useState([]),r=x.useCallback(i=>{const a=i.id??nt();return n(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=x.useCallback(i=>(n(a=>a.filter(l=>l.id!==i)),i),[]),s=x.useCallback(()=>{n(()=>[])},[]);return h.jsx(AM.Provider,{value:{toasts:t,addToast:r,removeToast:o,clearToasts:s},children:e})}function Br(){const e=x.useContext(AM);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}const pe=x.forwardRef(function({children:t,disabled:n,type:r,...o},s){const i=z(),a=s==null?void 0:s.current;return n&&a===document.activeElement&&i.getContainer().focus(),h.jsx("button",{ref:s,type:"button",draggable:!1,disabled:n,...o,className:ue("tlui-button",`tlui-button__${r}`,o.className),children:t})});function xt({children:e}){return h.jsx("span",{className:"tlui-button__label",children:e})}const Rs=x.memo(function({small:t,invertIcon:n,icon:r,color:o,className:s,...i}){const a=Ox(),l=a.icons[r]??a.icons["question-mark-circle"],c=x.useRef(null);return x.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]),h.jsx("div",{...i,ref:c,className:ue("tlui-icon",{"tlui-icon__small":t},s),style:{color:o,mask:`url(${l}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})}),hq={success:"check-circle",warning:"warning-triangle",error:"cross-circle",info:"info-circle"};function pq({toast:e}){const{removeToast:t}=Br(),n=_e(),r=i=>{i||t(e.id)},o=e.actions&&e.actions.length>0,s=e.icon||e.severity&&hq[e.severity];return h.jsxs(VY,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,"data-severity":e.severity,children:[s&&h.jsx("div",{className:"tlui-toast__icon",children:h.jsx(Rs,{icon:s})}),h.jsxs("div",{className:"tlui-toast__main",children:[h.jsxs("div",{className:"tlui-toast__content",children:[e.title&&h.jsx(WY,{className:"tlui-toast__title",children:e.title}),e.description&&h.jsx(GY,{className:"tlui-toast__description",children:e.description})]}),e.actions&&h.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((i,a)=>h.jsx(YY,{altText:i.label,asChild:!0,onClick:i.onClick,children:h.jsx(pe,{type:i.type,children:h.jsx(xt,{children:i.label})})},a)),h.jsx(AC,{asChild:!0,children:h.jsx(pe,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:h.jsx(xt,{children:e.closeLabel??n("toast.close")})})})]})]}),!o&&h.jsx(AC,{asChild:!0,children:h.jsx(pe,{type:"normal",className:"tlui-toast__close",children:h.jsx(xt,{children:e.closeLabel??n("toast.close")})})})]})}function fq(){const{toasts:e}=Br();return h.jsx(h.Fragment,{children:e.map(t=>h.jsx(pq,{toast:t},t.id))})}const gq=x.memo(fq);function mq(){const{toasts:e}=Br(),[t,n]=x.useState(!1);return x.useEffect(()=>{let r=!1;return e.length?n(!0):setTimeout(()=>{r||n(!1)},1e3),()=>{r=!0}},[e.length,n]),t?h.jsx(kY,{className:"tlui-toast__viewport"}):null}function Ie({icon:e,small:t,invertIcon:n}){return h.jsx(Rs,{className:"tlui-button__icon",icon:e,small:t,invertIcon:n})}const ey=[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 yi="2.1.0-canary.41601ac61ec7";let gv={fonts:{draw:`https://unpkg.com/@tldraw/assets@${yi}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${yi}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${yi}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${yi}/fonts/IBMPlexMono-Medium.woff2`}};function jM(e){return x.useMemo(()=>e?{fonts:{...gv.fonts,...e==null?void 0:e.fonts}}:gv,[e])}const yq=["align-bottom-center","align-bottom-left","align-bottom-right","align-bottom","align-center-center","align-center-horizontal","align-center-left","align-center-right","align-center-vertical","align-left","align-right","align-top-center","align-top-left","align-top-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","aspect-ratio","avatar","blob","bring-forward","bring-to-front","check-circle","check","checkbox-checked","checkbox-empty","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","collab","color","comment","cross-2","cross-circle","cross","dash-dashed","dash-dotted","dash-draw","dash-solid","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","error","external-link","file","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","hidden","image","info-circle","leading","link","lock-small","lock","menu","minus","mixed","pack","page","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","ruler","search","send-backward","send-to-back","settings-horizontal","settings-vertical-1","settings-vertical","share-1","share-2","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","status-online","stretch-horizontal","stretch-vertical","text-align-center","text-align-justify","text-align-left","text-align-right","tool-arrow","tool-embed","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-text","trash","triangle-down","triangle-up","twitter","undo","ungroup","unlock-small","unlock","vertical-align-center","vertical-align-end","vertical-align-start","visible","warning-triangle","zoom-in","zoom-out"];let Jl={...gv,icons:Object.fromEntries(yq.map(e=>[e,`https://unpkg.com/@tldraw/assets@${yi}/icons/icon/${e}.svg`])),translations:Object.fromEntries(Rc.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${yi}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Ya.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${yi}/embed-icons/${e.type}.png`]))};function Sq(e){return e?{fonts:Object.assign({...Jl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...Jl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...Jl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...Jl.translations},{...e==null?void 0:e.translations})}:Jl}function ng({className:e,children:t}){return h.jsx("div",{className:ue("tlui-dialog__header",e),children:t})}function rg({className:e,children:t}){return h.jsx(ZX,{dir:"ltr",className:ue("tlui-dialog__header__title",e),children:t})}function og(){return h.jsx("div",{className:"tlui-dialog__header__close",children:h.jsx(JX,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:h.jsx(pe,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:h.jsx(Ie,{small:!0,icon:"cross-2"})})})})}function uu({className:e,children:t,style:n}){return h.jsx("div",{className:ue("tlui-dialog__body",e),style:n,children:t})}function Ux({className:e,children:t}){return h.jsx("div",{className:ue("tlui-dialog__footer",e),children:t})}const Hx=x.forwardRef(function({className:t,label:n,icon:r,iconLeft:o,autoselect:s=!1,autofocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:d,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:f=!1,children:y,value:g},w){const S=z(),v=x.useRef(null);x.useImperativeHandle(w,()=>v.current);const C=_e(),I=x.useRef(a??""),P=x.useRef(a??""),[E,_]=x.useState(!1),k=x.useCallback(L=>{_(!0);const N=L.currentTarget;P.current=N.value,requestAnimationFrame(()=>{s&&N.select()})},[s]),$=x.useCallback(L=>{const N=L.currentTarget.value;P.current=N,u==null||u(N)},[u]),T=x.useCallback(L=>{switch(L.key){case"Enter":{L.currentTarget.blur(),rn(L),c==null||c(L.currentTarget.value);break}case"Escape":{L.currentTarget.value=I.current,L.currentTarget.blur(),rn(L),d==null||d(L.currentTarget.value);break}}},[c,d]),j=x.useCallback(L=>{_(!1);const N=L.currentTarget.value;p==null||p(N)},[p]);return x.useEffect(()=>{if(!S.environment.isIos)return;const L=window.visualViewport;if(E&&f&&L){const N=()=>{var F;(F=v.current)==null||F.scrollIntoView({block:"center"})};return L.addEventListener("resize",N),L.addEventListener("scroll",N),requestAnimationFrame(()=>{var F;(F=v.current)==null||F.scrollIntoView({block:"center"})}),()=>{L.removeEventListener("resize",N),L.removeEventListener("scroll",N)}}},[S,E,f]),h.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,n&&h.jsx("label",{children:C(n)}),o&&h.jsx(Rs,{icon:o,className:"tlui-icon-left",small:!0}),h.jsx("input",{ref:v,className:ue("tlui-input",t),type:"text",defaultValue:a,onKeyUp:T,onChange:$,onFocus:k,onBlur:j,autoFocus:i,placeholder:l,value:g}),r&&h.jsx(Rs,{icon:r,small:!!n})]})}),OM=tr(function({onClose:t}){const n=z(),r=_e(),o=Ox(),[s,i]=x.useState(null),[a,l]=x.useState(""),[c,u]=x.useState(null),[d,p]=x.useState(!1),f=x.useRef(-1);return h.jsxs(h.Fragment,{children:[h.jsxs(ng,{children:[h.jsx(rg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),h.jsx(og,{})]}),s?h.jsxs(h.Fragment,{children:[h.jsxs(uu,{className:"tlui-embed-dialog__enter",children:[h.jsx(Hx,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"http://example.com",autofocus:!0,onValueChange:y=>{l(y);const g=xs(y);u(g&&g.definition.type===s.type?g:null),p(!1),clearTimeout(f.current),f.current=setTimeout(()=>p(!g),320)}}),a===""?h.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[h.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&h.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",h.jsx(Rs,{icon:"external-link",small:!0})]})]}):h.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),h.jsxs(Ux,{className:"tlui-dialog__footer__actions",children:[h.jsx(pe,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:h.jsx(xt,{children:r("embed-dialog.back")})}),h.jsx("div",{className:"tlui-embed__spacer"}),h.jsx(pe,{type:"normal",onClick:t,children:h.jsx(xt,{children:r("embed-dialog.cancel")})}),h.jsx(pe,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageCenter(),embed:c.definition}),t())},children:h.jsx(xt,{children:r("embed-dialog.create")})})]})]}):h.jsx(h.Fragment,{children:h.jsx(uu,{className:"tlui-embed-dialog__list",children:Ya.map(y=>h.jsxs(pe,{type:"menu",onClick:()=>i(y),children:[h.jsx(xt,{children:y.title}),h.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})]},y.type))})})]})});function DM(){const e=z(),t=x.useRef();return x.useEffect(()=>{const n=window.document.createElement("input");n.type="file",n.accept="image/jpeg,image/png,image/gif,image/svg+xml,video/mp4,video/quicktime",n.multiple=!0,t.current=n;async function r(o){const s=o.target.files;!s||s.length===0||(await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),n.value="")}return n.addEventListener("change",r),()=>{t.current=void 0,n.removeEventListener("change",r)}},[e]),x.useCallback(()=>{var n;(n=t.current)==null||n.click()},[t])}const RM=x.createContext({});function vq({overrides:e,children:t}){const n=z(),r=fo(),{addDialog:o}=Vi(),s=DM(),i=x.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){n.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){n.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){n.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){n.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...eo.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){n.batch(()=>{n.updateInstanceState({stylesForNextShape:{...n.getInstanceState().stylesForNextShape,[eo.id]:c}},{ephemeral:!0}),n.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){n.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){n.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){n.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){n.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){n.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){n.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"tool-embed",onSelect(c){o({component:OM}),r("select-tool",{source:c,id:"embed"})}},{id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){n.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}}];a.push();const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(n,l,{insertMedia:s}):l},[e,n,r,s,o]);return h.jsx(RM.Provider,{value:i,children:t})}function De(){const e=x.useContext(RM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}const LM=Se.createContext(0);function xq({forceMobile:e=!1,children:t}){const n=z(),r=K("breakpoint",()=>{const{width:o}=n.getViewportScreenBounds(),s=e?yt.MOBILE_SM:ey.length-1;for(let i=0;i<s;i++)if(o>ey[i]&&o<=ey[i+1])return i;return s},[n]);return h.jsx(LM.Provider,{value:r,children:t})}function Ln(){return x.useContext(LM)}function wq(){const{addToast:e,removeToast:t,clearToasts:n}=Br(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=Vi(),l=Ln()<yt.TABLET_SM,c=_e();return x.useMemo(()=>({addToast:e,removeToast:t,clearToasts:n,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,e,o,n,c,s,t,i,l])}function bq(e,t){const n={};for(const r of e)if(r.translations)for(const[o,s]of Jr(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,t));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...t,...s}));return o},translations:n}}function FM(e){return x.useMemo(()=>e,e)}function Pq(e){const t=FM(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const n={};for(const r of t)if(r.translations)for(const[o,s]of Jr(r.translations)){let i=n[o];i||(i=n[o]={}),Object.assign(i,s)}return n},[t])}function Cq(e){const t=wq(),n=FM(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>bq(n,t),[n,t])}function Iq(e,t){const n=fe(t.map(o=>e.getShape(o)).filter(o=>o&&e.isShapeOfType(o,"frame")));if(!n.length)return;const r=[];e.batch(()=>{n.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(t)})}const Eq=50;function _q(e,t,n={}){const r=e.getShape(t);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=fe(o.map(f=>e.getShape(f)));if(!s.length)return;const i=te.FromPoints(s.flatMap(f=>{const y=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(y.vertices)})),{padding:a=Eq}=n,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,d=a-i.minY;if(u===0&&d===0&&r.props.w===l&&r.props.h===c)return;const p=new b(u,d).rot(r.rotation);e.batch(()=>{const f=o.map(y=>{const g=e.getShape(y);return{id:g.id,type:g.type,x:g.x+u,y:g.y+d}});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 HC(e){return Qn.isValid(e)?{isValid:!0,hasProtocol:!0}:Qn.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const kq=tr(function({onClose:t}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?h.jsx(Tq,{onClose:t,selectedShape:r}):null}),Tq=tr(function({onClose:t,selectedShape:n}){const r=z(),o=_e(),s=x.useRef(null);x.useEffect(()=>{requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[]);const i=x.useRef(n.props.url),[a,l]=x.useState(()=>{const y=HC(n.props.url),g=y.isValid===!0?y.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:g,safe:g,valid:!0}}),c=x.useCallback(y=>{const g=y.replace(/https?:\/\/(https?:\/\/)/,(v,C)=>C),w=HC(g),S=w.isValid===!0?w.hasProtocol?g:"https://"+g:"https://";l({actual:g,safe:S,valid:w.isValid})},[]),u=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),t())},[r,t]),d=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),t())},[r,t,a]),p=x.useCallback(()=>{t()},[t]);if(!n)return t(),null;const f=i.current&&!a.valid;return h.jsxs(h.Fragment,{children:[h.jsxs(ng,{children:[h.jsx(rg,{children:o("edit-link-dialog.title")}),h.jsx(og,{})]}),h.jsx(uu,{children:h.jsxs("div",{className:"tlui-edit-link-dialog",children:[h.jsx(Hx,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autofocus:!0,value:a.actual,onValueChange:c,onComplete:d,onCancel:p}),h.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),h.jsxs(Ux,{className:"tlui-dialog__footer__actions",children:[h.jsx(pe,{type:"normal",onClick:p,onTouchEnd:p,children:h.jsx(xt,{children:o("edit-link-dialog.cancel")})}),f?h.jsx(pe,{type:"danger",onTouchEnd:u,onClick:u,children:h.jsx(xt,{children:o("edit-link-dialog.clear")})}):h.jsx(pe,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:h.jsx(xt,{children:o("edit-link-dialog.save")})})]})]})});var Kx={exports:{}};Kx.exports;(function(e){var t=function(){var n=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 n(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),d=0,p=c.length;d<p;d++){var f=c.charCodeAt(d);u[d*2]=f>>>8,u[d*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,d=c.length;u<d;u++)c[u]=l[u*2]*256+l[u*2+1];var p=[];return c.forEach(function(f){p.push(n(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 n(c)})},_compress:function(l,c,u){if(l==null)return"";var d,p,f={},y={},g="",w="",S="",v=2,C=3,I=2,P=[],E=0,_=0,k;for(k=0;k<l.length;k+=1)if(g=l.charAt(k),Object.prototype.hasOwnProperty.call(f,g)||(f[g]=C++,y[g]=!0),w=S+g,Object.prototype.hasOwnProperty.call(f,w))S=w;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<I;d++)E=E<<1,_==c-1?(_=0,P.push(u(E)),E=0):_++;for(p=S.charCodeAt(0),d=0;d<8;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1}else{for(p=1,d=0;d<I;d++)E=E<<1|p,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=0;for(p=S.charCodeAt(0),d=0;d<16;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1}v--,v==0&&(v=Math.pow(2,I),I++),delete y[S]}else for(p=f[S],d=0;d<I;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1;v--,v==0&&(v=Math.pow(2,I),I++),f[w]=C++,S=String(g)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<I;d++)E=E<<1,_==c-1?(_=0,P.push(u(E)),E=0):_++;for(p=S.charCodeAt(0),d=0;d<8;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1}else{for(p=1,d=0;d<I;d++)E=E<<1|p,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=0;for(p=S.charCodeAt(0),d=0;d<16;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1}v--,v==0&&(v=Math.pow(2,I),I++),delete y[S]}else for(p=f[S],d=0;d<I;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1;v--,v==0&&(v=Math.pow(2,I),I++)}for(p=2,d=0;d<I;d++)E=E<<1|p&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,p=p>>1;for(;;)if(E=E<<1,_==c-1){P.push(u(E));break}else _++;return P.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var d=[],p=4,f=4,y=3,g="",w=[],S,v,C,I,P,E,_,k={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)d[S]=S;for(C=0,P=Math.pow(2,2),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;switch(C){case 0:for(C=0,P=Math.pow(2,8),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;_=n(C);break;case 1:for(C=0,P=Math.pow(2,16),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;_=n(C);break;case 2:return""}for(d[3]=_,v=_,w.push(_);;){if(k.index>l)return"";for(C=0,P=Math.pow(2,y),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;switch(_=C){case 0:for(C=0,P=Math.pow(2,8),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;d[f++]=n(C),_=f-1,p--;break;case 1:for(C=0,P=Math.pow(2,16),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;d[f++]=n(C),_=f-1,p--;break;case 2:return w.join("")}if(p==0&&(p=Math.pow(2,y),y++),d[_])g=d[_];else if(_===f)g=v+v.charAt(0);else return null;w.push(g),d[f++]=v+g.charAt(0),p--,v=g,p==0&&(p=Math.pow(2,y),y++)}}};return a}();e!=null?e.exports=t:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return t})})(Kx);var NM=Kx.exports;async function $q(e,t,n){var S,v,C;const{elements:r,files:o}=t,s={shapes:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,u=[],d=new Set;r.forEach(I=>{if(c.set(I.id,Be()),I.boundElements!==null)for(const P of I.boundElements)P.type==="text"&&d.add(P.id)});let p=_D;for(const I of r){if(d.has(I.id))continue;const P=c.get(I.id),E={id:P,typeName:"shape",parentId:l,index:p,x:I.x,y:I.y,rotation:0,isLocked:I.locked,opacity:Mq(I.opacity),meta:{}};switch(I.angle!==0&&a.set(P,I.angle),I.groupIds&&I.groupIds.length>0?i.has(I.groupIds[0])?(S=i.get(I.groupIds[0]))==null||S.push(P):i.set(I.groupIds[0],[P]):u.push(P),I.type){case"rectangle":case"ellipse":case"diamond":{let _="",k="middle";if(I.boundElements!==null){for(const T of I.boundElements)if(T.type==="text"){const j=r.find(L=>L.id===T.id);j&&(_=j.text,k=KC[j.textAlign])}}const $=I.backgroundColor==="transparent"?I.strokeColor:I.backgroundColor;s.shapes.push({...E,type:"geo",props:{geo:I.type,url:I.link??"",w:I.width,h:I.height,size:Wd[I.strokeWidth]??"draw",color:ec[$]??"black",text:_,align:k,dash:Gd(I),fill:Fq(I)}});break}case"freedraw":{s.shapes.push({...E,type:"draw",props:{dash:Gd(I),size:Wd[I.strokeWidth],color:ec[I.strokeColor]??"black",segments:[{type:"free",points:I.points.map(([_,k,$=.5])=>({x:_,y:k,z:$}))}]}});break}case"line":{const _=I.points[0],k=I.points[I.points.length-1],$=Ac(I.points.length);s.shapes.push({...E,type:"line",props:{dash:Gd(I),size:Wd[I.strokeWidth],color:ec[I.strokeColor]??"black",spline:I.roundness?"cubic":"line",handles:{start:{id:"start",type:"vertex",index:$[0],x:_[0],y:_[1]},end:{id:"end",type:"vertex",index:$[$.length-1],x:k[0],y:k[1]},...Object.fromEntries(I.points.slice(1,-1).map(([T,j],L)=>{const N=nt();return[N,{id:N,type:"vertex",index:$[L+1],x:T,y:j}]}))}}});break}case"arrow":{let _="";if(I.boundElements!==null){for(const L of I.boundElements)if(L.type==="text"){const N=r.find(F=>F.id===L.id);N&&(_=N.text)}}const k=I.points[0],$=I.points[I.points.length-1],T=c.get((v=I.startBinding)==null?void 0:v.elementId),j=c.get((C=I.endBinding)==null?void 0:C.elementId);s.shapes.push({...E,type:"arrow",props:{text:_,bend:Lq(I,k,$),dash:Gd(I),size:Wd[I.strokeWidth]??"m",color:ec[I.strokeColor]??"black",start:T?{type:"binding",boundShapeId:T,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:k[0],y:k[1]},end:j?{type:"binding",boundShapeId:j,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:$[0],y:$[1]},arrowheadEnd:VC[I.endArrowhead]??"none",arrowheadStart:VC[I.startArrowhead]??"none"}});break}case"text":{const{size:_,scale:k}=jq(I.fontSize);s.shapes.push({...E,type:"text",props:{size:_,scale:k,font:Oq[I.fontFamily]??"draw",color:ec[I.strokeColor]??"black",text:I.text,align:KC[I.textAlign]}});break}case"image":{const _=o[I.fileId];if(!_)break;const k=hi.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:I.width,h:I.height,name:I.id??"Untitled",isAnimated:!1,mimeType:_.mimeType,src:_.dataURL},meta:{}}),s.shapes.push({...E,type:"image",props:{w:I.width,h:I.height,assetId:k}})}}p=Eo(p)}const f=n??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:f,select:!1,preserveIds:!0});for(const I of i.values())if(I.length>1){e.groupShapes(I);const P=e.getShape(I[0]);P!=null&&P.parentId&&wn(P.parentId)&&u.push(P.parentId)}for(const[I,P]of a)e.select(I),e.rotateShapesBy([I],P);const y=fe(u.map(I=>e.getShape(I))),g=te.Common(y.map(I=>e.getShapePageBounds(I))),w=e.getViewportPageBounds().center;e.updateShapes(y.map(I=>{const P={x:(I.x??0)-(g.x+g.w/2),y:(I.y??0)-(g.y+g.h/2)};return{id:I.id,type:I.type,x:w.x+P.x,y:w.y+P.y}})),e.setSelectedShapes(u)}const Mq=e=>{const t=e/100;return t<.2?.1:t<.4?.25:t<.6?.5:t<.8?.75:1},Wd={1:"s",2:"m",3:"l",4:"xl"},Aq={16:"s",20:"m",28:"l",36:"xl"};function jq(e){const t=Aq[e];return t?{size:t,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}const Oq={1:"draw",2:"sans",3:"mono"},ec={"#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"},Dq={solid:"draw",dashed:"dashed",dotted:"dotted"},Rq={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},KC={left:"start",center:"middle",right:"end"},VC={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Lq(e,t,n){let r=0;if(e.points.length>2){const o=new b(t[0],t[1]),s=new b(n[0],n[1]),i=new b(e.points[1][0],e.points[1][1]),a=b.Sub(s,o),l=b.Per(a),c=b.Med(s,o),u=b.Sub(c,l),d=b.Add(c,l),p=b.NearestPointOnLineSegment(u,d,i,!1);r=b.Dist(p,c),b.Clockwise(p,s,c)&&(r*=-1)}return r}const Gd=e=>{let t=Dq[e.strokeStyle]??"draw";return t==="draw"&&e.roughness===0&&(t="solid"),t},Fq=e=>e.backgroundColor==="transparent"?"none":Rq[e.fillStyle]??"solid";async function zM(e,t,n,r){const s=(await Promise.all(t.map(async i=>await(await fetch(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r}),t.forEach(i=>URL.revokeObjectURL(i))}function Nq(e,t,n){const r=n??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(t,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0}),setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},150))}async function mv(e,t,n,r){var o;try{if(new URL(t).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await fetch(t,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),zM(e,[t]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:n,url:t,sources:r})}function zq(e){const t=document.implementation.createHTMLDocument("");return t.documentElement.innerHTML=e.trim(),t.body.textContent||t.body.innerText||""}const Bq=e=>{try{const t=new URL(e);return t.protocol==="http:"||t.protocol==="https:"}catch{return!1}},Uq=e=>{const t=e.split(/[\n\s]/);for(const n of t)try{const r=new URL(n);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return n_(t)},Hq=e=>/^<svg/.test(e),Kq=["input","select","textarea"];function qh(e){const{activeElement:t}=document;return e.getIsMenuOpen()||t&&(t.getAttribute("contenteditable")||Kq.indexOf(t.tagName.toLowerCase())>-1)}const Vq=e=>e.types.find(t=>t.match(/^image\//)),ty=(e,t,n,r)=>{const o=Uq(t);if(o)for(const s of o)mv(e,s,n);else Bq(t)?mv(e,t,n):Hq(t)?(e.mark("paste"),e.putExternalContent({type:"svg-text",text:t,point:n,sources:r})):(e.mark("paste"),e.putExternalContent({type:"text",text:t,point:n,sources:r}))},Wq=async(e,t,n)=>{if(e.getEditingShapeId()!==null)return;if(!t)throw Error("No clipboard data");const r=[];for(const o of Object.values(t.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}}UM(e,r,n)},BM=async(e,t,n)=>{const r=[];for(const o of t){if(Vq(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 Aa.blobToText(s)})()}),o.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const s=await o.getType("text/uri-list");return await Aa.blobToText(s)})()}),o.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const s=await o.getType("text/plain");return await Aa.blobToText(s)})()})}return await UM(e,r,n)};async function UM(e,t,n){const r=t.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 zM(e,i,n)}const o=await Promise.all(t.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:u[1];if(c)try{const d=NM.decompressFromBase64(c);if(d===null){i({type:"error",data:d,reason:"found tldraw data comment but could not parse base64"});return}else{const p=JSON.parse(d);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 d=JSON.parse(l);if(d.type==="excalidraw/clipboard"){i({type:"excalidraw",data:d});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){Nq(e,s.data,n);return}for(const s of o)if(s.type==="excalidraw"){$q(e,s.data,n);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");ty(e,c,n,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){ty(e,zq(s.data),n,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){mv(e,s.data,n,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){ty(e,s.data,n,o);return}}const tf=e=>{var r;const t=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!t){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=NM.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:t}));if(!(typeof navigator>"u")){const o=t.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(RD);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<tldraw>${n}</tldraw>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${n}</tldraw>`)}};function Gq(){const e=z(),t=fo(),n=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(tf(e),t("copy",{source:i}))},[e,t]),r=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(tf(e),e.deleteShapes(e.getSelectedShapeIds()),t("cut",{source:i}))},[e,t]),o=x.useCallback(async function(i,a,l){e.getEditingShapeId()!==null||qh(e)||(Array.isArray(i)&&i[0]instanceof ClipboardItem?(BM(e,i,l),t("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[e,t]);return{copy:n,cut:r,paste:o}}function Yq(){const e=z(),t=fo(),n=K("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!n)return;const r=()=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||qh(e)||(tf(e),t("copy",{source:"kbd"}))};function o(){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||qh(e)||(tf(e),e.deleteShapes(e.getSelectedShapeIds()),t("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){l.stopPropagation();return}e.getEditingShapeId()!==null||qh(e)||(l.clipboardData&&!e.inputs.shiftKey?Wq(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&BM(e,c,e.inputs.currentPagePoint)}),t("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,t,n])}async function HM(e,t,n){const{type:r,quality:o,scale:s,width:i,height:a}=n;let[l,c]=await G2(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,d=URL.createObjectURL(new Blob([e],{type:"image/svg+xml"})),p=await new Promise(y=>{const g=new Image;g.crossOrigin="anonymous",g.onload=async()=>{t&&await new Promise(v=>setTimeout(v,250));const w=document.createElement("canvas"),S=w.getContext("2d");w.width=l,w.height=c,S.imageSmoothingEnabled=!0,S.imageSmoothingQuality="high",S.drawImage(g,0,0,l,c),URL.revokeObjectURL(d),y(w)},g.onerror=()=>{y(null)},g.src=d});if(!p)return null;const f=await new Promise(y=>p.toBlob(g=>{(!g||Tt.throwToBlob.get())&&y(null),y(g)},"image/"+r,o));if(!f)return null;if(r==="png"){const y=new DataView(await f.arrayBuffer());return Gr.setPhysChunk(y,u,{type:"image/"+r})}else return f}async function KM(e,t,n){const r=await e.getSvgString(t!=null&&t.length?t:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...n});if(!r)throw new Error("Could not construct SVG.");return r}async function yv(e,t,n,r={}){var o;switch(n){case"svg":return(o=await KM(e,t,r))==null?void 0:o.svg;case"json":{const s=e.getContentFromCurrentPage(t);return JSON.stringify(s)}default:Bs(n)}}async function VM({editor:e,ids:t,format:n,opts:r={}}){switch(n){case"svg":return new Blob([await yv(e,t,"svg",r)],{type:"text/plain"});case"json":return new Blob([await yv(e,t,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await KM(e,t,r);if(!o)throw new Error("Could not construct image.");const s=await HM(o.svg,e.environment.isSafari,{type:n,quality:1,scale:2,width:o.width,height:o.height});if(!s)throw new Error("Could not construct image.");return s}default:Bs(n)}}const Xq={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function qq(e,t,n,r={}){return{blobPromise:VM({editor:e,ids:t,format:n,opts:r}),mimeType:Xq[n]}}function Zq(e,t,n="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=qq(e,t,n,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(n){case"json":case"svg":return Qq(async()=>yv(e,t,n,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Bs(n)}}async function Qq(e){var t,n;await((n=(t=navigator.clipboard)==null?void 0:t.writeText)==null?void 0:n.call(t,await e()))}function Jq(){const e=z(),{addToast:t}=Br(),n=_e();return x.useCallback((r,o="svg")=>{Zq(e,r,o).catch(()=>{t({id:"copy-fail",severity:"warning",title:n("toast.error.copy-fail.title"),description:n("toast.error.copy-fail.desc")})})},[e,t,n])}async function eZ(e,t,n="png",r,o={}){if(!r&&(r=`shapes at ${WC()}`,t.length===1)){const a=e.getShape(t[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${WC()}`}r+=`.${n}`;const s=await VM({editor:e,ids:t,format:n,opts:o}),i=new File([s],r,{type:s.type});tZ(i)}function WC(){const e=new Date,t=String(e.getFullYear()).slice(2),n=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`${t}-${n}-${r} ${o}.${s}.${i}`}function tZ(e){const t=document.createElement("a"),n=URL.createObjectURL(e);t.href=n,t.download=e.name,t.click(),URL.revokeObjectURL(n)}function nZ(){const e=z(),{addToast:t}=Br(),n=_e();return x.useCallback((r,o="png",s)=>{eZ(e,r,o,s,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),t({id:"export-fail",title:n("toast.error.export-fail.title"),description:n("toast.error.export-fail.desc"),severity:"error"})})},[e,t,n])}function rZ(){const e=z(),t=x.useRef(null),n=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,v)=>{S&&(S.innerHTML=""),v&&document.head.contains(v)&&document.head.removeChild(v),S&&document.body.contains(S)&&document.body.removeChild(S)};i(t.current,n.current),t.current=o,n.current=s;const a=`tl-print-surface-${nt()}`;o.className=a,s.innerHTML=`
218
- .${a} {
219
- display: none;
220
- }
221
-
222
- .${a} svg {
223
- max-width: 100%;
224
- height: 100%;
225
- display: block;
226
- }
227
-
228
- @media print {
229
- html, body {
230
- min-height: 100%;
231
- height: 100%;
232
- margin: 0;
233
- }
234
-
235
- body {
236
- position: relative;
237
- }
238
-
239
- body > * {
240
- display: none;
241
- }
242
-
243
- .tldraw__editor {
244
- display: none;
245
- }
246
-
247
- .${a} {
248
- display: block !important;
249
- background: white;
250
- min-height: 100%;
251
- height: 100%;
252
- max-width: 100%;
253
- }
254
-
255
- .${a}__item {
256
- padding: 10mm;
257
- display: flex;
258
- min-height: 100%;
259
- flex-direction: column;
260
- page-break-after: always;
261
- position: relative;
262
- overflow: hidden;
263
- height: 100%;
264
- }
265
-
266
- .${a}__item__main {
267
- flex: 1;
268
- display: flex;
269
- align-items: center;
270
- justify-content: center;
271
- max-height: 100%;
272
- }
273
-
274
- .${a}__item__header {
275
- display: none;
276
- }
277
-
278
- .${a}__item__footer {
279
- display: none;
280
- text-align: right;
281
- }
282
-
283
- .${a}__item__footer__hide {
284
- display: none;
285
- }
286
-
287
-
288
- }
289
-
290
- `;const l=()=>{document.head.appendChild(s),document.body.appendChild(o)},c=()=>{e.once("change-history",()=>{i(o,s)})};window.addEventListener("beforeprint",l),window.addEventListener("afterprint",c);function u(S,v,C){try{o.innerHTML+=`<div class="${a}__item">
291
- <div class="${a}__item__header">
292
- ${S.replace(/</g,"&lt;").replace(/>/g,"&gt;")}
293
- </div>
294
- <div class="${a}__item__main">
295
- ${C}
296
- </div>
297
- <div class="${a}__item__footer ${a}__item__footer__${v?"":"hide"}">
298
- ${v??""}
299
- </div>
300
- </div>`}catch(I){console.error(I)}}function d(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const p=e.getSelectedShapeIds(),f=e.getCurrentPageId(),y=e.getPages(),w={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvgString(p,w);if(S){const v=y.find(C=>C.id===f);u(`tldraw — ${v==null?void 0:v.name}`,null,S.svg),d()}}else{const S=e.getCurrentPage(),v=await e.getSvgString(e.getSortedChildIdsForParent(S.id),w);v&&(u(`tldraw — ${S.name}`,null,v.svg),d())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const WM=x.createContext({});function oZ(e){return Object.fromEntries(e.map(t=>[t.id,t]))}function da(e,t){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||t}function sZ({overrides:e,children:t}){const n=z(),{addDialog:r,clearDialogs:o}=Vi(),{clearToasts:s}=Br(),i=_e(),a=DM(),l=rZ(),{cut:c,copy:u,paste:d}=Gq(),p=Jq(),f=nZ(),y=i("document.default-name"),g=fo(),w=x.useMemo(()=>{function S(){return n.isIn("select")||(n.complete(),n.setCurrentTool("select")),!1}function v(){return n.isIn("select")&&n.getSelectedShapeIds().length>0}const I=oZ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(P){v()&&(S()||(g("edit-link",{source:P}),n.mark("edit-link"),r({component:kq})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(P){g("insert-embed",{source:P}),r({component:OM})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(P){g("insert-media",{source:P}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(P){g("undo",{source:P}),n.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(P){g("redo",{source:P}),n.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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("export-as",{format:"svg",source:P}),f(E,"svg",da(n,y)))}},{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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("export-as",{format:"png",source:P}),f(E,"png",da(n,y)))}},{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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("export-as",{format:"json",source:P}),f(E,"json",da(n,y)))}},{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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("export-all-as",{format:"svg",source:P}),f(Array.from(n.getCurrentPageShapeIds()),"svg",da(n,y)))}},{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(P){const E=Array.from(n.getCurrentPageShapeIds().values());E.length!==0&&(g("export-all-as",{format:"png",source:P}),f(E,"png",da(n,y)))}},{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(P){const E=Array.from(n.getCurrentPageShapeIds().values());E.length!==0&&(g("export-all-as",{format:"json",source:P}),f(E,"json",da(n,y)))}},{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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("copy-as",{format:"svg",source:P}),p(E,"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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("copy-as",{format:"png",source:P}),p(E,"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(P){let E=n.getSelectedShapeIds();E.length===0&&(E=Array.from(n.getCurrentPageShapeIds().values())),E.length!==0&&(g("copy-as",{format:"json",source:P}),p(E,"json"))}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(P){if(!v()||S())return;g("toggle-auto-size",{source:P}),n.mark("toggling auto size");const E=n.getSelectedShapes().filter(_=>n.isShapeOfType(_,"text")&&_.props.autoSize===!1);n.updateShapes(E.map(_=>({id:_.id,type:_.type,props:{..._.props,w:8,autoSize:!0}}))),Ve(n,E.map(_=>_.id))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(P){g("open-embed-link",{source:P});const E=n.getSelectedShapeIds(),_="No embed shapes selected";if(E.length!==1){console.error(_);return}const k=n.getShape(E[0]);if(!k||!n.isShapeOfType(k,"embed")){console.error(_);return}l8(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(P){var E,_;if(((E=n.root.getCurrent())==null?void 0:E.id)!=="zoom"&&(g("zoom-tool",{source:P}),!(n.inputs.shiftKey||n.inputs.ctrlKey))){const k=n.root.getCurrent();k&&((_=k.getCurrent())==null?void 0:_.id)==="idle"&&n.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(P){v()&&(S()||n.batch(()=>{g("convert-to-bookmark",{source:P});const E=n.getSelectedShapes(),_=[],k=[];for(const $ of E){if(!$||!n.isShapeOfType($,"embed")||!$.props.url)continue;const T=new b($.x,$.y);T.rot(-$.rotation),T.add(new b($.props.w/2-300/2,$.props.h/2-320/2)),T.rot($.rotation);const j={id:Be(),type:"bookmark",rotation:$.rotation,x:T.x,y:T.y,opacity:1,props:{url:$.props.url}};_.push(j),k.push($.id)}n.mark("convert shapes to bookmark"),n.deleteShapes(k),n.createShapes(_)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(P){v()&&(S()||(g("convert-to-embed",{source:P}),n.batch(()=>{const E=n.getSelectedShapeIds(),_=fe(E.map(T=>n.getShape(T))),k=[],$=[];for(const T of _){if(!n.isShapeOfType(T,"bookmark"))continue;const{url:j}=T.props,L=xs(T.props.url);if(!L||!L.definition)continue;const{width:N,height:F}=L.definition,B=new b(T.x,T.y);B.rot(-T.rotation),B.add(new b(T.props.w/2-N/2,T.props.h/2-F/2)),B.rot(T.rotation);const q={id:Be(),type:"embed",x:B.x,y:B.y,rotation:T.rotation,props:{url:j,w:N,h:F}};k.push(q),$.push(T.id)}n.mark("convert shapes to embed"),n.deleteShapes($),n.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(P){if(!v()||S())return;g("duplicate-shapes",{source:P});const E=n.getInstanceState();let _,k;if(E.duplicateProps)_=E.duplicateProps.shapeIds,k=E.duplicateProps.offset;else{_=n.getSelectedShapeIds();const $=te.Common(fe(_.map(T=>n.getShapePageBounds(T))));k=E.canMoveCamera?{x:$.width+20,y:0}:{x:20,y:20}}n.mark("duplicate shapes"),n.duplicateShapes(_,k),E.duplicateProps&&n.updateInstanceState({duplicateProps:{...E.duplicateProps,shapeIds:n.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(P){v()&&(S()||(g("ungroup-shapes",{source:P}),n.mark("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(P){if(!v()||S())return;g("group-shapes",{source:P});const E=n.getOnlySelectedShape();E&&n.isShapeOfType(E,"group")?(n.mark("ungroup"),n.ungroupShapes(n.getSelectedShapeIds())):(n.mark("group"),n.groupShapes(n.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(P){if(!v())return;g("remove-frame",{source:P});const E=n.getSelectedShapes();E.length>0&&E.every(_=>n.isShapeOfType(_,"frame"))&&(n.mark("remove-frame"),Iq(n,E.map(_=>_.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(P){if(!v())return;g("fit-frame-to-content",{source:P});const E=n.getOnlySelectedShape();E&&n.isShapeOfType(E,"frame")&&(n.mark("fit-frame-to-content"),_q(n,E.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(P){if(!v()||S())return;g("align-shapes",{operation:"left",source:P}),n.mark("align left");const E=n.getSelectedShapeIds();n.alignShapes(E,"left"),Ve(n,E)}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(P){if(!v()||S())return;g("align-shapes",{operation:"center-horizontal",source:P}),n.mark("align center horizontal");const E=n.getSelectedShapeIds();n.alignShapes(E,"center-horizontal"),Ve(n,E)}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(P){if(!v()||S())return;g("align-shapes",{operation:"right",source:P}),n.mark("align right");const E=n.getSelectedShapeIds();n.alignShapes(E,"right"),Ve(n,E)}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(P){if(!v()||S())return;g("align-shapes",{operation:"center-vertical",source:P}),n.mark("align center vertical");const E=n.getSelectedShapeIds();n.alignShapes(E,"center-vertical"),Ve(n,E)}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(P){if(!v()||S())return;g("align-shapes",{operation:"top",source:P}),n.mark("align top");const E=n.getSelectedShapeIds();n.alignShapes(E,"top"),Ve(n,E)}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(P){if(!v()||S())return;g("align-shapes",{operation:"bottom",source:P}),n.mark("align bottom");const E=n.getSelectedShapeIds();n.alignShapes(E,"bottom"),Ve(n,E)}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(P){if(!v()||S())return;g("distribute-shapes",{operation:"horizontal",source:P}),n.mark("distribute horizontal");const E=n.getSelectedShapeIds();n.distributeShapes(E,"horizontal"),Ve(n,E)}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(P){if(!v()||S())return;g("distribute-shapes",{operation:"vertical",source:P}),n.mark("distribute vertical");const E=n.getSelectedShapeIds();n.distributeShapes(E,"vertical"),Ve(n,E)}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(P){if(!v()||S())return;g("stretch-shapes",{operation:"horizontal",source:P}),n.mark("stretch horizontal");const E=n.getSelectedShapeIds();n.stretchShapes(E,"horizontal"),Ve(n,E)}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(P){if(!v()||S())return;g("stretch-shapes",{operation:"vertical",source:P}),n.mark("stretch vertical");const E=n.getSelectedShapeIds();n.stretchShapes(E,"vertical"),Ve(n,E)}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(P){if(!v()||S())return;g("flip-shapes",{operation:"horizontal",source:P}),n.mark("flip horizontal");const E=n.getSelectedShapeIds();n.flipShapes(E,"horizontal"),Ve(n,E)}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(P){if(!v()||S())return;g("flip-shapes",{operation:"vertical",source:P}),n.mark("flip vertical");const E=n.getSelectedShapeIds();n.flipShapes(E,"vertical"),Ve(n,E)}},{id:"pack",label:"action.pack",icon:"pack",onSelect(P){if(!v()||S())return;g("pack-shapes",{source:P}),n.mark("pack");const E=n.getSelectedShapeIds();n.packShapes(E,16),Ve(n,E)}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(P){if(!v()||S())return;g("stack-shapes",{operation:"vertical",source:P}),n.mark("stack-vertical");const E=n.getSelectedShapeIds();n.stackShapes(E,"vertical",16),Ve(n,E)}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(P){if(!v()||S())return;g("stack-shapes",{operation:"horizontal",source:P}),n.mark("stack-horizontal");const E=n.getSelectedShapeIds();n.stackShapes(E,"horizontal",16),Ve(n,E)}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(P){v()&&(S()||(g("reorder-shapes",{operation:"toFront",source:P}),n.mark("bring to front"),n.bringToFront(n.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(P){v()&&(S()||(g("reorder-shapes",{operation:"forward",source:P}),n.mark("bring forward"),n.bringForward(n.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(P){v()&&(S()||(g("reorder-shapes",{operation:"backward",source:P}),n.mark("send backward"),n.sendBackward(n.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(P){v()&&(S()||(g("reorder-shapes",{operation:"toBack",source:P}),n.mark("send to back"),n.sendToBack(n.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(P){v()&&(S()||(n.mark("cut"),c(P)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(P){v()&&(S()||u(P))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(P){var E;(E=navigator.clipboard)==null||E.read().then(_=>{d(_,P,P==="context-menu"?n.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(P){n.batch(()=>{S()||(g("select-all-shapes",{source:P}),n.mark("select all kbd"),n.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(P){v()&&(S()||(g("select-none-shapes",{source:P}),n.mark("select none"),n.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(P){v()&&(S()||(g("delete-shapes",{source:P}),n.mark("delete"),n.deleteShapes(n.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(P){if(!v()||S())return;g("rotate-cw",{source:P}),n.mark("rotate-cw");const E=n.getSelectionRotation()%(Ge/2),_=mc(E,0)||mc(E,Ge/2),k=n.getSelectedShapeIds();n.rotateShapesBy(k,Ge/2-(_?0:E)),Ve(n,k)}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(P){if(!v()||S())return;g("rotate-ccw",{source:P}),n.mark("rotate-ccw");const E=n.getSelectionRotation()%(Ge/2),_=mc(E,0),k=n.getSelectedShapeIds();n.rotateShapesBy(k,_?-(Ge/2):-E),Ve(n,k)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(P){g("zoom-in",{source:P}),n.zoomIn(n.getViewportScreenCenter(),{duration:Yr})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(P){g("zoom-out",{source:P}),n.zoomOut(n.getViewportScreenCenter(),{duration:Yr})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(P){g("reset-zoom",{source:P}),n.resetZoom(n.getViewportScreenCenter(),{duration:Yr})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(P){g("zoom-to-fit",{source:P}),n.zoomToFit({duration:Yr})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(P){v()&&(S()||(g("zoom-to-selection",{source:P}),n.zoomToSelection({duration:Yr})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(P){g("toggle-snap-mode",{source:P}),n.user.updateUserPreferences({isSnapMode:!n.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(P){g("toggle-dark-mode",{source:P}),n.user.updateUserPreferences({isDarkMode:!n.user.getIsDarkMode()})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(P){g("toggle-wrap-mode",{source:P}),n.user.updateUserPreferences({isWrapMode:!n.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(P){g("toggle-reduce-motion",{source:P}),n.user.updateUserPreferences({animationSpeed:n.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(P){g("toggle-edge-scrolling",{source:P}),n.user.updateUserPreferences({edgeScrollSpeed:n.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(P){g("toggle-transparent",{source:P}),n.updateInstanceState({exportBackground:!n.getInstanceState().exportBackground},{ephemeral:!0})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(P){g("toggle-tool-lock",{source:P}),n.updateInstanceState({isToolLocked:!n.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(P){g("unlock-all",{source:P});const E=[];for(const _ of n.getCurrentPageShapes())_.isLocked&&E.push({id:_.id,type:_.type,isLocked:!1});E.length>0&&n.updateShapes(E)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(P){requestAnimationFrame(()=>{n.batch(()=>{g("toggle-focus-mode",{source:P}),o(),s(),n.updateInstanceState({isFocusMode:!n.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(P){g("toggle-grid-mode",{source:P}),n.updateInstanceState({isGridMode:!n.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(P){g("toggle-debug-mode",{source:P}),n.updateInstanceState({isDebugMode:!n.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(P){g("print",{source:P}),l()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(P){g("exit-pen-mode",{source:P}),n.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(P){g("stop-following",{source:P}),n.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(P){g("zoom-to-content",{source:P}),n.zoomToContent()}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(P){n.mark("locking"),g("toggle-lock",{source:P}),n.toggleLock(n.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(P){const E=Lo.createId(),_=n.getSelectedShapeIds();n.batch(()=>{n.mark("move_shapes_to_page"),n.createPage({name:i("page-menu.new-page-initial-name"),id:E}),n.moveShapesToPage(_,E)}),g("new-page",{source:P})}},{id:"select-white-color",label:"color-style.white",kbd:"?t",onSelect(P){const E=Jn;n.batch(()=>{n.mark("change-color"),n.isIn("select")&&n.setStyleForSelectedShapes(E,"white",{squashing:!1}),n.setStyleForNextShapes(E,"white",{squashing:!1}),n.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),g("set-style",{source:P,id:E.id,value:"white"})}}]);return e?e(n,I,void 0):I},[n,g,e,r,a,f,p,c,u,d,o,s,l,i,y]);return h.jsx(WM.Provider,{value:w,children:t})}function le(){const e=x.useContext(WM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function du(e,t){return e?typeof e=="string"?e:t?e[t]??e.default:void 0:void 0}const iZ=["top","right","bottom","left"],Ls=Math.min,Wn=Math.max,nf=Math.round,Yd=Math.floor,Fs=e=>({x:e,y:e}),aZ={left:"right",right:"left",bottom:"top",top:"bottom"},lZ={start:"end",end:"start"};function Sv(e,t,n){return Wn(e,Ls(t,n))}function Vo(e,t){return typeof e=="function"?e(t):e}function Wo(e){return e.split("-")[0]}function Pl(e){return e.split("-")[1]}function Vx(e){return e==="x"?"y":"x"}function Wx(e){return e==="y"?"height":"width"}function Cl(e){return["top","bottom"].includes(Wo(e))?"y":"x"}function Gx(e){return Vx(Cl(e))}function cZ(e,t,n){n===void 0&&(n=!1);const r=Pl(e),o=Gx(e),s=Wx(o);let i=o==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return t.reference[s]>t.floating[s]&&(i=rf(i)),[i,rf(i)]}function uZ(e){const t=rf(e);return[vv(e),t,vv(t)]}function vv(e){return e.replace(/start|end/g,t=>lZ[t])}function dZ(e,t,n){const r=["left","right"],o=["right","left"],s=["top","bottom"],i=["bottom","top"];switch(e){case"top":case"bottom":return n?t?o:r:t?r:o;case"left":case"right":return t?s:i;default:return[]}}function hZ(e,t,n,r){const o=Pl(e);let s=dZ(Wo(e),n==="start",r);return o&&(s=s.map(i=>i+"-"+o),t&&(s=s.concat(s.map(vv)))),s}function rf(e){return e.replace(/left|right|bottom|top/g,t=>aZ[t])}function pZ(e){return{top:0,right:0,bottom:0,left:0,...e}}function GM(e){return typeof e!="number"?pZ(e):{top:e,right:e,bottom:e,left:e}}function of(e){return{...e,top:e.y,left:e.x,right:e.x+e.width,bottom:e.y+e.height}}function GC(e,t,n){let{reference:r,floating:o}=e;const s=Cl(t),i=Gx(t),a=Wx(i),l=Wo(t),c=s==="y",u=r.x+r.width/2-o.width/2,d=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:d};break;case"left":f={x:r.x-o.width,y:d};break;default:f={x:r.x,y:r.y}}switch(Pl(t)){case"start":f[i]-=p*(n&&c?-1:1);break;case"end":f[i]+=p*(n&&c?-1:1);break}return f}const fZ=async(e,t,n)=>{const{placement:r="bottom",strategy:o="absolute",middleware:s=[],platform:i}=n,a=s.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(t));let c=await i.getElementRects({reference:e,floating:t,strategy:o}),{x:u,y:d}=GC(c,r,l),p=r,f={},y=0;for(let g=0;g<a.length;g++){const{name:w,fn:S}=a[g],{x:v,y:C,data:I,reset:P}=await S({x:u,y:d,initialPlacement:r,placement:p,strategy:o,middlewareData:f,rects:c,platform:i,elements:{reference:e,floating:t}});u=v??u,d=C??d,f={...f,[w]:{...f[w],...I}},P&&y<=50&&(y++,typeof P=="object"&&(P.placement&&(p=P.placement),P.rects&&(c=P.rects===!0?await i.getElementRects({reference:e,floating:t,strategy:o}):P.rects),{x:u,y:d}=GC(c,p,l)),g=-1)}return{x:u,y:d,placement:p,strategy:o,middlewareData:f}};async function hu(e,t){var n;t===void 0&&(t={});const{x:r,y:o,platform:s,rects:i,elements:a,strategy:l}=e,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:d="floating",altBoundary:p=!1,padding:f=0}=Vo(t,e),y=GM(f),w=a[p?d==="floating"?"reference":"floating":d],S=of(await s.getClippingRect({element:(n=await(s.isElement==null?void 0:s.isElement(w)))==null||n?w:w.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),v=d==="floating"?{...i.floating,x:r,y:o}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a.floating)),I=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},P=of(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:v,offsetParent:C,strategy:l}):v);return{top:(S.top-P.top+y.top)/I.y,bottom:(P.bottom-S.bottom+y.bottom)/I.y,left:(S.left-P.left+y.left)/I.x,right:(P.right-S.right+y.right)/I.x}}const gZ=e=>({name:"arrow",options:e,async fn(t){const{x:n,y:r,placement:o,rects:s,platform:i,elements:a,middlewareData:l}=t,{element:c,padding:u=0}=Vo(e,t)||{};if(c==null)return{};const d=GM(u),p={x:n,y:r},f=Gx(o),y=Wx(f),g=await i.getDimensions(c),w=f==="y",S=w?"top":"left",v=w?"bottom":"right",C=w?"clientHeight":"clientWidth",I=s.reference[y]+s.reference[f]-p[f]-s.floating[y],P=p[f]-s.reference[f],E=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let _=E?E[C]:0;(!_||!await(i.isElement==null?void 0:i.isElement(E)))&&(_=a.floating[C]||s.floating[y]);const k=I/2-P/2,$=_/2-g[y]/2-1,T=Ls(d[S],$),j=Ls(d[v],$),L=T,N=_-g[y]-j,F=_/2-g[y]/2+k,B=Sv(L,F,N),q=!l.arrow&&Pl(o)!=null&&F!==B&&s.reference[y]/2-(F<L?T:j)-g[y]/2<0,Q=q?F<L?F-L:F-N:0;return{[f]:p[f]+Q,data:{[f]:B,centerOffset:F-B-Q,...q&&{alignmentOffset:Q}},reset:q}}}),mZ=function(e){return e===void 0&&(e={}),{name:"flip",options:e,async fn(t){var n,r;const{placement:o,middlewareData:s,rects:i,initialPlacement:a,platform:l,elements:c}=t,{mainAxis:u=!0,crossAxis:d=!0,fallbackPlacements:p,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:y="none",flipAlignment:g=!0,...w}=Vo(e,t);if((n=s.arrow)!=null&&n.alignmentOffset)return{};const S=Wo(o),v=Wo(a)===a,C=await(l.isRTL==null?void 0:l.isRTL(c.floating)),I=p||(v||!g?[rf(a)]:uZ(a));!p&&y!=="none"&&I.push(...hZ(a,g,y,C));const P=[a,...I],E=await hu(t,w),_=[];let k=((r=s.flip)==null?void 0:r.overflows)||[];if(u&&_.push(E[S]),d){const L=cZ(o,i,C);_.push(E[L[0]],E[L[1]])}if(k=[...k,{placement:o,overflows:_}],!_.every(L=>L<=0)){var $,T;const L=((($=s.flip)==null?void 0:$.index)||0)+1,N=P[L];if(N)return{data:{index:L,overflows:k},reset:{placement:N}};let F=(T=k.filter(B=>B.overflows[0]<=0).sort((B,q)=>B.overflows[1]-q.overflows[1])[0])==null?void 0:T.placement;if(!F)switch(f){case"bestFit":{var j;const B=(j=k.map(q=>[q.placement,q.overflows.filter(Q=>Q>0).reduce((Q,V)=>Q+V,0)]).sort((q,Q)=>q[1]-Q[1])[0])==null?void 0:j[0];B&&(F=B);break}case"initialPlacement":F=a;break}if(o!==F)return{reset:{placement:F}}}return{}}}};function YC(e,t){return{top:e.top-t.height,right:e.right-t.width,bottom:e.bottom-t.height,left:e.left-t.width}}function XC(e){return iZ.some(t=>e[t]>=0)}const yZ=function(e){return e===void 0&&(e={}),{name:"hide",options:e,async fn(t){const{rects:n}=t,{strategy:r="referenceHidden",...o}=Vo(e,t);switch(r){case"referenceHidden":{const s=await hu(t,{...o,elementContext:"reference"}),i=YC(s,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:XC(i)}}}case"escaped":{const s=await hu(t,{...o,altBoundary:!0}),i=YC(s,n.floating);return{data:{escapedOffsets:i,escaped:XC(i)}}}default:return{}}}}};async function SZ(e,t){const{placement:n,platform:r,elements:o}=e,s=await(r.isRTL==null?void 0:r.isRTL(o.floating)),i=Wo(n),a=Pl(n),l=Cl(n)==="y",c=["left","top"].includes(i)?-1:1,u=s&&l?-1:1,d=Vo(t,e);let{mainAxis:p,crossAxis:f,alignmentAxis:y}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:0,crossAxis:0,alignmentAxis:null,...d};return a&&typeof y=="number"&&(f=a==="end"?y*-1:y),l?{x:f*u,y:p*c}:{x:p*c,y:f*u}}const vZ=function(e){return e===void 0&&(e=0),{name:"offset",options:e,async fn(t){var n,r;const{x:o,y:s,placement:i,middlewareData:a}=t,l=await SZ(t,e);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:o+l.x,y:s+l.y,data:{...l,placement:i}}}}},xZ=function(e){return e===void 0&&(e={}),{name:"shift",options:e,async fn(t){const{x:n,y:r,placement:o}=t,{mainAxis:s=!0,crossAxis:i=!1,limiter:a={fn:w=>{let{x:S,y:v}=w;return{x:S,y:v}}},...l}=Vo(e,t),c={x:n,y:r},u=await hu(t,l),d=Cl(Wo(o)),p=Vx(d);let f=c[p],y=c[d];if(s){const w=p==="y"?"top":"left",S=p==="y"?"bottom":"right",v=f+u[w],C=f-u[S];f=Sv(v,f,C)}if(i){const w=d==="y"?"top":"left",S=d==="y"?"bottom":"right",v=y+u[w],C=y-u[S];y=Sv(v,y,C)}const g=a.fn({...t,[p]:f,[d]:y});return{...g,data:{x:g.x-n,y:g.y-r}}}}},wZ=function(e){return e===void 0&&(e={}),{options:e,fn(t){const{x:n,y:r,placement:o,rects:s,middlewareData:i}=t,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=Vo(e,t),u={x:n,y:r},d=Cl(o),p=Vx(d);let f=u[p],y=u[d];const g=Vo(a,t),w=typeof g=="number"?{mainAxis:g,crossAxis:0}:{mainAxis:0,crossAxis:0,...g};if(l){const C=p==="y"?"height":"width",I=s.reference[p]-s.floating[C]+w.mainAxis,P=s.reference[p]+s.reference[C]-w.mainAxis;f<I?f=I:f>P&&(f=P)}if(c){var S,v;const C=p==="y"?"width":"height",I=["top","left"].includes(Wo(o)),P=s.reference[d]-s.floating[C]+(I&&((S=i.offset)==null?void 0:S[d])||0)+(I?0:w.crossAxis),E=s.reference[d]+s.reference[C]+(I?0:((v=i.offset)==null?void 0:v[d])||0)-(I?w.crossAxis:0);y<P?y=P:y>E&&(y=E)}return{[p]:f,[d]:y}}}},bZ=function(e){return e===void 0&&(e={}),{name:"size",options:e,async fn(t){const{placement:n,rects:r,platform:o,elements:s}=t,{apply:i=()=>{},...a}=Vo(e,t),l=await hu(t,a),c=Wo(n),u=Pl(n),d=Cl(n)==="y",{width:p,height:f}=r.floating;let y,g;c==="top"||c==="bottom"?(y=c,g=u===(await(o.isRTL==null?void 0:o.isRTL(s.floating))?"start":"end")?"left":"right"):(g=c,y=u==="end"?"top":"bottom");const w=f-l[y],S=p-l[g],v=!t.middlewareData.shift;let C=w,I=S;if(d){const E=p-l.left-l.right;I=u||v?Ls(S,E):E}else{const E=f-l.top-l.bottom;C=u||v?Ls(w,E):E}if(v&&!u){const E=Wn(l.left,0),_=Wn(l.right,0),k=Wn(l.top,0),$=Wn(l.bottom,0);d?I=p-2*(E!==0||_!==0?E+_:Wn(l.left,l.right)):C=f-2*(k!==0||$!==0?k+$:Wn(l.top,l.bottom))}await i({...t,availableWidth:I,availableHeight:C});const P=await o.getDimensions(s.floating);return p!==P.width||f!==P.height?{reset:{rects:!0}}:{}}}};function Ns(e){return YM(e)?(e.nodeName||"").toLowerCase():"#document"}function Zn(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function ns(e){var t;return(t=(YM(e)?e.ownerDocument:e.document)||window.document)==null?void 0:t.documentElement}function YM(e){return e instanceof Node||e instanceof Zn(e).Node}function Go(e){return e instanceof Element||e instanceof Zn(e).Element}function lo(e){return e instanceof HTMLElement||e instanceof Zn(e).HTMLElement}function qC(e){return typeof ShadowRoot>"u"?!1:e instanceof ShadowRoot||e instanceof Zn(e).ShadowRoot}function Lu(e){const{overflow:t,overflowX:n,overflowY:r,display:o}=Sr(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&!["inline","contents"].includes(o)}function PZ(e){return["table","td","th"].includes(Ns(e))}function Yx(e){const t=Xx(),n=Sr(e);return n.transform!=="none"||n.perspective!=="none"||(n.containerType?n.containerType!=="normal":!1)||!t&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!t&&(n.filter?n.filter!=="none":!1)||["transform","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function CZ(e){let t=al(e);for(;lo(t)&&!sg(t);){if(Yx(t))return t;t=al(t)}return null}function Xx(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function sg(e){return["html","body","#document"].includes(Ns(e))}function Sr(e){return Zn(e).getComputedStyle(e)}function ig(e){return Go(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.pageXOffset,scrollTop:e.pageYOffset}}function al(e){if(Ns(e)==="html")return e;const t=e.assignedSlot||e.parentNode||qC(e)&&e.host||ns(e);return qC(t)?t.host:t}function XM(e){const t=al(e);return sg(t)?e.ownerDocument?e.ownerDocument.body:e.body:lo(t)&&Lu(t)?t:XM(t)}function pu(e,t,n){var r;t===void 0&&(t=[]),n===void 0&&(n=!0);const o=XM(e),s=o===((r=e.ownerDocument)==null?void 0:r.body),i=Zn(o);return s?t.concat(i,i.visualViewport||[],Lu(o)?o:[],i.frameElement&&n?pu(i.frameElement):[]):t.concat(o,pu(o,[],n))}function qM(e){const t=Sr(e);let n=parseFloat(t.width)||0,r=parseFloat(t.height)||0;const o=lo(e),s=o?e.offsetWidth:n,i=o?e.offsetHeight:r,a=nf(n)!==s||nf(r)!==i;return a&&(n=s,r=i),{width:n,height:r,$:a}}function qx(e){return Go(e)?e:e.contextElement}function Va(e){const t=qx(e);if(!lo(t))return Fs(1);const n=t.getBoundingClientRect(),{width:r,height:o,$:s}=qM(t);let i=(s?nf(n.width):n.width)/r,a=(s?nf(n.height):n.height)/o;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const IZ=Fs(0);function ZM(e){const t=Zn(e);return!Xx()||!t.visualViewport?IZ:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function EZ(e,t,n){return t===void 0&&(t=!1),!n||t&&n!==Zn(e)?!1:t}function ji(e,t,n,r){t===void 0&&(t=!1),n===void 0&&(n=!1);const o=e.getBoundingClientRect(),s=qx(e);let i=Fs(1);t&&(r?Go(r)&&(i=Va(r)):i=Va(e));const a=EZ(s,n,r)?ZM(s):Fs(0);let l=(o.left+a.x)/i.x,c=(o.top+a.y)/i.y,u=o.width/i.x,d=o.height/i.y;if(s){const p=Zn(s),f=r&&Go(r)?Zn(r):r;let y=p,g=y.frameElement;for(;g&&r&&f!==y;){const w=Va(g),S=g.getBoundingClientRect(),v=Sr(g),C=S.left+(g.clientLeft+parseFloat(v.paddingLeft))*w.x,I=S.top+(g.clientTop+parseFloat(v.paddingTop))*w.y;l*=w.x,c*=w.y,u*=w.x,d*=w.y,l+=C,c+=I,y=Zn(g),g=y.frameElement}}return of({width:u,height:d,x:l,y:c})}const _Z=[":popover-open",":modal"];function QM(e){return _Z.some(t=>{try{return e.matches(t)}catch{return!1}})}function kZ(e){let{elements:t,rect:n,offsetParent:r,strategy:o}=e;const s=o==="fixed",i=ns(r),a=t?QM(t.floating):!1;if(r===i||a&&s)return n;let l={scrollLeft:0,scrollTop:0},c=Fs(1);const u=Fs(0),d=lo(r);if((d||!d&&!s)&&((Ns(r)!=="body"||Lu(i))&&(l=ig(r)),lo(r))){const p=ji(r);c=Va(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x,y:n.y*c.y-l.scrollTop*c.y+u.y}}function TZ(e){return Array.from(e.getClientRects())}function JM(e){return ji(ns(e)).left+ig(e).scrollLeft}function $Z(e){const t=ns(e),n=ig(e),r=e.ownerDocument.body,o=Wn(t.scrollWidth,t.clientWidth,r.scrollWidth,r.clientWidth),s=Wn(t.scrollHeight,t.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+JM(e);const a=-n.scrollTop;return Sr(r).direction==="rtl"&&(i+=Wn(t.clientWidth,r.clientWidth)-o),{width:o,height:s,x:i,y:a}}function MZ(e,t){const n=Zn(e),r=ns(e),o=n.visualViewport;let s=r.clientWidth,i=r.clientHeight,a=0,l=0;if(o){s=o.width,i=o.height;const c=Xx();(!c||c&&t==="fixed")&&(a=o.offsetLeft,l=o.offsetTop)}return{width:s,height:i,x:a,y:l}}function AZ(e,t){const n=ji(e,!0,t==="fixed"),r=n.top+e.clientTop,o=n.left+e.clientLeft,s=lo(e)?Va(e):Fs(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 ZC(e,t,n){let r;if(t==="viewport")r=MZ(e,n);else if(t==="document")r=$Z(ns(e));else if(Go(t))r=AZ(t,n);else{const o=ZM(e);r={...t,x:t.x-o.x,y:t.y-o.y}}return of(r)}function eA(e,t){const n=al(e);return n===t||!Go(n)||sg(n)?!1:Sr(n).position==="fixed"||eA(n,t)}function jZ(e,t){const n=t.get(e);if(n)return n;let r=pu(e,[],!1).filter(a=>Go(a)&&Ns(a)!=="body"),o=null;const s=Sr(e).position==="fixed";let i=s?al(e):e;for(;Go(i)&&!sg(i);){const a=Sr(i),l=Yx(i);!l&&a.position==="fixed"&&(o=null),(s?!l&&!o:!l&&a.position==="static"&&!!o&&["absolute","fixed"].includes(o.position)||Lu(i)&&!l&&eA(e,i))?r=r.filter(u=>u!==i):o=a,i=al(i)}return t.set(e,r),r}function OZ(e){let{element:t,boundary:n,rootBoundary:r,strategy:o}=e;const i=[...n==="clippingAncestors"?jZ(t,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const d=ZC(t,u,o);return c.top=Wn(d.top,c.top),c.right=Ls(d.right,c.right),c.bottom=Ls(d.bottom,c.bottom),c.left=Wn(d.left,c.left),c},ZC(t,a,o));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function DZ(e){const{width:t,height:n}=qM(e);return{width:t,height:n}}function RZ(e,t,n){const r=lo(t),o=ns(t),s=n==="fixed",i=ji(e,!0,s,t);let a={scrollLeft:0,scrollTop:0};const l=Fs(0);if(r||!r&&!s)if((Ns(t)!=="body"||Lu(o))&&(a=ig(t)),r){const d=ji(t,!0,s,t);l.x=d.x+t.clientLeft,l.y=d.y+t.clientTop}else o&&(l.x=JM(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 QC(e,t){return!lo(e)||Sr(e).position==="fixed"?null:t?t(e):e.offsetParent}function tA(e,t){const n=Zn(e);if(!lo(e)||QM(e))return n;let r=QC(e,t);for(;r&&PZ(r)&&Sr(r).position==="static";)r=QC(r,t);return r&&(Ns(r)==="html"||Ns(r)==="body"&&Sr(r).position==="static"&&!Yx(r))?n:r||CZ(e)||n}const LZ=async function(e){const t=this.getOffsetParent||tA,n=this.getDimensions;return{reference:RZ(e.reference,await t(e.floating),e.strategy),floating:{x:0,y:0,...await n(e.floating)}}};function FZ(e){return Sr(e).direction==="rtl"}const NZ={convertOffsetParentRelativeRectToViewportRelativeRect:kZ,getDocumentElement:ns,getClippingRect:OZ,getOffsetParent:tA,getElementRects:LZ,getClientRects:TZ,getDimensions:DZ,getScale:Va,isElement:Go,isRTL:FZ};function zZ(e,t){let n=null,r;const o=ns(e);function s(){var a;clearTimeout(r),(a=n)==null||a.disconnect(),n=null}function i(a,l){a===void 0&&(a=!1),l===void 0&&(l=1),s();const{left:c,top:u,width:d,height:p}=e.getBoundingClientRect();if(a||t(),!d||!p)return;const f=Yd(u),y=Yd(o.clientWidth-(c+d)),g=Yd(o.clientHeight-(u+p)),w=Yd(c),v={rootMargin:-f+"px "+-y+"px "+-g+"px "+-w+"px",threshold:Wn(0,Ls(1,l))||1};let C=!0;function I(P){const E=P[0].intersectionRatio;if(E!==l){if(!C)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},100)}C=!1}try{n=new IntersectionObserver(I,{...v,root:o.ownerDocument})}catch{n=new IntersectionObserver(I,v)}n.observe(e)}return i(!0),s}function BZ(e,t,n,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=qx(e),u=o||s?[...c?pu(c):[],...pu(t)]:[];u.forEach(S=>{o&&S.addEventListener("scroll",n,{passive:!0}),s&&S.addEventListener("resize",n)});const d=c&&a?zZ(c,n):null;let p=-1,f=null;i&&(f=new ResizeObserver(S=>{let[v]=S;v&&v.target===c&&f&&(f.unobserve(t),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var C;(C=f)==null||C.observe(t)})),n()}),c&&!l&&f.observe(c),f.observe(t));let y,g=l?ji(e):null;l&&w();function w(){const S=ji(e);g&&(S.x!==g.x||S.y!==g.y||S.width!==g.width||S.height!==g.height)&&n(),g=S,y=requestAnimationFrame(w)}return n(),()=>{var S;u.forEach(v=>{o&&v.removeEventListener("scroll",n),s&&v.removeEventListener("resize",n)}),d==null||d(),(S=f)==null||S.disconnect(),f=null,l&&cancelAnimationFrame(y)}}const UZ=xZ,HZ=mZ,KZ=bZ,VZ=yZ,JC=gZ,WZ=wZ,GZ=(e,t,n)=>{const r=new Map,o={platform:NZ,...n},s={...o.platform,_c:r};return fZ(e,t,{...o,platform:s})},YZ=e=>{function t(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:e,fn(n){const{element:r,padding:o}=typeof e=="function"?e(n):e;return r&&t(r)?r.current!=null?JC({element:r.current,padding:o}).fn(n):{}:r?JC({element:r,padding:o}).fn(n):{}}}};var Zh=typeof document<"u"?x.useLayoutEffect:x.useEffect;function sf(e,t){if(e===t)return!0;if(typeof e!=typeof t)return!1;if(typeof e=="function"&&e.toString()===t.toString())return!0;let n,r,o;if(e&&t&&typeof e=="object"){if(Array.isArray(e)){if(n=e.length,n!==t.length)return!1;for(r=n;r--!==0;)if(!sf(e[r],t[r]))return!1;return!0}if(o=Object.keys(e),n=o.length,n!==Object.keys(t).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(t,o[r]))return!1;for(r=n;r--!==0;){const s=o[r];if(!(s==="_owner"&&e.$$typeof)&&!sf(e[s],t[s]))return!1}return!0}return e!==e&&t!==t}function nA(e){return typeof window>"u"?1:(e.ownerDocument.defaultView||window).devicePixelRatio||1}function eI(e,t){const n=nA(e);return Math.round(t*n)/n}function tI(e){const t=x.useRef(e);return Zh(()=>{t.current=e}),t}function XZ(e){e===void 0&&(e={});const{placement:t="bottom",strategy:n="absolute",middleware:r=[],platform:o,elements:{reference:s,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=e,[u,d]=x.useState({x:0,y:0,strategy:n,placement:t,middlewareData:{},isPositioned:!1}),[p,f]=x.useState(r);sf(p,r)||f(r);const[y,g]=x.useState(null),[w,S]=x.useState(null),v=x.useCallback(Q=>{Q!==E.current&&(E.current=Q,g(Q))},[]),C=x.useCallback(Q=>{Q!==_.current&&(_.current=Q,S(Q))},[]),I=s||y,P=i||w,E=x.useRef(null),_=x.useRef(null),k=x.useRef(u),$=l!=null,T=tI(l),j=tI(o),L=x.useCallback(()=>{if(!E.current||!_.current)return;const Q={placement:t,strategy:n,middleware:p};j.current&&(Q.platform=j.current),GZ(E.current,_.current,Q).then(V=>{const U={...V,isPositioned:!0};N.current&&!sf(k.current,U)&&(k.current=U,zi.flushSync(()=>{d(U)}))})},[p,t,n,j]);Zh(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,d(Q=>({...Q,isPositioned:!1})))},[c]);const N=x.useRef(!1);Zh(()=>(N.current=!0,()=>{N.current=!1}),[]),Zh(()=>{if(I&&(E.current=I),P&&(_.current=P),I&&P){if(T.current)return T.current(I,P,L);L()}},[I,P,L,T,$]);const F=x.useMemo(()=>({reference:E,floating:_,setReference:v,setFloating:C}),[v,C]),B=x.useMemo(()=>({reference:I,floating:P}),[I,P]),q=x.useMemo(()=>{const Q={position:n,left:0,top:0};if(!B.floating)return Q;const V=eI(B.floating,u.x),U=eI(B.floating,u.y);return a?{...Q,transform:"translate("+V+"px, "+U+"px)",...nA(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:V,top:U}},[n,a,B.floating,u.x,u.y]);return x.useMemo(()=>({...u,update:L,refs:F,elements:B,floatingStyles:q}),[u,L,F,B,q])}function rA(e){const[t,n]=x.useState(void 0);return Ai(()=>{if(e){n({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;n({width:i,height:a})});return r.observe(e,{box:"border-box"}),()=>r.unobserve(e)}else n(void 0)},[e]),t}const oA="Popper",[sA,ag]=ho(oA),[qZ,iA]=sA(oA),ZZ=e=>{const{__scopePopper:t,children:n}=e,[r,o]=x.useState(null);return x.createElement(qZ,{scope:t,anchor:r,onAnchorChange:o},n)},QZ="PopperAnchor",JZ=x.forwardRef((e,t)=>{const{__scopePopper:n,virtualRef:r,...o}=e,s=iA(QZ,n),i=x.useRef(null),a=Xe(t,i);return x.useEffect(()=>{s.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:x.createElement(Ke.div,X({},o,{ref:a}))}),aA="PopperContent",[eQ,Vre]=sA(aA),tQ=x.forwardRef((e,t)=>{var n,r,o,s,i,a,l,c;const{__scopePopper:u,side:d="bottom",sideOffset:p=0,align:f="center",alignOffset:y=0,arrowPadding:g=0,avoidCollisions:w=!0,collisionBoundary:S=[],collisionPadding:v=0,sticky:C="partial",hideWhenDetached:I=!1,updatePositionStrategy:P="optimized",onPlaced:E,..._}=e,k=iA(aA,u),[$,T]=x.useState(null),j=Xe(t,qe=>T(qe)),[L,N]=x.useState(null),F=rA(L),B=(n=F==null?void 0:F.width)!==null&&n!==void 0?n:0,q=(r=F==null?void 0:F.height)!==null&&r!==void 0?r:0,Q=d+(f!=="center"?"-"+f:""),V=typeof v=="number"?v:{top:0,right:0,bottom:0,left:0,...v},U=Array.isArray(S)?S:[S],H=U.length>0,Z={padding:V,boundary:U.filter(nQ),altBoundary:H},{refs:ce,floatingStyles:be,placement:ke,isPositioned:ae,middlewareData:Te}=XZ({strategy:"fixed",placement:Q,whileElementsMounted:(...qe)=>BZ(...qe,{animationFrame:P==="always"}),elements:{reference:k.anchor},middleware:[vZ({mainAxis:p+q,alignmentAxis:y}),w&&UZ({mainAxis:!0,crossAxis:!1,limiter:C==="partial"?WZ():void 0,...Z}),w&&HZ({...Z}),KZ({...Z,apply:({elements:qe,rects:jt,availableWidth:yo,availableHeight:El})=>{const{width:_l,height:fg}=jt.reference,Gi=qe.floating.style;Gi.setProperty("--radix-popper-available-width",`${yo}px`),Gi.setProperty("--radix-popper-available-height",`${El}px`),Gi.setProperty("--radix-popper-anchor-width",`${_l}px`),Gi.setProperty("--radix-popper-anchor-height",`${fg}px`)}}),L&&YZ({element:L,padding:g}),rQ({arrowWidth:B,arrowHeight:q}),I&&VZ({strategy:"referenceHidden",...Z})]}),[Re,st]=lA(ke),Pe=sn(E);Ai(()=>{ae&&(Pe==null||Pe())},[ae,Pe]);const ft=(o=Te.arrow)===null||o===void 0?void 0:o.x,He=(s=Te.arrow)===null||s===void 0?void 0:s.y,or=((i=Te.arrow)===null||i===void 0?void 0:i.centerOffset)!==0,[Fn,Nn]=x.useState();return Ai(()=>{$&&Nn(window.getComputedStyle($).zIndex)},[$]),x.createElement("div",{ref:ce.setFloating,"data-radix-popper-content-wrapper":"",style:{...be,transform:ae?be.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:Fn,"--radix-popper-transform-origin":[(a=Te.transformOrigin)===null||a===void 0?void 0:a.x,(l=Te.transformOrigin)===null||l===void 0?void 0:l.y].join(" ")},dir:e.dir},x.createElement(eQ,{scope:u,placedSide:Re,onArrowChange:N,arrowX:ft,arrowY:He,shouldHideArrow:or},x.createElement(Ke.div,X({"data-side":Re,"data-align":st},_,{ref:j,style:{..._.style,animation:ae?void 0:"none",opacity:(c=Te.hide)!==null&&c!==void 0&&c.referenceHidden?0:void 0}}))))});function nQ(e){return e!==null}const rQ=e=>({name:"transformOrigin",options:e,fn(t){var n,r,o,s,i;const{placement:a,rects:l,middlewareData:c}=t,d=((n=c.arrow)===null||n===void 0?void 0:n.centerOffset)!==0,p=d?0:e.arrowWidth,f=d?0:e.arrowHeight,[y,g]=lA(a),w={start:"0%",center:"50%",end:"100%"}[g],S=((r=(o=c.arrow)===null||o===void 0?void 0:o.x)!==null&&r!==void 0?r:0)+p/2,v=((s=(i=c.arrow)===null||i===void 0?void 0:i.y)!==null&&s!==void 0?s:0)+f/2;let C="",I="";return y==="bottom"?(C=d?w:`${S}px`,I=`${-f}px`):y==="top"?(C=d?w:`${S}px`,I=`${l.floating.height+f}px`):y==="right"?(C=`${-f}px`,I=d?w:`${v}px`):y==="left"&&(C=`${l.floating.width+f}px`,I=d?w:`${v}px`),{data:{x:C,y:I}}}});function lA(e){const[t,n="center"]=e.split("-");return[t,n]}const Zx=ZZ,cA=JZ,uA=tQ,dA="Popover",[hA,Wre]=ho(dA,[ag]),Qx=ag(),[oQ,Il]=hA(dA),sQ=e=>{const{__scopePopover:t,children:n,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Qx(t),l=x.useRef(null),[c,u]=x.useState(!1),[d=!1,p]=Ys({prop:r,defaultProp:o,onChange:s});return x.createElement(Zx,a,x.createElement(oQ,{scope:t,contentId:Ro(),triggerRef:l,open:d,onOpenChange:p,onOpenToggle:x.useCallback(()=>p(f=>!f),[p]),hasCustomAnchor:c,onCustomAnchorAdd:x.useCallback(()=>u(!0),[]),onCustomAnchorRemove:x.useCallback(()=>u(!1),[]),modal:i},n))},iQ="PopoverTrigger",aQ=x.forwardRef((e,t)=>{const{__scopePopover:n,...r}=e,o=Il(iQ,n),s=Qx(n),i=Xe(t,o.triggerRef),a=x.createElement(Ke.button,X({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":gA(o.open)},r,{ref:i,onClick:se(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(cA,X({asChild:!0},s),a)}),pA="PopoverPortal",[lQ,cQ]=hA(pA,{forceMount:void 0}),uQ=e=>{const{__scopePopover:t,forceMount:n,children:r,container:o}=e,s=Il(pA,t);return x.createElement(lQ,{scope:t,forceMount:n},x.createElement(po,{present:n||s.open},x.createElement(Qf,{asChild:!0,container:o},r)))},fu="PopoverContent",dQ=x.forwardRef((e,t)=>{const n=cQ(fu,e.__scopePopover),{forceMount:r=n.forceMount,...o}=e,s=Il(fu,e.__scopePopover);return x.createElement(po,{present:r||s.open},s.modal?x.createElement(hQ,X({},o,{ref:t})):x.createElement(pQ,X({},o,{ref:t})))}),hQ=x.forwardRef((e,t)=>{const n=Il(fu,e.__scopePopover),r=x.useRef(null),o=Xe(t,r),s=x.useRef(!1);return x.useEffect(()=>{const i=r.current;if(i)return Bx(i)},[]),x.createElement(zx,{as:Mi,allowPinchZoom:!0},x.createElement(fA,X({},e,{ref:o,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=n.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),pQ=x.forwardRef((e,t)=>{const n=Il(fu,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(fA,X({},e,{ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=n.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=n.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),fA=x.forwardRef((e,t)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...d}=e,p=Il(fu,n),f=Qx(n);return Nx(),x.createElement(Fx,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(Zf,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>p.onOpenChange(!1)},x.createElement(uA,X({"data-state":gA(p.open),role:"dialog",id:p.contentId},f,d,{ref:t,style:{...d.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}}))))});function gA(e){return e?"open":"closed"}const fQ=sQ,gQ=aQ,mQ=uQ,yQ=dQ;function Xs(e,t){const n=z(),r=x.useRef(!1),o=fo(),s=x.useCallback(a=>{r.current=a,n.batch(()=>{a?(n.complete(),n.addOpenMenu(e)):n.updateInstanceState({openMenus:n.getOpenMenus().filter(l=>!l.startsWith(e))}),t==null||t(a)})},[n,e,t]),i=K("is menu open",()=>n.getOpenMenus().includes(e),[n,e]);return x.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),n.addOpenMenu(e)),()=>{r.current&&(n.deleteOpenMenu(e),n.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),n.deleteOpenMenu(a))}),r.current=!1)}),[n,e,o]),[i,s]}function Jx({id:e,children:t,onOpenChange:n,open:r}){const[o,s]=Xs(e,n);return h.jsx(fQ,{onOpenChange:s,open:r||o,children:h.jsx("div",{className:"tlui-popover",children:t})})}function ew({children:e}){return h.jsx(gQ,{asChild:!0,dir:"ltr",children:e})}function tw({side:e,children:t,align:n="center",sideOffset:r=8,alignOffset:o=0}){const s=ln();return h.jsx(mQ,{container:s,children:h.jsx(yQ,{className:"tlui-popover__content",side:e,sideOffset:r,align:n,alignOffset:o,dir:"ltr",children:t})})}const mA=x.createContext({type:"menu",sourceId:"main-menu"});function lg(){return x.useContext(mA)}function vr({type:e,sourceId:t,children:n}){return h.jsx(mA.Provider,{value:{type:e,sourceId:t},children:n})}const SQ=x.createContext(void 0);function nw(e){const t=x.useContext(SQ);return e||t||"ltr"}const ny="rovingFocusGroup.onEntryFocus",vQ={bubbles:!1,cancelable:!0},rw="RovingFocusGroup",[xv,yA,xQ]=qf(rw),[wQ,SA]=ho(rw,[xQ]),[bQ,PQ]=wQ(rw),CQ=x.forwardRef((e,t)=>x.createElement(xv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(xv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(IQ,X({},e,{ref:t}))))),IQ=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,...u}=e,d=x.useRef(null),p=Xe(t,d),f=nw(s),[y=null,g]=Ys({prop:i,defaultProp:a,onChange:l}),[w,S]=x.useState(!1),v=sn(c),C=yA(n),I=x.useRef(!1),[P,E]=x.useState(0);return x.useEffect(()=>{const _=d.current;if(_)return _.addEventListener(ny,v),()=>_.removeEventListener(ny,v)},[v]),x.createElement(bQ,{scope:n,orientation:r,dir:f,loop:o,currentTabStopId:y,onItemFocus:x.useCallback(_=>g(_),[g]),onItemShiftTab:x.useCallback(()=>S(!0),[]),onFocusableItemAdd:x.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:x.useCallback(()=>E(_=>_-1),[])},x.createElement(Ke.div,X({tabIndex:w||P===0?-1:0,"data-orientation":r},u,{ref:p,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{I.current=!0}),onFocus:se(e.onFocus,_=>{const k=!I.current;if(_.target===_.currentTarget&&k&&!w){const $=new CustomEvent(ny,vQ);if(_.currentTarget.dispatchEvent($),!$.defaultPrevented){const T=C().filter(B=>B.focusable),j=T.find(B=>B.active),L=T.find(B=>B.id===y),F=[j,L,...T].filter(Boolean).map(B=>B.ref.current);vA(F)}}I.current=!1}),onBlur:se(e.onBlur,()=>S(!1))})))}),EQ="RovingFocusGroupItem",_Q=x.forwardRef((e,t)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Ro(),l=s||a,c=PQ(EQ,n),u=c.currentTabStopId===l,d=yA(n),{onFocusableItemAdd:p,onFocusableItemRemove:f}=c;return x.useEffect(()=>{if(r)return p(),()=>f()},[r,p,f]),x.createElement(xv.ItemSlot,{scope:n,id:l,focusable:r,active:o},x.createElement(Ke.span,X({tabIndex:u?0:-1,"data-orientation":c.orientation},i,{ref:t,onMouseDown:se(e.onMouseDown,y=>{r?c.onItemFocus(l):y.preventDefault()}),onFocus:se(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){c.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=$Q(y,c.orientation,c.dir);if(g!==void 0){y.preventDefault();let S=d().filter(v=>v.focusable).map(v=>v.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const v=S.indexOf(y.currentTarget);S=c.loop?MQ(S,v+1):S.slice(v+1)}setTimeout(()=>vA(S))}})})))}),kQ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function TQ(e,t){return t!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function $Q(e,t,n){const r=TQ(e.key,n);if(!(t==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(t==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return kQ[r]}function vA(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function MQ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}const AQ=CQ,jQ=_Q,wv=["Enter"," "],OQ=["ArrowDown","PageUp","Home"],xA=["ArrowUp","PageDown","End"],DQ=[...OQ,...xA],RQ={ltr:[...wv,"ArrowRight"],rtl:[...wv,"ArrowLeft"]},LQ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},cg="Menu",[gu,FQ,NQ]=qf(cg),[Wi,ug]=ho(cg,[NQ,ag,SA]),dg=ag(),wA=SA(),[bA,qs]=Wi(cg),[zQ,Fu]=Wi(cg),BQ=e=>{const{__scopeMenu:t,open:n=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=dg(t),[l,c]=x.useState(null),u=x.useRef(!1),d=sn(s),p=nw(o);return x.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),x.createElement(Zx,a,x.createElement(bA,{scope:t,open:n,onOpenChange:d,content:l,onContentChange:c},x.createElement(zQ,{scope:t,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:p,modal:i},r)))},PA=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e,o=dg(n);return x.createElement(cA,X({},o,r,{ref:t}))}),CA="MenuPortal",[UQ,IA]=Wi(CA,{forceMount:void 0}),HQ=e=>{const{__scopeMenu:t,forceMount:n,children:r,container:o}=e,s=qs(CA,t);return x.createElement(UQ,{scope:t,forceMount:n},x.createElement(po,{present:n||s.open},x.createElement(Qf,{asChild:!0,container:o},r)))},Lr="MenuContent",[KQ,ow]=Wi(Lr),VQ=x.forwardRef((e,t)=>{const n=IA(Lr,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=qs(Lr,e.__scopeMenu),i=Fu(Lr,e.__scopeMenu);return x.createElement(gu.Provider,{scope:e.__scopeMenu},x.createElement(po,{present:r||s.open},x.createElement(gu.Slot,{scope:e.__scopeMenu},i.modal?x.createElement(WQ,X({},o,{ref:t})):x.createElement(GQ,X({},o,{ref:t})))))}),WQ=x.forwardRef((e,t)=>{const n=qs(Lr,e.__scopeMenu),r=x.useRef(null),o=Xe(t,r);return x.useEffect(()=>{const s=r.current;if(s)return Bx(s)},[]),x.createElement(sw,X({},e,{ref:o,trapFocus:n.open,disableOutsidePointerEvents:n.open,disableOutsideScroll:!0,onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>n.onOpenChange(!1)}))}),GQ=x.forwardRef((e,t)=>{const n=qs(Lr,e.__scopeMenu);return x.createElement(sw,X({},e,{ref:t,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>n.onOpenChange(!1)}))}),sw=x.forwardRef((e,t)=>{const{__scopeMenu:n,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:p,onDismiss:f,disableOutsideScroll:y,...g}=e,w=qs(Lr,n),S=Fu(Lr,n),v=dg(n),C=wA(n),I=FQ(n),[P,E]=x.useState(null),_=x.useRef(null),k=Xe(t,_,w.onContentChange),$=x.useRef(0),T=x.useRef(""),j=x.useRef(0),L=x.useRef(null),N=x.useRef("right"),F=x.useRef(0),B=y?zx:x.Fragment,q=y?{as:Mi,allowPinchZoom:!0}:void 0,Q=U=>{var H,Z;const ce=T.current+U,be=I().filter(Pe=>!Pe.disabled),ke=document.activeElement,ae=(H=be.find(Pe=>Pe.ref.current===ke))===null||H===void 0?void 0:H.textValue,Te=be.map(Pe=>Pe.textValue),Re=aJ(Te,ce,ae),st=(Z=be.find(Pe=>Pe.textValue===Re))===null||Z===void 0?void 0:Z.ref.current;(function Pe(ft){T.current=ft,window.clearTimeout($.current),ft!==""&&($.current=window.setTimeout(()=>Pe(""),1e3))})(ce),st&&setTimeout(()=>st.focus())};x.useEffect(()=>()=>window.clearTimeout($.current),[]),Nx();const V=x.useCallback(U=>{var H,Z;return N.current===((H=L.current)===null||H===void 0?void 0:H.side)&&cJ(U,(Z=L.current)===null||Z===void 0?void 0:Z.area)},[]);return x.createElement(KQ,{scope:n,searchRef:T,onItemEnter:x.useCallback(U=>{V(U)&&U.preventDefault()},[V]),onItemLeave:x.useCallback(U=>{var H;V(U)||((H=_.current)===null||H===void 0||H.focus(),E(null))},[V]),onTriggerLeave:x.useCallback(U=>{V(U)&&U.preventDefault()},[V]),pointerGraceTimerRef:j,onPointerGraceIntentChange:x.useCallback(U=>{L.current=U},[])},x.createElement(B,q,x.createElement(Fx,{asChild:!0,trapped:o,onMountAutoFocus:se(s,U=>{var H;U.preventDefault(),(H=_.current)===null||H===void 0||H.focus()}),onUnmountAutoFocus:i},x.createElement(Zf,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:p,onDismiss:f},x.createElement(AQ,X({asChild:!0},C,{dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:P,onCurrentTabStopIdChange:E,onEntryFocus:se(l,U=>{S.isUsingKeyboardRef.current||U.preventDefault()})}),x.createElement(uA,X({role:"menu","aria-orientation":"vertical","data-state":$A(w.open),"data-radix-menu-content":"",dir:S.dir},v,g,{ref:k,style:{outline:"none",...g.style},onKeyDown:se(g.onKeyDown,U=>{const Z=U.target.closest("[data-radix-menu-content]")===U.currentTarget,ce=U.ctrlKey||U.altKey||U.metaKey,be=U.key.length===1;Z&&(U.key==="Tab"&&U.preventDefault(),!ce&&be&&Q(U.key));const ke=_.current;if(U.target!==ke||!DQ.includes(U.key))return;U.preventDefault();const Te=I().filter(Re=>!Re.disabled).map(Re=>Re.ref.current);xA.includes(U.key)&&Te.reverse(),sJ(Te)}),onBlur:se(e.onBlur,U=>{U.currentTarget.contains(U.target)||(window.clearTimeout($.current),T.current="")}),onPointerMove:se(e.onPointerMove,mu(U=>{const H=U.target,Z=F.current!==U.clientX;if(U.currentTarget.contains(H)&&Z){const ce=U.clientX>F.current?"right":"left";N.current=ce,F.current=U.clientX}}))})))))))}),YQ=x.forwardRef((e,t)=>{const{__scopeMenu:n,...r}=e;return x.createElement(Ke.div,X({role:"group"},r,{ref:t}))}),bv="MenuItem",nI="menu.itemSelect",EA=x.forwardRef((e,t)=>{const{disabled:n=!1,onSelect:r,...o}=e,s=x.useRef(null),i=Fu(bv,e.__scopeMenu),a=ow(bv,e.__scopeMenu),l=Xe(t,s),c=x.useRef(!1),u=()=>{const d=s.current;if(!n&&d){const p=new CustomEvent(nI,{bubbles:!0,cancelable:!0});d.addEventListener(nI,f=>r==null?void 0:r(f),{once:!0}),Rx(d,p),p.defaultPrevented?c.current=!1:i.onClose()}};return x.createElement(_A,X({},o,{ref:l,disabled:n,onClick:se(e.onClick,u),onPointerDown:d=>{var p;(p=e.onPointerDown)===null||p===void 0||p.call(e,d),c.current=!0},onPointerUp:se(e.onPointerUp,d=>{var p;c.current||(p=d.currentTarget)===null||p===void 0||p.click()}),onKeyDown:se(e.onKeyDown,d=>{const p=a.searchRef.current!=="";n||p&&d.key===" "||wv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),_A=x.forwardRef((e,t)=>{const{__scopeMenu:n,disabled:r=!1,textValue:o,...s}=e,i=ow(bv,n),a=wA(n),l=x.useRef(null),c=Xe(t,l),[u,d]=x.useState(!1),[p,f]=x.useState("");return x.useEffect(()=>{const y=l.current;if(y){var g;f(((g=y.textContent)!==null&&g!==void 0?g:"").trim())}},[s.children]),x.createElement(gu.ItemSlot,{scope:n,disabled:r,textValue:o??p},x.createElement(jQ,X({asChild:!0},a,{focusable:!r}),x.createElement(Ke.div,X({role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:c,onPointerMove:se(e.onPointerMove,mu(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus())})),onPointerLeave:se(e.onPointerLeave,mu(y=>i.onItemLeave(y))),onFocus:se(e.onFocus,()=>d(!0)),onBlur:se(e.onBlur,()=>d(!1))}))))}),XQ=x.forwardRef((e,t)=>{const{checked:n=!1,onCheckedChange:r,...o}=e;return x.createElement(QQ,{scope:e.__scopeMenu,checked:n},x.createElement(EA,X({role:"menuitemcheckbox","aria-checked":Pv(n)?"mixed":n},o,{ref:t,"data-state":oJ(n),onSelect:se(o.onSelect,()=>r==null?void 0:r(Pv(n)?!0:!n),{checkForDefaultPrevented:!1})})))}),qQ="MenuRadioGroup";Wi(qQ,{value:void 0,onValueChange:()=>{}});const ZQ="MenuItemIndicator",[QQ,Gre]=Wi(ZQ,{checked:!1}),kA="MenuSub",[JQ,TA]=Wi(kA),eJ=e=>{const{__scopeMenu:t,children:n,open:r=!1,onOpenChange:o}=e,s=qs(kA,t),i=dg(t),[a,l]=x.useState(null),[c,u]=x.useState(null),d=sn(o);return x.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),x.createElement(Zx,i,x.createElement(bA,{scope:t,open:r,onOpenChange:d,content:c,onContentChange:u},x.createElement(JQ,{scope:t,contentId:Ro(),triggerId:Ro(),trigger:a,onTriggerChange:l},n)))},Xd="MenuSubTrigger",tJ=x.forwardRef((e,t)=>{const n=qs(Xd,e.__scopeMenu),r=Fu(Xd,e.__scopeMenu),o=TA(Xd,e.__scopeMenu),s=ow(Xd,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),x.createElement(PA,X({asChild:!0},c),x.createElement(_A,X({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":n.open,"aria-controls":o.contentId,"data-state":$A(n.open)},e,{ref:Xf(t,o.onTriggerChange),onClick:d=>{var p;(p=e.onClick)===null||p===void 0||p.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),n.open||n.onOpenChange(!0))},onPointerMove:se(e.onPointerMove,mu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!n.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{n.onOpenChange(!0),u()},100))})),onPointerLeave:se(e.onPointerLeave,mu(d=>{var p;u();const f=(p=n.content)===null||p===void 0?void 0:p.getBoundingClientRect();if(f){var y;const g=(y=n.content)===null||y===void 0?void 0:y.dataset.side,w=g==="right",S=w?-5:5,v=f[w?"left":"right"],C=f[w?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+S,y:d.clientY},{x:v,y:f.top},{x:C,y:f.top},{x:C,y:f.bottom},{x:v,y:f.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:se(e.onKeyDown,d=>{const p=s.searchRef.current!=="";if(!(e.disabled||p&&d.key===" ")&&RQ[r.dir].includes(d.key)){var f;n.onOpenChange(!0),(f=n.content)===null||f===void 0||f.focus(),d.preventDefault()}})})))}),nJ="MenuSubContent",rJ=x.forwardRef((e,t)=>{const n=IA(Lr,e.__scopeMenu),{forceMount:r=n.forceMount,...o}=e,s=qs(Lr,e.__scopeMenu),i=Fu(Lr,e.__scopeMenu),a=TA(nJ,e.__scopeMenu),l=x.useRef(null),c=Xe(t,l);return x.createElement(gu.Provider,{scope:e.__scopeMenu},x.createElement(po,{present:r||s.open},x.createElement(gu.Slot,{scope:e.__scopeMenu},x.createElement(sw,X({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;i.isUsingKeyboardRef.current&&((d=l.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:se(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:se(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:se(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),p=LQ[i.dir].includes(u.key);if(d&&p){var f;s.onOpenChange(!1),(f=a.trigger)===null||f===void 0||f.focus(),u.preventDefault()}})})))))});function $A(e){return e?"open":"closed"}function Pv(e){return e==="indeterminate"}function oJ(e){return Pv(e)?"indeterminate":e?"checked":"unchecked"}function sJ(e){const t=document.activeElement;for(const n of e)if(n===t||(n.focus(),document.activeElement!==t))return}function iJ(e,t){return e.map((n,r)=>e[(t+r)%e.length])}function aJ(e,t,n){const o=t.length>1&&Array.from(t).every(c=>c===t[0])?t[0]:t,s=n?e.indexOf(n):-1;let i=iJ(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==n));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==n?l:void 0}function lJ(e,t){const{x:n,y:r}=e;let o=!1;for(let s=0,i=t.length-1;s<t.length;i=s++){const a=t[s].x,l=t[s].y,c=t[i].x,u=t[i].y;l>r!=u>r&&n<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function cJ(e,t){if(!t)return!1;const n={x:e.clientX,y:e.clientY};return lJ(n,t)}function mu(e){return t=>t.pointerType==="mouse"?e(t):void 0}const MA=BQ,AA=PA,jA=HQ,OA=VQ,DA=YQ,RA=EA,LA=XQ,FA=eJ,NA=tJ,zA=rJ,BA="ContextMenu",[uJ,Yre]=ho(BA,[ug]),go=ug(),[dJ,UA]=uJ(BA),hJ=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=x.useState(!1),l=go(t),c=sn(r),u=x.useCallback(d=>{a(d),c(d)},[c]);return x.createElement(dJ,{scope:t,open:i,onOpenChange:u,modal:s},x.createElement(MA,X({},l,{dir:o,open:i,onOpenChange:u,modal:s}),n))},pJ="ContextMenuTrigger",fJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,disabled:r=!1,...o}=e,s=UA(pJ,n),i=go(n),a=x.useRef({x:0,y:0}),l=x.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=x.useRef(0),u=x.useCallback(()=>window.clearTimeout(c.current),[]),d=p=>{a.current={x:p.clientX,y:p.clientY},s.onOpenChange(!0)};return x.useEffect(()=>u,[u]),x.useEffect(()=>void(r&&u()),[r,u]),x.createElement(x.Fragment,null,x.createElement(AA,X({},i,{virtualRef:l})),x.createElement(Ke.span,X({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:t,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:se(e.onContextMenu,p=>{u(),d(p),p.preventDefault()}),onPointerDown:r?e.onPointerDown:se(e.onPointerDown,qd(p=>{u(),c.current=window.setTimeout(()=>d(p),700)})),onPointerMove:r?e.onPointerMove:se(e.onPointerMove,qd(u)),onPointerCancel:r?e.onPointerCancel:se(e.onPointerCancel,qd(u)),onPointerUp:r?e.onPointerUp:se(e.onPointerUp,qd(u))})))}),HA=e=>{const{__scopeContextMenu:t,...n}=e,r=go(t);return x.createElement(jA,X({},r,n))},gJ="ContextMenuContent",mJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=UA(gJ,n),s=go(n),i=x.useRef(!1);return x.createElement(OA,X({},s,r,{ref:t,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),yJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=go(n);return x.createElement(DA,X({},o,r,{ref:t}))}),SJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=go(n);return x.createElement(RA,X({},o,r,{ref:t}))}),vJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=go(n);return x.createElement(LA,X({},o,r,{ref:t}))}),xJ=e=>{const{__scopeContextMenu:t,children:n,onOpenChange:r,open:o,defaultOpen:s}=e,i=go(t),[a,l]=Ys({prop:o,defaultProp:s,onChange:r});return x.createElement(FA,X({},i,{open:a,onOpenChange:l}),n)},wJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=go(n);return x.createElement(NA,X({},o,r,{ref:t}))}),bJ=x.forwardRef((e,t)=>{const{__scopeContextMenu:n,...r}=e,o=go(n);return x.createElement(zA,X({},o,r,{ref:t,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))});function qd(e){return t=>t.pointerType!=="mouse"?e(t):void 0}const PJ=hJ,CJ=fJ,IJ=HA,EJ=mJ,_J=vJ,KA=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,kJ=KA?"⌘":"Ctrl",TJ=KA?"⌥":"Alt";function VA(e){return e.split(",")[0].split("").map(t=>{const n=t.replace(/\$/g,kJ).replace(/\?/g,TJ).replace(/!/g,"⇧");return n[0].toUpperCase()+n.slice(1)})}function Cv(e){return"— "+VA(e).join(" ")}function $J(e){return h.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:h.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[h.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),h.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:h.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const WA="DropdownMenu",[MJ,Xre]=ho(WA,[ug]),mo=ug(),[AJ,GA]=MJ(WA),jJ=e=>{const{__scopeDropdownMenu:t,children:n,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=mo(t),c=x.useRef(null),[u=!1,d]=Ys({prop:o,defaultProp:s,onChange:i});return x.createElement(AJ,{scope:t,triggerId:Ro(),triggerRef:c,contentId:Ro(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(p=>!p),[d]),modal:a},x.createElement(MA,X({},l,{open:u,onOpenChange:d,dir:r,modal:a}),n))},OJ="DropdownMenuTrigger",DJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,disabled:r=!1,...o}=e,s=GA(OJ,n),i=mo(n);return x.createElement(AA,X({asChild:!0},i),x.createElement(Ke.button,X({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:Xf(t,s.triggerRef),onPointerDown:se(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:se(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),RJ=e=>{const{__scopeDropdownMenu:t,...n}=e,r=mo(t);return x.createElement(jA,X({},r,n))},LJ="DropdownMenuContent",FJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=GA(LJ,n),s=mo(n),i=x.useRef(!1);return x.createElement(OA,X({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:t,onCloseAutoFocus:se(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)===null||l===void 0||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),NJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=mo(n);return x.createElement(DA,X({},o,r,{ref:t}))}),zJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=mo(n);return x.createElement(RA,X({},o,r,{ref:t}))}),BJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=mo(n);return x.createElement(LA,X({},o,r,{ref:t}))}),UJ=e=>{const{__scopeDropdownMenu:t,children:n,open:r,onOpenChange:o,defaultOpen:s}=e,i=mo(t),[a=!1,l]=Ys({prop:r,defaultProp:s,onChange:o});return x.createElement(FA,X({},i,{open:a,onOpenChange:l}),n)},HJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=mo(n);return x.createElement(NA,X({},o,r,{ref:t}))}),KJ=x.forwardRef((e,t)=>{const{__scopeDropdownMenu:n,...r}=e,o=mo(n);return x.createElement(zA,X({},o,r,{ref:t,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)"}}))}),iw=jJ,aw=DJ,hg=RJ,lw=FJ,VJ=NJ,WJ=zJ,GJ=BJ,YJ=UJ,XJ=HJ,qJ=KJ;function Oi({id:e,children:t,modal:n=!1,debugOpen:r=!1}){const[o,s]=Xs(e);return h.jsx(iw,{open:r||o,dir:"ltr",modal:n,onOpenChange:s,children:t})}function Di({children:e,...t}){return h.jsx(aw,{dir:"ltr",asChild:!0,onTouchEnd:n=>Ae(n),...t,children:e})}function Ri({side:e="bottom",align:t="start",sideOffset:n=8,alignOffset:r=8,children:o}){const s=ln();return h.jsx(hg,{container:s,children:h.jsx(lw,{className:"tlui-menu",side:e,sideOffset:n,align:t,alignOffset:r,collisionPadding:4,children:o})})}function ZJ({id:e,children:t}){const[n,r]=Xs(e);return h.jsx(YJ,{open:n,onOpenChange:r,children:t})}function QJ({id:e,label:t,title:n,disabled:r}){return h.jsx(XJ,{dir:"ltr",asChild:!0,disabled:r,children:h.jsxs(pe,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:n,children:[h.jsx(xt,{children:t}),h.jsx(Ie,{icon:"chevron-right",small:!0})]})})}function JJ({id:e,alignOffset:t=-1,sideOffset:n=-4,size:r="small",children:o}){const s=ln();return h.jsx(hg,{container:s,children:h.jsx(qJ,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:t,sideOffset:n,collisionPadding:4,"data-size":r,children:o})})}function eee({children:e}){return h.jsx(VJ,{dir:"ltr",className:"tlui-menu__group",children:e})}function yu({noClose:e,children:t}){return h.jsx(WJ,{dir:"ltr",asChild:!0,onClick:e?Ae:void 0,children:t})}function $c({children:e,visibleOnMobileLayout:t=!1}){const n=Ln();return!t&&n<yt.MOBILE?null:h.jsx("kbd",{className:"tlui-kbd",children:VA(e).map((r,o)=>h.jsx("span",{children:r},o))})}function R({disabled:e=!1,spinner:t=!1,readonlyOk:n=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:l,isSelected:c}){const{type:u,sourceId:d}=lg(),p=_e(),[f,y]=x.useState(!1);if(es()&&!n)return null;const w=du(s,u),S=o?Cv(o):void 0,v=w?p(w):void 0,C=v&&S?`${v} ${S}`:v;switch(u){case"menu":return h.jsx(yu,{children:h.jsxs(pe,{type:"menu","data-testid":`${d}.${r}`,disabled:e,title:C,onClick:I=>{l&&Ae(I),f?y(!1):a(d)},children:[h.jsx(xt,{children:v}),o&&h.jsx($c,{children:o})]})});case"context-menu":return e?null:h.jsxs(SJ,{dir:"ltr",title:C,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${d}.${r}`,onSelect:I=>{l&&Ae(I),f?y(!1):a(d)},children:[h.jsx("span",{className:"tlui-button__label",draggable:!1,children:v}),o&&h.jsx($c,{children:o}),t&&h.jsx($J,{})]});case"panel":return h.jsxs(pe,{"data-testid":`${d}.${r}`,type:"menu",title:C,disabled:e,onClick:()=>a(d),children:[h.jsx(xt,{children:v}),i&&h.jsx(Ie,{icon:i})]});case"small-icons":case"icons":return h.jsx(pe,{"data-testid":`${d}.${r}`,type:"icon",title:C,disabled:e,onClick:()=>a(d),children:h.jsx(Ie,{icon:i,small:u==="small-icons"})});case"keyboard-shortcuts":return o?h.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${d}.${r}`,children:[h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:v}),h.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:h.jsx($c,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return h.jsxs(pe,{type:"low",onClick:()=>a(d),children:[h.jsx(Ie,{icon:i}),h.jsx(xt,{children:v})]});case"toolbar":return h.jsx(pe,{type:"tool","data-testid":`tools.${r}`,"aria-label":w,"data-value":r,onClick:()=>a("toolbar"),title:C,onTouchStart:I=>{Ae(I),a("toolbar")},role:"radio","aria-checked":c?"true":"false",children:h.jsx(Ie,{icon:i})});case"toolbar-overflow":return h.jsx(yu,{"aria-label":s,children:h.jsx(pe,{type:"icon",className:"tlui-button-grid__button",onClick:()=>{a("toolbar")},"data-testid":`tools.more.${r}`,title:C,role:"radio","aria-checked":c?"true":"false","data-value":r,children:h.jsx(Ie,{icon:i})})});default:throw Bs(u)}}function tee(){return h.jsxs(h.Fragment,{children:[h.jsx(nee,{}),h.jsx(ree,{}),h.jsx(oee,{}),h.jsx(see,{}),h.jsx(iee,{}),h.jsx(cee,{}),h.jsx(uee,{}),h.jsx(dee,{})]})}function nee(){const e=le(),t=vn(2);return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["align-left"],disabled:!t}),h.jsx(R,{...e["align-center-horizontal"],disabled:!t}),h.jsx(R,{...e["align-right"],disabled:!t}),h.jsx(R,{...e["stretch-horizontal"],disabled:!t}),h.jsx(R,{...e["align-top"],disabled:!t}),h.jsx(R,{...e["align-center-vertical"],disabled:!t}),h.jsx(R,{...e["align-bottom"],disabled:!t}),h.jsx(R,{...e["stretch-vertical"],disabled:!t})]})}function ree(){const e=le(),t=vn(3);return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["distribute-horizontal"],disabled:!t}),h.jsx(R,{...e["distribute-vertical"],disabled:!t})]})}function oee(){const e=le(),t=N2();return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["stack-horizontal"],disabled:!t}),h.jsx(R,{...e["stack-vertical"],disabled:!t})]})}function see(){const e=le(),t=vn(1);return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["send-to-back"],disabled:!t}),h.jsx(R,{...e["send-backward"],disabled:!t}),h.jsx(R,{...e["bring-forward"],disabled:!t}),h.jsx(R,{...e["bring-to-front"],disabled:!t})]})}function iee(){return Ln()<yt.TABLET_SM?h.jsx(aee,{}):h.jsx(lee,{})}function aee(){const e=le(),t=z(),n=K("zoom is 1",()=>t.getZoomLevel()===1,[t]);return h.jsx(R,{...e["zoom-to-100"],disabled:n})}function lee(){const e=le(),t=vn(1);return h.jsx(R,{...e["rotate-ccw"],disabled:!t})}function cee(){const e=le(),t=vn(1);return h.jsx(R,{...e["rotate-cw"],disabled:!t})}function uee(){const e=le(),t=U2();return h.jsx(R,{...e["edit-link"],disabled:!t})}function dee(){const e=z2(),t=B2();return e?h.jsx(rI,{}):t?h.jsx(hee,{}):h.jsx(rI,{})}function rI(){const e=le(),t=vn(2);return h.jsx(R,{...e.group,disabled:!t})}function hee(){const e=le();return h.jsx(R,{...e.ungroup})}const pee=x.memo(function({children:t}){const n=_e(),r=Ln(),o=es(),s=z(),i=K("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=t??h.jsx(tee,{});if(!(o&&!i))return h.jsxs(Jx,{id:"actions-menu",children:[h.jsx(ew,{children:h.jsx(pe,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:h.jsx(Ie,{icon:"dots-vertical",small:!0})})}),h.jsx(tw,{side:r>=yt.TABLET?"bottom":"top",sideOffset:6,children:h.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:h.jsx(vr,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function xr({id:e,kbd:t,label:n,readonlyOk:r,onSelect:o,disabled:s=!1,checked:i=!1}){const{type:a,sourceId:l}=lg(),c=es(),u=_e();if(c&&!r)return null;const d=du(n,a),p=d?u(d):void 0;switch(a){case"menu":return h.jsxs(GJ,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:p,onSelect:f=>{o==null||o(l),Ae(f)},disabled:s,checked:i,children:[h.jsx(Rs,{small:!0,icon:i?"check":"checkbox-empty"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),t&&h.jsx($c,{children:t})]});case"context-menu":return h.jsxs(_J,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:p,onSelect:f=>{o(l),Ae(f)},disabled:s,checked:i,children:[h.jsx(Rs,{small:!0,icon:i?"check":"checkbox-empty"}),p&&h.jsx("span",{className:"tlui-button__label",draggable:!1,children:p}),t&&h.jsx($c,{children:t})]},e);default:return null}}function ye({id:e,label:t,children:n}){const{type:r,sourceId:o}=lg(),s=_e(),i=du(t,r),a=i?s(i):void 0;switch(r){case"panel":return h.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:n});case"menu":return h.jsx(eee,{"data-testid":`${o}-group.${e}`,children:n});case"context-menu":return h.jsx(yJ,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:n});case"keyboard-shortcuts":return h.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[h.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),h.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:n})]});default:return n}}function wr({id:e,disabled:t=!1,label:n,size:r="small",children:o}){const{type:s,sourceId:i}=lg(),a=ln(),l=_e(),c=n?typeof n=="string"?n:n[s]??n.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return h.jsxs(ZJ,{id:`${i}-sub.${e}`,children:[h.jsx(QJ,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:t,label:u,title:u}),h.jsx(JJ,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return t?null:h.jsxs(fee,{id:`${i}-sub.${e}`,children:[h.jsx(wJ,{dir:"ltr",disabled:t,asChild:!0,children:h.jsxs(pe,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[h.jsx(xt,{children:u}),h.jsx(Ie,{icon:"chevron-right",small:!0})]})}),h.jsx(HA,{container:a,children:h.jsx(bJ,{"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 fee({id:e,children:t}){const[n,r]=Xs(e);return h.jsx(xJ,{open:n,onOpenChange:r,children:t})}function YA(){const e=le();return nV()?h.jsx(R,{...e["toggle-auto-size"]}):null}function XA(){const e=le();return U2()?h.jsx(R,{...e["edit-link"]}):null}function gee(){const e=le();return vn(1)?h.jsx(R,{...e.duplicate}):null}function qA(){const e=le();return z2()?h.jsx(R,{...e.group}):null}function ZA(){const e=le();return B2()?h.jsx(R,{...e.ungroup}):null}function QA(){const e=z(),t=le();return K("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e])?h.jsx(R,{...t["remove-frame"]}):null}function JA(){const e=z(),t=le();return K("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e])?h.jsx(R,{...t["fit-frame-to-content"]}):null}function ej(){const e=z(),t=le();return K("selected shapes",()=>e.getSelectedShapes().length>0,[e])?h.jsx(R,{...t["toggle-lock"]}):null}function cw(){const e=le(),t=z(),n=K("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return h.jsx(xr,{...e["toggle-transparent"],checked:n})}function mee(){const e=z(),t=le(),n=K("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsx(R,{...t["unlock-all"],disabled:!n})}function tj(){const e=z(),t=K("zoomed to 100",()=>e.getZoomLevel()===1,[e]),n=le();return h.jsx(R,{...n["zoom-to-100"],noClose:!0,disabled:t})}function nj(){const e=z(),t=K("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),n=le();return h.jsx(R,{...n["zoom-to-fit"],disabled:!t,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function rj(){const e=z(),t=K("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),n=le();return h.jsx(R,{...n["zoom-to-selection"],disabled:!t,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function oj(){return h.jsxs(ye,{id:"clipboard",children:[h.jsx(See,{}),h.jsx(vee,{}),h.jsx(xee,{}),h.jsx(gee,{}),h.jsx(wee,{})]})}function yee(){var r;const e=z(),t=le(),n=K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e]);return h.jsxs(wr,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!n,children:[h.jsxs(ye,{id:"copy-as-group",children:[h.jsx(R,{...t["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&h.jsx(R,{...t["copy-as-png"]}),h.jsx(R,{...t["copy-as-json"]})]}),h.jsx(ye,{id:"copy-as-bg",children:h.jsx(cw,{})})]})}function See(){const e=le(),t=vn(1);return h.jsx(R,{...e.cut,disabled:!t})}function vee(){const e=le(),t=tV(1);return h.jsx(R,{...e.copy,disabled:!t})}function xee(){const e=le(),t=eV;return h.jsx(R,{...e.paste,disabled:!t})}function sj(){const e=z(),t=le();return K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[e])?h.jsxs(ye,{id:"conversions",children:[h.jsx(yee,{}),h.jsxs(wr,{id:"export-as",label:"context-menu.export-as",size:"small",children:[h.jsxs(ye,{id:"export-as-group",children:[h.jsx(R,{...t["export-as-svg"]}),h.jsx(R,{...t["export-as-png"]}),h.jsx(R,{...t["export-as-json"]})]}),h.jsx(ye,{id:"export-as-bg",children:h.jsx(cw,{})})]})]}):null}function ij(){const e=le(),t=z(),n=K("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return h.jsx(R,{...e["select-all"],disabled:!n})}function wee(){const e=le(),t=vn(1);return h.jsx(R,{...e.delete,disabled:!t})}function bee(){const e=vn(2),t=rV(),n=le();return e||t?h.jsxs(wr,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&h.jsxs(ye,{id:"align",children:[h.jsx(R,{...n["align-left"]}),h.jsx(R,{...n["align-center-horizontal"]}),h.jsx(R,{...n["align-right"]}),h.jsx(R,{...n["align-top"]}),h.jsx(R,{...n["align-center-vertical"]}),h.jsx(R,{...n["align-bottom"]})]}),h.jsx(Pee,{}),e&&h.jsxs(ye,{id:"stretch",children:[h.jsx(R,{...n["stretch-horizontal"]}),h.jsx(R,{...n["stretch-vertical"]})]}),(e||t)&&h.jsxs(ye,{id:"flip",children:[h.jsx(R,{...n["flip-horizontal"]}),h.jsx(R,{...n["flip-vertical"]})]}),h.jsx(Cee,{})]}):null}function Pee(){const e=le();return vn(3)?h.jsxs(ye,{id:"distribute",children:[h.jsx(R,{...e["distribute-horizontal"]}),h.jsx(R,{...e["distribute-vertical"]})]}):null}function Cee(){const e=le(),t=vn(2),n=N2();return t?h.jsxs(ye,{id:"order",children:[h.jsx(R,{...e.pack}),n&&h.jsx(R,{...e["stack-horizontal"]}),n&&h.jsx(R,{...e["stack-vertical"]})]}):null}function Iee(){const e=le();return vn(1)?h.jsx(wr,{id:"reorder",label:"context-menu.reorder",size:"small",children:h.jsxs(ye,{id:"reorder",children:[h.jsx(R,{...e["bring-to-front"]}),h.jsx(R,{...e["bring-forward"]}),h.jsx(R,{...e["send-backward"]}),h.jsx(R,{...e["send-to-back"]})]})}):null}function Eee(){const e=z(),t=K("pages",()=>e.getPages(),[e]),n=K("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Br(),o=le(),s=fo();return vn(1)?h.jsxs(wr,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[h.jsx(ye,{id:"pages",children:t.map(a=>h.jsx(R,{id:a.id,disabled:n===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(n)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),h.jsx(ye,{id:"new-page",children:h.jsx(R,{...o["new-page"]})})]}):null}function aj(){const e=z(),t=le();return K("oneEmbedSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"embed")&&r.props.url&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(R,{...t["convert-to-bookmark"]}):null}function lj(){const e=z(),t=le();return K("oneEmbeddableBookmarkSelected",()=>{const r=e.getOnlySelectedShape();return r?!!(e.isShapeOfType(r,"bookmark")&&r.props.url&&xs(r.props.url)&&!e.isShapeOrAncestorLocked(r)):!1},[e])?h.jsx(R,{...t["convert-to-embed"]}):null}function _ee(){const e=le(),t=z(),n=K("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return h.jsx(xr,{...e["toggle-snap-mode"],checked:n})}function kee(){const e=le(),t=z(),n=K("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return h.jsx(xr,{...e["toggle-tool-lock"],checked:n})}function Tee(){const e=le(),t=z(),n=K("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return h.jsx(xr,{...e["toggle-grid"],checked:n})}function $ee(){const e=le(),t=z(),n=K("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return h.jsx(xr,{...e["toggle-wrap-mode"],checked:n})}function Mee(){const e=le(),t=z(),n=K("isDarkMode",()=>t.user.getIsDarkMode(),[t]);return h.jsx(xr,{...e["toggle-dark-mode"],checked:n})}function Aee(){const e=le(),t=z(),n=K("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return h.jsx(xr,{...e["toggle-focus-mode"],checked:n})}function jee(){const e=le(),t=z(),n=K("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return h.jsx(xr,{...e["toggle-edge-scrolling"],checked:n===1})}function Oee(){const e=le(),t=z(),n=K("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return h.jsx(xr,{...e["toggle-reduce-motion"],checked:n===0})}function Dee(){const e=le(),t=z(),n=K("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return h.jsx(xr,{...e["toggle-debug-mode"],checked:n})}function Ree(){const e=z();return K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?h.jsxs(h.Fragment,{children:[h.jsxs(ye,{id:"misc",children:[h.jsx(qA,{}),h.jsx(ZA,{}),h.jsx(XA,{}),h.jsx(YA,{}),h.jsx(QA,{}),h.jsx(JA,{}),h.jsx(lj,{}),h.jsx(aj,{}),h.jsx(ej,{})]}),h.jsxs(ye,{id:"modify",children:[h.jsx(bee,{}),h.jsx(Iee,{}),h.jsx(Eee,{})]}),h.jsx(oj,{}),h.jsx(sj,{}),h.jsx(ye,{id:"select-all",children:h.jsx(ij,{})})]}):null}const Lee=x.memo(function({children:t}){const n=z(),{Canvas:r}=ht(),o=x.useCallback(c=>{if(c){if(n.getInstanceState().isCoarsePointer){const u=n.getSelectedShapes(),{inputs:{currentPagePoint:d}}=n,p=n.getShapesAtPoint(d);if(!n.getSelectedShapes().length||!p.some(f=>u.includes(f))){const f=p.filter(y=>n.isShapeOrAncestorLocked(y));f.length&&n.select(...f.map(y=>y.id))}}}else{const u=n.getOnlySelectedShape();u&&n.isShapeOrAncestorLocked(u)&&n.setSelectedShapes([])}},[n]),s=ln(),[i,a]=Xs("context menu",o),l=t??h.jsx(Ree,{});return h.jsxs(PJ,{dir:"ltr",onOpenChange:a,modal:!1,children:[h.jsx(CJ,{onContextMenu:void 0,dir:"ltr",children:r?h.jsx(r,{}):null}),i&&h.jsx(IJ,{container:s,children:h.jsx(EJ,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:Ae,children:h.jsx(vr,{type:"context-menu",sourceId:"context-menu",children:l})})})]})});function Iv({checked:e}){return h.jsx(Rs,{icon:e?"check":"checkbox-empty",className:"tlui-button__icon",small:!0})}function Fee(){const e=z(),{addToast:t}=Br(),{addDialog:n}=Vi(),[r,o]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(ye,{id:"items",children:[h.jsx(R,{id:"add-toast",onSelect:()=>{t({id:nt(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),t({id:nt(),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:()=>{}}]}),t({id:nt(),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:()=>{}}]}),t({id:nt(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),h.jsx(R,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:s})=>h.jsx(Bee,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),h.jsx(R,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>Uee(e,100)}),h.jsx(R,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const s=e.getSelectedShapes(),i=s.length===0?e.getRenderingShapes():s;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),h.jsx(R,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),h.jsx(R,{id:"hard-reset",onSelect:l_,label:"Hard reset"})]}),h.jsxs(ye,{id:"flags",children:[h.jsx(Nee,{}),h.jsx(zee,{})]})]})}function Nee(){const e=Object.values(Tt);return e.length?h.jsx(wr,{id:"debug flags",label:"Debug Flags",children:h.jsx(ye,{id:"debug flags",children:e.map(t=>h.jsx(cj,{flag:t},t.name))})}):null}function zee(){const e=Object.values(v3);return e.length?h.jsx(wr,{id:"feature flags",label:"Feature Flags",children:h.jsx(ye,{id:"feature flags",children:e.map(t=>h.jsx(cj,{flag:t},t.name))})}):null}function Bee({title:e="title",body:t="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=Se.useState(!1);return h.jsxs(h.Fragment,{children:[h.jsxs(ng,{children:[h.jsx(rg,{children:e}),h.jsx(og,{})]}),h.jsx(uu,{style:{maxWidth:350},children:t}),h.jsxs(Ux,{className:"tlui-dialog__footer__actions",children:[o&&h.jsxs(pe,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[h.jsx(Iv,{checked:a}),h.jsx(xt,{children:"Don't show again"})]}),h.jsx(pe,{type:"normal",onClick:s,children:h.jsx(xt,{children:n})}),h.jsx(pe,{type:"primary",onClick:async()=>i(),children:h.jsx(xt,{children:r})})]})]})}const cj=tr(function({flag:t,onChange:n}){const r=t.get();return h.jsx(xr,{id:t.name,title:t.name,label:t.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{t.set(!r),n==null||n(!r)}})});let oI=0;function Uee(e,t){const n=Array(t),r=Math.floor(Math.sqrt(t));for(let o=0;o<t;o++)oI++,n[o]={id:Be("box"+oI),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(n).setSelectedShapes(n.map(o=>o.id))})}function Hee({children:e}){const t=e??h.jsx(Fee,{});return h.jsxs(Oi,{id:"debug",children:[h.jsx(Di,{children:h.jsx(pe,{type:"icon",title:"Debug menu",children:h.jsx(Ie,{icon:"dots-horizontal"})})}),h.jsx(Ri,{side:"top",align:"end",alignOffset:0,children:h.jsx(vr,{type:"menu",sourceId:"debug-panel",children:t})})]})}const Kee=x.memo(function(){const{DebugMenu:t}=Zs();return h.jsxs("div",{className:"tlui-debug-panel",children:[h.jsx(Wee,{}),h.jsx(Gee,{}),t&&h.jsx(t,{})]})});function Vee(e=!0){const[t,n]=x.useState(0),r=z();x.useEffect(()=>{if(!e)return;const o=()=>n(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const Wee=tr(function(){Vee();const t=z(),n=t.getPath(),r=t.getHoveredShape(),o=t.getOnlySelectedShape(),s=n==="select.idle"||!n.includes("select.")?r:o,i=s&&n.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${b.ToFixed(t.getPointInShapeSpace(s,t.inputs.currentPagePoint),0)}]`:"",a=n.startsWith("select.")&&!n.includes(".idle")?` / [${b.ToFixed(t.inputs.originPagePoint,0)}] → [${b.ToFixed(t.inputs.currentPagePoint,0)}] = ${b.Dist(t.inputs.originPagePoint,t.inputs.currentPagePoint).toFixed(0)}`:"";return h.jsx("div",{className:"tlui-debug-panel__current-state",children:`${n}${i}${a}`})});function Gee(){const e=K("show_fps",()=>Tt.showFps.get(),[Tt]),t=x.useRef(null);return x.useEffect(()=>{if(!e)return;const n=250;let r=0,o=!1,s=performance.now(),i=0,a=0,l=!1;function c(){if(!o){if(a++,i=performance.now()-s,i>n){const u=Math.round(a*(n/i)*(1e3/n));u>r&&(r=u);const d=r*.75;(u<d&&!l||u>=d&&l)&&(l=!l),t.current.innerHTML=`FPS ${u.toString()}`,t.current.className="tlui-debug-panel__fps"+(l?" tlui-debug-panel__fps__slow":""),i-=n,a=0,s=performance.now()}requestAnimationFrame(c)}}return c(),()=>{o=!0}},[e]),e?h.jsx("div",{ref:t}):null}function uj(){const e=z(),t=fo(),n=K("locale",()=>e.user.getLocale(),[e]);return h.jsx(wr,{id:"help menu language",label:"menu.language",children:h.jsx(ye,{id:"languages",children:Rc.map(({locale:r,label:o})=>h.jsx(xr,{id:`language-${r}`,title:r,label:o,checked:r===n,onSelect:()=>{e.user.updateUserPreferences({locale:r}),t("change-language",{source:"menu",locale:r})}},r))})})}function Yee(){return h.jsxs(h.Fragment,{children:[h.jsx(uj,{}),h.jsx(Xee,{})]})}function Xee(){const{KeyboardShortcutsDialog:e}=Zs(),{addDialog:t}=Vi();return e?h.jsx(R,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{t({component:e})}}):null}const qee=x.memo(function({children:t}){const n=_e(),r=Ln(),o=t??h.jsx(Yee,{});return r<yt.MOBILE?null:h.jsx("div",{className:"tlui-help-menu",children:h.jsxs(Oi,{id:"help menu",children:[h.jsx(Di,{children:h.jsx(pe,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:h.jsx(Ie,{icon:"question-mark",small:!0})})}),h.jsx(Ri,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:h.jsx(vr,{type:"menu",sourceId:"help-menu",children:o})})]})})});function Zee(){const e=z(),t=le(),[n,r]=x.useState(!1);return x.useEffect(()=>{let o=!1;const s=setInterval(()=>{const i=e.getRenderingShapes(),a=e.getRenderingBounds(),c=i.filter(u=>{const d=e.getShapeMaskedPageBounds(u.id);return d&&a.includes(d)}).length===0&&e.getCurrentPageShapes().length>0;o!==c&&(r(c),o=c)},1e3);return()=>{clearInterval(s)}},[e]),n?h.jsx(R,{...t["back-to-content"],onSelect:()=>{t["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function Qee(){const e=z(),t=le();return K("is pen mode",()=>e.getInstanceState().isPenMode,[e])?h.jsx(R,{...t["exit-pen-mode"]}):null}function Jee(){const e=z(),t=le();return K("is following user",()=>!!e.getInstanceState().followingUserId,[e])?h.jsx(R,{...t["stop-following"]}):null}function ete(){return h.jsxs(h.Fragment,{children:[h.jsx(Qee,{}),h.jsx(Zee,{}),h.jsx(Jee,{})]})}function tte({children:e}){const t=e??h.jsx(ete,{});return h.jsx("div",{className:"tlui-helper-buttons",children:h.jsx(vr,{type:"helper-buttons",sourceId:"helper-buttons",children:t})})}function nte(){const e=le(),t=De();return h.jsxs(h.Fragment,{children:[h.jsxs(ye,{label:"shortcuts-dialog.tools",id:"tools",children:[h.jsx(R,{...e["toggle-tool-lock"]}),h.jsx(R,{...e["insert-media"]}),h.jsx(R,{...t.select}),h.jsx(R,{...t.draw}),h.jsx(R,{...t.eraser}),h.jsx(R,{...t.hand}),h.jsx(R,{...t.rectangle}),h.jsx(R,{...t.ellipse}),h.jsx(R,{...t.arrow}),h.jsx(R,{...t.line}),h.jsx(R,{...t.text}),h.jsx(R,{...t.frame}),h.jsx(R,{...t.note}),h.jsx(R,{...t.laser})]}),h.jsxs(ye,{label:"shortcuts-dialog.preferences",id:"preferences",children:[h.jsx(R,{...e["toggle-dark-mode"]}),h.jsx(R,{...e["toggle-focus-mode"]}),h.jsx(R,{...e["toggle-grid"]})]}),h.jsxs(ye,{label:"shortcuts-dialog.edit",id:"edit",children:[h.jsx(R,{...e.undo}),h.jsx(R,{...e.redo}),h.jsx(R,{...e.cut}),h.jsx(R,{...e.copy}),h.jsx(R,{...e.paste}),h.jsx(R,{...e["select-all"]}),h.jsx(R,{...e.delete}),h.jsx(R,{...e.duplicate})]}),h.jsxs(ye,{label:"shortcuts-dialog.view",id:"view",children:[h.jsx(R,{...e["zoom-in"]}),h.jsx(R,{...e["zoom-out"]}),h.jsx(R,{...e["zoom-to-100"]}),h.jsx(R,{...e["zoom-to-fit"]}),h.jsx(R,{...e["zoom-to-selection"]})]}),h.jsxs(ye,{label:"shortcuts-dialog.transform",id:"transform",children:[h.jsx(R,{...e["bring-to-front"]}),h.jsx(R,{...e["bring-forward"]}),h.jsx(R,{...e["send-backward"]}),h.jsx(R,{...e["send-to-back"]}),h.jsx(R,{...e.group}),h.jsx(R,{...e.ungroup}),h.jsx(R,{...e["flip-horizontal"]}),h.jsx(R,{...e["flip-vertical"]}),h.jsx(R,{...e["align-top"]}),h.jsx(R,{...e["align-center-vertical"]}),h.jsx(R,{...e["align-bottom"]}),h.jsx(R,{...e["align-left"]}),h.jsx(R,{...e["align-center-horizontal"]}),h.jsx(R,{...e["align-right"]})]})]})}const rte=x.memo(function({children:t}){const n=_e(),r=Ln(),o=t??h.jsx(nte,{});return h.jsxs(h.Fragment,{children:[h.jsxs(ng,{className:"tlui-shortcuts-dialog__header",children:[h.jsx(rg,{children:n("shortcuts-dialog.title")}),h.jsx(og,{})]}),h.jsx(uu,{className:ue("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=yt.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=yt.TABLET}),children:h.jsx(vr,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),h.jsx("div",{className:"tlui-dialog__scrim"})]})});function ote(){return h.jsxs(h.Fragment,{children:[h.jsx(ite,{}),h.jsx(ute,{}),h.jsx(ste,{}),h.jsx(dte,{}),h.jsx(hte,{})]})}function ste(){const e=le();return h.jsxs(wr,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[h.jsxs(ye,{id:"export-all-as-group",children:[h.jsx(R,{...e["export-all-as-svg"]}),h.jsx(R,{...e["export-all-as-png"]}),h.jsx(R,{...e["export-all-as-json"]})]}),h.jsx(ye,{id:"export-all-as-bg",children:h.jsx(cw,{})})]})}function ite(){const e=z(),t=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return h.jsxs(wr,{id:"edit",label:"menu.edit",disabled:!t,children:[h.jsx(cte,{}),h.jsx(oj,{}),h.jsx(sj,{}),h.jsx(ate,{}),h.jsx(lte,{}),h.jsx(ye,{id:"select-all",children:h.jsx(ij,{})})]})}function ate(){return h.jsxs(ye,{id:"misc",children:[h.jsx(qA,{}),h.jsx(ZA,{}),h.jsx(XA,{}),h.jsx(YA,{}),h.jsx(QA,{}),h.jsx(JA,{}),h.jsx(lj,{}),h.jsx(aj,{})]})}function lte(){return h.jsxs(ye,{id:"lock",children:[h.jsx(ej,{}),h.jsx(mee,{})]})}function cte(){const e=le(),t=K2(),n=H2();return h.jsxs(ye,{id:"undo-redo",children:[h.jsx(R,{...e.undo,disabled:!t}),h.jsx(R,{...e.redo,disabled:!n})]})}function ute(){const e=le();return h.jsx(wr,{id:"view",label:"menu.view",children:h.jsxs(ye,{id:"view-actions",children:[h.jsx(R,{...e["zoom-in"]}),h.jsx(R,{...e["zoom-out"]}),h.jsx(tj,{}),h.jsx(nj,{}),h.jsx(rj,{})]})})}function dte(){const e=le();return h.jsxs(ye,{id:"extras",children:[h.jsx(R,{...e["insert-embed"]}),h.jsx(R,{...e["insert-media"]})]})}function hte(){return h.jsx(ye,{id:"preferences",children:h.jsxs(wr,{id:"preferences",label:"menu.preferences",children:[h.jsxs(ye,{id:"preferences-actions",children:[h.jsx(_ee,{}),h.jsx(kee,{}),h.jsx(Tee,{}),h.jsx($ee,{}),h.jsx(Mee,{}),h.jsx(Aee,{}),h.jsx(jee,{}),h.jsx(Oee,{}),h.jsx(Dee,{})]}),h.jsx(ye,{id:"language",children:h.jsx(uj,{})})]})})}const pte=x.memo(function({children:t}){const n=ln(),[r,o]=Xs("main menu"),s=_e(),i=t??h.jsx(ote,{});return h.jsxs(iw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(aw,{asChild:!0,dir:"ltr",children:h.jsx(pe,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:h.jsx(Ie,{icon:"menu",small:!0})})}),h.jsx(hg,{container:n,children:h.jsx(lw,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:h.jsx(vr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),fte=x.memo(function(){const t=Ln(),{MainMenu:n,QuickActions:r,ActionsMenu:o,PageMenu:s}=Zs();return!n&&!s&&t<6?null:h.jsx("div",{className:"tlui-menu-zone",children:h.jsxs("div",{className:"tlui-buttons__horizontal",children:[n&&h.jsx(n,{}),s&&h.jsx(s,{}),t<6?null:h.jsxs(h.Fragment,{children:[r&&h.jsx(r,{}),o&&h.jsx(o,{})]})]})})});class af{constructor(t){m(this,"dpr",1);m(this,"colors",{shapeFill:"rgba(144, 144, 144, .1)",selectFill:"#2f80ed",viewportFill:"rgba(144, 144, 144, .1)"});m(this,"id",nt());m(this,"cvs",null);m(this,"pageBounds",[]);m(this,"collaborators",[]);m(this,"canvasScreenBounds",new te);m(this,"canvasPageBounds",new te);m(this,"contentPageBounds",new te);m(this,"contentScreenBounds",new te);m(this,"originPagePoint",new b);m(this,"originPageCenter",new b);m(this,"isInViewport",!1);m(this,"debug",!1);m(this,"updateContentScreenBounds",()=>{const{contentScreenBounds:t,contentPageBounds:n,canvasScreenBounds:r}=this;let{x:o,y:s,w:i,h:a}=t;if(n.w>n.h){const l=r.w/(n.w/n.h);l>r.h?(o=(r.w-r.w*(r.h/l))/2,s=0,i=r.w*(r.h/l),a=r.h):(o=0,s=(r.h-l)/2,i=r.w,a=l)}else if(n.w<n.h){const l=r.h/(n.h/n.w);o=(r.w-l)/2,s=0,i=l,a=r.h}else o=r.h/2,s=0,i=r.h,a=r.h;t.set(o,s,i,a)});m(this,"updateCanvasPageBounds",()=>{const{canvasPageBounds:t,canvasScreenBounds:n,contentPageBounds:r,contentScreenBounds:o}=this;t.set(0,0,r.width/(o.width/n.width),r.height/(o.height/n.height)),t.center=r.center});m(this,"getScreenPoint",(t,n)=>{const{canvasScreenBounds:r}=this,o=(t-r.minX)*this.dpr,s=(n-r.minY)*this.dpr;return{x:o,y:s}});m(this,"getPagePoint",(t,n)=>{const{contentPageBounds:r,contentScreenBounds:o,canvasPageBounds:s}=this,{x:i,y:a}=this.getScreenPoint(t,n);return new b(s.minX+i*r.width/o.width,s.minY+a*r.height/o.height,1)});m(this,"minimapScreenPointToPagePoint",(t,n,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getPagePoint(t,n);if(o){const c=this.editor.getCurrentPageBounds(),u=i,d=((c==null?void 0:c.minX)??0)-u.width/2,p=((c==null?void 0:c.maxX)??0)+u.width/2,f=((c==null?void 0:c.minY)??0)-u.height/2,y=((c==null?void 0:c.maxY)??0)+u.height/2,g=Math.max(0,d+u.width-a),w=Math.max(0,-(p-u.width-a)),S=Math.max(0,f+u.height-l),v=Math.max(0,-(y-u.height-l)),C=Math.max(0,g-w),I=Math.max(0,w-g),P=Math.max(0,S-v),E=Math.max(0,v-S);C&&C>I?a+=C/2:I&&(a-=I/2),P&&P>E?l+=P/2:E&&(l-=E/2),a=Zr(a,d,p),l=Zr(l,f,y)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),d=Math.abs(l-c.y);u>d?l=c.y:a=c.x}return new b(a,l)});m(this,"updateColors",()=>{const t=getComputedStyle(this.editor.getContainer());this.colors={shapeFill:t.getPropertyValue("--color-text-3").trim(),selectFill:t.getPropertyValue("--color-selected").trim(),viewportFill:t.getPropertyValue("--color-muted-1").trim()}});m(this,"render",()=>{const{cvs:t,pageBounds:n}=this;this.updateCanvasPageBounds();const{editor:r,canvasScreenBounds:o,canvasPageBounds:s,contentPageBounds:i,contentScreenBounds:a}=this,{width:l,height:c}=o,u=new Set(r.getSelectedShapeIds()),d=r.getViewportPageBounds();if(!t||!n)return;const p=t.getContext("2d");if(!p)throw new Error("Minimap (shapes): Could not get context");p.resetTransform(),p.globalAlpha=1,p.clearRect(0,0,l,c);const f=a.width/i.width,y=a.height/i.height;p.translate((l-a.width)/2,(c-a.height)/2),p.scale(f,y),p.translate(-i.minX,-i.minY);const g=new Path2D,w=new Path2D,{shapeFill:S,selectFill:v,viewportFill:C}=this.colors;let I;for(let $=0,T=n.length;$<T;$++)I=n[$],(u.has(I.id)?w:g).rect(I.minX,I.minY,I.width,I.height);if(p.fillStyle=S,p.fill(g),p.fillStyle=v,p.fill(w),this.debug){const $=te.Common(n),{minX:T,minY:j,width:L,height:N}=$;p.strokeStyle="green",p.lineWidth=2/f,p.strokeRect(T+1/f,j+1/y,L-2/f,N-2/y)}{const{brush:$}=r.getInstanceState();if($){const{x:T,y:j,w:L,h:N}=$;p.beginPath(),af.sharpRect(p,T,j,L,N),p.closePath(),p.fillStyle=C,p.fill()}}{const{minX:$,minY:T,width:j,height:L}=d;p.beginPath();const N=12/f,F=12/f;af.roundedRect(p,$,T,j,L,Math.min(j/4,N),Math.min(L/4,F)),p.closePath(),p.fillStyle=C,p.fill(),this.debug&&(p.strokeStyle="orange",p.strokeRect($+1/f,T+1/y,j-2/f,L-2/y))}const P=2.5/f,E=2.5/y,_=r.getCurrentPageId();let k;for(let $=0;$<this.collaborators.length;$++)k=this.collaborators[$],k.currentPageId===_&&(p.beginPath(),p.ellipse(Zr(k.cursor.x,s.minX+P,s.maxX-P),Zr(k.cursor.y,s.minY+E,s.maxY-E),5/f,5/y,0,0,Fe),p.fillStyle=k.color,p.fill());if(this.debug){p.lineWidth=2/f;{const{minX:$,minY:T,width:j,height:L}=i;p.strokeStyle="red",p.strokeRect($+1/f,T+1/y,j-2/f,L-2/y)}{const{minX:$,minY:T,width:j,height:L}=s;p.strokeStyle="blue",p.strokeRect($+1/f,T+1/y,j-2/f,L-2/y)}}});this.editor=t}setDpr(t){this.dpr=+t.toFixed(2)}static roundedRect(t,n,r,o,s,i,a){if(i<1&&a<1){t.rect(n,r,o,s);return}t.moveTo(n+i,r),t.lineTo(n+o-i,r),t.quadraticCurveTo(n+o,r,n+o,r+a),t.lineTo(n+o,r+s-a),t.quadraticCurveTo(n+o,r+s,n+o-i,r+s),t.lineTo(n+i,r+s),t.quadraticCurveTo(n,r+s,n,r+s-a),t.lineTo(n,r+a),t.quadraticCurveTo(n,r,n+i,r)}static sharpRect(t,n,r,o,s,i,a){t.rect(n,r,o,s)}}function gte(){const e=z(),t=x.useRef(null),n=x.useRef(!1),r=Mu(),o=MI("dpr",()=>e.getInstanceState().devicePixelRatio,[e]),s=x.useMemo(()=>e.store.query.records("instance_presence"),[e]),i=x.useMemo(()=>new af(e),[e]);x.useEffect(()=>{const d=requestAnimationFrame(()=>{i.updateColors(),i.render()});return()=>{cancelAnimationFrame(d)}},[e,i,r]);const a=x.useCallback(d=>{if(!e.getCurrentPageShapeIds().size)return;const p=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),f=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);i.originPagePoint.setTo(f),i.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(p,{duration:Yr})},[e,i]),l=x.useCallback(d=>{const p=d.currentTarget;if(pl(p,d),!e.getCurrentPageShapeIds().size)return;n.current=!0,i.isInViewport=!1;const f=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),y=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0),g=e.getViewportPageBounds();if(i.isInViewport=g.containsPoint(y),i.isInViewport)i.originPagePoint.setTo(y),i.originPageCenter.setTo(g.center);else{const S=b.Sub(g.center,g.point),v=b.Add(f,S);i.originPagePoint.setTo(v),i.originPageCenter.setTo(f),e.centerOnPoint(f,{duration:Yr})}function w(S){p&&Pu(p,S),n.current=!1,document.body.removeEventListener("pointerup",w)}document.body.addEventListener("pointerup",w)},[e,i]),c=x.useCallback(d=>{const p=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,d.shiftKey,!0);if(n.current){if(i.isInViewport){const w=i.originPagePoint.clone().sub(i.originPageCenter);e.centerOnPoint(b.Sub(p,w));return}e.centerOnPoint(p)}const f=i.getPagePoint(d.clientX,d.clientY),y=e.pageToScreen(f),g={type:"pointer",target:"canvas",name:"pointer_move",...En(d),point:y,isPen:e.getInstanceState().isPenMode};e.dispatch(g)},[e,i]),u=x.useCallback(d=>{const p=GE(d);e.dispatch({type:"wheel",name:"wheel",delta:p,point:new b(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey})},[e]);return Mo("update when dpr changes",()=>{const d=o.get();i.setDpr(d);const p=t.current,f=p.getBoundingClientRect(),y=f.width*d,g=f.height*d;p.width=y,p.height=g,i.canvasScreenBounds.set(f.x,f.y,y,g),i.cvs=t.current},[o,i]),Mo("minimap render when pagebounds or collaborators changes",()=>{const d=e.getCurrentPageShapeIds(),p=e.getCurrentPageBounds(),f=e.getViewportPageBounds();o.get(),i.contentPageBounds=p?te.Expand(p,f):f,i.updateContentScreenBounds();const y=[];d.forEach(g=>{let w=e.getShapePageBounds(g);if(!w)return;const S=e.getShapeMask(g);if(S){const v=DS(S,w.corners);if(!v)return;w=te.FromPoints(v)}w&&(w.id=g,y.push(w))}),i.pageBounds=y,i.collaborators=s.get(),i.render()},[e,i]),h.jsx("div",{className:"tlui-minimap",children:h.jsx("canvas",{role:"img","aria-label":"minimap",ref:t,className:"tlui-minimap__canvas",onDoubleClick:a,onPointerMove:c,onPointerDown:l,onWheel:u})})}function mte(e,t){const[n,r]=Se.useState(t);Se.useLayoutEffect(()=>{const s=Lv(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=Se.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return Fv(e,JSON.stringify(a)),a})},[e]);return[n,o]}const yte=x.memo(function(){const t=le(),n=_e(),r=Ln(),[o,s]=mte("minimap",!0),i=x.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=Zs();return r<yt.MOBILE?null:h.jsxs("div",{className:"tlui-navigation-panel",children:[h.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<yt.TABLET?h.jsx(a,{}):o?h.jsxs(h.Fragment,{children:[a&&h.jsx(a,{}),l&&h.jsx(pe,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(Ie,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):h.jsxs(h.Fragment,{children:[h.jsx(pe,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(du(t["zoom-out"].label))} ${Cv(t["zoom-out"].kbd)}`,onClick:()=>t["zoom-out"].onSelect("navigation-zone"),children:h.jsx(Ie,{icon:"minus"})}),a&&h.jsx(a,{}),h.jsx(pe,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(du(t["zoom-in"].label))} ${Cv(t["zoom-in"].kbd)}`,onClick:()=>t["zoom-in"].onSelect("navigation-zone"),children:h.jsx(Ie,{icon:"plus"})}),l&&h.jsx(pe,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:h.jsx(Ie,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=yt.TABLET&&!o&&h.jsx(l,{})]})}),Ste=function({name:t,id:n,isCurrentPage:r}){const o=z(),s=x.useRef(null),i=x.useCallback(l=>{o.renamePage(n,l||"New Page",{ephemeral:!0})},[o,n]),a=x.useCallback(l=>{o.mark("rename page"),o.renamePage(n,l||"New Page",{ephemeral:!1})},[o,n]);return h.jsx(Hx,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:t,onValueChange:i,onComplete:a,onCancel:a,shouldManuallyMaintainScrollPositionWhenFocused:!0,autofocus:r,autoselect:!0})},Ev=(e,t,n,r)=>{let o;const s=e.getPages(),i=n>r?s[r-1]:s[r],a=n>r?s[r]:s[r+1];i&&!a?o=Eo(i.index):!i&&a?o=TD(s[0].index):o=fc(i.index,a.index),o!==s[n].index&&(e.mark("moving page"),e.updatePage({id:t,index:o}))},sI=tr(function({index:t,listSize:n,item:r,onRename:o}){const s=z(),i=_e(),a=s.getPages(),l=x.useCallback(()=>{s.mark("creating page");const p=Lo.createId();s.duplicatePage(r.id,p)},[s,r]),c=x.useCallback(()=>{Ev(s,r.id,t,t-1)},[s,r,t]),u=x.useCallback(()=>{Ev(s,r.id,t,t+1)},[s,r,t]),d=x.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return h.jsxs(Oi,{id:`page item submenu ${t}`,children:[h.jsx(Di,{children:h.jsx(pe,{type:"icon",title:i("page-menu.submenu.title"),children:h.jsx(Ie,{icon:"dots-vertical"})})}),h.jsx(Ri,{alignOffset:0,side:"right",sideOffset:-4,children:h.jsxs(vr,{type:"menu",sourceId:"page-menu",children:[h.jsxs(ye,{id:"modify",children:[o&&h.jsx(R,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),h.jsx(R,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:a.length>=gp}),t>0&&h.jsx(R,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),t<n-1&&h.jsx(R,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),n>1&&h.jsx(ye,{id:"delete",children:h.jsx(R,{id:"delete",onSelect:d,label:"page-menu.submenu.delete"})})]})})]})}),vte=x.memo(function(){const t=z(),n=_e(),r=Ln(),o=x.useCallback(()=>w(!1),[]),[s,i]=Xs("page-menu",o),a=36,l=x.useRef(null),c=K("pages",()=>t.getPages(),[t]),u=K("currentPage",()=>t.getCurrentPage(),[t]),d=K("currentPageId",()=>t.getCurrentPageId(),[t]),p=es(),f=K("maxPageCountReached",()=>t.getPages().length>=gp,[t]),y=K("isCoarsePointer",()=>t.getInstanceState().isCoarsePointer,[t]),[g,w]=x.useState(!1),S=x.useCallback(()=>{p||w(T=>!T)},[p]),v=x.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[C,I]=x.useState(Object.fromEntries(c.map((T,j)=>[T.id,{y:j*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{I(Object.fromEntries(c.map((T,j)=>[T.id,{y:j*a,offsetY:0,isSelected:!1}])))},[a,c]),x.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const j=l.current;if(!j)return;const L=T.offsetTop,N=j.scrollTop;L<N&&j.scrollTo({top:L});const F=L+a,B=j.scrollTop+j.offsetHeight;F>B&&j.scrollTo({top:F-j.offsetHeight})}})},[a,d,s]);const P=x.useCallback(T=>{const{clientY:j,currentTarget:L}=T,{dataset:{id:N,index:F}}=L;if(!N||!F)return;const B=v.current;pl(T.currentTarget,T),B.status="pointing",B.pointing={id:N,index:+F};const Q=C[N].y;B.startY=j,B.startIndex=Math.max(0,Math.min(Math.round(Q/a),c.length-1))},[a,c.length,C]),E=x.useCallback(T=>{const j=v.current;if(j.status==="pointing"){const{clientY:L}=T,N=L-j.startY;Math.abs(N)>5&&(j.status="dragging")}if(j.status==="dragging"){const{clientY:L}=T,N=L-j.startY,F=C[j.pointing.id],{startIndex:B,pointing:q}=j,Q=F.y+N,V=Math.max(0,Math.min(Math.round(Q/a),c.length-1)),U={...C};if(U[q.id]={y:F.y,offsetY:N,isSelected:!0},V!==j.dragIndex){j.dragIndex=V;for(let H=0;H<c.length;H++){const Z=c[H];if(Z.id===j.pointing.id)continue;let{y:ce}=U[Z.id];V===B?ce=H*a:V<B?V<=H&&H<B?ce=(H+1)*a:ce=H*a:V>B&&(V>=H&&H>B?ce=(H-1)*a:ce=H*a),ce!==U[Z.id].y&&(U[Z.id]={y:ce,offsetY:0,isSelected:!0})}}I(U)}},[a,c,C]),_=x.useCallback(T=>{const j=v.current;if(j.status==="dragging"){const{id:L,index:N}=j.pointing;Ev(t,L,N,j.dragIndex)}Pu(T.currentTarget,T),j.status="idle"},[t]),k=x.useCallback(T=>{const j=v.current;T.key==="Escape"&&(j.status==="dragging"&&I(Object.fromEntries(c.map((L,N)=>[L.id,{y:N*a,offsetY:0,isSelected:!1}]))),j.status="idle")},[a,c]),$=x.useCallback(()=>{p||t.batch(()=>{t.mark("creating page");const T=Lo.createId();t.createPage({name:n("page-menu.new-page-initial-name"),id:T}),t.setCurrentPage(T),w(!0)})},[t,n,p]);return h.jsxs(Jx,{id:"pages",onOpenChange:i,open:s,children:[h.jsx(ew,{"data-testid":"main.page-menu",children:h.jsxs(pe,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[h.jsx("div",{className:"tlui-page-menu__name",children:u.name}),h.jsx(Ie,{icon:"chevron-down",small:!0})]})}),h.jsx(tw,{side:"bottom",align:"start",sideOffset:6,children:h.jsxs("div",{className:"tlui-page-menu__wrapper",children:[h.jsxs("div",{className:"tlui-page-menu__header",children:[h.jsx("div",{className:"tlui-page-menu__header__title",children:n("page-menu.title")}),!p&&h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsx(pe,{type:"icon","data-testid":"page-menu.edit",title:n(g?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:h.jsx(Ie,{icon:g?"check":"edit"})}),h.jsx(pe,{type:"icon","data-testid":"page-menu.create",title:n(f?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:f,onClick:$,children:h.jsx(Ie,{icon:"plus"})})]})]}),h.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((T,j)=>{const L=C[T.id]??{position:j*40,offsetY:0};return g?h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===u.id?888:j,transform:`translate(0px, ${L.y+L.offsetY}px)`},children:[h.jsx(pe,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:P,onPointerUp:_,onPointerMove:E,onKeyDown:k,"data-id":T.id,"data-index":j,children:h.jsx(Ie,{icon:"drag-handle-dots"})}),r<yt.TABLET_SM&&y?h.jsxs(pe,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const N=window.prompt("Rename page",T.name);N&&N!==T.name&&t.renamePage(T.id,N)},onDoubleClick:S,children:[h.jsx(Iv,{checked:T.id===u.id}),h.jsx(xt,{children:T.name})]}):h.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:h.jsx(Ste,{id:T.id,name:T.name,isCurrentPage:T.id===u.id})}),!p&&h.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":g,children:h.jsx(sI,{index:j,item:T,listSize:c.length})})]},T.id+"_editing"):h.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[h.jsxs(pe,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>t.setCurrentPage(T.id),onDoubleClick:S,title:n("page-menu.go-to-page"),children:[h.jsx(Iv,{checked:T.id===u.id}),h.jsx(xt,{children:T.name})]}),!p&&h.jsx("div",{className:"tlui-page_menu__item__submenu",children:h.jsx(sI,{index:j,item:T,listSize:c.length,onRename:()=>{if(t.environment.isIos){const N=window.prompt("Rename page",T.name);N&&N!==T.name&&t.renamePage(T.id,N)}else t.batch(()=>{w(!0),t.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function xte(){const e=le(),t=z(),n=K2(),r=H2(),o=vn(1),s=es(),i=K("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]);if(!(s&&!i))return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e.undo,disabled:!n}),h.jsx(R,{...e.redo,disabled:!r}),h.jsx(R,{...e.delete,disabled:!o}),h.jsx(R,{...e.duplicate,disabled:!o})]})}const wte=x.memo(function({children:t}){const n=t??h.jsx(xte,{});return h.jsx(vr,{type:"small-icons",sourceId:"quick-actions",children:n})}),bte=Object.freeze([Jn,wi,Ga,io]);function dj(e=bte){const t=z();return K("getRelevantStyles",()=>{var s;const n=new RS(t.getSharedStyles()),r=!!((s=t.root.getCurrent())!=null&&s.shapeType),o=t.isIn("select")&&t.getSelectedShapeIds().length>0;if(n.size===0&&t.isIn("select")&&t.getSelectedShapeIds().length===0)for(const i of e)n.applyValue(i,t.getStyleForNextShape(i));return r||o||n.size>0?n:null},[t])}const jr={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],horizontalAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-center"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"cloud",icon:"geo-cloud"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"star",icon:"geo-star"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]};function Pte(e){const{uiType:t,items:n,title:r,style:o,value:s,onValueChange:i,theme:a}=e,l=z(),c=_e(),u=x.useRef(!1),{handleButtonClick:d,handleButtonPointerDown:p,handleButtonPointerEnter:f,handleButtonPointerUp:y}=x.useMemo(()=>{const g=()=>{u.current=!1,window.removeEventListener("pointerup",g)};return{handleButtonClick:I=>{const{id:P}=I.currentTarget.dataset;s.type==="shared"&&s.value===P||(l.mark("point picker item"),i(o,P,!1))},handleButtonPointerDown:I=>{const{id:P}=I.currentTarget.dataset;l.mark("point picker item"),i(o,P,!0),u.current=!0,window.addEventListener("pointerup",g)},handleButtonPointerEnter:I=>{if(!u.current)return;const{id:P}=I.currentTarget.dataset;i(o,P,!0)},handleButtonPointerUp:I=>{const{id:P}=I.currentTarget.dataset;s.type==="shared"&&s.value===P||i(o,P,!1)}}},[s,l,i,o]);return h.jsx("div",{"data-testid":`style.${t}`,className:ue("tlui-buttons__grid"),children:n.map(g=>h.jsx(pe,{type:"icon","data-id":g.value,"data-testid":`style.${t}.${g.value}`,"aria-label":g.value,"data-state":s.type==="shared"&&s.value===g.value?"hinted":void 0,title:r+" — "+c(`${t}-style.${g.value}`),className:ue("tlui-button-grid__button"),style:o===Jn?{color:a[g.value].solid}:void 0,onPointerEnter:f,onPointerDown:p,onPointerUp:y,onClick:d,children:h.jsx(Ie,{icon:g.icon})},g.value))})}const Ma=x.memo(Pte);function hj(e,[t,n]){return Math.min(n,Math.max(t,e))}function Cte(e){const t=x.useRef({value:e,previous:e});return x.useMemo(()=>(t.current.value!==e&&(t.current.previous=t.current.value,t.current.value=e),t.current.previous),[e])}const pj=["PageUp","PageDown"],fj=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],gj={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Nu="Slider",[_v,Ite,Ete]=qf(Nu),[mj,qre]=ho(Nu,[Ete]),[_te,pg]=mj(Nu),kte=x.forwardRef((e,t)=>{const{name:n,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:d=()=>{},onValueCommit:p=()=>{},inverted:f=!1,...y}=e,[g,w]=x.useState(null),S=Xe(t,F=>w(F)),v=x.useRef(new Set),C=x.useRef(0),I=i==="horizontal",P=g?!!g.closest("form"):!0,E=I?Tte:$te,[_=[],k]=Ys({prop:u,defaultProp:c,onChange:F=>{var B;(B=[...v.current][C.current])===null||B===void 0||B.focus(),d(F)}}),$=x.useRef(_);function T(F){const B=Nte(_,F);N(F,B)}function j(F){N(F,C.current)}function L(){const F=$.current[C.current];_[C.current]!==F&&p(_)}function N(F,B,{commit:q}={commit:!1}){const Q=Hte(s),V=Kte(Math.round((F-r)/s)*s+r,Q),U=hj(V,[r,o]);k((H=[])=>{const Z=Lte(H,U,B);if(Ute(Z,l*s)){C.current=Z.indexOf(U);const ce=String(Z)!==String(H);return ce&&q&&p(Z),ce?Z:H}else return H})}return x.createElement(_te,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:C,thumbs:v.current,values:_,orientation:i},x.createElement(_v.Provider,{scope:e.__scopeSlider},x.createElement(_v.Slot,{scope:e.__scopeSlider},x.createElement(E,X({"aria-disabled":a,"data-disabled":a?"":void 0},y,{ref:S,onPointerDown:se(y.onPointerDown,()=>{a||($.current=_)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:T,onSlideMove:a?void 0:j,onSlideEnd:a?void 0:L,onHomeKeyDown:()=>!a&&N(r,0,{commit:!0}),onEndKeyDown:()=>!a&&N(o,_.length-1,{commit:!0}),onStepKeyDown:({event:F,direction:B})=>{if(!a){const V=pj.includes(F.key)||F.shiftKey&&fj.includes(F.key)?10:1,U=C.current,H=_[U],Z=s*V*B;N(H+Z,U,{commit:!0})}}})))),P&&_.map((F,B)=>x.createElement(Rte,{key:B,name:n?n+(_.length>1?"[]":""):void 0,value:F})))}),[yj,Sj]=mj(Nu,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Tte=x.forwardRef((e,t)=>{const{min:n,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[d,p]=x.useState(null),f=Xe(t,C=>p(C)),y=x.useRef(),g=nw(o),w=g==="ltr",S=w&&!s||!w&&s;function v(C){const I=y.current||d.getBoundingClientRect(),P=[0,I.width],_=uw(P,S?[n,r]:[r,n]);return y.current=I,_(C-I.left)}return x.createElement(yj,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width"},x.createElement(vj,X({dir:g,"data-orientation":"horizontal"},u,{ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:C=>{const I=v(C.clientX);i==null||i(I)},onSlideMove:C=>{const I=v(C.clientX);a==null||a(I)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:C=>{const P=gj[S?"from-left":"from-right"].includes(C.key);c==null||c({event:C,direction:P?-1:1})}})))}),$te=x.forwardRef((e,t)=>{const{min:n,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=x.useRef(null),d=Xe(t,u),p=x.useRef(),f=!o;function y(g){const w=p.current||u.current.getBoundingClientRect(),S=[0,w.height],C=uw(S,f?[r,n]:[n,r]);return p.current=w,C(g-w.top)}return x.createElement(yj,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1},x.createElement(vj,X({"data-orientation":"vertical"},c,{ref:d,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const w=y(g.clientY);s==null||s(w)},onSlideMove:g=>{const w=y(g.clientY);i==null||i(w)},onSlideEnd:()=>{p.current=void 0,a==null||a()},onStepKeyDown:g=>{const S=gj[f?"from-bottom":"from-top"].includes(g.key);l==null||l({event:g,direction:S?-1:1})}})))}),vj=x.forwardRef((e,t)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=pg(Nu,n);return x.createElement(Ke.span,X({},c,{ref:t,onKeyDown:se(e.onKeyDown,d=>{d.key==="Home"?(i(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):pj.concat(fj).includes(d.key)&&(l(d),d.preventDefault())}),onPointerDown:se(e.onPointerDown,d=>{const p=d.target;p.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(p)?p.focus():r(d)}),onPointerMove:se(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:se(e.onPointerUp,d=>{const p=d.target;p.hasPointerCapture(d.pointerId)&&(p.releasePointerCapture(d.pointerId),s(d))})}))}),Mte="SliderTrack",Ate=x.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=pg(Mte,n);return x.createElement(Ke.span,X({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:t}))}),iI="SliderRange",jte=x.forwardRef((e,t)=>{const{__scopeSlider:n,...r}=e,o=pg(iI,n),s=Sj(iI,n),i=x.useRef(null),a=Xe(t,i),l=o.values.length,c=o.values.map(p=>xj(p,o.min,o.max)),u=l>1?Math.min(...c):0,d=100-Math.max(...c);return x.createElement(Ke.span,X({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:d+"%"}}))}),aI="SliderThumb",Ote=x.forwardRef((e,t)=>{const n=Ite(e.__scopeSlider),[r,o]=x.useState(null),s=Xe(t,a=>o(a)),i=x.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return x.createElement(Dte,X({},e,{ref:s,index:i}))}),Dte=x.forwardRef((e,t)=>{const{__scopeSlider:n,index:r,...o}=e,s=pg(aI,n),i=Sj(aI,n),[a,l]=x.useState(null),c=Xe(t,w=>l(w)),u=rA(a),d=s.values[r],p=d===void 0?0:xj(d,s.min,s.max),f=Fte(r,s.values.length),y=u==null?void 0:u[i.size],g=y?zte(y,p,i.direction):0;return x.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${p}% + ${g}px)`}},x.createElement(_v.ItemSlot,{scope:e.__scopeSlider},x.createElement(Ke.span,X({role:"slider","aria-label":e["aria-label"]||f,"aria-valuemin":s.min,"aria-valuenow":d,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:c,style:d===void 0?{display:"none"}:e.style,onFocus:se(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),Rte=e=>{const{value:t,...n}=e,r=x.useRef(null),o=Cte(t);return x.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==t&&l){const c=new Event("input",{bubbles:!0});l.call(s,t),s.dispatchEvent(c)}},[o,t]),x.createElement("input",X({style:{display:"none"}},n,{ref:r,defaultValue:t}))};function Lte(e=[],t,n){const r=[...e];return r[n]=t,r.sort((o,s)=>o-s)}function xj(e,t,n){const s=100/(n-t)*(e-t);return hj(s,[0,100])}function Fte(e,t){return t>2?`Value ${e+1} of ${t}`:t===2?["Minimum","Maximum"][e]:void 0}function Nte(e,t){if(e.length===1)return 0;const n=e.map(o=>Math.abs(o-t)),r=Math.min(...n);return n.indexOf(r)}function zte(e,t,n){const r=e/2,s=uw([0,50],[0,r]);return(r-s(t)*n)*n}function Bte(e){return e.slice(0,-1).map((t,n)=>e[n+1]-t)}function Ute(e,t){if(t>0){const n=Bte(e);return Math.min(...n)>=t}return!0}function uw(e,t){return n=>{if(e[0]===e[1]||t[0]===t[1])return t[0];const r=(t[1]-t[0])/(e[1]-e[0]);return t[0]+r*(n-e[0])}}function Hte(e){return(String(e).split(".")[1]||"").length}function Kte(e,t){const n=Math.pow(10,t);return Math.round(e*n)/n}const Vte=kte,Wte=Ate,Gte=jte,Yte=Ote,Xte=x.memo(function(t){const{title:n,steps:r,value:o,label:s,onValueChange:i}=t,a=z(),l=_e(),c=x.useCallback(p=>{i(p[0],!0)},[i]),u=x.useCallback(()=>{a.mark("click slider")},[a]),d=x.useCallback(()=>{o&&i(o,!1)},[o,i]);return h.jsx("div",{className:"tlui-slider__container",children:h.jsxs(Vte,{"data-testid":t["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:d,title:n+" — "+l(s),children:[h.jsx(Wte,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&h.jsx(Gte,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&h.jsx(Yte,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function qte({label:e,uiTypeA:t,uiTypeB:n,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:d}){const p=_e(),f=x.useMemo(()=>{var g;return((g=s.find(w=>c.type==="shared"&&c.value===w.value))==null?void 0:g.icon)??"mixed"},[s,c]),y=x.useMemo(()=>{var g;return((g=i.find(w=>u.type==="shared"&&u.value===w.value))==null?void 0:g.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:h.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[h.jsx("div",{title:p(e),className:"tlui-style-panel__double-select-picker-label",children:p(e)}),h.jsxs("div",{className:"tlui-buttons__horizontal",children:[h.jsxs(Oi,{id:`style panel ${t} A`,children:[h.jsx(Di,{children:h.jsx(pe,{type:"icon","data-testid":`style.${t}`,title:p(r)+" — "+(c===null||c.type==="mixed"?p("style-panel.mixed"):p(`${t}-style.${c.value}`)),children:h.jsx(Ie,{icon:f,small:!0,invertIcon:!0})})}),h.jsx(Ri,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:h.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,w)=>h.jsx(yu,{"data-testid":`style.${t}.${g.value}`,children:h.jsx(pe,{type:"icon",onClick:()=>d(a,g.value,!1),title:`${p(r)} — ${p(`${t}-style.${g.value}`)}`,children:h.jsx(Ie,{icon:g.icon,invertIcon:!0})},g.value)},w))})})]}),h.jsxs(Oi,{id:`style panel ${n}`,children:[h.jsx(Di,{children:h.jsx(pe,{type:"icon","data-testid":`style.${n}`,title:p(o)+" — "+(u===null||u.type==="mixed"?p("style-panel.mixed"):p(`${n}-style.${u.value}`)),children:h.jsx(Ie,{icon:y,small:!0})})}),h.jsx(Ri,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:h.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>h.jsx(yu,{children:h.jsx(pe,{type:"icon",title:`${p(o)} — ${p(`${n}-style.${g.value}`)}`,"data-testid":`style.${n}.${g.value}`,onClick:()=>d(l,g.value,!1),children:h.jsx(Ie,{icon:g.icon})})},g.value))})})]})]})]})}const Zte=x.memo(qte);function Qte({id:e,label:t,uiType:n,style:r,items:o,type:s,value:i,onValueChange:a}){const l=_e(),c=z(),u=x.useMemo(()=>{var f;return(f=o.find(y=>i.type==="shared"&&y.value===i.value))==null?void 0:f.icon},[o,i]),d=i.type==="mixed"?l("style-panel.mixed"):l(`${n}-style.${i.value}`),p=t?l(t):"";return h.jsxs(Oi,{id:`style panel ${e}`,children:[h.jsx(Di,{children:h.jsxs(pe,{type:s,"data-testid":`style.${n}`,title:d,children:[h.jsx(xt,{children:p}),h.jsx(Ie,{icon:u??"mixed"})]})}),h.jsx(Ri,{side:"left",align:"center",alignOffset:0,children:h.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>h.jsx(yu,{children:h.jsx(pe,{type:"icon","data-testid":`style.${n}.${f.value}`,title:l(`${n}-style.${f.value}`),onClick:()=>{c.mark("select style dropdown item"),a(r,f.value,!1)},children:h.jsx(Ie,{icon:f.icon})})},f.value))})})]})}const dw=x.memo(Qte);function Jte({styles:e}){const t=Mu();if(!e)return null;const n=e.get(eo),r=e.get(cp),o=e.get(lp),s=e.get(dp),i=e.get(so),a=n===void 0,l=r===void 0&&o===void 0,c=s===void 0,u=i===void 0,d=qo({isDarkMode:t});return h.jsxs(h.Fragment,{children:[h.jsx(ene,{theme:d,styles:e}),!u&&h.jsx(tne,{theme:d,styles:e}),!(a&&l&&c)&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[h.jsx(nne,{styles:e}),h.jsx(one,{styles:e}),h.jsx(rne,{styles:e})]})]})}function zu(){const e=z(),t=fo();return Se.useMemo(()=>function(r,o,s){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,o,{squashing:s}),e.setStyleForNextShapes(r,o,{squashing:s}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),t("set-style",{source:"style-panel",id:r.id,value:o})},[e,t])}function ene({styles:e,theme:t}){const n=_e(),r=z(),o=zu(),s=e.get(Jn),i=e.get(Ga),a=e.get(wi),l=e.get(io),c=i!==void 0||a!==void 0||l!==void 0;return h.jsxs(h.Fragment,{children:[h.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[s===void 0?null:h.jsx(Ma,{title:n("style-panel.color"),uiType:"color",style:Jn,items:jr.color,value:s,onValueChange:o,theme:t}),h.jsx(sne,{})]}),c&&h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[i===void 0?null:h.jsx(Ma,{title:n("style-panel.fill"),uiType:"fill",style:Ga,items:jr.fill,value:i,onValueChange:o,theme:t}),a===void 0?null:h.jsx(Ma,{title:n("style-panel.dash"),uiType:"dash",style:wi,items:jr.dash,value:a,onValueChange:o,theme:t}),l===void 0?null:h.jsx(Ma,{title:n("style-panel.size"),uiType:"size",style:io,items:jr.size,value:l,onValueChange:(u,d,p)=>{o(u,d,p);const f=r.getSelectedShapeIds();f.length>0&&Ve(r,f)},theme:t})]})]})}function tne({theme:e,styles:t}){const n=_e(),r=zu(),o=t.get(so),s=t.get(Dc),i=t.get(up);return o===void 0&&s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[o===void 0?null:h.jsx(Ma,{title:n("style-panel.font"),uiType:"font",style:so,items:jr.font,value:o,onValueChange:r,theme:e}),s===void 0?null:h.jsxs("div",{className:"tlui-style-panel__row",children:[h.jsx(Ma,{title:n("style-panel.align"),uiType:"align",style:Dc,items:jr.horizontalAlign,value:s,onValueChange:r,theme:e}),h.jsx("div",{className:"tlui-style-panel__row__extra-button",children:i===void 0?h.jsx(pe,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:h.jsx(Ie,{icon:"vertical-align-center"})}):h.jsx(dw,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:up,items:jr.verticalAlign,value:i,onValueChange:r})})]})]})}function nne({styles:e}){const t=zu(),n=e.get(eo);return n===void 0?null:h.jsx(dw,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:eo,items:jr.geo,value:n,onValueChange:t})}function rne({styles:e}){const t=zu(),n=e.get(dp);return n===void 0?null:h.jsx(dw,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:dp,items:jr.spline,value:n,onValueChange:t})}function one({styles:e}){const t=zu(),n=e.get(cp),r=e.get(lp);return!n||!r?null:h.jsx(Zte,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:lp,itemsA:jr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:cp,itemsB:jr.arrowheadEnd,valueB:n,onValueChange:t,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const tc=[.1,.25,.5,.75,1];function sne(){const e=z(),t=K("opacity",()=>e.getSharedOpacity(),[e]),n=fo(),r=_e(),o=Se.useCallback((i,a)=>{const l=tc[i];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(l,{squashing:a}),e.setOpacityForNextShapes(l,{squashing:a}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),n("set-style",{source:"style-panel",id:"opacity",value:i})},[e,n]);if(t===void 0)return null;const s=t.type==="mixed"?-1:tc.indexOf(wD(tc,i=>Math.abs(i-t.value)));return h.jsx(Xte,{"data-testid":"style.opacity",value:s>=0?s:tc.length-1,label:t.type==="mixed"?"style-panel.mixed":`opacity-style.${t.value}`,onValueChange:o,steps:tc.length-1,title:r("style-panel.opacity")})}const ine=x.memo(function({isMobile:t,children:n}){const r=z(),o=dj(),s=x.useCallback(()=>{t||r.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[r,t]),i=n??h.jsx(Jte,{styles:o});return h.jsx("div",{className:ue("tlui-style-panel",{"tlui-style-panel__wrapper":!t}),"data-ismobile":t,onPointerLeave:s,children:i})});function ane(){const e=z(),t=_e(),n=dj(),r=n==null?void 0:n.get(Jn),o=qo({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=K("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(c=>{c||e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[e]),{StylePanel:l}=Zs();return l?h.jsxs(Jx,{id:"mobile style menu",onOpenChange:a,children:[h.jsx(ew,{children:h.jsx(pe,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:t("style-panel.title"),disabled:i,children:h.jsx(Ie,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),h.jsx(tw,{side:"top",align:"end",children:l&&h.jsx(l,{isMobile:!0})})]}):null}function lne(){return h.jsxs(h.Fragment,{children:[h.jsx(cne,{}),h.jsx(une,{}),h.jsx(dne,{}),h.jsx(hne,{}),h.jsx(pne,{}),h.jsx(fne,{}),h.jsx(gne,{}),h.jsx(mne,{}),h.jsx(yne,{}),h.jsx(Sne,{}),h.jsx(vne,{}),h.jsx(xne,{}),h.jsx(wne,{}),h.jsx(bne,{}),h.jsx(Pne,{}),h.jsx(Cne,{}),h.jsx(Ine,{}),h.jsx(Ene,{}),h.jsx(_ne,{}),h.jsx(kne,{}),h.jsx(Tne,{}),h.jsx($ne,{}),h.jsx(Mne,{}),h.jsx(Ane,{}),h.jsx(jne,{}),h.jsx(One,{}),h.jsx(Dne,{}),h.jsx(Rne,{})]})}function Ue(e){var r;const t=z(),n=(r=e.meta)==null?void 0:r.geo;return K("is tool selected",()=>{const o=t.getCurrentToolId(),s=t.getSharedStyles().getAsKnownValue(eo);return n?o==="geo"&&s===n:o===e.id},[t,e.id,n])}function cne(){const e=De(),t=Ue(e.select);return h.jsx(R,{...e.select,isSelected:t})}function une(){const e=De(),t=Ue(e.hand);return h.jsx(R,{...e.hand,isSelected:t})}function dne(){const e=De(),t=Ue(e.draw);return h.jsx(R,{...e.draw,isSelected:t})}function hne(){const e=De(),t=Ue(e.eraser);return h.jsx(R,{...e.eraser,isSelected:t})}function pne(){const e=De(),t=Ue(e.arrow);return h.jsx(R,{...e.arrow,isSelected:t})}function fne(){const e=De(),t=Ue(e.text);return h.jsx(R,{...e.text,isSelected:t})}function gne(){const e=De(),t=Ue(e.note);return h.jsx(R,{...e.note,isSelected:t})}function mne(){const e=De(),t=Ue(e.asset);return h.jsx(R,{...e.asset,isSelected:t})}function yne(){const e=De(),t=Ue(e.rectangle);return h.jsx(R,{...e.rectangle,isSelected:t})}function Sne(){const e=De(),t=Ue(e.ellipse);return h.jsx(R,{...e.ellipse,isSelected:t})}function vne(){const e=De(),t=Ue(e.diamond);return h.jsx(R,{...e.diamond,isSelected:t})}function xne(){const e=De(),t=Ue(e.triangle);return h.jsx(R,{...e.triangle,isSelected:t})}function wne(){const e=De(),t=Ue(e.trapezoid);return h.jsx(R,{...e.trapezoid,isSelected:t})}function bne(){const e=De(),t=Ue(e.rhombus);return h.jsx(R,{...e.rhombus,isSelected:t})}function Pne(){const e=De(),t=Ue(e.hexagon);return h.jsx(R,{...e.hexagon,isSelected:t})}function Cne(){const e=De(),t=Ue(e.cloud);return h.jsx(R,{...e.cloud,isSelected:t})}function Ine(){const e=De(),t=Ue(e.star);return h.jsx(R,{...e.star,isSelected:t})}function Ene(){const e=De(),t=Ue(e.oval);return h.jsx(R,{...e.oval,isSelected:t})}function _ne(){const e=De(),t=Ue(e["x-box"]);return h.jsx(R,{...e["x-box"],isSelected:t})}function kne(){const e=De(),t=Ue(e["check-box"]);return h.jsx(R,{...e["check-box"],isSelected:t})}function Tne(){const e=De(),t=Ue(e["arrow-left"]);return h.jsx(R,{...e["arrow-left"],isSelected:t})}function $ne(){const e=De(),t=Ue(e["arrow-up"]);return h.jsx(R,{...e["arrow-up"],isSelected:t})}function Mne(){const e=De(),t=Ue(e["arrow-down"]);return h.jsx(R,{...e["arrow-down"],isSelected:t})}function Ane(){const e=De(),t=Ue(e["arrow-right"]);return h.jsx(R,{...e["arrow-right"],isSelected:t})}function jne(){const e=De(),t=Ue(e.line);return h.jsx(R,{...e.line,isSelected:t})}function One(){const e=De(),t=Ue(e.highlight);return h.jsx(R,{...e.highlight,isSelected:t})}function Dne(){const e=De(),t=Ue(e.frame);return h.jsx(R,{...e.frame,isSelected:t})}function Rne(){const e=De(),t=Ue(e.laser);return h.jsx(R,{...e.laser,isSelected:t})}const ry=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function oy(e,t,n,r){e.addEventListener?e.addEventListener(t,n,r):e.attachEvent&&e.attachEvent("on".concat(t),n)}function nc(e,t,n,r){e.removeEventListener?e.removeEventListener(t,n,r):e.detachEvent&&e.detachEvent("on".concat(t),n)}function wj(e,t){const n=t.slice(0,t.length-1);for(let r=0;r<n.length;r++)n[r]=e[n[r].toLowerCase()];return n}function bj(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function Lne(e,t){const n=e.length>=t.length?e:t,r=e.length>=t.length?t:e;let o=!0;for(let s=0;s<n.length;s++)r.indexOf(n[s])===-1&&(o=!1);return o}const Su={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,"-":ry?173:189,"=":ry?61:187,";":ry?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},kv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Rt={16:!1,18:!1,17:!1,91:!1},ut={};for(let e=1;e<20;e++)Su["f".concat(e)]=111+e;let We=[],Mc=null,Pj="all";const Io=new Map,Bu=e=>Su[e.toLowerCase()]||co[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),Fne=e=>Object.keys(Su).find(t=>Su[t]===e),Nne=e=>Object.keys(co).find(t=>co[t]===e);function Cj(e){Pj=e||"all"}function vu(){return Pj||"all"}function zne(){return We.slice(0)}function Bne(){return We.map(e=>Fne(e)||Nne(e)||String.fromCharCode(e))}function Une(){const e=[];return Object.keys(ut).forEach(t=>{ut[t].forEach(n=>{let{key:r,scope:o,mods:s,shortcut:i}=n;e.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>Bu(a))})})}),e}function Hne(e){const t=e.target||e.srcElement,{tagName:n}=t;let r=!0;const o=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(t.type);return(t.isContentEditable||(o||n==="TEXTAREA"||n==="SELECT")&&!t.readOnly)&&(r=!1),r}function Kne(e){return typeof e=="string"&&(e=Bu(e)),We.indexOf(e)!==-1}function Vne(e,t){let n,r;e||(e=vu());for(const o in ut)if(Object.prototype.hasOwnProperty.call(ut,o))for(n=ut[o],r=0;r<n.length;)n[r].scope===e?n.splice(r,1).forEach(i=>{let{element:a}=i;return hw(a)}):r++;vu()===e&&Cj(t||"all")}function Wne(e){let t=e.keyCode||e.which||e.charCode;const n=We.indexOf(t);if(n>=0&&We.splice(n,1),e.key&&e.key.toLowerCase()==="meta"&&We.splice(0,We.length),(t===93||t===224)&&(t=91),t in Rt){Rt[t]=!1;for(const r in co)co[r]===t&&(kn[r]=!1)}}function Ij(e){if(typeof e>"u")Object.keys(ut).forEach(o=>{Array.isArray(ut[o])&&ut[o].forEach(s=>Zd(s)),delete ut[o]}),hw(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Zd(o)});else if(typeof e=="object")e.key&&Zd(e);else if(typeof e=="string"){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];let[o,s]=n;typeof o=="function"&&(s=o,o=""),Zd({key:e,scope:o,method:s,splitKey:"+"})}}const Zd=e=>{let{key:t,scope:n,method:r,splitKey:o="+"}=e;bj(t).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Bu(c);if(!ut[u])return;n||(n=vu());const d=l>1?wj(co,a):[],p=[];ut[u]=ut[u].filter(f=>{const g=(r?f.method===r:!0)&&f.scope===n&&Lne(f.mods,d);return g&&p.push(f.element),!g}),p.forEach(f=>hw(f))})};function lI(e,t,n,r){if(t.element!==r)return;let o;if(t.scope===n||t.scope==="all"){o=t.mods.length>0;for(const s in Rt)Object.prototype.hasOwnProperty.call(Rt,s)&&(!Rt[s]&&t.mods.indexOf(+s)>-1||Rt[s]&&t.mods.indexOf(+s)===-1)&&(o=!1);(t.mods.length===0&&!Rt[16]&&!Rt[18]&&!Rt[17]&&!Rt[91]||o||t.shortcut==="*")&&(t.keys=[],t.keys=t.keys.concat(We),t.method(e,t)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function cI(e,t){const n=ut["*"];let r=e.keyCode||e.which||e.charCode;if(!kn.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=kv[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 Rt){Rt[r]=!0;for(const a in co)co[a]===r&&(kn[a]=!0);if(!n)return}for(const a in Rt)Object.prototype.hasOwnProperty.call(Rt,a)&&(Rt[a]=e[kv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(We.indexOf(17)===-1&&We.push(17),We.indexOf(18)===-1&&We.push(18),Rt[17]=!0,Rt[18]=!0);const o=vu();if(n)for(let a=0;a<n.length;a++)n[a].scope===o&&(e.type==="keydown"&&n[a].keydown||e.type==="keyup"&&n[a].keyup)&&lI(e,n[a],o,t);if(!(r in ut))return;const s=ut[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,u=l.key.split(c),d=[];for(let p=0;p<u.length;p++)d.push(Bu(u[p]));d.sort().join("")===We.sort().join("")&&lI(e,l,o,t)}}function kn(e,t,n){We=[];const r=bj(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",d=!1,p=!1;for(n===void 0&&typeof t=="function"&&(n=t),Object.prototype.toString.call(t)==="[object Object]"&&(t.scope&&(s=t.scope),t.element&&(i=t.element),t.keyup&&(l=t.keyup),t.keydown!==void 0&&(c=t.keydown),t.capture!==void 0&&(d=t.capture),typeof t.splitKey=="string"&&(u=t.splitKey),t.single===!0&&(p=!0)),typeof t=="string"&&(s=t),p&&Ij(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=wj(co,e)),e=e[e.length-1],e=e==="*"?"*":Bu(e),e in ut||(ut[e]=[]),ut[e].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!Io.has(i)){const f=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return cI(g,i)},y=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;cI(g,i),Wne(g)};Io.set(i,{keydownListener:f,keyupListenr:y,capture:d}),oy(i,"keydown",f,d),oy(i,"keyup",y,d)}if(!Mc){const f=()=>{We=[]};Mc={listener:f,capture:d},oy(window,"focus",f,d)}}}function Gne(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ut).forEach(n=>{ut[n].filter(o=>o.scope===t&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function hw(e){const t=Object.values(ut).flat();if(t.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=Io.get(e)||{};r&&o&&(nc(e,"keyup",o,s),nc(e,"keydown",r,s),Io.delete(e))}if((t.length<=0||Io.size<=0)&&(Object.keys(Io).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=Io.get(o)||{};s&&i&&(nc(o,"keyup",i,a),nc(o,"keydown",s,a),Io.delete(o))}),Io.clear(),Object.keys(ut).forEach(o=>delete ut[o]),Mc)){const{listener:o,capture:s}=Mc;nc(window,"focus",o,s),Mc=null}}const sy={getPressedKeyString:Bne,setScope:Cj,getScope:vu,deleteScope:Vne,getPressedKeyCodes:zne,getAllKeyCodes:Une,isPressed:Kne,filter:Hne,trigger:Gne,unbind:Ij,keyMap:Su,modifier:co,modifierMap:kv};for(const e in sy)Object.prototype.hasOwnProperty.call(sy,e)&&(kn[e]=sy[e]);if(typeof window<"u"){const e=window.hotkeys;kn.noConflict=t=>(t&&window.hotkeys===kn&&(window.hotkeys=e),kn),window.hotkeys=kn}const uI=["copy","cut","paste","asset"];function Yne(){const e=z(),t=es(),n=le(),r=De(),o=K("is focused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!o)return;const s=e.getContainer();kn.setScope(e.store.id);const i=(l,c)=>{kn(l,{element:document.body,scope:e.store.id},c)},a=(l,c)=>{kn(l,{element:document.body,keyup:!0,keydown:!1,scope:e.store.id},c)};for(const l of Object.values(n))l.kbd&&(t&&!l.readonlyOk||uI.includes(l.id)||i(dI(l.kbd),c=>{pc(e)||(Ae(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&e.getInstanceState().isReadonly||uI.includes(l.id)||i(dI(l.kbd),c=>{pc(e)||(Ae(c),l.onSelect("kbd"))});return i(",",l=>{if(pc(e)||e.inputs.keys.has("Comma"))return;Ae(l),s.focus(),e.inputs.keys.add("Comma");const{x:c,y:u,z:d}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_down",point:{x:c,y:u,z:d},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(pc(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:c,y:u,z:d}=e.inputs.currentScreenPoint,p={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:d},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(p)}),()=>{kn.deleteScope(e.store.id)}},[n,r,t,e,o])}function dI(e){return Xne(e).map(t=>{let n="";const r=t.split("");return r.length===1?n=r[0]:r[0]==="!"?n=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?n=`alt+shift+${r[2]}`:n=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?n=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?n=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:n=`cmd+${r[1]},ctrl+${r[1]}`:n=t,n}).join(",")}function Xne(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const t=e.split(",");let n=t.lastIndexOf("");for(;n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function pc(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}const qne=x.createContext(!1);function Zne({children:e}){const t=z(),n=e8(),r=Ln(),o=_e(),s=Math.min(8,5+r),[i,a]=x.useState(0),l=x.useRef(null),[c,u]=x.useState(null),d=x.useMemo(()=>{const f=[],y=[];c?f.push(`[data-value="${c}"]`):f.push(`:nth-child(${s+1})`);for(let g=0;g<s;g++)f.push(`:nth-child(${g+1})`),y.push(`:nth-child(${g+1})`);return`
301
- #${n}_main > *:not(${f.join(", ")}) {
302
- display: none;
303
- }
304
- ${y.map(g=>`#${n}_more > *${g}`).join(", ")} {
305
- display: none;
306
- }
307
- `},[c,n,s]),p=ex(()=>{if(!l.current)return;const f=Array.from(l.current.children);a(f.length),f.findIndex(w=>w.getAttribute("data-value")===c)<=s&&u(null);const g=Array.from(l.current.children).findIndex(w=>w.getAttribute("aria-checked")==="true");g!==-1&&g>=s&&u(f[g].getAttribute("data-value"))});return x.useLayoutEffect(()=>{p()}),x.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]),x.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[y,g]of f)kn(y,w=>{var C;if(pc(t))return;Ae(w);const v=Array.from(((C=l.current)==null?void 0:C.children)??[]).filter(I=>!(I instanceof HTMLElement)||I.tagName.toLowerCase()!=="button"?!1:!!(I.offsetWidth||I.offsetHeight))[g];v&&v.click()});return()=>{kn.unbind("1,2,3,4,5,6,7,8,9,0")}},[t]),h.jsxs(h.Fragment,{children:[h.jsx("style",{children:d}),h.jsxs("div",{className:ue("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<yt.TABLET_SM}),role:"radiogroup",children:[h.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:h.jsx(vr,{type:"toolbar",sourceId:"toolbar",children:e})}),i>s&&h.jsx(qne.Provider,{value:!0,children:h.jsxs(Oi,{id:"toolbar overflow",modal:!1,children:[h.jsx(Di,{children:h.jsx(pe,{title:o("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:h.jsx(Ie,{icon:"chevron-up"})})}),h.jsx(Ri,{side:"top",align:"center",children:h.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:h.jsx(vr,{type:"toolbar-overflow",sourceId:"toolbar",children:e})})})]})})]})]})}const Qne=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Jne({activeToolId:e}){const t=z(),n=Ln(),r=_e(),o=K("is tool locked",()=>t.getInstanceState().isToolLocked,[t]);return!e||Qne.includes(e)?null:h.jsx(pe,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ue("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<yt.TABLET_SM}),onClick:()=>t.updateInstanceState({isToolLocked:!o}),children:h.jsx(Ie,{icon:o?"lock":"unlock",small:!0})})}const ere=x.memo(function({children:t}){const n=z(),r=Ln(),o=es(),s=K("current tool id",()=>n.getCurrentToolId(),[n]),{ActionsMenu:i,QuickActions:a}=Zs();return h.jsx("div",{className:"tlui-toolbar",children:h.jsxs("div",{className:"tlui-toolbar__inner",children:[h.jsxs("div",{className:"tlui-toolbar__left",children:[!o&&h.jsxs("div",{className:"tlui-toolbar__extras",children:[r<yt.TABLET&&h.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[a&&h.jsx(a,{}),i&&h.jsx(i,{})]}),h.jsx(Jne,{activeToolId:s})]}),h.jsx(Zne,{children:t??h.jsx(lne,{})})]}),r<yt.TABLET_SM&&!o&&h.jsx("div",{className:"tlui-toolbar__tools",children:h.jsx(ane,{})})]})})});function tre(){const e=le();return h.jsxs(h.Fragment,{children:[h.jsx(R,{...e["zoom-in"],noClose:!0}),h.jsx(R,{...e["zoom-out"],noClose:!0}),h.jsx(tj,{}),h.jsx(nj,{}),h.jsx(rj,{})]})}const nre=x.memo(function({children:t}){const n=ln(),[r,o]=Xs("zoom menu"),s=t??h.jsx(tre,{});return h.jsxs(iw,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[h.jsx(aw,{asChild:!0,dir:"ltr",children:h.jsx(rre,{})}),h.jsx(hg,{container:n,children:h.jsx(lw,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:h.jsx(vr,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),rre=x.forwardRef(function(t,n){const r=z(),o=Ln(),s=K("zoom",()=>r.getZoomLevel(),[r]),i=_e(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{duration:Yr})},[r]);return h.jsx(pe,{ref:n,...t,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:h.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),Ej=x.createContext({});function ore({overrides:e={},children:t}){const n=n0(e);return h.jsx(Ej.Provider,{value:x.useMemo(()=>({ContextMenu:Lee,ActionsMenu:pee,HelpMenu:qee,ZoomMenu:nre,MainMenu:pte,Minimap:gte,StylePanel:ine,PageMenu:vte,NavigationPanel:yte,Toolbar:ere,KeyboardShortcutsDialog:rte,QuickActions:wte,HelperButtons:tte,DebugPanel:Kee,DebugMenu:Hee,MenuPanel:fte,...n}),[n]),children:t})}function Zs(){return x.useContext(Ej)}function sre({overrides:e,components:t,assetUrls:n,onUiEvent:r,forceMobile:o,children:s}){return h.jsx(AG,{assetUrls:Sq(n),children:h.jsx(DG,{overrides:Pq(e),children:h.jsx(oq,{onEvent:r,children:h.jsx(dq,{children:h.jsx(sq,{children:h.jsx(xq,{forceMobile:o,children:h.jsx(ore,{overrides:t,children:h.jsx(ire,{overrides:e,children:s})})})})})})})})}function ire({overrides:e,children:t}){const n=Cq(e);return h.jsx(sZ,{overrides:n.actions,children:h.jsx(vq,{overrides:n.tools,children:t})})}function are(){const e=z(),{addToast:t}=Br();x.useEffect(()=>{function n({name:r,count:o}){t({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",n),()=>{e.removeListener("max-shapes",n)}},[e,t])}const lre=Se.memo(function({renderDebugMenuItems:t,children:n,hideUi:r,components:o,...s}){return h.jsx(sre,{...s,components:o,children:h.jsx(cre,{hideUi:r,renderDebugMenuItems:t,children:n})})}),cre=Se.memo(function({children:t,hideUi:n,...r}){return h.jsxs(h.Fragment,{children:[t,n?null:h.jsx(ure,{...r})]})}),ure=Se.memo(function(){const t=z(),n=_e(),r=Ln(),o=es(),s=K("focus",()=>t.getInstanceState().isFocusMode,[t]),i=K("debug",()=>t.getInstanceState().isDebugMode,[t]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:d,HelpMenu:p,NavigationPanel:f,HelperButtons:y,DebugPanel:g}=Zs();Yne(),Yq(),are();const{"toggle-focus-mode":w}=le();return h.jsx(aM,{children:h.jsxs("div",{className:ue("tlui-layout",{"tlui-layout__mobile":r<yt.TABLET_SM}),"data-breakpoint":r,children:[s?h.jsx("div",{className:"tlui-layout__top",children:h.jsx(pe,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>w.onSelect("menu"),children:h.jsx(Ie,{icon:"dot"})})}):h.jsxs(h.Fragment,{children:[h.jsxs("div",{className:"tlui-layout__top",children:[h.jsxs("div",{className:"tlui-layout__top__left",children:[c&&h.jsx(c,{}),y&&h.jsx(y,{})]}),h.jsx("div",{className:"tlui-layout__top__center",children:l&&h.jsx(l,{})}),h.jsxs("div",{className:"tlui-layout__top__right",children:[a&&h.jsx(a,{}),u&&r>=yt.TABLET_SM&&!o&&h.jsx(u,{})]})]}),h.jsxs("div",{className:"tlui-layout__bottom",children:[h.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&h.jsx(f,{}),d&&h.jsx(d,{}),p&&h.jsx(p,{})]}),i&&g&&h.jsx(g,{})]})]}),h.jsx(gq,{}),h.jsx(lq,{}),h.jsx(mq,{}),h.jsx(cq,{})]})})}),Qd=(e,t)=>{const[n,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),rD(e,t).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,t]),n};function dre(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 _j(e){const t=x.useMemo(()=>dre(e),[e]),n=[Qd("tldraw_draw",t.draw),Qd("tldraw_serif",t.serif),Qd("tldraw_sans",t.sansSerif),Qd("tldraw_mono",t.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function hre(e){const{children:t,maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],tools:c=[],...u}=e,d=n0(a),p=x.useMemo(()=>({Scribble:WP,CollaboratorScribble:WP,SelectionForeground:dV,SelectionBackground:cV,Handles:oV,...d}),[d]),f=zy(l),y=x.useMemo(()=>[...T$,...f],[f]),g=zy(c),w=x.useMemo(()=>[...sY,...lW,...g],[g]),S=jM(u.assetUrls),{done:v,error:C}=_j(S);return C?h.jsx(zT,{children:"Could not load assets. Please refresh the page."}):v?h.jsx(Gz,{initialState:"select",...u,components:p,shapeUtils:y,tools:w,children:h.jsxs(lre,{...u,components:p,children:[h.jsx(gre,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),t]})}):h.jsx(NT,{children:"Loading assets..."})}const pre=Object.freeze(["image/jpeg","image/png","image/gif","image/svg+xml"]),fre=Object.freeze(["video/mp4","video/quicktime"]);function gre({maxImageDimension:e=1e3,maxAssetSize:t=10*1024*1024,acceptedImageMimeTypes:n=pre,acceptedVideoMimeTypes:r=fre,onMount:o}){const s=z(),i=Br(),a=_e(),l=ex(d=>{const p=[];return p.push(...HG(d)),VV(d,{maxImageDimension:e,maxAssetSize:t,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),p.push(o==null?void 0:o(d)),()=>{p.forEach(f=>f==null?void 0:f())}});x.useLayoutEffect(()=>{if(s)return l==null?void 0:l(s)},[s,l]);const{Canvas:c}=ht(),{ContextMenu:u}=Zs();return u?h.jsx(u,{}):c?h.jsx(c,{}):null}x.memo(function(t){const[n,r]=x.useState(null),[o,s]=x.useState(null),i=zy(t.shapeUtils??[]),a=x.useMemo(()=>[...T$,...i],[i]),l=DT({snapshot:t.snapshot,shapeUtils:a}),c=jM(),{done:u,error:d}=_j(c),{pageId:p,bounds:f,scale:y,background:g,padding:w,darkMode:S,preserveAspectRatio:v,format:C="svg"}=t;return x.useLayoutEffect(()=>{if(!o||!l||!u)return;let I=!1;const P=document.createElement("div");o.appendChild(P),o.classList.add("tl-container","tl-theme__light");const E=new oe({store:l,shapeUtils:a??[],tools:[],getContainer:()=>P});p&&E.setCurrentPage(p);const _=E.getCurrentPageShapeIds();async function k(){const $=await E.getSvgString([..._],{bounds:f,scale:y,background:g,padding:w,darkMode:S,preserveAspectRatio:v});if($&&!I){if(C==="svg"){if(!I){const T=new Blob([$.svg],{type:"image/svg+xml"}),j=URL.createObjectURL(T);r(j)}}else if(C==="png"){const T=await HM($.svg,E.environment.isSafari,{type:C,quality:1,scale:2,width:$.width,height:$.height});if(T&&!I){const j=URL.createObjectURL(T);r(j)}}}E.dispose()}return k(),()=>{I=!0}},[C,o,l,a,p,f,y,g,w,S,v,u,d]),d?h.jsx(zT,{children:"Could not load assets."}):u?h.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:n&&h.jsx("img",{src:n,style:{width:"100%",height:"100%"}})}):h.jsx(NT,{children:"Loading assets..."})});const mre=1,yre=xe({tldrawFileFormatVersion:QD,schema:xe({schemaVersion:Qu,storeVersion:Qu,recordVersions:jy(me,xe({version:Qu,subTypeVersions:jy(me,Qu).optional(),subTypeKey:me.optional()}))}),records:Nt(xe({id:me,typeName:me}).allowUnknownProperties())});function Sre(e){var t;try{return!!((t=e.document)!=null&&t.version)}catch{return!1}}function vre({json:e,schema:t}){let n;try{n=yre.validate(JSON.parse(e))}catch(o){try{if(n=JSON.parse(e),Sre(n))return ri.err({type:"v1File",data:n})}catch{}return ri.err({type:"notATldrawFile",cause:o})}if(n.tldrawFileFormatVersion>mre)return ri.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r;try{const o=Object.fromEntries(n.records.map(s=>[s.id,s]));r=t.migrateStoreSnapshot({store:o,schema:n.schema})}catch(o){return ri.err({type:"invalidRecords",cause:o})}if(r.type==="error")return ri.err({type:"migrationFailed",reason:r.reason});try{return ri.ok(OT({initialData:r.value,schema:t}))}catch(o){return ri.err({type:"invalidRecords",cause:o})}}function xre(){const[e,t]=x.useState();function n(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=vre({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),t(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.zoomToFit(),r.clearOpenMenus())}return h.jsx("div",{style:{inset:0,position:"fixed"},children:h.jsx(hre,{assetUrls:nD(),onMount:n,store:e})})}jS.createRoot(document.querySelector("#root")).render(h.jsx(Se.StrictMode,{children:h.jsx(xre,{})}));