import{r as c,u as W,j as e}from"./index-CgQG7qql.js";import{u as be}from"./use-resilient-parse-Xt8SaEA4.js";import{b as ye}from"./index-C81iO5At.js";import le from"./manifest-AZFh6VhQ.js";const ve=`
  var editActive = false;
  var editDirty = false;
  var editOriginalText = '';
  var editFocusedTag = '';
  var editChanges = [];

  window.addEventListener('message', function(e) {
    if (!e.data || e.data.type !== 'pneuma:editMode') return;
    editActive = !!e.data.enabled;
    toggleEditable(editActive);
    if (!editActive) {
      if (editDirty) { sendEditedContent(); editDirty = false; }
      editChanges = [];
    }
  });

  function toggleEditable(enable) {
    var tags = 'h1,h2,h3,h4,h5,h6,p,li,td,th,span,a,blockquote,figcaption,label,dt,dd';
    var els = document.querySelectorAll(tags);
    for (var i = 0; i < els.length; i++) {
      els[i].contentEditable = enable ? 'true' : 'false';
      els[i].style.cursor = enable ? 'text' : '';
    }
    if (enable) document.addEventListener('click', preventEditNav, true);
    else document.removeEventListener('click', preventEditNav, true);
  }

  function preventEditNav(e) {
    if (e.target.closest && e.target.closest('a')) e.preventDefault();
  }

  document.addEventListener('focus', function(e) {
    if (!editActive) return;
    var el = e.target;
    if (el && el.contentEditable === 'true') {
      editOriginalText = (el.textContent || '').trim();
      editFocusedTag = el.tagName ? el.tagName.toLowerCase() : '';
    }
  }, true);

  document.addEventListener('input', function() { if (editActive) editDirty = true; });

  document.addEventListener('blur', function(e) {
    if (!editActive) return;
    var el = e.target;
    if (el && el.contentEditable === 'true') {
      var newText = (el.textContent || '').trim();
      if (editOriginalText !== newText) {
        editChanges.push({ tag: editFocusedTag, before: editOriginalText, after: newText });
        editDirty = true;
      }
      if (editDirty) { sendEditedContent(); editDirty = false; }
    }
  }, true);

  function serializeCleanBody() {
    var clone = document.body.cloneNode(true);
    var scripts = clone.querySelectorAll('script');
    for (var i = scripts.length - 1; i >= 0; i--) scripts[i].parentNode.removeChild(scripts[i]);
    var eds = clone.querySelectorAll('[contenteditable]');
    for (var i = 0; i < eds.length; i++) eds[i].removeAttribute('contenteditable');
    var styled = clone.querySelectorAll('[style]');
    for (var i = 0; i < styled.length; i++) {
      var s = styled[i].style;
      s.outline = ''; s.outlineOffset = ''; s.borderRadius = ''; s.cursor = '';
      if (!styled[i].getAttribute('style').trim()) styled[i].removeAttribute('style');
    }
    return clone.innerHTML.trim();
  }

  function sendEditedContent() {
    var changes = editChanges.slice();
    editChanges = [];
    window.parent.postMessage({ type: 'pneuma:textEdit', html: serializeCleanBody(), changes: changes }, '*');
  }
`,je=ye({extensions:[ve]}),x={width:14,height:14,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:1.5,strokeLinecap:"round",strokeLinejoin:"round"},p={maximize:e.jsx("svg",{...x,children:e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"})}),smartphone:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"M12 18h.01"})]}),tablet:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"2"}),e.jsx("path",{d:"M12 18h.01"})]}),monitor:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2"}),e.jsx("path",{d:"M8 21h8M12 17v4"})]}),settings:e.jsxs("svg",{...x,children:[e.jsx("circle",{cx:"12",cy:"12",r:"3"}),e.jsx("path",{d:"M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"})]}),search:e.jsxs("svg",{...x,children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"M21 21l-4.35-4.35"})]}),sparkles:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M12 3l1.5 4.5L18 9l-4.5 1.5L12 15l-1.5-4.5L6 9l4.5-1.5L12 3z"}),e.jsx("path",{d:"M19 13l.75 2.25L22 16l-2.25.75L19 19l-.75-2.25L16 16l2.25-.75L19 13z"})]}),zap:e.jsx("svg",{...x,children:e.jsx("path",{d:"M13 2L3 14h9l-1 8 10-12h-9l1-8z"})}),palette:e.jsxs("svg",{...x,children:[e.jsx("circle",{cx:"13.5",cy:"6.5",r:"1.5"}),e.jsx("circle",{cx:"17.5",cy:"10.5",r:"1.5"}),e.jsx("circle",{cx:"8.5",cy:"7.5",r:"1.5"}),e.jsx("circle",{cx:"6.5",cy:"12",r:"1.5"}),e.jsx("path",{d:"M12 2a10 10 0 0 0-1.16 19.93c.8.1 1.16-.36 1.16-.8v-1.48c0-.83-.67-1.5-1.5-1.5a3 3 0 0 1-3-3c0-1.66 1.34-3 3-3h5a5 5 0 0 0 0-10H12z"})]}),building:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"4",y:"2",width:"16",height:"20",rx:"1"}),e.jsx("path",{d:"M9 22V12h6v10"}),e.jsx("path",{d:"M8 6h.01M16 6h.01M12 6h.01M8 10h.01M16 10h.01M12 10h.01"})]}),graduationCap:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M22 10v6M2 10l10-5 10 5-10 5z"}),e.jsx("path",{d:"M6 12v5c0 1.1 2.7 3 6 3s6-1.9 6-3v-5"})]}),clipboardCheck:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"8",y:"2",width:"8",height:"4",rx:"1"}),e.jsx("path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"}),e.jsx("path",{d:"M9 14l2 2 4-4"})]}),messageCircle:e.jsx("svg",{...x,children:e.jsx("path",{d:"M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"})}),ruler:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.32 4.36a.5.5 0 0 0 .62.62l4.36-1.32a2 2 0 0 0 .83-.5z"}),e.jsx("path",{d:"M15 5l4 4"}),e.jsx("path",{d:"M13.5 6.5l1 1M10.5 9.5l1 1M7.5 12.5l1 1"})]}),gem:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M6 3h12l4 6-10 13L2 9z"}),e.jsx("path",{d:"M11 3l1 10M2 9h20M7.5 3L6 9l6 13M16.5 3L18 9l-6 13"})]}),flask:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M9 3h6M10 9V3M14 9V3"}),e.jsx("path",{d:"M5.5 21h13c.83 0 1.5-.67 1.5-1.5 0-.2-.04-.39-.11-.57L15 9H9l-4.89 9.93A1.5 1.5 0 0 0 5.5 21z"})]}),lightbulb:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M9 18h6M10 22h4"}),e.jsx("path",{d:"M15.09 14c.18-.98.65-1.74 1.41-2.5A4.65 4.65 0 0 0 18 8 6 6 0 0 0 6 8c0 1 .23 2.23 1.5 3.5A4.61 4.61 0 0 1 8.91 14"})]}),gauge:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M12 16v-4"}),e.jsx("path",{d:"M12 8h.01"}),e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M14.31 8l1.5-1.5"})]}),shield:e.jsx("svg",{...x,children:e.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})}),play:e.jsxs("svg",{...x,children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("polygon",{points:"10,8 16,12 10,16"})]}),droplets:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M7 16.3c2.2 0 4-1.83 4-4.05 0-1.16-.57-2.26-1.71-3.19S7.29 6.75 7 5.3c-.29 1.45-1.14 2.84-2.29 3.76S3 11.1 3 12.25c0 2.22 1.8 4.05 4 4.05z"}),e.jsx("path",{d:"M12.56 14.65c1.35 0 2.44-1.12 2.44-2.48 0-.71-.35-1.38-1.05-1.95S12.78 9 12.56 8.25c-.17.89-.7 1.73-1.4 2.3s-1.05 1.23-1.05 1.95c0 1.36 1.1 2.48 2.44 2.48z"})]}),flame:e.jsx("svg",{...x,children:e.jsx("path",{d:"M8.5 14.5A2.5 2.5 0 0 0 11 12c0-1.38-.5-2-1-3-1.072-2.143-.224-4.054 2-6 .5 2.5 2 4.9 4 6.5 2 1.6 3 3.5 3 5.5a7 7 0 1 1-14 0c0-1.153.433-2.294 1-3a2.5 2.5 0 0 0 2.5 2.5z"})}),leaf:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M11 20A7 7 0 0 1 9.8 6.9C15.5 4.9 17 3.5 19 2c1 2 2 4.5 2 8 0 5.5-4.78 10-10 10z"}),e.jsx("path",{d:"M2 21c0-3 1.85-5.36 5.08-6C9.5 14.52 12 13 13 12"})]}),heart:e.jsx("svg",{...x,children:e.jsx("path",{d:"M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7z"})}),package:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M16.5 9.4l-9-5.19M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"}),e.jsx("polyline",{points:"3.27,6.96 12,12.01 20.73,6.96"}),e.jsx("line",{x1:"12",y1:"22.08",x2:"12",y2:"12"})]}),layoutGrid:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"3",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"3",width:"7",height:"7"}),e.jsx("rect",{x:"3",y:"14",width:"7",height:"7"}),e.jsx("rect",{x:"14",y:"14",width:"7",height:"7"})]}),userPlus:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e.jsx("circle",{cx:"9",cy:"7",r:"4"}),e.jsx("path",{d:"M19 8v6M22 11h-6"})]}),type:e.jsxs("svg",{...x,children:[e.jsx("polyline",{points:"4,7 4,4 20,4 20,7"}),e.jsx("line",{x1:"9.5",y1:"20",x2:"14.5",y2:"20"}),e.jsx("line",{x1:"12",y1:"4",x2:"12",y2:"20"})]}),columns:e.jsxs("svg",{...x,children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("path",{d:"M9 3v18M15 3v18"})]}),bolt:e.jsxs("svg",{...x,children:[e.jsx("path",{d:"M13 2L3 14h9l-1 8 10-12h-9l1-8z"}),e.jsx("circle",{cx:"12",cy:"12",r:"10",fill:"none"})]})},Z=[{id:"full",label:"Full",icon:p.maximize,width:0,height:0},{id:"mobile",label:"Mobile",icon:p.smartphone,width:375,height:812},{id:"tablet",label:"Tablet",icon:p.tablet,width:768,height:1024},{id:"desktop",label:"Desktop",icon:p.monitor,width:1280,height:800}],we={"teach-impeccable":p.graduationCap,audit:p.clipboardCheck,critique:p.messageCircle,normalize:p.ruler,polish:p.gem,distill:p.flask,clarify:p.lightbulb,typeset:p.type,arrange:p.columns,optimize:p.gauge,harden:p.shield,animate:p.play,colorize:p.droplets,bolder:p.flame,quieter:p.leaf,delight:p.heart,overdrive:p.bolt,extract:p.package,adapt:p.layoutGrid,onboard:p.userPlus},Me=[{name:"Setup",icon:p.settings,actionIds:["teach-impeccable"]},{name:"Review",icon:p.search,actionIds:["audit","critique"]},{name:"Refine",icon:p.sparkles,actionIds:["normalize","polish","distill","clarify","typeset","arrange"]},{name:"Performance",icon:p.zap,actionIds:["optimize","harden"]},{name:"Style",icon:p.palette,actionIds:["animate","colorize","bolder","quieter","delight","overdrive"]},{name:"Architecture",icon:p.building,actionIds:["extract","adapt","onboard"]}];function Ce(i){const d=new Map(i.map(r=>[r.id,r]));return Me.map(r=>({name:r.name,icon:r.icon,commands:r.actionIds.filter(h=>d.has(h)).map(h=>{const a=d.get(h);return{id:a.id,label:a.label,icon:we[a.id]??p.sparkles,description:a.description??""}})})).filter(r=>r.commands.length>0)}function ke({collapsed:i}){const[d,r]=c.useState(!1),h={padding:i?"8px 4px":"8px 12px",borderTop:"1px solid rgba(255,255,255,0.08)",display:"flex",alignItems:"center",justifyContent:i?"center":"flex-start",gap:"6px",position:"relative"},a={fontSize:"10px",color:"rgba(255,255,255,0.35)",textDecoration:"none",transition:"color 0.15s",lineHeight:1.3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},u={background:"none",border:"1px solid rgba(255,255,255,0.15)",borderRadius:"50%",width:"15px",height:"15px",fontSize:"9px",color:"rgba(255,255,255,0.35)",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0,padding:0,lineHeight:1,transition:"border-color 0.15s, color 0.15s"},m={position:"absolute",bottom:"100%",left:i?"-4px":"8px",marginBottom:"6px",width:"260px",padding:"10px 12px",background:"#141414",border:"1px solid rgba(255,255,255,0.12)",borderRadius:"6px",fontSize:"11px",lineHeight:1.55,color:"rgba(255,255,255,0.7)",boxShadow:"0 8px 30px rgba(0,0,0,0.7)",zIndex:9999};return e.jsxs("div",{style:h,children:[e.jsx("a",{href:"https://impeccable.style",target:"_blank",rel:"noopener noreferrer",style:a,title:"impeccable.style",onMouseEnter:f=>{f.currentTarget.style.color="rgba(255,255,255,0.6)"},onMouseLeave:f=>{f.currentTarget.style.color="rgba(255,255,255,0.35)"},children:i?e.jsx("span",{style:{fontSize:"12px"},children:"*"}):"impeccable.style"}),e.jsx("button",{style:u,onClick:()=>r(!d),onBlur:()=>r(!1),onMouseEnter:f=>{f.currentTarget.style.borderColor="rgba(255,255,255,0.3)",f.currentTarget.style.color="rgba(255,255,255,0.6)"},onMouseLeave:f=>{f.currentTarget.style.borderColor="rgba(255,255,255,0.15)",f.currentTarget.style.color="rgba(255,255,255,0.35)"},title:"About design intelligence",children:"?"}),d&&e.jsxs("div",{style:m,children:[e.jsx("div",{style:{fontWeight:600,marginBottom:"6px",color:"rgba(255,255,255,0.85)"},children:"Powered by Impeccable"}),e.jsxs("p",{style:{margin:"0 0 8px"},children:["Design principles and commands are adapted from"," ",e.jsx("a",{href:"https://impeccable.style",target:"_blank",rel:"noopener noreferrer",style:{color:"#f97316",textDecoration:"none"},children:"impeccable.style"})," ","by Paul Bakaus."]}),e.jsx("p",{style:{margin:0,color:"rgba(255,255,255,0.5)",fontSize:"10px"},children:"Pneuma integrates Impeccable's skill content directly into the mode rather than installing it as a standalone skill. This allows the design commands to work with the live preview viewer architecture (toolbar buttons, agent notifications, context extraction) which requires tighter integration than a drop-in skill install provides."})]})]})}const Se=`<script>
document.addEventListener('click',function(e){
  var a=e.target.closest('a[href^="#"]');
  if(!a)return;
  var hash=a.getAttribute('href');
  if(!hash||hash.length<2)return;
  e.preventDefault();
  var target=document.querySelector(hash)||document.getElementById(hash.slice(1));
  if(target)target.scrollIntoView({behavior:'smooth'});
});
<\/script>`;function $e(i,d){const r=/<!DOCTYPE|<html/i.test(i),h=Se+je;if(r){let a=i;const u=`<base href="${d}">`;return/<head[^>]*>/i.test(a)?a=a.replace(/<head([^>]*)>/i,`<head$1>${u}`):/<html[^>]*>/i.test(a)&&(a=a.replace(/<html([^>]*)>/i,`<html$1><head>${u}</head>`)),/<\/body>/i.test(a)?a=a.replace(/<\/body>/i,`${h}</body>`):a+=h,a}return`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <base href="${d}">
</head>
<body>
${i}
${h}
</body>
</html>`}function Ee({pages:i,activePage:d,onPageChange:r,baseHref:h}){const[a,u]=c.useState(null),[m,f]=c.useState({x:0,y:0}),o=(n,g)=>{const v=g.currentTarget.getBoundingClientRect();u(n),f({x:v.left+v.width/2,y:v.top})};return e.jsxs("div",{style:{borderTop:"1px solid rgba(255,255,255,0.08)",background:"rgba(0,0,0,0.3)",display:"flex",overflowX:"auto",padding:"0 8px",flexShrink:0,position:"relative"},children:[i.map(n=>e.jsx("button",{onClick:()=>r(n.file),onMouseEnter:g=>o(n.file,g),onMouseLeave:()=>u(null),style:{padding:"6px 14px",fontSize:"12px",color:n.file===d?"rgba(255,255,255,0.9)":"rgba(255,255,255,0.5)",background:"none",border:"none",borderBottomWidth:"2px",borderBottomStyle:"solid",borderBottomColor:n.file===d?"#f97316":"transparent",cursor:"pointer",whiteSpace:"nowrap",transition:"color 0.15s"},title:n.file,children:n.title},n.file)),a&&a!==d&&e.jsx("div",{style:{position:"fixed",left:m.x-120,top:m.y-160,width:240,height:150,background:"#1a1a1a",border:"1px solid rgba(255,255,255,0.15)",borderRadius:"6px",overflow:"hidden",boxShadow:"0 8px 24px rgba(0,0,0,0.6)",zIndex:9999,pointerEvents:"none"},children:e.jsx("iframe",{src:`${h}${a}`,style:{width:"1280px",height:"800px",border:"none",transform:"scale(0.1875)",transformOrigin:"top left",pointerEvents:"none"},sandbox:"allow-same-origin",title:"Page preview",tabIndex:-1})})]})}function Te(){return e.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{width:"14px",height:"14px"},children:[e.jsx("path",{d:"M1 8s2.5-5 7-5 7 5 7 5-2.5 5-7 5-7-5-7-5z"}),e.jsx("circle",{cx:"8",cy:"8",r:"2"})]})}function Le(){return e.jsx("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{width:"14px",height:"14px"},children:e.jsx("path",{d:"M3 2l4 12 2-5 5-2L3 2z",strokeLinejoin:"round"})})}function ze(){return e.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{width:"14px",height:"14px"},children:[e.jsx("path",{d:"M11.5 2.5l2 2-8 8L3 13.5l1-2.5z",strokeLinejoin:"round"}),e.jsx("path",{d:"M9.5 4.5l2 2"})]})}function Ie(){return e.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{width:"14px",height:"14px"},children:[e.jsx("path",{d:"M12 3l1.5 1.5L5 13l-2 .5.5-2z",strokeLinejoin:"round"}),e.jsx("path",{d:"M2 15h5",strokeLinecap:"round",strokeDasharray:"2 1.5"})]})}function Ae(){return e.jsxs("svg",{viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{width:"14px",height:"14px"},children:[e.jsx("path",{d:"M8 2v8M5 7l3 3 3-3",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M2 11v2a1 1 0 001 1h10a1 1 0 001-1v-2"})]})}const Re=[{value:"view",label:"View",icon:e.jsx(Te,{}),title:"Read-only view"},{value:"edit",label:"Edit",icon:e.jsx(ze,{}),title:"Edit text directly in preview"},{value:"select",label:"Select",icon:e.jsx(Le,{}),title:"Select elements (Esc to exit)"},{value:"annotate",label:"Annotate",icon:e.jsx(Ie,{}),title:"Annotate multiple elements (Esc to exit)"}];function Pe({activePreset:i,onPresetChange:d,previewMode:r,onSetPreviewMode:h,onExport:a,readonly:u}){const m=Z.find(o=>o.id===i),f=m&&m.width>0;return e.jsxs("div",{style:{padding:"4px 12px",borderBottom:"1px solid rgba(255,255,255,0.08)",background:"rgba(0,0,0,0.2)",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"4px",flexShrink:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px"},children:[e.jsx("span",{style:{fontSize:"11px",color:"rgba(255,255,255,0.4)",marginRight:"4px"},children:"Viewport:"}),Z.map(o=>e.jsxs("button",{onClick:()=>d(o.id),style:{background:o.id===i?"rgba(249,115,22,0.15)":"none",border:o.id===i?"1px solid rgba(249,115,22,0.4)":"1px solid transparent",borderRadius:"4px",padding:"3px 8px",cursor:"pointer",color:o.id===i?"#f97316":"rgba(255,255,255,0.5)",fontSize:"11px",display:"flex",alignItems:"center",gap:"4px",transition:"all 0.15s"},title:o.width>0?`${o.label} (${o.width}x${o.height})`:o.label,onMouseEnter:n=>{o.id!==i&&(n.currentTarget.style.color="rgba(255,255,255,0.8)",n.currentTarget.style.background="rgba(255,255,255,0.06)")},onMouseLeave:n=>{o.id!==i&&(n.currentTarget.style.color="rgba(255,255,255,0.5)",n.currentTarget.style.background="none")},children:[e.jsx("span",{style:{display:"flex",alignItems:"center"},children:o.icon}),e.jsx("span",{children:o.label})]},o.id)),f&&e.jsxs("span",{style:{fontSize:"10px",color:"rgba(255,255,255,0.3)",marginLeft:"8px"},children:[m.width," x ",m.height]})]}),!u&&e.jsx("div",{style:{display:"flex",alignItems:"center",gap:"1px",background:"rgba(0,0,0,0.3)",borderRadius:"6px",padding:"2px"},children:Re.map(o=>e.jsxs("button",{onClick:()=>h(o.value),style:{display:"flex",alignItems:"center",gap:"4px",padding:"3px 8px",borderRadius:"4px",border:"none",cursor:"pointer",fontSize:"11px",transition:"all 0.15s",background:r===o.value?"rgba(249,115,22,0.2)":"transparent",color:r===o.value?"#f97316":"rgba(255,255,255,0.5)"},title:o.title,onMouseEnter:n=>{r!==o.value&&(n.currentTarget.style.color="rgba(255,255,255,0.8)")},onMouseLeave:n=>{r!==o.value&&(n.currentTarget.style.color="rgba(255,255,255,0.5)")},children:[o.icon,e.jsx("span",{children:o.label})]},o.value))}),e.jsx("button",{onClick:a,title:"Export & Download",style:{display:"flex",alignItems:"center",gap:"4px",padding:"3px 8px",borderRadius:"4px",border:"none",cursor:"pointer",fontSize:"11px",transition:"all 0.15s",background:"transparent",color:"rgba(255,255,255,0.5)"},onMouseEnter:o=>{o.currentTarget.style.color="rgba(255,255,255,0.8)",o.currentTarget.style.background="rgba(255,255,255,0.06)"},onMouseLeave:o=>{o.currentTarget.style.color="rgba(255,255,255,0.5)",o.currentTarget.style.background="transparent"},children:e.jsx(Ae,{})})]})}function Ne({style:i,label:d,thumbnail:r,onConfirm:h,onCancel:a}){const[u,m]=c.useState(""),f=c.useRef(null);c.useEffect(()=>{const n=setTimeout(()=>f.current?.focus(),50);return()=>clearTimeout(n)},[]);const o=n=>{n.key==="Enter"?(n.preventDefault(),h(u)):n.key==="Escape"&&(n.preventDefault(),n.stopPropagation(),a())};return e.jsxs("div",{style:i,className:"bg-neutral-800 border border-neutral-600 rounded-lg shadow-xl p-3 text-sm",onClick:n=>n.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2 min-w-0",children:[r&&e.jsx("img",{src:r,alt:"",className:"w-8 h-8 rounded border border-neutral-600 shrink-0 object-contain bg-white"}),e.jsx("span",{className:"text-neutral-300 truncate text-xs",children:d||"Element"})]}),e.jsx("input",{ref:f,type:"text",value:u,onChange:n=>m(n.target.value),onKeyDown:o,placeholder:"Add comment (optional)...",className:"w-full bg-neutral-900 border border-neutral-600 rounded px-2 py-1.5 text-sm text-white placeholder-neutral-500 outline-none focus:border-blue-500"}),e.jsxs("div",{className:"flex justify-end gap-2 mt-2",children:[e.jsx("button",{onClick:a,className:"px-2.5 py-1 text-xs text-neutral-400 hover:text-white rounded hover:bg-neutral-700 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:()=>h(u),className:"px-2.5 py-1 text-xs text-white bg-blue-600 hover:bg-blue-500 rounded transition-colors",children:"Add"})]})]})}function De({files:i,selection:d,onSelect:r,mode:h,contentVersion:a,imageVersion:u,activeFile:m,onActiveFileChange:f,onNotifyAgent:o,navigateRequest:n,onNavigateComplete:g,commands:v,readonly:z}){const b=z?"view":h,I=z?(()=>{}):r,T=z?void 0:o,L=c.useRef(null),J=c.useRef(null),[H,ce]=c.useState(""),[Y,de]=c.useState(null),[j,he]=c.useState(!1),ee=c.useMemo(()=>Ce(v??[]),[v]),[V,pe]=c.useState("full"),P=W(t=>t.activeContentSet),X=W(t=>t.setPreviewMode),te=W(t=>t.addAnnotation);W(t=>t.annotations);const[$,N]=c.useState(null),G=be(i,t=>{const s=t.find(y=>y.path==="manifest.json"||y.path.endsWith("/manifest.json"));if(!s)return{data:null};const l=JSON.parse(s.content),w=l.pages||l.files;return!Array.isArray(w)||w.length===0?{data:null}:{data:w.map(y=>({file:y.file||y.path||"",title:y.title||(y.file||y.path||"").replace(/\.html$/i,"").replace(/^.*\//,"")})),file:s.path}},T),F=c.useMemo(()=>G||i.filter(t=>/\.html$/i.test(t.path)).map(t=>({file:t.path,title:t.path.replace(/\.html$/i,"").replace(/^.*\//,"")})),[G,i]),D=c.useMemo(()=>F.map(t=>t.file),[F]),S=c.useMemo(()=>m&&D.includes(m)?m:H&&D.includes(H)?H:D.find(t=>/^index\.html$/i.test(t))||D[0]||"",[m,H,D]),K=c.useMemo(()=>P?`/content/${P}/`:"/content/",[P]),O=c.useMemo(()=>{if(!S)return"";const t=i.find(s=>s.path===S);return t?$e(t.content,K):""},[S,i,K]),ne=c.useRef("");c.useEffect(()=>{!L.current||!O||ne.current!==O&&(ne.current=O,L.current.srcdoc=O)},[O]);const _=b==="select"||b==="annotate",q=b==="edit";c.useEffect(()=>{const t=L.current;if(t?.contentWindow)try{t.contentWindow.postMessage({type:"pneuma:selectMode",enabled:_},"*")}catch{}},[_]),c.useEffect(()=>{const t=L.current;if(t?.contentWindow)try{t.contentWindow.postMessage({type:"pneuma:editMode",enabled:q},"*")}catch{}},[q]);const ie=c.useCallback(()=>{const t=L.current;if(t?.contentWindow)try{t.contentWindow.postMessage({type:"pneuma:selectMode",enabled:_},"*"),t.contentWindow.postMessage({type:"pneuma:editMode",enabled:q},"*")}catch{}},[_,q]),se=c.useRef([]),re=c.useRef(void 0),oe=c.useCallback((t,s,l)=>{l?.length&&se.current.push(...l),clearTimeout(re.current),re.current=setTimeout(()=>{const y=i.find(k=>k.path===t);if(!y)return;const M=y.content;let C;/<body[^>]*>/i.test(M)?C=M.replace(/(<body[^>]*>)([\s\S]*?)(<\/body>)/i,`$1
${s}
$3`):C=s;const A=P?`${P}/${t}`:t;fetch("/api/files",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:A,content:C})}).catch(()=>{});const R=se.current.splice(0).map(k=>`  <${k.tag}>: "${k.before}" → "${k.after}"`),E=R.length>0?`Edited text on "${t}":
${R.join(`
`)}`:`Edited text on "${t}"`;W.getState().pushUserAction({timestamp:Date.now(),actionId:"edit-text",description:E})},800)},[i,P]);c.useEffect(()=>{function t(s){if(s.data?.type==="pneuma:textEdit"){oe(S,s.data.html,s.data.changes);return}if(s.data?.type==="pneuma:select"){const l=s.data.selection;if(!l){b==="annotate"?N(null):I(null);return}if(b==="annotate"){if(!l.rect)return;N({selection:l,pageFile:S,rect:l.rect})}else I({type:l.type,content:l.content,level:l.level,file:S,tag:l.tag,classes:l.classes,selector:l.selector,thumbnail:l.thumbnail,label:l.label,nearbyText:l.nearbyText,accessibility:l.accessibility})}}return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[S,I,oe,b]);const xe=c.useCallback(t=>{if(!$)return;const{selection:s,pageFile:l}=$;te({id:`ann-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,slideFile:l,element:{file:l,type:s.type,content:s.content,level:s.level,tag:s.tag,classes:s.classes,selector:s.selector,thumbnail:s.thumbnail,label:s.label,nearbyText:s.nearbyText,accessibility:s.accessibility},comment:t}),N(null)},[$,te]);c.useEffect(()=>{N(null)},[S]),c.useEffect(()=>{function t(s){if(s.key==="Escape"){if($){N(null);return}(b==="select"||b==="annotate"||b==="edit")&&X("view")}}return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[b,X,$]);const ae=c.useCallback(t=>{ce(t),f?.(t),I(null)},[f,I]);c.useEffect(()=>{if(!n)return;const{data:t}=n;if(t.page||t.file){const s=t.page||t.file;D.includes(s)&&ae(s)}g?.()},[n]);const[Q,ue]=c.useState({width:0,height:0});c.useEffect(()=>{const t=J.current;if(!t)return;const s=new ResizeObserver(l=>{for(const w of l){const y=Math.round(w.contentRect.width),M=Math.round(w.contentRect.height);ue(C=>C.width===y&&C.height===M?C:{width:y,height:M})}});return s.observe(t),()=>s.disconnect()},[]);const B=c.useMemo(()=>{const t=Z.find(k=>k.id===V);if(!t||t.width===0)return{width:"100%",height:"100%",scale:1,useTransform:!1};const s=t.width,l=t.height,w=Q.width,y=Q.height;if(w===0||y===0)return{width:`${s}px`,height:`${l}px`,scale:1,useTransform:!1};const M=32,C=w-M*2,A=y-M*2,U=C/s,R=A/l,E=Math.min(U,R,1);return{width:`${s}px`,height:`${l}px`,scale:E,useTransform:!0}},[V,Q]),fe=c.useCallback(()=>{const s=W.getState().activeContentSet,l=s?`?contentSet=${encodeURIComponent(s)}`:"";window.open(`/export/webcraft${l}`,"_blank")},[]),ge=c.useCallback(t=>{if(!T)return;const l=ee.flatMap(w=>w.commands).find(w=>w.id===t);l&&T({type:"impeccable-command",message:`Please run the Impeccable "${l.id}" command on the current workspace. Follow the instructions in the cmd-${l.id} reference document.`,severity:"warning",summary:`/${l.id}`})},[T]),me=c.useCallback(t=>{de(s=>s===t?null:t)},[]);return e.jsxs("div",{style:{display:"flex",height:"100%",width:"100%",overflow:"hidden"},children:[!z&&e.jsxs("div",{style:{width:j?"36px":"180px",minWidth:j?"36px":"180px",height:"100%",borderRight:"1px solid rgba(255,255,255,0.08)",background:"rgba(0,0,0,0.3)",display:"flex",flexDirection:"column",overflow:"hidden",transition:"width 0.2s, min-width 0.2s"},children:[e.jsxs("div",{style:{padding:j?"8px 6px":"8px 12px",borderBottom:"1px solid rgba(255,255,255,0.08)",display:"flex",alignItems:"center",justifyContent:j?"center":"space-between",gap:"4px"},children:[!j&&e.jsx("span",{style:{fontSize:"11px",fontWeight:600,color:"rgba(255,255,255,0.5)",textTransform:"uppercase",letterSpacing:"0.05em"},children:"Impeccable"}),e.jsx("button",{onClick:()=>he(!j),style:{background:"none",border:"none",color:"rgba(255,255,255,0.4)",cursor:"pointer",padding:"2px",fontSize:"12px",lineHeight:1,display:"flex",alignItems:"center",justifyContent:"center"},title:j?"Expand command bar":"Collapse command bar",children:j?"▶":"◀"})]}),e.jsx("div",{style:{flex:1,overflowY:"auto",padding:j?"4px 2px":"4px 0"},children:ee.map(t=>e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>me(t.name),style:{width:"100%",background:"none",border:"none",padding:j?"6px 4px":"6px 12px",display:"flex",alignItems:"center",justifyContent:j?"center":"flex-start",gap:"6px",cursor:"pointer",color:Y===t.name?"rgba(255,255,255,0.9)":"rgba(255,255,255,0.5)",fontSize:"12px",fontWeight:500,transition:"color 0.15s"},title:t.name,children:[e.jsx("span",{style:{display:"flex",alignItems:"center"},children:t.icon}),!j&&e.jsx("span",{children:t.name}),!j&&e.jsx("span",{style:{marginLeft:"auto",fontSize:"9px",transform:Y===t.name?"rotate(90deg)":"none",transition:"transform 0.15s"},children:"▶"})]}),(Y===t.name||j)&&e.jsx("div",{style:{padding:j?"0":"0 0 4px 0"},children:t.commands.map(s=>e.jsxs("button",{onClick:()=>ge(s.id),style:{width:"100%",background:"none",border:"none",padding:j?"5px 4px":"4px 12px 4px 24px",display:"flex",alignItems:"center",justifyContent:j?"center":"flex-start",gap:"6px",cursor:"pointer",color:"rgba(255,255,255,0.65)",fontSize:"12px",transition:"background 0.1s, color 0.1s"},title:`${s.label}: ${s.description}`,onMouseEnter:l=>{l.currentTarget.style.background="rgba(255,255,255,0.06)",l.currentTarget.style.color="rgba(255,255,255,0.9)"},onMouseLeave:l=>{l.currentTarget.style.background="none",l.currentTarget.style.color="rgba(255,255,255,0.65)"},children:[e.jsx("span",{style:{display:"flex",alignItems:"center",justifyContent:"center",width:"16px"},children:s.icon}),!j&&e.jsx("span",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:s.label})]},s.id))})]},t.name))}),e.jsx(ke,{collapsed:j})]}),e.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",overflow:"hidden"},children:[e.jsx(Pe,{activePreset:V,onPresetChange:pe,previewMode:b,onSetPreviewMode:X,onExport:fe,readonly:z}),e.jsxs("div",{ref:J,style:{flex:1,position:"relative",background:V==="full"?"#ffffff":"#1a1a1a",overflow:"hidden",display:"flex",alignItems:"center",justifyContent:"center"},children:[S&&O?B.useTransform?e.jsx("div",{style:{width:B.width,height:B.height,transform:`scale(${B.scale})`,transformOrigin:"center center",borderRadius:"8px",overflow:"hidden",boxShadow:"0 4px 24px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.1)",flexShrink:0},children:e.jsx("iframe",{ref:L,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#ffffff"},sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",title:"Web Preview",onLoad:ie})}):e.jsx("iframe",{ref:L,style:{width:"100%",height:"100%",border:"none",display:"block",background:"#ffffff"},sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",title:"Web Preview",onLoad:ie}):e.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",width:"100%",color:"rgba(0,0,0,0.4)",fontSize:"14px",background:"#fafafa"},children:e.jsxs("div",{style:{textAlign:"center"},children:[e.jsx("div",{style:{fontSize:"32px",marginBottom:"12px",opacity:.5},children:"🌐"}),e.jsx("div",{children:"No HTML files in workspace"}),e.jsx("div",{style:{fontSize:"12px",marginTop:"4px",opacity:.6},children:"Create an HTML file to see a live preview"})]})}),$&&e.jsx(Ne,{style:(()=>{const{rect:t}=$,s=280,l=130,w=J.current,y=L.current;if(!w||!y)return{position:"absolute",top:100,left:100,width:s,zIndex:50};const M=w.getBoundingClientRect(),C=y.getBoundingClientRect(),A=B.useTransform?B.scale:1,U=C.left-M.left,R=C.top-M.top;let E=R+t.bottom*A+8;E+l>M.height&&(E=R+t.top*A-l-8),E=Math.max(8,E);let k=U+t.left*A;return k=Math.max(8,Math.min(k,M.width-s-8)),{position:"absolute",top:E,left:k,width:s,zIndex:50}})(),label:$.selection.label,thumbnail:$.selection.thumbnail,onConfirm:xe,onCancel:()=>N(null)})]}),F.length>=2&&e.jsx(Ee,{pages:F,activePage:S,onPageChange:ae,baseHref:K})]})]})}function Oe(i){const d=[],r=new Set;for(const h of i){const a=h.path.match(/^([^/]+)\/manifest\.json$/);if(!a)continue;const u=a[1];if(u.startsWith(".")||r.has(u))continue;r.add(u);let m=u.charAt(0).toUpperCase()+u.slice(1);try{const f=JSON.parse(h.content);f.title&&(m=f.title)}catch{}d.push({prefix:u,label:m,traits:{}})}return d.length===0?[]:d}const Fe={manifest:le,viewer:{PreviewComponent:De,workspace:{type:"manifest",multiFile:!0,ordered:!1,hasActiveFile:!0,manifestFile:"manifest.json",resolveContentSets:Oe,resolveItems(i){const d=i.find(r=>r.path==="manifest.json"||r.path.endsWith("/manifest.json"));if(!d)return i.filter(r=>/\.html$/i.test(r.path)).map((r,h)=>({path:r.path,label:r.path.replace(/^.*\//,"").replace(/\.html$/i,""),index:h}));try{return(JSON.parse(d.content).pages||[]).map((h,a)=>({path:h.file,label:h.title||h.file.replace(/\.html$/i,""),index:a}))}catch{return[]}},createEmpty(i){const d=new Set;for(const o of i){const n=o.path.indexOf("/");n>0&&d.add(o.path.slice(0,n))}let r="site-1",h=1;for(;d.has(r);)r=`site-${++h}`;let a="";for(const o of d){const n=i.find(g=>g.path===`${o}/styles.css`);if(n){a=n.content;break}}const u={title:"New Site",pages:[{file:"index.html",title:"Home"}]},m=`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Home</title>${a?`
  <link rel="stylesheet" href="styles.css">`:""}
</head>
<body>
  <h1>Home</h1>
  <p>Start building your new site.</p>
</body>
</html>
`,f=[{path:`${r}/index.html`,content:m},{path:`${r}/manifest.json`,content:JSON.stringify(u,null,2)}];return a&&f.push({path:`${r}/styles.css`,content:a}),f}},actions:le.viewerApi?.actions,extractContext(i,d){const r=i?.file||d.find(n=>/\.html$/i.test(n.path))?.path||"";if(!r)return"";const h=d.find(n=>n.path==="manifest.json"||n.path.endsWith("/manifest.json"));let a=[];if(h)try{a=JSON.parse(h.content).pages??[]}catch{}let u;if(a.length>0){const n=a.findIndex(g=>g.file===r);if(n>=0){const g=a[n].title||r.replace(/\.html$/i,"").replace(/^.*\//,"");u=`Viewing page ${n+1}/${a.length}: "${g}"`}else u=`Viewing: ${r}`}else{const n=d.filter(v=>/\.html$/i.test(v.path)),g=n.findIndex(v=>v.path===r);u=g>=0?`Viewing page ${g+1}/${n.length}: "${r.replace(/\.html$/i,"").replace(/^.*\//,"")}"`:`Viewing: ${r}`}const m=n=>{if(a.length>0){const g=a.findIndex(v=>v.file===n);if(g>=0){const v=a[g].title||n.replace(/\.html$/i,"").replace(/^.*\//,"");return`page ${g+1}: "${v}"`}}return n};if(i?.type==="annotations"&&i.annotations?.length){const n=['mode="webcraft"',`file="${r}"`],g=[];return g.push(u),g.push("Annotations:"),i.annotations.forEach((v,z)=>{const b=v.element,I=m(v.slideFile);let T;b.selector?T=b.selector:T=`${b.type} "${(b.content||"").slice(0,50)}"`,g.push(`  ${z+1}. [${I}] ${T}`),b.label&&g.push(`     Element: ${b.label}`),b.nearbyText&&g.push(`     Context: ${b.nearbyText}`),b.accessibility&&g.push(`     Accessibility: ${b.accessibility}`),v.comment&&g.push(`     Feedback: ${v.comment}`)}),`<viewer-context ${n.join(" ")}>
${g.join(`
`)}
</viewer-context>`}const f=['mode="webcraft"',`file="${r}"`],o=[];if(o.push(u),i&&i.type!=="viewing"){if(i.selector)o.push(`Selected: ${i.selector}`);else{const n=i.level?`${i.type} (level ${i.level})`:i.type;o.push(`Selected: ${n} "${i.content}"`)}i.label&&o.push(`  Element: ${i.label}`),i.tag&&o.push(`  Tag: <${i.tag}>`),i.classes&&o.push(`  Classes: ${i.classes}`),i.nearbyText&&o.push(`  Context: ${i.nearbyText}`),i.accessibility&&o.push(`  Accessibility: ${i.accessibility}`)}return`<viewer-context ${f.join(" ")}>
${o.join(`
`)}
</viewer-context>`},updateStrategy:"full-reload"}};export{Fe as default};
