@vcp-dev/site-edit-engine 0.10.26 → 0.10.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import*as Jh from"@babel/parser";import*as Wn from"@babel/types";import*as qt from"node:path";var Ns=[".tsx",".ts",".jsx",".js"],Xh=Ns.map(e=>`/index${e}`),zh=new Set(["json","css","scss","sass","less","svg","png","jpg","jpeg","gif","webp","avif","ico","bmp","woff","woff2","ttf","otf","eot","mp4","webm","mp3","wav","ogg","pdf","txt","md","csv","xml","yaml","yml"]);function ou(e){let t=e.replace(/[?#].*$/,""),n=/\.([a-z0-9]+)$/i.exec(t);return n!==null&&zh.has(n[1].toLowerCase())}function iu(e){let t=[];for(let n of e.program.body)Wn.isImportDeclaration(n)&&typeof n.source.value=="string"&&Pt(n.source.value)&&t.push(n.source.value),Wn.isExportNamedDeclaration(n)&&n.source&&typeof n.source.value=="string"&&Pt(n.source.value)&&t.push(n.source.value),Wn.isExportAllDeclaration(n)&&typeof n.source.value=="string"&&Pt(n.source.value)&&t.push(n.source.value);return ws(e.program,t),t}function ws(e,t){if(!e||typeof e!="object")return;let n=e;if(n.type==="CallExpression"&&n.callee?.type==="Import"){let r=n.arguments?.[0];r?.type==="StringLiteral"&&typeof r.value=="string"&&Pt(r.value)&&t.push(r.value)}for(let r of Object.values(n))if(Array.isArray(r))for(let o of r)ws(o,t);else r&&typeof r=="object"&&ws(r,t)}function Pt(e){return e.startsWith("./")||e.startsWith("../")||e.startsWith("@/")}function yn(e,t){if(t.startsWith("@/"))return t.slice(2).replace(/\\/g,"/");let n=qt.dirname(e);return qt.join(n,t).replace(/\\/g,"/")}async function Wh(e,t){if(Ns.some(n=>e.endsWith(n))&&await t(e))return e;for(let n of Ns){let r=`${e}${n}`;if(await t(r))return r}for(let n of Xh){let r=`${e}${n}`;if(await t(r))return r}return null}async function xn(e,t,n){let r=await Fo(e,t,n);return r.ok?r.path:null}async function Fo(e,t,n){let r=yn(e,t);try{if(!Hh(e,t,r))return{ok:!1,diagnostic:{path:r,code:"import-not-found",message:`Local import not found: ${t}`,details:{fromFile:e,specifier:t}}};let o=await Wh(r,n);return o?{ok:!0,path:o}:{ok:!1,diagnostic:{path:r,code:"import-not-found",message:`Local import not found: ${t}`,details:{fromFile:e,specifier:t}}}}catch(o){return{ok:!1,diagnostic:{path:r,code:"import-resolve-failed",message:`Failed to resolve local import: ${t}`,details:{fromFile:e,specifier:t,reason:o instanceof Error?o.message:String(o)}}}}}function Hh(e,t,n){if(!Pt(t)||t.includes("\0")||t.includes("\\")||qt.posix.isAbsolute(n))return!1;let r=qt.posix.normalize(n);if(r===".."||r.startsWith("../"))return!1;if(t.startsWith("@/")){let o=t.slice(2);return o.length>0&&!o.split("/").some(i=>i==="..")}return!qt.posix.isAbsolute(e)}import{createHash as Yh}from"node:crypto";import*as su from"@babel/parser";function bn(e,t,n,r){return{code:e,message:t,locatorKind:n,details:r}}function K(e,t,n,r,o){return{ok:!1,source:e,diagnostic:bn(t,n,r,o)}}function Ps(e,t,n,r,o){return{ok:!1,source:e,diagnostic:bn(t,n,r,o)}}var Gh={"tsx-module":["jsx","typescript"],"ts-module":["typescript"],"next-app-entry":["jsx","typescript"]};function At(e){let{source:t,profile:n}=e;try{return{ok:!0,ast:su.parse(t,{sourceType:"module",plugins:Gh[n]})}}catch(r){return{ok:!1,source:t,diagnostic:bn("parse-failed",`AST parse failed: ${r instanceof Error?r.message:String(r)}`)}}}function As(e,t){return At({source:e,profile:au(t.kind)})}function vr(e,t){return At({source:e,profile:au(t)})}function au(e){return"next-app-entry"}function Sn(e){let{filePath:t,source:n}=e,r=t.toLowerCase().split(".").pop()??"";return r==="tsx"?"tsx-module":r==="ts"?"ts-module":r==="jsx"||r==="js"||r===""&&/<\w[\s\S]*>/.test(n)?"tsx-module":"next-app-entry"}var En=(e,t)=>{let n=At({source:t,profile:Sn({filePath:e,source:t})});return n.ok?{ok:!0,module:{file:e,source:t,sourceHash:`sha256:${Yh("sha256").update(t).digest("hex")}`,ast:n.ast,imports:iu(n.ast).map(r=>({specifier:r}))}}:{ok:!1,diagnostic:{path:e,code:"parse-failed",message:n.diagnostic.message}}};function Zh(e,t){return En(e,t)}function Qh(e,t){return yn(e,t)}import Fs from"@babel/generator";import*as pu from"@babel/parser";import _s from"@babel/traverse";import*as Ie from"@babel/types";import{computeSiteEditSourceIdentityKey as ey}from"@vcp-dev/contracts";var cu="data-vcp-ui-component",_o="components/ui";function Ut(e){if(!e)return!1;let t=Ts(e);return t===_o||t.startsWith(`${_o}/`)||t.includes(`/${_o}/`)||t.endsWith(`/${_o}`)}function vn(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?Ut(e.slice(2)):e.startsWith("./")||e.startsWith("../")?Ut(Ts(`${qh(t)}/${e}`)):Ut(e):!1}function Ts(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let o of n.split("/"))if(!(!o||o===".")){if(o===".."){r.pop();continue}r.push(o)}return r.join("/")}function qh(e){let t=Ts(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}import{stripSiteEditRepeatInstanceKeys as ww}from"@vcp-dev/contracts";import{isSiteEditRuntimeContainerTag as Aw,isSiteEditRuntimeTextTag as Tw}from"@vcp-dev/contracts/site-edit-runtime-capability";var lu={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags",publicUiComponent:"data-vcp-ui-component"};var ty=typeof Fs=="function"?Fs:Fs.default,ny=typeof _s=="function"?_s:_s.default,ry=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]),oy="suppressHydrationWarning",iy=new Set(["SiteEditBootstrap"]);function sy(e){let t=ly(e.file,e.projectRoot);if(!cy(e.source)||Ut(t))return{code:e.source,elements:[]};let n=e.attributes??lu,r=pu.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),o=[],i=dy(r,t);return ny(r,{JSXElement(s){let a=s.node.openingElement,c=a.name;if(!py(c)||mu(a,n.key))return;let l=gy(s)??"default",d=yy(s),f=ey(t,l,d),m=Mo(c)??"unknown",u=uy(c)?"jsx":"component-call";if(u==="component-call"&&!hy(s.node.children)&&iy.has(m))return;let g=u==="component-call"&&fy(m,i);my(a,n.key,f),g&&uu(a,cu),ay(s)&&uu(a,oy),o.push({key:f,tag:m,componentName:l,sourceFile:t,sourceKind:u})}}),o.length===0?{code:e.source,elements:o}:{code:ty(r,{jsescOption:{minimal:!0}}).code,elements:o}}function ay(e){return!e.findParent(t=>t.isJSXElement())}function cy(e){return/(?:^|[=(:,?;\[{>&|\n\r]|return\s+)\s*<(?:[A-Za-z][\w.:-]*|>)(?:\s|>|\/)/m.test(e)}function ly(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1);for(let[i,s]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let a=n.indexOf(i);if(a>=0)return n.slice(a+s)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function uy(e){return Ie.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function Mo(e){return Ie.isJSXIdentifier(e)?e.name:Ie.isJSXMemberExpression(e)?hu(e):null}function dy(e,t){let n=new Set;for(let r of e.program.body)if(!(!Ie.isImportDeclaration(r)||!vn(r.source.value,t)))for(let o of r.specifiers)n.add(o.local.name);return n}function fy(e,t){let n=e.split(".")[0]??e;return t.has(n)}function py(e){let t=Mo(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!ry.has(t)}function mu(e,t){return e.attributes.some(n=>Ie.isJSXAttribute(n)&&Ie.isJSXIdentifier(n.name,{name:t}))}function my(e,t,n){gu(e,Ie.jsxAttribute(Ie.jsxIdentifier(t),Ie.stringLiteral(n)))}function uu(e,t){mu(e,t)||gu(e,Ie.jsxAttribute(Ie.jsxIdentifier(t),null))}function gu(e,t){let n=e.attributes.findIndex(r=>Ie.isJSXSpreadAttribute(r));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function hu(e){return`${Ie.isJSXIdentifier(e.object)?e.object.name:hu(e.object)}.${e.property.name}`}function gy(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&Ie.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function hy(e){return e.some(t=>Ie.isJSXElement(t)||Ie.isJSXFragment(t))}var du=new WeakMap,Oo=new WeakMap,Os=new WeakMap;function yy(e){let t=du.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let i=xy(r);i&&n.unshift(i)}r=r.parentPath}let o=n.join("/");return du.set(e.node,o),o}function xy(e){let t=Mo(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${fu(e,t)}`:`${t}#${fu(e,t)}`}function fu(e,t){let n=yu(e)??e.getFunctionParent();if(!n)return 0;let r=Os.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let o=Os.get(n.node);o||(o=new Map,Os.set(n.node,o));let i=o.get(t);i||(i=new WeakMap,o.set(t,i));let s=0,a=n.isJSXElement()||n.isJSXFragment()?Do(n):by(n);for(let c of a)if(Mo(c.node.openingElement.name)===t){if(i.set(c.node,s),c.node===e.node)return s;s+=1}return i.get(e.node)??0}function by(e){let t=Oo.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!yu(r)&&n.push(r)}}),Oo.set(e.node,n),n}function yu(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return n}function Do(e){let t=Oo.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let o of r)if(!Array.isArray(o)){if(o.isJSXElement()){n.push(o);continue}if(o.isJSXFragment()){n.push(...Do(o));continue}o.isJSXExpressionContainer()&&n.push(...kn(o.get("expression")))}return Oo.set(e.node,n),n}function kn(e){if(e.isJSXElement())return[e];if(e.isJSXFragment())return Do(e);if(e.isParenthesizedExpression())return kn(e.get("expression"));if(e.isLogicalExpression()&&e.node.operator==="&&")return kn(e.get("right"));if(e.isConditionalExpression())return[...kn(e.get("consequent")),...kn(e.get("alternate"))];if(e.isCallExpression()&&Ey(e.node)){let t=e.get("arguments")[0];return Sy(t)}return[]}function Sy(e){if(!e.isArrowFunctionExpression()&&!e.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return Do(t);if(t.isParenthesizedExpression())return kn(t.get("expression"));if(!t.isBlockStatement())return[];for(let n of t.get("body")){if(!n.isReturnStatement())continue;let r=n.get("argument");return r.node?kn(r):[]}return[]}function Ey(e){return Ie.isMemberExpression(e.callee)&&Ie.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}import{SiteEditOperationRequestSchema as DN,SiteEditPatchPlanSchema as LN}from"@vcp-dev/contracts";function In(e){return{requestId:e.requestId,kind:e.kind,composition:e.composition,target:e.target,resultVersion:e.resultVersion,affectedFiles:e.affectedFiles,...e.output?{output:e.output}:{},...e.selectionRef?{selectionRef:e.selectionRef}:{}}}function Lo(e,t){let n=t[0]??"Site edit operation request failed contract validation.";return{ok:!1,composition:{routeId:e.composition.routeId,...e.composition.templateId!==void 0?{effectiveTemplateId:e.composition.templateId}:{}},error:{code:"INVALID_PARAMS",message:n},data:{requestId:e.id,kind:e.kind,composition:{routeId:e.composition.routeId,...e.composition.templateId!==void 0?{effectiveTemplateId:e.composition.templateId}:{}},target:e.target,resultVersion:e.documentVersion}}}function Bo(e,t){if(!e.pageComposition)throw new Error("RenderDocument is missing the required Page Composition projection.");return{siteId:t.siteId,snapshotId:t.snapshotId,composition:e.composition,version:e.version,entries:e.entries.map(n=>({key:n.key,parentKey:n.parentKey,...n.pageCompositionUnitKey?{pageCompositionUnitKey:n.pageCompositionUnitKey}:{},...n.pageCompositionActionScope?{pageCompositionActionScope:n.pageCompositionActionScope}:{},operationSummary:{canUpdateText:n.operationSummary.canUpdateText,canInsertChild:n.operationSummary.canInsertChild,canMove:n.operationSummary.canMove,canRemove:n.operationSummary.canRemove},...n.dynamicDataSummary?{dynamicDataSummary:n.dynamicDataSummary}:{}})),pageComposition:e.pageComposition.status==="unsupported"?{status:"unsupported",reason:e.pageComposition.reason,diagnostics:e.pageComposition.diagnostics}:{status:"supported",containerKey:e.pageComposition.container.key,hasBusinessMembers:e.pageComposition.businessMembers.length>0,placementUnitKeys:e.pageComposition.placementUnits.map(n=>n.key),placements:e.pageComposition.placements.map(n=>({placementKey:n.placementKey,placementUnitKey:n.placementUnitKey,relation:n.relation}))}}}function jo(e){return{composition:e.composition,key:e.key,tag:e.tag,label:e.label,sourceLocator:e.sourceLocator,isOpaque:e.isOpaque,ancestors:e.ancestors,componentName:e.componentName,sourceFile:e.sourceFile,capabilities:vy(e.capabilities),provenanceChain:e.provenanceChain?{editMode:e.provenanceChain.editMode,diagnostics:e.provenanceChain.diagnostics}:void 0,dynamicData:e.dynamicData,...e.properties?{properties:e.properties}:{},textSegments:e.textSegments.map(t=>({index:t.index,editable:t.editable,sourceKind:t.source?.kind??null})),boundaryKind:e.boundaryKind}}function $o(e,t){let n=new Date().toISOString();return e.type==="document-changed"?{type:"site-edit.document.changed",siteId:t.siteId,snapshotId:t.snapshotId,composition:e.composition,version:e.version,at:n}:e.type==="operation-completed"?{type:"site-edit.operation.completed",siteId:t.siteId,composition:e.composition,result:In(e.result),at:n}:e.type==="operation-failed"?{type:"site-edit.operation.failed",siteId:t.siteId,requestId:e.requestId,composition:e.composition,error:e.error,at:n}:e.type==="capability-changed"?{type:"site-edit.capability.changed",siteId:t.siteId,composition:e.composition,keys:e.keys,at:n}:e.type==="graph-invalidated"?{type:"site-edit.graph.invalidated",siteId:t.siteId,composition:e.composition,at:n}:e.type==="graph-ready"?{type:"site-edit.graph.ready",siteId:t.siteId,composition:e.composition,version:e.version,at:n}:e.type==="graph-error"?{type:"site-edit.graph.error",siteId:t.siteId,composition:e.composition,message:e.message,at:n}:null}function vy(e){return{composition:e.composition,key:e.key,canUpdateText:e.canUpdateText,canInsertChild:e.canInsertChild,canMove:e.canMove,canRemove:e.canRemove,editModes:e.editModes?{updateText:e.editModes.updateText?{mode:e.editModes.updateText.mode,reasonCode:e.editModes.updateText.reasonCode}:void 0,insertChild:e.editModes.insertChild?{mode:e.editModes.insertChild.mode,reasonCode:e.editModes.insertChild.reasonCode}:void 0,move:e.editModes.move?{mode:e.editModes.move.mode,reasonCode:e.editModes.move.reasonCode}:void 0,remove:e.editModes.remove?{mode:e.editModes.remove.mode,reasonCode:e.editModes.remove.reasonCode}:void 0}:void 0,constraints:e.constraints}}import{checkGlobalsCssEdit as zR,computeSiteEditCompositionKey as WR,getSiteEditSourceDeleteProtectionReason as HR,isSiteEditTextSourcePath as GR,parseSiteEditRepeatInstanceKey as YR,SITE_EDIT_SOURCE_DELETE_CAPABILITY as ZR,stripSiteEditRepeatInstanceKeys as nt}from"@vcp-dev/contracts";import as from"node:path";import{parse as QR}from"yaml";import js from"node:path";import{TextDecoder as Iy}from"node:util";import{SITE_EDIT_SOURCE_ALLOWED_APP_FILES as bu,SITE_EDIT_SOURCE_ALLOWED_DIRS as Su,SITE_EDIT_SOURCE_ALLOWED_ROOT_FILES as Eu,SiteEditCompositionContextSchema as Cy,SiteEditSourceFileResponseSchema as Ms,SiteEditSourceLocationSchema as Ry,SiteEditSourcePathSchema as Vo,SiteEditSourceTreeResponseSchema as Ny,isSiteEditTextSourcePath as wy}from"@vcp-dev/contracts";import{createHash as ky}from"node:crypto";var kr=class{constructor(t){this.original=new Map,this.files=new Map,this.versions=new Map;for(let n of t)this.original.set(n.path,n.content),this.files.set(n.path,n.content),this.versions.set(n.path,n.version??1)}async readFile(t){let n=this.files.get(t);if(n===void 0)throw new Error(`Snapshot file not found: ${t}`);return n}async readFileBytes(t){return Buffer.from(await this.readFile(t),"utf8")}async getFileInfo(t){let n=this.files.get(t);return n===void 0?null:{path:t,sizeBytes:Buffer.byteLength(n,"utf8")}}async writeFile(t,n){this.files.set(t,n)}async createExclusive(t,n){if(this.files.has(t))throw Object.assign(new Error(`Snapshot file already exists: ${t}`),{code:"EEXIST"});this.files.set(t,n)}async deleteFile(t){this.files.delete(t)}async exists(t){return this.files.has(t)}async listFiles(t={}){let n=t.roots??[],r=[...this.files.keys()].filter(a=>n.length===0?!0:n.some(c=>a===c||a.startsWith(`${c}/`))),o=[],i=new Set,s=0;for(let a of r.sort()){let c=Buffer.byteLength(this.files.get(a)??"","utf8"),l=a.split("/").length;if(t.maxDepth!==void 0&&l>t.maxDepth){i.add("max-depth");continue}if(t.maxFiles!==void 0&&o.length>=t.maxFiles){i.add("max-files");break}if(t.maxTotalBytes!==void 0&&s+c>t.maxTotalBytes){i.add("max-total-bytes");break}o.push({path:a,sizeBytes:c}),s+=c}return i.size>0?{files:o,truncated:{reasons:[...i]}}:{files:o}}getVersion(t){return this.versions.get(t)??0}bumpVersion(t){let n=this.getVersion(t)+1;return this.versions.set(t,n),n}getChangedFiles(){let t=new Set([...this.original.keys(),...this.files.keys()]),n=[];for(let r of[...t].sort()){let o=this.original.get(r),i=this.files.get(r);o!==i&&n.push({path:r,before:o,after:i})}return n}};function Ee(e){return`sha256:${ky("sha256").update(e).digest("hex")}`}var Py=[...Eu,...bu,...Su];function $s(e){if(!e.composition)throw new Error("Composition unavailable for source access policy.");return Cy.parse(e.composition)}var Ds=2e3,Ls=12,Bs=24*1024*1024,xu=512*1024,Ay=new Set(["image/avif","image/gif","image/jpeg","image/png","image/webp","image/x-icon"]),Ty={".avif":"image/avif",".bin":"application/octet-stream",".eot":"application/vnd.ms-fontobject",".gif":"image/gif",".glb":"model/gltf-binary",".ico":"image/x-icon",".jpeg":"image/jpeg",".jpg":"image/jpeg",".mp3":"audio/mpeg",".mp4":"video/mp4",".pdf":"application/pdf",".png":"image/png",".svg":"image/svg+xml",".ttf":"font/ttf",".wasm":"application/wasm",".webm":"video/webm",".webp":"image/webp",".woff":"font/woff",".woff2":"font/woff2",".zip":"application/zip"},Fy={".cjs":"javascript",".css":"css",".cts":"typescript",".html":"html",".js":"javascript",".jsx":"javascript",".json":"json",".md":"markdown",".mdx":"markdown",".mjs":"javascript",".mts":"typescript",".ts":"typescript",".tsx":"typescript",".txt":"plaintext",".yaml":"yaml",".yml":"yaml"},_y=new Iy("utf-8",{fatal:!0});async function Ko(e,t={}){let n=$s(t),{files:r,truncated:o}=await $y(e,t),i=Uy(r.map(s=>s.metadata));return Ny.parse({composition:n,nodes:i,defaultPath:Jy(r.map(s=>s.metadata)),totalFiles:r.length,...o?{truncated:o}:{}})}async function Uo(e,t,n={}){let r=$s(n),o=Vo.parse(t.path),i=await My(e,o,n);if(!i)throw new Error(`Source file not found: ${o}`);if(Ks(o)){let a=Iu(o),c=await Ly(e,{path:o,sizeBytes:i.sizeBytes,mimeType:a});return Ms.parse({composition:r,path:o,kind:"binary",language:null,sizeBytes:i.sizeBytes,mimeType:a,readonly:!0,...c})}let s=await Vs(e,o);return s.ok?Ms.parse({composition:r,path:o,kind:"text",language:Cu(o),sizeBytes:s.sizeBytes,contentHash:Ee(s.content),readonly:!1,content:s.content}):Ms.parse({composition:r,path:o,kind:"binary",language:null,sizeBytes:s.sizeBytes,mimeType:"application/octet-stream",readonly:!0,previewUnavailableReason:"unsupported-mime"})}async function Vs(e,t){if(e.readFileBytes){let o=await e.readFileBytes(t),i=Oy(o);return i===null?{ok:!1,sizeBytes:o.byteLength}:{ok:!0,content:i,sizeBytes:o.byteLength}}let n=await e.readFile(t),r=Buffer.byteLength(n,"utf8");return n.includes("\0")?{ok:!1,sizeBytes:r}:{ok:!0,content:n,sizeBytes:r}}function Oy(e){if(e.includes(0))return null;try{return _y.decode(e)}catch{return null}}async function My(e,t,n){if(!By(t,n))return null;let r=await Dy(e,t);return r?{path:t,sizeBytes:r.sizeBytes}:null}async function Dy(e,t){if(e.getFileInfo)return e.getFileInfo(t);if(e.listFiles){let o=vu(await e.listFiles({roots:[t],maxFiles:1,maxDepth:t.split("/").length})).files.find(i=>i.path===t);if(o)return o}if(!await e.exists(t))return null;if(e.readFileBytes){let r=await e.readFileBytes(t);return{path:t,sizeBytes:r.byteLength}}if(Ks(t))return{path:t,sizeBytes:0};let n=await e.readFile(t);return{path:t,sizeBytes:Buffer.byteLength(n,"utf8")}}async function Ly(e,t){if(!Ay.has(t.mimeType))return{previewUnavailableReason:"unsupported-mime"};if(t.sizeBytes>xu)return{previewUnavailableReason:"too-large"};if(!e.readFileBytes)return{previewUnavailableReason:"bytes-unavailable"};let n=await e.readFileBytes(t.path);return n.byteLength>xu?{previewUnavailableReason:"too-large"}:{contentBase64:Buffer.from(n).toString("base64")}}function By(e,t){return Eu.some(n=>n===e)||bu.some(n=>n===e)||Su.some(n=>e===n||e.startsWith(`${n}/`))?!0:!e.startsWith("app/")&&!e.startsWith("src/app/")?!1:(t.routeEntryFiles??[]).some(n=>{let r=Vo.safeParse(n);return r.success&&r.data===e})}function Jo(e,t){if(!t.sourceLocator)throw new Error(`Source location not available for key: ${e.key}`);return Ry.parse({key:e.key,composition:t.composition,sourceFile:t.sourceLocator.sourceFile,componentName:t.sourceLocator.componentName,openingElementRange:{startLine:t.sourceLocator.openingElementRange.startLine,startColumn:t.sourceLocator.openingElementRange.startColumn,endLine:t.sourceLocator.openingElementRange.endLine,endColumn:t.sourceLocator.openingElementRange.endColumn},structuralPath:t.sourceLocator.structuralPath,textPreview:t.sourceLocator.textPreview})}function vu(e){return Array.isArray(e)?{files:e}:e}function jy(e){return["max-files","max-depth","max-total-bytes"].filter(n=>e.includes(n))}async function $y(e,t){if(!e.listFiles)throw new Error("Source file listing is unavailable.");let n=vu(await e.listFiles({roots:Vy(t),maxFiles:Ds+1,maxDepth:Ls,maxTotalBytes:Bs+1})),r=new Map,o=new Set(n.truncated?.reasons),i=0;for(let a of[...n.files].sort((c,l)=>c.path.localeCompare(l.path))){let c=Vo.safeParse(a.path);if(!c.success)continue;let l=c.data;if(l.split("/").length>Ls){o.add("max-depth");continue}if(r.size>=Ds){o.add("max-files");break}if(i+a.sizeBytes>Bs){o.add("max-total-bytes");break}r.set(l,{path:l,sizeBytes:a.sizeBytes,metadata:Ky(l,a.sizeBytes,$s(t))}),i+=a.sizeBytes}return{files:[...r.values()].sort((a,c)=>a.path.localeCompare(c.path)),...o.size>0?{truncated:{reasons:jy([...o]),maxFiles:Ds,maxDepth:Ls,maxTotalBytes:Bs}}:{}}}function Vy(e){let t=new Set(Py);for(let n of e.routeEntryFiles??[]){let r=Vo.safeParse(n);r.success&&(r.data.startsWith("app/")||r.data.startsWith("src/app/"))&&t.add(r.data)}return[...t]}function Ky(e,t,n){return Ks(e)?{composition:n,path:e,kind:"binary",language:null,sizeBytes:t,mimeType:Iu(e),readonly:!0}:{composition:n,path:e,kind:"text",language:Cu(e),sizeBytes:t,readonly:!1}}function Uy(e){let t=[];for(let n of e){let r=n.path.split("/"),o=t,i="";for(let[s,a]of r.entries()){i=i?`${i}/${a}`:a;let c=s===r.length-1,l=o.find(d=>d.name===a);if(l||(l=c?{kind:"file",name:a,path:i,file:n}:{kind:"directory",name:a,path:i,children:[]},o.push(l)),c){if(l.kind!=="file")throw new Error(`Source tree path collision: ${n.path}`);l.file=n}else{if(l.kind!=="directory")throw new Error(`Source tree path collision: ${n.path}`);o=l.children}}}return ku(t)}function ku(e){return e.map(t=>t.kind==="directory"?{...t,children:ku(t.children)}:t).sort((t,n)=>t.kind!==n.kind?t.kind==="directory"?-1:1:t.name.localeCompare(n.name))}function Jy(e){let t=e.find(r=>r.path.toLowerCase()==="design.md");if(t)return t.path;let n=e.find(r=>r.path==="app/page.tsx");return n?n.path:e.find(r=>r.kind==="text")?.path??e.at(0)?.path}function Ks(e){return!wy(e)}function Iu(e){let t=js.posix.extname(e).toLowerCase();return!t&&js.posix.basename(e).toLowerCase()==="favicon"?"image/x-icon":Ty[t]??"application/octet-stream"}function Cu(e){let t=js.posix.extname(e).toLowerCase();return Fy[t]??"plaintext"}import Us from"@babel/traverse";import*as Tt from"@babel/types";function Fe(e){if(e.isJSXFragment())return!0;if(!e.isJSXElement())return!1;let t=e.node.openingElement.name;if(Tt.isJSXIdentifier(t)){let o=e.scope.getBinding(t.name);if(!o)return!1;let i=o.path;if(!i.isImportSpecifier())return!1;let s=i.node.imported;return(Tt.isIdentifier(s)&&s.name==="Fragment"||Tt.isStringLiteral(s)&&s.value==="Fragment")&&Ru(i.parentPath)}if(!Tt.isJSXMemberExpression(t)||!Tt.isJSXIdentifier(t.property)||t.property.name!=="Fragment"||!Tt.isJSXIdentifier(t.object))return!1;let n=e.scope.getBinding(t.object.name);if(!n)return!1;let r=n.path;return(r.isImportDefaultSpecifier()||r.isImportNamespaceSpecifier())&&Ru(r.parentPath)}function Ru(e){return e?.isImportDeclaration()===!0&&e.node.source.value==="react"}var en=typeof Us=="function"?Us:Us.default,Xo=new WeakMap,zo=new WeakMap;function Ft(e,t){let n=As(e,t);if(!n.ok)return Ps(e,n.diagnostic.code,n.diagnostic.message,t.kind);let r=ae(n.ast,t);return r.ok?{ok:!0,match:{locatorKind:r.match.locatorKind,node:r.match.node,start:r.match.start,end:r.match.end}}:Ps(e,r.diagnostic.code,r.diagnostic.message,t.kind,r.diagnostic.details)}function ae(e,t){return t.kind==="jsx-node"?Au(e,t):t.kind==="jsx-attribute"?Yy(e,t):t.kind==="value"?Zy(e,t):t.kind==="expression"?Qy(e,t):t.kind==="directive"?qy(e,t):t.kind==="export"?ex(e,t):{ok:!1,diagnostic:bn("unsupported-syntax",`Unsupported locator kind: ${t.kind}`)}}function Au(e,t){return t.strategy==="source-range"?Xy(e,t):zy(e,t)}function Xy(e,t){let n=null;if(en(e,{JSXElement(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);if(i){if(!n){n=i;return}i.end-i.start<n.end-n.start&&(n=i)}},JSXFragment(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);i&&(!n||i.end-i.start<n.end-n.start)&&(n=i)},JSXExpressionContainer(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);i&&(!n||i.end-i.start<n.end-n.start)&&(n=i)},JSXText(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);i&&(!n||i.end-i.start<n.end-n.start)&&(n=i)}}),!n)return Be("jsx-node","locator-miss","JSX node not found for source-range locator");let r=n;return t.expectedIdentity&&!fx(r.path,t.expectedIdentity)?Be("jsx-node","locator-miss","JSX node failed expected identity validation"):{ok:!0,match:r}}function zy(e,t){if(t.structuralPath===""){let r=Hy(e,t.component);if(r){let o=Gy(r);if(o)return o}}let n=null;return en(e,{JSXElement(r){if(Cr(r)!==t.component||Xs(r)!==t.structuralPath)return;let i=Le("jsx-node",r);i&&(n=i,r.stop())},JSXFragment(r){if(Cr(r)!==t.component||Xs(r)!==t.structuralPath)return;let i=Le("jsx-node",r);i&&(n=i,r.stop())}}),!n&&t.expectedRange&&(n=Wy(e,t.component,t.expectedRange)),n?{ok:!0,match:n}:Be("jsx-node","locator-miss","JSX node not found for structural-path locator")}function Wy(e,t,n){let r=null;return en(e,{JSXElement(o){if(Cr(o)!==t||!Cn(o.node,n))return;let i=Le("jsx-node",o);i&&(r=i,o.stop())},JSXFragment(o){if(Cr(o)!==t||!Cn(o.node,n))return;let i=Le("jsx-node",o);i&&(r=i,o.stop())}}),r}function Hy(e,t){let n=null;return en(e,{FunctionDeclaration(r){r.node.id?.name===t&&(n=r,r.stop())},VariableDeclarator(r){if(r.node.id.type==="Identifier"&&r.node.id.name===t){let o=r.get("init");(o.isArrowFunctionExpression()||o.isFunctionExpression())&&(n=o),r.stop()}}}),n}function Gy(e){if(e.isArrowFunctionExpression()){let t=e.get("body");if(t.isBlockStatement()){let r=t.get("body").find(o=>o.isReturnStatement());if(r){let o=r.get("argument");if((o.isParenthesizedExpression()?o.get("expression"):o).isJSXFragment())return Be("jsx-node","unsupported-syntax","JSXFragment is not a supported edit target")}return null}return(t.isParenthesizedExpression()?t.get("expression"):t).isJSXFragment()?Be("jsx-node","unsupported-syntax","JSXFragment is not a supported edit target"):null}if(e.isFunctionDeclaration()||e.isFunctionExpression()){let t=e.get("body");if(t.isBlockStatement()){let n=t.get("body").find(r=>r.isReturnStatement());if(n){let r=n.get("argument");if((r.isParenthesizedExpression()?r.get("expression"):r).isJSXFragment())return Be("jsx-node","unsupported-syntax","JSXFragment is not a supported edit target")}}}return null}function Yy(e,t){let n=Au(e,t.element);if(!n.ok)return n;let s=n.match.path.get("openingElement").get("attributes").find(c=>px(c,t.name));if(!s||!s.isJSXAttribute())return Be("jsx-attribute","locator-miss",`JSX attribute '${t.name}' not found`);let a=Le("jsx-attribute",s);return a?{ok:!0,match:a}:Be("jsx-attribute","locator-miss",`JSX attribute '${t.name}' has no source range`)}function Zy(e,t){let n=tx(e,t);if(!n.ok)return n;let r=nx(n.match.path,t.path??[]);return r.ok?t.expectedRange&&!Xt(r.match.path.node.loc,t.expectedRange)?Be("value","locator-miss","Resolved value does not match expected range"):{ok:!0,match:r.match}:r}function Qy(e,t){let n=null;return en(e,{Identifier(r){if(!cx(r))return;let o=wu(r);if(!o||!Pu(o,t))return;let i=Le("expression",r);i&&(t.expectedRange&&!Xt(r.node.loc,t.expectedRange)||(n=i,r.stop()))},MemberExpression(r){let o=wu(r);if(!o||!Pu(o,t))return;let i=Le("expression",r);i&&(t.expectedRange&&!Xt(r.node.loc,t.expectedRange)||(n=i,r.stop()))}}),n?{ok:!0,match:n}:Be("expression","locator-miss","Expression not found")}function qy(e,t){let n=null;return en(e,{Program(r){let i=r.get("directives").find(a=>a.node.value.value===t.value);if(!i||t.expectedRange&&!Xt(i.node.loc,t.expectedRange))return;let s=Le("directive",i);s&&(n=s,r.stop())}}),n?{ok:!0,match:n}:Be("directive","locator-miss",`Directive '${t.value}' not found`)}function ex(e,t){let n=null;return en(e,{ExportNamedDeclaration(r){if(t.exportKind==="generate-metadata"){let c=r.get("declaration");if(c.isFunctionDeclaration()&&c.node.id?.name==="generateMetadata"){let m=Le("export",c);if(!m||t.expectedRange&&!Xt(c.node.loc,t.expectedRange))return;n=m,r.stop();return}if(!c.isVariableDeclaration())return;let l=zs(c,"generateMetadata");if(!l||!l.isVariableDeclarator())return;let d=l.get("init");if(!d.node)return;let f=Le("export",d);if(!f||t.expectedRange&&!Xt(d.node.loc,t.expectedRange))return;n=f,r.stop();return}let o=r.get("declaration");if(!o.isVariableDeclaration())return;let i=zs(o,t.exportKind==="named"?t.name:"metadata");if(!i||!i.isVariableDeclarator())return;let s=i.get("init");if(!s.node||t.expectedRange&&!Xt(s.node.loc,t.expectedRange))return;let a=Le("export",s);a&&(n=a,r.stop())},ExportDefaultDeclaration(r){if(t.exportKind!=="default")return;let o=r.get("declaration"),i=Le("export",o);i&&(t.expectedRange&&!Xt(o.node.loc,t.expectedRange)||(n=i,r.stop()))}}),n?{ok:!0,match:n}:Be("export","export-not-found",`Export '${dx(t)}' not found`)}function tx(e,t){let n=null;return en(e,{Expression(r){if(n||t.root.kind!=="expression"||!Cn(r.node,t.root.sourceRange))return;let o=Le("value",r);o&&(n=o,r.stop())},VariableDeclarator(r){if(n)return;if(t.root.kind==="binding"){if(r.node.id.type!=="Identifier"||r.node.id.name!==t.root.name)return;let u=r.get("init");if(!u.node)return;let g=Le("value",u);if(!g)return;n=g,r.stop();return}if(t.root.kind!=="hook-state")return;let o=t.root,i=r.get("id"),s=r.get("init");if(!i.isArrayPattern()||!s.isCallExpression()||i.node.elements.findIndex(u=>u?.type==="Identifier"&&u.name===o.name)!==0)return;let c=s.node.callee;if((c.type==="Identifier"?c.name:c.type==="MemberExpression"&&c.property.type==="Identifier"?c.property.name:null)!==o.hook)return;let d=o.hook==="useReducer"?1:0,f=r.get(`init.arguments.${d}`);if(!f||Array.isArray(f)||!f.node)return;let m=Le("value",f);m&&(n=m,r.stop())},ExportNamedDeclaration(r){if(n||t.root.kind!=="named-export")return;let o=r.get("declaration");if(!o.isVariableDeclaration())return;let i=zs(o,t.root.name);if(!i||!i.isVariableDeclarator())return;let s=i.get("init");if(!s.node)return;let a=Le("value",s);a&&(n=a,r.stop())},ExportDefaultDeclaration(r){if(n||t.root.kind!=="default-export")return;let o=r.get("declaration"),i=Le("value",o);i&&(n=i,r.stop())}}),n?{ok:!0,match:n}:Be("value",t.root.kind==="named-export"||t.root.kind==="default-export"?"export-not-found":t.root.kind==="expression"?"locator-miss":"binding-not-found","Value root was not found")}function nx(e,t){let n=Js(e);for(let o of t){if(n=Js(n),o.kind==="property"){if(!n.isObjectExpression())return Be("value","unsupported-syntax","Property path requires object expression");let a=n.get("properties");if(a.some(l=>!l.isObjectProperty()))return Be("value","unsupported-syntax","Spread properties are not supported");let c=a.find(l=>mx(l,o.name));if(!c||!c.isObjectProperty())return Be("value","property-not-found",`Property '${o.name}' not found`);n=c.get("value");continue}if(!n.isArrayExpression())return Be("value","unsupported-syntax","Array index path requires array expression");let i=n.get("elements");if(i.some(a=>a.node?.type==="SpreadElement"))return Be("value","unsupported-syntax","Spread array elements are not supported");let s=i[o.index];if(!s?.node)return Be("value","array-index-out-of-range",`Array index ${o.index} is out of range`);n=s}n=Js(n);let r=Le("value",n);return r?{ok:!0,match:r}:Be("value","locator-miss","Resolved value has no source range")}function Js(e){let t=e;for(;t.isTSAsExpression()||t.isTSSatisfiesExpression()||t.isTSNonNullExpression();)t=t.get("expression");return t}function Le(e,t){let n=t.node;return n.start==null||n.end==null?null:{locatorKind:e,node:n,start:n.start,end:n.end,path:t}}function Cn(e,t){return Xt(e.loc,t)}function Xt(e,t){return e?e.start.line===t.startLine&&e.start.column===t.startColumn&&e.end.line===t.endLine&&e.end.column===t.endColumn:!1}function Xs(e){let t=[],n=e,r=e.node;for(;n;){if(n.isJSXElement()){if(!Fe(n)){let o=Fu(n.node.openingElement);o&&(/^[A-Z]/.test(o)?t.unshift(`component:${o}#${Nu(n,o)}`):t.unshift(`${o}#${Nu(n,o)}`))}}else n.isJSXFragment()&&n.node===r&&t.unshift("fragment");if(!n.parentPath||sx(n.parentPath)&&!ax(n.parentPath))break;n=n.parentPath}return t.join("/")}function Nu(e,t){let n=Tu(e)??e.getFunctionParent();if(!n)return 0;let r=Xo.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let o=0,i=Xo.get(n.node)?.get(t);if(!i){let a=Xo.get(n.node);a||(a=new Map,Xo.set(n.node,a)),i=new WeakMap,a.set(t,i)}let s=n.isJSXElement()||n.isJSXFragment()?Ir(n):rx(n);for(let a of s)if(Fu(a.node.openingElement)===t){if(i.set(a.node,o),a.node===e.node)return o;o++}return i.get(e.node)??0}function rx(e){let t=zo.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!Tu(r)&&n.push(r)}}),zo.set(e.node,n),n}function Tu(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement()){if(Fe(t)){t=t.parentPath;continue}return t}t=t.parentPath}return n}function Ir(e){let t=zo.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let o of r)if(!Array.isArray(o)){if(o.isJSXElement()){if(Fe(o)){n.push(...Ir(o));continue}n.push(o);continue}if(o.isJSXFragment()){n.push(...Ir(o));continue}o.isJSXExpressionContainer()&&n.push(...Jt(o.get("expression")))}return zo.set(e.node,n),n}function Jt(e){if(e.isJSXElement())return Fe(e)?Ir(e):[e];if(e.isJSXFragment())return Ir(e);if(e.isParenthesizedExpression())return Jt(e.get("expression"));if(e.isLogicalExpression()&&ox(e.node.operator))return Jt(e.get("right"));if(e.isCallExpression()||e.isOptionalCallExpression()){let t=e.get("callee"),n=!Array.isArray(t)&&(t.isMemberExpression()||t.isOptionalMemberExpression())?t.get("property"):null;if(!Array.isArray(t)&&(t.isMemberExpression()||t.isOptionalMemberExpression())&&!t.node.computed&&n!==null&&!Array.isArray(n)&&n.isIdentifier()&&n.node.name==="map"){let r=e.get("arguments").find(o=>!Array.isArray(o)&&(o.isArrowFunctionExpression()||o.isFunctionExpression()));if(r&&!Array.isArray(r)){let o=r.get("body");if(!Array.isArray(o)){if(o.isBlockStatement()){let i=[];for(let s of o.get("body")){if(s.isVariableDeclaration())for(let a of s.get("declarations")){let c=a.get("init");(c.isJSXElement()||c.isJSXFragment())&&i.push(...Jt(c))}if(s.isReturnStatement()){let a=s.get("argument");a.isExpression()&&i.push(...Jt(a));break}}return i}else if(o.node&&o.isExpression())return Jt(o)}}}}return e.isConditionalExpression()?[...Jt(e.get("consequent")),...Jt(e.get("alternate"))]:e.isArrayExpression()?e.get("elements").flatMap(t=>Array.isArray(t)||!t.node||!t.isExpression()?[]:Jt(t)):[]}function ox(e){return e==="&&"||e==="||"||e==="??"}function Fu(e){return e.name.type==="JSXIdentifier"?e.name.name:e.name.type==="JSXMemberExpression"?ix(e.name):null}function ix(e){let t=[],n=e;for(;n.type==="JSXMemberExpression";)t.unshift(n.property.name),n=n.object;return t.unshift(n.name),t.join(".")}function Cr(e){let t=e;for(;t;){if(t.isFunctionDeclaration())return t.node.id?.name??null;if((t.isArrowFunctionExpression()||t.isFunctionExpression())&&t.parentPath?.isVariableDeclarator()){let n=t.parentPath.node.id;return n.type==="Identifier"?n.name:null}t=t.parentPath}return null}function sx(e){return!!(e.isFunctionDeclaration()||e.isFunctionExpression()||e.isArrowFunctionExpression())}function ax(e){let t=e.parentPath;if(!t||!t.isCallExpression()&&!t.isOptionalCallExpression())return!1;let n=t.get("callee"),r=!Array.isArray(n)&&(n.isMemberExpression()||n.isOptionalMemberExpression())?n.get("property"):null;if(Array.isArray(n)||!n.isMemberExpression()&&!n.isOptionalMemberExpression()||n.node.computed||r===null||Array.isArray(r)||!r.isIdentifier()||r.node.name!=="map")return!1;let o=t.get("arguments");return Array.isArray(o)?o.some(i=>!Array.isArray(i)&&i.node===e.node):!1}function cx(e){return!(!e.isExpression()||e.parentPath?.isMemberExpression({property:e.node}))}function wu(e){if(e.isIdentifier())return{base:e.node.name,path:[]};if(!e.isMemberExpression())return null;let t=[],n=e.node;for(;n.type==="MemberExpression";){if(n.computed)if(n.property.type==="NumericLiteral")t.unshift({kind:"index",index:n.property.value});else if(n.property.type==="StringLiteral")t.unshift({kind:"property",name:n.property.value});else return null;else if(n.property.type==="Identifier")t.unshift({kind:"property",name:n.property.name});else return null;if(n.object.type==="Identifier")return{base:n.object.name,path:t};if(n.object.type!=="MemberExpression")return null;n=n.object}return null}function Pu(e,t){return e.base===t.base&&lx(e.path,t.path??[])}function lx(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],o=t[n];if(r.kind!==o.kind)return!1;if(r.kind==="property"){if(o.kind!=="property"||r.name!==o.name)return!1;continue}if(o.kind!=="index"||r.index!==o.index)return!1}return!0}function ux(e){return e.key.type==="Identifier"?e.key.name:e.key.type==="StringLiteral"?e.key.value:null}function dx(e){return e.exportKind==="named"?e.name:e.exportKind}function Be(e,t,n,r){return{ok:!1,diagnostic:bn(t,n,e,r)}}function fx(e,t){return Cr(e)!==t.component?!1:Xs(e)===t.structuralPath}function px(e,t){return!e.isJSXAttribute()||e.node.name.type!=="JSXIdentifier"?!1:e.node.name.name===t}function zs(e,t){return e.get("declarations").find(n=>!n.isVariableDeclarator()||n.node.id.type!=="Identifier"?!1:n.node.id.name===t)}function mx(e,t){return e.isObjectProperty()?ux(e.node)===t:!1}import*as Ou from"@babel/parser";import{arrayExpression as bx,booleanLiteral as Sx,identifier as Ex,jsxAttribute as vx,jsxExpressionContainer as kx,jsxIdentifier as Ix,nullLiteral as Cx,numericLiteral as Rx,objectExpression as Nx,objectProperty as wx,stringLiteral as Hs}from"@babel/types";import Ws from"@babel/generator";var gx=typeof Ws=="function"?Ws:Ws.default;function hx(e){let t=e.split(`
1
+ import*as Jh from"@babel/parser";import*as Wn from"@babel/types";import*as qt from"node:path";var Ns=[".tsx",".ts",".jsx",".js"],Xh=Ns.map(e=>`/index${e}`),zh=new Set(["json","css","scss","sass","less","svg","png","jpg","jpeg","gif","webp","avif","ico","bmp","woff","woff2","ttf","otf","eot","mp4","webm","mp3","wav","ogg","pdf","txt","md","csv","xml","yaml","yml"]);function ou(e){let t=e.replace(/[?#].*$/,""),n=/\.([a-z0-9]+)$/i.exec(t);return n!==null&&zh.has(n[1].toLowerCase())}function iu(e){let t=[];for(let n of e.program.body)Wn.isImportDeclaration(n)&&typeof n.source.value=="string"&&Pt(n.source.value)&&t.push(n.source.value),Wn.isExportNamedDeclaration(n)&&n.source&&typeof n.source.value=="string"&&Pt(n.source.value)&&t.push(n.source.value),Wn.isExportAllDeclaration(n)&&typeof n.source.value=="string"&&Pt(n.source.value)&&t.push(n.source.value);return ws(e.program,t),t}function ws(e,t){if(!e||typeof e!="object")return;let n=e;if(n.type==="CallExpression"&&n.callee?.type==="Import"){let r=n.arguments?.[0];r?.type==="StringLiteral"&&typeof r.value=="string"&&Pt(r.value)&&t.push(r.value)}for(let r of Object.values(n))if(Array.isArray(r))for(let o of r)ws(o,t);else r&&typeof r=="object"&&ws(r,t)}function Pt(e){return e.startsWith("./")||e.startsWith("../")||e.startsWith("@/")}function yn(e,t){if(t.startsWith("@/"))return t.slice(2).replace(/\\/g,"/");let n=qt.dirname(e);return qt.join(n,t).replace(/\\/g,"/")}async function Wh(e,t){if(Ns.some(n=>e.endsWith(n))&&await t(e))return e;for(let n of Ns){let r=`${e}${n}`;if(await t(r))return r}for(let n of Xh){let r=`${e}${n}`;if(await t(r))return r}return null}async function xn(e,t,n){let r=await Fo(e,t,n);return r.ok?r.path:null}async function Fo(e,t,n){let r=yn(e,t);try{if(!Hh(e,t,r))return{ok:!1,diagnostic:{path:r,code:"import-not-found",message:`Local import not found: ${t}`,details:{fromFile:e,specifier:t}}};let o=await Wh(r,n);return o?{ok:!0,path:o}:{ok:!1,diagnostic:{path:r,code:"import-not-found",message:`Local import not found: ${t}`,details:{fromFile:e,specifier:t}}}}catch(o){return{ok:!1,diagnostic:{path:r,code:"import-resolve-failed",message:`Failed to resolve local import: ${t}`,details:{fromFile:e,specifier:t,reason:o instanceof Error?o.message:String(o)}}}}}function Hh(e,t,n){if(!Pt(t)||t.includes("\0")||t.includes("\\")||qt.posix.isAbsolute(n))return!1;let r=qt.posix.normalize(n);if(r===".."||r.startsWith("../"))return!1;if(t.startsWith("@/")){let o=t.slice(2);return o.length>0&&!o.split("/").some(i=>i==="..")}return!qt.posix.isAbsolute(e)}import{createHash as Yh}from"node:crypto";import*as su from"@babel/parser";function bn(e,t,n,r){return{code:e,message:t,locatorKind:n,details:r}}function K(e,t,n,r,o){return{ok:!1,source:e,diagnostic:bn(t,n,r,o)}}function Ps(e,t,n,r,o){return{ok:!1,source:e,diagnostic:bn(t,n,r,o)}}var Gh={"tsx-module":["jsx","typescript"],"ts-module":["typescript"],"next-app-entry":["jsx","typescript"]};function At(e){let{source:t,profile:n}=e;try{return{ok:!0,ast:su.parse(t,{sourceType:"module",plugins:Gh[n]})}}catch(r){return{ok:!1,source:t,diagnostic:bn("parse-failed",`AST parse failed: ${r instanceof Error?r.message:String(r)}`)}}}function As(e,t){return At({source:e,profile:au(t.kind)})}function vr(e,t){return At({source:e,profile:au(t)})}function au(e){return"next-app-entry"}function Sn(e){let{filePath:t,source:n}=e,r=t.toLowerCase().split(".").pop()??"";return r==="tsx"?"tsx-module":r==="ts"?"ts-module":r==="jsx"||r==="js"||r===""&&/<\w[\s\S]*>/.test(n)?"tsx-module":"next-app-entry"}var En=(e,t)=>{let n=At({source:t,profile:Sn({filePath:e,source:t})});return n.ok?{ok:!0,module:{file:e,source:t,sourceHash:`sha256:${Yh("sha256").update(t).digest("hex")}`,ast:n.ast,imports:iu(n.ast).map(r=>({specifier:r}))}}:{ok:!1,diagnostic:{path:e,code:"parse-failed",message:n.diagnostic.message}}};function Zh(e,t){return En(e,t)}function Qh(e,t){return yn(e,t)}import Fs from"@babel/generator";import*as pu from"@babel/parser";import _s from"@babel/traverse";import*as Ie from"@babel/types";import{computeSiteEditSourceIdentityKey as ey}from"@vcp-dev/contracts";var cu="data-vcp-ui-component",_o="components/ui";function Ut(e){if(!e)return!1;let t=Ts(e);return t===_o||t.startsWith(`${_o}/`)||t.includes(`/${_o}/`)||t.endsWith(`/${_o}`)}function vn(e,t){return e?e.startsWith("@/")||e.startsWith("~/")?Ut(e.slice(2)):e.startsWith("./")||e.startsWith("../")?Ut(Ts(`${qh(t)}/${e}`)):Ut(e):!1}function Ts(e){let n=(e.split("?")[0]??e).replace(/\\/g,"/").replace(/^\.\//,""),r=[];for(let o of n.split("/"))if(!(!o||o===".")){if(o===".."){r.pop();continue}r.push(o)}return r.join("/")}function qh(e){let t=Ts(e),n=t.lastIndexOf("/");return n>=0?t.slice(0,n):""}import{stripSiteEditRepeatInstanceKeys as ww}from"@vcp-dev/contracts";import{isSiteEditRuntimeContainerTag as Aw,isSiteEditRuntimeTextTag as Tw}from"@vcp-dev/contracts/site-edit-runtime-capability";var lu={key:"data-vcp-edit-key",parentKey:"data-vcp-edit-parent-key",movable:"data-vcp-movable",removable:"data-vcp-removable",flags:"data-vcp-flags",publicUiComponent:"data-vcp-ui-component"};var ty=typeof Fs=="function"?Fs:Fs.default,ny=typeof _s=="function"?_s:_s.default,ry=new Set(["base","body","head","html","link","meta","noscript","script","style","template","title"]),oy="suppressHydrationWarning",iy=new Set(["SiteEditBootstrap"]);function sy(e){let t=ly(e.file,e.projectRoot);if(!cy(e.source)||Ut(t))return{code:e.source,elements:[]};let n=e.attributes??lu,r=pu.parse(e.source,{sourceType:"module",plugins:["jsx","typescript"]}),o=[],i=dy(r,t);return ny(r,{JSXElement(s){let a=s.node.openingElement,c=a.name;if(!py(c)||mu(a,n.key))return;let l=gy(s)??"default",d=yy(s),f=ey(t,l,d),m=Mo(c)??"unknown",u=uy(c)?"jsx":"component-call";if(u==="component-call"&&!hy(s.node.children)&&iy.has(m))return;let g=u==="component-call"&&fy(m,i);my(a,n.key,f),g&&uu(a,cu),ay(s)&&uu(a,oy),o.push({key:f,tag:m,componentName:l,sourceFile:t,sourceKind:u})}}),o.length===0?{code:e.source,elements:o}:{code:ty(r,{jsescOption:{minimal:!0}}).code,elements:o}}function ay(e){return!e.findParent(t=>t.isJSXElement())}function cy(e){return/(?:^|[=(:,?;\[{>&|\n\r]|return\s+)\s*<(?:[A-Za-z][\w.:-]*|>)(?:\s|>|\/)/m.test(e)}function ly(e,t){let n=e.replace(/\\/g,"/").replace(/^\.\//,""),r=t?.replace(/\\/g,"/").replace(/\/+$/,"");if(r&&n.startsWith(`${r}/`))return n.slice(r.length+1);for(let[i,s]of[["/src/app/",1],["/src/components/",1],["/app/",1],["/components/",1]]){let a=n.indexOf(i);if(a>=0)return n.slice(a+s)}return n.match(/(?:^|\/)((?:src\/app|src\/components|app|components)\/.+)$/)?.[1]??n}function uy(e){return Ie.isJSXIdentifier(e)&&/^[a-z]/.test(e.name)}function Mo(e){return Ie.isJSXIdentifier(e)?e.name:Ie.isJSXMemberExpression(e)?hu(e):null}function dy(e,t){let n=new Set;for(let r of e.program.body)if(!(!Ie.isImportDeclaration(r)||!vn(r.source.value,t)))for(let o of r.specifiers)n.add(o.local.name);return n}function fy(e,t){let n=e.split(".")[0]??e;return t.has(n)}function py(e){let t=Mo(e);return!t||t==="Fragment"||t.endsWith(".Fragment")?!1:!ry.has(t)}function mu(e,t){return e.attributes.some(n=>Ie.isJSXAttribute(n)&&Ie.isJSXIdentifier(n.name,{name:t}))}function my(e,t,n){gu(e,Ie.jsxAttribute(Ie.jsxIdentifier(t),Ie.stringLiteral(n)))}function uu(e,t){mu(e,t)||gu(e,Ie.jsxAttribute(Ie.jsxIdentifier(t),null))}function gu(e,t){let n=e.attributes.findIndex(r=>Ie.isJSXSpreadAttribute(r));if(n>=0){e.attributes.splice(n,0,t);return}e.attributes.push(t)}function hu(e){return`${Ie.isJSXIdentifier(e.object)?e.object.name:hu(e.object)}.${e.property.name}`}function gy(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isVariableDeclarator()&&Ie.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}function hy(e){return e.some(t=>Ie.isJSXElement(t)||Ie.isJSXFragment(t))}var du=new WeakMap,Oo=new WeakMap,Os=new WeakMap;function yy(e){let t=du.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let i=xy(r);i&&n.unshift(i)}r=r.parentPath}let o=n.join("/");return du.set(e.node,o),o}function xy(e){let t=Mo(e.node.openingElement.name);return!t||t==="Fragment"||t.endsWith(".Fragment")?null:/^[A-Z]/.test(t)?`component:${t}#${fu(e,t)}`:`${t}#${fu(e,t)}`}function fu(e,t){let n=yu(e)??e.getFunctionParent();if(!n)return 0;let r=Os.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let o=Os.get(n.node);o||(o=new Map,Os.set(n.node,o));let i=o.get(t);i||(i=new WeakMap,o.set(t,i));let s=0,a=n.isJSXElement()||n.isJSXFragment()?Do(n):by(n);for(let c of a)if(Mo(c.node.openingElement.name)===t){if(i.set(c.node,s),c.node===e.node)return s;s+=1}return i.get(e.node)??0}function by(e){let t=Oo.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!yu(r)&&n.push(r)}}),Oo.set(e.node,n),n}function yu(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement())return t;t=t.parentPath}return n}function Do(e){let t=Oo.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let o of r)if(!Array.isArray(o)){if(o.isJSXElement()){n.push(o);continue}if(o.isJSXFragment()){n.push(...Do(o));continue}o.isJSXExpressionContainer()&&n.push(...kn(o.get("expression")))}return Oo.set(e.node,n),n}function kn(e){if(e.isJSXElement())return[e];if(e.isJSXFragment())return Do(e);if(e.isParenthesizedExpression())return kn(e.get("expression"));if(e.isLogicalExpression()&&e.node.operator==="&&")return kn(e.get("right"));if(e.isConditionalExpression())return[...kn(e.get("consequent")),...kn(e.get("alternate"))];if(e.isCallExpression()&&Ey(e.node)){let t=e.get("arguments")[0];return Sy(t)}return[]}function Sy(e){if(!e.isArrowFunctionExpression()&&!e.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return[t];if(t.isJSXFragment())return Do(t);if(t.isParenthesizedExpression())return kn(t.get("expression"));if(!t.isBlockStatement())return[];for(let n of t.get("body")){if(!n.isReturnStatement())continue;let r=n.get("argument");return r.node?kn(r):[]}return[]}function Ey(e){return Ie.isMemberExpression(e.callee)&&Ie.isIdentifier(e.callee.property)&&e.callee.property.name==="map"}import{SiteEditOperationRequestSchema as DN,SiteEditPatchPlanSchema as LN}from"@vcp-dev/contracts";function In(e){return{requestId:e.requestId,kind:e.kind,composition:e.composition,target:e.target,resultVersion:e.resultVersion,affectedFiles:e.affectedFiles,...e.output?{output:e.output}:{},...e.selectionRef?{selectionRef:e.selectionRef}:{}}}function Lo(e,t){let n=t[0]??"Site edit operation request failed contract validation.";return{ok:!1,composition:{routeId:e.composition.routeId,...e.composition.templateId!==void 0?{effectiveTemplateId:e.composition.templateId}:{}},error:{code:"INVALID_PARAMS",message:n},data:{requestId:e.id,kind:e.kind,composition:{routeId:e.composition.routeId,...e.composition.templateId!==void 0?{effectiveTemplateId:e.composition.templateId}:{}},target:e.target,resultVersion:e.documentVersion}}}function Bo(e,t){if(!e.pageComposition)throw new Error("RenderDocument is missing the required Page Composition projection.");return{siteId:t.siteId,snapshotId:t.snapshotId,composition:e.composition,version:e.version,entries:e.entries.map(n=>({key:n.key,parentKey:n.parentKey,...n.pageCompositionUnitKey?{pageCompositionUnitKey:n.pageCompositionUnitKey}:{},...n.pageCompositionActionScope?{pageCompositionActionScope:n.pageCompositionActionScope}:{},operationSummary:{canUpdateText:n.operationSummary.canUpdateText,canInsertChild:n.operationSummary.canInsertChild,canMove:n.operationSummary.canMove,canRemove:n.operationSummary.canRemove},...n.dynamicDataSummary?{dynamicDataSummary:n.dynamicDataSummary}:{}})),pageComposition:e.pageComposition.status==="unsupported"?{status:"unsupported",reason:e.pageComposition.reason,diagnostics:e.pageComposition.diagnostics}:{status:"supported",containerKey:e.pageComposition.container.key,hasBusinessMembers:e.pageComposition.businessMembers.length>0,placementUnitKeys:e.pageComposition.placementUnits.map(n=>n.key),placements:e.pageComposition.placements.map(n=>({placementKey:n.placementKey,placementUnitKey:n.placementUnitKey,relation:n.relation}))}}}function jo(e){return{composition:e.composition,key:e.key,tag:e.tag,...e.linkSourceKind?{linkSourceKind:e.linkSourceKind}:{},label:e.label,sourceLocator:e.sourceLocator,isOpaque:e.isOpaque,ancestors:e.ancestors,componentName:e.componentName,sourceFile:e.sourceFile,capabilities:vy(e.capabilities),provenanceChain:e.provenanceChain?{editMode:e.provenanceChain.editMode,diagnostics:e.provenanceChain.diagnostics}:void 0,dynamicData:e.dynamicData,...e.properties?{properties:e.properties}:{},textSegments:e.textSegments.map(t=>({index:t.index,editable:t.editable,sourceKind:t.source?.kind??null})),boundaryKind:e.boundaryKind}}function $o(e,t){let n=new Date().toISOString();return e.type==="document-changed"?{type:"site-edit.document.changed",siteId:t.siteId,snapshotId:t.snapshotId,composition:e.composition,version:e.version,at:n}:e.type==="operation-completed"?{type:"site-edit.operation.completed",siteId:t.siteId,composition:e.composition,result:In(e.result),at:n}:e.type==="operation-failed"?{type:"site-edit.operation.failed",siteId:t.siteId,requestId:e.requestId,composition:e.composition,error:e.error,at:n}:e.type==="capability-changed"?{type:"site-edit.capability.changed",siteId:t.siteId,composition:e.composition,keys:e.keys,at:n}:e.type==="graph-invalidated"?{type:"site-edit.graph.invalidated",siteId:t.siteId,composition:e.composition,at:n}:e.type==="graph-ready"?{type:"site-edit.graph.ready",siteId:t.siteId,composition:e.composition,version:e.version,at:n}:e.type==="graph-error"?{type:"site-edit.graph.error",siteId:t.siteId,composition:e.composition,message:e.message,at:n}:null}function vy(e){return{composition:e.composition,key:e.key,canUpdateText:e.canUpdateText,canInsertChild:e.canInsertChild,canMove:e.canMove,canRemove:e.canRemove,editModes:e.editModes?{updateText:e.editModes.updateText?{mode:e.editModes.updateText.mode,reasonCode:e.editModes.updateText.reasonCode}:void 0,insertChild:e.editModes.insertChild?{mode:e.editModes.insertChild.mode,reasonCode:e.editModes.insertChild.reasonCode}:void 0,move:e.editModes.move?{mode:e.editModes.move.mode,reasonCode:e.editModes.move.reasonCode}:void 0,remove:e.editModes.remove?{mode:e.editModes.remove.mode,reasonCode:e.editModes.remove.reasonCode}:void 0}:void 0,constraints:e.constraints}}import{checkGlobalsCssEdit as zR,computeSiteEditCompositionKey as WR,getSiteEditSourceDeleteProtectionReason as HR,isSiteEditTextSourcePath as GR,parseSiteEditRepeatInstanceKey as YR,SITE_EDIT_SOURCE_DELETE_CAPABILITY as ZR,stripSiteEditRepeatInstanceKeys as nt}from"@vcp-dev/contracts";import as from"node:path";import{parse as QR}from"yaml";import js from"node:path";import{TextDecoder as Iy}from"node:util";import{SITE_EDIT_SOURCE_ALLOWED_APP_FILES as bu,SITE_EDIT_SOURCE_ALLOWED_DIRS as Su,SITE_EDIT_SOURCE_ALLOWED_ROOT_FILES as Eu,SiteEditCompositionContextSchema as Cy,SiteEditSourceFileResponseSchema as Ms,SiteEditSourceLocationSchema as Ry,SiteEditSourcePathSchema as Vo,SiteEditSourceTreeResponseSchema as Ny,isSiteEditTextSourcePath as wy}from"@vcp-dev/contracts";import{createHash as ky}from"node:crypto";var kr=class{constructor(t){this.original=new Map,this.files=new Map,this.versions=new Map;for(let n of t)this.original.set(n.path,n.content),this.files.set(n.path,n.content),this.versions.set(n.path,n.version??1)}async readFile(t){let n=this.files.get(t);if(n===void 0)throw new Error(`Snapshot file not found: ${t}`);return n}async readFileBytes(t){return Buffer.from(await this.readFile(t),"utf8")}async getFileInfo(t){let n=this.files.get(t);return n===void 0?null:{path:t,sizeBytes:Buffer.byteLength(n,"utf8")}}async writeFile(t,n){this.files.set(t,n)}async createExclusive(t,n){if(this.files.has(t))throw Object.assign(new Error(`Snapshot file already exists: ${t}`),{code:"EEXIST"});this.files.set(t,n)}async deleteFile(t){this.files.delete(t)}async exists(t){return this.files.has(t)}async listFiles(t={}){let n=t.roots??[],r=[...this.files.keys()].filter(a=>n.length===0?!0:n.some(c=>a===c||a.startsWith(`${c}/`))),o=[],i=new Set,s=0;for(let a of r.sort()){let c=Buffer.byteLength(this.files.get(a)??"","utf8"),l=a.split("/").length;if(t.maxDepth!==void 0&&l>t.maxDepth){i.add("max-depth");continue}if(t.maxFiles!==void 0&&o.length>=t.maxFiles){i.add("max-files");break}if(t.maxTotalBytes!==void 0&&s+c>t.maxTotalBytes){i.add("max-total-bytes");break}o.push({path:a,sizeBytes:c}),s+=c}return i.size>0?{files:o,truncated:{reasons:[...i]}}:{files:o}}getVersion(t){return this.versions.get(t)??0}bumpVersion(t){let n=this.getVersion(t)+1;return this.versions.set(t,n),n}getChangedFiles(){let t=new Set([...this.original.keys(),...this.files.keys()]),n=[];for(let r of[...t].sort()){let o=this.original.get(r),i=this.files.get(r);o!==i&&n.push({path:r,before:o,after:i})}return n}};function Ee(e){return`sha256:${ky("sha256").update(e).digest("hex")}`}var Py=[...Eu,...bu,...Su];function $s(e){if(!e.composition)throw new Error("Composition unavailable for source access policy.");return Cy.parse(e.composition)}var Ds=2e3,Ls=12,Bs=24*1024*1024,xu=512*1024,Ay=new Set(["image/avif","image/gif","image/jpeg","image/png","image/webp","image/x-icon"]),Ty={".avif":"image/avif",".bin":"application/octet-stream",".eot":"application/vnd.ms-fontobject",".gif":"image/gif",".glb":"model/gltf-binary",".ico":"image/x-icon",".jpeg":"image/jpeg",".jpg":"image/jpeg",".mp3":"audio/mpeg",".mp4":"video/mp4",".pdf":"application/pdf",".png":"image/png",".svg":"image/svg+xml",".ttf":"font/ttf",".wasm":"application/wasm",".webm":"video/webm",".webp":"image/webp",".woff":"font/woff",".woff2":"font/woff2",".zip":"application/zip"},Fy={".cjs":"javascript",".css":"css",".cts":"typescript",".html":"html",".js":"javascript",".jsx":"javascript",".json":"json",".md":"markdown",".mdx":"markdown",".mjs":"javascript",".mts":"typescript",".ts":"typescript",".tsx":"typescript",".txt":"plaintext",".yaml":"yaml",".yml":"yaml"},_y=new Iy("utf-8",{fatal:!0});async function Ko(e,t={}){let n=$s(t),{files:r,truncated:o}=await $y(e,t),i=Uy(r.map(s=>s.metadata));return Ny.parse({composition:n,nodes:i,defaultPath:Jy(r.map(s=>s.metadata)),totalFiles:r.length,...o?{truncated:o}:{}})}async function Uo(e,t,n={}){let r=$s(n),o=Vo.parse(t.path),i=await My(e,o,n);if(!i)throw new Error(`Source file not found: ${o}`);if(Ks(o)){let a=Iu(o),c=await Ly(e,{path:o,sizeBytes:i.sizeBytes,mimeType:a});return Ms.parse({composition:r,path:o,kind:"binary",language:null,sizeBytes:i.sizeBytes,mimeType:a,readonly:!0,...c})}let s=await Vs(e,o);return s.ok?Ms.parse({composition:r,path:o,kind:"text",language:Cu(o),sizeBytes:s.sizeBytes,contentHash:Ee(s.content),readonly:!1,content:s.content}):Ms.parse({composition:r,path:o,kind:"binary",language:null,sizeBytes:s.sizeBytes,mimeType:"application/octet-stream",readonly:!0,previewUnavailableReason:"unsupported-mime"})}async function Vs(e,t){if(e.readFileBytes){let o=await e.readFileBytes(t),i=Oy(o);return i===null?{ok:!1,sizeBytes:o.byteLength}:{ok:!0,content:i,sizeBytes:o.byteLength}}let n=await e.readFile(t),r=Buffer.byteLength(n,"utf8");return n.includes("\0")?{ok:!1,sizeBytes:r}:{ok:!0,content:n,sizeBytes:r}}function Oy(e){if(e.includes(0))return null;try{return _y.decode(e)}catch{return null}}async function My(e,t,n){if(!By(t,n))return null;let r=await Dy(e,t);return r?{path:t,sizeBytes:r.sizeBytes}:null}async function Dy(e,t){if(e.getFileInfo)return e.getFileInfo(t);if(e.listFiles){let o=vu(await e.listFiles({roots:[t],maxFiles:1,maxDepth:t.split("/").length})).files.find(i=>i.path===t);if(o)return o}if(!await e.exists(t))return null;if(e.readFileBytes){let r=await e.readFileBytes(t);return{path:t,sizeBytes:r.byteLength}}if(Ks(t))return{path:t,sizeBytes:0};let n=await e.readFile(t);return{path:t,sizeBytes:Buffer.byteLength(n,"utf8")}}async function Ly(e,t){if(!Ay.has(t.mimeType))return{previewUnavailableReason:"unsupported-mime"};if(t.sizeBytes>xu)return{previewUnavailableReason:"too-large"};if(!e.readFileBytes)return{previewUnavailableReason:"bytes-unavailable"};let n=await e.readFileBytes(t.path);return n.byteLength>xu?{previewUnavailableReason:"too-large"}:{contentBase64:Buffer.from(n).toString("base64")}}function By(e,t){return Eu.some(n=>n===e)||bu.some(n=>n===e)||Su.some(n=>e===n||e.startsWith(`${n}/`))?!0:!e.startsWith("app/")&&!e.startsWith("src/app/")?!1:(t.routeEntryFiles??[]).some(n=>{let r=Vo.safeParse(n);return r.success&&r.data===e})}function Jo(e,t){if(!t.sourceLocator)throw new Error(`Source location not available for key: ${e.key}`);return Ry.parse({key:e.key,composition:t.composition,sourceFile:t.sourceLocator.sourceFile,componentName:t.sourceLocator.componentName,openingElementRange:{startLine:t.sourceLocator.openingElementRange.startLine,startColumn:t.sourceLocator.openingElementRange.startColumn,endLine:t.sourceLocator.openingElementRange.endLine,endColumn:t.sourceLocator.openingElementRange.endColumn},structuralPath:t.sourceLocator.structuralPath,textPreview:t.sourceLocator.textPreview})}function vu(e){return Array.isArray(e)?{files:e}:e}function jy(e){return["max-files","max-depth","max-total-bytes"].filter(n=>e.includes(n))}async function $y(e,t){if(!e.listFiles)throw new Error("Source file listing is unavailable.");let n=vu(await e.listFiles({roots:Vy(t),maxFiles:Ds+1,maxDepth:Ls,maxTotalBytes:Bs+1})),r=new Map,o=new Set(n.truncated?.reasons),i=0;for(let a of[...n.files].sort((c,l)=>c.path.localeCompare(l.path))){let c=Vo.safeParse(a.path);if(!c.success)continue;let l=c.data;if(l.split("/").length>Ls){o.add("max-depth");continue}if(r.size>=Ds){o.add("max-files");break}if(i+a.sizeBytes>Bs){o.add("max-total-bytes");break}r.set(l,{path:l,sizeBytes:a.sizeBytes,metadata:Ky(l,a.sizeBytes,$s(t))}),i+=a.sizeBytes}return{files:[...r.values()].sort((a,c)=>a.path.localeCompare(c.path)),...o.size>0?{truncated:{reasons:jy([...o]),maxFiles:Ds,maxDepth:Ls,maxTotalBytes:Bs}}:{}}}function Vy(e){let t=new Set(Py);for(let n of e.routeEntryFiles??[]){let r=Vo.safeParse(n);r.success&&(r.data.startsWith("app/")||r.data.startsWith("src/app/"))&&t.add(r.data)}return[...t]}function Ky(e,t,n){return Ks(e)?{composition:n,path:e,kind:"binary",language:null,sizeBytes:t,mimeType:Iu(e),readonly:!0}:{composition:n,path:e,kind:"text",language:Cu(e),sizeBytes:t,readonly:!1}}function Uy(e){let t=[];for(let n of e){let r=n.path.split("/"),o=t,i="";for(let[s,a]of r.entries()){i=i?`${i}/${a}`:a;let c=s===r.length-1,l=o.find(d=>d.name===a);if(l||(l=c?{kind:"file",name:a,path:i,file:n}:{kind:"directory",name:a,path:i,children:[]},o.push(l)),c){if(l.kind!=="file")throw new Error(`Source tree path collision: ${n.path}`);l.file=n}else{if(l.kind!=="directory")throw new Error(`Source tree path collision: ${n.path}`);o=l.children}}}return ku(t)}function ku(e){return e.map(t=>t.kind==="directory"?{...t,children:ku(t.children)}:t).sort((t,n)=>t.kind!==n.kind?t.kind==="directory"?-1:1:t.name.localeCompare(n.name))}function Jy(e){let t=e.find(r=>r.path.toLowerCase()==="design.md");if(t)return t.path;let n=e.find(r=>r.path==="app/page.tsx");return n?n.path:e.find(r=>r.kind==="text")?.path??e.at(0)?.path}function Ks(e){return!wy(e)}function Iu(e){let t=js.posix.extname(e).toLowerCase();return!t&&js.posix.basename(e).toLowerCase()==="favicon"?"image/x-icon":Ty[t]??"application/octet-stream"}function Cu(e){let t=js.posix.extname(e).toLowerCase();return Fy[t]??"plaintext"}import Us from"@babel/traverse";import*as Tt from"@babel/types";function Fe(e){if(e.isJSXFragment())return!0;if(!e.isJSXElement())return!1;let t=e.node.openingElement.name;if(Tt.isJSXIdentifier(t)){let o=e.scope.getBinding(t.name);if(!o)return!1;let i=o.path;if(!i.isImportSpecifier())return!1;let s=i.node.imported;return(Tt.isIdentifier(s)&&s.name==="Fragment"||Tt.isStringLiteral(s)&&s.value==="Fragment")&&Ru(i.parentPath)}if(!Tt.isJSXMemberExpression(t)||!Tt.isJSXIdentifier(t.property)||t.property.name!=="Fragment"||!Tt.isJSXIdentifier(t.object))return!1;let n=e.scope.getBinding(t.object.name);if(!n)return!1;let r=n.path;return(r.isImportDefaultSpecifier()||r.isImportNamespaceSpecifier())&&Ru(r.parentPath)}function Ru(e){return e?.isImportDeclaration()===!0&&e.node.source.value==="react"}var en=typeof Us=="function"?Us:Us.default,Xo=new WeakMap,zo=new WeakMap;function Ft(e,t){let n=As(e,t);if(!n.ok)return Ps(e,n.diagnostic.code,n.diagnostic.message,t.kind);let r=ae(n.ast,t);return r.ok?{ok:!0,match:{locatorKind:r.match.locatorKind,node:r.match.node,start:r.match.start,end:r.match.end}}:Ps(e,r.diagnostic.code,r.diagnostic.message,t.kind,r.diagnostic.details)}function ae(e,t){return t.kind==="jsx-node"?Au(e,t):t.kind==="jsx-attribute"?Yy(e,t):t.kind==="value"?Zy(e,t):t.kind==="expression"?Qy(e,t):t.kind==="directive"?qy(e,t):t.kind==="export"?ex(e,t):{ok:!1,diagnostic:bn("unsupported-syntax",`Unsupported locator kind: ${t.kind}`)}}function Au(e,t){return t.strategy==="source-range"?Xy(e,t):zy(e,t)}function Xy(e,t){let n=null;if(en(e,{JSXElement(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);if(i){if(!n){n=i;return}i.end-i.start<n.end-n.start&&(n=i)}},JSXFragment(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);i&&(!n||i.end-i.start<n.end-n.start)&&(n=i)},JSXExpressionContainer(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);i&&(!n||i.end-i.start<n.end-n.start)&&(n=i)},JSXText(o){if(!Cn(o.node,t.sourceRange))return;let i=Le("jsx-node",o);i&&(!n||i.end-i.start<n.end-n.start)&&(n=i)}}),!n)return Be("jsx-node","locator-miss","JSX node not found for source-range locator");let r=n;return t.expectedIdentity&&!fx(r.path,t.expectedIdentity)?Be("jsx-node","locator-miss","JSX node failed expected identity validation"):{ok:!0,match:r}}function zy(e,t){if(t.structuralPath===""){let r=Hy(e,t.component);if(r){let o=Gy(r);if(o)return o}}let n=null;return en(e,{JSXElement(r){if(Cr(r)!==t.component||Xs(r)!==t.structuralPath)return;let i=Le("jsx-node",r);i&&(n=i,r.stop())},JSXFragment(r){if(Cr(r)!==t.component||Xs(r)!==t.structuralPath)return;let i=Le("jsx-node",r);i&&(n=i,r.stop())}}),!n&&t.expectedRange&&(n=Wy(e,t.component,t.expectedRange)),n?{ok:!0,match:n}:Be("jsx-node","locator-miss","JSX node not found for structural-path locator")}function Wy(e,t,n){let r=null;return en(e,{JSXElement(o){if(Cr(o)!==t||!Cn(o.node,n))return;let i=Le("jsx-node",o);i&&(r=i,o.stop())},JSXFragment(o){if(Cr(o)!==t||!Cn(o.node,n))return;let i=Le("jsx-node",o);i&&(r=i,o.stop())}}),r}function Hy(e,t){let n=null;return en(e,{FunctionDeclaration(r){r.node.id?.name===t&&(n=r,r.stop())},VariableDeclarator(r){if(r.node.id.type==="Identifier"&&r.node.id.name===t){let o=r.get("init");(o.isArrowFunctionExpression()||o.isFunctionExpression())&&(n=o),r.stop()}}}),n}function Gy(e){if(e.isArrowFunctionExpression()){let t=e.get("body");if(t.isBlockStatement()){let r=t.get("body").find(o=>o.isReturnStatement());if(r){let o=r.get("argument");if((o.isParenthesizedExpression()?o.get("expression"):o).isJSXFragment())return Be("jsx-node","unsupported-syntax","JSXFragment is not a supported edit target")}return null}return(t.isParenthesizedExpression()?t.get("expression"):t).isJSXFragment()?Be("jsx-node","unsupported-syntax","JSXFragment is not a supported edit target"):null}if(e.isFunctionDeclaration()||e.isFunctionExpression()){let t=e.get("body");if(t.isBlockStatement()){let n=t.get("body").find(r=>r.isReturnStatement());if(n){let r=n.get("argument");if((r.isParenthesizedExpression()?r.get("expression"):r).isJSXFragment())return Be("jsx-node","unsupported-syntax","JSXFragment is not a supported edit target")}}}return null}function Yy(e,t){let n=Au(e,t.element);if(!n.ok)return n;let s=n.match.path.get("openingElement").get("attributes").find(c=>px(c,t.name));if(!s||!s.isJSXAttribute())return Be("jsx-attribute","locator-miss",`JSX attribute '${t.name}' not found`);let a=Le("jsx-attribute",s);return a?{ok:!0,match:a}:Be("jsx-attribute","locator-miss",`JSX attribute '${t.name}' has no source range`)}function Zy(e,t){let n=tx(e,t);if(!n.ok)return n;let r=nx(n.match.path,t.path??[]);return r.ok?t.expectedRange&&!Xt(r.match.path.node.loc,t.expectedRange)?Be("value","locator-miss","Resolved value does not match expected range"):{ok:!0,match:r.match}:r}function Qy(e,t){let n=null;return en(e,{Identifier(r){if(!cx(r))return;let o=wu(r);if(!o||!Pu(o,t))return;let i=Le("expression",r);i&&(t.expectedRange&&!Xt(r.node.loc,t.expectedRange)||(n=i,r.stop()))},MemberExpression(r){let o=wu(r);if(!o||!Pu(o,t))return;let i=Le("expression",r);i&&(t.expectedRange&&!Xt(r.node.loc,t.expectedRange)||(n=i,r.stop()))}}),n?{ok:!0,match:n}:Be("expression","locator-miss","Expression not found")}function qy(e,t){let n=null;return en(e,{Program(r){let i=r.get("directives").find(a=>a.node.value.value===t.value);if(!i||t.expectedRange&&!Xt(i.node.loc,t.expectedRange))return;let s=Le("directive",i);s&&(n=s,r.stop())}}),n?{ok:!0,match:n}:Be("directive","locator-miss",`Directive '${t.value}' not found`)}function ex(e,t){let n=null;return en(e,{ExportNamedDeclaration(r){if(t.exportKind==="generate-metadata"){let c=r.get("declaration");if(c.isFunctionDeclaration()&&c.node.id?.name==="generateMetadata"){let m=Le("export",c);if(!m||t.expectedRange&&!Xt(c.node.loc,t.expectedRange))return;n=m,r.stop();return}if(!c.isVariableDeclaration())return;let l=zs(c,"generateMetadata");if(!l||!l.isVariableDeclarator())return;let d=l.get("init");if(!d.node)return;let f=Le("export",d);if(!f||t.expectedRange&&!Xt(d.node.loc,t.expectedRange))return;n=f,r.stop();return}let o=r.get("declaration");if(!o.isVariableDeclaration())return;let i=zs(o,t.exportKind==="named"?t.name:"metadata");if(!i||!i.isVariableDeclarator())return;let s=i.get("init");if(!s.node||t.expectedRange&&!Xt(s.node.loc,t.expectedRange))return;let a=Le("export",s);a&&(n=a,r.stop())},ExportDefaultDeclaration(r){if(t.exportKind!=="default")return;let o=r.get("declaration"),i=Le("export",o);i&&(t.expectedRange&&!Xt(o.node.loc,t.expectedRange)||(n=i,r.stop()))}}),n?{ok:!0,match:n}:Be("export","export-not-found",`Export '${dx(t)}' not found`)}function tx(e,t){let n=null;return en(e,{Expression(r){if(n||t.root.kind!=="expression"||!Cn(r.node,t.root.sourceRange))return;let o=Le("value",r);o&&(n=o,r.stop())},VariableDeclarator(r){if(n)return;if(t.root.kind==="binding"){if(r.node.id.type!=="Identifier"||r.node.id.name!==t.root.name)return;let u=r.get("init");if(!u.node)return;let g=Le("value",u);if(!g)return;n=g,r.stop();return}if(t.root.kind!=="hook-state")return;let o=t.root,i=r.get("id"),s=r.get("init");if(!i.isArrayPattern()||!s.isCallExpression()||i.node.elements.findIndex(u=>u?.type==="Identifier"&&u.name===o.name)!==0)return;let c=s.node.callee;if((c.type==="Identifier"?c.name:c.type==="MemberExpression"&&c.property.type==="Identifier"?c.property.name:null)!==o.hook)return;let d=o.hook==="useReducer"?1:0,f=r.get(`init.arguments.${d}`);if(!f||Array.isArray(f)||!f.node)return;let m=Le("value",f);m&&(n=m,r.stop())},ExportNamedDeclaration(r){if(n||t.root.kind!=="named-export")return;let o=r.get("declaration");if(!o.isVariableDeclaration())return;let i=zs(o,t.root.name);if(!i||!i.isVariableDeclarator())return;let s=i.get("init");if(!s.node)return;let a=Le("value",s);a&&(n=a,r.stop())},ExportDefaultDeclaration(r){if(n||t.root.kind!=="default-export")return;let o=r.get("declaration"),i=Le("value",o);i&&(n=i,r.stop())}}),n?{ok:!0,match:n}:Be("value",t.root.kind==="named-export"||t.root.kind==="default-export"?"export-not-found":t.root.kind==="expression"?"locator-miss":"binding-not-found","Value root was not found")}function nx(e,t){let n=Js(e);for(let o of t){if(n=Js(n),o.kind==="property"){if(!n.isObjectExpression())return Be("value","unsupported-syntax","Property path requires object expression");let a=n.get("properties");if(a.some(l=>!l.isObjectProperty()))return Be("value","unsupported-syntax","Spread properties are not supported");let c=a.find(l=>mx(l,o.name));if(!c||!c.isObjectProperty())return Be("value","property-not-found",`Property '${o.name}' not found`);n=c.get("value");continue}if(!n.isArrayExpression())return Be("value","unsupported-syntax","Array index path requires array expression");let i=n.get("elements");if(i.some(a=>a.node?.type==="SpreadElement"))return Be("value","unsupported-syntax","Spread array elements are not supported");let s=i[o.index];if(!s?.node)return Be("value","array-index-out-of-range",`Array index ${o.index} is out of range`);n=s}n=Js(n);let r=Le("value",n);return r?{ok:!0,match:r}:Be("value","locator-miss","Resolved value has no source range")}function Js(e){let t=e;for(;t.isTSAsExpression()||t.isTSSatisfiesExpression()||t.isTSNonNullExpression();)t=t.get("expression");return t}function Le(e,t){let n=t.node;return n.start==null||n.end==null?null:{locatorKind:e,node:n,start:n.start,end:n.end,path:t}}function Cn(e,t){return Xt(e.loc,t)}function Xt(e,t){return e?e.start.line===t.startLine&&e.start.column===t.startColumn&&e.end.line===t.endLine&&e.end.column===t.endColumn:!1}function Xs(e){let t=[],n=e,r=e.node;for(;n;){if(n.isJSXElement()){if(!Fe(n)){let o=Fu(n.node.openingElement);o&&(/^[A-Z]/.test(o)?t.unshift(`component:${o}#${Nu(n,o)}`):t.unshift(`${o}#${Nu(n,o)}`))}}else n.isJSXFragment()&&n.node===r&&t.unshift("fragment");if(!n.parentPath||sx(n.parentPath)&&!ax(n.parentPath))break;n=n.parentPath}return t.join("/")}function Nu(e,t){let n=Tu(e)??e.getFunctionParent();if(!n)return 0;let r=Xo.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let o=0,i=Xo.get(n.node)?.get(t);if(!i){let a=Xo.get(n.node);a||(a=new Map,Xo.set(n.node,a)),i=new WeakMap,a.set(t,i)}let s=n.isJSXElement()||n.isJSXFragment()?Ir(n):rx(n);for(let a of s)if(Fu(a.node.openingElement)===t){if(i.set(a.node,o),a.node===e.node)return o;o++}return i.get(e.node)??0}function rx(e){let t=zo.get(e.node);if(t)return t;let n=[];return e.traverse({JSXElement(r){r.getFunctionParent()?.node===e.node&&!Tu(r)&&n.push(r)}}),zo.set(e.node,n),n}function Tu(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement()){if(Fe(t)){t=t.parentPath;continue}return t}t=t.parentPath}return n}function Ir(e){let t=zo.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let o of r)if(!Array.isArray(o)){if(o.isJSXElement()){if(Fe(o)){n.push(...Ir(o));continue}n.push(o);continue}if(o.isJSXFragment()){n.push(...Ir(o));continue}o.isJSXExpressionContainer()&&n.push(...Jt(o.get("expression")))}return zo.set(e.node,n),n}function Jt(e){if(e.isJSXElement())return Fe(e)?Ir(e):[e];if(e.isJSXFragment())return Ir(e);if(e.isParenthesizedExpression())return Jt(e.get("expression"));if(e.isLogicalExpression()&&ox(e.node.operator))return Jt(e.get("right"));if(e.isCallExpression()||e.isOptionalCallExpression()){let t=e.get("callee"),n=!Array.isArray(t)&&(t.isMemberExpression()||t.isOptionalMemberExpression())?t.get("property"):null;if(!Array.isArray(t)&&(t.isMemberExpression()||t.isOptionalMemberExpression())&&!t.node.computed&&n!==null&&!Array.isArray(n)&&n.isIdentifier()&&n.node.name==="map"){let r=e.get("arguments").find(o=>!Array.isArray(o)&&(o.isArrowFunctionExpression()||o.isFunctionExpression()));if(r&&!Array.isArray(r)){let o=r.get("body");if(!Array.isArray(o)){if(o.isBlockStatement()){let i=[];for(let s of o.get("body")){if(s.isVariableDeclaration())for(let a of s.get("declarations")){let c=a.get("init");(c.isJSXElement()||c.isJSXFragment())&&i.push(...Jt(c))}if(s.isReturnStatement()){let a=s.get("argument");a.isExpression()&&i.push(...Jt(a));break}}return i}else if(o.node&&o.isExpression())return Jt(o)}}}}return e.isConditionalExpression()?[...Jt(e.get("consequent")),...Jt(e.get("alternate"))]:e.isArrayExpression()?e.get("elements").flatMap(t=>Array.isArray(t)||!t.node||!t.isExpression()?[]:Jt(t)):[]}function ox(e){return e==="&&"||e==="||"||e==="??"}function Fu(e){return e.name.type==="JSXIdentifier"?e.name.name:e.name.type==="JSXMemberExpression"?ix(e.name):null}function ix(e){let t=[],n=e;for(;n.type==="JSXMemberExpression";)t.unshift(n.property.name),n=n.object;return t.unshift(n.name),t.join(".")}function Cr(e){let t=e;for(;t;){if(t.isFunctionDeclaration())return t.node.id?.name??null;if((t.isArrowFunctionExpression()||t.isFunctionExpression())&&t.parentPath?.isVariableDeclarator()){let n=t.parentPath.node.id;return n.type==="Identifier"?n.name:null}t=t.parentPath}return null}function sx(e){return!!(e.isFunctionDeclaration()||e.isFunctionExpression()||e.isArrowFunctionExpression())}function ax(e){let t=e.parentPath;if(!t||!t.isCallExpression()&&!t.isOptionalCallExpression())return!1;let n=t.get("callee"),r=!Array.isArray(n)&&(n.isMemberExpression()||n.isOptionalMemberExpression())?n.get("property"):null;if(Array.isArray(n)||!n.isMemberExpression()&&!n.isOptionalMemberExpression()||n.node.computed||r===null||Array.isArray(r)||!r.isIdentifier()||r.node.name!=="map")return!1;let o=t.get("arguments");return Array.isArray(o)?o.some(i=>!Array.isArray(i)&&i.node===e.node):!1}function cx(e){return!(!e.isExpression()||e.parentPath?.isMemberExpression({property:e.node}))}function wu(e){if(e.isIdentifier())return{base:e.node.name,path:[]};if(!e.isMemberExpression())return null;let t=[],n=e.node;for(;n.type==="MemberExpression";){if(n.computed)if(n.property.type==="NumericLiteral")t.unshift({kind:"index",index:n.property.value});else if(n.property.type==="StringLiteral")t.unshift({kind:"property",name:n.property.value});else return null;else if(n.property.type==="Identifier")t.unshift({kind:"property",name:n.property.name});else return null;if(n.object.type==="Identifier")return{base:n.object.name,path:t};if(n.object.type!=="MemberExpression")return null;n=n.object}return null}function Pu(e,t){return e.base===t.base&&lx(e.path,t.path??[])}function lx(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){let r=e[n],o=t[n];if(r.kind!==o.kind)return!1;if(r.kind==="property"){if(o.kind!=="property"||r.name!==o.name)return!1;continue}if(o.kind!=="index"||r.index!==o.index)return!1}return!0}function ux(e){return e.key.type==="Identifier"?e.key.name:e.key.type==="StringLiteral"?e.key.value:null}function dx(e){return e.exportKind==="named"?e.name:e.exportKind}function Be(e,t,n,r){return{ok:!1,diagnostic:bn(t,n,e,r)}}function fx(e,t){return Cr(e)!==t.component?!1:Xs(e)===t.structuralPath}function px(e,t){return!e.isJSXAttribute()||e.node.name.type!=="JSXIdentifier"?!1:e.node.name.name===t}function zs(e,t){return e.get("declarations").find(n=>!n.isVariableDeclarator()||n.node.id.type!=="Identifier"?!1:n.node.id.name===t)}function mx(e,t){return e.isObjectProperty()?ux(e.node)===t:!1}import*as Ou from"@babel/parser";import{arrayExpression as bx,booleanLiteral as Sx,identifier as Ex,jsxAttribute as vx,jsxExpressionContainer as kx,jsxIdentifier as Ix,nullLiteral as Cx,numericLiteral as Rx,objectExpression as Nx,objectProperty as wx,stringLiteral as Hs}from"@babel/types";import Ws from"@babel/generator";var gx=typeof Ws=="function"?Ws:Ws.default;function hx(e){let t=e.split(`
2
2
  `),n=[],r=!1;for(let s of t){let a=s.match(/^(\s+)/);if(a){let c=a[1];c.includes(" ")?r=!0:c.length>0&&n.push(c.length)}}if(r&&t.every(a=>{let c=a.match(/^(\s+)/);return!c||c[1].includes(" ")}))return"tab";if(n.length===0)return"2";function o(s,a){return a===0?s:o(a,s%a)}let i=n[0];for(let s=1;s<n.length;s++)i=o(i,n[s]);return i>=4?"4":"2"}function yx(e,t){let n=e.match(/^(\s+)(.*)/s);if(!n)return e;let r=n[1],o=n[2];if(r.length===0)return e;let i=r.includes(" ")?r.split(" ").length-1:Math.max(1,Math.round(r.length/2)),s=Math.min(Math.max(i,0),20);return t==="tab"?" ".repeat(s)+o:t==="4"?" ".repeat(s)+o:" ".repeat(s)+o}function xx(e,t){return e.split(`
3
3
  `).map(r=>yx(r,t)).join(`
4
4
  `)}function Wo(e){let{ast:t,source:n}=e;try{let r=hx(n),i=gx(t,{comments:!0,jsescOption:{minimal:!0,quotes:"single"}},n).code;return r!=="2"&&(i=xx(i,r)),{ok:!0,source:i}}catch(r){return K(n,"printer-failed",`AST print failed: ${r instanceof Error?r.message:String(r)}`)}}function _u(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t|=0}return`0x${Math.abs(t).toString(16)}`}function Rr(e,t,n){return{ok:!0,source:t,operation:{type:n.kind,nodeId:n.target,kind:n.kind,target:n.target,beforeSourceHash:_u(e),afterSourceHash:_u(t),inverse:n.inverse}}}function me(e,t,n){let r=Wo({ast:e,source:t});return r.ok?Rr(t,r.source,n):r}function Ce(e,t){let n=vr(e,t);return n.ok?{ok:!0,ast:n.ast}:{ok:!1,result:{ok:!1,source:e,diagnostic:n.diagnostic}}}function Ho(e,t){return Wo({ast:e,source:t})}function Px(e,t,n){let r=ae(e,t);return r.ok?{ok:!0,match:r.match}:{ok:!1,result:{ok:!1,source:n,diagnostic:r.diagnostic}}}function Hn(e,t,n){let r=Px(e,t,n);return r.ok?r.match.path.isJSXElement()?r:{ok:!1,result:K(n,"unsupported-syntax","JSX locator must resolve to JSXElement","jsx-node")}:r}function tn(e){return typeof e=="string"?Hs(e):typeof e=="number"?Rx(e):typeof e=="boolean"?Sx(e):e===null?Cx():Array.isArray(e)?bx(e.map(t=>tn(t))):Nx(Object.entries(e).map(([t,n])=>{let r=wx(Gs(t),tn(n));return t==="__proto__"&&(r.computed=!0),r}))}function Ax(e){return typeof e=="string"?Hs(e):kx(tn(e))}function Nr(e,t){return vx(Ix(e),Ax(t))}function Go(e,t){try{let r=Ou.parse(`const __VD_NODE__ = (${t});`,{sourceType:"module",plugins:["jsx","typescript"]}).program.body[0];return r?.type!=="VariableDeclaration"||r.declarations[0]?.type!=="VariableDeclarator"||!r.declarations[0].init||r.declarations[0].init.type!=="JSXElement"&&r.declarations[0].init.type!=="JSXFragment"?{ok:!1,result:K(e,"unsupported-syntax","Provided JSX source does not resolve to a JSX node","jsx-node")}:{ok:!0,node:r.declarations[0].init}}catch(n){return{ok:!1,result:K(e,"parse-failed",`AST parse failed: ${n instanceof Error?n.message:String(n)}`,"jsx-node")}}}function Gs(e){return/^[$A-Z_][0-9A-Z_$]*$/i.test(e)?Ex(e):Hs(e)}function Yo(e){let{source:t,locator:n,segmentIndex:r,newText:o}=e,i=Ce(t,"jsx-node");if(!i.ok)return i.result;let s=ae(i.ast,n);if(!s.ok)return{ok:!1,source:t,diagnostic:s.diagnostic};let c=Tx(s.match.path)[r];if(!c)return K(t,"locator-miss",`Text segment ${r} not found`,"jsx-node");switch(c.kind){case"jsx-text":c.path.node.value=Fx(c.path.node.value,o);break;case"string-literal":c.path.node.value=o;break;case"template-literal":{let l=c.quasiIndex;c.path.node.quasis[l].value.raw=o,c.path.node.quasis[l].value.cooked=o;break}}return me(i.ast,t,{kind:"update-text",target:"jsx-node",inverse:"restore-text"})}function Tx(e){let t=[],n=e.isJSXElement()||e.isJSXFragment()?e.get("children"):[];for(let r of n){if(r.isJSXText()){r.node.value.trim().length>0&&t.push({kind:"jsx-text",path:r});continue}if(r.isJSXExpressionContainer()){let o=_x(r.get("expression"));o.length>0&&t.push(...o)}}return t}function Fx(e,t){let n=e.match(/^\s*/)?.[0]??"",r=e.match(/\s*$/)?.[0]??"";return`${n}${t.trim()}${r}`}function _x(e){if(e.isStringLiteral())return[{kind:"string-literal",path:e}];if(e.isTemplateLiteral()){let t=[],n=e.node.quasis;for(let r=0;r<n.length;r++)n[r].value.raw.trim().length>0&&t.push({kind:"template-literal",path:e,quasiIndex:r});if(t.length>0)return t}return e.isCallExpression()?[]:[]}import{nullLiteral as Ys}from"@babel/types";function Gn(e){let{source:t,locator:n}=e,r=Ce(t,"jsx-node");if(!r.ok)return r.result;let o=ae(r.ast,n);return o.ok?(Ox(o.match.path),me(r.ast,t,{kind:"remove-node",target:"jsx-node",inverse:"insert-child"})):{ok:!1,source:t,diagnostic:o.diagnostic}}function Ox(e){if(e.parentPath?.isConditionalExpression()&&(e.key==="consequent"||e.key==="alternate")){e.replaceWith(Ys());return}if(e.parentPath?.isArrowFunctionExpression()&&e.key==="body"){e.replaceWith(Ys());return}if(e.parentPath?.isReturnStatement()&&e.key==="argument"){e.replaceWith(Ys());return}e.remove()}import{cloneNode as Mx}from"@babel/types";function Zo(e){let t=Ce(e.source,"jsx-node");if(!t.ok)return t.result;let n=ae(t.ast,e.locator);if(!n.ok)return{ok:!1,source:e.source,diagnostic:n.diagnostic};let r=Go(e.source,e.node.jsx);return r.ok?(n.match.path.replaceWith(Mx(r.node,!0)),me(t.ast,e.source,{kind:"replace-node",target:"jsx-node",inverse:"replace-node"})):r.result}import{cloneNode as zx}from"@babel/types";import Zs from"@babel/traverse";import*as q from"@babel/types";function wr(e,t,n){return`${e}::${t}::${n}`}var $={NODE_NOT_FOUND:"NODE_NOT_FOUND",HOME_PAGE_LOCKED:"HOME_PAGE_LOCKED",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",CAPABILITY_REJECTED:"CAPABILITY_REJECTED",CONSTRAINT_VIOLATED:"CONSTRAINT_VIOLATED",INVALID_PARAMS:"INVALID_PARAMS",PLAN_FAILED:"PLAN_FAILED",TRANSACTION_PREFLIGHT_FAILED:"TRANSACTION_PREFLIGHT_FAILED",ROUTE_REBUILD_FAILED:"ROUTE_REBUILD_FAILED",HISTORY_COMMIT_FAILED:"HISTORY_COMMIT_FAILED",MATERIALIZATION_CONFLICT:"MATERIALIZATION_CONFLICT",MATERIALIZATION_REJECTED:"MATERIALIZATION_REJECTED",MUTATION_ASSERTION_REQUIRED:"MUTATION_ASSERTION_REQUIRED",MUTATION_ASSERTION_INVALID:"MUTATION_ASSERTION_INVALID",VERSION_STALE:"VERSION_STALE",AST_PARSE_ERROR:"AST_PARSE_ERROR",UNSUPPORTED_OPERATION:"UNSUPPORTED_OPERATION",LOCATOR_FAILED:"LOCATOR_FAILED",INVALID_TARGET:"INVALID_TARGET",WRITE_IO_ERROR:"WRITE_IO_ERROR",CONCURRENT_MODIFIED:"CONCURRENT_MODIFIED",ROLLBACK_FAILED:"ROLLBACK_FAILED",RECOVERY_REQUIRED:"RECOVERY_REQUIRED",RECOVERY_PERSIST_FAILED:"RECOVERY_PERSIST_FAILED",MUTATION_SESSION_REQUIRED:"MUTATION_SESSION_REQUIRED",LEASE_ASSERTION_INVALID:"LEASE_ASSERTION_INVALID",LEASE_ASSERTION_EXPIRED:"LEASE_ASSERTION_EXPIRED",LEASE_ASSERTION_SCOPE_MISMATCH:"LEASE_ASSERTION_SCOPE_MISMATCH",CROSS_PAGE_MOVE_UNSUPPORTED:"CROSS_PAGE_MOVE_UNSUPPORTED",INTERNAL_ERROR:"INTERNAL_ERROR"};var Dx=typeof Zs=="function"?Zs:Zs.default;function gt(e,t,n,r){if(!e.ok)return e;let o=mt(n,t);if(!o)return e;let i=Lx(t,o,r);return i?{...e,selectionRef:i}:e}function Lx(e,t,n){let r=Bx(e,t);if(!r)return;let o=n.sourceLocator?Mu(n.sourceLocator):void 0,i=n.targetParentLocator?Mu(n.targetParentLocator):void 0,s=n.file??i?.file??o?.file,a=n.component??$x(r)??i?.component??o?.component;if(!(!s||!a))return{key:wr(s,a,Vx(r))}}function Mu(e){return e.strategy==="structural-path"?{file:e.file,component:e.component,structuralPath:e.structuralPath}:e.expectedIdentity}function Bx(e,t){let n=Vu(e,t);return!n||n.node.type!=="JSXElement"?null:n}function Vu(e,t){let n=null;return Dx(e,{JSXElement(r){r.node===t&&(n=r,r.stop())},JSXFragment(r){r.node===t&&(n=r,r.stop())}}),n}function mt(e,t){if(!e)return null;if(q.isJSXElement(e))return Xx(t,e)?Du(e.children,t):e;if(q.isJSXFragment(e))return Du(e.children,t);if(q.isJSXExpressionContainer(e)||q.isParenthesizedExpression(e)||q.isTSAsExpression(e)||q.isTSSatisfiesExpression(e)||q.isTSTypeAssertion(e)||q.isTSNonNullExpression(e))return mt(e.expression,t);if(q.isLogicalExpression(e))return mt(e.right,t);if(q.isConditionalExpression(e))return mt(e.consequent,t)??mt(e.alternate,t);if(q.isCallExpression(e)||q.isOptionalCallExpression(e))return Ku(e)?jx(e.arguments[0],t):null;if(q.isArrayExpression(e))for(let n of e.elements){if(!n)continue;let r=mt(n,t);if(r)return r}return null}function Du(e,t){for(let n of e){let r=mt(n,t);if(r)return r}return null}function jx(e,t){return!e||!q.isArrowFunctionExpression(e)&&!q.isFunctionExpression(e)?null:q.isBlockStatement(e.body)?Pr(e.body.body,t):mt(e.body,t)}function Pr(e,t){for(let n of e){if(q.isReturnStatement(n)){let r=mt(n.argument,t);if(r)return r;continue}if(q.isBlockStatement(n)){let r=Pr(n.body,t);if(r)return r;continue}if(q.isIfStatement(n)){let r=Lu(n.consequent,t);if(r)return r;let o=n.alternate?Lu(n.alternate,t):null;if(o)return o;continue}if(q.isSwitchStatement(n))for(let r of n.cases){let o=Pr(r.consequent,t);if(o)return o}}return null}function Lu(e,t){return q.isBlockStatement(e)?Pr(e.body,t):Pr([e],t)}function $x(e){let t=e;for(;t;){if(t.isFunctionDeclaration()||t.isClassDeclaration())return t.node.id?.name??null;if(t.isExportDefaultDeclaration()){let n=t.node.declaration;if(q.isFunctionDeclaration(n))return n.id?.name??"default"}if(t.isVariableDeclarator()&&q.isIdentifier(t.node.id)){let n=t.get("init");if(!Array.isArray(n)&&(n.isArrowFunctionExpression()||n.isFunctionExpression()))return t.node.id.name}t=t.parentPath}return null}var Bu=new WeakMap,ju=new WeakMap,Qs=new WeakMap;function Vx(e){let t=Bu.get(e.node);if(t!==void 0)return t;let n=[],r=e;for(;r;){if(r.isJSXElement()){let i=Kx(r);i&&n.unshift(i)}r=r.parentPath}let o=n.join("/");return Bu.set(e.node,o),o}function Kx(e){let t=Uu(e.node.openingElement.name);return!t||Fe(e)?null:/^[A-Z]/.test(t)?`component:${t}#${$u(e,t)}`:`${t}#${$u(e,t)}`}function $u(e,t){let n=Ux(e);if(!n)return 0;let r=Qs.get(n.node)?.get(t)?.get(e.node);if(r!==void 0)return r;let o=Qs.get(n.node);o||(o=new Map,Qs.set(n.node,o));let i=o.get(t);i||(i=new WeakMap,o.set(t,i));let s=0;for(let a of Rn(n))if(Uu(a.node.openingElement.name)===t){if(i.set(a.node,s),a.node===e.node)return s;s+=1}return i.get(e.node)??0}function Ux(e){let t=e.parentPath,n=null;for(;t;){if(t.isJSXFragment()){n=t,t=t.parentPath;continue}if(t.isJSXElement()){if(Fe(t)){t=t.parentPath;continue}return t}t=t.parentPath}return n}function Rn(e){let t=ju.get(e.node);if(t)return t;let n=[],r=e.get("children");for(let o of r)if(!Array.isArray(o)){if(o.isJSXElement()){if(Fe(o)){n.push(...Rn(o));continue}n.push(o);continue}if(o.isJSXFragment()){n.push(...Rn(o));continue}o.isJSXExpressionContainer()&&n.push(..._t(o.get("expression")))}return ju.set(e.node,n),n}function _t(e){if(e.isJSXElement())return Fe(e)?Rn(e):[e];if(e.isJSXFragment())return Rn(e);if(e.isParenthesizedExpression())return _t(e.get("expression"));if(e.isLogicalExpression())return _t(e.get("right"));if(e.isConditionalExpression())return[..._t(e.get("consequent")),..._t(e.get("alternate"))];if(e.isArrayExpression())return e.get("elements").flatMap(t=>Array.isArray(t)||!t.node||!t.isExpression()?[]:_t(t));if((e.isCallExpression()||e.isOptionalCallExpression())&&Ku(e.node)){let t=e.get("arguments"),n=Array.isArray(t)?t[0]:void 0;return n?Jx(n):[]}return[]}function Jx(e){if(!e.isArrowFunctionExpression()&&!e.isFunctionExpression())return[];let t=e.get("body");if(t.isJSXElement())return Fe(t)?Rn(t):[t];if(t.isJSXFragment())return Rn(t);if(t.isParenthesizedExpression())return _t(t.get("expression"));if(t.isLogicalExpression()||t.isConditionalExpression())return _t(t);if(!t.isBlockStatement())return[];let n=[];for(let r of t.get("body")){if(r.isVariableDeclaration())for(let i of r.get("declarations")){let s=i.get("init");(s.isJSXElement()||s.isJSXFragment())&&n.push(..._t(s))}if(!r.isReturnStatement())continue;let o=r.get("argument");return o.node&&n.push(..._t(o)),n}return n}function Ku(e){let t=e.callee;return(q.isMemberExpression(t)||q.isOptionalMemberExpression(t))&&q.isIdentifier(t.property)&&t.property.name==="map"&&!t.computed}function Xx(e,t){let n=Vu(e,t);return n?Fe(n):!1}function Uu(e){return q.isJSXIdentifier(e)?e.name:q.isJSXMemberExpression(e)?Ju(e):q.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:null}function Ju(e){return`${q.isJSXIdentifier(e.object)?e.object.name:Ju(e.object)}.${e.property.name}`}function nn(e,t){if(t.parentPath===e&&t.listKey==="children"&&qs(e))return e;if(!t.parentPath||t.listKey!=="children")return null;let n=t.parentPath;if(!qs(n))return null;let r=n;for(;r&&r!==e;){if(!qs(r)||!Fe(r)||r.listKey!=="children")return null;r=r.parentPath}return r===e?n:null}function qs(e){return e.isJSXElement()||e.isJSXFragment()}function Yn(e){let{source:t,locator:n,node:r,placement:o,anchorLocator:i,selectionContext:s}=e,a=Ce(t,"jsx-node");if(!a.ok)return a.result;let c=ae(a.ast,n);if(!c.ok)return{ok:!1,source:t,diagnostic:c.diagnostic};if(!c.match.path.isJSXElement()&&!c.match.path.isJSXFragment())return K(t,"unsupported-syntax","insert-child target must be a JSXElement or JSXFragment","jsx-node");let l=c.match.path;if(c.match.path.isJSXElement()){let I=c.match.path.node;if(!I.closingElement||I.openingElement.selfClosing)return K(t,"self-closing-element","Cannot insert child into self-closing element","jsx-node")}let d=Go(t,r.jsx);if(!d.ok)return d.result;let f=zx(d.node,!0),m=l.node.children,u={...s,targetParentLocator:n},g=I=>s?gt(I,a.ast,f,u):I;if(o==="append")return m.push(f),g(me(a.ast,t,{kind:"insert-child",target:"jsx-node",inverse:"remove-child"}));if(o==="prepend")return m.unshift(f),g(me(a.ast,t,{kind:"insert-child",target:"jsx-node",inverse:"remove-child"}));if(!i)return K(t,"locator-miss",`Placement '${o}' requires anchorLocator`,"jsx-node");let h=ae(a.ast,i);if(!h.ok)return{ok:!1,source:t,diagnostic:h.diagnostic};let b=nn(c.match.path,h.match.path);if(!b)return K(t,"invalid-parent-child-relation","Anchor node is not a direct child of the target parent","jsx-node");l=b;let E=l.node.children,v=E.findIndex(I=>I===h.match.path.node);return v===-1?K(t,"locator-miss","Anchor node no longer exists in target parent","jsx-node"):(E.splice(o==="before"?v:v+1,0,f),g(me(a.ast,t,{kind:"insert-child",target:"jsx-node",inverse:"remove-child"})))}import*as Xu from"@babel/parser";import{cloneNode as Wx}from"@babel/types";function Qo(e){let{source:t,locator:n,expression:r,placement:o,anchorLocator:i,selectionContext:s}=e,a=Ce(t,"jsx-node");if(!a.ok)return a.result;let c=Hx(t,r);if(!c.ok)return c.result;let l=ae(a.ast,n);if(!l.ok)return{ok:!1,source:t,diagnostic:l.diagnostic};if(!l.match.path.isJSXElement()&&!l.match.path.isJSXFragment())return K(t,"unsupported-syntax","insert-jsx-expression-child target must be a JSXElement or JSXFragment","jsx-node");if(l.match.path.isJSXElement()){let E=l.match.path.node;if(!E.closingElement||E.openingElement.selfClosing)return K(t,"self-closing-element","Cannot insert child into self-closing element","jsx-node")}let d=l.match.path,f=null;if(i){let E=ae(a.ast,i);if(!E.ok)return{ok:!1,source:t,diagnostic:E.diagnostic};let v=nn(l.match.path,E.match.path);if(!v)return K(t,"invalid-parent-child-relation","Anchor node is not a direct child of the target parent","jsx-node");d=v,f=E.match.path.node}else if(o==="before"||o==="after")return K(t,"locator-miss",`Placement '${o}' requires anchorLocator`,"jsx-node");let m=Wx(c.node,!0),u=d.node.children,g={...s,targetParentLocator:n},h=E=>s?gt(E,a.ast,m,g):E;if(o==="append")return u.push(m),h(me(a.ast,t,{kind:"insert-jsx-expression-child",target:"jsx-node",inverse:"remove-child"}));if(o==="prepend")return u.unshift(m),h(me(a.ast,t,{kind:"insert-jsx-expression-child",target:"jsx-node",inverse:"remove-child"}));let b=u.findIndex(E=>E===f);return b===-1?K(t,"locator-miss","Anchor node no longer exists in target parent","jsx-node"):(u.splice(o==="before"?b:b+1,0,m),h(me(a.ast,t,{kind:"insert-jsx-expression-child",target:"jsx-node",inverse:"remove-child"})))}function Hx(e,t){try{let r=Xu.parse(`const __VD_EXPR__ = <>{${t}}</>;`,{sourceType:"module",plugins:["jsx","typescript"]}).program.body[0],o=r?.type==="VariableDeclaration"?r.declarations[0]?.init:null,i=o?.type==="JSXFragment"?o.children[0]:void 0;return i?.type!=="JSXExpressionContainer"?{ok:!1,result:K(e,"unsupported-syntax","Expression must parse as a JSX expression container","jsx-node")}:{ok:!0,node:i}}catch(n){return{ok:!1,result:K(e,"parse-failed",`AST parse failed: ${n instanceof Error?n.message:String(n)}`,"jsx-node")}}}import{cloneNode as Gx,nullLiteral as ea}from"@babel/types";import*as rn from"@babel/types";import*as zu from"@babel/types";function Ar(e,t){let n=e.parentPath;if(!n?.isConditionalExpression()||e.key!=="consequent"||!zu.isNullLiteral(n.node.alternate))return e;let r=n.parentPath;return!r?.isJSXExpressionContainer()||r.parentPath?.node!==t.node||r.listKey!=="children"?e:r}function Zn(e){let{source:t,locator:n,targetParentLocator:r,placement:o,anchorLocator:i,selectionContext:s}=e,a=Ce(t,"jsx-node");if(!a.ok)return a.result;let c=ae(a.ast,n);if(!c.ok)return{ok:!1,source:t,diagnostic:c.diagnostic};let l=ae(a.ast,r);if(!l.ok)return{ok:!1,source:t,diagnostic:l.diagnostic};if(!l.match.path.isJSXElement()&&!l.match.path.isJSXFragment())return K(t,"unsupported-syntax","move-node target parent must be a JSXElement or JSXFragment","jsx-node");let d=l.match.path;if(l.match.path.isJSXElement()){let I=l.match.path.node;if(!I.closingElement||I.openingElement.selfClosing)return K(t,"self-closing-element","Cannot move child into self-closing element","jsx-node")}let f=null;if(i){let I=ae(a.ast,i);if(!I.ok)return{ok:!1,source:t,diagnostic:I.diagnostic};let R=I.match.path.isJSXElement()?Ar(I.match.path,l.match.path):I.match.path,A=nn(l.match.path,R);if(!A)return K(t,"invalid-parent-child-relation","Anchor node is not a direct child of the target parent","jsx-node");d=A,f=R}else if(o==="before"||o==="after")return K(t,"locator-miss",`Placement '${o}' requires anchorLocator`,"jsx-node");let m=f&&typeof f.key=="number"?f.key:-1;if(f&&m===-1)return K(t,"locator-miss","Anchor node does not exist in target parent","jsx-node");let u=c.match.path.isJSXElement()?Ar(c.match.path,l.match.path):c.match.path,g=Gx(u.node,!0);if(!rn.isJSXElement(g)&&!rn.isJSXExpressionContainer(g)&&!rn.isJSXFragment(g)&&!rn.isJSXText(g))return K(t,"unsupported-syntax","move-node source must resolve to a JSX child","jsx-node");let h=u.parentPath?.node===d.node&&typeof u.key=="number"?u.key:-1;if(f&&u.parentPath?.node===f.parentPath?.node&&u.key===f.key)return K(t,"invalid-parent-child-relation","Cannot move a node relative to itself","jsx-node");Yx(u);let b=d.node.children,E={...s,sourceLocator:n,targetParentLocator:r};if(o==="append")return b.push(g),gt(Ho(a.ast,t),a.ast,g,E);if(o==="prepend")return b.unshift(g),gt(Ho(a.ast,t),a.ast,g,E);let v=m-(h!==-1&&h<m?1:0);return b.splice(o==="before"?v:v+1,0,g),gt(Ho(a.ast,t),a.ast,g,E)}function Yx(e){if(e.parentPath?.isConditionalExpression()&&(e.key==="consequent"||e.key==="alternate")){e.replaceWith(ea());return}if(e.parentPath?.isArrowFunctionExpression()&&e.key==="body"){e.replaceWith(ea());return}if(e.parentPath?.isReturnStatement()&&e.key==="argument"){e.replaceWith(ea());return}e.remove()}import*as Wu from"@babel/parser";import{cloneNode as Zx,nullLiteral as ta}from"@babel/types";function qo(e){let{source:t,locator:n,targetParentLocator:r,placement:o,anchorLocator:i,repeatExpression:s,selectionContext:a}=e,c=Ce(t,"jsx-node");if(!c.ok)return c.result;let l=Qx(t,s);if(!l.ok)return l.result;let d=ae(c.ast,n);if(!d.ok)return{ok:!1,source:t,diagnostic:d.diagnostic};let f=ae(c.ast,r);if(!f.ok)return{ok:!1,source:t,diagnostic:f.diagnostic};if(!f.match.path.isJSXElement()&&!f.match.path.isJSXFragment())return K(t,"unsupported-syntax","move-repeat-template-child target parent must be a JSXElement or JSXFragment","jsx-node");if(f.match.path.isJSXElement()){let I=f.match.path.node;if(!I.closingElement||I.openingElement.selfClosing)return K(t,"self-closing-element","Cannot move repeat child into self-closing element","jsx-node")}let m=f.match.path,u=null;if(i){let I=ae(c.ast,i);if(!I.ok)return{ok:!1,source:t,diagnostic:I.diagnostic};let R=nn(f.match.path,I.match.path);if(!R)return K(t,"invalid-parent-child-relation","Anchor node is not a direct child of the target parent","jsx-node");m=R,u=I.match.path.node}else if(o==="before"||o==="after")return K(t,"locator-miss",`Placement '${o}' requires anchorLocator`,"jsx-node");if(!d.match.path.isJSXElement())return K(t,"unsupported-syntax","move-repeat-template-child source must be a JSXElement","jsx-node");let g=m.node,h=Zx(l.node,!0);qx(d.match.path);let b={...a,sourceLocator:n,targetParentLocator:r},E=g.children;if(o==="append")return E.push(h),gt(me(c.ast,t,{kind:"move-repeat-template-child",target:"jsx-node",inverse:"move-repeat-template-child"}),c.ast,h,b);if(o==="prepend")return E.unshift(h),gt(me(c.ast,t,{kind:"move-repeat-template-child",target:"jsx-node",inverse:"move-repeat-template-child"}),c.ast,h,b);let v=E.findIndex(I=>I===u);return v===-1?K(t,"locator-miss","Anchor node no longer exists in target parent","jsx-node"):(E.splice(o==="before"?v:v+1,0,h),gt(me(c.ast,t,{kind:"move-repeat-template-child",target:"jsx-node",inverse:"move-repeat-template-child"}),c.ast,h,b))}function Qx(e,t){try{let r=Wu.parse(`const __VD_EXPR__ = <>{${t}}</>;`,{sourceType:"module",plugins:["jsx","typescript"]}).program.body[0],o=r?.type==="VariableDeclaration"?r.declarations[0]?.init:null,i=o?.type==="JSXFragment"?o.children[0]:void 0;return i?.type!=="JSXExpressionContainer"?{ok:!1,result:K(e,"unsupported-syntax","Repeat expression must parse as a JSX expression container","jsx-node")}:{ok:!0,node:i}}catch(n){return{ok:!1,result:K(e,"parse-failed",`AST parse failed: ${n instanceof Error?n.message:String(n)}`,"jsx-node")}}}function qx(e){if(e.parentPath?.isConditionalExpression()&&(e.key==="consequent"||e.key==="alternate")){e.replaceWith(ta());return}if(e.parentPath?.isArrowFunctionExpression()&&e.key==="body"){e.replaceWith(ta());return}if(e.parentPath?.isReturnStatement()&&e.key==="argument"){e.replaceWith(ta());return}e.remove()}import{SiteEditSetPropsParamsSchema as eb,classifySiteEditPropertyName as tb}from"@vcp-dev/contracts";import*as Qn from"@babel/types";function ei(e){let t=eb.safeParse({kind:"set-props",scope:"selection",changes:e.changes});if(!t.success)return K(e.source,"unsupported-syntax","Invalid typed JSX property changes","jsx-node",{issues:t.error.issues});let n=Ce(e.source,"jsx-node");if(!n.ok)return n.result;let r=Hn(n.ast,e.locator,e.source);if(!r.ok)return r.result;for(let a of t.data.changes){let c=tb(a.name);if(c.owner!=="generic")return K(e.source,"unsupported-syntax",c.diagnostic?.message??`Property '${a.name}' is not owned by the generic JSX primitive`,"jsx-node")}let o=r.match.path.node.openingElement,i=o.attributes.filter(Qn.isJSXAttribute),s=new Map;for(let a of i){let c=nb(a);if(!c)continue;let l=s.get(c)??[];l.push(a),s.set(c,l)}for(let a of t.data.changes)if((s.get(a.name)??[]).length>1)return K(e.source,"unsupported-syntax",`JSX attribute '${a.name}' has multiple sources`,"jsx-node");for(let a of t.data.changes){let c=s.get(a.name)?.[0];if(a.operation==="remove"){c&&(o.attributes=o.attributes.filter(d=>d!==c));continue}let l=Nr(a.name,a.value).value;c?c.value=l:o.attributes.push(Nr(a.name,a.value))}return me(n.ast,e.source,{kind:"set-props",target:"jsx-node",inverse:"set-props"})}function nb(e){return Qn.isJSXIdentifier(e.name)?e.name.name:Qn.isJSXNamespacedName(e.name)?`${e.name.namespace.name}:${e.name.name.name}`:null}import{SiteEditOperationParamsSchema as rb}from"@vcp-dev/contracts";import*as z from"@babel/types";var Hu=["prefetch","replace","scroll","locale","onNavigate"],ob=/^on(?:Click|DoubleClick|AuxClick|MouseDown|MouseUp|PointerDown|PointerUp|TouchStart|TouchEnd|KeyDown|KeyUp|ContextMenu)(?:Capture)?$/;function ib(e){let t=e;for(;t;){if(t.isJSXElement()&&t.node.openingElement.attributes.some(n=>z.isJSXAttribute(n)&&z.isJSXIdentifier(n.name)&&ob.test(n.name.name)))return!0;t=t.parentPath}return!1}function ti(e){let t=Ce(e.source,"jsx-node");if(!t.ok)return t.result;let n=Hn(t.ast,e.locator,e.source);if(!n.ok)return n.result;let r=rb.safeParse({kind:"set-link-target",scope:"selection",link:e.link,changes:e.changes});if(!r.success||r.data.kind!=="set-link-target")return zt(e.source,"Invalid typed link-target changes");let o=n.match.path,i=o.node,s=i.openingElement,a=fb(s.name);if(!a)return zt(e.source,"Unsupported JSX link tag");if(s.attributes.some(z.isJSXSpreadAttribute))return zt(e.source,"Link elements with spread props cannot be transformed safely");let c=new Map;for(let g of s.attributes){if(!z.isJSXAttribute(g))continue;let h=ra(g);if(!h)return zt(e.source,"Unsupported JSX attribute name");let b=c.get(h)??[];b.push(g),c.set(h,b)}if([...c.values()].some(g=>g.length>1))return zt(e.source,"Duplicate JSX attributes cannot be transformed safely");let l=c.get("href")?.[0];if(l&&!db(l))return zt(e.source,"Dynamic link href cannot be transformed safely");let d=a==="a",f=d?null:cb(o,s.name);if(!d&&!f)return zt(e.source,"Only native anchors and imported next/link components are supported");if(e.link.kind==="none"&&ib(o))return zt(e.source,"A link with an active event handler in its JSX ancestry cannot become an inert anchor");let m=null;if(e.link.kind==="internal-route")if(f)m=a;else{let g=lb(t.ast,o);if(!g.ok)return zt(e.source,g.reason);m=g.localName}if(f&&e.link.kind!=="internal-route"){let g=z.jsxIdentifier("a");s.name=g,i.closingElement&&(i.closingElement.name=z.jsxIdentifier("a")),ub(t.ast,f,o)}else m&&d&&(s.name=z.jsxIdentifier(m),i.closingElement&&(i.closingElement.name=z.jsxIdentifier(m)));let u=new Set;return e.link.kind==="none"?(u.add("href"),u.add("target"),u.add("rel"),Hu.forEach(g=>u.add(g))):(u.add("href"),e.link.kind==="native-link"&&Hu.forEach(g=>u.add(g))),s.attributes=s.attributes.filter(g=>{if(!z.isJSXAttribute(g))return!0;let h=ra(g);return!h||!u.has(h)}),e.link.kind!=="none"&&s.attributes.push(z.jsxAttribute(z.jsxIdentifier("href"),z.stringLiteral(e.link.href))),sb(s,e.changes),me(t.ast,e.source,{kind:"set-link-target",target:"jsx-node",inverse:"set-link-target"})}function sb(e,t){for(let n of t){let r=e.attributes.find(s=>z.isJSXAttribute(s)&&ra(s)===n.name);if(n.operation==="remove"){e.attributes=e.attributes.filter(s=>s!==r);continue}let o=typeof n.value=="string"?z.stringLiteral(n.value):z.jsxExpressionContainer(na(n.value)),i=z.jsxAttribute(z.jsxIdentifier(n.name),o);r&&z.isJSXAttribute(r)?r.value=i.value:e.attributes.push(i)}}function na(e){return e===null?z.nullLiteral():typeof e=="string"?z.stringLiteral(e):typeof e=="number"?z.numericLiteral(e):typeof e=="boolean"?z.booleanLiteral(e):Array.isArray(e)?z.arrayExpression(e.map(t=>na(t))):typeof e=="object"?z.objectExpression(Object.entries(e).map(([t,n])=>z.objectProperty(z.isValidIdentifier(t)?z.identifier(t):z.stringLiteral(t),na(n)))):z.nullLiteral()}function ab(e){return z.isImportDefaultSpecifier(e)||z.isImportSpecifier(e)&&e.importKind!=="type"&&(z.isIdentifier(e.imported,{name:"default"})||z.isStringLiteral(e.imported,{value:"default"}))}function Gu(e){return!e.parentPath?.isImportDeclaration()||e.parentPath.node.importKind==="type"?!1:e.isImportDefaultSpecifier()||e.isImportSpecifier()&&e.node.importKind!=="type"&&(z.isIdentifier(e.node.imported,{name:"default"})||z.isStringLiteral(e.node.imported,{value:"default"}))}function cb(e,t){if(!z.isJSXIdentifier(t))return null;let n=e.scope.getBinding(t.name);if(!n||!Gu(n.path))return null;let r=n.path.parentPath;return!r?.isImportDeclaration()||r.node.source.value!=="next/link"?null:t.name}function lb(e,t){let n=e.program.body.filter(c=>z.isImportDeclaration(c)&&c.source.value==="next/link"&&c.importKind!=="type"),r=n[0],o=n.flatMap(c=>c.specifiers).find(ab);if(o)return t.scope.getBinding(o.local.name)?.path.node!==o?{ok:!1,reason:"The next/link import is shadowed at the selected element"}:{ok:!0,localName:o.local.name};let i=t.scope.getProgramParent(),s=["Link","NextLink",...Array.from({length:20},(c,l)=>`NextLink${l+2}`)].find(c=>!i.hasBinding(c)&&!t.scope.hasBinding(c));if(!s)return{ok:!1,reason:"Cannot create an unshadowed runtime next/link import"};let a=z.importDefaultSpecifier(z.identifier(s));if(r)r.specifiers.unshift(a);else{let c=z.importDeclaration([a],z.stringLiteral("next/link")),l=0;for(;l<e.program.body.length&&z.isImportDeclaration(e.program.body[l]);)l+=1;e.program.body.splice(l,0,c)}return{ok:!0,localName:s}}function ub(e,t,n){let r=n.scope.getProgramParent();r.crawl();let o=r.getBinding(t);if(!o||!Gu(o.path)||o.referenced)return;let i=o.path.parentPath;if(!(!i?.isImportDeclaration()||i.node.source.value!=="next/link")&&(i.node.specifiers=i.node.specifiers.filter(s=>s!==o.path.node),i.node.specifiers.length===0)){let s=e.program.body.indexOf(i.node);s>=0&&e.program.body.splice(s,1)}}function db(e){return!e.value||z.isStringLiteral(e.value)}function fb(e){return z.isJSXIdentifier(e)?e.name:null}function ra(e){return z.isJSXIdentifier(e.name)?e.name.name:null}function zt(e,t){return K(e,"unsupported-syntax",t,"jsx-node")}import*as Ke from"@babel/types";import{classifySiteEditPropertyName as Yu}from"@vcp-dev/contracts";function ni(e){let t=Yu(e.name),n=Yu(e.property);if(t.owner!=="generic"||n.owner!=="generic")return K(e.source,"unsupported-syntax","Property binding is only available for generic properties","jsx-node");if(!Zu(e.object))return K(e.source,"unsupported-syntax","Property binding object must be a single identifier","jsx-node");if(e.property.length===0)return K(e.source,"unsupported-syntax","Property binding requires a non-empty property name","jsx-node");let r=Ce(e.source,"jsx-node");if(!r.ok)return r.result;let o=Hn(r.ast,e.locator,e.source);if(!o.ok)return o.result;let i=o.match.path.node.openingElement,s=i.attributes.filter(l=>Ke.isJSXAttribute(l)&&mb(l)===e.name);if(s.length>1)return K(e.source,"unsupported-syntax",`JSX attribute '${e.name}' has multiple sources`,"jsx-node");let a=pb(e.object,e.property),c=s[0];if(c)c.value=Ke.jsxExpressionContainer(a);else{let l=Nr(e.name,"");l.value=Ke.jsxExpressionContainer(a),i.attributes.push(l)}return me(r.ast,e.source,{kind:"set-property-binding",target:"jsx-node",inverse:"restore-property-binding"})}function pb(e,t){return Zu(t)?Ke.memberExpression(Ke.identifier(e),Ke.identifier(t)):Ke.memberExpression(Ke.identifier(e),Ke.stringLiteral(t),!0)}function Zu(e){return/^[A-Za-z_$][A-Za-z0-9_$]*$/u.test(e)}function mb(e){return Ke.isJSXIdentifier(e.name)?e.name.name:Ke.isJSXNamespacedName(e.name)?`${e.name.namespace.name}:${e.name.name.name}`:null}import{getBindingIdentifiers as hb,identifier as Tr,importDeclaration as yb,importDefaultSpecifier as xb,importNamespaceSpecifier as bb,importSpecifier as Sb,isImportDefaultSpecifier as Qu,isImportNamespaceSpecifier as qu,isImportSpecifier as ed,stringLiteral as Eb}from"@babel/types";function qn(e){let{source:t,moduleSpecifier:n,imports:r}=e,o=r.findIndex(b=>!Ab(b));if(o!==-1){let b=r[o],E=b&&typeof b=="object"&&"kind"in b?b.kind:void 0;return K(t,"unsupported-syntax",`Unsupported import spec kind: ${String(E)}`)}let i=Nb(r);if(!i.ok)return K(t,"unsupported-syntax",i.message);let s=Ce(t);if(!s.ok)return s.result;let{ast:a}=s,c=a.program,l=c.body.filter(b=>b.type==="ImportDeclaration"&&b.source.value===n),d=new Set(l.flatMap(b=>b.specifiers.flatMap(E=>{let v=Tb(b,E);return v?[v]:[]}))),f=i.imports.filter(b=>!d.has(sd(b)));if(f.length===0)return Rr(t,t,{kind:"add-import",target:"import",inverse:"remove-import"});let m=wb(c.body),u=f.find(b=>m.has(oa(b)));if(u)return K(t,"unsupported-syntax",`Import local binding already exists: ${oa(u)}`);let g=Rb(f);if(g.reduce((b,E)=>b+E.length,0)!==f.length)return K(t,"unsupported-syntax","Unsupported import specifier grouping");for(let b of g){if(!od(nd(b)))return K(t,"unsupported-syntax","Unsupported import specifier combination");let E=l.find(v=>vb(v,b));if(E)kb(E,b);else{let v=yb(td(b),Eb(n));Pb(c.body,v),l.push(v)}}return me(a,t,{kind:"add-import",target:"import",inverse:"remove-import"})}function vb(e,t){return e.importKind==="type"?!1:od(Cb(Ib(e),nd(t)))}function kb(e,t){let n=!1,r=new Set(e.specifiers.map(o=>ia(o)));for(let o of td(t)){let i=ia(o);r.has(i)||(e.specifiers.push(o),r.add(i),n=!0)}return id(e.specifiers),{changed:n}}function td(e){let t=e.map(n=>{switch(n.kind){case"named":return Sb(n.local?Tr(n.local):Tr(n.imported),Tr(n.imported));case"default":return xb(Tr(n.local));case"namespace":return bb(Tr(n.local));default:return n}});return id(t),t}function nd(e){let t=rd();for(let n of e)n.kind==="default"?t.defaultLocals.add(n.local):n.kind==="named"?t.hasNamed=!0:t.namespaceLocals.add(n.local);return t}function Ib(e){let t=rd();for(let n of e.specifiers)Qu(n)?t.defaultLocals.add(n.local.name):qu(n)?t.namespaceLocals.add(n.local.name):t.hasNamed=!0;return t}function rd(){return{defaultLocals:new Set,hasNamed:!1,namespaceLocals:new Set}}function Cb(e,t){return{defaultLocals:new Set([...e.defaultLocals,...t.defaultLocals]),hasNamed:e.hasNamed||t.hasNamed,namespaceLocals:new Set([...e.namespaceLocals,...t.namespaceLocals])}}function od(e){return e.defaultLocals.size>1||e.namespaceLocals.size>1?!1:!(e.hasNamed&&e.namespaceLocals.size>0)}function id(e){let t=[...e.filter(n=>Qu(n)),...e.filter(n=>qu(n)),...e.filter(n=>ed(n))];e.splice(0,e.length,...t)}function Rb(e){let t=e.filter(i=>i.kind==="default"),n=e.filter(i=>i.kind==="namespace"),r=e.filter(i=>i.kind==="named"),o=[];if(n.length>0){let i=Math.max(t.length,n.length);for(let s=0;s<i;s+=1){let a=[],c=t[s],l=n[s];c&&a.push(c),l&&a.push(l),o.push(a)}return r.length>0&&o.push(r),o}if(t.length>0){o.push([t[0],...r]);for(let i of t.slice(1))o.push([i])}else r.length>0&&o.push(r);return o}function Nb(e){let t=new Map,n=new Map;for(let r of e){let o=sd(r);if(t.has(o))continue;let i=oa(r),s=n.get(i);if(s&&s!==o)return{ok:!1,message:`Import local binding is requested more than once: ${i}`};t.set(o,r),n.set(i,o)}return{ok:!0,imports:[...t.values()]}}function wb(e){let t=new Set;for(let n of e){if(n.type==="ImportDeclaration"){for(let o of n.specifiers)t.add(o.local.name);continue}let r=(n.type==="ExportNamedDeclaration"||n.type==="ExportDefaultDeclaration")&&n.declaration?n.declaration:n;if(r.type==="VariableDeclaration")for(let o of r.declarations)for(let i of Object.keys(hb(o.id)))t.add(i);else(r.type==="FunctionDeclaration"||r.type==="ClassDeclaration"||r.type==="TSEnumDeclaration")&&r.id&&t.add(r.id.name)}return t}function Pb(e,t){let n=[...e].reverse().findIndex(r=>r.type==="ImportDeclaration");if(n===-1)e.unshift(t);else{let r=e.length-n;e.splice(r,0,t)}}function Ab(e){if(!e||typeof e!="object"||!("kind"in e))return!1;let t=e.kind;return t==="named"?typeof e.imported=="string"&&(e.local===void 0||typeof e.local=="string"):t==="default"||t==="namespace"?typeof e.local=="string":!1}function sd(e){switch(e.kind){case"default":return`default:${e.local}`;case"namespace":return`namespace:${e.local}`;case"named":return`named:${e.imported}:${e.local??e.imported}`;default:return e}}function oa(e){return e.kind==="named"?e.local??e.imported:e.local}function Tb(e,t){return e.importKind==="type"||ed(t)&&t.importKind==="type"?null:ia(t)}function ia(e){if(e.type==="ImportDefaultSpecifier")return`default:${e.local.name}`;if(e.type==="ImportNamespaceSpecifier")return`namespace:${e.local.name}`;let t=e.imported.type==="Identifier"?e.imported.name:e.imported.value,n=e.local.name;return`named:${t}:${n}`}function er(e){let{source:t,moduleSpecifier:n,imports:r}=e,o=r.findIndex(d=>!_b(d));if(o!==-1){let d=r[o],f=d&&typeof d=="object"&&"kind"in d?d.kind:void 0;return K(t,"unsupported-syntax",`Unsupported remove import spec kind: ${String(f)}`)}let i=Ce(t);if(!i.ok)return i.result;let{ast:s}=i,a=s.program,c=a.body.findIndex(d=>d.type==="ImportDeclaration"&&d.source.value===n);if(c===-1)return Rr(t,t,{kind:"remove-import",target:"import",inverse:"add-import"});let l=a.body[c];return r.length===0?(a.body.splice(c,1),me(s,t,{kind:"remove-import",target:"import",inverse:"add-import"})):(l.specifiers=l.specifiers.filter(d=>!r.some(f=>Fb(d,f))),l.specifiers.length===0&&a.body.splice(c,1),me(s,t,{kind:"remove-import",target:"import",inverse:"add-import"}))}function Fb(e,t){return t.kind==="default"?e.type==="ImportDefaultSpecifier":t.kind==="namespace"?e.type==="ImportNamespaceSpecifier":e.type!=="ImportSpecifier"?!1:(e.imported.type==="Identifier"?e.imported.name:e.imported.value)===t.imported}function _b(e){if(!e||typeof e!="object"||!("kind"in e))return!1;let t=e.kind;return t==="named"?typeof e.imported=="string":t==="default"||t==="namespace"}function Fr(e){let{source:t,locator:n,next:r}=e,o=si(t,n);return o.ok?(o.path.replaceWith(tn(r)),me(o.ast,t,{kind:"update-value",target:"value",inverse:"restore-value"})):o.result}function ri(e){let{source:t,locator:n,index:r,value:o}=e,i=si(t,n);return i.ok?i.path.isArrayExpression()?i.path.node.elements.some(s=>s?.type==="SpreadElement")?K(t,"unsupported-syntax","Spread array elements are not supported","value"):r<0||r>i.path.node.elements.length?K(t,"array-index-out-of-range",`Array index ${r} is out of range`,"value"):(i.path.node.elements.splice(r,0,tn(o)),me(i.ast,t,{kind:"insert-array-element",target:"value",inverse:"remove-array-element"})):K(t,"unsupported-syntax","Array operations require array expression target","value"):i.result}function oi(e){let{source:t,locator:n,index:r}=e,o=si(t,n);return o.ok?o.path.isArrayExpression()?o.path.node.elements.some(i=>i?.type==="SpreadElement")?K(t,"unsupported-syntax","Spread array elements are not supported","value"):r<0||r>=o.path.node.elements.length?K(t,"array-index-out-of-range",`Array index ${r} is out of range`,"value"):(o.path.node.elements.splice(r,1),me(o.ast,t,{kind:"remove-array-element",target:"value",inverse:"insert-array-element"})):K(t,"unsupported-syntax","Array operations require array expression target","value"):o.result}function ii(e){let{source:t,locator:n,fromIndex:r,toIndex:o}=e,i=si(t,n);if(!i.ok)return i.result;if(!i.path.isArrayExpression())return K(t,"unsupported-syntax","Array operations require array expression target","value");if(i.path.node.elements.some(c=>c?.type==="SpreadElement"))return K(t,"unsupported-syntax","Spread array elements are not supported","value");if(r<0||r>=i.path.node.elements.length||o<0||o>i.path.node.elements.length)return K(t,"array-index-out-of-range","Array move indices are out of range","value");let[s]=i.path.node.elements.splice(r,1),a=Math.min(o,i.path.node.elements.length);return i.path.node.elements.splice(a,0,s),me(i.ast,t,{kind:"move-array-element",target:"value",inverse:"move-array-element-back"})}function si(e,t){let n=Ce(e,"value");if(!n.ok)return{ok:!1,result:n.result};let r=ae(n.ast,t);return r.ok?{ok:!0,ast:n.ast,path:r.match.path}:{ok:!1,result:{ok:!1,source:e,diagnostic:r.diagnostic}}}import*as Xe from"@babel/types";function ai(e){let t=Ce(e.source,"value");if(!t.ok)return t.result;let n=ae(t.ast,e.objectLocator);if(!n.ok)return{ok:!1,source:e.source,diagnostic:n.diagnostic};if(!n.match.path.isObjectExpression())return K(e.source,"unsupported-syntax","Object property upsert requires an ObjectExpression parent","value");let r=n.match.path.node;if(r.properties.some(a=>Xe.isSpreadElement(a)||Xe.isObjectProperty(a)&&a.computed))return K(e.source,"unsupported-syntax","Object property upsert does not support spreads or computed keys","value");let o=r.properties.filter(a=>Xe.isObjectProperty(a)&&Ob(a.key)===e.name);if(o.length>1)return K(e.source,"unsupported-syntax",`Object property '${e.name}' has multiple sources`,"value");let i=e.value.kind==="undefined"?Xe.unaryExpression("void",Xe.numericLiteral(0)):tn(e.value.value),s=o[0];if(s)s.value=i,s.shorthand=!1;else{let a=Xe.objectProperty(Gs(e.name),i);e.name==="__proto__"&&(a.computed=!0),r.properties.push(a)}return me(t.ast,e.source,{kind:"upsert-object-property",target:"value",inverse:"restore-object-property"})}function Ob(e){return Xe.isIdentifier(e)?e.name:Xe.isStringLiteral(e)?e.value:Xe.isNumericLiteral(e)?String(e.value):null}import{isSiteEditRuntimeContainerTag as Mb,isSiteEditRuntimeVoidElementTag as Db}from"@vcp-dev/contracts/site-edit-runtime-capability";function tr(e){if(!e.composition)throw new Error("Composition unavailable for render source graph.");return e.composition}function Lb(e,t,n){let r=tr(n),o=t.nodes.get(e),i=n.elements.get(e);if(!o||!i)return{composition:r,key:e,canUpdateText:!1,canInsertChild:!1,canMove:!1,canRemove:!1,constraints:[{kind:"opaque-region",message:"Node not found in graph"}]};let s=o.constraints.map(R=>({kind:R.kind,message:R.reason})),a=i.isOpaque,l=o.parentKey===null&&i.componentName==="Page",d=i.tag.toLowerCase(),f=i.tag!==d,m=!f&&Db(d),u=f||Mb(d),g=f&&i.childKeys.length>0&&!i.isPublicUiComponent,h=i.textSegments.length>0&&i.textSegments.some(R=>R.editable);m&&!s.some(R=>R.kind==="void-element")&&s.push({kind:"void-element",message:`Element '${i.tag}' is void: children cannot be inserted`}),!m&&!u&&!s.some(R=>R.kind==="void-element")&&s.push({kind:"void-element",message:`Element '${i.tag}' cannot contain structured children`});let b=h&&(!a||i.importedFrom==="next/link"),E=!i.isPublicUiComponent&&!m&&u&&(!a||g);return{composition:r,key:e,canUpdateText:b,canInsertChild:E,canMove:!l,canRemove:!l,constraints:s}}function ad(e,t){let n=new Map;for(let r of e.nodes.keys())n.set(r,Lb(r,e,t));return n}function sa(e){let t=e.route.graph.elements.get(e.key);if(!t)return{key:e.key,composition:e.route.composition,filePath:"",componentName:"",sourceKind:"missing",attrRaw:null,valueRaw:null,attrRange:null,openingElementRange:{start:0,end:0},version:{documentVersion:e.route.graph.version,contentHash:Ee(e.route.source)},diagnostics:[{code:"source-locator-warning",message:`Key not found: ${e.key}`}]};let n=Bb(e.route.source,t);if(!n)return{key:e.key,composition:e.route.composition,filePath:t.sourceFile,componentName:t.componentName,sourceKind:"missing",attrRaw:null,valueRaw:null,attrRange:null,openingElementRange:{start:0,end:0},version:{documentVersion:e.route.graph.version,contentHash:Ee(e.route.source)},diagnostics:[{code:"source-locator-warning",message:`Unable to locate JSX element for key ${t.identity.key}`}]};let r=n.openingElement,o=r.attributes.find(c=>c.type==="JSXAttribute"&&c.name.type==="JSXIdentifier"&&c.name.name==="className"),i={key:e.key,composition:e.route.composition,filePath:t.sourceFile,componentName:t.componentName,openingElementRange:ld(r),version:{documentVersion:e.route.graph.version,contentHash:Ee(e.route.source)}};if(!o)return{...i,sourceKind:"missing",attrRaw:null,valueRaw:null,attrRange:null,diagnostics:[{code:"missing-class-name",message:"No className attribute is present on this element."}]};let s=o.value,a=s?.type==="StringLiteral"?"stringLiteral":"expression";return{...i,sourceKind:a,attrRaw:cd(e.route.source,o),valueRaw:s?cd(e.route.source,s):null,attrRange:ld(o),diagnostics:[]}}function ud(e){let{source:t,oldAttrRange:n,openingElementRange:r,newAttrRaw:o}=e;if(n){let a=n.start>0&&/\s/.test(t[n.start-1]??"")?n.start-1:n.start,c=o?`${a<n.start?" ":""}${o}`:"";return t.slice(0,a)+c+t.slice(n.end)}if(!o)return t;let i=r.end,s=t.slice(Math.max(0,i-2),i)==="/>"?i-2:i-1;return t.slice(0,s)+` ${o}`+t.slice(s)}function Bb(e,t){let n=At({source:e,profile:Sn({filePath:t.sourceFile,source:e})});if(!n.ok)return null;let r=ae(n.ast,{kind:"jsx-node",strategy:"structural-path",file:t.identity.file,component:t.identity.component,structuralPath:t.identity.structuralPath,expectedRange:jb(t.sourceRange)});return!r.ok||r.match.node.type!=="JSXElement"?null:r.match.node}function dd(e){let t=At({source:`const __v = <div ${e} />;`,profile:"tsx-module"});if(!t.ok)return!1;let n=t.ast.program.body[0],o=(n?.type==="VariableDeclaration"?n.declarations[0]:null)?.init;if(o?.type!=="JSXElement")return!1;let i=o.openingElement.attributes;return i.length===1&&i[0]?.type==="JSXAttribute"&&i[0].name.type==="JSXIdentifier"&&i[0].name.name==="className"}function cd(e,t){return t.start==null||t.end==null?"":e.slice(t.start,t.end)}function ld(e){if(e.start==null||e.end==null)throw new Error("AST node does not include offsets.");return{start:e.start,end:e.end}}function jb(e){return{startLine:e.startLine,startColumn:e.startColumn,endLine:e.endLine,endColumn:e.endColumn}}function fd(){let e=new Set;return{emit(t){for(let n of Array.from(e))try{n(t)}catch{}},subscribe(t){return e.add(t),()=>{e.delete(t)}}}}import{randomUUID as $b}from"node:crypto";import ci from"node:fs/promises";import aa from"node:path";import{setTimeout as Vb}from"node:timers/promises";var Kb={async mkdir(e,t){await ci.mkdir(e,t)},async writeFile(e,t,n){await ci.writeFile(e,t,n)},async rename(e,t){await ci.rename(e,t)},async rm(e,t){await ci.rm(e,t)}},Ub=new Set(["EACCES","EBUSY","EPERM"]),Jb=[10,20,40,80,160];async function Xb(e,t,n){for(let r of Jb)try{await e.rename(t,n);return}catch(o){if(!zb(o))throw o;await Vb(r)}await e.rename(t,n)}function zb(e){return e instanceof Error&&"code"in e&&typeof e.code=="string"&&Ub.has(e.code)}async function li(e,t,n=Kb){let r=aa.dirname(e),o=aa.basename(e),i=aa.join(r,`.${o}.${process.pid}.${$b()}.tmp`),s=!1;try{await n.mkdir(r,{recursive:!0}),await n.writeFile(i,t,"utf8"),await Xb(n,i,e),s=!0}finally{if(!s)try{await n.rm(i,{force:!0})}catch{}}}import ca from"@babel/traverse";import*as S from"@babel/types";import*as ue from"@babel/types";function Ot(e,t={}){if(ue.isTSAsExpression(e)||ue.isTSSatisfiesExpression(e)||ue.isTSNonNullExpression(e)||ue.isTypeCastExpression(e)||ue.isParenthesizedExpression(e))return Ot(e.expression,t);if(ue.isStringLiteral(e))return{status:"resolved",value:e.value};if(ue.isNumericLiteral(e))return Number.isFinite(e.value)?{status:"resolved",value:e.value}:{status:"unresolved"};if(ue.isBooleanLiteral(e))return{status:"resolved",value:e.value};if(ue.isNullLiteral(e))return{status:"resolved",value:null};if(ue.isTemplateLiteral(e))return e.expressions.length===0&&e.quasis.length===1?{status:"resolved",value:e.quasis[0].value.cooked??e.quasis[0].value.raw}:{status:"unresolved"};if(ue.isIdentifier(e))return e.name==="undefined"&&!t.resolveIdentifier?{status:"undefined"}:t.resolveIdentifier?.(e.name)??{status:"unresolved"};if(ue.isUnaryExpression(e)&&e.operator==="void"&&ue.isNumericLiteral(e.argument)&&e.argument.value===0)return{status:"undefined"};if(ue.isArrayExpression(e)){let n=[];for(let r of e.elements){if(!r||ue.isSpreadElement(r))return{status:"unresolved"};let o=Ot(r,t);if(o.status!=="resolved")return{status:"unresolved"};n.push(o.value)}return{status:"resolved",value:n}}if(ue.isObjectExpression(e)){let n=Object.create(null);for(let r of e.properties){if(!ue.isObjectProperty(r)||r.computed||!ue.isExpression(r.value))return{status:"unresolved"};let o=Wb(r.key);if(o===null)return{status:"unresolved"};let i=Ot(r.value,t);if(i.status!=="resolved")return{status:"unresolved"};Object.defineProperty(n,o,{configurable:!0,enumerable:!0,value:i.value,writable:!0})}return{status:"resolved",value:n}}return ue.isMemberExpression(e)||ue.isOptionalMemberExpression(e)?t.resolveMember?.(e)??{status:"unresolved"}:{status:"unresolved"}}function Wb(e){return ue.isIdentifier(e)?e.name:ue.isStringLiteral(e)?e.value:ue.isNumericLiteral(e)?String(e.value):null}var Hb=typeof ca=="function"?ca:ca.default;function Ge(e){return{startLine:e.loc?.start.line??0,startColumn:e.loc?.start.column??0,endLine:e.loc?.end.line??0,endColumn:e.loc?.end.column??0}}function Gb(e){return/^[A-Z]/.test(e)}function pa(e){let t=e.openingElement;return S.isJSXIdentifier(t.name)?t.name.name==="Fragment":S.isJSXMemberExpression(t.name)?t.name.property.name==="Fragment":!1}function rr(e){return S.isJSXFragment(e)}function md(e){return S.isJSXIdentifier(e.name)?e.name.name:S.isJSXMemberExpression(e.name)?gd(e.name):S.isJSXNamespacedName(e.name)?`${e.name.namespace.name}:${e.name.name.name}`:"unknown"}function gd(e){return S.isJSXIdentifier(e.object)?`${e.object.name}.${e.property.name}`:S.isJSXMemberExpression(e.object)?`${gd(e.object)}.${e.property.name}`:e.property.name}function Yb(e){return e.split(".")[0]??e}function Zb(e){let t=e;for(;t;){let n=t.node;if(S.isFunctionDeclaration(n)&&n.id||S.isVariableDeclarator(n)&&S.isIdentifier(n.id))return n.id.name;if(S.isExportDefaultDeclaration(n)){let r=n.declaration;if(S.isFunctionDeclaration(r)&&r.id)return r.id.name;if(S.isFunctionDeclaration(r)&&!r.id)return"default"}t=t.parentPath}return null}function Qb(){let e=new Map;return{getOrdinal(t,n){let r=t??"__root__";e.has(r)||e.set(r,new Map);let o=e.get(r),i=o.get(n)??0;return o.set(n,i+1),i}}}function qb(e){let t=new Map;for(let n of e.program.body){if(!S.isImportDeclaration(n))continue;let r=n.source.value;for(let o of n.specifiers)if(S.isImportDefaultSpecifier(o))t.set(o.local.name,{specifier:r,exportName:"default"});else if(S.isImportNamespaceSpecifier(o))t.set(o.local.name,{specifier:r,exportName:"*"});else if(S.isImportSpecifier(o)){let i=S.isIdentifier(o.imported)?o.imported.name:o.imported.value;t.set(o.local.name,{specifier:r,exportName:i})}}return t}function Wt(e,t=[]){if(S.isIdentifier(e))return t.push(e.name),t;if(S.isObjectPattern(e)){for(let n of e.properties)S.isObjectProperty(n)?Wt(n.value,t):S.isRestElement(n)&&Wt(n.argument,t);return t}if(S.isArrayPattern(e)){for(let n of e.elements)n&&(S.isRestElement(n)?Wt(n.argument,t):Wt(n,t));return t}return S.isAssignmentPattern(e)?(Wt(e.left,t),t):(S.isRestElement(e)&&Wt(e.argument,t),t)}function vt(e,t){return e.start==null||e.end==null?"":t.slice(e.start,e.end)}function _r(e,t){for(let n=t.length-1;n>=0;n-=1){let r=t[n].get(e);if(r)return r.resolved?{kind:"resolved",value:r.value}:{kind:"unresolved"}}return{kind:"unresolved"}}function eS(e,t,n){e.set(t,{resolved:!0,value:n})}function ma(e,t){e.set(t,{resolved:!1})}function hd(e,t){let n=e;for(let r of t){if(r.kind==="property"){if(n==null||Array.isArray(n)||typeof n!="object"||!(r.name in n))return{kind:"known-empty"};n=n[r.name];continue}if(!Array.isArray(n)||r.index<0||r.index>=n.length)return{kind:"known-empty"};n=n[r.index]}return{kind:"resolved",value:n}}function $e(e,t,n){if(S.isTSAsExpression(e)||S.isTSSatisfiesExpression(e)||S.isTSNonNullExpression(e)||S.isTypeCastExpression(e)||S.isParenthesizedExpression(e))return $e(e.expression,t,n);if(S.isLogicalExpression(e))return ui([$e(e.left,t,n),$e(e.right,t,n)]);if(S.isBinaryExpression(e))return ui([S.isExpression(e.left)?$e(e.left,t,n):null,S.isExpression(e.right)?$e(e.right,t,n):null]);if(S.isConditionalExpression(e))return ui([$e(e.consequent,t,n),$e(e.alternate,t,n)]);if(S.isTemplateLiteral(e))return ui(e.expressions.filter(S.isExpression).map(i=>$e(i,t,n)));if(S.isIdentifier(e))return{kind:"identifier",expression:e.name,base:e.name,path:[]};if(!S.isMemberExpression(e)&&!S.isOptionalMemberExpression(e))return null;let r=[],o=e;for(;S.isMemberExpression(o)||S.isOptionalMemberExpression(o);){if(o.computed)if(S.isNumericLiteral(o.property))r.unshift({kind:"index",index:o.property.value});else if(S.isStringLiteral(o.property))r.unshift({kind:"property",name:o.property.value});else if(n&&S.isExpression(o.property)){let i=on(o.property,n);if(typeof i=="string")r.unshift({kind:"property",name:i});else if(Number.isInteger(i))r.unshift({kind:"index",index:i});else return null}else return null;else{if(!S.isIdentifier(o.property))return null;r.unshift({kind:"property",name:o.property.name})}o=o.object}return S.isIdentifier(o)?{kind:r.some(i=>i.kind==="index")?"index-expression":"member-expression",expression:vt(e,t),base:o.name,path:r}:null}function ui(e){let t=e.filter(r=>r!==null);if(t.length===0)return null;let n=t[0];return t.some(r=>r.base!==n.base||JSON.stringify(r.path)!==JSON.stringify(n.path))?null:{...n}}function on(e,t){if(S.isStringLiteral(e)||S.isNumericLiteral(e)||S.isBooleanLiteral(e))return e.value;if(S.isNullLiteral(e))return null;if(S.isTemplateLiteral(e))return e.expressions.length===0&&e.quasis.length===1?e.quasis[0].value.cooked??e.quasis[0].value.raw:void 0;if(S.isIdentifier(e)){let n=_r(e.name,t.valueScopes);return n.kind==="resolved"?n.value:void 0}if(S.isArrayExpression(e)){let n=[];for(let r of e.elements){if(!r||S.isSpreadElement(r))return;let o=on(r,t);if(o===void 0)return;n.push(o)}return n}if(S.isObjectExpression(e)){let n={};for(let r of e.properties){if(!S.isObjectProperty(r)||r.computed||!S.isExpression(r.value))return;let o=null;if(S.isIdentifier(r.key)?o=r.key.name:S.isStringLiteral(r.key)&&(o=r.key.value),!o)return;let i;if(r.shorthand){if(!S.isIdentifier(r.value))return;let s=_r(r.value.name,t.valueScopes);if(s.kind!=="resolved")return;i=s.value}else i=on(r.value,t);if(i===void 0)return;n[o]=i}return n}if(S.isMemberExpression(e)){let n=$e(e,"",t);if(!n)return;let r=_r(n.base,t.valueScopes);if(r.kind!=="resolved")return;let o=hd(r.value,n.path);return o.kind==="resolved"?o.value:void 0}if(S.isCallExpression(e))return xd(e,t)??void 0}function yd(e,t,n){let r=$e(e,n,t);if(!r)return S.isMemberExpression(e)||S.isBinaryExpression(e)||S.isLogicalExpression(e)||S.isConditionalExpression(e)||S.isCallExpression(e)?{value:vt(e,n),source:null}:null;let o=_r(r.base,t.valueScopes),i=r.kind==="identifier"?o:o.kind==="resolved"?hd(o.value,r.path):o;return i.kind==="resolved"&&(typeof i.value=="string"||typeof i.value=="number")?{value:String(i.value),source:r}:i.kind==="resolved"&&(typeof i.value=="boolean"||i.value===null)||i.kind==="known-empty"?null:{value:r.expression,source:r}}function la(e,t,n,r,o,i){return{file:e,componentName:t,elements:n,regions:r,ordinalTracker:Qb(),parentStack:[],valueScopes:i,importMap:o}}function da(e,t,n){for(let r of e)for(let o of r.declarations){for(let s of Wt(o.id))ma(n,s);if(!S.isIdentifier(o.id)||!o.init||!S.isExpression(o.init))continue;let i=on(o.init,t);i!==void 0&&eS(n,o.id.name,i)}}function tS(e){let t=[];for(let n of e){if(S.isVariableDeclaration(n)){t.push(n);continue}S.isExportNamedDeclaration(n)&&n.declaration&&S.isVariableDeclaration(n.declaration)&&t.push(n.declaration)}return t}function nS(e,t,n){let r=[],o=0;for(let i of e)if(S.isJSXText(i)){let s=i.value.trim();s&&r.push({index:o++,value:s,sourceRange:Ge(i),editable:!0,source:null})}else if(S.isJSXExpressionContainer(i)&&S.isStringLiteral(i.expression))r.push({index:o++,value:i.expression.value,sourceRange:Ge(i),editable:!0,source:null});else if(S.isJSXExpressionContainer(i)&&S.isTemplateLiteral(i.expression)){let s=i.expression;s.expressions.length===0&&s.quasis.length===1?r.push({index:o++,value:s.quasis[0].value.cooked??s.quasis[0].value.raw,sourceRange:Ge(i),editable:!0,source:null}):r.push({index:o++,value:vt(s,n),sourceRange:Ge(i),editable:!0,source:$e(s,n,t)})}else if(S.isJSXExpressionContainer(i)&&S.isExpression(i.expression)){let s=yd(i.expression,t,n);s&&r.push({index:o++,value:s.value,sourceRange:Ge(i),editable:!0,source:s.source})}return r}function rS(e,t,n){let r=[];for(let[o,i]of e.attributes.entries()){if(!S.isJSXAttribute(i))continue;let s=iS(i.name);if(!s)continue;let a=vt(i,n);if(S.isStringLiteral(i.value)){r.push({name:s,value:i.value.value,sourceRange:Ge(i),source:null,syntaxKind:"literal",raw:a,order:o,resolution:{status:"resolved",value:i.value.value}});continue}if(i.value===null){r.push({name:s,value:"true",sourceRange:Ge(i),source:null,syntaxKind:"boolean-shorthand",raw:a,order:o,resolution:{status:"resolved",value:!0},resolvedValue:!0});continue}if(S.isJSXExpressionContainer(i.value)&&S.isExpression(i.value.expression)){let c=on(i.value.expression,t);if(s==="className"){let u=typeof c=="string"?c:c===void 0?xd(i.value.expression,t):null;if(u){r.push({name:s,value:u,sourceRange:Ge(i),source:null,resolvedValue:u,syntaxKind:"expression",raw:a,order:o,resolution:{status:"resolved",value:u}});continue}}let l=yd(i.value.expression,t,n);if(c!==void 0){r.push({name:s,value:fS(c),sourceRange:Ge(i),source:$e(i.value.expression,n,t),resolvedValue:c,syntaxKind:"expression",raw:a,order:o,resolution:{status:"resolved",value:c}});continue}let d=sS(i.value.expression,t),f=$e(i.value.expression,n,t),m=l?.value??vt(i.value.expression,n);r.push({name:s,value:d.status==="undefined"?"undefined":m,sourceRange:Ge(i),source:l?.source??f,syntaxKind:"expression",raw:a,order:o,resolution:d})}}return r}function oS(e,t,n){return e.attributes.flatMap((r,o)=>!S.isJSXSpreadAttribute(r)||!S.isExpression(r.argument)?[]:[{raw:vt(r.argument,n),sourceRange:Ge(r),order:o,source:$e(r.argument,n,t)}])}function iS(e){return S.isJSXIdentifier(e)?e.name:S.isJSXNamespacedName(e)?`${e.namespace.name}:${e.name.name}`:null}function sS(e,t){return Ot(e,{resolveIdentifier(n){let r=_r(n,t.valueScopes);return r.kind==="resolved"?{status:"resolved",value:r.value}:n==="undefined"&&!t.valueScopes.some(o=>o.has(n))?{status:"undefined"}:{status:"unresolved"}},resolveMember(n){let r=on(n,t);return r===void 0?{status:"unresolved"}:{status:"resolved",value:r}}})}function xd(e,t){let n=nr(e,t);return n&&n.map(o=>o.trim()).filter(Boolean).join(" ")||null}function nr(e,t){if(S.isStringLiteral(e))return[e.value];if(S.isTemplateLiteral(e))return e.expressions.length>0?null:[e.quasis.map(n=>n.value.cooked??"").join("")];if(S.isNullLiteral(e))return[];if(S.isBooleanLiteral(e))return e.value?null:[];if(S.isIdentifier(e)||S.isMemberExpression(e)){if(S.isIdentifier(e)&&e.name==="undefined")return[];let n=on(e,t);return typeof n=="string"?[n]:null}if(S.isConditionalExpression(e)){let n=nr(e.consequent,t),r=nr(e.alternate,t);return!n||!r?null:[...n,...r]}if(S.isLogicalExpression(e)){if(e.operator!=="&&")return null;let n=on(e.left,t);return n===!1||n===null?[]:nr(e.right,t)}if(S.isArrayExpression(e)){let n=[];for(let r of e.elements){if(!r||S.isSpreadElement(r))return null;let o=nr(r,t);if(!o)return null;n.push(...o)}return n}if(S.isObjectExpression(e)){let n=[];for(let r of e.properties){if(!S.isObjectProperty(r))return null;let o=cS(r.key);if(!o)return null;n.push(o)}return n}if(S.isCallExpression(e)){let n=aS(e.callee);if(!n||!["cn","clsx","twMerge"].includes(n))return null;let r=[];for(let o of e.arguments){if(!S.isExpression(o))return null;let i=nr(o,t);if(!i)return null;r.push(...i)}return r}return null}function aS(e){return S.isIdentifier(e)?e.name:S.isMemberExpression(e)&&S.isIdentifier(e.property)?e.property.name:null}function cS(e){return S.isIdentifier(e)?e.name:S.isStringLiteral(e)?e.value:null}function lS(e,t){let n=e.attributes.find(r=>S.isJSXAttribute(r)&&S.isJSXIdentifier(r.name)&&r.name.name===t);return!n||!S.isJSXAttribute(n)||!S.isJSXExpressionContainer(n.value)?null:n.value.expression}function uS(e,t){for(let n of t){let r=lS(e,n);if(r)return r}return null}function dS(e){return S.isJSXIdentifier(e.name)?e.name.name:null}function fS(e){return e===null?"null":typeof e=="boolean"?e?"true":"false":JSON.stringify(e)}function pS(e){if(!S.isCallExpression(e)&&!S.isOptionalCallExpression(e))return null;let t=e.callee;return!S.isMemberExpression(t)&&!S.isOptionalMemberExpression(t)||!S.isIdentifier(t.property)||t.property.name!=="map"||t.computed||!S.isExpression(t.object)?null:{call:e,collection:t.object,callback:e.arguments[0]}}function ua(e){return S.isArrowFunctionExpression(e)||S.isFunctionExpression(e)}function mS(e){return e==="render"||e==="itemRender"||e==="rowRender"||e==="children"}function gS(e){return e==="empty"||e==="emptyRender"||e==="loading"||e==="loadingRender"||e==="error"||e==="errorRender"||e==="fallback"||e==="headerRender"||e==="footerRender"}function pd(e,t,n,r){if(!e||!S.isExpression(e))return null;let o={kind:"repeat-template",collectionExpression:vt(e,n),collectionSource:$e(e,n,r)};if(t){let i=t.params[0],s=t.params[1];S.isIdentifier(i)&&(o.itemParamName=i.name),S.isIdentifier(s)&&(o.indexParamName=s.name)}return o}function Ht(e,t,n){if(!e)return[];if(S.isJSXElement(e)){if(pa(e))return gi(e.children,t,n);let r=pi(e,t,n);return r?[r]:[]}return rr(e)?mi(e,t,n):S.isParenthesizedExpression(e)?Ht(e.expression,t,n):S.isExpression(e)?hi(e,t,n):[]}function di(e,t,n){let r=new Map;for(let o of e.params)for(let i of Wt(o))ma(r,i);t.valueScopes.push(r);try{if(!S.isBlockStatement(e.body))return Ht(e.body,t,n);let o=new Map;t.valueScopes.push(o);try{return bd(e.body.body,t,n)}finally{t.valueScopes.pop()}}finally{t.valueScopes.pop()}}function bd(e,t,n){let r=[];for(let o of e){if(S.isVariableDeclaration(o)){let i=t.valueScopes[t.valueScopes.length-1];if(i){da([o],t,i);for(let s of o.declarations)S.isIdentifier(s.id)&&(S.isJSXElement(s.init)||S.isJSXFragment(s.init))&&r.push(...Ht(s.init,t,n))}continue}r.push(...fa(o,t,n))}return r}function fa(e,t,n){if(S.isReturnStatement(e))return e.argument?Ht(e.argument,t,n):[];if(S.isBlockStatement(e))return Nn(e.body,t,n);if(S.isIfStatement(e)){let r=S.isBlockStatement(e.consequent)?Nn(e.consequent.body,t,n):fa(e.consequent,t,n),o=e.alternate?S.isBlockStatement(e.alternate)?Nn(e.alternate.body,t,n):fa(e.alternate,t,n):[];return[...r,...o]}if(S.isSwitchStatement(e))return Nn(e.cases.flatMap(r=>r.consequent),t,n);if(S.isTryStatement(e)){let r=Nn(e.block.body,t,n);return e.handler&&r.push(...Nn(e.handler.body.body,t,n)),e.finalizer&&r.push(...Nn(e.finalizer.body,t,n)),r}return[]}function Nn(e,t,n){let r=new Map;t.valueScopes.push(r);try{return bd(e,t,n)}finally{t.valueScopes.pop()}}function fi(e,t,n,r,o,i){o.length!==0&&e.regions.push({kind:t,ownerKey:n,childKeys:o,sourceRange:Ge(r),sourceCandidates:i&&i.length>0?i:void 0})}function hS(e,t,n,r){let o=uS(e.openingElement,["items","dataSource","data"]),i={key:t,tag:md(e.openingElement)};n.parentStack.push(i);try{for(let s of e.openingElement.attributes){if(!S.isJSXAttribute(s))continue;let a=dS(s);if(!a||!S.isJSXExpressionContainer(s.value))continue;let c=s.value.expression;if(!S.isJSXEmptyExpression(c)){if(mS(a)&&ua(c)){let l=di(c,n,r),d=pd(o,c,r,n);fi(n,"repeat-region",t,s,l,d?[d]:void 0);continue}if(gS(a)){let l=ua(c)?di(c,n,r):Ht(c,n,r);fi(n,"conditional-region",t,s,l)}}}if(o)for(let s of e.children){if(!S.isJSXExpressionContainer(s)||!ua(s.expression))continue;let a=di(s.expression,n,r),c=pd(o,s.expression,r,n);fi(n,"repeat-region",t,s,a,c?[c]:void 0)}}finally{n.parentStack.pop()}}function pi(e,t,n){let r=md(e.openingElement);if(r==="Fragment"||pa(e))return gi(e.children,t,n),null;let o=t.parentStack[t.parentStack.length-1]??null,i=o?.key??null,s=Gb(r),a;if(s){let R=t.ordinalTracker.getOrdinal(i,r);a=`component:${r}#${R}`}else{let R=t.ordinalTracker.getOrdinal(i,r);a=`${r}#${R}`}let c=o?t.elements.get(o.key)?.identity.structuralPath:void 0,l=c?`${c}/${a}`:a,d=wr(t.file,t.componentName,l),f={file:t.file,component:t.componentName,structuralPath:l,key:d},m=s?"component-boundary":null,u=nS(e.children,t,n),g=rS(e.openingElement,t,n),h=oS(e.openingElement,t,n),b,E,v=!1;if(s){let R=t.importMap.get(r)??t.importMap.get(Yb(r));R&&(b=R.specifier,E=R.exportName,v=vn(R.specifier,t.file))}let I={identity:f,tag:r,componentName:t.componentName,sourceFile:t.file,sourceRange:Ge(e),parentKey:i,childKeys:[],textSegments:u,attributes:g.length>0?g:void 0,attributeSpreads:h.length>0?h:void 0,boundaryKind:m,isOpaque:s,...v?{isPublicUiComponent:!0}:{},importedFrom:b,exportName:E};return t.elements.set(d,I),i&&t.elements.has(i)&&t.elements.get(i).childKeys.push(d),hS(e,d,t,n),(!s||e.children.length>0)&&(t.parentStack.push({key:d,tag:r}),yS(e.children,t,n),t.parentStack.pop()),d}function mi(e,t,n){return gi(e.children,t,n)}function gi(e,t,n){let r=[];for(let o of e)if(S.isJSXElement(o))if(pa(o))r.push(...gi(o.children,t,n));else{let i=pi(o,t,n);i&&r.push(i)}else rr(o)?r.push(...mi(o,t,n)):S.isJSXExpressionContainer(o)&&r.push(...hi(o.expression,t,n));return r}function yS(e,t,n){for(let r of e)S.isJSXElement(r)?pi(r,t,n):rr(r)?mi(r,t,n):S.isJSXExpressionContainer(r)&&hi(r.expression,t,n)}function xS(e){return e==="&&"||e==="||"||e==="??"}function hi(e,t,n){if(S.isJSXEmptyExpression(e))return[];let r=pS(e);if(r){let o=r.call,i=t.parentStack[t.parentStack.length-1]??null,s=[],a=r.callback,c={kind:"repeat-template",collectionExpression:vt(r.collection,n),collectionSource:$e(r.collection,n,t)};if(S.isArrowFunctionExpression(a)||S.isFunctionExpression(a)){let d=a.params[0],f=a.params[1];S.isIdentifier(d)&&(c.itemParamName=d.name),S.isIdentifier(f)&&(c.indexParamName=f.name)}s.push(c);let l={kind:"repeat-region",ownerKey:i?.key??"",childKeys:[],sourceRange:Ge(o),sourceCandidates:s.length>0?s:void 0};return t.regions.push(l),(S.isArrowFunctionExpression(a)||S.isFunctionExpression(a))&&l.childKeys.push(...di(a,t,n)),l.childKeys}if(S.isConditionalExpression(e)){let o=t.parentStack[t.parentStack.length-1]??null,i={kind:"conditional-branch",conditionExpression:vt(e.test,n),conditionSource:$e(e.test,n,t)},s={kind:"conditional-region",ownerKey:o?.key??"",childKeys:[],sourceRange:Ge(e),sourceCandidates:[i]};return t.regions.push(s),s.childKeys.push(...Ht(e.consequent,t,n)),s.childKeys.push(...Ht(e.alternate,t,n)),s.childKeys}if(S.isLogicalExpression(e)&&xS(e.operator)){let o=t.parentStack[t.parentStack.length-1]??null,i={kind:"conditional-branch",conditionExpression:vt(e.left,n),conditionSource:$e(e.left,n,t)},s={kind:"conditional-region",ownerKey:o?.key??"",childKeys:[],sourceRange:Ge(e),sourceCandidates:[i]};return t.regions.push(s),s.childKeys.push(...Ht(e.right,t,n)),s.childKeys}if(S.isParenthesizedExpression(e))return hi(e.expression,t,n);if(S.isJSXElement(e)){let o=pi(e,t,n);return o?[o]:[]}return rr(e)?mi(e,t,n):[]}function bS(e){let t=e.argument;return t&&(S.isExpression(t)||rr(t))?t:null}function Or(e,t){let n=[];for(let r of e){if(S.isReturnStatement(r)){let o=bS(r);o&&n.push({argument:o,statement:r,condition:t});continue}if(S.isIfStatement(r)){let o=S.isBlockStatement(r.consequent)?r.consequent.body:[r.consequent];if(n.push(...Or(o,r.test)),r.alternate){let i=S.isBlockStatement(r.alternate)?r.alternate.body:[r.alternate];n.push(...Or(i,r.test))}continue}if(S.isSwitchStatement(r))for(let o of r.cases){let i=o.test?S.binaryExpression("===",r.discriminant,o.test):r.discriminant;n.push(...Or(o.consequent,i))}}return n}function Sd(e){let{file:t,source:n,ast:r}=e,o=e.imports.map(f=>f.specifier),i=new Map,s=[],a=[],c=new Map,l=qb(r);Hb(r,{"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression"(f){let m=Zb(f);if(!m)return;let u=f.node,g=[];if(S.isArrowFunctionExpression(u))S.isExpression(u.body)||rr(u.body)?g=[{argument:u.body,statement:S.returnStatement(S.isExpression(u.body)?u.body:null)}]:S.isBlockStatement(u.body)&&(g=Or(u.body.body));else{let R=u.body;S.isBlockStatement(R)&&(g=Or(R.body))}if(g.length===0){f.skip();return}let h=new Map;da(tS(r.program.body),la(t,m,i,s,l,[h]),h);let b=new Map;for(let R of u.params)for(let A of Wt(R))ma(b,A);let E=S.isBlockStatement(u.body)?u.body.body:[],v=g[0]?.statement??null;for(let R of E){if(v&&R===v)break;S.isVariableDeclaration(R)&&da([R],la(t,m,i,s,l,[h,b]),b)}let I=la(t,m,i,s,l,[h,b]);for(let R of g){let A=Ht(R.argument,I,n);for(let T of A)a.includes(T)||a.push(T);if(R.condition){let T={kind:"conditional-branch",conditionExpression:vt(R.condition,n),conditionSource:$e(R.condition,n,I)};fi(I,"conditional-region","",R.statement,A,[T])}}f.skip()}});let d=[...i.keys()];return d.length>0&&c.set(t,d),{graph:{routeId:t,rootKeys:a,elements:i,regions:s,fileIndex:c,version:1,diagnostics:[]},localImports:o}}function ga(e,t,n,r){return[...e.map(o=>({...o})),{fromFile:t,specifier:n,targetPath:r}]}function yi(e,t,n){return{...e,details:{...e.details??{},entryFile:t,importStack:n.map(r=>({...r}))}}}async function Ed(e,t,n,r,o={}){let i=o.maxDepth??10,s=o.version??1,a=o.parseModule??En,c=new Map,l=new Map,d=new Map,f=[],m=new Set,u=E=>{let v=`${E.path}\0${E.code}\0${E.message}\0${JSON.stringify(E.details??{})}`;m.has(v)||(m.add(v),f.push(E))},g=[{file:e,source:t,depth:0,diagnosticEntryFile:e,importStack:[]},...(o.additionalEntries??[]).map(E=>({file:E.file,source:E.source,depth:0,diagnosticEntryFile:E.file,importStack:[]}))],h=new Set;for(;g.length>0;){let E=g.shift(),{file:v,source:I,depth:R,diagnosticEntryFile:A,importStack:T}=E;if(h.has(v))continue;h.add(v),c.set(v,I);let C=a(v,I);if(!C.ok){u(yi(C.diagnostic,A,T));continue}d.set(v,C.module);let{graph:P,localImports:O}=Sd(C.module);for(let D of P.elements.values())if(D.importedFrom&&Pt(D.importedFrom)){let U=D.importedFrom,ee=await Fo(v,U,r);ee.ok?(D.importedFrom=ee.path,Ut(ee.path)&&(D.isPublicUiComponent=!0)):vn(U,v)||u(yi(ee.diagnostic,A,ga(T,v,U,ee.diagnostic.path)))}if(l.set(v,P),!(R>=i))for(let D of O){if(ou(D))continue;let U=await Fo(v,D,r);if(!U.ok){vn(D,v)||u(yi(U.diagnostic,A,ga(T,v,D,U.diagnostic.path)));continue}let ee=U.path;if(h.has(ee)||Ut(ee))continue;let Re=ga(T,v,D,ee);try{let Q=await n(ee);g.push({file:ee,source:Q,depth:R+1,diagnosticEntryFile:A,importStack:Re})}catch(Q){u(yi({path:ee,code:"import-read-failed",message:`Failed to read imported file: ${ee}`,details:{fromFile:v,specifier:D,reason:Q instanceof Error?Q.message:String(Q)}},A,Re))}}}let b=SS(e,l,s,(o.additionalEntries??[]).map(E=>E.file));return b.diagnostics=f,{graph:b,allSources:c,diagnostics:f,parsedModules:d,entryModule:d.get(e)??null}}function SS(e,t,n,r=[]){let o=new Map,i=[],s=new Map,a=[];for(let[c,l]of t){for(let[d,f]of l.elements)o.set(d,f);for(let d of l.regions)i.push(d);for(let[d,f]of l.fileIndex){let m=s.get(d)??[];s.set(d,[...m,...f])}if(c===e){a=l.rootKeys;continue}r.includes(c)&&(a=[...a,...l.rootKeys])}return{routeId:e,rootKeys:a,elements:o,regions:i,fileIndex:s,version:n}}import{SiteEditHistoryProvenanceSchema as ES}from"@vcp-dev/contracts";var vS={affectedCompositions:[]};function Nd(e){let t=null,n=new WeakMap;async function r(){return t??=kS(e),t}return{async prepareAppend(o){let i=await e.readIndex(),s=await e.stageAppend(Cd(o),{durableManifest:!1}),a;try{a=await e.previewStagedAppend(s.entryId,i.digest)}catch(l){throw await e.discardStage(s.stageId),l}let c={kind:"append",entry:o,historyTransition:a};return n.set(c,{expectedDigest:i.digest,stageId:s.stageId,entryId:s.entryId}),c},async prepareUndo(){let i=(await r()).undo.at(-1);if(!i?.historyId)return null;let s=await e.readIndex(),a=s.entryIds.indexOf(i.historyId);if(a<0)throw new Error("undo entry is missing from index");let c=a-1,l=await e.previewCursor(c,s.digest),d={kind:"undo",entry:i,historyTransition:l};return n.set(d,{expectedDigest:s.digest,cursor:c}),d},async prepareRedo(){let i=(await r()).redo.at(-1);if(!i?.historyId)return null;let s=await e.readIndex(),a=s.entryIds.indexOf(i.historyId);if(a<0)throw new Error("redo entry is missing from index");let c=a,l=await e.previewCursor(c,s.digest),d={kind:"redo",entry:i,historyTransition:l};return n.set(d,{expectedDigest:s.digest,cursor:c}),d},async publishPrepared(o){let i=n.get(o);if(!i)throw new Error("history mutation was not prepared");let s=await r();if(o.kind==="append"){if(!i.entryId)throw new Error("staged entry id is missing");let a=await e.publishStagedAppend(i.entryId,i.expectedDigest,i.stageId);vd(a,o.historyTransition),o.entry.historyId=i.entryId,s.entryIds=[...a.entryIds],s.cursor=a.cursor,s.undo.push(o.entry),s.redo.length=0}else{if(i.cursor===void 0)throw new Error("prepared cursor is missing");let a=await e.setCursor(i.cursor,i.expectedDigest);if(vd(a,o.historyTransition),o.kind==="undo"){if(s.undo.at(-1)!==o.entry)throw new Error("undo state changed before publish");s.undo.pop(),s.redo.push(o.entry)}else{if(s.redo.at(-1)!==o.entry)throw new Error("redo state changed before publish");s.redo.pop(),s.undo.push(o.entry)}s.cursor=i.cursor}n.delete(o)},async discardPrepared(o){let i=n.get(o);if(!i)return;let s=o.historyTransition;if(s){let a=await e.readIndex();if(a.digest===s.publishedIndexDigest&&a.cursor===s.publishedCursor&&a.currentId===s.publishedCurrentId)throw new Error("cannot discard a history mutation whose index was published")}i.stageId&&await e.discardStage(i.stageId),n.delete(o)},async peekUndo(){return(await r()).undo.at(-1)??null},async pushUndo(o){let i=await r(),s=o;if(s.historyId){let l=i.entryIds.indexOf(s.historyId);if(l>=0)try{await e.setCursor(l),i.undo.push(o),i.cursor=l;return}catch(d){throw i.redo.push(o),d}}let a=await e.append(Cd(o)),c=a.currentId;if(!c)throw new Error("history store did not publish an entry");o.historyId=c,i.entryIds=[...a.entryIds],i.cursor=a.cursor,i.undo.push(o),i.redo.length=0},async popUndo(){return(await r()).undo.pop()??null},async peekRedo(){return(await r()).redo.at(-1)??null},async pushRedo(o){let i=await r(),s=o;if(!s.historyId)throw i.undo.push(o),new Error("cannot move an unpersisted history entry to redo");let a=i.entryIds.indexOf(s.historyId);if(a<0)throw i.undo.push(o),new Error("history entry is missing from the durable index");try{await e.setCursor(a-1),i.cursor=a-1,i.redo.push(o)}catch(c){throw i.undo.push(o),c}},async popRedo(){return(await r()).redo.pop()??null},async clearRedo(){(await r()).redo.length=0},async getStatus(){let o=await e.readStatus();return{canUndo:o.canUndo,canRedo:o.canRedo,undoDepth:o.undoDepth,redoDepth:o.redoDepth,recoveryRequired:o.recoveryRequired}},async markRecoveryRequired(o){await e.markRecoveryRequired(o)}}}function vd(e,t){if(!t)throw new Error("durable history transition is missing");if(e.digest!==t.publishedIndexDigest||e.cursor!==t.publishedCursor||e.currentId!==t.publishedCurrentId)throw new Error("durable history published an unexpected index state")}async function kS(e){let t=await e.readIndex(),n=await Promise.all(t.undoIds.map(async o=>kd(e,o))),r=await Promise.all(t.redoIds.map(async o=>kd(e,o)));return{undo:n.reverse(),redo:r.reverse(),entryIds:[...t.entryIds],cursor:t.cursor}}async function kd(e,t){let n=await e.readEntry(t),r=IS(n),o=r.provenance??vS;return{historyId:t,...o.initiatingComposition?{composition:o.initiatingComposition}:{},operationId:r.operationId,kind:r.kind,target:r.target,provenance:o,...r.selectionRef?{selectionRef:r.selectionRef}:{},...r.output?{output:r.output}:{},preSnapshots:await Id(e,n,r.preSnapshots),postSnapshots:await Id(e,n,r.postSnapshots)}}async function Id(e,t,n){let r=new Map(t.blobs.map(o=>[o.name,o.digest]));return Promise.all(n.map(async o=>{let i=o.exists&&o.blobName?Buffer.from(await e.readBlob(NS(r,o.blobName))).toString("utf8"):"";return{file:o.file,content:i,version:o.version,exists:o.exists,...o.sha256?{sha256:o.sha256}:{}}}))}function Cd(e){let t=[],n=(i,s)=>i.map((a,c)=>{let l={file:a.file,exists:a.exists!==!1,version:a.version,...a.sha256?{sha256:a.sha256}:{}};if(l.exists){let d=`${s}-${c}`;l.blobName=d,t.push({name:d,data:a.content})}return l}),r=CS(e),o={operationId:e.operationId,kind:e.kind,target:e.target,...r?{provenance:r}:{},...e.selectionRef?{selectionRef:e.selectionRef}:{},...e.output?{output:e.output}:{},preSnapshots:n(e.preSnapshots,"pre"),postSnapshots:n(e.postSnapshots,"post")};return{kind:"site-edit-operation",manifest:JSON.parse(JSON.stringify(o)),blobs:t}}function IS(e){if(!Pd(e.manifest))throw new Error("durable history manifest is not an object");let t=e.manifest,n=new Set(["operationId","kind","target","selectionRef","output","provenance","preSnapshots","postSnapshots"]);if(Object.keys(t).some(r=>!n.has(r)))throw new Error("durable history manifest contains unknown fields");if(typeof t.operationId!="string"||t.operationId.length===0||typeof t.kind!="string"||t.kind.length===0||!Array.isArray(t.preSnapshots)||!Array.isArray(t.postSnapshots))throw new Error("durable history manifest has an invalid shape");return{operationId:t.operationId,kind:t.kind,target:t.target,...t.selectionRef!==void 0?{selectionRef:t.selectionRef}:{},...t.output!==void 0?{output:t.output}:{},...t.provenance!==void 0?{provenance:wd(t.provenance)}:{},preSnapshots:Rd(t.preSnapshots,"preSnapshots"),postSnapshots:Rd(t.postSnapshots,"postSnapshots")}}function CS(e){if(e.provenance!==void 0)return wd(e.provenance);if(e.composition)return{initiatingComposition:e.composition,affectedCompositions:[]}}function wd(e){let t=ES.safeParse(e);if(!t.success)throw new Error("durable history provenance is invalid");return{...t.data.initiatingComposition?{initiatingComposition:t.data.initiatingComposition}:{},affectedCompositions:t.data.affectedCompositions.map(n=>({routeId:n.routeId,...n.effectiveTemplateId?{effectiveTemplateId:n.effectiveTemplateId}:{}}))}}function Rd(e,t){return e.map((n,r)=>{if(!Pd(n))throw new Error(`durable history ${t}[${r}] is invalid`);if(typeof n.file!="string"||n.file.length===0||!Number.isInteger(n.version)||n.exists!==void 0&&typeof n.exists!="boolean"||n.sha256!==void 0&&!RS(n.sha256)||n.blobName!==void 0&&typeof n.blobName!="string")throw new Error(`durable history ${t}[${r}] is invalid`);return{file:n.file,exists:n.exists!==!1,version:n.version,...n.sha256?{sha256:n.sha256}:{},...n.blobName?{blobName:n.blobName}:{}}})}function RS(e){return/^sha256:[0-9a-f]{64}$/.test(e)}function NS(e,t){let n=e.get(t);if(!n)throw new Error(`durable history blob is missing: ${t}`);return n}function Pd(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}import{COMPONENT_I18N_FILE_SUFFIX as wS,parseComponentI18nResourcesJson as PS,resolveSiteTextDirection as AS,SiteLocaleSchema as TS}from"@vcp-dev/contracts";var FS=["i18next","react-i18next"],_S="components/ui/site-locale-provider.tsx",OS="components/ui/component-i18n-provider.tsx",Ad="app/layout.tsx";async function ya(e){let t=e.files.filter(m=>m.path.endsWith(wS));if(t.length===0)return{ok:!0};for(let m of["package.json",Ad,_S,OS])if(!await e.exists(m))return wn(`Target snapshot is missing required i18n host file: ${m}`);let n;try{n=JSON.parse(await e.readFile("package.json"))}catch{return wn("Target snapshot package.json is invalid.")}let r=Td(n)&&Td(n.dependencies)?n.dependencies:{},o=FS.filter(m=>typeof r[m]!="string"||r[m].trim().length===0);if(o.length>0)return wn(`Target snapshot must already declare: ${o.join(", ")}.`);let i=await e.readFile(Ad),s=ha(i,"html","lang"),a=ha(i,"html","dir"),c=ha(i,"SiteLocaleProvider","locale"),l=TS.safeParse(s);if(!l.success||!a||!c||s!==c||a!==AS(l.data))return wn("Target snapshot app/layout.tsx must keep html lang/dir and SiteLocaleProvider locale consistent.");if(!i.includes('from "@/components/ui/site-locale-provider"')||!/<SiteLocaleProvider\b/.test(i)||!/<\/SiteLocaleProvider>/.test(i))return wn("Target snapshot root layout is not wired to SiteLocaleProvider.");let d=l.data,f=d.split("-")[0];for(let m of t){let u=PS(m.content);if(!u.success)return wn(`Component i18n resource is invalid: ${m.path}.`);if(!Object.hasOwn(u.data,d)&&!Object.hasOwn(u.data,f))return wn(`Component i18n resource ${m.path} has no locale for ${d} or ${f}.`)}return{ok:!0}}function ha(e,t,n){let r=e.match(new RegExp(`<${t}\\b[^>]*>`))?.[0];if(!r)return null;let o=[...r.matchAll(new RegExp(`\\b${n}=(?:"([^"]+)"|\\{"([^"]+)"\\})`,"g"))];return o.length!==1?null:o[0]?.[1]??o[0]?.[2]??null}function Td(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function wn(e){return{ok:!1,message:e}}import{randomBytes as GS}from"node:crypto";import bi from"node:path";import{parse as Vd}from"@babel/parser";import YS from"@babel/traverse";import*as Kd from"@babel/types";import{COMPONENT_I18N_FILE_SUFFIX as ba,PageResourceArtifactSchema as ZS,SITE_EDIT_MATERIALIZATION_MAX_FILE_COUNT as QS,SITE_EDIT_MATERIALIZATION_MAX_FILE_CONTENT_BYTES as qS,SITE_EDIT_MATERIALIZATION_MAX_TOTAL_CONTENT_BYTES as eE,parseComponentI18nResourcesJson as tE}from"@vcp-dev/contracts";var _d=/#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|hwb|oklch|oklab|lab|lch|color)\s*\(/i,Od=/\b(?:bg-black|bg-white|text-white|text-black)(?:\b|\/)/g,MS=/\b(?:bg|text|border|ring|outline|decoration|divide|from|via|to|fill|stroke)-\[#(?:[0-9a-fA-F]{3,8})\](?:\/\d+)?/g,DS=/\b(?:color|backgroundColor|background|borderColor|boxShadow|textShadow)\s*:\s*['"][^'"]*#[0-9a-fA-F]{3,8}[^'"]*['"]/g,LS=/\b(?:bg|text|border|ring|outline|decoration|divide|from|via|to|fill|stroke|shadow)-\[[^\]]*rgba?\([^\]]+\)[^\]]*\](?:\/\d+)?/gi,BS=/\b(?:color|backgroundColor|backgroundImage|background|borderColor|boxShadow|textShadow)\s*:\s*['"][^'"]*rgba?\([^)]+\)[^'"]*['"]/gi,jS=/\b(?:color|backgroundColor|background|borderColor|boxShadow|textShadow)\s*:\s*['"][^'"]*rgba?\([^)]+\)[^'"]*['"]/gi,$S=/\b(?:bg|text|border|ring|outline|decoration|divide|from|via|to|fill|stroke|shadow)-\[[^\]]*(?:oklch|lab|lch|hsla?)\([^\]]+\)[^\]]*\](?:\/\d+)?/gi,VS=/\b(?:color|backgroundColor|backgroundImage|background|borderColor|boxShadow|textShadow)\s*:\s*['"][^'"]*(?:oklch|lab|lch|hsla?)\([^)]+\)[^'"]*['"]/gi,KS=/\b(?:bg|text|border|ring|outline|decoration|divide|from|via|to|fill|stroke|shadow)-\[[^\]]*color-mix\([^\]]+\)[^\]]*\](?:\/\d+)?/gi,US=/\b(?:color|backgroundColor|backgroundImage|background|borderColor|boxShadow|textShadow)\s*:\s*['"][^'"]*color-mix\([^'"]*['"]/gi,JS=/\b(?:bg|text|border|ring|outline|fill|stroke)-(?:black|white|slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)(?:-\d{2,3})?(?:\b|\/)/g,XS=/var\(\s*--(?:_|private-|vcp-)[^)]+\)/gi,zS=/#[0-9a-fA-F]{3,8}\b|\b(?:rgba?|hsla?|hwb|oklch|oklab|lab|lch|color)\s*\([^)]*\)/gi;function Mr(e,t){let n=xi([...ht(e,MS),...ht(e,DS),...ht(e,LS),...ht(e,t.includeRgbBackgroundImage?BS:jS),...t.includeExtendedColorFunctions?[...ht(e,$S),...ht(e,VS)]:[]]),r=xi([...ht(e,KS),...ht(e,US)]).filter(o=>t.colorMixPolicy==="always"||_d.test(o));return n.push(...r.filter(o=>!n.includes(o))),t.rejectTailwindPalette&&n.push(...ht(e,JS).filter(o=>!n.includes(o))),t.rejectAnyRawColorLiteral&&n.push(...ht(e,zS).filter(o=>!n.includes(o))),{hardCodedSurfaceHits:xi(ht(e,Od)),hardCodedSurfaceOccurrences:HS(e),rawColorHits:n,privateTokenHits:t.rejectPrivateTokens?xi(ht(e,XS)):[]}}function ht(e,t){return e.match(new RegExp(t.source,t.flags))??[]}var Fd=160,WS=/((?:[a-z][a-z0-9-]*(?:\[[^\]]*\])?:)+)$/;function HS(e){let t=new RegExp(Od.source,"g"),n=[0];for(let s=0;s<e.length;s+=1)e[s]===`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vcp-dev/site-edit-engine",
3
- "version": "0.10.26",
3
+ "version": "0.10.27",
4
4
  "type": "module",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -60,7 +60,7 @@
60
60
  "@babel/parser": "^7.29.3",
61
61
  "@babel/traverse": "^7.29.0",
62
62
  "@babel/types": "^7.29.0",
63
- "@vcp-dev/contracts": "0.10.26",
63
+ "@vcp-dev/contracts": "0.10.27",
64
64
  "yaml": "^2.9.0"
65
65
  },
66
66
  "devDependencies": {