moi-computer 0.4.1-next.0 → 0.5.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Pc as a}from"/chunk-h3evrtyp.js";if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);async function e(r){let{mount:t}=await import("/chunk-
|
|
1
|
+
import{Pc as a}from"/chunk-h3evrtyp.js";if(typeof globalThis.structuredClone==="function")globalThis.structuredClone=globalThis.structuredClone.bind(globalThis);async function e(r){let{mount:t}=await import("/chunk-gc2smzc9.js");t(r)}globalThis.__init=e;
|
|
@@ -24,4 +24,4 @@ manually, then import it to moi`,tj={"claude-code":"Anthropic",codex:"OpenAI",op
|
|
|
24
24
|
`);if(!G&&Y.length===0)return null;return A0.jsxs("div",{className:"ml-8 flex min-w-0 flex-col items-end gap-1.5",children:[Y.map((Q,z)=>A0.jsx(Nq,{mediaType:Q.mediaType,url:Q.url,filename:Q.filename},z)),G&&A0.jsx("p",{className:"max-w-full min-w-0 rounded-lg bg-accent px-4 py-2 text-sm leading-normal wrap-anywhere whitespace-pre-wrap text-accent-foreground",children:G})]})}return A0.jsx(dE,{parts:Z.parts,cwd:X,processing:J})});function lE({part:$}){switch($.type){case"text":return A0.jsx(Kq,{content:$.text});case"tool-call":return A0.jsx(AQ,{parts:[$],cwd:null});case"file":return A0.jsx(Nq,{mediaType:$.mediaType,url:$.url,filename:$.filename});case"source-url":return A0.jsx(Uq,{url:$.url,title:$.title});case"source-document":return A0.jsx(Uq,{url:"#",title:$.title});case"data":return A0.jsx(iE,{name:$.name,data:$.data});case"reasoning":return null}}function Nq({mediaType:$,url:Z,filename:J}){if($.startsWith("image/")&&Z)return A0.jsx("img",{src:Z,alt:J??"attachment",className:"max-h-64 max-w-full rounded-lg border border-border object-contain"});return A0.jsxs("div",{className:"flex items-center gap-1.5 rounded-lg border border-border bg-accent px-2.5 py-1.5 text-xs text-accent-foreground",children:[A0.jsx(x6,{size:16,stroke:1.75}),A0.jsx("span",{className:"truncate",children:J??$})]})}function Uq({url:$,title:Z}){return A0.jsx("a",{href:$,target:"_blank",rel:"noreferrer",className:"text-xs underline",children:Z??$})}function iE({name:$,data:Z}){return A0.jsxs("details",{children:[A0.jsxs("summary",{className:"cursor-pointer text-xs text-muted-foreground",children:["data:",$]}),A0.jsx("pre",{className:"mt-1 overflow-auto rounded bg-muted p-2 font-mono text-xs text-muted-foreground",children:JSON.stringify(Z,null,2)})]})}var l0=_(y(),1);function aJ({active:$=!0,focusRequest:Z=0,chatLoaded:J,view:X,previewTurn:Y,sessionId:G,processing:Q,error:z,onDismissError:H,composerBanner:U,unavailableReason:W,send:K,stop:V,onSwitchThread:N,onClose:B}){let q=s0(),F=f2.useRef(null),L=f2.useRef(null),A=X.turns,M=w2((h)=>h.hasSentMessageFromMoi),j=w2((h)=>(h.workspaceIdsPendingAnalysis??[]).includes(q)),O=f5((h)=>(h.attachments[E2(q,G??null)]??[]).some((b)=>b.status==="uploading")),D=!_4(!0,O,W),P=f2.useMemo(()=>dV(Y?[...A,Y]:A),[A,Y]),T=J&&P.length===0&&!Q,k=Qq({hasSentMessageFromMoi:M,isWorkspacePendingAnalysis:j}),{atBottom:S,scrollToBottom:I,scrollToTop:E}=pV(L,G);f2.useLayoutEffect(()=>{if(T&&k!=="empty")E()},[T,k,E]),f2.useEffect(()=>{if($)F.current?.focus()},[$,Z]);let w=f2.useCallback((h,b)=>{K(h,b),I()},[K,I]),C=f2.useCallback((h)=>{if(D)return;w(h.prompt,{directives:h.context})},[w,D]);return l0.jsxs("div",{className:"flex min-h-0 flex-1 flex-col pt-2 pb-3",children:[l0.jsxs("header",{className:"mx-auto flex w-full max-w-[calc(var(--chat-max-container)+40px)] items-center justify-between pr-2 pb-2 pl-2",children:[l0.jsx(Hq,{onSwitch:N}),B&&l0.jsx(M1,{variant:"ghost",size:"icon",onClick:B,"aria-label":"Close chat",children:l0.jsx(i5,{stroke:1.5})})]}),l0.jsxs("div",{className:"relative flex min-h-0 flex-1 flex-col",children:[l0.jsx("div",{ref:L,className:"flex scrollbar-thin flex-1 scroll-fade flex-col overflow-y-auto overscroll-contain px-5 pt-4 pb-12 [--scroll-fade-reveal:8px]",children:l0.jsxs("div",{className:"mx-auto flex w-full max-w-(--chat-max-container) flex-1 flex-col gap-6",children:[T&&l0.jsx(zq,{kind:k,disabled:D,onSelectPrompt:C}),P.map((h,b)=>l0.jsx(Vq,{turn:h,processing:Q&&b===P.length-1},h.id)),Q&&!Y&&l0.jsx(Bq,{})]})}),!S&&A.length>0&&l0.jsx(M1,{type:"button",variant:"outline",size:"icon",onClick:()=>I("smooth"),"aria-label":"Jump to latest",className:"absolute bottom-3 left-1/2 -translate-x-1/2 animate-in rounded-full fade-in slide-in-from-bottom-1",children:l0.jsx(I6,{stroke:1.5})})]}),l0.jsx("div",{className:"mx-auto flex w-full max-w-[calc(var(--chat-max-container)+24px)] flex-col px-3",children:l0.jsxs("div",{className:Z1("@container flex w-full flex-col transition-[padding]",(U||z)&&"gap-1 rounded-2xl p-2",U&&"bg-muted",z&&"bg-destructive/10"),children:[U,z&&l0.jsxs("div",{className:"flex w-full items-start gap-2 px-3 py-2 text-sm text-destructive",children:[l0.jsx("span",{className:"flex-1 wrap-break-word",children:z}),H&&l0.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",onClick:H,className:"-m-1","aria-label":"Dismiss error",children:l0.jsx(i5,{stroke:1.75})})]}),l0.jsx(Jq,{composerRef:F,onSend:w,onStop:V,processing:Q,unavailableReason:W})]})})]})}var j9={};o7(j9,{createHandle:()=>gq,Viewport:()=>vq,Trigger:()=>_q,Title:()=>hq,Root:()=>Fq,Positioner:()=>jq,Portal:()=>Dq,Popup:()=>Tq,Handle:()=>ZX,Description:()=>xq,Close:()=>fq,Backdrop:()=>Sq,Arrow:()=>wq});var b2=_(x(),1);var oJ=_(x(),1),_Q=oJ.createContext(void 0);function i0($){let Z=oJ.useContext(_Q);if(Z===void 0&&!$)throw Error(O1(47));return Z}var R6=_(x(),1),qq=_(D2(),1);function rE(){return{...X9(),disabled:!1,modal:!1,instantType:void 0,openMethod:null,openChangeReason:null,titleElementId:void 0,descriptionElementId:void 0,stickIfOpen:!0,nested:!1,openOnHover:!1,closeDelay:0,hasViewport:!1}}var nE={...Y9,disabled:A1(($)=>$.disabled),instantType:A1(($)=>$.instantType),openMethod:A1(($)=>$.openMethod),openChangeReason:A1(($)=>$.openChangeReason),modal:A1(($)=>$.modal),stickIfOpen:A1(($)=>$.stickIfOpen),titleElementId:A1(($)=>$.titleElementId),descriptionElementId:A1(($)=>$.descriptionElementId),openOnHover:A1(($)=>$.openOnHover),closeDelay:A1(($)=>$.closeDelay),hasViewport:A1(($)=>$.hasViewport)};class f6 extends u2{constructor($){let Z={...rE(),...$};if(Z.open&&$?.mounted===void 0)Z.mounted=!0;super(Z,{popupRef:R6.createRef(),backdropRef:R6.createRef(),internalBackdropRef:R6.createRef(),onOpenChange:void 0,onOpenChangeComplete:void 0,triggerFocusTargetRef:R6.createRef(),beforeContentFocusGuardRef:R6.createRef(),stickIfOpenTimeout:new D5,triggerElements:new G2},nE)}setOpen=($,Z)=>{let J=Z.reason===l.triggerHover,X=Z.reason===l.triggerPress&&Z.event.detail===0,Y=!$&&(Z.reason===l.escapeKey||Z.reason==null);if(Z.preventUnmountOnClose=()=>{this.set("preventUnmountingOnClose",!0)},this.context.onOpenChange?.($,Z),Z.isCanceled)return;let G={open:$,nativeEvent:Z.event,reason:Z.reason,nested:this.state.nested,triggerElement:Z.trigger};this.state.floatingRootContext.context.events?.emit("openchange",G);let z=()=>{let H={open:$,openChangeReason:Z.reason},U=Z.trigger?.id??null;if(U||$)H.activeTriggerId=U,H.activeTriggerElement=Z.trigger??null;this.update(H)};if(J)this.set("stickIfOpen",!0),this.context.stickIfOpenTimeout.start(vJ,()=>{this.set("stickIfOpen",!1)}),qq.flushSync(z);else z();if(X||Y)this.set("instantType",X?"click":"dismiss");else if(Z.reason===l.focusOut)this.set("instantType","focus");else this.set("instantType",void 0)};static useStore($,Z){let J=G0(()=>{return new f6(Z)}).current,X=$??J;return G7(J.disposeEffect),X}disposeEffect=()=>{return this.context.stickIfOpenTimeout.disposeEffect()}}var q3=_(y(),1);function Lq({props:$}){let{children:Z,open:J,defaultOpen:X=!1,onOpenChange:Y,onOpenChangeComplete:G,modal:Q=!1,handle:z,triggerId:H,defaultTriggerId:U=null}=$,W=f6.useStore(z?.store,{modal:Q,open:X,openProp:J,activeTriggerId:U,triggerIdProp:H});r7(()=>{if(J===void 0&&W.state.open===!1&&X===!0)W.update({open:!0,activeTriggerId:U})}),W.useControlledProp("openProp",J),W.useControlledProp("triggerIdProp",H);let K=W.useState("open"),V=W.useState("positionerElement"),N=W.useState("payload"),B=W.useState("openChangeReason");W.useContextCallback("onOpenChange",Y),W.useContextCallback("onOpenChangeComplete",G);let{openMethod:q,triggerProps:F,reset:L}=Y6(K);Z9(W);let{forceUnmount:A}=J9(K,W,()=>{W.update({stickIfOpen:!0,openChangeReason:null}),L()});J6(K&&Q===!0&&B!==l.triggerHover&&q!=="touch",V),b2.useEffect(()=>{if(!K)W.context.stickIfOpenTimeout.clear()},[W,K]);let M=b2.useCallback((h)=>{let b=H1(h);return b.preventUnmountOnClose=()=>{W.set("preventUnmountingOnClose",!0)},b},[W]),j=b2.useCallback(()=>{W.setOpen(!1,M(l.imperativeAction))},[W,M]);b2.useImperativeHandle($.actionsRef,()=>({unmount:A,close:j}),[A,j]);let O=C7({popupStore:W,onOpenChange:W.setOpen}),D=S7(O,{outsidePressEvent:{mouse:Q==="trap-focus"?"sloppy":"intentional",touch:"sloppy"}}),P=e9(O),{getReferenceProps:T,getFloatingProps:k,getTriggerProps:S}=T5([D,P]),I=b2.useMemo(()=>{return T(F)},[T,F]),E=b2.useMemo(()=>{return S(F)},[S,F]),w=b2.useMemo(()=>{return k()},[k]);W.useSyncedValues({modal:Q,openMethod:q,activeTriggerProps:I,inactiveTriggerProps:E,popupProps:w,floatingRootContext:O,nested:Y5()!=null});let C=b2.useMemo(()=>({store:W}),[W]);return q3.jsx(_Q.Provider,{value:C,children:typeof Z==="function"?Z({payload:N}):Z})}function Fq($){if(i0(!0))return q3.jsx(Lq,{props:$});return q3.jsx(B8,{children:q3.jsx(Lq,{props:$})})}var a2=_(x(),1),MQ=_(D2(),1);var Aq=300;var j4=_(y(),1),_q=a2.forwardRef(function(Z,J){let{render:X,className:Y,disabled:G=!1,nativeButton:Q=!0,handle:z,payload:H,openOnHover:U=!1,delay:W=Aq,closeDelay:K=0,id:V,...N}=Z,B=i0(!0),q=z?.store??B?.store;if(!q)throw Error(O1(74));let F=v1(V),L=q.useState("isTriggerActive",F),A=q.useState("floatingRootContext"),M=q.useState("isOpenedByTrigger",F),j=a2.useRef(null),{registerTrigger:O,isMountedByThisTrigger:D}=$9(F,j,q,{payload:H,disabled:G,openOnHover:U,closeDelay:K}),P=q.useState("openChangeReason"),T=q.useState("stickIfOpen"),k=q.useState("openMethod"),S=h7(A,{enabled:A!=null&&U&&(k!=="touch"||P!==l.triggerPress),mouseOnly:!0,move:!1,handleClose:I7(),restMs:W,delay:{close:K},triggerElementRef:j,isActiveTrigger:L}),I=k7(A,{enabled:A!=null,stickIfOpen:T}),E=T5([I]),w=q.useState("triggerProps",D),C={disabled:G,open:M},{getButtonProps:h,buttonRef:b}=E5({disabled:G,native:Q}),f=a2.useMemo(()=>({open(U1){if(U1&&P===l.triggerPress)return D8.open(U1);return z9.open(U1)}}),[P]),g=Y1("button",Z,{state:C,ref:[b,J,O,j],props:[E.getReferenceProps(),S,w,{[p4]:"",id:F},N,h],stateAttributesMapping:f}),o=a2.useRef(null),m=a((U1)=>{MQ.flushSync(()=>{q.setOpen(!1,H1(l.focusOut,U1.nativeEvent,U1.currentTarget))}),L$(o.current)?.focus()}),V1=a((U1)=>{let q1=q.select("positionerElement");if(q1&&v2(U1,q1))q.context.beforeContentFocusGuardRef.current?.focus();else{MQ.flushSync(()=>{q.setOpen(!1,H1(l.focusOut,U1.nativeEvent,U1.currentTarget))});let e=q$(q.context.triggerFocusTargetRef.current||j.current);while(e!==null&&T1(q1,e)){let D1=e;if(e=s7(e),e===D1)break}e?.focus()}});if(L)return j4.jsxs(a2.Fragment,{children:[j4.jsx(O2,{ref:o,onFocus:m}),j4.jsx(a2.Fragment,{children:g},F),j4.jsx(O2,{ref:q.context.triggerFocusTargetRef,onFocus:V1})]});return j4.jsx(a2.Fragment,{children:g},F)});var Oq=_(x(),1);var tJ=_(x(),1),OQ=tJ.createContext(void 0);function Mq(){let $=tJ.useContext(OQ);if($===void 0)throw Error(O1(45));return $}var DQ=_(y(),1),Dq=Oq.forwardRef(function(Z,J){let{keepMounted:X=!1,...Y}=Z,{store:G}=i0();if(!(G.useState("mounted")||X))return null;return DQ.jsx(OQ.Provider,{value:X,children:DQ.jsx(i9,{ref:J,...Y})})});var v7=_(x(),1);var eJ=_(x(),1),jQ=eJ.createContext(void 0);function b6(){let $=eJ.useContext(jQ);if(!$)throw Error(O1(46));return $}var L3=_(y(),1),jq=v7.forwardRef(function(Z,J){let{render:X,className:Y,anchor:G,positionMethod:Q="absolute",side:z="bottom",align:H="center",sideOffset:U=0,alignOffset:W=0,collisionBoundary:K="clipping-ancestors",collisionPadding:V=5,arrowPadding:N=5,sticky:B=!1,disableAnchorTracking:q=!1,collisionAvoidance:F=a4,...L}=Z,{store:A}=i0(),M=Mq(),j=p9(),O=A.useState("floatingRootContext"),D=A.useState("mounted"),P=A.useState("open"),T=A.useState("openChangeReason"),k=A.useState("activeTriggerElement"),S=A.useState("modal"),I=A.useState("positionerElement"),E=A.useState("instantType"),w=A.useState("transitionStatus"),C=A.useState("hasViewport"),h=v7.useRef(null),b=K7(I,!1,!1),f=n4({anchor:G,floatingRootContext:O,positionMethod:Q,mounted:D,side:z,sideOffset:U,align:H,alignOffset:W,arrowPadding:N,collisionBoundary:K,collisionPadding:V,sticky:B,disableAnchorTracking:q,keepMounted:M,nodeId:j,collisionAvoidance:F,adaptiveOrigin:C?d$:void 0}),g=v7.useMemo(()=>{let e={};if(!P)e.pointerEvents="none";return{role:"presentation",hidden:!D,style:{...f.positionerStyles,...e}}},[P,D,f.positionerStyles]),o=v7.useMemo(()=>({props:g,...f}),[g,f]),m=O.useState("domReferenceElement");r(()=>{let e=m,D1=h.current;if(e)h.current=e;if(D1&&e&&e!==D1){A.set("instantType",void 0);let v=new AbortController;return b(()=>{A.set("instantType","trigger-change")},v.signal),()=>{v.abort()}}return},[m,b,A]);let V1={open:P,side:o.side,align:o.align,anchorHidden:o.anchorHidden,instant:E},U1=v7.useCallback((e)=>{A.set("positionerElement",e)},[A]),q1=Y1("div",Z,{state:V1,props:[o.props,T2(w),L],ref:[J,U1],stateAttributesMapping:W0});return L3.jsxs(jQ.Provider,{value:o,children:[D&&S===!0&&T!==l.triggerHover&&L3.jsx(Z6,{ref:A.context.internalBackdropRef,inert:U9(!P),cutout:k}),L3.jsx(W8,{id:j,children:q1})]})});var $X=_(x(),1);var Pq=_(y(),1),sE={...W0,...R0},Tq=$X.forwardRef(function(Z,J){let{className:X,render:Y,initialFocus:G,finalFocus:Q,...z}=Z,{store:H}=i0(),U=b6(),W=DJ(!0)!=null,K=H.useState("open"),V=H.useState("openMethod"),N=H.useState("instantType"),B=H.useState("transitionStatus"),q=H.useState("popupProps"),F=H.useState("titleElementId"),L=H.useState("descriptionElementId"),A=H.useState("modal"),M=H.useState("mounted"),j=H.useState("openChangeReason"),O=H.useState("activeTriggerElement"),D=H.useState("floatingRootContext");W5({open:K,ref:H.context.popupRef,onComplete(){if(K)H.context.onOpenChangeComplete?.(!0)}});let P=H.useState("disabled"),T=H.useState("openOnHover"),k=H.useState("closeDelay");a9(D,{enabled:T&&!P,closeDelay:k});function S(h){if(h==="touch")return H.context.popupRef.current;return!0}let I=G===void 0?S:G,E={open:K,side:U.side,align:U.align,instant:N,transitionStatus:B},w=$X.useCallback((h)=>{H.set("popupElement",h)},[H]),C=Y1("div",Z,{state:E,ref:[J,H.context.popupRef,w],props:[q,{"aria-labelledby":F,"aria-describedby":L,onKeyDown(h){if(W&&$6.has(h.key))h.stopPropagation()}},T2(B),z],stateAttributesMapping:sE});return Pq.jsx(r9,{context:D,openInteractionType:V,modal:A==="trap-focus",disabled:!M||j===l.triggerHover,initialFocus:I,returnFocus:Q,restoreFocus:"popup",previousFocusableElement:x0(O)?O:void 0,nextFocusableElement:H.context.triggerFocusTargetRef,beforeContentFocusGuardRef:H.context.beforeContentFocusGuardRef,children:C})});var Eq=_(x(),1);var wq=Eq.forwardRef(function(Z,J){let{className:X,render:Y,...G}=Z,{store:Q}=i0(),z=Q.useState("open"),{arrowRef:H,side:U,align:W,arrowUncentered:K,arrowStyles:V}=b6();return Y1("div",Z,{state:{open:z,side:U,align:W,uncentered:K},ref:[J,H],props:[{style:V,"aria-hidden":!0},G],stateAttributesMapping:W0})});var kq=_(x(),1);var aE={...W0,...R0},Sq=kq.forwardRef(function(Z,J){let{className:X,render:Y,...G}=Z,{store:Q}=i0(),z=Q.useState("open"),H=Q.useState("mounted"),U=Q.useState("transitionStatus"),W=Q.useState("openChangeReason");return Y1("div",Z,{state:{open:z,transitionStatus:U},ref:[Q.context.backdropRef,J],props:[{role:"presentation",hidden:!H,style:{pointerEvents:W===l.triggerHover?"none":void 0,userSelect:"none",WebkitUserSelect:"none"}},G],stateAttributesMapping:aE})});var Cq=_(x(),1);var hq=Cq.forwardRef(function(Z,J){let{render:X,className:Y,...G}=Z,{store:Q}=i0(),z=v1(G.id);return r(()=>{return Q.set("titleElementId",z),()=>{Q.set("titleElementId",void 0)}},[Q,z]),Y1("h2",Z,{ref:J,props:[{id:z},G]})});var Iq=_(x(),1);var xq=Iq.forwardRef(function(Z,J){let{render:X,className:Y,...G}=Z,{store:Q}=i0(),z=v1(G.id);return r(()=>{return Q.set("descriptionElementId",z),()=>{Q.set("descriptionElementId",void 0)}},[Q,z]),Y1("p",Z,{ref:J,props:[{id:z},G]})});var Rq=_(x(),1);var fq=Rq.forwardRef(function(Z,J){let{render:X,className:Y,disabled:G=!1,nativeButton:Q=!0,...z}=Z,{buttonRef:H,getButtonProps:U}=E5({disabled:G,focusableWhenDisabled:!1,native:Q}),{store:W}=i0();return Y1("button",Z,{ref:[J,H],props:[{onClick(V){W.setOpen(!1,H1(l.closePress,V.nativeEvent,V.currentTarget))}},z,U]})});var yq=_(x(),1);var bq=function($){return $.popupWidth="--popup-width",$.popupHeight="--popup-height",$}({});var oE={activationDirection:($)=>$?{"data-activation-direction":$}:null},vq=yq.forwardRef(function(Z,J){let{render:X,className:Y,children:G,...Q}=Z,{store:z}=i0(),{side:H}=b6(),U=z.useState("instantType"),{children:W,state:K}=r$({store:z,side:H,cssVars:bq,children:G}),V={activationDirection:K.activationDirection,transitioning:K.transitioning,instant:U};return Y1("div",Z,{state:V,ref:J,props:[Q,{children:W}],stateAttributesMapping:oE})});class ZX{constructor(){this.store=new f6}open($){let Z=$?this.store.context.triggerElements.getById($)??void 0:void 0;if($&&!Z)throw Error(O1(80,$));this.store.setOpen(!0,H1(l.imperativeAction,void 0,Z))}close(){this.store.setOpen(!1,H1(l.imperativeAction,void 0,void 0))}get isOpen(){return this.store.state.open}}function gq(){return new ZX}var y6=_(y(),1);function mq({...$}){return y6.jsx(j9.Root,{"data-slot":"popover",...$})}function uq({...$}){return y6.jsx(j9.Trigger,{"data-slot":"popover-trigger",...$})}function cq({className:$,align:Z="center",alignOffset:J=0,side:X="bottom",sideOffset:Y=4,keepMounted:G=!1,container:Q,...z}){return y6.jsx(j9.Portal,{keepMounted:G,container:Q,children:y6.jsx(j9.Positioner,{align:Z,alignOffset:J,side:X,sideOffset:Y,className:"isolate z-50",children:y6.jsx(j9.Popup,{"data-slot":"popover-content",className:Z1("z-50 flex w-72 origin-(--transform-origin) flex-col gap-2.5 rounded-lg bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-border outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",$),...z})})})}var g7=_(y(),1);function pq({open:$,onOpenChange:Z,onOpenChangeComplete:J,children:X}){let Y=()=>Z(!1);return g7.jsxs(mq,{open:$,onOpenChange:Z,onOpenChangeComplete:J,children:[g7.jsx(uq,{render:g7.jsx("div",{className:"fixed right-4 bottom-4 sm:right-6 sm:bottom-6",children:g7.jsx(m0.div,{variants:{from:{opacity:0,scale:0.8,filter:"blur(4px)"},to:{opacity:1,scale:1,filter:"blur(0px)"},invisible:{opacity:0,scale:1,filter:"blur(4px)"}},initial:"from",animate:$?"invisible":"to",transition:{type:"spring",duration:0.3,delay:0.2,bounce:0},children:g7.jsx(M1,{variant:"outline",size:"icon-lg",className:"bg-card shadow-md hover:shadow-lg","aria-label":"Agent",children:g7.jsx(y7,{stroke:1.75})})})})}),g7.jsx(cq,{side:"top",sideOffset:-48,align:"end",alignOffset:-8,className:"flex h-[calc(100vh-2rem)] w-[min(440px,calc(100vw-1rem))] flex-col gap-0 rounded-3xl p-0 sm:h-[calc(100vh-8rem)] sm:w-[min(440px,calc(100vw-2rem))] sm:p-1",keepMounted:!0,children:X(Y)})]})}var P9=_(y(),1);function JX({className:$,title:Z,children:J,onClose:X,ref:Y}){return P9.jsxs(m0.div,{ref:Y,className:Z1("absolute inset-x-4 bottom-4 no-scrollbar flex max-h-full flex-col gap-4 overflow-y-auto rounded-2xl bg-card p-(--page-pad) pb-0 text-card-foreground shadow-md",$),variants:{hidden:{opacity:0,y:40,filter:"blur(4px)"},visible:{opacity:1,y:0,filter:"blur(0px)"}},initial:"hidden",animate:"visible",exit:"hidden",transition:{type:"spring",duration:0.25,bounce:0},children:[P9.jsxs("div",{className:"flex shrink-0 items-center justify-between gap-4",children:[P9.jsx("p",{className:"text-sm font-medium",children:Z}),P9.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",onClick:X,"aria-label":"Close panel",children:P9.jsx(i5,{stroke:1.75})})]}),P9.jsx("div",{className:"flex-1 pb-(--page-pad)",children:J})]})}var J5=_(y(),1),tE=Object.entries(L9),eE=Object.entries(YV);function $w($,Z){return($.primary??void 0)===Z}function dq({children:$,label:Z}){return J5.jsxs("div",{className:"flex flex-col gap-2",children:[J5.jsx("p",{className:"text-xs font-medium",children:Z}),J5.jsx("div",{role:"group","aria-label":Z,className:"grid grid-cols-3 gap-2",children:$})]})}function lq({active:$,children:Z,className:J,onSelect:X,style:Y}){return J5.jsxs("button",{type:"button","aria-pressed":$,onClick:X,className:Z1("relative w-full rounded-lg bg-card text-left ring-1 ring-border transition-opacity outline-none focus-visible:ring-3 focus-visible:ring-ring/50","flex items-center gap-2 p-3",J,!$&&"cursor-pointer pr-9 opacity-70 hover:opacity-100"),style:Y,children:[J5.jsx("div",{className:"flex-1",children:Z}),$&&J5.jsx(EZ,{size:20,stroke:1.5,"aria-hidden":"true"})]})}function iq({onClose:$,ref:Z}){oZ();let{layout:J,setLayout:X}=B0(),Y=J.theme?.font??"default",G=J.theme?.primary;function Q(z,H){X({theme:{font:z,...H?{primary:H}:{}}})}return J5.jsx(JX,{ref:Z,title:"Customize",onClose:$,children:J5.jsxs("div",{className:"flex flex-col gap-4",children:[J5.jsx(dq,{label:"Font",children:tE.map(([z,H])=>J5.jsx(lq,{active:z===Y,onSelect:()=>Q(z,G),style:{fontFamily:H.sans},children:J5.jsxs("div",{className:"flex flex-col",children:[J5.jsx("span",{className:"text-sm font-medium",children:H.label}),J5.jsx("span",{className:"text-xs text-muted-foreground",children:H.feel})]})},z))}),J5.jsx(dq,{label:"Colors",children:eE.map(([z,H])=>J5.jsx(lq,{active:$w(H,G),className:H.primary&&"bg-background text-foreground",onSelect:()=>Q(Y,H.primary),style:H.primary?F4({font:Y,primary:H.primary}):void 0,children:J5.jsxs("div",{className:"flex gap-2",children:[J5.jsx("span",{className:Z1("flex size-5 shrink-0 items-center justify-center rounded-sm text-[9px] leading-none font-bold",H.primary?"bg-primary text-primary-foreground":"bg-foreground text-background"),children:"Aa"}),J5.jsx("span",{className:"text-sm font-medium",children:H.label})]})},z))})]})})}var XX=_(x(),1);var rq=_(x(),1),PQ=new Map;function Zw($){let Z=window.__moiAppletCss?.get($)??"",J=PQ.get($);if(!J){let G=document.createElement("style");G.dataset.appletStyle=$,document.head.appendChild(G),J={el:G,refs:0},PQ.set($,J)}if(J.el.textContent!==Z)J.el.textContent=Z;J.refs++;let X=J,Y=!1;return()=>{if(Y)return;if(Y=!0,X.refs--,X.refs<=0)X.el.remove(),PQ.delete($)}}function nq($,Z){rq.useInsertionEffect(()=>Zw($),[$,Z])}var sq=_(y(),1);function YX({segment:$,name:Z,version:J,asChild:X,children:Y}){let G=s0();nq(PV($,G,Z),J);let z=`${$==="widgets"?"widget":"view"}:${Z}`;if(X&&XX.isValidElement(Y))return XX.cloneElement(Y,{"data-applet":z});return sq.jsx("div",{"data-applet":z,className:"size-full",children:Y})}var oq=_(x(),1);var v6=_(y(),1);class F3 extends oq.Component{state={error:null};static getDerivedStateFromError($){return{error:$}}componentDidCatch($,Z){console.error(`[widget:${this.props.name}]`,$,Z.componentStack),c2(this.props.workspaceId,{source:"render",kind:this.props.kind,name:this.props.name,message:$.message||String($),stack:[$.stack,Z.componentStack].filter(Boolean).join(`
|
|
25
25
|
`)})}componentDidUpdate($){if($.resetKey!==this.props.resetKey&&this.state.error)this.setState({error:null})}render(){if(this.state.error)return v6.jsxs("div",{className:"flex h-full w-full flex-col items-start justify-start gap-1.5 p-4 text-xs",children:[v6.jsxs("div",{className:"flex items-center gap-1.5 font-semibold text-destructive",children:[v6.jsx(aq,{size:16,stroke:1.75}),"Widget crashed"]}),v6.jsx("div",{className:"font-mono break-words text-muted-foreground",children:this.state.error.message})]});return this.props.children}}var r6=_(x(),1);function A3($,Z,J,X){let Y=$.reduce((G,Q)=>Math.max(G,Q.y+Q.h),0);for(let G=0;G<=Y+J;G++)for(let Q=0;Q<=X-Z;Q++)if(!$.some((H)=>!(Q+Z<=H.x||H.x+H.w<=Q||G+J<=H.y||H.y+H.h<=G)))return{x:Q,y:G};return{x:0,y:Y}}function _3($,Z=[],J=4){let X=[];for(let Y of $){let{x:G,y:Q}=Y.x!==void 0&&Y.y!==void 0?{x:Y.x,y:Y.y}:A3([...Z,...X],Y.w,Y.h,J);X.push({i:Y.id,x:G,y:Q,w:Y.w,h:Y.h})}return X}var T9=_(y(),1);function tq({name:$}){let Z=s0(),J=kV($);return T9.jsxs(j7,{mode:"wait",initial:!1,children:[J.status==="ready"&&T9.jsx(m0.div,{className:"absolute inset-0",initial:{opacity:0,filter:"blur(4px)"},animate:{opacity:1,filter:"blur(0px)"},exit:{opacity:0,filter:"blur(4px)"},transition:{duration:0.45,ease:"easeInOut"},children:T9.jsx(F3,{name:$,kind:"widget",workspaceId:Z,resetKey:J.version,children:T9.jsx(YX,{segment:"widgets",name:$,version:J.version,children:T9.jsx(J.Component,{})})})},J.version),J.status==="error"&&T9.jsx(m0.p,{className:"absolute inset-0 p-4 text-xs text-destructive",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:0.45,ease:"easeInOut"},children:J.error},`err-${J.version}`)]})}var eq=_(y(),1);function g6({className:$,...Z}){return eq.jsx("div",{"data-slot":"skeleton",className:Z1("animate-pulse rounded-lg bg-muted",$),...Z})}var ZL=_(x(),1);var E9=_(y(),1);function GX({editing:$,hidden:Z,onRemove:J,children:X}){return E9.jsxs(m0.div,{variants:{idle:{rotate:0},wiggle:{rotate:[0.5,-0.5],transition:{rotate:{repeat:1/0,repeatType:"reverse",duration:0.15,ease:"easeInOut"}}}},animate:$?"wiggle":"idle",transition:{type:"spring",duration:0.35,bounce:0},className:"group/widget relative size-full",children:[E9.jsx("div",{"data-widget-chrome":!0,className:Z1("dark absolute inset-0 overflow-hidden rounded-2xl [corner-shape:superellipse(1.2)]","shadow-[0_1px_2px_-1px_rgba(0,0,0,0.08),0_2px_4px_0_rgba(0,0,0,0.03)]","after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit]","after:content-[''] after:[corner-shape:inherit]","after:shadow-[inset_0_0_0_1px_rgba(0,0,0,0.05)]","text-foreground",$&&"pointer-events-none"),children:X}),$&&J&&E9.jsx("div",{className:"absolute -top-2 -right-2 opacity-0 transition-opacity group-hover/widget:opacity-100",children:E9.jsx(M1,{size:"icon-sm",variant:"outline",className:"rounded-full",onClick:J,children:Z?E9.jsx(v5,{stroke:1.75}):E9.jsx($L,{stroke:1.75})})})]})}var m6=_(y(),1),Jw={0:"col-start-1",1:"col-start-2",2:"col-start-3",3:"col-start-4"},Xw={0:"row-start-1",1:"row-start-2",2:"row-start-3",3:"row-start-4",4:"row-start-5",5:"row-start-6",6:"row-start-7",7:"row-start-8"},Yw={1:"col-span-1",2:"col-span-2",3:"col-span-3",4:"col-span-4"},Gw={1:"row-span-1",2:"row-span-2",3:"row-span-3",4:"row-span-4"};function JL({items:$,renderItem:Z,onClose:J,onRestore:X,ref:Y}){let G=ZL.useMemo(()=>_3($),[$]);return m6.jsx(JX,{ref:Y,title:"Hidden widgets",onClose:J,className:"max-h-[60vh]",children:m6.jsx("div",{className:"grid auto-rows-[160px] grid-cols-4 gap-2",children:m6.jsx(j7,{children:G.map((Q)=>m6.jsx(m0.div,{layoutId:Q.i,className:Z1(Jw[Q.x],Xw[Q.y],Yw[Q.w],Gw[Q.h]),transition:{type:"spring",duration:0.35,bounce:0},children:m6.jsx(GX,{editing:!0,onRemove:()=>X(Q.i),hidden:!0,children:Z(Q.i)})},Q.i))})})})}var x3=_(x(),1);function k9($){let{margin:Z,containerPadding:J,containerWidth:X,cols:Y}=$;return(X-Z[0]*(Y-1)-J[0]*2)/Y}function o2($,Z,J){if(!Number.isFinite($))return $;return Math.round(Z*$+Math.max(0,$-1)*J)}function O3($,Z,J,X,Y,G,Q){let{margin:z,containerPadding:H,rowHeight:U}=$,W=k9($),K,V,N,B;if(Q)K=Math.round(Q.width),V=Math.round(Q.height);else K=o2(X,W,z[0]),V=o2(Y,U,z[1]);if(G)N=Math.round(G.top),B=Math.round(G.left);else if(Q)N=Math.round(Q.top),B=Math.round(Q.left);else N=Math.round((U+z[1])*J+H[1]),B=Math.round((W+z[0])*Z+H[0]);if(!G&&!Q){if(Number.isFinite(X)){let F=Math.round((W+z[0])*(Z+X)+H[0])-B-K;if(F!==z[0])K+=F-z[0]}if(Number.isFinite(Y)){let F=Math.round((U+z[1])*(J+Y)+H[1])-N-V;if(F!==z[1])V+=F-z[1]}}return{top:N,left:B,width:K,height:V}}function YL($,Z,J,X,Y){let{margin:G,containerPadding:Q,cols:z,rowHeight:H,maxRows:U}=$,W=k9($),K=Math.round((J-Q[0])/(W+G[0])),V=Math.round((Z-Q[1])/(H+G[1]));return K=M3(K,0,z-X),V=M3(V,0,U-Y),{x:K,y:V}}function D3($,Z,J){let{margin:X,containerPadding:Y,rowHeight:G}=$,Q=k9($),z=Math.round((J-Y[0])/(Q+X[0])),H=Math.round((Z-Y[1])/(G+X[1]));return{x:z,y:H}}function GL($,Z,J){let{margin:X,rowHeight:Y}=$,G=k9($),Q=Math.max(1,Math.round((Z+X[0])/(G+X[0]))),z=Math.max(1,Math.round((J+X[1])/(Y+X[1])));return{w:Q,h:z}}function M3($,Z,J){return Math.max(Math.min($,J),Z)}function zX($,Z){if($.i===Z.i)return!1;if($.x+$.w<=Z.x)return!1;if($.x>=Z.x+Z.w)return!1;if($.y+$.h<=Z.y)return!1;if($.y>=Z.y+Z.h)return!1;return!0}function S9($,Z){for(let J=0;J<$.length;J++){let X=$[J];if(X!==void 0&&zX(X,Z))return X}return}function TQ($,Z){return $.filter((J)=>zX(J,Z))}function Qw($,Z){if(Z==="horizontal")return EQ($);if(Z==="vertical")return QX($);if(Z==="wrap")return QX($);return[...$]}function QX($){return[...$].sort((Z,J)=>{if(Z.y!==J.y)return Z.y-J.y;return Z.x-J.x})}function EQ($){return[...$].sort((Z,J)=>{if(Z.x!==J.x)return Z.x-J.x;return Z.y-J.y})}function j3($){let Z=0;for(let J=0;J<$.length;J++){let X=$[J];if(X!==void 0){let Y=X.y+X.h;if(Y>Z)Z=Y}}return Z}function C9($,Z){for(let J=0;J<$.length;J++){let X=$[J];if(X!==void 0&&X.i===Z)return X}return}function P3($){return $.filter((Z)=>Z.static===!0)}function m7($){return{i:$.i,x:$.x,y:$.y,w:$.w,h:$.h,minW:$.minW,maxW:$.maxW,minH:$.minH,maxH:$.maxH,moved:Boolean($.moved),static:Boolean($.static),isDraggable:$.isDraggable,isResizable:$.isResizable,resizeHandles:$.resizeHandles,constraints:$.constraints,isBounded:$.isBounded}}function u6($){let Z=Array($.length);for(let J=0;J<$.length;J++){let X=$[J];if(X!==void 0)Z[J]=m7(X)}return Z}function zw($,Z){let J=Array($.length);for(let X=0;X<$.length;X++){let Y=$[X];if(Y!==void 0)if(Z.i===Y.i)J[X]=Z;else J[X]=Y}return J}function QL($,Z,J){let X=C9($,Z);if(!X)return[[...$],null];return X=J(m7(X)),[zw($,X),X]}function wQ($,Z){let J=P3($);for(let X=0;X<$.length;X++){let Y=$[X];if(Y===void 0)continue;if(Y.x+Y.w>Z.cols)Y.x=Z.cols-Y.w;if(Y.x<0)Y.x=0,Y.w=Z.cols;if(!Y.static)J.push(Y);else while(S9(J,Y))Y.y++}return $}function w9($,Z,J,X,Y,G,Q,z,H){if(Z.static&&Z.isDraggable!==!0)return[...$];if(Z.y===X&&Z.x===J)return[...$];let{x:U,y:W}=Z;if(typeof J==="number")Z.x=J;if(typeof X==="number")Z.y=X;Z.moved=!0;let K=Qw($,Q);if(Q==="vertical"&&typeof X==="number"?W>=X:Q==="horizontal"&&typeof J==="number"?U>=J:!1)K=K.reverse();let N=TQ(K,Z),B=N.length>0;if(B&&H)return u6($);if(B&&G)return Z.x=U,Z.y=W,Z.moved=!1,$;let q=[...$];for(let F=0;F<N.length;F++){let L=N[F];if(L===void 0)continue;if(L.moved)continue;if(L.static)q=XL(q,L,Z,Y,Q);else q=XL(q,Z,L,Y,Q)}return q}function XL($,Z,J,X,Y,G){let Q=Y==="horizontal",z=Y==="vertical",H=Z.static;if(X){X=!1;let K={x:Q?Math.max(Z.x-J.w,0):J.x,y:z?Math.max(Z.y-J.h,0):J.y,w:J.w,h:J.h,i:"-1"},V=S9($,K),N=V!==void 0&&V.y+V.h>Z.y,B=V!==void 0&&Z.x+Z.w>V.x;if(!V)return w9($,J,Q?K.x:void 0,z?K.y:void 0,X,H,Y);if(N&&z)return w9($,J,void 0,J.y+1,X,H,Y);if(N&&Y===null)return Z.y=J.y,J.y=J.y+J.h,[...$];if(B&&Q)return w9($,Z,J.x,void 0,X,H,Y)}let U=Q?J.x+1:void 0,W=z?J.y+1:void 0;if(U===void 0&&W===void 0)return[...$];return w9($,J,U,W,X,H,Y)}function c6($,Z,J){return Math.max(Z,Math.min(J,$))}var Hw={name:"gridBounds",constrainPosition($,Z,J,{cols:X,maxRows:Y}){return{x:c6(Z,0,Math.max(0,X-$.w)),y:c6(J,0,Math.max(0,Y-$.h))}},constrainSize($,Z,J,X,{cols:Y,maxRows:G}){let Q=X==="w"||X==="nw"||X==="sw"?$.x+$.w:Y-$.x,z=X==="n"||X==="nw"||X==="ne"?$.y+$.h:G-$.y;return{w:c6(Z,1,Math.max(1,Q)),h:c6(J,1,Math.max(1,z))}}},Uw={name:"minMaxSize",constrainSize($,Z,J){return{w:c6(Z,$.minW??1,$.maxW??1/0),h:c6(J,$.minH??1,$.maxH??1/0)}}};var kQ=[Hw,Uw];function T3($,Z,J,X,Y){let G={x:J,y:X};for(let Q of $)if(Q.constrainPosition)G=Q.constrainPosition(Z,G.x,G.y,Y);if(Z.constraints){for(let Q of Z.constraints)if(Q.constrainPosition)G=Q.constrainPosition(Z,G.x,G.y,Y)}return G}function zL($,Z,J,X,Y,G){let Q={w:J,h:X};for(let z of $)if(z.constrainSize)Q=z.constrainSize(Z,Q.w,Q.h,Y,G);if(Z.constraints){for(let z of Z.constraints)if(z.constrainSize)Q=z.constrainSize(Z,Q.w,Q.h,Y,G)}return Q}function UX({top:$,left:Z,width:J,height:X}){let Y=`translate(${Z}px,${$}px)`;return{transform:Y,WebkitTransform:Y,MozTransform:Y,msTransform:Y,OTransform:Y,width:`${J}px`,height:`${X}px`,position:"absolute"}}function SQ({top:$,left:Z,width:J,height:X}){return{top:`${$}px`,left:`${Z}px`,width:`${J}px`,height:`${X}px`,position:"absolute"}}function CQ($){return $*100+"%"}function Kw($,Z,J,X){return $+J>X?Z:J}function HL($,Z,J){return $<0?Z:J}function Ww($){return Math.max(0,$)}function HX($){return Math.max(0,$)}var hQ=($,Z,J)=>{let{left:X,height:Y,width:G}=Z,Q=$.top-(Y-$.height);return{left:X,width:G,height:HL(Q,$.height,Y),top:HX(Q)}},IQ=($,Z,J)=>{let{top:X,left:Y,height:G,width:Q}=Z;return{top:X,height:G,width:Kw($.left,$.width,Q,J),left:Ww(Y)}},xQ=($,Z,J)=>{let{top:X,height:Y,width:G}=Z,Q=$.left+$.width-G;if(Q<0)return{height:Y,width:$.left+$.width,top:HX(X),left:0};return{height:Y,width:G,top:HX(X),left:Q}},RQ=($,Z,J)=>{let{top:X,left:Y,height:G,width:Q}=Z;return{width:Q,left:Y,height:HL(X,$.height,G),top:HX(X)}},Bw=($,Z,J)=>hQ($,IQ($,Z,J)),Vw=($,Z,J)=>hQ($,xQ($,Z)),Nw=($,Z,J)=>RQ($,IQ($,Z,J)),qw=($,Z,J)=>RQ($,xQ($,Z)),Lw={n:hQ,ne:Bw,e:IQ,se:Nw,s:RQ,sw:qw,w:xQ,nw:Vw};function UL($,Z,J,X){let Y=Lw[$];if(!Y)return J;return Y(Z,{...Z,...J},X)}var Fw={type:"transform",scale:1,calcStyle($){return UX($)}};var KL=Fw,WL={cols:12,rowHeight:150,margin:[10,10],containerPadding:null,maxRows:1/0},BL={enabled:!0,bounded:!1,threshold:3},VL={enabled:!0,handles:["se"]},NL={enabled:!1,defaultItem:{w:1,h:1}};function fQ($,Z,J,X,Y){let G=X==="x"?"w":"h";Z[X]+=1;let Q=$.findIndex((H)=>H.i===Z.i),z=Y??P3($).length>0;for(let H=Q+1;H<$.length;H++){let U=$[H];if(U===void 0)continue;if(U.static)continue;if(!z&&U.y>Z.y+Z.h)break;if(zX(Z,U))fQ($,U,J+Z[G],X,z)}Z[X]=J}function Aw($,Z,J,X){Z.x=Math.max(Z.x,0),Z.y=Math.max(Z.y,0),Z.y=Math.min(X,Z.y);while(Z.y>0&&!S9($,Z))Z.y--;let Y;while((Y=S9($,Z))!==void 0)fQ(J,Z,Y.y+Y.h,"y");return Z.y=Math.max(Z.y,0),Z}function _w($,Z,J,X){Z.x=Math.max(Z.x,0),Z.y=Math.max(Z.y,0);while(Z.x>0&&!S9($,Z))Z.x--;let Y;while((Y=S9($,Z))!==void 0)if(fQ(X,Z,Y.x+Y.w,"x"),Z.x+Z.w>J){Z.x=J-Z.w,Z.y++;while(Z.x>0&&!S9($,Z))Z.x--}return Z.x=Math.max(Z.x,0),Z}var E3={type:"vertical",allowOverlap:!1,compact($,Z){let J=P3($),X=j3(J),Y=QX($),G=Array($.length);for(let Q=0;Q<Y.length;Q++){let z=Y[Q];if(z===void 0)continue;let H=m7(z);if(!H.static)H=Aw(J,H,Y,X),X=Math.max(X,H.y+H.h),J.push(H);let U=$.indexOf(z);G[U]=H,H.moved=!1}return G}},bQ={type:"horizontal",allowOverlap:!1,compact($,Z){let J=P3($),X=EQ($),Y=Array($.length);for(let G=0;G<X.length;G++){let Q=X[G];if(Q===void 0)continue;let z=m7(Q);if(!z.static)z=_w(J,z,Z,X),J.push(z);let H=$.indexOf(Q);Y[H]=z,z.moved=!1}return Y}},yQ={type:null,allowOverlap:!1,compact($,Z){return u6($)}},Mw={...E3,allowOverlap:!0,compact($,Z){return u6($)}},Ow={...bQ,allowOverlap:!0,compact($,Z){return u6($)}},Dw={...yQ,allowOverlap:!0};function vQ($,Z=!1,J=!1){let X;if(Z)if($==="vertical")X=Mw;else if($==="horizontal")X=Ow;else X=Dw;else if($==="vertical")X=E3;else if($==="horizontal")X=bQ;else X=yQ;if(J)return{...X,preventCollision:J};return X}var t2=_(x(),1);function gQ($={}){let{measureBeforeMount:Z=!1,initialWidth:J=1280}=$,[X,Y]=t2.useState(J),[G,Q]=t2.useState(!Z),z=t2.useRef(null),H=t2.useRef(null),U=t2.useCallback(()=>{let W=z.current;if(W){let K=W.offsetWidth;if(Y(K),!G)Q(!0)}},[G]);return t2.useEffect(()=>{let W=z.current;if(!W)return;if(U(),typeof ResizeObserver<"u"){let K=null;return H.current=new ResizeObserver((V)=>{let N=V[0];if(N){let B=N.contentRect.width;if(K!==null)cancelAnimationFrame(K);K=requestAnimationFrame(()=>{Y(B),K=null})}}),H.current.observe(W),()=>{if(K!==null)cancelAnimationFrame(K);if(H.current)H.current.disconnect(),H.current=null}}return()=>{if(H.current)H.current.disconnect(),H.current=null}},[U]),{width:X,mounted:G,containerRef:z,measureWidth:U}}var N1=_(x(),1),BF=_(AX(),1),VF=_(UF(),1);var c7=_(y(),1),P4=_(LL(),1);function Gz($){let{children:Z,cols:J,containerWidth:X,margin:Y,containerPadding:G,rowHeight:Q,maxRows:z,isDraggable:H,isResizable:U,isBounded:W,static:K,useCSSTransforms:V=!0,usePercentages:N=!1,transformScale:B=1,positionStrategy:q,dragThreshold:F=0,droppingPosition:L,className:A="",style:M,handle:j="",cancel:O="",x:D,y:P,w:T,h:k,minW:S=1,maxW:I=1/0,minH:E=1,maxH:w=1/0,i:C,resizeHandles:h,resizeHandle:b,constraints:f=kQ,layoutItem:g,layout:o=[],onDragStart:m,onDrag:V1,onDragStop:U1,onResizeStart:q1,onResize:e,onResizeStop:D1}=$,[v,$1]=N1.useState(!1),[K1,t]=N1.useState(!1),J1=N1.useRef(null),z1=N1.useRef({left:0,top:0}),R=N1.useRef({top:0,left:0,width:0,height:0}),i=N1.useRef(void 0),u=N1.useRef(o);u.current=o;let W1=N1.useRef(null),s=N1.useRef(null),X1=N1.useRef(!1),G1=N1.useRef({x:0,y:0}),d=N1.useRef(!1),Q1=N1.useMemo(()=>({cols:J,containerPadding:G,containerWidth:X,margin:Y,maxRows:z,rowHeight:Q}),[J,G,X,Y,z,Q]),n=N1.useMemo(()=>({cols:J,maxRows:z,containerWidth:X,containerHeight:0,rowHeight:Q,margin:Y,layout:[]}),[J,z,X,Q,Y]),L1=N1.useCallback(()=>({...n,layout:u.current}),[n]),c=N1.useMemo(()=>g??{i:C,x:D,y:P,w:T,h:k,minW:S,maxW:I,minH:E,maxH:w},[g,C,D,P,T,k,S,I,E,w]),_1=N1.useCallback((P1)=>{if(q?.calcStyle)return q.calcStyle(P1);if(V)return UX(P1);let k1=SQ(P1);if(N)return{...k1,left:CQ(P1.left/X),width:CQ(P1.width/X)};return k1},[q,V,N,X]),x1=N1.useCallback((P1,{node:k1})=>{if(!m)return;let{offsetParent:m1}=k1;if(!m1)return;let u1=m1.getBoundingClientRect(),t1=k1.getBoundingClientRect(),X0=t1.left/B,V0=u1.left/B,k0=t1.top/B,a1=u1.top/B,S0;if(q?.calcDragPosition){let C1=P1;S0=q.calcDragPosition(C1.clientX,C1.clientY,C1.clientX-t1.left,C1.clientY-t1.top)}else S0={left:X0-V0+m1.scrollLeft,top:k0-a1+m1.scrollTop};if(z1.current=S0,F>0){let C1=P1;G1.current={x:C1.clientX,y:C1.clientY},X1.current=!0,d.current=!1,$1(!0);return}$1(!0);let n0=D3(Q1,S0.top,S0.left),{x:e0,y:F1}=T3(f,c,n0.x,n0.y,L1());m(C,e0,F1,{e:P1,node:k1,newPosition:S0})},[m,B,Q1,q,F,f,c,L1,C]),$0=N1.useCallback((P1,{node:k1,deltaX:m1,deltaY:u1})=>{if(!V1||!v)return;let t1=P1;if(X1.current&&!d.current){let e0=t1.clientX-G1.current.x,F1=t1.clientY-G1.current.y;if(Math.hypot(e0,F1)<F)return;if(d.current=!0,X1.current=!1,m){let j1=D3(Q1,z1.current.top,z1.current.left),{x:c1,y:Z0}=T3(f,c,j1.x,j1.y,L1());m(C,c1,Z0,{e:P1,node:k1,newPosition:z1.current})}}let X0=z1.current.top+u1,V0=z1.current.left+m1;if(W){let{offsetParent:e0}=k1;if(e0){let F1=e0.clientHeight-o2(k,Q,Y[1]);X0=M3(X0,0,F1);let C1=k9(Q1),j1=X-o2(T,C1,Y[0]);V0=M3(V0,0,j1)}}let k0={top:X0,left:V0};z1.current=k0;let a1=D3(Q1,X0,V0),{x:S0,y:n0}=T3(f,c,a1.x,a1.y,L1());V1(C,S0,n0,{e:P1,node:k1,newPosition:k0})},[V1,m,v,F,W,k,Q,Y,Q1,X,T,C,f,c,L1]),d1=N1.useCallback((P1,{node:k1})=>{if(!U1||!v)return;let m1=X1.current;if(X1.current=!1,d.current=!1,G1.current={x:0,y:0},m1){$1(!1),z1.current={left:0,top:0};return}let{left:u1,top:t1}=z1.current,X0={top:t1,left:u1};$1(!1),z1.current={left:0,top:0};let V0=D3(Q1,t1,u1),{x:k0,y:a1}=T3(f,c,V0.x,V0.y,L1());U1(C,k0,a1,{e:P1,node:k1,newPosition:X0})},[U1,v,Q1,f,c,L1,C]);W1.current=x1,s.current=$0;let w1=N1.useCallback((P1,{node:k1,size:m1,handle:u1},t1,X0)=>{let V0=X0==="onResizeStart"?q1:X0==="onResize"?e:D1;if(!V0)return;let k0;if(k1)k0=UL(u1,t1,m1,X);else k0={...m1,top:t1.top,left:t1.left};R.current=k0;let a1=GL(Q1,k0.width,k0.height),{w:S0,h:n0}=zL(f,c,a1.w,a1.h,u1,L1());V0(C,S0,n0,{e:P1.nativeEvent,node:k1,size:k0,handle:u1})},[q1,e,D1,X,Q1,C,f,c,L1]),o1=N1.useCallback((P1,k1)=>{t(!0);let m1=O3(Q1,D,P,T,k),u1={...k1,handle:k1.handle};w1(P1,u1,m1,"onResizeStart")},[w1,Q1,D,P,T,k]),b1=N1.useCallback((P1,k1)=>{let m1=O3(Q1,D,P,T,k),u1={...k1,handle:k1.handle};w1(P1,u1,m1,"onResize")},[w1,Q1,D,P,T,k]),s1=N1.useCallback((P1,k1)=>{t(!1),R.current={top:0,left:0,width:0,height:0};let m1=O3(Q1,D,P,T,k),u1={...k1,handle:k1.handle};w1(P1,u1,m1,"onResizeStop")},[w1,Q1,D,P,T,k]);N1.useEffect(()=>{if(!L)return;let P1=J1.current;if(!P1)return;let k1=i.current||{left:0,top:0},m1=v&&(L.left!==k1.left||L.top!==k1.top);if(!v){let u1={node:P1,deltaX:L.left,deltaY:L.top,lastX:0,lastY:0,x:L.left,y:L.top};W1.current?.(L.e,u1)}else if(m1){let u1=L.left-z1.current.left,t1=L.top-z1.current.top,X0={node:P1,deltaX:u1,deltaY:t1,lastX:z1.current.left,lastY:z1.current.top,x:L.left,y:L.top};s.current?.(L.e,X0)}i.current=L},[L,v,C]);let r0=O3(Q1,D,P,T,k,v?z1.current:null,K1?R.current:null),h5=N1.default.Children.only(Z),R1=k9(Q1),r1=[o2(S,R1,Y[0]),o2(E,Q,Y[1])],_0=[o2(I,R1,Y[0]),o2(w,Q,Y[1])],g1=h5.props,q0=g1.className,o0=g1.style,M0=N1.default.cloneElement(h5,{ref:J1,className:Qz("react-grid-item",q0,A,{static:K,resizing:K1,"react-draggable":H,"react-draggable-dragging":v,dropping:Boolean(L),cssTransforms:V}),style:{...M,...o0,..._1(r0)}}),t0=b;return M0=c7.jsx(VF.Resizable,{draggableOpts:{disabled:!U},className:U?void 0:"react-resizable-hide",width:r0.width,height:r0.height,minConstraints:r1,maxConstraints:_0,onResizeStart:o1,onResize:b1,onResizeStop:s1,transformScale:B,resizeHandles:h,handle:t0,children:M0}),M0=c7.jsx(BF.DraggableCore,{disabled:!H,onStart:x1,onDrag:$0,onStop:d1,handle:j,cancel:".react-resizable-handle"+(O?","+O:""),scale:B,nodeRef:J1,children:M0}),M0}var u7=()=>{},KF="react-grid-layout",NF=!1;try{NF=/firefox/i.test(navigator.userAgent)}catch{}function fS($,Z){let J=N1.default.Children.toArray($),X=N1.default.Children.toArray(Z);if(J.length!==X.length)return!1;for(let Y=0;Y<J.length;Y++){let G=J[Y],Q=X[Y];if(G?.key!==Q?.key)return!1}return!0}function WF($,Z,J,X){let Y=[],G=new Set;N1.default.Children.forEach(Z,(z)=>{if(!N1.default.isValidElement(z)||z.key===null)return;let H=String(z.key);G.add(H);let U=$.find((W)=>W.i===H);if(U)Y.push(m7(U));else{let K=z.props["data-grid"];if(K)Y.push({i:H,x:K.x??0,y:K.y??0,w:K.w??1,h:K.h??1,minW:K.minW,maxW:K.maxW,minH:K.minH,maxH:K.maxH,static:K.static,isDraggable:K.isDraggable,isResizable:K.isResizable,resizeHandles:K.resizeHandles,isBounded:K.isBounded});else Y.push({i:H,x:0,y:j3(Y),w:1,h:1})}});let Q=wQ(Y,{cols:J});return X.compact(Q,J)}function I3($){let{children:Z,width:J,gridConfig:X,dragConfig:Y,resizeConfig:G,dropConfig:Q,positionStrategy:z=KL,compactor:H,constraints:U=kQ,layout:W=[],droppingItem:K,autoSize:V=!0,className:N="",style:B={},innerRef:q,onLayoutChange:F=u7,onDragStart:L=u7,onDrag:A=u7,onDragStop:M=u7,onResizeStart:j=u7,onResize:O=u7,onResizeStop:D=u7,onDrop:P=u7,onDropDragOver:T=u7}=$,k=N1.useMemo(()=>({...WL,...X}),[X]),S=N1.useMemo(()=>({...BL,...Y}),[Y]),I=N1.useMemo(()=>({...VL,...G}),[G]),E=N1.useMemo(()=>({...NL,...Q}),[Q]),{cols:w,rowHeight:C,maxRows:h,margin:b,containerPadding:f}=k,{enabled:g,bounded:o,handle:m,cancel:V1,threshold:U1}=S,{enabled:q1,handles:e,handleComponent:D1}=I,{enabled:v,defaultItem:$1,onDragOver:K1}=E,t=H??vQ("vertical"),J1=t.type,z1=t.allowOverlap,R=t.preventCollision??!1,i=N1.useMemo(()=>K??{i:"__dropping-elem__",...$1},[K,$1]),u=z.type==="transform",W1=z.scale,s=f??b,[X1,G1]=N1.useState(!1),[d,Q1]=N1.useState(()=>WF(W,Z,w,t)),[n,L1]=N1.useState(null),[c,_1]=N1.useState(!1),[x1,$0]=N1.useState(null),[d1,w1]=N1.useState(),o1=N1.useRef(null),b1=N1.useRef(null),s1=N1.useRef(null),r0=N1.useRef(0),h5=N1.useRef(d),R1=N1.useRef(W),r1=N1.useRef(Z),_0=N1.useRef(J1),g1=N1.useRef(d);g1.current=d,N1.useEffect(()=>{if(G1(!0),!P4.deepEqual(d,W))F(d)},[]),N1.useEffect(()=>{if(n)return;if(x1)return;let F1=!P4.deepEqual(W,R1.current),C1=!fS(Z,r1.current),j1=J1!==_0.current;if(F1||C1||j1){let Z0=WF(F1?W:d,Z,w,t);if(!P4.deepEqual(Z0,d))Q1(Z0)}R1.current=W,r1.current=Z,_0.current=J1},[W,Z,w,J1,t,n,x1,d]),N1.useEffect(()=>{if(!n&&!P4.deepEqual(d,h5.current)){h5.current=d;let F1=d.filter((C1)=>C1.i!==i.i);F(F1)}},[d,n,F,i.i]);let q0=N1.useMemo(()=>{if(!V)return;let F1=j3(d),C1=s[1];return F1*C+(F1-1)*b[1]+C1*2+"px"},[V,d,C,b,s]),o0=N1.useCallback((F1,C1,j1,c1)=>{let Z0=g1.current,Y0=C9(Z0,F1);if(!Y0)return;let C0={w:Y0.w,h:Y0.h,x:Y0.x,y:Y0.y,i:F1};o1.current=m7(Y0),s1.current=Z0,L1(C0),L(Z0,Y0,Y0,null,c1.e,c1.node)},[L]),M0=N1.useCallback((F1,C1,j1,c1)=>{let Z0=g1.current,Y0=o1.current,C0=C9(Z0,F1);if(!C0)return;let K5={w:C0.w,h:C0.h,x:C0.x,y:C0.y,i:F1},h0=w9(Z0,C0,C1,j1,!0,R,J1,w,z1);A(h0,Y0,C0,K5,c1.e,c1.node),Q1(t.compact(h0,w)),L1(K5)},[R,J1,w,z1,t,A]),t0=N1.useCallback((F1,C1,j1,c1)=>{if(!n)return;let Z0=g1.current,Y0=o1.current,C0=C9(Z0,F1);if(!C0)return;let K5=w9(Z0,C0,C1,j1,!0,R,J1,w,z1),h0=t.compact(K5,w);M(h0,Y0,C0,null,c1.e,c1.node);let I5=s1.current;if(o1.current=null,s1.current=null,L1(null),Q1(h0),I5&&!P4.deepEqual(I5,h0))F(h0)},[n,R,J1,w,z1,t,M,F]),P1=N1.useCallback((F1,C1,j1,c1)=>{let Z0=g1.current,Y0=C9(Z0,F1);if(!Y0)return;b1.current=m7(Y0),s1.current=Z0,_1(!0),j(Z0,Y0,Y0,null,c1.e,c1.node)},[j]),k1=N1.useCallback((F1,C1,j1,c1)=>{let Z0=g1.current,Y0=b1.current,{handle:C0}=c1,K5=!1,h0,I5,[v3,E7]=QL(Z0,F1,(v0)=>{if(h0=v0.x,I5=v0.y,["sw","w","nw","n","ne"].includes(C0)){if(["sw","nw","w"].includes(C0))h0=v0.x+(v0.w-C1),C1=v0.x!==h0&&h0<0?v0.w:C1,h0=h0<0?0:h0;if(["ne","n","nw"].includes(C0))I5=v0.y+(v0.h-j1),j1=v0.y!==I5&&I5<0?v0.h:j1,I5=I5<0?0:I5;K5=!0}if(R&&!z1){if(TQ(Z0,{...v0,w:C1,h:j1,x:h0??v0.x,y:I5??v0.y}).filter((m3)=>m3.i!==v0.i).length>0)I5=v0.y,j1=v0.h,h0=v0.x,C1=v0.w,K5=!1}return v0.w=C1,v0.h=j1,v0});if(!E7)return;let $8=v3;if(K5&&h0!==void 0&&I5!==void 0)$8=w9(v3,E7,h0,I5,!0,R,J1,w,z1);let g3={w:E7.w,h:E7.h,x:E7.x,y:E7.y,i:F1,static:!0};O($8,Y0,E7,g3,c1.e,c1.node),Q1(t.compact($8,w)),L1(g3)},[R,J1,w,z1,t,O]),m1=N1.useCallback((F1,C1,j1,c1)=>{let Z0=g1.current,Y0=b1.current,C0=C9(Z0,F1),K5=t.compact(Z0,w);D(K5,Y0,C0??null,null,c1.e,c1.node);let h0=s1.current;if(b1.current=null,s1.current=null,L1(null),_1(!1),Q1(K5),h0&&!P4.deepEqual(h0,K5))F(K5)},[w,t,D,F]),u1=N1.useCallback(()=>{let F1=g1.current;if(!F1.some((c1)=>c1.i===i.i)){$0(null),L1(null),w1(void 0);return}let j1=t.compact(F1.filter((c1)=>c1.i!==i.i),w);Q1(j1),$0(null),L1(null),w1(void 0)},[i.i,w,t]),t1=N1.useCallback((F1)=>{if(F1.preventDefault(),F1.stopPropagation(),NF&&!F1.nativeEvent.target?.classList.contains(KF))return!1;let C1=K1?K1(F1.nativeEvent):T(F1);if(C1===!1){if(x1)u1();return!1}let{dragOffsetX:j1=0,dragOffsetY:c1=0,...Z0}=C1??{},Y0={...i,...Z0},C0=F1.currentTarget.getBoundingClientRect(),K5={cols:w,margin:b,maxRows:h,rowHeight:C,containerWidth:J,containerPadding:s},h0=k9(K5),I5=o2(Y0.w,h0,b[0]),v3=o2(Y0.h,C,b[1]),E7=I5/2,$8=v3/2,g3=F1.clientX-C0.left+j1-E7,v0=F1.clientY-C0.top+c1-$8,gX=Math.max(0,g3),m3=Math.max(0,v0),u3={left:gX/W1,top:m3/W1,e:F1.nativeEvent};if(!x1){let mX=YL(K5,m3,gX,Y0.w,Y0.h);$0(c7.jsx("div",{},Y0.i)),w1(u3);let gM=g1.current.filter((mM)=>mM.i!==Y0.i);Q1([...gM,{...Y0,x:mX.x,y:mX.y,static:!1,isDraggable:!0}])}else if(d1){if(d1.left!==u3.left||d1.top!==u3.top)w1(u3)}},[x1,d1,i,K1,T,u1,W1,w,b,h,C,J,s]),X0=N1.useCallback((F1)=>{if(F1.preventDefault(),F1.stopPropagation(),r0.current--,r0.current<0)r0.current=0;if(r0.current===0)u1()},[u1]),V0=N1.useCallback((F1)=>{F1.preventDefault(),F1.stopPropagation(),r0.current++},[]),k0=N1.useCallback((F1)=>{F1.preventDefault(),F1.stopPropagation();let C1=g1.current,j1=C1.find((c1)=>c1.i===i.i);r0.current=0,u1(),P(C1,j1,F1.nativeEvent)},[i.i,u1,P]),a1=N1.useCallback((F1,C1)=>{if(!F1||!F1.key)return null;let j1=C9(d,String(F1.key));if(!j1)return null;let c1=typeof j1.isDraggable==="boolean"?j1.isDraggable:!j1.static&&g,Z0=typeof j1.isResizable==="boolean"?j1.isResizable:!j1.static&&q1,Y0=j1.resizeHandles||[...e],C0=c1&&o&&j1.isBounded!==!1,K5=D1;return c7.jsx(Gz,{containerWidth:J,cols:w,margin:b,containerPadding:s,maxRows:h,rowHeight:C,cancel:V1,handle:m,onDragStart:o0,onDrag:M0,onDragStop:t0,onResizeStart:P1,onResize:k1,onResizeStop:m1,isDraggable:c1,isResizable:Z0,isBounded:C0,useCSSTransforms:u&&X1,usePercentages:!X1,transformScale:W1,positionStrategy:z,dragThreshold:U1,w:j1.w,h:j1.h,x:j1.x,y:j1.y,i:j1.i,minH:j1.minH,minW:j1.minW,maxH:j1.maxH,maxW:j1.maxW,static:j1.static,droppingPosition:C1?d1:void 0,resizeHandles:Y0,resizeHandle:K5,constraints:U,layoutItem:j1,layout:d,children:F1},j1.i)},[d,J,w,b,s,h,C,V1,m,o0,M0,t0,P1,k1,m1,g,q1,o,u,X1,W1,z,U1,d1,e,D1,U]),S0=()=>{if(!n)return null;return c7.jsx(Gz,{w:n.w,h:n.h,x:n.x,y:n.y,i:n.i,className:`react-grid-placeholder ${c?"placeholder-resizing":""}`,containerWidth:J,cols:w,margin:b,containerPadding:s,maxRows:h,rowHeight:C,isDraggable:!1,isResizable:!1,isBounded:!1,useCSSTransforms:u,transformScale:W1,constraints:U,layout:d,children:c7.jsx("div",{})})},n0=Qz(KF,N),e0={height:q0,...B};return c7.jsxs("div",{ref:q,className:n0,style:e0,onDrop:v?k0:void 0,onDragLeave:v?X0:void 0,onDragEnter:v?V0:void 0,onDragOver:v?t1:void 0,children:[N1.default.Children.map(Z,(F1)=>{if(!N1.default.isValidElement(F1))return null;return a1(F1)}),v&&x1&&a1(x1,!0),S0()]})}var T4=_(y(),1);function zz({items:$,editing:Z,renderItem:J,onLayoutChange:X}){let[Y,G]=x3.useState(()=>_3($,[])),[Q,z]=x3.useState($),{width:H,containerRef:U,mounted:W}=gQ({measureBeforeMount:!0});if(Q!==$)z($),G((V)=>{let N=new Map(V.map((L)=>[L.i,L])),B=$.filter((L)=>N.has(L.id)).map((L)=>({...N.get(L.id),w:L.w,h:L.h})),q=new Set(B.map((L)=>L.i)),F=_3($.filter((L)=>!q.has(L.id)),B);return[...B,...F]});let K=x3.useCallback((V)=>{G(V),X?.(V.map((N)=>({id:N.i,w:N.w,h:N.h,x:N.x,y:N.y})))},[X]);return T4.jsx("div",{ref:U,className:"mx-auto w-full max-w-[var(--column-w)]",children:W&&T4.jsx(I3,{width:H,layout:Y,gridConfig:{cols:4,rowHeight:160,margin:[8,8],containerPadding:[0,0]},dragConfig:{enabled:!!Z},resizeConfig:{enabled:!1},compactor:E3,onLayoutChange:K,children:Y.map((V)=>T4.jsx("div",{children:T4.jsx(m0.div,{layoutId:V.i,"data-snapshot-widget":V.i,className:"size-full",transition:{type:"spring",duration:0.35,bounce:0},children:J(V.i)})},V.i))})})}function qF({items:$,editing:Z,renderItem:J,onLayoutChange:X,onRemove:Y}){return T4.jsx(zz,{items:$,editing:Z,onLayoutChange:X,renderItem:(G)=>T4.jsx(GX,{editing:Z,onRemove:Y?()=>Y(G):void 0,children:J(G)})})}var E4=_(x(),1);function LF($){let Z=y1();return O0({mutationFn:({key:J,thumbnails:X})=>p2(`/api/workspaces/${$}/thumbnails`,B5("PUT",{key:J,thumbnails:X}),"Failed to save thumbnails"),onMutate:({key:J})=>{Z.setQueryData(B1.layout($),(X)=>X?{...X,widgetThumbnails:{key:J,at:new Date().toISOString()}}:X)},onSuccess:()=>{Z.invalidateQueries({queryKey:B1.preview($)})}})}var yS=($)=>Math.min(1,400/Math.max($.offsetWidth,$.offsetHeight)),FF=($,Z)=>{let J=new Map(Z.map((X)=>[X.id,X.tag]));return[...$].sort().map((X)=>`${X}@${J.get(X)??""}`).join(" ")},vS=($)=>new Promise((Z)=>{setTimeout(()=>Z(null),$)});async function AF($){let{createContext:Z,destroyContext:J,domToDataUrl:X}=await import("/chunk-m9qja0nx.js"),Y=async()=>{let G=await Z($,{scale:yS($),type:"image/webp",quality:0.8,backgroundColor:"#ffffff",timeout:1000,onCreateForeignObjectSvg:(Q)=>{let z=document.createElement("style");z.textContent="[data-widget-chrome] { border-radius: 0 !important; box-shadow: none !important; }[data-widget-chrome]::after { display: none !important; }",Q.append(z)}});try{return await X(G)}finally{J(G)}};return Promise.race([Y(),vS(1e4)])}var gS=5000,mS=10800000;function _F({containerRef:$,widgets:Z,visibleIds:J,editing:X}){let{layout:Y,workspaceId:G}=B0(),Q=LF(G),z=E4.useRef(Q.mutate);z.current=Q.mutate;let H=E4.useRef(!1),[U,W]=E4.useState(0),K=FF(J,Z),V=Date.parse(Y.widgetThumbnails?.at??""),N=!Number.isFinite(V)||Date.now()-V>mS,B=K!==""&&(K!==Y.widgetThumbnails?.key||N);E4.useEffect(()=>{if(!B||X)return;if(document.visibilityState!=="visible"){let L=()=>W((A)=>A+1);return document.addEventListener("visibilitychange",L,{once:!0}),()=>document.removeEventListener("visibilitychange",L)}let q=!1,F=setTimeout(async()=>{if(H.current)return;H.current=!0;try{let L={};for(let A of J){if(q)return;let M=$.current?.querySelector(`[data-snapshot-widget="${CSS.escape(A)}"]`),j=M?await AF(M):null;if(j)L[A]=j}if(q)return;z.current({key:K,thumbnails:L})}finally{H.current=!1,W((L)=>L+1)}},gS);return()=>{q=!0,clearTimeout(F)}},[K,B,X,U])}var l1=_(y(),1);function MF($){return l1.jsx(tq,{name:$})}var uS=Array.from({length:10},($,Z)=>({id:`empty-widget-${Z}`,w:2,h:1}));function cS(){return l1.jsx(g6,{className:"size-full animate-none rounded-2xl [corner-shape:superellipse(1.2)]"})}function pS({onCreateWidget:$}){return l1.jsxs("div",{className:"relative min-h-0 flex-1 pt-7",children:[l1.jsx("div",{"aria-hidden":"true",children:l1.jsx(zz,{items:uS,renderItem:cS})}),l1.jsx("div",{className:"absolute inset-0 flex items-center justify-center p-6",children:l1.jsxs("div",{className:"flex h-full w-full max-w-(--column-w) flex-col items-center justify-center gap-4 bg-radial from-background from-50% to-transparent to-75% text-center",children:[l1.jsxs("div",{className:"flex flex-col gap-1.5",children:[l1.jsx("h2",{className:"font-medium",children:"A little empty here"}),l1.jsx("p",{className:"mx-auto max-w-sm text-sm text-muted-foreground",children:"Widgets are small apps that can read data, perform tasks, and show a compact view of the information that matters."})]}),l1.jsxs(M1,{type:"button",variant:"secondary",size:"sm",onClick:$,children:[l1.jsx(v5,{"data-icon":"inline-start",stroke:1.5}),"Create widget"]})]})})]})}function dS({editing:$,onCreateWidget:Z,onEditingChange:J}){return l1.jsxs("div",{className:"mx-auto mb-4 flex w-full max-w-(--column-w) shrink-0 items-center justify-end gap-2",children:[$&&l1.jsxs(M1,{type:"button",variant:"ghost",size:"sm",className:"mr-auto",onClick:Z,children:[l1.jsx(v5,{"data-icon":"inline-start",stroke:1.75}),"New widget"]}),l1.jsx(j7,{mode:"popLayout",initial:!1,children:$?l1.jsx(m0.div,{variants:{from:{opacity:0,scale:0.8,filter:"blur(4px)"},to:{opacity:1,scale:1,filter:"blur(0px)"}},initial:"from",animate:"to",exit:"from",transition:{type:"spring",duration:0.3,bounce:0},children:l1.jsx(M1,{type:"button",size:"sm",onClick:()=>J(!1),children:"Done"})},"done"):l1.jsx(m0.div,{className:"flex items-center gap-1",variants:{from:{opacity:0,scale:0.8,filter:"blur(4px)"},to:{opacity:1,scale:1,filter:"blur(0px)"}},initial:"from",animate:"to",exit:"from",transition:{type:"spring",duration:0.3,bounce:0},children:l1.jsx(M1,{type:"button",variant:"ghost",size:"sm",className:"text-muted-foreground group-hover/widgets:opacity-100 [@media(hover:hover)]:opacity-0",onClick:()=>J(!0),children:"Edit widgets"})},"actions")})]})}function lS(){return l1.jsx("div",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3",children:l1.jsx("p",{className:"text-sm text-muted-foreground",children:"No widgets added yet"})})}function iS(){let[$,Z]=r6.useState(0);return[r6.useCallback((X)=>{if(!X)return;let Y=new ResizeObserver(([G])=>{let Q=G.borderBoxSize?.[0];Z(Q?Q.blockSize:G.contentRect.height)});return Y.observe(X),()=>Y.disconnect()},[]),$]}function DF({onCreateWidget:$,editing:Z,onEditingChange:J,widgets:X}){let{layout:Y,setLayout:G}=B0(),Q=X.length>0,z=new Set(Y.widgetGrid.map((F)=>F.i)),H=Y.widgetGrid.filter((F)=>X.some((L)=>L.id===F.i)).map((F)=>{let L=X.find((A)=>A.id===F.i);return{id:F.i,w:L.config.colSpan,h:L.config.rowSpan,x:F.x,y:F.y}}),U=X.filter((F)=>!z.has(F.id)).map((F)=>({id:F.id,w:F.config.colSpan,h:F.config.rowSpan})),[W,K]=iS(),V=Z&&U.length>0,N=r6.useRef(null);_F({containerRef:N,widgets:X,visibleIds:H.map((F)=>F.id),editing:Z});function B(F){G({widgetGrid:Y.widgetGrid.filter((L)=>L.i!==F)})}function q(F){let L=X.find((j)=>j.id===F);if(!L)return;let A=Y.widgetGrid.map((j)=>{let O=X.find((D)=>D.id===j.i);return{...j,w:O?.config.colSpan??1,h:O?.config.rowSpan??1}}),M=A3(A,L.config.colSpan,L.config.rowSpan,4);G({widgetGrid:[...Y.widgetGrid,{i:F,x:M.x,y:M.y}]})}return l1.jsx("div",{ref:N,className:"group/widgets relative min-h-0 flex-1",children:l1.jsxs(OF,{children:[l1.jsx("div",{className:Z1("relative flex h-full flex-col p-4",Q?"overflow-y-auto":"overflow-hidden"),children:Q?l1.jsxs(l1.Fragment,{children:[l1.jsx(dS,{editing:Z,onCreateWidget:$,onEditingChange:J}),H.length===0?l1.jsx(m0.div,{className:"mx-auto flex min-h-0 w-full max-w-[var(--column-w)] flex-1 flex-col",animate:{paddingBottom:V?K:0},transition:{type:"spring",duration:0.3,bounce:0},children:l1.jsx(lS,{})}):l1.jsx(m0.div,{animate:{marginBottom:V?K:0},transition:{type:"spring",duration:0.3,bounce:0},children:l1.jsx(qF,{items:H,editing:Z,renderItem:MF,onRemove:B,onLayoutChange:(F)=>G({widgetGrid:F.map((L)=>({i:L.id,x:L.x??0,y:L.y??0}))})})})]}):l1.jsx(pS,{onCreateWidget:$})}),l1.jsx(j7,{children:Q&&Z&&U.length>0&&l1.jsx(JL,{ref:W,items:U,renderItem:MF,onClose:()=>J(!1),onRestore:q})})]})})}var PF=_(y(),1);function jF({children:$}){return PF.jsx("header",{className:"@container flex h-11 shrink-0 items-center gap-2.5 border-b border-border/75 pr-3 pl-4",children:$})}var Mz=_(x(),1);var M5=_(y(),1);function rS($){if($==="needs-auth")return"Needs auth";return $[0].toUpperCase()+$.slice(1)}function nS({name:$,status:Z}){let J=EF($),X="size-full rounded-lg ring-2 ring-background";return M5.jsxs("span",{className:"relative size-10 shrink-0",children:[J?M5.jsx("img",{src:J,alt:"",className:"size-full rounded-lg ring-2 ring-background"}):M5.jsx("span",{className:"flex size-full items-center justify-center rounded-lg bg-muted text-muted-foreground ring-2 ring-background",children:M5.jsx(kF,{className:"size-5"})}),Z!=="connected"&&M5.jsx(TF,{"aria-hidden":"true",size:16,stroke:1.75,className:"absolute -top-1 -right-1 rounded-full bg-card text-amber-400"})]})}function SF($){return[...$].sort((Z,J)=>Number(J.status==="connected")-Number(Z.status==="connected"))}function CF({icon:$,children:Z}){return M5.jsxs("div",{className:"flex items-center gap-3 text-card-foreground",children:[$,M5.jsx("div",{className:"flex min-w-0 flex-1 flex-col justify-center gap-0.5",children:Z})]})}function hF({server:$}){return M5.jsxs(CF,{icon:M5.jsx(nS,{name:$.name,status:$.status}),children:[M5.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:wF($.name)}),M5.jsx("span",{className:"text-sm text-muted-foreground",children:rS($.status)})]})}function IF(){return M5.jsxs(CF,{icon:M5.jsx(g6,{className:"size-10 shrink-0 rounded-lg"}),children:[M5.jsx(g6,{className:"h-4 w-36 max-w-full"}),M5.jsx(g6,{className:"h-4 w-20"})]})}function Uz({children:$}){return M5.jsx("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2",children:$})}function xF($,Z){return I0({queryKey:B1.mcp($),queryFn:()=>e1(`/api/workspaces/${$}/mcp`),enabled:Z,staleTime:1/0,gcTime:1/0,refetchOnMount:!1,refetchOnWindowFocus:!1})}var Z2=_(y(),1);function n6({title:$,description:Z,children:J}){return Z2.jsxs("div",{className:"flex flex-col gap-6",children:[Z2.jsxs("header",{className:"flex flex-col gap-0.5",children:[Z2.jsx("h2",{className:"text-lg font-medium tracking-tight",children:$}),Z&&Z2.jsx("p",{className:"text-sm text-muted-foreground",children:Z})]}),J]})}function s6({label:$,children:Z}){return Z2.jsxs("section",{className:"flex flex-col gap-2",children:[$&&Z2.jsx("p",{className:"px-0.5 text-xs font-medium text-muted-foreground",children:$}),Z2.jsx("div",{className:"flex flex-col divide-y divide-dashed divide-border overflow-hidden rounded-xl border border-border bg-card text-card-foreground",children:Z})]})}function a6({title:$,description:Z,control:J}){return Z2.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-3",children:[Z2.jsxs("div",{className:"flex min-w-0 flex-col",children:[Z2.jsx("span",{className:"text-sm font-medium",children:$}),Z&&Z2.jsx("span",{className:"text-xs text-muted-foreground",children:Z})]}),J&&Z2.jsx("div",{className:"ml-auto flex shrink-0 items-center pl-3",children:J})]})}var u5=_(y(),1),sS=Array.from({length:4},($,Z)=>Z);function aS({connectors:$}){if($.isPending)return u5.jsx("div",{role:"status","aria-label":"Loading connectors",children:u5.jsx(Uz,{children:sS.map((Z)=>u5.jsx(IF,{},Z))})});if($.isError)return u5.jsxs(RF,{children:[u5.jsx("p",{className:"text-sm text-muted-foreground",children:"Could not load connectors."}),u5.jsx(M1,{variant:"outline",size:"sm",onClick:()=>$.refetch(),children:"Retry"})]});if($.data.length===0)return u5.jsxs(RF,{children:[u5.jsx(DX,{size:24,stroke:1.5,className:"text-muted-foreground"}),u5.jsx("p",{className:"text-sm text-foreground",children:"No connectors configured."})]});return u5.jsx(Uz,{children:SF($.data).map((Z)=>u5.jsx(hF,{server:Z},Z.name))})}function RF({children:$}){return u5.jsx("div",{className:"flex min-h-48 flex-col items-center justify-center gap-3 rounded-xl border border-dashed border-border px-8 py-12 text-center",children:$})}function fF(){let{workspaceId:$}=B0(),Z=xF($,!0);return u5.jsx(n6,{title:"Connectors",description:"Connectors available to the agent in this workspace.",children:u5.jsx(aS,{connectors:Z})})}var Wz=_(x(),1);var Kz=["app-settings"];function bF(){let $=y1();return r5((Z)=>{if(Z.type==="settings:updated")$.setQueryData(Kz,Z.settings)}),I0({queryKey:Kz,queryFn:()=>e1("/api/settings"),staleTime:30000})}function yF(){let $=y1();return O0({mutationFn:(Z)=>e1("/api/settings",B5("PATCH",Z),"Failed to save settings"),onSuccess:(Z)=>{$.setQueryData(Kz,Z)}})}function vF($){return I0({queryKey:B1.env($),queryFn:()=>e1(`/api/workspaces/${$}/env`),...n2})}function gF($){let Z=y1();return O0({mutationFn:(J)=>e1(`/api/workspaces/${$}/env`,B5("PUT",J)),onSuccess:(J)=>{Z.setQueryData(B1.env($),J)}})}function mF($){let Z=y1();return O0({mutationFn:(J)=>p2(`/api/workspaces/${$}/config`,B5("PUT",{name:J}),"Failed to save name"),onSuccess:()=>{Z.invalidateQueries({queryKey:B1.layout($)}),Z.invalidateQueries({queryKey:B1.all})}})}function uF($){let Z=y1();return O0({scope:{id:`workspace-icon:${$}`},mutationFn:(J)=>e1(`/api/workspaces/${$}/icon`,{method:"PUT",headers:{"Content-Type":J.type||"application/octet-stream"},body:J}),onSuccess:()=>{Z.invalidateQueries({queryKey:B1.layout($)}),Z.invalidateQueries({queryKey:B1.all})}})}function cF($){let Z=y1();return O0({scope:{id:`workspace-icon:${$}`},mutationFn:()=>p2(`/api/workspaces/${$}/icon`,{method:"DELETE"},"Failed to reset icon"),onSuccess:()=>{Z.invalidateQueries({queryKey:B1.layout($)}),Z.invalidateQueries({queryKey:B1.all})}})}function pF($){let Z=y1();return r5((J)=>{if(J.type==="env:updated"&&J.workspaceId===$)Z.invalidateQueries({queryKey:B1.env($)})}),{env:vF($),update:gF($)}}var c0=_(y(),1),oS={dotenv:".env",custom:"secret",both:"override"},tS=/^[A-Za-z_][A-Za-z0-9_]*$/;function lF(){let{workspaceId:$}=B0(),{env:Z,update:J}=pF($),[X,Y]=Wz.useState(""),[G,Q]=Wz.useState(""),z=tS.test(X),H=z&&G.length>0&&!J.isPending,U=()=>{if(!H)return;J.mutate({set:{[X]:G}},{onSuccess:()=>{Y(""),Q("")}})},W=Z.data?.vars??[],K=Z.data?.files.reduce((N,B)=>N+B.count,0)??0,V=Z.data?.files.length??0;return c0.jsxs(n6,{title:"Environment",description:"Secrets injected into widgets and the agent at run time. Values are write-only — they're never shown again once saved.",children:[c0.jsxs(s6,{label:"Variables",children:[Z.isLoading?c0.jsx("div",{className:"flex items-center justify-center px-3.5 py-6 text-muted-foreground",children:c0.jsx(H5,{className:"size-4 animate-spin",stroke:1.75})}):W.length===0?c0.jsx("p",{className:"px-3.5 py-4 text-sm text-muted-foreground",children:"No variables yet."}):W.map((N)=>{let B=N.source!=="dotenv";return c0.jsxs("div",{className:"flex items-center gap-3 px-3.5 py-2.5",children:[c0.jsx("code",{className:"min-w-0 flex-1 truncate font-mono text-xs text-foreground",children:N.key}),c0.jsx("span",{className:"text-xs tracking-widest text-muted-foreground/60 select-none",children:"••••••"}),c0.jsx("span",{className:Z1("rounded-lg px-1.5 py-0.5 text-[11px] font-medium",N.source==="dotenv"?"bg-muted text-muted-foreground":"bg-primary/10 text-primary"),children:oS[N.source]}),!B&&c0.jsx("span",{className:"text-right text-[11px] text-muted-foreground/60",children:"from file"}),c0.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>J.mutate({remove:[N.key]}),disabled:!B,"aria-label":`Delete ${N.key}`,className:"disabled:invisible",children:c0.jsx(dF,{stroke:1.75})})]},N.key)}),c0.jsxs("div",{className:"flex items-center gap-2 px-3.5 py-2.5",children:[c0.jsx(W9,{value:X,onChange:(N)=>Y(N.target.value),placeholder:"NEW_KEY","aria-invalid":X.length>0&&!z,className:"h-7 w-40 font-mono text-xs"}),c0.jsx(W9,{value:G,onChange:(N)=>Q(N.target.value),onKeyDown:(N)=>{if(N.key==="Enter")U()},type:"password",placeholder:"value",className:"h-7 flex-1 text-xs"}),c0.jsxs(M1,{variant:"outline",size:"sm",onClick:U,disabled:!H,children:[J.isPending?c0.jsx(H5,{stroke:1.75,className:"animate-spin"}):c0.jsx(v5,{stroke:1.75}),"Add"]})]})]}),c0.jsx(s6,{label:"From .env files",children:c0.jsx(a6,{title:"Inherit .env files",description:V>0?`Discovered ${K} ${K===1?"key":"keys"} across ${V} ${V===1?"file":"files"} in this space.`:"No .env files found in this space.",control:c0.jsx(cJ,{checked:Z.data?.inheritDotenv??!0,disabled:Z.isLoading,onCheckedChange:(N)=>J.mutate({inheritDotenv:N})})})})]})}var r_=_(x(),1);var S5=_(x(),1);var E1=_(x(),1),o6=_(x(),1),V2=_(x(),1),VA=_(y(),1),PX=_(x(),1),TX=_(x(),1),i1=_(y(),1),eS=Object.defineProperty,$C=($,Z)=>{for(var J in Z)eS($,J,{get:Z[J],enumerable:!0})},p7={};$C(p7,{ActiveEmoji:()=>SA,Empty:()=>kA,List:()=>TA,Loading:()=>wA,Root:()=>AA,Search:()=>_A,SkinTone:()=>CA,SkinToneSelector:()=>EA,Viewport:()=>MA});var zA="'Apple Color Emoji', 'Noto Color Emoji', 'Twemoji Mozilla', 'Android Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', EmojiSymbols, sans-serif",Nz=["none","light","medium-light","medium","medium-dark","dark"];function Bz($){return $.charAt(0).toUpperCase()+$.slice(1)}var $7=2,c5=null;function iF($){try{c5??=document.createElement("canvas").getContext("2d",{willReadFrequently:!0})}catch{}if(!c5||(queueMicrotask(()=>{c5&&(c5=null)}),c5.canvas.width=$7,c5.canvas.height=$7,c5.font=`2px ${zA}`,c5.textBaseline="middle",c5.measureText($).width>=$7*2))return!1;c5.fillStyle="#00f",c5.fillText($,0,0);let Z=c5.getImageData(0,0,$7,$7).data;c5.clearRect(0,0,$7,$7),c5.fillStyle="#f00",c5.fillText($,0,0);let J=c5.getImageData(0,0,$7,$7).data;for(let X=0;X<$7*$7*4;X+=4)if(Z[X]!==J[X]||Z[X+1]!==J[X+1]||Z[X+2]!==J[X+2])return!1;return!0}function rF($,Z,J){try{let X=$.getItem(Z);if(!X)throw Error(`No value found for "${Z}".`);let Y=JSON.parse(X);return J(Y)}catch{return null}}function HA($,Z,J){$.setItem(Z,JSON.stringify(J))}function nF($){return(Z)=>Z===void 0?void 0:$(Z)}function sF($){return(Z)=>Z===null?null:$(Z)}function k5($){if(typeof $!="string")throw Error();return $}function jX($){if(typeof $!="number")throw Error();return $}function UA($){if(typeof $!="boolean")throw Error();return $}function x9($){return(Z)=>{if(typeof Z!="object"||Z===null)throw Error();let J={};for(let X in $){let Y=Z[X];Y===void 0&&$[X](void 0),J[X]=$[X](Y)}return J}}function Vz($){return(Z)=>{if(!Array.isArray(Z))throw Error();return Z.length>0&&$(Z[0]),Z}}var KA=($,Z)=>`${$}/${Z}/data.json`,WA=($,Z)=>`${$}/${Z}/messages.json`,ZC=["bn","da","de","en-gb","en","es-mx","es","et","fi","fr","hi","hu","it","ja","ko","lt","ms","nb","nl","pl","pt","ru","sv","th","uk","vi","zh-hant","zh"],aF="en",BA=($)=>`frimousse/data/${$}`,oF="frimousse/metadata";async function tF($,Z){try{return(await fetch($,{method:"HEAD",signal:Z})).headers.get("etag")}catch{return null}}async function JC($,Z,J){let[{emojis:X,emojisEtag:Y},{messages:G,messagesEtag:Q}]=await Promise.all([fetch(KA($,Z),{signal:J}).then(async(z)=>({emojis:await z.json(),emojisEtag:z.headers.get("etag")})),fetch(WA($,Z),{signal:J}).then(async(z)=>({messages:await z.json(),messagesEtag:z.headers.get("etag")}))]);return{emojis:X,messages:G,emojisEtag:Y,messagesEtag:Q}}async function XC($,Z,J){let[X,Y]=await Promise.all([tF(KA($,Z),J),tF(WA($,Z),J)]);return{emojisEtag:X,messagesEtag:Y}}function YC($){return $.skins?$.skins.filter((Z)=>typeof Z.tone=="number").reduce((Z,J)=>{let X=Nz[J.tone];return Z[X]=J.emoji,Z},{}):void 0}async function eF($,Z,J){let{emojis:X,emojisEtag:Y,messages:G,messagesEtag:Q}=await JC($,Z,J),z=G.subgroups.find((B)=>B.key==="country-flag"||B.key==="subdivision-flag"),H=G.groups.filter((B)=>B.key!=="component"),U=X.filter((B)=>("group"in B)),W=H.map((B)=>({index:B.order,label:Bz(B.message)})),K=G.skinTones.reduce((B,q)=>(B[q.key]=Bz(q.message),B),{}),V=U.map((B)=>({emoji:B.emoji,category:B.group,version:B.version,label:Bz(B.label),tags:B.tags??[],countryFlag:z&&B.subgroup===z.order||void 0,skins:YC(B)})),N={locale:Z,emojis:V,categories:W,skinTones:K};return HA(localStorage,BA(Z),{data:N,metadata:{emojisEtag:Y,messagesEtag:Q}}),N}function GC($,Z){let J=new Map;for(let Q of $)J.has(Q.version)||J.set(Q.version,Q.emoji);let X=[...J.keys()].sort((Q,z)=>z-Q),Y=X[0]??0,G=iF("\uD83C\uDDEA\uD83C\uDDFA");if(typeof Z=="number")return{emojiVersion:Z,countryFlags:G};for(let Q of X){let z=J.get(Q);if(iF(z))return{emojiVersion:Q,countryFlags:G}}return{emojiVersion:Y,countryFlags:G}}var QC=x9({emojiVersion:jX,countryFlags:UA}),zC=x9({data:x9({locale:k5,emojis:Vz(x9({emoji:k5,category:jX,label:k5,version:jX,tags:Vz(k5),countryFlag:nF(UA),skins:nF(x9({light:k5,"medium-light":k5,medium:k5,"medium-dark":k5,dark:k5}))})),categories:Vz(x9({index:jX,label:k5})),skinTones:x9({light:k5,"medium-light":k5,medium:k5,"medium-dark":k5,dark:k5})}),metadata:x9({emojisEtag:sF(k5),messagesEtag:sF(k5)})});async function HC({locale:$,emojiVersion:Z,emojibaseUrl:J,signal:X}){let Y=typeof J=="string"?J:`https://cdn.jsdelivr.net/npm/emojibase-data@${typeof Z=="number"?Math.floor(Z):"latest"}`,G=rF(sessionStorage,oF,QC),Q=rF(localStorage,BA($),zC),z;if(!Q)z=await eF(Y,$,X);else if(G)z=Q.data;else try{let{emojisEtag:U,messagesEtag:W}=await XC(Y,$,X);z=!U||!W||U!==Q.metadata.emojisEtag||W!==Q.metadata.messagesEtag?await eF(Y,$,X):Q.data}catch{z=Q.data}G??=GC(z.emojis,Z),HA(sessionStorage,oF,G);let H=z.emojis.filter((U)=>{let W=U.version<=G.emojiVersion;return U.countryFlag?W&&G.countryFlags:W});return{locale:$,emojis:H,categories:z.categories,skinTones:z.skinTones}}function $A($){return ZC.includes($)?$:(console.warn(`Locale "${$}" is not supported, using "${aF}" instead.`),aF)}function ZA($){return Nz.includes($)?$:(console.warn(`Skin tone "${$}" is not valid, using "none" instead.`),"none")}function UC($,Z){let J=[];if(Z<=0)return J;for(let X=0,Y=$.length;X<Y;X+=Z)J.push($.slice(X,X+Z));return J}function KC($,Z){if(!Z)return $;let J=Z.toLowerCase().trim(),X=new WeakMap;return $.filter((Y)=>{let G=0;Y.label.toLowerCase().includes(J)&&(G+=10);for(let Q of Y.tags)Q.toLowerCase().includes(J)&&(G+=1);return G>0?(X.set(Y,G),!0):!1}).sort((Y,G)=>(X.get(G)??0)-(X.get(Y)??0))}function WC($,Z,J,X){let Y=KC($.emojis,X),G=[],Q=[],z=[],H={},U=0,W=0;for(let K of Y)H[K.category]||(H[K.category]=[]),H[K.category].push({emoji:J&&J!=="none"&&K.skins?K.skins[J]:K.emoji,label:K.label});for(let K of $.categories){let V=H[K.index];if(!V||V.length===0)continue;let N=UC(Array.from(V),Z).map((B)=>({categoryIndex:U,emojis:B}));G.push(...N),Q.push({label:K.label,rowsCount:N.length,startRowIndex:W}),z.push(W),U++,W+=N.length}return{count:Y.length,categories:Q,categoriesStartRowIndices:z,rows:G,skinTones:$.skinTones}}function BC($){let Z={},J=null,X=null,Y=new Set,G=()=>{if(J){Z=J,J=null;for(let U of Y)U(Z)}X=null},Q=()=>J??Z,z=(U)=>{J??=Z,Object.assign(J,typeof U=="function"?U(Q()):U),X||(X=requestAnimationFrame(G))},H=(U)=>(Y.add(U),()=>Y.delete(U));return Z=$(z,Q),{get:Q,set:z,subscribe:H}}function VC($){let[Z]=V2.useState($);return Z}function NC($){let Z=V2.createContext(null);return{useStore:()=>{let J=V2.useContext(Z);if(!J)throw Error($);return J},Provider:({store:J,children:X})=>VA.jsx(Z.Provider,{value:J,children:X})}}function B2($,Z,J=Object.is){let[X,Y]=V2.useState(()=>Z($.get()));return V2.useEffect(()=>$.subscribe(()=>{let G=Z($.get());Y((Q)=>J(Q,G)?Q:G)}),[$,Z,J]),V2.useDebugValue(X),X}function P7($,Z,J){let X=V2.useCallback((Y)=>Y[Z],[Z]);return B2($,X,J)}var JA=2;function qC($,Z,J,X,Y){let G=0;return BC((Q,z)=>({locale:Z,columns:J,sticky:X,skinTone:Y,onEmojiSelect:$,data:null,search:"",interaction:"none",activeColumnIndex:0,activeRowIndex:0,rowHeight:null,categoryHeaderHeight:null,viewportWidth:null,viewportHeight:null,viewportCurrentCategoryIndex:null,viewportStartCategoryIndex:0,viewportStartRowIndex:0,viewportEndRowIndex:0,rootRef:null,searchRef:null,viewportRef:null,listRef:null,updateViewportState:(H)=>{let U=z(),W=H?.data??U.data,K=H?.categoryHeaderHeight??U.categoryHeaderHeight,V=H?.rowHeight??U.rowHeight,N=H?.viewportHeight??U.viewportHeight;if(!W||W.rows.length===0||!K||!V||!N)return Q({...H,viewportStartCategoryIndex:0,viewportStartRowIndex:0,viewportEndRowIndex:0});let B=0,q=0;for(let T of W.categories)if(q++*K+T.startRowIndex*V<G)B+=K;else break;let F=W.categories.length*K+W.rows.length*V,L=Math.floor(JA*V/2),A=Math.ceil(JA*V/2),M=Math.min(G-B-L,F-N),j=M+N+A,O=Math.max(0,Math.floor(M/V)),D=Math.min(W.rows.length-1,Math.ceil(j/V)),P=W.rows[O]?.categoryIndex;return Q(P===void 0&&H?H:{...H,viewportStartCategoryIndex:P,viewportStartRowIndex:O,viewportEndRowIndex:D})},onDataChange:(H)=>{z().updateViewportState({data:H,activeColumnIndex:0,activeRowIndex:0})},onSearchChange:(H)=>{Q({search:H,interaction:H?"keyboard":"none"})},onActiveEmojiChange:(H,U,W)=>{if(Q({interaction:H,activeColumnIndex:U,activeRowIndex:W}),H!=="keyboard")return;let{listRef:K,viewportRef:V,sticky:N,rowHeight:B,viewportHeight:q,categoryHeaderHeight:F}=z(),L=K?.current,A=V?.current;if(!L||!A||!B||!F||!q)return;let M=W;M===0&&A.scrollTo({top:0,behavior:"instant"});let j=L.querySelector(`[aria-rowindex="${M}"]`);if(!(j instanceof HTMLElement))return;let O=j.offsetTop,D=getComputedStyle(j),P=Number.parseFloat(D.scrollMarginTop),T=Number.parseFloat(D.scrollMarginBottom),k=G+P;N&&O<G+q/2&&(k+=F);let S=k+q-T;(O<k||O+B>S)&&A.scrollTo({top:Math.max(O<k+F?O-Math.max(N?F:0,P):O-q+B+T,0),behavior:"instant"})},onActiveEmojiReset:()=>{Q({interaction:"none",activeColumnIndex:0,activeRowIndex:0})},onRowHeightChange:(H)=>{z().updateViewportState({rowHeight:H})},onCategoryHeaderHeightChange:(H)=>{z().updateViewportState({categoryHeaderHeight:H})},onViewportSizeChange:(H,U)=>{z().updateViewportState({viewportWidth:H,viewportHeight:U})},onViewportScroll:(H)=>{G=H,z().updateViewportState()}}))}var{useStore:J2,Provider:LC}=NC("EmojiPicker.Root is missing.");function FC($){return $.search}function qz($){return $.interaction==="none"?void 0:$.data?.rows[$.activeRowIndex]?.emojis[$.activeColumnIndex]}function AC($){return $.data===void 0||typeof $.data?.count=="number"&&$.data.count===0}function _C($){return $.data===null||$.viewportHeight===null||$.rowHeight===null||$.categoryHeaderHeight===null}function NA($){return $.data?.rows.length}function MC($){return $.data?.categories.length}function OC($){return $.data?.categoriesStartRowIndices}function DC($){return $.data?.skinTones}function qA($,Z){return $?.emoji===Z?.emoji}function jC($,Z){return $?.categoryIndex!==Z?.categoryIndex||$?.emojis.length!==Z?.emojis.length?!1:!!$?.emojis.every((J,X)=>qA(J,Z?.emojis[X]))}var R3="",XA=/\p{Emoji_Modifier_Base}/u,PC=/\uFE0F$/,TC=/\u{1F3FB}|\u{1F3FC}|\u{1F3FD}|\u{1F3FE}|\u{1F3FF}/gu,EC={light:"\uD83C\uDFFB","medium-light":"\uD83C\uDFFC",medium:"\uD83C\uDFFD","medium-dark":"\uD83C\uDFFE",dark:"\uD83C\uDFFF"};function wC($,Z){if(!$.split(R3).some((X)=>XA.test(X)))return $;let J=$.split(R3).map((X)=>X.replace(TC,"")).join(R3);return Z==="none"?J:J.split(R3).map((X,Y,G)=>{let Q=G.length>1;return!XA.test(X)||Q&&X==="\uD83E\uDD1D"?X:X.replace(PC,"")+EC[Z]}).join(R3)}function kC($){return Nz.map((Z)=>({skinTone:Z,emoji:wC($,Z)}))}function LA(){let $=J2(),Z=B2($,qz,qA);return o6.useDeferredValue(Z)}function FA($="✋"){let Z=J2(),J=P7(Z,"skinTone"),X=o6.useMemo(()=>kC($),[$]),Y=o6.useCallback((G)=>{Z.set({skinTone:G})},[]);return[J,Y,X]}function Lz($,Z){if(Object.is($,Z))return!0;if(typeof $!="object"||typeof Z!="object"||$===null||Z===null||Array.isArray($)!==Array.isArray(Z))return!1;let J=Object.keys($),X=Object.keys(Z);return J.length!==X.length?!1:J.every((Y)=>(Y in Z)&&$[Y]===Z[Y])}function SC(...$){}function CC($,Z){let J=null;if(typeof window.requestIdleCallback=="function")J=window.requestIdleCallback($,Z);else{let X=Date.now();J=window.setTimeout(()=>{$({didTimeout:!1,timeRemaining:()=>Math.max(0,(Z?.timeout??50)-(Date.now()-X))})},10)}return()=>{typeof window.cancelIdleCallback=="function"?window.cancelIdleCallback(J):window.clearTimeout(J)}}var Z7=typeof window<"u"?PX.useLayoutEffect:PX.useEffect;function hC($){let Z=TX.useRef($);return Z7(()=>{Z.current=$}),TX.useCallback((...J)=>Z.current(...J),[])}function IC({emojiVersion:$,emojibaseUrl:Z}){let[J,X]=E1.useState(void 0),Y=J2(),G=P7(Y,"locale"),Q=P7(Y,"columns"),z=P7(Y,"skinTone"),H=P7(Y,"search");return E1.useEffect(()=>{let U=new AbortController,W=U.signal;return HC({locale:G,emojiVersion:$,emojibaseUrl:Z,signal:W}).then((K)=>{X(K)}).catch((K)=>{W.aborted||console.error(K)}),()=>{U.abort()}},[$,Z,G]),E1.useEffect(()=>{if(J)return CC(()=>{Y.get().onDataChange(WC(J,Q,z,H))},{timeout:100})},[J,Q,z,H]),null}var AA=E1.forwardRef(({locale:$="en",columns:Z=9,skinTone:J="none",onEmojiSelect:X=SC,emojiVersion:Y,emojibaseUrl:G,onFocusCapture:Q,onBlurCapture:z,children:H,style:U,sticky:W=!0,...K},V)=>{let N=hC(X),B=VC(()=>qC(N,$A($),Z,W,ZA(J))),[q,F]=E1.useState(!1),L=E1.useRef(null),A=E1.useCallback((O)=>{O&&(L.current=O,B.set({rootRef:L}))},[]);Z7(()=>{B.set({locale:$A($)})},[$]),Z7(()=>{B.set({columns:Z})},[Z]),Z7(()=>{B.set({sticky:W})},[W]),Z7(()=>{B.set({skinTone:ZA(J)})},[J]);let M=E1.useCallback((O)=>{Q?.(O);let{searchRef:D,viewportRef:P}=B.get(),T=O.target===D?.current||O.target.hasAttribute("frimousse-search"),k=O.target===P?.current||O.target.hasAttribute("frimousse-viewport");O.isDefaultPrevented()||(F(T||k),O.isDefaultPrevented()||(F(T||k),k?B.get().onActiveEmojiChange("keyboard",0,0):T&&B.get().search===""&&B.set({interaction:"none"})))},[Q]),j=E1.useCallback((O)=>{z?.(O),!O.isDefaultPrevented()&&!O.currentTarget.contains(O.relatedTarget)&&F(!1)},[z]);return Z7(()=>{q||B.get().onActiveEmojiReset()},[q]),E1.useImperativeHandle(V,()=>L.current),E1.useEffect(()=>{if(!q)return;function O(D){if(D.defaultPrevented||!D.key.startsWith("Arrow")&&D.key!=="Enter")return;let{data:P,onEmojiSelect:T,onActiveEmojiChange:k,interaction:S,activeColumnIndex:I,activeRowIndex:E}=B.get();if(D.key==="Enter"){let w=qz(B.get());w&&(D.preventDefault(),T(w))}if(D.key.startsWith("Arrow")){let w=I,C=E;if(D.preventDefault(),S!=="none"){if(P?.rows&&P.rows.length>0)switch(D.key){case"ArrowLeft":{if(w===0){let h=C-1,b=P.rows[h];b&&(C=h,w=b.emojis.length-1)}else w-=1;break}case"ArrowRight":{if(w===P.rows[C].emojis.length-1){let h=C+1;P.rows[h]&&(C=h,w=0)}else w+=1;break}case"ArrowUp":{let h=P.rows[C-1];h&&(C-=1,h.emojis[w]||(w=h.emojis.length-1));break}case"ArrowDown":{let h=P.rows[C+1];h&&(C+=1,h.emojis[w]||(w=h.emojis.length-1));break}}k("keyboard",w,C)}else k("keyboard",0,0)}}return document.addEventListener("keydown",O),()=>{document.removeEventListener("keydown",O)}},[q]),Z7(()=>{let O=null,D=null,P=null,T=null,k=B.subscribe((C)=>{L.current&&(O!==C.viewportWidth&&(O=C.viewportWidth,L.current.style.setProperty("--frimousse-viewport-width",`${C.viewportWidth}px`)),D!==C.viewportHeight&&(D=C.viewportHeight,L.current.style.setProperty("--frimousse-viewport-height",`${C.viewportHeight}px`)),P!==C.rowHeight&&(P=C.rowHeight,L.current.style.setProperty("--frimousse-row-height",`${C.rowHeight}px`)),T!==C.categoryHeaderHeight&&(T=C.categoryHeaderHeight,L.current.style.setProperty("--frimousse-category-header-height",`${C.categoryHeaderHeight}px`)))}),{viewportWidth:S,viewportHeight:I,rowHeight:E,categoryHeaderHeight:w}=B.get();return S&&L.current.style.setProperty("--frimousse-viewport-width",`${S}px`),I&&L.current.style.setProperty("--frimousse-viewport-height",`${I}px`),E&&L.current.style.setProperty("--frimousse-row-height",`${E}px`),w&&L.current.style.setProperty("--frimousse-category-header-height",`${w}px`),k},[]),i1.jsx("div",{"data-focused":q?"":void 0,"frimousse-root":"",onBlurCapture:j,onFocusCapture:M,...K,ref:A,style:{"--frimousse-emoji-font":zA,...U},children:i1.jsxs(LC,{store:B,children:[i1.jsx(IC,{emojiVersion:Y,emojibaseUrl:G}),H]})})}),_A=E1.forwardRef(({value:$,defaultValue:Z,onChange:J,...X},Y)=>{let G=J2(),Q=E1.useRef(null),z=E1.useCallback((K)=>{K&&(Q.current=K,G.set({searchRef:Q}))},[]),H=typeof $=="string",U=E1.useRef(H);E1.useEffect(()=>{U.current=H},[H]),Z7(()=>{G.set({search:typeof $=="string"?$:typeof Z=="string"?Z:""})},[]),Z7(()=>{typeof $=="string"&&G.get().onSearchChange($)},[$]);let W=E1.useCallback((K)=>{J?.(K),K.isDefaultPrevented()||G.get().onSearchChange(K.target.value)},[J]);return E1.useImperativeHandle(Y,()=>Q.current),i1.jsx("input",{autoCapitalize:"off",autoComplete:"off",autoCorrect:"off",enterKeyHint:"done","frimousse-search":"",placeholder:"Search…",spellCheck:!1,type:"search",...X,defaultValue:Z,onChange:W,ref:z,value:$})}),xC=E1.memo(()=>{let $=LA();return $?i1.jsx("div",{"aria-live":"polite",style:{border:0,clip:"rect(0, 0, 0, 0)",height:1,margin:-1,overflow:"hidden",padding:0,position:"absolute",whiteSpace:"nowrap",width:1,wordWrap:"normal"},children:$.label}):null}),MA=E1.forwardRef(({children:$,onScroll:Z,onKeyDown:J,style:X,...Y},G)=>{let Q=J2(),z=E1.useRef(null),H=E1.useCallback((V)=>{V&&(z.current=V,Q.set({viewportRef:z}))},[]),U=B2(Q,NA),W=B2(Q,MC),K=E1.useCallback((V)=>{Z?.(V),Q.get().onViewportScroll(V.currentTarget.scrollTop)},[Z]);return Z7(()=>{if(!z.current)return;let V=new ResizeObserver(([N])=>{let B=N?.borderBoxSize[0]?.inlineSize??0,q=N?.borderBoxSize[0]?.blockSize??0,{onViewportSizeChange:F,viewportHeight:L,viewportWidth:A}=Q.get();(L!==q||A!==B)&&F(B,q)});return V.observe(z.current),Q.get().onViewportSizeChange(z.current.offsetWidth,z.current.clientHeight),()=>{V.disconnect()}},[]),E1.useImperativeHandle(G,()=>z.current),i1.jsxs("div",{"frimousse-viewport":"",...Y,onScroll:K,ref:H,style:{position:"relative",boxSizing:"border-box",contain:"layout paint",containIntrinsicSize:typeof U=="number"&&typeof W=="number"?`var(--frimousse-viewport-width, auto) calc(${U} * var(--frimousse-row-height) + ${W} * var(--frimousse-category-header-height))`:void 0,overflowY:"auto",overscrollBehavior:"contain",scrollbarGutter:"stable",willChange:"scroll-position",...X},children:[i1.jsx(xC,{}),$]})});function OA($,Z,J){return{emoji:{...$,isActive:J},role:"gridcell","aria-colindex":Z,"aria-selected":J||void 0,"aria-label":$.label,"data-active":J?"":void 0,"frimousse-emoji":"",style:{fontFamily:"var(--frimousse-emoji-font)"},tabIndex:-1}}function DA($,Z=!1){return{role:Z?void 0:"row","aria-rowindex":Z?void 0:$,"frimousse-row":"",style:{contain:Z?void 0:"content",height:Z?void 0:"var(--frimousse-row-height)",display:"flex"}}}function jA($,Z){return{"frimousse-category":"",style:{contain:"content",top:Z?`calc(${$} * var(--frimousse-category-header-height) + ${Z.startRowIndex} * var(--frimousse-row-height))`:void 0,height:Z?`calc(var(--frimousse-category-header-height) + ${Z.rowsCount} * var(--frimousse-row-height))`:void 0,width:"100%",pointerEvents:"none",position:"absolute"}}}function PA($,Z=!1,J=!0){return{category:$,"frimousse-category-header":"",style:{contain:Z?void 0:"layout paint",height:Z?void 0:"var(--frimousse-category-header-height)",pointerEvents:"auto",position:J?"sticky":void 0,top:0}}}function YA($,Z,J,X){return{"frimousse-list-sizer":"",style:{position:"relative",boxSizing:"border-box",height:`calc(${$} * var(--frimousse-row-height) + ${Z} * var(--frimousse-category-header-height))`,paddingTop:`calc(${J} * var(--frimousse-row-height) + ${X} * var(--frimousse-category-header-height))`}}}function GA($,Z,J){return{"aria-colcount":$,"aria-rowcount":Z,"frimousse-list":"",style:{"--frimousse-list-columns":$,...J},role:"grid"}}function RC($){$.preventDefault()}var fC=E1.memo(({Emoji:$,emoji:Z,columnIndex:J,rowIndex:X})=>{let Y=J2(),G=B2(Y,(U)=>qz(U)?.emoji===Z.emoji),Q=E1.useCallback(()=>{Y.get().onEmojiSelect(Z)},[Z]),z=E1.useCallback(()=>{Y.get().onActiveEmojiChange("pointer",J,X)},[J,X]),H=E1.useCallback(()=>{Y.get().onActiveEmojiReset()},[]);return i1.jsx($,{...OA(Z,J,G),onClick:Q,onPointerDown:RC,onPointerEnter:z,onPointerLeave:H})}),bC=E1.memo(({Row:$,Emoji:Z,rowIndex:J})=>{let X=J2(),Y=B2(X,(G)=>G.data?.rows[J],jC);return Y?i1.jsx($,{...DA(J),children:Y.emojis.map((G,Q)=>i1.jsx(fC,{Emoji:Z,columnIndex:Q,emoji:G,rowIndex:J},G.label))}):null}),yC=E1.memo(({CategoryHeader:$,categoryIndex:Z})=>{let J=J2(),X=B2(J,(G)=>G.data?.categories[Z],Lz),Y=P7(J,"sticky");return X?i1.jsx("div",{...jA(Z,X),children:i1.jsx($,{...PA({label:X.label},!1,Y)})}):null}),QA=E1.memo(({CategoryHeader:$,Row:Z,Emoji:J})=>{let X=E1.useRef(null),Y=J2(),G=P7(Y,"columns"),Q=E1.useMemo(()=>Array(G).fill({emoji:"\uD83D\uDE42",label:""}),[G]),z=E1.useMemo(()=>({label:"Category"}),[]),H=E1.useRef(null),U=E1.useRef(null);return Z7(()=>{let W=X.current?.parentElement?.parentElement;if(!W||!H.current||!U.current)return;let K=new ResizeObserver((B)=>{for(let q of B){let F=q.contentRect.height,{onRowHeightChange:L,onCategoryHeaderHeightChange:A,rowHeight:M,categoryHeaderHeight:j}=Y.get();q.target===H.current&&M!==F&&L(F),q.target===U.current&&j!==F&&A(F)}});K.observe(W),K.observe(H.current),K.observe(U.current);let{onRowHeightChange:V,onCategoryHeaderHeightChange:N}=Y.get();return V(H.current.clientHeight),N(U.current.clientHeight),()=>{K.disconnect()}},[]),i1.jsxs("div",{"aria-hidden":!0,ref:X,style:{height:0,visibility:"hidden"},children:[i1.jsx("div",{"frimousse-row-sizer":"",ref:H,children:i1.jsx(Z,{...DA(-1,!0),children:Q.map((W,K)=>i1.jsx(J,{...OA(W,K,!1)},K))})}),i1.jsx("div",{...jA(-1),children:i1.jsx("div",{"frimousse-category-header-sizer":"",ref:U,children:i1.jsx($,{...PA(z,!0)})})})]})});function vC({category:$,...Z}){return i1.jsx("div",{...Z,children:$.label})}function gC({emoji:$,...Z}){return i1.jsx("button",{type:"button",...Z,children:$.emoji})}function mC({...$}){return i1.jsx("div",{...$})}var TA=E1.forwardRef(({style:$,components:Z,...J},X)=>{let Y=J2(),G=E1.useRef(null),Q=E1.useCallback((L)=>{L&&(G.current=L,Y.set({listRef:G}))},[]),z=Z?.CategoryHeader??vC,H=Z?.Emoji??gC,U=Z?.Row??mC,W=P7(Y,"columns"),K=P7(Y,"viewportStartRowIndex"),V=P7(Y,"viewportEndRowIndex"),N=B2(Y,NA),B=B2(Y,OC,Lz),q=E1.useMemo(()=>B?.filter((L)=>L<K).length??0,[B,K]),F=B?.length??0;return E1.useImperativeHandle(X,()=>G.current),!N||!B||F===0?i1.jsx("div",{...GA(W,0,$),...J,children:i1.jsx("div",{...YA(0,0,0,0),children:i1.jsx(QA,{CategoryHeader:z,Emoji:H,Row:U})})}):i1.jsx("div",{...GA(W,N,$),...J,ref:Q,children:i1.jsxs("div",{...YA(N,F,K,q),children:[i1.jsx(QA,{CategoryHeader:z,Emoji:H,Row:U}),Array.from({length:V-K+1},(L,A)=>{let M=K+A,j=B.indexOf(M);return i1.jsxs(E1.Fragment,{children:[j>=0&&i1.jsx("div",{style:{height:"var(--frimousse-category-header-height)"}}),i1.jsx(bC,{Emoji:H,Row:U,rowIndex:M})]},M)}),Array.from({length:F},(L,A)=>i1.jsx(yC,{CategoryHeader:z,categoryIndex:A},A))]})})}),EA=E1.forwardRef(({emoji:$,onClick:Z,"aria-label":J="Change skin tone",...X},Y)=>{let G=J2(),Q=B2(G,DC,Lz),[z,H,U]=FA($),W=E1.useMemo(()=>Math.max(0,U.findIndex((F)=>F.skinTone===z)),[z,U]),K=U[W],V=U[(W+1)%U.length].skinTone,N=z==="none"?void 0:Q?.[z],B=V==="none"?void 0:Q?.[V],q=E1.useCallback((F)=>{Z?.(F),F.isDefaultPrevented()||H(V)},[Z,H,V]);return i1.jsx("button",{type:"button",...X,"aria-label":J+(B?` (${B})`:""),"aria-live":"polite","aria-valuetext":N,"frimousse-skin-tone-selector":"",onClick:q,ref:Y,children:K.emoji})});function wA({children:$,...Z}){let J=J2();return B2(J,_C)?i1.jsx("span",{"frimousse-loading":"",...Z,children:$}):null}function uC({children:$}){let Z=J2(),J=B2(Z,FC);return $({search:J})}function kA({children:$,...Z}){let J=J2();return B2(J,AC)?i1.jsx("span",{"frimousse-empty":"",...Z,children:typeof $=="function"?i1.jsx(uC,{children:$}):$}):null}function SA({children:$}){let Z=LA();return $({emoji:Z})}function CA({children:$,emoji:Z}){let[J,X,Y]=FA(Z);return $({skinTone:J,setSkinTone:X,skinToneVariations:Y})}AA.displayName="EmojiPicker.Root";_A.displayName="EmojiPicker.Search";MA.displayName="EmojiPicker.Viewport";TA.displayName="EmojiPicker.List";wA.displayName="EmojiPicker.Loading";kA.displayName="EmojiPicker.Empty";EA.displayName="EmojiPicker.SkinToneSelector";SA.displayName="EmojiPicker.ActiveEmoji";CA.displayName="EmojiPicker.SkinTone";var f3=["rocket","sparkles","bolt","flame","star","heart","diamond","trophy","target","bulb","brain","robot","wand","atom","flask","cpu","code","terminal","api","database","cube","hexagon","plug","tool","settings","bug","activity","chart","briefcase","folder","file","book","message","mail","bell","paperclip","key","shield","user","home","globe","world","planet","compass","map","calendar","cloud","sun","moon","snowflake","leaf","mountain","feather","ghost","music","piano","camera","photo","palette","gamepad","gift","cart","chef"],cC=new Set(f3);function hA($){return cC.has($)}var R_={rocket:M_,sparkles:P_,bolt:bA,flame:$_,star:T_,heart:G_,diamond:tA,trophy:C_,target:w_,bulb:mA,brain:vA,robot:__,wand:I_,atom:RA,flask:Z_,cpu:nA,code:iA,terminal:k_,api:xA,database:aA,cube:sA,hexagon:Q_,plug:A_,tool:S_,settings:b3,bug:gA,activity:IA,chart:pA,briefcase:nJ,folder:J_,file:x6,book:yA,message:W_,mail:U_,bell:fA,paperclip:lJ,key:EX,shield:O_,user:h_,home:z_,globe:Y_,world:x_,planet:F_,compass:rA,map:K_,calendar:uA,cloud:lA,sun:E_,moon:B_,snowflake:j_,leaf:H_,mountain:V_,feather:eA,ghost:y7,music:N_,piano:sJ,camera:cA,photo:L_,palette:q_,gamepad:oA,gift:X_,cart:D_,chef:dA},Fz=f3.map(($)=>({id:$,Icon:R_[$]}));function wX($){return $&&hA($)?R_[$]:null}var _z=[{id:"sunrise",gradient:{angle:140,stops:["#FFE29F","#FFA99F","#FF719A"]}},{id:"ocean",gradient:{angle:135,stops:["#67E8F9","#3B82F6","#4F46E5"]}},{id:"meadow",gradient:{angle:135,stops:["#A7F3D0","#34D399","#059669"]}},{id:"dusk",gradient:{angle:120,stops:["#C471F5","#FA71CD"]}},{id:"midnight",gradient:{angle:135,stops:["#30CFD0","#330867"]}}];function Az($,Z,J){let X=J*Math.PI/180,Y=Z*Math.cos(X),G=Z*Math.sin(X),Q=($+0.3963377774*Y+0.2158037573*G)**3,z=($-0.1055613458*Y-0.0638541728*G)**3,H=($-0.0894841775*Y-1.291485548*G)**3;return`#${[4.0767416621*Q-3.3077115913*z+0.2309699292*H,-1.2684380046*Q+2.6097574011*z-0.3413193965*H,-0.0041960863*Q-0.7034186147*z+1.707614701*H].map((W)=>{let K=Math.min(1,Math.max(0,W)),V=K<=0.0031308?12.92*K:1.055*K**0.4166666666666667-0.055;return Math.round(V*255).toString(16).padStart(2,"0")}).join("")}`}function f_(){let $=Math.random()*360,Z=(35+Math.random()*55)*(Math.random()<0.5?-1:1),J=Math.round(115+Math.random()*55),X=Az(0.83+Math.random()*0.06,0.09+Math.random()*0.06,$),Y=Az(0.5+Math.random()*0.14,0.17+Math.random()*0.07,$+Z);if(Math.random()<0.4){let G=Az(0.7+Math.random()*0.05,0.15,$+Z/2);return{angle:J,stops:[X,G,Y]}}return{angle:J,stops:[X,Y]}}var pC="radial-gradient(120% 100% at 28% 12%, rgba(255,255,255,0.32), rgba(255,255,255,0) 58%)";function kX($){return`${pC}, linear-gradient(${$.angle}deg, ${$.stops.join(", ")})`}var U5=256;function b_($,Z){let J=Z.angle*Math.PI/180,X=Math.sin(J),Y=-Math.cos(J),G=U5*(Math.abs(X)+Math.abs(Y))/2,Q=U5/2,z=$.createLinearGradient(Q-X*G,Q-Y*G,Q+X*G,Q+Y*G),H=Z.stops.length-1;Z.stops.forEach((W,K)=>z.addColorStop(H===0?0:K/H,W)),$.fillStyle=z,$.fillRect(0,0,U5,U5);let U=$.createRadialGradient(U5*0.28,U5*0.12,0,U5*0.28,U5*0.12,U5*1.1);U.addColorStop(0,"rgba(255,255,255,0.32)"),U.addColorStop(0.58,"rgba(255,255,255,0)"),$.fillStyle=U,$.fillRect(0,0,U5,U5)}function y_($){return new Promise((Z,J)=>{$.toBlob((X)=>X?Z(X):J(Error("Canvas is empty")),"image/png")})}function v_(){let $=document.createElement("canvas");$.width=U5,$.height=U5;let Z=$.getContext("2d");if(!Z)throw Error("2D canvas unavailable");return[$,Z]}var dC=0.92,lC=0.68;async function g_($,Z){let[J,X]=v_();if(Z)b_(X,Z);X.textAlign="center",X.textBaseline="middle";let Y=Z?lC:dC;return X.font=`${Math.round(U5*Y)}px "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji",sans-serif`,X.fillText($,U5/2,U5/2+U5*0.04),y_(J)}function iC($){return new Promise((Z,J)=>{let X=new Image;X.onload=()=>Z(X),X.onerror=()=>J(Error("Failed to load SVG")),X.src=$})}var rC=0.78,nC=0.6;async function m_($,Z){let[J,X]=v_();if(Z)b_(X,Z);let Y=Z?"#ffffff":"#18181b",G=$.replace(/currentColor/g,Y),Q=await iC(`data:image/svg+xml;utf8,${encodeURIComponent(G)}`),z=U5*(Z?nC:rC),H=(U5-z)/2;return X.drawImage(Q,H,H,z,z),y_(J)}var u_=["\uD83D\uDE80","✨","\uD83D\uDD25","⚡","\uD83D\uDCA1","\uD83E\uDDE0","\uD83E\uDD16","\uD83E\uDE84","\uD83E\uDDEA","⚙️","\uD83D\uDEE0️","\uD83D\uDCBB","\uD83D\uDCE6","\uD83D\uDCCA","\uD83D\uDCC8","\uD83D\uDCDD","\uD83D\uDCDA","\uD83C\uDFAF","\uD83C\uDFC6","\uD83D\uDC8E","\uD83E\uDE90","\uD83C\uDF0D","\uD83E\uDDED","\uD83C\uDFA8","\uD83C\uDFAE","☕"],SX="font-[Apple_Color_Emoji,Segoe_UI_Emoji,Noto_Color_Emoji,sans-serif]";var S1=_(y(),1);function sC({category:$,...Z}){return S1.jsx("div",{className:"bg-background px-2.5 pt-2.5 pb-1 text-xs font-medium text-muted-foreground",...Z,children:$.label})}function aC({children:$,...Z}){return S1.jsx("div",{className:"scroll-my-1 px-1.5",...Z,children:$})}function oC({emoji:$,...Z}){return S1.jsx("button",{className:Z1("flex size-9 items-center justify-center rounded-xl text-[22px] transition-colors duration-75 data-active:bg-muted",SX),...Z,children:$.emoji})}function i_({icon:$}){let{workspaceId:Z,provider:J}=B0(),{isPending:X,mutateAsync:Y}=uF(Z),{isPending:G,mutate:Q}=cF(Z),[z,H]=S5.useState("emoji"),[U,W]=S5.useState({id:"sunrise",gradient:_z[0].gradient}),[K,V]=S5.useState(null),[N,B]=S5.useState(null),[q,F]=S5.useState(""),[L,A]=S5.useState(null),[M,j]=S5.useState(null),[O,D]=S5.useState(!1),[P,T]=S5.useState(null),k=S5.useRef(null),S=S5.useRef(null),I=S5.useRef(null),E=Fz.find((m)=>m.id===L),w=U.gradient!==null,C=X||G,h=()=>{let m=f_();V(m),W({id:"shuffle",gradient:m})},b=(m)=>{T(null),I.current=m,H("upload"),j(URL.createObjectURL(m))};S5.useEffect(()=>{let m=!1,V1=async()=>{let q1;if(z==="upload"){if(!I.current)return;q1=I.current}else if(z==="emoji"){if(!N)return;q1=await g_(N,U.gradient)}else{let e=S.current?.querySelector("svg");if(!e)return;q1=await m_(new XMLSerializer().serializeToString(e),U.gradient)}if(!m)await Y(q1)};T(null);let U1=window.setTimeout(()=>{V1().catch((q1)=>{if(!m)T(q1 instanceof Error?q1.message:"Failed to save icon")})},150);return()=>{m=!0,window.clearTimeout(U1)}},[U.gradient,N,z,Y,E,M]),S5.useEffect(()=>{return()=>{if(M)URL.revokeObjectURL(M)}},[M]);let f=()=>{I.current=null,B(null),A(null),j(null),T(null),Q()},g=z==="emoji"&&N?"emoji":z==="icon"&&E?"glyph":"image",o=z==="upload"&&M?M:$??l2[J??"claude-code"];return S1.jsxs("div",{className:"flex gap-6",children:[S1.jsxs("div",{className:"flex w-24 shrink-0 flex-col items-center gap-2.5",children:[S1.jsx("div",{className:Z1("flex size-24 items-center justify-center overflow-hidden rounded-xl shadow-sm ring-1 ring-border",g!=="image"&&!w&&"bg-[repeating-conic-gradient(#0000000d_0%_25%,transparent_0%_50%)] bg-[length:16px_16px]"),style:g!=="image"&&U.gradient?{background:kX(U.gradient)}:void 0,children:g==="emoji"?S1.jsx("span",{className:Z1("leading-none",SX,w?"text-[64px]":"text-[86px]"),children:N}):g==="glyph"&&E?S1.jsx(E.Icon,{stroke:1.5,className:Z1(w?"size-14 text-white":"size-18 text-foreground")}):S1.jsx("img",{src:o,alt:"",className:"size-full object-cover"})}),S1.jsx("button",{type:"button",onClick:f,disabled:C,className:"text-xs text-muted-foreground transition-colors hover:text-foreground disabled:opacity-50",children:"Reset to default"})]}),S1.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-3",children:[S1.jsx("div",{className:"flex gap-1 self-start rounded-xl bg-muted p-0.5",children:["emoji","icon","upload"].map((m)=>S1.jsx("button",{type:"button",onClick:()=>H(m),className:Z1("rounded-lg px-3.5 py-1 text-xs font-medium capitalize transition-colors",z===m?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"),children:m},m))}),S1.jsxs("div",{className:Z1("flex items-center gap-2",z==="upload"&&"pointer-events-none opacity-35"),children:[S1.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"Background"}),S1.jsxs("div",{className:"flex items-center gap-2",children:[S1.jsx("button",{type:"button","aria-label":"No background",onClick:()=>W({id:"none",gradient:null}),className:Z1("flex size-7 items-center justify-center rounded-full bg-muted ring-offset-2 ring-offset-card transition-shadow",U.id==="none"?"ring-2 ring-primary":"ring-1 ring-border hover:ring-muted-foreground/30"),children:S1.jsx(p_,{size:16,stroke:1.75,className:"text-muted-foreground"})}),_z.map((m)=>S1.jsx("button",{type:"button","aria-label":`${m.id} background`,onClick:()=>W({id:m.id,gradient:m.gradient}),style:{background:kX(m.gradient)},className:Z1("size-7 rounded-full ring-offset-2 ring-offset-card transition-shadow",U.id===m.id?"ring-2 ring-primary":"hover:ring-2 hover:ring-muted-foreground/30")},m.id)),S1.jsx("button",{type:"button","aria-label":"Random background",title:"Surprise me",onClick:h,style:K?{background:kX(K)}:void 0,className:Z1("flex size-7 items-center justify-center rounded-full ring-offset-2 ring-offset-card transition-shadow",K?"text-white":"bg-muted text-muted-foreground ring-1 ring-border",U.id==="shuffle"?"ring-2 ring-primary":"hover:ring-2 hover:ring-muted-foreground/30"),children:S1.jsx(c_,{size:16,stroke:1.75})})]})]}),z==="emoji"?S1.jsxs(p7.Root,{onEmojiSelect:(m)=>B(m.emoji),emojibaseUrl:"/vendor/emojibase",columns:13,className:"isolate flex h-72 flex-col overflow-hidden rounded-xl border border-border bg-background",children:[S1.jsxs("div",{className:"flex items-center gap-1.5 p-1.5 pb-0",children:[S1.jsx(p7.Search,{placeholder:"Search emoji…",onChange:(m)=>F(m.target.value),className:"h-8 min-w-0 flex-1 appearance-none rounded-lg bg-muted px-2.5 text-sm outline-none placeholder:text-muted-foreground"}),S1.jsx(p7.SkinToneSelector,{className:"size-8 shrink-0 rounded-lg text-lg hover:bg-accent"})]}),S1.jsxs(p7.Viewport,{className:"relative scrollbar-thin flex-1 overflow-y-auto outline-none",children:[S1.jsxs(p7.Loading,{className:"absolute inset-0 flex items-center justify-center gap-2 text-xs text-muted-foreground",children:[S1.jsx(H5,{size:16,stroke:1.75,className:"animate-spin"}),"Loading emoji…"]}),q.trim()===""&&S1.jsxs("div",{className:"border-b border-dashed border-border pb-1.5",children:[S1.jsx("p",{className:"px-2.5 pt-2.5 pb-1 text-xs font-medium text-muted-foreground",children:"Favorites"}),S1.jsx("div",{className:"grid grid-cols-13 justify-items-start px-1.5",children:u_.map((m)=>S1.jsx("button",{type:"button",onClick:()=>B(m),className:Z1("flex size-9 items-center justify-center rounded-xl text-[22px] transition-colors duration-75",SX,N===m?"bg-primary/10":"hover:bg-accent"),children:m},m))})]}),S1.jsxs(p7.Empty,{className:"absolute inset-0 flex flex-col items-center justify-center gap-1 text-xs text-muted-foreground",children:[S1.jsx(d_,{size:20,stroke:1.5}),"No emoji found"]}),S1.jsx(p7.List,{className:"pb-1.5 select-none",components:{CategoryHeader:sC,Row:aC,Emoji:oC}})]})]}):z==="icon"?S1.jsx("div",{className:"grid scrollbar-thin h-72 grid-cols-[repeat(auto-fill,minmax(2.25rem,1fr))] content-start gap-1 overflow-y-auto rounded-xl border border-border bg-background p-1.5",children:Fz.map(({id:m,Icon:V1})=>S1.jsx("button",{type:"button","aria-label":m,onClick:()=>A(m),className:Z1("flex aspect-square items-center justify-center rounded-xl text-muted-foreground transition-colors [&_svg]:size-5",L===m?"bg-primary/10 text-primary":"hover:bg-accent hover:text-accent-foreground"),children:S1.jsx(V1,{stroke:1.5})},m))}):S1.jsxs("button",{type:"button",onClick:()=>k.current?.click(),onDragOver:(m)=>{m.preventDefault(),D(!0)},onDragLeave:()=>D(!1),onDrop:(m)=>{m.preventDefault(),D(!1);let V1=m.dataTransfer.files?.[0];if(V1)b(V1)},className:Z1("flex h-72 flex-col items-center justify-center gap-2 rounded-xl border border-dashed transition-colors",O?"border-primary bg-primary/5 text-primary":"border-border text-muted-foreground hover:border-muted-foreground/30 hover:text-foreground"),children:[S1.jsx(l_,{size:24,stroke:1.5}),S1.jsx("span",{className:"text-xs font-medium",children:"Click or drop an image"}),S1.jsx("span",{className:"text-[11px] text-muted-foreground/70",children:"PNG, JPG, GIF, or WebP"})]}),S1.jsx("div",{className:"min-h-4","aria-live":"polite",children:P?S1.jsx("p",{className:"text-xs text-destructive",children:P}):C?S1.jsx("p",{className:"text-xs text-muted-foreground",children:"Saving…"}):null})]}),S1.jsx("input",{ref:k,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",className:"hidden",onChange:(m)=>{let V1=m.target.files?.[0];if(V1)b(V1);m.target.value=""}}),S1.jsx("span",{ref:S,"aria-hidden":!0,className:"hidden",children:E&&S1.jsx(E.Icon,{stroke:1.5})})]})}var O5=_(y(),1);function n_(){let{name:$,icon:Z,cwd:J,workspaceId:X}=B0(),[,Y]=C2(),G=mF(X),Q=TK(),[z,H]=r_.useState($??"");return O5.jsxs(n6,{title:"General",description:"Basic details for this space.",children:[O5.jsxs(s6,{children:[O5.jsx(a6,{title:"Name",description:"Shown in the sidebar and the workspace header.",control:O5.jsx(W9,{value:z,onChange:(K)=>H(K.target.value),onBlur:()=>{let K=z.trim();if(K===($??""))return;G.mutate(K===""?null:K)},onKeyDown:(K)=>{if(K.key==="Enter")K.currentTarget.blur()},placeholder:"Space name",className:"w-56"})}),O5.jsx(a6,{title:"Path",control:O5.jsx(W9,{value:J??"",readOnly:!0,"aria-label":"Workspace path",title:J??void 0,className:"w-56"})}),O5.jsxs("div",{className:"flex flex-col gap-4 px-3.5 py-3.5",children:[O5.jsxs("div",{className:"flex flex-col",children:[O5.jsx("span",{className:"text-sm font-medium",children:"Icon"}),O5.jsx("span",{className:"text-xs text-muted-foreground",children:"Pick an emoji or a glyph on a generated background, or upload an image."})]}),O5.jsx(i_,{icon:Z})]})]}),O5.jsxs(s6,{label:"Danger zone",children:[O5.jsx(a6,{title:"Remove space",description:"Remove this space from moi. Its folder and sessions stay on disk.",control:O5.jsxs(M1,{type:"button",variant:"destructive",size:"sm",onClick:()=>{let V=`Remove "${$??J??"this space"}" from your workspaces?
|
|
26
26
|
|
|
27
|
-
This only removes it from your list. The folder and its sessions stay on disk. You can add it back any time.`;if(!window.confirm(V))return;Q.mutate(X,{onSuccess:()=>Y("/")})},disabled:Q.isPending,children:[Q.isPending&&O5.jsx(H5,{"data-icon":"inline-start",stroke:1.75,className:"animate-spin"}),"Remove"]})}),Q.isError&&O5.jsx("p",{className:"px-3.5 py-3 text-xs text-destructive",children:Q.error.message})]})]})}var E0=_(y(),1),tC=[{id:"general",label:"General",icon:b3},{id:"connectors",label:"Connectors",icon:DX},{id:"environment",label:"Environment",icon:EX}];function s_(){let[$,Z]=Mz.useState(!1),[J,X]=Mz.useState("general");return E0.jsxs(E0.Fragment,{children:[E0.jsxs(V7,{children:[E0.jsx(N7,{render:E0.jsx(M1,{variant:"ghost",size:"icon-sm","aria-label":"Settings",onClick:()=>Z(!0),children:E0.jsx(b3,{stroke:1.75})})}),E0.jsx(q7,{children:"Settings"})]}),E0.jsx(G6,{open:$,onOpenChange:Z,children:E0.jsxs(WZ,{className:"flex h-[min(680px,90vh)] w-[880px] max-w-[94vw]",children:[E0.jsx(Q6,{className:"sr-only",children:"Space settings"}),E0.jsxs("nav",{className:"flex w-48 shrink-0 flex-col gap-0.5 border-r border-border bg-muted/30 p-3",children:[E0.jsx("p",{className:"px-2.5 pt-4 pb-2 text-[11px] font-semibold tracking-wider text-muted-foreground/80 uppercase",children:"Settings"}),tC.map((Y)=>E0.jsxs(M1,{type:"button",variant:J===Y.id?"secondary":"ghost",size:"sm",onClick:()=>X(Y.id),className:"justify-start",children:[E0.jsx(Y.icon,{stroke:1.75}),Y.label]},Y.id))]}),E0.jsxs("div",{className:"relative scrollbar-thin min-w-0 flex-1 overflow-y-auto",children:[E0.jsx(KZ,{render:E0.jsx(M1,{variant:"ghost",size:"icon","aria-label":"Close",className:"absolute top-3 right-3 z-10",children:E0.jsx(i5,{stroke:1.5})})}),E0.jsxs("div",{className:"px-8 py-7",children:[J==="general"&&E0.jsx(n_,{}),J==="connectors"&&E0.jsx(fF,{}),J==="environment"&&E0.jsx(lF,{})]})]})]})})]})}function eC($){if($===null)return null;if($===void 0)return"this workspace's agent availability has not resolved yet";return`this workspace's agent is unavailable (${$})`}function a_({send:$,revealChat:Z,unavailableReason:J}){let X=s0();YJ(X,"sendChatMessage",(Y)=>{let G=eC(J);if(G){c2(X,{source:"runtime",message:`sendChatMessage("${Y.message}") was dropped: ${G}.`});return}let{message:Q,...z}=Y;Z(),$(Q,{applet:z})})}var w4=_(x(),1);var JM=_(x(),1);function CX($,Z){let J=$??[];if(J.findIndex((Y)=>Y.id===Z.id)===-1)return[...J,Z];return J.map((Y)=>Y.id===Z.id&&Y.updatedAt<=Z.updatedAt?Z:Y)}function hX($){let Z=y1();return r5((J)=>{if(J.type==="view-builder:updated"&&J.workspaceId===$)Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J.builder));else if(J.type==="view-builder:deleted"&&J.workspaceId===$)Z.setQueryData(B1.viewBuilders($),(X)=>(X??[]).filter((Y)=>Y.id!==J.builderId))}),I0({queryKey:B1.viewBuilders($),queryFn:async()=>{return(await e1(`/api/workspaces/${$}/view-builders`)).builders},...n2})}function o_($){let Z=y1();return O0({mutationFn:()=>e1(`/api/workspaces/${$}/view-builders`,B5("POST"),"Failed to create view builder"),onSuccess:(J)=>{Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J))}})}function t_($){let Z=y1();return O0({mutationFn:({builderId:J,requirements:X})=>e1(`/api/workspaces/${$}/view-builders/${J}`,B5("PATCH",{input:{requirements:X}}),"Failed to save view requirements"),onSuccess:(J)=>{Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J))}})}function e_($){let Z=y1();return O0({mutationFn:({builderId:J,requirements:X,...Y})=>e1(`/api/workspaces/${$}/view-builders/${J}/submit`,B5("POST",{input:{requirements:X},availableIcons:f3,...Y}),"Failed to start view builder"),onSuccess:(J)=>{Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J))}})}function $M($){let Z=y1();return O0({mutationFn:(J)=>p2(`/api/workspaces/${$}/view-builders/${J}`,{method:"DELETE"},"Failed to discard view builder"),onSuccess:(J,X)=>{Z.setQueryData(B1.viewBuilders($),(Y)=>(Y??[]).filter((G)=>G.id!==X))}})}var ZM=new Map;function $h($){let Z=ZM.get($)??[];return ZM.delete($),Z}function Zh($,Z=[]){return[...$h($),...Z]}function Jh($,Z){if(!$.startsWith("view:"))return;return Object.keys(Z).length>0?Z:void 0}function Xh($,Z,J){if($.startsWith("view:"))return Z?.find((X)=>X.id===$.slice(5))?.config.title||void 0;if($.startsWith("view-builder:"))return J?.find((X)=>X.id===$.slice(13))?.title||void 0;return}function XM({activeTab:$,appletParams:Z}){let J=s0(),X=zJ(J).data,Y=hX(J).data;return JM.useCallback((G={})=>{let Q=Zh(J,G.directives??[]),z=Jh($,Z);return{activeTab:$,tabTitle:Xh($,X,Y),...z?{tabParams:z}:{},...G.applet?{applet:G.applet}:{},...Q.length>0?{directives:Q}:{}}},[J,$,Z,X,Y])}var YM=!0;function Oz($){return!$?.applet}function GM($,Z,J){if(!Oz(J))return[];return(n1.getState().attachments[E2($,Z)]??[]).filter((Y)=>Y.status==="ready"&&Y.upload)}function IX({queryClient:$,workspaceId:Z,sessionId:J,parts:X}){let Y=`optimistic:${crypto.randomUUID()}`;return $.setQueryData(B1.events(Z,J),(G)=>k8(G??w8(),{kind:"turn",turn:{id:Y,role:"user",origin:{kind:"user-input"},parts:X,timestamp:new Date().toISOString()}})),n1.getState().setActivity(Z,J,"running"),n1.getState().setError(Z,J,null),Y}function xX($,Z,J){let X=$?.models,Y=!Z||!X||X.some((H)=>H.value===Z)?Z:void 0,G=X?.find((H)=>H.value===Y),Q=J&&(!G||(G.supportedEffortLevels??[]).includes(J))?J:void 0,z=YM&&$?.supportsStreaming?!0:void 0;return{model:Y,effort:Q,stream:z}}function Yh($){return $.filter((Z)=>Z.text.length>0).map((Z)=>Z.kind==="reasoning"?{type:"reasoning",text:Z.text}:{type:"text",text:Z.text})}function QM($){let Z=Yh($?.blocks??[]);if(Z.length===0)return null;return{id:"live-preview",role:"assistant",origin:{kind:"user-input"},parts:Z}}var Gh=w8();function zM($){let Z=s0(),J=y1(),{layout:X}=B0(),Y=_6(Z).data,G=A6(Z).data,Q=XM($),z=f5((D)=>D.activeByWorkspace[Z]??null),H=f5((D)=>Object.prototype.hasOwnProperty.call(D.activeByWorkspace,Z)),W=f5((D)=>z?D.activity[`${Z}:${z}`]??"idle":"idle")==="running",K=f5((D)=>z?D.errors[`${Z}:${z}`]??null:null),V=NV(Z,z),N=V.data??Gh,B=H&&G!==void 0&&(z===null||G.some((D)=>D.sessionId===z)&&V.data!==void 0),q=f5((D)=>D.previews),F=w4.useMemo(()=>QM(HK(q,Z,z).root),[q,Z,z]),L=ZJ(Z,z).data,A=w4.useCallback((D,P)=>{let T=D.trim(),k=GM(Z,z,P);if(!T&&k.length===0)return;let S=z,I=!1;if(!S)S=crypto.randomUUID(),I=!0,n1.getState().setActive(Z,S);let E=[];for(let o of k)if(o.upload?.kind==="image"&&o.previewUrl)E.push({type:"file",mediaType:o.mediaType,url:o.previewUrl,filename:o.name});else E.push({type:"file",mediaType:o.mediaType,url:"",filename:o.name});if(T)E.push({type:"text",text:T});let w=IX({queryClient:J,workspaceId:Z,sessionId:S,parts:E}),C=L?.model??X.selectedModel,h=L?.effort??X.selectedEffort,{model:b,effort:f,stream:g}=xX(Y,C,h);if(e$({type:"chat",workspaceId:Z,content:T,sessionId:S,isNew:I,optimisticId:w,model:b,effort:f,stream:g,context:Q(P),...k.length>0?{attachments:k.map((o)=>o.upload.id)}:{}}),w2.getState().markMessageSentFromMoi(Z),I)J.invalidateQueries({queryKey:B1.preview(Z)});if(Oz(P))n1.getState().clearAttachments(Z,z)},[z,Z,J,X.selectedModel,X.selectedEffort,Q,L?.model,L?.effort,Y]),M=w4.useCallback(()=>{if(!z)return;n1.getState().setError(Z,z,null)},[z,Z]),j=w4.useCallback(()=>{if(!W||!z)return;e$({type:"stop",workspaceId:Z,sessionId:z})},[W,z,Z]),O=w4.useCallback((D)=>{n1.getState().setActive(Z,D)},[Z]);return{view:N,chatLoaded:B,previewTurn:F,sessionId:z,processing:W,error:K,send:A,stop:j,switchThread:O,dismissError:M}}var d7=_(x(),1);var w0=_(y(),1);function HM({builder:$,unavailableReason:Z,onSave:J,onSubmit:X,onOpenChat:Y,onDiscard:G}){let[Q,z]=d7.useState($.input.requirements),[H,U]=d7.useState(!1),[W,K]=d7.useState(null),V=d7.useRef(null),N=d7.useRef(J);N.current=J;let B=Q.trim().length>0,q=_4(B,H,Z);d7.useEffect(()=>{if($.status!=="draft"||Q===$.input.requirements)return;let L=setTimeout(()=>{N.current(Q).then(()=>K(null)).catch((A)=>K(A instanceof Error?A.message:"Could not save requirements"))},500);return()=>clearTimeout(L)},[$.input.requirements,$.status,Q]);let F=async(L)=>{if(L.preventDefault(),!q)return;U(!0);try{await X(Q)}catch(A){K(A instanceof Error?A.message:"Could not start view builder"),U(!1)}};if($.status==="draft")return w0.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center px-3 py-6",children:w0.jsxs("div",{className:"flex w-full max-w-(--chat-max-container) flex-col gap-6",children:[w0.jsxs("div",{className:"flex flex-col gap-1 text-center",children:[w0.jsx("h1",{className:"font-medium",children:"What should this view do?"}),w0.jsx("p",{className:"mx-auto max-w-sm text-sm text-muted-foreground",children:"Describe the content, data, and actions you need."})]}),w0.jsxs(HJ,{composerRef:V,onSubmit:F,children:[w0.jsx("label",{className:"sr-only",htmlFor:`view-builder-${$.id}`,children:"View requirements"}),w0.jsx(UJ,{textareaRef:V,id:`view-builder-${$.id}`,value:Q,onChange:(L)=>z(L.target.value),onKeyDown:(L)=>{if(L.key==="Enter"&&(L.metaKey||L.ctrlKey))L.preventDefault(),L.currentTarget.form?.requestSubmit()},placeholder:"Build a customer dashboard with…",rows:1,className:"min-h-16","aria-describedby":W?`view-builder-error-${$.id}`:void 0,"aria-invalid":Boolean(W),autoFocus:!0}),w0.jsxs(KJ,{children:[w0.jsx(dJ,{scope:"workspace"}),w0.jsx(WJ,{label:"Build view",hasContent:B,loading:H,unavailableReason:Z})]})]}),W&&w0.jsx("p",{id:`view-builder-error-${$.id}`,role:"alert",className:"text-sm text-destructive",children:W})]})});if($.status==="waiting")return w0.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:w0.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[w0.jsxs("div",{className:"flex flex-col gap-1",children:[w0.jsx("h1",{className:"text-lg font-semibold",children:"The view needs your attention"}),w0.jsx("p",{className:"text-sm text-muted-foreground",children:$.error??"Open its chat to answer or ask the agent to continue."})]}),w0.jsxs("div",{className:"flex gap-2",children:[w0.jsx(M1,{onClick:Y,children:"Open chat"}),w0.jsx(M1,{variant:"secondary",onClick:G,children:"Discard"})]})]})});return w0.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:w0.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[w0.jsx(H5,{stroke:1.75,className:"animate-spin"}),$.status==="ready"?"Opening view…":"Building your view…"]})})}function UM(){let $=y1(),{workspaceId:Z,layout:J}=B0(),X=_6(Z).data,Y=o_(Z),G=t_(Z),Q=e_(Z),z=$M(Z);return{create:()=>Y.mutateAsync(),save:(V,N)=>G.mutateAsync({builderId:V,requirements:N}),submit:async(V,N)=>{let B=N.trim();if(!B)return;let q=IX({queryClient:$,workspaceId:Z,sessionId:V.sessionId,parts:[{type:"text",text:B}]});n1.getState().setActive(Z,V.sessionId);let{model:F,effort:L,stream:A}=xX(X,J.selectedModel,J.selectedEffort);try{await Q.mutateAsync({builderId:V.id,requirements:B,optimisticId:q,model:F,effort:L,stream:A})}catch(M){throw n1.getState().setActivity(Z,V.sessionId,"idle"),n1.getState().setError(Z,V.sessionId,M instanceof Error?M.message:"Could not start view builder"),M}},discard:(V)=>z.mutateAsync(V)}}var t6=_(x(),1);function KM($){let Z=document.documentElement,J=getComputedStyle(Z).getPropertyValue($).trim(),X=Number.parseFloat(J);if(!Number.isFinite(X))return 0;return J.endsWith("rem")?X*Number.parseFloat(getComputedStyle(Z).fontSize):X}function WM(){let $=t6.useRef(null),[Z,J]=t6.useState(!1);return t6.useLayoutEffect(()=>{let X=$.current;if(!X)return;let Y=(Q)=>{let z=KM("--column-w"),H=KM("--chat-min");J(Q-H>=z)};Y(X.getBoundingClientRect().width);let G=new ResizeObserver(([Q])=>{if(Q)Y(Q.contentRect.width)});return G.observe(X),()=>G.disconnect()},[]),{ref:$,fits:Z}}var C5=_(y(),1);function RX({error:$,pendingAction:Z,onUpdate:J,onDismiss:X}){if(!$&&Z==="auto")return C5.jsxs("div",{role:"status",className:"flex w-full items-center gap-1.5 p-2 text-sm text-muted-foreground",children:[C5.jsx(H5,{size:20,stroke:1.5,className:"shrink-0 animate-spin"}),C5.jsx("span",{className:"wrap-break-word",children:"Updating moi skills…"})]});let Y=Z!==null;return C5.jsxs("div",{role:$?"alert":"status",className:Z1("grid w-full grid-cols-[minmax(0,1fr)_auto] gap-x-2 gap-y-2 p-2 text-sm","@xl:flex @xl:items-center @xl:px-2 @xl:pl-3",$&&"text-destructive"),children:[C5.jsxs("div",{className:"flex min-w-0 items-start gap-1.5 @xl:order-1 @xl:flex-1 @xl:items-center",children:[C5.jsx(BM,{size:20,stroke:1.5,className:"shrink-0"}),$?C5.jsx("span",{className:"wrap-break-word",children:`Update failed: ${$}`}):C5.jsx("span",{className:"wrap-break-word",children:"This workspace is using old moi skills"})]}),C5.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",onClick:X,className:"col-start-2 row-start-1 -mt-1 -mr-1 text-muted-foreground hover:text-foreground @xl:order-4 @xl:m-0","aria-label":"Dismiss skill update",children:C5.jsx(i5,{stroke:1.75})}),C5.jsxs("div",{className:"col-span-2 flex flex-wrap gap-1.5 @xl:contents",children:[C5.jsxs(M1,{type:"button",variant:"default",size:"sm",onClick:()=>J("auto"),disabled:Y,className:"@xl:order-2",children:[Z==="auto"&&C5.jsx(H5,{stroke:1.75,className:"animate-spin"}),Z==="auto"?"Updating…":"Auto-update"]}),C5.jsxs(M1,{type:"button",variant:"secondary",size:"sm",onClick:()=>J("once"),disabled:Y,className:"@xl:order-3",children:[Z==="once"&&C5.jsx(H5,{stroke:1.75,className:"animate-spin"}),Z==="once"?"Updating…":"Update once"]})]})]})}var R9=_(x(),1);function Dz($){return{workspaceId:$,phase:"idle",pendingAction:null,error:null}}function Qh($){return $.phase==="active"||$.phase==="idle"&&$.updateAvailable&&!$.autoUpdateEnabled}function zh($){return $.updateAvailable&&$.autoUpdateEnabled&&!$.updatePending&&$.phase==="idle"}function VM($){let Z=xV($),{isPending:J,mutate:X,reset:Y}=RV($),G=bF(),{mutate:Q}=yF(),z=G.data!==void 0,H=G.data?.autoUpdateSkills??!1,U=R9.useCallback(()=>Q({autoUpdateSkills:!0}),[Q]),[W,K]=R9.useState(()=>Dz($)),V=W.workspaceId===$?W:Dz($);R9.useEffect(()=>{K(Dz($)),Y()},[$,Y]);let N=R9.useCallback((F)=>{if(J)return;if(F==="auto")U();K({workspaceId:$,phase:"active",pendingAction:F,error:null}),X(void 0,{onSuccess:()=>{K((L)=>L.workspaceId===$?{...L,phase:"dismissed",pendingAction:null,error:null}:L)},onError:(L)=>{K((A)=>A.workspaceId===$&&A.phase!=="dismissed"?{...A,phase:"active",pendingAction:null,error:L.message}:A)}})},[U,J,X,$]),B=Z.data?.updateAvailable??!1;return R9.useEffect(()=>{if(z&&zh({updateAvailable:B,autoUpdateEnabled:H,updatePending:J,phase:V.phase}))N("auto")},[H,V.phase,N,z,B,J]),{bannerProps:z&&Qh({updateAvailable:B,autoUpdateEnabled:H,phase:V.phase})?{error:V.error,pendingAction:V.pendingAction,onUpdate:N,onDismiss:()=>{K((F)=>F.workspaceId===$?{...F,phase:"dismissed",pendingAction:null,error:null}:F)}}:null}}var jz=rG();function fX($){if(!$||!Array.isArray($.open))return jz;let Z=$.open.filter((J,X,Y)=>Y.indexOf(J)===X);if(Z.length===0)return jz;return{open:Z,active:Z.includes($.active)?$.active:Z[0]}}function y3($,Z,J){if($==="agent"||$==="widgets"||$==="scratchpad")return!0;let X=A4($);if(X)return J.some((G)=>G.id===X);let Y=F9($);return Y?Z.some((G)=>G.id===Y):!1}function bX($,Z,J){let X=$.open.filter((Y)=>y3(Y,Z,J));return X.length>0?X:jz.open}function NM($){if(!$)return!1;let Z=Y3($);return Z===null||F9(Z)!==null}function qM($,Z,J,X,Y){if($!==null&&y3($,J,X)&&!(Y&&$==="agent"))return $;let G=bX(Z,J,X),Q=Y?G.filter((z)=>z!=="agent"):G;return Q.includes(Z.active)?Z.active:Q[0]??"agent"}var T7=_(x(),1);function AM({views:$,builders:Z,split:J}){let{layout:X,setLayout:Y,workspaceId:G}=B0(),[,Q]=C2(),z=FM()["*"]??null,H=LM(),U=T7.useMemo(()=>AV(H),[H]),W=fX(X.tabs),K=T7.useRef(W);K.current=W;let V=Y3(z),N=qM(V,W,$,Z,J),B=V!==null&&V===N,q=T7.useCallback((L,A)=>{Q(FV(G,L),{replace:!0,...A?{state:{appletParams:A}}:{}})},[Q,G]),F=T7.useCallback((L)=>{K.current=L,Y({tabs:L})},[Y]);return T7.useEffect(()=>{if(z===N)return;if(NM(z))Hh(G,z,N);q(N)},[N,q,z,G]),T7.useEffect(()=>{if(!B)return;let L=K.current,A=L.open.includes(N)?L.open:[...L.open,N];if(A===L.open&&L.active===N)return;F({open:A,active:N})},[N,F,B]),{tabsState:W,activeTab:N,appletParams:U,navigateToTab:q,setTabs:F}}function Hh($,Z,J){let X=Y3(Z),Y=X?F9(X):null;c2($,{source:"runtime",...Y?{kind:"view",name:Y}:{},message:`Tab "${Z}" does not exist in this workspace — the URL redirected to "${J}". A link, bookmark, or focusTab call is pointing at a tab that was deleted or renamed.`})}var y0=_(y(),1),Uh=MM([o8({variant:"ghost",size:"sm"}),"group/tab min-w-0"],{variants:{active:{true:"bg-accent text-accent-foreground"},dragging:{true:"invisible"},preview:{true:"cursor-grabbing ring-1 ring-border"}},compoundVariants:[{preview:!0}]});function Kh({items:$}){return y0.jsxs(C6,{children:[y0.jsx(h6,{render:y0.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",className:"text-muted-foreground","aria-label":"Create tab",children:y0.jsx(v5,{stroke:1.75})})}),y0.jsx(M4,{align:"start",className:"min-w-48",children:y0.jsx(O4,{children:$.map(({key:Z,Icon:J,label:X,onClick:Y})=>y0.jsxs(U3,{onClick:Y,className:"font-medium",children:[y0.jsx(J,{stroke:2}),X]},Z))})})]})}function _M($){let{tab:Z,active:J}=$,X=$.preview===!0;return y0.jsxs("button",{type:"button","aria-hidden":X||void 0,"aria-label":Z.label,disabled:X,tabIndex:X?-1:void 0,onClick:$.preview?void 0:()=>$.onSelect(Z.key),className:Uh({active:J,dragging:$.preview?!1:$.state.isDragging,preview:X}),...$.preview?{}:$.state.dragHandleProps,children:[y0.jsxs("div",{className:Z1("flex items-center gap-1 overflow-hidden",Z.closable&&"group-hover/tab:mr-3"),children:[y0.jsx(Z.Icon,{"data-icon":"inline-start",stroke:2}),y0.jsx("span",{className:Z1("truncate",Z.closable&&"group-hover/tab:-mr-3 group-hover/tab:mask-r-from-[calc(100%-24px)] group-hover/tab:mask-r-to-[calc(100%-12px)]"),children:Z.label})]}),Z.closable&&y0.jsx("div",{"aria-label":`Close ${Z.label}`,tabIndex:X?-1:void 0,className:Z1("absolute right-2 hidden size-3 items-center justify-center text-muted-foreground group-hover/tab:flex hover:text-foreground",X&&"pointer-events-none"),onClick:$.preview?void 0:(Y)=>{Y.stopPropagation(),$.onClose(Z.key)},children:y0.jsx(i5,{stroke:1.75})})]})}function OM({tabs:$,active:Z,createItems:J,onSelect:X,onClose:Y,onReorder:G}){return y0.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:[y0.jsx("div",{className:"no-scrollbar min-w-0 scroll-fade-x overflow-x-auto overflow-y-hidden [--scroll-fade-reveal:16px]",children:y0.jsx(mZ,{items:$,getId:(Q)=>Q.key,className:"flex w-max items-center gap-1",onReorder:(Q)=>G(Q),renderPlaceholder:()=>y0.jsx("div",{className:"pointer-events-none absolute inset-0 rounded-md bg-muted"}),renderOverlay:(Q)=>y0.jsx(_M,{tab:Q,active:Z===Q.key,preview:!0}),renderItem:(Q,z)=>y0.jsx(_M,{tab:Q,active:Z===Q.key,state:z,onSelect:X,onClose:Y})})}),y0.jsx("div",{className:"shrink-0",children:y0.jsx(Kh,{items:J})})]})}var f1=_(y(),1),Wh=N2.lazy(()=>import("/chunk-3m1xe1j3.js").then(($)=>({default:$.Scratchpad}))),TM=($)=>$.config.title||$.id,EM=($)=>wX($.icon)??B3;function wM($,Z){let J=Z.find((X)=>X.viewId===$.id);return wX($.config.icon)??wX(J?.icon)??B3}function Bh({mode:$,onToggleMode:Z}){return f1.jsx(M1,{variant:"ghost",size:"icon-sm",onClick:Z,"aria-label":$==="fullscreen"?"Switch to split view":"Switch to full-screen view",children:f1.jsx(jM,{stroke:1.75})})}function Vh({view:$,params:Z}){let J=s0(),X=SV($.id);return f1.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:f1.jsxs(j7,{mode:"wait",initial:!1,children:[X.status==="ready"&&f1.jsx(YX,{asChild:!0,segment:"views",name:$.id,version:X.version,children:f1.jsx(m0.div,{className:"absolute inset-0 overflow-auto",initial:{opacity:0,filter:"blur(4px)"},animate:{opacity:1,filter:"blur(0px)"},exit:{opacity:0,filter:"blur(4px)"},transition:{duration:0.3,ease:"easeInOut"},children:f1.jsx(F3,{name:$.id,kind:"view",workspaceId:J,resetKey:X.version,children:f1.jsx(X.Component,{params:Z})})})},X.version),X.status==="error"&&f1.jsx(m0.p,{className:"absolute inset-0 p-4 text-xs text-destructive",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:0.3,ease:"easeInOut"},children:X.error},`err-${X.version}`)]})})}function Nh({active:$,onToggle:Z}){return f1.jsxs(V7,{children:[f1.jsx(N7,{render:f1.jsx(M1,{variant:$?"secondary":"ghost",size:"icon-sm","aria-label":"Customize","aria-pressed":$,onClick:Z,children:f1.jsx(PM,{stroke:1.75})})}),f1.jsx(q7,{children:"Customize"})]})}function qh($,Z,J,X){if($==="agent")return{key:$,Icon:y7,label:"Agent",closable:X};if($==="widgets")return{key:$,Icon:V3,label:"Widgets",closable:X};if($==="scratchpad")return{key:$,Icon:N3,label:"Scratchpad",closable:X};let Y=A4($),G=Y?J.find((H)=>H.id===Y):null;if(G)return{key:$,Icon:EM(G),label:G.title||G.viewId||"New view",closable:X};let Q=F9($),z=Q?Z.find((H)=>H.id===Q):null;return z?{key:$,Icon:wM(z,J),label:TM(z),closable:X}:null}function Lh($,Z,J){let X=new Set(Z),Y=0;return $.map((G)=>X.has(G)?J[Y++]:G)}function kM({widgets:$,views:Z,builders:J}){let{layout:X,setLayout:Y,name:G,icon:Q,provider:z,workspaceId:H}=B0(),U=IV(H).data,{bannerProps:W}=VM(H),K=U===void 0?void 0:U.available?null:U.reason,V=UM(),{ref:N,fits:B}=WM(),[q,F]=N2.useState("idle"),[L,A]=N2.useState(!1),[M,j]=N2.useState(0);UV(X.theme);let O=bX(fX(X.tabs),Z,J),D=O.filter((c)=>c!=="agent"),P=D.length>0,k=X.layoutMode==="split"&&P&&B?"split":"fullscreen",S=k==="split",{tabsState:I,activeTab:E,appletParams:w,navigateToTab:C,setTabs:h}=AM({views:Z,builders:J,split:S}),{view:b,chatLoaded:f,previewTurn:g,sessionId:o,processing:m,error:V1,send:U1,stop:q1,switchThread:e,dismissError:D1}=zM({activeTab:E,appletParams:w}),v=new Set(I.open),$1=(c)=>{Y({layoutMode:c})},K1=S?D:O,t=O.length>1,J1=K1.map((c)=>qh(c,Z,J,t||A4(c)!==null)).filter((c)=>Boolean(c)),z1=F9(E),R=z1?Z.find((c)=>c.id===z1):void 0,i=A4(E),u=i?J.find((c)=>c.id===i):void 0;N2.useEffect(()=>{if(I.open.filter((x1)=>y3(x1,Z,J)).length===I.open.length)return;let _1=bX(I,Z,J);Y({tabs:{open:_1,active:_1.includes(I.active)?I.active:_1[0]}})},[J,Y,I,Z]),N2.useEffect(()=>{let c=new Map;for(let b1 of J){if(b1.status!=="ready"||!b1.viewId)continue;if(!Z.some((s1)=>s1.id===b1.viewId))continue;c.set(G3(b1.id),cG(b1.viewId))}if(c.size===0)return;let _1=c.get(E);if(_1)C(_1);let x1=new Set(c.values()),$0=new Map([...c].map(([b1,s1])=>[s1,b1])),d1=[],w1=!1;for(let b1 of I.open){let s1=$0.get(b1);if(x1.has(b1)&&s1&&I.open.includes(s1)){w1=!0;continue}let r0=c.get(b1),h5=r0??b1;if(r0)w1=!0;if(!d1.includes(h5))d1.push(h5)}if(!w1)return;let o1=c.get(I.active)??I.active;Y({tabs:{open:d1.length>0?d1:["agent"],active:o1}})},[E,J,C,Y,I,Z]),N2.useEffect(()=>{let c=u??J.find((_1)=>_1.viewId===z1);if(c)n1.getState().setActive(H,c.sessionId)},[u,z1,J,H]),N2.useEffect(()=>{if(k!=="fullscreen"||E==="agent")A(!1)},[E,k]);let W1=(c,_1)=>{if(C(c,_1),c==="agent")A(!1),j((x1)=>x1+1)};YJ(H,"focusTab",W1),r5((c)=>{if(c.type==="tab:focus"&&c.workspaceId===H)W1(c.tab,c.params)});let s=(c)=>{let _1=A4(c),x1=_1?J.find((b1)=>b1.id===_1):void 0;if(!t&&!x1||!v.has(c))return;let $0=I.open.filter((b1)=>b1!==c);if($0.length===0)$0=["agent"];let d1=K1.indexOf(c),w1=K1[d1+1]??K1[d1-1]??$0.find((b1)=>y3(b1,Z,J))??"agent",o1=I.active===c||!$0.includes(I.active)?w1:I.active;if(h({open:$0,active:o1}),E===c)C(w1);if(x1?.status==="draft")V.discard(x1.id)},X1=(c)=>{let _1=G3(c.id);if(v.has(_1)){let x1=I.open.filter(($0)=>$0!==_1);if(x1.length===0)x1=["agent"];if(h({open:x1,active:I.active===_1?x1[0]:I.active}),E===_1)C(x1[0])}V.discard(c.id)},G1=(c)=>{let _1=Lh(I.open,K1,c);if(_1===I.open)return;h({open:_1,active:I.active})},d=(c)=>{if(c!==void 0)n1.getState().setDraft(H,o,c);if(k==="fullscreen"&&E!=="agent"){if(A(!0),L)j((_1)=>_1+1);return}j((_1)=>_1+1)};a_({send:U1,revealChat:d,unavailableReason:K});let Q1=[...!S&&!v.has("agent")?[{key:"agent",Icon:y7,label:"Agent",onClick:()=>W1("agent")}]:[],...!v.has("widgets")?[{key:"widgets",Icon:V3,label:"Widgets",onClick:()=>W1("widgets")}]:[],...!v.has("scratchpad")?[{key:"scratchpad",Icon:N3,label:"Scratchpad",onClick:()=>W1("scratchpad")}]:[],...Z.map((c)=>({view:c,tab:cG(c.id)})).filter(({tab:c})=>!v.has(c)).map(({view:c,tab:_1})=>({key:_1,Icon:wM(c,J),label:TM(c),onClick:()=>W1(_1)})),...J.filter((c)=>c.status!=="ready").map((c)=>({builder:c,tab:G3(c.id)})).filter(({tab:c})=>!v.has(c)).map(({builder:c,tab:_1})=>({key:_1,Icon:EM(c),label:c.title||c.viewId||"New view",onClick:()=>W1(_1)})),{key:"create-view",Icon:DM,label:"New view",onClick:()=>{V.create().then((c)=>W1(G3(c.id)))}}],n=f1.jsx(aJ,{active:k==="split",focusRequest:M,chatLoaded:f,view:b,previewTurn:g,sessionId:o,processing:m,error:V1,onDismissError:D1,composerBanner:W?f1.jsx(RX,{...W}):void 0,unavailableReason:K,send:U1,stop:q1,onSwitchThread:e}),L1=f1.jsx(aJ,{active:k==="fullscreen"&&E==="agent",focusRequest:M,chatLoaded:f,view:b,previewTurn:g,sessionId:o,processing:m,error:V1,onDismissError:D1,composerBanner:W?f1.jsx(RX,{...W}):void 0,unavailableReason:K,send:U1,stop:q1,onSwitchThread:e});return f1.jsxs("div",{className:"relative flex h-full min-h-0 flex-col bg-background font-sans text-foreground",children:[f1.jsxs("div",{ref:N,className:"flex min-h-0 flex-1",children:[(k==="fullscreen"||P)&&f1.jsxs("div",{className:Z1("flex min-h-0 flex-1 flex-col",k==="split"&&"min-w-(--column-w)"),children:[f1.jsxs(jF,{children:[f1.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-4",children:[f1.jsxs("div",{className:"flex items-center gap-2",children:[f1.jsx("img",{src:Q??l2[z??"claude-code"],alt:"",className:"size-5 shrink-0 rounded-xs"}),G&&f1.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:G})]}),f1.jsx(OM,{tabs:J1,active:E,createItems:Q1,onSelect:W1,onClose:s,onReorder:G1})]}),f1.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[f1.jsx(Nh,{active:q==="customizing",onToggle:()=>F(q==="customizing"?"idle":"customizing")}),f1.jsx(s_,{}),P&&B&&f1.jsx(Bh,{mode:k,onToggleMode:()=>$1(k==="fullscreen"?"split":"fullscreen")})]})]}),E==="agent"?L1:E==="widgets"?f1.jsx(DF,{editing:q==="editing",onEditingChange:(c)=>F(c?"editing":"idle"),widgets:$,onCreateWidget:()=>d("Create widget")}):E==="scratchpad"?f1.jsx(N2.Suspense,{fallback:null,children:f1.jsx(Wh,{})}):u?f1.jsx(HM,{builder:u,unavailableReason:K,onSave:(c)=>V.save(u.id,c),onSubmit:(c)=>{if(k==="fullscreen")A(!0);return V.submit(u,c)},onOpenChat:()=>{n1.getState().setActive(H,u.sessionId),d()},onDiscard:()=>X1(u)},u.id):R?f1.jsx(Vh,{view:R,params:w}):null]}),k==="split"&&f1.jsx("div",{className:Z1("flex min-h-0 min-w-(--chat-min) flex-[0_1_var(--chat-max)] flex-col overflow-hidden border-l border-border"),children:n})]}),f1.jsx(j7,{children:q==="customizing"&&f1.jsx(iq,{onClose:()=>F("idle")})}),k==="fullscreen"&&E!=="agent"&&P&&f1.jsx(pq,{open:L,onOpenChange:A,onOpenChangeComplete:(c)=>{if(c)j((_1)=>_1+1)},children:(c)=>f1.jsx(aJ,{active:L,focusRequest:M,chatLoaded:f,view:b,previewTurn:g,sessionId:o,processing:m,error:V1,onDismissError:D1,composerBanner:W?f1.jsx(RX,{...W}):void 0,unavailableReason:K,send:U1,stop:q1,onSwitchThread:e,onClose:c})})]})}var yX=_(x(),1);function SM($,Z,J,X){let Y=yX.useRef(null);yX.useEffect(()=>{if(!Z)return;let G=new Map(Z.map((N)=>[N.id,{w:N.config.colSpan,h:N.config.rowSpan}]));if(Y.current?.workspaceId!==$){Y.current={workspaceId:$,sizes:G};return}let Q=Y.current.sizes,z=new Set(J.widgetGrid.map((N)=>N.i)),H=Z.filter((N)=>{if(!Q.has(N.id))return!z.has(N.id);if(!z.has(N.id))return!1;let q=Q.get(N.id);return q.w!==N.config.colSpan||q.h!==N.config.rowSpan});if(Y.current={workspaceId:$,sizes:G},H.length===0)return;let U=new Map(Z.map((N)=>[N.id,N.config])),W=J.widgetGrid.filter((N)=>!H.some((B)=>B.id===N.i)&&U.has(N.i)).map((N)=>{let B=U.get(N.i);return{i:N.i,x:N.x,y:N.y,w:B.colSpan,h:B.rowSpan}}),K=W.map(({i:N,x:B,y:q})=>({i:N,x:B,y:q})),V=[...W];for(let N of H){let B=A3(V,N.config.colSpan,N.config.rowSpan,4);K.push({i:N.id,x:B.x,y:B.y}),V.push({i:N.id,x:B.x,y:B.y,w:N.config.colSpan,h:N.config.rowSpan})}X({widgetGrid:K})},[$,Z,J.widgetGrid,X])}var q2=_(y(),1);function xM({id:$}){return q2.jsx(hM,{id:$,children:q2.jsx(mV,{id:$,children:q2.jsx(Fh,{id:$})})})}function Fh({id:$}){let Z=y1(),{layout:J,setLayout:X,isLoading:Y}=B0(),G=fV($),Q=zJ($),z=hX($),H=A6($);SM($,G.data,J,X),CV(),r5((W)=>{if(W.type==="theme:updated"||W.type==="workspace:updated")Z.invalidateQueries({queryKey:B1.layout($)});else if(W.type==="widget-layout:updated"||W.type==="widget:updated")Z.invalidateQueries({queryKey:B1.widgets($)});else if(W.type==="view-layout:updated")Z.invalidateQueries({queryKey:B1.views($)})});let U=Y||G.isLoading||Q.isLoading||z.isLoading;return q2.jsxs(q2.Fragment,{children:[q2.jsx(Ah,{workspaceId:$,sessions:H.data}),q2.jsx(uZ,{children:U?q2.jsx("div",{className:"flex h-full items-center justify-center",children:q2.jsx(CM,{sprite:"moi",effect:"chaos"})}):q2.jsx(kM,{widgets:G.data??[],views:Q.data??[],builders:z.data??[]})})]})}function Ah({workspaceId:$,sessions:Z}){return IM.useEffect(()=>{if(!Z)return;let J=n1.getState().activeByWorkspace,X=Object.prototype.hasOwnProperty.call(J,$),Y=J[$],G=Y===null||Z.some((Q)=>Q.sessionId===Y);if(X&&G)return;n1.getState().setActive($,Z[0]?.sessionId??null)},[$,Z]),null}var l7=_(y(),1),_h=e6.lazy(()=>import("/chunk-7bzpmtxp.js"));function Mh(){return l7.jsx(e6.Suspense,{fallback:null,children:l7.jsx(_h,{})})}function fM(){let[,$]=C2();return e6.useEffect(()=>{return JG((Z)=>$(`/workspace/${Z}`)),()=>JG(null)},[$]),l7.jsxs(RM,{children:[l7.jsx(vX,{path:"/",component:VV}),l7.jsx(vX,{path:"/dev/*?",component:Mh}),l7.jsx(vX,{path:"/workspace/:id/*?",children:(Z)=>l7.jsx(xM,{id:Z.id},Z.id)})]})}var k4=_(y(),1),vM=new tX;qK(vM);YK();function CJ1($){function Z(){return k4.jsx($Y,{client:vM,children:k4.jsxs(ZK,{children:[k4.jsx(bM,{children:k4.jsx(fM,{})}),!1]})})}yM.createRoot($).render(k4.jsx(Z,{}))}export{CJ1 as mount};
|
|
27
|
+
This only removes it from your list. The folder and its sessions stay on disk. You can add it back any time.`;if(!window.confirm(V))return;Q.mutate(X,{onSuccess:()=>Y("/")})},disabled:Q.isPending,children:[Q.isPending&&O5.jsx(H5,{"data-icon":"inline-start",stroke:1.75,className:"animate-spin"}),"Remove"]})}),Q.isError&&O5.jsx("p",{className:"px-3.5 py-3 text-xs text-destructive",children:Q.error.message})]})]})}var E0=_(y(),1),tC=[{id:"general",label:"General",icon:b3},{id:"connectors",label:"Connectors",icon:DX},{id:"environment",label:"Environment",icon:EX}];function s_(){let[$,Z]=Mz.useState(!1),[J,X]=Mz.useState("general");return E0.jsxs(E0.Fragment,{children:[E0.jsxs(V7,{children:[E0.jsx(N7,{render:E0.jsx(M1,{variant:"ghost",size:"icon-sm","aria-label":"Settings",onClick:()=>Z(!0),children:E0.jsx(b3,{stroke:1.75})})}),E0.jsx(q7,{children:"Settings"})]}),E0.jsx(G6,{open:$,onOpenChange:Z,children:E0.jsxs(WZ,{className:"flex h-[min(680px,90vh)] w-[880px] max-w-[94vw]",children:[E0.jsx(Q6,{className:"sr-only",children:"Space settings"}),E0.jsxs("nav",{className:"flex w-48 shrink-0 flex-col gap-0.5 border-r border-border bg-muted/30 p-3",children:[E0.jsx("p",{className:"px-2.5 pt-4 pb-2 text-[11px] font-semibold tracking-wider text-muted-foreground/80 uppercase",children:"Settings"}),tC.map((Y)=>E0.jsxs(M1,{type:"button",variant:J===Y.id?"secondary":"ghost",size:"sm",onClick:()=>X(Y.id),className:"justify-start",children:[E0.jsx(Y.icon,{stroke:1.75}),Y.label]},Y.id))]}),E0.jsxs("div",{className:"relative scrollbar-thin min-w-0 flex-1 overflow-y-auto",children:[E0.jsx(KZ,{render:E0.jsx(M1,{variant:"ghost",size:"icon","aria-label":"Close",className:"absolute top-3 right-3 z-10",children:E0.jsx(i5,{stroke:1.5})})}),E0.jsxs("div",{className:"px-8 py-7",children:[J==="general"&&E0.jsx(n_,{}),J==="connectors"&&E0.jsx(fF,{}),J==="environment"&&E0.jsx(lF,{})]})]})]})})]})}function eC($){if($===null)return null;if($===void 0)return"this workspace's agent availability has not resolved yet";return`this workspace's agent is unavailable (${$})`}function a_({send:$,revealChat:Z,unavailableReason:J}){let X=s0();YJ(X,"sendChatMessage",(Y)=>{let G=eC(J);if(G){c2(X,{source:"runtime",message:`sendChatMessage("${Y.message}") was dropped: ${G}.`});return}let{message:Q,...z}=Y;Z(),$(Q,{applet:z})})}var w4=_(x(),1);var JM=_(x(),1);function CX($,Z){let J=$??[];if(J.findIndex((Y)=>Y.id===Z.id)===-1)return[...J,Z];return J.map((Y)=>Y.id===Z.id&&Y.updatedAt<=Z.updatedAt?Z:Y)}function hX($){let Z=y1();return r5((J)=>{if(J.type==="view-builder:updated"&&J.workspaceId===$)Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J.builder));else if(J.type==="view-builder:deleted"&&J.workspaceId===$)Z.setQueryData(B1.viewBuilders($),(X)=>(X??[]).filter((Y)=>Y.id!==J.builderId))}),I0({queryKey:B1.viewBuilders($),queryFn:async()=>{return(await e1(`/api/workspaces/${$}/view-builders`)).builders},...n2})}function o_($){let Z=y1();return O0({mutationFn:()=>e1(`/api/workspaces/${$}/view-builders`,B5("POST"),"Failed to create view builder"),onSuccess:(J)=>{Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J))}})}function t_($){let Z=y1();return O0({mutationFn:({builderId:J,requirements:X})=>e1(`/api/workspaces/${$}/view-builders/${J}`,B5("PATCH",{input:{requirements:X}}),"Failed to save view requirements"),onSuccess:(J)=>{Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J))}})}function e_($){let Z=y1();return O0({mutationFn:({builderId:J,requirements:X,...Y})=>e1(`/api/workspaces/${$}/view-builders/${J}/submit`,B5("POST",{input:{requirements:X},availableIcons:f3,...Y}),"Failed to start view builder"),onSuccess:(J)=>{Z.setQueryData(B1.viewBuilders($),(X)=>CX(X,J))}})}function $M($){let Z=y1();return O0({mutationFn:(J)=>p2(`/api/workspaces/${$}/view-builders/${J}`,{method:"DELETE"},"Failed to discard view builder"),onSuccess:(J,X)=>{Z.setQueryData(B1.viewBuilders($),(Y)=>(Y??[]).filter((G)=>G.id!==X))}})}var ZM=new Map;function $h($){let Z=ZM.get($)??[];return ZM.delete($),Z}function Zh($,Z=[]){return[...$h($),...Z]}function Jh($,Z){if(!$.startsWith("view:"))return;return Object.keys(Z).length>0?Z:void 0}function Xh($,Z,J){if($.startsWith("view:"))return Z?.find((X)=>X.id===$.slice(5))?.config.title||void 0;if($.startsWith("view-builder:"))return J?.find((X)=>X.id===$.slice(13))?.title||void 0;return}function XM({activeTab:$,appletParams:Z}){let J=s0(),X=zJ(J).data,Y=hX(J).data;return JM.useCallback((G={})=>{let Q=Zh(J,G.directives??[]),z=Jh($,Z);return{activeTab:$,tabTitle:Xh($,X,Y),...z?{tabParams:z}:{},...G.applet?{applet:G.applet}:{},...Q.length>0?{directives:Q}:{}}},[J,$,Z,X,Y])}var YM=!0;function Oz($){return!$?.applet}function GM($,Z,J){if(!Oz(J))return[];return(n1.getState().attachments[E2($,Z)]??[]).filter((Y)=>Y.status==="ready"&&Y.upload)}function IX({queryClient:$,workspaceId:Z,sessionId:J,parts:X}){let Y=`optimistic:${crypto.randomUUID()}`;return $.setQueryData(B1.events(Z,J),(G)=>k8(G??w8(),{kind:"turn",turn:{id:Y,role:"user",origin:{kind:"user-input"},parts:X,timestamp:new Date().toISOString()}})),n1.getState().setActivity(Z,J,"running"),n1.getState().setError(Z,J,null),Y}function xX($,Z,J){let X=$?.models,Y=!Z||!X||X.some((H)=>H.value===Z)?Z:void 0,G=X?.find((H)=>H.value===Y),Q=J&&(!G||(G.supportedEffortLevels??[]).includes(J))?J:void 0,z=YM&&$?.supportsStreaming?!0:void 0;return{model:Y,effort:Q,stream:z}}function Yh($){return $.filter((Z)=>Z.text.length>0).map((Z)=>Z.kind==="reasoning"?{type:"reasoning",text:Z.text}:{type:"text",text:Z.text})}function QM($){let Z=Yh($?.blocks??[]);if(Z.length===0)return null;return{id:"live-preview",role:"assistant",origin:{kind:"user-input"},parts:Z}}var Gh=w8();function zM($){let Z=s0(),J=y1(),{layout:X}=B0(),Y=_6(Z).data,G=A6(Z).data,Q=XM($),z=f5((D)=>D.activeByWorkspace[Z]??null),H=f5((D)=>Object.prototype.hasOwnProperty.call(D.activeByWorkspace,Z)),W=f5((D)=>z?D.activity[`${Z}:${z}`]??"idle":"idle")==="running",K=f5((D)=>z?D.errors[`${Z}:${z}`]??null:null),V=NV(Z,z),N=V.data??Gh,B=H&&G!==void 0&&(z===null||G.some((D)=>D.sessionId===z)&&V.data!==void 0),q=f5((D)=>D.previews),F=w4.useMemo(()=>QM(HK(q,Z,z).root),[q,Z,z]),L=ZJ(Z,z).data,A=w4.useCallback((D,P)=>{let T=D.trim(),k=GM(Z,z,P);if(!T&&k.length===0)return;let S=z,I=!1;if(!S)S=crypto.randomUUID(),I=!0,n1.getState().setActive(Z,S);let E=[];for(let o of k)if(o.upload?.kind==="image"&&o.previewUrl)E.push({type:"file",mediaType:o.mediaType,url:o.previewUrl,filename:o.name});else E.push({type:"file",mediaType:o.mediaType,url:"",filename:o.name});if(T)E.push({type:"text",text:T});let w=IX({queryClient:J,workspaceId:Z,sessionId:S,parts:E}),C=L?.model??X.selectedModel,h=L?.effort??X.selectedEffort,{model:b,effort:f,stream:g}=xX(Y,C,h);if(e$({type:"chat",workspaceId:Z,content:T,sessionId:S,isNew:I,optimisticId:w,model:b,effort:f,stream:g,context:Q(P),...k.length>0?{attachments:k.map((o)=>o.upload.id)}:{}}),w2.getState().markMessageSentFromMoi(Z),I)J.invalidateQueries({queryKey:B1.preview(Z)});if(Oz(P))n1.getState().clearAttachments(Z,z)},[z,Z,J,X.selectedModel,X.selectedEffort,Q,L?.model,L?.effort,Y]),M=w4.useCallback(()=>{if(!z)return;n1.getState().setError(Z,z,null)},[z,Z]),j=w4.useCallback(()=>{if(!W||!z)return;e$({type:"stop",workspaceId:Z,sessionId:z})},[W,z,Z]),O=w4.useCallback((D)=>{n1.getState().setActive(Z,D)},[Z]);return{view:N,chatLoaded:B,previewTurn:F,sessionId:z,processing:W,error:K,send:A,stop:j,switchThread:O,dismissError:M}}var d7=_(x(),1);var w0=_(y(),1);function HM({builder:$,unavailableReason:Z,onSave:J,onSubmit:X,onOpenChat:Y,onDiscard:G}){let[Q,z]=d7.useState($.input.requirements),[H,U]=d7.useState(!1),[W,K]=d7.useState(null),V=d7.useRef(null),N=d7.useRef(J);N.current=J;let B=Q.trim().length>0,q=_4(B,H,Z);d7.useEffect(()=>{if($.status!=="draft"||Q===$.input.requirements)return;let L=setTimeout(()=>{N.current(Q).then(()=>K(null)).catch((A)=>K(A instanceof Error?A.message:"Could not save requirements"))},500);return()=>clearTimeout(L)},[$.input.requirements,$.status,Q]);let F=async(L)=>{if(L.preventDefault(),!q)return;U(!0);try{await X(Q)}catch(A){K(A instanceof Error?A.message:"Could not start view builder"),U(!1)}};if($.status==="draft")return w0.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center px-3 py-6",children:w0.jsxs("div",{className:"flex w-full max-w-(--chat-max-container) flex-col gap-6",children:[w0.jsxs("div",{className:"flex flex-col gap-1 text-center",children:[w0.jsx("h1",{className:"font-medium",children:"What should this view do?"}),w0.jsx("p",{className:"mx-auto max-w-sm text-sm text-muted-foreground",children:"Describe the content, data, and actions you need."})]}),w0.jsxs(HJ,{composerRef:V,onSubmit:F,children:[w0.jsx("label",{className:"sr-only",htmlFor:`view-builder-${$.id}`,children:"View requirements"}),w0.jsx(UJ,{textareaRef:V,id:`view-builder-${$.id}`,value:Q,onChange:(L)=>z(L.target.value),onKeyDown:(L)=>{if(L.key==="Enter"&&(L.metaKey||L.ctrlKey))L.preventDefault(),L.currentTarget.form?.requestSubmit()},placeholder:"Build a customer dashboard with…",rows:1,className:"min-h-16","aria-describedby":W?`view-builder-error-${$.id}`:void 0,"aria-invalid":Boolean(W),autoFocus:!0}),w0.jsxs(KJ,{children:[w0.jsx(dJ,{scope:"workspace"}),w0.jsx(WJ,{label:"Build view",hasContent:B,loading:H,unavailableReason:Z})]})]}),W&&w0.jsx("p",{id:`view-builder-error-${$.id}`,role:"alert",className:"text-sm text-destructive",children:W})]})});if($.status==="waiting")return w0.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:w0.jsxs("div",{className:"flex max-w-md flex-col items-center gap-4 text-center",children:[w0.jsxs("div",{className:"flex flex-col gap-1",children:[w0.jsx("h1",{className:"text-lg font-semibold",children:"The view needs your attention"}),w0.jsx("p",{className:"text-sm text-muted-foreground",children:$.error??"Open its chat to answer or ask the agent to continue."})]}),w0.jsxs("div",{className:"flex gap-2",children:[w0.jsx(M1,{onClick:Y,children:"Open chat"}),w0.jsx(M1,{variant:"secondary",onClick:G,children:"Discard"})]})]})});return w0.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center p-6",children:w0.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[w0.jsx(H5,{stroke:1.75,className:"animate-spin"}),$.status==="ready"?"Opening view…":"Building your view…"]})})}function UM(){let $=y1(),{workspaceId:Z,layout:J}=B0(),X=_6(Z).data,Y=o_(Z),G=t_(Z),Q=e_(Z),z=$M(Z);return{create:()=>Y.mutateAsync(),save:(V,N)=>G.mutateAsync({builderId:V,requirements:N}),submit:async(V,N)=>{let B=N.trim();if(!B)return;let q=IX({queryClient:$,workspaceId:Z,sessionId:V.sessionId,parts:[{type:"text",text:B}]});n1.getState().setActive(Z,V.sessionId);let{model:F,effort:L,stream:A}=xX(X,J.selectedModel,J.selectedEffort);try{await Q.mutateAsync({builderId:V.id,requirements:B,optimisticId:q,model:F,effort:L,stream:A})}catch(M){throw n1.getState().setActivity(Z,V.sessionId,"idle"),n1.getState().setError(Z,V.sessionId,M instanceof Error?M.message:"Could not start view builder"),M}},discard:(V)=>z.mutateAsync(V)}}var t6=_(x(),1);function KM($){let Z=document.documentElement,J=getComputedStyle(Z).getPropertyValue($).trim(),X=Number.parseFloat(J);if(!Number.isFinite(X))return 0;return J.endsWith("rem")?X*Number.parseFloat(getComputedStyle(Z).fontSize):X}function WM(){let $=t6.useRef(null),[Z,J]=t6.useState(!1);return t6.useLayoutEffect(()=>{let X=$.current;if(!X)return;let Y=(Q)=>{let z=KM("--column-w"),H=KM("--chat-min");J(Q-H>=z)};Y(X.getBoundingClientRect().width);let G=new ResizeObserver(([Q])=>{if(Q)Y(Q.contentRect.width)});return G.observe(X),()=>G.disconnect()},[]),{ref:$,fits:Z}}var C5=_(y(),1);function RX({error:$,pendingAction:Z,onUpdate:J,onDismiss:X}){if(!$&&Z==="auto")return C5.jsxs("div",{role:"status",className:"flex w-full items-center gap-1.5 p-2 text-sm text-muted-foreground",children:[C5.jsx(H5,{size:20,stroke:1.5,className:"shrink-0 animate-spin"}),C5.jsx("span",{className:"wrap-break-word",children:"Updating moi skills…"})]});let Y=Z!==null;return C5.jsxs("div",{role:$?"alert":"status",className:Z1("grid w-full grid-cols-[minmax(0,1fr)_auto] gap-x-2 gap-y-2 p-2 text-sm","@xl:flex @xl:items-center @xl:px-2 @xl:pl-3",$&&"text-destructive"),children:[C5.jsxs("div",{className:"flex min-w-0 items-start gap-1.5 @xl:order-1 @xl:flex-1 @xl:items-center",children:[C5.jsx(BM,{size:20,stroke:1.5,className:"shrink-0"}),$?C5.jsx("span",{className:"wrap-break-word",children:`Update failed: ${$}`}):C5.jsx("span",{className:"wrap-break-word",children:"This workspace is using old moi skills"})]}),C5.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",onClick:X,className:"col-start-2 row-start-1 -mt-1 -mr-1 text-muted-foreground hover:text-foreground @xl:order-4 @xl:m-0","aria-label":"Dismiss skill update",children:C5.jsx(i5,{stroke:1.75})}),C5.jsxs("div",{className:"col-span-2 flex flex-wrap gap-1.5 @xl:contents",children:[C5.jsxs(M1,{type:"button",variant:"default",size:"sm",onClick:()=>J("auto"),disabled:Y,className:"@xl:order-2",children:[Z==="auto"&&C5.jsx(H5,{stroke:1.75,className:"animate-spin"}),Z==="auto"?"Updating…":"Auto-update"]}),C5.jsxs(M1,{type:"button",variant:"secondary",size:"sm",onClick:()=>J("once"),disabled:Y,className:"@xl:order-3",children:[Z==="once"&&C5.jsx(H5,{stroke:1.75,className:"animate-spin"}),Z==="once"?"Updating…":"Update once"]})]})]})}var R9=_(x(),1);function Dz($){return{workspaceId:$,phase:"idle",pendingAction:null,error:null}}function Qh($){return $.phase==="active"||$.phase==="idle"&&$.updateAvailable&&!$.autoUpdateEnabled}function zh($){return $.updateAvailable&&$.autoUpdateEnabled&&!$.updatePending&&$.phase==="idle"}function VM($){let Z=xV($),{isPending:J,mutate:X,reset:Y}=RV($),G=bF(),{mutate:Q}=yF(),z=G.data!==void 0,H=G.data?.autoUpdateSkills??!1,U=R9.useCallback(()=>Q({autoUpdateSkills:!0}),[Q]),[W,K]=R9.useState(()=>Dz($)),V=W.workspaceId===$?W:Dz($);R9.useEffect(()=>{K(Dz($)),Y()},[$,Y]);let N=R9.useCallback((F)=>{if(J)return;if(F==="auto")U();K({workspaceId:$,phase:"active",pendingAction:F,error:null}),X(void 0,{onSuccess:()=>{K((L)=>L.workspaceId===$?{...L,phase:"dismissed",pendingAction:null,error:null}:L)},onError:(L)=>{K((A)=>A.workspaceId===$&&A.phase!=="dismissed"?{...A,phase:"active",pendingAction:null,error:L.message}:A)}})},[U,J,X,$]),B=Z.data?.updateAvailable??!1;return R9.useEffect(()=>{if(z&&zh({updateAvailable:B,autoUpdateEnabled:H,updatePending:J,phase:V.phase}))N("auto")},[H,V.phase,N,z,B,J]),{bannerProps:z&&Qh({updateAvailable:B,autoUpdateEnabled:H,phase:V.phase})?{error:V.error,pendingAction:V.pendingAction,onUpdate:N,onDismiss:()=>{K((F)=>F.workspaceId===$?{...F,phase:"dismissed",pendingAction:null,error:null}:F)}}:null}}var jz=rG();function fX($){if(!$||!Array.isArray($.open))return jz;let Z=$.open.filter((J,X,Y)=>Y.indexOf(J)===X);if(Z.length===0)return jz;return{open:Z,active:Z.includes($.active)?$.active:Z[0]}}function y3($,Z,J){if($==="agent"||$==="widgets"||$==="scratchpad")return!0;let X=A4($);if(X)return J.some((G)=>G.id===X);let Y=F9($);return Y?Z.some((G)=>G.id===Y):!1}function bX($,Z,J){let X=$.open.filter((Y)=>y3(Y,Z,J));return X.length>0?X:jz.open}function NM($){if(!$)return!1;let Z=Y3($);return Z===null||F9(Z)!==null}function qM($,Z,J,X,Y){if($!==null&&y3($,J,X)&&!(Y&&$==="agent"))return $;let G=bX(Z,J,X),Q=Y?G.filter((z)=>z!=="agent"):G;return Q.includes(Z.active)?Z.active:Q[0]??"agent"}var T7=_(x(),1);function AM({views:$,builders:Z,split:J}){let{layout:X,setLayout:Y,workspaceId:G}=B0(),[,Q]=C2(),z=FM()["*"]??null,H=LM(),U=T7.useMemo(()=>AV(H),[H]),W=fX(X.tabs),K=T7.useRef(W);K.current=W;let V=Y3(z),N=qM(V,W,$,Z,J),B=V!==null&&V===N,q=T7.useCallback((L,A)=>{Q(FV(G,L),{replace:!0,...A?{state:{appletParams:A}}:{}})},[Q,G]),F=T7.useCallback((L)=>{K.current=L,Y({tabs:L})},[Y]);return T7.useEffect(()=>{if(z===N)return;if(NM(z))Hh(G,z,N);q(N)},[N,q,z,G]),T7.useEffect(()=>{if(!B)return;let L=K.current,A=L.open.includes(N)?L.open:[...L.open,N];if(A===L.open&&L.active===N)return;F({open:A,active:N})},[N,F,B]),{tabsState:W,activeTab:N,appletParams:U,navigateToTab:q,setTabs:F}}function Hh($,Z,J){let X=Y3(Z),Y=X?F9(X):null;c2($,{source:"runtime",...Y?{kind:"view",name:Y}:{},message:`Tab "${Z}" does not exist in this workspace — the URL redirected to "${J}". A link, bookmark, or focusTab call is pointing at a tab that was deleted or renamed.`})}var y0=_(y(),1),Uh=MM([o8({variant:"ghost",size:"sm"}),"group/tab min-w-0"],{variants:{active:{true:"bg-accent text-accent-foreground"},dragging:{true:"invisible"},preview:{true:"cursor-grabbing ring-1 ring-border"}},compoundVariants:[{preview:!0}]});function Kh({items:$}){return y0.jsxs(C6,{children:[y0.jsx(h6,{render:y0.jsx(M1,{type:"button",variant:"ghost",size:"icon-sm",className:"text-muted-foreground","aria-label":"Create tab",children:y0.jsx(v5,{stroke:1.75})})}),y0.jsx(M4,{align:"start",className:"min-w-48",children:y0.jsx(O4,{children:$.map(({key:Z,Icon:J,label:X,onClick:Y})=>y0.jsxs(U3,{onClick:Y,className:"font-medium",children:[y0.jsx(J,{stroke:2}),X]},Z))})})]})}function _M($){let{tab:Z,active:J}=$,X=$.preview===!0;return y0.jsxs("button",{type:"button","aria-hidden":X||void 0,"aria-label":Z.label,disabled:X,tabIndex:X?-1:void 0,onClick:$.preview?void 0:()=>$.onSelect(Z.key),className:Uh({active:J,dragging:$.preview?!1:$.state.isDragging,preview:X}),...$.preview?{}:$.state.dragHandleProps,children:[y0.jsxs("div",{className:Z1("flex items-center gap-1 overflow-hidden",Z.closable&&"group-hover/tab:mr-3"),children:[y0.jsx(Z.Icon,{"data-icon":"inline-start",stroke:2}),y0.jsx("span",{className:Z1("truncate",Z.closable&&"group-hover/tab:-mr-3 group-hover/tab:mask-r-from-[calc(100%-24px)] group-hover/tab:mask-r-to-[calc(100%-12px)]"),children:Z.label})]}),Z.closable&&y0.jsx("div",{"aria-label":`Close ${Z.label}`,tabIndex:X?-1:void 0,className:Z1("absolute right-2 hidden size-3 items-center justify-center text-muted-foreground group-hover/tab:flex hover:text-foreground",X&&"pointer-events-none"),onClick:$.preview?void 0:(Y)=>{Y.stopPropagation(),$.onClose(Z.key)},children:y0.jsx(i5,{stroke:1.75})})]})}function OM({tabs:$,active:Z,createItems:J,onSelect:X,onClose:Y,onReorder:G}){return y0.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1",children:[y0.jsx("div",{className:"no-scrollbar min-w-0 scroll-fade-x overflow-x-auto overflow-y-hidden [--scroll-fade-reveal:16px]",children:y0.jsx(mZ,{items:$,getId:(Q)=>Q.key,className:"flex w-max items-center gap-1",onReorder:(Q)=>G(Q),renderPlaceholder:()=>y0.jsx("div",{className:"pointer-events-none absolute inset-0 rounded-md bg-muted"}),renderOverlay:(Q)=>y0.jsx(_M,{tab:Q,active:Z===Q.key,preview:!0}),renderItem:(Q,z)=>y0.jsx(_M,{tab:Q,active:Z===Q.key,state:z,onSelect:X,onClose:Y})})}),y0.jsx("div",{className:"shrink-0",children:y0.jsx(Kh,{items:J})})]})}var f1=_(y(),1),Wh=N2.lazy(()=>import("/chunk-jg6ezptn.js").then(($)=>({default:$.Scratchpad}))),TM=($)=>$.config.title||$.id,EM=($)=>wX($.icon)??B3;function wM($,Z){let J=Z.find((X)=>X.viewId===$.id);return wX($.config.icon)??wX(J?.icon)??B3}function Bh({mode:$,onToggleMode:Z}){return f1.jsx(M1,{variant:"ghost",size:"icon-sm",onClick:Z,"aria-label":$==="fullscreen"?"Switch to split view":"Switch to full-screen view",children:f1.jsx(jM,{stroke:1.75})})}function Vh({view:$,params:Z}){let J=s0(),X=SV($.id);return f1.jsx("div",{className:"relative min-h-0 flex-1 overflow-hidden",children:f1.jsxs(j7,{mode:"wait",initial:!1,children:[X.status==="ready"&&f1.jsx(YX,{asChild:!0,segment:"views",name:$.id,version:X.version,children:f1.jsx(m0.div,{className:"absolute inset-0 overflow-auto",initial:{opacity:0,filter:"blur(4px)"},animate:{opacity:1,filter:"blur(0px)"},exit:{opacity:0,filter:"blur(4px)"},transition:{duration:0.3,ease:"easeInOut"},children:f1.jsx(F3,{name:$.id,kind:"view",workspaceId:J,resetKey:X.version,children:f1.jsx(X.Component,{params:Z})})})},X.version),X.status==="error"&&f1.jsx(m0.p,{className:"absolute inset-0 p-4 text-xs text-destructive",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:0.3,ease:"easeInOut"},children:X.error},`err-${X.version}`)]})})}function Nh({active:$,onToggle:Z}){return f1.jsxs(V7,{children:[f1.jsx(N7,{render:f1.jsx(M1,{variant:$?"secondary":"ghost",size:"icon-sm","aria-label":"Customize","aria-pressed":$,onClick:Z,children:f1.jsx(PM,{stroke:1.75})})}),f1.jsx(q7,{children:"Customize"})]})}function qh($,Z,J,X){if($==="agent")return{key:$,Icon:y7,label:"Agent",closable:X};if($==="widgets")return{key:$,Icon:V3,label:"Widgets",closable:X};if($==="scratchpad")return{key:$,Icon:N3,label:"Scratchpad",closable:X};let Y=A4($),G=Y?J.find((H)=>H.id===Y):null;if(G)return{key:$,Icon:EM(G),label:G.title||G.viewId||"New view",closable:X};let Q=F9($),z=Q?Z.find((H)=>H.id===Q):null;return z?{key:$,Icon:wM(z,J),label:TM(z),closable:X}:null}function Lh($,Z,J){let X=new Set(Z),Y=0;return $.map((G)=>X.has(G)?J[Y++]:G)}function kM({widgets:$,views:Z,builders:J}){let{layout:X,setLayout:Y,name:G,icon:Q,provider:z,workspaceId:H}=B0(),U=IV(H).data,{bannerProps:W}=VM(H),K=U===void 0?void 0:U.available?null:U.reason,V=UM(),{ref:N,fits:B}=WM(),[q,F]=N2.useState("idle"),[L,A]=N2.useState(!1),[M,j]=N2.useState(0);UV(X.theme);let O=bX(fX(X.tabs),Z,J),D=O.filter((c)=>c!=="agent"),P=D.length>0,k=X.layoutMode==="split"&&P&&B?"split":"fullscreen",S=k==="split",{tabsState:I,activeTab:E,appletParams:w,navigateToTab:C,setTabs:h}=AM({views:Z,builders:J,split:S}),{view:b,chatLoaded:f,previewTurn:g,sessionId:o,processing:m,error:V1,send:U1,stop:q1,switchThread:e,dismissError:D1}=zM({activeTab:E,appletParams:w}),v=new Set(I.open),$1=(c)=>{Y({layoutMode:c})},K1=S?D:O,t=O.length>1,J1=K1.map((c)=>qh(c,Z,J,t||A4(c)!==null)).filter((c)=>Boolean(c)),z1=F9(E),R=z1?Z.find((c)=>c.id===z1):void 0,i=A4(E),u=i?J.find((c)=>c.id===i):void 0;N2.useEffect(()=>{if(I.open.filter((x1)=>y3(x1,Z,J)).length===I.open.length)return;let _1=bX(I,Z,J);Y({tabs:{open:_1,active:_1.includes(I.active)?I.active:_1[0]}})},[J,Y,I,Z]),N2.useEffect(()=>{let c=new Map;for(let b1 of J){if(b1.status!=="ready"||!b1.viewId)continue;if(!Z.some((s1)=>s1.id===b1.viewId))continue;c.set(G3(b1.id),cG(b1.viewId))}if(c.size===0)return;let _1=c.get(E);if(_1)C(_1);let x1=new Set(c.values()),$0=new Map([...c].map(([b1,s1])=>[s1,b1])),d1=[],w1=!1;for(let b1 of I.open){let s1=$0.get(b1);if(x1.has(b1)&&s1&&I.open.includes(s1)){w1=!0;continue}let r0=c.get(b1),h5=r0??b1;if(r0)w1=!0;if(!d1.includes(h5))d1.push(h5)}if(!w1)return;let o1=c.get(I.active)??I.active;Y({tabs:{open:d1.length>0?d1:["agent"],active:o1}})},[E,J,C,Y,I,Z]),N2.useEffect(()=>{let c=u??J.find((_1)=>_1.viewId===z1);if(c)n1.getState().setActive(H,c.sessionId)},[u,z1,J,H]),N2.useEffect(()=>{if(k!=="fullscreen"||E==="agent")A(!1)},[E,k]);let W1=(c,_1)=>{if(C(c,_1),c==="agent")A(!1),j((x1)=>x1+1)};YJ(H,"focusTab",W1),r5((c)=>{if(c.type==="tab:focus"&&c.workspaceId===H)W1(c.tab,c.params)});let s=(c)=>{let _1=A4(c),x1=_1?J.find((b1)=>b1.id===_1):void 0;if(!t&&!x1||!v.has(c))return;let $0=I.open.filter((b1)=>b1!==c);if($0.length===0)$0=["agent"];let d1=K1.indexOf(c),w1=K1[d1+1]??K1[d1-1]??$0.find((b1)=>y3(b1,Z,J))??"agent",o1=I.active===c||!$0.includes(I.active)?w1:I.active;if(h({open:$0,active:o1}),E===c)C(w1);if(x1?.status==="draft")V.discard(x1.id)},X1=(c)=>{let _1=G3(c.id);if(v.has(_1)){let x1=I.open.filter(($0)=>$0!==_1);if(x1.length===0)x1=["agent"];if(h({open:x1,active:I.active===_1?x1[0]:I.active}),E===_1)C(x1[0])}V.discard(c.id)},G1=(c)=>{let _1=Lh(I.open,K1,c);if(_1===I.open)return;h({open:_1,active:I.active})},d=(c)=>{if(c!==void 0)n1.getState().setDraft(H,o,c);if(k==="fullscreen"&&E!=="agent"){if(A(!0),L)j((_1)=>_1+1);return}j((_1)=>_1+1)};a_({send:U1,revealChat:d,unavailableReason:K});let Q1=[...!S&&!v.has("agent")?[{key:"agent",Icon:y7,label:"Agent",onClick:()=>W1("agent")}]:[],...!v.has("widgets")?[{key:"widgets",Icon:V3,label:"Widgets",onClick:()=>W1("widgets")}]:[],...!v.has("scratchpad")?[{key:"scratchpad",Icon:N3,label:"Scratchpad",onClick:()=>W1("scratchpad")}]:[],...Z.map((c)=>({view:c,tab:cG(c.id)})).filter(({tab:c})=>!v.has(c)).map(({view:c,tab:_1})=>({key:_1,Icon:wM(c,J),label:TM(c),onClick:()=>W1(_1)})),...J.filter((c)=>c.status!=="ready").map((c)=>({builder:c,tab:G3(c.id)})).filter(({tab:c})=>!v.has(c)).map(({builder:c,tab:_1})=>({key:_1,Icon:EM(c),label:c.title||c.viewId||"New view",onClick:()=>W1(_1)})),{key:"create-view",Icon:DM,label:"New view",onClick:()=>{V.create().then((c)=>W1(G3(c.id)))}}],n=f1.jsx(aJ,{active:k==="split",focusRequest:M,chatLoaded:f,view:b,previewTurn:g,sessionId:o,processing:m,error:V1,onDismissError:D1,composerBanner:W?f1.jsx(RX,{...W}):void 0,unavailableReason:K,send:U1,stop:q1,onSwitchThread:e}),L1=f1.jsx(aJ,{active:k==="fullscreen"&&E==="agent",focusRequest:M,chatLoaded:f,view:b,previewTurn:g,sessionId:o,processing:m,error:V1,onDismissError:D1,composerBanner:W?f1.jsx(RX,{...W}):void 0,unavailableReason:K,send:U1,stop:q1,onSwitchThread:e});return f1.jsxs("div",{className:"relative flex h-full min-h-0 flex-col bg-background font-sans text-foreground",children:[f1.jsxs("div",{ref:N,className:"flex min-h-0 flex-1",children:[(k==="fullscreen"||P)&&f1.jsxs("div",{className:Z1("flex min-h-0 flex-1 flex-col",k==="split"&&"min-w-(--column-w)"),children:[f1.jsxs(jF,{children:[f1.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-4",children:[f1.jsxs("div",{className:"flex items-center gap-2",children:[f1.jsx("img",{src:Q??l2[z??"claude-code"],alt:"",className:"size-5 shrink-0 rounded-xs"}),G&&f1.jsx("span",{className:"truncate text-sm font-medium text-foreground",children:G})]}),f1.jsx(OM,{tabs:J1,active:E,createItems:Q1,onSelect:W1,onClose:s,onReorder:G1})]}),f1.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[f1.jsx(Nh,{active:q==="customizing",onToggle:()=>F(q==="customizing"?"idle":"customizing")}),f1.jsx(s_,{}),P&&B&&f1.jsx(Bh,{mode:k,onToggleMode:()=>$1(k==="fullscreen"?"split":"fullscreen")})]})]}),E==="agent"?L1:E==="widgets"?f1.jsx(DF,{editing:q==="editing",onEditingChange:(c)=>F(c?"editing":"idle"),widgets:$,onCreateWidget:()=>d("Create widget")}):E==="scratchpad"?f1.jsx(N2.Suspense,{fallback:null,children:f1.jsx(Wh,{})}):u?f1.jsx(HM,{builder:u,unavailableReason:K,onSave:(c)=>V.save(u.id,c),onSubmit:(c)=>{if(k==="fullscreen")A(!0);return V.submit(u,c)},onOpenChat:()=>{n1.getState().setActive(H,u.sessionId),d()},onDiscard:()=>X1(u)},u.id):R?f1.jsx(Vh,{view:R,params:w}):null]}),k==="split"&&f1.jsx("div",{className:Z1("flex min-h-0 min-w-(--chat-min) flex-[0_1_var(--chat-max)] flex-col overflow-hidden border-l border-border"),children:n})]}),f1.jsx(j7,{children:q==="customizing"&&f1.jsx(iq,{onClose:()=>F("idle")})}),k==="fullscreen"&&E!=="agent"&&P&&f1.jsx(pq,{open:L,onOpenChange:A,onOpenChangeComplete:(c)=>{if(c)j((_1)=>_1+1)},children:(c)=>f1.jsx(aJ,{active:L,focusRequest:M,chatLoaded:f,view:b,previewTurn:g,sessionId:o,processing:m,error:V1,onDismissError:D1,composerBanner:W?f1.jsx(RX,{...W}):void 0,unavailableReason:K,send:U1,stop:q1,onSwitchThread:e,onClose:c})})]})}var yX=_(x(),1);function SM($,Z,J,X){let Y=yX.useRef(null);yX.useEffect(()=>{if(!Z)return;let G=new Map(Z.map((N)=>[N.id,{w:N.config.colSpan,h:N.config.rowSpan}]));if(Y.current?.workspaceId!==$){Y.current={workspaceId:$,sizes:G};return}let Q=Y.current.sizes,z=new Set(J.widgetGrid.map((N)=>N.i)),H=Z.filter((N)=>{if(!Q.has(N.id))return!z.has(N.id);if(!z.has(N.id))return!1;let q=Q.get(N.id);return q.w!==N.config.colSpan||q.h!==N.config.rowSpan});if(Y.current={workspaceId:$,sizes:G},H.length===0)return;let U=new Map(Z.map((N)=>[N.id,N.config])),W=J.widgetGrid.filter((N)=>!H.some((B)=>B.id===N.i)&&U.has(N.i)).map((N)=>{let B=U.get(N.i);return{i:N.i,x:N.x,y:N.y,w:B.colSpan,h:B.rowSpan}}),K=W.map(({i:N,x:B,y:q})=>({i:N,x:B,y:q})),V=[...W];for(let N of H){let B=A3(V,N.config.colSpan,N.config.rowSpan,4);K.push({i:N.id,x:B.x,y:B.y}),V.push({i:N.id,x:B.x,y:B.y,w:N.config.colSpan,h:N.config.rowSpan})}X({widgetGrid:K})},[$,Z,J.widgetGrid,X])}var q2=_(y(),1);function xM({id:$}){return q2.jsx(hM,{id:$,children:q2.jsx(mV,{id:$,children:q2.jsx(Fh,{id:$})})})}function Fh({id:$}){let Z=y1(),{layout:J,setLayout:X,isLoading:Y}=B0(),G=fV($),Q=zJ($),z=hX($),H=A6($);SM($,G.data,J,X),CV(),r5((W)=>{if(W.type==="theme:updated"||W.type==="workspace:updated")Z.invalidateQueries({queryKey:B1.layout($)});else if(W.type==="widget-layout:updated"||W.type==="widget:updated")Z.invalidateQueries({queryKey:B1.widgets($)});else if(W.type==="view-layout:updated")Z.invalidateQueries({queryKey:B1.views($)})});let U=Y||G.isLoading||Q.isLoading||z.isLoading;return q2.jsxs(q2.Fragment,{children:[q2.jsx(Ah,{workspaceId:$,sessions:H.data}),q2.jsx(uZ,{children:U?q2.jsx("div",{className:"flex h-full items-center justify-center",children:q2.jsx(CM,{sprite:"moi",effect:"chaos"})}):q2.jsx(kM,{widgets:G.data??[],views:Q.data??[],builders:z.data??[]})})]})}function Ah({workspaceId:$,sessions:Z}){return IM.useEffect(()=>{if(!Z)return;let J=n1.getState().activeByWorkspace,X=Object.prototype.hasOwnProperty.call(J,$),Y=J[$],G=Y===null||Z.some((Q)=>Q.sessionId===Y);if(X&&G)return;n1.getState().setActive($,Z[0]?.sessionId??null)},[$,Z]),null}var l7=_(y(),1),_h=e6.lazy(()=>import("/chunk-7bzpmtxp.js"));function Mh(){return l7.jsx(e6.Suspense,{fallback:null,children:l7.jsx(_h,{})})}function fM(){let[,$]=C2();return e6.useEffect(()=>{return JG((Z)=>$(`/workspace/${Z}`)),()=>JG(null)},[$]),l7.jsxs(RM,{children:[l7.jsx(vX,{path:"/",component:VV}),l7.jsx(vX,{path:"/dev/*?",component:Mh}),l7.jsx(vX,{path:"/workspace/:id/*?",children:(Z)=>l7.jsx(xM,{id:Z.id},Z.id)})]})}var k4=_(y(),1),vM=new tX;qK(vM);YK();function CJ1($){function Z(){return k4.jsx($Y,{client:vM,children:k4.jsxs(ZK,{children:[k4.jsx(bM,{children:k4.jsx(fM,{})}),!1]})})}yM.createRoot($).render(k4.jsx(Z,{}))}export{CJ1 as mount};
|
|
@@ -92,7 +92,7 @@ Keep seeing this message?
|
|
|
92
92
|
*
|
|
93
93
|
* N.B. On iOS, you have to take into account the offsetTop as well so that you get an accurate position
|
|
94
94
|
* while using the virtual keyboard.
|
|
95
|
-
*/function HU(J){let Q=new ArrayBuffer(J.length),Z=new Uint8Array(Q);for(let q=0,X=J.length;q<X;q++)Z[q]=J.charCodeAt(q);return Q}function hg(J){let Q=atob(J),Z=HU(Q);return crypto.subtle.importKey("spki",new Uint8Array(Z),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}var DJ0=30,R2={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8,EVALUATION_LICENSE:16,NATIVE_LICENSE:32},MJ0=Math.max(...Object.values(R2)),yG={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},jJ0=Object.keys(yG).length,dK="sales@tldraw.com",RJ0=`${Q6()}/watermarks/watermark-track.svg`;class UZ{publicKey="MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ";isDevelopment;isTest;isCryptoAvailable;state=V0("license state","pending");verbose=!0;constructor(J,Q){this.isTest=!1,this.isDevelopment=this.getIsDevelopment(),this.publicKey=Q||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.getLicenseFromKey(J).then((Z)=>{let q=kJ0(Z,(X)=>this.outputMessages(X),this.isDevelopment);this.maybeTrack(Z,q),this.state.set(q)}).catch((Z)=>{console.error("License validation failed:",Z),this.state.set("unlicensed")})}getIsDevelopment(){return!["https:","vscode-webview:"].includes(window.location.protocol)||this.isLoopbackHost(window.location.hostname)||!1}isLoopbackHost(J){let Q=J.toLowerCase().replace(/^\[|\]$/g,"");return Q==="localhost"||Q==="::1"||/^127(?:\.\d{1,3}){3}$/.test(Q)}getTrackType(J,Q){if(Q==="unlicensed-production")return"unlicensed";if(this.isDevelopment)return null;if(!J.isLicenseParseable)return null;if(J.isEvaluationLicense)return"evaluation";if(Q==="licensed-with-watermark")return"with_watermark";return null}maybeTrack(J,Q){let Z=this.getTrackType(J,Q);if(!Z)return;let q=new URL(RJ0);if(q.searchParams.set("version",gK),q.searchParams.set("license_type",Z),"license"in J){q.searchParams.set("license_id",J.license.id);let X=this.isFlagEnabled(J.license.flags,R2.EVALUATION_LICENSE)?"evaluation":this.isFlagEnabled(J.license.flags,R2.ANNUAL_LICENSE)?"annual":this.isFlagEnabled(J.license.flags,R2.PERPETUAL_LICENSE)?"perpetual":"unknown";q.searchParams.set("sku",X)}q.searchParams.set("url",window.location.href),q.searchParams.set("environment","production"),fetch(q.toString())}async extractLicenseKey(J){let[Q,Z]=J.split("."),[q,X]=Q.split("/");if(!q.startsWith("tldraw-"))throw Error(`Unsupported prefix '${q}'`);let K=await hg(this.publicKey),Y;try{Y=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},K,new Uint8Array(HU(atob(Z))),new Uint8Array(HU(atob(X))))}catch(z){throw console.error(z),Error("Could not perform signature validation")}if(!Y)throw Error("Invalid signature");let W;try{W=JSON.parse(atob(X))}catch{throw Error("Could not parse object")}if(W.length>jJ0)this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]);return{id:W[yG.ID],hosts:W[yG.HOSTS],flags:W[yG.FLAGS],expiryDate:W[yG.EXPIRY_DATE]}}async getLicenseFromKey(J){if(!J){if(!this.isDevelopment)this.outputNoLicenseKeyProvided();return{isLicenseParseable:!1,reason:"no-key-provided"}}if(this.isDevelopment&&!this.isCryptoAvailable){if(this.verbose)console.log("tldraw: you seem to be in a development environment that does not support crypto. License not verified."),console.log("You should check that this works in production separately.");return{isLicenseParseable:!1,reason:"has-key-development-mode"}}let Q=J.replace(/[\u200B-\u200D\uFEFF]/g,"");Q=Q.replace(/\r?\n|\r/g,"");try{let Z=await this.extractLicenseKey(Q),q=new Date(Z.expiryDate),X=this.isFlagEnabled(Z.flags,R2.ANNUAL_LICENSE),K=this.isFlagEnabled(Z.flags,R2.PERPETUAL_LICENSE),Y=this.isFlagEnabled(Z.flags,R2.EVALUATION_LICENSE),W=X&&this.isAnnualLicenseExpired(q),z=K&&this.isPerpetualLicenseExpired(q),G=K&&!z?0:this.getDaysSinceExpiry(q),H={license:Z,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(Z),expiryDate:q,isAnnualLicense:X,isAnnualLicenseExpired:W,isPerpetualLicense:K,isPerpetualLicenseExpired:z,isInternalLicense:this.isFlagEnabled(Z.flags,R2.INTERNAL_LICENSE),isNativeLicense:this.isNativeLicense(Z),isLicensedWithWatermark:this.isFlagEnabled(Z.flags,R2.WITH_WATERMARK),isEvaluationLicense:Y,isEvaluationLicenseExpired:Y&&this.isEvaluationLicenseExpired(q),daysSinceExpiry:G};return this.outputLicenseInfoIfNeeded(H),H}catch(Z){return this.outputInvalidLicenseKey(Z.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(J){let Q=window.location.hostname.toLowerCase();return J.hosts.some((Z)=>{let q=Z.toLowerCase().trim();if(q===Q||`www.${q}`===Q||q===`www.${Q}`)return!0;if(Z==="*")return!0;if(this.isNativeLicense(J))return new RegExp(q).test(window.location.href);if(Z.includes("*")){let X=new RegExp(Z.replace(/\*/g,".*?"));return X.test(Q)||X.test(`www.${Q}`)}if(window.location.protocol==="vscode-webview:"){let K=new URL(window.location.href).searchParams.get("extensionId");if(q===K)return!0}return!1})}isNativeLicense(J){return this.isFlagEnabled(J.flags,R2.NATIVE_LICENSE)}getExpirationDateWithoutGracePeriod(J){return new Date(J.getFullYear(),J.getMonth(),J.getDate())}getExpirationDateWithGracePeriod(J){return new Date(J.getFullYear(),J.getMonth(),J.getDate()+DJ0+1)}isAnnualLicenseExpired(J){let Q=this.getExpirationDateWithGracePeriod(J);return new Date>=Q}isPerpetualLicenseExpired(J){let Q=this.getExpirationDateWithGracePeriod(J),Z={major:new Date(vj.major),minor:new Date(vj.minor)};return Z.major>=Q||Z.minor>=Q}getDaysSinceExpiry(J){let Q=new Date,Z=this.getExpirationDateWithoutGracePeriod(J),q=Q.getTime()-Z.getTime(),X=Math.floor(q/86400000);return Math.max(0,X)}isEvaluationLicenseExpired(J){let Q=new Date,Z=this.getExpirationDateWithoutGracePeriod(J);return Q>=Z}isFlagEnabled(J,Q){return(J&Q)===Q}outputNoLicenseKeyProvided(){}outputInvalidLicenseKey(J){this.outputMessages(["Invalid tldraw license key",`Reason: ${J}`])}outputLicenseInfoIfNeeded(J){if(J.license.flags>=MJ0*2)this.outputMessages(["Warning: This tldraw license contains some unknown flags.","This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality."],"warning")}outputMessages(J,Q="error"){if(this.isTest)return;if(this.verbose){this.outputDelimiter(Q);for(let Z of J){let q=Q==="warning"?"orange":"crimson";console.log(`%c${Z}`,`color: white; background: ${q}; padding: 2px; border-radius: 3px;`)}this.outputDelimiter(Q)}}outputDelimiter(J="error"){console.log("%c-------------------------------------------------------------------",`color: white; background: ${J==="warning"?"orange":"crimson"}; padding: 2px; border-radius: 3px;`)}static className="tl-watermark_SEE-LICENSE"}function kJ0(J,Q,Z){if(!J.isLicenseParseable){if(Z)return"unlicensed";if(J.reason==="no-key-provided")Q(["No tldraw license key provided!","A license is required for production deployments.",`Please reach out to ${dK} to purchase a license.`]);else Q(["Invalid license key. tldraw requires a valid license for production use.",`Please reach out to ${dK} to purchase a license.`]);return"unlicensed-production"}if(!J.isDomainValid&&!J.isDevelopment)return Q(["License key is not valid for this domain.","A license is required for production deployments.",`Please reach out to ${dK} to purchase a license.`]),"unlicensed-production";if(J.isEvaluationLicense)if(J.isEvaluationLicenseExpired)return Q(["Your tldraw evaluation license has expired!",`Please reach out to ${dK} to purchase a full license.`]),"expired";else return"licensed";if(J.isPerpetualLicenseExpired||J.isAnnualLicenseExpired)return Q(["Your tldraw license has been expired for more than 30 days!",`Please reach out to ${dK} to renew your license.`]),"expired";let q=J.daysSinceExpiry;if(q>0&&!J.isEvaluationLicense)return Q(["Your tldraw license has expired.",`License expired ${q} days ago.`,`Please reach out to ${dK} to renew your license.`]),"licensed";if(J.isLicensedWithWatermark)return"licensed-with-watermark";return"licensed"}var FU=E(c(),1);var wJ=E(m(),1);var mg=wJ.createContext({});function cg(){return wJ.useContext(mg)}function ug(J){return J==="expired"||J==="unlicensed-production"}var lg=5000;function pg({licenseKey:J=AJ0()??void 0,children:Q}){let[Z]=wJ.useState(()=>new UZ(J)),q=S(Z.state),[X,K]=wJ.useState(!0);if(wJ.useEffect(()=>{if(ug(q)&&X){let Y=setTimeout(()=>{K(!1)},lg);return()=>clearTimeout(Y)}},[q,X]),ug(q)&&!X)return FU.jsx(EJ0,{});return FU.jsx(mg.Provider,{value:Z,children:Q})}function EJ0(){return FU.jsx("div",{"data-testid":"tl-license-expired",style:{display:"none"}})}var _U=void 0;function AJ0(){if(_U!==void 0)return _U;return _U=t9(()=>process.env.TLDRAW_LICENSE_KEY)||t9(()=>process.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY)||t9(()=>process.env.REACT_APP_TLDRAW_LICENSE_KEY)||t9(()=>process.env.GATSBY_TLDRAW_LICENSE_KEY)||t9(()=>process.env.VITE_TLDRAW_LICENSE_KEY)||t9(()=>"")||t9(()=>import.meta.env.TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.REACT_APP_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.GATSBY_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.VITE_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.PUBLIC_TLDRAW_LICENSE_KEY)||null,_U}function t9(J){try{return J()}catch{return}}function bJ(J,Q=20){return Math.max(8,Math.ceil(J/Q))}class O3 extends n6{_center;_radius;_start;_end;_largeArcFlag;_sweepFlag;_measure;_angleStart;_angleEnd;constructor(J){super({...J,isFilled:!1,isClosed:!1});let{center:Q,sweepFlag:Z,largeArcFlag:q,start:X,end:K}=J;if(X.equals(K))throw Error("Arc must have different start and end points.");this._angleStart=D.Angle(Q,X),this._angleEnd=D.Angle(Q,K),this._radius=D.Dist(Q,X),this._measure=vM(this._angleStart,this._angleEnd,Z,q),this._start=X,this._end=K,this._sweepFlag=Z,this._largeArcFlag=q,this._center=Q}nearestPoint(J){let{_center:Q,_measure:Z,_radius:q,_angleEnd:X,_angleStart:K,_start:Y,_end:W}=this,z=AF(Z,K,X,Q.angle(J));if(z<=0)return Y;if(z>=1)return W;let G=J.x-Q.x,H=J.y-Q.y,$=Math.sqrt(G*G+H*H);if($===0)return Y;let _=q/$;return new D(Q.x+G*_,Q.y+H*_)}hitTestLineSegment(J,Q){let{_center:Z,_radius:q,_measure:X,_angleStart:K,_angleEnd:Y}=this,W=kJ(J,Q,Z,q);if(W===null)return!1;return W.some((z)=>{let G=AF(X,K,Y,Z.angle(z));return G>=0&&G<=1})}getVertices(){let{_center:J,_measure:Q,length:Z,_radius:q,_angleStart:X}=this,K=[];for(let Y=0,W=bJ(Math.abs(Z));Y<W+1;Y++){let z=Y/W*Q,G=X+z;K.push(J3(J,q,G))}return K}getSvgPathData(J=!0){let{_start:Q,_end:Z,_radius:q,_largeArcFlag:X,_sweepFlag:K}=this;return`${J?`M${Q.toFixed()}`:""} A${q} ${q} 0 ${X} ${K} ${Z.toFixed()}`}getLength(){return Math.abs(this._measure*this._radius)}}class p7 extends n6{constructor(J){super({isClosed:!0,...J});this.config=J;let{x:Q=0,y:Z=0,radius:q}=J;this._x=Q,this._y=Z,this._center=new D(q+Q,q+Z),this._radius=q}config;_center;_radius;_x;_y;getBounds(){return new p(this._x,this._y,this._radius*2,this._radius*2)}getVertices(){let{_center:J,_radius:Q}=this,Z=N1*Q,q=[];for(let X=0,K=bJ(Z);X<K;X++){let Y=X/K*N1;q.push(J3(J,Q,Y))}return q}nearestPoint(J){let{_center:Q,_radius:Z}=this,q=J.x-Q.x,X=J.y-Q.y,K=Math.sqrt(q*q+X*X);if(K===0)return new D(Q.x+Z,Q.y);let Y=Z/K;return new D(Q.x+q*Y,Q.y+X*Y)}distanceToPoint(J,Q=!1){let{_center:Z,_radius:q}=this,X=J.x-Z.x,K=J.y-Z.y,W=Math.sqrt(X*X+K*K)-q;if(W<0&&(this.isFilled||Q))return W;return Math.abs(W)}hitTestPoint(J,Q=0,Z=!1){let{_center:q,_radius:X}=this,K=J.x-q.x,Y=J.y-q.y,W=K*K+Y*Y;if((this.isFilled||Z)&&W<=X*X)return!0;let z=X+Q;if(W>z*z)return!1;let G=X-Q;if(G<=0)return!0;return W>=G*G}hitTestLineSegment(J,Q,Z=0){let{_center:q,_radius:X}=this;return kJ(J,Q,q,X+Z)!==null}getSvgPathData(){let{_center:J,_radius:Q}=this;return`M${J.x+Q},${J.y} a${Q},${Q} 0 1,0 ${Q*2},0a${Q},${Q} 0 1,0 -${Q*2},0`}}class iK extends o9{_a;_b;_c;_d;_resolution;constructor(J){let{start:Q,cp1:Z,cp2:q,end:X}=J;super({...J,points:[Q,X]});this._a=Q,this._b=Z,this._c=q,this._d=X,this._resolution=J.resolution??10}getVertices(){let J=[],{_a:Q,_b:Z,_c:q,_d:X}=this;for(let K=0,Y=this._resolution;K<=Y;K++){let W=K/Y;J.push(new D((1-W)*(1-W)*(1-W)*Q.x+3*((1-W)*(1-W))*W*Z.x+3*(1-W)*(W*W)*q.x+W*W*W*X.x,(1-W)*(1-W)*(1-W)*Q.y+3*((1-W)*(1-W))*W*Z.y+3*(1-W)*(W*W)*q.y+W*W*W*X.y))}return J}nearestPoint(J){let Q,Z=1/0,q,X;for(let K of this.segments)if(X=K.nearestPoint(J),q=D.Dist2(X,J),q<Z)Q=X,Z=q;if(!Q)throw Error("nearest point not found");return Q}distanceToPoint(J,Q=!1){let{segments:Z}=this,q=1/0;for(let X=0;X<Z.length;X++){let K=Z[X].distanceToPoint(J);if(K<q)q=K}return q}getSvgPathData(J=!0){let{_a:Q,_b:Z,_c:q,_d:X}=this;return`${J?`M ${Q.toFixed()} `:""} C${Z.toFixed()} ${q.toFixed()} ${X.toFixed()}`}static GetAtT(J,Q){let{_a:Z,_b:q,_c:X,_d:K}=J;return new D((1-Q)*(1-Q)*(1-Q)*Z.x+3*((1-Q)*(1-Q))*Q*q.x+3*(1-Q)*(Q*Q)*X.x+Q*Q*Q*K.x,(1-Q)*(1-Q)*(1-Q)*Z.y+3*((1-Q)*(1-Q))*Q*q.y+3*(1-Q)*(Q*Q)*X.y+Q*Q*Q*K.y)}getLength(J,Q=32){let Z,q=this._a,X=0;for(let K=1;K<=Q;K++)Z=iK.GetAtT(this,K/Q),X+=D.Dist(q,Z),q=Z;return X}}class nK extends n6{constructor(J){super({...J,isClosed:!0});this.config=J;let{width:Q,height:Z}=J;this._w=Q,this._h=Z}config;_w;_h;_edges;get edges(){if(!this._edges){let{vertices:J}=this;this._edges=[];for(let Q=0,Z=J.length;Q<Z;Q++){let q=J[Q],X=J[(Q+1)%Z];this._edges.push(new l8({start:q,end:X}))}}return this._edges}getVertices(){let J=Math.max(1,this._w),Q=Math.max(1,this._h),Z=J/2,q=Q/2,X=Math.pow(Z-q,2)/Math.pow(Z+q,2),K=B1*(Z+q)*(1+3*X/(10+Math.sqrt(4-3*X))),Y=bJ(K),W=N1/Y,z=Math.cos(W),G=Math.sin(W),H=0,$=1,_=0,F=1,U=Array(Y);for(let V=0;V<Y;V++)U[V]=new D(M0(Z+Z*$,0,J),M0(q+q*H,0,Q)),_=G*$+z*H,F=z*$-G*H,H=_,$=F;return U}nearestPoint(J){let Q,Z=1/0,q,X;for(let K of this.edges)if(X=K.nearestPoint(J),q=D.Dist2(X,J),q<Z)Q=X,Z=q;if(!Q)throw Error("nearest point not found");return Q}distanceToPoint(J,Q=!1){let{edges:Z}=this,q=1/0;for(let X=0;X<Z.length;X++){let K=Z[X].distanceToPoint(J);if(K<q)q=K}if(this.isClosed&&(this.isFilled||Q)&&n1(J,this.vertices))return-q;return q}hitTestLineSegment(J,Q){return this.edges.some((Z)=>Z.hitTestLineSegment(J,Q))}getBounds(){return new p(0,0,this._w,this._h)}getLength(){let{_w:J,_h:Q}=this,Z=J/2,q=Q/2,X=Math.max(0,Z),K=Math.max(0,q);return bM(X,K)}getSvgPathData(J=!1){let{_w:Q,_h:Z}=this,q=Q/2,X=Z/2,K=Math.max(0,q),Y=Math.max(0,X);return`${J?`M${q-K},${X}`:""} a${K},${Y},0,1,1,${K*2},0a${K},${Y},0,1,1,-${K*2},0`}}var i4=E(c(),1);var Zh=E(c1(),1),Y4=E(m(),1);var dg=E(m(),1);function ig(){let J=y(),Q=Q1(),Z=z6(),q=S(V1.forceSrgb);dg.default.useEffect(()=>{if(Z==="dark")Q.setAttribute("data-color-mode","dark"),Q.classList.remove("tl-theme__light"),Q.classList.add("tl-theme__dark");else Q.setAttribute("data-color-mode","light"),Q.classList.remove("tl-theme__dark"),Q.classList.add("tl-theme__light");if(q)Q.classList.add("tl-theme__force-sRGB");else Q.classList.remove("tl-theme__force-sRGB")},[J,Q,q,Z])}var UU=E(m(),1);function ng(){let[J,Q]=UU.useState(0);UU.useEffect(()=>Q((Z)=>Z+1),[])}var sg=E(m(),1);function rg(){let J=y();sg.useLayoutEffect(()=>{return g1("stateAttribute",()=>{let Q=J.getContainer(),Z=J.getInstanceState();Q.setAttribute("data-state",J.getPath()),Q.setAttribute("data-coarse",String(Z.isCoarsePointer))})},[J])}var ag=E(m(),1);function og(){let J=y(),Q=Q1();ag.useEffect(()=>{let Z=(K)=>Q.style.setProperty("--tl-zoom",K.toString()),q=$J(Z,100),X=new U9("useZoomCss",()=>Z(J.getEfficientZoomLevel()));return X.attach(),X.execute(),()=>{X.detach(),q.cancel()}},[J,Q])}var b9=E(c(),1);var VZ=E(m(),1);var tg='<svg xmlns="http://www.w3.org/2000/svg" width="3001" height="1000" fill="none"><path fill="#000" d="M590.656 300.449c0 49.706-40.294 90-90 90-49.705 0-90-40.294-90-90 0-49.705 40.295-90 90-90 49.706 0 90 40.295 90 90M569.431 719.011c-15.247 32.821-56.006 91.589-98.338 91.438-32.004-.115-38.642-30.904-17.414-50.856 17.381-16.337 28.246-48.075 31.995-72.719.415-2.728-1.556-5.197-4.272-5.679-39.666-7.04-70.746-40.877-70.746-83.417 0-48.23 38.983-87.329 87.07-87.329 39.936 0 70.172 22.237 83.369 52.397 18.839 43.055 7.117 115.733-11.664 156.165M2613.29 385.681V239.319c0-11.363 9.22-20.569 20.59-20.569h8.26c11.37 0 20.59 9.206 20.59 20.569v36.911c0 8.629 7 15.625 15.63 15.625h35.25c8.63 0 15.63-6.996 15.63-15.625v-36.911c0-11.363 9.22-20.569 20.59-20.569h8.17c11.37 0 20.59 9.206 20.59 20.569v146.362c0 11.363-9.22 20.569-20.59 20.569h-8.17c-11.37 0-20.59-9.206-20.59-20.569v-36.999c0-8.63-7-15.625-15.63-15.625h-35.25c-8.63 0-15.63 6.995-15.63 15.625v36.999c0 11.363-9.22 20.569-20.59 20.569h-8.26c-11.37 0-20.59-9.206-20.59-20.569M2391.97 239.319v146.362c0 11.348-9.16 20.569-20.49 20.569h-8.2c-11.33 0-20.49-9.221-20.49-20.569V239.319c0-11.348 9.16-20.569 20.49-20.569h8.2c11.33 0 20.49 9.221 20.49 20.569M2098.23 391.43l-42.69-146.361c-3.85-13.171 6.06-26.319 19.79-26.319h10.6c9.59 0 17.93 6.611 20.08 15.952l17.01 73.045c1.48 6.348 10.47 6.478 12.14.176l19.47-73.838c2.38-9.04 10.57-15.335 19.93-15.335h12.1c9.37 0 17.56 6.3 19.94 15.346l19.49 74.067c1.66 6.305 10.65 6.178 12.13-.171l17.09-73.294c2.15-9.339 10.49-15.948 20.08-15.948h10.53c13.72 0 23.63 13.141 19.79 26.31l-42.63 146.361c-2.56 8.789-10.63 14.829-19.79 14.829h-15.68c-9.12 0-17.16-5.98-19.76-14.709l-21.17-71.059c-1.77-5.948-10.19-5.957-11.97-.012l-21.33 71.071c-2.6 8.729-10.64 14.709-19.76 14.709h-15.59c-9.17 0-17.23-6.035-19.8-14.82M2443.23 218.75h118.59c11.38 0 20.62 9.195 20.62 20.557s-9.24 20.556-20.62 20.556h-24.79c-5.53 0-10 4.477-10 10v115.818c0 11.368-9.25 20.569-20.63 20.569h-7.65c-11.39 0-20.63-9.201-20.63-20.569V269.863c0-5.523-4.48-10-10-10h-24.89c-11.37 0-20.61-9.195-20.61-20.556s9.24-20.557 20.61-20.557M1174.15 218.75h24.64c8.35 0 15.88 5.042 19.04 12.764l34.61 83.942c2.13 5.161 9.44 5.155 11.56-.01l34.43-83.932a20.58 20.58 0 0 1 19.04-12.764h24.64c11.37 0 20.58 9.208 20.58 20.569v146.362c0 11.361-9.21 20.569-20.58 20.569h-7.09c-11.36 0-20.58-9.208-20.58-20.569l-.12-50.645c-.01-6.888-9.53-8.688-12.06-2.283l-23.46 59.332a20.57 20.57 0 0 1-19.14 13.009h-3.03a20.57 20.57 0 0 1-19.15-13.046l-23.47-59.68c-2.52-6.416-12.05-4.623-12.06 2.271l-.13 51.042c0 11.361-9.21 20.569-20.57 20.569h-7.1c-11.36 0-20.57-9.208-20.57-20.569V239.319c0-11.361 9.21-20.569 20.57-20.569"/><path fill="#000" fill-rule="evenodd" d="m1449.94 391.836 6.12-19.392a6.255 6.255 0 0 1 5.96-4.369l50.22-.061a6.24 6.24 0 0 1 5.96 4.348l6.23 19.486c2.71 8.581 10.71 14.402 19.74 14.402h9.34c14.13 0 24.15-13.791 19.61-27.151l-49.74-146.361c-2.85-8.37-10.74-13.988-19.61-13.988h-33.16c-8.87 0-16.77 5.618-19.61 13.988l-49.74 146.361c-4.54 13.36 5.48 27.151 19.61 27.151h9.32c9.04 0 17.04-5.827 19.75-14.414m31.1-98.858c1.85-5.807 10.08-5.796 11.91.016l8.83 27.916c1.28 4.028-1.73 8.134-5.96 8.134h-17.74c-4.23 0-7.24-4.119-5.95-8.151zM1681.81 406.25c18.91 0 35.39-3.686 49.36-11.168 13.97-7.544 24.73-18.394 32.24-32.489 7.56-14.105 11.29-30.866 11.29-50.182 0-19.256-3.73-35.957-11.29-50.004-7.57-14.094-18.35-24.912-32.32-32.397-13.91-7.545-30.4-11.26-49.37-11.26h-49.5c-11.38 0-20.63 9.201-20.63 20.569v146.362c0 11.368 9.25 20.569 20.63 20.569zm23.13-47.701c-6.62 3.215-14.85 4.886-24.79 4.886-10.49 0-19-8.507-19-19v-64.34c0-10.149 8.23-18.376 18.38-18.376 10.18 0 18.56 1.703 25.23 4.974 6.59 3.149 11.63 8.315 15.08 15.633 3.45 7.269 5.28 17.268 5.28 30.162 0 12.891-1.82 22.951-5.28 30.347-3.39 7.319-8.36 12.509-14.9 15.714" clip-rule="evenodd"/><path fill="#000" d="M1804.21 385.681V239.319c0-11.361 9.21-20.569 20.58-20.569h91.28c11.36 0 20.57 9.202 20.57 20.557s-9.21 20.556-20.57 20.556h-54.64a7.807 7.807 0 0 0-7.81 7.813v16.366a7.806 7.806 0 0 0 7.81 7.812h48.13c11.37 0 20.58 9.246 20.58 20.602s-9.21 20.601-20.58 20.601h-48.13a7.806 7.806 0 0 0-7.81 7.812v16.455a7.807 7.807 0 0 0 7.81 7.813h54.64c11.36 0 20.57 9.202 20.57 20.556s-9.21 20.557-20.57 20.557h-91.28c-11.37 0-20.58-9.208-20.58-20.569"/><path fill="#000" fill-rule="evenodd" d="M2875.5 68.75h-2750c-31.066 0-56.25 25.184-56.25 56.25v750c0 31.066 25.184 56.25 56.25 56.25h2750c31.07 0 56.25-25.184 56.25-56.25V125c0-31.066-25.18-56.25-56.25-56.25M125.5 0C56.464 0 .5 55.964.5 125v750c0 69.036 55.965 125 125 125h2750c69.04 0 125-55.964 125-125V125c0-69.036-55.96-125-125-125z" clip-rule="evenodd"/><path fill="#000" d="M2476.06 804.813c-10.54 0-19.82-6.947-22.81-17.068L2390.79 575.7c-4.49-15.248 6.92-30.534 22.8-30.534h27.75c11.1 0 20.72 7.686 23.18 18.52L2489 671.402c2.07 9.093 14.93 9.321 17.32.308l28.83-108.844c2.76-10.435 12.19-17.7 22.98-17.7h25.17c10.8 0 20.25 7.293 22.99 17.755l28.27 107.739c2.36 9.001 15.18 8.829 17.3-.232l25.01-106.888c2.51-10.763 12.1-18.374 23.14-18.374h27.87c15.88 0 27.29 15.286 22.8 30.534l-62.46 212.045a23.78 23.78 0 0 1-22.81 17.068h-32.12c-10.39 0-19.58-6.763-22.69-16.696l-32.08-102.694c-2.62-8.397-14.51-8.331-17.04.095l-30.74 102.346c-3.02 10.061-12.27 16.949-22.76 16.949zM1742.44 804.813h-75.81c-13.09 0-23.71-10.656-23.71-23.801V568.967c0-13.145 10.62-23.801 23.71-23.801h74.8c26.6 0 49.59 5.198 68.95 15.594 19.45 10.312 34.44 25.187 44.96 44.627 10.61 19.355 15.91 42.556 15.91 69.602q0 40.57-15.78 69.73c-10.53 19.355-25.43 34.231-44.71 44.627-19.28 10.311-42.05 15.467-68.32 15.467m-29.3-83.642c0 13.145 10.61 23.801 23.71 23.801h3.06c12.8 0 23.7-2.07 32.71-6.212 9.09-4.141 16-11.283 20.71-21.426q7.2-15.213 7.2-42.345 0-27.13-7.32-42.344c-4.8-10.143-11.87-17.285-21.22-21.426-9.26-4.142-20.63-6.212-34.1-6.212h-1.04c-13.1 0-23.71 10.656-23.71 23.801zM1460.86 804.813c-13.12 0-23.76-10.656-23.76-23.801V568.967c0-13.145 10.64-23.801 23.76-23.801h22.84c13.13 0 23.76 10.656 23.76 23.801v155.247c0 13.145 10.64 23.801 23.76 23.801h57.27c13.12 0 23.76 10.656 23.76 23.801v9.196c0 13.145-10.64 23.801-23.76 23.801zM1204.45 601.964c-13.13 0-23.77-10.656-23.77-23.801v-9.196c0-13.145 10.64-23.801 23.77-23.801h177.89c13.13 0 23.78 10.656 23.78 23.801v9.196c0 13.145-10.65 23.801-23.78 23.801h-39.38c-8.21 0-14.86 6.66-14.86 14.875v164.173c0 13.145-10.64 23.801-23.78 23.801h-21.85c-13.13 0-23.78-10.656-23.78-23.801V616.839c0-8.215-6.65-14.875-14.86-14.875z"/><path fill="#000" fill-rule="evenodd" d="M2223.05 787.891c-3.02 10.047-12.27 16.922-22.74 16.922h-25.43c-16.19 0-27.64-15.862-22.57-31.261l69.88-212.045c3.21-9.753 12.31-16.341 22.56-16.341h61.84c10.25 0 19.35 6.588 22.56 16.341l69.87 212.045c5.08 15.399-6.37 31.261-22.56 31.261h-25.43c-10.48 0-19.72-6.875-22.74-16.922l-6.7-22.2a14.84 14.84 0 0 0-14.21-10.576h-63.42c-6.55 0-12.32 4.296-14.22 10.576zm76.13-96.945-14.13-48.436c-2.46-8.451-14.36-8.602-17.04-.217l-15.46 48.436c-1.84 5.759 2.45 11.645 8.48 11.645h29.6c5.94 0 10.22-5.715 8.55-11.428" clip-rule="evenodd"/><path fill="#000" d="M1939.6 804.813c-13.13 0-23.77-10.656-23.77-23.801V568.967c0-13.145 10.64-23.801 23.77-23.801h88.13c19.24 0 36.08 3.508 50.51 10.523s25.65 17.115 33.67 30.3q12.03 19.779 12.03 47.416c0 18.595-4.14 34.273-12.41 47.036-7.64 11.913-18.18 21.101-31.63 27.564-16.98 8.159-36 11.104-54.7 11.104h-43.07c-76.56 0 4.08-135.84 4.08-84.706v7.996c0 12.117 9.81 21.941 21.91 21.941 8.12 0 16.3-.345 24.04-3.043 5.91-2.113 10.43-5.451 13.55-10.015 3.2-4.565 4.81-10.523 4.81-17.877 0-7.437-1.61-13.481-4.81-18.129-3.12-4.733-7.64-8.199-13.55-10.396-7.05-2.766-14.67-3.423-22.18-3.423-13.13 0-23.77 10.656-23.77 23.801v47.71c0 11.825 11.14 16.003 19.91 20.752 12.31 6.671 7.58 25.389-6.42 25.389-7.45 0-13.49 6.048-13.49 13.508v48.395c0 13.145-10.63 23.801-23.76 23.801zm134.89-106.758 5.41 9.95 33.51 61.622c8.62 15.86-2.84 35.186-20.87 35.186h-22.27c-8.74 0-16.77-4.798-20.92-12.496l-35.05-65.04a15.52 15.52 0 0 0-13.66-8.168c-42.24 0 40.62-82.154 73.85-21.054M931.652 0h68.748v1000h-68.748z"/></svg>',eg='<svg xmlns="http://www.w3.org/2000/svg" width="400" height="1601" fill="none"><path fill="#000" d="M72 1319.8c0-10.73 7.071-20.18 17.372-23.22l215.823-63.62c15.519-4.57 31.078 7.05 31.078 23.22v28.26c0 11.31-7.824 21.1-18.85 23.61l-109.636 24.94c-9.254 2.1-9.487 15.2-.313 17.63l110.784 29.37a24.21 24.21 0 0 1 18.015 23.4v25.64c0 11-7.423 20.62-18.071 23.41l-109.659 28.79c-9.162 2.41-8.986 15.47.236 17.63l108.792 25.46c10.955 2.56 18.702 12.33 18.702 23.57v28.39c0 16.17-15.559 27.79-31.078 23.22l-215.823-63.62c-10.3-3.04-17.372-12.49-17.372-23.22v-32.72c0-10.59 6.883-19.95 16.994-23.11l104.523-32.67c8.547-2.67 8.479-14.79-.096-17.36l-104.17-31.3C79.01 1372.42 72 1363 72 1352.31zM72 572.638V495.43c0-13.336 10.846-24.147 24.225-24.147h215.823c13.379 0 24.225 10.811 24.225 24.147v76.179q0 40.645-15.872 70.228-15.743 29.712-45.422 45.79-29.55 16.206-70.843 16.206-41.292 0-70.971-16.078-29.55-16.077-45.422-45.532Q72 612.767 72 572.638m85.132-29.84c-13.379 0-24.225 10.81-24.225 24.146v3.122q0 19.55 6.323 33.313 6.323 13.89 21.807 21.094 15.485 7.332 43.099 7.331t43.1-7.46q15.484-7.33 21.807-21.608 6.323-14.15 6.323-34.728v-1.064c0-13.336-10.846-24.146-24.225-24.146zM72 285.858c0-13.363 10.846-24.197 24.225-24.197h215.823c13.379 0 24.225 10.834 24.225 24.197v23.27c0 13.364-10.846 24.197-24.225 24.197H154.035c-13.379 0-24.225 10.834-24.225 24.197v58.328c0 13.364-10.846 24.197-24.225 24.197h-9.36C82.845 440.047 72 429.214 72 415.85zM278.463 24.72c0-13.374 10.846-24.216 24.225-24.216h9.36c13.379 0 24.225 10.842 24.225 24.216v181.174c0 13.374-10.846 24.216-24.225 24.216h-9.36c-13.379 0-24.225-10.842-24.225-24.216v-40.108c0-8.359-6.779-15.135-15.141-15.135H96.225c-13.38 0-24.225-10.842-24.225-24.216v-22.256c0-13.374 10.846-24.216 24.225-24.216h167.097c8.362 0 15.141-6.776 15.141-15.135z"/><path fill="#000" fill-rule="evenodd" d="M89.224 1062.13C78.997 1059.04 72 1049.63 72 1038.96v-25.9c0-16.486 16.145-28.147 31.818-22.979l215.823 71.169a24.19 24.19 0 0 1 16.632 22.98v62.97c0 10.45-6.706 19.71-16.632 22.98l-215.823 71.17C88.145 1246.51 72 1234.86 72 1218.37v-25.9c0-10.67 6.997-20.08 17.224-23.17l22.595-6.81a15.13 15.13 0 0 0 10.765-14.48v-64.59a15.13 15.13 0 0 0-10.765-14.48zm98.672 77.53 49.299-14.39c8.601-2.51 8.755-14.62.22-17.35l-49.299-15.75c-5.861-1.88-11.852 2.49-11.852 8.64v30.14c0 6.05 5.817 10.41 11.632 8.71" clip-rule="evenodd"/><path fill="#000" d="M72 773.439c0-13.367 10.846-24.203 24.225-24.203h215.823c13.379 0 24.225 10.836 24.225 24.203v89.762q0 29.395-10.711 51.439-10.71 22.046-30.84 34.293t-48.261 12.248q-28.388 0-47.873-12.635-18.187-11.672-28.056-32.218c-8.303-17.289-11.301-36.661-11.301-55.705v-43.867c0-77.976 138.26 4.16 86.215 4.16h-8.138c-12.334 0-22.332 9.989-22.332 22.311 0 8.269.351 16.6 3.097 24.487q3.225 9.024 10.194 13.794 6.968 4.899 18.194 4.899 11.356 0 18.453-4.899 7.226-4.77 10.581-13.794c2.815-7.188 3.484-14.944 3.484-22.596 0-13.366-10.846-24.202-24.225-24.202h-48.56c-12.036 0-16.288 11.345-21.122 20.272-6.79 12.539-25.841 7.72-25.841-6.536 0-7.586-6.156-13.736-13.749-13.736H96.225C82.845 820.916 72 810.08 72 796.714zm108.66 137.378-10.128 5.511-62.72 34.131C91.67 959.243 72 947.569 72 929.205V906.52a24.2 24.2 0 0 1 12.719-21.299l66.199-35.696a15.82 15.82 0 0 0 8.313-13.921c0-43.012 83.618 41.371 21.429 75.213"/></svg>';function Jh(J){return S("watermarkState",()=>J.state.get(),[J])}var CJ0=`data:image/svg+xml;utf8,${encodeURIComponent(tg)}`,PJ0=`data:image/svg+xml;utf8,${encodeURIComponent(eg)}`,Qh=VZ.memo(function(){let Q=cg(),Z=y(),q=S("is mobile",()=>Z.getViewportScreenBounds().width<700,[Z]),X=Jh(Q);if(!["licensed-with-watermark","unlicensed"].includes(X))return null;return b9.jsxs(b9.Fragment,{children:[b9.jsx(bJ0,{}),b9.jsx(wJ0,{src:q?PJ0:CJ0,isUnlicensed:X==="unlicensed"})]})}),IJ0=VZ.memo(function({isDebugMode:Q,isMobile:Z}){let q=y(),X=oq(),K=VZ.useRef(null);r6(K);let Y="https://tldraw.dev/pricing?utm_source=sdk&utm_medium=organic&utm_campaign=watermark";return b9.jsx("div",{ref:K,className:UZ.className,"data-debug":Q,"data-mobile":Z,"data-unlicensed":!0,"data-testid":"tl-watermark-unlicensed",draggable:!1,...X,children:b9.jsx("button",{draggable:!1,role:"button",onPointerDown:(W)=>{q.markEventAsHandled(W),W0(W)},title:"The tldraw SDK requires a license key to work in production. You can get a free 100-day trial license at tldraw.dev/pricing.",onClick:()=>{Y3.openWindow(Y,"_blank",!0)},children:"Get a license for production"})})}),wJ0=VZ.memo(function({src:Q,isUnlicensed:Z}){let q=y(),X=S("debug mode",()=>q.getInstanceState().isDebugMode,[q]),K=S("is mobile",()=>q.getViewportScreenBounds().width<700,[q]),Y=oq(),W=VZ.useRef(null);r6(W);let z=`url('${Q}') center 100% / 100% no-repeat`,G="https://tldraw.dev/?utm_source=sdk&utm_medium=organic&utm_campaign=watermark";if(Z)return b9.jsx(IJ0,{isDebugMode:X,isMobile:K});return b9.jsx("div",{ref:W,className:UZ.className,"data-debug":X,"data-mobile":K,"data-testid":"tl-watermark-licensed",draggable:!1,...Y,children:b9.jsx("button",{draggable:!1,role:"button",onPointerDown:(H)=>{q.markEventAsHandled(H),W0(H)},title:"Build infinite canvas applications with the tldraw SDK. Learn more at https://tldraw.dev.",onClick:()=>{Y3.openWindow(G,"_blank")},style:{mask:z,WebkitMask:z}})})}),bJ0=VZ.memo(function(){let Q=y(),Z=UZ.className,q=`
|
|
95
|
+
*/function HU(J){let Q=new ArrayBuffer(J.length),Z=new Uint8Array(Q);for(let q=0,X=J.length;q<X;q++)Z[q]=J.charCodeAt(q);return Q}function hg(J){let Q=atob(J),Z=HU(Q);return crypto.subtle.importKey("spki",new Uint8Array(Z),{name:"ECDSA",namedCurve:"P-256"},!0,["verify"])}var DJ0=30,R2={ANNUAL_LICENSE:1,PERPETUAL_LICENSE:2,INTERNAL_LICENSE:4,WITH_WATERMARK:8,EVALUATION_LICENSE:16,NATIVE_LICENSE:32},MJ0=Math.max(...Object.values(R2)),yG={ID:0,HOSTS:1,FLAGS:2,EXPIRY_DATE:3},jJ0=Object.keys(yG).length,dK="sales@tldraw.com",RJ0=`${Q6()}/watermarks/watermark-track.svg`;class UZ{publicKey="MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEHJh0uUfxHtCGyerXmmatE368Hd9rI6LH9oPDQihnaCryRFWEVeOvf9U/SPbyxX74LFyJs5tYeAHq5Nc0Ax25LQ";isDevelopment;isTest;isCryptoAvailable;state=V0("license state","pending");verbose=!0;constructor(J,Q){this.isTest=!1,this.isDevelopment=this.getIsDevelopment(),this.publicKey=Q||this.publicKey,this.isCryptoAvailable=!!crypto.subtle,this.getLicenseFromKey(J).then((Z)=>{let q=kJ0(Z,(X)=>this.outputMessages(X),this.isDevelopment);this.maybeTrack(Z,q),this.state.set(q)}).catch((Z)=>{console.error("License validation failed:",Z),this.state.set("unlicensed")})}getIsDevelopment(){return!["https:","vscode-webview:"].includes(window.location.protocol)||this.isLoopbackHost(window.location.hostname)||!1}isLoopbackHost(J){let Q=J.toLowerCase().replace(/^\[|\]$/g,"");return Q==="localhost"||Q==="::1"||/^127(?:\.\d{1,3}){3}$/.test(Q)}getTrackType(J,Q){if(Q==="unlicensed-production")return"unlicensed";if(this.isDevelopment)return null;if(!J.isLicenseParseable)return null;if(J.isEvaluationLicense)return"evaluation";if(Q==="licensed-with-watermark")return"with_watermark";return null}maybeTrack(J,Q){let Z=this.getTrackType(J,Q);if(!Z)return;let q=new URL(RJ0);if(q.searchParams.set("version",gK),q.searchParams.set("license_type",Z),"license"in J){q.searchParams.set("license_id",J.license.id);let X=this.isFlagEnabled(J.license.flags,R2.EVALUATION_LICENSE)?"evaluation":this.isFlagEnabled(J.license.flags,R2.ANNUAL_LICENSE)?"annual":this.isFlagEnabled(J.license.flags,R2.PERPETUAL_LICENSE)?"perpetual":"unknown";q.searchParams.set("sku",X)}q.searchParams.set("url",window.location.href),q.searchParams.set("environment","production"),fetch(q.toString())}async extractLicenseKey(J){let[Q,Z]=J.split("."),[q,X]=Q.split("/");if(!q.startsWith("tldraw-"))throw Error(`Unsupported prefix '${q}'`);let K=await hg(this.publicKey),Y;try{Y=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},K,new Uint8Array(HU(atob(Z))),new Uint8Array(HU(atob(X))))}catch(z){throw console.error(z),Error("Could not perform signature validation")}if(!Y)throw Error("Invalid signature");let W;try{W=JSON.parse(atob(X))}catch{throw Error("Could not parse object")}if(W.length>jJ0)this.outputMessages(["License key contains some unknown properties.","You may want to update tldraw packages to a newer version to get access to new functionality."]);return{id:W[yG.ID],hosts:W[yG.HOSTS],flags:W[yG.FLAGS],expiryDate:W[yG.EXPIRY_DATE]}}async getLicenseFromKey(J){if(!J){if(!this.isDevelopment)this.outputNoLicenseKeyProvided();return{isLicenseParseable:!1,reason:"no-key-provided"}}if(this.isDevelopment&&!this.isCryptoAvailable){if(this.verbose)console.log("tldraw: you seem to be in a development environment that does not support crypto. License not verified."),console.log("You should check that this works in production separately.");return{isLicenseParseable:!1,reason:"has-key-development-mode"}}let Q=J.replace(/[\u200B-\u200D\uFEFF]/g,"");Q=Q.replace(/\r?\n|\r/g,"");try{let Z=await this.extractLicenseKey(Q),q=new Date(Z.expiryDate),X=this.isFlagEnabled(Z.flags,R2.ANNUAL_LICENSE),K=this.isFlagEnabled(Z.flags,R2.PERPETUAL_LICENSE),Y=this.isFlagEnabled(Z.flags,R2.EVALUATION_LICENSE),W=X&&this.isAnnualLicenseExpired(q),z=K&&this.isPerpetualLicenseExpired(q),G=K&&!z?0:this.getDaysSinceExpiry(q),H={license:Z,isLicenseParseable:!0,isDevelopment:this.isDevelopment,isDomainValid:this.isDomainValid(Z),expiryDate:q,isAnnualLicense:X,isAnnualLicenseExpired:W,isPerpetualLicense:K,isPerpetualLicenseExpired:z,isInternalLicense:this.isFlagEnabled(Z.flags,R2.INTERNAL_LICENSE),isNativeLicense:this.isNativeLicense(Z),isLicensedWithWatermark:this.isFlagEnabled(Z.flags,R2.WITH_WATERMARK),isEvaluationLicense:Y,isEvaluationLicenseExpired:Y&&this.isEvaluationLicenseExpired(q),daysSinceExpiry:G};return this.outputLicenseInfoIfNeeded(H),H}catch(Z){return this.outputInvalidLicenseKey(Z.message),{isLicenseParseable:!1,reason:"invalid-license-key"}}}isDomainValid(J){let Q=window.location.hostname.toLowerCase();return J.hosts.some((Z)=>{let q=Z.toLowerCase().trim();if(q===Q||`www.${q}`===Q||q===`www.${Q}`)return!0;if(Z==="*")return!0;if(this.isNativeLicense(J))return new RegExp(q).test(window.location.href);if(Z.includes("*")){let X=new RegExp(Z.replace(/\*/g,".*?"));return X.test(Q)||X.test(`www.${Q}`)}if(window.location.protocol==="vscode-webview:"){let K=new URL(window.location.href).searchParams.get("extensionId");if(q===K)return!0}return!1})}isNativeLicense(J){return this.isFlagEnabled(J.flags,R2.NATIVE_LICENSE)}getExpirationDateWithoutGracePeriod(J){return new Date(J.getFullYear(),J.getMonth(),J.getDate())}getExpirationDateWithGracePeriod(J){return new Date(J.getFullYear(),J.getMonth(),J.getDate()+DJ0+1)}isAnnualLicenseExpired(J){let Q=this.getExpirationDateWithGracePeriod(J);return new Date>=Q}isPerpetualLicenseExpired(J){let Q=this.getExpirationDateWithGracePeriod(J),Z={major:new Date(vj.major),minor:new Date(vj.minor)};return Z.major>=Q||Z.minor>=Q}getDaysSinceExpiry(J){let Q=new Date,Z=this.getExpirationDateWithoutGracePeriod(J),q=Q.getTime()-Z.getTime(),X=Math.floor(q/86400000);return Math.max(0,X)}isEvaluationLicenseExpired(J){let Q=new Date,Z=this.getExpirationDateWithoutGracePeriod(J);return Q>=Z}isFlagEnabled(J,Q){return(J&Q)===Q}outputNoLicenseKeyProvided(){}outputInvalidLicenseKey(J){this.outputMessages(["Invalid tldraw license key",`Reason: ${J}`])}outputLicenseInfoIfNeeded(J){if(J.license.flags>=MJ0*2)this.outputMessages(["Warning: This tldraw license contains some unknown flags.","This will still work, however, you may want to update tldraw packages to a newer version to get access to new functionality."],"warning")}outputMessages(J,Q="error"){if(this.isTest)return;if(this.verbose){this.outputDelimiter(Q);for(let Z of J){let q=Q==="warning"?"orange":"crimson";console.log(`%c${Z}`,`color: white; background: ${q}; padding: 2px; border-radius: 3px;`)}this.outputDelimiter(Q)}}outputDelimiter(J="error"){console.log("%c-------------------------------------------------------------------",`color: white; background: ${J==="warning"?"orange":"crimson"}; padding: 2px; border-radius: 3px;`)}static className="tl-watermark_SEE-LICENSE"}function kJ0(J,Q,Z){if(!J.isLicenseParseable){if(Z)return"unlicensed";if(J.reason==="no-key-provided")Q(["No tldraw license key provided!","A license is required for production deployments.",`Please reach out to ${dK} to purchase a license.`]);else Q(["Invalid license key. tldraw requires a valid license for production use.",`Please reach out to ${dK} to purchase a license.`]);return"unlicensed-production"}if(!J.isDomainValid&&!J.isDevelopment)return Q(["License key is not valid for this domain.","A license is required for production deployments.",`Please reach out to ${dK} to purchase a license.`]),"unlicensed-production";if(J.isEvaluationLicense)if(J.isEvaluationLicenseExpired)return Q(["Your tldraw evaluation license has expired!",`Please reach out to ${dK} to purchase a full license.`]),"expired";else return"licensed";if(J.isPerpetualLicenseExpired||J.isAnnualLicenseExpired)return Q(["Your tldraw license has been expired for more than 30 days!",`Please reach out to ${dK} to renew your license.`]),"expired";let q=J.daysSinceExpiry;if(q>0&&!J.isEvaluationLicense)return Q(["Your tldraw license has expired.",`License expired ${q} days ago.`,`Please reach out to ${dK} to renew your license.`]),"licensed";if(J.isLicensedWithWatermark)return"licensed-with-watermark";return"licensed"}var FU=E(c(),1);var wJ=E(m(),1);var mg=wJ.createContext({});function cg(){return wJ.useContext(mg)}function ug(J){return J==="expired"||J==="unlicensed-production"}var lg=5000;function pg({licenseKey:J=AJ0()??void 0,children:Q}){let[Z]=wJ.useState(()=>new UZ(J)),q=S(Z.state),[X,K]=wJ.useState(!0);if(wJ.useEffect(()=>{if(ug(q)&&X){let Y=setTimeout(()=>{K(!1)},lg);return()=>clearTimeout(Y)}},[q,X]),ug(q)&&!X)return FU.jsx(EJ0,{});return FU.jsx(mg.Provider,{value:Z,children:Q})}function EJ0(){return FU.jsx("div",{"data-testid":"tl-license-expired",style:{display:"none"}})}var _U=void 0;function AJ0(){if(_U!==void 0)return _U;return _U=t9(()=>process.env.TLDRAW_LICENSE_KEY)||t9(()=>process.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY)||t9(()=>process.env.REACT_APP_TLDRAW_LICENSE_KEY)||t9(()=>process.env.GATSBY_TLDRAW_LICENSE_KEY)||t9(()=>process.env.VITE_TLDRAW_LICENSE_KEY)||t9(()=>"tldraw-2026-09-27/WyJlaDdIczMxRSIsWyIqIl0sMTYsIjIwMjYtMDktMjciXQ.6OucDghQHnAFl2Ceg8qf48M2oIis6qHdZfqFsKdBZwd610QixrvG1jUnwCbI1Xs2BoXzptPs+pQYF25NyShFbw")||t9(()=>import.meta.env.TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.NEXT_PUBLIC_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.REACT_APP_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.GATSBY_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.VITE_TLDRAW_LICENSE_KEY)||t9(()=>import.meta.env.PUBLIC_TLDRAW_LICENSE_KEY)||null,_U}function t9(J){try{return J()}catch{return}}function bJ(J,Q=20){return Math.max(8,Math.ceil(J/Q))}class O3 extends n6{_center;_radius;_start;_end;_largeArcFlag;_sweepFlag;_measure;_angleStart;_angleEnd;constructor(J){super({...J,isFilled:!1,isClosed:!1});let{center:Q,sweepFlag:Z,largeArcFlag:q,start:X,end:K}=J;if(X.equals(K))throw Error("Arc must have different start and end points.");this._angleStart=D.Angle(Q,X),this._angleEnd=D.Angle(Q,K),this._radius=D.Dist(Q,X),this._measure=vM(this._angleStart,this._angleEnd,Z,q),this._start=X,this._end=K,this._sweepFlag=Z,this._largeArcFlag=q,this._center=Q}nearestPoint(J){let{_center:Q,_measure:Z,_radius:q,_angleEnd:X,_angleStart:K,_start:Y,_end:W}=this,z=AF(Z,K,X,Q.angle(J));if(z<=0)return Y;if(z>=1)return W;let G=J.x-Q.x,H=J.y-Q.y,$=Math.sqrt(G*G+H*H);if($===0)return Y;let _=q/$;return new D(Q.x+G*_,Q.y+H*_)}hitTestLineSegment(J,Q){let{_center:Z,_radius:q,_measure:X,_angleStart:K,_angleEnd:Y}=this,W=kJ(J,Q,Z,q);if(W===null)return!1;return W.some((z)=>{let G=AF(X,K,Y,Z.angle(z));return G>=0&&G<=1})}getVertices(){let{_center:J,_measure:Q,length:Z,_radius:q,_angleStart:X}=this,K=[];for(let Y=0,W=bJ(Math.abs(Z));Y<W+1;Y++){let z=Y/W*Q,G=X+z;K.push(J3(J,q,G))}return K}getSvgPathData(J=!0){let{_start:Q,_end:Z,_radius:q,_largeArcFlag:X,_sweepFlag:K}=this;return`${J?`M${Q.toFixed()}`:""} A${q} ${q} 0 ${X} ${K} ${Z.toFixed()}`}getLength(){return Math.abs(this._measure*this._radius)}}class p7 extends n6{constructor(J){super({isClosed:!0,...J});this.config=J;let{x:Q=0,y:Z=0,radius:q}=J;this._x=Q,this._y=Z,this._center=new D(q+Q,q+Z),this._radius=q}config;_center;_radius;_x;_y;getBounds(){return new p(this._x,this._y,this._radius*2,this._radius*2)}getVertices(){let{_center:J,_radius:Q}=this,Z=N1*Q,q=[];for(let X=0,K=bJ(Z);X<K;X++){let Y=X/K*N1;q.push(J3(J,Q,Y))}return q}nearestPoint(J){let{_center:Q,_radius:Z}=this,q=J.x-Q.x,X=J.y-Q.y,K=Math.sqrt(q*q+X*X);if(K===0)return new D(Q.x+Z,Q.y);let Y=Z/K;return new D(Q.x+q*Y,Q.y+X*Y)}distanceToPoint(J,Q=!1){let{_center:Z,_radius:q}=this,X=J.x-Z.x,K=J.y-Z.y,W=Math.sqrt(X*X+K*K)-q;if(W<0&&(this.isFilled||Q))return W;return Math.abs(W)}hitTestPoint(J,Q=0,Z=!1){let{_center:q,_radius:X}=this,K=J.x-q.x,Y=J.y-q.y,W=K*K+Y*Y;if((this.isFilled||Z)&&W<=X*X)return!0;let z=X+Q;if(W>z*z)return!1;let G=X-Q;if(G<=0)return!0;return W>=G*G}hitTestLineSegment(J,Q,Z=0){let{_center:q,_radius:X}=this;return kJ(J,Q,q,X+Z)!==null}getSvgPathData(){let{_center:J,_radius:Q}=this;return`M${J.x+Q},${J.y} a${Q},${Q} 0 1,0 ${Q*2},0a${Q},${Q} 0 1,0 -${Q*2},0`}}class iK extends o9{_a;_b;_c;_d;_resolution;constructor(J){let{start:Q,cp1:Z,cp2:q,end:X}=J;super({...J,points:[Q,X]});this._a=Q,this._b=Z,this._c=q,this._d=X,this._resolution=J.resolution??10}getVertices(){let J=[],{_a:Q,_b:Z,_c:q,_d:X}=this;for(let K=0,Y=this._resolution;K<=Y;K++){let W=K/Y;J.push(new D((1-W)*(1-W)*(1-W)*Q.x+3*((1-W)*(1-W))*W*Z.x+3*(1-W)*(W*W)*q.x+W*W*W*X.x,(1-W)*(1-W)*(1-W)*Q.y+3*((1-W)*(1-W))*W*Z.y+3*(1-W)*(W*W)*q.y+W*W*W*X.y))}return J}nearestPoint(J){let Q,Z=1/0,q,X;for(let K of this.segments)if(X=K.nearestPoint(J),q=D.Dist2(X,J),q<Z)Q=X,Z=q;if(!Q)throw Error("nearest point not found");return Q}distanceToPoint(J,Q=!1){let{segments:Z}=this,q=1/0;for(let X=0;X<Z.length;X++){let K=Z[X].distanceToPoint(J);if(K<q)q=K}return q}getSvgPathData(J=!0){let{_a:Q,_b:Z,_c:q,_d:X}=this;return`${J?`M ${Q.toFixed()} `:""} C${Z.toFixed()} ${q.toFixed()} ${X.toFixed()}`}static GetAtT(J,Q){let{_a:Z,_b:q,_c:X,_d:K}=J;return new D((1-Q)*(1-Q)*(1-Q)*Z.x+3*((1-Q)*(1-Q))*Q*q.x+3*(1-Q)*(Q*Q)*X.x+Q*Q*Q*K.x,(1-Q)*(1-Q)*(1-Q)*Z.y+3*((1-Q)*(1-Q))*Q*q.y+3*(1-Q)*(Q*Q)*X.y+Q*Q*Q*K.y)}getLength(J,Q=32){let Z,q=this._a,X=0;for(let K=1;K<=Q;K++)Z=iK.GetAtT(this,K/Q),X+=D.Dist(q,Z),q=Z;return X}}class nK extends n6{constructor(J){super({...J,isClosed:!0});this.config=J;let{width:Q,height:Z}=J;this._w=Q,this._h=Z}config;_w;_h;_edges;get edges(){if(!this._edges){let{vertices:J}=this;this._edges=[];for(let Q=0,Z=J.length;Q<Z;Q++){let q=J[Q],X=J[(Q+1)%Z];this._edges.push(new l8({start:q,end:X}))}}return this._edges}getVertices(){let J=Math.max(1,this._w),Q=Math.max(1,this._h),Z=J/2,q=Q/2,X=Math.pow(Z-q,2)/Math.pow(Z+q,2),K=B1*(Z+q)*(1+3*X/(10+Math.sqrt(4-3*X))),Y=bJ(K),W=N1/Y,z=Math.cos(W),G=Math.sin(W),H=0,$=1,_=0,F=1,U=Array(Y);for(let V=0;V<Y;V++)U[V]=new D(M0(Z+Z*$,0,J),M0(q+q*H,0,Q)),_=G*$+z*H,F=z*$-G*H,H=_,$=F;return U}nearestPoint(J){let Q,Z=1/0,q,X;for(let K of this.edges)if(X=K.nearestPoint(J),q=D.Dist2(X,J),q<Z)Q=X,Z=q;if(!Q)throw Error("nearest point not found");return Q}distanceToPoint(J,Q=!1){let{edges:Z}=this,q=1/0;for(let X=0;X<Z.length;X++){let K=Z[X].distanceToPoint(J);if(K<q)q=K}if(this.isClosed&&(this.isFilled||Q)&&n1(J,this.vertices))return-q;return q}hitTestLineSegment(J,Q){return this.edges.some((Z)=>Z.hitTestLineSegment(J,Q))}getBounds(){return new p(0,0,this._w,this._h)}getLength(){let{_w:J,_h:Q}=this,Z=J/2,q=Q/2,X=Math.max(0,Z),K=Math.max(0,q);return bM(X,K)}getSvgPathData(J=!1){let{_w:Q,_h:Z}=this,q=Q/2,X=Z/2,K=Math.max(0,q),Y=Math.max(0,X);return`${J?`M${q-K},${X}`:""} a${K},${Y},0,1,1,${K*2},0a${K},${Y},0,1,1,-${K*2},0`}}var i4=E(c(),1);var Zh=E(c1(),1),Y4=E(m(),1);var dg=E(m(),1);function ig(){let J=y(),Q=Q1(),Z=z6(),q=S(V1.forceSrgb);dg.default.useEffect(()=>{if(Z==="dark")Q.setAttribute("data-color-mode","dark"),Q.classList.remove("tl-theme__light"),Q.classList.add("tl-theme__dark");else Q.setAttribute("data-color-mode","light"),Q.classList.remove("tl-theme__dark"),Q.classList.add("tl-theme__light");if(q)Q.classList.add("tl-theme__force-sRGB");else Q.classList.remove("tl-theme__force-sRGB")},[J,Q,q,Z])}var UU=E(m(),1);function ng(){let[J,Q]=UU.useState(0);UU.useEffect(()=>Q((Z)=>Z+1),[])}var sg=E(m(),1);function rg(){let J=y();sg.useLayoutEffect(()=>{return g1("stateAttribute",()=>{let Q=J.getContainer(),Z=J.getInstanceState();Q.setAttribute("data-state",J.getPath()),Q.setAttribute("data-coarse",String(Z.isCoarsePointer))})},[J])}var ag=E(m(),1);function og(){let J=y(),Q=Q1();ag.useEffect(()=>{let Z=(K)=>Q.style.setProperty("--tl-zoom",K.toString()),q=$J(Z,100),X=new U9("useZoomCss",()=>Z(J.getEfficientZoomLevel()));return X.attach(),X.execute(),()=>{X.detach(),q.cancel()}},[J,Q])}var b9=E(c(),1);var VZ=E(m(),1);var tg='<svg xmlns="http://www.w3.org/2000/svg" width="3001" height="1000" fill="none"><path fill="#000" d="M590.656 300.449c0 49.706-40.294 90-90 90-49.705 0-90-40.294-90-90 0-49.705 40.295-90 90-90 49.706 0 90 40.295 90 90M569.431 719.011c-15.247 32.821-56.006 91.589-98.338 91.438-32.004-.115-38.642-30.904-17.414-50.856 17.381-16.337 28.246-48.075 31.995-72.719.415-2.728-1.556-5.197-4.272-5.679-39.666-7.04-70.746-40.877-70.746-83.417 0-48.23 38.983-87.329 87.07-87.329 39.936 0 70.172 22.237 83.369 52.397 18.839 43.055 7.117 115.733-11.664 156.165M2613.29 385.681V239.319c0-11.363 9.22-20.569 20.59-20.569h8.26c11.37 0 20.59 9.206 20.59 20.569v36.911c0 8.629 7 15.625 15.63 15.625h35.25c8.63 0 15.63-6.996 15.63-15.625v-36.911c0-11.363 9.22-20.569 20.59-20.569h8.17c11.37 0 20.59 9.206 20.59 20.569v146.362c0 11.363-9.22 20.569-20.59 20.569h-8.17c-11.37 0-20.59-9.206-20.59-20.569v-36.999c0-8.63-7-15.625-15.63-15.625h-35.25c-8.63 0-15.63 6.995-15.63 15.625v36.999c0 11.363-9.22 20.569-20.59 20.569h-8.26c-11.37 0-20.59-9.206-20.59-20.569M2391.97 239.319v146.362c0 11.348-9.16 20.569-20.49 20.569h-8.2c-11.33 0-20.49-9.221-20.49-20.569V239.319c0-11.348 9.16-20.569 20.49-20.569h8.2c11.33 0 20.49 9.221 20.49 20.569M2098.23 391.43l-42.69-146.361c-3.85-13.171 6.06-26.319 19.79-26.319h10.6c9.59 0 17.93 6.611 20.08 15.952l17.01 73.045c1.48 6.348 10.47 6.478 12.14.176l19.47-73.838c2.38-9.04 10.57-15.335 19.93-15.335h12.1c9.37 0 17.56 6.3 19.94 15.346l19.49 74.067c1.66 6.305 10.65 6.178 12.13-.171l17.09-73.294c2.15-9.339 10.49-15.948 20.08-15.948h10.53c13.72 0 23.63 13.141 19.79 26.31l-42.63 146.361c-2.56 8.789-10.63 14.829-19.79 14.829h-15.68c-9.12 0-17.16-5.98-19.76-14.709l-21.17-71.059c-1.77-5.948-10.19-5.957-11.97-.012l-21.33 71.071c-2.6 8.729-10.64 14.709-19.76 14.709h-15.59c-9.17 0-17.23-6.035-19.8-14.82M2443.23 218.75h118.59c11.38 0 20.62 9.195 20.62 20.557s-9.24 20.556-20.62 20.556h-24.79c-5.53 0-10 4.477-10 10v115.818c0 11.368-9.25 20.569-20.63 20.569h-7.65c-11.39 0-20.63-9.201-20.63-20.569V269.863c0-5.523-4.48-10-10-10h-24.89c-11.37 0-20.61-9.195-20.61-20.556s9.24-20.557 20.61-20.557M1174.15 218.75h24.64c8.35 0 15.88 5.042 19.04 12.764l34.61 83.942c2.13 5.161 9.44 5.155 11.56-.01l34.43-83.932a20.58 20.58 0 0 1 19.04-12.764h24.64c11.37 0 20.58 9.208 20.58 20.569v146.362c0 11.361-9.21 20.569-20.58 20.569h-7.09c-11.36 0-20.58-9.208-20.58-20.569l-.12-50.645c-.01-6.888-9.53-8.688-12.06-2.283l-23.46 59.332a20.57 20.57 0 0 1-19.14 13.009h-3.03a20.57 20.57 0 0 1-19.15-13.046l-23.47-59.68c-2.52-6.416-12.05-4.623-12.06 2.271l-.13 51.042c0 11.361-9.21 20.569-20.57 20.569h-7.1c-11.36 0-20.57-9.208-20.57-20.569V239.319c0-11.361 9.21-20.569 20.57-20.569"/><path fill="#000" fill-rule="evenodd" d="m1449.94 391.836 6.12-19.392a6.255 6.255 0 0 1 5.96-4.369l50.22-.061a6.24 6.24 0 0 1 5.96 4.348l6.23 19.486c2.71 8.581 10.71 14.402 19.74 14.402h9.34c14.13 0 24.15-13.791 19.61-27.151l-49.74-146.361c-2.85-8.37-10.74-13.988-19.61-13.988h-33.16c-8.87 0-16.77 5.618-19.61 13.988l-49.74 146.361c-4.54 13.36 5.48 27.151 19.61 27.151h9.32c9.04 0 17.04-5.827 19.75-14.414m31.1-98.858c1.85-5.807 10.08-5.796 11.91.016l8.83 27.916c1.28 4.028-1.73 8.134-5.96 8.134h-17.74c-4.23 0-7.24-4.119-5.95-8.151zM1681.81 406.25c18.91 0 35.39-3.686 49.36-11.168 13.97-7.544 24.73-18.394 32.24-32.489 7.56-14.105 11.29-30.866 11.29-50.182 0-19.256-3.73-35.957-11.29-50.004-7.57-14.094-18.35-24.912-32.32-32.397-13.91-7.545-30.4-11.26-49.37-11.26h-49.5c-11.38 0-20.63 9.201-20.63 20.569v146.362c0 11.368 9.25 20.569 20.63 20.569zm23.13-47.701c-6.62 3.215-14.85 4.886-24.79 4.886-10.49 0-19-8.507-19-19v-64.34c0-10.149 8.23-18.376 18.38-18.376 10.18 0 18.56 1.703 25.23 4.974 6.59 3.149 11.63 8.315 15.08 15.633 3.45 7.269 5.28 17.268 5.28 30.162 0 12.891-1.82 22.951-5.28 30.347-3.39 7.319-8.36 12.509-14.9 15.714" clip-rule="evenodd"/><path fill="#000" d="M1804.21 385.681V239.319c0-11.361 9.21-20.569 20.58-20.569h91.28c11.36 0 20.57 9.202 20.57 20.557s-9.21 20.556-20.57 20.556h-54.64a7.807 7.807 0 0 0-7.81 7.813v16.366a7.806 7.806 0 0 0 7.81 7.812h48.13c11.37 0 20.58 9.246 20.58 20.602s-9.21 20.601-20.58 20.601h-48.13a7.806 7.806 0 0 0-7.81 7.812v16.455a7.807 7.807 0 0 0 7.81 7.813h54.64c11.36 0 20.57 9.202 20.57 20.556s-9.21 20.557-20.57 20.557h-91.28c-11.37 0-20.58-9.208-20.58-20.569"/><path fill="#000" fill-rule="evenodd" d="M2875.5 68.75h-2750c-31.066 0-56.25 25.184-56.25 56.25v750c0 31.066 25.184 56.25 56.25 56.25h2750c31.07 0 56.25-25.184 56.25-56.25V125c0-31.066-25.18-56.25-56.25-56.25M125.5 0C56.464 0 .5 55.964.5 125v750c0 69.036 55.965 125 125 125h2750c69.04 0 125-55.964 125-125V125c0-69.036-55.96-125-125-125z" clip-rule="evenodd"/><path fill="#000" d="M2476.06 804.813c-10.54 0-19.82-6.947-22.81-17.068L2390.79 575.7c-4.49-15.248 6.92-30.534 22.8-30.534h27.75c11.1 0 20.72 7.686 23.18 18.52L2489 671.402c2.07 9.093 14.93 9.321 17.32.308l28.83-108.844c2.76-10.435 12.19-17.7 22.98-17.7h25.17c10.8 0 20.25 7.293 22.99 17.755l28.27 107.739c2.36 9.001 15.18 8.829 17.3-.232l25.01-106.888c2.51-10.763 12.1-18.374 23.14-18.374h27.87c15.88 0 27.29 15.286 22.8 30.534l-62.46 212.045a23.78 23.78 0 0 1-22.81 17.068h-32.12c-10.39 0-19.58-6.763-22.69-16.696l-32.08-102.694c-2.62-8.397-14.51-8.331-17.04.095l-30.74 102.346c-3.02 10.061-12.27 16.949-22.76 16.949zM1742.44 804.813h-75.81c-13.09 0-23.71-10.656-23.71-23.801V568.967c0-13.145 10.62-23.801 23.71-23.801h74.8c26.6 0 49.59 5.198 68.95 15.594 19.45 10.312 34.44 25.187 44.96 44.627 10.61 19.355 15.91 42.556 15.91 69.602q0 40.57-15.78 69.73c-10.53 19.355-25.43 34.231-44.71 44.627-19.28 10.311-42.05 15.467-68.32 15.467m-29.3-83.642c0 13.145 10.61 23.801 23.71 23.801h3.06c12.8 0 23.7-2.07 32.71-6.212 9.09-4.141 16-11.283 20.71-21.426q7.2-15.213 7.2-42.345 0-27.13-7.32-42.344c-4.8-10.143-11.87-17.285-21.22-21.426-9.26-4.142-20.63-6.212-34.1-6.212h-1.04c-13.1 0-23.71 10.656-23.71 23.801zM1460.86 804.813c-13.12 0-23.76-10.656-23.76-23.801V568.967c0-13.145 10.64-23.801 23.76-23.801h22.84c13.13 0 23.76 10.656 23.76 23.801v155.247c0 13.145 10.64 23.801 23.76 23.801h57.27c13.12 0 23.76 10.656 23.76 23.801v9.196c0 13.145-10.64 23.801-23.76 23.801zM1204.45 601.964c-13.13 0-23.77-10.656-23.77-23.801v-9.196c0-13.145 10.64-23.801 23.77-23.801h177.89c13.13 0 23.78 10.656 23.78 23.801v9.196c0 13.145-10.65 23.801-23.78 23.801h-39.38c-8.21 0-14.86 6.66-14.86 14.875v164.173c0 13.145-10.64 23.801-23.78 23.801h-21.85c-13.13 0-23.78-10.656-23.78-23.801V616.839c0-8.215-6.65-14.875-14.86-14.875z"/><path fill="#000" fill-rule="evenodd" d="M2223.05 787.891c-3.02 10.047-12.27 16.922-22.74 16.922h-25.43c-16.19 0-27.64-15.862-22.57-31.261l69.88-212.045c3.21-9.753 12.31-16.341 22.56-16.341h61.84c10.25 0 19.35 6.588 22.56 16.341l69.87 212.045c5.08 15.399-6.37 31.261-22.56 31.261h-25.43c-10.48 0-19.72-6.875-22.74-16.922l-6.7-22.2a14.84 14.84 0 0 0-14.21-10.576h-63.42c-6.55 0-12.32 4.296-14.22 10.576zm76.13-96.945-14.13-48.436c-2.46-8.451-14.36-8.602-17.04-.217l-15.46 48.436c-1.84 5.759 2.45 11.645 8.48 11.645h29.6c5.94 0 10.22-5.715 8.55-11.428" clip-rule="evenodd"/><path fill="#000" d="M1939.6 804.813c-13.13 0-23.77-10.656-23.77-23.801V568.967c0-13.145 10.64-23.801 23.77-23.801h88.13c19.24 0 36.08 3.508 50.51 10.523s25.65 17.115 33.67 30.3q12.03 19.779 12.03 47.416c0 18.595-4.14 34.273-12.41 47.036-7.64 11.913-18.18 21.101-31.63 27.564-16.98 8.159-36 11.104-54.7 11.104h-43.07c-76.56 0 4.08-135.84 4.08-84.706v7.996c0 12.117 9.81 21.941 21.91 21.941 8.12 0 16.3-.345 24.04-3.043 5.91-2.113 10.43-5.451 13.55-10.015 3.2-4.565 4.81-10.523 4.81-17.877 0-7.437-1.61-13.481-4.81-18.129-3.12-4.733-7.64-8.199-13.55-10.396-7.05-2.766-14.67-3.423-22.18-3.423-13.13 0-23.77 10.656-23.77 23.801v47.71c0 11.825 11.14 16.003 19.91 20.752 12.31 6.671 7.58 25.389-6.42 25.389-7.45 0-13.49 6.048-13.49 13.508v48.395c0 13.145-10.63 23.801-23.76 23.801zm134.89-106.758 5.41 9.95 33.51 61.622c8.62 15.86-2.84 35.186-20.87 35.186h-22.27c-8.74 0-16.77-4.798-20.92-12.496l-35.05-65.04a15.52 15.52 0 0 0-13.66-8.168c-42.24 0 40.62-82.154 73.85-21.054M931.652 0h68.748v1000h-68.748z"/></svg>',eg='<svg xmlns="http://www.w3.org/2000/svg" width="400" height="1601" fill="none"><path fill="#000" d="M72 1319.8c0-10.73 7.071-20.18 17.372-23.22l215.823-63.62c15.519-4.57 31.078 7.05 31.078 23.22v28.26c0 11.31-7.824 21.1-18.85 23.61l-109.636 24.94c-9.254 2.1-9.487 15.2-.313 17.63l110.784 29.37a24.21 24.21 0 0 1 18.015 23.4v25.64c0 11-7.423 20.62-18.071 23.41l-109.659 28.79c-9.162 2.41-8.986 15.47.236 17.63l108.792 25.46c10.955 2.56 18.702 12.33 18.702 23.57v28.39c0 16.17-15.559 27.79-31.078 23.22l-215.823-63.62c-10.3-3.04-17.372-12.49-17.372-23.22v-32.72c0-10.59 6.883-19.95 16.994-23.11l104.523-32.67c8.547-2.67 8.479-14.79-.096-17.36l-104.17-31.3C79.01 1372.42 72 1363 72 1352.31zM72 572.638V495.43c0-13.336 10.846-24.147 24.225-24.147h215.823c13.379 0 24.225 10.811 24.225 24.147v76.179q0 40.645-15.872 70.228-15.743 29.712-45.422 45.79-29.55 16.206-70.843 16.206-41.292 0-70.971-16.078-29.55-16.077-45.422-45.532Q72 612.767 72 572.638m85.132-29.84c-13.379 0-24.225 10.81-24.225 24.146v3.122q0 19.55 6.323 33.313 6.323 13.89 21.807 21.094 15.485 7.332 43.099 7.331t43.1-7.46q15.484-7.33 21.807-21.608 6.323-14.15 6.323-34.728v-1.064c0-13.336-10.846-24.146-24.225-24.146zM72 285.858c0-13.363 10.846-24.197 24.225-24.197h215.823c13.379 0 24.225 10.834 24.225 24.197v23.27c0 13.364-10.846 24.197-24.225 24.197H154.035c-13.379 0-24.225 10.834-24.225 24.197v58.328c0 13.364-10.846 24.197-24.225 24.197h-9.36C82.845 440.047 72 429.214 72 415.85zM278.463 24.72c0-13.374 10.846-24.216 24.225-24.216h9.36c13.379 0 24.225 10.842 24.225 24.216v181.174c0 13.374-10.846 24.216-24.225 24.216h-9.36c-13.379 0-24.225-10.842-24.225-24.216v-40.108c0-8.359-6.779-15.135-15.141-15.135H96.225c-13.38 0-24.225-10.842-24.225-24.216v-22.256c0-13.374 10.846-24.216 24.225-24.216h167.097c8.362 0 15.141-6.776 15.141-15.135z"/><path fill="#000" fill-rule="evenodd" d="M89.224 1062.13C78.997 1059.04 72 1049.63 72 1038.96v-25.9c0-16.486 16.145-28.147 31.818-22.979l215.823 71.169a24.19 24.19 0 0 1 16.632 22.98v62.97c0 10.45-6.706 19.71-16.632 22.98l-215.823 71.17C88.145 1246.51 72 1234.86 72 1218.37v-25.9c0-10.67 6.997-20.08 17.224-23.17l22.595-6.81a15.13 15.13 0 0 0 10.765-14.48v-64.59a15.13 15.13 0 0 0-10.765-14.48zm98.672 77.53 49.299-14.39c8.601-2.51 8.755-14.62.22-17.35l-49.299-15.75c-5.861-1.88-11.852 2.49-11.852 8.64v30.14c0 6.05 5.817 10.41 11.632 8.71" clip-rule="evenodd"/><path fill="#000" d="M72 773.439c0-13.367 10.846-24.203 24.225-24.203h215.823c13.379 0 24.225 10.836 24.225 24.203v89.762q0 29.395-10.711 51.439-10.71 22.046-30.84 34.293t-48.261 12.248q-28.388 0-47.873-12.635-18.187-11.672-28.056-32.218c-8.303-17.289-11.301-36.661-11.301-55.705v-43.867c0-77.976 138.26 4.16 86.215 4.16h-8.138c-12.334 0-22.332 9.989-22.332 22.311 0 8.269.351 16.6 3.097 24.487q3.225 9.024 10.194 13.794 6.968 4.899 18.194 4.899 11.356 0 18.453-4.899 7.226-4.77 10.581-13.794c2.815-7.188 3.484-14.944 3.484-22.596 0-13.366-10.846-24.202-24.225-24.202h-48.56c-12.036 0-16.288 11.345-21.122 20.272-6.79 12.539-25.841 7.72-25.841-6.536 0-7.586-6.156-13.736-13.749-13.736H96.225C82.845 820.916 72 810.08 72 796.714zm108.66 137.378-10.128 5.511-62.72 34.131C91.67 959.243 72 947.569 72 929.205V906.52a24.2 24.2 0 0 1 12.719-21.299l66.199-35.696a15.82 15.82 0 0 0 8.313-13.921c0-43.012 83.618 41.371 21.429 75.213"/></svg>';function Jh(J){return S("watermarkState",()=>J.state.get(),[J])}var CJ0=`data:image/svg+xml;utf8,${encodeURIComponent(tg)}`,PJ0=`data:image/svg+xml;utf8,${encodeURIComponent(eg)}`,Qh=VZ.memo(function(){let Q=cg(),Z=y(),q=S("is mobile",()=>Z.getViewportScreenBounds().width<700,[Z]),X=Jh(Q);if(!["licensed-with-watermark","unlicensed"].includes(X))return null;return b9.jsxs(b9.Fragment,{children:[b9.jsx(bJ0,{}),b9.jsx(wJ0,{src:q?PJ0:CJ0,isUnlicensed:X==="unlicensed"})]})}),IJ0=VZ.memo(function({isDebugMode:Q,isMobile:Z}){let q=y(),X=oq(),K=VZ.useRef(null);r6(K);let Y="https://tldraw.dev/pricing?utm_source=sdk&utm_medium=organic&utm_campaign=watermark";return b9.jsx("div",{ref:K,className:UZ.className,"data-debug":Q,"data-mobile":Z,"data-unlicensed":!0,"data-testid":"tl-watermark-unlicensed",draggable:!1,...X,children:b9.jsx("button",{draggable:!1,role:"button",onPointerDown:(W)=>{q.markEventAsHandled(W),W0(W)},title:"The tldraw SDK requires a license key to work in production. You can get a free 100-day trial license at tldraw.dev/pricing.",onClick:()=>{Y3.openWindow(Y,"_blank",!0)},children:"Get a license for production"})})}),wJ0=VZ.memo(function({src:Q,isUnlicensed:Z}){let q=y(),X=S("debug mode",()=>q.getInstanceState().isDebugMode,[q]),K=S("is mobile",()=>q.getViewportScreenBounds().width<700,[q]),Y=oq(),W=VZ.useRef(null);r6(W);let z=`url('${Q}') center 100% / 100% no-repeat`,G="https://tldraw.dev/?utm_source=sdk&utm_medium=organic&utm_campaign=watermark";if(Z)return b9.jsx(IJ0,{isDebugMode:X,isMobile:K});return b9.jsx("div",{ref:W,className:UZ.className,"data-debug":X,"data-mobile":K,"data-testid":"tl-watermark-licensed",draggable:!1,...Y,children:b9.jsx("button",{draggable:!1,role:"button",onPointerDown:(H)=>{q.markEventAsHandled(H),W0(H)},title:"Build infinite canvas applications with the tldraw SDK. Learn more at https://tldraw.dev.",onClick:()=>{Y3.openWindow(G,"_blank")},style:{mask:z,WebkitMask:z}})})}),bJ0=VZ.memo(function(){let Q=y(),Z=UZ.className,q=`
|
|
96
96
|
/* ------------------- SEE LICENSE -------------------
|
|
97
97
|
The tldraw watermark is part of tldraw's license. It is shown for unlicensed
|
|
98
98
|
or "licensed-with-watermark" users. By using this library, you agree to
|
|
@@ -543,4 +543,4 @@ ${Z}
|
|
|
543
543
|
${(q?Q.height:0)-(Y?Y:0)}px)`:""} ${W}`,transformOrigin:Q?"0 0":"center center"}}function FN0({shape:J,src:Q}){let Z=D5(),q=le(J),X=J.props.crop;if(q.transform&&X){let{transform:K,width:Y,height:W}=q,z=(X.bottomRight.x-X.topLeft.x)*Y,G=(X.bottomRight.y-X.topLeft.y)*W,H=[new D(0,0),new D(z,0),new D(z,G),new D(0,G)],$=X_(J,{width:Y,height:W});return C4.jsxs(C4.Fragment,{children:[C4.jsx("defs",{children:C4.jsx("clipPath",{id:Z,children:X.isCircle?C4.jsx("ellipse",{cx:z/2,cy:G/2,rx:z/2,ry:G/2}):C4.jsx("polygon",{points:H.map((_)=>`${_.x},${_.y}`).join(" ")})})}),C4.jsx("g",{clipPath:`url(#${Z})`,children:C4.jsx("image",{href:Q,width:Y,height:W,"aria-label":J.props.altText,style:$?{...$}:{transform:K}})})]})}else return C4.jsx("image",{href:Q,width:J.props.w,height:J.props.h,"aria-label":J.props.altText,style:X_(J,{width:J.props.w,height:J.props.h})})}function pe(J){let Q=!1;return{promise:new Promise((q)=>{let X=P7();X.onload=()=>{if(Q)return;let K=_4().createElement("canvas");K.width=X.width,K.height=X.height;let Y=K.getContext("2d");if(!Y)return;Y.drawImage(X,0,0),q(K.toDataURL())},X.crossOrigin="anonymous",X.src=J}),cancel:()=>Q=!0}}var ML=E(c(),1);var UN0=new C1;class jL extends s6{static type="line";static props=cz;static migrations=lz;options={getDefaultDisplayValues(J,Q,Z,q){let{color:X,size:K}=Q.props;return{strokeColor:W1(Z.colors[q],X,"solid"),strokeWidth:Z.strokeWidth*Q4[K]}},getCustomDisplayValues(){return{}}};hideResizeHandles(J){return!0}hideRotateHandle(J){return!0}hideSelectionBoundsFg(J){return!0}hideSelectionBoundsBg(J){return!0}hideInMinimap(){return!0}getDefaultProps(){let[J,Q]=V2(2);return{dash:"draw",size:"m",color:"black",spline:"line",points:{[J]:{id:J,index:J,x:0,y:0},[Q]:{id:Q,index:Q,x:0.1,y:0.1}},scale:1}}getGeometry(J){let Q=vb(J).toGeometry();return Q0(Q instanceof HY),Q}getHandles(J){return UN0.get(J.props,()=>{let Q=this.getGeometry(J),Z=K_(J),q=Z.map((X)=>({...X,id:X.index,type:"vertex",canSnap:!0}));for(let X=0;X<Z.length-1;X++){let K=i9(Z[X].index,Z[X+1].index),W=Q.getSegments()[X].interpolateAlongEdge(0.5);q.push({id:K,type:"create",index:K,x:W.x,y:W.y,canSnap:!0})}return q.sort(L4)})}onResize(J,Q){let{scaleX:Z,scaleY:q}=Q;return{props:{points:B5(J.props.points,(X,{id:K,index:Y,x:W,y:z})=>({id:K,index:Y,x:W*Z,y:z*q}))}}}onBeforeCreate(J){let{props:{points:Q}}=J,Z=Object.keys(Q);if(Z.length<2)return;let q=Q[Z[0]];if(Z.every((K)=>{let Y=Q[K];return Y.x===q.x&&Y.y===q.y})){let K=Z[Z.length-1];return Q[K]={...Q[K],x:Q[K].x+0.1,y:Q[K].y+0.1},J}return}onHandleDrag(J,{handle:Q}){let Z=j6(new D(Q.x,Q.y),this.editor);return{...J,props:{...J.props,points:{...J.props.points,[Q.id]:{id:Q.id,index:Q.index,x:Z.x,y:Z.y}}}}}onHandleDragStart(J,{handle:Q}){if(Q.type==="create")return{...J,props:{...J.props,points:{...J.props.points,[Q.index]:{id:Q.index,index:Q.index,x:Q.x,y:Q.y}}}};return}component(J){let Q=z6(),Z=k0(this,J,Q);return ML.jsx(e5,{style:{minWidth:50,minHeight:50},children:ML.jsx(de,{shape:J,strokeColor:Z.strokeColor,strokeWidth:Z.strokeWidth})})}getIndicatorPath(J){let Q=k0(this,J).strokeWidth*J.props.scale,Z=vb(J),{dash:q}=J.props;return Z.toPath2D({style:q==="draw"?"draw":"solid",strokeWidth:1,passes:1,randomSeed:J.id,offset:0,roundness:Q*2})}toSvg(J,Q){let Z=k0(this,J,Q.colorMode);return ML.jsx(de,{shouldScale:!0,shape:J,strokeColor:Z.strokeColor,strokeWidth:Z.strokeWidth})}getHandleSnapGeometry(J){let Q=K_(J);return{points:Q,getSelfSnapPoints:(Z)=>{let q=this.getHandles(J).filter((X)=>X.type==="vertex").findIndex((X)=>X.id===Z.id);return Q.filter((X,K)=>Math.abs(K-q)>1).map(D.From)},getSelfSnapOutline:(Z)=>{let q=this.getHandles(J).filter((K)=>K.type==="vertex").findIndex((K)=>K.id===Z.id),X=this.getGeometry(J).getSegments().filter((K,Y)=>Y!==q-1&&Y!==q);if(!X.length)return null;return new y4({children:X})}}}getInterpolatedProps(J,Q,Z){let q=K_(J),X=K_(Q),K=[],Y=[],W=fq;if(q.length>X.length)for(let z=0;z<q.length;z++){if(K[z]={...q[z]},X[z]===void 0)Y[z]={...X[X.length-1],id:W};else Y[z]={...X[z],id:W};W=p6(W)}else if(X.length>q.length)for(let z=0;z<X.length;z++){if(Y[z]={...X[z]},q[z]===void 0)K[z]={...q[q.length-1],id:W};else K[z]={...q[z],id:W};W=p6(W)}else for(let z=0;z<X.length;z++)K[z]=q[z],Y[z]=X[z];return{...Z>0.5?Q.props:J.props,points:Object.fromEntries(K.map((z,G)=>{let H=Y[G];return[z.id,{...z,x:I0(z.x,H.x,Z),y:I0(z.y,H.y,Z)}]})),scale:I0(J.props.scale,Q.props.scale,Z)}}}function K_(J){return Object.values(J.props.points).sort(L4)}var VN0=new C1;function vb(J){return VN0.get(J,()=>{let Q=K_(J).map(D.From);switch(J.props.spline){case"cubic":return P1.cubicSplineThroughPoints(Q,{endOffsets:0});case"line":return P1.lineThroughPoints(Q,{endOffsets:0})}})}function de({shape:J,shouldScale:Q=!1,forceSolid:Z=!1,strokeColor:q,strokeWidth:X}){let K=vb(J),{dash:Y}=J.props,W=1/J.props.scale,z=Q?W:1,G=X*J.props.scale;return K.toSvg({style:Y,strokeWidth:G,forceSolid:Z,randomSeed:J.id,props:{transform:`scale(${z})`,stroke:q,fill:"none"}})}var m1=E(c(),1);var kL=E(m(),1);var NN0=Object.freeze({start:"start",middle:"center",end:"end","start-legacy":"start","end-legacy":"end","middle-legacy":"center"}),BN0=Object.freeze({start:"start",middle:"middle",end:"end"});class EL extends s6{static type="note";static props=pz;static migrations=dz;options={resizeMode:"none",getDefaultDisplayValues(J,Q,Z,q){let{color:X,labelColor:K,font:Y,size:W,align:z,verticalAlign:G}=Q.props,H=Z.colors[q];return{noteWidth:200,noteHeight:200,noteBackgroundColor:W1(H,X,"noteFill"),borderColor:H.noteBorder,borderWidth:2,labelColor:K==="black"?W1(H,X,"noteText"):W1(H,K,"fill"),labelFontFamily:v9(Z,Y),labelFontSize:Z.fontSize*j$[W],labelLineHeight:Z.lineHeight,labelFontWeight:z5.fontWeight,labelFontVariant:z5.fontVariant,labelFontStyle:z5.fontStyle,labelPadding:mJ,labelHorizontalAlign:NN0[z],labelVerticalAlign:BN0[G]}},getCustomDisplayValues(){return{}}};canEdit(J){return!0}hideResizeHandles(J){let{resizeMode:Q}=this.options;switch(Q){case"none":return!0;case"scale":return!1;default:throw h0(Q)}}isAspectRatioLocked(J){return this.options.resizeMode==="scale"}hideSelectionBoundsFg(J){return!1}getDefaultProps(){return{color:"black",richText:y1(""),size:"m",font:"draw",align:"middle",verticalAlign:"middle",labelColor:"black",growY:0,fontSizeAdjustment:1,url:"",scale:1,textLastEditedBy:null}}getGeometry(J){let{labelHeight:Q,labelWidth:Z}=this.getLabelSize(J),{scale:q}=J.props,X=k0(this,J),K=Q*q,Y=Z*q,W=X.noteWidth*q,z=RL(J,X.noteHeight);return new y4({children:[new x4({width:W,height:z,isFilled:!0}),new x4({x:X.labelHorizontalAlign==="start"?0:X.labelHorizontalAlign==="end"?W-Y:(W-Y)/2,y:X.labelVerticalAlign==="start"?0:X.labelVerticalAlign==="end"?z-K:(z-K)/2,width:Y,height:K,isFilled:!0,isLabel:!0,excludeFromShapeBounds:!0})]})}getHandles(J){let{scale:Q}=J.props;if(this.editor.getInstanceState().isCoarsePointer)return[];let q=this.editor.getEfficientZoomLevel();if(q*Q<0.25)return[];let X=k0(this,J),K=RL(J,X.noteHeight),Y=X.noteWidth*Q,W=Ze/q*Q;if(q*Q<0.5)return[{id:"bottom",index:"a3",type:"clone",x:Y/2,y:K+W}];return[{id:"top",index:"a1",type:"clone",x:Y/2,y:-W},{id:"right",index:"a2",type:"clone",x:Y+W,y:K/2},{id:"bottom",index:"a3",type:"clone",x:Y/2,y:K+W},{id:"left",index:"a4",type:"clone",x:-W,y:K/2}]}onResize(J,Q){let{resizeMode:Z}=this.options;switch(Z){case"none":return;case"scale":return wG(J,Q);default:throw h0(Z)}}getText(J){return f9(this.editor,J.props.richText)}getReferencedUserIds(J){return J.props.textLastEditedBy?[J.props.textLastEditedBy]:[]}getFontFaces(J){let Q=r1(J.props.richText)?[]:uJ(this.editor,J.props.richText,{family:`tldraw_${J.props.font}`,weight:"normal",style:"normal"});if(J.props.textLastEditedBy&&!r1(J.props.richText))return[...Q,d3.tldraw_sans.normal.normal];let Z=IZ(this.editor.getCurrentTheme(),J.props.font);if(Z)return[...Z,...Q];return Q.length?Q:Y1}component(J){let{id:Q,type:Z,props:q}=J,{scale:X,richText:K,fontSizeAdjustment:Y,textLastEditedBy:W}=q,z=ON0(Q),G=S("shape rotation",()=>this.editor.getShapePageTransform(Q)?.rotation()??0,[this.editor]),H=z6(),$=k0(this,J,H),_=$.noteWidth*X,F=RL(J,$.noteHeight),U=Oq(0.25/X),V=J.id===this.editor.getOnlySelectedShapeId(),N=sH(this.editor,J.id),B=r1(K),O=S("attribution",()=>{if(!W||B)return null;let M=this.editor.getAttributionDisplayName(W);if(!M)return null;return{short:M.split(" ")[0],full:M}},[W,B,this.editor]);return m1.jsxs(m1.Fragment,{children:[m1.jsxs("div",{id:Q,className:"tl-note__container",style:{width:_,height:F,backgroundColor:$.noteBackgroundColor,borderBottom:U?`${$.borderWidth*X}px solid ${$.borderColor}`:"none",boxShadow:U?"none":LN0(J.id,G,X)},children:[O&&m1.jsx(o8,{content:O.full,side:"bottom",children:m1.jsx("div",{className:"tl-note__attribution",style:{["--note-attribution-scale"]:X,fontSize:11*X,color:$.labelColor,opacity:0.6},children:O.short})}),(V||N||!B)&&m1.jsx(CQ,{shapeId:Q,type:Z,fontFamily:$.labelFontFamily,fontSize:(Y??1)*$.labelFontSize,lineHeight:$.labelLineHeight,textAlign:$.labelHorizontalAlign,verticalAlign:$.labelVerticalAlign,richText:K,isSelected:V,labelColor:$.labelColor,wrap:!0,padding:$.labelPadding,hasCustomTabBehavior:!0,showTextOutline:!1,onKeyDown:z,style:X!==1?{transform:`scale(${X})`,transformOrigin:"top left",width:$.noteWidth,height:$.noteHeight+J.props.growY}:void 0})]}),"url"in J.props&&J.props.url&&m1.jsx(G2,{url:J.props.url})]})}getIndicatorPath(J){let{scale:Q}=J.props,Z=k0(this,J),q=new Path2D;return q.rect(0,0,Z.noteWidth*Q,RL(J,Z.noteHeight)),q}toSvg(J,Q){let Z=k0(this,J,Q.colorMode),q=new p(0,0,Z.noteWidth,Z.noteHeight+J.props.growY),X=`note-shadow-${J.id.replace(/:/g,"_")}`;Q.addExportDef({key:X,getElement:()=>m1.jsxs("filter",{id:X,x:"-10%",y:"-10%",width:"130%",height:"150%",children:[m1.jsx("feMorphology",{in:"SourceAlpha",operator:"erode",radius:"3",result:"erode1"}),m1.jsx("feGaussianBlur",{in:"erode1",stdDeviation:"3",result:"blur1"}),m1.jsx("feOffset",{in:"blur1",dy:"3",result:"offsetBlur1"}),m1.jsx("feComponentTransfer",{in:"offsetBlur1",result:"shadow1",children:m1.jsx("feFuncA",{type:"linear",slope:"0.5"})}),m1.jsx("feMorphology",{in:"SourceAlpha",operator:"erode",radius:"10",result:"erode2"}),m1.jsx("feGaussianBlur",{in:"erode2",stdDeviation:"6",result:"blur2"}),m1.jsx("feOffset",{in:"blur2",dy:"6",result:"offsetBlur2"}),m1.jsx("feComponentTransfer",{in:"offsetBlur2",result:"shadow2",children:m1.jsx("feFuncA",{type:"linear",slope:"0.5"})}),m1.jsxs("feMerge",{children:[m1.jsx("feMergeNode",{in:"shadow1"}),m1.jsx("feMergeNode",{in:"shadow2"}),m1.jsx("feMergeNode",{in:"SourceGraphic"})]})]})});let{textLastEditedBy:K}=J.props,Y=K&&!r1(J.props.richText)?this.editor.getAttributionDisplayName(K)?.split(" ")[0]??null:null;return m1.jsxs(m1.Fragment,{children:[Q.isDarkMode?null:m1.jsx("rect",{rx:1,width:Z.noteWidth,height:q.h,fill:Z.noteBackgroundColor,filter:`url(#${X})`}),m1.jsx("rect",{rx:1,width:Z.noteWidth,height:q.h,fill:Z.noteBackgroundColor}),m1.jsx(PQ,{fontSize:(J.props.fontSizeAdjustment??1)*Z.labelFontSize,fontFamily:Z.labelFontFamily,lineHeight:Z.labelLineHeight,textAlign:Z.labelHorizontalAlign,verticalAlign:Z.labelVerticalAlign,richText:J.props.richText,labelColor:Z.labelColor,bounds:q,padding:Z.labelPadding,showTextOutline:!1}),Y&&m1.jsx("foreignObject",{x:0,y:0,width:Z.noteWidth,height:q.h,className:"tl-export-embed-styles",children:m1.jsx("div",{style:{position:"relative",width:"100%",height:"100%"},children:m1.jsx("div",{className:"tl-note__attribution",style:{fontSize:11,color:Z.labelColor,opacity:0.6},children:Y})})})]})}onBeforeCreate(J){return this.getNoteSizeAdjustments(J)}onBeforeUpdate(J,Q){let Z=!V6.default(J.props.richText,Q.props.richText);if(!Z&&J.props.font===Q.props.font&&J.props.size===Q.props.size)return;let q=Q;if(Z)if(r1(Q.props.richText))q={...q,props:{...q.props,textLastEditedBy:null}};else q={...q,props:{...q.props,textLastEditedBy:this.editor.getAttributionUserId()}};return this.getNoteSizeAdjustments(q)??(Z?q:void 0)}getInterpolatedProps(J,Q,Z){return{...Z>0.5?Q.props:J.props,scale:I0(J.props.scale,Q.props.scale,Z)}}getNoteSizeAdjustments(J){let Q=k0(this,J),{labelHeight:Z,fontSizeAdjustment:q}=this.getLabelSize(J),X=Math.max(0,Z-Q.noteHeight);if(X!==J.props.growY||q!==J.props.fontSizeAdjustment)return{...J,props:{...J.props,growY:X,fontSizeAdjustment:q}};return}_labelSizesForNoteCache=new C1;getLabelSize(J){return this._labelSizesForNoteCache.get(J,()=>this.measureNoteLabelSize(J))}measureNoteLabelSize(J){let Q=k0(this,J),{richText:Z}=J.props;if(r1(Z))return{labelHeight:p8(Q.labelFontSize,Q.labelLineHeight)+Q.labelPadding*2,labelWidth:100,fontSizeAdjustment:1};let q=Q.labelFontSize,X=q,K=0,Y=Q.noteHeight,W=Q.noteWidth,z=1;do{X=Math.min(q,q-K);let G=S9(this.editor,Z),H=this.editor.textMeasure.measureHtml(G,{...z5,lineHeight:Q.labelLineHeight,fontFamily:Q.labelFontFamily,fontSize:X,maxWidth:Q.noteWidth-Q.labelPadding*2-z,disableOverflowWrapBreaking:!0,measureScrollWidth:!0});if(Y=H.h+Q.labelPadding*2,W=H.w+Q.labelPadding*2,X<=14){let $=S9(this.editor,Z),_=this.editor.textMeasure.measureHtml($,{...z5,lineHeight:Q.labelLineHeight,fontFamily:Q.labelFontFamily,fontSize:X,maxWidth:Q.noteWidth-Q.labelPadding*2-z});Y=_.h+Q.labelPadding*2,W=_.w+Q.labelPadding*2;break}if(H.scrollWidth.toFixed(0)===H.w.toFixed(0))break}while(K++<50);return{labelHeight:Y,labelWidth:W,fontSizeAdjustment:X===q?1:X/q}}}function ON0(J){let Q=y(),Z=kL.useContext(O$);return kL.useCallback((q)=>{let X=Q.getShape(J);if(!X)return;let K=q.key==="Tab",Y=(q.metaKey||q.ctrlKey)&&q.key==="Enter";if(K&&WN(Q)){q.preventDefault();return}if(K||Y){q.preventDefault();let W=Q.getShapePageTransform(J),z=W.rotation(),G=!!(Z?.dir==="rtl"||zN(f9(Q,X.props.richText))),H=Q.getShapeUtil(X),$=k0(H,X),F=(K?$.noteWidth+Q.options.adjacentShapeMargin:$.noteHeight+Q.options.adjacentShapeMargin+(Y&&!q.shiftKey?X.props.growY:0))*X.props.scale,U=new D(K?q.shiftKey!=G?-1:1:0,Y?q.shiftKey?-1:1:0).mul(F).add(new D($.noteWidth/2,$.noteHeight/2).mul(X.props.scale)).rot(z).add(W.point()),V=aO(Q,{shape:X,center:U,pageRotation:z,noteWidth:$.noteWidth,noteHeight:$.noteHeight});if(V)S4(Q,V,{selectAll:!0})}},[J,Q,Z?.dir])}function RL(J,Q){return(Q+J.props.growY)*J.props.scale}function LN0(J,Q,Z){let q=F9(J),X=Math.abs(q())+0.5,K=Math.cos(Q),Y=5*Z,W=4*Z,z=6*Z,G=7*Z;return`0px ${Math.max(0,Y-X)}px ${Y}px -${Y}px rgba(15, 23, 31, .6),
|
|
544
544
|
0px ${(W+X*G)*Math.max(0,K)}px ${z+X*G}px -${W+X*z}px rgba(15, 23, 31, ${(0.3+X*0.1).toFixed(2)}),
|
|
545
545
|
0px ${48*Z}px ${10*Z}px -${10*Z}px inset rgba(15, 23, 44, ${((0.022+q()*0.005)*((1+K)/2)).toFixed(2)})`}var Sb=E(c(),1);var ie=E(m(),1);var DN0=0.3,MN0=O9("text size",(J,Q)=>{J.fonts.trackFontsForShape(Q);let Z=J.getShapeUtil(Q),q=k0(Z,Q);return ne(J,Q.props,q)},{areRecordsEqual:(J,Q)=>J.props===Q.props});class AL extends s6{static type="text";static props=iz;static migrations=nz;options={extraArrowHorizontalPadding:10,showTextOutline:!0,getDefaultDisplayValues(J,Q,Z,q){let{color:X,font:K,size:Y}=Q.props;return{color:W1(Z.colors[q],X,"solid"),fontFamily:v9(Z,K),fontSize:Z.fontSize*S3[Y],lineHeight:Z.lineHeight,fontWeight:z5.fontWeight,fontStyle:z5.fontStyle,fontVariant:z5.fontVariant}},getCustomDisplayValues(){return{}}};getDefaultProps(){return{color:"black",size:"m",w:8,font:"draw",textAlign:"start",autoSize:!0,scale:1,richText:y1("")}}getMinDimensions(J){return MN0.get(this.editor,J.id)}getGeometry(J,Q){let{scale:Z}=J.props,{width:q,height:X}=this.getMinDimensions(J),K=Q?.context??"none";return new x4({x:(K==="@tldraw/arrow-without-arrowhead"?-this.options.extraArrowHorizontalPadding:0)*Z,width:(q+(K==="@tldraw/arrow-without-arrowhead"?this.options.extraArrowHorizontalPadding*2:0))*Z,height:X*Z,isFilled:!0,isLabel:!0})}getFontFaces(J){let Q=IZ(this.editor.getCurrentTheme(),J.props.font);if(Q)return Q;return uJ(this.editor,J.props.richText,{family:`tldraw_${J.props.font}`,weight:"normal",style:"normal"})}getText(J){return f9(this.editor,J.props.richText)}canEdit(J){return!0}isAspectRatioLocked(J){return!0}component(J){let{id:Q,props:{richText:Z,scale:q,textAlign:X}}=J,{width:K,height:Y}=this.getMinDimensions(J),W=J.id===this.editor.getOnlySelectedShapeId(),z=z6(),G=k0(this,J,z),H=jN0(Q);return Sb.jsx(CQ,{shapeId:Q,classNamePrefix:"tl-text-shape",type:"text",fontFamily:G.fontFamily,fontSize:G.fontSize,lineHeight:G.lineHeight,textAlign:X==="middle"?"center":X,verticalAlign:"middle",richText:Z,labelColor:G.color,isSelected:W,textWidth:K,textHeight:Y,showTextOutline:this.options.showTextOutline,style:{transform:`scale(${q})`,transformOrigin:"top left"},wrap:!0,onKeyDown:H})}getIndicatorPath(J){if(J.props.autoSize&&this.editor.getEditingShapeId()===J.id)return;let Q=this.editor.getShapeGeometry(J).bounds,Z=new Path2D;return Z.rect(0,0,Q.width,Q.height),Z}toSvg(J,Q){let Z=this.editor.getShapeGeometry(J).bounds,q=Z.width/(J.props.scale??1),X=Z.height/(J.props.scale??1),K=k0(this,J,Q.colorMode),Y=Math.ceil(K.fontSize*DN0),W=new p(-Y,-Y,q+Y*2,X+Y*2);return Sb.jsx(PQ,{fontSize:K.fontSize,fontFamily:K.fontFamily,lineHeight:K.lineHeight,textAlign:J.props.textAlign==="middle"?"center":J.props.textAlign,verticalAlign:"middle",richText:J.props.richText,labelColor:K.color,bounds:W,padding:Y,showTextOutline:this.options.showTextOutline})}onResize(J,Q){let{newPoint:Z,initialBounds:q,initialShape:X,scaleX:K,handle:Y}=Q;if(Q.mode==="scale_shape"||Y!=="right"&&Y!=="left")return{id:J.id,type:J.type,...wG(J,Q)};else{let W=Math.max(1,Math.abs(q.width*K)),{x:z,y:G}=K<0?D.Sub(Z,D.FromAngle(J.rotation).mul(W)):Z;return{id:J.id,type:J.type,x:z,y:G,props:{w:W/X.props.scale,autoSize:!1}}}}onEditEnd(J){if(f9(this.editor,J.props.richText).trimEnd().length===0)this.editor.deleteShapes([J.id])}onBeforeUpdate(J,Q){if(!Q.props.autoSize)return;let Z=J.props.size!==Q.props.size||J.props.textAlign!==Q.props.textAlign||J.props.font!==Q.props.font||J.props.scale!==1&&Q.props.scale===1,q=!V6.default(J.props.richText,Q.props.richText);if(!Z&&!q)return;let X=this.getMinDimensions(J),K=k0(this,Q),Y=ne(this.editor,Q.props,K),W=X.width*J.props.scale,z=X.height*J.props.scale,G=Y.width*Q.props.scale,H=Y.height*Q.props.scale,$;switch(Q.props.textAlign){case"middle":{$=new D((G-W)/2,q?0:(H-z)/2);break}case"end":{$=new D(G-W,q?0:(H-z)/2);break}default:{if(q)break;$=new D(0,(H-z)/2);break}}if($){$.rot(Q.rotation);let{x:_,y:F}=Q;return{...Q,x:_-$.x,y:F-$.y,props:{...Q.props,w:G}}}else return{...Q,props:{...Q.props,w:G}}}}function ne(J,Q,Z){let{richText:q,w:X}=Q,K=16,Y=Q.autoSize?null:Math.max(16,Math.floor(X)),W=S9(J,q),z=J.textMeasure.measureHtml(W,{lineHeight:Z.lineHeight,fontWeight:Z.fontWeight,fontStyle:Z.fontStyle,padding:"0px",fontFamily:Z.fontFamily,fontSize:Z.fontSize,maxWidth:Y});return{width:Y??Math.max(16,z.w+1),height:Math.max(Z.fontSize,z.h)}}function jN0(J){let Q=y();return ie.useCallback((Z)=>{if(Q.getEditingShapeId()!==J)return;switch(Z.key){case"Enter":{if(Z.ctrlKey||Z.metaKey)Q.complete();break}}},[Q,J])}var T5=E(c(),1);var se=E(c1(),1),A7=E(m(),1);var RN0=new C1;class CL extends d8{static type="video";static props=sz;static migrations=rz;static handledAssetTypes=["video"];options={autoplay:!0,getDefaultDisplayValues(){return{}},getCustomDisplayValues(){return{}}};canEdit(J){return!0}isAspectRatioLocked(J){return!0}getDefaultProps(){return{w:100,h:100,assetId:null,autoplay:this.options.autoplay,url:"",altText:"",time:0,playing:!0}}createShapeForAsset(J,Q){let Z=J;return{id:l0(),type:"video",x:Q.x,y:Q.y,opacity:1,props:{assetId:Z.id,w:Z.props.w,h:Z.props.h}}}getAriaDescriptor(J){return J.props.altText}component(J){return T5.jsx(kN0,{shape:J})}getIndicatorPath(J){let Q=new Path2D;return Q.rect(0,0,J.props.w,J.props.h),Q}async toSvg(J,Q){let Z=J.props;if(!Z.assetId)return null;let q=this.editor.getAsset(Z.assetId);if(!q)return null;let X=await RN0.get(q,async()=>{let K=await Q.resolveAssetUrl(q.id,Z.w);if(!K)return null;let Y=await l6.loadVideo(K,this.editor.getContainerDocument());return await l6.getVideoFrameAsDataUrl(Y,0)});if(!X)return null;return T5.jsx("image",{href:X,width:Z.w,height:Z.h,"aria-label":J.props.altText})}}var kN0=A7.memo(function({shape:Q}){let Z=y(),q=Z.getShapeGeometry(Q).bounds.w*Z.getEfficientZoomLevel()>=110,X=IJ(Q.id),K=V$(),{Spinner:Y}=T4(),{asset:W,url:z}=Q_({shapeId:Q.id,assetId:Q.props.assetId,width:Q.props.w}),G=A7.useRef(null),[H,$]=A7.useState(!1),_=A7.useCallback((V)=>{if(!V.currentTarget)return;$(!0)},[]),[F,U]=A7.useState(!1);return A7.useEffect(()=>{let V=G.current?.ownerDocument??Z.getContainerDocument(),N=()=>U(V.fullscreenElement===G.current);return V.addEventListener("fullscreenchange",N),()=>V.removeEventListener("fullscreenchange",N)}),A7.useEffect(()=>{let V=G.current;if(!V)return;if(X){if(V.ownerDocument.activeElement!==V)V.focus()}},[X,H]),T5.jsxs(T5.Fragment,{children:[T5.jsx(u8,{id:Q.id,style:{color:"var(--tl-color-text-3)",backgroundColor:W?"transparent":"var(--tl-color-low)",border:W?"none":"1px solid var(--tl-color-low-border)"},children:T5.jsx("div",{className:"tl-counter-scaled",children:T5.jsx("div",{className:"tl-video-container",children:!W?T5.jsx(OL,{}):Y&&!W.props.src?T5.jsx(Y,{}):z?T5.jsxs(T5.Fragment,{children:[T5.jsx("video",{ref:G,style:X?{pointerEvents:"all"}:!H?{display:"none"}:void 0,className:se.default("tl-video",`tl-video-shape-${Q.id.split(":")[1]}`,{"tl-video-is-fullscreen":F}),width:"100%",height:"100%",draggable:!1,playsInline:!0,autoPlay:Q.props.autoplay&&!K,muted:!0,loop:!0,disableRemotePlayback:!0,disablePictureInPicture:!0,controls:X&&q,onLoadedData:_,hidden:!H,"aria-label":Q.props.altText,children:T5.jsx("source",{src:z})},z),!H&&Y&&T5.jsx(Y,{})]}):null})})}),"url"in Q.props&&Q.props.url&&T5.jsx(G2,{url:Q.props.url})]})});var bX=[AL,KL,zL,UL,EL,jL,FL,qL,BL,Dq,DL,CL];function fb(J){let Q=J.sideEffects.register({instance:{afterChange:(Z,q)=>{if(Z.cameraState!==q.cameraState&&q.cameraState==="idle")W2(J)}},instance_page_state:{afterChange:(Z,q)=>{if(Z.croppingShapeId!==q.croppingShapeId){let X=J.isIn("select.crop");if(!Z.croppingShapeId&&q.croppingShapeId){if(!X)J.setCurrentTool("select.crop.idle")}else if(Z.croppingShapeId&&!q.croppingShapeId){if(X)J.setCurrentTool("select.idle")}}if(Z.editingShapeId!==q.editingShapeId){if(!Z.editingShapeId&&q.editingShapeId){if(!J.isIn("select.editing_shape")){let X=J.getEditingShape();if(X&&X.type==="text"&&J.isInAny("text.pointing","select.resizing")&&J.getInstanceState().isToolLocked)J.setCurrentTool("select.editing_shape",{target:"shape",shape:X,isCreatingTextWhileToolLocked:!0});else J.setCurrentTool("select.editing_shape",{target:"shape",shape:X})}}else if(Z.editingShapeId&&!q.editingShapeId){if(J.isIn("select.editing_shape"))J.setCurrentTool("select.idle")}}}}});return()=>{Q(),Vq(J)}}class gb extends a{static id="erasing";static trackPerformance=!0;info={};scribbleId="id";markId="";excludedShapeIds=new Set;_erasingShapeIds=[];onEnter(J){this.markId=this.editor.markHistoryStoppingPoint("erase scribble begin"),this.info=J;let Q=this.editor.inputs.getOriginPagePoint();this.excludedShapeIds=new Set(this.editor.getCurrentPageShapes().filter((q)=>{if(this.editor.isShapeOrAncestorLocked(q))return!0;if(this.editor.isShapeOfType(q,"group")||this.editor.isShapeFrameLike(q)){let X=this.editor.getPointInShapeSpace(q,Q);return this.editor.getShapeGeometry(q).bounds.containsPoint(X)}return!1}).map((q)=>q.id)),this._erasingShapeIds=this.editor.getShapesAtPoint(Q).filter((q)=>!this.excludedShapeIds.has(q.id)).map((q)=>q.id),this.editor.setErasingShapes([...new Set([...this.editor.getErasingShapeIds(),...this._erasingShapeIds])]);let Z=this.editor.scribbles.addScribble({color:"muted-1",size:12});this.scribbleId=Z.id,this.update()}pushPointToScribble(){let{x:J,y:Q}=this.editor.inputs.getCurrentPagePoint();this.editor.scribbles.addPoint(this.scribbleId,J,Q)}onExit(){this.editor.setErasingShapes([]),this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.update()}onPointerUp(J){this.complete(J)}onCancel(){this.cancel()}onComplete(){this.complete()}update(){let{editor:J,excludedShapeIds:Q}=this,Z=J.getErasingShapeIds(),q=J.getZoomLevel(),X=J.inputs.getCurrentPagePoint(),K=J.inputs.getPreviousPagePoint();this.pushPointToScribble();let Y=new Set(Z),W=this.editor.options.hitTestMargin/q,z=p.FromPoints([K,X]).expandBy(W),G=J.getShapeIdsInsideBounds(z);if(G.size===0){J.setErasingShapes(Array.from(Y));return}let $=J.getCurrentPageRenderingShapesSorted().filter((_)=>G.has(_.id));for(let _ of $){if(J.isShapeOfType(_,"group"))continue;let F=J.getShapeMask(_.id);if(F&&!n1(X,F))continue;let U=J.getShapeGeometry(_),V=J.getShapePageTransform(_);if(!U||!V)continue;let N=V.clone().invert(),B=N.applyToPoint(K),O=N.applyToPoint(X),{bounds:M}=U;if(M.minX-W>Math.max(B.x,O.x)||M.minY-W>Math.max(B.y,O.y)||M.maxX+W<Math.min(B.x,O.x)||M.maxY+W<Math.min(B.y,O.y))continue;if(U.hitTestLineSegment(B,O,W)){let L=J.getOutermostSelectableShape(_);if(Q.has(L.id))Y.add(J.getOutermostSelectableShape(_,(j)=>!Q.has(j.id)).id);else Y.add(L.id)}this._erasingShapeIds=[...Y]}this.editor.setErasingShapes(this._erasingShapeIds.filter((_)=>!Q.has(_)))}complete(J){let{editor:Q}=this;Q.deleteShapes(Q.getCurrentPageState().erasingShapeIds),this.parent.transition("idle",J),this._erasingShapeIds=[]}cancel(){let{editor:J}=this;J.bailToMark(this.markId),this.parent.transition("idle",this.info)}}class hb extends a{static id="idle";onEnter(J){if(!(J?.accelKey??this.editor.inputs.getAccelKey()))this.parent.maybeReturnToOriginatingTool()}onKeyUp(J){if(!J6(J))this.parent.maybeReturnToOriginatingTool()}onPointerDown(J){this.parent.transition("pointing",J)}onCancel(){let J=this.parent.info.onInteractionEnd;this.editor.setCurrentTool(J??"select")}}class ub extends a{static id="pointing";onEnter(J){let Q=J.accelKey,Z=this.editor.getZoomLevel(),q=this.editor.getCurrentPageRenderingShapesSorted(),X=this.editor.inputs.getCurrentPagePoint(),K=new Set,Y=K.size;for(let W=q.length,z=W-1;z>=0;z--){let G=q[z];if(this.editor.isShapeOrAncestorLocked(G)||this.editor.isShapeOfType(G,"group"))continue;if(this.editor.isPointInShape(G,X,{hitInside:!1,margin:this.editor.options.hitTestMargin/Z})){let H=this.editor.getOutermostSelectableShape(G);if(this.editor.isShapeFrameLike(H)&&K.size>Y)break;if(K.add(H.id),Q)break}}this.editor.setErasingShapes([...K])}onLongPress(J){if(J.accelKey)return;this.startErasing(J)}onExit(J,Q){if(Q!=="erasing")this.editor.setErasingShapes([])}onPointerMove(J){if(this.editor.inputs.getIsDragging())this.startErasing(J)}onPointerUp(J){this.complete(J)}onCancel(){this.cancel()}onComplete(){this.complete()}onInterrupt(){this.cancel()}startErasing(J){this.parent.transition("erasing",J)}complete(J){let Q=this.editor.getErasingShapeIds();if(Q.length)this.editor.markHistoryStoppingPoint("erase end"),this.editor.deleteShapes(Q);this.parent.transition("idle",J)}cancel(){this.parent.transition("idle")}}class PL extends a{static id="eraser";static initial="idle";static isLockable=!1;static children(){return[hb,ub,gb]}info={};onEnter(J={}){if(this.info=J,J.onInteractionEnd)this.setCurrentToolIdMask(J.onInteractionEnd);this.editor.setCursor({type:"cross",rotation:0})}onExit(){this.setCurrentToolIdMask(void 0),this.info={}}maybeReturnToOriginatingTool(){let{onInteractionEnd:J}=this.info;if(!J)return;this.editor.setCurrentTool(J)}}class mb extends a{static id="dragging";static trackPerformance=!0;initialCamera=new D;onEnter(){this.initialCamera=D.From(this.editor.getCamera()),this.update()}onPointerMove(){this.update()}onPointerDown(){this.parent.transition("idle")}onPointerUp(){this.complete()}onInterrupt(){this.parent.transition("idle")}onCancel(){this.parent.transition("idle")}onComplete(){this.complete()}update(){let{initialCamera:J,editor:Q}=this,Z=Q.inputs.getCurrentScreenPoint(),q=Q.inputs.getOriginScreenPoint(),X=D.Sub(Z,q).div(Q.getZoomLevel());if(X.len2()===0)return;Q.setCamera(J.clone().add(X))}complete(){let{editor:J}=this,Q=J.inputs.getPointerVelocity(),Z=Math.min(Q.len(),2);if(Z>0.1)this.editor.slideCamera({speed:Z,direction:{x:Q.x,y:Q.y,z:0}});this.parent.transition("idle")}}class cb extends a{static id="idle";onEnter(){this.editor.setCursor({type:"grab",rotation:0})}onPointerDown(J){this.parent.transition("pointing",J)}onCancel(){this.editor.setCurrentTool("select")}}class lb extends a{static id="one_finger_zooming";anchorScreenPoint=new D;initialCamera=new D;initialZoom=1;originScreenY=0;onEnter(J){let Q=this.editor.getCamera();this.initialCamera=D.From(Q),this.initialZoom=Q.z,this.anchorScreenPoint=this.editor.inputs.getOriginScreenPoint().clone(),this.originScreenY=this.editor.inputs.getCurrentScreenPoint().y,this.editor.setCursor({type:"grab",rotation:0})}onPointerMove(J){this.editor.menus.clearOpenMenus();let Q=this.editor.inputs.getCurrentScreenPoint().y,Z=(this.originScreenY-Q)*-1,q=Math.pow(2,Z/200),X=this.clampZoom(this.initialZoom*q),{x:K,y:Y}=this.initialCamera,{x:W,y:z}=this.anchorScreenPoint;this.editor.setCamera(new D(K+W/X-W/this.initialZoom,Y+z/X-z/this.initialZoom,X),{immediate:!0})}onPointerUp(J){this.complete()}onCancel(){this.parent.transition("idle")}onInterrupt(){this.parent.transition("idle")}complete(){let J=this.editor.inputs.getPointerVelocity(),Q=Math.min(J.len(),2);if(Q>0.1)this.editor.slideCamera({speed:Q,direction:{x:0,y:0,z:Math.sign(J.y)*0.01}});this.parent.transition("idle")}clampZoom(J){let{zoomSteps:Q}=this.editor.getCameraOptions(),Z=this.editor.getBaseZoom(),q=Q[0]*Z,X=Y6(Q)*Z;return M0(J,q,X)}}class pb extends a{static id="pointing";onEnter(){this.editor.stopCameraAnimation(),this.editor.setCursor({type:"grabbing",rotation:0})}onLongPress(){this.startDragging()}onPointerMove(){if(this.editor.inputs.getIsDragging())this.startDragging()}startDragging(){this.parent.transition("dragging")}onPointerUp(){this.complete()}onCancel(){this.complete()}onComplete(){this.complete()}onInterrupt(){this.complete()}complete(){this.parent.transition("idle")}}class IL extends a{static id="hand";static initial="idle";static isLockable=!1;static children(){return[cb,pb,mb,lb]}onDoubleClick(J){switch(J.phase){case"settle-down":{if(this.editor.getInstanceState().isCoarsePointer)this.transition("one_finger_zooming",J);break}case"settle-up":{let Q=this.editor.inputs.getCurrentScreenPoint();this.editor.zoomIn(Q,{animation:{duration:220,easing:L6.easeOutQuint}});break}}}}class db extends a{static id="idle";onPointerDown(){let J=this.parent.getSessionId(),Q=this.editor.scribbles.addScribbleToSession(J,{color:"laser",opacity:0.7,size:4,taper:!1});this.parent.transition("lasering",{sessionId:J,scribbleId:Q.id})}}class ib extends a{static id="lasering";static trackPerformance=!0;scribbleId="";sessionId="";onEnter(J){this.sessionId=J.sessionId,this.scribbleId=J.scribbleId,this.pushPointToScribble()}onPointerMove(){this.pushPointToScribble()}pushPointToScribble(){let{x:J,y:Q}=this.editor.inputs.getCurrentPagePoint();this.editor.scribbles.addPointToSession(this.sessionId,this.scribbleId,J,Q)}onTick(){this.editor.scribbles.extendSession(this.sessionId)}onPointerUp(){this.complete()}onCancel(){this.onComplete()}onComplete(){this.complete()}complete(){this.editor.scribbles.complete(this.scribbleId),this.parent.transition("idle")}}class wL extends a{static id="laser";static initial="idle";static children(){return[db,ib]}static isLockable=!1;sessionId=null;onEnter(){this.editor.setCursor({type:"cross",rotation:0})}onExit(){this.sessionId=null}onCancel(){if(this.sessionId&&this.editor.scribbles.isSessionActive(this.sessionId))this.editor.scribbles.clearSession(this.sessionId),this.sessionId=null,this.transition("idle");else this.editor.setCurrentTool("select")}getSessionId(){if(this.sessionId&&this.editor.scribbles.isSessionActive(this.sessionId))return this.sessionId;return this.sessionId=this.editor.scribbles.startSession({selfConsume:!1,idleTimeoutMs:this.editor.options.laserDelayMs,fadeMode:"grouped",fadeEasing:"ease-in"}),this.sessionId}}class nb extends a{static id="brushing";static trackPerformance=!0;info={};initialSelectedShapeIds=[];excludedShapeIds=new Set;isWrapMode=!1;viewportDidChange=!1;cleanupViewportChangeReactor(){}onEnter(J){let{editor:Q}=this,Z=Q.inputs.getAltKey();this.isWrapMode=Q.user.getIsWrapMode(),this.viewportDidChange=!1;let q=!0;if(this.cleanupViewportChangeReactor=g1("viewport change while brushing",()=>{if(Q.getViewportPageBounds(),!q&&!this.viewportDidChange)this.viewportDidChange=!0}),Z){this.parent.transition("scribble_brushing",J);return}let X=Q.options.selectLockedShapes;this.excludedShapeIds=new Set(Q.getCurrentPageShapes().filter((K)=>Q.isShapeOfType(K,"group")||!X&&Q.isShapeOrAncestorLocked(K)).map((K)=>K.id)),this.info=J,this.initialSelectedShapeIds=Q.getSelectedShapeIds().slice(),this.hitTestShapes(),q=!1}onExit(){this.initialSelectedShapeIds=[],this.editor.updateInstanceState({brush:null}),this.cleanupViewportChangeReactor()}onTick({elapsed:J}){let{editor:Q}=this;if(!Q.inputs.getIsDragging()||Q.inputs.getIsPanning())return;Q.edgeScrollManager.updateEdgeScrolling(J)}onPointerMove(){this.hitTestShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(J){this.editor.setSelectedShapes(this.initialSelectedShapeIds),this.parent.transition("idle",J)}onKeyDown(J){if(this.editor.inputs.getAltKey())this.parent.transition("scribble_brushing",J);else this.hitTestShapes()}onKeyUp(){this.hitTestShapes()}complete(){this.hitTestShapes(),this.parent.transition("idle")}hitTestShapes(){let{editor:J,excludedShapeIds:Q,isWrapMode:Z}=this,q=J.inputs.getOriginPagePoint(),X=J.inputs.getCurrentPagePoint(),K=J.inputs.getShiftKey(),Y=J.inputs.getCtrlKey(),W=new Set(K?this.initialSelectedShapeIds:[]),z=Z?!Y:Y,G=p.FromPoints([q,X]),{corners:H}=G,$,_,F,U,V,N,B=J.getViewportPageBounds().contains(G),O=J.getCurrentPageId(),M=J.getShapeIdsInsideBounds(G);if(M.size===0){let I=J.getInstanceState().brush;if(!I||!G.equals(I))J.updateInstanceState({brush:{...G.toJson()}});let A=J.getSelectedShapeIds();if(A.length!==W.size||A.some((w)=>!W.has(w)))J.setSelectedShapes(Array.from(W));return}let j=(B&&!this.viewportDidChange?J.getCurrentPageRenderingShapesSorted():J.getCurrentPageShapesSorted()).filter((I)=>M.has(I.id));J:for(let I=0,A=j.length;I<A;I++){if(F=j[I],Q.has(F.id)||W.has(F.id))continue J;if(U=J.getShapePageBounds(F),!U)continue J;if(G.contains(U)){this.handleHit(F,X,O,W,H);continue J}if(z||J.isShapeFrameLike(F))continue J;if(G.collides(U)){if(V=J.getShapePageTransform(F),!V)continue J;N=V.clone().invert().applyToPoints(H);let w=J.getShapeGeometry(F);Q:for(let C=0;C<4;C++)if($=N[C],_=N[(C+1)%4],w.hitTestLineSegment($,_,0)){this.handleHit(F,X,O,W,H);break Q}}}let k=J.getInstanceState().brush;if(!k||!G.equals(k))J.updateInstanceState({brush:{...G.toJson()}});let R=J.getSelectedShapeIds();if(R.length!==W.size||R.some((I)=>!W.has(I)))J.setSelectedShapes(Array.from(W))}onInterrupt(){this.editor.updateInstanceState({brush:null})}handleHit(J,Q,Z,q,X){if(J.parentId===Z){q.add(J.id);return}let K=this.editor.getOutermostSelectableShape(J),Y=this.editor.getShapeMask(K.id);if(Y&&!HG(Y,X)&&!n1(Q,Y))return;q.add(K.id)}}var qJ={bottom:"ns-resize",top:"ns-resize",left:"ew-resize",right:"ew-resize",bottom_left:"nesw-resize",bottom_right:"nwse-resize",top_left:"nwse-resize",top_right:"nesw-resize",bottom_left_rotate:"swne-rotate",bottom_right_rotate:"senw-rotate",top_left_rotate:"nwse-rotate",top_right_rotate:"nesw-rotate",mobile_rotate:"grabbing"};class sb extends a{static id="pointing_resize_handle";info={};updateCursor(){let J=qJ[this.info.handle];this.editor.setCursor({type:J,rotation:this.editor.getSelectionRotation()})}onEnter(J){if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){if(this.editor.inputs.getIsDragging())this.startResizing()}onLongPress(){this.startResizing()}startResizing(){if(this.editor.getIsReadonly())return;this.parent.transition("resizing",this.info)}onPointerUp(){this.complete()}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(J)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,{});else J();return}this.parent.transition("idle")}cancel(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,{});else J();return}this.parent.transition("idle")}}class Y_ extends a{static id="cropping";static trackPerformance=!0;info={};markId="";snapshot={};onEnter(J){if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);this.markId=this.editor.markHistoryStoppingPoint("cropping"),this.snapshot=this.createSnapshot(),this.updateShapes()}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0)}updateCursor(){if(!this.editor.getSelectedShapes()[0])return;let Q=qJ[this.info.handle];this.editor.setCursor({type:Q,rotation:this.editor.getSelectionRotation()})}updateShapes(){let{shape:J,cursorHandleOffset:Q}=this.snapshot;if(!J)return;let Z=this.editor.getShapeUtil(J.type);if(!Z)return;let q=this.editor.inputs.getShiftKey(),X=this.editor.inputs.getCurrentPagePoint().clone().sub(Q),K=this.editor.inputs.getOriginPagePoint().clone().sub(Q),Y=X.clone().sub(K).rot(-J.rotation),W=J.props.crop??s8(),z=k8(J.props,W),H=(Z.onCrop?.bind(Z)??sk)(J,{handle:this.info.handle,change:Y,crop:W,uncroppedSize:z,initialShape:this.snapshot.shape,aspectRatioLocked:q});if(!H)return;this.editor.updateShapes([{id:J.id,type:J.type,...H}]),this.updateCursor()}complete(){this.updateShapes(),z1(this.editor,[this.snapshot.shape.id]);let{onInteractionEnd:J}=this.info;if(J)if(typeof J==="string")this.editor.setCurrentTool(J,this.info);else J();else this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle")}cancel(){this.editor.bailToMark(this.markId);let{onInteractionEnd:J}=this.info;if(J)if(typeof J==="string")this.editor.setCurrentTool(J,this.info);else J();else this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle")}createSnapshot(){let J=this.editor.getSelectionRotation(),Q=this.editor.inputs.getOriginPagePoint(),Z=this.editor.getOnlySelectedShape(),q=this.editor.getSelectionRotatedPageBounds(),X=D.RotWith(q.getHandlePoint(this.info.handle),q.point,J),K=D.Sub(Q,X);return{shape:Z,cursorHandleOffset:K}}}class W_ extends a{static id="pointing_crop_handle";info={};onEnter(J){if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);let Q=this.editor.getSelectedShapes()[0];if(!Q)return;let Z=qJ[this.info.handle];this.editor.setCursor({type:Z,rotation:this.editor.getSelectionRotation()}),this.editor.setCroppingShape(Q.id)}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0)}onPointerMove(){if(this.editor.inputs.getIsDragging())this.startCropping()}onLongPress(){this.startCropping()}startCropping(){if(this.editor.getIsReadonly())return;this.parent.transition("cropping",{...this.info,onInteractionEnd:this.info.onInteractionEnd})}onPointerUp(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,this.info);else J();return}this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle")}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(J)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,this.info);else J();return}this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle")}}function TX(J,Q=!1){let Z=J.getZoomLevel(),q=J.inputs.getCurrentPagePoint();return J.getShapeAtPoint(q,{hitInside:!1,hitLabels:Q,hitLocked:J.options.selectLockedShapes,margin:J.options.hitTestMargin/Z,renderingOnly:!0})??J.getSelectedShapeAtPoint(q)}function AW(J){if(J.isDisposed)return!1;let Q=J.inputs.getCurrentPagePoint(),Z=J.options.hitTestMargin/J.getZoomLevel(),q=J.overlays.getOverlayAtPoint(Q,Z),X=J.overlays.getHoveredOverlayId();if(q){J.overlays.setHoveredOverlay(q.id),J.setHoveredShape(null);let Y=J.overlays.getOverlayUtil(q).getCursor(q);if(Y)J.setCursor({type:Y,rotation:J.getSelectionRotation()});return!0}if(X)J.setCursor({type:"default",rotation:0});return J.overlays.setHoveredOverlay(null),!1}function bL(J,Q,Z){if(!Q)throw Error("Needs to translate a cropped shape!");let{crop:q}=Q.props;if(!q)return;let X=J.inputs.getShiftKey()?Math.abs(Z.x)<Math.abs(Z.y)?"x":"y":null;if(X==="x")Z.x=0;else if(X==="y")Z.y=0;Z.rot(-Q.rotation);let{w:K,h:Y}=k8(Q.props,q),W=q.bottomRight.x-q.topLeft.x,z=q.bottomRight.y-q.topLeft.y,G=H1(q),H=1-W,$=1-z;return G.topLeft.x=M0(G.topLeft.x-Z.x/K,0,H),G.topLeft.y=M0(G.topLeft.y-Z.y/Y,0,$),G.bottomRight.x=G.topLeft.x+W,G.bottomRight.y=G.topLeft.y+z,{id:Q.id,type:Q.type,props:{crop:G}}}class rb extends a{static id="idle";onEnter(){this.editor.setCursor({type:"default",rotation:0});let J=this.editor.getOnlySelectedShape();if(J)this.editor.setCroppingShape(J.id);AW(this.editor)}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){AW(this.editor)}onCancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}onPointerDown(J){if(J.accelKey){this.cancel(),this.editor.root.handleEvent(J);return}switch(J.target){case"canvas":{let Q=this.editor.inputs.getCurrentPagePoint(),Z=this.editor.overlays.getOverlayAtPoint(Q,this.editor.options.hitTestMargin/this.editor.getZoomLevel());if(Z){let X=Z.props.overlayType;if(X==="resize_handle"||X==="rotate_handle"||X==="mobile_rotate"){this.onPointerDown({...J,target:"selection",handle:Z.props.handle});return}}let q=TX(this.editor);if(q&&!this.editor.isShapeOfType(q,"group")){this.onPointerDown({...J,shape:q,target:"shape"});return}this.cancel(),this.editor.root.handleEvent(J);break}case"shape":{if(J.shape.id===this.editor.getCroppingShapeId()){this.editor.setCurrentTool("select.crop.pointing_crop",J);return}else if(this.editor.getShapeUtil(J.shape)?.canCrop(J.shape))this.editor.setCroppingShape(J.shape.id),this.editor.setSelectedShapes([J.shape.id]),this.editor.setCurrentTool("select.crop.pointing_crop",J);else this.cancel(),this.editor.root.handleEvent(J);break}case"selection":{switch(J.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{this.editor.setCurrentTool("select.pointing_rotate_handle",{...J,onInteractionEnd:"select.crop.idle"});break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{this.editor.setCurrentTool("select.crop.pointing_crop_handle",{...J,onInteractionEnd:"select.crop.idle"});break}default:this.cancel()}break}}}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down")return;let Q=this.editor.getCroppingShapeId();if(!Q)return;let Z=this.editor.getShape(Q);if(!Z)return;let q=this.editor.getShapeUtil(Z);if(!q)return;if(J.target==="canvas"){let X=this.editor.inputs.getCurrentPagePoint(),K=this.editor.overlays.getOverlayAtPoint(X,this.editor.options.hitTestMargin/this.editor.getZoomLevel());if(K){let Y=K.props.overlayType;if(Y==="resize_handle"||Y==="rotate_handle"||Y==="mobile_rotate"){this.onDoubleClick({...J,target:"selection",handle:K.props.handle});return}}}if(J.target==="selection"){q.onDoubleClickEdge?.(Z,J);return}this.cancel(),this.editor.root.handleEvent(J)}onKeyDown(){this.nudgeCroppingImage(!1)}onKeyRepeat(){this.nudgeCroppingImage(!0)}onKeyUp(J){switch(J.key){case"Enter":{this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{});break}}}cancel(){this.editor.setCroppingShape(null),this.editor.setCurrentTool("select.idle",{})}nudgeCroppingImage(J=!1){let{editor:{inputs:{keys:Q}}}=this,Z=Q.has("ShiftLeft"),q=new D(0,0);if(Q.has("ArrowLeft"))q.x+=1;if(Q.has("ArrowRight"))q.x-=1;if(Q.has("ArrowUp"))q.y+=1;if(Q.has("ArrowDown"))q.y-=1;if(q.equals(new D(0,0)))return;if(Z)q.mul(10);let X=this.editor.getShape(this.editor.getCroppingShapeId());if(!X)return;let K=bL(this.editor,X,q);if(K){if(!J)this.editor.markHistoryStoppingPoint("translate crop");this.editor.updateShapes([K])}}}class ab extends a{static id="pointing_crop";onCancel(){this.editor.setCurrentTool("select.crop.idle",{})}onPointerMove(J){if(this.editor.inputs.getIsDragging())this.startDragging(J)}onLongPress(J){this.startDragging(J)}onPointerUp(J){this.editor.setCurrentTool("select.crop.idle",J)}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(J)}startDragging(J){this.editor.setCurrentTool("select.crop.translating_crop",J)}}class ob extends a{static id="translating_crop";info={};markId="";snapshot={};onEnter(J){this.info=J,this.snapshot=this.createSnapshot(),this.markId=this.editor.markHistoryStoppingPoint("translating_crop"),this.editor.setCursor({type:"move",rotation:0}),this.updateShapes()}onExit(){this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}onKeyDown(J){switch(J.key){case"Alt":case"Shift":{this.updateShapes();return}}}onKeyUp(J){switch(J.key){case"Enter":{this.complete();return}case"Alt":case"Shift":this.updateShapes()}}complete(){this.updateShapes(),this.editor.setCurrentTool("select.crop.idle",this.info)}cancel(){this.editor.bailToMark(this.markId),this.editor.setCurrentTool("select.crop.idle",this.info)}createSnapshot(){return{shape:this.editor.getOnlySelectedShape()}}updateShapes(){let J=this.snapshot.shape;if(!J)return;let Q=this.editor.inputs.getOriginPagePoint(),q=this.editor.inputs.getCurrentPagePoint().clone().sub(Q),X=bL(this.editor,J,q);if(X)this.editor.updateShapes([X])}}class tb extends a{static id="crop";static initial="idle";static children(){return[rb,ob,ab,W_,Y_]}markId="";onEnter(){this.didExit=!1,this.markId=this.editor.markHistoryStoppingPoint("crop")}didExit=!1;onExit(){if(!this.didExit){if(this.didExit=!0,this.editor.getMarkIdMatching(this.markId)===this.markId)this.editor.squashToMark(this.markId)}}onCancel(){if(!this.didExit)this.didExit=!0,this.editor.bailToMark(this.markId)}}class eb extends a{static id="dragging_handle";static trackPerformance=!0;shapeId;initialHandle;initialAdjacentHandle;initialPagePoint;markId;initialPageTransform;initialPageRotation;info;isPrecise=!1;isPreciseId=null;pointingId=null;onEnter(J){let{shape:Q,isCreating:Z,creatingMarkId:q,handle:X}=J;if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);if(this.shapeId=Q.id,this.markId="",Z)if(q)this.markId=q;else{let H=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);if(H)this.markId=H}else this.markId=this.editor.markHistoryStoppingPoint("dragging handle");this.initialHandle=H1(X),this.initialPageTransform=this.editor.getShapePageTransform(Q),this.initialPageRotation=this.initialPageTransform.rotation(),this.initialPagePoint=this.editor.inputs.getOriginPagePoint().clone(),this.editor.setCursor({type:Z?"cross":"grabbing",rotation:0});let K=this.editor.getShapeHandles(Q).sort(L4),Y=K.findIndex((H)=>H.id===J.handle.id);if(this.initialAdjacentHandle=null,J.handle.snapReferenceHandleId){let H=K.find(($)=>$.id===J.handle.snapReferenceHandleId);if(H)this.initialAdjacentHandle=H}if(!this.initialAdjacentHandle){for(let H=Y+1;H<K.length;H++){let $=K[H];if($.type==="vertex"&&$.id!=="middle"&&$.id!==J.handle.id){this.initialAdjacentHandle=$;break}}if(!this.initialAdjacentHandle)for(let H=K.length-1;H>=0;H--){let $=K[H];if($.type==="vertex"&&$.id!=="middle"&&$.id!==J.handle.id){this.initialAdjacentHandle=$;break}}}if(this.editor.isShapeOfType(Q,"arrow")){let H=Z4(this.editor,Q)[J.handle.id];if(this.isPrecise=!1,H)if(this.isPrecise=H.props.isPrecise,this.isPrecise)this.isPreciseId=H.toId;else this.resetExactTimeout()}let W={handle:this.initialHandle,isPrecise:this.isPrecise,isCreatingShape:!!this.info.isCreating,initial:Q},G=this.editor.getShapeUtil(Q).onHandleDragStart?.(Q,W);if(G)this.editor.updateShapes([{...G,id:Q.id,type:Q.type}]);this.update(),this.editor.select(this.shapeId)}exactTimeout=-1;resetExactTimeout(){let Q=this.editor.getShapeUtil("arrow").options.pointingPreciseTimeout;if(this.exactTimeout!==-1)this.clearExactTimeout();this.exactTimeout=this.editor.timers.setTimeout(()=>{if(this.getIsActive()&&!this.isPrecise)this.isPrecise=!0,this.isPreciseId=this.pointingId,this.update();this.exactTimeout=-1},Q)}clearExactTimeout(){if(this.exactTimeout!==-1)clearTimeout(this.exactTimeout),this.exactTimeout=-1}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.update(),this.complete()}onCancel(){this.cancel()}onExit(){this.parent.setCurrentToolIdMask(void 0),jX(this.editor),this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0})}complete(){this.editor.snaps.clearIndicators(),z1(this.editor,[this.shapeId]);let J=this.editor.getShape(this.shapeId);if(J){let Z=this.editor.getShapeUtil(J),q={handle:this.initialHandle,isPrecise:this.isPrecise,isCreatingShape:!!this.info.isCreating,initial:this.info.shape},X=Z.onHandleDragEnd?.(J,q);if(X)this.editor.updateShapes([{...X,id:J.id}])}let{onInteractionEnd:Q}=this.info;if(Q)if(typeof Q==="string"){if(this.editor.getInstanceState().isToolLocked&&Q){this.editor.setCurrentTool(Q,{shapeId:this.shapeId});return}}else{Q?.();return}this.parent.transition("idle")}cancel(){let J=this.editor.getShape(this.shapeId);if(J){let Z=this.editor.getShapeUtil(J),q={handle:this.initialHandle,isPrecise:this.isPrecise,isCreatingShape:!!this.info.isCreating,initial:this.info.shape};Z.onHandleDragCancel?.(J,q)}this.editor.bailToMark(this.markId),this.editor.snaps.clearIndicators();let{onInteractionEnd:Q}=this.info;if(Q){if(typeof Q==="string")this.editor.setCurrentTool(Q,{shapeId:this.shapeId});else Q?.();return}this.parent.transition("idle")}update(){let{editor:J,shapeId:Q,initialPagePoint:Z}=this,{initialHandle:q,initialPageRotation:X,initialAdjacentHandle:K}=this,Y=this.editor.user.getIsSnapMode(),{snaps:W}=J,z=J.inputs.getCurrentPagePoint(),G=J.inputs.getShiftKey(),H=J.inputs.getCtrlKey(),$=J.inputs.getAltKey(),_=J.inputs.getPointerVelocity(),F=this.info.shape,U=J.getShape(Q);if(!U)return;let V=J.getShapeUtil(U),N=J.isShapeOfType(U,"arrow")?Z4(J,U)[q.id]:void 0,B=z.clone().sub(Z).rot(-X).add(q);if(G&&K&&q.id!=="middle"){let k=D.Angle(K,B),I=XZ(k,24)-k;B=D.RotWith(B,K,I)}J.snaps.clearIndicators();let O={...q,x:B.x,y:B.y},M=!1;if(q.canSnap&&q.snapType)eX("canSnap is deprecated. Cannot use both canSnap and snapType together - snapping disabled. Please use only snapType.");else M=q.canSnap||q.snapType!==void 0;if(M&&(Y?!H:H)){if(!J.getShapePageTransform(U.id))throw Error("Expected a page transform");let R=W.handles.snapHandle({currentShapeId:Q,handle:O});if(R)R.nudge.rot(-J.getShapeParentTransform(U).rotation()),B.add(R.nudge),O={...q,x:B.x,y:B.y}}let L=V.onHandleDrag?.(U,{handle:O,isPrecise:this.isPrecise||$,isCreatingShape:!!this.info.isCreating,initial:F}),j={id:U.id,type:U.type,...L};if(q.type==="vertex"&&this.editor.isShapeOfType(U,"arrow")){let k=Z4(J,U)[q.id];if(k){if(N?.toId!==k.toId)this.pointingId=k.toId,this.isPrecise=_.len()<0.5||$,this.isPreciseId=this.isPrecise?k.toId:null,this.resetExactTimeout()}else if(N)this.pointingId=null,this.isPrecise=!1,this.isPreciseId=null,this.resetExactTimeout()}if(L)J.updateShapes([j])}}function TL(J){if(J.isLabel)return[J];if(J instanceof y4)return J.children.filter((Q)=>Q.isLabel);return[]}class JT extends a{static id="editing_shape";hitLabelOnShapeForPointerUp=null;info={};didPointerDownOnEditingShape=!1;isTextInputFocused(){let J=this.editor.getContainer(),Q=this.editor.getContainerDocument();return J.contains(Q.activeElement)&&RJ(!1,Q)}onEnter(J){let Q=this.editor.getEditingShape();if(!Q)throw Error("Entered editing state without an editing shape");if(this.hitLabelOnShapeForPointerUp=null,this.didPointerDownOnEditingShape=!1,this.info=J,J.isCreatingTextWhileToolLocked)this.parent.setCurrentToolIdMask("text");this.editor.setCursor({type:"default",rotation:0}),W2(this.editor),this.editor.select(Q)}onExit(){let J=!!this.editor.getEditingShapeId();if(this.editor.setEditingShape(null),Vq(this.editor),this.info.isCreatingTextWhileToolLocked&&J)this.parent.setCurrentToolIdMask(void 0),this.editor.setCurrentTool("text",{})}onPointerMove(J){if(this.hitLabelOnShapeForPointerUp&&this.editor.inputs.getIsDragging()){if(this.editor.getIsReadonly())return;if(this.hitLabelOnShapeForPointerUp.isLocked)return;this.editor.select(this.hitLabelOnShapeForPointerUp),this.parent.transition("translating",J),this.hitLabelOnShapeForPointerUp=null;return}if(this.didPointerDownOnEditingShape&&this.editor.inputs.isDragging){if(this.editor.getIsReadonly())return;let Q=this.editor.getEditingShape();if(!Q||Q.isLocked)return;if(!this.isTextInputFocused()){this.editor.select(Q),this.parent.transition("translating",J),this.didPointerDownOnEditingShape=!1;return}this.didPointerDownOnEditingShape=!1}switch(J.target){case"shape":case"canvas":{W2(this.editor);return}}}onPointerDown(J){switch(this.hitLabelOnShapeForPointerUp=null,this.didPointerDownOnEditingShape=!1,J.target){case"canvas":{let Q=TX(this.editor,!0);if(Q){this.onPointerDown({...J,shape:Q,target:"shape"});return}break}case"shape":{let{shape:Q}=J,Z=this.editor.getEditingShape();if(!Z)throw Error("Expected an editing shape!");let q=this.editor.getShapeUtil(Q).getGeometry(Q),X=TL(q),K=X.length===1?X[0]:void 0,Y=this.editor.isShapeOfType(Z,"text")&&f9(this.editor,Z.props.richText).trim()==="";if(K&&!Y){let W=this.editor.getPointInShapeSpace(Q,this.editor.inputs.getCurrentPagePoint());if(K.bounds.containsPoint(W,0)&&K.hitTestPoint(W))if(Q.id===Z.id){this.didPointerDownOnEditingShape=!0;return}else{this.hitLabelOnShapeForPointerUp=Q,this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(Q.id);return}}else{if(Q.id===Z.id){if(this.editor.isShapeFrameLike(Q))this.editor.setEditingShape(null),this.parent.transition("idle",J)}else{this.parent.transition("pointing_shape",J);return}return}break}}this.parent.transition("idle",J),this.editor.root.handleEvent(J)}onPointerUp(J){if(this.didPointerDownOnEditingShape){if(this.didPointerDownOnEditingShape=!1,!this.isTextInputFocused()){this.editor.getRichTextEditor()?.commands.focus("all");return}}let Q=this.hitLabelOnShapeForPointerUp;if(!Q)return;this.hitLabelOnShapeForPointerUp=null;let Z=this.editor.getShapeUtil(Q);if(Q.isLocked)return;if(this.editor.getIsReadonly()){if(!Z.canEditInReadonly(Q)){this.parent.transition("pointing_shape",J);return}}this.editor.select(Q.id);let q=this.editor.getEditingShape(),X=q&&q.id!==Q.id;this.editor.setEditingShape(Q.id);let K=S0.isIos||S0.isAndroid;if(!K||!X)this.editor.emit("place-caret",{shapeId:Q.id,point:J.point});else if(K&&X)this.editor.emit("select-all-text",{shapeId:Q.id});W2(this.editor)}onComplete(J){this.editor.getContainer().focus(),this.parent.transition("idle",J)}onCancel(J){this.editor.getContainer().focus(),this.parent.transition("idle",J)}}function yX(J,Q){let Z=J.getSelectedShapeIds(),q=J.inputs.getCurrentPagePoint(),{shiftKey:X,altKey:K,accelKey:Y}=Q,W=X||Y,z=J.options.selectLockedShapes,G=J.getShapeAtPoint(q,{hitInside:!1,margin:J.options.hitTestMargin/J.getZoomLevel(),hitLabels:!0,hitLocked:z,renderingOnly:!0,filter:(H)=>z||!H.isLocked});if(G){let H=J.getOutermostSelectableShape(G);if(W&&!K)if(J.cancelDoubleClick(),Z.includes(H.id))J.markHistoryStoppingPoint("deselecting shape"),J.deselect(H);else J.markHistoryStoppingPoint("shift selecting shape"),J.setSelectedShapes([...Z,H.id]);else{let $=void 0;if(H===G)$=G;else if(H.id===J.getFocusedGroupId()||Z.includes(H.id))$=G;else $=H;if($&&!Z.includes($.id))J.markHistoryStoppingPoint("selecting shape"),J.select($.id)}}else if(W)return;else{if(Z.length>0)J.markHistoryStoppingPoint("selecting none"),J.selectNone();let H=J.getFocusedGroupId();if(H4(H)){let $=J.getShape(H);if(!J.isPointInShape($,q,{margin:0,hitInside:!0}))J.setFocusedGroup(null)}}}var EN0=["Delete","Backspace","[","]","Enter"," ","Shift","Tab"];class QT extends a{static id="idle";selectedShapesOnKeyDown=[];onEnter(){if(this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),!AW(this.editor))W2(this.editor);this.selectedShapesOnKeyDown=[]}onExit(){this.editor.updateInstanceState({isChangingStyle:!1}),Vq(this.editor)}onPointerMove(){if(!AW(this.editor))W2(this.editor);if(x5(()=>this.editor.getInstanceState()).isChangingStyle)this.editor.updateInstanceState({isChangingStyle:!1})}onPointerDown(J){switch(J.target){case"canvas":{let Q=this.editor.inputs.getCurrentPagePoint(),Z=this.editor.overlays.getOverlayAtPoint(Q,this.editor.options.hitTestMargin/this.editor.getZoomLevel());if(Z){this.onPointerDown({...J,target:"overlay",overlay:Z});return}let q=TX(this.editor);if(q&&(this.editor.options.selectLockedShapes||!q.isLocked)){this.onPointerDown({...J,shape:q,target:"shape"});return}let X=this.editor.getSelectedShapeIds(),K=this.editor.getOnlySelectedShape();if(X.length>1||K&&!this.editor.getShapeUtil(K).hideSelectionBoundsBg(K)){if(re(this.editor,Q)){this.onPointerDown({...J,target:"selection"});return}}this.parent.transition("pointing_canvas",J);break}case"overlay":{let{overlay:Q}=J,Z=this.editor.overlays.getOverlayUtil(Q);if(Z.onPointerDown){if(Z.onPointerDown(Q,J)!==!1)return}let q=Q.props.overlayType;if(Q.type==="shape_handle"){let X=this.editor.getShape(Q.props.shapeId);if(X)this.onPointerDown({...J,target:"handle",shape:X,handle:Q.props.handle})}else switch(q){case"rotate_handle":{this.onPointerDown({...J,target:"selection",handle:Q.props.handle});break}case"mobile_rotate":{this.onPointerDown({...J,target:"selection",handle:Q.props.handle});break}case"resize_handle":{this.onPointerDown({...J,target:"selection",handle:Q.props.handle});break}default:this.onPointerDown({...J,target:"selection"})}break}case"shape":{let{shape:Q}=J;if(!this.editor.options.selectLockedShapes&&this.editor.isShapeOrAncestorLocked(Q)){this.parent.transition("pointing_canvas",J);break}this.parent.transition("pointing_shape",J);break}case"handle":{if(this.editor.getIsReadonly())break;if(this.editor.inputs.getAltKey())this.parent.transition("pointing_shape",J);else this.parent.transition("pointing_handle",J);break}case"selection":{switch(J.handle){case"mobile_rotate":case"top_left_rotate":case"top_right_rotate":case"bottom_left_rotate":case"bottom_right_rotate":{if(J.accelKey){this.parent.transition("brushing",J);break}this.parent.transition("pointing_rotate_handle",J);break}case"top":case"right":case"bottom":case"left":case"top_left":case"top_right":case"bottom_left":case"bottom_right":{let Q=this.editor.getOnlySelectedShape();if(J.ctrlKey&&this.editor.canCropShape(Q))this.parent.transition("crop.pointing_crop_handle",J);else{if(J.accelKey){this.parent.transition("brushing",J);break}this.parent.transition("pointing_resize_handle",J)}break}default:{let Q=this.editor.getHoveredShape();if(Q&&!this.editor.getSelectedShapeIds().includes(Q.id)&&(this.editor.options.selectLockedShapes||!Q.isLocked)){this.onPointerDown({...J,shape:Q,target:"shape"});return}this.parent.transition("pointing_selection",J)}}break}}}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down")return;if(J.ctrlKey||J.shiftKey)return;switch(J.target){case"canvas":{let Q=this.editor.inputs.getCurrentPagePoint(),Z=this.editor.overlays.getOverlayAtPoint(Q,this.editor.options.hitTestMargin/this.editor.getZoomLevel());if(Z){if(Z.type==="shape_handle"){let Y=this.editor.getShape(Z.props.shapeId);if(Y){this.onDoubleClick({...J,target:"handle",shape:Y,handle:Z.props.handle});return}}let K=Z.props.overlayType;if(K==="resize_handle"||K==="rotate_handle"||K==="mobile_rotate"){this.onDoubleClick({...J,target:"selection",handle:Z.props.handle});return}}let q=this.editor.getHoveredShape(),X=q&&!this.editor.isShapeOfType(q,"group")?q:this.editor.getSelectedShapeAtPoint(Q)??this.editor.getShapeAtPoint(Q,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1});if(X){if(this.editor.isShapeOfType(X,"group")){yX(this.editor,J);return}else{let K=this.editor.getShape(X.parentId);if(K&&this.editor.isShapeOfType(K,"group")){let Y=this.editor.getFocusedGroupId();if(Y&&K.id===Y);else{yX(this.editor,J);return}}}this.onDoubleClick({...J,shape:X,target:"shape"});return}if(!this.editor.inputs.getShiftKey())this.handleDoubleClickOnCanvas(J);break}case"selection":{let Q=this.editor.getOnlySelectedShape();if(Q){let Z=this.editor.getShapeUtil(Q),q=J.handle==="right"||J.handle==="left"||J.handle==="top"||J.handle==="bottom",X=J.handle==="top_left"||J.handle==="top_right"||J.handle==="bottom_right"||J.handle==="bottom_left";if(this.editor.getIsReadonly()){if(this.editor.canEditShape(Q,{type:X?"double-click-corner":q?"double-click-edge":"double-click"}))this.startEditingShape(Q,J,!0);break}if(q){let K=Z.onDoubleClickEdge?.(Q,J);if(K){this.editor.markHistoryStoppingPoint("double click edge"),this.editor.updateShapes([K]),z1(this.editor,[Q.id]);return}}if(X){let K=Z.onDoubleClickCorner?.(Q,J);if(K){this.editor.markHistoryStoppingPoint("double click corner"),this.editor.updateShapes([K]),z1(this.editor,[Q.id]);return}}if(this.editor.canCropShape(Q)){this.parent.transition("crop",J);return}if(this.editor.canEditShape(Q))this.startEditingShape(Q,J,!0)}break}case"shape":{let{shape:Q}=J,Z=this.editor.getShapeUtil(Q);if(Q.type!=="video"&&Q.type!=="embed"&&this.editor.getIsReadonly())break;if(Z.onDoubleClick){let q=Z.onDoubleClick?.(Q);if(q){this.editor.updateShapes([q]);return}}if(Z.canCrop(Q)&&!this.editor.isShapeOrAncestorLocked(Q)){this.editor.markHistoryStoppingPoint("select and crop"),this.editor.select(J.shape?.id),this.parent.transition("crop",J);return}if(this.editor.canEditShape(Q))this.startEditingShape(Q,J,!0);else this.handleDoubleClickOnCanvas(J);break}case"handle":{if(this.editor.getIsReadonly())break;let{shape:Q,handle:Z}=J,X=this.editor.getShapeUtil(Q).onDoubleClickHandle?.(Q,Z);if(X)this.editor.updateShapes([X]);else if(this.editor.canEditShape(Q))this.startEditingShape(Q,J,!0)}}}onRightClick(J){switch(J.target){case"canvas":{let Q=this.editor.getSelectedShapeIds(),Z=this.editor.getOnlySelectedShape(),q=this.editor.inputs.getCurrentPagePoint();if(Q.length>1||Z&&!this.editor.getShapeUtil(Z).hideSelectionBoundsBg(Z)){if(re(this.editor,q)){this.onRightClick({...J,target:"selection"});return}}let X=this.editor.getHoveredShape(),K=X&&!this.editor.isShapeOfType(X,"group")?X:this.editor.getShapeAtPoint(q,{margin:this.editor.options.hitTestMargin/this.editor.getZoomLevel(),hitInside:!1,hitLabels:!0,hitLocked:!0,hitFrameInside:!0,renderingOnly:!0});if(K){this.onRightClick({...J,shape:K,target:"shape"});return}this.editor.selectNone();break}case"shape":{let{selectedShapeIds:Q}=this.editor.getCurrentPageState(),{shape:Z}=J,q=this.editor.getOutermostSelectableShape(Z,(X)=>!Q.includes(X.id));if(!Q.includes(q.id)&&!this.editor.findShapeAncestor(q,(X)=>Q.includes(X.id)))this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([q.id]);break}}}onCancel(){if(this.editor.getFocusedGroupId()!==this.editor.getCurrentPageId()&&this.editor.getSelectedShapeIds().length>0)this.editor.popFocusedGroupId();else this.editor.markHistoryStoppingPoint("clearing selection"),this.editor.selectNone()}onKeyDown(J){switch(this.selectedShapesOnKeyDown=this.editor.getSelectedShapes(),J.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(J.accelKey){if(J.shiftKey){if(J.code==="ArrowDown")this.editor.selectFirstChildShape();else if(J.code==="ArrowUp")this.editor.selectParentShape()}else this.editor.selectAdjacentShape(J.code.replace("Arrow","").toLowerCase());return}this.nudgeSelectedShapes(!1);return}}if(V1.editOnType.get()){if(!EN0.includes(J.key)&&!J.altKey&&!J.ctrlKey){let Q=this.editor.getOnlySelectedShape();if(Q&&this.editor.isShapeOfType(Q,"note")&&this.editor.canEditShape(Q)){this.startEditingShape(Q,{...J,target:"shape",shape:Q},!0);return}}}}onKeyRepeat(J){switch(J.code){case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"ArrowDown":{if(J.accelKey){this.editor.selectAdjacentShape(J.code.replace("Arrow","").toLowerCase());return}this.nudgeSelectedShapes(!0);break}case"Tab":{if(this.editor.getSelectedShapes().length&&!J.altKey)this.editor.selectAdjacentShape(J.shiftKey?"prev":"next");break}}}onKeyUp(J){switch(J.key){case"Enter":{if(!this.selectedShapesOnKeyDown.length)return;let Q=this.editor.getSelectedShapes();if(Q.every((q)=>this.editor.isShapeOfType(q,"group"))){this.editor.setSelectedShapes(Q.flatMap((q)=>this.editor.getSortedChildIdsForParent(q.id)));return}let Z=this.editor.getOnlySelectedShape();if(Z&&this.editor.canEditShape(Z,{type:"press_enter"})){this.startEditingShape(Z,{...J,target:"shape",shape:Z},!0);return}if(this.editor.canCropShape(Z))this.parent.transition("crop",J);break}case"Tab":{if(this.editor.getSelectedShapes().length&&!J.altKey)this.editor.selectAdjacentShape(J.shiftKey?"prev":"next");break}}}startEditingShape(J,Q,Z){let{editor:q}=this;if(this.editor.markHistoryStoppingPoint("editing shape"),hk(J))S4(q,J,{selectAll:Z});else q.setEditingShape(J);this.parent.transition("editing_shape",Q)}isOverArrowLabelTest(J){if(!J)return!1;return ZL(this.editor,J)}handleDoubleClickOnCanvas(J){if(this.editor.getIsReadonly())return;if(!this.editor.options.createTextOnCanvasDoubleClick)return;this.editor.markHistoryStoppingPoint("creating text shape");let Q=l0(),{x:Z,y:q}=this.editor.inputs.getCurrentPagePoint();this.editor.createShapes([{id:Q,type:"text",x:Z,y:q,props:{richText:y1(""),autoSize:!0}}]);let X=this.editor.getShape(Q);if(!X)return;if(!this.editor.canEditShape(X))return;S4(this.editor,Q,{info:J})}nudgeSelectedShapes(J=!1){let{editor:{inputs:{keys:Q}}}=this,Z=Q.has("ShiftLeft"),q=new D(0,0);if(Q.has("ArrowLeft"))q.x-=1;if(Q.has("ArrowRight"))q.x+=1;if(Q.has("ArrowUp"))q.y-=1;if(Q.has("ArrowDown"))q.y+=1;if(q.equals(new D(0,0)))return;if(!J)this.editor.markHistoryStoppingPoint("nudge shapes");this.editor.updateInstanceState({isChangingStyle:!0});let{gridSize:X}=this.editor.getDocumentSettings(),K=this.editor.getInstanceState().isGridMode?Z?X*PN0:X:Z?AN0:CN0,Y=this.editor.getSelectedShapeIds();this.editor.nudgeShapes(Y,q.mul(K)),z1(this.editor,Y)}}var AN0=10,CN0=1,PN0=5;function re(J,Q){let Z=J.getSelectionRotatedPageBounds();if(!Z)return!1;let q=J.getSelectionRotation();if(!q)return Z.containsPoint(Q);return n1(Q,Z.corners.map((X)=>D.RotWith(X,Z.point,q)))}class ZT extends a{static id="pointing_arrow_label";shapeId="";markId="";wasAlreadySelected=!1;didDrag=!1;didCtrlOnEnter=!1;info={};updateCursor(){this.editor.setCursor({type:"grabbing",rotation:0})}onEnter(J){let{shape:Q}=J;if(typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);this.info=J,this.shapeId=Q.id,this.didDrag=!1,this.didCtrlOnEnter=J.accelKey,this.wasAlreadySelected=this.editor.getOnlySelectedShapeId()===Q.id,this.updateCursor();let q=this.editor.getShapeGeometry(Q).children[1];if(!q)throw Error(`Expected to find an arrow label geometry for shape: ${Q.id}`);let X=this.editor.inputs.getCurrentPagePoint(),K=this.editor.getPointInShapeSpace(Q,X);if(this._labelDragOffset=D.Sub(q.center,K),this.markId=this.editor.markHistoryStoppingPoint("label-drag start"),J.shiftKey||J.accelKey){let W=this.editor.getSelectedShapeIds();this.editor.setSelectedShapes([...W,this.shapeId]);return}this.editor.setSelectedShapes([this.shapeId])}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}_labelDragOffset=new D(0,0);onPointerMove(){if(!this.editor.inputs.getIsDragging())return;if(this.didCtrlOnEnter){this.parent.transition("brushing",this.info);return}let Q=this.editor.getShape(this.shapeId);if(!Q)return;let Z=this.editor.getShapeUtil("arrow").options,q=PX(this.editor,Q),X=this.editor.getShapePageTransform(Q.id),K=this.editor.getPointInShapeSpace(Q,this.editor.inputs.getCurrentPagePoint()).add(this._labelDragOffset),Y=QL(this.editor,Q),W=q.uninterpolateAlongEdge(K);if(isNaN(W))W=Y;let z=X.applyToPoint(q.interpolateAlongEdge(W)),G=X.applyToPoint(q.interpolateAlongEdge(Y));if(D.DistMin(z,G,Z.labelCenterSnapDistance/this.editor.getZoomLevel()))W=Y;this.didDrag=!0,this.editor.updateShape({id:Q.id,type:Q.type,props:{labelPosition:W}})}onPointerUp(){let J=this.editor.getShape(this.shapeId);if(!J)return;if(this.didDrag||!this.wasAlreadySelected)this.complete();else if(this.editor.canEditShape(J))S4(this.editor,J.id)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,{});else J();return}this.parent.transition("idle")}cancel(){this.editor.bailToMark(this.markId);let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,{});else J();return}this.parent.transition("idle")}}class qT extends a{static id="pointing_canvas";onEnter(J){if(!(J.shiftKey||J.accelKey)){if(this.editor.getSelectedShapeIds().length>0)this.editor.markHistoryStoppingPoint("selecting none"),this.editor.selectNone()}}onPointerMove(J){if(this.editor.inputs.getIsDragging())this.parent.transition("brushing",J)}onPointerUp(J){yX(this.editor,J),this.complete()}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(J)}onComplete(){this.complete()}onInterrupt(){this.parent.transition("idle")}complete(){this.parent.transition("idle")}}class XT extends a{static id="pointing_handle";didCtrlOnEnter=!1;info={};isDoubleClick=!1;onEnter(J){this.info=J,this.isDoubleClick=!1,this.didCtrlOnEnter=J.accelKey;let{shape:Q}=J;if(this.editor.isShapeOfType(Q,"arrow")){let Z=Z4(this.editor,Q),q=Z[J.handle.id],X=Z[J.handle.id==="start"?"end":"start"],K=this.editor.getShapePageTransform(Q.id);if(q)OQ({editor:this.editor,pointInPageSpace:K.applyToPoint(J.handle),arrow:Q,isPrecise:q.props.isPrecise,currentBinding:q,oppositeBinding:X})}this.editor.setCursor({type:"grabbing",rotation:0})}onExit(){this.editor.setHintingShapes([]),this.editor.setCursor({type:"default",rotation:0})}onPointerUp(){let{shape:J,handle:Q}=this.info;if(this.isDoubleClick){this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent({...this.info,type:"click",name:"double_click",phase:"down"});return}if(this.editor.isShapeOfType(J,"note")){let{editor:Z}=this,q=ae(Z,J,Q,!1);if(q){S4(Z,q,{selectAll:!0});return}}this.parent.transition("idle",this.info)}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;this.isDoubleClick=!0}onPointerMove(J){let{editor:Q}=this;if(Q.inputs.getIsDragging())if(this.didCtrlOnEnter)this.parent.transition("brushing",J);else this.startDraggingHandle()}onLongPress(){this.startDraggingHandle()}startDraggingHandle(){let{editor:J}=this;if(J.getIsReadonly())return;let{shape:Q,handle:Z}=this.info;if(J.isShapeOfType(Q,"note")){let q=J.getShapeUtil(Q),X=k0(q,Q),K=ae(J,Q,Z,!0);if(K){let Y=J.getPointInParentSpace(K,J.inputs.getOriginPagePoint()).sub(D.Rot(new D(X.noteWidth/2,X.noteHeight/2).mul(Q.props.scale),K.rotation));J.updateShape({...K,x:Y.x,y:Y.y}),J.setHoveredShape(K.id).select(K.id).setCurrentTool("select.translating",{...this.info,target:"shape",shape:J.getShape(K),onInteractionEnd:"note",isCreating:!0,onCreate:()=>{S4(J,K,{selectAll:!0})}});return}}this.parent.transition("dragging_handle",this.info)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}function ae(J,Q,Z,q){let X=J.getShapeUtil(Q),K=k0(X,Q),Y=J.getShapePageTransform(Q.id),W=Y.point(),z=Y.rotation(),H=Zb(J,{pagePoint:W,pageRotation:z,growY:Q.props.growY*Q.props.scale,extraHeight:0,scale:Q.props.scale,noteWidth:K.noteWidth,noteHeight:K.noteHeight})[Z.index];if(H)return aO(J,{shape:Q,center:H,pageRotation:z,noteWidth:K.noteWidth,noteHeight:K.noteHeight,forceNew:q});return}class KT extends a{static id="pointing_rotate_handle";info={};updateCursor(){this.editor.setCursor({type:qJ[this.info.handle],rotation:this.editor.getSelectionRotation()})}onEnter(J){if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0})}onPointerMove(){if(this.editor.inputs.getIsDragging())this.startRotating()}onLongPress(){this.startRotating()}startRotating(){if(this.editor.getIsReadonly())return;this.parent.transition("rotating",this.info)}onPointerUp(){this.complete()}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent(J)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}complete(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,{});else J?.();return}this.parent.transition("idle")}cancel(){let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,{});else J();return}this.parent.transition("idle")}}class YT extends a{static id="pointing_selection";info={};onEnter(J){this.info=J}onPointerUp(J){yX(this.editor,J),this.parent.transition("idle",J)}onPointerMove(J){if(this.editor.inputs.getIsDragging())this.startTranslating(J)}onLongPress(J){this.startTranslating(J)}startTranslating(J){if(this.editor.getIsReadonly())return;this.parent.transition("translating",J)}onDoubleClick(J){if(this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;let Q=this.editor.getHoveredShape(),Z=Q&&!this.editor.isShapeOfType(Q,"group")?Q:this.editor.getShapeAtPoint(this.editor.inputs.getCurrentPagePoint(),{hitInside:!0,margin:0,renderingOnly:!0});if(Z){this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent({...J,target:"shape",shape:this.editor.getShape(Z)});return}}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}class WT extends a{static id="pointing_shape";hitShape={};hitShapeForPointerUp={};isDoubleClick=!1;didCtrlOnEnter=!1;didSelectOnEnter=!1;onEnter(J){let Q=this.editor.getSelectedShapeIds(),Z=this.editor.getSelectionRotatedPageBounds(),q=this.editor.getFocusedGroupId(),X=this.editor.inputs.getCurrentPagePoint(),{shiftKey:K,altKey:Y,accelKey:W}=J;this.hitShape=J.shape,this.isDoubleClick=!1,this.didCtrlOnEnter=W;let z=this.editor.getOutermostSelectableShape(J.shape),G=this.editor.findShapeAncestor(z,(H)=>Q.includes(H.id));if(this.didCtrlOnEnter||this.editor.getShapeUtil(J.shape).onClick||z.id===q||Q.includes(z.id)||G||Q.length>1&&Z?.containsPoint(X)){this.didSelectOnEnter=!1,this.hitShapeForPointerUp=z;return}if(this.didSelectOnEnter=!0,K&&!Y){if(this.editor.cancelDoubleClick(),!Q.includes(z.id))this.editor.markHistoryStoppingPoint("shift selecting shape"),this.editor.setSelectedShapes([...Q,z.id])}else this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([z.id])}onPointerUp(J){let Q=this.editor.getSelectedShapeIds(),Z=this.editor.getFocusedGroupId(),q=this.editor.getZoomLevel(),X=this.editor.inputs.getCurrentPagePoint(),K=J.shiftKey||J.accelKey,Y=this.editor.getShapeAtPoint(X,{margin:this.editor.options.hitTestMargin/q,hitInside:!0,renderingOnly:!0})??this.hitShape;if(!this.editor.getShape(Y.id)){this.parent.transition("idle",J);return}let W=Y?this.editor.getOutermostSelectableShape(Y):this.hitShapeForPointerUp;if(W){let z=this.editor.getShapeUtil(W);if(z.onClick){let G=z.onClick?.(W);if(G){this.editor.markHistoryStoppingPoint("shape on click"),this.editor.updateShapes([G]),this.parent.transition("idle",J);return}}if(W.id===Z){if(Q.length>0)this.editor.markHistoryStoppingPoint("clearing shape ids"),this.editor.setSelectedShapes([]);else this.editor.popFocusedGroupId();this.parent.transition("idle",J);return}}if(!this.didSelectOnEnter){let z=this.editor.getOutermostSelectableShape(Y,(G)=>!Q.includes(G.id));if(Q.includes(z.id))if(K)this.editor.markHistoryStoppingPoint("deselecting on pointer up"),this.editor.deselect(W);else if(Q.includes(W.id)){if(Q.length===1){let G=this.editor.getShapeUtil(W).getGeometry(W),H=TL(G),$=H.length===1?H[0]:void 0;if($){let _=this.editor.getPointInShapeSpace(W,X);if($.bounds.containsPoint(_,0)&&$.hitTestPoint(_)){this.editor.run(()=>{if(this.editor.markHistoryStoppingPoint("editing on pointer up"),this.editor.select(W.id),!this.editor.canEditShape(W))return;if(this.editor.setEditingShape(W.id),this.editor.setCurrentTool("select.editing_shape"),this.isDoubleClick)this.editor.emit("select-all-text",{shapeId:W.id});else this.editor.emit("place-caret",{shapeId:W.id,point:J.point})});return}}}this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(W.id)}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.select(W);else if(K){let G=this.editor.getShapeAncestors(z);this.editor.markHistoryStoppingPoint("shift deselecting on pointer up"),this.editor.setSelectedShapes([...this.editor.getSelectedShapeIds().filter((H)=>!G.find(($)=>$.id===H)),z.id])}else this.editor.markHistoryStoppingPoint("selecting on pointer up"),this.editor.setSelectedShapes([z.id])}this.parent.transition("idle",J)}onDoubleClick(J){if(this.isDoubleClick=!0,this.editor.inputs.getShiftKey()||J.phase!=="down"||J.ctrlKey||J.shiftKey)return;let{shape:Q,...Z}=J;this.parent.transition("idle"),this.parent.getCurrent()?.handleEvent({...Z,target:"canvas"})}onPointerMove(J){if(this.editor.inputs.getIsDragging()){if(ZL(this.editor,this.hitShape)){this.parent.transition("pointing_arrow_label",{...J,shape:this.hitShape});return}if(this.didCtrlOnEnter)this.parent.transition("brushing",J);else this.startTranslating(J)}}onLongPress(J){this.startTranslating(J)}startTranslating(J){if(this.editor.getIsReadonly())return;if(!this.didSelectOnEnter&&!this.editor.getSelectedShapeIds().length)this.editor.markHistoryStoppingPoint("selecting shape"),this.editor.setSelectedShapes([this.hitShapeForPointerUp.id]);this.editor.focus(),this.parent.transition("translating",J)}onCancel(){this.cancel()}onComplete(){this.cancel()}onInterrupt(){this.cancel()}cancel(){this.parent.transition("idle")}}class GT extends a{static id="resizing";static trackPerformance=!0;info={};markId="";didHoldCommand=!1;creationCursorOffset={x:0,y:0};snapshot={};onEnter(J){let{isCreating:Q=!1,creatingMarkId:Z,creationCursorOffset:q={x:0,y:0}}=J;if(this.info=J,this.didHoldCommand=!1,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);this.creationCursorOffset=q;try{this.snapshot=this._createSnapshot()}catch(X){console.error(X),this.cancel();return}if(this.markId="",Q)if(Z)this.markId=Z;else{let X=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);if(X)this.markId=X}else this.markId=this.editor.markHistoryStoppingPoint("starting resizing");if(Q)this.editor.setCursor({type:"cross",rotation:0});this.handleResizeStart(),this.updateShapes()}onTick({elapsed:J}){let{editor:Q}=this;if(!Q.inputs.getIsDragging()||Q.inputs.getIsPanning())return;Q.edgeScrollManager.updateEdgeScrolling(J)}onPointerMove(){this.updateShapes()}onKeyDown(){this.updateShapes()}onKeyUp(){this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}cancel(){let{shapeSnapshots:J}=this.snapshot;J.forEach(({shape:Z})=>{let q=this.editor.getShape(Z.id);if(q)this.editor.getShapeUtil(Z).onResizeCancel?.(Z,q)}),this.editor.bailToMark(this.markId);let{onInteractionEnd:Q}=this.info;if(Q){if(typeof Q==="string")this.editor.setCurrentTool(Q,{});else Q();return}this.parent.transition("idle")}complete(){if(z1(this.editor,this.snapshot.selectedShapeIds),this.handleResizeEnd(),this.info.isCreating&&this.info.onCreate){this.info.onCreate?.(this.editor.getOnlySelectedShape());return}let{onInteractionEnd:J}=this.info;if(J)if(typeof J==="string"){if(this.editor.getInstanceState().isToolLocked){this.editor.setCurrentTool(J,{});return}}else{J();return}this.parent.transition("idle")}handleResizeStart(){let{shapeSnapshots:J}=this.snapshot,Q=[];if(J.forEach(({shape:Z})=>{let X=this.editor.getShapeUtil(Z).onResizeStart?.(Z);if(X)Q.push(X)}),Q.length>0)this.editor.updateShapes(Q)}handleResizeEnd(){let{shapeSnapshots:J}=this.snapshot,Q=[];if(J.forEach(({shape:Z})=>{let q=this.editor.getShape(Z.id),K=this.editor.getShapeUtil(Z).onResizeEnd?.(Z,q);if(K)Q.push(K)}),Q.length>0)this.editor.updateShapes(Q)}updateShapes(){let{editor:J,info:Q,snapshot:{frames:Z,shapeSnapshots:q,selectionBounds:X,cursorHandleOffset:K,selectedShapeIds:Y,selectionRotation:W,canShapesDeform:z,initialSelectionPageBounds:G,resizeLevels:H}}=this,$=J.inputs.getAltKey(),F=J.inputs.getShiftKey()||!z;if(q.size===1){let w=[...q.values()][0];if(J.isShapeOfType(w.shape,"text"))F=!(Q.handle==="left"||Q.handle==="right")}let U=J6(J.inputs),V=J.inputs.getCurrentPagePoint().clone().sub(K).sub(this.creationCursorOffset),N=J.inputs.getOriginPagePoint().clone().sub(K);if(J.getInstanceState().isGridMode&&!U){let{gridSize:w}=J.getDocumentSettings();V.snapToGrid(w)}let B=Q.handle,O=oe(B,Math.PI);if(J.snaps.clearIndicators(),(J.user.getIsSnapMode()?!U:U)&&W%F4===0){let{nudge:w}=J.snaps.shapeBounds.snapResizeShapes({dragDelta:D.Sub(V,N),initialSelectionPageBounds:G,handle:oe(B,W),isAspectRatioLocked:F,isResizingFromCenter:$});V.add(w)}let L=D.RotWith($?X.center:X.getHandlePoint(O),X.point,W),j=D.Sub(V,L).rot(-W),k=D.Sub(N,L).rot(-W),R=D.DivV(j,k);if(!Number.isFinite(R.x))R.x=1;if(!Number.isFinite(R.y))R.y=1;let I=B==="top"||B==="bottom",A=B==="left"||B==="right";if(F)if(A)R.y=Math.abs(R.x);else if(I)R.x=Math.abs(R.y);else if(Math.abs(R.x)>Math.abs(R.y))R.y=Math.abs(R.x)*(R.y<0?-1:1);else R.x=Math.abs(R.y)*(R.x<0?-1:1);else{if(I)R.x=1;if(A)R.y=1}if(!this.info.isCreating)this.updateCursor({dragHandle:B,isFlippedX:R.x<0,isFlippedY:R.y<0,rotation:W});if(q.size>1)fe(this.editor,q,R,W,F);for(let w of H){let C=[];for(let x of w){let f=q.get(x),T=J.getResizeShapePartial(x,R,{initialShape:f.shape,initialBounds:f.bounds,initialPageTransform:f.pageTransform,dragHandle:B,mode:Y.length===1&&x===Y[0]?"resize_bounds":"scale_shape",scaleOrigin:L,isAspectRatioLocked:F,scaleAxisRotation:W,skipStartAndEndCallbacks:!0});if(T)C.push(T)}if(C.length>0)J.updateShapes(C)}if(U){this.didHoldCommand=!0;let w=[];for(let{id:C,children:x}of Z){if(!x.length)continue;let f=q.get(C).shape,T=this.editor.getShape(C);if(!(f&&T))continue;let h=T.x-f.x,b=T.y-f.y,v=new D(h,b).rot(-f.rotation);if(v.x!==0||v.y!==0)for(let g of x)w.push({id:g.id,type:g.type,x:g.x-v.x,y:g.y-v.y})}if(w.length>0)this.editor.updateShapes(w)}else if(this.didHoldCommand){this.didHoldCommand=!1;let w=[];for(let{children:C}of Z)for(let x of C)w.push({id:x.id,type:x.type,x:x.x,y:x.y});if(w.length>0)this.editor.updateShapes(w)}this.updateEnclosureHints()}updateEnclosureHints(){if(!this.info.isCreating)return;let J=this.editor.getOnlySelectedShape();if(!J||!this.editor.isShapeOfType(J,"frame"))return;let Q=aw(this.editor,J),Z=this.editor.getHintingShapeIds();if(Q.length===Z.length&&Q.every((q,X)=>q===Z[X]))return;this.editor.setHintingShapes(Q)}updateCursor({dragHandle:J,isFlippedX:Q,isFlippedY:Z,rotation:q}){let X=this.editor.getInstanceState().cursor,K=X.type;switch(J){case"top_left":case"bottom_right":{if(K="nwse-resize",Q!==Z)K="nesw-resize";break}case"top_right":case"bottom_left":{if(K="nesw-resize",Q!==Z)K="nwse-resize";break}}if(K===X.type&&q===X.rotation)return;this.editor.setCursor({type:K,rotation:q})}onExit(){if(this.parent.setCurrentToolIdMask(void 0),this.editor.setCursor({type:"default",rotation:0}),this.editor.snaps.clearIndicators(),Pb(this.editor,null),this.info.isCreating&&this.editor.getHintingShapeIds().length>0)this.editor.setHintingShapes([])}_createSnapshot(){let{editor:J}=this,Q=J.getSelectedShapeIds(),Z=J.getSelectionRotation(),q=J.inputs.getOriginPagePoint(),X=J.getSelectionRotatedPageBounds();if(!X)throw Error("Resizing but nothing is selected");let K=D.RotWith(X.getHandlePoint(this.info.handle),X.point,Z),Y=D.Sub(q,K),W=new Map,z=[],G=(U)=>{let V=J.getShape(U);if(!V)return!1;let N=J.getShapeUtil(V);if(N.canResize(V)){let B=J.getShapePageTransform(V);W.set(V.id,{shape:V,bounds:J.getShapeGeometry(V).bounds,pageTransform:B,pageRotation:d.Decompose(B).rotation,isAspectRatioLocked:N.isAspectRatioLocked(V)})}if(J.isShapeFrameLike(V))z.push({id:V.id,children:D0(J.getSortedChildIdsForParent(V).map((B)=>J.getShape(B)))});if(!N.canResizeChildren(V))return!1;return};Q.forEach((U)=>{if(G(U)===!1)return;J.visitDescendants(U,G)});let H=![...W.values()].some((U)=>!eq(U.pageRotation,Z)||U.isAspectRatioLocked),$=[],_=new Map,F=(U)=>{let V=_.get(U);if(V!==void 0)return V;let N=0,B=J.getShape(U)?.parentId;while(B&&H4(B)){if(W.has(B)){N=F(B)+1;break}B=J.getShape(B)?.parentId}return _.set(U,N),N};for(let U of W.keys()){let V=F(U);while($.length<=V)$.push([]);$[V].push(U)}return{shapeSnapshots:W,selectionBounds:X,cursorHandleOffset:Y,selectionRotation:Z,selectedShapeIds:Q,canShapesDeform:H,initialSelectionPageBounds:this.editor.getSelectionPageBounds(),frames:z,resizeLevels:$}}}var zT=["top","top_right","right","bottom_right","bottom","bottom_left","left","top_left"];function oe(J,Q){Q=Q%N1;let Z=Math.round(Q/(B1/4)),q=zT.indexOf(J);return zT[(q+Z)%zT.length]}var te=Math.PI/180;class $T extends a{static id="rotating";static trackPerformance=!0;snapshot={};info={};markId="";onEnter(J){if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);this.markId=this.editor.markHistoryStoppingPoint("rotate start");let Q=kG({editor:this.editor,ids:this.editor.getSelectedShapeIds()});if(!Q){this.parent.transition("idle",this.info);return}this.snapshot=Q;let Z=this._getRotationFromPointerPosition({snapToNearestDegree:!1});H3({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!1}),snapshot:this.snapshot,stage:"start"}),this.editor.setCursor({type:qJ[this.info.handle],rotation:Z+this.snapshot.initialShapesRotation})}onExit(){this.editor.setCursor({type:"default",rotation:0}),this.parent.setCurrentToolIdMask(void 0),this.snapshot={}}onPointerMove(){this.update()}onKeyDown(){this.update()}onKeyUp(){this.update()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}update(){let J=this._getRotationFromPointerPosition({snapToNearestDegree:!1});H3({editor:this.editor,delta:J,snapshot:this.snapshot,stage:"update"}),this.editor.setCursor({type:qJ[this.info.handle],rotation:J+this.snapshot.initialShapesRotation})}cancel(){let{shapeSnapshots:J}=this.snapshot;J.forEach(({shape:Z})=>{let q=this.editor.getShape(Z.id);if(q)this.editor.getShapeUtil(Z).onRotateCancel?.(Z,q)}),this.editor.bailToMark(this.markId);let{onInteractionEnd:Q}=this.info;if(Q){if(typeof Q==="string")this.editor.setCurrentTool(Q,this.info);else Q();return}this.parent.transition("idle",this.info)}complete(){H3({editor:this.editor,delta:this._getRotationFromPointerPosition({snapToNearestDegree:!0}),snapshot:this.snapshot,stage:"end"}),z1(this.editor,this.snapshot.shapeSnapshots.map((Q)=>Q.shape.id));let{onInteractionEnd:J}=this.info;if(J){if(typeof J==="string")this.editor.setCurrentTool(J,this.info);else J();return}this.parent.transition("idle",this.info)}_getRotationFromPointerPosition({snapToNearestDegree:J}){let Q=this.editor.inputs.getShiftKey(),Z=this.editor.inputs.getCurrentPagePoint(),{initialCursorAngle:q,initialShapesRotation:X,initialPageCenter:K}=this.snapshot,Y=K.angle(Z)-q,W=X+Y;if(Q)W=XZ(W,24);else if(J){if(W=Math.round(W/te)*te,this.editor.getInstanceState().isCoarsePointer){let z=XZ(W,4),G=EK(W,z);if(Math.abs(G)<yM(5))W=z}}return W-X}}class HT extends a{static id="scribble_brushing";static trackPerformance=!0;hits=new Set;size=0;scribbleId="id";initialSelectedShapeIds=new Set;newlySelectedShapeIds=new Set;onEnter(){this.initialSelectedShapeIds=new Set(this.editor.inputs.getShiftKey()?this.editor.getSelectedShapeIds():[]),this.newlySelectedShapeIds=new Set,this.size=0,this.hits.clear();let J=this.editor.scribbles.addScribble({color:"selection-stroke",opacity:0.32,size:12});this.scribbleId=J.id,this.updateScribbleSelection(!0),this.editor.updateInstanceState({brush:null})}onExit(){this.editor.scribbles.stop(this.scribbleId)}onPointerMove(){this.updateScribbleSelection(!0)}onPointerUp(){this.complete()}onKeyDown(){this.updateScribbleSelection(!1)}onKeyUp(){if(!this.editor.inputs.getAltKey())this.parent.transition("brushing");else this.updateScribbleSelection(!1)}onCancel(){this.cancel()}onComplete(){this.complete()}pushPointToScribble(){let{x:J,y:Q}=this.editor.inputs.getCurrentPagePoint();this.editor.scribbles.addPoint(this.scribbleId,J,Q)}updateScribbleSelection(J){let{editor:Q}=this,Z=this.editor.inputs.getShiftKey(),q=this.editor.inputs.getOriginPagePoint(),X=this.editor.inputs.getPreviousPagePoint(),K=this.editor.inputs.getCurrentPagePoint(),{newlySelectedShapeIds:Y,initialSelectedShapeIds:W}=this;if(J)this.pushPointToScribble();let z=0,G=p.FromPoints([X,K]).expandBy(z),H=Q.getShapeIdsInsideBounds(G);if(H.size===0){let L=Q.getSelectedShapeIds(),j=new Set(Z?[...Y,...W]:[...Y]);if(L.length!==j.size||L.some((k)=>!j.has(k)))this.editor.setSelectedShapes(Array.from(j));return}let F=this.editor.getCurrentPageRenderingShapesSorted().filter((L)=>H.has(L.id)),U,V,N,B;for(let L=0,j=F.length;L<j;L++){if(U=F[L],Q.isShapeOfType(U,"group")||Y.has(U.id)||!Q.options.selectLockedShapes&&Q.isShapeOrAncestorLocked(U))continue;if(V=Q.getShapeGeometry(U),Q.isShapeFrameLike(U)&&V.bounds.containsPoint(Q.getPointInShapeSpace(U,q)))continue;let k=Q.getShapePageTransform(U);if(!V||!k)continue;let R=k.clone().invert();N=R.applyToPoint(X),B=R.applyToPoint(K);let{bounds:I}=V;if(I.minX-z>Math.max(N.x,B.x)||I.minY-z>Math.max(N.y,B.y)||I.maxX+z<Math.min(N.x,B.x)||I.maxY+z<Math.min(N.y,B.y))continue;if(V.hitTestLineSegment(N,B,z)){let A=this.editor.getOutermostSelectableShape(U),w=this.editor.getShapeMask(A.id);if(w){if(X3(X,K,w)!==null){if(!n1(K,w))continue}}Y.add(A.id)}}let O=Q.getSelectedShapeIds(),M=new Set(Z?[...Y,...W]:[...Y]);if(O.length!==M.size||O.some((L)=>!M.has(L)))this.editor.setSelectedShapes(Array.from(M))}complete(){this.updateScribbleSelection(!0),this.parent.transition("idle")}cancel(){this.editor.setSelectedShapes([...this.initialSelectedShapeIds]),this.parent.transition("idle")}}var{defineProperty:IN0,getOwnPropertyDescriptor:wN0}=Object,bN0=(J,Q,Z,q)=>{var X=q>1?void 0:q?wN0(Q,Z):Q;for(var K=J.length-1,Y;K>=0;K--)if(Y=J[K])X=(q?Y(Q,Z,X):Y(X))||X;if(q&&X)IN0(Q,Z,X);return X},TN0=320,yN0=60;class yL{constructor(J){this.editor=J,J.disposables.add(this.dispose)}editor;shapesToActuallyMove=[];draggedOverShapeIds=new Set;initialGroupIds=new Map;initialParentIds=new Map;initialIndices=new Map;initialDraggingOverShape;prevDraggingOverShape;prevPagePoint=new D;intervalTimerId=-1;startDraggingShapes(J,Q,Z){let{editor:q}=this;if(this.intervalTimerId!==-1)return;let X=new Set(J),K=new Set;for(let z of X){let G=q.getShapeParent(z);if(G&&q.isShapeOfType(G,"group")){if(!K.has(G))K.add(G)}}for(let z of K){let G=D0(q.getSortedChildIdsForParent(z).map((H)=>q.getShape(H)));X.add(z);for(let H of G)X.delete(H)}this.initialParentIds.clear();for(let z of X){let G=q.getShapeParent(z);if(G)this.initialParentIds.set(z.id,G.id);this.initialIndices.set(z.id,z.index);let H=q.findShapeAncestor(z,($)=>q.isShapeOfType($,"group"));if(H)this.initialGroupIds.set(z.id,H.id)}let Y=q.getCurrentPageShapesSorted();this.shapesToActuallyMove=Array.from(X).filter((z)=>!z.isLocked).sort((z,G)=>Y.indexOf(z)-Y.indexOf(G)),this.initialDraggingOverShape=q.getDraggingOverShape(Q,this.shapesToActuallyMove),this.prevDraggingOverShape=this.initialDraggingOverShape,this.updateDraggingShapes(Q,Z);let W=0;this.intervalTimerId=this.editor.timers.setInterval(()=>{if(W++,W%3&&this.editor.inputs.getPointerVelocity().len()>0.5)return;this.updateDraggingShapes(q.inputs.getCurrentPagePoint(),Z)},J.length>10?TN0:yN0)}dropShapes(J){let{editor:Q}=this,Z=Q.inputs.getCurrentPagePoint();this.updateDraggingShapes(Z);let q=Q.getDraggingOverShape(Z,J);if(q){let X=Q.getShapeUtil(q),K=ee(Q,q,J);if(K.length>0)X.onDropShapesOver?.(q,K,{initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices})}this.dispose()}clear(){clearInterval(this.intervalTimerId),this.intervalTimerId=-1,this.initialParentIds.clear(),this.initialIndices.clear(),this.shapesToActuallyMove=[],this.initialDraggingOverShape=void 0,this.prevDraggingOverShape=void 0,this.editor.setHintingShapes([])}dispose(){this.clear()}updateDraggingShapes(J,Q){let{editor:Z}=this,q=D0(this.shapesToActuallyMove.map((W)=>Z.getShape(W)));if(!q.length)return;let X=Z.getDraggingOverShape(J,this.shapesToActuallyMove),K=Z.inputs.getCurrentPagePoint(),Y=!this.prevPagePoint.equals(K);this.prevPagePoint.setTo(K),Z.run(()=>{if(this.prevDraggingOverShape?.id===X?.id){if(Y&&X&&H4(X.id)&&!Z.inputs.getPreviousPagePoint().equals(K))Z.getShapeUtil(X).onDragShapesOver?.(X,q,{initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices});return}if(this.prevDraggingOverShape){let W=Z.getShapeUtil(this.prevDraggingOverShape),z=this.editor.getShape(this.prevDraggingOverShape),G=xN0(Z,z,q);if(G.length>0)W.onDragShapesOut?.(z,G,{nextDraggingOverShapeId:X?.id??null,initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices})}if(X){let W=Z.getShapeUtil(X),z=ee(Z,X,q);if(z.length>0)W.onDragShapesIn?.(X,z,{initialDraggingOverShapeId:this.initialDraggingOverShape?.id??null,prevDraggingOverShapeId:this.prevDraggingOverShape?.id??null,initialParentIds:this.initialParentIds,initialIndices:this.initialIndices}),Z.setHintingShapes([X.id]);else if(this.prevDraggingOverShape)Z.setHintingShapes([])}else if(this.prevDraggingOverShape)Z.setHintingShapes([]);Q?.()}),this.prevDraggingOverShape=X}}bN0([S1],yL.prototype,"dispose",1);function ee(J,Q,Z){let q=J.getShapeUtil(Q);return Z.filter((X)=>q.canReceiveNewChildrenOfType(Q,X.type))}function xN0(J,Q,Z){let q=J.getShapeUtil(Q);return Z.filter((X)=>q.canRemoveChildrenOfType(Q,X.type))}var{defineProperty:vN0,getOwnPropertyDescriptor:SN0}=Object,fN0=(J,Q,Z,q)=>{var X=q>1?void 0:q?SN0(Q,Z):Q;for(var K=J.length-1,Y;K>=0;K--)if(Y=J[K])X=(q?Y(Q,Z,X):Y(X))||X;if(q&&X)vN0(Q,Z,X);return X};class xL extends a{static id="translating";static trackPerformance=!0;info={};selectionSnapshot={};snapshot={};markId="";isCloning=!1;isCreating=!1;onCreate(J){return}dragAndDropManager=new yL(this.editor);onEnter(J){let{isCreating:Q=!1,creatingMarkId:Z,onCreate:q=()=>{return}}=J;if(!this.editor.getSelectedShapeIds()?.length){this.parent.transition("idle");return}if(this.info=J,typeof J.onInteractionEnd==="string")this.parent.setCurrentToolIdMask(J.onInteractionEnd);if(this.isCreating=Q,this.markId="",Q)if(Z)this.markId=Z;else{let X=this.editor.getMarkIdMatching(`creating:${this.editor.getOnlySelectedShapeId()}`);if(X)this.markId=X}else this.markId=this.editor.markHistoryStoppingPoint("translating");if(this.onCreate=q,this.isCloning=!1,this.info=J,this.editor.setCursor({type:"move",rotation:0}),this.selectionSnapshot=J00(this.editor),!this.isCreating){if(this.editor.inputs.getAltKey()){if(this.startCloning(),this.isCloning)return}}this.snapshot=this.selectionSnapshot,this.handleStart(),this.updateShapes()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.selectionSnapshot={},this.snapshot={},this.editor.snaps.clearIndicators(),this.editor.setCursor({type:"default",rotation:0}),this.dragAndDropManager.clear()}onTick({elapsed:J}){let{editor:Q}=this;if(!Q.inputs.getIsDragging()||Q.inputs.getIsPanning())return;Q.edgeScrollManager.updateEdgeScrolling(J)}onPointerMove(){this.updateShapes()}onKeyDown(){if(this.editor.inputs.getAltKey()&&!this.isCloning){if(this.startCloning(),this.isCloning)return}this.updateShapes()}onKeyUp(){if(!this.editor.inputs.getAltKey()&&this.isCloning){this.stopCloning();return}this.updateShapes()}onPointerUp(){this.complete()}onComplete(){this.complete()}onCancel(){this.cancel()}startCloning(){if(this.isCreating)return;let J=Array.from(this.editor.getSelectedShapeIds());if(!this.editor.canCreateShapes(J))return;this.isCloning=!0,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate cloning"),this.editor.duplicateShapes(Array.from(this.editor.getSelectedShapeIds())),this.snapshot=J00(this.editor),this.handleStart(),this.updateShapes()}stopCloning(){this.isCloning=!1,this.snapshot=this.selectionSnapshot,this.reset(),this.markId=this.editor.markHistoryStoppingPoint("translate"),this.updateShapes()}reset(){this.editor.bailToMark(this.markId)}complete(){this.updateShapes(),this.dragAndDropManager.dropShapes(this.snapshot.movingShapes),this.handleEnd(),z1(this.editor,this.snapshot.movingShapes.map((Q)=>Q.id));let{onInteractionEnd:J}=this.info;if(J)if(typeof J==="string"){if(this.editor.getInstanceState().isToolLocked){this.editor.setCurrentTool(J);return}}else{J();return}if(this.isCreating)this.onCreate?.(this.editor.getOnlySelectedShape());else this.parent.transition("idle")}cancel(){let{movingShapes:J}=this.snapshot;J.forEach((Z)=>{let q=this.editor.getShape(Z.id);if(q)this.editor.getShapeUtil(Z).onTranslateCancel?.(Z,q)}),this.reset();let{onInteractionEnd:Q}=this.info;if(Q){if(typeof Q==="string")this.editor.setCurrentTool(Q);else Q();return}this.parent.transition("idle",this.info)}handleStart(){let{movingShapes:J}=this.snapshot,Q=[];if(J.forEach((Z)=>{let X=this.editor.getShapeUtil(Z).onTranslateStart?.(Z);if(X)Q.push(X)}),Q.length>0)this.editor.updateShapes(Q);this.dragAndDropManager.startDraggingShapes(D0(this.snapshot.movingShapes.map((Z)=>this.editor.getShape(Z.id))),this.editor.inputs.getOriginPagePoint(),this.updateParentTransforms),this.editor.setHoveredShape(null)}handleEnd(){let{movingShapes:J}=this.snapshot;if(this.isCloning&&J.length>0){let Z=D.Average(J.map((X)=>this.editor.getShapePageTransform(X.id).point())),q=D.Sub(Z,this.selectionSnapshot.averagePagePoint);if(!D.IsNaN(q))this.editor.updateInstanceState({duplicateProps:{shapeIds:J.map((X)=>X.id),offset:{x:q.x,y:q.y}}})}let Q=[];if(J.forEach((Z)=>{let q=this.editor.getShape(Z.id),K=this.editor.getShapeUtil(Z).onTranslateEnd?.(Z,q);if(K)Q.push(K)}),Q.length>0)this.editor.updateShapes(Q)}updateShapes(){let{snapshot:J}=this;this.dragAndDropManager.startDraggingShapes(J.movingShapes,this.editor.inputs.getOriginPagePoint(),this.updateParentTransforms),gN0({editor:this.editor,snapshot:J});let{movingShapes:Q}=J,Z=[];if(Q.forEach((q)=>{let X=this.editor.getShape(q.id),Y=this.editor.getShapeUtil(q).onTranslate?.(q,X);if(Y)Z.push(Y)}),Z.length>0)this.editor.updateShapes(Z)}updateParentTransforms(){let{editor:J,snapshot:{shapeSnapshots:Q}}=this,Z=[];Q.forEach((q)=>{let X=J.getShape(q.shape.id);if(!X)return;Z.push(X);let K=B6(X.parentId)?null:d.Inverse(J.getShapePageTransform(X.parentId));q.parentTransform=K})}}fN0([S1],xL.prototype,"updateParentTransforms",1);function J00(J){let Q=[],Z=[],q=J.getSelectedShapeIds(),X=D0(q.map((_)=>{let F=J.getShape(_);if(!F)return null;Q.push(F);let U=J.getShapePageTransform(_),V=U.point(),N=U.rotation();Z.push(V);let B=w4.isId(F.parentId)?null:d.Inverse(J.getShapePageTransform(F.parentId));return{shape:F,pagePoint:V,pageRotation:N,parentTransform:B}})),K=J.getOnlySelectedShape(),Y=[];if(K)Y=J.snaps.shapeBounds.getSnapPoints(K.id);else{let _=J.getSelectionPageBounds();if(_)Y=_.cornersAndCenter.map((F,U)=>({id:"selection:"+U,x:F.x,y:F.y}))}let W,z,G,H=J.inputs.getOriginPagePoint(),$=X.filter((_)=>J.isShapeOfType(_.shape,"note")&&J.isPointInShape(_.shape,H));if($.length===0);else if($.length===1)z=$[0];else{let _=J.getCurrentPageShapesSorted();z=$.map((F)=>({snapshot:F,index:_.findIndex((U)=>U.id===F.shape.id)})).sort((F,U)=>U.index-F.index)[0]?.snapshot}if(z){let _=J.getShapeUtil(z.shape),F=k0(_,z.shape);W=rO(J,{rotation:z.pageRotation,scale:z.shape.props.scale,extraHeight:z.shape.props.growY??0,noteWidth:F.noteWidth,noteHeight:F.noteHeight}),G=new D(F.noteWidth/2,F.noteHeight/2)}return{averagePagePoint:D.Average(Z),movingShapes:Q,shapeSnapshots:X,initialPageBounds:J.getSelectionPageBounds(),initialSnapPoints:Y,noteAdjacentPositions:W,noteSnapshot:z,noteCenterOffset:G}}function gN0({editor:J,snapshot:Q}){let{inputs:Z}=J,{noteSnapshot:q,noteAdjacentPositions:X,noteCenterOffset:K,initialPageBounds:Y,initialSnapPoints:W,shapeSnapshots:z,averagePagePoint:G}=Q,H=J.inputs.getShiftKey(),$=J.inputs.getAccelKey(),_=J.getInstanceState().isGridMode,F=J.getDocumentSettings().gridSize,U=D.Sub(Z.getCurrentPagePoint(),Z.getOriginPagePoint()),V=H?Math.abs(U.x)<Math.abs(U.y)?"x":"y":null;if(V==="x")U.x=0;else if(V==="y")U.y=0;J.snaps.clearIndicators();let N=J.user.getIsSnapMode()?!$:$,B=!1;if(N&&J.inputs.getPointerVelocity().len()<0.5){let{nudge:j}=J.snaps.shapeBounds.snapTranslateShapes({dragDelta:U,initialSelectionPageBounds:Y,lockedAxis:V,initialSelectionSnapPoints:W});U.add(j)}else if(q&&X&&K){let{scale:j}=q.shape.props,k=q.pagePoint.clone().add(U).add(K.clone().mul(j).rot(q.pageRotation)),R=sO/J.getZoomLevel(),I=new D(0,0);for(let A of X){let w=D.Sub(k,A),C=w.len();if(C<R)B=!0,R=C,I=w}U.sub(I)}let O=D.Add(G,U),M=J.snaps.getIndicators();if(_&&!$&&!B&&M.length===0)O.snapToGrid(F);let L=D.Sub(O,G);J.updateShapes(D0(z.map(({shape:j,pagePoint:k,parentTransform:R})=>{let I=D.Add(k,L),A=R?d.applyToPoint(R,I):I;return{id:j.id,type:j.type,x:A.x,y:A.y}})))}class vL extends a{static id="select";static initial="idle";static isLockable=!1;reactor=void 0;static children(){return[tb,Y_,QT,qT,WT,xL,nb,HT,W_,YT,sb,JT,GT,$T,KT,ZT,XT,eb]}cleanUpDuplicateProps(){let J=this.editor.getSelectedShapeIds(),Q=this.editor.getInstanceState();if(!Q.duplicateProps)return;let Z=new Set(Q.duplicateProps.shapeIds);if(J.length===Z.size&&J.every((q)=>Z.has(q)))return;this.editor.updateInstanceState({duplicateProps:null})}onEnter(){this.reactor=g1("clean duplicate props",()=>{try{this.cleanUpDuplicateProps()}catch(J){console.error(J)}})}onExit(){if(this.reactor?.(),this.editor.getCurrentPageState().editingShapeId)this.editor.setEditingShape(null)}}class _T extends a{static id="idle";info={};onEnter(J){this.info=J}onPointerDown(){this.parent.transition("pointing",this.info)}onKeyDown(J){if(J.key==="Shift")this.parent.transition("zoom_quick",this.info)}}class FT extends a{static id="pointing";info={};onEnter(J){this.info=J}onPointerUp(){this.complete()}onPointerMove(){if(this.editor.inputs.getIsDragging())this.parent.transition("zoom_brushing",this.info)}onCancel(){this.cancel()}complete(){let J=this.editor.inputs.getCurrentScreenPoint();if(this.editor.inputs.getAltKey())this.editor.zoomOut(J,{animation:{duration:220}});else this.editor.zoomIn(J,{animation:{duration:220}});this.parent.transition("idle",this.info)}cancel(){this.parent.transition("idle",this.info)}}class UT extends a{static id="zoom_brushing";info={};zoomBrush=new p;onEnter(J){this.info=J,this.update()}onExit(){this.editor.updateInstanceState({zoomBrush:null})}onPointerMove(){this.update()}onPointerUp(){this.complete()}onCancel(){this.cancel()}update(){let J=this.editor.inputs.getOriginPagePoint(),Q=this.editor.inputs.getCurrentPagePoint();this.zoomBrush.setTo(p.FromPoints([J,Q])),this.editor.updateInstanceState({zoomBrush:this.zoomBrush.toJson()})}cancel(){this.parent.transition("idle",this.info)}complete(){let{zoomBrush:J}=this,Q=8/this.editor.getZoomLevel();if(J.width<Q&&J.height<Q){let Z=this.editor.inputs.getCurrentScreenPoint();if(this.editor.inputs.getAltKey())this.editor.zoomOut(Z,{animation:{duration:220}});else this.editor.zoomIn(Z,{animation:{duration:220}})}else{let Z=this.editor.inputs.getAltKey()?this.editor.getZoomLevel()/2:void 0;this.editor.zoomToBounds(J,{targetZoom:Z,animation:{duration:220}})}this.parent.transition("idle",this.info)}}class VT extends a{static id="zoom_quick";info={};qzState="idle";initialVpb=new p;initialPp=new D;overviewZoom=1;cleanupZoomReactor(){}nextVpb=new p;onEnter(J){let{editor:Q}=this;this.info=J,this.qzState="idle",this.initialVpb=Q.getViewportPageBounds(),this.initialPp=D.From(Q.inputs.getCurrentPagePoint()),Q.setCursor({type:"zoom-in",rotation:0});let Z=this.initialVpb,q=Q.getCurrentPageBounds(),X=q?p.Expand(Z,q):Z.clone(),K=Q.getViewportScreenBounds(),Y=Q.inputs.getCurrentScreenPoint(),W=Y.x,z=Y.y,{x:G,y:H}=this.initialPp,$=G-X.minX,_=X.maxX-G,F=H-X.minY,U=X.maxY-H,V=Q.getCamera().z;if($>0)V=Math.min(V,W/$);if(_>0)V=Math.min(V,(K.w-W)/_);if(F>0)V=Math.min(V,z/F);if(U>0)V=Math.min(V,(K.h-z)/U);if(V*=0.85,V=Math.max(Q.getCameraOptions().zoomSteps[0],V),this.overviewZoom=V,Q.options.quickZoomPreservesScreenBounds)this.cleanupZoomReactor=g1("zoom change in quick zoom",()=>{Q.getZoomLevel(),this.updateBrush()});let{x:N,y:B,z:O}=Q.getCamera(),M=O/V;if(Q.setCamera(new D((N+G)*M-G,(B+H)*M-H,V)),!Q.options.quickZoomPreservesScreenBounds)this.updateBrush()}onExit(){this.cleanupZoomReactor(),this.zoomToNewViewport(),this.editor.updateInstanceState({zoomBrush:null})}onPointerUp(){let J=this.info.onInteractionEnd?.split(".")[0]??"select";this.editor.setCurrentTool(J)}onCancel(){this.qzState="idle";let J=this.info.onInteractionEnd?.split(".")[0]??"select";this.editor.setCurrentTool(J)}onKeyUp(J){if(J.key==="Shift")this.parent.transition("idle",this.info)}updateBrush(){let{editor:J}=this,Q=this.getNextVpb();this.nextVpb.setTo(Q),J.updateInstanceState({zoomBrush:Q.toJson()})}zoomToNewViewport(){let{editor:J}=this;switch(this.qzState){case"idle":J.zoomToBounds(this.initialVpb,{inset:0});break;case"moving":J.zoomToBounds(this.nextVpb,{inset:0});break}}onPointerMove(){if(this.qzState!=="moving")return;this.updateBrush()}onTick(){let{editor:J}=this;switch(this.qzState){case"idle":{let Q=J.getZoomLevel();if(D.Dist2(J.inputs.getCurrentPagePoint(),this.initialPp)*Q>J.options.dragDistanceSquared/Q)this.qzState="moving",this.updateBrush();break}case"moving":break}}getNextVpb(){let{editor:J}=this,Q,Z;if(J.options.quickZoomPreservesScreenBounds){let G=this.overviewZoom/J.getCamera().z;Q=this.initialVpb.w*G,Z=this.initialVpb.h*G}else Q=this.initialVpb.w,Z=this.initialVpb.h;let{x:q,y:X}=J.inputs.getCurrentPagePoint(),K=J.getViewportScreenBounds(),Y=J.inputs.getCurrentScreenPoint(),{x:W,y:z}=new D(Y.x/K.w,Y.y/K.h);return new p(q-W*Q,X-z*Z,Q,Z)}}class SL extends a{static id="zoom";static initial="idle";static children(){return[_T,FT,UT,VT]}static isLockable=!1;info={};onEnter(J){this.info=J;let Q=J.onInteractionEnd?.split(".")[0];this.parent.setCurrentToolIdMask(Q),this.updateCursor()}onExit(){this.parent.setCurrentToolIdMask(void 0),this.editor.updateInstanceState({zoomBrush:null,cursor:{type:"default",rotation:0}})}onKeyDown(){this.updateCursor()}onKeyUp(J){if(this.updateCursor(),J.key.toLowerCase()==="z")this.complete()}onInterrupt(){this.complete()}complete(){let J=this.info.onInteractionEnd?.split(".")[0]??"select";this.editor.setCurrentTool(J)}updateCursor(){if(this.editor.inputs.getAltKey()&&!this.editor.isIn("zoom.zoom_quick"))this.editor.setCursor({type:"zoom-out",rotation:0});else this.editor.setCursor({type:"zoom-in",rotation:0})}}var NT=[PL,IL,wL,SL,vL];var xX=E(c(),1);var q00=E(c1(),1),X00=E(m(),1);var Q00=E(c(),1);var Z00=E(m(),1),BT=Z00.default.forwardRef(function({isEditing:Q,text:Z,handleFocus:q,handleChange:X,handleKeyDown:K,handlePaste:Y,handleBlur:W,handleInputPointerDown:z,handleDoubleClick:G},H){let $=y();return Q00.jsx("textarea",{ref:H,className:"tl-text tl-text-input",name:"text",tabIndex:-1,disabled:!Q,readOnly:!Q,autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",autoSave:"off",placeholder:"",spellCheck:"true",wrap:"off",dir:"auto",defaultValue:Z,onFocus:q,onChange:(F)=>{X({plaintext:F.target.value})},onKeyDown:(F)=>K(F.nativeEvent),onBlur:W,onTouchEnd:$.markEventAsHandled,onContextMenu:Q?(F)=>F.stopPropagation():void 0,onPointerDown:z,onPaste:Y,onDoubleClick:G,onDragStart:W0})});var hN0=X00.default.memo(function({shapeId:Q,type:Z,text:q,labelColor:X,fontFamily:K,fontSize:Y,lineHeight:W,textAlign:z,verticalAlign:G,wrap:H,isSelected:$,padding:_=0,onKeyDown:F,classNamePrefix:U,style:V,textWidth:N,textHeight:B,showTextOutline:O=!0}){let{rInput:M,isEmpty:L,isEditing:j,isReadyForEditing:k,...R}=_b(Q,Z,q),I=i3.normalizeTextForDom(q||""),A=I.length>0,w=nH(z);if(!j&&!A)return null;let C=U||"tl-text";return xX.jsx("div",{className:`${C}-label tl-text-wrapper tl-plain-text-wrapper`,"aria-hidden":!j,"data-hastext":!L,"data-isediting":j,"data-is-ready-for-editing":k,"data-textwrap":!!H,"data-isselected":$,style:{fontFamily:K,textAlign:z,justifyContent:z==="center"||w?"center":z==="end"?"flex-end":"flex-start",alignItems:G==="middle"?"center":G==="end"?"flex-end":"flex-start",padding:_,...V},children:xX.jsxs("div",{className:`${C}-label__inner tl-text-content__wrapper`,style:{fontSize:Y,lineHeight:`${p8(Y,W)}px`,minHeight:`${p8(Y,W)}px`,minWidth:Math.ceil(N||0),color:X,width:N?Math.ceil(N):void 0,height:B?Math.ceil(B):void 0},children:[xX.jsx("div",{className:q00.default(`${C} tl-text tl-text-content`,O?"tl-text__outline":"tl-text__no-outline"),dir:"auto",children:I.split(`
|
|
546
|
-
`).map((x,f)=>xX.jsx("div",{dir:"auto",children:x},f))}),(k||$)&&xX.jsx(BT,{ref:M,text:q,isEditing:j,shapeId:Q,...R,handleKeyDown:F??R.handleKeyDown})]})})});var $9=E(c(),1);var $2=E(m(),1);var Y00=E(m(),1);var K00=E(m(),1),z_={fonts:{tldraw_mono:`${Q6()}/fonts/IBMPlexMono-Medium.woff2`,tldraw_mono_italic:`${Q6()}/fonts/IBMPlexMono-MediumItalic.woff2`,tldraw_mono_bold:`${Q6()}/fonts/IBMPlexMono-Bold.woff2`,tldraw_mono_italic_bold:`${Q6()}/fonts/IBMPlexMono-BoldItalic.woff2`,tldraw_serif:`${Q6()}/fonts/IBMPlexSerif-Medium.woff2`,tldraw_serif_italic:`${Q6()}/fonts/IBMPlexSerif-MediumItalic.woff2`,tldraw_serif_bold:`${Q6()}/fonts/IBMPlexSerif-Bold.woff2`,tldraw_serif_italic_bold:`${Q6()}/fonts/IBMPlexSerif-BoldItalic.woff2`,tldraw_sans:`${Q6()}/fonts/IBMPlexSans-Medium.woff2`,tldraw_sans_italic:`${Q6()}/fonts/IBMPlexSans-MediumItalic.woff2`,tldraw_sans_bold:`${Q6()}/fonts/IBMPlexSans-Bold.woff2`,tldraw_sans_italic_bold:`${Q6()}/fonts/IBMPlexSans-BoldItalic.woff2`,tldraw_draw:`${Q6()}/fonts/Shantell_Sans-Informal_Regular.woff2`,tldraw_draw_italic:`${Q6()}/fonts/Shantell_Sans-Informal_Regular_Italic.woff2`,tldraw_draw_bold:`${Q6()}/fonts/Shantell_Sans-Informal_Bold.woff2`,tldraw_draw_italic_bold:`${Q6()}/fonts/Shantell_Sans-Informal_Bold_Italic.woff2`}};function fL(J){return K00.useMemo(()=>{if(!J)return z_;return{fonts:{...z_.fonts,...J?.fonts}}},[J])}var OT=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","alt","arrow-arc","arrow-cycle","arrow-elbow","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bold","bookmark","bring-forward","bring-to-front","broken","bulletList","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","color","comment","corners","crop","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","download","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-lined-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","heading","help-circle","highlight","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","italic","leading","link","list","lock","manual","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","strike","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","underline","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];var G_={...z_,icons:Object.fromEntries(OT.map((J)=>[J,`${Q6()}/icons/icon/0_merged.svg#${J}`])),translations:Object.fromEntries(L2.map((J)=>[J.locale,`${Q6()}/translations/${J.locale}.json`])),embedIcons:Object.fromEntries(mY.map((J)=>[J.type,`${Q6()}/embed-icons/${J.type}.png`]))};function gL(J){return Y00.useMemo(()=>{if(!J)return G_;return{fonts:Object.assign({...G_.fonts},{...J?.fonts}),icons:Object.assign({...G_.icons},{...J?.icons}),embedIcons:Object.assign({...G_.embedIcons},{...J?.embedIcons}),translations:Object.assign({...G_.translations},{...J?.translations})}},[J])}var LT=E(c(),1);function W00(){let{Spinner:J}=T4();return LT.jsx(FR,{children:J?LT.jsx(J,{}):null})}var U1=E(c(),1);var $00=E(c1(),1),c9=E(m(),1);var G9=E(c(),1);var DT=p1(function({overrides:Q,components:Z,assetUrls:q,onUiEvent:X,forceMobile:K,mediaMimeTypes:Y,children:W}){let z=J1();return G9.jsx(rP.Provider,{value:Y,children:G9.jsx(B$,{assetUrls:gL(q),children:G9.jsx(L$,{overrides:TB(Q),locale:z?.user.getLocale()??v6.locale,children:G9.jsx(VP,{children:G9.jsx(jP,{onEvent:X,children:G9.jsx(gP,{children:G9.jsx(SP,{context:"tla",children:G9.jsx(mk,{children:G9.jsx(LP,{forceMobile:K,children:G9.jsx(Iw,{overrides:Z,children:G9.jsx(uN0,{overrides:Q,children:W})})})})})})})})})})})});function uN0({overrides:J,children:Q}){let Z=lr(J);return G9.jsx(Lt,{overrides:Z.actions,children:G9.jsx(ir,{overrides:Z.tools,children:Q})})}var z00=E(m(),1);function G00(){let J=y(),{addToast:Q}=C5();z00.useEffect(()=>{function Z({name:q,count:X}){Q({title:"Maximum shapes reached",description:`You've reached the maximum number of shapes allowed on ${q} (${X}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return J.addListener("max-shapes",Z),()=>{J.removeListener("max-shapes",Z)}},[J,Q])}var MT=c9.default.memo(function({renderDebugMenuItems:Q,children:Z,hideUi:q,components:X,...K}){return U1.jsx(DT,{...K,components:X,children:U1.jsx(mN0,{hideUi:q,renderDebugMenuItems:Q,children:Z})})}),mN0=c9.default.memo(function({children:Q,hideUi:Z,...q}){return Dw(),dP(),U1.jsxs(U1.Fragment,{children:[Q,Z?null:U1.jsx(cN0,{...q})]})}),cN0=c9.default.memo(function(){let Q=y(),Z=t(),q=A1(),X=I6(),K=S("focus",()=>Q.getInstanceState().isFocusMode,[Q]),Y=S("debug",()=>Q.getInstanceState().isDebugMode,[Q]),W=Q1(),z=t0(),G=S("locale",()=>Q.user.getLocale(),[Q]);c9.useEffect(()=>{W.dir=z,W.lang=G},[W,z,G]);let{SharePanel:H,TopPanel:$,MenuPanel:_,StylePanel:F,Toolbar:U,HelpMenu:V,NavigationPanel:N,HelperButtons:B,DebugPanel:O,Toasts:M,Dialogs:L,A11y:j,FollowingIndicator:k}=N4();G00();let R=c9.useRef(!1),I=c9.useRef(-1),[A,w]=c9.useState(!1);FJ("update hide toolbar while delayed",()=>{if(!(S0.isIos||S0.isAndroid))return;if(Q.getEditingShapeId()===null){if(R.current)if(R.current=!1,clearTimeout(I.current),S0.isAndroid)I.current=Q.timers.setTimeout(()=>{w(!1)},150);else w(!1);return}if(!R.current)R.current=!0,clearTimeout(I.current),w(!0)},[]);let{"toggle-focus-mode":C}=f6(),{breakpointsAbove:x,breakpointsBelow:f}=c9.useMemo(()=>{let T=[],h=[];for(let b=0;b<lY.length;b++)if(b<=q)T.push(b);else h.push(b);return{breakpointsAbove:T,breakpointsBelow:h}},[q]);return U1.jsxs("div",{className:$00.default("tlui-layout",{"tlui-layout__mobile":q<e0.TABLET_SM}),role:"document","data-iseditinganything":A,"data-breakpoint":q,"data-breakpoints-above":x.join(" "),"data-breakpoints-below":f.join(" "),children:[U1.jsx(jt,{}),K?U1.jsx("div",{className:"tlui-layout__top",children:U1.jsx(w0,{type:"icon",className:"tlui-focus-button",title:Z("focus-mode.toggle-focus-mode"),onClick:()=>C.onSelect("menu"),children:U1.jsx(z0,{icon:"dot"})})}):U1.jsxs(U1.Fragment,{children:[U1.jsxs("div",{className:"tlui-layout__top",children:[U1.jsxs("div",{className:"tlui-layout__top__left",children:[_&&U1.jsx(_,{}),B&&U1.jsx(B,{})]}),U1.jsx("div",{className:"tlui-layout__top__center",children:$&&U1.jsx($,{})}),U1.jsxs("div",{className:"tlui-layout__top__right",children:[H&&U1.jsx(H,{}),F&&q>=e0.TABLET_SM&&!X&&U1.jsx(F,{})]})]}),U1.jsxs("div",{className:"tlui-layout__bottom",children:[U1.jsxs("div",{className:"tlui-layout__bottom__main",children:[N&&U1.jsx(N,{}),U&&U1.jsx(U,{}),V&&U1.jsx(V,{})]}),Y&&O&&U1.jsx(O,{}),j&&U1.jsx(j,{})]})]}),k&&U1.jsx(k,{}),M&&U1.jsx(M,{}),L&&U1.jsx(L,{})]})});function hL(){let{RichTextToolbar:J,ImageToolbar:Q,VideoToolbar:Z,CursorChatBubble:q}=N4();return U1.jsxs(U1.Fragment,{children:[J&&U1.jsx(J,{}),Q&&U1.jsx(Q,{}),Z&&U1.jsx(Z,{}),q&&U1.jsx(q,{})]})}var lN0=[...NT,...Wb];function pN0(J,Q){let{maxImageDimension:Z,acceptedImageMimeTypes:q,acceptedVideoMimeTypes:X}=Q,K=Z!==void 0||q!==void 0,Y=X!==void 0;if(!K&&!Y)return J;return J.map((W)=>{if(K&&W.type==="image")return W.configure({...Z!==void 0&&{maxDimension:Z},...q!==void 0&&{supportedMimeTypes:q}});if(Y&&W.type==="video")return W.configure({...X!==void 0&&{supportedMimeTypes:X}});return W})}function jT(J){let{children:Q,maxImageDimension:Z,maxAssetSize:q,acceptedImageMimeTypes:X,acceptedVideoMimeTypes:K,onMount:Y,components:W={},shapeUtils:z=[],bindingUtils:G=[],assetUtils:H=[],overlayUtils:$=[],tools:_=[],embeds:F,options:U,locale:V,textOptions:N,...B}=J,O=P9(W),M=W?.InFrontOfTheCanvas,L=$2.useMemo(()=>{if(B.hideUi)return M??null;if(!M)return hL;return()=>$9.jsxs($9.Fragment,{children:[$9.jsx(hL,{}),$9.jsx(M,{})]})},[B.hideUi,M]),j=$2.useMemo(()=>({Spinner:qH,LoadingScreen:W00,...O,InFrontOfTheCanvas:L}),[O,L]),k=m8(z),R=$2.useMemo(()=>F2("type",k,bX),[k]),I=m8(G),A=$2.useMemo(()=>F2("type",I,AX),[I]),w=m8(H),C=$2.useMemo(()=>pN0(F2("type",w,iw),{maxImageDimension:Z,acceptedImageMimeTypes:X,acceptedVideoMimeTypes:K}),[w,Z,X,K]),x=m8($),f=$2.useMemo(()=>F2("type",x,nw),[x]),T=m8(_),h=$2.useMemo(()=>F2("id",T,lN0),[T]),b=m8(X??vq),v=m8(K??nX),g=U?.text??N,u=$2.useMemo(()=>{return{addFontsFromNode:f$,...g,tipTapConfig:{extensions:wZ,...g?.tipTapConfig}}},[g]),n=$2.useMemo(()=>({...U,text:u}),[U,u]),o=$2.useMemo(()=>[...b,...v],[b,v]),K0=fL(B.assetUrls);if(R.find((y0)=>y0.type==="embed")&&F)Dq.setEmbedDefinitions(F);return $9.jsx(B$,{assetUrls:gL(B.assetUrls),children:$9.jsx(L$,{overrides:TB(B.overrides),locale:V??B.user?.userPreferences.get().locale??v6.locale,children:$9.jsx(_R,{initialState:"select",...B,components:j,shapeUtils:R,bindingUtils:A,assetUtils:C,overlayUtils:f,tools:h,options:n,assetUrls:K0,children:$9.jsxs(MT,{...B,components:j,mediaMimeTypes:o,children:[$9.jsx(dN0,{maxImageDimension:Z,maxAssetSize:q,acceptedImageMimeTypes:b,acceptedVideoMimeTypes:v,onMount:Y}),Q]})})})})}function dN0({maxImageDimension:J,maxAssetSize:Q,acceptedImageMimeTypes:Z,acceptedVideoMimeTypes:q,onMount:X}){let K=y(),Y=C5(),W=t(),z=o0();VU(()=>{let $=[];$.push(fb(K)),K.fonts.requestFonts(cE);let _=K.getThemes();for(let F of Object.values(_))for(let U of Object.keys(F.fonts)){let V=F.fonts[U];if(V.faces?.length)K.fonts.requestFonts(V.faces)}return K.once("edit",()=>z("edit",{source:"unknown"})),iE(K,{maxImageDimension:J,maxAssetSize:Q,acceptedImageMimeTypes:Z,acceptedVideoMimeTypes:q,toasts:Y,msg:W}),$.push(K.store.props.onMount(K)),$.push(X?.(K)),()=>{$.forEach((F)=>F?.())}});let{Canvas:G}=T4(),{ContextMenu:H}=N4();if(H)return $9.jsx(H,{});if(G)return $9.jsx(G,{});return null}var RT=E(c(),1);var l9=E(m(),1);var H00={text:{tipTapConfig:{extensions:wZ},addFontsFromNode:f$}},iN0=l9.memo(function(Q){let[Z,q]=l9.useState(null),[X,K]=l9.useState(null),Y=m8(Q.shapeUtils??[]),W=l9.useMemo(()=>F2("type",Y,bX),[Y]),z=m8(Q.bindingUtils??[]),G=l9.useMemo(()=>F2("type",z,AX),[z]),H=$R({snapshot:Q.snapshot,shapeUtils:W}),{pageId:$,bounds:_,scale:F,pixelRatio:U,background:V,padding:N,darkMode:B,preserveAspectRatio:O,format:M="svg",licenseKey:L,assetUrls:j,options:k,textOptions:R}=Q,I=l9.useMemo(()=>({...H00,...k,text:{...H00.text,...k?.text??R}}),[k,R]),A=fL(j);return l9.useLayoutEffect(()=>{if(!X)return;if(!H)return;let w=!1,C=X.ownerDocument.createElement("div");X.appendChild(C),X.classList.add("tl-container","tl-theme__light");let x=new G0({store:H,shapeUtils:W,bindingUtils:G,tools:[],getContainer:()=>C,licenseKey:L,fontAssetUrls:A.fonts,options:I});if($)x.setCurrentPage($);let f=x.getCurrentPageShapeIds();async function T(){let h=await x.toImage([...f],{bounds:_,scale:F,background:V,padding:N,darkMode:B,preserveAspectRatio:O,format:M});if(!h||w)return;let b=URL.createObjectURL(h.blob);q(b),x.dispose()}return T(),()=>{w=!0}},[M,X,H,W,G,$,_,F,V,N,B,O,L,U,A,I]),l9.useEffect(()=>{return()=>{if(Z)URL.revokeObjectURL(Z)}},[Z]),RT.jsx("div",{ref:K,style:{position:"relative",width:"100%",height:"100%"},children:Z&&RT.jsx("img",{src:Z,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})})});var XJ=E(c(),1);var uL=E(m(),1);var nN0=uL.memo(function({children:Q}){let Z=t(),q=A1(),X=uL.useRef(null);r6(X);let K=Q??XJ.jsx(vI,{});if(q<e0.MOBILE)return null;return XJ.jsx("div",{ref:X,className:"tlui-help-menu",children:XJ.jsxs(XQ,{id:"help menu",children:[XJ.jsx(KQ,{children:XJ.jsx(w0,{type:"help",title:Z("help-menu.title"),"data-testid":"help-menu.button",children:XJ.jsx(z0,{icon:"question-mark",small:!0})})}),XJ.jsx(YQ,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:XJ.jsx(z4,{type:"menu",sourceId:"help-menu",children:K})})]})})});var $_=E(c(),1);var _00=E(c1(),1);var F00=E(m(),1);var sN0=F00.forwardRef(function({children:Q,className:Z},q){return $_.jsxs(o$.Trigger,{ref:q,className:_00.default("tlui-button tlui-select__trigger",Z),children:[Q,$_.jsx(o$.Icon,{className:"tlui-select__chevron",children:$_.jsx(S6,{icon:"chevron-down",label:"",small:!0})})]})});var rN0=E(c(),1),kT=E(m(),1);var p9={White:"white",LightGray:"lightGray",Gray:"gray",Black:"black",Green:"green",Cyan:"cyan",Blue:"blue",Indigo:"indigo",Violet:"violet",Red:"red",Orange:"orange",Yellow:"yellow"},vX={Small:"small",Medium:"medium",Large:"large"},H_={Draw:"draw",Solid:"solid",Dashed:"dashed",Dotted:"dotted"},TQ={Start:"start",Middle:"middle",End:"end",Justify:"justify"},__={Script:"script",Sans:"sans",Serif:"serif",Mono:"mono"};var eB1={[p9.White]:"black",[p9.Black]:"black",[p9.LightGray]:"grey",[p9.Gray]:"grey",[p9.Green]:"light-green",[p9.Cyan]:"green",[p9.Blue]:"light-blue",[p9.Indigo]:"blue",[p9.Orange]:"orange",[p9.Yellow]:"yellow",[p9.Red]:"red",[p9.Violet]:"light-violet"},JO1={[__.Mono]:"mono",[__.Sans]:"sans",[__.Script]:"draw",[__.Serif]:"serif"},QO1={[TQ.Start]:"start",[TQ.Middle]:"middle",[TQ.End]:"end",[TQ.Justify]:"start"},ZO1={[TQ.Start]:"start",[TQ.Middle]:"middle",[TQ.End]:"end",[TQ.Justify]:"start"},qO1={[vX.Small]:"s",[vX.Medium]:"l",[vX.Large]:"xl"},XO1={[vX.Small]:"m",[vX.Medium]:"l",[vX.Large]:"xl"},KO1={[H_.Solid]:"solid",[H_.Dashed]:"dashed",[H_.Dotted]:"dotted",[H_.Draw]:"draw"};var oN0=P.object({schemaVersion:P.literal(1),storeVersion:P.positiveInteger,recordVersions:P.dict(P.string,P.object({version:P.positiveInteger,subTypeVersions:P.dict(P.string,P.positiveInteger).optional(),subTypeKey:P.string.optional()}))}),tN0=P.object({schemaVersion:P.literal(2),sequences:P.dict(P.string,P.positiveInteger)}),GO1=P.object({tldrawFileFormatVersion:P.nonZeroInteger,schema:P.numberUnion("schemaVersion",{1:oN0,2:tN0}),records:P.arrayOf(P.object({id:P.string,typeName:P.string}).allowUnknownProperties())});y5("tldraw","5.2.3","esm");var SX=E(m(),1);function eN0(J){if(!J||typeof J!=="object")return null;let Q=J.sequences;if(!Q||typeof Q!=="object")return null;let Z={};for(let[q,X]of Object.entries(Q))if(typeof X==="number")Z[q]=X;return Object.keys(Z).length>0?Z:null}function U00(J,Q){let Z=eN0(J);if(!Z)return[];let q=[];for(let[X,K]of Object.entries(Z)){let Y=Q[X];if(Y===void 0)q.push({id:X,fileVersion:K});else if(K>Y)q.push({id:X,fileVersion:K,runtimeVersion:Y})}return q}function V00(J,Q){if(J)return`moi ${J.moi}, tldraw ${J.tldraw}`;return Q.map((Z)=>Z.runtimeVersion===void 0?`${Z.id} v${Z.fileVersion} (unknown here)`:`${Z.id} v${Z.fileVersion} > v${Z.runtimeVersion}`).join(", ")}var H9=E(c(),1),N00=null;function JB0(){return N00??=j2({shapeUtils:bX,bindingUtils:AX}).schema,N00}function ET(J,Q){let Z=JB0();try{if(Z.migrateStoreSnapshot(J).type==="success")return null}catch{}let q=U00(J.schema,Z.serialize().sequences);if(q.length>0)return{newer:!0,writer:Q,detail:V00(Q,q)};return{newer:!1,writer:Q,detail:"The saved snapshot failed to load."}}function O00(J){let[Q,Z]=SX.useState(!1),[q,X]=SX.useState(null),K=SX.useRef(void 0);return SX.useEffect(()=>{let Y=!1;return Z(!1),X(null),K.current=void 0,fetch(`/api/workspaces/${J}/scratchpad`).then((W)=>W.json()).then((W)=>{if(Y)return;if(W?.document){let z=ET(W.document,W.writer);if(z)X(z);else K.current=W.document}Z(!0)}).catch(()=>{if(!Y)Z(!0)}),()=>{Y=!0}},[J]),{loaded:Q,snapshot:K.current,skew:q,flagSkew:X}}function L00({skew:J}){return H9.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-muted/40 bg-[radial-gradient(var(--color-border)_1px,transparent_1px)] [background-size:16px_16px] p-6",children:H9.jsxs("div",{className:"flex max-w-md animate-in flex-col gap-3 rounded-lg bg-background p-6 shadow-xs duration-200 fade-in-0 zoom-in-95",children:[H9.jsxs("div",{className:"flex items-center gap-2",children:[H9.jsx(B00,{size:20,stroke:1.5,className:"shrink-0 text-amber-600"}),H9.jsx("h2",{className:"font-medium text-foreground",children:J.newer?"This canvas needs a newer moi":"This canvas couldn’t be loaded"})]}),J.newer?H9.jsxs(H9.Fragment,{children:[H9.jsxs("p",{className:"text-sm text-pretty text-muted-foreground",children:["This scratchpad was saved by a newer version of moi",J.writer?` (v${J.writer.moi})`:"",".",H9.jsx("br",{})," Please update moi and restart the server:"]}),H9.jsx("code",{className:"self-start rounded bg-muted px-2 py-1 font-mono text-xs text-foreground",children:"bun install -g moi-computer@latest"})]}):H9.jsx("p",{className:"text-sm text-muted-foreground",children:J.detail})]})})}var jq=E(m(),1);var u4=E(c(),1),QB0=[{kind:"tool",id:"select",label:"Select",Icon:C00},{kind:"tool",id:"hand",label:"Hand",Icon:k00},{kind:"sep"},{kind:"tool",id:"draw",label:"Pencil",Icon:PT},{kind:"geo",label:"Rectangle",Icon:P00},{kind:"tool",id:"note",label:"Sticker",Icon:I00},{kind:"tool",id:"text",label:"Text",Icon:IT},{kind:"tool",id:"line",label:"Line",Icon:A00},{kind:"tool",id:"arrow",label:"Arrow",Icon:j00},{kind:"sep"},{kind:"tool",id:"highlight",label:"Highlighter",Icon:E00},{kind:"tool",id:"eraser",label:"Eraser",Icon:R00}];function AT({label:J,active:Q,Icon:Z,onClick:q}){return u4.jsx(w00,{type:"button",size:"icon",variant:Q?"default":"ghost","aria-label":J,title:J,onClick:q,className:yQ(!Q&&"text-muted-foreground hover:text-foreground"),children:u4.jsx(Z,{stroke:1.5})})}function D00(J,Q){if(Q==="geo")J.setStyleForNextShapes(T6,"draw"),J.setStyleForNextShapes(e4,"m");else if(Q==="note")J.setStyleForNextShapes(I4,"draw"),J.setStyleForNextShapes(R9,"middle"),J.setStyleForNextShapes(k9,"middle"),M00(J,"sticker","yellow");else if(Q==="text")J.setStyleForNextShapes(I4,"draw"),J.setStyleForNextShapes(R9,"middle"),J.setStyleForNextShapes(k9,"middle");else if(Q==="highlight")M00(J,"highlight","yellow");else if(Q==="arrow")J.setStyleForNextShapes(T6,"draw");else if(Q==="draw"||Q==="line"){let Z=J.getStyleForNextShape(T6);if(Z!=="draw"&&Z!=="dashed")J.setStyleForNextShapes(T6,"draw")}}function T00({editor:J}){let[Q,Z]=jq.useState(()=>J.getCurrentToolId());jq.useEffect(()=>{return Z(J.getCurrentToolId()),g1("scratch current tool",()=>Z(J.getCurrentToolId()))},[J]);let q=(K)=>{J.run(()=>{D00(J,K),J.setCurrentTool(K)})},X=()=>{J.run(()=>{J.setStyleForNextShapes(x6,"rectangle"),D00(J,"geo"),J.setCurrentTool("geo")})};return u4.jsx("div",{className:"absolute top-1/2 left-2 z-10 -translate-y-1/2",children:u4.jsx(b00.div,{initial:{x:-72,opacity:0},animate:{x:0,opacity:1},transition:{type:"spring",bounce:0.2,duration:0.55},className:"flex flex-col gap-1 rounded-xl bg-background/95 p-1 shadow-md backdrop-blur",children:QB0.map((K,Y)=>{if(K.kind==="sep")return u4.jsx("div",{className:"mx-1 my-0.5 h-px bg-border"},`sep-${Y}`);if(K.kind==="geo")return u4.jsx(AT,{label:K.label,Icon:K.Icon,active:Q==="geo",onClick:X},"geo");if(K.kind==="menu")return u4.jsx(AT,{label:K.label,Icon:K.Icon,active:!1,onClick:()=>{}},"menu");return u4.jsx(AT,{label:K.label,Icon:K.Icon,active:Q===K.id,onClick:()=>q(K.id)},K.id)})})})}var ZB0=["color","size","dash","fill"],y00={draw:["color","size","dash"],geo:["color","fill"],note:["color","size"],text:["color","size"],line:["color","dash","size"],highlight:["color","size"],arrow:["color","size"]},qB0={draw:["color","size","dash"],geo:["color","fill"],note:["color","size"],text:["color","size"],line:["color","dash","size"],highlight:["color","size"],arrow:["color","size"]},x00={regular:{swatches:[{value:"black",klass:"bg-[#1d1d1d]"},{value:"red",klass:"bg-[#e03131]"},{value:"yellow",klass:"bg-[#f1ac4b]"},{value:"green",klass:"bg-[#099268]"},{value:"blue",klass:"bg-[#4465e9]"},{value:"grey",klass:"bg-[#9fa8b2]"}]},highlight:{swatches:[{value:"yellow",klass:"bg-[#fddd00]"},{value:"green",klass:"bg-[#00ffc8]"},{value:"blue",klass:"bg-[#10acff]"}]},sticker:{swatches:[{value:"yellow",klass:"bg-[#fed49a]"},{value:"blue",klass:"bg-[#8aa3ff]"},{value:"green",klass:"bg-[#6fc896]"}]}};function XB0(J){let Q=J.getCurrentToolId();if(Q==="highlight")return"highlight";if(Q==="note")return"sticker";if(y00[Q])return"regular";let Z=new Set(J.getSelectedShapeIds().map((q)=>J.getShape(q)?.type));if(Z.size===1){if(Z.has("highlight"))return"highlight";if(Z.has("note"))return"sticker"}return"regular"}function M00(J,Q,Z){if(!x00[Q].swatches.map((X)=>X.value).includes(J.getStyleForNextShape(_1)))J.setStyleForNextShapes(_1,Z)}var KB0=[{value:"m",label:"Small",dot:"size-1.5",glyph:16},{value:"xl",label:"Large",dot:"size-3",glyph:24}],YB0=[{value:"draw",label:"Rough",preview:"border-b-2 border-current"},{value:"dashed",label:"Dash",preview:"border-b-2 border-dashed border-current"}],WB0=[{value:"none",label:"None",preview:"border border-foreground/50"},{value:"solid",label:"Semi",preview:"border border-foreground/40 bg-foreground/25"},{value:"fill",label:"Solid",preview:"border border-foreground bg-foreground"},{value:"pattern",label:"Pattern",preview:"border border-foreground/40 bg-[repeating-linear-gradient(45deg,currentColor_0,currentColor_1px,transparent_1px,transparent_3px)]"}];function mL(J,Q){if(J.getSelectedShapeIds().length>0)return J.getSharedStyles().getAsKnownValue(Q);return J.getStyleForNextShape(Q)}function cL(J,Q,Z){J.run(()=>{if(J.setStyleForNextShapes(Q,Z),J.getSelectedShapeIds().length>0)J.setStyleForSelectedShapes(Q,Z)})}function zB0(J){let Q=y00[J.getCurrentToolId()];if(Q)return Q;let Z=J.getSelectedShapeIds();if(Z.length===0)return[];let q=new Set;for(let X of Z){let K=J.getShape(X);if(!K)continue;for(let Y of qB0[K.type]??[])q.add(Y)}return ZB0.filter((X)=>q.has(X))}function GB0(J){let Q=J.getCurrentToolId();if(Q==="draw")return"pen";if(Q==="text")return"letter";let Z=J.getSelectedShapeIds(),q=new Set(Z.map((X)=>J.getShape(X)?.type));if(q.size===1){if(q.has("draw"))return"pen";if(q.has("text"))return"letter"}return"dot"}function CT(J){return{controls:zB0(J),palette:x00[XB0(J)],color:mL(J,_1),size:mL(J,e4),sizeGlyph:GB0(J),dash:mL(J,T6),fill:mL(J,y6)}}function v00({editor:J}){let[Q,Z]=jq.useState(()=>CT(J));if(jq.useEffect(()=>{return Z(CT(J)),g1("scratch styles",()=>Z(CT(J)))},[J]),Q.controls.length===0)return null;let q={color:u4.jsx("div",{className:"flex flex-col items-center gap-2 pt-1",children:Q.palette.swatches.map((X)=>u4.jsx("button",{type:"button",title:X.value,onClick:()=>cL(J,_1,X.value),className:yQ("size-5.5 rounded-full ring-offset-1 ring-offset-background",X.klass,Q.color===X.value?"ring-2 ring-primary":"ring-1 ring-black/15")},X.value))}),size:u4.jsx("div",{className:"flex flex-col items-center gap-1 text-foreground",children:KB0.map((X)=>u4.jsx("button",{type:"button",title:X.label,onClick:()=>cL(J,e4,X.value),className:yQ("flex size-7.5 items-center justify-center rounded-full hover:bg-accent hover:text-accent-foreground",Q.size===X.value&&"bg-accent text-accent-foreground"),children:Q.sizeGlyph==="pen"?u4.jsx(PT,{size:20,stroke:1.5}):Q.sizeGlyph==="letter"?u4.jsx(IT,{size:X.glyph,stroke:X.glyph===16?1.75:1.5}):u4.jsx("span",{className:yQ("rounded-full bg-current",X.dot)})},X.value))}),dash:u4.jsx("div",{className:"flex flex-col items-center gap-1 text-foreground",children:YB0.map((X)=>u4.jsx("button",{type:"button",title:X.label,onClick:()=>cL(J,T6,X.value),className:yQ("flex size-7.5 items-center justify-center rounded-full hover:bg-accent hover:text-accent-foreground",Q.dash===X.value&&"bg-accent text-accent-foreground"),children:u4.jsx("span",{className:yQ("w-3.5",X.preview)})},X.value))}),fill:u4.jsx("div",{className:"flex flex-col items-center gap-1 text-foreground",children:WB0.map((X)=>u4.jsx("button",{type:"button",title:X.label,onClick:()=>cL(J,y6,X.value),className:yQ("flex size-7.5 items-center justify-center rounded-full hover:bg-accent hover:text-accent-foreground",Q.fill===X.value&&"bg-accent text-accent-foreground"),children:u4.jsx("span",{className:yQ("size-4.5 rounded-lg",X.preview)})},X.value))})};return u4.jsx("div",{className:"absolute top-1/2 left-14 z-10 flex -translate-y-1/2 flex-col items-center gap-1.5 rounded-full bg-background/95 px-1 py-1 shadow-[0_2px_8px_rgba(0,0,0,0.08),0_4px_16px_rgba(0,0,0,0.06),0_0_0_1px_rgba(0,0,0,0.04)] backdrop-blur",children:Q.controls.map((X,K)=>u4.jsxs(jq.Fragment,{children:[K>0&&u4.jsx("div",{className:"h-px w-5 bg-border"}),q[X]]},X))})}var S8=E(c(),1),S00=Math.random().toString(36).slice(2),$B0=500,HB0=void 0;function _B0(J){return async(Q)=>{if(Q.kind!=="view")throw Error(`Scratchpad op "${Q.kind}" runs on the server, not the browser.`);let Z=[...J.getCurrentPageShapeIds()];if(Z.length===0)throw Error("Canvas is empty — nothing to view.");let{url:q}=await J.toImageDataUrl(Z,{format:"png",background:!0,padding:32});return{image:q}}}function FB0(J){let Q=`/api/workspaces/${J}/scratchpad/assets`;return{async upload(Z,q){let X=await fetch(Q,{method:"POST",headers:{"Content-Type":q.type||"application/octet-stream"},body:q});if(!X.ok)throw Error(`Upload failed: ${await X.text()}`);let{src:K}=await X.json();return{src:K}},resolve(Z){let q=Z.props.src;if(q?.startsWith("asset:"))return`${Q}/${q.slice(6)}`;return q}}}function UB0(){return S8.jsx("div",{className:"absolute inset-0 bg-[color-mix(in_oklch,var(--muted),var(--background)_50%)]"})}function VB0({x:J,y:Q,z:Z,size:q}){let X=D5("scratch-grid"),K=y(),Y=K.options.gridSteps[0]?.step??1;for(let _ of K.options.gridSteps)if(Z>=_.min)Y=_.step;let W=Y*q*Z,z=0.5+J*Z,G=0.5+Q*Z,H=z>0?z%W:W+z%W,$=G>0?G%W:W+G%W;return S8.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[S8.jsx("defs",{children:S8.jsx("pattern",{id:X,width:W,height:W,patternUnits:"userSpaceOnUse",children:S8.jsx("circle",{className:"fill-accent",cx:H,cy:$,r:1})})}),S8.jsx("rect",{width:"100%",height:"100%",fill:`url(#${X})`})]})}var NB0={Background:UB0,Grid:VB0,Toolbar:null,StylePanel:null,Minimap:null,MainMenu:null,PageMenu:null,ActionsMenu:null,QuickActions:null,HelpMenu:null,DebugMenu:null,ZoomMenu:null},BB0={tools(J,Q){return delete Q.frame,delete Q.laser,Q},actions(J,Q){for(let Z of["export-as-svg","export-as-png","copy-as-svg","copy-as-png","print"])delete Q[Z];return Q}},OB0={maxPages:1},LB0=33554432,DB0=2048;function sj1(){let J=g00(),Q=H2.useRef(null),Z=H2.useRef(null),q=H2.useRef(null),X=H2.useRef(!1),[K,Y]=H2.useState(null),{loaded:W,snapshot:z,skew:G,flagSkew:H}=O00(J),$=H2.useRef(null);if($.current?.id!==J)$.current={id:J,store:FB0(J)};let _=$.current.store,F=H2.useCallback(()=>{let V=Q.current;if(!V)return;let N;try{N=OG(V.store).document}catch{return}fetch(`/api/workspaces/${J}/scratchpad`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({document:N,origin:S00})}).catch(()=>{})},[J]);f00((V)=>{if(V.type!=="scratchpad:updated"||V.workspaceId!==J)return;if(V.origin&&V.origin===S00)return;if(!Q.current)return;fetch(`/api/workspaces/${J}/scratchpad`).then((N)=>N.json()).then((N)=>{let B=Q.current;if(!B||!N?.document)return;let O=ET(N.document,N.writer);if(O){if(q.current)clearTimeout(q.current);H(O);return}X.current=!0,z3(B.store,{document:N.document})}).catch(()=>{})});let U=H2.useCallback((V)=>{Q.current=V,Y(V),V.updateInstanceState({isGridMode:!0}),V.run(()=>{V.setStyleForNextShapes(I4,"draw"),V.setStyleForNextShapes(R9,"middle"),V.setStyleForNextShapes(k9,"middle"),V.setStyleForNextShapes(y6,"fill")});let N=V.store.listen(()=>{if(X.current){X.current=!1;return}if(q.current)clearTimeout(q.current);q.current=setTimeout(F,$B0)},{source:"user",scope:"document"});wT(J,_B0(V));let B=(M)=>{let L=M.target;if(!!L&&!!Z.current?.contains(L)){if(!V.getIsFocused())V.focus()}else if(V.getIsFocused())V.blur()},O=V.getContainer().ownerDocument;return O.addEventListener("pointerdown",B,!0),V.focus(),()=>{if(N(),O.removeEventListener("pointerdown",B,!0),q.current)clearTimeout(q.current);wT(J,null),Y(null),Q.current=null}},[J,F]);if(!W)return S8.jsx("div",{className:"min-h-0 flex-1 bg-muted/40"});if(G)return S8.jsx(L00,{skew:G});return S8.jsxs("div",{ref:Z,className:"relative min-h-0 flex-1 overflow-hidden",children:[S8.jsx("div",{className:"absolute inset-0",children:S8.jsx(jT,{snapshot:z,assets:_,licenseKey:HB0,onMount:U,components:NB0,overrides:BB0,options:OB0,maxAssetSize:LB0,maxImageDimension:DB0,autoFocus:!1})}),K&&S8.jsx(T00,{editor:K}),K&&S8.jsx(v00,{editor:K})]})}export{sj1 as Scratchpad};
|
|
546
|
+
`).map((x,f)=>xX.jsx("div",{dir:"auto",children:x},f))}),(k||$)&&xX.jsx(BT,{ref:M,text:q,isEditing:j,shapeId:Q,...R,handleKeyDown:F??R.handleKeyDown})]})})});var $9=E(c(),1);var $2=E(m(),1);var Y00=E(m(),1);var K00=E(m(),1),z_={fonts:{tldraw_mono:`${Q6()}/fonts/IBMPlexMono-Medium.woff2`,tldraw_mono_italic:`${Q6()}/fonts/IBMPlexMono-MediumItalic.woff2`,tldraw_mono_bold:`${Q6()}/fonts/IBMPlexMono-Bold.woff2`,tldraw_mono_italic_bold:`${Q6()}/fonts/IBMPlexMono-BoldItalic.woff2`,tldraw_serif:`${Q6()}/fonts/IBMPlexSerif-Medium.woff2`,tldraw_serif_italic:`${Q6()}/fonts/IBMPlexSerif-MediumItalic.woff2`,tldraw_serif_bold:`${Q6()}/fonts/IBMPlexSerif-Bold.woff2`,tldraw_serif_italic_bold:`${Q6()}/fonts/IBMPlexSerif-BoldItalic.woff2`,tldraw_sans:`${Q6()}/fonts/IBMPlexSans-Medium.woff2`,tldraw_sans_italic:`${Q6()}/fonts/IBMPlexSans-MediumItalic.woff2`,tldraw_sans_bold:`${Q6()}/fonts/IBMPlexSans-Bold.woff2`,tldraw_sans_italic_bold:`${Q6()}/fonts/IBMPlexSans-BoldItalic.woff2`,tldraw_draw:`${Q6()}/fonts/Shantell_Sans-Informal_Regular.woff2`,tldraw_draw_italic:`${Q6()}/fonts/Shantell_Sans-Informal_Regular_Italic.woff2`,tldraw_draw_bold:`${Q6()}/fonts/Shantell_Sans-Informal_Bold.woff2`,tldraw_draw_italic_bold:`${Q6()}/fonts/Shantell_Sans-Informal_Bold_Italic.woff2`}};function fL(J){return K00.useMemo(()=>{if(!J)return z_;return{fonts:{...z_.fonts,...J?.fonts}}},[J])}var OT=["align-bottom","align-center-horizontal","align-center-vertical","align-left","align-right","align-top","alt","arrow-arc","arrow-cycle","arrow-elbow","arrow-left","arrowhead-arrow","arrowhead-bar","arrowhead-diamond","arrowhead-dot","arrowhead-none","arrowhead-square","arrowhead-triangle-inverted","arrowhead-triangle","blob","bold","bookmark","bring-forward","bring-to-front","broken","bulletList","check-circle","check","chevron-down","chevron-left","chevron-right","chevron-up","chevrons-ne","chevrons-sw","clipboard-copied","clipboard-copy","code","color","comment","corners","crop","cross-2","cross-circle","dash-dashed","dash-dotted","dash-draw","dash-solid","disconnected","discord","distribute-horizontal","distribute-vertical","dot","dots-horizontal","dots-vertical","download","drag-handle-dots","duplicate","edit","external-link","fill-fill","fill-lined-fill","fill-none","fill-pattern","fill-semi","fill-solid","follow","following","font-draw","font-mono","font-sans","font-serif","geo-arrow-down","geo-arrow-left","geo-arrow-right","geo-arrow-up","geo-check-box","geo-cloud","geo-diamond","geo-ellipse","geo-heart","geo-hexagon","geo-octagon","geo-oval","geo-pentagon","geo-rectangle","geo-rhombus-2","geo-rhombus","geo-star","geo-trapezoid","geo-triangle","geo-x-box","github","group","heading","help-circle","highlight","horizontal-align-end","horizontal-align-middle","horizontal-align-start","info-circle","italic","leading","link","list","lock","manual","menu","minus","mixed","pack","plus","question-mark-circle","question-mark","redo","reset-zoom","rotate-ccw","rotate-cw","send-backward","send-to-back","share-1","size-extra-large","size-large","size-medium","size-small","spline-cubic","spline-line","stack-horizontal","stack-vertical","status-offline","stretch-horizontal","stretch-vertical","strike","text-align-center","text-align-left","text-align-right","toggle-off","toggle-on","tool-arrow","tool-eraser","tool-frame","tool-hand","tool-highlight","tool-laser","tool-line","tool-media","tool-note","tool-pencil","tool-pointer","tool-screenshot","tool-text","trash","twitter","underline","undo","ungroup","unlock","vertical-align-end","vertical-align-middle","vertical-align-start","warning-triangle","zoom-in","zoom-out"];var G_={...z_,icons:Object.fromEntries(OT.map((J)=>[J,`${Q6()}/icons/icon/0_merged.svg#${J}`])),translations:Object.fromEntries(L2.map((J)=>[J.locale,`${Q6()}/translations/${J.locale}.json`])),embedIcons:Object.fromEntries(mY.map((J)=>[J.type,`${Q6()}/embed-icons/${J.type}.png`]))};function gL(J){return Y00.useMemo(()=>{if(!J)return G_;return{fonts:Object.assign({...G_.fonts},{...J?.fonts}),icons:Object.assign({...G_.icons},{...J?.icons}),embedIcons:Object.assign({...G_.embedIcons},{...J?.embedIcons}),translations:Object.assign({...G_.translations},{...J?.translations})}},[J])}var LT=E(c(),1);function W00(){let{Spinner:J}=T4();return LT.jsx(FR,{children:J?LT.jsx(J,{}):null})}var U1=E(c(),1);var $00=E(c1(),1),c9=E(m(),1);var G9=E(c(),1);var DT=p1(function({overrides:Q,components:Z,assetUrls:q,onUiEvent:X,forceMobile:K,mediaMimeTypes:Y,children:W}){let z=J1();return G9.jsx(rP.Provider,{value:Y,children:G9.jsx(B$,{assetUrls:gL(q),children:G9.jsx(L$,{overrides:TB(Q),locale:z?.user.getLocale()??v6.locale,children:G9.jsx(VP,{children:G9.jsx(jP,{onEvent:X,children:G9.jsx(gP,{children:G9.jsx(SP,{context:"tla",children:G9.jsx(mk,{children:G9.jsx(LP,{forceMobile:K,children:G9.jsx(Iw,{overrides:Z,children:G9.jsx(uN0,{overrides:Q,children:W})})})})})})})})})})})});function uN0({overrides:J,children:Q}){let Z=lr(J);return G9.jsx(Lt,{overrides:Z.actions,children:G9.jsx(ir,{overrides:Z.tools,children:Q})})}var z00=E(m(),1);function G00(){let J=y(),{addToast:Q}=C5();z00.useEffect(()=>{function Z({name:q,count:X}){Q({title:"Maximum shapes reached",description:`You've reached the maximum number of shapes allowed on ${q} (${X}). Please delete some shapes or move to a different page to continue.`,severity:"warning"})}return J.addListener("max-shapes",Z),()=>{J.removeListener("max-shapes",Z)}},[J,Q])}var MT=c9.default.memo(function({renderDebugMenuItems:Q,children:Z,hideUi:q,components:X,...K}){return U1.jsx(DT,{...K,components:X,children:U1.jsx(mN0,{hideUi:q,renderDebugMenuItems:Q,children:Z})})}),mN0=c9.default.memo(function({children:Q,hideUi:Z,...q}){return Dw(),dP(),U1.jsxs(U1.Fragment,{children:[Q,Z?null:U1.jsx(cN0,{...q})]})}),cN0=c9.default.memo(function(){let Q=y(),Z=t(),q=A1(),X=I6(),K=S("focus",()=>Q.getInstanceState().isFocusMode,[Q]),Y=S("debug",()=>Q.getInstanceState().isDebugMode,[Q]),W=Q1(),z=t0(),G=S("locale",()=>Q.user.getLocale(),[Q]);c9.useEffect(()=>{W.dir=z,W.lang=G},[W,z,G]);let{SharePanel:H,TopPanel:$,MenuPanel:_,StylePanel:F,Toolbar:U,HelpMenu:V,NavigationPanel:N,HelperButtons:B,DebugPanel:O,Toasts:M,Dialogs:L,A11y:j,FollowingIndicator:k}=N4();G00();let R=c9.useRef(!1),I=c9.useRef(-1),[A,w]=c9.useState(!1);FJ("update hide toolbar while delayed",()=>{if(!(S0.isIos||S0.isAndroid))return;if(Q.getEditingShapeId()===null){if(R.current)if(R.current=!1,clearTimeout(I.current),S0.isAndroid)I.current=Q.timers.setTimeout(()=>{w(!1)},150);else w(!1);return}if(!R.current)R.current=!0,clearTimeout(I.current),w(!0)},[]);let{"toggle-focus-mode":C}=f6(),{breakpointsAbove:x,breakpointsBelow:f}=c9.useMemo(()=>{let T=[],h=[];for(let b=0;b<lY.length;b++)if(b<=q)T.push(b);else h.push(b);return{breakpointsAbove:T,breakpointsBelow:h}},[q]);return U1.jsxs("div",{className:$00.default("tlui-layout",{"tlui-layout__mobile":q<e0.TABLET_SM}),role:"document","data-iseditinganything":A,"data-breakpoint":q,"data-breakpoints-above":x.join(" "),"data-breakpoints-below":f.join(" "),children:[U1.jsx(jt,{}),K?U1.jsx("div",{className:"tlui-layout__top",children:U1.jsx(w0,{type:"icon",className:"tlui-focus-button",title:Z("focus-mode.toggle-focus-mode"),onClick:()=>C.onSelect("menu"),children:U1.jsx(z0,{icon:"dot"})})}):U1.jsxs(U1.Fragment,{children:[U1.jsxs("div",{className:"tlui-layout__top",children:[U1.jsxs("div",{className:"tlui-layout__top__left",children:[_&&U1.jsx(_,{}),B&&U1.jsx(B,{})]}),U1.jsx("div",{className:"tlui-layout__top__center",children:$&&U1.jsx($,{})}),U1.jsxs("div",{className:"tlui-layout__top__right",children:[H&&U1.jsx(H,{}),F&&q>=e0.TABLET_SM&&!X&&U1.jsx(F,{})]})]}),U1.jsxs("div",{className:"tlui-layout__bottom",children:[U1.jsxs("div",{className:"tlui-layout__bottom__main",children:[N&&U1.jsx(N,{}),U&&U1.jsx(U,{}),V&&U1.jsx(V,{})]}),Y&&O&&U1.jsx(O,{}),j&&U1.jsx(j,{})]})]}),k&&U1.jsx(k,{}),M&&U1.jsx(M,{}),L&&U1.jsx(L,{})]})});function hL(){let{RichTextToolbar:J,ImageToolbar:Q,VideoToolbar:Z,CursorChatBubble:q}=N4();return U1.jsxs(U1.Fragment,{children:[J&&U1.jsx(J,{}),Q&&U1.jsx(Q,{}),Z&&U1.jsx(Z,{}),q&&U1.jsx(q,{})]})}var lN0=[...NT,...Wb];function pN0(J,Q){let{maxImageDimension:Z,acceptedImageMimeTypes:q,acceptedVideoMimeTypes:X}=Q,K=Z!==void 0||q!==void 0,Y=X!==void 0;if(!K&&!Y)return J;return J.map((W)=>{if(K&&W.type==="image")return W.configure({...Z!==void 0&&{maxDimension:Z},...q!==void 0&&{supportedMimeTypes:q}});if(Y&&W.type==="video")return W.configure({...X!==void 0&&{supportedMimeTypes:X}});return W})}function jT(J){let{children:Q,maxImageDimension:Z,maxAssetSize:q,acceptedImageMimeTypes:X,acceptedVideoMimeTypes:K,onMount:Y,components:W={},shapeUtils:z=[],bindingUtils:G=[],assetUtils:H=[],overlayUtils:$=[],tools:_=[],embeds:F,options:U,locale:V,textOptions:N,...B}=J,O=P9(W),M=W?.InFrontOfTheCanvas,L=$2.useMemo(()=>{if(B.hideUi)return M??null;if(!M)return hL;return()=>$9.jsxs($9.Fragment,{children:[$9.jsx(hL,{}),$9.jsx(M,{})]})},[B.hideUi,M]),j=$2.useMemo(()=>({Spinner:qH,LoadingScreen:W00,...O,InFrontOfTheCanvas:L}),[O,L]),k=m8(z),R=$2.useMemo(()=>F2("type",k,bX),[k]),I=m8(G),A=$2.useMemo(()=>F2("type",I,AX),[I]),w=m8(H),C=$2.useMemo(()=>pN0(F2("type",w,iw),{maxImageDimension:Z,acceptedImageMimeTypes:X,acceptedVideoMimeTypes:K}),[w,Z,X,K]),x=m8($),f=$2.useMemo(()=>F2("type",x,nw),[x]),T=m8(_),h=$2.useMemo(()=>F2("id",T,lN0),[T]),b=m8(X??vq),v=m8(K??nX),g=U?.text??N,u=$2.useMemo(()=>{return{addFontsFromNode:f$,...g,tipTapConfig:{extensions:wZ,...g?.tipTapConfig}}},[g]),n=$2.useMemo(()=>({...U,text:u}),[U,u]),o=$2.useMemo(()=>[...b,...v],[b,v]),K0=fL(B.assetUrls);if(R.find((y0)=>y0.type==="embed")&&F)Dq.setEmbedDefinitions(F);return $9.jsx(B$,{assetUrls:gL(B.assetUrls),children:$9.jsx(L$,{overrides:TB(B.overrides),locale:V??B.user?.userPreferences.get().locale??v6.locale,children:$9.jsx(_R,{initialState:"select",...B,components:j,shapeUtils:R,bindingUtils:A,assetUtils:C,overlayUtils:f,tools:h,options:n,assetUrls:K0,children:$9.jsxs(MT,{...B,components:j,mediaMimeTypes:o,children:[$9.jsx(dN0,{maxImageDimension:Z,maxAssetSize:q,acceptedImageMimeTypes:b,acceptedVideoMimeTypes:v,onMount:Y}),Q]})})})})}function dN0({maxImageDimension:J,maxAssetSize:Q,acceptedImageMimeTypes:Z,acceptedVideoMimeTypes:q,onMount:X}){let K=y(),Y=C5(),W=t(),z=o0();VU(()=>{let $=[];$.push(fb(K)),K.fonts.requestFonts(cE);let _=K.getThemes();for(let F of Object.values(_))for(let U of Object.keys(F.fonts)){let V=F.fonts[U];if(V.faces?.length)K.fonts.requestFonts(V.faces)}return K.once("edit",()=>z("edit",{source:"unknown"})),iE(K,{maxImageDimension:J,maxAssetSize:Q,acceptedImageMimeTypes:Z,acceptedVideoMimeTypes:q,toasts:Y,msg:W}),$.push(K.store.props.onMount(K)),$.push(X?.(K)),()=>{$.forEach((F)=>F?.())}});let{Canvas:G}=T4(),{ContextMenu:H}=N4();if(H)return $9.jsx(H,{});if(G)return $9.jsx(G,{});return null}var RT=E(c(),1);var l9=E(m(),1);var H00={text:{tipTapConfig:{extensions:wZ},addFontsFromNode:f$}},iN0=l9.memo(function(Q){let[Z,q]=l9.useState(null),[X,K]=l9.useState(null),Y=m8(Q.shapeUtils??[]),W=l9.useMemo(()=>F2("type",Y,bX),[Y]),z=m8(Q.bindingUtils??[]),G=l9.useMemo(()=>F2("type",z,AX),[z]),H=$R({snapshot:Q.snapshot,shapeUtils:W}),{pageId:$,bounds:_,scale:F,pixelRatio:U,background:V,padding:N,darkMode:B,preserveAspectRatio:O,format:M="svg",licenseKey:L,assetUrls:j,options:k,textOptions:R}=Q,I=l9.useMemo(()=>({...H00,...k,text:{...H00.text,...k?.text??R}}),[k,R]),A=fL(j);return l9.useLayoutEffect(()=>{if(!X)return;if(!H)return;let w=!1,C=X.ownerDocument.createElement("div");X.appendChild(C),X.classList.add("tl-container","tl-theme__light");let x=new G0({store:H,shapeUtils:W,bindingUtils:G,tools:[],getContainer:()=>C,licenseKey:L,fontAssetUrls:A.fonts,options:I});if($)x.setCurrentPage($);let f=x.getCurrentPageShapeIds();async function T(){let h=await x.toImage([...f],{bounds:_,scale:F,background:V,padding:N,darkMode:B,preserveAspectRatio:O,format:M});if(!h||w)return;let b=URL.createObjectURL(h.blob);q(b),x.dispose()}return T(),()=>{w=!0}},[M,X,H,W,G,$,_,F,V,N,B,O,L,U,A,I]),l9.useEffect(()=>{return()=>{if(Z)URL.revokeObjectURL(Z)}},[Z]),RT.jsx("div",{ref:K,style:{position:"relative",width:"100%",height:"100%"},children:Z&&RT.jsx("img",{src:Z,referrerPolicy:"strict-origin-when-cross-origin",style:{width:"100%",height:"100%"}})})});var XJ=E(c(),1);var uL=E(m(),1);var nN0=uL.memo(function({children:Q}){let Z=t(),q=A1(),X=uL.useRef(null);r6(X);let K=Q??XJ.jsx(vI,{});if(q<e0.MOBILE)return null;return XJ.jsx("div",{ref:X,className:"tlui-help-menu",children:XJ.jsxs(XQ,{id:"help menu",children:[XJ.jsx(KQ,{children:XJ.jsx(w0,{type:"help",title:Z("help-menu.title"),"data-testid":"help-menu.button",children:XJ.jsx(z0,{icon:"question-mark",small:!0})})}),XJ.jsx(YQ,{side:"top",align:"end",alignOffset:0,sideOffset:8,children:XJ.jsx(z4,{type:"menu",sourceId:"help-menu",children:K})})]})})});var $_=E(c(),1);var _00=E(c1(),1);var F00=E(m(),1);var sN0=F00.forwardRef(function({children:Q,className:Z},q){return $_.jsxs(o$.Trigger,{ref:q,className:_00.default("tlui-button tlui-select__trigger",Z),children:[Q,$_.jsx(o$.Icon,{className:"tlui-select__chevron",children:$_.jsx(S6,{icon:"chevron-down",label:"",small:!0})})]})});var rN0=E(c(),1),kT=E(m(),1);var p9={White:"white",LightGray:"lightGray",Gray:"gray",Black:"black",Green:"green",Cyan:"cyan",Blue:"blue",Indigo:"indigo",Violet:"violet",Red:"red",Orange:"orange",Yellow:"yellow"},vX={Small:"small",Medium:"medium",Large:"large"},H_={Draw:"draw",Solid:"solid",Dashed:"dashed",Dotted:"dotted"},TQ={Start:"start",Middle:"middle",End:"end",Justify:"justify"},__={Script:"script",Sans:"sans",Serif:"serif",Mono:"mono"};var eB1={[p9.White]:"black",[p9.Black]:"black",[p9.LightGray]:"grey",[p9.Gray]:"grey",[p9.Green]:"light-green",[p9.Cyan]:"green",[p9.Blue]:"light-blue",[p9.Indigo]:"blue",[p9.Orange]:"orange",[p9.Yellow]:"yellow",[p9.Red]:"red",[p9.Violet]:"light-violet"},JO1={[__.Mono]:"mono",[__.Sans]:"sans",[__.Script]:"draw",[__.Serif]:"serif"},QO1={[TQ.Start]:"start",[TQ.Middle]:"middle",[TQ.End]:"end",[TQ.Justify]:"start"},ZO1={[TQ.Start]:"start",[TQ.Middle]:"middle",[TQ.End]:"end",[TQ.Justify]:"start"},qO1={[vX.Small]:"s",[vX.Medium]:"l",[vX.Large]:"xl"},XO1={[vX.Small]:"m",[vX.Medium]:"l",[vX.Large]:"xl"},KO1={[H_.Solid]:"solid",[H_.Dashed]:"dashed",[H_.Dotted]:"dotted",[H_.Draw]:"draw"};var oN0=P.object({schemaVersion:P.literal(1),storeVersion:P.positiveInteger,recordVersions:P.dict(P.string,P.object({version:P.positiveInteger,subTypeVersions:P.dict(P.string,P.positiveInteger).optional(),subTypeKey:P.string.optional()}))}),tN0=P.object({schemaVersion:P.literal(2),sequences:P.dict(P.string,P.positiveInteger)}),GO1=P.object({tldrawFileFormatVersion:P.nonZeroInteger,schema:P.numberUnion("schemaVersion",{1:oN0,2:tN0}),records:P.arrayOf(P.object({id:P.string,typeName:P.string}).allowUnknownProperties())});y5("tldraw","5.2.3","esm");var SX=E(m(),1);function eN0(J){if(!J||typeof J!=="object")return null;let Q=J.sequences;if(!Q||typeof Q!=="object")return null;let Z={};for(let[q,X]of Object.entries(Q))if(typeof X==="number")Z[q]=X;return Object.keys(Z).length>0?Z:null}function U00(J,Q){let Z=eN0(J);if(!Z)return[];let q=[];for(let[X,K]of Object.entries(Z)){let Y=Q[X];if(Y===void 0)q.push({id:X,fileVersion:K});else if(K>Y)q.push({id:X,fileVersion:K,runtimeVersion:Y})}return q}function V00(J,Q){if(J)return`moi ${J.moi}, tldraw ${J.tldraw}`;return Q.map((Z)=>Z.runtimeVersion===void 0?`${Z.id} v${Z.fileVersion} (unknown here)`:`${Z.id} v${Z.fileVersion} > v${Z.runtimeVersion}`).join(", ")}var H9=E(c(),1),N00=null;function JB0(){return N00??=j2({shapeUtils:bX,bindingUtils:AX}).schema,N00}function ET(J,Q){let Z=JB0();try{if(Z.migrateStoreSnapshot(J).type==="success")return null}catch{}let q=U00(J.schema,Z.serialize().sequences);if(q.length>0)return{newer:!0,writer:Q,detail:V00(Q,q)};return{newer:!1,writer:Q,detail:"The saved snapshot failed to load."}}function O00(J){let[Q,Z]=SX.useState(!1),[q,X]=SX.useState(null),K=SX.useRef(void 0);return SX.useEffect(()=>{let Y=!1;return Z(!1),X(null),K.current=void 0,fetch(`/api/workspaces/${J}/scratchpad`).then((W)=>W.json()).then((W)=>{if(Y)return;if(W?.document){let z=ET(W.document,W.writer);if(z)X(z);else K.current=W.document}Z(!0)}).catch(()=>{if(!Y)Z(!0)}),()=>{Y=!0}},[J]),{loaded:Q,snapshot:K.current,skew:q,flagSkew:X}}function L00({skew:J}){return H9.jsx("div",{className:"flex min-h-0 flex-1 items-center justify-center bg-muted/40 bg-[radial-gradient(var(--color-border)_1px,transparent_1px)] [background-size:16px_16px] p-6",children:H9.jsxs("div",{className:"flex max-w-md animate-in flex-col gap-3 rounded-lg bg-background p-6 shadow-xs duration-200 fade-in-0 zoom-in-95",children:[H9.jsxs("div",{className:"flex items-center gap-2",children:[H9.jsx(B00,{size:20,stroke:1.5,className:"shrink-0 text-amber-600"}),H9.jsx("h2",{className:"font-medium text-foreground",children:J.newer?"This canvas needs a newer moi":"This canvas couldn’t be loaded"})]}),J.newer?H9.jsxs(H9.Fragment,{children:[H9.jsxs("p",{className:"text-sm text-pretty text-muted-foreground",children:["This scratchpad was saved by a newer version of moi",J.writer?` (v${J.writer.moi})`:"",".",H9.jsx("br",{})," Please update moi and restart the server:"]}),H9.jsx("code",{className:"self-start rounded bg-muted px-2 py-1 font-mono text-xs text-foreground",children:"bun install -g moi-computer@latest"})]}):H9.jsx("p",{className:"text-sm text-muted-foreground",children:J.detail})]})})}var jq=E(m(),1);var u4=E(c(),1),QB0=[{kind:"tool",id:"select",label:"Select",Icon:C00},{kind:"tool",id:"hand",label:"Hand",Icon:k00},{kind:"sep"},{kind:"tool",id:"draw",label:"Pencil",Icon:PT},{kind:"geo",label:"Rectangle",Icon:P00},{kind:"tool",id:"note",label:"Sticker",Icon:I00},{kind:"tool",id:"text",label:"Text",Icon:IT},{kind:"tool",id:"line",label:"Line",Icon:A00},{kind:"tool",id:"arrow",label:"Arrow",Icon:j00},{kind:"sep"},{kind:"tool",id:"highlight",label:"Highlighter",Icon:E00},{kind:"tool",id:"eraser",label:"Eraser",Icon:R00}];function AT({label:J,active:Q,Icon:Z,onClick:q}){return u4.jsx(w00,{type:"button",size:"icon",variant:Q?"default":"ghost","aria-label":J,title:J,onClick:q,className:yQ(!Q&&"text-muted-foreground hover:text-foreground"),children:u4.jsx(Z,{stroke:1.5})})}function D00(J,Q){if(Q==="geo")J.setStyleForNextShapes(T6,"draw"),J.setStyleForNextShapes(e4,"m");else if(Q==="note")J.setStyleForNextShapes(I4,"draw"),J.setStyleForNextShapes(R9,"middle"),J.setStyleForNextShapes(k9,"middle"),M00(J,"sticker","yellow");else if(Q==="text")J.setStyleForNextShapes(I4,"draw"),J.setStyleForNextShapes(R9,"middle"),J.setStyleForNextShapes(k9,"middle");else if(Q==="highlight")M00(J,"highlight","yellow");else if(Q==="arrow")J.setStyleForNextShapes(T6,"draw");else if(Q==="draw"||Q==="line"){let Z=J.getStyleForNextShape(T6);if(Z!=="draw"&&Z!=="dashed")J.setStyleForNextShapes(T6,"draw")}}function T00({editor:J}){let[Q,Z]=jq.useState(()=>J.getCurrentToolId());jq.useEffect(()=>{return Z(J.getCurrentToolId()),g1("scratch current tool",()=>Z(J.getCurrentToolId()))},[J]);let q=(K)=>{J.run(()=>{D00(J,K),J.setCurrentTool(K)})},X=()=>{J.run(()=>{J.setStyleForNextShapes(x6,"rectangle"),D00(J,"geo"),J.setCurrentTool("geo")})};return u4.jsx("div",{className:"absolute top-1/2 left-2 z-10 -translate-y-1/2",children:u4.jsx(b00.div,{initial:{x:-72,opacity:0},animate:{x:0,opacity:1},transition:{type:"spring",bounce:0.2,duration:0.55},className:"flex flex-col gap-1 rounded-xl bg-background/95 p-1 shadow-md backdrop-blur",children:QB0.map((K,Y)=>{if(K.kind==="sep")return u4.jsx("div",{className:"mx-1 my-0.5 h-px bg-border"},`sep-${Y}`);if(K.kind==="geo")return u4.jsx(AT,{label:K.label,Icon:K.Icon,active:Q==="geo",onClick:X},"geo");if(K.kind==="menu")return u4.jsx(AT,{label:K.label,Icon:K.Icon,active:!1,onClick:()=>{}},"menu");return u4.jsx(AT,{label:K.label,Icon:K.Icon,active:Q===K.id,onClick:()=>q(K.id)},K.id)})})})}var ZB0=["color","size","dash","fill"],y00={draw:["color","size","dash"],geo:["color","fill"],note:["color","size"],text:["color","size"],line:["color","dash","size"],highlight:["color","size"],arrow:["color","size"]},qB0={draw:["color","size","dash"],geo:["color","fill"],note:["color","size"],text:["color","size"],line:["color","dash","size"],highlight:["color","size"],arrow:["color","size"]},x00={regular:{swatches:[{value:"black",klass:"bg-[#1d1d1d]"},{value:"red",klass:"bg-[#e03131]"},{value:"yellow",klass:"bg-[#f1ac4b]"},{value:"green",klass:"bg-[#099268]"},{value:"blue",klass:"bg-[#4465e9]"},{value:"grey",klass:"bg-[#9fa8b2]"}]},highlight:{swatches:[{value:"yellow",klass:"bg-[#fddd00]"},{value:"green",klass:"bg-[#00ffc8]"},{value:"blue",klass:"bg-[#10acff]"}]},sticker:{swatches:[{value:"yellow",klass:"bg-[#fed49a]"},{value:"blue",klass:"bg-[#8aa3ff]"},{value:"green",klass:"bg-[#6fc896]"}]}};function XB0(J){let Q=J.getCurrentToolId();if(Q==="highlight")return"highlight";if(Q==="note")return"sticker";if(y00[Q])return"regular";let Z=new Set(J.getSelectedShapeIds().map((q)=>J.getShape(q)?.type));if(Z.size===1){if(Z.has("highlight"))return"highlight";if(Z.has("note"))return"sticker"}return"regular"}function M00(J,Q,Z){if(!x00[Q].swatches.map((X)=>X.value).includes(J.getStyleForNextShape(_1)))J.setStyleForNextShapes(_1,Z)}var KB0=[{value:"m",label:"Small",dot:"size-1.5",glyph:16},{value:"xl",label:"Large",dot:"size-3",glyph:24}],YB0=[{value:"draw",label:"Rough",preview:"border-b-2 border-current"},{value:"dashed",label:"Dash",preview:"border-b-2 border-dashed border-current"}],WB0=[{value:"none",label:"None",preview:"border border-foreground/50"},{value:"solid",label:"Semi",preview:"border border-foreground/40 bg-foreground/25"},{value:"fill",label:"Solid",preview:"border border-foreground bg-foreground"},{value:"pattern",label:"Pattern",preview:"border border-foreground/40 bg-[repeating-linear-gradient(45deg,currentColor_0,currentColor_1px,transparent_1px,transparent_3px)]"}];function mL(J,Q){if(J.getSelectedShapeIds().length>0)return J.getSharedStyles().getAsKnownValue(Q);return J.getStyleForNextShape(Q)}function cL(J,Q,Z){J.run(()=>{if(J.setStyleForNextShapes(Q,Z),J.getSelectedShapeIds().length>0)J.setStyleForSelectedShapes(Q,Z)})}function zB0(J){let Q=y00[J.getCurrentToolId()];if(Q)return Q;let Z=J.getSelectedShapeIds();if(Z.length===0)return[];let q=new Set;for(let X of Z){let K=J.getShape(X);if(!K)continue;for(let Y of qB0[K.type]??[])q.add(Y)}return ZB0.filter((X)=>q.has(X))}function GB0(J){let Q=J.getCurrentToolId();if(Q==="draw")return"pen";if(Q==="text")return"letter";let Z=J.getSelectedShapeIds(),q=new Set(Z.map((X)=>J.getShape(X)?.type));if(q.size===1){if(q.has("draw"))return"pen";if(q.has("text"))return"letter"}return"dot"}function CT(J){return{controls:zB0(J),palette:x00[XB0(J)],color:mL(J,_1),size:mL(J,e4),sizeGlyph:GB0(J),dash:mL(J,T6),fill:mL(J,y6)}}function v00({editor:J}){let[Q,Z]=jq.useState(()=>CT(J));if(jq.useEffect(()=>{return Z(CT(J)),g1("scratch styles",()=>Z(CT(J)))},[J]),Q.controls.length===0)return null;let q={color:u4.jsx("div",{className:"flex flex-col items-center gap-2 pt-1",children:Q.palette.swatches.map((X)=>u4.jsx("button",{type:"button",title:X.value,onClick:()=>cL(J,_1,X.value),className:yQ("size-5.5 rounded-full ring-offset-1 ring-offset-background",X.klass,Q.color===X.value?"ring-2 ring-primary":"ring-1 ring-black/15")},X.value))}),size:u4.jsx("div",{className:"flex flex-col items-center gap-1 text-foreground",children:KB0.map((X)=>u4.jsx("button",{type:"button",title:X.label,onClick:()=>cL(J,e4,X.value),className:yQ("flex size-7.5 items-center justify-center rounded-full hover:bg-accent hover:text-accent-foreground",Q.size===X.value&&"bg-accent text-accent-foreground"),children:Q.sizeGlyph==="pen"?u4.jsx(PT,{size:20,stroke:1.5}):Q.sizeGlyph==="letter"?u4.jsx(IT,{size:X.glyph,stroke:X.glyph===16?1.75:1.5}):u4.jsx("span",{className:yQ("rounded-full bg-current",X.dot)})},X.value))}),dash:u4.jsx("div",{className:"flex flex-col items-center gap-1 text-foreground",children:YB0.map((X)=>u4.jsx("button",{type:"button",title:X.label,onClick:()=>cL(J,T6,X.value),className:yQ("flex size-7.5 items-center justify-center rounded-full hover:bg-accent hover:text-accent-foreground",Q.dash===X.value&&"bg-accent text-accent-foreground"),children:u4.jsx("span",{className:yQ("w-3.5",X.preview)})},X.value))}),fill:u4.jsx("div",{className:"flex flex-col items-center gap-1 text-foreground",children:WB0.map((X)=>u4.jsx("button",{type:"button",title:X.label,onClick:()=>cL(J,y6,X.value),className:yQ("flex size-7.5 items-center justify-center rounded-full hover:bg-accent hover:text-accent-foreground",Q.fill===X.value&&"bg-accent text-accent-foreground"),children:u4.jsx("span",{className:yQ("size-4.5 rounded-lg",X.preview)})},X.value))})};return u4.jsx("div",{className:"absolute top-1/2 left-14 z-10 flex -translate-y-1/2 flex-col items-center gap-1.5 rounded-full bg-background/95 px-1 py-1 shadow-[0_2px_8px_rgba(0,0,0,0.08),0_4px_16px_rgba(0,0,0,0.06),0_0_0_1px_rgba(0,0,0,0.04)] backdrop-blur",children:Q.controls.map((X,K)=>u4.jsxs(jq.Fragment,{children:[K>0&&u4.jsx("div",{className:"h-px w-5 bg-border"}),q[X]]},X))})}var S8=E(c(),1),S00=Math.random().toString(36).slice(2),$B0=500,HB0="tldraw-2026-09-27/WyJlaDdIczMxRSIsWyIqIl0sMTYsIjIwMjYtMDktMjciXQ.6OucDghQHnAFl2Ceg8qf48M2oIis6qHdZfqFsKdBZwd610QixrvG1jUnwCbI1Xs2BoXzptPs+pQYF25NyShFbw";function _B0(J){return async(Q)=>{if(Q.kind!=="view")throw Error(`Scratchpad op "${Q.kind}" runs on the server, not the browser.`);let Z=[...J.getCurrentPageShapeIds()];if(Z.length===0)throw Error("Canvas is empty — nothing to view.");let{url:q}=await J.toImageDataUrl(Z,{format:"png",background:!0,padding:32});return{image:q}}}function FB0(J){let Q=`/api/workspaces/${J}/scratchpad/assets`;return{async upload(Z,q){let X=await fetch(Q,{method:"POST",headers:{"Content-Type":q.type||"application/octet-stream"},body:q});if(!X.ok)throw Error(`Upload failed: ${await X.text()}`);let{src:K}=await X.json();return{src:K}},resolve(Z){let q=Z.props.src;if(q?.startsWith("asset:"))return`${Q}/${q.slice(6)}`;return q}}}function UB0(){return S8.jsx("div",{className:"absolute inset-0 bg-[color-mix(in_oklch,var(--muted),var(--background)_50%)]"})}function VB0({x:J,y:Q,z:Z,size:q}){let X=D5("scratch-grid"),K=y(),Y=K.options.gridSteps[0]?.step??1;for(let _ of K.options.gridSteps)if(Z>=_.min)Y=_.step;let W=Y*q*Z,z=0.5+J*Z,G=0.5+Q*Z,H=z>0?z%W:W+z%W,$=G>0?G%W:W+G%W;return S8.jsxs("svg",{className:"tl-grid",version:"1.1",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:[S8.jsx("defs",{children:S8.jsx("pattern",{id:X,width:W,height:W,patternUnits:"userSpaceOnUse",children:S8.jsx("circle",{className:"fill-accent",cx:H,cy:$,r:1})})}),S8.jsx("rect",{width:"100%",height:"100%",fill:`url(#${X})`})]})}var NB0={Background:UB0,Grid:VB0,Toolbar:null,StylePanel:null,Minimap:null,MainMenu:null,PageMenu:null,ActionsMenu:null,QuickActions:null,HelpMenu:null,DebugMenu:null,ZoomMenu:null},BB0={tools(J,Q){return delete Q.frame,delete Q.laser,Q},actions(J,Q){for(let Z of["export-as-svg","export-as-png","copy-as-svg","copy-as-png","print"])delete Q[Z];return Q}},OB0={maxPages:1},LB0=33554432,DB0=2048;function sj1(){let J=g00(),Q=H2.useRef(null),Z=H2.useRef(null),q=H2.useRef(null),X=H2.useRef(!1),[K,Y]=H2.useState(null),{loaded:W,snapshot:z,skew:G,flagSkew:H}=O00(J),$=H2.useRef(null);if($.current?.id!==J)$.current={id:J,store:FB0(J)};let _=$.current.store,F=H2.useCallback(()=>{let V=Q.current;if(!V)return;let N;try{N=OG(V.store).document}catch{return}fetch(`/api/workspaces/${J}/scratchpad`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({document:N,origin:S00})}).catch(()=>{})},[J]);f00((V)=>{if(V.type!=="scratchpad:updated"||V.workspaceId!==J)return;if(V.origin&&V.origin===S00)return;if(!Q.current)return;fetch(`/api/workspaces/${J}/scratchpad`).then((N)=>N.json()).then((N)=>{let B=Q.current;if(!B||!N?.document)return;let O=ET(N.document,N.writer);if(O){if(q.current)clearTimeout(q.current);H(O);return}X.current=!0,z3(B.store,{document:N.document})}).catch(()=>{})});let U=H2.useCallback((V)=>{Q.current=V,Y(V),V.updateInstanceState({isGridMode:!0}),V.run(()=>{V.setStyleForNextShapes(I4,"draw"),V.setStyleForNextShapes(R9,"middle"),V.setStyleForNextShapes(k9,"middle"),V.setStyleForNextShapes(y6,"fill")});let N=V.store.listen(()=>{if(X.current){X.current=!1;return}if(q.current)clearTimeout(q.current);q.current=setTimeout(F,$B0)},{source:"user",scope:"document"});wT(J,_B0(V));let B=(M)=>{let L=M.target;if(!!L&&!!Z.current?.contains(L)){if(!V.getIsFocused())V.focus()}else if(V.getIsFocused())V.blur()},O=V.getContainer().ownerDocument;return O.addEventListener("pointerdown",B,!0),V.focus(),()=>{if(N(),O.removeEventListener("pointerdown",B,!0),q.current)clearTimeout(q.current);wT(J,null),Y(null),Q.current=null}},[J,F]);if(!W)return S8.jsx("div",{className:"min-h-0 flex-1 bg-muted/40"});if(G)return S8.jsx(L00,{skew:G});return S8.jsxs("div",{ref:Z,className:"relative min-h-0 flex-1 overflow-hidden",children:[S8.jsx("div",{className:"absolute inset-0",children:S8.jsx(jT,{snapshot:z,assets:_,licenseKey:HB0,onMount:U,components:NB0,overrides:BB0,options:OB0,maxAssetSize:LB0,maxImageDimension:DB0,autoFocus:!1})}),K&&S8.jsx(T00,{editor:K}),K&&S8.jsx(v00,{editor:K})]})}export{sj1 as Scratchpad};
|
package/dist/index.html
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
}
|
|
22
22
|
</script>
|
|
23
23
|
|
|
24
|
-
<link rel="stylesheet" crossorigin href="/chunk-s7za1qsv.css"><script type="module" crossorigin src="/chunk-
|
|
24
|
+
<link rel="stylesheet" crossorigin href="/chunk-s7za1qsv.css"><script type="module" crossorigin src="/chunk-4tcmvefj.js"></script></head>
|
|
25
25
|
<body>
|
|
26
26
|
<div id="root"></div>
|
|
27
27
|
|