@1agh/maude 0.48.0 → 0.49.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/apps/studio/api.ts +18 -2
  2. package/apps/studio/assets-s3.ts +291 -0
  3. package/apps/studio/collab/origins.ts +150 -0
  4. package/apps/studio/collab/protocol.ts +36 -9
  5. package/apps/studio/collab/room.ts +124 -0
  6. package/apps/studio/context.ts +9 -0
  7. package/apps/studio/dist/client.bundle.js +1 -1
  8. package/apps/studio/dist/comment-mount.js +2 -2
  9. package/apps/studio/http.ts +45 -0
  10. package/apps/studio/server.ts +75 -2
  11. package/apps/studio/sync/autocommit.ts +299 -0
  12. package/apps/studio/sync/doc-name.ts +228 -0
  13. package/apps/studio/sync/index.ts +95 -1
  14. package/apps/studio/sync/workspace-signin.ts +301 -0
  15. package/apps/studio/test/assets-s3.test.ts +249 -0
  16. package/apps/studio/test/canvas-origin-gate.test.ts +7 -0
  17. package/apps/studio/test/collab-origin-gate.test.ts +323 -0
  18. package/apps/studio/test/sync-autocommit.test.ts +334 -0
  19. package/apps/studio/test/sync-doc-name.test.ts +281 -0
  20. package/apps/studio/test/workspace-containment.test.ts +258 -0
  21. package/apps/studio/test/workspace-signin.test.ts +270 -0
  22. package/apps/studio/use-collab.tsx +28 -1
  23. package/apps/studio/workspace-mode.ts +210 -0
  24. package/apps/studio/ws.ts +11 -2
  25. package/cli/commands/hub-workspace.mjs +341 -0
  26. package/cli/commands/hub.mjs +325 -3
  27. package/cli/commands/hub.test.mjs +14 -1
  28. package/cli/lib/cell-plan.mjs +302 -0
  29. package/cli/lib/cell-plan.test.mjs +225 -0
  30. package/cli/lib/gitignore-block.mjs +12 -1
  31. package/cli/lib/workspace-plan.mjs +422 -0
  32. package/cli/lib/workspace-plan.test.mjs +223 -0
  33. package/package.json +8 -8
