@kitschpatrol/tldraw-cli 4.3.0 → 4.3.2
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 +5 -5
- package/dist/.DS_Store +0 -0
- package/dist/lib/index.js +4 -4
- package/dist/tldraw/assets/{index-BXtO505R.js → index-DYBjYoWp.js} +2 -2
- package/dist/tldraw/index.html +1 -1
- package/package.json +11 -11
- package/readme.md +28 -27
|
@@ -234,7 +234,7 @@ Error generating stack: `+s.message+`
|
|
|
234
234
|
`)},BX=function(e){var n=e.noRelative,t=e.noImportant,r=e.gapMode,o=r===void 0?"margin":r,s=x.useMemo(function(){return NX(o)},[o]);return x.useEffect(function(){return document.body.setAttribute(of,""),function(){document.body.removeAttribute(of)}},[]),x.createElement(FX,{styles:zX(s,!n,o,t?"":"!important")})},hv=!1;if(typeof window<"u")try{var Wd=Object.defineProperty({},"passive",{get:function(){return hv=!0,!0}});window.addEventListener("test",Wd,Wd),window.removeEventListener("test",Wd,Wd)}catch{hv=!1}var aa=hv?{passive:!1}:!1,UX=function(e){return e.tagName==="TEXTAREA"},mM=function(e,n){var t=window.getComputedStyle(e);return t[n]!=="hidden"&&!(t.overflowY===t.overflowX&&!UX(e)&&t[n]==="visible")},HX=function(e){return mM(e,"overflowY")},KX=function(e){return mM(e,"overflowX")},UC=function(e,n){var t=n;do{typeof ShadowRoot<"u"&&t instanceof ShadowRoot&&(t=t.host);var r=yM(e,t);if(r){var o=SM(e,t),s=o[1],i=o[2];if(s>i)return!0}t=t.parentNode}while(t&&t!==document.body);return!1},VX=function(e){var n=e.scrollTop,t=e.scrollHeight,r=e.clientHeight;return[n,t,r]},WX=function(e){var n=e.scrollLeft,t=e.scrollWidth,r=e.clientWidth;return[n,t,r]},yM=function(e,n){return e==="v"?HX(n):KX(n)},SM=function(e,n){return e==="v"?VX(n):WX(n)},GX=function(e,n){return e==="h"&&n==="rtl"?-1:1},YX=function(e,n,t,r,o){var s=GX(e,window.getComputedStyle(n).direction),i=s*r,a=t.target,l=n.contains(a),c=!1,u=i>0,d=0,h=0;do{var f=SM(e,a),y=f[0],g=f[1],v=f[2],S=g-v-s*y;(y||S)&&yM(e,a)&&(d+=S,h+=y),a=a.parentNode}while(!l&&a!==document.body||l&&(n.contains(a)||n===a));return(u&&(o&&d===0||!o&&i>d)||!u&&(o&&h===0||!o&&-i>h))&&(c=!0),c},Gd=function(e){return"changedTouches"in e?[e.changedTouches[0].clientX,e.changedTouches[0].clientY]:[0,0]},HC=function(e){return[e.deltaX,e.deltaY]},KC=function(e){return e&&"current"in e?e.current:e},XX=function(e,n){return e[0]===n[0]&&e[1]===n[1]},qX=function(e){return`
|
|
235
235
|
.block-interactivity-`.concat(e,` {pointer-events: none;}
|
|
236
236
|
.allow-interactivity-`).concat(e,` {pointer-events: all;}
|
|
237
|
-
`)},ZX=0,la=[];function QX(e){var n=x.useRef([]),t=x.useRef([0,0]),r=x.useRef(),o=x.useState(ZX++)[0],s=x.useState(function(){return gM()})[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=xX([e.lockRef.current],(e.shards||[]).map(KC),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(g,v){if("touches"in g&&g.touches.length===2)return!i.current.allowPinchZoom;var S=Gd(g),w=t.current,C="deltaX"in g?g.deltaX:w[0]-S[0],I="deltaY"in g?g.deltaY:w[1]-S[1],P,E=g.target,_=Math.abs(C)>Math.abs(I)?"h":"v";if("touches"in g&&_==="h"&&E.type==="range")return!1;var k=UC(_,E);if(!k)return!0;if(k?P=_:(P=_==="v"?"h":"v",k=UC(_,E)),!k)return!1;if(!r.current&&"changedTouches"in g&&(C||I)&&(r.current=P),!P)return!0;var M=r.current||P;return YX(M,v,g,M==="h"?C:I,!0)},[]),l=x.useCallback(function(g){var v=g;if(!(!la.length||la[la.length-1]!==s)){var S="deltaY"in v?HC(v):Gd(v),w=n.current.filter(function(P){return P.name===v.type&&P.target===v.target&&XX(P.delta,S)})[0];if(w&&w.should){v.cancelable&&v.preventDefault();return}if(!w){var C=(i.current.shards||[]).map(KC).filter(Boolean).filter(function(P){return P.contains(v.target)}),I=C.length>0?a(v,C[0]):!i.current.noIsolation;I&&v.cancelable&&v.preventDefault()}}},[]),c=x.useCallback(function(g,v,S,w){var C={name:g,delta:v,target:S,should:w};n.current.push(C),setTimeout(function(){n.current=n.current.filter(function(I){return I!==C})},1)},[]),u=x.useCallback(function(g){t.current=Gd(g),r.current=void 0},[]),d=x.useCallback(function(g){c(g.type,HC(g),g.target,a(g,e.lockRef.current))},[]),h=x.useCallback(function(g){c(g.type,Gd(g),g.target,a(g,e.lockRef.current))},[]);x.useEffect(function(){return la.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:h}),document.addEventListener("wheel",l,aa),document.addEventListener("touchmove",l,aa),document.addEventListener("touchstart",u,aa),function(){la=la.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,aa),document.removeEventListener("touchmove",l,aa),document.removeEventListener("touchstart",u,aa)}},[]);var f=e.removeScrollBar,y=e.inert;return x.createElement(x.Fragment,null,y?x.createElement(s,{styles:qX(o)}):null,f?x.createElement(BX,{gapMode:"margin"}):null)}const JX=TX(fM,QX);var vM=x.forwardRef(function(e,n){return x.createElement(eg,eo({},e,{ref:n,sideCar:JX}))});vM.classNames=eg.classNames;const Bw=vM,wM="Popover",[xM,Mne]=go(wM,[Jf]),Uw=Jf(),[eq,Sl]=xM(wM),tq=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Uw(n),l=x.useRef(null),[c,u]=x.useState(!1),[d=!1,h]=Ws({prop:r,defaultProp:o,onChange:s});return x.createElement(Fw,a,x.createElement(eq,{scope:n,contentId:Fo(),triggerRef:l,open:d,onOpenChange:h,onOpenToggle:x.useCallback(()=>h(f=>!f),[h]),hasCustomAnchor:c,onCustomAnchorAdd:x.useCallback(()=>u(!0),[]),onCustomAnchorRemove:x.useCallback(()=>u(!1),[]),modal:i},t))},nq="PopoverTrigger",rq=x.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Sl(nq,t),s=Uw(t),i=Ye(n,o.triggerRef),a=x.createElement(Be.button,Q({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":CM(o.open)},r,{ref:i,onClick:se(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(cM,Q({asChild:!0},s),a)}),bM="PopoverPortal",[oq,sq]=xM(bM,{forceMount:void 0}),iq=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=Sl(bM,n);return x.createElement(oq,{scope:n,forceMount:t},x.createElement(mo,{present:t||s.open},x.createElement(Yf,{asChild:!0,container:o},r)))},ou="PopoverContent",aq=x.forwardRef((e,n)=>{const t=sq(ou,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=Sl(ou,e.__scopePopover);return x.createElement(mo,{present:r||s.open},s.modal?x.createElement(lq,Q({},o,{ref:n})):x.createElement(cq,Q({},o,{ref:n})))}),lq=x.forwardRef((e,n)=>{const t=Sl(ou,e.__scopePopover),r=x.useRef(null),o=Ye(n,r),s=x.useRef(!1);return x.useEffect(()=>{const i=r.current;if(i)return zw(i)},[]),x.createElement(Bw,{as:Ei,allowPinchZoom:!0},x.createElement(PM,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),cq=x.forwardRef((e,n)=>{const t=Sl(ou,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(PM,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),PM=x.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...d}=e,h=Sl(ou,t),f=Uw(t);return Mw(),x.createElement(Aw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(Gf,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>h.onOpenChange(!1)},x.createElement(uM,Q({"data-state":CM(h.open),role:"dialog",id:h.contentId},f,d,{ref:n,style:{...d.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}}))))});function CM(e){return e?"open":"closed"}const uq=tq,dq=rq,hq=iq,pq=aq,IM=()=>{},EM=x.createContext({});function fq({onEvent:e,children:n}){return p.jsx(EM.Provider,{value:e??IM,children:n})}function yo(){return x.useContext(EM)??IM}function Gs(e,n){const t=F(),r=x.useRef(!1),o=yo(),s=x.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(l=>!l.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=K("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return x.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),t.addOpenMenu(e)),()=>{r.current&&(t.deleteOpenMenu(e),t.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),t.deleteOpenMenu(a))}),r.current=!1)}),[t,e,o]),[i,s]}function Hw({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=Gs(e,t);return p.jsx(uq,{onOpenChange:s,open:r||o,children:p.jsx("div",{className:"tlui-popover",children:n})})}function Kw({children:e}){return p.jsx(dq,{asChild:!0,dir:"ltr",children:e})}function Vw({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=mn();return p.jsx(hq,{container:s,children:p.jsx(pq,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const _M=x.createContext({type:"menu",sourceId:"main-menu"});function tg(){return x.useContext(_M)}function So({type:e,sourceId:n,children:t}){return p.jsx(_M.Provider,{value:{type:e,sourceId:n},children:t})}function gq(e,n){const t=ge(n.map(o=>e.getShape(o)).filter(o=>o&&e.isShapeOfType(o,"frame")));if(!t.length)return;const r=[];e.batch(()=>{t.map(o=>{const s=e.getSortedChildIdsForParent(o.id);s.length&&(e.reparentShapes(s,o.parentId,o.index),r.push(...s))}),e.setSelectedShapes(r),e.deleteShapes(n)})}const mq=50;function yq(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=ge(o.map(f=>e.getShape(f)));if(!s.length)return;const i=ne.FromPoints(s.flatMap(f=>{const y=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(y.vertices)})),{padding:a=mq}=t,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,d=a-i.minY;if(u===0&&d===0&&r.props.w===l&&r.props.h===c)return;const h=new b(u,d).rot(r.rotation);e.batch(()=>{const f=o.map(y=>{const g=e.getShape(y);return{id:g.id,type:g.type,x:g.x+u,y:g.y+d}});f.push({id:r.id,type:r.type,x:r.x-h.x,y:r.y-h.y,props:{w:l,h:c}}),e.updateShapes(f)})}function mt({children:e}){return p.jsx("span",{className:"tlui-button__label",children:e})}const kM="Dialog",[TM,Ane]=go(kM),[Sq,es]=TM(kM),vq=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),l=x.useRef(null),[c=!1,u]=Ws({prop:r,defaultProp:o,onChange:s});return x.createElement(Sq,{scope:n,triggerRef:a,contentRef:l,contentId:Fo(),titleId:Fo(),descriptionId:Fo(),open:c,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(d=>!d),[u]),modal:i},t)},$M="DialogPortal",[wq,MM]=TM($M,{forceMount:void 0}),xq=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=es($M,n);return x.createElement(wq,{scope:n,forceMount:t},x.Children.map(r,i=>x.createElement(mo,{present:t||s.open},x.createElement(Yf,{asChild:!0,container:o},i))))},pv="DialogOverlay",bq=x.forwardRef((e,n)=>{const t=MM(pv,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=es(pv,e.__scopeDialog);return s.modal?x.createElement(mo,{present:r||s.open},x.createElement(Pq,Q({},o,{ref:n}))):null}),Pq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=es(pv,t);return x.createElement(Bw,{as:Ei,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(Be.div,Q({"data-state":jM(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),su="DialogContent",Cq=x.forwardRef((e,n)=>{const t=MM(su,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=es(su,e.__scopeDialog);return x.createElement(mo,{present:r||s.open},s.modal?x.createElement(Iq,Q({},o,{ref:n})):x.createElement(Eq,Q({},o,{ref:n})))}),Iq=x.forwardRef((e,n)=>{const t=es(su,e.__scopeDialog),r=x.useRef(null),o=Ye(n,t.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return zw(s)},[]),x.createElement(AM,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault())}))}),Eq=x.forwardRef((e,n)=>{const t=es(su,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(AM,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),AM=x.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=es(su,t),l=x.useRef(null),c=Ye(n,l);return Mw(),x.createElement(x.Fragment,null,x.createElement(Aw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(Gf,Q({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":jM(a.open)},i,{ref:c,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),_q="DialogTitle",kq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=es(_q,t);return x.createElement(Be.h2,Q({id:o.titleId},r,{ref:n}))});const Tq="DialogClose",$q=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=es(Tq,t);return x.createElement(Be.button,Q({type:"button"},r,{ref:n,onClick:se(e.onClick,()=>o.onOpenChange(!1))}))});function jM(e){return e?"open":"closed"}const Mq=vq,Aq=xq,jq=bq,Oq=Cq;function ng({className:e,children:n}){return p.jsx("div",{className:fe("tlui-dialog__header",e),children:n})}function rg({className:e,children:n}){return p.jsx(kq,{dir:"ltr",className:fe("tlui-dialog__header__title",e),children:n})}function og(){return p.jsx("div",{className:"tlui-dialog__header__close",children:p.jsx($q,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:p.jsx(he,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:p.jsx(Ie,{small:!0,icon:"cross-2"})})})})}function iu({className:e,children:n,style:t}){return p.jsx("div",{className:fe("tlui-dialog__body",e),style:t,children:n})}function Ww({className:e,children:n}){return p.jsx("div",{className:fe("tlui-dialog__footer",e),children:n})}const Gw=x.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoselect:s=!1,autofocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:d,onBlur:h,shouldManuallyMaintainScrollPositionWhenFocused:f=!1,children:y,value:g},v){const S=F(),w=x.useRef(null);x.useImperativeHandle(v,()=>w.current);const C=Ee(),I=x.useRef(a??""),P=x.useRef(a??""),[E,_]=x.useState(!1),k=x.useCallback(O=>{_(!0);const U=O.currentTarget;P.current=U.value,requestAnimationFrame(()=>{s&&U.select()})},[s]),M=x.useCallback(O=>{const U=O.currentTarget.value;P.current=U,u==null||u(U)},[u]),T=x.useCallback(O=>{switch(O.key){case"Enter":{O.currentTarget.blur(),It(O),c==null||c(O.currentTarget.value);break}case"Escape":{O.currentTarget.value=I.current,O.currentTarget.blur(),It(O),d==null||d(O.currentTarget.value);break}}},[c,d]),R=x.useCallback(O=>{_(!1);const U=O.currentTarget.value;h==null||h(U)},[h]);return x.useEffect(()=>{if(!S.environment.isIos)return;const O=window.visualViewport;if(E&&f&&O){const U=()=>{var N;(N=w.current)==null||N.scrollIntoView({block:"center"})};return O.addEventListener("resize",U),O.addEventListener("scroll",U),requestAnimationFrame(()=>{var N;(N=w.current)==null||N.scrollIntoView({block:"center"})}),()=>{O.removeEventListener("resize",U),O.removeEventListener("scroll",U)}}},[S,E,f]),p.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,t&&p.jsx("label",{children:C(t)}),o&&p.jsx(Rs,{icon:o,className:"tlui-icon-left",small:!0}),p.jsx("input",{ref:w,className:fe("tlui-input",n),type:"text",defaultValue:a,onKeyUp:T,onChange:M,onFocus:k,onBlur:R,autoFocus:i,placeholder:l,value:g}),r&&p.jsx(Rs,{icon:r,small:!!t})]})});function VC(e){return Qn.isValid(e)?{isValid:!0,hasProtocol:!0}:Qn.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Dq=Tt(function({onClose:n}){const r=F().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?p.jsx(Rq,{onClose:n,selectedShape:r}):null}),Rq=Tt(function({onClose:n,selectedShape:t}){const r=F(),o=Ee(),s=x.useRef(null);x.useEffect(()=>{requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[]);const i=x.useRef(t.props.url),[a,l]=x.useState(()=>{const y=VC(t.props.url),g=y.isValid===!0?y.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:g,safe:g,valid:!0}}),c=x.useCallback(y=>{const g=y.replace(/https?:\/\/(https?:\/\/)/,(w,C)=>C),v=VC(g),S=v.isValid===!0?v.hasProtocol?g:"https://"+g:"https://";l({actual:g,safe:S,valid:v.isValid})},[]),u=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),n())},[r,n]),d=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),n())},[r,n,a]),h=x.useCallback(()=>{n()},[n]);if(!t)return n(),null;const f=i.current&&!a.valid;return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{children:[p.jsx(rg,{children:o("edit-link-dialog.title")}),p.jsx(og,{})]}),p.jsx(iu,{children:p.jsxs("div",{className:"tlui-edit-link-dialog",children:[p.jsx(Gw,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autofocus:!0,value:a.actual,onValueChange:c,onComplete:d,onCancel:h}),p.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),p.jsxs(Ww,{className:"tlui-dialog__footer__actions",children:[p.jsx(he,{type:"normal",onClick:h,onTouchEnd:h,children:p.jsx(mt,{children:o("edit-link-dialog.cancel")})}),f?p.jsx(he,{type:"danger",onTouchEnd:u,onClick:u,children:p.jsx(mt,{children:o("edit-link-dialog.clear")})}):p.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:p.jsx(mt,{children:o("edit-link-dialog.save")})})]})]})}),OM=Tt(function({onClose:n}){const t=F(),r=Ee(),o=$w(),[s,i]=x.useState(null),[a,l]=x.useState(""),[c,u]=x.useState(null),[d,h]=x.useState(!1),f=x.useRef(-1);return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{children:[p.jsx(rg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),p.jsx(og,{})]}),s?p.jsxs(p.Fragment,{children:[p.jsxs(iu,{className:"tlui-embed-dialog__enter",children:[p.jsx(Gw,{className:"tlui-embed-dialog__input",label:"embed-url",placeholder:"http://example.com",autofocus:!0,onValueChange:y=>{l(y);const g=Ao(y);u(g&&g.definition.type===s.type?g:null),h(!1),clearTimeout(f.current),f.current=setTimeout(()=>h(!g),320)}}),a===""?p.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[p.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&p.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",p.jsx(Rs,{icon:"external-link",small:!0})]})]}):p.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),p.jsxs(Ww,{className:"tlui-dialog__footer__actions",children:[p.jsx(he,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:p.jsx(mt,{children:r("embed-dialog.back")})}),p.jsx("div",{className:"tlui-embed__spacer"}),p.jsx(he,{type:"normal",onClick:n,children:p.jsx(mt,{children:r("embed-dialog.cancel")})}),p.jsx(he,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageCenter(),embed:c.definition}),n())},children:p.jsx(mt,{children:r("embed-dialog.create")})})]})]}):p.jsx(p.Fragment,{children:p.jsx(iu,{className:"tlui-embed-dialog__list",children:Ha.map(y=>p.jsxs(he,{type:"menu",onClick:()=>i(y),children:[p.jsx(mt,{children:y.title}),p.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})]},y.type))})})]})});var Yw={exports:{}};Yw.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),d=0,h=c.length;d<h;d++){var f=c.charCodeAt(d);u[d*2]=f>>>8,u[d*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,d=c.length;u<d;u++)c[u]=l[u*2]*256+l[u*2+1];var h=[];return c.forEach(function(f){h.push(t(f))}),a.decompress(h.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,u){if(l==null)return"";var d,h,f={},y={},g="",v="",S="",w=2,C=3,I=2,P=[],E=0,_=0,k;for(k=0;k<l.length;k+=1)if(g=l.charAt(k),Object.prototype.hasOwnProperty.call(f,g)||(f[g]=C++,y[g]=!0),v=S+g,Object.prototype.hasOwnProperty.call(f,v))S=v;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<I;d++)E=E<<1,_==c-1?(_=0,P.push(u(E)),E=0):_++;for(h=S.charCodeAt(0),d=0;d<8;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}else{for(h=1,d=0;d<I;d++)E=E<<1|h,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=0;for(h=S.charCodeAt(0),d=0;d<16;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}w--,w==0&&(w=Math.pow(2,I),I++),delete y[S]}else for(h=f[S],d=0;d<I;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1;w--,w==0&&(w=Math.pow(2,I),I++),f[v]=C++,S=String(g)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<I;d++)E=E<<1,_==c-1?(_=0,P.push(u(E)),E=0):_++;for(h=S.charCodeAt(0),d=0;d<8;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}else{for(h=1,d=0;d<I;d++)E=E<<1|h,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=0;for(h=S.charCodeAt(0),d=0;d<16;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}w--,w==0&&(w=Math.pow(2,I),I++),delete y[S]}else for(h=f[S],d=0;d<I;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1;w--,w==0&&(w=Math.pow(2,I),I++)}for(h=2,d=0;d<I;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1;for(;;)if(E=E<<1,_==c-1){P.push(u(E));break}else _++;return P.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var d=[],h=4,f=4,y=3,g="",v=[],S,w,C,I,P,E,_,k={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)d[S]=S;for(C=0,P=Math.pow(2,2),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;switch(C){case 0:for(C=0,P=Math.pow(2,8),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;_=t(C);break;case 1:for(C=0,P=Math.pow(2,16),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;_=t(C);break;case 2:return""}for(d[3]=_,w=_,v.push(_);;){if(k.index>l)return"";for(C=0,P=Math.pow(2,y),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;switch(_=C){case 0:for(C=0,P=Math.pow(2,8),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;d[f++]=t(C),_=f-1,h--;break;case 1:for(C=0,P=Math.pow(2,16),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;d[f++]=t(C),_=f-1,h--;break;case 2:return v.join("")}if(h==0&&(h=Math.pow(2,y),y++),d[_])g=d[_];else if(_===f)g=w+w.charAt(0);else return null;v.push(g),d[f++]=w+g.charAt(0),h--,w=g,h==0&&(h=Math.pow(2,y),y++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(Yw);var DM=Yw.exports;async function Lq(e,n,t){var S,w,C;const{elements:r,files:o}=n,s={shapes:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,u=[],d=new Set;r.forEach(I=>{if(c.set(I.id,We()),I.boundElements!==null)for(const P of I.boundElements)P.type==="text"&&d.add(P.id)});let h=dD;for(const I of r){if(d.has(I.id))continue;const P=c.get(I.id),E={id:P,typeName:"shape",parentId:l,index:h,x:I.x,y:I.y,rotation:0,isLocked:I.locked,opacity:Nq(I.opacity),meta:{}};switch(I.angle!==0&&a.set(P,I.angle),I.groupIds&&I.groupIds.length>0?i.has(I.groupIds[0])?(S=i.get(I.groupIds[0]))==null||S.push(P):i.set(I.groupIds[0],[P]):u.push(P),I.type){case"rectangle":case"ellipse":case"diamond":{let _="",k="middle";if(I.boundElements!==null){for(const T of I.boundElements)if(T.type==="text"){const R=r.find(O=>O.id===T.id);R&&(_=R.text,k=WC[R.textAlign])}}const M=I.backgroundColor==="transparent"?I.strokeColor:I.backgroundColor;s.shapes.push({...E,type:"geo",props:{geo:I.type,url:I.link??"",w:I.width,h:I.height,size:Yd[I.strokeWidth]??"draw",color:Kl[M]??"black",text:_,align:k,dash:Xd(I),fill:Vq(I)}});break}case"freedraw":{s.shapes.push({...E,type:"draw",props:{dash:Xd(I),size:Yd[I.strokeWidth],color:Kl[I.strokeColor]??"black",segments:[{type:"free",points:I.points.map(([_,k,M=.5])=>({x:_,y:k,z:M}))}]}});break}case"line":{const _=I.points[0],k=I.points[I.points.length-1],M=Pc(I.points.length);s.shapes.push({...E,type:"line",props:{dash:Xd(I),size:Yd[I.strokeWidth],color:Kl[I.strokeColor]??"black",spline:I.roundness?"cubic":"line",handles:{start:{id:"start",type:"vertex",index:M[0],x:_[0],y:_[1]},end:{id:"end",type:"vertex",index:M[M.length-1],x:k[0],y:k[1]},...Object.fromEntries(I.points.slice(1,-1).map(([T,R],O)=>{const U=ze();return[U,{id:U,type:"vertex",index:M[O+1],x:T,y:R}]}))}}});break}case"arrow":{let _="";if(I.boundElements!==null){for(const O of I.boundElements)if(O.type==="text"){const U=r.find(N=>N.id===O.id);U&&(_=U.text)}}const k=I.points[0],M=I.points[I.points.length-1],T=c.get((w=I.startBinding)==null?void 0:w.elementId),R=c.get((C=I.endBinding)==null?void 0:C.elementId);s.shapes.push({...E,type:"arrow",props:{text:_,bend:Kq(I,k,M),dash:Xd(I),size:Yd[I.strokeWidth]??"m",color:Kl[I.strokeColor]??"black",start:T?{type:"binding",boundShapeId:T,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:k[0],y:k[1]},end:R?{type:"binding",boundShapeId:R,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:M[0],y:M[1]},arrowheadEnd:GC[I.endArrowhead]??"none",arrowheadStart:GC[I.startArrowhead]??"none"}});break}case"text":{const{size:_,scale:k}=zq(I.fontSize);s.shapes.push({...E,type:"text",props:{size:_,scale:k,font:Bq[I.fontFamily]??"draw",color:Kl[I.strokeColor]??"black",text:I.text,align:WC[I.textAlign]}});break}case"image":{const _=o[I.fileId];if(!_)break;const k=li.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:I.width,h:I.height,name:I.id??"Untitled",isAnimated:!1,mimeType:_.mimeType,src:_.dataURL},meta:{}}),s.shapes.push({...E,type:"image",props:{w:I.width,h:I.height,assetId:k}})}}h=ko(h)}const f=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:f,select:!1,preserveIds:!0});for(const I of i.values())if(I.length>1){e.groupShapes(I);const P=e.getShape(I[0]);P!=null&&P.parentId&&Hn(P.parentId)&&u.push(P.parentId)}for(const[I,P]of a)e.select(I),e.rotateShapesBy([I],P);const y=ge(u.map(I=>e.getShape(I))),g=ne.Common(y.map(I=>e.getShapePageBounds(I))),v=e.getViewportPageBounds().center;e.updateShapes(y.map(I=>{const P={x:(I.x??0)-(g.x+g.w/2),y:(I.y??0)-(g.y+g.h/2)};return{id:I.id,type:I.type,x:v.x+P.x,y:v.y+P.y}})),e.setSelectedShapes(u)}const Nq=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},Yd={1:"s",2:"m",3:"l",4:"xl"},Fq={16:"s",20:"m",28:"l",36:"xl"};function zq(e){const n=Fq[e];return n?{size:n,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}const Bq={1:"draw",2:"sans",3:"mono"},Kl={"#ffffff":"grey","#000000":"black","#343a40":"black","#495057":"grey","#c92a2a":"red","#a61e4d":"light-red","#862e9c":"violet","#5f3dc4":"light-violet","#364fc7":"blue","#1864ab":"light-blue","#0b7285":"light-green","#087f5b":"light-green","#2b8a3e":"green","#5c940d":"light-green","#e67700":"yellow","#d9480f":"orange","#ced4da":"grey","#868e96":"grey","#fa5252":"light-red","#e64980":"red","#be4bdb":"light-violet","#7950f2":"violet","#4c6ef5":"blue","#228be6":"light-blue","#15aabf":"light-green","#12b886":"green","#40c057":"green","#82c91e":"light-green","#fab005":"yellow","#fd7e14":"orange","#212529":"grey"},Uq={solid:"draw",dashed:"dashed",dotted:"dotted"},Hq={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},WC={left:"start",center:"middle",right:"end"},GC={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Kq(e,n,t){let r=0;if(e.points.length>2){const o=new b(n[0],n[1]),s=new b(t[0],t[1]),i=new b(e.points[1][0],e.points[1][1]),a=b.Sub(s,o),l=b.Per(a),c=b.Med(s,o),u=b.Sub(c,l),d=b.Add(c,l),h=b.NearestPointOnLineSegment(u,d,i,!1);r=b.Dist(h,c),b.Clockwise(h,s,c)&&(r*=-1)}return r}const Xd=e=>{let n=Uq[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},Vq=e=>e.backgroundColor==="transparent"?"none":Hq[e.fillStyle]??"solid";async function RM(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await fetch(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r}),n.forEach(i=>URL.revokeObjectURL(i))}function Wq(e,n,t){const r=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(n,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0}),setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},150))}async function fv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await fetch(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),RM(e,[n]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:t,url:n,sources:r})}function Gq(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const Yq=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},Xq=e=>{const n=e.split(/[\n\s]/);for(const t of n)try{const r=new URL(t);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return HE(n)},qq=e=>/^<svg/.test(e),Zq=["input","select","textarea"];function Zh(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||Zq.indexOf(n.tagName.toLowerCase())>-1)}async function ty(e){return new Promise((n,t)=>{const r=new FileReader;r.addEventListener("loadend",()=>{const o=r.result;n(o)}),r.addEventListener("error",()=>{t(r.error)}),r.readAsText(e)})}const Qq=e=>e.types.find(n=>n.match(/^image\//)),ny=(e,n,t,r)=>{const o=Xq(n);if(o)for(const s of o)fv(e,s,t);else Yq(n)?fv(e,n,t):qq(n)?(e.mark("paste"),e.putExternalContent({type:"svg-text",text:n,point:t,sources:r})):(e.mark("paste"),e.putExternalContent({type:"text",text:n,point:t,sources:r}))},Jq=async(e,n,t)=>{if(e.getEditingShapeId()!==null)return;if(!n)throw Error("No clipboard data");const r=[];for(const o of Object.values(n.items))switch(o.kind){case"file":{r.push({type:"file",source:new Promise(s=>s(o.getAsFile()))});break}case"string":{o.type==="text/html"?r.push({type:"html",source:new Promise(s=>o.getAsString(s))}):o.type==="text/plain"?r.push({type:"text",source:new Promise(s=>o.getAsString(s))}):r.push({type:o.type,source:new Promise(s=>o.getAsString(s))});break}}NM(e,r,t)},LM=async(e,n,t)=>{const r=[];for(const o of n){if(Qq(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:new Promise(s=>o.getType("text/html").then(i=>ty(i).then(s)))}),o.types.includes("text/uri-list")&&r.push({type:"url",source:new Promise(s=>o.getType("text/uri-list").then(i=>ty(i).then(s)))}),o.types.includes("text/plain")&&r.push({type:"text",source:new Promise(s=>o.getType("text/plain").then(i=>ty(i).then(s)))})}return await NM(e,r,t)};async function NM(e,n,t){const r=n.filter(s=>(s.type==="file"||s.type==="blob")&&s.source!==null);if(r.length){const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await RM(e,i,t)}const o=await Promise.all(n.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:u[1];if(c)try{const d=DM.decompressFromBase64(c);if(d===null){i({type:"error",data:d,reason:"found tldraw data comment but could not parse base64"});return}else{const h=JSON.parse(d);if(h.type!=="application/tldraw"&&i({type:"error",data:h,reason:`found tldraw data comment but JSON was of a different type: ${h.type}`}),typeof h.data=="string"){i({type:"error",data:h,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:h.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const d=JSON.parse(l);if(d.type==="excalidraw/clipboard"){i({type:"excalidraw",data:d});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){Wq(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){Lq(e,s.data,t);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");ny(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){ny(e,Gq(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){fv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){ny(e,s.data,t,o);return}}const sf=e=>{var r;const n=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=DM.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:n}));if(!(typeof navigator>"u")){const o=n.shapes.map(s=>e.isShapeOfType(s,"text")||e.isShapeOfType(s,"geo")||e.isShapeOfType(s,"arrow")?s.props.text:e.isShapeOfType(s,"bookmark")||e.isShapeOfType(s,"embed")?s.props.url:null).filter(gD);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<tldraw>${t}</tldraw>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${t}</tldraw>`)}};function eZ(){const e=F(),n=yo(),t=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(sf(e),n("copy",{source:i}))},[e,n]),r=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(sf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=x.useCallback(async function(i,a,l){e.getEditingShapeId()!==null||Zh(e)||(Array.isArray(i)&&i[0]instanceof ClipboardItem?(LM(e,i,l),n("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[e,n]);return{copy:t,cut:r,paste:o}}function tZ(){const e=F(),n=yo(),t=K("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!t)return;const r=()=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Zh(e)||(sf(e),n("copy",{source:"kbd"}))};function o(){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Zh(e)||(sf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){l.stopPropagation();return}e.getEditingShapeId()!==null||Zh(e)||(l.clipboardData&&!e.inputs.shiftKey?Jq(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&LM(e,c,e.inputs.currentPagePoint)}),n("paste",{source:"kbd"}))};return document.addEventListener("copy",r),document.addEventListener("cut",o),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[e,n,t])}async function FM(e,n,t){const{type:r,quality:o,scale:s}=t,i=+e.getAttribute("width"),a=+e.getAttribute("height");let[l,c]=await $k(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,d=await Xw(e),h=URL.createObjectURL(new Blob([d],{type:"image/svg+xml"})),f=await new Promise(v=>{const S=new Image;S.crossOrigin="anonymous",S.onload=async()=>{n&&await new Promise(I=>setTimeout(I,250));const w=document.createElement("canvas"),C=w.getContext("2d");w.width=l,w.height=c,C.imageSmoothingEnabled=!0,C.imageSmoothingQuality="high",C.drawImage(S,0,0,l,c),URL.revokeObjectURL(h),v(w)},S.onerror=()=>{v(null)},S.src=h});if(!f)return null;const y=await new Promise(v=>f.toBlob(S=>{(!S||Ft.throwToBlob.get())&&v(null),v(S)},"image/"+r,o));if(!y)return null;const g=new DataView(await y.arrayBuffer());return Qr.setPhysChunk(g,u,{type:"image/"+r})}async function Xw(e){const n=e.cloneNode(!0);e.setAttribute("width",+e.getAttribute("width")+""),e.setAttribute("height",+e.getAttribute("height")+"");const t=new FileReader,r=Array.from(n.querySelectorAll("image"));for(const s of r){const i=s.getAttribute("xlink:href");if(i&&!i.startsWith("data:")){const a=await(await fetch(i)).blob(),l=await new Promise((c,u)=>{t.onload=()=>c(t.result),t.onerror=()=>u(t.error),t.readAsDataURL(a)});s.setAttribute("xlink:href",l)}}return new XMLSerializer().serializeToString(n).replaceAll(" ","").replaceAll(/((\s|")[0-9]*\.[0-9]{2})([0-9]*)(\b|"|\))/g,"$1")}async function zM(e,n,t){const r=await e.getSvg(n!=null&&n.length?n:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...t});if(!r)throw new Error("Could not construct SVG.");return r}async function gv(e,n,t,r={}){switch(t){case"svg":return Xw(await zM(e,n,r));case"json":{const o=e.getContentFromCurrentPage(n);return JSON.stringify(o)}default:Ai(t)}}async function BM({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await gv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await gv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await FM(await zM(e,n,r),e.environment.isSafari,{type:t,quality:1,scale:2});if(!o)throw new Error("Could not construct image.");return o}default:Ai(t)}}const nZ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function rZ(e,n,t,r={}){return{blobPromise:BM({editor:e,ids:n,format:t,opts:r}),mimeType:nZ[t]}}function oZ(e,n,t="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=rZ(e,n,t,r);return window.navigator.clipboard.write([new ClipboardItem({[s]:o})]).catch(i=>(console.error(i),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[s]:a})]))))}switch(t){case"json":case"svg":return sZ(async()=>gv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ai(t)}}async function sZ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}const UM=x.createContext({});function iZ({children:e}){const[n,t]=x.useState([]),r=x.useCallback(i=>{const a=i.id??ze();return t(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=x.useCallback(i=>(t(a=>a.filter(l=>l.id!==i)),i),[]),s=x.useCallback(()=>{t(()=>[])},[]);return p.jsx(UM.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})}function Wr(){const e=x.useContext(UM);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}function aZ(){const e=F(),{addToast:n}=Wr(),t=Ee();return x.useCallback((r,o="svg")=>{oZ(e,r,o).catch(()=>{n({id:"copy-fail",icon:"warning-triangle",title:t("toast.error.copy-fail.title"),description:t("toast.error.copy-fail.desc")})})},[e,n,t])}async function lZ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${YC()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${YC()}`}r+=`.${t}`;const s=await BM({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});cZ(i)}function YC(){const e=new Date,n=String(e.getFullYear()).slice(2),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return`${n}-${t}-${r} ${o}.${s}.${i}`}function cZ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function uZ(){const e=F(),{addToast:n}=Wr(),t=Ee();return x.useCallback((r,o="png",s)=>{lZ(e,r,o,s,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),n({id:"export-fail",title:t("toast.error.export-fail.title"),description:t("toast.error.export-fail.desc")})})},[e,n,t])}function HM(){const e=F(),n=x.useRef();return x.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept="image/jpeg,image/png,image/gif,image/svg+xml,video/mp4,video/quicktime",t.multiple=!0,n.current=t;async function r(o){const s=o.target.files;!s||s.length===0||(await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),t.value="")}return t.addEventListener("change",r),()=>{n.current=void 0,t.removeEventListener("change",r)}},[e]),x.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}function dZ(){const e=F(),n=x.useRef(null),t=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,w)=>{S&&(S.innerHTML=""),w&&document.head.contains(w)&&document.head.removeChild(w),S&&document.body.contains(S)&&document.body.removeChild(S)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${ze()}`;o.className=a,s.innerHTML=`
|
|
237
|
+
`)},ZX=0,la=[];function QX(e){var n=x.useRef([]),t=x.useRef([0,0]),r=x.useRef(),o=x.useState(ZX++)[0],s=x.useState(function(){return gM()})[0],i=x.useRef(e);x.useEffect(function(){i.current=e},[e]),x.useEffect(function(){if(e.inert){document.body.classList.add("block-interactivity-".concat(o));var g=xX([e.lockRef.current],(e.shards||[]).map(KC),!0).filter(Boolean);return g.forEach(function(v){return v.classList.add("allow-interactivity-".concat(o))}),function(){document.body.classList.remove("block-interactivity-".concat(o)),g.forEach(function(v){return v.classList.remove("allow-interactivity-".concat(o))})}}},[e.inert,e.lockRef.current,e.shards]);var a=x.useCallback(function(g,v){if("touches"in g&&g.touches.length===2)return!i.current.allowPinchZoom;var S=Gd(g),w=t.current,C="deltaX"in g?g.deltaX:w[0]-S[0],I="deltaY"in g?g.deltaY:w[1]-S[1],P,E=g.target,_=Math.abs(C)>Math.abs(I)?"h":"v";if("touches"in g&&_==="h"&&E.type==="range")return!1;var k=UC(_,E);if(!k)return!0;if(k?P=_:(P=_==="v"?"h":"v",k=UC(_,E)),!k)return!1;if(!r.current&&"changedTouches"in g&&(C||I)&&(r.current=P),!P)return!0;var M=r.current||P;return YX(M,v,g,M==="h"?C:I,!0)},[]),l=x.useCallback(function(g){var v=g;if(!(!la.length||la[la.length-1]!==s)){var S="deltaY"in v?HC(v):Gd(v),w=n.current.filter(function(P){return P.name===v.type&&P.target===v.target&&XX(P.delta,S)})[0];if(w&&w.should){v.cancelable&&v.preventDefault();return}if(!w){var C=(i.current.shards||[]).map(KC).filter(Boolean).filter(function(P){return P.contains(v.target)}),I=C.length>0?a(v,C[0]):!i.current.noIsolation;I&&v.cancelable&&v.preventDefault()}}},[]),c=x.useCallback(function(g,v,S,w){var C={name:g,delta:v,target:S,should:w};n.current.push(C),setTimeout(function(){n.current=n.current.filter(function(I){return I!==C})},1)},[]),u=x.useCallback(function(g){t.current=Gd(g),r.current=void 0},[]),d=x.useCallback(function(g){c(g.type,HC(g),g.target,a(g,e.lockRef.current))},[]),h=x.useCallback(function(g){c(g.type,Gd(g),g.target,a(g,e.lockRef.current))},[]);x.useEffect(function(){return la.push(s),e.setCallbacks({onScrollCapture:d,onWheelCapture:d,onTouchMoveCapture:h}),document.addEventListener("wheel",l,aa),document.addEventListener("touchmove",l,aa),document.addEventListener("touchstart",u,aa),function(){la=la.filter(function(g){return g!==s}),document.removeEventListener("wheel",l,aa),document.removeEventListener("touchmove",l,aa),document.removeEventListener("touchstart",u,aa)}},[]);var f=e.removeScrollBar,y=e.inert;return x.createElement(x.Fragment,null,y?x.createElement(s,{styles:qX(o)}):null,f?x.createElement(BX,{gapMode:"margin"}):null)}const JX=TX(fM,QX);var vM=x.forwardRef(function(e,n){return x.createElement(eg,eo({},e,{ref:n,sideCar:JX}))});vM.classNames=eg.classNames;const Bw=vM,wM="Popover",[xM,Mne]=go(wM,[Jf]),Uw=Jf(),[eq,Sl]=xM(wM),tq=e=>{const{__scopePopover:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!1}=e,a=Uw(n),l=x.useRef(null),[c,u]=x.useState(!1),[d=!1,h]=Ws({prop:r,defaultProp:o,onChange:s});return x.createElement(Fw,a,x.createElement(eq,{scope:n,contentId:Fo(),triggerRef:l,open:d,onOpenChange:h,onOpenToggle:x.useCallback(()=>h(f=>!f),[h]),hasCustomAnchor:c,onCustomAnchorAdd:x.useCallback(()=>u(!0),[]),onCustomAnchorRemove:x.useCallback(()=>u(!1),[]),modal:i},t))},nq="PopoverTrigger",rq=x.forwardRef((e,n)=>{const{__scopePopover:t,...r}=e,o=Sl(nq,t),s=Uw(t),i=Ye(n,o.triggerRef),a=x.createElement(Be.button,Q({type:"button","aria-haspopup":"dialog","aria-expanded":o.open,"aria-controls":o.contentId,"data-state":CM(o.open)},r,{ref:i,onClick:se(e.onClick,o.onOpenToggle)}));return o.hasCustomAnchor?a:x.createElement(cM,Q({asChild:!0},s),a)}),bM="PopoverPortal",[oq,sq]=xM(bM,{forceMount:void 0}),iq=e=>{const{__scopePopover:n,forceMount:t,children:r,container:o}=e,s=Sl(bM,n);return x.createElement(oq,{scope:n,forceMount:t},x.createElement(mo,{present:t||s.open},x.createElement(Yf,{asChild:!0,container:o},r)))},ou="PopoverContent",aq=x.forwardRef((e,n)=>{const t=sq(ou,e.__scopePopover),{forceMount:r=t.forceMount,...o}=e,s=Sl(ou,e.__scopePopover);return x.createElement(mo,{present:r||s.open},s.modal?x.createElement(lq,Q({},o,{ref:n})):x.createElement(cq,Q({},o,{ref:n})))}),lq=x.forwardRef((e,n)=>{const t=Sl(ou,e.__scopePopover),r=x.useRef(null),o=Ye(n,r),s=x.useRef(!1);return x.useEffect(()=>{const i=r.current;if(i)return zw(i)},[]),x.createElement(Bw,{as:Ei,allowPinchZoom:!0},x.createElement(PM,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,i=>{var a;i.preventDefault(),s.current||(a=t.triggerRef.current)===null||a===void 0||a.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,i=>{const a=i.detail.originalEvent,l=a.button===0&&a.ctrlKey===!0,c=a.button===2||l;s.current=c},{checkForDefaultPrevented:!1}),onFocusOutside:se(e.onFocusOutside,i=>i.preventDefault(),{checkForDefaultPrevented:!1})})))}),cq=x.forwardRef((e,n)=>{const t=Sl(ou,e.__scopePopover),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(PM,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),PM=x.forwardRef((e,n)=>{const{__scopePopover:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,disableOutsidePointerEvents:i,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onInteractOutside:u,...d}=e,h=Sl(ou,t),f=Uw(t);return Mw(),x.createElement(Aw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(Gf,{asChild:!0,disableOutsidePointerEvents:i,onInteractOutside:u,onEscapeKeyDown:a,onPointerDownOutside:l,onFocusOutside:c,onDismiss:()=>h.onOpenChange(!1)},x.createElement(uM,Q({"data-state":CM(h.open),role:"dialog",id:h.contentId},f,d,{ref:n,style:{...d.style,"--radix-popover-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-popover-content-available-width":"var(--radix-popper-available-width)","--radix-popover-content-available-height":"var(--radix-popper-available-height)","--radix-popover-trigger-width":"var(--radix-popper-anchor-width)","--radix-popover-trigger-height":"var(--radix-popper-anchor-height)"}}))))});function CM(e){return e?"open":"closed"}const uq=tq,dq=rq,hq=iq,pq=aq,IM=()=>{},EM=x.createContext({});function fq({onEvent:e,children:n}){return p.jsx(EM.Provider,{value:e??IM,children:n})}function yo(){return x.useContext(EM)??IM}function Gs(e,n){const t=F(),r=x.useRef(!1),o=yo(),s=x.useCallback(a=>{r.current=a,t.batch(()=>{a?(t.complete(),t.addOpenMenu(e)):t.updateInstanceState({openMenus:t.getOpenMenus().filter(l=>!l.startsWith(e))}),n==null||n(a)})},[t,e,n]),i=K("is menu open",()=>t.getOpenMenus().includes(e),[t,e]);return x.useEffect(()=>(r.current&&(o("open-menu",{source:"unknown",id:e}),t.addOpenMenu(e)),()=>{r.current&&(t.deleteOpenMenu(e),t.getOpenMenus().forEach(a=>{a.startsWith(e)&&(o("close-menu",{source:"unknown",id:e}),t.deleteOpenMenu(a))}),r.current=!1)}),[t,e,o]),[i,s]}function Hw({id:e,children:n,onOpenChange:t,open:r}){const[o,s]=Gs(e,t);return p.jsx(uq,{onOpenChange:s,open:r||o,children:p.jsx("div",{className:"tlui-popover",children:n})})}function Kw({children:e}){return p.jsx(dq,{asChild:!0,dir:"ltr",children:e})}function Vw({side:e,children:n,align:t="center",sideOffset:r=8,alignOffset:o=0}){const s=mn();return p.jsx(hq,{container:s,children:p.jsx(pq,{className:"tlui-popover__content",side:e,sideOffset:r,align:t,alignOffset:o,dir:"ltr",children:n})})}const _M=x.createContext({type:"menu",sourceId:"main-menu"});function tg(){return x.useContext(_M)}function So({type:e,sourceId:n,children:t}){return p.jsx(_M.Provider,{value:{type:e,sourceId:n},children:t})}function gq(e,n){const t=ge(n.map(o=>e.getShape(o)).filter(o=>o&&e.isShapeOfType(o,"frame")));if(!t.length)return;const r=[];e.batch(()=>{t.map(o=>{const s=e.getSortedChildIdsForParent(o.id);s.length&&(e.reparentShapes(s,o.parentId,o.index),r.push(...s))}),e.setSelectedShapes(r),e.deleteShapes(n)})}const mq=50;function yq(e,n,t={}){const r=e.getShape(n);if(!r)return;const o=e.getSortedChildIdsForParent(r.id),s=ge(o.map(f=>e.getShape(f)));if(!s.length)return;const i=ne.FromPoints(s.flatMap(f=>{const y=e.getShapeGeometry(f.id);return e.getShapeLocalTransform(f).applyToPoints(y.vertices)})),{padding:a=mq}=t,l=i.w+2*a,c=i.h+2*a,u=a-i.minX,d=a-i.minY;if(u===0&&d===0&&r.props.w===l&&r.props.h===c)return;const h=new b(u,d).rot(r.rotation);e.batch(()=>{const f=o.map(y=>{const g=e.getShape(y);return{id:g.id,type:g.type,x:g.x+u,y:g.y+d}});f.push({id:r.id,type:r.type,x:r.x-h.x,y:r.y-h.y,props:{w:l,h:c}}),e.updateShapes(f)})}function mt({children:e}){return p.jsx("span",{className:"tlui-button__label",children:e})}const kM="Dialog",[TM,Ane]=go(kM),[Sq,es]=TM(kM),vq=e=>{const{__scopeDialog:n,children:t,open:r,defaultOpen:o,onOpenChange:s,modal:i=!0}=e,a=x.useRef(null),l=x.useRef(null),[c=!1,u]=Ws({prop:r,defaultProp:o,onChange:s});return x.createElement(Sq,{scope:n,triggerRef:a,contentRef:l,contentId:Fo(),titleId:Fo(),descriptionId:Fo(),open:c,onOpenChange:u,onOpenToggle:x.useCallback(()=>u(d=>!d),[u]),modal:i},t)},$M="DialogPortal",[wq,MM]=TM($M,{forceMount:void 0}),xq=e=>{const{__scopeDialog:n,forceMount:t,children:r,container:o}=e,s=es($M,n);return x.createElement(wq,{scope:n,forceMount:t},x.Children.map(r,i=>x.createElement(mo,{present:t||s.open},x.createElement(Yf,{asChild:!0,container:o},i))))},pv="DialogOverlay",bq=x.forwardRef((e,n)=>{const t=MM(pv,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=es(pv,e.__scopeDialog);return s.modal?x.createElement(mo,{present:r||s.open},x.createElement(Pq,Q({},o,{ref:n}))):null}),Pq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=es(pv,t);return x.createElement(Bw,{as:Ei,allowPinchZoom:!0,shards:[o.contentRef]},x.createElement(Be.div,Q({"data-state":jM(o.open)},r,{ref:n,style:{pointerEvents:"auto",...r.style}})))}),su="DialogContent",Cq=x.forwardRef((e,n)=>{const t=MM(su,e.__scopeDialog),{forceMount:r=t.forceMount,...o}=e,s=es(su,e.__scopeDialog);return x.createElement(mo,{present:r||s.open},s.modal?x.createElement(Iq,Q({},o,{ref:n})):x.createElement(Eq,Q({},o,{ref:n})))}),Iq=x.forwardRef((e,n)=>{const t=es(su,e.__scopeDialog),r=x.useRef(null),o=Ye(n,t.contentRef,r);return x.useEffect(()=>{const s=r.current;if(s)return zw(s)},[]),x.createElement(AM,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:!0,onCloseAutoFocus:se(e.onCloseAutoFocus,s=>{var i;s.preventDefault(),(i=t.triggerRef.current)===null||i===void 0||i.focus()}),onPointerDownOutside:se(e.onPointerDownOutside,s=>{const i=s.detail.originalEvent,a=i.button===0&&i.ctrlKey===!0;(i.button===2||a)&&s.preventDefault()}),onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault())}))}),Eq=x.forwardRef((e,n)=>{const t=es(su,e.__scopeDialog),r=x.useRef(!1),o=x.useRef(!1);return x.createElement(AM,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,onCloseAutoFocus:s=>{var i;if((i=e.onCloseAutoFocus)===null||i===void 0||i.call(e,s),!s.defaultPrevented){var a;r.current||(a=t.triggerRef.current)===null||a===void 0||a.focus(),s.preventDefault()}r.current=!1,o.current=!1},onInteractOutside:s=>{var i,a;(i=e.onInteractOutside)===null||i===void 0||i.call(e,s),s.defaultPrevented||(r.current=!0,s.detail.originalEvent.type==="pointerdown"&&(o.current=!0));const l=s.target;((a=t.triggerRef.current)===null||a===void 0?void 0:a.contains(l))&&s.preventDefault(),s.detail.originalEvent.type==="focusin"&&o.current&&s.preventDefault()}}))}),AM=x.forwardRef((e,n)=>{const{__scopeDialog:t,trapFocus:r,onOpenAutoFocus:o,onCloseAutoFocus:s,...i}=e,a=es(su,t),l=x.useRef(null),c=Ye(n,l);return Mw(),x.createElement(x.Fragment,null,x.createElement(Aw,{asChild:!0,loop:!0,trapped:r,onMountAutoFocus:o,onUnmountAutoFocus:s},x.createElement(Gf,Q({role:"dialog",id:a.contentId,"aria-describedby":a.descriptionId,"aria-labelledby":a.titleId,"data-state":jM(a.open)},i,{ref:c,onDismiss:()=>a.onOpenChange(!1)}))),!1)}),_q="DialogTitle",kq=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=es(_q,t);return x.createElement(Be.h2,Q({id:o.titleId},r,{ref:n}))});const Tq="DialogClose",$q=x.forwardRef((e,n)=>{const{__scopeDialog:t,...r}=e,o=es(Tq,t);return x.createElement(Be.button,Q({type:"button"},r,{ref:n,onClick:se(e.onClick,()=>o.onOpenChange(!1))}))});function jM(e){return e?"open":"closed"}const Mq=vq,Aq=xq,jq=bq,Oq=Cq;function ng({className:e,children:n}){return p.jsx("div",{className:fe("tlui-dialog__header",e),children:n})}function rg({className:e,children:n}){return p.jsx(kq,{dir:"ltr",className:fe("tlui-dialog__header__title",e),children:n})}function og(){return p.jsx("div",{className:"tlui-dialog__header__close",children:p.jsx($q,{"data-testid":"dialog.close",dir:"ltr",asChild:!0,children:p.jsx(he,{type:"icon","aria-label":"Close",onTouchEnd:e=>e.target.click(),children:p.jsx(Ie,{small:!0,icon:"cross-2"})})})})}function iu({className:e,children:n,style:t}){return p.jsx("div",{className:fe("tlui-dialog__body",e),style:t,children:n})}function Ww({className:e,children:n}){return p.jsx("div",{className:fe("tlui-dialog__footer",e),children:n})}const Gw=x.forwardRef(function({className:n,label:t,icon:r,iconLeft:o,autoselect:s=!1,autofocus:i=!1,defaultValue:a,placeholder:l,onComplete:c,onValueChange:u,onCancel:d,onBlur:h,shouldManuallyMaintainScrollPositionWhenFocused:f=!1,children:y,value:g},v){const S=F(),w=x.useRef(null);x.useImperativeHandle(v,()=>w.current);const C=Ee(),I=x.useRef(a??""),P=x.useRef(a??""),[E,_]=x.useState(!1),k=x.useCallback(O=>{_(!0);const U=O.currentTarget;P.current=U.value,requestAnimationFrame(()=>{s&&U.select()})},[s]),M=x.useCallback(O=>{const U=O.currentTarget.value;P.current=U,u==null||u(U)},[u]),T=x.useCallback(O=>{switch(O.key){case"Enter":{O.currentTarget.blur(),It(O),c==null||c(O.currentTarget.value);break}case"Escape":{O.currentTarget.value=I.current,O.currentTarget.blur(),It(O),d==null||d(O.currentTarget.value);break}}},[c,d]),R=x.useCallback(O=>{_(!1);const U=O.currentTarget.value;h==null||h(U)},[h]);return x.useEffect(()=>{if(!S.environment.isIos)return;const O=window.visualViewport;if(E&&f&&O){const U=()=>{var N;(N=w.current)==null||N.scrollIntoView({block:"center"})};return O.addEventListener("resize",U),O.addEventListener("scroll",U),requestAnimationFrame(()=>{var N;(N=w.current)==null||N.scrollIntoView({block:"center"})}),()=>{O.removeEventListener("resize",U),O.removeEventListener("scroll",U)}}},[S,E,f]),p.jsxs("div",{draggable:!1,className:"tlui-input__wrapper",children:[y,t&&p.jsx("label",{children:C(t)}),o&&p.jsx(Rs,{icon:o,className:"tlui-icon-left",small:!0}),p.jsx("input",{ref:w,className:fe("tlui-input",n),type:"text",defaultValue:a,onKeyUp:T,onChange:M,onFocus:k,onBlur:R,autoFocus:i,placeholder:l,value:g}),r&&p.jsx(Rs,{icon:r,small:!!t})]})});function VC(e){return Qn.isValid(e)?{isValid:!0,hasProtocol:!0}:Qn.isValid("https://"+e)?{isValid:!0,hasProtocol:!1}:{isValid:!1,hasProtocol:!1}}const Dq=Tt(function({onClose:n}){const r=F().getOnlySelectedShape();return r&&"url"in r.props&&typeof r.props.url=="string"?p.jsx(Rq,{onClose:n,selectedShape:r}):null}),Rq=Tt(function({onClose:n,selectedShape:t}){const r=F(),o=Ee(),s=x.useRef(null);x.useEffect(()=>{requestAnimationFrame(()=>{var y;return(y=s.current)==null?void 0:y.focus()})},[]);const i=x.useRef(t.props.url),[a,l]=x.useState(()=>{const y=VC(t.props.url),g=y.isValid===!0?y.hasProtocol?t.props.url:"https://"+t.props.url:"https://";return{actual:g,safe:g,valid:!0}}),c=x.useCallback(y=>{const g=y.replace(/https?:\/\/(https?:\/\/)/,(w,C)=>C),v=VC(g),S=v.isValid===!0?v.hasProtocol?g:"https://"+g:"https://";l({actual:g,safe:S,valid:v.isValid})},[]),u=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(r.updateShapes([{id:y.id,type:y.type,props:{url:""}}]),n())},[r,n]),d=x.useCallback(()=>{const y=r.getOnlySelectedShape();y&&(y&&"url"in y.props&&y.props.url!==a.safe&&r.updateShapes([{id:y.id,type:y.type,props:{url:a.safe}}]),n())},[r,n,a]),h=x.useCallback(()=>{n()},[n]);if(!t)return n(),null;const f=i.current&&!a.valid;return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{children:[p.jsx(rg,{children:o("edit-link-dialog.title")}),p.jsx(og,{})]}),p.jsx(iu,{children:p.jsxs("div",{className:"tlui-edit-link-dialog",children:[p.jsx(Gw,{ref:s,className:"tlui-edit-link-dialog__input",label:"edit-link-dialog.url",autofocus:!0,value:a.actual,onValueChange:c,onComplete:d,onCancel:h}),p.jsx("div",{children:a.valid?o("edit-link-dialog.detail"):o("edit-link-dialog.invalid-url")})]})}),p.jsxs(Ww,{className:"tlui-dialog__footer__actions",children:[p.jsx(he,{type:"normal",onClick:h,onTouchEnd:h,children:p.jsx(mt,{children:o("edit-link-dialog.cancel")})}),f?p.jsx(he,{type:"danger",onTouchEnd:u,onClick:u,children:p.jsx(mt,{children:o("edit-link-dialog.clear")})}):p.jsx(he,{type:"primary",disabled:!a.valid,onTouchEnd:d,onClick:d,children:p.jsx(mt,{children:o("edit-link-dialog.save")})})]})]})}),OM=Tt(function({onClose:n}){const t=F(),r=Ee(),o=$w(),[s,i]=x.useState(null),[a,l]=x.useState(""),[c,u]=x.useState(null),[d,h]=x.useState(!1),f=x.useRef(-1);return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{children:[p.jsx(rg,{children:s?`${r("embed-dialog.title")} — ${s.title}`:r("embed-dialog.title")}),p.jsx(og,{})]}),s?p.jsxs(p.Fragment,{children:[p.jsxs(iu,{className:"tlui-embed-dialog__enter",children:[p.jsx(Gw,{className:"tlui-embed-dialog__input",label:"embed-url",placeholder:"http://example.com",autofocus:!0,onValueChange:y=>{l(y);const g=Ao(y);u(g&&g.definition.type===s.type?g:null),h(!1),clearTimeout(f.current),f.current=setTimeout(()=>h(!g),320)}}),a===""?p.jsxs("div",{className:"tlui-embed-dialog__instruction",children:[p.jsx("span",{children:r("embed-dialog.instruction")})," ",s.instructionLink&&p.jsxs("a",{target:"_blank",rel:"noopener noreferrer",href:s.instructionLink,className:"tlui-embed-dialog__instruction__link",children:["Learn more.",p.jsx(Rs,{icon:"external-link",small:!0})]})]}):p.jsx("div",{className:"tlui-embed-dialog__warning",children:d?r("embed-dialog.invalid-url"):" "})]}),p.jsxs(Ww,{className:"tlui-dialog__footer__actions",children:[p.jsx(he,{type:"normal",onClick:()=>{i(null),u(null),l("")},children:p.jsx(mt,{children:r("embed-dialog.back")})}),p.jsx("div",{className:"tlui-embed__spacer"}),p.jsx(he,{type:"normal",onClick:n,children:p.jsx(mt,{children:r("embed-dialog.cancel")})}),p.jsx(he,{type:"primary",disabled:!c,onClick:()=>{c&&(t.putExternalContent({type:"embed",url:a,point:t.getViewportPageCenter(),embed:c.definition}),n())},children:p.jsx(mt,{children:r("embed-dialog.create")})})]})]}):p.jsx(p.Fragment,{children:p.jsx(iu,{className:"tlui-embed-dialog__list",children:Ha.map(y=>p.jsxs(he,{type:"menu",onClick:()=>i(y),children:[p.jsx(mt,{children:y.title}),p.jsx("div",{className:"tlui-embed-dialog__item__image",style:{backgroundImage:`url(${o.embedIcons[y.type]})`}})]},y.type))})})]})});var Yw={exports:{}};Yw.exports;(function(e){var n=function(){var t=String.fromCharCode,r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-$",s={};function i(l,c){if(!s[l]){s[l]={};for(var u=0;u<l.length;u++)s[l][l.charAt(u)]=u}return s[l][c]}var a={compressToBase64:function(l){if(l==null)return"";var c=a._compress(l,6,function(u){return r.charAt(u)});switch(c.length%4){default:case 0:return c;case 1:return c+"===";case 2:return c+"==";case 3:return c+"="}},decompressFromBase64:function(l){return l==null?"":l==""?null:a._decompress(l.length,32,function(c){return i(r,l.charAt(c))})},compressToUTF16:function(l){return l==null?"":a._compress(l,15,function(c){return t(c+32)})+" "},decompressFromUTF16:function(l){return l==null?"":l==""?null:a._decompress(l.length,16384,function(c){return l.charCodeAt(c)-32})},compressToUint8Array:function(l){for(var c=a.compress(l),u=new Uint8Array(c.length*2),d=0,h=c.length;d<h;d++){var f=c.charCodeAt(d);u[d*2]=f>>>8,u[d*2+1]=f%256}return u},decompressFromUint8Array:function(l){if(l==null)return a.decompress(l);for(var c=new Array(l.length/2),u=0,d=c.length;u<d;u++)c[u]=l[u*2]*256+l[u*2+1];var h=[];return c.forEach(function(f){h.push(t(f))}),a.decompress(h.join(""))},compressToEncodedURIComponent:function(l){return l==null?"":a._compress(l,6,function(c){return o.charAt(c)})},decompressFromEncodedURIComponent:function(l){return l==null?"":l==""?null:(l=l.replace(/ /g,"+"),a._decompress(l.length,32,function(c){return i(o,l.charAt(c))}))},compress:function(l){return a._compress(l,16,function(c){return t(c)})},_compress:function(l,c,u){if(l==null)return"";var d,h,f={},y={},g="",v="",S="",w=2,C=3,I=2,P=[],E=0,_=0,k;for(k=0;k<l.length;k+=1)if(g=l.charAt(k),Object.prototype.hasOwnProperty.call(f,g)||(f[g]=C++,y[g]=!0),v=S+g,Object.prototype.hasOwnProperty.call(f,v))S=v;else{if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<I;d++)E=E<<1,_==c-1?(_=0,P.push(u(E)),E=0):_++;for(h=S.charCodeAt(0),d=0;d<8;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}else{for(h=1,d=0;d<I;d++)E=E<<1|h,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=0;for(h=S.charCodeAt(0),d=0;d<16;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}w--,w==0&&(w=Math.pow(2,I),I++),delete y[S]}else for(h=f[S],d=0;d<I;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1;w--,w==0&&(w=Math.pow(2,I),I++),f[v]=C++,S=String(g)}if(S!==""){if(Object.prototype.hasOwnProperty.call(y,S)){if(S.charCodeAt(0)<256){for(d=0;d<I;d++)E=E<<1,_==c-1?(_=0,P.push(u(E)),E=0):_++;for(h=S.charCodeAt(0),d=0;d<8;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}else{for(h=1,d=0;d<I;d++)E=E<<1|h,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=0;for(h=S.charCodeAt(0),d=0;d<16;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1}w--,w==0&&(w=Math.pow(2,I),I++),delete y[S]}else for(h=f[S],d=0;d<I;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1;w--,w==0&&(w=Math.pow(2,I),I++)}for(h=2,d=0;d<I;d++)E=E<<1|h&1,_==c-1?(_=0,P.push(u(E)),E=0):_++,h=h>>1;for(;;)if(E=E<<1,_==c-1){P.push(u(E));break}else _++;return P.join("")},decompress:function(l){return l==null?"":l==""?null:a._decompress(l.length,32768,function(c){return l.charCodeAt(c)})},_decompress:function(l,c,u){var d=[],h=4,f=4,y=3,g="",v=[],S,w,C,I,P,E,_,k={val:u(0),position:c,index:1};for(S=0;S<3;S+=1)d[S]=S;for(C=0,P=Math.pow(2,2),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;switch(C){case 0:for(C=0,P=Math.pow(2,8),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;_=t(C);break;case 1:for(C=0,P=Math.pow(2,16),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;_=t(C);break;case 2:return""}for(d[3]=_,w=_,v.push(_);;){if(k.index>l)return"";for(C=0,P=Math.pow(2,y),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;switch(_=C){case 0:for(C=0,P=Math.pow(2,8),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;d[f++]=t(C),_=f-1,h--;break;case 1:for(C=0,P=Math.pow(2,16),E=1;E!=P;)I=k.val&k.position,k.position>>=1,k.position==0&&(k.position=c,k.val=u(k.index++)),C|=(I>0?1:0)*E,E<<=1;d[f++]=t(C),_=f-1,h--;break;case 2:return v.join("")}if(h==0&&(h=Math.pow(2,y),y++),d[_])g=d[_];else if(_===f)g=w+w.charAt(0);else return null;v.push(g),d[f++]=w+g.charAt(0),h--,w=g,h==0&&(h=Math.pow(2,y),y++)}}};return a}();e!=null?e.exports=n:typeof angular<"u"&&angular!=null&&angular.module("LZString",[]).factory("LZString",function(){return n})})(Yw);var DM=Yw.exports;async function Lq(e,n,t){var S,w,C;const{elements:r,files:o}=n,s={shapes:[],rootShapeIds:[],assets:[],schema:e.store.schema.serialize()},i=new Map,a=new Map,l=e.getCurrentPageId(),c=new Map,u=[],d=new Set;r.forEach(I=>{if(c.set(I.id,We()),I.boundElements!==null)for(const P of I.boundElements)P.type==="text"&&d.add(P.id)});let h=dD;for(const I of r){if(d.has(I.id))continue;const P=c.get(I.id),E={id:P,typeName:"shape",parentId:l,index:h,x:I.x,y:I.y,rotation:0,isLocked:I.locked,opacity:Nq(I.opacity),meta:{}};switch(I.angle!==0&&a.set(P,I.angle),I.groupIds&&I.groupIds.length>0?i.has(I.groupIds[0])?(S=i.get(I.groupIds[0]))==null||S.push(P):i.set(I.groupIds[0],[P]):u.push(P),I.type){case"rectangle":case"ellipse":case"diamond":{let _="",k="middle";if(I.boundElements!==null){for(const T of I.boundElements)if(T.type==="text"){const R=r.find(O=>O.id===T.id);R&&(_=R.text,k=WC[R.textAlign])}}const M=I.backgroundColor==="transparent"?I.strokeColor:I.backgroundColor;s.shapes.push({...E,type:"geo",props:{geo:I.type,url:I.link??"",w:I.width,h:I.height,size:Yd[I.strokeWidth]??"draw",color:Kl[M]??"black",text:_,align:k,dash:Xd(I),fill:Vq(I)}});break}case"freedraw":{s.shapes.push({...E,type:"draw",props:{dash:Xd(I),size:Yd[I.strokeWidth],color:Kl[I.strokeColor]??"black",segments:[{type:"free",points:I.points.map(([_,k,M=.5])=>({x:_,y:k,z:M}))}]}});break}case"line":{const _=I.points[0],k=I.points[I.points.length-1],M=Pc(I.points.length);s.shapes.push({...E,type:"line",props:{dash:Xd(I),size:Yd[I.strokeWidth],color:Kl[I.strokeColor]??"black",spline:I.roundness?"cubic":"line",handles:{start:{id:"start",type:"vertex",index:M[0],x:_[0],y:_[1]},end:{id:"end",type:"vertex",index:M[M.length-1],x:k[0],y:k[1]},...Object.fromEntries(I.points.slice(1,-1).map(([T,R],O)=>{const U=ze();return[U,{id:U,type:"vertex",index:M[O+1],x:T,y:R}]}))}}});break}case"arrow":{let _="";if(I.boundElements!==null){for(const O of I.boundElements)if(O.type==="text"){const U=r.find(N=>N.id===O.id);U&&(_=U.text)}}const k=I.points[0],M=I.points[I.points.length-1],T=c.get((w=I.startBinding)==null?void 0:w.elementId),R=c.get((C=I.endBinding)==null?void 0:C.elementId);s.shapes.push({...E,type:"arrow",props:{text:_,bend:Kq(I,k,M),dash:Xd(I),size:Yd[I.strokeWidth]??"m",color:Kl[I.strokeColor]??"black",start:T?{type:"binding",boundShapeId:T,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:k[0],y:k[1]},end:R?{type:"binding",boundShapeId:R,normalizedAnchor:{x:.5,y:.5},isPrecise:!1,isExact:!1}:{type:"point",x:M[0],y:M[1]},arrowheadEnd:GC[I.endArrowhead]??"none",arrowheadStart:GC[I.startArrowhead]??"none"}});break}case"text":{const{size:_,scale:k}=zq(I.fontSize);s.shapes.push({...E,type:"text",props:{size:_,scale:k,font:Bq[I.fontFamily]??"draw",color:Kl[I.strokeColor]??"black",text:I.text,align:WC[I.textAlign]}});break}case"image":{const _=o[I.fileId];if(!_)break;const k=li.createId();s.assets.push({id:k,typeName:"asset",type:"image",props:{w:I.width,h:I.height,name:I.id??"Untitled",isAnimated:!1,mimeType:_.mimeType,src:_.dataURL},meta:{}}),s.shapes.push({...E,type:"image",props:{w:I.width,h:I.height,assetId:k}})}}h=ko(h)}const f=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0);e.mark("paste"),e.putContentOntoCurrentPage(s,{point:f,select:!1,preserveIds:!0});for(const I of i.values())if(I.length>1){e.groupShapes(I);const P=e.getShape(I[0]);P!=null&&P.parentId&&Hn(P.parentId)&&u.push(P.parentId)}for(const[I,P]of a)e.select(I),e.rotateShapesBy([I],P);const y=ge(u.map(I=>e.getShape(I))),g=ne.Common(y.map(I=>e.getShapePageBounds(I))),v=e.getViewportPageBounds().center;e.updateShapes(y.map(I=>{const P={x:(I.x??0)-(g.x+g.w/2),y:(I.y??0)-(g.y+g.h/2)};return{id:I.id,type:I.type,x:v.x+P.x,y:v.y+P.y}})),e.setSelectedShapes(u)}const Nq=e=>{const n=e/100;return n<.2?.1:n<.4?.25:n<.6?.5:n<.8?.75:1},Yd={1:"s",2:"m",3:"l",4:"xl"},Fq={16:"s",20:"m",28:"l",36:"xl"};function zq(e){const n=Fq[e];return n?{size:n,scale:1}:e<16?{size:"s",scale:e/16}:e>36?{size:"xl",scale:e/36}:{size:"m",scale:1}}const Bq={1:"draw",2:"sans",3:"mono"},Kl={"#ffffff":"grey","#000000":"black","#343a40":"black","#495057":"grey","#c92a2a":"red","#a61e4d":"light-red","#862e9c":"violet","#5f3dc4":"light-violet","#364fc7":"blue","#1864ab":"light-blue","#0b7285":"light-green","#087f5b":"light-green","#2b8a3e":"green","#5c940d":"light-green","#e67700":"yellow","#d9480f":"orange","#ced4da":"grey","#868e96":"grey","#fa5252":"light-red","#e64980":"red","#be4bdb":"light-violet","#7950f2":"violet","#4c6ef5":"blue","#228be6":"light-blue","#15aabf":"light-green","#12b886":"green","#40c057":"green","#82c91e":"light-green","#fab005":"yellow","#fd7e14":"orange","#212529":"grey"},Uq={solid:"draw",dashed:"dashed",dotted:"dotted"},Hq={"cross-hatch":"pattern",hachure:"pattern",solid:"solid"},WC={left:"start",center:"middle",right:"end"},GC={arrow:"arrow",dot:"dot",triangle:"triangle",bar:"pipe"};function Kq(e,n,t){let r=0;if(e.points.length>2){const o=new b(n[0],n[1]),s=new b(t[0],t[1]),i=new b(e.points[1][0],e.points[1][1]),a=b.Sub(s,o),l=b.Per(a),c=b.Med(s,o),u=b.Sub(c,l),d=b.Add(c,l),h=b.NearestPointOnLineSegment(u,d,i,!1);r=b.Dist(h,c),b.Clockwise(h,s,c)&&(r*=-1)}return r}const Xd=e=>{let n=Uq[e.strokeStyle]??"draw";return n==="draw"&&e.roughness===0&&(n="solid"),n},Vq=e=>e.backgroundColor==="transparent"?"none":Hq[e.fillStyle]??"solid";async function RM(e,n,t,r){const s=(await Promise.all(n.map(async i=>await(await fetch(i)).blob()))).map(i=>new File([i],"tldrawFile",{type:i.type}));e.mark("paste"),await e.putExternalContent({type:"files",files:s,point:t,ignoreParent:!1,sources:r}),n.forEach(i=>URL.revokeObjectURL(i))}function Wq(e,n,t){const r=t??(e.inputs.shiftKey?e.inputs.currentPagePoint:void 0),o=e.getSelectionPageBounds();e.mark("paste"),e.putContentOntoCurrentPage(n,{point:r,select:!0});const s=e.getSelectionPageBounds();o&&s&&(o!=null&&o.collides(s))&&(e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0}),setTimeout(()=>{e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},150))}async function fv(e,n,t,r){var o;try{if(new URL(n).pathname.match(/\.(png|jpe?g|gif|svg|webp)$/i)&&(o=(await fetch(n,{method:"HEAD"})).headers.get("content-type"))!=null&&o.match(/^image\//)){e.mark("paste"),RM(e,[n]);return}}catch(s){s.message!=="Failed to fetch"&&console.error(s)}return e.mark("paste"),await e.putExternalContent({type:"url",point:t,url:n,sources:r})}function Gq(e){const n=document.implementation.createHTMLDocument("");return n.documentElement.innerHTML=e.trim(),n.body.textContent||n.body.innerText||""}const Yq=e=>{try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}},Xq=e=>{const n=e.split(/[\n\s]/);for(const t of n)try{const r=new URL(t);if(!(r.protocol==="http:"||r.protocol==="https:"))return}catch{return}return HE(n)},qq=e=>/^<svg/.test(e),Zq=["input","select","textarea"];function Zh(e){const{activeElement:n}=document;return e.getIsMenuOpen()||n&&(n.getAttribute("contenteditable")||Zq.indexOf(n.tagName.toLowerCase())>-1)}async function ty(e){return new Promise((n,t)=>{const r=new FileReader;r.addEventListener("loadend",()=>{const o=r.result;n(o)}),r.addEventListener("error",()=>{t(r.error)}),r.readAsText(e)})}const Qq=e=>e.types.find(n=>n.match(/^image\//)),ny=(e,n,t,r)=>{const o=Xq(n);if(o)for(const s of o)fv(e,s,t);else Yq(n)?fv(e,n,t):qq(n)?(e.mark("paste"),e.putExternalContent({type:"svg-text",text:n,point:t,sources:r})):(e.mark("paste"),e.putExternalContent({type:"text",text:n,point:t,sources:r}))},Jq=async(e,n,t)=>{if(e.getEditingShapeId()!==null)return;if(!n)throw Error("No clipboard data");const r=[];for(const o of Object.values(n.items))switch(o.kind){case"file":{r.push({type:"file",source:new Promise(s=>s(o.getAsFile()))});break}case"string":{o.type==="text/html"?r.push({type:"html",source:new Promise(s=>o.getAsString(s))}):o.type==="text/plain"?r.push({type:"text",source:new Promise(s=>o.getAsString(s))}):r.push({type:o.type,source:new Promise(s=>o.getAsString(s))});break}}NM(e,r,t)},LM=async(e,n,t)=>{const r=[];for(const o of n){if(Qq(o))for(const s of o.types)s.match(/^image\//)&&r.push({type:"blob",source:o.getType(s)});o.types.includes("text/html")&&r.push({type:"html",source:new Promise(s=>o.getType("text/html").then(i=>ty(i).then(s)))}),o.types.includes("text/uri-list")&&r.push({type:"url",source:new Promise(s=>o.getType("text/uri-list").then(i=>ty(i).then(s)))}),o.types.includes("text/plain")&&r.push({type:"text",source:new Promise(s=>o.getType("text/plain").then(i=>ty(i).then(s)))})}return await NM(e,r,t)};async function NM(e,n,t){const r=n.filter(s=>(s.type==="file"||s.type==="blob")&&s.source!==null);if(r.length){const i=(await Promise.all(r.map(a=>a.source))).filter(Boolean).map(a=>URL.createObjectURL(a));return await RM(e,i,t)}const o=await Promise.all(n.filter(s=>s.type!=="file").map(s=>new Promise(i=>{const a=s;if(a.type==="file"){i({type:"error",data:null,reason:"unexpected file"});return}a.source.then(l=>{var u;const c=(u=l.match(/<tldraw[^>]*>(.*)<\/tldraw>/))==null?void 0:u[1];if(c)try{const d=DM.decompressFromBase64(c);if(d===null){i({type:"error",data:d,reason:"found tldraw data comment but could not parse base64"});return}else{const h=JSON.parse(d);if(h.type!=="application/tldraw"&&i({type:"error",data:h,reason:`found tldraw data comment but JSON was of a different type: ${h.type}`}),typeof h.data=="string"){i({type:"error",data:h,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}i({type:"tldraw",data:h.data});return}}catch{i({type:"error",data:c,reason:"found tldraw json but data was a string instead of a TLClipboardModel object"});return}else{if(a.type==="html"){i({type:"text",data:l,subtype:"html"});return}if(a.type==="url"){i({type:"text",data:l,subtype:"url"});return}try{const d=JSON.parse(l);if(d.type==="excalidraw/clipboard"){i({type:"excalidraw",data:d});return}else{i({type:"text",data:l,subtype:"json"});return}}catch{i({type:"text",data:l,subtype:"text"});return}}i({type:"error",data:l,reason:"unhandled case"})})})));for(const s of o)if(s.type==="tldraw"){Wq(e,s.data,t);return}for(const s of o)if(s.type==="excalidraw"){Lq(e,s.data,t);return}for(const s of o)if(s.type==="text"&&s.subtype==="html"){const a=new DOMParser().parseFromString(s.data,"text/html").querySelector("body");if(a&&Array.from(a.children).filter(c=>c.nodeType===1).length===1&&a.firstElementChild&&a.firstElementChild.tagName==="A"&&a.firstElementChild.hasAttribute("href")&&a.firstElementChild.getAttribute("href")!==""){const c=a.firstElementChild.getAttribute("href");ny(e,c,t,o);return}if(!o.some(c=>c.type==="text"&&c.subtype!=="html")&&s.data.trim()){ny(e,Gq(s.data),t,o);return}}for(const s of o)if(s.type==="text"&&s.subtype==="url"){fv(e,s.data,t,o);return}for(const s of o)if(s.type==="text"&&s.subtype==="text"&&s.data.trim()){ny(e,s.data,t,o);return}}const sf=e=>{var r;const n=e.getContentFromCurrentPage(e.getSelectedShapeIds());if(!n){navigator&&navigator.clipboard&&navigator.clipboard.writeText("");return}const t=DM.compressToBase64(JSON.stringify({type:"application/tldraw",kind:"content",data:n}));if(!(typeof navigator>"u")){const o=n.shapes.map(s=>e.isShapeOfType(s,"text")||e.isShapeOfType(s,"geo")||e.isShapeOfType(s,"arrow")?s.props.text:e.isShapeOfType(s,"bookmark")||e.isShapeOfType(s,"embed")?s.props.url:null).filter(gD);if((r=navigator.clipboard)!=null&&r.write){const s=new Blob([`<tldraw>${t}</tldraw>`],{type:"text/html"});let i=o.join(" ");i===""&&(i=" "),navigator.clipboard.write([new ClipboardItem({"text/html":s,"text/plain":new Blob([i],{type:"text/plain"})})])}else navigator.clipboard.writeText&&navigator.clipboard.writeText(`<tldraw>${t}</tldraw>`)}};function eZ(){const e=F(),n=yo(),t=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(sf(e),n("copy",{source:i}))},[e,n]),r=x.useCallback(function(i){e.getSelectedShapeIds().length!==0&&(sf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:i}))},[e,n]),o=x.useCallback(async function(i,a,l){e.getEditingShapeId()!==null||Zh(e)||(Array.isArray(i)&&i[0]instanceof ClipboardItem?(LM(e,i,l),n("paste",{source:"menu"})):navigator.clipboard.read().then(c=>{o(c,a,l)}))},[e,n]);return{copy:t,cut:r,paste:o}}function tZ(){const e=F(),n=yo(),t=K("editor.isFocused",()=>e.getInstanceState().isFocused,[e]);x.useEffect(()=>{if(!t)return;const r=()=>{e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Zh(e)||(sf(e),n("copy",{source:"kbd"}))};function o(){e.getSelectedShapeIds().length===0||e.getEditingShapeId()!==null||Zh(e)||(sf(e),e.deleteShapes(e.getSelectedShapeIds()),n("cut",{source:"kbd"}))}let s=!1;const i=l=>{l.button===1&&(s=!0,requestAnimationFrame(()=>{s=!1}))},a=l=>{if(s){l.stopPropagation();return}e.getEditingShapeId()!==null||Zh(e)||(l.clipboardData&&!e.inputs.shiftKey?Jq(e,l.clipboardData):navigator.clipboard.read().then(c=>{Array.isArray(c)&&c[0]instanceof ClipboardItem&&LM(e,c,e.inputs.currentPagePoint)}),n("paste",{source:"kbd"}))};return document.addEventListener("copy",r),document.addEventListener("cut",o),document.addEventListener("paste",a),document.addEventListener("pointerup",i),()=>{document.removeEventListener("copy",r),document.removeEventListener("cut",o),document.removeEventListener("paste",a),document.removeEventListener("pointerup",i)}},[e,n,t])}async function FM(e,n,t){const{type:r,quality:o,scale:s}=t,i=+e.getAttribute("width"),a=+e.getAttribute("height");let[l,c]=await $k(i*s,a*s);l=Math.floor(l),c=Math.floor(c);const u=l/i,d=await Xw(e),h=URL.createObjectURL(new Blob([d],{type:"image/svg+xml"})),f=await new Promise(g=>{const v=new Image;v.crossOrigin="anonymous",v.onload=async()=>{n&&await new Promise(C=>setTimeout(C,250));const S=document.createElement("canvas"),w=S.getContext("2d");S.width=l,S.height=c,w.imageSmoothingEnabled=!0,w.imageSmoothingQuality="high",w.drawImage(v,0,0,l,c),URL.revokeObjectURL(h),g(S)},v.onerror=()=>{g(null)},v.src=h});if(!f)return null;const y=await new Promise(g=>f.toBlob(v=>{(!v||Ft.throwToBlob.get())&&g(null),g(v)},"image/"+r,o));if(!y)return null;if(r==="png"){const g=new DataView(await y.arrayBuffer());return Qr.setPhysChunk(g,u,{type:"image/"+r})}else return y}async function Xw(e){const n=e.cloneNode(!0);e.setAttribute("width",+e.getAttribute("width")+""),e.setAttribute("height",+e.getAttribute("height")+"");const t=new FileReader,r=Array.from(n.querySelectorAll("image"));for(const s of r){const i=s.getAttribute("xlink:href");if(i&&!i.startsWith("data:")){const a=await(await fetch(i)).blob(),l=await new Promise((c,u)=>{t.onload=()=>c(t.result),t.onerror=()=>u(t.error),t.readAsDataURL(a)});s.setAttribute("xlink:href",l)}}return new XMLSerializer().serializeToString(n).replaceAll(" ","").replaceAll(/((\s|")[0-9]*\.[0-9]{2})([0-9]*)(\b|"|\))/g,"$1")}async function zM(e,n,t){const r=await e.getSvg(n!=null&&n.length?n:[...e.getCurrentPageShapeIds()],{scale:1,background:e.getInstanceState().exportBackground,...t});if(!r)throw new Error("Could not construct SVG.");return r}async function gv(e,n,t,r={}){switch(t){case"svg":return Xw(await zM(e,n,r));case"json":{const o=e.getContentFromCurrentPage(n);return JSON.stringify(o)}default:Ai(t)}}async function BM({editor:e,ids:n,format:t,opts:r={}}){switch(t){case"svg":return new Blob([await gv(e,n,"svg",r)],{type:"text/plain"});case"json":return new Blob([await gv(e,n,"json",r)],{type:"text/plain"});case"jpeg":case"png":case"webp":{const o=await FM(await zM(e,n,r),e.environment.isSafari,{type:t,quality:1,scale:2});if(!o)throw new Error("Could not construct image.");return o}default:Ai(t)}}const nZ={jpeg:"image/jpeg",png:"image/png",webp:"image/webp",json:"text/plain",svg:"text/plain"};function rZ(e,n,t,r={}){return{blobPromise:BM({editor:e,ids:n,format:t,opts:r}),mimeType:nZ[t]}}function oZ(e,n,t="svg",r={}){if(!window.navigator.clipboard)return Promise.reject(new Error("Copy not supported"));if(window.navigator.clipboard.write){const{blobPromise:o,mimeType:s}=rZ(e,n,t,r);return window.navigator.clipboard.write([new ClipboardItem({[s]:o})]).catch(i=>(console.error(i),o.then(a=>window.navigator.clipboard.write([new ClipboardItem({[s]:a})]))))}switch(t){case"json":case"svg":return sZ(async()=>gv(e,n,t,r));case"jpeg":case"png":throw new Error("Copy not supported");default:Ai(t)}}async function sZ(e){var n,t;await((t=(n=navigator.clipboard)==null?void 0:n.writeText)==null?void 0:t.call(n,await e()))}const UM=x.createContext({});function iZ({children:e}){const[n,t]=x.useState([]),r=x.useCallback(i=>{const a=i.id??ze();return t(l=>[...l.filter(c=>c.id!==i.id),{...i,id:a}]),a},[]),o=x.useCallback(i=>(t(a=>a.filter(l=>l.id!==i)),i),[]),s=x.useCallback(()=>{t(()=>[])},[]);return p.jsx(UM.Provider,{value:{toasts:n,addToast:r,removeToast:o,clearToasts:s},children:e})}function Wr(){const e=x.useContext(UM);if(!e)throw new Error("useToasts must be used within a ToastsProvider");return e}function aZ(){const e=F(),{addToast:n}=Wr(),t=Ee();return x.useCallback((r,o="svg")=>{oZ(e,r,o).catch(()=>{n({id:"copy-fail",icon:"warning-triangle",title:t("toast.error.copy-fail.title"),description:t("toast.error.copy-fail.desc")})})},[e,n,t])}async function lZ(e,n,t="png",r,o={}){if(!r&&(r=`shapes at ${YC()}`,n.length===1)){const a=e.getShape(n[0]);e.isShapeOfType(a,"frame")?r=a.props.name??"frame":r=`${a.id.replace(/:/,"_")} at ${YC()}`}r+=`.${t}`;const s=await BM({editor:e,ids:n,format:t,opts:o}),i=new File([s],r,{type:s.type});cZ(i)}function YC(){const e=new Date,n=String(e.getFullYear()).slice(2),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),s=String(e.getMinutes()).padStart(2,"0"),i=String(e.getSeconds()).padStart(2,"0");return`${n}-${t}-${r} ${o}.${s}.${i}`}function cZ(e){const n=document.createElement("a"),t=URL.createObjectURL(e);n.href=t,n.download=e.name,n.click(),URL.revokeObjectURL(t)}function uZ(){const e=F(),{addToast:n}=Wr(),t=Ee();return x.useCallback((r,o="png",s)=>{lZ(e,r,o,s,{scale:1,background:e.getInstanceState().exportBackground}).catch(i=>{console.error(i.message),n({id:"export-fail",title:t("toast.error.export-fail.title"),description:t("toast.error.export-fail.desc")})})},[e,n,t])}function HM(){const e=F(),n=x.useRef();return x.useEffect(()=>{const t=window.document.createElement("input");t.type="file",t.accept="image/jpeg,image/png,image/gif,image/svg+xml,video/mp4,video/quicktime",t.multiple=!0,n.current=t;async function r(o){const s=o.target.files;!s||s.length===0||(await e.putExternalContent({type:"files",files:Array.from(s),point:e.getViewportPageBounds().center,ignoreParent:!1}),t.value="")}return t.addEventListener("change",r),()=>{n.current=void 0,t.removeEventListener("change",r)}},[e]),x.useCallback(()=>{var t;(t=n.current)==null||t.click()},[n])}function dZ(){const e=F(),n=x.useRef(null),t=x.useRef(null);return x.useCallback(async function(){const o=document.createElement("div"),s=document.createElement("style"),i=(S,w)=>{S&&(S.innerHTML=""),w&&document.head.contains(w)&&document.head.removeChild(w),S&&document.body.contains(S)&&document.body.removeChild(S)};i(n.current,t.current),n.current=o,t.current=s;const a=`tl-print-surface-${ze()}`;o.className=a,s.innerHTML=`
|
|
238
238
|
.${a} {
|
|
239
239
|
display: none;
|
|
240
240
|
}
|
|
@@ -317,4 +317,4 @@ Error generating stack: `+s.message+`
|
|
|
317
317
|
<div class="${a}__item__footer ${a}__item__footer__${w?"":"hide"}">
|
|
318
318
|
${w??""}
|
|
319
319
|
</div>
|
|
320
|
-
</div>`}catch(I){console.error(I)}}function d(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const h=e.getSelectedShapeIds(),f=e.getCurrentPageId(),y=e.getPages(),v={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvg(h,v);if(S){const w=y.find(C=>C.id===f);u(`tldraw — ${w==null?void 0:w.name}`,null,S),d()}}else{const S=e.getCurrentPage(),w=await e.getSvg(e.getSortedChildIdsForParent(S.id),v);w&&(u(`tldraw — ${S.name}`,null,w),d())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const KM=x.createContext({});function hZ({children:e}){const n=F(),t=yo(),[r,o]=x.useState([]),s=x.useCallback(c=>{const u=c.id??ze();return o(d=>[...d.filter(h=>h.id!==c.id),{...c,id:u}]),t("open-menu",{source:"dialog",id:u}),n.addOpenMenu(u),u},[n,t]),i=x.useCallback((c,u)=>(o(d=>d.map(h=>h.id===c?{...h,...u}:h)),t("open-menu",{source:"dialog",id:c}),n.addOpenMenu(c),c),[n,t]),a=x.useCallback(c=>(o(u=>u.filter(d=>{var h;return d.id===c?((h=d.onClose)==null||h.call(d),!1):!0})),t("close-menu",{source:"dialog",id:c}),n.deleteOpenMenu(c),c),[n,t]),l=x.useCallback(()=>{o(c=>(c.forEach(u=>{var d;(d=u.onClose)==null||d.call(u),t("close-menu",{source:"dialog",id:u.id}),n.deleteOpenMenu(u.id)}),[]))},[n,t]);return p.jsx(KM.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function zi(){const e=x.useContext(KM);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const VM=x.createContext({});function pZ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function ca(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function fZ({overrides:e,children:n}){const t=F(),{addDialog:r,clearDialogs:o}=zi(),{clearToasts:s}=Wr(),i=Ee(),a=HM(),l=dZ(),{cut:c,copy:u,paste:d}=eZ(),h=aZ(),f=uZ(),y=i("document.default-name"),g=yo(),v=x.useMemo(()=>{function S(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function w(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const I=pZ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(P){w()&&(S()||(g("edit-link",{source:P}),t.mark("edit-link"),r({component:Dq})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(P){g("insert-embed",{source:P}),r({component:OM})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(P){g("insert-media",{source:P}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(P){g("undo",{source:P}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(P){g("redo",{source:P}),t.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(P){g("export-as",{format:"svg",source:P}),f(t.getSelectedShapeIds(),"svg",ca(t,y))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(P){g("export-as",{format:"png",source:P}),f(t.getSelectedShapeIds(),"png",ca(t,y))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(P){g("export-as",{format:"json",source:P}),f(t.getSelectedShapeIds(),"json",ca(t,y))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(P){g("export-all-as",{format:"svg",source:P}),f(Array.from(t.getCurrentPageShapeIds()),"svg",ca(t,y))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(P){g("export-all-as",{format:"png",source:P}),f(Array.from(t.getCurrentPageShapeIds()),"png",ca(t,y))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(P){g("export-all-as",{format:"json",source:P}),f(Array.from(t.getCurrentPageShapeIds()),"json",ca(t,y))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(P){g("copy-as",{format:"svg",source:P}),h(t.getSelectedShapeIds(),"svg")}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(P){g("copy-as",{format:"png",source:P}),h(t.getSelectedShapeIds(),"png")}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(P){g("copy-as",{format:"json",source:P}),h(t.getSelectedShapeIds(),"json")}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(P){w()&&(S()||(g("toggle-auto-size",{source:P}),t.mark("toggling auto size"),t.updateShapes(t.getSelectedShapes().filter(E=>t.isShapeOfType(E,"text")&&E.props.autoSize===!1).map(E=>({id:E.id,type:E.type,props:{...E.props,w:8,autoSize:!0}})))))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(P){g("open-embed-link",{source:P});const E=t.getSelectedShapeIds(),_="No embed shapes selected";if(E.length!==1){console.error(_);return}const k=t.getShape(E[0]);if(!k||!t.isShapeOfType(k,"embed")){console.error(_);return}AF(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(P){var E,_;if(((E=t.root.getCurrent())==null?void 0:E.id)!=="zoom"&&(g("zoom-tool",{source:P}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const k=t.root.getCurrent();k&&((_=k.getCurrent())==null?void 0:_.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(P){w()&&(S()||t.batch(()=>{g("convert-to-bookmark",{source:P});const E=t.getSelectedShapes(),_=[],k=[];for(const M of E){if(!M||!t.isShapeOfType(M,"embed")||!M.props.url)continue;const T=new b(M.x,M.y);T.rot(-M.rotation),T.add(new b(M.props.w/2-300/2,M.props.h/2-320/2)),T.rot(M.rotation);const R={id:We(),type:"bookmark",rotation:M.rotation,x:T.x,y:T.y,opacity:1,props:{url:M.props.url}};_.push(R),k.push(M.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(k),t.createShapes(_)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(P){w()&&(S()||(g("convert-to-embed",{source:P}),t.batch(()=>{const E=t.getSelectedShapeIds(),_=ge(E.map(T=>t.getShape(T))),k=[],M=[];for(const T of _){if(!t.isShapeOfType(T,"bookmark"))continue;const{url:R}=T.props,O=Ao(T.props.url);if(!O||!O.definition)continue;const{width:U,height:N}=O.definition,L=new b(T.x,T.y);L.rot(-T.rotation),L.add(new b(T.props.w/2-U/2,T.props.h/2-N/2)),L.rot(T.rotation);const G={id:We(),type:"embed",x:L.x,y:L.y,rotation:T.rotation,props:{url:R,w:U,h:N}};k.push(G),M.push(T.id)}t.mark("convert shapes to embed"),t.deleteShapes(M),t.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(P){if(!w()||S())return;g("duplicate-shapes",{source:P});const E=t.getInstanceState();let _,k;if(E.duplicateProps)_=E.duplicateProps.shapeIds,k=E.duplicateProps.offset;else{_=t.getSelectedShapeIds();const M=ne.Common(ge(_.map(T=>t.getShapePageBounds(T))));k=E.canMoveCamera?{x:M.width+10,y:0}:{x:16/t.getZoomLevel(),y:16/t.getZoomLevel()}}t.mark("duplicate shapes"),t.duplicateShapes(_,k),E.duplicateProps&&t.updateInstanceState({duplicateProps:{...E.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(P){w()&&(S()||(g("ungroup-shapes",{source:P}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(P){if(!w()||S())return;g("group-shapes",{source:P});const E=t.getOnlySelectedShape();E&&t.isShapeOfType(E,"group")?(t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())):(t.mark("group"),t.groupShapes(t.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(P){if(!w())return;g("remove-frame",{source:P});const E=t.getSelectedShapes();E.length>0&&E.every(_=>t.isShapeOfType(_,"frame"))&&(t.mark("remove-frame"),gq(t,E.map(_=>_.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(P){if(!w())return;g("fit-frame-to-content",{source:P});const E=t.getOnlySelectedShape();E&&t.isShapeOfType(E,"frame")&&(t.mark("fit-frame-to-content"),yq(t,E.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"left",source:P}),t.mark("align left"),t.alignShapes(t.getSelectedShapeIds(),"left")))}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"center-horizontal",source:P}),t.mark("align center horizontal"),t.alignShapes(t.getSelectedShapeIds(),"center-horizontal")))}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"right",source:P}),t.mark("align right"),t.alignShapes(t.getSelectedShapeIds(),"right")))}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"center-vertical",source:P}),t.mark("align center vertical"),t.alignShapes(t.getSelectedShapeIds(),"center-vertical")))}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"top",source:P}),t.mark("align top"),t.alignShapes(t.getSelectedShapeIds(),"top")))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"bottom",source:P}),t.mark("align bottom"),t.alignShapes(t.getSelectedShapeIds(),"bottom")))}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(P){w()&&(S()||(g("distribute-shapes",{operation:"horizontal",source:P}),t.mark("distribute horizontal"),t.distributeShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(P){w()&&(S()||(g("distribute-shapes",{operation:"vertical",source:P}),t.mark("distribute vertical"),t.distributeShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(P){w()&&(S()||(g("stretch-shapes",{operation:"horizontal",source:P}),t.mark("stretch horizontal"),t.stretchShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(P){w()&&(S()||(g("stretch-shapes",{operation:"vertical",source:P}),t.mark("stretch vertical"),t.stretchShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(P){w()&&(S()||(g("flip-shapes",{operation:"horizontal",source:P}),t.mark("flip horizontal"),t.flipShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(P){w()&&(S()||(g("flip-shapes",{operation:"vertical",source:P}),t.mark("flip vertical"),t.flipShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"pack",label:"action.pack",icon:"pack",onSelect(P){w()&&(S()||(g("pack-shapes",{source:P}),t.mark("pack"),t.packShapes(t.getSelectedShapeIds(),16)))}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(P){w()&&(S()||(g("stack-shapes",{operation:"vertical",source:P}),t.mark("stack-vertical"),t.stackShapes(t.getSelectedShapeIds(),"vertical",16)))}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(P){w()&&(S()||(g("stack-shapes",{operation:"horizontal",source:P}),t.mark("stack-horizontal"),t.stackShapes(t.getSelectedShapeIds(),"horizontal",16)))}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"toFront",source:P}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"forward",source:P}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"backward",source:P}),t.mark("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"toBack",source:P}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(P){w()&&(S()||(t.mark("cut"),c(P)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(P){w()&&(S()||u(P))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(P){var E;(E=navigator.clipboard)==null||E.read().then(_=>{d(_,P,P==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(P){t.batch(()=>{S()||(g("select-all-shapes",{source:P}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(P){w()&&(S()||(g("select-none-shapes",{source:P}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(P){w()&&(S()||(g("delete-shapes",{source:P}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(P){if(!w()||S())return;g("rotate-cw",{source:P}),t.mark("rotate-cw");const E=t.getSelectionRotation()%(Ke/2),_=ic(E,0)||ic(E,Ke/2);t.rotateShapesBy(t.getSelectedShapeIds(),Ke/2-(_?0:E))}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(P){if(!w()||S())return;g("rotate-ccw",{source:P}),t.mark("rotate-ccw");const E=t.getSelectionRotation()%(Ke/2),_=ic(E,0);t.rotateShapesBy(t.getSelectedShapeIds(),_?-(Ke/2):-E)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(P){g("zoom-in",{source:P}),t.zoomIn(t.getViewportScreenCenter(),{duration:Mo})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(P){g("zoom-out",{source:P}),t.zoomOut(t.getViewportScreenCenter(),{duration:Mo})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(P){g("reset-zoom",{source:P}),t.resetZoom(t.getViewportScreenCenter(),{duration:Mo})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(P){g("zoom-to-fit",{source:P}),t.zoomToFit({duration:Mo})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(P){w()&&(S()||(g("zoom-to-selection",{source:P}),t.zoomToSelection({duration:Mo})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(P){g("toggle-snap-mode",{source:P}),t.user.updateUserPreferences({isSnapMode:!t.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(P){g("toggle-dark-mode",{source:P}),t.user.updateUserPreferences({isDarkMode:!t.user.getIsDarkMode()})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(P){g("toggle-wrap-mode",{source:P}),t.user.updateUserPreferences({isWrapMode:!t.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(P){g("toggle-reduce-motion",{source:P}),t.user.updateUserPreferences({animationSpeed:t.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(P){g("toggle-edge-scrolling",{source:P}),t.user.updateUserPreferences({edgeScrollSpeed:t.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(P){g("toggle-transparent",{source:P}),t.updateInstanceState({exportBackground:!t.getInstanceState().exportBackground},{ephemeral:!0})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(P){g("toggle-tool-lock",{source:P}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(P){g("unlock-all",{source:P});const E=[];for(const _ of t.getCurrentPageShapes())_.isLocked&&E.push({id:_.id,type:_.type,isLocked:!1});E.length>0&&t.updateShapes(E)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(P){requestAnimationFrame(()=>{t.batch(()=>{g("toggle-focus-mode",{source:P}),o(),s(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(P){g("toggle-grid-mode",{source:P}),t.updateInstanceState({isGridMode:!t.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(P){g("toggle-debug-mode",{source:P}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(P){g("print",{source:P}),l()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(P){g("exit-pen-mode",{source:P}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(P){g("stop-following",{source:P}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(P){g("zoom-to-content",{source:P}),t.zoomToContent()}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(P){t.mark("locking"),g("toggle-lock",{source:P}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(P){const E=zo.createId(),_=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:i("page-menu.new-page-initial-name"),id:E}),t.moveShapesToPage(_,E)}),g("new-page",{source:P})}}]);return e?e(t,I,void 0):I},[t,g,e,r,a,f,h,c,u,d,o,s,l,i,y]);return p.jsx(VM.Provider,{value:v,children:n})}function le(){const e=x.useContext(VM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function au(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const gZ=x.createContext(void 0);function qw(e){const n=x.useContext(gZ);return e||n||"ltr"}const ry="rovingFocusGroup.onEntryFocus",mZ={bubbles:!1,cancelable:!0},Zw="RovingFocusGroup",[mv,WM,yZ]=Wf(Zw),[SZ,GM]=go(Zw,[yZ]),[vZ,wZ]=SZ(Zw),xZ=x.forwardRef((e,n)=>x.createElement(mv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(mv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(bZ,Q({},e,{ref:n}))))),bZ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,...u}=e,d=x.useRef(null),h=Ye(n,d),f=qw(s),[y=null,g]=Ws({prop:i,defaultProp:a,onChange:l}),[v,S]=x.useState(!1),w=on(c),C=WM(t),I=x.useRef(!1),[P,E]=x.useState(0);return x.useEffect(()=>{const _=d.current;if(_)return _.addEventListener(ry,w),()=>_.removeEventListener(ry,w)},[w]),x.createElement(vZ,{scope:t,orientation:r,dir:f,loop:o,currentTabStopId:y,onItemFocus:x.useCallback(_=>g(_),[g]),onItemShiftTab:x.useCallback(()=>S(!0),[]),onFocusableItemAdd:x.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:x.useCallback(()=>E(_=>_-1),[])},x.createElement(Be.div,Q({tabIndex:v||P===0?-1:0,"data-orientation":r},u,{ref:h,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{I.current=!0}),onFocus:se(e.onFocus,_=>{const k=!I.current;if(_.target===_.currentTarget&&k&&!v){const M=new CustomEvent(ry,mZ);if(_.currentTarget.dispatchEvent(M),!M.defaultPrevented){const T=C().filter(L=>L.focusable),R=T.find(L=>L.active),O=T.find(L=>L.id===y),N=[R,O,...T].filter(Boolean).map(L=>L.ref.current);YM(N)}}I.current=!1}),onBlur:se(e.onBlur,()=>S(!1))})))}),PZ="RovingFocusGroupItem",CZ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Fo(),l=s||a,c=wZ(PZ,t),u=c.currentTabStopId===l,d=WM(t),{onFocusableItemAdd:h,onFocusableItemRemove:f}=c;return x.useEffect(()=>{if(r)return h(),()=>f()},[r,h,f]),x.createElement(mv.ItemSlot,{scope:t,id:l,focusable:r,active:o},x.createElement(Be.span,Q({tabIndex:u?0:-1,"data-orientation":c.orientation},i,{ref:n,onMouseDown:se(e.onMouseDown,y=>{r?c.onItemFocus(l):y.preventDefault()}),onFocus:se(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){c.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=_Z(y,c.orientation,c.dir);if(g!==void 0){y.preventDefault();let S=d().filter(w=>w.focusable).map(w=>w.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const w=S.indexOf(y.currentTarget);S=c.loop?kZ(S,w+1):S.slice(w+1)}setTimeout(()=>YM(S))}})})))}),IZ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function EZ(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function _Z(e,n,t){const r=EZ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return IZ[r]}function YM(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function kZ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const TZ=xZ,$Z=CZ,yv=["Enter"," "],MZ=["ArrowDown","PageUp","Home"],XM=["ArrowUp","PageDown","End"],AZ=[...MZ,...XM],jZ={ltr:[...yv,"ArrowRight"],rtl:[...yv,"ArrowLeft"]},OZ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},sg="Menu",[lu,DZ,RZ]=Wf(sg),[Bi,ig]=go(sg,[RZ,Jf,GM]),ag=Jf(),qM=GM(),[ZM,Ys]=Bi(sg),[LZ,Nu]=Bi(sg),NZ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ag(n),[l,c]=x.useState(null),u=x.useRef(!1),d=on(s),h=qw(o);return x.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),x.createElement(Fw,a,x.createElement(ZM,{scope:n,open:t,onOpenChange:d,content:l,onContentChange:c},x.createElement(LZ,{scope:n,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:h,modal:i},r)))},QM=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=ag(t);return x.createElement(cM,Q({},o,r,{ref:n}))}),JM="MenuPortal",[FZ,eA]=Bi(JM,{forceMount:void 0}),zZ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=Ys(JM,n);return x.createElement(FZ,{scope:n,forceMount:t},x.createElement(mo,{present:t||s.open},x.createElement(Yf,{asChild:!0,container:o},r)))},zr="MenuContent",[BZ,Qw]=Bi(zr),UZ=x.forwardRef((e,n)=>{const t=eA(zr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=Ys(zr,e.__scopeMenu),i=Nu(zr,e.__scopeMenu);return x.createElement(lu.Provider,{scope:e.__scopeMenu},x.createElement(mo,{present:r||s.open},x.createElement(lu.Slot,{scope:e.__scopeMenu},i.modal?x.createElement(HZ,Q({},o,{ref:n})):x.createElement(KZ,Q({},o,{ref:n})))))}),HZ=x.forwardRef((e,n)=>{const t=Ys(zr,e.__scopeMenu),r=x.useRef(null),o=Ye(n,r);return x.useEffect(()=>{const s=r.current;if(s)return zw(s)},[]),x.createElement(Jw,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)}))}),KZ=x.forwardRef((e,n)=>{const t=Ys(zr,e.__scopeMenu);return x.createElement(Jw,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),Jw=x.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:f,disableOutsideScroll:y,...g}=e,v=Ys(zr,t),S=Nu(zr,t),w=ag(t),C=qM(t),I=DZ(t),[P,E]=x.useState(null),_=x.useRef(null),k=Ye(n,_,v.onContentChange),M=x.useRef(0),T=x.useRef(""),R=x.useRef(0),O=x.useRef(null),U=x.useRef("right"),N=x.useRef(0),L=y?Bw:x.Fragment,G=y?{as:Ei,allowPinchZoom:!0}:void 0,X=B=>{var W,Y;const J=T.current+B,ke=I().filter(Ue=>!Ue.disabled),ve=document.activeElement,pe=(W=ke.find(Ue=>Ue.ref.current===ve))===null||W===void 0?void 0:W.textValue,me=ke.map(Ue=>Ue.textValue),Xe=oQ(me,J,pe),Ae=(Y=ke.find(Ue=>Ue.textValue===Xe))===null||Y===void 0?void 0:Y.ref.current;(function Ue(yt){T.current=yt,window.clearTimeout(M.current),yt!==""&&(M.current=window.setTimeout(()=>Ue(""),1e3))})(J),Ae&&setTimeout(()=>Ae.focus())};x.useEffect(()=>()=>window.clearTimeout(M.current),[]),Mw();const H=x.useCallback(B=>{var W,Y;return U.current===((W=O.current)===null||W===void 0?void 0:W.side)&&iQ(B,(Y=O.current)===null||Y===void 0?void 0:Y.area)},[]);return x.createElement(BZ,{scope:t,searchRef:T,onItemEnter:x.useCallback(B=>{H(B)&&B.preventDefault()},[H]),onItemLeave:x.useCallback(B=>{var W;H(B)||((W=_.current)===null||W===void 0||W.focus(),E(null))},[H]),onTriggerLeave:x.useCallback(B=>{H(B)&&B.preventDefault()},[H]),pointerGraceTimerRef:R,onPointerGraceIntentChange:x.useCallback(B=>{O.current=B},[])},x.createElement(L,G,x.createElement(Aw,{asChild:!0,trapped:o,onMountAutoFocus:se(s,B=>{var W;B.preventDefault(),(W=_.current)===null||W===void 0||W.focus()}),onUnmountAutoFocus:i},x.createElement(Gf,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:f},x.createElement(TZ,Q({asChild:!0},C,{dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:P,onCurrentTabStopIdChange:E,onEntryFocus:se(l,B=>{S.isUsingKeyboardRef.current||B.preventDefault()})}),x.createElement(uM,Q({role:"menu","aria-orientation":"vertical","data-state":sA(v.open),"data-radix-menu-content":"",dir:S.dir},w,g,{ref:k,style:{outline:"none",...g.style},onKeyDown:se(g.onKeyDown,B=>{const Y=B.target.closest("[data-radix-menu-content]")===B.currentTarget,J=B.ctrlKey||B.altKey||B.metaKey,ke=B.key.length===1;Y&&(B.key==="Tab"&&B.preventDefault(),!J&&ke&&X(B.key));const ve=_.current;if(B.target!==ve||!AZ.includes(B.key))return;B.preventDefault();const me=I().filter(Xe=>!Xe.disabled).map(Xe=>Xe.ref.current);XM.includes(B.key)&&me.reverse(),nQ(me)}),onBlur:se(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(M.current),T.current="")}),onPointerMove:se(e.onPointerMove,cu(B=>{const W=B.target,Y=N.current!==B.clientX;if(B.currentTarget.contains(W)&&Y){const J=B.clientX>N.current?"right":"left";U.current=J,N.current=B.clientX}}))})))))))}),VZ=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return x.createElement(Be.div,Q({role:"group"},r,{ref:n}))}),Sv="MenuItem",XC="menu.itemSelect",tA=x.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=x.useRef(null),i=Nu(Sv,e.__scopeMenu),a=Qw(Sv,e.__scopeMenu),l=Ye(n,s),c=x.useRef(!1),u=()=>{const d=s.current;if(!t&&d){const h=new CustomEvent(XC,{bubbles:!0,cancelable:!0});d.addEventListener(XC,f=>r==null?void 0:r(f),{once:!0}),kw(d,h),h.defaultPrevented?c.current=!1:i.onClose()}};return x.createElement(nA,Q({},o,{ref:l,disabled:t,onClick:se(e.onClick,u),onPointerDown:d=>{var h;(h=e.onPointerDown)===null||h===void 0||h.call(e,d),c.current=!0},onPointerUp:se(e.onPointerUp,d=>{var h;c.current||(h=d.currentTarget)===null||h===void 0||h.click()}),onKeyDown:se(e.onKeyDown,d=>{const h=a.searchRef.current!=="";t||h&&d.key===" "||yv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),nA=x.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=Qw(Sv,t),a=qM(t),l=x.useRef(null),c=Ye(n,l),[u,d]=x.useState(!1),[h,f]=x.useState("");return x.useEffect(()=>{const y=l.current;if(y){var g;f(((g=y.textContent)!==null&&g!==void 0?g:"").trim())}},[s.children]),x.createElement(lu.ItemSlot,{scope:t,disabled:r,textValue:o??h},x.createElement($Z,Q({asChild:!0},a,{focusable:!r}),x.createElement(Be.div,Q({role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:c,onPointerMove:se(e.onPointerMove,cu(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus())})),onPointerLeave:se(e.onPointerLeave,cu(y=>i.onItemLeave(y))),onFocus:se(e.onFocus,()=>d(!0)),onBlur:se(e.onBlur,()=>d(!1))}))))}),WZ=x.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return x.createElement(XZ,{scope:e.__scopeMenu,checked:t},x.createElement(tA,Q({role:"menuitemcheckbox","aria-checked":vv(t)?"mixed":t},o,{ref:n,"data-state":tQ(t),onSelect:se(o.onSelect,()=>r==null?void 0:r(vv(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),GZ="MenuRadioGroup";Bi(GZ,{value:void 0,onValueChange:()=>{}});const YZ="MenuItemIndicator",[XZ,jne]=Bi(YZ,{checked:!1}),rA="MenuSub",[qZ,oA]=Bi(rA),ZZ=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=Ys(rA,n),i=ag(n),[a,l]=x.useState(null),[c,u]=x.useState(null),d=on(o);return x.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),x.createElement(Fw,i,x.createElement(ZM,{scope:n,open:r,onOpenChange:d,content:c,onContentChange:u},x.createElement(qZ,{scope:n,contentId:Fo(),triggerId:Fo(),trigger:a,onTriggerChange:l},t)))},qd="MenuSubTrigger",QZ=x.forwardRef((e,n)=>{const t=Ys(qd,e.__scopeMenu),r=Nu(qd,e.__scopeMenu),o=oA(qd,e.__scopeMenu),s=Qw(qd,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),x.createElement(QM,Q({asChild:!0},c),x.createElement(nA,Q({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":sA(t.open)},e,{ref:Vf(n,o.onTriggerChange),onClick:d=>{var h;(h=e.onClick)===null||h===void 0||h.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:se(e.onPointerMove,cu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:se(e.onPointerLeave,cu(d=>{var h;u();const f=(h=t.content)===null||h===void 0?void 0:h.getBoundingClientRect();if(f){var y;const g=(y=t.content)===null||y===void 0?void 0:y.dataset.side,v=g==="right",S=v?-5:5,w=f[v?"left":"right"],C=f[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+S,y:d.clientY},{x:w,y:f.top},{x:C,y:f.top},{x:C,y:f.bottom},{x:w,y:f.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:se(e.onKeyDown,d=>{const h=s.searchRef.current!=="";if(!(e.disabled||h&&d.key===" ")&&jZ[r.dir].includes(d.key)){var f;t.onOpenChange(!0),(f=t.content)===null||f===void 0||f.focus(),d.preventDefault()}})})))}),JZ="MenuSubContent",eQ=x.forwardRef((e,n)=>{const t=eA(zr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=Ys(zr,e.__scopeMenu),i=Nu(zr,e.__scopeMenu),a=oA(JZ,e.__scopeMenu),l=x.useRef(null),c=Ye(n,l);return x.createElement(lu.Provider,{scope:e.__scopeMenu},x.createElement(mo,{present:r||s.open},x.createElement(lu.Slot,{scope:e.__scopeMenu},x.createElement(Jw,Q({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;i.isUsingKeyboardRef.current&&((d=l.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:se(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:se(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:se(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),h=OZ[i.dir].includes(u.key);if(d&&h){var f;s.onOpenChange(!1),(f=a.trigger)===null||f===void 0||f.focus(),u.preventDefault()}})})))))});function sA(e){return e?"open":"closed"}function vv(e){return e==="indeterminate"}function tQ(e){return vv(e)?"indeterminate":e?"checked":"unchecked"}function nQ(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function rQ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function oQ(e,n,t){const o=n.length>1&&Array.from(n).every(c=>c===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=rQ(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==t));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==t?l:void 0}function sQ(e,n){const{x:t,y:r}=e;let o=!1;for(let s=0,i=n.length-1;s<n.length;i=s++){const a=n[s].x,l=n[s].y,c=n[i].x,u=n[i].y;l>r!=u>r&&t<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function iQ(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return sQ(t,n)}function cu(e){return n=>n.pointerType==="mouse"?e(n):void 0}const iA=NZ,aA=QM,lA=zZ,cA=UZ,uA=VZ,dA=tA,hA=WZ,pA=ZZ,fA=QZ,gA=eQ,mA="ContextMenu",[aQ,One]=go(mA,[ig]),vo=ig(),[lQ,yA]=aQ(mA),cQ=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=x.useState(!1),l=vo(n),c=on(r),u=x.useCallback(d=>{a(d),c(d)},[c]);return x.createElement(lQ,{scope:n,open:i,onOpenChange:u,modal:s},x.createElement(iA,Q({},l,{dir:o,open:i,onOpenChange:u,modal:s}),t))},uQ="ContextMenuTrigger",dQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=yA(uQ,t),i=vo(t),a=x.useRef({x:0,y:0}),l=x.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=x.useRef(0),u=x.useCallback(()=>window.clearTimeout(c.current),[]),d=h=>{a.current={x:h.clientX,y:h.clientY},s.onOpenChange(!0)};return x.useEffect(()=>u,[u]),x.useEffect(()=>void(r&&u()),[r,u]),x.createElement(x.Fragment,null,x.createElement(aA,Q({},i,{virtualRef:l})),x.createElement(Be.span,Q({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:se(e.onContextMenu,h=>{u(),d(h),h.preventDefault()}),onPointerDown:r?e.onPointerDown:se(e.onPointerDown,Zd(h=>{u(),c.current=window.setTimeout(()=>d(h),700)})),onPointerMove:r?e.onPointerMove:se(e.onPointerMove,Zd(u)),onPointerCancel:r?e.onPointerCancel:se(e.onPointerCancel,Zd(u)),onPointerUp:r?e.onPointerUp:se(e.onPointerUp,Zd(u))})))}),SA=e=>{const{__scopeContextMenu:n,...t}=e,r=vo(n);return x.createElement(lA,Q({},r,t))},hQ="ContextMenuContent",pQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=yA(hQ,t),s=vo(t),i=x.useRef(!1);return x.createElement(cA,Q({},s,r,{ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),fQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(uA,Q({},o,r,{ref:n}))}),gQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(dA,Q({},o,r,{ref:n}))}),mQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(hA,Q({},o,r,{ref:n}))}),yQ=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=vo(n),[a,l]=Ws({prop:o,defaultProp:s,onChange:r});return x.createElement(pA,Q({},i,{open:a,onOpenChange:l}),t)},SQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(fA,Q({},o,r,{ref:n}))}),vQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(gA,Q({},o,r,{ref:n,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))});function Zd(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const wQ=cQ,xQ=dQ,bQ=SA,PQ=pQ,CQ=mQ,vA=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,IQ=vA?"⌘":"Ctrl",EQ=vA?"⌥":"Alt";function wA(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,IQ).replace(/\?/g,EQ).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function uu(e){return"— "+wA(e).join(" ")}function _Q(e){return p.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:p.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[p.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),p.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:p.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const xA="DropdownMenu",[kQ,Dne]=go(xA,[ig]),wo=ig(),[TQ,bA]=kQ(xA),$Q=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=wo(n),c=x.useRef(null),[u=!1,d]=Ws({prop:o,defaultProp:s,onChange:i});return x.createElement(TQ,{scope:n,triggerId:Fo(),triggerRef:c,contentId:Fo(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(h=>!h),[d]),modal:a},x.createElement(iA,Q({},l,{open:u,onOpenChange:d,dir:r,modal:a}),t))},MQ="DropdownMenuTrigger",AQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=bA(MQ,t),i=wo(t);return x.createElement(aA,Q({asChild:!0},i),x.createElement(Be.button,Q({type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r},o,{ref:Vf(n,s.triggerRef),onPointerDown:se(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:se(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),jQ=e=>{const{__scopeDropdownMenu:n,...t}=e,r=wo(n);return x.createElement(lA,Q({},r,t))},OQ="DropdownMenuContent",DQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=bA(OQ,t),s=wo(t),i=x.useRef(!1);return x.createElement(cA,Q({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:n,onCloseAutoFocus:se(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)===null||l===void 0||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),RQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(uA,Q({},o,r,{ref:n}))}),LQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(dA,Q({},o,r,{ref:n}))}),NQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(hA,Q({},o,r,{ref:n}))}),FQ=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=wo(n),[a=!1,l]=Ws({prop:r,defaultProp:s,onChange:o});return x.createElement(pA,Q({},i,{open:a,onOpenChange:l}),t)},zQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(fA,Q({},o,r,{ref:n}))}),BQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(gA,Q({},o,r,{ref:n,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),ex=$Q,tx=AQ,lg=jQ,nx=DQ,UQ=RQ,HQ=LQ,KQ=NQ,VQ=FQ,WQ=zQ,GQ=BQ;function Ti({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=Gs(e);return p.jsx(ex,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function $i({children:e,...n}){return p.jsx(tx,{dir:"ltr",asChild:!0,onTouchEnd:t=>je(t),...n,children:e})}function Mi({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=mn();return p.jsx(lg,{container:s,children:p.jsx(nx,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function YQ({id:e,children:n}){const[t,r]=Gs(e);return p.jsx(VQ,{open:t,onOpenChange:r,children:n})}function XQ({id:e,label:n,title:t,disabled:r}){return p.jsx(WQ,{dir:"ltr",asChild:!0,disabled:r,children:p.jsxs(he,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[p.jsx(mt,{children:n}),p.jsx(Ie,{icon:"chevron-right",small:!0})]})})}function qQ({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=mn();return p.jsx(lg,{container:s,children:p.jsx(GQ,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function ZQ({children:e}){return p.jsx(UQ,{dir:"ltr",className:"tlui-menu__group",children:e})}function du({noClose:e,children:n}){return p.jsx(HQ,{dir:"ltr",asChild:!0,onClick:e?je:void 0,children:n})}function wc({children:e,visibleOnMobileLayout:n=!1}){const t=Ln();return!n&&t<ht.MOBILE?null:p.jsx("kbd",{className:"tlui-kbd",children:wA(e).map((r,o)=>p.jsx("span",{children:r},o))})}function z({disabled:e=!1,spinner:n=!1,readonlyOk:t=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:l}){const{type:c,sourceId:u}=tg(),d=Ee(),[h,f]=x.useState(!1);if(fo()&&!t)return null;const g=au(s,c),v=o?uu(o):void 0,S=g?d(g):void 0,w=S&&v?`${S} ${v}`:S;switch(c){case"menu":return p.jsx(du,{children:p.jsxs(he,{type:"menu","data-testid":`${u}.${r}`,disabled:e,title:w,onClick:C=>{l&&je(C),h?f(!1):a(u)},children:[p.jsx(mt,{children:S}),o&&p.jsx(wc,{children:o})]})});case"context-menu":return e?null:p.jsxs(gQ,{dir:"ltr",title:w,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${u}.${r}`,onSelect:C=>{l&&je(C),h?f(!1):a(u)},children:[p.jsx("span",{className:"tlui-button__label",draggable:!1,children:S}),o&&p.jsx(wc,{children:o}),n&&p.jsx(_Q,{})]});case"panel":return p.jsxs(he,{"data-testid":`${u}.${r}`,type:"menu",title:w,disabled:e,onClick:()=>a(u),children:[p.jsx(mt,{children:S}),i&&p.jsx(Ie,{icon:i})]});case"small-icons":case"icons":return p.jsx(he,{"data-testid":`${u}.${r}`,type:"icon",title:w,disabled:e,onClick:()=>a(u),children:p.jsx(Ie,{icon:i,small:c==="small-icons"})});case"keyboard-shortcuts":return o?p.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${u}.${r}`,children:[p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:S}),p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:p.jsx(wc,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return p.jsxs(he,{type:"low",onClick:()=>a(u),children:[p.jsx(Ie,{icon:i}),p.jsx(mt,{children:S})]});default:return null}}function QQ(){return p.jsxs(p.Fragment,{children:[p.jsx(JQ,{}),p.jsx(eJ,{}),p.jsx(tJ,{}),p.jsx(nJ,{}),p.jsx(rJ,{}),p.jsx(iJ,{}),p.jsx(aJ,{}),p.jsx(lJ,{})]})}function JQ(){const e=le(),n=an(2);return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["align-left"],disabled:!n}),p.jsx(z,{...e["align-center-horizontal"],disabled:!n}),p.jsx(z,{...e["align-right"],disabled:!n}),p.jsx(z,{...e["stretch-horizontal"],disabled:!n}),p.jsx(z,{...e["align-top"],disabled:!n}),p.jsx(z,{...e["align-center-vertical"],disabled:!n}),p.jsx(z,{...e["align-bottom"],disabled:!n}),p.jsx(z,{...e["stretch-vertical"],disabled:!n})]})}function eJ(){const e=le(),n=an(3);return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["distribute-horizontal"],disabled:!n}),p.jsx(z,{...e["distribute-vertical"],disabled:!n})]})}function tJ(){const e=le(),n=bk();return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["stack-horizontal"],disabled:!n}),p.jsx(z,{...e["stack-vertical"],disabled:!n})]})}function nJ(){const e=le(),n=an(1);return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["send-to-back"],disabled:!n}),p.jsx(z,{...e["send-backward"],disabled:!n}),p.jsx(z,{...e["bring-forward"],disabled:!n}),p.jsx(z,{...e["bring-to-front"],disabled:!n})]})}function rJ(){return Ln()<ht.TABLET_SM?p.jsx(oJ,{}):p.jsx(sJ,{})}function oJ(){const e=le(),n=F(),t=K("zoom is 1",()=>n.getZoomLevel()===1,[n]);return p.jsx(z,{...e["zoom-to-100"],disabled:t})}function sJ(){const e=le(),n=an(1);return p.jsx(z,{...e["rotate-ccw"],disabled:!n})}function iJ(){const e=le(),n=an(1);return p.jsx(z,{...e["rotate-cw"],disabled:!n})}function aJ(){const e=le(),n=Ik();return p.jsx(z,{...e["edit-link"],disabled:!n})}function lJ(){const e=Pk(),n=Ck();return e?p.jsx(qC,{}):n?p.jsx(cJ,{}):p.jsx(qC,{})}function qC(){const e=le(),n=an(2);return p.jsx(z,{...e.group,disabled:!n})}function cJ(){const e=le();return p.jsx(z,{...e.ungroup})}const uJ=x.memo(function({children:n}){const t=Ee(),r=Ln(),o=fo(),s=F(),i=K("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??p.jsx(QQ,{});if(!(o&&!i))return p.jsxs(Hw,{id:"actions-menu",children:[p.jsx(Kw,{children:p.jsx(he,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:p.jsx(Ie,{icon:"dots-vertical",small:!0})})}),p.jsx(Vw,{side:r>=ht.TABLET?"bottom":"top",sideOffset:6,children:p.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:p.jsx(So,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function wr({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,disabled:s=!1,checked:i=!1}){const{type:a,sourceId:l}=tg(),c=fo(),u=Ee();if(c&&!r)return null;const d=au(t,a),h=d?u(d):void 0;switch(a){case"menu":return p.jsxs(KQ,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:h,onSelect:f=>{o==null||o(l),je(f)},disabled:s,checked:i,children:[p.jsx(Rs,{small:!0,icon:i?"check":"checkbox-empty"}),h&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:h}),n&&p.jsx(wc,{children:n})]});case"context-menu":return p.jsxs(CQ,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:h,onSelect:f=>{o(l),je(f)},disabled:s,checked:i,children:[p.jsx(Rs,{small:!0,icon:i?"check":"checkbox-empty"}),h&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:h}),n&&p.jsx(wc,{children:n})]},e);default:return null}}function we({id:e,label:n,children:t}){const{type:r,sourceId:o}=tg(),s=Ee(),i=au(n,r),a=i?s(i):void 0;switch(r){case"panel":return p.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return p.jsx(ZQ,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return p.jsx(fQ,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return p.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[p.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),p.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function xr({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=tg(),a=mn(),l=Ee(),c=t?typeof t=="string"?t:t[s]??t.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return p.jsxs(YQ,{id:`${i}-sub.${e}`,children:[p.jsx(XQ,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:n,label:u,title:u}),p.jsx(qQ,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:p.jsxs(dJ,{id:`${i}-sub.${e}`,children:[p.jsx(SQ,{dir:"ltr",disabled:n,asChild:!0,children:p.jsxs(he,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[p.jsx(mt,{children:u}),p.jsx(Ie,{icon:"chevron-right",small:!0})]})}),p.jsx(SA,{container:a,children:p.jsx(vQ,{"data-testid":`${i}-sub-content.${e}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function dJ({id:e,children:n}){const[t,r]=Gs(e);return p.jsx(yQ,{open:t,onOpenChange:r,children:n})}function PA(){const e=le(),n=EU();return p.jsx(z,{...e["toggle-auto-size"],disabled:!n})}function CA(){const e=le(),n=Ik();return p.jsx(z,{...e["edit-link"],disabled:!n})}function hJ(){const e=le(),n=an(1);return p.jsx(z,{...e.duplicate,disabled:!n})}function IA(){const e=le(),n=Pk();return p.jsx(z,{...e.group,disabled:!n})}function EA(){const e=le(),n=Ck();return p.jsx(z,{...e.ungroup,disabled:!n})}function _A(){const e=F(),n=le(),t=K("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e]);return p.jsx(z,{...n["remove-frame"],disabled:!t})}function kA(){const e=F(),n=le(),t=K("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e]);return p.jsx(z,{...n["fit-frame-to-content"],disabled:!t})}function TA(){const e=F(),n=le(),t=K("selected shapes",()=>e.getSelectedShapes().length>0,[e]);return p.jsx(z,{...n["toggle-lock"],disabled:!t})}function $A(){const e=le(),n=F(),t=K("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return p.jsx(wr,{...e["toggle-transparent"],checked:t})}function pJ(){const e=F(),n=le(),t=K("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return p.jsx(z,{...n["unlock-all"],disabled:!t})}function MA(){const e=F(),n=K("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=le();return p.jsx(z,{...t["zoom-to-100"],noClose:!0,disabled:n})}function AA(){const e=F(),n=K("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=le();return p.jsx(z,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function jA(){const e=F(),n=K("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=le();return p.jsx(z,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function OA(){var r;const e=F(),n=le(),t=K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[]);return p.jsxs(we,{id:"clipboard",children:[p.jsx(fJ,{}),p.jsx(gJ,{}),p.jsxs(xr,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[p.jsxs(we,{id:"copy-as-group",children:[p.jsx(z,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&p.jsx(z,{...n["copy-as-png"]}),p.jsx(z,{...n["copy-as-json"]})]}),p.jsx(we,{id:"copy-as-bg",children:p.jsx($A,{})})]}),p.jsx(hJ,{}),p.jsx(mJ,{}),p.jsx(yJ,{})]})}function fJ(){const e=le(),n=an(1);return p.jsx(z,{...e.cut,disabled:!n})}function gJ(){const e=le(),n=IU(1);return p.jsx(z,{...e.copy,disabled:!n})}function mJ(){const e=le(),n=CU;return p.jsx(z,{...e.paste,disabled:!n})}function DA(){const e=le(),n=an(1);return p.jsx(we,{id:"conversions",children:p.jsxs(xr,{id:"export-as",label:"context-menu.export-as",size:"small",disabled:!n,children:[p.jsxs(we,{id:"export-as-group",children:[p.jsx(z,{...e["export-as-svg"]}),p.jsx(z,{...e["export-as-png"]}),p.jsx(z,{...e["export-as-json"]})]}),p.jsx(we,{id:"export-as-bg",children:p.jsx($A,{})})]})})}function RA(){const e=le(),n=F(),t=K("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(we,{id:"set-selection-group",children:p.jsx(z,{...e["select-all"],disabled:!t})})}function yJ(){const e=le(),n=an(1);return p.jsx(z,{...e.delete,disabled:!n})}function SJ(){const e=an(2),n=_U(),t=le();return e||n?p.jsxs(xr,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&p.jsxs(we,{id:"align",children:[p.jsx(z,{...t["align-left"]}),p.jsx(z,{...t["align-center-horizontal"]}),p.jsx(z,{...t["align-right"]}),p.jsx(z,{...t["align-top"]}),p.jsx(z,{...t["align-center-vertical"]}),p.jsx(z,{...t["align-bottom"]})]}),p.jsx(vJ,{}),e&&p.jsxs(we,{id:"stretch",children:[p.jsx(z,{...t["stretch-horizontal"]}),p.jsx(z,{...t["stretch-vertical"]})]}),n&&p.jsxs(we,{id:"flip",children:[p.jsx(z,{...t["flip-horizontal"]}),p.jsx(z,{...t["flip-vertical"]})]}),p.jsx(wJ,{})]}):null}function vJ(){const e=le();return an(3)?p.jsxs(we,{id:"distribute",children:[p.jsx(z,{...e["distribute-horizontal"]}),p.jsx(z,{...e["distribute-vertical"]})]}):null}function wJ(){const e=le(),n=an(2),t=bk();return n?p.jsxs(we,{id:"order",children:[p.jsx(z,{...e.pack}),t&&p.jsx(z,{...e["stack-horizontal"]}),t&&p.jsx(z,{...e["stack-vertical"]})]}):null}function xJ(){const e=le();return an(1)?p.jsx(xr,{id:"reorder",label:"context-menu.reorder",size:"small",children:p.jsxs(we,{id:"reorder",children:[p.jsx(z,{...e["bring-to-front"]}),p.jsx(z,{...e["bring-forward"]}),p.jsx(z,{...e["send-backward"]}),p.jsx(z,{...e["send-to-back"]})]})}):null}function bJ(){const e=F(),n=K("pages",()=>e.getPages(),[e]),t=K("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Wr(),o=le(),s=yo();return an(1)?p.jsxs(xr,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[p.jsx(we,{id:"pages",children:n.map(a=>p.jsx(z,{id:a.id,disabled:t===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const l=e.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})},title:a.name},a.id))}),p.jsx(we,{id:"new-page",children:p.jsx(z,{...o["new-page"]})})]}):null}function LA(){const e=F(),n=le(),t=K("oneEmbedSelected",()=>{const o=e.getOnlySelectedShape();return o?!!(e.isShapeOfType(o,"embed")&&o.props.url&&!e.isShapeOrAncestorLocked(o)):!1},[e]),r=K("oneEmbeddableBookmarkSelected",()=>{const o=e.getOnlySelectedShape();return o?!!(e.isShapeOfType(o,"bookmark")&&o.props.url&&Ao(o.props.url)&&!e.isShapeOrAncestorLocked(o)):!1},[e]);return p.jsxs(we,{id:"embeds",children:[p.jsx(z,{...n["convert-to-bookmark"],disabled:!t}),p.jsx(z,{...n["convert-to-embed"],disabled:!r})]})}function PJ(){const e=le(),n=F(),t=K("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return p.jsx(wr,{...e["toggle-snap-mode"],checked:t})}function CJ(){const e=le(),n=F(),t=K("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return p.jsx(wr,{...e["toggle-tool-lock"],checked:t})}function IJ(){const e=le(),n=F(),t=K("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return p.jsx(wr,{...e["toggle-grid"],checked:t})}function EJ(){const e=le(),n=F(),t=K("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return p.jsx(wr,{...e["toggle-wrap-mode"],checked:t})}function _J(){const e=le(),n=F(),t=K("isDarkMode",()=>n.user.getIsDarkMode(),[n]);return p.jsx(wr,{...e["toggle-dark-mode"],checked:t})}function kJ(){const e=le(),n=F(),t=K("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return p.jsx(wr,{...e["toggle-focus-mode"],checked:t})}function TJ(){const e=le(),n=F(),t=K("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return p.jsx(wr,{...e["toggle-edge-scrolling"],checked:t===1})}function $J(){const e=le(),n=F(),t=K("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return p.jsx(wr,{...e["toggle-reduce-motion"],checked:t===0})}function MJ(){const e=le(),n=F(),t=K("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return p.jsx(wr,{...e["toggle-debug-mode"],checked:t})}function AJ(){const e=F();return K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?p.jsxs(p.Fragment,{children:[p.jsxs(we,{id:"selection",children:[p.jsx(PA,{}),p.jsx(CA,{}),p.jsx(IA,{}),p.jsx(EA,{}),p.jsx(_A,{}),p.jsx(kA,{}),p.jsx(TA,{})]}),p.jsx(LA,{}),p.jsxs(we,{id:"modify",children:[p.jsx(SJ,{}),p.jsx(xJ,{}),p.jsx(bJ,{})]}),p.jsx(OA,{}),p.jsx(DA,{}),p.jsx(RA,{})]}):null}const jJ=x.memo(function({children:n}){const t=F(),{Canvas:r}=Ge(),o=x.useCallback(c=>{if(c){if(t.getInstanceState().isCoarsePointer){const u=t.getSelectedShapes(),{inputs:{currentPagePoint:d}}=t,h=t.getShapesAtPoint(d);if(!t.getSelectedShapes().length||!h.some(f=>u.includes(f))){const f=h.filter(y=>t.isShapeOrAncestorLocked(y));f.length&&t.select(...f.map(y=>y.id))}}}else{const u=t.getOnlySelectedShape();u&&t.isShapeOrAncestorLocked(u)&&t.setSelectedShapes([])}},[t]),s=mn(),[i,a]=Gs("context menu",o),l=n??p.jsx(AJ,{});return p.jsxs(wQ,{dir:"ltr",onOpenChange:a,modal:!1,children:[p.jsx(xQ,{onContextMenu:void 0,dir:"ltr",children:r?p.jsx(r,{}):null}),i&&p.jsx(bQ,{container:s,children:p.jsx(PQ,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:je,children:p.jsx(So,{type:"context-menu",sourceId:"context-menu",children:l})})})]})});function wv({checked:e}){return p.jsx(Rs,{icon:e?"check":"checkbox-empty",className:"tlui-button__icon",small:!0})}function OJ(){const e=F(),{addToast:n}=Wr(),{addDialog:t}=zi(),[r,o]=ie.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(we,{id:"items",children:[p.jsx(z,{id:"add-toast",onSelect:()=>{n({id:ze(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0}),n({id:ze(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),n({id:ze(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,icon:"twitter",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]})},label:"Show toast"}),p.jsx(z,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>p.jsx(LJ,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),p.jsx(z,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>NJ(e,100)}),p.jsx(z,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{function s({children:u}){let d=0;if(!u.length)return 0;for(const h of[...u])d++,d+=s(h);return d}const i=e.getSelectedShapes(),a=i.length===0?e.getRenderingShapes():i,l=a.map(u=>document.getElementById(u.id).parentElement);let c=l.length;for(const u of l)c+=s(u);window.alert(`Shapes ${a.length}, DOM nodes:${c}`)}}),(()=>{if(r)throw Error("oh no!")})(),p.jsx(z,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),p.jsx(z,{id:"hard-reset",onSelect:qE,label:"Hard reset"})]}),p.jsxs(we,{id:"flags",children:[p.jsx(DJ,{}),p.jsx(RJ,{})]})]})}function DJ(){const e=Object.values(Ft);return e.length?p.jsx(xr,{id:"debug flags",label:"Debug Flags",children:p.jsx(we,{id:"debug flags",children:e.map(n=>p.jsx(NA,{flag:n},n.name))})}):null}function RJ(){const e=Object.values(XR);return e.length?p.jsx(xr,{id:"feature flags",label:"Feature Flags",children:p.jsx(we,{id:"feature flags",children:e.map(n=>p.jsx(NA,{flag:n},n.name))})}):null}function LJ({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=ie.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{children:[p.jsx(rg,{children:e}),p.jsx(og,{})]}),p.jsx(iu,{style:{maxWidth:350},children:n}),p.jsxs(Ww,{className:"tlui-dialog__footer__actions",children:[o&&p.jsxs(he,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[p.jsx(wv,{checked:a}),p.jsx(mt,{children:"Don't show again"})]}),p.jsx(he,{type:"normal",onClick:s,children:p.jsx(mt,{children:t})}),p.jsx(he,{type:"primary",onClick:async()=>i(),children:p.jsx(mt,{children:r})})]})]})}const NA=Tt(function({flag:n,onChange:t}){const r=n.get();return p.jsx(wr,{id:n.name,title:n.name,label:n.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{n.set(!r),t==null||t(!r)}})});let ZC=0;function NJ(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)ZC++,t[o]={id:We("box"+ZC),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function FJ({children:e}){const n=e??p.jsx(OJ,{});return p.jsxs(Ti,{id:"debug",children:[p.jsx($i,{children:p.jsx(he,{type:"icon",title:"Debug menu",children:p.jsx(Ie,{icon:"dots-horizontal"})})}),p.jsx(Mi,{side:"top",align:"end",alignOffset:0,children:p.jsx(So,{type:"menu",sourceId:"debug-panel",children:n})})]})}function zJ(){const e=F();return{languages:_c,currentLanguage:e.user.getLocale()}}const FA=Tt(function(){const n=F(),t=yo(),{languages:r,currentLanguage:o}=zJ();return p.jsx(xr,{id:"help menu language",label:"menu.language",children:p.jsx(we,{id:"languages",children:r.map(({locale:s,label:i})=>p.jsx(wr,{id:`language-${s}`,title:s,label:i,checked:s===o,onSelect:()=>{n.user.updateUserPreferences({locale:s}),t("change-language",{source:"menu",locale:s})}},s))})})});function BJ(){return p.jsxs(p.Fragment,{children:[p.jsx(FA,{}),p.jsx(UJ,{})]})}function UJ(){const{KeyboardShortcutsDialog:e}=Xs(),{addDialog:n}=zi();return e?p.jsx(z,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const HJ=x.memo(function({children:n}){const t=Ee(),r=Ln(),o=n??p.jsx(BJ,{});return r<ht.MOBILE?null:p.jsx("div",{className:"tlui-help-menu",children:p.jsxs(Ti,{id:"help menu",children:[p.jsx($i,{children:p.jsx(he,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:p.jsx(Ie,{icon:"question-mark",small:!0})})}),p.jsx(Mi,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:p.jsx(So,{type:"menu",sourceId:"help-menu",children:o})})]})})});function KJ(){const e=F(),n=le(),[t,r]=x.useState(!1);return x.useEffect(()=>{let o=!1;const s=setInterval(()=>{const i=e.getRenderingShapes(),a=e.getRenderingBounds(),c=i.filter(u=>u.maskedPageBounds&&a.includes(u.maskedPageBounds)).length===0&&e.getCurrentPageShapes().length>0;o!==c&&(r(c),o=c)},1e3);return()=>{clearInterval(s)}},[e]),t?p.jsx(z,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function VJ(){const e=F(),n=le();return K("is pen mode",()=>e.getInstanceState().isPenMode,[e])?p.jsx(z,{...n["exit-pen-mode"]}):null}function WJ(){const e=F(),n=le();return K("is following user",()=>!!e.getInstanceState().followingUserId,[e])?p.jsx(z,{...n["stop-following"]}):null}function GJ(){return p.jsxs(p.Fragment,{children:[p.jsx(VJ,{}),p.jsx(KJ,{}),p.jsx(WJ,{})]})}function YJ({children:e}){const n=e??p.jsx(GJ,{});return p.jsx("div",{className:"tlui-helper-buttons",children:p.jsx(So,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}const zA=x.createContext({});function XJ({overrides:e,children:n}){const t=F(),r=yo(),{addDialog:o}=zi(),s=HM(),i=x.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){t.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){t.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){t.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){t.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...so.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){t.batch(()=>{t.updateInstanceState({stylesForNextShape:{...t.getInstanceState().stylesForNextShape,[so.id]:c}},{ephemeral:!0}),t.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){t.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){t.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){t.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){t.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){t.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){t.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"tool-embed",onSelect(c){o({component:OM}),r("select-tool",{source:c,id:"embed"})}}];a.push({id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){t.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}});const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(t,l,{insertMedia:s}):l},[e,t,r,s,o]);return p.jsx(zA.Provider,{value:i,children:n})}function rx(){const e=x.useContext(zA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function qJ(){const e=le(),n=rx();return p.jsxs(p.Fragment,{children:[p.jsxs(we,{label:"shortcuts-dialog.tools",id:"tools",children:[p.jsx(z,{...e["toggle-tool-lock"]}),p.jsx(z,{...n.select}),p.jsx(z,{...n.draw}),p.jsx(z,{...n.eraser}),p.jsx(z,{...n.hand}),p.jsx(z,{...n.rectangle}),p.jsx(z,{...n.ellipse}),p.jsx(z,{...n.arrow}),p.jsx(z,{...n.line}),p.jsx(z,{...n.text}),p.jsx(z,{...n.frame}),p.jsx(z,{...n.note}),p.jsx(z,{...n.laser})]}),p.jsxs(we,{label:"shortcuts-dialog.file",id:"file",children:[p.jsx(z,{...e["insert-media"]}),p.jsx(z,{...e.print})]}),p.jsxs(we,{label:"shortcuts-dialog.preferences",id:"preferences",children:[p.jsx(z,{...e["toggle-dark-mode"]}),p.jsx(z,{...e["toggle-focus-mode"]}),p.jsx(z,{...e["toggle-grid"]})]}),p.jsxs(we,{label:"shortcuts-dialog.edit",id:"edit",children:[p.jsx(z,{...e.undo}),p.jsx(z,{...e.redo}),p.jsx(z,{...e.cut}),p.jsx(z,{...e.copy}),p.jsx(z,{...e.paste}),p.jsx(z,{...e["select-all"]}),p.jsx(z,{...e.delete}),p.jsx(z,{...e.duplicate})]}),p.jsxs(we,{label:"shortcuts-dialog.view",id:"view",children:[p.jsx(z,{...e["zoom-in"]}),p.jsx(z,{...e["zoom-out"]}),p.jsx(z,{...e["zoom-to-100"]}),p.jsx(z,{...e["zoom-to-fit"]}),p.jsx(z,{...e["zoom-to-selection"]})]}),p.jsxs(we,{label:"shortcuts-dialog.transform",id:"transform",children:[p.jsx(z,{...e["bring-to-front"]}),p.jsx(z,{...e["bring-forward"]}),p.jsx(z,{...e["send-backward"]}),p.jsx(z,{...e["send-to-back"]}),p.jsx(z,{...e.group}),p.jsx(z,{...e.ungroup}),p.jsx(z,{...e["flip-horizontal"]}),p.jsx(z,{...e["flip-vertical"]}),p.jsx(z,{...e["align-top"]}),p.jsx(z,{...e["align-center-vertical"]}),p.jsx(z,{...e["align-bottom"]}),p.jsx(z,{...e["align-left"]}),p.jsx(z,{...e["align-center-horizontal"]}),p.jsx(z,{...e["align-right"]})]})]})}const ZJ=x.memo(function({children:n}){const t=Ee(),r=Ln(),o=n??p.jsx(qJ,{});return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{className:"tlui-shortcuts-dialog__header",children:[p.jsx(rg,{children:t("shortcuts-dialog.title")}),p.jsx(og,{})]}),p.jsx(iu,{className:fe("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=ht.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=ht.TABLET}),children:p.jsx(So,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),p.jsx("div",{className:"tlui-dialog__scrim"})]})});function QJ(){return p.jsxs(p.Fragment,{children:[p.jsx(JJ,{}),p.jsx(eee,{}),p.jsx(see,{}),p.jsx(iee,{}),p.jsx(aee,{})]})}function JJ(){const e=F(),n=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return p.jsxs(xr,{id:"edit",label:"menu.edit",disabled:!n,children:[p.jsx(oee,{}),p.jsx(OA,{}),p.jsx(RA,{})]})}function eee(){const e=F(),n=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return p.jsxs(xr,{id:"shape",label:"menu.shape",disabled:!n,children:[p.jsx(DA,{}),p.jsx(ree,{}),p.jsx(tee,{}),p.jsx(LA,{}),p.jsx(nee,{})]})}function tee(){return p.jsxs(we,{id:"misc",children:[p.jsx(PA,{}),p.jsx(CA,{})]})}function nee(){return p.jsxs(we,{id:"lock",children:[p.jsx(TA,{}),p.jsx(pJ,{})]})}function ree(){return p.jsxs(we,{id:"multi-shape",children:[p.jsx(IA,{}),p.jsx(EA,{}),p.jsx(_A,{}),p.jsx(kA,{})]})}function oee(){const e=le(),n=_k(),t=Ek();return p.jsxs(we,{id:"undo-redo",children:[p.jsx(z,{...e.undo,disabled:!n}),p.jsx(z,{...e.redo,disabled:!t})]})}function see(){const e=le();return p.jsx(xr,{id:"view",label:"menu.view",children:p.jsxs(we,{id:"view-actions",children:[p.jsx(z,{...e["zoom-in"]}),p.jsx(z,{...e["zoom-out"]}),p.jsx(MA,{}),p.jsx(AA,{}),p.jsx(jA,{})]})})}function iee(){const e=le();return p.jsxs(we,{id:"extras",children:[p.jsx(z,{...e["insert-embed"]}),p.jsx(z,{...e["insert-media"]})]})}function aee(){return p.jsx(we,{id:"preferences",children:p.jsxs(xr,{id:"preferences",label:"menu.preferences",children:[p.jsxs(we,{id:"preferences-actions",children:[p.jsx(PJ,{}),p.jsx(CJ,{}),p.jsx(IJ,{}),p.jsx(EJ,{}),p.jsx(_J,{}),p.jsx(kJ,{}),p.jsx(TJ,{}),p.jsx($J,{}),p.jsx(MJ,{})]}),p.jsx(we,{id:"language",children:p.jsx(FA,{})})]})})}const lee=x.memo(function({children:n}){const t=mn(),[r,o]=Gs("main menu"),s=Ee(),i=n??p.jsx(QJ,{});return p.jsxs(ex,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[p.jsx(tx,{asChild:!0,dir:"ltr",children:p.jsx(he,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:p.jsx(Ie,{icon:"menu",small:!0})})}),p.jsx(lg,{container:t,children:p.jsx(nx,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:p.jsx(So,{type:"menu",sourceId:"main-menu",children:i})})})]})}),cee=x.memo(function(){const n=Ln(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=Xs();return!t&&!s&&n<6?null:p.jsx("div",{className:"tlui-menu-zone",children:p.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&p.jsx(t,{}),s&&p.jsx(s,{}),n<6?null:p.jsxs(p.Fragment,{children:[r&&p.jsx(r,{}),o&&p.jsx(o,{})]})]})})});class xc{constructor(n){m(this,"dpr",1);m(this,"colors",{shapeFill:"rgba(144, 144, 144, .1)",selectFill:"#2f80ed",viewportFill:"rgba(144, 144, 144, .1)"});m(this,"id",ze());m(this,"cvs",null);m(this,"pageBounds",[]);m(this,"collaborators",[]);m(this,"canvasScreenBounds",new ne);m(this,"canvasPageBounds",new ne);m(this,"contentPageBounds",new ne);m(this,"contentScreenBounds",new ne);m(this,"originPagePoint",new b);m(this,"originPageCenter",new b);m(this,"isInViewport",!1);m(this,"debug",!1);m(this,"updateContentScreenBounds",()=>{const{contentScreenBounds:n,contentPageBounds:t,canvasScreenBounds:r}=this;let{x:o,y:s,w:i,h:a}=n;if(t.w>t.h){const l=r.w/(t.w/t.h);l>r.h?(o=(r.w-r.w*(r.h/l))/2,s=0,i=r.w*(r.h/l),a=r.h):(o=0,s=(r.h-l)/2,i=r.w,a=l)}else if(t.w<t.h){const l=r.h/(t.h/t.w);o=(r.w-l)/2,s=0,i=l,a=r.h}else o=r.h/2,s=0,i=r.h,a=r.h;n.set(o,s,i,a)});m(this,"updateCanvasPageBounds",()=>{const{canvasPageBounds:n,canvasScreenBounds:t,contentPageBounds:r,contentScreenBounds:o}=this;n.set(0,0,r.width/(o.width/t.width),r.height/(o.height/t.height)),n.center=r.center});m(this,"getScreenPoint",(n,t)=>{const{canvasScreenBounds:r}=this,o=(n-r.minX)*this.dpr,s=(t-r.minY)*this.dpr;return{x:o,y:s}});m(this,"getPagePoint",(n,t)=>{const{contentPageBounds:r,contentScreenBounds:o,canvasPageBounds:s}=this,{x:i,y:a}=this.getScreenPoint(n,t);return new b(s.minX+i*r.width/o.width,s.minY+a*r.height/o.height,1)});m(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getPagePoint(n,t);if(o){const c=this.editor.getCurrentPageBounds(),u=i,d=((c==null?void 0:c.minX)??0)-u.width/2,h=((c==null?void 0:c.maxX)??0)+u.width/2,f=((c==null?void 0:c.minY)??0)-u.height/2,y=((c==null?void 0:c.maxY)??0)+u.height/2,g=Math.max(0,d+u.width-a),v=Math.max(0,-(h-u.width-a)),S=Math.max(0,f+u.height-l),w=Math.max(0,-(y-u.height-l)),C=Math.max(0,g-v),I=Math.max(0,v-g),P=Math.max(0,S-w),E=Math.max(0,w-S);C&&C>I?a+=C/2:I&&(a-=I/2),P&&P>E?l+=P/2:E&&(l-=E/2),a=ar(a,d,h),l=ar(l,f,y)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),d=Math.abs(l-c.y);u>d?l=c.y:a=c.x}return new b(a,l)});m(this,"updateColors",()=>{const n=getComputedStyle(this.editor.getContainer());this.colors={shapeFill:n.getPropertyValue("--color-text-3").trim(),selectFill:n.getPropertyValue("--color-selected").trim(),viewportFill:n.getPropertyValue("--color-muted-1").trim()}});m(this,"render",()=>{const{cvs:n,pageBounds:t}=this;this.updateCanvasPageBounds();const{editor:r,canvasScreenBounds:o,canvasPageBounds:s,contentPageBounds:i,contentScreenBounds:a}=this,{width:l,height:c}=o,u=r.getSelectedShapeIds(),d=r.getViewportPageBounds();if(!n||!t)return;const h=n.getContext("2d");if(!h)throw new Error("Minimap (shapes): Could not get context");h.resetTransform(),h.globalAlpha=1,h.clearRect(0,0,l,c);const f=a.width/i.width,y=a.height/i.height;h.translate((l-a.width)/2,(c-a.height)/2),h.scale(f,y),h.translate(-i.minX,-i.minY);const g=8/f,v=8/f,S=1/f,w=1/f,C=g/4,I=v/4,P=new Path2D,E=new Path2D,{shapeFill:_,selectFill:k,viewportFill:M}=this.colors;let T;for(let L=0,G=t.length;L<G;L++)T=t[L],xc.roundedRect(u.includes(T.id)?E:P,T.minX,T.minY,T.width,T.height,ar(g,S,T.width/C),ar(v,w,T.height/I));if(h.fillStyle=_,h.fill(P),h.fillStyle=k,h.fill(E),this.debug){const L=ne.Common(t),{minX:G,minY:X,width:H,height:B}=L;h.strokeStyle="green",h.lineWidth=2/f,h.strokeRect(G+1/f,X+1/y,H-2/f,B-2/y)}{const{brush:L}=r.getInstanceState();if(L){const{x:G,y:X,w:H,h:B}=L;h.beginPath(),xc.sharpRect(h,G,X,H,B),h.closePath(),h.fillStyle=M,h.fill()}}{const{minX:L,minY:G,width:X,height:H}=d;h.beginPath();const B=12/f,W=12/f;xc.roundedRect(h,L,G,X,H,Math.min(X/4,B),Math.min(H/4,W)),h.closePath(),h.fillStyle=M,h.fill(),this.debug&&(h.strokeStyle="orange",h.strokeRect(L+1/f,G+1/y,X-2/f,H-2/y))}const R=2.5/f,O=2.5/y,U=r.getCurrentPageId();let N;for(let L=0;L<this.collaborators.length;L++)N=this.collaborators[L],N.currentPageId===U&&(h.beginPath(),h.ellipse(ar(N.cursor.x,s.minX+R,s.maxX-R),ar(N.cursor.y,s.minY+O,s.maxY-O),5/f,5/y,0,0,De),h.fillStyle=N.color,h.fill());if(this.debug){h.lineWidth=2/f;{const{minX:L,minY:G,width:X,height:H}=i;h.strokeStyle="red",h.strokeRect(L+1/f,G+1/y,X-2/f,H-2/y)}{const{minX:L,minY:G,width:X,height:H}=s;h.strokeStyle="blue",h.strokeRect(L+1/f,G+1/y,X-2/f,H-2/y)}}});this.editor=n}setDpr(n){this.dpr=+n.toFixed(2)}static roundedRect(n,t,r,o,s,i,a){if(i<1&&a<1){n.rect(t,r,o,s);return}n.moveTo(t+i,r),n.lineTo(t+o-i,r),n.quadraticCurveTo(t+o,r,t+o,r+a),n.lineTo(t+o,r+s-a),n.quadraticCurveTo(t+o,r+s,t+o-i,r+s),n.lineTo(t+i,r+s),n.quadraticCurveTo(t,r+s,t,r+s-a),n.lineTo(t,r+a),n.quadraticCurveTo(t,r,t+i,r)}static sharpRect(n,t,r,o,s,i,a){n.rect(t,r,o,s)}}function uee(){const e=F(),n=x.useRef(null),t=x.useRef(!1),r=Sf(),o=EI("dpr",()=>e.getInstanceState().devicePixelRatio,[e]),s=x.useMemo(()=>e.store.query.records("instance_presence"),[e]),i=x.useMemo(()=>new xc(e),[e]);x.useEffect(()=>{const d=requestAnimationFrame(()=>{i.updateColors(),i.render()});return()=>{cancelAnimationFrame(d)}},[e,i,r]);const a=x.useCallback(d=>{if(!e.getCurrentPageShapeIds().size)return;const h=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),f=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);i.originPagePoint.setTo(f),i.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(h,{duration:Mo})},[e,i]),l=x.useCallback(d=>{const h=d.currentTarget;if(Su(h,d),!e.getCurrentPageShapeIds().size)return;t.current=!0,i.isInViewport=!1;const f=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),y=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0),g=e.getViewportPageBounds();if(i.isInViewport=g.containsPoint(y),i.isInViewport)i.originPagePoint.setTo(y),i.originPageCenter.setTo(g.center);else{const S=b.Sub(g.center,g.point),w=b.Add(f,S);i.originPagePoint.setTo(w),i.originPageCenter.setTo(f),e.centerOnPoint(f,{duration:Mo})}function v(S){h&&vu(h,S),t.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[e,i]),c=x.useCallback(d=>{const h=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,d.shiftKey,!0);if(t.current){if(i.isInViewport){const v=i.originPagePoint.clone().sub(i.originPageCenter);e.centerOnPoint(b.Sub(h,v));return}e.centerOnPoint(h)}const f=i.getPagePoint(d.clientX,d.clientY),y=e.pageToScreen(f),g={type:"pointer",target:"canvas",name:"pointer_move",...In(d),point:y,isPen:e.getInstanceState().isPenMode};e.dispatch(g)},[e,i]),u=x.useCallback(d=>{const h=RE(d);e.dispatch({type:"wheel",name:"wheel",delta:h,point:new b(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey})},[e]);return fi("update when dpr changes",()=>{const d=o.get();i.setDpr(d);const h=n.current,f=h.getBoundingClientRect(),y=f.width*d,g=f.height*d;h.width=y,h.height=g,i.canvasScreenBounds.set(f.x,f.y,y,g),i.cvs=n.current},[o,i]),fi("minimap render when pagebounds or collaborators changes",()=>{const d=e.getCurrentPageShapeIds(),h=e.getCurrentPageBounds(),f=e.getViewportPageBounds();o.get(),i.contentPageBounds=h?ne.Expand(h,f):f,i.updateContentScreenBounds();const y=[];d.forEach(g=>{let v=e.getShapePageBounds(g);if(!v)return;const S=e.getShapeMask(g);if(S){const w=Hy(S,v.corners);if(!w)return;v=ne.FromPoints(w)}v&&(v.id=g,y.push(v))}),i.pageBounds=y,i.collaborators=s.get(),i.render()},[e,i]),p.jsx("div",{className:"tlui-minimap",children:p.jsx("canvas",{role:"img","aria-label":"minimap",ref:n,className:"tlui-minimap__canvas",onDoubleClick:a,onPointerMove:c,onPointerDown:l,onWheel:u})})}function dee(e,n){const[t,r]=ie.useState(n);ie.useLayoutEffect(()=>{const s=localStorage.getItem(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=ie.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return localStorage.setItem(e,JSON.stringify(a)),a})},[e]);return[t,o]}const hee=x.memo(function(){const n=le(),t=Ee(),r=Ln(),[o,s]=dee("minimap",!0),i=x.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=Xs();return r<ht.MOBILE?null:p.jsxs("div",{className:"tlui-navigation-panel",children:[p.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<ht.TABLET?p.jsx(a,{}):o?p.jsxs(p.Fragment,{children:[a&&p.jsx(a,{}),l&&p.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:p.jsx(Ie,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):p.jsxs(p.Fragment,{children:[p.jsx(he,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(au(n["zoom-out"].label))} ${uu(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:p.jsx(Ie,{icon:"minus"})}),a&&p.jsx(a,{}),p.jsx(he,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(au(n["zoom-in"].label))} ${uu(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:p.jsx(Ie,{icon:"plus"})}),l&&p.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:p.jsx(Ie,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=ht.TABLET&&!o&&p.jsx(l,{})]})}),pee=function({name:n,id:t,isCurrentPage:r}){const o=F(),s=x.useRef(null),i=x.useCallback(l=>{o.renamePage(t,l||"New Page",{ephemeral:!0})},[o,t]),a=x.useCallback(l=>{o.mark("rename page"),o.renamePage(t,l||"New Page",{ephemeral:!1})},[o,t]);return p.jsx(Gw,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:n,onValueChange:i,onComplete:a,onCancel:a,shouldManuallyMaintainScrollPositionWhenFocused:!0,autofocus:r,autoselect:!0})},xv=(e,n,t,r)=>{let o;const s=e.getPages(),i=t>r?s[r-1]:s[r],a=t>r?s[r]:s[r+1];i&&!a?o=ko(i.index):!i&&a?o=pD(s[0].index):o=oc(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},QC=Tt(function({index:n,listSize:t,item:r,onRename:o}){const s=F(),i=Ee(),a=s.getPages(),l=x.useCallback(()=>{s.mark("creating page");const h=zo.createId();s.duplicatePage(r.id,h)},[s,r]),c=x.useCallback(()=>{xv(s,r.id,n,n-1)},[s,r,n]),u=x.useCallback(()=>{xv(s,r.id,n,n+1)},[s,r,n]),d=x.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return p.jsxs(Ti,{id:`page item submenu ${n}`,children:[p.jsx($i,{children:p.jsx(he,{type:"icon",title:i("page-menu.submenu.title"),children:p.jsx(Ie,{icon:"dots-vertical"})})}),p.jsx(Mi,{alignOffset:0,side:"right",sideOffset:-4,children:p.jsxs(So,{type:"menu",sourceId:"page-menu",children:[p.jsxs(we,{id:"modify",children:[o&&p.jsx(z,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),p.jsx(z,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:a.length>=fp}),n>0&&p.jsx(z,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),n<t-1&&p.jsx(z,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),t>1&&p.jsx(we,{id:"delete",children:p.jsx(z,{id:"delete",onSelect:d,label:"page-menu.submenu.delete"})})]})})]})}),fee=x.memo(function(){const n=F(),t=Ee(),r=Ln(),o=x.useCallback(()=>v(!1),[]),[s,i]=Gs("page-menu",o),a=36,l=x.useRef(null),c=K("pages",()=>n.getPages(),[n]),u=K("currentPage",()=>n.getCurrentPage(),[n]),d=K("currentPageId",()=>n.getCurrentPageId(),[n]),h=fo(),f=K("maxPageCountReached",()=>n.getPages().length>=fp,[n]),y=K("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[g,v]=x.useState(!1),S=x.useCallback(()=>{h||v(T=>!T)},[h]),w=x.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[C,I]=x.useState(Object.fromEntries(c.map((T,R)=>[T.id,{y:R*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{I(Object.fromEntries(c.map((T,R)=>[T.id,{y:R*a,offsetY:0,isSelected:!1}])))},[a,c]),x.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const R=l.current;if(!R)return;const O=T.offsetTop,U=R.scrollTop;O<U&&R.scrollTo({top:O});const N=O+a,L=R.scrollTop+R.offsetHeight;N>L&&R.scrollTo({top:N-R.offsetHeight})}})},[a,d,s]);const P=x.useCallback(T=>{const{clientY:R,currentTarget:O}=T,{dataset:{id:U,index:N}}=O;if(!U||!N)return;const L=w.current;Su(T.currentTarget,T),L.status="pointing",L.pointing={id:U,index:+N};const X=C[U].y;L.startY=R,L.startIndex=Math.max(0,Math.min(Math.round(X/a),c.length-1))},[a,c.length,C]),E=x.useCallback(T=>{const R=w.current;if(R.status==="pointing"){const{clientY:O}=T,U=O-R.startY;Math.abs(U)>5&&(R.status="dragging")}if(R.status==="dragging"){const{clientY:O}=T,U=O-R.startY,N=C[R.pointing.id],{startIndex:L,pointing:G}=R,X=N.y+U,H=Math.max(0,Math.min(Math.round(X/a),c.length-1)),B={...C};if(B[G.id]={y:N.y,offsetY:U,isSelected:!0},H!==R.dragIndex){R.dragIndex=H;for(let W=0;W<c.length;W++){const Y=c[W];if(Y.id===R.pointing.id)continue;let{y:J}=B[Y.id];H===L?J=W*a:H<L?H<=W&&W<L?J=(W+1)*a:J=W*a:H>L&&(H>=W&&W>L?J=(W-1)*a:J=W*a),J!==B[Y.id].y&&(B[Y.id]={y:J,offsetY:0,isSelected:!0})}}I(B)}},[a,c,C]),_=x.useCallback(T=>{const R=w.current;if(R.status==="dragging"){const{id:O,index:U}=R.pointing;xv(n,O,U,R.dragIndex)}vu(T.currentTarget,T),R.status="idle"},[n]),k=x.useCallback(T=>{const R=w.current;T.key==="Escape"&&(R.status==="dragging"&&I(Object.fromEntries(c.map((O,U)=>[O.id,{y:U*a,offsetY:0,isSelected:!1}]))),R.status="idle")},[a,c]),M=x.useCallback(()=>{h||n.batch(()=>{n.mark("creating page");const T=zo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),v(!0)})},[n,t,h]);return p.jsxs(Hw,{id:"pages",onOpenChange:i,open:s,children:[p.jsx(Kw,{"data-testid":"main.page-menu",children:p.jsxs(he,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[p.jsx("div",{className:"tlui-page-menu__name",children:u.name}),p.jsx(Ie,{icon:"chevron-down",small:!0})]})}),p.jsx(Vw,{side:"bottom",align:"start",sideOffset:6,children:p.jsxs("div",{className:"tlui-page-menu__wrapper",children:[p.jsxs("div",{className:"tlui-page-menu__header",children:[p.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!h&&p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsx(he,{type:"icon","data-testid":"page-menu.edit",title:t(g?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:p.jsx(Ie,{icon:g?"check":"edit"})}),p.jsx(he,{type:"icon","data-testid":"page-menu.create",title:t(f?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:f,onClick:M,children:p.jsx(Ie,{icon:"plus"})})]})]}),p.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*c.length+4},ref:l,children:c.map((T,R)=>{const O=C[T.id]??{position:R*40,offsetY:0};return g?p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===u.id?888:R,transform:`translate(0px, ${O.y+O.offsetY}px)`},children:[p.jsx(he,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:P,onPointerUp:_,onPointerMove:E,onKeyDown:k,"data-id":T.id,"data-index":R,children:p.jsx(Ie,{icon:"drag-handle-dots"})}),r<ht.TABLET_SM&&y?p.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const U=window.prompt("Rename page",T.name);U&&U!==T.name&&n.renamePage(T.id,U)},onDoubleClick:S,children:[p.jsx(wv,{checked:T.id===u.id}),p.jsx(mt,{children:T.name})]}):p.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:p.jsx(pee,{id:T.id,name:T.name,isCurrentPage:T.id===u.id})}),!h&&p.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":g,children:p.jsx(QC,{index:R,item:T,listSize:c.length})})]},T.id+"_editing"):p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[p.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(T.id),onDoubleClick:S,title:t("page-menu.go-to-page"),children:[p.jsx(wv,{checked:T.id===u.id}),p.jsx(mt,{children:T.name})]}),!h&&p.jsx("div",{className:"tlui-page_menu__item__submenu",children:p.jsx(QC,{index:R,item:T,listSize:c.length,onRename:()=>{if(n.environment.isIos){const U=window.prompt("Rename page",T.name);U&&U!==T.name&&n.renamePage(T.id,U)}else n.batch(()=>{v(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function gee(){const e=le(),n=F(),t=_k(),r=Ek(),o=an(1),s=fo(),i=K("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(s&&!i))return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e.undo,disabled:!t}),p.jsx(z,{...e.redo,disabled:!r}),p.jsx(z,{...e.delete,disabled:!o}),p.jsx(z,{...e.duplicate,disabled:!o})]})}const mee=x.memo(function({children:n}){const t=n??p.jsx(gee,{});return p.jsx(So,{type:"small-icons",sourceId:"quick-actions",children:t})}),yee=Object.freeze([mr,yi,Ua,co]);function BA(e=yee){const n=F();return K("getRelevantStyles",()=>{var s;const t=new Ky(n.getSharedStyles()),r=!!((s=n.root.getCurrent())!=null&&s.shapeType),o=n.isIn("select")&&n.getSelectedShapeIds().length>0;if(t.size===0&&n.isIn("select")&&n.getSelectedShapeIds().length===0)for(const i of e)t.applyValue(i,n.getStyleForNextShape(i));return r||o||t.size>0?t:null},[n])}const Or={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],horizontalAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-center"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"cloud",icon:"geo-cloud"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"star",icon:"geo-star"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]};function See(e){const{uiType:n,items:t,title:r,style:o,value:s,onValueChange:i}=e,a=F(),l=Ee(),c=x.useRef(!1),{handleButtonClick:u,handleButtonPointerDown:d,handleButtonPointerEnter:h,handleButtonPointerUp:f}=x.useMemo(()=>{const g=()=>{c.current=!1,window.removeEventListener("pointerup",g)};return{handleButtonClick:I=>{const{id:P}=I.currentTarget.dataset;s.type==="shared"&&s.value===P||(a.mark("point picker item"),i(o,P,!1))},handleButtonPointerDown:I=>{const{id:P}=I.currentTarget.dataset;a.mark("point picker item"),i(o,P,!0),c.current=!0,window.addEventListener("pointerup",g)},handleButtonPointerEnter:I=>{if(!c.current)return;const{id:P}=I.currentTarget.dataset;i(o,P,!0)},handleButtonPointerUp:I=>{const{id:P}=I.currentTarget.dataset;s.type==="shared"&&s.value===P||i(o,P,!1)}}},[s,a,i,o]),y=K("theme",()=>Dn({isDarkMode:a.user.getIsDarkMode()}),[a]);return p.jsx("div",{"data-testid":`style.${n}`,className:fe("tlui-buttons__grid"),children:t.map(g=>p.jsx(he,{type:"icon","data-id":g.value,"data-testid":`style.${n}.${g.value}`,"aria-label":g.value,"data-state":s.type==="shared"&&s.value===g.value?"hinted":void 0,title:r+" — "+l(`${n}-style.${g.value}`),className:fe("tlui-button-grid__button"),style:o===mr?{color:y[g.value].solid}:void 0,onPointerEnter:h,onPointerDown:d,onPointerUp:f,onClick:u,children:p.jsx(Ie,{icon:g.icon})},g.value))})}const Ta=x.memo(See);function UA(e,[n,t]){return Math.min(t,Math.max(n,e))}function vee(e){const n=x.useRef({value:e,previous:e});return x.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}const HA=["PageUp","PageDown"],KA=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],VA={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Fu="Slider",[bv,wee,xee]=Wf(Fu),[WA,Rne]=go(Fu,[xee]),[bee,cg]=WA(Fu),Pee=x.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:d=()=>{},onValueCommit:h=()=>{},inverted:f=!1,...y}=e,[g,v]=x.useState(null),S=Ye(n,N=>v(N)),w=x.useRef(new Set),C=x.useRef(0),I=i==="horizontal",P=g?!!g.closest("form"):!0,E=I?Cee:Iee,[_=[],k]=Ws({prop:u,defaultProp:c,onChange:N=>{var L;(L=[...w.current][C.current])===null||L===void 0||L.focus(),d(N)}}),M=x.useRef(_);function T(N){const L=Oee(_,N);U(N,L)}function R(N){U(N,C.current)}function O(){const N=M.current[C.current];_[C.current]!==N&&h(_)}function U(N,L,{commit:G}={commit:!1}){const X=Nee(s),H=Fee(Math.round((N-r)/s)*s+r,X),B=UA(H,[r,o]);k((W=[])=>{const Y=Aee(W,B,L);if(Lee(Y,l*s)){C.current=Y.indexOf(B);const J=String(Y)!==String(W);return J&&G&&h(Y),J?Y:W}else return W})}return x.createElement(bee,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:C,thumbs:w.current,values:_,orientation:i},x.createElement(bv.Provider,{scope:e.__scopeSlider},x.createElement(bv.Slot,{scope:e.__scopeSlider},x.createElement(E,Q({"aria-disabled":a,"data-disabled":a?"":void 0},y,{ref:S,onPointerDown:se(y.onPointerDown,()=>{a||(M.current=_)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:T,onSlideMove:a?void 0:R,onSlideEnd:a?void 0:O,onHomeKeyDown:()=>!a&&U(r,0,{commit:!0}),onEndKeyDown:()=>!a&&U(o,_.length-1,{commit:!0}),onStepKeyDown:({event:N,direction:L})=>{if(!a){const H=HA.includes(N.key)||N.shiftKey&&KA.includes(N.key)?10:1,B=C.current,W=_[B],Y=s*H*L;U(W+Y,B,{commit:!0})}}})))),P&&_.map((N,L)=>x.createElement(Mee,{key:L,name:t?t+(_.length>1?"[]":""):void 0,value:N})))}),[GA,YA]=WA(Fu,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Cee=x.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[d,h]=x.useState(null),f=Ye(n,C=>h(C)),y=x.useRef(),g=qw(o),v=g==="ltr",S=v&&!s||!v&&s;function w(C){const I=y.current||d.getBoundingClientRect(),P=[0,I.width],_=ox(P,S?[t,r]:[r,t]);return y.current=I,_(C-I.left)}return x.createElement(GA,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width"},x.createElement(XA,Q({dir:g,"data-orientation":"horizontal"},u,{ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:C=>{const I=w(C.clientX);i==null||i(I)},onSlideMove:C=>{const I=w(C.clientX);a==null||a(I)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:C=>{const P=VA[S?"from-left":"from-right"].includes(C.key);c==null||c({event:C,direction:P?-1:1})}})))}),Iee=x.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=x.useRef(null),d=Ye(n,u),h=x.useRef(),f=!o;function y(g){const v=h.current||u.current.getBoundingClientRect(),S=[0,v.height],C=ox(S,f?[r,t]:[t,r]);return h.current=v,C(g-v.top)}return x.createElement(GA,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1},x.createElement(XA,Q({"data-orientation":"vertical"},c,{ref:d,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const v=y(g.clientY);s==null||s(v)},onSlideMove:g=>{const v=y(g.clientY);i==null||i(v)},onSlideEnd:()=>{h.current=void 0,a==null||a()},onStepKeyDown:g=>{const S=VA[f?"from-bottom":"from-top"].includes(g.key);l==null||l({event:g,direction:S?-1:1})}})))}),XA=x.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=cg(Fu,t);return x.createElement(Be.span,Q({},c,{ref:n,onKeyDown:se(e.onKeyDown,d=>{d.key==="Home"?(i(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):HA.concat(KA).includes(d.key)&&(l(d),d.preventDefault())}),onPointerDown:se(e.onPointerDown,d=>{const h=d.target;h.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(h)?h.focus():r(d)}),onPointerMove:se(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:se(e.onPointerUp,d=>{const h=d.target;h.hasPointerCapture(d.pointerId)&&(h.releasePointerCapture(d.pointerId),s(d))})}))}),Eee="SliderTrack",_ee=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=cg(Eee,t);return x.createElement(Be.span,Q({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),JC="SliderRange",kee=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=cg(JC,t),s=YA(JC,t),i=x.useRef(null),a=Ye(n,i),l=o.values.length,c=o.values.map(h=>qA(h,o.min,o.max)),u=l>1?Math.min(...c):0,d=100-Math.max(...c);return x.createElement(Be.span,Q({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:d+"%"}}))}),eI="SliderThumb",Tee=x.forwardRef((e,n)=>{const t=wee(e.__scopeSlider),[r,o]=x.useState(null),s=Ye(n,a=>o(a)),i=x.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return x.createElement($ee,Q({},e,{ref:s,index:i}))}),$ee=x.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,s=cg(eI,t),i=YA(eI,t),[a,l]=x.useState(null),c=Ye(n,v=>l(v)),u=rM(a),d=s.values[r],h=d===void 0?0:qA(d,s.min,s.max),f=jee(r,s.values.length),y=u==null?void 0:u[i.size],g=y?Dee(y,h,i.direction):0;return x.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${h}% + ${g}px)`}},x.createElement(bv.ItemSlot,{scope:e.__scopeSlider},x.createElement(Be.span,Q({role:"slider","aria-label":e["aria-label"]||f,"aria-valuemin":s.min,"aria-valuenow":d,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:c,style:d===void 0?{display:"none"}:e.style,onFocus:se(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),Mee=e=>{const{value:n,...t}=e,r=x.useRef(null),o=vee(n);return x.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&l){const c=new Event("input",{bubbles:!0});l.call(s,n),s.dispatchEvent(c)}},[o,n]),x.createElement("input",Q({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function Aee(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function qA(e,n,t){const s=100/(t-n)*(e-n);return UA(s,[0,100])}function jee(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function Oee(e,n){if(e.length===1)return 0;const t=e.map(o=>Math.abs(o-n)),r=Math.min(...t);return t.indexOf(r)}function Dee(e,n,t){const r=e/2,s=ox([0,50],[0,r]);return(r-s(n)*t)*t}function Ree(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function Lee(e,n){if(n>0){const t=Ree(e);return Math.min(...t)>=n}return!0}function ox(e,n){return t=>{if(e[0]===e[1]||n[0]===n[1])return n[0];const r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-e[0])}}function Nee(e){return(String(e).split(".")[1]||"").length}function Fee(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const zee=Pee,Bee=_ee,Uee=kee,Hee=Tee,Kee=x.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=F(),l=Ee(),c=x.useCallback(h=>{i(h[0],!0)},[i]),u=x.useCallback(()=>{a.mark("click slider")},[a]),d=x.useCallback(()=>{o&&i(o,!1)},[o,i]);return p.jsx("div",{className:"tlui-slider__container",children:p.jsxs(zee,{"data-testid":n["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:d,title:t+" — "+l(s),children:[p.jsx(Bee,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&p.jsx(Uee,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&p.jsx(Hee,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Vee({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:d}){const h=Ee(),f=x.useMemo(()=>{var g;return((g=s.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:g.icon)??"mixed"},[s,c]),y=x.useMemo(()=>{var g;return((g=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:g.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:p.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[p.jsx("div",{title:h(e),className:"tlui-style-panel__double-select-picker-label",children:h(e)}),p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsxs(Ti,{id:`style panel ${n} A`,children:[p.jsx($i,{children:p.jsx(he,{type:"icon","data-testid":`style.${n}`,title:h(r)+" — "+(c===null||c.type==="mixed"?h("style-panel.mixed"):h(`${n}-style.${c.value}`)),children:p.jsx(Ie,{icon:f,small:!0,invertIcon:!0})})}),p.jsx(Mi,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:p.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,v)=>p.jsx(du,{"data-testid":`style.${n}.${g.value}`,children:p.jsx(he,{type:"icon",onClick:()=>d(a,g.value,!1),title:`${h(r)} — ${h(`${n}-style.${g.value}`)}`,children:p.jsx(Ie,{icon:g.icon,invertIcon:!0})},g.value)},v))})})]}),p.jsxs(Ti,{id:`style panel ${t}`,children:[p.jsx($i,{children:p.jsx(he,{type:"icon","data-testid":`style.${t}`,title:h(o)+" — "+(u===null||u.type==="mixed"?h("style-panel.mixed"):h(`${t}-style.${u.value}`)),children:p.jsx(Ie,{icon:y,small:!0})})}),p.jsx(Mi,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:p.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>p.jsx(du,{children:p.jsx(he,{type:"icon",title:`${h(o)} — ${h(`${t}-style.${g.value}`)}`,"data-testid":`style.${t}.${g.value}`,onClick:()=>d(l,g.value,!1),children:p.jsx(Ie,{icon:g.icon})})},g.value))})})]})]})]})}const Wee=x.memo(Vee);function Gee({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Ee(),c=F(),u=x.useMemo(()=>{var f;return(f=o.find(y=>i.type==="shared"&&y.value===i.value))==null?void 0:f.icon},[o,i]),d=i.type==="mixed"?l("style-panel.mixed"):l(`${t}-style.${i.value}`),h=n?l(n):"";return p.jsxs(Ti,{id:`style panel ${e}`,children:[p.jsx($i,{children:p.jsxs(he,{type:s,"data-testid":`style.${t}`,title:d,children:[p.jsx(mt,{children:h}),p.jsx(Ie,{icon:u??"mixed"})]})}),p.jsx(Mi,{side:"left",align:"center",alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>p.jsx(du,{children:p.jsx(he,{type:"icon","data-testid":`style.${t}.${f.value}`,title:l(`${t}-style.${f.value}`),onClick:()=>{c.mark("select style dropdown item"),a(r,f.value,!1)},children:p.jsx(Ie,{icon:f.icon})})},f.value))})})]})}const sx=x.memo(Gee);function Yee({styles:e}){if(!e)return null;const n=e.get(so),t=e.get(cp),r=e.get(lp),o=e.get(dp),s=e.get(lo),i=n===void 0,a=t===void 0&&r===void 0,l=o===void 0,c=s===void 0;return p.jsxs(p.Fragment,{children:[p.jsx(Xee,{styles:e}),!c&&p.jsx(qee,{styles:e}),!(i&&a&&l)&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[p.jsx(Zee,{styles:e}),p.jsx(Jee,{styles:e}),p.jsx(Qee,{styles:e})]})]})}function zu(){const e=F(),n=yo();return ie.useMemo(()=>function(r,o,s){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,o,{squashing:s}),e.setStyleForNextShapes(r,o,{squashing:s}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),n("set-style",{source:"style-panel",id:r.id,value:o})},[e,n])}function Xee({styles:e}){const n=Ee(),t=zu(),r=e.get(mr),o=e.get(Ua),s=e.get(yi),i=e.get(co),a=o!==void 0||s!==void 0||i!==void 0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[r===void 0?null:p.jsx(Ta,{title:n("style-panel.color"),uiType:"color",style:mr,items:Or.color,value:r,onValueChange:t}),p.jsx(ete,{})]}),a&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[o===void 0?null:p.jsx(Ta,{title:n("style-panel.fill"),uiType:"fill",style:Ua,items:Or.fill,value:o,onValueChange:t}),s===void 0?null:p.jsx(Ta,{title:n("style-panel.dash"),uiType:"dash",style:yi,items:Or.dash,value:s,onValueChange:t}),i===void 0?null:p.jsx(Ta,{title:n("style-panel.size"),uiType:"size",style:co,items:Or.size,value:i,onValueChange:t})]})]})}function qee({styles:e}){const n=Ee(),t=zu(),r=e.get(lo),o=e.get(Ec),s=e.get(up);return r===void 0&&o===void 0?null:p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[r===void 0?null:p.jsx(Ta,{title:n("style-panel.font"),uiType:"font",style:lo,items:Or.font,value:r,onValueChange:t}),o===void 0?null:p.jsxs("div",{className:"tlui-style-panel__row",children:[p.jsx(Ta,{title:n("style-panel.align"),uiType:"align",style:Ec,items:Or.horizontalAlign,value:o,onValueChange:t}),p.jsx("div",{className:"tlui-style-panel__row__extra-button",children:s===void 0?p.jsx(he,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:p.jsx(Ie,{icon:"vertical-align-center"})}):p.jsx(sx,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:up,items:Or.verticalAlign,value:s,onValueChange:t})})]})]})}function Zee({styles:e}){const n=zu(),t=e.get(so);return t===void 0?null:p.jsx(sx,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:so,items:Or.geo,value:t,onValueChange:n})}function Qee({styles:e}){const n=zu(),t=e.get(dp);return t===void 0?null:p.jsx(sx,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:dp,items:Or.spline,value:t,onValueChange:n})}function Jee({styles:e}){const n=zu(),t=e.get(cp),r=e.get(lp);return!t||!r?null:p.jsx(Wee,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:lp,itemsA:Or.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:cp,itemsB:Or.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Vl=[.1,.25,.5,.75,1];function ete(){const e=F(),n=K("opacity",()=>e.getSharedOpacity(),[e]),t=yo(),r=Ee(),o=ie.useCallback((i,a)=>{const l=Vl[i];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(l,{squashing:a}),e.setOpacityForNextShapes(l,{squashing:a}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),t("set-style",{source:"style-panel",id:"opacity",value:i})},[e,t]);if(n===void 0)return null;const s=n.type==="mixed"?-1:Vl.indexOf(nD(Vl,i=>Math.abs(i-n.value)));return p.jsx(Kee,{"data-testid":"style.opacity",value:s>=0?s:Vl.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:Vl.length-1,title:r("style-panel.opacity")})}const tte=x.memo(function({isMobile:n,children:t}){const r=F(),o=BA(),s=x.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[r,n]),i=t??p.jsx(Yee,{styles:o});return p.jsx("div",{className:fe("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})}),oy=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function sy(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function Wl(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function ZA(e,n){const t=n.slice(0,n.length-1);for(let r=0;r<t.length;r++)t[r]=e[t[r].toLowerCase()];return t}function QA(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const n=e.split(",");let t=n.lastIndexOf("");for(;t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function nte(e,n){const t=e.length>=n.length?e:n,r=e.length>=n.length?n:e;let o=!0;for(let s=0;s<t.length;s++)r.indexOf(t[s])===-1&&(o=!1);return o}const hu={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,"-":oy?173:189,"=":oy?61:187,";":oy?59:186,"'":222,"[":219,"]":221,"\\":220},ho={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Pv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Dt={16:!1,18:!1,17:!1,91:!1},at={};for(let e=1;e<20;e++)hu["f".concat(e)]=111+e;let He=[],bc=null,JA="all";const _o=new Map,Bu=e=>hu[e.toLowerCase()]||ho[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),rte=e=>Object.keys(hu).find(n=>hu[n]===e),ote=e=>Object.keys(ho).find(n=>ho[n]===e);function ej(e){JA=e||"all"}function pu(){return JA||"all"}function ste(){return He.slice(0)}function ite(){return He.map(e=>rte(e)||ote(e)||String.fromCharCode(e))}function ate(){const e=[];return Object.keys(at).forEach(n=>{at[n].forEach(t=>{let{key:r,scope:o,mods:s,shortcut:i}=t;e.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>Bu(a))})})}),e}function lte(e){const n=e.target||e.srcElement,{tagName:t}=n;let r=!0;const o=t==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(n.type);return(n.isContentEditable||(o||t==="TEXTAREA"||t==="SELECT")&&!n.readOnly)&&(r=!1),r}function cte(e){return typeof e=="string"&&(e=Bu(e)),He.indexOf(e)!==-1}function ute(e,n){let t,r;e||(e=pu());for(const o in at)if(Object.prototype.hasOwnProperty.call(at,o))for(t=at[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return ix(a)}):r++;pu()===e&&ej(n||"all")}function dte(e){let n=e.keyCode||e.which||e.charCode;const t=He.indexOf(n);if(t>=0&&He.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&He.splice(0,He.length),(n===93||n===224)&&(n=91),n in Dt){Dt[n]=!1;for(const r in ho)ho[r]===n&&(kn[r]=!1)}}function tj(e){if(typeof e>"u")Object.keys(at).forEach(o=>{Array.isArray(at[o])&&at[o].forEach(s=>Qd(s)),delete at[o]}),ix(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Qd(o)});else if(typeof e=="object")e.key&&Qd(e);else if(typeof e=="string"){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];let[o,s]=t;typeof o=="function"&&(s=o,o=""),Qd({key:e,scope:o,method:s,splitKey:"+"})}}const Qd=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;QA(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Bu(c);if(!at[u])return;t||(t=pu());const d=l>1?ZA(ho,a):[],h=[];at[u]=at[u].filter(f=>{const g=(r?f.method===r:!0)&&f.scope===t&&nte(f.mods,d);return g&&h.push(f.element),!g}),h.forEach(f=>ix(f))})};function tI(e,n,t,r){if(n.element!==r)return;let o;if(n.scope===t||n.scope==="all"){o=n.mods.length>0;for(const s in Dt)Object.prototype.hasOwnProperty.call(Dt,s)&&(!Dt[s]&&n.mods.indexOf(+s)>-1||Dt[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!Dt[16]&&!Dt[18]&&!Dt[17]&&!Dt[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(He),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function nI(e,n){const t=at["*"];let r=e.keyCode||e.which||e.charCode;if(!kn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),He.indexOf(r)===-1&&r!==229&&He.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=Pv[a];e[a]&&He.indexOf(l)===-1?He.push(l):!e[a]&&He.indexOf(l)>-1?He.splice(He.indexOf(l),1):a==="metaKey"&&e[a]&&He.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(He=He.slice(He.indexOf(l))))}),r in Dt){Dt[r]=!0;for(const a in ho)ho[a]===r&&(kn[a]=!0);if(!t)return}for(const a in Dt)Object.prototype.hasOwnProperty.call(Dt,a)&&(Dt[a]=e[Pv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(He.indexOf(17)===-1&&He.push(17),He.indexOf(18)===-1&&He.push(18),Dt[17]=!0,Dt[18]=!0);const o=pu();if(t)for(let a=0;a<t.length;a++)t[a].scope===o&&(e.type==="keydown"&&t[a].keydown||e.type==="keyup"&&t[a].keyup)&&tI(e,t[a],o,n);if(!(r in at))return;const s=at[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,u=l.key.split(c),d=[];for(let h=0;h<u.length;h++)d.push(Bu(u[h]));d.sort().join("")===He.sort().join("")&&tI(e,l,o,n)}}function kn(e,n,t){He=[];const r=QA(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",d=!1,h=!1;for(t===void 0&&typeof n=="function"&&(t=n),Object.prototype.toString.call(n)==="[object Object]"&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(l=n.keyup),n.keydown!==void 0&&(c=n.keydown),n.capture!==void 0&&(d=n.capture),typeof n.splitKey=="string"&&(u=n.splitKey),n.single===!0&&(h=!0)),typeof n=="string"&&(s=n),h&&tj(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=ZA(ho,e)),e=e[e.length-1],e=e==="*"?"*":Bu(e),e in at||(at[e]=[]),at[e].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!_o.has(i)){const f=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return nI(g,i)},y=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;nI(g,i),dte(g)};_o.set(i,{keydownListener:f,keyupListenr:y,capture:d}),sy(i,"keydown",f,d),sy(i,"keyup",y,d)}if(!bc){const f=()=>{He=[]};bc={listener:f,capture:d},sy(window,"focus",f,d)}}}function hte(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(at).forEach(t=>{at[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function ix(e){const n=Object.values(at).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=_o.get(e)||{};r&&o&&(Wl(e,"keyup",o,s),Wl(e,"keydown",r,s),_o.delete(e))}if((n.length<=0||_o.size<=0)&&(Object.keys(_o).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=_o.get(o)||{};s&&i&&(Wl(o,"keyup",i,a),Wl(o,"keydown",s,a),_o.delete(o))}),_o.clear(),Object.keys(at).forEach(o=>delete at[o]),bc)){const{listener:o,capture:s}=bc;Wl(window,"focus",o,s),bc=null}}const iy={getPressedKeyString:ite,setScope:ej,getScope:pu,deleteScope:ute,getPressedKeyCodes:ste,getAllKeyCodes:ate,isPressed:cte,filter:lte,trigger:hte,unbind:tj,keyMap:hu,modifier:ho,modifierMap:Pv};for(const e in iy)Object.prototype.hasOwnProperty.call(iy,e)&&(kn[e]=iy[e]);if(typeof window<"u"){const e=window.hotkeys;kn.noConflict=n=>(n&&window.hotkeys===kn&&(window.hotkeys=e),kn),window.hotkeys=kn}const rI=["copy","cut","paste","asset"];function pte(){const e=F(),n=fo(),t=le(),r=rx(),o=K("is focused",()=>e.getInstanceState().isFocused,[e]),{itemsInPanel:s}=oj();x.useEffect(()=>{if(!o)return;const i=e.getContainer();kn.setScope(e.store.id);const a=(c,u)=>{kn(c,{element:document.body,scope:e.store.id},u)},l=(c,u)=>{kn(c,{element:document.body,keyup:!0,keydown:!1,scope:e.store.id},u)};for(const c of Object.values(t))c.kbd&&(n&&!c.readonlyOk||rI.includes(c.id)||a(oI(c.kbd),u=>{rc(e)||(je(u),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&e.getInstanceState().isReadonly||rI.includes(c.id)||a(oI(c.kbd),u=>{rc(e)||(je(u),c.onSelect("kbd"))});return a(",",c=>{if(rc(e)||e.inputs.keys.has("Comma"))return;je(c),i.focus(),e.inputs.keys.add("Comma");const{x:u,y:d,z:h}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_down",point:{x:u,y:d,z:h},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),l(",",c=>{if(rc(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:u,y:d,z:h}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_up",point:{x:u,y:d,z:h},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),()=>{kn.deleteScope(e.store.id)}},[t,r,n,e,o,s])}function oI(e){return fte(e).map(n=>{let t="";const r=n.split("");return r.length===1?t=r[0]:r[0]==="!"?t=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?t=`alt+shift+${r[2]}`:t=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?t=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?t=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:t=`cmd+${r[1]},ctrl+${r[1]}`:t=n,t}).join(",")}function fte(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const n=e.split(",");let t=n.lastIndexOf("");for(;t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function rc(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}function Fe(e){return{id:e.id,type:"item",readonlyOk:e.readonlyOk,toolItem:e}}const nj=ie.createContext([]);function gte({overrides:e,children:n}){const t=F(),r=rx(),o=ie.useMemo(()=>{const s=ge([Fe(r.select),Fe(r.hand),Fe(r.draw),Fe(r.eraser),Fe(r.arrow),Fe(r.text),Fe(r.note),Fe(r.asset),Fe(r.rectangle),Fe(r.ellipse),Fe(r.diamond),Fe(r.triangle),Fe(r.trapezoid),Fe(r.rhombus),Fe(r.hexagon),Fe(r.cloud),Fe(r.star),Fe(r.oval),Fe(r["x-box"]),Fe(r["check-box"]),Fe(r["arrow-left"]),Fe(r["arrow-up"]),Fe(r["arrow-down"]),Fe(r["arrow-right"]),Fe(r.line),Fe(r.highlight),Fe(r.frame),Fe(r.laser)]);return e?e(t,s,{tools:r}):s},[t,e,r]);return p.jsx(nj.Provider,{value:o,children:n})}function rj(){const e=ie.useContext(nj);if(!e)throw new Error("useToolbarSchema must be used within a ToolbarSchemaProvider");return e}function mte(){const e=F(),n=Ee(),t=BA(),r=t==null?void 0:t.get(mr),o=Dn({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=K("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(c=>{c||e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[e]),{StylePanel:l}=Xs();return l?p.jsxs(Hw,{id:"mobile style menu",onOpenChange:a,children:[p.jsx(Kw,{children:p.jsx(he,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),disabled:i,children:p.jsx(Ie,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),p.jsx(Vw,{side:"top",align:"end",children:l&&p.jsx(l,{isMobile:!0})})]}):null}const yte=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Ste({activeToolId:e}){const n=F(),t=Ln(),r=Ee(),o=K("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||yte.includes(e)?null:p.jsx(he,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:fe("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<ht.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:p.jsx(Ie,{icon:o?"lock":"unlock",small:!0})})}const vte=x.memo(function(){const n=F(),t=Ee(),r=Ln(),o=ie.useRef(void 0),s=fo(),i=rj(),a=K("current tool id",()=>n.getCurrentToolId(),[n]),l=K("geo",()=>n.getSharedStyles().getAsKnownValue(so),[n]),c=v=>v.label?`${t(v.label)} ${v.kbd?uu(v.kbd):""}`:"",u=i.find(v=>ay(v.toolItem,a,l)),{itemsInPanel:d,itemsInDropdown:h}=oj(),f=x.useMemo(()=>{let v=h.find(S=>S===u);return v||(o.current||(o.current=h[0]),v=o.current,h.includes(v)||(v=h[0])),o.current=v,v},[u,h]);x.useEffect(()=>{const v=[...d,f];for(let S=0;S<Math.min(10,v.length);S++){const w=`${S+1}`.slice(-1);kn(w,C=>{rc(n)||(je(C),v[S].toolItem.onSelect("kbd"))})}return()=>{kn.unbind("1,2,3,4,5,6,7,8,9,0")}},[f,n,d]);const{ActionsMenu:y,QuickActions:g}=Xs();return p.jsx("div",{className:"tlui-toolbar",children:p.jsxs("div",{className:"tlui-toolbar__inner",children:[p.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&p.jsxs("div",{className:"tlui-toolbar__extras",children:[r<ht.TABLET&&p.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[g&&p.jsx(g,{}),y&&p.jsx(y,{})]}),p.jsx(Ste,{activeToolId:a})]}),p.jsxs("div",{className:fe("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<ht.TABLET_SM}),children:[d.map(({toolItem:v})=>p.jsx(sI,{item:v,title:c(v),isSelected:ay(v,a,l)},v.id)),h.length?p.jsxs(p.Fragment,{children:[p.jsx(sI,{item:f.toolItem,title:c(f.toolItem),isSelected:ay(f.toolItem,a,l)},f.toolItem.id),p.jsxs(Ti,{id:"toolbar overflow",modal:!1,children:[p.jsx($i,{children:p.jsx(he,{title:t("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:p.jsx(Ie,{icon:"chevron-up"})})}),p.jsx(Mi,{side:"top",align:"center",children:p.jsx(wte,{toolbarItems:h})})]})]}):null]})]}),r<ht.TABLET_SM&&!s&&p.jsx("div",{className:"tlui-toolbar__tools",children:p.jsx(mte,{})})]})})}),wte=Tt(function({toolbarItems:n}){const t=Ee();return p.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",children:n.map(({toolItem:{id:r,meta:o,kbd:s,label:i,onSelect:a,icon:l}})=>p.jsx(du,{"data-tool":r,"data-geo":(o==null?void 0:o.geo)??"","aria-label":i,children:p.jsx(he,{type:"icon",className:"tlui-button-grid__button",onClick:()=>a("toolbar"),"data-testid":`tools.more.${r}`,title:i?`${t(i)} ${s?uu(s):""}`:"",children:p.jsx(Ie,{icon:l})})},r))})});function sI({item:e,title:n,isSelected:t}){var r;return p.jsx(he,{type:"tool","data-testid":`tools.${e.id}`,"data-tool":e.id,"data-geo":((r=e.meta)==null?void 0:r.geo)??"","aria-label":e.label,"data-state":t?"selected":void 0,onClick:()=>e.onSelect("toolbar"),title:n,onTouchStart:o=>{je(o),e.onSelect("toolbar")},children:p.jsx(Ie,{icon:e.icon})})}const ay=(e,n,t)=>{var r,o;return(r=e.meta)!=null&&r.geo?n==="geo"&&t===((o=e.meta)==null?void 0:o.geo):n===e.id};function oj(){const e=Ln(),n=rj(),t=fo();return x.useMemo(()=>{const r=n.filter(a=>!t||a.readonlyOk),o=Math.min(8,5+e),s=r.slice(0,o),i=r.slice(o);return i.length<=2?{itemsInPanel:r,itemsInDropdown:[]}:{itemsInPanel:s,itemsInDropdown:i}},[n,e,t])}function xte(){const e=le();return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["zoom-in"],noClose:!0}),p.jsx(z,{...e["zoom-out"],noClose:!0}),p.jsx(MA,{}),p.jsx(AA,{}),p.jsx(jA,{})]})}const bte=x.memo(function({children:n}){const t=mn(),[r,o]=Gs("zoom menu"),s=n??p.jsx(xte,{});return p.jsxs(ex,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[p.jsx(tx,{asChild:!0,dir:"ltr",children:p.jsx(Pte,{})}),p.jsx(lg,{container:t,children:p.jsx(nx,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:p.jsx(So,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),Pte=x.forwardRef(function(n,t){const r=F(),o=Ln(),s=K("zoom",()=>r.getZoomLevel(),[r]),i=Ee(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{duration:Mo})},[r]);return p.jsx(he,{ref:t,...n,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<ht.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<ht.MOBILE?"zoom-in":void 0,children:o<ht.MOBILE?null:p.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),sj=x.createContext({});function Cte({overrides:e={},children:n}){const t=Zv(e);return p.jsx(sj.Provider,{value:x.useMemo(()=>({ContextMenu:jJ,ActionsMenu:uJ,HelpMenu:HJ,ZoomMenu:bte,MainMenu:lee,Minimap:uee,StylePanel:tte,PageMenu:fee,NavigationPanel:hee,Toolbar:vte,KeyboardShortcutsDialog:ZJ,QuickActions:mee,HelperButtons:YJ,DebugMenu:FJ,MenuPanel:cee,...t}),[t]),children:n})}function Xs(){return x.useContext(sj)}const Ite=x.memo(function(){const{DebugMenu:n}=Xs();return p.jsxs("div",{className:"tlui-debug-panel",children:[p.jsx(_te,{}),p.jsx(kte,{}),n&&p.jsx(n,{})]})});function Ete(e=!0){const[n,t]=x.useState(0),r=F();x.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const _te=Tt(function(){Ete();const n=F(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),s=t==="select.idle"||!t.includes("select.")?r:o,i=s&&t.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${b.ToFixed(n.getPointInShapeSpace(s,n.inputs.currentPagePoint),0)}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${b.ToFixed(n.inputs.originPagePoint,0)}] → [${b.ToFixed(n.inputs.currentPagePoint,0)}] = ${b.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return p.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function kte(){const e=K("show_fps",()=>Ft.showFps.get(),[Ft]),n=x.useRef(null);return x.useEffect(()=>{if(!e)return;const t=250;let r=0,o=!1,s=performance.now(),i=0,a=0,l=!1;function c(){if(!o){if(a++,i=performance.now()-s,i>t){const u=Math.round(a*(t/i)*(1e3/t));u>r&&(r=u);const d=r*.75;(u<d&&!l||u>=d&&l)&&(l=!l),n.current.innerHTML=`FPS ${u.toString()}`,n.current.className="tlui-debug-panel__fps"+(l?" tlui-debug-panel__fps__slow":""),i-=t,a=0,s=performance.now()}requestAnimationFrame(c)}}return c(),()=>{o=!0}},[e]),e?p.jsx("div",{ref:n}):null}const Tte=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=zi(),o=mn(),s=x.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return p.jsx(Mq,{onOpenChange:s,defaultOpen:!0,children:p.jsx(Aq,{container:o,children:p.jsx(jq,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:p.jsx(Oq,{dir:"ltr",className:"tlui-dialog__content",children:p.jsx(n,{onClose:()=>s(!1)})})})})})};function $te(){const{dialogs:e}=zi();return p.jsx(p.Fragment,{children:e.map(n=>p.jsx(Tte,{...n},n.id))})}const Mte=ie.memo($te);function Ate(){const e=F(),n=K("follow",()=>e.getInstanceState().followingUserId,[e]);return n?p.jsx(jte,{userId:n}):null}function jte({userId:e}){const n=KE(e);return n?p.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function Ote({toast:e}){const{removeToast:n}=Wr(),t=Ee(),r=s=>{s||n(e.id)},o=e.actions&&e.actions.length>0;return p.jsxs(rY,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,children:[e.icon&&p.jsx("div",{className:"tlui-toast__icon",children:p.jsx(Rs,{icon:e.icon})}),p.jsxs("div",{className:"tlui-toast__main",children:[p.jsxs("div",{className:"tlui-toast__content",children:[e.title&&p.jsx(oY,{className:"tlui-toast__title",children:e.title}),e.description&&p.jsx(sY,{className:"tlui-toast__description",children:e.description})]}),e.actions&&p.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((s,i)=>p.jsx(iY,{altText:s.label,asChild:!0,onClick:s.onClick,children:p.jsx(he,{type:s.type,children:p.jsx(mt,{children:s.label})})},i)),p.jsx(EC,{asChild:!0,children:p.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:p.jsx(mt,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&p.jsx(EC,{asChild:!0,children:p.jsx(he,{type:"normal",className:"tlui-toast__close",children:p.jsx(mt,{children:e.closeLabel??t("toast.close")})})})]})}function Dte(){const{toasts:e}=Wr();return p.jsx(p.Fragment,{children:e.map(n=>p.jsx(Ote,{toast:n},n.id))})}const Rte=x.memo(Dte);function Lte(){const{toasts:e}=Wr(),[n,t]=x.useState(!1);return x.useEffect(()=>{let r=!1;return e.length?t(!0):setTimeout(()=>{r||t(!1)},1e3),()=>{r=!0}},[e.length,t]),n?p.jsx(zG,{className:"tlui-toast__viewport"}):null}const pi="2.0.1";let Cv={fonts:{draw:`https://unpkg.com/@tldraw/assets@${pi}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${pi}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${pi}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${pi}/fonts/IBMPlexMono-Medium.woff2`}};function ij(e){return x.useMemo(()=>e?{fonts:{...Cv.fonts,...e==null?void 0:e.fonts}}:Cv,[e])}const Nte=["align-bottom-center","align-bottom-left","align-bottom-right","align-bottom","align-center-center","align-center-horizontal","align-center-left","align-center-right","align-center-vertical","align-left","align-right","align-top-center","align-top-left","align-top-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","aspect-ratio","avatar","blob","bring-forward","bring-to-front","check","checkbox-checked","checkbox-empty","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","collab","color","comment","cross-2","cross","dash-dashed","dash-dotted","dash-draw","dash-solid","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","file","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","hidden","image","info-circle","leading","link","lock-small","lock","menu","minus","mixed","pack","page","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","ruler","search","send-backward","send-to-back","settings-horizontal","settings-vertical-1","settings-vertical","share-1","share-2","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","status-online","stretch-horizontal","stretch-vertical","text-align-center","text-align-justify","text-align-left","text-align-right","tool-arrow","tool-embed","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-text","trash","triangle-down","triangle-up","twitter","undo","ungroup","unlock-small","unlock","vertical-align-center","vertical-align-end","vertical-align-start","visible","warning-triangle","zoom-in","zoom-out"];let Gl={...Cv,icons:Object.fromEntries(Nte.map(e=>[e,`https://unpkg.com/@tldraw/assets@${pi}/icons/icon/${e}.svg`])),translations:Object.fromEntries(_c.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${pi}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Ha.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${pi}/embed-icons/${e.type}.png`]))};function Fte(e){return e?{fonts:Object.assign({...Gl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...Gl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...Gl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...Gl.translations},{...e==null?void 0:e.translations})}:Gl}function zte(){const{addToast:e,removeToast:n,clearToasts:t}=Wr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=zi(),l=Ln()<ht.TABLET_SM,c=Ee();return x.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,e,o,t,c,s,n,i,l])}function Bte(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of oo(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,n));return o},toolbar:(r,o,s)=>{for(const i of e)i.toolbar&&(o=i.toolbar(r,o,{...n,...s}));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...n,...s}));return o},translations:t}}function aj(e){return x.useMemo(()=>e,e)}function Ute(e){const n=aj(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of oo(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function Hte(e){const n=zte(),t=aj(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>Bte(t,n),[t,n])}function Kte({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return p.jsx(lY,{assetUrls:Fte(t),children:p.jsx(dY,{overrides:Ute(e),children:p.jsx(fq,{onEvent:r,children:p.jsx(iZ,{children:p.jsx(hZ,{children:p.jsx(aY,{forceMobile:o,children:p.jsx(Cte,{overrides:n,children:p.jsx(Vte,{overrides:e,children:s})})})})})})})})}function Vte({overrides:e,children:n}){const t=Hte(e);return p.jsx(fZ,{overrides:t.actions,children:p.jsx(XJ,{overrides:t.tools,children:p.jsx(gte,{overrides:t.toolbar,children:n})})})}function Wte(){const e=F(),{addToast:n}=Wr();x.useEffect(()=>{function t({name:r,count:o}){n({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${o}). Please delete some shapes or move to a different page to continue.`})}return e.addListener("max-shapes",t),()=>{e.removeListener("max-shapes",t)}},[e,n])}const Gte=ie.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return p.jsx(Kte,{...s,components:o,children:p.jsx(Yte,{hideUi:r,renderDebugMenuItems:n,children:t})})}),Yte=ie.memo(function({children:n,hideUi:t,...r}){return p.jsxs(p.Fragment,{children:[n,t?null:p.jsx(Xte,{...r})]})}),Xte=ie.memo(function(){const n=F(),t=Ee(),r=Ln(),o=fo(),s=K("focus",()=>n.getInstanceState().isFocusMode,[n]),i=K("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:d,HelpMenu:h,NavigationPanel:f,HelperButtons:y}=Xs();pte(),tZ(),Wte();const{"toggle-focus-mode":g}=le();return p.jsx(L$,{children:p.jsxs("div",{className:fe("tlui-layout",{"tlui-layout__mobile":r<ht.TABLET_SM}),"data-breakpoint":r,children:[s?p.jsx("div",{className:"tlui-layout__top",children:p.jsx(he,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>g.onSelect("menu"),children:p.jsx(Ie,{icon:"dot"})})}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"tlui-layout__top",children:[p.jsxs("div",{className:"tlui-layout__top__left",children:[c&&p.jsx(c,{}),y&&p.jsx(y,{})]}),p.jsx("div",{className:"tlui-layout__top__center",children:l&&p.jsx(l,{})}),p.jsxs("div",{className:"tlui-layout__top__right",children:[a&&p.jsx(a,{}),u&&r>=ht.TABLET_SM&&!o&&p.jsx(u,{})]})]}),p.jsxs("div",{className:"tlui-layout__bottom",children:[p.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&p.jsx(f,{}),d&&p.jsx(d,{}),h&&p.jsx(h,{})]}),i&&p.jsx(Ite,{})]})]}),p.jsx(Rte,{}),p.jsx(Mte,{}),p.jsx(Lte,{}),p.jsx(Ate,{})]})})}),Jd=(e,n)=>{const[t,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),NO(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function qte(e){return{draw:{url:e.fonts.draw,format:e.fonts.draw.split(".").pop()},serif:{url:e.fonts.serif,format:e.fonts.serif.split(".").pop()},sansSerif:{url:e.fonts.sansSerif,format:e.fonts.sansSerif.split(".").pop()},monospace:{url:e.fonts.monospace,format:e.fonts.monospace.split(".").pop()}}}function lj(e){const n=x.useMemo(()=>qte(e),[e]),t=[Jd("tldraw_draw",n.draw),Jd("tldraw_serif",n.serif),Jd("tldraw_sans",n.sansSerif),Jd("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Zte(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],tools:c=[],...u}=e,d=Zv(a),h=x.useMemo(()=>({Scribble:j1,CollaboratorScribble:j1,SelectionForeground:RU,SelectionBackground:OU,Handles:kU,HoveredShapeIndicator:TU,...d}),[d]),f=By(l),y=x.useMemo(()=>[...r2,...f],[f]),g=By(c),v=x.useMemo(()=>[...pV,...$H,...g],[g]),S=ij(u.assetUrls),{done:w,error:C}=lj(S);return C?p.jsx(P_,{children:"Could not load assets. Please refresh the page."}):w?p.jsx(vF,{initialState:"select",...u,components:h,shapeUtils:y,tools:v,children:p.jsxs(Gte,{...u,components:h,children:[p.jsx(ene,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),n]})}):p.jsx(b_,{children:"Loading assets..."})}const Qte=Object.freeze(["image/jpeg","image/png","image/gif","image/svg+xml"]),Jte=Object.freeze(["video/mp4","video/quicktime"]);function ene({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=Qte,acceptedVideoMimeTypes:r=Jte,onMount:o}){const s=F(),i=Wr(),a=Ee(),l=tne(d=>{const h=[];return h.push(...eV(d)),yH(d,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),h.push(o==null?void 0:o(d)),()=>{h.forEach(f=>f==null?void 0:f())}});x.useLayoutEffect(()=>{if(s)return l==null?void 0:l(s)},[s,l]);const{Canvas:c}=Ge(),{ContextMenu:u}=Xs();return u?p.jsx(u,{}):c?p.jsx(c,{}):null}function tne(e){const n=x.useRef();return x.useLayoutEffect(()=>{n.current=e}),x.useDebugValue(e),x.useCallback((...t)=>{const r=n.current;return Do(r,"fn does not exist"),r(...t)},[])}x.memo(function(n){const[t,r]=x.useState(null),[o,s]=x.useState(null),i=By(n.shapeUtils??[]),a=x.useMemo(()=>[...r2,...i],[i]),l=S_({snapshot:n.snapshot,shapeUtils:a}),c=ij(),{done:u,error:d}=lj(c),{pageId:h,bounds:f,scale:y,background:g,padding:v,darkMode:S,preserveAspectRatio:w,format:C="svg"}=n;return x.useLayoutEffect(()=>{if(!o||!l||!u)return;let I=!1;const P=document.createElement("div");o.appendChild(P),o.classList.add("tl-container","tl-theme__light");const E=new ae({store:l,shapeUtils:a??[],tools:[],getContainer:()=>P});h&&E.setCurrentPage(h);const _=E.getCurrentPageShapeIds();async function k(){const M=await E.getSvg([..._],{bounds:f,scale:y,background:g,padding:v,darkMode:S,preserveAspectRatio:w});if(M&&!I){if(C==="svg"){const T=await Xw(M);if(!I){const R=new Blob([T],{type:"image/svg+xml"}),O=URL.createObjectURL(R);r(O)}}else if(C==="png"){const T=await FM(M,E.environment.isSafari,{type:C,quality:1,scale:2});if(T&&!I){const R=URL.createObjectURL(T);r(R)}}}E.dispose()}return k(),()=>{I=!0}},[C,o,l,a,h,f,y,g,v,S,w,u,d]),d?p.jsx(P_,{children:"Could not load assets."}):u?p.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&p.jsx("img",{src:t,style:{width:"100%",height:"100%"}})}):p.jsx(b_,{children:"Loading assets..."})});const nne=1,rne=be({tldrawFileFormatVersion:TD,schema:be({schemaVersion:Qu,storeVersion:Qu,recordVersions:Oy(Se,be({version:Qu,subTypeVersions:Oy(Se,Qu).optional(),subTypeKey:Se.optional()}))}),records:zt(be({id:Se,typeName:Se}).allowUnknownProperties())});function one(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function sne({json:e,schema:n}){let t;try{t=rne.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),one(t))return ti.err({type:"v1File",data:t})}catch{}return ti.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>nne)return ti.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=Object.fromEntries(t.records.map(s=>[s.id,s]));r=n.migrateStoreSnapshot({store:o,schema:t.schema})}catch(o){return ti.err({type:"invalidRecords",cause:o})}if(r.type==="error")return ti.err({type:"migrationFailed",reason:r.reason});try{return ti.ok(y_({initialData:r.value,schema:n}))}catch(o){return ti.err({type:"invalidRecords",cause:o})}}function ine(){const[e,n]=x.useState();function t(r){window.editor=r,e===void 0?fetch("/tldr-data").then(async o=>{if(!o.ok){console.log(`No tldr data to load from local endpoint (${o.status})`);return}return o.text()}).then(o=>{if(o===void 0)return;const s=sne({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),n(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.zoomToFit(),r.clearOpenMenus())}return p.jsx("div",{style:{inset:0,position:"fixed"},children:p.jsx(Zte,{assetUrls:LO(),onMount:t,store:e})})}var Iv={},iI=gl;Iv.createRoot=iI.createRoot,Iv.hydrateRoot=iI.hydrateRoot;Iv.createRoot(document.querySelector("#root")).render(p.jsx(ie.StrictMode,{children:p.jsx(ine,{})}));
|
|
320
|
+
</div>`}catch(I){console.error(I)}}function d(){e.environment.isChromeForIos?(l(),window.print()):e.environment.isSafari?(l(),document.execCommand("print",!1)):window.print()}const h=e.getSelectedShapeIds(),f=e.getCurrentPageId(),y=e.getPages(),v={scale:1,background:!1,darkMode:!1,preserveAspectRatio:"xMidYMid meet"};if(e.getSelectedShapeIds().length>0){const S=await e.getSvg(h,v);if(S){const w=y.find(C=>C.id===f);u(`tldraw — ${w==null?void 0:w.name}`,null,S),d()}}else{const S=e.getCurrentPage(),w=await e.getSvg(e.getSortedChildIdsForParent(S.id),v);w&&(u(`tldraw — ${S.name}`,null,w),d())}window.removeEventListener("beforeprint",l),window.removeEventListener("afterprint",c)},[e])}const KM=x.createContext({});function hZ({children:e}){const n=F(),t=yo(),[r,o]=x.useState([]),s=x.useCallback(c=>{const u=c.id??ze();return o(d=>[...d.filter(h=>h.id!==c.id),{...c,id:u}]),t("open-menu",{source:"dialog",id:u}),n.addOpenMenu(u),u},[n,t]),i=x.useCallback((c,u)=>(o(d=>d.map(h=>h.id===c?{...h,...u}:h)),t("open-menu",{source:"dialog",id:c}),n.addOpenMenu(c),c),[n,t]),a=x.useCallback(c=>(o(u=>u.filter(d=>{var h;return d.id===c?((h=d.onClose)==null||h.call(d),!1):!0})),t("close-menu",{source:"dialog",id:c}),n.deleteOpenMenu(c),c),[n,t]),l=x.useCallback(()=>{o(c=>(c.forEach(u=>{var d;(d=u.onClose)==null||d.call(u),t("close-menu",{source:"dialog",id:u.id}),n.deleteOpenMenu(u.id)}),[]))},[n,t]);return p.jsx(KM.Provider,{value:{dialogs:r,addDialog:s,removeDialog:a,clearDialogs:l,updateDialog:i},children:e})}function zi(){const e=x.useContext(KM);if(!e)throw new Error("useDialogs must be used within a DialogsProvider");return e}const VM=x.createContext({});function pZ(e){return Object.fromEntries(e.map(n=>[n.id,n]))}function ca(e,n){if(e.getSelectedShapes().length===0)return e.getDocumentSettings().name||n}function fZ({overrides:e,children:n}){const t=F(),{addDialog:r,clearDialogs:o}=zi(),{clearToasts:s}=Wr(),i=Ee(),a=HM(),l=dZ(),{cut:c,copy:u,paste:d}=eZ(),h=aZ(),f=uZ(),y=i("document.default-name"),g=yo(),v=x.useMemo(()=>{function S(){return t.isIn("select")||(t.complete(),t.setCurrentTool("select")),!1}function w(){return t.isIn("select")&&t.getSelectedShapeIds().length>0}const I=pZ([{id:"edit-link",label:"action.edit-link",icon:"link",onSelect(P){w()&&(S()||(g("edit-link",{source:P}),t.mark("edit-link"),r({component:Dq})))}},{id:"insert-embed",label:"action.insert-embed",kbd:"$i",onSelect(P){g("insert-embed",{source:P}),r({component:OM})}},{id:"insert-media",label:"action.insert-media",kbd:"$u",onSelect(P){g("insert-media",{source:P}),a()}},{id:"undo",label:"action.undo",icon:"undo",kbd:"$z",onSelect(P){g("undo",{source:P}),t.undo()}},{id:"redo",label:"action.redo",icon:"redo",kbd:"$!z",onSelect(P){g("redo",{source:P}),t.redo()}},{id:"export-as-svg",label:{default:"action.export-as-svg",menu:"action.export-as-svg.short","context-menu":"action.export-as-svg.short"},readonlyOk:!0,onSelect(P){g("export-as",{format:"svg",source:P}),f(t.getSelectedShapeIds(),"svg",ca(t,y))}},{id:"export-as-png",label:{default:"action.export-as-png",menu:"action.export-as-png.short","context-menu":"action.export-as-png.short"},readonlyOk:!0,onSelect(P){g("export-as",{format:"png",source:P}),f(t.getSelectedShapeIds(),"png",ca(t,y))}},{id:"export-as-json",label:{default:"action.export-as-json",menu:"action.export-as-json.short","context-menu":"action.export-as-json.short"},readonlyOk:!0,onSelect(P){g("export-as",{format:"json",source:P}),f(t.getSelectedShapeIds(),"json",ca(t,y))}},{id:"export-all-as-svg",label:{default:"action.export-all-as-svg",menu:"action.export-all-as-svg.short","context-menu":"action.export-all-as-svg.short"},readonlyOk:!0,onSelect(P){g("export-all-as",{format:"svg",source:P}),f(Array.from(t.getCurrentPageShapeIds()),"svg",ca(t,y))}},{id:"export-all-as-png",label:{default:"action.export-all-as-png",menu:"action.export-all-as-png.short","context-menu":"action.export-all-as-png.short"},readonlyOk:!0,onSelect(P){g("export-all-as",{format:"png",source:P}),f(Array.from(t.getCurrentPageShapeIds()),"png",ca(t,y))}},{id:"export-all-as-json",label:{default:"action.export-all-as-json",menu:"action.export-all-as-json.short","context-menu":"action.export-all-as-json.short"},readonlyOk:!0,onSelect(P){g("export-all-as",{format:"json",source:P}),f(Array.from(t.getCurrentPageShapeIds()),"json",ca(t,y))}},{id:"copy-as-svg",label:{default:"action.copy-as-svg",menu:"action.copy-as-svg.short","context-menu":"action.copy-as-svg.short"},kbd:"$!c",readonlyOk:!0,onSelect(P){g("copy-as",{format:"svg",source:P}),h(t.getSelectedShapeIds(),"svg")}},{id:"copy-as-png",label:{default:"action.copy-as-png",menu:"action.copy-as-png.short","context-menu":"action.copy-as-png.short"},readonlyOk:!0,onSelect(P){g("copy-as",{format:"png",source:P}),h(t.getSelectedShapeIds(),"png")}},{id:"copy-as-json",label:{default:"action.copy-as-json",menu:"action.copy-as-json.short","context-menu":"action.copy-as-json.short"},readonlyOk:!0,onSelect(P){g("copy-as",{format:"json",source:P}),h(t.getSelectedShapeIds(),"json")}},{id:"toggle-auto-size",label:"action.toggle-auto-size",onSelect(P){w()&&(S()||(g("toggle-auto-size",{source:P}),t.mark("toggling auto size"),t.updateShapes(t.getSelectedShapes().filter(E=>t.isShapeOfType(E,"text")&&E.props.autoSize===!1).map(E=>({id:E.id,type:E.type,props:{...E.props,w:8,autoSize:!0}})))))}},{id:"open-embed-link",label:"action.open-embed-link",readonlyOk:!0,onSelect(P){g("open-embed-link",{source:P});const E=t.getSelectedShapeIds(),_="No embed shapes selected";if(E.length!==1){console.error(_);return}const k=t.getShape(E[0]);if(!k||!t.isShapeOfType(k,"embed")){console.error(_);return}AF(k.props.url,"_blank")}},{id:"select-zoom-tool",readonlyOk:!0,kbd:"z",onSelect(P){var E,_;if(((E=t.root.getCurrent())==null?void 0:E.id)!=="zoom"&&(g("zoom-tool",{source:P}),!(t.inputs.shiftKey||t.inputs.ctrlKey))){const k=t.root.getCurrent();k&&((_=k.getCurrent())==null?void 0:_.id)==="idle"&&t.setCurrentTool("zoom",{onInteractionEnd:k.id,maskAs:"zoom"})}}},{id:"convert-to-bookmark",label:"action.convert-to-bookmark",onSelect(P){w()&&(S()||t.batch(()=>{g("convert-to-bookmark",{source:P});const E=t.getSelectedShapes(),_=[],k=[];for(const M of E){if(!M||!t.isShapeOfType(M,"embed")||!M.props.url)continue;const T=new b(M.x,M.y);T.rot(-M.rotation),T.add(new b(M.props.w/2-300/2,M.props.h/2-320/2)),T.rot(M.rotation);const R={id:We(),type:"bookmark",rotation:M.rotation,x:T.x,y:T.y,opacity:1,props:{url:M.props.url}};_.push(R),k.push(M.id)}t.mark("convert shapes to bookmark"),t.deleteShapes(k),t.createShapes(_)}))}},{id:"convert-to-embed",label:"action.convert-to-embed",onSelect(P){w()&&(S()||(g("convert-to-embed",{source:P}),t.batch(()=>{const E=t.getSelectedShapeIds(),_=ge(E.map(T=>t.getShape(T))),k=[],M=[];for(const T of _){if(!t.isShapeOfType(T,"bookmark"))continue;const{url:R}=T.props,O=Ao(T.props.url);if(!O||!O.definition)continue;const{width:U,height:N}=O.definition,L=new b(T.x,T.y);L.rot(-T.rotation),L.add(new b(T.props.w/2-U/2,T.props.h/2-N/2)),L.rot(T.rotation);const G={id:We(),type:"embed",x:L.x,y:L.y,rotation:T.rotation,props:{url:R,w:U,h:N}};k.push(G),M.push(T.id)}t.mark("convert shapes to embed"),t.deleteShapes(M),t.createShapes(k)})))}},{id:"duplicate",kbd:"$d",label:"action.duplicate",icon:"duplicate",onSelect(P){if(!w()||S())return;g("duplicate-shapes",{source:P});const E=t.getInstanceState();let _,k;if(E.duplicateProps)_=E.duplicateProps.shapeIds,k=E.duplicateProps.offset;else{_=t.getSelectedShapeIds();const M=ne.Common(ge(_.map(T=>t.getShapePageBounds(T))));k=E.canMoveCamera?{x:M.width+10,y:0}:{x:16/t.getZoomLevel(),y:16/t.getZoomLevel()}}t.mark("duplicate shapes"),t.duplicateShapes(_,k),E.duplicateProps&&t.updateInstanceState({duplicateProps:{...E.duplicateProps,shapeIds:t.getSelectedShapeIds()}})}},{id:"ungroup",label:"action.ungroup",kbd:"$!g",icon:"ungroup",onSelect(P){w()&&(S()||(g("ungroup-shapes",{source:P}),t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())))}},{id:"group",label:"action.group",kbd:"$g",icon:"group",onSelect(P){if(!w()||S())return;g("group-shapes",{source:P});const E=t.getOnlySelectedShape();E&&t.isShapeOfType(E,"group")?(t.mark("ungroup"),t.ungroupShapes(t.getSelectedShapeIds())):(t.mark("group"),t.groupShapes(t.getSelectedShapeIds()))}},{id:"remove-frame",label:"action.remove-frame",kbd:"$!f",onSelect(P){if(!w())return;g("remove-frame",{source:P});const E=t.getSelectedShapes();E.length>0&&E.every(_=>t.isShapeOfType(_,"frame"))&&(t.mark("remove-frame"),gq(t,E.map(_=>_.id)))}},{id:"fit-frame-to-content",label:"action.fit-frame-to-content",onSelect(P){if(!w())return;g("fit-frame-to-content",{source:P});const E=t.getOnlySelectedShape();E&&t.isShapeOfType(E,"frame")&&(t.mark("fit-frame-to-content"),yq(t,E.id))}},{id:"align-left",label:"action.align-left",kbd:"?A",icon:"align-left",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"left",source:P}),t.mark("align left"),t.alignShapes(t.getSelectedShapeIds(),"left")))}},{id:"align-center-horizontal",label:{default:"action.align-center-horizontal","context-menu":"action.align-center-horizontal.short"},kbd:"?H",icon:"align-center-horizontal",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"center-horizontal",source:P}),t.mark("align center horizontal"),t.alignShapes(t.getSelectedShapeIds(),"center-horizontal")))}},{id:"align-right",label:"action.align-right",kbd:"?D",icon:"align-right",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"right",source:P}),t.mark("align right"),t.alignShapes(t.getSelectedShapeIds(),"right")))}},{id:"align-center-vertical",label:{default:"action.align-center-vertical","context-menu":"action.align-center-vertical.short"},kbd:"?V",icon:"align-center-vertical",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"center-vertical",source:P}),t.mark("align center vertical"),t.alignShapes(t.getSelectedShapeIds(),"center-vertical")))}},{id:"align-top",label:"action.align-top",icon:"align-top",kbd:"?W",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"top",source:P}),t.mark("align top"),t.alignShapes(t.getSelectedShapeIds(),"top")))}},{id:"align-bottom",label:"action.align-bottom",icon:"align-bottom",kbd:"?S",onSelect(P){w()&&(S()||(g("align-shapes",{operation:"bottom",source:P}),t.mark("align bottom"),t.alignShapes(t.getSelectedShapeIds(),"bottom")))}},{id:"distribute-horizontal",label:{default:"action.distribute-horizontal","context-menu":"action.distribute-horizontal.short"},icon:"distribute-horizontal",kbd:"?!h",onSelect(P){w()&&(S()||(g("distribute-shapes",{operation:"horizontal",source:P}),t.mark("distribute horizontal"),t.distributeShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"distribute-vertical",label:{default:"action.distribute-vertical","context-menu":"action.distribute-vertical.short"},icon:"distribute-vertical",kbd:"?!V",onSelect(P){w()&&(S()||(g("distribute-shapes",{operation:"vertical",source:P}),t.mark("distribute vertical"),t.distributeShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"stretch-horizontal",label:{default:"action.stretch-horizontal","context-menu":"action.stretch-horizontal.short"},icon:"stretch-horizontal",onSelect(P){w()&&(S()||(g("stretch-shapes",{operation:"horizontal",source:P}),t.mark("stretch horizontal"),t.stretchShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"stretch-vertical",label:{default:"action.stretch-vertical","context-menu":"action.stretch-vertical.short"},icon:"stretch-vertical",onSelect(P){w()&&(S()||(g("stretch-shapes",{operation:"vertical",source:P}),t.mark("stretch vertical"),t.stretchShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"flip-horizontal",label:{default:"action.flip-horizontal","context-menu":"action.flip-horizontal.short"},kbd:"!h",onSelect(P){w()&&(S()||(g("flip-shapes",{operation:"horizontal",source:P}),t.mark("flip horizontal"),t.flipShapes(t.getSelectedShapeIds(),"horizontal")))}},{id:"flip-vertical",label:{default:"action.flip-vertical","context-menu":"action.flip-vertical.short"},kbd:"!v",onSelect(P){w()&&(S()||(g("flip-shapes",{operation:"vertical",source:P}),t.mark("flip vertical"),t.flipShapes(t.getSelectedShapeIds(),"vertical")))}},{id:"pack",label:"action.pack",icon:"pack",onSelect(P){w()&&(S()||(g("pack-shapes",{source:P}),t.mark("pack"),t.packShapes(t.getSelectedShapeIds(),16)))}},{id:"stack-vertical",label:{default:"action.stack-vertical","context-menu":"action.stack-vertical.short"},icon:"stack-vertical",onSelect(P){w()&&(S()||(g("stack-shapes",{operation:"vertical",source:P}),t.mark("stack-vertical"),t.stackShapes(t.getSelectedShapeIds(),"vertical",16)))}},{id:"stack-horizontal",label:{default:"action.stack-horizontal","context-menu":"action.stack-horizontal.short"},icon:"stack-horizontal",onSelect(P){w()&&(S()||(g("stack-shapes",{operation:"horizontal",source:P}),t.mark("stack-horizontal"),t.stackShapes(t.getSelectedShapeIds(),"horizontal",16)))}},{id:"bring-to-front",label:"action.bring-to-front",kbd:"]",icon:"bring-to-front",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"toFront",source:P}),t.mark("bring to front"),t.bringToFront(t.getSelectedShapeIds())))}},{id:"bring-forward",label:"action.bring-forward",icon:"bring-forward",kbd:"?]",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"forward",source:P}),t.mark("bring forward"),t.bringForward(t.getSelectedShapeIds())))}},{id:"send-backward",label:"action.send-backward",icon:"send-backward",kbd:"?[",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"backward",source:P}),t.mark("send backward"),t.sendBackward(t.getSelectedShapeIds())))}},{id:"send-to-back",label:"action.send-to-back",icon:"send-to-back",kbd:"[",onSelect(P){w()&&(S()||(g("reorder-shapes",{operation:"toBack",source:P}),t.mark("send to back"),t.sendToBack(t.getSelectedShapeIds())))}},{id:"cut",label:"action.cut",kbd:"$x",onSelect(P){w()&&(S()||(t.mark("cut"),c(P)))}},{id:"copy",label:"action.copy",kbd:"$c",readonlyOk:!0,onSelect(P){w()&&(S()||u(P))}},{id:"paste",label:"action.paste",kbd:"$v",onSelect(P){var E;(E=navigator.clipboard)==null||E.read().then(_=>{d(_,P,P==="context-menu"?t.inputs.currentPagePoint:void 0)})}},{id:"select-all",label:"action.select-all",kbd:"$a",readonlyOk:!0,onSelect(P){t.batch(()=>{S()||(g("select-all-shapes",{source:P}),t.mark("select all kbd"),t.selectAll())})}},{id:"select-none",label:"action.select-none",readonlyOk:!0,onSelect(P){w()&&(S()||(g("select-none-shapes",{source:P}),t.mark("select none"),t.selectNone()))}},{id:"delete",label:"action.delete",kbd:"⌫,del,backspace",icon:"trash",onSelect(P){w()&&(S()||(g("delete-shapes",{source:P}),t.mark("delete"),t.deleteShapes(t.getSelectedShapeIds())))}},{id:"rotate-cw",label:"action.rotate-cw",icon:"rotate-cw",onSelect(P){if(!w()||S())return;g("rotate-cw",{source:P}),t.mark("rotate-cw");const E=t.getSelectionRotation()%(Ke/2),_=ic(E,0)||ic(E,Ke/2);t.rotateShapesBy(t.getSelectedShapeIds(),Ke/2-(_?0:E))}},{id:"rotate-ccw",label:"action.rotate-ccw",icon:"rotate-ccw",onSelect(P){if(!w()||S())return;g("rotate-ccw",{source:P}),t.mark("rotate-ccw");const E=t.getSelectionRotation()%(Ke/2),_=ic(E,0);t.rotateShapesBy(t.getSelectedShapeIds(),_?-(Ke/2):-E)}},{id:"zoom-in",label:"action.zoom-in",kbd:"$=,=",readonlyOk:!0,onSelect(P){g("zoom-in",{source:P}),t.zoomIn(t.getViewportScreenCenter(),{duration:Mo})}},{id:"zoom-out",label:"action.zoom-out",kbd:"$-,-",readonlyOk:!0,onSelect(P){g("zoom-out",{source:P}),t.zoomOut(t.getViewportScreenCenter(),{duration:Mo})}},{id:"zoom-to-100",label:"action.zoom-to-100",icon:"reset-zoom",kbd:"!0",readonlyOk:!0,onSelect(P){g("reset-zoom",{source:P}),t.resetZoom(t.getViewportScreenCenter(),{duration:Mo})}},{id:"zoom-to-fit",label:"action.zoom-to-fit",kbd:"!1",readonlyOk:!0,onSelect(P){g("zoom-to-fit",{source:P}),t.zoomToFit({duration:Mo})}},{id:"zoom-to-selection",label:"action.zoom-to-selection",kbd:"!2",readonlyOk:!0,onSelect(P){w()&&(S()||(g("zoom-to-selection",{source:P}),t.zoomToSelection({duration:Mo})))}},{id:"toggle-snap-mode",label:{default:"action.toggle-snap-mode",menu:"action.toggle-snap-mode.menu"},onSelect(P){g("toggle-snap-mode",{source:P}),t.user.updateUserPreferences({isSnapMode:!t.user.getIsSnapMode()})},checkbox:!0},{id:"toggle-dark-mode",label:{default:"action.toggle-dark-mode",menu:"action.toggle-dark-mode.menu"},kbd:"$/",readonlyOk:!0,onSelect(P){g("toggle-dark-mode",{source:P}),t.user.updateUserPreferences({isDarkMode:!t.user.getIsDarkMode()})},checkbox:!0},{id:"toggle-wrap-mode",label:{default:"action.toggle-wrap-mode",menu:"action.toggle-wrap-mode.menu"},readonlyOk:!0,onSelect(P){g("toggle-wrap-mode",{source:P}),t.user.updateUserPreferences({isWrapMode:!t.user.getIsWrapMode()})},checkbox:!0},{id:"toggle-reduce-motion",label:{default:"action.toggle-reduce-motion",menu:"action.toggle-reduce-motion.menu"},readonlyOk:!0,onSelect(P){g("toggle-reduce-motion",{source:P}),t.user.updateUserPreferences({animationSpeed:t.user.getAnimationSpeed()===0?1:0})},checkbox:!0},{id:"toggle-edge-scrolling",label:{default:"action.toggle-edge-scrolling",menu:"action.toggle-edge-scrolling.menu"},readonlyOk:!0,onSelect(P){g("toggle-edge-scrolling",{source:P}),t.user.updateUserPreferences({edgeScrollSpeed:t.user.getEdgeScrollSpeed()===0?1:0})},checkbox:!0},{id:"toggle-transparent",label:{default:"action.toggle-transparent",menu:"action.toggle-transparent.menu","context-menu":"action.toggle-transparent.context-menu"},readonlyOk:!0,onSelect(P){g("toggle-transparent",{source:P}),t.updateInstanceState({exportBackground:!t.getInstanceState().exportBackground},{ephemeral:!0})},checkbox:!0},{id:"toggle-tool-lock",label:{default:"action.toggle-tool-lock",menu:"action.toggle-tool-lock.menu"},kbd:"q",onSelect(P){g("toggle-tool-lock",{source:P}),t.updateInstanceState({isToolLocked:!t.getInstanceState().isToolLocked})},checkbox:!0},{id:"unlock-all",label:"action.unlock-all",onSelect(P){g("unlock-all",{source:P});const E=[];for(const _ of t.getCurrentPageShapes())_.isLocked&&E.push({id:_.id,type:_.type,isLocked:!1});E.length>0&&t.updateShapes(E)}},{id:"toggle-focus-mode",label:{default:"action.toggle-focus-mode",menu:"action.toggle-focus-mode.menu"},readonlyOk:!0,kbd:"$.",checkbox:!0,onSelect(P){requestAnimationFrame(()=>{t.batch(()=>{g("toggle-focus-mode",{source:P}),o(),s(),t.updateInstanceState({isFocusMode:!t.getInstanceState().isFocusMode})})})}},{id:"toggle-grid",label:{default:"action.toggle-grid",menu:"action.toggle-grid.menu"},readonlyOk:!0,kbd:"$'",onSelect(P){g("toggle-grid-mode",{source:P}),t.updateInstanceState({isGridMode:!t.getInstanceState().isGridMode})},checkbox:!0},{id:"toggle-debug-mode",label:{default:"action.toggle-debug-mode",menu:"action.toggle-debug-mode.menu"},readonlyOk:!0,onSelect(P){g("toggle-debug-mode",{source:P}),t.updateInstanceState({isDebugMode:!t.getInstanceState().isDebugMode})},checkbox:!0},{id:"print",label:"action.print",kbd:"$p",readonlyOk:!0,onSelect(P){g("print",{source:P}),l()}},{id:"exit-pen-mode",label:"action.exit-pen-mode",icon:"cross-2",readonlyOk:!0,onSelect(P){g("exit-pen-mode",{source:P}),t.updateInstanceState({isPenMode:!1})}},{id:"stop-following",label:"action.stop-following",icon:"cross-2",readonlyOk:!0,onSelect(P){g("stop-following",{source:P}),t.stopFollowingUser()}},{id:"back-to-content",label:"action.back-to-content",icon:"arrow-left",readonlyOk:!0,onSelect(P){g("zoom-to-content",{source:P}),t.zoomToContent()}},{id:"toggle-lock",label:"action.toggle-lock",kbd:"!l",onSelect(P){t.mark("locking"),g("toggle-lock",{source:P}),t.toggleLock(t.getSelectedShapeIds())}},{id:"new-page",label:"context.pages.new-page",onSelect(P){const E=zo.createId(),_=t.getSelectedShapeIds();t.batch(()=>{t.mark("move_shapes_to_page"),t.createPage({name:i("page-menu.new-page-initial-name"),id:E}),t.moveShapesToPage(_,E)}),g("new-page",{source:P})}}]);return e?e(t,I,void 0):I},[t,g,e,r,a,f,h,c,u,d,o,s,l,i,y]);return p.jsx(VM.Provider,{value:v,children:n})}function le(){const e=x.useContext(VM);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function au(e,n){return e?typeof e=="string"?e:n?e[n]??e.default:void 0:void 0}const gZ=x.createContext(void 0);function qw(e){const n=x.useContext(gZ);return e||n||"ltr"}const ry="rovingFocusGroup.onEntryFocus",mZ={bubbles:!1,cancelable:!0},Zw="RovingFocusGroup",[mv,WM,yZ]=Wf(Zw),[SZ,GM]=go(Zw,[yZ]),[vZ,wZ]=SZ(Zw),xZ=x.forwardRef((e,n)=>x.createElement(mv.Provider,{scope:e.__scopeRovingFocusGroup},x.createElement(mv.Slot,{scope:e.__scopeRovingFocusGroup},x.createElement(bZ,Q({},e,{ref:n}))))),bZ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,orientation:r,loop:o=!1,dir:s,currentTabStopId:i,defaultCurrentTabStopId:a,onCurrentTabStopIdChange:l,onEntryFocus:c,...u}=e,d=x.useRef(null),h=Ye(n,d),f=qw(s),[y=null,g]=Ws({prop:i,defaultProp:a,onChange:l}),[v,S]=x.useState(!1),w=on(c),C=WM(t),I=x.useRef(!1),[P,E]=x.useState(0);return x.useEffect(()=>{const _=d.current;if(_)return _.addEventListener(ry,w),()=>_.removeEventListener(ry,w)},[w]),x.createElement(vZ,{scope:t,orientation:r,dir:f,loop:o,currentTabStopId:y,onItemFocus:x.useCallback(_=>g(_),[g]),onItemShiftTab:x.useCallback(()=>S(!0),[]),onFocusableItemAdd:x.useCallback(()=>E(_=>_+1),[]),onFocusableItemRemove:x.useCallback(()=>E(_=>_-1),[])},x.createElement(Be.div,Q({tabIndex:v||P===0?-1:0,"data-orientation":r},u,{ref:h,style:{outline:"none",...e.style},onMouseDown:se(e.onMouseDown,()=>{I.current=!0}),onFocus:se(e.onFocus,_=>{const k=!I.current;if(_.target===_.currentTarget&&k&&!v){const M=new CustomEvent(ry,mZ);if(_.currentTarget.dispatchEvent(M),!M.defaultPrevented){const T=C().filter(L=>L.focusable),R=T.find(L=>L.active),O=T.find(L=>L.id===y),N=[R,O,...T].filter(Boolean).map(L=>L.ref.current);YM(N)}}I.current=!1}),onBlur:se(e.onBlur,()=>S(!1))})))}),PZ="RovingFocusGroupItem",CZ=x.forwardRef((e,n)=>{const{__scopeRovingFocusGroup:t,focusable:r=!0,active:o=!1,tabStopId:s,...i}=e,a=Fo(),l=s||a,c=wZ(PZ,t),u=c.currentTabStopId===l,d=WM(t),{onFocusableItemAdd:h,onFocusableItemRemove:f}=c;return x.useEffect(()=>{if(r)return h(),()=>f()},[r,h,f]),x.createElement(mv.ItemSlot,{scope:t,id:l,focusable:r,active:o},x.createElement(Be.span,Q({tabIndex:u?0:-1,"data-orientation":c.orientation},i,{ref:n,onMouseDown:se(e.onMouseDown,y=>{r?c.onItemFocus(l):y.preventDefault()}),onFocus:se(e.onFocus,()=>c.onItemFocus(l)),onKeyDown:se(e.onKeyDown,y=>{if(y.key==="Tab"&&y.shiftKey){c.onItemShiftTab();return}if(y.target!==y.currentTarget)return;const g=_Z(y,c.orientation,c.dir);if(g!==void 0){y.preventDefault();let S=d().filter(w=>w.focusable).map(w=>w.ref.current);if(g==="last")S.reverse();else if(g==="prev"||g==="next"){g==="prev"&&S.reverse();const w=S.indexOf(y.currentTarget);S=c.loop?kZ(S,w+1):S.slice(w+1)}setTimeout(()=>YM(S))}})})))}),IZ={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"};function EZ(e,n){return n!=="rtl"?e:e==="ArrowLeft"?"ArrowRight":e==="ArrowRight"?"ArrowLeft":e}function _Z(e,n,t){const r=EZ(e.key,t);if(!(n==="vertical"&&["ArrowLeft","ArrowRight"].includes(r))&&!(n==="horizontal"&&["ArrowUp","ArrowDown"].includes(r)))return IZ[r]}function YM(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function kZ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}const TZ=xZ,$Z=CZ,yv=["Enter"," "],MZ=["ArrowDown","PageUp","Home"],XM=["ArrowUp","PageDown","End"],AZ=[...MZ,...XM],jZ={ltr:[...yv,"ArrowRight"],rtl:[...yv,"ArrowLeft"]},OZ={ltr:["ArrowLeft"],rtl:["ArrowRight"]},sg="Menu",[lu,DZ,RZ]=Wf(sg),[Bi,ig]=go(sg,[RZ,Jf,GM]),ag=Jf(),qM=GM(),[ZM,Ys]=Bi(sg),[LZ,Nu]=Bi(sg),NZ=e=>{const{__scopeMenu:n,open:t=!1,children:r,dir:o,onOpenChange:s,modal:i=!0}=e,a=ag(n),[l,c]=x.useState(null),u=x.useRef(!1),d=on(s),h=qw(o);return x.useEffect(()=>{const f=()=>{u.current=!0,document.addEventListener("pointerdown",y,{capture:!0,once:!0}),document.addEventListener("pointermove",y,{capture:!0,once:!0})},y=()=>u.current=!1;return document.addEventListener("keydown",f,{capture:!0}),()=>{document.removeEventListener("keydown",f,{capture:!0}),document.removeEventListener("pointerdown",y,{capture:!0}),document.removeEventListener("pointermove",y,{capture:!0})}},[]),x.createElement(Fw,a,x.createElement(ZM,{scope:n,open:t,onOpenChange:d,content:l,onContentChange:c},x.createElement(LZ,{scope:n,onClose:x.useCallback(()=>d(!1),[d]),isUsingKeyboardRef:u,dir:h,modal:i},r)))},QM=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e,o=ag(t);return x.createElement(cM,Q({},o,r,{ref:n}))}),JM="MenuPortal",[FZ,eA]=Bi(JM,{forceMount:void 0}),zZ=e=>{const{__scopeMenu:n,forceMount:t,children:r,container:o}=e,s=Ys(JM,n);return x.createElement(FZ,{scope:n,forceMount:t},x.createElement(mo,{present:t||s.open},x.createElement(Yf,{asChild:!0,container:o},r)))},zr="MenuContent",[BZ,Qw]=Bi(zr),UZ=x.forwardRef((e,n)=>{const t=eA(zr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=Ys(zr,e.__scopeMenu),i=Nu(zr,e.__scopeMenu);return x.createElement(lu.Provider,{scope:e.__scopeMenu},x.createElement(mo,{present:r||s.open},x.createElement(lu.Slot,{scope:e.__scopeMenu},i.modal?x.createElement(HZ,Q({},o,{ref:n})):x.createElement(KZ,Q({},o,{ref:n})))))}),HZ=x.forwardRef((e,n)=>{const t=Ys(zr,e.__scopeMenu),r=x.useRef(null),o=Ye(n,r);return x.useEffect(()=>{const s=r.current;if(s)return zw(s)},[]),x.createElement(Jw,Q({},e,{ref:o,trapFocus:t.open,disableOutsidePointerEvents:t.open,disableOutsideScroll:!0,onFocusOutside:se(e.onFocusOutside,s=>s.preventDefault(),{checkForDefaultPrevented:!1}),onDismiss:()=>t.onOpenChange(!1)}))}),KZ=x.forwardRef((e,n)=>{const t=Ys(zr,e.__scopeMenu);return x.createElement(Jw,Q({},e,{ref:n,trapFocus:!1,disableOutsidePointerEvents:!1,disableOutsideScroll:!1,onDismiss:()=>t.onOpenChange(!1)}))}),Jw=x.forwardRef((e,n)=>{const{__scopeMenu:t,loop:r=!1,trapFocus:o,onOpenAutoFocus:s,onCloseAutoFocus:i,disableOutsidePointerEvents:a,onEntryFocus:l,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:f,disableOutsideScroll:y,...g}=e,v=Ys(zr,t),S=Nu(zr,t),w=ag(t),C=qM(t),I=DZ(t),[P,E]=x.useState(null),_=x.useRef(null),k=Ye(n,_,v.onContentChange),M=x.useRef(0),T=x.useRef(""),R=x.useRef(0),O=x.useRef(null),U=x.useRef("right"),N=x.useRef(0),L=y?Bw:x.Fragment,G=y?{as:Ei,allowPinchZoom:!0}:void 0,X=B=>{var W,Y;const J=T.current+B,ke=I().filter(Ue=>!Ue.disabled),ve=document.activeElement,pe=(W=ke.find(Ue=>Ue.ref.current===ve))===null||W===void 0?void 0:W.textValue,me=ke.map(Ue=>Ue.textValue),Xe=oQ(me,J,pe),Ae=(Y=ke.find(Ue=>Ue.textValue===Xe))===null||Y===void 0?void 0:Y.ref.current;(function Ue(yt){T.current=yt,window.clearTimeout(M.current),yt!==""&&(M.current=window.setTimeout(()=>Ue(""),1e3))})(J),Ae&&setTimeout(()=>Ae.focus())};x.useEffect(()=>()=>window.clearTimeout(M.current),[]),Mw();const H=x.useCallback(B=>{var W,Y;return U.current===((W=O.current)===null||W===void 0?void 0:W.side)&&iQ(B,(Y=O.current)===null||Y===void 0?void 0:Y.area)},[]);return x.createElement(BZ,{scope:t,searchRef:T,onItemEnter:x.useCallback(B=>{H(B)&&B.preventDefault()},[H]),onItemLeave:x.useCallback(B=>{var W;H(B)||((W=_.current)===null||W===void 0||W.focus(),E(null))},[H]),onTriggerLeave:x.useCallback(B=>{H(B)&&B.preventDefault()},[H]),pointerGraceTimerRef:R,onPointerGraceIntentChange:x.useCallback(B=>{O.current=B},[])},x.createElement(L,G,x.createElement(Aw,{asChild:!0,trapped:o,onMountAutoFocus:se(s,B=>{var W;B.preventDefault(),(W=_.current)===null||W===void 0||W.focus()}),onUnmountAutoFocus:i},x.createElement(Gf,{asChild:!0,disableOutsidePointerEvents:a,onEscapeKeyDown:c,onPointerDownOutside:u,onFocusOutside:d,onInteractOutside:h,onDismiss:f},x.createElement(TZ,Q({asChild:!0},C,{dir:S.dir,orientation:"vertical",loop:r,currentTabStopId:P,onCurrentTabStopIdChange:E,onEntryFocus:se(l,B=>{S.isUsingKeyboardRef.current||B.preventDefault()})}),x.createElement(uM,Q({role:"menu","aria-orientation":"vertical","data-state":sA(v.open),"data-radix-menu-content":"",dir:S.dir},w,g,{ref:k,style:{outline:"none",...g.style},onKeyDown:se(g.onKeyDown,B=>{const Y=B.target.closest("[data-radix-menu-content]")===B.currentTarget,J=B.ctrlKey||B.altKey||B.metaKey,ke=B.key.length===1;Y&&(B.key==="Tab"&&B.preventDefault(),!J&&ke&&X(B.key));const ve=_.current;if(B.target!==ve||!AZ.includes(B.key))return;B.preventDefault();const me=I().filter(Xe=>!Xe.disabled).map(Xe=>Xe.ref.current);XM.includes(B.key)&&me.reverse(),nQ(me)}),onBlur:se(e.onBlur,B=>{B.currentTarget.contains(B.target)||(window.clearTimeout(M.current),T.current="")}),onPointerMove:se(e.onPointerMove,cu(B=>{const W=B.target,Y=N.current!==B.clientX;if(B.currentTarget.contains(W)&&Y){const J=B.clientX>N.current?"right":"left";U.current=J,N.current=B.clientX}}))})))))))}),VZ=x.forwardRef((e,n)=>{const{__scopeMenu:t,...r}=e;return x.createElement(Be.div,Q({role:"group"},r,{ref:n}))}),Sv="MenuItem",XC="menu.itemSelect",tA=x.forwardRef((e,n)=>{const{disabled:t=!1,onSelect:r,...o}=e,s=x.useRef(null),i=Nu(Sv,e.__scopeMenu),a=Qw(Sv,e.__scopeMenu),l=Ye(n,s),c=x.useRef(!1),u=()=>{const d=s.current;if(!t&&d){const h=new CustomEvent(XC,{bubbles:!0,cancelable:!0});d.addEventListener(XC,f=>r==null?void 0:r(f),{once:!0}),kw(d,h),h.defaultPrevented?c.current=!1:i.onClose()}};return x.createElement(nA,Q({},o,{ref:l,disabled:t,onClick:se(e.onClick,u),onPointerDown:d=>{var h;(h=e.onPointerDown)===null||h===void 0||h.call(e,d),c.current=!0},onPointerUp:se(e.onPointerUp,d=>{var h;c.current||(h=d.currentTarget)===null||h===void 0||h.click()}),onKeyDown:se(e.onKeyDown,d=>{const h=a.searchRef.current!=="";t||h&&d.key===" "||yv.includes(d.key)&&(d.currentTarget.click(),d.preventDefault())})}))}),nA=x.forwardRef((e,n)=>{const{__scopeMenu:t,disabled:r=!1,textValue:o,...s}=e,i=Qw(Sv,t),a=qM(t),l=x.useRef(null),c=Ye(n,l),[u,d]=x.useState(!1),[h,f]=x.useState("");return x.useEffect(()=>{const y=l.current;if(y){var g;f(((g=y.textContent)!==null&&g!==void 0?g:"").trim())}},[s.children]),x.createElement(lu.ItemSlot,{scope:t,disabled:r,textValue:o??h},x.createElement($Z,Q({asChild:!0},a,{focusable:!r}),x.createElement(Be.div,Q({role:"menuitem","data-highlighted":u?"":void 0,"aria-disabled":r||void 0,"data-disabled":r?"":void 0},s,{ref:c,onPointerMove:se(e.onPointerMove,cu(y=>{r?i.onItemLeave(y):(i.onItemEnter(y),y.defaultPrevented||y.currentTarget.focus())})),onPointerLeave:se(e.onPointerLeave,cu(y=>i.onItemLeave(y))),onFocus:se(e.onFocus,()=>d(!0)),onBlur:se(e.onBlur,()=>d(!1))}))))}),WZ=x.forwardRef((e,n)=>{const{checked:t=!1,onCheckedChange:r,...o}=e;return x.createElement(XZ,{scope:e.__scopeMenu,checked:t},x.createElement(tA,Q({role:"menuitemcheckbox","aria-checked":vv(t)?"mixed":t},o,{ref:n,"data-state":tQ(t),onSelect:se(o.onSelect,()=>r==null?void 0:r(vv(t)?!0:!t),{checkForDefaultPrevented:!1})})))}),GZ="MenuRadioGroup";Bi(GZ,{value:void 0,onValueChange:()=>{}});const YZ="MenuItemIndicator",[XZ,jne]=Bi(YZ,{checked:!1}),rA="MenuSub",[qZ,oA]=Bi(rA),ZZ=e=>{const{__scopeMenu:n,children:t,open:r=!1,onOpenChange:o}=e,s=Ys(rA,n),i=ag(n),[a,l]=x.useState(null),[c,u]=x.useState(null),d=on(o);return x.useEffect(()=>(s.open===!1&&d(!1),()=>d(!1)),[s.open,d]),x.createElement(Fw,i,x.createElement(ZM,{scope:n,open:r,onOpenChange:d,content:c,onContentChange:u},x.createElement(qZ,{scope:n,contentId:Fo(),triggerId:Fo(),trigger:a,onTriggerChange:l},t)))},qd="MenuSubTrigger",QZ=x.forwardRef((e,n)=>{const t=Ys(qd,e.__scopeMenu),r=Nu(qd,e.__scopeMenu),o=oA(qd,e.__scopeMenu),s=Qw(qd,e.__scopeMenu),i=x.useRef(null),{pointerGraceTimerRef:a,onPointerGraceIntentChange:l}=s,c={__scopeMenu:e.__scopeMenu},u=x.useCallback(()=>{i.current&&window.clearTimeout(i.current),i.current=null},[]);return x.useEffect(()=>u,[u]),x.useEffect(()=>{const d=a.current;return()=>{window.clearTimeout(d),l(null)}},[a,l]),x.createElement(QM,Q({asChild:!0},c),x.createElement(nA,Q({id:o.triggerId,"aria-haspopup":"menu","aria-expanded":t.open,"aria-controls":o.contentId,"data-state":sA(t.open)},e,{ref:Vf(n,o.onTriggerChange),onClick:d=>{var h;(h=e.onClick)===null||h===void 0||h.call(e,d),!(e.disabled||d.defaultPrevented)&&(d.currentTarget.focus(),t.open||t.onOpenChange(!0))},onPointerMove:se(e.onPointerMove,cu(d=>{s.onItemEnter(d),!d.defaultPrevented&&!e.disabled&&!t.open&&!i.current&&(s.onPointerGraceIntentChange(null),i.current=window.setTimeout(()=>{t.onOpenChange(!0),u()},100))})),onPointerLeave:se(e.onPointerLeave,cu(d=>{var h;u();const f=(h=t.content)===null||h===void 0?void 0:h.getBoundingClientRect();if(f){var y;const g=(y=t.content)===null||y===void 0?void 0:y.dataset.side,v=g==="right",S=v?-5:5,w=f[v?"left":"right"],C=f[v?"right":"left"];s.onPointerGraceIntentChange({area:[{x:d.clientX+S,y:d.clientY},{x:w,y:f.top},{x:C,y:f.top},{x:C,y:f.bottom},{x:w,y:f.bottom}],side:g}),window.clearTimeout(a.current),a.current=window.setTimeout(()=>s.onPointerGraceIntentChange(null),300)}else{if(s.onTriggerLeave(d),d.defaultPrevented)return;s.onPointerGraceIntentChange(null)}})),onKeyDown:se(e.onKeyDown,d=>{const h=s.searchRef.current!=="";if(!(e.disabled||h&&d.key===" ")&&jZ[r.dir].includes(d.key)){var f;t.onOpenChange(!0),(f=t.content)===null||f===void 0||f.focus(),d.preventDefault()}})})))}),JZ="MenuSubContent",eQ=x.forwardRef((e,n)=>{const t=eA(zr,e.__scopeMenu),{forceMount:r=t.forceMount,...o}=e,s=Ys(zr,e.__scopeMenu),i=Nu(zr,e.__scopeMenu),a=oA(JZ,e.__scopeMenu),l=x.useRef(null),c=Ye(n,l);return x.createElement(lu.Provider,{scope:e.__scopeMenu},x.createElement(mo,{present:r||s.open},x.createElement(lu.Slot,{scope:e.__scopeMenu},x.createElement(Jw,Q({id:a.contentId,"aria-labelledby":a.triggerId},o,{ref:c,align:"start",side:i.dir==="rtl"?"left":"right",disableOutsidePointerEvents:!1,disableOutsideScroll:!1,trapFocus:!1,onOpenAutoFocus:u=>{var d;i.isUsingKeyboardRef.current&&((d=l.current)===null||d===void 0||d.focus()),u.preventDefault()},onCloseAutoFocus:u=>u.preventDefault(),onFocusOutside:se(e.onFocusOutside,u=>{u.target!==a.trigger&&s.onOpenChange(!1)}),onEscapeKeyDown:se(e.onEscapeKeyDown,u=>{i.onClose(),u.preventDefault()}),onKeyDown:se(e.onKeyDown,u=>{const d=u.currentTarget.contains(u.target),h=OZ[i.dir].includes(u.key);if(d&&h){var f;s.onOpenChange(!1),(f=a.trigger)===null||f===void 0||f.focus(),u.preventDefault()}})})))))});function sA(e){return e?"open":"closed"}function vv(e){return e==="indeterminate"}function tQ(e){return vv(e)?"indeterminate":e?"checked":"unchecked"}function nQ(e){const n=document.activeElement;for(const t of e)if(t===n||(t.focus(),document.activeElement!==n))return}function rQ(e,n){return e.map((t,r)=>e[(n+r)%e.length])}function oQ(e,n,t){const o=n.length>1&&Array.from(n).every(c=>c===n[0])?n[0]:n,s=t?e.indexOf(t):-1;let i=rQ(e,Math.max(s,0));o.length===1&&(i=i.filter(c=>c!==t));const l=i.find(c=>c.toLowerCase().startsWith(o.toLowerCase()));return l!==t?l:void 0}function sQ(e,n){const{x:t,y:r}=e;let o=!1;for(let s=0,i=n.length-1;s<n.length;i=s++){const a=n[s].x,l=n[s].y,c=n[i].x,u=n[i].y;l>r!=u>r&&t<(c-a)*(r-l)/(u-l)+a&&(o=!o)}return o}function iQ(e,n){if(!n)return!1;const t={x:e.clientX,y:e.clientY};return sQ(t,n)}function cu(e){return n=>n.pointerType==="mouse"?e(n):void 0}const iA=NZ,aA=QM,lA=zZ,cA=UZ,uA=VZ,dA=tA,hA=WZ,pA=ZZ,fA=QZ,gA=eQ,mA="ContextMenu",[aQ,One]=go(mA,[ig]),vo=ig(),[lQ,yA]=aQ(mA),cQ=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,dir:o,modal:s=!0}=e,[i,a]=x.useState(!1),l=vo(n),c=on(r),u=x.useCallback(d=>{a(d),c(d)},[c]);return x.createElement(lQ,{scope:n,open:i,onOpenChange:u,modal:s},x.createElement(iA,Q({},l,{dir:o,open:i,onOpenChange:u,modal:s}),t))},uQ="ContextMenuTrigger",dQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,disabled:r=!1,...o}=e,s=yA(uQ,t),i=vo(t),a=x.useRef({x:0,y:0}),l=x.useRef({getBoundingClientRect:()=>DOMRect.fromRect({width:0,height:0,...a.current})}),c=x.useRef(0),u=x.useCallback(()=>window.clearTimeout(c.current),[]),d=h=>{a.current={x:h.clientX,y:h.clientY},s.onOpenChange(!0)};return x.useEffect(()=>u,[u]),x.useEffect(()=>void(r&&u()),[r,u]),x.createElement(x.Fragment,null,x.createElement(aA,Q({},i,{virtualRef:l})),x.createElement(Be.span,Q({"data-state":s.open?"open":"closed","data-disabled":r?"":void 0},o,{ref:n,style:{WebkitTouchCallout:"none",...e.style},onContextMenu:r?e.onContextMenu:se(e.onContextMenu,h=>{u(),d(h),h.preventDefault()}),onPointerDown:r?e.onPointerDown:se(e.onPointerDown,Zd(h=>{u(),c.current=window.setTimeout(()=>d(h),700)})),onPointerMove:r?e.onPointerMove:se(e.onPointerMove,Zd(u)),onPointerCancel:r?e.onPointerCancel:se(e.onPointerCancel,Zd(u)),onPointerUp:r?e.onPointerUp:se(e.onPointerUp,Zd(u))})))}),SA=e=>{const{__scopeContextMenu:n,...t}=e,r=vo(n);return x.createElement(lA,Q({},r,t))},hQ="ContextMenuContent",pQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=yA(hQ,t),s=vo(t),i=x.useRef(!1);return x.createElement(cA,Q({},s,r,{ref:n,side:"right",sideOffset:2,align:"start",onCloseAutoFocus:a=>{var l;(l=e.onCloseAutoFocus)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&i.current&&a.preventDefault(),i.current=!1},onInteractOutside:a=>{var l;(l=e.onInteractOutside)===null||l===void 0||l.call(e,a),!a.defaultPrevented&&!o.modal&&(i.current=!0)},style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),fQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(uA,Q({},o,r,{ref:n}))}),gQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(dA,Q({},o,r,{ref:n}))}),mQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(hA,Q({},o,r,{ref:n}))}),yQ=e=>{const{__scopeContextMenu:n,children:t,onOpenChange:r,open:o,defaultOpen:s}=e,i=vo(n),[a,l]=Ws({prop:o,defaultProp:s,onChange:r});return x.createElement(pA,Q({},i,{open:a,onOpenChange:l}),t)},SQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(fA,Q({},o,r,{ref:n}))}),vQ=x.forwardRef((e,n)=>{const{__scopeContextMenu:t,...r}=e,o=vo(t);return x.createElement(gA,Q({},o,r,{ref:n,style:{...e.style,"--radix-context-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-context-menu-content-available-width":"var(--radix-popper-available-width)","--radix-context-menu-content-available-height":"var(--radix-popper-available-height)","--radix-context-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-context-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))});function Zd(e){return n=>n.pointerType!=="mouse"?e(n):void 0}const wQ=cQ,xQ=dQ,bQ=SA,PQ=pQ,CQ=mQ,vA=typeof window>"u"?!1:window.navigator.userAgent.toLowerCase().indexOf("mac")>-1,IQ=vA?"⌘":"Ctrl",EQ=vA?"⌥":"Alt";function wA(e){return e.split(",")[0].split("").map(n=>{const t=n.replace(/\$/g,IQ).replace(/\?/g,EQ).replace(/!/g,"⇧");return t[0].toUpperCase()+t.slice(1)})}function uu(e){return"— "+wA(e).join(" ")}function _Q(e){return p.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",...e,children:p.jsxs("g",{strokeWidth:2,fill:"none",fillRule:"evenodd",children:[p.jsx("circle",{strokeOpacity:.25,cx:8,cy:8,r:7,stroke:"currentColor"}),p.jsx("path",{strokeLinecap:"round",d:"M15 8c0-4.5-4.5-7-7-7",stroke:"currentColor",children:p.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 8 8",to:"360 8 8",dur:"1s",repeatCount:"indefinite"})})]})})}const xA="DropdownMenu",[kQ,Dne]=go(xA,[ig]),wo=ig(),[TQ,bA]=kQ(xA),$Q=e=>{const{__scopeDropdownMenu:n,children:t,dir:r,open:o,defaultOpen:s,onOpenChange:i,modal:a=!0}=e,l=wo(n),c=x.useRef(null),[u=!1,d]=Ws({prop:o,defaultProp:s,onChange:i});return x.createElement(TQ,{scope:n,triggerId:Fo(),triggerRef:c,contentId:Fo(),open:u,onOpenChange:d,onOpenToggle:x.useCallback(()=>d(h=>!h),[d]),modal:a},x.createElement(iA,Q({},l,{open:u,onOpenChange:d,dir:r,modal:a}),t))},MQ="DropdownMenuTrigger",AQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,disabled:r=!1,...o}=e,s=bA(MQ,t),i=wo(t);return x.createElement(aA,Q({asChild:!0},i),x.createElement(Be.button,Q({type:"button",id:s.triggerId,"aria-haspopup":"menu","aria-expanded":s.open,"aria-controls":s.open?s.contentId:void 0,"data-state":s.open?"open":"closed","data-disabled":r?"":void 0,disabled:r},o,{ref:Vf(n,s.triggerRef),onPointerDown:se(e.onPointerDown,a=>{!r&&a.button===0&&a.ctrlKey===!1&&(s.onOpenToggle(),s.open||a.preventDefault())}),onKeyDown:se(e.onKeyDown,a=>{r||(["Enter"," "].includes(a.key)&&s.onOpenToggle(),a.key==="ArrowDown"&&s.onOpenChange(!0),["Enter"," ","ArrowDown"].includes(a.key)&&a.preventDefault())})})))}),jQ=e=>{const{__scopeDropdownMenu:n,...t}=e,r=wo(n);return x.createElement(lA,Q({},r,t))},OQ="DropdownMenuContent",DQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=bA(OQ,t),s=wo(t),i=x.useRef(!1);return x.createElement(cA,Q({id:o.contentId,"aria-labelledby":o.triggerId},s,r,{ref:n,onCloseAutoFocus:se(e.onCloseAutoFocus,a=>{var l;i.current||(l=o.triggerRef.current)===null||l===void 0||l.focus(),i.current=!1,a.preventDefault()}),onInteractOutside:se(e.onInteractOutside,a=>{const l=a.detail.originalEvent,c=l.button===0&&l.ctrlKey===!0,u=l.button===2||c;(!o.modal||u)&&(i.current=!0)}),style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),RQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(uA,Q({},o,r,{ref:n}))}),LQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(dA,Q({},o,r,{ref:n}))}),NQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(hA,Q({},o,r,{ref:n}))}),FQ=e=>{const{__scopeDropdownMenu:n,children:t,open:r,onOpenChange:o,defaultOpen:s}=e,i=wo(n),[a=!1,l]=Ws({prop:r,defaultProp:s,onChange:o});return x.createElement(pA,Q({},i,{open:a,onOpenChange:l}),t)},zQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(fA,Q({},o,r,{ref:n}))}),BQ=x.forwardRef((e,n)=>{const{__scopeDropdownMenu:t,...r}=e,o=wo(t);return x.createElement(gA,Q({},o,r,{ref:n,style:{...e.style,"--radix-dropdown-menu-content-transform-origin":"var(--radix-popper-transform-origin)","--radix-dropdown-menu-content-available-width":"var(--radix-popper-available-width)","--radix-dropdown-menu-content-available-height":"var(--radix-popper-available-height)","--radix-dropdown-menu-trigger-width":"var(--radix-popper-anchor-width)","--radix-dropdown-menu-trigger-height":"var(--radix-popper-anchor-height)"}}))}),ex=$Q,tx=AQ,lg=jQ,nx=DQ,UQ=RQ,HQ=LQ,KQ=NQ,VQ=FQ,WQ=zQ,GQ=BQ;function Ti({id:e,children:n,modal:t=!1,debugOpen:r=!1}){const[o,s]=Gs(e);return p.jsx(ex,{open:r||o,dir:"ltr",modal:t,onOpenChange:s,children:n})}function $i({children:e,...n}){return p.jsx(tx,{dir:"ltr",asChild:!0,onTouchEnd:t=>je(t),...n,children:e})}function Mi({side:e="bottom",align:n="start",sideOffset:t=8,alignOffset:r=8,children:o}){const s=mn();return p.jsx(lg,{container:s,children:p.jsx(nx,{className:"tlui-menu",side:e,sideOffset:t,align:n,alignOffset:r,collisionPadding:4,children:o})})}function YQ({id:e,children:n}){const[t,r]=Gs(e);return p.jsx(VQ,{open:t,onOpenChange:r,children:n})}function XQ({id:e,label:n,title:t,disabled:r}){return p.jsx(WQ,{dir:"ltr",asChild:!0,disabled:r,children:p.jsxs(he,{"data-testid":e,type:"menu",className:"tlui-menu__submenu__trigger",disabled:r,title:t,children:[p.jsx(mt,{children:n}),p.jsx(Ie,{icon:"chevron-right",small:!0})]})})}function qQ({id:e,alignOffset:n=-1,sideOffset:t=-4,size:r="small",children:o}){const s=mn();return p.jsx(lg,{container:s,children:p.jsx(GQ,{"data-testid":e,className:"tlui-menu tlui-menu__submenu__content",alignOffset:n,sideOffset:t,collisionPadding:4,"data-size":r,children:o})})}function ZQ({children:e}){return p.jsx(UQ,{dir:"ltr",className:"tlui-menu__group",children:e})}function du({noClose:e,children:n}){return p.jsx(HQ,{dir:"ltr",asChild:!0,onClick:e?je:void 0,children:n})}function wc({children:e,visibleOnMobileLayout:n=!1}){const t=Ln();return!n&&t<ht.MOBILE?null:p.jsx("kbd",{className:"tlui-kbd",children:wA(e).map((r,o)=>p.jsx("span",{children:r},o))})}function z({disabled:e=!1,spinner:n=!1,readonlyOk:t=!1,id:r,kbd:o,label:s,icon:i,onSelect:a,noClose:l}){const{type:c,sourceId:u}=tg(),d=Ee(),[h,f]=x.useState(!1);if(fo()&&!t)return null;const g=au(s,c),v=o?uu(o):void 0,S=g?d(g):void 0,w=S&&v?`${S} ${v}`:S;switch(c){case"menu":return p.jsx(du,{children:p.jsxs(he,{type:"menu","data-testid":`${u}.${r}`,disabled:e,title:w,onClick:C=>{l&&je(C),h?f(!1):a(u)},children:[p.jsx(mt,{children:S}),o&&p.jsx(wc,{children:o})]})});case"context-menu":return e?null:p.jsxs(gQ,{dir:"ltr",title:w,draggable:!1,className:"tlui-button tlui-button__menu","data-testid":`${u}.${r}`,onSelect:C=>{l&&je(C),h?f(!1):a(u)},children:[p.jsx("span",{className:"tlui-button__label",draggable:!1,children:S}),o&&p.jsx(wc,{children:o}),n&&p.jsx(_Q,{})]});case"panel":return p.jsxs(he,{"data-testid":`${u}.${r}`,type:"menu",title:w,disabled:e,onClick:()=>a(u),children:[p.jsx(mt,{children:S}),i&&p.jsx(Ie,{icon:i})]});case"small-icons":case"icons":return p.jsx(he,{"data-testid":`${u}.${r}`,type:"icon",title:w,disabled:e,onClick:()=>a(u),children:p.jsx(Ie,{icon:i,small:c==="small-icons"})});case"keyboard-shortcuts":return o?p.jsxs("div",{className:"tlui-shortcuts-dialog__key-pair","data-testid":`${u}.${r}`,children:[p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__key",children:S}),p.jsx("div",{className:"tlui-shortcuts-dialog__key-pair__value",children:p.jsx(wc,{visibleOnMobileLayout:!0,children:o})})]}):(console.warn(`Menu item '${s}' isn't shown in the keyboard shortcuts dialog because it doesn't have a keyboard shortcut.`),null);case"helper-buttons":return p.jsxs(he,{type:"low",onClick:()=>a(u),children:[p.jsx(Ie,{icon:i}),p.jsx(mt,{children:S})]});default:return null}}function QQ(){return p.jsxs(p.Fragment,{children:[p.jsx(JQ,{}),p.jsx(eJ,{}),p.jsx(tJ,{}),p.jsx(nJ,{}),p.jsx(rJ,{}),p.jsx(iJ,{}),p.jsx(aJ,{}),p.jsx(lJ,{})]})}function JQ(){const e=le(),n=an(2);return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["align-left"],disabled:!n}),p.jsx(z,{...e["align-center-horizontal"],disabled:!n}),p.jsx(z,{...e["align-right"],disabled:!n}),p.jsx(z,{...e["stretch-horizontal"],disabled:!n}),p.jsx(z,{...e["align-top"],disabled:!n}),p.jsx(z,{...e["align-center-vertical"],disabled:!n}),p.jsx(z,{...e["align-bottom"],disabled:!n}),p.jsx(z,{...e["stretch-vertical"],disabled:!n})]})}function eJ(){const e=le(),n=an(3);return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["distribute-horizontal"],disabled:!n}),p.jsx(z,{...e["distribute-vertical"],disabled:!n})]})}function tJ(){const e=le(),n=bk();return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["stack-horizontal"],disabled:!n}),p.jsx(z,{...e["stack-vertical"],disabled:!n})]})}function nJ(){const e=le(),n=an(1);return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["send-to-back"],disabled:!n}),p.jsx(z,{...e["send-backward"],disabled:!n}),p.jsx(z,{...e["bring-forward"],disabled:!n}),p.jsx(z,{...e["bring-to-front"],disabled:!n})]})}function rJ(){return Ln()<ht.TABLET_SM?p.jsx(oJ,{}):p.jsx(sJ,{})}function oJ(){const e=le(),n=F(),t=K("zoom is 1",()=>n.getZoomLevel()===1,[n]);return p.jsx(z,{...e["zoom-to-100"],disabled:t})}function sJ(){const e=le(),n=an(1);return p.jsx(z,{...e["rotate-ccw"],disabled:!n})}function iJ(){const e=le(),n=an(1);return p.jsx(z,{...e["rotate-cw"],disabled:!n})}function aJ(){const e=le(),n=Ik();return p.jsx(z,{...e["edit-link"],disabled:!n})}function lJ(){const e=Pk(),n=Ck();return e?p.jsx(qC,{}):n?p.jsx(cJ,{}):p.jsx(qC,{})}function qC(){const e=le(),n=an(2);return p.jsx(z,{...e.group,disabled:!n})}function cJ(){const e=le();return p.jsx(z,{...e.ungroup})}const uJ=x.memo(function({children:n}){const t=Ee(),r=Ln(),o=fo(),s=F(),i=K("should display quick actions when in readonly",()=>s.isInAny("hand","zoom"),[s]),a=n??p.jsx(QQ,{});if(!(o&&!i))return p.jsxs(Hw,{id:"actions-menu",children:[p.jsx(Kw,{children:p.jsx(he,{type:"icon","data-testid":"actions-menu.button",title:t("actions-menu.title"),children:p.jsx(Ie,{icon:"dots-vertical",small:!0})})}),p.jsx(Vw,{side:r>=ht.TABLET?"bottom":"top",sideOffset:6,children:p.jsx("div",{className:"tlui-actions-menu tlui-buttons__grid","data-testid":"actions-menu.content",children:p.jsx(So,{type:"icons",sourceId:"actions-menu",children:a})})})]})});function wr({id:e,kbd:n,label:t,readonlyOk:r,onSelect:o,disabled:s=!1,checked:i=!1}){const{type:a,sourceId:l}=tg(),c=fo(),u=Ee();if(c&&!r)return null;const d=au(t,a),h=d?u(d):void 0;switch(a){case"menu":return p.jsxs(KQ,{dir:"ltr",className:"tlui-button tlui-button__menu tlui-button__checkbox",title:h,onSelect:f=>{o==null||o(l),je(f)},disabled:s,checked:i,children:[p.jsx(Rs,{small:!0,icon:i?"check":"checkbox-empty"}),h&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:h}),n&&p.jsx(wc,{children:n})]});case"context-menu":return p.jsxs(CQ,{className:"tlui-button tlui-button__menu tlui-button__checkbox",dir:"ltr",title:h,onSelect:f=>{o(l),je(f)},disabled:s,checked:i,children:[p.jsx(Rs,{small:!0,icon:i?"check":"checkbox-empty"}),h&&p.jsx("span",{className:"tlui-button__label",draggable:!1,children:h}),n&&p.jsx(wc,{children:n})]},e);default:return null}}function we({id:e,label:n,children:t}){const{type:r,sourceId:o}=tg(),s=Ee(),i=au(n,r),a=i?s(i):void 0;switch(r){case"panel":return p.jsx("div",{className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"menu":return p.jsx(ZQ,{"data-testid":`${o}-group.${e}`,children:t});case"context-menu":return p.jsx(fQ,{dir:"ltr",className:"tlui-menu__group","data-testid":`${o}-group.${e}`,children:t});case"keyboard-shortcuts":return p.jsxs("div",{className:"tlui-shortcuts-dialog__group","data-testid":`${o}-group.${e}`,children:[p.jsx("h2",{className:"tlui-shortcuts-dialog__group__title",children:a}),p.jsx("div",{className:"tlui-shortcuts-dialog__group__content",children:t})]});default:return t}}function xr({id:e,disabled:n=!1,label:t,size:r="small",children:o}){const{type:s,sourceId:i}=tg(),a=mn(),l=Ee(),c=t?typeof t=="string"?t:t[s]??t.default:void 0,u=c?l(c):void 0;switch(s){case"menu":return p.jsxs(YQ,{id:`${i}-sub.${e}`,children:[p.jsx(XQ,{id:`${i}-sub.${u?u.toLowerCase()+"-button":""}`,disabled:n,label:u,title:u}),p.jsx(qQ,{id:`${i}-sub.${u?u.toLowerCase()+"-content":""}`,size:r,children:o})]});case"context-menu":return n?null:p.jsxs(dJ,{id:`${i}-sub.${e}`,children:[p.jsx(SQ,{dir:"ltr",disabled:n,asChild:!0,children:p.jsxs(he,{"data-testid":`${i}-sub-trigger.${e}`,type:"menu",className:"tlui-menu__submenu__trigger",children:[p.jsx(mt,{children:u}),p.jsx(Ie,{icon:"chevron-right",small:!0})]})}),p.jsx(SA,{container:a,children:p.jsx(vQ,{"data-testid":`${i}-sub-content.${e}`,className:"tlui-menu tlui-menu__submenu__content",alignOffset:-1,sideOffset:-4,collisionPadding:4,"data-size":r,children:o})})]});default:return o}}function dJ({id:e,children:n}){const[t,r]=Gs(e);return p.jsx(yQ,{open:t,onOpenChange:r,children:n})}function PA(){const e=le(),n=EU();return p.jsx(z,{...e["toggle-auto-size"],disabled:!n})}function CA(){const e=le(),n=Ik();return p.jsx(z,{...e["edit-link"],disabled:!n})}function hJ(){const e=le(),n=an(1);return p.jsx(z,{...e.duplicate,disabled:!n})}function IA(){const e=le(),n=Pk();return p.jsx(z,{...e.group,disabled:!n})}function EA(){const e=le(),n=Ck();return p.jsx(z,{...e.ungroup,disabled:!n})}function _A(){const e=F(),n=le(),t=K("allow unframe",()=>{const r=e.getSelectedShapes();return r.length===0?!1:r.every(o=>e.isShapeOfType(o,"frame"))},[e]);return p.jsx(z,{...n["remove-frame"],disabled:!t})}function kA(){const e=F(),n=le(),t=K("allow fit frame to content",()=>{const r=e.getOnlySelectedShape();return r?e.isShapeOfType(r,"frame")&&e.getSortedChildIdsForParent(r).length>0:!1},[e]);return p.jsx(z,{...n["fit-frame-to-content"],disabled:!t})}function TA(){const e=F(),n=le(),t=K("selected shapes",()=>e.getSelectedShapes().length>0,[e]);return p.jsx(z,{...n["toggle-lock"],disabled:!t})}function $A(){const e=le(),n=F(),t=K("isTransparentBg",()=>!n.getInstanceState().exportBackground,[n]);return p.jsx(wr,{...e["toggle-transparent"],checked:t})}function pJ(){const e=F(),n=le(),t=K("any shapes",()=>e.getCurrentPageShapeIds().size>0,[e]);return p.jsx(z,{...n["unlock-all"],disabled:!t})}function MA(){const e=F(),n=K("zoomed to 100",()=>e.getZoomLevel()===1,[e]),t=le();return p.jsx(z,{...t["zoom-to-100"],noClose:!0,disabled:n})}function AA(){const e=F(),n=K("has shapes",()=>e.getCurrentPageShapeIds().size>0,[e]),t=le();return p.jsx(z,{...t["zoom-to-fit"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-fit",noClose:!0})}function jA(){const e=F(),n=K("has shapes",()=>e.getSelectedShapeIds().length>0,[e]),t=le();return p.jsx(z,{...t["zoom-to-selection"],disabled:!n,"data-testid":"minimap.zoom-menu.zoom-to-selection",noClose:!0})}function OA(){var r;const e=F(),n=le(),t=K("atLeastOneShapeOnPage",()=>e.getCurrentPageShapeIds().size>0,[]);return p.jsxs(we,{id:"clipboard",children:[p.jsx(fJ,{}),p.jsx(gJ,{}),p.jsxs(xr,{id:"copy-as",label:"context-menu.copy-as",size:"small",disabled:!t,children:[p.jsxs(we,{id:"copy-as-group",children:[p.jsx(z,{...n["copy-as-svg"]}),!!((r=window.navigator.clipboard)!=null&&r.write)&&p.jsx(z,{...n["copy-as-png"]}),p.jsx(z,{...n["copy-as-json"]})]}),p.jsx(we,{id:"copy-as-bg",children:p.jsx($A,{})})]}),p.jsx(hJ,{}),p.jsx(mJ,{}),p.jsx(yJ,{})]})}function fJ(){const e=le(),n=an(1);return p.jsx(z,{...e.cut,disabled:!n})}function gJ(){const e=le(),n=IU(1);return p.jsx(z,{...e.copy,disabled:!n})}function mJ(){const e=le(),n=CU;return p.jsx(z,{...e.paste,disabled:!n})}function DA(){const e=le(),n=an(1);return p.jsx(we,{id:"conversions",children:p.jsxs(xr,{id:"export-as",label:"context-menu.export-as",size:"small",disabled:!n,children:[p.jsxs(we,{id:"export-as-group",children:[p.jsx(z,{...e["export-as-svg"]}),p.jsx(z,{...e["export-as-png"]}),p.jsx(z,{...e["export-as-json"]})]}),p.jsx(we,{id:"export-as-bg",children:p.jsx($A,{})})]})})}function RA(){const e=le(),n=F(),t=K("atLeastOneShapeOnPage",()=>n.getCurrentPageShapeIds().size>0,[n]);return p.jsx(we,{id:"set-selection-group",children:p.jsx(z,{...e["select-all"],disabled:!t})})}function yJ(){const e=le(),n=an(1);return p.jsx(z,{...e.delete,disabled:!n})}function SJ(){const e=an(2),n=_U(),t=le();return e||n?p.jsxs(xr,{id:"arrange",label:"context-menu.arrange",size:"small",children:[e&&p.jsxs(we,{id:"align",children:[p.jsx(z,{...t["align-left"]}),p.jsx(z,{...t["align-center-horizontal"]}),p.jsx(z,{...t["align-right"]}),p.jsx(z,{...t["align-top"]}),p.jsx(z,{...t["align-center-vertical"]}),p.jsx(z,{...t["align-bottom"]})]}),p.jsx(vJ,{}),e&&p.jsxs(we,{id:"stretch",children:[p.jsx(z,{...t["stretch-horizontal"]}),p.jsx(z,{...t["stretch-vertical"]})]}),n&&p.jsxs(we,{id:"flip",children:[p.jsx(z,{...t["flip-horizontal"]}),p.jsx(z,{...t["flip-vertical"]})]}),p.jsx(wJ,{})]}):null}function vJ(){const e=le();return an(3)?p.jsxs(we,{id:"distribute",children:[p.jsx(z,{...e["distribute-horizontal"]}),p.jsx(z,{...e["distribute-vertical"]})]}):null}function wJ(){const e=le(),n=an(2),t=bk();return n?p.jsxs(we,{id:"order",children:[p.jsx(z,{...e.pack}),t&&p.jsx(z,{...e["stack-horizontal"]}),t&&p.jsx(z,{...e["stack-vertical"]})]}):null}function xJ(){const e=le();return an(1)?p.jsx(xr,{id:"reorder",label:"context-menu.reorder",size:"small",children:p.jsxs(we,{id:"reorder",children:[p.jsx(z,{...e["bring-to-front"]}),p.jsx(z,{...e["bring-forward"]}),p.jsx(z,{...e["send-backward"]}),p.jsx(z,{...e["send-to-back"]})]})}):null}function bJ(){const e=F(),n=K("pages",()=>e.getPages(),[e]),t=K("current page id",()=>e.getCurrentPageId(),[e]),{addToast:r}=Wr(),o=le(),s=yo();return an(1)?p.jsxs(xr,{id:"move-to-page",label:"context-menu.move-to-page",size:"small",children:[p.jsx(we,{id:"pages",children:n.map(a=>p.jsx(z,{id:a.id,disabled:t===a.id,label:a.name,onSelect:()=>{e.mark("move_shapes_to_page"),e.moveShapesToPage(e.getSelectedShapeIds(),a.id);const l=e.getPage(a.id);l&&r({title:"Changed Page",description:`Moved to ${l.name}.`,actions:[{label:"Go Back",type:"primary",onClick:()=>{e.mark("change-page"),e.setCurrentPage(t)}}]}),s("move-to-page",{source:"context-menu"})},title:a.name},a.id))}),p.jsx(we,{id:"new-page",children:p.jsx(z,{...o["new-page"]})})]}):null}function LA(){const e=F(),n=le(),t=K("oneEmbedSelected",()=>{const o=e.getOnlySelectedShape();return o?!!(e.isShapeOfType(o,"embed")&&o.props.url&&!e.isShapeOrAncestorLocked(o)):!1},[e]),r=K("oneEmbeddableBookmarkSelected",()=>{const o=e.getOnlySelectedShape();return o?!!(e.isShapeOfType(o,"bookmark")&&o.props.url&&Ao(o.props.url)&&!e.isShapeOrAncestorLocked(o)):!1},[e]);return p.jsxs(we,{id:"embeds",children:[p.jsx(z,{...n["convert-to-bookmark"],disabled:!t}),p.jsx(z,{...n["convert-to-embed"],disabled:!r})]})}function PJ(){const e=le(),n=F(),t=K("isSnapMode",()=>n.user.getIsSnapMode(),[n]);return p.jsx(wr,{...e["toggle-snap-mode"],checked:t})}function CJ(){const e=le(),n=F(),t=K("isToolLock",()=>n.getInstanceState().isToolLocked,[n]);return p.jsx(wr,{...e["toggle-tool-lock"],checked:t})}function IJ(){const e=le(),n=F(),t=K("isGridMode",()=>n.getInstanceState().isGridMode,[n]);return p.jsx(wr,{...e["toggle-grid"],checked:t})}function EJ(){const e=le(),n=F(),t=K("isWrapMode",()=>n.user.getIsWrapMode(),[n]);return p.jsx(wr,{...e["toggle-wrap-mode"],checked:t})}function _J(){const e=le(),n=F(),t=K("isDarkMode",()=>n.user.getIsDarkMode(),[n]);return p.jsx(wr,{...e["toggle-dark-mode"],checked:t})}function kJ(){const e=le(),n=F(),t=K("isFocusMode",()=>n.getInstanceState().isFocusMode,[n]);return p.jsx(wr,{...e["toggle-focus-mode"],checked:t})}function TJ(){const e=le(),n=F(),t=K("edgeScrollSpeed",()=>n.user.getEdgeScrollSpeed(),[n]);return p.jsx(wr,{...e["toggle-edge-scrolling"],checked:t===1})}function $J(){const e=le(),n=F(),t=K("animationSpeed",()=>n.user.getAnimationSpeed(),[n]);return p.jsx(wr,{...e["toggle-reduce-motion"],checked:t===0})}function MJ(){const e=le(),n=F(),t=K("isDebugMode",()=>n.getInstanceState().isDebugMode,[n]);return p.jsx(wr,{...e["toggle-debug-mode"],checked:t})}function AJ(){const e=F();return K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e])?p.jsxs(p.Fragment,{children:[p.jsxs(we,{id:"selection",children:[p.jsx(PA,{}),p.jsx(CA,{}),p.jsx(IA,{}),p.jsx(EA,{}),p.jsx(_A,{}),p.jsx(kA,{}),p.jsx(TA,{})]}),p.jsx(LA,{}),p.jsxs(we,{id:"modify",children:[p.jsx(SJ,{}),p.jsx(xJ,{}),p.jsx(bJ,{})]}),p.jsx(OA,{}),p.jsx(DA,{}),p.jsx(RA,{})]}):null}const jJ=x.memo(function({children:n}){const t=F(),{Canvas:r}=Ge(),o=x.useCallback(c=>{if(c){if(t.getInstanceState().isCoarsePointer){const u=t.getSelectedShapes(),{inputs:{currentPagePoint:d}}=t,h=t.getShapesAtPoint(d);if(!t.getSelectedShapes().length||!h.some(f=>u.includes(f))){const f=h.filter(y=>t.isShapeOrAncestorLocked(y));f.length&&t.select(...f.map(y=>y.id))}}}else{const u=t.getOnlySelectedShape();u&&t.isShapeOrAncestorLocked(u)&&t.setSelectedShapes([])}},[t]),s=mn(),[i,a]=Gs("context menu",o),l=n??p.jsx(AJ,{});return p.jsxs(wQ,{dir:"ltr",onOpenChange:a,modal:!1,children:[p.jsx(xQ,{onContextMenu:void 0,dir:"ltr",children:r?p.jsx(r,{}):null}),i&&p.jsx(bQ,{container:s,children:p.jsx(PQ,{className:"tlui-menu scrollable","data-testid":"context-menu",alignOffset:-4,collisionPadding:4,onContextMenu:je,children:p.jsx(So,{type:"context-menu",sourceId:"context-menu",children:l})})})]})});function wv({checked:e}){return p.jsx(Rs,{icon:e?"check":"checkbox-empty",className:"tlui-button__icon",small:!0})}function OJ(){const e=F(),{addToast:n}=Wr(),{addDialog:t}=zi(),[r,o]=ie.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(we,{id:"items",children:[p.jsx(z,{id:"add-toast",onSelect:()=>{n({id:ze(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0}),n({id:ze(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]}),n({id:ze(),title:"Something happened",description:"Hey, attend to this thing over here. It might be important!",keepOpen:!0,icon:"twitter",actions:[{label:"Primary",type:"primary",onClick:()=>{}},{label:"Normal",type:"normal",onClick:()=>{}},{label:"Danger",type:"danger",onClick:()=>{}}]})},label:"Show toast"}),p.jsx(z,{id:"show-dialog",label:"Show dialog",onSelect:()=>{t({component:({onClose:s})=>p.jsx(LJ,{displayDontShowAgain:!0,onCancel:()=>s(),onContinue:()=>s()}),onClose:()=>{}})}}),p.jsx(z,{id:"create-shapes",label:"Create 100 shapes",onSelect:()=>NJ(e,100)}),p.jsx(z,{id:"count-nodes",label:"Count shapes / nodes",onSelect:()=>{function s({children:u}){let d=0;if(!u.length)return 0;for(const h of[...u])d++,d+=s(h);return d}const i=e.getSelectedShapes(),a=i.length===0?e.getRenderingShapes():i,l=a.map(u=>document.getElementById(u.id).parentElement);let c=l.length;for(const u of l)c+=s(u);window.alert(`Shapes ${a.length}, DOM nodes:${c}`)}}),(()=>{if(r)throw Error("oh no!")})(),p.jsx(z,{id:"throw-error",onSelect:()=>o(!0),label:"Throw error"}),p.jsx(z,{id:"hard-reset",onSelect:qE,label:"Hard reset"})]}),p.jsxs(we,{id:"flags",children:[p.jsx(DJ,{}),p.jsx(RJ,{})]})]})}function DJ(){const e=Object.values(Ft);return e.length?p.jsx(xr,{id:"debug flags",label:"Debug Flags",children:p.jsx(we,{id:"debug flags",children:e.map(n=>p.jsx(NA,{flag:n},n.name))})}):null}function RJ(){const e=Object.values(XR);return e.length?p.jsx(xr,{id:"feature flags",label:"Feature Flags",children:p.jsx(we,{id:"feature flags",children:e.map(n=>p.jsx(NA,{flag:n},n.name))})}):null}function LJ({title:e="title",body:n="hello hello hello",cancel:t="Cancel",confirm:r="Continue",displayDontShowAgain:o=!1,onCancel:s,onContinue:i}){const[a,l]=ie.useState(!1);return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{children:[p.jsx(rg,{children:e}),p.jsx(og,{})]}),p.jsx(iu,{style:{maxWidth:350},children:n}),p.jsxs(Ww,{className:"tlui-dialog__footer__actions",children:[o&&p.jsxs(he,{type:"normal",onClick:()=>l(!a),style:{marginRight:"auto"},children:[p.jsx(wv,{checked:a}),p.jsx(mt,{children:"Don't show again"})]}),p.jsx(he,{type:"normal",onClick:s,children:p.jsx(mt,{children:t})}),p.jsx(he,{type:"primary",onClick:async()=>i(),children:p.jsx(mt,{children:r})})]})]})}const NA=Tt(function({flag:n,onChange:t}){const r=n.get();return p.jsx(wr,{id:n.name,title:n.name,label:n.name.replace(/([a-z0-9])([A-Z])/g,o=>`${o[0]} ${o[1].toLowerCase()}`).replace(/^[a-z]/,o=>o.toUpperCase()),checked:r,onSelect:()=>{n.set(!r),t==null||t(!r)}})});let ZC=0;function NJ(e,n){const t=Array(n),r=Math.floor(Math.sqrt(n));for(let o=0;o<n;o++)ZC++,t[o]={id:We("box"+ZC),type:"geo",x:o%r*132,y:Math.floor(o/r)*132};e.batch(()=>{e.createShapes(t).setSelectedShapes(t.map(o=>o.id))})}function FJ({children:e}){const n=e??p.jsx(OJ,{});return p.jsxs(Ti,{id:"debug",children:[p.jsx($i,{children:p.jsx(he,{type:"icon",title:"Debug menu",children:p.jsx(Ie,{icon:"dots-horizontal"})})}),p.jsx(Mi,{side:"top",align:"end",alignOffset:0,children:p.jsx(So,{type:"menu",sourceId:"debug-panel",children:n})})]})}function zJ(){const e=F();return{languages:_c,currentLanguage:e.user.getLocale()}}const FA=Tt(function(){const n=F(),t=yo(),{languages:r,currentLanguage:o}=zJ();return p.jsx(xr,{id:"help menu language",label:"menu.language",children:p.jsx(we,{id:"languages",children:r.map(({locale:s,label:i})=>p.jsx(wr,{id:`language-${s}`,title:s,label:i,checked:s===o,onSelect:()=>{n.user.updateUserPreferences({locale:s}),t("change-language",{source:"menu",locale:s})}},s))})})});function BJ(){return p.jsxs(p.Fragment,{children:[p.jsx(FA,{}),p.jsx(UJ,{})]})}function UJ(){const{KeyboardShortcutsDialog:e}=Xs(),{addDialog:n}=zi();return e?p.jsx(z,{id:"keyboard-shortcuts-button",label:"help-menu.keyboard-shortcuts",readonlyOk:!0,onSelect:()=>{n({component:e})}}):null}const HJ=x.memo(function({children:n}){const t=Ee(),r=Ln(),o=n??p.jsx(BJ,{});return r<ht.MOBILE?null:p.jsx("div",{className:"tlui-help-menu",children:p.jsxs(Ti,{id:"help menu",children:[p.jsx($i,{children:p.jsx(he,{type:"help",title:t("help-menu.title"),"data-testid":"help-menu.button",children:p.jsx(Ie,{icon:"question-mark",small:!0})})}),p.jsx(Mi,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:p.jsx(So,{type:"menu",sourceId:"help-menu",children:o})})]})})});function KJ(){const e=F(),n=le(),[t,r]=x.useState(!1);return x.useEffect(()=>{let o=!1;const s=setInterval(()=>{const i=e.getRenderingShapes(),a=e.getRenderingBounds(),c=i.filter(u=>u.maskedPageBounds&&a.includes(u.maskedPageBounds)).length===0&&e.getCurrentPageShapes().length>0;o!==c&&(r(c),o=c)},1e3);return()=>{clearInterval(s)}},[e]),t?p.jsx(z,{...n["back-to-content"],onSelect:()=>{n["back-to-content"].onSelect("helper-buttons"),r(!1)}}):null}function VJ(){const e=F(),n=le();return K("is pen mode",()=>e.getInstanceState().isPenMode,[e])?p.jsx(z,{...n["exit-pen-mode"]}):null}function WJ(){const e=F(),n=le();return K("is following user",()=>!!e.getInstanceState().followingUserId,[e])?p.jsx(z,{...n["stop-following"]}):null}function GJ(){return p.jsxs(p.Fragment,{children:[p.jsx(VJ,{}),p.jsx(KJ,{}),p.jsx(WJ,{})]})}function YJ({children:e}){const n=e??p.jsx(GJ,{});return p.jsx("div",{className:"tlui-helper-buttons",children:p.jsx(So,{type:"helper-buttons",sourceId:"helper-buttons",children:n})})}const zA=x.createContext({});function XJ({overrides:e,children:n}){const t=F(),r=yo(),{addDialog:o}=zi(),s=HM(),i=x.useMemo(()=>{const a=[{id:"select",label:"tool.select",icon:"tool-pointer",kbd:"v",readonlyOk:!0,onSelect(c){t.setCurrentTool("select"),r("select-tool",{source:c,id:"select"})}},{id:"hand",label:"tool.hand",icon:"tool-hand",kbd:"h",readonlyOk:!0,onSelect(c){t.setCurrentTool("hand"),r("select-tool",{source:c,id:"hand"})}},{id:"eraser",label:"tool.eraser",icon:"tool-eraser",kbd:"e",onSelect(c){t.setCurrentTool("eraser"),r("select-tool",{source:c,id:"eraser"})}},{id:"draw",label:"tool.draw",icon:"tool-pencil",kbd:"d,b,x",onSelect(c){t.setCurrentTool("draw"),r("select-tool",{source:c,id:"draw"})}},...[...so.values].map(c=>({id:c,label:`tool.${c}`,meta:{geo:c},kbd:c==="rectangle"?"r":c==="ellipse"?"o":void 0,icon:"geo-"+c,onSelect(u){t.batch(()=>{t.updateInstanceState({stylesForNextShape:{...t.getInstanceState().stylesForNextShape,[so.id]:c}},{ephemeral:!0}),t.setCurrentTool("geo"),r("select-tool",{source:u,id:`geo-${c}`})})}})),{id:"arrow",label:"tool.arrow",icon:"tool-arrow",kbd:"a",onSelect(c){t.setCurrentTool("arrow"),r("select-tool",{source:c,id:"arrow"})}},{id:"line",label:"tool.line",icon:"tool-line",kbd:"l",onSelect(c){t.setCurrentTool("line"),r("select-tool",{source:c,id:"line"})}},{id:"frame",label:"tool.frame",icon:"tool-frame",kbd:"f",onSelect(c){t.setCurrentTool("frame"),r("select-tool",{source:c,id:"frame"})}},{id:"text",label:"tool.text",icon:"tool-text",kbd:"t",onSelect(c){t.setCurrentTool("text"),r("select-tool",{source:c,id:"text"})}},{id:"asset",label:"tool.asset",icon:"tool-media",kbd:"$u",onSelect(c){s(),r("select-tool",{source:c,id:"media"})}},{id:"note",label:"tool.note",icon:"tool-note",kbd:"n",onSelect(c){t.setCurrentTool("note"),r("select-tool",{source:c,id:"note"})}},{id:"laser",label:"tool.laser",readonlyOk:!0,icon:"tool-laser",kbd:"k",onSelect(c){t.setCurrentTool("laser"),r("select-tool",{source:c,id:"laser"})}},{id:"embed",label:"tool.embed",icon:"tool-embed",onSelect(c){o({component:OM}),r("select-tool",{source:c,id:"embed"})}}];a.push({id:"highlight",label:"tool.highlight",icon:"tool-highlight",kbd:"!d",onSelect(c){t.setCurrentTool("highlight"),r("select-tool",{source:c,id:"highlight"})}});const l=Object.fromEntries(a.map(c=>[c.id,c]));return e?e(t,l,{insertMedia:s}):l},[e,t,r,s,o]);return p.jsx(zA.Provider,{value:i,children:n})}function rx(){const e=x.useContext(zA);if(!e)throw new Error("useTools must be used within a ToolProvider");return e}function qJ(){const e=le(),n=rx();return p.jsxs(p.Fragment,{children:[p.jsxs(we,{label:"shortcuts-dialog.tools",id:"tools",children:[p.jsx(z,{...e["toggle-tool-lock"]}),p.jsx(z,{...n.select}),p.jsx(z,{...n.draw}),p.jsx(z,{...n.eraser}),p.jsx(z,{...n.hand}),p.jsx(z,{...n.rectangle}),p.jsx(z,{...n.ellipse}),p.jsx(z,{...n.arrow}),p.jsx(z,{...n.line}),p.jsx(z,{...n.text}),p.jsx(z,{...n.frame}),p.jsx(z,{...n.note}),p.jsx(z,{...n.laser})]}),p.jsxs(we,{label:"shortcuts-dialog.file",id:"file",children:[p.jsx(z,{...e["insert-media"]}),p.jsx(z,{...e.print})]}),p.jsxs(we,{label:"shortcuts-dialog.preferences",id:"preferences",children:[p.jsx(z,{...e["toggle-dark-mode"]}),p.jsx(z,{...e["toggle-focus-mode"]}),p.jsx(z,{...e["toggle-grid"]})]}),p.jsxs(we,{label:"shortcuts-dialog.edit",id:"edit",children:[p.jsx(z,{...e.undo}),p.jsx(z,{...e.redo}),p.jsx(z,{...e.cut}),p.jsx(z,{...e.copy}),p.jsx(z,{...e.paste}),p.jsx(z,{...e["select-all"]}),p.jsx(z,{...e.delete}),p.jsx(z,{...e.duplicate})]}),p.jsxs(we,{label:"shortcuts-dialog.view",id:"view",children:[p.jsx(z,{...e["zoom-in"]}),p.jsx(z,{...e["zoom-out"]}),p.jsx(z,{...e["zoom-to-100"]}),p.jsx(z,{...e["zoom-to-fit"]}),p.jsx(z,{...e["zoom-to-selection"]})]}),p.jsxs(we,{label:"shortcuts-dialog.transform",id:"transform",children:[p.jsx(z,{...e["bring-to-front"]}),p.jsx(z,{...e["bring-forward"]}),p.jsx(z,{...e["send-backward"]}),p.jsx(z,{...e["send-to-back"]}),p.jsx(z,{...e.group}),p.jsx(z,{...e.ungroup}),p.jsx(z,{...e["flip-horizontal"]}),p.jsx(z,{...e["flip-vertical"]}),p.jsx(z,{...e["align-top"]}),p.jsx(z,{...e["align-center-vertical"]}),p.jsx(z,{...e["align-bottom"]}),p.jsx(z,{...e["align-left"]}),p.jsx(z,{...e["align-center-horizontal"]}),p.jsx(z,{...e["align-right"]})]})]})}const ZJ=x.memo(function({children:n}){const t=Ee(),r=Ln(),o=n??p.jsx(qJ,{});return p.jsxs(p.Fragment,{children:[p.jsxs(ng,{className:"tlui-shortcuts-dialog__header",children:[p.jsx(rg,{children:t("shortcuts-dialog.title")}),p.jsx(og,{})]}),p.jsx(iu,{className:fe("tlui-shortcuts-dialog__body",{"tlui-shortcuts-dialog__body__mobile":r<=ht.MOBILE_XS,"tlui-shortcuts-dialog__body__tablet":r<=ht.TABLET}),children:p.jsx(So,{type:"keyboard-shortcuts",sourceId:"kbd",children:o})}),p.jsx("div",{className:"tlui-dialog__scrim"})]})});function QJ(){return p.jsxs(p.Fragment,{children:[p.jsx(JJ,{}),p.jsx(eee,{}),p.jsx(see,{}),p.jsx(iee,{}),p.jsx(aee,{})]})}function JJ(){const e=F(),n=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return p.jsxs(xr,{id:"edit",label:"menu.edit",disabled:!n,children:[p.jsx(oee,{}),p.jsx(OA,{}),p.jsx(RA,{})]})}function eee(){const e=F(),n=K("isSelectToolActive",()=>e.getCurrentToolId()==="select",[e]);return p.jsxs(xr,{id:"shape",label:"menu.shape",disabled:!n,children:[p.jsx(DA,{}),p.jsx(ree,{}),p.jsx(tee,{}),p.jsx(LA,{}),p.jsx(nee,{})]})}function tee(){return p.jsxs(we,{id:"misc",children:[p.jsx(PA,{}),p.jsx(CA,{})]})}function nee(){return p.jsxs(we,{id:"lock",children:[p.jsx(TA,{}),p.jsx(pJ,{})]})}function ree(){return p.jsxs(we,{id:"multi-shape",children:[p.jsx(IA,{}),p.jsx(EA,{}),p.jsx(_A,{}),p.jsx(kA,{})]})}function oee(){const e=le(),n=_k(),t=Ek();return p.jsxs(we,{id:"undo-redo",children:[p.jsx(z,{...e.undo,disabled:!n}),p.jsx(z,{...e.redo,disabled:!t})]})}function see(){const e=le();return p.jsx(xr,{id:"view",label:"menu.view",children:p.jsxs(we,{id:"view-actions",children:[p.jsx(z,{...e["zoom-in"]}),p.jsx(z,{...e["zoom-out"]}),p.jsx(MA,{}),p.jsx(AA,{}),p.jsx(jA,{})]})})}function iee(){const e=le();return p.jsxs(we,{id:"extras",children:[p.jsx(z,{...e["insert-embed"]}),p.jsx(z,{...e["insert-media"]})]})}function aee(){return p.jsx(we,{id:"preferences",children:p.jsxs(xr,{id:"preferences",label:"menu.preferences",children:[p.jsxs(we,{id:"preferences-actions",children:[p.jsx(PJ,{}),p.jsx(CJ,{}),p.jsx(IJ,{}),p.jsx(EJ,{}),p.jsx(_J,{}),p.jsx(kJ,{}),p.jsx(TJ,{}),p.jsx($J,{}),p.jsx(MJ,{})]}),p.jsx(we,{id:"language",children:p.jsx(FA,{})})]})})}const lee=x.memo(function({children:n}){const t=mn(),[r,o]=Gs("main menu"),s=Ee(),i=n??p.jsx(QJ,{});return p.jsxs(ex,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[p.jsx(tx,{asChild:!0,dir:"ltr",children:p.jsx(he,{type:"icon","data-testid":"main-menu.button",title:s("menu.title"),children:p.jsx(Ie,{icon:"menu",small:!0})})}),p.jsx(lg,{container:t,children:p.jsx(nx,{className:"tlui-menu",side:"bottom",align:"start",collisionPadding:4,alignOffset:0,sideOffset:6,children:p.jsx(So,{type:"menu",sourceId:"main-menu",children:i})})})]})}),cee=x.memo(function(){const n=Ln(),{MainMenu:t,QuickActions:r,ActionsMenu:o,PageMenu:s}=Xs();return!t&&!s&&n<6?null:p.jsx("div",{className:"tlui-menu-zone",children:p.jsxs("div",{className:"tlui-buttons__horizontal",children:[t&&p.jsx(t,{}),s&&p.jsx(s,{}),n<6?null:p.jsxs(p.Fragment,{children:[r&&p.jsx(r,{}),o&&p.jsx(o,{})]})]})})});class xc{constructor(n){m(this,"dpr",1);m(this,"colors",{shapeFill:"rgba(144, 144, 144, .1)",selectFill:"#2f80ed",viewportFill:"rgba(144, 144, 144, .1)"});m(this,"id",ze());m(this,"cvs",null);m(this,"pageBounds",[]);m(this,"collaborators",[]);m(this,"canvasScreenBounds",new ne);m(this,"canvasPageBounds",new ne);m(this,"contentPageBounds",new ne);m(this,"contentScreenBounds",new ne);m(this,"originPagePoint",new b);m(this,"originPageCenter",new b);m(this,"isInViewport",!1);m(this,"debug",!1);m(this,"updateContentScreenBounds",()=>{const{contentScreenBounds:n,contentPageBounds:t,canvasScreenBounds:r}=this;let{x:o,y:s,w:i,h:a}=n;if(t.w>t.h){const l=r.w/(t.w/t.h);l>r.h?(o=(r.w-r.w*(r.h/l))/2,s=0,i=r.w*(r.h/l),a=r.h):(o=0,s=(r.h-l)/2,i=r.w,a=l)}else if(t.w<t.h){const l=r.h/(t.h/t.w);o=(r.w-l)/2,s=0,i=l,a=r.h}else o=r.h/2,s=0,i=r.h,a=r.h;n.set(o,s,i,a)});m(this,"updateCanvasPageBounds",()=>{const{canvasPageBounds:n,canvasScreenBounds:t,contentPageBounds:r,contentScreenBounds:o}=this;n.set(0,0,r.width/(o.width/t.width),r.height/(o.height/t.height)),n.center=r.center});m(this,"getScreenPoint",(n,t)=>{const{canvasScreenBounds:r}=this,o=(n-r.minX)*this.dpr,s=(t-r.minY)*this.dpr;return{x:o,y:s}});m(this,"getPagePoint",(n,t)=>{const{contentPageBounds:r,contentScreenBounds:o,canvasPageBounds:s}=this,{x:i,y:a}=this.getScreenPoint(n,t);return new b(s.minX+i*r.width/o.width,s.minY+a*r.height/o.height,1)});m(this,"minimapScreenPointToPagePoint",(n,t,r=!1,o=!1)=>{const{editor:s}=this,i=s.getViewportPageBounds();let{x:a,y:l}=this.getPagePoint(n,t);if(o){const c=this.editor.getCurrentPageBounds(),u=i,d=((c==null?void 0:c.minX)??0)-u.width/2,h=((c==null?void 0:c.maxX)??0)+u.width/2,f=((c==null?void 0:c.minY)??0)-u.height/2,y=((c==null?void 0:c.maxY)??0)+u.height/2,g=Math.max(0,d+u.width-a),v=Math.max(0,-(h-u.width-a)),S=Math.max(0,f+u.height-l),w=Math.max(0,-(y-u.height-l)),C=Math.max(0,g-v),I=Math.max(0,v-g),P=Math.max(0,S-w),E=Math.max(0,w-S);C&&C>I?a+=C/2:I&&(a-=I/2),P&&P>E?l+=P/2:E&&(l-=E/2),a=ar(a,d,h),l=ar(l,f,y)}if(r){const{originPagePoint:c}=this,u=Math.abs(a-c.x),d=Math.abs(l-c.y);u>d?l=c.y:a=c.x}return new b(a,l)});m(this,"updateColors",()=>{const n=getComputedStyle(this.editor.getContainer());this.colors={shapeFill:n.getPropertyValue("--color-text-3").trim(),selectFill:n.getPropertyValue("--color-selected").trim(),viewportFill:n.getPropertyValue("--color-muted-1").trim()}});m(this,"render",()=>{const{cvs:n,pageBounds:t}=this;this.updateCanvasPageBounds();const{editor:r,canvasScreenBounds:o,canvasPageBounds:s,contentPageBounds:i,contentScreenBounds:a}=this,{width:l,height:c}=o,u=r.getSelectedShapeIds(),d=r.getViewportPageBounds();if(!n||!t)return;const h=n.getContext("2d");if(!h)throw new Error("Minimap (shapes): Could not get context");h.resetTransform(),h.globalAlpha=1,h.clearRect(0,0,l,c);const f=a.width/i.width,y=a.height/i.height;h.translate((l-a.width)/2,(c-a.height)/2),h.scale(f,y),h.translate(-i.minX,-i.minY);const g=8/f,v=8/f,S=1/f,w=1/f,C=g/4,I=v/4,P=new Path2D,E=new Path2D,{shapeFill:_,selectFill:k,viewportFill:M}=this.colors;let T;for(let L=0,G=t.length;L<G;L++)T=t[L],xc.roundedRect(u.includes(T.id)?E:P,T.minX,T.minY,T.width,T.height,ar(g,S,T.width/C),ar(v,w,T.height/I));if(h.fillStyle=_,h.fill(P),h.fillStyle=k,h.fill(E),this.debug){const L=ne.Common(t),{minX:G,minY:X,width:H,height:B}=L;h.strokeStyle="green",h.lineWidth=2/f,h.strokeRect(G+1/f,X+1/y,H-2/f,B-2/y)}{const{brush:L}=r.getInstanceState();if(L){const{x:G,y:X,w:H,h:B}=L;h.beginPath(),xc.sharpRect(h,G,X,H,B),h.closePath(),h.fillStyle=M,h.fill()}}{const{minX:L,minY:G,width:X,height:H}=d;h.beginPath();const B=12/f,W=12/f;xc.roundedRect(h,L,G,X,H,Math.min(X/4,B),Math.min(H/4,W)),h.closePath(),h.fillStyle=M,h.fill(),this.debug&&(h.strokeStyle="orange",h.strokeRect(L+1/f,G+1/y,X-2/f,H-2/y))}const R=2.5/f,O=2.5/y,U=r.getCurrentPageId();let N;for(let L=0;L<this.collaborators.length;L++)N=this.collaborators[L],N.currentPageId===U&&(h.beginPath(),h.ellipse(ar(N.cursor.x,s.minX+R,s.maxX-R),ar(N.cursor.y,s.minY+O,s.maxY-O),5/f,5/y,0,0,De),h.fillStyle=N.color,h.fill());if(this.debug){h.lineWidth=2/f;{const{minX:L,minY:G,width:X,height:H}=i;h.strokeStyle="red",h.strokeRect(L+1/f,G+1/y,X-2/f,H-2/y)}{const{minX:L,minY:G,width:X,height:H}=s;h.strokeStyle="blue",h.strokeRect(L+1/f,G+1/y,X-2/f,H-2/y)}}});this.editor=n}setDpr(n){this.dpr=+n.toFixed(2)}static roundedRect(n,t,r,o,s,i,a){if(i<1&&a<1){n.rect(t,r,o,s);return}n.moveTo(t+i,r),n.lineTo(t+o-i,r),n.quadraticCurveTo(t+o,r,t+o,r+a),n.lineTo(t+o,r+s-a),n.quadraticCurveTo(t+o,r+s,t+o-i,r+s),n.lineTo(t+i,r+s),n.quadraticCurveTo(t,r+s,t,r+s-a),n.lineTo(t,r+a),n.quadraticCurveTo(t,r,t+i,r)}static sharpRect(n,t,r,o,s,i,a){n.rect(t,r,o,s)}}function uee(){const e=F(),n=x.useRef(null),t=x.useRef(!1),r=Sf(),o=EI("dpr",()=>e.getInstanceState().devicePixelRatio,[e]),s=x.useMemo(()=>e.store.query.records("instance_presence"),[e]),i=x.useMemo(()=>new xc(e),[e]);x.useEffect(()=>{const d=requestAnimationFrame(()=>{i.updateColors(),i.render()});return()=>{cancelAnimationFrame(d)}},[e,i,r]);const a=x.useCallback(d=>{if(!e.getCurrentPageShapeIds().size)return;const h=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),f=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0);i.originPagePoint.setTo(f),i.originPageCenter.setTo(e.getViewportPageBounds().center),e.centerOnPoint(h,{duration:Mo})},[e,i]),l=x.useCallback(d=>{const h=d.currentTarget;if(Su(h,d),!e.getCurrentPageShapeIds().size)return;t.current=!0,i.isInViewport=!1;const f=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!1),y=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,!1,!0),g=e.getViewportPageBounds();if(i.isInViewport=g.containsPoint(y),i.isInViewport)i.originPagePoint.setTo(y),i.originPageCenter.setTo(g.center);else{const S=b.Sub(g.center,g.point),w=b.Add(f,S);i.originPagePoint.setTo(w),i.originPageCenter.setTo(f),e.centerOnPoint(f,{duration:Mo})}function v(S){h&&vu(h,S),t.current=!1,document.body.removeEventListener("pointerup",v)}document.body.addEventListener("pointerup",v)},[e,i]),c=x.useCallback(d=>{const h=i.minimapScreenPointToPagePoint(d.clientX,d.clientY,d.shiftKey,!0);if(t.current){if(i.isInViewport){const v=i.originPagePoint.clone().sub(i.originPageCenter);e.centerOnPoint(b.Sub(h,v));return}e.centerOnPoint(h)}const f=i.getPagePoint(d.clientX,d.clientY),y=e.pageToScreen(f),g={type:"pointer",target:"canvas",name:"pointer_move",...In(d),point:y,isPen:e.getInstanceState().isPenMode};e.dispatch(g)},[e,i]),u=x.useCallback(d=>{const h=RE(d);e.dispatch({type:"wheel",name:"wheel",delta:h,point:new b(d.clientX,d.clientY),shiftKey:d.shiftKey,altKey:d.altKey,ctrlKey:d.metaKey||d.ctrlKey})},[e]);return fi("update when dpr changes",()=>{const d=o.get();i.setDpr(d);const h=n.current,f=h.getBoundingClientRect(),y=f.width*d,g=f.height*d;h.width=y,h.height=g,i.canvasScreenBounds.set(f.x,f.y,y,g),i.cvs=n.current},[o,i]),fi("minimap render when pagebounds or collaborators changes",()=>{const d=e.getCurrentPageShapeIds(),h=e.getCurrentPageBounds(),f=e.getViewportPageBounds();o.get(),i.contentPageBounds=h?ne.Expand(h,f):f,i.updateContentScreenBounds();const y=[];d.forEach(g=>{let v=e.getShapePageBounds(g);if(!v)return;const S=e.getShapeMask(g);if(S){const w=Hy(S,v.corners);if(!w)return;v=ne.FromPoints(w)}v&&(v.id=g,y.push(v))}),i.pageBounds=y,i.collaborators=s.get(),i.render()},[e,i]),p.jsx("div",{className:"tlui-minimap",children:p.jsx("canvas",{role:"img","aria-label":"minimap",ref:n,className:"tlui-minimap__canvas",onDoubleClick:a,onPointerMove:c,onPointerDown:l,onWheel:u})})}function dee(e,n){const[t,r]=ie.useState(n);ie.useLayoutEffect(()=>{const s=localStorage.getItem(e);if(s)try{r(JSON.parse(s))}catch{console.error(`Could not restore value ${e} from local storage.`)}},[e]);const o=ie.useCallback(s=>{r(i=>{const a=typeof s=="function"?s(i):s;return localStorage.setItem(e,JSON.stringify(a)),a})},[e]);return[t,o]}const hee=x.memo(function(){const n=le(),t=Ee(),r=Ln(),[o,s]=dee("minimap",!0),i=x.useCallback(()=>{s(c=>!c)},[s]),{ZoomMenu:a,Minimap:l}=Xs();return r<ht.MOBILE?null:p.jsxs("div",{className:"tlui-navigation-panel",children:[p.jsx("div",{className:"tlui-buttons__horizontal",children:a&&r<ht.TABLET?p.jsx(a,{}):o?p.jsxs(p.Fragment,{children:[a&&p.jsx(a,{}),l&&p.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:p.jsx(Ie,{icon:o?"chevrons-ne":"chevrons-sw"})})]}):p.jsxs(p.Fragment,{children:[p.jsx(he,{type:"icon","data-testid":"minimap.zoom-out",title:`${t(au(n["zoom-out"].label))} ${uu(n["zoom-out"].kbd)}`,onClick:()=>n["zoom-out"].onSelect("navigation-zone"),children:p.jsx(Ie,{icon:"minus"})}),a&&p.jsx(a,{}),p.jsx(he,{type:"icon","data-testid":"minimap.zoom-in",title:`${t(au(n["zoom-in"].label))} ${uu(n["zoom-in"].kbd)}`,onClick:()=>n["zoom-in"].onSelect("navigation-zone"),children:p.jsx(Ie,{icon:"plus"})}),l&&p.jsx(he,{type:"icon","data-testid":"minimap.toggle-button",title:t("navigation-zone.toggle-minimap"),className:"tlui-navigation-panel__toggle",onClick:i,children:p.jsx(Ie,{icon:o?"chevrons-ne":"chevrons-sw"})})]})}),l&&r>=ht.TABLET&&!o&&p.jsx(l,{})]})}),pee=function({name:n,id:t,isCurrentPage:r}){const o=F(),s=x.useRef(null),i=x.useCallback(l=>{o.renamePage(t,l||"New Page",{ephemeral:!0})},[o,t]),a=x.useCallback(l=>{o.mark("rename page"),o.renamePage(t,l||"New Page",{ephemeral:!1})},[o,t]);return p.jsx(Gw,{className:"tlui-page-menu__item__input",ref:l=>s.current=l,defaultValue:n,onValueChange:i,onComplete:a,onCancel:a,shouldManuallyMaintainScrollPositionWhenFocused:!0,autofocus:r,autoselect:!0})},xv=(e,n,t,r)=>{let o;const s=e.getPages(),i=t>r?s[r-1]:s[r],a=t>r?s[r]:s[r+1];i&&!a?o=ko(i.index):!i&&a?o=pD(s[0].index):o=oc(i.index,a.index),o!==s[t].index&&(e.mark("moving page"),e.updatePage({id:n,index:o}))},QC=Tt(function({index:n,listSize:t,item:r,onRename:o}){const s=F(),i=Ee(),a=s.getPages(),l=x.useCallback(()=>{s.mark("creating page");const h=zo.createId();s.duplicatePage(r.id,h)},[s,r]),c=x.useCallback(()=>{xv(s,r.id,n,n-1)},[s,r,n]),u=x.useCallback(()=>{xv(s,r.id,n,n+1)},[s,r,n]),d=x.useCallback(()=>{s.mark("deleting page"),s.deletePage(r.id)},[s,r]);return p.jsxs(Ti,{id:`page item submenu ${n}`,children:[p.jsx($i,{children:p.jsx(he,{type:"icon",title:i("page-menu.submenu.title"),children:p.jsx(Ie,{icon:"dots-vertical"})})}),p.jsx(Mi,{alignOffset:0,side:"right",sideOffset:-4,children:p.jsxs(So,{type:"menu",sourceId:"page-menu",children:[p.jsxs(we,{id:"modify",children:[o&&p.jsx(z,{id:"rename",label:"page-menu.submenu.rename",onSelect:o}),p.jsx(z,{id:"duplicate",label:"page-menu.submenu.duplicate-page",onSelect:l,disabled:a.length>=fp}),n>0&&p.jsx(z,{id:"move-up",onSelect:c,label:"page-menu.submenu.move-up"}),n<t-1&&p.jsx(z,{id:"move-down",label:"page-menu.submenu.move-down",onSelect:u})]}),t>1&&p.jsx(we,{id:"delete",children:p.jsx(z,{id:"delete",onSelect:d,label:"page-menu.submenu.delete"})})]})})]})}),fee=x.memo(function(){const n=F(),t=Ee(),r=Ln(),o=x.useCallback(()=>v(!1),[]),[s,i]=Gs("page-menu",o),a=36,l=x.useRef(null),c=K("pages",()=>n.getPages(),[n]),u=K("currentPage",()=>n.getCurrentPage(),[n]),d=K("currentPageId",()=>n.getCurrentPageId(),[n]),h=fo(),f=K("maxPageCountReached",()=>n.getPages().length>=fp,[n]),y=K("isCoarsePointer",()=>n.getInstanceState().isCoarsePointer,[n]),[g,v]=x.useState(!1),S=x.useCallback(()=>{h||v(T=>!T)},[h]),w=x.useRef({isPointing:!1,status:"idle",pointing:null,startY:0,startIndex:0,dragIndex:0}),[C,I]=x.useState(Object.fromEntries(c.map((T,R)=>[T.id,{y:R*a,offsetY:0,isSelected:!1}])));x.useLayoutEffect(()=>{I(Object.fromEntries(c.map((T,R)=>[T.id,{y:R*a,offsetY:0,isSelected:!1}])))},[a,c]),x.useEffect(()=>{s&&requestAnimationFrame(()=>{const T=document.querySelector(`[data-testid="page-menu-item-${d}"]`);if(T){const R=l.current;if(!R)return;const O=T.offsetTop,U=R.scrollTop;O<U&&R.scrollTo({top:O});const N=O+a,L=R.scrollTop+R.offsetHeight;N>L&&R.scrollTo({top:N-R.offsetHeight})}})},[a,d,s]);const P=x.useCallback(T=>{const{clientY:R,currentTarget:O}=T,{dataset:{id:U,index:N}}=O;if(!U||!N)return;const L=w.current;Su(T.currentTarget,T),L.status="pointing",L.pointing={id:U,index:+N};const X=C[U].y;L.startY=R,L.startIndex=Math.max(0,Math.min(Math.round(X/a),c.length-1))},[a,c.length,C]),E=x.useCallback(T=>{const R=w.current;if(R.status==="pointing"){const{clientY:O}=T,U=O-R.startY;Math.abs(U)>5&&(R.status="dragging")}if(R.status==="dragging"){const{clientY:O}=T,U=O-R.startY,N=C[R.pointing.id],{startIndex:L,pointing:G}=R,X=N.y+U,H=Math.max(0,Math.min(Math.round(X/a),c.length-1)),B={...C};if(B[G.id]={y:N.y,offsetY:U,isSelected:!0},H!==R.dragIndex){R.dragIndex=H;for(let W=0;W<c.length;W++){const Y=c[W];if(Y.id===R.pointing.id)continue;let{y:J}=B[Y.id];H===L?J=W*a:H<L?H<=W&&W<L?J=(W+1)*a:J=W*a:H>L&&(H>=W&&W>L?J=(W-1)*a:J=W*a),J!==B[Y.id].y&&(B[Y.id]={y:J,offsetY:0,isSelected:!0})}}I(B)}},[a,c,C]),_=x.useCallback(T=>{const R=w.current;if(R.status==="dragging"){const{id:O,index:U}=R.pointing;xv(n,O,U,R.dragIndex)}vu(T.currentTarget,T),R.status="idle"},[n]),k=x.useCallback(T=>{const R=w.current;T.key==="Escape"&&(R.status==="dragging"&&I(Object.fromEntries(c.map((O,U)=>[O.id,{y:U*a,offsetY:0,isSelected:!1}]))),R.status="idle")},[a,c]),M=x.useCallback(()=>{h||n.batch(()=>{n.mark("creating page");const T=zo.createId();n.createPage({name:t("page-menu.new-page-initial-name"),id:T}),n.setCurrentPage(T),v(!0)})},[n,t,h]);return p.jsxs(Hw,{id:"pages",onOpenChange:i,open:s,children:[p.jsx(Kw,{"data-testid":"main.page-menu",children:p.jsxs(he,{type:"menu",title:u.name,"data-testid":"page-menu.button",className:"tlui-page-menu__trigger",children:[p.jsx("div",{className:"tlui-page-menu__name",children:u.name}),p.jsx(Ie,{icon:"chevron-down",small:!0})]})}),p.jsx(Vw,{side:"bottom",align:"start",sideOffset:6,children:p.jsxs("div",{className:"tlui-page-menu__wrapper",children:[p.jsxs("div",{className:"tlui-page-menu__header",children:[p.jsx("div",{className:"tlui-page-menu__header__title",children:t("page-menu.title")}),!h&&p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsx(he,{type:"icon","data-testid":"page-menu.edit",title:t(g?"page-menu.edit-done":"page-menu.edit-start"),onClick:S,children:p.jsx(Ie,{icon:g?"check":"edit"})}),p.jsx(he,{type:"icon","data-testid":"page-menu.create",title:t(f?"page-menu.max-page-count-reached":"page-menu.create-new-page"),disabled:f,onClick:M,children:p.jsx(Ie,{icon:"plus"})})]})]}),p.jsx("div",{"data-testid":"page-menu.list",className:"tlui-page-menu__list tlui-menu__group",style:{height:a*c.length+4},ref:l,children:c.map((T,R)=>{const O=C[T.id]??{position:R*40,offsetY:0};return g?p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page_menu__item__sortable",style:{zIndex:T.id===u.id?888:R,transform:`translate(0px, ${O.y+O.offsetY}px)`},children:[p.jsx(he,{type:"icon",tabIndex:-1,className:"tlui-page_menu__item__sortable__handle",onPointerDown:P,onPointerUp:_,onPointerMove:E,onKeyDown:k,"data-id":T.id,"data-index":R,children:p.jsx(Ie,{icon:"drag-handle-dots"})}),r<ht.TABLET_SM&&y?p.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>{const U=window.prompt("Rename page",T.name);U&&U!==T.name&&n.renamePage(T.id,U)},onDoubleClick:S,children:[p.jsx(wv,{checked:T.id===u.id}),p.jsx(mt,{children:T.name})]}):p.jsx("div",{className:"tlui-page_menu__item__sortable__title",style:{height:a},children:p.jsx(pee,{id:T.id,name:T.name,isCurrentPage:T.id===u.id})}),!h&&p.jsx("div",{className:"tlui-page_menu__item__submenu","data-isediting":g,children:p.jsx(QC,{index:R,item:T,listSize:c.length})})]},T.id+"_editing"):p.jsxs("div",{"data-testid":"page-menu.item",className:"tlui-page-menu__item",children:[p.jsxs(he,{type:"normal",className:"tlui-page-menu__item__button",onClick:()=>n.setCurrentPage(T.id),onDoubleClick:S,title:t("page-menu.go-to-page"),children:[p.jsx(wv,{checked:T.id===u.id}),p.jsx(mt,{children:T.name})]}),!h&&p.jsx("div",{className:"tlui-page_menu__item__submenu",children:p.jsx(QC,{index:R,item:T,listSize:c.length,onRename:()=>{if(n.environment.isIos){const U=window.prompt("Rename page",T.name);U&&U!==T.name&&n.renamePage(T.id,U)}else n.batch(()=>{v(!0),n.setCurrentPage(T.id)})}})})]},T.id)})})]})})]})});function gee(){const e=le(),n=F(),t=_k(),r=Ek(),o=an(1),s=fo(),i=K("should display quick actions",()=>n.isInAny("select","hand","zoom"),[n]);if(!(s&&!i))return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e.undo,disabled:!t}),p.jsx(z,{...e.redo,disabled:!r}),p.jsx(z,{...e.delete,disabled:!o}),p.jsx(z,{...e.duplicate,disabled:!o})]})}const mee=x.memo(function({children:n}){const t=n??p.jsx(gee,{});return p.jsx(So,{type:"small-icons",sourceId:"quick-actions",children:t})}),yee=Object.freeze([mr,yi,Ua,co]);function BA(e=yee){const n=F();return K("getRelevantStyles",()=>{var s;const t=new Ky(n.getSharedStyles()),r=!!((s=n.root.getCurrent())!=null&&s.shapeType),o=n.isIn("select")&&n.getSelectedShapeIds().length>0;if(t.size===0&&n.isIn("select")&&n.getSelectedShapeIds().length===0)for(const i of e)t.applyValue(i,n.getStyleForNextShape(i));return r||o||t.size>0?t:null},[n])}const Or={color:[{value:"black",icon:"color"},{value:"grey",icon:"color"},{value:"light-violet",icon:"color"},{value:"violet",icon:"color"},{value:"blue",icon:"color"},{value:"light-blue",icon:"color"},{value:"yellow",icon:"color"},{value:"orange",icon:"color"},{value:"green",icon:"color"},{value:"light-green",icon:"color"},{value:"light-red",icon:"color"},{value:"red",icon:"color"}],fill:[{value:"none",icon:"fill-none"},{value:"semi",icon:"fill-semi"},{value:"solid",icon:"fill-solid"},{value:"pattern",icon:"fill-pattern"}],dash:[{value:"draw",icon:"dash-draw"},{value:"dashed",icon:"dash-dashed"},{value:"dotted",icon:"dash-dotted"},{value:"solid",icon:"dash-solid"}],size:[{value:"s",icon:"size-small"},{value:"m",icon:"size-medium"},{value:"l",icon:"size-large"},{value:"xl",icon:"size-extra-large"}],font:[{value:"draw",icon:"font-draw"},{value:"sans",icon:"font-sans"},{value:"serif",icon:"font-serif"},{value:"mono",icon:"font-mono"}],horizontalAlign:[{value:"start",icon:"text-align-left"},{value:"middle",icon:"text-align-center"},{value:"end",icon:"text-align-right"}],verticalAlign:[{value:"start",icon:"vertical-align-start"},{value:"middle",icon:"vertical-align-center"},{value:"end",icon:"vertical-align-end"}],geo:[{value:"rectangle",icon:"geo-rectangle"},{value:"ellipse",icon:"geo-ellipse"},{value:"cloud",icon:"geo-cloud"},{value:"triangle",icon:"geo-triangle"},{value:"diamond",icon:"geo-diamond"},{value:"pentagon",icon:"geo-pentagon"},{value:"hexagon",icon:"geo-hexagon"},{value:"octagon",icon:"geo-octagon"},{value:"star",icon:"geo-star"},{value:"rhombus",icon:"geo-rhombus"},{value:"rhombus-2",icon:"geo-rhombus-2"},{value:"oval",icon:"geo-oval"},{value:"trapezoid",icon:"geo-trapezoid"},{value:"arrow-right",icon:"geo-arrow-right"},{value:"arrow-left",icon:"geo-arrow-left"},{value:"arrow-up",icon:"geo-arrow-up"},{value:"arrow-down",icon:"geo-arrow-down"},{value:"x-box",icon:"geo-x-box"},{value:"check-box",icon:"geo-check-box"}],arrowheadStart:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],arrowheadEnd:[{value:"none",icon:"arrowhead-none"},{value:"arrow",icon:"arrowhead-arrow"},{value:"triangle",icon:"arrowhead-triangle"},{value:"square",icon:"arrowhead-square"},{value:"dot",icon:"arrowhead-dot"},{value:"diamond",icon:"arrowhead-diamond"},{value:"inverted",icon:"arrowhead-triangle-inverted"},{value:"bar",icon:"arrowhead-bar"}],spline:[{value:"line",icon:"spline-line"},{value:"cubic",icon:"spline-cubic"}]};function See(e){const{uiType:n,items:t,title:r,style:o,value:s,onValueChange:i}=e,a=F(),l=Ee(),c=x.useRef(!1),{handleButtonClick:u,handleButtonPointerDown:d,handleButtonPointerEnter:h,handleButtonPointerUp:f}=x.useMemo(()=>{const g=()=>{c.current=!1,window.removeEventListener("pointerup",g)};return{handleButtonClick:I=>{const{id:P}=I.currentTarget.dataset;s.type==="shared"&&s.value===P||(a.mark("point picker item"),i(o,P,!1))},handleButtonPointerDown:I=>{const{id:P}=I.currentTarget.dataset;a.mark("point picker item"),i(o,P,!0),c.current=!0,window.addEventListener("pointerup",g)},handleButtonPointerEnter:I=>{if(!c.current)return;const{id:P}=I.currentTarget.dataset;i(o,P,!0)},handleButtonPointerUp:I=>{const{id:P}=I.currentTarget.dataset;s.type==="shared"&&s.value===P||i(o,P,!1)}}},[s,a,i,o]),y=K("theme",()=>Dn({isDarkMode:a.user.getIsDarkMode()}),[a]);return p.jsx("div",{"data-testid":`style.${n}`,className:fe("tlui-buttons__grid"),children:t.map(g=>p.jsx(he,{type:"icon","data-id":g.value,"data-testid":`style.${n}.${g.value}`,"aria-label":g.value,"data-state":s.type==="shared"&&s.value===g.value?"hinted":void 0,title:r+" — "+l(`${n}-style.${g.value}`),className:fe("tlui-button-grid__button"),style:o===mr?{color:y[g.value].solid}:void 0,onPointerEnter:h,onPointerDown:d,onPointerUp:f,onClick:u,children:p.jsx(Ie,{icon:g.icon})},g.value))})}const Ta=x.memo(See);function UA(e,[n,t]){return Math.min(t,Math.max(n,e))}function vee(e){const n=x.useRef({value:e,previous:e});return x.useMemo(()=>(n.current.value!==e&&(n.current.previous=n.current.value,n.current.value=e),n.current.previous),[e])}const HA=["PageUp","PageDown"],KA=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"],VA={"from-left":["Home","PageDown","ArrowDown","ArrowLeft"],"from-right":["Home","PageDown","ArrowDown","ArrowRight"],"from-bottom":["Home","PageDown","ArrowDown","ArrowLeft"],"from-top":["Home","PageDown","ArrowUp","ArrowLeft"]},Fu="Slider",[bv,wee,xee]=Wf(Fu),[WA,Rne]=go(Fu,[xee]),[bee,cg]=WA(Fu),Pee=x.forwardRef((e,n)=>{const{name:t,min:r=0,max:o=100,step:s=1,orientation:i="horizontal",disabled:a=!1,minStepsBetweenThumbs:l=0,defaultValue:c=[r],value:u,onValueChange:d=()=>{},onValueCommit:h=()=>{},inverted:f=!1,...y}=e,[g,v]=x.useState(null),S=Ye(n,N=>v(N)),w=x.useRef(new Set),C=x.useRef(0),I=i==="horizontal",P=g?!!g.closest("form"):!0,E=I?Cee:Iee,[_=[],k]=Ws({prop:u,defaultProp:c,onChange:N=>{var L;(L=[...w.current][C.current])===null||L===void 0||L.focus(),d(N)}}),M=x.useRef(_);function T(N){const L=Oee(_,N);U(N,L)}function R(N){U(N,C.current)}function O(){const N=M.current[C.current];_[C.current]!==N&&h(_)}function U(N,L,{commit:G}={commit:!1}){const X=Nee(s),H=Fee(Math.round((N-r)/s)*s+r,X),B=UA(H,[r,o]);k((W=[])=>{const Y=Aee(W,B,L);if(Lee(Y,l*s)){C.current=Y.indexOf(B);const J=String(Y)!==String(W);return J&&G&&h(Y),J?Y:W}else return W})}return x.createElement(bee,{scope:e.__scopeSlider,disabled:a,min:r,max:o,valueIndexToChangeRef:C,thumbs:w.current,values:_,orientation:i},x.createElement(bv.Provider,{scope:e.__scopeSlider},x.createElement(bv.Slot,{scope:e.__scopeSlider},x.createElement(E,Q({"aria-disabled":a,"data-disabled":a?"":void 0},y,{ref:S,onPointerDown:se(y.onPointerDown,()=>{a||(M.current=_)}),min:r,max:o,inverted:f,onSlideStart:a?void 0:T,onSlideMove:a?void 0:R,onSlideEnd:a?void 0:O,onHomeKeyDown:()=>!a&&U(r,0,{commit:!0}),onEndKeyDown:()=>!a&&U(o,_.length-1,{commit:!0}),onStepKeyDown:({event:N,direction:L})=>{if(!a){const H=HA.includes(N.key)||N.shiftKey&&KA.includes(N.key)?10:1,B=C.current,W=_[B],Y=s*H*L;U(W+Y,B,{commit:!0})}}})))),P&&_.map((N,L)=>x.createElement(Mee,{key:L,name:t?t+(_.length>1?"[]":""):void 0,value:N})))}),[GA,YA]=WA(Fu,{startEdge:"left",endEdge:"right",size:"width",direction:1}),Cee=x.forwardRef((e,n)=>{const{min:t,max:r,dir:o,inverted:s,onSlideStart:i,onSlideMove:a,onSlideEnd:l,onStepKeyDown:c,...u}=e,[d,h]=x.useState(null),f=Ye(n,C=>h(C)),y=x.useRef(),g=qw(o),v=g==="ltr",S=v&&!s||!v&&s;function w(C){const I=y.current||d.getBoundingClientRect(),P=[0,I.width],_=ox(P,S?[t,r]:[r,t]);return y.current=I,_(C-I.left)}return x.createElement(GA,{scope:e.__scopeSlider,startEdge:S?"left":"right",endEdge:S?"right":"left",direction:S?1:-1,size:"width"},x.createElement(XA,Q({dir:g,"data-orientation":"horizontal"},u,{ref:f,style:{...u.style,"--radix-slider-thumb-transform":"translateX(-50%)"},onSlideStart:C=>{const I=w(C.clientX);i==null||i(I)},onSlideMove:C=>{const I=w(C.clientX);a==null||a(I)},onSlideEnd:()=>{y.current=void 0,l==null||l()},onStepKeyDown:C=>{const P=VA[S?"from-left":"from-right"].includes(C.key);c==null||c({event:C,direction:P?-1:1})}})))}),Iee=x.forwardRef((e,n)=>{const{min:t,max:r,inverted:o,onSlideStart:s,onSlideMove:i,onSlideEnd:a,onStepKeyDown:l,...c}=e,u=x.useRef(null),d=Ye(n,u),h=x.useRef(),f=!o;function y(g){const v=h.current||u.current.getBoundingClientRect(),S=[0,v.height],C=ox(S,f?[r,t]:[t,r]);return h.current=v,C(g-v.top)}return x.createElement(GA,{scope:e.__scopeSlider,startEdge:f?"bottom":"top",endEdge:f?"top":"bottom",size:"height",direction:f?1:-1},x.createElement(XA,Q({"data-orientation":"vertical"},c,{ref:d,style:{...c.style,"--radix-slider-thumb-transform":"translateY(50%)"},onSlideStart:g=>{const v=y(g.clientY);s==null||s(v)},onSlideMove:g=>{const v=y(g.clientY);i==null||i(v)},onSlideEnd:()=>{h.current=void 0,a==null||a()},onStepKeyDown:g=>{const S=VA[f?"from-bottom":"from-top"].includes(g.key);l==null||l({event:g,direction:S?-1:1})}})))}),XA=x.forwardRef((e,n)=>{const{__scopeSlider:t,onSlideStart:r,onSlideMove:o,onSlideEnd:s,onHomeKeyDown:i,onEndKeyDown:a,onStepKeyDown:l,...c}=e,u=cg(Fu,t);return x.createElement(Be.span,Q({},c,{ref:n,onKeyDown:se(e.onKeyDown,d=>{d.key==="Home"?(i(d),d.preventDefault()):d.key==="End"?(a(d),d.preventDefault()):HA.concat(KA).includes(d.key)&&(l(d),d.preventDefault())}),onPointerDown:se(e.onPointerDown,d=>{const h=d.target;h.setPointerCapture(d.pointerId),d.preventDefault(),u.thumbs.has(h)?h.focus():r(d)}),onPointerMove:se(e.onPointerMove,d=>{d.target.hasPointerCapture(d.pointerId)&&o(d)}),onPointerUp:se(e.onPointerUp,d=>{const h=d.target;h.hasPointerCapture(d.pointerId)&&(h.releasePointerCapture(d.pointerId),s(d))})}))}),Eee="SliderTrack",_ee=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=cg(Eee,t);return x.createElement(Be.span,Q({"data-disabled":o.disabled?"":void 0,"data-orientation":o.orientation},r,{ref:n}))}),JC="SliderRange",kee=x.forwardRef((e,n)=>{const{__scopeSlider:t,...r}=e,o=cg(JC,t),s=YA(JC,t),i=x.useRef(null),a=Ye(n,i),l=o.values.length,c=o.values.map(h=>qA(h,o.min,o.max)),u=l>1?Math.min(...c):0,d=100-Math.max(...c);return x.createElement(Be.span,Q({"data-orientation":o.orientation,"data-disabled":o.disabled?"":void 0},r,{ref:a,style:{...e.style,[s.startEdge]:u+"%",[s.endEdge]:d+"%"}}))}),eI="SliderThumb",Tee=x.forwardRef((e,n)=>{const t=wee(e.__scopeSlider),[r,o]=x.useState(null),s=Ye(n,a=>o(a)),i=x.useMemo(()=>r?t().findIndex(a=>a.ref.current===r):-1,[t,r]);return x.createElement($ee,Q({},e,{ref:s,index:i}))}),$ee=x.forwardRef((e,n)=>{const{__scopeSlider:t,index:r,...o}=e,s=cg(eI,t),i=YA(eI,t),[a,l]=x.useState(null),c=Ye(n,v=>l(v)),u=rM(a),d=s.values[r],h=d===void 0?0:qA(d,s.min,s.max),f=jee(r,s.values.length),y=u==null?void 0:u[i.size],g=y?Dee(y,h,i.direction):0;return x.useEffect(()=>{if(a)return s.thumbs.add(a),()=>{s.thumbs.delete(a)}},[a,s.thumbs]),x.createElement("span",{style:{transform:"var(--radix-slider-thumb-transform)",position:"absolute",[i.startEdge]:`calc(${h}% + ${g}px)`}},x.createElement(bv.ItemSlot,{scope:e.__scopeSlider},x.createElement(Be.span,Q({role:"slider","aria-label":e["aria-label"]||f,"aria-valuemin":s.min,"aria-valuenow":d,"aria-valuemax":s.max,"aria-orientation":s.orientation,"data-orientation":s.orientation,"data-disabled":s.disabled?"":void 0,tabIndex:s.disabled?void 0:0},o,{ref:c,style:d===void 0?{display:"none"}:e.style,onFocus:se(e.onFocus,()=>{s.valueIndexToChangeRef.current=r})}))))}),Mee=e=>{const{value:n,...t}=e,r=x.useRef(null),o=vee(n);return x.useEffect(()=>{const s=r.current,i=window.HTMLInputElement.prototype,l=Object.getOwnPropertyDescriptor(i,"value").set;if(o!==n&&l){const c=new Event("input",{bubbles:!0});l.call(s,n),s.dispatchEvent(c)}},[o,n]),x.createElement("input",Q({style:{display:"none"}},t,{ref:r,defaultValue:n}))};function Aee(e=[],n,t){const r=[...e];return r[t]=n,r.sort((o,s)=>o-s)}function qA(e,n,t){const s=100/(t-n)*(e-n);return UA(s,[0,100])}function jee(e,n){return n>2?`Value ${e+1} of ${n}`:n===2?["Minimum","Maximum"][e]:void 0}function Oee(e,n){if(e.length===1)return 0;const t=e.map(o=>Math.abs(o-n)),r=Math.min(...t);return t.indexOf(r)}function Dee(e,n,t){const r=e/2,s=ox([0,50],[0,r]);return(r-s(n)*t)*t}function Ree(e){return e.slice(0,-1).map((n,t)=>e[t+1]-n)}function Lee(e,n){if(n>0){const t=Ree(e);return Math.min(...t)>=n}return!0}function ox(e,n){return t=>{if(e[0]===e[1]||n[0]===n[1])return n[0];const r=(n[1]-n[0])/(e[1]-e[0]);return n[0]+r*(t-e[0])}}function Nee(e){return(String(e).split(".")[1]||"").length}function Fee(e,n){const t=Math.pow(10,n);return Math.round(e*t)/t}const zee=Pee,Bee=_ee,Uee=kee,Hee=Tee,Kee=x.memo(function(n){const{title:t,steps:r,value:o,label:s,onValueChange:i}=n,a=F(),l=Ee(),c=x.useCallback(h=>{i(h[0],!0)},[i]),u=x.useCallback(()=>{a.mark("click slider")},[a]),d=x.useCallback(()=>{o&&i(o,!1)},[o,i]);return p.jsx("div",{className:"tlui-slider__container",children:p.jsxs(zee,{"data-testid":n["data-testid"],className:"tlui-slider","area-label":"Opacity",dir:"ltr",min:0,max:r,step:1,value:o?[o]:void 0,onPointerDown:u,onValueChange:c,onPointerUp:d,title:t+" — "+l(s),children:[p.jsx(Bee,{className:"tlui-slider__track",dir:"ltr",children:o!==null&&p.jsx(Uee,{className:"tlui-slider__range",dir:"ltr"})}),o!==null&&p.jsx(Hee,{className:"tlui-slider__thumb",dir:"ltr"})]})})});function Vee({label:e,uiTypeA:n,uiTypeB:t,labelA:r,labelB:o,itemsA:s,itemsB:i,styleA:a,styleB:l,valueA:c,valueB:u,onValueChange:d}){const h=Ee(),f=x.useMemo(()=>{var g;return((g=s.find(v=>c.type==="shared"&&c.value===v.value))==null?void 0:g.icon)??"mixed"},[s,c]),y=x.useMemo(()=>{var g;return((g=i.find(v=>u.type==="shared"&&u.value===v.value))==null?void 0:g.icon)??"mixed"},[i,u]);return c===void 0&&u===void 0?null:p.jsxs("div",{className:"tlui-style-panel__double-select-picker",children:[p.jsx("div",{title:h(e),className:"tlui-style-panel__double-select-picker-label",children:h(e)}),p.jsxs("div",{className:"tlui-buttons__horizontal",children:[p.jsxs(Ti,{id:`style panel ${n} A`,children:[p.jsx($i,{children:p.jsx(he,{type:"icon","data-testid":`style.${n}`,title:h(r)+" — "+(c===null||c.type==="mixed"?h("style-panel.mixed"):h(`${n}-style.${c.value}`)),children:p.jsx(Ie,{icon:f,small:!0,invertIcon:!0})})}),p.jsx(Mi,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:p.jsx("div",{className:"tlui-buttons__grid",children:s.map((g,v)=>p.jsx(du,{"data-testid":`style.${n}.${g.value}`,children:p.jsx(he,{type:"icon",onClick:()=>d(a,g.value,!1),title:`${h(r)} — ${h(`${n}-style.${g.value}`)}`,children:p.jsx(Ie,{icon:g.icon,invertIcon:!0})},g.value)},v))})})]}),p.jsxs(Ti,{id:`style panel ${t}`,children:[p.jsx($i,{children:p.jsx(he,{type:"icon","data-testid":`style.${t}`,title:h(o)+" — "+(u===null||u.type==="mixed"?h("style-panel.mixed"):h(`${t}-style.${u.value}`)),children:p.jsx(Ie,{icon:y,small:!0})})}),p.jsx(Mi,{side:"bottom",align:"end",sideOffset:0,alignOffset:-2,children:p.jsx("div",{className:"tlui-buttons__grid",children:i.map(g=>p.jsx(du,{children:p.jsx(he,{type:"icon",title:`${h(o)} — ${h(`${t}-style.${g.value}`)}`,"data-testid":`style.${t}.${g.value}`,onClick:()=>d(l,g.value,!1),children:p.jsx(Ie,{icon:g.icon})})},g.value))})})]})]})]})}const Wee=x.memo(Vee);function Gee({id:e,label:n,uiType:t,style:r,items:o,type:s,value:i,onValueChange:a}){const l=Ee(),c=F(),u=x.useMemo(()=>{var f;return(f=o.find(y=>i.type==="shared"&&y.value===i.value))==null?void 0:f.icon},[o,i]),d=i.type==="mixed"?l("style-panel.mixed"):l(`${t}-style.${i.value}`),h=n?l(n):"";return p.jsxs(Ti,{id:`style panel ${e}`,children:[p.jsx($i,{children:p.jsxs(he,{type:s,"data-testid":`style.${t}`,title:d,children:[p.jsx(mt,{children:h}),p.jsx(Ie,{icon:u??"mixed"})]})}),p.jsx(Mi,{side:"left",align:"center",alignOffset:0,children:p.jsx("div",{className:"tlui-buttons__grid",children:o.map(f=>p.jsx(du,{children:p.jsx(he,{type:"icon","data-testid":`style.${t}.${f.value}`,title:l(`${t}-style.${f.value}`),onClick:()=>{c.mark("select style dropdown item"),a(r,f.value,!1)},children:p.jsx(Ie,{icon:f.icon})})},f.value))})})]})}const sx=x.memo(Gee);function Yee({styles:e}){if(!e)return null;const n=e.get(so),t=e.get(cp),r=e.get(lp),o=e.get(dp),s=e.get(lo),i=n===void 0,a=t===void 0&&r===void 0,l=o===void 0,c=s===void 0;return p.jsxs(p.Fragment,{children:[p.jsx(Xee,{styles:e}),!c&&p.jsx(qee,{styles:e}),!(i&&a&&l)&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[p.jsx(Zee,{styles:e}),p.jsx(Jee,{styles:e}),p.jsx(Qee,{styles:e})]})]})}function zu(){const e=F(),n=yo();return ie.useMemo(()=>function(r,o,s){e.batch(()=>{e.isIn("select")&&e.setStyleForSelectedShapes(r,o,{squashing:s}),e.setStyleForNextShapes(r,o,{squashing:s}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),n("set-style",{source:"style-panel",id:r.id,value:o})},[e,n])}function Xee({styles:e}){const n=Ee(),t=zu(),r=e.get(mr),o=e.get(Ua),s=e.get(yi),i=e.get(co),a=o!==void 0||s!==void 0||i!==void 0;return p.jsxs(p.Fragment,{children:[p.jsxs("div",{tabIndex:-1,className:"tlui-style-panel__section__common","aria-label":"style panel styles","data-testid":"style.panel",children:[r===void 0?null:p.jsx(Ta,{title:n("style-panel.color"),uiType:"color",style:mr,items:Or.color,value:r,onValueChange:t}),p.jsx(ete,{})]}),a&&p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel styles",children:[o===void 0?null:p.jsx(Ta,{title:n("style-panel.fill"),uiType:"fill",style:Ua,items:Or.fill,value:o,onValueChange:t}),s===void 0?null:p.jsx(Ta,{title:n("style-panel.dash"),uiType:"dash",style:yi,items:Or.dash,value:s,onValueChange:t}),i===void 0?null:p.jsx(Ta,{title:n("style-panel.size"),uiType:"size",style:co,items:Or.size,value:i,onValueChange:t})]})]})}function qee({styles:e}){const n=Ee(),t=zu(),r=e.get(lo),o=e.get(Ec),s=e.get(up);return r===void 0&&o===void 0?null:p.jsxs("div",{className:"tlui-style-panel__section","aria-label":"style panel text",children:[r===void 0?null:p.jsx(Ta,{title:n("style-panel.font"),uiType:"font",style:lo,items:Or.font,value:r,onValueChange:t}),o===void 0?null:p.jsxs("div",{className:"tlui-style-panel__row",children:[p.jsx(Ta,{title:n("style-panel.align"),uiType:"align",style:Ec,items:Or.horizontalAlign,value:o,onValueChange:t}),p.jsx("div",{className:"tlui-style-panel__row__extra-button",children:s===void 0?p.jsx(he,{type:"icon",title:n("style-panel.vertical-align"),"data-testid":"vertical-align",disabled:!0,children:p.jsx(Ie,{icon:"vertical-align-center"})}):p.jsx(sx,{type:"icon",id:"geo-vertical-alignment",uiType:"verticalAlign",style:up,items:Or.verticalAlign,value:s,onValueChange:t})})]})]})}function Zee({styles:e}){const n=zu(),t=e.get(so);return t===void 0?null:p.jsx(sx,{id:"geo",type:"menu",label:"style-panel.geo",uiType:"geo",style:so,items:Or.geo,value:t,onValueChange:n})}function Qee({styles:e}){const n=zu(),t=e.get(dp);return t===void 0?null:p.jsx(sx,{id:"spline",type:"menu",label:"style-panel.spline",uiType:"spline",style:dp,items:Or.spline,value:t,onValueChange:n})}function Jee({styles:e}){const n=zu(),t=e.get(cp),r=e.get(lp);return!t||!r?null:p.jsx(Wee,{label:"style-panel.arrowheads",uiTypeA:"arrowheadStart",styleA:lp,itemsA:Or.arrowheadStart,valueA:r,uiTypeB:"arrowheadEnd",styleB:cp,itemsB:Or.arrowheadEnd,valueB:t,onValueChange:n,labelA:"style-panel.arrowhead-start",labelB:"style-panel.arrowhead-end"})}const Vl=[.1,.25,.5,.75,1];function ete(){const e=F(),n=K("opacity",()=>e.getSharedOpacity(),[e]),t=yo(),r=Ee(),o=ie.useCallback((i,a)=>{const l=Vl[i];e.batch(()=>{e.isIn("select")&&e.setOpacityForSelectedShapes(l,{squashing:a}),e.setOpacityForNextShapes(l,{squashing:a}),e.updateInstanceState({isChangingStyle:!0},{ephemeral:!0})}),t("set-style",{source:"style-panel",id:"opacity",value:i})},[e,t]);if(n===void 0)return null;const s=n.type==="mixed"?-1:Vl.indexOf(nD(Vl,i=>Math.abs(i-n.value)));return p.jsx(Kee,{"data-testid":"style.opacity",value:s>=0?s:Vl.length-1,label:n.type==="mixed"?"style-panel.mixed":`opacity-style.${n.value}`,onValueChange:o,steps:Vl.length-1,title:r("style-panel.opacity")})}const tte=x.memo(function({isMobile:n,children:t}){const r=F(),o=BA(),s=x.useCallback(()=>{n||r.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[r,n]),i=t??p.jsx(Yee,{styles:o});return p.jsx("div",{className:fe("tlui-style-panel",{"tlui-style-panel__wrapper":!n}),"data-ismobile":n,onPointerLeave:s,children:i})}),oy=typeof navigator<"u"?navigator.userAgent.toLowerCase().indexOf("firefox")>0:!1;function sy(e,n,t,r){e.addEventListener?e.addEventListener(n,t,r):e.attachEvent&&e.attachEvent("on".concat(n),t)}function Wl(e,n,t,r){e.removeEventListener?e.removeEventListener(n,t,r):e.detachEvent&&e.detachEvent("on".concat(n),t)}function ZA(e,n){const t=n.slice(0,n.length-1);for(let r=0;r<t.length;r++)t[r]=e[t[r].toLowerCase()];return t}function QA(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const n=e.split(",");let t=n.lastIndexOf("");for(;t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function nte(e,n){const t=e.length>=n.length?e:n,r=e.length>=n.length?n:e;let o=!0;for(let s=0;s<t.length;s++)r.indexOf(t[s])===-1&&(o=!1);return o}const hu={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,"-":oy?173:189,"=":oy?61:187,";":oy?59:186,"'":222,"[":219,"]":221,"\\":220},ho={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":91,cmd:91,command:91},Pv={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},Dt={16:!1,18:!1,17:!1,91:!1},at={};for(let e=1;e<20;e++)hu["f".concat(e)]=111+e;let He=[],bc=null,JA="all";const _o=new Map,Bu=e=>hu[e.toLowerCase()]||ho[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),rte=e=>Object.keys(hu).find(n=>hu[n]===e),ote=e=>Object.keys(ho).find(n=>ho[n]===e);function ej(e){JA=e||"all"}function pu(){return JA||"all"}function ste(){return He.slice(0)}function ite(){return He.map(e=>rte(e)||ote(e)||String.fromCharCode(e))}function ate(){const e=[];return Object.keys(at).forEach(n=>{at[n].forEach(t=>{let{key:r,scope:o,mods:s,shortcut:i}=t;e.push({scope:o,shortcut:i,mods:s,keys:r.split("+").map(a=>Bu(a))})})}),e}function lte(e){const n=e.target||e.srcElement,{tagName:t}=n;let r=!0;const o=t==="INPUT"&&!["checkbox","radio","range","button","file","reset","submit","color"].includes(n.type);return(n.isContentEditable||(o||t==="TEXTAREA"||t==="SELECT")&&!n.readOnly)&&(r=!1),r}function cte(e){return typeof e=="string"&&(e=Bu(e)),He.indexOf(e)!==-1}function ute(e,n){let t,r;e||(e=pu());for(const o in at)if(Object.prototype.hasOwnProperty.call(at,o))for(t=at[o],r=0;r<t.length;)t[r].scope===e?t.splice(r,1).forEach(i=>{let{element:a}=i;return ix(a)}):r++;pu()===e&&ej(n||"all")}function dte(e){let n=e.keyCode||e.which||e.charCode;const t=He.indexOf(n);if(t>=0&&He.splice(t,1),e.key&&e.key.toLowerCase()==="meta"&&He.splice(0,He.length),(n===93||n===224)&&(n=91),n in Dt){Dt[n]=!1;for(const r in ho)ho[r]===n&&(kn[r]=!1)}}function tj(e){if(typeof e>"u")Object.keys(at).forEach(o=>{Array.isArray(at[o])&&at[o].forEach(s=>Qd(s)),delete at[o]}),ix(null);else if(Array.isArray(e))e.forEach(o=>{o.key&&Qd(o)});else if(typeof e=="object")e.key&&Qd(e);else if(typeof e=="string"){for(var n=arguments.length,t=new Array(n>1?n-1:0),r=1;r<n;r++)t[r-1]=arguments[r];let[o,s]=t;typeof o=="function"&&(s=o,o=""),Qd({key:e,scope:o,method:s,splitKey:"+"})}}const Qd=e=>{let{key:n,scope:t,method:r,splitKey:o="+"}=e;QA(n).forEach(i=>{const a=i.split(o),l=a.length,c=a[l-1],u=c==="*"?"*":Bu(c);if(!at[u])return;t||(t=pu());const d=l>1?ZA(ho,a):[],h=[];at[u]=at[u].filter(f=>{const g=(r?f.method===r:!0)&&f.scope===t&&nte(f.mods,d);return g&&h.push(f.element),!g}),h.forEach(f=>ix(f))})};function tI(e,n,t,r){if(n.element!==r)return;let o;if(n.scope===t||n.scope==="all"){o=n.mods.length>0;for(const s in Dt)Object.prototype.hasOwnProperty.call(Dt,s)&&(!Dt[s]&&n.mods.indexOf(+s)>-1||Dt[s]&&n.mods.indexOf(+s)===-1)&&(o=!1);(n.mods.length===0&&!Dt[16]&&!Dt[18]&&!Dt[17]&&!Dt[91]||o||n.shortcut==="*")&&(n.keys=[],n.keys=n.keys.concat(He),n.method(e,n)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0)))}}function nI(e,n){const t=at["*"];let r=e.keyCode||e.which||e.charCode;if(!kn.filter.call(this,e))return;if((r===93||r===224)&&(r=91),He.indexOf(r)===-1&&r!==229&&He.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(a=>{const l=Pv[a];e[a]&&He.indexOf(l)===-1?He.push(l):!e[a]&&He.indexOf(l)>-1?He.splice(He.indexOf(l),1):a==="metaKey"&&e[a]&&He.length===3&&(e.ctrlKey||e.shiftKey||e.altKey||(He=He.slice(He.indexOf(l))))}),r in Dt){Dt[r]=!0;for(const a in ho)ho[a]===r&&(kn[a]=!0);if(!t)return}for(const a in Dt)Object.prototype.hasOwnProperty.call(Dt,a)&&(Dt[a]=e[Pv[a]]);e.getModifierState&&!(e.altKey&&!e.ctrlKey)&&e.getModifierState("AltGraph")&&(He.indexOf(17)===-1&&He.push(17),He.indexOf(18)===-1&&He.push(18),Dt[17]=!0,Dt[18]=!0);const o=pu();if(t)for(let a=0;a<t.length;a++)t[a].scope===o&&(e.type==="keydown"&&t[a].keydown||e.type==="keyup"&&t[a].keyup)&&tI(e,t[a],o,n);if(!(r in at))return;const s=at[r],i=s.length;for(let a=0;a<i;a++)if((e.type==="keydown"&&s[a].keydown||e.type==="keyup"&&s[a].keyup)&&s[a].key){const l=s[a],{splitKey:c}=l,u=l.key.split(c),d=[];for(let h=0;h<u.length;h++)d.push(Bu(u[h]));d.sort().join("")===He.sort().join("")&&tI(e,l,o,n)}}function kn(e,n,t){He=[];const r=QA(e);let o=[],s="all",i=document,a=0,l=!1,c=!0,u="+",d=!1,h=!1;for(t===void 0&&typeof n=="function"&&(t=n),Object.prototype.toString.call(n)==="[object Object]"&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(l=n.keyup),n.keydown!==void 0&&(c=n.keydown),n.capture!==void 0&&(d=n.capture),typeof n.splitKey=="string"&&(u=n.splitKey),n.single===!0&&(h=!0)),typeof n=="string"&&(s=n),h&&tj(e,s);a<r.length;a++)e=r[a].split(u),o=[],e.length>1&&(o=ZA(ho,e)),e=e[e.length-1],e=e==="*"?"*":Bu(e),e in at||(at[e]=[]),at[e].push({keyup:l,keydown:c,scope:s,mods:o,shortcut:r[a],method:t,key:r[a],splitKey:u,element:i});if(typeof i<"u"&&window){if(!_o.has(i)){const f=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;return nI(g,i)},y=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:window.event;nI(g,i),dte(g)};_o.set(i,{keydownListener:f,keyupListenr:y,capture:d}),sy(i,"keydown",f,d),sy(i,"keyup",y,d)}if(!bc){const f=()=>{He=[]};bc={listener:f,capture:d},sy(window,"focus",f,d)}}}function hte(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:"all";Object.keys(at).forEach(t=>{at[t].filter(o=>o.scope===n&&o.shortcut===e).forEach(o=>{o&&o.method&&o.method()})})}function ix(e){const n=Object.values(at).flat();if(n.findIndex(r=>{let{element:o}=r;return o===e})<0){const{keydownListener:r,keyupListenr:o,capture:s}=_o.get(e)||{};r&&o&&(Wl(e,"keyup",o,s),Wl(e,"keydown",r,s),_o.delete(e))}if((n.length<=0||_o.size<=0)&&(Object.keys(_o).forEach(o=>{const{keydownListener:s,keyupListenr:i,capture:a}=_o.get(o)||{};s&&i&&(Wl(o,"keyup",i,a),Wl(o,"keydown",s,a),_o.delete(o))}),_o.clear(),Object.keys(at).forEach(o=>delete at[o]),bc)){const{listener:o,capture:s}=bc;Wl(window,"focus",o,s),bc=null}}const iy={getPressedKeyString:ite,setScope:ej,getScope:pu,deleteScope:ute,getPressedKeyCodes:ste,getAllKeyCodes:ate,isPressed:cte,filter:lte,trigger:hte,unbind:tj,keyMap:hu,modifier:ho,modifierMap:Pv};for(const e in iy)Object.prototype.hasOwnProperty.call(iy,e)&&(kn[e]=iy[e]);if(typeof window<"u"){const e=window.hotkeys;kn.noConflict=n=>(n&&window.hotkeys===kn&&(window.hotkeys=e),kn),window.hotkeys=kn}const rI=["copy","cut","paste","asset"];function pte(){const e=F(),n=fo(),t=le(),r=rx(),o=K("is focused",()=>e.getInstanceState().isFocused,[e]),{itemsInPanel:s}=oj();x.useEffect(()=>{if(!o)return;const i=e.getContainer();kn.setScope(e.store.id);const a=(c,u)=>{kn(c,{element:document.body,scope:e.store.id},u)},l=(c,u)=>{kn(c,{element:document.body,keyup:!0,keydown:!1,scope:e.store.id},u)};for(const c of Object.values(t))c.kbd&&(n&&!c.readonlyOk||rI.includes(c.id)||a(oI(c.kbd),u=>{rc(e)||(je(u),c.onSelect("kbd"))}));for(const c of Object.values(r))!c.kbd||!c.readonlyOk&&e.getInstanceState().isReadonly||rI.includes(c.id)||a(oI(c.kbd),u=>{rc(e)||(je(u),c.onSelect("kbd"))});return a(",",c=>{if(rc(e)||e.inputs.keys.has("Comma"))return;je(c),i.focus(),e.inputs.keys.add("Comma");const{x:u,y:d,z:h}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_down",point:{x:u,y:d,z:h},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),l(",",c=>{if(rc(e)||!e.inputs.keys.has("Comma"))return;e.inputs.keys.delete("Comma");const{x:u,y:d,z:h}=e.inputs.currentScreenPoint,f={type:"pointer",name:"pointer_up",point:{x:u,y:d,z:h},shiftKey:c.shiftKey,altKey:c.altKey,ctrlKey:c.metaKey||c.ctrlKey,pointerId:0,button:0,isPen:e.getInstanceState().isPenMode,target:"canvas"};e.dispatch(f)}),()=>{kn.deleteScope(e.store.id)}},[t,r,n,e,o,s])}function oI(e){return fte(e).map(n=>{let t="";const r=n.split("");return r.length===1?t=r[0]:r[0]==="!"?t=`shift+${r[1]}`:r[0]==="?"?r.length===3&&r[1]==="!"?t=`alt+shift+${r[2]}`:t=`alt+${r[1]}`:r[0]==="$"?r[1]==="!"?t=`cmd+shift+${r[2]},ctrl+shift+${r[2]}`:r[1]==="?"?t=`cmd+⌥+${r[2]},ctrl+alt+${r[2]}`:t=`cmd+${r[1]},ctrl+${r[1]}`:t=n,t}).join(",")}function fte(e){typeof e!="string"&&(e=""),e=e.replace(/\s/g,"");const n=e.split(",");let t=n.lastIndexOf("");for(;t>=0;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function rc(e){return e.getIsMenuOpen()||e.getEditingShapeId()!==null||e.getCrashingError()}function Fe(e){return{id:e.id,type:"item",readonlyOk:e.readonlyOk,toolItem:e}}const nj=ie.createContext([]);function gte({overrides:e,children:n}){const t=F(),r=rx(),o=ie.useMemo(()=>{const s=ge([Fe(r.select),Fe(r.hand),Fe(r.draw),Fe(r.eraser),Fe(r.arrow),Fe(r.text),Fe(r.note),Fe(r.asset),Fe(r.rectangle),Fe(r.ellipse),Fe(r.diamond),Fe(r.triangle),Fe(r.trapezoid),Fe(r.rhombus),Fe(r.hexagon),Fe(r.cloud),Fe(r.star),Fe(r.oval),Fe(r["x-box"]),Fe(r["check-box"]),Fe(r["arrow-left"]),Fe(r["arrow-up"]),Fe(r["arrow-down"]),Fe(r["arrow-right"]),Fe(r.line),Fe(r.highlight),Fe(r.frame),Fe(r.laser)]);return e?e(t,s,{tools:r}):s},[t,e,r]);return p.jsx(nj.Provider,{value:o,children:n})}function rj(){const e=ie.useContext(nj);if(!e)throw new Error("useToolbarSchema must be used within a ToolbarSchemaProvider");return e}function mte(){const e=F(),n=Ee(),t=BA(),r=t==null?void 0:t.get(mr),o=Dn({isDarkMode:e.user.getIsDarkMode()}),s=((r==null?void 0:r.type)==="shared"?o[r.value]:o.black).solid,i=K("disable style panel",()=>e.isInAny("hand","zoom","eraser","laser"),[e]),a=x.useCallback(c=>{c||e.updateInstanceState({isChangingStyle:!1},{ephemeral:!0})},[e]),{StylePanel:l}=Xs();return l?p.jsxs(Hw,{id:"mobile style menu",onOpenChange:a,children:[p.jsx(Kw,{children:p.jsx(he,{type:"tool","data-testid":"mobile-styles.button",style:{color:i?"var(--color-muted-1)":s},title:n("style-panel.title"),disabled:i,children:p.jsx(Ie,{icon:i?"blob":(r==null?void 0:r.type)==="mixed"?"mixed":"blob"})})}),p.jsx(Vw,{side:"top",align:"end",children:l&&p.jsx(l,{isMobile:!0})})]}):null}const yte=["select","hand","draw","eraser","text","zoom","laser","highlight"];function Ste({activeToolId:e}){const n=F(),t=Ln(),r=Ee(),o=K("is tool locked",()=>n.getInstanceState().isToolLocked,[n]);return!e||yte.includes(e)?null:p.jsx(he,{type:"normal",title:r("action.toggle-tool-lock"),"data-testid":"tool-lock",className:fe("tlui-toolbar__lock-button",{"tlui-toolbar__lock-button__mobile":t<ht.TABLET_SM}),onClick:()=>n.updateInstanceState({isToolLocked:!o}),children:p.jsx(Ie,{icon:o?"lock":"unlock",small:!0})})}const vte=x.memo(function(){const n=F(),t=Ee(),r=Ln(),o=ie.useRef(void 0),s=fo(),i=rj(),a=K("current tool id",()=>n.getCurrentToolId(),[n]),l=K("geo",()=>n.getSharedStyles().getAsKnownValue(so),[n]),c=v=>v.label?`${t(v.label)} ${v.kbd?uu(v.kbd):""}`:"",u=i.find(v=>ay(v.toolItem,a,l)),{itemsInPanel:d,itemsInDropdown:h}=oj(),f=x.useMemo(()=>{let v=h.find(S=>S===u);return v||(o.current||(o.current=h[0]),v=o.current,h.includes(v)||(v=h[0])),o.current=v,v},[u,h]);x.useEffect(()=>{const v=[...d,f];for(let S=0;S<Math.min(10,v.length);S++){const w=`${S+1}`.slice(-1);kn(w,C=>{rc(n)||(je(C),v[S].toolItem.onSelect("kbd"))})}return()=>{kn.unbind("1,2,3,4,5,6,7,8,9,0")}},[f,n,d]);const{ActionsMenu:y,QuickActions:g}=Xs();return p.jsx("div",{className:"tlui-toolbar",children:p.jsxs("div",{className:"tlui-toolbar__inner",children:[p.jsxs("div",{className:"tlui-toolbar__left",children:[!s&&p.jsxs("div",{className:"tlui-toolbar__extras",children:[r<ht.TABLET&&p.jsxs("div",{className:"tlui-toolbar__extras__controls tlui-buttons__horizontal",children:[g&&p.jsx(g,{}),y&&p.jsx(y,{})]}),p.jsx(Ste,{activeToolId:a})]}),p.jsxs("div",{className:fe("tlui-toolbar__tools",{"tlui-toolbar__tools__mobile":r<ht.TABLET_SM}),children:[d.map(({toolItem:v})=>p.jsx(sI,{item:v,title:c(v),isSelected:ay(v,a,l)},v.id)),h.length?p.jsxs(p.Fragment,{children:[p.jsx(sI,{item:f.toolItem,title:c(f.toolItem),isSelected:ay(f.toolItem,a,l)},f.toolItem.id),p.jsxs(Ti,{id:"toolbar overflow",modal:!1,children:[p.jsx($i,{children:p.jsx(he,{title:t("tool-panel.more"),type:"tool",className:"tlui-toolbar__overflow","data-testid":"tools.more-button",children:p.jsx(Ie,{icon:"chevron-up"})})}),p.jsx(Mi,{side:"top",align:"center",children:p.jsx(wte,{toolbarItems:h})})]})]}):null]})]}),r<ht.TABLET_SM&&!s&&p.jsx("div",{className:"tlui-toolbar__tools",children:p.jsx(mte,{})})]})})}),wte=Tt(function({toolbarItems:n}){const t=Ee();return p.jsx("div",{className:"tlui-buttons__grid","data-testid":"tools.more-content",children:n.map(({toolItem:{id:r,meta:o,kbd:s,label:i,onSelect:a,icon:l}})=>p.jsx(du,{"data-tool":r,"data-geo":(o==null?void 0:o.geo)??"","aria-label":i,children:p.jsx(he,{type:"icon",className:"tlui-button-grid__button",onClick:()=>a("toolbar"),"data-testid":`tools.more.${r}`,title:i?`${t(i)} ${s?uu(s):""}`:"",children:p.jsx(Ie,{icon:l})})},r))})});function sI({item:e,title:n,isSelected:t}){var r;return p.jsx(he,{type:"tool","data-testid":`tools.${e.id}`,"data-tool":e.id,"data-geo":((r=e.meta)==null?void 0:r.geo)??"","aria-label":e.label,"data-state":t?"selected":void 0,onClick:()=>e.onSelect("toolbar"),title:n,onTouchStart:o=>{je(o),e.onSelect("toolbar")},children:p.jsx(Ie,{icon:e.icon})})}const ay=(e,n,t)=>{var r,o;return(r=e.meta)!=null&&r.geo?n==="geo"&&t===((o=e.meta)==null?void 0:o.geo):n===e.id};function oj(){const e=Ln(),n=rj(),t=fo();return x.useMemo(()=>{const r=n.filter(a=>!t||a.readonlyOk),o=Math.min(8,5+e),s=r.slice(0,o),i=r.slice(o);return i.length<=2?{itemsInPanel:r,itemsInDropdown:[]}:{itemsInPanel:s,itemsInDropdown:i}},[n,e,t])}function xte(){const e=le();return p.jsxs(p.Fragment,{children:[p.jsx(z,{...e["zoom-in"],noClose:!0}),p.jsx(z,{...e["zoom-out"],noClose:!0}),p.jsx(MA,{}),p.jsx(AA,{}),p.jsx(jA,{})]})}const bte=x.memo(function({children:n}){const t=mn(),[r,o]=Gs("zoom menu"),s=n??p.jsx(xte,{});return p.jsxs(ex,{dir:"ltr",open:r,onOpenChange:o,modal:!1,children:[p.jsx(tx,{asChild:!0,dir:"ltr",children:p.jsx(Pte,{})}),p.jsx(lg,{container:t,children:p.jsx(nx,{className:"tlui-menu",side:"top",align:"start",alignOffset:0,sideOffset:8,collisionPadding:4,children:p.jsx(So,{type:"menu",sourceId:"zoom-menu",children:s})})})]})}),Pte=x.forwardRef(function(n,t){const r=F(),o=Ln(),s=K("zoom",()=>r.getZoomLevel(),[r]),i=Ee(),a=x.useCallback(()=>{r.resetZoom(r.getViewportScreenCenter(),{duration:Mo})},[r]);return p.jsx(he,{ref:t,...n,type:"icon",title:`${i("navigation-zone.zoom")}`,"data-testid":"minimap.zoom-menu-button",className:o<ht.TABLET_SM?"tlui-zoom-menu__button":"tlui-zoom-menu__button__pct",onDoubleClick:a,icon:o<ht.MOBILE?"zoom-in":void 0,children:o<ht.MOBILE?null:p.jsxs("span",{style:{flexGrow:0,textAlign:"center"},children:[Math.floor(s*100),"%"]})})}),sj=x.createContext({});function Cte({overrides:e={},children:n}){const t=Zv(e);return p.jsx(sj.Provider,{value:x.useMemo(()=>({ContextMenu:jJ,ActionsMenu:uJ,HelpMenu:HJ,ZoomMenu:bte,MainMenu:lee,Minimap:uee,StylePanel:tte,PageMenu:fee,NavigationPanel:hee,Toolbar:vte,KeyboardShortcutsDialog:ZJ,QuickActions:mee,HelperButtons:YJ,DebugMenu:FJ,MenuPanel:cee,...t}),[t]),children:n})}function Xs(){return x.useContext(sj)}const Ite=x.memo(function(){const{DebugMenu:n}=Xs();return p.jsxs("div",{className:"tlui-debug-panel",children:[p.jsx(_te,{}),p.jsx(kte,{}),n&&p.jsx(n,{})]})});function Ete(e=!0){const[n,t]=x.useState(0),r=F();x.useEffect(()=>{if(!e)return;const o=()=>t(s=>s+1);return r.on("tick",o),()=>{r.off("tick",o)}},[r,e])}const _te=Tt(function(){Ete();const n=F(),t=n.getPath(),r=n.getHoveredShape(),o=n.getOnlySelectedShape(),s=t==="select.idle"||!t.includes("select.")?r:o,i=s&&t.includes("select.")?` / ${s.type||""}${"geo"in s.props?" / "+s.props.geo:""} / [${b.ToFixed(n.getPointInShapeSpace(s,n.inputs.currentPagePoint),0)}]`:"",a=t.startsWith("select.")&&!t.includes(".idle")?` / [${b.ToFixed(n.inputs.originPagePoint,0)}] → [${b.ToFixed(n.inputs.currentPagePoint,0)}] = ${b.Dist(n.inputs.originPagePoint,n.inputs.currentPagePoint).toFixed(0)}`:"";return p.jsx("div",{className:"tlui-debug-panel__current-state",children:`${t}${i}${a}`})});function kte(){const e=K("show_fps",()=>Ft.showFps.get(),[Ft]),n=x.useRef(null);return x.useEffect(()=>{if(!e)return;const t=250;let r=0,o=!1,s=performance.now(),i=0,a=0,l=!1;function c(){if(!o){if(a++,i=performance.now()-s,i>t){const u=Math.round(a*(t/i)*(1e3/t));u>r&&(r=u);const d=r*.75;(u<d&&!l||u>=d&&l)&&(l=!l),n.current.innerHTML=`FPS ${u.toString()}`,n.current.className="tlui-debug-panel__fps"+(l?" tlui-debug-panel__fps__slow":""),i-=t,a=0,s=performance.now()}requestAnimationFrame(c)}}return c(),()=>{o=!0}},[e]),e?p.jsx("div",{ref:n}):null}const Tte=({id:e,component:n,onClose:t})=>{const{removeDialog:r}=zi(),o=mn(),s=x.useCallback(i=>{if(!i){if(t)try{t()}catch(a){console.warn(a)}r(e)}},[e,t,r]);return p.jsx(Mq,{onOpenChange:s,defaultOpen:!0,children:p.jsx(Aq,{container:o,children:p.jsx(jq,{dir:"ltr",className:"tlui-dialog__overlay",onClick:i=>{i.target===i.currentTarget&&s(!1)},children:p.jsx(Oq,{dir:"ltr",className:"tlui-dialog__content",children:p.jsx(n,{onClose:()=>s(!1)})})})})})};function $te(){const{dialogs:e}=zi();return p.jsx(p.Fragment,{children:e.map(n=>p.jsx(Tte,{...n},n.id))})}const Mte=ie.memo($te);function Ate(){const e=F(),n=K("follow",()=>e.getInstanceState().followingUserId,[e]);return n?p.jsx(jte,{userId:n}):null}function jte({userId:e}){const n=KE(e);return n?p.jsx("div",{className:"tlui-following-indicator",style:{borderColor:n.color}}):null}function Ote({toast:e}){const{removeToast:n}=Wr(),t=Ee(),r=s=>{s||n(e.id)},o=e.actions&&e.actions.length>0;return p.jsxs(rY,{onOpenChange:r,className:"tlui-toast__container",duration:e.keepOpen?1/0:5e3,children:[e.icon&&p.jsx("div",{className:"tlui-toast__icon",children:p.jsx(Rs,{icon:e.icon})}),p.jsxs("div",{className:"tlui-toast__main",children:[p.jsxs("div",{className:"tlui-toast__content",children:[e.title&&p.jsx(oY,{className:"tlui-toast__title",children:e.title}),e.description&&p.jsx(sY,{className:"tlui-toast__description",children:e.description})]}),e.actions&&p.jsxs("div",{className:"tlui-toast__actions",children:[e.actions.map((s,i)=>p.jsx(iY,{altText:s.label,asChild:!0,onClick:s.onClick,children:p.jsx(he,{type:s.type,children:p.jsx(mt,{children:s.label})})},i)),p.jsx(EC,{asChild:!0,children:p.jsx(he,{type:"normal",className:"tlui-toast__close",style:{marginLeft:"auto"},children:p.jsx(mt,{children:e.closeLabel??t("toast.close")})})})]})]}),!o&&p.jsx(EC,{asChild:!0,children:p.jsx(he,{type:"normal",className:"tlui-toast__close",children:p.jsx(mt,{children:e.closeLabel??t("toast.close")})})})]})}function Dte(){const{toasts:e}=Wr();return p.jsx(p.Fragment,{children:e.map(n=>p.jsx(Ote,{toast:n},n.id))})}const Rte=x.memo(Dte);function Lte(){const{toasts:e}=Wr(),[n,t]=x.useState(!1);return x.useEffect(()=>{let r=!1;return e.length?t(!0):setTimeout(()=>{r||t(!1)},1e3),()=>{r=!0}},[e.length,t]),n?p.jsx(zG,{className:"tlui-toast__viewport"}):null}const pi="2.0.2";let Cv={fonts:{draw:`https://unpkg.com/@tldraw/assets@${pi}/fonts/Shantell_Sans-Tldrawish.woff2`,serif:`https://unpkg.com/@tldraw/assets@${pi}/fonts/IBMPlexSerif-Medium.woff2`,sansSerif:`https://unpkg.com/@tldraw/assets@${pi}/fonts/IBMPlexSans-Medium.woff2`,monospace:`https://unpkg.com/@tldraw/assets@${pi}/fonts/IBMPlexMono-Medium.woff2`}};function ij(e){return x.useMemo(()=>e?{fonts:{...Cv.fonts,...e==null?void 0:e.fonts}}:Cv,[e])}const Nte=["align-bottom-center","align-bottom-left","align-bottom-right","align-bottom","align-center-center","align-center-horizontal","align-center-left","align-center-right","align-center-vertical","align-left","align-right","align-top-center","align-top-left","align-top-right","align-top","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","aspect-ratio","avatar","blob","bring-forward","bring-to-front","check","checkbox-checked","checkbox-empty","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","collab","color","comment","cross-2","cross","dash-dashed","dash-dotted","dash-draw","dash-solid","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","drag-handle-dots","duplicate","edit","external-link","file","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","hidden","image","info-circle","leading","link","lock-small","lock","menu","minus","mixed","pack","page","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","ruler","search","send-backward","send-to-back","settings-horizontal","settings-vertical-1","settings-vertical","share-1","share-2","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","status-online","stretch-horizontal","stretch-vertical","text-align-center","text-align-justify","text-align-left","text-align-right","tool-arrow","tool-embed","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-text","trash","triangle-down","triangle-up","twitter","undo","ungroup","unlock-small","unlock","vertical-align-center","vertical-align-end","vertical-align-start","visible","warning-triangle","zoom-in","zoom-out"];let Gl={...Cv,icons:Object.fromEntries(Nte.map(e=>[e,`https://unpkg.com/@tldraw/assets@${pi}/icons/icon/${e}.svg`])),translations:Object.fromEntries(_c.map(e=>[e.locale,`https://unpkg.com/@tldraw/assets@${pi}/translations/${e.locale}.json`])),embedIcons:Object.fromEntries(Ha.map(e=>[e.type,`https://unpkg.com/@tldraw/assets@${pi}/embed-icons/${e.type}.png`]))};function Fte(e){return e?{fonts:Object.assign({...Gl.fonts},{...e==null?void 0:e.fonts}),icons:Object.assign({...Gl.icons},{...e==null?void 0:e.icons}),embedIcons:Object.assign({...Gl.embedIcons},{...e==null?void 0:e.embedIcons}),translations:Object.assign({...Gl.translations},{...e==null?void 0:e.translations})}:Gl}function zte(){const{addToast:e,removeToast:n,clearToasts:t}=Wr(),{addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i}=zi(),l=Ln()<ht.TABLET_SM,c=Ee();return x.useMemo(()=>({addToast:e,removeToast:n,clearToasts:t,addDialog:r,clearDialogs:o,removeDialog:s,updateDialog:i,msg:c,isMobile:l}),[r,e,o,t,c,s,n,i,l])}function Bte(e,n){const t={};for(const r of e)if(r.translations)for(const[o,s]of oo(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return{actions:(r,o)=>{for(const s of e)s.actions&&(o=s.actions(r,o,n));return o},toolbar:(r,o,s)=>{for(const i of e)i.toolbar&&(o=i.toolbar(r,o,{...n,...s}));return o},tools:(r,o,s)=>{for(const i of e)i.tools&&(o=i.tools(r,o,{...n,...s}));return o},translations:t}}function aj(e){return x.useMemo(()=>e,e)}function Ute(e){const n=aj(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>{const t={};for(const r of n)if(r.translations)for(const[o,s]of oo(r.translations)){let i=t[o];i||(i=t[o]={}),Object.assign(i,s)}return t},[n])}function Hte(e){const n=zte(),t=aj(e==null?[]:Array.isArray(e)?e:[e]);return x.useMemo(()=>Bte(t,n),[t,n])}function Kte({overrides:e,components:n,assetUrls:t,onUiEvent:r,forceMobile:o,children:s}){return p.jsx(lY,{assetUrls:Fte(t),children:p.jsx(dY,{overrides:Ute(e),children:p.jsx(fq,{onEvent:r,children:p.jsx(iZ,{children:p.jsx(hZ,{children:p.jsx(aY,{forceMobile:o,children:p.jsx(Cte,{overrides:n,children:p.jsx(Vte,{overrides:e,children:s})})})})})})})})}function Vte({overrides:e,children:n}){const t=Hte(e);return p.jsx(fZ,{overrides:t.actions,children:p.jsx(XJ,{overrides:t.tools,children:p.jsx(gte,{overrides:t.toolbar,children:n})})})}function Wte(){const e=F(),{addToast:n}=Wr();x.useEffect(()=>{function t({name:r,count:o}){n({title:"Maximum Shapes Reached",description:`You've reached the maximum number of shapes allowed on ${r} (${o}). Please delete some shapes or move to a different page to continue.`})}return e.addListener("max-shapes",t),()=>{e.removeListener("max-shapes",t)}},[e,n])}const Gte=ie.memo(function({renderDebugMenuItems:n,children:t,hideUi:r,components:o,...s}){return p.jsx(Kte,{...s,components:o,children:p.jsx(Yte,{hideUi:r,renderDebugMenuItems:n,children:t})})}),Yte=ie.memo(function({children:n,hideUi:t,...r}){return p.jsxs(p.Fragment,{children:[n,t?null:p.jsx(Xte,{...r})]})}),Xte=ie.memo(function(){const n=F(),t=Ee(),r=Ln(),o=fo(),s=K("focus",()=>n.getInstanceState().isFocusMode,[n]),i=K("debug",()=>n.getInstanceState().isDebugMode,[n]),{SharePanel:a,TopPanel:l,MenuPanel:c,StylePanel:u,Toolbar:d,HelpMenu:h,NavigationPanel:f,HelperButtons:y}=Xs();pte(),tZ(),Wte();const{"toggle-focus-mode":g}=le();return p.jsx(L$,{children:p.jsxs("div",{className:fe("tlui-layout",{"tlui-layout__mobile":r<ht.TABLET_SM}),"data-breakpoint":r,children:[s?p.jsx("div",{className:"tlui-layout__top",children:p.jsx(he,{type:"icon",className:"tlui-focus-button",title:t("focus-mode.toggle-focus-mode"),onClick:()=>g.onSelect("menu"),children:p.jsx(Ie,{icon:"dot"})})}):p.jsxs(p.Fragment,{children:[p.jsxs("div",{className:"tlui-layout__top",children:[p.jsxs("div",{className:"tlui-layout__top__left",children:[c&&p.jsx(c,{}),y&&p.jsx(y,{})]}),p.jsx("div",{className:"tlui-layout__top__center",children:l&&p.jsx(l,{})}),p.jsxs("div",{className:"tlui-layout__top__right",children:[a&&p.jsx(a,{}),u&&r>=ht.TABLET_SM&&!o&&p.jsx(u,{})]})]}),p.jsxs("div",{className:"tlui-layout__bottom",children:[p.jsxs("div",{className:"tlui-layout__bottom__main",children:[f&&p.jsx(f,{}),d&&p.jsx(d,{}),h&&p.jsx(h,{})]}),i&&p.jsx(Ite,{})]})]}),p.jsx(Rte,{}),p.jsx(Mte,{}),p.jsx(Lte,{}),p.jsx(Ate,{})]})})}),Jd=(e,n)=>{const[t,r]=x.useState(2);return x.useEffect(()=>{let o=!1;return r(2),NO(e,n).then(()=>{o||r(0)}).catch(s=>{o||(console.error(s),r(1))}),()=>{o=!0}},[e,n]),t};function qte(e){return{draw:{url:e.fonts.draw,format:e.fonts.draw.split(".").pop()},serif:{url:e.fonts.serif,format:e.fonts.serif.split(".").pop()},sansSerif:{url:e.fonts.sansSerif,format:e.fonts.sansSerif.split(".").pop()},monospace:{url:e.fonts.monospace,format:e.fonts.monospace.split(".").pop()}}}function lj(e){const n=x.useMemo(()=>qte(e),[e]),t=[Jd("tldraw_draw",n.draw),Jd("tldraw_serif",n.serif),Jd("tldraw_sans",n.sansSerif),Jd("tldraw_mono",n.monospace)];return{error:t.some(r=>r===1),done:!t.some(r=>r===2)}}function Zte(e){const{children:n,maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i,components:a={},shapeUtils:l=[],tools:c=[],...u}=e,d=Zv(a),h=x.useMemo(()=>({Scribble:j1,CollaboratorScribble:j1,SelectionForeground:RU,SelectionBackground:OU,Handles:kU,HoveredShapeIndicator:TU,...d}),[d]),f=By(l),y=x.useMemo(()=>[...r2,...f],[f]),g=By(c),v=x.useMemo(()=>[...pV,...$H,...g],[g]),S=ij(u.assetUrls),{done:w,error:C}=lj(S);return C?p.jsx(P_,{children:"Could not load assets. Please refresh the page."}):w?p.jsx(vF,{initialState:"select",...u,components:h,shapeUtils:y,tools:v,children:p.jsxs(Gte,{...u,components:h,children:[p.jsx(ene,{maxImageDimension:t,maxAssetSize:r,acceptedImageMimeTypes:o,acceptedVideoMimeTypes:s,onMount:i}),n]})}):p.jsx(b_,{children:"Loading assets..."})}const Qte=Object.freeze(["image/jpeg","image/png","image/gif","image/svg+xml"]),Jte=Object.freeze(["video/mp4","video/quicktime"]);function ene({maxImageDimension:e=1e3,maxAssetSize:n=10*1024*1024,acceptedImageMimeTypes:t=Qte,acceptedVideoMimeTypes:r=Jte,onMount:o}){const s=F(),i=Wr(),a=Ee(),l=tne(d=>{const h=[];return h.push(...eV(d)),yH(d,{maxImageDimension:e,maxAssetSize:n,acceptedImageMimeTypes:t,acceptedVideoMimeTypes:r},{toasts:i,msg:a}),h.push(o==null?void 0:o(d)),()=>{h.forEach(f=>f==null?void 0:f())}});x.useLayoutEffect(()=>{if(s)return l==null?void 0:l(s)},[s,l]);const{Canvas:c}=Ge(),{ContextMenu:u}=Xs();return u?p.jsx(u,{}):c?p.jsx(c,{}):null}function tne(e){const n=x.useRef();return x.useLayoutEffect(()=>{n.current=e}),x.useDebugValue(e),x.useCallback((...t)=>{const r=n.current;return Do(r,"fn does not exist"),r(...t)},[])}x.memo(function(n){const[t,r]=x.useState(null),[o,s]=x.useState(null),i=By(n.shapeUtils??[]),a=x.useMemo(()=>[...r2,...i],[i]),l=S_({snapshot:n.snapshot,shapeUtils:a}),c=ij(),{done:u,error:d}=lj(c),{pageId:h,bounds:f,scale:y,background:g,padding:v,darkMode:S,preserveAspectRatio:w,format:C="svg"}=n;return x.useLayoutEffect(()=>{if(!o||!l||!u)return;let I=!1;const P=document.createElement("div");o.appendChild(P),o.classList.add("tl-container","tl-theme__light");const E=new ae({store:l,shapeUtils:a??[],tools:[],getContainer:()=>P});h&&E.setCurrentPage(h);const _=E.getCurrentPageShapeIds();async function k(){const M=await E.getSvg([..._],{bounds:f,scale:y,background:g,padding:v,darkMode:S,preserveAspectRatio:w});if(M&&!I){if(C==="svg"){const T=await Xw(M);if(!I){const R=new Blob([T],{type:"image/svg+xml"}),O=URL.createObjectURL(R);r(O)}}else if(C==="png"){const T=await FM(M,E.environment.isSafari,{type:C,quality:1,scale:2});if(T&&!I){const R=URL.createObjectURL(T);r(R)}}}E.dispose()}return k(),()=>{I=!0}},[C,o,l,a,h,f,y,g,v,S,w,u,d]),d?p.jsx(P_,{children:"Could not load assets."}):u?p.jsx("div",{ref:s,style:{position:"relative",width:"100%",height:"100%"},children:t&&p.jsx("img",{src:t,style:{width:"100%",height:"100%"}})}):p.jsx(b_,{children:"Loading assets..."})});const nne=1,rne=be({tldrawFileFormatVersion:TD,schema:be({schemaVersion:Qu,storeVersion:Qu,recordVersions:Oy(Se,be({version:Qu,subTypeVersions:Oy(Se,Qu).optional(),subTypeKey:Se.optional()}))}),records:zt(be({id:Se,typeName:Se}).allowUnknownProperties())});function one(e){var n;try{return!!((n=e.document)!=null&&n.version)}catch{return!1}}function sne({json:e,schema:n}){let t;try{t=rne.validate(JSON.parse(e))}catch(o){try{if(t=JSON.parse(e),one(t))return ti.err({type:"v1File",data:t})}catch{}return ti.err({type:"notATldrawFile",cause:o})}if(t.tldrawFileFormatVersion>nne)return ti.err({type:"fileFormatVersionTooNew",version:t.tldrawFileFormatVersion});let r;try{const o=Object.fromEntries(t.records.map(s=>[s.id,s]));r=n.migrateStoreSnapshot({store:o,schema:t.schema})}catch(o){return ti.err({type:"invalidRecords",cause:o})}if(r.type==="error")return ti.err({type:"migrationFailed",reason:r.reason});try{return ti.ok(y_({initialData:r.value,schema:n}))}catch(o){return ti.err({type:"invalidRecords",cause:o})}}function ine(){const[e,n]=x.useState();function t(r){window.editor=r,e===void 0?fetch("/tldr-data").then(async o=>{if(!o.ok){console.log(`No tldr data to load from local endpoint (${o.status})`);return}return o.text()}).then(o=>{if(o===void 0)return;const s=sne({json:o,schema:r.store.schema});s.ok?(console.log("Loaded tldr file from local endpoint"),n(s.value)):console.error(`Couldn't parse tldr file: ${String(s.error.type)}`)}).catch(o=>{console.error("Couldn't fetch data:",o)}):(r.zoomToFit(),r.clearOpenMenus())}return p.jsx("div",{style:{inset:0,position:"fixed"},children:p.jsx(Zte,{assetUrls:LO(),onMount:t,store:e})})}var Iv={},iI=gl;Iv.createRoot=iI.createRoot,Iv.hydrateRoot=iI.hydrateRoot;Iv.createRoot(document.querySelector("#root")).render(p.jsx(ie.StrictMode,{children:p.jsx(ine,{})}));
|