@uicopilot/storybook-addon 0.5.7 → 0.5.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/preset.d.mts CHANGED
@@ -27,7 +27,7 @@ declare function experimental_serverChannel(channel: Channel): Channel;
27
27
  declare function viteFinal(config: any): any;
28
28
 
29
29
  /**
30
- * UI Copilot Storybook Addon - Preset
30
+ * UI Parity Storybook Addon - Preset
31
31
  *
32
32
  * This file tells Storybook where to find the addon's manager entry point.
33
33
  * The experimental_serverChannel is re-exported from @uicopilot/storybook-adapter
package/dist/preset.d.ts CHANGED
@@ -27,7 +27,7 @@ declare function experimental_serverChannel(channel: Channel): Channel;
27
27
  declare function viteFinal(config: any): any;
28
28
 
29
29
  /**
30
- * UI Copilot Storybook Addon - Preset
30
+ * UI Parity Storybook Addon - Preset
31
31
  *
32
32
  * This file tells Storybook where to find the addon's manager entry point.
33
33
  * The experimental_serverChannel is re-exported from @uicopilot/storybook-adapter
package/dist/preset.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var Se=Object.create;var $=Object.defineProperty;var Ie=Object.getOwnPropertyDescriptor;var be=Object.getOwnPropertyNames;var ve=Object.getPrototypeOf,Oe=Object.prototype.hasOwnProperty;var Te=(e,o)=>()=>(e&&(o=e(e=0)),o);var G=(e,o)=>{for(var t in o)$(e,t,{get:o[t],enumerable:!0})},K=(e,o,t,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of be(o))!Oe.call(e,r)&&r!==t&&$(e,r,{get:()=>o[r],enumerable:!(s=Ie(o,r))||s.enumerable});return e};var F=(e,o,t)=>(t=e!=null?Se(ve(e)):{},K(o||!e||!e.__esModule?$(t,"default",{value:e,enumerable:!0}):t,e)),Ee=e=>K($({},"__esModule",{value:!0}),e);var ie={};G(ie,{detectFileType:()=>se,formatValidationResult:()=>Le,isValidCode:()=>Me,validateCode:()=>re,validateCodeForFile:()=>ne});function xe(e,o={}){let t=o.minLength??_e;return e.length<t?{code:"CODE_TOO_SHORT",message:`Code is too short (${e.length} chars). Minimum: ${t}. Likely incomplete or a snippet.`,severity:"error"}:null}function $e(e){let o=[/^[+-]{3}\s+[ab]\//m,/^@@\s+-\d+,\d+\s+\+\d+,\d+\s+@@/m,/^diff --git/m,/^index [a-f0-9]+\.\.[a-f0-9]+/m];for(let t of o)if(t.test(e))return{code:"CODE_IS_DIFF",message:"Code appears to be a diff/patch format, not complete file content.",severity:"error"};return null}function Fe(e){let o=e.split(`
2
- `).filter(r=>r.trim()),t=o.filter(r=>r.trim().startsWith("//")||r.trim().startsWith("/*")||r.trim().startsWith("*")||r.trim().startsWith("#"));if(o.length>0&&t.length/o.length>.8)return{code:"CODE_IS_INSTRUCTIONS",message:"Code appears to be mostly comments/instructions, not actual implementation.",severity:"error"};let s=[/^\/\/\s*(Change|Replace|Update|Modify|Add|Remove|Delete)\s+(from|to|this|the)/im,/^\/\/\s*To:/m,/^\/\/\s*From:/m];for(let r of s)if(r.test(e))return{code:"CODE_IS_INSTRUCTIONS",message:'Code contains instruction comments (e.g., "// Change from:" / "// To:") instead of actual code.',severity:"error"};return null}function Re(e){let o={"{":"}","[":"]","(":")"},t=[],s=!1,r="",c=!1;for(let h=0;h<e.length;h++){let i=e[h],u=e[h-1];if((i==='"'||i==="'"||i==="`")&&u!=="\\"){s?i===r&&(s=!1,c=!1):(s=!0,r=i,i==="`"&&(c=!0));continue}if(!s){if(o[i])t.push(o[i]);else if(Object.values(o).includes(i)&&t.pop()!==i)return{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets detected. Found unexpected '${i}'.`,severity:"warning"}}}return t.length>0?{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets. Missing: ${t.reverse().join("")}`,severity:"warning"}:null}function oe(e,o={}){let t=[],s=[];e.includes("import ")||t.push({code:"TSX_MISSING_IMPORTS",message:"Component file missing import statements. A complete file must have imports.",severity:"error"}),e.includes("export ")||t.push({code:"TSX_MISSING_EXPORTS",message:"Component file missing exports. A complete file must export something.",severity:"error"});let r=/import\s+(?:React|\{[^}]*\})\s+from\s+['"]react['"]/.test(e);/<[A-Z][a-zA-Z]*|<[a-z]+[\s/>]/.test(e)&&!r&&s.push({code:"TSX_NO_REACT_IMPORT",message:"JSX detected but no React import. OK for React 17+ with automatic runtime.",severity:"warning"}),/export\s+(default\s+)?function\s+\w+/.test(e)||/export\s+(const|let)\s+\w+\s*[:=]/.test(e)||/export\s+default\s+\w+/.test(e)||/export\s+\{[^}]+\}/.test(e)||s.push({code:"TSX_NO_COMPONENT_DEF",message:"No clear component definition found. Expected function or const export.",severity:"warning"});let i=[{pattern:/\.\.\.\s*$/,message:'Code ends with "..." - likely truncated'},{pattern:/\/\/\s*\.\.\./m,message:'Contains "// ..." - likely incomplete'},{pattern:/{\s*\/\*\s*\.\.\.\s*\*\/\s*}/m,message:'Contains "{/* ... */}" placeholder'}];for(let{pattern:u,message:f}of i)u.test(e)&&t.push({code:"TSX_INCOMPLETE",message:f,severity:"error"});return{errors:t,warnings:s}}function Ue(e,o={}){let t=[],s=[];(e.includes("import ")||e.includes("export "))&&t.push({code:"CSS_HAS_JS_CODE",message:"CSS file contains JavaScript import/export statements. Wrong file type.",severity:"error"}),/[.#\w\[\]]+\s*\{[\s\S]*?:\s*[^;]+;?[\s\S]*?\}/.test(e)||t.push({code:"CSS_INVALID_SYNTAX",message:"No valid CSS syntax found. Expected selector { property: value; } pattern.",severity:"error"});let c=(e.match(/\{[^}]+\}/g)||[]).length;return c===0&&t.push({code:"CSS_NO_RULES",message:"No CSS rules found. File appears empty or malformed.",severity:"error"}),(e.includes("/* ... */")||e.includes("// ..."))&&t.push({code:"CSS_INCOMPLETE",message:"CSS contains placeholder comments (/* ... */) - likely incomplete.",severity:"error"}),c>0&&c<3&&!o.allowPartial&&s.push({code:"CSS_FEW_RULES",message:`Only ${c} CSS rule(s) found. Might be incomplete.`,severity:"warning"}),{errors:t,warnings:s}}function Ne(e,o={}){let t=[],s=[];return e.includes("import ")||t.push({code:"STORIES_MISSING_IMPORTS",message:"Stories file missing import statements.",severity:"error"}),/@storybook\//.test(e)||t.push({code:"STORIES_NO_STORYBOOK_IMPORT",message:"Stories file must import from @storybook/* (e.g., @storybook/react).",severity:"error"}),e.includes("Meta")||e.includes("ComponentMeta")||s.push({code:"STORIES_NO_META_TYPE",message:"Stories file should have Meta type import for type safety.",severity:"warning"}),e.includes("StoryObj")||e.includes("ComponentStory")||e.includes("Story")||s.push({code:"STORIES_NO_STORY_TYPE",message:"Stories file should have StoryObj/Story type for type safety.",severity:"warning"}),e.includes("export default")||t.push({code:"STORIES_NO_DEFAULT_EXPORT",message:"Stories file must have a default export (meta configuration).",severity:"error"}),/export\s+const\s+\w+\s*[:=]/.test(e)||t.push({code:"STORIES_NO_STORY_EXPORTS",message:"Stories file must have at least one named export (story definition).",severity:"error"}),/import\s+\{?\s*\w+\s*\}?\s+from\s+['"]\.\//.test(e)||s.push({code:"STORIES_NO_COMPONENT_IMPORT",message:"Stories file should import the component being documented.",severity:"warning"}),(e.includes("// ... other")||e.includes("/* ... */"))&&t.push({code:"STORIES_INCOMPLETE",message:"Stories file contains placeholder comments - likely incomplete.",severity:"error"}),{errors:t,warnings:s}}function se(e){let o=e.toLowerCase();if(o.includes(".stories."))return"stories";switch(o.split(".").pop()){case"tsx":return"tsx";case"jsx":return"jsx";case"ts":return"ts";case"js":return"js";case"css":return"css";case"scss":return"scss";case"less":return"less";default:return"unknown"}}function re(e,o,t={}){let s={valid:!0,fileType:o,errors:[],warnings:[]},r=xe(e,t);r&&s.errors.push(r);let c=$e(e);c&&s.errors.push(c);let h=Fe(e);h&&s.errors.push(h);let i=Re(e);switch(i&&(t.strict?s.errors.push({...i,severity:"error"}):s.warnings.push(i)),o){case"stories":{let{errors:u,warnings:f}=Ne(e,t);s.errors.push(...u),s.warnings.push(...f);break}case"tsx":case"jsx":{let{errors:u,warnings:f}=oe(e,t);s.errors.push(...u),s.warnings.push(...f);break}case"css":case"scss":case"less":{let{errors:u,warnings:f}=Ue(e,t);s.errors.push(...u),s.warnings.push(...f);break}case"ts":case"js":{let{errors:u,warnings:f}=oe(e,t);s.errors.push(...u),s.warnings.push(...f.filter(n=>!n.code.includes("JSX")));break}default:break}return s.valid=s.errors.length===0,s}function ne(e,o,t={}){let s=se(o);return re(e,s,t)}function Me(e,o,t={}){return ne(e,o,t).valid}function Le(e){if(e.valid&&e.warnings.length===0)return`\u2713 Valid ${e.fileType} code`;let o=[];if(e.valid)o.push(`\u26A0 Valid ${e.fileType} code with warnings`);else{o.push(`\u2717 Invalid ${e.fileType} code`),o.push(""),o.push("Errors:");for(let t of e.errors)o.push(` - [${t.code}] ${t.message}`)}if(e.warnings.length>0){o.push(""),o.push("Warnings:");for(let t of e.warnings)o.push(` - [${t.code}] ${t.message}`)}return o.join(`
3
- `)}var _e,ae=Te(()=>{"use strict";_e=50});var Qe={};G(Qe,{experimental_serverChannel:()=>ge,managerEntries:()=>qe,previewAnnotations:()=>ze,viteFinal:()=>me});module.exports=Ee(Qe);var P=require("path"),X=require("url");var he=F(require("fs/promises")),M=F(require("path")),W=require("glob");var z=require("fs"),Q=require("module"),R=null,E=null,q=!1;async function B(){if(q)return!!R;if(q=!0,process.env.STORYBOOK_UICOPILOT_NO_PUPPETEER==="true")return console.log("[UI Copilot] Puppeteer disabled via STORYBOOK_UICOPILOT_NO_PUPPETEER flag"),!1;let e=(0,Q.createRequire)(process.cwd()+"/");try{return R=e("puppeteer"),console.log("[UI Copilot] Puppeteer loaded \u2014 server-side screenshots enabled"),!0}catch{}try{return R=e("puppeteer-core"),console.log("[UI Copilot] puppeteer-core loaded \u2014 server-side screenshots enabled"),!0}catch{}return console.log("[UI Copilot] Puppeteer not found \u2014 install puppeteer for pixel-perfect screenshots"),!1}function Pe(){let e=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary","/Applications/Chromium.app/Contents/MacOS/Chromium","/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium"];for(let o of e)if((0,z.existsSync)(o))return o}async function Z(){if(E&&E.connected)return E;let e=Pe(),o={headless:!0,args:["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage"],...e?{executablePath:e}:{}};return E=await R.launch(o),console.log("[UI Copilot] Headless Chrome launched for screenshots"),E}async function H(e,o){if(!await B())return null;let r=await(await Z()).newPage();try{await r.setCacheEnabled(!1),await r.setViewport({width:o?.width||800,height:o?.height||600,deviceScaleFactor:1}),await r.goto(e,{waitUntil:"networkidle2",timeout:15e3}),await r.evaluate(()=>document.fonts.ready),await r.waitForSelector("#storybook-root > *",{timeout:1e4}),await r.waitForFunction(()=>new Promise(i=>{let u=document.querySelectorAll("style").length,f=0,n=()=>{let p=document.querySelectorAll("style").length;if(p===u){if(f++,f>=3){i(!0);return}}else f=0,u=p;setTimeout(n,100)};setTimeout(n,200)}),{timeout:5e3}).catch(()=>{}),await new Promise(i=>setTimeout(i,500));let c=await r.evaluate(()=>{let i=document.querySelector("#storybook-root");if(!i)return null;let u=window.innerWidth;function f(g){let a=g.getBoundingClientRect();if(a.width===0||a.height===0)return null;if(a.width<u*.8&&a.height>0)return a;for(let m of Array.from(g.children)){let d=window.getComputedStyle(m);if(d.position==="fixed"||d.position==="absolute"||d.display==="none"||d.visibility==="hidden")continue;let l=f(m);if(l)return l}return null}let n=f(i);if(n)return{x:Math.max(0,n.x-8),y:Math.max(0,n.y-8),width:n.width+16,height:n.height+16};let p=i.firstElementChild;if(p){let g=p.getBoundingClientRect();return{x:g.x,y:g.y,width:g.width,height:g.height}}return null});if(!c)throw new Error("Could not determine component bounds");let h=await r.screenshot({type:"png",clip:c});return Buffer.from(h)}finally{await r.close()}}async function ee(e,o,t,s){if(!await B())return null;let h=await(await Z()).newPage();try{await h.setCacheEnabled(!1),await h.setViewport({width:s?.width||800,height:s?.height||600,deviceScaleFactor:1});let i=s?.storyId||"",u=`${t}/iframe.html?viewMode=story&id=${i}&globals=`;await h.goto(u,{waitUntil:"load",timeout:15e3}),await h.waitForSelector("#storybook-root > *",{timeout:1e4}),await h.evaluate(p=>{let g=document.getElementById("storybook-root");g&&(g.innerHTML=p)},e),await h.evaluate(()=>document.fonts.ready),await new Promise(p=>setTimeout(p,500));let f=await h.evaluate(()=>{let p=document.querySelector("#storybook-root");if(!p)return null;let g=window.innerWidth;function a(l){let y=l.getBoundingClientRect();if(y.width===0||y.height===0)return null;if(y.width<g*.8&&y.height>0)return y;for(let v of Array.from(l.children)){let w=window.getComputedStyle(v);if(w.position==="fixed"||w.position==="absolute"||w.display==="none"||w.visibility==="hidden")continue;let C=a(v);if(C)return C}return null}let m=a(p);if(m)return{x:Math.max(0,m.x-8),y:Math.max(0,m.y-8),width:m.width+16,height:m.height+16};let d=p.firstElementChild;if(d){let l=d.getBoundingClientRect();return{x:l.x,y:l.y,width:l.width,height:l.height}}return null});if(!f)throw new Error("Could not determine component bounds from snapshot");let n=await h.screenshot({type:"png",clip:f});return Buffer.from(n)}finally{await h.close()}}async function U(){return B()}async function te(){E&&(await E.close(),E=null)}var J=null,N=null,le=!1;async function ke(){if(!le){le=!0;try{let e=await Promise.resolve().then(()=>(ae(),ie));J=e.validateCodeForFile,N=e.formatValidationResult,console.log("[UI Copilot] Code validator loaded - fix validation enabled")}catch{console.log("[UI Copilot] Code validator not available - skipping fix validation")}}}var Ae="UICOPILOT/APPLY_FIXES",De="UICOPILOT/FIX_STARTED",je="UICOPILOT/FIX_COMPLETED",Be="UICOPILOT/FIX_FAILED",ce="UICOPILOT/ALL_FIXES_APPLIED",He="UICOPILOT/RELOAD_REQUIRED",de="UICOPILOT/WORKSPACE_PATH",We="UICOPILOT/REQUEST_WORKSPACE_PATH",Je="UICOPILOT/DISCOVER_COMPONENT_FILES",ue="UICOPILOT/COMPONENT_FILES_DISCOVERED";async function pe(e,o){let t=e.toLowerCase(),s=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),r=[`src/**/fui-${t}/fui-${t}.css`,`src/**/fui-${t}/*.css`,`src/**/${t}/${t}.css`,`src/**/${s}/${s}.css`,`src/**/*${t}*.css`,`src/**/*${s}*.css`,`styles/**/*${t}*.css`],c=[`src/**/fui-${t}/fui-${t}.tsx`,`src/**/fui-${t}/*.tsx`,`src/**/${t}/${t}.tsx`,`src/**/${s}/${s}.tsx`,`src/**/*${s}*.tsx`,`src/**/*${s}*.jsx`],h=[],i=[];for(let d of r)try{let l=await(0,W.glob)(d,{cwd:o,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**"]});l.length>0&&h.push(...l)}catch{}for(let d of c)try{let l=await(0,W.glob)(d,{cwd:o,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**","**/*.stories.*","**/*.test.*"]});l.length>0&&i.push(...l)}catch{}let u=[...new Set(h)],f=[...new Set(i)],n=d=>{if(d.length===0)return;let l=d.find(w=>w.includes(`/fui-${t}/`)&&w.endsWith(".css"));if(l)return l;let y=d.find(w=>w.toLowerCase().includes(`/${t}/${t}.css`)||w.includes(`/${s}/${s}.css`));if(y)return y;let v=d.find(w=>w.toLowerCase().endsWith(`/${t}.css`)||w.endsWith(`/${s}.css`));return v||d[0]},p=d=>{if(d.length===0)return;let l=d.filter(C=>!C.includes(".stories.")&&!C.includes(".test."));if(l.length===0)return d[0];let y=l.find(C=>C.includes(`/fui-${t}/`)&&(C.endsWith(".tsx")||C.endsWith(".jsx")));if(y)return y;let v=l.find(C=>C.toLowerCase().includes(`/${t}/${t}.tsx`)||C.includes(`/${s}/${s}.tsx`));if(v)return v;let w=l.find(C=>C.toLowerCase().endsWith(`/${t}.tsx`)||C.endsWith(`/${s}.tsx`));return w||l[0]},g=n(u),a=p(f),m=[...u,...f];return console.log(`[UI Copilot] Discovered files for "${e}":`,{cssFile:g,componentFile:a,totalMatches:m.length}),{cssFile:g,componentFile:a,allMatches:[...new Set(m)]}}var Xe=100;function Ve(e){return new Promise(o=>setTimeout(o,e))}async function Ye(e,o){if(await ke(),!J||!N)return console.log(`[UI Copilot] Skipping validation (validator not available) for ${o}`),{valid:!0};let t=J(e,o);if(!t.valid){let s=t.errors.map(r=>r.message).join("; ");return console.warn(`[UI Copilot] Code validation failed for ${o}:`),console.warn(N(t)),{valid:!1,error:s}}return t.warnings.length>0&&(console.warn(`[UI Copilot] Code validation warnings for ${o}:`),console.warn(N(t))),console.log(`[UI Copilot] Validation passed for ${o}`),{valid:!0}}var fe=!1;function ge(e){if(fe)return e;fe=!0;let o=process.cwd();return console.log("[UI Copilot] Apply fixes initialized"),console.log("[UI Copilot] Workspace:",o),e.emit(de,{path:o}),e.on(We,()=>{console.log("[UI Copilot] Workspace path requested by browser"),console.log("[UI Copilot] Emitting workspace path response:",o),e.emit(de,{path:o})}),e.on(Je,async t=>{let{componentName:s,storyId:r}=t;console.log(`[UI Copilot] Discovering files for component: ${s}`);try{let c=await pe(s,o);e.emit(ue,{componentName:s,storyId:r,...c,workspacePath:o})}catch(c){console.error("[UI Copilot] File discovery error:",c),e.emit(ue,{componentName:s,storyId:r,error:c.message,allMatches:[]})}}),e.on(Ae,t=>{setTimeout(async()=>{try{let{issues:s,storybookRoot:r}=t,c=r||o;console.log(r?`[UI Copilot] Using storybookRoot from API: ${r}`:`[UI Copilot] Using process.cwd(): ${o}`),console.log(`[UI Copilot] Received APPLY_FIXES for ${s.length} issue(s)`);let h=new Map;async function i(n){let p=n.targetFileType||"css",g=n.targetFilePath||n.generatedFix?.filePath,a="",m=n.title?.match(/^(\w+)\s/);if(m&&(a=m[1]),!a&&g){let y=g.match(/\/(\w+)\.(?:css|tsx|jsx)$/i);y&&(a=y[1])}if(!a)return console.log(`[UI Copilot] Could not extract component name, using provided path: ${g}`),g||null;if(!h.has(a)){let y=await pe(a,c);h.set(a,y)}let d=h.get(a),l=p==="css"?d.cssFile:d.componentFile;return l?(console.log(`[UI Copilot] Discovered ${p} path: ${l} (was: ${g})`),l):(console.log(`[UI Copilot] No ${p} file discovered, using provided: ${g}`),g||null)}let u=[];for(let n of s){let{generatedFix:p}=n,g=n.targetFilePath||p?.filePath,a=await i(n)||g;console.log("[UI Copilot] Processing issue:",{id:n.id,type:n.type,targetFileType:n.targetFileType||"css",targetPath:a,providedPath:g!==a?g:"(same)",codeLength:p?.code?.length||0}),e.emit(De,{issueId:n.id});try{if(!p||!p.code||!a)throw new Error("Missing AI-generated fix data (code or filePath)");console.log("[UI Copilot] Code to write (first 200 chars):",p.code.substring(0,200)),console.log(`[UI Copilot] Code length: ${p.code.length} chars`);let m=await Ye(p.code,a);if(!m.valid)throw new Error(`Code validation failed: ${m.error}. Fix was not applied to prevent breaking the file.`);let d=M.isAbsolute(a)?a:M.join(c,a);console.log(`[UI Copilot] Writing to absolute path: ${d}`),await he.writeFile(d,p.code,"utf-8"),await Ve(Xe);let l={success:!0,issueId:n.id,filePath:a,timestamp:new Date};e.emit(je,{issueId:n.id,result:l}),console.log(`[UI Copilot] \u2713 Applied ${n.targetFileType||"css"} fix to: ${a}`),u.push(l)}catch(m){let d=m.message||"Unknown error";e.emit(Be,{issueId:n.id,error:d}),console.error(`[UI Copilot] \u2717 Error: ${d}`),u.push({success:!1,issueId:n.id,error:d,timestamp:new Date})}}let f={total:u.length,succeeded:u.filter(n=>n.success).length,failed:u.filter(n=>!n.success).length};e.emit(ce,{results:u,summary:f}),console.log(`[UI Copilot] Completed: ${f.succeeded}/${f.total} fixes applied`),f.succeeded>0&&e.emit(He,{message:"Fixes applied. If Storybook crashes due to HMR, please restart it.",filesChanged:u.filter(n=>n.success).map(n=>n.filePath)})}catch(s){console.error("[UI Copilot] Fatal error during fix application:",s),e.emit(ce,{results:[],summary:{total:t.issues?.length||0,succeeded:0,failed:t.issues?.length||0}})}},0)}),e}function me(e){let o=process.cwd();return e.plugins=e.plugins||[],e.plugins.push({name:"uicopilot-server-api",configureServer(t){t.middlewares.use("/__uicopilot/health",(s,r)=>{r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({ok:!0,workspacePath:o}))}),t.middlewares.use("/__uicopilot/screenshot",async(s,r)=>{try{if(!await U()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed. Run: npm install puppeteer"}));return}let i=new URL(s.url||"",`http://${s.headers.host}`).searchParams.get("storyId");if(!i){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing storyId parameter"}));return}let f=`http://${s.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${i}&globals=`;console.log(`[UI Copilot] Taking screenshot: ${i}`);let n=await H(f,{selector:"#storybook-root > *"});if(!n){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p=n.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${p}`}))}catch(c){console.error("[UI Copilot] Screenshot error:",c.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:c.message}))}}),t.middlewares.use("/__uicopilot/capture",async(s,r)=>{try{if(!await U()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed"}));return}let i=new URL(s.url||"",`http://${s.headers.host}`).searchParams.get("storyId");if(!i){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing storyId parameter"}));return}let f=`http://${s.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${i}&globals=`;console.log(`[UI Copilot] Full capture: ${i}`);let n=await H(f,{selector:"#storybook-root > *"});if(!n){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p;try{p=(await import("puppeteer")).default}catch{p=(await import("puppeteer-core")).default}let g=await p.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),a=await g.newPage();try{await a.setCacheEnabled(!1),await a.setViewport({width:800,height:600}),await a.goto(f,{waitUntil:"networkidle2",timeout:15e3}),await a.evaluate(()=>document.fonts.ready),await a.waitForSelector("#storybook-root > *",{timeout:1e4});let m=await a.evaluate(()=>{let l=document.querySelector("#storybook-root > *")||document.querySelector("#root > *"),y={};if(l){let S=window.getComputedStyle(l);for(let O=0;O<S.length;O++)y[S[O]]=S.getPropertyValue(S[O])}let v={backgroundColor:["transparent","rgba(0, 0, 0, 0)"],border:["none","0px none","0px none rgb(0, 0, 0)"],borderRadius:["0px"],boxShadow:["none"],opacity:["1"]};function w(S){return S.replace(/-([a-z])/g,(O,T)=>T.toUpperCase())}function C(S,O){if(O>4)return null;let T=S.tagName.toLowerCase();if(["script","style","link","meta","br","hr","noscript"].includes(T))return null;let L=S.className,k=typeof L=="string"?L:L?.baseVal||"",A=S.id||void 0,ye=S.getAttribute("role")||void 0,V;for(let b of Array.from(S.childNodes))if(b.nodeType===3){let I=b.textContent?.trim();if(I){V=I.length>50?I.substring(0,50)+"...":I;break}}let D=T;A?D=`${T}#${A}`:k&&(D=`${T}.${k.split(" ").filter(Boolean).join(".")}`);let we=window.getComputedStyle(S),Ce=["background-color","border","border-radius","box-shadow","opacity","fill","stroke","stroke-width","font-size","font-family","font-weight","line-height","letter-spacing","color","text-align","display","padding","margin","gap","flex-direction","justify-content","align-items","width","height"],j={};for(let b of Ce){let I=we.getPropertyValue(b),x=w(b);I&&!v[x]?.includes(I)&&(j[x]=I)}if(T==="svg"||S.closest("svg"))for(let b of["fill","stroke","stroke-width","viewBox","d","r","cx","cy"]){let I=S.getAttribute(b);I&&(j[w(b)]=I)}let Y=[];for(let b of Array.from(S.children)){let I=window.getComputedStyle(b);if(I.display==="none"||I.visibility==="hidden")continue;let x=C(b,O+1);x&&Y.push(x)}return{selector:D,tagName:T,className:k,id:A,role:ye,textContent:V,styles:j,children:Y}}return{computedStyles:y,domTree:l?C(l,0):null}}),d=n.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${d}`,computedStyles:m.computedStyles,domTree:m.domTree}))}finally{await a.close(),await g.close()}}catch(c){console.error("[UI Copilot] Capture error:",c.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:c.message}))}}),t.middlewares.use("/__uicopilot/screenshot-snapshot",async(s,r)=>{if(s.method!=="POST"){r.writeHead(405,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"POST required"}));return}try{if(!await U()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed"}));return}let h=[];for await(let d of s)h.push(typeof d=="string"?Buffer.from(d):d);let i=JSON.parse(Buffer.concat(h).toString()),{html:u,stylesheetUrls:f,storyId:n}=i;if(!u){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing html in body"}));return}let g=`http://${s.headers.host||"localhost:6006"}`;console.log(`[UI Copilot] Taking snapshot screenshot for ${n||"unknown"}`);let a=await ee(u,f||[],g,{storyId:n});if(!a){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Snapshot screenshot failed"}));return}let m=a.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${m}`}))}catch(c){console.error("[UI Copilot] Snapshot screenshot error:",c.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:c.message}))}}),t.httpServer?.on("close",()=>{te().catch(()=>{})})}}),e}var _={},Ge=()=>{if(typeof _<"u"&&_.url){let e=(0,X.fileURLToPath)(_.url),o=(0,P.dirname)(e);return(0,P.join)(o,"manager.mjs")}return(0,P.join)(__dirname,"manager.mjs")},Ke=()=>{if(typeof _<"u"&&_.url){let e=(0,X.fileURLToPath)(_.url),o=(0,P.dirname)(e);return(0,P.join)(o,"preview.mjs")}return(0,P.join)(__dirname,"preview.mjs")};function qe(e=[]){return[...e,Ge()]}function ze(e=[]){return[...e,Ke()]}0&&(module.exports={experimental_serverChannel,managerEntries,previewAnnotations,viteFinal});
1
+ "use strict";var $e=Object.create;var R=Object.defineProperty;var _e=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Le=Object.getPrototypeOf,Re=Object.prototype.hasOwnProperty;var Ne=(e,i)=>()=>(e&&(i=e(e=0)),i);var ee=(e,i)=>{for(var t in i)R(e,t,{get:i[t],enumerable:!0})},te=(e,i,t,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Oe(i))!Re.call(e,n)&&n!==t&&R(e,n,{get:()=>i[n],enumerable:!(s=_e(i,n))||s.enumerable});return e};var N=(e,i,t)=>(t=e!=null?$e(Le(e)):{},te(i||!e||!e.__esModule?R(t,"default",{value:e,enumerable:!0}):t,e)),Fe=e=>te(R({},"__esModule",{value:!0}),e);var me={};ee(me,{detectFileType:()=>ue,formatValidationResult:()=>st,isValidCode:()=>it,validateCode:()=>pe,validateCodeForFile:()=>fe});function Ye(e,i={}){let t=i.minLength??qe;return e.length<t?{code:"CODE_TOO_SHORT",message:`Code is too short (${e.length} chars). Minimum: ${t}. Likely incomplete or a snippet.`,severity:"error"}:null}function Ke(e){let i=[/^[+-]{3}\s+[ab]\//m,/^@@\s+-\d+,\d+\s+\+\d+,\d+\s+@@/m,/^diff --git/m,/^index [a-f0-9]+\.\.[a-f0-9]+/m];for(let t of i)if(t.test(e))return{code:"CODE_IS_DIFF",message:"Code appears to be a diff/patch format, not complete file content.",severity:"error"};return null}function Qe(e){let i=e.split(`
2
+ `).filter(n=>n.trim()),t=i.filter(n=>n.trim().startsWith("//")||n.trim().startsWith("/*")||n.trim().startsWith("*")||n.trim().startsWith("#"));if(i.length>0&&t.length/i.length>.8)return{code:"CODE_IS_INSTRUCTIONS",message:"Code appears to be mostly comments/instructions, not actual implementation.",severity:"error"};let s=[/^\/\/\s*(Change|Replace|Update|Modify|Add|Remove|Delete)\s+(from|to|this|the)/im,/^\/\/\s*To:/m,/^\/\/\s*From:/m];for(let n of s)if(n.test(e))return{code:"CODE_IS_INSTRUCTIONS",message:'Code contains instruction comments (e.g., "// Change from:" / "// To:") instead of actual code.',severity:"error"};return null}function Ze(e){let i={"{":"}","[":"]","(":")"},t=[],s=!1,n="",o=!1;for(let r=0;r<e.length;r++){let d=e[r],g=e[r-1];if((d==='"'||d==="'"||d==="`")&&g!=="\\"){s?d===n&&(s=!1,o=!1):(s=!0,n=d,d==="`"&&(o=!0));continue}if(!s){if(i[d])t.push(i[d]);else if(Object.values(i).includes(d)&&t.pop()!==d)return{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets detected. Found unexpected '${d}'.`,severity:"warning"}}}return t.length>0?{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets. Missing: ${t.reverse().join("")}`,severity:"warning"}:null}function de(e,i={}){let t=[],s=[];e.includes("import ")||t.push({code:"TSX_MISSING_IMPORTS",message:"Component file missing import statements. A complete file must have imports.",severity:"error"}),e.includes("export ")||t.push({code:"TSX_MISSING_EXPORTS",message:"Component file missing exports. A complete file must export something.",severity:"error"});let n=/import\s+(?:React|\{[^}]*\})\s+from\s+['"]react['"]/.test(e);/<[A-Z][a-zA-Z]*|<[a-z]+[\s/>]/.test(e)&&!n&&s.push({code:"TSX_NO_REACT_IMPORT",message:"JSX detected but no React import. OK for React 17+ with automatic runtime.",severity:"warning"}),/export\s+(default\s+)?function\s+\w+/.test(e)||/export\s+(const|let)\s+\w+\s*[:=]/.test(e)||/export\s+default\s+\w+/.test(e)||/export\s+\{[^}]+\}/.test(e)||s.push({code:"TSX_NO_COMPONENT_DEF",message:"No clear component definition found. Expected function or const export.",severity:"warning"});let d=[{pattern:/\.\.\.\s*$/,message:'Code ends with "..." - likely truncated'},{pattern:/\/\/\s*\.\.\./m,message:'Contains "// ..." - likely incomplete'},{pattern:/{\s*\/\*\s*\.\.\.\s*\*\/\s*}/m,message:'Contains "{/* ... */}" placeholder'}];for(let{pattern:g,message:f}of d)g.test(e)&&t.push({code:"TSX_INCOMPLETE",message:f,severity:"error"});return{errors:t,warnings:s}}function et(e,i={}){let t=[],s=[];(e.includes("import ")||e.includes("export "))&&t.push({code:"CSS_HAS_JS_CODE",message:"CSS file contains JavaScript import/export statements. Wrong file type.",severity:"error"}),/[.#\w\[\]]+\s*\{[\s\S]*?:\s*[^;]+;?[\s\S]*?\}/.test(e)||t.push({code:"CSS_INVALID_SYNTAX",message:"No valid CSS syntax found. Expected selector { property: value; } pattern.",severity:"error"});let o=(e.match(/\{[^}]+\}/g)||[]).length;return o===0&&t.push({code:"CSS_NO_RULES",message:"No CSS rules found. File appears empty or malformed.",severity:"error"}),(e.includes("/* ... */")||e.includes("// ..."))&&t.push({code:"CSS_INCOMPLETE",message:"CSS contains placeholder comments (/* ... */) - likely incomplete.",severity:"error"}),o>0&&o<3&&!i.allowPartial&&s.push({code:"CSS_FEW_RULES",message:`Only ${o} CSS rule(s) found. Might be incomplete.`,severity:"warning"}),{errors:t,warnings:s}}function tt(e,i={}){let t=[],s=[];return e.includes("import ")||t.push({code:"STORIES_MISSING_IMPORTS",message:"Stories file missing import statements.",severity:"error"}),/@storybook\//.test(e)||t.push({code:"STORIES_NO_STORYBOOK_IMPORT",message:"Stories file must import from @storybook/* (e.g., @storybook/react).",severity:"error"}),e.includes("Meta")||e.includes("ComponentMeta")||s.push({code:"STORIES_NO_META_TYPE",message:"Stories file should have Meta type import for type safety.",severity:"warning"}),e.includes("StoryObj")||e.includes("ComponentStory")||e.includes("Story")||s.push({code:"STORIES_NO_STORY_TYPE",message:"Stories file should have StoryObj/Story type for type safety.",severity:"warning"}),e.includes("export default")||t.push({code:"STORIES_NO_DEFAULT_EXPORT",message:"Stories file must have a default export (meta configuration).",severity:"error"}),/export\s+const\s+\w+\s*[:=]/.test(e)||t.push({code:"STORIES_NO_STORY_EXPORTS",message:"Stories file must have at least one named export (story definition).",severity:"error"}),/import\s+\{?\s*\w+\s*\}?\s+from\s+['"]\.\//.test(e)||s.push({code:"STORIES_NO_COMPONENT_IMPORT",message:"Stories file should import the component being documented.",severity:"warning"}),(e.includes("// ... other")||e.includes("/* ... */"))&&t.push({code:"STORIES_INCOMPLETE",message:"Stories file contains placeholder comments - likely incomplete.",severity:"error"}),{errors:t,warnings:s}}function ue(e){let i=e.toLowerCase();if(i.includes(".stories."))return"stories";switch(i.split(".").pop()){case"tsx":return"tsx";case"jsx":return"jsx";case"ts":return"ts";case"js":return"js";case"css":return"css";case"scss":return"scss";case"less":return"less";default:return"unknown"}}function pe(e,i,t={}){let s={valid:!0,fileType:i,errors:[],warnings:[]},n=Ye(e,t);n&&s.errors.push(n);let o=Ke(e);o&&s.errors.push(o);let r=Qe(e);r&&s.errors.push(r);let d=Ze(e);switch(d&&(t.strict?s.errors.push({...d,severity:"error"}):s.warnings.push(d)),i){case"stories":{let{errors:g,warnings:f}=tt(e,t);s.errors.push(...g),s.warnings.push(...f);break}case"tsx":case"jsx":{let{errors:g,warnings:f}=de(e,t);s.errors.push(...g),s.warnings.push(...f);break}case"css":case"scss":case"less":{let{errors:g,warnings:f}=et(e,t);s.errors.push(...g),s.warnings.push(...f);break}case"ts":case"js":{let{errors:g,warnings:f}=de(e,t);s.errors.push(...g),s.warnings.push(...f.filter(c=>!c.code.includes("JSX")));break}default:break}return s.valid=s.errors.length===0,s}function fe(e,i,t={}){let s=ue(i);return pe(e,s,t)}function it(e,i,t={}){return fe(e,i,t).valid}function st(e){if(e.valid&&e.warnings.length===0)return`\u2713 Valid ${e.fileType} code`;let i=[];if(e.valid)i.push(`\u26A0 Valid ${e.fileType} code with warnings`);else{i.push(`\u2717 Invalid ${e.fileType} code`),i.push(""),i.push("Errors:");for(let t of e.errors)i.push(` - [${t.code}] ${t.message}`)}if(e.warnings.length>0){i.push(""),i.push("Warnings:");for(let t of e.warnings)i.push(` - [${t.code}] ${t.message}`)}return i.join(`
3
+ `)}var qe,he=Ne(()=>{"use strict";qe=50});var xt={};ee(xt,{experimental_serverChannel:()=>Ce,managerEntries:()=>yt,previewAnnotations:()=>wt,viteFinal:()=>Ie});module.exports=Fe(xt);var _=require("path"),Y=require("url");var ve=N(require("fs/promises")),D=N(require("path")),J=require("glob");var oe=require("fs"),ae=require("module");var B={NAME:"UI Parity",SHORT:"Parity",DOMAIN:"uiparity.com",MARKETING_URL:"https://uiparity.com",APP_URL:"https://app.uiparity.com",API_URL:"https://api.uiparity.com",SUPPORT_EMAIL:"feedback@uiparity.com",TAGLINE:"Pixel-perfect isn't a feeling. It's a score."};function Me(){if(typeof process<"u"&&process.env)return process.env.UICOPILOT_DEBUG==="1";if(typeof globalThis<"u"&&"localStorage"in globalThis)try{return globalThis.localStorage.getItem("uicopilot_debug")==="1"}catch{return!1}return!1}var F=`[${B.NAME}]`,l={debug:(...e)=>{Me()&&console.log(F,...e)},info:(...e)=>{console.log(F,...e)},warn:(...e)=>{console.warn(F,...e)},error:(...e)=>{console.error(F,...e)}};var Ge=["flex","inline-flex"],We=["grid","inline-grid"],Vt=[...Ge,...We];var M=null,$=null,ne=!1;async function G(){if(ne)return!!M;if(ne=!0,process.env.STORYBOOK_UICOPILOT_NO_PUPPETEER==="true")return l.debug("Puppeteer disabled via STORYBOOK_UICOPILOT_NO_PUPPETEER flag"),!1;let e=(0,ae.createRequire)(process.cwd()+"/");try{return M=e("puppeteer"),l.debug("Puppeteer loaded \u2014 server-side screenshots enabled"),!0}catch{}try{return M=e("puppeteer-core"),l.debug("puppeteer-core loaded \u2014 server-side screenshots enabled"),!0}catch{}return l.debug("Puppeteer not found \u2014 install puppeteer for pixel-perfect screenshots"),!1}function Je(){let e=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary","/Applications/Chromium.app/Contents/MacOS/Chromium","/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium"];for(let i of e)if((0,oe.existsSync)(i))return i}async function ce(){if($&&$.connected)return $;let e=Je(),i={headless:!0,args:["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage"],...e?{executablePath:e}:{}};return $=await M.launch(i),l.debug("Headless Chrome launched for screenshots"),$}async function W(e,i){if(!await G())return null;let n=await(await ce()).newPage();try{await n.setCacheEnabled(!1),await n.setViewport({width:i?.width||800,height:i?.height||600,deviceScaleFactor:1}),await n.goto(e,{waitUntil:"networkidle2",timeout:15e3}),await n.evaluate(()=>document.fonts.ready),await n.waitForSelector("#storybook-root > *",{timeout:1e4}),await n.waitForFunction(()=>new Promise(f=>{let c=document.querySelectorAll("style").length,m=0,h=()=>{let p=document.querySelectorAll("style").length;if(p===c){if(m++,m>=3){f(!0);return}}else m=0,c=p;setTimeout(h,100)};setTimeout(h,200)}),{timeout:5e3}).catch(()=>{}),await new Promise(f=>setTimeout(f,500));let o=await n.evaluate(()=>{let f=document.querySelector("#storybook-root");if(!f)return null;let c=window.innerHeight,m=window.innerWidth,h=1/0,p=0,x=1/0,a=0,u=!1;function S(b){for(let y of Array.from(b.children)){let w=window.getComputedStyle(y);if(w.display==="none"||w.visibility==="hidden"||w.position==="fixed"||w.position==="absolute")continue;let C=y.getBoundingClientRect();if(!(C.height<=0||C.width<=0)){if(C.height>=c*.9&&C.width>=m*.9){S(y);continue}h=Math.min(h,C.top),p=Math.max(p,C.bottom),x=Math.min(x,C.left),a=Math.max(a,C.right),u=!0}}}return S(f),u?{top:h,bottom:p,left:x,right:a}:null}),r=16,d=o?{x:Math.max(0,o.left-r),y:Math.max(0,o.top-r),width:Math.min(o.right-o.left+r*2,800),height:Math.min(o.bottom-o.top+r*2,600)}:void 0,g=await n.screenshot({type:"png",...d?{clip:d}:{fullPage:!1}});return Buffer.from(g)}finally{await n.close()}}async function le(e,i,t,s){if(!await G())return null;let r=await(await ce()).newPage();try{await r.setCacheEnabled(!1),await r.setViewport({width:s?.width||800,height:s?.height||600,deviceScaleFactor:1});let d=s?.storyId||"",g=`${t}/iframe.html?viewMode=story&id=${d}&globals=`;await r.goto(g,{waitUntil:"load",timeout:15e3}),await r.waitForSelector("#storybook-root > *",{timeout:1e4}),await r.evaluate(m=>{let h=document.getElementById("storybook-root");h&&(h.innerHTML=m)},e),await r.evaluate(()=>document.fonts.ready),await new Promise(m=>setTimeout(m,500));let f=await r.evaluate(()=>{let m=document.querySelector("#storybook-root");if(!m)return null;let h=window.innerWidth;function p(u){let S=u.getBoundingClientRect();if(S.width===0||S.height===0)return null;if(S.width<h*.8&&S.height>0)return S;for(let b of Array.from(u.children)){let y=window.getComputedStyle(b);if(y.position==="fixed"||y.position==="absolute"||y.display==="none"||y.visibility==="hidden")continue;let w=p(b);if(w)return w}return null}let x=p(m);if(x)return{x:Math.max(0,x.x-8),y:Math.max(0,x.y-8),width:x.width+16,height:x.height+16};let a=m.firstElementChild;if(a){let u=a.getBoundingClientRect();return{x:u.x,y:u.y,width:u.width,height:u.height}}return null});if(!f)throw new Error("Could not determine component bounds from snapshot");let c=await r.screenshot({type:"png",clip:f});return Buffer.from(c)}finally{await r.close()}}async function k(){return G()}async function X(){$&&(await $.close(),$=null)}var q=null,A=null,ge=!1;async function rt(){if(!ge){ge=!0;try{let e=await Promise.resolve().then(()=>(he(),me));q=e.validateCodeForFile,A=e.formatValidationResult,l.debug("Code validator loaded - fix validation enabled")}catch{l.debug("Code validator not available - skipping fix validation")}}}var nt="UICOPILOT/APPLY_FIXES",ot="UICOPILOT/FIX_STARTED",at="UICOPILOT/FIX_COMPLETED",ct="UICOPILOT/FIX_FAILED",ye="UICOPILOT/ALL_FIXES_APPLIED",lt="UICOPILOT/RELOAD_REQUIRED",we="UICOPILOT/WORKSPACE_PATH",dt="UICOPILOT/REQUEST_WORKSPACE_PATH",ut="UICOPILOT/DISCOVER_COMPONENT_FILES",xe="UICOPILOT/COMPONENT_FILES_DISCOVERED";async function Se(e,i){let t=e.toLowerCase(),s=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),n=[`src/**/fui-${t}/fui-${t}.css`,`src/**/fui-${t}/*.css`,`src/**/${t}/${t}.css`,`src/**/${s}/${s}.css`,`src/**/*${t}*.css`,`src/**/*${s}*.css`,`styles/**/*${t}*.css`],o=[`src/**/fui-${t}/fui-${t}.tsx`,`src/**/fui-${t}/*.tsx`,`src/**/${t}/${t}.tsx`,`src/**/${s}/${s}.tsx`,`src/**/*${s}*.tsx`,`src/**/*${s}*.jsx`],r=[],d=[];for(let a of n)try{let u=await(0,J.glob)(a,{cwd:i,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**"]});u.length>0&&r.push(...u)}catch{}for(let a of o)try{let u=await(0,J.glob)(a,{cwd:i,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**","**/*.stories.*","**/*.test.*"]});u.length>0&&d.push(...u)}catch{}let g=[...new Set(r)],f=[...new Set(d)],c=a=>{if(a.length===0)return;let u=a.find(y=>y.includes(`/fui-${t}/`)&&y.endsWith(".css"));if(u)return u;let S=a.find(y=>y.toLowerCase().includes(`/${t}/${t}.css`)||y.includes(`/${s}/${s}.css`));if(S)return S;let b=a.find(y=>y.toLowerCase().endsWith(`/${t}.css`)||y.endsWith(`/${s}.css`));return b||a[0]},m=a=>{if(a.length===0)return;let u=a.filter(w=>!w.includes(".stories.")&&!w.includes(".test."));if(u.length===0)return a[0];let S=u.find(w=>w.includes(`/fui-${t}/`)&&(w.endsWith(".tsx")||w.endsWith(".jsx")));if(S)return S;let b=u.find(w=>w.toLowerCase().includes(`/${t}/${t}.tsx`)||w.includes(`/${s}/${s}.tsx`));if(b)return b;let y=u.find(w=>w.toLowerCase().endsWith(`/${t}.tsx`)||w.endsWith(`/${s}.tsx`));return y||u[0]},h=c(g),p=m(f),x=[...g,...f];return l.debug(`Discovered files for "${e}":`,{cssFile:h,componentFile:p,totalMatches:x.length}),{cssFile:h,componentFile:p,allMatches:[...new Set(x)]}}var pt=100;function ft(e){return new Promise(i=>setTimeout(i,e))}async function mt(e,i){if(await rt(),!q||!A)return l.debug(`Skipping validation (validator not available) for ${i}`),{valid:!0};let t=q(e,i);if(!t.valid){let s=t.errors.map(n=>n.message).join("; ");return l.warn(`Code validation failed for ${i}:`),console.warn(A(t)),{valid:!1,error:s}}return t.warnings.length>0&&(l.warn(`Code validation warnings for ${i}:`),console.warn(A(t))),l.debug(`Validation passed for ${i}`),{valid:!0}}var be=!1;function Ce(e){if(be)return e;be=!0;let i=process.cwd();return l.debug("Apply fixes initialized"),l.debug("Workspace:",i),e.emit(we,{path:i}),e.on(dt,()=>{l.debug("Workspace path requested by browser"),l.debug("Emitting workspace path response:",i),e.emit(we,{path:i})}),e.on(ut,async t=>{let{componentName:s,storyId:n}=t;l.debug(`Discovering files for component: ${s}`);try{let o=await Se(s,i);e.emit(xe,{componentName:s,storyId:n,...o,workspacePath:i})}catch(o){l.error("File discovery error:",o),e.emit(xe,{componentName:s,storyId:n,error:o.message,allMatches:[]})}}),e.on(nt,t=>{setTimeout(async()=>{try{let{issues:s,storybookRoot:n}=t,o=n||i;n?l.debug(`Using storybookRoot from API: ${n}`):l.debug(`Using process.cwd(): ${i}`),l.debug(`Received APPLY_FIXES for ${s.length} issue(s)`);let r=new Map;async function d(c){let m=c.targetFileType||"css",h=c.targetFilePath||c.generatedFix?.filePath,p="",x=c.title?.match(/^(\w+)\s/);if(x&&(p=x[1]),!p&&h){let S=h.match(/\/(\w+)\.(?:css|tsx|jsx)$/i);S&&(p=S[1])}if(!p)return l.debug(`Could not extract component name, using provided path: ${h}`),h||null;if(!r.has(p)){let S=await Se(p,o);r.set(p,S)}let a=r.get(p),u=m==="css"?a.cssFile:a.componentFile;return u?(l.debug(`Discovered ${m} path: ${u} (was: ${h})`),u):(l.debug(`No ${m} file discovered, using provided: ${h}`),h||null)}let g=[];for(let c of s){let{generatedFix:m}=c,h=c.targetFilePath||m?.filePath,p=await d(c)||h;l.debug("Processing issue:",{id:c.id,type:c.type,targetFileType:c.targetFileType||"css",targetPath:p,providedPath:h!==p?h:"(same)",codeLength:m?.code?.length||0}),e.emit(ot,{issueId:c.id});try{if(!m||!m.code||!p)throw new Error("Missing AI-generated fix data (code or filePath)");l.debug("Code to write (first 200 chars):",m.code.substring(0,200)),l.debug(`Code length: ${m.code.length} chars`);let x=await mt(m.code,p);if(!x.valid)throw new Error(`Code validation failed: ${x.error}. Fix was not applied to prevent breaking the file.`);let a=D.isAbsolute(p)?p:D.join(o,p);l.debug(`Writing to absolute path: ${a}`),await ve.writeFile(a,m.code,"utf-8"),await ft(pt);let u={success:!0,issueId:c.id,filePath:p,timestamp:new Date};e.emit(at,{issueId:c.id,result:u}),l.debug(`\u2713 Applied ${c.targetFileType||"css"} fix to: ${p}`),g.push(u)}catch(x){let a=x.message||"Unknown error";e.emit(ct,{issueId:c.id,error:a}),l.error(`\u2717 Error: ${a}`),g.push({success:!1,issueId:c.id,error:a,timestamp:new Date})}}let f={total:g.length,succeeded:g.filter(c=>c.success).length,failed:g.filter(c=>!c.success).length};e.emit(ye,{results:g,summary:f}),l.debug(`Completed: ${f.succeeded}/${f.total} fixes applied`),f.succeeded>0&&e.emit(lt,{message:"Fixes applied. If Storybook crashes due to HMR, please restart it.",filesChanged:g.filter(c=>c.success).map(c=>c.filePath)})}catch(s){l.error("Fatal error during fix application:",s),e.emit(ye,{results:[],summary:{total:t.issues?.length||0,succeeded:0,failed:t.issues?.length||0}})}},0)}),e}function Ie(e){let i=process.cwd();return e.plugins=e.plugins||[],e.plugins.push({name:"uicopilot-server-api",configureServer(t){t.middlewares.use("/__uicopilot/health",(o,r)=>{r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({ok:!0,workspacePath:i}))}),t.middlewares.use("/__uicopilot/screenshot",async(o,r)=>{try{if(!await k()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed. Run: npm install puppeteer"}));return}let f=new URL(o.url||"",`http://${o.headers.host}`).searchParams.get("storyId");if(!f){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing storyId parameter"}));return}let m=`http://${o.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${f}&globals=`;l.debug(`Taking screenshot: ${f}`);let h=await W(m,{selector:"#storybook-root > *"});if(!h){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p=h.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${p}`}))}catch(d){l.error("Screenshot error:",d.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:d.message}))}}),t.middlewares.use("/__uicopilot/capture",async(o,r)=>{try{if(!await k()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed"}));return}let f=new URL(o.url||"",`http://${o.headers.host}`).searchParams.get("storyId");if(!f){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing storyId parameter"}));return}let m=`http://${o.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${f}&globals=`;l.debug(`Full capture: ${f}`);let h=await W(m,{selector:"#storybook-root > *"});if(!h){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p;try{p=(await import("puppeteer")).default}catch{p=(await import("puppeteer-core")).default}let x=await p.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),a=await x.newPage();try{await a.setCacheEnabled(!1),await a.setViewport({width:800,height:600}),await a.goto(m,{waitUntil:"networkidle2",timeout:15e3}),await a.evaluate(()=>document.fonts.ready),await a.waitForSelector("#storybook-root > *",{timeout:1e4}),await a.evaluate(()=>new Promise(b=>{let y=setTimeout(b,5e3);try{let w=window.__STORYBOOK_ADDONS_CHANNEL__;if(w){let C=()=>{clearTimeout(y),w.off("storyRendered",C),setTimeout(b,100)};w.on("storyRendered",C)}else clearTimeout(y),setTimeout(b,300)}catch{clearTimeout(y),b()}}));let u=await a.evaluate(()=>{let b=document.querySelector("#storybook-root > *")||document.querySelector("#root > *"),y={};if(b){let v=window.getComputedStyle(b);for(let E=0;E<v.length;E++)y[v[E]]=v.getPropertyValue(v[E])}let w={backgroundColor:["transparent","rgba(0, 0, 0, 0)"],border:["none","0px none","0px none rgb(0, 0, 0)"],borderRadius:["0px"],boxShadow:["none"],opacity:["1"]};function C(v){return v.replace(/-([a-z])/g,(E,P)=>P.toUpperCase())}function K(v,E){if(E>4)return null;let P=v.tagName.toLowerCase();if(["script","style","link","meta","br","hr","noscript"].includes(P))return null;let H=v.className,V=typeof H=="string"?H:H?.baseVal||"",U=v.id||void 0,Te=v.getAttribute("role")||void 0,Q;for(let T of Array.from(v.childNodes))if(T.nodeType===3){let I=T.textContent?.trim();if(I){Q=I.length>50?I.substring(0,50)+"...":I;break}}let z=P;U?z=`${P}#${U}`:V&&(z=`${P}.${V.split(" ").filter(Boolean).join(".")}`);let Ee=window.getComputedStyle(v),Pe=["background-color","border","border-radius","box-shadow","opacity","fill","stroke","stroke-width","font-size","font-family","font-weight","line-height","letter-spacing","color","text-align","display","padding","margin","gap","flex-direction","justify-content","align-items","width","height"],j={};for(let T of Pe){let I=Ee.getPropertyValue(T),L=C(T);I&&!w[L]?.includes(I)&&(j[L]=I)}if(P==="svg"||v.closest("svg"))for(let T of["fill","stroke","stroke-width","viewBox","d","r","cx","cy"]){let I=v.getAttribute(T);I&&(j[C(T)]=I)}let Z=[];for(let T of Array.from(v.children)){let I=window.getComputedStyle(T);if(I.display==="none"||I.visibility==="hidden")continue;let L=K(T,E+1);L&&Z.push(L)}return{selector:z,tagName:P,className:V,id:U,role:Te,textContent:Q,styles:j,children:Z}}return{computedStyles:y,domTree:b?K(b,0):null}}),S=h.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${S}`,computedStyles:u.computedStyles,domTree:u.domTree}))}finally{await a.close(),await x.close()}}catch(d){l.error("Capture error:",d.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:d.message}))}}),t.middlewares.use("/__uicopilot/screenshot-snapshot",async(o,r)=>{if(o.method!=="POST"){r.writeHead(405,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"POST required"}));return}try{if(!await k()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed"}));return}let g=[];for await(let S of o)g.push(typeof S=="string"?Buffer.from(S):S);let f=JSON.parse(Buffer.concat(g).toString()),{html:c,stylesheetUrls:m,storyId:h}=f;if(!c){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing html in body"}));return}let x=`http://${o.headers.host||"localhost:6006"}`;l.debug(`Taking snapshot screenshot for ${h||"unknown"}`);let a=await le(c,m||[],x,{storyId:h});if(!a){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Snapshot screenshot failed"}));return}let u=a.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${u}`}))}catch(d){l.error("Snapshot screenshot error:",d.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:d.message}))}}),t.httpServer?.on("close",()=>{X().catch(()=>{})});let s=o=>{X().catch(()=>{}).finally(()=>{process.kill(process.pid,o)})},n=globalThis;n.__uicopilotShutdownRegistered||(n.__uicopilotShutdownRegistered=!0,process.once("SIGINT",()=>s("SIGINT")),process.once("SIGTERM",()=>s("SIGTERM")))}}),e}var O={},ht=()=>{if(typeof O<"u"&&O.url){let e=(0,Y.fileURLToPath)(O.url),i=(0,_.dirname)(e);return(0,_.join)(i,"manager.mjs")}return(0,_.join)(__dirname,"manager.mjs")},gt=()=>{if(typeof O<"u"&&O.url){let e=(0,Y.fileURLToPath)(O.url),i=(0,_.dirname)(e);return(0,_.join)(i,"preview.mjs")}return(0,_.join)(__dirname,"preview.mjs")};function yt(e=[]){return[...e,ht()]}function wt(e=[]){return[...e,gt()]}0&&(module.exports={experimental_serverChannel,managerEntries,previewAnnotations,viteFinal});
package/dist/preset.mjs CHANGED
@@ -1,3 +1,3 @@
1
- var pe=Object.defineProperty;var fe=(e,r)=>()=>(e&&(r=e(e=0)),r);var he=(e,r)=>{for(var t in r)pe(e,t,{get:r[t],enumerable:!0})};var z={};he(z,{detectFileType:()=>G,formatValidationResult:()=>Ee,isValidCode:()=>Te,validateCode:()=>K,validateCodeForFile:()=>q});function Ce(e,r={}){let t=r.minLength??we;return e.length<t?{code:"CODE_TOO_SHORT",message:`Code is too short (${e.length} chars). Minimum: ${t}. Likely incomplete or a snippet.`,severity:"error"}:null}function Se(e){let r=[/^[+-]{3}\s+[ab]\//m,/^@@\s+-\d+,\d+\s+\+\d+,\d+\s+@@/m,/^diff --git/m,/^index [a-f0-9]+\.\.[a-f0-9]+/m];for(let t of r)if(t.test(e))return{code:"CODE_IS_DIFF",message:"Code appears to be a diff/patch format, not complete file content.",severity:"error"};return null}function Ie(e){let r=e.split(`
2
- `).filter(s=>s.trim()),t=r.filter(s=>s.trim().startsWith("//")||s.trim().startsWith("/*")||s.trim().startsWith("*")||s.trim().startsWith("#"));if(r.length>0&&t.length/r.length>.8)return{code:"CODE_IS_INSTRUCTIONS",message:"Code appears to be mostly comments/instructions, not actual implementation.",severity:"error"};let o=[/^\/\/\s*(Change|Replace|Update|Modify|Add|Remove|Delete)\s+(from|to|this|the)/im,/^\/\/\s*To:/m,/^\/\/\s*From:/m];for(let s of o)if(s.test(e))return{code:"CODE_IS_INSTRUCTIONS",message:'Code contains instruction comments (e.g., "// Change from:" / "// To:") instead of actual code.',severity:"error"};return null}function be(e){let r={"{":"}","[":"]","(":")"},t=[],o=!1,s="",c=!1;for(let h=0;h<e.length;h++){let i=e[h],u=e[h-1];if((i==='"'||i==="'"||i==="`")&&u!=="\\"){o?i===s&&(o=!1,c=!1):(o=!0,s=i,i==="`"&&(c=!0));continue}if(!o){if(r[i])t.push(r[i]);else if(Object.values(r).includes(i)&&t.pop()!==i)return{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets detected. Found unexpected '${i}'.`,severity:"warning"}}}return t.length>0?{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets. Missing: ${t.reverse().join("")}`,severity:"warning"}:null}function Y(e,r={}){let t=[],o=[];e.includes("import ")||t.push({code:"TSX_MISSING_IMPORTS",message:"Component file missing import statements. A complete file must have imports.",severity:"error"}),e.includes("export ")||t.push({code:"TSX_MISSING_EXPORTS",message:"Component file missing exports. A complete file must export something.",severity:"error"});let s=/import\s+(?:React|\{[^}]*\})\s+from\s+['"]react['"]/.test(e);/<[A-Z][a-zA-Z]*|<[a-z]+[\s/>]/.test(e)&&!s&&o.push({code:"TSX_NO_REACT_IMPORT",message:"JSX detected but no React import. OK for React 17+ with automatic runtime.",severity:"warning"}),/export\s+(default\s+)?function\s+\w+/.test(e)||/export\s+(const|let)\s+\w+\s*[:=]/.test(e)||/export\s+default\s+\w+/.test(e)||/export\s+\{[^}]+\}/.test(e)||o.push({code:"TSX_NO_COMPONENT_DEF",message:"No clear component definition found. Expected function or const export.",severity:"warning"});let i=[{pattern:/\.\.\.\s*$/,message:'Code ends with "..." - likely truncated'},{pattern:/\/\/\s*\.\.\./m,message:'Contains "// ..." - likely incomplete'},{pattern:/{\s*\/\*\s*\.\.\.\s*\*\/\s*}/m,message:'Contains "{/* ... */}" placeholder'}];for(let{pattern:u,message:f}of i)u.test(e)&&t.push({code:"TSX_INCOMPLETE",message:f,severity:"error"});return{errors:t,warnings:o}}function ve(e,r={}){let t=[],o=[];(e.includes("import ")||e.includes("export "))&&t.push({code:"CSS_HAS_JS_CODE",message:"CSS file contains JavaScript import/export statements. Wrong file type.",severity:"error"}),/[.#\w\[\]]+\s*\{[\s\S]*?:\s*[^;]+;?[\s\S]*?\}/.test(e)||t.push({code:"CSS_INVALID_SYNTAX",message:"No valid CSS syntax found. Expected selector { property: value; } pattern.",severity:"error"});let c=(e.match(/\{[^}]+\}/g)||[]).length;return c===0&&t.push({code:"CSS_NO_RULES",message:"No CSS rules found. File appears empty or malformed.",severity:"error"}),(e.includes("/* ... */")||e.includes("// ..."))&&t.push({code:"CSS_INCOMPLETE",message:"CSS contains placeholder comments (/* ... */) - likely incomplete.",severity:"error"}),c>0&&c<3&&!r.allowPartial&&o.push({code:"CSS_FEW_RULES",message:`Only ${c} CSS rule(s) found. Might be incomplete.`,severity:"warning"}),{errors:t,warnings:o}}function Oe(e,r={}){let t=[],o=[];return e.includes("import ")||t.push({code:"STORIES_MISSING_IMPORTS",message:"Stories file missing import statements.",severity:"error"}),/@storybook\//.test(e)||t.push({code:"STORIES_NO_STORYBOOK_IMPORT",message:"Stories file must import from @storybook/* (e.g., @storybook/react).",severity:"error"}),e.includes("Meta")||e.includes("ComponentMeta")||o.push({code:"STORIES_NO_META_TYPE",message:"Stories file should have Meta type import for type safety.",severity:"warning"}),e.includes("StoryObj")||e.includes("ComponentStory")||e.includes("Story")||o.push({code:"STORIES_NO_STORY_TYPE",message:"Stories file should have StoryObj/Story type for type safety.",severity:"warning"}),e.includes("export default")||t.push({code:"STORIES_NO_DEFAULT_EXPORT",message:"Stories file must have a default export (meta configuration).",severity:"error"}),/export\s+const\s+\w+\s*[:=]/.test(e)||t.push({code:"STORIES_NO_STORY_EXPORTS",message:"Stories file must have at least one named export (story definition).",severity:"error"}),/import\s+\{?\s*\w+\s*\}?\s+from\s+['"]\.\//.test(e)||o.push({code:"STORIES_NO_COMPONENT_IMPORT",message:"Stories file should import the component being documented.",severity:"warning"}),(e.includes("// ... other")||e.includes("/* ... */"))&&t.push({code:"STORIES_INCOMPLETE",message:"Stories file contains placeholder comments - likely incomplete.",severity:"error"}),{errors:t,warnings:o}}function G(e){let r=e.toLowerCase();if(r.includes(".stories."))return"stories";switch(r.split(".").pop()){case"tsx":return"tsx";case"jsx":return"jsx";case"ts":return"ts";case"js":return"js";case"css":return"css";case"scss":return"scss";case"less":return"less";default:return"unknown"}}function K(e,r,t={}){let o={valid:!0,fileType:r,errors:[],warnings:[]},s=Ce(e,t);s&&o.errors.push(s);let c=Se(e);c&&o.errors.push(c);let h=Ie(e);h&&o.errors.push(h);let i=be(e);switch(i&&(t.strict?o.errors.push({...i,severity:"error"}):o.warnings.push(i)),r){case"stories":{let{errors:u,warnings:f}=Oe(e,t);o.errors.push(...u),o.warnings.push(...f);break}case"tsx":case"jsx":{let{errors:u,warnings:f}=Y(e,t);o.errors.push(...u),o.warnings.push(...f);break}case"css":case"scss":case"less":{let{errors:u,warnings:f}=ve(e,t);o.errors.push(...u),o.warnings.push(...f);break}case"ts":case"js":{let{errors:u,warnings:f}=Y(e,t);o.errors.push(...u),o.warnings.push(...f.filter(n=>!n.code.includes("JSX")));break}default:break}return o.valid=o.errors.length===0,o}function q(e,r,t={}){let o=G(r);return K(e,o,t)}function Te(e,r,t={}){return q(e,r,t).valid}function Ee(e){if(e.valid&&e.warnings.length===0)return`\u2713 Valid ${e.fileType} code`;let r=[];if(e.valid)r.push(`\u26A0 Valid ${e.fileType} code with warnings`);else{r.push(`\u2717 Invalid ${e.fileType} code`),r.push(""),r.push("Errors:");for(let t of e.errors)r.push(` - [${t.code}] ${t.message}`)}if(e.warnings.length>0){r.push(""),r.push("Warnings:");for(let t of e.warnings)r.push(` - [${t.code}] ${t.message}`)}return r.join(`
3
- `)}var we,Q=fe(()=>{"use strict";we=50});import{dirname as ae,join as R}from"path";import{fileURLToPath as le}from"url";import*as ie from"fs/promises";import*as F from"path";import{glob as Z}from"glob";import{existsSync as ge}from"fs";import{createRequire as me}from"module";var _=null,E=null,W=!1;async function A(){if(W)return!!_;if(W=!0,process.env.STORYBOOK_UICOPILOT_NO_PUPPETEER==="true")return console.log("[UI Copilot] Puppeteer disabled via STORYBOOK_UICOPILOT_NO_PUPPETEER flag"),!1;let e=me(process.cwd()+"/");try{return _=e("puppeteer"),console.log("[UI Copilot] Puppeteer loaded \u2014 server-side screenshots enabled"),!0}catch{}try{return _=e("puppeteer-core"),console.log("[UI Copilot] puppeteer-core loaded \u2014 server-side screenshots enabled"),!0}catch{}return console.log("[UI Copilot] Puppeteer not found \u2014 install puppeteer for pixel-perfect screenshots"),!1}function ye(){let e=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary","/Applications/Chromium.app/Contents/MacOS/Chromium","/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium"];for(let r of e)if(ge(r))return r}async function J(){if(E&&E.connected)return E;let e=ye(),r={headless:!0,args:["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage"],...e?{executablePath:e}:{}};return E=await _.launch(r),console.log("[UI Copilot] Headless Chrome launched for screenshots"),E}async function D(e,r){if(!await A())return null;let s=await(await J()).newPage();try{await s.setCacheEnabled(!1),await s.setViewport({width:r?.width||800,height:r?.height||600,deviceScaleFactor:1}),await s.goto(e,{waitUntil:"networkidle2",timeout:15e3}),await s.evaluate(()=>document.fonts.ready),await s.waitForSelector("#storybook-root > *",{timeout:1e4}),await s.waitForFunction(()=>new Promise(i=>{let u=document.querySelectorAll("style").length,f=0,n=()=>{let p=document.querySelectorAll("style").length;if(p===u){if(f++,f>=3){i(!0);return}}else f=0,u=p;setTimeout(n,100)};setTimeout(n,200)}),{timeout:5e3}).catch(()=>{}),await new Promise(i=>setTimeout(i,500));let c=await s.evaluate(()=>{let i=document.querySelector("#storybook-root");if(!i)return null;let u=window.innerWidth;function f(g){let a=g.getBoundingClientRect();if(a.width===0||a.height===0)return null;if(a.width<u*.8&&a.height>0)return a;for(let m of Array.from(g.children)){let d=window.getComputedStyle(m);if(d.position==="fixed"||d.position==="absolute"||d.display==="none"||d.visibility==="hidden")continue;let l=f(m);if(l)return l}return null}let n=f(i);if(n)return{x:Math.max(0,n.x-8),y:Math.max(0,n.y-8),width:n.width+16,height:n.height+16};let p=i.firstElementChild;if(p){let g=p.getBoundingClientRect();return{x:g.x,y:g.y,width:g.width,height:g.height}}return null});if(!c)throw new Error("Could not determine component bounds");let h=await s.screenshot({type:"png",clip:c});return Buffer.from(h)}finally{await s.close()}}async function X(e,r,t,o){if(!await A())return null;let h=await(await J()).newPage();try{await h.setCacheEnabled(!1),await h.setViewport({width:o?.width||800,height:o?.height||600,deviceScaleFactor:1});let i=o?.storyId||"",u=`${t}/iframe.html?viewMode=story&id=${i}&globals=`;await h.goto(u,{waitUntil:"load",timeout:15e3}),await h.waitForSelector("#storybook-root > *",{timeout:1e4}),await h.evaluate(p=>{let g=document.getElementById("storybook-root");g&&(g.innerHTML=p)},e),await h.evaluate(()=>document.fonts.ready),await new Promise(p=>setTimeout(p,500));let f=await h.evaluate(()=>{let p=document.querySelector("#storybook-root");if(!p)return null;let g=window.innerWidth;function a(l){let y=l.getBoundingClientRect();if(y.width===0||y.height===0)return null;if(y.width<g*.8&&y.height>0)return y;for(let v of Array.from(l.children)){let w=window.getComputedStyle(v);if(w.position==="fixed"||w.position==="absolute"||w.display==="none"||w.visibility==="hidden")continue;let C=a(v);if(C)return C}return null}let m=a(p);if(m)return{x:Math.max(0,m.x-8),y:Math.max(0,m.y-8),width:m.width+16,height:m.height+16};let d=p.firstElementChild;if(d){let l=d.getBoundingClientRect();return{x:l.x,y:l.y,width:l.width,height:l.height}}return null});if(!f)throw new Error("Could not determine component bounds from snapshot");let n=await h.screenshot({type:"png",clip:f});return Buffer.from(n)}finally{await h.close()}}async function x(){return A()}async function V(){E&&(await E.close(),E=null)}var j=null,$=null,ee=!1;async function Pe(){if(!ee){ee=!0;try{let e=await Promise.resolve().then(()=>(Q(),z));j=e.validateCodeForFile,$=e.formatValidationResult,console.log("[UI Copilot] Code validator loaded - fix validation enabled")}catch{console.log("[UI Copilot] Code validator not available - skipping fix validation")}}}var _e="UICOPILOT/APPLY_FIXES",xe="UICOPILOT/FIX_STARTED",$e="UICOPILOT/FIX_COMPLETED",Fe="UICOPILOT/FIX_FAILED",te="UICOPILOT/ALL_FIXES_APPLIED",Re="UICOPILOT/RELOAD_REQUIRED",oe="UICOPILOT/WORKSPACE_PATH",Ue="UICOPILOT/REQUEST_WORKSPACE_PATH",Ne="UICOPILOT/DISCOVER_COMPONENT_FILES",se="UICOPILOT/COMPONENT_FILES_DISCOVERED";async function re(e,r){let t=e.toLowerCase(),o=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),s=[`src/**/fui-${t}/fui-${t}.css`,`src/**/fui-${t}/*.css`,`src/**/${t}/${t}.css`,`src/**/${o}/${o}.css`,`src/**/*${t}*.css`,`src/**/*${o}*.css`,`styles/**/*${t}*.css`],c=[`src/**/fui-${t}/fui-${t}.tsx`,`src/**/fui-${t}/*.tsx`,`src/**/${t}/${t}.tsx`,`src/**/${o}/${o}.tsx`,`src/**/*${o}*.tsx`,`src/**/*${o}*.jsx`],h=[],i=[];for(let d of s)try{let l=await Z(d,{cwd:r,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**"]});l.length>0&&h.push(...l)}catch{}for(let d of c)try{let l=await Z(d,{cwd:r,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**","**/*.stories.*","**/*.test.*"]});l.length>0&&i.push(...l)}catch{}let u=[...new Set(h)],f=[...new Set(i)],n=d=>{if(d.length===0)return;let l=d.find(w=>w.includes(`/fui-${t}/`)&&w.endsWith(".css"));if(l)return l;let y=d.find(w=>w.toLowerCase().includes(`/${t}/${t}.css`)||w.includes(`/${o}/${o}.css`));if(y)return y;let v=d.find(w=>w.toLowerCase().endsWith(`/${t}.css`)||w.endsWith(`/${o}.css`));return v||d[0]},p=d=>{if(d.length===0)return;let l=d.filter(C=>!C.includes(".stories.")&&!C.includes(".test."));if(l.length===0)return d[0];let y=l.find(C=>C.includes(`/fui-${t}/`)&&(C.endsWith(".tsx")||C.endsWith(".jsx")));if(y)return y;let v=l.find(C=>C.toLowerCase().includes(`/${t}/${t}.tsx`)||C.includes(`/${o}/${o}.tsx`));if(v)return v;let w=l.find(C=>C.toLowerCase().endsWith(`/${t}.tsx`)||C.endsWith(`/${o}.tsx`));return w||l[0]},g=n(u),a=p(f),m=[...u,...f];return console.log(`[UI Copilot] Discovered files for "${e}":`,{cssFile:g,componentFile:a,totalMatches:m.length}),{cssFile:g,componentFile:a,allMatches:[...new Set(m)]}}var Me=100;function Le(e){return new Promise(r=>setTimeout(r,e))}async function ke(e,r){if(await Pe(),!j||!$)return console.log(`[UI Copilot] Skipping validation (validator not available) for ${r}`),{valid:!0};let t=j(e,r);if(!t.valid){let o=t.errors.map(s=>s.message).join("; ");return console.warn(`[UI Copilot] Code validation failed for ${r}:`),console.warn($(t)),{valid:!1,error:o}}return t.warnings.length>0&&(console.warn(`[UI Copilot] Code validation warnings for ${r}:`),console.warn($(t))),console.log(`[UI Copilot] Validation passed for ${r}`),{valid:!0}}var ne=!1;function Ae(e){if(ne)return e;ne=!0;let r=process.cwd();return console.log("[UI Copilot] Apply fixes initialized"),console.log("[UI Copilot] Workspace:",r),e.emit(oe,{path:r}),e.on(Ue,()=>{console.log("[UI Copilot] Workspace path requested by browser"),console.log("[UI Copilot] Emitting workspace path response:",r),e.emit(oe,{path:r})}),e.on(Ne,async t=>{let{componentName:o,storyId:s}=t;console.log(`[UI Copilot] Discovering files for component: ${o}`);try{let c=await re(o,r);e.emit(se,{componentName:o,storyId:s,...c,workspacePath:r})}catch(c){console.error("[UI Copilot] File discovery error:",c),e.emit(se,{componentName:o,storyId:s,error:c.message,allMatches:[]})}}),e.on(_e,t=>{setTimeout(async()=>{try{let{issues:o,storybookRoot:s}=t,c=s||r;console.log(s?`[UI Copilot] Using storybookRoot from API: ${s}`:`[UI Copilot] Using process.cwd(): ${r}`),console.log(`[UI Copilot] Received APPLY_FIXES for ${o.length} issue(s)`);let h=new Map;async function i(n){let p=n.targetFileType||"css",g=n.targetFilePath||n.generatedFix?.filePath,a="",m=n.title?.match(/^(\w+)\s/);if(m&&(a=m[1]),!a&&g){let y=g.match(/\/(\w+)\.(?:css|tsx|jsx)$/i);y&&(a=y[1])}if(!a)return console.log(`[UI Copilot] Could not extract component name, using provided path: ${g}`),g||null;if(!h.has(a)){let y=await re(a,c);h.set(a,y)}let d=h.get(a),l=p==="css"?d.cssFile:d.componentFile;return l?(console.log(`[UI Copilot] Discovered ${p} path: ${l} (was: ${g})`),l):(console.log(`[UI Copilot] No ${p} file discovered, using provided: ${g}`),g||null)}let u=[];for(let n of o){let{generatedFix:p}=n,g=n.targetFilePath||p?.filePath,a=await i(n)||g;console.log("[UI Copilot] Processing issue:",{id:n.id,type:n.type,targetFileType:n.targetFileType||"css",targetPath:a,providedPath:g!==a?g:"(same)",codeLength:p?.code?.length||0}),e.emit(xe,{issueId:n.id});try{if(!p||!p.code||!a)throw new Error("Missing AI-generated fix data (code or filePath)");console.log("[UI Copilot] Code to write (first 200 chars):",p.code.substring(0,200)),console.log(`[UI Copilot] Code length: ${p.code.length} chars`);let m=await ke(p.code,a);if(!m.valid)throw new Error(`Code validation failed: ${m.error}. Fix was not applied to prevent breaking the file.`);let d=F.isAbsolute(a)?a:F.join(c,a);console.log(`[UI Copilot] Writing to absolute path: ${d}`),await ie.writeFile(d,p.code,"utf-8"),await Le(Me);let l={success:!0,issueId:n.id,filePath:a,timestamp:new Date};e.emit($e,{issueId:n.id,result:l}),console.log(`[UI Copilot] \u2713 Applied ${n.targetFileType||"css"} fix to: ${a}`),u.push(l)}catch(m){let d=m.message||"Unknown error";e.emit(Fe,{issueId:n.id,error:d}),console.error(`[UI Copilot] \u2717 Error: ${d}`),u.push({success:!1,issueId:n.id,error:d,timestamp:new Date})}}let f={total:u.length,succeeded:u.filter(n=>n.success).length,failed:u.filter(n=>!n.success).length};e.emit(te,{results:u,summary:f}),console.log(`[UI Copilot] Completed: ${f.succeeded}/${f.total} fixes applied`),f.succeeded>0&&e.emit(Re,{message:"Fixes applied. If Storybook crashes due to HMR, please restart it.",filesChanged:u.filter(n=>n.success).map(n=>n.filePath)})}catch(o){console.error("[UI Copilot] Fatal error during fix application:",o),e.emit(te,{results:[],summary:{total:t.issues?.length||0,succeeded:0,failed:t.issues?.length||0}})}},0)}),e}function De(e){let r=process.cwd();return e.plugins=e.plugins||[],e.plugins.push({name:"uicopilot-server-api",configureServer(t){t.middlewares.use("/__uicopilot/health",(o,s)=>{s.writeHead(200,{"Content-Type":"application/json"}),s.end(JSON.stringify({ok:!0,workspacePath:r}))}),t.middlewares.use("/__uicopilot/screenshot",async(o,s)=>{try{if(!await x()){s.writeHead(501,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Puppeteer not installed. Run: npm install puppeteer"}));return}let i=new URL(o.url||"",`http://${o.headers.host}`).searchParams.get("storyId");if(!i){s.writeHead(400,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Missing storyId parameter"}));return}let f=`http://${o.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${i}&globals=`;console.log(`[UI Copilot] Taking screenshot: ${i}`);let n=await D(f,{selector:"#storybook-root > *"});if(!n){s.writeHead(500,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p=n.toString("base64");s.writeHead(200,{"Content-Type":"application/json"}),s.end(JSON.stringify({screenshot:`data:image/png;base64,${p}`}))}catch(c){console.error("[UI Copilot] Screenshot error:",c.message),s.writeHead(500,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:c.message}))}}),t.middlewares.use("/__uicopilot/capture",async(o,s)=>{try{if(!await x()){s.writeHead(501,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Puppeteer not installed"}));return}let i=new URL(o.url||"",`http://${o.headers.host}`).searchParams.get("storyId");if(!i){s.writeHead(400,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Missing storyId parameter"}));return}let f=`http://${o.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${i}&globals=`;console.log(`[UI Copilot] Full capture: ${i}`);let n=await D(f,{selector:"#storybook-root > *"});if(!n){s.writeHead(500,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p;try{p=(await import("puppeteer")).default}catch{p=(await import("puppeteer-core")).default}let g=await p.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),a=await g.newPage();try{await a.setCacheEnabled(!1),await a.setViewport({width:800,height:600}),await a.goto(f,{waitUntil:"networkidle2",timeout:15e3}),await a.evaluate(()=>document.fonts.ready),await a.waitForSelector("#storybook-root > *",{timeout:1e4});let m=await a.evaluate(()=>{let l=document.querySelector("#storybook-root > *")||document.querySelector("#root > *"),y={};if(l){let S=window.getComputedStyle(l);for(let O=0;O<S.length;O++)y[S[O]]=S.getPropertyValue(S[O])}let v={backgroundColor:["transparent","rgba(0, 0, 0, 0)"],border:["none","0px none","0px none rgb(0, 0, 0)"],borderRadius:["0px"],boxShadow:["none"],opacity:["1"]};function w(S){return S.replace(/-([a-z])/g,(O,T)=>T.toUpperCase())}function C(S,O){if(O>4)return null;let T=S.tagName.toLowerCase();if(["script","style","link","meta","br","hr","noscript"].includes(T))return null;let U=S.className,N=typeof U=="string"?U:U?.baseVal||"",M=S.id||void 0,ce=S.getAttribute("role")||void 0,B;for(let b of Array.from(S.childNodes))if(b.nodeType===3){let I=b.textContent?.trim();if(I){B=I.length>50?I.substring(0,50)+"...":I;break}}let L=T;M?L=`${T}#${M}`:N&&(L=`${T}.${N.split(" ").filter(Boolean).join(".")}`);let de=window.getComputedStyle(S),ue=["background-color","border","border-radius","box-shadow","opacity","fill","stroke","stroke-width","font-size","font-family","font-weight","line-height","letter-spacing","color","text-align","display","padding","margin","gap","flex-direction","justify-content","align-items","width","height"],k={};for(let b of ue){let I=de.getPropertyValue(b),P=w(b);I&&!v[P]?.includes(I)&&(k[P]=I)}if(T==="svg"||S.closest("svg"))for(let b of["fill","stroke","stroke-width","viewBox","d","r","cx","cy"]){let I=S.getAttribute(b);I&&(k[w(b)]=I)}let H=[];for(let b of Array.from(S.children)){let I=window.getComputedStyle(b);if(I.display==="none"||I.visibility==="hidden")continue;let P=C(b,O+1);P&&H.push(P)}return{selector:L,tagName:T,className:N,id:M,role:ce,textContent:B,styles:k,children:H}}return{computedStyles:y,domTree:l?C(l,0):null}}),d=n.toString("base64");s.writeHead(200,{"Content-Type":"application/json"}),s.end(JSON.stringify({screenshot:`data:image/png;base64,${d}`,computedStyles:m.computedStyles,domTree:m.domTree}))}finally{await a.close(),await g.close()}}catch(c){console.error("[UI Copilot] Capture error:",c.message),s.writeHead(500,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:c.message}))}}),t.middlewares.use("/__uicopilot/screenshot-snapshot",async(o,s)=>{if(o.method!=="POST"){s.writeHead(405,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"POST required"}));return}try{if(!await x()){s.writeHead(501,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Puppeteer not installed"}));return}let h=[];for await(let d of o)h.push(typeof d=="string"?Buffer.from(d):d);let i=JSON.parse(Buffer.concat(h).toString()),{html:u,stylesheetUrls:f,storyId:n}=i;if(!u){s.writeHead(400,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Missing html in body"}));return}let g=`http://${o.headers.host||"localhost:6006"}`;console.log(`[UI Copilot] Taking snapshot screenshot for ${n||"unknown"}`);let a=await X(u,f||[],g,{storyId:n});if(!a){s.writeHead(500,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:"Snapshot screenshot failed"}));return}let m=a.toString("base64");s.writeHead(200,{"Content-Type":"application/json"}),s.end(JSON.stringify({screenshot:`data:image/png;base64,${m}`}))}catch(c){console.error("[UI Copilot] Snapshot screenshot error:",c.message),s.writeHead(500,{"Content-Type":"application/json"}),s.end(JSON.stringify({error:c.message}))}}),t.httpServer?.on("close",()=>{V().catch(()=>{})})}}),e}var je=()=>{if(typeof import.meta<"u"&&import.meta.url){let e=le(import.meta.url),r=ae(e);return R(r,"manager.mjs")}return R(__dirname,"manager.mjs")},Be=()=>{if(typeof import.meta<"u"&&import.meta.url){let e=le(import.meta.url),r=ae(e);return R(r,"preview.mjs")}return R(__dirname,"preview.mjs")};function ze(e=[]){return[...e,je()]}function Qe(e=[]){return[...e,Be()]}export{Ae as experimental_serverChannel,ze as managerEntries,Qe as previewAnnotations,De as viteFinal};
1
+ var Se=Object.defineProperty;var be=(e,i)=>()=>(e&&(i=e(e=0)),i);var ve=(e,i)=>{for(var t in i)Se(e,t,{get:i[t],enumerable:!0})};var ne={};ve(ne,{detectFileType:()=>ie,formatValidationResult:()=>Xe,isValidCode:()=>We,validateCode:()=>se,validateCodeForFile:()=>re});function Ve(e,i={}){let t=i.minLength??He;return e.length<t?{code:"CODE_TOO_SHORT",message:`Code is too short (${e.length} chars). Minimum: ${t}. Likely incomplete or a snippet.`,severity:"error"}:null}function Ue(e){let i=[/^[+-]{3}\s+[ab]\//m,/^@@\s+-\d+,\d+\s+\+\d+,\d+\s+@@/m,/^diff --git/m,/^index [a-f0-9]+\.\.[a-f0-9]+/m];for(let t of i)if(t.test(e))return{code:"CODE_IS_DIFF",message:"Code appears to be a diff/patch format, not complete file content.",severity:"error"};return null}function ze(e){let i=e.split(`
2
+ `).filter(o=>o.trim()),t=i.filter(o=>o.trim().startsWith("//")||o.trim().startsWith("/*")||o.trim().startsWith("*")||o.trim().startsWith("#"));if(i.length>0&&t.length/i.length>.8)return{code:"CODE_IS_INSTRUCTIONS",message:"Code appears to be mostly comments/instructions, not actual implementation.",severity:"error"};let s=[/^\/\/\s*(Change|Replace|Update|Modify|Add|Remove|Delete)\s+(from|to|this|the)/im,/^\/\/\s*To:/m,/^\/\/\s*From:/m];for(let o of s)if(o.test(e))return{code:"CODE_IS_INSTRUCTIONS",message:'Code contains instruction comments (e.g., "// Change from:" / "// To:") instead of actual code.',severity:"error"};return null}function je(e){let i={"{":"}","[":"]","(":")"},t=[],s=!1,o="",n=!1;for(let r=0;r<e.length;r++){let d=e[r],g=e[r-1];if((d==='"'||d==="'"||d==="`")&&g!=="\\"){s?d===o&&(s=!1,n=!1):(s=!0,o=d,d==="`"&&(n=!0));continue}if(!s){if(i[d])t.push(i[d]);else if(Object.values(i).includes(d)&&t.pop()!==d)return{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets detected. Found unexpected '${d}'.`,severity:"warning"}}}return t.length>0?{code:"UNBALANCED_BRACES",message:`Unbalanced braces/brackets. Missing: ${t.reverse().join("")}`,severity:"warning"}:null}function te(e,i={}){let t=[],s=[];e.includes("import ")||t.push({code:"TSX_MISSING_IMPORTS",message:"Component file missing import statements. A complete file must have imports.",severity:"error"}),e.includes("export ")||t.push({code:"TSX_MISSING_EXPORTS",message:"Component file missing exports. A complete file must export something.",severity:"error"});let o=/import\s+(?:React|\{[^}]*\})\s+from\s+['"]react['"]/.test(e);/<[A-Z][a-zA-Z]*|<[a-z]+[\s/>]/.test(e)&&!o&&s.push({code:"TSX_NO_REACT_IMPORT",message:"JSX detected but no React import. OK for React 17+ with automatic runtime.",severity:"warning"}),/export\s+(default\s+)?function\s+\w+/.test(e)||/export\s+(const|let)\s+\w+\s*[:=]/.test(e)||/export\s+default\s+\w+/.test(e)||/export\s+\{[^}]+\}/.test(e)||s.push({code:"TSX_NO_COMPONENT_DEF",message:"No clear component definition found. Expected function or const export.",severity:"warning"});let d=[{pattern:/\.\.\.\s*$/,message:'Code ends with "..." - likely truncated'},{pattern:/\/\/\s*\.\.\./m,message:'Contains "// ..." - likely incomplete'},{pattern:/{\s*\/\*\s*\.\.\.\s*\*\/\s*}/m,message:'Contains "{/* ... */}" placeholder'}];for(let{pattern:g,message:f}of d)g.test(e)&&t.push({code:"TSX_INCOMPLETE",message:f,severity:"error"});return{errors:t,warnings:s}}function Be(e,i={}){let t=[],s=[];(e.includes("import ")||e.includes("export "))&&t.push({code:"CSS_HAS_JS_CODE",message:"CSS file contains JavaScript import/export statements. Wrong file type.",severity:"error"}),/[.#\w\[\]]+\s*\{[\s\S]*?:\s*[^;]+;?[\s\S]*?\}/.test(e)||t.push({code:"CSS_INVALID_SYNTAX",message:"No valid CSS syntax found. Expected selector { property: value; } pattern.",severity:"error"});let n=(e.match(/\{[^}]+\}/g)||[]).length;return n===0&&t.push({code:"CSS_NO_RULES",message:"No CSS rules found. File appears empty or malformed.",severity:"error"}),(e.includes("/* ... */")||e.includes("// ..."))&&t.push({code:"CSS_INCOMPLETE",message:"CSS contains placeholder comments (/* ... */) - likely incomplete.",severity:"error"}),n>0&&n<3&&!i.allowPartial&&s.push({code:"CSS_FEW_RULES",message:`Only ${n} CSS rule(s) found. Might be incomplete.`,severity:"warning"}),{errors:t,warnings:s}}function Ge(e,i={}){let t=[],s=[];return e.includes("import ")||t.push({code:"STORIES_MISSING_IMPORTS",message:"Stories file missing import statements.",severity:"error"}),/@storybook\//.test(e)||t.push({code:"STORIES_NO_STORYBOOK_IMPORT",message:"Stories file must import from @storybook/* (e.g., @storybook/react).",severity:"error"}),e.includes("Meta")||e.includes("ComponentMeta")||s.push({code:"STORIES_NO_META_TYPE",message:"Stories file should have Meta type import for type safety.",severity:"warning"}),e.includes("StoryObj")||e.includes("ComponentStory")||e.includes("Story")||s.push({code:"STORIES_NO_STORY_TYPE",message:"Stories file should have StoryObj/Story type for type safety.",severity:"warning"}),e.includes("export default")||t.push({code:"STORIES_NO_DEFAULT_EXPORT",message:"Stories file must have a default export (meta configuration).",severity:"error"}),/export\s+const\s+\w+\s*[:=]/.test(e)||t.push({code:"STORIES_NO_STORY_EXPORTS",message:"Stories file must have at least one named export (story definition).",severity:"error"}),/import\s+\{?\s*\w+\s*\}?\s+from\s+['"]\.\//.test(e)||s.push({code:"STORIES_NO_COMPONENT_IMPORT",message:"Stories file should import the component being documented.",severity:"warning"}),(e.includes("// ... other")||e.includes("/* ... */"))&&t.push({code:"STORIES_INCOMPLETE",message:"Stories file contains placeholder comments - likely incomplete.",severity:"error"}),{errors:t,warnings:s}}function ie(e){let i=e.toLowerCase();if(i.includes(".stories."))return"stories";switch(i.split(".").pop()){case"tsx":return"tsx";case"jsx":return"jsx";case"ts":return"ts";case"js":return"js";case"css":return"css";case"scss":return"scss";case"less":return"less";default:return"unknown"}}function se(e,i,t={}){let s={valid:!0,fileType:i,errors:[],warnings:[]},o=Ve(e,t);o&&s.errors.push(o);let n=Ue(e);n&&s.errors.push(n);let r=ze(e);r&&s.errors.push(r);let d=je(e);switch(d&&(t.strict?s.errors.push({...d,severity:"error"}):s.warnings.push(d)),i){case"stories":{let{errors:g,warnings:f}=Ge(e,t);s.errors.push(...g),s.warnings.push(...f);break}case"tsx":case"jsx":{let{errors:g,warnings:f}=te(e,t);s.errors.push(...g),s.warnings.push(...f);break}case"css":case"scss":case"less":{let{errors:g,warnings:f}=Be(e,t);s.errors.push(...g),s.warnings.push(...f);break}case"ts":case"js":{let{errors:g,warnings:f}=te(e,t);s.errors.push(...g),s.warnings.push(...f.filter(c=>!c.code.includes("JSX")));break}default:break}return s.valid=s.errors.length===0,s}function re(e,i,t={}){let s=ie(i);return se(e,s,t)}function We(e,i,t={}){return re(e,i,t).valid}function Xe(e){if(e.valid&&e.warnings.length===0)return`\u2713 Valid ${e.fileType} code`;let i=[];if(e.valid)i.push(`\u26A0 Valid ${e.fileType} code with warnings`);else{i.push(`\u2717 Invalid ${e.fileType} code`),i.push(""),i.push("Errors:");for(let t of e.errors)i.push(` - [${t.code}] ${t.message}`)}if(e.warnings.length>0){i.push(""),i.push("Warnings:");for(let t of e.warnings)i.push(` - [${t.code}] ${t.message}`)}return i.join(`
3
+ `)}var He,oe=be(()=>{"use strict";He=50});import{dirname as he,join as M}from"path";import{fileURLToPath as ge}from"url";import*as me from"fs/promises";import*as F from"path";import{glob as ae}from"glob";import{existsSync as ke}from"fs";import{createRequire as Ae}from"module";var U={NAME:"UI Parity",SHORT:"Parity",DOMAIN:"uiparity.com",MARKETING_URL:"https://uiparity.com",APP_URL:"https://app.uiparity.com",API_URL:"https://api.uiparity.com",SUPPORT_EMAIL:"feedback@uiparity.com",TAGLINE:"Pixel-perfect isn't a feeling. It's a score."};function Ce(){if(typeof process<"u"&&process.env)return process.env.UICOPILOT_DEBUG==="1";if(typeof globalThis<"u"&&"localStorage"in globalThis)try{return globalThis.localStorage.getItem("uicopilot_debug")==="1"}catch{return!1}return!1}var O=`[${U.NAME}]`,l={debug:(...e)=>{Ce()&&console.log(O,...e)},info:(...e)=>{console.log(O,...e)},warn:(...e)=>{console.warn(O,...e)},error:(...e)=>{console.error(O,...e)}};var Ne=["flex","inline-flex"],Fe=["grid","inline-grid"],_t=[...Ne,...Fe];var L=null,$=null,Q=!1;async function z(){if(Q)return!!L;if(Q=!0,process.env.STORYBOOK_UICOPILOT_NO_PUPPETEER==="true")return l.debug("Puppeteer disabled via STORYBOOK_UICOPILOT_NO_PUPPETEER flag"),!1;let e=Ae(process.cwd()+"/");try{return L=e("puppeteer"),l.debug("Puppeteer loaded \u2014 server-side screenshots enabled"),!0}catch{}try{return L=e("puppeteer-core"),l.debug("puppeteer-core loaded \u2014 server-side screenshots enabled"),!0}catch{}return l.debug("Puppeteer not found \u2014 install puppeteer for pixel-perfect screenshots"),!1}function De(){let e=["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome","/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary","/Applications/Chromium.app/Contents/MacOS/Chromium","/usr/bin/google-chrome","/usr/bin/google-chrome-stable","/usr/bin/chromium-browser","/usr/bin/chromium"];for(let i of e)if(ke(i))return i}async function Z(){if($&&$.connected)return $;let e=De(),i={headless:!0,args:["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage"],...e?{executablePath:e}:{}};return $=await L.launch(i),l.debug("Headless Chrome launched for screenshots"),$}async function j(e,i){if(!await z())return null;let o=await(await Z()).newPage();try{await o.setCacheEnabled(!1),await o.setViewport({width:i?.width||800,height:i?.height||600,deviceScaleFactor:1}),await o.goto(e,{waitUntil:"networkidle2",timeout:15e3}),await o.evaluate(()=>document.fonts.ready),await o.waitForSelector("#storybook-root > *",{timeout:1e4}),await o.waitForFunction(()=>new Promise(f=>{let c=document.querySelectorAll("style").length,m=0,h=()=>{let p=document.querySelectorAll("style").length;if(p===c){if(m++,m>=3){f(!0);return}}else m=0,c=p;setTimeout(h,100)};setTimeout(h,200)}),{timeout:5e3}).catch(()=>{}),await new Promise(f=>setTimeout(f,500));let n=await o.evaluate(()=>{let f=document.querySelector("#storybook-root");if(!f)return null;let c=window.innerHeight,m=window.innerWidth,h=1/0,p=0,x=1/0,a=0,u=!1;function S(b){for(let y of Array.from(b.children)){let w=window.getComputedStyle(y);if(w.display==="none"||w.visibility==="hidden"||w.position==="fixed"||w.position==="absolute")continue;let C=y.getBoundingClientRect();if(!(C.height<=0||C.width<=0)){if(C.height>=c*.9&&C.width>=m*.9){S(y);continue}h=Math.min(h,C.top),p=Math.max(p,C.bottom),x=Math.min(x,C.left),a=Math.max(a,C.right),u=!0}}}return S(f),u?{top:h,bottom:p,left:x,right:a}:null}),r=16,d=n?{x:Math.max(0,n.left-r),y:Math.max(0,n.top-r),width:Math.min(n.right-n.left+r*2,800),height:Math.min(n.bottom-n.top+r*2,600)}:void 0,g=await o.screenshot({type:"png",...d?{clip:d}:{fullPage:!1}});return Buffer.from(g)}finally{await o.close()}}async function ee(e,i,t,s){if(!await z())return null;let r=await(await Z()).newPage();try{await r.setCacheEnabled(!1),await r.setViewport({width:s?.width||800,height:s?.height||600,deviceScaleFactor:1});let d=s?.storyId||"",g=`${t}/iframe.html?viewMode=story&id=${d}&globals=`;await r.goto(g,{waitUntil:"load",timeout:15e3}),await r.waitForSelector("#storybook-root > *",{timeout:1e4}),await r.evaluate(m=>{let h=document.getElementById("storybook-root");h&&(h.innerHTML=m)},e),await r.evaluate(()=>document.fonts.ready),await new Promise(m=>setTimeout(m,500));let f=await r.evaluate(()=>{let m=document.querySelector("#storybook-root");if(!m)return null;let h=window.innerWidth;function p(u){let S=u.getBoundingClientRect();if(S.width===0||S.height===0)return null;if(S.width<h*.8&&S.height>0)return S;for(let b of Array.from(u.children)){let y=window.getComputedStyle(b);if(y.position==="fixed"||y.position==="absolute"||y.display==="none"||y.visibility==="hidden")continue;let w=p(b);if(w)return w}return null}let x=p(m);if(x)return{x:Math.max(0,x.x-8),y:Math.max(0,x.y-8),width:x.width+16,height:x.height+16};let a=m.firstElementChild;if(a){let u=a.getBoundingClientRect();return{x:u.x,y:u.y,width:u.width,height:u.height}}return null});if(!f)throw new Error("Could not determine component bounds from snapshot");let c=await r.screenshot({type:"png",clip:f});return Buffer.from(c)}finally{await r.close()}}async function R(){return z()}async function B(){$&&(await $.close(),$=null)}var G=null,N=null,ce=!1;async function Je(){if(!ce){ce=!0;try{let e=await Promise.resolve().then(()=>(oe(),ne));G=e.validateCodeForFile,N=e.formatValidationResult,l.debug("Code validator loaded - fix validation enabled")}catch{l.debug("Code validator not available - skipping fix validation")}}}var qe="UICOPILOT/APPLY_FIXES",Ye="UICOPILOT/FIX_STARTED",Ke="UICOPILOT/FIX_COMPLETED",Qe="UICOPILOT/FIX_FAILED",le="UICOPILOT/ALL_FIXES_APPLIED",Ze="UICOPILOT/RELOAD_REQUIRED",de="UICOPILOT/WORKSPACE_PATH",et="UICOPILOT/REQUEST_WORKSPACE_PATH",tt="UICOPILOT/DISCOVER_COMPONENT_FILES",ue="UICOPILOT/COMPONENT_FILES_DISCOVERED";async function pe(e,i){let t=e.toLowerCase(),s=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),o=[`src/**/fui-${t}/fui-${t}.css`,`src/**/fui-${t}/*.css`,`src/**/${t}/${t}.css`,`src/**/${s}/${s}.css`,`src/**/*${t}*.css`,`src/**/*${s}*.css`,`styles/**/*${t}*.css`],n=[`src/**/fui-${t}/fui-${t}.tsx`,`src/**/fui-${t}/*.tsx`,`src/**/${t}/${t}.tsx`,`src/**/${s}/${s}.tsx`,`src/**/*${s}*.tsx`,`src/**/*${s}*.jsx`],r=[],d=[];for(let a of o)try{let u=await ae(a,{cwd:i,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**"]});u.length>0&&r.push(...u)}catch{}for(let a of n)try{let u=await ae(a,{cwd:i,nodir:!0,ignore:["**/node_modules/**","**/dist/**","**/.storybook/**","**/*.stories.*","**/*.test.*"]});u.length>0&&d.push(...u)}catch{}let g=[...new Set(r)],f=[...new Set(d)],c=a=>{if(a.length===0)return;let u=a.find(y=>y.includes(`/fui-${t}/`)&&y.endsWith(".css"));if(u)return u;let S=a.find(y=>y.toLowerCase().includes(`/${t}/${t}.css`)||y.includes(`/${s}/${s}.css`));if(S)return S;let b=a.find(y=>y.toLowerCase().endsWith(`/${t}.css`)||y.endsWith(`/${s}.css`));return b||a[0]},m=a=>{if(a.length===0)return;let u=a.filter(w=>!w.includes(".stories.")&&!w.includes(".test."));if(u.length===0)return a[0];let S=u.find(w=>w.includes(`/fui-${t}/`)&&(w.endsWith(".tsx")||w.endsWith(".jsx")));if(S)return S;let b=u.find(w=>w.toLowerCase().includes(`/${t}/${t}.tsx`)||w.includes(`/${s}/${s}.tsx`));if(b)return b;let y=u.find(w=>w.toLowerCase().endsWith(`/${t}.tsx`)||w.endsWith(`/${s}.tsx`));return y||u[0]},h=c(g),p=m(f),x=[...g,...f];return l.debug(`Discovered files for "${e}":`,{cssFile:h,componentFile:p,totalMatches:x.length}),{cssFile:h,componentFile:p,allMatches:[...new Set(x)]}}var it=100;function st(e){return new Promise(i=>setTimeout(i,e))}async function rt(e,i){if(await Je(),!G||!N)return l.debug(`Skipping validation (validator not available) for ${i}`),{valid:!0};let t=G(e,i);if(!t.valid){let s=t.errors.map(o=>o.message).join("; ");return l.warn(`Code validation failed for ${i}:`),console.warn(N(t)),{valid:!1,error:s}}return t.warnings.length>0&&(l.warn(`Code validation warnings for ${i}:`),console.warn(N(t))),l.debug(`Validation passed for ${i}`),{valid:!0}}var fe=!1;function nt(e){if(fe)return e;fe=!0;let i=process.cwd();return l.debug("Apply fixes initialized"),l.debug("Workspace:",i),e.emit(de,{path:i}),e.on(et,()=>{l.debug("Workspace path requested by browser"),l.debug("Emitting workspace path response:",i),e.emit(de,{path:i})}),e.on(tt,async t=>{let{componentName:s,storyId:o}=t;l.debug(`Discovering files for component: ${s}`);try{let n=await pe(s,i);e.emit(ue,{componentName:s,storyId:o,...n,workspacePath:i})}catch(n){l.error("File discovery error:",n),e.emit(ue,{componentName:s,storyId:o,error:n.message,allMatches:[]})}}),e.on(qe,t=>{setTimeout(async()=>{try{let{issues:s,storybookRoot:o}=t,n=o||i;o?l.debug(`Using storybookRoot from API: ${o}`):l.debug(`Using process.cwd(): ${i}`),l.debug(`Received APPLY_FIXES for ${s.length} issue(s)`);let r=new Map;async function d(c){let m=c.targetFileType||"css",h=c.targetFilePath||c.generatedFix?.filePath,p="",x=c.title?.match(/^(\w+)\s/);if(x&&(p=x[1]),!p&&h){let S=h.match(/\/(\w+)\.(?:css|tsx|jsx)$/i);S&&(p=S[1])}if(!p)return l.debug(`Could not extract component name, using provided path: ${h}`),h||null;if(!r.has(p)){let S=await pe(p,n);r.set(p,S)}let a=r.get(p),u=m==="css"?a.cssFile:a.componentFile;return u?(l.debug(`Discovered ${m} path: ${u} (was: ${h})`),u):(l.debug(`No ${m} file discovered, using provided: ${h}`),h||null)}let g=[];for(let c of s){let{generatedFix:m}=c,h=c.targetFilePath||m?.filePath,p=await d(c)||h;l.debug("Processing issue:",{id:c.id,type:c.type,targetFileType:c.targetFileType||"css",targetPath:p,providedPath:h!==p?h:"(same)",codeLength:m?.code?.length||0}),e.emit(Ye,{issueId:c.id});try{if(!m||!m.code||!p)throw new Error("Missing AI-generated fix data (code or filePath)");l.debug("Code to write (first 200 chars):",m.code.substring(0,200)),l.debug(`Code length: ${m.code.length} chars`);let x=await rt(m.code,p);if(!x.valid)throw new Error(`Code validation failed: ${x.error}. Fix was not applied to prevent breaking the file.`);let a=F.isAbsolute(p)?p:F.join(n,p);l.debug(`Writing to absolute path: ${a}`),await me.writeFile(a,m.code,"utf-8"),await st(it);let u={success:!0,issueId:c.id,filePath:p,timestamp:new Date};e.emit(Ke,{issueId:c.id,result:u}),l.debug(`\u2713 Applied ${c.targetFileType||"css"} fix to: ${p}`),g.push(u)}catch(x){let a=x.message||"Unknown error";e.emit(Qe,{issueId:c.id,error:a}),l.error(`\u2717 Error: ${a}`),g.push({success:!1,issueId:c.id,error:a,timestamp:new Date})}}let f={total:g.length,succeeded:g.filter(c=>c.success).length,failed:g.filter(c=>!c.success).length};e.emit(le,{results:g,summary:f}),l.debug(`Completed: ${f.succeeded}/${f.total} fixes applied`),f.succeeded>0&&e.emit(Ze,{message:"Fixes applied. If Storybook crashes due to HMR, please restart it.",filesChanged:g.filter(c=>c.success).map(c=>c.filePath)})}catch(s){l.error("Fatal error during fix application:",s),e.emit(le,{results:[],summary:{total:t.issues?.length||0,succeeded:0,failed:t.issues?.length||0}})}},0)}),e}function ot(e){let i=process.cwd();return e.plugins=e.plugins||[],e.plugins.push({name:"uicopilot-server-api",configureServer(t){t.middlewares.use("/__uicopilot/health",(n,r)=>{r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({ok:!0,workspacePath:i}))}),t.middlewares.use("/__uicopilot/screenshot",async(n,r)=>{try{if(!await R()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed. Run: npm install puppeteer"}));return}let f=new URL(n.url||"",`http://${n.headers.host}`).searchParams.get("storyId");if(!f){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing storyId parameter"}));return}let m=`http://${n.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${f}&globals=`;l.debug(`Taking screenshot: ${f}`);let h=await j(m,{selector:"#storybook-root > *"});if(!h){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p=h.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${p}`}))}catch(d){l.error("Screenshot error:",d.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:d.message}))}}),t.middlewares.use("/__uicopilot/capture",async(n,r)=>{try{if(!await R()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed"}));return}let f=new URL(n.url||"",`http://${n.headers.host}`).searchParams.get("storyId");if(!f){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing storyId parameter"}));return}let m=`http://${n.headers.host||"localhost:6006"}/iframe.html?viewMode=story&id=${f}&globals=`;l.debug(`Full capture: ${f}`);let h=await j(m,{selector:"#storybook-root > *"});if(!h){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Screenshot capture failed"}));return}let p;try{p=(await import("puppeteer")).default}catch{p=(await import("puppeteer-core")).default}let x=await p.launch({headless:!0,args:["--no-sandbox","--disable-setuid-sandbox"]}),a=await x.newPage();try{await a.setCacheEnabled(!1),await a.setViewport({width:800,height:600}),await a.goto(m,{waitUntil:"networkidle2",timeout:15e3}),await a.evaluate(()=>document.fonts.ready),await a.waitForSelector("#storybook-root > *",{timeout:1e4}),await a.evaluate(()=>new Promise(b=>{let y=setTimeout(b,5e3);try{let w=window.__STORYBOOK_ADDONS_CHANNEL__;if(w){let C=()=>{clearTimeout(y),w.off("storyRendered",C),setTimeout(b,100)};w.on("storyRendered",C)}else clearTimeout(y),setTimeout(b,300)}catch{clearTimeout(y),b()}}));let u=await a.evaluate(()=>{let b=document.querySelector("#storybook-root > *")||document.querySelector("#root > *"),y={};if(b){let v=window.getComputedStyle(b);for(let E=0;E<v.length;E++)y[v[E]]=v.getPropertyValue(v[E])}let w={backgroundColor:["transparent","rgba(0, 0, 0, 0)"],border:["none","0px none","0px none rgb(0, 0, 0)"],borderRadius:["0px"],boxShadow:["none"],opacity:["1"]};function C(v){return v.replace(/-([a-z])/g,(E,P)=>P.toUpperCase())}function W(v,E){if(E>4)return null;let P=v.tagName.toLowerCase();if(["script","style","link","meta","br","hr","noscript"].includes(P))return null;let k=v.className,A=typeof k=="string"?k:k?.baseVal||"",D=v.id||void 0,ye=v.getAttribute("role")||void 0,X;for(let T of Array.from(v.childNodes))if(T.nodeType===3){let I=T.textContent?.trim();if(I){X=I.length>50?I.substring(0,50)+"...":I;break}}let H=P;D?H=`${P}#${D}`:A&&(H=`${P}.${A.split(" ").filter(Boolean).join(".")}`);let we=window.getComputedStyle(v),xe=["background-color","border","border-radius","box-shadow","opacity","fill","stroke","stroke-width","font-size","font-family","font-weight","line-height","letter-spacing","color","text-align","display","padding","margin","gap","flex-direction","justify-content","align-items","width","height"],V={};for(let T of xe){let I=we.getPropertyValue(T),_=C(T);I&&!w[_]?.includes(I)&&(V[_]=I)}if(P==="svg"||v.closest("svg"))for(let T of["fill","stroke","stroke-width","viewBox","d","r","cx","cy"]){let I=v.getAttribute(T);I&&(V[C(T)]=I)}let J=[];for(let T of Array.from(v.children)){let I=window.getComputedStyle(T);if(I.display==="none"||I.visibility==="hidden")continue;let _=W(T,E+1);_&&J.push(_)}return{selector:H,tagName:P,className:A,id:D,role:ye,textContent:X,styles:V,children:J}}return{computedStyles:y,domTree:b?W(b,0):null}}),S=h.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${S}`,computedStyles:u.computedStyles,domTree:u.domTree}))}finally{await a.close(),await x.close()}}catch(d){l.error("Capture error:",d.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:d.message}))}}),t.middlewares.use("/__uicopilot/screenshot-snapshot",async(n,r)=>{if(n.method!=="POST"){r.writeHead(405,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"POST required"}));return}try{if(!await R()){r.writeHead(501,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Puppeteer not installed"}));return}let g=[];for await(let S of n)g.push(typeof S=="string"?Buffer.from(S):S);let f=JSON.parse(Buffer.concat(g).toString()),{html:c,stylesheetUrls:m,storyId:h}=f;if(!c){r.writeHead(400,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Missing html in body"}));return}let x=`http://${n.headers.host||"localhost:6006"}`;l.debug(`Taking snapshot screenshot for ${h||"unknown"}`);let a=await ee(c,m||[],x,{storyId:h});if(!a){r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:"Snapshot screenshot failed"}));return}let u=a.toString("base64");r.writeHead(200,{"Content-Type":"application/json"}),r.end(JSON.stringify({screenshot:`data:image/png;base64,${u}`}))}catch(d){l.error("Snapshot screenshot error:",d.message),r.writeHead(500,{"Content-Type":"application/json"}),r.end(JSON.stringify({error:d.message}))}}),t.httpServer?.on("close",()=>{B().catch(()=>{})});let s=n=>{B().catch(()=>{}).finally(()=>{process.kill(process.pid,n)})},o=globalThis;o.__uicopilotShutdownRegistered||(o.__uicopilotShutdownRegistered=!0,process.once("SIGINT",()=>s("SIGINT")),process.once("SIGTERM",()=>s("SIGTERM")))}}),e}var at=()=>{if(typeof import.meta<"u"&&import.meta.url){let e=ge(import.meta.url),i=he(e);return M(i,"manager.mjs")}return M(__dirname,"manager.mjs")},ct=()=>{if(typeof import.meta<"u"&&import.meta.url){let e=ge(import.meta.url),i=he(e);return M(i,"preview.mjs")}return M(__dirname,"preview.mjs")};function ci(e=[]){return[...e,at()]}function li(e=[]){return[...e,ct()]}export{nt as experimental_serverChannel,ci as managerEntries,li as previewAnnotations,ot as viteFinal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uicopilot/storybook-addon",
3
- "version": "0.5.7",
3
+ "version": "0.5.10",
4
4
  "description": "AI-powered Figma comparison for Storybook components",
5
5
  "keywords": [
6
6
  "storybook-addons",
@@ -14,7 +14,7 @@
14
14
  "url": "https://github.com/eransc/uicopilot",
15
15
  "directory": "packages/storybook-addon"
16
16
  },
17
- "author": "UI Copilot",
17
+ "author": "UI Parity",
18
18
  "license": "MIT",
19
19
  "publishConfig": {
20
20
  "registry": "https://registry.npmjs.org",
@@ -117,4 +117,4 @@
117
117
  ],
118
118
  "icon": "https://user-images.githubusercontent.com/263385/199832481-14b26767-3db1-48eb-9f95-25a93c99c35e.png"
119
119
  }
120
- }
120
+ }