@kitschpatrol/tldraw-cli 4.6.27 → 4.6.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +510 -202
- package/dist/lib/index.js +509 -201
- package/dist/tldraw/assets/{index-D-73B8sU.js → index-Cg19E2b-.js} +12 -12
- package/dist/tldraw/index.html +1 -1
- package/package.json +5 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var $
|
|
1
|
+
var $4=Object.defineProperty;var F4=(t,e,n)=>e in t?$4(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var I=(t,e,n)=>F4(t,typeof e!="symbol"?e+"":e,n);function N4(t,e){for(var n=0;n<e.length;n++){const r=e[n];if(typeof r!="string"&&!Array.isArray(r)){for(const s in r)if(s!=="default"&&!(s in t)){const o=Object.getOwnPropertyDescriptor(r,s);o&&Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>r[s]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}(function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))r(s);new MutationObserver(s=>{for(const o of s)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&r(i)}).observe(document,{childList:!0,subtree:!0});function n(s){const o={};return s.integrity&&(o.integrity=s.integrity),s.referrerPolicy&&(o.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?o.credentials="include":s.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function r(s){if(s.ep)return;s.ep=!0;const o=n(s);fetch(s.href,o)}})();var dn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function wi(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var g2={exports:{}},tg={},m2={exports:{}},Ie={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react.production.min.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@ var $N=Object.defineProperty;var FN=(t,e,n)=>e in t?$N(t,e,{enumerable:!0,config
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ju=Symbol.for("react.element"),
|
|
9
|
+
*/var Ju=Symbol.for("react.element"),z4=Symbol.for("react.portal"),B4=Symbol.for("react.fragment"),U4=Symbol.for("react.strict_mode"),H4=Symbol.for("react.profiler"),K4=Symbol.for("react.provider"),W4=Symbol.for("react.context"),G4=Symbol.for("react.forward_ref"),V4=Symbol.for("react.suspense"),Y4=Symbol.for("react.memo"),X4=Symbol.for("react.lazy"),SP=Symbol.iterator;function q4(t){return t===null||typeof t!="object"?null:(t=SP&&t[SP]||t["@@iterator"],typeof t=="function"?t:null)}var y2={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S2=Object.assign,v2={};function Ul(t,e,n){this.props=t,this.context=e,this.refs=v2,this.updater=n||y2}Ul.prototype.isReactComponent={};Ul.prototype.setState=function(t,e){if(typeof t!="object"&&typeof t!="function"&&t!=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,t,e,"setState")};Ul.prototype.forceUpdate=function(t){this.updater.enqueueForceUpdate(this,t,"forceUpdate")};function x2(){}x2.prototype=Ul.prototype;function vw(t,e,n){this.props=t,this.context=e,this.refs=v2,this.updater=n||y2}var xw=vw.prototype=new x2;xw.constructor=vw;S2(xw,Ul.prototype);xw.isPureReactComponent=!0;var vP=Array.isArray,w2=Object.prototype.hasOwnProperty,ww={current:null},b2={key:!0,ref:!0,__self:!0,__source:!0};function P2(t,e,n){var r,s={},o=null,i=null;if(e!=null)for(r in e.ref!==void 0&&(i=e.ref),e.key!==void 0&&(o=""+e.key),e)w2.call(e,r)&&!b2.hasOwnProperty(r)&&(s[r]=e[r]);var a=arguments.length-2;if(a===1)s.children=n;else if(1<a){for(var l=Array(a),c=0;c<a;c++)l[c]=arguments[c+2];s.children=l}if(t&&t.defaultProps)for(r in a=t.defaultProps,a)s[r]===void 0&&(s[r]=a[r]);return{$$typeof:Ju,type:t,key:o,ref:i,props:s,_owner:ww.current}}function Z4(t,e){return{$$typeof:Ju,type:t.type,key:e,ref:t.ref,props:t.props,_owner:t._owner}}function bw(t){return typeof t=="object"&&t!==null&&t.$$typeof===Ju}function Q4(t){var e={"=":"=0",":":"=2"};return"$"+t.replace(/[=:]/g,function(n){return e[n]})}var xP=/\/+/g;function Fm(t,e){return typeof t=="object"&&t!==null&&t.key!=null?Q4(""+t.key):e.toString(36)}function Kh(t,e,n,r,s){var o=typeof t;(o==="undefined"||o==="boolean")&&(t=null);var i=!1;if(t===null)i=!0;else switch(o){case"string":case"number":i=!0;break;case"object":switch(t.$$typeof){case Ju:case z4:i=!0}}if(i)return i=t,s=s(i),t=r===""?"."+Fm(i,0):r,vP(s)?(n="",t!=null&&(n=t.replace(xP,"$&/")+"/"),Kh(s,e,n,"",function(c){return c})):s!=null&&(bw(s)&&(s=Z4(s,n+(!s.key||i&&i.key===s.key?"":(""+s.key).replace(xP,"$&/")+"/")+t)),e.push(s)),1;if(i=0,r=r===""?".":r+":",vP(t))for(var a=0;a<t.length;a++){o=t[a];var l=r+Fm(o,a);i+=Kh(o,e,n,l,s)}else if(l=q4(t),typeof l=="function")for(t=l.call(t),a=0;!(o=t.next()).done;)o=o.value,l=r+Fm(o,a++),i+=Kh(o,e,n,l,s);else if(o==="object")throw e=String(t),Error("Objects are not valid as a React child (found: "+(e==="[object Object]"?"object with keys {"+Object.keys(t).join(", ")+"}":e)+"). If you meant to render a collection of children, use an array instead.");return i}function Nd(t,e,n){if(t==null)return t;var r=[],s=0;return Kh(t,r,"","",function(o){return e.call(n,o,s++)}),r}function J4(t){if(t._status===-1){var e=t._result;e=e(),e.then(function(n){(t._status===0||t._status===-1)&&(t._status=1,t._result=n)},function(n){(t._status===0||t._status===-1)&&(t._status=2,t._result=n)}),t._status===-1&&(t._status=0,t._result=e)}if(t._status===1)return t._result.default;throw t._result}var Cn={current:null},Wh={transition:null},e6={ReactCurrentDispatcher:Cn,ReactCurrentBatchConfig:Wh,ReactCurrentOwner:ww};function C2(){throw Error("act(...) is not supported in production builds of React.")}Ie.Children={map:Nd,forEach:function(t,e,n){Nd(t,function(){e.apply(this,arguments)},n)},count:function(t){var e=0;return Nd(t,function(){e++}),e},toArray:function(t){return Nd(t,function(e){return e})||[]},only:function(t){if(!bw(t))throw Error("React.Children.only expected to receive a single React element child.");return t}};Ie.Component=Ul;Ie.Fragment=B4;Ie.Profiler=H4;Ie.PureComponent=vw;Ie.StrictMode=U4;Ie.Suspense=V4;Ie.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=e6;Ie.act=C2;Ie.cloneElement=function(t,e,n){if(t==null)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+t+".");var r=S2({},t.props),s=t.key,o=t.ref,i=t._owner;if(e!=null){if(e.ref!==void 0&&(o=e.ref,i=ww.current),e.key!==void 0&&(s=""+e.key),t.type&&t.type.defaultProps)var a=t.type.defaultProps;for(l in e)w2.call(e,l)&&!b2.hasOwnProperty(l)&&(r[l]=e[l]===void 0&&a!==void 0?a[l]:e[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:Ju,type:t.type,key:s,ref:o,props:r,_owner:i}};Ie.createContext=function(t){return t={$$typeof:W4,_currentValue:t,_currentValue2:t,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null},t.Provider={$$typeof:K4,_context:t},t.Consumer=t};Ie.createElement=P2;Ie.createFactory=function(t){var e=P2.bind(null,t);return e.type=t,e};Ie.createRef=function(){return{current:null}};Ie.forwardRef=function(t){return{$$typeof:G4,render:t}};Ie.isValidElement=bw;Ie.lazy=function(t){return{$$typeof:X4,_payload:{_status:-1,_result:t},_init:J4}};Ie.memo=function(t,e){return{$$typeof:Y4,type:t,compare:e===void 0?null:e}};Ie.startTransition=function(t){var e=Wh.transition;Wh.transition={};try{t()}finally{Wh.transition=e}};Ie.unstable_act=C2;Ie.useCallback=function(t,e){return Cn.current.useCallback(t,e)};Ie.useContext=function(t){return Cn.current.useContext(t)};Ie.useDebugValue=function(){};Ie.useDeferredValue=function(t){return Cn.current.useDeferredValue(t)};Ie.useEffect=function(t,e){return Cn.current.useEffect(t,e)};Ie.useId=function(){return Cn.current.useId()};Ie.useImperativeHandle=function(t,e,n){return Cn.current.useImperativeHandle(t,e,n)};Ie.useInsertionEffect=function(t,e){return Cn.current.useInsertionEffect(t,e)};Ie.useLayoutEffect=function(t,e){return Cn.current.useLayoutEffect(t,e)};Ie.useMemo=function(t,e){return Cn.current.useMemo(t,e)};Ie.useReducer=function(t,e,n){return Cn.current.useReducer(t,e,n)};Ie.useRef=function(t){return Cn.current.useRef(t)};Ie.useState=function(t){return Cn.current.useState(t)};Ie.useSyncExternalStore=function(t,e,n){return Cn.current.useSyncExternalStore(t,e,n)};Ie.useTransition=function(){return Cn.current.useTransition()};Ie.version="18.3.1";m2.exports=Ie;var w=m2.exports;const ke=wi(w),t6=N4({__proto__:null,default:ke},[w]);/**
|
|
10
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.production.min.js
|
|
12
12
|
*
|
|
@@ -64,7 +64,7 @@ ${u}`}),"","You should configure your bundler to only import one version of each
|
|
|
64
64
|
*/let Vv=[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"&&(Vv=new Int32Array(Vv));const B9=(t,e)=>{let n=-1;for(let r=0;r<t.length;r++)n=Vv[(n^t[r])&255]^n>>>8;return n^-1},LC=4,$C=4;class Ps{static isPng(e,n){return e.getUint8(n+0)===137&&e.getUint8(n+1)===80&&e.getUint8(n+2)===78&&e.getUint8(n+3)===71&&e.getUint8(n+4)===13&&e.getUint8(n+5)===10&&e.getUint8(n+6)===26&&e.getUint8(n+7)===10}static getChunkType(e,n){return[String.fromCharCode(e.getUint8(n)),String.fromCharCode(e.getUint8(n+1)),String.fromCharCode(e.getUint8(n+2)),String.fromCharCode(e.getUint8(n+3))].join("")}static readChunks(e,n=0){const r={};if(!Ps.isPng(e,n))throw new Error("Not a PNG");for(n+=8;n<=e.buffer.byteLength;){const s=n,o=e.getInt32(n);n+=4;const i=Ps.getChunkType(e,n);if(i==="IDAT"&&r[i]){n+=o+LC+$C;continue}if(i==="IEND")break;r[i]={start:s,dataOffset:n+4,size:o},n+=o+LC+$C}return r}static parsePhys(e,n){return{ppux:e.getUint32(n),ppuy:e.getUint32(n+4),unit:e.getUint8(n+4)}}static findChunk(e,n){return Ps.readChunks(e)[n]}static setPhysChunk(e,n=1,r){let s=46,o=0;const i=Ps.findChunk(e,"pHYs");i&&(s=i.start,o=i.size);const a=Ps.findChunk(e,"IDAT");a&&(s=a.start,o=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 h=new Uint8Array(l.slice(4,17));c.setInt32(17,B9(h));const f=e.buffer.slice(0,s),p=e.buffer.slice(s+o);return new Blob([f,l,p],r)}}/*!
|
|
65
65
|
* MIT License: https://github.com/sindresorhus/is-webp/blob/main/license
|
|
66
66
|
* Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
67
|
-
*/function U9(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function H9(t){const e=new Uint8Array(t);return!U9(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const $T=Object.freeze(["image/svg+xml"]),FT=Object.freeze(["image/jpeg","image/png","image/webp"]),NT=Object.freeze(["image/gif","image/apng","image/avif"]),xg=Object.freeze([...FT,...$T,...NT]),x0=Object.freeze(["video/mp4","video/webm","video/quicktime"]),K9=[...xg,...x0].join(",");class ar{static loadVideo(e){return new Promise((n,r)=>{const s=document.createElement("video");s.onloadeddata=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=e})}static async getVideoFrameAsDataUrl(e,n=0){const r=y0();let s=!1;const o=()=>{if(!s)if(e.readyState>=e.HAVE_METADATA)s=!0,e.currentTime=n;else return;if(e.readyState>=e.HAVE_CURRENT_DATA){const a=document.createElement("canvas");a.width=e.videoWidth,a.height=e.videoHeight;const l=a.getContext("2d");if(!l)throw new Error("Could not get 2d context");l.drawImage(e,0,0),r.resolve(a.toDataURL())}},i=a=>{console.error(a),r.reject(new Error("Could not get video frame"))};e.addEventListener("loadedmetadata",o),e.addEventListener("loadeddata",o),e.addEventListener("canplay",o),e.addEventListener("seeked",o),e.addEventListener("error",i),e.addEventListener("stalled",i),o();try{return await r}finally{e.removeEventListener("loadedmetadata",o),e.removeEventListener("loadeddata",o),e.removeEventListener("canplay",o),e.removeEventListener("seeked",o),e.removeEventListener("error",i),e.removeEventListener("stalled",i)}}static loadImage(e){return new Promise((n,r)=>{const s=Lu();s.onload=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load image"))},s.crossOrigin="anonymous",s.referrerPolicy="strict-origin-when-cross-origin",s.src=e})}static async getVideoSize(e){return ar.usingObjectURL(e,async n=>{const r=await ar.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const n=await ar.usingObjectURL(e,ar.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(Ps.isPng(r,0)){const s=Ps.findChunk(r,"pHYs");if(s){const o=Ps.parsePhys(r,s.dataOffset);if(o.unit===0&&o.ppux===o.ppuy){const i=Math.max(o.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 isAnimated(e){return e.type==="image/gif"?z9(await e.arrayBuffer()):e.type==="image/avif"?F9(await e.arrayBuffer()):e.type==="image/webp"?H9(await e.arrayBuffer()):e.type==="image/apng"?$9(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return NT.includes(e||"")}static isStaticImageType(e){return FT.includes(e||"")}static isVectorImageType(e){return $T.includes(e||"")}static isImageType(e){return xg.includes(e)}static async usingObjectURL(e,n){const r=URL.createObjectURL(e);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function _e(t,e,n){return t+(e-t)*n}function cs(t=""){let e=0,n=0,r=0,s=0;function o(){const i=e^e<<11;return e=n,n=r,r=s,s^=(s>>>19^i^i>>>8)>>>0,s/4294967296*2}for(let i=0;i<t.length+64;i++)e^=t.charCodeAt(i)|0,o();return o}function Ol(t,e,n,r=!1){const[s,o]=e,[i,a]=n,l=i+(t-s)/(o-s)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function ns(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function hn(t,e){if(ns(t,e))return t[e]}function FC(t){return Object.keys(t)}function ut(t){return Object.values(t)}function Xn(t){return Object.entries(t)}function w0(t){return Object.fromEntries(t)}function au(t,e){const n={};let r=!1;for(const[s,o]of Xn(t))e(s,o)?n[s]=o:r=!0;return r?n:t}function sd(t,e){const n={};for(const[r,s]of Xn(t)){const o=e(r,s);n[r]=o}return n}function zT(t,e){if(t===e)return!0;const n=new Set(Object.keys(t)),r=new Set(Object.keys(e));if(n.size!==r.size)return!1;for(const s of n)if(!r.has(s)||!Object.is(t[s],e[s]))return!1;return!0}function W9(t){const e=G9(t.chars),n=V9(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=Y9(r,e.length);return{chars:t.chars,byChar:e.byChar,byCode:e.byCode,length:e.length,first:e.byCode[0],last:e.byCode[e.length-1],firstPositive:n.firstPositive,mostPositive:n.mostPositive,firstNegative:n.firstNegative,mostNegative:n.mostNegative,jitterRange:r,paddingDict:s}}function G9(t){const e={},n={},r=t.length;for(let s=0;s<r;s++){const o=t[s];e[s]=o,n[o]=s}return{byCode:e,byChar:n,length:r}}function V9(t,e,n,r){const s=e?t.byChar[e]:Math.ceil(t.length/2),o=n?t.byChar[n]:t.length-1,i=r?t.byChar[r]:0;if(s===void 0||o===void 0||i===void 0)throw new Error("invalid charSet");if(o-s<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(s-i<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:t.byCode[s],mostPositive:t.byCode[o],firstNegative:t.byCode[s-1],mostNegative:t.byCode[i]}}function Y9(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var gy=null;function b0(){return gy||(gy=W9({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Jo(t,e,n){const r=n.byChar[t],s=n.byChar[e];return Math.abs(r-s)}function P0(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Jo(n,e.firstPositive,e)+1+hp(t.slice(1),"positive",e):n===e.mostNegative?Jo(n,e.firstNegative,e)+1+hp(t.slice(1),"negative",e):n>=e.firstPositive?Jo(n,e.firstPositive,e)+2:Jo(n,e.firstNegative,e)+2}function hp(t,e,n){const r=t[0];if(r>n.mostPositive||r<n.mostNegative)throw new Error("invalid firstChar on key");return r===n.mostPositive&&e==="positive"?Jo(r,n.mostNegative,n)+1+hp(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Jo(r,n.mostPositive,n)+1+hp(t.slice(1),e,n):e==="positive"?Jo(r,n.mostNegative,n)+2:Jo(r,n.mostPositive,n)+2}function wg(t,e,n,r,s){const o=Math.max(t.length,e.length);return n==="start"?[t.padStart(o,r),e.padStart(o,r)]:[t.padEnd(o,r),e.padEnd(o,r)]}function X9(t,e,n){let[r,s]=wg(t,e,"end",n.first),o=Yv(r,s,n);o===1&&(r=r.padEnd(r.length+1,n.first),o=n.length);const i=HT(Math.floor(o/2),n);return C0(r,i,n)}function Yv(t,e,n){const[r,s]=wg(t,e,"end",n.first).sort(),o=BT(s,r,n);return q9(o,n)}function C0(t,e,n){const r=n.length,[s,o]=wg(t,e,"start",n.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){const c=n.byChar[s[l]],u=n.byChar[o[l]],h=c+u+a;a=Math.floor(h/r);const f=h%r;i.unshift(n.byCode[f])}return a>0&&i.unshift(n.byCode[a]),i.join("")}function BT(t,e,n){const r=n.length,[s,o]=wg(t,e,"start",n.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){let c=n.byChar[s[l]];const u=n.byChar[o[l]]+a;c<u?(a=1,c+=r):a=0;const h=c-u;i.unshift(n.byCode[h])}if(a>0)throw new Error("Subtraction result is negative. Ensure a is greater than or equal to b.");for(;i.length>1&&i[0]===n.byCode[0];)i.shift();return i.join("")}function UT(t,e){return C0(t,e.byCode[1],e)}function Xv(t,e){return BT(t,e.byCode[1],e)}function HT(t,e){if(t===0)return e.byCode[0];let n="";const r=e.length;for(;t>0;)n=e.byCode[t%r]+n,t=Math.floor(t/r);return n}function q9(t,e){let n=0;const r=t.length,s=e.length;for(let o=0;o<r;o++)n+=e.byChar[t[o]]*Math.pow(s,r-o-1);return n}function Z9(t){return t.firstPositive+t.byCode[0]}function Q9(t,e){return P0(t,e)===t.length}function NC(t,e){fp(t,e)}function fp(t,e){const n=GT(t,e),r=P0(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function KT(t,e){if(!Q9(t,e))throw new Error("invalid integer length: "+t)}function WT(t,e){KT(t,e);const[n,r]=VT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=UT(r,e);return n+i}const o=eB(n,e);return YT(o,"lower",e)}function J9(t,e){KT(t,e);const[n,r]=VT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Xv(r,e);return n+i}const o=tB(n,e);return YT(o,"upper",e)}function GT(t,e){let n=0;if(t[0]===e.mostPositive)for(;t[n]===e.mostPositive;)n=n+1;if(t[0]===e.mostNegative)for(;t[n]===e.mostNegative;)n=n+1;return t.slice(0,n+1)}function VT(t,e){const n=GT(t,e),r=t.slice(n.length);return[n,r]}function eB(t,e){const n=t>=e.firstPositive,r=UT(t,e),s=t[t.length-1]===e.mostPositive,o=r[r.length-1]===e.mostPositive;return n&&o?r+e.mostNegative:!n&&s?t.slice(0,t.length-1):r}function tB(t,e){const n=t>=e.firstPositive,r=t[t.length-1]===e.mostNegative;if(n&&r){const s=t.slice(0,t.length-1);return Xv(s,e)}return!n&&r?t+e.mostPositive:Xv(t,e)}function YT(t,e,n){const r=P0(t,n),s=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+s.repeat(r-t.length)}function XT(t,e){const n=HT(Math.floor(Math.random()*e.jitterRange),e);return C0(t,n,e)}function nB(t,e,n){const r=t.padEnd(t.length+e,n.first);return XT(r,n)}function rB(t,e,n){const r=fp(t,n),s=WT(r,n);let o=0;if(e!==null){const a=Yv(t,e,n);a<n.jitterRange+1&&(o=Math.max(o,zC(a,n)))}const i=Yv(t,s,n);return i<n.jitterRange+1&&(o=Math.max(o,zC(i,n))),o}function zC(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([s,o])=>o>n);return r?parseInt(r[0]):0}function sB(t,e,n=b0()){if(t!==null&&NC(t,n),e!==null&&NC(e,n),t===null&&e===null)return Z9(n);if(t===null){const r=fp(e,n);return J9(r,n)}if(e===null){const r=fp(t,n);return WT(r,n)}if(t>=e)throw new Error(t+" >= "+e);return X9(t,e,n)}function qT(t,e,n=b0()){const r=sB(t,e,n),s=rB(r,e,n);return s?nB(r,s,n):XT(r,n)}function ZT(t,e,n,r=b0()){return oB(t,e,n,r,qT,ZT)}function oB(t,e,n,r,s,o){if(n===0)return[];if(n===1)return[s(t,e,r)];if(e==null){let l=s(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=s(l,e,r),c.push(l);return c}if(t==null){let l=s(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=s(t,l,r),c.push(l);return c.reverse(),c}const i=Math.floor(n/2),a=s(t,e,r);return[...o(t,a,i,r),a,...o(a,e,n-i-1,r)]}const Vl=ZT,QT="a0";function iB(t){try{qT(t,null)}catch{throw new Error("invalid index: "+t)}}function Dl(t,e,n){return Vl(t??null,e??null,n)}function my(t,e){return Vl(t??null,null,e)}function $u(t,e){return Vl(t??null,e??null,1)[0]}function _s(t=null){return Vl(t,null,1)[0]}function aB(t=null){return Vl(null,t,1)[0]}function Fu(t,e="a1"){return[e,...Vl(e,null,t)]}function cn(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function lB(t,e){return t.id>e.id?1:-1}function _0(t){try{return localStorage.getItem(t)}catch{return null}}function I0(t,e){try{localStorage.setItem(t,e)}catch{}}function cB(){try{localStorage.clear()}catch{}}function JT(t){try{return sessionStorage.getItem(t)}catch{return null}}function E0(t,e){try{sessionStorage.setItem(t,e)}catch{}}function eM(t){try{sessionStorage.removeItem(t)}catch{}}function uB(){try{sessionStorage.clear()}catch{}}const ol=[],dB=60,nf=Math.ceil(1e3/dB);let wc,yy=0,qv=0;const hB=()=>{const t=ol.splice(0,ol.length);for(const e of t)e()};function tM(){if(wc)return;const t=Date.now(),e=t-qv;if(yy+e<nf){wc=requestAnimationFrame(()=>{wc=void 0,tM()});return}wc=requestAnimationFrame(()=>{wc=void 0,qv=t,yy=Math.min(yy+e-nf,nf*10),hB()})}let BC=!1;function nM(t){return ol.includes(t)||(ol.push(t),BC||(BC=!0,qv=Date.now()-nf-1),tM()),()=>{const e=ol.indexOf(t);e>-1&&ol.splice(e,1)}}class fB{constructor(){I(this,"timeouts",new Map);I(this,"intervals",new Map);I(this,"rafs",new Map);this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,n,r,...s){const o=window.setTimeout(n,r,s),i=this.timeouts.get(e)??[];return this.timeouts.set(e,[...i,o]),o}setInterval(e,n,r,...s){const o=window.setInterval(n,r,s),i=this.intervals.get(e)??[];return this.intervals.set(e,[...i,o]),o}requestAnimationFrame(e,n){const r=window.requestAnimationFrame(n),s=this.rafs.get(e)??[];return this.rafs.set(e,[...s,r]),r}dispose(e){var n,r,s;(n=this.timeouts.get(e))==null||n.forEach(o=>clearTimeout(o)),(r=this.intervals.get(e))==null||r.forEach(o=>clearInterval(o)),(s=this.rafs.get(e))==null||s.forEach(o=>cancelAnimationFrame(o)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(const e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(n,r,...s)=>this.setTimeout(e,n,r,s),setInterval:(n,r,...s)=>this.setInterval(e,n,r,s),requestAnimationFrame:n=>this.requestAnimationFrame(e,n),dispose:()=>this.dispose(e)}}}const ge=(t,e)=>{try{return new URL(t,e)}catch{return}};function pB(t){return t!==void 0}function gB(){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]:[t=>t&&JSON.parse(JSON.stringify(t)),!1]}const rM=gB(),nt=rM[0];rM[1];const mB=Object.getPrototypeOf(nt({}));_i("@tldraw/utils","3.8.0-canary.c422debb621c","esm");var bc=function(t){return t&&t.Math===Math&&t},In=bc(typeof globalThis=="object"&&globalThis)||bc(typeof window=="object"&&window)||bc(typeof self=="object"&&self)||bc(typeof dn=="object"&&dn)||bc(typeof dn=="object"&&dn)||function(){return this}()||Function("return this")(),k0={},En=function(t){try{return!!t()}catch{return!0}},yB=En,Ii=!yB(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),SB=En,bg=!SB(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),vB=bg,nh=Function.prototype.call,Io=vB?nh.bind(nh):function(){return nh.apply(nh,arguments)},sM={},oM={}.propertyIsEnumerable,iM=Object.getOwnPropertyDescriptor,xB=iM&&!oM.call({1:2},1);sM.f=xB?function(e){var n=iM(this,e);return!!n&&n.enumerable}:oM;var aM=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},lM=bg,cM=Function.prototype,Zv=cM.call,wB=lM&&cM.bind.bind(Zv,Zv),Lt=lM?wB:function(t){return function(){return Zv.apply(t,arguments)}},uM=Lt,bB=uM({}.toString),PB=uM("".slice),Yl=function(t){return PB(bB(t),8,-1)},CB=Lt,_B=En,IB=Yl,Sy=Object,EB=CB("".split),kB=_B(function(){return!Sy("z").propertyIsEnumerable(0)})?function(t){return IB(t)==="String"?EB(t,""):Sy(t)}:Sy,Pg=function(t){return t==null},TB=Pg,MB=TypeError,Xl=function(t){if(TB(t))throw new MB("Can't call method on "+t);return t},AB=kB,jB=Xl,Cg=function(t){return AB(jB(t))},vy=typeof document=="object"&&document.all,kn=typeof vy>"u"&&vy!==void 0?function(t){return typeof t=="function"||t===vy}:function(t){return typeof t=="function"},OB=kn,Pa=function(t){return typeof t=="object"?t!==null:OB(t)},xy=In,DB=kn,RB=function(t){return DB(t)?t:void 0},_g=function(t,e){return arguments.length<2?RB(xy[t]):xy[t]&&xy[t][e]},LB=Lt,dM=LB({}.isPrototypeOf),$B=In,UC=$B.navigator,HC=UC&&UC.userAgent,FB=HC?String(HC):"",hM=In,wy=FB,KC=hM.process,WC=hM.Deno,GC=KC&&KC.versions||WC&&WC.version,VC=GC&&GC.v8,Xr,pp;VC&&(Xr=VC.split("."),pp=Xr[0]>0&&Xr[0]<4?1:+(Xr[0]+Xr[1]));!pp&&wy&&(Xr=wy.match(/Edge\/(\d+)/),(!Xr||Xr[1]>=74)&&(Xr=wy.match(/Chrome\/(\d+)/),Xr&&(pp=+Xr[1])));var NB=pp,YC=NB,zB=En,BB=In,UB=BB.String,fM=!!Object.getOwnPropertySymbols&&!zB(function(){var t=Symbol("symbol detection");return!UB(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&YC&&YC<41}),HB=fM,pM=HB&&!Symbol.sham&&typeof Symbol.iterator=="symbol",KB=_g,WB=kn,GB=dM,VB=pM,YB=Object,gM=VB?function(t){return typeof t=="symbol"}:function(t){var e=KB("Symbol");return WB(e)&&GB(e.prototype,YB(t))},XB=String,qB=function(t){try{return XB(t)}catch{return"Object"}},ZB=kn,QB=qB,JB=TypeError,T0=function(t){if(ZB(t))return t;throw new JB(QB(t)+" is not a function")},e7=T0,t7=Pg,M0=function(t,e){var n=t[e];return t7(n)?void 0:e7(n)},by=Io,Py=kn,Cy=Pa,n7=TypeError,r7=function(t,e){var n,r;if(e==="string"&&Py(n=t.toString)&&!Cy(r=by(n,t))||Py(n=t.valueOf)&&!Cy(r=by(n,t))||e!=="string"&&Py(n=t.toString)&&!Cy(r=by(n,t)))return r;throw new n7("Can't convert object to primitive value")},mM={exports:{}},XC=In,s7=Object.defineProperty,A0=function(t,e){try{s7(XC,t,{value:e,configurable:!0,writable:!0})}catch{XC[t]=e}return e},o7=In,i7=A0,qC="__core-js_shared__",ZC=mM.exports=o7[qC]||i7(qC,{});(ZC.versions||(ZC.versions=[])).push({version:"3.40.0",mode:"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.40.0/LICENSE",source:"https://github.com/zloirock/core-js"});var j0=mM.exports,QC=j0,O0=function(t,e){return QC[t]||(QC[t]=e||{})},a7=Xl,l7=Object,od=function(t){return l7(a7(t))},c7=Lt,u7=od,d7=c7({}.hasOwnProperty),Ei=Object.hasOwn||function(e,n){return d7(u7(e),n)},h7=Lt,f7=0,p7=Math.random(),g7=h7(1 .toString),yM=function(t){return"Symbol("+(t===void 0?"":t)+")_"+g7(++f7+p7,36)},m7=In,y7=O0,JC=Ei,S7=yM,v7=fM,x7=pM,il=m7.Symbol,_y=y7("wks"),w7=x7?il.for||il:il&&il.withoutSetter||S7,Eo=function(t){return JC(_y,t)||(_y[t]=v7&&JC(il,t)?il[t]:w7("Symbol."+t)),_y[t]},b7=Io,e_=Pa,t_=gM,P7=M0,C7=r7,_7=Eo,I7=TypeError,E7=_7("toPrimitive"),k7=function(t,e){if(!e_(t)||t_(t))return t;var n=P7(t,E7),r;if(n){if(e===void 0&&(e="default"),r=b7(n,t,e),!e_(r)||t_(r))return r;throw new I7("Can't convert object to primitive value")}return e===void 0&&(e="number"),C7(t,e)},T7=k7,M7=gM,SM=function(t){var e=T7(t,"string");return M7(e)?e:e+""},A7=In,n_=Pa,Qv=A7.document,j7=n_(Qv)&&n_(Qv.createElement),vM=function(t){return j7?Qv.createElement(t):{}},O7=Ii,D7=En,R7=vM,xM=!O7&&!D7(function(){return Object.defineProperty(R7("div"),"a",{get:function(){return 7}}).a!==7}),L7=Ii,$7=Io,F7=sM,N7=aM,z7=Cg,B7=SM,U7=Ei,H7=xM,r_=Object.getOwnPropertyDescriptor;k0.f=L7?r_:function(e,n){if(e=z7(e),n=B7(n),H7)try{return r_(e,n)}catch{}if(U7(e,n))return N7(!$7(F7.f,e,n),e[n])};var ql={},K7=Ii,W7=En,wM=K7&&W7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),G7=Pa,V7=String,Y7=TypeError,Ca=function(t){if(G7(t))return t;throw new Y7(V7(t)+" is not an object")},X7=Ii,q7=xM,Z7=wM,rh=Ca,s_=SM,Q7=TypeError,Iy=Object.defineProperty,J7=Object.getOwnPropertyDescriptor,Ey="enumerable",ky="configurable",Ty="writable";ql.f=X7?Z7?function(e,n,r){if(rh(e),n=s_(n),rh(r),typeof e=="function"&&n==="prototype"&&"value"in r&&Ty in r&&!r[Ty]){var s=J7(e,n);s&&s[Ty]&&(e[n]=r.value,r={configurable:ky in r?r[ky]:s[ky],enumerable:Ey in r?r[Ey]:s[Ey],writable:!1})}return Iy(e,n,r)}:Iy:function(e,n,r){if(rh(e),n=s_(n),rh(r),q7)try{return Iy(e,n,r)}catch{}if("get"in r||"set"in r)throw new Q7("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var eU=Ii,tU=ql,nU=aM,D0=eU?function(t,e,n){return tU.f(t,e,nU(1,n))}:function(t,e,n){return t[e]=n,t},bM={exports:{}},Jv=Ii,rU=Ei,PM=Function.prototype,sU=Jv&&Object.getOwnPropertyDescriptor,R0=rU(PM,"name"),oU=R0&&(function(){}).name==="something",iU=R0&&(!Jv||Jv&&sU(PM,"name").configurable),aU={EXISTS:R0,PROPER:oU,CONFIGURABLE:iU},lU=Lt,cU=kn,ex=j0,uU=lU(Function.toString);cU(ex.inspectSource)||(ex.inspectSource=function(t){return uU(t)});var CM=ex.inspectSource,dU=In,hU=kn,o_=dU.WeakMap,fU=hU(o_)&&/native code/.test(String(o_)),pU=O0,gU=yM,i_=pU("keys"),_M=function(t){return i_[t]||(i_[t]=gU(t))},L0={},mU=fU,IM=In,yU=Pa,SU=D0,My=Ei,Ay=j0,vU=_M,xU=L0,a_="Object already initialized",tx=IM.TypeError,wU=IM.WeakMap,gp,Nu,mp,bU=function(t){return mp(t)?Nu(t):gp(t,{})},PU=function(t){return function(e){var n;if(!yU(e)||(n=Nu(e)).type!==t)throw new tx("Incompatible receiver, "+t+" required");return n}};if(mU||Ay.state){var ms=Ay.state||(Ay.state=new wU);ms.get=ms.get,ms.has=ms.has,ms.set=ms.set,gp=function(t,e){if(ms.has(t))throw new tx(a_);return e.facade=t,ms.set(t,e),e},Nu=function(t){return ms.get(t)||{}},mp=function(t){return ms.has(t)}}else{var Aa=vU("state");xU[Aa]=!0,gp=function(t,e){if(My(t,Aa))throw new tx(a_);return e.facade=t,SU(t,Aa,e),e},Nu=function(t){return My(t,Aa)?t[Aa]:{}},mp=function(t){return My(t,Aa)}}var EM={set:gp,get:Nu,has:mp,enforce:bU,getterFor:PU},$0=Lt,CU=En,_U=kn,sh=Ei,nx=Ii,IU=aU.CONFIGURABLE,EU=CM,kM=EM,kU=kM.enforce,TU=kM.get,l_=String,rf=Object.defineProperty,MU=$0("".slice),AU=$0("".replace),jU=$0([].join),OU=nx&&!CU(function(){return rf(function(){},"length",{value:8}).length!==8}),DU=String(String).split("String"),RU=bM.exports=function(t,e,n){MU(l_(e),0,7)==="Symbol("&&(e="["+AU(l_(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!sh(t,"name")||IU&&t.name!==e)&&(nx?rf(t,"name",{value:e,configurable:!0}):t.name=e),OU&&n&&sh(n,"arity")&&t.length!==n.arity&&rf(t,"length",{value:n.arity});try{n&&sh(n,"constructor")&&n.constructor?nx&&rf(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=kU(t);return sh(r,"source")||(r.source=jU(DU,typeof e=="string"?e:"")),t};Function.prototype.toString=RU(function(){return _U(this)&&TU(this).source||EU(this)},"toString");var LU=bM.exports,$U=kn,FU=ql,NU=LU,zU=A0,TM=function(t,e,n,r){r||(r={});var s=r.enumerable,o=r.name!==void 0?r.name:e;if($U(n)&&NU(n,o,r),r.global)s?t[e]=n:zU(e,n);else{try{r.unsafe?t[e]&&(s=!0):delete t[e]}catch{}s?t[e]=n:FU.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},MM={},BU=Math.ceil,UU=Math.floor,HU=Math.trunc||function(e){var n=+e;return(n>0?UU:BU)(n)},KU=HU,_a=function(t){var e=+t;return e!==e||e===0?0:KU(e)},WU=_a,GU=Math.max,VU=Math.min,YU=function(t,e){var n=WU(t);return n<0?GU(n+e,0):VU(n,e)},XU=_a,qU=Math.min,AM=function(t){var e=XU(t);return e>0?qU(e,9007199254740991):0},ZU=AM,id=function(t){return ZU(t.length)},QU=Cg,JU=YU,eH=id,c_=function(t){return function(e,n,r){var s=QU(e),o=eH(s);if(o===0)return!t&&-1;var i=JU(r,o),a;if(t&&n!==n){for(;o>i;)if(a=s[i++],a!==a)return!0}else for(;o>i;i++)if((t||i in s)&&s[i]===n)return t||i||0;return!t&&-1}},tH={includes:c_(!0),indexOf:c_(!1)},nH=Lt,jy=Ei,rH=Cg,sH=tH.indexOf,oH=L0,u_=nH([].push),jM=function(t,e){var n=rH(t),r=0,s=[],o;for(o in n)!jy(oH,o)&&jy(n,o)&&u_(s,o);for(;e.length>r;)jy(n,o=e[r++])&&(~sH(s,o)||u_(s,o));return s},F0=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],iH=jM,aH=F0,lH=aH.concat("length","prototype");MM.f=Object.getOwnPropertyNames||function(e){return iH(e,lH)};var OM={};OM.f=Object.getOwnPropertySymbols;var cH=_g,uH=Lt,dH=MM,hH=OM,fH=Ca,pH=uH([].concat),gH=cH("Reflect","ownKeys")||function(e){var n=dH.f(fH(e)),r=hH.f;return r?pH(n,r(e)):n},d_=Ei,mH=gH,yH=k0,SH=ql,vH=function(t,e,n){for(var r=mH(e),s=SH.f,o=yH.f,i=0;i<r.length;i++){var a=r[i];!d_(t,a)&&!(n&&d_(n,a))&&s(t,a,o(e,a))}},xH=En,wH=kn,bH=/#|\.prototype\./,ad=function(t,e){var n=CH[PH(t)];return n===IH?!0:n===_H?!1:wH(e)?xH(e):!!e},PH=ad.normalize=function(t){return String(t).replace(bH,".").toLowerCase()},CH=ad.data={},_H=ad.NATIVE="N",IH=ad.POLYFILL="P",EH=ad,oh=In,kH=k0.f,TH=D0,MH=TM,AH=A0,jH=vH,OH=EH,Zl=function(t,e){var n=t.target,r=t.global,s=t.stat,o,i,a,l,c,u;if(r?i=oh:s?i=oh[n]||AH(n,{}):i=oh[n]&&oh[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=kH(i,a),l=u&&u.value):l=i[a],o=OH(r?a:n+(s?".":"#")+a,t.forced),!o&&l!==void 0){if(typeof c==typeof l)continue;jH(c,l)}(t.sham||l&&l.sham)&&TH(c,"sham",!0),MH(i,a,c,t)}},DM={},DH=jM,RH=F0,LH=Object.keys||function(e){return DH(e,RH)},$H=Ii,FH=wM,NH=ql,zH=Ca,BH=Cg,UH=LH;DM.f=$H&&!FH?Object.defineProperties:function(e,n){zH(e);for(var r=BH(n),s=UH(n),o=s.length,i=0,a;o>i;)NH.f(e,a=s[i++],r[a]);return e};var HH=_g,KH=HH("document","documentElement"),WH=Ca,GH=DM,h_=F0,VH=L0,YH=KH,XH=vM,qH=_M,f_=">",p_="<",rx="prototype",sx="script",RM=qH("IE_PROTO"),Oy=function(){},LM=function(t){return p_+sx+f_+t+p_+"/"+sx+f_},g_=function(t){t.write(LM("")),t.close();var e=t.parentWindow.Object;return t=null,e},ZH=function(){var t=XH("iframe"),e="java"+sx+":",n;return t.style.display="none",YH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(LM("document.F=Object")),n.close(),n.F},ih,sf=function(){try{ih=new ActiveXObject("htmlfile")}catch{}sf=typeof document<"u"?document.domain&&ih?g_(ih):ZH():g_(ih);for(var t=h_.length;t--;)delete sf[rx][h_[t]];return sf()};VH[RM]=!0;var $M=Object.create||function(e,n){var r;return e!==null?(Oy[rx]=WH(e),r=new Oy,Oy[rx]=null,r[RM]=e):r=sf(),n===void 0?r:GH.f(r,n)},QH=Eo,JH=$M,eK=ql.f,ox=QH("unscopables"),ix=Array.prototype;ix[ox]===void 0&&eK(ix,ox,{configurable:!0,value:JH(null)});var N0=function(t){ix[ox][t]=!0},tK=Zl,nK=od,rK=id,sK=_a,oK=N0;tK({target:"Array",proto:!0},{at:function(e){var n=nK(this),r=rK(n),s=sK(e),o=s>=0?s:r+s;return o<0||o>=r?void 0:n[o]}});oK("at");var iK=In,aK=Lt,ld=function(t,e){return aK(iK[t].prototype[e])},lK=ld;lK("Array","at");var cK=Yl,FM=Array.isArray||function(e){return cK(e)==="Array"},uK=TypeError,dK=9007199254740991,hK=function(t){if(t>dK)throw uK("Maximum allowed index exceeded");return t},fK=Yl,pK=Lt,gK=function(t){if(fK(t)==="Function")return pK(t)},m_=gK,mK=T0,yK=bg,SK=m_(m_.bind),vK=function(t,e){return mK(t),e===void 0?t:yK?SK(t,e):function(){return t.apply(e,arguments)}},xK=FM,wK=id,bK=hK,PK=vK,NM=function(t,e,n,r,s,o,i,a){for(var l=s,c=0,u=i?PK(i,a):!1,h,f;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],o>0&&xK(h)?(f=wK(h),l=NM(t,e,h,f,l,o-1)-1):(bK(l+1),t[l]=h),l++),c++;return l},zM=NM,CK=Eo,_K=CK("toStringTag"),BM={};BM[_K]="z";var IK=String(BM)==="[object z]",EK=IK,kK=kn,of=Yl,TK=Eo,MK=TK("toStringTag"),AK=Object,jK=of(function(){return arguments}())==="Arguments",OK=function(t,e){try{return t[e]}catch{}},UM=EK?of:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=OK(e=AK(t),MK))=="string"?n:jK?of(e):(r=of(e))==="Object"&&kK(e.callee)?"Arguments":r},DK=Lt,RK=En,HM=kn,LK=UM,$K=_g,FK=CM,KM=function(){},WM=$K("Reflect","construct"),z0=/^\s*(?:class|function)\b/,NK=DK(z0.exec),zK=!z0.test(KM),Pc=function(e){if(!HM(e))return!1;try{return WM(KM,[],e),!0}catch{return!1}},GM=function(e){if(!HM(e))return!1;switch(LK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return zK||!!NK(z0,FK(e))}catch{return!0}};GM.sham=!0;var BK=!WM||RK(function(){var t;return Pc(Pc.call)||!Pc(Object)||!Pc(function(){t=!0})||t})?GM:Pc,y_=FM,UK=BK,HK=Pa,KK=Eo,WK=KK("species"),S_=Array,GK=function(t){var e;return y_(t)&&(e=t.constructor,UK(e)&&(e===S_||y_(e.prototype))?e=void 0:HK(e)&&(e=e[WK],e===null&&(e=void 0))),e===void 0?S_:e},VK=GK,VM=function(t,e){return new(VK(t))(e===0?0:e)},YK=Zl,XK=zM,qK=T0,ZK=od,QK=id,JK=VM;YK({target:"Array",proto:!0},{flatMap:function(e){var n=ZK(this),r=QK(n),s;return qK(e),s=JK(n,0),s.length=XK(s,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),s}});var eW=N0;eW("flatMap");var tW=ld;tW("Array","flatMap");var nW=Zl,rW=zM,sW=od,oW=id,iW=_a,aW=VM;nW({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=sW(this),r=oW(n),s=aW(n,0);return s.length=rW(s,n,n,r,0,e===void 0?1:iW(e)),s}});var lW=N0;lW("flat");var cW=ld;cW("Array","flat");var uW=UM,dW=String,cd=function(t){if(uW(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return dW(t)},hW=Zl,fW=Lt,pW=Xl,gW=_a,mW=cd,yW=En,SW=fW("".charAt),vW=yW(function(){return"𠮷".at(-2)!=="\uD842"});hW({target:"String",proto:!0,forced:vW},{at:function(e){var n=mW(pW(this)),r=n.length,s=gW(e),o=s>=0?s:r+s;return o<0||o>=r?void 0:SW(n,o)}});var xW=ld;xW("String","at");var wW=Ca,YM=function(){var t=wW(this),e="";return t.hasIndices&&(e+="d"),t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.unicodeSets&&(e+="v"),t.sticky&&(e+="y"),e},B0=En,bW=In,U0=bW.RegExp,H0=B0(function(){var t=U0("a","y");return t.lastIndex=2,t.exec("abcd")!==null}),PW=H0||B0(function(){return!U0("a","y").sticky}),CW=H0||B0(function(){var t=U0("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),_W={BROKEN_CARET:CW,MISSED_STICKY:PW,UNSUPPORTED_Y:H0},IW=En,EW=In,kW=EW.RegExp,TW=IW(function(){var t=kW(".","s");return!(t.dotAll&&t.test(`
|
|
67
|
+
*/function U9(t){return!t||t.length<12?!1:t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80}function H9(t){const e=new Uint8Array(t);return!U9(e)||!e||e.length<21?!1:(e[20]>>1&1)===1}const $T=Object.freeze(["image/svg+xml"]),FT=Object.freeze(["image/jpeg","image/png","image/webp"]),NT=Object.freeze(["image/gif","image/apng","image/avif"]),xg=Object.freeze([...FT,...$T,...NT]),x0=Object.freeze(["video/mp4","video/webm","video/quicktime"]),K9=[...xg,...x0].join(",");class ar{static loadVideo(e){return new Promise((n,r)=>{const s=document.createElement("video");s.onloadeddata=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load video"))},s.crossOrigin="anonymous",s.src=e})}static async getVideoFrameAsDataUrl(e,n=0){const r=y0();let s=!1;const o=()=>{if(!s)if(e.readyState>=e.HAVE_METADATA)s=!0,e.currentTime=n;else return;if(e.readyState>=e.HAVE_CURRENT_DATA){const a=document.createElement("canvas");a.width=e.videoWidth,a.height=e.videoHeight;const l=a.getContext("2d");if(!l)throw new Error("Could not get 2d context");l.drawImage(e,0,0),r.resolve(a.toDataURL())}},i=a=>{console.error(a),r.reject(new Error("Could not get video frame"))};e.addEventListener("loadedmetadata",o),e.addEventListener("loadeddata",o),e.addEventListener("canplay",o),e.addEventListener("seeked",o),e.addEventListener("error",i),e.addEventListener("stalled",i),o();try{return await r}finally{e.removeEventListener("loadedmetadata",o),e.removeEventListener("loadeddata",o),e.removeEventListener("canplay",o),e.removeEventListener("seeked",o),e.removeEventListener("error",i),e.removeEventListener("stalled",i)}}static loadImage(e){return new Promise((n,r)=>{const s=Lu();s.onload=()=>n(s),s.onerror=o=>{console.error(o),r(new Error("Could not load image"))},s.crossOrigin="anonymous",s.referrerPolicy="strict-origin-when-cross-origin",s.src=e})}static async getVideoSize(e){return ar.usingObjectURL(e,async n=>{const r=await ar.loadVideo(n);return{w:r.videoWidth,h:r.videoHeight}})}static async getImageSize(e){const n=await ar.usingObjectURL(e,ar.loadImage);try{if(e.type==="image/png"){const r=new DataView(await e.arrayBuffer());if(Ps.isPng(r,0)){const s=Ps.findChunk(r,"pHYs");if(s){const o=Ps.parsePhys(r,s.dataOffset);if(o.unit===0&&o.ppux===o.ppuy){const i=Math.max(o.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 isAnimated(e){return e.type==="image/gif"?z9(await e.arrayBuffer()):e.type==="image/avif"?F9(await e.arrayBuffer()):e.type==="image/webp"?H9(await e.arrayBuffer()):e.type==="image/apng"?$9(await e.arrayBuffer()):!1}static isAnimatedImageType(e){return NT.includes(e||"")}static isStaticImageType(e){return FT.includes(e||"")}static isVectorImageType(e){return $T.includes(e||"")}static isImageType(e){return xg.includes(e)}static async usingObjectURL(e,n){const r=URL.createObjectURL(e);try{return await n(r)}finally{URL.revokeObjectURL(r)}}}function _e(t,e,n){return t+(e-t)*n}function cs(t=""){let e=0,n=0,r=0,s=0;function o(){const i=e^e<<11;return e=n,n=r,r=s,s^=(s>>>19^i^i>>>8)>>>0,s/4294967296*2}for(let i=0;i<t.length+64;i++)e^=t.charCodeAt(i)|0,o();return o}function Ol(t,e,n,r=!1){const[s,o]=e,[i,a]=n,l=i+(t-s)/(o-s)*(a-i);return r?i<a?Math.max(Math.min(l,a),i):Math.max(Math.min(l,i),a):l}function ns(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function hn(t,e){if(ns(t,e))return t[e]}function FC(t){return Object.keys(t)}function ut(t){return Object.values(t)}function Xn(t){return Object.entries(t)}function w0(t){return Object.fromEntries(t)}function au(t,e){const n={};let r=!1;for(const[s,o]of Xn(t))e(s,o)?n[s]=o:r=!0;return r?n:t}function sd(t,e){const n={};for(const[r,s]of Xn(t)){const o=e(r,s);n[r]=o}return n}function zT(t,e){if(t===e)return!0;const n=new Set(Object.keys(t)),r=new Set(Object.keys(e));if(n.size!==r.size)return!1;for(const s of n)if(!r.has(s)||!Object.is(t[s],e[s]))return!1;return!0}function W9(t){const e=G9(t.chars),n=V9(e,t.firstPositive,t.mostPositive,t.mostNegative),r=t.jitterRange??Math.floor(Math.pow(e.length,3)/5),s=Y9(r,e.length);return{chars:t.chars,byChar:e.byChar,byCode:e.byCode,length:e.length,first:e.byCode[0],last:e.byCode[e.length-1],firstPositive:n.firstPositive,mostPositive:n.mostPositive,firstNegative:n.firstNegative,mostNegative:n.mostNegative,jitterRange:r,paddingDict:s}}function G9(t){const e={},n={},r=t.length;for(let s=0;s<r;s++){const o=t[s];e[s]=o,n[o]=s}return{byCode:e,byChar:n,length:r}}function V9(t,e,n,r){const s=e?t.byChar[e]:Math.ceil(t.length/2),o=n?t.byChar[n]:t.length-1,i=r?t.byChar[r]:0;if(s===void 0||o===void 0||i===void 0)throw new Error("invalid charSet");if(o-s<3)throw new Error("mostPositive must be at least 3 characters away from neutral");if(s-i<3)throw new Error("mostNegative must be at least 3 characters away from neutral");return{firstPositive:t.byCode[s],mostPositive:t.byCode[o],firstNegative:t.byCode[s-1],mostNegative:t.byCode[i]}}function Y9(t,e){const n={};for(let r=0;r<100&&(n[r]=Math.pow(e,r),!(n[r]>t));r++);return n}var gy=null;function b0(){return gy||(gy=W9({chars:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",firstPositive:"a",mostPositive:"z",mostNegative:"A"}))}function Jo(t,e,n){const r=n.byChar[t],s=n.byChar[e];return Math.abs(r-s)}function P0(t,e){const n=t[0];if(n>e.mostPositive||n<e.mostNegative)throw new Error("invalid firstChar on key");return n===e.mostPositive?Jo(n,e.firstPositive,e)+1+hp(t.slice(1),"positive",e):n===e.mostNegative?Jo(n,e.firstNegative,e)+1+hp(t.slice(1),"negative",e):n>=e.firstPositive?Jo(n,e.firstPositive,e)+2:Jo(n,e.firstNegative,e)+2}function hp(t,e,n){const r=t[0];if(r>n.mostPositive||r<n.mostNegative)throw new Error("invalid firstChar on key");return r===n.mostPositive&&e==="positive"?Jo(r,n.mostNegative,n)+1+hp(t.slice(1),e,n):r===n.mostNegative&&e==="negative"?Jo(r,n.mostPositive,n)+1+hp(t.slice(1),e,n):e==="positive"?Jo(r,n.mostNegative,n)+2:Jo(r,n.mostPositive,n)+2}function wg(t,e,n,r,s){const o=Math.max(t.length,e.length);return n==="start"?[t.padStart(o,r),e.padStart(o,r)]:[t.padEnd(o,r),e.padEnd(o,r)]}function X9(t,e,n){let[r,s]=wg(t,e,"end",n.first),o=Yv(r,s,n);o===1&&(r=r.padEnd(r.length+1,n.first),o=n.length);const i=HT(Math.floor(o/2),n);return C0(r,i,n)}function Yv(t,e,n){const[r,s]=wg(t,e,"end",n.first).sort(),o=BT(s,r,n);return q9(o,n)}function C0(t,e,n){const r=n.length,[s,o]=wg(t,e,"start",n.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){const c=n.byChar[s[l]],u=n.byChar[o[l]],h=c+u+a;a=Math.floor(h/r);const f=h%r;i.unshift(n.byCode[f])}return a>0&&i.unshift(n.byCode[a]),i.join("")}function BT(t,e,n){const r=n.length,[s,o]=wg(t,e,"start",n.first),i=[];let a=0;for(let l=s.length-1;l>=0;l--){let c=n.byChar[s[l]];const u=n.byChar[o[l]]+a;c<u?(a=1,c+=r):a=0;const h=c-u;i.unshift(n.byCode[h])}if(a>0)throw new Error("Subtraction result is negative. Ensure a is greater than or equal to b.");for(;i.length>1&&i[0]===n.byCode[0];)i.shift();return i.join("")}function UT(t,e){return C0(t,e.byCode[1],e)}function Xv(t,e){return BT(t,e.byCode[1],e)}function HT(t,e){if(t===0)return e.byCode[0];let n="";const r=e.length;for(;t>0;)n=e.byCode[t%r]+n,t=Math.floor(t/r);return n}function q9(t,e){let n=0;const r=t.length,s=e.length;for(let o=0;o<r;o++)n+=e.byChar[t[o]]*Math.pow(s,r-o-1);return n}function Z9(t){return t.firstPositive+t.byCode[0]}function Q9(t,e){return P0(t,e)===t.length}function NC(t,e){fp(t,e)}function fp(t,e){const n=GT(t,e),r=P0(n,e);if(r>t.length)throw new Error("invalid order key length: "+t);return t.slice(0,r)}function KT(t,e){if(!Q9(t,e))throw new Error("invalid integer length: "+t)}function WT(t,e){KT(t,e);const[n,r]=VT(t,e);if(r.split("").some(i=>i!==e.byCode[e.length-1])){const i=UT(r,e);return n+i}const o=eB(n,e);return YT(o,"lower",e)}function J9(t,e){KT(t,e);const[n,r]=VT(t,e);if(r.split("").some(i=>i!==e.byCode[0])){const i=Xv(r,e);return n+i}const o=tB(n,e);return YT(o,"upper",e)}function GT(t,e){let n=0;if(t[0]===e.mostPositive)for(;t[n]===e.mostPositive;)n=n+1;if(t[0]===e.mostNegative)for(;t[n]===e.mostNegative;)n=n+1;return t.slice(0,n+1)}function VT(t,e){const n=GT(t,e),r=t.slice(n.length);return[n,r]}function eB(t,e){const n=t>=e.firstPositive,r=UT(t,e),s=t[t.length-1]===e.mostPositive,o=r[r.length-1]===e.mostPositive;return n&&o?r+e.mostNegative:!n&&s?t.slice(0,t.length-1):r}function tB(t,e){const n=t>=e.firstPositive,r=t[t.length-1]===e.mostNegative;if(n&&r){const s=t.slice(0,t.length-1);return Xv(s,e)}return!n&&r?t+e.mostPositive:Xv(t,e)}function YT(t,e,n){const r=P0(t,n),s=e==="upper"?n.byCode[n.length-1]:n.byCode[0];return t+s.repeat(r-t.length)}function XT(t,e){const n=HT(Math.floor(Math.random()*e.jitterRange),e);return C0(t,n,e)}function nB(t,e,n){const r=t.padEnd(t.length+e,n.first);return XT(r,n)}function rB(t,e,n){const r=fp(t,n),s=WT(r,n);let o=0;if(e!==null){const a=Yv(t,e,n);a<n.jitterRange+1&&(o=Math.max(o,zC(a,n)))}const i=Yv(t,s,n);return i<n.jitterRange+1&&(o=Math.max(o,zC(i,n))),o}function zC(t,e){const n=e.jitterRange-t,r=Object.entries(e.paddingDict).find(([s,o])=>o>n);return r?parseInt(r[0]):0}function sB(t,e,n=b0()){if(t!==null&&NC(t,n),e!==null&&NC(e,n),t===null&&e===null)return Z9(n);if(t===null){const r=fp(e,n);return J9(r,n)}if(e===null){const r=fp(t,n);return WT(r,n)}if(t>=e)throw new Error(t+" >= "+e);return X9(t,e,n)}function qT(t,e,n=b0()){const r=sB(t,e,n),s=rB(r,e,n);return s?nB(r,s,n):XT(r,n)}function ZT(t,e,n,r=b0()){return oB(t,e,n,r,qT,ZT)}function oB(t,e,n,r,s,o){if(n===0)return[];if(n===1)return[s(t,e,r)];if(e==null){let l=s(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=s(l,e,r),c.push(l);return c}if(t==null){let l=s(t,e,r);const c=[l];for(let u=0;u<n-1;u++)l=s(t,l,r),c.push(l);return c.reverse(),c}const i=Math.floor(n/2),a=s(t,e,r);return[...o(t,a,i,r),a,...o(a,e,n-i-1,r)]}const Vl=ZT,QT="a0";function iB(t){try{qT(t,null)}catch{throw new Error("invalid index: "+t)}}function Dl(t,e,n){return Vl(t??null,e??null,n)}function my(t,e){return Vl(t??null,null,e)}function $u(t,e){return Vl(t??null,e??null,1)[0]}function _s(t=null){return Vl(t,null,1)[0]}function aB(t=null){return Vl(null,t,1)[0]}function Fu(t,e="a1"){return[e,...Vl(e,null,t)]}function cn(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function lB(t,e){return t.id>e.id?1:-1}function _0(t){try{return localStorage.getItem(t)}catch{return null}}function I0(t,e){try{localStorage.setItem(t,e)}catch{}}function cB(){try{localStorage.clear()}catch{}}function JT(t){try{return sessionStorage.getItem(t)}catch{return null}}function E0(t,e){try{sessionStorage.setItem(t,e)}catch{}}function eM(t){try{sessionStorage.removeItem(t)}catch{}}function uB(){try{sessionStorage.clear()}catch{}}const ol=[],dB=60,nf=Math.ceil(1e3/dB);let wc,yy=0,qv=0;const hB=()=>{const t=ol.splice(0,ol.length);for(const e of t)e()};function tM(){if(wc)return;const t=Date.now(),e=t-qv;if(yy+e<nf){wc=requestAnimationFrame(()=>{wc=void 0,tM()});return}wc=requestAnimationFrame(()=>{wc=void 0,qv=t,yy=Math.min(yy+e-nf,nf*10),hB()})}let BC=!1;function nM(t){return ol.includes(t)||(ol.push(t),BC||(BC=!0,qv=Date.now()-nf-1),tM()),()=>{const e=ol.indexOf(t);e>-1&&ol.splice(e,1)}}class fB{constructor(){I(this,"timeouts",new Map);I(this,"intervals",new Map);I(this,"rafs",new Map);this.setTimeout=this.setTimeout.bind(this),this.setInterval=this.setInterval.bind(this),this.requestAnimationFrame=this.requestAnimationFrame.bind(this),this.dispose=this.dispose.bind(this)}setTimeout(e,n,r,...s){const o=window.setTimeout(n,r,s),i=this.timeouts.get(e)??[];return this.timeouts.set(e,[...i,o]),o}setInterval(e,n,r,...s){const o=window.setInterval(n,r,s),i=this.intervals.get(e)??[];return this.intervals.set(e,[...i,o]),o}requestAnimationFrame(e,n){const r=window.requestAnimationFrame(n),s=this.rafs.get(e)??[];return this.rafs.set(e,[...s,r]),r}dispose(e){var n,r,s;(n=this.timeouts.get(e))==null||n.forEach(o=>clearTimeout(o)),(r=this.intervals.get(e))==null||r.forEach(o=>clearInterval(o)),(s=this.rafs.get(e))==null||s.forEach(o=>cancelAnimationFrame(o)),this.timeouts.delete(e),this.intervals.delete(e),this.rafs.delete(e)}disposeAll(){for(const e of this.timeouts.keys())this.dispose(e)}forContext(e){return{setTimeout:(n,r,...s)=>this.setTimeout(e,n,r,s),setInterval:(n,r,...s)=>this.setInterval(e,n,r,s),requestAnimationFrame:n=>this.requestAnimationFrame(e,n),dispose:()=>this.dispose(e)}}}const ge=(t,e)=>{try{return new URL(t,e)}catch{return}};function pB(t){return t!==void 0}function gB(){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]:[t=>t&&JSON.parse(JSON.stringify(t)),!1]}const rM=gB(),nt=rM[0];rM[1];const mB=Object.getPrototypeOf(nt({}));_i("@tldraw/utils","3.7.2","esm");var bc=function(t){return t&&t.Math===Math&&t},In=bc(typeof globalThis=="object"&&globalThis)||bc(typeof window=="object"&&window)||bc(typeof self=="object"&&self)||bc(typeof dn=="object"&&dn)||bc(typeof dn=="object"&&dn)||function(){return this}()||Function("return this")(),k0={},En=function(t){try{return!!t()}catch{return!0}},yB=En,Ii=!yB(function(){return Object.defineProperty({},1,{get:function(){return 7}})[1]!==7}),SB=En,bg=!SB(function(){var t=(function(){}).bind();return typeof t!="function"||t.hasOwnProperty("prototype")}),vB=bg,nh=Function.prototype.call,Io=vB?nh.bind(nh):function(){return nh.apply(nh,arguments)},sM={},oM={}.propertyIsEnumerable,iM=Object.getOwnPropertyDescriptor,xB=iM&&!oM.call({1:2},1);sM.f=xB?function(e){var n=iM(this,e);return!!n&&n.enumerable}:oM;var aM=function(t,e){return{enumerable:!(t&1),configurable:!(t&2),writable:!(t&4),value:e}},lM=bg,cM=Function.prototype,Zv=cM.call,wB=lM&&cM.bind.bind(Zv,Zv),Lt=lM?wB:function(t){return function(){return Zv.apply(t,arguments)}},uM=Lt,bB=uM({}.toString),PB=uM("".slice),Yl=function(t){return PB(bB(t),8,-1)},CB=Lt,_B=En,IB=Yl,Sy=Object,EB=CB("".split),kB=_B(function(){return!Sy("z").propertyIsEnumerable(0)})?function(t){return IB(t)==="String"?EB(t,""):Sy(t)}:Sy,Pg=function(t){return t==null},TB=Pg,MB=TypeError,Xl=function(t){if(TB(t))throw new MB("Can't call method on "+t);return t},AB=kB,jB=Xl,Cg=function(t){return AB(jB(t))},vy=typeof document=="object"&&document.all,kn=typeof vy>"u"&&vy!==void 0?function(t){return typeof t=="function"||t===vy}:function(t){return typeof t=="function"},OB=kn,Pa=function(t){return typeof t=="object"?t!==null:OB(t)},xy=In,DB=kn,RB=function(t){return DB(t)?t:void 0},_g=function(t,e){return arguments.length<2?RB(xy[t]):xy[t]&&xy[t][e]},LB=Lt,dM=LB({}.isPrototypeOf),$B=In,UC=$B.navigator,HC=UC&&UC.userAgent,FB=HC?String(HC):"",hM=In,wy=FB,KC=hM.process,WC=hM.Deno,GC=KC&&KC.versions||WC&&WC.version,VC=GC&&GC.v8,Xr,pp;VC&&(Xr=VC.split("."),pp=Xr[0]>0&&Xr[0]<4?1:+(Xr[0]+Xr[1]));!pp&&wy&&(Xr=wy.match(/Edge\/(\d+)/),(!Xr||Xr[1]>=74)&&(Xr=wy.match(/Chrome\/(\d+)/),Xr&&(pp=+Xr[1])));var NB=pp,YC=NB,zB=En,BB=In,UB=BB.String,fM=!!Object.getOwnPropertySymbols&&!zB(function(){var t=Symbol("symbol detection");return!UB(t)||!(Object(t)instanceof Symbol)||!Symbol.sham&&YC&&YC<41}),HB=fM,pM=HB&&!Symbol.sham&&typeof Symbol.iterator=="symbol",KB=_g,WB=kn,GB=dM,VB=pM,YB=Object,gM=VB?function(t){return typeof t=="symbol"}:function(t){var e=KB("Symbol");return WB(e)&&GB(e.prototype,YB(t))},XB=String,qB=function(t){try{return XB(t)}catch{return"Object"}},ZB=kn,QB=qB,JB=TypeError,T0=function(t){if(ZB(t))return t;throw new JB(QB(t)+" is not a function")},e7=T0,t7=Pg,M0=function(t,e){var n=t[e];return t7(n)?void 0:e7(n)},by=Io,Py=kn,Cy=Pa,n7=TypeError,r7=function(t,e){var n,r;if(e==="string"&&Py(n=t.toString)&&!Cy(r=by(n,t))||Py(n=t.valueOf)&&!Cy(r=by(n,t))||e!=="string"&&Py(n=t.toString)&&!Cy(r=by(n,t)))return r;throw new n7("Can't convert object to primitive value")},mM={exports:{}},XC=In,s7=Object.defineProperty,A0=function(t,e){try{s7(XC,t,{value:e,configurable:!0,writable:!0})}catch{XC[t]=e}return e},o7=In,i7=A0,qC="__core-js_shared__",ZC=mM.exports=o7[qC]||i7(qC,{});(ZC.versions||(ZC.versions=[])).push({version:"3.40.0",mode:"global",copyright:"© 2014-2025 Denis Pushkarev (zloirock.ru)",license:"https://github.com/zloirock/core-js/blob/v3.40.0/LICENSE",source:"https://github.com/zloirock/core-js"});var j0=mM.exports,QC=j0,O0=function(t,e){return QC[t]||(QC[t]=e||{})},a7=Xl,l7=Object,od=function(t){return l7(a7(t))},c7=Lt,u7=od,d7=c7({}.hasOwnProperty),Ei=Object.hasOwn||function(e,n){return d7(u7(e),n)},h7=Lt,f7=0,p7=Math.random(),g7=h7(1 .toString),yM=function(t){return"Symbol("+(t===void 0?"":t)+")_"+g7(++f7+p7,36)},m7=In,y7=O0,JC=Ei,S7=yM,v7=fM,x7=pM,il=m7.Symbol,_y=y7("wks"),w7=x7?il.for||il:il&&il.withoutSetter||S7,Eo=function(t){return JC(_y,t)||(_y[t]=v7&&JC(il,t)?il[t]:w7("Symbol."+t)),_y[t]},b7=Io,e_=Pa,t_=gM,P7=M0,C7=r7,_7=Eo,I7=TypeError,E7=_7("toPrimitive"),k7=function(t,e){if(!e_(t)||t_(t))return t;var n=P7(t,E7),r;if(n){if(e===void 0&&(e="default"),r=b7(n,t,e),!e_(r)||t_(r))return r;throw new I7("Can't convert object to primitive value")}return e===void 0&&(e="number"),C7(t,e)},T7=k7,M7=gM,SM=function(t){var e=T7(t,"string");return M7(e)?e:e+""},A7=In,n_=Pa,Qv=A7.document,j7=n_(Qv)&&n_(Qv.createElement),vM=function(t){return j7?Qv.createElement(t):{}},O7=Ii,D7=En,R7=vM,xM=!O7&&!D7(function(){return Object.defineProperty(R7("div"),"a",{get:function(){return 7}}).a!==7}),L7=Ii,$7=Io,F7=sM,N7=aM,z7=Cg,B7=SM,U7=Ei,H7=xM,r_=Object.getOwnPropertyDescriptor;k0.f=L7?r_:function(e,n){if(e=z7(e),n=B7(n),H7)try{return r_(e,n)}catch{}if(U7(e,n))return N7(!$7(F7.f,e,n),e[n])};var ql={},K7=Ii,W7=En,wM=K7&&W7(function(){return Object.defineProperty(function(){},"prototype",{value:42,writable:!1}).prototype!==42}),G7=Pa,V7=String,Y7=TypeError,Ca=function(t){if(G7(t))return t;throw new Y7(V7(t)+" is not an object")},X7=Ii,q7=xM,Z7=wM,rh=Ca,s_=SM,Q7=TypeError,Iy=Object.defineProperty,J7=Object.getOwnPropertyDescriptor,Ey="enumerable",ky="configurable",Ty="writable";ql.f=X7?Z7?function(e,n,r){if(rh(e),n=s_(n),rh(r),typeof e=="function"&&n==="prototype"&&"value"in r&&Ty in r&&!r[Ty]){var s=J7(e,n);s&&s[Ty]&&(e[n]=r.value,r={configurable:ky in r?r[ky]:s[ky],enumerable:Ey in r?r[Ey]:s[Ey],writable:!1})}return Iy(e,n,r)}:Iy:function(e,n,r){if(rh(e),n=s_(n),rh(r),q7)try{return Iy(e,n,r)}catch{}if("get"in r||"set"in r)throw new Q7("Accessors not supported");return"value"in r&&(e[n]=r.value),e};var eU=Ii,tU=ql,nU=aM,D0=eU?function(t,e,n){return tU.f(t,e,nU(1,n))}:function(t,e,n){return t[e]=n,t},bM={exports:{}},Jv=Ii,rU=Ei,PM=Function.prototype,sU=Jv&&Object.getOwnPropertyDescriptor,R0=rU(PM,"name"),oU=R0&&(function(){}).name==="something",iU=R0&&(!Jv||Jv&&sU(PM,"name").configurable),aU={EXISTS:R0,PROPER:oU,CONFIGURABLE:iU},lU=Lt,cU=kn,ex=j0,uU=lU(Function.toString);cU(ex.inspectSource)||(ex.inspectSource=function(t){return uU(t)});var CM=ex.inspectSource,dU=In,hU=kn,o_=dU.WeakMap,fU=hU(o_)&&/native code/.test(String(o_)),pU=O0,gU=yM,i_=pU("keys"),_M=function(t){return i_[t]||(i_[t]=gU(t))},L0={},mU=fU,IM=In,yU=Pa,SU=D0,My=Ei,Ay=j0,vU=_M,xU=L0,a_="Object already initialized",tx=IM.TypeError,wU=IM.WeakMap,gp,Nu,mp,bU=function(t){return mp(t)?Nu(t):gp(t,{})},PU=function(t){return function(e){var n;if(!yU(e)||(n=Nu(e)).type!==t)throw new tx("Incompatible receiver, "+t+" required");return n}};if(mU||Ay.state){var ms=Ay.state||(Ay.state=new wU);ms.get=ms.get,ms.has=ms.has,ms.set=ms.set,gp=function(t,e){if(ms.has(t))throw new tx(a_);return e.facade=t,ms.set(t,e),e},Nu=function(t){return ms.get(t)||{}},mp=function(t){return ms.has(t)}}else{var Aa=vU("state");xU[Aa]=!0,gp=function(t,e){if(My(t,Aa))throw new tx(a_);return e.facade=t,SU(t,Aa,e),e},Nu=function(t){return My(t,Aa)?t[Aa]:{}},mp=function(t){return My(t,Aa)}}var EM={set:gp,get:Nu,has:mp,enforce:bU,getterFor:PU},$0=Lt,CU=En,_U=kn,sh=Ei,nx=Ii,IU=aU.CONFIGURABLE,EU=CM,kM=EM,kU=kM.enforce,TU=kM.get,l_=String,rf=Object.defineProperty,MU=$0("".slice),AU=$0("".replace),jU=$0([].join),OU=nx&&!CU(function(){return rf(function(){},"length",{value:8}).length!==8}),DU=String(String).split("String"),RU=bM.exports=function(t,e,n){MU(l_(e),0,7)==="Symbol("&&(e="["+AU(l_(e),/^Symbol\(([^)]*)\).*$/,"$1")+"]"),n&&n.getter&&(e="get "+e),n&&n.setter&&(e="set "+e),(!sh(t,"name")||IU&&t.name!==e)&&(nx?rf(t,"name",{value:e,configurable:!0}):t.name=e),OU&&n&&sh(n,"arity")&&t.length!==n.arity&&rf(t,"length",{value:n.arity});try{n&&sh(n,"constructor")&&n.constructor?nx&&rf(t,"prototype",{writable:!1}):t.prototype&&(t.prototype=void 0)}catch{}var r=kU(t);return sh(r,"source")||(r.source=jU(DU,typeof e=="string"?e:"")),t};Function.prototype.toString=RU(function(){return _U(this)&&TU(this).source||EU(this)},"toString");var LU=bM.exports,$U=kn,FU=ql,NU=LU,zU=A0,TM=function(t,e,n,r){r||(r={});var s=r.enumerable,o=r.name!==void 0?r.name:e;if($U(n)&&NU(n,o,r),r.global)s?t[e]=n:zU(e,n);else{try{r.unsafe?t[e]&&(s=!0):delete t[e]}catch{}s?t[e]=n:FU.f(t,e,{value:n,enumerable:!1,configurable:!r.nonConfigurable,writable:!r.nonWritable})}return t},MM={},BU=Math.ceil,UU=Math.floor,HU=Math.trunc||function(e){var n=+e;return(n>0?UU:BU)(n)},KU=HU,_a=function(t){var e=+t;return e!==e||e===0?0:KU(e)},WU=_a,GU=Math.max,VU=Math.min,YU=function(t,e){var n=WU(t);return n<0?GU(n+e,0):VU(n,e)},XU=_a,qU=Math.min,AM=function(t){var e=XU(t);return e>0?qU(e,9007199254740991):0},ZU=AM,id=function(t){return ZU(t.length)},QU=Cg,JU=YU,eH=id,c_=function(t){return function(e,n,r){var s=QU(e),o=eH(s);if(o===0)return!t&&-1;var i=JU(r,o),a;if(t&&n!==n){for(;o>i;)if(a=s[i++],a!==a)return!0}else for(;o>i;i++)if((t||i in s)&&s[i]===n)return t||i||0;return!t&&-1}},tH={includes:c_(!0),indexOf:c_(!1)},nH=Lt,jy=Ei,rH=Cg,sH=tH.indexOf,oH=L0,u_=nH([].push),jM=function(t,e){var n=rH(t),r=0,s=[],o;for(o in n)!jy(oH,o)&&jy(n,o)&&u_(s,o);for(;e.length>r;)jy(n,o=e[r++])&&(~sH(s,o)||u_(s,o));return s},F0=["constructor","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","toLocaleString","toString","valueOf"],iH=jM,aH=F0,lH=aH.concat("length","prototype");MM.f=Object.getOwnPropertyNames||function(e){return iH(e,lH)};var OM={};OM.f=Object.getOwnPropertySymbols;var cH=_g,uH=Lt,dH=MM,hH=OM,fH=Ca,pH=uH([].concat),gH=cH("Reflect","ownKeys")||function(e){var n=dH.f(fH(e)),r=hH.f;return r?pH(n,r(e)):n},d_=Ei,mH=gH,yH=k0,SH=ql,vH=function(t,e,n){for(var r=mH(e),s=SH.f,o=yH.f,i=0;i<r.length;i++){var a=r[i];!d_(t,a)&&!(n&&d_(n,a))&&s(t,a,o(e,a))}},xH=En,wH=kn,bH=/#|\.prototype\./,ad=function(t,e){var n=CH[PH(t)];return n===IH?!0:n===_H?!1:wH(e)?xH(e):!!e},PH=ad.normalize=function(t){return String(t).replace(bH,".").toLowerCase()},CH=ad.data={},_H=ad.NATIVE="N",IH=ad.POLYFILL="P",EH=ad,oh=In,kH=k0.f,TH=D0,MH=TM,AH=A0,jH=vH,OH=EH,Zl=function(t,e){var n=t.target,r=t.global,s=t.stat,o,i,a,l,c,u;if(r?i=oh:s?i=oh[n]||AH(n,{}):i=oh[n]&&oh[n].prototype,i)for(a in e){if(c=e[a],t.dontCallGetSet?(u=kH(i,a),l=u&&u.value):l=i[a],o=OH(r?a:n+(s?".":"#")+a,t.forced),!o&&l!==void 0){if(typeof c==typeof l)continue;jH(c,l)}(t.sham||l&&l.sham)&&TH(c,"sham",!0),MH(i,a,c,t)}},DM={},DH=jM,RH=F0,LH=Object.keys||function(e){return DH(e,RH)},$H=Ii,FH=wM,NH=ql,zH=Ca,BH=Cg,UH=LH;DM.f=$H&&!FH?Object.defineProperties:function(e,n){zH(e);for(var r=BH(n),s=UH(n),o=s.length,i=0,a;o>i;)NH.f(e,a=s[i++],r[a]);return e};var HH=_g,KH=HH("document","documentElement"),WH=Ca,GH=DM,h_=F0,VH=L0,YH=KH,XH=vM,qH=_M,f_=">",p_="<",rx="prototype",sx="script",RM=qH("IE_PROTO"),Oy=function(){},LM=function(t){return p_+sx+f_+t+p_+"/"+sx+f_},g_=function(t){t.write(LM("")),t.close();var e=t.parentWindow.Object;return t=null,e},ZH=function(){var t=XH("iframe"),e="java"+sx+":",n;return t.style.display="none",YH.appendChild(t),t.src=String(e),n=t.contentWindow.document,n.open(),n.write(LM("document.F=Object")),n.close(),n.F},ih,sf=function(){try{ih=new ActiveXObject("htmlfile")}catch{}sf=typeof document<"u"?document.domain&&ih?g_(ih):ZH():g_(ih);for(var t=h_.length;t--;)delete sf[rx][h_[t]];return sf()};VH[RM]=!0;var $M=Object.create||function(e,n){var r;return e!==null?(Oy[rx]=WH(e),r=new Oy,Oy[rx]=null,r[RM]=e):r=sf(),n===void 0?r:GH.f(r,n)},QH=Eo,JH=$M,eK=ql.f,ox=QH("unscopables"),ix=Array.prototype;ix[ox]===void 0&&eK(ix,ox,{configurable:!0,value:JH(null)});var N0=function(t){ix[ox][t]=!0},tK=Zl,nK=od,rK=id,sK=_a,oK=N0;tK({target:"Array",proto:!0},{at:function(e){var n=nK(this),r=rK(n),s=sK(e),o=s>=0?s:r+s;return o<0||o>=r?void 0:n[o]}});oK("at");var iK=In,aK=Lt,ld=function(t,e){return aK(iK[t].prototype[e])},lK=ld;lK("Array","at");var cK=Yl,FM=Array.isArray||function(e){return cK(e)==="Array"},uK=TypeError,dK=9007199254740991,hK=function(t){if(t>dK)throw uK("Maximum allowed index exceeded");return t},fK=Yl,pK=Lt,gK=function(t){if(fK(t)==="Function")return pK(t)},m_=gK,mK=T0,yK=bg,SK=m_(m_.bind),vK=function(t,e){return mK(t),e===void 0?t:yK?SK(t,e):function(){return t.apply(e,arguments)}},xK=FM,wK=id,bK=hK,PK=vK,NM=function(t,e,n,r,s,o,i,a){for(var l=s,c=0,u=i?PK(i,a):!1,h,f;c<r;)c in n&&(h=u?u(n[c],c,e):n[c],o>0&&xK(h)?(f=wK(h),l=NM(t,e,h,f,l,o-1)-1):(bK(l+1),t[l]=h),l++),c++;return l},zM=NM,CK=Eo,_K=CK("toStringTag"),BM={};BM[_K]="z";var IK=String(BM)==="[object z]",EK=IK,kK=kn,of=Yl,TK=Eo,MK=TK("toStringTag"),AK=Object,jK=of(function(){return arguments}())==="Arguments",OK=function(t,e){try{return t[e]}catch{}},UM=EK?of:function(t){var e,n,r;return t===void 0?"Undefined":t===null?"Null":typeof(n=OK(e=AK(t),MK))=="string"?n:jK?of(e):(r=of(e))==="Object"&&kK(e.callee)?"Arguments":r},DK=Lt,RK=En,HM=kn,LK=UM,$K=_g,FK=CM,KM=function(){},WM=$K("Reflect","construct"),z0=/^\s*(?:class|function)\b/,NK=DK(z0.exec),zK=!z0.test(KM),Pc=function(e){if(!HM(e))return!1;try{return WM(KM,[],e),!0}catch{return!1}},GM=function(e){if(!HM(e))return!1;switch(LK(e)){case"AsyncFunction":case"GeneratorFunction":case"AsyncGeneratorFunction":return!1}try{return zK||!!NK(z0,FK(e))}catch{return!0}};GM.sham=!0;var BK=!WM||RK(function(){var t;return Pc(Pc.call)||!Pc(Object)||!Pc(function(){t=!0})||t})?GM:Pc,y_=FM,UK=BK,HK=Pa,KK=Eo,WK=KK("species"),S_=Array,GK=function(t){var e;return y_(t)&&(e=t.constructor,UK(e)&&(e===S_||y_(e.prototype))?e=void 0:HK(e)&&(e=e[WK],e===null&&(e=void 0))),e===void 0?S_:e},VK=GK,VM=function(t,e){return new(VK(t))(e===0?0:e)},YK=Zl,XK=zM,qK=T0,ZK=od,QK=id,JK=VM;YK({target:"Array",proto:!0},{flatMap:function(e){var n=ZK(this),r=QK(n),s;return qK(e),s=JK(n,0),s.length=XK(s,n,n,r,0,1,e,arguments.length>1?arguments[1]:void 0),s}});var eW=N0;eW("flatMap");var tW=ld;tW("Array","flatMap");var nW=Zl,rW=zM,sW=od,oW=id,iW=_a,aW=VM;nW({target:"Array",proto:!0},{flat:function(){var e=arguments.length?arguments[0]:void 0,n=sW(this),r=oW(n),s=aW(n,0);return s.length=rW(s,n,n,r,0,e===void 0?1:iW(e)),s}});var lW=N0;lW("flat");var cW=ld;cW("Array","flat");var uW=UM,dW=String,cd=function(t){if(uW(t)==="Symbol")throw new TypeError("Cannot convert a Symbol value to a string");return dW(t)},hW=Zl,fW=Lt,pW=Xl,gW=_a,mW=cd,yW=En,SW=fW("".charAt),vW=yW(function(){return"𠮷".at(-2)!=="\uD842"});hW({target:"String",proto:!0,forced:vW},{at:function(e){var n=mW(pW(this)),r=n.length,s=gW(e),o=s>=0?s:r+s;return o<0||o>=r?void 0:SW(n,o)}});var xW=ld;xW("String","at");var wW=Ca,YM=function(){var t=wW(this),e="";return t.hasIndices&&(e+="d"),t.global&&(e+="g"),t.ignoreCase&&(e+="i"),t.multiline&&(e+="m"),t.dotAll&&(e+="s"),t.unicode&&(e+="u"),t.unicodeSets&&(e+="v"),t.sticky&&(e+="y"),e},B0=En,bW=In,U0=bW.RegExp,H0=B0(function(){var t=U0("a","y");return t.lastIndex=2,t.exec("abcd")!==null}),PW=H0||B0(function(){return!U0("a","y").sticky}),CW=H0||B0(function(){var t=U0("^r","gy");return t.lastIndex=2,t.exec("str")!==null}),_W={BROKEN_CARET:CW,MISSED_STICKY:PW,UNSUPPORTED_Y:H0},IW=En,EW=In,kW=EW.RegExp,TW=IW(function(){var t=kW(".","s");return!(t.dotAll&&t.test(`
|
|
68
68
|
`)&&t.flags==="s")}),MW=En,AW=In,jW=AW.RegExp,OW=MW(function(){var t=jW("(?<a>b)","g");return t.exec("b").groups.a!=="b"||"b".replace(t,"$<a>c")!=="bc"}),al=Io,Ig=Lt,DW=cd,RW=YM,LW=_W,$W=O0,FW=$M,NW=EM.get,zW=TW,BW=OW,UW=$W("native-string-replace",String.prototype.replace),yp=RegExp.prototype.exec,ax=yp,HW=Ig("".charAt),KW=Ig("".indexOf),WW=Ig("".replace),Dy=Ig("".slice),lx=function(){var t=/a/,e=/b*/g;return al(yp,t,"a"),al(yp,e,"a"),t.lastIndex!==0||e.lastIndex!==0}(),XM=LW.BROKEN_CARET,cx=/()??/.exec("")[1]!==void 0,GW=lx||cx||XM||zW||BW;GW&&(ax=function(e){var n=this,r=NW(n),s=DW(e),o=r.raw,i,a,l,c,u,h,f;if(o)return o.lastIndex=n.lastIndex,i=al(ax,o,s),n.lastIndex=o.lastIndex,i;var p=r.groups,g=XM&&n.sticky,m=al(RW,n),v=n.source,y=0,S=s;if(g&&(m=WW(m,"y",""),KW(m,"g")===-1&&(m+="g"),S=Dy(s,n.lastIndex),n.lastIndex>0&&(!n.multiline||n.multiline&&HW(s,n.lastIndex-1)!==`
|
|
69
69
|
`)&&(v="(?: "+v+")",S=" "+S,y++),a=new RegExp("^(?:"+v+")",m)),cx&&(a=new RegExp("^"+v+"$(?!\\s)",m)),lx&&(l=n.lastIndex),c=al(yp,g?a:n,S),g?c?(c.input=Dy(c.input,y),c[0]=Dy(c[0],y),c.index=n.lastIndex,n.lastIndex+=c[0].length):n.lastIndex=0:lx&&c&&(n.lastIndex=n.global?c.index+c[0].length:l),cx&&c&&c.length>1&&al(UW,c[0],a,function(){for(u=1;u<arguments.length-2;u++)arguments[u]===void 0&&(c[u]=void 0)}),c&&p)for(c.groups=h=FW(null),u=0;u<p.length;u++)f=p[u],h[f[0]]=c[f[1]];return c});var K0=ax,VW=Zl,v_=K0;VW({target:"RegExp",proto:!0,forced:/./.exec!==v_},{exec:v_});var YW=bg,qM=Function.prototype,x_=qM.apply,w_=qM.call,XW=typeof Reflect=="object"&&Reflect.apply||(YW?w_.bind(x_):function(){return w_.apply(x_,arguments)}),b_=Io,P_=TM,qW=K0,C_=En,ZM=Eo,ZW=D0,QW=ZM("species"),Ry=RegExp.prototype,JW=function(t,e,n,r){var s=ZM(t),o=!C_(function(){var c={};return c[s]=function(){return 7},""[t](c)!==7}),i=o&&!C_(function(){var c=!1,u=/a/;return t==="split"&&(u={},u.constructor={},u.constructor[QW]=function(){return u},u.flags="",u[s]=/./[s]),u.exec=function(){return c=!0,null},u[s](""),!c});if(!o||!i||n){var a=/./[s],l=e(s,""[t],function(c,u,h,f,p){var g=u.exec;return g===qW||g===Ry.exec?o&&!p?{done:!0,value:b_(a,u,h,f)}:{done:!0,value:b_(c,h,u,f)}:{done:!1}});P_(String.prototype,t,l[0]),P_(Ry,s,l[1])}r&&ZW(Ry[s],"sham",!0)},W0=Lt,eG=_a,tG=cd,nG=Xl,rG=W0("".charAt),__=W0("".charCodeAt),sG=W0("".slice),I_=function(t){return function(e,n){var r=tG(nG(e)),s=eG(n),o=r.length,i,a;return s<0||s>=o?t?"":void 0:(i=__(r,s),i<55296||i>56319||s+1===o||(a=__(r,s+1))<56320||a>57343?t?rG(r,s):i:t?sG(r,s,s+2):(i-55296<<10)+(a-56320)+65536)}},oG={codeAt:I_(!1),charAt:I_(!0)},iG=oG.charAt,aG=function(t,e,n){return e+(n?iG(t,e).length:1)},G0=Lt,lG=od,cG=Math.floor,Ly=G0("".charAt),uG=G0("".replace),$y=G0("".slice),dG=/\$([$&'`]|\d{1,2}|<[^>]*>)/g,hG=/\$([$&'`]|\d{1,2})/g,QM=function(t,e,n,r,s,o){var i=n+t.length,a=r.length,l=hG;return s!==void 0&&(s=lG(s),l=dG),uG(o,l,function(c,u){var h;switch(Ly(u,0)){case"$":return"$";case"&":return t;case"`":return $y(e,0,n);case"'":return $y(e,i);case"<":h=s[$y(u,1,-1)];break;default:var f=+u;if(f===0)return c;if(f>a){var p=cG(f/10);return p===0?c:p<=a?r[p-1]===void 0?Ly(u,1):r[p-1]+Ly(u,1):c}h=r[f-1]}return h===void 0?"":h})},E_=Io,fG=Ca,pG=kn,gG=Yl,mG=K0,yG=TypeError,SG=function(t,e){var n=t.exec;if(pG(n)){var r=E_(n,t,e);return r!==null&&fG(r),r}if(gG(t)==="RegExp")return E_(mG,t,e);throw new yG("RegExp#exec called on incompatible receiver")},vG=XW,k_=Io,Eg=Lt,xG=JW,wG=En,bG=Ca,PG=kn,CG=Pg,_G=_a,IG=AM,ja=cd,EG=Xl,kG=aG,TG=M0,MG=QM,AG=SG,jG=Eo,ux=jG("replace"),OG=Math.max,DG=Math.min,RG=Eg([].concat),Fy=Eg([].push),T_=Eg("".indexOf),M_=Eg("".slice),LG=function(t){return t===void 0?t:String(t)},$G=function(){return"a".replace(/./,"$0")==="$0"}(),A_=function(){return/./[ux]?/./[ux]("a","$0")==="":!1}(),FG=!wG(function(){var t=/./;return t.exec=function(){var e=[];return e.groups={a:"7"},e},"".replace(t,"$<a>")!=="7"});xG("replace",function(t,e,n){var r=A_?"$":"$0";return[function(o,i){var a=EG(this),l=CG(o)?void 0:TG(o,ux);return l?k_(l,o,a,i):k_(e,ja(a),o,i)},function(s,o){var i=bG(this),a=ja(s);if(typeof o=="string"&&T_(o,r)===-1&&T_(o,"$<")===-1){var l=n(e,i,a,o);if(l.done)return l.value}var c=PG(o);c||(o=ja(o));var u=i.global,h;u&&(h=i.unicode,i.lastIndex=0);for(var f=[],p;p=AG(i,a),!(p===null||(Fy(f,p),!u));){var g=ja(p[0]);g===""&&(i.lastIndex=kG(a,IG(i.lastIndex),h))}for(var m="",v=0,y=0;y<f.length;y++){p=f[y];for(var S=ja(p[0]),b=OG(DG(_G(p.index),a.length),0),P=[],C,_=1;_<p.length;_++)Fy(P,LG(p[_]));var E=p.groups;if(c){var k=RG([S],P,b,a);E!==void 0&&Fy(k,E),C=ja(vG(o,void 0,k))}else C=MG(S,a,b,P,E,o);b>=v&&(m+=M_(a,v,b)+C,v=b+S.length)}return m+M_(a,v)}]},!FG||!$G||A_);var NG=Pa,zG=Yl,BG=Eo,UG=BG("match"),HG=function(t){var e;return NG(t)&&((e=t[UG])!==void 0?!!e:zG(t)==="RegExp")},KG=Io,WG=Ei,GG=dM,VG=YM,j_=RegExp.prototype,YG=function(t){var e=t.flags;return e===void 0&&!("flags"in j_)&&!WG(t,"flags")&&GG(j_,t)?KG(VG,t):e},XG=Zl,qG=Io,V0=Lt,O_=Xl,ZG=kn,QG=Pg,JG=HG,Cc=cd,eV=M0,tV=YG,nV=QM,rV=Eo,sV=rV("replace"),oV=TypeError,Ny=V0("".indexOf);V0("".replace);var D_=V0("".slice),iV=Math.max;XG({target:"String",proto:!0},{replaceAll:function(e,n){var r=O_(this),s,o,i,a,l,c,u,h,f,p,g=0,m="";if(!QG(e)){if(s=JG(e),s&&(o=Cc(O_(tV(e))),!~Ny(o,"g")))throw new oV("`.replaceAll` does not allow non-global regexes");if(i=eV(e,sV),i)return qG(i,e,r,n)}for(a=Cc(r),l=Cc(e),c=ZG(n),c||(n=Cc(n)),u=l.length,h=iV(1,u),f=Ny(a,l);f!==-1;)p=c?Cc(n(l,f,a)):nV(l,a,f,[],void 0,n),m+=D_(a,g,f)+p,g=f+u,f=f+h>a.length?-1:Ny(a,l,f+h);return g<a.length&&(m+=D_(a,g)),m}});var aV=ld;aV("String","replaceAll");function JM(t){return t&&typeof t=="object"&&"parents"in t}function eA(t){for(let e=0,n=t.parents.length;e<n;e++)if(t.parents[e].__unsafe__getWithoutCapture(!0),t.parents[e].lastChangedEpoch!==t.parentEpochs[e])return!0;return!1}function Sp(t,e){if(t.children.remove(e)&&t.children.isEmpty&&JM(t))for(let n=0,r=t.parents.length;n<r;n++)Sp(t.parents[n],t)}function Y0(t,e){if(t.children.add(e)&&JM(t))for(let n=0,r=t.parents.length;n<r;n++)Y0(t.parents[n],t)}function tA(t,e){return t===e||Object.is(t,e)||!!(t&&e&&typeof t.equals=="function"&&t.equals(e))}function ki(t,e){const n=Symbol.for(`com.tldraw.state/${t}`),r=globalThis;return r[n]??(r[n]=e()),r[n]}const fo=ki("empty_array",()=>Object.freeze([])),R_=8;class vp{constructor(){I(this,"arraySize",0);I(this,"array",Array(R_));I(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(e){if(this.array)return this.array.indexOf(e)!==-1?!1:this.arraySize<R_?(this.array[this.arraySize]=e,this.arraySize++,!0):(this.set=new Set(this.array),this.array=null,this.set.add(e),!0);if(this.set)return this.set.has(e)?!1:(this.set.add(e),!0);throw new Error("no set or array")}remove(e){if(this.array){const n=this.array.indexOf(e);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(e)?(this.set.delete(e),!0):!1;throw new Error("no set or array")}visit(e){if(this.array){for(let n=0;n<this.arraySize;n++){const r=this.array[n];typeof r<"u"&&e(r)}return}if(this.set){this.set.forEach(e);return}throw new Error("no set or array")}has(e){return this.array?this.array.indexOf(e)!==-1:this.set.has(e)}clear(){this.set?this.set.clear():(this.arraySize=0,this.array=[])}size(){return this.set?this.set.size:this.arraySize}}const ur=Symbol.for("com.tldraw.state/RESET_VALUE");class nA{constructor(e){I(this,"index",0);I(this,"buffer");this.capacity=e,this.buffer=new Array(e)}pushEntry(e,n,r){if(r!==void 0){if(r===ur){this.clear();return}this.buffer[this.index]=[e,n,r],this.index=(this.index+1)%this.capacity}}clear(){this.index=0,this.buffer.fill(void 0)}getChangesSince(e){const{index:n,capacity:r,buffer:s}=this;for(let o=0;o<r;o++){const i=(n-1+r-o)%r,a=s[i];if(!a)return ur;const[l,c]=a;if(o===0&&e>=c)return[];if(l<=e&&e<c){const u=o+1,h=new Array(u);for(let f=0;f<u;f++)h[f]=s[(i+f)%r][2];return h}}return ur}}class lV{constructor(e,n){I(this,"offset",0);I(this,"maybeRemoved");this.below=e,this.child=n}}const ot=ki("capture",()=>({stack:null}));function ah(t){const e=ot.stack;ot.stack=null;try{return t()}finally{ot.stack=e}}function rA(t){ot.stack=new lV(ot.stack,t),t.parentSet.clear()}function sA(){const t=ot.stack;if(ot.stack=t.below,t.offset<t.child.parents.length){for(let e=t.offset;e<t.child.parents.length;e++){const n=t.child.parents[e];t.child.parentSet.has(n)||Sp(n,t.child)}t.child.parents.length=t.offset,t.child.parentEpochs.length=t.offset}if(t.maybeRemoved)for(let e=0;e<t.maybeRemoved.length;e++){const n=t.maybeRemoved[e];t.child.parentSet.has(n)||Sp(n,t.child)}}function xp(t){if(ot.stack){if(ot.stack.child.parentSet.has(t))return;if(ot.stack.child.parentSet.add(t),ot.stack.child.isActivelyListening&&Y0(t,ot.stack.child),ot.stack.offset<ot.stack.child.parents.length){const n=ot.stack.child.parents[ot.stack.offset];n!==t&&(ot.stack.maybeRemoved?ot.stack.maybeRemoved.push(n):ot.stack.maybeRemoved=[n])}ot.stack.child.parents[ot.stack.offset]=t,ot.stack.child.parentEpochs[ot.stack.offset]=t.lastChangedEpoch,ot.stack.offset++}}const ei=-1;class cV{constructor(e,n,r){I(this,"_isActivelyListening",!1);I(this,"lastTraversedEpoch",ei);I(this,"lastReactedEpoch",ei);I(this,"_scheduleCount",0);I(this,"parentSet",new vp);I(this,"parentEpochs",[]);I(this,"parents",[]);I(this,"_scheduleEffect");I(this,"maybeExecute",()=>{this._isActivelyListening&&this.execute()});this.name=e,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!==$n()){if(this.parents.length&&!eA(this)){this.lastReactedEpoch=$n();return}this.scheduleEffect()}}scheduleEffect(){this._scheduleCount++,this._scheduleEffect?this._scheduleEffect(this.maybeExecute):this.execute()}attach(){this._isActivelyListening=!0;for(let e=0,n=this.parents.length;e<n;e++)Y0(this.parents[e],this)}detach(){this._isActivelyListening=!1;for(let e=0,n=this.parents.length;e<n;e++)Sp(this.parents[e],this)}execute(){try{rA(this);const e=$n(),n=this.runEffect(this.lastReactedEpoch);return this.lastReactedEpoch=e,n}finally{sA()}}}const Ql=ki("EffectScheduler",()=>cV);function As(t,e,n){const r=new Ql(t,e,n);return r.attach(),r.scheduleEffect(),()=>{r.detach()}}function uV(t,e,n){const r=new Ql(t,e,n);return{scheduler:r,start:s=>{const o=(s==null?void 0:s.force)??!1;r.attach(),o?r.scheduleEffect():r.maybeScheduleEffect()},stop:()=>{r.detach()}}}class dV{constructor(e){I(this,"initialAtomValues",new Map);this.parent=e}get isRoot(){return this.parent===null}commit(){if(Re.globalIsReacting)for(const e of this.initialAtomValues.keys())iA(e);else this.isRoot?oA(this.initialAtomValues.keys()):this.initialAtomValues.forEach((e,n)=>{this.parent.initialAtomValues.has(n)||this.parent.initialAtomValues.set(n,e)})}abort(){Re.globalEpoch++,this.initialAtomValues.forEach((e,n)=>{var r;n.set(e),(r=n.historyBuffer)==null||r.clear()}),this.commit()}}const Re=ki("transactions",()=>({globalEpoch:ei+1,globalIsReacting:!1,currentTransaction:null,cleanupReactors:null,reactionEpoch:ei+1}));function hV(){return Re.reactionEpoch}function $n(){return Re.globalEpoch}function fV(){return Re.globalIsReacting}function X0(t,e){e.lastTraversedEpoch!==Re.globalEpoch&&(e.lastTraversedEpoch=Re.globalEpoch,e instanceof Ql?t.add(e):e.children.visit(n=>X0(t,n)))}function oA(t){var n;if(Re.globalIsReacting)throw new Error("flushChanges cannot be called during a reaction");const e=Re.currentTransaction;try{Re.currentTransaction=null,Re.globalIsReacting=!0,Re.reactionEpoch=Re.globalEpoch;const r=new Set;for(const o of t)o.children.visit(i=>X0(r,i));for(const o of r)o.maybeScheduleEffect();let s=0;for(;(n=Re.cleanupReactors)!=null&&n.size;){if(s++>1e3)throw new Error("Reaction update depth limit exceeded");const o=Re.cleanupReactors;Re.cleanupReactors=null;for(const i of o)i.maybeScheduleEffect()}}finally{Re.cleanupReactors=null,Re.globalIsReacting=!1,Re.currentTransaction=e}}function pV(t,e){Re.currentTransaction?Re.currentTransaction.initialAtomValues.has(t)||Re.currentTransaction.initialAtomValues.set(t,e):Re.globalIsReacting?iA(t):oA([t])}function iA(t){const e=Re.cleanupReactors??(Re.cleanupReactors=new Set);t.children.visit(n=>X0(e,n))}function gV(){Re.globalEpoch++}function mV(t){const e=new dV(Re.currentTransaction);Re.currentTransaction=e;try{let n,r=!1;try{n=t(()=>r=!0)}catch(s){throw e.abort(),s}return r?e.abort():e.commit(),n}finally{Re.currentTransaction=Re.currentTransaction.parent}}function js(t){return Re.currentTransaction?t():mV(t)}class yV{constructor(e,n,r){I(this,"isEqual");I(this,"computeDiff");I(this,"lastChangedEpoch",$n());I(this,"children",new vp);I(this,"historyBuffer");this.name=e,this.current=n,this.isEqual=(r==null?void 0:r.isEqual)??null,r&&(r.historyLength&&(this.historyBuffer=new nA(r.historyLength)),this.computeDiff=r.computeDiff)}__unsafe__getWithoutCapture(e){return this.current}get(){return xp(this),this.current}set(e,n){var s,o;if(((s=this.isEqual)==null?void 0:s.call(this,this.current,e))??tA(this.current,e))return this.current;gV(),this.historyBuffer&&this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),n??((o=this.computeDiff)==null?void 0:o.call(this,this.current,e,this.lastChangedEpoch,$n()))??ur),this.lastChangedEpoch=$n();const r=this.current;return this.current=e,pV(this,r),e}update(e){return this.set(e(this.current))}getDiffSince(e){var n;return xp(this),e>=this.lastChangedEpoch?fo:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const SV=ki("Atom",()=>yV);function It(t,e,n){return new SV(t,e,n)}let L_=!1;function vV(){L_||(L_=!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.
|
|
70
70
|
|
|
@@ -79,13 +79,13 @@ get foo() {
|
|
|
79
79
|
getFoo() {
|
|
80
80
|
return 'foo'
|
|
81
81
|
}
|
|
82
|
-
`))}const Hc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Qi(t){return t===Hc}const dx=ki("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Kc(t,e){return new dx(t,e)}class xV{constructor(e,n,r){I(this,"lastChangedEpoch",ei);I(this,"lastTraversedEpoch",ei);I(this,"lastCheckedEpoch",ei);I(this,"parentSet",new vp);I(this,"parents",[]);I(this,"parentEpochs",[]);I(this,"children",new vp);I(this,"historyBuffer");I(this,"state",Hc);I(this,"error",null);I(this,"computeDiff");I(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new nA(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??tA}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var s;const n=this.lastChangedEpoch===ei,r=$n();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&fV()&&this.lastTraversedEpoch<hV()||!eA(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{rA(this);const o=this.derive(this.state,this.lastCheckedEpoch),i=o instanceof dx?o.value:o,a=this.state===Hc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=o instanceof dx?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,i,this.lastCheckedEpoch,$n()))??ur)}this.lastChangedEpoch=$n(),this.state=i}return this.error=null,this.lastCheckedEpoch=$n(),this.state}catch(o){if(this.state!==Hc&&(this.state=Hc,this.lastChangedEpoch=$n()),this.lastCheckedEpoch=$n(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!e)throw o;return this.state}finally{sA()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{xp(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),xp(this),e>=this.lastChangedEpoch?fo:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const kg=ki("Computed",()=>xV);function wV(t={},e,n,r){const s=r.value,o=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[o];return i||(i=new kg(n,s.bind(this),t),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[aA]=!0,r}function bV(t={},e,n,r){const s=r.get,o=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[o];return i||(i=new kg(n,s.bind(this),t),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function PV(t,e,n){Le(n.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(n.name)),s=function(){let o=this[r];return o||(o=new kg(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()};return s[aA]=!0,s}function $_(t={},e){if(e.length===2){const[n,r]=e;return PV(t,n,r)}else{const[n,r,s]=e;return s.get?(vV(),bV(t,n,r,s)):wV(t,n,r,s)}}const aA="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const t=arguments[0];return(...e)=>$_(t,e)}else return typeof arguments[0]=="string"?new kg(arguments[0],arguments[1],arguments[2]):$_(void 0,arguments)}const lA=1,CV=ki("apiVersion",()=>lA);if(CV!==lA)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");_i("@tldraw/state","3.8.0-canary.c422debb621c","esm");function Tg(t,e,n=[]){const r=ke.useRef(e);r.current=e;const[s,o,i]=ke.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),c=new Ql(`useStateTracking(${t})`,()=>{var h;return(h=r.current)==null?void 0:h.call(r)},{scheduleEffect(){a==null||a()}});return[c,l,()=>c.scheduleCount]},[t,...n]);return ke.useSyncExternalStore(o,i,i),ke.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const F_={apply(t,e,n){return Tg(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},_V=Symbol.for("react.memo"),IV=Symbol.for("react.forward_ref");function Zt(t){let e=null;const n=t.$$typeof;return n===_V&&(t=t.type,e=t.compare),n===IV?w.memo(w.forwardRef(new Proxy(t.render,F_))):w.memo(new Proxy(t,F_),e)}function q0(t,e,n){return w.useState(()=>{const r=typeof e=="function"?e():e;return It(`useAtom(${t})`,r,n)})[0]}function EV(){const t=arguments[0],e=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return w.useMemo(()=>G(`useComputed(${t})`,e,n),r)}function ui(t,e,n=fo){w.useEffect(()=>{const r=new Ql(t,e);return r.attach(),r.execute(),()=>{r.detach()}},n)}function U(){const t=arguments,e=t.length===3?t[2]:[t[0]],n=t.length===3?t[0]:`useValue(${t[0].name})`,r=w.useRef(!0);r.current=!0;const s=w.useMemo(()=>t.length===1?t[0]:G(n,()=>{if(r.current)return t[1]();try{return t[1]()}catch{return{}}}),e);try{const{subscribe:o,getSnapshot:i}=w.useMemo(()=>({subscribe:a=>As(`useValue(${n})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return w.useSyncExternalStore(o,i,i)}finally{r.current=!1}}_i("@tldraw/state-react","3.8.0-canary.c422debb621c","esm");const kV=(t,e)=>e.some(n=>t instanceof n);let N_,z_;function TV(){return N_||(N_=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function MV(){return z_||(z_=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const cA=new WeakMap,hx=new WeakMap,uA=new WeakMap,zy=new WeakMap,Z0=new WeakMap;function AV(t){const e=new Promise((n,r)=>{const s=()=>{t.removeEventListener("success",o),t.removeEventListener("error",i)},o=()=>{n(po(t.result)),s()},i=()=>{r(t.error),s()};t.addEventListener("success",o),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&cA.set(n,t)}).catch(()=>{}),Z0.set(e,t),e}function jV(t){if(hx.has(t))return;const e=new Promise((n,r)=>{const s=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",i),t.removeEventListener("abort",i)},o=()=>{n(),s()},i=()=>{r(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",o),t.addEventListener("error",i),t.addEventListener("abort",i)});hx.set(t,e)}let fx={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return hx.get(t);if(e==="objectStoreNames")return t.objectStoreNames||uA.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return po(t[e])},set(t,e,n){return t[e]=n,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function OV(t){fx=t(fx)}function DV(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(By(this),e,...n);return uA.set(r,e.sort?e.sort():[e]),po(r)}:MV().includes(t)?function(...e){return t.apply(By(this),e),po(cA.get(this))}:function(...e){return po(t.apply(By(this),e))}}function RV(t){return typeof t=="function"?DV(t):(t instanceof IDBTransaction&&jV(t),kV(t,TV())?new Proxy(t,fx):t)}function po(t){if(t instanceof IDBRequest)return AV(t);if(zy.has(t))return zy.get(t);const e=RV(t);return e!==t&&(zy.set(t,e),Z0.set(e,t)),e}const By=t=>Z0.get(t);function dA(t,e,{blocked:n,upgrade:r,blocking:s,terminated:o}={}){const i=indexedDB.open(t,e),a=po(i);return r&&i.addEventListener("upgradeneeded",l=>{r(po(i.result),l.oldVersion,l.newVersion,po(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),s&&l.addEventListener("versionchange",c=>s(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function hA(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),po(n).then(()=>{})}const LV=["get","getKey","getAll","getAllKeys","count"],$V=["put","add","delete","clear"],Uy=new Map;function B_(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Uy.get(e))return Uy.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,s=$V.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(s||LV.includes(n)))return;const o=async function(i,...a){const l=this.transaction(i,s?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[n](...a),s&&l.done]))[0]};return Uy.set(e,o),o}OV(t=>({...t,get:(e,n,r)=>B_(e,n)||t.get(e,n,r),has:(e,n)=>!!B_(e,n)||t.has(e,n)}));const FV="TLDRAW_DOCUMENT_v2",NV="TLDRAW_ASSET_STORE_v1",fA="TLDRAW_DB_NAME_INDEX_v2",Ce={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function pA(t){const e=FV+t;return BV(e),await dA(e,4,{upgrade(n){n.objectStoreNames.contains(Ce.Records)||n.createObjectStore(Ce.Records),n.objectStoreNames.contains(Ce.Schema)||n.createObjectStore(Ce.Schema),n.objectStoreNames.contains(Ce.SessionState)||n.createObjectStore(Ce.SessionState),n.objectStoreNames.contains(Ce.Assets)||n.createObjectStore(Ce.Assets)}})}async function zV(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(f=>f.name):Q0(),n=NV+t;if(!e.find(f=>f===n))return;const s=await dA(n,1,{upgrade(f){f.objectStoreNames.contains("assets")||f.createObjectStore("assets")}});if(!s.objectStoreNames.contains("assets"))return;const o=s.transaction(["assets"],"readonly"),i=o.objectStore("assets"),a=await i.getAllKeys(),l=await Promise.all(a.map(async f=>[f,await i.get(f)]));await o.done;const c=await pA(t),u=c.transaction([Ce.Assets],"readwrite"),h=u.objectStore(Ce.Assets);for(const[f,p]of l)h.put(p,f);await u.done,s.close(),c.close(),await hA(n)}const mu=class mu{constructor(e){I(this,"getDbPromise");I(this,"isClosed",!1);I(this,"pendingTransactionSet",new Set);mu.connectedInstances.add(this),this.getDbPromise=(async()=>(await zV(e),await pA(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Ru)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),mu.connectedInstances.delete(this))}tx(e,n,r){const s=(async()=>{Le(!this.isClosed,"db is closed");const i=(await this.getDb()).transaction(n,e),a=i.done.catch(l=>{if(!this.isClosed)throw l});try{return await r(i)}finally{this.isClosed?i.abort():await a}})();return this.pendingTransactionSet.add(s),s.finally(()=>this.pendingTransactionSet.delete(s)),s}async load({sessionId:e}={}){return await this.tx("readonly",[Ce.Records,Ce.Schema,Ce.SessionState],async n=>{var l,c;const r=n.objectStore(Ce.Records),s=n.objectStore(Ce.Schema),o=n.objectStore(Ce.SessionState);let i=e?(l=await o.get(e))==null?void 0:l.snapshot:null;return i||(i=(c=(await o.getAll()).sort((h,f)=>h.updatedAt-f.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(Ce.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async o=>{const i=o.objectStore(Ce.Records),a=o.objectStore(Ce.Schema),l=o.objectStore(Ce.SessionState);for(const[c,u]of Object.entries(n.added))await i.put(u,c);for(const[c,u]of Object.values(n.updated))await i.put(u,u.id);for(const c of Object.keys(n.removed))await i.delete(c);a.put(e.serialize(),Ce.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async o=>{const i=o.objectStore(Ce.Records),a=o.objectStore(Ce.Schema),l=o.objectStore(Ce.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(e.serialize(),Ce.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[Ce.SessionState],async e=>{const n=e.objectStore(Ce.SessionState),r=(await n.getAll()).sort((o,i)=>o.updatedAt-i.updatedAt);if(r.length<10){await e.done;return}const s=r.slice(0,r.length-10);for(const{id:o}of s)await n.delete(o)})}async getAsset(e){return await this.tx("readonly",[Ce.Assets],async n=>await n.objectStore(Ce.Assets).get(e))}async storeAsset(e,n){await this.tx("readwrite",[Ce.Assets],async r=>{await r.objectStore(Ce.Assets).put(n,e)})}};I(mu,"connectedInstances",new Set);let wp=mu;function Q0(){const t=JSON.parse(_0(fA)||"[]")??[];return Array.isArray(t)?t:[]}function BV(t){const e=new Set(Q0());e.add(t),I0(fA,JSON.stringify([...e]))}class af{constructor(e){I(this,"nextValue");I(this,"diff");this.previousValue=e}get(){var r,s,o,i;const e=((s=(r=this.diff)==null?void 0:r.removed)==null?void 0:s.size)??0,n=((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.size)??0;if(!(e===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(e,n){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(e),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(e):((s=this.diff).added??(s.added=new Set),this.diff.added.add(e))}add(e){var s,o,i;const n=this.previousValue.has(e);if(n)return((o=(s=this.diff)==null?void 0:s.removed)==null?void 0:o.has(e))?this._add(e,n):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,n)}_remove(e,n){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(e),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(e)):(s=this.diff.added)==null||s.delete(e)}remove(e){var s,o,i,a;const n=this.previousValue.has(e);if(!n)return((o=(s=this.diff)==null?void 0:s.added)==null?void 0:o.has(e))?this._remove(e,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(e)||this._remove(e,n)}}class Mg{constructor(e,n){I(this,"createDefaultProperties");I(this,"validator");I(this,"ephemeralKeys");I(this,"ephemeralKeySet");I(this,"scope");this.typeName=e,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:s=>s},this.scope=n.scope??"document",this.ephemeralKeys=n.ephemeralKeys;const r=new Set;if(n.ephemeralKeys)for(const[s,o]of Xn(n.ephemeralKeys))o&&r.add(s);this.ephemeralKeySet=r}create(e){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,s]of Object.entries(e))s!==void 0&&(n[r]=s);return n.typeName=this.typeName,n}clone(e){return{...nt(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??ze())}createCustomId(e){return this.typeName+":"+e}parseId(e){if(!this.isId(e))throw new Error(`ID "${e}" is not a valid ID for type "${this.typeName}"`);return e.slice(this.typeName.length+1)}isInstance(e){return(e==null?void 0:e.typeName)===this.typeName}isId(e){if(!e)return!1;for(let n=0;n<this.typeName.length;n++)if(e[n]!==this.typeName[n])return!1;return e[this.typeName.length]===":"}withDefaultProperties(e){return new Mg(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,n){return n&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(n,e):this.validator.validate(e)}}function Hs(t,e){return new Mg(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function bp(){return{added:{},updated:{},removed:{}}}function px(t){const e={added:t.removed,removed:t.added,updated:{}};for(const[n,r]of Object.values(t.updated))e.updated[n.id]=[r,n];return e}function gA(t){return Object.keys(t.added).length===0&&Object.keys(t.updated).length===0&&Object.keys(t.removed).length===0}function J0(t){const e={added:{},removed:{},updated:{}};return lu(e,t),e}function lu(t,e){for(const n of e){for(const[r,s]of Xn(n.added))if(t.removed[r]){const o=t.removed[r];delete t.removed[r],o!==s&&(t.updated[r]=[o,s])}else t.added[r]=s;for(const[r,[s,o]]of Xn(n.updated)){if(t.added[r]){t.added[r]=o,delete t.updated[r],delete t.removed[r];continue}if(t.updated[r]){t.updated[r]=[t.updated[r][0],o],delete t.removed[r];continue}t.updated[r]=n.updated[r],delete t.removed[r]}for(const[r,s]of Xn(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]=s}}var Pp={exports:{}};Pp.exports;(function(t,e){var n=200,r="__lodash_hash_undefined__",s=1,o=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",f="[object Error]",p="[object Function]",g="[object GeneratorFunction]",m="[object Map]",v="[object Number]",y="[object Null]",S="[object Object]",b="[object Promise]",P="[object Proxy]",C="[object RegExp]",_="[object Set]",E="[object String]",k="[object Symbol]",D="[object Undefined]",T="[object WeakMap]",j="[object ArrayBuffer]",L="[object DataView]",M="[object Float32Array]",O="[object Float64Array]",F="[object Int8Array]",B="[object Int16Array]",K="[object Int32Array]",R="[object Uint8Array]",H="[object Uint8ClampedArray]",X="[object Uint16Array]",te="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,de=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,oe={};oe[M]=oe[O]=oe[F]=oe[B]=oe[K]=oe[R]=oe[H]=oe[X]=oe[te]=!0,oe[a]=oe[l]=oe[j]=oe[u]=oe[L]=oe[h]=oe[f]=oe[p]=oe[m]=oe[v]=oe[S]=oe[C]=oe[_]=oe[E]=oe[T]=!1;var Ue=typeof dn=="object"&&dn&&dn.Object===Object&&dn,Ne=typeof self=="object"&&self&&self.Object===Object&&self,lt=Ue||Ne||Function("return this")(),$e=e&&!e.nodeType&&e,Ye=$e&&!0&&t&&!t.nodeType&&t,We=Ye&&Ye.exports===$e,er=We&&Ue.process,$t=function(){try{return er&&er.binding&&er.binding("util")}catch{}}(),On=$t&&$t.isTypedArray;function Mt(A,$){for(var V=-1,ne=A==null?0:A.length,Je=0,Se=[];++V<ne;){var mt=A[V];$(mt,V,A)&&(Se[Je++]=mt)}return Se}function Ft(A,$){for(var V=-1,ne=$.length,Je=A.length;++V<ne;)A[Je+V]=$[V];return A}function jo(A,$){for(var V=-1,ne=A==null?0:A.length;++V<ne;)if($(A[V],V,A))return!0;return!1}function Ys(A,$){for(var V=-1,ne=Array(A);++V<A;)ne[V]=$(V);return ne}function Oo(A){return function($){return A($)}}function Mm(A,$){return A.has($)}function O4(A,$){return A==null?void 0:A[$]}function D4(A){var $=-1,V=Array(A.size);return A.forEach(function(ne,Je){V[++$]=[Je,ne]}),V}function R4(A,$){return function(V){return A($(V))}}function L4(A){var $=-1,V=Array(A.size);return A.forEach(function(ne){V[++$]=ne}),V}var $4=Array.prototype,F4=Function.prototype,Ad=Object.prototype,Am=lt["__core-js_shared__"],eP=F4.toString,ps=Ad.hasOwnProperty,tP=function(){var A=/[^.]+$/.exec(Am&&Am.keys&&Am.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),nP=Ad.toString,N4=RegExp("^"+eP.call(ps).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rP=We?lt.Buffer:void 0,jd=lt.Symbol,sP=lt.Uint8Array,oP=Ad.propertyIsEnumerable,z4=$4.splice,Li=jd?jd.toStringTag:void 0,iP=Object.getOwnPropertySymbols,B4=rP?rP.isBuffer:void 0,U4=R4(Object.keys,Object),jm=Ta(lt,"DataView"),cc=Ta(lt,"Map"),Om=Ta(lt,"Promise"),Dm=Ta(lt,"Set"),Rm=Ta(lt,"WeakMap"),uc=Ta(Object,"create"),H4=Ni(jm),K4=Ni(cc),W4=Ni(Om),G4=Ni(Dm),V4=Ni(Rm),aP=jd?jd.prototype:void 0,Lm=aP?aP.valueOf:void 0;function $i(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function Y4(){this.__data__=uc?uc(null):{},this.size=0}function X4(A){var $=this.has(A)&&delete this.__data__[A];return this.size-=$?1:0,$}function q4(A){var $=this.__data__;if(uc){var V=$[A];return V===r?void 0:V}return ps.call($,A)?$[A]:void 0}function Z4(A){var $=this.__data__;return uc?$[A]!==void 0:ps.call($,A)}function Q4(A,$){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=uc&&$===void 0?r:$,this}$i.prototype.clear=Y4,$i.prototype.delete=X4,$i.prototype.get=q4,$i.prototype.has=Z4,$i.prototype.set=Q4;function Xs(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function J4(){this.__data__=[],this.size=0}function eN(A){var $=this.__data__,V=Dd($,A);if(V<0)return!1;var ne=$.length-1;return V==ne?$.pop():z4.call($,V,1),--this.size,!0}function tN(A){var $=this.__data__,V=Dd($,A);return V<0?void 0:$[V][1]}function nN(A){return Dd(this.__data__,A)>-1}function rN(A,$){var V=this.__data__,ne=Dd(V,A);return ne<0?(++this.size,V.push([A,$])):V[ne][1]=$,this}Xs.prototype.clear=J4,Xs.prototype.delete=eN,Xs.prototype.get=tN,Xs.prototype.has=nN,Xs.prototype.set=rN;function Fi(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function sN(){this.size=0,this.__data__={hash:new $i,map:new(cc||Xs),string:new $i}}function oN(A){var $=Rd(this,A).delete(A);return this.size-=$?1:0,$}function iN(A){return Rd(this,A).get(A)}function aN(A){return Rd(this,A).has(A)}function lN(A,$){var V=Rd(this,A),ne=V.size;return V.set(A,$),this.size+=V.size==ne?0:1,this}Fi.prototype.clear=sN,Fi.prototype.delete=oN,Fi.prototype.get=iN,Fi.prototype.has=aN,Fi.prototype.set=lN;function Od(A){var $=-1,V=A==null?0:A.length;for(this.__data__=new Fi;++$<V;)this.add(A[$])}function cN(A){return this.__data__.set(A,r),this}function uN(A){return this.__data__.has(A)}Od.prototype.add=Od.prototype.push=cN,Od.prototype.has=uN;function Do(A){var $=this.__data__=new Xs(A);this.size=$.size}function dN(){this.__data__=new Xs,this.size=0}function hN(A){var $=this.__data__,V=$.delete(A);return this.size=$.size,V}function fN(A){return this.__data__.get(A)}function pN(A){return this.__data__.has(A)}function gN(A,$){var V=this.__data__;if(V instanceof Xs){var ne=V.__data__;if(!cc||ne.length<n-1)return ne.push([A,$]),this.size=++V.size,this;V=this.__data__=new Fi(ne)}return V.set(A,$),this.size=V.size,this}Do.prototype.clear=dN,Do.prototype.delete=hN,Do.prototype.get=fN,Do.prototype.has=pN,Do.prototype.set=gN;function mN(A,$){var V=Ld(A),ne=!V&&AN(A),Je=!V&&!ne&&$m(A),Se=!V&&!ne&&!Je&&mP(A),mt=V||ne||Je||Se,At=mt?Ys(A.length,String):[],Nt=At.length;for(var ct in A)ps.call(A,ct)&&!(mt&&(ct=="length"||Je&&(ct=="offset"||ct=="parent")||Se&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||IN(ct,Nt)))&&At.push(ct);return At}function Dd(A,$){for(var V=A.length;V--;)if(hP(A[V][0],$))return V;return-1}function yN(A,$,V){var ne=$(A);return Ld(A)?ne:Ft(ne,V(A))}function dc(A){return A==null?A===void 0?D:y:Li&&Li in Object(A)?CN(A):MN(A)}function lP(A){return hc(A)&&dc(A)==a}function cP(A,$,V,ne,Je){return A===$?!0:A==null||$==null||!hc(A)&&!hc($)?A!==A&&$!==$:SN(A,$,V,ne,cP,Je)}function SN(A,$,V,ne,Je,Se){var mt=Ld(A),At=Ld($),Nt=mt?l:Ro(A),ct=At?l:Ro($);Nt=Nt==a?S:Nt,ct=ct==a?S:ct;var tr=Nt==S,Ur=ct==S,en=Nt==ct;if(en&&$m(A)){if(!$m($))return!1;mt=!0,tr=!1}if(en&&!tr)return Se||(Se=new Do),mt||mP(A)?uP(A,$,V,ne,Je,Se):bN(A,$,Nt,V,ne,Je,Se);if(!(V&s)){var Pr=tr&&ps.call(A,"__wrapped__"),Cr=Ur&&ps.call($,"__wrapped__");if(Pr||Cr){var Lo=Pr?A.value():A,qs=Cr?$.value():$;return Se||(Se=new Do),Je(Lo,qs,V,ne,Se)}}return en?(Se||(Se=new Do),PN(A,$,V,ne,Je,Se)):!1}function vN(A){if(!gP(A)||kN(A))return!1;var $=fP(A)?N4:de;return $.test(Ni(A))}function xN(A){return hc(A)&&pP(A.length)&&!!oe[dc(A)]}function wN(A){if(!TN(A))return U4(A);var $=[];for(var V in Object(A))ps.call(A,V)&&V!="constructor"&&$.push(V);return $}function uP(A,$,V,ne,Je,Se){var mt=V&s,At=A.length,Nt=$.length;if(At!=Nt&&!(mt&&Nt>At))return!1;var ct=Se.get(A);if(ct&&Se.get($))return ct==$;var tr=-1,Ur=!0,en=V&o?new Od:void 0;for(Se.set(A,$),Se.set($,A);++tr<At;){var Pr=A[tr],Cr=$[tr];if(ne)var Lo=mt?ne(Cr,Pr,tr,$,A,Se):ne(Pr,Cr,tr,A,$,Se);if(Lo!==void 0){if(Lo)continue;Ur=!1;break}if(en){if(!jo($,function(qs,zi){if(!Mm(en,zi)&&(Pr===qs||Je(Pr,qs,V,ne,Se)))return en.push(zi)})){Ur=!1;break}}else if(!(Pr===Cr||Je(Pr,Cr,V,ne,Se))){Ur=!1;break}}return Se.delete(A),Se.delete($),Ur}function bN(A,$,V,ne,Je,Se,mt){switch(V){case L:if(A.byteLength!=$.byteLength||A.byteOffset!=$.byteOffset)return!1;A=A.buffer,$=$.buffer;case j:return!(A.byteLength!=$.byteLength||!Se(new sP(A),new sP($)));case u:case h:case v:return hP(+A,+$);case f:return A.name==$.name&&A.message==$.message;case C:case E:return A==$+"";case m:var At=D4;case _:var Nt=ne&s;if(At||(At=L4),A.size!=$.size&&!Nt)return!1;var ct=mt.get(A);if(ct)return ct==$;ne|=o,mt.set(A,$);var tr=uP(At(A),At($),ne,Je,Se,mt);return mt.delete(A),tr;case k:if(Lm)return Lm.call(A)==Lm.call($)}return!1}function PN(A,$,V,ne,Je,Se){var mt=V&s,At=dP(A),Nt=At.length,ct=dP($),tr=ct.length;if(Nt!=tr&&!mt)return!1;for(var Ur=Nt;Ur--;){var en=At[Ur];if(!(mt?en in $:ps.call($,en)))return!1}var Pr=Se.get(A);if(Pr&&Se.get($))return Pr==$;var Cr=!0;Se.set(A,$),Se.set($,A);for(var Lo=mt;++Ur<Nt;){en=At[Ur];var qs=A[en],zi=$[en];if(ne)var yP=mt?ne(zi,qs,en,$,A,Se):ne(qs,zi,en,A,$,Se);if(!(yP===void 0?qs===zi||Je(qs,zi,V,ne,Se):yP)){Cr=!1;break}Lo||(Lo=en=="constructor")}if(Cr&&!Lo){var $d=A.constructor,Fd=$.constructor;$d!=Fd&&"constructor"in A&&"constructor"in $&&!(typeof $d=="function"&&$d instanceof $d&&typeof Fd=="function"&&Fd instanceof Fd)&&(Cr=!1)}return Se.delete(A),Se.delete($),Cr}function dP(A){return yN(A,DN,_N)}function Rd(A,$){var V=A.__data__;return EN($)?V[typeof $=="string"?"string":"hash"]:V.map}function Ta(A,$){var V=O4(A,$);return vN(V)?V:void 0}function CN(A){var $=ps.call(A,Li),V=A[Li];try{A[Li]=void 0;var ne=!0}catch{}var Je=nP.call(A);return ne&&($?A[Li]=V:delete A[Li]),Je}var _N=iP?function(A){return A==null?[]:(A=Object(A),Mt(iP(A),function($){return oP.call(A,$)}))}:RN,Ro=dc;(jm&&Ro(new jm(new ArrayBuffer(1)))!=L||cc&&Ro(new cc)!=m||Om&&Ro(Om.resolve())!=b||Dm&&Ro(new Dm)!=_||Rm&&Ro(new Rm)!=T)&&(Ro=function(A){var $=dc(A),V=$==S?A.constructor:void 0,ne=V?Ni(V):"";if(ne)switch(ne){case H4:return L;case K4:return m;case W4:return b;case G4:return _;case V4:return T}return $});function IN(A,$){return $=$??i,!!$&&(typeof A=="number"||Me.test(A))&&A>-1&&A%1==0&&A<$}function EN(A){var $=typeof A;return $=="string"||$=="number"||$=="symbol"||$=="boolean"?A!=="__proto__":A===null}function kN(A){return!!tP&&tP in A}function TN(A){var $=A&&A.constructor,V=typeof $=="function"&&$.prototype||Ad;return A===V}function MN(A){return nP.call(A)}function Ni(A){if(A!=null){try{return eP.call(A)}catch{}try{return A+""}catch{}}return""}function hP(A,$){return A===$||A!==A&&$!==$}var AN=lP(function(){return arguments}())?lP:function(A){return hc(A)&&ps.call(A,"callee")&&!oP.call(A,"callee")},Ld=Array.isArray;function jN(A){return A!=null&&pP(A.length)&&!fP(A)}var $m=B4||LN;function ON(A,$){return cP(A,$)}function fP(A){if(!gP(A))return!1;var $=dc(A);return $==p||$==g||$==c||$==P}function pP(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function gP(A){var $=typeof A;return A!=null&&($=="object"||$=="function")}function hc(A){return A!=null&&typeof A=="object"}var mP=On?Oo(On):xN;function DN(A){return jN(A)?mN(A):wN(A)}function RN(){return[]}function LN(){return!1}t.exports=ON})(Pp,Pp.exports);var UV=Pp.exports;const mA=wi(UV);function HV(t){if(t.length===0)return new Set;const e=t[0],n=t.slice(1),r=new Set;for(const s of e)n.every(o=>o.has(s))&&r.add(s);return r}function KV(t,e){const n={};for(const r of e)t.has(r)||(n.added??(n.added=new Set),n.added.add(r));for(const r of t)e.has(r)||(n.removed??(n.removed=new Set),n.removed.add(r));return n.added||n.removed?n:void 0}function U_(t,e){for(const[n,r]of Object.entries(t)){const s=r,o=e[n];if("eq"in s&&o!==s.eq||"neq"in s&&o===s.neq||"gt"in s&&(typeof o!="number"||o<=s.gt))return!1}return!0}function H_(t,e,n){const r=Object.fromEntries(Object.keys(n).map(s=>[s,new Set]));for(const[s,o]of Object.entries(n))if("eq"in o){const a=t.index(e,s).get().get(o.eq);if(a)for(const l of a)r[s].add(l)}else if("neq"in o){const i=t.index(e,s);for(const[a,l]of i.get())if(a!==o.neq)for(const c of l)r[s].add(c)}else if("gt"in o){const i=t.index(e,s);for(const[a,l]of i.get())if(a>o.gt)for(const c of l)r[s].add(c)}return HV(Object.values(r))}class WV{constructor(e,n){I(this,"indexCache",new Map);I(this,"historyCache",new Map);this.atoms=e,this.history=n}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const n=G("filterHistory:"+e,(r,s)=>{if(Qi(r))return this.history.get();const o=this.history.getDiffSince(s);if(o===ur)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of o){for(const h of ut(u.added))if(h.typeName===e)if(i.removed[h.id]){const f=i.removed[h.id];delete i.removed[h.id],l--,f!==h&&(i.updated[h.id]=[f,h],c++)}else i.added[h.id]=h,a++;for(const[h,f]of ut(u.updated))f.typeName===e&&(i.added[f.id]?i.added[f.id]=f:i.updated[f.id]?i.updated[f.id]=[i.updated[f.id][0],f]:(i.updated[f.id]=[h,f],c++));for(const h of ut(u.removed))h.typeName===e&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?Kc(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(e,n),n}index(e,n){const r=e+":"+n;if(this.indexCache.has(r))return this.indexCache.get(r);const s=this.__uncached_createIndex(e,n);return this.indexCache.set(r,s),s}__uncached_createIndex(e,n){const r=this.filterHistory(e),s=()=>{r.get();const o=new Map;for(const i of ut(this.atoms.get())){const a=i.get();if(a.typeName===e){const l=a[n];o.has(l)||o.set(l,new Set),o.get(l).add(a.id)}}return o};return G("index:"+e+":"+n,(o,i)=>{if(Qi(o))return s();const a=r.getDiffSince(i);if(a===ur)return s();const l=new Map,c=(p,g)=>{let m=l.get(p);m||(m=new af(o.get(p)??new Set)),m.add(g),l.set(p,m)},u=(p,g)=>{let m=l.get(p);m||(m=new af(o.get(p)??new Set)),m.remove(g),l.set(p,m)};for(const p of a){for(const g of ut(p.added))if(g.typeName===e){const m=g[n];c(m,g.id)}for(const[g,m]of ut(p.updated))if(m.typeName===e){const v=g[n],y=m[n];v!==y&&(u(v,m.id),c(y,m.id))}for(const g of ut(p.removed))if(g.typeName===e){const m=g[n];u(m,g.id)}}let h,f;for(const[p,g]of l){const m=g.get();m&&(h||(h=new Map(o)),f||(f=new Map),m.value.size===0?h.delete(p):h.set(p,m.value),f.set(p,m.diff))}return h&&f?Kc(h,f):o},{historyLength:100})}record(e,n=()=>({}),r="record:"+e+(n?":"+n.toString():"")){const s=this.ids(e,n,r);return G(r,()=>{var o;for(const i of s.get())return(o=this.atoms.get()[i])==null?void 0:o.get()})}records(e,n=()=>({}),r="records:"+e+(n?":"+n.toString():"")){const s=this.ids(e,n,"ids:"+r);return G(r,()=>{const o=this.atoms.get();return[...s.get()].map(i=>{const a=o[i];if(!a)throw new Error("no atom found for record id: "+i);return a.get()})},{isEqual:LT})}ids(e,n=()=>({}),r="ids:"+e+(n?":"+n.toString():"")){const s=this.filterHistory(e),o=()=>{s.get();const l=n();return Object.keys(l).length===0?new Set(ut(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===e?u.id:[]})):H_(this,e,l)},i=l=>{const c=o(),u=KV(l,c);return u?Kc(c,u):l},a=G("ids_query:"+r,n,{isEqual:mA});return G("query:"+r,(l,c)=>{const u=a.get();if(Qi(l))return o();if(c<a.lastChangedEpoch)return i(l);const h=s.getDiffSince(c);if(h===ur)return i(l);const f=new af(l);for(const g of h){for(const m of ut(g.added))m.typeName===e&&U_(u,m)&&f.add(m.id);for(const[m,v]of ut(g.updated))v.typeName===e&&(U_(u,v)?f.add(v.id):f.remove(v.id));for(const m of ut(g.removed))m.typeName===e&&f.remove(m.id)}const p=f.get();return p?Kc(p.value,p.diff):l},{historyLength:50})}exec(e,n){const r=H_(this,e,n);if(r.size===0)return fo;const s=this.atoms.get();return[...r].map(o=>s[o].get())}}class GV{constructor(e){I(this,"_beforeCreateHandlers",{});I(this,"_afterCreateHandlers",{});I(this,"_beforeChangeHandlers",{});I(this,"_afterChangeHandlers",{});I(this,"_beforeDeleteHandlers",{});I(this,"_afterDeleteHandlers",{});I(this,"_operationCompleteHandlers",[]);I(this,"_isEnabled",!0);this.store=e}isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,n){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let s=e;for(const o of r)s=o(s,n);return s}return e}handleAfterCreate(e,n){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const s of r)s(e,n)}handleBeforeChange(e,n,r){if(!this._isEnabled)return n;const s=this._beforeChangeHandlers[n.typeName];if(s){let o=n;for(const i of s)o=i(e,o,r);return o}return n}handleAfterChange(e,n,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[n.typeName];if(s)for(const o of s)o(e,n,r)}handleBeforeDelete(e,n){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const s of r)if(s(e,n)===!1)return!1}return!0}handleAfterDelete(e,n){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const s of r)s(e,n)}handleOperationComplete(e){if(this._isEnabled)for(const n of this._operationCompleteHandlers)n(e)}register(e){const n=[];for(const[r,s]of Object.entries(e))s!=null&&s.beforeCreate&&n.push(this.registerBeforeCreateHandler(r,s.beforeCreate)),s!=null&&s.afterCreate&&n.push(this.registerAfterCreateHandler(r,s.afterCreate)),s!=null&&s.beforeChange&&n.push(this.registerBeforeChangeHandler(r,s.beforeChange)),s!=null&&s.afterChange&&n.push(this.registerAfterChangeHandler(r,s.afterChange)),s!=null&&s.beforeDelete&&n.push(this.registerBeforeDeleteHandler(r,s.beforeDelete)),s!=null&&s.afterDelete&&n.push(this.registerAfterDeleteHandler(r,s.afterDelete));return()=>{for(const r of n)r()}}registerBeforeCreateHandler(e,n){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(n),()=>Bi(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>Bi(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>Bi(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>Bi(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>Bi(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>Bi(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Bi(this._operationCompleteHandlers,e)}}function Bi(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class eb{constructor(e){I(this,"id");I(this,"atoms",It("store_atoms",{}));I(this,"history",It("history",0,{historyLength:1e3}));I(this,"query",new WV(this.atoms,this.history));I(this,"listeners",new Set);I(this,"historyAccumulator",new YV);I(this,"historyReactor");I(this,"schema");I(this,"props");I(this,"scopedTypes");I(this,"sideEffects",new GV(this));I(this,"isMergingRemoteChanges",!1);I(this,"_integrityChecker");I(this,"_isPossiblyCorrupted",!1);I(this,"pendingAfterEvents",null);I(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:s}=e;this.id=s??ze(),this.schema=r,this.props=e.props,n&&this.atoms.set(w0(Xn(n).map(([o,i])=>[o,It("atom:"+o,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=uV("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>this.cancelHistoryReactor=nM(o)}),this.scopedTypes={document:new Set(ut(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(ut(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(ut(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}cancelHistoryReactor(){}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:n,source:r}of e){let s=null,o=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(o??(o=this.filterChangesByScope(n,"document")),!o)continue;a({changes:o,source:r})}else if(l.scope==="session"){if(s??(s=this.filterChangesByScope(n,"session")),!s)continue;a({changes:s,source:r})}else{if(i??(i=this.filterChangesByScope(n,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:n,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,n){const r={added:au(e.added,(s,o)=>this.scopedTypes[n].has(o.typeName)),updated:au(e.updated,(s,o)=>this.scopedTypes[n].has(o[1].typeName)),removed:au(e.removed,(s,o)=>this.scopedTypes[n].has(o.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(e){this.historyAccumulator.add({changes:e,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,e)}validate(e){this.allRecords().forEach(n=>this.schema.validateRecord(this,n,e,null))}put(e,n){this.atomic(()=>{const r={},s={},o=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.isMergingRemoteChanges?"remote":"user";for(let u=0,h=e.length;u<h;u++){a=e[u];const f=(i??o)[a.id];if(f){const p=f.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(p,a,c),this.schema.validateRecord(this,a,n??"updateRecord",p)===p)continue;f.set(a),l=!0;const m=f.__unsafe__getWithoutCapture();r[a.id]=[p,m],this.addDiffForAfterEvent(p,m)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),s[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...o}),i[a.id]=It("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:s,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const n=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of e){const i=this.atoms.__unsafe__getWithoutCapture()[o];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&n.add(o)}let s;this.atoms.update(o=>{let i;for(const a of e){if(n.has(a)||!(a in o))continue;i||(i={...o}),s||(s={}),delete i[a];const l=o[a].get();s[a]=l,this.addDiffForAfterEvent(l,null)}return i??o}),s&&this.updateHistory({added:{},updated:{},removed:s})})}get(e){var n;return(n=this.atoms.get()[e])==null?void 0:n.get()}unsafeGetWithoutCapture(e){var n;return(n=this.atoms.__unsafe__getWithoutCapture()[e])==null?void 0:n.__unsafe__getWithoutCapture()}serialize(e="document"){const n={};for(const[r,s]of Xn(this.atoms.get())){const o=s.get();(e==="all"||this.scopedTypes[e].has(o.typeName))&&(n[r]=o)}return n}getStoreSnapshot(e="document"){return{store:this.serialize(e),schema:this.schema.serialize()}}getSnapshot(e="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(e)}migrateSnapshot(e){const n=this.schema.migrateStoreSnapshot(e);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);return{store:n.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){const n=this.schema.migrateStoreSnapshot(e);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(n.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(e){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(e)}allRecords(){return ut(this.atoms.get()).map(e=>e.get())}clear(){this.remove(FC(this.atoms.get()))}update(e,n){const r=this.atoms.get()[e];if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])}has(e){return!!this.atoms.get()[e]}listen(e,n){this._flushHistory();const r={onHistory:e,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(r),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,js(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(s=>n.push(s.changes));try{return js(e),J0(n)}finally{r()}}applyDiff(e,{runCallbacks:n=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=ut(e.added);for(const[i,a]of ut(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){s.push(a);continue}let u=null;for(const[h,f]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(f,hn(c,h))||(u||(u={...c}),u[h]=f);u&&s.push(u)}else s.push(a)}const o=FC(e.removed);s.length&&this.put(s),o.length&&this.remove(o)},n)}createComputedCache(e,n,r){const s=new Ds;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(e+":"+o,()=>n(a.get()))}).get()}}}createSelectedComputedCache(e,n,r){const s=new Ds;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=G(e+":"+o+":selector",()=>n(i.get()));return G(e+":"+o,()=>r(a.get()))}).get()}}}ensureStoreIsUsable(){this.atomic(()=>{var e;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(e=this._integrityChecker)==null||e.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(e,n){if(Le(this.pendingAfterEvents,"must be in event operation"),e===n||(e&&n&&Le(e.id===n.id),!e&&!n))return;const r=(e||n).id,s=this.pendingAfterEvents.get(r);s?s.after=n:this.pendingAfterEvents.set(r,{before:e,after:n})}flushAtomicCallbacks(){let e=0;const n=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(e++,e>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:s,after:o}of r.values())s&&o?this.sideEffects.handleAfterChange(s,o,n):s&&!o?this.sideEffects.handleAfterDelete(s,n):!s&&o&&this.sideEffects.handleAfterCreate(o,n);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(n)}}}atomic(e,n=!0){return js(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),e();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(n??r),this._isInAtomicOp=!0;try{const s=e();return this.flushAtomicCallbacks(),s}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(n=>e(n,this.isMergingRemoteChanges?"remote":"user"))}}function VV(t){if(t.length===0)return[];const e=[];let n=[t[0]],r;for(let s=1,o=t.length;s<o;s++)r=t[s],n[0].source!==r.source&&(e.push(n),n=[]),n.push(r);return e.push(n),e.map(s=>({source:s[0].source,changes:J0(s.map(o=>o.changes))}))}class YV{constructor(){I(this,"_history",[]);I(this,"_interceptors",new Set)}addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const n of this._interceptors)n(e)}flush(){const e=VV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function XV(t,e,n){const r=new Ds;return{get(s,o){return r.get(s,()=>(s instanceof eb?s:s.store).createComputedCache(t,l=>e(s,l),n)).get(o)}}}function qV(t){const e=[];for(let n=t.length-1;n>=0;n--){const r=t[n];if("id"in r)e.unshift(r);else{const s=r.dependsOn,o=e[0];o&&(e[0]={...o,dependsOn:s.concat(o.dependsOn??[])})}}return e}function vl({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:qV(t)};return yA(r),r}function Zn(t,e){return Object.fromEntries(Xn(e).map(([n,r])=>[n,`${t}/${r}`]))}function xr(t){const e=t.sequenceId;return vl({sequenceId:e,retroactive:t.retroactive??!0,sequence:t.sequence.map(n=>"id"in n?{...n,scope:"record",filter:r=>{var s,o;return r.typeName===t.recordType&&(((s=n.filter)==null?void 0:s.call(n,r))??!0)&&(((o=t.filter)==null?void 0:o.call(t,r))??!0)}}:n)})}function ZV(t){const e=new Map(t.map(o=>[o.id,o])),n=new Set,r=[];function s(o){Le(!n.has(o.id),`Circular dependency in migrations: ${o.id}`),n.add(o.id);const{version:i,sequenceId:a}=Cp(o.id),l=e.get(`${a}/${i-1}`);if(l&&s(l),o.dependsOn)for(const c of o.dependsOn){const u=e.get(c);u&&s(u)}e.delete(o.id),r.push(o)}for(const o of e.values())s(o);return r}function Cp(t){const[e,n]=t.split("/");return{sequenceId:e,version:parseInt(n)}}function K_(t,e){e&&Le(t.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${t}'`),Le(t.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${t}'`)}function yA(t){if(Le(!t.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${t.sequenceId}`),Le(t.sequenceId.length,"sequenceId must be a non-empty string"),t.sequence.length===0)return;K_(t.sequence[0].id,t.sequenceId);let e=Cp(t.sequence[0].id).version;Le(e===1,`Expected the first migrationId to be '${t.sequenceId}/1' but got '${t.sequence[0].id}'`);for(let n=1;n<t.sequence.length;n++){const r=t.sequence[n].id;K_(r,t.sequenceId);const s=Cp(r).version;Le(s===e+1,`Migration id numbers must increase in increments of 1, expected ${t.sequenceId}/${e+1} but got '${t.sequence[n].id}'`),e=s}}var Bo=(t=>(t.IncompatibleSubtype="incompatible-subtype",t.UnknownType="unknown-type",t.TargetVersionTooNew="target-version-too-new",t.TargetVersionTooOld="target-version-too-old",t.MigrationError="migration-error",t.UnrecognizedSubtype="unrecognized-subtype",t))(Bo||{});function QV(t){if(t.schemaVersion>2||t.schemaVersion<1)return wn.err("Bad schema version");if(t.schemaVersion===2)return wn.ok(t);const e={schemaVersion:2,sequences:{"com.tldraw.store":t.storeVersion}};for(const[n,r]of Object.entries(t.recordVersions))if(e.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(const[s,o]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${n}.${s}`]=o;return wn.ok(e)}class tb{constructor(e,n){I(this,"migrations",{});I(this,"sortedMigrations");var s;this.types=e,this.options=n;for(const o of n.migrations??[])Le(!this.migrations[o.sequenceId],`Duplicate migration sequenceId ${o.sequenceId}`),yA(o),this.migrations[o.sequenceId]=o;const r=Object.values(this.migrations).flatMap(o=>o.sequence);this.sortedMigrations=ZV(r);for(const o of this.sortedMigrations)if((s=o.dependsOn)!=null&&s.length)for(const i of o.dependsOn){const a=r.find(l=>l.id===i);Le(a,`Migration '${o.id}' depends on missing migration '${i}'`)}}static create(e,n){return new tb(e,n??{})}validateRecord(e,n,r,s){try{const o=hn(this.types,n.typeName);if(!o)throw new Error(`Missing definition for record type ${n.typeName}`);return o.validate(n,s??void 0)}catch(o){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:n,phase:r,recordBefore:s,error:o});throw o}}getMigrationsSince(e){const n=QV(e);if(!n.ok)return n;const r=n.value,s=new Set(Object.keys(r.sequences).filter(i=>this.migrations[i]));for(const i in this.migrations)r.sequences[i]===void 0&&this.migrations[i].retroactive&&s.add(i);if(s.size===0)return wn.ok([]);const o=new Set;for(const i of s){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)o.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return wn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))o.add(u.id)}return wn.ok(this.sortedMigrations.filter(({id:i})=>o.has(i)))}migratePersistedRecord(e,n,r="up"){const s=this.getMigrationsSince(n);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:Bo.MigrationError};let o=s.value;if(o.length===0)return{type:"success",value:e};if(o.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?Bo.TargetVersionTooOld:Bo.TargetVersionTooNew};if(r==="down"){if(!o.every(i=>i.down))return{type:"error",reason:Bo.TargetVersionTooOld};o=o.slice().reverse()}e=nt(e);try{for(const i of o){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(e):!0))continue;const l=i[r](e);l&&(e=nt(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Bo.MigrationError}}return{type:"success",value:e}}migrateStoreSnapshot(e){let{store:n}=e;const r=this.getMigrationsSince(e.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:Bo.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:n};n=nt(n);try{for(const o of s)if(o.scope==="record")for(const[i,a]of Object.entries(n)){if(!(o.filter?o.filter(a):!0))continue;const c=o.up(a);c&&(n[i]=nt(c))}else if(o.scope==="store"){const i=o.up(n);i&&(n=nt(i))}else Ot(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Bo.MigrationError}}return{type:"success",value:n}}createIntegrityChecker(e){var n,r;return((r=(n=this.options).createIntegrityChecker)==null?void 0:r.call(n,e))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:n})=>[e,n.length?Cp(n.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const n=hn(this.types,e);return Le(n,"record type does not exists"),n}}_i("@tldraw/store","3.8.0-canary.c422debb621c","esm");function JV(t){if(!t.length)return null;let e="";for(const n of t)typeof n=="number"?e+=`.${n}`:n.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${n.slice(1)}`:e+=n:e+=`.${n}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class Te extends Error{constructor(n,r=[]){const s=JV(r),o=n.split(`
|
|
82
|
+
`))}const Hc=Symbol.for("com.tldraw.state/UNINITIALIZED");function Qi(t){return t===Hc}const dx=ki("WithDiff",()=>class{constructor(e,n){this.value=e,this.diff=n}});function Kc(t,e){return new dx(t,e)}class xV{constructor(e,n,r){I(this,"lastChangedEpoch",ei);I(this,"lastTraversedEpoch",ei);I(this,"lastCheckedEpoch",ei);I(this,"parentSet",new vp);I(this,"parents",[]);I(this,"parentEpochs",[]);I(this,"children",new vp);I(this,"historyBuffer");I(this,"state",Hc);I(this,"error",null);I(this,"computeDiff");I(this,"isEqual");this.name=e,this.derive=n,r!=null&&r.historyLength&&(this.historyBuffer=new nA(r.historyLength)),this.computeDiff=r==null?void 0:r.computeDiff,this.isEqual=(r==null?void 0:r.isEqual)??tA}get isActivelyListening(){return!this.children.isEmpty}__unsafe__getWithoutCapture(e){var s;const n=this.lastChangedEpoch===ei,r=$n();if(!n&&(this.lastCheckedEpoch===r||this.isActivelyListening&&fV()&&this.lastTraversedEpoch<hV()||!eA(this)))if(this.lastCheckedEpoch=r,this.error){if(e)return this.state;throw this.error.thrownValue}else return this.state;try{rA(this);const o=this.derive(this.state,this.lastCheckedEpoch),i=o instanceof dx?o.value:o,a=this.state===Hc;if(a||!this.isEqual(i,this.state)){if(this.historyBuffer&&!a){const l=o instanceof dx?o.diff:void 0;this.historyBuffer.pushEntry(this.lastChangedEpoch,$n(),l??((s=this.computeDiff)==null?void 0:s.call(this,this.state,i,this.lastCheckedEpoch,$n()))??ur)}this.lastChangedEpoch=$n(),this.state=i}return this.error=null,this.lastCheckedEpoch=$n(),this.state}catch(o){if(this.state!==Hc&&(this.state=Hc,this.lastChangedEpoch=$n()),this.lastCheckedEpoch=$n(),this.historyBuffer&&this.historyBuffer.clear(),this.error={thrownValue:o},!e)throw o;return this.state}finally{sA()}}get(){try{return this.__unsafe__getWithoutCapture()}finally{xp(this)}}getDiffSince(e){var n;return this.__unsafe__getWithoutCapture(!0),xp(this),e>=this.lastChangedEpoch?fo:((n=this.historyBuffer)==null?void 0:n.getChangesSince(e))??ur}}const kg=ki("Computed",()=>xV);function wV(t={},e,n,r){const s=r.value,o=Symbol.for("__@tldraw/state__computed__"+n);return r.value=function(){let i=this[o];return i||(i=new kg(n,s.bind(this),t),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r.value[aA]=!0,r}function bV(t={},e,n,r){const s=r.get,o=Symbol.for("__@tldraw/state__computed__"+n);return r.get=function(){let i=this[o];return i||(i=new kg(n,s.bind(this),t),Object.defineProperty(this,o,{enumerable:!1,configurable:!1,writable:!1,value:i})),i.get()},r}function PV(t,e,n){Le(n.kind==="method","@computed can only be used on methods");const r=Symbol.for("__@tldraw/state__computed__"+String(n.name)),s=function(){let o=this[r];return o||(o=new kg(String(n.name),e.bind(this),t),Object.defineProperty(this,r,{enumerable:!1,configurable:!1,writable:!1,value:o})),o.get()};return s[aA]=!0,s}function $_(t={},e){if(e.length===2){const[n,r]=e;return PV(t,n,r)}else{const[n,r,s]=e;return s.get?(vV(),bV(t,n,r,s)):wV(t,n,r,s)}}const aA="@@__isComputedMethod__@@";function G(){if(arguments.length===1){const t=arguments[0];return(...e)=>$_(t,e)}else return typeof arguments[0]=="string"?new kg(arguments[0],arguments[1],arguments[2]):$_(void 0,arguments)}const lA=1,CV=ki("apiVersion",()=>lA);if(CV!==lA)throw new Error("You have multiple incompatible versions of @tldraw/state in your app. Please deduplicate the package.");_i("@tldraw/state","3.7.2","esm");function Tg(t,e,n=[]){const r=ke.useRef(e);r.current=e;const[s,o,i]=ke.useMemo(()=>{let a=null;const l=h=>(a=h,()=>{a=null}),c=new Ql(`useStateTracking(${t})`,()=>{var h;return(h=r.current)==null?void 0:h.call(r)},{scheduleEffect(){a==null||a()}});return[c,l,()=>c.scheduleCount]},[t,...n]);return ke.useSyncExternalStore(o,i,i),ke.useEffect(()=>(s.attach(),s.maybeScheduleEffect(),()=>{s.detach()}),[s]),s.execute()}const F_={apply(t,e,n){return Tg(t.displayName??t.name??"tracked(???)",()=>t.apply(e,n))}},_V=Symbol.for("react.memo"),IV=Symbol.for("react.forward_ref");function Zt(t){let e=null;const n=t.$$typeof;return n===_V&&(t=t.type,e=t.compare),n===IV?w.memo(w.forwardRef(new Proxy(t.render,F_))):w.memo(new Proxy(t,F_),e)}function q0(t,e,n){return w.useState(()=>{const r=typeof e=="function"?e():e;return It(`useAtom(${t})`,r,n)})[0]}function EV(){const t=arguments[0],e=arguments[1],n=arguments.length===3?void 0:arguments[2],r=arguments.length===3?arguments[2]:arguments[3];return w.useMemo(()=>G(`useComputed(${t})`,e,n),r)}function ui(t,e,n=fo){w.useEffect(()=>{const r=new Ql(t,e);return r.attach(),r.execute(),()=>{r.detach()}},n)}function U(){const t=arguments,e=t.length===3?t[2]:[t[0]],n=t.length===3?t[0]:`useValue(${t[0].name})`,r=w.useRef(!0);r.current=!0;const s=w.useMemo(()=>t.length===1?t[0]:G(n,()=>{if(r.current)return t[1]();try{return t[1]()}catch{return{}}}),e);try{const{subscribe:o,getSnapshot:i}=w.useMemo(()=>({subscribe:a=>As(`useValue(${n})`,()=>{s.get(),a()}),getSnapshot:()=>s.get()}),[s]);return w.useSyncExternalStore(o,i,i)}finally{r.current=!1}}_i("@tldraw/state-react","3.7.2","esm");const kV=(t,e)=>e.some(n=>t instanceof n);let N_,z_;function TV(){return N_||(N_=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function MV(){return z_||(z_=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const cA=new WeakMap,hx=new WeakMap,uA=new WeakMap,zy=new WeakMap,Z0=new WeakMap;function AV(t){const e=new Promise((n,r)=>{const s=()=>{t.removeEventListener("success",o),t.removeEventListener("error",i)},o=()=>{n(po(t.result)),s()},i=()=>{r(t.error),s()};t.addEventListener("success",o),t.addEventListener("error",i)});return e.then(n=>{n instanceof IDBCursor&&cA.set(n,t)}).catch(()=>{}),Z0.set(e,t),e}function jV(t){if(hx.has(t))return;const e=new Promise((n,r)=>{const s=()=>{t.removeEventListener("complete",o),t.removeEventListener("error",i),t.removeEventListener("abort",i)},o=()=>{n(),s()},i=()=>{r(t.error||new DOMException("AbortError","AbortError")),s()};t.addEventListener("complete",o),t.addEventListener("error",i),t.addEventListener("abort",i)});hx.set(t,e)}let fx={get(t,e,n){if(t instanceof IDBTransaction){if(e==="done")return hx.get(t);if(e==="objectStoreNames")return t.objectStoreNames||uA.get(t);if(e==="store")return n.objectStoreNames[1]?void 0:n.objectStore(n.objectStoreNames[0])}return po(t[e])},set(t,e,n){return t[e]=n,!0},has(t,e){return t instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in t}};function OV(t){fx=t(fx)}function DV(t){return t===IDBDatabase.prototype.transaction&&!("objectStoreNames"in IDBTransaction.prototype)?function(e,...n){const r=t.call(By(this),e,...n);return uA.set(r,e.sort?e.sort():[e]),po(r)}:MV().includes(t)?function(...e){return t.apply(By(this),e),po(cA.get(this))}:function(...e){return po(t.apply(By(this),e))}}function RV(t){return typeof t=="function"?DV(t):(t instanceof IDBTransaction&&jV(t),kV(t,TV())?new Proxy(t,fx):t)}function po(t){if(t instanceof IDBRequest)return AV(t);if(zy.has(t))return zy.get(t);const e=RV(t);return e!==t&&(zy.set(t,e),Z0.set(e,t)),e}const By=t=>Z0.get(t);function dA(t,e,{blocked:n,upgrade:r,blocking:s,terminated:o}={}){const i=indexedDB.open(t,e),a=po(i);return r&&i.addEventListener("upgradeneeded",l=>{r(po(i.result),l.oldVersion,l.newVersion,po(i.transaction),l)}),n&&i.addEventListener("blocked",l=>n(l.oldVersion,l.newVersion,l)),a.then(l=>{o&&l.addEventListener("close",()=>o()),s&&l.addEventListener("versionchange",c=>s(c.oldVersion,c.newVersion,c))}).catch(()=>{}),a}function hA(t,{blocked:e}={}){const n=indexedDB.deleteDatabase(t);return e&&n.addEventListener("blocked",r=>e(r.oldVersion,r)),po(n).then(()=>{})}const LV=["get","getKey","getAll","getAllKeys","count"],$V=["put","add","delete","clear"],Uy=new Map;function B_(t,e){if(!(t instanceof IDBDatabase&&!(e in t)&&typeof e=="string"))return;if(Uy.get(e))return Uy.get(e);const n=e.replace(/FromIndex$/,""),r=e!==n,s=$V.includes(n);if(!(n in(r?IDBIndex:IDBObjectStore).prototype)||!(s||LV.includes(n)))return;const o=async function(i,...a){const l=this.transaction(i,s?"readwrite":"readonly");let c=l.store;return r&&(c=c.index(a.shift())),(await Promise.all([c[n](...a),s&&l.done]))[0]};return Uy.set(e,o),o}OV(t=>({...t,get:(e,n,r)=>B_(e,n)||t.get(e,n,r),has:(e,n)=>!!B_(e,n)||t.has(e,n)}));const FV="TLDRAW_DOCUMENT_v2",NV="TLDRAW_ASSET_STORE_v1",fA="TLDRAW_DB_NAME_INDEX_v2",Ce={Records:"records",Schema:"schema",SessionState:"session_state",Assets:"assets"};async function pA(t){const e=FV+t;return BV(e),await dA(e,4,{upgrade(n){n.objectStoreNames.contains(Ce.Records)||n.createObjectStore(Ce.Records),n.objectStoreNames.contains(Ce.Schema)||n.createObjectStore(Ce.Schema),n.objectStoreNames.contains(Ce.SessionState)||n.createObjectStore(Ce.SessionState),n.objectStoreNames.contains(Ce.Assets)||n.createObjectStore(Ce.Assets)}})}async function zV(t){const e=window.indexedDB.databases?(await window.indexedDB.databases()).map(f=>f.name):Q0(),n=NV+t;if(!e.find(f=>f===n))return;const s=await dA(n,1,{upgrade(f){f.objectStoreNames.contains("assets")||f.createObjectStore("assets")}});if(!s.objectStoreNames.contains("assets"))return;const o=s.transaction(["assets"],"readonly"),i=o.objectStore("assets"),a=await i.getAllKeys(),l=await Promise.all(a.map(async f=>[f,await i.get(f)]));await o.done;const c=await pA(t),u=c.transaction([Ce.Assets],"readwrite"),h=u.objectStore(Ce.Assets);for(const[f,p]of l)h.put(p,f);await u.done,s.close(),c.close(),await hA(n)}const mu=class mu{constructor(e){I(this,"getDbPromise");I(this,"isClosed",!1);I(this,"pendingTransactionSet",new Set);mu.connectedInstances.add(this),this.getDbPromise=(async()=>(await zV(e),await pA(e)))()}getDb(){return this.getDbPromise}pending(){return Promise.allSettled([this.getDbPromise,...this.pendingTransactionSet]).then(Ru)}async close(){this.isClosed||(this.isClosed=!0,await this.pending(),(await this.getDb()).close(),mu.connectedInstances.delete(this))}tx(e,n,r){const s=(async()=>{Le(!this.isClosed,"db is closed");const i=(await this.getDb()).transaction(n,e),a=i.done.catch(l=>{if(!this.isClosed)throw l});try{return await r(i)}finally{this.isClosed?i.abort():await a}})();return this.pendingTransactionSet.add(s),s.finally(()=>this.pendingTransactionSet.delete(s)),s}async load({sessionId:e}={}){return await this.tx("readonly",[Ce.Records,Ce.Schema,Ce.SessionState],async n=>{var l,c;const r=n.objectStore(Ce.Records),s=n.objectStore(Ce.Schema),o=n.objectStore(Ce.SessionState);let i=e?(l=await o.get(e))==null?void 0:l.snapshot:null;return i||(i=(c=(await o.getAll()).sort((h,f)=>h.updatedAt-f.updatedAt).pop())==null?void 0:c.snapshot),{records:await r.getAll(),schema:await s.get(Ce.Schema),sessionStateSnapshot:i}})}async storeChanges({schema:e,changes:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async o=>{const i=o.objectStore(Ce.Records),a=o.objectStore(Ce.Schema),l=o.objectStore(Ce.SessionState);for(const[c,u]of Object.entries(n.added))await i.put(u,c);for(const[c,u]of Object.values(n.updated))await i.put(u,u.id);for(const c of Object.keys(n.removed))await i.delete(c);a.put(e.serialize(),Ce.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async storeSnapshot({schema:e,snapshot:n,sessionId:r,sessionStateSnapshot:s}){await this.tx("readwrite",[Ce.Records,Ce.Schema,Ce.SessionState],async o=>{const i=o.objectStore(Ce.Records),a=o.objectStore(Ce.Schema),l=o.objectStore(Ce.SessionState);await i.clear();for(const[c,u]of Object.entries(n))await i.put(u,c);a.put(e.serialize(),Ce.Schema),s&&r?l.put({snapshot:s,updatedAt:Date.now(),id:r},r):(s||r)&&console.error("sessionStateSnapshot and instanceId must be provided together")})}async pruneSessions(){await this.tx("readwrite",[Ce.SessionState],async e=>{const n=e.objectStore(Ce.SessionState),r=(await n.getAll()).sort((o,i)=>o.updatedAt-i.updatedAt);if(r.length<10){await e.done;return}const s=r.slice(0,r.length-10);for(const{id:o}of s)await n.delete(o)})}async getAsset(e){return await this.tx("readonly",[Ce.Assets],async n=>await n.objectStore(Ce.Assets).get(e))}async storeAsset(e,n){await this.tx("readwrite",[Ce.Assets],async r=>{await r.objectStore(Ce.Assets).put(n,e)})}};I(mu,"connectedInstances",new Set);let wp=mu;function Q0(){const t=JSON.parse(_0(fA)||"[]")??[];return Array.isArray(t)?t:[]}function BV(t){const e=new Set(Q0());e.add(t),I0(fA,JSON.stringify([...e]))}class af{constructor(e){I(this,"nextValue");I(this,"diff");this.previousValue=e}get(){var r,s,o,i;const e=((s=(r=this.diff)==null?void 0:r.removed)==null?void 0:s.size)??0,n=((i=(o=this.diff)==null?void 0:o.added)==null?void 0:i.size)??0;if(!(e===0&&n===0))return{value:this.nextValue,diff:this.diff}}_add(e,n){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.add(e),this.diff??(this.diff={}),n?(r=this.diff.removed)==null||r.delete(e):((s=this.diff).added??(s.added=new Set),this.diff.added.add(e))}add(e){var s,o,i;const n=this.previousValue.has(e);if(n)return((o=(s=this.diff)==null?void 0:s.removed)==null?void 0:o.has(e))?this._add(e,n):void 0;(i=this.nextValue)!=null&&i.has(e)||this._add(e,n)}_remove(e,n){var r,s;this.nextValue??(this.nextValue=new Set(this.previousValue)),this.nextValue.delete(e),this.diff??(this.diff={}),n?((r=this.diff).removed??(r.removed=new Set),this.diff.removed.add(e)):(s=this.diff.added)==null||s.delete(e)}remove(e){var s,o,i,a;const n=this.previousValue.has(e);if(!n)return((o=(s=this.diff)==null?void 0:s.added)==null?void 0:o.has(e))?this._remove(e,n):void 0;(a=(i=this.diff)==null?void 0:i.removed)!=null&&a.has(e)||this._remove(e,n)}}class Mg{constructor(e,n){I(this,"createDefaultProperties");I(this,"validator");I(this,"ephemeralKeys");I(this,"ephemeralKeySet");I(this,"scope");this.typeName=e,this.createDefaultProperties=n.createDefaultProperties,this.validator=n.validator??{validate:s=>s},this.scope=n.scope??"document",this.ephemeralKeys=n.ephemeralKeys;const r=new Set;if(n.ephemeralKeys)for(const[s,o]of Xn(n.ephemeralKeys))o&&r.add(s);this.ephemeralKeySet=r}create(e){const n={...this.createDefaultProperties(),id:this.createId()};for(const[r,s]of Object.entries(e))s!==void 0&&(n[r]=s);return n.typeName=this.typeName,n}clone(e){return{...nt(e),id:this.createId()}}createId(e){return this.typeName+":"+(e??ze())}createCustomId(e){return this.typeName+":"+e}parseId(e){if(!this.isId(e))throw new Error(`ID "${e}" is not a valid ID for type "${this.typeName}"`);return e.slice(this.typeName.length+1)}isInstance(e){return(e==null?void 0:e.typeName)===this.typeName}isId(e){if(!e)return!1;for(let n=0;n<this.typeName.length;n++)if(e[n]!==this.typeName[n])return!1;return e[this.typeName.length]===":"}withDefaultProperties(e){return new Mg(this.typeName,{createDefaultProperties:e,validator:this.validator,scope:this.scope,ephemeralKeys:this.ephemeralKeys})}validate(e,n){return n&&this.validator.validateUsingKnownGoodVersion?this.validator.validateUsingKnownGoodVersion(n,e):this.validator.validate(e)}}function Hs(t,e){return new Mg(t,{createDefaultProperties:()=>({}),validator:e.validator,scope:e.scope,ephemeralKeys:e.ephemeralKeys})}function bp(){return{added:{},updated:{},removed:{}}}function px(t){const e={added:t.removed,removed:t.added,updated:{}};for(const[n,r]of Object.values(t.updated))e.updated[n.id]=[r,n];return e}function gA(t){return Object.keys(t.added).length===0&&Object.keys(t.updated).length===0&&Object.keys(t.removed).length===0}function J0(t){const e={added:{},removed:{},updated:{}};return lu(e,t),e}function lu(t,e){for(const n of e){for(const[r,s]of Xn(n.added))if(t.removed[r]){const o=t.removed[r];delete t.removed[r],o!==s&&(t.updated[r]=[o,s])}else t.added[r]=s;for(const[r,[s,o]]of Xn(n.updated)){if(t.added[r]){t.added[r]=o,delete t.updated[r],delete t.removed[r];continue}if(t.updated[r]){t.updated[r]=[t.updated[r][0],o],delete t.removed[r];continue}t.updated[r]=n.updated[r],delete t.removed[r]}for(const[r,s]of Xn(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]=s}}var Pp={exports:{}};Pp.exports;(function(t,e){var n=200,r="__lodash_hash_undefined__",s=1,o=2,i=9007199254740991,a="[object Arguments]",l="[object Array]",c="[object AsyncFunction]",u="[object Boolean]",h="[object Date]",f="[object Error]",p="[object Function]",g="[object GeneratorFunction]",m="[object Map]",v="[object Number]",y="[object Null]",S="[object Object]",b="[object Promise]",P="[object Proxy]",C="[object RegExp]",_="[object Set]",E="[object String]",k="[object Symbol]",D="[object Undefined]",T="[object WeakMap]",j="[object ArrayBuffer]",L="[object DataView]",M="[object Float32Array]",O="[object Float64Array]",F="[object Int8Array]",B="[object Int16Array]",K="[object Int32Array]",R="[object Uint8Array]",H="[object Uint8ClampedArray]",X="[object Uint16Array]",te="[object Uint32Array]",le=/[\\^$.*+?()[\]{}|]/g,de=/^\[object .+?Constructor\]$/,Me=/^(?:0|[1-9]\d*)$/,oe={};oe[M]=oe[O]=oe[F]=oe[B]=oe[K]=oe[R]=oe[H]=oe[X]=oe[te]=!0,oe[a]=oe[l]=oe[j]=oe[u]=oe[L]=oe[h]=oe[f]=oe[p]=oe[m]=oe[v]=oe[S]=oe[C]=oe[_]=oe[E]=oe[T]=!1;var Ue=typeof dn=="object"&&dn&&dn.Object===Object&&dn,Ne=typeof self=="object"&&self&&self.Object===Object&&self,lt=Ue||Ne||Function("return this")(),$e=e&&!e.nodeType&&e,Ye=$e&&!0&&t&&!t.nodeType&&t,We=Ye&&Ye.exports===$e,er=We&&Ue.process,$t=function(){try{return er&&er.binding&&er.binding("util")}catch{}}(),On=$t&&$t.isTypedArray;function Mt(A,$){for(var V=-1,ne=A==null?0:A.length,Je=0,Se=[];++V<ne;){var mt=A[V];$(mt,V,A)&&(Se[Je++]=mt)}return Se}function Ft(A,$){for(var V=-1,ne=$.length,Je=A.length;++V<ne;)A[Je+V]=$[V];return A}function jo(A,$){for(var V=-1,ne=A==null?0:A.length;++V<ne;)if($(A[V],V,A))return!0;return!1}function Ys(A,$){for(var V=-1,ne=Array(A);++V<A;)ne[V]=$(V);return ne}function Oo(A){return function($){return A($)}}function Mm(A,$){return A.has($)}function ON(A,$){return A==null?void 0:A[$]}function DN(A){var $=-1,V=Array(A.size);return A.forEach(function(ne,Je){V[++$]=[Je,ne]}),V}function RN(A,$){return function(V){return A($(V))}}function LN(A){var $=-1,V=Array(A.size);return A.forEach(function(ne){V[++$]=ne}),V}var $N=Array.prototype,FN=Function.prototype,Ad=Object.prototype,Am=lt["__core-js_shared__"],eP=FN.toString,ps=Ad.hasOwnProperty,tP=function(){var A=/[^.]+$/.exec(Am&&Am.keys&&Am.keys.IE_PROTO||"");return A?"Symbol(src)_1."+A:""}(),nP=Ad.toString,NN=RegExp("^"+eP.call(ps).replace(le,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rP=We?lt.Buffer:void 0,jd=lt.Symbol,sP=lt.Uint8Array,oP=Ad.propertyIsEnumerable,zN=$N.splice,Li=jd?jd.toStringTag:void 0,iP=Object.getOwnPropertySymbols,BN=rP?rP.isBuffer:void 0,UN=RN(Object.keys,Object),jm=Ta(lt,"DataView"),cc=Ta(lt,"Map"),Om=Ta(lt,"Promise"),Dm=Ta(lt,"Set"),Rm=Ta(lt,"WeakMap"),uc=Ta(Object,"create"),HN=Ni(jm),KN=Ni(cc),WN=Ni(Om),GN=Ni(Dm),VN=Ni(Rm),aP=jd?jd.prototype:void 0,Lm=aP?aP.valueOf:void 0;function $i(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function YN(){this.__data__=uc?uc(null):{},this.size=0}function XN(A){var $=this.has(A)&&delete this.__data__[A];return this.size-=$?1:0,$}function qN(A){var $=this.__data__;if(uc){var V=$[A];return V===r?void 0:V}return ps.call($,A)?$[A]:void 0}function ZN(A){var $=this.__data__;return uc?$[A]!==void 0:ps.call($,A)}function QN(A,$){var V=this.__data__;return this.size+=this.has(A)?0:1,V[A]=uc&&$===void 0?r:$,this}$i.prototype.clear=YN,$i.prototype.delete=XN,$i.prototype.get=qN,$i.prototype.has=ZN,$i.prototype.set=QN;function Xs(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function JN(){this.__data__=[],this.size=0}function e4(A){var $=this.__data__,V=Dd($,A);if(V<0)return!1;var ne=$.length-1;return V==ne?$.pop():zN.call($,V,1),--this.size,!0}function t4(A){var $=this.__data__,V=Dd($,A);return V<0?void 0:$[V][1]}function n4(A){return Dd(this.__data__,A)>-1}function r4(A,$){var V=this.__data__,ne=Dd(V,A);return ne<0?(++this.size,V.push([A,$])):V[ne][1]=$,this}Xs.prototype.clear=JN,Xs.prototype.delete=e4,Xs.prototype.get=t4,Xs.prototype.has=n4,Xs.prototype.set=r4;function Fi(A){var $=-1,V=A==null?0:A.length;for(this.clear();++$<V;){var ne=A[$];this.set(ne[0],ne[1])}}function s4(){this.size=0,this.__data__={hash:new $i,map:new(cc||Xs),string:new $i}}function o4(A){var $=Rd(this,A).delete(A);return this.size-=$?1:0,$}function i4(A){return Rd(this,A).get(A)}function a4(A){return Rd(this,A).has(A)}function l4(A,$){var V=Rd(this,A),ne=V.size;return V.set(A,$),this.size+=V.size==ne?0:1,this}Fi.prototype.clear=s4,Fi.prototype.delete=o4,Fi.prototype.get=i4,Fi.prototype.has=a4,Fi.prototype.set=l4;function Od(A){var $=-1,V=A==null?0:A.length;for(this.__data__=new Fi;++$<V;)this.add(A[$])}function c4(A){return this.__data__.set(A,r),this}function u4(A){return this.__data__.has(A)}Od.prototype.add=Od.prototype.push=c4,Od.prototype.has=u4;function Do(A){var $=this.__data__=new Xs(A);this.size=$.size}function d4(){this.__data__=new Xs,this.size=0}function h4(A){var $=this.__data__,V=$.delete(A);return this.size=$.size,V}function f4(A){return this.__data__.get(A)}function p4(A){return this.__data__.has(A)}function g4(A,$){var V=this.__data__;if(V instanceof Xs){var ne=V.__data__;if(!cc||ne.length<n-1)return ne.push([A,$]),this.size=++V.size,this;V=this.__data__=new Fi(ne)}return V.set(A,$),this.size=V.size,this}Do.prototype.clear=d4,Do.prototype.delete=h4,Do.prototype.get=f4,Do.prototype.has=p4,Do.prototype.set=g4;function m4(A,$){var V=Ld(A),ne=!V&&A4(A),Je=!V&&!ne&&$m(A),Se=!V&&!ne&&!Je&&mP(A),mt=V||ne||Je||Se,At=mt?Ys(A.length,String):[],Nt=At.length;for(var ct in A)ps.call(A,ct)&&!(mt&&(ct=="length"||Je&&(ct=="offset"||ct=="parent")||Se&&(ct=="buffer"||ct=="byteLength"||ct=="byteOffset")||I4(ct,Nt)))&&At.push(ct);return At}function Dd(A,$){for(var V=A.length;V--;)if(hP(A[V][0],$))return V;return-1}function y4(A,$,V){var ne=$(A);return Ld(A)?ne:Ft(ne,V(A))}function dc(A){return A==null?A===void 0?D:y:Li&&Li in Object(A)?C4(A):M4(A)}function lP(A){return hc(A)&&dc(A)==a}function cP(A,$,V,ne,Je){return A===$?!0:A==null||$==null||!hc(A)&&!hc($)?A!==A&&$!==$:S4(A,$,V,ne,cP,Je)}function S4(A,$,V,ne,Je,Se){var mt=Ld(A),At=Ld($),Nt=mt?l:Ro(A),ct=At?l:Ro($);Nt=Nt==a?S:Nt,ct=ct==a?S:ct;var tr=Nt==S,Ur=ct==S,en=Nt==ct;if(en&&$m(A)){if(!$m($))return!1;mt=!0,tr=!1}if(en&&!tr)return Se||(Se=new Do),mt||mP(A)?uP(A,$,V,ne,Je,Se):b4(A,$,Nt,V,ne,Je,Se);if(!(V&s)){var Pr=tr&&ps.call(A,"__wrapped__"),Cr=Ur&&ps.call($,"__wrapped__");if(Pr||Cr){var Lo=Pr?A.value():A,qs=Cr?$.value():$;return Se||(Se=new Do),Je(Lo,qs,V,ne,Se)}}return en?(Se||(Se=new Do),P4(A,$,V,ne,Je,Se)):!1}function v4(A){if(!gP(A)||k4(A))return!1;var $=fP(A)?NN:de;return $.test(Ni(A))}function x4(A){return hc(A)&&pP(A.length)&&!!oe[dc(A)]}function w4(A){if(!T4(A))return UN(A);var $=[];for(var V in Object(A))ps.call(A,V)&&V!="constructor"&&$.push(V);return $}function uP(A,$,V,ne,Je,Se){var mt=V&s,At=A.length,Nt=$.length;if(At!=Nt&&!(mt&&Nt>At))return!1;var ct=Se.get(A);if(ct&&Se.get($))return ct==$;var tr=-1,Ur=!0,en=V&o?new Od:void 0;for(Se.set(A,$),Se.set($,A);++tr<At;){var Pr=A[tr],Cr=$[tr];if(ne)var Lo=mt?ne(Cr,Pr,tr,$,A,Se):ne(Pr,Cr,tr,A,$,Se);if(Lo!==void 0){if(Lo)continue;Ur=!1;break}if(en){if(!jo($,function(qs,zi){if(!Mm(en,zi)&&(Pr===qs||Je(Pr,qs,V,ne,Se)))return en.push(zi)})){Ur=!1;break}}else if(!(Pr===Cr||Je(Pr,Cr,V,ne,Se))){Ur=!1;break}}return Se.delete(A),Se.delete($),Ur}function b4(A,$,V,ne,Je,Se,mt){switch(V){case L:if(A.byteLength!=$.byteLength||A.byteOffset!=$.byteOffset)return!1;A=A.buffer,$=$.buffer;case j:return!(A.byteLength!=$.byteLength||!Se(new sP(A),new sP($)));case u:case h:case v:return hP(+A,+$);case f:return A.name==$.name&&A.message==$.message;case C:case E:return A==$+"";case m:var At=DN;case _:var Nt=ne&s;if(At||(At=LN),A.size!=$.size&&!Nt)return!1;var ct=mt.get(A);if(ct)return ct==$;ne|=o,mt.set(A,$);var tr=uP(At(A),At($),ne,Je,Se,mt);return mt.delete(A),tr;case k:if(Lm)return Lm.call(A)==Lm.call($)}return!1}function P4(A,$,V,ne,Je,Se){var mt=V&s,At=dP(A),Nt=At.length,ct=dP($),tr=ct.length;if(Nt!=tr&&!mt)return!1;for(var Ur=Nt;Ur--;){var en=At[Ur];if(!(mt?en in $:ps.call($,en)))return!1}var Pr=Se.get(A);if(Pr&&Se.get($))return Pr==$;var Cr=!0;Se.set(A,$),Se.set($,A);for(var Lo=mt;++Ur<Nt;){en=At[Ur];var qs=A[en],zi=$[en];if(ne)var yP=mt?ne(zi,qs,en,$,A,Se):ne(qs,zi,en,A,$,Se);if(!(yP===void 0?qs===zi||Je(qs,zi,V,ne,Se):yP)){Cr=!1;break}Lo||(Lo=en=="constructor")}if(Cr&&!Lo){var $d=A.constructor,Fd=$.constructor;$d!=Fd&&"constructor"in A&&"constructor"in $&&!(typeof $d=="function"&&$d instanceof $d&&typeof Fd=="function"&&Fd instanceof Fd)&&(Cr=!1)}return Se.delete(A),Se.delete($),Cr}function dP(A){return y4(A,D4,_4)}function Rd(A,$){var V=A.__data__;return E4($)?V[typeof $=="string"?"string":"hash"]:V.map}function Ta(A,$){var V=ON(A,$);return v4(V)?V:void 0}function C4(A){var $=ps.call(A,Li),V=A[Li];try{A[Li]=void 0;var ne=!0}catch{}var Je=nP.call(A);return ne&&($?A[Li]=V:delete A[Li]),Je}var _4=iP?function(A){return A==null?[]:(A=Object(A),Mt(iP(A),function($){return oP.call(A,$)}))}:R4,Ro=dc;(jm&&Ro(new jm(new ArrayBuffer(1)))!=L||cc&&Ro(new cc)!=m||Om&&Ro(Om.resolve())!=b||Dm&&Ro(new Dm)!=_||Rm&&Ro(new Rm)!=T)&&(Ro=function(A){var $=dc(A),V=$==S?A.constructor:void 0,ne=V?Ni(V):"";if(ne)switch(ne){case HN:return L;case KN:return m;case WN:return b;case GN:return _;case VN:return T}return $});function I4(A,$){return $=$??i,!!$&&(typeof A=="number"||Me.test(A))&&A>-1&&A%1==0&&A<$}function E4(A){var $=typeof A;return $=="string"||$=="number"||$=="symbol"||$=="boolean"?A!=="__proto__":A===null}function k4(A){return!!tP&&tP in A}function T4(A){var $=A&&A.constructor,V=typeof $=="function"&&$.prototype||Ad;return A===V}function M4(A){return nP.call(A)}function Ni(A){if(A!=null){try{return eP.call(A)}catch{}try{return A+""}catch{}}return""}function hP(A,$){return A===$||A!==A&&$!==$}var A4=lP(function(){return arguments}())?lP:function(A){return hc(A)&&ps.call(A,"callee")&&!oP.call(A,"callee")},Ld=Array.isArray;function j4(A){return A!=null&&pP(A.length)&&!fP(A)}var $m=BN||L4;function O4(A,$){return cP(A,$)}function fP(A){if(!gP(A))return!1;var $=dc(A);return $==p||$==g||$==c||$==P}function pP(A){return typeof A=="number"&&A>-1&&A%1==0&&A<=i}function gP(A){var $=typeof A;return A!=null&&($=="object"||$=="function")}function hc(A){return A!=null&&typeof A=="object"}var mP=On?Oo(On):x4;function D4(A){return j4(A)?m4(A):w4(A)}function R4(){return[]}function L4(){return!1}t.exports=O4})(Pp,Pp.exports);var UV=Pp.exports;const mA=wi(UV);function HV(t){if(t.length===0)return new Set;const e=t[0],n=t.slice(1),r=new Set;for(const s of e)n.every(o=>o.has(s))&&r.add(s);return r}function KV(t,e){const n={};for(const r of e)t.has(r)||(n.added??(n.added=new Set),n.added.add(r));for(const r of t)e.has(r)||(n.removed??(n.removed=new Set),n.removed.add(r));return n.added||n.removed?n:void 0}function U_(t,e){for(const[n,r]of Object.entries(t)){const s=r,o=e[n];if("eq"in s&&o!==s.eq||"neq"in s&&o===s.neq||"gt"in s&&(typeof o!="number"||o<=s.gt))return!1}return!0}function H_(t,e,n){const r=Object.fromEntries(Object.keys(n).map(s=>[s,new Set]));for(const[s,o]of Object.entries(n))if("eq"in o){const a=t.index(e,s).get().get(o.eq);if(a)for(const l of a)r[s].add(l)}else if("neq"in o){const i=t.index(e,s);for(const[a,l]of i.get())if(a!==o.neq)for(const c of l)r[s].add(c)}else if("gt"in o){const i=t.index(e,s);for(const[a,l]of i.get())if(a>o.gt)for(const c of l)r[s].add(c)}return HV(Object.values(r))}class WV{constructor(e,n){I(this,"indexCache",new Map);I(this,"historyCache",new Map);this.atoms=e,this.history=n}filterHistory(e){if(this.historyCache.has(e))return this.historyCache.get(e);const n=G("filterHistory:"+e,(r,s)=>{if(Qi(r))return this.history.get();const o=this.history.getDiffSince(s);if(o===ur)return this.history.get();const i={added:{},removed:{},updated:{}};let a=0,l=0,c=0;for(const u of o){for(const h of ut(u.added))if(h.typeName===e)if(i.removed[h.id]){const f=i.removed[h.id];delete i.removed[h.id],l--,f!==h&&(i.updated[h.id]=[f,h],c++)}else i.added[h.id]=h,a++;for(const[h,f]of ut(u.updated))f.typeName===e&&(i.added[f.id]?i.added[f.id]=f:i.updated[f.id]?i.updated[f.id]=[i.updated[f.id][0],f]:(i.updated[f.id]=[h,f],c++));for(const h of ut(u.removed))h.typeName===e&&(i.added[h.id]?(delete i.added[h.id],a--):i.updated[h.id]?(i.removed[h.id]=i.updated[h.id][0],delete i.updated[h.id],c--,l++):(i.removed[h.id]=h,l++))}return a||l||c?Kc(this.history.get(),i):r},{historyLength:100});return this.historyCache.set(e,n),n}index(e,n){const r=e+":"+n;if(this.indexCache.has(r))return this.indexCache.get(r);const s=this.__uncached_createIndex(e,n);return this.indexCache.set(r,s),s}__uncached_createIndex(e,n){const r=this.filterHistory(e),s=()=>{r.get();const o=new Map;for(const i of ut(this.atoms.get())){const a=i.get();if(a.typeName===e){const l=a[n];o.has(l)||o.set(l,new Set),o.get(l).add(a.id)}}return o};return G("index:"+e+":"+n,(o,i)=>{if(Qi(o))return s();const a=r.getDiffSince(i);if(a===ur)return s();const l=new Map,c=(p,g)=>{let m=l.get(p);m||(m=new af(o.get(p)??new Set)),m.add(g),l.set(p,m)},u=(p,g)=>{let m=l.get(p);m||(m=new af(o.get(p)??new Set)),m.remove(g),l.set(p,m)};for(const p of a){for(const g of ut(p.added))if(g.typeName===e){const m=g[n];c(m,g.id)}for(const[g,m]of ut(p.updated))if(m.typeName===e){const v=g[n],y=m[n];v!==y&&(u(v,m.id),c(y,m.id))}for(const g of ut(p.removed))if(g.typeName===e){const m=g[n];u(m,g.id)}}let h,f;for(const[p,g]of l){const m=g.get();m&&(h||(h=new Map(o)),f||(f=new Map),m.value.size===0?h.delete(p):h.set(p,m.value),f.set(p,m.diff))}return h&&f?Kc(h,f):o},{historyLength:100})}record(e,n=()=>({}),r="record:"+e+(n?":"+n.toString():"")){const s=this.ids(e,n,r);return G(r,()=>{var o;for(const i of s.get())return(o=this.atoms.get()[i])==null?void 0:o.get()})}records(e,n=()=>({}),r="records:"+e+(n?":"+n.toString():"")){const s=this.ids(e,n,"ids:"+r);return G(r,()=>{const o=this.atoms.get();return[...s.get()].map(i=>{const a=o[i];if(!a)throw new Error("no atom found for record id: "+i);return a.get()})},{isEqual:LT})}ids(e,n=()=>({}),r="ids:"+e+(n?":"+n.toString():"")){const s=this.filterHistory(e),o=()=>{s.get();const l=n();return Object.keys(l).length===0?new Set(ut(this.atoms.get()).flatMap(c=>{const u=c.get();return u.typeName===e?u.id:[]})):H_(this,e,l)},i=l=>{const c=o(),u=KV(l,c);return u?Kc(c,u):l},a=G("ids_query:"+r,n,{isEqual:mA});return G("query:"+r,(l,c)=>{const u=a.get();if(Qi(l))return o();if(c<a.lastChangedEpoch)return i(l);const h=s.getDiffSince(c);if(h===ur)return i(l);const f=new af(l);for(const g of h){for(const m of ut(g.added))m.typeName===e&&U_(u,m)&&f.add(m.id);for(const[m,v]of ut(g.updated))v.typeName===e&&(U_(u,v)?f.add(v.id):f.remove(v.id));for(const m of ut(g.removed))m.typeName===e&&f.remove(m.id)}const p=f.get();return p?Kc(p.value,p.diff):l},{historyLength:50})}exec(e,n){const r=H_(this,e,n);if(r.size===0)return fo;const s=this.atoms.get();return[...r].map(o=>s[o].get())}}class GV{constructor(e){I(this,"_beforeCreateHandlers",{});I(this,"_afterCreateHandlers",{});I(this,"_beforeChangeHandlers",{});I(this,"_afterChangeHandlers",{});I(this,"_beforeDeleteHandlers",{});I(this,"_afterDeleteHandlers",{});I(this,"_operationCompleteHandlers",[]);I(this,"_isEnabled",!0);this.store=e}isEnabled(){return this._isEnabled}setIsEnabled(e){this._isEnabled=e}handleBeforeCreate(e,n){if(!this._isEnabled)return e;const r=this._beforeCreateHandlers[e.typeName];if(r){let s=e;for(const o of r)s=o(s,n);return s}return e}handleAfterCreate(e,n){if(!this._isEnabled)return;const r=this._afterCreateHandlers[e.typeName];if(r)for(const s of r)s(e,n)}handleBeforeChange(e,n,r){if(!this._isEnabled)return n;const s=this._beforeChangeHandlers[n.typeName];if(s){let o=n;for(const i of s)o=i(e,o,r);return o}return n}handleAfterChange(e,n,r){if(!this._isEnabled)return;const s=this._afterChangeHandlers[n.typeName];if(s)for(const o of s)o(e,n,r)}handleBeforeDelete(e,n){if(!this._isEnabled)return!0;const r=this._beforeDeleteHandlers[e.typeName];if(r){for(const s of r)if(s(e,n)===!1)return!1}return!0}handleAfterDelete(e,n){if(!this._isEnabled)return;const r=this._afterDeleteHandlers[e.typeName];if(r)for(const s of r)s(e,n)}handleOperationComplete(e){if(this._isEnabled)for(const n of this._operationCompleteHandlers)n(e)}register(e){const n=[];for(const[r,s]of Object.entries(e))s!=null&&s.beforeCreate&&n.push(this.registerBeforeCreateHandler(r,s.beforeCreate)),s!=null&&s.afterCreate&&n.push(this.registerAfterCreateHandler(r,s.afterCreate)),s!=null&&s.beforeChange&&n.push(this.registerBeforeChangeHandler(r,s.beforeChange)),s!=null&&s.afterChange&&n.push(this.registerAfterChangeHandler(r,s.afterChange)),s!=null&&s.beforeDelete&&n.push(this.registerBeforeDeleteHandler(r,s.beforeDelete)),s!=null&&s.afterDelete&&n.push(this.registerAfterDeleteHandler(r,s.afterDelete));return()=>{for(const r of n)r()}}registerBeforeCreateHandler(e,n){return this._beforeCreateHandlers[e]||(this._beforeCreateHandlers[e]=[]),this._beforeCreateHandlers[e].push(n),()=>Bi(this._beforeCreateHandlers[e],n)}registerAfterCreateHandler(e,n){return this._afterCreateHandlers[e]||(this._afterCreateHandlers[e]=[]),this._afterCreateHandlers[e].push(n),()=>Bi(this._afterCreateHandlers[e],n)}registerBeforeChangeHandler(e,n){return this._beforeChangeHandlers[e]||(this._beforeChangeHandlers[e]=[]),this._beforeChangeHandlers[e].push(n),()=>Bi(this._beforeChangeHandlers[e],n)}registerAfterChangeHandler(e,n){return this._afterChangeHandlers[e]||(this._afterChangeHandlers[e]=[]),this._afterChangeHandlers[e].push(n),()=>Bi(this._afterChangeHandlers[e],n)}registerBeforeDeleteHandler(e,n){return this._beforeDeleteHandlers[e]||(this._beforeDeleteHandlers[e]=[]),this._beforeDeleteHandlers[e].push(n),()=>Bi(this._beforeDeleteHandlers[e],n)}registerAfterDeleteHandler(e,n){return this._afterDeleteHandlers[e]||(this._afterDeleteHandlers[e]=[]),this._afterDeleteHandlers[e].push(n),()=>Bi(this._afterDeleteHandlers[e],n)}registerOperationCompleteHandler(e){return this._operationCompleteHandlers.push(e),()=>Bi(this._operationCompleteHandlers,e)}}function Bi(t,e){const n=t.indexOf(e);n>=0&&t.splice(n,1)}class eb{constructor(e){I(this,"id");I(this,"atoms",It("store_atoms",{}));I(this,"history",It("history",0,{historyLength:1e3}));I(this,"query",new WV(this.atoms,this.history));I(this,"listeners",new Set);I(this,"historyAccumulator",new YV);I(this,"historyReactor");I(this,"schema");I(this,"props");I(this,"scopedTypes");I(this,"sideEffects",new GV(this));I(this,"isMergingRemoteChanges",!1);I(this,"_integrityChecker");I(this,"_isPossiblyCorrupted",!1);I(this,"pendingAfterEvents",null);I(this,"_isInAtomicOp",!1);const{initialData:n,schema:r,id:s}=e;this.id=s??ze(),this.schema=r,this.props=e.props,n&&this.atoms.set(w0(Xn(n).map(([o,i])=>[o,It("atom:"+o,this.schema.validateRecord(this,i,"initialize",null))]))),this.historyReactor=uV("Store.historyReactor",()=>{this.history.get(),this._flushHistory()},{scheduleEffect:o=>this.cancelHistoryReactor=nM(o)}),this.scopedTypes={document:new Set(ut(this.schema.types).filter(o=>o.scope==="document").map(o=>o.typeName)),session:new Set(ut(this.schema.types).filter(o=>o.scope==="session").map(o=>o.typeName)),presence:new Set(ut(this.schema.types).filter(o=>o.scope==="presence").map(o=>o.typeName))}}cancelHistoryReactor(){}_flushHistory(){if(this.historyAccumulator.hasChanges()){const e=this.historyAccumulator.flush();for(const{changes:n,source:r}of e){let s=null,o=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(o??(o=this.filterChangesByScope(n,"document")),!o)continue;a({changes:o,source:r})}else if(l.scope==="session"){if(s??(s=this.filterChangesByScope(n,"session")),!s)continue;a({changes:s,source:r})}else{if(i??(i=this.filterChangesByScope(n,"presence")),!i)continue;a({changes:i,source:r})}else a({changes:n,source:r})}}}dispose(){this.cancelHistoryReactor()}filterChangesByScope(e,n){const r={added:au(e.added,(s,o)=>this.scopedTypes[n].has(o.typeName)),updated:au(e.updated,(s,o)=>this.scopedTypes[n].has(o[1].typeName)),removed:au(e.removed,(s,o)=>this.scopedTypes[n].has(o.typeName))};return Object.keys(r.added).length===0&&Object.keys(r.updated).length===0&&Object.keys(r.removed).length===0?null:r}updateHistory(e){this.historyAccumulator.add({changes:e,source:this.isMergingRemoteChanges?"remote":"user"}),this.listeners.size===0&&this.historyAccumulator.clear(),this.history.set(this.history.get()+1,e)}validate(e){this.allRecords().forEach(n=>this.schema.validateRecord(this,n,e,null))}put(e,n){this.atomic(()=>{const r={},s={},o=this.atoms.__unsafe__getWithoutCapture();let i=null,a,l=!1;const c=this.isMergingRemoteChanges?"remote":"user";for(let u=0,h=e.length;u<h;u++){a=e[u];const f=(i??o)[a.id];if(f){const p=f.__unsafe__getWithoutCapture();if(a=this.sideEffects.handleBeforeChange(p,a,c),this.schema.validateRecord(this,a,n??"updateRecord",p)===p)continue;f.set(a),l=!0;const m=f.__unsafe__getWithoutCapture();r[a.id]=[p,m],this.addDiffForAfterEvent(p,m)}else a=this.sideEffects.handleBeforeCreate(a,c),l=!0,a=this.schema.validateRecord(this,a,n??"createRecord",null),s[a.id]=a,this.addDiffForAfterEvent(null,a),i||(i={...o}),i[a.id]=It("atom:"+a.id,a)}i&&this.atoms.set(i),l&&this.updateHistory({added:s,updated:r,removed:{}})})}remove(e){this.atomic(()=>{const n=new Set,r=this.isMergingRemoteChanges?"remote":"user";if(this.sideEffects.isEnabled())for(const o of e){const i=this.atoms.__unsafe__getWithoutCapture()[o];i&&this.sideEffects.handleBeforeDelete(i.get(),r)===!1&&n.add(o)}let s;this.atoms.update(o=>{let i;for(const a of e){if(n.has(a)||!(a in o))continue;i||(i={...o}),s||(s={}),delete i[a];const l=o[a].get();s[a]=l,this.addDiffForAfterEvent(l,null)}return i??o}),s&&this.updateHistory({added:{},updated:{},removed:s})})}get(e){var n;return(n=this.atoms.get()[e])==null?void 0:n.get()}unsafeGetWithoutCapture(e){var n;return(n=this.atoms.__unsafe__getWithoutCapture()[e])==null?void 0:n.__unsafe__getWithoutCapture()}serialize(e="document"){const n={};for(const[r,s]of Xn(this.atoms.get())){const o=s.get();(e==="all"||this.scopedTypes[e].has(o.typeName))&&(n[r]=o)}return n}getStoreSnapshot(e="document"){return{store:this.serialize(e),schema:this.schema.serialize()}}getSnapshot(e="document"){return console.warn("[tldraw] `Store.getSnapshot` is deprecated and will be removed in a future release. Use `getSnapshot` from the `tldraw` package instead."),this.getStoreSnapshot(e)}migrateSnapshot(e){const n=this.schema.migrateStoreSnapshot(e);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);return{store:n.value,schema:this.schema.serialize()}}loadStoreSnapshot(e){const n=this.schema.migrateStoreSnapshot(e);if(n.type==="error")throw new Error(`Failed to migrate snapshot: ${n.reason}`);const r=this.sideEffects.isEnabled();try{this.sideEffects.setIsEnabled(!1),this.atomic(()=>{this.clear(),this.put(Object.values(n.value)),this.ensureStoreIsUsable()})}finally{this.sideEffects.setIsEnabled(r)}}loadSnapshot(e){console.warn("[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead."),this.loadStoreSnapshot(e)}allRecords(){return ut(this.atoms.get()).map(e=>e.get())}clear(){this.remove(FC(this.atoms.get()))}update(e,n){const r=this.atoms.get()[e];if(!r){console.error(`Record ${e} not found. This is probably an error`);return}this.put([n(r.__unsafe__getWithoutCapture())])}has(e){return!!this.atoms.get()[e]}listen(e,n){this._flushHistory();const r={onHistory:e,filters:{source:(n==null?void 0:n.source)??"all",scope:(n==null?void 0:n.scope)??"all"}};return this.historyReactor.scheduler.isActivelyListening||(this.historyReactor.start(),this.historyReactor.scheduler.execute()),this.listeners.add(r),()=>{this.listeners.delete(r),this.listeners.size===0&&this.historyReactor.stop()}}mergeRemoteChanges(e){if(this.isMergingRemoteChanges)return e();if(this._isInAtomicOp)throw new Error("Cannot merge remote changes while in atomic operation");try{this.isMergingRemoteChanges=!0,js(e)}finally{this.isMergingRemoteChanges=!1,this.ensureStoreIsUsable()}}extractingChanges(e){const n=[],r=this.historyAccumulator.addInterceptor(s=>n.push(s.changes));try{return js(e),J0(n)}finally{r()}}applyDiff(e,{runCallbacks:n=!0,ignoreEphemeralKeys:r=!1}={}){this.atomic(()=>{const s=ut(e.added);for(const[i,a]of ut(e.updated)){const l=this.schema.getType(a.typeName);if(r&&l.ephemeralKeySet.size){const c=this.get(a.id);if(!c){s.push(a);continue}let u=null;for(const[h,f]of Object.entries(a))l.ephemeralKeySet.has(h)||Object.is(f,hn(c,h))||(u||(u={...c}),u[h]=f);u&&s.push(u)}else s.push(a)}const o=FC(e.removed);s.length&&this.put(s),o.length&&this.remove(o)},n)}createComputedCache(e,n,r){const s=new Ds;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=r?G(i.name+":equals",()=>i.get(),{isEqual:r}):i;return G(e+":"+o,()=>n(a.get()))}).get()}}}createSelectedComputedCache(e,n,r){const s=new Ds;return{get:o=>{const i=this.atoms.get()[o];if(i)return s.get(i,()=>{const a=G(e+":"+o+":selector",()=>n(i.get()));return G(e+":"+o,()=>r(a.get()))}).get()}}}ensureStoreIsUsable(){this.atomic(()=>{var e;this._integrityChecker??(this._integrityChecker=this.schema.createIntegrityChecker(this)),(e=this._integrityChecker)==null||e.call(this)})}markAsPossiblyCorrupted(){this._isPossiblyCorrupted=!0}isPossiblyCorrupted(){return this._isPossiblyCorrupted}addDiffForAfterEvent(e,n){if(Le(this.pendingAfterEvents,"must be in event operation"),e===n||(e&&n&&Le(e.id===n.id),!e&&!n))return;const r=(e||n).id,s=this.pendingAfterEvents.get(r);s?s.after=n:this.pendingAfterEvents.set(r,{before:e,after:n})}flushAtomicCallbacks(){let e=0;const n=this.isMergingRemoteChanges?"remote":"user";for(;this.pendingAfterEvents;){const r=this.pendingAfterEvents;if(this.pendingAfterEvents=null,!!this.sideEffects.isEnabled()){if(e++,e>100)throw new Error("Maximum store update depth exceeded, bailing out");for(const{before:s,after:o}of r.values())s&&o?this.sideEffects.handleAfterChange(s,o,n):s&&!o?this.sideEffects.handleAfterDelete(s,n):!s&&o&&this.sideEffects.handleAfterCreate(o,n);this.pendingAfterEvents||this.sideEffects.handleOperationComplete(n)}}}atomic(e,n=!0){return js(()=>{if(this._isInAtomicOp)return this.pendingAfterEvents||(this.pendingAfterEvents=new Map),e();this.pendingAfterEvents=new Map;const r=this.sideEffects.isEnabled();this.sideEffects.setIsEnabled(n??r),this._isInAtomicOp=!0;try{const s=e();return this.flushAtomicCallbacks(),s}finally{this.pendingAfterEvents=null,this.sideEffects.setIsEnabled(r),this._isInAtomicOp=!1}})}addHistoryInterceptor(e){return this.historyAccumulator.addInterceptor(n=>e(n,this.isMergingRemoteChanges?"remote":"user"))}}function VV(t){if(t.length===0)return[];const e=[];let n=[t[0]],r;for(let s=1,o=t.length;s<o;s++)r=t[s],n[0].source!==r.source&&(e.push(n),n=[]),n.push(r);return e.push(n),e.map(s=>({source:s[0].source,changes:J0(s.map(o=>o.changes))}))}class YV{constructor(){I(this,"_history",[]);I(this,"_interceptors",new Set)}addInterceptor(e){return this._interceptors.add(e),()=>{this._interceptors.delete(e)}}add(e){this._history.push(e);for(const n of this._interceptors)n(e)}flush(){const e=VV(this._history);return this._history=[],e}clear(){this._history=[]}hasChanges(){return this._history.length>0}}function XV(t,e,n){const r=new Ds;return{get(s,o){return r.get(s,()=>(s instanceof eb?s:s.store).createComputedCache(t,l=>e(s,l),n)).get(o)}}}function qV(t){const e=[];for(let n=t.length-1;n>=0;n--){const r=t[n];if("id"in r)e.unshift(r);else{const s=r.dependsOn,o=e[0];o&&(e[0]={...o,dependsOn:s.concat(o.dependsOn??[])})}}return e}function vl({sequence:t,sequenceId:e,retroactive:n=!0}){const r={sequenceId:e,retroactive:n,sequence:qV(t)};return yA(r),r}function Zn(t,e){return Object.fromEntries(Xn(e).map(([n,r])=>[n,`${t}/${r}`]))}function xr(t){const e=t.sequenceId;return vl({sequenceId:e,retroactive:t.retroactive??!0,sequence:t.sequence.map(n=>"id"in n?{...n,scope:"record",filter:r=>{var s,o;return r.typeName===t.recordType&&(((s=n.filter)==null?void 0:s.call(n,r))??!0)&&(((o=t.filter)==null?void 0:o.call(t,r))??!0)}}:n)})}function ZV(t){const e=new Map(t.map(o=>[o.id,o])),n=new Set,r=[];function s(o){Le(!n.has(o.id),`Circular dependency in migrations: ${o.id}`),n.add(o.id);const{version:i,sequenceId:a}=Cp(o.id),l=e.get(`${a}/${i-1}`);if(l&&s(l),o.dependsOn)for(const c of o.dependsOn){const u=e.get(c);u&&s(u)}e.delete(o.id),r.push(o)}for(const o of e.values())s(o);return r}function Cp(t){const[e,n]=t.split("/");return{sequenceId:e,version:parseInt(n)}}function K_(t,e){e&&Le(t.startsWith(e+"/"),`Every migration in sequence '${e}' must have an id starting with '${e}/'. Got invalid id: '${t}'`),Le(t.match(/^(.*?)\/(0|[1-9]\d*)$/),`Invalid migration id: '${t}'`)}function yA(t){if(Le(!t.sequenceId.includes("/"),`sequenceId cannot contain a '/', got ${t.sequenceId}`),Le(t.sequenceId.length,"sequenceId must be a non-empty string"),t.sequence.length===0)return;K_(t.sequence[0].id,t.sequenceId);let e=Cp(t.sequence[0].id).version;Le(e===1,`Expected the first migrationId to be '${t.sequenceId}/1' but got '${t.sequence[0].id}'`);for(let n=1;n<t.sequence.length;n++){const r=t.sequence[n].id;K_(r,t.sequenceId);const s=Cp(r).version;Le(s===e+1,`Migration id numbers must increase in increments of 1, expected ${t.sequenceId}/${e+1} but got '${t.sequence[n].id}'`),e=s}}var Bo=(t=>(t.IncompatibleSubtype="incompatible-subtype",t.UnknownType="unknown-type",t.TargetVersionTooNew="target-version-too-new",t.TargetVersionTooOld="target-version-too-old",t.MigrationError="migration-error",t.UnrecognizedSubtype="unrecognized-subtype",t))(Bo||{});function QV(t){if(t.schemaVersion>2||t.schemaVersion<1)return wn.err("Bad schema version");if(t.schemaVersion===2)return wn.ok(t);const e={schemaVersion:2,sequences:{"com.tldraw.store":t.storeVersion}};for(const[n,r]of Object.entries(t.recordVersions))if(e.sequences[`com.tldraw.${n}`]=r.version,"subTypeKey"in r)for(const[s,o]of Object.entries(r.subTypeVersions))e.sequences[`com.tldraw.${n}.${s}`]=o;return wn.ok(e)}class tb{constructor(e,n){I(this,"migrations",{});I(this,"sortedMigrations");var s;this.types=e,this.options=n;for(const o of n.migrations??[])Le(!this.migrations[o.sequenceId],`Duplicate migration sequenceId ${o.sequenceId}`),yA(o),this.migrations[o.sequenceId]=o;const r=Object.values(this.migrations).flatMap(o=>o.sequence);this.sortedMigrations=ZV(r);for(const o of this.sortedMigrations)if((s=o.dependsOn)!=null&&s.length)for(const i of o.dependsOn){const a=r.find(l=>l.id===i);Le(a,`Migration '${o.id}' depends on missing migration '${i}'`)}}static create(e,n){return new tb(e,n??{})}validateRecord(e,n,r,s){try{const o=hn(this.types,n.typeName);if(!o)throw new Error(`Missing definition for record type ${n.typeName}`);return o.validate(n,s??void 0)}catch(o){if(this.options.onValidationFailure)return this.options.onValidationFailure({store:e,record:n,phase:r,recordBefore:s,error:o});throw o}}getMigrationsSince(e){const n=QV(e);if(!n.ok)return n;const r=n.value,s=new Set(Object.keys(r.sequences).filter(i=>this.migrations[i]));for(const i in this.migrations)r.sequences[i]===void 0&&this.migrations[i].retroactive&&s.add(i);if(s.size===0)return wn.ok([]);const o=new Set;for(const i of s){const a=r.sequences[i];if(typeof a!="number"&&this.migrations[i].retroactive||a===0){for(const u of this.migrations[i].sequence)o.add(u.id);continue}const l=`${i}/${a}`,c=this.migrations[i].sequence.findIndex(u=>u.id===l);if(c===-1)return wn.err("Incompatible schema?");for(const u of this.migrations[i].sequence.slice(c+1))o.add(u.id)}return wn.ok(this.sortedMigrations.filter(({id:i})=>o.has(i)))}migratePersistedRecord(e,n,r="up"){const s=this.getMigrationsSince(n);if(!s.ok)return console.error("Error migrating record",s.error),{type:"error",reason:Bo.MigrationError};let o=s.value;if(o.length===0)return{type:"success",value:e};if(o.some(i=>i.scope==="store"))return{type:"error",reason:r==="down"?Bo.TargetVersionTooOld:Bo.TargetVersionTooNew};if(r==="down"){if(!o.every(i=>i.down))return{type:"error",reason:Bo.TargetVersionTooOld};o=o.slice().reverse()}e=nt(e);try{for(const i of o){if(i.scope==="store")throw new Error;if(!(i.filter?i.filter(e):!0))continue;const l=i[r](e);l&&(e=nt(l))}}catch(i){return console.error("Error migrating record",i),{type:"error",reason:Bo.MigrationError}}return{type:"success",value:e}}migrateStoreSnapshot(e){let{store:n}=e;const r=this.getMigrationsSince(e.schema);if(!r.ok)return console.error("Error migrating store",r.error),{type:"error",reason:Bo.MigrationError};const s=r.value;if(s.length===0)return{type:"success",value:n};n=nt(n);try{for(const o of s)if(o.scope==="record")for(const[i,a]of Object.entries(n)){if(!(o.filter?o.filter(a):!0))continue;const c=o.up(a);c&&(n[i]=nt(c))}else if(o.scope==="store"){const i=o.up(n);i&&(n=nt(i))}else Ot(o)}catch(o){return console.error("Error migrating store",o),{type:"error",reason:Bo.MigrationError}}return{type:"success",value:n}}createIntegrityChecker(e){var n,r;return((r=(n=this.options).createIntegrityChecker)==null?void 0:r.call(n,e))??void 0}serialize(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e,sequence:n})=>[e,n.length?Cp(n.at(-1).id).version:0]))}}serializeEarliestVersion(){return{schemaVersion:2,sequences:Object.fromEntries(Object.values(this.migrations).map(({sequenceId:e})=>[e,0]))}}getType(e){const n=hn(this.types,e);return Le(n,"record type does not exists"),n}}_i("@tldraw/store","3.7.2","esm");function JV(t){if(!t.length)return null;let e="";for(const n of t)typeof n=="number"?e+=`.${n}`:n.startsWith("(")?e.endsWith(")")?e=`${e.slice(0,-1)}, ${n.slice(1)}`:e+=n:e+=`.${n}`;return e=e.replace(/id = [^,]+, /,"").replace(/id = [^)]+/,""),e.startsWith(".")?e.slice(1):e}class Te extends Error{constructor(n,r=[]){const s=JV(r),o=n.split(`
|
|
83
83
|
`).map((i,a)=>a===0?i:` ${i}`).join(`
|
|
84
|
-
`);super(r?`At ${s}: ${o}`:o);I(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function qn(t,e){try{return e()}catch(n){throw n instanceof Te?new Te(n.rawMessage,[t,...n.path]):new Te(n.toString(),[t])}}function gi(t){if(t===null)return"null";if(Array.isArray(t))return"an array";const e=typeof t;switch(e){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${e}`;case"object":return`an ${e}`;case"undefined":return"undefined";default:Ot(e)}}class Tn{constructor(e,n){this.validationFn=e,this.validateUsingKnownGoodVersionFn=n}validate(e){return this.validationFn(e)}validateUsingKnownGoodVersion(e,n){return Object.is(e,n)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,n):this.validate(n)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return oY(this)}optional(){return vA(this)}refine(e){return new Tn(n=>e(this.validate(n)),(n,r)=>{const s=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,s)?n:e(s)})}check(e,n){return typeof e=="string"?this.refine(r=>(qn(`(check ${e})`,()=>n(r)),r)):this.refine(r=>(e(r),r))}}class eY extends Tn{constructor(e){super(n=>{const r=W_.validate(n);for(let s=0;s<r.length;s++)qn(s,()=>e.validate(r[s]));return r},(n,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=W_.validate(r);let o=n.length!==s.length;for(let i=0;i<s.length;i++){const a=s[i];if(i>=n.length){o=!0,qn(i,()=>e.validate(a));continue}if(Object.is(n[i],a))continue;const l=qn(i,()=>e.validateUsingKnownGoodVersion(n[i],a));Object.is(l,n[i])||(o=!0)}return o?r:n}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new Te("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new Te("Expected an array with length greater than 1")})}}class _p extends Tn{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Te(`Expected object, got ${gi(r)}`);for(const[s,o]of Object.entries(e))qn(s,()=>{o.validate(hn(r,s))});if(!n){for(const s of Object.keys(r))if(!ns(e,s))throw new Te("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new Te(`Expected object, got ${gi(s)}`);let o=!1;for(const[i,a]of Object.entries(e)){const l=hn(r,i),c=hn(s,i);if(Object.is(l,c))continue;const u=qn(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(o=!0)}if(!n){for(const i of Object.keys(s))if(!ns(e,i))throw new Te("Unexpected property",[i])}for(const i of Object.keys(r))if(!ns(s,i)){o=!0;break}return o?s:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new _p(this.config,!0)}extend(e){return new _p({...this.config,...e})}}class Ag extends Tn{constructor(e,n,r,s){super(o=>{this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(o);return i===void 0?this.unknownValueValidation(o,a):qn(`(${e} = ${a})`,()=>i.validate(o))},(o,i)=>{this.expectObject(i),this.expectObject(o);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):hn(o,e)!==hn(i,e)?qn(`(${e} = ${l})`,()=>a.validate(i)):qn(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(o,i):a.validate(i))}),this.key=e,this.config=n,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(e){if(typeof e!="object"||e===null)throw new Te(`Expected an object, got ${gi(e)}`,[])}getMatchingSchemaAndVariant(e){const n=hn(e,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Te(`Expected a string for key "${this.key}", got ${gi(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Te(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:ns(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new Ag(this.key,this.config,e,this.useNumberKeys)}}class tY extends Tn{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Te(`Expected object, got ${gi(r)}`);for(const[s,o]of Object.entries(r))qn(s,()=>{e.validate(s),n.validate(o)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new Te(`Expected object, got ${gi(s)}`);let o=!1;for(const[i,a]of Object.entries(s)){if(!ns(r,i)){o=!0,qn(i,()=>{e.validate(i),n.validate(a)});continue}const l=hn(r,i),c=a;if(Object.is(l,c))continue;const u=qn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(o=!0)}for(const i of Object.keys(r))if(!ns(s,i)){o=!0;break}return o?s:r}),this.keyValidator=e,this.valueValidator=n}}function nb(t){return new Tn(e=>{if(typeof e!==t)throw new Te(`Expected ${t}, got ${gi(e)}`);return e})}const nY=new Tn(t=>t),ye=nb("string"),pe=nb("number").check(t=>{if(Number.isNaN(t))throw new Te("Expected a number, got NaN");if(!Number.isFinite(t))throw new Te(`Expected a finite number, got ${t}`)}),Ip=pe.check(t=>{if(t<0)throw new Te(`Expected a positive number, got ${t}`)}),Pt=pe.check(t=>{if(t<=0)throw new Te(`Expected a non-zero positive number, got ${t}`)}),SA=pe.check(t=>{if(!Number.isInteger(t))throw new Te(`Expected an integer, got ${t}`)}),lf=SA.check(t=>{if(t<0)throw new Te(`Expected a positive integer, got ${t}`)}),rY=SA.check(t=>{if(t<=0)throw new Te(`Expected a non-zero positive integer, got ${t}`)}),we=nb("boolean");function mn(t){return new Tn(e=>{if(e!==t)throw new Te(`Expected ${t}, got ${JSON.stringify(e)}`);return t})}const W_=new Tn(t=>{if(!Array.isArray(t))throw new Te(`Expected an array, got ${gi(t)}`);return t});function Wt(t){return new eY(t)}function Pe(t){return new _p(t)}function gx(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===mB)}function mx(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(mx):gx(t)?Object.values(t).every(mx):!1}const Gt=new Tn(t=>{if(mx(t))return t;throw new Te(`Expected json serializable value, got ${typeof t}`)},(t,e)=>{if(Array.isArray(t)&&Array.isArray(e)){let n=t.length!==e.length;for(let r=0;r<e.length;r++){if(r>=t.length){n=!0,Gt.validate(e[r]);continue}const s=t[r],o=e[r];if(Object.is(s,o))continue;const i=Gt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}return n?e:t}else if(gx(t)&&gx(e)){let n=!1;for(const r of Object.keys(e)){if(!ns(t,r)){n=!0,Gt.validate(e[r]);continue}const s=t[r],o=e[r];if(Object.is(s,o))continue;const i=Gt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}for(const r of Object.keys(t))if(!ns(e,r)){n=!0;break}return n?e:t}else return Gt.validate(e)});function Ep(t,e){return new tY(t,e)}function rb(t,e){return new Ag(t,e,(n,r)=>{throw new Te(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!1)}function sY(t,e){return new Ag(t,e,(n,r)=>{throw new Te(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!0)}function Ks(t,e){return new Tn(n=>qn(t,()=>e.validate(n)),(n,r)=>qn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function jg(t){return new Tn(e=>{if(!t.has(e)){const n=Array.from(t,r=>JSON.stringify(r)).join(" or ");throw new Te(`Expected ${n}, got ${e}`)}return e})}function vA(t){return new Tn(e=>{if(e!==void 0)return t.validate(e)},(e,n)=>{if(!(e===void 0&&n===void 0)&&n!==void 0)return t.validateUsingKnownGoodVersion&&e!==void 0?t.validateUsingKnownGoodVersion(e,n):t.validate(n)})}function oY(t){return new Tn(e=>e===null?null:t.validate(e),(e,n)=>n===null?null:t.validateUsingKnownGoodVersion&&e!==null?t.validateUsingKnownGoodVersion(e,n):t.validate(n))}function Og(...t){return jg(new Set(t))}function sb(t){try{return new URL(t)}catch{if(t.startsWith("/")||t.startsWith("./"))try{return new URL(t,"http://example.com")}catch{throw new Te(`Expected a valid url, got ${JSON.stringify(t)}`)}throw new Te(`Expected a valid url, got ${JSON.stringify(t)}`)}}const iY=new Set(["http:","https:","mailto:"]),gr=ye.check(t=>{if(t==="")return;const e=sb(t);if(!iY.has(e.protocol.toLowerCase()))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),aY=new Set(["http:","https:","data:","asset:"]),la=ye.check(t=>{if(t==="")return;const e=sb(t);if(!aY.has(e.protocol.toLowerCase()))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});ye.check(t=>{if(t==="")return;if(!sb(t).protocol.toLowerCase().match(/^https?:$/))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});const ob=ye.refine(t=>{try{return iB(t),t}catch{throw new Te(`Expected an index key, got ${JSON.stringify(t)}`)}});_i("@tldraw/validate","3.8.0-canary.c422debb621c","esm");function dr(t){return ye.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const Dg=dr("asset");function ib(t,e){return Pe({id:Dg,typeName:mn("asset"),type:mn(t),props:e,meta:Gt})}const ca=Pe({x:pe,y:pe,z:pe.optional()}),cu=Pe({x:pe,y:pe,w:pe,h:pe}),xA=pe.check(t=>{if(t<0||t>1)throw new Te("Opacity must be between 0 and 1")}),lY=ye.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),Ir=dr("shape");function cY(t,e,n){return Pe({id:Ir,typeName:mn("shape"),x:pe,y:pe,rotation:pe,index:ob,parentId:lY,type:mn(t),isLocked:we,opacity:xA,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}const uY=dr("binding");function dY(t,e,n){return Pe({id:uY,typeName:mn("binding"),type:mn(t),fromId:Ir,toId:Ir,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}Zn("com.tldraw.binding",{});xr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Ji(t){return`binding:${ze()}`}function hY(t){return Hs("binding",{scope:"document",validator:Ks("binding",rb("type",sd(t,(e,{props:n,meta:r})=>dY(e,n,r))))}).withDefaultProperties(()=>({meta:{}}))}class Qt{constructor(e,n,r){this.id=e,this.defaultValue=n,this.type=r}static define(e,n){const{defaultValue:r,type:s=nY}=n;return new Qt(e,r,s)}static defineEnum(e,n){const{defaultValue:r,values:s}=n;return new fY(e,r,s)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,n){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,n):this.validate(n)}}class fY extends Qt{constructor(e,n,r){super(e,n,Og(...r)),this.values=r}}const lh=Zn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),pY=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:lh.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:lh.HoistOpacity,up:t=>{t.opacity=Number(t.props.opacity??"1"),delete t.props.opacity},down:t=>{const e=t.opacity;delete t.opacity,t.props.opacity=e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}},{id:lh.AddMeta,up:t=>{t.meta={}}},{id:lh.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function ll(t){return t?t.typeName==="shape":!1}function Fn(t){return t?t.startsWith("shape:"):!1}function Ke(t){return`shape:${t??ze()}`}function wA(t){const e=new Map;for(const[n,r]of Object.entries(t))if(r instanceof Qt){if(e.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);e.set(r,n)}return e}function us(t,e){return sd(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function gY(t){return Hs("shape",{scope:"document",validator:Ks("shape",rb("type",sd(t,(e,{props:n,meta:r})=>cY(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function G_(t,e){const n=[];for(const[r,{migrations:s}]of Object.entries(e)){const o=`com.tldraw.${t}.${r}`;s?"sequenceId"in s?(Le(o===s.sequenceId,`sequenceId mismatch for ${r} ${Mg} migrations. Expected '${o}', got '${s.sequenceId}'`),n.push(s)):"sequence"in s?n.push(vl({sequenceId:o,retroactive:!1,sequence:s.sequence.map(i=>"id"in i?bA(t,r,i):i)})):n.push(vl({sequenceId:o,retroactive:!1,sequence:Object.keys(s.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${o}/${i}`,scope:"record",filter:a=>a.typeName===t&&a.type===r,up:a=>{const l=s.migrators[i].up(a);if(l)return l},down:a=>{const l=s.migrators[i].down(a);if(l)return l}}))})):n.push(vl({sequenceId:o,retroactive:!1,sequence:[]}))}return n}function bA(t,e,n){return{id:n.id,dependsOn:n.dependsOn,scope:"record",filter:r=>r.typeName===t&&r.type===e,up:r=>{const s=n.up(r.props);s&&(r.props=s)},down:typeof n.down=="function"?r=>{const s=n.down(r.props);s&&(r.props=s)}:void 0}}const PA=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],kp={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",fill:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",fill:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",fill:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",fill:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",fill:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",fill:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",fill:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",fill:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",fill:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",fill:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",fill:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",fill:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function ko(t){return t.isDarkMode?kp.darkMode:kp.lightMode}const mr=Qt.defineEnum("tldraw:color",{defaultValue:"black",values:PA}),ab=Qt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:PA}),ua=Qt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),da=Qt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Ls=Qt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),CA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},$s=Qt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),_A=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Tp=Qt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:_A}),Mp=Qt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:_A}),IA={labelColor:ab,color:mr,fill:da,dash:ua,size:$s,arrowheadStart:Tp,arrowheadEnd:Mp,font:Ls,start:ca,end:ca,bend:pe,text:ye,labelPosition:pe,scale:Pt},Ha=us("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function ch(t){return bA("shape","arrow",t)}const EA=vl({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[ch({id:Ha.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),ch({id:Ha.AddIsPrecise,up:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise=!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),ch({id:Ha.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:Ha.ExtractBindings,scope:"store",up:t=>{const e=Object.values(t).filter(n=>n.typeName==="shape"&&n.type==="arrow");for(const n of e){const{start:r,end:s}=n.props;if(r.type==="binding"){const o=Ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};t[o]=i,n.props.start={x:0,y:0}}else delete n.props.start.type;if(s.type==="binding"){const o=Ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};t[o]=i,n.props.end={x:0,y:0}}else delete n.props.end.type}}},ch({id:Ha.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),kA={terminal:Og("start","end"),normalizedAnchor:ca,isExact:we,isPrecise:we},TA={sequence:[{dependsOn:[Ha.ExtractBindings]}]},mY=Ks("camera",Pe({typeName:mn("camera"),id:dr("camera"),x:pe,y:pe,z:pe,meta:Gt})),yY=Zn("com.tldraw.camera",{AddMeta:1}),SY=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:yY.AddMeta,up:t=>{t.meta={}}}]}),Is=Hs("camera",{validator:mY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),vY=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"]),MA=jg(vY),xY=Pe({type:MA,rotation:pe}),wY=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),bY=jg(wY),PY=new Set(["starting","paused","active","stopping"]),AA=Pe({id:ye,points:Wt(ca),size:Ip,color:bY,opacity:pe,state:jg(PY),delay:pe,shrink:pe,taper:we}),zu=dr("page"),CY=Ks("page",Pe({typeName:mn("page"),id:zu,name:ye,index:ob,meta:Gt})),_Y=Zn("com.tldraw.page",{AddMeta:1}),IY=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:_Y.AddMeta,up:t=>{t.meta={}}}]}),yr=Hs("page",{validator:CY,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Rn(t){return yr.isId(t)}const EY={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1};function jA(t){return t?au(t,e=>EY[e]):null}dr("instance");function kY(t){const e={};for(const[r,s]of t)e[r]=vA(s);const n=Ks("instance",Pe({typeName:mn("instance"),id:dr("instance"),currentPageId:zu,followingUserId:ye.nullable(),brush:cu.nullable(),opacityForNextShape:xA,stylesForNextShape:Pe(e),cursor:xY,scribbles:Wt(AA),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:cu,insets:Wt(we),zoomBrush:cu.nullable(),isPenMode:we,isGridMode:we,chatMessage:ye,isChatting:we,highlightedUserIds:Wt(ye),isFocused:we,devicePixelRatio:pe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Wt(ye),isChangingStyle:we,isReadonly:we,meta:Gt,duplicateProps:Pe({shapeIds:Wt(dr("shape")),offset:Pe({x:pe,y:pe})}).nullable()}));return Hs("instance",{validator:n,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const et=Zn("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25}),TY=xr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:et.AddTransparentExportBgs,up:t=>({...t,exportBackground:!0})},{id:et.RemoveDialog,up:({dialog:t,...e})=>e},{id:et.AddToolLockMode,up:t=>({...t,isToolLocked:!1})},{id:et.RemoveExtraPropsForNextShape,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:Object.fromEntries(Object.entries(t).filter(([n])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(n)))})},{id:et.AddLabelColor,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:{...t,labelColor:"black"}})},{id:et.AddFollowingUserId,up:t=>({...t,followingUserId:null})},{id:et.RemoveAlignJustify,up:t=>{let e=t.propsForNextShape.align;return e==="justify"&&(e="start"),{...t,propsForNextShape:{...t.propsForNextShape,align:e}}}},{id:et.AddZoom,up:t=>({...t,zoomBrush:null})},{id:et.AddVerticalAlign,up:t=>({...t,propsForNextShape:{...t.propsForNextShape,verticalAlign:"middle"}})},{id:et.AddScribbleDelay,up:t=>t.scribble!==null?{...t,scribble:{...t.scribble,delay:0}}:{...t}},{id:et.RemoveUserId,up:({userId:t,...e})=>e},{id:et.AddIsPenModeAndIsGridMode,up:t=>({...t,isPenMode:!1,isGridMode:!1})},{id:et.HoistOpacity,up:({propsForNextShape:{opacity:t,...e},...n})=>({...n,opacityForNextShape:Number(t??"1"),propsForNextShape:e})},{id:et.AddChat,up:t=>({...t,chatMessage:"",isChatting:!1})},{id:et.AddHighlightedUserIds,up:t=>({...t,highlightedUserIds:[]})},{id:et.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:t,...e})=>({...e,stylesForNextShape:{}})},{id:et.AddMeta,up:t=>({...t,meta:{}})},{id:et.RemoveCursorColor,up:t=>{const{color:e,...n}=t.cursor;return{...t,cursor:n}}},{id:et.AddLonelyProperties,up:t=>({...t,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:et.ReadOnlyReadonly,up:({isReadOnly:t,...e})=>({...e,isReadonly:t})},{id:et.AddHoveringCanvas,up:t=>({...t,isHoveringCanvas:null})},{id:et.AddScribbles,up:({scribble:t,...e})=>({...e,scribbles:[]})},{id:et.AddInset,up:t=>({...t,insets:[!1,!1,!1,!1]}),down:({insets:t,...e})=>({...e})},{id:et.AddDuplicateProps,up:t=>({...t,duplicateProps:null}),down:({duplicateProps:t,...e})=>({...e})},{id:et.RemoveCanMoveCamera,up:({canMoveCamera:t,...e})=>({...e}),down:t=>({...t,canMoveCamera:!0})}]}),bn="instance:instance",MY=Ks("instance_page_state",Pe({typeName:mn("instance_page_state"),id:dr("instance_page_state"),pageId:zu,selectedShapeIds:Wt(Ir),hintingShapeIds:Wt(Ir),erasingShapeIds:Wt(Ir),hoveredShapeId:Ir.nullable(),editingShapeId:Ir.nullable(),croppingShapeId:Ir.nullable(),focusedGroupId:Ir.nullable(),meta:Gt})),_c=Zn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),AY=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:_c.AddCroppingId,up(t){t.croppingShapeId=null}},{id:_c.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:_c.AddMeta,up:t=>{t.meta={}}},{id:_c.RenameProperties,up:t=>{},down:t=>{}},{id:_c.RenamePropertiesAgain,up:t=>{t.selectedShapeIds=t.selectedIds,delete t.selectedIds,t.hintingShapeIds=t.hintingIds,delete t.hintingIds,t.erasingShapeIds=t.erasingIds,delete t.erasingIds,t.hoveredShapeId=t.hoveredId,delete t.hoveredId,t.editingShapeId=t.editingId,delete t.editingId,t.croppingShapeId=t.croppingShapeId??t.croppingId??null,delete t.croppingId,t.focusedGroupId=t.focusLayerId,delete t.focusLayerId},down:t=>{t.selectedIds=t.selectedShapeIds,delete t.selectedShapeIds,t.hintingIds=t.hintingShapeIds,delete t.hintingShapeIds,t.erasingIds=t.erasingShapeIds,delete t.erasingShapeIds,t.hoveredId=t.hoveredShapeId,delete t.hoveredShapeId,t.editingId=t.editingShapeId,delete t.editingShapeId,t.croppingId=t.croppingShapeId,delete t.croppingShapeId,t.focusLayerId=t.focusedGroupId,delete t.focusedGroupId}}]}),Qr=Hs("instance_page_state",{validator:MY,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!1,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),jY=Ks("pointer",Pe({typeName:mn("pointer"),id:dr("pointer"),x:pe,y:pe,lastActivityTimestamp:pe,meta:Gt})),OY=Zn("com.tldraw.pointer",{AddMeta:1}),DY=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:OY.AddMeta,up:t=>{t.meta={}}}]}),lb=Hs("pointer",{validator:jY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Ap=lb.createId("pointer"),RY=Ks("instance_presence",Pe({typeName:mn("instance_presence"),id:dr("instance_presence"),userId:ye,userName:ye,lastActivityTimestamp:pe.nullable(),followingUserId:ye.nullable(),cursor:Pe({x:pe,y:pe,type:MA,rotation:pe}).nullable(),color:ye,camera:Pe({x:pe,y:pe,z:pe}).nullable(),screenBounds:cu.nullable(),selectedShapeIds:Wt(dr("shape")),currentPageId:dr("page"),brush:cu.nullable(),scribbles:Wt(AA),chatMessage:ye,meta:Gt})),Oa=Zn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),LY=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Oa.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:Oa.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:Oa.AddChatMessage,up:t=>{t.chatMessage=""}},{id:Oa.AddMeta,up:t=>{t.meta={}}},{id:Oa.RenameSelectedShapeIds,up:t=>{}},{id:Oa.NullableCameraCursor,up:t=>{},down:t=>{t.camera===null&&(t.camera={x:0,y:0,z:1}),t.lastActivityTimestamp===null&&(t.lastActivityTimestamp=0),t.cursor===null&&(t.cursor={type:"default",x:0,y:0,rotation:0}),t.screenBounds===null&&(t.screenBounds={x:0,y:0,w:1,h:1})}}]}),$Y=Hs("instance_presence",{validator:RY,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),FY=Ks("document",Pe({typeName:mn("document"),id:mn("document:document"),gridSize:pe,name:ye,meta:Gt})),V_=Zn("com.tldraw.document",{AddName:1,AddMeta:2}),NY=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:V_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:V_.AddMeta,up:t=>{t.meta={}}}]}),cb=Hs("document",{validator:FY,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),yx=cb.createId("document");function zY(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function Y_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function BY({error:t,phase:e,record:n,recordBefore:r}){throw v0(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?Y_(nt(r)):void 0,recordAfter:Y_(nt(n))}}),t}function UY(){return[yr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function HY(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(yx))return t.put([cb.create({id:yx,name:t.props.defaultName})]),r();if(!t.has(Ap))return t.put([lb.create({id:Ap})]),r();const s=e.get();if(s.size===0)return t.put(UY()),r();const o=()=>[...s].map(u=>t.get(u)).sort(zY)[0].id,i=t.get(bn);if(i){if(!s.has(i.currentPageId))return t.put([{...i,currentPageId:o()}]),r()}else return t.put([t.schema.types.instance.create({id:bn,currentPageId:o(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of s){const h=Qr.createId(u);t.get(h)||a.add(h);const p=Is.createId(u);t.has(p)||l.add(p)}a.size>0&&t.put([...a].map(u=>Qr.create({id:u,pageId:Qr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>Is.create({id:u})));const c=n.get();for(const u of c){if(!s.has(u.pageId)){t.remove([u.id]);continue}if(u.croppingShapeId&&!t.has(u.croppingShapeId))return t.put([{...u,croppingShapeId:null}]),r();if(u.focusedGroupId&&!t.has(u.focusedGroupId))return t.put([{...u,focusedGroupId:null}]),r();if(u.hoveredShapeId&&!t.has(u.hoveredShapeId))return t.put([{...u,hoveredShapeId:null}]),r();const h=u.selectedShapeIds.filter(g=>t.has(g));if(h.length!==u.selectedShapeIds.length)return t.put([{...u,selectedShapeIds:h}]),r();const f=u.hintingShapeIds.filter(g=>t.has(g));if(f.length!==u.hintingShapeIds.length)return t.put([{...u,hintingShapeIds:f}]),r();const p=u.erasingShapeIds.filter(g=>t.has(g));if(p.length!==u.erasingShapeIds.length)return t.put([{...u,erasingShapeIds:p}]),r()}};return r}const KY=ib("bookmark",Pe({title:ye,description:ye,image:ye,favicon:ye,src:la.nullable()})),X_=Zn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),WY=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:X_.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:X_.AddFavicon,up:t=>{la.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),GY=ib("image",Pe({w:pe,h:pe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:la.nullable(),fileSize:Pt.optional()})),Ic=Zn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),VY=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",sequence:[{id:Ic.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ic.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:Ic.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ic.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ic.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),YY=ib("video",Pe({w:pe,h:pe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:la.nullable(),fileSize:pe.optional()})),Ec=Zn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),XY=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:Ec.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ec.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:Ec.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ec.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ec.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),qY=Ks("asset",rb("type",{image:GY,video:YY,bookmark:KY})),ZY=Zn("com.tldraw.asset",{AddMeta:1}),QY=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:ZY.AddMeta,up:t=>{t.meta={}}}]}),Yo=Hs("asset",{validator:qY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),OA={w:Pt,h:Pt,assetId:Dg.nullable(),url:gr},q_=us("bookmark",{NullAssetId:1,MakeUrlsValid:2}),DA={sequence:[{id:q_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:q_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},RA=Pe({type:Og("free","straight"),points:Wt(ca)}),LA={color:mr,fill:da,dash:ua,size:$s,segments:Wt(RA),isComplete:we,isClosed:we,isPen:we,scale:Pt},Z_=us("draw",{AddInPen:1,AddScale:2}),$A={sequence:[{id:Z_.AddInPen,up:t=>{const{points:e}=t.segments[0];if(e.length===0){t.isPen=!1;return}let n=!(e[0].z===0||e[0].z===.5);e[1]&&(n=n&&!(e[1].z===0||e[1].z===.5)),t.isPen=n},down:"retired"},{id:Z_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},JY=/(^\/r\/[^/]+\/?$)/,eX=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(JY))return t}},{hostnames:["figma.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{hostnames:["google.*"],fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:t=>{const e=ge(t),n=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:t=>{const e=ge(t),n=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{hostnames:["calendar.google.*"],fromEmbedUrl:t=>{const e=ge(t),n=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&n){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const s of r)e.searchParams.delete(s);return e.searchParams.set("cid",n),e.href}}},{hostnames:["docs.google.*"],fromEmbedUrl:t=>{const e=ge(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}}},{hostnames:["gist.github.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0}},{hostnames:["replit.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{hostnames:["open.spotify.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="player.vimeo.com"){const n=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{hostnames:["excalidraw.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hash.match(/#room=/))return t}},{hostnames:["observablehq.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","")}#cell-*`;if(e&&e.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","/d")}#cell-*`}},{hostnames:["desmos.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],FA={w:Pt,h:Pt,url:ye},uh=us("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),NA={sequence:[{id:uh.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const s of eX)if(s.hostnames.includes(n))try{r=s.fromEmbedUrl(e)}catch(o){console.warn(o)}t.tmpOldUrl=t.url,t.url=r??""}catch{t.url="",t.tmpOldUrl=t.url}},down:"retired"},{id:uh.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:uh.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:uh.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},zA={w:Pt,h:Pt,name:ye},BA={sequence:[]},jp=Qt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Op=Qt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Jr=Qt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),UA={geo:Jr,labelColor:ab,color:mr,fill:da,dash:ua,size:$s,font:Ls,align:jp,verticalAlign:Op,url:gr,w:Pt,h:Pt,growY:Ip,text:ye,scale:Pt},Qs=us("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),HA={sequence:[{id:Qs.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Qs.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Qs.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Qs.AddCheckBox,up:t=>{},down:"retired"},{id:Qs.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Qs.MigrateLegacyAlign,up:t=>{let e;switch(t.align){case"start":e="start-legacy";break;case"end":e="end-legacy";break;default:e="middle-legacy";break}t.align=e},down:"retired"},{id:Qs.AddCloud,up:t=>{},down:"retired"},{id:Qs.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Qs.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},KA={},WA={sequence:[]},GA={color:mr,size:$s,segments:Wt(RA),isComplete:we,isPen:we,scale:Pt},tX=us("highlight",{AddScale:1}),VA={sequence:[{id:tX.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},nX=Pe({topLeft:ca,bottomRight:ca}),YA={w:Pt,h:Pt,playing:we,url:gr,assetId:Dg.nullable(),crop:nX.nullable(),flipX:we,flipY:we},dh=us("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),XA={sequence:[{id:dh.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:dh.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:dh.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:dh.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},Dp=Qt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),rX=Pe({id:ye,index:ob,x:pe,y:pe}),qA={color:mr,dash:ua,size:$s,spline:Dp,points:Ep(ye,rX),scale:Pt},kc=us("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),ZA={sequence:[{id:kc.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:kc.RemoveExtraHandleProps,up:t=>{t.handles=w0(Object.values(t.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:t=>{const e=Object.entries(t.handles).map(([n,r])=>({index:n,...r})).sort(cn);t.handles=Object.fromEntries(e.map((n,r)=>{const s=r===0?"start":r===e.length-1?"end":`handle:${n.index}`;return[s,{id:s,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}},{id:kc.HandlesToPoints,up:t=>{const e=Object.entries(t.handles).map(([n,{x:r,y:s}])=>({x:r,y:s,index:n})).sort(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r})),delete t.handles},down:t=>{const e=Fu(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:kc.PointIndexIds,up:t=>{const e=Fu(t.points.length);t.points=Object.fromEntries(t.points.map((n,r)=>{const s=e[r];return[s,{id:s,index:s,x:n.x,y:n.y}]}))},down:t=>{const e=Object.values(t.points).sort(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r}))}},{id:kc.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},QA={color:mr,labelColor:ab,size:$s,font:Ls,fontSizeAdjustment:Ip,align:jp,verticalAlign:Op,growY:Ip,url:gr,text:ye,scale:Pt},Fo=us("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8}),JA={sequence:[{id:Fo.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Fo.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Fo.MigrateLegacyAlign,up:t=>{switch(t.align){case"start":t.align="start-legacy";return;case"end":t.align="end-legacy";return;default:t.align="middle-legacy";return}},down:"retired"},{id:Fo.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Fo.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Fo.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:Fo.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}},{id:Fo.AddLabelColor,up:t=>{t.labelColor="black"},down:t=>{delete t.labelColor}}]},Sx=Qt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),ej={color:mr,size:$s,font:Ls,textAlign:Sx,w:Pt,text:ye,scale:Pt,autoSize:we},Q_=us("text",{RemoveJustify:1,AddTextAlign:2}),tj={sequence:[{id:Q_.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Q_.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},nj={w:Pt,h:Pt,time:pe,playing:we,url:gr,assetId:Dg.nullable()},J_=us("video",{AddUrlProp:1,MakeUrlsValid:2}),rj={sequence:[{id:J_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:J_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},hh=Zn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),sX=vl({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:hh.RemoveCodeAndIconShapeTypes,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete t[e]}},{id:hh.AddInstancePresenceType,scope:"store",up(t){}},{id:hh.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:hh.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match("user_document")&&delete t[e]}}]}),oX={arrow:{migrations:EA,props:IA},bookmark:{migrations:DA,props:OA},draw:{migrations:$A,props:LA},embed:{migrations:NA,props:FA},frame:{migrations:BA,props:zA},geo:{migrations:HA,props:UA},group:{migrations:WA,props:KA},highlight:{migrations:VA,props:GA},image:{migrations:XA,props:YA},line:{migrations:ZA,props:qA},note:{migrations:JA,props:QA},text:{migrations:tj,props:ej},video:{migrations:rj,props:nj}},iX={arrow:{migrations:TA,props:kA}};function aX({shapes:t=oX,bindings:e=iX,migrations:n}={}){const r=new Map;for(const a of ut(t))for(const l of wA(a.props??{}).keys()){if(r.has(l.id)&&r.get(l.id)!==l)throw new Error(`Multiple StyleProp instances with the same id: ${l.id}`);r.set(l.id,l)}const s=gY(t),o=hY(e),i=kY(r);return tb.create({asset:Yo,binding:o,camera:Is,document:cb,instance:i,instance_page_state:Qr,page:yr,instance_presence:$Y,pointer:lb,shape:s},{migrations:[sX,QY,SY,NY,TY,AY,IY,LY,DY,pY,WY,VY,XY,...G_("shape",t),...G_("binding",e),...n??[]],onValidationFailure:BY,createIntegrityChecker:HY})}const Bu=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"so",label:"Somali"},{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 lX(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return cX(t)}function cX(t){for(const e of t){const n=uX(e);if(n)return n}return"en"}const eI={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function uX(t){const e=Bu.find(s=>s.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=Bu.find(o=>o.locale===n);if(s)return s.locale}return n in eI?eI[n]:null}_i("@tldraw/tlschema","3.8.0-canary.c422debb621c","esm");var sj={exports:{}};/*!
|
|
84
|
+
`);super(r?`At ${s}: ${o}`:o);I(this,"name","ValidationError");this.rawMessage=n,this.path=r}}function qn(t,e){try{return e()}catch(n){throw n instanceof Te?new Te(n.rawMessage,[t,...n.path]):new Te(n.toString(),[t])}}function gi(t){if(t===null)return"null";if(Array.isArray(t))return"an array";const e=typeof t;switch(e){case"bigint":case"boolean":case"function":case"number":case"string":case"symbol":return`a ${e}`;case"object":return`an ${e}`;case"undefined":return"undefined";default:Ot(e)}}class Tn{constructor(e,n){this.validationFn=e,this.validateUsingKnownGoodVersionFn=n}validate(e){return this.validationFn(e)}validateUsingKnownGoodVersion(e,n){return Object.is(e,n)?e:this.validateUsingKnownGoodVersionFn?this.validateUsingKnownGoodVersionFn(e,n):this.validate(n)}isValid(e){try{return this.validate(e),!0}catch{return!1}}nullable(){return oY(this)}optional(){return vA(this)}refine(e){return new Tn(n=>e(this.validate(n)),(n,r)=>{const s=this.validateUsingKnownGoodVersion(n,r);return Object.is(n,s)?n:e(s)})}check(e,n){return typeof e=="string"?this.refine(r=>(qn(`(check ${e})`,()=>n(r)),r)):this.refine(r=>(e(r),r))}}class eY extends Tn{constructor(e){super(n=>{const r=W_.validate(n);for(let s=0;s<r.length;s++)qn(s,()=>e.validate(r[s]));return r},(n,r)=>{if(!e.validateUsingKnownGoodVersion)return this.validate(r);const s=W_.validate(r);let o=n.length!==s.length;for(let i=0;i<s.length;i++){const a=s[i];if(i>=n.length){o=!0,qn(i,()=>e.validate(a));continue}if(Object.is(n[i],a))continue;const l=qn(i,()=>e.validateUsingKnownGoodVersion(n[i],a));Object.is(l,n[i])||(o=!0)}return o?r:n}),this.itemValidator=e}nonEmpty(){return this.check(e=>{if(e.length===0)throw new Te("Expected a non-empty array")})}lengthGreaterThan1(){return this.check(e=>{if(e.length<=1)throw new Te("Expected an array with length greater than 1")})}}class _p extends Tn{constructor(e,n=!1){super(r=>{if(typeof r!="object"||r===null)throw new Te(`Expected object, got ${gi(r)}`);for(const[s,o]of Object.entries(e))qn(s,()=>{o.validate(hn(r,s))});if(!n){for(const s of Object.keys(r))if(!ns(e,s))throw new Te("Unexpected property",[s])}return r},(r,s)=>{if(typeof s!="object"||s===null)throw new Te(`Expected object, got ${gi(s)}`);let o=!1;for(const[i,a]of Object.entries(e)){const l=hn(r,i),c=hn(s,i);if(Object.is(l,c))continue;const u=qn(i,()=>{const h=a;return h.validateUsingKnownGoodVersion?h.validateUsingKnownGoodVersion(l,c):h.validate(c)});Object.is(u,l)||(o=!0)}if(!n){for(const i of Object.keys(s))if(!ns(e,i))throw new Te("Unexpected property",[i])}for(const i of Object.keys(r))if(!ns(s,i)){o=!0;break}return o?s:r}),this.config=e,this.shouldAllowUnknownProperties=n}allowUnknownProperties(){return new _p(this.config,!0)}extend(e){return new _p({...this.config,...e})}}class Ag extends Tn{constructor(e,n,r,s){super(o=>{this.expectObject(o);const{matchingSchema:i,variant:a}=this.getMatchingSchemaAndVariant(o);return i===void 0?this.unknownValueValidation(o,a):qn(`(${e} = ${a})`,()=>i.validate(o))},(o,i)=>{this.expectObject(i),this.expectObject(o);const{matchingSchema:a,variant:l}=this.getMatchingSchemaAndVariant(i);return a===void 0?this.unknownValueValidation(i,l):hn(o,e)!==hn(i,e)?qn(`(${e} = ${l})`,()=>a.validate(i)):qn(`(${e} = ${l})`,()=>a.validateUsingKnownGoodVersion?a.validateUsingKnownGoodVersion(o,i):a.validate(i))}),this.key=e,this.config=n,this.unknownValueValidation=r,this.useNumberKeys=s}expectObject(e){if(typeof e!="object"||e===null)throw new Te(`Expected an object, got ${gi(e)}`,[])}getMatchingSchemaAndVariant(e){const n=hn(e,this.key);if(!this.useNumberKeys&&typeof n!="string")throw new Te(`Expected a string for key "${this.key}", got ${gi(n)}`);if(this.useNumberKeys&&!Number.isFinite(Number(n)))throw new Te(`Expected a number for key "${this.key}", got "${n}"`);return{matchingSchema:ns(this.config,n)?this.config[n]:void 0,variant:n}}validateUnknownVariants(e){return new Ag(this.key,this.config,e,this.useNumberKeys)}}class tY extends Tn{constructor(e,n){super(r=>{if(typeof r!="object"||r===null)throw new Te(`Expected object, got ${gi(r)}`);for(const[s,o]of Object.entries(r))qn(s,()=>{e.validate(s),n.validate(o)});return r},(r,s)=>{if(typeof s!="object"||s===null)throw new Te(`Expected object, got ${gi(s)}`);let o=!1;for(const[i,a]of Object.entries(s)){if(!ns(r,i)){o=!0,qn(i,()=>{e.validate(i),n.validate(a)});continue}const l=hn(r,i),c=a;if(Object.is(l,c))continue;const u=qn(i,()=>n.validateUsingKnownGoodVersion?n.validateUsingKnownGoodVersion(l,c):n.validate(c));Object.is(u,l)||(o=!0)}for(const i of Object.keys(r))if(!ns(s,i)){o=!0;break}return o?s:r}),this.keyValidator=e,this.valueValidator=n}}function nb(t){return new Tn(e=>{if(typeof e!==t)throw new Te(`Expected ${t}, got ${gi(e)}`);return e})}const nY=new Tn(t=>t),ye=nb("string"),pe=nb("number").check(t=>{if(Number.isNaN(t))throw new Te("Expected a number, got NaN");if(!Number.isFinite(t))throw new Te(`Expected a finite number, got ${t}`)}),Ip=pe.check(t=>{if(t<0)throw new Te(`Expected a positive number, got ${t}`)}),Pt=pe.check(t=>{if(t<=0)throw new Te(`Expected a non-zero positive number, got ${t}`)}),SA=pe.check(t=>{if(!Number.isInteger(t))throw new Te(`Expected an integer, got ${t}`)}),lf=SA.check(t=>{if(t<0)throw new Te(`Expected a positive integer, got ${t}`)}),rY=SA.check(t=>{if(t<=0)throw new Te(`Expected a non-zero positive integer, got ${t}`)}),we=nb("boolean");function mn(t){return new Tn(e=>{if(e!==t)throw new Te(`Expected ${t}, got ${JSON.stringify(e)}`);return t})}const W_=new Tn(t=>{if(!Array.isArray(t))throw new Te(`Expected an array, got ${gi(t)}`);return t});function Wt(t){return new eY(t)}function Pe(t){return new _p(t)}function gx(t){return typeof t=="object"&&t!==null&&(Object.getPrototypeOf(t)===Object.prototype||Object.getPrototypeOf(t)===null||Object.getPrototypeOf(t)===mB)}function mx(t){return t===null||typeof t=="number"||typeof t=="string"||typeof t=="boolean"?!0:Array.isArray(t)?t.every(mx):gx(t)?Object.values(t).every(mx):!1}const Gt=new Tn(t=>{if(mx(t))return t;throw new Te(`Expected json serializable value, got ${typeof t}`)},(t,e)=>{if(Array.isArray(t)&&Array.isArray(e)){let n=t.length!==e.length;for(let r=0;r<e.length;r++){if(r>=t.length){n=!0,Gt.validate(e[r]);continue}const s=t[r],o=e[r];if(Object.is(s,o))continue;const i=Gt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}return n?e:t}else if(gx(t)&&gx(e)){let n=!1;for(const r of Object.keys(e)){if(!ns(t,r)){n=!0,Gt.validate(e[r]);continue}const s=t[r],o=e[r];if(Object.is(s,o))continue;const i=Gt.validateUsingKnownGoodVersion(s,o);Object.is(i,s)||(n=!0)}for(const r of Object.keys(t))if(!ns(e,r)){n=!0;break}return n?e:t}else return Gt.validate(e)});function Ep(t,e){return new tY(t,e)}function rb(t,e){return new Ag(t,e,(n,r)=>{throw new Te(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!1)}function sY(t,e){return new Ag(t,e,(n,r)=>{throw new Te(`Expected one of ${Object.keys(e).map(s=>JSON.stringify(s)).join(" or ")}, got ${JSON.stringify(r)}`,[t])},!0)}function Ks(t,e){return new Tn(n=>qn(t,()=>e.validate(n)),(n,r)=>qn(t,()=>e.validateUsingKnownGoodVersion?e.validateUsingKnownGoodVersion(n,r):e.validate(r)))}function jg(t){return new Tn(e=>{if(!t.has(e)){const n=Array.from(t,r=>JSON.stringify(r)).join(" or ");throw new Te(`Expected ${n}, got ${e}`)}return e})}function vA(t){return new Tn(e=>{if(e!==void 0)return t.validate(e)},(e,n)=>{if(!(e===void 0&&n===void 0)&&n!==void 0)return t.validateUsingKnownGoodVersion&&e!==void 0?t.validateUsingKnownGoodVersion(e,n):t.validate(n)})}function oY(t){return new Tn(e=>e===null?null:t.validate(e),(e,n)=>n===null?null:t.validateUsingKnownGoodVersion&&e!==null?t.validateUsingKnownGoodVersion(e,n):t.validate(n))}function Og(...t){return jg(new Set(t))}function sb(t){try{return new URL(t)}catch{if(t.startsWith("/")||t.startsWith("./"))try{return new URL(t,"http://example.com")}catch{throw new Te(`Expected a valid url, got ${JSON.stringify(t)}`)}throw new Te(`Expected a valid url, got ${JSON.stringify(t)}`)}}const iY=new Set(["http:","https:","mailto:"]),gr=ye.check(t=>{if(t==="")return;const e=sb(t);if(!iY.has(e.protocol.toLowerCase()))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)}),aY=new Set(["http:","https:","data:","asset:"]),la=ye.check(t=>{if(t==="")return;const e=sb(t);if(!aY.has(e.protocol.toLowerCase()))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});ye.check(t=>{if(t==="")return;if(!sb(t).protocol.toLowerCase().match(/^https?:$/))throw new Te(`Expected a valid url, got ${JSON.stringify(t)} (invalid protocol)`)});const ob=ye.refine(t=>{try{return iB(t),t}catch{throw new Te(`Expected an index key, got ${JSON.stringify(t)}`)}});_i("@tldraw/validate","3.7.2","esm");function dr(t){return ye.refine(e=>{if(!e.startsWith(`${t}:`))throw new Error(`${t} ID must start with "${t}:"`);return e})}const Dg=dr("asset");function ib(t,e){return Pe({id:Dg,typeName:mn("asset"),type:mn(t),props:e,meta:Gt})}const ca=Pe({x:pe,y:pe,z:pe.optional()}),cu=Pe({x:pe,y:pe,w:pe,h:pe}),xA=pe.check(t=>{if(t<0||t>1)throw new Te("Opacity must be between 0 and 1")}),lY=ye.refine(t=>{if(!t.startsWith("page:")&&!t.startsWith("shape:"))throw new Error('Parent ID must start with "page:" or "shape:"');return t}),Ir=dr("shape");function cY(t,e,n){return Pe({id:Ir,typeName:mn("shape"),x:pe,y:pe,rotation:pe,index:ob,parentId:lY,type:mn(t),isLocked:we,opacity:xA,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}const uY=dr("binding");function dY(t,e,n){return Pe({id:uY,typeName:mn("binding"),type:mn(t),fromId:Ir,toId:Ir,props:e?Pe(e):Gt,meta:n?Pe(n):Gt})}Zn("com.tldraw.binding",{});xr({sequenceId:"com.tldraw.binding",recordType:"binding",sequence:[]});function Ji(t){return`binding:${ze()}`}function hY(t){return Hs("binding",{scope:"document",validator:Ks("binding",rb("type",sd(t,(e,{props:n,meta:r})=>dY(e,n,r))))}).withDefaultProperties(()=>({meta:{}}))}class Qt{constructor(e,n,r){this.id=e,this.defaultValue=n,this.type=r}static define(e,n){const{defaultValue:r,type:s=nY}=n;return new Qt(e,r,s)}static defineEnum(e,n){const{defaultValue:r,values:s}=n;return new fY(e,r,s)}setDefaultValue(e){this.defaultValue=e}validate(e){return this.type.validate(e)}validateUsingKnownGoodVersion(e,n){return this.type.validateUsingKnownGoodVersion?this.type.validateUsingKnownGoodVersion(e,n):this.validate(n)}}class fY extends Qt{constructor(e,n,r){super(e,n,Og(...r)),this.values=r}}const lh=Zn("com.tldraw.shape",{AddIsLocked:1,HoistOpacity:2,AddMeta:3,AddWhite:4}),pY=xr({sequenceId:"com.tldraw.shape",recordType:"shape",sequence:[{id:lh.AddIsLocked,up:t=>{t.isLocked=!1},down:t=>{delete t.isLocked}},{id:lh.HoistOpacity,up:t=>{t.opacity=Number(t.props.opacity??"1"),delete t.props.opacity},down:t=>{const e=t.opacity;delete t.opacity,t.props.opacity=e<.175?"0.1":e<.375?"0.25":e<.625?"0.5":e<.875?"0.75":"1"}},{id:lh.AddMeta,up:t=>{t.meta={}}},{id:lh.AddWhite,up:t=>{},down:t=>{t.props.color==="white"&&(t.props.color="black")}}]});function ll(t){return t?t.typeName==="shape":!1}function Fn(t){return t?t.startsWith("shape:"):!1}function Ke(t){return`shape:${t??ze()}`}function wA(t){const e=new Map;for(const[n,r]of Object.entries(t))if(r instanceof Qt){if(e.has(r))throw new Error(`Duplicate style prop ${r.id}. Each style prop can only be used once within a shape.`);e.set(r,n)}return e}function us(t,e){return sd(e,(n,r)=>`com.tldraw.shape.${t}/${r}`)}function gY(t){return Hs("shape",{scope:"document",validator:Ks("shape",rb("type",sd(t,(e,{props:n,meta:r})=>cY(e,n,r))))}).withDefaultProperties(()=>({x:0,y:0,rotation:0,isLocked:!1,opacity:1,meta:{}}))}function G_(t,e){const n=[];for(const[r,{migrations:s}]of Object.entries(e)){const o=`com.tldraw.${t}.${r}`;s?"sequenceId"in s?(Le(o===s.sequenceId,`sequenceId mismatch for ${r} ${Mg} migrations. Expected '${o}', got '${s.sequenceId}'`),n.push(s)):"sequence"in s?n.push(vl({sequenceId:o,retroactive:!1,sequence:s.sequence.map(i=>"id"in i?bA(t,r,i):i)})):n.push(vl({sequenceId:o,retroactive:!1,sequence:Object.keys(s.migrators).map(i=>Number(i)).sort((i,a)=>i-a).map(i=>({id:`${o}/${i}`,scope:"record",filter:a=>a.typeName===t&&a.type===r,up:a=>{const l=s.migrators[i].up(a);if(l)return l},down:a=>{const l=s.migrators[i].down(a);if(l)return l}}))})):n.push(vl({sequenceId:o,retroactive:!1,sequence:[]}))}return n}function bA(t,e,n){return{id:n.id,dependsOn:n.dependsOn,scope:"record",filter:r=>r.typeName===t&&r.type===e,up:r=>{const s=n.up(r.props);s&&(r.props=s)},down:typeof n.down=="function"?r=>{const s=n.down(r.props);s&&(r.props=s)}:void 0}}const PA=["black","grey","light-violet","violet","blue","light-blue","yellow","orange","green","light-green","light-red","red","white"],kp={lightMode:{id:"light",text:"#000000",background:"rgb(249, 250, 251)",solid:"#fcfffe",black:{solid:"#1d1d1d",fill:"#1d1d1d",note:{fill:"#FCE19C",text:"#000000"},semi:"#e8e8e8",pattern:"#494949",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},blue:{solid:"#4465e9",fill:"#4465e9",note:{fill:"#8AA3FF",text:"#000000"},semi:"#dce1f8",pattern:"#6681ee",highlight:{srgb:"#10acff",p3:"color(display-p3 0.308 0.6632 0.9996)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#6FC896",text:"#000000"},semi:"#d3e9e3",pattern:"#39a785",highlight:{srgb:"#00ffc8",p3:"color(display-p3 0.2536 0.984 0.7981)"}},grey:{solid:"#9fa8b2",fill:"#9fa8b2",note:{fill:"#C0CAD3",text:"#000000"},semi:"#eceef0",pattern:"#bcc3c9",highlight:{srgb:"#cbe7f1",p3:"color(display-p3 0.8163 0.9023 0.9416)"}},"light-blue":{solid:"#4ba1f1",fill:"#4ba1f1",note:{fill:"#9BC4FD",text:"#000000"},semi:"#ddedfa",pattern:"#6fbbf8",highlight:{srgb:"#00f4ff",p3:"color(display-p3 0.1512 0.9414 0.9996)"}},"light-green":{solid:"#4cb05e",fill:"#4cb05e",note:{fill:"#98D08A",text:"#000000"},semi:"#dbf0e0",pattern:"#65cb78",highlight:{srgb:"#65f641",p3:"color(display-p3 0.563 0.9495 0.3857)"}},"light-red":{solid:"#f87777",fill:"#f87777",note:{fill:"#F7A5A1",text:"#000000"},semi:"#f4dadb",pattern:"#fe9e9e",highlight:{srgb:"#ff7fa3",p3:"color(display-p3 0.9988 0.5301 0.6397)"}},"light-violet":{solid:"#e085f4",fill:"#e085f4",note:{fill:"#DFB0F9",text:"#000000"},semi:"#f5eafa",pattern:"#e9acf8",highlight:{srgb:"#ff88ff",p3:"color(display-p3 0.9676 0.5652 0.9999)"}},orange:{solid:"#e16919",fill:"#e16919",note:{fill:"#FAA475",text:"#000000"},semi:"#f8e2d4",pattern:"#f78438",highlight:{srgb:"#ffa500",p3:"color(display-p3 0.9988 0.6905 0.266)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#FC8282",text:"#000000"},semi:"#f4dadb",pattern:"#e55959",highlight:{srgb:"#ff636e",p3:"color(display-p3 0.9992 0.4376 0.45)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#DB91FD",text:"#000000"},semi:"#ecdcf2",pattern:"#bd63d3",highlight:{srgb:"#c77cff",p3:"color(display-p3 0.7469 0.5089 0.9995)"}},yellow:{solid:"#f1ac4b",fill:"#f1ac4b",note:{fill:"#FED49A",text:"#000000"},semi:"#f9f0e6",pattern:"#fecb92",highlight:{srgb:"#fddd00",p3:"color(display-p3 0.972 0.8705 0.05)"}},white:{solid:"#FFFFFF",fill:"#FFFFFF",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#FFFFFF",text:"#000000"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}},darkMode:{id:"dark",text:"hsl(210, 17%, 98%)",background:"hsl(240, 5%, 6.5%)",solid:"#010403",black:{solid:"#f2f2f2",fill:"#f2f2f2",note:{fill:"#2c2c2c",text:"#f2f2f2"},semi:"#2c3036",pattern:"#989898",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},blue:{solid:"#4f72fc",fill:"#4f72fc",note:{fill:"#2A3F98",text:"#f2f2f2"},semi:"#262d40",pattern:"#3a4b9e",highlight:{srgb:"#0079d2",p3:"color(display-p3 0.0032 0.4655 0.7991)"}},green:{solid:"#099268",fill:"#099268",note:{fill:"#014429",text:"#f2f2f2"},semi:"#253231",pattern:"#366a53",highlight:{srgb:"#009774",p3:"color(display-p3 0.0085 0.582 0.4604)"}},grey:{solid:"#9398b0",fill:"#9398b0",note:{fill:"#56595F",text:"#f2f2f2"},semi:"#33373c",pattern:"#7c8187",highlight:{srgb:"#9cb4cb",p3:"color(display-p3 0.6299 0.7012 0.7856)"}},"light-blue":{solid:"#4dabf7",fill:"#4dabf7",note:{fill:"#1F5495",text:"#f2f2f2"},semi:"#2a3642",pattern:"#4d7aa9",highlight:{srgb:"#00bdc8",p3:"color(display-p3 0.0023 0.7259 0.7735)"}},"light-green":{solid:"#40c057",fill:"#40c057",note:{fill:"#21581D",text:"#f2f2f2"},semi:"#2a3830",pattern:"#4e874e",highlight:{srgb:"#00a000",p3:"color(display-p3 0.2711 0.6172 0.0195)"}},"light-red":{solid:"#ff8787",fill:"#ff8787",note:{fill:"#923632",text:"#f2f2f2"},semi:"#3b3235",pattern:"#a56767",highlight:{srgb:"#db005b",p3:"color(display-p3 0.7849 0.0585 0.3589)"}},"light-violet":{solid:"#e599f7",fill:"#e599f7",note:{fill:"#762F8E",text:"#f2f2f2"},semi:"#383442",pattern:"#9770a9",highlight:{srgb:"#c400c7",p3:"color(display-p3 0.7024 0.0403 0.753)"}},orange:{solid:"#f76707",fill:"#f76707",note:{fill:"#843906",text:"#f2f2f2"},semi:"#3a2e2a",pattern:"#9f552d",highlight:{srgb:"#d07a00",p3:"color(display-p3 0.7699 0.4937 0.0085)"}},red:{solid:"#e03131",fill:"#e03131",note:{fill:"#89231A",text:"#f2f2f2"},semi:"#36292b",pattern:"#8f3734",highlight:{srgb:"#de002c",p3:"color(display-p3 0.7978 0.0509 0.2035)"}},violet:{solid:"#ae3ec9",fill:"#ae3ec9",note:{fill:"#681683",text:"#f2f2f2"},semi:"#31293c",pattern:"#763a8b",highlight:{srgb:"#9e00ee",p3:"color(display-p3 0.5651 0.0079 0.8986)"}},yellow:{solid:"#ffc034",fill:"#ffc034",note:{fill:"#98571B",text:"#f2f2f2"},semi:"#3c3934",pattern:"#fecb92",highlight:{srgb:"#d2b700",p3:"color(display-p3 0.8078 0.7225 0.0312)"}},white:{solid:"#f3f3f3",fill:"#f3f3f3",semi:"#f5f5f5",pattern:"#f9f9f9",note:{fill:"#eaeaea",text:"#1d1d1d"},highlight:{srgb:"#ffffff",p3:"color(display-p3 1 1 1)"}}}};function ko(t){return t.isDarkMode?kp.darkMode:kp.lightMode}const mr=Qt.defineEnum("tldraw:color",{defaultValue:"black",values:PA}),ab=Qt.defineEnum("tldraw:labelColor",{defaultValue:"black",values:PA}),ua=Qt.defineEnum("tldraw:dash",{defaultValue:"draw",values:["draw","solid","dashed","dotted"]}),da=Qt.defineEnum("tldraw:fill",{defaultValue:"none",values:["none","semi","solid","pattern","fill"]}),Ls=Qt.defineEnum("tldraw:font",{defaultValue:"draw",values:["draw","sans","serif","mono"]}),CA={draw:"'tldraw_draw', sans-serif",sans:"'tldraw_sans', sans-serif",serif:"'tldraw_serif', serif",mono:"'tldraw_mono', monospace"},$s=Qt.defineEnum("tldraw:size",{defaultValue:"m",values:["s","m","l","xl"]}),_A=["arrow","triangle","square","dot","pipe","diamond","inverted","bar","none"],Tp=Qt.defineEnum("tldraw:arrowheadStart",{defaultValue:"none",values:_A}),Mp=Qt.defineEnum("tldraw:arrowheadEnd",{defaultValue:"arrow",values:_A}),IA={labelColor:ab,color:mr,fill:da,dash:ua,size:$s,arrowheadStart:Tp,arrowheadEnd:Mp,font:Ls,start:ca,end:ca,bend:pe,text:ye,labelPosition:pe,scale:Pt},Ha=us("arrow",{AddLabelColor:1,AddIsPrecise:2,AddLabelPosition:3,ExtractBindings:4,AddScale:5});function ch(t){return bA("shape","arrow",t)}const EA=vl({sequenceId:"com.tldraw.shape.arrow",retroactive:!1,sequence:[ch({id:Ha.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"}),ch({id:Ha.AddIsPrecise,up:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise=!(t.normalizedAnchor.x===.5&&t.normalizedAnchor.y===.5)),e.type==="binding"&&(e.isPrecise=!(e.normalizedAnchor.x===.5&&e.normalizedAnchor.y===.5))},down:({start:t,end:e})=>{t.type==="binding"&&(t.isPrecise||(t.normalizedAnchor={x:.5,y:.5}),delete t.isPrecise),e.type==="binding"&&(e.isPrecise||(e.normalizedAnchor={x:.5,y:.5}),delete e.isPrecise)}}),ch({id:Ha.AddLabelPosition,up:t=>{t.labelPosition=.5},down:t=>{delete t.labelPosition}}),{id:Ha.ExtractBindings,scope:"store",up:t=>{const e=Object.values(t).filter(n=>n.typeName==="shape"&&n.type==="arrow");for(const n of e){const{start:r,end:s}=n.props;if(r.type==="binding"){const o=Ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:r.boundShapeId,meta:{},props:{terminal:"start",normalizedAnchor:r.normalizedAnchor,isExact:r.isExact,isPrecise:r.isPrecise}};t[o]=i,n.props.start={x:0,y:0}}else delete n.props.start.type;if(s.type==="binding"){const o=Ji(),i={typeName:"binding",id:o,type:"arrow",fromId:n.id,toId:s.boundShapeId,meta:{},props:{terminal:"end",normalizedAnchor:s.normalizedAnchor,isExact:s.isExact,isPrecise:s.isPrecise}};t[o]=i,n.props.end={x:0,y:0}}else delete n.props.end.type}}},ch({id:Ha.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}})]}),kA={terminal:Og("start","end"),normalizedAnchor:ca,isExact:we,isPrecise:we},TA={sequence:[{dependsOn:[Ha.ExtractBindings]}]},mY=Ks("camera",Pe({typeName:mn("camera"),id:dr("camera"),x:pe,y:pe,z:pe,meta:Gt})),yY=Zn("com.tldraw.camera",{AddMeta:1}),SY=xr({sequenceId:"com.tldraw.camera",recordType:"camera",sequence:[{id:yY.AddMeta,up:t=>{t.meta={}}}]}),Is=Hs("camera",{validator:mY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,z:1,meta:{}})),vY=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"]),MA=jg(vY),xY=Pe({type:MA,rotation:pe}),wY=new Set(["accent","white","black","selection-stroke","selection-fill","laser","muted-1"]),bY=jg(wY),PY=new Set(["starting","paused","active","stopping"]),AA=Pe({id:ye,points:Wt(ca),size:Ip,color:bY,opacity:pe,state:jg(PY),delay:pe,shrink:pe,taper:we}),zu=dr("page"),CY=Ks("page",Pe({typeName:mn("page"),id:zu,name:ye,index:ob,meta:Gt})),_Y=Zn("com.tldraw.page",{AddMeta:1}),IY=xr({sequenceId:"com.tldraw.page",recordType:"page",sequence:[{id:_Y.AddMeta,up:t=>{t.meta={}}}]}),yr=Hs("page",{validator:CY,scope:"document"}).withDefaultProperties(()=>({meta:{}}));function Rn(t){return yr.isId(t)}const EY={id:!1,typeName:!1,currentPageId:!1,opacityForNextShape:!1,stylesForNextShape:!1,followingUserId:!1,highlightedUserIds:!1,brush:!1,cursor:!1,scribbles:!1,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!1,chatMessage:!1,isChatting:!1,isPenMode:!1,isGridMode:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!1,openMenus:!1,isChangingStyle:!1,isReadonly:!0,meta:!1,duplicateProps:!1};function jA(t){return t?au(t,e=>EY[e]):null}dr("instance");function kY(t){const e={};for(const[r,s]of t)e[r]=vA(s);const n=Ks("instance",Pe({typeName:mn("instance"),id:dr("instance"),currentPageId:zu,followingUserId:ye.nullable(),brush:cu.nullable(),opacityForNextShape:xA,stylesForNextShape:Pe(e),cursor:xY,scribbles:Wt(AA),isFocusMode:we,isDebugMode:we,isToolLocked:we,exportBackground:we,screenBounds:cu,insets:Wt(we),zoomBrush:cu.nullable(),isPenMode:we,isGridMode:we,chatMessage:ye,isChatting:we,highlightedUserIds:Wt(ye),isFocused:we,devicePixelRatio:pe,isCoarsePointer:we,isHoveringCanvas:we.nullable(),openMenus:Wt(ye),isChangingStyle:we,isReadonly:we,meta:Gt,duplicateProps:Pe({shapeIds:Wt(dr("shape")),offset:Pe({x:pe,y:pe})}).nullable()}));return Hs("instance",{validator:n,scope:"session",ephemeralKeys:{currentPageId:!1,meta:!1,followingUserId:!0,opacityForNextShape:!0,stylesForNextShape:!0,brush:!0,cursor:!0,scribbles:!0,isFocusMode:!0,isDebugMode:!0,isToolLocked:!0,exportBackground:!0,screenBounds:!0,insets:!0,zoomBrush:!0,isPenMode:!0,isGridMode:!0,chatMessage:!0,isChatting:!0,highlightedUserIds:!0,isFocused:!0,devicePixelRatio:!0,isCoarsePointer:!0,isHoveringCanvas:!0,openMenus:!0,isChangingStyle:!0,isReadonly:!0,duplicateProps:!0}}).withDefaultProperties(()=>({followingUserId:null,opacityForNextShape:1,stylesForNextShape:{},brush:null,scribbles:[],cursor:{type:"default",rotation:0},isFocusMode:!1,exportBackground:!1,isDebugMode:!1,isToolLocked:!1,screenBounds:{x:0,y:0,w:1080,h:720},insets:[!1,!1,!1,!1],zoomBrush:null,isGridMode:!1,isPenMode:!1,chatMessage:"",isChatting:!1,highlightedUserIds:[],isFocused:!1,devicePixelRatio:typeof window>"u"?1:window.devicePixelRatio,isCoarsePointer:!1,isHoveringCanvas:null,openMenus:[],isChangingStyle:!1,isReadonly:!1,meta:{},duplicateProps:null}))}const et=Zn("com.tldraw.instance",{AddTransparentExportBgs:1,RemoveDialog:2,AddToolLockMode:3,RemoveExtraPropsForNextShape:4,AddLabelColor:5,AddFollowingUserId:6,RemoveAlignJustify:7,AddZoom:8,AddVerticalAlign:9,AddScribbleDelay:10,RemoveUserId:11,AddIsPenModeAndIsGridMode:12,HoistOpacity:13,AddChat:14,AddHighlightedUserIds:15,ReplacePropsForNextShapeWithStylesForNextShape:16,AddMeta:17,RemoveCursorColor:18,AddLonelyProperties:19,ReadOnlyReadonly:20,AddHoveringCanvas:21,AddScribbles:22,AddInset:23,AddDuplicateProps:24,RemoveCanMoveCamera:25}),TY=xr({sequenceId:"com.tldraw.instance",recordType:"instance",sequence:[{id:et.AddTransparentExportBgs,up:t=>({...t,exportBackground:!0})},{id:et.RemoveDialog,up:({dialog:t,...e})=>e},{id:et.AddToolLockMode,up:t=>({...t,isToolLocked:!1})},{id:et.RemoveExtraPropsForNextShape,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:Object.fromEntries(Object.entries(t).filter(([n])=>["color","labelColor","dash","fill","size","font","align","verticalAlign","icon","geo","arrowheadStart","arrowheadEnd","spline"].includes(n)))})},{id:et.AddLabelColor,up:({propsForNextShape:t,...e})=>({...e,propsForNextShape:{...t,labelColor:"black"}})},{id:et.AddFollowingUserId,up:t=>({...t,followingUserId:null})},{id:et.RemoveAlignJustify,up:t=>{let e=t.propsForNextShape.align;return e==="justify"&&(e="start"),{...t,propsForNextShape:{...t.propsForNextShape,align:e}}}},{id:et.AddZoom,up:t=>({...t,zoomBrush:null})},{id:et.AddVerticalAlign,up:t=>({...t,propsForNextShape:{...t.propsForNextShape,verticalAlign:"middle"}})},{id:et.AddScribbleDelay,up:t=>t.scribble!==null?{...t,scribble:{...t.scribble,delay:0}}:{...t}},{id:et.RemoveUserId,up:({userId:t,...e})=>e},{id:et.AddIsPenModeAndIsGridMode,up:t=>({...t,isPenMode:!1,isGridMode:!1})},{id:et.HoistOpacity,up:({propsForNextShape:{opacity:t,...e},...n})=>({...n,opacityForNextShape:Number(t??"1"),propsForNextShape:e})},{id:et.AddChat,up:t=>({...t,chatMessage:"",isChatting:!1})},{id:et.AddHighlightedUserIds,up:t=>({...t,highlightedUserIds:[]})},{id:et.ReplacePropsForNextShapeWithStylesForNextShape,up:({propsForNextShape:t,...e})=>({...e,stylesForNextShape:{}})},{id:et.AddMeta,up:t=>({...t,meta:{}})},{id:et.RemoveCursorColor,up:t=>{const{color:e,...n}=t.cursor;return{...t,cursor:n}}},{id:et.AddLonelyProperties,up:t=>({...t,canMoveCamera:!0,isFocused:!1,devicePixelRatio:1,isCoarsePointer:!1,openMenus:[],isChangingStyle:!1,isReadOnly:!1})},{id:et.ReadOnlyReadonly,up:({isReadOnly:t,...e})=>({...e,isReadonly:t})},{id:et.AddHoveringCanvas,up:t=>({...t,isHoveringCanvas:null})},{id:et.AddScribbles,up:({scribble:t,...e})=>({...e,scribbles:[]})},{id:et.AddInset,up:t=>({...t,insets:[!1,!1,!1,!1]}),down:({insets:t,...e})=>({...e})},{id:et.AddDuplicateProps,up:t=>({...t,duplicateProps:null}),down:({duplicateProps:t,...e})=>({...e})},{id:et.RemoveCanMoveCamera,up:({canMoveCamera:t,...e})=>({...e}),down:t=>({...t,canMoveCamera:!0})}]}),bn="instance:instance",MY=Ks("instance_page_state",Pe({typeName:mn("instance_page_state"),id:dr("instance_page_state"),pageId:zu,selectedShapeIds:Wt(Ir),hintingShapeIds:Wt(Ir),erasingShapeIds:Wt(Ir),hoveredShapeId:Ir.nullable(),editingShapeId:Ir.nullable(),croppingShapeId:Ir.nullable(),focusedGroupId:Ir.nullable(),meta:Gt})),_c=Zn("com.tldraw.instance_page_state",{AddCroppingId:1,RemoveInstanceIdAndCameraId:2,AddMeta:3,RenameProperties:4,RenamePropertiesAgain:5}),AY=xr({sequenceId:"com.tldraw.instance_page_state",recordType:"instance_page_state",sequence:[{id:_c.AddCroppingId,up(t){t.croppingShapeId=null}},{id:_c.RemoveInstanceIdAndCameraId,up(t){delete t.instanceId,delete t.cameraId}},{id:_c.AddMeta,up:t=>{t.meta={}}},{id:_c.RenameProperties,up:t=>{},down:t=>{}},{id:_c.RenamePropertiesAgain,up:t=>{t.selectedShapeIds=t.selectedIds,delete t.selectedIds,t.hintingShapeIds=t.hintingIds,delete t.hintingIds,t.erasingShapeIds=t.erasingIds,delete t.erasingIds,t.hoveredShapeId=t.hoveredId,delete t.hoveredId,t.editingShapeId=t.editingId,delete t.editingId,t.croppingShapeId=t.croppingShapeId??t.croppingId??null,delete t.croppingId,t.focusedGroupId=t.focusLayerId,delete t.focusLayerId},down:t=>{t.selectedIds=t.selectedShapeIds,delete t.selectedShapeIds,t.hintingIds=t.hintingShapeIds,delete t.hintingShapeIds,t.erasingIds=t.erasingShapeIds,delete t.erasingShapeIds,t.hoveredId=t.hoveredShapeId,delete t.hoveredShapeId,t.editingId=t.editingShapeId,delete t.editingShapeId,t.croppingId=t.croppingShapeId,delete t.croppingShapeId,t.focusLayerId=t.focusedGroupId,delete t.focusedGroupId}}]}),Qr=Hs("instance_page_state",{validator:MY,scope:"session",ephemeralKeys:{pageId:!1,selectedShapeIds:!1,editingShapeId:!1,croppingShapeId:!1,meta:!1,hintingShapeIds:!0,erasingShapeIds:!0,hoveredShapeId:!0,focusedGroupId:!0}}).withDefaultProperties(()=>({editingShapeId:null,croppingShapeId:null,selectedShapeIds:[],hoveredShapeId:null,erasingShapeIds:[],hintingShapeIds:[],focusedGroupId:null,meta:{}})),jY=Ks("pointer",Pe({typeName:mn("pointer"),id:dr("pointer"),x:pe,y:pe,lastActivityTimestamp:pe,meta:Gt})),OY=Zn("com.tldraw.pointer",{AddMeta:1}),DY=xr({sequenceId:"com.tldraw.pointer",recordType:"pointer",sequence:[{id:OY.AddMeta,up:t=>{t.meta={}}}]}),lb=Hs("pointer",{validator:jY,scope:"session"}).withDefaultProperties(()=>({x:0,y:0,lastActivityTimestamp:0,meta:{}})),Ap=lb.createId("pointer"),RY=Ks("instance_presence",Pe({typeName:mn("instance_presence"),id:dr("instance_presence"),userId:ye,userName:ye,lastActivityTimestamp:pe.nullable(),followingUserId:ye.nullable(),cursor:Pe({x:pe,y:pe,type:MA,rotation:pe}).nullable(),color:ye,camera:Pe({x:pe,y:pe,z:pe}).nullable(),screenBounds:cu.nullable(),selectedShapeIds:Wt(dr("shape")),currentPageId:dr("page"),brush:cu.nullable(),scribbles:Wt(AA),chatMessage:ye,meta:Gt})),Oa=Zn("com.tldraw.instance_presence",{AddScribbleDelay:1,RemoveInstanceId:2,AddChatMessage:3,AddMeta:4,RenameSelectedShapeIds:5,NullableCameraCursor:6}),LY=xr({sequenceId:"com.tldraw.instance_presence",recordType:"instance_presence",sequence:[{id:Oa.AddScribbleDelay,up:t=>{t.scribble!==null&&(t.scribble.delay=0)}},{id:Oa.RemoveInstanceId,up:t=>{delete t.instanceId}},{id:Oa.AddChatMessage,up:t=>{t.chatMessage=""}},{id:Oa.AddMeta,up:t=>{t.meta={}}},{id:Oa.RenameSelectedShapeIds,up:t=>{}},{id:Oa.NullableCameraCursor,up:t=>{},down:t=>{t.camera===null&&(t.camera={x:0,y:0,z:1}),t.lastActivityTimestamp===null&&(t.lastActivityTimestamp=0),t.cursor===null&&(t.cursor={type:"default",x:0,y:0,rotation:0}),t.screenBounds===null&&(t.screenBounds={x:0,y:0,w:1,h:1})}}]}),$Y=Hs("instance_presence",{validator:RY,scope:"presence"}).withDefaultProperties(()=>({lastActivityTimestamp:null,followingUserId:null,color:"#FF0000",camera:null,cursor:null,screenBounds:null,selectedShapeIds:[],brush:null,scribbles:[],chatMessage:"",meta:{}})),FY=Ks("document",Pe({typeName:mn("document"),id:mn("document:document"),gridSize:pe,name:ye,meta:Gt})),V_=Zn("com.tldraw.document",{AddName:1,AddMeta:2}),NY=xr({sequenceId:"com.tldraw.document",recordType:"document",sequence:[{id:V_.AddName,up:t=>{t.name=""},down:t=>{delete t.name}},{id:V_.AddMeta,up:t=>{t.meta={}}}]}),cb=Hs("document",{validator:FY,scope:"document"}).withDefaultProperties(()=>({gridSize:10,name:"",meta:{}})),yx=cb.createId("document");function zY(t,e){return t.index<e.index?-1:t.index>e.index?1:0}function Y_(t){t.typeName==="asset"&&("src"in t&&(t.src="<redacted>"),"src"in t.props&&(t.props.src="<redacted>"))}function BY({error:t,phase:e,record:n,recordBefore:r}){throw v0(t,{tags:{origin:"store.validateRecord",storePhase:e,isExistingValidationIssue:e==="initialize"},extras:{recordBefore:r?Y_(nt(r)):void 0,recordAfter:Y_(nt(n))}}),t}function UY(){return[yr.create({id:"page:page",name:"Page 1",index:"a1",meta:{}})]}function HY(t){const e=t.query.ids("page"),n=t.query.records("instance_page_state"),r=()=>{if(!t.has(yx))return t.put([cb.create({id:yx,name:t.props.defaultName})]),r();if(!t.has(Ap))return t.put([lb.create({id:Ap})]),r();const s=e.get();if(s.size===0)return t.put(UY()),r();const o=()=>[...s].map(u=>t.get(u)).sort(zY)[0].id,i=t.get(bn);if(i){if(!s.has(i.currentPageId))return t.put([{...i,currentPageId:o()}]),r()}else return t.put([t.schema.types.instance.create({id:bn,currentPageId:o(),exportBackground:!0})]),r();const a=new Set,l=new Set;for(const u of s){const h=Qr.createId(u);t.get(h)||a.add(h);const p=Is.createId(u);t.has(p)||l.add(p)}a.size>0&&t.put([...a].map(u=>Qr.create({id:u,pageId:Qr.parseId(u)}))),l.size>0&&t.put([...l].map(u=>Is.create({id:u})));const c=n.get();for(const u of c){if(!s.has(u.pageId)){t.remove([u.id]);continue}if(u.croppingShapeId&&!t.has(u.croppingShapeId))return t.put([{...u,croppingShapeId:null}]),r();if(u.focusedGroupId&&!t.has(u.focusedGroupId))return t.put([{...u,focusedGroupId:null}]),r();if(u.hoveredShapeId&&!t.has(u.hoveredShapeId))return t.put([{...u,hoveredShapeId:null}]),r();const h=u.selectedShapeIds.filter(g=>t.has(g));if(h.length!==u.selectedShapeIds.length)return t.put([{...u,selectedShapeIds:h}]),r();const f=u.hintingShapeIds.filter(g=>t.has(g));if(f.length!==u.hintingShapeIds.length)return t.put([{...u,hintingShapeIds:f}]),r();const p=u.erasingShapeIds.filter(g=>t.has(g));if(p.length!==u.erasingShapeIds.length)return t.put([{...u,erasingShapeIds:p}]),r()}};return r}const KY=ib("bookmark",Pe({title:ye,description:ye,image:ye,favicon:ye,src:la.nullable()})),X_=Zn("com.tldraw.asset.bookmark",{MakeUrlsValid:1,AddFavicon:2}),WY=xr({sequenceId:"com.tldraw.asset.bookmark",recordType:"asset",filter:t=>t.type==="bookmark",sequence:[{id:X_.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:X_.AddFavicon,up:t=>{la.isValid(t.props.favicon)||(t.props.favicon="")},down:t=>{delete t.props.favicon}}]}),GY=ib("image",Pe({w:pe,h:pe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:la.nullable(),fileSize:Pt.optional()})),Ic=Zn("com.tldraw.asset.image",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),VY=xr({sequenceId:"com.tldraw.asset.image",recordType:"asset",filter:t=>t.type==="image",sequence:[{id:Ic.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ic.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:Ic.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ic.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ic.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),YY=ib("video",Pe({w:pe,h:pe,name:ye,isAnimated:we,mimeType:ye.nullable(),src:la.nullable(),fileSize:pe.optional()})),Ec=Zn("com.tldraw.asset.video",{AddIsAnimated:1,RenameWidthHeight:2,MakeUrlsValid:3,AddFileSize:4,MakeFileSizeOptional:5}),XY=xr({sequenceId:"com.tldraw.asset.video",recordType:"asset",filter:t=>t.type==="video",sequence:[{id:Ec.AddIsAnimated,up:t=>{t.props.isAnimated=!1},down:t=>{delete t.props.isAnimated}},{id:Ec.RenameWidthHeight,up:t=>{t.props.w=t.props.width,t.props.h=t.props.height,delete t.props.width,delete t.props.height},down:t=>{t.props.width=t.props.w,t.props.height=t.props.h,delete t.props.w,delete t.props.h}},{id:Ec.MakeUrlsValid,up:t=>{la.isValid(t.props.src)||(t.props.src="")},down:t=>{}},{id:Ec.AddFileSize,up:t=>{t.props.fileSize=-1},down:t=>{delete t.props.fileSize}},{id:Ec.MakeFileSizeOptional,up:t=>{t.props.fileSize===-1&&(t.props.fileSize=void 0)},down:t=>{t.props.fileSize===void 0&&(t.props.fileSize=-1)}}]}),qY=Ks("asset",rb("type",{image:GY,video:YY,bookmark:KY})),ZY=Zn("com.tldraw.asset",{AddMeta:1}),QY=xr({sequenceId:"com.tldraw.asset",recordType:"asset",sequence:[{id:ZY.AddMeta,up:t=>{t.meta={}}}]}),Yo=Hs("asset",{validator:qY,scope:"document"}).withDefaultProperties(()=>({meta:{}})),OA={w:Pt,h:Pt,assetId:Dg.nullable(),url:gr},q_=us("bookmark",{NullAssetId:1,MakeUrlsValid:2}),DA={sequence:[{id:q_.NullAssetId,up:t=>{t.assetId===void 0&&(t.assetId=null)},down:"retired"},{id:q_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},RA=Pe({type:Og("free","straight"),points:Wt(ca)}),LA={color:mr,fill:da,dash:ua,size:$s,segments:Wt(RA),isComplete:we,isClosed:we,isPen:we,scale:Pt},Z_=us("draw",{AddInPen:1,AddScale:2}),$A={sequence:[{id:Z_.AddInPen,up:t=>{const{points:e}=t.segments[0];if(e.length===0){t.isPen=!1;return}let n=!(e[0].z===0||e[0].z===.5);e[1]&&(n=n&&!(e[1].z===0||e[1].z===.5)),t.isPen=n},down:"retired"},{id:Z_.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},JY=/(^\/r\/[^/]+\/?$)/,eX=[{hostnames:["beta.tldraw.com","tldraw.com","localhost:3000"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(JY))return t}},{hostnames:["figma.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{hostnames:["google.*"],fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${r}z`}}},{hostnames:["val.town"],fromEmbedUrl:t=>{const e=ge(t),n=e&&e.pathname.match(/\/embed\/(.+)\/?/);if(n)return`https://www.val.town/v/${n[1]}`}},{hostnames:["codesandbox.io"],fromEmbedUrl:t=>{const e=ge(t),n=e&&e.pathname.match(/\/embed\/([^/]+)\/?/);if(n)return`https://codesandbox.io/s/${n[1]}`}},{hostnames:["codepen.io"],fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{hostnames:["scratch.mit.edu"],fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{hostnames:["*.youtube.com","youtube.com","youtu.be"],fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{hostnames:["calendar.google.*"],fromEmbedUrl:t=>{const e=ge(t),n=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&n){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const s of r)e.searchParams.delete(s);return e.searchParams.set("cid",n),e.href}}},{hostnames:["docs.google.*"],fromEmbedUrl:t=>{const e=ge(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}}},{hostnames:["gist.github.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([^/]+)/))return t.split("/").pop()?t:void 0}},{hostnames:["replit.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{hostnames:["felt.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{hostnames:["open.spotify.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{hostnames:["vimeo.com","player.vimeo.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="player.vimeo.com"){const n=e.pathname.match(/^\/video\/([^/]+)\/?$/);if(n)return"https://vimeo.com/"+n[1]}}},{hostnames:["excalidraw.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hash.match(/#room=/))return t}},{hostnames:["observablehq.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","")}#cell-*`;if(e&&e.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","/d")}#cell-*`}},{hostnames:["desmos.com"],fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],FA={w:Pt,h:Pt,url:ye},uh=us("embed",{GenOriginalUrlInEmbed:1,RemoveDoesResize:2,RemoveTmpOldUrl:3,RemovePermissionOverrides:4}),NA={sequence:[{id:uh.GenOriginalUrlInEmbed,up:t=>{try{const e=t.url,n=new URL(e).host.replace("www.","");let r;for(const s of eX)if(s.hostnames.includes(n))try{r=s.fromEmbedUrl(e)}catch(o){console.warn(o)}t.tmpOldUrl=t.url,t.url=r??""}catch{t.url="",t.tmpOldUrl=t.url}},down:"retired"},{id:uh.RemoveDoesResize,up:t=>{delete t.doesResize},down:"retired"},{id:uh.RemoveTmpOldUrl,up:t=>{delete t.tmpOldUrl},down:"retired"},{id:uh.RemovePermissionOverrides,up:t=>{delete t.overridePermissions},down:"retired"}]},zA={w:Pt,h:Pt,name:ye},BA={sequence:[]},jp=Qt.defineEnum("tldraw:horizontalAlign",{defaultValue:"middle",values:["start","middle","end","start-legacy","end-legacy","middle-legacy"]}),Op=Qt.defineEnum("tldraw:verticalAlign",{defaultValue:"middle",values:["start","middle","end"]}),Jr=Qt.defineEnum("tldraw:geo",{defaultValue:"rectangle",values:["cloud","rectangle","ellipse","triangle","diamond","pentagon","hexagon","octagon","star","rhombus","rhombus-2","oval","trapezoid","arrow-right","arrow-left","arrow-up","arrow-down","x-box","check-box","heart"]}),UA={geo:Jr,labelColor:ab,color:mr,fill:da,dash:ua,size:$s,font:Ls,align:jp,verticalAlign:Op,url:gr,w:Pt,h:Pt,growY:Ip,text:ye,scale:Pt},Qs=us("geo",{AddUrlProp:1,AddLabelColor:2,RemoveJustify:3,AddCheckBox:4,AddVerticalAlign:5,MigrateLegacyAlign:6,AddCloud:7,MakeUrlsValid:8,AddScale:9}),HA={sequence:[{id:Qs.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Qs.AddLabelColor,up:t=>{t.labelColor="black"},down:"retired"},{id:Qs.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Qs.AddCheckBox,up:t=>{},down:"retired"},{id:Qs.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Qs.MigrateLegacyAlign,up:t=>{let e;switch(t.align){case"start":e="start-legacy";break;case"end":e="end-legacy";break;default:e="middle-legacy";break}t.align=e},down:"retired"},{id:Qs.AddCloud,up:t=>{},down:"retired"},{id:Qs.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Qs.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},KA={},WA={sequence:[]},GA={color:mr,size:$s,segments:Wt(RA),isComplete:we,isPen:we,scale:Pt},tX=us("highlight",{AddScale:1}),VA={sequence:[{id:tX.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},nX=Pe({topLeft:ca,bottomRight:ca}),YA={w:Pt,h:Pt,playing:we,url:gr,assetId:Dg.nullable(),crop:nX.nullable(),flipX:we,flipY:we},dh=us("image",{AddUrlProp:1,AddCropProp:2,MakeUrlsValid:3,AddFlipProps:4}),XA={sequence:[{id:dh.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:dh.AddCropProp,up:t=>{t.crop=null},down:t=>{delete t.crop}},{id:dh.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:dh.AddFlipProps,up:t=>{t.flipX=!1,t.flipY=!1},down:t=>{delete t.flipX,delete t.flipY}}]},Dp=Qt.defineEnum("tldraw:spline",{defaultValue:"line",values:["cubic","line"]}),rX=Pe({id:ye,index:ob,x:pe,y:pe}),qA={color:mr,dash:ua,size:$s,spline:Dp,points:Ep(ye,rX),scale:Pt},kc=us("line",{AddSnapHandles:1,RemoveExtraHandleProps:2,HandlesToPoints:3,PointIndexIds:4,AddScale:5}),ZA={sequence:[{id:kc.AddSnapHandles,up:t=>{for(const e of Object.values(t.handles))e.canSnap=!0},down:"retired"},{id:kc.RemoveExtraHandleProps,up:t=>{t.handles=w0(Object.values(t.handles).map(e=>[e.index,{x:e.x,y:e.y}]))},down:t=>{const e=Object.entries(t.handles).map(([n,r])=>({index:n,...r})).sort(cn);t.handles=Object.fromEntries(e.map((n,r)=>{const s=r===0?"start":r===e.length-1?"end":`handle:${n.index}`;return[s,{id:s,type:"vertex",canBind:!1,canSnap:!0,index:n.index,x:n.x,y:n.y}]}))}},{id:kc.HandlesToPoints,up:t=>{const e=Object.entries(t.handles).map(([n,{x:r,y:s}])=>({x:r,y:s,index:n})).sort(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r})),delete t.handles},down:t=>{const e=Fu(t.points.length);t.handles=Object.fromEntries(t.points.map((n,r)=>[e[r],{x:n.x,y:n.y}])),delete t.points}},{id:kc.PointIndexIds,up:t=>{const e=Fu(t.points.length);t.points=Object.fromEntries(t.points.map((n,r)=>{const s=e[r];return[s,{id:s,index:s,x:n.x,y:n.y}]}))},down:t=>{const e=Object.values(t.points).sort(cn);t.points=e.map(({x:n,y:r})=>({x:n,y:r}))}},{id:kc.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}}]},QA={color:mr,labelColor:ab,size:$s,font:Ls,fontSizeAdjustment:Ip,align:jp,verticalAlign:Op,growY:Ip,url:gr,text:ye,scale:Pt},Fo=us("note",{AddUrlProp:1,RemoveJustify:2,MigrateLegacyAlign:3,AddVerticalAlign:4,MakeUrlsValid:5,AddFontSizeAdjustment:6,AddScale:7,AddLabelColor:8}),JA={sequence:[{id:Fo.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:Fo.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Fo.MigrateLegacyAlign,up:t=>{switch(t.align){case"start":t.align="start-legacy";return;case"end":t.align="end-legacy";return;default:t.align="middle-legacy";return}},down:"retired"},{id:Fo.AddVerticalAlign,up:t=>{t.verticalAlign="middle"},down:"retired"},{id:Fo.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}},{id:Fo.AddFontSizeAdjustment,up:t=>{t.fontSizeAdjustment=0},down:t=>{delete t.fontSizeAdjustment}},{id:Fo.AddScale,up:t=>{t.scale=1},down:t=>{delete t.scale}},{id:Fo.AddLabelColor,up:t=>{t.labelColor="black"},down:t=>{delete t.labelColor}}]},Sx=Qt.defineEnum("tldraw:textAlign",{defaultValue:"start",values:["start","middle","end"]}),ej={color:mr,size:$s,font:Ls,textAlign:Sx,w:Pt,text:ye,scale:Pt,autoSize:we},Q_=us("text",{RemoveJustify:1,AddTextAlign:2}),tj={sequence:[{id:Q_.RemoveJustify,up:t=>{t.align==="justify"&&(t.align="start")},down:"retired"},{id:Q_.AddTextAlign,up:t=>{t.textAlign=t.align,delete t.align},down:t=>{t.align=t.textAlign,delete t.textAlign}}]},nj={w:Pt,h:Pt,time:pe,playing:we,url:gr,assetId:Dg.nullable()},J_=us("video",{AddUrlProp:1,MakeUrlsValid:2}),rj={sequence:[{id:J_.AddUrlProp,up:t=>{t.url=""},down:"retired"},{id:J_.MakeUrlsValid,up:t=>{gr.isValid(t.url)||(t.url="")},down:t=>{}}]},hh=Zn("com.tldraw.store",{RemoveCodeAndIconShapeTypes:1,AddInstancePresenceType:2,RemoveTLUserAndPresenceAndAddPointer:3,RemoveUserDocument:4}),sX=vl({sequenceId:"com.tldraw.store",retroactive:!1,sequence:[{id:hh.RemoveCodeAndIconShapeTypes,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName==="shape"&&(n.type==="icon"||n.type==="code")&&delete t[e]}},{id:hh.AddInstancePresenceType,scope:"store",up(t){}},{id:hh.RemoveTLUserAndPresenceAndAddPointer,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match(/^(user|user_presence)$/)&&delete t[e]}},{id:hh.RemoveUserDocument,scope:"store",up:t=>{for(const[e,n]of Xn(t))n.typeName.match("user_document")&&delete t[e]}}]}),oX={arrow:{migrations:EA,props:IA},bookmark:{migrations:DA,props:OA},draw:{migrations:$A,props:LA},embed:{migrations:NA,props:FA},frame:{migrations:BA,props:zA},geo:{migrations:HA,props:UA},group:{migrations:WA,props:KA},highlight:{migrations:VA,props:GA},image:{migrations:XA,props:YA},line:{migrations:ZA,props:qA},note:{migrations:JA,props:QA},text:{migrations:tj,props:ej},video:{migrations:rj,props:nj}},iX={arrow:{migrations:TA,props:kA}};function aX({shapes:t=oX,bindings:e=iX,migrations:n}={}){const r=new Map;for(const a of ut(t))for(const l of wA(a.props??{}).keys()){if(r.has(l.id)&&r.get(l.id)!==l)throw new Error(`Multiple StyleProp instances with the same id: ${l.id}`);r.set(l.id,l)}const s=gY(t),o=hY(e),i=kY(r);return tb.create({asset:Yo,binding:o,camera:Is,document:cb,instance:i,instance_page_state:Qr,page:yr,instance_presence:$Y,pointer:lb,shape:s},{migrations:[sX,QY,SY,NY,TY,AY,IY,LY,DY,pY,WY,VY,XY,...G_("shape",t),...G_("binding",e),...n??[]],onValidationFailure:BY,createIntegrityChecker:HY})}const Bu=[{locale:"id",label:"Bahasa Indonesia"},{locale:"ca",label:"Català"},{locale:"cs",label:"Čeština"},{locale:"da",label:"Danish"},{locale:"de",label:"Deutsch"},{locale:"en",label:"English"},{locale:"es",label:"Español"},{locale:"fr",label:"Français"},{locale:"gl",label:"Galego"},{locale:"hr",label:"Hrvatski"},{locale:"it",label:"Italiano"},{locale:"hu",label:"Magyar"},{locale:"no",label:"Norwegian"},{locale:"pl",label:"Polski"},{locale:"pt-br",label:"Português - Brasil"},{locale:"pt-pt",label:"Português - Europeu"},{locale:"ro",label:"Română"},{locale:"ru",label:"Russian"},{locale:"sl",label:"Slovenščina"},{locale:"so",label:"Somali"},{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 lX(){const t=typeof window<"u"?window.navigator.languages??["en"]:["en"];return cX(t)}function cX(t){for(const e of t){const n=uX(e);if(n)return n}return"en"}const eI={zh:"zh-cn",pt:"pt-br",ko:"ko-kr",hi:"hi-in"};function uX(t){const e=Bu.find(s=>s.locale===t.toLowerCase());if(e)return e.locale;const[n,r]=t.split(/[-_]/).map(s=>s.toLowerCase());if(r){const s=Bu.find(o=>o.locale===n);if(s)return s.locale}return n in eI?eI[n]:null}_i("@tldraw/tlschema","3.7.2","esm");var sj={exports:{}};/*!
|
|
85
85
|
Copyright (c) 2018 Jed Watson.
|
|
86
86
|
Licensed under the MIT License (MIT), see
|
|
87
87
|
http://jedwatson.github.io/classnames
|
|
88
|
-
*/(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var o="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(o=s(o,r(a)))}return o}function r(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return n.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var i="";for(var a in o)e.call(o,a)&&o[a]&&(i=s(i,a));return i}function s(o,i){return i?o?o+" "+i:o+i:o}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(sj);var dX=sj.exports;const ce=wi(dX),oj="3.8.0-canary.c422debb621c",tI={major:"2024-09-13T14:36:29.063Z",minor:"2025-01-09T17:28:08.649Z",patch:"2025-01-09T17:28:08.649Z"},hX={error:null};class ub extends w.Component{constructor(){super(...arguments);I(this,"state",hX)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,s;(s=(r=this.props).onError)==null||s.call(r,n)}render(){const{error:n}=this.state;if(n!==null){const{fallback:r}=this.props;return d.jsx(r,{error:n})}return this.props.children}}function Uu({children:t,fallback:e,...n}){return e===null?t:d.jsx(ub,{fallback:e,...n,children:t})}function db(t,e){return Rg(`${t}_${e}`)}function Jl(t){return Rg(`${w.useId()}${t??""}`)}function rs(t){const e=zn(w.useContext(ij));return Rg(`${e}_${t}`)}function Rg(t){return t.replace(/:/g,"_")}const ij=w.createContext(null);function fX({children:t}){const e=Jl();return d.jsx(ij.Provider,{value:e,children:t})}const hb=w.createContext(null);function z(){const t=ke.useContext(hb);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function Ti(){return ke.useContext(hb)}function fb({editor:t,children:e}){return d.jsx(hb.Provider,{value:t,children:d.jsx(fX,{children:e})})}function pX(){return d.jsx("div",{className:"tl-background"})}function ec(t,e,n,r,s,o){w.useLayoutEffect(()=>{const i=t.current;if(!i||e===void 0)return;let a=`translate(${e}px, ${n}px)`;r!==void 0&&(a+=` scale(${r})`),s!==void 0&&(a+=` rotate(${s}rad)`),o&&(a+=` translate(${o.x}px, ${o.y}px)`),i.style.transform=a})}const Dt={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>t*(2-t),easeInOutQuad:t=>t<.5?2*t*t:-1+(4-2*t)*t,easeInCubic:t=>t*t*t,easeOutCubic:t=>--t*t*t+1,easeInOutCubic:t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,easeInQuart:t=>t*t*t*t,easeOutQuart:t=>1- --t*t*t*t,easeInOutQuart:t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t,easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>1+--t*t*t*t*t,easeInOutQuint:t=>t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t,easeInSine:t=>1-Math.cos(t*Math.PI/2),easeOutSine:t=>Math.sin(t*Math.PI/2),easeInOutSine:t=>-(Math.cos(Math.PI*t)-1)/2,easeInExpo:t=>t<=0?0:Math.pow(2,10*t-10),easeOutExpo:t=>t>=1?1:1-Math.pow(2,-10*t),easeInOutExpo:t=>t<=0?0:t>=1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2};class x{constructor(e=0,n=0,r=1){this.x=e,this.y=n,this.z=r}get pressure(){return this.z}set(e=this.x,n=this.y,r=this.z){return this.x=e,this.y=n,this.z=r,this}setTo({x:e=0,y:n=0,z:r=1}){return this.x=e,this.y=n,this.z=r,this}rot(e){if(e===0)return this;const{x:n,y:r}=this,s=Math.sin(e),o=Math.cos(e);return this.x=n*o-r*s,this.y=n*s+r*o,this}rotWith(e,n){if(n===0)return this;const r=this.x-e.x,s=this.y-e.y,o=Math.sin(n),i=Math.cos(n);return this.x=e.x+(r*i-s*o),this.y=e.y+(r*o+s*i),this}clone(){const{x:e,y:n,z:r}=this;return new x(e,n,r)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,n){return this.x-=e,this.y-=n,this}subScalar(e){return this.x-=e,this.y-=e,this}add(e){return this.x+=e.x,this.y+=e.y,this}addXY(e,n){return this.x+=e,this.y+=n,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,n){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),n!==void 0&&(this.x=Math.min(this.x,n),this.y=Math.min(this.y,n)),this}div(e){return this.x/=e,this.y/=e,this}divV(e){return this.x/=e.x,this.y/=e.y,this}mul(e){return this.x*=e,this.y*=e,this}mulV(e){return this.x*=e.x,this.y*=e.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(e,n){const r=x.Tan(e,this);return this.add(r.mul(n))}neg(){return this.x*=-1,this.y*=-1,this}cross(e){return this.x=this.y*e.z-this.z*e.y,this.y=this.z*e.x-this.x*e.z,this}dpr(e){return x.Dpr(this,e)}cpr(e){return x.Cpr(this,e)}len2(){return x.Len2(this)}len(){return x.Len(this)}pry(e){return x.Pry(this,e)}per(){const{x:e,y:n}=this;return this.x=n,this.y=-e,this}uni(){return x.Uni(this)}tan(e){return x.Tan(this,e)}dist(e){return x.Dist(this,e)}distanceToLineSegment(e,n){return x.DistanceToLineSegment(e,n,this)}slope(e){return x.Slope(this,e)}snapToGrid(e){return this.x=Math.round(this.x/e)*e,this.y=Math.round(this.y/e)*e,this}angle(e){return x.Angle(this,e)}toAngle(){return x.ToAngle(this)}lrp(e,n){return this.x=this.x+(e.x-this.x)*n,this.y=this.y+(e.y-this.y)*n,this}equals(e){return x.Equals(this,e)}equalsXY(e,n){return x.EqualsXY(this,e,n)}norm(){const e=this.len();return this.x=e===0?0:this.x/e,this.y=e===0?0:this.y/e,this}toFixed(){return x.ToFixed(this)}toString(){return x.ToString(x.ToFixed(this))}toJson(){return x.ToJson(this)}toArray(){return x.ToArray(this)}static Add(e,n){return new x(e.x+n.x,e.y+n.y)}static AddXY(e,n,r){return new x(e.x+n,e.y+r)}static Sub(e,n){return new x(e.x-n.x,e.y-n.y)}static SubXY(e,n,r){return new x(e.x-n,e.y-r)}static AddScalar(e,n){return new x(e.x+n,e.y+n)}static SubScalar(e,n){return new x(e.x-n,e.y-n)}static Div(e,n){return new x(e.x/n,e.y/n)}static Mul(e,n){return new x(e.x*n,e.y*n)}static DivV(e,n){return new x(e.x/n.x,e.y/n.y)}static MulV(e,n){return new x(e.x*n.x,e.y*n.y)}static Neg(e){return new x(-e.x,-e.y)}static Per(e){return new x(e.y,-e.x)}static Abs(e){return new x(Math.abs(e.x),Math.abs(e.y))}static Dist(e,n){return((e.y-n.y)**2+(e.x-n.x)**2)**.5}static DistMin(e,n,r){return(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y)<r**2}static Dist2(e,n){return(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y)}static Dpr(e,n){return e.x*n.x+e.y*n.y}static Cross(e,n){return new x(e.y*n.z-e.z*n.y,e.z*n.x-e.x*n.z)}static Cpr(e,n){return e.x*n.y-n.x*e.y}static Len2(e){return e.x*e.x+e.y*e.y}static Len(e){return(e.x*e.x+e.y*e.y)**.5}static Pry(e,n){return x.Dpr(e,n)/x.Len(n)}static Uni(e){return x.Div(e,x.Len(e))}static Tan(e,n){return x.Uni(x.Sub(e,n))}static Min(e,n){return new x(Math.min(e.x,n.x),Math.min(e.y,n.y))}static Max(e,n){return new x(Math.max(e.x,n.x),Math.max(e.y,n.y))}static From({x:e,y:n,z:r=1}){return new x(e,n,r)}static FromArray(e){return new x(e[0],e[1])}static Rot(e,n=0){const r=Math.sin(n),s=Math.cos(n);return new x(e.x*s-e.y*r,e.x*r+e.y*s)}static RotWith(e,n,r){const s=e.x-n.x,o=e.y-n.y,i=Math.sin(r),a=Math.cos(r);return new x(n.x+(s*a-o*i),n.y+(s*i+o*a))}static NearestPointOnLineThroughPoint(e,n,r){return x.Mul(n,x.Sub(r,e).pry(n)).add(e)}static NearestPointOnLineSegment(e,n,r,s=!0){if(x.Equals(e,r)||x.Equals(n,r))return x.From(r);const o=x.Tan(n,e),i=x.Add(e,x.Mul(o,x.Sub(r,e).pry(o)));if(s){if(i.x<Math.min(e.x,n.x))return x.Cast(e.x<n.x?e:n);if(i.x>Math.max(e.x,n.x))return x.Cast(e.x>n.x?e:n);if(i.y<Math.min(e.y,n.y))return x.Cast(e.y<n.y?e:n);if(i.y>Math.max(e.y,n.y))return x.Cast(e.y>n.y?e:n)}return i}static DistanceToLineThroughPoint(e,n,r){return x.Dist(r,x.NearestPointOnLineThroughPoint(e,n,r))}static DistanceToLineSegment(e,n,r,s=!0){return x.Dist(r,x.NearestPointOnLineSegment(e,n,r,s))}static Snap(e,n=1){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}static Cast(e){return e instanceof x?e:x.From(e)}static Slope(e,n){return e.x===n.y?NaN:(e.y-n.y)/(e.x-n.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static Angle(e,n){return Math.atan2(n.y-e.y,n.x-e.x)}static Lrp(e,n,r){return x.Sub(n,e).mul(r).add(e)}static Med(e,n){return new x((e.x+n.x)/2,(e.y+n.y)/2)}static Equals(e,n){return Math.abs(e.x-n.x)<1e-4&&Math.abs(e.y-n.y)<1e-4}static EqualsXY(e,n,r){return e.x===n&&e.y===r}static Clockwise(e,n,r){return(r.x-e.x)*(n.y-e.y)-(n.x-e.x)*(r.y-e.y)<0}static Rescale(e,n){const r=x.Len(e);return new x(n*e.x/r,n*e.y/r)}static ScaleWithOrigin(e,n,r){return x.Sub(e,r).mul(n).add(r)}static ToFixed(e){return new x(io(e.x),io(e.y))}static ToInt(e){return new x(parseInt(e.x.toFixed(0)),parseInt(e.y.toFixed(0)),parseInt((e.z??0).toFixed(0)))}static ToCss(e){return`${e.x},${e.y}`}static Nudge(e,n,r){return x.Add(e,x.Tan(n,e).mul(r))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let n=Math.atan2(e.y,e.x);return n<0&&(n+=Math.PI*2),n}static FromAngle(e,n=1){return new x(Math.cos(e)*n,Math.sin(e)*n)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){const{x:n,y:r,z:s}=e;return{x:n,y:r,z:s}}static Average(e){const n=e.length,r=new x(0,0);if(n===0)return r;for(let s=0;s<n;s++)r.add(e[s]);return r.div(n)}static Clamp(e,n,r){return r===void 0?new x(Math.min(Math.max(e.x,n)),Math.min(Math.max(e.y,n))):new x(Math.min(Math.max(e.x,n),r),Math.min(Math.max(e.y,n),r))}static PointsBetween(e,n,r=6){const s=[];for(let o=0;o<r;o++){const i=Dt.easeInQuad(o/(r-1)),a=x.Lrp(e,n,i);a.z=Math.min(1,.5+Math.abs(.5-gX(i))*.65),s.push(a)}return s}static SnapToGrid(e,n=8){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}}const gX=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${N(t.x)},${N(t.y)} `}function Bn(t,e){return`${N((t.x+e.x)/2)},${N((t.y+e.y)/2)} `}const De=Math.PI,Ze=De/2,Fe=De*2,mX=Math.sin;function Bt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function fh(t,e=1e10){return t?Math.round(t*e)/e:0}function di(t,e,n=1e-6){return Math.abs(t-e)<=n}function aj(t,e){const n=Math.pow(t-e,2)/Math.pow(t+e,2);return De*(t+e)*(1+3*n/(10+Math.sqrt(4-3*n)))}function ea(t){return t=t%Fe,t<0?t=t+Fe:t===0&&(t=0),t}function ud(t,e){return t=ea(t),e=ea(e),t>e&&(e+=Fe),e-t}function lj(t,e){return Fe-ud(t,e)}function cf(t,e){const n=(e-t)%Fe;return 2*n%Fe-n}function vx(t){return(Fe+t)%Fe}function Rp(t,e){const n=Fe/e;let r=Math.floor((vx(t)+n/2)/n)*n%Fe;return r<De&&(r+=Fe),r>De&&(r-=Fe),r}function cj(t,e){return t===e||di(t%(Math.PI/2)-e%(Math.PI/2),0)}function yX(t){return t*De/180}function SX(t){return t*180/De}function ha(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function Hy(t,e,n){const r=t/2,s=e/2,o=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let g=0;g<n;g++){const m=Fe/n,v=-Ze+g*m,y=r+r*Math.cos(v),S=s+s*Math.sin(v);y<i&&(i=y),S<l&&(l=S),y>a&&(a=y),S>c&&(c=S),o.push(new x(y,S))}const u=a-i,h=c-l,f=t-u,p=e-h;if(f!==0||p!==0)for(let g=0;g<o.length;g++){const m=o[g];m.x=(m.x-i)/u*t,m.y=(m.y-l)/h*e}return o}function Tc(t,e,n,r){return t<r&&n<e}function Gr(t,e,n,r){const s=Math.max(t,n),o=Math.min(e,r);return s<=o?[s,o]:null}function nI(t,e,n){return(e.x-t.x)*(n.y-t.y)-(n.x-t.x)*(e.y-t.y)}function hr(t,e){let n=0,r,s;for(let o=0;o<e.length;o++){if(r=e[o],r.x===t.x&&r.y===t.y||(s=e[(o+1)%e.length],x.Dist(t,r)+x.Dist(t,s)===x.Dist(r,s)))return!0;r.y<=t.y?s.y>t.y&&nI(r,s,t)>0&&(n+=1):s.y<=t.y&&nI(r,s,t)<0&&(n-=1)}return n!==0}function N(t){return Math.round(t*1e4)/1e4}function io(t){return Math.round(t*100)/100}const rI=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function Xo(t,e,n){return n<0?ud(t,e):lj(t,e)}function xx(t,e,n,r){let s;if(Math.abs(t)>De){s=cf(e,r);const o=cf(r,n);return Math.abs(s)<Math.abs(o)?s/t:(t-o)/t}else{s=cf(e,r);const o=s/t;return Math.sign(s)!==Math.sign(t)?Math.abs(o)>.5?1:0:o}}function vX(t,e,n,r){const s=2*((e-t)%Fe)%Fe-(e-t)%Fe;return r?(Fe-Math.abs(s))*(n?1:-1):s}function pb(t,e,n){const r=-2*(t.x*(e.y-n.y)-t.y*(e.x-n.x)+e.x*n.y-n.x*e.y),s=((t.x*t.x+t.y*t.y)*(n.y-e.y)+(e.x*e.x+e.y*e.y)*(t.y-n.y)+(n.x*n.x+n.y*n.y)*(e.y-t.y))/r,o=((t.x*t.x+t.y*t.y)*(e.x-n.x)+(e.x*e.x+e.y*e.y)*(n.x-t.x)+(n.x*n.x+n.y*n.y)*(t.x-e.x))/r;return!Number.isFinite(s)||!Number.isFinite(o)?null:new x(s,o)}function xX(t,e,n,r,s){if(n===null)return[x.From(t),x.From(e)];const o=[],i=x.Angle(n,t),a=x.Angle(n,e),l=ud(i,a);for(let c=0;c<s;c++){const u=c/(s-1),h=i+l*u,f=ha(n,r,h);o.push(f)}return o}const Ky=({brush:t,color:e,opacity:n,className:r})=>{const s=w.useRef(null);ec(s,t.x,t.y);const o=N(Math.max(1,t.w)),i=N(Math.max(1,t.h));return d.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?d.jsxs("g",{className:"tl-brush",opacity:n,children:[d.jsx("rect",{width:o,height:i,fill:e,opacity:.75}),d.jsx("rect",{width:o,height:i,fill:"none",stroke:e,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:o,height:i})})},Ge={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1};typeof window<"u"&&"navigator"in window&&(Ge.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Ge.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Ge.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Ge.isFirefox=/firefox/i.test(navigator.userAgent),Ge.isAndroid=/android/i.test(navigator.userAgent),Ge.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1);const sI={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Wy={duration:0,easing:Dt.easeInOutCubic},oI={CAMERA_MOVE:-10},wX=["top","right","bottom","left"],iI=0,gb=2,ph=1,aI=5,bX=128;var Gy={};const PX={},uj=Dn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),wt={logPreventDefaults:Dn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Dn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Dn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Dn("debugSvg",{defaults:{all:!1}}),showFps:Dn("showFps",{defaults:{all:!1}}),measurePerformance:Dn("measurePerformance",{defaults:{all:!1}}),throwToBlob:Dn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Dn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Dn("debugCursors",{defaults:{all:!1}}),forceSrgb:Dn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Dn("debugGeometry",{defaults:{all:!1}}),hideShapes:Dn("hideShapes",{defaults:{all:!1}}),editOnType:Dn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const t=Element.prototype.removeChild;As("element removal logging",()=>{wt.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),t.call(this,e)}:Element.prototype.removeChild=t})}function Dn(t,{defaults:e,shouldStoreForSession:n=!0}){return CX({name:t,defaults:e,shouldStoreForSession:n})}function CX(t){const e=IX(t),n=t.shouldStoreForSession?_X(t.name):null,r=It(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&As(`debug:${t.name}`,()=>{const s=r.get();s===e?eM(`tldraw_debug:${t.name}`):E0(`tldraw_debug:${t.name}`,JSON.stringify(s))}),Object.defineProperty(window,`tldraw${t.name.replace(/^[a-z]/,s=>s.toUpperCase())}`,{get(){return r.get()},set(s){r.set(s)},configurable:!0})),Object.assign(r,t)}function _X(t){try{return JSON.parse(JT(`tldraw_debug:${t}`)??"null")}catch{return null}}function Vy(t){try{return t()}catch{return null}}function IX(t){switch(Vy(()=>Gy.TLDRAW_ENV)??Vy(()=>Gy.VERCEL_PUBLIC_TLDRAW_ENV)??Vy(()=>Gy.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return t.defaults.production??t.defaults.all;case"preview":case"staging":return t.defaults.staging??t.defaults.all;default:return t.defaults.development??t.defaults.all}}function Lp(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return Lp(t.parentElement);throw Error("Could not find a parent element of an HTML type!")}function xe(t){t.preventDefault(),wt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",t)}function dd(t,e){if(t.setPointerCapture(e.pointerId),wt.logPointerCaptures.get()){const n=uj.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function hd(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),wt.logPointerCaptures.get())){const n=uj.get();n.get(t)===1?n.delete(t):n.has(t)?n.set(t,n.get(t)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",t,e)}}const Ct=t=>t.stopPropagation(),rn=(t,e,n)=>{t&&t.style.setProperty(e,n)},un=t=>Ge.isDarwin?t.metaKey:t.ctrlKey||t.metaKey;function lr(t){return t.isKilled=!0,{point:{x:t.clientX,y:t.clientY,z:t.pressure},shiftKey:t.shiftKey,altKey:t.altKey,ctrlKey:t.metaKey||t.ctrlKey,metaKey:t.metaKey,accelKey:un(t),pointerId:t.pointerId,button:t.button,isPen:t.pointerType==="pen"}}function mb(){const t=z();return w.useMemo(function(){let r,s;function o(m){if(!m.isKilled){if(m.button===gb){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...lr(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(dd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...lr(m)}))}}function i(m){m.isKilled||m.clientX===r&&m.clientY===s||(r=m.clientX,s=m.clientY,t.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...lr(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,s=m.clientY,hd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...lr(m)}))}function l(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!0:null})}function c(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!1:null})}function u(m){m.isKilled=!0,xe(m)}function h(m){m.isKilled=!0,m.target instanceof HTMLElement&&m.target.tagName!=="A"&&m.target.tagName!=="TEXTAREA"&&!(t.getEditingShape()&&m.target.className.includes("tl-text-content"))&&xe(m)}function f(m){xe(m)}async function p(m){var y,S;if(xe(m),Ct(m),!((S=(y=m.dataTransfer)==null?void 0:y.files)!=null&&S.length))return;const v=Array.from(m.dataTransfer.files);await t.putExternalContent({type:"files",files:v,point:t.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function g(m){Ct(m)}return{onPointerDown:o,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:f,onDrop:p,onTouchStart:u,onTouchEnd:h,onClick:g}},[t])}function EX(){const t=z();w.useEffect(()=>{let e=t.getInstanceState().isCoarsePointer;const n=i=>{const a=i.pointerType!=="mouse";e!==a&&(e=a,t.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",n,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),s=Ge.isFirefox&&!Ge.isAndroid&&!Ge.isIos,o=()=>{const i=s?!1:r.matches;e===i&&(e=i,t.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",o),o()),()=>{window.removeEventListener("pointerdown",n,{capture:!0}),r&&r.removeEventListener("change",o)}},[t])}const dj=w.createContext(null);function hj({container:t,children:e}){return d.jsx(dj.Provider,{value:t,children:e})}function Tt(){return zn(w.useContext(dj),"useContainer used outside of <Tldraw />")}function kX(){const t=z(),e=Tt(),n=U("isFocused",()=>t.getIsFocused(),[t]);w.useEffect(()=>{if(!e)return;function r(s){if(s.isSpecialRedispatchedEvent)return;xe(s),Ct(s);const o=e.querySelector(".tl-canvas");if(!o)return;const i=new DragEvent(s.type,s);i.isSpecialRedispatchedEvent=!0,o.dispatchEvent(i)}return e.addEventListener("dragover",r),e.addEventListener("drop",r),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",r)}},[e]),w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let r=null;const s=()=>{r!=null&&r();const o=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(o),a=l=>{l.type==="change"&&s()};i.addEventListener?i.addEventListener("change",s):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",s):i.removeListener&&i.removeListener(a)},t.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{r==null||r()}},[t]),w.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(t.isIn("zoom")||!t.getPath().endsWith(".idle"))&&!gh(t)&&xe(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){xe(a);return}break}case"Tab":{if(gh(t))return;break}case",":return;case"Escape":{if((t.getEditingShape()||t.getSelectedShapeIds().length>0)&&xe(a),t.menus.getOpenMenus().length>0)return;t.inputs.keys.has("Escape")||(t.inputs.keys.add("Escape"),t.cancel(),e.focus());return}default:if(gh(t))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,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)},s=a=>{if(a.isKilled||(a.isKilled=!0,gh(t))||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,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)};function o(a){var l,c;if(e.contains(a.target)){const u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+h>t.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),xe(a))}}const i=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&xe(a)};return e.addEventListener("touchstart",o,{passive:!1}),e.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",xe),document.addEventListener("gesturechange",xe),document.addEventListener("gestureend",xe),e.addEventListener("keydown",r),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",xe),document.removeEventListener("gesturechange",xe),document.removeEventListener("gestureend",xe),e.removeEventListener("keydown",r),e.removeEventListener("keyup",s)}},[t,e,n])}const TX=["input","select","button","textarea"];function gh(t){const{activeElement:e}=document;return t.menus.hasOpenMenus()||e&&(e.getAttribute("contenteditable")||TX.indexOf(e.tagName.toLowerCase())>-1)}const MX=["textarea","input"];function AX(t){const e=z();w.useEffect(()=>{const n=t.current;if(!n)return;const r=s=>{var o;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:i}=s;if(MX.includes((o=i.tagName)==null?void 0:o.toLocaleLowerCase())||e.isIn("select.editing_shape"))return;xe(s)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[e,t])}function jX(t,e,n){return Math.max(e,Math.min(t,n))}const Vt={toVector(t,e){return t===void 0&&(t=e),Array.isArray(t)?t:[t,t]},add(t,e){return[t[0]+e[0],t[1]+e[1]]},sub(t,e){return[t[0]-e[0],t[1]-e[1]]},addTo(t,e){t[0]+=e[0],t[1]+=e[1]},subTo(t,e){t[0]-=e[0],t[1]-=e[1]}};function lI(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function cI(t,e,n,r=.15){return r===0?jX(t,e,n):t<e?-lI(e-t,n-e,r)+e:t>n?+lI(t-n,n-e,r)+n:t}function OX(t,[e,n],[r,s]){const[[o,i],[a,l]]=t;return[cI(e,o,i,r),cI(n,a,l,s)]}function DX(t,e){if(typeof t!="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function RX(t){var e=DX(t,"string");return typeof e=="symbol"?e:String(e)}function on(t,e,n){return e=RX(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function uI(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),n.push.apply(n,r)}return n}function ht(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?uI(Object(n),!0).forEach(function(r){on(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const fj={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 dI(t){return t?t[0].toUpperCase()+t.slice(1):""}const LX=["enter","leave"];function $X(t=!1,e){return t&&!LX.includes(e)}function FX(t,e="",n=!1){const r=fj[t],s=r&&r[e]||e;return"on"+dI(t)+dI(s)+($X(n,s)?"Capture":"")}const NX=["gotpointercapture","lostpointercapture"];function zX(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=NX.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:n}}function BX(t,e=""){const n=fj[t],r=n&&n[e]||e;return t+r}function pj(t){return"touches"in t}function UX(t){return pj(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function HX(t){return Array.from(t.touches).filter(e=>{var n,r;return e.target===t.currentTarget||((n=t.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,e.target))})}function wx(t,e){try{const n=e.clientX-t.clientX,r=e.clientY-t.clientY,s=(e.clientX+t.clientX)/2,o=(e.clientY+t.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function KX(t){return HX(t).map(e=>e.identifier)}function hI(t,e){const[n,r]=Array.from(t.touches).filter(s=>e.includes(s.identifier));return wx(n,r)}const fI=40,pI=800;function gj(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=fI,n*=fI):r===2&&(e*=pI,n*=pI),[e,n]}function WX(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o}=t;Object.assign(e,{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o})}return e}function $p(t,...e){return typeof t=="function"?t(...e):t}function GX(){}function VX(...t){return t.length===0?GX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function gI(t,e){return Object.assign({},e,t||{})}const YX=32;class mj{constructor(e,n,r){this.ctrl=e,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(e){this.ctrl.state[this.key]=e}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:e,shared:n,ingKey:r,args:s}=this;n[r]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=e.target,n.currentTarget=e.currentTarget,n.lastOffset=r.from?$p(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=e.timeStamp)}computeValues(e){const n=this.state;n._values=e,n.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:n,config:r,shared:s}=this;n.args=this.args;let o=0;if(e&&(n.event=e,r.preventDefault&&e.cancelable&&n.event.preventDefault(),n.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,WX(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-n.timeStamp,n.timeStamp=e.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const _=n._delta.map(Math.abs);Vt.addTo(n._distance,_)}this.axisIntent&&this.axisIntent(e);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:h}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const f=[0,0];if(r.hasCustomTransform){const[_,E]=h;f[0]=u[0]!==!1?_-u[0]:0,f[1]=u[1]!==!1?E-u[1]:0}else f[0]=u[0]!==!1?i-u[0]:0,f[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(f);const p=n.offset,g=n._active&&!n._blocked||n.active;g&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=s[this.ingKey]=n._active,e&&(n.first&&("bounds"in r&&(n._bounds=$p(r.bounds,n)),this.setup&&this.setup()),n.movement=f,this.computeOffset()));const[m,v]=n.offset,[[y,S],[b,P]]=n._bounds;n.overflow=[m<y?-1:m>S?1:0,v<b?-1:v>P?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 C=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=OX(n._bounds,n.offset,C),n.delta=Vt.sub(n.offset,p),this.computeMovement(),g&&(!n.last||o>YX)){n.delta=Vt.sub(n.offset,p);const _=n.delta.map(Math.abs);Vt.addTo(n.distance,_),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&o>0&&(n.velocity=[_[0]/o,_[1]/o],n.timeDelta=o)}}emit(){const e=this.state,n=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const s=this.handler(ht(ht(ht({},n),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function XX([t,e],n){const r=Math.abs(t),s=Math.abs(e);if(r>s&&r>n)return"x";if(s>r&&s>n)return"y"}class qX extends mj{constructor(...e){super(...e),on(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=Vt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Vt.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const n=this.state,r=this.config;if(!n.axis&&e){const s=typeof r.axisThreshold=="object"?r.axisThreshold[UX(e)]:r.axisThreshold;n.axis=XX(n._movement,s)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const ZX=t=>t,mI=.15,yj={enabled(t=!0){return t},eventOptions(t,e,n){return ht(ht({},n.shared.eventOptions),t)},preventDefault(t=!1){return t},triggerAllEvents(t=!1){return t},rubberband(t=0){switch(t){case!0:return[mI,mI];case!1:return[0,0];default:return Vt.toVector(t)}},from(t){if(typeof t=="function")return t;if(t!=null)return Vt.toVector(t)},transform(t,e,n){const r=t||n.shared.transform;return this.hasCustomTransform=!!r,r||ZX},threshold(t){return Vt.toVector(t,0)}},QX=0,fd=ht(ht({},yj),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=QX){return t},bounds(t={}){if(typeof t=="function")return o=>fd.bounds(t(o));if("current"in t)return()=>t.current;if(typeof HTMLElement=="function"&&t instanceof HTMLElement)return t;const{left:e=-1/0,right:n=1/0,top:r=-1/0,bottom:s=1/0}=t;return[[e,n],[r,s]]}}),pd=typeof window<"u"&&window.document&&window.document.createElement;function Sj(){return pd&&"ontouchstart"in window}function JX(){return Sj()||pd&&window.navigator.maxTouchPoints>1}function eq(){return pd&&"onpointerdown"in window}function tq(){return pd&&"exitPointerLock"in window.document}function nq(){try{return"constructor"in GestureEvent}catch{return!1}}const Mr={isBrowser:pd,gesture:nq(),touch:Sj(),touchscreen:JX(),pointer:eq(),pointerLock:tq()},rq=250,sq=180,oq=.5,iq=50,aq=250,lq=10,yI={mouse:0,touch:0,pen:8};ht(ht({},fd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&Mr.pointerLock,Mr.touch&&n?"touch":this.pointerLock?"mouse":Mr.pointer&&!s?"pointer":Mr.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?rq:void 0,!(!Mr.touchscreen||n===!1))return t||(n!==void 0?"y":void 0)},pointerCapture(t,e,{pointer:{capture:n=!0,buttons:r=1,keys:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&n},threshold(t,e,{filterTaps:n=!1,tapsThreshold:r=3,axis:s=void 0}){const o=Vt.toVector(t,n?r:s?1:0);return this.filterTaps=n,this.tapsThreshold=r,o},swipe({velocity:t=oq,distance:e=iq,duration:n=aq}={}){return{velocity:this.transform(Vt.toVector(t)),distance:this.transform(Vt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return sq;case!1:return 0;default:return t}},axisThreshold(t){return t?ht(ht({},yI),t):yI},keyboardDisplacement(t=lq){return t}});function vj(t){const[e,n]=t.overflow,[r,s]=t._delta,[o,i]=t._direction;(e<0&&r>0&&o<0||e>0&&r<0&&o>0)&&(t._movement[0]=t._movementBound[0]),(n<0&&s>0&&i<0||n>0&&s<0&&i>0)&&(t._movement[1]=t._movementBound[1])}const cq=30,uq=100;class dq extends mj{constructor(...e){super(...e),on(this,"ingKey","pinching"),on(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:n,lastOffset:r}=this.state;e==="wheel"?this.state.offset=Vt.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:n}=this.state;this.state.movement=[e[0]/n[0],e[1]-n[1]]}axisIntent(){const e=this.state,[n,r]=e._movement;if(!e.axis){const s=Math.abs(n)*cq-Math.abs(r);s<0?e.axis="angle":s>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(o=>r.has(o))||r.size<2)return;this.start(e),n._touchIds=Array.from(r).slice(0,2);const s=hI(e,n._touchIds);s&&this.pinchStart(e,s)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const n=this.state,r=n._pointerEvents,s=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(e.pointerId,e),n._pointerEvents.size<2))return;this.start(e);const o=wx(...Array.from(r.values()));o&&this.pinchStart(e,o)}pinchStart(e,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const n=hI(e,this.state._touchIds);n&&this.pinchMove(e,n)}pointerMove(e){const n=this.state._pointerEvents;if(n.has(e.pointerId)&&n.set(e.pointerId,e),!this.state._active)return;const r=wx(...Array.from(n.values()));r&&this.pinchMove(e,r)}pinchMove(e,n){const r=this.state,s=r._values[1],o=n.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),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(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const n=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}n._pointerEvents.has(e.pointerId)&&n._pointerEvents.delete(e.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const n=this.state;n._active||(this.start(e),this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY];const r=n._movement;n._movement=[e.scale-1,e.rotation],n._delta=Vt.sub(n._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>e[r]):!e[n])||(this.state._active?this.wheelChange(e):this.wheelStart(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(e){this.start(e),this.wheelChange(e)}wheelChange(e){"uv"in e||e.cancelable&&e.preventDefault();const r=this.state;r._delta=[-gj(e)[1]/uq*r.offset[0],0],Vt.addTo(r._movement,r._delta),vj(r),this.state.origin=[e.clientX,e.clientY],this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){const n=this.config.device;n&&(e(n,"start",this[n+"Start"].bind(this)),e(n,"change",this[n+"Move"].bind(this)),e(n,"end",this[n+"End"].bind(this)),e(n,"cancel",this[n+"End"].bind(this)),e("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const hq=ht(ht({},yj),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!Mr.touch&&Mr.gesture)return"gesture";if(Mr.touch&&r)return"touch";if(Mr.touchscreen){if(Mr.pointer)return"pointer";if(Mr.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const s=i=>{const a=gI($p(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=gI($p(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(i)]},threshold(t,e,n){return this.lockDirection=n.axis==="lock",Vt.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey(t){return t===void 0?"ctrlKey":t},pinchOnWheel(t=!0){return t}});ht(ht({},fd),{},{mouseOnly:(t=!0)=>t});class fq extends qX{constructor(...e){super(...e),on(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const n=this.state;n._delta=gj(e),Vt.addTo(n._movement,n._delta),vj(n),this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("wheel","",this.wheel.bind(this))}}const pq=fd;ht(ht({},fd),{},{mouseOnly:(t=!0)=>t});const yb=new Map,bx=new Map;function gq(t){yb.set(t.key,t.engine),bx.set(t.key,t.resolver)}const mq={key:"pinch",engine:dq,resolver:hq},yq={key:"wheel",engine:fq,resolver:pq};function Sq(t,e){if(t==null)return{};var n={},r=Object.keys(t),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(n[s]=t[s]);return n}function vq(t,e){if(t==null)return{};var n=Sq(t,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}const xq={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=Mr.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},wq=["target","eventOptions","window","enabled","transform"];function uf(t={},e){const n={};for(const[r,s]of Object.entries(e))switch(typeof s){case"function":n[r]=s.call(n,t[r],r,t);break;case"object":n[r]=uf(t[r],s);break;case"boolean":s&&(n[r]=t[r]);break}return n}function bq(t,e,n={}){const r=t,{target:s,eventOptions:o,window:i,enabled:a,transform:l}=r,c=vq(r,wq);if(n.shared=uf({target:s,eventOptions:o,window:i,enabled:a,transform:l},xq),e){const u=bx.get(e);n[e]=uf(ht({shared:n.shared},c),u)}else for(const u in c){const h=bx.get(u);h&&(n[u]=uf(ht({shared:n.shared},c[u]),h))}return n}class xj{constructor(e,n){on(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=n}add(e,n,r,s,o){const i=this._listeners,a=BX(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ht(ht({},l),o);e.addEventListener(a,s,c);const u=()=>{e.removeEventListener(a,s,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Pq{constructor(){on(this,"_timeouts",new Map)}add(e,n,r=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(n,r,...s))}remove(e){const n=this._timeouts.get(e);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class Cq{constructor(e){on(this,"gestures",new Set),on(this,"_targetEventStore",new xj(this)),on(this,"gestureEventStores",{}),on(this,"gestureTimeoutStores",{}),on(this,"handlers",{}),on(this,"config",{}),on(this,"pointerIds",new Set),on(this,"touchIds",new Set),on(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),_q(this,e)}setEventIds(e){if(pj(e))return this.touchIds=new Set(KX(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,n){this.handlers=e,this.nativeHandlers=n}applyConfig(e,n){this.config=bq(e,n,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const n=this.config.shared,r={};let s;if(!(n.target&&(s=n.target(),!s))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=SI(r,a.eventOptions,!!s);if(a.enabled){const c=yb.get(i);new c(this,e,i).bind(l)}}const o=SI(r,n.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](ht(ht({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const o in r)r[o]=VX(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:l}=zX(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:l})}}}}function Da(t,e){t.gestures.add(e),t.gestureEventStores[e]=new xj(t,e),t.gestureTimeoutStores[e]=new Pq}function _q(t,e){e.drag&&Da(t,"drag"),e.wheel&&Da(t,"wheel"),e.scroll&&Da(t,"scroll"),e.move&&Da(t,"move"),e.pinch&&Da(t,"pinch"),e.hover&&Da(t,"hover")}const SI=(t,e,n)=>(r,s,o,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:e.capture,h=(c=i.passive)!==null&&c!==void 0?c:e.passive;let f=a?r:FX(r,s,u);n&&h&&(f+="Passive"),t[f]=t[f]||[],t[f].push(o)},Iq=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Eq(t){const e={},n={},r=new Set;for(let s in t)Iq.test(s)?(r.add(RegExp.lastMatch),n[s]=t[s]):e[s]=t[s];return[n,e,r]}function Ra(t,e,n,r,s,o){if(!t.has(n)||!yb.has(r))return;const i=n+"Start",a=n+"End",l=c=>{let u;return c.first&&i in e&&e[i](c),n in e&&(u=e[n](c)),c.last&&a in e&&e[a](c),u};s[r]=l,o[r]=o[r]||{}}function kq(t,e){const[n,r,s]=Eq(t),o={};return Ra(s,n,"onDrag","drag",o,e),Ra(s,n,"onWheel","wheel",o,e),Ra(s,n,"onScroll","scroll",o,e),Ra(s,n,"onPinch","pinch",o,e),Ra(s,n,"onMove","move",o,e),Ra(s,n,"onHover","hover",o,e),{handlers:o,config:e,nativeHandlers:r}}function Tq(t,e={},n,r){const s=ke.useMemo(()=>new Cq(t),[]);if(s.applyHandlers(t,r),s.applyConfig(e,n),ke.useEffect(s.effect.bind(s)),ke.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Mq(t){return t.forEach(gq),function(n,r){const{handlers:s,nativeHandlers:o,config:i}=kq(n,r||{});return Tq(s,i,void 0,o)}}const vI=10,Aq=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function wj(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>vI?vI*Math.sign(e):e)/100:t.shiftKey&&!Aq&&(n=e,e=0),{x:-n,y:-e,z:-r}}const jq=Mq([yq,mq]);let La;const Oq=t=>La===void 0?(La=t,!1):t-La>120&&t-La<160?(La=t,!0):(La=t,!1);function Dq(t){const e=z(),n=w.useMemo(()=>{let r="not sure";const s=({event:m})=>{if(!e.getInstanceState().isFocused||(r="not sure",Oq(Date.now())))return;const v=e.getEditingShapeId();if(v){const b=e.getShape(v);if(b&&e.getShapeUtil(b).canScroll(b)){const C=e.getShapePageBounds(v);if(C!=null&&C.containsPoint(e.inputs.currentPagePoint))return}}xe(m),Ct(m);const y=wj(m);if(y.x===0&&y.y===0)return;const S={type:"wheel",name:"wheel",delta:y,point:new x(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey,metaKey:m.metaKey,accelKey:un(m)};e.dispatch(S)};let o=1,i=1,a=1,l=0;const c=new x,u=new x,h=m=>{const v=t.current;r="not sure";const{event:y,origin:S,da:b}=m;y instanceof WheelEvent||(y.target===v||v!=null&&v.contains(y.target))&&(u.x=S[0],u.y=S[1],c.x=S[0],c.y=S[1],o=b[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:S[0],y:S[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)}))},f=m=>{if(m&&(r="zooming"),r==="zooming")return;const v=Math.abs(l-o),y=x.Dist(c,u);switch(r){case"not sure":{v>24?r="zooming":y>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:h,onPinchEnd:m=>{const v=t.current,{event:y,origin:S,offset:b}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const P=b[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:S[0],y:S[1],z:P},delta:{x:S[0],y:S[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)})})},onPinch:m=>{const v=t.current,{event:y,origin:S,offset:b,da:P}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";l=P[0];const _=S[0]-u.x,E=S[1]-u.y;switch(u.x=S[0],u.y=S[1],f(C),r){case"zooming":{a=b[0],e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:a},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:i},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}}}}},[e,t]);jq(n,{target:t,eventOptions:{passive:!1},pinch:{from:()=>[e.getZoomLevel(),0],scaleBounds:()=>{const r=e.getBaseZoom(),s=e.getCameraOptions().zoomSteps,o=s[0]*r,i=s[s.length-1]*r;return{from:e.getZoomLevel(),max:i,min:o}}}})}function Yy(t,e,n){const r=t.getShape(e),s=t.getShapeHandles(r);return{shape:r,handle:s.find(o=>o.id===n)}}function Rq(t,e){const n=z();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Lp(l.currentTarget);dd(c,l);const{shape:u,handle:h}=Yy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...lr(l)})};let s,o;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===s&&l.clientY===o)return;s=l.clientX,o=l.clientY;const{shape:c,handle:u}=Yy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...lr(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Lp(l.currentTarget);hd(c,l);const{shape:u,handle:h}=Yy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...lr(l)})}}},[n,t,e])}function Lq(t){const e=z();w.useLayoutEffect(()=>{const n=TT(()=>{t.current&&e.updateViewportScreenBounds(t.current)},200,{trailing:!0}),r=e.timers.setInterval(n,1e3);window.addEventListener("resize",n);const s=new ResizeObserver(a=>{a[0].contentRect&&n()}),o=t.current;let i=null;return o&&(s.observe(o),i=$q(o),i.addEventListener("scroll",n)),()=>{clearInterval(r),window.removeEventListener("resize",n),s.disconnect(),i==null||i.removeEventListener("scroll",n),n.cancel()}},[e,t])}/*!
|
|
88
|
+
*/(function(t){(function(){var e={}.hasOwnProperty;function n(){for(var o="",i=0;i<arguments.length;i++){var a=arguments[i];a&&(o=s(o,r(a)))}return o}function r(o){if(typeof o=="string"||typeof o=="number")return o;if(typeof o!="object")return"";if(Array.isArray(o))return n.apply(null,o);if(o.toString!==Object.prototype.toString&&!o.toString.toString().includes("[native code]"))return o.toString();var i="";for(var a in o)e.call(o,a)&&o[a]&&(i=s(i,a));return i}function s(o,i){return i?o?o+" "+i:o+i:o}t.exports?(n.default=n,t.exports=n):window.classNames=n})()})(sj);var dX=sj.exports;const ce=wi(dX),oj="3.7.2",tI={major:"2024-09-13T14:36:29.063Z",minor:"2025-01-07T15:59:09.453Z",patch:"2025-01-16T12:44:39.524Z"},hX={error:null};class ub extends w.Component{constructor(){super(...arguments);I(this,"state",hX)}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n){var r,s;(s=(r=this.props).onError)==null||s.call(r,n)}render(){const{error:n}=this.state;if(n!==null){const{fallback:r}=this.props;return d.jsx(r,{error:n})}return this.props.children}}function Uu({children:t,fallback:e,...n}){return e===null?t:d.jsx(ub,{fallback:e,...n,children:t})}function db(t,e){return Rg(`${t}_${e}`)}function Jl(t){return Rg(`${w.useId()}${t??""}`)}function rs(t){const e=zn(w.useContext(ij));return Rg(`${e}_${t}`)}function Rg(t){return t.replace(/:/g,"_")}const ij=w.createContext(null);function fX({children:t}){const e=Jl();return d.jsx(ij.Provider,{value:e,children:t})}const hb=w.createContext(null);function z(){const t=ke.useContext(hb);if(!t)throw new Error("useEditor must be used inside of the <Tldraw /> or <TldrawEditor /> components");return t}function Ti(){return ke.useContext(hb)}function fb({editor:t,children:e}){return d.jsx(hb.Provider,{value:t,children:d.jsx(fX,{children:e})})}function pX(){return d.jsx("div",{className:"tl-background"})}function ec(t,e,n,r,s,o){w.useLayoutEffect(()=>{const i=t.current;if(!i||e===void 0)return;let a=`translate(${e}px, ${n}px)`;r!==void 0&&(a+=` scale(${r})`),s!==void 0&&(a+=` rotate(${s}rad)`),o&&(a+=` translate(${o.x}px, ${o.y}px)`),i.style.transform=a})}const Dt={linear:t=>t,easeInQuad:t=>t*t,easeOutQuad:t=>t*(2-t),easeInOutQuad:t=>t<.5?2*t*t:-1+(4-2*t)*t,easeInCubic:t=>t*t*t,easeOutCubic:t=>--t*t*t+1,easeInOutCubic:t=>t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1,easeInQuart:t=>t*t*t*t,easeOutQuart:t=>1- --t*t*t*t,easeInOutQuart:t=>t<.5?8*t*t*t*t:1-8*--t*t*t*t,easeInQuint:t=>t*t*t*t*t,easeOutQuint:t=>1+--t*t*t*t*t,easeInOutQuint:t=>t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t,easeInSine:t=>1-Math.cos(t*Math.PI/2),easeOutSine:t=>Math.sin(t*Math.PI/2),easeInOutSine:t=>-(Math.cos(Math.PI*t)-1)/2,easeInExpo:t=>t<=0?0:Math.pow(2,10*t-10),easeOutExpo:t=>t>=1?1:1-Math.pow(2,-10*t),easeInOutExpo:t=>t<=0?0:t>=1?1:t<.5?Math.pow(2,20*t-10)/2:(2-Math.pow(2,-20*t+10))/2};class x{constructor(e=0,n=0,r=1){this.x=e,this.y=n,this.z=r}get pressure(){return this.z}set(e=this.x,n=this.y,r=this.z){return this.x=e,this.y=n,this.z=r,this}setTo({x:e=0,y:n=0,z:r=1}){return this.x=e,this.y=n,this.z=r,this}rot(e){if(e===0)return this;const{x:n,y:r}=this,s=Math.sin(e),o=Math.cos(e);return this.x=n*o-r*s,this.y=n*s+r*o,this}rotWith(e,n){if(n===0)return this;const r=this.x-e.x,s=this.y-e.y,o=Math.sin(n),i=Math.cos(n);return this.x=e.x+(r*i-s*o),this.y=e.y+(r*o+s*i),this}clone(){const{x:e,y:n,z:r}=this;return new x(e,n,r)}sub(e){return this.x-=e.x,this.y-=e.y,this}subXY(e,n){return this.x-=e,this.y-=n,this}subScalar(e){return this.x-=e,this.y-=e,this}add(e){return this.x+=e.x,this.y+=e.y,this}addXY(e,n){return this.x+=e,this.y+=n,this}addScalar(e){return this.x+=e,this.y+=e,this}clamp(e,n){return this.x=Math.max(this.x,e),this.y=Math.max(this.y,e),n!==void 0&&(this.x=Math.min(this.x,n),this.y=Math.min(this.y,n)),this}div(e){return this.x/=e,this.y/=e,this}divV(e){return this.x/=e.x,this.y/=e.y,this}mul(e){return this.x*=e,this.y*=e,this}mulV(e){return this.x*=e.x,this.y*=e.y,this}abs(){return this.x=Math.abs(this.x),this.y=Math.abs(this.y),this}nudge(e,n){const r=x.Tan(e,this);return this.add(r.mul(n))}neg(){return this.x*=-1,this.y*=-1,this}cross(e){return this.x=this.y*e.z-this.z*e.y,this.y=this.z*e.x-this.x*e.z,this}dpr(e){return x.Dpr(this,e)}cpr(e){return x.Cpr(this,e)}len2(){return x.Len2(this)}len(){return x.Len(this)}pry(e){return x.Pry(this,e)}per(){const{x:e,y:n}=this;return this.x=n,this.y=-e,this}uni(){return x.Uni(this)}tan(e){return x.Tan(this,e)}dist(e){return x.Dist(this,e)}distanceToLineSegment(e,n){return x.DistanceToLineSegment(e,n,this)}slope(e){return x.Slope(this,e)}snapToGrid(e){return this.x=Math.round(this.x/e)*e,this.y=Math.round(this.y/e)*e,this}angle(e){return x.Angle(this,e)}toAngle(){return x.ToAngle(this)}lrp(e,n){return this.x=this.x+(e.x-this.x)*n,this.y=this.y+(e.y-this.y)*n,this}equals(e){return x.Equals(this,e)}equalsXY(e,n){return x.EqualsXY(this,e,n)}norm(){const e=this.len();return this.x=e===0?0:this.x/e,this.y=e===0?0:this.y/e,this}toFixed(){return x.ToFixed(this)}toString(){return x.ToString(x.ToFixed(this))}toJson(){return x.ToJson(this)}toArray(){return x.ToArray(this)}static Add(e,n){return new x(e.x+n.x,e.y+n.y)}static AddXY(e,n,r){return new x(e.x+n,e.y+r)}static Sub(e,n){return new x(e.x-n.x,e.y-n.y)}static SubXY(e,n,r){return new x(e.x-n,e.y-r)}static AddScalar(e,n){return new x(e.x+n,e.y+n)}static SubScalar(e,n){return new x(e.x-n,e.y-n)}static Div(e,n){return new x(e.x/n,e.y/n)}static Mul(e,n){return new x(e.x*n,e.y*n)}static DivV(e,n){return new x(e.x/n.x,e.y/n.y)}static MulV(e,n){return new x(e.x*n.x,e.y*n.y)}static Neg(e){return new x(-e.x,-e.y)}static Per(e){return new x(e.y,-e.x)}static Abs(e){return new x(Math.abs(e.x),Math.abs(e.y))}static Dist(e,n){return((e.y-n.y)**2+(e.x-n.x)**2)**.5}static DistMin(e,n,r){return(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y)<r**2}static Dist2(e,n){return(e.x-n.x)*(e.x-n.x)+(e.y-n.y)*(e.y-n.y)}static Dpr(e,n){return e.x*n.x+e.y*n.y}static Cross(e,n){return new x(e.y*n.z-e.z*n.y,e.z*n.x-e.x*n.z)}static Cpr(e,n){return e.x*n.y-n.x*e.y}static Len2(e){return e.x*e.x+e.y*e.y}static Len(e){return(e.x*e.x+e.y*e.y)**.5}static Pry(e,n){return x.Dpr(e,n)/x.Len(n)}static Uni(e){return x.Div(e,x.Len(e))}static Tan(e,n){return x.Uni(x.Sub(e,n))}static Min(e,n){return new x(Math.min(e.x,n.x),Math.min(e.y,n.y))}static Max(e,n){return new x(Math.max(e.x,n.x),Math.max(e.y,n.y))}static From({x:e,y:n,z:r=1}){return new x(e,n,r)}static FromArray(e){return new x(e[0],e[1])}static Rot(e,n=0){const r=Math.sin(n),s=Math.cos(n);return new x(e.x*s-e.y*r,e.x*r+e.y*s)}static RotWith(e,n,r){const s=e.x-n.x,o=e.y-n.y,i=Math.sin(r),a=Math.cos(r);return new x(n.x+(s*a-o*i),n.y+(s*i+o*a))}static NearestPointOnLineThroughPoint(e,n,r){return x.Mul(n,x.Sub(r,e).pry(n)).add(e)}static NearestPointOnLineSegment(e,n,r,s=!0){if(x.Equals(e,r)||x.Equals(n,r))return x.From(r);const o=x.Tan(n,e),i=x.Add(e,x.Mul(o,x.Sub(r,e).pry(o)));if(s){if(i.x<Math.min(e.x,n.x))return x.Cast(e.x<n.x?e:n);if(i.x>Math.max(e.x,n.x))return x.Cast(e.x>n.x?e:n);if(i.y<Math.min(e.y,n.y))return x.Cast(e.y<n.y?e:n);if(i.y>Math.max(e.y,n.y))return x.Cast(e.y>n.y?e:n)}return i}static DistanceToLineThroughPoint(e,n,r){return x.Dist(r,x.NearestPointOnLineThroughPoint(e,n,r))}static DistanceToLineSegment(e,n,r,s=!0){return x.Dist(r,x.NearestPointOnLineSegment(e,n,r,s))}static Snap(e,n=1){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}static Cast(e){return e instanceof x?e:x.From(e)}static Slope(e,n){return e.x===n.y?NaN:(e.y-n.y)/(e.x-n.x)}static IsNaN(e){return isNaN(e.x)||isNaN(e.y)}static Angle(e,n){return Math.atan2(n.y-e.y,n.x-e.x)}static Lrp(e,n,r){return x.Sub(n,e).mul(r).add(e)}static Med(e,n){return new x((e.x+n.x)/2,(e.y+n.y)/2)}static Equals(e,n){return Math.abs(e.x-n.x)<1e-4&&Math.abs(e.y-n.y)<1e-4}static EqualsXY(e,n,r){return e.x===n&&e.y===r}static Clockwise(e,n,r){return(r.x-e.x)*(n.y-e.y)-(n.x-e.x)*(r.y-e.y)<0}static Rescale(e,n){const r=x.Len(e);return new x(n*e.x/r,n*e.y/r)}static ScaleWithOrigin(e,n,r){return x.Sub(e,r).mul(n).add(r)}static ToFixed(e){return new x(io(e.x),io(e.y))}static ToInt(e){return new x(parseInt(e.x.toFixed(0)),parseInt(e.y.toFixed(0)),parseInt((e.z??0).toFixed(0)))}static ToCss(e){return`${e.x},${e.y}`}static Nudge(e,n,r){return x.Add(e,x.Tan(n,e).mul(r))}static ToString(e){return`${e.x}, ${e.y}`}static ToAngle(e){let n=Math.atan2(e.y,e.x);return n<0&&(n+=Math.PI*2),n}static FromAngle(e,n=1){return new x(Math.cos(e)*n,Math.sin(e)*n)}static ToArray(e){return[e.x,e.y,e.z]}static ToJson(e){const{x:n,y:r,z:s}=e;return{x:n,y:r,z:s}}static Average(e){const n=e.length,r=new x(0,0);if(n===0)return r;for(let s=0;s<n;s++)r.add(e[s]);return r.div(n)}static Clamp(e,n,r){return r===void 0?new x(Math.min(Math.max(e.x,n)),Math.min(Math.max(e.y,n))):new x(Math.min(Math.max(e.x,n),r),Math.min(Math.max(e.y,n),r))}static PointsBetween(e,n,r=6){const s=[];for(let o=0;o<r;o++){const i=Dt.easeInQuad(o/(r-1)),a=x.Lrp(e,n,i);a.z=Math.min(1,.5+Math.abs(.5-gX(i))*.65),s.push(a)}return s}static SnapToGrid(e,n=8){return new x(Math.round(e.x/n)*n,Math.round(e.y/n)*n)}}const gX=t=>t<.5?2*t*t:-1+(4-2*t)*t;function je(t){return`${N(t.x)},${N(t.y)} `}function Bn(t,e){return`${N((t.x+e.x)/2)},${N((t.y+e.y)/2)} `}const De=Math.PI,Ze=De/2,Fe=De*2,mX=Math.sin;function Bt(t,e,n){return Math.max(e,typeof n<"u"?Math.min(t,n):t)}function fh(t,e=1e10){return t?Math.round(t*e)/e:0}function di(t,e,n=1e-6){return Math.abs(t-e)<=n}function aj(t,e){const n=Math.pow(t-e,2)/Math.pow(t+e,2);return De*(t+e)*(1+3*n/(10+Math.sqrt(4-3*n)))}function ea(t){return t=t%Fe,t<0?t=t+Fe:t===0&&(t=0),t}function ud(t,e){return t=ea(t),e=ea(e),t>e&&(e+=Fe),e-t}function lj(t,e){return Fe-ud(t,e)}function cf(t,e){const n=(e-t)%Fe;return 2*n%Fe-n}function vx(t){return(Fe+t)%Fe}function Rp(t,e){const n=Fe/e;let r=Math.floor((vx(t)+n/2)/n)*n%Fe;return r<De&&(r+=Fe),r>De&&(r-=Fe),r}function cj(t,e){return t===e||di(t%(Math.PI/2)-e%(Math.PI/2),0)}function yX(t){return t*De/180}function SX(t){return t*180/De}function ha(t,e,n){return new x(t.x,t.y).add(x.FromAngle(n,e))}function Hy(t,e,n){const r=t/2,s=e/2,o=[];let i=1/0,a=-1/0,l=1/0,c=-1/0;for(let g=0;g<n;g++){const m=Fe/n,v=-Ze+g*m,y=r+r*Math.cos(v),S=s+s*Math.sin(v);y<i&&(i=y),S<l&&(l=S),y>a&&(a=y),S>c&&(c=S),o.push(new x(y,S))}const u=a-i,h=c-l,f=t-u,p=e-h;if(f!==0||p!==0)for(let g=0;g<o.length;g++){const m=o[g];m.x=(m.x-i)/u*t,m.y=(m.y-l)/h*e}return o}function Tc(t,e,n,r){return t<r&&n<e}function Gr(t,e,n,r){const s=Math.max(t,n),o=Math.min(e,r);return s<=o?[s,o]:null}function nI(t,e,n){return(e.x-t.x)*(n.y-t.y)-(n.x-t.x)*(e.y-t.y)}function hr(t,e){let n=0,r,s;for(let o=0;o<e.length;o++){if(r=e[o],r.x===t.x&&r.y===t.y||(s=e[(o+1)%e.length],x.Dist(t,r)+x.Dist(t,s)===x.Dist(r,s)))return!0;r.y<=t.y?s.y>t.y&&nI(r,s,t)>0&&(n+=1):s.y<=t.y&&nI(r,s,t)<0&&(n-=1)}return n!==0}function N(t){return Math.round(t*1e4)/1e4}function io(t){return Math.round(t*100)/100}const rI=t=>Math.abs(t)<Number.MAX_SAFE_INTEGER;function Xo(t,e,n){return n<0?ud(t,e):lj(t,e)}function xx(t,e,n,r){let s;if(Math.abs(t)>De){s=cf(e,r);const o=cf(r,n);return Math.abs(s)<Math.abs(o)?s/t:(t-o)/t}else{s=cf(e,r);const o=s/t;return Math.sign(s)!==Math.sign(t)?Math.abs(o)>.5?1:0:o}}function vX(t,e,n,r){const s=2*((e-t)%Fe)%Fe-(e-t)%Fe;return r?(Fe-Math.abs(s))*(n?1:-1):s}function pb(t,e,n){const r=-2*(t.x*(e.y-n.y)-t.y*(e.x-n.x)+e.x*n.y-n.x*e.y),s=((t.x*t.x+t.y*t.y)*(n.y-e.y)+(e.x*e.x+e.y*e.y)*(t.y-n.y)+(n.x*n.x+n.y*n.y)*(e.y-t.y))/r,o=((t.x*t.x+t.y*t.y)*(e.x-n.x)+(e.x*e.x+e.y*e.y)*(n.x-t.x)+(n.x*n.x+n.y*n.y)*(t.x-e.x))/r;return!Number.isFinite(s)||!Number.isFinite(o)?null:new x(s,o)}function xX(t,e,n,r,s){if(n===null)return[x.From(t),x.From(e)];const o=[],i=x.Angle(n,t),a=x.Angle(n,e),l=ud(i,a);for(let c=0;c<s;c++){const u=c/(s-1),h=i+l*u,f=ha(n,r,h);o.push(f)}return o}const Ky=({brush:t,color:e,opacity:n,className:r})=>{const s=w.useRef(null);ec(s,t.x,t.y);const o=N(Math.max(1,t.w)),i=N(Math.max(1,t.h));return d.jsx("svg",{className:"tl-overlays__item",ref:s,children:e?d.jsxs("g",{className:"tl-brush",opacity:n,children:[d.jsx("rect",{width:o,height:i,fill:e,opacity:.75}),d.jsx("rect",{width:o,height:i,fill:"none",stroke:e,opacity:.1})]}):d.jsx("rect",{className:`tl-brush tl-brush__default ${r}`,width:o,height:i})})},Ge={isSafari:!1,isIos:!1,isChromeForIos:!1,isFirefox:!1,isAndroid:!1,isWebview:!1,isDarwin:!1};typeof window<"u"&&"navigator"in window&&(Ge.isSafari=/^((?!chrome|android).)*safari/i.test(navigator.userAgent),Ge.isIos=!!navigator.userAgent.match(/iPad/i)||!!navigator.userAgent.match(/iPhone/i),Ge.isChromeForIos=/crios.*safari/i.test(navigator.userAgent),Ge.isFirefox=/firefox/i.test(navigator.userAgent),Ge.isAndroid=/android/i.test(navigator.userAgent),Ge.isDarwin=window.navigator.userAgent.toLowerCase().indexOf("mac")>-1);const sI={isLocked:!1,wheelBehavior:"pan",panSpeed:1,zoomSpeed:1,zoomSteps:[.1,.25,.5,1,2,4,8]},Wy={duration:0,easing:Dt.easeInOutCubic},oI={CAMERA_MOVE:-10},wX=["top","right","bottom","left"],iI=0,gb=2,ph=1,aI=5,bX=128;var Gy={};const PX={},uj=Dn("pointerCaptureTrackingObject",{defaults:{all:new Map},shouldStoreForSession:!1}),wt={logPreventDefaults:Dn("logPreventDefaults",{defaults:{all:!1}}),logPointerCaptures:Dn("logPointerCaptures",{defaults:{all:!1}}),logElementRemoves:Dn("logElementRemoves",{defaults:{all:!1}}),debugSvg:Dn("debugSvg",{defaults:{all:!1}}),showFps:Dn("showFps",{defaults:{all:!1}}),measurePerformance:Dn("measurePerformance",{defaults:{all:!1}}),throwToBlob:Dn("throwToBlob",{defaults:{all:!1}}),reconnectOnPing:Dn("reconnectOnPing",{defaults:{all:!1}}),debugCursors:Dn("debugCursors",{defaults:{all:!1}}),forceSrgb:Dn("forceSrgbColors",{defaults:{all:!1}}),debugGeometry:Dn("debugGeometry",{defaults:{all:!1}}),hideShapes:Dn("hideShapes",{defaults:{all:!1}}),editOnType:Dn("editOnType",{defaults:{all:!1}})};if(typeof Element<"u"){const t=Element.prototype.removeChild;As("element removal logging",()=>{wt.logElementRemoves.get()?Element.prototype.removeChild=function(e){return console.warn("[tldraw] removing child:",e),t.call(this,e)}:Element.prototype.removeChild=t})}function Dn(t,{defaults:e,shouldStoreForSession:n=!0}){return CX({name:t,defaults:e,shouldStoreForSession:n})}function CX(t){const e=IX(t),n=t.shouldStoreForSession?_X(t.name):null,r=It(`debug:${t.name}`,n??e);return typeof window<"u"&&(t.shouldStoreForSession&&As(`debug:${t.name}`,()=>{const s=r.get();s===e?eM(`tldraw_debug:${t.name}`):E0(`tldraw_debug:${t.name}`,JSON.stringify(s))}),Object.defineProperty(window,`tldraw${t.name.replace(/^[a-z]/,s=>s.toUpperCase())}`,{get(){return r.get()},set(s){r.set(s)},configurable:!0})),Object.assign(r,t)}function _X(t){try{return JSON.parse(JT(`tldraw_debug:${t}`)??"null")}catch{return null}}function Vy(t){try{return t()}catch{return null}}function IX(t){switch(Vy(()=>Gy.TLDRAW_ENV)??Vy(()=>Gy.VERCEL_PUBLIC_TLDRAW_ENV)??Vy(()=>Gy.NEXT_PUBLIC_TLDRAW_ENV)??"production"){case"production":return t.defaults.production??t.defaults.all;case"preview":case"staging":return t.defaults.staging??t.defaults.all;default:return t.defaults.development??t.defaults.all}}function Lp(t){if(t instanceof HTMLElement)return t;if(t.parentElement)return Lp(t.parentElement);throw Error("Could not find a parent element of an HTML type!")}function xe(t){t.preventDefault(),wt.logPreventDefaults.get()&&console.warn("preventDefault called on event:",t)}function dd(t,e){if(t.setPointerCapture(e.pointerId),wt.logPointerCaptures.get()){const n=uj.get();n.set(t,(n.get(t)??0)+1),console.warn("setPointerCapture called on element:",t,e)}}function hd(t,e){if(t.hasPointerCapture(e.pointerId)&&(t.releasePointerCapture(e.pointerId),wt.logPointerCaptures.get())){const n=uj.get();n.get(t)===1?n.delete(t):n.has(t)?n.set(t,n.get(t)-1):console.warn("Release without capture"),console.warn("releasePointerCapture called on element:",t,e)}}const Ct=t=>t.stopPropagation(),rn=(t,e,n)=>{t&&t.style.setProperty(e,n)},un=t=>Ge.isDarwin?t.metaKey:t.ctrlKey||t.metaKey;function lr(t){return t.isKilled=!0,{point:{x:t.clientX,y:t.clientY,z:t.pressure},shiftKey:t.shiftKey,altKey:t.altKey,ctrlKey:t.metaKey||t.ctrlKey,metaKey:t.metaKey,accelKey:un(t),pointerId:t.pointerId,button:t.button,isPen:t.pointerType==="pen"}}function mb(){const t=z();return w.useMemo(function(){let r,s;function o(m){if(!m.isKilled){if(m.button===gb){t.dispatch({type:"pointer",target:"canvas",name:"right_click",...lr(m)});return}m.button!==0&&m.button!==1&&m.button!==5||(dd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_down",...lr(m)}))}}function i(m){m.isKilled||m.clientX===r&&m.clientY===s||(r=m.clientX,s=m.clientY,t.dispatch({type:"pointer",target:"canvas",name:"pointer_move",...lr(m)}))}function a(m){m.isKilled||m.button!==0&&m.button!==1&&m.button!==2&&m.button!==5||(r=m.clientX,s=m.clientY,hd(m.currentTarget,m),t.dispatch({type:"pointer",target:"canvas",name:"pointer_up",...lr(m)}))}function l(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!0:null})}function c(m){if(m.isKilled||t.getInstanceState().isPenMode&&m.pointerType!=="pen")return;const v=m.pointerType==="mouse"||m.pointerType==="pen";t.updateInstanceState({isHoveringCanvas:v?!1:null})}function u(m){m.isKilled=!0,xe(m)}function h(m){m.isKilled=!0,m.target instanceof HTMLElement&&m.target.tagName!=="A"&&m.target.tagName!=="TEXTAREA"&&!(t.getEditingShape()&&m.target.className.includes("tl-text-content"))&&xe(m)}function f(m){xe(m)}async function p(m){var y,S;if(xe(m),Ct(m),!((S=(y=m.dataTransfer)==null?void 0:y.files)!=null&&S.length))return;const v=Array.from(m.dataTransfer.files);await t.putExternalContent({type:"files",files:v,point:t.screenToPage({x:m.clientX,y:m.clientY}),ignoreParent:!1})}function g(m){Ct(m)}return{onPointerDown:o,onPointerMove:i,onPointerUp:a,onPointerEnter:l,onPointerLeave:c,onDragOver:f,onDrop:p,onTouchStart:u,onTouchEnd:h,onClick:g}},[t])}function EX(){const t=z();w.useEffect(()=>{let e=t.getInstanceState().isCoarsePointer;const n=i=>{const a=i.pointerType!=="mouse";e!==a&&(e=a,t.updateInstanceState({isCoarsePointer:a}))};window.addEventListener("pointerdown",n,{capture:!0});const r=window.matchMedia&&window.matchMedia("(any-pointer: coarse)"),s=Ge.isFirefox&&!Ge.isAndroid&&!Ge.isIos,o=()=>{const i=s?!1:r.matches;e===i&&(e=i,t.updateInstanceState({isCoarsePointer:i}))};return r&&(r.addEventListener("change",o),o()),()=>{window.removeEventListener("pointerdown",n,{capture:!0}),r&&r.removeEventListener("change",o)}},[t])}const dj=w.createContext(null);function hj({container:t,children:e}){return d.jsx(dj.Provider,{value:t,children:e})}function Tt(){return zn(w.useContext(dj),"useContainer used outside of <Tldraw />")}function kX(){const t=z(),e=Tt(),n=U("isFocused",()=>t.getIsFocused(),[t]);w.useEffect(()=>{if(!e)return;function r(s){if(s.isSpecialRedispatchedEvent)return;xe(s),Ct(s);const o=e.querySelector(".tl-canvas");if(!o)return;const i=new DragEvent(s.type,s);i.isSpecialRedispatchedEvent=!0,o.dispatchEvent(i)}return e.addEventListener("dragover",r),e.addEventListener("drop",r),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",r)}},[e]),w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;let r=null;const s=()=>{r!=null&&r();const o=`(resolution: ${window.devicePixelRatio}dppx)`,i=matchMedia(o),a=l=>{l.type==="change"&&s()};i.addEventListener?i.addEventListener("change",s):i.addListener&&i.addListener(a),r=()=>{i.removeEventListener?i.removeEventListener("change",s):i.removeListener&&i.removeListener(a)},t.updateInstanceState({devicePixelRatio:window.devicePixelRatio})};return s(),()=>{r==null||r()}},[t]),w.useEffect(()=>{if(!n)return;const r=a=>{if(a.altKey&&(t.isIn("zoom")||!t.getPath().endsWith(".idle"))&&!gh(t)&&xe(a),a.isKilled)return;switch(a.isKilled=!0,a.key){case"=":case"-":case"0":{if(a.metaKey||a.ctrlKey){xe(a);return}break}case"Tab":{if(gh(t))return;break}case",":return;case"Escape":{if((t.getEditingShape()||t.getSelectedShapeIds().length>0)&&xe(a),t.menus.getOpenMenus().length>0)return;t.inputs.keys.has("Escape")||(t.inputs.keys.add("Escape"),t.cancel(),e.focus());return}default:if(gh(t))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,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)},s=a=>{if(a.isKilled||(a.isKilled=!0,gh(t))||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,metaKey:a.metaKey,accelKey:un(a)};t.dispatch(l)};function o(a){var l,c;if(e.contains(a.target)){const u=a.touches[0].pageX,h=a.touches[0].radiusX||0;(u-h<10||u+h>t.getViewportScreenBounds().width-10)&&(((l=a.target)==null?void 0:l.tagName)==="BUTTON"&&((c=a.target)==null||c.click()),xe(a))}}const i=a=>{e.contains(a.target)&&(a.ctrlKey||a.metaKey)&&xe(a)};return e.addEventListener("touchstart",o,{passive:!1}),e.addEventListener("wheel",i,{passive:!1}),document.addEventListener("gesturestart",xe),document.addEventListener("gesturechange",xe),document.addEventListener("gestureend",xe),e.addEventListener("keydown",r),e.addEventListener("keyup",s),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("wheel",i),document.removeEventListener("gesturestart",xe),document.removeEventListener("gesturechange",xe),document.removeEventListener("gestureend",xe),e.removeEventListener("keydown",r),e.removeEventListener("keyup",s)}},[t,e,n])}const TX=["input","select","button","textarea"];function gh(t){const{activeElement:e}=document;return t.menus.hasOpenMenus()||e&&(e.getAttribute("contenteditable")||TX.indexOf(e.tagName.toLowerCase())>-1)}const MX=["textarea","input"];function AX(t){const e=z();w.useEffect(()=>{const n=t.current;if(!n)return;const r=s=>{var o;if(s instanceof PointerEvent&&s.pointerType==="pen"){s.isKilled=!0;const{target:i}=s;if(MX.includes((o=i.tagName)==null?void 0:o.toLocaleLowerCase())||e.isIn("select.editing_shape"))return;xe(s)}};return n.addEventListener("touchstart",r),n.addEventListener("touchend",r),()=>{n.removeEventListener("touchstart",r),n.removeEventListener("touchend",r)}},[e,t])}function jX(t,e,n){return Math.max(e,Math.min(t,n))}const Vt={toVector(t,e){return t===void 0&&(t=e),Array.isArray(t)?t:[t,t]},add(t,e){return[t[0]+e[0],t[1]+e[1]]},sub(t,e){return[t[0]-e[0],t[1]-e[1]]},addTo(t,e){t[0]+=e[0],t[1]+=e[1]},subTo(t,e){t[0]-=e[0],t[1]-=e[1]}};function lI(t,e,n){return e===0||Math.abs(e)===1/0?Math.pow(t,n*5):t*e*n/(e+n*t)}function cI(t,e,n,r=.15){return r===0?jX(t,e,n):t<e?-lI(e-t,n-e,r)+e:t>n?+lI(t-n,n-e,r)+n:t}function OX(t,[e,n],[r,s]){const[[o,i],[a,l]]=t;return[cI(e,o,i,r),cI(n,a,l,s)]}function DX(t,e){if(typeof t!="object"||t===null)return t;var n=t[Symbol.toPrimitive];if(n!==void 0){var r=n.call(t,e||"default");if(typeof r!="object")return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function RX(t){var e=DX(t,"string");return typeof e=="symbol"?e:String(e)}function on(t,e,n){return e=RX(e),e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function uI(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),n.push.apply(n,r)}return n}function ht(t){for(var e=1;e<arguments.length;e++){var n=arguments[e]!=null?arguments[e]:{};e%2?uI(Object(n),!0).forEach(function(r){on(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):uI(Object(n)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(n,r))})}return t}const fj={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 dI(t){return t?t[0].toUpperCase()+t.slice(1):""}const LX=["enter","leave"];function $X(t=!1,e){return t&&!LX.includes(e)}function FX(t,e="",n=!1){const r=fj[t],s=r&&r[e]||e;return"on"+dI(t)+dI(s)+($X(n,s)?"Capture":"")}const NX=["gotpointercapture","lostpointercapture"];function zX(t){let e=t.substring(2).toLowerCase();const n=!!~e.indexOf("passive");n&&(e=e.replace("passive",""));const r=NX.includes(e)?"capturecapture":"capture",s=!!~e.indexOf(r);return s&&(e=e.replace("capture","")),{device:e,capture:s,passive:n}}function BX(t,e=""){const n=fj[t],r=n&&n[e]||e;return t+r}function pj(t){return"touches"in t}function UX(t){return pj(t)?"touch":"pointerType"in t?t.pointerType:"mouse"}function HX(t){return Array.from(t.touches).filter(e=>{var n,r;return e.target===t.currentTarget||((n=t.currentTarget)===null||n===void 0||(r=n.contains)===null||r===void 0?void 0:r.call(n,e.target))})}function wx(t,e){try{const n=e.clientX-t.clientX,r=e.clientY-t.clientY,s=(e.clientX+t.clientX)/2,o=(e.clientY+t.clientY)/2,i=Math.hypot(n,r);return{angle:-(Math.atan2(n,r)*180)/Math.PI,distance:i,origin:[s,o]}}catch{}return null}function KX(t){return HX(t).map(e=>e.identifier)}function hI(t,e){const[n,r]=Array.from(t.touches).filter(s=>e.includes(s.identifier));return wx(n,r)}const fI=40,pI=800;function gj(t){let{deltaX:e,deltaY:n,deltaMode:r}=t;return r===1?(e*=fI,n*=fI):r===2&&(e*=pI,n*=pI),[e,n]}function WX(t){const e={};if("buttons"in t&&(e.buttons=t.buttons),"shiftKey"in t){const{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o}=t;Object.assign(e,{shiftKey:n,altKey:r,metaKey:s,ctrlKey:o})}return e}function $p(t,...e){return typeof t=="function"?t(...e):t}function GX(){}function VX(...t){return t.length===0?GX:t.length===1?t[0]:function(){let e;for(const n of t)e=n.apply(this,arguments)||e;return e}}function gI(t,e){return Object.assign({},e,t||{})}const YX=32;class mj{constructor(e,n,r){this.ctrl=e,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(e){this.ctrl.state[this.key]=e}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:e,shared:n,ingKey:r,args:s}=this;n[r]=e._active=e.active=e._blocked=e._force=!1,e._step=[!1,!1],e.intentional=!1,e._movement=[0,0],e._distance=[0,0],e._direction=[0,0],e._delta=[0,0],e._bounds=[[-1/0,1/0],[-1/0,1/0]],e.args=s,e.axis=void 0,e.memo=void 0,e.elapsedTime=e.timeDelta=0,e.direction=[0,0],e.distance=[0,0],e.overflow=[0,0],e._movementBound=[!1,!1],e.velocity=[0,0],e.movement=[0,0],e.delta=[0,0],e.timeStamp=0}start(e){const n=this.state,r=this.config;n._active||(this.reset(),this.computeInitial(),n._active=!0,n.target=e.target,n.currentTarget=e.currentTarget,n.lastOffset=r.from?$p(r.from,n):n.offset,n.offset=n.lastOffset,n.startTime=n.timeStamp=e.timeStamp)}computeValues(e){const n=this.state;n._values=e,n.values=this.config.transform(e)}computeInitial(){const e=this.state;e._initial=e._values,e.initial=e.values}compute(e){const{state:n,config:r,shared:s}=this;n.args=this.args;let o=0;if(e&&(n.event=e,r.preventDefault&&e.cancelable&&n.event.preventDefault(),n.type=e.type,s.touches=this.ctrl.pointerIds.size||this.ctrl.touchIds.size,s.locked=!!document.pointerLockElement,Object.assign(s,WX(e)),s.down=s.pressed=s.buttons%2===1||s.touches>0,o=e.timeStamp-n.timeStamp,n.timeStamp=e.timeStamp,n.elapsedTime=n.timeStamp-n.startTime),n._active){const _=n._delta.map(Math.abs);Vt.addTo(n._distance,_)}this.axisIntent&&this.axisIntent(e);const[i,a]=n._movement,[l,c]=r.threshold,{_step:u,values:h}=n;if(r.hasCustomTransform?(u[0]===!1&&(u[0]=Math.abs(i)>=l&&h[0]),u[1]===!1&&(u[1]=Math.abs(a)>=c&&h[1])):(u[0]===!1&&(u[0]=Math.abs(i)>=l&&Math.sign(i)*l),u[1]===!1&&(u[1]=Math.abs(a)>=c&&Math.sign(a)*c)),n.intentional=u[0]!==!1||u[1]!==!1,!n.intentional)return;const f=[0,0];if(r.hasCustomTransform){const[_,E]=h;f[0]=u[0]!==!1?_-u[0]:0,f[1]=u[1]!==!1?E-u[1]:0}else f[0]=u[0]!==!1?i-u[0]:0,f[1]=u[1]!==!1?a-u[1]:0;this.restrictToAxis&&!n._blocked&&this.restrictToAxis(f);const p=n.offset,g=n._active&&!n._blocked||n.active;g&&(n.first=n._active&&!n.active,n.last=!n._active&&n.active,n.active=s[this.ingKey]=n._active,e&&(n.first&&("bounds"in r&&(n._bounds=$p(r.bounds,n)),this.setup&&this.setup()),n.movement=f,this.computeOffset()));const[m,v]=n.offset,[[y,S],[b,P]]=n._bounds;n.overflow=[m<y?-1:m>S?1:0,v<b?-1:v>P?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 C=n._active?r.rubberband||[0,0]:[0,0];if(n.offset=OX(n._bounds,n.offset,C),n.delta=Vt.sub(n.offset,p),this.computeMovement(),g&&(!n.last||o>YX)){n.delta=Vt.sub(n.offset,p);const _=n.delta.map(Math.abs);Vt.addTo(n.distance,_),n.direction=n.delta.map(Math.sign),n._direction=n._delta.map(Math.sign),!n.first&&o>0&&(n.velocity=[_[0]/o,_[1]/o],n.timeDelta=o)}}emit(){const e=this.state,n=this.shared,r=this.config;if(e._active||this.clean(),(e._blocked||!e.intentional)&&!e._force&&!r.triggerAllEvents)return;const s=this.handler(ht(ht(ht({},n),e),{},{[this.aliasKey]:e.values}));s!==void 0&&(e.memo=s)}clean(){this.eventStore.clean(),this.timeoutStore.clean()}}function XX([t,e],n){const r=Math.abs(t),s=Math.abs(e);if(r>s&&r>n)return"x";if(s>r&&s>n)return"y"}class qX extends mj{constructor(...e){super(...e),on(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=Vt.add(this.state.lastOffset,this.state.movement)}computeMovement(){this.state.movement=Vt.sub(this.state.offset,this.state.lastOffset)}axisIntent(e){const n=this.state,r=this.config;if(!n.axis&&e){const s=typeof r.axisThreshold=="object"?r.axisThreshold[UX(e)]:r.axisThreshold;n.axis=XX(n._movement,s)}n._blocked=(r.lockDirection||!!r.axis)&&!n.axis||!!r.axis&&r.axis!==n.axis}restrictToAxis(e){if(this.config.axis||this.config.lockDirection)switch(this.state.axis){case"x":e[1]=0;break;case"y":e[0]=0;break}}}const ZX=t=>t,mI=.15,yj={enabled(t=!0){return t},eventOptions(t,e,n){return ht(ht({},n.shared.eventOptions),t)},preventDefault(t=!1){return t},triggerAllEvents(t=!1){return t},rubberband(t=0){switch(t){case!0:return[mI,mI];case!1:return[0,0];default:return Vt.toVector(t)}},from(t){if(typeof t=="function")return t;if(t!=null)return Vt.toVector(t)},transform(t,e,n){const r=t||n.shared.transform;return this.hasCustomTransform=!!r,r||ZX},threshold(t){return Vt.toVector(t,0)}},QX=0,fd=ht(ht({},yj),{},{axis(t,e,{axis:n}){if(this.lockDirection=n==="lock",!this.lockDirection)return n},axisThreshold(t=QX){return t},bounds(t={}){if(typeof t=="function")return o=>fd.bounds(t(o));if("current"in t)return()=>t.current;if(typeof HTMLElement=="function"&&t instanceof HTMLElement)return t;const{left:e=-1/0,right:n=1/0,top:r=-1/0,bottom:s=1/0}=t;return[[e,n],[r,s]]}}),pd=typeof window<"u"&&window.document&&window.document.createElement;function Sj(){return pd&&"ontouchstart"in window}function JX(){return Sj()||pd&&window.navigator.maxTouchPoints>1}function eq(){return pd&&"onpointerdown"in window}function tq(){return pd&&"exitPointerLock"in window.document}function nq(){try{return"constructor"in GestureEvent}catch{return!1}}const Mr={isBrowser:pd,gesture:nq(),touch:Sj(),touchscreen:JX(),pointer:eq(),pointerLock:tq()},rq=250,sq=180,oq=.5,iq=50,aq=250,lq=10,yI={mouse:0,touch:0,pen:8};ht(ht({},fd),{},{device(t,e,{pointer:{touch:n=!1,lock:r=!1,mouse:s=!1}={}}){return this.pointerLock=r&&Mr.pointerLock,Mr.touch&&n?"touch":this.pointerLock?"mouse":Mr.pointer&&!s?"pointer":Mr.touch?"touch":"mouse"},preventScrollAxis(t,e,{preventScroll:n}){if(this.preventScrollDelay=typeof n=="number"?n:n||n===void 0&&t?rq:void 0,!(!Mr.touchscreen||n===!1))return t||(n!==void 0?"y":void 0)},pointerCapture(t,e,{pointer:{capture:n=!0,buttons:r=1,keys:s=!0}={}}){return this.pointerButtons=r,this.keys=s,!this.pointerLock&&this.device==="pointer"&&n},threshold(t,e,{filterTaps:n=!1,tapsThreshold:r=3,axis:s=void 0}){const o=Vt.toVector(t,n?r:s?1:0);return this.filterTaps=n,this.tapsThreshold=r,o},swipe({velocity:t=oq,distance:e=iq,duration:n=aq}={}){return{velocity:this.transform(Vt.toVector(t)),distance:this.transform(Vt.toVector(e)),duration:n}},delay(t=0){switch(t){case!0:return sq;case!1:return 0;default:return t}},axisThreshold(t){return t?ht(ht({},yI),t):yI},keyboardDisplacement(t=lq){return t}});function vj(t){const[e,n]=t.overflow,[r,s]=t._delta,[o,i]=t._direction;(e<0&&r>0&&o<0||e>0&&r<0&&o>0)&&(t._movement[0]=t._movementBound[0]),(n<0&&s>0&&i<0||n>0&&s<0&&i>0)&&(t._movement[1]=t._movementBound[1])}const cq=30,uq=100;class dq extends mj{constructor(...e){super(...e),on(this,"ingKey","pinching"),on(this,"aliasKey","da")}init(){this.state.offset=[1,0],this.state.lastOffset=[1,0],this.state._pointerEvents=new Map}reset(){super.reset();const e=this.state;e._touchIds=[],e.canceled=!1,e.cancel=this.cancel.bind(this),e.turns=0}computeOffset(){const{type:e,movement:n,lastOffset:r}=this.state;e==="wheel"?this.state.offset=Vt.add(n,r):this.state.offset=[(1+n[0])*r[0],n[1]+r[1]]}computeMovement(){const{offset:e,lastOffset:n}=this.state;this.state.movement=[e[0]/n[0],e[1]-n[1]]}axisIntent(){const e=this.state,[n,r]=e._movement;if(!e.axis){const s=Math.abs(n)*cq-Math.abs(r);s<0?e.axis="angle":s>0&&(e.axis="scale")}}restrictToAxis(e){this.config.lockDirection&&(this.state.axis==="scale"?e[1]=0:this.state.axis==="angle"&&(e[0]=0))}cancel(){const e=this.state;e.canceled||setTimeout(()=>{e.canceled=!0,e._active=!1,this.compute(),this.emit()},0)}touchStart(e){this.ctrl.setEventIds(e);const n=this.state,r=this.ctrl.touchIds;if(n._active&&n._touchIds.every(o=>r.has(o))||r.size<2)return;this.start(e),n._touchIds=Array.from(r).slice(0,2);const s=hI(e,n._touchIds);s&&this.pinchStart(e,s)}pointerStart(e){if(e.buttons!=null&&e.buttons%2!==1)return;this.ctrl.setEventIds(e),e.target.setPointerCapture(e.pointerId);const n=this.state,r=n._pointerEvents,s=this.ctrl.pointerIds;if(n._active&&Array.from(r.keys()).every(i=>s.has(i))||(r.size<2&&r.set(e.pointerId,e),n._pointerEvents.size<2))return;this.start(e);const o=wx(...Array.from(r.values()));o&&this.pinchStart(e,o)}pinchStart(e,n){const r=this.state;r.origin=n.origin,this.computeValues([n.distance,n.angle]),this.computeInitial(),this.compute(e),this.emit()}touchMove(e){if(!this.state._active)return;const n=hI(e,this.state._touchIds);n&&this.pinchMove(e,n)}pointerMove(e){const n=this.state._pointerEvents;if(n.has(e.pointerId)&&n.set(e.pointerId,e),!this.state._active)return;const r=wx(...Array.from(n.values()));r&&this.pinchMove(e,r)}pinchMove(e,n){const r=this.state,s=r._values[1],o=n.angle-s;let i=0;Math.abs(o)>270&&(i+=Math.sign(o)),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(e),this.emit()}touchEnd(e){this.ctrl.setEventIds(e),this.state._active&&this.state._touchIds.some(n=>!this.ctrl.touchIds.has(n))&&(this.state._active=!1,this.compute(e),this.emit())}pointerEnd(e){const n=this.state;this.ctrl.setEventIds(e);try{e.target.releasePointerCapture(e.pointerId)}catch{}n._pointerEvents.has(e.pointerId)&&n._pointerEvents.delete(e.pointerId),n._active&&n._pointerEvents.size<2&&(n._active=!1,this.compute(e),this.emit())}gestureStart(e){e.cancelable&&e.preventDefault();const n=this.state;n._active||(this.start(e),this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY],this.compute(e),this.emit())}gestureMove(e){if(e.cancelable&&e.preventDefault(),!this.state._active)return;const n=this.state;this.computeValues([e.scale,e.rotation]),n.origin=[e.clientX,e.clientY];const r=n._movement;n._movement=[e.scale-1,e.rotation],n._delta=Vt.sub(n._movement,r),this.compute(e),this.emit()}gestureEnd(e){this.state._active&&(this.state._active=!1,this.compute(e),this.emit())}wheel(e){const n=this.config.modifierKey;n&&(Array.isArray(n)?!n.find(r=>e[r]):!e[n])||(this.state._active?this.wheelChange(e):this.wheelStart(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this)))}wheelStart(e){this.start(e),this.wheelChange(e)}wheelChange(e){"uv"in e||e.cancelable&&e.preventDefault();const r=this.state;r._delta=[-gj(e)[1]/uq*r.offset[0],0],Vt.addTo(r._movement,r._delta),vj(r),this.state.origin=[e.clientX,e.clientY],this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){const n=this.config.device;n&&(e(n,"start",this[n+"Start"].bind(this)),e(n,"change",this[n+"Move"].bind(this)),e(n,"end",this[n+"End"].bind(this)),e(n,"cancel",this[n+"End"].bind(this)),e("lostPointerCapture","",this[n+"End"].bind(this))),this.config.pinchOnWheel&&e("wheel","",this.wheel.bind(this),{passive:!1})}}const hq=ht(ht({},yj),{},{device(t,e,{shared:n,pointer:{touch:r=!1}={}}){if(n.target&&!Mr.touch&&Mr.gesture)return"gesture";if(Mr.touch&&r)return"touch";if(Mr.touchscreen){if(Mr.pointer)return"pointer";if(Mr.touch)return"touch"}},bounds(t,e,{scaleBounds:n={},angleBounds:r={}}){const s=i=>{const a=gI($p(n,i),{min:-1/0,max:1/0});return[a.min,a.max]},o=i=>{const a=gI($p(r,i),{min:-1/0,max:1/0});return[a.min,a.max]};return typeof n!="function"&&typeof r!="function"?[s(),o()]:i=>[s(i),o(i)]},threshold(t,e,n){return this.lockDirection=n.axis==="lock",Vt.toVector(t,this.lockDirection?[.1,3]:0)},modifierKey(t){return t===void 0?"ctrlKey":t},pinchOnWheel(t=!0){return t}});ht(ht({},fd),{},{mouseOnly:(t=!0)=>t});class fq extends qX{constructor(...e){super(...e),on(this,"ingKey","wheeling")}wheel(e){this.state._active||this.start(e),this.wheelChange(e),this.timeoutStore.add("wheelEnd",this.wheelEnd.bind(this))}wheelChange(e){const n=this.state;n._delta=gj(e),Vt.addTo(n._movement,n._delta),vj(n),this.compute(e),this.emit()}wheelEnd(){this.state._active&&(this.state._active=!1,this.compute(),this.emit())}bind(e){e("wheel","",this.wheel.bind(this))}}const pq=fd;ht(ht({},fd),{},{mouseOnly:(t=!0)=>t});const yb=new Map,bx=new Map;function gq(t){yb.set(t.key,t.engine),bx.set(t.key,t.resolver)}const mq={key:"pinch",engine:dq,resolver:hq},yq={key:"wheel",engine:fq,resolver:pq};function Sq(t,e){if(t==null)return{};var n={},r=Object.keys(t),s,o;for(o=0;o<r.length;o++)s=r[o],!(e.indexOf(s)>=0)&&(n[s]=t[s]);return n}function vq(t,e){if(t==null)return{};var n=Sq(t,e),r,s;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);for(s=0;s<o.length;s++)r=o[s],!(e.indexOf(r)>=0)&&Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}const xq={target(t){if(t)return()=>"current"in t?t.current:t},enabled(t=!0){return t},window(t=Mr.isBrowser?window:void 0){return t},eventOptions({passive:t=!0,capture:e=!1}={}){return{passive:t,capture:e}},transform(t){return t}},wq=["target","eventOptions","window","enabled","transform"];function uf(t={},e){const n={};for(const[r,s]of Object.entries(e))switch(typeof s){case"function":n[r]=s.call(n,t[r],r,t);break;case"object":n[r]=uf(t[r],s);break;case"boolean":s&&(n[r]=t[r]);break}return n}function bq(t,e,n={}){const r=t,{target:s,eventOptions:o,window:i,enabled:a,transform:l}=r,c=vq(r,wq);if(n.shared=uf({target:s,eventOptions:o,window:i,enabled:a,transform:l},xq),e){const u=bx.get(e);n[e]=uf(ht({shared:n.shared},c),u)}else for(const u in c){const h=bx.get(u);h&&(n[u]=uf(ht({shared:n.shared},c[u]),h))}return n}class xj{constructor(e,n){on(this,"_listeners",new Set),this._ctrl=e,this._gestureKey=n}add(e,n,r,s,o){const i=this._listeners,a=BX(n,r),l=this._gestureKey?this._ctrl.config[this._gestureKey].eventOptions:{},c=ht(ht({},l),o);e.addEventListener(a,s,c);const u=()=>{e.removeEventListener(a,s,c),i.delete(u)};return i.add(u),u}clean(){this._listeners.forEach(e=>e()),this._listeners.clear()}}class Pq{constructor(){on(this,"_timeouts",new Map)}add(e,n,r=140,...s){this.remove(e),this._timeouts.set(e,window.setTimeout(n,r,...s))}remove(e){const n=this._timeouts.get(e);n&&window.clearTimeout(n)}clean(){this._timeouts.forEach(e=>void window.clearTimeout(e)),this._timeouts.clear()}}class Cq{constructor(e){on(this,"gestures",new Set),on(this,"_targetEventStore",new xj(this)),on(this,"gestureEventStores",{}),on(this,"gestureTimeoutStores",{}),on(this,"handlers",{}),on(this,"config",{}),on(this,"pointerIds",new Set),on(this,"touchIds",new Set),on(this,"state",{shared:{shiftKey:!1,metaKey:!1,ctrlKey:!1,altKey:!1}}),_q(this,e)}setEventIds(e){if(pj(e))return this.touchIds=new Set(KX(e)),this.touchIds;if("pointerId"in e)return e.type==="pointerup"||e.type==="pointercancel"?this.pointerIds.delete(e.pointerId):e.type==="pointerdown"&&this.pointerIds.add(e.pointerId),this.pointerIds}applyHandlers(e,n){this.handlers=e,this.nativeHandlers=n}applyConfig(e,n){this.config=bq(e,n,this.config)}clean(){this._targetEventStore.clean();for(const e of this.gestures)this.gestureEventStores[e].clean(),this.gestureTimeoutStores[e].clean()}effect(){return this.config.shared.target&&this.bind(),()=>this._targetEventStore.clean()}bind(...e){const n=this.config.shared,r={};let s;if(!(n.target&&(s=n.target(),!s))){if(n.enabled){for(const i of this.gestures){const a=this.config[i],l=SI(r,a.eventOptions,!!s);if(a.enabled){const c=yb.get(i);new c(this,e,i).bind(l)}}const o=SI(r,n.eventOptions,!!s);for(const i in this.nativeHandlers)o(i,"",a=>this.nativeHandlers[i](ht(ht({},this.state.shared),{},{event:a,args:e})),void 0,!0)}for(const o in r)r[o]=VX(...r[o]);if(!s)return r;for(const o in r){const{device:i,capture:a,passive:l}=zX(o);this._targetEventStore.add(s,i,"",r[o],{capture:a,passive:l})}}}}function Da(t,e){t.gestures.add(e),t.gestureEventStores[e]=new xj(t,e),t.gestureTimeoutStores[e]=new Pq}function _q(t,e){e.drag&&Da(t,"drag"),e.wheel&&Da(t,"wheel"),e.scroll&&Da(t,"scroll"),e.move&&Da(t,"move"),e.pinch&&Da(t,"pinch"),e.hover&&Da(t,"hover")}const SI=(t,e,n)=>(r,s,o,i={},a=!1)=>{var l,c;const u=(l=i.capture)!==null&&l!==void 0?l:e.capture,h=(c=i.passive)!==null&&c!==void 0?c:e.passive;let f=a?r:FX(r,s,u);n&&h&&(f+="Passive"),t[f]=t[f]||[],t[f].push(o)},Iq=/^on(Drag|Wheel|Scroll|Move|Pinch|Hover)/;function Eq(t){const e={},n={},r=new Set;for(let s in t)Iq.test(s)?(r.add(RegExp.lastMatch),n[s]=t[s]):e[s]=t[s];return[n,e,r]}function Ra(t,e,n,r,s,o){if(!t.has(n)||!yb.has(r))return;const i=n+"Start",a=n+"End",l=c=>{let u;return c.first&&i in e&&e[i](c),n in e&&(u=e[n](c)),c.last&&a in e&&e[a](c),u};s[r]=l,o[r]=o[r]||{}}function kq(t,e){const[n,r,s]=Eq(t),o={};return Ra(s,n,"onDrag","drag",o,e),Ra(s,n,"onWheel","wheel",o,e),Ra(s,n,"onScroll","scroll",o,e),Ra(s,n,"onPinch","pinch",o,e),Ra(s,n,"onMove","move",o,e),Ra(s,n,"onHover","hover",o,e),{handlers:o,config:e,nativeHandlers:r}}function Tq(t,e={},n,r){const s=ke.useMemo(()=>new Cq(t),[]);if(s.applyHandlers(t,r),s.applyConfig(e,n),ke.useEffect(s.effect.bind(s)),ke.useEffect(()=>s.clean.bind(s),[]),e.target===void 0)return s.bind.bind(s)}function Mq(t){return t.forEach(gq),function(n,r){const{handlers:s,nativeHandlers:o,config:i}=kq(n,r||{});return Tq(s,i,void 0,o)}}const vI=10,Aq=/Mac|iPod|iPhone|iPad/.test(typeof window>"u"?"node":window.navigator.platform);function wj(t){let{deltaY:e,deltaX:n}=t,r=0;return t.ctrlKey||t.altKey||t.metaKey?r=(Math.abs(e)>vI?vI*Math.sign(e):e)/100:t.shiftKey&&!Aq&&(n=e,e=0),{x:-n,y:-e,z:-r}}const jq=Mq([yq,mq]);let La;const Oq=t=>La===void 0?(La=t,!1):t-La>120&&t-La<160?(La=t,!0):(La=t,!1);function Dq(t){const e=z(),n=w.useMemo(()=>{let r="not sure";const s=({event:m})=>{if(!e.getInstanceState().isFocused||(r="not sure",Oq(Date.now())))return;const v=e.getEditingShapeId();if(v){const b=e.getShape(v);if(b&&e.getShapeUtil(b).canScroll(b)){const C=e.getShapePageBounds(v);if(C!=null&&C.containsPoint(e.inputs.currentPagePoint))return}}xe(m),Ct(m);const y=wj(m);if(y.x===0&&y.y===0)return;const S={type:"wheel",name:"wheel",delta:y,point:new x(m.clientX,m.clientY),shiftKey:m.shiftKey,altKey:m.altKey,ctrlKey:m.metaKey||m.ctrlKey,metaKey:m.metaKey,accelKey:un(m)};e.dispatch(S)};let o=1,i=1,a=1,l=0;const c=new x,u=new x,h=m=>{const v=t.current;r="not sure";const{event:y,origin:S,da:b}=m;y instanceof WheelEvent||(y.target===v||v!=null&&v.contains(y.target))&&(u.x=S[0],u.y=S[1],c.x=S[0],c.y=S[1],o=b[0],i=e.getZoomLevel(),e.dispatch({type:"pinch",name:"pinch_start",point:{x:S[0],y:S[1],z:e.getZoomLevel()},delta:{x:0,y:0},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)}))},f=m=>{if(m&&(r="zooming"),r==="zooming")return;const v=Math.abs(l-o),y=x.Dist(c,u);switch(r){case"not sure":{v>24?r="zooming":y>16&&(r="panning");break}case"panning":{v>64&&(r="zooming");break}}};return{onWheel:s,onPinchStart:h,onPinchEnd:m=>{const v=t.current,{event:y,origin:S,offset:b}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const P=b[0];r="not sure",e.timers.requestAnimationFrame(()=>{e.dispatch({type:"pinch",name:"pinch_end",point:{x:S[0],y:S[1],z:P},delta:{x:S[0],y:S[1]},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)})})},onPinch:m=>{const v=t.current,{event:y,origin:S,offset:b,da:P}=m;if(y instanceof WheelEvent||!(y.target===v||v!=null&&v.contains(y.target)))return;const C=m.type==="gesturechange"||m.type==="gestureend";l=P[0];const _=S[0]-u.x,E=S[1]-u.y;switch(u.x=S[0],u.y=S[1],f(C),r){case"zooming":{a=b[0],e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:a},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}case"panning":{e.dispatch({type:"pinch",name:"pinch",point:{x:S[0],y:S[1],z:i},delta:{x:_,y:E},shiftKey:y.shiftKey,altKey:y.altKey,ctrlKey:y.metaKey||y.ctrlKey,metaKey:y.metaKey,accelKey:un(y)});break}}}}},[e,t]);jq(n,{target:t,eventOptions:{passive:!1},pinch:{from:()=>[e.getZoomLevel(),0],scaleBounds:()=>{const r=e.getBaseZoom(),s=e.getCameraOptions().zoomSteps,o=s[0]*r,i=s[s.length-1]*r;return{from:e.getZoomLevel(),max:i,min:o}}}})}function Yy(t,e,n){const r=t.getShape(e),s=t.getShapeHandles(r);return{shape:r,handle:s.find(o=>o.id===n)}}function Rq(t,e){const n=z();return w.useMemo(()=>{const r=l=>{if(l.isKilled)return;const c=Lp(l.currentTarget);dd(c,l);const{shape:u,handle:h}=Yy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_down",...lr(l)})};let s,o;return{onPointerDown:r,onPointerMove:l=>{if(l.isKilled||l.clientX===s&&l.clientY===o)return;s=l.clientX,o=l.clientY;const{shape:c,handle:u}=Yy(n,t,e);u&&n.dispatch({type:"pointer",target:"handle",handle:u,shape:c,name:"pointer_move",...lr(l)})},onPointerUp:l=>{if(l.isKilled)return;const c=Lp(l.currentTarget);hd(c,l);const{shape:u,handle:h}=Yy(n,t,e);h&&n.dispatch({type:"pointer",target:"handle",handle:h,shape:u,name:"pointer_up",...lr(l)})}}},[n,t,e])}function Lq(t){const e=z();w.useLayoutEffect(()=>{const n=TT(()=>{t.current&&e.updateViewportScreenBounds(t.current)},200,{trailing:!0}),r=e.timers.setInterval(n,1e3);window.addEventListener("resize",n);const s=new ResizeObserver(a=>{a[0].contentRect&&n()}),o=t.current;let i=null;return o&&(s.observe(o),i=$q(o),i.addEventListener("scroll",n)),()=>{clearInterval(r),window.removeEventListener("resize",n),s.disconnect(),i==null||i.removeEventListener("scroll",n),n.cancel()}},[e,t])}/*!
|
|
89
89
|
* Author: excalidraw
|
|
90
90
|
* MIT License: https://github.com/excalidraw/excalidraw/blob/master/LICENSE
|
|
91
91
|
* https://github.com/excalidraw/excalidraw/blob/48c3465b19f10ec755b3eb84e21a01a468e96e43/packages/excalidraw/utils.ts#L600
|
|
@@ -192,7 +192,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
192
192
|
opacity: 1;
|
|
193
193
|
pointer-events: all;
|
|
194
194
|
}
|
|
195
|
-
}`;return d.jsx("style",{children:n})}),tte=[],nte=[],rte=[],ste="tl-container",ote=w.memo(function({store:e,components:n,className:r,user:s,options:o,...i}){const[a,l]=w.useState(null),c=w.useMemo(()=>s??Uj(),[s]),u=(n==null?void 0:n.ErrorFallback)===void 0?Oj:n==null?void 0:n.ErrorFallback,h={...i,shapeUtils:i.shapeUtils??tte,bindingUtils:i.bindingUtils??nte,tools:i.tools??rte,components:n,options:tc(o)};return d.jsx("div",{ref:l,"data-tldraw":oj,draggable:!1,className:ce(`${ste} tl-theme__light`,r),onPointerDown:Ct,tabIndex:-1,children:d.jsx(Uu,{fallback:u,onError:f=>v0(f,{tags:{origin:"react.tldraw-before-app"}}),children:a&&d.jsx(Gee,{licenseKey:i.licenseKey,children:d.jsx(hj,{container:a,children:d.jsx(AZ,{overrides:n,children:e?e instanceof eb?d.jsx(XR,{...h,store:e,user:c}):d.jsx(YR,{...h,store:e,user:c}):d.jsx(ite,{...h,store:e,user:c})})})})})})});function ite(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:s,bindingUtils:o,persistenceKey:i,sessionId:a,user:l,assets:c}=t,u=$ee({shapeUtils:s,bindingUtils:o,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c});return d.jsx(YR,{...t,store:u,user:l})}const YR=w.memo(function({store:e,user:n,...r}){const s=Tt();w.useLayoutEffect(()=>{n.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,n]);const{LoadingScreen:o}=st();switch(e.status){case"error":throw e.error;case"loading":return o?d.jsx(o,{}):null}return d.jsx(XR,{...r,store:e.store,user:n})}),nS=()=>document.location.search.includes("tldraw_preserve_focus");function XR({onMount:t,children:e,store:n,tools:r,shapeUtils:s,bindingUtils:o,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,options:h,licenseKey:f,deepLinks:p,isShapeHidden:g}){const{ErrorFallback:m}=st(),v=Tt(),[y,S]=GR(null),b=w.useRef(null),P=tc(p===!0?{}:p),C=w.useRef({autoFocus:l&&!nS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!nS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P}},[l,c,a,u,P]),w.useLayoutEffect(()=>{const{autoFocus:k,inferDarkMode:D,initialState:T,cameraOptions:j,deepLinks:L}=C.current,M=new Q({store:n,shapeUtils:s,bindingUtils:o,tools:r,getContainer:()=>v,user:i,initialState:T,autoFocus:k,inferDarkMode:D,cameraOptions:j,options:h,licenseKey:f,isShapeHidden:g});return M.updateViewportScreenBounds(b.current??v),L&&(L!=null&&L.getUrl?M.navigateToDeepLink({...L,url:L.getUrl(M)}):M.navigateToDeepLink(L)),S(M),()=>{M.dispose()}},[o,v,h,s,n,r,i,S,f,g]),w.useLayoutEffect(()=>{if(y&&P)return y.registerDeepLinkListener(P)},[y,P]),w.useLayoutEffect(()=>{y&&u&&y.setCameraOptions(u)},[y,u]);const _=w.useSyncExternalStore(w.useCallback(k=>y?(y.on("crash",k),()=>y.off("crash",k)):()=>{},[y]),()=>(y==null?void 0:y.getCrashingError())??null);w.useEffect(function(){if(!y)return;function D(){y&&y.focus()}function T(){y&&y.blur()}if(l&&nS())return y.getContainer().addEventListener("pointerdown",D),document.body.addEventListener("pointerdown",T),()=>{var j;(j=y.getContainer())==null||j.removeEventListener("pointerdown",D),document.body.removeEventListener("pointerdown",T)}},[y,l]);const{Canvas:E}=st();return y?d.jsx(Uu,{fallback:m,onError:k=>y.annotateError(k,{origin:"react.tldraw",willCrashApp:!0}),children:_?d.jsx(lte,{crashingError:_}):d.jsx(fb,{editor:y,children:d.jsxs(ate,{onMount:t,children:[e??(E?d.jsx(E,{},y.contextId):null),d.jsx(Qee,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:b})}function ate({children:t,onMount:e}){return Fee(),Pee(),Cee(),_ee(),ZR(n=>{const r=n.store.props.onMount(n),s=e==null?void 0:e(n);return()=>{r==null||r(),s==null||s()}}),t}function lte({crashingError:t}){throw t}function Db({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function qR({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function ZR(t){const e=z(),n=Hg(r=>{let s;return r.run(()=>{s=t==null?void 0:t(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});ke.useLayoutEffect(()=>{if(e)return n==null?void 0:n(e)},[e,n])}function hi({children:t,className:e="",...n}){return d.jsx("div",{...n,className:ce("tl-html-container",e),children:t})}class ff{constructor(e){this.editor=e}}I(ff,"props"),I(ff,"migrations"),I(ff,"type");function qg(t,e,n={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let h=t.props.w*o,f=t.props.h*i;const p=new x(0,0);if(h>0){if(h<a){switch(s){case"top_left":case"left":case"bottom_left":{p.x=h-a;break}case"top":case"bottom":{p.x=(h-a)/2;break}default:p.x=0}h=a}}else if(p.x=h,h=-h,h<a){switch(s){case"top_left":case"left":case"bottom_left":{p.x=-h;break}default:p.x=-a}h=a}if(f>0){if(f<c){switch(s){case"top_left":case"top":case"top_right":{p.y=f-c;break}case"right":case"left":{p.y=(f-c)/2;break}default:p.y=0}f=c}}else if(p.y=f,f=-f,f<c){switch(s){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-c}f=c}const{x:g,y:m}=p.rot(t.rotation).add(r);return{...t,x:g,y:m,props:{w:Math.min(l,h),h:Math.min(u,f)}}}class oc extends ss{getGeometry(e){return new Fs({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return qg(e,n)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,n,r){return{...n.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}var jS;let cte=(jS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(jS,"id","idle"),jS);var OS;let ute=(OS=class extends ie{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=this.parent.shapeType,s=Ke(),o=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),i=is(n,this.editor);this.editor.createShapes([{id:s,type:r,x:i.x,y:i.y,props:{w:1,h:1}}]).select(s);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?l=>{var c;return(c=a.onCreate)==null?void 0:c.call(a,l)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,n=this.parent.shapeType,r=Ke();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:n,x:e.x,y:e.y}]);const s=this.editor.getShape(r);if(!s){this.cancel();return}let{w:o,h:i}=s.props;const a=new x(o/2,i/2),l=this.editor.getShapeParentTransform(s);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),o*=c,i*=c,a.mul(c));const u=nt(s),h=is(new x(s.x-a.x,s.y-a.y),this.editor);u.x=h.x,u.y=h.y,u.props.w=o,u.props.h=i,"scale"in s.props&&(u.props.scale=c),this.editor.updateShape(u),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},I(OS,"id","pointing"),OS);function is(t,e){const n=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return n?t.clone().snapToGrid(r):t.clone()}class Ox extends ie{static children(){return[cte,ute]}}I(Ox,"id","box"),I(Ox,"initial","idle");function dte(t,e,n){const r=w.useRef(!1),s=w.useCallback(i=>{r.current=i,i?Vr.addOpenMenu(t):Vr.deleteOpenMenu(t),e==null||e(i)},[t,e]),o=U("is menu open",()=>Vr.getOpenMenus().includes(t),[t]);return w.useEffect(()=>(r.current&&(n==null||n("open-menu"),Vr.addOpenMenu(t)),()=>{r.current&&(Vr.deleteOpenMenu(t),Vr.getOpenMenus().forEach(i=>{i.startsWith(t)&&(n==null||n("close-menu"),Vr.deleteOpenMenu(i))}),r.current=!1)}),[t,n]),[o,s]}function Zg(t){const e=z();return U("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function ws(t){const e=z();return w.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===gb){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...lr(c)});return}if(c.button!==0)return;const u=Lp(c.currentTarget);function h(){u.removeEventListener("pointerup",h),hd(u,c)}dd(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...lr(c)}),Ct(c)};let o,i;function a(c){c.isKilled||c.button===0&&(c.clientX===o&&c.clientY===i||(o=c.clientX,i=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:t,...lr(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...lr(c)})}}},[e,t])}function hte(t){const[e,n]=w.useState(()=>({store:Hu(t),opts:t}));if(!zT(e.opts,t)){const r={store:Hu(t),opts:t};return n(r),r.store}return e.store}const fte=20,pte=8;function Rb(t,e=fte){return Math.max(pte,Math.ceil(t/e))}class cl extends Mi{constructor(n){super({...n,isFilled:!1,isClosed:!1});I(this,"_center");I(this,"radius");I(this,"start");I(this,"end");I(this,"largeArcFlag");I(this,"sweepFlag");I(this,"measure");I(this,"angleStart");I(this,"angleEnd");const{center:r,sweepFlag:s,largeArcFlag:o,start:i,end:a}=n;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=x.Angle(r,i),this.angleEnd=x.Angle(r,a),this.radius=x.Dist(r,i),this.measure=vX(this.angleStart,this.angleEnd,s,o),this.start=i,this.end=a,this.sweepFlag=s,this.largeArcFlag=o,this._center=r}nearestPoint(n){const{_center:r,measure:s,radius:o,angleEnd:i,angleStart:a,start:l,end:c}=this,u=xx(s,a,i,r.angle(n));if(u<=0)return l;if(u>=1)return c;const h=r.clone().add(n.clone().sub(r).uni().mul(o));let f,p=1/0,g;for(const m of[l,c,h])g=x.Dist2(n,m),g<p&&(f=m,p=g);if(!f)throw Error("nearest point not found");return f}hitTestLineSegment(n,r){const{_center:s,radius:o,measure:i,angleStart:a,angleEnd:l}=this,c=gd(n,r,s,o);return c===null?!1:c.some(u=>{const h=xx(i,a,l,s.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:n,measure:r,length:s,radius:o,angleStart:i}=this,a=[];for(let l=0,c=Rb(Math.abs(s));l<c+1;l++){const u=l/c*r,h=i+u;a.push(ha(n,o,h))}return a}getSvgPathData(n=!0){const{start:r,end:s,radius:o,largeArcFlag:i,sweepFlag:a}=this;return`${n?`M${r.toFixed()}`:""} A${o} ${o} 0 ${i} ${a} ${s.toFixed()}`}getLength(){return this.measure*this.radius}}class Lb extends Mi{constructor(n){super({isClosed:!0,...n});I(this,"_center");I(this,"radius");I(this,"x");I(this,"y");this.config=n;const{x:r=0,y:s=0,radius:o}=n;this.x=r,this.y=s,this._center=new x(o+r,o+s),this.radius=o}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,s=Fe*r,o=[];for(let i=0,a=Rb(s);i<a;i++){const l=i/a*Fe;o.push(ha(n,r,l))}return o}nearestPoint(n){const{_center:r,radius:s}=this;return r.equals(n)?x.AddXY(r,s,0):r.clone().add(n.clone().sub(r).uni().mul(s))}hitTestLineSegment(n,r,s=0){const{_center:o,radius:i}=this;return gd(n,r,o,i+s)!==null}getSvgPathData(){const{_center:n,radius:r}=this;return`M${n.x+r},${n.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class an extends nc{constructor(n){const{start:r,cp1:s,cp2:o,end:i}=n;super({...n,points:[r,i]});I(this,"a");I(this,"b");I(this,"c");I(this,"d");this.a=r,this.b=s,this.c=o,this.d=i}getVertices(){const n=[],{a:r,b:s,c:o,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;n.push(new x((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*s.x+3*(1-c)*(c*c)*o.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*s.y+3*(1-c)*(c*c)*o.y+c*c*c*i.y))}return n}midPoint(){return an.GetAtT(this,.5)}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}getSvgPathData(n=!0){const{a:r,b:s,c:o,d:i}=this;return`${n?`M ${r.toFixed()} `:""} C${s.toFixed()} ${o.toFixed()} ${i.toFixed()}`}static GetAtT(n,r){const{a:s,b:o,c:i,d:a}=n;return new x((1-r)*(1-r)*(1-r)*s.x+3*((1-r)*(1-r))*r*o.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*s.y+3*((1-r)*(1-r))*r*o.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(n=32){let r,s=this.a,o=0;for(let i=1;i<=n;i++)r=an.GetAtT(this,i/n),o+=x.Dist(s,r),s=r;return o}}class gte extends Mi{constructor(n){super({...n,isClosed:!1,isFilled:!1});I(this,"points");I(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,s=r-2,o=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===s?c:n[i+2],h=l,f=i===0?a:new x(l.x+(c.x-a.x)/6*o,l.y+(c.y-a.y)/6*o),p=i===s?c:new x(c.x-(u.x-l.x)/6*o,c.y-(u.y-l.y)/6*o),g=c;this._segments.push(new an({start:h,cp1:f,cp2:p,end:g}))}}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){const n=this.segments.reduce((r,s)=>r.concat(s.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(s=>s.hitTestLineSegment(n,r))}getSvgPathData(){let n=this.segments.reduce((r,s,o)=>r+s.getSvgPathData(o===0),"");return this.isClosed&&(n+="Z"),n}}class mte extends Mi{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"_edges");this.config=n;const{width:r,height:s}=n;this.w=r,this.h=s}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,s=n.length;r<s;r++){const o=n[r],i=n[(r+1)%s];this._edges.push(new co({start:o,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),s=n/2,o=r/2,i=Math.pow(s-o,2)/Math.pow(s+o,2),a=De*(s+o)*(1+3*i/(10+Math.sqrt(4-3*i))),l=Rb(a),c=Fe/l,u=Math.cos(c),h=Math.sin(c);let f=0,p=1,g=0,m=1;const v=Array(l);for(let y=0;y<l;y++)v[y]=new x(s+s*p,o+o*f),g=h*p+u*f,m=u*p-h*f,f=g,p=m;return v}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.edges)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(s=>s.hitTestLineSegment(n,r))}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{w:n,h:r}=this,s=n/2,o=r/2,i=Math.max(0,s),a=Math.max(0,o);return aj(i,a)}getSvgPathData(n=!1){const{w:r,h:s}=this,o=r/2,i=s/2,a=Math.max(0,o),l=Math.max(0,i);return`${n?`M${o-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class yte extends Mi{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"a");I(this,"b");I(this,"c");I(this,"d");this.config=n;const{width:r,height:s}=n;if(this.w=r,this.h=s,s>r){const o=r/2;this.a=new cl({start:new x(0,o),end:new x(r,o),center:new x(r/2,o),sweepFlag:1,largeArcFlag:1}),this.b=new co({start:new x(r,o),end:new x(r,s-o)}),this.c=new cl({start:new x(r,s-o),end:new x(0,s-o),center:new x(r/2,s-o),sweepFlag:1,largeArcFlag:1}),this.d=new co({start:new x(0,s-o),end:new x(0,o)})}else{const o=s/2;this.a=new cl({start:new x(o,s),end:new x(o,0),center:new x(o,o),sweepFlag:1,largeArcFlag:1}),this.b=new co({start:new x(o,0),end:new x(r-o,0)}),this.c=new cl({start:new x(r-o,0),end:new x(r-o,s),center:new x(r-o,o),sweepFlag:1,largeArcFlag:1}),this.d=new co({start:new x(r-o,s),end:new x(o,s)})}}nearestPoint(n){let r,s=1/0,o,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){const{a:s,b:o,c:i,d:a}=this;return[s,o,i,a].some(l=>l.hitTestLineSegment(n,r))}getVertices(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{h:n,w:r}=this;return n>r?(De*(r/2)+(n-r))*2:(De*(n/2)+(r-n))*2}getSvgPathData(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function Ste({shouldReload:t=!0}={}){uB();for(const e of wp.connectedInstances)await e.close();await Promise.all(Q0().map(e=>hA(e))),cB(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Ste);function vte(t,e="_blank"){$g.openWindow(t,e)}_i("@tldraw/editor","3.8.0-canary.c422debb621c","esm");function QR(){const[t,e]=w.useState(!1);return w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{e(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}const JR=()=>{},e3=w.createContext(null);function xte({onEvent:t,children:e}){return d.jsx(e3.Provider,{value:t??JR,children:e})}function Jt(){return w.useContext(e3)??JR}function se(t,e,{checkForDefaultPrevented:n=!0}={}){return function(s){if(t==null||t(s),n===!1||!s.defaultPrevented)return e==null?void 0:e(s)}}function wte(t,e){const n=w.createContext(e),r=o=>{const{children:i,...a}=o,l=w.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=t+"Provider";function s(o){const i=w.useContext(n);if(i)return i;if(e!==void 0)return e;throw new Error(`\`${o}\` must be used within \`${t}\``)}return[r,s]}function Ws(t,e=[]){let n=[];function r(o,i){const a=w.createContext(i),l=n.length;n=[...n,i];const c=h=>{var y;const{scope:f,children:p,...g}=h,m=((y=f==null?void 0:f[t])==null?void 0:y[l])||a,v=w.useMemo(()=>g,Object.values(g));return d.jsx(m.Provider,{value:v,children:p})};c.displayName=o+"Provider";function u(h,f){var m;const p=((m=f==null?void 0:f[t])==null?void 0:m[l])||a,g=w.useContext(p);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${o}\``)}return[c,u]}const s=()=>{const o=n.map(i=>w.createContext(i));return function(a){const l=(a==null?void 0:a[t])||o;return w.useMemo(()=>({[`__scope${t}`]:{...a,[t]:l}}),[a,l])}};return s.scopeName=t,[r,bte(s,...e)]}function bte(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(o)[`__scope${c}`];return{...a,...h}},{});return w.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return n.scopeName=e.scopeName,n}function GI(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function Qg(...t){return e=>{let n=!1;const r=t.map(s=>{const o=GI(s,e);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let s=0;s<r.length;s++){const o=r[s];typeof o=="function"?o():GI(t[s],null)}}}}function Qe(...t){return w.useCallback(Qg(...t),t)}var fa=w.forwardRef((t,e)=>{const{children:n,...r}=t,s=w.Children.toArray(n),o=s.find(Cte);if(o){const i=o.props.children,a=s.map(l=>l===o?w.Children.count(i)>1?w.Children.only(null):w.isValidElement(i)?i.props.children:null:l);return d.jsx(Dx,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(Dx,{...r,ref:e,children:n})});fa.displayName="Slot";var Dx=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const s=Ite(n);return w.cloneElement(n,{..._te(r,n.props),ref:e?Qg(e,s):s})}return w.Children.count(n)>1?w.Children.only(null):null});Dx.displayName="SlotClone";var Pte=({children:t})=>d.jsx(d.Fragment,{children:t});function Cte(t){return w.isValidElement(t)&&t.type===Pte}function _te(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...a)=>{o(...a),s(...a)}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"&&(n[r]=[s,o].filter(Boolean).join(" "))}return{...t,...n}}function Ite(t){var r,s;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(s=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:s.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var Ete=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ae=Ete.reduce((t,e)=>{const n=w.forwardRef((r,s)=>{const{asChild:o,...i}=r,a=o?fa:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(a,{...i,ref:s})});return n.displayName=`Primitive.${e}`,{...t,[e]:n}},{});function $b(t,e){t&&ba.flushSync(()=>t.dispatchEvent(e))}function Jg(t){const e=t+"CollectionProvider",[n,r]=Ws(e),[s,o]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:g,children:m}=p,v=ke.useRef(null),y=ke.useRef(new Map).current;return d.jsx(s,{scope:g,itemMap:y,collectionRef:v,children:m})};i.displayName=e;const a=t+"CollectionSlot",l=ke.forwardRef((p,g)=>{const{scope:m,children:v}=p,y=o(a,m),S=Qe(g,y.collectionRef);return d.jsx(fa,{ref:S,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=ke.forwardRef((p,g)=>{const{scope:m,children:v,...y}=p,S=ke.useRef(null),b=Qe(g,S),P=o(c,m);return ke.useEffect(()=>(P.itemMap.set(S,{ref:S,...y}),()=>void P.itemMap.delete(S))),d.jsx(fa,{[u]:"",ref:b,children:v})});h.displayName=c;function f(p){const g=o(t+"CollectionConsumer",p);return ke.useCallback(()=>{const v=g.collectionRef.current;if(!v)return[];const y=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(g.itemMap.values()).sort((P,C)=>y.indexOf(P.ref.current)-y.indexOf(C.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},f,r]}var kte=w.createContext(void 0);function Fb(t){const e=w.useContext(kte);return t||e||"ltr"}function qt(t){const e=w.useRef(t);return w.useEffect(()=>{e.current=t}),w.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function Tte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t);w.useEffect(()=>{const r=s=>{s.key==="Escape"&&n(s)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var Mte="DismissableLayer",Rx="dismissableLayer.update",Ate="dismissableLayer.pointerDownOutside",jte="dismissableLayer.focusOutside",VI,t3=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),wd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(t3),[u,h]=w.useState(null),f=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=w.useState({}),g=Qe(e,E=>h(E)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=m.indexOf(v),S=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,P=S>=y,C=Dte(E=>{const k=E.target,D=[...c.branches].some(T=>T.contains(k));!P||D||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},f),_=Rte(E=>{const k=E.target;[...c.branches].some(T=>T.contains(k))||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},f);return Tte(E=>{S===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},f),w.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(VI=f.body.style.pointerEvents,f.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),YI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=VI)}},[u,f,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),YI())},[u,c]),w.useEffect(()=>{const E=()=>p({});return document.addEventListener(Rx,E),()=>document.removeEventListener(Rx,E)},[]),d.jsx(Ae.div,{...l,ref:g,style:{pointerEvents:b?P?"auto":"none":void 0,...t.style},onFocusCapture:se(t.onFocusCapture,_.onFocusCapture),onBlurCapture:se(t.onBlurCapture,_.onBlurCapture),onPointerDownCapture:se(t.onPointerDownCapture,C.onPointerDownCapture)})});wd.displayName=Mte;var Ote="DismissableLayerBranch",n3=w.forwardRef((t,e)=>{const n=w.useContext(t3),r=w.useRef(null),s=Qe(e,r);return w.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),d.jsx(Ae.div,{...t,ref:s})});n3.displayName=Ote;function Dte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1),s=w.useRef(()=>{});return w.useEffect(()=>{const o=a=>{if(a.target&&!r.current){let l=function(){r3(Ate,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",s.current),s.current=l,e.addEventListener("click",s.current,{once:!0})):l()}else e.removeEventListener("click",s.current);r.current=!1},i=window.setTimeout(()=>{e.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(i),e.removeEventListener("pointerdown",o),e.removeEventListener("click",s.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function Rte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1);return w.useEffect(()=>{const s=o=>{o.target&&!r.current&&r3(jte,n,{originalEvent:o},{discrete:!1})};return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function YI(){const t=new CustomEvent(Rx);document.dispatchEvent(t)}function r3(t,e,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?$b(s,o):s.dispatchEvent(o)}var Lte=wd,$te=n3,rS=0;function Nb(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??XI()),document.body.insertAdjacentElement("beforeend",t[1]??XI()),rS++,()=>{rS===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),rS--}},[])}function XI(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var sS="focusScope.autoFocusOnMount",oS="focusScope.autoFocusOnUnmount",qI={bubbles:!1,cancelable:!0},Fte="FocusScope",em=w.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...i}=t,[a,l]=w.useState(null),c=qt(s),u=qt(o),h=w.useRef(null),f=Qe(e,m=>l(m)),p=w.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;w.useEffect(()=>{if(r){let m=function(b){if(p.paused||!a)return;const P=b.target;a.contains(P)?h.current=P:Uo(h.current,{select:!0})},v=function(b){if(p.paused||!a)return;const P=b.relatedTarget;P!==null&&(a.contains(P)||Uo(h.current,{select:!0}))},y=function(b){if(document.activeElement===document.body)for(const C of b)C.removedNodes.length>0&&Uo(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const S=new MutationObserver(y);return a&&S.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),S.disconnect()}}},[r,a,p.paused]),w.useEffect(()=>{if(a){QI.add(p);const m=document.activeElement;if(!a.contains(m)){const y=new CustomEvent(sS,qI);a.addEventListener(sS,c),a.dispatchEvent(y),y.defaultPrevented||(Nte(Kte(s3(a)),{select:!0}),document.activeElement===m&&Uo(a))}return()=>{a.removeEventListener(sS,c),setTimeout(()=>{const y=new CustomEvent(oS,qI);a.addEventListener(oS,u),a.dispatchEvent(y),y.defaultPrevented||Uo(m??document.body,{select:!0}),a.removeEventListener(oS,u),QI.remove(p)},0)}}},[a,c,u,p]);const g=w.useCallback(m=>{if(!n&&!r||p.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,y=document.activeElement;if(v&&y){const S=m.currentTarget,[b,P]=zte(S);b&&P?!m.shiftKey&&y===P?(m.preventDefault(),n&&Uo(b,{select:!0})):m.shiftKey&&y===b&&(m.preventDefault(),n&&Uo(P,{select:!0})):y===S&&m.preventDefault()}},[n,r,p.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:f,onKeyDown:g})});em.displayName=Fte;function Nte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Uo(r,{select:e}),document.activeElement!==n)return}function zte(t){const e=s3(t),n=ZI(e,t),r=ZI(e.reverse(),t);return[n,r]}function s3(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function ZI(t,e){for(const n of t)if(!Bte(n,{upTo:e}))return n}function Bte(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Ute(t){return t instanceof HTMLInputElement&&"select"in t}function Uo(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&Ute(t)&&e&&t.select()}}var QI=Hte();function Hte(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=JI(t,e),t.unshift(e)},remove(e){var n;t=JI(t,e),(n=t[0])==null||n.resume()}}}function JI(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function Kte(t){return t.filter(e=>e.tagName!=="A")}var yi=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},Wte=t6.useId||(()=>{}),Gte=0;function mo(t){const[e,n]=w.useState(Wte());return yi(()=>{t||n(r=>r??String(Gte++))},[t]),t||(e?`radix-${e}`:"")}const Vte=["top","right","bottom","left"],Si=Math.min,or=Math.max,Np=Math.round,bh=Math.floor,Os=t=>({x:t,y:t}),Yte={left:"right",right:"left",bottom:"top",top:"bottom"},Xte={start:"end",end:"start"};function Lx(t,e,n){return or(t,Si(e,n))}function bo(t,e){return typeof t=="function"?t(e):t}function Po(t){return t.split("-")[0]}function ic(t){return t.split("-")[1]}function zb(t){return t==="x"?"y":"x"}function Bb(t){return t==="y"?"height":"width"}function vi(t){return["top","bottom"].includes(Po(t))?"y":"x"}function Ub(t){return zb(vi(t))}function qte(t,e,n){n===void 0&&(n=!1);const r=ic(t),s=Ub(t),o=Bb(s);let i=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(i=zp(i)),[i,zp(i)]}function Zte(t){const e=zp(t);return[$x(t),e,$x(e)]}function $x(t){return t.replace(/start|end/g,e=>Xte[e])}function Qte(t,e,n){const r=["left","right"],s=["right","left"],o=["top","bottom"],i=["bottom","top"];switch(t){case"top":case"bottom":return n?e?s:r:e?r:s;case"left":case"right":return e?o:i;default:return[]}}function Jte(t,e,n,r){const s=ic(t);let o=Qte(Po(t),n==="start",r);return s&&(o=o.map(i=>i+"-"+s),e&&(o=o.concat(o.map($x)))),o}function zp(t){return t.replace(/left|right|bottom|top/g,e=>Yte[e])}function ene(t){return{top:0,right:0,bottom:0,left:0,...t}}function o3(t){return typeof t!="number"?ene(t):{top:t,right:t,bottom:t,left:t}}function Bp(t){const{x:e,y:n,width:r,height:s}=t;return{width:r,height:s,top:n,left:e,right:e+r,bottom:n+s,x:e,y:n}}function eE(t,e,n){let{reference:r,floating:s}=t;const o=vi(e),i=Ub(e),a=Bb(i),l=Po(e),c=o==="y",u=r.x+r.width/2-s.width/2,h=r.y+r.height/2-s.height/2,f=r[a]/2-s[a]/2;let p;switch(l){case"top":p={x:u,y:r.y-s.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:h};break;case"left":p={x:r.x-s.width,y:h};break;default:p={x:r.x,y:r.y}}switch(ic(e)){case"start":p[i]-=f*(n&&c?-1:1);break;case"end":p[i]+=f*(n&&c?-1:1);break}return p}const tne=async(t,e,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=n,a=o.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(e));let c=await i.getElementRects({reference:t,floating:e,strategy:s}),{x:u,y:h}=eE(c,r,l),f=r,p={},g=0;for(let m=0;m<a.length;m++){const{name:v,fn:y}=a[m],{x:S,y:b,data:P,reset:C}=await y({x:u,y:h,initialPlacement:r,placement:f,strategy:s,middlewareData:p,rects:c,platform:i,elements:{reference:t,floating:e}});u=S??u,h=b??h,p={...p,[v]:{...p[v],...P}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(f=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:s}):C.rects),{x:u,y:h}=eE(c,f,l)),m=-1)}return{x:u,y:h,placement:f,strategy:s,middlewareData:p}};async function Ku(t,e){var n;e===void 0&&(e={});const{x:r,y:s,platform:o,rects:i,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:f=!1,padding:p=0}=bo(e,t),g=o3(p),v=a[f?h==="floating"?"reference":"floating":h],y=Bp(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(v)))==null||n?v:v.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),S=h==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,b=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),P=await(o.isElement==null?void 0:o.isElement(b))?await(o.getScale==null?void 0:o.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Bp(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:S,offsetParent:b,strategy:l}):S);return{top:(y.top-C.top+g.top)/P.y,bottom:(C.bottom-y.bottom+g.bottom)/P.y,left:(y.left-C.left+g.left)/P.x,right:(C.right-y.right+g.right)/P.x}}const nne=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:s,rects:o,platform:i,elements:a,middlewareData:l}=e,{element:c,padding:u=0}=bo(t,e)||{};if(c==null)return{};const h=o3(u),f={x:n,y:r},p=Ub(s),g=Bb(p),m=await i.getDimensions(c),v=p==="y",y=v?"top":"left",S=v?"bottom":"right",b=v?"clientHeight":"clientWidth",P=o.reference[g]+o.reference[p]-f[p]-o.floating[g],C=f[p]-o.reference[p],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=_?_[b]:0;(!E||!await(i.isElement==null?void 0:i.isElement(_)))&&(E=a.floating[b]||o.floating[g]);const k=P/2-C/2,D=E/2-m[g]/2-1,T=Si(h[y],D),j=Si(h[S],D),L=T,M=E-m[g]-j,O=E/2-m[g]/2+k,F=Lx(L,O,M),B=!l.arrow&&ic(s)!=null&&O!==F&&o.reference[g]/2-(O<L?T:j)-m[g]/2<0,K=B?O<L?O-L:O-M:0;return{[p]:f[p]+K,data:{[p]:F,centerOffset:O-F-K,...B&&{alignmentOffset:K}},reset:B}}}),rne=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:m=!0,...v}=bo(t,e);if((n=o.arrow)!=null&&n.alignmentOffset)return{};const y=Po(s),S=vi(a),b=Po(a)===a,P=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=f||(b||!m?[zp(a)]:Zte(a)),_=g!=="none";!f&&_&&C.push(...Jte(a,m,g,P));const E=[a,...C],k=await Ku(e,v),D=[];let T=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&D.push(k[y]),h){const O=qte(s,i,P);D.push(k[O[0]],k[O[1]])}if(T=[...T,{placement:s,overflows:D}],!D.every(O=>O<=0)){var j,L;const O=(((j=o.flip)==null?void 0:j.index)||0)+1,F=E[O];if(F)return{data:{index:O,overflows:T},reset:{placement:F}};let B=(L=T.filter(K=>K.overflows[0]<=0).sort((K,R)=>K.overflows[1]-R.overflows[1])[0])==null?void 0:L.placement;if(!B)switch(p){case"bestFit":{var M;const K=(M=T.filter(R=>{if(_){const H=vi(R.placement);return H===S||H==="y"}return!0}).map(R=>[R.placement,R.overflows.filter(H=>H>0).reduce((H,X)=>H+X,0)]).sort((R,H)=>R[1]-H[1])[0])==null?void 0:M[0];K&&(B=K);break}case"initialPlacement":B=a;break}if(s!==B)return{reset:{placement:B}}}return{}}}};function tE(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function nE(t){return Vte.some(e=>t[e]>=0)}const sne=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...s}=bo(t,e);switch(r){case"referenceHidden":{const o=await Ku(e,{...s,elementContext:"reference"}),i=tE(o,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nE(i)}}}case"escaped":{const o=await Ku(e,{...s,altBoundary:!0}),i=tE(o,n.floating);return{data:{escapedOffsets:i,escaped:nE(i)}}}default:return{}}}}};async function one(t,e){const{placement:n,platform:r,elements:s}=t,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=Po(n),a=ic(n),l=vi(n)==="y",c=["left","top"].includes(i)?-1:1,u=o&&l?-1:1,h=bo(e,t);let{mainAxis:f,crossAxis:p,alignmentAxis:g}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*u,y:f*c}:{x:f*c,y:p*u}}const ine=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:s,y:o,placement:i,middlewareData:a}=e,l=await one(e,t);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:o+l.y,data:{...l,placement:i}}}}},ane=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:s}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:y,y:S}=v;return{x:y,y:S}}},...l}=bo(t,e),c={x:n,y:r},u=await Ku(e,l),h=vi(Po(s)),f=zb(h);let p=c[f],g=c[h];if(o){const v=f==="y"?"top":"left",y=f==="y"?"bottom":"right",S=p+u[v],b=p-u[y];p=Lx(S,p,b)}if(i){const v=h==="y"?"top":"left",y=h==="y"?"bottom":"right",S=g+u[v],b=g-u[y];g=Lx(S,g,b)}const m=a.fn({...e,[f]:p,[h]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[f]:o,[h]:i}}}}}},lne=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:s,rects:o,middlewareData:i}=e,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=bo(t,e),u={x:n,y:r},h=vi(s),f=zb(h);let p=u[f],g=u[h];const m=bo(a,e),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=f==="y"?"height":"width",P=o.reference[f]-o.floating[b]+v.mainAxis,C=o.reference[f]+o.reference[b]-v.mainAxis;p<P?p=P:p>C&&(p=C)}if(c){var y,S;const b=f==="y"?"width":"height",P=["top","left"].includes(Po(s)),C=o.reference[h]-o.floating[b]+(P&&((y=i.offset)==null?void 0:y[h])||0)+(P?0:v.crossAxis),_=o.reference[h]+o.reference[b]+(P?0:((S=i.offset)==null?void 0:S[h])||0)-(P?v.crossAxis:0);g<C?g=C:g>_&&(g=_)}return{[f]:p,[h]:g}}}},cne=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,r;const{placement:s,rects:o,platform:i,elements:a}=e,{apply:l=()=>{},...c}=bo(t,e),u=await Ku(e,c),h=Po(s),f=ic(s),p=vi(s)==="y",{width:g,height:m}=o.floating;let v,y;h==="top"||h==="bottom"?(v=h,y=f===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=h,v=f==="end"?"top":"bottom");const S=m-u.top-u.bottom,b=g-u.left-u.right,P=Si(m-u[v],S),C=Si(g-u[y],b),_=!e.middlewareData.shift;let E=P,k=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(k=b),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(E=S),_&&!f){const T=or(u.left,0),j=or(u.right,0),L=or(u.top,0),M=or(u.bottom,0);p?k=g-2*(T!==0||j!==0?T+j:or(u.left,u.right)):E=m-2*(L!==0||M!==0?L+M:or(u.top,u.bottom))}await l({...e,availableWidth:k,availableHeight:E});const D=await i.getDimensions(a.floating);return g!==D.width||m!==D.height?{reset:{rects:!0}}:{}}}};function tm(){return typeof window<"u"}function ac(t){return i3(t)?(t.nodeName||"").toLowerCase():"#document"}function fr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Gs(t){var e;return(e=(i3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function i3(t){return tm()?t instanceof Node||t instanceof fr(t).Node:!1}function as(t){return tm()?t instanceof Element||t instanceof fr(t).Element:!1}function Ns(t){return tm()?t instanceof HTMLElement||t instanceof fr(t).HTMLElement:!1}function rE(t){return!tm()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof fr(t).ShadowRoot}function bd(t){const{overflow:e,overflowX:n,overflowY:r,display:s}=ls(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(s)}function une(t){return["table","td","th"].includes(ac(t))}function nm(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function Hb(t){const e=Kb(),n=as(t)?ls(t):t;return["transform","translate","scale","rotate","perspective"].some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function dne(t){let e=xi(t);for(;Ns(e)&&!Rl(e);){if(Hb(e))return e;if(nm(e))return null;e=xi(e)}return null}function Kb(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Rl(t){return["html","body","#document"].includes(ac(t))}function ls(t){return fr(t).getComputedStyle(t)}function rm(t){return as(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function xi(t){if(ac(t)==="html")return t;const e=t.assignedSlot||t.parentNode||rE(t)&&t.host||Gs(t);return rE(e)?e.host:e}function a3(t){const e=xi(t);return Rl(e)?t.ownerDocument?t.ownerDocument.body:t.body:Ns(e)&&bd(e)?e:a3(e)}function Wu(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const s=a3(t),o=s===((r=t.ownerDocument)==null?void 0:r.body),i=fr(s);if(o){const a=Fx(i);return e.concat(i,i.visualViewport||[],bd(s)?s:[],a&&n?Wu(a):[])}return e.concat(s,Wu(s,[],n))}function Fx(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function l3(t){const e=ls(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Ns(t),o=s?t.offsetWidth:n,i=s?t.offsetHeight:r,a=Np(n)!==o||Np(r)!==i;return a&&(n=o,r=i),{width:n,height:r,$:a}}function Wb(t){return as(t)?t:t.contextElement}function Pl(t){const e=Wb(t);if(!Ns(e))return Os(1);const n=e.getBoundingClientRect(),{width:r,height:s,$:o}=l3(e);let i=(o?Np(n.width):n.width)/r,a=(o?Np(n.height):n.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const hne=Os(0);function c3(t){const e=fr(t);return!Kb()||!e.visualViewport?hne:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function fne(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==fr(t)?!1:e}function pa(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const s=t.getBoundingClientRect(),o=Wb(t);let i=Os(1);e&&(r?as(r)&&(i=Pl(r)):i=Pl(t));const a=fne(o,n,r)?c3(o):Os(0);let l=(s.left+a.x)/i.x,c=(s.top+a.y)/i.y,u=s.width/i.x,h=s.height/i.y;if(o){const f=fr(o),p=r&&as(r)?fr(r):r;let g=f,m=Fx(g);for(;m&&r&&p!==g;){const v=Pl(m),y=m.getBoundingClientRect(),S=ls(m),b=y.left+(m.clientLeft+parseFloat(S.paddingLeft))*v.x,P=y.top+(m.clientTop+parseFloat(S.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=b,c+=P,g=fr(m),m=Fx(g)}}return Bp({width:u,height:h,x:l,y:c})}function Gb(t,e){const n=rm(t).scrollLeft;return e?e.left+n:pa(Gs(t)).left+n}function u3(t,e,n){n===void 0&&(n=!1);const r=t.getBoundingClientRect(),s=r.left+e.scrollLeft-(n?0:Gb(t,r)),o=r.top+e.scrollTop;return{x:s,y:o}}function pne(t){let{elements:e,rect:n,offsetParent:r,strategy:s}=t;const o=s==="fixed",i=Gs(r),a=e?nm(e.floating):!1;if(r===i||a&&o)return n;let l={scrollLeft:0,scrollTop:0},c=Os(1);const u=Os(0),h=Ns(r);if((h||!h&&!o)&&((ac(r)!=="body"||bd(i))&&(l=rm(r)),Ns(r))){const p=pa(r);c=Pl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const f=i&&!h&&!o?u3(i,l,!0):Os(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+f.x,y:n.y*c.y-l.scrollTop*c.y+u.y+f.y}}function gne(t){return Array.from(t.getClientRects())}function mne(t){const e=Gs(t),n=rm(t),r=t.ownerDocument.body,s=or(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=or(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Gb(t);const a=-n.scrollTop;return ls(r).direction==="rtl"&&(i+=or(e.clientWidth,r.clientWidth)-s),{width:s,height:o,x:i,y:a}}function yne(t,e){const n=fr(t),r=Gs(t),s=n.visualViewport;let o=r.clientWidth,i=r.clientHeight,a=0,l=0;if(s){o=s.width,i=s.height;const c=Kb();(!c||c&&e==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:o,height:i,x:a,y:l}}function Sne(t,e){const n=pa(t,!0,e==="fixed"),r=n.top+t.clientTop,s=n.left+t.clientLeft,o=Ns(t)?Pl(t):Os(1),i=t.clientWidth*o.x,a=t.clientHeight*o.y,l=s*o.x,c=r*o.y;return{width:i,height:a,x:l,y:c}}function sE(t,e,n){let r;if(e==="viewport")r=yne(t,n);else if(e==="document")r=mne(Gs(t));else if(as(e))r=Sne(e,n);else{const s=c3(t);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return Bp(r)}function d3(t,e){const n=xi(t);return n===e||!as(n)||Rl(n)?!1:ls(n).position==="fixed"||d3(n,e)}function vne(t,e){const n=e.get(t);if(n)return n;let r=Wu(t,[],!1).filter(a=>as(a)&&ac(a)!=="body"),s=null;const o=ls(t).position==="fixed";let i=o?xi(t):t;for(;as(i)&&!Rl(i);){const a=ls(i),l=Hb(i);!l&&a.position==="fixed"&&(s=null),(o?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||bd(i)&&!l&&d3(t,i))?r=r.filter(u=>u!==i):s=a,i=xi(i)}return e.set(t,r),r}function xne(t){let{element:e,boundary:n,rootBoundary:r,strategy:s}=t;const i=[...n==="clippingAncestors"?nm(e)?[]:vne(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=sE(e,u,s);return c.top=or(h.top,c.top),c.right=Si(h.right,c.right),c.bottom=Si(h.bottom,c.bottom),c.left=or(h.left,c.left),c},sE(e,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function wne(t){const{width:e,height:n}=l3(t);return{width:e,height:n}}function bne(t,e,n){const r=Ns(e),s=Gs(e),o=n==="fixed",i=pa(t,!0,o,e);let a={scrollLeft:0,scrollTop:0};const l=Os(0);if(r||!r&&!o)if((ac(e)!=="body"||bd(s))&&(a=rm(e)),r){const f=pa(e,!0,o,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}else s&&(l.x=Gb(s));const c=s&&!r&&!o?u3(s,a):Os(0),u=i.left+a.scrollLeft-l.x-c.x,h=i.top+a.scrollTop-l.y-c.y;return{x:u,y:h,width:i.width,height:i.height}}function iS(t){return ls(t).position==="static"}function oE(t,e){if(!Ns(t)||ls(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Gs(t)===n&&(n=n.ownerDocument.body),n}function h3(t,e){const n=fr(t);if(nm(t))return n;if(!Ns(t)){let s=xi(t);for(;s&&!Rl(s);){if(as(s)&&!iS(s))return s;s=xi(s)}return n}let r=oE(t,e);for(;r&&une(r)&&iS(r);)r=oE(r,e);return r&&Rl(r)&&iS(r)&&!Hb(r)?n:r||dne(t)||n}const Pne=async function(t){const e=this.getOffsetParent||h3,n=this.getDimensions,r=await n(t.floating);return{reference:bne(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Cne(t){return ls(t).direction==="rtl"}const _ne={convertOffsetParentRelativeRectToViewportRelativeRect:pne,getDocumentElement:Gs,getClippingRect:xne,getOffsetParent:h3,getElementRects:Pne,getClientRects:gne,getDimensions:wne,getScale:Pl,isElement:as,isRTL:Cne};function f3(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Ine(t,e){let n=null,r;const s=Gs(t);function o(){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),o();const c=t.getBoundingClientRect(),{left:u,top:h,width:f,height:p}=c;if(a||e(),!f||!p)return;const g=bh(h),m=bh(s.clientWidth-(u+f)),v=bh(s.clientHeight-(h+p)),y=bh(u),b={rootMargin:-g+"px "+-m+"px "+-v+"px "+-y+"px",threshold:or(0,Si(1,l))||1};let P=!0;function C(_){const E=_[0].intersectionRatio;if(E!==l){if(!P)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!f3(c,t.getBoundingClientRect())&&i(),P=!1}try{n=new IntersectionObserver(C,{...b,root:s.ownerDocument})}catch{n=new IntersectionObserver(C,b)}n.observe(t)}return i(!0),o}function Ene(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Wb(t),u=s||o?[...c?Wu(c):[],...Wu(e)]:[];u.forEach(y=>{s&&y.addEventListener("scroll",n,{passive:!0}),o&&y.addEventListener("resize",n)});const h=c&&a?Ine(c,n):null;let f=-1,p=null;i&&(p=new ResizeObserver(y=>{let[S]=y;S&&S.target===c&&p&&(p.unobserve(e),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var b;(b=p)==null||b.observe(e)})),n()}),c&&!l&&p.observe(c),p.observe(e));let g,m=l?pa(t):null;l&&v();function v(){const y=pa(t);m&&!f3(m,y)&&n(),m=y,g=requestAnimationFrame(v)}return n(),()=>{var y;u.forEach(S=>{s&&S.removeEventListener("scroll",n),o&&S.removeEventListener("resize",n)}),h==null||h(),(y=p)==null||y.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const kne=ine,Tne=ane,Mne=rne,Ane=cne,jne=sne,iE=nne,One=lne,Dne=(t,e,n)=>{const r=new Map,s={platform:_ne,...n},o={...s.platform,_c:r};return tne(t,e,{...s,platform:o})};var pf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Up(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,s;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!Up(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&t.$$typeof)&&!Up(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}function p3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function aE(t,e){const n=p3(t);return Math.round(e*n)/n}function aS(t){const e=w.useRef(t);return pf(()=>{e.current=t}),e}function Rne(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=t,[u,h]=w.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[f,p]=w.useState(r);Up(f,r)||p(r);const[g,m]=w.useState(null),[v,y]=w.useState(null),S=w.useCallback(R=>{R!==_.current&&(_.current=R,m(R))},[]),b=w.useCallback(R=>{R!==E.current&&(E.current=R,y(R))},[]),P=o||g,C=i||v,_=w.useRef(null),E=w.useRef(null),k=w.useRef(u),D=l!=null,T=aS(l),j=aS(s),L=aS(c),M=w.useCallback(()=>{if(!_.current||!E.current)return;const R={placement:e,strategy:n,middleware:f};j.current&&(R.platform=j.current),Dne(_.current,E.current,R).then(H=>{const X={...H,isPositioned:L.current!==!1};O.current&&!Up(k.current,X)&&(k.current=X,ba.flushSync(()=>{h(X)}))})},[f,e,n,j,L]);pf(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,h(R=>({...R,isPositioned:!1})))},[c]);const O=w.useRef(!1);pf(()=>(O.current=!0,()=>{O.current=!1}),[]),pf(()=>{if(P&&(_.current=P),C&&(E.current=C),P&&C){if(T.current)return T.current(P,C,M);M()}},[P,C,M,T,D]);const F=w.useMemo(()=>({reference:_,floating:E,setReference:S,setFloating:b}),[S,b]),B=w.useMemo(()=>({reference:P,floating:C}),[P,C]),K=w.useMemo(()=>{const R={position:n,left:0,top:0};if(!B.floating)return R;const H=aE(B.floating,u.x),X=aE(B.floating,u.y);return a?{...R,transform:"translate("+H+"px, "+X+"px)",...p3(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:X}},[n,a,B.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:M,refs:F,elements:B,floatingStyles:K}),[u,M,F,B,K])}const Lne=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:s}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?iE({element:r.current,padding:s}).fn(n):{}:r?iE({element:r,padding:s}).fn(n):{}}}},$ne=(t,e)=>({...kne(t),options:[t,e]}),Fne=(t,e)=>({...Tne(t),options:[t,e]}),Nne=(t,e)=>({...One(t),options:[t,e]}),zne=(t,e)=>({...Mne(t),options:[t,e]}),Bne=(t,e)=>({...Ane(t),options:[t,e]}),Une=(t,e)=>({...jne(t),options:[t,e]}),Hne=(t,e)=>({...Lne(t),options:[t,e]});var Kne="Arrow",g3=w.forwardRef((t,e)=>{const{children:n,width:r=10,height:s=5,...o}=t;return d.jsx(Ae.svg,{...o,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});g3.displayName=Kne;var Wne=g3;function m3(t){const[e,n]=w.useState(void 0);return yi(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let i,a;if("borderBoxSize"in o){const l=o.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=t.offsetWidth,a=t.offsetHeight;n({width:i,height:a})});return r.observe(t,{box:"border-box"}),()=>r.unobserve(t)}else n(void 0)},[t]),e}var Vb="Popper",[y3,sm]=Ws(Vb),[Gne,S3]=y3(Vb),v3=t=>{const{__scopePopper:e,children:n}=t,[r,s]=w.useState(null);return d.jsx(Gne,{scope:e,anchor:r,onAnchorChange:s,children:n})};v3.displayName=Vb;var x3="PopperAnchor",w3=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...s}=t,o=S3(x3,n),i=w.useRef(null),a=Qe(e,i);return w.useEffect(()=>{o.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ae.div,{...s,ref:a})});w3.displayName=x3;var Yb="PopperContent",[Vne,Yne]=y3(Yb),b3=w.forwardRef((t,e)=>{var Ne,lt,$e,Ye,We,er;const{__scopePopper:n,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:f=!1,updatePositionStrategy:p="optimized",onPlaced:g,...m}=t,v=S3(Yb,n),[y,S]=w.useState(null),b=Qe(e,$t=>S($t)),[P,C]=w.useState(null),_=m3(P),E=(_==null?void 0:_.width)??0,k=(_==null?void 0:_.height)??0,D=r+(o!=="center"?"-"+o:""),T=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},j=Array.isArray(c)?c:[c],L=j.length>0,M={padding:T,boundary:j.filter(qne),altBoundary:L},{refs:O,floatingStyles:F,placement:B,isPositioned:K,middlewareData:R}=Rne({strategy:"fixed",placement:D,whileElementsMounted:(...$t)=>Ene(...$t,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[$ne({mainAxis:s+k,alignmentAxis:i}),l&&Fne({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Nne():void 0,...M}),l&&zne({...M}),Bne({...M,apply:({elements:$t,rects:On,availableWidth:Mt,availableHeight:Ft})=>{const{width:jo,height:Ys}=On.reference,Oo=$t.floating.style;Oo.setProperty("--radix-popper-available-width",`${Mt}px`),Oo.setProperty("--radix-popper-available-height",`${Ft}px`),Oo.setProperty("--radix-popper-anchor-width",`${jo}px`),Oo.setProperty("--radix-popper-anchor-height",`${Ys}px`)}}),P&&Hne({element:P,padding:a}),Zne({arrowWidth:E,arrowHeight:k}),f&&Une({strategy:"referenceHidden",...M})]}),[H,X]=_3(B),te=qt(g);yi(()=>{K&&(te==null||te())},[K,te]);const le=(Ne=R.arrow)==null?void 0:Ne.x,de=(lt=R.arrow)==null?void 0:lt.y,Me=(($e=R.arrow)==null?void 0:$e.centerOffset)!==0,[oe,Ue]=w.useState();return yi(()=>{y&&Ue(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:K?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:oe,"--radix-popper-transform-origin":[(Ye=R.transformOrigin)==null?void 0:Ye.x,(We=R.transformOrigin)==null?void 0:We.y].join(" "),...((er=R.hide)==null?void 0:er.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(Vne,{scope:n,placedSide:H,onArrowChange:C,arrowX:le,arrowY:de,shouldHideArrow:Me,children:d.jsx(Ae.div,{"data-side":H,"data-align":X,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});b3.displayName=Yb;var P3="PopperArrow",Xne={top:"bottom",right:"left",bottom:"top",left:"right"},C3=w.forwardRef(function(e,n){const{__scopePopper:r,...s}=e,o=Yne(P3,r),i=Xne[o.placedSide];return d.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:d.jsx(Wne,{...s,ref:n,style:{...s.style,display:"block"}})})});C3.displayName=P3;function qne(t){return t!==null}var Zne=t=>({name:"transformOrigin",options:t,fn(e){var v,y,S;const{placement:n,rects:r,middlewareData:s}=e,i=((v=s.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:t.arrowWidth,l=i?0:t.arrowHeight,[c,u]=_3(n),h={start:"0%",center:"50%",end:"100%"}[u],f=(((y=s.arrow)==null?void 0:y.x)??0)+a/2,p=(((S=s.arrow)==null?void 0:S.y)??0)+l/2;let g="",m="";return c==="bottom"?(g=i?h:`${f}px`,m=`${-l}px`):c==="top"?(g=i?h:`${f}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?h:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?h:`${p}px`),{data:{x:g,y:m}}}});function _3(t){const[e,n="center"]=t.split("-");return[e,n]}var Xb=v3,qb=w3,I3=b3,E3=C3,Qne="Portal",Pd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[s,o]=w.useState(!1);yi(()=>o(!0),[]);const i=n||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?d8.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});Pd.displayName=Qne;function Jne(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var ds=t=>{const{present:e,children:n}=t,r=ere(e),s=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),o=Qe(r.ref,tre(s));return typeof n=="function"||r.isPresent?w.cloneElement(s,{ref:o}):null};ds.displayName="Presence";function ere(t){const[e,n]=w.useState(),r=w.useRef({}),s=w.useRef(t),o=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Jne(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=Ph(r.current);o.current=a==="mounted"?c:"none"},[a]),yi(()=>{const c=r.current,u=s.current;if(u!==t){const f=o.current,p=Ph(c);t?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&f!==p?"ANIMATION_OUT":"UNMOUNT"),s.current=t}},[t,l]),yi(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=p=>{const m=Ph(r.current).includes(p.animationName);if(p.target===e&&m&&(l("ANIMATION_END"),!s.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",c=u.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},f=p=>{p.target===e&&(o.current=Ph(r.current))};return e.addEventListener("animationstart",f),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{u.clearTimeout(c),e.removeEventListener("animationstart",f),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:w.useCallback(c=>{c&&(r.current=getComputedStyle(c)),n(c)},[])}}function Ph(t){return(t==null?void 0:t.animationName)||"none"}function tre(t){var r,s;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(s=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:s.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}function ji({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,s]=nre({defaultProp:e,onChange:n}),o=t!==void 0,i=o?t:r,a=qt(n),l=w.useCallback(c=>{if(o){const h=typeof c=="function"?c(t):c;h!==t&&a(h)}else s(c)},[o,t,s,a]);return[i,l]}function nre({defaultProp:t,onChange:e}){const n=w.useState(t),[r]=n,s=w.useRef(r),o=qt(e);return w.useEffect(()=>{s.current!==r&&(o(r),s.current=r)},[r,s,o]),n}var lS="rovingFocusGroup.onEntryFocus",rre={bubbles:!1,cancelable:!0},om="RovingFocusGroup",[Nx,k3,sre]=Jg(om),[ore,T3]=Ws(om,[sre]),[ire,are]=ore(om),M3=w.forwardRef((t,e)=>d.jsx(Nx.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Nx.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(lre,{...t,ref:e})})}));M3.displayName=om;var lre=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:s=!1,dir:o,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=t,f=w.useRef(null),p=Qe(e,f),g=Fb(o),[m=null,v]=ji({prop:i,defaultProp:a,onChange:l}),[y,S]=w.useState(!1),b=qt(c),P=k3(n),C=w.useRef(!1),[_,E]=w.useState(0);return w.useEffect(()=>{const k=f.current;if(k)return k.addEventListener(lS,b),()=>k.removeEventListener(lS,b)},[b]),d.jsx(ire,{scope:n,orientation:r,dir:g,loop:s,currentTabStopId:m,onItemFocus:w.useCallback(k=>v(k),[v]),onItemShiftTab:w.useCallback(()=>S(!0),[]),onFocusableItemAdd:w.useCallback(()=>E(k=>k+1),[]),onFocusableItemRemove:w.useCallback(()=>E(k=>k-1),[]),children:d.jsx(Ae.div,{tabIndex:y||_===0?-1:0,"data-orientation":r,...h,ref:p,style:{outline:"none",...t.style},onMouseDown:se(t.onMouseDown,()=>{C.current=!0}),onFocus:se(t.onFocus,k=>{const D=!C.current;if(k.target===k.currentTarget&&D&&!y){const T=new CustomEvent(lS,rre);if(k.currentTarget.dispatchEvent(T),!T.defaultPrevented){const j=P().filter(B=>B.focusable),L=j.find(B=>B.active),M=j.find(B=>B.id===m),F=[L,M,...j].filter(Boolean).map(B=>B.ref.current);O3(F,u)}}C.current=!1}),onBlur:se(t.onBlur,()=>S(!1))})})}),A3="RovingFocusGroupItem",j3=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:s=!1,tabStopId:o,...i}=t,a=mo(),l=o||a,c=are(A3,n),u=c.currentTabStopId===l,h=k3(n),{onFocusableItemAdd:f,onFocusableItemRemove:p}=c;return w.useEffect(()=>{if(r)return f(),()=>p()},[r,f,p]),d.jsx(Nx.ItemSlot,{scope:n,id:l,focusable:r,active:s,children:d.jsx(Ae.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:e,onMouseDown:se(t.onMouseDown,g=>{r?c.onItemFocus(l):g.preventDefault()}),onFocus:se(t.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(t.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){c.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const m=dre(g,c.orientation,c.dir);if(m!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let y=h().filter(S=>S.focusable).map(S=>S.ref.current);if(m==="last")y.reverse();else if(m==="prev"||m==="next"){m==="prev"&&y.reverse();const S=y.indexOf(g.currentTarget);y=c.loop?hre(y,S+1):y.slice(S+1)}setTimeout(()=>O3(y))}})})})});j3.displayName=A3;var cre={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ure(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function dre(t,e,n){const r=ure(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return cre[r]}function O3(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function hre(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var fre=M3,pre=j3,gre=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},Fa=new WeakMap,Ch=new WeakMap,_h={},cS=0,D3=function(t){return t&&(t.host||D3(t.parentNode))},mre=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=D3(n);return r&&t.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",t,". Doing nothing"),null)}).filter(function(n){return!!n})},yre=function(t,e,n,r){var s=mre(e,Array.isArray(t)?t:[t]);_h[n]||(_h[n]=new WeakMap);var o=_h[n],i=[],a=new Set,l=new Set(s),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};s.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(f){if(a.has(f))u(f);else try{var p=f.getAttribute(r),g=p!==null&&p!=="false",m=(Fa.get(f)||0)+1,v=(o.get(f)||0)+1;Fa.set(f,m),o.set(f,v),i.push(f),m===1&&g&&Ch.set(f,!0),v===1&&f.setAttribute(n,"true"),g||f.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",f,y)}})};return u(e),a.clear(),cS++,function(){i.forEach(function(h){var f=Fa.get(h)-1,p=o.get(h)-1;Fa.set(h,f),o.set(h,p),f||(Ch.has(h)||h.removeAttribute(r),Ch.delete(h)),p||h.removeAttribute(n)}),cS--,cS||(Fa=new WeakMap,Fa=new WeakMap,Ch=new WeakMap,_h={})}},Zb=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),s=gre(t);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),yre(r,s,n,"aria-hidden")):function(){return null}},Cs=function(){return Cs=Object.assign||function(e){for(var n,r=1,s=arguments.length;r<s;r++){n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Cs.apply(this,arguments)};function R3(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(n[r[s]]=t[r[s]]);return n}function Sre(t,e,n){if(n||arguments.length===2)for(var r=0,s=e.length,o;r<s;r++)(o||!(r in e))&&(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}var gf="right-scroll-bar-position",mf="width-before-scroll-bar",vre="with-scroll-bars-hidden",xre="--removed-body-scroll-bar-size";function uS(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function wre(t,e){var n=w.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var s=n.value;s!==r&&(n.value=r,n.callback(r,s))}}}})[0];return n.callback=e,n.facade}var bre=typeof window<"u"?w.useLayoutEffect:w.useEffect,lE=new WeakMap;function Pre(t,e){var n=wre(null,function(r){return t.forEach(function(s){return uS(s,r)})});return bre(function(){var r=lE.get(n);if(r){var s=new Set(r),o=new Set(t),i=n.current;s.forEach(function(a){o.has(a)||uS(a,null)}),o.forEach(function(a){s.has(a)||uS(a,i)})}lE.set(n,t)},[t]),n}function Cre(t){return t}function _re(t,e){e===void 0&&(e=Cre);var n=[],r=!1,s={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]:t},useMedium:function(o){var i=e(o,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(a){return o(a)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(o),i=n}var l=function(){var u=i;i=[],u.forEach(o)},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 s}function Ire(t){t===void 0&&(t={});var e=_re(null);return e.options=Cs({async:!0,ssr:!1},t),e}var L3=function(t){var e=t.sideCar,n=R3(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return w.createElement(r,Cs({},n))};L3.isSideCarExport=!0;function Ere(t,e){return t.useMedium(e),L3}var $3=Ire(),dS=function(){},im=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:dS,onWheelCapture:dS,onTouchMoveCapture:dS}),s=r[0],o=r[1],i=t.forwardProps,a=t.children,l=t.className,c=t.removeScrollBar,u=t.enabled,h=t.shards,f=t.sideCar,p=t.noIsolation,g=t.inert,m=t.allowPinchZoom,v=t.as,y=v===void 0?"div":v,S=t.gapMode,b=R3(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=f,C=Pre([n,e]),_=Cs(Cs({},b),s);return w.createElement(w.Fragment,null,u&&w.createElement(P,{sideCar:$3,removeScrollBar:c,shards:h,noIsolation:p,inert:g,setCallbacks:o,allowPinchZoom:!!m,lockRef:n,gapMode:S}),i?w.cloneElement(w.Children.only(a),Cs(Cs({},_),{ref:C})):w.createElement(y,Cs({},_,{className:l,ref:C}),a))});im.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};im.classNames={fullWidth:mf,zeroRight:gf};var kre=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Tre(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=kre();return e&&t.setAttribute("nonce",e),t}function Mre(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Are(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var jre=function(){var t=0,e=null;return{add:function(n){t==0&&(e=Tre())&&(Mre(e,n),Are(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Ore=function(){var t=jre();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},F3=function(){var t=Ore(),e=function(n){var r=n.styles,s=n.dynamic;return t(r,s),null};return e},Dre={left:0,top:0,right:0,gap:0},hS=function(t){return parseInt(t||"",10)||0},Rre=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],s=e[t==="padding"?"paddingRight":"marginRight"];return[hS(n),hS(r),hS(s)]},Lre=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Dre;var e=Rre(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},$re=F3(),Cl="data-scroll-locked",Fre=function(t,e,n,r){var s=t.left,o=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
|
|
195
|
+
}`;return d.jsx("style",{children:n})}),tte=[],nte=[],rte=[],ste="tl-container",ote=w.memo(function({store:e,components:n,className:r,user:s,options:o,...i}){const[a,l]=w.useState(null),c=w.useMemo(()=>s??Uj(),[s]),u=(n==null?void 0:n.ErrorFallback)===void 0?Oj:n==null?void 0:n.ErrorFallback,h={...i,shapeUtils:i.shapeUtils??tte,bindingUtils:i.bindingUtils??nte,tools:i.tools??rte,components:n,options:tc(o)};return d.jsx("div",{ref:l,"data-tldraw":oj,draggable:!1,className:ce(`${ste} tl-theme__light`,r),onPointerDown:Ct,tabIndex:-1,children:d.jsx(Uu,{fallback:u,onError:f=>v0(f,{tags:{origin:"react.tldraw-before-app"}}),children:a&&d.jsx(Gee,{licenseKey:i.licenseKey,children:d.jsx(hj,{container:a,children:d.jsx(AZ,{overrides:n,children:e?e instanceof eb?d.jsx(XR,{...h,store:e,user:c}):d.jsx(YR,{...h,store:e,user:c}):d.jsx(ite,{...h,store:e,user:c})})})})})})});function ite(t){const{defaultName:e,snapshot:n,initialData:r,shapeUtils:s,bindingUtils:o,persistenceKey:i,sessionId:a,user:l,assets:c,migrations:u}=t,h=$ee({shapeUtils:s,bindingUtils:o,initialData:r,persistenceKey:i,sessionId:a,defaultName:e,snapshot:n,assets:c,migrations:u});return d.jsx(YR,{...t,store:h,user:l})}const YR=w.memo(function({store:e,user:n,...r}){const s=Tt();w.useLayoutEffect(()=>{n.userPreferences.get().colorScheme==="dark"&&(s.classList.remove("tl-theme__light"),s.classList.add("tl-theme__dark"))},[s,n]);const{LoadingScreen:o}=st();switch(e.status){case"error":throw e.error;case"loading":return o?d.jsx(o,{}):null}return d.jsx(XR,{...r,store:e.store,user:n})}),nS=()=>document.location.search.includes("tldraw_preserve_focus");function XR({onMount:t,children:e,store:n,tools:r,shapeUtils:s,bindingUtils:o,user:i,initialState:a,autoFocus:l=!0,inferDarkMode:c,cameraOptions:u,options:h,licenseKey:f,deepLinks:p,isShapeHidden:g}){const{ErrorFallback:m}=st(),v=Tt(),[y,S]=GR(null),b=w.useRef(null),P=tc(p===!0?{}:p),C=w.useRef({autoFocus:l&&!nS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P});w.useLayoutEffect(()=>{C.current={autoFocus:l&&!nS(),inferDarkMode:c,initialState:a,cameraOptions:u,deepLinks:P}},[l,c,a,u,P]),w.useLayoutEffect(()=>{const{autoFocus:k,inferDarkMode:D,initialState:T,cameraOptions:j,deepLinks:L}=C.current,M=new Q({store:n,shapeUtils:s,bindingUtils:o,tools:r,getContainer:()=>v,user:i,initialState:T,autoFocus:k,inferDarkMode:D,cameraOptions:j,options:h,licenseKey:f,isShapeHidden:g});return M.updateViewportScreenBounds(b.current??v),L&&(L!=null&&L.getUrl?M.navigateToDeepLink({...L,url:L.getUrl(M)}):M.navigateToDeepLink(L)),S(M),()=>{M.dispose()}},[o,v,h,s,n,r,i,S,f,g]),w.useLayoutEffect(()=>{if(y&&P)return y.registerDeepLinkListener(P)},[y,P]),w.useLayoutEffect(()=>{y&&u&&y.setCameraOptions(u)},[y,u]);const _=w.useSyncExternalStore(w.useCallback(k=>y?(y.on("crash",k),()=>y.off("crash",k)):()=>{},[y]),()=>(y==null?void 0:y.getCrashingError())??null);w.useEffect(function(){if(!y)return;function D(){y&&y.focus()}function T(){y&&y.blur()}if(l&&nS())return y.getContainer().addEventListener("pointerdown",D),document.body.addEventListener("pointerdown",T),()=>{var j;(j=y.getContainer())==null||j.removeEventListener("pointerdown",D),document.body.removeEventListener("pointerdown",T)}},[y,l]);const{Canvas:E}=st();return y?d.jsx(Uu,{fallback:m,onError:k=>y.annotateError(k,{origin:"react.tldraw",willCrashApp:!0}),children:_?d.jsx(lte,{crashingError:_}):d.jsx(fb,{editor:y,children:d.jsxs(ate,{onMount:t,children:[e??(E?d.jsx(E,{},y.contextId):null),d.jsx(Qee,{})]})})}):d.jsx("div",{className:"tl-canvas",ref:b})}function ate({children:t,onMount:e}){return Fee(),Pee(),Cee(),_ee(),ZR(n=>{const r=n.store.props.onMount(n),s=e==null?void 0:e(n);return()=>{r==null||r(),s==null||s()}}),t}function lte({crashingError:t}){throw t}function Db({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function qR({children:t}){return d.jsx("div",{className:"tl-loading",children:t})}function ZR(t){const e=z(),n=Hg(r=>{let s;return r.run(()=>{s=t==null?void 0:t(r),r.emit("mount")},{history:"ignore"}),window.tldrawReady=!0,s});ke.useLayoutEffect(()=>{if(e)return n==null?void 0:n(e)},[e,n])}function hi({children:t,className:e="",...n}){return d.jsx("div",{...n,className:ce("tl-html-container",e),children:t})}class ff{constructor(e){this.editor=e}}I(ff,"props"),I(ff,"migrations"),I(ff,"type");function qg(t,e,n={}){const{newPoint:r,handle:s,scaleX:o,scaleY:i}=e,{minWidth:a=1,maxWidth:l=1/0,minHeight:c=1,maxHeight:u=1/0}=n;let h=t.props.w*o,f=t.props.h*i;const p=new x(0,0);if(h>0){if(h<a){switch(s){case"top_left":case"left":case"bottom_left":{p.x=h-a;break}case"top":case"bottom":{p.x=(h-a)/2;break}default:p.x=0}h=a}}else if(p.x=h,h=-h,h<a){switch(s){case"top_left":case"left":case"bottom_left":{p.x=-h;break}default:p.x=-a}h=a}if(f>0){if(f<c){switch(s){case"top_left":case"top":case"top_right":{p.y=f-c;break}case"right":case"left":{p.y=(f-c)/2;break}default:p.y=0}f=c}}else if(p.y=f,f=-f,f<c){switch(s){case"top_left":case"top":case"top_right":{p.y=-f;break}default:p.y=-c}f=c}const{x:g,y:m}=p.rot(t.rotation).add(r);return{...t,x:g,y:m,props:{w:Math.min(l,h),h:Math.min(u,f)}}}class oc extends ss{getGeometry(e){return new Fs({width:e.props.w,height:e.props.h,isFilled:!0})}onResize(e,n){return qg(e,n)}getHandleSnapGeometry(e){return{points:this.getGeometry(e).bounds.cornersAndCenter}}getInterpolatedProps(e,n,r){return{...n.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}var jS;let cte=(jS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onCancel(){this.editor.setCurrentTool("select")}},I(jS,"id","idle"),jS);var OS;let ute=(OS=class extends ie{onPointerMove(e){if(this.editor.inputs.isDragging){const{originPagePoint:n}=this.editor.inputs,r=this.parent.shapeType,s=Ke(),o=this.editor.markHistoryStoppingPoint(`creating_box:${s}`),i=is(n,this.editor);this.editor.createShapes([{id:s,type:r,x:i.x,y:i.y,props:{w:1,h:1}}]).select(s);const a=this.parent;this.editor.setCurrentTool("select.resizing",{...e,target:"selection",handle:"bottom_right",isCreating:!0,creatingMarkId:o,creationCursorOffset:{x:1,y:1},onInteractionEnd:this.parent.id,onCreate:a.onCreate?l=>{var c;return(c=a.onCreate)==null?void 0:c.call(a,l)}:void 0})}}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}complete(){const{originPagePoint:e}=this.editor.inputs,n=this.parent.shapeType,r=Ke();this.editor.markHistoryStoppingPoint(`creating_box:${r}`),this.editor.createShapes([{id:r,type:n,x:e.x,y:e.y}]);const s=this.editor.getShape(r);if(!s){this.cancel();return}let{w:o,h:i}=s.props;const a=new x(o/2,i/2),l=this.editor.getShapeParentTransform(s);l&&a.rot(-l.rotation());let c=1;this.editor.user.getIsDynamicResizeMode()&&(c=1/this.editor.getZoomLevel(),o*=c,i*=c,a.mul(c));const u=nt(s),h=is(new x(s.x-a.x,s.y-a.y),this.editor);u.x=h.x,u.y=h.y,u.props.w=o,u.props.h=i,"scale"in s.props&&(u.props.scale=c),this.editor.updateShape(u),this.editor.setSelectedShapes([r]),this.editor.getInstanceState().isToolLocked?this.parent.transition("idle"):this.editor.setCurrentTool("select.idle")}cancel(){this.parent.transition("idle")}},I(OS,"id","pointing"),OS);function is(t,e){const n=e.getInstanceState().isGridMode,r=e.getDocumentSettings().gridSize;return n?t.clone().snapToGrid(r):t.clone()}class Ox extends ie{static children(){return[cte,ute]}}I(Ox,"id","box"),I(Ox,"initial","idle");function dte(t,e,n){const r=w.useRef(!1),s=w.useCallback(i=>{r.current=i,i?Vr.addOpenMenu(t):Vr.deleteOpenMenu(t),e==null||e(i)},[t,e]),o=U("is menu open",()=>Vr.getOpenMenus().includes(t),[t]);return w.useEffect(()=>(r.current&&(n==null||n("open-menu"),Vr.addOpenMenu(t)),()=>{r.current&&(Vr.deleteOpenMenu(t),Vr.getOpenMenus().forEach(i=>{i.startsWith(t)&&(n==null||n("close-menu"),Vr.deleteOpenMenu(i))}),r.current=!1)}),[t,n]),[o,s]}function Zg(t){const e=z();return U("isEditing",()=>e.getEditingShapeId()===t,[e,t])}function ws(t){const e=z();return w.useMemo(function(){const s=c=>{if(c.isKilled)return;if(c.button===gb){e.dispatch({type:"pointer",target:"selection",handle:t,name:"right_click",...lr(c)});return}if(c.button!==0)return;const u=Lp(c.currentTarget);function h(){u.removeEventListener("pointerup",h),hd(u,c)}dd(u,c),u.addEventListener("pointerup",h),e.dispatch({name:"pointer_down",type:"pointer",target:"selection",handle:t,...lr(c)}),Ct(c)};let o,i;function a(c){c.isKilled||c.button===0&&(c.clientX===o&&c.clientY===i||(o=c.clientX,i=c.clientY,e.dispatch({name:"pointer_move",type:"pointer",target:"selection",handle:t,...lr(c)})))}return{onPointerDown:s,onPointerMove:a,onPointerUp:c=>{c.isKilled||c.button===0&&e.dispatch({name:"pointer_up",type:"pointer",target:"selection",handle:t,...lr(c)})}}},[e,t])}function hte(t){const[e,n]=w.useState(()=>({store:Hu(t),opts:t}));if(!zT(e.opts,t)){const r={store:Hu(t),opts:t};return n(r),r.store}return e.store}const fte=20,pte=8;function Rb(t,e=fte){return Math.max(pte,Math.ceil(t/e))}class cl extends Mi{constructor(n){super({...n,isFilled:!1,isClosed:!1});I(this,"_center");I(this,"radius");I(this,"start");I(this,"end");I(this,"largeArcFlag");I(this,"sweepFlag");I(this,"measure");I(this,"angleStart");I(this,"angleEnd");const{center:r,sweepFlag:s,largeArcFlag:o,start:i,end:a}=n;if(i.equals(a))throw Error("Arc must have different start and end points.");this.angleStart=x.Angle(r,i),this.angleEnd=x.Angle(r,a),this.radius=x.Dist(r,i),this.measure=vX(this.angleStart,this.angleEnd,s,o),this.start=i,this.end=a,this.sweepFlag=s,this.largeArcFlag=o,this._center=r}nearestPoint(n){const{_center:r,measure:s,radius:o,angleEnd:i,angleStart:a,start:l,end:c}=this,u=xx(s,a,i,r.angle(n));if(u<=0)return l;if(u>=1)return c;const h=r.clone().add(n.clone().sub(r).uni().mul(o));let f,p=1/0,g;for(const m of[l,c,h])g=x.Dist2(n,m),g<p&&(f=m,p=g);if(!f)throw Error("nearest point not found");return f}hitTestLineSegment(n,r){const{_center:s,radius:o,measure:i,angleStart:a,angleEnd:l}=this,c=gd(n,r,s,o);return c===null?!1:c.some(u=>{const h=xx(i,a,l,s.angle(u));return h>=0&&h<=1})}getVertices(){const{_center:n,measure:r,length:s,radius:o,angleStart:i}=this,a=[];for(let l=0,c=Rb(Math.abs(s));l<c+1;l++){const u=l/c*r,h=i+u;a.push(ha(n,o,h))}return a}getSvgPathData(n=!0){const{start:r,end:s,radius:o,largeArcFlag:i,sweepFlag:a}=this;return`${n?`M${r.toFixed()}`:""} A${o} ${o} 0 ${i} ${a} ${s.toFixed()}`}getLength(){return this.measure*this.radius}}class Lb extends Mi{constructor(n){super({isClosed:!0,...n});I(this,"_center");I(this,"radius");I(this,"x");I(this,"y");this.config=n;const{x:r=0,y:s=0,radius:o}=n;this.x=r,this.y=s,this._center=new x(o+r,o+s),this.radius=o}getBounds(){return new Z(this.x,this.y,this.radius*2,this.radius*2)}getVertices(){const{_center:n,radius:r}=this,s=Fe*r,o=[];for(let i=0,a=Rb(s);i<a;i++){const l=i/a*Fe;o.push(ha(n,r,l))}return o}nearestPoint(n){const{_center:r,radius:s}=this;return r.equals(n)?x.AddXY(r,s,0):r.clone().add(n.clone().sub(r).uni().mul(s))}hitTestLineSegment(n,r,s=0){const{_center:o,radius:i}=this;return gd(n,r,o,i+s)!==null}getSvgPathData(){const{_center:n,radius:r}=this;return`M${n.x+r},${n.y} a${r},${r} 0 1,0 ${r*2},0a${r},${r} 0 1,0 -${r*2},0`}}class an extends nc{constructor(n){const{start:r,cp1:s,cp2:o,end:i}=n;super({...n,points:[r,i]});I(this,"a");I(this,"b");I(this,"c");I(this,"d");this.a=r,this.b=s,this.c=o,this.d=i}getVertices(){const n=[],{a:r,b:s,c:o,d:i}=this;for(let a=0,l=10;a<=l;a++){const c=a/l;n.push(new x((1-c)*(1-c)*(1-c)*r.x+3*((1-c)*(1-c))*c*s.x+3*(1-c)*(c*c)*o.x+c*c*c*i.x,(1-c)*(1-c)*(1-c)*r.y+3*((1-c)*(1-c))*c*s.y+3*(1-c)*(c*c)*o.y+c*c*c*i.y))}return n}midPoint(){return an.GetAtT(this,.5)}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}getSvgPathData(n=!0){const{a:r,b:s,c:o,d:i}=this;return`${n?`M ${r.toFixed()} `:""} C${s.toFixed()} ${o.toFixed()} ${i.toFixed()}`}static GetAtT(n,r){const{a:s,b:o,c:i,d:a}=n;return new x((1-r)*(1-r)*(1-r)*s.x+3*((1-r)*(1-r))*r*o.x+3*(1-r)*(r*r)*i.x+r*r*r*a.x,(1-r)*(1-r)*(1-r)*s.y+3*((1-r)*(1-r))*r*o.y+3*(1-r)*(r*r)*i.y+r*r*r*a.y)}getLength(n=32){let r,s=this.a,o=0;for(let i=1;i<=n;i++)r=an.GetAtT(this,i/n),o+=x.Dist(s,r),s=r;return o}}class gte extends Mi{constructor(n){super({...n,isClosed:!1,isFilled:!1});I(this,"points");I(this,"_segments");const{points:r}=n;this.points=r}get segments(){if(!this._segments){this._segments=[];const{points:n}=this,r=n.length,s=r-2,o=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===s?c:n[i+2],h=l,f=i===0?a:new x(l.x+(c.x-a.x)/6*o,l.y+(c.y-a.y)/6*o),p=i===s?c:new x(c.x-(u.x-l.x)/6*o,c.y-(u.y-l.y)/6*o),g=c;this._segments.push(new an({start:h,cp1:f,cp2:p,end:g}))}}return this._segments}getLength(){return this.segments.reduce((n,r)=>n+r.length,0)}getVertices(){const n=this.segments.reduce((r,s)=>r.concat(s.vertices),[]);return n.push(this.points[this.points.length-1]),n}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.segments)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.segments.some(s=>s.hitTestLineSegment(n,r))}getSvgPathData(){let n=this.segments.reduce((r,s,o)=>r+s.getSvgPathData(o===0),"");return this.isClosed&&(n+="Z"),n}}class mte extends Mi{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"_edges");this.config=n;const{width:r,height:s}=n;this.w=r,this.h=s}get edges(){if(!this._edges){const{vertices:n}=this;this._edges=[];for(let r=0,s=n.length;r<s;r++){const o=n[r],i=n[(r+1)%s];this._edges.push(new co({start:o,end:i}))}}return this._edges}getVertices(){const n=Math.max(1,this.w),r=Math.max(1,this.h),s=n/2,o=r/2,i=Math.pow(s-o,2)/Math.pow(s+o,2),a=De*(s+o)*(1+3*i/(10+Math.sqrt(4-3*i))),l=Rb(a),c=Fe/l,u=Math.cos(c),h=Math.sin(c);let f=0,p=1,g=0,m=1;const v=Array(l);for(let y=0;y<l;y++)v[y]=new x(s+s*p,o+o*f),g=h*p+u*f,m=u*p-h*f,f=g,p=m;return v}nearestPoint(n){let r,s=1/0,o,i;for(const a of this.edges)i=a.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){return this.edges.some(s=>s.hitTestLineSegment(n,r))}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{w:n,h:r}=this,s=n/2,o=r/2,i=Math.max(0,s),a=Math.max(0,o);return aj(i,a)}getSvgPathData(n=!1){const{w:r,h:s}=this,o=r/2,i=s/2,a=Math.max(0,o),l=Math.max(0,i);return`${n?`M${o-a},${i}`:""} a${a},${l},0,1,1,${a*2},0a${a},${l},0,1,1,-${a*2},0`}}class yte extends Mi{constructor(n){super({...n,isClosed:!0});I(this,"w");I(this,"h");I(this,"a");I(this,"b");I(this,"c");I(this,"d");this.config=n;const{width:r,height:s}=n;if(this.w=r,this.h=s,s>r){const o=r/2;this.a=new cl({start:new x(0,o),end:new x(r,o),center:new x(r/2,o),sweepFlag:1,largeArcFlag:1}),this.b=new co({start:new x(r,o),end:new x(r,s-o)}),this.c=new cl({start:new x(r,s-o),end:new x(0,s-o),center:new x(r/2,s-o),sweepFlag:1,largeArcFlag:1}),this.d=new co({start:new x(0,s-o),end:new x(0,o)})}else{const o=s/2;this.a=new cl({start:new x(o,s),end:new x(o,0),center:new x(o,o),sweepFlag:1,largeArcFlag:1}),this.b=new co({start:new x(o,0),end:new x(r-o,0)}),this.c=new cl({start:new x(r-o,0),end:new x(r-o,s),center:new x(r-o,o),sweepFlag:1,largeArcFlag:1}),this.d=new co({start:new x(r-o,s),end:new x(o,s)})}}nearestPoint(n){let r,s=1/0,o,i;const{a,b:l,c,d:u}=this;for(const h of[a,l,c,u])i=h.nearestPoint(n),o=x.Dist2(i,n),o<s&&(r=i,s=o);if(!r)throw Error("nearest point not found");return r}hitTestLineSegment(n,r){const{a:s,b:o,c:i,d:a}=this;return[s,o,i,a].some(l=>l.hitTestLineSegment(n,r))}getVertices(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].reduce((i,a)=>(i.push(...a.vertices),i),[])}getBounds(){return new Z(0,0,this.w,this.h)}getLength(){const{h:n,w:r}=this;return n>r?(De*(r/2)+(n-r))*2:(De*(n/2)+(r-n))*2}getSvgPathData(){const{a:n,b:r,c:s,d:o}=this;return[n,r,s,o].map((i,a)=>i.getSvgPathData(a===0)).join(" ")+" Z"}}async function Ste({shouldReload:t=!0}={}){uB();for(const e of wp.connectedInstances)await e.close();await Promise.all(Q0().map(e=>hA(e))),cB(),t&&window.location.reload()}typeof window<"u"&&(window.__tldraw__hardReset=Ste);function vte(t,e="_blank"){$g.openWindow(t,e)}_i("@tldraw/editor","3.7.2","esm");function QR(){const[t,e]=w.useState(!1);return w.useEffect(()=>{if(typeof window>"u"||!("matchMedia"in window))return;const n=window.matchMedia("(prefers-reduced-motion: reduce)"),r=()=>{e(n.matches)};return r(),n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),t}const JR=()=>{},e3=w.createContext(null);function xte({onEvent:t,children:e}){return d.jsx(e3.Provider,{value:t??JR,children:e})}function Jt(){return w.useContext(e3)??JR}function se(t,e,{checkForDefaultPrevented:n=!0}={}){return function(s){if(t==null||t(s),n===!1||!s.defaultPrevented)return e==null?void 0:e(s)}}function wte(t,e){const n=w.createContext(e),r=o=>{const{children:i,...a}=o,l=w.useMemo(()=>a,Object.values(a));return d.jsx(n.Provider,{value:l,children:i})};r.displayName=t+"Provider";function s(o){const i=w.useContext(n);if(i)return i;if(e!==void 0)return e;throw new Error(`\`${o}\` must be used within \`${t}\``)}return[r,s]}function Ws(t,e=[]){let n=[];function r(o,i){const a=w.createContext(i),l=n.length;n=[...n,i];const c=h=>{var y;const{scope:f,children:p,...g}=h,m=((y=f==null?void 0:f[t])==null?void 0:y[l])||a,v=w.useMemo(()=>g,Object.values(g));return d.jsx(m.Provider,{value:v,children:p})};c.displayName=o+"Provider";function u(h,f){var m;const p=((m=f==null?void 0:f[t])==null?void 0:m[l])||a,g=w.useContext(p);if(g)return g;if(i!==void 0)return i;throw new Error(`\`${h}\` must be used within \`${o}\``)}return[c,u]}const s=()=>{const o=n.map(i=>w.createContext(i));return function(a){const l=(a==null?void 0:a[t])||o;return w.useMemo(()=>({[`__scope${t}`]:{...a,[t]:l}}),[a,l])}};return s.scopeName=t,[r,bte(s,...e)]}function bte(...t){const e=t[0];if(t.length===1)return e;const n=()=>{const r=t.map(s=>({useScope:s(),scopeName:s.scopeName}));return function(o){const i=r.reduce((a,{useScope:l,scopeName:c})=>{const h=l(o)[`__scope${c}`];return{...a,...h}},{});return w.useMemo(()=>({[`__scope${e.scopeName}`]:i}),[i])}};return n.scopeName=e.scopeName,n}function GI(t,e){if(typeof t=="function")return t(e);t!=null&&(t.current=e)}function Qg(...t){return e=>{let n=!1;const r=t.map(s=>{const o=GI(s,e);return!n&&typeof o=="function"&&(n=!0),o});if(n)return()=>{for(let s=0;s<r.length;s++){const o=r[s];typeof o=="function"?o():GI(t[s],null)}}}}function Qe(...t){return w.useCallback(Qg(...t),t)}var fa=w.forwardRef((t,e)=>{const{children:n,...r}=t,s=w.Children.toArray(n),o=s.find(Cte);if(o){const i=o.props.children,a=s.map(l=>l===o?w.Children.count(i)>1?w.Children.only(null):w.isValidElement(i)?i.props.children:null:l);return d.jsx(Dx,{...r,ref:e,children:w.isValidElement(i)?w.cloneElement(i,void 0,a):null})}return d.jsx(Dx,{...r,ref:e,children:n})});fa.displayName="Slot";var Dx=w.forwardRef((t,e)=>{const{children:n,...r}=t;if(w.isValidElement(n)){const s=Ite(n);return w.cloneElement(n,{..._te(r,n.props),ref:e?Qg(e,s):s})}return w.Children.count(n)>1?w.Children.only(null):null});Dx.displayName="SlotClone";var Pte=({children:t})=>d.jsx(d.Fragment,{children:t});function Cte(t){return w.isValidElement(t)&&t.type===Pte}function _te(t,e){const n={...e};for(const r in e){const s=t[r],o=e[r];/^on[A-Z]/.test(r)?s&&o?n[r]=(...a)=>{o(...a),s(...a)}:s&&(n[r]=s):r==="style"?n[r]={...s,...o}:r==="className"&&(n[r]=[s,o].filter(Boolean).join(" "))}return{...t,...n}}function Ite(t){var r,s;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(s=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:s.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}var Ete=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"],Ae=Ete.reduce((t,e)=>{const n=w.forwardRef((r,s)=>{const{asChild:o,...i}=r,a=o?fa:e;return typeof window<"u"&&(window[Symbol.for("radix-ui")]=!0),d.jsx(a,{...i,ref:s})});return n.displayName=`Primitive.${e}`,{...t,[e]:n}},{});function $b(t,e){t&&ba.flushSync(()=>t.dispatchEvent(e))}function Jg(t){const e=t+"CollectionProvider",[n,r]=Ws(e),[s,o]=n(e,{collectionRef:{current:null},itemMap:new Map}),i=p=>{const{scope:g,children:m}=p,v=ke.useRef(null),y=ke.useRef(new Map).current;return d.jsx(s,{scope:g,itemMap:y,collectionRef:v,children:m})};i.displayName=e;const a=t+"CollectionSlot",l=ke.forwardRef((p,g)=>{const{scope:m,children:v}=p,y=o(a,m),S=Qe(g,y.collectionRef);return d.jsx(fa,{ref:S,children:v})});l.displayName=a;const c=t+"CollectionItemSlot",u="data-radix-collection-item",h=ke.forwardRef((p,g)=>{const{scope:m,children:v,...y}=p,S=ke.useRef(null),b=Qe(g,S),P=o(c,m);return ke.useEffect(()=>(P.itemMap.set(S,{ref:S,...y}),()=>void P.itemMap.delete(S))),d.jsx(fa,{[u]:"",ref:b,children:v})});h.displayName=c;function f(p){const g=o(t+"CollectionConsumer",p);return ke.useCallback(()=>{const v=g.collectionRef.current;if(!v)return[];const y=Array.from(v.querySelectorAll(`[${u}]`));return Array.from(g.itemMap.values()).sort((P,C)=>y.indexOf(P.ref.current)-y.indexOf(C.ref.current))},[g.collectionRef,g.itemMap])}return[{Provider:i,Slot:l,ItemSlot:h},f,r]}var kte=w.createContext(void 0);function Fb(t){const e=w.useContext(kte);return t||e||"ltr"}function qt(t){const e=w.useRef(t);return w.useEffect(()=>{e.current=t}),w.useMemo(()=>(...n)=>{var r;return(r=e.current)==null?void 0:r.call(e,...n)},[])}function Tte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t);w.useEffect(()=>{const r=s=>{s.key==="Escape"&&n(s)};return e.addEventListener("keydown",r,{capture:!0}),()=>e.removeEventListener("keydown",r,{capture:!0})},[n,e])}var Mte="DismissableLayer",Rx="dismissableLayer.update",Ate="dismissableLayer.pointerDownOutside",jte="dismissableLayer.focusOutside",VI,t3=w.createContext({layers:new Set,layersWithOutsidePointerEventsDisabled:new Set,branches:new Set}),wd=w.forwardRef((t,e)=>{const{disableOutsidePointerEvents:n=!1,onEscapeKeyDown:r,onPointerDownOutside:s,onFocusOutside:o,onInteractOutside:i,onDismiss:a,...l}=t,c=w.useContext(t3),[u,h]=w.useState(null),f=(u==null?void 0:u.ownerDocument)??(globalThis==null?void 0:globalThis.document),[,p]=w.useState({}),g=Qe(e,E=>h(E)),m=Array.from(c.layers),[v]=[...c.layersWithOutsidePointerEventsDisabled].slice(-1),y=m.indexOf(v),S=u?m.indexOf(u):-1,b=c.layersWithOutsidePointerEventsDisabled.size>0,P=S>=y,C=Dte(E=>{const k=E.target,D=[...c.branches].some(T=>T.contains(k));!P||D||(s==null||s(E),i==null||i(E),E.defaultPrevented||a==null||a())},f),_=Rte(E=>{const k=E.target;[...c.branches].some(T=>T.contains(k))||(o==null||o(E),i==null||i(E),E.defaultPrevented||a==null||a())},f);return Tte(E=>{S===c.layers.size-1&&(r==null||r(E),!E.defaultPrevented&&a&&(E.preventDefault(),a()))},f),w.useEffect(()=>{if(u)return n&&(c.layersWithOutsidePointerEventsDisabled.size===0&&(VI=f.body.style.pointerEvents,f.body.style.pointerEvents="none"),c.layersWithOutsidePointerEventsDisabled.add(u)),c.layers.add(u),YI(),()=>{n&&c.layersWithOutsidePointerEventsDisabled.size===1&&(f.body.style.pointerEvents=VI)}},[u,f,n,c]),w.useEffect(()=>()=>{u&&(c.layers.delete(u),c.layersWithOutsidePointerEventsDisabled.delete(u),YI())},[u,c]),w.useEffect(()=>{const E=()=>p({});return document.addEventListener(Rx,E),()=>document.removeEventListener(Rx,E)},[]),d.jsx(Ae.div,{...l,ref:g,style:{pointerEvents:b?P?"auto":"none":void 0,...t.style},onFocusCapture:se(t.onFocusCapture,_.onFocusCapture),onBlurCapture:se(t.onBlurCapture,_.onBlurCapture),onPointerDownCapture:se(t.onPointerDownCapture,C.onPointerDownCapture)})});wd.displayName=Mte;var Ote="DismissableLayerBranch",n3=w.forwardRef((t,e)=>{const n=w.useContext(t3),r=w.useRef(null),s=Qe(e,r);return w.useEffect(()=>{const o=r.current;if(o)return n.branches.add(o),()=>{n.branches.delete(o)}},[n.branches]),d.jsx(Ae.div,{...t,ref:s})});n3.displayName=Ote;function Dte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1),s=w.useRef(()=>{});return w.useEffect(()=>{const o=a=>{if(a.target&&!r.current){let l=function(){r3(Ate,n,c,{discrete:!0})};const c={originalEvent:a};a.pointerType==="touch"?(e.removeEventListener("click",s.current),s.current=l,e.addEventListener("click",s.current,{once:!0})):l()}else e.removeEventListener("click",s.current);r.current=!1},i=window.setTimeout(()=>{e.addEventListener("pointerdown",o)},0);return()=>{window.clearTimeout(i),e.removeEventListener("pointerdown",o),e.removeEventListener("click",s.current)}},[e,n]),{onPointerDownCapture:()=>r.current=!0}}function Rte(t,e=globalThis==null?void 0:globalThis.document){const n=qt(t),r=w.useRef(!1);return w.useEffect(()=>{const s=o=>{o.target&&!r.current&&r3(jte,n,{originalEvent:o},{discrete:!1})};return e.addEventListener("focusin",s),()=>e.removeEventListener("focusin",s)},[e,n]),{onFocusCapture:()=>r.current=!0,onBlurCapture:()=>r.current=!1}}function YI(){const t=new CustomEvent(Rx);document.dispatchEvent(t)}function r3(t,e,n,{discrete:r}){const s=n.originalEvent.target,o=new CustomEvent(t,{bubbles:!1,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?$b(s,o):s.dispatchEvent(o)}var Lte=wd,$te=n3,rS=0;function Nb(){w.useEffect(()=>{const t=document.querySelectorAll("[data-radix-focus-guard]");return document.body.insertAdjacentElement("afterbegin",t[0]??XI()),document.body.insertAdjacentElement("beforeend",t[1]??XI()),rS++,()=>{rS===1&&document.querySelectorAll("[data-radix-focus-guard]").forEach(e=>e.remove()),rS--}},[])}function XI(){const t=document.createElement("span");return t.setAttribute("data-radix-focus-guard",""),t.tabIndex=0,t.style.outline="none",t.style.opacity="0",t.style.position="fixed",t.style.pointerEvents="none",t}var sS="focusScope.autoFocusOnMount",oS="focusScope.autoFocusOnUnmount",qI={bubbles:!1,cancelable:!0},Fte="FocusScope",em=w.forwardRef((t,e)=>{const{loop:n=!1,trapped:r=!1,onMountAutoFocus:s,onUnmountAutoFocus:o,...i}=t,[a,l]=w.useState(null),c=qt(s),u=qt(o),h=w.useRef(null),f=Qe(e,m=>l(m)),p=w.useRef({paused:!1,pause(){this.paused=!0},resume(){this.paused=!1}}).current;w.useEffect(()=>{if(r){let m=function(b){if(p.paused||!a)return;const P=b.target;a.contains(P)?h.current=P:Uo(h.current,{select:!0})},v=function(b){if(p.paused||!a)return;const P=b.relatedTarget;P!==null&&(a.contains(P)||Uo(h.current,{select:!0}))},y=function(b){if(document.activeElement===document.body)for(const C of b)C.removedNodes.length>0&&Uo(a)};document.addEventListener("focusin",m),document.addEventListener("focusout",v);const S=new MutationObserver(y);return a&&S.observe(a,{childList:!0,subtree:!0}),()=>{document.removeEventListener("focusin",m),document.removeEventListener("focusout",v),S.disconnect()}}},[r,a,p.paused]),w.useEffect(()=>{if(a){QI.add(p);const m=document.activeElement;if(!a.contains(m)){const y=new CustomEvent(sS,qI);a.addEventListener(sS,c),a.dispatchEvent(y),y.defaultPrevented||(Nte(Kte(s3(a)),{select:!0}),document.activeElement===m&&Uo(a))}return()=>{a.removeEventListener(sS,c),setTimeout(()=>{const y=new CustomEvent(oS,qI);a.addEventListener(oS,u),a.dispatchEvent(y),y.defaultPrevented||Uo(m??document.body,{select:!0}),a.removeEventListener(oS,u),QI.remove(p)},0)}}},[a,c,u,p]);const g=w.useCallback(m=>{if(!n&&!r||p.paused)return;const v=m.key==="Tab"&&!m.altKey&&!m.ctrlKey&&!m.metaKey,y=document.activeElement;if(v&&y){const S=m.currentTarget,[b,P]=zte(S);b&&P?!m.shiftKey&&y===P?(m.preventDefault(),n&&Uo(b,{select:!0})):m.shiftKey&&y===b&&(m.preventDefault(),n&&Uo(P,{select:!0})):y===S&&m.preventDefault()}},[n,r,p.paused]);return d.jsx(Ae.div,{tabIndex:-1,...i,ref:f,onKeyDown:g})});em.displayName=Fte;function Nte(t,{select:e=!1}={}){const n=document.activeElement;for(const r of t)if(Uo(r,{select:e}),document.activeElement!==n)return}function zte(t){const e=s3(t),n=ZI(e,t),r=ZI(e.reverse(),t);return[n,r]}function s3(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function ZI(t,e){for(const n of t)if(!Bte(n,{upTo:e}))return n}function Bte(t,{upTo:e}){if(getComputedStyle(t).visibility==="hidden")return!0;for(;t;){if(e!==void 0&&t===e)return!1;if(getComputedStyle(t).display==="none")return!0;t=t.parentElement}return!1}function Ute(t){return t instanceof HTMLInputElement&&"select"in t}function Uo(t,{select:e=!1}={}){if(t&&t.focus){const n=document.activeElement;t.focus({preventScroll:!0}),t!==n&&Ute(t)&&e&&t.select()}}var QI=Hte();function Hte(){let t=[];return{add(e){const n=t[0];e!==n&&(n==null||n.pause()),t=JI(t,e),t.unshift(e)},remove(e){var n;t=JI(t,e),(n=t[0])==null||n.resume()}}}function JI(t,e){const n=[...t],r=n.indexOf(e);return r!==-1&&n.splice(r,1),n}function Kte(t){return t.filter(e=>e.tagName!=="A")}var yi=globalThis!=null&&globalThis.document?w.useLayoutEffect:()=>{},Wte=t6.useId||(()=>{}),Gte=0;function mo(t){const[e,n]=w.useState(Wte());return yi(()=>{t||n(r=>r??String(Gte++))},[t]),t||(e?`radix-${e}`:"")}const Vte=["top","right","bottom","left"],Si=Math.min,or=Math.max,Np=Math.round,bh=Math.floor,Os=t=>({x:t,y:t}),Yte={left:"right",right:"left",bottom:"top",top:"bottom"},Xte={start:"end",end:"start"};function Lx(t,e,n){return or(t,Si(e,n))}function bo(t,e){return typeof t=="function"?t(e):t}function Po(t){return t.split("-")[0]}function ic(t){return t.split("-")[1]}function zb(t){return t==="x"?"y":"x"}function Bb(t){return t==="y"?"height":"width"}function vi(t){return["top","bottom"].includes(Po(t))?"y":"x"}function Ub(t){return zb(vi(t))}function qte(t,e,n){n===void 0&&(n=!1);const r=ic(t),s=Ub(t),o=Bb(s);let i=s==="x"?r===(n?"end":"start")?"right":"left":r==="start"?"bottom":"top";return e.reference[o]>e.floating[o]&&(i=zp(i)),[i,zp(i)]}function Zte(t){const e=zp(t);return[$x(t),e,$x(e)]}function $x(t){return t.replace(/start|end/g,e=>Xte[e])}function Qte(t,e,n){const r=["left","right"],s=["right","left"],o=["top","bottom"],i=["bottom","top"];switch(t){case"top":case"bottom":return n?e?s:r:e?r:s;case"left":case"right":return e?o:i;default:return[]}}function Jte(t,e,n,r){const s=ic(t);let o=Qte(Po(t),n==="start",r);return s&&(o=o.map(i=>i+"-"+s),e&&(o=o.concat(o.map($x)))),o}function zp(t){return t.replace(/left|right|bottom|top/g,e=>Yte[e])}function ene(t){return{top:0,right:0,bottom:0,left:0,...t}}function o3(t){return typeof t!="number"?ene(t):{top:t,right:t,bottom:t,left:t}}function Bp(t){const{x:e,y:n,width:r,height:s}=t;return{width:r,height:s,top:n,left:e,right:e+r,bottom:n+s,x:e,y:n}}function eE(t,e,n){let{reference:r,floating:s}=t;const o=vi(e),i=Ub(e),a=Bb(i),l=Po(e),c=o==="y",u=r.x+r.width/2-s.width/2,h=r.y+r.height/2-s.height/2,f=r[a]/2-s[a]/2;let p;switch(l){case"top":p={x:u,y:r.y-s.height};break;case"bottom":p={x:u,y:r.y+r.height};break;case"right":p={x:r.x+r.width,y:h};break;case"left":p={x:r.x-s.width,y:h};break;default:p={x:r.x,y:r.y}}switch(ic(e)){case"start":p[i]-=f*(n&&c?-1:1);break;case"end":p[i]+=f*(n&&c?-1:1);break}return p}const tne=async(t,e,n)=>{const{placement:r="bottom",strategy:s="absolute",middleware:o=[],platform:i}=n,a=o.filter(Boolean),l=await(i.isRTL==null?void 0:i.isRTL(e));let c=await i.getElementRects({reference:t,floating:e,strategy:s}),{x:u,y:h}=eE(c,r,l),f=r,p={},g=0;for(let m=0;m<a.length;m++){const{name:v,fn:y}=a[m],{x:S,y:b,data:P,reset:C}=await y({x:u,y:h,initialPlacement:r,placement:f,strategy:s,middlewareData:p,rects:c,platform:i,elements:{reference:t,floating:e}});u=S??u,h=b??h,p={...p,[v]:{...p[v],...P}},C&&g<=50&&(g++,typeof C=="object"&&(C.placement&&(f=C.placement),C.rects&&(c=C.rects===!0?await i.getElementRects({reference:t,floating:e,strategy:s}):C.rects),{x:u,y:h}=eE(c,f,l)),m=-1)}return{x:u,y:h,placement:f,strategy:s,middlewareData:p}};async function Ku(t,e){var n;e===void 0&&(e={});const{x:r,y:s,platform:o,rects:i,elements:a,strategy:l}=t,{boundary:c="clippingAncestors",rootBoundary:u="viewport",elementContext:h="floating",altBoundary:f=!1,padding:p=0}=bo(e,t),g=o3(p),v=a[f?h==="floating"?"reference":"floating":h],y=Bp(await o.getClippingRect({element:(n=await(o.isElement==null?void 0:o.isElement(v)))==null||n?v:v.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(a.floating)),boundary:c,rootBoundary:u,strategy:l})),S=h==="floating"?{x:r,y:s,width:i.floating.width,height:i.floating.height}:i.reference,b=await(o.getOffsetParent==null?void 0:o.getOffsetParent(a.floating)),P=await(o.isElement==null?void 0:o.isElement(b))?await(o.getScale==null?void 0:o.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Bp(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:a,rect:S,offsetParent:b,strategy:l}):S);return{top:(y.top-C.top+g.top)/P.y,bottom:(C.bottom-y.bottom+g.bottom)/P.y,left:(y.left-C.left+g.left)/P.x,right:(C.right-y.right+g.right)/P.x}}const nne=t=>({name:"arrow",options:t,async fn(e){const{x:n,y:r,placement:s,rects:o,platform:i,elements:a,middlewareData:l}=e,{element:c,padding:u=0}=bo(t,e)||{};if(c==null)return{};const h=o3(u),f={x:n,y:r},p=Ub(s),g=Bb(p),m=await i.getDimensions(c),v=p==="y",y=v?"top":"left",S=v?"bottom":"right",b=v?"clientHeight":"clientWidth",P=o.reference[g]+o.reference[p]-f[p]-o.floating[g],C=f[p]-o.reference[p],_=await(i.getOffsetParent==null?void 0:i.getOffsetParent(c));let E=_?_[b]:0;(!E||!await(i.isElement==null?void 0:i.isElement(_)))&&(E=a.floating[b]||o.floating[g]);const k=P/2-C/2,D=E/2-m[g]/2-1,T=Si(h[y],D),j=Si(h[S],D),L=T,M=E-m[g]-j,O=E/2-m[g]/2+k,F=Lx(L,O,M),B=!l.arrow&&ic(s)!=null&&O!==F&&o.reference[g]/2-(O<L?T:j)-m[g]/2<0,K=B?O<L?O-L:O-M:0;return{[p]:f[p]+K,data:{[p]:F,centerOffset:O-F-K,...B&&{alignmentOffset:K}},reset:B}}}),rne=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,r;const{placement:s,middlewareData:o,rects:i,initialPlacement:a,platform:l,elements:c}=e,{mainAxis:u=!0,crossAxis:h=!0,fallbackPlacements:f,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:m=!0,...v}=bo(t,e);if((n=o.arrow)!=null&&n.alignmentOffset)return{};const y=Po(s),S=vi(a),b=Po(a)===a,P=await(l.isRTL==null?void 0:l.isRTL(c.floating)),C=f||(b||!m?[zp(a)]:Zte(a)),_=g!=="none";!f&&_&&C.push(...Jte(a,m,g,P));const E=[a,...C],k=await Ku(e,v),D=[];let T=((r=o.flip)==null?void 0:r.overflows)||[];if(u&&D.push(k[y]),h){const O=qte(s,i,P);D.push(k[O[0]],k[O[1]])}if(T=[...T,{placement:s,overflows:D}],!D.every(O=>O<=0)){var j,L;const O=(((j=o.flip)==null?void 0:j.index)||0)+1,F=E[O];if(F)return{data:{index:O,overflows:T},reset:{placement:F}};let B=(L=T.filter(K=>K.overflows[0]<=0).sort((K,R)=>K.overflows[1]-R.overflows[1])[0])==null?void 0:L.placement;if(!B)switch(p){case"bestFit":{var M;const K=(M=T.filter(R=>{if(_){const H=vi(R.placement);return H===S||H==="y"}return!0}).map(R=>[R.placement,R.overflows.filter(H=>H>0).reduce((H,X)=>H+X,0)]).sort((R,H)=>R[1]-H[1])[0])==null?void 0:M[0];K&&(B=K);break}case"initialPlacement":B=a;break}if(s!==B)return{reset:{placement:B}}}return{}}}};function tE(t,e){return{top:t.top-e.height,right:t.right-e.width,bottom:t.bottom-e.height,left:t.left-e.width}}function nE(t){return Vte.some(e=>t[e]>=0)}const sne=function(t){return t===void 0&&(t={}),{name:"hide",options:t,async fn(e){const{rects:n}=e,{strategy:r="referenceHidden",...s}=bo(t,e);switch(r){case"referenceHidden":{const o=await Ku(e,{...s,elementContext:"reference"}),i=tE(o,n.reference);return{data:{referenceHiddenOffsets:i,referenceHidden:nE(i)}}}case"escaped":{const o=await Ku(e,{...s,altBoundary:!0}),i=tE(o,n.floating);return{data:{escapedOffsets:i,escaped:nE(i)}}}default:return{}}}}};async function one(t,e){const{placement:n,platform:r,elements:s}=t,o=await(r.isRTL==null?void 0:r.isRTL(s.floating)),i=Po(n),a=ic(n),l=vi(n)==="y",c=["left","top"].includes(i)?-1:1,u=o&&l?-1:1,h=bo(e,t);let{mainAxis:f,crossAxis:p,alignmentAxis:g}=typeof h=="number"?{mainAxis:h,crossAxis:0,alignmentAxis:null}:{mainAxis:h.mainAxis||0,crossAxis:h.crossAxis||0,alignmentAxis:h.alignmentAxis};return a&&typeof g=="number"&&(p=a==="end"?g*-1:g),l?{x:p*u,y:f*c}:{x:f*c,y:p*u}}const ine=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,r;const{x:s,y:o,placement:i,middlewareData:a}=e,l=await one(e,t);return i===((n=a.offset)==null?void 0:n.placement)&&(r=a.arrow)!=null&&r.alignmentOffset?{}:{x:s+l.x,y:o+l.y,data:{...l,placement:i}}}}},ane=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){const{x:n,y:r,placement:s}=e,{mainAxis:o=!0,crossAxis:i=!1,limiter:a={fn:v=>{let{x:y,y:S}=v;return{x:y,y:S}}},...l}=bo(t,e),c={x:n,y:r},u=await Ku(e,l),h=vi(Po(s)),f=zb(h);let p=c[f],g=c[h];if(o){const v=f==="y"?"top":"left",y=f==="y"?"bottom":"right",S=p+u[v],b=p-u[y];p=Lx(S,p,b)}if(i){const v=h==="y"?"top":"left",y=h==="y"?"bottom":"right",S=g+u[v],b=g-u[y];g=Lx(S,g,b)}const m=a.fn({...e,[f]:p,[h]:g});return{...m,data:{x:m.x-n,y:m.y-r,enabled:{[f]:o,[h]:i}}}}}},lne=function(t){return t===void 0&&(t={}),{options:t,fn(e){const{x:n,y:r,placement:s,rects:o,middlewareData:i}=e,{offset:a=0,mainAxis:l=!0,crossAxis:c=!0}=bo(t,e),u={x:n,y:r},h=vi(s),f=zb(h);let p=u[f],g=u[h];const m=bo(a,e),v=typeof m=="number"?{mainAxis:m,crossAxis:0}:{mainAxis:0,crossAxis:0,...m};if(l){const b=f==="y"?"height":"width",P=o.reference[f]-o.floating[b]+v.mainAxis,C=o.reference[f]+o.reference[b]-v.mainAxis;p<P?p=P:p>C&&(p=C)}if(c){var y,S;const b=f==="y"?"width":"height",P=["top","left"].includes(Po(s)),C=o.reference[h]-o.floating[b]+(P&&((y=i.offset)==null?void 0:y[h])||0)+(P?0:v.crossAxis),_=o.reference[h]+o.reference[b]+(P?0:((S=i.offset)==null?void 0:S[h])||0)-(P?v.crossAxis:0);g<C?g=C:g>_&&(g=_)}return{[f]:p,[h]:g}}}},cne=function(t){return t===void 0&&(t={}),{name:"size",options:t,async fn(e){var n,r;const{placement:s,rects:o,platform:i,elements:a}=e,{apply:l=()=>{},...c}=bo(t,e),u=await Ku(e,c),h=Po(s),f=ic(s),p=vi(s)==="y",{width:g,height:m}=o.floating;let v,y;h==="top"||h==="bottom"?(v=h,y=f===(await(i.isRTL==null?void 0:i.isRTL(a.floating))?"start":"end")?"left":"right"):(y=h,v=f==="end"?"top":"bottom");const S=m-u.top-u.bottom,b=g-u.left-u.right,P=Si(m-u[v],S),C=Si(g-u[y],b),_=!e.middlewareData.shift;let E=P,k=C;if((n=e.middlewareData.shift)!=null&&n.enabled.x&&(k=b),(r=e.middlewareData.shift)!=null&&r.enabled.y&&(E=S),_&&!f){const T=or(u.left,0),j=or(u.right,0),L=or(u.top,0),M=or(u.bottom,0);p?k=g-2*(T!==0||j!==0?T+j:or(u.left,u.right)):E=m-2*(L!==0||M!==0?L+M:or(u.top,u.bottom))}await l({...e,availableWidth:k,availableHeight:E});const D=await i.getDimensions(a.floating);return g!==D.width||m!==D.height?{reset:{rects:!0}}:{}}}};function tm(){return typeof window<"u"}function ac(t){return i3(t)?(t.nodeName||"").toLowerCase():"#document"}function fr(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function Gs(t){var e;return(e=(i3(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function i3(t){return tm()?t instanceof Node||t instanceof fr(t).Node:!1}function as(t){return tm()?t instanceof Element||t instanceof fr(t).Element:!1}function Ns(t){return tm()?t instanceof HTMLElement||t instanceof fr(t).HTMLElement:!1}function rE(t){return!tm()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof fr(t).ShadowRoot}function bd(t){const{overflow:e,overflowX:n,overflowY:r,display:s}=ls(t);return/auto|scroll|overlay|hidden|clip/.test(e+r+n)&&!["inline","contents"].includes(s)}function une(t){return["table","td","th"].includes(ac(t))}function nm(t){return[":popover-open",":modal"].some(e=>{try{return t.matches(e)}catch{return!1}})}function Hb(t){const e=Kb(),n=as(t)?ls(t):t;return["transform","translate","scale","rotate","perspective"].some(r=>n[r]?n[r]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(r=>(n.willChange||"").includes(r))||["paint","layout","strict","content"].some(r=>(n.contain||"").includes(r))}function dne(t){let e=xi(t);for(;Ns(e)&&!Rl(e);){if(Hb(e))return e;if(nm(e))return null;e=xi(e)}return null}function Kb(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function Rl(t){return["html","body","#document"].includes(ac(t))}function ls(t){return fr(t).getComputedStyle(t)}function rm(t){return as(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function xi(t){if(ac(t)==="html")return t;const e=t.assignedSlot||t.parentNode||rE(t)&&t.host||Gs(t);return rE(e)?e.host:e}function a3(t){const e=xi(t);return Rl(e)?t.ownerDocument?t.ownerDocument.body:t.body:Ns(e)&&bd(e)?e:a3(e)}function Wu(t,e,n){var r;e===void 0&&(e=[]),n===void 0&&(n=!0);const s=a3(t),o=s===((r=t.ownerDocument)==null?void 0:r.body),i=fr(s);if(o){const a=Fx(i);return e.concat(i,i.visualViewport||[],bd(s)?s:[],a&&n?Wu(a):[])}return e.concat(s,Wu(s,[],n))}function Fx(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function l3(t){const e=ls(t);let n=parseFloat(e.width)||0,r=parseFloat(e.height)||0;const s=Ns(t),o=s?t.offsetWidth:n,i=s?t.offsetHeight:r,a=Np(n)!==o||Np(r)!==i;return a&&(n=o,r=i),{width:n,height:r,$:a}}function Wb(t){return as(t)?t:t.contextElement}function Pl(t){const e=Wb(t);if(!Ns(e))return Os(1);const n=e.getBoundingClientRect(),{width:r,height:s,$:o}=l3(e);let i=(o?Np(n.width):n.width)/r,a=(o?Np(n.height):n.height)/s;return(!i||!Number.isFinite(i))&&(i=1),(!a||!Number.isFinite(a))&&(a=1),{x:i,y:a}}const hne=Os(0);function c3(t){const e=fr(t);return!Kb()||!e.visualViewport?hne:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function fne(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==fr(t)?!1:e}function pa(t,e,n,r){e===void 0&&(e=!1),n===void 0&&(n=!1);const s=t.getBoundingClientRect(),o=Wb(t);let i=Os(1);e&&(r?as(r)&&(i=Pl(r)):i=Pl(t));const a=fne(o,n,r)?c3(o):Os(0);let l=(s.left+a.x)/i.x,c=(s.top+a.y)/i.y,u=s.width/i.x,h=s.height/i.y;if(o){const f=fr(o),p=r&&as(r)?fr(r):r;let g=f,m=Fx(g);for(;m&&r&&p!==g;){const v=Pl(m),y=m.getBoundingClientRect(),S=ls(m),b=y.left+(m.clientLeft+parseFloat(S.paddingLeft))*v.x,P=y.top+(m.clientTop+parseFloat(S.paddingTop))*v.y;l*=v.x,c*=v.y,u*=v.x,h*=v.y,l+=b,c+=P,g=fr(m),m=Fx(g)}}return Bp({width:u,height:h,x:l,y:c})}function Gb(t,e){const n=rm(t).scrollLeft;return e?e.left+n:pa(Gs(t)).left+n}function u3(t,e,n){n===void 0&&(n=!1);const r=t.getBoundingClientRect(),s=r.left+e.scrollLeft-(n?0:Gb(t,r)),o=r.top+e.scrollTop;return{x:s,y:o}}function pne(t){let{elements:e,rect:n,offsetParent:r,strategy:s}=t;const o=s==="fixed",i=Gs(r),a=e?nm(e.floating):!1;if(r===i||a&&o)return n;let l={scrollLeft:0,scrollTop:0},c=Os(1);const u=Os(0),h=Ns(r);if((h||!h&&!o)&&((ac(r)!=="body"||bd(i))&&(l=rm(r)),Ns(r))){const p=pa(r);c=Pl(r),u.x=p.x+r.clientLeft,u.y=p.y+r.clientTop}const f=i&&!h&&!o?u3(i,l,!0):Os(0);return{width:n.width*c.x,height:n.height*c.y,x:n.x*c.x-l.scrollLeft*c.x+u.x+f.x,y:n.y*c.y-l.scrollTop*c.y+u.y+f.y}}function gne(t){return Array.from(t.getClientRects())}function mne(t){const e=Gs(t),n=rm(t),r=t.ownerDocument.body,s=or(e.scrollWidth,e.clientWidth,r.scrollWidth,r.clientWidth),o=or(e.scrollHeight,e.clientHeight,r.scrollHeight,r.clientHeight);let i=-n.scrollLeft+Gb(t);const a=-n.scrollTop;return ls(r).direction==="rtl"&&(i+=or(e.clientWidth,r.clientWidth)-s),{width:s,height:o,x:i,y:a}}function yne(t,e){const n=fr(t),r=Gs(t),s=n.visualViewport;let o=r.clientWidth,i=r.clientHeight,a=0,l=0;if(s){o=s.width,i=s.height;const c=Kb();(!c||c&&e==="fixed")&&(a=s.offsetLeft,l=s.offsetTop)}return{width:o,height:i,x:a,y:l}}function Sne(t,e){const n=pa(t,!0,e==="fixed"),r=n.top+t.clientTop,s=n.left+t.clientLeft,o=Ns(t)?Pl(t):Os(1),i=t.clientWidth*o.x,a=t.clientHeight*o.y,l=s*o.x,c=r*o.y;return{width:i,height:a,x:l,y:c}}function sE(t,e,n){let r;if(e==="viewport")r=yne(t,n);else if(e==="document")r=mne(Gs(t));else if(as(e))r=Sne(e,n);else{const s=c3(t);r={x:e.x-s.x,y:e.y-s.y,width:e.width,height:e.height}}return Bp(r)}function d3(t,e){const n=xi(t);return n===e||!as(n)||Rl(n)?!1:ls(n).position==="fixed"||d3(n,e)}function vne(t,e){const n=e.get(t);if(n)return n;let r=Wu(t,[],!1).filter(a=>as(a)&&ac(a)!=="body"),s=null;const o=ls(t).position==="fixed";let i=o?xi(t):t;for(;as(i)&&!Rl(i);){const a=ls(i),l=Hb(i);!l&&a.position==="fixed"&&(s=null),(o?!l&&!s:!l&&a.position==="static"&&!!s&&["absolute","fixed"].includes(s.position)||bd(i)&&!l&&d3(t,i))?r=r.filter(u=>u!==i):s=a,i=xi(i)}return e.set(t,r),r}function xne(t){let{element:e,boundary:n,rootBoundary:r,strategy:s}=t;const i=[...n==="clippingAncestors"?nm(e)?[]:vne(e,this._c):[].concat(n),r],a=i[0],l=i.reduce((c,u)=>{const h=sE(e,u,s);return c.top=or(h.top,c.top),c.right=Si(h.right,c.right),c.bottom=Si(h.bottom,c.bottom),c.left=or(h.left,c.left),c},sE(e,a,s));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function wne(t){const{width:e,height:n}=l3(t);return{width:e,height:n}}function bne(t,e,n){const r=Ns(e),s=Gs(e),o=n==="fixed",i=pa(t,!0,o,e);let a={scrollLeft:0,scrollTop:0};const l=Os(0);if(r||!r&&!o)if((ac(e)!=="body"||bd(s))&&(a=rm(e)),r){const f=pa(e,!0,o,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}else s&&(l.x=Gb(s));const c=s&&!r&&!o?u3(s,a):Os(0),u=i.left+a.scrollLeft-l.x-c.x,h=i.top+a.scrollTop-l.y-c.y;return{x:u,y:h,width:i.width,height:i.height}}function iS(t){return ls(t).position==="static"}function oE(t,e){if(!Ns(t)||ls(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return Gs(t)===n&&(n=n.ownerDocument.body),n}function h3(t,e){const n=fr(t);if(nm(t))return n;if(!Ns(t)){let s=xi(t);for(;s&&!Rl(s);){if(as(s)&&!iS(s))return s;s=xi(s)}return n}let r=oE(t,e);for(;r&&une(r)&&iS(r);)r=oE(r,e);return r&&Rl(r)&&iS(r)&&!Hb(r)?n:r||dne(t)||n}const Pne=async function(t){const e=this.getOffsetParent||h3,n=this.getDimensions,r=await n(t.floating);return{reference:bne(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:r.width,height:r.height}}};function Cne(t){return ls(t).direction==="rtl"}const _ne={convertOffsetParentRelativeRectToViewportRelativeRect:pne,getDocumentElement:Gs,getClippingRect:xne,getOffsetParent:h3,getElementRects:Pne,getClientRects:gne,getDimensions:wne,getScale:Pl,isElement:as,isRTL:Cne};function f3(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Ine(t,e){let n=null,r;const s=Gs(t);function o(){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),o();const c=t.getBoundingClientRect(),{left:u,top:h,width:f,height:p}=c;if(a||e(),!f||!p)return;const g=bh(h),m=bh(s.clientWidth-(u+f)),v=bh(s.clientHeight-(h+p)),y=bh(u),b={rootMargin:-g+"px "+-m+"px "+-v+"px "+-y+"px",threshold:or(0,Si(1,l))||1};let P=!0;function C(_){const E=_[0].intersectionRatio;if(E!==l){if(!P)return i();E?i(!1,E):r=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!f3(c,t.getBoundingClientRect())&&i(),P=!1}try{n=new IntersectionObserver(C,{...b,root:s.ownerDocument})}catch{n=new IntersectionObserver(C,b)}n.observe(t)}return i(!0),o}function Ene(t,e,n,r){r===void 0&&(r={});const{ancestorScroll:s=!0,ancestorResize:o=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:a=typeof IntersectionObserver=="function",animationFrame:l=!1}=r,c=Wb(t),u=s||o?[...c?Wu(c):[],...Wu(e)]:[];u.forEach(y=>{s&&y.addEventListener("scroll",n,{passive:!0}),o&&y.addEventListener("resize",n)});const h=c&&a?Ine(c,n):null;let f=-1,p=null;i&&(p=new ResizeObserver(y=>{let[S]=y;S&&S.target===c&&p&&(p.unobserve(e),cancelAnimationFrame(f),f=requestAnimationFrame(()=>{var b;(b=p)==null||b.observe(e)})),n()}),c&&!l&&p.observe(c),p.observe(e));let g,m=l?pa(t):null;l&&v();function v(){const y=pa(t);m&&!f3(m,y)&&n(),m=y,g=requestAnimationFrame(v)}return n(),()=>{var y;u.forEach(S=>{s&&S.removeEventListener("scroll",n),o&&S.removeEventListener("resize",n)}),h==null||h(),(y=p)==null||y.disconnect(),p=null,l&&cancelAnimationFrame(g)}}const kne=ine,Tne=ane,Mne=rne,Ane=cne,jne=sne,iE=nne,One=lne,Dne=(t,e,n)=>{const r=new Map,s={platform:_ne,...n},o={...s.platform,_c:r};return tne(t,e,{...s,platform:o})};var pf=typeof document<"u"?w.useLayoutEffect:w.useEffect;function Up(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="function"&&t.toString()===e.toString())return!0;let n,r,s;if(t&&e&&typeof t=="object"){if(Array.isArray(t)){if(n=t.length,n!==e.length)return!1;for(r=n;r--!==0;)if(!Up(t[r],e[r]))return!1;return!0}if(s=Object.keys(t),n=s.length,n!==Object.keys(e).length)return!1;for(r=n;r--!==0;)if(!{}.hasOwnProperty.call(e,s[r]))return!1;for(r=n;r--!==0;){const o=s[r];if(!(o==="_owner"&&t.$$typeof)&&!Up(t[o],e[o]))return!1}return!0}return t!==t&&e!==e}function p3(t){return typeof window>"u"?1:(t.ownerDocument.defaultView||window).devicePixelRatio||1}function aE(t,e){const n=p3(t);return Math.round(e*n)/n}function aS(t){const e=w.useRef(t);return pf(()=>{e.current=t}),e}function Rne(t){t===void 0&&(t={});const{placement:e="bottom",strategy:n="absolute",middleware:r=[],platform:s,elements:{reference:o,floating:i}={},transform:a=!0,whileElementsMounted:l,open:c}=t,[u,h]=w.useState({x:0,y:0,strategy:n,placement:e,middlewareData:{},isPositioned:!1}),[f,p]=w.useState(r);Up(f,r)||p(r);const[g,m]=w.useState(null),[v,y]=w.useState(null),S=w.useCallback(R=>{R!==_.current&&(_.current=R,m(R))},[]),b=w.useCallback(R=>{R!==E.current&&(E.current=R,y(R))},[]),P=o||g,C=i||v,_=w.useRef(null),E=w.useRef(null),k=w.useRef(u),D=l!=null,T=aS(l),j=aS(s),L=aS(c),M=w.useCallback(()=>{if(!_.current||!E.current)return;const R={placement:e,strategy:n,middleware:f};j.current&&(R.platform=j.current),Dne(_.current,E.current,R).then(H=>{const X={...H,isPositioned:L.current!==!1};O.current&&!Up(k.current,X)&&(k.current=X,ba.flushSync(()=>{h(X)}))})},[f,e,n,j,L]);pf(()=>{c===!1&&k.current.isPositioned&&(k.current.isPositioned=!1,h(R=>({...R,isPositioned:!1})))},[c]);const O=w.useRef(!1);pf(()=>(O.current=!0,()=>{O.current=!1}),[]),pf(()=>{if(P&&(_.current=P),C&&(E.current=C),P&&C){if(T.current)return T.current(P,C,M);M()}},[P,C,M,T,D]);const F=w.useMemo(()=>({reference:_,floating:E,setReference:S,setFloating:b}),[S,b]),B=w.useMemo(()=>({reference:P,floating:C}),[P,C]),K=w.useMemo(()=>{const R={position:n,left:0,top:0};if(!B.floating)return R;const H=aE(B.floating,u.x),X=aE(B.floating,u.y);return a?{...R,transform:"translate("+H+"px, "+X+"px)",...p3(B.floating)>=1.5&&{willChange:"transform"}}:{position:n,left:H,top:X}},[n,a,B.floating,u.x,u.y]);return w.useMemo(()=>({...u,update:M,refs:F,elements:B,floatingStyles:K}),[u,M,F,B,K])}const Lne=t=>{function e(n){return{}.hasOwnProperty.call(n,"current")}return{name:"arrow",options:t,fn(n){const{element:r,padding:s}=typeof t=="function"?t(n):t;return r&&e(r)?r.current!=null?iE({element:r.current,padding:s}).fn(n):{}:r?iE({element:r,padding:s}).fn(n):{}}}},$ne=(t,e)=>({...kne(t),options:[t,e]}),Fne=(t,e)=>({...Tne(t),options:[t,e]}),Nne=(t,e)=>({...One(t),options:[t,e]}),zne=(t,e)=>({...Mne(t),options:[t,e]}),Bne=(t,e)=>({...Ane(t),options:[t,e]}),Une=(t,e)=>({...jne(t),options:[t,e]}),Hne=(t,e)=>({...Lne(t),options:[t,e]});var Kne="Arrow",g3=w.forwardRef((t,e)=>{const{children:n,width:r=10,height:s=5,...o}=t;return d.jsx(Ae.svg,{...o,ref:e,width:r,height:s,viewBox:"0 0 30 10",preserveAspectRatio:"none",children:t.asChild?n:d.jsx("polygon",{points:"0,0 30,0 15,10"})})});g3.displayName=Kne;var Wne=g3;function m3(t){const[e,n]=w.useState(void 0);return yi(()=>{if(t){n({width:t.offsetWidth,height:t.offsetHeight});const r=new ResizeObserver(s=>{if(!Array.isArray(s)||!s.length)return;const o=s[0];let i,a;if("borderBoxSize"in o){const l=o.borderBoxSize,c=Array.isArray(l)?l[0]:l;i=c.inlineSize,a=c.blockSize}else i=t.offsetWidth,a=t.offsetHeight;n({width:i,height:a})});return r.observe(t,{box:"border-box"}),()=>r.unobserve(t)}else n(void 0)},[t]),e}var Vb="Popper",[y3,sm]=Ws(Vb),[Gne,S3]=y3(Vb),v3=t=>{const{__scopePopper:e,children:n}=t,[r,s]=w.useState(null);return d.jsx(Gne,{scope:e,anchor:r,onAnchorChange:s,children:n})};v3.displayName=Vb;var x3="PopperAnchor",w3=w.forwardRef((t,e)=>{const{__scopePopper:n,virtualRef:r,...s}=t,o=S3(x3,n),i=w.useRef(null),a=Qe(e,i);return w.useEffect(()=>{o.onAnchorChange((r==null?void 0:r.current)||i.current)}),r?null:d.jsx(Ae.div,{...s,ref:a})});w3.displayName=x3;var Yb="PopperContent",[Vne,Yne]=y3(Yb),b3=w.forwardRef((t,e)=>{var Ne,lt,$e,Ye,We,er;const{__scopePopper:n,side:r="bottom",sideOffset:s=0,align:o="center",alignOffset:i=0,arrowPadding:a=0,avoidCollisions:l=!0,collisionBoundary:c=[],collisionPadding:u=0,sticky:h="partial",hideWhenDetached:f=!1,updatePositionStrategy:p="optimized",onPlaced:g,...m}=t,v=S3(Yb,n),[y,S]=w.useState(null),b=Qe(e,$t=>S($t)),[P,C]=w.useState(null),_=m3(P),E=(_==null?void 0:_.width)??0,k=(_==null?void 0:_.height)??0,D=r+(o!=="center"?"-"+o:""),T=typeof u=="number"?u:{top:0,right:0,bottom:0,left:0,...u},j=Array.isArray(c)?c:[c],L=j.length>0,M={padding:T,boundary:j.filter(qne),altBoundary:L},{refs:O,floatingStyles:F,placement:B,isPositioned:K,middlewareData:R}=Rne({strategy:"fixed",placement:D,whileElementsMounted:(...$t)=>Ene(...$t,{animationFrame:p==="always"}),elements:{reference:v.anchor},middleware:[$ne({mainAxis:s+k,alignmentAxis:i}),l&&Fne({mainAxis:!0,crossAxis:!1,limiter:h==="partial"?Nne():void 0,...M}),l&&zne({...M}),Bne({...M,apply:({elements:$t,rects:On,availableWidth:Mt,availableHeight:Ft})=>{const{width:jo,height:Ys}=On.reference,Oo=$t.floating.style;Oo.setProperty("--radix-popper-available-width",`${Mt}px`),Oo.setProperty("--radix-popper-available-height",`${Ft}px`),Oo.setProperty("--radix-popper-anchor-width",`${jo}px`),Oo.setProperty("--radix-popper-anchor-height",`${Ys}px`)}}),P&&Hne({element:P,padding:a}),Zne({arrowWidth:E,arrowHeight:k}),f&&Une({strategy:"referenceHidden",...M})]}),[H,X]=_3(B),te=qt(g);yi(()=>{K&&(te==null||te())},[K,te]);const le=(Ne=R.arrow)==null?void 0:Ne.x,de=(lt=R.arrow)==null?void 0:lt.y,Me=(($e=R.arrow)==null?void 0:$e.centerOffset)!==0,[oe,Ue]=w.useState();return yi(()=>{y&&Ue(window.getComputedStyle(y).zIndex)},[y]),d.jsx("div",{ref:O.setFloating,"data-radix-popper-content-wrapper":"",style:{...F,transform:K?F.transform:"translate(0, -200%)",minWidth:"max-content",zIndex:oe,"--radix-popper-transform-origin":[(Ye=R.transformOrigin)==null?void 0:Ye.x,(We=R.transformOrigin)==null?void 0:We.y].join(" "),...((er=R.hide)==null?void 0:er.referenceHidden)&&{visibility:"hidden",pointerEvents:"none"}},dir:t.dir,children:d.jsx(Vne,{scope:n,placedSide:H,onArrowChange:C,arrowX:le,arrowY:de,shouldHideArrow:Me,children:d.jsx(Ae.div,{"data-side":H,"data-align":X,...m,ref:b,style:{...m.style,animation:K?void 0:"none"}})})})});b3.displayName=Yb;var P3="PopperArrow",Xne={top:"bottom",right:"left",bottom:"top",left:"right"},C3=w.forwardRef(function(e,n){const{__scopePopper:r,...s}=e,o=Yne(P3,r),i=Xne[o.placedSide];return d.jsx("span",{ref:o.onArrowChange,style:{position:"absolute",left:o.arrowX,top:o.arrowY,[i]:0,transformOrigin:{top:"",right:"0 0",bottom:"center 0",left:"100% 0"}[o.placedSide],transform:{top:"translateY(100%)",right:"translateY(50%) rotate(90deg) translateX(-50%)",bottom:"rotate(180deg)",left:"translateY(50%) rotate(-90deg) translateX(50%)"}[o.placedSide],visibility:o.shouldHideArrow?"hidden":void 0},children:d.jsx(Wne,{...s,ref:n,style:{...s.style,display:"block"}})})});C3.displayName=P3;function qne(t){return t!==null}var Zne=t=>({name:"transformOrigin",options:t,fn(e){var v,y,S;const{placement:n,rects:r,middlewareData:s}=e,i=((v=s.arrow)==null?void 0:v.centerOffset)!==0,a=i?0:t.arrowWidth,l=i?0:t.arrowHeight,[c,u]=_3(n),h={start:"0%",center:"50%",end:"100%"}[u],f=(((y=s.arrow)==null?void 0:y.x)??0)+a/2,p=(((S=s.arrow)==null?void 0:S.y)??0)+l/2;let g="",m="";return c==="bottom"?(g=i?h:`${f}px`,m=`${-l}px`):c==="top"?(g=i?h:`${f}px`,m=`${r.floating.height+l}px`):c==="right"?(g=`${-l}px`,m=i?h:`${p}px`):c==="left"&&(g=`${r.floating.width+l}px`,m=i?h:`${p}px`),{data:{x:g,y:m}}}});function _3(t){const[e,n="center"]=t.split("-");return[e,n]}var Xb=v3,qb=w3,I3=b3,E3=C3,Qne="Portal",Pd=w.forwardRef((t,e)=>{var a;const{container:n,...r}=t,[s,o]=w.useState(!1);yi(()=>o(!0),[]);const i=n||s&&((a=globalThis==null?void 0:globalThis.document)==null?void 0:a.body);return i?d8.createPortal(d.jsx(Ae.div,{...r,ref:e}),i):null});Pd.displayName=Qne;function Jne(t,e){return w.useReducer((n,r)=>e[n][r]??n,t)}var ds=t=>{const{present:e,children:n}=t,r=ere(e),s=typeof n=="function"?n({present:r.isPresent}):w.Children.only(n),o=Qe(r.ref,tre(s));return typeof n=="function"||r.isPresent?w.cloneElement(s,{ref:o}):null};ds.displayName="Presence";function ere(t){const[e,n]=w.useState(),r=w.useRef({}),s=w.useRef(t),o=w.useRef("none"),i=t?"mounted":"unmounted",[a,l]=Jne(i,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return w.useEffect(()=>{const c=Ph(r.current);o.current=a==="mounted"?c:"none"},[a]),yi(()=>{const c=r.current,u=s.current;if(u!==t){const f=o.current,p=Ph(c);t?l("MOUNT"):p==="none"||(c==null?void 0:c.display)==="none"?l("UNMOUNT"):l(u&&f!==p?"ANIMATION_OUT":"UNMOUNT"),s.current=t}},[t,l]),yi(()=>{if(e){let c;const u=e.ownerDocument.defaultView??window,h=p=>{const m=Ph(r.current).includes(p.animationName);if(p.target===e&&m&&(l("ANIMATION_END"),!s.current)){const v=e.style.animationFillMode;e.style.animationFillMode="forwards",c=u.setTimeout(()=>{e.style.animationFillMode==="forwards"&&(e.style.animationFillMode=v)})}},f=p=>{p.target===e&&(o.current=Ph(r.current))};return e.addEventListener("animationstart",f),e.addEventListener("animationcancel",h),e.addEventListener("animationend",h),()=>{u.clearTimeout(c),e.removeEventListener("animationstart",f),e.removeEventListener("animationcancel",h),e.removeEventListener("animationend",h)}}else l("ANIMATION_END")},[e,l]),{isPresent:["mounted","unmountSuspended"].includes(a),ref:w.useCallback(c=>{c&&(r.current=getComputedStyle(c)),n(c)},[])}}function Ph(t){return(t==null?void 0:t.animationName)||"none"}function tre(t){var r,s;let e=(r=Object.getOwnPropertyDescriptor(t.props,"ref"))==null?void 0:r.get,n=e&&"isReactWarning"in e&&e.isReactWarning;return n?t.ref:(e=(s=Object.getOwnPropertyDescriptor(t,"ref"))==null?void 0:s.get,n=e&&"isReactWarning"in e&&e.isReactWarning,n?t.props.ref:t.props.ref||t.ref)}function ji({prop:t,defaultProp:e,onChange:n=()=>{}}){const[r,s]=nre({defaultProp:e,onChange:n}),o=t!==void 0,i=o?t:r,a=qt(n),l=w.useCallback(c=>{if(o){const h=typeof c=="function"?c(t):c;h!==t&&a(h)}else s(c)},[o,t,s,a]);return[i,l]}function nre({defaultProp:t,onChange:e}){const n=w.useState(t),[r]=n,s=w.useRef(r),o=qt(e);return w.useEffect(()=>{s.current!==r&&(o(r),s.current=r)},[r,s,o]),n}var lS="rovingFocusGroup.onEntryFocus",rre={bubbles:!1,cancelable:!0},om="RovingFocusGroup",[Nx,k3,sre]=Jg(om),[ore,T3]=Ws(om,[sre]),[ire,are]=ore(om),M3=w.forwardRef((t,e)=>d.jsx(Nx.Provider,{scope:t.__scopeRovingFocusGroup,children:d.jsx(Nx.Slot,{scope:t.__scopeRovingFocusGroup,children:d.jsx(lre,{...t,ref:e})})}));M3.displayName=om;var lre=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,orientation:r,loop:s=!1,dir:o,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,preventScrollOnEntryFocus:u=!1,...h}=t,f=w.useRef(null),p=Qe(e,f),g=Fb(o),[m=null,v]=ji({prop:i,defaultProp:a,onChange:l}),[y,S]=w.useState(!1),b=qt(c),P=k3(n),C=w.useRef(!1),[_,E]=w.useState(0);return w.useEffect(()=>{const k=f.current;if(k)return k.addEventListener(lS,b),()=>k.removeEventListener(lS,b)},[b]),d.jsx(ire,{scope:n,orientation:r,dir:g,loop:s,currentTabStopId:m,onItemFocus:w.useCallback(k=>v(k),[v]),onItemShiftTab:w.useCallback(()=>S(!0),[]),onFocusableItemAdd:w.useCallback(()=>E(k=>k+1),[]),onFocusableItemRemove:w.useCallback(()=>E(k=>k-1),[]),children:d.jsx(Ae.div,{tabIndex:y||_===0?-1:0,"data-orientation":r,...h,ref:p,style:{outline:"none",...t.style},onMouseDown:se(t.onMouseDown,()=>{C.current=!0}),onFocus:se(t.onFocus,k=>{const D=!C.current;if(k.target===k.currentTarget&&D&&!y){const T=new CustomEvent(lS,rre);if(k.currentTarget.dispatchEvent(T),!T.defaultPrevented){const j=P().filter(B=>B.focusable),L=j.find(B=>B.active),M=j.find(B=>B.id===m),F=[L,M,...j].filter(Boolean).map(B=>B.ref.current);O3(F,u)}}C.current=!1}),onBlur:se(t.onBlur,()=>S(!1))})})}),A3="RovingFocusGroupItem",j3=w.forwardRef((t,e)=>{const{__scopeRovingFocusGroup:n,focusable:r=!0,active:s=!1,tabStopId:o,...i}=t,a=mo(),l=o||a,c=are(A3,n),u=c.currentTabStopId===l,h=k3(n),{onFocusableItemAdd:f,onFocusableItemRemove:p}=c;return w.useEffect(()=>{if(r)return f(),()=>p()},[r,f,p]),d.jsx(Nx.ItemSlot,{scope:n,id:l,focusable:r,active:s,children:d.jsx(Ae.span,{tabIndex:u?0:-1,"data-orientation":c.orientation,...i,ref:e,onMouseDown:se(t.onMouseDown,g=>{r?c.onItemFocus(l):g.preventDefault()}),onFocus:se(t.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(t.onKeyDown,g=>{if(g.key==="Tab"&&g.shiftKey){c.onItemShiftTab();return}if(g.target!==g.currentTarget)return;const m=dre(g,c.orientation,c.dir);if(m!==void 0){if(g.metaKey||g.ctrlKey||g.altKey||g.shiftKey)return;g.preventDefault();let y=h().filter(S=>S.focusable).map(S=>S.ref.current);if(m==="last")y.reverse();else if(m==="prev"||m==="next"){m==="prev"&&y.reverse();const S=y.indexOf(g.currentTarget);y=c.loop?hre(y,S+1):y.slice(S+1)}setTimeout(()=>O3(y))}})})})});j3.displayName=A3;var cre={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function ure(t,e){return e!=="rtl"?t:t==="ArrowLeft"?"ArrowRight":t==="ArrowRight"?"ArrowLeft":t}function dre(t,e,n){const r=ure(t.key,n);if(!(e==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(e==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return cre[r]}function O3(t,e=!1){const n=document.activeElement;for(const r of t)if(r===n||(r.focus({preventScroll:e}),document.activeElement!==n))return}function hre(t,e){return t.map((n,r)=>t[(e+r)%t.length])}var fre=M3,pre=j3,gre=function(t){if(typeof document>"u")return null;var e=Array.isArray(t)?t[0]:t;return e.ownerDocument.body},Fa=new WeakMap,Ch=new WeakMap,_h={},cS=0,D3=function(t){return t&&(t.host||D3(t.parentNode))},mre=function(t,e){return e.map(function(n){if(t.contains(n))return n;var r=D3(n);return r&&t.contains(r)?r:(console.error("aria-hidden",n,"in not contained inside",t,". Doing nothing"),null)}).filter(function(n){return!!n})},yre=function(t,e,n,r){var s=mre(e,Array.isArray(t)?t:[t]);_h[n]||(_h[n]=new WeakMap);var o=_h[n],i=[],a=new Set,l=new Set(s),c=function(h){!h||a.has(h)||(a.add(h),c(h.parentNode))};s.forEach(c);var u=function(h){!h||l.has(h)||Array.prototype.forEach.call(h.children,function(f){if(a.has(f))u(f);else try{var p=f.getAttribute(r),g=p!==null&&p!=="false",m=(Fa.get(f)||0)+1,v=(o.get(f)||0)+1;Fa.set(f,m),o.set(f,v),i.push(f),m===1&&g&&Ch.set(f,!0),v===1&&f.setAttribute(n,"true"),g||f.setAttribute(r,"true")}catch(y){console.error("aria-hidden: cannot operate on ",f,y)}})};return u(e),a.clear(),cS++,function(){i.forEach(function(h){var f=Fa.get(h)-1,p=o.get(h)-1;Fa.set(h,f),o.set(h,p),f||(Ch.has(h)||h.removeAttribute(r),Ch.delete(h)),p||h.removeAttribute(n)}),cS--,cS||(Fa=new WeakMap,Fa=new WeakMap,Ch=new WeakMap,_h={})}},Zb=function(t,e,n){n===void 0&&(n="data-aria-hidden");var r=Array.from(Array.isArray(t)?t:[t]),s=gre(t);return s?(r.push.apply(r,Array.from(s.querySelectorAll("[aria-live]"))),yre(r,s,n,"aria-hidden")):function(){return null}},Cs=function(){return Cs=Object.assign||function(e){for(var n,r=1,s=arguments.length;r<s;r++){n=arguments[r];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},Cs.apply(this,arguments)};function R3(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var s=0,r=Object.getOwnPropertySymbols(t);s<r.length;s++)e.indexOf(r[s])<0&&Object.prototype.propertyIsEnumerable.call(t,r[s])&&(n[r[s]]=t[r[s]]);return n}function Sre(t,e,n){if(n||arguments.length===2)for(var r=0,s=e.length,o;r<s;r++)(o||!(r in e))&&(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}var gf="right-scroll-bar-position",mf="width-before-scroll-bar",vre="with-scroll-bars-hidden",xre="--removed-body-scroll-bar-size";function uS(t,e){return typeof t=="function"?t(e):t&&(t.current=e),t}function wre(t,e){var n=w.useState(function(){return{value:t,callback:e,facade:{get current(){return n.value},set current(r){var s=n.value;s!==r&&(n.value=r,n.callback(r,s))}}}})[0];return n.callback=e,n.facade}var bre=typeof window<"u"?w.useLayoutEffect:w.useEffect,lE=new WeakMap;function Pre(t,e){var n=wre(null,function(r){return t.forEach(function(s){return uS(s,r)})});return bre(function(){var r=lE.get(n);if(r){var s=new Set(r),o=new Set(t),i=n.current;s.forEach(function(a){o.has(a)||uS(a,null)}),o.forEach(function(a){s.has(a)||uS(a,i)})}lE.set(n,t)},[t]),n}function Cre(t){return t}function _re(t,e){e===void 0&&(e=Cre);var n=[],r=!1,s={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]:t},useMedium:function(o){var i=e(o,r);return n.push(i),function(){n=n.filter(function(a){return a!==i})}},assignSyncMedium:function(o){for(r=!0;n.length;){var i=n;n=[],i.forEach(o)}n={push:function(a){return o(a)},filter:function(){return n}}},assignMedium:function(o){r=!0;var i=[];if(n.length){var a=n;n=[],a.forEach(o),i=n}var l=function(){var u=i;i=[],u.forEach(o)},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 s}function Ire(t){t===void 0&&(t={});var e=_re(null);return e.options=Cs({async:!0,ssr:!1},t),e}var L3=function(t){var e=t.sideCar,n=R3(t,["sideCar"]);if(!e)throw new Error("Sidecar: please provide `sideCar` property to import the right car");var r=e.read();if(!r)throw new Error("Sidecar medium not found");return w.createElement(r,Cs({},n))};L3.isSideCarExport=!0;function Ere(t,e){return t.useMedium(e),L3}var $3=Ire(),dS=function(){},im=w.forwardRef(function(t,e){var n=w.useRef(null),r=w.useState({onScrollCapture:dS,onWheelCapture:dS,onTouchMoveCapture:dS}),s=r[0],o=r[1],i=t.forwardProps,a=t.children,l=t.className,c=t.removeScrollBar,u=t.enabled,h=t.shards,f=t.sideCar,p=t.noIsolation,g=t.inert,m=t.allowPinchZoom,v=t.as,y=v===void 0?"div":v,S=t.gapMode,b=R3(t,["forwardProps","children","className","removeScrollBar","enabled","shards","sideCar","noIsolation","inert","allowPinchZoom","as","gapMode"]),P=f,C=Pre([n,e]),_=Cs(Cs({},b),s);return w.createElement(w.Fragment,null,u&&w.createElement(P,{sideCar:$3,removeScrollBar:c,shards:h,noIsolation:p,inert:g,setCallbacks:o,allowPinchZoom:!!m,lockRef:n,gapMode:S}),i?w.cloneElement(w.Children.only(a),Cs(Cs({},_),{ref:C})):w.createElement(y,Cs({},_,{className:l,ref:C}),a))});im.defaultProps={enabled:!0,removeScrollBar:!0,inert:!1};im.classNames={fullWidth:mf,zeroRight:gf};var kre=function(){if(typeof __webpack_nonce__<"u")return __webpack_nonce__};function Tre(){if(!document)return null;var t=document.createElement("style");t.type="text/css";var e=kre();return e&&t.setAttribute("nonce",e),t}function Mre(t,e){t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e))}function Are(t){var e=document.head||document.getElementsByTagName("head")[0];e.appendChild(t)}var jre=function(){var t=0,e=null;return{add:function(n){t==0&&(e=Tre())&&(Mre(e,n),Are(e)),t++},remove:function(){t--,!t&&e&&(e.parentNode&&e.parentNode.removeChild(e),e=null)}}},Ore=function(){var t=jre();return function(e,n){w.useEffect(function(){return t.add(e),function(){t.remove()}},[e&&n])}},F3=function(){var t=Ore(),e=function(n){var r=n.styles,s=n.dynamic;return t(r,s),null};return e},Dre={left:0,top:0,right:0,gap:0},hS=function(t){return parseInt(t||"",10)||0},Rre=function(t){var e=window.getComputedStyle(document.body),n=e[t==="padding"?"paddingLeft":"marginLeft"],r=e[t==="padding"?"paddingTop":"marginTop"],s=e[t==="padding"?"paddingRight":"marginRight"];return[hS(n),hS(r),hS(s)]},Lre=function(t){if(t===void 0&&(t="margin"),typeof window>"u")return Dre;var e=Rre(t),n=document.documentElement.clientWidth,r=window.innerWidth;return{left:e[0],top:e[1],right:e[2],gap:Math.max(0,r-n+e[2]-e[0])}},$re=F3(),Cl="data-scroll-locked",Fre=function(t,e,n,r){var s=t.left,o=t.top,i=t.right,a=t.gap;return n===void 0&&(n="margin"),`
|
|
196
196
|
.`.concat(vre,` {
|
|
197
197
|
overflow: hidden `).concat(r,`;
|
|
198
198
|
padding-right: `).concat(a,"px ").concat(r,`;
|
|
@@ -236,7 +236,7 @@ To remove the watermark, please purchase a license at tldraw.dev.
|
|
|
236
236
|
|
|
237
237
|
If you want to hide the \`${e.titleName}\`, you can wrap it with our VisuallyHidden component.
|
|
238
238
|
|
|
239
|
-
For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return w.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},zoe="DialogDescriptionWarning",Boe=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${g$(zoe).contentName}}.`;return w.useEffect(()=>{var o;const s=(o=t.current)==null?void 0:o.getAttribute("aria-describedby");e&&s&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},Uoe=r$,Hoe=i$,Koe=a$,Woe=l$;const zs=w.memo(function({small:e,invertIcon:n,icon:r,color:s,className:o,...i}){const a=h1(),l=a.icons[r]??a.icons["question-mark-circle"],c=w.useRef(null);return w.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?d.jsx("div",{className:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},o)}):d.jsx("div",{...i,ref:c,className:ce("tlui-icon",{"tlui-icon__small":e},o),style:{color:s,mask:`url(${l}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})});function be({icon:t,small:e,invertIcon:n}){return d.jsx(zs,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function dm({className:t,children:e}){return d.jsx("div",{className:ce("tlui-dialog__header",t),children:e})}function hm({className:t,children:e}){return d.jsx(u$,{dir:"ltr",className:ce("tlui-dialog__header__title",t),children:e})}function fm(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(f$,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon","aria-label":"Close",onTouchEnd:t=>t.target.click(),children:d.jsx(be,{small:!0,icon:"cross-2"})})})})}function Yu({className:t,children:e,style:n}){return d.jsx("div",{className:ce("tlui-dialog__body",t),style:n,children:e})}function y1({className:t,children:e}){return d.jsx("div",{className:ce("tlui-dialog__footer",t),children:e})}const pm=w.forwardRef(function({className:e,label:n,icon:r,iconLeft:s,autoSelect:o=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:f,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:g=!1,children:m,value:v},y){const S=Ti(),b=w.useRef(null);w.useImperativeHandle(y,()=>b.current);const P=Ee(),C=w.useRef(a??""),_=w.useRef(a??""),[E,k]=w.useState(!1),D=w.useCallback(M=>{k(!0);const O=M.currentTarget;_.current=O.value,S?S.timers.requestAnimationFrame(()=>{o&&O.select()}):kx.requestAnimationFrame("anon",()=>{o&&O.select()}),f==null||f()},[o,S,f]),T=w.useCallback(M=>{const O=M.currentTarget.value;_.current=O,u==null||u(O)},[u]),j=w.useCallback(M=>{switch(M.key){case"Enter":{M.currentTarget.blur(),Ct(M),c==null||c(M.currentTarget.value);break}case"Escape":{M.currentTarget.value=C.current,h==null||h(M.currentTarget.value),M.currentTarget.blur(),Ct(M);break}}},[c,h]),L=w.useCallback(M=>{k(!1);const O=M.currentTarget.value;p==null||p(O)},[p]);return w.useEffect(()=>{if(!Ge.isIos)return;const M=window.visualViewport;if(E&&g&&M){const O=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return M.addEventListener("resize",O),M.addEventListener("scroll",O),S?S.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}):kx.requestAnimationFrame("anon",()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{M.removeEventListener("resize",O),M.removeEventListener("scroll",O)}}},[E,S,g]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,n&&d.jsx("label",{children:P(n)}),s&&d.jsx(zs,{icon:s,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:ce("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:j,onChange:T,onFocus:D,onBlur:L,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(zs,{icon:r,small:!!n})]})});function pE(t){return gr.isValid(t)?{isValid:!0,hasProtocol:!0}:gr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Goe=Zt(function({onClose:e}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(Voe,{onClose:e,selectedShape:r}):null}),Voe=Zt(function({onClose:e,selectedShape:n}){const r=z(),s=Ee(),o=w.useRef(null);w.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var g;return(g=o.current)==null?void 0:g.focus()})},[r]);const i=w.useRef(n.props.url),[a,l]=w.useState(()=>{const g=pE(n.props.url),m=g.isValid===!0?g.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=w.useCallback(g=>{const m=g.replace(/https?:\/\/(https?:\/\/)/,(S,b)=>b),v=pE(m),y=v.isValid===!0?v.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:y,valid:v.isValid})},[]),u=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(r.updateShapes([{id:g.id,type:g.type,props:{url:""}}]),e())},[r,e]),h=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(g&&"url"in g.props&&g.props.url!==a.safe&&r.updateShapes([{id:g.id,type:g.type,props:{url:a.safe}}]),e())},[r,e,a]),f=w.useCallback(()=>{e()},[e]);if(!n)return e(),null;const p=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:s("edit-link-dialog.title")}),d.jsx(fm,{})]}),d.jsx(Yu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(pm,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:f}),d.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),d.jsxs(y1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:f,onTouchEnd:f,children:d.jsx(bt,{children:s("edit-link-dialog.cancel")})}),p?d.jsx(ue,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(bt,{children:s("edit-link-dialog.clear")})}):d.jsx(ue,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(bt,{children:s("edit-link-dialog.save")})})]})]})});var Yoe={};const gE=/(^\/r\/[^/]+\/?$)/,S1=[{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:t=>{const e=ge(t);if(e&&e.pathname.match(gE))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(gE))return t}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{if(t.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!t.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${t}`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:t=>{if(t.includes("/maps/embed?"))return t;if(t.includes("/maps/")){const e=t.match(/@(.*?),(.*?),(.*?)z/);let n;if(e){const[,r,s,o]=e;n=`https://${new URL(t).host.replace("www.","")}/maps/embed/v1/view?key=${Yoe.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${s}&zoom=${o}`}else n="";return n}},fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t),n=e&&e.pathname.match(/\/v\/(.+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:t=>{const e=ge(t),n=e&&e.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:t=>{const e=ge(t),n=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:t=>{const e=ge(t),n=e&&e.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:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/embed/${o}`}},fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:t=>{const e=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/embed/${s}`}},fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=ge(t);if(!e)return;const n=e.hostname.replace(/^www./,"");if(n==="youtu.be")return`https://www.youtube.com/embed/${e.pathname.split("/").filter(Boolean)[0]}`;if((n==="youtube.com"||n==="m.youtube.com")&&e.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${e.searchParams.get("v")}`},fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:t=>{const e=ge(t),n=e==null?void 0:e.searchParams.get("cid");if(e!=null&&e.pathname.match(/\/calendar\/u\/0/)&&n){e.pathname="/calendar/embed";const r=Array.from(e.searchParams.keys());for(const s of r)e.searchParams.delete(s);return e.searchParams.set("src",n),e.href}},fromEmbedUrl:t=>{const e=ge(t),n=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&n){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const s of r)e.searchParams.delete(s);return e.searchParams.set("cid",n),e.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:t=>{const e=ge(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/pub\/?$/))){e.pathname=e.pathname.replace(/\/pub$/,"/embed");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}},fromEmbedUrl:t=>{const e=ge(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return t.split("/").pop()?t:void 0},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return t.split("/").pop()?t:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${t}?embed=true`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="vimeo.com"&&e.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+e.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="player.vimeo.com"){const n=e.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:t=>{const e=ge(t);if(e&&e.hash.match(/#room=/))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hash.match(/#room=/))return t}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}/embed${e.pathname}?cell=*`;if(e&&e.pathname.match(/^\/d\/([^/]+)\/?$/)){const n=e.pathname.replace(/^\/d/,"");return`${e.origin}/embed${n}?cell=*`}},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","")}#cell-*`;if(e&&e.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","/d")}#cell-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${t}?embed`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],Xoe={"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},qoe=S1.map(t=>t.type);function Zoe(t){return qoe.includes(t)}function Qoe(t){return"icon"in t}function m$(){return z().getShapeUtil("embed")}function v1(){const t=m$();return e=>t?t.getEmbedDefinition(e):void 0}function Joe(){const t=m$();return t?t.getEmbedDefinitions():[]}const y$=Zt(function({onClose:e}){const n=z(),r=Ee(),s=h1(),[o,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,f]=w.useState(!1),p=w.useRef(-1),g=Joe(),m=v1();return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:o?`${r("embed-dialog.title")} — ${o.title}`:r("embed-dialog.title")}),d.jsx(fm,{})]}),o?d.jsxs(d.Fragment,{children:[d.jsxs(Yu,{className:"tlui-embed-dialog__enter",children:[d.jsx(pm,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:v=>{l(v);const y=m(v);u(y&&y.definition.type===o.type?y:null),f(!1),clearTimeout(p.current),p.current=n.timers.setTimeout(()=>f(!y),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",o.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:o.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(zs,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(y1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(bt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(ue,{type:"normal",onClick:e,children:d.jsx(bt,{children:r("embed-dialog.cancel")})}),d.jsx(ue,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageBounds().center,embed:c.definition}),e())},children:d.jsx(bt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(Yu,{className:"tlui-embed-dialog__list",children:g.map(v=>{const y=Zoe(v.type)?s.embedIcons[v.type]:Qoe(v)?v.icon:void 0;return d.jsxs(ue,{type:"menu",onClick:()=>i(v),children:[d.jsx(bt,{children:v.title}),y&&d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${y})`}})]},v.type)})})})]})});async function eie(t,e,n){const r=me(e.map(a=>{const l=t.getShape(a);if(!(!l||t.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||t.isShapeOfType(a,"image"))return}const s=[];if(n!==void 0){const a=r.map(l=>({shape:l,bounds:t.getShapeMaskedPageBounds(l).clone().expandBy(n)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){s[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of s)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||s.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>t.getShapeMaskedPageBounds(l)));s.push({shapes:r,bounds:a})}const o=t.options.flattenImageBoundsPadding;for(const a of s){n!==void 0&&a.bounds.expandBy(-n);const l=await t.getSvgString(a.shapes,{padding:o});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),u=await t.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return js(()=>{for(const a of s){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=t.findCommonAncestor(u)??t.getCurrentPageId();if(!h)continue;let f="a1";for(const y of u)if(y.parentId===h){y.index>f&&(f=y.index);break}let p,g,m;if(Fn(h)){const y=t.getShape(h);if(!y)continue;const S=t.getPointInShapeSpace(y,{x:c.x,y:c.y});m=t.getShapePageTransform(h).rotation(),S.sub(new x(o,o).rot(-m)),p=S.x,g=S.y}else p=c.x-o,g=c.y-o,m=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Ke();t.createShape({id:v,type:"image",index:f,parentId:h,x:p,y:g,rotation:-m,props:{assetId:l.id,w:c.w+o*2,h:c.h+o*2}}),i.push(v)}}),i}function gm(){const t=Ti();return(t==null?void 0:t.store.props.collaboration)!==void 0}function tie(){const t=Ti();return U("sync status",()=>{var e;return(e=t==null?void 0:t.store.props.collaboration)!=null&&e.status?t.store.props.collaboration.status.get():null},[t])}const fS=[0,389,436,476,580,640,840,1023];var St=(t=>(t[t.ZERO=0]="ZERO",t[t.MOBILE_XXS=1]="MOBILE_XXS",t[t.MOBILE_XS=2]="MOBILE_XS",t[t.MOBILE_SM=3]="MOBILE_SM",t[t.MOBILE=4]="MOBILE",t[t.TABLET_SM=5]="TABLET_SM",t[t.TABLET=6]="TABLET",t[t.DESKTOP=7]="DESKTOP",t))(St||{});const S$=ke.createContext(null);function nie({forceMobile:t=!1,children:e}){const n=Ti(),r=U("breakpoint",()=>{const{width:s}=(n==null?void 0:n.getViewportScreenBounds())??{width:window.innerWidth},o=t?St.MOBILE_SM:fS.length-1;for(let i=0;i<o;i++)if(s>fS[i]&&s<=fS[i+1])return i;return o},[n]);return d.jsx(S$.Provider,{value:r,children:e})}function An(){const t=w.useContext(S$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const v$=w.createContext(null);function rie({context:t,children:e}){const n=Jt(),r=q0("dialogs",[]),s=w.useMemo(()=>({dialogs:r,addDialog(o){const i=o.id??ze();return r.update(a=>[...a.filter(l=>l.id!==o.id),{...o,id:i}]),n("open-menu",{source:"dialog",id:i}),Vr.addOpenMenu(i,t),i},removeDialog(o){var a;const i=r.get().find(l=>l.id===o);return i&&((a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:o}),Vr.deleteOpenMenu(o,t),r.update(l=>l.filter(c=>c!==i))),o},clearDialogs(){const o=r.get();o.length!==0&&(o.forEach(i=>{var a;(a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:i.id}),Vr.deleteOpenMenu(i.id,t)}),r.set([]))}}),[n,r,t]);return d.jsx(v$.Provider,{value:s,children:e})}function Ed(){const t=w.useContext(v$);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}var sie="VisuallyHidden",x1=w.forwardRef((t,e)=>d.jsx(Ae.span,{...t,ref:e,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",...t.style}}));x1.displayName=sie;var w1="ToastProvider",[b1,oie,iie]=Jg("Toast"),[x$,gge]=Ws("Toast",[iie]),[aie,mm]=x$(w1),w$=t=>{const{__scopeToast:e,label:n="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:o=50,children:i}=t,[a,l]=w.useState(null),[c,u]=w.useState(0),h=w.useRef(!1),f=w.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${w1}\`. Expected non-empty \`string\`.`),d.jsx(b1.Provider,{scope:e,children:d.jsx(aie,{scope:e,label:n,duration:r,swipeDirection:s,swipeThreshold:o,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:w.useCallback(()=>u(p=>p+1),[]),onToastRemove:w.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:f,children:i})})};w$.displayName=w1;var b$="ToastViewport",lie=["F8"],Hx="toast.viewportPause",Kx="toast.viewportResume",P$=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=lie,label:s="Notifications ({hotkey})",...o}=t,i=mm(b$,n),a=oie(n),l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),h=w.useRef(null),f=Qe(e,h,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=i.toastCount>0;w.useEffect(()=>{const v=y=>{var b;r.length!==0&&r.every(P=>y[P]||y.code===P)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,y=h.current;if(g&&v&&y){const S=()=>{if(!i.isClosePausedRef.current){const _=new CustomEvent(Hx);y.dispatchEvent(_),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const _=new CustomEvent(Kx);y.dispatchEvent(_),i.isClosePausedRef.current=!1}},P=_=>{!v.contains(_.relatedTarget)&&b()},C=()=>{v.contains(document.activeElement)||b()};return v.addEventListener("focusin",S),v.addEventListener("focusout",P),v.addEventListener("pointermove",S),v.addEventListener("pointerleave",C),window.addEventListener("blur",S),window.addEventListener("focus",b),()=>{v.removeEventListener("focusin",S),v.removeEventListener("focusout",P),v.removeEventListener("pointermove",S),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",S),window.removeEventListener("focus",b)}}},[g,i.isClosePausedRef]);const m=w.useCallback(({tabbingDirection:v})=>{const S=a().map(b=>{const P=b.ref.current,C=[P,...wie(P)];return v==="forwards"?C:C.reverse()});return(v==="forwards"?S.reverse():S).flat()},[a]);return w.useEffect(()=>{const v=h.current;if(v){const y=S=>{var C,_,E;const b=S.altKey||S.ctrlKey||S.metaKey;if(S.key==="Tab"&&!b){const k=document.activeElement,D=S.shiftKey;if(S.target===v&&D){(C=c.current)==null||C.focus();return}const L=m({tabbingDirection:D?"backwards":"forwards"}),M=L.findIndex(O=>O===k);pS(L.slice(M+1))?S.preventDefault():D?(_=c.current)==null||_.focus():(E=u.current)==null||E.focus()}};return v.addEventListener("keydown",y),()=>v.removeEventListener("keydown",y)}},[a,m]),d.jsxs($te,{ref:l,role:"region","aria-label":s.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&d.jsx(Wx,{ref:c,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"forwards"});pS(v)}}),d.jsx(b1.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...o,ref:f})}),g&&d.jsx(Wx,{ref:u,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"backwards"});pS(v)}})]})});P$.displayName=b$;var C$="ToastFocusProxy",Wx=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...s}=t,o=mm(C$,n);return d.jsx(x1,{"aria-hidden":!0,tabIndex:0,...s,ref:e,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=o.viewport)!=null&&c.contains(a))&&r()}})});Wx.displayName=C$;var ym="Toast",cie="toast.swipeStart",uie="toast.swipeMove",die="toast.swipeCancel",hie="toast.swipeEnd",_$=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:s,onOpenChange:o,...i}=t,[a=!0,l]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(ds,{present:n||a,children:d.jsx(gie,{open:a,...i,ref:e,onClose:()=>l(!1),onPause:qt(t.onPause),onResume:qt(t.onResume),onSwipeStart:se(t.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:se(t.onSwipeMove,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:se(t.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(t.onSwipeEnd,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});_$.displayName=ym;var[fie,pie]=x$(ym,{onClose(){}}),gie=w.forwardRef((t,e)=>{const{__scopeToast:n,type:r="foreground",duration:s,open:o,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:f,onSwipeEnd:p,...g}=t,m=mm(ym,n),[v,y]=w.useState(null),S=Qe(e,O=>y(O)),b=w.useRef(null),P=w.useRef(null),C=s||m.duration,_=w.useRef(0),E=w.useRef(C),k=w.useRef(0),{onToastAdd:D,onToastRemove:T}=m,j=qt(()=>{var F;(v==null?void 0:v.contains(document.activeElement))&&((F=m.viewport)==null||F.focus()),i()}),L=w.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),_.current=new Date().getTime(),k.current=window.setTimeout(j,O))},[j]);w.useEffect(()=>{const O=m.viewport;if(O){const F=()=>{L(E.current),c==null||c()},B=()=>{const K=new Date().getTime()-_.current;E.current=E.current-K,window.clearTimeout(k.current),l==null||l()};return O.addEventListener(Hx,B),O.addEventListener(Kx,F),()=>{O.removeEventListener(Hx,B),O.removeEventListener(Kx,F)}}},[m.viewport,C,l,c,L]),w.useEffect(()=>{o&&!m.isClosePausedRef.current&&L(C)},[o,C,m.isClosePausedRef,L]),w.useEffect(()=>(D(),()=>T()),[D,T]);const M=w.useMemo(()=>v?j$(v):null,[v]);return m.viewport?d.jsxs(d.Fragment,{children:[M&&d.jsx(mie,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:M}),d.jsx(fie,{scope:n,onClose:j,children:ba.createPortal(d.jsx(b1.ItemSlot,{scope:n,children:d.jsx(Lte,{asChild:!0,onEscapeKeyDown:se(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||j(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ae.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":m.swipeDirection,...g,ref:S,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:se(t.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,j()))}),onPointerDown:se(t.onPointerDown,O=>{O.button===0&&(b.current={x:O.clientX,y:O.clientY})}),onPointerMove:se(t.onPointerMove,O=>{if(!b.current)return;const F=O.clientX-b.current.x,B=O.clientY-b.current.y,K=!!P.current,R=["left","right"].includes(m.swipeDirection),H=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,X=R?H(0,F):0,te=R?0:H(0,B),le=O.pointerType==="touch"?10:2,de={x:X,y:te},Me={originalEvent:O,delta:de};K?(P.current=de,Th(uie,h,Me,{discrete:!1})):mE(de,m.swipeDirection,le)?(P.current=de,Th(cie,u,Me,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(F)>le||Math.abs(B)>le)&&(b.current=null)}),onPointerUp:se(t.onPointerUp,O=>{const F=P.current,B=O.target;if(B.hasPointerCapture(O.pointerId)&&B.releasePointerCapture(O.pointerId),P.current=null,b.current=null,F){const K=O.currentTarget,R={originalEvent:O,delta:F};mE(F,m.swipeDirection,m.swipeThreshold)?Th(hie,p,R,{discrete:!0}):Th(die,f,R,{discrete:!0}),K.addEventListener("click",H=>H.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),mie=t=>{const{__scopeToast:e,children:n,...r}=t,s=mm(ym,e),[o,i]=w.useState(!1),[a,l]=w.useState(!1);return vie(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(Pd,{asChild:!0,children:d.jsx(x1,{...r,children:o&&d.jsxs(d.Fragment,{children:[s.label," ",n]})})})},yie="ToastTitle",I$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});I$.displayName=yie;var Sie="ToastDescription",E$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});E$.displayName=Sie;var k$="ToastAction",T$=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(A$,{altText:n,asChild:!0,children:d.jsx(P1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${k$}\`. Expected non-empty \`string\`.`),null)});T$.displayName=k$;var M$="ToastClose",P1=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,s=pie(M$,n);return d.jsx(A$,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,s.onClose)})})});P1.displayName=M$;var A$=w.forwardRef((t,e)=>{const{__scopeToast:n,altText:r,...s}=t;return d.jsx(Ae.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function j$(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),xie(r)){const s=r.ariaHidden||r.hidden||r.style.display==="none",o=r.dataset.radixToastAnnounceExclude==="";if(!s)if(o){const i=r.dataset.radixToastAnnounceAlt;i&&e.push(i)}else e.push(...j$(r))}}),e}function Th(t,e,n,{discrete:r}){const s=n.originalEvent.currentTarget,o=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?$b(s,o):s.dispatchEvent(o)}var mE=(t,e,n=0)=>{const r=Math.abs(t.x),s=Math.abs(t.y),o=r>s;return e==="left"||e==="right"?o&&r>n:!o&&s>n};function vie(t=()=>{}){const e=qt(t);yi(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function xie(t){return t.nodeType===t.ELEMENT_NODE}function wie(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function pS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var bie=_$,Pie=I$,Cie=E$,_ie=T$,yE=P1;const O$=w.createContext(null);function Iie({children:t}){const e=q0("toasts",[]),n=w.useMemo(()=>({toasts:e,addToast(r){const s=r.id??ze();return e.update(o=>[...o.filter(i=>i.id!==r.id),{...r,id:s}]),s},removeToast(r){return e.update(s=>s.filter(o=>o.id!==r)),r},clearToasts(){e.set([])}}),[e]);return d.jsx(w$,{children:d.jsx(O$.Provider,{value:n,children:t})})}function To(){const t=w.useContext(O$);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}var C1={exports:{}};C1.exports;(function(t){var e=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function i(l,c){if(!o[l]){o[l]={};for(var u=0;u<l.length;u++)o[l][l.charAt(u)]=u}return o[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),h=0,f=c.length;h<f;h++){var p=c.charCodeAt(h);u[h*2]=p>>>8,u[h*2+1]=p%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var f=[];return c.forEach(function(p){f.push(n(p))}),a.decompress(f.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return s.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(s,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 h,f,p={},g={},m="",v="",y="",S=2,b=3,P=2,C=[],_=0,E=0,k;for(k=0;k<l.length;k+=1)if(m=l.charAt(k),Object.prototype.hasOwnProperty.call(p,m)||(p[m]=b++,g[m]=!0),v=y+m,Object.prototype.hasOwnProperty.call(p,v))y=v;else{if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(f=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}else{for(f=1,h=0;h<P;h++)_=_<<1|f,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=0;for(f=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(f=p[y],h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;S--,S==0&&(S=Math.pow(2,P),P++),p[v]=b++,y=String(m)}if(y!==""){if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(f=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}else{for(f=1,h=0;h<P;h++)_=_<<1|f,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=0;for(f=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(f=p[y],h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;S--,S==0&&(S=Math.pow(2,P),P++)}for(f=2,h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;for(;;)if(_=_<<1,E==c-1){C.push(u(_));break}else E++;return C.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],f=4,p=4,g=3,m="",v=[],y,S,b,P,C,_,E,k={val:u(0),position:c,index:1};for(y=0;y<3;y+=1)h[y]=y;for(b=0,C=Math.pow(2,2),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 2:return""}for(h[3]=E,S=E,v.push(E);;){if(k.index>l)return"";for(b=0,C=Math.pow(2,g),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(E=b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[p++]=n(b),E=p-1,f--;break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[p++]=n(b),E=p-1,f--;break;case 2:return v.join("")}if(f==0&&(f=Math.pow(2,g),g++),h[E])m=h[E];else if(E===p)m=S+S.charAt(0);else return null;v.push(m),h[p++]=S+m.charAt(0),f--,S=m,f==0&&(f=Math.pow(2,g),g++)}}};return a}();t!=null?t.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})})(C1);var Eie=C1.exports;const D$=wi(Eie),_1="web image/vnd.tldraw+png",kie={"image/png":_1},Tie={[_1]:"image/png"};function Mie(t){return hn(kie,t)??null}function Aie(t){return hn(Tie,t)??t}function jie(t){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(t)}function Oie(t){const e=Object.entries(t);for(const[n,r]of e)r.catch(s=>console.error(s));return navigator.clipboard.write([new ClipboardItem(t)]).catch(n=>(console.error(n),Promise.all(e.map(async([r,s])=>[r,await s])).then(r=>{const s=w0(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function Die(t,e,n){var y,S,b;const{elements:r,files:s}=e,o={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:t.store.schema.serialize()},i=new Map,a=new Map,l=t.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(P=>{if(c.set(P.id,Ke()),P.boundElements!==null)for(const C of P.boundElements)C.type==="text"&&h.add(C.id)});let f=QT;for(const P of r){if(h.has(P.id))continue;const C=c.get(P.id),_={id:C,typeName:"shape",parentId:l,index:f,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:Rie(P.opacity),meta:{}};switch(P.angle!==0&&a.set(C,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(y=i.get(P.groupIds[0]))==null||y.push(C):i.set(P.groupIds[0],[C]):u.push(C),P.type){case"rectangle":case"ellipse":case"diamond":{let E="",k="middle";if(P.boundElements!==null){for(const T of P.boundElements)if(T.type==="text"){const j=r.find(L=>L.id===T.id);j&&(E=j.text,k=Uie[j.textAlign])}}const D=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;o.shapes.push({..._,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:Mh[P.strokeWidth]??"draw",color:Ac[D]??"black",text:E,align:k,dash:Ah(P),fill:Wie(P)}});break}case"freedraw":{o.shapes.push({..._,type:"draw",props:{dash:Ah(P),size:Mh[P.strokeWidth],color:Ac[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([E,k,D=.5])=>({x:E,y:k,z:D}))}]}});break}case"line":{if(P.points.slice().length<2)break;const k=Fu(P.points.length);o.shapes.push({..._,type:"line",props:{dash:Ah(P),size:Mh[P.strokeWidth],color:Ac[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",points:{...Object.fromEntries(P.points.map(([D,T],j)=>{const L=k[j];return[L,{id:L,index:L,x:D,y:T}]}))}}});break}case"arrow":{let E="";if(P.boundElements!==null){for(const L of P.boundElements)if(L.type==="text"){const M=r.find(O=>O.id===L.id);M&&(E=M.text)}}const k=P.points[0],D=P.points[P.points.length-1],T=c.get((S=P.startBinding)==null?void 0:S.elementId),j=c.get((b=P.endBinding)==null?void 0:b.elementId);o.shapes.push({..._,type:"arrow",props:{text:E,bend:Kie(P,k,D),dash:Ah(P),size:Mh[P.strokeWidth]??"m",color:Ac[P.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:D[0],y:D[1]},arrowheadEnd:SE[P.endArrowhead]??"none",arrowheadStart:SE[P.startArrowhead]??"none"}}),T&&o.bindings.push({id:Ji(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),j&&o.bindings.push({id:Ji(),typeName:"binding",type:"arrow",fromId:C,toId:j,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:E,scale:k}=$ie(P.fontSize);o.shapes.push({..._,type:"text",props:{size:E,scale:k,font:Fie[P.fontFamily]??"draw",color:Ac[P.strokeColor]??"black",text:P.text,textAlign:Hie[P.textAlign]}});break}case"image":{const E=s[P.fileId];if(!E)break;const k=Yo.createId();o.assets.push({id:k,typeName:"asset",type:"image",props:{w:P.width,h:P.height,fileSize:E.size,name:P.id??"Untitled",isAnimated:!1,mimeType:E.mimeType,src:E.dataURL},meta:{}}),o.shapes.push({..._,type:"image",props:{w:P.width,h:P.height,assetId:k}})}}f=_s(f)}const p=n??(t.inputs.shiftKey?t.inputs.currentPagePoint:void 0);t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(o,{point:p,select:!1,preserveIds:!0});for(const P of i.values())if(P.length>1){t.groupShapes(P);const C=t.getShape(P[0]);C!=null&&C.parentId&&Fn(C.parentId)&&u.push(C.parentId)}for(const[P,C]of a)t.select(P),t.rotateShapesBy([P],C);const g=me(u.map(P=>t.getShape(P))),m=Z.Common(g.map(P=>t.getShapePageBounds(P))),v=t.getViewportPageBounds().center;t.updateShapes(g.map(P=>{const C={x:(P.x??0)-(m.x+m.w/2),y:(P.y??0)-(m.y+m.h/2)};return{id:P.id,type:P.type,x:v.x+C.x,y:v.y+C.y}})),t.setSelectedShapes(u)}const Rie=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Mh={1:"s",2:"m",3:"l",4:"xl"},Lie={16:"s",20:"m",28:"l",36:"xl"};function $ie(t){const e=Lie[t];return e?{size:e,scale:1}:t<16?{size:"s",scale:t/16}:t>36?{size:"xl",scale:t/36}:{size:"m",scale:1}}const Fie={1:"draw",2:"sans",3:"mono"},Nie={gray:["#f8f9fa","#e9ecef","#ced4da","#868e96","#343a40"],red:["#fff5f5","#ffc9c9","#ff8787","#fa5252","#e03131"],pink:["#fff0f6","#fcc2d7","#f783ac","#e64980","#c2255c"],grape:["#f8f0fc","#eebefa","#da77f2","#be4bdb","#9c36b5"],violet:["#f3f0ff","#d0bfff","#9775fa","#7950f2","#6741d9"],indigo:["#edf2ff","#bac8ff","#748ffc","#4c6ef5","#3b5bdb"],blue:["#e7f5ff","#a5d8ff","#4dabf7","#228be6","#1971c2"],cyan:["#e3fafc","#99e9f2","#3bc9db","#15aabf","#0c8599"],teal:["#e6fcf5","#96f2d7","#38d9a9","#12b886","#099268"],green:["#ebfbee","#b2f2bb","#69db7c","#40c057","#2f9e44"],lime:["#f4fce3","#d8f5a2","#a9e34b","#82c91e","#66a80f"],yellow:["#fff9db","#ffec99","#ffd43b","#fab005","#f08c00"],orange:["#fff4e6","#ffd8a8","#ffa94d","#fd7e14","#e8590c"]};function Ss(t,e,n){const r=[0,1,2,3,4].map(s=>Nie[t][s]);return Object.fromEntries(r.map((s,o)=>[s,o<3?e:n]))}const Ac={...Ss("gray","grey","black"),...Ss("red","light-red","red"),...Ss("pink","light-red","red"),...Ss("grape","light-violet","violet"),...Ss("blue","light-blue","blue"),...Ss("cyan","light-blue","blue"),...Ss("teal","light-green","green"),...Ss("green","light-green","green"),...Ss("yellow","yellow","orange"),...Ss("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},zie={solid:"draw",dashed:"dashed",dotted:"dotted"},Bie={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Uie={left:"start",center:"middle",right:"end"},Hie={left:"start",center:"middle",right:"end"},SE={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Kie(t,e,n){let r=0;if(t.points.length>2){const s=new x(e[0],e[1]),o=new x(n[0],n[1]),i=new x(t.points[1][0],t.points[1][1]),a=x.Sub(o,s),l=x.Per(a),c=x.Med(o,s),u=x.Sub(c,l),h=x.Add(c,l),f=x.NearestPointOnLineSegment(u,h,i,!1);r=x.Dist(f,c),x.Clockwise(f,o,c)&&(r*=-1)}return r}const Ah=t=>{let e=zie[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Wie=t=>t.backgroundColor==="transparent"?"none":Bie[t.fillStyle]??"solid";async function Gie(t,e,n,r){const s=e.map(o=>o instanceof File?o:new File([o],"tldrawFile",{type:o.type}));t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r})}function Vie(t,e,n){const r=t.getSelectionPageBounds();t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(e,{point:n,select:!0});const s=t.getSelectionPageBounds();r&&s&&(r!=null&&r.collides(s))&&(t.updateInstanceState({isChangingStyle:!0}),t.timers.setTimeout(()=>{t.updateInstanceState({isChangingStyle:!1})},150))}async function Gx(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}const Yie=[_1,"image/png","image/jpeg","image/webp","image/svg+xml"];function Xie(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const qie=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Zie=t=>{const e=t.split(/[\n\s]/);for(const n of e)try{const r=new URL(n);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return Pj(e)},Qie=t=>/^<svg/.test(t),Jie=["input","select","textarea"];function gS(t){const{activeElement:e}=document;return t.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||Jie.indexOf(e.tagName.toLowerCase())>-1)}const jh=(t,e,n,r)=>{const s=Zie(e);if(s)for(const o of s)Gx(t,o,n);else qie(e)?Gx(t,e,n):Qie(e)?(t.markHistoryStoppingPoint("paste"),t.putExternalContent({type:"svg-text",text:e,point:n,sources:r})):(t.markHistoryStoppingPoint("paste"),t.putExternalContent({type:"text",text:e,point:n,sources:r}))},eae=async(t,e,n)=>{if(t.getEditingShapeId()!==null)return;if(!e)throw Error("No clipboard data");const r=[];for(const s of Object.values(e.items))switch(s.kind){case"file":{r.push({type:"file",source:new Promise(o=>o(s.getAsFile()))});break}case"string":{s.type==="text/html"?r.push({type:"html",source:new Promise(o=>s.getAsString(o))}):s.type==="text/plain"?r.push({type:"text",source:new Promise(o=>s.getAsString(o))}):r.push({type:s.type,source:new Promise(o=>s.getAsString(o))});break}}L$(t,r,n)},R$=async(t,e,n)=>{const r=[];for(const s of e){for(const o of Yie)if(s.types.includes(o)){const i=s.getType(o).then(a=>Zr.rewriteMimeType(a,Aie(o)));r.push({type:"blob",source:i});break}s.types.includes("text/html")&&r.push({type:"html",source:(async()=>{const o=await s.getType("text/html");return await Zr.blobToText(o)})()}),s.types.includes("text/uri-list")&&r.push({type:"url",source:(async()=>{const o=await s.getType("text/uri-list");return await Zr.blobToText(o)})()}),s.types.includes("text/plain")&&r.push({type:"text",source:(async()=>{const o=await s.getType("text/plain");return await Zr.blobToText(o)})()})}return await L$(t,r,n)};async function L$(t,e,n){const r=e.filter(o=>(o.type==="file"||o.type==="blob")&&o.source!==null);if(r.length){if(r.length>t.options.maxFilesAtOnce)throw Error("Too many files");const o=me(await Promise.all(r.map(i=>i.source)));return await Gie(t,o,n)}const s=await Promise.all(e.filter(o=>o.type!=="file").map(o=>new Promise(i=>{const a=o;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=D$.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const f=JSON.parse(h);if(f.type!=="application/tldraw"&&i({type:"error",data:f,reason:`found tldraw data comment but JSON was of a different type: ${f.type}`}),typeof f.data=="string"){i({type:"error",data:f,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:f.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const o of s)if(o.type==="tldraw"){Vie(t,o.data,n);return}for(const o of s)if(o.type==="excalidraw"){Die(t,o.data,n);return}for(const o of s){if(o.type==="text"&&o.subtype==="html"){const a=new DOMParser().parseFromString(o.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");jh(t,c,n,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&o.data.trim()){jh(t,Xie(o.data),n,s);return}}if(o.type==="text"&&o.subtype==="text"&&o.data.startsWith("<iframe ")){const a=new DOMParser().parseFromString(o.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="IFRAME"&&a.firstElementChild.hasAttribute("src")&&a.firstElementChild.getAttribute("src")!==""){const c=a.firstElementChild.getAttribute("src");jh(t,c,n,s);return}}}for(const o of s)if(o.type==="text"&&o.subtype==="url"){Gx(t,o.data,n,s);return}for(const o of s)if(o.type==="text"&&o.subtype==="text"&&o.data.trim()){jh(t,o.data,n,s);return}}const Vp=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=D$.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const s=e.shapes.map(o=>t.getShapeUtil(o).getText(o)).filter(pB);if((r=navigator.clipboard)!=null&&r.write){const o=new Blob([`<div data-tldraw>${n}</div>`],{type:"text/html"});let i=s.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${n}</div>`)}};function tae(){const t=z(),e=Jt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Vp(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Vp(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:i}))},[t,e]),s=w.useCallback(async function(i,a,l){t.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(R$(t,i,l),e("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{s(c,a,l)}))},[t,e]);return{copy:n,cut:r,paste:s}}function nae(){const t=z(),e=Jt(),n=U("editor.isFocused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!n)return;const r=async l=>{t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||gS(t)||(xe(l),await Vp(t),e("copy",{source:"kbd"}))};async function s(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||gS(t)||(xe(l),await Vp(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let o=!1;const i=l=>{l.button===1&&(o=!0,t.timers.requestAnimationFrame(()=>{o=!1}))},a=l=>{var f;if(o){Ct(l);return}if(t.getEditingShapeId()!==null||gS(t))return;let c,u=!1;t.inputs.shiftKey&&(u=!0),t.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=t.inputs.currentPagePoint);const h=()=>{l.clipboardData&&eae(t,l.clipboardData,c)};(f=navigator.clipboard)!=null&&f.read?navigator.clipboard.read().then(p=>{Array.isArray(p)&&p[0]instanceof ClipboardItem&&R$(t,p,c)},()=>{h()}):h(),xe(l),e("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",s),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",s),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[t,e,n])}/*!
|
|
239
|
+
For more information, see https://radix-ui.com/primitives/docs/components/${e.docsSlug}`;return w.useEffect(()=>{t&&(document.getElementById(t)||console.error(n))},[n,t]),null},zoe="DialogDescriptionWarning",Boe=({contentRef:t,descriptionId:e})=>{const r=`Warning: Missing \`Description\` or \`aria-describedby={undefined}\` for {${g$(zoe).contentName}}.`;return w.useEffect(()=>{var o;const s=(o=t.current)==null?void 0:o.getAttribute("aria-describedby");e&&s&&(document.getElementById(e)||console.warn(r))},[r,t,e]),null},Uoe=r$,Hoe=i$,Koe=a$,Woe=l$;const zs=w.memo(function({small:e,invertIcon:n,icon:r,color:s,className:o,...i}){const a=h1(),l=a.icons[r]??a.icons["question-mark-circle"],c=w.useRef(null);return w.useLayoutEffect(()=>{l||console.error(`Icon not found: ${r}. Add it to the assetUrls.icons object.`),c!=null&&c.current&&(c.current.style.webkitMask=`url(${l}) center 100% / 100% no-repeat`)},[c,l,r]),r==="none"?d.jsx("div",{className:ce("tlui-icon tlui-icon__placeholder",{"tlui-icon__small":e},o)}):d.jsx("div",{...i,ref:c,className:ce("tlui-icon",{"tlui-icon__small":e},o),style:{color:s,mask:`url(${l}) center 100% / 100% no-repeat`,transform:n?"scale(-1, 1)":void 0}})});function be({icon:t,small:e,invertIcon:n}){return d.jsx(zs,{className:"tlui-button__icon",icon:t,small:e,invertIcon:n})}function dm({className:t,children:e}){return d.jsx("div",{className:ce("tlui-dialog__header",t),children:e})}function hm({className:t,children:e}){return d.jsx(u$,{dir:"ltr",className:ce("tlui-dialog__header__title",t),children:e})}function fm(){return d.jsx("div",{className:"tlui-dialog__header__close",children:d.jsx(f$,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon","aria-label":"Close",onTouchEnd:t=>t.target.click(),children:d.jsx(be,{small:!0,icon:"cross-2"})})})})}function Yu({className:t,children:e,style:n}){return d.jsx("div",{className:ce("tlui-dialog__body",t),style:n,children:e})}function y1({className:t,children:e}){return d.jsx("div",{className:ce("tlui-dialog__footer",t),children:e})}const pm=w.forwardRef(function({className:e,label:n,icon:r,iconLeft:s,autoSelect:o=!1,autoFocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:h,onFocus:f,onBlur:p,shouldManuallyMaintainScrollPositionWhenFocused:g=!1,children:m,value:v},y){const S=Ti(),b=w.useRef(null);w.useImperativeHandle(y,()=>b.current);const P=Ee(),C=w.useRef(a??""),_=w.useRef(a??""),[E,k]=w.useState(!1),D=w.useCallback(M=>{k(!0);const O=M.currentTarget;_.current=O.value,S?S.timers.requestAnimationFrame(()=>{o&&O.select()}):kx.requestAnimationFrame("anon",()=>{o&&O.select()}),f==null||f()},[o,S,f]),T=w.useCallback(M=>{const O=M.currentTarget.value;_.current=O,u==null||u(O)},[u]),j=w.useCallback(M=>{switch(M.key){case"Enter":{M.currentTarget.blur(),Ct(M),c==null||c(M.currentTarget.value);break}case"Escape":{M.currentTarget.value=C.current,h==null||h(M.currentTarget.value),M.currentTarget.blur(),Ct(M);break}}},[c,h]),L=w.useCallback(M=>{k(!1);const O=M.currentTarget.value;p==null||p(O)},[p]);return w.useEffect(()=>{if(!Ge.isIos)return;const M=window.visualViewport;if(E&&g&&M){const O=()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})};return M.addEventListener("resize",O),M.addEventListener("scroll",O),S?S.timers.requestAnimationFrame(()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}):kx.requestAnimationFrame("anon",()=>{var F;(F=b.current)==null||F.scrollIntoView({block:"center"})}),()=>{M.removeEventListener("resize",O),M.removeEventListener("scroll",O)}}},[E,S,g]),d.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[m,n&&d.jsx("label",{children:P(n)}),s&&d.jsx(zs,{icon:s,className:"tlui-icon-left",small:!0}),d.jsx("input",{ref:b,className:ce("tlui-input",e),type:"text",defaultValue:a,onKeyDownCapture:j,onChange:T,onFocus:D,onBlur:L,autoFocus:i,placeholder:l,value:v}),r&&d.jsx(zs,{icon:r,small:!!n})]})});function pE(t){return gr.isValid(t)?{isValid:!0,hasProtocol:!0}:gr.isValid("https://"+t)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Goe=Zt(function({onClose:e}){const r=z().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?d.jsx(Voe,{onClose:e,selectedShape:r}):null}),Voe=Zt(function({onClose:e,selectedShape:n}){const r=z(),s=Ee(),o=w.useRef(null);w.useEffect(()=>{r.timers.requestAnimationFrame(()=>{var g;return(g=o.current)==null?void 0:g.focus()})},[r]);const i=w.useRef(n.props.url),[a,l]=w.useState(()=>{const g=pE(n.props.url),m=g.isValid===!0?g.hasProtocol?n.props.url:"https://"+n.props.url:"https://";return{actual:m,safe:m,valid:!0}}),c=w.useCallback(g=>{const m=g.replace(/https?:\/\/(https?:\/\/)/,(S,b)=>b),v=pE(m),y=v.isValid===!0?v.hasProtocol?m:"https://"+m:"https://";l({actual:m,safe:y,valid:v.isValid})},[]),u=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(r.updateShapes([{id:g.id,type:g.type,props:{url:""}}]),e())},[r,e]),h=w.useCallback(()=>{const g=r.getOnlySelectedShape();g&&(g&&"url"in g.props&&g.props.url!==a.safe&&r.updateShapes([{id:g.id,type:g.type,props:{url:a.safe}}]),e())},[r,e,a]),f=w.useCallback(()=>{e()},[e]);if(!n)return e(),null;const p=i.current&&!a.valid;return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:s("edit-link-dialog.title")}),d.jsx(fm,{})]}),d.jsx(Yu,{children:d.jsxs("div",{className:"tlui-edit-link-dialog",children:[d.jsx(pm,{ref:o,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autoFocus:!0,value:a.actual,onValueChange:c,onComplete:h,onCancel:f}),d.jsx("div",{children:a.valid?s("edit-link-dialog.detail"):s("edit-link-dialog.invalid-url")})]})}),d.jsxs(y1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:f,onTouchEnd:f,children:d.jsx(bt,{children:s("edit-link-dialog.cancel")})}),p?d.jsx(ue,{type:"danger",onTouchEnd:u,onClick:u,children:d.jsx(bt,{children:s("edit-link-dialog.clear")})}):d.jsx(ue,{type:"primary",disabled:!a.valid,onTouchEnd:h,onClick:h,children:d.jsx(bt,{children:s("edit-link-dialog.save")})})]})]})});var Yoe={};const gE=/(^\/r\/[^/]+\/?$)/,S1=[{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:t=>{const e=ge(t);if(e&&e.pathname.match(gE))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(gE))return t}},{type:"figma",title:"Figma",hostnames:["figma.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{if(t.match(/https:\/\/([\w\.-]+\.)?figma.com\/(file|proto)\/([0-9a-zA-Z]{22,128})(?:\/.*)?$/)&&!t.includes("figma.com/embed"))return`https://www.figma.com/embed?embed_host=share&url=${t}`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/?$/)){const n=e.searchParams.get("url");if(n)return n}}},{type:"google_maps",title:"Google Maps",hostnames:["google.*"],width:720,height:500,doesResize:!0,overridePermissions:{"allow-presentation":!0},toEmbedUrl:t=>{if(t.includes("/maps/embed?"))return t;if(t.includes("/maps/")){const e=t.match(/@(.*?),(.*?),(.*?)z/);let n;if(e){const[,r,s,o]=e;n=`https://${new URL(t).host.replace("www.","")}/maps/embed/v1/view?key=${Yoe.NEXT_PUBLIC_GC_API_KEY}¢er=${r},${s}&zoom=${o}`}else n="";return n}},fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.pathname.match(/^\/maps\/embed\/v1\/view\/?$/)&&e.searchParams.has("center")&&e.searchParams.get("zoom")){const r=e.searchParams.get("zoom"),[s,o]=e.searchParams.get("center").split(",");return`https://www.google.com/maps/@${s},${o},${r}z`}}},{type:"val_town",title:"Val Town",hostnames:["val.town"],minWidth:260,minHeight:100,width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t),n=e&&e.pathname.match(/\/v\/(.+)\/?/);if(n)return`https://www.val.town/embed/${n[1]}`},fromEmbedUrl:t=>{const e=ge(t),n=e&&e.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:t=>{const e=ge(t),n=e&&e.pathname.match(/\/s\/([^/]+)\/?/);if(n)return`https://codesandbox.io/embed/${n[1]}`},fromEmbedUrl:t=>{const e=ge(t),n=e&&e.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:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/pen\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/embed/${o}`}},fromEmbedUrl:t=>{const e=/https:\/\/codepen.io\/([^/]+)\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s,o]=n;return`https://codepen.io/${s}/pen/${o}`}}},{type:"scratch",title:"Scratch",hostnames:["scratch.mit.edu"],width:520,height:400,doesResize:!1,toEmbedUrl:t=>{const e=/https?:\/\/scratch.mit.edu\/projects\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/embed/${s}`}},fromEmbedUrl:t=>{const e=/https:\/\/scratch.mit.edu\/projects\/embed\/([^/]+)/,n=t.match(e);if(n){const[r,s]=n;return`https://scratch.mit.edu/projects/${s}`}}},{type:"youtube",title:"YouTube",hostnames:["*.youtube.com","youtube.com","youtu.be"],width:800,height:450,doesResize:!0,overridePermissions:{"allow-presentation":!0,"allow-popups-to-escape-sandbox":!0},isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=ge(t);if(!e)return;const n=e.hostname.replace(/^www./,"");if(n==="youtu.be")return`https://www.youtube.com/embed/${e.pathname.split("/").filter(Boolean)[0]}`;if((n==="youtube.com"||n==="m.youtube.com")&&e.pathname.match(/^\/watch/))return`https://www.youtube.com/embed/${e.searchParams.get("v")}`},fromEmbedUrl:t=>{const e=ge(t);if(!e)return;if(e.hostname.replace(/^www./,"")==="youtube.com"){const r=e.pathname.match(/^\/embed\/([^/]+)\/?/);if(r)return`https://www.youtube.com/watch?v=${r[1]}`}}},{type:"google_calendar",title:"Google Calendar",hostnames:["calendar.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,instructionLink:"https://support.google.com/calendar/answer/41207?hl=en",overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:t=>{const e=ge(t),n=e==null?void 0:e.searchParams.get("cid");if(e!=null&&e.pathname.match(/\/calendar\/u\/0/)&&n){e.pathname="/calendar/embed";const r=Array.from(e.searchParams.keys());for(const s of r)e.searchParams.delete(s);return e.searchParams.set("src",n),e.href}},fromEmbedUrl:t=>{const e=ge(t),n=e==null?void 0:e.searchParams.get("src");if(e!=null&&e.pathname.match(/\/calendar\/embed/)&&n){e.pathname="/calendar/u/0";const r=Array.from(e.searchParams.keys());for(const s of r)e.searchParams.delete(s);return e.searchParams.set("cid",n),e.href}}},{type:"google_slides",title:"Google Slides",hostnames:["docs.google.*"],width:720,height:500,minWidth:460,minHeight:360,doesResize:!0,overridePermissions:{"allow-popups-to-escape-sandbox":!0},toEmbedUrl:t=>{const e=ge(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/pub\/?$/))){e.pathname=e.pathname.replace(/\/pub$/,"/embed");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}},fromEmbedUrl:t=>{const e=ge(t);if(e!=null&&e.pathname.match(/^\/presentation/)&&(e!=null&&e.pathname.match(/\/embed\/?$/))){e.pathname=e.pathname.replace(/\/embed$/,"/pub");const n=Array.from(e.searchParams.keys());for(const r of n)e.searchParams.delete(r);return e.href}}},{type:"github_gist",title:"GitHub Gist",hostnames:["gist.github.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return t.split("/").pop()?t:void 0},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/([^/]+)\/([0-9a-f]+)$/))return t.split("/").pop()?t:void 0}},{type:"replit",title:"Replit",hostnames:["replit.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/))return`${t}?embed=true`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/\/@([^/]+)\/([^/]+)/)&&e.searchParams.has("embed"))return e.searchParams.delete("embed"),e.href}},{type:"felt",title:"Felt",hostnames:["felt.com"],width:720,height:500,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/map\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/map\//))return e.pathname=e.pathname.replace(/^\/embed/,""),e.href}},{type:"spotify",title:"Spotify",hostnames:["open.spotify.com"],width:720,height:500,minHeight:500,overrideOutlineRadius:12,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/(artist|album)\//))return e.origin+"/embed"+e.pathname},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/(artist|album)\//))return e.origin+e.pathname.replace(/^\/embed/,"")}},{type:"vimeo",title:"Vimeo",hostnames:["vimeo.com","player.vimeo.com"],width:640,height:360,doesResize:!0,isAspectRatioLocked:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="vimeo.com"&&e.pathname.match(/^\/[0-9]+/))return"https://player.vimeo.com/video/"+e.pathname.split("/")[1]+"?title=0&byline=0"},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="player.vimeo.com"){const n=e.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:t=>{const e=ge(t);if(e&&e.hash.match(/#room=/))return t},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hash.match(/#room=/))return t}},{type:"observable",title:"Observable",hostnames:["observablehq.com"],width:720,height:500,doesResize:!0,isAspectRatioLocked:!1,backgroundColor:"#fff",toEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}/embed${e.pathname}?cell=*`;if(e&&e.pathname.match(/^\/d\/([^/]+)\/?$/)){const n=e.pathname.replace(/^\/d/,"");return`${e.origin}/embed${n}?cell=*`}},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.pathname.match(/^\/embed\/@([^/]+)\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","")}#cell-*`;if(e&&e.pathname.match(/^\/embed\/([^/]+)\/?$/))return`${e.origin}${e.pathname.replace("/embed","/d")}#cell-*`}},{type:"desmos",title:"Desmos",hostnames:["desmos.com"],width:700,height:450,doesResize:!0,toEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search===""&&e.hash==="")return`${t}?embed`},fromEmbedUrl:t=>{const e=ge(t);if(e&&e.hostname==="www.desmos.com"&&e.pathname.match(/^\/calculator\/([^/]+)\/?$/)&&e.search==="?embed"&&e.hash==="")return t.replace("?embed","")}}],Xoe={"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},qoe=S1.map(t=>t.type);function Zoe(t){return qoe.includes(t)}function Qoe(t){return"icon"in t}function m$(){return z().getShapeUtil("embed")}function v1(){const t=m$();return e=>t?t.getEmbedDefinition(e):void 0}function Joe(){const t=m$();return t?t.getEmbedDefinitions():[]}const y$=Zt(function({onClose:e}){const n=z(),r=Ee(),s=h1(),[o,i]=w.useState(null),[a,l]=w.useState(""),[c,u]=w.useState(null),[h,f]=w.useState(!1),p=w.useRef(-1),g=Joe(),m=v1();return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:o?`${r("embed-dialog.title")} — ${o.title}`:r("embed-dialog.title")}),d.jsx(fm,{})]}),o?d.jsxs(d.Fragment,{children:[d.jsxs(Yu,{className:"tlui-embed-dialog__enter",children:[d.jsx(pm,{className:"tlui-embed-dialog__input",label:"embed-dialog.url",placeholder:"https://example.com",autoFocus:!0,onValueChange:v=>{l(v);const y=m(v);u(y&&y.definition.type===o.type?y:null),f(!1),clearTimeout(p.current),p.current=n.timers.setTimeout(()=>f(!y),320)}}),a===""?d.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[d.jsx("span",{children:r("embed-dialog.instruction")})," ",o.instructionLink&&d.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:o.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",d.jsx(zs,{icon:"external-link",small:!0})]})]}):d.jsx("div",{className:"tlui-embed-dialog__warning",children:h?r("embed-dialog.invalid-url"):" "})]}),d.jsxs(y1,{className:"tlui-dialog__footer__actions",children:[d.jsx(ue,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:d.jsx(bt,{children:r("embed-dialog.back")})}),d.jsx("div",{className:"tlui-embed__spacer"}),d.jsx(ue,{type:"normal",onClick:e,children:d.jsx(bt,{children:r("embed-dialog.cancel")})}),d.jsx(ue,{type:"primary",disabled:!c,onClick:()=>{c&&(n.putExternalContent({type:"embed",url:a,point:n.getViewportPageBounds().center,embed:c.definition}),e())},children:d.jsx(bt,{children:r("embed-dialog.create")})})]})]}):d.jsx(d.Fragment,{children:d.jsx(Yu,{className:"tlui-embed-dialog__list",children:g.map(v=>{const y=Zoe(v.type)?s.embedIcons[v.type]:Qoe(v)?v.icon:void 0;return d.jsxs(ue,{type:"menu",onClick:()=>i(v),children:[d.jsx(bt,{children:v.title}),y&&d.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${y})`}})]},v.type)})})})]})});async function eie(t,e,n){const r=me(e.map(a=>{const l=t.getShape(a);if(!(!l||t.getShapeUtil(l.type).toSvg===void 0))return l}));if(r.length===0)return;if(r.length===1){const a=r[0];if(!a||t.isShapeOfType(a,"image"))return}const s=[];if(n!==void 0){const a=r.map(l=>({shape:l,bounds:t.getShapeMaskedPageBounds(l).clone().expandBy(n)}));for(let l=0;l<a.length;l++){const c=a[l];if(l===0){s[0]={shapes:[c.shape],bounds:c.bounds};continue}let u=!1;for(const h of s)if(h.bounds.includes(c.bounds)){h.shapes.push(c.shape),h.bounds.expand(c.bounds),u=!0;break}u||s.push({shapes:[c.shape],bounds:c.bounds})}}else{const a=Z.Common(r.map(l=>t.getShapeMaskedPageBounds(l)));s.push({shapes:r,bounds:a})}const o=t.options.flattenImageBoundsPadding;for(const a of s){n!==void 0&&a.bounds.expandBy(-n);const l=await t.getSvgString(a.shapes,{padding:o});if(!(l!=null&&l.svg))continue;const c=new Blob([l.svg],{type:"image/svg+xml"}),u=await t.getAssetForExternalContent({type:"file",file:new File([c],"asset.svg",{type:"image/svg+xml"})});u&&(a.asset=u)}const i=[];return js(()=>{for(const a of s){const{asset:l,bounds:c,shapes:u}=a;if(!l)continue;const h=t.findCommonAncestor(u)??t.getCurrentPageId();if(!h)continue;let f="a1";for(const y of u)if(y.parentId===h){y.index>f&&(f=y.index);break}let p,g,m;if(Fn(h)){const y=t.getShape(h);if(!y)continue;const S=t.getPointInShapeSpace(y,{x:c.x,y:c.y});m=t.getShapePageTransform(h).rotation(),S.sub(new x(o,o).rot(-m)),p=S.x,g=S.y}else p=c.x-o,g=c.y-o,m=0;t.deleteShapes(u),t.createAssets([{...l,id:l.id}]);const v=Ke();t.createShape({id:v,type:"image",index:f,parentId:h,x:p,y:g,rotation:-m,props:{assetId:l.id,w:c.w+o*2,h:c.h+o*2}}),i.push(v)}}),i}function gm(){const t=Ti();return(t==null?void 0:t.store.props.collaboration)!==void 0}function tie(){const t=Ti();return U("sync status",()=>{var e;return(e=t==null?void 0:t.store.props.collaboration)!=null&&e.status?t.store.props.collaboration.status.get():null},[t])}const fS=[0,389,436,476,580,640,840,1023];var St=(t=>(t[t.ZERO=0]="ZERO",t[t.MOBILE_XXS=1]="MOBILE_XXS",t[t.MOBILE_XS=2]="MOBILE_XS",t[t.MOBILE_SM=3]="MOBILE_SM",t[t.MOBILE=4]="MOBILE",t[t.TABLET_SM=5]="TABLET_SM",t[t.TABLET=6]="TABLET",t[t.DESKTOP=7]="DESKTOP",t))(St||{});const S$=ke.createContext(null);function nie({forceMobile:t=!1,children:e}){const n=Ti(),r=U("breakpoint",()=>{const{width:s}=(n==null?void 0:n.getViewportScreenBounds())??{width:window.innerWidth},o=t?St.MOBILE_SM:fS.length-1;for(let i=0;i<o;i++)if(s>fS[i]&&s<=fS[i+1])return i;return o},[n]);return d.jsx(S$.Provider,{value:r,children:e})}function An(){const t=w.useContext(S$);if(t===null)throw new Error("useBreakpoint must be used inside of the <BreakpointProvider /> component");return t}const v$=w.createContext(null);function rie({context:t,children:e}){const n=Jt(),r=q0("dialogs",[]),s=w.useMemo(()=>({dialogs:r,addDialog(o){const i=o.id??ze();return r.update(a=>[...a.filter(l=>l.id!==o.id),{...o,id:i}]),n("open-menu",{source:"dialog",id:i}),Vr.addOpenMenu(i,t),i},removeDialog(o){var a;const i=r.get().find(l=>l.id===o);return i&&((a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:o}),Vr.deleteOpenMenu(o,t),r.update(l=>l.filter(c=>c!==i))),o},clearDialogs(){const o=r.get();o.length!==0&&(o.forEach(i=>{var a;(a=i.onClose)==null||a.call(i),n("close-menu",{source:"dialog",id:i.id}),Vr.deleteOpenMenu(i.id,t)}),r.set([]))}}),[n,r,t]);return d.jsx(v$.Provider,{value:s,children:e})}function Ed(){const t=w.useContext(v$);if(!t)throw new Error("useDialogs must be used within a DialogsProvider");return t}var sie="VisuallyHidden",x1=w.forwardRef((t,e)=>d.jsx(Ae.span,{...t,ref:e,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",...t.style}}));x1.displayName=sie;var w1="ToastProvider",[b1,oie,iie]=Jg("Toast"),[x$,gge]=Ws("Toast",[iie]),[aie,mm]=x$(w1),w$=t=>{const{__scopeToast:e,label:n="Notification",duration:r=5e3,swipeDirection:s="right",swipeThreshold:o=50,children:i}=t,[a,l]=w.useState(null),[c,u]=w.useState(0),h=w.useRef(!1),f=w.useRef(!1);return n.trim()||console.error(`Invalid prop \`label\` supplied to \`${w1}\`. Expected non-empty \`string\`.`),d.jsx(b1.Provider,{scope:e,children:d.jsx(aie,{scope:e,label:n,duration:r,swipeDirection:s,swipeThreshold:o,toastCount:c,viewport:a,onViewportChange:l,onToastAdd:w.useCallback(()=>u(p=>p+1),[]),onToastRemove:w.useCallback(()=>u(p=>p-1),[]),isFocusedToastEscapeKeyDownRef:h,isClosePausedRef:f,children:i})})};w$.displayName=w1;var b$="ToastViewport",lie=["F8"],Hx="toast.viewportPause",Kx="toast.viewportResume",P$=w.forwardRef((t,e)=>{const{__scopeToast:n,hotkey:r=lie,label:s="Notifications ({hotkey})",...o}=t,i=mm(b$,n),a=oie(n),l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),h=w.useRef(null),f=Qe(e,h,i.onViewportChange),p=r.join("+").replace(/Key/g,"").replace(/Digit/g,""),g=i.toastCount>0;w.useEffect(()=>{const v=y=>{var b;r.length!==0&&r.every(P=>y[P]||y.code===P)&&((b=h.current)==null||b.focus())};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[r]),w.useEffect(()=>{const v=l.current,y=h.current;if(g&&v&&y){const S=()=>{if(!i.isClosePausedRef.current){const _=new CustomEvent(Hx);y.dispatchEvent(_),i.isClosePausedRef.current=!0}},b=()=>{if(i.isClosePausedRef.current){const _=new CustomEvent(Kx);y.dispatchEvent(_),i.isClosePausedRef.current=!1}},P=_=>{!v.contains(_.relatedTarget)&&b()},C=()=>{v.contains(document.activeElement)||b()};return v.addEventListener("focusin",S),v.addEventListener("focusout",P),v.addEventListener("pointermove",S),v.addEventListener("pointerleave",C),window.addEventListener("blur",S),window.addEventListener("focus",b),()=>{v.removeEventListener("focusin",S),v.removeEventListener("focusout",P),v.removeEventListener("pointermove",S),v.removeEventListener("pointerleave",C),window.removeEventListener("blur",S),window.removeEventListener("focus",b)}}},[g,i.isClosePausedRef]);const m=w.useCallback(({tabbingDirection:v})=>{const S=a().map(b=>{const P=b.ref.current,C=[P,...wie(P)];return v==="forwards"?C:C.reverse()});return(v==="forwards"?S.reverse():S).flat()},[a]);return w.useEffect(()=>{const v=h.current;if(v){const y=S=>{var C,_,E;const b=S.altKey||S.ctrlKey||S.metaKey;if(S.key==="Tab"&&!b){const k=document.activeElement,D=S.shiftKey;if(S.target===v&&D){(C=c.current)==null||C.focus();return}const L=m({tabbingDirection:D?"backwards":"forwards"}),M=L.findIndex(O=>O===k);pS(L.slice(M+1))?S.preventDefault():D?(_=c.current)==null||_.focus():(E=u.current)==null||E.focus()}};return v.addEventListener("keydown",y),()=>v.removeEventListener("keydown",y)}},[a,m]),d.jsxs($te,{ref:l,role:"region","aria-label":s.replace("{hotkey}",p),tabIndex:-1,style:{pointerEvents:g?void 0:"none"},children:[g&&d.jsx(Wx,{ref:c,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"forwards"});pS(v)}}),d.jsx(b1.Slot,{scope:n,children:d.jsx(Ae.ol,{tabIndex:-1,...o,ref:f})}),g&&d.jsx(Wx,{ref:u,onFocusFromOutsideViewport:()=>{const v=m({tabbingDirection:"backwards"});pS(v)}})]})});P$.displayName=b$;var C$="ToastFocusProxy",Wx=w.forwardRef((t,e)=>{const{__scopeToast:n,onFocusFromOutsideViewport:r,...s}=t,o=mm(C$,n);return d.jsx(x1,{"aria-hidden":!0,tabIndex:0,...s,ref:e,style:{position:"fixed"},onFocus:i=>{var c;const a=i.relatedTarget;!((c=o.viewport)!=null&&c.contains(a))&&r()}})});Wx.displayName=C$;var ym="Toast",cie="toast.swipeStart",uie="toast.swipeMove",die="toast.swipeCancel",hie="toast.swipeEnd",_$=w.forwardRef((t,e)=>{const{forceMount:n,open:r,defaultOpen:s,onOpenChange:o,...i}=t,[a=!0,l]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(ds,{present:n||a,children:d.jsx(gie,{open:a,...i,ref:e,onClose:()=>l(!1),onPause:qt(t.onPause),onResume:qt(t.onResume),onSwipeStart:se(t.onSwipeStart,c=>{c.currentTarget.setAttribute("data-swipe","start")}),onSwipeMove:se(t.onSwipeMove,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","move"),c.currentTarget.style.setProperty("--radix-toast-swipe-move-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-move-y",`${h}px`)}),onSwipeCancel:se(t.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(t.onSwipeEnd,c=>{const{x:u,y:h}=c.detail.delta;c.currentTarget.setAttribute("data-swipe","end"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-x"),c.currentTarget.style.removeProperty("--radix-toast-swipe-move-y"),c.currentTarget.style.setProperty("--radix-toast-swipe-end-x",`${u}px`),c.currentTarget.style.setProperty("--radix-toast-swipe-end-y",`${h}px`),l(!1)})})})});_$.displayName=ym;var[fie,pie]=x$(ym,{onClose(){}}),gie=w.forwardRef((t,e)=>{const{__scopeToast:n,type:r="foreground",duration:s,open:o,onClose:i,onEscapeKeyDown:a,onPause:l,onResume:c,onSwipeStart:u,onSwipeMove:h,onSwipeCancel:f,onSwipeEnd:p,...g}=t,m=mm(ym,n),[v,y]=w.useState(null),S=Qe(e,O=>y(O)),b=w.useRef(null),P=w.useRef(null),C=s||m.duration,_=w.useRef(0),E=w.useRef(C),k=w.useRef(0),{onToastAdd:D,onToastRemove:T}=m,j=qt(()=>{var F;(v==null?void 0:v.contains(document.activeElement))&&((F=m.viewport)==null||F.focus()),i()}),L=w.useCallback(O=>{!O||O===1/0||(window.clearTimeout(k.current),_.current=new Date().getTime(),k.current=window.setTimeout(j,O))},[j]);w.useEffect(()=>{const O=m.viewport;if(O){const F=()=>{L(E.current),c==null||c()},B=()=>{const K=new Date().getTime()-_.current;E.current=E.current-K,window.clearTimeout(k.current),l==null||l()};return O.addEventListener(Hx,B),O.addEventListener(Kx,F),()=>{O.removeEventListener(Hx,B),O.removeEventListener(Kx,F)}}},[m.viewport,C,l,c,L]),w.useEffect(()=>{o&&!m.isClosePausedRef.current&&L(C)},[o,C,m.isClosePausedRef,L]),w.useEffect(()=>(D(),()=>T()),[D,T]);const M=w.useMemo(()=>v?j$(v):null,[v]);return m.viewport?d.jsxs(d.Fragment,{children:[M&&d.jsx(mie,{__scopeToast:n,role:"status","aria-live":r==="foreground"?"assertive":"polite","aria-atomic":!0,children:M}),d.jsx(fie,{scope:n,onClose:j,children:ba.createPortal(d.jsx(b1.ItemSlot,{scope:n,children:d.jsx(Lte,{asChild:!0,onEscapeKeyDown:se(a,()=>{m.isFocusedToastEscapeKeyDownRef.current||j(),m.isFocusedToastEscapeKeyDownRef.current=!1}),children:d.jsx(Ae.li,{role:"status","aria-live":"off","aria-atomic":!0,tabIndex:0,"data-state":o?"open":"closed","data-swipe-direction":m.swipeDirection,...g,ref:S,style:{userSelect:"none",touchAction:"none",...t.style},onKeyDown:se(t.onKeyDown,O=>{O.key==="Escape"&&(a==null||a(O.nativeEvent),O.nativeEvent.defaultPrevented||(m.isFocusedToastEscapeKeyDownRef.current=!0,j()))}),onPointerDown:se(t.onPointerDown,O=>{O.button===0&&(b.current={x:O.clientX,y:O.clientY})}),onPointerMove:se(t.onPointerMove,O=>{if(!b.current)return;const F=O.clientX-b.current.x,B=O.clientY-b.current.y,K=!!P.current,R=["left","right"].includes(m.swipeDirection),H=["left","up"].includes(m.swipeDirection)?Math.min:Math.max,X=R?H(0,F):0,te=R?0:H(0,B),le=O.pointerType==="touch"?10:2,de={x:X,y:te},Me={originalEvent:O,delta:de};K?(P.current=de,Th(uie,h,Me,{discrete:!1})):mE(de,m.swipeDirection,le)?(P.current=de,Th(cie,u,Me,{discrete:!1}),O.target.setPointerCapture(O.pointerId)):(Math.abs(F)>le||Math.abs(B)>le)&&(b.current=null)}),onPointerUp:se(t.onPointerUp,O=>{const F=P.current,B=O.target;if(B.hasPointerCapture(O.pointerId)&&B.releasePointerCapture(O.pointerId),P.current=null,b.current=null,F){const K=O.currentTarget,R={originalEvent:O,delta:F};mE(F,m.swipeDirection,m.swipeThreshold)?Th(hie,p,R,{discrete:!0}):Th(die,f,R,{discrete:!0}),K.addEventListener("click",H=>H.preventDefault(),{once:!0})}})})})}),m.viewport)})]}):null}),mie=t=>{const{__scopeToast:e,children:n,...r}=t,s=mm(ym,e),[o,i]=w.useState(!1),[a,l]=w.useState(!1);return vie(()=>i(!0)),w.useEffect(()=>{const c=window.setTimeout(()=>l(!0),1e3);return()=>window.clearTimeout(c)},[]),a?null:d.jsx(Pd,{asChild:!0,children:d.jsx(x1,{...r,children:o&&d.jsxs(d.Fragment,{children:[s.label," ",n]})})})},yie="ToastTitle",I$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});I$.displayName=yie;var Sie="ToastDescription",E$=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t;return d.jsx(Ae.div,{...r,ref:e})});E$.displayName=Sie;var k$="ToastAction",T$=w.forwardRef((t,e)=>{const{altText:n,...r}=t;return n.trim()?d.jsx(A$,{altText:n,asChild:!0,children:d.jsx(P1,{...r,ref:e})}):(console.error(`Invalid prop \`altText\` supplied to \`${k$}\`. Expected non-empty \`string\`.`),null)});T$.displayName=k$;var M$="ToastClose",P1=w.forwardRef((t,e)=>{const{__scopeToast:n,...r}=t,s=pie(M$,n);return d.jsx(A$,{asChild:!0,children:d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,s.onClose)})})});P1.displayName=M$;var A$=w.forwardRef((t,e)=>{const{__scopeToast:n,altText:r,...s}=t;return d.jsx(Ae.div,{"data-radix-toast-announce-exclude":"","data-radix-toast-announce-alt":r||void 0,...s,ref:e})});function j$(t){const e=[];return Array.from(t.childNodes).forEach(r=>{if(r.nodeType===r.TEXT_NODE&&r.textContent&&e.push(r.textContent),xie(r)){const s=r.ariaHidden||r.hidden||r.style.display==="none",o=r.dataset.radixToastAnnounceExclude==="";if(!s)if(o){const i=r.dataset.radixToastAnnounceAlt;i&&e.push(i)}else e.push(...j$(r))}}),e}function Th(t,e,n,{discrete:r}){const s=n.originalEvent.currentTarget,o=new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n});e&&s.addEventListener(t,e,{once:!0}),r?$b(s,o):s.dispatchEvent(o)}var mE=(t,e,n=0)=>{const r=Math.abs(t.x),s=Math.abs(t.y),o=r>s;return e==="left"||e==="right"?o&&r>n:!o&&s>n};function vie(t=()=>{}){const e=qt(t);yi(()=>{let n=0,r=0;return n=window.requestAnimationFrame(()=>r=window.requestAnimationFrame(e)),()=>{window.cancelAnimationFrame(n),window.cancelAnimationFrame(r)}},[e])}function xie(t){return t.nodeType===t.ELEMENT_NODE}function wie(t){const e=[],n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>{const s=r.tagName==="INPUT"&&r.type==="hidden";return r.disabled||r.hidden||s?NodeFilter.FILTER_SKIP:r.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)e.push(n.currentNode);return e}function pS(t){const e=document.activeElement;return t.some(n=>n===e?!0:(n.focus(),document.activeElement!==e))}var bie=_$,Pie=I$,Cie=E$,_ie=T$,yE=P1;const O$=w.createContext(null);function Iie({children:t}){const e=q0("toasts",[]),n=w.useMemo(()=>({toasts:e,addToast(r){const s=r.id??ze();return e.update(o=>[...o.filter(i=>i.id!==r.id),{...r,id:s}]),s},removeToast(r){return e.update(s=>s.filter(o=>o.id!==r)),r},clearToasts(){e.set([])}}),[e]);return d.jsx(w$,{children:d.jsx(O$.Provider,{value:n,children:t})})}function To(){const t=w.useContext(O$);if(!t)throw new Error("useToasts must be used within a ToastsProvider");return t}var C1={exports:{}};C1.exports;(function(t){var e=function(){var n=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",o={};function i(l,c){if(!o[l]){o[l]={};for(var u=0;u<l.length;u++)o[l][l.charAt(u)]=u}return o[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),h=0,f=c.length;h<f;h++){var p=c.charCodeAt(h);u[h*2]=p>>>8,u[h*2+1]=p%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,h=c.length;u<h;u++)c[u]=l[u*2]*256+l[u*2+1];var f=[];return c.forEach(function(p){f.push(n(p))}),a.decompress(f.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return s.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(s,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 h,f,p={},g={},m="",v="",y="",S=2,b=3,P=2,C=[],_=0,E=0,k;for(k=0;k<l.length;k+=1)if(m=l.charAt(k),Object.prototype.hasOwnProperty.call(p,m)||(p[m]=b++,g[m]=!0),v=y+m,Object.prototype.hasOwnProperty.call(p,v))y=v;else{if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(f=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}else{for(f=1,h=0;h<P;h++)_=_<<1|f,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=0;for(f=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(f=p[y],h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;S--,S==0&&(S=Math.pow(2,P),P++),p[v]=b++,y=String(m)}if(y!==""){if(Object.prototype.hasOwnProperty.call(g,y)){if(y.charCodeAt(0)<256){for(h=0;h<P;h++)_=_<<1,E==c-1?(E=0,C.push(u(_)),_=0):E++;for(f=y.charCodeAt(0),h=0;h<8;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}else{for(f=1,h=0;h<P;h++)_=_<<1|f,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=0;for(f=y.charCodeAt(0),h=0;h<16;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1}S--,S==0&&(S=Math.pow(2,P),P++),delete g[y]}else for(f=p[y],h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;S--,S==0&&(S=Math.pow(2,P),P++)}for(f=2,h=0;h<P;h++)_=_<<1|f&1,E==c-1?(E=0,C.push(u(_)),_=0):E++,f=f>>1;for(;;)if(_=_<<1,E==c-1){C.push(u(_));break}else E++;return C.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var h=[],f=4,p=4,g=3,m="",v=[],y,S,b,P,C,_,E,k={val:u(0),position:c,index:1};for(y=0;y<3;y+=1)h[y]=y;for(b=0,C=Math.pow(2,2),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;E=n(b);break;case 2:return""}for(h[3]=E,S=E,v.push(E);;){if(k.index>l)return"";for(b=0,C=Math.pow(2,g),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;switch(E=b){case 0:for(b=0,C=Math.pow(2,8),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[p++]=n(b),E=p-1,f--;break;case 1:for(b=0,C=Math.pow(2,16),_=1;_!=C;)P=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),b|=(P>0?1:0)*_,_<<=1;h[p++]=n(b),E=p-1,f--;break;case 2:return v.join("")}if(f==0&&(f=Math.pow(2,g),g++),h[E])m=h[E];else if(E===p)m=S+S.charAt(0);else return null;v.push(m),h[p++]=S+m.charAt(0),f--,S=m,f==0&&(f=Math.pow(2,g),g++)}}};return a}();t!=null?t.exports=e:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return e})})(C1);var Eie=C1.exports;const D$=wi(Eie),_1="web image/vnd.tldraw+png",kie={"image/png":_1},Tie={[_1]:"image/png"};function Mie(t){return hn(kie,t)??null}function Aie(t){return hn(Tie,t)??t}function jie(t){return typeof ClipboardItem<"u"&&"supports"in ClipboardItem&&ClipboardItem.supports(t)}function Oie(t){const e=Object.entries(t);for(const[n,r]of e)r.catch(s=>console.error(s));return navigator.clipboard.write([new ClipboardItem(t)]).catch(n=>(console.error(n),Promise.all(e.map(async([r,s])=>[r,await s])).then(r=>{const s=w0(r);return navigator.clipboard.write([new ClipboardItem(s)])})))}async function Die(t,e,n){var y,S,b;const{elements:r,files:s}=e,o={shapes:[],bindings:[],rootShapeIds:[],assets:[],schema:t.store.schema.serialize()},i=new Map,a=new Map,l=t.getCurrentPageId(),c=new Map,u=[],h=new Set;r.forEach(P=>{if(c.set(P.id,Ke()),P.boundElements!==null)for(const C of P.boundElements)C.type==="text"&&h.add(C.id)});let f=QT;for(const P of r){if(h.has(P.id))continue;const C=c.get(P.id),_={id:C,typeName:"shape",parentId:l,index:f,x:P.x,y:P.y,rotation:0,isLocked:P.locked,opacity:Rie(P.opacity),meta:{}};switch(P.angle!==0&&a.set(C,P.angle),P.groupIds&&P.groupIds.length>0?i.has(P.groupIds[0])?(y=i.get(P.groupIds[0]))==null||y.push(C):i.set(P.groupIds[0],[C]):u.push(C),P.type){case"rectangle":case"ellipse":case"diamond":{let E="",k="middle";if(P.boundElements!==null){for(const T of P.boundElements)if(T.type==="text"){const j=r.find(L=>L.id===T.id);j&&(E=j.text,k=Uie[j.textAlign])}}const D=P.backgroundColor==="transparent"?P.strokeColor:P.backgroundColor;o.shapes.push({..._,type:"geo",props:{geo:P.type,url:P.link??"",w:P.width,h:P.height,size:Mh[P.strokeWidth]??"draw",color:Ac[D]??"black",text:E,align:k,dash:Ah(P),fill:Wie(P)}});break}case"freedraw":{o.shapes.push({..._,type:"draw",props:{dash:Ah(P),size:Mh[P.strokeWidth],color:Ac[P.strokeColor]??"black",segments:[{type:"free",points:P.points.map(([E,k,D=.5])=>({x:E,y:k,z:D}))}]}});break}case"line":{if(P.points.slice().length<2)break;const k=Fu(P.points.length);o.shapes.push({..._,type:"line",props:{dash:Ah(P),size:Mh[P.strokeWidth],color:Ac[P.strokeColor]??"black",spline:P.roundness?"cubic":"line",points:{...Object.fromEntries(P.points.map(([D,T],j)=>{const L=k[j];return[L,{id:L,index:L,x:D,y:T}]}))}}});break}case"arrow":{let E="";if(P.boundElements!==null){for(const L of P.boundElements)if(L.type==="text"){const M=r.find(O=>O.id===L.id);M&&(E=M.text)}}const k=P.points[0],D=P.points[P.points.length-1],T=c.get((S=P.startBinding)==null?void 0:S.elementId),j=c.get((b=P.endBinding)==null?void 0:b.elementId);o.shapes.push({..._,type:"arrow",props:{text:E,bend:Kie(P,k,D),dash:Ah(P),size:Mh[P.strokeWidth]??"m",color:Ac[P.strokeColor]??"black",start:{x:k[0],y:k[1]},end:{x:D[0],y:D[1]},arrowheadEnd:SE[P.endArrowhead]??"none",arrowheadStart:SE[P.startArrowhead]??"none"}}),T&&o.bindings.push({id:Ji(),typeName:"binding",type:"arrow",fromId:C,toId:T,props:{terminal:"start",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}}),j&&o.bindings.push({id:Ji(),typeName:"binding",type:"arrow",fromId:C,toId:j,props:{terminal:"end",normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1},meta:{}});break}case"text":{const{size:E,scale:k}=$ie(P.fontSize);o.shapes.push({..._,type:"text",props:{size:E,scale:k,font:Fie[P.fontFamily]??"draw",color:Ac[P.strokeColor]??"black",text:P.text,textAlign:Hie[P.textAlign]}});break}case"image":{const E=s[P.fileId];if(!E)break;const k=Yo.createId();o.assets.push({id:k,typeName:"asset",type:"image",props:{w:P.width,h:P.height,fileSize:E.size,name:P.id??"Untitled",isAnimated:!1,mimeType:E.mimeType,src:E.dataURL},meta:{}}),o.shapes.push({..._,type:"image",props:{w:P.width,h:P.height,assetId:k}})}}f=_s(f)}const p=n??(t.inputs.shiftKey?t.inputs.currentPagePoint:void 0);t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(o,{point:p,select:!1,preserveIds:!0});for(const P of i.values())if(P.length>1){t.groupShapes(P);const C=t.getShape(P[0]);C!=null&&C.parentId&&Fn(C.parentId)&&u.push(C.parentId)}for(const[P,C]of a)t.select(P),t.rotateShapesBy([P],C);const g=me(u.map(P=>t.getShape(P))),m=Z.Common(g.map(P=>t.getShapePageBounds(P))),v=t.getViewportPageBounds().center;t.updateShapes(g.map(P=>{const C={x:(P.x??0)-(m.x+m.w/2),y:(P.y??0)-(m.y+m.h/2)};return{id:P.id,type:P.type,x:v.x+C.x,y:v.y+C.y}})),t.setSelectedShapes(u)}const Rie=t=>{const e=t/100;return e<.2?.1:e<.4?.25:e<.6?.5:e<.8?.75:1},Mh={1:"s",2:"m",3:"l",4:"xl"},Lie={16:"s",20:"m",28:"l",36:"xl"};function $ie(t){const e=Lie[t];return e?{size:e,scale:1}:t<16?{size:"s",scale:t/16}:t>36?{size:"xl",scale:t/36}:{size:"m",scale:1}}const Fie={1:"draw",2:"sans",3:"mono"},Nie={gray:["#f8f9fa","#e9ecef","#ced4da","#868e96","#343a40"],red:["#fff5f5","#ffc9c9","#ff8787","#fa5252","#e03131"],pink:["#fff0f6","#fcc2d7","#f783ac","#e64980","#c2255c"],grape:["#f8f0fc","#eebefa","#da77f2","#be4bdb","#9c36b5"],violet:["#f3f0ff","#d0bfff","#9775fa","#7950f2","#6741d9"],indigo:["#edf2ff","#bac8ff","#748ffc","#4c6ef5","#3b5bdb"],blue:["#e7f5ff","#a5d8ff","#4dabf7","#228be6","#1971c2"],cyan:["#e3fafc","#99e9f2","#3bc9db","#15aabf","#0c8599"],teal:["#e6fcf5","#96f2d7","#38d9a9","#12b886","#099268"],green:["#ebfbee","#b2f2bb","#69db7c","#40c057","#2f9e44"],lime:["#f4fce3","#d8f5a2","#a9e34b","#82c91e","#66a80f"],yellow:["#fff9db","#ffec99","#ffd43b","#fab005","#f08c00"],orange:["#fff4e6","#ffd8a8","#ffa94d","#fd7e14","#e8590c"]};function Ss(t,e,n){const r=[0,1,2,3,4].map(s=>Nie[t][s]);return Object.fromEntries(r.map((s,o)=>[s,o<3?e:n]))}const Ac={...Ss("gray","grey","black"),...Ss("red","light-red","red"),...Ss("pink","light-red","red"),...Ss("grape","light-violet","violet"),...Ss("blue","light-blue","blue"),...Ss("cyan","light-blue","blue"),...Ss("teal","light-green","green"),...Ss("green","light-green","green"),...Ss("yellow","yellow","orange"),...Ss("orange","yellow","orange"),"#ffffff":"white","#000000":"black"},zie={solid:"draw",dashed:"dashed",dotted:"dotted"},Bie={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},Uie={left:"start",center:"middle",right:"end"},Hie={left:"start",center:"middle",right:"end"},SE={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Kie(t,e,n){let r=0;if(t.points.length>2){const s=new x(e[0],e[1]),o=new x(n[0],n[1]),i=new x(t.points[1][0],t.points[1][1]),a=x.Sub(o,s),l=x.Per(a),c=x.Med(o,s),u=x.Sub(c,l),h=x.Add(c,l),f=x.NearestPointOnLineSegment(u,h,i,!1);r=x.Dist(f,c),x.Clockwise(f,o,c)&&(r*=-1)}return r}const Ah=t=>{let e=zie[t.strokeStyle]??"draw";return e==="draw"&&t.roughness===0&&(e="solid"),e},Wie=t=>t.backgroundColor==="transparent"?"none":Bie[t.fillStyle]??"solid";async function Gie(t,e,n,r){const s=e.map(o=>o instanceof File?o:new File([o],"tldrawFile",{type:o.type}));t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"files",files:s,point:n,ignoreParent:!1,sources:r})}function Vie(t,e,n){const r=t.getSelectionPageBounds();t.markHistoryStoppingPoint("paste"),t.putContentOntoCurrentPage(e,{point:n,select:!0});const s=t.getSelectionPageBounds();r&&s&&(r!=null&&r.collides(s))&&(t.updateInstanceState({isChangingStyle:!0}),t.timers.setTimeout(()=>{t.updateInstanceState({isChangingStyle:!1})},150))}async function Gx(t,e,n,r){return t.markHistoryStoppingPoint("paste"),await t.putExternalContent({type:"url",point:n,url:e,sources:r})}const Yie=[_1,"image/png","image/jpeg","image/webp","image/svg+xml"];function Xie(t){const e=document.implementation.createHTMLDocument("");return e.documentElement.innerHTML=t.trim(),e.body.textContent||e.body.innerText||""}const qie=t=>{try{const e=new URL(t);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}},Zie=t=>{const e=t.split(/[\n\s]/);for(const n of e)try{const r=new URL(n);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return Pj(e)},Qie=t=>/^<svg/.test(t),Jie=["input","select","textarea"];function gS(t){const{activeElement:e}=document;return t.menus.hasAnyOpenMenus()||e&&(e.getAttribute("contenteditable")||Jie.indexOf(e.tagName.toLowerCase())>-1)}const jh=(t,e,n,r)=>{const s=Zie(e);if(s)for(const o of s)Gx(t,o,n);else qie(e)?Gx(t,e,n):Qie(e)?(t.markHistoryStoppingPoint("paste"),t.putExternalContent({type:"svg-text",text:e,point:n,sources:r})):(t.markHistoryStoppingPoint("paste"),t.putExternalContent({type:"text",text:e,point:n,sources:r}))},eae=async(t,e,n)=>{if(t.getEditingShapeId()!==null)return;if(!e)throw Error("No clipboard data");const r=[];for(const s of Object.values(e.items))switch(s.kind){case"file":{r.push({type:"file",source:new Promise(o=>o(s.getAsFile()))});break}case"string":{s.type==="text/html"?r.push({type:"html",source:new Promise(o=>s.getAsString(o))}):s.type==="text/plain"?r.push({type:"text",source:new Promise(o=>s.getAsString(o))}):r.push({type:s.type,source:new Promise(o=>s.getAsString(o))});break}}L$(t,r,n)},R$=async({editor:t,clipboardItems:e,point:n,fallbackFiles:r})=>{const s=[];for(const o of e){for(const i of Yie)if(o.types.includes(i)){const a=o.getType(i).then(l=>Zr.rewriteMimeType(l,Aie(i)));s.push({type:"blob",source:a});break}o.types.includes("text/html")&&s.push({type:"html",source:(async()=>{const i=await o.getType("text/html");return await Zr.blobToText(i)})()}),o.types.includes("text/uri-list")&&s.push({type:"url",source:(async()=>{const i=await o.getType("text/uri-list");return await Zr.blobToText(i)})()}),o.types.includes("text/plain")&&s.push({type:"text",source:(async()=>{const i=await o.getType("text/plain");return await Zr.blobToText(i)})()})}return r&&s.length===1&&s[0].type==="text"&&(s.pop(),s.push(...r.map(o=>({type:"file",source:Promise.resolve(o)})))),await L$(t,s,n)};async function L$(t,e,n){const r=e.filter(o=>(o.type==="file"||o.type==="blob")&&o.source!==null);if(r.length){if(r.length>t.options.maxFilesAtOnce)throw Error("Too many files");const o=me(await Promise.all(r.map(i=>i.source)));return await Gie(t,o,n)}const s=await Promise.all(e.filter(o=>o.type!=="file").map(o=>new Promise(i=>{const a=o;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<div data-tldraw[^>]*>(.*)<\/div>/))==null?void 0:u[1];if(c)try{const h=D$.decompressFromBase64(c);if(h===null){i({type:"error",data:h,reason:"found tldraw data comment but could not parse base64"});return}else{const f=JSON.parse(h);if(f.type!=="application/tldraw"&&i({type:"error",data:f,reason:`found tldraw data comment but JSON was of a different type: ${f.type}`}),typeof f.data=="string"){i({type:"error",data:f,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:f.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const h=JSON.parse(l);if(h.type==="excalidraw/clipboard"){i({type:"excalidraw",data:h});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const o of s)if(o.type==="tldraw"){Vie(t,o.data,n);return}for(const o of s)if(o.type==="excalidraw"){Die(t,o.data,n);return}for(const o of s){if(o.type==="text"&&o.subtype==="html"){const a=new DOMParser().parseFromString(o.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");jh(t,c,n,s);return}if(!s.some(c=>c.type==="text"&&c.subtype!=="html")&&o.data.trim()){jh(t,Xie(o.data),n,s);return}}if(o.type==="text"&&o.subtype==="text"&&o.data.startsWith("<iframe ")){const a=new DOMParser().parseFromString(o.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="IFRAME"&&a.firstElementChild.hasAttribute("src")&&a.firstElementChild.getAttribute("src")!==""){const c=a.firstElementChild.getAttribute("src");jh(t,c,n,s);return}}}for(const o of s)if(o.type==="text"&&o.subtype==="url"){Gx(t,o.data,n,s);return}for(const o of s)if(o.type==="text"&&o.subtype==="text"&&o.data.trim()){jh(t,o.data,n,s);return}}const Vp=async t=>{var r;const e=await t.resolveAssetsInContent(t.getContentFromCurrentPage(t.getSelectedShapeIds()));if(!e){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const n=D$.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:e}));if(!(typeof navigator>"u")){const s=e.shapes.map(o=>t.getShapeUtil(o).getText(o)).filter(pB);if((r=navigator.clipboard)!=null&&r.write){const o=new Blob([`<div data-tldraw>${n}</div>`],{type:"text/html"});let i=s.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<div data-tldraw>${n}</div>`)}};function tae(){const t=z(),e=Jt(),n=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Vp(t),e("copy",{source:i}))},[t,e]),r=w.useCallback(async function(i){t.getSelectedShapeIds().length!==0&&(await Vp(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:i}))},[t,e]),s=w.useCallback(async function(i,a,l){t.getEditingShapeId()===null&&(Array.isArray(i)&&i[0]instanceof ClipboardItem?(R$({editor:t,clipboardItems:i,point:l}),e("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{s(c,a,l)}))},[t,e]);return{copy:n,cut:r,paste:s}}function nae(){const t=z(),e=Jt(),n=U("editor.isFocused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!n)return;const r=async l=>{t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||gS(t)||(xe(l),await Vp(t),e("copy",{source:"kbd"}))};async function s(l){t.getSelectedShapeIds().length===0||t.getEditingShapeId()!==null||gS(t)||(xe(l),await Vp(t),t.deleteShapes(t.getSelectedShapeIds()),e("cut",{source:"kbd"}))}let o=!1;const i=l=>{l.button===1&&(o=!0,t.timers.requestAnimationFrame(()=>{o=!1}))},a=l=>{var f,p;if(o){Ct(l);return}if(t.getEditingShapeId()!==null||gS(t))return;let c,u=!1;t.inputs.shiftKey&&(u=!0),t.user.getIsPasteAtCursorMode()&&(u=!u),u&&(c=t.inputs.currentPagePoint);const h=()=>{l.clipboardData&&eae(t,l.clipboardData,c)};if((f=navigator.clipboard)!=null&&f.read){const g=Array.from(((p=l.clipboardData)==null?void 0:p.files)||[]);navigator.clipboard.read().then(m=>{Array.isArray(m)&&m[0]instanceof ClipboardItem&&R$({editor:t,clipboardItems:m,point:c,fallbackFiles:g})},()=>{h()})}else h();xe(l),e("paste",{source:"kbd"})};return document.addEventListener("copy",r),document.addEventListener("cut",s),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",s),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[t,e,n])}/*!
|
|
240
240
|
* canvas-size
|
|
241
241
|
* v1.2.6
|
|
242
242
|
* https://github.com/jhildenbiddle/canvas-size
|
|
@@ -380,7 +380,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
380
380
|
</body>
|
|
381
381
|
</html>`})}function iw(t,e){const s=((ea(t.getShapePageTransform(e.id).rotation())+Math.PI/4)*(2/Math.PI)+4)%4;return Math.floor(s)}function HE(t,e,n){const r=t.textMeasure.measureTextSpans(S5(e.props.name,"Frame")+"",n),s=r[0],o=Ht(r),i=o.box.w+o.box.x-s.box.x;return{box:new Z(0,-n.height,i,n.height),spans:r}}function KE(t,e){return{fontSize:12,fontFamily:"Inter, sans-serif",textAlign:"start",width:t.props.w,height:32,padding:0,lineHeight:1,fontStyle:"normal",fontWeight:"normal",overflow:"truncate-ellipsis",verticalTextAlign:"middle",fill:e,offsetY:-34,offsetX:2}}function y5(t,e,n){const r=n?"":"px",s=n?"":"deg";let o;switch(e){case 0:o="";break;case 3:o=`translate(${N(t.props.w)}${r}, 0${r}) rotate(90${s})`;break;case 2:o=`translate(${N(t.props.w)}${r}, ${N(t.props.h)}${r}) rotate(180${s})`;break;case 1:o=`translate(0${r}, ${N(t.props.h)}${r}) rotate(270${s})`;break;default:throw Error("labelSide out of bounds")}return o}const Kce=w.forwardRef(({id:t,name:e,isEditing:n},r)=>{const s=z(),o=w.useCallback(l=>{l.key==="Enter"&&!l.nativeEvent.isComposing&&(Ct(l),l.currentTarget.blur(),s.setEditingShape(null))},[s]),i=w.useCallback(l=>{const c=s.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value.trim();u!==h&&s.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,s]),a=w.useCallback(l=>{const c=s.getShape(t);if(!c)return;const u=c.props.name,h=l.currentTarget.value;u!==h&&s.updateShapes([{id:t,type:"frame",props:{name:h}}])},[t,s]);return d.jsxs("div",{className:`tl-frame-label ${n?"tl-frame-label__editing":""}`,children:[d.jsx("input",{className:"tl-frame-name-input",ref:r,style:{display:n?void 0:"none"},value:e,autoFocus:!0,onKeyDown:o,onBlur:i,onChange:a}),S5(e,"Frame")+""]})});function Wce({id:t,name:e,width:n,height:r}){const s=z(),{side:o,translation:i}=U("shape rotation",()=>{const c=s.getShape(t);if(!c)return{side:0,translation:"translate(0, 0)"};const u=iw(s,c);return{side:u,translation:y5(c,u,!1)}},[s,t]),a=w.useRef(null),l=Zg(t);return w.useEffect(()=>{const c=a.current;c&&l&&(c.focus(),c.select())},[a,l]),d.jsx("div",{className:"tl-frame-heading",style:{overflow:l?"visible":"hidden",maxWidth:`calc(var(--tl-zoom) * ${Math.ceil(o===0||o===2?n:r)}px + var(--space-5))`,bottom:"100%",transform:`${i} scale(var(--tl-scale)) translateX(calc(-1 * var(--space-3))`},children:d.jsx("div",{className:"tl-frame-heading-hit-area",children:d.jsx(Kce,{ref:a,id:t,name:e,isEditing:l})})})}function S5(t,e){return t.match(/^\s*$/)?e:t}class _f extends oc{canEdit(){return!0}getDefaultProps(){return{w:160*2,h:90*2,name:""}}getGeometry(e){const{editor:n}=this,r=n.getZoomLevel(),s=KE(e,"black"),o=HE(n,e,s),i=iw(n,e);let a,l,c,u;const{w:h,h:f}=o.box,p=Math.min(h,e.props.w*r),g=Math.min(f,e.props.h*r);switch(i){case 0:{a=-8/r,l=(-f-4)/r,c=(p+16)/r,u=f/r;break}case 1:{a=(-f-4)/r,u=(g+16)/r,l=e.props.h-u+8/r,c=f/r;break}case 2:{a=e.props.w-(p+8)/r,l=e.props.h+4/r,c=(g+16)/r,u=f/r;break}case 3:{a=e.props.w+4/r,u=(g+16)/r,l=-8/r,c=f/r;break}}return new $r({children:[new Fs({width:e.props.w,height:e.props.h,isFilled:!1}),new Fs({x:a,y:l,width:c,height:u,isFilled:!0,isLabel:!0})]})}getText(e){return e.props.name}component(e){const n=this.editor.getShapeGeometry(e).bounds,r=zr(),s=U("is creating this shape",()=>{const o=this.editor.getStateDescendant("select.resizing");if(!o||!o.getIsActive())return!1;const i=o==null?void 0:o.info;return i?i.isCreating&&this.editor.getOnlySelectedShapeId()===e.id:!1},[e.id]);return d.jsxs(d.Fragment,{children:[d.jsx(mi,{children:d.jsx("rect",{className:ce("tl-frame__body",{"tl-frame__creating":s}),width:n.width,height:n.height,fill:r.solid,stroke:r.text})}),s?null:d.jsx(Wce,{id:e.id,name:e.props.name,width:n.width,height:n.height})]})}toSvg(e,n){const r=ko({isDarkMode:n.isDarkMode}),s=iw(this.editor,e),o=y5(e,s,!0),i=KE(e,r.text),{box:a,spans:l}=HE(this.editor,e,i),c=rw(this.editor,l,i);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{width:e.props.w,height:e.props.h,fill:r.solid,stroke:r.black.solid,strokeWidth:1,rx:1,ry:1}),d.jsxs("g",{transform:o,children:[d.jsx("rect",{x:a.x-8,y:a.y-4,width:a.width+20,height:a.height,fill:r.background,rx:4,ry:4}),c]})]})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds;return d.jsx("rect",{width:N(n.width),height:N(n.height),className:"tl-frame-indicator"})}canReceiveNewChildrenOfType(e,n){return!e.isLocked}providesBackgroundForChildren(){return!0}canDropShapes(e,n){return!e.isLocked}onDragShapesOver(e,n){n.every(r=>r.parentId===e.id)||this.editor.reparentShapes(n,e.id)}onDragShapesOut(e,n){const r=this.editor.getShape(e.parentId);r&&this.editor.isShapeOfType(r,"group")?this.editor.reparentShapes(n,r.id):this.editor.reparentShapes(n,this.editor.getCurrentPageId())}onResize(e,n){return qg(e,n)}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r)}}}I(_f,"type","frame"),I(_f,"props",zA),I(_f,"migrations",BA);function WE(t,e){return t>e?(De*(e/2)+(t-e))*2:(De*(t/2)+(e-t))*2}function v5(t,e){return $1(t,e).map((n,r)=>n.getSvgPathData(r===0)).join(" ")+" Z"}function Gce(t,e,n,r){const s=t/4,o=e/4,i=cs(r),a=n*.75,l=S=>S.addXY(i()*a,i()*a),c=new x(t/2,e),u=new x(0,o*1.2),h=new x(t/2,o*.9),f=new x(t,o*1.2),p=l(new x(t/2,e)),g=l(new x(0,o*1.2)),m=l(new x(t/2,o*.9)),v=l(new x(t,o*1.2));return[new an({start:c,cp1:new x(s*1.5,o*3),cp2:new x(0,o*2.5),end:u}),new an({start:u,cp1:new x(0,-o*.32),cp2:new x(s*1.85,-o*.32),end:h}),new an({start:h,cp1:new x(s*2.15,-o*.32),cp2:new x(t,-o*.32),end:f}),new an({start:f,cp1:new x(t,o*2.5),cp2:new x(s*2.5,o*3),end:p}),new an({start:p,cp1:new x(s*1.5,o*3),cp2:new x(0,o*2.5),end:g}),new an({start:g,cp1:new x(0,-o*.32),cp2:new x(s*1.85,-o*.32),end:m}),new an({start:m,cp1:new x(s*2.15,-o*.32),cp2:new x(t,-o*.32),end:v}),new an({start:v,cp1:new x(t,o*2.5),cp2:new x(s*2.5,o*3),end:c})].map((S,b)=>S.getSvgPathData(b===0)).join(" ")+" Z"}function $1(t,e){const n=t/4,r=e/4;return[new an({start:new x(t/2,e),cp1:new x(n*1.5,r*3),cp2:new x(0,r*2.5),end:new x(0,r*1.2)}),new an({start:new x(0,r*1.2),cp1:new x(0,-r*.32),cp2:new x(n*1.85,-r*.32),end:new x(t/2,r*.9)}),new an({start:new x(t/2,r*.9),cp1:new x(n*2.15,-r*.32),cp2:new x(t,-r*.32),end:new x(t,r*1.2)}),new an({start:new x(t,r*1.2),cp1:new x(t,r*2.5),cp2:new x(n*2.5,r*3),end:new x(t/2,e)})]}function Vce(t){return{size:1+t,thinning:.25,end:{taper:t},start:{taper:t},streamline:0,smoothing:1,simulatePressure:!1}}function Yce(t,e,n,r){const s=cs(t),o=e/2,i=n/2,a=aj(o,i),l=[],c=Fe*s(),u=Fe+Ze/2+Math.abs(s())*Ze,h=Math.max(16,a/10);for(let f=0;f<h;f++){const p=f/(h-1),g=c+p*u,m=Math.cos(g),v=Math.sin(g);l.push(new x(o*m+e*.5+.05*s(),i*v+n/2+.05*s(),Math.min(1,.5+Math.abs(.5-(s()>0?Dt.easeInOutSine(p):Dt.easeInExpo(p)))/2)))}return Bs(l,Vce(r))}function Xce(t,e,n,r){return va(Yce(t,e,n,r))}function aw(t){let e="M";const n=t.length;let r,s,o;for(let i=0,a=n;i<a;i+=3)r=t[i],s=t[i+1],o=t[i+2],e+=`${je(r)}L${je(s)}Q${je(o)}`;return e+=`${je(t[0])}`,e}function lw(t,e,n,r,s){const o=[],i=cs(t);let a=e[0],l;const c=e.length;for(let u=0,h=c*s;u<h;u++){l=x.AddXY(e[(u+1)%c],i()*n,i()*n);const f=x.Sub(l,a),p=x.Len(f),g=x.Div(f,p).mul(Math.min(p/4,r));o.push(x.Add(a,g),x.Add(l,g.neg()),l),a=l}return o}function qce(t,e,n){const r=Math.min(t,e)/2,s=Math.max(t,e)-r*2,i=(Math.PI*(r*2)+2*s)/n,a=t>e?[{type:"straight",start:new x(r,0),delta:new x(1,0)},{type:"arc",center:new x(t-r,r),startAngle:-De/2},{type:"straight",start:new x(t-r,e),delta:new x(-1,0)},{type:"arc",center:new x(r,r),startAngle:De/2}]:[{type:"straight",start:new x(t,r),delta:new x(0,1)},{type:"arc",center:new x(r,e-r),startAngle:0},{type:"straight",start:new x(0,e-r),delta:new x(0,-1)},{type:"arc",center:new x(r,r),startAngle:De}];let l=0;const c=[];for(let u=0;u<n;u++){const h=a[0];h.type==="straight"?c.push(x.Add(h.start,x.Mul(h.delta,l))):c.push(ha(h.center,r,h.startAngle+l/r)),l+=i;let f=h.type==="straight"?s:De*r;for(;l>f;)l-=f,a.push(a.shift()),f=a[0].type==="straight"?s:De*r}return c}const Zce={s:50,m:70,l:100,xl:130},Qce=.2;function _m(t,e,n,r,s){const o=cs(n),i=WE(t,e),a=Math.max(Math.ceil(i/Zce[r]),6,Math.ceil(i/Math.min(t,e))),l=i/a*Qce,c=Math.max(t-l*2,1),u=Math.max(e-l*2,1),f=WE(c,u)/a,p=(t-c)/2,g=(e-u)/2,m=qce(c,u,a).map(P=>P.addXY(p,g)),v=t<20?0:l*.3,y=e<20?0:l*.3,S=m.slice(0);for(let P=0;P<Math.floor(a/2);P++)S[P]=x.AddXY(S[P],o()*v*s,o()*y*s),S[a-P-1]=x.AddXY(S[a-P-1],o()*v*s,o()*y*s);const b=[];for(let P=0;P<S.length;P++){const C=P===S.length-1?0:P+1,_=S[P],E=S[C],k=m[P],D=m[C],T=x.Dist(k,D),j=f-T,M=x.Dist(_,E)/T,O=(Math.max(p,g)+j)*M,F=x.Lrp(k,D,.5).add(x.Sub(D,k).uni().per().mul(O));F.x<0?F.x=0:F.x>t&&(F.x=t),F.y<0?F.y=0:F.y>e&&(F.y=e);const B=pb(_,E,F),K=x.Dist(B||x.Average([_,E]),_);b.push({leftPoint:_,rightPoint:E,arcPoint:F,center:B,radius:K})}return b}function Jce(t,e,n,r,s){const o=[],i=_m(t,e,n,r,s);for(const{center:a,radius:l,leftPoint:c,rightPoint:u}of i)o.push(...xX(c,u,a,l,10));return o}function cw(t,e,n,r,s){const o=_m(t,e,n,r,s);let i=`M${o[0].leftPoint.toFixed()}`;for(const{leftPoint:a,rightPoint:l,radius:c,center:u}of o){if(u===null){i+=` L${l.toFixed()}`;continue}const h=x.Clockwise(a,l,u)?"0":"1";i+=` A${N(c)},${N(c)} 0 ${h},1 ${l.toFixed()}`}return i+=" Z",i}const eue={s:.5,m:.7,l:.9,xl:1.6};function tue(t,e,n,r,s){const o=cs(n),i=eue[r]*s,a=_m(t,e,n,r,s),u=a.reduce((g,m)=>g+x.Dist2(m.leftPoint,m.rightPoint),0)/a.length>(i*15)**2?g=>x.AddXY(g,o()*i*2,o()*i*2):g=>g;let h=`M${a[0].leftPoint.toFixed()}`,f=u(a[0].leftPoint),p=`M${f.toFixed()}`;for(const{leftPoint:g,center:m,rightPoint:v,radius:y,arcPoint:S}of a){if(m===null){h+=` L${v.toFixed()}`;const k=u(v);p+=` L${k.toFixed()}`,f=k;continue}const b=x.Clockwise(g,v,m)?"0":"1";h+=` A${N(y)},${N(y)} 0 ${b},1 ${v.toFixed()}`;const P=u(v),C=u(S),_=pb(f,P,C);if(!_){p+=` L${P.toFixed()}`,f=P;continue}const E=Math.abs(x.Dist(_,f));p+=` A${N(E)},${N(E)} 0 ${b},1 ${P.toFixed()}`,f=P}return h+p+" Z"}function uw(t,e){switch(t.geo){case"x-box":return nue(t.w,t.h,e,t.dash);case"check-box":return rue(t.w,t.h);default:return}}function nue(t,e,n,r){const s=r==="draw"?.62:0;if(r==="dashed")return[[new x(0,0),new x(t/2,e/2)],[new x(t,e),new x(t/2,e/2)],[new x(0,e),new x(t/2,e/2)],[new x(t,0),new x(t/2,e/2)]];const o=a=>Math.max(0,Math.min(t,a)),i=a=>Math.max(0,Math.min(e,a));return[[new x(o(n*s),i(n*s)),new x(o(t-n*s),i(e-n*s))],[new x(o(n*s),i(e-n*s)),new x(o(t-n*s),i(n*s))]]}function rue(t,e){const n=Math.min(t,e)*.82,r=(t-n)/2,s=(e-n)/2,o=a=>Math.max(0,Math.min(t,a)),i=a=>Math.max(0,Math.min(e,a));return[[new x(o(r+n*.25),i(s+n*.52)),new x(o(r+n*.45),i(s+n*.82))],[new x(o(r+n*.45),i(s+n*.82)),new x(o(r+n*.82),i(s+n*.22))]]}function GE({shape:t,shouldScale:e,forceSolid:n}){const r=e?t.props.scale:1,s=z(),o=zr(),{id:i,props:a}=t,{w:l,color:c,fill:u,dash:h,growY:f,size:p,scale:g}=a,m=fn[p]*r,v=a.h+f;switch(a.geo){case"cloud":if(h==="solid"){const y=cw(l,v,i,p,g);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="draw"){const y=tue(l,v,i,p,g);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}else{const y=cw(l,v,i,p,g),S=_m(l,v,i,p,g);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("g",{strokeWidth:m,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:S.map(({leftPoint:b,rightPoint:P,center:C,radius:_},E)=>{const k=C?_*ea(ea(x.Angle(C,P))-ea(x.Angle(C,b))):x.Dist(b,P),{strokeDasharray:D,strokeDashoffset:T}=qr(k,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("path",{d:C?`M${b.x},${b.y}A${_},${_},0,0,1,${P.x},${P.y}`:`M${b.x},${b.y}L${P.x},${P.y}`,strokeDasharray:D,strokeDashoffset:T},E)})})]})}case"ellipse":{const y=e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t),S=y.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=y.length,{strokeDasharray:P,strokeDashoffset:C}=qr(b<64?b*2:b,m,{style:h,snap:4,closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,strokeWidth:m,fill:"none",stroke:o[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else{const P=(e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t)).getSvgPathData(!0);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:P,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}}case"oval":{const y=e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t),S=y.getSvgPathData(!0);if(h==="dashed"||h==="dotted"){const b=y.getLength(),{strokeDasharray:P,strokeDashoffset:C}=qr(b<64?b*2:b,m,{style:h,snap:4,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,strokeWidth:m,fill:"none",stroke:o[c].solid,strokeDasharray:P,strokeDashoffset:C})]})}else return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:S,color:c,fill:u,scale:r}),d.jsx("path",{d:S,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}case"heart":if(h==="dashed"||h==="dotted"||h==="solid"){const y=v5(l,v),S=$1(l,v);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),S.map((b,P)=>{const{strokeDasharray:C,strokeDashoffset:_}=qr(b.length,m,{style:h,snap:1,start:"outset",end:"outset",closed:!0,forceSolid:n});return d.jsx("path",{d:b.getSvgPathData(),strokeWidth:m,fill:"none",stroke:o[c].solid,strokeDasharray:C,strokeDashoffset:_,pointerEvents:"all"},`curve_${P}`)})]})}else{const y=Gce(l,v,m,t.id);return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:y,color:c,fill:u,scale:r}),d.jsx("path",{d:y,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}default:{const y=e?s.getShapeGeometry(t):s.getShapeUtil(t).getGeometry(t),S=y instanceof $r?y.children[0].vertices:y.vertices,b=uw(t.props,m);if(h==="solid"){let P="M"+S[0]+"L"+S.slice(1)+"Z";if(b)for(const[C,_]of b)P+=`M${C.x},${C.y}L${_.x},${_.y}`;return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:P,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}else if(h==="dashed"||h==="dotted"){const P="M"+S[0]+"L"+S.slice(1)+"Z";return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:P,color:c,fill:u,scale:r}),d.jsxs("g",{strokeWidth:m,stroke:o[c].solid,fill:"none",pointerEvents:"all",children:[Array.from(Array(S.length)).map((C,_)=>{const E=x.ToFixed(S[_]),k=x.ToFixed(S[(_+1)%S.length]),D=x.Dist(E,k),{strokeDasharray:T,strokeDashoffset:j}=qr(D,m,{style:h,start:"outset",end:"outset",forceSolid:n});return d.jsx("line",{x1:E.x,y1:E.y,x2:k.x,y2:k.y,strokeDasharray:T,strokeDashoffset:j},_)}),b&&b.map(([C,_],E)=>{const k=x.Dist(C,_),{strokeDasharray:D,strokeDashoffset:T}=qr(k,m,{style:h,start:"skip",end:"skip",snap:h==="dotted"?4:void 0,forceSolid:n});return d.jsx("path",{d:`M${C.x},${C.y}L${_.x},${_.y}`,stroke:o[c].solid,strokeWidth:m,fill:"none",strokeDasharray:D,strokeDashoffset:T},`line_fg_${E}`)})]})]})}else if(h==="draw"){let P=aw(lw(i,S,m/3,m*2,2));if(b)for(const[_,E]of b)P+=`M${_.toFixed()}L${E.toFixed()}`;const C=aw(lw(i,S,0,m*2,1));return d.jsxs(d.Fragment,{children:[d.jsx(sn,{theme:o,d:C,color:c,fill:u,scale:r}),d.jsx("path",{d:P,stroke:o[c].solid,strokeWidth:m,fill:"none"})]})}}}}const VE=17*3;class If extends oc{canEdit(){return!0}getDefaultProps(){return{w:100,h:100,geo:"rectangle",color:"black",labelColor:"black",fill:"none",dash:"draw",size:"m",font:"draw",text:"",align:"middle",verticalAlign:"middle",growY:0,url:"",scale:1}}getGeometry(e){const n=Math.max(1,e.props.w),r=Math.max(1,e.props.h+e.props.growY),s=n/2,o=r/2,i=e.props.fill!=="none";let a;switch(e.props.geo){case"cloud":{a=new vt({points:Jce(n,r,e.id,e.props.size,e.props.scale),isFilled:i});break}case"triangle":{a=new vt({points:[new x(s,0),new x(n,r),new x(0,r)],isFilled:i});break}case"diamond":{a=new vt({points:[new x(s,0),new x(n,o),new x(s,r),new x(0,o)],isFilled:i});break}case"pentagon":{a=new vt({points:Hy(n,r,5),isFilled:i});break}case"hexagon":{a=new vt({points:Hy(n,r,6),isFilled:i});break}case"octagon":{a=new vt({points:Hy(n,r,8),isFilled:i});break}case"ellipse":{a=new mte({width:n,height:r,isFilled:i});break}case"oval":{a=new yte({width:n,height:r,isFilled:i});break}case"star":{const S=Fe/5/2,b=Math.floor(5/4)*2,P=5*2-b,C=0,_=Math.floor(5/2)*2,E=Math.cos(-Ze+b*S)*n/2,k=Math.cos(-Ze+P*S)*n/2,D=Math.sin(-Ze+C*S)*r/2,T=Math.sin(-Ze+_*S)*r/2,j=n-Math.abs(E-k),L=r-Math.abs(T-D),M=n/2+k-(n/2-E),O=r/2+D-(r/2-T),F=1,B=(n-M)/2,K=(r-O)/2,R=(n+j)/2,H=(r+L)/2,X=R*F/2,te=H*F/2;a=new vt({points:Array.from(Array(5*2)).map((le,de)=>{const Me=-Ze+de*S;return new x(B+(de%2?X:R)*Math.cos(Me),K+(de%2?te:H)*Math.sin(Me))}),isFilled:i});break}case"rhombus":{const y=Math.min(n*.38,r*.38);a=new vt({points:[new x(y,0),new x(n,0),new x(n-y,r),new x(0,r)],isFilled:i});break}case"rhombus-2":{const y=Math.min(n*.38,r*.38);a=new vt({points:[new x(0,0),new x(n-y,0),new x(n,r),new x(y,r)],isFilled:i});break}case"trapezoid":{const y=Math.min(n*.38,r*.38);a=new vt({points:[new x(y,0),new x(n-y,0),new x(n,r),new x(0,r)],isFilled:i});break}case"arrow-right":{const y=Math.min(n,r)*.38,S=r*.16;a=new vt({points:[new x(0,S),new x(n-y,S),new x(n-y,0),new x(n,r/2),new x(n-y,r),new x(n-y,r-S),new x(0,r-S)],isFilled:i});break}case"arrow-left":{const y=Math.min(n,r)*.38,S=r*.16;a=new vt({points:[new x(y,0),new x(y,S),new x(n,S),new x(n,r-S),new x(y,r-S),new x(y,r),new x(0,r/2)],isFilled:i});break}case"arrow-up":{const y=n*.16,S=Math.min(n,r)*.38;a=new vt({points:[new x(n/2,0),new x(n,S),new x(n-y,S),new x(n-y,r),new x(y,r),new x(y,S),new x(0,S)],isFilled:i});break}case"arrow-down":{const y=n*.16,S=Math.min(n,r)*.38;a=new vt({points:[new x(y,0),new x(n-y,0),new x(n-y,r-S),new x(n,r-S),new x(n/2,r),new x(0,r-S),new x(y,r-S)],isFilled:i});break}case"check-box":case"x-box":case"rectangle":{a=new Fs({width:n,height:r,isFilled:i});break}case"heart":{const S=$1(n,r).reduce((b,P)=>(b.push(...P.vertices),b),[]);a=new vt({points:S,isFilled:i});break}default:Ot(e.props.geo)}const l=$h(this.editor,e),c=n/e.props.scale,u=r/e.props.scale,h=Math.min(100,c/2),f=Math.min(yo[e.props.size]*pn.lineHeight+Er*2,u/2),p=Math.min(c,Math.max(l.w,Math.min(h,Math.max(1,c-8)))),g=Math.min(u,Math.max(l.h,Math.min(f,Math.max(1,u-8)))),m=uw(e.props,fn[e.props.size]*e.props.scale),v=m?m.map(y=>new nc({points:y})):[];return new $r({children:[a,new Fs({x:e.props.align==="start"?0:e.props.align==="end"?(c-p)*e.props.scale:(c-p)/2*e.props.scale,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?(u-g)*e.props.scale:(u-g)/2*e.props.scale,width:p*e.props.scale,height:g*e.props.scale,isFilled:!0,isLabel:!0}),...v]})}getHandleSnapGeometry(e){const n=this.getGeometry(e),r=n.children[0];switch(e.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:r,points:[...r.getVertices(),n.bounds.center]};case"cloud":case"ellipse":case"heart":case"oval":return{outline:r,points:[n.bounds.center]};default:Ot(e.props.geo)}}getText(e){return e.props.text}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e;s.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.trimEnd()}}])}component(e){const{id:n,type:r,props:s}=e,{fill:o,font:i,align:a,verticalAlign:l,size:c,text:u}=s,h=zr(),{editor:f}=this,p=U("isGeoOnlySelected",()=>e.id===f.getOnlySelectedShapeId(),[]),m=f.getEditingShapeId()!==null||e.props.text,v=U("force solid",()=>f.getZoomLevel()<.2,[f]);return d.jsxs(d.Fragment,{children:[d.jsx(mi,{children:d.jsx(GE,{shape:e,shouldScale:!0,forceSolid:v})}),m&&d.jsx(hi,{style:{overflow:"hidden",width:e.props.w,height:e.props.h+s.growY},children:d.jsx(Cm,{shapeId:n,type:r,font:i,fontSize:yo[c]*e.props.scale,lineHeight:pn.lineHeight,padding:Er*e.props.scale,fill:o,align:a,verticalAlign:l,text:u,isSelected:p,labelColor:h[s.labelColor].solid,wrap:!0})}),e.props.url&&d.jsx(Fl,{url:e.props.url})]})}indicator(e){const{id:n,props:r}=e,{w:s,size:o}=r,i=r.h+r.growY,a=fn[o],l=this.editor.getShapeGeometry(e);switch(r.geo){case"ellipse":return r.dash==="draw"?d.jsx("path",{d:Xce(n,s,i,a)}):d.jsx("path",{d:l.getSvgPathData(!0)});case"heart":return d.jsx("path",{d:v5(s,i)});case"oval":return d.jsx("path",{d:l.getSvgPathData(!0)});case"cloud":return d.jsx("path",{d:cw(s,i,n,o,e.props.scale)});default:{const c=this.editor.getShapeGeometry(e),u=c instanceof $r?c.children[0].vertices:c.vertices;let h;if(r.dash==="draw"){const p=lw(n,u,0,a*2*e.props.scale,1);h=aw(p)}else h="M"+u[0]+"L"+u.slice(1)+"Z";const f=uw(e.props,a);if(f)for(const[p,g]of f)h+=`M${p.x},${p.y}L${g.x},${g.y}`;return d.jsx("path",{d:h})}}}toSvg(e,n){const r={...e,props:{...e.props,w:e.props.w/e.props.scale,h:e.props.h/e.props.scale}},s=r.props;n.addExportDef(j1(s.fill));let o;if(s.text){n.addExportDef(bm(s.font));const i=ko(n),a=new Z(0,0,s.w,s.h+s.growY);o=d.jsx(Pm,{fontSize:yo[s.size],font:s.font,align:s.align,verticalAlign:s.verticalAlign,text:s.text,labelColor:i[s.labelColor].solid,bounds:a,padding:16})}return d.jsxs(d.Fragment,{children:[d.jsx(GE,{shouldScale:!1,shape:r,forceSolid:!1}),o]})}getCanvasSvgDefs(){return[O1()]}onResize(e,{handle:n,newPoint:r,scaleX:s,scaleY:o,initialShape:i}){const a=i.props.w/i.props.scale,l=i.props.h/i.props.scale,c=i.props.growY/i.props.scale;let u=a*s,h=(l+c)*o,f=0,p=0;const g=VE;if(e.props.text.trim()){let P=Math.max(Math.abs(u),g),C=Math.max(Math.abs(h),g);P<g&&C===g&&(P=g),P===g&&C<g&&(C=g);const _=$h(this.editor,{...e,props:{...e.props,w:P*e.props.scale,h:C*e.props.scale}}),E=Math.max(Math.abs(u),_.w)*Math.sign(u),k=Math.max(Math.abs(h),_.h)*Math.sign(h);f=Math.abs(E)-Math.abs(u),p=Math.abs(k)-Math.abs(h),u=E,h=k}const m=u*e.props.scale,v=h*e.props.scale,y=new x(0,0);s<0&&(y.x+=m),(n==="left"||n==="top_left"||n==="bottom_left")&&(y.x+=s<0?f:-f),o<0&&(y.y+=v),(n==="top"||n==="top_left"||n==="top_right")&&(y.y+=o<0?p:-p);const{x:S,y:b}=y.rot(e.rotation).add(r);return{x:S,y:b,props:{w:Math.max(Math.abs(m),1),h:Math.max(Math.abs(v),1),growY:0}}}onBeforeCreate(e){if(!e.props.text)return e.props.growY?{...e,props:{...e.props,growY:0}}:void 0;const n=e.props.h/e.props.scale,r=$h(this.editor,e).h;let s=null;if(r>n?s=r-n:e.props.growY&&(s=0),s!==null)return{...e,props:{...e.props,growY:s*e.props.scale}}}onBeforeUpdate(e,n){const r=e.props.text,s=n.props.text;if(r===s&&e.props.font===n.props.font&&e.props.size===n.props.size)return;if(r&&!s)return{...n,props:{...n.props,growY:0}};const o=e.props.w/e.props.scale,i=e.props.h/e.props.scale,a=e.props.growY/e.props.scale,l=$h(this.editor,n);if(!r&&s&&s.length===1){let u=Math.max(o,l.w),h=Math.max(i,l.h);const f=VE;return o<f&&i<f&&(u=Math.max(u,f),h=Math.max(h,f),u=Math.max(u,h),h=Math.max(u,h)),{...n,props:{...n.props,w:u*n.props.scale,h:h*n.props.scale,growY:0}}}let c=null;if(l.h>i?c=l.h-i:a&&(c=0),c!==null){const u=n.props.w/n.props.scale;return{...n,props:{...n.props,growY:c*n.props.scale,w:Math.max(u,l.w)*n.props.scale}}}if(l.w>o)return{...n,props:{...n.props,w:l.w*n.props.scale}}}onDoubleClick(e){if(this.editor.inputs.altKey)switch(e.props.geo){case"rectangle":return{...e,props:{geo:"check-box"}};case"check-box":return{...e,props:{geo:"rectangle"}}}}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(If,"type","geo"),I(If,"props",UA),I(If,"migrations",HA);function $h(t,e){const{text:n,font:r,size:s,w:o}=e.props;if(!n)return{w:0,h:0};const i=t.textMeasure.measureText("w",{...pn,fontFamily:Co[r],fontSize:yo[s],maxWidth:100}),a={s:2,m:3.5,l:5,xl:10},l=t.textMeasure.measureText(n,{...pn,fontFamily:Co[r],fontSize:yo[s],minWidth:i.w,maxWidth:Math.max(0,Math.ceil(i.w+a[s]),Math.ceil(o/e.props.scale-Er*2))});return{w:l.w+Er*2,h:l.h+Er*2}}function sue(){const[t,e]=w.useState(!1);return w.useEffect(()=>{const r=CSS.supports("color","color(display-p3 1 1 1)"),s=matchMedia("(color-gamut: p3)");e(r&&s.matches);const o=()=>e(r&&s.matches);return s.addEventListener("change",o),()=>s.removeEventListener("change",o)},[]),U(wt.forceSrgb)||!t?"srgb":"p3"}const YE=.35,XE=.82;class Ef extends ss{hideResizeHandles(e){return Fh(e)}hideRotateHandle(e){return Fh(e)}hideSelectionBoundsFg(e){return Fh(e)}getDefaultProps(){return{segments:[],color:"black",size:"m",isComplete:!1,isPen:!1,scale:1}}getGeometry(e){const n=Wi(e);if(Fh(e))return new Lb({x:-n/2,y:-n/2,radius:n/2,isFilled:!0});const{strokePoints:r,sw:s}=qE(e,n,!0),o=L1({strokeWidth:s,showAsComplete:!0});return xm(r,o),new vt({points:k1(r,o),isFilled:!0})}component(e){const n=_S(this.editor,e),r=Wi(e);return d.jsx(mi,{children:d.jsx(Nh,{shape:e,forceSolid:n,strokeWidth:r,opacity:YE})})}backgroundComponent(e){const n=_S(this.editor,e),r=Wi(e);return d.jsx(mi,{children:d.jsx(Nh,{shape:e,forceSolid:n,strokeWidth:r,opacity:XE})})}indicator(e){const n=_S(this.editor,e),r=Wi(e),{strokePoints:s,sw:o}=qE(e,r,n),i=Nl(e.props.segments);let a;return s.length<2?a=iue(i[0],o):a=va(s,!1),d.jsx("path",{d:a})}toSvg(e){const n=Wi(e),r=n<1.5,s=1/e.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(Nh,{forceSolid:r,strokeWidth:n,shape:e,opacity:YE})})}toBackgroundSvg(e){const n=Wi(e),r=n<1.5,s=1/e.props.scale;return d.jsx("g",{transform:`scale(${s})`,children:d.jsx(Nh,{forceSolid:r,strokeWidth:n,shape:e,opacity:XE})})}onResize(e,n){const{scaleX:r,scaleY:s}=n,o=[];for(const i of e.props.segments)o.push({...i,points:i.points.map(({x:a,y:l,z:c})=>({x:r*a,y:s*l,z:c}))});return{props:{segments:o}}}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,...n.props,segments:p5(e.props.segments,n.props.segments,r),scale:_e(e.props.scale,n.props.scale,r)}}}I(Ef,"type","highlight"),I(Ef,"props",GA),I(Ef,"migrations",VA);function oue(t){return`M ${t.x} ${t.y} m -${.1}, 0 a ${.1},${.1} 0 1,0 ${.1*2},0 a ${.1},${.1} 0 1,0 -${.1*2},0`}function iue(t,e){const n=e/2;return`M ${t.x} ${t.y} m -${n}, 0 a ${n},${n} 0 1,0 ${n*2},0 a ${n},${n} 0 1,0 -${n*2},0`}function qE(t,e,n){var l;const r=Nl(t.props.segments),s=t.props.isComplete||((l=Ht(t.props.segments))==null?void 0:l.type)==="straight";let o=e;!n&&!t.props.isPen&&r.length===1&&(o+=cs(t.id)()*(e/6));const i=L1({strokeWidth:o,showAsComplete:s});return{strokePoints:Bs(r,i),sw:o}}function Wi(t){return Ll[t.props.size]*1.12*t.props.scale}function Fh(t){return t.props.segments.length===1&&t.props.segments[0].points.length<2}function Nh({strokeWidth:t,forceSolid:e,shape:n,opacity:r}){var f;const s=zr(),o=Nl(n.props.segments);let i=t;!e&&!n.props.isPen&&o.length===1&&(i+=cs(n.id)()*(i/6));const a=L1({strokeWidth:i,showAsComplete:n.props.isComplete||((f=Ht(n.props.segments))==null?void 0:f.type)==="straight"}),l=Bs(o,a),c=l.length>1?va(l,!1):oue(n.props.segments[0].points[0]),u=sue(),h=s[n.props.color].highlight[u];return d.jsx("path",{d:c,strokeLinecap:"round",fill:"none",pointerEvents:"all",stroke:h,strokeWidth:i,opacity:r})}function _S(t,e){return U("forceSolid",()=>{const n=Wi(e),r=t.getZoomLevel();return n/r<1.5},[t])}function x5(){return d.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 30 30",xmlns:"http://www.w3.org/2000/svg",fill:"none",stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",children:[d.jsx("path",{d:"M3,11 L3,3 11,3",strokeWidth:"2"}),d.jsx("path",{d:"M19,27 L27,27 L27,19",strokeWidth:"2"}),d.jsx("path",{d:"M27,3 L3,27",strokeWidth:"2"})]})}function w5({shapeId:t,assetId:e}){const n=z(),r=!!md(),s=MQ(),o=w.useMemo(()=>vg(ZE,500),[]),[i,a]=w.useState(()=>({asset:e?n.getAsset(e)??null:null,url:null})),l=w.useRef(!1),c=w.useRef(null);return w.useEffect(()=>{if(!e)return;let u=!1,h;const f=As("update state",()=>{if(!r&&n.getCulledShapes().has(t))return;const p=n.getAsset(e);if(!p)return;const g=n.getShape(t);if(!g)return;if(!p.props.src){const y=n.getTemporaryAssetPreview(p.id);if(y){c.current!==y&&(c.current=y,a(S=>({...S,isPlaceholder:!0,url:y})),s());return}}const m=n.getZoomLevel()*(g.props.w/p.props.w);function v(y,S){u||c.current!==S&&(l.current=!0,c.current=S,a({asset:y,url:S}),s())}l.current?(o(n,e,m,r,y=>v(p,y)),h=o.cancel):ZE(n,e,m,r,y=>v(p,y))});return()=>{f(),h==null||h(),u=!0}},[n,e,r,s,t,o]),i}function ZE(t,e,n,r,s){t.resolveAssetUrl(e,{screenScale:n,shouldResolveToOriginal:r}).then(o=>{s(o)})}async function aue(t){const n=await(await Rs(t)).blob();return Zr.blobToDataUrl(n)}class kf extends oc{isAspectRatioLocked(){return!0}canCrop(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,playing:!0,url:"",crop:null,flipX:!1,flipY:!1}}onResize(e,n){let r=qg(e,n);const{flipX:s,flipY:o}=n.initialShape.props,{scaleX:i,scaleY:a,mode:l}=n;if(r={...r,props:{...r.props,flipX:i<0!==s,flipY:a<0!==o}},!e.props.crop)return r;const c=l==="scale_shape"&&i===-1||l==="resize_bounds"&&s!==r.props.flipX,u=l==="scale_shape"&&a===-1||l==="resize_bounds"&&o!==r.props.flipY,{topLeft:h,bottomRight:f}=e.props.crop;return r.props.crop={topLeft:{x:c?1-f.x:h.x,y:u?1-f.y:h.y},bottomRight:{x:c?1-h.x:f.x,y:u?1-h.y:f.y}},r}component(e){return d.jsx(lue,{shape:e})}indicator(e){return this.editor.getCroppingShapeId()===e.id?null:d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){if(!e.props.assetId||!this.editor.getAsset(e.props.assetId))return null;let r=await this.editor.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});return r?((r.startsWith("blob:")||r.startsWith("http")||r.startsWith("/")||r.startsWith("./"))&&(r=await aue(r)||""),d.jsx(uue,{shape:e,src:r})):null}onDoubleClickEdge(e){const n=e.props;if(!n||this.editor.getCroppingShapeId()!==e.id)return;const r=nt(n.crop)||{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},s=1/(r.bottomRight.x-r.topLeft.x)*e.props.w,o=1/(r.bottomRight.y-r.topLeft.y)*e.props.h,i=new x(r.topLeft.x*s,r.topLeft.y*o).rot(e.rotation),a={id:e.id,type:e.type,x:e.x-i.x,y:e.y-i.y,props:{crop:{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}},w:s,h:o}};this.editor.updateShapes([a])}getInterpolatedProps(e,n,r){function s(o,i){var h,f,p,g;if(o.props.crop===null&&i.props.crop===null)return null;const a=((h=o.props.crop)==null?void 0:h.topLeft)||{x:0,y:0},l=((f=o.props.crop)==null?void 0:f.bottomRight)||{x:1,y:1},c=((p=i.props.crop)==null?void 0:p.topLeft)||{x:0,y:0},u=((g=i.props.crop)==null?void 0:g.bottomRight)||{x:1,y:1};return{topLeft:{x:_e(a.x,c.x,r),y:_e(a.y,c.y,r)},bottomRight:{x:_e(l.x,u.x,r),y:_e(l.y,u.y,r)}}}return{...r>.5?n.props:e.props,w:_e(e.props.w,n.props.w,r),h:_e(e.props.h,n.props.h,r),crop:s(e,n)}}}I(kf,"type","image"),I(kf,"props",YA),I(kf,"migrations",XA);const lue=w.memo(function({shape:e}){var y;const n=z(),{asset:r,url:s}=w5({shapeId:e.id,assetId:e.props.assetId}),o=QR(),[i,a]=w.useState(""),[l,c]=w.useState(null),u=cue(n,e);w.useEffect(()=>{if(s&&u){let S=!1;const b=Lu();return b.onload=()=>{if(S)return;const P=document.createElement("canvas");P.width=b.width,P.height=b.height;const C=P.getContext("2d");C&&(C.drawImage(b,0,0),a(P.toDataURL()),c(s))},b.crossOrigin="anonymous",b.src=s,()=>{S=!0}}},[n,u,o,s]);const h=U("show crop preview",()=>e.id===n.getOnlySelectedShapeId()&&n.getCroppingShapeId()===e.id&&n.isIn("select.crop"),[n,e.id]),f=o&&(((y=r==null?void 0:r.props.mimeType)==null?void 0:y.includes("video"))||u),p=b5(e),g=s===l?null:s,m=f?i:l;if(!s&&!(r!=null&&r.props.src))return d.jsxs(hi,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h,color:"var(--color-text-3)",backgroundColor:"var(--color-low)",border:"1px solid var(--color-low-border)"},children:[d.jsx("div",{className:ce("tl-image-container",r&&"tl-image-container-loading"),style:p,children:r?null:d.jsx(x5,{})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]});const v=u?"anonymous":void 0;return d.jsxs(d.Fragment,{children:[h&&m&&d.jsx("div",{style:p,children:d.jsx("img",{className:"tl-image",style:{...pu(e),opacity:.1},crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1})}),d.jsxs(hi,{id:e.id,style:{overflow:"hidden",width:e.props.w,height:e.props.h},children:[d.jsxs("div",{className:ce("tl-image-container"),style:p,children:[m&&d.jsx("img",{className:"tl-image",style:pu(e),crossOrigin:v,src:m,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1},m),g&&d.jsx("img",{className:"tl-image",style:pu(e),crossOrigin:v,src:g,referrerPolicy:"strict-origin-when-cross-origin",draggable:!1,onLoad:()=>c(g)},g)]}),e.props.url&&d.jsx(Fl,{url:e.props.url})]})]})});function cue(t,e){const n=e.props.assetId?t.getAsset(e.props.assetId):void 0;return n?"mimeType"in n.props&&ar.isAnimatedImageType(n==null?void 0:n.props.mimeType)||"isAnimated"in n.props&&n.props.isAnimated:!1}function b5(t){const e=t.props.crop,n=e==null?void 0:e.topLeft;if(!n)return{width:t.props.w,height:t.props.h};const r=1/(e.bottomRight.x-e.topLeft.x)*t.props.w,s=1/(e.bottomRight.y-e.topLeft.y)*t.props.h,o=-n.x*r,i=-n.y*s;return{transform:`translate(${o}px, ${i}px)`,width:r,height:s}}function pu(t,e){const{flipX:n,flipY:r}=t.props;if(!n&&!r)return;const s=`scale(${n?-1:1}, ${r?-1:1})`;return{transform:`${e?`translate(${n?e.width:0}px, ${r?e.height:0}px)`:""} ${s}`,transformOrigin:e?"0 0":"center center"}}function uue({shape:t,src:e}){const n=Jl(),r=b5(t),s=t.props.crop;if(r.transform&&s){const{transform:o,width:i,height:a}=r,l=(s.bottomRight.x-s.topLeft.x)*i,c=(s.bottomRight.y-s.topLeft.y)*a,u=[new x(0,0),new x(l,0),new x(l,c),new x(0,c)],h=pu(t,{width:i,height:a});return d.jsxs(d.Fragment,{children:[d.jsx("defs",{children:d.jsx("clipPath",{id:n,children:d.jsx("polygon",{points:u.map(f=>`${f.x},${f.y}`).join(" ")})})}),d.jsx("g",{clipPath:`url(#${n})`,children:d.jsx("image",{href:e,width:i,height:a,style:h?{...h,transform:`${o} ${h.transform}`}:{transform:o}})})]})}else return d.jsx("image",{href:e,width:t.props.w,height:t.props.h,style:pu(t,{width:t.props.w,height:t.props.h})})}function P5(t){return{size:t,thinning:.4,streamline:0,smoothing:.5,simulatePressure:!0,last:!0}}function C5(t,e,n){const r=e.vertices,s=P5(n);return Bs(r,s)}function due(t,e,n){const r=P5(n);return k1(xm(C5(t,e,n),r),r)}function hue(t,e,n){const r=due(t,e,n);return Sb(r)}function fue(t,e,n){if(t.props.dash==="draw"){const r=C5(t,e,n);return va(r)}return e.getSvgPathData()}function _5(t,e,n){let r=`M ${je(e[0])}L`,s=`M ${je(e[0])}L`;const o=n/3,i=n*2,a=cs(t);let l=e[0],c,u=e[0],h;const f=e.length;for(let p=0,g=f-1;p<g;p++){c=e[p+1],h=x.AddXY(e[p+1],a()*o,a()*o);const m=x.Sub(c,l),v=x.Len(m),y=x.Div(m,v).mul(Math.min(v/4,i)),S=x.Add(l,y),b=x.Add(c,y.neg()),P=x.Sub(h,u),C=x.Len(P),_=x.Div(P,C).mul(Math.min(C/4,i)),E=x.Add(u,_),k=x.Add(h,_.neg());p===g-1?(r+=`${je(S)}L ${je(c)}`,s+=`${je(E)}L ${je(h)}`):(r+=`${je(S)}L ${je(b)}Q ${je(c)}`,s+=`${je(E)}L ${je(k)}Q ${je(h)}`,l=c,u=h)}return[r,r+s]}const pue=new Ds;class Tf extends ss{hideResizeHandles(){return!0}hideRotateHandle(){return!0}hideSelectionBoundsFg(){return!0}hideSelectionBoundsBg(){return!0}getDefaultProps(){const[e,n]=Fu(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[e]:{id:e,index:e,x:0,y:0},[n]:{id:n,index:n,x:.1,y:.1}},scale:1}}getGeometry(e){return qc(e)}getHandles(e){return pue.get(e.props,()=>{const n=qc(e),r=Xc(e),s=r.map(o=>({...o,id:o.index,type:"vertex",canSnap:!0}));for(let o=0;o<r.length-1;o++){const i=$u(r[o].index,r[o+1].index),l=n.segments[o].midPoint();s.push({id:i,type:"create",index:i,x:l.x,y:l.y,canSnap:!0})}return s.sort(cn)})}onResize(e,n){const{scaleX:r,scaleY:s}=n;return{props:{points:sd(e.props.points,(o,{id:i,index:a,x:l,y:c})=>({id:i,index:a,x:l*r,y:c*s}))}}}onBeforeCreate(e){const{props:{points:n}}=e,r=Object.keys(n);if(r.length<2)return;const s=n[r[0]];if(r.every(i=>{const a=n[i];return a.x===s.x&&a.y===s.y})){const i=r[r.length-1];return n[i]={...n[i],x:n[i].x+.1,y:n[i].y+.1},e}}onHandleDrag(e,{handle:n}){if(n.type!=="vertex")return;const r=is(new x(n.x,n.y),this.editor);return{...e,props:{...e.props,points:{...e.props.points,[n.id]:{id:n.id,index:n.index,x:r.x,y:r.y}}}}}component(e){return d.jsx(mi,{children:d.jsx(QE,{shape:e})})}indicator(e){const n=ks[e.props.size]*e.props.scale,r=qc(e),{dash:s}=e.props;let o;if(e.props.spline==="line"){const i=r.points;if(s==="solid"||s==="dotted"||s==="dashed")o="M"+i[0]+"L"+i.slice(1);else{const[a]=_5(e.id,i,n);o=a}}else o=fue(e,r,n);return d.jsx("path",{d:o})}toSvg(e){return d.jsx(QE,{shouldScale:!0,shape:e})}getHandleSnapGeometry(e){const n=Xc(e);return{points:n,getSelfSnapPoints:r=>{const s=this.getHandles(e).filter(o=>o.type==="vertex").findIndex(o=>o.id===r.id);return n.filter((o,i)=>Math.abs(i-s)>1).map(x.From)},getSelfSnapOutline:r=>{const s=this.getHandles(e).filter(i=>i.type==="vertex").findIndex(i=>i.id===r.id),o=qc(e).segments.filter((i,a)=>a!==s-1&&a!==s);return o.length?new $r({children:o}):null}}}getInterpolatedProps(e,n,r){const s=Xc(e),o=Xc(n),i=[],a=[];let l=QT;if(s.length>o.length)for(let c=0;c<s.length;c++)i[c]={...s[c]},o[c]===void 0?a[c]={...o[o.length-1],id:l}:a[c]={...o[c],id:l},l=_s(l);else if(o.length>s.length)for(let c=0;c<o.length;c++)a[c]={...o[c]},s[c]===void 0?i[c]={...s[s.length-1],id:l}:i[c]={...s[c],id:l},l=_s(l);else for(let c=0;c<o.length;c++)i[c]=s[c],a[c]=o[c];return{...r>.5?n.props:e.props,points:Object.fromEntries(i.map((c,u)=>{const h=a[u];return[c.id,{...c,x:_e(c.x,h.x,r),y:_e(c.y,h.y,r)}]})),scale:_e(e.props.scale,n.props.scale,r)}}}I(Tf,"type","line"),I(Tf,"props",qA),I(Tf,"migrations",ZA);function Xc(t){return Object.values(t.props.points).sort(cn)}function qc(t){const e=Xc(t).map(x.From);switch(t.props.spline){case"cubic":return new gte({points:e});case"line":return new nc({points:e})}}function QE({shape:t,shouldScale:e=!1,forceSolid:n=!1}){const r=zr(),s=qc(t),{dash:o,color:i,size:a}=t.props,l=1/t.props.scale,c=e?l:1,u=ks[a]*t.props.scale;if(t.props.spline==="line"){if(o==="solid"){const h=s.points,f="M"+h[0]+"L"+h.slice(1);return d.jsx("path",{d:f,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:s.segments.map((h,f)=>{const{strokeDasharray:p,strokeDashoffset:g}=n?{strokeDasharray:"none",strokeDashoffset:"none"}:qr(h.length,u,{style:o,start:f>0?"outset":"none",end:f<s.segments.length-1?"outset":"none"});return d.jsx("path",{strokeDasharray:p,strokeDashoffset:g,d:h.getSvgPathData(!0),fill:"none"},f)})});if(o==="draw"){const h=s.points,[f,p]=_5(t.id,h,u);return d.jsx("path",{d:p,stroke:r[i].solid,strokeWidth:u,fill:"none",transform:`scale(${c})`})}}if(t.props.spline==="cubic"){const h=s.getSvgPathData();if(o==="solid")return d.jsx("path",{strokeWidth:u,stroke:r[i].solid,fill:"none",d:h,transform:`scale(${c})`});if(o==="dashed"||o==="dotted")return d.jsx("g",{stroke:r[i].solid,strokeWidth:u,transform:`scale(${c})`,children:s.segments.map((f,p)=>{const{strokeDasharray:g,strokeDashoffset:m}=qr(f.length,u,{style:o,start:p>0?"outset":"none",end:p<s.segments.length-1?"outset":"none",forceSolid:n});return d.jsx("path",{strokeDasharray:g,strokeDashoffset:m,d:f.getSvgPathData(),fill:"none"},p)})});if(o==="draw")return d.jsx("path",{d:hue(t,s,u),strokeWidth:1,stroke:r[i].solid,fill:r[i].solid,transform:`scale(${c})`})}}class Mf extends ss{canEdit(){return!0}hideResizeHandles(){return!0}hideSelectionBoundsFg(){return!1}getDefaultProps(){return{color:"black",size:"m",text:"",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:0,url:"",scale:1}}getGeometry(e){const{labelHeight:n,labelWidth:r}=I5(this.editor,e),{scale:s}=e.props,o=n*s,i=r*s,a=He*s,l=zh(e);return new $r({children:[new Fs({width:a,height:l,isFilled:!0}),new Fs({x:e.props.align==="start"?0:e.props.align==="end"?a-i:(a-i)/2,y:e.props.verticalAlign==="start"?0:e.props.verticalAlign==="end"?l-o:(l-o)/2,width:i,height:o,isFilled:!0,isLabel:!0})]})}getHandles(e){const{scale:n}=e.props;if(this.editor.getInstanceState().isCoarsePointer)return[];const s=this.editor.getZoomLevel();if(s*n<.25)return[];const o=zh(e),i=He*n,a=Ole/s*n;return s*n<.5?[{id:"bottom",index:"a3",type:"clone",x:i/2,y:o+a}]:[{id:"top",index:"a1",type:"clone",x:i/2,y:-a},{id:"right",index:"a2",type:"clone",x:i+a,y:o/2},{id:"bottom",index:"a3",type:"clone",x:i/2,y:o+a},{id:"left",index:"a4",type:"clone",x:-a,y:o/2}]}getText(e){return e.props.text}component(e){const{id:n,type:r,props:{labelColor:s,scale:o,color:i,font:a,size:l,align:c,text:u,verticalAlign:h,fontSizeAdjustment:f}}=e,p=yue(n),g=zr(),m=He*o,v=zh(e),y=U("shape rotation",()=>{var C;return((C=this.editor.getShapePageTransform(n))==null?void 0:C.rotation())??0},[this.editor]),S=U("zoom",()=>this.editor.getZoomLevel()<.35/o,[o,this.editor]),b=U("dark mode",()=>this.editor.user.getIsDarkMode(),[this.editor]),P=e.id===this.editor.getOnlySelectedShapeId();return d.jsxs(d.Fragment,{children:[d.jsx("div",{id:n,className:"tl-note__container",style:{width:m,height:v,backgroundColor:g[i].note.fill,borderBottom:S?b?`${2*o}px solid rgb(20, 20, 20)`:`${2*o}px solid rgb(144, 144, 144)`:"none",boxShadow:S?"none":Sue(e.id,y,o)},children:d.jsx(Cm,{shapeId:n,type:r,font:a,fontSize:(f||yo[l])*o,lineHeight:pn.lineHeight,align:c,verticalAlign:h,text:u,isNote:!0,isSelected:P,labelColor:s==="black"?g[i].note.text:g[s].fill,wrap:!0,padding:16*o,onKeyDown:p})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]})}indicator(e){const{scale:n}=e.props;return d.jsx("rect",{rx:n,width:N(He*n),height:N(zh(e))})}toSvg(e,n){e.props.text&&n.addExportDef(bm(e.props.font));const r=ko({isDarkMode:n.isDarkMode}),s=vue(e);return d.jsxs(d.Fragment,{children:[d.jsx("rect",{x:5,y:5,rx:1,width:He-10,height:s.h,fill:"rgba(0,0,0,.1)"}),d.jsx("rect",{rx:1,width:He,height:s.h,fill:r[e.props.color].note.fill}),d.jsx(Pm,{fontSize:e.props.fontSizeAdjustment||yo[e.props.size],font:e.props.font,align:e.props.align,verticalAlign:e.props.verticalAlign,text:e.props.text,labelColor:r[e.props.color].note.text,bounds:s,stroke:!1})]})}onBeforeCreate(e){return JE(this.editor,e)}onBeforeUpdate(e,n){if(!(e.props.text===n.props.text&&e.props.font===n.props.font&&e.props.size===n.props.size))return JE(this.editor,n)}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e;s.trimEnd()!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.trimEnd()}}])}getInterpolatedProps(e,n,r){return{...r>.5?n.props:e.props,scale:_e(e.props.scale,n.props.scale,r)}}}I(Mf,"type","note"),I(Mf,"props",QA),I(Mf,"migrations",JA);function JE(t,e){const{labelHeight:n,fontSizeAdjustment:r}=I5(t,e),s=Math.max(0,n-He);if(s!==e.props.growY||r!==e.props.fontSizeAdjustment)return{...e,props:{...e.props,growY:s,fontSizeAdjustment:r}}}function gue(t,e){const{text:n}=e.props;if(!n)return{labelHeight:yo[e.props.size]*pn.lineHeight+Er*2,labelWidth:100,fontSizeAdjustment:0};const r=yo[e.props.size];let s=0,o=0,i=He,a=He;const l=1;do{s=Math.min(r,r-o);const c=t.textMeasure.measureText(n,{...pn,fontFamily:Co[e.props.font],fontSize:s,maxWidth:He-Er*2-l,disableOverflowWrapBreaking:!0});if(i=c.h+Er*2,a=c.w+Er*2,s<=14){const u=t.textMeasure.measureText(n,{...pn,fontFamily:Co[e.props.font],fontSize:s,maxWidth:He-Er*2-l});i=u.h+Er*2,a=u.w+Er*2;break}if(c.scrollWidth.toFixed(0)===c.w.toFixed(0))break}while(o++<50);return{labelHeight:i,labelWidth:a,fontSizeAdjustment:s}}const mue=new Ds;function I5(t,e){return mue.get(e,()=>gue(t,e))}function yue(t){const e=z(),n=t$();return w.useCallback(r=>{const s=e.getShape(t);if(!s)return;const o=r.key==="Tab",i=(r.metaKey||r.ctrlKey)&&r.key==="Enter";if(o||i){r.preventDefault();const a=e.getShapePageTransform(t),l=a.rotation(),c=!!(n.dir==="rtl"||q$(s.props.text)),u=(He+e.options.adjacentShapeMargin+(i&&!r.shiftKey?s.props.growY:0))*s.props.scale,h=new x(o?r.shiftKey!=c?-1:1:0,i?r.shiftKey?-1:1:0).mul(u).add(wm.clone().mul(s.props.scale)).rot(l).add(a.point()),f=r5(e,s,h,l);f&&(e.markHistoryStoppingPoint("editing adjacent shape"),Wp(e,f,!0))}},[t,e,n.dir])}function zh(t){return(He+t.props.growY)*t.props.scale}function Sue(t,e,n){const r=cs(t),s=Math.abs(r())+.5,o=Math.cos(e),i=5*n,a=4*n,l=6*n,c=7*n;return`0px ${i-s}px ${i}px -${i}px rgba(15, 23, 31, .6),
|
|
382
382
|
0px ${(a+s*c)*Math.max(0,o)}px ${l+s*c}px -${a+s*l}px rgba(15, 23, 31, ${(.3+s*.1).toFixed(2)}),
|
|
383
|
-
0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+o)/2)).toFixed(2)})`}function vue(t){return new Z(0,0,He,He+t.props.growY)}function xue(t,{initialBounds:e,scaleX:n,scaleY:r,newPoint:s}){const o=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new x(0,0);n<0&&(i.x=-(e.width*o)),r<0&&(i.y=-(e.height*o));const{x:a,y:l}=x.Add(s,i.rot(t.rotation));return{x:a,y:l,props:{scale:o*t.props.scale}}}const wue=new Ds;class Af extends ss{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return wue.get(e.props,n=>e2(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:s}=this.getMinDimensions(e);return new Fs({width:r*n,height:s*n,isFilled:!0,isLabel:!0})}getText(e){return e.props.text}canEdit(){return!0}isAspectRatioLocked(){return!0}component(e){const{id:n,props:{font:r,size:s,text:o,color:i,scale:a,textAlign:l}}=e,{width:c,height:u}=this.getMinDimensions(e),h=e.id===this.editor.getOnlySelectedShapeId(),f=zr(),p=bue(n);return d.jsx(Cm,{shapeId:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Ll[s],lineHeight:pn.lineHeight,align:l,verticalAlign:"middle",text:o,labelColor:f[i].solid,isSelected:h,textWidth:c,textHeight:u,style:{transform:`scale(${a})`,transformOrigin:"top left"},wrap:!0,onKeyDown:p})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds,r=z();return e.props.autoSize&&r.getEditingShapeId()===e.id?null:d.jsx("rect",{width:N(n.width),height:N(n.height)})}toSvg(e,n){e.props.text&&n.addExportDef(bm(e.props.font));const r=this.editor.getShapeGeometry(e).bounds,s=r.width/(e.props.scale??1),o=r.height/(e.props.scale??1),i=ko(n);return d.jsx(Pm,{fontSize:Ll[e.props.size],font:e.props.font,align:e.props.textAlign,verticalAlign:"middle",text:e.props.text,labelColor:i[e.props.color].solid,bounds:new Z(0,0,s,o),padding:0})}onResize(e,n){const{newPoint:r,initialBounds:s,initialShape:o,scaleX:i,handle:a}=n;if(n.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:e.id,type:e.type,...xue(e,n)};{const l=Math.max(1,Math.abs(s.width*i)),{x:c,y:u}=i<0?x.Sub(r,x.FromAngle(e.rotation).mul(l)):r;return{id:e.id,type:e.type,x:c,y:u,props:{w:l/o.props.scale,autoSize:!1}}}}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e,o=e.props.text.trimEnd();o.length===0?this.editor.deleteShapes([e.id]):o!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.trimEnd()}}])}onBeforeUpdate(e,n){if(!n.props.autoSize)return;const r=e.props.size!==n.props.size||e.props.textAlign!==n.props.textAlign||e.props.font!==n.props.font||e.props.scale!==1&&n.props.scale===1,s=e.props.text!==n.props.text;if(!r&&!s)return;const o=this.getMinDimensions(e),i=e2(this.editor,n.props),a=o.width*e.props.scale,l=o.height*e.props.scale,c=i.width*n.props.scale,u=i.height*n.props.scale;let h;switch(n.props.textAlign){case"middle":{h=new x((c-a)/2,s?0:(u-l)/2);break}case"end":{h=new x(c-a,s?0:(u-l)/2);break}default:{if(s)break;h=new x(0,(u-l)/2);break}}if(h){h.rot(n.rotation);const{x:f,y:p}=n;return{...n,x:f-h.x,y:p-h.y,props:{...n.props,w:c}}}else return{...n,props:{...n.props,w:c}}}}I(Af,"type","text"),I(Af,"props",ej),I(Af,"migrations",tj);function e2(t,e){const{font:n,text:r,autoSize:s,size:o,w:i}=e,a=s?16:Math.max(16,i),l=Ll[o],c=s?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...pn,fontFamily:Co[n],fontSize:l,maxWidth:c});return s&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function bue(t){const e=z();return w.useCallback(n=>{if(e.getEditingShapeId()===t)switch(n.key){case"Enter":{(n.ctrlKey||n.metaKey)&&e.complete();break}case"Tab":{xe(n),n.shiftKey?$l.unindent(n.currentTarget):$l.indent(n.currentTarget);break}}},[e,t])}class jf extends oc{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return d.jsx(Pue,{shape:e})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){const n=await Cue(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}I(jf,"type","video"),I(jf,"props",nj),I(jf,"migrations",rj);const Pue=w.memo(function({shape:e}){const n=z(),r=n.getShapeGeometry(e).bounds.w*n.getZoomLevel()>=110,s=Zg(e.id),o=QR(),{Spinner:i}=st(),{asset:a,url:l}=w5({shapeId:e.id,assetId:e.props.assetId}),c=w.useRef(null),[u,h]=w.useState(!1),[f,p]=w.useState(!1);w.useEffect(()=>{const m=()=>p(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",m),()=>document.removeEventListener("fullscreenchange",m)});const g=w.useCallback(m=>{m.currentTarget&&h(!0)},[]);return w.useEffect(()=>{const m=c.current;m&&s&&document.activeElement!==m&&m.focus()},[s,u]),w.useEffect(()=>{if(o){const m=c.current;if(!m)return;m.pause(),m.currentTime=0}},[c,o]),d.jsxs(d.Fragment,{children:[d.jsx(hi,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:a?i&&!a.props.src?d.jsx(i,{}):l?d.jsxs(d.Fragment,{children:[d.jsx("video",{ref:c,style:s?{pointerEvents:"all"}:u?void 0:{display:"none"},className:ce("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":f}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:s&&r,onLoadedData:g,hidden:!u,children:d.jsx("source",{src:l})}),!u&&i&&d.jsx(i,{})]}):null:d.jsx(x5,{})})})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]})});async function Cue(t,e){const n=await t.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!n)return null;const r=await ar.loadVideo(n);return ar.getVideoFrameAsDataUrl(r,0)}const E5=[Af,Pf,Cf,If,Mf,Tf,_f,bf,Ef,Jp,kf,jf];function _ue(t){return t.sideEffects.register({instance_page_state:{afterChange:(e,n)=>{if(e.croppingShapeId!==n.croppingShapeId){const r=t.isIn("select.crop");!e.croppingShapeId&&n.croppingShapeId?r||t.setCurrentTool("select.crop.idle"):e.croppingShapeId&&!n.croppingShapeId&&r&&t.setCurrentTool("select.idle")}if(e.editingShapeId!==n.editingShapeId)if(!e.editingShapeId&&n.editingShapeId){if(!t.isIn("select.editing_shape")){const r=t.getEditingShape();r&&r.type==="text"&&t.isInAny("text.pointing","select.resizing")&&t.getInstanceState().isToolLocked?t.setCurrentTool("select.editing_shape",{isCreatingTextWhileToolLocked:!0}):t.setCurrentTool("select.editing_shape")}}else e.editingShapeId&&!n.editingShapeId&&t.isIn("select.editing_shape")&&t.setCurrentTool("select.idle")}}})}class k5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"scribbleId","id");I(this,"markId","");I(this,"excludedShapeIds",new Set)}onEnter(n){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(o=>{if(this.editor.isShapeOrAncestorLocked(o))return!0;if(this.editor.isShapeOfType(o,"group")||this.editor.isShapeOfType(o,"frame")){const i=this.editor.getPointInShapeSpace(o,r);return this.editor.getShapeGeometry(o).bounds.containsPoint(i)}return!1}).map(o=>o.id));const s=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=s.id,this.update()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onExit(){this.editor.setErasingShapes([]),this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}update(){const{editor:n,excludedShapeIds:r}=this,s=n.getErasingShapeIds(),o=n.getZoomLevel(),i=n.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(s),u=this.editor.options.hitTestMargin/o;for(const h of i){if(n.isShapeOfType(h,"group"))continue;const f=n.getShapeMask(h.id);if(f&&!hr(a,f))continue;const p=n.getShapeGeometry(h),g=n.getShapePageTransform(h);if(!p||!g)continue;const m=g.clone().invert(),v=m.applyToPoint(l),y=m.applyToPoint(a),{bounds:S}=p;S.minX-u>Math.max(v.x,y.x)||S.minY-u>Math.max(v.y,y.y)||S.maxX+u<Math.min(v.x,y.x)||S.maxY+u<Math.min(v.y,y.y)||p.hitTestLineSegment(v,y,u)&&c.add(n.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}I(k5,"id","erasing");var WS;let Iue=(WS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(WS,"id","idle"),WS);var GS;let Eue=(GS=class extends ie{onEnter(){const e=this.editor.getZoomLevel(),n=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,s=new Set,o=s.size;for(let i=n.length,a=i-1;a>=0;a--){const l=n[a];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,r,{hitInside:!1,margin:this.editor.options.hitTestMargin/e})){const c=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(c,"frame")&&s.size>o)break;s.add(c.id)}}this.editor.setErasingShapes([...s])}onLongPress(e){this.startErasing(e)}onExit(e,n){n!=="erasing"&&this.editor.setErasingShapes([])}onPointerMove(e){this.editor.inputs.isDragging&&this.startErasing(e)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(e){this.parent.transition("erasing",e)}complete(){const e=this.editor.getErasingShapeIds();e.length&&(this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(e)),this.parent.transition("idle")}cancel(){this.parent.transition("idle")}},I(GS,"id","pointing"),GS);class Of extends ie{static children(){return[Iue,Eue,k5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Of,"id","eraser"),I(Of,"initial","idle"),I(Of,"isLockable",!1);class T5 extends ie{constructor(){super(...arguments);I(this,"initialCamera",new x)}onEnter(){this.initialCamera=x.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:s,originScreenPoint:o}=r.inputs,i=x.Sub(s,o).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,s=Math.min(r.len(),2);s>.1&&this.editor.slideCamera({speed:s,direction:r}),this.parent.transition("idle")}}I(T5,"id","dragging");var VS;let kue=(VS=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(VS,"id","idle"),VS);var YS;let Tue=(YS=class extends ie{onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){this.editor.inputs.isDragging&&this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}},I(YS,"id","pointing"),YS);class Df extends ie{static children(){return[kue,Tue,T5]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomIn(n,{animation:{duration:220,easing:Dt.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomOut(n,{animation:{duration:320,easing:Dt.easeOutQuint}})}}onQuadrupleClick(e){if(e.phase==="settle"){const n=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:r}}=this.editor;n===1?this.editor.zoomToFit({animation:{duration:400,easing:Dt.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:Dt.easeOutQuint}})}}}I(Df,"id","hand"),I(Df,"initial","idle"),I(Df,"isLockable",!1);var XS;let Mue=(XS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},I(XS,"id","idle"),XS);class M5 extends ie{constructor(){super(...arguments);I(this,"scribbleId","id")}onEnter(){const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:this.editor.options.laserDelayMs,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.pushPointToScribble()}onPointerUp(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onCancel(){this.cancel()}onComplete(){this.complete()}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}I(M5,"id","lasering");class Rf extends ie{static children(){return[Mue,M5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Rf,"id","laser"),I(Rf,"initial","idle"),I(Rf,"isLockable",!1);class A5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"initialSelectedShapeIds",[]);I(this,"excludedShapeIds",new Set);I(this,"isWrapMode",!1);I(this,"initialStartShape",null)}onEnter(n){const{altKey:r,currentPagePoint:s}=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(o=>this.editor.isShapeOfType(o,"group")||this.editor.isShapeOrAncestorLocked(o)).map(o=>o.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(s)[0],this.hitTestShapes()}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(n){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",n)}onKeyDown(n){this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:s}=this,{inputs:{originPagePoint:o,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=s?!l:l,h=Z.FromPoints([o,i]),{corners:f}=h;let p,g,m,v,y,S;const b=n.getCurrentPageRenderingShapesSorted(),P=n.getCurrentPageId();e:for(let E=0,k=b.length;E<k;E++){if(m=b[E],r.has(m.id)||c.has(m.id)||(v=n.getShapePageBounds(m),!v))continue e;if(h.contains(v)){this.handleHit(m,i,P,c,f);continue e}if(u||n.isShapeOfType(m,"frame"))continue e;if(h.collides(v)){if(y=n.getShapePageTransform(m),!y)continue e;S=y.clone().invert().applyToPoints(f);const D=n.getShapeGeometry(m);t:for(let T=0;T<4;T++)if(p=S[T],g=S[(T+1)%4],D.hitTestLineSegment(p,g,0)){this.handleHit(m,i,P,c,f);break t}}}const C=n.getInstanceState().brush;(!C||!h.equals(C))&&n.updateInstanceState({brush:{...h.toJson()}});const _=n.getSelectedShapeIds();(_.length!==c.size||_.some(E=>!c.has(E)))&&n.setSelectedShapes(Array.from(c))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(n,r,s,o,i){if(n.parentId===s){o.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),l=this.editor.getShapeMask(a.id);l&&!_b(l,i)&&!hr(r,l)||o.add(a.id)}}I(A5,"id","brushing");const zl={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 j5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=zl[this.info.handle];this.editor.setCursor({type:r,rotation:n.length===1?this.editor.getSelectionRotation():0})}onEnter(n){this.info=n,this.updateCursor()}onPointerMove(){this.editor.inputs.isDragging&&this.startResizing()}onLongPress(){this.startResizing()}startResizing(){this.editor.getIsReadonly()||this.parent.transition("resizing",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}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")}}I(j5,"id","pointing_resize_handle");const _r=8;class F1 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"snapshot",{})}onEnter(n){this.info=n,this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=zl[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}getDefaultCrop(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}updateShapes(){const{shape:n,cursorHandleOffset:r}=this.snapshot;if(!n||!this.editor.getShapeUtil("image"))return;const o=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=o.crop??this.getDefaultCrop(),u=nt(c),h=new x(n.x,n.y),f=new x(0,0),p=1/(c.bottomRight.x-c.topLeft.x)*o.w,g=1/(c.bottomRight.y-c.topLeft.y)*o.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(g<_r)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/g,g*(u.bottomRight.y-u.topLeft.y)<_r?(u.topLeft.y=u.bottomRight.y-_r/g,f.y=(u.topLeft.y-c.topLeft.y)*g):u.topLeft.y<=0?(u.topLeft.y=0,f.y=(u.topLeft.y-c.topLeft.y)*g):f.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(g<_r)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/g),g*(u.bottomRight.y-u.topLeft.y)<_r&&(u.bottomRight.y=u.topLeft.y+_r/g);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<_r)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/p,p*(u.bottomRight.x-u.topLeft.x)<_r?(u.topLeft.x=u.bottomRight.x-_r/p,f.x=(u.topLeft.x-c.topLeft.x)*p):u.topLeft.x<=0?(u.topLeft.x=0,f.x=(u.topLeft.x-c.topLeft.x)*p):f.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(p<_r)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/p),p*(u.bottomRight.x-u.topLeft.x)<_r&&(u.bottomRight.x=u.topLeft.x+_r/p);break}}if(!m)return;h.add(f.rot(n.rotation));const v={id:n.id,type:n.type,x:h.x,y:h.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*p,h:(u.bottomRight.y-u.topLeft.y)*g}};this.editor.updateShapes([v]),this.updateCursor()}complete(){this.updateShapes(),Xe(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const n=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,s=this.editor.getOnlySelectedShape(),o=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(o.getHandlePoint(this.info.handle),o.point,n),a=x.Sub(r,i);return{shape:s,cursorHandleOffset:a}}}I(F1,"id","cropping");function O5(t,e=!1){const n=t.getZoomLevel(),{inputs:{currentPagePoint:r}}=t;return t.getShapeAtPoint(r,{hitInside:!1,hitLabels:e,margin:t.options.hitTestMargin/n,renderingOnly:!0})??t.getSelectedShapeAtPoint(r)}function D5(t,e,n){if(!e)throw Error("Needs to translate a cropped shape!");const{crop:r}=e.props;if(!r)return;const s=t.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;s==="x"?n.x=0:s==="y"&&(n.y=0),n.rot(-e.rotation);const o=1/(r.bottomRight.x-r.topLeft.x)*e.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*e.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=nt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-n.x/o)),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:e.id,type:e.type,props:{crop:c}}}var qS;let Aue=(qS=class extends ie{onEnter(){this.editor.setCursor({type:"default",rotation:0});const e=this.editor.getOnlySelectedShape();e&&this.editor.setCroppingShape(e.id)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(e){var n;if(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=O5(this.editor);if(r&&!this.editor.isShapeOfType(r,"group")){this.onPointerDown({...e,shape:r,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(e);break}case"shape":{if(e.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",e);return}else(n=this.editor.getShapeUtil(e.shape))!=null&&n.canCrop(e.shape)?(this.editor.setCroppingShape(e.shape.id),this.editor.setSelectedShapes([e.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",e)):(this.cancel(),this.editor.root.handleEvent(e));break}case"selection":{switch(e.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",{...e,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...e,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}onDoubleClick(e){var o;if(this.editor.inputs.shiftKey||e.phase!=="up")return;const n=this.editor.getCroppingShapeId();if(!n)return;const r=this.editor.getShape(n);if(!r)return;const s=this.editor.getShapeUtil(r);if(s){if(e.target==="selection"){(o=s.onDoubleClickEdge)==null||o.call(s,r);return}this.cancel(),this.editor.root.handleEvent(e)}}onKeyDown(){this.nudgeCroppingImage(!1)}onKeyRepeat(){this.nudgeCroppingImage(!0)}onKeyUp(e){switch(e.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(e=!1){const{editor:{inputs:{keys:n}}}=this,r=n.has("ShiftLeft"),s=new x(0,0);if(n.has("ArrowLeft")&&(s.x+=1),n.has("ArrowRight")&&(s.x-=1),n.has("ArrowUp")&&(s.y+=1),n.has("ArrowDown")&&(s.y-=1),s.equals(new x(0,0)))return;r&&s.mul(10);const o=this.editor.getShape(this.editor.getCroppingShapeId());if(!o)return;const i=D5(this.editor,o,s);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},I(qS,"id","idle"),qS);class R5 extends ie{onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(e){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",e)}onPointerUp(e){this.editor.setCurrentTool("select.crop.idle",e)}}I(R5,"id","pointing_crop");class N1 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=zl[this.info.handle];this.editor.setCursor({type:s,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){this.editor.inputs.isDragging&&this.startCropping()}onLongPress(){this.startCropping()}startCropping(){this.editor.getIsReadonly()||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}onPointerUp(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}I(N1,"id","pointing_crop_handle");class L5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"snapshot",{})}onEnter(n){this.info=n,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(n){switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}}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:s}=this.editor.inputs,o=s.clone().sub(r),i=D5(this.editor,n,o);i&&this.editor.updateShapes([i])}}I(L5,"id","translating_crop");class dw extends ie{constructor(){super(...arguments);I(this,"markId","");I(this,"didExit",!1)}static children(){return[Aue,L5,R5,N1,F1]}onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}onExit(){this.didExit||(this.didExit=!0,this.editor.squashToMark(this.markId))}onCancel(){this.didExit||(this.didExit=!0,this.editor.bailToMark(this.markId))}}I(dw,"id","crop"),I(dw,"initial","idle");class $5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"initialHandle",{});I(this,"initialAdjacentHandle",null);I(this,"initialPagePoint",{});I(this,"markId","");I(this,"initialPageTransform");I(this,"initialPageRotation");I(this,"info",{});I(this,"isPrecise",!1);I(this,"isPreciseId",null);I(this,"pointingId",null);I(this,"exactTimeout",-1)}onEnter(n){const{shape:r,isCreating:s,creatingMarkId:o,handle:i}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId="",s)if(o)this.markId=o;else{const c=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);c&&(this.markId=c)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");if(this.initialHandle=nt(i),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[i.index]:{id:i.index,index:i.index,x:i.x,y:i.y}}}});const u=this.editor.getShapeHandles(r).find(h=>h.index===i.index);this.initialHandle=nt(u)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:s?"cross":"grabbing",rotation:0});const a=this.editor.getShapeHandles(r).sort(cn),l=a.findIndex(c=>c.id===n.handle.id);this.initialAdjacentHandle=null;for(let c=l+1;c<a.length;c++){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(!this.initialAdjacentHandle)for(let c=a.length-1;c>=0;c--){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=Un(this.editor,r)[n.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),Xe(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 E;const{editor:n,shapeId:r,initialPagePoint:s}=this,{initialHandle:o,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:f,ctrlKey:p,altKey:g,pointerVelocity:m}}=n,v=this.info.shape,y=n.getShape(r);if(!y)return;const S=n.getShapeUtil(y);let b=h.clone().sub(s).rot(-i).add(o);if(f&&a&&o.id!=="middle"){const k=x.Angle(a,b),T=Rp(k,24)-k;b=x.RotWith(b,a,T)}n.snaps.clearIndicators();let P={...o,x:b.x,y:b.y};if(o.canSnap&&(c?!p:p)){if(!n.getShapePageTransform(y.id))throw Error("Expected a page transform");const D=u.handles.snapHandle({currentShapeId:r,handle:P});D&&(D.nudge.rot(-n.getShapeParentTransform(y).rotation()),b.add(D.nudge),P={...o,x:b.x,y:b.y})}const C=(E=S.onHandleDrag)==null?void 0:E.call(S,y,{handle:P,isPrecise:this.isPrecise||g,initial:v}),_={id:y.id,type:y.type,...C};if(o.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const k=Un(n,y)[o.id];k?l[0]!==k.toId&&(n.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=m.len()<.5||g,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([_])}}I($5,"id","dragging_handle");function F5(t){return t.isLabel?[t]:t instanceof $r?t.children.filter(e=>e.isLabel):[]}class N5 extends ie{constructor(){super(...arguments);I(this,"hitShapeForPointerUp",null);I(this,"info",{})}onEnter(n){const r=this.editor.getEditingShape();if(!r)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,this.info=n,n.isCreatingTextWhileToolLocked&&this.parent.setCurrentToolIdMask("text"),uo(this.editor),this.editor.select(r)}onExit(){var o;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),uo.cancel();const r=this.editor.getShape(n),s=this.editor.getShapeUtil(r);(o=s.onEditEnd)==null||o.call(s,r),this.info.isCreatingTextWhileToolLocked&&(this.parent.setCurrentToolIdMask(void 0),this.editor.setCurrentTool("text",{}))}onPointerMove(n){if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getIsReadonly()||this.hitShapeForPointerUp.isLocked)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",n),this.hitShapeForPointerUp=null;return}switch(n.target){case"shape":case"canvas":{uo(this.editor);return}}}onPointerDown(n){switch(this.hitShapeForPointerUp=null,n.target){case"shape":{const{shape:r}=n,s=this.editor.getEditingShape();if(!s)throw Error("Expected an editing shape!");const o=this.editor.getShapeUtil(r).getGeometry(r),i=F5(o),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&s.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===s.id)return;this.hitShapeForPointerUp=r,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===s.id)this.editor.isShapeOfType(r,"frame")&&(this.editor.setEditingShape(null),this.parent.transition("idle",n));else{this.parent.transition("pointing_shape",n);return}return}break}}this.parent.transition("idle",n),this.editor.root.handleEvent(n)}onPointerUp(n){const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const s=this.editor.getShapeUtil(r);if(!r.isLocked){if(this.editor.getIsReadonly()&&!s.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),uo(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}I(N5,"id","editing_shape");function t2(t){const e=t.getOnlySelectedShape();return!!(e&&!t.isShapeOrAncestorLocked(e)&&t.getShapeUtil(e).canCrop(e))}function eg(t,e){const n=t.getSelectedShapeIds(),{currentPagePoint:r}=t.inputs,{shiftKey:s,altKey:o,accelKey:i}=e,a=s||i,l=t.getShapeAtPoint(r,{hitInside:!1,margin:t.options.hitTestMargin/t.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:c=>!c.isLocked});if(l){const c=t.getOutermostSelectableShape(l);if(a&&!o)t.cancelDoubleClick(),n.includes(c.id)?(t.markHistoryStoppingPoint("deselecting shape"),t.deselect(c)):(t.markHistoryStoppingPoint("shift selecting shape"),t.setSelectedShapes([...n,c.id]));else{let u;c===l||c.id===t.getFocusedGroupId()||n.includes(c.id)?u=l:u=c,u&&!n.includes(u.id)&&(t.markHistoryStoppingPoint("selecting shape"),t.select(u.id))}}else{if(a)return;{n.length>0&&(t.markHistoryStoppingPoint("selecting none"),t.selectNone());const c=t.getFocusedGroupId();if(Fn(c)){const u=t.getShape(c);t.isPointInShape(u,r,{margin:0,hitInside:!0})||t.setFocusedGroup(null)}}}}const jue=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var ZS;let Oue=(ZS=class extends ie{onEnter(){this.parent.setCurrentToolIdMask(void 0),uo(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){uo.cancel()}onPointerMove(){uo(this.editor)}onPointerDown(e){const n=e.ctrlKey&&t2(this.editor);switch(e.target){case"canvas":{const r=O5(this.editor);if(r&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((s.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&n2(this.editor,i)){this.onPointerDown({...e,target:"selection"});return}this.parent.transition("pointing_canvas",e);break}case"shape":{const{shape:r}=e;if(this.isOverArrowLabelTest(r)){this.parent.transition("pointing_arrow_label",e);break}if(this.editor.isShapeOrAncestorLocked(r)){this.parent.transition("pointing_canvas",e);break}this.parent.transition("pointing_shape",e);break}case"handle":{if(this.editor.getIsReadonly())break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",e):this.parent.transition("pointing_handle",e);break}case"selection":{switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_rotate_handle",e);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{if(n)this.parent.transition("crop.pointing_crop_handle",e);else{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_resize_handle",e)}break}default:{const r=this.editor.getHoveredShape();if(r&&!this.editor.getSelectedShapeIds().includes(r.id)&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}this.parent.transition("pointing_selection",e)}}break}}}onDoubleClick(e){var n,r,s,o;if(!(this.editor.inputs.shiftKey||e.phase!=="up")&&!(e.ctrlKey||e.shiftKey))switch(e.target){case"canvas":{const i=this.editor.getHoveredShape(),a=i&&!this.editor.isShapeOfType(i,"group")?i:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(a){if(this.editor.isShapeOfType(a,"group")){eg(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){eg(this.editor,e);return}}this.onDoubleClick({...e,shape:a,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(e);break}case"selection":{if(this.editor.getIsReadonly())break;const i=this.editor.getOnlySelectedShape();if(i){const a=this.editor.getShapeUtil(i);if(!this.canInteractWithShapeInReadOnly(i))return;if(e.handle==="right"||e.handle==="left"||e.handle==="top"||e.handle==="bottom"){const l=(n=a.onDoubleClickEdge)==null?void 0:n.call(a,i);if(l){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([l]),Xe(this.editor,[i.id]);return}}if(a.canCrop(i)&&!this.editor.isShapeOrAncestorLocked(i)){this.parent.transition("crop",e);return}this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}break}case"shape":{const{shape:i}=e,a=this.editor.getShapeUtil(i);if(i.type!=="video"&&i.type!=="embed"&&this.editor.getIsReadonly())break;if(a.onDoubleClick){const l=(r=a.onDoubleClick)==null?void 0:r.call(a,i);if(l){this.editor.updateShapes([l]);return}}if(a.canCrop(i)&&!this.editor.isShapeOrAncestorLocked(i)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select((s=e.shape)==null?void 0:s.id),this.parent.transition("crop",e);return}this.shouldStartEditingShape(i)?this.startEditingShape(i,e,!0):this.handleDoubleClickOnCanvas(e);break}case"handle":{if(this.editor.getIsReadonly())break;const{shape:i,handle:a}=e,l=this.editor.getShapeUtil(i),c=(o=l.onDoubleClickHandle)==null?void 0:o.call(l,i,a);c?this.editor.updateShapes([c]):this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}}}onRightClick(e){switch(e.target){case"canvas":{const n=this.editor.getHoveredShape(),r=n&&!this.editor.isShapeOfType(n,"group")?n:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!0,renderingOnly:!0});if(r){this.onRightClick({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((s.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&n2(this.editor,i)){this.onRightClick({...e,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:n}=this.editor.getCurrentPageState(),{shape:r}=e,s=this.editor.getOutermostSelectableShape(r,o=>!n.includes(o.id));!n.includes(s.id)&&!this.editor.findShapeAncestor(s,o=>n.includes(o.id))&&(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}}onCancel(){this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone())}onKeyDown(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(wt.editOnType.get()&&!jue.includes(e.key)&&!e.altKey&&!e.ctrlKey){const n=this.editor.getOnlySelectedShape();if(n&&this.editor.isShapeOfType(n,"note")&&this.shouldStartEditingShape(n)){this.startEditingShape(n,{...e,target:"shape",shape:n},!0);return}}}onKeyRepeat(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}}onKeyUp(e){switch(e.code){case"Enter":{const n=this.editor.getSelectedShapes();if(n.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(n.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const r=this.editor.getOnlySelectedShape();if(r&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...e,target:"shape",shape:r},!0);return}t2(this.editor)&&this.parent.transition("crop",e);break}}}shouldStartEditingShape(e=this.editor.getOnlySelectedShape()){return!e||this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||!this.canInteractWithShapeInReadOnly(e)?!1:this.editor.getShapeUtil(e).canEdit(e)}startEditingShape(e,n,r){this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||(this.editor.markHistoryStoppingPoint("editing shape"),Wp(this.editor,e,r),this.parent.transition("editing_shape",n))}isOverArrowLabelTest(e){if(!e)return!1;const n=this.editor.getPointInShapeSpace(e,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(e,"arrow")){const r=this.editor.getShapeGeometry(e).children[1];if(r&&hr(n,r.vertices))return!0}return!1}handleDoubleClickOnCanvas(e){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");const n=Ke(),{x:r,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:s,props:{text:"",autoSize:!0}}]);const o=this.editor.getShape(n);if(!o)return;const i=this.editor.getShapeUtil(o);this.editor.getIsReadonly()&&!i.canEditInReadOnly(o)||(this.editor.setEditingShape(n),this.editor.select(n),this.parent.transition("editing_shape",e))}nudgeSelectedShapes(e=!1){const{editor:{inputs:{keys:n}}}=this,r=n.has("ShiftLeft"),s=new x(0,0);if(n.has("ArrowLeft")&&(s.x-=1),n.has("ArrowRight")&&(s.x+=1),n.has("ArrowUp")&&(s.y-=1),n.has("ArrowDown")&&(s.y+=1),s.equals(new x(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:o}=this.editor.getDocumentSettings(),i=this.editor.getInstanceState().isGridMode?r?o*Lue:o:r?Due:Rue,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,s.mul(i)),Xe(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},I(ZS,"id","idle"),ZS);const Due=10,Rue=1,Lue=5;function n2(t,e){const n=t.getSelectionRotatedPageBounds();if(!n)return!1;const r=t.getSelectionRotation();return r?hr(e,n.corners.map(s=>x.RotWith(s,n.point,r))):n.containsPoint(e)}class z5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"markId","");I(this,"wasAlreadySelected",!1);I(this,"didDrag",!1);I(this,"didCtrlOnEnter",!1);I(this,"info",{});I(this,"_labelDragOffset",new x(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(n){const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.didCtrlOnEnter=n.accelKey,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const o=this.editor.getShapeGeometry(r).children[1];if(!o)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);if(this._labelDragOffset=x.Sub(o.center,a),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),n.shiftKey||n.accelKey){const c=this.editor.getSelectedShapeIds();this.editor.setSelectedShapes([...c,this.shapeId]);return}this.editor.setSelectedShapes([this.shapeId])}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){const{isDragging:n}=this.editor.inputs;if(!n)return;if(this.didCtrlOnEnter){this.parent.transition("brushing",this.info);return}const r=this.editor.getShape(this.shapeId);if(!r)return;const s=Es(this.editor,r),o=this.editor.getShapeGeometry(r),i=o.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(x.Add(a,this._labelDragOffset));let c;if(s.isStraight){const u=x.Dist(s.start.point,s.end.point);c=1-x.Dist(s.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:f,angleStart:p}=o.children[0];c=xx(h,p,f,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})}onPointerUp(){const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():this.editor.getIsReadonly()||(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}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")}}I(z5,"id","pointing_arrow_label");class B5 extends ie{onEnter(e){e.shiftKey||e.accelKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.markHistoryStoppingPoint("selecting none"),this.editor.selectNone())}onPointerMove(e){this.editor.inputs.isDragging&&this.parent.transition("brushing",e)}onPointerUp(e){eg(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}I(B5,"id","pointing_canvas");class U5 extends ie{constructor(){super(...arguments);I(this,"didCtrlOnEnter",!1);I(this,"info",{})}onEnter(n){this.info=n,this.didCtrlOnEnter=n.accelKey;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const s=Un(this.editor,r)[n.handle.id];s&&this.editor.setHintingShapes([s.toId])}this.editor.setCursor({type:"grabbing",rotation:0})}onExit(){this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})}onPointerUp(){const{shape:n,handle:r}=this.info;if(this.editor.isShapeOfType(n,"note")){const{editor:s}=this,o=r2(s,n,r,!1);if(o){Wp(s,o,!0);return}}this.parent.transition("idle",this.info)}onPointerMove(n){const{editor:r}=this;r.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",n):this.startDraggingHandle())}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){const{editor:n}=this;if(n.getIsReadonly())return;const{shape:r,handle:s}=this.info;if(n.isShapeOfType(r,"note")){const o=r2(n,r,s,!0);if(o){const i=n.getPointInParentSpace(o,n.inputs.originPagePoint).sub(x.Rot(wm.clone().mul(r.props.scale),o.rotation));n.updateShape({...o,x:i.x,y:i.y}),n.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{Wp(n,o,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(U5,"id","pointing_handle");function r2(t,e,n,r){const s=t.getShapePageTransform(e.id),o=s.point(),i=s.rotation(),l=t5(t,o,i,e.props.growY,0,e.props.scale)[n.index];if(l)return r5(t,e,l,i,r)}class H5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){this.editor.setCursor({type:zl[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(n){this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.editor.inputs.isDragging&&this.startRotating()}onLongPress(){this.startRotating()}startRotating(){this.editor.getIsReadonly()||this.parent.transition("rotating",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}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")}}I(H5,"id","pointing_rotate_handle");class K5 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(n){eg(this.editor,n),this.parent.transition("idle",n)}onPointerMove(n){this.editor.inputs.isDragging&&this.startTranslating(n)}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||this.parent.transition("translating",n)}onDoubleClick(n){var o,i;const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(s){this.parent.transition("idle"),(i=(o=this.parent).onDoubleClick)==null||i.call(o,{...n,target:"shape",shape:this.editor.getShape(s)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(K5,"id","pointing_selection");class W5 extends ie{constructor(){super(...arguments);I(this,"hitShape",{});I(this,"hitShapeForPointerUp",{});I(this,"isDoubleClick",!1);I(this,"didCtrlOnEnter",!1);I(this,"didSelectOnEnter",!1)}onEnter(n){const r=this.editor.getSelectedShapeIds(),s=this.editor.getSelectionRotatedPageBounds(),o=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i}}=this.editor,{shiftKey:a,altKey:l,accelKey:c}=n;this.hitShape=n.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=c;const u=this.editor.getOutermostSelectableShape(n.shape),h=this.editor.findShapeAncestor(u,f=>r.includes(f.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(n.shape).onClick||u.id===o||r.includes(u.id)||h||r.length>1&&(s!=null&&s.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=u;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(u.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,u.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([u.id]))}onPointerUp(n){var u;const r=this.editor.getSelectedShapeIds(),s=this.editor.getFocusedGroupId(),o=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i}}=this.editor,a=n.shiftKey||n.accelKey,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/o,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const f=(u=h.onClick)==null?void 0:u.call(h,c);if(f){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([f]),this.parent.transition("idle",n);return}}if(c.id===s){r.length>0?(this.editor.markHistoryStoppingPoint("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",n);return}}if(!this.didSelectOnEnter){const h=this.editor.getOutermostSelectableShape(l,f=>!r.includes(f.id));if(r.includes(h.id))if(a)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const f=this.editor.getShapeUtil(c).getGeometry(c),p=F5(f),g=p.length===1?p[0]:void 0;if(g){const m=this.editor.getPointInShapeSpace(c,i);if(g.bounds.containsPoint(m,0)&&g.hitTestPoint(m)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(c.id);const v=this.editor.getShapeUtil(c);this.editor.getIsReadonly()&&!v.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.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c);else if(a){const f=this.editor.getShapeAncestors(h);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(p=>!f.find(g=>g.id===p)),h.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",n)}onDoubleClick(){this.isDoubleClick=!0}onPointerMove(n){this.editor.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",n):this.startTranslating(n))}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||(this.editor.focus(),this.parent.transition("translating",n))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(W5,"id","pointing_shape");class G5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"didHoldCommand",!1);I(this,"creationCursorOffset",{x:0,y:0});I(this,"snapshot",{})}onEnter(n){const{isCreating:r=!1,creatingMarkId:s,creationCursorOffset:o={x:0,y:0}}=n;if(this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),this.markId="",r)if(s)this.markId=s;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");r&&this.editor.setCursor({type:"cross",rotation:0}),this.handleResizeStart(),this.updateShapes()}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(Xe(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:s})=>{var a;const o=this.editor.getShapeUtil(s),i=(a=o.onResizeStart)==null?void 0:a.call(o,s);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:s})=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onResizeEnd)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:n,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:o,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(o.size===1){const k=[...o.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:f}=this.editor.inputs,p=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),g=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!f){const{gridSize:k}=this.editor.getDocumentSettings();p.snapToGrid(k)}const m=this.info.handle,v=s2(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!f:f)&&c%Ze===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:x.Sub(p,g),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:s2(m,c),isAspectRatioLocked:h,isResizingFromCenter:n});p.add(k)}const S=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),b=x.Sub(p,S).rot(-c),P=x.Sub(g,S).rot(-c),C=x.DivV(b,P);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const _=m==="top"||m==="bottom",E=m==="left"||m==="right";h?E?C.y=Math.abs(C.x):_?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(_&&(C.x=1),E&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const k of o.keys()){const D=o.get(k);this.editor.resizeShape(k,C,{initialShape:D.shape,initialBounds:D.bounds,initialPageTransform:D.pageTransform,dragHandle:m,mode:l.length===1&&k===l[0]?"resize_bounds":"scale_shape",scaleOrigin:S,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:D}of s){if(!D.length)continue;const T=o.get(k).shape,j=this.editor.getShape(k);if(!(T&&j))continue;const L=j.x-T.x,M=j.y-T.y,O=new x(L,M).rot(-T.rotation);if(O.x!==0||O.y!==0)for(const F of D)this.editor.updateShape({id:F.id,type:F.type,x:F.x-O.x,y:F.y-O.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of s)if(k.length)for(const D of k)this.editor.updateShape({id:D.id,type:D.type,x:D.x,y:D.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:s,rotation:o}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==s&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==s&&(i.type="nwse-resize");break}}i.rotation=o,this.editor.setCursor(i)}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()}_createSnapshot(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:s}}=this.editor,o=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(o.getHandlePoint(this.info.handle),o.point,r),a=x.Sub(s,i),l=new Map,c=[];n.forEach(h=>{const f=this.editor.getShape(h);if(f){if(f.type==="frame"&&c.push({id:h,children:me(this.editor.getSortedChildIdsForParent(f).map(p=>this.editor.getShape(p)))}),l.set(f.id,this._createShapeSnapshot(f)),this.editor.isShapeOfType(f,"frame")&&n.length===1)return;this.editor.visitDescendants(f.id,p=>{const g=this.editor.getShape(p);if(g&&(l.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")))return!1})}});const u=![...l.values()].some(h=>!cj(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:o,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}}_createShapeSnapshot(n){const r=this.editor.getShapePageTransform(n),s=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:q.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(n)}}}I(G5,"id","resizing");const IS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function s2(t,e){e=e%Fe;const n=Math.round(e/(De/4)),r=IS.indexOf(t);return IS[(r+n)%IS.length]}const o2=Math.PI/180;class V5 extends ie{constructor(){super(...arguments);I(this,"snapshot",{});I(this,"info",{});I(this,"markId","")}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=SO({editor:this.editor,ids:this.editor.getSelectedShapeIds()});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const s=this._getRotationFromPointerPosition({snapToNearestDegree:!1});hf({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:zl[this.info.handle],rotation:s+this.snapshot.initialShapesRotation})}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}update(){const n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});hf({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:zl[this.info.handle],rotation:n+this.snapshot.initialShapesRotation})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)}complete(){hf({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Xe(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(),s=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:o,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialShapesRotation:l}=this.snapshot;if(!s)return l;const u=s.center.clone().rotWith(s.point,r).angle(i)-a;let h=l+u;if(o)h=Rp(h,24);else if(n&&(h=Math.round(h/o2)*o2,this.editor.getInstanceState().isCoarsePointer)){const f=Rp(h,4),p=cf(h,f);Math.abs(p)<yX(5)&&(h=f)}return h-l}}I(V5,"id","rotating");class Y5 extends ie{constructor(){super(...arguments);I(this,"hits",new Set);I(this,"size",0);I(this,"scribbleId","id");I(this,"initialSelectedShapeIds",new Set);I(this,"newlySelectedShapeIds",new Set)}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})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}updateScribbleSelection(n){const{editor:r}=this,s=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{shiftKey:o,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const h=s;let f,p,g,m;const v=0;for(let b=0,P=h.length;b<P;b++){if(f=h[b],r.isShapeOfType(f,"group")||c.has(f.id)||r.isShapeOrAncestorLocked(f)||(p=r.getShapeGeometry(f),r.isShapeOfType(f,"frame")&&p.bounds.containsPoint(r.getPointInShapeSpace(f,i))))continue;const C=r.getShapePageTransform(f);if(!p||!C)continue;const _=C.clone().invert();g=_.applyToPoint(a),m=_.applyToPoint(l);const{bounds:E}=p;if(!(E.minX-v>Math.max(g.x,m.x)||E.minY-v>Math.max(g.y,m.y)||E.maxX+v<Math.min(g.x,m.x)||E.maxY+v<Math.min(g.y,m.y))&&p.hitTestLineSegment(g,m,v)){const k=this.editor.getOutermostSelectableShape(f),D=this.editor.getShapeMask(k.id);if(D&&Pb(a,l,D)!==null&&!hr(l,D))continue;c.add(k.id)}}const y=r.getSelectedShapeIds(),S=new Set(o?[...c,...u]:[...c]);(y.length!==S.size||y.some(b=>!S.has(b)))&&this.editor.setSelectedShapes(Array.from(S))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}I(Y5,"id","scribble_brushing");var $ue=Object.create,X5=Object.defineProperty,Fue=Object.getOwnPropertyDescriptor,Nue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),q5=t=>{throw TypeError(t)},Z5=(t,e,n)=>e in t?X5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zue=t=>[,,,$ue(null)],Q5=["class","method","getter","setter","accessor","field","value","get","set"],J5=t=>t!==void 0&&typeof t!="function"?q5("Function expected"):t,Bue=(t,e,n,r,s)=>({kind:Q5[t],name:e,metadata:r,addInitializer:o=>n._?q5("Already initialized"):s.push(J5(o||null))}),Uue=(t,e)=>Z5(e,Nue("metadata"),t[3]),Hue=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Kue=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=Q5[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Fue(s,n)),y=r.length-1;y>=0;y--)l=Bue(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,J5(i)&&(v[g]=i);return v&&X5(s,n,v),s},ES=(t,e,n)=>Z5(t,typeof e!="symbol"?e+"":e,n),eF,Im;const Wue=20,Gue=100;eF=[Kn];class z1{constructor(e){this.editor=e,Hue(Im,5,this),ES(this,"prevDroppingShapeId",null),ES(this,"droppingNodeTimer",null),ES(this,"first",!0),e.disposables.add(this.dispose)}updateDroppingNode(e,n){var r;this.first&&(this.editor.setHintingShapes(e.map(s=>this.editor.findShapeAncestor(s,o=>o.type!=="group")).filter(s=>s)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,e))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(e,Wue,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Gue,n))}setDragTimer(e,n,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.run(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,e,r)}),this.droppingNodeTimer=null},n)}handleDrag(e,n,r){var l,c,u,h,f;n=me(n.map(p=>this.editor.getShape(p.id)));const s=((l=this.editor.getDroppingOverShape(e,n))==null?void 0:l.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:o}=this,i=o&&this.editor.getShape(o),a=s&&this.editor.getShape(s);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,n)),a&&((f=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||f.call(h,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=s}hintParents(e){const n=new Map;for(const s of e){const o=this.editor.findShapeAncestor(s,i=>i.type!=="group");o&&(n.has(o.id)||n.set(o.id,[]),n.get(o.id).push(s.id))}const r=[];for(const[s,o]of n){const i=this.editor.getShape(s);i&&QL(this.editor,i).length<o.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,s;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),n){const o=this.editor.getShape(n);if(!o)return;(s=(r=this.editor.getShapeUtil(o)).onDropShapesOver)==null||s.call(r,o,e)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}dispose(){this.clear()}}Im=zue();Kue(Im,1,"dispose",eF,z1);Uue(Im,z1);var Vue=Object.create,tF=Object.defineProperty,Yue=Object.getOwnPropertyDescriptor,nF=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),rF=t=>{throw TypeError(t)},sF=(t,e,n)=>e in t?tF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xue=t=>[,,,Vue((t==null?void 0:t[nF("metadata")])??null)],oF=["class","method","getter","setter","accessor","field","value","get","set"],iF=t=>t!==void 0&&typeof t!="function"?rF("Function expected"):t,que=(t,e,n,r,s)=>({kind:oF[t],name:e,metadata:r,addInitializer:o=>n._?rF("Already initialized"):s.push(iF(o||null))}),Zue=(t,e)=>sF(e,nF("metadata"),t[3]),Que=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Jue=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=oF[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Yue(s,n)),y=r.length-1;y>=0;y--)l=que(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,iF(i)&&(v[g]=i);return v&&tF(s,n,v),s},Ho=(t,e,n)=>sF(t,typeof e!="symbol"?e+"":e,n),aF,hw,Em;class km extends(hw=ie,aF=[Kn],hw){constructor(){super(...arguments),Que(Em,5,this),Ho(this,"info",{}),Ho(this,"selectionSnapshot",{}),Ho(this,"snapshot",{}),Ho(this,"markId",""),Ho(this,"isCloning",!1),Ho(this,"isCreating",!1),Ho(this,"dragAndDropManager",new z1(this.editor))}onCreate(e){}onEnter(e){var o;const{isCreating:n=!1,creatingMarkId:r,onCreate:s=()=>{}}=e;if(!((o=this.editor.getSelectedShapeIds())!=null&&o.length)){this.parent.transition("idle");return}if(this.info=e,this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.isCreating=n,this.markId="",n)if(r)this.markId=r;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("translating");if(this.onCreate=s,this.isCloning=!1,this.info=e,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=i2(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()}onTick({elapsed:e}){const{editor:n}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),n.edgeScrollManager.updateEdgeScrolling(e)}onPointerMove(){this.updateShapes()}onKeyDown(){if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()}onKeyUp(){if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate cloning"),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=i2(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate"),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){var e;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),Xe(this.editor,this.snapshot.movingShapes.map(n=>n.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(e=this.onCreate)==null||e.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:e}=this.snapshot,n=[];e.forEach(r=>{var i;const s=this.editor.getShapeUtil(r),o=(i=s.onTranslateStart)==null?void 0:i.call(s,r);o&&n.push(o)}),n.length>0&&this.editor.updateShapes(n),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:e}=this.snapshot;if(this.isCloning&&e.length>0){const r=x.Average(e.map(o=>this.editor.getShapePageTransform(o.id).point())),s=x.Sub(r,this.selectionSnapshot.averagePagePoint);x.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(o=>o.id),offset:{x:s.x,y:s.y}}})}const n=[];e.forEach(r=>{var a;const s=this.editor.getShape(r.id),o=this.editor.getShapeUtil(r),i=(a=o.onTranslateEnd)==null?void 0:a.call(o,r,s);i&&n.push(i)}),n.length>0&&this.editor.updateShapes(n)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),ede({editor:this.editor,snapshot:e});const{movingShapes:n}=e,r=[];n.forEach(s=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onTranslate)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateParentTransforms(){const{editor:e,snapshot:{shapeSnapshots:n}}=this;n.forEach(r=>{const s=e.getShape(r.shape.id);if(!s)return null;const o=Rn(s.parentId)?null:q.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=o})}}Em=Xue(hw);Jue(Em,1,"updateParentTransforms",aF,km);Zue(Em,km);Ho(km,"id","translating");function i2(t){var h;const e=[],n=[],r=t.getSelectedShapeIds(),s=me(r.map(f=>{const p=t.getShape(f);if(!p)return null;e.push(p);const g=t.getShapePageTransform(f),m=g.point(),v=g.rotation();n.push(m);const y=yr.isId(p.parentId)?null:q.Inverse(t.getShapePageTransform(p.parentId));return{shape:p,pagePoint:m,pageRotation:v,parentTransform:y}})),o=t.getOnlySelectedShape();let i=[];if(o)i=t.snaps.shapeBounds.getSnapPoints(o.id);else{const f=t.getSelectionPageBounds();f&&(i=f.cornersAndCenter.map((p,g)=>({id:"selection:"+g,x:p.x,y:p.y})))}let a,l;const{originPagePoint:c}=t.inputs,u=s.filter(f=>t.isShapeOfType(f.shape,"note")&&t.isPointInShape(f.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const f=t.getCurrentPageShapesSorted();l=(h=u.map(p=>({snapshot:p,index:f.findIndex(g=>g.id===p.shape.id)})).sort((p,g)=>g.index-p.index)[0])==null?void 0:h.snapshot}return l&&(a=n5(t,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:x.Average(n),movingShapes:e,shapeSnapshots:s,initialPageBounds:t.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function ede({editor:t,snapshot:e}){const{inputs:n}=t,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:o,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=e,c=t.getInstanceState().isGridMode,u=t.getDocumentSettings().gridSize,h=x.Sub(n.currentPagePoint,n.originPagePoint),f=t.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;f==="x"?h.x=0:f==="y"&&(h.y=0),t.snaps.clearIndicators();const p=t.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey;let g=!1;if(p&&t.inputs.pointerVelocity.len()<.5){const{nudge:S}=t.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:o,lockedAxis:f,initialSelectionSnapPoints:i});h.add(S)}else if(r&&s){const{scale:S}=r.shape.props,b=r.pagePoint.clone().add(h).add(wm.clone().mul(S).rot(r.pageRotation));let P=e5/t.getZoomLevel(),C=new x(0,0);for(const _ of s){const E=x.Sub(b,_),k=E.len();k<P&&(g=!0,P=k,C=E)}h.sub(C)}const m=x.Add(l,h),v=t.snaps.getIndicators();c&&!n.ctrlKey&&!g&&v.length===0&&m.snapToGrid(u);const y=x.Sub(m,l);t.updateShapes(me(a.map(({shape:S,pagePoint:b,parentTransform:P})=>{const C=x.Add(b,y),_=P?q.applyToPoint(P,C):C;return{id:S.id,type:S.type,x:_.x,y:_.y}})))}class Lf extends ie{constructor(){super(...arguments);I(this,"reactor")}static children(){return[dw,F1,Oue,B5,W5,km,A5,Y5,N1,K5,j5,N5,G5,V5,H5,z5,U5,$5]}cleanUpDuplicateProps(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const s=new Set(r.duplicateProps.shapeIds);n.length===s.size&&n.every(o=>s.has(o))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=As("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){console.error(n)}})}onExit(){var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}I(Lf,"id","select"),I(Lf,"initial","idle"),I(Lf,"isLockable",!1);class lF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}I(lF,"id","idle");class cF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{animation:{duration:220}}):this.editor.zoomIn(n,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}I(cF,"id","pointing");class uF extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"zoomBrush",new Z)}onEnter(n){this.info=n,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.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 s=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(s,{animation:{duration:220}}):this.editor.zoomIn(s,{animation:{duration:220}})}else{const s=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:s,animation:{duration:220}})}this.parent.transition("idle",this.info)}}I(uF,"id","zoom_brushing");class $f extends ie{constructor(){super(...arguments);I(this,"info",{})}static children(){return[lF,uF,cF]}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)}onKeyDown(){this.updateCursor()}onKeyUp(n){this.updateCursor(),n.code==="KeyZ"&&this.complete()}onInterrupt(){this.complete()}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}I($f,"id","zoom"),I($f,"initial","idle"),I($f,"isLockable",!1);const tde=[Of,Df,Rf,$f,Lf];function nde(){const t=z(),e=U("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(rde,{userId:e}):null}function rde({userId:t}){const e=Lg(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let fw={fonts:{draw:`${ti()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${ti()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${ti()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${ti()}/fonts/IBMPlexMono-Medium.woff2`}};function dF(t){return w.useMemo(()=>t?{fonts:{...fw.fonts,...t==null?void 0:t.fonts}}:fw,[t])}const sde=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bring-forward","bring-to-front","broken","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","color","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","leading","link","lock","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let Dc={...fw,icons:Object.fromEntries(sde.map(t=>[t,`${ti()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(Bu.map(t=>[t.locale,`${ti()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(S1.map(t=>[t.type,`${ti()}/embed-icons/${t.type}.png`]))};function ode(t){return t?{fonts:Object.assign({...Dc.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Dc.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Dc.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Dc.translations},{...t==null?void 0:t.translations})}:Dc}var B1="Popover",[hF,Dge]=Ws(B1,[sm]),kd=sm(),[ide,Di]=hF(B1),fF=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=t,a=kd(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,f]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(Xb,{...a,children:d.jsx(ide,{scope:e,contentId:mo(),triggerRef:l,open:h,onOpenChange:f,onOpenToggle:w.useCallback(()=>f(p=>!p),[f]),hasCustomAnchor:c,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:i,children:n})})};fF.displayName=B1;var pF="PopoverAnchor",ade=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(pF,n),o=kd(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=s;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(qb,{...o,...r,ref:e})});ade.displayName=pF;var gF="PopoverTrigger",mF=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(gF,n),o=kd(n),i=Qe(e,s.triggerRef),a=d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":wF(s.open),...r,ref:i,onClick:se(t.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:d.jsx(qb,{asChild:!0,...o,children:a})});mF.displayName=gF;var U1="PopoverPortal",[lde,cde]=hF(U1,{forceMount:void 0}),yF=t=>{const{__scopePopover:e,forceMount:n,children:r,container:s}=t,o=Di(U1,e);return d.jsx(lde,{scope:e,forceMount:n,children:d.jsx(ds,{present:n||o.open,children:d.jsx(Pd,{asChild:!0,container:s,children:r})})})};yF.displayName=U1;var Bl="PopoverContent",SF=w.forwardRef((t,e)=>{const n=cde(Bl,t.__scopePopover),{forceMount:r=n.forceMount,...s}=t,o=Di(Bl,t.__scopePopover);return d.jsx(ds,{present:r||o.open,children:o.modal?d.jsx(ude,{...s,ref:e}):d.jsx(dde,{...s,ref:e})})});SF.displayName=Bl;var ude=w.forwardRef((t,e)=>{const n=Di(Bl,t.__scopePopover),r=w.useRef(null),s=Qe(e,r),o=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return Zb(i)},[]),d.jsx(am,{as:fa,allowPinchZoom:!0,children:d.jsx(vF,{...t,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(t.onCloseAutoFocus,i=>{var a;i.preventDefault(),o.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:se(t.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;o.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),dde=w.forwardRef((t,e)=>{const n=Di(Bl,t.__scopePopover),r=w.useRef(!1),s=w.useRef(!1);return d.jsx(vF,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=t.onCloseAutoFocus)==null||i.call(t,o),o.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=t.onInteractOutside)==null||l.call(t,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),vF=w.forwardRef((t,e)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=t,f=Di(Bl,n),p=kd(n);return Nb(),d.jsx(em,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:d.jsx(wd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>f.onOpenChange(!1),children:d.jsx(I3,{"data-state":wF(f.open),role:"dialog",id:f.contentId,...p,...h,ref:e,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),xF="PopoverClose",hde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(xF,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,()=>s.onOpenChange(!1))})});hde.displayName=xF;var fde="PopoverArrow",pde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=kd(n);return d.jsx(E3,{...s,...r,ref:e})});pde.displayName=fde;function wF(t){return t?"open":"closed"}var H1=fF,K1=mF,W1=yF,G1=SF;function V1({id:t,children:e,onOpenChange:n,open:r}){const[s,o]=Mo(t,n);return d.jsx(H1,{onOpenChange:o,open:r||s,children:d.jsx("div",{className:"tlui-popover",children:e})})}function Y1({children:t}){return d.jsx(K1,{asChild:!0,dir:"ltr",children:t})}function X1({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:o=!1}){const i=Tt();return d.jsx(W1,{container:i,children:d.jsx(G1,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:s,dir:"ltr",onEscapeKeyDown:a=>o&&a.preventDefault(),children:e})})}function gde(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const s=Un(t,r);if(s.start||s.end)return!1}return!0})}const bF=()=>{const t=z();return U("threeStackableItems",()=>gde(t).length>2,[t])},Ao=()=>{const t=z();return U("isInSelectState",()=>t.isIn("select"),[t])},PF=()=>{const t=z();return U("allow group",()=>{const e=t.getSelectedShapes();if(e.length<2)return!1;for(const n of e)if(t.isShapeOfType(n,"arrow")){const r=Un(t,n);if(r.start&&!e.some(s=>s.id===r.start.toId)||r.end&&!e.some(s=>s.id===r.end.toId))return!1}return!0},[t])},CF=()=>{const t=z();return U("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},mde=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function _F(t,e){const n=z();return U("selectedShapes",()=>n.getSelectedShapes().length>=t,[n,t,e])}function jn(t,e){const n=z();return U("selectedShapes",()=>{const r=n.getSelectedShapes().filter(s=>!n.isShapeOrAncestorLocked(s)).length;return t===void 0?r:r>=t},[n])}function yde(){const t=z();return U("showAutoSizeToggle",()=>{const e=t.getSelectedShapes();return e.length===1&&t.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[t])}function IF(){const t=z();return U("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function Sde(){const t=z();return U("onlyFlippableShape",()=>{const e=t.getOnlySelectedShape();return e&&(t.isShapeOfType(e,"group")||t.isShapeOfType(e,"image")||t.isShapeOfType(e,"arrow")||t.isShapeOfType(e,"line")||t.isShapeOfType(e,"draw"))},[t])}function EF(){const t=z();return U("useCanRedo",()=>t.getCanRedo(),[t])}function kF(){const t=z();return U("useCanUndo",()=>t.getCanUndo(),[t])}function vde(){return d.jsxs(d.Fragment,{children:[d.jsx(xde,{}),d.jsx(wde,{}),d.jsx(bde,{}),d.jsx(Pde,{}),d.jsx(Cde,{}),d.jsx(Ede,{}),d.jsx(kde,{}),d.jsx(Tde,{})]})}function xde(){const t=jn(2),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"align-left",disabled:!n}),d.jsx(W,{actionId:"align-center-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-right",disabled:!n}),d.jsx(W,{actionId:"stretch-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-top",disabled:!n}),d.jsx(W,{actionId:"align-center-vertical",disabled:!n}),d.jsx(W,{actionId:"align-bottom",disabled:!n}),d.jsx(W,{actionId:"stretch-vertical",disabled:!n})]})}function wde(){const t=jn(3),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"distribute-horizontal",disabled:!n}),d.jsx(W,{actionId:"distribute-vertical",disabled:!n})]})}function bde(){const t=bF(),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"stack-horizontal",disabled:!n}),d.jsx(W,{actionId:"stack-vertical",disabled:!n})]})}function Pde(){const t=jn(1),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"send-to-back",disabled:!n}),d.jsx(W,{actionId:"send-backward",disabled:!n}),d.jsx(W,{actionId:"bring-forward",disabled:!n}),d.jsx(W,{actionId:"bring-to-front",disabled:!n})]})}function Cde(){return An()<St.TABLET_SM?d.jsx(_de,{}):d.jsx(Ide,{})}function _de(){const t=z(),e=U("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",disabled:e})}function Ide(){const t=jn(1),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"rotate-ccw",disabled:!n})}function Ede(){const t=jn(1),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"rotate-cw",disabled:!n})}function kde(){const t=IF(),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"edit-link",disabled:!n})}function Tde(){const t=PF(),e=CF();return t?d.jsx(a2,{}):e?d.jsx(Mde,{}):d.jsx(a2,{})}function a2(){const t=jn(2),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"group",disabled:!n})}function Mde(){return d.jsx(W,{actionId:"ungroup"})}const Ade=w.memo(function({children:e}){const n=Ee(),r=An(),s=wr(),o=w.useRef(null);Ai(o);const i=z(),a=U("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??d.jsx(vde,{});if(!(s&&!a))return d.jsxs(V1,{id:"actions-menu",children:[d.jsx(Y1,{children:d.jsx(ue,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(X1,{side:r>=St.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{ref:o,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(Fr,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function TF(){return yde()?d.jsx(W,{actionId:"toggle-auto-size"}):null}function MF(){return IF()?d.jsx(W,{actionId:"edit-link"}):null}function jde(){return jn(1)?d.jsx(W,{actionId:"duplicate"}):null}function AF(){const t=z();return U("should display flatten option",()=>{if(t.getSelectedShapeIds().length===0)return!1;const r=t.getOnlySelectedShape();return!(r&&t.isShapeOfType(r,"image"))},[t])?d.jsx(W,{actionId:"flatten-to-image"}):null}function jF(){return PF()?d.jsx(W,{actionId:"group"}):null}function OF(){return CF()?d.jsx(W,{actionId:"ungroup"}):null}function DF(){const t=z();return U("allow unframe",()=>{const n=t.getSelectedShapes();return n.length===0?!1:n.every(r=>t.isShapeOfType(r,"frame"))},[t])?d.jsx(W,{actionId:"remove-frame"}):null}function RF(){const t=z();return U("allow fit frame to content",()=>{const n=t.getOnlySelectedShape();return n?t.isShapeOfType(n,"frame")&&t.getSortedChildIdsForParent(n).length>0:!1},[t])?d.jsx(W,{actionId:"fit-frame-to-content"}):null}function LF(){const t=z();return U("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(W,{actionId:"toggle-lock"}):null}function q1(){const t=z(),e=U("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(fs,{actionId:"toggle-transparent",checked:e,toggle:!0})}function Ode(){const t=z(),e=U("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"unlock-all",disabled:!e})}function $F(){const t=z(),e=U("zoomed to 100",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function FF(){const t=z(),e=U("has shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function NF(){const t=z(),e=U("has shapes",()=>t.getSelectedShapeIds().length>0,[t]);return d.jsx(W,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function zF(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(Rde,{}),d.jsx(Lde,{}),d.jsx($de,{}),d.jsx(jde,{}),d.jsx(Fde,{})]})}function Dde(){var n;const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsxs(Jn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[d.jsxs(ve,{id:"copy-as-group",children:[d.jsx(W,{actionId:"copy-as-svg"}),!!((n=window.navigator.clipboard)!=null&&n.write)&&d.jsx(W,{actionId:"copy-as-png"}),d.jsx(W,{actionId:"copy-as-json"})]}),d.jsx(ve,{id:"copy-as-bg",children:d.jsx(q1,{})})]})}function Rde(){const t=jn(1);return d.jsx(W,{actionId:"cut",disabled:!t})}function Lde(){const t=_F(1);return d.jsx(W,{actionId:"copy",disabled:!t})}function $de(){const t=mde;return d.jsx(W,{actionId:"paste",disabled:!t})}function BF(){const t=z();return U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t])?d.jsxs(ve,{id:"conversions",children:[d.jsx(Dde,{}),d.jsxs(Jn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(ve,{id:"export-as-group",children:[d.jsx(W,{actionId:"export-as-svg"}),d.jsx(W,{actionId:"export-as-png"}),d.jsx(W,{actionId:"export-as-json"})]}),d.jsx(ve,{id:"export-as-bg",children:d.jsx(q1,{})})]})]}):null}function UF(){const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"select-all",disabled:!e})}function Fde(){const t=jn(1);return d.jsx(W,{actionId:"delete",disabled:!t})}function Nde(){const t=wr();return!_F(1)||t?null:d.jsxs(Jn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(jF,{}),d.jsx(OF,{}),d.jsx(AF,{}),d.jsx(MF,{}),d.jsx(RF,{}),d.jsx(DF,{}),d.jsx(KF,{}),d.jsx(HF,{}),d.jsx(TF,{}),d.jsx(LF,{})]})}function zde(){const t=jn(2),e=Sde();return wr()||!(t||e)?null:d.jsxs(Jn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[t&&d.jsxs(ve,{id:"align",children:[d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"})]}),d.jsx(Bde,{}),t&&d.jsxs(ve,{id:"stretch",children:[d.jsx(W,{actionId:"stretch-horizontal"}),d.jsx(W,{actionId:"stretch-vertical"})]}),(t||e)&&d.jsxs(ve,{id:"flip",children:[d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"})]}),d.jsx(Ude,{})]})}function Bde(){return jn(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(W,{actionId:"distribute-horizontal"}),d.jsx(W,{actionId:"distribute-vertical"})]}):null}function Ude(){const t=jn(2),e=bF();return t?d.jsxs(ve,{id:"order",children:[d.jsx(W,{actionId:"pack"}),e&&d.jsx(W,{actionId:"stack-horizontal"}),e&&d.jsx(W,{actionId:"stack-vertical"})]}):null}function Hde(){const t=wr(),e=jn(1);return t||!e?null:d.jsx(Jn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ve,{id:"reorder",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"})]})})}function Kde(){const t=z(),e=U("pages",()=>t.getPages(),[t]),n=U("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=To(),s=Jt(),o=wr();return!jn(1)||o?null:d.jsxs(Jn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(a=>d.jsx(Kt,{id:a.id,disabled:n===a.id,label:a.name.length>30?`${a.name.slice(0,30)}…`:a.name,onSelect:()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.moveShapesToPage(t.getSelectedShapeIds(),a.id);const l=t.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{t.markHistoryStoppingPoint("change-page"),t.setCurrentPage(n)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(W,{actionId:"move-to-new-page"})})]})}function HF(){const t=z();return U("oneEmbedSelected",()=>{const n=t.getOnlySelectedShape();return n?!!(t.isShapeOfType(n,"embed")&&n.props.url&&!t.isShapeOrAncestorLocked(n)):!1},[t])?d.jsx(W,{actionId:"convert-to-bookmark"}):null}function KF(){const t=z(),e=v1();return U("oneEmbeddableBookmarkSelected",()=>{const r=t.getOnlySelectedShape();return r?!!(t.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!t.isShapeOrAncestorLocked(r)):!1},[t])?d.jsx(W,{actionId:"convert-to-embed"}):null}function Wde(){const t=z(),e=U("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(fs,{actionId:"toggle-snap-mode",checked:e})}function Gde(){const t=z(),e=U("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(fs,{actionId:"toggle-tool-lock",checked:e})}function Vde(){const t=z(),e=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(fs,{actionId:"toggle-grid",checked:e})}function Yde(){const t=z(),e=U("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(fs,{actionId:"toggle-wrap-mode",checked:e})}function Xde(){const t=z(),e=U("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(fs,{actionId:"toggle-focus-mode",checked:e})}function qde(){const t=z(),e=U("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(fs,{actionId:"toggle-edge-scrolling",checked:e===1})}function Zde(){const t=z(),e=U("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(fs,{actionId:"toggle-reduce-motion",checked:e===0})}function Qde(){const t=z(),e=U("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(fs,{actionId:"toggle-debug-mode",checked:e})}function Jde(){const t=z(),e=U("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(fs,{actionId:"toggle-dynamic-size-mode",checked:e})}function ehe(){const t=z(),e=U("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(fs,{actionId:"toggle-paste-at-cursor",checked:e})}function the(){const t=z();return U("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(W,{actionId:"open-cursor-chat"}):null}function nhe(){const t=z(),e=gm(),n=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]),r=U("isSinglePageMode",()=>t.options.maxPages<=1,[t]);return n?d.jsxs(d.Fragment,{children:[e&&d.jsx(the,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(Nde,{}),d.jsx(zde,{}),d.jsx(Hde,{}),!r&&d.jsx(Kde,{})]}),d.jsx(zF,{}),d.jsx(BF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(UF,{})})]}):null}const rhe=w.memo(function({children:e,disabled:n=!1}){const r=z(),{Canvas:s}=st(),o=w.useCallback(u=>{if(u){if(r.getInstanceState().isCoarsePointer){const h=r.getSelectedShapes(),{inputs:{currentPagePoint:f}}=r,p=r.getShapesAtPoint(f);if(!r.getSelectedShapes().length||!p.some(g=>h.includes(g))){const g=p.filter(m=>r.isShapeOrAncestorLocked(m));g.length&&r.select(...g.map(m=>m.id))}}}else{const h=r.getOnlySelectedShape();h&&r.isShapeOrAncestorLocked(h)&&r.setSelectedShapes([])}},[r]),i=Tt(),[a,l]=Mo("context menu",o),c=e??d.jsx(nhe,{});return d.jsxs(Vse,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx(Yse,{onContextMenu:void 0,dir:"ltr",disabled:n,children:s?d.jsx(s,{}):null}),a&&d.jsx(Xse,{container:i,children:d.jsx(qse,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:xe,children:d.jsx(Fr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),she=2e3,ohe=5e3,ihe=Zt(function(){const e=z(),{isChatting:n,chatMessage:r}=e.getInstanceState(),s=w.useRef(-1),[o,i]=w.useState("");return w.useEffect(()=>{if(!n&&r||n){const l=n?ohe:she;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(s.current)}},[e,r,n]),n?d.jsx(lhe,{value:o,setValue:i,chatMessage:r}):r.trim()?d.jsx(ahe,{chatMessage:r}):null});function WF(t){const e=z();w.useLayoutEffect(()=>{var i;if(!t.current)return;const{x:r,y:s}=e.inputs.currentScreenPoint;(i=t.current)==null||i.style.setProperty("transform",`translate(${r}px, ${s}px)`);function o(a){var u;const{minX:l,minY:c}=e.getViewportScreenBounds();(u=t.current)==null||u.style.setProperty("transform",`translate(${a.clientX-l}px, ${a.clientY-c}px)`)}return window.addEventListener("pointermove",o),()=>{window.removeEventListener("pointermove",o)}},[t,e])}const ahe=({chatMessage:t})=>{const e=z(),n=w.useRef(null);return WF(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},lhe=Zt(function({chatMessage:e,value:n,setValue:r}){const s=z(),o=Ee(),i=w.useRef(null),a=e||o("cursor-chat.type-to-chat");WF(i),w.useLayoutEffect(()=>{const f=i.current;if(!f)return;const p=s.textMeasure.measureText(n||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});f.style.setProperty("width",p.w+"px")},[s,n,a]),w.useLayoutEffect(()=>{const f=s.timers.requestAnimationFrame(()=>{var p;(p=i.current)==null||p.focus()});return()=>{cancelAnimationFrame(f)}},[s]);const l=w.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=w.useCallback(f=>{const{value:p}=f.target;r(p.slice(0,64)),s.updateInstanceState({chatMessage:p})},[s,r]),u=w.useCallback(f=>{const p=i.current;if(!p)return;const{value:g}=p;switch(f.key){case"Enter":{if(xe(f),f.stopPropagation(),!g){l();return}r("");break}case"Escape":{xe(f),f.stopPropagation(),l();break}}},[l,r]),h=w.useCallback(f=>{f.stopPropagation()},[]);return d.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:l,onChange:c,onKeyDown:u,onPaste:h,value:n,placeholder:a,spellCheck:!1})});function pw({checked:t}){return d.jsx(zs,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function che(){const t=z(),{addToast:e}=To(),{addDialog:n}=Ed(),[r,s]=ke.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"items",children:[d.jsx(Kt,{id:"add-toast",onSelect:()=>{e({id:ze(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:ze(),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:()=>{}}]}),e({id:ze(),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:()=>{}}]}),e({id:ze(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),d.jsx(Kt,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:o})=>d.jsx(hhe,{displayDontShowAgain:!0,onCancel:()=>o(),onContinue:()=>o()}),onClose:()=>{}})}}),d.jsx(Kt,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>fhe(t,100)}),d.jsx(Kt,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const o=t.getSelectedShapes(),i=o.length===0?t.getRenderingShapes():o;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),d.jsx(Kt,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"}),d.jsx(Kt,{id:"hard-reset",onSelect:jj,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(uhe,{}),d.jsx(dhe,{})]})]})}function uhe(){const t=Object.values(wt);return t.length?d.jsx(Jn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ve,{id:"debug flags",children:t.map(e=>d.jsx(GF,{flag:e},e.name))})}):null}function dhe(){const t=Object.values(PX);return t.length?d.jsx(Jn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ve,{id:"feature flags",children:t.map(e=>d.jsx(GF,{flag:e},e.name))})}):null}function hhe({title:t="title",body:e="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:o,onContinue:i}){const[a,l]=ke.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:t}),d.jsx(fm,{})]}),d.jsx(Yu,{style:{maxWidth:350},children:e}),d.jsxs(y1,{className:"tlui-dialog__footer__actions",children:[s&&d.jsxs(ue,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(pw,{checked:a}),d.jsx(bt,{children:"Don’t show again"})]}),d.jsx(ue,{type:"normal",onClick:o,children:d.jsx(bt,{children:n})}),d.jsx(ue,{type:"primary",onClick:async()=>i(),children:d.jsx(bt,{children:r})})]})]})}const GF=Zt(function({flag:e,onChange:n}){const r=e.get();return d.jsx(vm,{id:e.name,title:e.name,label:e.name.replace(/([a-z0-9])([A-Z])/g,s=>`${s[0]} ${s[1].toLowerCase()}`).replace(/^[a-z]/,s=>s.toUpperCase()),checked:r,onSelect:()=>{e.set(!r),n==null||n(!r)}})});let l2=0;function fhe(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let s=0;s<e;s++)l2++,n[s]={id:Ke("box"+l2),type:"geo",x:s%r*132,y:Math.floor(s/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(s=>s.id))})}function phe({children:t}){const e=t??d.jsx(che,{});return d.jsxs(ma,{id:"debug",children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(Sa,{side:"top",align:"end",alignOffset:0,children:d.jsx(Fr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const ghe=w.memo(function(){const{DebugMenu:e}=Ri(),n=w.useRef(null);return Ai(n),d.jsxs("div",{ref:n,className:"tlui-debug-panel",children:[d.jsx(yhe,{}),d.jsx(She,{}),e&&d.jsx(e,{})]})});function mhe(t=!0){const[e,n]=w.useState(0),r=z();w.useEffect(()=>{if(!t)return;const s=()=>n(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,t])}const yhe=Zt(function(){mhe();const e=z(),n=e.getPath(),r=e.getHoveredShape(),s=e.getOnlySelectedShape(),o=n==="select.idle"||!n.includes("select.")?r:s,i=o&&n.includes("select.")?` / ${o.type||""}${"geo"in o.props?" / "+o.props.geo:""} / [${x.ToInt(e.getPointInShapeSpace(o,e.inputs.currentPagePoint))}]`:"",a=n.startsWith("select.")&&!n.includes(".idle")?` / [${x.ToInt(e.inputs.originPagePoint)}] → [${x.ToInt(e.inputs.currentPagePoint)}] = ${x.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return d.jsx("div",{className:"tlui-debug-panel__current-state",children:`${n}${i}${a}`})});function She(){const t=z(),e=U("show_fps",()=>wt.showFps.get(),[wt]),n=w.useRef(null);return w.useEffect(()=>{if(!e)return;const r=250;let s=0,o=-1,i=performance.now(),a=0,l=0,c=!1;function u(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>s&&(s=h);const f=s*.75;(h<f&&!c||h>=f&&c)&&(c=!c),n.current.innerHTML=`FPS ${h.toString()}`,n.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}o=t.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(o)}},[e,t]),e?d.jsx("div",{ref:n}):null}const vhe=w.memo(function(){const e=An(),n=w.useRef(null);Ai(n);const{MainMenu:r,QuickActions:s,ActionsMenu:o,PageMenu:i}=Ri(),a=z(),l=U("isSinglePageMode",()=>a.options.maxPages<=1,[a]),c=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=St.TABLET;return!r&&!i&&!c?null:d.jsx("div",{ref:n,className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&d.jsx(r,{}),i&&!l&&d.jsx(i,{}),c?d.jsxs(d.Fragment,{children:[s&&d.jsx(s,{}),o&&d.jsx(o,{})]}):null]})})});function xhe(){const t=z(),e=ka(),[n,r]=w.useState(!1),s=w.useRef(!1);return ui("toggle showback to content",()=>{const o=s.current,i=t.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===t.getCulledShapes().size),o!==a&&(r(a),s.current=a)},[t]),n?d.jsx(W,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function whe(){const t=z();return U("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(W,{actionId:"exit-pen-mode"}):null}function bhe(){const t=z(),e=ka();return U("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Kt,{...e["stop-following"]}):null}function Phe(){return d.jsxs(d.Fragment,{children:[d.jsx(whe,{}),d.jsx(xhe,{}),d.jsx(bhe,{})]})}function Che({children:t}){const e=t??d.jsx(Phe,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Fr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function _he(){const t=gm();return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(W,{actionId:"toggle-tool-lock"}),d.jsx(W,{actionId:"insert-media"}),d.jsx(Ln,{toolId:"select"}),d.jsx(Ln,{toolId:"draw"}),d.jsx(Ln,{toolId:"eraser"}),d.jsx(Ln,{toolId:"hand"}),d.jsx(Ln,{toolId:"rectangle"}),d.jsx(Ln,{toolId:"ellipse"}),d.jsx(Ln,{toolId:"arrow"}),d.jsx(Ln,{toolId:"line"}),d.jsx(Ln,{toolId:"text"}),d.jsx(Ln,{toolId:"frame"}),d.jsx(Ln,{toolId:"note"}),d.jsx(Ln,{toolId:"laser"}),d.jsx(Kt,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),d.jsxs(ve,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(W,{actionId:"toggle-dark-mode"}),d.jsx(W,{actionId:"toggle-focus-mode"}),d.jsx(W,{actionId:"toggle-grid"})]}),d.jsxs(ve,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(W,{actionId:"undo"}),d.jsx(W,{actionId:"redo"}),d.jsx(W,{actionId:"cut"}),d.jsx(W,{actionId:"copy"}),d.jsx(W,{actionId:"paste"}),d.jsx(W,{actionId:"select-all"}),d.jsx(W,{actionId:"delete"}),d.jsx(W,{actionId:"duplicate"})]}),d.jsxs(ve,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx(W,{actionId:"zoom-to-100"}),d.jsx(W,{actionId:"zoom-to-fit"}),d.jsx(W,{actionId:"zoom-to-selection"})]}),d.jsxs(ve,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"}),d.jsx(W,{actionId:"group"}),d.jsx(W,{actionId:"ungroup"}),d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"}),d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"})]}),t&&d.jsx(ve,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:d.jsx(W,{actionId:"open-cursor-chat"})})]})}const Ihe=w.memo(function({children:e}){const n=Ee(),r=An(),s=e??d.jsx(_he,{});return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(hm,{children:n("shortcuts-dialog.title")}),d.jsx(fm,{})]}),d.jsx(Yu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=St.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=St.TABLET}),children:d.jsx(Fr,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})});function VF(){const t=Ti(),e=Jt(),n=U("locale",()=>t==null?void 0:t.user.getLocale(),[t]);return t?d.jsx(Jn,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:Bu.map(({locale:r,label:s})=>d.jsx(vm,{id:`language-${r}`,title:r,label:s,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})}):null}function Ehe(){return d.jsxs(d.Fragment,{children:[d.jsx(VF,{}),d.jsx(YF,{})]})}function YF(){const{KeyboardShortcutsDialog:t}=Ri(),{addDialog:e}=Ed(),n=w.useCallback(()=>{t&&e({component:t})},[e,t]);return t?d.jsx(Kt,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:n}):null}function khe(){return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"basic",children:[d.jsx(Mhe,{}),d.jsx(Dhe,{}),d.jsx(The,{}),d.jsx(Rhe,{})]}),d.jsx(Lhe,{})]})}function The(){return d.jsxs(Jn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(ve,{id:"export-all-as-group",children:[d.jsx(W,{actionId:"export-all-as-svg"}),d.jsx(W,{actionId:"export-all-as-png"}),d.jsx(W,{actionId:"export-all-as-json"})]}),d.jsx(ve,{id:"export-all-as-bg",children:d.jsx(q1,{})})]})}function Mhe(){const t=z(),e=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(Jn,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(Ohe,{}),d.jsx(zF,{}),d.jsx(BF,{}),d.jsx(Ahe,{}),d.jsx(jhe,{}),d.jsx(ve,{id:"select-all",children:d.jsx(UF,{})})]})}function Ahe(){return d.jsxs(ve,{id:"misc",children:[d.jsx(jF,{}),d.jsx(OF,{}),d.jsx(MF,{}),d.jsx(TF,{}),d.jsx(DF,{}),d.jsx(RF,{}),d.jsx(KF,{}),d.jsx(HF,{}),d.jsx(AF,{})]})}function jhe(){return d.jsxs(ve,{id:"lock",children:[d.jsx(LF,{}),d.jsx(Ode,{})]})}function Ohe(){const t=kF(),e=EF();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}function Dhe(){return d.jsx(Jn,{id:"view",label:"menu.view",children:d.jsxs(ve,{id:"view-actions",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx($F,{}),d.jsx(FF,{}),d.jsx(NF,{})]})})}function Rhe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"insert-embed"}),d.jsx(W,{actionId:"insert-media"})]})}function Lhe(){return d.jsxs(ve,{id:"preferences",children:[d.jsxs(Jn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ve,{id:"preferences-actions",children:[d.jsx(Wde,{}),d.jsx(Gde,{}),d.jsx(Vde,{}),d.jsx(Yde,{}),d.jsx(Xde,{}),d.jsx(qde,{}),d.jsx(Zde,{}),d.jsx(Jde,{}),d.jsx(ehe,{}),d.jsx(Qde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(Uae,{})})]}),d.jsx(VF,{}),d.jsx(YF,{})]})}const $he=w.memo(function({children:e}){const n=Tt(),[r,s]=Mo("main menu"),o=Ee(),i=e??d.jsx(khe,{});return d.jsxs(c1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(u1,{asChild:!0,dir:"ltr",children:d.jsx(ue,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:d.jsx(be,{icon:"menu",small:!0})})}),d.jsx(um,{container:n,children:d.jsx(d1,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Fr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),kS={};function Rc(t){if(kS[t])return kS[t];const n=document.createElement("canvas").getContext("2d");n.fillStyle=t,n.fillRect(0,0,1,1);const[r,s,o,i]=n.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,o/255,i/255]);return kS[t]=a,a}const Ff=10,XF=4*6*Ff+12+4*12;function Ka(t,{center:e,radius:n,numArcSegments:r=20,startAngle:s=0,endAngle:o=Fe,offset:i=0}){const a=(o-s)/r;let l=i;for(let c=s;c<o;c+=a)t[l++]=e.x,t[l++]=e.y,t[l++]=e.x+Math.cos(c)*n,t[l++]=e.y+Math.sin(c)*n,t[l++]=e.x+Math.cos(c+a)*n,t[l++]=e.y+Math.sin(c+a)*n;return t}function Wa(t,e,n,r,s,o){t[e++]=n,t[e++]=r,t[e++]=n,t[e++]=r+o,t[e++]=n+s,t[e++]=r,t[e++]=n+s,t[e++]=r,t[e++]=n,t[e++]=r+o,t[e++]=n+s,t[e++]=r+o}function Fhe(t,e,n){const r=Ff;n=Math.min(n,Math.min(e.w,e.h)/2);const s=Z.ExpandBy(e,-n);if(s.w<=0||s.h<=0)return Ka(t,{center:e.center,radius:n,numArcSegments:Ff*4}),Ff*4*6;let o=0;return Wa(t,o,s.minX,s.minY,s.w,s.h),o+=12,Wa(t,o,s.minX,e.minY,s.w,n),o+=12,Wa(t,o,s.maxX,s.minY,n,s.h),o+=12,Wa(t,o,s.minX,s.maxY,s.w,n),o+=12,Wa(t,o,e.minX,s.minY,n,s.h),o+=12,Ka(t,{numArcSegments:r,offset:o,center:s.point,radius:n,startAngle:De,endAngle:De*1.5}),o+=r*6,Ka(t,{numArcSegments:r,offset:o,center:x.Add(s.point,new x(s.w,0)),radius:n,startAngle:De*1.5,endAngle:Fe}),o+=r*6,Ka(t,{numArcSegments:r,offset:o,center:x.Add(s.point,s.size),radius:n,startAngle:0,endAngle:Ze}),o+=r*6,Ka(t,{numArcSegments:r,offset:o,center:x.Add(s.point,new x(0,s.h)),radius:n,startAngle:Ze,endAngle:De}),XF}function Nhe(t){if(!t)throw new Error("Canvas element not found");const e=t.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
|
|
383
|
+
0px ${48*n}px ${10*n}px -${10*n}px inset rgba(15, 23, 44, ${((.022+r()*.005)*((1+o)/2)).toFixed(2)})`}function vue(t){return new Z(0,0,He,He+t.props.growY)}function xue(t,{initialBounds:e,scaleX:n,scaleY:r,newPoint:s}){const o=Math.max(.01,Math.min(Math.abs(n),Math.abs(r))),i=new x(0,0);n<0&&(i.x=-(e.width*o)),r<0&&(i.y=-(e.height*o));const{x:a,y:l}=x.Add(s,i.rot(t.rotation));return{x:a,y:l,props:{scale:o*t.props.scale}}}const wue=new Ds;class Af extends ss{getDefaultProps(){return{color:"black",size:"m",w:8,text:"",font:"draw",textAlign:"start",autoSize:!0,scale:1}}getMinDimensions(e){return wue.get(e.props,n=>e2(this.editor,n))}getGeometry(e){const{scale:n}=e.props,{width:r,height:s}=this.getMinDimensions(e);return new Fs({width:r*n,height:s*n,isFilled:!0,isLabel:!0})}getText(e){return e.props.text}canEdit(){return!0}isAspectRatioLocked(){return!0}component(e){const{id:n,props:{font:r,size:s,text:o,color:i,scale:a,textAlign:l}}=e,{width:c,height:u}=this.getMinDimensions(e),h=e.id===this.editor.getOnlySelectedShapeId(),f=zr(),p=bue(n);return d.jsx(Cm,{shapeId:n,classNamePrefix:"tl-text-shape",type:"text",font:r,fontSize:Ll[s],lineHeight:pn.lineHeight,align:l,verticalAlign:"middle",text:o,labelColor:f[i].solid,isSelected:h,textWidth:c,textHeight:u,style:{transform:`scale(${a})`,transformOrigin:"top left"},wrap:!0,onKeyDown:p})}indicator(e){const n=this.editor.getShapeGeometry(e).bounds,r=z();return e.props.autoSize&&r.getEditingShapeId()===e.id?null:d.jsx("rect",{width:N(n.width),height:N(n.height)})}toSvg(e,n){e.props.text&&n.addExportDef(bm(e.props.font));const r=this.editor.getShapeGeometry(e).bounds,s=r.width/(e.props.scale??1),o=r.height/(e.props.scale??1),i=ko(n);return d.jsx(Pm,{fontSize:Ll[e.props.size],font:e.props.font,align:e.props.textAlign,verticalAlign:"middle",text:e.props.text,labelColor:i[e.props.color].solid,bounds:new Z(0,0,s,o),padding:0})}onResize(e,n){const{newPoint:r,initialBounds:s,initialShape:o,scaleX:i,handle:a}=n;if(n.mode==="scale_shape"||a!=="right"&&a!=="left")return{id:e.id,type:e.type,...xue(e,n)};{const l=Math.max(1,Math.abs(s.width*i)),{x:c,y:u}=i<0?x.Sub(r,x.FromAngle(e.rotation).mul(l)):r;return{id:e.id,type:e.type,x:c,y:u,props:{w:l/o.props.scale,autoSize:!1}}}}onEditEnd(e){const{id:n,type:r,props:{text:s}}=e,o=e.props.text.trimEnd();o.length===0?this.editor.deleteShapes([e.id]):o!==e.props.text&&this.editor.updateShapes([{id:n,type:r,props:{text:s.trimEnd()}}])}onBeforeUpdate(e,n){if(!n.props.autoSize)return;const r=e.props.size!==n.props.size||e.props.textAlign!==n.props.textAlign||e.props.font!==n.props.font||e.props.scale!==1&&n.props.scale===1,s=e.props.text!==n.props.text;if(!r&&!s)return;const o=this.getMinDimensions(e),i=e2(this.editor,n.props),a=o.width*e.props.scale,l=o.height*e.props.scale,c=i.width*n.props.scale,u=i.height*n.props.scale;let h;switch(n.props.textAlign){case"middle":{h=new x((c-a)/2,s?0:(u-l)/2);break}case"end":{h=new x(c-a,s?0:(u-l)/2);break}default:{if(s)break;h=new x(0,(u-l)/2);break}}if(h){h.rot(n.rotation);const{x:f,y:p}=n;return{...n,x:f-h.x,y:p-h.y,props:{...n.props,w:c}}}else return{...n,props:{...n.props,w:c}}}}I(Af,"type","text"),I(Af,"props",ej),I(Af,"migrations",tj);function e2(t,e){const{font:n,text:r,autoSize:s,size:o,w:i}=e,a=s?16:Math.max(16,i),l=Ll[o],c=s?null:Math.floor(Math.max(a,i)),u=t.textMeasure.measureText(r,{...pn,fontFamily:Co[n],fontSize:l,maxWidth:c});return s&&(u.w+=1),{width:Math.max(a,u.w),height:Math.max(l,u.h)}}function bue(t){const e=z();return w.useCallback(n=>{if(e.getEditingShapeId()===t)switch(n.key){case"Enter":{(n.ctrlKey||n.metaKey)&&e.complete();break}case"Tab":{xe(n),n.shiftKey?$l.unindent(n.currentTarget):$l.indent(n.currentTarget);break}}},[e,t])}class jf extends oc{canEdit(){return!0}isAspectRatioLocked(){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,time:0,playing:!0,url:""}}component(e){return d.jsx(Pue,{shape:e})}indicator(e){return d.jsx("rect",{width:N(e.props.w),height:N(e.props.h)})}async toSvg(e){const n=await Cue(this.editor,e);return n?d.jsx("image",{href:n,width:e.props.w,height:e.props.h}):null}}I(jf,"type","video"),I(jf,"props",nj),I(jf,"migrations",rj);const Pue=w.memo(function({shape:e}){const n=z(),r=n.getShapeGeometry(e).bounds.w*n.getZoomLevel()>=110,s=Zg(e.id),o=QR(),{Spinner:i}=st(),{asset:a,url:l}=w5({shapeId:e.id,assetId:e.props.assetId}),c=w.useRef(null),[u,h]=w.useState(!1),[f,p]=w.useState(!1);w.useEffect(()=>{const m=()=>p(document.fullscreenElement===c.current);return document.addEventListener("fullscreenchange",m),()=>document.removeEventListener("fullscreenchange",m)});const g=w.useCallback(m=>{m.currentTarget&&h(!0)},[]);return w.useEffect(()=>{const m=c.current;m&&s&&document.activeElement!==m&&m.focus()},[s,u]),w.useEffect(()=>{if(o){const m=c.current;if(!m)return;m.pause(),m.currentTime=0}},[c,o]),d.jsxs(d.Fragment,{children:[d.jsx(hi,{id:e.id,style:{color:"var(--color-text-3)",backgroundColor:a?"transparent":"var(--color-low)",border:a?"none":"1px solid var(--color-low-border)"},children:d.jsx("div",{className:"tl-counter-scaled",children:d.jsx("div",{className:"tl-video-container",children:a?i&&!a.props.src?d.jsx(i,{}):l?d.jsxs(d.Fragment,{children:[d.jsx("video",{ref:c,style:s?{pointerEvents:"all"}:u?void 0:{display:"none"},className:ce("tl-video",`tl-video-shape-${e.id.split(":")[1]}`,{"tl-video-is-fullscreen":f}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:!0,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:s&&r,onLoadedData:g,hidden:!u,children:d.jsx("source",{src:l})}),!u&&i&&d.jsx(i,{})]}):null:d.jsx(x5,{})})})}),"url"in e.props&&e.props.url&&d.jsx(Fl,{url:e.props.url})]})});async function Cue(t,e){const n=await t.resolveAssetUrl(e.props.assetId,{shouldResolveToOriginal:!0});if(!n)return null;const r=await ar.loadVideo(n);return ar.getVideoFrameAsDataUrl(r,0)}const E5=[Af,Pf,Cf,If,Mf,Tf,_f,bf,Ef,Jp,kf,jf];function _ue(t){return t.sideEffects.register({instance_page_state:{afterChange:(e,n)=>{if(e.croppingShapeId!==n.croppingShapeId){const r=t.isIn("select.crop");!e.croppingShapeId&&n.croppingShapeId?r||t.setCurrentTool("select.crop.idle"):e.croppingShapeId&&!n.croppingShapeId&&r&&t.setCurrentTool("select.idle")}if(e.editingShapeId!==n.editingShapeId)if(!e.editingShapeId&&n.editingShapeId){if(!t.isIn("select.editing_shape")){const r=t.getEditingShape();r&&r.type==="text"&&t.isInAny("text.pointing","select.resizing")&&t.getInstanceState().isToolLocked?t.setCurrentTool("select.editing_shape",{isCreatingTextWhileToolLocked:!0}):t.setCurrentTool("select.editing_shape")}}else e.editingShapeId&&!n.editingShapeId&&t.isIn("select.editing_shape")&&t.setCurrentTool("select.idle")}}})}class k5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"scribbleId","id");I(this,"markId","");I(this,"excludedShapeIds",new Set)}onEnter(n){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=n;const{originPagePoint:r}=this.editor.inputs;this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter(o=>{if(this.editor.isShapeOrAncestorLocked(o))return!0;if(this.editor.isShapeOfType(o,"group")||this.editor.isShapeOfType(o,"frame")){const i=this.editor.getPointInShapeSpace(o,r);return this.editor.getShapeGeometry(o).bounds.containsPoint(i)}return!1}).map(o=>o.id));const s=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=s.id,this.update()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onExit(){this.editor.setErasingShapes([]),this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}update(){const{editor:n,excludedShapeIds:r}=this,s=n.getErasingShapeIds(),o=n.getZoomLevel(),i=n.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:a,previousPagePoint:l}}=n;this.pushPointToScribble();const c=new Set(s),u=this.editor.options.hitTestMargin/o;for(const h of i){if(n.isShapeOfType(h,"group"))continue;const f=n.getShapeMask(h.id);if(f&&!hr(a,f))continue;const p=n.getShapeGeometry(h),g=n.getShapePageTransform(h);if(!p||!g)continue;const m=g.clone().invert(),v=m.applyToPoint(l),y=m.applyToPoint(a),{bounds:S}=p;S.minX-u>Math.max(v.x,y.x)||S.minY-u>Math.max(v.y,y.y)||S.maxX+u<Math.min(v.x,y.x)||S.maxY+u<Math.min(v.y,y.y)||p.hitTestLineSegment(v,y,u)&&c.add(n.getOutermostSelectableShape(h).id)}this.editor.setErasingShapes([...c].filter(h=>!r.has(h)))}complete(){const{editor:n}=this;n.deleteShapes(n.getCurrentPageState().erasingShapeIds),this.parent.transition("idle")}cancel(){const{editor:n}=this;n.bailToMark(this.markId),this.parent.transition("idle",this.info)}}I(k5,"id","erasing");var WS;let Iue=(WS=class extends ie{onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(WS,"id","idle"),WS);var GS;let Eue=(GS=class extends ie{onEnter(){const e=this.editor.getZoomLevel(),n=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{currentPagePoint:r}}=this.editor,s=new Set,o=s.size;for(let i=n.length,a=i-1;a>=0;a--){const l=n[a];if(!(this.editor.isShapeOrAncestorLocked(l)||this.editor.isShapeOfType(l,"group"))&&this.editor.isPointInShape(l,r,{hitInside:!1,margin:this.editor.options.hitTestMargin/e})){const c=this.editor.getOutermostSelectableShape(l);if(this.editor.isShapeOfType(c,"frame")&&s.size>o)break;s.add(c.id)}}this.editor.setErasingShapes([...s])}onLongPress(e){this.startErasing(e)}onExit(e,n){n!=="erasing"&&this.editor.setErasingShapes([])}onPointerMove(e){this.editor.inputs.isDragging&&this.startErasing(e)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(e){this.parent.transition("erasing",e)}complete(){const e=this.editor.getErasingShapeIds();e.length&&(this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(e)),this.parent.transition("idle")}cancel(){this.parent.transition("idle")}},I(GS,"id","pointing"),GS);class Of extends ie{static children(){return[Iue,Eue,k5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Of,"id","eraser"),I(Of,"initial","idle"),I(Of,"isLockable",!1);class T5 extends ie{constructor(){super(...arguments);I(this,"initialCamera",new x)}onEnter(){this.initialCamera=x.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){const{initialCamera:n,editor:r}=this,{currentScreenPoint:s,originScreenPoint:o}=r.inputs,i=x.Sub(s,o).div(r.getZoomLevel());i.len2()!==0&&r.setCamera(n.clone().add(i))}complete(){const{editor:n}=this,{pointerVelocity:r}=n.inputs,s=Math.min(r.len(),2);s>.1&&this.editor.slideCamera({speed:s,direction:r}),this.parent.transition("idle")}}I(T5,"id","dragging");var VS;let kue=(VS=class extends ie{onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(e){this.parent.transition("pointing",e)}onCancel(){this.editor.setCurrentTool("select")}},I(VS,"id","idle"),VS);var YS;let Tue=(YS=class extends ie{onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){this.editor.inputs.isDragging&&this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}},I(YS,"id","pointing"),YS);class Df extends ie{static children(){return[kue,Tue,T5]}onDoubleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomIn(n,{animation:{duration:220,easing:Dt.easeOutQuint}})}}onTripleClick(e){if(e.phase==="settle"){const{currentScreenPoint:n}=this.editor.inputs;this.editor.zoomOut(n,{animation:{duration:320,easing:Dt.easeOutQuint}})}}onQuadrupleClick(e){if(e.phase==="settle"){const n=this.editor.getZoomLevel(),{inputs:{currentScreenPoint:r}}=this.editor;n===1?this.editor.zoomToFit({animation:{duration:400,easing:Dt.easeOutQuint}}):this.editor.resetZoom(r,{animation:{duration:320,easing:Dt.easeOutQuint}})}}}I(Df,"id","hand"),I(Df,"initial","idle"),I(Df,"isLockable",!1);var XS;let Mue=(XS=class extends ie{onPointerDown(e){this.parent.transition("lasering",e)}},I(XS,"id","idle"),XS);class M5 extends ie{constructor(){super(...arguments);I(this,"scribbleId","id")}onEnter(){const n=this.editor.scribbles.addScribble({color:"laser",opacity:.7,size:4,delay:this.editor.options.laserDelayMs,shrink:.05,taper:!0});this.scribbleId=n.id,this.pushPointToScribble()}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.pushPointToScribble()}onPointerUp(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}onCancel(){this.cancel()}onComplete(){this.complete()}complete(){this.parent.transition("idle")}cancel(){this.parent.transition("idle")}}I(M5,"id","lasering");class Rf extends ie{static children(){return[Mue,M5]}onEnter(){this.editor.setCursor({type:"cross",rotation:0})}}I(Rf,"id","laser"),I(Rf,"initial","idle"),I(Rf,"isLockable",!1);class A5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"initialSelectedShapeIds",[]);I(this,"excludedShapeIds",new Set);I(this,"isWrapMode",!1);I(this,"initialStartShape",null)}onEnter(n){const{altKey:r,currentPagePoint:s}=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(o=>this.editor.isShapeOfType(o,"group")||this.editor.isShapeOrAncestorLocked(o)).map(o=>o.id)),this.info=n,this.initialSelectedShapeIds=this.editor.getSelectedShapeIds().slice(),this.initialStartShape=this.editor.getShapesAtPoint(s)[0],this.hitTestShapes()}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null})}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(n){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",n)}onKeyDown(n){this.editor.inputs.altKey?this.parent.transition("scribble_brushing",n):this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){const{editor:n,excludedShapeIds:r,isWrapMode:s}=this,{inputs:{originPagePoint:o,currentPagePoint:i,shiftKey:a,ctrlKey:l}}=n,c=new Set(a?this.initialSelectedShapeIds:[]),u=s?!l:l,h=Z.FromPoints([o,i]),{corners:f}=h;let p,g,m,v,y,S;const b=n.getCurrentPageRenderingShapesSorted(),P=n.getCurrentPageId();e:for(let E=0,k=b.length;E<k;E++){if(m=b[E],r.has(m.id)||c.has(m.id)||(v=n.getShapePageBounds(m),!v))continue e;if(h.contains(v)){this.handleHit(m,i,P,c,f);continue e}if(u||n.isShapeOfType(m,"frame"))continue e;if(h.collides(v)){if(y=n.getShapePageTransform(m),!y)continue e;S=y.clone().invert().applyToPoints(f);const D=n.getShapeGeometry(m);t:for(let T=0;T<4;T++)if(p=S[T],g=S[(T+1)%4],D.hitTestLineSegment(p,g,0)){this.handleHit(m,i,P,c,f);break t}}}const C=n.getInstanceState().brush;(!C||!h.equals(C))&&n.updateInstanceState({brush:{...h.toJson()}});const _=n.getSelectedShapeIds();(_.length!==c.size||_.some(E=>!c.has(E)))&&n.setSelectedShapes(Array.from(c))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(n,r,s,o,i){if(n.parentId===s){o.add(n.id);return}const a=this.editor.getOutermostSelectableShape(n),l=this.editor.getShapeMask(a.id);l&&!_b(l,i)&&!hr(r,l)||o.add(a.id)}}I(A5,"id","brushing");const zl={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 j5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){const n=this.editor.getSelectedShapes(),r=zl[this.info.handle];this.editor.setCursor({type:r,rotation:n.length===1?this.editor.getSelectionRotation():0})}onEnter(n){this.info=n,this.updateCursor()}onPointerMove(){this.editor.inputs.isDragging&&this.startResizing()}onLongPress(){this.startResizing()}startResizing(){this.editor.getIsReadonly()||this.parent.transition("resizing",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}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")}}I(j5,"id","pointing_resize_handle");const _r=8;class F1 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"snapshot",{})}onEnter(n){this.info=n,this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;const r=zl[this.info.handle];this.editor.setCursor({type:r,rotation:this.editor.getSelectionRotation()})}getDefaultCrop(){return{topLeft:{x:0,y:0},bottomRight:{x:1,y:1}}}updateShapes(){const{shape:n,cursorHandleOffset:r}=this.snapshot;if(!n||!this.editor.getShapeUtil("image"))return;const o=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=o.crop??this.getDefaultCrop(),u=nt(c),h=new x(n.x,n.y),f=new x(0,0),p=1/(c.bottomRight.x-c.topLeft.x)*o.w,g=1/(c.bottomRight.y-c.topLeft.y)*o.h;let m=!1;switch(this.info.handle){case"top":case"top_left":case"top_right":{if(g<_r)break;m=!0,u.topLeft.y=u.topLeft.y+l.y/g,g*(u.bottomRight.y-u.topLeft.y)<_r?(u.topLeft.y=u.bottomRight.y-_r/g,f.y=(u.topLeft.y-c.topLeft.y)*g):u.topLeft.y<=0?(u.topLeft.y=0,f.y=(u.topLeft.y-c.topLeft.y)*g):f.y=l.y;break}case"bottom":case"bottom_left":case"bottom_right":{if(g<_r)break;m=!0,u.bottomRight.y=Math.min(1,u.bottomRight.y+l.y/g),g*(u.bottomRight.y-u.topLeft.y)<_r&&(u.bottomRight.y=u.topLeft.y+_r/g);break}}switch(this.info.handle){case"left":case"top_left":case"bottom_left":{if(p<_r)break;m=!0,u.topLeft.x=u.topLeft.x+l.x/p,p*(u.bottomRight.x-u.topLeft.x)<_r?(u.topLeft.x=u.bottomRight.x-_r/p,f.x=(u.topLeft.x-c.topLeft.x)*p):u.topLeft.x<=0?(u.topLeft.x=0,f.x=(u.topLeft.x-c.topLeft.x)*p):f.x=l.x;break}case"right":case"top_right":case"bottom_right":{if(p<_r)break;m=!0,u.bottomRight.x=Math.min(1,u.bottomRight.x+l.x/p),p*(u.bottomRight.x-u.topLeft.x)<_r&&(u.bottomRight.x=u.topLeft.x+_r/p);break}}if(!m)return;h.add(f.rot(n.rotation));const v={id:n.id,type:n.type,x:h.x,y:h.y,props:{crop:u,w:(u.bottomRight.x-u.topLeft.x)*p,h:(u.bottomRight.y-u.topLeft.y)*g}};this.editor.updateShapes([v]),this.updateCursor()}complete(){this.updateShapes(),Xe(this.editor,[this.snapshot.shape.id]),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}createSnapshot(){const n=this.editor.getSelectionRotation(),{inputs:{originPagePoint:r}}=this.editor,s=this.editor.getOnlySelectedShape(),o=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(o.getHandlePoint(this.info.handle),o.point,n),a=x.Sub(r,i);return{shape:s,cursorHandleOffset:a}}}I(F1,"id","cropping");function O5(t,e=!1){const n=t.getZoomLevel(),{inputs:{currentPagePoint:r}}=t;return t.getShapeAtPoint(r,{hitInside:!1,hitLabels:e,margin:t.options.hitTestMargin/n,renderingOnly:!0})??t.getSelectedShapeAtPoint(r)}function D5(t,e,n){if(!e)throw Error("Needs to translate a cropped shape!");const{crop:r}=e.props;if(!r)return;const s=t.inputs.shiftKey?Math.abs(n.x)<Math.abs(n.y)?"x":"y":null;s==="x"?n.x=0:s==="y"&&(n.y=0),n.rot(-e.rotation);const o=1/(r.bottomRight.x-r.topLeft.x)*e.props.w,i=1/(r.bottomRight.y-r.topLeft.y)*e.props.h,a=r.bottomRight.y-r.topLeft.y,l=r.bottomRight.x-r.topLeft.x,c=nt(r);return c.topLeft.x=Math.min(1-l,Math.max(0,c.topLeft.x-n.x/o)),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:e.id,type:e.type,props:{crop:c}}}var qS;let Aue=(qS=class extends ie{onEnter(){this.editor.setCursor({type:"default",rotation:0});const e=this.editor.getOnlySelectedShape();e&&this.editor.setCroppingShape(e.id)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(e){var n;if(e.accelKey){this.cancel(),this.editor.root.handleEvent(e);return}switch(e.target){case"canvas":{const r=O5(this.editor);if(r&&!this.editor.isShapeOfType(r,"group")){this.onPointerDown({...e,shape:r,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(e);break}case"shape":{if(e.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",e);return}else(n=this.editor.getShapeUtil(e.shape))!=null&&n.canCrop(e.shape)?(this.editor.setCroppingShape(e.shape.id),this.editor.setSelectedShapes([e.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",e)):(this.cancel(),this.editor.root.handleEvent(e));break}case"selection":{switch(e.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",{...e,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...e,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}onDoubleClick(e){var o;if(this.editor.inputs.shiftKey||e.phase!=="up")return;const n=this.editor.getCroppingShapeId();if(!n)return;const r=this.editor.getShape(n);if(!r)return;const s=this.editor.getShapeUtil(r);if(s){if(e.target==="selection"){(o=s.onDoubleClickEdge)==null||o.call(s,r);return}this.cancel(),this.editor.root.handleEvent(e)}}onKeyDown(){this.nudgeCroppingImage(!1)}onKeyRepeat(){this.nudgeCroppingImage(!0)}onKeyUp(e){switch(e.code){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(e=!1){const{editor:{inputs:{keys:n}}}=this,r=n.has("ShiftLeft"),s=new x(0,0);if(n.has("ArrowLeft")&&(s.x+=1),n.has("ArrowRight")&&(s.x-=1),n.has("ArrowUp")&&(s.y+=1),n.has("ArrowDown")&&(s.y-=1),s.equals(new x(0,0)))return;r&&s.mul(10);const o=this.editor.getShape(this.editor.getCroppingShapeId());if(!o)return;const i=D5(this.editor,o,s);i&&(e||this.editor.markHistoryStoppingPoint("translate crop"),this.editor.updateShapes([i]))}},I(qS,"id","idle"),qS);class R5 extends ie{onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(e){this.editor.inputs.isDragging&&this.editor.setCurrentTool("select.crop.translating_crop",e)}onPointerUp(e){this.editor.setCurrentTool("select.crop.idle",e)}}I(R5,"id","pointing_crop");class N1 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd);const r=this.editor.getSelectedShapes()[0];if(!r)return;const s=zl[this.info.handle];this.editor.setCursor({type:s,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(r.id)}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){this.editor.inputs.isDragging&&this.startCropping()}onLongPress(){this.startCropping()}startCropping(){this.editor.getIsReadonly()||this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}onPointerUp(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):(this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle"))}}I(N1,"id","pointing_crop_handle");class L5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"snapshot",{})}onEnter(n){this.info=n,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(n){switch(n.key){case"Alt":case"Shift":{this.updateShapes();return}}}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:s}=this.editor.inputs,o=s.clone().sub(r),i=D5(this.editor,n,o);i&&this.editor.updateShapes([i])}}I(L5,"id","translating_crop");class dw extends ie{constructor(){super(...arguments);I(this,"markId","");I(this,"didExit",!1)}static children(){return[Aue,L5,R5,N1,F1]}onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}onExit(){this.didExit||(this.didExit=!0,this.editor.squashToMark(this.markId))}onCancel(){this.didExit||(this.didExit=!0,this.editor.bailToMark(this.markId))}}I(dw,"id","crop"),I(dw,"initial","idle");class $5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"initialHandle",{});I(this,"initialAdjacentHandle",null);I(this,"initialPagePoint",{});I(this,"markId","");I(this,"initialPageTransform");I(this,"initialPageRotation");I(this,"info",{});I(this,"isPrecise",!1);I(this,"isPreciseId",null);I(this,"pointingId",null);I(this,"exactTimeout",-1)}onEnter(n){const{shape:r,isCreating:s,creatingMarkId:o,handle:i}=n;if(this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.shapeId=r.id,this.markId="",s)if(o)this.markId=o;else{const c=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);c&&(this.markId=c)}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");if(this.initialHandle=nt(i),this.editor.isShapeOfType(r,"line")&&this.initialHandle.type==="create"){this.editor.updateShape({...r,props:{points:{...r.props.points,[i.index]:{id:i.index,index:i.index,x:i.x,y:i.y}}}});const u=this.editor.getShapeHandles(r).find(h=>h.index===i.index);this.initialHandle=nt(u)}this.initialPageTransform=this.editor.getShapePageTransform(r),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.originPagePoint.clone(),this.editor.setCursor({type:s?"cross":"grabbing",rotation:0});const a=this.editor.getShapeHandles(r).sort(cn),l=a.findIndex(c=>c.id===n.handle.id);this.initialAdjacentHandle=null;for(let c=l+1;c<a.length;c++){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(!this.initialAdjacentHandle)for(let c=a.length-1;c>=0;c--){const u=a[c];if(u.type==="vertex"&&u.id!=="middle"&&u.id!==n.handle.id){this.initialAdjacentHandle=u;break}}if(this.editor.isShapeOfType(r,"arrow")){const c=Un(this.editor,r)[n.handle.id];this.isPrecise=!1,c?(this.editor.setHintingShapes([c.toId]),this.isPrecise=c.props.isPrecise,this.isPrecise?this.isPreciseId=c.toId:this.resetExactTimeout()):this.editor.setHintingShapes([])}this.update(),this.editor.select(this.shapeId)}resetExactTimeout(){this.exactTimeout!==-1&&this.clearExactTimeout(),this.exactTimeout=this.editor.timers.setTimeout(()=>{this.getIsActive()&&!this.isPrecise&&(this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update()),this.exactTimeout=-1},750)}clearExactTimeout(){this.exactTimeout!==-1&&(clearTimeout(this.exactTimeout),this.exactTimeout=-1)}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setHintingShapes([]),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),Xe(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 E;const{editor:n,shapeId:r,initialPagePoint:s}=this,{initialHandle:o,initialPageRotation:i,initialAdjacentHandle:a}=this,l=this.editor.getHintingShapeIds(),c=this.editor.user.getIsSnapMode(),{snaps:u,inputs:{currentPagePoint:h,shiftKey:f,ctrlKey:p,altKey:g,pointerVelocity:m}}=n,v=this.info.shape,y=n.getShape(r);if(!y)return;const S=n.getShapeUtil(y);let b=h.clone().sub(s).rot(-i).add(o);if(f&&a&&o.id!=="middle"){const k=x.Angle(a,b),T=Rp(k,24)-k;b=x.RotWith(b,a,T)}n.snaps.clearIndicators();let P={...o,x:b.x,y:b.y};if(o.canSnap&&(c?!p:p)){if(!n.getShapePageTransform(y.id))throw Error("Expected a page transform");const D=u.handles.snapHandle({currentShapeId:r,handle:P});D&&(D.nudge.rot(-n.getShapeParentTransform(y).rotation()),b.add(D.nudge),P={...o,x:b.x,y:b.y})}const C=(E=S.onHandleDrag)==null?void 0:E.call(S,y,{handle:P,isPrecise:this.isPrecise||g,initial:v}),_={id:y.id,type:y.type,...C};if(o.type==="vertex"&&this.editor.isShapeOfType(y,"arrow")){const k=Un(n,y)[o.id];k?l[0]!==k.toId&&(n.setHintingShapes([k.toId]),this.pointingId=k.toId,this.isPrecise=m.len()<.5||g,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()):l.length>0&&(n.setHintingShapes([]),this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout())}C&&n.updateShapes([_])}}I($5,"id","dragging_handle");function F5(t){return t.isLabel?[t]:t instanceof $r?t.children.filter(e=>e.isLabel):[]}class N5 extends ie{constructor(){super(...arguments);I(this,"hitShapeForPointerUp",null);I(this,"info",{})}onEnter(n){const r=this.editor.getEditingShape();if(!r)throw Error("Entered editing state without an editing shape");this.hitShapeForPointerUp=null,this.info=n,n.isCreatingTextWhileToolLocked&&this.parent.setCurrentToolIdMask("text"),uo(this.editor),this.editor.select(r)}onExit(){var o;const{editingShapeId:n}=this.editor.getCurrentPageState();if(!n)return;this.editor.setEditingShape(null),uo.cancel();const r=this.editor.getShape(n),s=this.editor.getShapeUtil(r);(o=s.onEditEnd)==null||o.call(s,r),this.info.isCreatingTextWhileToolLocked&&(this.parent.setCurrentToolIdMask(void 0),this.editor.setCurrentTool("text",{}))}onPointerMove(n){if(this.hitShapeForPointerUp&&this.editor.inputs.isDragging){if(this.editor.getIsReadonly()||this.hitShapeForPointerUp.isLocked)return;this.editor.select(this.hitShapeForPointerUp),this.parent.transition("translating",n),this.hitShapeForPointerUp=null;return}switch(n.target){case"shape":case"canvas":{uo(this.editor);return}}}onPointerDown(n){switch(this.hitShapeForPointerUp=null,n.target){case"shape":{const{shape:r}=n,s=this.editor.getEditingShape();if(!s)throw Error("Expected an editing shape!");const o=this.editor.getShapeUtil(r).getGeometry(r),i=F5(o),a=i.length===1?i[0]:void 0,l=this.editor.isShapeOfType(s,"text")&&s.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===s.id)return;this.hitShapeForPointerUp=r,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(r.id);return}}else{if(r.id===s.id)this.editor.isShapeOfType(r,"frame")&&(this.editor.setEditingShape(null),this.parent.transition("idle",n));else{this.parent.transition("pointing_shape",n);return}return}break}}this.parent.transition("idle",n),this.editor.root.handleEvent(n)}onPointerUp(n){const r=this.hitShapeForPointerUp;if(!r)return;this.hitShapeForPointerUp=null;const s=this.editor.getShapeUtil(r);if(!r.isLocked){if(this.editor.getIsReadonly()&&!s.canEditInReadOnly(r)){this.parent.transition("pointing_shape",n);return}this.editor.select(r.id),this.editor.setEditingShape(r.id),uo(this.editor)}}onComplete(n){this.parent.transition("idle",n)}onCancel(n){this.parent.transition("idle",n)}}I(N5,"id","editing_shape");function t2(t){const e=t.getOnlySelectedShape();return!!(e&&!t.isShapeOrAncestorLocked(e)&&t.getShapeUtil(e).canCrop(e))}function eg(t,e){const n=t.getSelectedShapeIds(),{currentPagePoint:r}=t.inputs,{shiftKey:s,altKey:o,accelKey:i}=e,a=s||i,l=t.getShapeAtPoint(r,{hitInside:!1,margin:t.options.hitTestMargin/t.getZoomLevel(),hitLabels:!0,renderingOnly:!0,filter:c=>!c.isLocked});if(l){const c=t.getOutermostSelectableShape(l);if(a&&!o)t.cancelDoubleClick(),n.includes(c.id)?(t.markHistoryStoppingPoint("deselecting shape"),t.deselect(c)):(t.markHistoryStoppingPoint("shift selecting shape"),t.setSelectedShapes([...n,c.id]));else{let u;c===l||c.id===t.getFocusedGroupId()||n.includes(c.id)?u=l:u=c,u&&!n.includes(u.id)&&(t.markHistoryStoppingPoint("selecting shape"),t.select(u.id))}}else{if(a)return;{n.length>0&&(t.markHistoryStoppingPoint("selecting none"),t.selectNone());const c=t.getFocusedGroupId();if(Fn(c)){const u=t.getShape(c);t.isPointInShape(u,r,{margin:0,hitInside:!0})||t.setFocusedGroup(null)}}}}const jue=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];var ZS;let Oue=(ZS=class extends ie{onEnter(){this.parent.setCurrentToolIdMask(void 0),uo(this.editor),this.editor.setCursor({type:"default",rotation:0})}onExit(){uo.cancel()}onPointerMove(){uo(this.editor)}onPointerDown(e){const n=e.ctrlKey&&t2(this.editor);switch(e.target){case"canvas":{const r=O5(this.editor);if(r&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((s.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&n2(this.editor,i)){this.onPointerDown({...e,target:"selection"});return}this.parent.transition("pointing_canvas",e);break}case"shape":{const{shape:r}=e;if(this.isOverArrowLabelTest(r)){this.parent.transition("pointing_arrow_label",e);break}if(this.editor.isShapeOrAncestorLocked(r)){this.parent.transition("pointing_canvas",e);break}this.parent.transition("pointing_shape",e);break}case"handle":{if(this.editor.getIsReadonly())break;this.editor.inputs.altKey?this.parent.transition("pointing_shape",e):this.parent.transition("pointing_handle",e);break}case"selection":{switch(e.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_rotate_handle",e);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{if(n)this.parent.transition("crop.pointing_crop_handle",e);else{if(e.accelKey){this.parent.transition("brushing",e);break}this.parent.transition("pointing_resize_handle",e)}break}default:{const r=this.editor.getHoveredShape();if(r&&!this.editor.getSelectedShapeIds().includes(r.id)&&!r.isLocked){this.onPointerDown({...e,shape:r,target:"shape"});return}this.parent.transition("pointing_selection",e)}}break}}}onDoubleClick(e){var n,r,s,o;if(!(this.editor.inputs.shiftKey||e.phase!=="up")&&!(e.ctrlKey||e.shiftKey))switch(e.target){case"canvas":{const i=this.editor.getHoveredShape(),a=i&&!this.editor.isShapeOfType(i,"group")?i:this.editor.getSelectedShapeAtPoint(this.editor.inputs.currentPagePoint)??this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1}),l=this.editor.getFocusedGroupId();if(a){if(this.editor.isShapeOfType(a,"group")){eg(this.editor,e);return}else{const c=this.editor.getShape(a.parentId);if(c&&this.editor.isShapeOfType(c,"group")&&!(l&&c.id===l)){eg(this.editor,e);return}}this.onDoubleClick({...e,shape:a,target:"shape"});return}this.editor.inputs.shiftKey||this.handleDoubleClickOnCanvas(e);break}case"selection":{if(this.editor.getIsReadonly())break;const i=this.editor.getOnlySelectedShape();if(i){const a=this.editor.getShapeUtil(i);if(!this.canInteractWithShapeInReadOnly(i))return;if(e.handle==="right"||e.handle==="left"||e.handle==="top"||e.handle==="bottom"){const l=(n=a.onDoubleClickEdge)==null?void 0:n.call(a,i);if(l){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([l]),Xe(this.editor,[i.id]);return}}if(a.canCrop(i)&&!this.editor.isShapeOrAncestorLocked(i)){this.parent.transition("crop",e);return}this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}break}case"shape":{const{shape:i}=e,a=this.editor.getShapeUtil(i);if(i.type!=="video"&&i.type!=="embed"&&this.editor.getIsReadonly())break;if(a.onDoubleClick){const l=(r=a.onDoubleClick)==null?void 0:r.call(a,i);if(l){this.editor.updateShapes([l]);return}}if(a.canCrop(i)&&!this.editor.isShapeOrAncestorLocked(i)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select((s=e.shape)==null?void 0:s.id),this.parent.transition("crop",e);return}this.shouldStartEditingShape(i)?this.startEditingShape(i,e,!0):this.handleDoubleClickOnCanvas(e);break}case"handle":{if(this.editor.getIsReadonly())break;const{shape:i,handle:a}=e,l=this.editor.getShapeUtil(i),c=(o=l.onDoubleClickHandle)==null?void 0:o.call(l,i,a);c?this.editor.updateShapes([c]):this.shouldStartEditingShape(i)&&this.startEditingShape(i,e,!0)}}}onRightClick(e){switch(e.target){case"canvas":{const n=this.editor.getHoveredShape(),r=n&&!this.editor.isShapeOfType(n,"group")?n:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!0,renderingOnly:!0});if(r){this.onRightClick({...e,shape:r,target:"shape"});return}const s=this.editor.getSelectedShapeIds(),o=this.editor.getOnlySelectedShape(),{inputs:{currentPagePoint:i}}=this.editor;if((s.length>1||o&&!this.editor.getShapeUtil(o).hideSelectionBoundsBg(o))&&n2(this.editor,i)){this.onRightClick({...e,target:"selection"});return}this.editor.selectNone();break}case"shape":{const{selectedShapeIds:n}=this.editor.getCurrentPageState(),{shape:r}=e,s=this.editor.getOutermostSelectableShape(r,o=>!n.includes(o.id));!n.includes(s.id)&&!this.editor.findShapeAncestor(s,o=>n.includes(o.id))&&(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([s.id]));break}}}onCancel(){this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0?this.editor.popFocusedGroupId():(this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone())}onKeyDown(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!1);return}}if(wt.editOnType.get()&&!jue.includes(e.key)&&!e.altKey&&!e.ctrlKey){const n=this.editor.getOnlySelectedShape();if(n&&this.editor.isShapeOfType(n,"note")&&this.shouldStartEditingShape(n)){this.startEditingShape(n,{...e,target:"shape",shape:n},!0);return}}}onKeyRepeat(e){switch(e.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{this.nudgeSelectedShapes(!0);break}}}onKeyUp(e){switch(e.code){case"Enter":{const n=this.editor.getSelectedShapes();if(n.every(s=>this.editor.isShapeOfType(s,"group"))){this.editor.setSelectedShapes(n.flatMap(s=>this.editor.getSortedChildIdsForParent(s.id)));return}const r=this.editor.getOnlySelectedShape();if(r&&this.shouldStartEditingShape(r)){this.startEditingShape(r,{...e,target:"shape",shape:r},!0);return}t2(this.editor)&&this.parent.transition("crop",e);break}}}shouldStartEditingShape(e=this.editor.getOnlySelectedShape()){return!e||this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||!this.canInteractWithShapeInReadOnly(e)?!1:this.editor.getShapeUtil(e).canEdit(e)}startEditingShape(e,n,r){this.editor.isShapeOrAncestorLocked(e)&&e.type!=="embed"||(this.editor.markHistoryStoppingPoint("editing shape"),Wp(this.editor,e,r),this.parent.transition("editing_shape",n))}isOverArrowLabelTest(e){if(!e)return!1;const n=this.editor.getPointInShapeSpace(e,this.editor.inputs.currentPagePoint);if(this.editor.isShapeOfType(e,"arrow")){const r=this.editor.getShapeGeometry(e).children[1];if(r&&hr(n,r.vertices))return!0}return!1}handleDoubleClickOnCanvas(e){if(this.editor.getIsReadonly()||!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");const n=Ke(),{x:r,y:s}=this.editor.inputs.currentPagePoint;this.editor.createShapes([{id:n,type:"text",x:r,y:s,props:{text:"",autoSize:!0}}]);const o=this.editor.getShape(n);if(!o)return;const i=this.editor.getShapeUtil(o);this.editor.getIsReadonly()&&!i.canEditInReadOnly(o)||(this.editor.setEditingShape(n),this.editor.select(n),this.parent.transition("editing_shape",e))}nudgeSelectedShapes(e=!1){const{editor:{inputs:{keys:n}}}=this,r=n.has("ShiftLeft"),s=new x(0,0);if(n.has("ArrowLeft")&&(s.x-=1),n.has("ArrowRight")&&(s.x+=1),n.has("ArrowUp")&&(s.y-=1),n.has("ArrowDown")&&(s.y+=1),s.equals(new x(0,0)))return;e||this.editor.markHistoryStoppingPoint("nudge shapes");const{gridSize:o}=this.editor.getDocumentSettings(),i=this.editor.getInstanceState().isGridMode?r?o*Lue:o:r?Due:Rue,a=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(a,s.mul(i)),Xe(this.editor,a)}canInteractWithShapeInReadOnly(e){return!!(!this.editor.getIsReadonly()||this.editor.getShapeUtil(e).canEditInReadOnly(e))}},I(ZS,"id","idle"),ZS);const Due=10,Rue=1,Lue=5;function n2(t,e){const n=t.getSelectionRotatedPageBounds();if(!n)return!1;const r=t.getSelectionRotation();return r?hr(e,n.corners.map(s=>x.RotWith(s,n.point,r))):n.containsPoint(e)}class z5 extends ie{constructor(){super(...arguments);I(this,"shapeId","");I(this,"markId","");I(this,"wasAlreadySelected",!1);I(this,"didDrag",!1);I(this,"didCtrlOnEnter",!1);I(this,"info",{});I(this,"_labelDragOffset",new x(0,0))}updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(n){const{shape:r}=n;this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.shapeId=r.id,this.didDrag=!1,this.didCtrlOnEnter=n.accelKey,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===r.id,this.updateCursor();const o=this.editor.getShapeGeometry(r).children[1];if(!o)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=x.Sub(o.center,a),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),this.editor.setSelectedShapes([this.shapeId])}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){const{isDragging:n}=this.editor.inputs;if(!n)return;if(this.didCtrlOnEnter){this.parent.transition("brushing",this.info);return}const r=this.editor.getShape(this.shapeId);if(!r)return;const s=Es(this.editor,r),o=this.editor.getShapeGeometry(r),i=o.children[0],a=this.editor.getPointInShapeSpace(r,this.editor.inputs.currentPagePoint),l=i.nearestPoint(x.Add(a,this._labelDragOffset));let c;if(s.isStraight){const u=x.Dist(s.start.point,s.end.point);c=1-x.Dist(s.end.point,l)/u}else{const{_center:u,measure:h,angleEnd:f,angleStart:p}=o.children[0];c=xx(h,p,f,u.angle(l))}isNaN(c)&&(c=.5),this.didDrag=!0,this.editor.updateShape({id:r.id,type:r.type,props:{labelPosition:c}})}onPointerUp(){const n=this.editor.getShape(this.shapeId);n&&(this.didDrag||!this.wasAlreadySelected?this.complete():this.editor.getIsReadonly()||(this.editor.setEditingShape(n.id),this.editor.setCurrentTool("select.editing_shape")))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}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")}}I(z5,"id","pointing_arrow_label");class B5 extends ie{onEnter(e){e.shiftKey||e.accelKey||this.editor.getSelectedShapeIds().length>0&&(this.editor.markHistoryStoppingPoint("selecting none"),this.editor.selectNone())}onPointerMove(e){this.editor.inputs.isDragging&&this.parent.transition("brushing",e)}onPointerUp(e){eg(this.editor,e),this.complete()}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}I(B5,"id","pointing_canvas");class U5 extends ie{constructor(){super(...arguments);I(this,"didCtrlOnEnter",!1);I(this,"info",{})}onEnter(n){this.info=n,this.didCtrlOnEnter=n.accelKey;const{shape:r}=n;if(this.editor.isShapeOfType(r,"arrow")){const s=Un(this.editor,r)[n.handle.id];s&&this.editor.setHintingShapes([s.toId])}this.editor.setCursor({type:"grabbing",rotation:0})}onExit(){this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})}onPointerUp(){const{shape:n,handle:r}=this.info;if(this.editor.isShapeOfType(n,"note")){const{editor:s}=this,o=r2(s,n,r,!1);if(o){Wp(s,o,!0);return}}this.parent.transition("idle",this.info)}onPointerMove(n){const{editor:r}=this;r.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",n):this.startDraggingHandle())}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){const{editor:n}=this;if(n.getIsReadonly())return;const{shape:r,handle:s}=this.info;if(n.isShapeOfType(r,"note")){const o=r2(n,r,s,!0);if(o){const i=n.getPointInParentSpace(o,n.inputs.originPagePoint).sub(x.Rot(wm.clone().mul(r.props.scale),o.rotation));n.updateShape({...o,x:i.x,y:i.y}),n.setHoveredShape(o.id).select(o.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:n.getShape(o),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{Wp(n,o,!0)}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(U5,"id","pointing_handle");function r2(t,e,n,r){const s=t.getShapePageTransform(e.id),o=s.point(),i=s.rotation(),l=t5(t,o,i,e.props.growY,0,e.props.scale)[n.index];if(l)return r5(t,e,l,i,r)}class H5 extends ie{constructor(){super(...arguments);I(this,"info",{})}updateCursor(){this.editor.setCursor({type:zl[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(n){this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.info=n,this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.editor.inputs.isDragging&&this.startRotating()}onLongPress(){this.startRotating()}startRotating(){this.editor.getIsReadonly()||this.parent.transition("rotating",this.info)}onPointerUp(){this.complete()}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}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")}}I(H5,"id","pointing_rotate_handle");class K5 extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(n){eg(this.editor,n),this.parent.transition("idle",n)}onPointerMove(n){this.editor.inputs.isDragging&&this.startTranslating(n)}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||this.parent.transition("translating",n)}onDoubleClick(n){var o,i;const r=this.editor.getHoveredShape(),s=r&&!this.editor.isShapeOfType(r,"group")?r:this.editor.getShapeAtPoint(this.editor.inputs.currentPagePoint,{hitInside:!0,margin:0,renderingOnly:!0});if(s){this.parent.transition("idle"),(i=(o=this.parent).onDoubleClick)==null||i.call(o,{...n,target:"shape",shape:this.editor.getShape(s)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(K5,"id","pointing_selection");class W5 extends ie{constructor(){super(...arguments);I(this,"hitShape",{});I(this,"hitShapeForPointerUp",{});I(this,"isDoubleClick",!1);I(this,"didCtrlOnEnter",!1);I(this,"didSelectOnEnter",!1)}onEnter(n){const r=this.editor.getSelectedShapeIds(),s=this.editor.getSelectionRotatedPageBounds(),o=this.editor.getFocusedGroupId(),{inputs:{currentPagePoint:i}}=this.editor,{shiftKey:a,altKey:l,accelKey:c}=n;this.hitShape=n.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=c;const u=this.editor.getOutermostSelectableShape(n.shape),h=this.editor.findShapeAncestor(u,f=>r.includes(f.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(n.shape).onClick||u.id===o||r.includes(u.id)||h||r.length>1&&(s!=null&&s.containsPoint(i))){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=u;return}this.didSelectOnEnter=!0,a&&!l?(this.editor.cancelDoubleClick(),r.includes(u.id)||(this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...r,u.id]))):(this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([u.id]))}onPointerUp(n){var u;const r=this.editor.getSelectedShapeIds(),s=this.editor.getFocusedGroupId(),o=this.editor.getZoomLevel(),{inputs:{currentPagePoint:i}}=this.editor,a=n.shiftKey||n.accelKey,l=this.editor.getShapeAtPoint(i,{margin:this.editor.options.hitTestMargin/o,hitInside:!0,renderingOnly:!0})??this.hitShape,c=l?this.editor.getOutermostSelectableShape(l):this.hitShapeForPointerUp;if(c){const h=this.editor.getShapeUtil(c);if(h.onClick){const f=(u=h.onClick)==null?void 0:u.call(h,c);if(f){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([f]),this.parent.transition("idle",n);return}}if(c.id===s){r.length>0?(this.editor.markHistoryStoppingPoint("clearing shape ids"),this.editor.setSelectedShapes([])):this.editor.popFocusedGroupId(),this.parent.transition("idle",n);return}}if(!this.didSelectOnEnter){const h=this.editor.getOutermostSelectableShape(l,f=>!r.includes(f.id));if(r.includes(h.id))if(a)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(c);else if(r.includes(c.id)){if(r.length===1){const f=this.editor.getShapeUtil(c).getGeometry(c),p=F5(f),g=p.length===1?p[0]:void 0;if(g){const m=this.editor.getPointInShapeSpace(c,i);if(g.bounds.containsPoint(m,0)&&g.hitTestPoint(m)){this.editor.run(()=>{this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(c.id);const v=this.editor.getShapeUtil(c);this.editor.getIsReadonly()&&!v.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.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(c);else if(a){const f=this.editor.getShapeAncestors(h);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter(p=>!f.find(g=>g.id===p)),h.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([h.id])}this.parent.transition("idle",n)}onDoubleClick(){this.isDoubleClick=!0}onPointerMove(n){this.editor.inputs.isDragging&&(this.didCtrlOnEnter?this.parent.transition("brushing",n):this.startTranslating(n))}onLongPress(n){this.startTranslating(n)}startTranslating(n){this.editor.getIsReadonly()||(this.editor.focus(),this.parent.transition("translating",n))}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}I(W5,"id","pointing_shape");class G5 extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"markId","");I(this,"didHoldCommand",!1);I(this,"creationCursorOffset",{x:0,y:0});I(this,"snapshot",{})}onEnter(n){const{isCreating:r=!1,creatingMarkId:s,creationCursorOffset:o={x:0,y:0}}=n;if(this.info=n,this.didHoldCommand=!1,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.creationCursorOffset=o,this.snapshot=this._createSnapshot(),this.markId="",r)if(s)this.markId=s;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");r&&this.editor.setCursor({type:"cross",rotation:0}),this.handleResizeStart(),this.updateShapes()}onTick({elapsed:n}){const{editor:r}=this;r.edgeScrollManager.updateEdgeScrolling(n)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,{}):this.parent.transition("idle")}complete(){var n,r;if(Xe(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:s})=>{var a;const o=this.editor.getShapeUtil(s),i=(a=o.onResizeStart)==null?void 0:a.call(o,s);i&&r.push(i)}),r.length>0&&this.editor.updateShapes(r)}handleResizeEnd(){const{shapeSnapshots:n}=this.snapshot,r=[];n.forEach(({shape:s})=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onResizeEnd)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateShapes(){const{altKey:n,shiftKey:r}=this.editor.inputs,{frames:s,shapeSnapshots:o,selectionBounds:i,cursorHandleOffset:a,selectedShapeIds:l,selectionRotation:c,canShapesDeform:u}=this.snapshot;let h=r||!u;if(o.size===1){const k=[...o.values()][0];this.editor.isShapeOfType(k.shape,"text")&&(h=!(this.info.handle==="left"||this.info.handle==="right"))}const{ctrlKey:f}=this.editor.inputs,p=this.editor.inputs.currentPagePoint.clone().sub(a).sub(this.creationCursorOffset),g=this.editor.inputs.originPagePoint.clone().sub(a);if(this.editor.getInstanceState().isGridMode&&!f){const{gridSize:k}=this.editor.getDocumentSettings();p.snapToGrid(k)}const m=this.info.handle,v=s2(m,Math.PI);if(this.editor.snaps.clearIndicators(),(this.editor.user.getIsSnapMode()?!f:f)&&c%Ze===0){const{nudge:k}=this.editor.snaps.shapeBounds.snapResizeShapes({dragDelta:x.Sub(p,g),initialSelectionPageBounds:this.snapshot.initialSelectionPageBounds,handle:s2(m,c),isAspectRatioLocked:h,isResizingFromCenter:n});p.add(k)}const S=x.RotWith(n?i.center:i.getHandlePoint(v),i.point,c),b=x.Sub(p,S).rot(-c),P=x.Sub(g,S).rot(-c),C=x.DivV(b,P);Number.isFinite(C.x)||(C.x=1),Number.isFinite(C.y)||(C.y=1);const _=m==="top"||m==="bottom",E=m==="left"||m==="right";h?E?C.y=Math.abs(C.x):_?C.x=Math.abs(C.y):Math.abs(C.x)>Math.abs(C.y)?C.y=Math.abs(C.x)*(C.y<0?-1:1):C.x=Math.abs(C.y)*(C.x<0?-1:1):(_&&(C.x=1),E&&(C.y=1)),this.info.isCreating||this.updateCursor({dragHandle:m,isFlippedX:C.x<0,isFlippedY:C.y<0,rotation:c});for(const k of o.keys()){const D=o.get(k);this.editor.resizeShape(k,C,{initialShape:D.shape,initialBounds:D.bounds,initialPageTransform:D.pageTransform,dragHandle:m,mode:l.length===1&&k===l[0]?"resize_bounds":"scale_shape",scaleOrigin:S,isAspectRatioLocked:h,scaleAxisRotation:c,skipStartAndEndCallbacks:!0})}if(this.editor.inputs.ctrlKey){this.didHoldCommand=!0;for(const{id:k,children:D}of s){if(!D.length)continue;const T=o.get(k).shape,j=this.editor.getShape(k);if(!(T&&j))continue;const L=j.x-T.x,M=j.y-T.y,O=new x(L,M).rot(-T.rotation);if(O.x!==0||O.y!==0)for(const F of D)this.editor.updateShape({id:F.id,type:F.type,x:F.x-O.x,y:F.y-O.y})}}else if(this.didHoldCommand){this.didHoldCommand=!1;for(const{children:k}of s)if(k.length)for(const D of k)this.editor.updateShape({id:D.id,type:D.type,x:D.x,y:D.y})}}updateCursor({dragHandle:n,isFlippedX:r,isFlippedY:s,rotation:o}){const i={...this.editor.getInstanceState().cursor};switch(n){case"top_left":case"bottom_right":{i.type="nwse-resize",r!==s&&(i.type="nesw-resize");break}case"top_right":case"bottom_left":{i.type="nesw-resize",r!==s&&(i.type="nwse-resize");break}}i.rotation=o,this.editor.setCursor(i)}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators()}_createSnapshot(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getSelectionRotation(),{inputs:{originPagePoint:s}}=this.editor,o=this.editor.getSelectionRotatedPageBounds(),i=x.RotWith(o.getHandlePoint(this.info.handle),o.point,r),a=x.Sub(s,i),l=new Map,c=[];n.forEach(h=>{const f=this.editor.getShape(h);if(f){if(f.type==="frame"&&c.push({id:h,children:me(this.editor.getSortedChildIdsForParent(f).map(p=>this.editor.getShape(p)))}),l.set(f.id,this._createShapeSnapshot(f)),this.editor.isShapeOfType(f,"frame")&&n.length===1)return;this.editor.visitDescendants(f.id,p=>{const g=this.editor.getShape(p);if(g&&(l.set(g.id,this._createShapeSnapshot(g)),this.editor.isShapeOfType(g,"frame")))return!1})}});const u=![...l.values()].some(h=>!cj(h.pageRotation,r)||h.isAspectRatioLocked);return{shapeSnapshots:l,selectionBounds:o,cursorHandleOffset:a,selectionRotation:r,selectedShapeIds:n,canShapesDeform:u,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:c}}_createShapeSnapshot(n){const r=this.editor.getShapePageTransform(n),s=this.editor.getShapeUtil(n);return{shape:n,bounds:this.editor.getShapeGeometry(n).bounds,pageTransform:r,pageRotation:q.Decompose(r).rotation,isAspectRatioLocked:s.isAspectRatioLocked(n)}}}I(G5,"id","resizing");const IS=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function s2(t,e){e=e%Fe;const n=Math.round(e/(De/4)),r=IS.indexOf(t);return IS[(r+n)%IS.length]}const o2=Math.PI/180;class V5 extends ie{constructor(){super(...arguments);I(this,"snapshot",{});I(this,"info",{});I(this,"markId","")}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.markId=this.editor.markHistoryStoppingPoint("rotate start");const r=SO({editor:this.editor,ids:this.editor.getSelectedShapeIds()});if(!r)return this.parent.transition("idle",this.info);this.snapshot=r;const s=this._getRotationFromPointerPosition({snapToNearestDegree:!1});hf({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:zl[this.info.handle],rotation:s+this.snapshot.initialShapesRotation})}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}update(){const n=this._getRotationFromPointerPosition({snapToNearestDegree:!1});hf({editor:this.editor,delta:n,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:zl[this.info.handle],rotation:n+this.snapshot.initialShapesRotation})}cancel(){this.editor.bailToMark(this.markId),this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("idle",this.info)}complete(){hf({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),Xe(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(),s=this.editor.getSelectionRotatedPageBounds(),{inputs:{shiftKey:o,currentPagePoint:i}}=this.editor,{initialCursorAngle:a,initialShapesRotation:l}=this.snapshot;if(!s)return l;const u=s.center.clone().rotWith(s.point,r).angle(i)-a;let h=l+u;if(o)h=Rp(h,24);else if(n&&(h=Math.round(h/o2)*o2,this.editor.getInstanceState().isCoarsePointer)){const f=Rp(h,4),p=cf(h,f);Math.abs(p)<yX(5)&&(h=f)}return h-l}}I(V5,"id","rotating");class Y5 extends ie{constructor(){super(...arguments);I(this,"hits",new Set);I(this,"size",0);I(this,"scribbleId","id");I(this,"initialSelectedShapeIds",new Set);I(this,"newlySelectedShapeIds",new Set)}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})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){this.editor.inputs.altKey?this.updateScribbleSelection(!1):this.parent.transition("brushing")}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){const{x:n,y:r}=this.editor.inputs.currentPagePoint;this.editor.scribbles.addPoint(this.scribbleId,n,r)}updateScribbleSelection(n){const{editor:r}=this,s=this.editor.getCurrentPageRenderingShapesSorted(),{inputs:{shiftKey:o,originPagePoint:i,previousPagePoint:a,currentPagePoint:l}}=this.editor,{newlySelectedShapeIds:c,initialSelectedShapeIds:u}=this;n&&this.pushPointToScribble();const h=s;let f,p,g,m;const v=0;for(let b=0,P=h.length;b<P;b++){if(f=h[b],r.isShapeOfType(f,"group")||c.has(f.id)||r.isShapeOrAncestorLocked(f)||(p=r.getShapeGeometry(f),r.isShapeOfType(f,"frame")&&p.bounds.containsPoint(r.getPointInShapeSpace(f,i))))continue;const C=r.getShapePageTransform(f);if(!p||!C)continue;const _=C.clone().invert();g=_.applyToPoint(a),m=_.applyToPoint(l);const{bounds:E}=p;if(!(E.minX-v>Math.max(g.x,m.x)||E.minY-v>Math.max(g.y,m.y)||E.maxX+v<Math.min(g.x,m.x)||E.maxY+v<Math.min(g.y,m.y))&&p.hitTestLineSegment(g,m,v)){const k=this.editor.getOutermostSelectableShape(f),D=this.editor.getShapeMask(k.id);if(D&&Pb(a,l,D)!==null&&!hr(l,D))continue;c.add(k.id)}}const y=r.getSelectedShapeIds(),S=new Set(o?[...c,...u]:[...c]);(y.length!==S.size||y.some(b=>!S.has(b)))&&this.editor.setSelectedShapes(Array.from(S))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}I(Y5,"id","scribble_brushing");var $ue=Object.create,X5=Object.defineProperty,Fue=Object.getOwnPropertyDescriptor,Nue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),q5=t=>{throw TypeError(t)},Z5=(t,e,n)=>e in t?X5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zue=t=>[,,,$ue(null)],Q5=["class","method","getter","setter","accessor","field","value","get","set"],J5=t=>t!==void 0&&typeof t!="function"?q5("Function expected"):t,Bue=(t,e,n,r,s)=>({kind:Q5[t],name:e,metadata:r,addInitializer:o=>n._?q5("Already initialized"):s.push(J5(o||null))}),Uue=(t,e)=>Z5(e,Nue("metadata"),t[3]),Hue=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Kue=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=Q5[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Fue(s,n)),y=r.length-1;y>=0;y--)l=Bue(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,J5(i)&&(v[g]=i);return v&&X5(s,n,v),s},ES=(t,e,n)=>Z5(t,typeof e!="symbol"?e+"":e,n),eF,Im;const Wue=20,Gue=100;eF=[Kn];class z1{constructor(e){this.editor=e,Hue(Im,5,this),ES(this,"prevDroppingShapeId",null),ES(this,"droppingNodeTimer",null),ES(this,"first",!0),e.disposables.add(this.dispose)}updateDroppingNode(e,n){var r;this.first&&(this.editor.setHintingShapes(e.map(s=>this.editor.findShapeAncestor(s,o=>o.type!=="group")).filter(s=>s)),this.prevDroppingShapeId=((r=this.editor.getDroppingOverShape(this.editor.inputs.originPagePoint,e))==null?void 0:r.id)??null,this.first=!1),this.droppingNodeTimer===null?this.setDragTimer(e,Wue,n):this.editor.inputs.pointerVelocity.len()>.5&&(clearTimeout(this.droppingNodeTimer),this.setDragTimer(e,Gue,n))}setDragTimer(e,n,r){this.droppingNodeTimer=this.editor.timers.setTimeout(()=>{this.editor.run(()=>{this.handleDrag(this.editor.inputs.currentPagePoint,e,r)}),this.droppingNodeTimer=null},n)}handleDrag(e,n,r){var l,c,u,h,f;n=me(n.map(p=>this.editor.getShape(p.id)));const s=((l=this.editor.getDroppingOverShape(e,n))==null?void 0:l.id)??null;if(s===this.prevDroppingShapeId){this.hintParents(n);return}const{prevDroppingShapeId:o}=this,i=o&&this.editor.getShape(o),a=s&&this.editor.getShape(s);i&&((u=(c=this.editor.getShapeUtil(i)).onDragShapesOut)==null||u.call(c,i,n)),a&&((f=(h=this.editor.getShapeUtil(a)).onDragShapesOver)==null||f.call(h,a,n)),this.hintParents(n),r==null||r(),this.prevDroppingShapeId=s}hintParents(e){const n=new Map;for(const s of e){const o=this.editor.findShapeAncestor(s,i=>i.type!=="group");o&&(n.has(o.id)||n.set(o.id,[]),n.get(o.id).push(s.id))}const r=[];for(const[s,o]of n){const i=this.editor.getShape(s);i&&QL(this.editor,i).length<o.length&&r.push(i.id)}this.editor.setHintingShapes(r)}dropShapes(e){var r,s;const{prevDroppingShapeId:n}=this;if(this.handleDrag(this.editor.inputs.currentPagePoint,e),n){const o=this.editor.getShape(n);if(!o)return;(s=(r=this.editor.getShapeUtil(o)).onDropShapesOver)==null||s.call(r,o,e)}}clear(){this.prevDroppingShapeId=null,this.droppingNodeTimer!==null&&clearTimeout(this.droppingNodeTimer),this.droppingNodeTimer=null,this.editor.setHintingShapes([]),this.first=!0}dispose(){this.clear()}}Im=zue();Kue(Im,1,"dispose",eF,z1);Uue(Im,z1);var Vue=Object.create,tF=Object.defineProperty,Yue=Object.getOwnPropertyDescriptor,nF=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),rF=t=>{throw TypeError(t)},sF=(t,e,n)=>e in t?tF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xue=t=>[,,,Vue((t==null?void 0:t[nF("metadata")])??null)],oF=["class","method","getter","setter","accessor","field","value","get","set"],iF=t=>t!==void 0&&typeof t!="function"?rF("Function expected"):t,que=(t,e,n,r,s)=>({kind:oF[t],name:e,metadata:r,addInitializer:o=>n._?rF("Already initialized"):s.push(iF(o||null))}),Zue=(t,e)=>sF(e,nF("metadata"),t[3]),Que=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Jue=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=oF[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Yue(s,n)),y=r.length-1;y>=0;y--)l=que(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,iF(i)&&(v[g]=i);return v&&tF(s,n,v),s},Ho=(t,e,n)=>sF(t,typeof e!="symbol"?e+"":e,n),aF,hw,Em;class km extends(hw=ie,aF=[Kn],hw){constructor(){super(...arguments),Que(Em,5,this),Ho(this,"info",{}),Ho(this,"selectionSnapshot",{}),Ho(this,"snapshot",{}),Ho(this,"markId",""),Ho(this,"isCloning",!1),Ho(this,"isCreating",!1),Ho(this,"dragAndDropManager",new z1(this.editor))}onCreate(e){}onEnter(e){var o;const{isCreating:n=!1,creatingMarkId:r,onCreate:s=()=>{}}=e;if(!((o=this.editor.getSelectedShapeIds())!=null&&o.length)){this.parent.transition("idle");return}if(this.info=e,this.parent.setCurrentToolIdMask(e.onInteractionEnd),this.isCreating=n,this.markId="",n)if(r)this.markId=r;else{const i=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);i&&(this.markId=i)}else this.markId=this.editor.markHistoryStoppingPoint("translating");if(this.onCreate=s,this.isCloning=!1,this.info=e,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=i2(this.editor),!this.isCreating&&this.editor.inputs.altKey){this.startCloning();return}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()}onTick({elapsed:e}){const{editor:n}=this;this.dragAndDropManager.updateDroppingNode(this.snapshot.movingShapes,this.updateParentTransforms),n.edgeScrollManager.updateEdgeScrolling(e)}onPointerMove(){this.updateShapes()}onKeyDown(){if(this.editor.inputs.altKey&&!this.isCloning){this.startCloning();return}this.updateShapes()}onKeyUp(){if(!this.editor.inputs.altKey&&this.isCloning){this.stopCloning();return}this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}startCloning(){this.isCreating||(this.isCloning=!0,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate cloning"),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=i2(this.editor),this.handleStart(),this.updateShapes())}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate"),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){var e;this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),Xe(this.editor,this.snapshot.movingShapes.map(n=>n.id)),this.handleEnd(),this.editor.getInstanceState().isToolLocked&&this.info.onInteractionEnd?this.editor.setCurrentTool(this.info.onInteractionEnd):this.isCreating?(e=this.onCreate)==null||e.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:e}=this.snapshot,n=[];e.forEach(r=>{var i;const s=this.editor.getShapeUtil(r),o=(i=s.onTranslateStart)==null?void 0:i.call(s,r);o&&n.push(o)}),n.length>0&&this.editor.updateShapes(n),this.editor.setHoveredShape(null)}handleEnd(){const{movingShapes:e}=this.snapshot;if(this.isCloning&&e.length>0){const r=x.Average(e.map(o=>this.editor.getShapePageTransform(o.id).point())),s=x.Sub(r,this.selectionSnapshot.averagePagePoint);x.IsNaN(s)||this.editor.updateInstanceState({duplicateProps:{shapeIds:e.map(o=>o.id),offset:{x:s.x,y:s.y}}})}const n=[];e.forEach(r=>{var a;const s=this.editor.getShape(r.id),o=this.editor.getShapeUtil(r),i=(a=o.onTranslateEnd)==null?void 0:a.call(o,r,s);i&&n.push(i)}),n.length>0&&this.editor.updateShapes(n)}updateShapes(){const{snapshot:e}=this;this.dragAndDropManager.updateDroppingNode(e.movingShapes,this.updateParentTransforms),ede({editor:this.editor,snapshot:e});const{movingShapes:n}=e,r=[];n.forEach(s=>{var l;const o=this.editor.getShape(s.id),i=this.editor.getShapeUtil(s),a=(l=i.onTranslate)==null?void 0:l.call(i,s,o);a&&r.push(a)}),r.length>0&&this.editor.updateShapes(r)}updateParentTransforms(){const{editor:e,snapshot:{shapeSnapshots:n}}=this;n.forEach(r=>{const s=e.getShape(r.shape.id);if(!s)return null;const o=Rn(s.parentId)?null:q.Inverse(e.getShapePageTransform(s.parentId));r.parentTransform=o})}}Em=Xue(hw);Jue(Em,1,"updateParentTransforms",aF,km);Zue(Em,km);Ho(km,"id","translating");function i2(t){var h;const e=[],n=[],r=t.getSelectedShapeIds(),s=me(r.map(f=>{const p=t.getShape(f);if(!p)return null;e.push(p);const g=t.getShapePageTransform(f),m=g.point(),v=g.rotation();n.push(m);const y=yr.isId(p.parentId)?null:q.Inverse(t.getShapePageTransform(p.parentId));return{shape:p,pagePoint:m,pageRotation:v,parentTransform:y}})),o=t.getOnlySelectedShape();let i=[];if(o)i=t.snaps.shapeBounds.getSnapPoints(o.id);else{const f=t.getSelectionPageBounds();f&&(i=f.cornersAndCenter.map((p,g)=>({id:"selection:"+g,x:p.x,y:p.y})))}let a,l;const{originPagePoint:c}=t.inputs,u=s.filter(f=>t.isShapeOfType(f.shape,"note")&&t.isPointInShape(f.shape,c));if(u.length!==0)if(u.length===1)l=u[0];else{const f=t.getCurrentPageShapesSorted();l=(h=u.map(p=>({snapshot:p,index:f.findIndex(g=>g.id===p.shape.id)})).sort((p,g)=>g.index-p.index)[0])==null?void 0:h.snapshot}return l&&(a=n5(t,l.pageRotation,l.shape.props.scale,l.shape.props.growY??0)),{averagePagePoint:x.Average(n),movingShapes:e,shapeSnapshots:s,initialPageBounds:t.getSelectionPageBounds(),initialSnapPoints:i,noteAdjacentPositions:a,noteSnapshot:l}}function ede({editor:t,snapshot:e}){const{inputs:n}=t,{noteSnapshot:r,noteAdjacentPositions:s,initialPageBounds:o,initialSnapPoints:i,shapeSnapshots:a,averagePagePoint:l}=e,c=t.getInstanceState().isGridMode,u=t.getDocumentSettings().gridSize,h=x.Sub(n.currentPagePoint,n.originPagePoint),f=t.inputs.shiftKey?Math.abs(h.x)<Math.abs(h.y)?"x":"y":null;f==="x"?h.x=0:f==="y"&&(h.y=0),t.snaps.clearIndicators();const p=t.user.getIsSnapMode()?!n.ctrlKey:n.ctrlKey;let g=!1;if(p&&t.inputs.pointerVelocity.len()<.5){const{nudge:S}=t.snaps.shapeBounds.snapTranslateShapes({dragDelta:h,initialSelectionPageBounds:o,lockedAxis:f,initialSelectionSnapPoints:i});h.add(S)}else if(r&&s){const{scale:S}=r.shape.props,b=r.pagePoint.clone().add(h).add(wm.clone().mul(S).rot(r.pageRotation));let P=e5/t.getZoomLevel(),C=new x(0,0);for(const _ of s){const E=x.Sub(b,_),k=E.len();k<P&&(g=!0,P=k,C=E)}h.sub(C)}const m=x.Add(l,h),v=t.snaps.getIndicators();c&&!n.ctrlKey&&!g&&v.length===0&&m.snapToGrid(u);const y=x.Sub(m,l);t.updateShapes(me(a.map(({shape:S,pagePoint:b,parentTransform:P})=>{const C=x.Add(b,y),_=P?q.applyToPoint(P,C):C;return{id:S.id,type:S.type,x:_.x,y:_.y}})))}class Lf extends ie{constructor(){super(...arguments);I(this,"reactor")}static children(){return[dw,F1,Oue,B5,W5,km,A5,Y5,N1,K5,j5,N5,G5,V5,H5,z5,U5,$5]}cleanUpDuplicateProps(){const n=this.editor.getSelectedShapeIds(),r=this.editor.getInstanceState();if(!r.duplicateProps)return;const s=new Set(r.duplicateProps.shapeIds);n.length===s.size&&n.every(o=>s.has(o))||this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=As("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(n){console.error(n)}})}onExit(){var n;(n=this.reactor)==null||n.call(this),this.editor.getCurrentPageState().editingShapeId&&this.editor.setEditingShape(null)}}I(Lf,"id","select"),I(Lf,"initial","idle"),I(Lf,"isLockable",!1);class lF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerDown(){this.parent.transition("pointing",this.info)}}I(lF,"id","idle");class cF extends ie{constructor(){super(...arguments);I(this,"info",{})}onEnter(n){this.info=n}onPointerUp(){this.complete()}onPointerMove(){this.editor.inputs.isDragging&&this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){const{currentScreenPoint:n}=this.editor.inputs;this.editor.inputs.altKey?this.editor.zoomOut(n,{animation:{duration:220}}):this.editor.zoomIn(n,{animation:{duration:220}}),this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}I(cF,"id","pointing");class uF extends ie{constructor(){super(...arguments);I(this,"info",{});I(this,"zoomBrush",new Z)}onEnter(n){this.info=n,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){const{inputs:{originPagePoint:n,currentPagePoint:r}}=this.editor;this.zoomBrush.setTo(Z.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 s=this.editor.inputs.currentScreenPoint;this.editor.inputs.altKey?this.editor.zoomOut(s,{animation:{duration:220}}):this.editor.zoomIn(s,{animation:{duration:220}})}else{const s=this.editor.inputs.altKey?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(n,{targetZoom:s,animation:{duration:220}})}this.parent.transition("idle",this.info)}}I(uF,"id","zoom_brushing");class $f extends ie{constructor(){super(...arguments);I(this,"info",{})}static children(){return[lF,uF,cF]}onEnter(n){this.info=n,this.parent.setCurrentToolIdMask(n.onInteractionEnd),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}}),this.parent.setCurrentToolIdMask(void 0)}onKeyDown(){this.updateCursor()}onKeyUp(n){this.updateCursor(),n.code==="KeyZ"&&this.complete()}onInterrupt(){this.complete()}complete(){this.info.onInteractionEnd&&this.info.onInteractionEnd!=="select"?this.editor.setCurrentTool(this.info.onInteractionEnd,this.info):this.parent.transition("select")}updateCursor(){this.editor.inputs.altKey?this.editor.setCursor({type:"zoom-out",rotation:0}):this.editor.setCursor({type:"zoom-in",rotation:0})}}I($f,"id","zoom"),I($f,"initial","idle"),I($f,"isLockable",!1);const tde=[Of,Df,Rf,$f,Lf];function nde(){const t=z(),e=U("follow",()=>t.getInstanceState().followingUserId,[t]);return e?d.jsx(rde,{userId:e}):null}function rde({userId:t}){const e=Lg(t);return e?d.jsx("div",{className:"tlui-following-indicator",style:{borderColor:e.color}}):null}let fw={fonts:{draw:`${ti()}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`${ti()}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`${ti()}/fonts/IBMPlexSans-Medium.woff2`,monospace:`${ti()}/fonts/IBMPlexMono-Medium.woff2`}};function dF(t){return w.useMemo(()=>t?{fonts:{...fw.fonts,...t==null?void 0:t.fonts}}:fw,[t])}const sde=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bring-forward","bring-to-front","broken","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","color","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","leading","link","lock","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];let Dc={...fw,icons:Object.fromEntries(sde.map(t=>[t,`${ti()}/icons/icon/0_merged.svg#${t}`])),translations:Object.fromEntries(Bu.map(t=>[t.locale,`${ti()}/translations/${t.locale}.json`])),embedIcons:Object.fromEntries(S1.map(t=>[t.type,`${ti()}/embed-icons/${t.type}.png`]))};function ode(t){return t?{fonts:Object.assign({...Dc.fonts},{...t==null?void 0:t.fonts}),icons:Object.assign({...Dc.icons},{...t==null?void 0:t.icons}),embedIcons:Object.assign({...Dc.embedIcons},{...t==null?void 0:t.embedIcons}),translations:Object.assign({...Dc.translations},{...t==null?void 0:t.translations})}:Dc}var B1="Popover",[hF,Dge]=Ws(B1,[sm]),kd=sm(),[ide,Di]=hF(B1),fF=t=>{const{__scopePopover:e,children:n,open:r,defaultOpen:s,onOpenChange:o,modal:i=!1}=t,a=kd(e),l=w.useRef(null),[c,u]=w.useState(!1),[h=!1,f]=ji({prop:r,defaultProp:s,onChange:o});return d.jsx(Xb,{...a,children:d.jsx(ide,{scope:e,contentId:mo(),triggerRef:l,open:h,onOpenChange:f,onOpenToggle:w.useCallback(()=>f(p=>!p),[f]),hasCustomAnchor:c,onCustomAnchorAdd:w.useCallback(()=>u(!0),[]),onCustomAnchorRemove:w.useCallback(()=>u(!1),[]),modal:i,children:n})})};fF.displayName=B1;var pF="PopoverAnchor",ade=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(pF,n),o=kd(n),{onCustomAnchorAdd:i,onCustomAnchorRemove:a}=s;return w.useEffect(()=>(i(),()=>a()),[i,a]),d.jsx(qb,{...o,...r,ref:e})});ade.displayName=pF;var gF="PopoverTrigger",mF=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(gF,n),o=kd(n),i=Qe(e,s.triggerRef),a=d.jsx(Ae.button,{type:"button","aria-haspopup":"dialog","aria-expanded":s.open,"aria-controls":s.contentId,"data-state":wF(s.open),...r,ref:i,onClick:se(t.onClick,s.onOpenToggle)});return s.hasCustomAnchor?a:d.jsx(qb,{asChild:!0,...o,children:a})});mF.displayName=gF;var U1="PopoverPortal",[lde,cde]=hF(U1,{forceMount:void 0}),yF=t=>{const{__scopePopover:e,forceMount:n,children:r,container:s}=t,o=Di(U1,e);return d.jsx(lde,{scope:e,forceMount:n,children:d.jsx(ds,{present:n||o.open,children:d.jsx(Pd,{asChild:!0,container:s,children:r})})})};yF.displayName=U1;var Bl="PopoverContent",SF=w.forwardRef((t,e)=>{const n=cde(Bl,t.__scopePopover),{forceMount:r=n.forceMount,...s}=t,o=Di(Bl,t.__scopePopover);return d.jsx(ds,{present:r||o.open,children:o.modal?d.jsx(ude,{...s,ref:e}):d.jsx(dde,{...s,ref:e})})});SF.displayName=Bl;var ude=w.forwardRef((t,e)=>{const n=Di(Bl,t.__scopePopover),r=w.useRef(null),s=Qe(e,r),o=w.useRef(!1);return w.useEffect(()=>{const i=r.current;if(i)return Zb(i)},[]),d.jsx(am,{as:fa,allowPinchZoom:!0,children:d.jsx(vF,{...t,ref:s,trapFocus:n.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(t.onCloseAutoFocus,i=>{var a;i.preventDefault(),o.current||(a=n.triggerRef.current)==null||a.focus()}),onPointerDownOutside:se(t.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;o.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(t.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})})}),dde=w.forwardRef((t,e)=>{const n=Di(Bl,t.__scopePopover),r=w.useRef(!1),s=w.useRef(!1);return d.jsx(vF,{...t,ref:e,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:o=>{var i,a;(i=t.onCloseAutoFocus)==null||i.call(t,o),o.defaultPrevented||(r.current||(a=n.triggerRef.current)==null||a.focus(),o.preventDefault()),r.current=!1,s.current=!1},onInteractOutside:o=>{var l,c;(l=t.onInteractOutside)==null||l.call(t,o),o.defaultPrevented||(r.current=!0,o.detail.originalEvent.type==="pointerdown"&&(s.current=!0));const i=o.target;((c=n.triggerRef.current)==null?void 0:c.contains(i))&&o.preventDefault(),o.detail.originalEvent.type==="focusin"&&s.current&&o.preventDefault()}})}),vF=w.forwardRef((t,e)=>{const{__scopePopover:n,trapFocus:r,onOpenAutoFocus:s,onCloseAutoFocus:o,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...h}=t,f=Di(Bl,n),p=kd(n);return Nb(),d.jsx(em,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:s,onUnmountAutoFocus:o,children:d.jsx(wd,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>f.onOpenChange(!1),children:d.jsx(I3,{"data-state":wF(f.open),role:"dialog",id:f.contentId,...p,...h,ref:e,style:{...h.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}})})})}),xF="PopoverClose",hde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=Di(xF,n);return d.jsx(Ae.button,{type:"button",...r,ref:e,onClick:se(t.onClick,()=>s.onOpenChange(!1))})});hde.displayName=xF;var fde="PopoverArrow",pde=w.forwardRef((t,e)=>{const{__scopePopover:n,...r}=t,s=kd(n);return d.jsx(E3,{...s,...r,ref:e})});pde.displayName=fde;function wF(t){return t?"open":"closed"}var H1=fF,K1=mF,W1=yF,G1=SF;function V1({id:t,children:e,onOpenChange:n,open:r}){const[s,o]=Mo(t,n);return d.jsx(H1,{onOpenChange:o,open:r||s,children:d.jsx("div",{className:"tlui-popover",children:e})})}function Y1({children:t}){return d.jsx(K1,{asChild:!0,dir:"ltr",children:t})}function X1({side:t,children:e,align:n="center",sideOffset:r=8,alignOffset:s=0,disableEscapeKeyDown:o=!1}){const i=Tt();return d.jsx(W1,{container:i,children:d.jsx(G1,{className:"tlui-popover__content",side:t,sideOffset:r,align:n,alignOffset:s,dir:"ltr",onEscapeKeyDown:a=>o&&a.preventDefault(),children:e})})}function gde(t){return t.getSelectedShapeIds().map(r=>t.getShape(r)).filter(r=>{if(!r)return!1;if(t.isShapeOfType(r,"arrow")){const s=Un(t,r);if(s.start||s.end)return!1}return!0})}const bF=()=>{const t=z();return U("threeStackableItems",()=>gde(t).length>2,[t])},Ao=()=>{const t=z();return U("isInSelectState",()=>t.isIn("select"),[t])},PF=()=>{const t=z();return U("allow group",()=>{const e=t.getSelectedShapes();if(e.length<2)return!1;for(const n of e)if(t.isShapeOfType(n,"arrow")){const r=Un(t,n);if(r.start&&!e.some(s=>s.id===r.start.toId)||r.end&&!e.some(s=>s.id===r.end.toId))return!1}return!0},[t])},CF=()=>{const t=z();return U("allowUngroup",()=>t.getSelectedShapeIds().some(e=>{var n;return((n=t.getShape(e))==null?void 0:n.type)==="group"}),[t])},mde=typeof window<"u"&&"navigator"in window&&!!navigator.clipboard&&!!navigator.clipboard.read;function _F(t,e){const n=z();return U("selectedShapes",()=>n.getSelectedShapes().length>=t,[n,t,e])}function jn(t,e){const n=z();return U("selectedShapes",()=>{const r=n.getSelectedShapes().filter(s=>!n.isShapeOrAncestorLocked(s)).length;return t===void 0?r:r>=t},[n])}function yde(){const t=z();return U("showAutoSizeToggle",()=>{const e=t.getSelectedShapes();return e.length===1&&t.isShapeOfType(e[0],"text")&&e[0].props.autoSize===!1},[t])}function IF(){const t=z();return U("hasLinkShapeSelected",()=>{const e=t.getOnlySelectedShape();return!!(e&&e.type!=="embed"&&"url"in e.props&&!e.isLocked)},[t])}function Sde(){const t=z();return U("onlyFlippableShape",()=>{const e=t.getOnlySelectedShape();return e&&(t.isShapeOfType(e,"group")||t.isShapeOfType(e,"image")||t.isShapeOfType(e,"arrow")||t.isShapeOfType(e,"line")||t.isShapeOfType(e,"draw"))},[t])}function EF(){const t=z();return U("useCanRedo",()=>t.getCanRedo(),[t])}function kF(){const t=z();return U("useCanUndo",()=>t.getCanUndo(),[t])}function vde(){return d.jsxs(d.Fragment,{children:[d.jsx(xde,{}),d.jsx(wde,{}),d.jsx(bde,{}),d.jsx(Pde,{}),d.jsx(Cde,{}),d.jsx(Ede,{}),d.jsx(kde,{}),d.jsx(Tde,{})]})}function xde(){const t=jn(2),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"align-left",disabled:!n}),d.jsx(W,{actionId:"align-center-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-right",disabled:!n}),d.jsx(W,{actionId:"stretch-horizontal",disabled:!n}),d.jsx(W,{actionId:"align-top",disabled:!n}),d.jsx(W,{actionId:"align-center-vertical",disabled:!n}),d.jsx(W,{actionId:"align-bottom",disabled:!n}),d.jsx(W,{actionId:"stretch-vertical",disabled:!n})]})}function wde(){const t=jn(3),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"distribute-horizontal",disabled:!n}),d.jsx(W,{actionId:"distribute-vertical",disabled:!n})]})}function bde(){const t=bF(),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"stack-horizontal",disabled:!n}),d.jsx(W,{actionId:"stack-vertical",disabled:!n})]})}function Pde(){const t=jn(1),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"send-to-back",disabled:!n}),d.jsx(W,{actionId:"send-backward",disabled:!n}),d.jsx(W,{actionId:"bring-forward",disabled:!n}),d.jsx(W,{actionId:"bring-to-front",disabled:!n})]})}function Cde(){return An()<St.TABLET_SM?d.jsx(_de,{}):d.jsx(Ide,{})}function _de(){const t=z(),e=U("zoom is 1",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",disabled:e})}function Ide(){const t=jn(1),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"rotate-ccw",disabled:!n})}function Ede(){const t=jn(1),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"rotate-cw",disabled:!n})}function kde(){const t=IF(),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"edit-link",disabled:!n})}function Tde(){const t=PF(),e=CF();return t?d.jsx(a2,{}):e?d.jsx(Mde,{}):d.jsx(a2,{})}function a2(){const t=jn(2),e=Ao(),n=t&&e;return d.jsx(W,{actionId:"group",disabled:!n})}function Mde(){return d.jsx(W,{actionId:"ungroup"})}const Ade=w.memo(function({children:e}){const n=Ee(),r=An(),s=wr(),o=w.useRef(null);Ai(o);const i=z(),a=U("should display quick actions when in readonly",()=>i.isInAny("hand","zoom"),[i]),l=e??d.jsx(vde,{});if(!(s&&!a))return d.jsxs(V1,{id:"actions-menu",children:[d.jsx(Y1,{children:d.jsx(ue,{type:"icon","data-testid":"actions-menu.button",title:n("actions-menu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(X1,{side:r>=St.TABLET?"bottom":"top",sideOffset:6,children:d.jsx("div",{ref:o,className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:d.jsx(Fr,{type:"icons",sourceId:"actions-menu",children:l})})})]})});function TF(){return yde()?d.jsx(W,{actionId:"toggle-auto-size"}):null}function MF(){return IF()?d.jsx(W,{actionId:"edit-link"}):null}function jde(){return jn(1)?d.jsx(W,{actionId:"duplicate"}):null}function AF(){const t=z();return U("should display flatten option",()=>{if(t.getSelectedShapeIds().length===0)return!1;const r=t.getOnlySelectedShape();return!(r&&t.isShapeOfType(r,"image"))},[t])?d.jsx(W,{actionId:"flatten-to-image"}):null}function jF(){return PF()?d.jsx(W,{actionId:"group"}):null}function OF(){return CF()?d.jsx(W,{actionId:"ungroup"}):null}function DF(){const t=z();return U("allow unframe",()=>{const n=t.getSelectedShapes();return n.length===0?!1:n.every(r=>t.isShapeOfType(r,"frame"))},[t])?d.jsx(W,{actionId:"remove-frame"}):null}function RF(){const t=z();return U("allow fit frame to content",()=>{const n=t.getOnlySelectedShape();return n?t.isShapeOfType(n,"frame")&&t.getSortedChildIdsForParent(n).length>0:!1},[t])?d.jsx(W,{actionId:"fit-frame-to-content"}):null}function LF(){const t=z();return U("selected shapes",()=>t.getSelectedShapes().length>0,[t])?d.jsx(W,{actionId:"toggle-lock"}):null}function q1(){const t=z(),e=U("isTransparentBg",()=>!t.getInstanceState().exportBackground,[t]);return d.jsx(fs,{actionId:"toggle-transparent",checked:e,toggle:!0})}function Ode(){const t=z(),e=U("any shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"unlock-all",disabled:!e})}function $F(){const t=z(),e=U("zoomed to 100",()=>t.getZoomLevel()===1,[t]);return d.jsx(W,{actionId:"zoom-to-100",noClose:!0,disabled:e})}function FF(){const t=z(),e=U("has shapes",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"zoom-to-fit",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function NF(){const t=z(),e=U("has shapes",()=>t.getSelectedShapeIds().length>0,[t]);return d.jsx(W,{actionId:"zoom-to-selection",disabled:!e,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function zF(){return d.jsxs(ve,{id:"clipboard",children:[d.jsx(Rde,{}),d.jsx(Lde,{}),d.jsx($de,{}),d.jsx(jde,{}),d.jsx(Fde,{})]})}function Dde(){var n;const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsxs(Jn,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!e,children:[d.jsxs(ve,{id:"copy-as-group",children:[d.jsx(W,{actionId:"copy-as-svg"}),!!((n=window.navigator.clipboard)!=null&&n.write)&&d.jsx(W,{actionId:"copy-as-png"}),d.jsx(W,{actionId:"copy-as-json"})]}),d.jsx(ve,{id:"copy-as-bg",children:d.jsx(q1,{})})]})}function Rde(){const t=jn(1);return d.jsx(W,{actionId:"cut",disabled:!t})}function Lde(){const t=_F(1);return d.jsx(W,{actionId:"copy",disabled:!t})}function $de(){const t=mde;return d.jsx(W,{actionId:"paste",disabled:!t})}function BF(){const t=z();return U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t])?d.jsxs(ve,{id:"conversions",children:[d.jsx(Dde,{}),d.jsxs(Jn,{id:"export-as",label:"context-menu.export-as",size:"small",children:[d.jsxs(ve,{id:"export-as-group",children:[d.jsx(W,{actionId:"export-as-svg"}),d.jsx(W,{actionId:"export-as-png"}),d.jsx(W,{actionId:"export-as-json"})]}),d.jsx(ve,{id:"export-as-bg",children:d.jsx(q1,{})})]})]}):null}function UF(){const t=z(),e=U("atLeastOneShapeOnPage",()=>t.getCurrentPageShapeIds().size>0,[t]);return d.jsx(W,{actionId:"select-all",disabled:!e})}function Fde(){const t=jn(1);return d.jsx(W,{actionId:"delete",disabled:!t})}function Nde(){const t=wr();return!_F(1)||t?null:d.jsxs(Jn,{id:"edit",label:"context-menu.edit",size:"small",children:[d.jsx(jF,{}),d.jsx(OF,{}),d.jsx(AF,{}),d.jsx(MF,{}),d.jsx(RF,{}),d.jsx(DF,{}),d.jsx(KF,{}),d.jsx(HF,{}),d.jsx(TF,{}),d.jsx(LF,{})]})}function zde(){const t=jn(2),e=Sde();return wr()||!(t||e)?null:d.jsxs(Jn,{id:"arrange",label:"context-menu.arrange",size:"small",children:[t&&d.jsxs(ve,{id:"align",children:[d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"})]}),d.jsx(Bde,{}),t&&d.jsxs(ve,{id:"stretch",children:[d.jsx(W,{actionId:"stretch-horizontal"}),d.jsx(W,{actionId:"stretch-vertical"})]}),(t||e)&&d.jsxs(ve,{id:"flip",children:[d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"})]}),d.jsx(Ude,{})]})}function Bde(){return jn(3)?d.jsxs(ve,{id:"distribute",children:[d.jsx(W,{actionId:"distribute-horizontal"}),d.jsx(W,{actionId:"distribute-vertical"})]}):null}function Ude(){const t=jn(2),e=bF();return t?d.jsxs(ve,{id:"order",children:[d.jsx(W,{actionId:"pack"}),e&&d.jsx(W,{actionId:"stack-horizontal"}),e&&d.jsx(W,{actionId:"stack-vertical"})]}):null}function Hde(){const t=wr(),e=jn(1);return t||!e?null:d.jsx(Jn,{id:"reorder",label:"context-menu.reorder",size:"small",children:d.jsxs(ve,{id:"reorder",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"})]})})}function Kde(){const t=z(),e=U("pages",()=>t.getPages(),[t]),n=U("current page id",()=>t.getCurrentPageId(),[t]),{addToast:r}=To(),s=Jt(),o=wr();return!jn(1)||o?null:d.jsxs(Jn,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[d.jsx(ve,{id:"pages",children:e.map(a=>d.jsx(Kt,{id:a.id,disabled:n===a.id,label:a.name.length>30?`${a.name.slice(0,30)}…`:a.name,onSelect:()=>{t.markHistoryStoppingPoint("move_shapes_to_page"),t.moveShapesToPage(t.getSelectedShapeIds(),a.id);const l=t.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{t.markHistoryStoppingPoint("change-page"),t.setCurrentPage(n)}}]}),s("move-to-page",{source:"context-menu"})}},a.id))}),d.jsx(ve,{id:"new-page",children:d.jsx(W,{actionId:"move-to-new-page"})})]})}function HF(){const t=z();return U("oneEmbedSelected",()=>{const n=t.getOnlySelectedShape();return n?!!(t.isShapeOfType(n,"embed")&&n.props.url&&!t.isShapeOrAncestorLocked(n)):!1},[t])?d.jsx(W,{actionId:"convert-to-bookmark"}):null}function KF(){const t=z(),e=v1();return U("oneEmbeddableBookmarkSelected",()=>{const r=t.getOnlySelectedShape();return r?!!(t.isShapeOfType(r,"bookmark")&&r.props.url&&e(r.props.url)&&!t.isShapeOrAncestorLocked(r)):!1},[t])?d.jsx(W,{actionId:"convert-to-embed"}):null}function Wde(){const t=z(),e=U("isSnapMode",()=>t.user.getIsSnapMode(),[t]);return d.jsx(fs,{actionId:"toggle-snap-mode",checked:e})}function Gde(){const t=z(),e=U("isToolLock",()=>t.getInstanceState().isToolLocked,[t]);return d.jsx(fs,{actionId:"toggle-tool-lock",checked:e})}function Vde(){const t=z(),e=U("isGridMode",()=>t.getInstanceState().isGridMode,[t]);return d.jsx(fs,{actionId:"toggle-grid",checked:e})}function Yde(){const t=z(),e=U("isWrapMode",()=>t.user.getIsWrapMode(),[t]);return d.jsx(fs,{actionId:"toggle-wrap-mode",checked:e})}function Xde(){const t=z(),e=U("isFocusMode",()=>t.getInstanceState().isFocusMode,[t]);return d.jsx(fs,{actionId:"toggle-focus-mode",checked:e})}function qde(){const t=z(),e=U("edgeScrollSpeed",()=>t.user.getEdgeScrollSpeed(),[t]);return d.jsx(fs,{actionId:"toggle-edge-scrolling",checked:e===1})}function Zde(){const t=z(),e=U("animationSpeed",()=>t.user.getAnimationSpeed(),[t]);return d.jsx(fs,{actionId:"toggle-reduce-motion",checked:e===0})}function Qde(){const t=z(),e=U("isDebugMode",()=>t.getInstanceState().isDebugMode,[t]);return d.jsx(fs,{actionId:"toggle-debug-mode",checked:e})}function Jde(){const t=z(),e=U("dynamic resize",()=>t.user.getIsDynamicResizeMode(),[t]);return d.jsx(fs,{actionId:"toggle-dynamic-size-mode",checked:e})}function ehe(){const t=z(),e=U("paste at cursor",()=>t.user.getIsPasteAtCursorMode(),[t]);return d.jsx(fs,{actionId:"toggle-paste-at-cursor",checked:e})}function the(){const t=z();return U("show cursor chat",()=>t.getCurrentToolId()==="select"&&!t.getInstanceState().isCoarsePointer,[t])?d.jsx(W,{actionId:"open-cursor-chat"}):null}function nhe(){const t=z(),e=gm(),n=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]),r=U("isSinglePageMode",()=>t.options.maxPages<=1,[t]);return n?d.jsxs(d.Fragment,{children:[e&&d.jsx(the,{}),d.jsxs(ve,{id:"modify",children:[d.jsx(Nde,{}),d.jsx(zde,{}),d.jsx(Hde,{}),!r&&d.jsx(Kde,{})]}),d.jsx(zF,{}),d.jsx(BF,{}),d.jsx(ve,{id:"select-all",children:d.jsx(UF,{})})]}):null}const rhe=w.memo(function({children:e,disabled:n=!1}){const r=z(),{Canvas:s}=st(),o=w.useCallback(u=>{if(u){if(r.getInstanceState().isCoarsePointer){const h=r.getSelectedShapes(),{inputs:{currentPagePoint:f}}=r,p=r.getShapesAtPoint(f);if(!r.getSelectedShapes().length||!p.some(g=>h.includes(g))){const g=p.filter(m=>r.isShapeOrAncestorLocked(m));g.length&&r.select(...g.map(m=>m.id))}}}else{const h=r.getOnlySelectedShape();h&&r.isShapeOrAncestorLocked(h)&&r.setSelectedShapes([])}},[r]),i=Tt(),[a,l]=Mo("context menu",o),c=e??d.jsx(nhe,{});return d.jsxs(Vse,{dir:"ltr",onOpenChange:l,modal:!1,children:[d.jsx(Yse,{onContextMenu:void 0,dir:"ltr",disabled:n,children:s?d.jsx(s,{}):null}),a&&d.jsx(Xse,{container:i,children:d.jsx(qse,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:xe,children:d.jsx(Fr,{type:"context-menu",sourceId:"context-menu",children:c})})})]})}),she=2e3,ohe=5e3,ihe=Zt(function(){const e=z(),{isChatting:n,chatMessage:r}=e.getInstanceState(),s=w.useRef(-1),[o,i]=w.useState("");return w.useEffect(()=>{if(!n&&r||n){const l=n?ohe:she;s.current=e.timers.setTimeout(()=>{e.updateInstanceState({chatMessage:"",isChatting:!1}),i(""),e.focus()},l)}return()=>{clearTimeout(s.current)}},[e,r,n]),n?d.jsx(lhe,{value:o,setValue:i,chatMessage:r}):r.trim()?d.jsx(ahe,{chatMessage:r}):null});function WF(t){const e=z();w.useLayoutEffect(()=>{var i;if(!t.current)return;const{x:r,y:s}=e.inputs.currentScreenPoint;(i=t.current)==null||i.style.setProperty("transform",`translate(${r}px, ${s}px)`);function o(a){var u;const{minX:l,minY:c}=e.getViewportScreenBounds();(u=t.current)==null||u.style.setProperty("transform",`translate(${a.clientX-l}px, ${a.clientY-c}px)`)}return window.addEventListener("pointermove",o),()=>{window.removeEventListener("pointermove",o)}},[t,e])}const ahe=({chatMessage:t})=>{const e=z(),n=w.useRef(null);return WF(n),d.jsx("div",{ref:n,className:"tl-cursor-chat tl-cursor-chat__bubble",style:{backgroundColor:e.user.getColor()},children:t})},lhe=Zt(function({chatMessage:e,value:n,setValue:r}){const s=z(),o=Ee(),i=w.useRef(null),a=e||o("cursor-chat.type-to-chat");WF(i),w.useLayoutEffect(()=>{const f=i.current;if(!f)return;const p=s.textMeasure.measureText(n||a,{fontFamily:"var(--font-body)",fontSize:12,fontWeight:"500",fontStyle:"normal",maxWidth:null,lineHeight:1,padding:"6px"});f.style.setProperty("width",p.w+"px")},[s,n,a]),w.useLayoutEffect(()=>{const f=s.timers.requestAnimationFrame(()=>{var p;(p=i.current)==null||p.focus()});return()=>{cancelAnimationFrame(f)}},[s]);const l=w.useCallback(()=>{s.updateInstanceState({isChatting:!1}),s.focus()},[s]),c=w.useCallback(f=>{const{value:p}=f.target;r(p.slice(0,64)),s.updateInstanceState({chatMessage:p})},[s,r]),u=w.useCallback(f=>{const p=i.current;if(!p)return;const{value:g}=p;switch(f.key){case"Enter":{if(xe(f),f.stopPropagation(),!g){l();return}r("");break}case"Escape":{xe(f),f.stopPropagation(),l();break}}},[l,r]),h=w.useCallback(f=>{f.stopPropagation()},[]);return d.jsx("input",{ref:i,className:"tl-cursor-chat",style:{backgroundColor:s.user.getColor()},onBlur:l,onChange:c,onKeyDown:u,onPaste:h,value:n,placeholder:a,spellCheck:!1})});function pw({checked:t}){return d.jsx(zs,{icon:t?"check":"none",className:"tlui-button__icon",small:!0})}function che(){const t=z(),{addToast:e}=To(),{addDialog:n}=Ed(),[r,s]=ke.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"items",children:[d.jsx(Kt,{id:"add-toast",onSelect:()=>{e({id:ze(),title:"Something good happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,severity:"success"}),e({id:ze(),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:()=>{}}]}),e({id:ze(),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:()=>{}}]}),e({id:ze(),title:"Something bad happened",severity:"error",keepOpen:!0})},label:"Show toast"}),d.jsx(Kt,{id:"show-dialog",label:"Show dialog",onSelect:()=>{n({component:({onClose:o})=>d.jsx(hhe,{displayDontShowAgain:!0,onCancel:()=>o(),onContinue:()=>o()}),onClose:()=>{}})}}),d.jsx(Kt,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>fhe(t,100)}),d.jsx(Kt,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{var a;const o=t.getSelectedShapes(),i=o.length===0?t.getRenderingShapes():o;window.alert(`Shapes ${i.length}, DOM nodes:${(a=document.querySelector(".tl-shapes").querySelectorAll("*"))==null?void 0:a.length}`)}}),(()=>{if(r)throw Error("oh no!");return null})(),d.jsx(Kt,{id:"throw-error",onSelect:()=>s(!0),label:"Throw error"}),d.jsx(Kt,{id:"hard-reset",onSelect:jj,label:"Hard reset"})]}),d.jsxs(ve,{id:"flags",children:[d.jsx(uhe,{}),d.jsx(dhe,{})]})]})}function uhe(){const t=Object.values(wt);return t.length?d.jsx(Jn,{id:"debug flags",label:"Debug Flags",children:d.jsx(ve,{id:"debug flags",children:t.map(e=>d.jsx(GF,{flag:e},e.name))})}):null}function dhe(){const t=Object.values(PX);return t.length?d.jsx(Jn,{id:"feature flags",label:"Feature Flags",children:d.jsx(ve,{id:"feature flags",children:t.map(e=>d.jsx(GF,{flag:e},e.name))})}):null}function hhe({title:t="title",body:e="hello hello hello",cancel:n="Cancel",confirm:r="Continue",displayDontShowAgain:s=!1,onCancel:o,onContinue:i}){const[a,l]=ke.useState(!1);return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{children:[d.jsx(hm,{children:t}),d.jsx(fm,{})]}),d.jsx(Yu,{style:{maxWidth:350},children:e}),d.jsxs(y1,{className:"tlui-dialog__footer__actions",children:[s&&d.jsxs(ue,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[d.jsx(pw,{checked:a}),d.jsx(bt,{children:"Don’t show again"})]}),d.jsx(ue,{type:"normal",onClick:o,children:d.jsx(bt,{children:n})}),d.jsx(ue,{type:"primary",onClick:async()=>i(),children:d.jsx(bt,{children:r})})]})]})}const GF=Zt(function({flag:e,onChange:n}){const r=e.get();return d.jsx(vm,{id:e.name,title:e.name,label:e.name.replace(/([a-z0-9])([A-Z])/g,s=>`${s[0]} ${s[1].toLowerCase()}`).replace(/^[a-z]/,s=>s.toUpperCase()),checked:r,onSelect:()=>{e.set(!r),n==null||n(!r)}})});let l2=0;function fhe(t,e){const n=Array(e),r=Math.floor(Math.sqrt(e));for(let s=0;s<e;s++)l2++,n[s]={id:Ke("box"+l2),type:"geo",x:s%r*132,y:Math.floor(s/r)*132};t.run(()=>{t.createShapes(n).setSelectedShapes(n.map(s=>s.id))})}function phe({children:t}){const e=t??d.jsx(che,{});return d.jsxs(ma,{id:"debug",children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon",title:"Debug menu",children:d.jsx(be,{icon:"dots-horizontal"})})}),d.jsx(Sa,{side:"top",align:"end",alignOffset:0,children:d.jsx(Fr,{type:"menu",sourceId:"debug-panel",children:e})})]})}const ghe=w.memo(function(){const{DebugMenu:e}=Ri(),n=w.useRef(null);return Ai(n),d.jsxs("div",{ref:n,className:"tlui-debug-panel",children:[d.jsx(yhe,{}),d.jsx(She,{}),e&&d.jsx(e,{})]})});function mhe(t=!0){const[e,n]=w.useState(0),r=z();w.useEffect(()=>{if(!t)return;const s=()=>n(o=>o+1);return r.on("tick",s),()=>{r.off("tick",s)}},[r,t])}const yhe=Zt(function(){mhe();const e=z(),n=e.getPath(),r=e.getHoveredShape(),s=e.getOnlySelectedShape(),o=n==="select.idle"||!n.includes("select.")?r:s,i=o&&n.includes("select.")?` / ${o.type||""}${"geo"in o.props?" / "+o.props.geo:""} / [${x.ToInt(e.getPointInShapeSpace(o,e.inputs.currentPagePoint))}]`:"",a=n.startsWith("select.")&&!n.includes(".idle")?` / [${x.ToInt(e.inputs.originPagePoint)}] → [${x.ToInt(e.inputs.currentPagePoint)}] = ${x.Dist(e.inputs.originPagePoint,e.inputs.currentPagePoint).toFixed(0)}`:"";return d.jsx("div",{className:"tlui-debug-panel__current-state",children:`${n}${i}${a}`})});function She(){const t=z(),e=U("show_fps",()=>wt.showFps.get(),[wt]),n=w.useRef(null);return w.useEffect(()=>{if(!e)return;const r=250;let s=0,o=-1,i=performance.now(),a=0,l=0,c=!1;function u(){if(l++,a=performance.now()-i,a>r){const h=Math.round(l*(r/a)*(1e3/r));h>s&&(s=h);const f=s*.75;(h<f&&!c||h>=f&&c)&&(c=!c),n.current.innerHTML=`FPS ${h.toString()}`,n.current.className="tlui-debug-panel__fps"+(c?" tlui-debug-panel__fps__slow":""),a-=r,l=0,i=performance.now()}o=t.timers.requestAnimationFrame(u)}return u(),()=>{cancelAnimationFrame(o)}},[e,t]),e?d.jsx("div",{ref:n}):null}const vhe=w.memo(function(){const e=An(),n=w.useRef(null);Ai(n);const{MainMenu:r,QuickActions:s,ActionsMenu:o,PageMenu:i}=Ri(),a=z(),l=U("isSinglePageMode",()=>a.options.maxPages<=1,[a]),c=a.options.actionShortcutsLocation==="menu"?!0:a.options.actionShortcutsLocation==="toolbar"?!1:e>=St.TABLET;return!r&&!i&&!c?null:d.jsx("div",{ref:n,className:"tlui-menu-zone",children:d.jsxs("div",{className:"tlui-buttons__horizontal",children:[r&&d.jsx(r,{}),i&&!l&&d.jsx(i,{}),c?d.jsxs(d.Fragment,{children:[s&&d.jsx(s,{}),o&&d.jsx(o,{})]}):null]})})});function xhe(){const t=z(),e=ka(),[n,r]=w.useState(!1),s=w.useRef(!1);return ui("toggle showback to content",()=>{const o=s.current,i=t.getCurrentPageShapeIds();let a=!1;i.size&&(a=i.size===t.getCulledShapes().size),o!==a&&(r(a),s.current=a)},[t]),n?d.jsx(W,{actionId:"back-to-content",onSelect:()=>{e["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function whe(){const t=z();return U("is pen mode",()=>t.getInstanceState().isPenMode,[t])?d.jsx(W,{actionId:"exit-pen-mode"}):null}function bhe(){const t=z(),e=ka();return U("is following user",()=>!!t.getInstanceState().followingUserId,[t])?d.jsx(Kt,{...e["stop-following"]}):null}function Phe(){return d.jsxs(d.Fragment,{children:[d.jsx(whe,{}),d.jsx(xhe,{}),d.jsx(bhe,{})]})}function Che({children:t}){const e=t??d.jsx(Phe,{});return d.jsx("div",{className:"tlui-helper-buttons",children:d.jsx(Fr,{type:"helper-buttons",sourceId:"helper-buttons",children:e})})}function _he(){const t=gm();return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{label:"shortcuts-dialog.tools",id:"tools",children:[d.jsx(W,{actionId:"toggle-tool-lock"}),d.jsx(W,{actionId:"insert-media"}),d.jsx(Ln,{toolId:"select"}),d.jsx(Ln,{toolId:"draw"}),d.jsx(Ln,{toolId:"eraser"}),d.jsx(Ln,{toolId:"hand"}),d.jsx(Ln,{toolId:"rectangle"}),d.jsx(Ln,{toolId:"ellipse"}),d.jsx(Ln,{toolId:"arrow"}),d.jsx(Ln,{toolId:"line"}),d.jsx(Ln,{toolId:"text"}),d.jsx(Ln,{toolId:"frame"}),d.jsx(Ln,{toolId:"note"}),d.jsx(Ln,{toolId:"laser"}),d.jsx(Kt,{id:"pointer-down",label:"tool.pointer-down",kbd:",",onSelect:()=>{}})]}),d.jsxs(ve,{label:"shortcuts-dialog.preferences",id:"preferences",children:[d.jsx(W,{actionId:"toggle-dark-mode"}),d.jsx(W,{actionId:"toggle-focus-mode"}),d.jsx(W,{actionId:"toggle-grid"})]}),d.jsxs(ve,{label:"shortcuts-dialog.edit",id:"edit",children:[d.jsx(W,{actionId:"undo"}),d.jsx(W,{actionId:"redo"}),d.jsx(W,{actionId:"cut"}),d.jsx(W,{actionId:"copy"}),d.jsx(W,{actionId:"paste"}),d.jsx(W,{actionId:"select-all"}),d.jsx(W,{actionId:"delete"}),d.jsx(W,{actionId:"duplicate"})]}),d.jsxs(ve,{label:"shortcuts-dialog.view",id:"view",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx(W,{actionId:"zoom-to-100"}),d.jsx(W,{actionId:"zoom-to-fit"}),d.jsx(W,{actionId:"zoom-to-selection"})]}),d.jsxs(ve,{label:"shortcuts-dialog.transform",id:"transform",children:[d.jsx(W,{actionId:"bring-to-front"}),d.jsx(W,{actionId:"bring-forward"}),d.jsx(W,{actionId:"send-backward"}),d.jsx(W,{actionId:"send-to-back"}),d.jsx(W,{actionId:"group"}),d.jsx(W,{actionId:"ungroup"}),d.jsx(W,{actionId:"flip-horizontal"}),d.jsx(W,{actionId:"flip-vertical"}),d.jsx(W,{actionId:"align-top"}),d.jsx(W,{actionId:"align-center-vertical"}),d.jsx(W,{actionId:"align-bottom"}),d.jsx(W,{actionId:"align-left"}),d.jsx(W,{actionId:"align-center-horizontal"}),d.jsx(W,{actionId:"align-right"})]}),t&&d.jsx(ve,{label:"shortcuts-dialog.collaboration",id:"collaboration",children:d.jsx(W,{actionId:"open-cursor-chat"})})]})}const Ihe=w.memo(function({children:e}){const n=Ee(),r=An(),s=e??d.jsx(_he,{});return d.jsxs(d.Fragment,{children:[d.jsxs(dm,{className:"tlui-shortcuts-dialog__header",children:[d.jsx(hm,{children:n("shortcuts-dialog.title")}),d.jsx(fm,{})]}),d.jsx(Yu,{className:ce("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=St.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=St.TABLET}),children:d.jsx(Fr,{type:"keyboard-shortcuts",sourceId:"kbd",children:s})}),d.jsx("div",{className:"tlui-dialog__scrim"})]})});function VF(){const t=Ti(),e=Jt(),n=U("locale",()=>t==null?void 0:t.user.getLocale(),[t]);return t?d.jsx(Jn,{id:"help menu language",label:"menu.language",children:d.jsx(ve,{id:"languages",children:Bu.map(({locale:r,label:s})=>d.jsx(vm,{id:`language-${r}`,title:r,label:s,checked:r===n,readonlyOk:!0,onSelect:()=>{t.user.updateUserPreferences({locale:r}),e("change-language",{source:"menu",locale:r})}},r))})}):null}function Ehe(){return d.jsxs(d.Fragment,{children:[d.jsx(VF,{}),d.jsx(YF,{})]})}function YF(){const{KeyboardShortcutsDialog:t}=Ri(),{addDialog:e}=Ed(),n=w.useCallback(()=>{t&&e({component:t})},[e,t]);return t?d.jsx(Kt,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:n}):null}function khe(){return d.jsxs(d.Fragment,{children:[d.jsxs(ve,{id:"basic",children:[d.jsx(Mhe,{}),d.jsx(Dhe,{}),d.jsx(The,{}),d.jsx(Rhe,{})]}),d.jsx(Lhe,{})]})}function The(){return d.jsxs(Jn,{id:"export-all-as",label:"context-menu.export-all-as",size:"small",children:[d.jsxs(ve,{id:"export-all-as-group",children:[d.jsx(W,{actionId:"export-all-as-svg"}),d.jsx(W,{actionId:"export-all-as-png"}),d.jsx(W,{actionId:"export-all-as-json"})]}),d.jsx(ve,{id:"export-all-as-bg",children:d.jsx(q1,{})})]})}function Mhe(){const t=z(),e=U("isSelectToolActive",()=>t.getCurrentToolId()==="select",[t]);return d.jsxs(Jn,{id:"edit",label:"menu.edit",disabled:!e,children:[d.jsx(Ohe,{}),d.jsx(zF,{}),d.jsx(BF,{}),d.jsx(Ahe,{}),d.jsx(jhe,{}),d.jsx(ve,{id:"select-all",children:d.jsx(UF,{})})]})}function Ahe(){return d.jsxs(ve,{id:"misc",children:[d.jsx(jF,{}),d.jsx(OF,{}),d.jsx(MF,{}),d.jsx(TF,{}),d.jsx(DF,{}),d.jsx(RF,{}),d.jsx(KF,{}),d.jsx(HF,{}),d.jsx(AF,{})]})}function jhe(){return d.jsxs(ve,{id:"lock",children:[d.jsx(LF,{}),d.jsx(Ode,{})]})}function Ohe(){const t=kF(),e=EF();return d.jsxs(ve,{id:"undo-redo",children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}function Dhe(){return d.jsx(Jn,{id:"view",label:"menu.view",children:d.jsxs(ve,{id:"view-actions",children:[d.jsx(W,{actionId:"zoom-in"}),d.jsx(W,{actionId:"zoom-out"}),d.jsx($F,{}),d.jsx(FF,{}),d.jsx(NF,{})]})})}function Rhe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"insert-embed"}),d.jsx(W,{actionId:"insert-media"})]})}function Lhe(){return d.jsxs(ve,{id:"preferences",children:[d.jsxs(Jn,{id:"preferences",label:"menu.preferences",children:[d.jsxs(ve,{id:"preferences-actions",children:[d.jsx(Wde,{}),d.jsx(Gde,{}),d.jsx(Vde,{}),d.jsx(Yde,{}),d.jsx(Xde,{}),d.jsx(qde,{}),d.jsx(Zde,{}),d.jsx(Jde,{}),d.jsx(ehe,{}),d.jsx(Qde,{})]}),d.jsx(ve,{id:"color-scheme",children:d.jsx(Uae,{})})]}),d.jsx(VF,{}),d.jsx(YF,{})]})}const $he=w.memo(function({children:e}){const n=Tt(),[r,s]=Mo("main menu"),o=Ee(),i=e??d.jsx(khe,{});return d.jsxs(c1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(u1,{asChild:!0,dir:"ltr",children:d.jsx(ue,{type:"icon","data-testid":"main-menu.button",title:o("menu.title"),children:d.jsx(be,{icon:"menu",small:!0})})}),d.jsx(um,{container:n,children:d.jsx(d1,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:d.jsx(Fr,{type:"menu",sourceId:"main-menu",children:i})})})]})}),kS={};function Rc(t){if(kS[t])return kS[t];const n=document.createElement("canvas").getContext("2d");n.fillStyle=t,n.fillRect(0,0,1,1);const[r,s,o,i]=n.getImageData(0,0,1,1).data,a=new Float32Array([r/255,s/255,o/255,i/255]);return kS[t]=a,a}const Ff=10,XF=4*6*Ff+12+4*12;function Ka(t,{center:e,radius:n,numArcSegments:r=20,startAngle:s=0,endAngle:o=Fe,offset:i=0}){const a=(o-s)/r;let l=i;for(let c=s;c<o;c+=a)t[l++]=e.x,t[l++]=e.y,t[l++]=e.x+Math.cos(c)*n,t[l++]=e.y+Math.sin(c)*n,t[l++]=e.x+Math.cos(c+a)*n,t[l++]=e.y+Math.sin(c+a)*n;return t}function Wa(t,e,n,r,s,o){t[e++]=n,t[e++]=r,t[e++]=n,t[e++]=r+o,t[e++]=n+s,t[e++]=r,t[e++]=n+s,t[e++]=r,t[e++]=n,t[e++]=r+o,t[e++]=n+s,t[e++]=r+o}function Fhe(t,e,n){const r=Ff;n=Math.min(n,Math.min(e.w,e.h)/2);const s=Z.ExpandBy(e,-n);if(s.w<=0||s.h<=0)return Ka(t,{center:e.center,radius:n,numArcSegments:Ff*4}),Ff*4*6;let o=0;return Wa(t,o,s.minX,s.minY,s.w,s.h),o+=12,Wa(t,o,s.minX,e.minY,s.w,n),o+=12,Wa(t,o,s.maxX,s.minY,n,s.h),o+=12,Wa(t,o,s.minX,s.maxY,s.w,n),o+=12,Wa(t,o,e.minX,s.minY,n,s.h),o+=12,Ka(t,{numArcSegments:r,offset:o,center:s.point,radius:n,startAngle:De,endAngle:De*1.5}),o+=r*6,Ka(t,{numArcSegments:r,offset:o,center:x.Add(s.point,new x(s.w,0)),radius:n,startAngle:De*1.5,endAngle:Fe}),o+=r*6,Ka(t,{numArcSegments:r,offset:o,center:x.Add(s.point,s.size),radius:n,startAngle:0,endAngle:Ze}),o+=r*6,Ka(t,{numArcSegments:r,offset:o,center:x.Add(s.point,new x(0,s.h)),radius:n,startAngle:Ze,endAngle:De}),XF}function Nhe(t){if(!t)throw new Error("Canvas element not found");const e=t.getContext("webgl2",{premultipliedAlpha:!1});if(!e)throw new Error("Failed to get webgl2 context");const n=`#version 300 es
|
|
384
384
|
precision mediump float;
|
|
385
385
|
|
|
386
386
|
in vec2 shapeVertexPosition;
|
|
@@ -408,18 +408,18 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
408
408
|
|
|
409
409
|
void main() {
|
|
410
410
|
outputColor = fillColor;
|
|
411
|
-
}`,o=e.createShader(e.FRAGMENT_SHADER);if(!o)throw new Error("Failed to create fragment shader");if(e.shaderSource(o,s),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=e.createProgram();if(!i)throw new Error("Failed to create program");if(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:Bh(e,1024),unselectedShapes:Bh(e,4096),viewport:Bh(e,XF),collaborators:Bh(e,1024),prepareTriangles(f,p){e.bindBuffer(e.ARRAY_BUFFER,f.buffer),e.bufferData(e.ARRAY_BUFFER,f.vertices,e.STATIC_DRAW,0,p),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(f){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,f/2),e.disable(e.BLEND)},drawTriangles(f){e.drawArrays(e.TRIANGLES,0,f/2)},setFillColor(f){e.uniform4fv(c,f)},setCanvasPageBounds(f){e.uniform4fv(l,f)}}}function Bh(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function c2(t,e,n){let r=t.vertices.length;for(;r<e+n.length;)r*=2;if(r!=t.vertices.length){const s=new Float32Array(r);s.set(t.vertices),t.vertices=s}t.vertices.set(n,e)}var zhe=Object.create,qF=Object.defineProperty,Bhe=Object.getOwnPropertyDescriptor,Uhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),ZF=t=>{throw TypeError(t)},QF=(t,e,n)=>e in t?qF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hhe=t=>[,,,zhe(null)],JF=["class","method","getter","setter","accessor","field","value","get","set"],e4=t=>t!==void 0&&typeof t!="function"?ZF("Function expected"):t,Khe=(t,e,n,r,s)=>({kind:JF[t],name:e,metadata:r,addInitializer:o=>n._?ZF("Already initialized"):s.push(e4(o||null))}),Whe=(t,e)=>QF(e,Uhe("metadata"),t[3]),Ghe=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Vs=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=JF[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Bhe(s,n)),y=r.length-1;y>=0;y--)l=Khe(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,e4(i)&&(v[g]=i);return v&&qF(s,n,v),s},Js=(t,e,n)=>QF(t,typeof e!="symbol"?e+"":e,n),t4,n4,r4,s4,o4,i4,a4,l4,c4,u4,br;u4=[Kn],c4=[G],l4=[G],a4=[G],i4=[G],o4=[G],s4=[G],r4=[G],n4=[G],t4=[Kn];class Br{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,Ghe(br,5,this),Js(this,"disposables",[]),Js(this,"gl"),Js(this,"shapeGeometryCache"),Js(this,"colors"),Js(this,"id",ze()),Js(this,"canvasBoundingClientRect",It("canvasBoundingClientRect",new Z)),Js(this,"originPagePoint",new x),Js(this,"originPageCenter",new x),Js(this,"isInViewport",!1),this.gl=Nhe(n),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",s=>{const o=e.getShapeMaskedPageBounds(s.id);if(!o)return null;const i=new Float32Array(12);return Wa(i,0,o.x,o.y,o.w,o.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),As("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Rc(e.getPropertyValue("--color-text-3").trim()),selectFill:Rc(e.getPropertyValue("--color-selected").trim()),viewportFill:Rc(e.getPropertyValue("--color-muted-1").trim()),background:Rc(e.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const e=this.editor.getViewportPageBounds(),n=this.editor.getCurrentPageBounds();return n?Z.Expand(n,e):e}getContentScreenBounds(){const e=this.getContentPageBounds(),n=this.editor.pageToScreen(e.point),r=this.editor.pageToScreen(new x(e.maxX,e.maxY));return new Z(n.x,n.y,r.x-n.x,r.y-n.y)}_getCanvasBoundingRect(){const{x:e,y:n,width:r,height:s}=this.elem.getBoundingClientRect();return new Z(e,n,r,s)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const e=new ResizeObserver(()=>{const n=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(n)});return e.observe(this.elem),e.observe(this.container),()=>e.disconnect()}getCanvasSize(){const e=this.canvasBoundingClientRect.get(),n=this.getDpr();return new x(e.width*n,e.height*n)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const e=this.getCanvasScreenBounds(),n=this.getContentPageBounds(),r=e.width/e.height;let s=n.width,o=s/r;o<n.height&&(o=n.height,s=o*r);const i=new Z(0,0,s,o);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:n,w:r,h:s}=this.getCanvasPageBounds();return new Float32Array([e,n,r,s])}getMinimapPagePoint(e,n){const r=this.getCanvasPageBounds(),s=this.getCanvasScreenBounds();let o=e-s.x,i=n-s.y;return o*=r.width/s.width,i*=r.height/s.height,o+=r.minX,i+=r.minY,new x(o,i,1)}minimapScreenPointToPagePoint(e,n,r=!1,s=!1){const{editor:o}=this,i=o.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,n);if(s){const c=this.editor.getCurrentPageBounds()??new Z,u=c.minX-i.width/2,h=c.maxX+i.width/2,f=c.minY-i.height/2,p=c.maxY+i.height/2,g=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),v=Math.max(0,f+i.height-l),y=Math.max(0,-(p-i.height-l));a+=(g-m)/2,l+=(v-y)/2,a=Bt(a,u,h),l=Bt(l,f,p)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new x(a,l)}render(){const e=this.gl.context,n=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=n.x,this.elem.height=n.y,e.viewport(0,0,n.x,n.y),e.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),e.clear(e.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),s=this.colors;let o=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const f=h.length;r.has(u)?(c2(this.gl.selectedShapes,o,h),o+=f):(c2(this.gl.unselectedShapes,i,h),i+=f)}this.drawShapes(this.gl.unselectedShapes,i,s.shapeFill),this.drawShapes(this.gl.selectedShapes,o,s.selectFill),this.drawViewport(),this.drawCollaborators()}drawShapes(e,n,r){this.gl.prepareTriangles(e,n),this.gl.setFillColor(r),this.gl.drawTriangles(n)}drawViewport(){const e=this.editor.getViewportPageBounds(),n=Fhe(this.gl.viewport.vertices,e,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,n),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(n),Ge.isSafari&&(this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n))}drawCollaborators(){const e=this.editor.getCollaboratorsOnCurrentPage();if(!e.length)return;const n=20,r=n*6,s=r*e.length;this.gl.collaborators.vertices.length<s&&(this.gl.collaborators.vertices=new Float32Array(s));const o=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:l}of e)l&&(Ka(o,{center:x.From(l),radius:3*a,offset:i,numArcSegments:n}),i+=r);this.gl.prepareTriangles(this.gl.collaborators,s),i=0;for(const{color:l}of e)this.gl.setFillColor(Rc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}br=Hhe();Vs(br,1,"close",u4,Br);Vs(br,1,"getDpr",c4,Br);Vs(br,1,"getContentPageBounds",l4,Br);Vs(br,1,"getContentScreenBounds",a4,Br);Vs(br,1,"getCanvasSize",i4,Br);Vs(br,1,"getCanvasClientPosition",o4,Br);Vs(br,1,"getCanvasPageBounds",s4,Br);Vs(br,1,"getZoom",r4,Br);Vs(br,1,"getCanvasPageBoundsArray",n4,Br);Vs(br,1,"render",t4,Br);Whe(br,Br);function Vhe(){const t=z(),e=Tt(),n=w.useRef(null),r=w.useRef(!1),s=w.useRef();w.useEffect(()=>{try{const u=new Br(t,n.current,e);return s.current=u,s.current.close}catch(u){t.annotateError(u,{origin:"minimap",willCrashApp:!1}),t.timers.setTimeout(()=>{throw u})}},[t,e]);const o=w.useCallback(u=>{if(!t.getCurrentPageShapeIds().size||!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.originPagePoint.setTo(f),s.current.originPageCenter.setTo(t.getViewportPageBounds().center),t.centerOnPoint(h,{animation:{duration:t.options.animationMediumMs}})},[t]),i=w.useCallback(u=>{if(!s.current)return;const h=u.currentTarget;if(dd(h,u),!t.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const f=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=t.getViewportPageBounds(),g=s.current.getContentPageBounds();if(new Z(g.x-p.width/2,g.y-p.height/2,g.width+p.width,g.height+p.height).containsPoint(f)&&!p.containsPoint(f)){s.current.isInViewport=p.containsPoint(f);const y=x.Sub(p.center,p.point),S=x.Add(f,y);s.current.originPagePoint.setTo(S),s.current.originPageCenter.setTo(f),t.centerOnPoint(f,{animation:{duration:t.options.animationMediumMs}})}else{const y=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.isInViewport=p.containsPoint(y),s.current.originPagePoint.setTo(y),s.current.originPageCenter.setTo(p.center)}function v(y){h&&hd(h,y),r.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[t]),a=w.useCallback(u=>{if(!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(s.current.isInViewport){const m=s.current.originPagePoint.clone().sub(s.current.originPageCenter);t.centerOnPoint(x.Sub(h,m));return}t.centerOnPoint(h)}const f=s.current.getMinimapPagePoint(u.clientX,u.clientY),p=t.pageToScreen(f),g={type:"pointer",target:"canvas",name:"pointer_move",...lr(u),point:p,isPen:t.getInstanceState().isPenMode};t.dispatch(g)},[t]),l=w.useCallback(u=>{const h=wj(u);t.dispatch({type:"wheel",name:"wheel",delta:h,point:new x(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey,metaKey:u.metaKey,accelKey:un(u)})},[t]),c=xd();return w.useEffect(()=>{t.timers.setTimeout(()=>{var u,h;(u=s.current)==null||u.updateColors(),(h=s.current)==null||h.render()})},[c,t]),d.jsx("div",{className:"tlui-minimap",children:d.jsx("canvas",{role:"img","aria-label":"minimap",ref:n,className:"tlui-minimap__canvas",onDoubleClick:o,onPointerMove:a,onPointerDown:i,onWheelCapture:l})})}function Yhe(t,e){const[n,r]=ke.useState(e);ke.useLayoutEffect(()=>{const o=_0(t);if(o)try{r(JSON.parse(o))}catch{console.error(`Could not restore value ${t} from local storage.`)}},[t]);const s=ke.useCallback(o=>{r(i=>{const a=typeof o=="function"?o(i):o;return I0(t,JSON.stringify(a)),a})},[t]);return[n,s]}const Xhe=w.memo(function(){const e=ka(),n=Ee(),r=An(),s=w.useRef(null);Ai(s);const[o,i]=Yhe("minimap",!0),a=w.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=Ri();return r<St.MOBILE?null:d.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:l&&r<St.TABLET?d.jsx(l,{}):o?d.jsxs(d.Fragment,{children:[l&&d.jsx(l,{}),c&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(Xu(e["zoom-out"].label))} ${Xx(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"minus"})}),l&&d.jsx(l,{}),d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(Xu(e["zoom-in"].label))} ${Xx(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"plus"})}),c&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=St.TABLET&&!o&&d.jsx(c,{})]})}),qhe=function({name:e,id:n,isCurrentPage:r,onCancel:s}){const o=z(),i=Jt(),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(()=>{l.current=o.markHistoryStoppingPoint("rename page")},[o]),u=w.useCallback(f=>{o.renamePage(n,f||"New Page"),i("rename-page",{source:"page-menu"})},[o,n,i]),h=w.useCallback(()=>{l.current&&o.bailToMark(l.current),s()},[o,s]);return d.jsx(pm,{className:"tlui-page-menu__item__input",ref:f=>a.current=f,defaultValue:e,onValueChange:u,onCancel:h,onFocus:c,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},gw=(t,e,n,r,s)=>{let o;const i=t.getPages(),a=n>r?i[r-1]:i[r],l=n>r?i[r]:i[r+1];a&&!l?o=_s(a.index):!a&&l?o=aB(i[0].index):o=$u(a.index,l.index),o!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:o}),s("move-page",{source:"page-menu"}))},u2=Zt(function({index:e,listSize:n,item:r,onRename:s}){const o=z(),i=Ee(),a=o.getPages(),l=Jt(),c=w.useCallback(()=>{o.markHistoryStoppingPoint("creating page");const p=yr.createId();o.duplicatePage(r.id,p),l("duplicate-page",{source:"page-menu"})},[o,r,l]),u=w.useCallback(()=>{gw(o,r.id,e,e-1,l)},[o,r,e,l]),h=w.useCallback(()=>{gw(o,r.id,e,e+1,l)},[o,r,e,l]),f=w.useCallback(()=>{o.markHistoryStoppingPoint("deleting page"),o.deletePage(r.id),l("delete-page",{source:"page-menu"})},[o,r,l]);return d.jsxs(ma,{id:`page item submenu ${e}`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(Sa,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Fr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ve,{id:"modify",children:[s&&d.jsx(Kt,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),d.jsx(Kt,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=o.options.maxPages}),e>0&&d.jsx(Kt,{id:"move-up",onSelect:u,label:"page-menu.submenu.move-up"}),e<n-1&&d.jsx(Kt,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),n>1&&d.jsx(ve,{id:"delete",children:d.jsx(Kt,{id:"delete",onSelect:f,label:"page-menu.submenu.delete"})})]})})]})}),Zhe=w.memo(function(){const e=z(),n=Jt(),r=Ee(),s=An(),o=w.useCallback(()=>y(!1),[]),[i,a]=Mo("page-menu",o),l=36,c=w.useRef(null),u=U("pages",()=>e.getPages(),[e]),h=U("currentPage",()=>e.getCurrentPage(),[e]),f=U("currentPageId",()=>e.getCurrentPageId(),[e]),p=wr(),g=U("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),m=U("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,y]=w.useState(!1),S=w.useCallback(()=>{p||y(M=>!M)},[p]),b=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,C]=w.useState(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{C(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])))},[l,u]),w.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const M=document.querySelector(`[data-testid="page-menu-item-${f}"]`);if(M){const O=c.current;if(!O)return;const F=M.offsetTop,B=O.scrollTop;F<B&&O.scrollTo({top:F});const K=F+l,R=O.scrollTop+O.offsetHeight;K>R&&O.scrollTo({top:K-O.offsetHeight})}})},[l,f,i,e]);const _=w.useCallback(M=>{const{clientY:O,currentTarget:F}=M,{dataset:{id:B,index:K}}=F;if(!B||!K)return;const R=b.current;dd(M.currentTarget,M),R.status="pointing",R.pointing={id:B,index:+K};const X=P[B].y;R.startY=O,R.startIndex=Math.max(0,Math.min(Math.round(X/l),u.length-1))},[l,u.length,P]),E=w.useCallback(M=>{const O=b.current;if(O.status==="pointing"){const{clientY:F}=M,B=F-O.startY;Math.abs(B)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:F}=M,B=F-O.startY,K=P[O.pointing.id],{startIndex:R,pointing:H}=O,X=K.y+B,te=Math.max(0,Math.min(Math.round(X/l),u.length-1)),le={...P};if(le[H.id]={y:K.y,offsetY:B,isSelected:!0},te!==O.dragIndex){O.dragIndex=te;for(let de=0;de<u.length;de++){const Me=u[de];if(Me.id===O.pointing.id)continue;let{y:oe}=le[Me.id];te===R?oe=de*l:te<R?te<=de&&de<R?oe=(de+1)*l:oe=de*l:te>R&&(te>=de&&de>R?oe=(de-1)*l:oe=de*l),oe!==le[Me.id].y&&(le[Me.id]={y:oe,offsetY:0,isSelected:!0})}}C(le)}},[l,u,P]),k=w.useCallback(M=>{const O=b.current;if(O.status==="dragging"){const{id:F,index:B}=O.pointing;gw(e,F,B,O.dragIndex,n)}hd(M.currentTarget,M),O.status="idle"},[e,n]),D=w.useCallback(M=>{const O=b.current;M.key==="Escape"&&(O.status==="dragging"&&C(Object.fromEntries(u.map((F,B)=>[F.id,{y:B*l,offsetY:0,isSelected:!1}]))),O.status="idle")},[l,u]),T=w.useCallback(()=>{p||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const M=yr.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:M}),e.setCurrentPage(M),y(!0)}),n("new-page",{source:"page-menu"}))},[e,r,p,n]),j=w.useCallback(M=>{e.setCurrentPage(M),n("change-page",{source:"page-menu"})},[e,n]),L=w.useCallback((M,O)=>{e.renamePage(M,O),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(V1,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(Y1,{"data-testid":"main.page-menu",children:d.jsxs(ue,{type:"menu",title:h.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:h.name}),d.jsx(be,{icon:"chevron-down",small:!0})]})}),d.jsx(X1,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:v,children:d.jsxs("div",{className:"tlui-page-menu__wrapper",children:[d.jsxs("div",{className:"tlui-page-menu__header",children:[d.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!p&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(ue,{type:"icon","data-testid":"page-menu.edit",title:r(v?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:d.jsx(be,{icon:v?"check":"edit"})}),d.jsx(ue,{type:"icon","data-testid":"page-menu.create",title:r(g?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:g,onClick:T,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((M,O)=>{const F=P[M.id]??{position:O*40,offsetY:0};return v?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:M.id===h.id?888:O,transform:`translate(0px, ${F.y+F.offsetY}px)`},children:[d.jsx(ue,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:_,onPointerUp:k,onPointerMove:E,onKeyDown:D,"data-id":M.id,"data-index":O,children:d.jsx(be,{icon:"drag-handle-dots"})}),s<St.TABLET_SM&&m?d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const B=window.prompt("Rename page",M.name);B&&B!==M.name&&L(M.id,B)},onDoubleClick:S,children:[d.jsx(pw,{checked:M.id===h.id}),d.jsx(bt,{children:M.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(qhe,{id:M.id,name:M.name,isCurrentPage:M.id===h.id,onCancel:()=>{y(!1),e.menus.clearOpenMenus()}})}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":v,children:d.jsx(u2,{index:O,item:M,listSize:u.length})})]},M.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>j(M.id),onDoubleClick:S,title:r("page-menu.go-to-page"),children:[d.jsx(pw,{checked:M.id===h.id}),d.jsx(bt,{children:M.name})]}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(u2,{index:O,item:M,listSize:u.length,onRename:()=>{if(Ge.isIos){const B=window.prompt("Rename page",M.name);B&&B!==M.name&&L(M.id,B)}else y(!0),f!==M.id&&j(M.id)}})})]},M.id)})})]})})]})});function Qhe(){const t=z(),e=wr(),n=U("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]);if(!(e&&!n))return d.jsxs(d.Fragment,{children:[d.jsx(efe,{}),d.jsx(Jhe,{})]})}function Jhe(){const t=jn(1),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"delete",disabled:!n}),d.jsx(W,{actionId:"duplicate",disabled:!n})]})}function efe(){const t=kF(),e=EF();return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}const tfe=w.memo(function({children:e}){const n=e??d.jsx(Qhe,{});return d.jsx(Fr,{type:"small-icons",sourceId:"quick-actions",children:n})});function nfe({userId:t}){const e=Lg(t);return e?d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:e.userName==="New User"?"":e.userName[0]??""},t):null}const rfe=Zt(function({userId:e}){const n=z(),r=Ee(),s=Jt(),o=Lg(e),i=w.useCallback(()=>{n.getInstanceState().followingUserId===e?(n.stopFollowingUser(),s("stop-following",{source:"people-menu"})):(n.startFollowingUser(e),s("start-following",{source:"people-menu"}))},[n,e,s]),a=(o==null?void 0:o.followingUserId)===n.user.getId(),l=n.getInstanceState().followingUserId===e;return o?d.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[d.jsxs(ue,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>n.zoomToUser(e),onDoubleClick:i,children:[d.jsx(zs,{icon:"color",color:o.color}),d.jsx("div",{className:"tlui-people-menu__name",children:o.userName??"New User"})]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,"data-active":l||a,children:d.jsx(be,{icon:a?"leading":l?"following":"follow"})})]}):null});function sfe({count:t}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(t)})}const ofe=Zt(function(){const e=z(),n=Tt(),r=Ee(),s=Jt(),o=w.useRef(!1),[i,a]=w.useState(!1),l=w.useCallback(m=>{a(m)},[]),c=e.user.getColor(),u=w.useCallback(m=>{e.user.updateUserPreferences({color:m}),s("set-color",{source:"people-menu"})},[e,s]),{handleButtonClick:h,handleButtonPointerDown:f,handleButtonPointerEnter:p,handleButtonPointerUp:g}=ke.useMemo(()=>{const m=()=>{o.current=!1,window.removeEventListener("pointerup",m)};return{handleButtonClick:P=>{const{id:C}=P.currentTarget.dataset;C&&c!==C&&u(C)},handleButtonPointerDown:P=>{const{id:C}=P.currentTarget.dataset;C&&(u(C),o.current=!0,window.addEventListener("pointerup",m))},handleButtonPointerEnter:P=>{if(!o.current)return;const{id:C}=P.currentTarget.dataset;C&&u(C)},handleButtonPointerUp:P=>{const{id:C}=P.currentTarget.dataset;C&&u(C)}}},[c,u]);return d.jsxs(H1,{onOpenChange:l,open:i,children:[d.jsx(K1,{dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:d.jsx(be,{icon:"color"})})}),d.jsx(W1,{container:n,children:d.jsx(G1,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:d.jsx("div",{className:"tlui-buttons__grid",children:Px.map(m=>d.jsx(ue,{type:"icon","data-id":m,"data-testid":m,"aria-label":m,"data-state":c===m?"hinted":void 0,title:m,className:"tlui-button-grid__button",style:{color:m},onPointerEnter:p,onPointerDown:f,onPointerUp:g,onClick:h,children:d.jsx(be,{icon:"color"})},m))})})})]})});function ife(){const t=z(),e=Jt(),n=U("userName",()=>t.user.getName(),[]),r=Ee(),s=w.useRef(n),o=w.useRef(n),[i,a]=w.useState(!1),l=w.useCallback(()=>{a(f=>!f)},[]),c=w.useCallback(f=>{o.current=f,t.user.updateUserPreferences({name:f})},[t]),u=w.useCallback(()=>{s.current!==o.current&&(e("change-user-name",{source:"people-menu"}),s.current=o.current)},[e]),h=w.useCallback(()=>{a(!1),t.user.updateUserPreferences({name:s.current}),t.menus.clearOpenMenus()},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(ofe,{}),i?d.jsx(pm,{className:"tlui-people-menu__user__input",defaultValue:n,onValueChange:c,onComplete:l,onCancel:h,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:n}),n==="New User"?d.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:d.jsx(be,{icon:i?"check":"edit"})})]})}function afe({displayUserWhenAlone:t,children:e}){const n=Ee(),r=Tt(),s=z(),o=Cj(),i=U("user",()=>s.user.getColor(),[s]),a=U("user",()=>s.user.getName(),[s]),[l,c]=Mo("people menu");return d.jsxs(H1,{onOpenChange:c,open:l,children:[d.jsx(K1,{dir:"ltr",asChild:!0,children:d.jsxs("button",{className:"tlui-people-menu__avatars-button",title:n("people-menu.title"),children:[o.length>5&&d.jsx(sfe,{count:o.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[o.slice(-5).map(u=>d.jsx(nfe,{userId:u},u)),(t||o.length>0)&&d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(W1,{container:r,children:d.jsx(G1,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:xe,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(ife,{})}),o.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:o.map(u=>d.jsx(rfe,{userId:u},u+"_presence"))}),e]})})})]})}function lfe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(afe,{displayUserWhenAlone:!0})})}const cfe=Object.freeze([mr,ua,da,$s]);function d4(t=cfe){const e=z();return U("getRelevantStyles",()=>{var o;const n=new Tx(e.getSharedStyles()),r=!!((o=e.root.getCurrent())!=null&&o.shapeType),s=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(n.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const i of t)n.applyValue(i,e.getStyleForNextShape(i));return r||s||n.size>0?n:null},[e])}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"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Xi=w.memo(function(e){const{uiType:n,items:r,title:s,style:o,value:i,onValueChange:a,onHistoryMark:l,theme:c}=e,u=Ee(),h=w.useRef(!1),f=w.useRef(null),{handleButtonClick:p,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:v}=w.useMemo(()=>{const y=()=>{h.current=!1,window.removeEventListener("pointerup",y);const _=f.current;_&&["TEXTAREA","INPUT"].includes(_.nodeName)&&_.focus(),f.current=null};return{handleButtonClick:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||(l==null||l("point picker item"),a(o,E))},handleButtonPointerDown:_=>{const{id:E}=_.currentTarget.dataset;l==null||l("point picker item"),a(o,E),h.current=!0,f.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:_=>{if(!h.current)return;const{id:E}=_.currentTarget.dataset;a(o,E)},handleButtonPointerUp:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||a(o,E)}}},[i,l,a,o]);return d.jsx("div",{"data-testid":`style.${n}`,className:ce("tlui-buttons__grid"),children:r.map(y=>d.jsx(ue,{type:"icon","data-id":y.value,"data-testid":`style.${n}.${y.value}`,"aria-label":y.value,"data-state":i.type==="shared"&&i.value===y.value?"hinted":void 0,title:s+" — "+u(`${n}-style.${y.value}`),className:ce("tlui-button-grid__button"),style:o===mr?{color:c[y.value].solid}:void 0,onPointerEnter:m,onPointerDown:g,onPointerUp:v,onClick:p,children:d.jsx(be,{icon:y.icon})},y.value))})});function h4(t,[e,n]){return Math.min(n,Math.max(e,t))}function ufe(t){const e=w.useRef({value:t,previous:t});return w.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var f4=["PageUp","PageDown"],p4=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],g4={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},lc="Slider",[mw,dfe,hfe]=Jg(lc),[m4,Rge]=Ws(lc,[hfe]),[ffe,Tm]=m4(lc),y4=w.forwardRef((t,e)=>{const{name:n,min:r=0,max:s=100,step:o=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:f=()=>{},inverted:p=!1,form:g,...m}=t,v=w.useRef(new Set),y=w.useRef(0),b=i==="horizontal"?pfe:gfe,[P=[],C]=ji({prop:u,defaultProp:c,onChange:j=>{var M;(M=[...v.current][y.current])==null||M.focus(),h(j)}}),_=w.useRef(P);function E(j){const L=xfe(P,j);T(j,L)}function k(j){T(j,y.current)}function D(){const j=_.current[y.current];P[y.current]!==j&&f(P)}function T(j,L,{commit:M}={commit:!1}){const O=Cfe(o),F=_fe(Math.round((j-r)/o)*o+r,O),B=h4(F,[r,s]);C((K=[])=>{const R=Sfe(K,B,L);if(Pfe(R,l*o)){y.current=R.indexOf(B);const H=String(R)!==String(K);return H&&M&&f(R),H?R:K}else return K})}return d.jsx(ffe,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:s,valueIndexToChangeRef:y,thumbs:v.current,values:P,orientation:i,form:g,children:d.jsx(mw.Provider,{scope:t.__scopeSlider,children:d.jsx(mw.Slot,{scope:t.__scopeSlider,children:d.jsx(b,{"aria-disabled":a,"data-disabled":a?"":void 0,...m,ref:e,onPointerDown:se(m.onPointerDown,()=>{a||(_.current=P)}),min:r,max:s,inverted:p,onSlideStart:a?void 0:E,onSlideMove:a?void 0:k,onSlideEnd:a?void 0:D,onHomeKeyDown:()=>!a&&T(r,0,{commit:!0}),onEndKeyDown:()=>!a&&T(s,P.length-1,{commit:!0}),onStepKeyDown:({event:j,direction:L})=>{if(!a){const F=f4.includes(j.key)||j.shiftKey&&p4.includes(j.key)?10:1,B=y.current,K=P[B],R=o*F*L;T(K+R,B,{commit:!0})}}})})})})});y4.displayName=lc;var[S4,v4]=m4(lc,{startEdge:"left",endEdge:"right",size:"width",direction:1}),pfe=w.forwardRef((t,e)=>{const{min:n,max:r,dir:s,inverted:o,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=t,[h,f]=w.useState(null),p=Qe(e,b=>f(b)),g=w.useRef(void 0),m=Fb(s),v=m==="ltr",y=v&&!o||!v&&o;function S(b){const P=g.current||h.getBoundingClientRect(),C=[0,P.width],E=Z1(C,y?[n,r]:[r,n]);return g.current=P,E(b-P.left)}return d.jsx(S4,{scope:t.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:d.jsx(x4,{dir:m,"data-orientation":"horizontal",...u,ref:p,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=S(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=S(b.clientX);a==null||a(P)},onSlideEnd:()=>{g.current=void 0,l==null||l()},onStepKeyDown:b=>{const C=g4[y?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:C?-1:1})}})})}),gfe=w.forwardRef((t,e)=>{const{min:n,max:r,inverted:s,onSlideStart:o,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=t,u=w.useRef(null),h=Qe(e,u),f=w.useRef(void 0),p=!s;function g(m){const v=f.current||u.current.getBoundingClientRect(),y=[0,v.height],b=Z1(y,p?[r,n]:[n,r]);return f.current=v,b(m-v.top)}return d.jsx(S4,{scope:t.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1,children:d.jsx(x4,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const v=g(m.clientY);o==null||o(v)},onSlideMove:m=>{const v=g(m.clientY);i==null||i(v)},onSlideEnd:()=>{f.current=void 0,a==null||a()},onStepKeyDown:m=>{const y=g4[p?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:y?-1:1})}})})}),x4=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:s,onSlideEnd:o,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=Tm(lc,n);return d.jsx(Ae.span,{...c,ref:e,onKeyDown:se(t.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):f4.concat(p4).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:se(t.onPointerDown,h=>{const f=h.target;f.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(f)?f.focus():r(h)}),onPointerMove:se(t.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&s(h)}),onPointerUp:se(t.onPointerUp,h=>{const f=h.target;f.hasPointerCapture(h.pointerId)&&(f.releasePointerCapture(h.pointerId),o(h))})})}),w4="SliderTrack",b4=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,s=Tm(w4,n);return d.jsx(Ae.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});b4.displayName=w4;var yw="SliderRange",P4=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,s=Tm(yw,n),o=v4(yw,n),i=w.useRef(null),a=Qe(e,i),l=s.values.length,c=s.values.map(f=>_4(f,s.min,s.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ae.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...t.style,[o.startEdge]:u+"%",[o.endEdge]:h+"%"}})});P4.displayName=yw;var Sw="SliderThumb",C4=w.forwardRef((t,e)=>{const n=dfe(t.__scopeSlider),[r,s]=w.useState(null),o=Qe(e,a=>s(a)),i=w.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return d.jsx(mfe,{...t,ref:o,index:i})}),mfe=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:s,...o}=t,i=Tm(Sw,n),a=v4(Sw,n),[l,c]=w.useState(null),u=Qe(e,S=>c(S)),h=l?i.form||!!l.closest("form"):!0,f=m3(l),p=i.values[r],g=p===void 0?0:_4(p,i.min,i.max),m=vfe(r,i.values.length),v=f==null?void 0:f[a.size],y=v?wfe(v,g,a.direction):0;return w.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${y}px)`},children:[d.jsx(mw.ItemSlot,{scope:t.__scopeSlider,children:d.jsx(Ae.span,{role:"slider","aria-label":t["aria-label"]||m,"aria-valuemin":i.min,"aria-valuenow":p,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...o,ref:u,style:p===void 0?{display:"none"}:t.style,onFocus:se(t.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(yfe,{name:s??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:p},r)]})});C4.displayName=Sw;var yfe=t=>{const{value:e,...n}=t,r=w.useRef(null),s=ufe(e);return w.useEffect(()=>{const o=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(s!==e&&l){const c=new Event("input",{bubbles:!0});l.call(o,e),o.dispatchEvent(c)}},[s,e]),d.jsx("input",{style:{display:"none"},...n,ref:r,defaultValue:e})};function Sfe(t=[],e,n){const r=[...t];return r[n]=e,r.sort((s,o)=>s-o)}function _4(t,e,n){const o=100/(n-e)*(t-e);return h4(o,[0,100])}function vfe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function xfe(t,e){if(t.length===1)return 0;const n=t.map(s=>Math.abs(s-e)),r=Math.min(...n);return n.indexOf(r)}function wfe(t,e,n){const r=t/2,o=Z1([0,50],[0,r]);return(r-o(e)*n)*n}function bfe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function Pfe(t,e){if(e>0){const n=bfe(t);return Math.min(...n)>=e}return!0}function Z1(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}function Cfe(t){return(String(t).split(".")[1]||"").length}function _fe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var Ife=y4,Efe=b4,kfe=P4,Tfe=C4;const Mfe=w.memo(function({onHistoryMark:e,title:n,steps:r,value:s,label:o,onValueChange:i,["data-testid"]:a}){const l=Ee(),c=w.useCallback(f=>{i(f[0])},[i]),u=w.useCallback(()=>{e("click slider")},[e]),h=w.useCallback(()=>{s&&i(s)},[s,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(Ife,{"data-testid":a,className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:h,title:n+" — "+l(o),children:[d.jsx(Efe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&d.jsx(kfe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&d.jsx(Tfe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Afe({label:t,uiTypeA:e,uiTypeB:n,labelA:r,labelB:s,itemsA:o,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const f=Ee(),p=w.useMemo(()=>{var m;return((m=o.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:m.icon)??"mixed"},[o,c]),g=w.useMemo(()=>{var m;return((m=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:f(t),className:"tlui-style-panel__double-select-picker-label",children:f(t)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(ma,{id:`style panel ${e} A`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon","data-testid":`style.${e}`,title:f(r)+" — "+(c===null||c.type==="mixed"?f("style-panel.mixed"):f(`${e}-style.${c.value}`)),children:d.jsx(be,{icon:p,small:!0,invertIcon:!0})})}),d.jsx(Sa,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map((m,v)=>d.jsx(qu,{"data-testid":`style.${e}.${m.value}`,children:d.jsx(ue,{type:"icon",onClick:()=>h(a,m.value),title:`${f(r)} — ${f(`${e}-style.${m.value}`)}`,children:d.jsx(be,{icon:m.icon,invertIcon:!0})},m.value)},v))})})]}),d.jsxs(ma,{id:`style panel ${n}`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}`,title:f(s)+" — "+(u===null||u.type==="mixed"?f("style-panel.mixed"):f(`${n}-style.${u.value}`)),children:d.jsx(be,{icon:g,small:!0})})}),d.jsx(Sa,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(qu,{children:d.jsx(ue,{type:"icon",title:`${f(s)} — ${f(`${n}-style.${m.value}`)}`,"data-testid":`style.${n}.${m.value}`,onClick:()=>h(l,m.value),children:d.jsx(be,{icon:m.icon})})},m.value))})})]})]})]})}const jfe=w.memo(Afe);function Ofe({id:t,label:e,uiType:n,stylePanelType:r,style:s,items:o,type:i,value:a,onValueChange:l}){const c=Ee(),u=z(),h=w.useMemo(()=>{var m;return(m=o.find(v=>a.type==="shared"&&v.value===a.value))==null?void 0:m.icon},[o,a]),f=c(`style-panel.${r}`),p=a.type==="mixed"?c("style-panel.mixed"):f+" — "+c(`${n}-style.${a.value}`),g=e?c(e):"";return d.jsxs(ma,{id:`style panel ${t}`,children:[d.jsx(ya,{children:d.jsxs(ue,{type:i,"data-testid":`style.${n}`,title:p,children:[g&&d.jsx(bt,{children:g}),d.jsx(be,{icon:h??"mixed"})]})}),d.jsx(Sa,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(m=>d.jsx(qu,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}.${m.value}`,title:f+" — "+c(`${n}-style.${m.value}`),onClick:()=>{u.markHistoryStoppingPoint("select style dropdown item"),l(s,m.value)},children:d.jsx(be,{icon:m.icon})})},m.value))})})]})}const Q1=w.memo(Ofe);function Dfe({styles:t}){const e=xd();if(!t)return null;const n=t.get(Jr),r=t.get(Mp),s=t.get(Tp),o=t.get(Dp),i=t.get(Ls),a=n===void 0,l=r===void 0&&s===void 0,c=o===void 0,u=i===void 0,h=ko({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(Rfe,{theme:h,styles:t}),!u&&d.jsx(Lfe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx($fe,{styles:t}),d.jsx(Nfe,{styles:t}),d.jsx(Ffe,{styles:t})]})]})}function Td(){const t=z(),e=Jt();return ke.useMemo(()=>function(r,s){t.run(()=>{t.isIn("select")&&t.setStyleForSelectedShapes(r,s),t.setStyleForNextShapes(r,s),t.updateInstanceState({isChangingStyle:!0})}),e("set-style",{source:"style-panel",id:r.id,value:s})},[t,e])}function Rfe({styles:t,theme:e}){const n=Ee(),r=z(),s=w.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),o=Td(),i=t.get(mr),a=t.get(da),l=t.get(ua),c=t.get($s),u=a!==void 0||l!==void 0||c!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[i===void 0?null:d.jsx(Xi,{title:n("style-panel.color"),uiType:"color",style:mr,items:jr.color,value:i,onValueChange:o,theme:e,onHistoryMark:s}),d.jsx(zfe,{})]}),u&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:d.jsx(Xi,{title:n("style-panel.fill"),uiType:"fill",style:da,items:jr.fill,value:a,onValueChange:o,theme:e,onHistoryMark:s}),l===void 0?null:d.jsx(Xi,{title:n("style-panel.dash"),uiType:"dash",style:ua,items:jr.dash,value:l,onValueChange:o,theme:e,onHistoryMark:s}),c===void 0?null:d.jsx(Xi,{title:n("style-panel.size"),uiType:"size",style:$s,items:jr.size,value:c,onValueChange:(h,f)=>{o(h,f);const p=r.getSelectedShapeIds();p.length>0&&Xe(r,p)},theme:e,onHistoryMark:s})]})]})}function Lfe({theme:t,styles:e}){const n=Ee(),r=Td(),s=z(),o=w.useCallback(u=>s.markHistoryStoppingPoint(u),[s]),i=e.get(Ls),a=e.get(Sx),l=e.get(jp),c=e.get(Op);return i===void 0&&l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[i===void 0?null:d.jsx(Xi,{title:n("style-panel.font"),uiType:"font",style:Ls,items:jr.font,value:i,onValueChange:r,theme:t,onHistoryMark:o}),a===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Xi,{title:n("style-panel.align"),uiType:"align",style:Sx,items:jr.textAlign,value:a,onValueChange:r,theme:t,onHistoryMark:o}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Xi,{title:n("style-panel.label-align"),uiType:"align",style:jp,items:jr.horizontalAlign,value:l,onValueChange:r,theme:t,onHistoryMark:o}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(Q1,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:Op,items:jr.verticalAlign,value:c,onValueChange:r})})]})]})}function $fe({styles:t}){const e=Td(),n=t.get(Jr);return n===void 0?null:d.jsx(Q1,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:Jr,items:jr.geo,value:n,onValueChange:e})}function Ffe({styles:t}){const e=Td(),n=t.get(Dp);return n===void 0?null:d.jsx(Q1,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:Dp,items:jr.spline,value:n,onValueChange:e})}function Nfe({styles:t}){const e=Td(),n=t.get(Mp),r=t.get(Tp);return!n||!r?null:d.jsx(jfe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Tp,itemsA:jr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Mp,itemsB:jr.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Lc=[.1,.25,.5,.75,1];function zfe(){const t=z(),e=w.useCallback(a=>t.markHistoryStoppingPoint(a),[t]),n=U("opacity",()=>t.getSharedOpacity(),[t]),r=Jt(),s=Ee(),o=ke.useCallback(a=>{const l=Lc[a];t.run(()=>{t.isIn("select")&&t.setOpacityForSelectedShapes(l),t.setOpacityForNextShapes(l),t.updateInstanceState({isChangingStyle:!0})}),r("set-style",{source:"style-panel",id:"opacity",value:a})},[t,r]);if(n===void 0)return null;const i=n.type==="mixed"?-1:Lc.indexOf(M9(Lc,a=>Math.abs(a-n.value)));return d.jsx(Mfe,{"data-testid":"style.opacity",value:i>=0?i:Lc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:Lc.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const Bfe=w.memo(function({isMobile:e,children:n}){const r=z(),s=w.useRef(null);Ai(s);const o=d4(),i=w.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=n??d.jsx(Dfe,{styles:o});return d.jsx("div",{ref:s,className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:i,children:a})});function Ufe(){const t=z(),e=Ee(),n=d4(),r=n==null?void 0:n.get(mr),s=ko({isDarkMode:t.user.getIsDarkMode()}),o=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,i=U("disable style panel",()=>t.isInAny("hand","zoom","eraser","laser"),[t]),a=w.useCallback(c=>{c||t.updateInstanceState({isChangingStyle:!1})},[t]),{StylePanel:l}=Ri();return l?d.jsxs(V1,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(Y1,{children:d.jsx(ue,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":o},title:e("style-panel.title"),disabled:i,children:d.jsx(be,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),d.jsx(X1,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function Hfe(){return d.jsxs(d.Fragment,{children:[d.jsx(Wfe,{}),d.jsx(Gfe,{}),d.jsx(Vfe,{}),d.jsx(Yfe,{}),d.jsx(Xfe,{}),d.jsx(qfe,{}),d.jsx(Zfe,{}),d.jsx(Qfe,{}),d.jsx(Jfe,{}),d.jsx(epe,{}),d.jsx(npe,{}),d.jsx(tpe,{}),d.jsx(ope,{}),d.jsx(lpe,{}),d.jsx(rpe,{}),d.jsx(ape,{}),d.jsx(ipe,{}),d.jsx(spe,{}),d.jsx(cpe,{}),d.jsx(upe,{}),d.jsx(dpe,{}),d.jsx(hpe,{}),d.jsx(fpe,{}),d.jsx(ppe,{}),d.jsx(gpe,{}),d.jsx(mpe,{}),d.jsx(Spe,{}),d.jsx(ype,{})]})}function Kfe(t){var r;const e=z(),n=(r=t.meta)==null?void 0:r.geo;return U("is tool selected",()=>{const s=e.getCurrentToolId(),o=e.getSharedStyles().getAsKnownValue(Jr);return n?s==="geo"&&o===n:s===t.id},[e,t.id,n])}function Ve({tool:t}){const e=E1(),n=Kfe(e[t]);return d.jsx(Ln,{toolId:t,isSelected:n})}function Wfe(){return d.jsx(Ve,{tool:"select"})}function Gfe(){return d.jsx(Ve,{tool:"hand"})}function Vfe(){return d.jsx(Ve,{tool:"draw"})}function Yfe(){return d.jsx(Ve,{tool:"eraser"})}function Xfe(){return d.jsx(Ve,{tool:"arrow"})}function qfe(){return d.jsx(Ve,{tool:"text"})}function Zfe(){return d.jsx(Ve,{tool:"note"})}function Qfe(){return d.jsx(Ln,{toolId:"asset"})}function Jfe(){return d.jsx(Ve,{tool:"rectangle"})}function epe(){return d.jsx(Ve,{tool:"ellipse"})}function tpe(){return d.jsx(Ve,{tool:"diamond"})}function npe(){return d.jsx(Ve,{tool:"triangle"})}function rpe(){return d.jsx(Ve,{tool:"rhombus"})}function spe(){return d.jsx(Ve,{tool:"heart"})}function ope(){return d.jsx(Ve,{tool:"hexagon"})}function ipe(){return d.jsx(Ve,{tool:"cloud"})}function ape(){return d.jsx(Ve,{tool:"star"})}function lpe(){return d.jsx(Ve,{tool:"oval"})}function cpe(){return d.jsx(Ve,{tool:"x-box"})}function upe(){return d.jsx(Ve,{tool:"check-box"})}function dpe(){return d.jsx(Ve,{tool:"arrow-left"})}function hpe(){return d.jsx(Ve,{tool:"arrow-up"})}function fpe(){return d.jsx(Ve,{tool:"arrow-down"})}function ppe(){return d.jsx(Ve,{tool:"arrow-right"})}function gpe(){return d.jsx(Ve,{tool:"line"})}function mpe(){return d.jsx(Ve,{tool:"highlight"})}function ype(){return d.jsx(Ve,{tool:"frame"})}function Spe(){return d.jsx(Ve,{tool:"laser"})}const TS=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function MS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function $c(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function I4(t,e){const n=e.slice(0,e.length-1);for(let r=0;r<n.length;r++)n[r]=t[n[r].toLowerCase()];return n}function E4(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function vpe(t,e){const n=t.length>=e.length?t:e,r=t.length>=e.length?e:t;let s=!0;for(let o=0;o<n.length;o++)r.indexOf(n[o])===-1&&(s=!1);return s}const Zu={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,"-":TS?173:189,"=":TS?61:187,";":TS?59:186,"'":222,"[":219,"]":221,"\\":220},Us={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Nf={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Ut={16:!1,18:!1,17:!1,91:!1},ft={};for(let t=1;t<20;t++)Zu["f".concat(t)]=111+t;let it=[],gu=null,k4="all";const ro=new Map,Md=t=>Zu[t.toLowerCase()]||Us[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),xpe=t=>Object.keys(Zu).find(e=>Zu[e]===t),wpe=t=>Object.keys(Us).find(e=>Us[e]===t);function T4(t){k4=t||"all"}function Qu(){return k4||"all"}function bpe(){return it.slice(0)}function Ppe(){return it.map(t=>xpe(t)||wpe(t)||String.fromCharCode(t))}function Cpe(){const t=[];return Object.keys(ft).forEach(e=>{ft[e].forEach(n=>{let{key:r,scope:s,mods:o,shortcut:i}=n;t.push({scope:s,shortcut:i,mods:o,keys:r.split("+").map(a=>Md(a))})})}),t}function _pe(t){const e=t.target||t.srcElement,{tagName:n}=e;let r=!0;const s=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(s||n==="TEXTAREA"||n==="SELECT")&&!e.readOnly)&&(r=!1),r}function Ipe(t){return typeof t=="string"&&(t=Md(t)),it.indexOf(t)!==-1}function Epe(t,e){let n,r;t||(t=Qu());for(const s in ft)if(Object.prototype.hasOwnProperty.call(ft,s))for(n=ft[s],r=0;r<n.length;)n[r].scope===t?n.splice(r,1).forEach(i=>{let{element:a}=i;return J1(a)}):r++;Qu()===t&&T4(e||"all")}function kpe(t){let e=t.keyCode||t.which||t.charCode;const n=it.indexOf(e);if(n>=0&&it.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&it.splice(0,it.length),(e===93||e===224)&&(e=91),e in Ut){Ut[e]=!1;for(const r in Us)Us[r]===e&&(Wn[r]=!1)}}function M4(t){if(typeof t>"u")Object.keys(ft).forEach(s=>{Array.isArray(ft[s])&&ft[s].forEach(o=>Uh(o)),delete ft[s]}),J1(null);else if(Array.isArray(t))t.forEach(s=>{s.key&&Uh(s)});else if(typeof t=="object")t.key&&Uh(t);else if(typeof t=="string"){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];let[s,o]=n;typeof s=="function"&&(o=s,s=""),Uh({key:t,scope:s,method:o,splitKey:"+"})}}const Uh=t=>{let{key:e,scope:n,method:r,splitKey:s="+"}=t;E4(e).forEach(i=>{const a=i.split(s),l=a.length,c=a[l-1],u=c==="*"?"*":Md(c);if(!ft[u])return;n||(n=Qu());const h=l>1?I4(Us,a):[],f=[];ft[u]=ft[u].filter(p=>{const m=(r?p.method===r:!0)&&p.scope===n&&vpe(p.mods,h);return m&&f.push(p.element),!m}),f.forEach(p=>J1(p))})};function d2(t,e,n,r){if(e.element!==r)return;let s;if(e.scope===n||e.scope==="all"){s=e.mods.length>0;for(const o in Ut)Object.prototype.hasOwnProperty.call(Ut,o)&&(!Ut[o]&&e.mods.indexOf(+o)>-1||Ut[o]&&e.mods.indexOf(+o)===-1)&&(s=!1);(e.mods.length===0&&!Ut[16]&&!Ut[18]&&!Ut[17]&&!Ut[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(it),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function h2(t,e){const n=ft["*"];let r=t.keyCode||t.which||t.charCode;if(!Wn.filter.call(this,t))return;if((r===93||r===224)&&(r=91),it.indexOf(r)===-1&&r!==229&&it.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=Nf[a];t[a]&&it.indexOf(l)===-1?it.push(l):!t[a]&&it.indexOf(l)>-1?it.splice(it.indexOf(l),1):a==="metaKey"&&t[a]&&(it=it.filter(c=>c in Nf||c===r))}),r in Ut){Ut[r]=!0;for(const a in Us)Us[a]===r&&(Wn[a]=!0);if(!n)return}for(const a in Ut)Object.prototype.hasOwnProperty.call(Ut,a)&&(Ut[a]=t[Nf[a]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(it.indexOf(17)===-1&&it.push(17),it.indexOf(18)===-1&&it.push(18),Ut[17]=!0,Ut[18]=!0);const s=Qu();if(n)for(let a=0;a<n.length;a++)n[a].scope===s&&(t.type==="keydown"&&n[a].keydown||t.type==="keyup"&&n[a].keyup)&&d2(t,n[a],s,e);if(!(r in ft))return;const o=ft[r],i=o.length;for(let a=0;a<i;a++)if((t.type==="keydown"&&o[a].keydown||t.type==="keyup"&&o[a].keyup)&&o[a].key){const l=o[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let f=0;f<u.length;f++)h.push(Md(u[f]));h.sort().join("")===it.sort().join("")&&d2(t,l,s,e)}}function Wn(t,e,n){it=[];const r=E4(t);let s=[],o="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,f=!1;for(n===void 0&&typeof e=="function"&&(n=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(o=e.scope),e.element&&(i=e.element),e.keyup&&(l=e.keyup),e.keydown!==void 0&&(c=e.keydown),e.capture!==void 0&&(h=e.capture),typeof e.splitKey=="string"&&(u=e.splitKey),e.single===!0&&(f=!0)),typeof e=="string"&&(o=e),f&&M4(t,o);a<r.length;a++)t=r[a].split(u),s=[],t.length>1&&(s=I4(Us,t)),t=t[t.length-1],t=t==="*"?"*":Md(t),t in ft||(ft[t]=[]),ft[t].push({keyup:l,keydown:c,scope:o,mods:s,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!ro.has(i)){const p=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return h2(m,i)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;h2(m,i),kpe(m)};ro.set(i,{keydownListener:p,keyupListenr:g,capture:h}),MS(i,"keydown",p,h),MS(i,"keyup",g,h)}if(!gu){const p=()=>{it=[]};gu={listener:p,capture:h},MS(window,"focus",p,h)}}}function Tpe(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ft).forEach(n=>{ft[n].filter(s=>s.scope===e&&s.shortcut===t).forEach(s=>{s&&s.method&&s.method()})})}function J1(t){const e=Object.values(ft).flat();if(e.findIndex(r=>{let{element:s}=r;return s===t})<0){const{keydownListener:r,keyupListenr:s,capture:o}=ro.get(t)||{};r&&s&&($c(t,"keyup",s,o),$c(t,"keydown",r,o),ro.delete(t))}if((e.length<=0||ro.size<=0)&&(Object.keys(ro).forEach(s=>{const{keydownListener:o,keyupListenr:i,capture:a}=ro.get(s)||{};o&&i&&($c(s,"keyup",i,a),$c(s,"keydown",o,a),ro.delete(s))}),ro.clear(),Object.keys(ft).forEach(s=>delete ft[s]),gu)){const{listener:s,capture:o}=gu;$c(window,"focus",s,o),gu=null}}const AS={getPressedKeyString:Ppe,setScope:T4,getScope:Qu,deleteScope:Epe,getPressedKeyCodes:bpe,getAllKeyCodes:Cpe,isPressed:Ipe,filter:_pe,trigger:Tpe,unbind:M4,keyMap:Zu,modifier:Us,modifierMap:Nf};for(const t in AS)Object.prototype.hasOwnProperty.call(AS,t)&&(Wn[t]=AS[t]);if(typeof window<"u"){const t=window.hotkeys;Wn.noConflict=e=>(e&&window.hotkeys===Wn&&(window.hotkeys=t),Wn),window.hotkeys=Wn}const f2=["copy","cut","paste","asset"];function Mpe(){const t=z(),e=wr(),n=ka(),r=E1(),s=U("is focused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!s)return;const o=new Array,i=(l,c)=>{Wn(l,{element:document.body},c),o.push(()=>{Wn.unbind(l,c)})},a=(l,c)=>{Wn(l,{element:document.body,keyup:!0,keydown:!1},c),o.push(()=>{Wn.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(e&&!l.readonlyOk||f2.includes(l.id)||i(p2(l.kbd),c=>{Zc(t)||(xe(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getIsReadonly()||f2.includes(l.id)||i(p2(l.kbd),c=>{Zc(t)||(xe(c),l.onSelect("kbd"))});return i(",",l=>{if(Zc(t)||t.inputs.keys.has("Comma"))return;xe(l),t.focus(),t.inputs.keys.add("Comma");const{x:c,y:u,z:h}=t.inputs.currentPagePoint,f=t.pageToScreen({x:c,y:u}),p={type:"pointer",name:"pointer_down",point:{x:f.x,y:f.y,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(p)}),a(",",l=>{if(Zc(t)||!t.inputs.keys.has("Comma"))return;t.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=t.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(f)}),()=>{o.forEach(l=>l())}},[n,r,e,t,s])}function p2(t){return Ape(t).map(e=>{let n="";const r=e.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=e,n}).join(",")}function Ape(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function Zc(t){return t.menus.hasAnyOpenMenus()||t.getEditingShapeId()!==null||t.getCrashingError()}const jpe=w.createContext(!1);function Ope({children:t}){const e=z(),n=Jl(),r=An(),s=Ee(),o=Math.min(8,5+r),[i,a]=w.useState(0),l=w.useRef(null),[c,u]=w.useState(null),h=w.useMemo(()=>{const p=c?`:not([data-value="${c}"])`:"";return`
|
|
411
|
+
}`,o=e.createShader(e.FRAGMENT_SHADER);if(!o)throw new Error("Failed to create fragment shader");if(e.shaderSource(o,s),e.compileShader(o),!e.getShaderParameter(o,e.COMPILE_STATUS))throw new Error("Failed to compile fragment shader");const i=e.createProgram();if(!i)throw new Error("Failed to create program");if(e.attachShader(i,r),e.attachShader(i,o),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("Failed to link program");e.useProgram(i);const a=e.getAttribLocation(i,"shapeVertexPosition");if(a<0)throw new Error("Failed to get shapeVertexPosition attribute location");e.enableVertexAttribArray(a);const l=e.getUniformLocation(i,"canvasPageBounds"),c=e.getUniformLocation(i,"fillColor");if(!e.createBuffer())throw new Error("Failed to create buffer");if(!e.createBuffer())throw new Error("Failed to create buffer");return{context:e,selectedShapes:Bh(e,1024),unselectedShapes:Bh(e,4096),viewport:Bh(e,XF),collaborators:Bh(e,1024),prepareTriangles(f,p){e.bindBuffer(e.ARRAY_BUFFER,f.buffer),e.bufferData(e.ARRAY_BUFFER,f.vertices,e.STATIC_DRAW,0,p),e.enableVertexAttribArray(a),e.vertexAttribPointer(a,2,e.FLOAT,!1,0,0)},drawTrianglesTransparently(f){e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.drawArrays(e.TRIANGLES,0,f/2),e.disable(e.BLEND)},drawTriangles(f){e.drawArrays(e.TRIANGLES,0,f/2)},setFillColor(f){e.uniform4fv(c,f)},setCanvasPageBounds(f){e.uniform4fv(l,f)}}}function Bh(t,e){const n=t.createBuffer();if(!n)throw new Error("Failed to create buffer");return{buffer:n,vertices:new Float32Array(e)}}function c2(t,e,n){let r=t.vertices.length;for(;r<e+n.length;)r*=2;if(r!=t.vertices.length){const s=new Float32Array(r);s.set(t.vertices),t.vertices=s}t.vertices.set(n,e)}var zhe=Object.create,qF=Object.defineProperty,Bhe=Object.getOwnPropertyDescriptor,Uhe=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t),ZF=t=>{throw TypeError(t)},QF=(t,e,n)=>e in t?qF(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hhe=t=>[,,,zhe(null)],JF=["class","method","getter","setter","accessor","field","value","get","set"],eN=t=>t!==void 0&&typeof t!="function"?ZF("Function expected"):t,Khe=(t,e,n,r,s)=>({kind:JF[t],name:e,metadata:r,addInitializer:o=>n._?ZF("Already initialized"):s.push(eN(o||null))}),Whe=(t,e)=>QF(e,Uhe("metadata"),t[3]),Ghe=(t,e,n,r)=>{for(var s=0,o=t[e>>1],i=o&&o.length;s<i;s++)o[s].call(n);return r},Vs=(t,e,n,r,s,o)=>{for(var i,a,l,c,u=e&7,h=!1,f=!1,p=2,g=JF[u+5],m=t[p]||(t[p]=[]),v=(s=s.prototype,Bhe(s,n)),y=r.length-1;y>=0;y--)l=Khe(u,n,a={},t[3],m),l.static=h,l.private=f,c=l.access={has:S=>n in S},c.get=S=>S[n],i=(0,r[y])(v[g],l),a._=1,eN(i)&&(v[g]=i);return v&&qF(s,n,v),s},Js=(t,e,n)=>QF(t,typeof e!="symbol"?e+"":e,n),tN,nN,rN,sN,oN,iN,aN,lN,cN,uN,br;uN=[Kn],cN=[G],lN=[G],aN=[G],iN=[G],oN=[G],sN=[G],rN=[G],nN=[G],tN=[Kn];class Br{constructor(e,n,r){this.editor=e,this.elem=n,this.container=r,Ghe(br,5,this),Js(this,"disposables",[]),Js(this,"gl"),Js(this,"shapeGeometryCache"),Js(this,"colors"),Js(this,"id",ze()),Js(this,"canvasBoundingClientRect",It("canvasBoundingClientRect",new Z)),Js(this,"originPagePoint",new x),Js(this,"originPageCenter",new x),Js(this,"isInViewport",!1),this.gl=Nhe(n),this.shapeGeometryCache=e.store.createComputedCache("webgl-geometry",s=>{const o=e.getShapeMaskedPageBounds(s.id);if(!o)return null;const i=new Float32Array(12);return Wa(i,0,o.x,o.y,o.w,o.h),i}),this.colors=this._getColors(),this.disposables.push(this._listenForCanvasResize(),As("minimap render",this.render))}close(){return this.disposables.forEach(e=>e())}_getColors(){const e=getComputedStyle(this.editor.getContainer());return{shapeFill:Rc(e.getPropertyValue("--color-text-3").trim()),selectFill:Rc(e.getPropertyValue("--color-selected").trim()),viewportFill:Rc(e.getPropertyValue("--color-muted-1").trim()),background:Rc(e.getPropertyValue("--color-low").trim())}}updateColors(){this.colors=this._getColors()}getDpr(){return this.editor.getInstanceState().devicePixelRatio}getContentPageBounds(){const e=this.editor.getViewportPageBounds(),n=this.editor.getCurrentPageBounds();return n?Z.Expand(n,e):e}getContentScreenBounds(){const e=this.getContentPageBounds(),n=this.editor.pageToScreen(e.point),r=this.editor.pageToScreen(new x(e.maxX,e.maxY));return new Z(n.x,n.y,r.x-n.x,r.y-n.y)}_getCanvasBoundingRect(){const{x:e,y:n,width:r,height:s}=this.elem.getBoundingClientRect();return new Z(e,n,r,s)}getCanvasScreenBounds(){return this.canvasBoundingClientRect.get()}_listenForCanvasResize(){const e=new ResizeObserver(()=>{const n=this._getCanvasBoundingRect();this.canvasBoundingClientRect.set(n)});return e.observe(this.elem),e.observe(this.container),()=>e.disconnect()}getCanvasSize(){const e=this.canvasBoundingClientRect.get(),n=this.getDpr();return new x(e.width*n,e.height*n)}getCanvasClientPosition(){return this.canvasBoundingClientRect.get().point}getCanvasPageBounds(){const e=this.getCanvasScreenBounds(),n=this.getContentPageBounds(),r=e.width/e.height;let s=n.width,o=s/r;o<n.height&&(o=n.height,s=o*r);const i=new Z(0,0,s,o);return i.center=n.center,i}getZoom(){return this.getCanvasPageBounds().width/this.getCanvasScreenBounds().width}getCanvasPageBoundsArray(){const{x:e,y:n,w:r,h:s}=this.getCanvasPageBounds();return new Float32Array([e,n,r,s])}getMinimapPagePoint(e,n){const r=this.getCanvasPageBounds(),s=this.getCanvasScreenBounds();let o=e-s.x,i=n-s.y;return o*=r.width/s.width,i*=r.height/s.height,o+=r.minX,i+=r.minY,new x(o,i,1)}minimapScreenPointToPagePoint(e,n,r=!1,s=!1){const{editor:o}=this,i=o.getViewportPageBounds();let{x:a,y:l}=this.getMinimapPagePoint(e,n);if(s){const c=this.editor.getCurrentPageBounds()??new Z,u=c.minX-i.width/2,h=c.maxX+i.width/2,f=c.minY-i.height/2,p=c.maxY+i.height/2,g=Math.max(0,u+i.width-a),m=Math.max(0,-(h-i.width-a)),v=Math.max(0,f+i.height-l),y=Math.max(0,-(p-i.height-l));a+=(g-m)/2,l+=(v-y)/2,a=Bt(a,u,h),l=Bt(l,f,p)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),h=Math.abs(l-c.y);u>h?l=c.y:a=c.x}return new x(a,l)}render(){const e=this.gl.context,n=this.getCanvasSize();this.gl.setCanvasPageBounds(this.getCanvasPageBoundsArray()),this.elem.width=n.x,this.elem.height=n.y,e.viewport(0,0,n.x,n.y),e.clearColor(this.colors.background[0],this.colors.background[1],this.colors.background[2],1),e.clear(e.COLOR_BUFFER_BIT);const r=new Set(this.editor.getSelectedShapeIds()),s=this.colors;let o=0,i=0;const a=this.editor.getCurrentPageShapeIdsSorted();for(let l=0,c=a.length;l<c;l++){const u=a[l],h=this.shapeGeometryCache.get(u);if(!h)continue;const f=h.length;r.has(u)?(c2(this.gl.selectedShapes,o,h),o+=f):(c2(this.gl.unselectedShapes,i,h),i+=f)}this.drawShapes(this.gl.unselectedShapes,i,s.shapeFill),this.drawShapes(this.gl.selectedShapes,o,s.selectFill),this.drawViewport(),this.drawCollaborators()}drawShapes(e,n,r){this.gl.prepareTriangles(e,n),this.gl.setFillColor(r),this.gl.drawTriangles(n)}drawViewport(){const e=this.editor.getViewportPageBounds(),n=Fhe(this.gl.viewport.vertices,e,4*this.getZoom());this.gl.prepareTriangles(this.gl.viewport,n),this.gl.setFillColor(this.colors.viewportFill),this.gl.drawTrianglesTransparently(n),Ge.isSafari&&(this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n),this.gl.drawTrianglesTransparently(n))}drawCollaborators(){const e=this.editor.getCollaboratorsOnCurrentPage();if(!e.length)return;const n=20,r=n*6,s=r*e.length;this.gl.collaborators.vertices.length<s&&(this.gl.collaborators.vertices=new Float32Array(s));const o=this.gl.collaborators.vertices;let i=0;const a=this.getZoom();for(const{cursor:l}of e)l&&(Ka(o,{center:x.From(l),radius:3*a,offset:i,numArcSegments:n}),i+=r);this.gl.prepareTriangles(this.gl.collaborators,s),i=0;for(const{color:l}of e)this.gl.setFillColor(Rc(l)),this.gl.context.drawArrays(this.gl.context.TRIANGLES,i/2,r/2),i+=r}}br=Hhe();Vs(br,1,"close",uN,Br);Vs(br,1,"getDpr",cN,Br);Vs(br,1,"getContentPageBounds",lN,Br);Vs(br,1,"getContentScreenBounds",aN,Br);Vs(br,1,"getCanvasSize",iN,Br);Vs(br,1,"getCanvasClientPosition",oN,Br);Vs(br,1,"getCanvasPageBounds",sN,Br);Vs(br,1,"getZoom",rN,Br);Vs(br,1,"getCanvasPageBoundsArray",nN,Br);Vs(br,1,"render",tN,Br);Whe(br,Br);function Vhe(){const t=z(),e=Tt(),n=w.useRef(null),r=w.useRef(!1),s=w.useRef();w.useEffect(()=>{try{const u=new Br(t,n.current,e);return s.current=u,s.current.close}catch(u){t.annotateError(u,{origin:"minimap",willCrashApp:!1}),t.timers.setTimeout(()=>{throw u})}},[t,e]);const o=w.useCallback(u=>{if(!t.getCurrentPageShapeIds().size||!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),f=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.originPagePoint.setTo(f),s.current.originPageCenter.setTo(t.getViewportPageBounds().center),t.centerOnPoint(h,{animation:{duration:t.options.animationMediumMs}})},[t]),i=w.useCallback(u=>{if(!s.current)return;const h=u.currentTarget;if(dd(h,u),!t.getCurrentPageShapeIds().size)return;r.current=!0,s.current.isInViewport=!1;const f=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!1),p=t.getViewportPageBounds(),g=s.current.getContentPageBounds();if(new Z(g.x-p.width/2,g.y-p.height/2,g.width+p.width,g.height+p.height).containsPoint(f)&&!p.containsPoint(f)){s.current.isInViewport=p.containsPoint(f);const y=x.Sub(p.center,p.point),S=x.Add(f,y);s.current.originPagePoint.setTo(S),s.current.originPageCenter.setTo(f),t.centerOnPoint(f,{animation:{duration:t.options.animationMediumMs}})}else{const y=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,!1,!0);s.current.isInViewport=p.containsPoint(y),s.current.originPagePoint.setTo(y),s.current.originPageCenter.setTo(p.center)}function v(y){h&&hd(h,y),r.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[t]),a=w.useCallback(u=>{if(!s.current)return;const h=s.current.minimapScreenPointToPagePoint(u.clientX,u.clientY,u.shiftKey,!0);if(r.current){if(s.current.isInViewport){const m=s.current.originPagePoint.clone().sub(s.current.originPageCenter);t.centerOnPoint(x.Sub(h,m));return}t.centerOnPoint(h)}const f=s.current.getMinimapPagePoint(u.clientX,u.clientY),p=t.pageToScreen(f),g={type:"pointer",target:"canvas",name:"pointer_move",...lr(u),point:p,isPen:t.getInstanceState().isPenMode};t.dispatch(g)},[t]),l=w.useCallback(u=>{const h=wj(u);t.dispatch({type:"wheel",name:"wheel",delta:h,point:new x(u.clientX,u.clientY),shiftKey:u.shiftKey,altKey:u.altKey,ctrlKey:u.metaKey||u.ctrlKey,metaKey:u.metaKey,accelKey:un(u)})},[t]),c=xd();return w.useEffect(()=>{t.timers.setTimeout(()=>{var u,h;(u=s.current)==null||u.updateColors(),(h=s.current)==null||h.render()})},[c,t]),d.jsx("div",{className:"tlui-minimap",children:d.jsx("canvas",{role:"img","aria-label":"minimap",ref:n,className:"tlui-minimap__canvas",onDoubleClick:o,onPointerMove:a,onPointerDown:i,onWheelCapture:l})})}function Yhe(t,e){const[n,r]=ke.useState(e);ke.useLayoutEffect(()=>{const o=_0(t);if(o)try{r(JSON.parse(o))}catch{console.error(`Could not restore value ${t} from local storage.`)}},[t]);const s=ke.useCallback(o=>{r(i=>{const a=typeof o=="function"?o(i):o;return I0(t,JSON.stringify(a)),a})},[t]);return[n,s]}const Xhe=w.memo(function(){const e=ka(),n=Ee(),r=An(),s=w.useRef(null);Ai(s);const[o,i]=Yhe("minimap",!0),a=w.useCallback(()=>{i(u=>!u)},[i]),{ZoomMenu:l,Minimap:c}=Ri();return r<St.MOBILE?null:d.jsxs("div",{ref:s,className:"tlui-navigation-panel",children:[d.jsx("div",{className:"tlui-buttons__horizontal",children:l&&r<St.TABLET?d.jsx(l,{}):o?d.jsxs(d.Fragment,{children:[l&&d.jsx(l,{}),c&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):d.jsxs(d.Fragment,{children:[d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-out",title:`${n(Xu(e["zoom-out"].label))} ${Xx(e["zoom-out"].kbd)}`,onClick:()=>e["zoom-out"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"minus"})}),l&&d.jsx(l,{}),d.jsx(ue,{type:"icon","data-testid":"minimap.zoom-in",title:`${n(Xu(e["zoom-in"].label))} ${Xx(e["zoom-in"].kbd)}`,onClick:()=>e["zoom-in"].onSelect("navigation-zone"),children:d.jsx(be,{icon:"plus"})}),c&&d.jsx(ue,{type:"icon","data-testid":"minimap.toggle-button",title:n("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:a,children:d.jsx(be,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),c&&r>=St.TABLET&&!o&&d.jsx(c,{})]})}),qhe=function({name:e,id:n,isCurrentPage:r,onCancel:s}){const o=z(),i=Jt(),a=w.useRef(null),l=w.useRef(null),c=w.useCallback(()=>{l.current=o.markHistoryStoppingPoint("rename page")},[o]),u=w.useCallback(f=>{o.renamePage(n,f||"New Page"),i("rename-page",{source:"page-menu"})},[o,n,i]),h=w.useCallback(()=>{l.current&&o.bailToMark(l.current),s()},[o,s]);return d.jsx(pm,{className:"tlui-page-menu__item__input",ref:f=>a.current=f,defaultValue:e,onValueChange:u,onCancel:h,onFocus:c,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:r,autoSelect:!0})},gw=(t,e,n,r,s)=>{let o;const i=t.getPages(),a=n>r?i[r-1]:i[r],l=n>r?i[r]:i[r+1];a&&!l?o=_s(a.index):!a&&l?o=aB(i[0].index):o=$u(a.index,l.index),o!==i[n].index&&(t.markHistoryStoppingPoint("moving page"),t.updatePage({id:e,index:o}),s("move-page",{source:"page-menu"}))},u2=Zt(function({index:e,listSize:n,item:r,onRename:s}){const o=z(),i=Ee(),a=o.getPages(),l=Jt(),c=w.useCallback(()=>{o.markHistoryStoppingPoint("creating page");const p=yr.createId();o.duplicatePage(r.id,p),l("duplicate-page",{source:"page-menu"})},[o,r,l]),u=w.useCallback(()=>{gw(o,r.id,e,e-1,l)},[o,r,e,l]),h=w.useCallback(()=>{gw(o,r.id,e,e+1,l)},[o,r,e,l]),f=w.useCallback(()=>{o.markHistoryStoppingPoint("deleting page"),o.deletePage(r.id),l("delete-page",{source:"page-menu"})},[o,r,l]);return d.jsxs(ma,{id:`page item submenu ${e}`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon",title:i("page-menu.submenu.title"),children:d.jsx(be,{icon:"dots-vertical",small:!0})})}),d.jsx(Sa,{alignOffset:0,side:"right",sideOffset:-4,children:d.jsxs(Fr,{type:"menu",sourceId:"page-menu",children:[d.jsxs(ve,{id:"modify",children:[s&&d.jsx(Kt,{id:"rename",label:"page-menu.submenu.rename",onSelect:s}),d.jsx(Kt,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:c,disabled:a.length>=o.options.maxPages}),e>0&&d.jsx(Kt,{id:"move-up",onSelect:u,label:"page-menu.submenu.move-up"}),e<n-1&&d.jsx(Kt,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:h})]}),n>1&&d.jsx(ve,{id:"delete",children:d.jsx(Kt,{id:"delete",onSelect:f,label:"page-menu.submenu.delete"})})]})})]})}),Zhe=w.memo(function(){const e=z(),n=Jt(),r=Ee(),s=An(),o=w.useCallback(()=>y(!1),[]),[i,a]=Mo("page-menu",o),l=36,c=w.useRef(null),u=U("pages",()=>e.getPages(),[e]),h=U("currentPage",()=>e.getCurrentPage(),[e]),f=U("currentPageId",()=>e.getCurrentPageId(),[e]),p=wr(),g=U("maxPageCountReached",()=>e.getPages().length>=e.options.maxPages,[e]),m=U("isCoarsePointer",()=>e.getInstanceState().isCoarsePointer,[e]),[v,y]=w.useState(!1),S=w.useCallback(()=>{p||y(M=>!M)},[p]),b=w.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[P,C]=w.useState(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])));w.useLayoutEffect(()=>{C(Object.fromEntries(u.map((M,O)=>[M.id,{y:O*l,offsetY:0,isSelected:!1}])))},[l,u]),w.useEffect(()=>{i&&e.timers.requestAnimationFrame(()=>{const M=document.querySelector(`[data-testid="page-menu-item-${f}"]`);if(M){const O=c.current;if(!O)return;const F=M.offsetTop,B=O.scrollTop;F<B&&O.scrollTo({top:F});const K=F+l,R=O.scrollTop+O.offsetHeight;K>R&&O.scrollTo({top:K-O.offsetHeight})}})},[l,f,i,e]);const _=w.useCallback(M=>{const{clientY:O,currentTarget:F}=M,{dataset:{id:B,index:K}}=F;if(!B||!K)return;const R=b.current;dd(M.currentTarget,M),R.status="pointing",R.pointing={id:B,index:+K};const X=P[B].y;R.startY=O,R.startIndex=Math.max(0,Math.min(Math.round(X/l),u.length-1))},[l,u.length,P]),E=w.useCallback(M=>{const O=b.current;if(O.status==="pointing"){const{clientY:F}=M,B=F-O.startY;Math.abs(B)>5&&(O.status="dragging")}if(O.status==="dragging"){const{clientY:F}=M,B=F-O.startY,K=P[O.pointing.id],{startIndex:R,pointing:H}=O,X=K.y+B,te=Math.max(0,Math.min(Math.round(X/l),u.length-1)),le={...P};if(le[H.id]={y:K.y,offsetY:B,isSelected:!0},te!==O.dragIndex){O.dragIndex=te;for(let de=0;de<u.length;de++){const Me=u[de];if(Me.id===O.pointing.id)continue;let{y:oe}=le[Me.id];te===R?oe=de*l:te<R?te<=de&&de<R?oe=(de+1)*l:oe=de*l:te>R&&(te>=de&&de>R?oe=(de-1)*l:oe=de*l),oe!==le[Me.id].y&&(le[Me.id]={y:oe,offsetY:0,isSelected:!0})}}C(le)}},[l,u,P]),k=w.useCallback(M=>{const O=b.current;if(O.status==="dragging"){const{id:F,index:B}=O.pointing;gw(e,F,B,O.dragIndex,n)}hd(M.currentTarget,M),O.status="idle"},[e,n]),D=w.useCallback(M=>{const O=b.current;M.key==="Escape"&&(O.status==="dragging"&&C(Object.fromEntries(u.map((F,B)=>[F.id,{y:B*l,offsetY:0,isSelected:!1}]))),O.status="idle")},[l,u]),T=w.useCallback(()=>{p||(e.run(()=>{e.markHistoryStoppingPoint("creating page");const M=yr.createId();e.createPage({name:r("page-menu.new-page-initial-name"),id:M}),e.setCurrentPage(M),y(!0)}),n("new-page",{source:"page-menu"}))},[e,r,p,n]),j=w.useCallback(M=>{e.setCurrentPage(M),n("change-page",{source:"page-menu"})},[e,n]),L=w.useCallback((M,O)=>{e.renamePage(M,O),n("rename-page",{source:"page-menu"})},[e,n]);return d.jsxs(V1,{id:"pages",onOpenChange:a,open:i,children:[d.jsx(Y1,{"data-testid":"main.page-menu",children:d.jsxs(ue,{type:"menu",title:h.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[d.jsx("div",{className:"tlui-page-menu__name",children:h.name}),d.jsx(be,{icon:"chevron-down",small:!0})]})}),d.jsx(X1,{side:"bottom",align:"start",sideOffset:6,disableEscapeKeyDown:v,children:d.jsxs("div",{className:"tlui-page-menu__wrapper",children:[d.jsxs("div",{className:"tlui-page-menu__header",children:[d.jsx("div",{className:"tlui-page-menu__header__title",children:r("page-menu.title")}),!p&&d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsx(ue,{type:"icon","data-testid":"page-menu.edit",title:r(v?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:d.jsx(be,{icon:v?"check":"edit"})}),d.jsx(ue,{type:"icon","data-testid":"page-menu.create",title:r(g?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:g,onClick:T,children:d.jsx(be,{icon:"plus"})})]})]}),d.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:l*u.length+4},ref:c,children:u.map((M,O)=>{const F=P[M.id]??{position:O*40,offsetY:0};return v?d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:M.id===h.id?888:O,transform:`translate(0px, ${F.y+F.offsetY}px)`},children:[d.jsx(ue,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:_,onPointerUp:k,onPointerMove:E,onKeyDown:D,"data-id":M.id,"data-index":O,children:d.jsx(be,{icon:"drag-handle-dots"})}),s<St.TABLET_SM&&m?d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const B=window.prompt("Rename page",M.name);B&&B!==M.name&&L(M.id,B)},onDoubleClick:S,children:[d.jsx(pw,{checked:M.id===h.id}),d.jsx(bt,{children:M.name})]}):d.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:l},children:d.jsx(qhe,{id:M.id,name:M.name,isCurrentPage:M.id===h.id,onCancel:()=>{y(!1),e.menus.clearOpenMenus()}})}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":v,children:d.jsx(u2,{index:O,item:M,listSize:u.length})})]},M.id+"_editing"):d.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[d.jsxs(ue,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>j(M.id),onDoubleClick:S,title:r("page-menu.go-to-page"),children:[d.jsx(pw,{checked:M.id===h.id}),d.jsx(bt,{children:M.name})]}),!p&&d.jsx("div",{className:"tlui-page_menu__item__submenu",children:d.jsx(u2,{index:O,item:M,listSize:u.length,onRename:()=>{if(Ge.isIos){const B=window.prompt("Rename page",M.name);B&&B!==M.name&&L(M.id,B)}else y(!0),f!==M.id&&j(M.id)}})})]},M.id)})})]})})]})});function Qhe(){const t=z(),e=wr(),n=U("should display quick actions",()=>t.isInAny("select","hand","zoom"),[t]);if(!(e&&!n))return d.jsxs(d.Fragment,{children:[d.jsx(efe,{}),d.jsx(Jhe,{})]})}function Jhe(){const t=jn(1),e=Ao(),n=t&&e;return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"delete",disabled:!n}),d.jsx(W,{actionId:"duplicate",disabled:!n})]})}function efe(){const t=kF(),e=EF();return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"undo",disabled:!t}),d.jsx(W,{actionId:"redo",disabled:!e})]})}const tfe=w.memo(function({children:e}){const n=e??d.jsx(Qhe,{});return d.jsx(Fr,{type:"small-icons",sourceId:"quick-actions",children:n})});function nfe({userId:t}){const e=Lg(t);return e?d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:e.color},children:e.userName==="New User"?"":e.userName[0]??""},t):null}const rfe=Zt(function({userId:e}){const n=z(),r=Ee(),s=Jt(),o=Lg(e),i=w.useCallback(()=>{n.getInstanceState().followingUserId===e?(n.stopFollowingUser(),s("stop-following",{source:"people-menu"})):(n.startFollowingUser(e),s("start-following",{source:"people-menu"}))},[n,e,s]),a=(o==null?void 0:o.followingUserId)===n.user.getId(),l=n.getInstanceState().followingUserId===e;return o?d.jsxs("div",{className:"tlui-people-menu__item tlui-buttons__horizontal",children:[d.jsxs(ue,{type:"menu",className:"tlui-people-menu__item__button",onClick:()=>n.zoomToUser(e),onDoubleClick:i,children:[d.jsx(zs,{icon:"color",color:o.color}),d.jsx("div",{className:"tlui-people-menu__name",children:o.userName??"New User"})]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__item__follow",title:r(a?"people-menu.leading":l?"people-menu.following":"people-menu.follow"),onClick:i,disabled:a,"data-active":l||a,children:d.jsx(be,{icon:a?"leading":l?"following":"follow"})})]}):null});function sfe({count:t}){return d.jsx("div",{className:"tlui-people-menu__more",children:"+"+Math.abs(t)})}const ofe=Zt(function(){const e=z(),n=Tt(),r=Ee(),s=Jt(),o=w.useRef(!1),[i,a]=w.useState(!1),l=w.useCallback(m=>{a(m)},[]),c=e.user.getColor(),u=w.useCallback(m=>{e.user.updateUserPreferences({color:m}),s("set-color",{source:"people-menu"})},[e,s]),{handleButtonClick:h,handleButtonPointerDown:f,handleButtonPointerEnter:p,handleButtonPointerUp:g}=ke.useMemo(()=>{const m=()=>{o.current=!1,window.removeEventListener("pointerup",m)};return{handleButtonClick:P=>{const{id:C}=P.currentTarget.dataset;C&&c!==C&&u(C)},handleButtonPointerDown:P=>{const{id:C}=P.currentTarget.dataset;C&&(u(C),o.current=!0,window.addEventListener("pointerup",m))},handleButtonPointerEnter:P=>{if(!o.current)return;const{id:C}=P.currentTarget.dataset;C&&u(C)},handleButtonPointerUp:P=>{const{id:C}=P.currentTarget.dataset;C&&u(C)}}},[c,u]);return d.jsxs(H1,{onOpenChange:l,open:i,children:[d.jsx(K1,{dir:"ltr",asChild:!0,children:d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__color",style:{color:e.user.getColor()},title:r("people-menu.change-color"),children:d.jsx(be,{icon:"color"})})}),d.jsx(W1,{container:n,children:d.jsx(G1,{dir:"ltr",className:"tlui-menu tlui-people-menu__user__color-picker",align:"start",side:"left",sideOffset:8,children:d.jsx("div",{className:"tlui-buttons__grid",children:Px.map(m=>d.jsx(ue,{type:"icon","data-id":m,"data-testid":m,"aria-label":m,"data-state":c===m?"hinted":void 0,title:m,className:"tlui-button-grid__button",style:{color:m},onPointerEnter:p,onPointerDown:f,onPointerUp:g,onClick:h,children:d.jsx(be,{icon:"color"})},m))})})})]})});function ife(){const t=z(),e=Jt(),n=U("userName",()=>t.user.getName(),[]),r=Ee(),s=w.useRef(n),o=w.useRef(n),[i,a]=w.useState(!1),l=w.useCallback(()=>{a(f=>!f)},[]),c=w.useCallback(f=>{o.current=f,t.user.updateUserPreferences({name:f})},[t]),u=w.useCallback(()=>{s.current!==o.current&&(e("change-user-name",{source:"people-menu"}),s.current=o.current)},[e]),h=w.useCallback(()=>{a(!1),t.user.updateUserPreferences({name:s.current}),t.menus.clearOpenMenus()},[t]);return d.jsxs("div",{className:"tlui-people-menu__user",children:[d.jsx(ofe,{}),i?d.jsx(pm,{className:"tlui-people-menu__user__input",defaultValue:n,onValueChange:c,onComplete:l,onCancel:h,onBlur:u,shouldManuallyMaintainScrollPositionWhenFocused:!0,autoFocus:!0,autoSelect:!0}):d.jsxs(d.Fragment,{children:[d.jsx("div",{className:"tlui-people-menu__user__name",onDoubleClick:()=>{i||a(!0)},children:n}),n==="New User"?d.jsx("div",{className:"tlui-people-menu__user__label",children:r("people-menu.user")}):null]}),d.jsx(ue,{type:"icon",className:"tlui-people-menu__user__edit","data-testid":"people-menu.change-name",title:r("people-menu.change-name"),onClick:l,children:d.jsx(be,{icon:i?"check":"edit"})})]})}function afe({displayUserWhenAlone:t,children:e}){const n=Ee(),r=Tt(),s=z(),o=Cj(),i=U("user",()=>s.user.getColor(),[s]),a=U("user",()=>s.user.getName(),[s]),[l,c]=Mo("people menu");return d.jsxs(H1,{onOpenChange:c,open:l,children:[d.jsx(K1,{dir:"ltr",asChild:!0,children:d.jsxs("button",{className:"tlui-people-menu__avatars-button",title:n("people-menu.title"),children:[o.length>5&&d.jsx(sfe,{count:o.length-5}),d.jsxs("div",{className:"tlui-people-menu__avatars",children:[o.slice(-5).map(u=>d.jsx(nfe,{userId:u},u)),(t||o.length>0)&&d.jsx("div",{className:"tlui-people-menu__avatar",style:{backgroundColor:i},children:a==="New User"?"":a[0]??""})]})]})}),d.jsx(W1,{container:r,children:d.jsx(G1,{dir:"ltr",className:"tlui-menu",side:"bottom",sideOffset:2,collisionPadding:4,onEscapeKeyDown:xe,children:d.jsxs("div",{className:"tlui-people-menu__wrapper",children:[d.jsx("div",{className:"tlui-people-menu__section",children:d.jsx(ife,{})}),o.length>0&&d.jsx("div",{className:"tlui-people-menu__section",children:o.map(u=>d.jsx(rfe,{userId:u},u+"_presence"))}),e]})})})]})}function lfe(){return d.jsx("div",{className:"tlui-share-zone",draggable:!1,children:d.jsx(afe,{displayUserWhenAlone:!0})})}const cfe=Object.freeze([mr,ua,da,$s]);function dN(t=cfe){const e=z();return U("getRelevantStyles",()=>{var o;const n=new Tx(e.getSharedStyles()),r=!!((o=e.root.getCurrent())!=null&&o.shapeType),s=e.isIn("select")&&e.getSelectedShapeIds().length>0;if(n.size===0&&e.isIn("select")&&e.getSelectedShapeIds().length===0)for(const i of t)n.applyValue(i,e.getStyleForNextShape(i));return r||s||n.size>0?n:null},[e])}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"}],textAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],horizontalAlign:[{value:"start",icon:"horizontal-align-start"},{value:"middle",icon:"horizontal-align-middle"},{value:"end",icon:"horizontal-align-end"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-middle"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"star",icon:"geo-star"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"cloud",icon:"geo-cloud"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"},{value:"heart",icon:"geo-heart"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]},Xi=w.memo(function(e){const{uiType:n,items:r,title:s,style:o,value:i,onValueChange:a,onHistoryMark:l,theme:c}=e,u=Ee(),h=w.useRef(!1),f=w.useRef(null),{handleButtonClick:p,handleButtonPointerDown:g,handleButtonPointerEnter:m,handleButtonPointerUp:v}=w.useMemo(()=>{const y=()=>{h.current=!1,window.removeEventListener("pointerup",y);const _=f.current;_&&["TEXTAREA","INPUT"].includes(_.nodeName)&&_.focus(),f.current=null};return{handleButtonClick:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||(l==null||l("point picker item"),a(o,E))},handleButtonPointerDown:_=>{const{id:E}=_.currentTarget.dataset;l==null||l("point picker item"),a(o,E),h.current=!0,f.current=document.activeElement,window.addEventListener("pointerup",y)},handleButtonPointerEnter:_=>{if(!h.current)return;const{id:E}=_.currentTarget.dataset;a(o,E)},handleButtonPointerUp:_=>{const{id:E}=_.currentTarget.dataset;i.type==="shared"&&i.value===E||a(o,E)}}},[i,l,a,o]);return d.jsx("div",{"data-testid":`style.${n}`,className:ce("tlui-buttons__grid"),children:r.map(y=>d.jsx(ue,{type:"icon","data-id":y.value,"data-testid":`style.${n}.${y.value}`,"aria-label":y.value,"data-state":i.type==="shared"&&i.value===y.value?"hinted":void 0,title:s+" — "+u(`${n}-style.${y.value}`),className:ce("tlui-button-grid__button"),style:o===mr?{color:c[y.value].solid}:void 0,onPointerEnter:m,onPointerDown:g,onPointerUp:v,onClick:p,children:d.jsx(be,{icon:y.icon})},y.value))})});function hN(t,[e,n]){return Math.min(n,Math.max(e,t))}function ufe(t){const e=w.useRef({value:t,previous:t});return w.useMemo(()=>(e.current.value!==t&&(e.current.previous=e.current.value,e.current.value=t),e.current.previous),[t])}var fN=["PageUp","PageDown"],pN=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],gN={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},lc="Slider",[mw,dfe,hfe]=Jg(lc),[mN,Rge]=Ws(lc,[hfe]),[ffe,Tm]=mN(lc),yN=w.forwardRef((t,e)=>{const{name:n,min:r=0,max:s=100,step:o=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:h=()=>{},onValueCommit:f=()=>{},inverted:p=!1,form:g,...m}=t,v=w.useRef(new Set),y=w.useRef(0),b=i==="horizontal"?pfe:gfe,[P=[],C]=ji({prop:u,defaultProp:c,onChange:j=>{var M;(M=[...v.current][y.current])==null||M.focus(),h(j)}}),_=w.useRef(P);function E(j){const L=xfe(P,j);T(j,L)}function k(j){T(j,y.current)}function D(){const j=_.current[y.current];P[y.current]!==j&&f(P)}function T(j,L,{commit:M}={commit:!1}){const O=Cfe(o),F=_fe(Math.round((j-r)/o)*o+r,O),B=hN(F,[r,s]);C((K=[])=>{const R=Sfe(K,B,L);if(Pfe(R,l*o)){y.current=R.indexOf(B);const H=String(R)!==String(K);return H&&M&&f(R),H?R:K}else return K})}return d.jsx(ffe,{scope:t.__scopeSlider,name:n,disabled:a,min:r,max:s,valueIndexToChangeRef:y,thumbs:v.current,values:P,orientation:i,form:g,children:d.jsx(mw.Provider,{scope:t.__scopeSlider,children:d.jsx(mw.Slot,{scope:t.__scopeSlider,children:d.jsx(b,{"aria-disabled":a,"data-disabled":a?"":void 0,...m,ref:e,onPointerDown:se(m.onPointerDown,()=>{a||(_.current=P)}),min:r,max:s,inverted:p,onSlideStart:a?void 0:E,onSlideMove:a?void 0:k,onSlideEnd:a?void 0:D,onHomeKeyDown:()=>!a&&T(r,0,{commit:!0}),onEndKeyDown:()=>!a&&T(s,P.length-1,{commit:!0}),onStepKeyDown:({event:j,direction:L})=>{if(!a){const F=fN.includes(j.key)||j.shiftKey&&pN.includes(j.key)?10:1,B=y.current,K=P[B],R=o*F*L;T(K+R,B,{commit:!0})}}})})})})});yN.displayName=lc;var[SN,vN]=mN(lc,{startEdge:"left",endEdge:"right",size:"width",direction:1}),pfe=w.forwardRef((t,e)=>{const{min:n,max:r,dir:s,inverted:o,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=t,[h,f]=w.useState(null),p=Qe(e,b=>f(b)),g=w.useRef(void 0),m=Fb(s),v=m==="ltr",y=v&&!o||!v&&o;function S(b){const P=g.current||h.getBoundingClientRect(),C=[0,P.width],E=Z1(C,y?[n,r]:[r,n]);return g.current=P,E(b-P.left)}return d.jsx(SN,{scope:t.__scopeSlider,startEdge:y?"left":"right",endEdge:y?"right":"left",direction:y?1:-1,size:"width",children:d.jsx(xN,{dir:m,"data-orientation":"horizontal",...u,ref:p,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:b=>{const P=S(b.clientX);i==null||i(P)},onSlideMove:b=>{const P=S(b.clientX);a==null||a(P)},onSlideEnd:()=>{g.current=void 0,l==null||l()},onStepKeyDown:b=>{const C=gN[y?"from-left":"from-right"].includes(b.key);c==null||c({event:b,direction:C?-1:1})}})})}),gfe=w.forwardRef((t,e)=>{const{min:n,max:r,inverted:s,onSlideStart:o,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=t,u=w.useRef(null),h=Qe(e,u),f=w.useRef(void 0),p=!s;function g(m){const v=f.current||u.current.getBoundingClientRect(),y=[0,v.height],b=Z1(y,p?[r,n]:[n,r]);return f.current=v,b(m-v.top)}return d.jsx(SN,{scope:t.__scopeSlider,startEdge:p?"bottom":"top",endEdge:p?"top":"bottom",size:"height",direction:p?1:-1,children:d.jsx(xN,{"data-orientation":"vertical",...c,ref:h,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:m=>{const v=g(m.clientY);o==null||o(v)},onSlideMove:m=>{const v=g(m.clientY);i==null||i(v)},onSlideEnd:()=>{f.current=void 0,a==null||a()},onStepKeyDown:m=>{const y=gN[p?"from-bottom":"from-top"].includes(m.key);l==null||l({event:m,direction:y?-1:1})}})})}),xN=w.forwardRef((t,e)=>{const{__scopeSlider:n,onSlideStart:r,onSlideMove:s,onSlideEnd:o,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=t,u=Tm(lc,n);return d.jsx(Ae.span,{...c,ref:e,onKeyDown:se(t.onKeyDown,h=>{h.key==="Home"?(i(h),h.preventDefault()):h.key==="End"?(a(h),h.preventDefault()):fN.concat(pN).includes(h.key)&&(l(h),h.preventDefault())}),onPointerDown:se(t.onPointerDown,h=>{const f=h.target;f.setPointerCapture(h.pointerId),h.preventDefault(),u.thumbs.has(f)?f.focus():r(h)}),onPointerMove:se(t.onPointerMove,h=>{h.target.hasPointerCapture(h.pointerId)&&s(h)}),onPointerUp:se(t.onPointerUp,h=>{const f=h.target;f.hasPointerCapture(h.pointerId)&&(f.releasePointerCapture(h.pointerId),o(h))})})}),wN="SliderTrack",bN=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,s=Tm(wN,n);return d.jsx(Ae.span,{"data-disabled":s.disabled?"":void 0,"data-orientation":s.orientation,...r,ref:e})});bN.displayName=wN;var yw="SliderRange",PN=w.forwardRef((t,e)=>{const{__scopeSlider:n,...r}=t,s=Tm(yw,n),o=vN(yw,n),i=w.useRef(null),a=Qe(e,i),l=s.values.length,c=s.values.map(f=>_N(f,s.min,s.max)),u=l>1?Math.min(...c):0,h=100-Math.max(...c);return d.jsx(Ae.span,{"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,...r,ref:a,style:{...t.style,[o.startEdge]:u+"%",[o.endEdge]:h+"%"}})});PN.displayName=yw;var Sw="SliderThumb",CN=w.forwardRef((t,e)=>{const n=dfe(t.__scopeSlider),[r,s]=w.useState(null),o=Qe(e,a=>s(a)),i=w.useMemo(()=>r?n().findIndex(a=>a.ref.current===r):-1,[n,r]);return d.jsx(mfe,{...t,ref:o,index:i})}),mfe=w.forwardRef((t,e)=>{const{__scopeSlider:n,index:r,name:s,...o}=t,i=Tm(Sw,n),a=vN(Sw,n),[l,c]=w.useState(null),u=Qe(e,S=>c(S)),h=l?i.form||!!l.closest("form"):!0,f=m3(l),p=i.values[r],g=p===void 0?0:_N(p,i.min,i.max),m=vfe(r,i.values.length),v=f==null?void 0:f[a.size],y=v?wfe(v,g,a.direction):0;return w.useEffect(()=>{if(l)return i.thumbs.add(l),()=>{i.thumbs.delete(l)}},[l,i.thumbs]),d.jsxs("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[a.startEdge]:`calc(${g}% + ${y}px)`},children:[d.jsx(mw.ItemSlot,{scope:t.__scopeSlider,children:d.jsx(Ae.span,{role:"slider","aria-label":t["aria-label"]||m,"aria-valuemin":i.min,"aria-valuenow":p,"aria-valuemax":i.max,"aria-orientation":i.orientation,"data-orientation":i.orientation,"data-disabled":i.disabled?"":void 0,tabIndex:i.disabled?void 0:0,...o,ref:u,style:p===void 0?{display:"none"}:t.style,onFocus:se(t.onFocus,()=>{i.valueIndexToChangeRef.current=r})})}),h&&d.jsx(yfe,{name:s??(i.name?i.name+(i.values.length>1?"[]":""):void 0),form:i.form,value:p},r)]})});CN.displayName=Sw;var yfe=t=>{const{value:e,...n}=t,r=w.useRef(null),s=ufe(e);return w.useEffect(()=>{const o=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(s!==e&&l){const c=new Event("input",{bubbles:!0});l.call(o,e),o.dispatchEvent(c)}},[s,e]),d.jsx("input",{style:{display:"none"},...n,ref:r,defaultValue:e})};function Sfe(t=[],e,n){const r=[...t];return r[n]=e,r.sort((s,o)=>s-o)}function _N(t,e,n){const o=100/(n-e)*(t-e);return hN(o,[0,100])}function vfe(t,e){return e>2?`Value ${t+1} of ${e}`:e===2?["Minimum","Maximum"][t]:void 0}function xfe(t,e){if(t.length===1)return 0;const n=t.map(s=>Math.abs(s-e)),r=Math.min(...n);return n.indexOf(r)}function wfe(t,e,n){const r=t/2,o=Z1([0,50],[0,r]);return(r-o(e)*n)*n}function bfe(t){return t.slice(0,-1).map((e,n)=>t[n+1]-e)}function Pfe(t,e){if(e>0){const n=bfe(t);return Math.min(...n)>=e}return!0}function Z1(t,e){return n=>{if(t[0]===t[1]||e[0]===e[1])return e[0];const r=(e[1]-e[0])/(t[1]-t[0]);return e[0]+r*(n-t[0])}}function Cfe(t){return(String(t).split(".")[1]||"").length}function _fe(t,e){const n=Math.pow(10,e);return Math.round(t*n)/n}var Ife=yN,Efe=bN,kfe=PN,Tfe=CN;const Mfe=w.memo(function({onHistoryMark:e,title:n,steps:r,value:s,label:o,onValueChange:i,["data-testid"]:a}){const l=Ee(),c=w.useCallback(f=>{i(f[0])},[i]),u=w.useCallback(()=>{e("click slider")},[e]),h=w.useCallback(()=>{s&&i(s)},[s,i]);return d.jsx("div",{className:"tlui-slider__container",children:d.jsxs(Ife,{"data-testid":a,className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:s?[s]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:h,title:n+" — "+l(o),children:[d.jsx(Efe,{className:"tlui-slider__track",dir:"ltr",children:s!==null&&d.jsx(kfe,{className:"tlui-slider__range",dir:"ltr"})}),s!==null&&d.jsx(Tfe,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Afe({label:t,uiTypeA:e,uiTypeB:n,labelA:r,labelB:s,itemsA:o,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:h}){const f=Ee(),p=w.useMemo(()=>{var m;return((m=o.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:m.icon)??"mixed"},[o,c]),g=w.useMemo(()=>{var m;return((m=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:m.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:d.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[d.jsx("div",{title:f(t),className:"tlui-style-panel__double-select-picker-label",children:f(t)}),d.jsxs("div",{className:"tlui-buttons__horizontal",children:[d.jsxs(ma,{id:`style panel ${e} A`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon","data-testid":`style.${e}`,title:f(r)+" — "+(c===null||c.type==="mixed"?f("style-panel.mixed"):f(`${e}-style.${c.value}`)),children:d.jsx(be,{icon:p,small:!0,invertIcon:!0})})}),d.jsx(Sa,{side:"left",align:"center",sideOffset:80,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map((m,v)=>d.jsx(qu,{"data-testid":`style.${e}.${m.value}`,children:d.jsx(ue,{type:"icon",onClick:()=>h(a,m.value),title:`${f(r)} — ${f(`${e}-style.${m.value}`)}`,children:d.jsx(be,{icon:m.icon,invertIcon:!0})},m.value)},v))})})]}),d.jsxs(ma,{id:`style panel ${n}`,children:[d.jsx(ya,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}`,title:f(s)+" — "+(u===null||u.type==="mixed"?f("style-panel.mixed"):f(`${n}-style.${u.value}`)),children:d.jsx(be,{icon:g,small:!0})})}),d.jsx(Sa,{side:"left",align:"center",sideOffset:116,alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:i.map(m=>d.jsx(qu,{children:d.jsx(ue,{type:"icon",title:`${f(s)} — ${f(`${n}-style.${m.value}`)}`,"data-testid":`style.${n}.${m.value}`,onClick:()=>h(l,m.value),children:d.jsx(be,{icon:m.icon})})},m.value))})})]})]})]})}const jfe=w.memo(Afe);function Ofe({id:t,label:e,uiType:n,stylePanelType:r,style:s,items:o,type:i,value:a,onValueChange:l}){const c=Ee(),u=z(),h=w.useMemo(()=>{var m;return(m=o.find(v=>a.type==="shared"&&v.value===a.value))==null?void 0:m.icon},[o,a]),f=c(`style-panel.${r}`),p=a.type==="mixed"?c("style-panel.mixed"):f+" — "+c(`${n}-style.${a.value}`),g=e?c(e):"";return d.jsxs(ma,{id:`style panel ${t}`,children:[d.jsx(ya,{children:d.jsxs(ue,{type:i,"data-testid":`style.${n}`,title:p,children:[g&&d.jsx(bt,{children:g}),d.jsx(be,{icon:h??"mixed"})]})}),d.jsx(Sa,{side:"left",align:"center",alignOffset:0,children:d.jsx("div",{className:"tlui-buttons__grid",children:o.map(m=>d.jsx(qu,{children:d.jsx(ue,{type:"icon","data-testid":`style.${n}.${m.value}`,title:f+" — "+c(`${n}-style.${m.value}`),onClick:()=>{u.markHistoryStoppingPoint("select style dropdown item"),l(s,m.value)},children:d.jsx(be,{icon:m.icon})})},m.value))})})]})}const Q1=w.memo(Ofe);function Dfe({styles:t}){const e=xd();if(!t)return null;const n=t.get(Jr),r=t.get(Mp),s=t.get(Tp),o=t.get(Dp),i=t.get(Ls),a=n===void 0,l=r===void 0&&s===void 0,c=o===void 0,u=i===void 0,h=ko({isDarkMode:e});return d.jsxs(d.Fragment,{children:[d.jsx(Rfe,{theme:h,styles:t}),!u&&d.jsx(Lfe,{theme:h,styles:t}),!(a&&l&&c)&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[d.jsx($fe,{styles:t}),d.jsx(Nfe,{styles:t}),d.jsx(Ffe,{styles:t})]})]})}function Td(){const t=z(),e=Jt();return ke.useMemo(()=>function(r,s){t.run(()=>{t.isIn("select")&&t.setStyleForSelectedShapes(r,s),t.setStyleForNextShapes(r,s),t.updateInstanceState({isChangingStyle:!0})}),e("set-style",{source:"style-panel",id:r.id,value:s})},[t,e])}function Rfe({styles:t,theme:e}){const n=Ee(),r=z(),s=w.useCallback(h=>r.markHistoryStoppingPoint(h),[r]),o=Td(),i=t.get(mr),a=t.get(da),l=t.get(ua),c=t.get($s),u=a!==void 0||l!==void 0||c!==void 0;return d.jsxs(d.Fragment,{children:[d.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[i===void 0?null:d.jsx(Xi,{title:n("style-panel.color"),uiType:"color",style:mr,items:jr.color,value:i,onValueChange:o,theme:e,onHistoryMark:s}),d.jsx(zfe,{})]}),u&&d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[a===void 0?null:d.jsx(Xi,{title:n("style-panel.fill"),uiType:"fill",style:da,items:jr.fill,value:a,onValueChange:o,theme:e,onHistoryMark:s}),l===void 0?null:d.jsx(Xi,{title:n("style-panel.dash"),uiType:"dash",style:ua,items:jr.dash,value:l,onValueChange:o,theme:e,onHistoryMark:s}),c===void 0?null:d.jsx(Xi,{title:n("style-panel.size"),uiType:"size",style:$s,items:jr.size,value:c,onValueChange:(h,f)=>{o(h,f);const p=r.getSelectedShapeIds();p.length>0&&Xe(r,p)},theme:e,onHistoryMark:s})]})]})}function Lfe({theme:t,styles:e}){const n=Ee(),r=Td(),s=z(),o=w.useCallback(u=>s.markHistoryStoppingPoint(u),[s]),i=e.get(Ls),a=e.get(Sx),l=e.get(jp),c=e.get(Op);return i===void 0&&l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[i===void 0?null:d.jsx(Xi,{title:n("style-panel.font"),uiType:"font",style:Ls,items:jr.font,value:i,onValueChange:r,theme:t,onHistoryMark:o}),a===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Xi,{title:n("style-panel.align"),uiType:"align",style:Sx,items:jr.textAlign,value:a,onValueChange:r,theme:t,onHistoryMark:o}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})})})]}),l===void 0?null:d.jsxs("div",{className:"tlui-style-panel__row",children:[d.jsx(Xi,{title:n("style-panel.label-align"),uiType:"align",style:jp,items:jr.horizontalAlign,value:l,onValueChange:r,theme:t,onHistoryMark:o}),d.jsx("div",{className:"tlui-style-panel__row__extra-button",children:c===void 0?d.jsx(ue,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:d.jsx(be,{icon:"vertical-align-middle"})}):d.jsx(Q1,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",stylePanelType:"vertical-align",style:Op,items:jr.verticalAlign,value:c,onValueChange:r})})]})]})}function $fe({styles:t}){const e=Td(),n=t.get(Jr);return n===void 0?null:d.jsx(Q1,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",stylePanelType:"geo",style:Jr,items:jr.geo,value:n,onValueChange:e})}function Ffe({styles:t}){const e=Td(),n=t.get(Dp);return n===void 0?null:d.jsx(Q1,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",stylePanelType:"spline",style:Dp,items:jr.spline,value:n,onValueChange:e})}function Nfe({styles:t}){const e=Td(),n=t.get(Mp),r=t.get(Tp);return!n||!r?null:d.jsx(jfe,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:Tp,itemsA:jr.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:Mp,itemsB:jr.arrowheadEnd,valueB:n,onValueChange:e,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Lc=[.1,.25,.5,.75,1];function zfe(){const t=z(),e=w.useCallback(a=>t.markHistoryStoppingPoint(a),[t]),n=U("opacity",()=>t.getSharedOpacity(),[t]),r=Jt(),s=Ee(),o=ke.useCallback(a=>{const l=Lc[a];t.run(()=>{t.isIn("select")&&t.setOpacityForSelectedShapes(l),t.setOpacityForNextShapes(l),t.updateInstanceState({isChangingStyle:!0})}),r("set-style",{source:"style-panel",id:"opacity",value:a})},[t,r]);if(n===void 0)return null;const i=n.type==="mixed"?-1:Lc.indexOf(M9(Lc,a=>Math.abs(a-n.value)));return d.jsx(Mfe,{"data-testid":"style.opacity",value:i>=0?i:Lc.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:Lc.length-1,title:s("style-panel.opacity"),onHistoryMark:e})}const Bfe=w.memo(function({isMobile:e,children:n}){const r=z(),s=w.useRef(null);Ai(s);const o=dN(),i=w.useCallback(()=>{e||r.updateInstanceState({isChangingStyle:!1})},[r,e]),a=n??d.jsx(Dfe,{styles:o});return d.jsx("div",{ref:s,className:ce("tlui-style-panel",{"tlui-style-panel__wrapper":!e}),"data-ismobile":e,onPointerLeave:i,children:a})});function Ufe(){const t=z(),e=Ee(),n=dN(),r=n==null?void 0:n.get(mr),s=ko({isDarkMode:t.user.getIsDarkMode()}),o=((r==null?void 0:r.type)==="shared"?s[r.value]:s.black).solid,i=U("disable style panel",()=>t.isInAny("hand","zoom","eraser","laser"),[t]),a=w.useCallback(c=>{c||t.updateInstanceState({isChangingStyle:!1})},[t]),{StylePanel:l}=Ri();return l?d.jsxs(V1,{id:"mobile style menu",onOpenChange:a,children:[d.jsx(Y1,{children:d.jsx(ue,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":o},title:e("style-panel.title"),disabled:i,children:d.jsx(be,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),d.jsx(X1,{side:"top",align:"end",children:l&&d.jsx(l,{isMobile:!0})})]}):null}function Hfe(){return d.jsxs(d.Fragment,{children:[d.jsx(Wfe,{}),d.jsx(Gfe,{}),d.jsx(Vfe,{}),d.jsx(Yfe,{}),d.jsx(Xfe,{}),d.jsx(qfe,{}),d.jsx(Zfe,{}),d.jsx(Qfe,{}),d.jsx(Jfe,{}),d.jsx(epe,{}),d.jsx(npe,{}),d.jsx(tpe,{}),d.jsx(ope,{}),d.jsx(lpe,{}),d.jsx(rpe,{}),d.jsx(ape,{}),d.jsx(ipe,{}),d.jsx(spe,{}),d.jsx(cpe,{}),d.jsx(upe,{}),d.jsx(dpe,{}),d.jsx(hpe,{}),d.jsx(fpe,{}),d.jsx(ppe,{}),d.jsx(gpe,{}),d.jsx(mpe,{}),d.jsx(Spe,{}),d.jsx(ype,{})]})}function Kfe(t){var r;const e=z(),n=(r=t.meta)==null?void 0:r.geo;return U("is tool selected",()=>{const s=e.getCurrentToolId(),o=e.getSharedStyles().getAsKnownValue(Jr);return n?s==="geo"&&o===n:s===t.id},[e,t.id,n])}function Ve({tool:t}){const e=E1(),n=Kfe(e[t]);return d.jsx(Ln,{toolId:t,isSelected:n})}function Wfe(){return d.jsx(Ve,{tool:"select"})}function Gfe(){return d.jsx(Ve,{tool:"hand"})}function Vfe(){return d.jsx(Ve,{tool:"draw"})}function Yfe(){return d.jsx(Ve,{tool:"eraser"})}function Xfe(){return d.jsx(Ve,{tool:"arrow"})}function qfe(){return d.jsx(Ve,{tool:"text"})}function Zfe(){return d.jsx(Ve,{tool:"note"})}function Qfe(){return d.jsx(Ln,{toolId:"asset"})}function Jfe(){return d.jsx(Ve,{tool:"rectangle"})}function epe(){return d.jsx(Ve,{tool:"ellipse"})}function tpe(){return d.jsx(Ve,{tool:"diamond"})}function npe(){return d.jsx(Ve,{tool:"triangle"})}function rpe(){return d.jsx(Ve,{tool:"rhombus"})}function spe(){return d.jsx(Ve,{tool:"heart"})}function ope(){return d.jsx(Ve,{tool:"hexagon"})}function ipe(){return d.jsx(Ve,{tool:"cloud"})}function ape(){return d.jsx(Ve,{tool:"star"})}function lpe(){return d.jsx(Ve,{tool:"oval"})}function cpe(){return d.jsx(Ve,{tool:"x-box"})}function upe(){return d.jsx(Ve,{tool:"check-box"})}function dpe(){return d.jsx(Ve,{tool:"arrow-left"})}function hpe(){return d.jsx(Ve,{tool:"arrow-up"})}function fpe(){return d.jsx(Ve,{tool:"arrow-down"})}function ppe(){return d.jsx(Ve,{tool:"arrow-right"})}function gpe(){return d.jsx(Ve,{tool:"line"})}function mpe(){return d.jsx(Ve,{tool:"highlight"})}function ype(){return d.jsx(Ve,{tool:"frame"})}function Spe(){return d.jsx(Ve,{tool:"laser"})}const TS=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function MS(t,e,n,r){t.addEventListener?t.addEventListener(e,n,r):t.attachEvent&&t.attachEvent("on".concat(e),n)}function $c(t,e,n,r){t.removeEventListener?t.removeEventListener(e,n,r):t.detachEvent&&t.detachEvent("on".concat(e),n)}function IN(t,e){const n=e.slice(0,e.length-1);for(let r=0;r<n.length;r++)n[r]=t[n[r].toLowerCase()];return n}function EN(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function vpe(t,e){const n=t.length>=e.length?t:e,r=t.length>=e.length?e:t;let s=!0;for(let o=0;o<n.length;o++)r.indexOf(n[o])===-1&&(s=!1);return s}const Zu={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,"-":TS?173:189,"=":TS?61:187,";":TS?59:186,"'":222,"[":219,"]":221,"\\":220},Us={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Nf={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Ut={16:!1,18:!1,17:!1,91:!1},ft={};for(let t=1;t<20;t++)Zu["f".concat(t)]=111+t;let it=[],gu=null,kN="all";const ro=new Map,Md=t=>Zu[t.toLowerCase()]||Us[t.toLowerCase()]||t.toUpperCase().charCodeAt(0),xpe=t=>Object.keys(Zu).find(e=>Zu[e]===t),wpe=t=>Object.keys(Us).find(e=>Us[e]===t);function TN(t){kN=t||"all"}function Qu(){return kN||"all"}function bpe(){return it.slice(0)}function Ppe(){return it.map(t=>xpe(t)||wpe(t)||String.fromCharCode(t))}function Cpe(){const t=[];return Object.keys(ft).forEach(e=>{ft[e].forEach(n=>{let{key:r,scope:s,mods:o,shortcut:i}=n;t.push({scope:s,shortcut:i,mods:o,keys:r.split("+").map(a=>Md(a))})})}),t}function _pe(t){const e=t.target||t.srcElement,{tagName:n}=e;let r=!0;const s=n==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(e.type);return(e.isContentEditable||(s||n==="TEXTAREA"||n==="SELECT")&&!e.readOnly)&&(r=!1),r}function Ipe(t){return typeof t=="string"&&(t=Md(t)),it.indexOf(t)!==-1}function Epe(t,e){let n,r;t||(t=Qu());for(const s in ft)if(Object.prototype.hasOwnProperty.call(ft,s))for(n=ft[s],r=0;r<n.length;)n[r].scope===t?n.splice(r,1).forEach(i=>{let{element:a}=i;return J1(a)}):r++;Qu()===t&&TN(e||"all")}function kpe(t){let e=t.keyCode||t.which||t.charCode;const n=it.indexOf(e);if(n>=0&&it.splice(n,1),t.key&&t.key.toLowerCase()==="meta"&&it.splice(0,it.length),(e===93||e===224)&&(e=91),e in Ut){Ut[e]=!1;for(const r in Us)Us[r]===e&&(Wn[r]=!1)}}function MN(t){if(typeof t>"u")Object.keys(ft).forEach(s=>{Array.isArray(ft[s])&&ft[s].forEach(o=>Uh(o)),delete ft[s]}),J1(null);else if(Array.isArray(t))t.forEach(s=>{s.key&&Uh(s)});else if(typeof t=="object")t.key&&Uh(t);else if(typeof t=="string"){for(var e=arguments.length,n=new Array(e>1?e-1:0),r=1;r<e;r++)n[r-1]=arguments[r];let[s,o]=n;typeof s=="function"&&(o=s,s=""),Uh({key:t,scope:s,method:o,splitKey:"+"})}}const Uh=t=>{let{key:e,scope:n,method:r,splitKey:s="+"}=t;EN(e).forEach(i=>{const a=i.split(s),l=a.length,c=a[l-1],u=c==="*"?"*":Md(c);if(!ft[u])return;n||(n=Qu());const h=l>1?IN(Us,a):[],f=[];ft[u]=ft[u].filter(p=>{const m=(r?p.method===r:!0)&&p.scope===n&&vpe(p.mods,h);return m&&f.push(p.element),!m}),f.forEach(p=>J1(p))})};function d2(t,e,n,r){if(e.element!==r)return;let s;if(e.scope===n||e.scope==="all"){s=e.mods.length>0;for(const o in Ut)Object.prototype.hasOwnProperty.call(Ut,o)&&(!Ut[o]&&e.mods.indexOf(+o)>-1||Ut[o]&&e.mods.indexOf(+o)===-1)&&(s=!1);(e.mods.length===0&&!Ut[16]&&!Ut[18]&&!Ut[17]&&!Ut[91]||s||e.shortcut==="*")&&(e.keys=[],e.keys=e.keys.concat(it),e.method(t,e)===!1&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0)))}}function h2(t,e){const n=ft["*"];let r=t.keyCode||t.which||t.charCode;if(!Wn.filter.call(this,t))return;if((r===93||r===224)&&(r=91),it.indexOf(r)===-1&&r!==229&&it.push(r),["metaKey","ctrlKey","altKey","shiftKey"].forEach(a=>{const l=Nf[a];t[a]&&it.indexOf(l)===-1?it.push(l):!t[a]&&it.indexOf(l)>-1?it.splice(it.indexOf(l),1):a==="metaKey"&&t[a]&&(it=it.filter(c=>c in Nf||c===r))}),r in Ut){Ut[r]=!0;for(const a in Us)Us[a]===r&&(Wn[a]=!0);if(!n)return}for(const a in Ut)Object.prototype.hasOwnProperty.call(Ut,a)&&(Ut[a]=t[Nf[a]]);t.getModifierState&&!(t.altKey&&!t.ctrlKey)&&t.getModifierState("AltGraph")&&(it.indexOf(17)===-1&&it.push(17),it.indexOf(18)===-1&&it.push(18),Ut[17]=!0,Ut[18]=!0);const s=Qu();if(n)for(let a=0;a<n.length;a++)n[a].scope===s&&(t.type==="keydown"&&n[a].keydown||t.type==="keyup"&&n[a].keyup)&&d2(t,n[a],s,e);if(!(r in ft))return;const o=ft[r],i=o.length;for(let a=0;a<i;a++)if((t.type==="keydown"&&o[a].keydown||t.type==="keyup"&&o[a].keyup)&&o[a].key){const l=o[a],{splitKey:c}=l,u=l.key.split(c),h=[];for(let f=0;f<u.length;f++)h.push(Md(u[f]));h.sort().join("")===it.sort().join("")&&d2(t,l,s,e)}}function Wn(t,e,n){it=[];const r=EN(t);let s=[],o="all",i=document,a=0,l=!1,c=!0,u="+",h=!1,f=!1;for(n===void 0&&typeof e=="function"&&(n=e),Object.prototype.toString.call(e)==="[object Object]"&&(e.scope&&(o=e.scope),e.element&&(i=e.element),e.keyup&&(l=e.keyup),e.keydown!==void 0&&(c=e.keydown),e.capture!==void 0&&(h=e.capture),typeof e.splitKey=="string"&&(u=e.splitKey),e.single===!0&&(f=!0)),typeof e=="string"&&(o=e),f&&MN(t,o);a<r.length;a++)t=r[a].split(u),s=[],t.length>1&&(s=IN(Us,t)),t=t[t.length-1],t=t==="*"?"*":Md(t),t in ft||(ft[t]=[]),ft[t].push({keyup:l,keydown:c,scope:o,mods:s,shortcut:r[a],method:n,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!ro.has(i)){const p=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return h2(m,i)},g=function(){let m=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;h2(m,i),kpe(m)};ro.set(i,{keydownListener:p,keyupListenr:g,capture:h}),MS(i,"keydown",p,h),MS(i,"keyup",g,h)}if(!gu){const p=()=>{it=[]};gu={listener:p,capture:h},MS(window,"focus",p,h)}}}function Tpe(t){let e=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(ft).forEach(n=>{ft[n].filter(s=>s.scope===e&&s.shortcut===t).forEach(s=>{s&&s.method&&s.method()})})}function J1(t){const e=Object.values(ft).flat();if(e.findIndex(r=>{let{element:s}=r;return s===t})<0){const{keydownListener:r,keyupListenr:s,capture:o}=ro.get(t)||{};r&&s&&($c(t,"keyup",s,o),$c(t,"keydown",r,o),ro.delete(t))}if((e.length<=0||ro.size<=0)&&(Object.keys(ro).forEach(s=>{const{keydownListener:o,keyupListenr:i,capture:a}=ro.get(s)||{};o&&i&&($c(s,"keyup",i,a),$c(s,"keydown",o,a),ro.delete(s))}),ro.clear(),Object.keys(ft).forEach(s=>delete ft[s]),gu)){const{listener:s,capture:o}=gu;$c(window,"focus",s,o),gu=null}}const AS={getPressedKeyString:Ppe,setScope:TN,getScope:Qu,deleteScope:Epe,getPressedKeyCodes:bpe,getAllKeyCodes:Cpe,isPressed:Ipe,filter:_pe,trigger:Tpe,unbind:MN,keyMap:Zu,modifier:Us,modifierMap:Nf};for(const t in AS)Object.prototype.hasOwnProperty.call(AS,t)&&(Wn[t]=AS[t]);if(typeof window<"u"){const t=window.hotkeys;Wn.noConflict=e=>(e&&window.hotkeys===Wn&&(window.hotkeys=t),Wn),window.hotkeys=Wn}const f2=["copy","cut","paste","asset"];function Mpe(){const t=z(),e=wr(),n=ka(),r=E1(),s=U("is focused",()=>t.getInstanceState().isFocused,[t]);w.useEffect(()=>{if(!s)return;const o=new Array,i=(l,c)=>{Wn(l,{element:document.body},c),o.push(()=>{Wn.unbind(l,c)})},a=(l,c)=>{Wn(l,{element:document.body,keyup:!0,keydown:!1},c),o.push(()=>{Wn.unbind(l,c)})};for(const l of Object.values(n))l.kbd&&(e&&!l.readonlyOk||f2.includes(l.id)||i(p2(l.kbd),c=>{Zc(t)||(xe(c),l.onSelect("kbd"))}));for(const l of Object.values(r))!l.kbd||!l.readonlyOk&&t.getIsReadonly()||f2.includes(l.id)||i(p2(l.kbd),c=>{Zc(t)||(xe(c),l.onSelect("kbd"))});return i(",",l=>{if(Zc(t)||t.inputs.keys.has("Comma"))return;xe(l),t.focus(),t.inputs.keys.add("Comma");const{x:c,y:u,z:h}=t.inputs.currentPagePoint,f=t.pageToScreen({x:c,y:u}),p={type:"pointer",name:"pointer_down",point:{x:f.x,y:f.y,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(p)}),a(",",l=>{if(Zc(t)||!t.inputs.keys.has("Comma"))return;t.inputs.keys.delete("Comma");const{x:c,y:u,z:h}=t.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_up",point:{x:c,y:u,z:h},shiftKey:l.shiftKey,altKey:l.altKey,ctrlKey:l.metaKey||l.ctrlKey,metaKey:l.metaKey,accelKey:un(l),pointerId:0,button:0,isPen:t.getInstanceState().isPenMode,target:"canvas"};t.dispatch(f)}),()=>{o.forEach(l=>l())}},[n,r,e,t,s])}function p2(t){return Ape(t).map(e=>{let n="";const r=e.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=e,n}).join(",")}function Ape(t){typeof t!="string"&&(t=""),t=t.replace(/\s/g,"");const e=t.split(",");let n=e.lastIndexOf("");for(;n>=0;)e[n-1]+=",",e.splice(n,1),n=e.lastIndexOf("");return e}function Zc(t){return t.menus.hasAnyOpenMenus()||t.getEditingShapeId()!==null||t.getCrashingError()}const jpe=w.createContext(!1);function Ope({children:t}){const e=z(),n=Jl(),r=An(),s=Ee(),o=Math.min(8,5+r),[i,a]=w.useState(0),l=w.useRef(null),[c,u]=w.useState(null),h=w.useMemo(()=>{const p=c?`:not([data-value="${c}"])`:"";return`
|
|
412
412
|
#${n}_main > *:nth-child(n + ${o+(c?1:2)})${p} {
|
|
413
413
|
display: none;
|
|
414
414
|
}
|
|
415
415
|
#${n}_more > *:nth-child(-n + ${o}) {
|
|
416
416
|
display: none;
|
|
417
417
|
}
|
|
418
|
-
`},[c,n,o]),f=Hg(()=>{if(!l.current)return;const p=Array.from(l.current.children);a(p.length),p.findIndex(v=>v.getAttribute("data-value")===c)<=o&&u(null);const m=Array.from(l.current.children).findIndex(v=>v.getAttribute("aria-checked")==="true");m!==-1&&m>=o&&u(p[m].getAttribute("data-value"))});return w.useLayoutEffect(()=>{f()}),w.useLayoutEffect(()=>{if(!l.current)return;const p=new MutationObserver(f);return p.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{p.disconnect()}},[f]),w.useEffect(()=>{const p=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[g,m]of p)Wn(g,v=>{var b;if(Zc(e))return;xe(v);const S=Array.from(((b=l.current)==null?void 0:b.children)??[]).filter(P=>!(P instanceof HTMLElement)||P.tagName.toLowerCase()!=="button"?!1:!!(P.offsetWidth||P.offsetHeight))[m];S&&S.click()});return()=>{Wn.unbind("1,2,3,4,5,6,7,8,9,0")}},[e]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<St.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(Fr,{type:"toolbar",sourceId:"toolbar",children:t})}),i>o+1&&d.jsx(jpe.Provider,{value:!0,children:d.jsxs(ma,{id:"toolbar overflow",modal:!1,children:[d.jsx(ya,{children:d.jsx(ue,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(be,{icon:"chevron-up"})})}),d.jsx(Sa,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Fr,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function Dpe({activeToolId:t}){const e=z(),n=An(),r=Ee(),s=U("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),o=U("current tool",()=>e.getCurrentTool(),[e]);return!t||!o.isLockable?null:d.jsx(ue,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ce("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<St.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:d.jsx(be,{icon:s?"lock":"unlock",small:!0})})}const Rpe=w.memo(function({children:e}){const n=z(),r=An(),s=wr(),o=U("current tool id",()=>n.getCurrentToolId(),[n]),i=w.useRef(null);Ai(i);const{ActionsMenu:a,QuickActions:l}=Ri(),c=n.options.actionShortcutsLocation==="menu"?!1:n.options.actionShortcutsLocation==="toolbar"?!0:r<St.TABLET;return d.jsx("div",{ref:i,className:"tlui-toolbar",children:d.jsxs("div",{className:"tlui-toolbar__inner",children:[d.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&d.jsxs("div",{className:"tlui-toolbar__extras",children:[c&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[l&&d.jsx(l,{}),a&&d.jsx(a,{})]}),d.jsx(Dpe,{activeToolId:o})]}),d.jsx(Ope,{children:e??d.jsx(Hfe,{})})]}),r<St.TABLET_SM&&!s&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(Ufe,{})})]})})});function Lpe(){const t=Ee();return d.jsxs("div",{className:ce("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(zs,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function $pe({maxWidth:t=420,ignoreRightWidth:e=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:o}){const i=w.useRef(null),a=An(),l=w.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),f=u.querySelector(".tlui-layout__top__right"),p=u.offsetWidth,g=h.offsetWidth,m=f.offsetWidth,v=c.offsetWidth-e;let y=(p-v)/2;p%2!==0&&(y-=.5);const S=g+r,b=c.offsetLeft,P=Math.min(p-m-g-2*r,t),C=Math.max(y,S)-b;f.offsetWidth>n&&a<=6?c.style.setProperty("max-width",P-s+"px"):c.style.setProperty("max-width",P+"px"),c.style.setProperty("transform",`translate(${C}px, 0px)`)},[a,e,r,t,s,n]);return w.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),f=u.querySelector(".tlui-layout__top__right"),p=new ResizeObserver(l);return p.observe(h),p.observe(f),p.observe(u),p.observe(c),l(),()=>{p.disconnect()}},[l]),w.useLayoutEffect(()=>{l()}),d.jsx("div",{ref:i,className:"tlui-top-panel__container",children:o})}function Fpe(){const t=tie()==="offline";return d.jsx($pe,{children:t&&d.jsx(Lpe,{})})}function Npe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"zoom-in",noClose:!0}),d.jsx(W,{actionId:"zoom-out",noClose:!0}),d.jsx($F,{}),d.jsx(FF,{}),d.jsx(NF,{})]})}const zpe=w.memo(function({children:e}){const n=Tt(),[r,s]=Mo("zoom menu"),o=e??d.jsx(Npe,{});return d.jsxs(c1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(u1,{asChild:!0,dir:"ltr",children:d.jsx(Bpe,{})}),d.jsx(um,{container:n,children:d.jsx(d1,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Fr,{type:"menu",sourceId:"zoom-menu",children:o})})})]})}),Bpe=w.forwardRef(function(e,n){const r=z(),s=An(),o=U("zoom",()=>r.getZoomLevel(),[r]),i=Ee(),a=w.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(ue,{ref:n,...e,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<St.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:s<St.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(o*100),"%"]})})}),
|
|
418
|
+
`},[c,n,o]),f=Hg(()=>{if(!l.current)return;const p=Array.from(l.current.children);a(p.length),p.findIndex(v=>v.getAttribute("data-value")===c)<=o&&u(null);const m=Array.from(l.current.children).findIndex(v=>v.getAttribute("aria-checked")==="true");m!==-1&&m>=o&&u(p[m].getAttribute("data-value"))});return w.useLayoutEffect(()=>{f()}),w.useLayoutEffect(()=>{if(!l.current)return;const p=new MutationObserver(f);return p.observe(l.current,{childList:!0,subtree:!0,attributeFilter:["data-value","aria-checked"]}),()=>{p.disconnect()}},[f]),w.useEffect(()=>{const p=[["1",0],["2",1],["3",2],["4",3],["5",4],["6",5],["7",6],["8",7],["9",8],["0",9]];for(const[g,m]of p)Wn(g,v=>{var b;if(Zc(e))return;xe(v);const S=Array.from(((b=l.current)==null?void 0:b.children)??[]).filter(P=>!(P instanceof HTMLElement)||P.tagName.toLowerCase()!=="button"?!1:!!(P.offsetWidth||P.offsetHeight))[m];S&&S.click()});return()=>{Wn.unbind("1,2,3,4,5,6,7,8,9,0")}},[e]),d.jsxs(d.Fragment,{children:[d.jsx("style",{children:h}),d.jsxs("div",{className:ce("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<St.TABLET_SM}),role:"radiogroup",children:[d.jsx("div",{id:`${n}_main`,ref:l,className:"tlui-toolbar__tools__list",children:d.jsx(Fr,{type:"toolbar",sourceId:"toolbar",children:t})}),i>o+1&&d.jsx(jpe.Provider,{value:!0,children:d.jsxs(ma,{id:"toolbar overflow",modal:!1,children:[d.jsx(ya,{children:d.jsx(ue,{title:s("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:d.jsx(be,{icon:"chevron-up"})})}),d.jsx(Sa,{side:"top",align:"center",children:d.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",id:`${n}_more`,children:d.jsx(Fr,{type:"toolbar-overflow",sourceId:"toolbar",children:t})})})]})})]})]})}function Dpe({activeToolId:t}){const e=z(),n=An(),r=Ee(),s=U("is tool locked",()=>e.getInstanceState().isToolLocked,[e]),o=U("current tool",()=>e.getCurrentTool(),[e]);return!t||!o.isLockable?null:d.jsx(ue,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:ce("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":n<St.TABLET_SM}),onClick:()=>e.updateInstanceState({isToolLocked:!s}),children:d.jsx(be,{icon:s?"lock":"unlock",small:!0})})}const Rpe=w.memo(function({children:e}){const n=z(),r=An(),s=wr(),o=U("current tool id",()=>n.getCurrentToolId(),[n]),i=w.useRef(null);Ai(i);const{ActionsMenu:a,QuickActions:l}=Ri(),c=n.options.actionShortcutsLocation==="menu"?!1:n.options.actionShortcutsLocation==="toolbar"?!0:r<St.TABLET;return d.jsx("div",{ref:i,className:"tlui-toolbar",children:d.jsxs("div",{className:"tlui-toolbar__inner",children:[d.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&d.jsxs("div",{className:"tlui-toolbar__extras",children:[c&&d.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[l&&d.jsx(l,{}),a&&d.jsx(a,{})]}),d.jsx(Dpe,{activeToolId:o})]}),d.jsx(Ope,{children:e??d.jsx(Hfe,{})})]}),r<St.TABLET_SM&&!s&&d.jsx("div",{className:"tlui-toolbar__tools",children:d.jsx(Ufe,{})})]})})});function Lpe(){const t=Ee();return d.jsxs("div",{className:ce("tlui-offline-indicator"),children:[t("status.offline"),d.jsx(zs,{"aria-label":"offline",icon:"status-offline",small:!0})]})}function $pe({maxWidth:t=420,ignoreRightWidth:e=0,stylePanelWidth:n=148,marginBetweenZones:r=12,squeezeAmount:s=52,children:o}){const i=w.useRef(null),a=An(),l=w.useCallback(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),f=u.querySelector(".tlui-layout__top__right"),p=u.offsetWidth,g=h.offsetWidth,m=f.offsetWidth,v=c.offsetWidth-e;let y=(p-v)/2;p%2!==0&&(y-=.5);const S=g+r,b=c.offsetLeft,P=Math.min(p-m-g-2*r,t),C=Math.max(y,S)-b;f.offsetWidth>n&&a<=6?c.style.setProperty("max-width",P-s+"px"):c.style.setProperty("max-width",P+"px"),c.style.setProperty("transform",`translate(${C}px, 0px)`)},[a,e,r,t,s,n]);return w.useLayoutEffect(()=>{const c=i.current;if(!c)return;const u=c.parentElement.parentElement,h=u.querySelector(".tlui-layout__top__left"),f=u.querySelector(".tlui-layout__top__right"),p=new ResizeObserver(l);return p.observe(h),p.observe(f),p.observe(u),p.observe(c),l(),()=>{p.disconnect()}},[l]),w.useLayoutEffect(()=>{l()}),d.jsx("div",{ref:i,className:"tlui-top-panel__container",children:o})}function Fpe(){const t=tie()==="offline";return d.jsx($pe,{children:t&&d.jsx(Lpe,{})})}function Npe(){return d.jsxs(d.Fragment,{children:[d.jsx(W,{actionId:"zoom-in",noClose:!0}),d.jsx(W,{actionId:"zoom-out",noClose:!0}),d.jsx($F,{}),d.jsx(FF,{}),d.jsx(NF,{})]})}const zpe=w.memo(function({children:e}){const n=Tt(),[r,s]=Mo("zoom menu"),o=e??d.jsx(Npe,{});return d.jsxs(c1,{dir:"ltr",open:r,onOpenChange:s,modal:!1,children:[d.jsx(u1,{asChild:!0,dir:"ltr",children:d.jsx(Bpe,{})}),d.jsx(um,{container:n,children:d.jsx(d1,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:d.jsx(Fr,{type:"menu",sourceId:"zoom-menu",children:o})})})]})}),Bpe=w.forwardRef(function(e,n){const r=z(),s=An(),o=U("zoom",()=>r.getZoomLevel(),[r]),i=Ee(),a=w.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{animation:{duration:r.options.animationMediumMs}})},[r]);return d.jsx(ue,{ref:n,...e,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:s<St.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,children:s<St.MOBILE?null:d.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(o*100),"%"]})})}),AN=w.createContext(null);function Upe({overrides:t={},children:e}){const n=tc(t),r=gm();return d.jsx(AN.Provider,{value:w.useMemo(()=>({ContextMenu:rhe,ActionsMenu:Ade,HelpMenu:null,ZoomMenu:zpe,MainMenu:$he,Minimap:Vhe,StylePanel:Bfe,PageMenu:Zhe,NavigationPanel:Xhe,Toolbar:Rpe,KeyboardShortcutsDialog:Ihe,QuickActions:tfe,HelperButtons:Che,DebugPanel:ghe,DebugMenu:phe,MenuPanel:vhe,SharePanel:r?lfe:null,CursorChatBubble:r?ihe:null,TopPanel:r?Fpe:null,...n}),[n,r]),children:e})}function Ri(){const t=w.useContext(AN);if(!t)throw new Error("useTldrawUiComponents must be used within a TldrawUiComponentsProvider");return t}const Hpe=Zt(function({overrides:e,components:n,assetUrls:r,onUiEvent:s,forceMobile:o,mediaMimeTypes:i,children:a}){const l=Ti();return d.jsx(B$.Provider,{value:i,children:d.jsx(koe,{assetUrls:ode(r),children:d.jsx(Aoe,{overrides:Mae(e),locale:(l==null?void 0:l.user.getLocale())??vs.locale,children:d.jsx(xte,{onEvent:s,children:d.jsx(Iie,{children:d.jsx(rie,{context:l==null?void 0:l.contextId,children:d.jsx(nie,{forceMobile:o,children:d.jsx(Upe,{overrides:n,children:l?d.jsx(Kpe,{overrides:e,children:a}):a})})})})})})})})});function Kpe({overrides:t,children:e}){const n=Aae(t);return d.jsx(Oae,{overrides:n.actions,children:d.jsx(Xae,{overrides:n.tools,children:e})})}function Wpe(){const t=z(),{addToast:e}=To();w.useEffect(()=>{function n({name:r,count:s}){e({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${s}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return t.addListener("max-shapes",n),()=>{t.removeListener("max-shapes",n)}},[t,e])}const Gpe=ke.memo(function({renderDebugMenuItems:e,children:n,hideUi:r,components:s,...o}){return d.jsx(Hpe,{...o,components:s,children:d.jsx(Vpe,{hideUi:r,renderDebugMenuItems:e,children:n})})}),Vpe=ke.memo(function({children:e,hideUi:n,...r}){return d.jsxs(d.Fragment,{children:[e,n?null:d.jsx(Ype,{...r})]})}),Ype=ke.memo(function(){const e=z(),n=Ee(),r=An(),s=wr(),o=U("focus",()=>e.getInstanceState().isFocusMode,[e]),i=U("debug",()=>e.getInstanceState().isDebugMode,[e]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:h,HelpMenu:f,NavigationPanel:p,HelperButtons:g,DebugPanel:m,CursorChatBubble:v}=Ri();Mpe(),nae(),Wpe();const{"toggle-focus-mode":y}=ka();return d.jsxs("div",{className:ce("tlui-layout",{"tlui-layout__mobile":r<St.TABLET_SM}),"data-breakpoint":r,children:[o?d.jsx("div",{className:"tlui-layout__top",children:d.jsx(ue,{type:"icon",className:"tlui-focus-button",title:n("focus-mode.toggle-focus-mode"),onClick:()=>y.onSelect("menu"),children:d.jsx(be,{icon:"dot"})})}):d.jsxs(d.Fragment,{children:[d.jsxs("div",{className:"tlui-layout__top",children:[d.jsxs("div",{className:"tlui-layout__top__left",children:[c&&d.jsx(c,{}),g&&d.jsx(g,{})]}),d.jsx("div",{className:"tlui-layout__top__center",children:l&&d.jsx(l,{})}),d.jsxs("div",{className:"tlui-layout__top__right",children:[a&&d.jsx(a,{}),u&&r>=St.TABLET_SM&&!s&&d.jsx(u,{})]})]}),d.jsxs("div",{className:"tlui-layout__bottom",children:[d.jsxs("div",{className:"tlui-layout__bottom__main",children:[p&&d.jsx(p,{}),h&&d.jsx(h,{}),f&&d.jsx(f,{})]}),i&&m&&d.jsx(m,{})]})]}),d.jsx(Yae,{}),d.jsx(Kae,{}),d.jsx(nde,{}),v&&d.jsx(v,{})]})});async function Xpe(t,e){const{url:n,style:r="normal",weight:s="500",display:o,featureSettings:i,stretch:a,unicodeRange:l,variant:c,format:u}=e,h={style:r,weight:s,display:o,featureSettings:i,stretch:a,unicodeRange:l,variant:c},f=new FontFace(t,`url(${n})`,h);return await f.load(),document.fonts.add(f),f.$$_url=n,f.$$_fontface=`
|
|
419
419
|
@font-face {
|
|
420
420
|
font-family: ${f.family};
|
|
421
421
|
font-stretch: ${f.stretch};
|
|
422
422
|
font-weight: ${f.weight};
|
|
423
423
|
font-style: ${f.style};
|
|
424
424
|
src: url("${n}") format("${u}")
|
|
425
|
-
}`,f}const Hh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let s=!1;return r(2),Xpe(t,e).then(()=>{s||r(0)}).catch(o=>{s||(console.error(o),r(1))}),()=>{s=!0}},[t,e]),n};function qpe(t){return{draw:{url:t.fonts.draw,format:t.fonts.draw.split(".").pop()},serif:{url:t.fonts.serif,format:t.fonts.serif.split(".").pop()},sansSerif:{url:t.fonts.sansSerif,format:t.fonts.sansSerif.split(".").pop()},monospace:{url:t.fonts.monospace,format:t.fonts.monospace.split(".").pop()}}}function
|
|
425
|
+
}`,f}const Hh=(t,e)=>{const[n,r]=w.useState(2);return w.useEffect(()=>{let s=!1;return r(2),Xpe(t,e).then(()=>{s||r(0)}).catch(o=>{s||(console.error(o),r(1))}),()=>{s=!0}},[t,e]),n};function qpe(t){return{draw:{url:t.fonts.draw,format:t.fonts.draw.split(".").pop()},serif:{url:t.fonts.serif,format:t.fonts.serif.split(".").pop()},sansSerif:{url:t.fonts.sansSerif,format:t.fonts.sansSerif.split(".").pop()},monospace:{url:t.fonts.monospace,format:t.fonts.monospace.split(".").pop()}}}function jN(t){const e=w.useMemo(()=>qpe(t),[t]),n=[Hh("tldraw_draw",e.draw),Hh("tldraw_serif",e.serif),Hh("tldraw_sans",e.sansSerif),Hh("tldraw_mono",e.monospace)];return{error:n.some(r=>r===1),done:!n.some(r=>r===2)}}function Zpe(t){const{children:e,maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:s,acceptedVideoMimeTypes:o,onMount:i,components:a={},shapeUtils:l=[],bindingUtils:c=[],tools:u=[],embeds:h,...f}=t,p=tc(a),g=w.useMemo(()=>({Scribble:CE,ShapeIndicators:ile,CollaboratorScribble:CE,SelectionForeground:rle,SelectionBackground:tle,Handles:qae,...p}),[p]),m=qo(l),v=w.useMemo(()=>[...E5,...m],[m]),y=qo(c),S=w.useMemo(()=>[...X$,...y],[y]),b=qo(u),P=w.useMemo(()=>[...tde,...Kle,...b],[b]),C=qo(s??xg),_=qo(o??x0),E=w.useMemo(()=>[...C,..._],[C,_]),k=dF(f.assetUrls),{done:D,error:T}=jN(k);return T?d.jsx(qR,{children:"Could not load assets. Please refresh the page."}):D?(v.find(L=>L.type==="embed")&&h&&Jp.setEmbedDefinitions(h),d.jsx(ote,{initialState:"select",...f,components:g,shapeUtils:v,bindingUtils:S,tools:P,children:d.jsxs(Gpe,{...f,components:g,mediaMimeTypes:E,children:[d.jsx(Qpe,{maxImageDimension:n,maxAssetSize:r,acceptedImageMimeTypes:C,acceptedVideoMimeTypes:_,onMount:i}),e]})})):d.jsx(Db,{children:d.jsx(vb,{})})}function Qpe({maxImageDimension:t=5e3,maxAssetSize:e=10*1024*1024,acceptedImageMimeTypes:n=xg,acceptedVideoMimeTypes:r=x0,onMount:s}){const o=z(),i=To(),a=Ee();ZR(()=>{const u=[];return u.push(_ue(o)),Ple(o,{maxImageDimension:t,maxAssetSize:e,acceptedImageMimeTypes:n,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),u.push(o.store.props.onMount(o)),u.push(s==null?void 0:s(o)),()=>{u.forEach(h=>h==null?void 0:h())}});const{Canvas:l}=st(),{ContextMenu:c}=Ri();return c?d.jsx(c,{}):l?d.jsx(l,{}):null}w.memo(function(e){const[n,r]=w.useState(null),[s,o]=w.useState(null),i=qo(e.shapeUtils??[]),a=w.useMemo(()=>[...E5,...i],[i]),l=qo(e.bindingUtils??[]),c=w.useMemo(()=>[...X$,...l],[l]),u=hte({snapshot:e.snapshot,shapeUtils:a}),h=dF(e.assetUrls),{done:f,error:p}=jN(h),{pageId:g,bounds:m,scale:v,pixelRatio:y,background:S,padding:b,darkMode:P,preserveAspectRatio:C,format:_="svg",licenseKey:E}=e;return w.useLayoutEffect(()=>{if(!s||!u||!f)return;let k=!1;const D=document.createElement("div");s.appendChild(D),s.classList.add("tl-container","tl-theme__light");const T=new Q({store:u,shapeUtils:a,bindingUtils:c,tools:[],getContainer:()=>D,licenseKey:E});g&&T.setCurrentPage(g);const j=T.getCurrentPageShapeIds();async function L(){const M=await T.getSvgString([...j],{bounds:m,scale:v,background:S,padding:b,darkMode:P,preserveAspectRatio:C});if(M&&!k){if(_==="svg"){if(!k){const O=new Blob([M.svg],{type:"image/svg+xml"}),F=URL.createObjectURL(O);r(F)}}else if(_==="png"){const O=await F$(T,M.svg,{type:_,width:M.width,height:M.height,pixelRatio:y});if(O&&!k){const F=URL.createObjectURL(O);r(F)}}}T.dispose()}return L(),()=>{k=!0}},[_,s,u,a,c,g,m,v,S,b,P,C,f,p,E,y]),p?d.jsx(qR,{children:"Could not load assets."}):f?d.jsx("div",{ref:o,style:{position:"relative",width:"100%",height:"100%"},children:n&&d.jsx("img",{src:n,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})}):d.jsx(Db,{children:d.jsx(vb,{})})});w.memo(function({children:e}){const n=Ee(),r=An(),s=w.useRef(null);Ai(s);const o=e??d.jsx(Ehe,{});return r<St.MOBILE?null:d.jsx("div",{ref:s,className:"tlui-help-menu",children:d.jsxs(ma,{id:"help menu",children:[d.jsx(ya,{children:d.jsx(ue,{type:"help",title:n("help-menu.title"),"data-testid":"help-menu.button",children:d.jsx(be,{icon:"question-mark",small:!0})})}),d.jsx(Sa,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:d.jsx(Fr,{type:"menu",sourceId:"help-menu",children:o})})]})})});const Jpe=1,ege=Pe({schemaVersion:mn(1),storeVersion:lf,recordVersions:Ep(ye,Pe({version:lf,subTypeVersions:Ep(ye,lf).optional(),subTypeKey:ye.optional()}))}),tge=Pe({schemaVersion:mn(2),sequences:Ep(ye,lf)}),nge=Pe({tldrawFileFormatVersion:rY,schema:sY("schemaVersion",{1:ege,2:tge}),records:Wt(Pe({id:ye,typeName:ye}).allowUnknownProperties())});function rge(t){var e;try{return!!((e=t.document)!=null&&e.version)}catch{return!1}}function sge({json:t,schema:e}){let n;try{n=nge.validate(JSON.parse(t))}catch(o){try{if(n=JSON.parse(t),rge(n))return wn.err({type:"v1File",data:n})}catch{}return wn.err({type:"notATldrawFile",cause:o})}if(n.tldrawFileFormatVersion>Jpe)return wn.err({type:"fileFormatVersionTooNew",version:n.tldrawFileFormatVersion});let r,s;try{const o=oge(n.records);s=Object.fromEntries(o.map(i=>[i.id,i])),r=e.migrateStoreSnapshot({store:s,schema:n.schema})}catch(o){return wn.err({type:"invalidRecords",cause:o})}if(r.type==="error")return wn.err({type:"migrationFailed",reason:r.reason});try{return wn.ok(Hu({snapshot:{store:s,schema:n.schema},schema:e}))}catch(o){return wn.err({type:"invalidRecords",cause:o})}}function oge(t){const e=new Set;for(const n of t)n.typeName==="shape"&&"assetId"in n.props&&n.props.assetId&&e.add(n.props.assetId);return t.filter(n=>n.typeName!=="asset"||e.has(n.id))}_i("tldraw","3.7.2","esm");function ige(){const[t,e]=w.useState();function n(r){window.editor=r,t===void 0?fetch("/tldr-data").then(async s=>{if(!s.ok){console.log(`No tldr data to load from local endpoint (${s.status})`);return}return s.text()}).then(s=>{if(s===void 0)return;const o=sge({json:s,schema:r.store.schema});o.ok?(console.log("Loaded tldr file from local endpoint"),e(o.value)):console.error(`Couldn't parse tldr file: ${String(o.error.type)}`)}).catch(s=>{console.error("Couldn't fetch data:",s)}):(r.zoomToFit(),r.clearOpenMenus())}return d.jsx("div",{style:{inset:0,position:"fixed"},children:d.jsx(Zpe,{assetUrls:h8(),onMount:n,store:t})})}QS.createRoot(document.querySelector("#root")).render(d.jsx(ke.StrictMode,{children:d.jsx(ige,{})}));
|