@@ -1,4 +1,4 @@
1
- import{Component as _Q,createElement as g,Fragment as AQ,useCallback as w7,useEffect as f,useMemo as IQ,useRef as p,useState as $7}from"react";import{createRoot as OQ}from"react-dom/client";import{useCallback as k,useEffect as S,useMemo as s,useRef as R,useState as u}from"react";function z7(){if(typeof window>"u")return;try{let J=window.location.pathname;if(J==="/_canvas-shell.html"||J==="/_canvas-shell"){let Q=new URLSearchParams(window.location.search),$=Q.get("canvas")??"",V=(Q.get("designRel")??".design").replace(/^\/+|\/+$/g,"");return $?`${V}/${$}`:void 0}return decodeURIComponent(J).replace(/^\//,"")}catch{return}}function Z7(J){if(!J)return"";return(J.getAttribute("class")??"").trim().split(/\s+/).filter((Q)=>Q&&!Q.startsWith("dgn-")&&!Q.startsWith("dc-cv-")).join(" ")}function FJ(J,Q){if(!J)return"";let $=(J.innerText||J.textContent||"").replace(/\s+/g," ").trim();return $.length>Q?`${$.slice(0,Q-1)}…`:$}function DJ(J){if(!J)return"";let Q=[],$=J;while($&&$.nodeType===1&&Q.length<8){let V=$.getAttribute?.("data-dc-element");if(V){Q.unshift(`[data-dc-element="${V}"]`);break}let q=$.getAttribute?.("data-dc-screen");if(q){Q.unshift(`[data-dc-screen="${q}"]`);break}let B=$.nodeName.toLowerCase();if($.id){B=`#${$.id}`,Q.unshift(B);break}let K=Z7($).split(/\s+/).filter(Boolean).slice(0,2);if(K.length)B+=`.${K.join(".")}`;let U=1,H=$.previousElementSibling;while(H)U++,H=H.previousElementSibling;B+=`:nth-child(${U})`,Q.unshift(B),$=$.parentElement}return Q.join(" > ")}function v7(J){let Q=[],$=J;while($&&$.nodeType===1&&Q.length<8){let V=$.nodeName.toLowerCase(),q=$.getAttribute?.("data-dc-element"),B=$.getAttribute?.("data-dc-screen");if(q)V+=`[data-dc-element="${q}"]`;else if(B)V+=`[data-dc-screen="${B}"]`;else if($.id)V+=`#${$.id}`;let K=Z7($).split(/\s+/).filter(Boolean).slice(0,2);if(K.length&&!q&&!B)V+=`.${K.join(".")}`;Q.unshift(V),$=$.parentElement}return Q}function LJ(J){return J.replace(/[^a-zA-Z0-9_-]/g,(Q)=>`\\${Q}`)}function S7(J,Q){return Q?`[data-dc-screen="${Q}"] [data-cd-id="${J}"]`:`[data-cd-id="${J}"]`}function R7(J,Q,$){if(!$)return 0;try{let V=J.querySelectorAll(Q);for(let q=0;q<V.length;q++)if(V[q]===$)return q}catch{}return 0}function g7(J,Q,$){if(!Q||!$)return 0;return R7(J,`[data-cd-id="${LJ(Q)}"]`,$)}function Y7(J,Q){let $=(V)=>{try{let q=J.querySelectorAll(V);if(!q.length)return null;let B=Q.index&&Q.index>0&&Q.index<q.length?Q.index:0;return q[B]??q[0]}catch{return null}};if(Q.id){let V=$(S7(Q.id,Q.artboardId));if(V)return V}if(Q.selector)return $(Q.selector);return null}function PJ(J,Q){let $=0,V=Math.min(J.length,Q.length);for(let q=1;q<=V;q++){if(J[J.length-q]!==Q[Q.length-q])break;$++}return $}function h7(J,Q){let $=Q.dom_path,V=(Q.tag||"").toLowerCase();if(!$||$.length===0||!V)return null;let q=J;if(Q.artboardId){let H=J.querySelector(`[data-dc-screen="${Q.artboardId}"]`);if(H)q=H}let B=(Q.classes||"").split(/\s+/).filter(Boolean),K=null,U=0;for(let H of Array.from(q.querySelectorAll("[data-cd-id]"))){if(H.tagName.toLowerCase()!==V)continue;let M=PJ(v7(H),$);if(M===0)continue;let j=Z7(H).split(/\s+/).filter(Boolean),z=B.filter((F)=>j.includes(F)).length,G=M*10+z;if(G>U)U=G,K=H}return K}var C7=["display","flex-direction","flex-wrap","align-items","justify-content","gap","flex","flex-grow","flex-shrink","flex-basis","align-self","font-family","color","font-size","font-weight","line-height","letter-spacing","text-align","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","width","height","min-width","min-height","max-width","max-height","background-color","border-radius","border-top-left-radius","border-top-right-radius","border-bottom-left-radius","border-bottom-right-radius","border-width","border-style","border-color","box-shadow","opacity","position","top","right","bottom","left","z-index","transform","transform-origin","font-style","text-transform","text-decoration","white-space","overflow","object-fit","aspect-ratio","object-position"],MJ=/^(style|class|data-cd-id|data-dc-|data-dcid$)/;function jJ(J){if(!J||typeof window>"u"||!window.getComputedStyle)return{authored:{},computed:{},customStyles:{},attrs:{}};try{let Q=J.style,$=window.getComputedStyle(J),V={},q={},B=new Set(C7);for(let G of C7){let F=Q.getPropertyValue(G);if(F)V[G]=F.trim();let Y=$.getPropertyValue(G);if(Y)q[G]=Y.trim()}let K=/^(margin|padding|border)(-|$)/,U={};for(let G=0;G<Q.length;G++){let F=Q.item(G);if(!F||B.has(F)||K.test(F))continue;let Y=Q.getPropertyValue(F);if(Y)U[F]=Y.trim()}let H={};for(let G of Array.from(J.attributes)){if(MJ.test(G.name))continue;H[G.name]=G.value}if(J.hasAttribute("data-dc-screen")){for(let G of Array.from(J.attributes))if(G.name.startsWith("data-dc-")&&G.name!=="data-dcid")H[G.name]=G.value}let M=J.parentElement,j=M?window.getComputedStyle(M).display:"",z=M&&(j==="flex"||j==="inline-flex")?window.getComputedStyle(M).flexDirection:"";return{authored:V,computed:q,customStyles:U,attrs:H,parentDisplay:j,parentFlexDirection:z}}catch{return{authored:{},computed:{},customStyles:{},attrs:{}}}}function H7(J,Q){let $=J.el,V=$&&$.getBoundingClientRect?$.getBoundingClientRect():null,q=J.cdId,B=q?S7(q,J.artboardId):J.artboardId?`[data-dc-screen="${J.artboardId}"]`:DJ($),K=q&&typeof document<"u"?R7(document,B,$):0;return{file:Q??z7(),id:q??void 0,selector:B,artboardId:J.artboardId,index:K,tag:$?.tagName.toLowerCase()??"",classes:Z7($),text:FJ($,240),dom_path:v7($),bounds:V?{x:Math.round(V.left),y:Math.round(V.top),w:Math.round(V.width),h:Math.round(V.height)}:null,worldW:$ instanceof HTMLElement?Math.round($.offsetWidth):void 0,worldH:$ instanceof HTMLElement?Math.round($.offsetHeight):void 0,html:$?($.outerHTML??"").slice(0,4000):"",...(()=>{if($?.tagName?.toLowerCase()!=="img")return{};let U=/assets\/[0-9a-f]{8}\.[a-z0-9]+/i,H=$.getAttribute?.("data-photo-asset");if(H&&U.test(H))return{photoKind:"artboard-img",photoAsset:H};let M=$.getAttribute?.("src")||"",j=U.exec(M);return j?{photoKind:"artboard-img",photoAsset:j[0]}:{}})(),...jJ($)}}import*as F7 from"lib0/decoding";import*as a from"lib0/encoding";import{createContext as NJ,useCallback as hQ,useContext as _J,useEffect as fQ,useMemo as pQ,useReducer as uQ,useRef as mQ,useState as dQ}from"react";import{Awareness as cQ,applyAwarenessUpdate as lQ,encodeAwarenessUpdate as rQ}from"y-protocols/awareness";import{readSyncMessage as oQ,writeSyncStep1 as aQ,writeUpdate as sQ}from"y-protocols/sync";import*as AJ from"yjs";import{jsx as eQ}from"react/jsx-runtime";var IJ=NJ(null);function f7(){return _J(IJ)}import{createContext as OJ,useCallback as l,useContext as L7,useEffect as TJ,useMemo as kJ,useRef as EJ,useState as wJ}from"react";import{jsx as D7,Fragment as xJ}from"react/jsx-runtime";var q7=OJ(null);function r(J){return J.id?`id:${J.id}`:`sel:${J.selector}`}function p7(J){let Q=[],$=new Set;for(let V of J){let q=r(V);if($.has(q))continue;$.add(q),Q.push(V)}return Q}var yJ=50;function bJ({children:J,postTarget:Q}){let[$,V]=wJ([]),q=EJ(null),B=l((G)=>{if(q.current)clearTimeout(q.current);q.current=setTimeout(()=>{q.current=null;let F=Q??(typeof window<"u"?window.parent:null);if(!F)return;let Y=G.length===0?null:G.length===1?G[0]??null:G;try{F.postMessage({dgn:"select-set",selection:Y},"*")}catch{}},yJ)},[Q]);TJ(()=>()=>{if(q.current)clearTimeout(q.current)},[]);let K=l((G)=>{let F=p7(Array.isArray(G)?G:[G]);V(F),B(F)},[B]),U=l((G)=>{let F=Array.isArray(G)?G:[G];V((Y)=>{let L=p7([...Y,...F]);return B(L),L})},[B]),H=l((G)=>{let F=r(G);V((Y)=>{let L=Y.filter((_)=>r(_)!==F);return B(L),L})},[B]),M=l((G)=>{let F=r(G);V((Y)=>{let L=Y.some((_)=>r(_)===F)?Y.filter((_)=>r(_)!==F):[...Y,G];return B(L),L})},[B]),j=l(()=>{V([]),B([])},[B]),z=kJ(()=>({selected:$,replace:K,add:U,remove:H,toggle:M,clear:j}),[$,K,U,H,M,j]);return D7(q7.Provider,{value:z,children:J})}function u7({children:J}){if(L7(q7))return D7(xJ,{children:J});return D7(bJ,{children:J})}function B7(){let J=L7(q7);if(!J)throw Error("useSelectionSet must be used inside <SelectionSetProvider>");return J}function m7(){return L7(q7)}import{jsx as O,jsxs as b}from"react/jsx-runtime";var CJ="/_client/comments-overlay.css";function vJ(){if(typeof document>"u")return;if(document.getElementById("cm-overlay-css"))return;let J=document.createElement("link");J.id="cm-overlay-css",J.rel="stylesheet",J.href=CJ,document.head.appendChild(J)}function SJ(){if(typeof window>"u")return null;try{let J=window.location.pathname;if(J==="/_canvas-shell.html"||J==="/_canvas-shell"){let Q=new URLSearchParams(window.location.search),$=Q.get("canvas")??"",V=(Q.get("designRel")??".design").replace(/^\/+|\/+$/g,"");return $?`${V}/${$}`:null}return decodeURIComponent(J).replace(/^\//,"")}catch{return null}}function RJ(J){if(!J.selector)return null;let Q=null;try{let $=document.querySelectorAll(J.selector),V=J.index&&J.index>0&&J.index<$.length?J.index:0;Q=$[V]??$[0]??null}catch{Q=null}if(Q&&J.tag&&Q.tagName.toLowerCase()!==J.tag.toLowerCase())Q=null;if(!Q&&J.dom_path?.length){let $=J.selector.match(/data-dc-screen="([^"]+)"/)?.[1];Q=h7(document,{artboardId:$,tag:J.tag,classes:J.classes,dom_path:J.dom_path})}return Q}function M7(J){let Q=RJ(J);if(!Q?.isConnected)return null;let $=Q.getBoundingClientRect();if($.width===0&&$.height===0)return null;return{x:$.left,y:$.top,w:$.width,h:$.height}}function l7(J,Q){let V=typeof window<"u"?window.innerWidth:J.x+Q.w,q=typeof window<"u"?window.innerHeight:J.y+Q.h,B=J.x;if(B+Q.w+8>V){let U=J.x-Q.w;B=U>=8?U:Math.max(8,V-Q.w-8)}let K=J.y;if(K+Q.h+8>q){let U=J.y-Q.h;K=U>=8?U:Math.max(8,q-Q.h-8)}return{x:B,y:K}}function r7(){vJ();let J=m7(),[Q,$]=u([]),[V,q]=u(null),[B,K]=u(null),U=s(()=>SJ(),[]);S(()=>{if(typeof document>"u")return;let W=document.getElementById("dgn-pin-layer");if(!W)return;let D=W.style.display;return W.style.display="none",()=>{W.style.display=D}},[]);let H=k((W)=>{if(!J)return;if(!W?.selector){J.clear();return}let D=W.selector.match(/data-cd-id="([^"]+)"/),N=D?D[1]:void 0,A,I;try{let P=document.querySelector(W.selector);if(P)A=P.tagName.toLowerCase(),I=(P.getAttribute("class")??"").split(/\s+/).filter((T)=>T&&!T.startsWith("dgn-")&&!T.startsWith("dc-cv-")).join(" ")}catch{}J.replace({file:U??void 0,id:N,selector:W.selector,tag:A,classes:I,bounds:W.bounds??void 0})},[J,U]),M=R(Q);M.current=Q;let j=f7();S(()=>{if(!j)return;let W=j.doc.getArray("comments"),D=()=>{$(W.toArray())};if(W.length>0)D();return W.observe(D),()=>{try{W.unobserve(D)}catch{}}},[j]),S(()=>{if(typeof window>"u")return;let W=(D)=>{let N=D.data;if(!N||typeof N!=="object"||!N.dgn)return;if(N.dgn==="comments-set"&&Array.isArray(N.comments))$(N.comments);else if(N.dgn==="comment-focus"){let A=typeof N.id==="string"?N.id:null;q(A);let I=A?M.current.find((P)=>P.id===A):void 0;H(I)}};return window.addEventListener("message",W),()=>window.removeEventListener("message",W)},[H]),S(()=>{if(typeof document>"u")return;let W=(D)=>{let N=D.detail;if(!N?.selection)return;K({selection:N.selection,clientX:typeof N.clientX==="number"?N.clientX:0,clientY:typeof N.clientY==="number"?N.clientY:0})};return document.addEventListener("cm:open-composer",W),()=>document.removeEventListener("cm:open-composer",W)},[]);let z=k(()=>{if(K(null),typeof window>"u")return;try{window.parent.postMessage({dgn:"force-clear"},"*")}catch{}},[]),G=k((W)=>{if(!B)return;let D=B.selection,N={file:D.file,selector:D.selector,index:D.index,dom_path:D.dom_path,tag:D.tag,classes:D.classes,bounds:D.bounds,html_excerpt:D.html,text:W};if(typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-submit",payload:N},"*")}catch{}z()},[B,z]);S(()=>{if(!U)return;let W=!1;return(async()=>{try{let D=await fetch(`/_comments?file=${encodeURIComponent(U)}`);if(!D.ok)return;let N=await D.json();if(W)return;if(Array.isArray(N.comments))$((A)=>A.length===0?N.comments??[]:A)}catch{}})(),()=>{W=!0}},[U]);let F=s(()=>{return Q.slice().sort((D,N)=>D.created.localeCompare(N.created)).filter((D)=>D.status!=="resolved")},[Q]),Y=s(()=>{let W=new Map;return Q.slice().sort((N,A)=>N.created.localeCompare(A.created)).forEach((N,A)=>{W.set(N.id,A+1)}),W},[Q]),L=k((W)=>{if(q(W),H(Q.find((D)=>D.id===W)),typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-click",id:W},"*")}catch{}},[Q,H]),_=k((W,D)=>{if(typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-patch",id:W,patch:D},"*")}catch{}},[]),Z=k((W)=>{if(typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-delete",id:W},"*")}catch{}q((D)=>D===W?null:D)},[]),X=k(async(W,D)=>{if(typeof fetch>"u")return!1;try{let N=await fetch(`/_api/comments/${encodeURIComponent(W)}/reply`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:D})});if(!N.ok)return!1;let A=await N.json();return $((I)=>I.map((P)=>P.id===A.id?A:P)),!0}catch{return!1}},[]);return b("div",{className:"cm-layer","aria-hidden":!1,children:[F.map((W)=>{let D=Y.get(W.id)??0;return O(pJ,{comment:W,sequence:D,focused:V===W.id,onClick:L,onOrphaned:Z},W.id)}),B?O(uJ,{state:B,onSubmit:G,onCancel:z}):null,(()=>{if(!V)return null;let W=F.find((D)=>D.id===V);if(!W)return null;return O(mJ,{comment:W,sequence:Y.get(W.id)??0,onClose:()=>{q(null),J?.clear()},onPatch:(D)=>_(W.id,D),onDelete:()=>Z(W.id),onReply:(D)=>X(W.id,D)})})()]})}var P7=null;async function gJ(){if(!P7)P7=(async()=>{try{let J=await fetch("/_api/git-committers");if(!J.ok)return[];let Q=await J.json();return Array.isArray(Q.committers)?Q.committers:[]}catch{return[]}})();return P7}function d7(J){return(J.trim().split(/\s+/)[0]??"").replace(/[^\w.-]/g,"").toLowerCase()}function hJ(J,Q){if(Q<=0||Q>J.length)return null;let $=Q-1;while($>=0){let V=J[$]??"";if(V==="@"){let q=$>0?J[$-1]:"";if($===0||/\s/.test(q??"")){let B=J.slice($+1,Q);return{start:$,end:Q,query:B}}return null}if(!/[\w.-]/.test(V))return null;$-=1}return null}function n7({className:J,value:Q,onChange:$,onKeyDown:V,placeholder:q,rows:B,disabled:K,textareaRef:U,ariaLabel:H}){let M=R(null),j=k((P)=>{if(M.current=P,U)U.current=P},[U]),[z,G]=u([]),[F,Y]=u(null),[L,_]=u(0),Z=k(()=>{if(z.length>0)return;gJ().then((P)=>G(P))},[z.length]),X=s(()=>{if(!F)return[];let P=F.query.toLowerCase();return(!P?z:z.filter((E)=>E.name.toLowerCase().includes(P)||E.email.toLowerCase().includes(P))).slice(0,8)},[F,z]),W=k((P)=>{let T=P.selectionStart??P.value.length,E=hJ(P.value,T);Y(E),_(0)},[]),D=k((P)=>{$(P.target.value),W(P.target)},[$,W]),N=k((P)=>{if(!F)return;let T=M.current;if(!T)return;let E=`@${d7(P.name)}`,x=`${Q.slice(0,F.start)}${E} ${Q.slice(F.end)}`;$(x),Y(null);let w=F.start+E.length+1;requestAnimationFrame(()=>{T.focus(),T.setSelectionRange(w,w)})},[F,Q,$]),A=k((P)=>{if(F&&X.length>0){if(P.key==="ArrowDown"){P.preventDefault(),_((T)=>(T+1)%X.length);return}if(P.key==="ArrowUp"){P.preventDefault(),_((T)=>(T-1+X.length)%X.length);return}if(P.key==="Enter"||P.key==="Tab"){P.preventDefault();let T=X[L]??X[0];if(T)N(T);return}if(P.key==="Escape"){P.preventDefault(),Y(null);return}}V?.(P)},[F,X,L,N,V]),I=k((P)=>{W(P.currentTarget)},[W]);return b("div",{style:{position:"relative"},children:[O("textarea",{ref:j,className:J,value:Q,placeholder:q,rows:B,disabled:K,"aria-label":H,onChange:D,onKeyDown:A,onFocus:Z,onSelect:I,onClick:I}),F&&X.length>0?O("ul",{className:"cm-mention-popup",role:"listbox","aria-label":"Mention suggestions",style:{left:0,top:"100%"},children:X.map((P,T)=>{return b("li",{role:"option","aria-selected":T===L,className:"cm-mention-popup__item",onMouseEnter:()=>_(T),onMouseDown:(x)=>{x.preventDefault(),N(P)},children:[b("span",{className:"cm-mention-popup__name",children:["@",d7(P.name)]}),O("span",{className:"cm-mention-popup__email",children:P.email})]},`${P.name}-${P.email}`)})}):null]})}var fJ=3000;function pJ({comment:J,sequence:Q,focused:$,onClick:V,onOrphaned:q}){let B=R(null),K=R(null),U=R(null);S(()=>{let j=()=>{K.current=null;let z=B.current;if(!z)return;let G=M7(J);if(G)U.current=null;else{if(U.current==null)U.current=Date.now();else if(Date.now()-U.current>fJ)q(J.id);if(J.bounds)G={x:J.bounds.x,y:J.bounds.y,w:J.bounds.w,h:J.bounds.h}}if(!G){z.style.display="none",K.current=requestAnimationFrame(j);return}z.style.display="grid";let F=Math.round(G.x+G.w-12),Y=Math.round(G.y-12);z.style.left=`${F}px`,z.style.top=`${Y}px`,K.current=requestAnimationFrame(j)};return K.current=requestAnimationFrame(j),()=>{if(K.current!=null)cancelAnimationFrame(K.current)}},[J,q]);let H=J.author?.trim()||"unknown",M=`Comment ${Q} by ${H}`;return O("button",{ref:B,type:"button",className:"cm-pin","data-resolved":J.status==="resolved"?"true":"false","data-focused":$?"true":"false","data-comment-pin":J.id,"aria-label":M,"aria-expanded":$,title:J.text.slice(0,200),onClick:(j)=>{j.preventDefault(),j.stopPropagation(),V(J.id)},children:Q})}function uJ({state:J,onSubmit:Q,onCancel:$}){let[V,q]=u(""),B=R(null),K=R(null),U=R(null);S(()=>{let z=()=>{U.current=null;let G=K.current;if(!G)return;let F=cJ(J),Y=l7(F,{w:G.offsetWidth,h:G.offsetHeight});G.style.left=`${Math.round(Y.x)}px`,G.style.top=`${Math.round(Y.y)}px`,U.current=requestAnimationFrame(z)};return U.current=requestAnimationFrame(z),()=>{if(U.current!=null)cancelAnimationFrame(U.current)}},[J]),S(()=>{B.current?.focus()},[]);let H=k(()=>{let z=V.trim();if(!z)return;Q(z)},[V,Q]),M=k((z)=>{if(z.key==="Escape"){z.preventDefault(),$();return}if((z.metaKey||z.ctrlKey)&&z.key==="Enter")z.preventDefault(),H()},[$,H]),j=s(()=>{let z=J.selection.selector||"";if(!z)return J.selection.tag||"canvas";let G=z.match(/data-cd-id="([^"]+)"/);if(G)return`cd:${G[1]}`;return z.length>36?`${z.slice(0,33)}…`:z},[J.selection]);return b("div",{ref:K,className:"cm-composer",role:"dialog","aria-label":"New comment",onClick:(z)=>z.stopPropagation(),onPointerDown:(z)=>z.stopPropagation(),children:[b("div",{className:"cm-composer__head",children:[O("span",{children:"New comment"}),O("span",{className:"cm-composer__selector",children:j})]}),O(n7,{textareaRef:B,className:"cm-composer__textarea",value:V,placeholder:"Type a comment. ⌘↵ to save · Esc to cancel · @name to tag",onChange:q,onKeyDown:M,rows:3,ariaLabel:"Comment body"}),b("div",{className:"cm-composer__actions",children:[O("button",{type:"button",className:"cm-btn",onClick:$,children:"Cancel"}),O("button",{type:"button",className:"cm-btn cm-btn--primary",disabled:!V.trim(),onClick:H,children:"Save"})]})]})}function mJ({comment:J,sequence:Q,onClose:$,onPatch:V,onDelete:q,onReply:B}){let K=R(null),U=R(null),H=R(null),[M,j]=u(""),[z,G]=u(!1);S(()=>{let Z=()=>{H.current=null;let X=K.current;if(!X)return;let W=iJ(J),D=l7(W,{w:X.offsetWidth,h:X.offsetHeight});X.style.left=`${Math.round(D.x)}px`,X.style.top=`${Math.round(D.y)}px`,H.current=requestAnimationFrame(Z)};return H.current=requestAnimationFrame(Z),()=>{if(H.current!=null)cancelAnimationFrame(H.current)}},[J]),S(()=>{K.current?.focus();let Z=J.id;return()=>{document.querySelector(`[data-comment-pin="${Z}"]`)?.focus()}},[J.id]),S(()=>{if(typeof document>"u")return;let Z=(X)=>{if(X.key!=="Escape")return;let W=K.current;if(!W)return;if(W.contains(X.target)||document.activeElement===W)X.preventDefault(),$()};return document.addEventListener("keydown",Z),()=>document.removeEventListener("keydown",Z)},[$]);let F=k(async()=>{let Z=M.trim();if(!Z||z)return;G(!0);let X=await B(Z);if(G(!1),X)j(""),U.current?.focus()},[M,z,B]),Y=k((Z)=>{if((Z.metaKey||Z.ctrlKey)&&Z.key==="Enter")Z.preventDefault(),F()},[F]),L=`cm-thread-head-${J.id}`,_=dJ(J.selector,"");return b("div",{ref:K,className:"cm-thread",role:"dialog","aria-labelledby":L,tabIndex:-1,onClick:(Z)=>Z.stopPropagation(),onPointerDown:(Z)=>Z.stopPropagation(),children:[b("div",{className:"cm-thread__head",id:L,children:[b("div",{className:"cm-thread__head-row",children:[O("span",{className:"cm-thread__seq","aria-hidden":"true",children:Q}),O("span",{className:"cm-thread__author",children:J.author?.trim()||"unknown"}),O("span",{className:"cm-thread__time",children:c7(J.created)}),O("button",{type:"button",className:"cm-thread__close","aria-label":"Close thread",title:"Close · Esc",onClick:$,children:"×"})]}),_?O("code",{className:"cm-thread__selector",children:_}):null]}),O("div",{className:"cm-thread__body",children:i7(J.text)}),(J.thread??[]).map((Z)=>b("div",{className:"cm-thread__reply",children:[b("div",{className:"cm-thread__reply-head",children:[O("span",{className:"cm-thread__reply-author",children:Z.author?.trim()||"unknown"}),O("span",{className:"cm-thread__reply-time",children:c7(Z.created)})]}),O("div",{className:"cm-thread__reply-body",children:i7(Z.body)})]},Z.id)),b("div",{className:"cm-thread__reply-form",children:[O(n7,{textareaRef:U,className:"cm-thread__reply-textarea",value:M,placeholder:"Reply… ⌘↵ to send · @name to tag",onChange:j,onKeyDown:Y,rows:2,ariaLabel:"Reply",disabled:z}),O("div",{className:"cm-thread__reply-actions",children:O("button",{type:"button",className:"cm-btn cm-btn--primary",disabled:!M.trim()||z,onClick:()=>void F(),children:"Send"})})]}),b("div",{className:"cm-thread__actions",children:[J.status==="resolved"?O("button",{type:"button",className:"cm-btn",onClick:()=>V({status:"open"}),children:"↺ Reopen"}):O("button",{type:"button",className:"cm-btn cm-btn--primary",onClick:()=>{V({status:"resolved"}),$()},children:"✓ Resolve"}),O("button",{type:"button",className:"cm-btn cm-btn--danger",onClick:()=>{q(),$()},children:"Delete"})]})]})}function i7(J){if(!J)return null;let Q=/(@[\w][\w.-]*)/g;return J.split(Q).map((V,q)=>{let B=`${q}:${V}`;if(q%2===1)return O("strong",{"data-mention":"true",children:V},B);return O("span",{children:V},B)})}function c7(J){if(!J)return"";let Q=Date.parse(J);if(!Number.isFinite(Q))return"";let $=Math.round((Date.now()-Q)/1000);if($<60)return`${Math.max($,0)}s ago`;if($<3600)return`${Math.round($/60)}m ago`;if($<86400)return`${Math.round($/3600)}h ago`;return`${Math.round($/86400)}d ago`}function dJ(J,Q){if(!J)return Q;let $=J.match(/data-cd-id="([^"]+)"/);if($)return`cd:${$[1]}`;return J.length>36?`${J.slice(0,33)}…`:J}function iJ(J){let Q=J.selector?M7(J):null;if(Q)return{x:Q.x+Q.w-12,y:Q.y+16};if(J.bounds)return{x:J.bounds.x+J.bounds.w-12,y:J.bounds.y+16};return{x:16,y:16}}function cJ(J){if(J.clientX||J.clientY)return{x:J.clientX,y:J.clientY+8};if(J.selection.selector){let Q=M7(J.selection);if(Q)return{x:Q.x,y:Q.y+Q.h+8}}return{x:16,y:16}}import{useEffect as lJ}from"react";var rJ=new Set(["pen","highlighter","shape","rect","ellipse","arrow","sticky","text","section","eraser"]);function j7(J){return rJ.has(J)}var t=(J)=>!!(J.metaKey||J.ctrlKey);function e(J){if(J.type==="keydown"){if(J.isEditable)return{kind:"no-op"};if(J.metaKey||J.ctrlKey||J.altKey){if(J.key==="Escape")return{kind:"escape"};let $=(J.key||"").toLowerCase();if(!J.altKey&&(J.metaKey||J.ctrlKey)){if($==="z"&&J.shiftKey)return{kind:"redo"};if($==="z")return{kind:"undo"};if($==="y"&&!J.shiftKey)return{kind:"redo"}}return{kind:"no-op"}}let Q=(J.key||"").toLowerCase();if(Q==="v")return{kind:"tool",tool:"move"};if(Q==="h")return{kind:"tool",tool:"hand"};if(Q==="c")return{kind:"tool",tool:"comment"};if(Q==="b")return{kind:"tool",tool:"pen"};if(Q==="i")return{kind:"tool",tool:"highlighter"};if(Q==="r"||Q==="o")return{kind:"tool",tool:"shape"};if(Q==="a")return{kind:"tool",tool:"arrow"};if(Q==="n")return{kind:"tool",tool:"sticky"};if(Q==="t")return{kind:"tool",tool:"text"};if(Q==="s"&&J.shiftKey)return{kind:"tool",tool:"section"};if(Q==="e")return{kind:"tool",tool:"eraser"};if(J.key==="Escape")return{kind:"escape"};return{kind:"no-op"}}if(J.type==="contextmenu")return{kind:"context-menu",clientX:J.clientX??0,clientY:J.clientY??0};if(J.type==="pointermove"){if(j7(J.activeTool))return{kind:"no-op"};if(J.activeTool==="hand")return{kind:"no-op"};if(J.activeTool==="browse"){if(!t(J))return{kind:"no-op"};return{kind:"hover",deep:!0,clientX:J.clientX??0,clientY:J.clientY??0}}if(J.activeTool==="comment")return{kind:"hover",deep:!0,clientX:J.clientX??0,clientY:J.clientY??0};return{kind:"hover",deep:t(J),clientX:J.clientX??0,clientY:J.clientY??0}}if(J.type==="pointerdown"){if(J.button===2)return{kind:"context-menu",clientX:J.clientX??0,clientY:J.clientY??0};if(J.button===1||J.spaceHeld)return{kind:"no-op"};if(J.button!==0)return{kind:"no-op"};if(j7(J.activeTool)&&!t(J))return{kind:"no-op"};if(J.activeTool==="comment")return{kind:"drop-comment",clientX:J.clientX??0,clientY:J.clientY??0};if(J.activeTool==="hand")return{kind:"no-op"};if(J.activeTool==="browse"){if(!t(J))return{kind:"no-op"};return{kind:"select",mode:J.shiftKey?"add":"replace",deep:!0,clientX:J.clientX??0,clientY:J.clientY??0}}let Q=t(J);return{kind:"select",mode:!!J.shiftKey?"add":"replace",deep:Q,clientX:J.clientX??0,clientY:J.clientY??0}}return{kind:"no-op"}}function G7(J){if(!J||!J.tagName)return!1;let Q=J,$=Q.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return!0;if(Q.isContentEditable)return!0;let V=Q.getAttribute?.("contenteditable");if(V==="true"||V==="plaintext-only"||V==="")return!0;return!1}function J7(J){if(!J||!J.closest)return!1;return!!J.closest(".cm-composer, .cm-thread, .cm-mention-popup, .cm-pin, [data-mediaref-player]")}function o7(J){let{hostRef:Q,getActiveTool:$,isSpaceHeld:V,callbacks:q,enabled:B=!0,claimableActions:K}=J;lJ(()=>{if(!B)return;let U=Q.current;if(!U)return;let H=(Z)=>K&&Z.kind!=="no-op"&&!K.has(Z.kind)?{kind:"no-op"}:Z,M=(Z)=>{switch(Z.kind){case"hover":q.onHover?.(Z);break;case"select":q.onSelect?.(Z);break;case"drop-comment":q.onDropComment?.(Z);break;case"context-menu":q.onContextMenu?.(Z);break;case"tool":q.onTool?.(Z);break;case"escape":q.onEscape?.();break;case"undo":q.onUndo?.();break;case"redo":q.onRedo?.();break;case"no-op":break}},j=(Z)=>{let X=H(e({type:"pointermove",button:Z.button,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,clientX:Z.clientX,clientY:Z.clientY,spaceHeld:V?.()??!1,activeTool:$()}));M(X)},z=(Z)=>{if(J7(Z.target))return;if(G7(Z.target))return;let X=H(e({type:"pointerdown",button:Z.button,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,clientX:Z.clientX,clientY:Z.clientY,spaceHeld:V?.()??!1,activeTool:$()}));if(X.kind!=="no-op")Z.preventDefault(),Z.stopImmediatePropagation();M(X)},G=(Z)=>{if(J7(Z.target))return;if(G7(Z.target))return;let X=H(e({type:"pointerdown",button:Z.button,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,clientX:Z.clientX,clientY:Z.clientY,spaceHeld:V?.()??!1,activeTool:$()}));if(X.kind!=="no-op"){if(Z.preventDefault(),Z.stopImmediatePropagation(),X.kind==="select")try{window.focus()}catch{}}},F=(Z)=>{if(J7(Z.target))return;if(G7(Z.target))return;let X=$(),W=Z.metaKey||Z.ctrlKey,D=X==="comment"?"drop-comment":X==="move"&&Z.button===0?"select":(j7(X)||X==="browse")&&W&&Z.button===0?"select":Z.button===2?"context-menu":null;if(D&&(!K||K.has(D)))Z.preventDefault(),Z.stopImmediatePropagation()},Y=(Z)=>{let X=H(e({type:"contextmenu",clientX:Z.clientX,clientY:Z.clientY,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,activeTool:$()}));if(X.kind==="no-op")return;Z.preventDefault(),Z.stopImmediatePropagation(),M(X)},L=(Z)=>{let X=H(e({type:"keydown",key:Z.key,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,isEditable:G7(Z.target),activeTool:$()}));if(X.kind==="tool"||X.kind==="escape"||X.kind==="undo"||X.kind==="redo")Z.preventDefault();M(X)};U.addEventListener("pointermove",j,{passive:!0}),U.addEventListener("pointerdown",z,{capture:!0}),U.addEventListener("mousedown",G,{capture:!0}),U.addEventListener("click",F,{capture:!0}),U.addEventListener("contextmenu",Y,{capture:!0});let _=U.ownerDocument??document;return _.addEventListener("keydown",L,!0),()=>{U.removeEventListener("pointermove",j),U.removeEventListener("pointerdown",z,{capture:!0}),U.removeEventListener("mousedown",G,{capture:!0}),U.removeEventListener("click",F,{capture:!0}),U.removeEventListener("contextmenu",Y,{capture:!0}),_.removeEventListener("keydown",L,!0)}},[B,Q,$,V,q,K])}function N7(J,Q,$,V){let q=J.elementFromPoint(Q,$);if(!q)return null;if(q.closest?.(".dc-mm, .dc-zoom-tb, .dc-tool-palette, .dc-context-menu, .dc-cv-group-bbox"))return null;let B=q.closest?.("[data-dc-screen]")??null,K=B?.getAttribute("data-dc-screen")??null,U=q.closest?.(".dc-artboard-body")??null;if(!U){if(B&&K)return{el:B,cdId:null,artboardId:K};return null}if(q===U){if(B&&K)return{el:B,cdId:null,artboardId:K};return null}if(V.deep){let G=q.getAttribute?.("data-cd-id")??null;return{el:q,cdId:G,artboardId:K}}let H=q,M=null;while(H&&H!==U){if(H.hasAttribute?.("data-cd-id"))M=H;H=H.parentElement}let j=M??q,z=j.getAttribute?.("data-cd-id")??null;return{el:j,cdId:z,artboardId:K}}import{useCallback as KQ,useEffect as JJ,useRef as K7}from"react";var nJ=!1;function a7(){return nJ}import{createContext as VQ,useCallback as O7,useContext as t7,useEffect as ZQ,useMemo as qQ,useState as T7}from"react";function m(J,Q,$,V){return`url("data:image/svg+xml,${encodeURIComponent(J.trim())}") ${Q} ${$}, ${V}`}var A7="width='24' height='24' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'",I7="#1f1f1f",_7="stroke='#ffffff' stroke-linejoin='round' stroke-linecap='round'";function i(J,Q,$){let V=$?`<g transform='${$}'>`:"";return`<svg ${A7}>${V}<path fill='#ffffff' d='${J}'/><path fill='${I7}' d='${Q}'/>${$?"</g>":""}</svg>`}var s7="translate(0,32) scale(1,-1)",oJ=m(i("M10.25 8.25 L10.05 8.65 10 9 10 23.1 10.05 23.4 10.25 23.75 10.8 24 11.45 23.85 11.6 23.7 11.75 23.45 14.65 19.8 14.85 19.65 14.95 19.5 15.4 19.2 15.95 19.1 21.05 19.1 21.2 19.1 21.35 19.05 21.65 18.9 21.9 18.6 22 18.3 22 17.9 21.9 17.65 21.75 17.35 21.65 17.3 21.55 17.15 11.5 8.25 11.25 8.05 10.95 8 10.6 8.05 10.25 8.25 M9.15 6.6 L9.7 6.25 10 6.15 10.95 6 11.9 6.15 13 6.9 22.9 15.65 23 15.8 23.2 15.95 23.75 16.75 24 17.9 24 18.3 23.9 18.95 23.8 19.25 23.6 19.7 23.1 20.35 22.75 20.6 22.1 20.9 22.05 20.95 22 20.95 21.2 21.1 21.05 21.1 16.2 21.1 16.1 21.25 16.05 21.25 13.4 24.6 13.05 25.15 12.9 25.3 12.55 25.55 Q11.6 26.15 10.55 26 L10.5 26 Q9.65 25.85 9 25.3 L8.45 24.65 8.4 24.5 8.15 24.05 8 23.1 8 9 Q8 8.45 8.15 8.05 L8.25 7.75 8.45 7.35 9.15 6.6","M10.25 8.25 L10.6 8.05 10.95 8 11.25 8.05 11.5 8.25 21.55 17.15 21.65 17.3 21.75 17.35 21.9 17.65 22 17.9 22 18.3 21.9 18.6 21.65 18.9 21.35 19.05 21.2 19.1 21.05 19.1 15.95 19.1 15.4 19.2 14.95 19.5 14.85 19.65 14.65 19.8 11.75 23.45 11.6 23.7 11.45 23.85 10.8 24 10.25 23.75 10.05 23.4 10 23.1 10 9 10.05 8.65 10.25 8.25"),8,5,"default"),aJ=m(i("M28.55 17.8 Q29.4 20.3 28.75 22.8 L28.7 23 28.15 24.55 28.05 24.75 Q26.4 28.2 22.75 29.4 L22.45 29.5 18 29.9 17.75 29.85 Q15.8 29.25 13.8 28.1 L13.45 27.95 Q12 27.05 10.35 26.8 L10.25 26.75 7.9 26.7 7.8 26.7 Q6.1 26.9 4.8 25.8 L4.75 25.8 4.65 25.7 4.6 25.65 Q3.25 24.5 3.05 22.85 L3 22.75 Q2.8 20.95 4 19.5 5.05 18.15 6.75 17.95 L8.4 17.9 7.5 15.55 7.3 15.2 7.2 15 5 10.95 Q3.9 9.15 4.3 7.75 L4.4 7.5 Q4.75 6.15 6.45 5.2 9 3.65 11 5 11.05 4.1 11.5 3.45 12.15 2.1 14.2 1.6 L14.35 1.6 Q18.05 0.6 19.6 4.4 L19.65 4.55 Q20.75 3.65 22.7 3.75 L22.75 3.75 Q26.75 4 27 8.15 L27 8.25 27 8.35 27 8.45 Q26.9 10.75 27.1 12.6 27.15 14.65 28.2 16.75 L28.55 17.8 M26.65 18.4 L26.1 16.8 26.1 16.85 Q24.8 13.7 25 8.35 L25 8.25 Q24.85 5.9 22.6 5.75 20.7 5.65 20.4 7.35 L20.1 7.95 19.5 8.2 18.85 8.05 18.45 7.5 17.75 5.15 Q16.85 2.95 14.7 3.55 L14.65 3.55 Q12.55 4.05 13.15 6.15 L13.85 8.75 13.75 9.45 13.25 9.95 12.55 9.95 12 9.55 10.9 7.7 Q9.5 5.7 7.45 6.9 6.5 7.45 6.25 8.15 6.1 8.9 6.7 9.85 9.2 13.9 10.8 18.65 L10.8 19.3 10.4 19.8 9.75 19.95 Q8.35 19.8 6.95 19.95 6.1 20.05 5.55 20.75 4.9 21.55 5 22.55 5.15 23.55 6 24.2 L6.05 24.25 Q6.75 24.85 7.65 24.7 L7.7 24.7 10.65 24.8 Q12.7 25.15 14.45 26.2 L14.5 26.2 Q16.4 27.35 18.3 27.9 L22.05 27.5 22.1 27.5 Q24.95 26.55 26.25 23.85 L26.8 22.3 Q27.3 20.35 26.65 18.4","M26.65 18.4 Q27.3 20.35 26.8 22.3 L26.25 23.85 Q24.95 26.55 22.1 27.5 L22.05 27.5 18.3 27.9 Q16.4 27.35 14.5 26.2 L14.45 26.2 Q12.7 25.15 10.65 24.8 L7.7 24.7 7.65 24.7 Q6.75 24.85 6.05 24.25 L6 24.2 Q5.15 23.55 5 22.55 4.9 21.55 5.55 20.75 6.1 20.05 6.95 19.95 8.35 19.8 9.75 19.95 L10.4 19.8 10.8 19.3 10.8 18.65 Q9.2 13.9 6.7 9.85 6.1 8.9 6.25 8.15 6.5 7.45 7.45 6.9 9.5 5.7 10.9 7.7 L12 9.55 12.55 9.95 13.25 9.95 13.75 9.45 13.85 8.75 13.15 6.15 Q12.55 4.05 14.65 3.55 L14.7 3.55 Q16.85 2.95 17.75 5.15 L18.45 7.5 18.85 8.05 19.5 8.2 20.1 7.95 20.4 7.35 Q20.7 5.65 22.6 5.75 24.85 5.9 25 8.25 L25 8.35 Q24.8 13.7 26.1 16.85 L26.1 16.8 26.65 18.4"),12,12,"grab"),sJ=m(i("M28 14 Q28 9.85 24.45 6.9 20.95 4 16 4 11.05 4 7.5 6.9 L7.45 7 Q4 9.9 4 14 4 18.15 7.55 21.05 L7.5 21.05 Q9.2 22.45 11.2 23.2 L15.3 27.3 16 27.6 16.7 27.3 20.85 23.2 Q22.7 22.45 24.3 21.15 L24.45 21.05 Q28 18.15 28 14 M25.75 5.35 Q30.05 8.95 30 14 30.05 19.05 25.75 22.6 L25.4 22.85 Q23.8 24.1 22 24.9 L18.1 28.75 18.15 28.75 Q17.2 29.6 16 29.6 14.8 29.6 13.85 28.75 L13.9 28.75 10 24.9 6.6 22.85 6.25 22.6 Q1.95 19.05 2 14 1.95 8.95 6.25 5.35 10.3 2 16 2 21.7 2 25.75 5.35","M28 14 Q28 18.15 24.45 21.05 L24.3 21.15 Q22.7 22.45 20.85 23.2 L16.7 27.3 16 27.6 15.3 27.3 11.2 23.2 Q9.2 22.45 7.5 21.05 L7.55 21.05 Q4 18.15 4 14 4 9.9 7.45 7 L7.5 6.9 Q11.05 4 16 4 20.95 4 24.45 6.9 28 9.85 28 14"),12,21,"crosshair"),tJ=m(i("M4 13.1 L4 6 Q4 5.15 4.6 4.6 5.15 4 6 4 L13.1 4 Q13.95 4 14.55 4.6 L28.65 18.75 Q29.8 19.9 29.75 21.45 L29.75 21.6 29.75 21.7 Q29.75 23.2 28.7 24.35 L24.45 28.65 24.35 28.75 Q23.15 29.85 21.65 29.8 L21.55 29.8 21.4 29.8 Q20.2 29.8 19.25 29.15 L18 29.35 Q16.6 29.4 15.25 28 L15.2 27.95 8.2 20.95 Q7.6 20.35 7.6 19.55 7.6 18.7 8.2 18.1 L4.6 14.5 Q4 13.9 4 13.1 M19.5 26.65 L20.1 27.25 Q20.7 27.85 21.5 27.8 22.35 27.85 23 27.25 L27.25 22.95 Q27.8 22.35 27.75 21.55 27.8 20.75 27.2 20.15 L13.1 6 6 6 6 13.1 12.35 19.45 9.6 19.5 16.65 26.55 Q18.05 28.05 19.5 26.65 M8.05 12.3 L8 8 12.25 8.05 13.8 9.6 9.6 13.85 8.05 12.3 M15.25 11.05 L23 18.8 18.8 23.05 11.05 15.3 15.25 11.05","M15.25 11.05 L11.05 15.3 18.8 23.05 23 18.8 15.25 11.05 M12.35 19.45 L6 13.1 6 6 13.1 6 27.2 20.15 Q27.8 20.75 27.75 21.55 27.8 22.35 27.25 22.95 L23 27.25 Q22.35 27.85 21.5 27.8 20.7 27.85 20.1 27.25 L19.5 26.65 12.35 19.45 M8.05 12.3 L9.6 13.85 13.8 9.6 12.25 8.05 8 8 8.05 12.3",s7),6,18,"crosshair"),eJ=m(i("M5.15 10.85 Q4 9.65 4 8.1 L4 7.95 4 7.85 Q3.95 6.2 5.1 5.15 6.25 4 7.85 4 L7.95 4 8.1 4 Q9.65 4 10.85 5.15 L11 5.3 14.3 5.25 Q15.15 5.25 15.75 5.85 L29.9 20 Q31 21.15 31 22.75 L31 22.85 31 23 Q31.05 24.5 29.9 25.7 L29.55 25.95 25.65 29.9 25.65 29.95 Q24.45 31.1 22.75 31.1 21.2 31.15 20 29.95 L5.85 15.8 Q5.25 15.2 5.25 14.35 L5.25 10.95 5.15 10.85 M19.95 24.2 L18.55 22.8 22.8 18.55 24.2 19.95 19.95 24.2 M28.45 21.4 L14.3 7.25 10.15 7.3 9.4 6.55 Q8.8 5.95 7.95 6 7.1 5.95 6.5 6.55 5.95 7.1 6 7.95 5.95 8.8 6.55 9.4 L7.25 10.1 7.25 14.35 21.4 28.5 Q22 29.1 22.75 29.1 23.6 29.1 24.2 28.5 L28.45 24.25 Q29.05 23.65 29 22.85 29.05 22 28.45 21.4 M9.25 13.5 L9.25 9.3 13.5 9.25 14.3 10.05 10.05 14.3 9.25 13.5 M17.15 21.4 L11.5 15.75 15.75 11.5 21.4 17.15 17.15 21.4","M17.15 21.4 L21.4 17.15 15.75 11.5 11.5 15.75 17.15 21.4 M28.45 21.4 Q29.05 22 29 22.85 29.05 23.65 28.45 24.25 L24.2 28.5 Q23.6 29.1 22.75 29.1 22 29.1 21.4 28.5 L7.25 14.35 7.25 10.1 6.55 9.4 Q5.95 8.8 6 7.95 5.95 7.1 6.5 6.55 7.1 5.95 7.95 6 8.8 5.95 9.4 6.55 L10.15 7.3 14.3 7.25 28.45 21.4 M19.95 24.2 L24.2 19.95 22.8 18.55 18.55 22.8 19.95 24.2 M9.25 13.5 L10.05 14.3 14.3 10.05 13.5 9.25 9.25 9.3 9.25 13.5",s7),6,18,"crosshair"),Q7=m(i("M17 2 Q18.2 2 19.15 2.9 20 3.8 20 5 L20 12 27 12 Q28.2 12 29.15 12.9 30 13.8 30 15 L30 17 Q30 18.2 29.15 19.15 28.2 20 27 20 L20 20 20 27 Q20 28.2 19.15 29.15 18.2 30 17 30 L15 30 Q13.8 30 12.9 29.15 12 28.2 12 27 L12 20 5 20 Q3.8 20 2.9 19.15 2 18.2 2 17 L2 15 Q2 13.8 2.9 12.9 3.8 12 5 12 L12 12 12 5 Q12 3.8 12.9 2.9 13.8 2 15 2 L17 2 M14 27 L14.3 27.7 Q14.6 28 15 28 L17 28 17.7 27.7 18 27 18 18.05 18.05 18 27 18 Q27.4 18 27.7 17.7 L28 17 28 15 27.7 14.3 Q27.4 14 27 14 L18 14 18 5 17.7 4.3 17 4 15 4 Q14.6 4 14.3 4.3 14 4.6 14 5 L14 14 5 14 Q4.6 14 4.3 14.3 4 14.6 4 15 L4 17 Q4 17.4 4.3 17.7 4.6 18 5 18 L14 18 14 27","M14 27 L14 18 5 18 Q4.6 18 4.3 17.7 4 17.4 4 17 L4 15 Q4 14.6 4.3 14.3 4.6 14 5 14 L14 14 14 5 Q14 4.6 14.3 4.3 14.6 4 15 4 L17 4 17.7 4.3 18 5 18 14 27 14 Q27.4 14 27.7 14.3 L28 15 28 17 27.7 17.7 Q27.4 18 27 18 L18.05 18 18 18.05 18 27 17.7 27.7 17 28 15 28 Q14.6 28 14.3 27.7 L14 27"),12,12,"crosshair"),JQ=m(i("M3.9 11.35 Q2.3 12.5 3.7 13.9 L16.4 26.65 Q17.85 28.05 19.45 26.9 L27.65 21.15 Q29.3 20 27.85 18.6 L15.15 5.85 Q13.75 4.45 12.1 5.6 L3.9 11.35 M1.05 12.4 Q1 10.95 2.75 9.75 L10.95 4 10.95 3.95 Q14 1.85 16.6 4.45 L29.3 17.2 Q30.8 18.65 30.55 20.1 30.55 21.55 28.8 22.8 L20.6 28.55 20.65 28.55 Q17.7 30.65 15 28.1 L15 28.05 2.3 15.3 2.3 15.35 Q0.8 13.85 1.05 12.4 M13.5 7 L19.85 13.35 11.65 19.15 5.3 12.75 13.5 7","M13.5 7 L5.3 12.75 11.65 19.15 19.85 13.35 13.5 7 M3.9 11.35 L12.1 5.6 Q13.75 4.45 15.15 5.85 L27.85 18.6 Q29.3 20 27.65 21.15 L19.45 26.9 Q17.85 28.05 16.4 26.65 L3.7 13.9 Q2.3 12.5 3.9 11.35"),6,14,"cell"),QQ=m(`<svg ${A7}><path d='M16 4V28M11 4H21M11 28H21' fill='none' ${_7} stroke-width='5'/><path d='M16 4V28M11 4H21M11 28H21' fill='none' stroke='${I7}' stroke-width='2.25' stroke-linecap='round'/></svg>`,12,12,"text"),$Q=m(`<svg ${A7}><path d='M6 5H21L26 10V27H6Z' fill='${I7}' ${_7} stroke-width='2.5'/><path d='M21 5V11H26' fill='none' ${_7} stroke-width='2.25'/></svg>`,5,5,"crosshair"),v=Object.freeze({browse:"default",move:oJ,hand:aJ,comment:sJ,pen:tJ,section:Q7,highlighter:eJ,shape:Q7,rect:Q7,ellipse:Q7,sticky:$Q,arrow:Q7,text:QQ,eraser:JQ});import{jsx as k7,Fragment as WQ}from"react/jsx-runtime";var BQ=Object.freeze([{id:"browse",label:"Browse",shortcut:"",cursor:v.browse},{id:"move",label:"Select",shortcut:"V",cursor:v.move},{id:"hand",label:"Hand",shortcut:"H",cursor:v.hand},{id:"comment",label:"Comment",shortcut:"C",cursor:v.comment},{id:"pen",label:"Pen",shortcut:"B",cursor:v.pen},{id:"highlighter",label:"Highlighter",shortcut:"I",cursor:v.highlighter},{id:"shape",label:"Shape",shortcut:"R",cursor:v.shape},{id:"sticky",label:"Sticky",shortcut:"N",cursor:v.sticky},{id:"section",label:"Section",shortcut:"⇧S",cursor:v.shape},{id:"arrow",label:"Arrow",shortcut:"A",cursor:v.arrow},{id:"text",label:"Text",shortcut:"T",cursor:v.text},{id:"eraser",label:"Eraser",shortcut:"E",cursor:v.eraser}]),E7=VQ(null);function GQ({children:J,tools:Q=BQ,initial:$="browse"}){let[V,q]=T7($),[B,K]=T7(()=>({tool:null,locked:!1})),U=O7((F)=>{q(F),K((Y)=>Y.locked&&Y.tool===F?Y:{tool:null,locked:!1})},[]),H=O7((F)=>{K((Y)=>{if(Y.locked&&Y.tool===F)return{tool:null,locked:!1};return{tool:F,locked:!0}}),q(F)},[]),M=O7(()=>{K({tool:null,locked:!1})},[]),[j,z]=T7("rounded");ZQ(()=>{if(typeof document>"u")return;let F=Q.find((_)=>_.id===V);if(!F)return;let Y=document.body.style.cursor,L=document.getElementById("dc-tool-cursor");if(!L)L=document.createElement("style"),L.id="dc-tool-cursor",document.head.appendChild(L);if(V==="browse"){if(document.body.style.cursor="",L.textContent="",typeof window<"u"&&window.parent&&window.parent!==window)try{window.parent.postMessage({dgn:"tool-cursor",tool:V},"*")}catch{}return()=>{document.body.style.cursor=Y}}if(document.body.style.cursor=F.cursor,L.textContent=`* { cursor: ${F.cursor} !important; }`,typeof window<"u"&&window.parent&&window.parent!==window)try{window.parent.postMessage({dgn:"tool-cursor",tool:V},"*")}catch{}return()=>{document.body.style.cursor=Y;let _=document.getElementById("dc-tool-cursor");if(_)_.textContent=""}},[V,Q]);let G=qQ(()=>({tool:V,setTool:U,tools:Q,sticky:B,toggleSticky:H,clearSticky:M,shapeKind:j,setShapeKind:z}),[V,U,Q,B,H,M,j]);return k7(E7.Provider,{value:G,children:J})}function e7({children:J}){if(t7(E7))return k7(WQ,{children:J});return k7(GQ,{children:J})}function W7(){let J=t7(E7);if(!J)throw Error("useToolMode must be used inside <ToolProvider>");return J}import{jsx as NQ}from"react/jsx-runtime";var UQ=`
1
+ import{Component as OQ,createElement as g,Fragment as TQ,useCallback as w7,useEffect as f,useMemo as kQ,useRef as p,useState as $7}from"react";import{createRoot as EQ}from"react-dom/client";import{useCallback as k,useEffect as R,useMemo as s,useRef as S,useState as u}from"react";function U7(){if(typeof window>"u")return;try{let J=window.location.pathname;if(J==="/_canvas-shell.html"||J==="/_canvas-shell"){let Q=new URLSearchParams(window.location.search),$=Q.get("canvas")??"",V=(Q.get("designRel")??".design").replace(/^\/+|\/+$/g,"");return $?`${V}/${$}`:void 0}return decodeURIComponent(J).replace(/^\//,"")}catch{return}}function Z7(J){if(!J)return"";return(J.getAttribute("class")??"").trim().split(/\s+/).filter((Q)=>Q&&!Q.startsWith("dgn-")&&!Q.startsWith("dc-cv-")).join(" ")}function DJ(J,Q){if(!J)return"";let $=(J.innerText||J.textContent||"").replace(/\s+/g," ").trim();return $.length>Q?`${$.slice(0,Q-1)}…`:$}function PJ(J){if(!J)return"";let Q=[],$=J;while($&&$.nodeType===1&&Q.length<8){let V=$.getAttribute?.("data-dc-element");if(V){Q.unshift(`[data-dc-element="${V}"]`);break}let q=$.getAttribute?.("data-dc-screen");if(q){Q.unshift(`[data-dc-screen="${q}"]`);break}let G=$.nodeName.toLowerCase();if($.id){G=`#${$.id}`,Q.unshift(G);break}let K=Z7($).split(/\s+/).filter(Boolean).slice(0,2);if(K.length)G+=`.${K.join(".")}`;let X=1,H=$.previousElementSibling;while(H)X++,H=H.previousElementSibling;G+=`:nth-child(${X})`,Q.unshift(G),$=$.parentElement}return Q.join(" > ")}function C7(J){let Q=[],$=J;while($&&$.nodeType===1&&Q.length<8){let V=$.nodeName.toLowerCase(),q=$.getAttribute?.("data-dc-element"),G=$.getAttribute?.("data-dc-screen");if(q)V+=`[data-dc-element="${q}"]`;else if(G)V+=`[data-dc-screen="${G}"]`;else if($.id)V+=`#${$.id}`;let K=Z7($).split(/\s+/).filter(Boolean).slice(0,2);if(K.length&&!q&&!G)V+=`.${K.join(".")}`;Q.unshift(V),$=$.parentElement}return Q}function MJ(J){return J.replace(/[^a-zA-Z0-9_-]/g,(Q)=>`\\${Q}`)}function R7(J,Q){return Q?`[data-dc-screen="${Q}"] [data-cd-id="${J}"]`:`[data-cd-id="${J}"]`}function S7(J,Q,$){if(!$)return 0;try{let V=J.querySelectorAll(Q);for(let q=0;q<V.length;q++)if(V[q]===$)return q}catch{}return 0}function g7(J,Q,$){if(!Q||!$)return 0;return S7(J,`[data-cd-id="${MJ(Q)}"]`,$)}function Y7(J,Q){let $=(V)=>{try{let q=J.querySelectorAll(V);if(!q.length)return null;let G=Q.index&&Q.index>0&&Q.index<q.length?Q.index:0;return q[G]??q[0]}catch{return null}};if(Q.id){let V=$(R7(Q.id,Q.artboardId));if(V)return V}if(Q.selector)return $(Q.selector);return null}function jJ(J,Q){let $=0,V=Math.min(J.length,Q.length);for(let q=1;q<=V;q++){if(J[J.length-q]!==Q[Q.length-q])break;$++}return $}function h7(J,Q){let $=Q.dom_path,V=(Q.tag||"").toLowerCase();if(!$||$.length===0||!V)return null;let q=J;if(Q.artboardId){let H=J.querySelector(`[data-dc-screen="${Q.artboardId}"]`);if(H)q=H}let G=(Q.classes||"").split(/\s+/).filter(Boolean),K=null,X=0;for(let H of Array.from(q.querySelectorAll("[data-cd-id]"))){if(H.tagName.toLowerCase()!==V)continue;let j=jJ(C7(H),$);if(j===0)continue;let L=Z7(H).split(/\s+/).filter(Boolean),U=G.filter((F)=>L.includes(F)).length,B=j*10+U;if(B>X)X=B,K=H}return K}var v7=["display","flex-direction","flex-wrap","align-items","justify-content","gap","flex","flex-grow","flex-shrink","flex-basis","align-self","font-family","color","font-size","font-weight","line-height","letter-spacing","text-align","margin","margin-top","margin-right","margin-bottom","margin-left","padding","padding-top","padding-right","padding-bottom","padding-left","width","height","min-width","min-height","max-width","max-height","background-color","border-radius","border-top-left-radius","border-top-right-radius","border-bottom-left-radius","border-bottom-right-radius","border-width","border-style","border-color","box-shadow","opacity","position","top","right","bottom","left","z-index","transform","transform-origin","font-style","text-transform","text-decoration","white-space","overflow","object-fit","aspect-ratio","object-position"],LJ=/^(style|class|data-cd-id|data-dc-|data-dcid$)/;function NJ(J){if(!J||typeof window>"u"||!window.getComputedStyle)return{authored:{},computed:{},customStyles:{},attrs:{}};try{let Q=J.style,$=window.getComputedStyle(J),V={},q={},G=new Set(v7);for(let B of v7){let F=Q.getPropertyValue(B);if(F)V[B]=F.trim();let Y=$.getPropertyValue(B);if(Y)q[B]=Y.trim()}let K=/^(margin|padding|border)(-|$)/,X={};for(let B=0;B<Q.length;B++){let F=Q.item(B);if(!F||G.has(F)||K.test(F))continue;let Y=Q.getPropertyValue(F);if(Y)X[F]=Y.trim()}let H={};for(let B of Array.from(J.attributes)){if(LJ.test(B.name))continue;H[B.name]=B.value}if(J.hasAttribute("data-dc-screen")){for(let B of Array.from(J.attributes))if(B.name.startsWith("data-dc-")&&B.name!=="data-dcid")H[B.name]=B.value}let j=J.parentElement,L=j?window.getComputedStyle(j).display:"",U=j&&(L==="flex"||L==="inline-flex")?window.getComputedStyle(j).flexDirection:"";return{authored:V,computed:q,customStyles:X,attrs:H,parentDisplay:L,parentFlexDirection:U}}catch{return{authored:{},computed:{},customStyles:{},attrs:{}}}}function H7(J,Q){let $=J.el,V=$&&$.getBoundingClientRect?$.getBoundingClientRect():null,q=J.cdId,G=q?R7(q,J.artboardId):J.artboardId?`[data-dc-screen="${J.artboardId}"]`:PJ($),K=q&&typeof document<"u"?S7(document,G,$):0;return{file:Q??U7(),id:q??void 0,selector:G,artboardId:J.artboardId,index:K,tag:$?.tagName.toLowerCase()??"",classes:Z7($),text:DJ($,240),dom_path:C7($),bounds:V?{x:Math.round(V.left),y:Math.round(V.top),w:Math.round(V.width),h:Math.round(V.height)}:null,worldW:$ instanceof HTMLElement?Math.round($.offsetWidth):void 0,worldH:$ instanceof HTMLElement?Math.round($.offsetHeight):void 0,html:$?($.outerHTML??"").slice(0,4000):"",...(()=>{if($?.tagName?.toLowerCase()!=="img")return{};let X=/assets\/[0-9a-f]{8}\.[a-z0-9]+/i,H=$.getAttribute?.("data-photo-asset");if(H&&X.test(H))return{photoKind:"artboard-img",photoAsset:H};let j=$.getAttribute?.("src")||"",L=X.exec(j);return L?{photoKind:"artboard-img",photoAsset:L[0]}:{}})(),...NJ($)}}import*as F7 from"lib0/decoding";import*as a from"lib0/encoding";import{createContext as IJ,useCallback as lQ,useContext as OJ,useEffect as rQ,useMemo as nQ,useReducer as oQ,useRef as aQ,useState as sQ}from"react";import{Awareness as eQ,applyAwarenessUpdate as J0,encodeAwarenessUpdate as Q0}from"y-protocols/awareness";import{readSyncMessage as V0,writeSyncStep1 as Z0,writeUpdate as q0}from"y-protocols/sync";import*as TJ from"yjs";import*as _J from"yjs";var AJ=new WeakSet;function f7(J){return AJ.add(J),J}var pQ=f7(Object.freeze({maudeOrigin:"shell-edit"})),uQ=f7(Object.freeze({maudeOrigin:"sync-agent"}));import{jsx as W0}from"react/jsx-runtime";var kJ=IJ(null);function p7(){return OJ(kJ)}import{createContext as EJ,useCallback as l,useContext as P7,useEffect as wJ,useMemo as yJ,useRef as bJ,useState as xJ}from"react";import{jsx as D7,Fragment as RJ}from"react/jsx-runtime";var q7=EJ(null);function r(J){return J.id?`id:${J.id}`:`sel:${J.selector}`}function u7(J){let Q=[],$=new Set;for(let V of J){let q=r(V);if($.has(q))continue;$.add(q),Q.push(V)}return Q}var vJ=50;function CJ({children:J,postTarget:Q}){let[$,V]=xJ([]),q=bJ(null),G=l((B)=>{if(q.current)clearTimeout(q.current);q.current=setTimeout(()=>{q.current=null;let F=Q??(typeof window<"u"?window.parent:null);if(!F)return;let Y=B.length===0?null:B.length===1?B[0]??null:B;try{F.postMessage({dgn:"select-set",selection:Y},"*")}catch{}},vJ)},[Q]);wJ(()=>()=>{if(q.current)clearTimeout(q.current)},[]);let K=l((B)=>{let F=u7(Array.isArray(B)?B:[B]);V(F),G(F)},[G]),X=l((B)=>{let F=Array.isArray(B)?B:[B];V((Y)=>{let P=u7([...Y,...F]);return G(P),P})},[G]),H=l((B)=>{let F=r(B);V((Y)=>{let P=Y.filter((_)=>r(_)!==F);return G(P),P})},[G]),j=l((B)=>{let F=r(B);V((Y)=>{let P=Y.some((_)=>r(_)===F)?Y.filter((_)=>r(_)!==F):[...Y,B];return G(P),P})},[G]),L=l(()=>{V([]),G([])},[G]),U=yJ(()=>({selected:$,replace:K,add:X,remove:H,toggle:j,clear:L}),[$,K,X,H,j,L]);return D7(q7.Provider,{value:U,children:J})}function m7({children:J}){if(P7(q7))return D7(RJ,{children:J});return D7(CJ,{children:J})}function G7(){let J=P7(q7);if(!J)throw Error("useSelectionSet must be used inside <SelectionSetProvider>");return J}function d7(){return P7(q7)}import{jsx as O,jsxs as b}from"react/jsx-runtime";var SJ="/_client/comments-overlay.css";function gJ(){if(typeof document>"u")return;if(document.getElementById("cm-overlay-css"))return;let J=document.createElement("link");J.id="cm-overlay-css",J.rel="stylesheet",J.href=SJ,document.head.appendChild(J)}function hJ(){if(typeof window>"u")return null;try{let J=window.location.pathname;if(J==="/_canvas-shell.html"||J==="/_canvas-shell"){let Q=new URLSearchParams(window.location.search),$=Q.get("canvas")??"",V=(Q.get("designRel")??".design").replace(/^\/+|\/+$/g,"");return $?`${V}/${$}`:null}return decodeURIComponent(J).replace(/^\//,"")}catch{return null}}function fJ(J){if(!J.selector)return null;let Q=null;try{let $=document.querySelectorAll(J.selector),V=J.index&&J.index>0&&J.index<$.length?J.index:0;Q=$[V]??$[0]??null}catch{Q=null}if(Q&&J.tag&&Q.tagName.toLowerCase()!==J.tag.toLowerCase())Q=null;if(!Q&&J.dom_path?.length){let $=J.selector.match(/data-dc-screen="([^"]+)"/)?.[1];Q=h7(document,{artboardId:$,tag:J.tag,classes:J.classes,dom_path:J.dom_path})}return Q}function j7(J){let Q=fJ(J);if(!Q?.isConnected)return null;let $=Q.getBoundingClientRect();if($.width===0&&$.height===0)return null;return{x:$.left,y:$.top,w:$.width,h:$.height}}function r7(J,Q){let V=typeof window<"u"?window.innerWidth:J.x+Q.w,q=typeof window<"u"?window.innerHeight:J.y+Q.h,G=J.x;if(G+Q.w+8>V){let X=J.x-Q.w;G=X>=8?X:Math.max(8,V-Q.w-8)}let K=J.y;if(K+Q.h+8>q){let X=J.y-Q.h;K=X>=8?X:Math.max(8,q-Q.h-8)}return{x:G,y:K}}function n7(){gJ();let J=d7(),[Q,$]=u([]),[V,q]=u(null),[G,K]=u(null),X=s(()=>hJ(),[]);R(()=>{if(typeof document>"u")return;let W=document.getElementById("dgn-pin-layer");if(!W)return;let D=W.style.display;return W.style.display="none",()=>{W.style.display=D}},[]);let H=k((W)=>{if(!J)return;if(!W?.selector){J.clear();return}let D=W.selector.match(/data-cd-id="([^"]+)"/),N=D?D[1]:void 0,A,I;try{let M=document.querySelector(W.selector);if(M)A=M.tagName.toLowerCase(),I=(M.getAttribute("class")??"").split(/\s+/).filter((T)=>T&&!T.startsWith("dgn-")&&!T.startsWith("dc-cv-")).join(" ")}catch{}J.replace({file:X??void 0,id:N,selector:W.selector,tag:A,classes:I,bounds:W.bounds??void 0})},[J,X]),j=S(Q);j.current=Q;let L=p7();R(()=>{if(!L)return;let W=L.doc.getArray("comments"),D=()=>{$(W.toArray())};if(W.length>0)D();return W.observe(D),()=>{try{W.unobserve(D)}catch{}}},[L]),R(()=>{if(typeof window>"u")return;let W=(D)=>{let N=D.data;if(!N||typeof N!=="object"||!N.dgn)return;if(N.dgn==="comments-set"&&Array.isArray(N.comments))$(N.comments);else if(N.dgn==="comment-focus"){let A=typeof N.id==="string"?N.id:null;q(A);let I=A?j.current.find((M)=>M.id===A):void 0;H(I)}};return window.addEventListener("message",W),()=>window.removeEventListener("message",W)},[H]),R(()=>{if(typeof document>"u")return;let W=(D)=>{let N=D.detail;if(!N?.selection)return;K({selection:N.selection,clientX:typeof N.clientX==="number"?N.clientX:0,clientY:typeof N.clientY==="number"?N.clientY:0})};return document.addEventListener("cm:open-composer",W),()=>document.removeEventListener("cm:open-composer",W)},[]);let U=k(()=>{if(K(null),typeof window>"u")return;try{window.parent.postMessage({dgn:"force-clear"},"*")}catch{}},[]),B=k((W)=>{if(!G)return;let D=G.selection,N={file:D.file,selector:D.selector,index:D.index,dom_path:D.dom_path,tag:D.tag,classes:D.classes,bounds:D.bounds,html_excerpt:D.html,text:W};if(typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-submit",payload:N},"*")}catch{}U()},[G,U]);R(()=>{if(!X)return;let W=!1;return(async()=>{try{let D=await fetch(`/_comments?file=${encodeURIComponent(X)}`);if(!D.ok)return;let N=await D.json();if(W)return;if(Array.isArray(N.comments))$((A)=>A.length===0?N.comments??[]:A)}catch{}})(),()=>{W=!0}},[X]);let F=s(()=>{return Q.slice().sort((D,N)=>D.created.localeCompare(N.created)).filter((D)=>D.status!=="resolved")},[Q]),Y=s(()=>{let W=new Map;return Q.slice().sort((N,A)=>N.created.localeCompare(A.created)).forEach((N,A)=>{W.set(N.id,A+1)}),W},[Q]),P=k((W)=>{if(q(W),H(Q.find((D)=>D.id===W)),typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-click",id:W},"*")}catch{}},[Q,H]),_=k((W,D)=>{if(typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-patch",id:W,patch:D},"*")}catch{}},[]),Z=k((W)=>{if(typeof window>"u")return;try{window.parent.postMessage({dgn:"comment-delete",id:W},"*")}catch{}q((D)=>D===W?null:D)},[]),z=k(async(W,D)=>{if(typeof fetch>"u")return!1;try{let N=await fetch(`/_api/comments/${encodeURIComponent(W)}/reply`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({body:D})});if(!N.ok)return!1;let A=await N.json();return $((I)=>I.map((M)=>M.id===A.id?A:M)),!0}catch{return!1}},[]);return b("div",{className:"cm-layer","aria-hidden":!1,children:[F.map((W)=>{let D=Y.get(W.id)??0;return O(dJ,{comment:W,sequence:D,focused:V===W.id,onClick:P,onOrphaned:Z},W.id)}),G?O(iJ,{state:G,onSubmit:B,onCancel:U}):null,(()=>{if(!V)return null;let W=F.find((D)=>D.id===V);if(!W)return null;return O(cJ,{comment:W,sequence:Y.get(W.id)??0,onClose:()=>{q(null),J?.clear()},onPatch:(D)=>_(W.id,D),onDelete:()=>Z(W.id),onReply:(D)=>z(W.id,D)})})()]})}var M7=null;async function pJ(){if(!M7)M7=(async()=>{try{let J=await fetch("/_api/git-committers");if(!J.ok)return[];let Q=await J.json();return Array.isArray(Q.committers)?Q.committers:[]}catch{return[]}})();return M7}function i7(J){return(J.trim().split(/\s+/)[0]??"").replace(/[^\w.-]/g,"").toLowerCase()}function uJ(J,Q){if(Q<=0||Q>J.length)return null;let $=Q-1;while($>=0){let V=J[$]??"";if(V==="@"){let q=$>0?J[$-1]:"";if($===0||/\s/.test(q??"")){let G=J.slice($+1,Q);return{start:$,end:Q,query:G}}return null}if(!/[\w.-]/.test(V))return null;$-=1}return null}function o7({className:J,value:Q,onChange:$,onKeyDown:V,placeholder:q,rows:G,disabled:K,textareaRef:X,ariaLabel:H}){let j=S(null),L=k((M)=>{if(j.current=M,X)X.current=M},[X]),[U,B]=u([]),[F,Y]=u(null),[P,_]=u(0),Z=k(()=>{if(U.length>0)return;pJ().then((M)=>B(M))},[U.length]),z=s(()=>{if(!F)return[];let M=F.query.toLowerCase();return(!M?U:U.filter((E)=>E.name.toLowerCase().includes(M)||E.email.toLowerCase().includes(M))).slice(0,8)},[F,U]),W=k((M)=>{let T=M.selectionStart??M.value.length,E=uJ(M.value,T);Y(E),_(0)},[]),D=k((M)=>{$(M.target.value),W(M.target)},[$,W]),N=k((M)=>{if(!F)return;let T=j.current;if(!T)return;let E=`@${i7(M.name)}`,x=`${Q.slice(0,F.start)}${E} ${Q.slice(F.end)}`;$(x),Y(null);let w=F.start+E.length+1;requestAnimationFrame(()=>{T.focus(),T.setSelectionRange(w,w)})},[F,Q,$]),A=k((M)=>{if(F&&z.length>0){if(M.key==="ArrowDown"){M.preventDefault(),_((T)=>(T+1)%z.length);return}if(M.key==="ArrowUp"){M.preventDefault(),_((T)=>(T-1+z.length)%z.length);return}if(M.key==="Enter"||M.key==="Tab"){M.preventDefault();let T=z[P]??z[0];if(T)N(T);return}if(M.key==="Escape"){M.preventDefault(),Y(null);return}}V?.(M)},[F,z,P,N,V]),I=k((M)=>{W(M.currentTarget)},[W]);return b("div",{style:{position:"relative"},children:[O("textarea",{ref:L,className:J,value:Q,placeholder:q,rows:G,disabled:K,"aria-label":H,onChange:D,onKeyDown:A,onFocus:Z,onSelect:I,onClick:I}),F&&z.length>0?O("ul",{className:"cm-mention-popup",role:"listbox","aria-label":"Mention suggestions",style:{left:0,top:"100%"},children:z.map((M,T)=>{return b("li",{role:"option","aria-selected":T===P,className:"cm-mention-popup__item",onMouseEnter:()=>_(T),onMouseDown:(x)=>{x.preventDefault(),N(M)},children:[b("span",{className:"cm-mention-popup__name",children:["@",i7(M.name)]}),O("span",{className:"cm-mention-popup__email",children:M.email})]},`${M.name}-${M.email}`)})}):null]})}var mJ=3000;function dJ({comment:J,sequence:Q,focused:$,onClick:V,onOrphaned:q}){let G=S(null),K=S(null),X=S(null);R(()=>{let L=()=>{K.current=null;let U=G.current;if(!U)return;let B=j7(J);if(B)X.current=null;else{if(X.current==null)X.current=Date.now();else if(Date.now()-X.current>mJ)q(J.id);if(J.bounds)B={x:J.bounds.x,y:J.bounds.y,w:J.bounds.w,h:J.bounds.h}}if(!B){U.style.display="none",K.current=requestAnimationFrame(L);return}U.style.display="grid";let F=Math.round(B.x+B.w-12),Y=Math.round(B.y-12);U.style.left=`${F}px`,U.style.top=`${Y}px`,K.current=requestAnimationFrame(L)};return K.current=requestAnimationFrame(L),()=>{if(K.current!=null)cancelAnimationFrame(K.current)}},[J,q]);let H=J.author?.trim()||"unknown",j=`Comment ${Q} by ${H}`;return O("button",{ref:G,type:"button",className:"cm-pin","data-resolved":J.status==="resolved"?"true":"false","data-focused":$?"true":"false","data-comment-pin":J.id,"aria-label":j,"aria-expanded":$,title:J.text.slice(0,200),onClick:(L)=>{L.preventDefault(),L.stopPropagation(),V(J.id)},children:Q})}function iJ({state:J,onSubmit:Q,onCancel:$}){let[V,q]=u(""),G=S(null),K=S(null),X=S(null);R(()=>{let U=()=>{X.current=null;let B=K.current;if(!B)return;let F=nJ(J),Y=r7(F,{w:B.offsetWidth,h:B.offsetHeight});B.style.left=`${Math.round(Y.x)}px`,B.style.top=`${Math.round(Y.y)}px`,X.current=requestAnimationFrame(U)};return X.current=requestAnimationFrame(U),()=>{if(X.current!=null)cancelAnimationFrame(X.current)}},[J]),R(()=>{G.current?.focus()},[]);let H=k(()=>{let U=V.trim();if(!U)return;Q(U)},[V,Q]),j=k((U)=>{if(U.key==="Escape"){U.preventDefault(),$();return}if((U.metaKey||U.ctrlKey)&&U.key==="Enter")U.preventDefault(),H()},[$,H]),L=s(()=>{let U=J.selection.selector||"";if(!U)return J.selection.tag||"canvas";let B=U.match(/data-cd-id="([^"]+)"/);if(B)return`cd:${B[1]}`;return U.length>36?`${U.slice(0,33)}…`:U},[J.selection]);return b("div",{ref:K,className:"cm-composer",role:"dialog","aria-label":"New comment",onClick:(U)=>U.stopPropagation(),onPointerDown:(U)=>U.stopPropagation(),children:[b("div",{className:"cm-composer__head",children:[O("span",{children:"New comment"}),O("span",{className:"cm-composer__selector",children:L})]}),O(o7,{textareaRef:G,className:"cm-composer__textarea",value:V,placeholder:"Type a comment. ⌘↵ to save · Esc to cancel · @name to tag",onChange:q,onKeyDown:j,rows:3,ariaLabel:"Comment body"}),b("div",{className:"cm-composer__actions",children:[O("button",{type:"button",className:"cm-btn",onClick:$,children:"Cancel"}),O("button",{type:"button",className:"cm-btn cm-btn--primary",disabled:!V.trim(),onClick:H,children:"Save"})]})]})}function cJ({comment:J,sequence:Q,onClose:$,onPatch:V,onDelete:q,onReply:G}){let K=S(null),X=S(null),H=S(null),[j,L]=u(""),[U,B]=u(!1);R(()=>{let Z=()=>{H.current=null;let z=K.current;if(!z)return;let W=rJ(J),D=r7(W,{w:z.offsetWidth,h:z.offsetHeight});z.style.left=`${Math.round(D.x)}px`,z.style.top=`${Math.round(D.y)}px`,H.current=requestAnimationFrame(Z)};return H.current=requestAnimationFrame(Z),()=>{if(H.current!=null)cancelAnimationFrame(H.current)}},[J]),R(()=>{K.current?.focus();let Z=J.id;return()=>{document.querySelector(`[data-comment-pin="${Z}"]`)?.focus()}},[J.id]),R(()=>{if(typeof document>"u")return;let Z=(z)=>{if(z.key!=="Escape")return;let W=K.current;if(!W)return;if(W.contains(z.target)||document.activeElement===W)z.preventDefault(),$()};return document.addEventListener("keydown",Z),()=>document.removeEventListener("keydown",Z)},[$]);let F=k(async()=>{let Z=j.trim();if(!Z||U)return;B(!0);let z=await G(Z);if(B(!1),z)L(""),X.current?.focus()},[j,U,G]),Y=k((Z)=>{if((Z.metaKey||Z.ctrlKey)&&Z.key==="Enter")Z.preventDefault(),F()},[F]),P=`cm-thread-head-${J.id}`,_=lJ(J.selector,"");return b("div",{ref:K,className:"cm-thread",role:"dialog","aria-labelledby":P,tabIndex:-1,onClick:(Z)=>Z.stopPropagation(),onPointerDown:(Z)=>Z.stopPropagation(),children:[b("div",{className:"cm-thread__head",id:P,children:[b("div",{className:"cm-thread__head-row",children:[O("span",{className:"cm-thread__seq","aria-hidden":"true",children:Q}),O("span",{className:"cm-thread__author",children:J.author?.trim()||"unknown"}),O("span",{className:"cm-thread__time",children:l7(J.created)}),O("button",{type:"button",className:"cm-thread__close","aria-label":"Close thread",title:"Close · Esc",onClick:$,children:"×"})]}),_?O("code",{className:"cm-thread__selector",children:_}):null]}),O("div",{className:"cm-thread__body",children:c7(J.text)}),(J.thread??[]).map((Z)=>b("div",{className:"cm-thread__reply",children:[b("div",{className:"cm-thread__reply-head",children:[O("span",{className:"cm-thread__reply-author",children:Z.author?.trim()||"unknown"}),O("span",{className:"cm-thread__reply-time",children:l7(Z.created)})]}),O("div",{className:"cm-thread__reply-body",children:c7(Z.body)})]},Z.id)),b("div",{className:"cm-thread__reply-form",children:[O(o7,{textareaRef:X,className:"cm-thread__reply-textarea",value:j,placeholder:"Reply… ⌘↵ to send · @name to tag",onChange:L,onKeyDown:Y,rows:2,ariaLabel:"Reply",disabled:U}),O("div",{className:"cm-thread__reply-actions",children:O("button",{type:"button",className:"cm-btn cm-btn--primary",disabled:!j.trim()||U,onClick:()=>void F(),children:"Send"})})]}),b("div",{className:"cm-thread__actions",children:[J.status==="resolved"?O("button",{type:"button",className:"cm-btn",onClick:()=>V({status:"open"}),children:"↺ Reopen"}):O("button",{type:"button",className:"cm-btn cm-btn--primary",onClick:()=>{V({status:"resolved"}),$()},children:"✓ Resolve"}),O("button",{type:"button",className:"cm-btn cm-btn--danger",onClick:()=>{q(),$()},children:"Delete"})]})]})}function c7(J){if(!J)return null;let Q=/(@[\w][\w.-]*)/g;return J.split(Q).map((V,q)=>{let G=`${q}:${V}`;if(q%2===1)return O("strong",{"data-mention":"true",children:V},G);return O("span",{children:V},G)})}function l7(J){if(!J)return"";let Q=Date.parse(J);if(!Number.isFinite(Q))return"";let $=Math.round((Date.now()-Q)/1000);if($<60)return`${Math.max($,0)}s ago`;if($<3600)return`${Math.round($/60)}m ago`;if($<86400)return`${Math.round($/3600)}h ago`;return`${Math.round($/86400)}d ago`}function lJ(J,Q){if(!J)return Q;let $=J.match(/data-cd-id="([^"]+)"/);if($)return`cd:${$[1]}`;return J.length>36?`${J.slice(0,33)}…`:J}function rJ(J){let Q=J.selector?j7(J):null;if(Q)return{x:Q.x+Q.w-12,y:Q.y+16};if(J.bounds)return{x:J.bounds.x+J.bounds.w-12,y:J.bounds.y+16};return{x:16,y:16}}function nJ(J){if(J.clientX||J.clientY)return{x:J.clientX,y:J.clientY+8};if(J.selection.selector){let Q=j7(J.selection);if(Q)return{x:Q.x,y:Q.y+Q.h+8}}return{x:16,y:16}}import{useEffect as oJ}from"react";var aJ=new Set(["pen","highlighter","shape","rect","ellipse","arrow","sticky","text","section","eraser"]);function L7(J){return aJ.has(J)}var t=(J)=>!!(J.metaKey||J.ctrlKey);function e(J){if(J.type==="keydown"){if(J.isEditable)return{kind:"no-op"};if(J.metaKey||J.ctrlKey||J.altKey){if(J.key==="Escape")return{kind:"escape"};let $=(J.key||"").toLowerCase();if(!J.altKey&&(J.metaKey||J.ctrlKey)){if($==="z"&&J.shiftKey)return{kind:"redo"};if($==="z")return{kind:"undo"};if($==="y"&&!J.shiftKey)return{kind:"redo"}}return{kind:"no-op"}}let Q=(J.key||"").toLowerCase();if(Q==="v")return{kind:"tool",tool:"move"};if(Q==="h")return{kind:"tool",tool:"hand"};if(Q==="c")return{kind:"tool",tool:"comment"};if(Q==="b")return{kind:"tool",tool:"pen"};if(Q==="i")return{kind:"tool",tool:"highlighter"};if(Q==="r"||Q==="o")return{kind:"tool",tool:"shape"};if(Q==="a")return{kind:"tool",tool:"arrow"};if(Q==="n")return{kind:"tool",tool:"sticky"};if(Q==="t")return{kind:"tool",tool:"text"};if(Q==="s"&&J.shiftKey)return{kind:"tool",tool:"section"};if(Q==="e")return{kind:"tool",tool:"eraser"};if(J.key==="Escape")return{kind:"escape"};return{kind:"no-op"}}if(J.type==="contextmenu")return{kind:"context-menu",clientX:J.clientX??0,clientY:J.clientY??0};if(J.type==="pointermove"){if(L7(J.activeTool))return{kind:"no-op"};if(J.activeTool==="hand")return{kind:"no-op"};if(J.activeTool==="browse"){if(!t(J))return{kind:"no-op"};return{kind:"hover",deep:!0,clientX:J.clientX??0,clientY:J.clientY??0}}if(J.activeTool==="comment")return{kind:"hover",deep:!0,clientX:J.clientX??0,clientY:J.clientY??0};return{kind:"hover",deep:t(J),clientX:J.clientX??0,clientY:J.clientY??0}}if(J.type==="pointerdown"){if(J.button===2)return{kind:"context-menu",clientX:J.clientX??0,clientY:J.clientY??0};if(J.button===1||J.spaceHeld)return{kind:"no-op"};if(J.button!==0)return{kind:"no-op"};if(L7(J.activeTool)&&!t(J))return{kind:"no-op"};if(J.activeTool==="comment")return{kind:"drop-comment",clientX:J.clientX??0,clientY:J.clientY??0};if(J.activeTool==="hand")return{kind:"no-op"};if(J.activeTool==="browse"){if(!t(J))return{kind:"no-op"};return{kind:"select",mode:J.shiftKey?"add":"replace",deep:!0,clientX:J.clientX??0,clientY:J.clientY??0}}let Q=t(J);return{kind:"select",mode:!!J.shiftKey?"add":"replace",deep:Q,clientX:J.clientX??0,clientY:J.clientY??0}}return{kind:"no-op"}}function B7(J){if(!J||!J.tagName)return!1;let Q=J,$=Q.tagName;if($==="INPUT"||$==="TEXTAREA"||$==="SELECT")return!0;if(Q.isContentEditable)return!0;let V=Q.getAttribute?.("contenteditable");if(V==="true"||V==="plaintext-only"||V==="")return!0;return!1}function J7(J){if(!J||!J.closest)return!1;return!!J.closest(".cm-composer, .cm-thread, .cm-mention-popup, .cm-pin, [data-mediaref-player]")}function a7(J){let{hostRef:Q,getActiveTool:$,isSpaceHeld:V,callbacks:q,enabled:G=!0,claimableActions:K}=J;oJ(()=>{if(!G)return;let X=Q.current;if(!X)return;let H=(Z)=>K&&Z.kind!=="no-op"&&!K.has(Z.kind)?{kind:"no-op"}:Z,j=(Z)=>{switch(Z.kind){case"hover":q.onHover?.(Z);break;case"select":q.onSelect?.(Z);break;case"drop-comment":q.onDropComment?.(Z);break;case"context-menu":q.onContextMenu?.(Z);break;case"tool":q.onTool?.(Z);break;case"escape":q.onEscape?.();break;case"undo":q.onUndo?.();break;case"redo":q.onRedo?.();break;case"no-op":break}},L=(Z)=>{let z=H(e({type:"pointermove",button:Z.button,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,clientX:Z.clientX,clientY:Z.clientY,spaceHeld:V?.()??!1,activeTool:$()}));j(z)},U=(Z)=>{if(J7(Z.target))return;if(B7(Z.target))return;let z=H(e({type:"pointerdown",button:Z.button,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,clientX:Z.clientX,clientY:Z.clientY,spaceHeld:V?.()??!1,activeTool:$()}));if(z.kind!=="no-op")Z.preventDefault(),Z.stopImmediatePropagation();j(z)},B=(Z)=>{if(J7(Z.target))return;if(B7(Z.target))return;let z=H(e({type:"pointerdown",button:Z.button,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,clientX:Z.clientX,clientY:Z.clientY,spaceHeld:V?.()??!1,activeTool:$()}));if(z.kind!=="no-op"){if(Z.preventDefault(),Z.stopImmediatePropagation(),z.kind==="select")try{window.focus()}catch{}}},F=(Z)=>{if(J7(Z.target))return;if(B7(Z.target))return;let z=$(),W=Z.metaKey||Z.ctrlKey,D=z==="comment"?"drop-comment":z==="move"&&Z.button===0?"select":(L7(z)||z==="browse")&&W&&Z.button===0?"select":Z.button===2?"context-menu":null;if(D&&(!K||K.has(D)))Z.preventDefault(),Z.stopImmediatePropagation()},Y=(Z)=>{let z=H(e({type:"contextmenu",clientX:Z.clientX,clientY:Z.clientY,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,activeTool:$()}));if(z.kind==="no-op")return;Z.preventDefault(),Z.stopImmediatePropagation(),j(z)},P=(Z)=>{let z=H(e({type:"keydown",key:Z.key,metaKey:Z.metaKey,ctrlKey:Z.ctrlKey,shiftKey:Z.shiftKey,altKey:Z.altKey,isEditable:B7(Z.target),activeTool:$()}));if(z.kind==="tool"||z.kind==="escape"||z.kind==="undo"||z.kind==="redo")Z.preventDefault();j(z)};X.addEventListener("pointermove",L,{passive:!0}),X.addEventListener("pointerdown",U,{capture:!0}),X.addEventListener("mousedown",B,{capture:!0}),X.addEventListener("click",F,{capture:!0}),X.addEventListener("contextmenu",Y,{capture:!0});let _=X.ownerDocument??document;return _.addEventListener("keydown",P,!0),()=>{X.removeEventListener("pointermove",L),X.removeEventListener("pointerdown",U,{capture:!0}),X.removeEventListener("mousedown",B,{capture:!0}),X.removeEventListener("click",F,{capture:!0}),X.removeEventListener("contextmenu",Y,{capture:!0}),_.removeEventListener("keydown",P,!0)}},[G,Q,$,V,q,K])}function N7(J,Q,$,V){let q=J.elementFromPoint(Q,$);if(!q)return null;if(q.closest?.(".dc-mm, .dc-zoom-tb, .dc-tool-palette, .dc-context-menu, .dc-cv-group-bbox"))return null;let G=q.closest?.("[data-dc-screen]")??null,K=G?.getAttribute("data-dc-screen")??null,X=q.closest?.(".dc-artboard-body")??null;if(!X){if(G&&K)return{el:G,cdId:null,artboardId:K};return null}if(q===X){if(G&&K)return{el:G,cdId:null,artboardId:K};return null}if(V.deep){let B=q.getAttribute?.("data-cd-id")??null;return{el:q,cdId:B,artboardId:K}}let H=q,j=null;while(H&&H!==X){if(H.hasAttribute?.("data-cd-id"))j=H;H=H.parentElement}let L=j??q,U=L.getAttribute?.("data-cd-id")??null;return{el:L,cdId:U,artboardId:K}}import{useCallback as UQ,useEffect as QJ,useRef as K7}from"react";var sJ=!1;function s7(){return sJ}import{createContext as GQ,useCallback as O7,useContext as e7,useEffect as BQ,useMemo as WQ,useState as T7}from"react";function m(J,Q,$,V){return`url("data:image/svg+xml,${encodeURIComponent(J.trim())}") ${Q} ${$}, ${V}`}var A7="width='24' height='24' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'",I7="#1f1f1f",_7="stroke='#ffffff' stroke-linejoin='round' stroke-linecap='round'";function i(J,Q,$){let V=$?`<g transform='${$}'>`:"";return`<svg ${A7}>${V}<path fill='#ffffff' d='${J}'/><path fill='${I7}' d='${Q}'/>${$?"</g>":""}</svg>`}var t7="translate(0,32) scale(1,-1)",tJ=m(i("M10.25 8.25 L10.05 8.65 10 9 10 23.1 10.05 23.4 10.25 23.75 10.8 24 11.45 23.85 11.6 23.7 11.75 23.45 14.65 19.8 14.85 19.65 14.95 19.5 15.4 19.2 15.95 19.1 21.05 19.1 21.2 19.1 21.35 19.05 21.65 18.9 21.9 18.6 22 18.3 22 17.9 21.9 17.65 21.75 17.35 21.65 17.3 21.55 17.15 11.5 8.25 11.25 8.05 10.95 8 10.6 8.05 10.25 8.25 M9.15 6.6 L9.7 6.25 10 6.15 10.95 6 11.9 6.15 13 6.9 22.9 15.65 23 15.8 23.2 15.95 23.75 16.75 24 17.9 24 18.3 23.9 18.95 23.8 19.25 23.6 19.7 23.1 20.35 22.75 20.6 22.1 20.9 22.05 20.95 22 20.95 21.2 21.1 21.05 21.1 16.2 21.1 16.1 21.25 16.05 21.25 13.4 24.6 13.05 25.15 12.9 25.3 12.55 25.55 Q11.6 26.15 10.55 26 L10.5 26 Q9.65 25.85 9 25.3 L8.45 24.65 8.4 24.5 8.15 24.05 8 23.1 8 9 Q8 8.45 8.15 8.05 L8.25 7.75 8.45 7.35 9.15 6.6","M10.25 8.25 L10.6 8.05 10.95 8 11.25 8.05 11.5 8.25 21.55 17.15 21.65 17.3 21.75 17.35 21.9 17.65 22 17.9 22 18.3 21.9 18.6 21.65 18.9 21.35 19.05 21.2 19.1 21.05 19.1 15.95 19.1 15.4 19.2 14.95 19.5 14.85 19.65 14.65 19.8 11.75 23.45 11.6 23.7 11.45 23.85 10.8 24 10.25 23.75 10.05 23.4 10 23.1 10 9 10.05 8.65 10.25 8.25"),8,5,"default"),eJ=m(i("M28.55 17.8 Q29.4 20.3 28.75 22.8 L28.7 23 28.15 24.55 28.05 24.75 Q26.4 28.2 22.75 29.4 L22.45 29.5 18 29.9 17.75 29.85 Q15.8 29.25 13.8 28.1 L13.45 27.95 Q12 27.05 10.35 26.8 L10.25 26.75 7.9 26.7 7.8 26.7 Q6.1 26.9 4.8 25.8 L4.75 25.8 4.65 25.7 4.6 25.65 Q3.25 24.5 3.05 22.85 L3 22.75 Q2.8 20.95 4 19.5 5.05 18.15 6.75 17.95 L8.4 17.9 7.5 15.55 7.3 15.2 7.2 15 5 10.95 Q3.9 9.15 4.3 7.75 L4.4 7.5 Q4.75 6.15 6.45 5.2 9 3.65 11 5 11.05 4.1 11.5 3.45 12.15 2.1 14.2 1.6 L14.35 1.6 Q18.05 0.6 19.6 4.4 L19.65 4.55 Q20.75 3.65 22.7 3.75 L22.75 3.75 Q26.75 4 27 8.15 L27 8.25 27 8.35 27 8.45 Q26.9 10.75 27.1 12.6 27.15 14.65 28.2 16.75 L28.55 17.8 M26.65 18.4 L26.1 16.8 26.1 16.85 Q24.8 13.7 25 8.35 L25 8.25 Q24.85 5.9 22.6 5.75 20.7 5.65 20.4 7.35 L20.1 7.95 19.5 8.2 18.85 8.05 18.45 7.5 17.75 5.15 Q16.85 2.95 14.7 3.55 L14.65 3.55 Q12.55 4.05 13.15 6.15 L13.85 8.75 13.75 9.45 13.25 9.95 12.55 9.95 12 9.55 10.9 7.7 Q9.5 5.7 7.45 6.9 6.5 7.45 6.25 8.15 6.1 8.9 6.7 9.85 9.2 13.9 10.8 18.65 L10.8 19.3 10.4 19.8 9.75 19.95 Q8.35 19.8 6.95 19.95 6.1 20.05 5.55 20.75 4.9 21.55 5 22.55 5.15 23.55 6 24.2 L6.05 24.25 Q6.75 24.85 7.65 24.7 L7.7 24.7 10.65 24.8 Q12.7 25.15 14.45 26.2 L14.5 26.2 Q16.4 27.35 18.3 27.9 L22.05 27.5 22.1 27.5 Q24.95 26.55 26.25 23.85 L26.8 22.3 Q27.3 20.35 26.65 18.4","M26.65 18.4 Q27.3 20.35 26.8 22.3 L26.25 23.85 Q24.95 26.55 22.1 27.5 L22.05 27.5 18.3 27.9 Q16.4 27.35 14.5 26.2 L14.45 26.2 Q12.7 25.15 10.65 24.8 L7.7 24.7 7.65 24.7 Q6.75 24.85 6.05 24.25 L6 24.2 Q5.15 23.55 5 22.55 4.9 21.55 5.55 20.75 6.1 20.05 6.95 19.95 8.35 19.8 9.75 19.95 L10.4 19.8 10.8 19.3 10.8 18.65 Q9.2 13.9 6.7 9.85 6.1 8.9 6.25 8.15 6.5 7.45 7.45 6.9 9.5 5.7 10.9 7.7 L12 9.55 12.55 9.95 13.25 9.95 13.75 9.45 13.85 8.75 13.15 6.15 Q12.55 4.05 14.65 3.55 L14.7 3.55 Q16.85 2.95 17.75 5.15 L18.45 7.5 18.85 8.05 19.5 8.2 20.1 7.95 20.4 7.35 Q20.7 5.65 22.6 5.75 24.85 5.9 25 8.25 L25 8.35 Q24.8 13.7 26.1 16.85 L26.1 16.8 26.65 18.4"),12,12,"grab"),JQ=m(i("M28 14 Q28 9.85 24.45 6.9 20.95 4 16 4 11.05 4 7.5 6.9 L7.45 7 Q4 9.9 4 14 4 18.15 7.55 21.05 L7.5 21.05 Q9.2 22.45 11.2 23.2 L15.3 27.3 16 27.6 16.7 27.3 20.85 23.2 Q22.7 22.45 24.3 21.15 L24.45 21.05 Q28 18.15 28 14 M25.75 5.35 Q30.05 8.95 30 14 30.05 19.05 25.75 22.6 L25.4 22.85 Q23.8 24.1 22 24.9 L18.1 28.75 18.15 28.75 Q17.2 29.6 16 29.6 14.8 29.6 13.85 28.75 L13.9 28.75 10 24.9 6.6 22.85 6.25 22.6 Q1.95 19.05 2 14 1.95 8.95 6.25 5.35 10.3 2 16 2 21.7 2 25.75 5.35","M28 14 Q28 18.15 24.45 21.05 L24.3 21.15 Q22.7 22.45 20.85 23.2 L16.7 27.3 16 27.6 15.3 27.3 11.2 23.2 Q9.2 22.45 7.5 21.05 L7.55 21.05 Q4 18.15 4 14 4 9.9 7.45 7 L7.5 6.9 Q11.05 4 16 4 20.95 4 24.45 6.9 28 9.85 28 14"),12,21,"crosshair"),QQ=m(i("M4 13.1 L4 6 Q4 5.15 4.6 4.6 5.15 4 6 4 L13.1 4 Q13.95 4 14.55 4.6 L28.65 18.75 Q29.8 19.9 29.75 21.45 L29.75 21.6 29.75 21.7 Q29.75 23.2 28.7 24.35 L24.45 28.65 24.35 28.75 Q23.15 29.85 21.65 29.8 L21.55 29.8 21.4 29.8 Q20.2 29.8 19.25 29.15 L18 29.35 Q16.6 29.4 15.25 28 L15.2 27.95 8.2 20.95 Q7.6 20.35 7.6 19.55 7.6 18.7 8.2 18.1 L4.6 14.5 Q4 13.9 4 13.1 M19.5 26.65 L20.1 27.25 Q20.7 27.85 21.5 27.8 22.35 27.85 23 27.25 L27.25 22.95 Q27.8 22.35 27.75 21.55 27.8 20.75 27.2 20.15 L13.1 6 6 6 6 13.1 12.35 19.45 9.6 19.5 16.65 26.55 Q18.05 28.05 19.5 26.65 M8.05 12.3 L8 8 12.25 8.05 13.8 9.6 9.6 13.85 8.05 12.3 M15.25 11.05 L23 18.8 18.8 23.05 11.05 15.3 15.25 11.05","M15.25 11.05 L11.05 15.3 18.8 23.05 23 18.8 15.25 11.05 M12.35 19.45 L6 13.1 6 6 13.1 6 27.2 20.15 Q27.8 20.75 27.75 21.55 27.8 22.35 27.25 22.95 L23 27.25 Q22.35 27.85 21.5 27.8 20.7 27.85 20.1 27.25 L19.5 26.65 12.35 19.45 M8.05 12.3 L9.6 13.85 13.8 9.6 12.25 8.05 8 8 8.05 12.3",t7),6,18,"crosshair"),$Q=m(i("M5.15 10.85 Q4 9.65 4 8.1 L4 7.95 4 7.85 Q3.95 6.2 5.1 5.15 6.25 4 7.85 4 L7.95 4 8.1 4 Q9.65 4 10.85 5.15 L11 5.3 14.3 5.25 Q15.15 5.25 15.75 5.85 L29.9 20 Q31 21.15 31 22.75 L31 22.85 31 23 Q31.05 24.5 29.9 25.7 L29.55 25.95 25.65 29.9 25.65 29.95 Q24.45 31.1 22.75 31.1 21.2 31.15 20 29.95 L5.85 15.8 Q5.25 15.2 5.25 14.35 L5.25 10.95 5.15 10.85 M19.95 24.2 L18.55 22.8 22.8 18.55 24.2 19.95 19.95 24.2 M28.45 21.4 L14.3 7.25 10.15 7.3 9.4 6.55 Q8.8 5.95 7.95 6 7.1 5.95 6.5 6.55 5.95 7.1 6 7.95 5.95 8.8 6.55 9.4 L7.25 10.1 7.25 14.35 21.4 28.5 Q22 29.1 22.75 29.1 23.6 29.1 24.2 28.5 L28.45 24.25 Q29.05 23.65 29 22.85 29.05 22 28.45 21.4 M9.25 13.5 L9.25 9.3 13.5 9.25 14.3 10.05 10.05 14.3 9.25 13.5 M17.15 21.4 L11.5 15.75 15.75 11.5 21.4 17.15 17.15 21.4","M17.15 21.4 L21.4 17.15 15.75 11.5 11.5 15.75 17.15 21.4 M28.45 21.4 Q29.05 22 29 22.85 29.05 23.65 28.45 24.25 L24.2 28.5 Q23.6 29.1 22.75 29.1 22 29.1 21.4 28.5 L7.25 14.35 7.25 10.1 6.55 9.4 Q5.95 8.8 6 7.95 5.95 7.1 6.5 6.55 7.1 5.95 7.95 6 8.8 5.95 9.4 6.55 L10.15 7.3 14.3 7.25 28.45 21.4 M19.95 24.2 L24.2 19.95 22.8 18.55 18.55 22.8 19.95 24.2 M9.25 13.5 L10.05 14.3 14.3 10.05 13.5 9.25 9.25 9.3 9.25 13.5",t7),6,18,"crosshair"),Q7=m(i("M17 2 Q18.2 2 19.15 2.9 20 3.8 20 5 L20 12 27 12 Q28.2 12 29.15 12.9 30 13.8 30 15 L30 17 Q30 18.2 29.15 19.15 28.2 20 27 20 L20 20 20 27 Q20 28.2 19.15 29.15 18.2 30 17 30 L15 30 Q13.8 30 12.9 29.15 12 28.2 12 27 L12 20 5 20 Q3.8 20 2.9 19.15 2 18.2 2 17 L2 15 Q2 13.8 2.9 12.9 3.8 12 5 12 L12 12 12 5 Q12 3.8 12.9 2.9 13.8 2 15 2 L17 2 M14 27 L14.3 27.7 Q14.6 28 15 28 L17 28 17.7 27.7 18 27 18 18.05 18.05 18 27 18 Q27.4 18 27.7 17.7 L28 17 28 15 27.7 14.3 Q27.4 14 27 14 L18 14 18 5 17.7 4.3 17 4 15 4 Q14.6 4 14.3 4.3 14 4.6 14 5 L14 14 5 14 Q4.6 14 4.3 14.3 4 14.6 4 15 L4 17 Q4 17.4 4.3 17.7 4.6 18 5 18 L14 18 14 27","M14 27 L14 18 5 18 Q4.6 18 4.3 17.7 4 17.4 4 17 L4 15 Q4 14.6 4.3 14.3 4.6 14 5 14 L14 14 14 5 Q14 4.6 14.3 4.3 14.6 4 15 4 L17 4 17.7 4.3 18 5 18 14 27 14 Q27.4 14 27.7 14.3 L28 15 28 17 27.7 17.7 Q27.4 18 27 18 L18.05 18 18 18.05 18 27 17.7 27.7 17 28 15 28 Q14.6 28 14.3 27.7 L14 27"),12,12,"crosshair"),VQ=m(i("M3.9 11.35 Q2.3 12.5 3.7 13.9 L16.4 26.65 Q17.85 28.05 19.45 26.9 L27.65 21.15 Q29.3 20 27.85 18.6 L15.15 5.85 Q13.75 4.45 12.1 5.6 L3.9 11.35 M1.05 12.4 Q1 10.95 2.75 9.75 L10.95 4 10.95 3.95 Q14 1.85 16.6 4.45 L29.3 17.2 Q30.8 18.65 30.55 20.1 30.55 21.55 28.8 22.8 L20.6 28.55 20.65 28.55 Q17.7 30.65 15 28.1 L15 28.05 2.3 15.3 2.3 15.35 Q0.8 13.85 1.05 12.4 M13.5 7 L19.85 13.35 11.65 19.15 5.3 12.75 13.5 7","M13.5 7 L5.3 12.75 11.65 19.15 19.85 13.35 13.5 7 M3.9 11.35 L12.1 5.6 Q13.75 4.45 15.15 5.85 L27.85 18.6 Q29.3 20 27.65 21.15 L19.45 26.9 Q17.85 28.05 16.4 26.65 L3.7 13.9 Q2.3 12.5 3.9 11.35"),6,14,"cell"),ZQ=m(`<svg ${A7}><path d='M16 4V28M11 4H21M11 28H21' fill='none' ${_7} stroke-width='5'/><path d='M16 4V28M11 4H21M11 28H21' fill='none' stroke='${I7}' stroke-width='2.25' stroke-linecap='round'/></svg>`,12,12,"text"),qQ=m(`<svg ${A7}><path d='M6 5H21L26 10V27H6Z' fill='${I7}' ${_7} stroke-width='2.5'/><path d='M21 5V11H26' fill='none' ${_7} stroke-width='2.25'/></svg>`,5,5,"crosshair"),C=Object.freeze({browse:"default",move:tJ,hand:eJ,comment:JQ,pen:QQ,section:Q7,highlighter:$Q,shape:Q7,rect:Q7,ellipse:Q7,sticky:qQ,arrow:Q7,text:ZQ,eraser:VQ});import{jsx as k7,Fragment as zQ}from"react/jsx-runtime";var KQ=Object.freeze([{id:"browse",label:"Browse",shortcut:"",cursor:C.browse},{id:"move",label:"Select",shortcut:"V",cursor:C.move},{id:"hand",label:"Hand",shortcut:"H",cursor:C.hand},{id:"comment",label:"Comment",shortcut:"C",cursor:C.comment},{id:"pen",label:"Pen",shortcut:"B",cursor:C.pen},{id:"highlighter",label:"Highlighter",shortcut:"I",cursor:C.highlighter},{id:"shape",label:"Shape",shortcut:"R",cursor:C.shape},{id:"sticky",label:"Sticky",shortcut:"N",cursor:C.sticky},{id:"section",label:"Section",shortcut:"⇧S",cursor:C.shape},{id:"arrow",label:"Arrow",shortcut:"A",cursor:C.arrow},{id:"text",label:"Text",shortcut:"T",cursor:C.text},{id:"eraser",label:"Eraser",shortcut:"E",cursor:C.eraser}]),E7=GQ(null);function XQ({children:J,tools:Q=KQ,initial:$="browse"}){let[V,q]=T7($),[G,K]=T7(()=>({tool:null,locked:!1})),X=O7((F)=>{q(F),K((Y)=>Y.locked&&Y.tool===F?Y:{tool:null,locked:!1})},[]),H=O7((F)=>{K((Y)=>{if(Y.locked&&Y.tool===F)return{tool:null,locked:!1};return{tool:F,locked:!0}}),q(F)},[]),j=O7(()=>{K({tool:null,locked:!1})},[]),[L,U]=T7("rounded");BQ(()=>{if(typeof document>"u")return;let F=Q.find((_)=>_.id===V);if(!F)return;let Y=document.body.style.cursor,P=document.getElementById("dc-tool-cursor");if(!P)P=document.createElement("style"),P.id="dc-tool-cursor",document.head.appendChild(P);if(V==="browse"){if(document.body.style.cursor="",P.textContent="",typeof window<"u"&&window.parent&&window.parent!==window)try{window.parent.postMessage({dgn:"tool-cursor",tool:V},"*")}catch{}return()=>{document.body.style.cursor=Y}}if(document.body.style.cursor=F.cursor,P.textContent=`* { cursor: ${F.cursor} !important; }`,typeof window<"u"&&window.parent&&window.parent!==window)try{window.parent.postMessage({dgn:"tool-cursor",tool:V},"*")}catch{}return()=>{document.body.style.cursor=Y;let _=document.getElementById("dc-tool-cursor");if(_)_.textContent=""}},[V,Q]);let B=WQ(()=>({tool:V,setTool:X,tools:Q,sticky:G,toggleSticky:H,clearSticky:j,shapeKind:L,setShapeKind:U}),[V,X,Q,G,H,j,L]);return k7(E7.Provider,{value:B,children:J})}function JJ({children:J}){if(e7(E7))return k7(zQ,{children:J});return k7(XQ,{children:J})}function W7(){let J=e7(E7);if(!J)throw Error("useToolMode must be used inside <ToolProvider>");return J}import{jsx as IQ}from"react/jsx-runtime";var YQ=`
2
2
  .dc-el-resize-handle {
3
3
  position: fixed;
4
4
  width: 8px;
@@ -56,4 +56,4 @@ import{Component as _Q,createElement as g,Fragment as AQ,useCallback as w7,useEf
56
56
  @media (prefers-reduced-motion: reduce) {
57
57
  .dc-el-resize-handle, .dc-el-resize-readout { transition-duration: 1ms; }
58
58
  }
59
- `.trim();function XQ(){if(typeof document>"u")return;if(document.getElementById("dc-el-resize-css"))return;let J=document.createElement("style");J.id="dc-el-resize-css",J.textContent=UQ,document.head.appendChild(J)}var zQ=["nw","n","ne","e","se","s","sw","w"];function YQ(J){return{movesLeft:J==="nw"||J==="w"||J==="sw",movesRight:J==="ne"||J==="e"||J==="se",movesTop:J==="nw"||J==="n"||J==="ne",movesBottom:J==="sw"||J==="s"||J==="se"}}var n=(J)=>Math.round(J*100)/100,U7=1;function HQ(J,Q,$,V,q,B){let{movesLeft:K,movesRight:U,movesTop:H,movesBottom:M}=YQ(J),j=q.center,z=Q.w,G=Q.h;if(U)z=Q.w+(j?2*$:$);else if(K)z=Q.w-(j?2*$:$);if(M)G=Q.h+(j?2*V:V);else if(H)G=Q.h-(j?2*V:V);if(q.aspect&&Q.w>0&&Q.h>0){let Y=Q.w/Q.h;if((K||U)&&(H||M)){let _=Math.abs(z-Q.w)/Q.w,Z=Math.abs(G-Q.h)/Q.h;if(_>=Z)G=z/Y;else z=G*Y}else if(K||U)G=z/Y;else if(H||M)z=G*Y}if(z<U7)z=U7;if(G<U7)G=U7;let F={width:n(z),height:n(G)};if(j){if(B.canMoveLeft&&(K||U))F.left=n(Q.left+(Q.w-z)/2);if(B.canMoveTop&&(H||M))F.top=n(Q.top+(Q.h-G)/2)}else{if(B.canMoveLeft&&K)F.left=n(Q.left+Q.w-z);if(B.canMoveTop&&H)F.top=n(Q.top+Q.h-G)}return F}function QJ(J){if(!J||J==="none")return 0;let Q=/matrix\(([^)]+)\)/.exec(J);if(!Q)return 0;let $=Q[1].split(",").map(Number),V=$[0]??1,q=$[1]??0;return Math.round(Math.atan2(q,V)*(180/Math.PI)*100)/100}function FQ(J){if(!J||J==="none")return 1;let Q=/matrix\(([^)]+)\)/.exec(J);if(!Q)return 1;let $=Q[1].split(",").map(Number),V=$[0]??1,q=$[1]??0,B=Math.hypot(V,q);return B>0?B:1}function DQ(J){let Q=J.closest(".dc-world");if(!Q)return 1;let $=getComputedStyle(Q),V=Number.parseFloat($.zoom||"1")||1;return FQ($.transform)*V}function $J(J,Q,$){let V=$*Math.PI/180,q=Math.cos(V),B=Math.sin(V);return[J*q-Q*B,J*B+Q*q]}function VJ(J,Q,$,V){return Math.atan2(V-Q,$-J)}function LQ(J,Q,$,V){let q=J+($-Q)*(180/Math.PI);while(q>180)q-=360;while(q<=-180)q+=360;if(V)q=Math.round(q/15)*15;return Math.round(q*100)/100}function PQ(J,Q){let $={width:`${Q.width}px`,height:`${Q.height}px`};if(typeof Q.left==="number")$.left=`${Q.left}px`;if(typeof Q.top==="number")$.top=`${Q.top}px`;try{window.parent.postMessage({dgn:"resize-request",id:J.cdId,patch:$,before:J.before,idIndex:J.idIndex},"*")}catch{}}function MQ(J,Q){if(!J.artboardId)return;try{window.parent.postMessage({dgn:"resize-artboard-request",artboardId:J.artboardId,width:Q.width,height:Q.height},"*")}catch{}}function jQ(J,Q){try{window.parent.postMessage({dgn:"resize-request",id:J.cdId,patch:{transform:Q},before:J.before,idIndex:J.idIndex},"*")}catch{}}function ZJ(){XQ();let{selected:J}=B7(),{tool:Q}=W7(),$=K7(null),V=K7(null),q=K7(null),B=K7(null),K=J.length===1?J[0]:null,U=K&&typeof K.id==="string"?K.id:null,H=K&&!U&&typeof K.artboardId==="string"?K.artboardId:null,M=Q==="move"&&(!!U||!!H);JJ(()=>{let z=$.current;if(!z)return;let G=()=>{for(let Y of Array.from(z.children)){let L=Y;L.style.opacity="0",L.style.pointerEvents="none"}};if(!M||!K){G();return}let F=()=>{if(V.current=null,a7()){G(),V.current=requestAnimationFrame(F);return}let Y=Y7(document,K);if(!Y){G(),V.current=requestAnimationFrame(F);return}let L=Y.getBoundingClientRect();if(L.width<=0&&L.height<=0){G(),V.current=requestAnimationFrame(F);return}let _=H?["e","s","se"]:zQ,Z=H?[]:["rot-nw","rot-ne","rot-sw","rot-se"],X=_.length+Z.length+1;while(z.children.length<X)z.appendChild(document.createElement("div"));while(z.children.length>X)z.lastChild&&z.removeChild(z.lastChild);let W=L.left+L.width/2,D=L.top+L.height/2,N=QJ(getComputedStyle(Y).transform),A=DQ(Y),I=Y.offsetWidth*A/2,P=Y.offsetHeight*A/2,T={nw:[-I,-P],n:[0,-P],ne:[I,-P],e:[I,0],se:[I,P],s:[0,P],sw:[-I,P],w:[-I,0],"rot-nw":[-I,-P],"rot-ne":[I,-P],"rot-sw":[-I,P],"rot-se":[I,P]},E=[...Z,..._];for(let h=0;h<E.length;h++){let y=E[h],C=z.children[h],[d,c]=T[y]??[0,0],[KJ,UJ]=$J(d,c,N),XJ=W+KJ,zJ=D+UJ,X7=y.startsWith("rot-"),b7=y==="n"||y==="s",x7=y==="e"||y==="w",YJ=X7?10:b7?7:x7?3:4,HJ=X7?10:b7?3:x7?7:4;C.className="dc-el-resize-handle",C.dataset.corner=y,C.style.opacity="1",C.style.pointerEvents="auto",C.style.left=`${Math.round(XJ-YJ)}px`,C.style.top=`${Math.round(zJ-HJ)}px`,C.style.transform=X7?"":`rotate(${N}deg)`}let x=z.children[E.length],w=q.current;if(w&&w.el===Y&&!w.corner.startsWith("rot-")){let h=w.lastResult?.width??Y.offsetWidth,y=w.lastResult?.height??Y.offsetHeight,C=`${Math.round(h)} × ${Math.round(y)}`,d=w.lastResult?.left,c=w.lastResult?.top;if(typeof d==="number"||typeof c==="number")C+=` · ${Math.round(d??w.start.left)}, ${Math.round(c??w.start.top)}`;x.className="dc-el-resize-readout",x.textContent=C,x.style.opacity="1",x.style.left=`${Math.round(W)}px`,x.style.top=`${Math.round(D+P)}px`}else x.style.opacity="0";V.current=requestAnimationFrame(F)};return V.current=requestAnimationFrame(F),()=>{if(V.current!=null)cancelAnimationFrame(V.current)}},[M,K,H]);let j=KQ((z,G)=>{if(z.el.style.width=`${G.width}px`,z.el.style.height=`${G.height}px`,typeof G.left==="number")z.el.style.left=`${G.left}px`;if(typeof G.top==="number")z.el.style.top=`${G.top}px`;z.lastResult=G},[]);return JJ(()=>{let z=$.current;if(!z)return;let G=(Z,X)=>{let[W,D]=$J(X.clientX-Z.startClientX,X.clientY-Z.startClientY,-Z.angle);return HQ(Z.corner,Z.start,W/Z.elZoom,D/Z.elZoom,{aspect:!!X.shiftKey,center:!Z.artboardId&&!!X.altKey},Z.flags)},F=(Z)=>{let X=Z.target;if(!X?.classList.contains("dc-el-resize-handle"))return;let W=X.dataset.corner;if(!W||!K)return;let D=typeof K.id==="string"?K.id:null,N=!D&&typeof K.artboardId==="string"?K.artboardId:null;if(!D&&!N)return;let A=Y7(document,K);if(!A)return;Z.preventDefault(),Z.stopPropagation();let I=A.getBoundingClientRect(),P=A.offsetWidth?I.width/A.offsetWidth:1,T=getComputedStyle(A),E=!N&&(T.position==="absolute"||T.position==="fixed"),x=N?Number.NaN:Number.parseFloat(A.style.left),w=N?Number.NaN:Number.parseFloat(A.style.top),h=N?0:QJ(T.transform),y=P>0?P:1,C=I.left+I.width/2,d=I.top+I.height/2,c={pointerId:Z.pointerId,corner:W,el:A,cdId:D??"",artboardId:N,idIndex:D?g7(document,D,A):0,startClientX:Z.clientX,startClientY:Z.clientY,elZoom:y,angle:h,cx:C,cy:d,rotStartPointer:VJ(C,d,Z.clientX,Z.clientY),start:{w:(h?A.offsetWidth:I.width/y)||I.width/y,h:(h?A.offsetHeight:I.height/y)||I.height/y,left:x,top:w},flags:{canMoveLeft:E&&Number.isFinite(x),canMoveTop:E&&Number.isFinite(w)},before:{width:A.style.width||null,height:A.style.height||null,left:A.style.left||null,top:A.style.top||null,transform:A.style.transform||null},lastResult:null,lastTransform:null};q.current=c;try{X.setPointerCapture(Z.pointerId)}catch{}},Y=(Z)=>{let X=q.current;if(!X||Z.pointerId!==X.pointerId)return;if(Z.preventDefault(),X.corner.startsWith("rot-")){let D=`rotate(${LQ(X.angle,X.rotStartPointer,VJ(X.cx,X.cy,Z.clientX,Z.clientY),!!Z.shiftKey)}deg)`;X.el.style.transform=D,X.lastTransform=D;return}j(X,G(X,Z))},L=(Z)=>{let X=q.current;if(!X||Z.pointerId!==X.pointerId)return;if(q.current=null,X.corner.startsWith("rot-")){let N=X.lastTransform;if(!N||N===X.before.transform)return;B.current={el:X.el,before:X.before},jQ(X,N);return}let W=X.lastResult??G(X,Z);if(!(`${W.width}px`!==X.before.width||`${W.height}px`!==X.before.height||typeof W.left==="number"&&`${W.left}px`!==X.before.left||typeof W.top==="number"&&`${W.top}px`!==X.before.top))return;if(B.current={el:X.el,before:X.before},X.artboardId)MQ(X,W);else PQ(X,W)},_=(Z)=>{let X=Z.data;if(X?.dgn!=="resize-failed"&&X?.dgn!=="resize-artboard-failed")return;if(Z.source!==window.parent)return;let W=B.current;if(!W)return;if(W.el.style.width=W.before.width??"",W.el.style.height=W.before.height??"",W.before.left!==null||W.el.style.left)W.el.style.left=W.before.left??"";if(W.before.top!==null||W.el.style.top)W.el.style.top=W.before.top??"";if(W.before.transform!==null||W.el.style.transform)W.el.style.transform=W.before.transform??"";B.current=null};return z.addEventListener("pointerdown",F),window.addEventListener("pointermove",Y),window.addEventListener("pointerup",L),window.addEventListener("pointercancel",L),window.addEventListener("message",_),()=>{z.removeEventListener("pointerdown",F),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",L),window.removeEventListener("pointercancel",L),window.removeEventListener("message",_)}},[K,j]),NQ("div",{ref:$,"aria-hidden":"true"})}import{jsx as o,jsxs as SQ}from"react/jsx-runtime";var TQ=new Set(["drop-comment","tool","escape","hover"]);function V7(){return typeof document<"u"&&!document.querySelector(".dc-canvas")}function y7(J,Q){if(typeof document>"u")return null;let $=document.elementFromPoint(J,Q);if(!$)return null;if($.closest(".cm-composer, .cm-thread, .cm-mention-popup, .cm-pin, [data-mc-hover-halo], [data-mc-selection-halo], .dc-el-resize-handle"))return null;let V=$.tagName;if(V==="HTML"||V==="BODY")return null;return $}function kQ(J,Q){let $=y7(J,Q);if(!$)return null;return $.closest("[data-cd-id]")??$}function EQ({children:J,file:Q}){let{tool:$,setTool:V}=W7(),q=B7(),B=p(null),[K,U]=$7(null),H=p($);H.current=$;let M=IQ(()=>()=>H.current,[]);f(()=>{if($!=="comment")U(null)},[$]);let[j,z]=$7(null),[G,F]=$7(!1);return f(()=>{let Y=()=>F(V7());Y();let L=requestAnimationFrame(Y),_=setTimeout(Y,120);return()=>{cancelAnimationFrame(L),clearTimeout(_)}},[]),f(()=>{if(typeof document>"u")return;let Y=(L)=>{if(L.button!==0||!(L.metaKey||L.ctrlKey))return;if(!V7())return;if(J7(L.target))return;let _=kQ(L.clientX,L.clientY);if(!_)return;L.preventDefault(),L.stopImmediatePropagation();let Z=_.getAttribute("data-cd-id"),X=H7({el:_,cdId:Z,artboardId:null});if(L.shiftKey)q.add(X);else q.replace(X);z(_)};return document.addEventListener("pointerdown",Y,!0),()=>document.removeEventListener("pointerdown",Y,!0)},[q]),f(()=>{if(q.selected.length===0)z(null)},[q.selected]),f(()=>{let Y=B.current;if(Y)Y.setAttribute("data-active-tool",$);if(typeof document<"u"&&document.body)document.body.setAttribute("data-active-tool",$);return()=>{Y?.removeAttribute("data-active-tool")}},[$]),f(()=>{if(typeof window>"u")return;let Y=(L)=>{let _=L.data;if(!_||typeof _!=="object"||_.dgn!=="tool-set")return;if(typeof _.tool==="string")V(_.tool)};return window.addEventListener("message",Y),()=>window.removeEventListener("message",Y)},[V]),o7({hostRef:B,getActiveTool:M,claimableActions:TQ,callbacks:{onHover:({clientX:Y,clientY:L})=>{if(H.current!=="comment"||!V7()){U(null);return}let _=y7(Y,L);U((Z)=>Z===_?Z:_)},onTool:({tool:Y})=>V(Y),onEscape:()=>{if(H.current!=="move")V("move");if(U(null),q.clear(),typeof window<"u")try{window.parent.postMessage({dgn:"force-clear"},"*")}catch{}},onDropComment:({clientX:Y,clientY:L})=>bQ(Y,L,q,Q)}}),SQ("div",{"data-mc-host":!0,ref:B,style:{display:"contents"},children:[J,K?o(yQ,{el:K}):null,j?o(wQ,{el:j}):null,G?o(ZJ,{}):null,o(r7,{})]})}function wQ({el:J}){let Q=p(null),$=p(J);$.current=J;let V=p(null);return f(()=>{let q=()=>{V.current=null;let B=Q.current,K=$.current;if(B&&K?.isConnected){let U=K.getBoundingClientRect();if(U.width===0&&U.height===0)B.style.display="none";else B.style.display="block",B.style.left=`${Math.round(U.left)}px`,B.style.top=`${Math.round(U.top)}px`,B.style.width=`${Math.round(U.width)}px`,B.style.height=`${Math.round(U.height)}px`}else if(B)B.style.display="none";V.current=requestAnimationFrame(q)};return V.current=requestAnimationFrame(q),()=>{if(V.current!=null)cancelAnimationFrame(V.current)}},[]),o("div",{ref:Q,"aria-hidden":"true","data-mc-selection-halo":"",style:{position:"fixed",display:"none",pointerEvents:"none",zIndex:2147483645,border:"1.5px solid var(--maude-hud-accent, oklch(0.680 0.180 268))",borderRadius:"3px",boxSizing:"border-box"}})}function yQ({el:J}){let Q=p(null),$=p(J);$.current=J;let V=p(null);return f(()=>{let q=()=>{V.current=null;let B=Q.current,K=$.current;if(B&&K?.isConnected){let U=K.getBoundingClientRect();if(U.width===0&&U.height===0)B.style.display="none";else B.style.display="block",B.style.left=`${Math.round(U.left)}px`,B.style.top=`${Math.round(U.top)}px`,B.style.width=`${Math.round(U.width)}px`,B.style.height=`${Math.round(U.height)}px`}else if(B)B.style.display="none";V.current=requestAnimationFrame(q)};return V.current=requestAnimationFrame(q),()=>{if(V.current!=null)cancelAnimationFrame(V.current)}},[]),o("div",{ref:Q,"aria-hidden":"true","data-mc-hover-halo":"",style:{position:"fixed",display:"none",pointerEvents:"none",zIndex:2147483646,border:"2px solid var(--maude-hud-accent, #d63b1f)",borderRadius:"3px",boxSizing:"border-box"}})}function bQ(J,Q,$,V){if(typeof document>"u")return;let q=N7(document,J,Q,{deep:!0});if(!q)q=N7(document,J,Q,{deep:!1});if(!q&&!V7()&&typeof document.elementsFromPoint==="function"){let K=document.elementsFromPoint(J,Q);for(let U of K){let H=U.closest?.("[data-cd-id]");if(!H)continue;if(!H.closest(".dc-artboard-body"))continue;let M=H.closest("[data-dc-screen]");q={el:H,cdId:H.getAttribute("data-cd-id"),artboardId:M?.getAttribute("data-dc-screen")??null};break}}if(!q&&V7()){let K=y7(J,Q);if(K)q={el:K,cdId:K.getAttribute("data-cd-id"),artboardId:null}}if(!q){let K={file:V,id:void 0,selector:"",artboardId:null,tag:"",classes:"",text:"",dom_path:[],bounds:{x:J-12,y:Q-12,w:24,h:24},html:""};qJ(K,J,Q);return}let B=H7(q,V);$.replace(B),qJ(B,J,Q)}function qJ(J,Q,$){if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("cm:open-composer",{detail:{selection:J,clientX:Q,clientY:$}}))}catch{}if(typeof window<"u")try{window.parent.postMessage({dgn:"comment-compose",selection:J},"*")}catch{}}function GJ(J,Q){return g(e7,null,g(u7,null,g(EQ,{file:Q},g(J))))}function C0(J,Q){let $=OQ(Q.rootEl);if(!Q.commentsEnabled){$.render(g(J));return}let V=Q.file??z7();$.render(g(vQ,{initialCanvas:J,file:V}))}var BJ="__maudeCanvasRuntime";function xQ({Canvas:J,file:Q,onOk:$}){return f(()=>{$()},[]),GJ(J,Q)}class WJ extends _Q{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}componentDidUpdate(J){if(J.attempt!==this.props.attempt&&this.state.hasError)this.setState({hasError:!1})}render(){if(this.state.hasError)return this.props.fallback();return this.props.children}}function CQ({message:J}){return g("div",{className:"dc-hmr-holding",role:"status","aria-live":"polite",title:J?`Holding last working render — ${J}`:"Holding last working render"},"⏸ build error — držím poslední funkční verzi")}function vQ({initialCanvas:J,file:Q}){let[{canvas:$,attempt:V},q]=$7({canvas:J,attempt:0}),[B,K]=$7({on:!1}),U=p(null),H=p($);H.current=$,f(()=>{let G={remount:(F)=>q((Y)=>({canvas:F,attempt:Y.attempt+1})),setHolding:(F,Y)=>K(F?{on:!0,message:Y}:{on:!1})};return window[BJ]=G,()=>{window[BJ]=void 0}},[]);let M=w7(()=>{U.current=H.current,K((G)=>G.on?{on:!1}:G)},[]),j=w7(()=>{K({on:!0,message:"render error"})},[]),z=w7(()=>{let G=U.current;return G?GJ(G,Q):null},[Q]);return g(AQ,null,g(WJ,{attempt:V,onError:j,fallback:z},g(xQ,{key:V,Canvas:$,file:Q,onOk:M})),B.on?g(CQ,{message:B.message}):null)}export{kQ as pickSpecimenSelectEl,C0 as mountCanvas,V7 as isBareSpecimen,WJ as CanvasErrorBoundary};
59
+ `.trim();function HQ(){if(typeof document>"u")return;if(document.getElementById("dc-el-resize-css"))return;let J=document.createElement("style");J.id="dc-el-resize-css",J.textContent=YQ,document.head.appendChild(J)}var FQ=["nw","n","ne","e","se","s","sw","w"];function DQ(J){return{movesLeft:J==="nw"||J==="w"||J==="sw",movesRight:J==="ne"||J==="e"||J==="se",movesTop:J==="nw"||J==="n"||J==="ne",movesBottom:J==="sw"||J==="s"||J==="se"}}var n=(J)=>Math.round(J*100)/100,X7=1;function PQ(J,Q,$,V,q,G){let{movesLeft:K,movesRight:X,movesTop:H,movesBottom:j}=DQ(J),L=q.center,U=Q.w,B=Q.h;if(X)U=Q.w+(L?2*$:$);else if(K)U=Q.w-(L?2*$:$);if(j)B=Q.h+(L?2*V:V);else if(H)B=Q.h-(L?2*V:V);if(q.aspect&&Q.w>0&&Q.h>0){let Y=Q.w/Q.h;if((K||X)&&(H||j)){let _=Math.abs(U-Q.w)/Q.w,Z=Math.abs(B-Q.h)/Q.h;if(_>=Z)B=U/Y;else U=B*Y}else if(K||X)B=U/Y;else if(H||j)U=B*Y}if(U<X7)U=X7;if(B<X7)B=X7;let F={width:n(U),height:n(B)};if(L){if(G.canMoveLeft&&(K||X))F.left=n(Q.left+(Q.w-U)/2);if(G.canMoveTop&&(H||j))F.top=n(Q.top+(Q.h-B)/2)}else{if(G.canMoveLeft&&K)F.left=n(Q.left+Q.w-U);if(G.canMoveTop&&H)F.top=n(Q.top+Q.h-B)}return F}function $J(J){if(!J||J==="none")return 0;let Q=/matrix\(([^)]+)\)/.exec(J);if(!Q)return 0;let $=Q[1].split(",").map(Number),V=$[0]??1,q=$[1]??0;return Math.round(Math.atan2(q,V)*(180/Math.PI)*100)/100}function MQ(J){if(!J||J==="none")return 1;let Q=/matrix\(([^)]+)\)/.exec(J);if(!Q)return 1;let $=Q[1].split(",").map(Number),V=$[0]??1,q=$[1]??0,G=Math.hypot(V,q);return G>0?G:1}function jQ(J){let Q=J.closest(".dc-world");if(!Q)return 1;let $=getComputedStyle(Q),V=Number.parseFloat($.zoom||"1")||1;return MQ($.transform)*V}function VJ(J,Q,$){let V=$*Math.PI/180,q=Math.cos(V),G=Math.sin(V);return[J*q-Q*G,J*G+Q*q]}function ZJ(J,Q,$,V){return Math.atan2(V-Q,$-J)}function LQ(J,Q,$,V){let q=J+($-Q)*(180/Math.PI);while(q>180)q-=360;while(q<=-180)q+=360;if(V)q=Math.round(q/15)*15;return Math.round(q*100)/100}function NQ(J,Q){let $={width:`${Q.width}px`,height:`${Q.height}px`};if(typeof Q.left==="number")$.left=`${Q.left}px`;if(typeof Q.top==="number")$.top=`${Q.top}px`;try{window.parent.postMessage({dgn:"resize-request",id:J.cdId,patch:$,before:J.before,idIndex:J.idIndex},"*")}catch{}}function _Q(J,Q){if(!J.artboardId)return;try{window.parent.postMessage({dgn:"resize-artboard-request",artboardId:J.artboardId,width:Q.width,height:Q.height},"*")}catch{}}function AQ(J,Q){try{window.parent.postMessage({dgn:"resize-request",id:J.cdId,patch:{transform:Q},before:J.before,idIndex:J.idIndex},"*")}catch{}}function qJ(){HQ();let{selected:J}=G7(),{tool:Q}=W7(),$=K7(null),V=K7(null),q=K7(null),G=K7(null),K=J.length===1?J[0]:null,X=K&&typeof K.id==="string"?K.id:null,H=K&&!X&&typeof K.artboardId==="string"?K.artboardId:null,j=Q==="move"&&(!!X||!!H);QJ(()=>{let U=$.current;if(!U)return;let B=()=>{for(let Y of Array.from(U.children)){let P=Y;P.style.opacity="0",P.style.pointerEvents="none"}};if(!j||!K){B();return}let F=()=>{if(V.current=null,s7()){B(),V.current=requestAnimationFrame(F);return}let Y=Y7(document,K);if(!Y){B(),V.current=requestAnimationFrame(F);return}let P=Y.getBoundingClientRect();if(P.width<=0&&P.height<=0){B(),V.current=requestAnimationFrame(F);return}let _=H?["e","s","se"]:FQ,Z=H?[]:["rot-nw","rot-ne","rot-sw","rot-se"],z=_.length+Z.length+1;while(U.children.length<z)U.appendChild(document.createElement("div"));while(U.children.length>z)U.lastChild&&U.removeChild(U.lastChild);let W=P.left+P.width/2,D=P.top+P.height/2,N=$J(getComputedStyle(Y).transform),A=jQ(Y),I=Y.offsetWidth*A/2,M=Y.offsetHeight*A/2,T={nw:[-I,-M],n:[0,-M],ne:[I,-M],e:[I,0],se:[I,M],s:[0,M],sw:[-I,M],w:[-I,0],"rot-nw":[-I,-M],"rot-ne":[I,-M],"rot-sw":[-I,M],"rot-se":[I,M]},E=[...Z,..._];for(let h=0;h<E.length;h++){let y=E[h],v=U.children[h],[d,c]=T[y]??[0,0],[XJ,zJ]=VJ(d,c,N),UJ=W+XJ,YJ=D+zJ,z7=y.startsWith("rot-"),b7=y==="n"||y==="s",x7=y==="e"||y==="w",HJ=z7?10:b7?7:x7?3:4,FJ=z7?10:b7?3:x7?7:4;v.className="dc-el-resize-handle",v.dataset.corner=y,v.style.opacity="1",v.style.pointerEvents="auto",v.style.left=`${Math.round(UJ-HJ)}px`,v.style.top=`${Math.round(YJ-FJ)}px`,v.style.transform=z7?"":`rotate(${N}deg)`}let x=U.children[E.length],w=q.current;if(w&&w.el===Y&&!w.corner.startsWith("rot-")){let h=w.lastResult?.width??Y.offsetWidth,y=w.lastResult?.height??Y.offsetHeight,v=`${Math.round(h)} × ${Math.round(y)}`,d=w.lastResult?.left,c=w.lastResult?.top;if(typeof d==="number"||typeof c==="number")v+=` · ${Math.round(d??w.start.left)}, ${Math.round(c??w.start.top)}`;x.className="dc-el-resize-readout",x.textContent=v,x.style.opacity="1",x.style.left=`${Math.round(W)}px`,x.style.top=`${Math.round(D+M)}px`}else x.style.opacity="0";V.current=requestAnimationFrame(F)};return V.current=requestAnimationFrame(F),()=>{if(V.current!=null)cancelAnimationFrame(V.current)}},[j,K,H]);let L=UQ((U,B)=>{if(U.el.style.width=`${B.width}px`,U.el.style.height=`${B.height}px`,typeof B.left==="number")U.el.style.left=`${B.left}px`;if(typeof B.top==="number")U.el.style.top=`${B.top}px`;U.lastResult=B},[]);return QJ(()=>{let U=$.current;if(!U)return;let B=(Z,z)=>{let[W,D]=VJ(z.clientX-Z.startClientX,z.clientY-Z.startClientY,-Z.angle);return PQ(Z.corner,Z.start,W/Z.elZoom,D/Z.elZoom,{aspect:!!z.shiftKey,center:!Z.artboardId&&!!z.altKey},Z.flags)},F=(Z)=>{let z=Z.target;if(!z?.classList.contains("dc-el-resize-handle"))return;let W=z.dataset.corner;if(!W||!K)return;let D=typeof K.id==="string"?K.id:null,N=!D&&typeof K.artboardId==="string"?K.artboardId:null;if(!D&&!N)return;let A=Y7(document,K);if(!A)return;Z.preventDefault(),Z.stopPropagation();let I=A.getBoundingClientRect(),M=A.offsetWidth?I.width/A.offsetWidth:1,T=getComputedStyle(A),E=!N&&(T.position==="absolute"||T.position==="fixed"),x=N?Number.NaN:Number.parseFloat(A.style.left),w=N?Number.NaN:Number.parseFloat(A.style.top),h=N?0:$J(T.transform),y=M>0?M:1,v=I.left+I.width/2,d=I.top+I.height/2,c={pointerId:Z.pointerId,corner:W,el:A,cdId:D??"",artboardId:N,idIndex:D?g7(document,D,A):0,startClientX:Z.clientX,startClientY:Z.clientY,elZoom:y,angle:h,cx:v,cy:d,rotStartPointer:ZJ(v,d,Z.clientX,Z.clientY),start:{w:(h?A.offsetWidth:I.width/y)||I.width/y,h:(h?A.offsetHeight:I.height/y)||I.height/y,left:x,top:w},flags:{canMoveLeft:E&&Number.isFinite(x),canMoveTop:E&&Number.isFinite(w)},before:{width:A.style.width||null,height:A.style.height||null,left:A.style.left||null,top:A.style.top||null,transform:A.style.transform||null},lastResult:null,lastTransform:null};q.current=c;try{z.setPointerCapture(Z.pointerId)}catch{}},Y=(Z)=>{let z=q.current;if(!z||Z.pointerId!==z.pointerId)return;if(Z.preventDefault(),z.corner.startsWith("rot-")){let D=`rotate(${LQ(z.angle,z.rotStartPointer,ZJ(z.cx,z.cy,Z.clientX,Z.clientY),!!Z.shiftKey)}deg)`;z.el.style.transform=D,z.lastTransform=D;return}L(z,B(z,Z))},P=(Z)=>{let z=q.current;if(!z||Z.pointerId!==z.pointerId)return;if(q.current=null,z.corner.startsWith("rot-")){let N=z.lastTransform;if(!N||N===z.before.transform)return;G.current={el:z.el,before:z.before},AQ(z,N);return}let W=z.lastResult??B(z,Z);if(!(`${W.width}px`!==z.before.width||`${W.height}px`!==z.before.height||typeof W.left==="number"&&`${W.left}px`!==z.before.left||typeof W.top==="number"&&`${W.top}px`!==z.before.top))return;if(G.current={el:z.el,before:z.before},z.artboardId)_Q(z,W);else NQ(z,W)},_=(Z)=>{let z=Z.data;if(z?.dgn!=="resize-failed"&&z?.dgn!=="resize-artboard-failed")return;if(Z.source!==window.parent)return;let W=G.current;if(!W)return;if(W.el.style.width=W.before.width??"",W.el.style.height=W.before.height??"",W.before.left!==null||W.el.style.left)W.el.style.left=W.before.left??"";if(W.before.top!==null||W.el.style.top)W.el.style.top=W.before.top??"";if(W.before.transform!==null||W.el.style.transform)W.el.style.transform=W.before.transform??"";G.current=null};return U.addEventListener("pointerdown",F),window.addEventListener("pointermove",Y),window.addEventListener("pointerup",P),window.addEventListener("pointercancel",P),window.addEventListener("message",_),()=>{U.removeEventListener("pointerdown",F),window.removeEventListener("pointermove",Y),window.removeEventListener("pointerup",P),window.removeEventListener("pointercancel",P),window.removeEventListener("message",_)}},[K,L]),IQ("div",{ref:$,"aria-hidden":"true"})}import{jsx as o,jsxs as hQ}from"react/jsx-runtime";var wQ=new Set(["drop-comment","tool","escape","hover"]);function V7(){return typeof document<"u"&&!document.querySelector(".dc-canvas")}function y7(J,Q){if(typeof document>"u")return null;let $=document.elementFromPoint(J,Q);if(!$)return null;if($.closest(".cm-composer, .cm-thread, .cm-mention-popup, .cm-pin, [data-mc-hover-halo], [data-mc-selection-halo], .dc-el-resize-handle"))return null;let V=$.tagName;if(V==="HTML"||V==="BODY")return null;return $}function yQ(J,Q){let $=y7(J,Q);if(!$)return null;return $.closest("[data-cd-id]")??$}function bQ({children:J,file:Q}){let{tool:$,setTool:V}=W7(),q=G7(),G=p(null),[K,X]=$7(null),H=p($);H.current=$;let j=kQ(()=>()=>H.current,[]);f(()=>{if($!=="comment")X(null)},[$]);let[L,U]=$7(null),[B,F]=$7(!1);return f(()=>{let Y=()=>F(V7());Y();let P=requestAnimationFrame(Y),_=setTimeout(Y,120);return()=>{cancelAnimationFrame(P),clearTimeout(_)}},[]),f(()=>{if(typeof document>"u")return;let Y=(P)=>{if(P.button!==0||!(P.metaKey||P.ctrlKey))return;if(!V7())return;if(J7(P.target))return;let _=yQ(P.clientX,P.clientY);if(!_)return;P.preventDefault(),P.stopImmediatePropagation();let Z=_.getAttribute("data-cd-id"),z=H7({el:_,cdId:Z,artboardId:null});if(P.shiftKey)q.add(z);else q.replace(z);U(_)};return document.addEventListener("pointerdown",Y,!0),()=>document.removeEventListener("pointerdown",Y,!0)},[q]),f(()=>{if(q.selected.length===0)U(null)},[q.selected]),f(()=>{let Y=G.current;if(Y)Y.setAttribute("data-active-tool",$);if(typeof document<"u"&&document.body)document.body.setAttribute("data-active-tool",$);return()=>{Y?.removeAttribute("data-active-tool")}},[$]),f(()=>{if(typeof window>"u")return;let Y=(P)=>{let _=P.data;if(!_||typeof _!=="object"||_.dgn!=="tool-set")return;if(typeof _.tool==="string")V(_.tool)};return window.addEventListener("message",Y),()=>window.removeEventListener("message",Y)},[V]),a7({hostRef:G,getActiveTool:j,claimableActions:wQ,callbacks:{onHover:({clientX:Y,clientY:P})=>{if(H.current!=="comment"||!V7()){X(null);return}let _=y7(Y,P);X((Z)=>Z===_?Z:_)},onTool:({tool:Y})=>V(Y),onEscape:()=>{if(H.current!=="move")V("move");if(X(null),q.clear(),typeof window<"u")try{window.parent.postMessage({dgn:"force-clear"},"*")}catch{}},onDropComment:({clientX:Y,clientY:P})=>CQ(Y,P,q,Q)}}),hQ("div",{"data-mc-host":!0,ref:G,style:{display:"contents"},children:[J,K?o(vQ,{el:K}):null,L?o(xQ,{el:L}):null,B?o(qJ,{}):null,o(n7,{})]})}function xQ({el:J}){let Q=p(null),$=p(J);$.current=J;let V=p(null);return f(()=>{let q=()=>{V.current=null;let G=Q.current,K=$.current;if(G&&K?.isConnected){let X=K.getBoundingClientRect();if(X.width===0&&X.height===0)G.style.display="none";else G.style.display="block",G.style.left=`${Math.round(X.left)}px`,G.style.top=`${Math.round(X.top)}px`,G.style.width=`${Math.round(X.width)}px`,G.style.height=`${Math.round(X.height)}px`}else if(G)G.style.display="none";V.current=requestAnimationFrame(q)};return V.current=requestAnimationFrame(q),()=>{if(V.current!=null)cancelAnimationFrame(V.current)}},[]),o("div",{ref:Q,"aria-hidden":"true","data-mc-selection-halo":"",style:{position:"fixed",display:"none",pointerEvents:"none",zIndex:2147483645,border:"1.5px solid var(--maude-hud-accent, oklch(0.680 0.180 268))",borderRadius:"3px",boxSizing:"border-box"}})}function vQ({el:J}){let Q=p(null),$=p(J);$.current=J;let V=p(null);return f(()=>{let q=()=>{V.current=null;let G=Q.current,K=$.current;if(G&&K?.isConnected){let X=K.getBoundingClientRect();if(X.width===0&&X.height===0)G.style.display="none";else G.style.display="block",G.style.left=`${Math.round(X.left)}px`,G.style.top=`${Math.round(X.top)}px`,G.style.width=`${Math.round(X.width)}px`,G.style.height=`${Math.round(X.height)}px`}else if(G)G.style.display="none";V.current=requestAnimationFrame(q)};return V.current=requestAnimationFrame(q),()=>{if(V.current!=null)cancelAnimationFrame(V.current)}},[]),o("div",{ref:Q,"aria-hidden":"true","data-mc-hover-halo":"",style:{position:"fixed",display:"none",pointerEvents:"none",zIndex:2147483646,border:"2px solid var(--maude-hud-accent, #d63b1f)",borderRadius:"3px",boxSizing:"border-box"}})}function CQ(J,Q,$,V){if(typeof document>"u")return;let q=N7(document,J,Q,{deep:!0});if(!q)q=N7(document,J,Q,{deep:!1});if(!q&&!V7()&&typeof document.elementsFromPoint==="function"){let K=document.elementsFromPoint(J,Q);for(let X of K){let H=X.closest?.("[data-cd-id]");if(!H)continue;if(!H.closest(".dc-artboard-body"))continue;let j=H.closest("[data-dc-screen]");q={el:H,cdId:H.getAttribute("data-cd-id"),artboardId:j?.getAttribute("data-dc-screen")??null};break}}if(!q&&V7()){let K=y7(J,Q);if(K)q={el:K,cdId:K.getAttribute("data-cd-id"),artboardId:null}}if(!q){let K={file:V,id:void 0,selector:"",artboardId:null,tag:"",classes:"",text:"",dom_path:[],bounds:{x:J-12,y:Q-12,w:24,h:24},html:""};GJ(K,J,Q);return}let G=H7(q,V);$.replace(G),GJ(G,J,Q)}function GJ(J,Q,$){if(typeof document<"u")try{document.dispatchEvent(new CustomEvent("cm:open-composer",{detail:{selection:J,clientX:Q,clientY:$}}))}catch{}if(typeof window<"u")try{window.parent.postMessage({dgn:"comment-compose",selection:J},"*")}catch{}}function WJ(J,Q){return g(JJ,null,g(m7,null,g(bQ,{file:Q},g(J))))}function m0(J,Q){let $=EQ(Q.rootEl);if(!Q.commentsEnabled){$.render(g(J));return}let V=Q.file??U7();$.render(g(gQ,{initialCanvas:J,file:V}))}var BJ="__maudeCanvasRuntime";function RQ({Canvas:J,file:Q,onOk:$}){return f(()=>{$()},[]),WJ(J,Q)}class KJ extends OQ{state={hasError:!1};static getDerivedStateFromError(){return{hasError:!0}}componentDidCatch(){this.props.onError()}componentDidUpdate(J){if(J.attempt!==this.props.attempt&&this.state.hasError)this.setState({hasError:!1})}render(){if(this.state.hasError)return this.props.fallback();return this.props.children}}function SQ({message:J}){return g("div",{className:"dc-hmr-holding",role:"status","aria-live":"polite",title:J?`Holding last working render — ${J}`:"Holding last working render"},"⏸ build error — držím poslední funkční verzi")}function gQ({initialCanvas:J,file:Q}){let[{canvas:$,attempt:V},q]=$7({canvas:J,attempt:0}),[G,K]=$7({on:!1}),X=p(null),H=p($);H.current=$,f(()=>{let B={remount:(F)=>q((Y)=>({canvas:F,attempt:Y.attempt+1})),setHolding:(F,Y)=>K(F?{on:!0,message:Y}:{on:!1})};return window[BJ]=B,()=>{window[BJ]=void 0}},[]);let j=w7(()=>{X.current=H.current,K((B)=>B.on?{on:!1}:B)},[]),L=w7(()=>{K({on:!0,message:"render error"})},[]),U=w7(()=>{let B=X.current;return B?WJ(B,Q):null},[Q]);return g(TQ,null,g(KJ,{attempt:V,onError:L,fallback:U},g(RQ,{key:V,Canvas:$,file:Q,onOk:j})),G.on?g(SQ,{message:G.message}):null)}export{yQ as pickSpecimenSelectEl,m0 as mountCanvas,V7 as isBareSpecimen,KJ as CanvasErrorBoundary};
@@ -85,6 +85,7 @@ import { createPhotoStore, PHOTO_EDIT_MAX_BYTES } from './photo-store.ts';
85
85
  import { probeReadiness } from './readiness.ts';
86
86
  import { getRuntimeBundle, packageForSlug } from './runtime-bundle.ts';
87
87
  import { linkHub } from './sync/hub-link.ts';
88
+ import { signInToWorkspace, workspaceDisclosure } from './sync/workspace-signin.ts';
88
89
  import { readUiPrefs, type UiPrefs, writeUiPrefs } from './ui-prefs.ts';
89
90
  import { loadWhatsNew } from './whats-new.ts';
90
91
  import { isLoopbackHost } from './ws.ts';
@@ -1759,6 +1760,50 @@ export function createHttp(
1759
1760
  return gitJson(await linkHub(body));
1760
1761
  },
1761
1762
 
1763
+ // Cloud Phase 3 Task 3 — "Sign in to workspace". The person-facing
1764
+ // counterpart to /_api/hub/link: an address plus an email and password,
1765
+ // rather than a token to paste. Same gates as the link route (MAIN ORIGIN
1766
+ // only, loopback, POST CSRF) for the same reason — this handler receives a
1767
+ // PASSWORD, so the untrusted canvas origin must never be able to reach it.
1768
+ '/_api/workspace/sign-in': async (req: Request) => {
1769
+ if (req.method !== 'POST') return new Response('Method not allowed', { status: 405 });
1770
+ if (!sameOriginWrite(req))
1771
+ return new Response('cross-origin write rejected', { status: 403 });
1772
+ if (!isLoopbackHost(req.headers.get('host')))
1773
+ return new Response('local request required', { status: 403 });
1774
+ const body = await readJson<unknown>(req, 8 * 1024);
1775
+ const result = await signInToWorkspace((body ?? {}) as Record<string, unknown>);
1776
+ return Response.json(result.json, {
1777
+ status: result.status,
1778
+ headers: { 'Cache-Control': 'no-store' },
1779
+ });
1780
+ },
1781
+
1782
+ // The DDR-054 trust model in plain words, for the panel that replaces
1783
+ // DDR-079's terminal banner (DDR-192 §6). Read-only and main-origin — the
1784
+ // operator name is not secret, but this is UI chrome the canvas has no use
1785
+ // for, and every route the canvas can reach is one more thing to reason about.
1786
+ '/_api/workspace/disclosure': async (req: Request) => {
1787
+ if (req.method !== 'GET') return new Response('Method not allowed', { status: 405 });
1788
+ if (!isLoopbackHost(req.headers.get('host')))
1789
+ return new Response('local request required', { status: 403 });
1790
+ const url = new URL(req.url);
1791
+ const linked = ctx.cfg.linkedHub?.url ?? null;
1792
+ const operator =
1793
+ url.searchParams.get('operator') || (linked ? new URL(linked).host : 'your team');
1794
+ return Response.json(
1795
+ {
1796
+ operator,
1797
+ workspace: linked,
1798
+ items: workspaceDisclosure({
1799
+ operator,
1800
+ aiAvailable: url.searchParams.get('ai') !== '0',
1801
+ }),
1802
+ },
1803
+ { headers: { 'Cache-Control': 'no-store' } }
1804
+ );
1805
+ },
1806
+
1762
1807
  '/_api/edit-css': async (req: Request) => {
1763
1808
  // Phase 12 (DDR-103) — single-property inline CSS edit. POST body
1764
1809
  // { canvas, id, property, value } → writes one key into the element's
@@ -34,6 +34,12 @@ import { createHttp } from './http.ts';
34
34
  import { createInspect } from './inspect.ts';
35
35
  import { startHeapWatch } from './mem.ts';
36
36
  import { createSyncRuntime } from './sync/index.ts';
37
+ import {
38
+ assertContainment,
39
+ isForbiddenRoute,
40
+ isWorkspaceMode,
41
+ pruneForWorkspace,
42
+ } from './workspace-mode.ts';
37
43
  import { createWs, isLoopbackHost, isSameOriginWs, parseCollabSlug, type WsData } from './ws.ts';
38
44
 
39
45
  // Phase 19 / DDR-044 — covers the marketplace-cache-install gap where
@@ -141,16 +147,73 @@ type BunServer = ReturnType<typeof Bun.serve<WsData, never>>;
141
147
  // transient-buffer tradeoff on the buffering routes, noted in DDR-148).
142
148
  const MAX_REQUEST_BODY = ASSET_MAX_VIDEO_BYTES + 8 * 1024 * 1024;
143
149
 
150
+ // Containment invariant (DDR-193 §2) — the boot-assert. No-op outside workspace
151
+ // mode; in a cell it refuses to start when a rendering / evaluating / exporting
152
+ // surface is reachable, naming exactly which one. See workspace-mode.ts for why
153
+ // this is a process that will not start rather than a convention.
154
+ //
155
+ // Checked against the ACTUAL route table (`http.routes` keys plus the paths the
156
+ // `fetch` fall-through owns), not a hand-maintained list, so a future route can
157
+ // only escape it by being invisible to both.
158
+ const WORKSPACE_FETCH_ROUTES = ['/_ws/acp', '/_canvas-shell.html', '/_canvas-runtime/'];
159
+ const WORKSPACE = isWorkspaceMode();
160
+ // PRUNE first, then assert over what survived — so the assert is a
161
+ // post-condition on the pruning rather than a second, driftable opinion. A
162
+ // prefix added to the vocabulary then both prunes and is verified, together.
163
+ const pruned = WORKSPACE ? pruneForWorkspace(http.routes) : { routes: http.routes, removed: [] };
164
+ const SERVER_ROUTES = pruned.routes as typeof http.routes;
165
+ if (WORKSPACE && pruned.removed.length > 0) {
166
+ console.log(
167
+ `[studio] workspace mode — withheld ${pruned.removed.length} route(s) that would evaluate ` +
168
+ `tenant content: ${pruned.removed.join(', ')}`
169
+ );
170
+ }
171
+ try {
172
+ assertContainment([...Object.keys(SERVER_ROUTES), ...(WORKSPACE ? [] : WORKSPACE_FETCH_ROUTES)], {
173
+ // Presence of the dependency is the signal: a cell image that ships
174
+ // Playwright is one import() away from rendering tenant content. Skippable
175
+ // in a dev checkout, where Playwright is a legitimate devDependency of the
176
+ // E2E harness and would otherwise make workspace mode untestable locally.
177
+ // A BUILT cell image has no such escape — scripts/check-containment.sh
178
+ // enforces the runtime-dependency half at build time.
179
+ resolveModule:
180
+ process.env.MAUDE_WORKSPACE_ALLOW_DEV_MODULES === '1'
181
+ ? undefined
182
+ : (specifier) => {
183
+ try {
184
+ return !!import.meta.resolveSync?.(specifier);
185
+ } catch {
186
+ return false;
187
+ }
188
+ },
189
+ });
190
+ } catch (err) {
191
+ console.error(`\n${(err as Error).message}\n`);
192
+ process.exit(1);
193
+ }
194
+ if (isWorkspaceMode()) {
195
+ console.log('[studio] workspace mode — sync + git + assets only (DDR-193 containment invariant)');
196
+ }
197
+
144
198
  function startServer(port: number): BunServer {
145
199
  return Bun.serve<WsData, never>({
146
200
  port,
147
201
  hostname: '127.0.0.1',
148
202
  development: process.env.NODE_ENV !== 'production',
149
203
  maxRequestBodySize: MAX_REQUEST_BODY,
150
- routes: http.routes,
204
+ routes: SERVER_ROUTES,
151
205
  async fetch(req, srv) {
152
206
  const pathname = new URL(req.url).pathname;
153
207
 
208
+ // Containment (DDR-193 §2) — the `fetch` fall-through owns paths that are
209
+ // not in the route table (`/_ws/acp`, `/_canvas-shell.html`,
210
+ // `/_canvas-runtime/*`), so pruning the table alone would leave them
211
+ // reachable. 404, not 403: a cell should look like it never had the
212
+ // feature, rather than like it is refusing one.
213
+ if (WORKSPACE && isForbiddenRoute(pathname)) {
214
+ return new Response('not found', { status: 404 });
215
+ }
216
+
154
217
  // Phase 8 — collab WS, binary y-websocket protocol. Loopback-only;
155
218
  // DDR-047 makes cross-machine collab a Phase 9 hub-deploy story, not
156
219
  // a `--bind 0.0.0.0` flag on this server.
@@ -167,6 +230,8 @@ function startServer(port: number): BunServer {
167
230
  remote: req.headers.get('x-forwarded-for') ?? '127.0.0.1',
168
231
  kind: 'collab',
169
232
  slug: collabSlug,
233
+ // Privileged shell origin — ungated (see collab/origins.ts).
234
+ realm: 'main',
170
235
  },
171
236
  });
172
237
  if (ok) return undefined as unknown as Response;
@@ -275,6 +340,10 @@ function startCanvasServer(port: number): BunServer {
275
340
  remote: req.headers.get('x-forwarded-for') ?? '127.0.0.1',
276
341
  kind: 'collab',
277
342
  slug: collabSlug,
343
+ // UNTRUSTED canvas iframe origin (DDR-063 split). Every sync frame
344
+ // from here goes through the origin gate and may never write a
345
+ // body lane — DDR-122 follow-up, collab/origins.ts.
346
+ realm: 'canvas',
278
347
  },
279
348
  });
280
349
  if (ok) return undefined as unknown as Response;
@@ -377,7 +446,11 @@ ctx.mainOrigin = `http://localhost:${server.port} http://127.0.0.1:${server.port
377
446
  const CANVAS_ORIGIN_SPLIT = !/^(0|false|off|no)$/i.test(
378
447
  process.env.MAUDE_CANVAS_ORIGIN_SPLIT ?? ''
379
448
  );
380
- const canvasServer = CANVAS_ORIGIN_SPLIT ? startCanvasServer(0) : null;
449
+ // The canvas origin exists to SERVE AND RENDER canvases (DDR-063). A workspace
450
+ // cell has no business starting it — that second origin is the surface the
451
+ // containment invariant is about. Not started here rather than started-and-
452
+ // pruned: there would be nothing left to serve.
453
+ const canvasServer = CANVAS_ORIGIN_SPLIT && !WORKSPACE ? startCanvasServer(0) : null;
381
454
  const canvasOrigin = canvasServer ? `http://localhost:${canvasServer.port}` : undefined;
382
455
  if (canvasOrigin) ctx.canvasOrigin = canvasOrigin;
383
456