"use strict";var Zo=Object.create;var Tt=Object.defineProperty;var ei=Object.getOwnPropertyDescriptor;var ti=Object.getOwnPropertyNames;var ni=Object.getPrototypeOf,ri=Object.prototype.hasOwnProperty;var Be=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),oi=(e,t)=>{for(var r in t)Tt(e,r,{get:t[r],enumerable:!0})},zn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ti(t))!ri.call(e,o)&&o!==r&&Tt(e,o,{get:()=>t[o],enumerable:!(n=ei(t,o))||n.enumerable});return e};var ii=(e,t,r)=>(r=e!=null?Zo(ni(e)):{},zn(t||!e||!e.__esModule?Tt(r,"default",{value:e,enumerable:!0}):r,e)),ai=e=>zn(Tt({},"__esModule",{value:!0}),e);var Tn=Be(zt=>{"use strict";Object.defineProperty(zt,"__esModule",{value:!0});function xo(e){return Object.prototype.toString.call(e)}zt.getType=xo;function Ks(e){throw new TypeError("unsupported data type: "+xo(e))}zt.throwUnknownDataType=Ks});var Nn=Be(Re=>{"use strict";Object.defineProperty(Re,"__esModule",{value:!0});var Ie="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);Ie+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);Ie+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);Ie+=t}var it=Ie.length,vn={};for(let e=0;e=0;n--){let o=e[n],i=vn[o];i*=r,t+=i,r*=it}return t}Re.s_to_int=In;function ho(e){let t=BigInt(0),r=BigInt(1),n=BigInt(it);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(vn[i]);a*=r,t+=a,r*=n}return t}Re.s_to_big_int=ho;function Rn(e){if(e===0)return Ie[0];let t=[];for(;e!==0;){let r=e%it,n=Ie[r];t.push(n),e-=r,e/=it}return t.reverse().join("")}Re.int_to_s=Rn;function Eo(e){let t=BigInt(0),r=BigInt(it);if(e===t)return Ie[0];let n=[];for(;e!==t;){let o=e%r,i=Ie[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}Re.big_int_to_s=Eo;function Jt(e){return e.split("").reverse().join("")}function So(e){if(e<0)return"-"+So(-e);let[t,r]=e.toString().split(".");if(!r)return Rn(e);let n;r&&([r,n]=r.split("e")),t=qt(t),r=Jt(r),r=qt(r);let o=t+"."+r;if(n){switch(o+=".",n[0]){case"+":n=n.slice(1);break;case"-":o+="-",n=n.slice(1);break}n=Jt(n),n=qt(n),o+=n}return o}Re.num_to_s=So;function qt(e){let t=+e;return t.toString()===e?Rn(t):":"+Eo(BigInt(e))}Re.int_str_to_s=qt;function bn(e){return e[0]===":"?ho(e.substring(1)).toString():In(e).toString()}function Ao(e){if(e[0]==="-")return-Ao(e.substr(1));let[t,r,n]=e.split(".");if(!r)return In(t);t=bn(t),r=bn(r),r=Jt(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=bn(n),n=Jt(n),o+=i?-n:+n}return+o}Re.s_to_num=Ao});var On=Be(Ne=>{"use strict";Object.defineProperty(Ne,"__esModule",{value:!0});var Bn=Nn();function Ms(e){return"n|"+Bn.num_to_s(e)}Ne.encodeNum=Ms;function Us(e){return e=e.replace("n|",""),Bn.s_to_num(e)}Ne.decodeNum=Us;function zs(e){return typeof e=="number"?e:Bn.s_to_int(e)}Ne.decodeKey=zs;function qs(e){return e?"b|T":"b|F"}Ne.encodeBool=qs;function Js(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}Ne.decodeBool=Js;function Qs(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}Ne.encodeStr=Qs;function Ws(e){return e[0]+e[1]==="s|"?e.substr(2):e}Ne.decodeStr=Ws});var Fo=Be(kn=>{"use strict";Object.defineProperty(kn,"__esModule",{value:!0});kn.config={sort_key:!1}});var _n=Be(Ye=>{"use strict";Object.defineProperty(Ye,"__esModule",{value:!0});var Ys=Fo(),Gs=Tn(),Ln=On(),Hs=Nn();function Xs(e){return e.store.toArray()}Ye.memToValues=Xs;function Po(){let e=[];return{forEach(t){for(let r=0;r{"use strict";Object.defineProperty(yt,"__esModule",{value:!0});var tu=Tn(),Qt=On(),jn=_n();function nu(e){let t=jn.makeInMemoryMemory(),r=jn.addValue(t,e,void 0);return[jn.memToValues(t),r]}yt.compress=nu;function ru(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=Pt(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s{"use strict";Object.defineProperty(Wt,"__esModule",{value:!0});function au(e){for(let t in e)e[t]===void 0&&delete e[t]}Wt.trimUndefined=au;function su(e){wo(e,new Set)}Wt.trimUndefinedRecursively=su;function wo(e,t){t.add(e);for(let r in e)if(e[r]===void 0)delete e[r];else{let n=e[r];n&&typeof n=="object"&&!t.has(n)&&wo(n,t)}}});var Io=Be(Ke=>{"use strict";Object.defineProperty(Ke,"__esModule",{value:!0});var bo=$n();Ke.compress=bo.compress;Ke.decompress=bo.decompress;var uu=$n();Ke.decode=uu.decode;var pu=_n();Ke.addValue=pu.addValue;var vo=To();Ke.trimUndefined=vo.trimUndefined;Ke.trimUndefinedRecursively=vo.trimUndefinedRecursively});var Au={};oi(Au,{createDevTools:()=>Oo,createDevToolsSys:()=>Lo,detectFrameworks:()=>Oe,detectFrameworksFromPackageJson:()=>Gt,ensureConfigPlugin:()=>Go,findBuildToolConfig:()=>Un,getClientScript:()=>Xo,parseDotEnvContent:()=>Ht,version:()=>wt});module.exports=ai(Au);async function bt(e,t){let r=e.resolve("/");for(let n=0;n<20;n++){let o=e.join(t,"package.json"),i=await e.readFile(o);if(i)return JSON.parse(i);if(t===r)break;t=e.dirname(t)}return null}async function qn(e,t){for(let r=0;r<20;r++){let n=e.dirname(t),o=e.join(n,"node_modules");if(await e.exists(o))return o;if(t===e.getAppRootDir())break;t=e.dirname(t)}return e.join(e.getAppRootDir(),"node_modules")}async function at(e,t,r){let n=await e.readdir(t);return n.includes(r)?e.join(t,r):(await Promise.all(n.map(async i=>{if(i.startsWith(".")||i==="node_modules")return;let a=e.join(t,i);if((await e.stat(a)).isDirectory()){let u=await at(e,a,r);if(u)return u}}))).find(i=>typeof i=="string")}async function Oe(e){let t=[],r=await bt(e,e.getRepoRootDir());if(r){let n=Gt(r);t.push(...n)}return t}function Gt(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of si)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var si=["@shopify/remix-oxygen","@shopify/hydrogen","@builder.io/qwik-city","@remix-run/react","@sveltejs/kit","astro","gatsby","next","nuxt","@builder.io/qwik","@angular/core","react","solid-js","svelte","vue"];async function fe(e){let t=Jn(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function de(e,t){t=typeof t=="object"&&t!=null?t:{};let r=Jn(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function Jn(e){let t=e.getAppRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function ke(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getAppRootDir(),o),a=await ui(e,i);if(a){let s=a[r];if(typeof s=="string"&&s.length>0&&s!=="YOUR_API_KEY")return n.envValue=s,n.file=i,n}}return n.file=e.join(e.getAppRootDir(),t[t.length-1]),n}async function ui(e,t){let r=await e.readFile(t);return typeof r=="string"?Ht(r):null}function Ht(e){let t={},r=e.replace(/\r\n?/gm,` `),n;for(;(n=pi.exec(r))!=null;){let o=n[1],i=n[2]||"";i=i.trim();let a=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/gm,"$2"),a==='"'&&(i=i.replace(/\\n/g,` `),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var pi=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function Le(e,t,r,n){let o="# https://www.builder.io/c/docs/using-your-api-key",i=await e.readFile(t);if(i)if(i.includes(r))if(i.includes(n))e.debug(`"${r}" with "${n}" already set in ${t}`);else return e.debug(`Replace "${r}" in ${t}`),i=i.replace(new RegExp(`${r}=.*`),`${r}=${n}`),await e.writeFile(t,i),"update";else return e.debug(`Append "${r}" to ${t}`),i+=` ${o} ${r}=${n} `,await e.writeFile(t,i),"update";else return e.debug(`Creating new .env file with "${r}" at ${t}`),i=[o,`${r}=${n}`,""].join(` `),await e.writeFile(t,i),"create";return null}async function st(e){return await ke(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],ge)}async function Qn(e,t){let r=await st(e),n=await Le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ge="NEXT_PUBLIC_BUILDER_API_KEY";var w={gen1:"Gen 1",gen2:"Gen 2"};function I(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest,void 0)}function vt(e,t=""){let r=I(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function _(e,t,r){if(t){let n=e.ts.createPrinter({newLine:e.ts.NewLineKind.LineFeed,removeComments:r});return e.ts.isSourceFile(t)?n.printFile(t).trim()+` `:n.printNode(e.ts.EmitHint.Unspecified,t,e.ts.createSourceFile("module.tsx","",e.ts.ScriptTarget.Latest)).trim()+` `}return""}function B(e,t,r){t=pe(t),r=pe(r),t=e.dirname(t);let n=e.basename(r,e.extname(r));r=e.dirname(r);let o;return n==="index"?o=e.relative(t,r):o=e.relative(t,e.join(r,n)),o=pe(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function pe(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Ue(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return Wn(o==="index"?e.basename(e.dirname(t)):o)}function Wn(e){return K(e).replace(/ /g,"")}function ie(e,t){let r=e.extname(t),n=pe(e.basename(t,r)).split("/").pop();return K(n==="index"?e.basename(e.dirname(t)):n)}function $(e,t){let r=pe(e.relative(e.getAppRootDir(),t));r=r.split("/").filter(o=>o!=="."&&o!==".."&&o!=="").join("/"),r.endsWith(".tsx")||r.endsWith(".jsx")?r=r.slice(0,-4):(r.endsWith(".ts")||r.endsWith(".js"))&&(r=r.slice(0,-3));let n=e.getFrameworks();return r.startsWith("src/")&&(r=r.slice(4)),n.some(o=>o.name.includes("next"))?"@/"+r:"~/"+r}function k(e,t){let r=t,n=[];for(let o=0;o<2;o++){let i=e.basename(r);if(!i||i==="components")break;n.unshift(i),r=e.dirname(r)}return n.join("/")}function K(e){for(e=e.replace(/([A-Z])/g," $1").replace(/\./g," ").replace(/_/g," ").replace(/-/g," ").replace(/\s/g," ").trim();e.includes(" ");)e=e.replace(/ /g," ");return e.split(" ").map(t=>t.length>2?t[0].toUpperCase()+t.slice(1):t).join("").trim()}function te(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function V(e,t,r,n){if(typeof r!="string"||r==="")throw new Error(`getComponentId(), exportName must be a non-empty string, received: ${r}, ${t}`);return n&&(t=n),t=e.normalize(t),(await e.hash(t+"#"+r)).substring(0,8)}function ut(e){return typeof e=="number"}function Ge(e){return typeof e=="boolean"}function Z(e){return typeof e=="string"}function He(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function re(e){return JSON.parse(JSON.stringify(e))}function It(e,t,r){for(let n of t)if(e.dirname(r).includes(n))return!0;return!1}function lt(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=li(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,u)=>u!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,pt(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,pt(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function li(e,t,r){return t.properties.findIndex(n=>N(e,n)===r)}function ct(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return mi(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return ci(e,t);case e.ts.SyntaxKind.StringLiteral:return t.text;case e.ts.SyntaxKind.NumericLiteral:return Number(t.text);case e.ts.SyntaxKind.NoSubstitutionTemplateLiteral:return t.text;case e.ts.SyntaxKind.TrueKeyword:return!0;case e.ts.SyntaxKind.FalseKeyword:return!1;case e.ts.SyntaxKind.Identifier:switch(t.escapedText){case"undefined":return;case"null":return null;case"String":return String;case"Number":return Number;case"Boolean":return Boolean;case"NaN":return NaN}}}function ci(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=N(e,n);o&&(r[o]=ct(e,n.initializer))}}return r}function mi(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>ct(e,r)):[]}function N(e,t){if(t&&e.ts.isPropertyAssignment(t)){let r=t.name;switch(r.kind){case e.ts.SyntaxKind.Identifier:return r.text;case e.ts.SyntaxKind.StringLiteral:case e.ts.SyntaxKind.NumericLiteral:return r.text;case e.ts.SyntaxKind.ComputedPropertyName:let n=r.expression;if(e.ts.isStringLiteral(n)||e.ts.isNumericLiteral(n))return r.expression.text}}}function pt(e,t){return Xt(e,t,new WeakSet)}function Xt(e,t,r){return t===void 0?e.ts.factory.createIdentifier("undefined"):t===null?e.ts.factory.createIdentifier("null"):typeof t=="string"?e.ts.factory.createStringLiteral(t):typeof t=="number"?isNaN(t)?e.ts.factory.createIdentifier("NaN"):e.ts.factory.createNumericLiteral(t):t===!0?e.ts.factory.createTrue():t===!1?e.ts.factory.createFalse():t===String?e.ts.factory.createIdentifier("String"):t===Number?e.ts.factory.createIdentifier("Number"):t===Boolean?e.ts.factory.createIdentifier("Boolean"):Array.isArray(t)?fi(e,t,r):typeof t=="object"?di(e,t,r):e.ts.factory.createIdentifier(t)}function fi(e,t,r){let n=t.map(o=>Xt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function di(e,t,r){if(r.has(t))return e.ts.factory.createIdentifier("undefined");r.add(t);let n=Object.keys(t).map(o=>e.ts.factory.createPropertyAssignment(o,Xt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function ze(e,t,r){let n=[];if(!r)return n;let o=null;if(e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r)){let i=r.parameters;if(i.length>0){let a=i[0],s=t.getTypeAtLocation(a);s.aliasTypeArguments&&s.aliasTypeArguments.length>0?o=s.aliasTypeArguments[0].getProperties():o=s.getProperties()}}else if(e.ts.isIdentifier(r)){let i=t.getTypeAtLocation(r),a=i.symbol?.valueDeclaration;if(a&&e.ts.isClassDeclaration(a)){let u=a.heritageClauses?.find(p=>p.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(u){for(let p of u)if(t.getSymbolAtLocation(p.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(p)){let m=p.typeArguments;if(m){let c=m[0];o=t.getTypeFromTypeNode(c).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let u=s[0].getParameters();u.length>0&&(o=t.getTypeOfSymbolAtLocation(u[0],r).getProperties())}}}else if(e.ts.isExportSpecifier(r)){let i=t.getSymbolAtLocation(r.name);if(i){let s=t.getTypeOfSymbolAtLocation(i,r).getCallSignatures();if(s.length>0){let u=s[0].getParameters();u.length>0&&(o=t.getTypeOfSymbolAtLocation(u[0],r).getProperties())}}}if(o)for(let i of o){let a=gi(e,t,i);a&&n.push(a)}return n=n.filter(Gn),n.length>0?n:Di(e,r)}function gi(e,t,r){let n=r.valueDeclaration,o=r.getName();if(n||(n=r.getDeclarations()?.[0]),n&&e.ts.isPropertySignature(n)){if(o!=="children"&&n.getSourceFile().fileName.includes("node_modules/@types/"))return null;let i="string",a;if(n?.type){let u=t.getTypeFromTypeNode(n.type),p=t.typeToString(u),d=Zt(p);d.knownType?i=d.builderType:xi(p)||u.flags&e.ts.TypeFlags.StringLike?i="string":u.flags&e.ts.TypeFlags.NumberLike?i="number":u.flags&e.ts.TypeFlags.IndexedAccess?i="list":u.flags&e.ts.TypeFlags.Object||u.isUnion()&&u.types.every(m=>m.flags&e.ts.TypeFlags.Object)||u.isIntersection()&&u.types.some(m=>m.flags&e.ts.TypeFlags.Object)?i="object":i="string",p!==i&&(a=p)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let u=Ai(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},u&&u.length>0&&s.type==="string"&&u.every(Ei)?s.enum=u.map(Si):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function Di(e,t){let r=[],n=e.ts.getJSDocCommentsAndTags(t);for(let o of n)if(!(!e.ts.isJSDoc(o)||!o.tags))for(let i of o.tags){if(!e.ts.isJSDocParameterTag(i)||i.tagName.text!=="param")continue;let s=i.typeExpression?.type;if(!s||!e.ts.isJSDocTypeLiteral(s))continue;let u=s.jsDocPropertyTags;if(u)for(let p of u){if(!e.ts.isJSDocPropertyLikeTag(p))continue;let d=p.name;if(!e.ts.isQualifiedName(d))continue;let m=p.typeExpression;if(!m)continue;let c="";switch(m.type.kind){case e.ts.SyntaxKind.StringKeyword:{c="string";break}case e.ts.SyntaxKind.NumberKeyword:{c="number";break}case e.ts.SyntaxKind.BooleanKeyword:{c="boolean";break}default:continue}let C={name:d.right.text,type:c,isRegistered:!1};r.push(C)}}return r.filter(Gn)}var Ci=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function xi(e){return typeof e!="string"?!1:!!Ci.some(t=>e.includes(t))}function Zt(e){return typeof e=="string"&&(e=e.trim(),hi.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var hi=[{value:"boolean",text:"boolean"},{value:"color",text:"color (provides a color in hex or rgb)"},{value:"date",text:"date (same format as the Date constructor)"},{value:"email",text:"email"},{value:"file",text:"file (uploads a file and provides a url)"},{value:"list",text:"list (collection of items)"},{value:"longText",text:"longText (multiline text editor)"},{value:"number",text:"number"},{value:"object",text:"object (set of specific names and values)"},{value:"richText",text:"richText (provides value as html)"},{value:"string",text:"string"}];function Ei(e){return/^['"].*['"]$/.test(e)}function Si(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Ai=(e,t,r)=>{let n=new Set;Yn(e,t,r,n);let o=n.delete("true"),i=n.delete("false");(o||i)&&n.add("boolean");let a=Array.from(n.keys()).sort();if(a.length>1&&(a=a.map(s=>s.indexOf("=>")>=0?`(${s})`:s)),!(a.length>20))return a},Fi=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Yn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Yn(e,t,o,n)});else if(r.isLiteral()){let o=Fi(e,t,r);n.add(o)}};function Gn(e){let t=e?.name;if(typeof t!="string"||t===""||t.startsWith("aria")||t.startsWith("data-"))return!1;if(t.startsWith("on")&&t.length>2){let r=t.charAt(2);if(r.toUpperCase()===r)return!1}return!Pi.has(t.toLowerCase())}var Pi=new Set(["about","accessKey","accessKeyLabel","asChild","autoCapitalize","autoCorrect","autoFocus","autoSave","blur","contentEditable","contextMenu","dangerouslySetInnerHTML","datatype","defaultChecked","defaultValue","dir","draggable","enterKeyHint","focus","form","formAction","formEncType","formMethod","formNoValidate","formTarget","inlist","innerText","inputMode","is","isContentEditable","itemID","itemProp","itemRef","itemScope","itemType","lang","nonce","offsetHeight","offsetLeft","offsetTop","offsetWidth","outerText","prefix","property","radioGroup","rel","resource","results","rev","role","security","slot","spellCheck","suppressContentEditableWarning","suppressHydrationWarning","tabIndex","translate","typeof","unselectable","vocab"].map(e=>e.toLowerCase()));function ne(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=N(e,n);if(o==="name"&&e.ts.isStringLiteral(n.initializer)){t.name=n.initializer.text;continue}if(o==="description"&&e.ts.isStringLiteral(n.initializer)){t.description=n.initializer.text;continue}if(o==="image"&&e.ts.isStringLiteral(n.initializer)){t.image=n.initializer.text;continue}if(o==="inputs"&&e.ts.isArrayLiteralExpression(n.initializer)){let i=yi(e,n.initializer);oe(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=ct(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function yi(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(wi(e,n));return r}function wi(e,t){let r=ct(e,t),n=Bi(r);return n.isRegistered=!0,n}function Q(e,t,r){let n=bi(r);return t=lt(e,t,"name",n.name,!1),t=lt(e,t,"description",n.description),t=lt(e,t,"image",n.image),t=Ti(e,t,n),Oi(e,t)}function Ti(e,t,r){let n=null,o=t.properties.filter(s=>e.ts.isPropertyAssignment(s)&&e.ts.isIdentifier(s.name)),i=o.findIndex(s=>e.ts.isIdentifier(s.name)&&s.name.text==="inputs"),a=[...r.inputs??[]];if(i>-1){if(a.length===0)return lt(e,t,"inputs",null);let s=o[i];e.ts.isPropertyAssignment(s)&&e.ts.isArrayLiteralExpression(s.initializer)&&(n=s.initializer)}return a.length===0?t:(n=Ii(e,n||e.ts.factory.createArrayLiteralExpression(),a),i>-1?o[i]=e.ts.factory.updatePropertyAssignment(o[i],o[i].name,n):o.push(e.ts.factory.createPropertyAssignment("inputs",n)),e.ts.factory.updateObjectLiteralExpression(t,o))}function bi(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(vi)}}function vi(e){let t={name:e.name,type:e.type};return(Z(e.defaultValue)||ut(e.defaultValue)||Ge(e.defaultValue))&&(t.defaultValue=e.defaultValue),Z(e.friendlyName)&&(t.friendlyName=e.friendlyName),Z(e.helperText)&&(t.helperText=e.helperText),e.required===!0&&(t.required=!0),Array.isArray(e.enum)&&(t.enum=e.enum),e.hideFromUI===!0&&(t.hideFromUI=!0),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(t.meta=e.meta),t}function Ii(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>N(e,s)==="name");if(!i)return!1;let a=i.initializer;return e.ts.isStringLiteral(a)?r.some(s=>s.name===a.text):!1});for(let o of r)n=Ri(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>N(e,c)==="name"),s=i.properties.find(c=>N(e,c)==="name"),u=a?.initializer,p=s?.initializer,d=u&&e.ts.isStringLiteral(u)?u.text:"zz",m=p&&e.ts.isStringLiteral(p)?p.text:"zz";return d.toLowerCase().localeCompare(m.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Ri(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=N(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=Hn(e,t[n],r);else{let o=Hn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Hn(e,t,r){let n=t.properties.filter(i=>e.ts.isPropertyAssignment(i)),o=Object.keys(r).filter(i=>i!=="isRegistered");for(let i of o)n=Ni(e,n,r,i);return n=ki(e,n.filter(i=>{let a=N(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Ni(e,t,r,n){let o=t.findIndex(i=>e.ts.isIdentifier(i.name)&&i.name.text===n);return o>-1?t[o]=e.ts.factory.updatePropertyAssignment(t[o],t[o].name,pt(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,pt(e,r[n]))),t}function oe(e,t){for(let r of t){let n=e.inputs.findIndex(o=>o.name===r.name);n>-1?(r.isRegistered||!e.inputs[n].isRegistered)&&(e.inputs[n]=r):e.inputs.push(r)}e.acceptsChildren=en(e)}function Bi(e){let t=Zt(e.type),r={name:e.name.trim(),type:t.builderType};return Z(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(Z(e.defaultValue)||ut(e.defaultValue)||Ge(e.defaultValue))&&(r.defaultValue=e.defaultValue),Z(e.helperText)&&(r.helperText=e.helperText),Ge(e.required)&&(r.required=e.required),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(r.meta=e.meta),Array.isArray(e.enum)&&e.enum.length>0&&(r.enum=e.enum),e.hideFromUI===!0&&(r.hideFromUI=!0),tn(r)}function en(e){let t=e.inputs.some(n=>n.name==="children"),r=e.inputs.some(n=>n.meta?.ts==="ReactNode");return!!(t||r||e.acceptsChildren===!0)}function tn(e){if(e.name==="children"&&(e.hideFromUI=!0,delete e.required),e.type==="object"&&e.defaultValue==null&&(e.hideFromUI=!0),e.type==="list"&&e.defaultValue==null&&(e.hideFromUI=!0),e.meta){let t=e.meta.ts;typeof t=="string"&&(t=t.trim(),t.endsWith("ReactNode")&&(t="ReactNode"),e.meta.ts=t,t==="ReactNode"&&(e.hideFromUI=!0))}return e}function Oi(e,t){let r=[...t.properties].sort((n,o)=>{let i=N(e,n)||"zz",a=N(e,o)||"zz";if(i==="inputs")return 1;let s=Xn.indexOf(i),u=Xn.indexOf(a);return s>-1?u>-1&&s>u?1:-1:u>-1?s>-1&&u{let i=N(e,n)||"zz",a=N(e,o)||"zz",s=Zn.indexOf(i),u=Zn.indexOf(a);return s>-1?u>-1&&s>u?1:-1:u>-1?s>-1&&u import(${JSON.stringify(o)}))), `:r+=` dynamic(() => import(${JSON.stringify(o)})), `:t.acceptsChildren?r+=` withChildren(dynamic(async () => (await import(${JSON.stringify(o)})).${t.exportName})), `:r+=` dynamic(async () => (await import(${JSON.stringify(o)})).${t.exportName}), `}r+=` { name: "${t.name}", } `,r+=");";let n=vt(e,r);return nn(e,n,t)}function nn(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;r.acceptsChildren?e.ts.isCallExpression(o[0])&&e.ts.isIdentifier(o[0].expression)&&o[0].expression.text==="withChildren"||(o[0]=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("withChildren"),void 0,[o[0]])):e.ts.isCallExpression(o[0])&&e.ts.isIdentifier(o[0].expression)&&o[0].expression.text==="withChildren"&&(o[0]=o[0].arguments[0]);let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=Q(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function G(e,t){if(!Array.isArray(t)||t.length===0)throw new Error(`createTsProgram() Invalid filePaths: ${t}`);let r=await qn(e,t[0]),n=e.join(r,"typescript","lib"),o=new Map,i={fileExists:a=>{if(a=e.normalize(a),a.includes("node_modules")){let s=mt.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}mt.set(a,s)}return s.exists}return o.has(a)||o.set(a,e.existsSync(a)),o.get(a)},getCanonicalFileName:a=>e.normalize(a),getCurrentDirectory:()=>e.cwd(),getDefaultLibFileName:()=>e.join(n,"lib.d.ts"),getDefaultLibLocation:()=>n,getNewLine:()=>` `,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let u=mt.get(a);if(u)return I(e,u.content)}let s=e.readFileSync(a);if(s==null){let u=e.basename(a),p=e.extname(u).toLowerCase();if(a.startsWith(n)&&p===".ts"&&(s=nr.get(u),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new Nt(u)}return a.includes("node_modules")&&(s?mt.set(a,{exists:!0,content:s}):mt.set(a,{exists:!1})),I(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return Li(e,i,t)}catch(a){if(a instanceof Nt){await _i(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Li(e,t,r){let n={rootNames:[...r],options:{},host:t},o=e.ts.findConfigFile(e.dirname(r[0]),i=>e.existsSync(i));if(o){let i=tr.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let u=e.readFileSync(s);return typeof u=="string"?u:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(u,p)=>e.readdirSync(u),fileExists:u=>e.existsSync(u),readFile:u=>e.readFileSync(u)||void 0},e.dirname(o),void 0,o).options,tr.set(o,i))}i&&(n.options=re(i))}return n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function Ze(e,t,r){r||(r=await G(e,[t]));let n=r.getSourceFile(t);if(!n)throw new Error(`getTypeChecker() Could not find source file: ${t}`);return{typeChecker:r.getTypeChecker(),sourceFile:n}}var Nt=class{constructor(t){this.libName=t}};async function _i(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;Rt.has(t)||Rt.set(t,fetch(r).then(n=>n.text()).then(n=>{nr.set(t,n)})),await Rt.get(t),Rt.delete(t)}var nr=new Map,Rt=new Map,mt=new Map,tr=new Map;function v(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=ji(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=$i(e,t,r.defaultImport,r.importPath,n)),t}function ji(e,t,r,n,o,i){return i==="cjs"?or(e,t,null,r,n):rr(e,t,null,r,n,o)}function $i(e,t,r,n,o){return o==="cjs"?or(e,t,r,null,n):rr(e,t,r,null,n,!1)}function rr(e,t,r,n,o,i){let a=[...t.statements],s=0,u=!1,p=!1;for(let f=0;fx.name.text===n))return t;l.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),l.sort((x,S)=>x.name.text.localeCompare(S.name.text)),u=!0}let g=C.importClause?C.importClause.name:void 0;if(typeof r=="string"){if(g&&g.text===r)return t;g=e.ts.factory.createIdentifier(r),p=!0}if(u||p)return a[f]=e.ts.factory.updateImportDeclaration(C,void 0,e.ts.factory.createImportClause(i,g,e.ts.factory.createNamedImports(l)),C.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,m;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(m=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let c=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,m),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function or(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s!e.ts.isBindingElement(g)||!e.ts.isIdentifier(g.name)?!1:g.name.text===n)?t:(l.push(e.ts.factory.createBindingElement(void 0,void 0,n)),l.sort((g,x)=>!e.ts.isBindingElement(g)||!e.ts.isIdentifier(g.name)||!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?0:g.name.text.localeCompare(x.name.text)),d[p]=e.ts.factory.updateVariableDeclaration(m,e.ts.factory.createObjectBindingPattern(l),m.exclamationToken,m.type,m.initializer),i[s]=e.ts.factory.updateVariableStatement(u,u.modifiers,e.ts.factory.updateVariableDeclarationList(u.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function ae(e,t,r="esm"){return r==="cjs"?Ki(e,t):Vi(e,t)}function Vi(e,t){let r=[];for(let n of t.statements){if(e.ts.isExportDeclaration(n)){if(n.exportClause&&e.ts.isNamedExports(n.exportClause)){for(let o of n.exportClause.elements)if(n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:o}),e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}else!n.exportClause&&n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:n});continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let u of s.declarationList.declarations)e.ts.isIdentifier(u.name)&&u.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function Ki(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let u of s.declarationList.declarations)e.ts.isIdentifier(u.name)&&u.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s});else e.ts.isFunctionDeclaration(s)&&s.name&&s.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s})}else r.push({isDefaultExport:!0,statement:n,node:i});continue}}return r}function Mi(e,t,r){for(let n of t.statements)if(e.ts.isImportDeclaration(n)&&n.importClause){if(n.importClause.namedBindings&&e.ts.isNamedImports(n.importClause.namedBindings)){for(let o of n.importClause.namedBindings.elements)if(e.ts.isIdentifier(o.name)&&o.name.text===r&&e.ts.isStringLiteral(n.moduleSpecifier))return{importPath:n.moduleSpecifier.text,exportType:"named"}}if(n.importClause.name&&n.importClause.name.text===r&&e.ts.isStringLiteral(n.moduleSpecifier))return{importPath:n.moduleSpecifier.text,exportType:"default"}}return null}async function De(e,t,r,n){let o=Mi(e,r,n);if(o){let i=await ft(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getAppRootDir(),i);return{displayFilePath:k(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function et(e,t,r){for(let n=0;n0){let o=n.statement.declarationList.declarations[0];if(o.initializer&&e.ts.isArrayLiteralExpression(o.initializer))return{statement:n.statement,statementIndex:n.statementIndex,variableDeclaration:o,arrayLiteralExp:o.initializer}}return null}function Bt(e,t){if(t){if(Ui(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Bt(e,n)&&(r=!0)}),r)return!0}return!1}function Ui(e,t){return e.ts.isJsxElement(t)||e.ts.isJsxOpeningElement(t)||e.ts.isJsxOpeningFragment(t)||e.ts.isJsxSelfClosingElement(t)||e.ts.isJsxFragment(t)||e.ts.isJsxChild(t)}async function ft(e,t){let r=e.extname(t).toLowerCase();if(r===""||!rn.includes(r)){for(let n of rn){let o=t+n;if(await e.exists(o))return o}for(let n of rn){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var rn=[".tsx",".jsx",".ts",".js"];function dt(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=zi(e,i);return a?[{name:a}]:void 0}function zi(e,t){if(typeof t=="string"){t=e.normalize(pe(t));let r=t.split("/"),n=r.lastIndexOf("node_modules");if(n>-1){let o=r.slice(n+1),i=o[0];if(i)return i.startsWith("@")&&o[1]&&(i+="/"+o[1]),i}}}function Ce(e){let t=[];for(let r of e)if(r.dependencies)for(let n of r.dependencies)t.some(o=>o.name===n.name)||t.push({...n});return t.sort((r,n)=>r.name.localeCompare(n.name))}async function tt(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await G(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{let s=n.getSourceFile(a.filePath);if(s){let p=(await je(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);p&&(a.inputs=ze(e,o,p.node.fnNode))}return a}))}async function nt(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Ze(e,t.cmpInfo.filePath,r),a=(await je(e,o,t.cmpInfo.filePath,n)).find(s=>s.cmpInfo.id===t.cmpInfo.id);if(!a)throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return ze(e,o,a.node.fnNode)}return[]}async function ar(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return qi(e,t,n)}return null}function qi(e,t,r){let n=I(e,r);return je(e,null,t,n)}async function je(e,t,r,n){let o=[];for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isStringLiteral(a.expression)&&a.expression.text==="use server")return o;let i=ae(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await Ji(e,t,r,a);o.push(...s)})),o}async function Ji(e,t,r,n){let o=[],i=e.relative(e.getAppRootDir(),r),a=$(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!He(s.name.text))continue;let u=_e(e,t,s.initializer);if(u){let p=u.name||s.name.text,d=n.isDefaultExport?"default":p,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await V(e,r,d),displayFilePath:k(e,r),name:K(p),inputs:[],exportName:d,exportType:m,importName:p,filePath:r,relFilePath:i,importPath:a,dependencies:u.deps},node:u})}}return o}if(e.ts.isArrowFunction(n.node)){let s=_e(e,t,n.node);if(s){let u=ie(e,r),p=n.isDefaultExport?"default":u,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await V(e,r,p),displayFilePath:k(e,r),name:u,inputs:[],exportName:p,exportType:d,importName:Ue(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let s=n.node.name?.text;if(s&&!He(s))return o;let u=_e(e,t,n.node);if(u){let p=u.name||ie(e,r),d=n.isDefaultExport||!u.name?"default":u.name,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await V(e,r,d),displayFilePath:k(e,r),name:p,inputs:[],exportName:d,exportType:m,importName:u.name||Ue(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:u.deps},node:u})}return o}if(e.ts.isExportSpecifier(n.node)&&He(n.node.getText())){let s,u=_e(e,t,n.node);if(u){let p=u.name||ie(e,r),d=n.isDefaultExport||!u.name?"default":u.name,m=n.isDefaultExport?"default":"named",f=n.node.parent.parent.moduleSpecifier;if(f&&e.ts.isStringLiteral(f)){let C=t?.getSymbolAtLocation(f);if(C&&C.declarations&&C.declarations.length>0){let l=C.declarations[0];(!e.ts.isSourceFile(l)||e.ts.isSourceFile(l)&&l.fileName.includes("node_modules"))&&(s=f.text)}}o.push({cmpInfo:{id:await V(e,r,d,s),displayFilePath:k(e,r),name:p,inputs:[],exportName:d,exportType:m,importName:u.name||Ue(e,r),filePath:r,relFilePath:i,importPath:s||a,externalImportPath:s,dependencies:u.deps},node:u})}return o}if(e.ts.isExportDeclaration(n.node)&&n.node.exportClause===void 0){let s=n.node.moduleSpecifier;if(s&&e.ts.isStringLiteral(s)){let u=await Wi(e,t,r,s);o.push(...u)}return o}return o}function _e(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Bt(e,r.body)?{name:"",fnNode:r,deps:dt(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Bt(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:dt(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:_e(e,t,o[0])}if(!t)return null;if(e.ts.isPropertyAccessExpression(r)){let n=r.expression,o=r.name;if(!e.ts.isIdentifier(n)||!e.ts.isIdentifier(o)||!He(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:dt(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:dt(e,t,n)}}if(e.ts.isExpressionStatement(r)){let n=r.expression;if(e.ts.isAsExpression(n)&&e.ts.isIdentifier(n.type)&&n.type.text==="default")return _e(e,t,n.expression)}if(e.ts.isVariableStatement(r)){for(let n of r.declarationList.declarations)if(n.initializer&&e.ts.isAsExpression(n.initializer)){let o=n.initializer;if(e.ts.isIdentifier(o.type)&&o.type.text==="default"){let i=_e(e,t,o.expression);if(i&&e.ts.isIdentifier(n.name))return{name:n.name.text,fnNode:i.fnNode,deps:i.deps}}}}return null}async function sr(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.normalize(i.fileName);if(It(e,Qi,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await je(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Qi=new Set(["node_modules","dist"]);async function Wi(e,t,r,n){let o=[],i=n.text;if(!t)return o;try{let a=t.getSymbolAtLocation(n);if(!a)return o;let s=t.getExportsOfModule(a);for(let u of s){let p=u.valueDeclaration||u.declarations?.[0];if(!p)continue;let d=u.name;if(!He(d)&&d!=="default"||!ur(e,t,p))continue;let m=_e(e,t,p);if(m){let c=u.name,f=c==="default"?"default":"named",C=K(c),l=c==="default"?Ue(e,r):c;o.push({cmpInfo:{id:await V(e,r,c,i),displayFilePath:k(e,r),name:C,inputs:[],exportName:c,exportType:f,importName:l,filePath:r,relFilePath:e.relative(e.getAppRootDir(),r),importPath:i,externalImportPath:i,dependencies:m.deps},node:m})}}}catch(a){console.error(`Error processing module ${i}:`,a)}return o}function ur(e,t,r){if(e.ts.isInterfaceDeclaration(r)||e.ts.isTypeAliasDeclaration(r))return!1;if(e.ts.isExportSpecifier(r)){let n=t.getSymbolAtLocation(r.name);if(n){let i=t.getAliasedSymbol(n).declarations?.[0];if(i)return ur(e,t,i)}return!1}if(e.ts.isFunctionDeclaration(r)||e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r)){let n=t.getSignatureFromDeclaration(r);if(n){let o=t.getReturnTypeOfSignature(n);return ir(o,t)}}return e.ts.isClassDeclaration(r)?r.heritageClauses?.some(o=>o.types.some(i=>i.expression.getText()==="React.Component"||i.expression.getText()==="Component"))??!1:e.ts.isVariableDeclaration(r)?t.getTypeAtLocation(r).getCallSignatures().some(i=>ir(t.getReturnTypeOfSignature(i),t)):!1}function ir(e,t){let r=t.typeToString(e);return r==="JSX.Element"||r==="Element"||r.includes("ReactElement")||r.includes("React.ReactElement")||r.includes("ReactNode")}async function pr(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(e.appDir&&Yi.has(a)||e.dirname(i.fileName).includes("node_modules"))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let u=await je(e,o,s,i);r.push(...u)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Yi=new Set(["default.tsx","default.ts","default.jsx","default.js","error.tsx","error.ts","error.jsx","error.js","layout.tsx","layout.ts","layout.jsx","layout.js","loading.tsx","loading.ts","loading.jsx","loading.js","not-found.tsx","not-found.ts","not-found.jsx","not-found.js","page.tsx","page.ts","page.jsx","page.js","route.tsx","route.ts","route.jsx","route.js","template.tsx","template.ts","template.jsx","template.js"]);function xe(e,t){let r=[],n=[],o=[],i=[];for(let a of t.statements){if(e.ts.isImportDeclaration(a)){if(e.ts.isStringLiteral(a.moduleSpecifier)){let u=a.moduleSpecifier.text;if(!u.startsWith(".")&&!u.startsWith("/")){r.push(a);continue}}let s=a.importClause;if(s){if(s.namedBindings){n.push(a);continue}if(s.name){n.push(a);continue}}o.push(a);continue}i.push(a)}return e.ts.factory.updateSourceFile(t,[...on(e,r),...on(e,n),...on(e,o),...i])}function se(e){let t=e.split(` `).map(n=>n.trimEnd());e="";let r=!1;for(let n=t.length-1;n>=0;n--){let o=t[n];!r&&o.startsWith("import ")&&(r=!0,o=o+` `),/^builder.init(.*)$/.test(o)&&(o=o+` `),t[n-1]&&!t[n-1].includes("*/")&&(o.trim().startsWith("Builder.registerComponent")&&(o=` `+o),o.trim().startsWith("/**")&&(o=` `+o),o.trim().startsWith("module.exports")&&(o=` `+o),o.trim().startsWith("export ")&&(o=` `+o)),e=o+` `+e}return e.trim()+` `}function on(e,t){return t.sort((r,n)=>{let o=lr(e,r),i=lr(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function lr(e,t){let r=t.importClause;if(r){let n=r.namedBindings;if(n&&e.ts.isNamedImports(n)&&n.elements.length>0)return n.elements[0].name.text;if(r.name)return r.name.text}return t.moduleSpecifier&&e.ts.isStringLiteral(t.moduleSpecifier)?t.moduleSpecifier.text:""}function mr(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client" ${e}`),e}function fr(e,t){let r=t.statements.filter(n=>!(e.ts.isExpressionStatement(n)&&e.ts.isStringLiteral(n.expression)&&e.ts.isStringLiteral(n.expression)&&n.expression.text==="use client"));return e.ts.factory.updateSourceFile(t,r)}function he(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=cr(e,r),i=cr(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function cr(e,t){let r=t.properties.find(n=>N(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function dr(e){let t=await e.readFile(e.registryPath);return t?Gi(e,t):{components:[],sourceFile:I(e,"")}}async function Gi(e,t){let r=I(e,t);return e.sdkVersion===w.gen2?Xi(e,r):Hi(e,r)}async function Hi(e,t){let r=[];for(let n=0;ne.ts.isImportDeclaration(p)),u=s.find(p=>p.importClause&&p.importClause.name?.text===n.text);if(u){let p=u.moduleSpecifier;if(!e.ts.isStringLiteral(p))return null;let d=await rt(e,p.text);a.filePath=d,a.relFilePath=e.relative(e.getAppRootDir(),a.filePath),await e.exists(d)?a.importPath=$(e,a.filePath):(a.externalImportPath=p.text,a.importPath=a.externalImportPath),a.name=ie(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let p=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(f=>f.name.text===n.text));if(!p)return null;let d=p.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let m=await rt(e,d.text);a.filePath=m,a.relFilePath=e.relative(e.getAppRootDir(),a.filePath),await e.exists(m)?a.importPath=$(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=K(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=ne(e,a,o),a.displayFilePath=k(e,a.filePath),a.filePath&&a.exportName&&(a.id=await V(e,a.filePath,a.exportName,a.externalImportPath)),a}function rt(e,t){return ft(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function gr(e,t,r){let n=!1,o=0,i=[...t.statements];for(let p=0;p{let a=await pn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function pn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};Xe(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(N(e,i)==="component"){let s,{initializer:u}=i;if(e.ts.isCallExpression(u)&&(e.ts.isIdentifier(u.expression)&&u.expression.text)==="dynamic"){let f=u.arguments;if(f.length===0)return null;let C=f[0];if(!e.ts.isArrowFunction(C))return null;let l=C.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let g=l.arguments[0];if(!e.ts.isStringLiteral(g))return null;let x=g.text,S=await rt(e,x);n.filePath=S,n.relFilePath=e.relative(e.getAppRootDir(),n.filePath),await e.exists(S)?n.importPath=$(e,n.filePath):(n.externalImportPath=x,n.importPath=n.externalImportPath),n.name=ie(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let D=l.expression;if(!e.ts.isParenthesizedExpression(D))return null;let g=D.expression;if(!e.ts.isAwaitExpression(g))return null;let x=g.expression;if(!e.ts.isCallExpression(x)||x.expression.kind!==e.ts.SyntaxKind.ImportKeyword||x.arguments.length!==1)return null;let P=x.arguments[0];if(!e.ts.isStringLiteral(P)||!e.ts.isIdentifier(l.name))return null;let A=P.text,E=await rt(e,A);n.filePath=E,n.relFilePath=e.relative(e.getAppRootDir(),n.filePath),await e.exists(E)?n.importPath=$(e,n.filePath):(n.externalImportPath=A,n.importPath=n.externalImportPath),n.name=K(l.name.text),n.importName=l.name.text,n.exportName=l.name.text,n.exportType="named"}else return null;return n=ne(e,n,r),n.displayFilePath=k(e,n.filePath),n.filePath&&n.exportName&&(n.id=await V(e,n.filePath,n.exportName,n.externalImportPath)),n}if(e.ts.isIdentifier(u)&&(s=u.text),!s)continue;n.name===""&&(n.name=K(s)),n.importName=s;let p=await De(e,e.registryPath,t,s);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,await e.exists(p.filePath)?n.importPath=$(e,p.filePath):(n.externalImportPath=p.importPath,n.importPath=n.externalImportPath),n.importPath=$(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),m=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(m){let c=m.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(C=>!C.importClause||!C.importClause.namedBindings||!e.ts.isNamedImports(C.importClause.namedBindings)?!1:C.importClause.namedBindings.elements.some(l=>l.name.text===s));if(!c)return null;let f=c.moduleSpecifier;if(!e.ts.isStringLiteral(f))return null;n.exportName=s}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await V(e,n.filePath,n.exportName,n.externalImportPath)),n}function Ee(e,t){let r=[...t.statements],n=!1;for(let o=t.statements.length-1;o>=0;o--){let i=t.statements[o];if(e.ts.isImportDeclaration(i)&&i.importClause){let a=!1,s=i.importClause.namedBindings;if(s&&e.ts.isNamedImports(s)&&s.elements){let u=[...s.elements];for(let p=u.length-1;p>=0;p--){let d=u[p];if(e.ts.isImportSpecifier(d)){let m=d.name;if(m&&e.ts.isIdentifier(m)){let c=m.text;Dr(e,t,c)||u.splice(p,1)}}}if(u.length===0)a=!0;else if(s.elements.length!==u.length){let p=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(u)),d=e.ts.factory.updateImportDeclaration(i,void 0,p,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let u=i.importClause.name.text;Dr(e,t,u)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Dr(e,t,r){let n=!1;function o(i){if(!e.ts.isImportDeclaration(i)){if(e.ts.isIdentifier(i)&&i.text===r){n=!0;return}e.ts.forEachChild(i,o)}}return e.ts.forEachChild(t,o),n}function Se(e,t,r,n,o,i,a){let s=null,u=null,p=null,d=-1;t=re(t),r=re(r);let m=t.find(f=>f.id===e),c=r.find(f=>f.id===e);if(n)c||(s={...re(m),inputs:re(m.inputs).map(f=>(f.isRegistered=!0,f))},d=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)d=c.nodeIndex,u=re(c),r=r.filter(f=>f.id!==e);else if(i!=null)Zi(c,i),d=c.nodeIndex,p=c;else if(a!=null){let f=c.inputs.find(C=>C.name===a.name);f&&(a.registerInput===!1?f.isRegistered=!1:(ea(f,a),f.isRegistered=!0),p=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:u,updateRegisteredCmp:p,nodeIndex:d,components:le(t,r)}}function le(e,t){let r=te([...t.map(n=>(n.isRegistered=!0,n)),...e.filter(n=>!t.some(o=>o.id===n.id)).map(n=>(n.isRegistered=!1,n))]);return r.forEach(n=>{n.inputs=n.inputs.map(tn),n.inputs.sort((a,s)=>a.name.toLowerCase().localeCompare(s.name.toLowerCase()));let o=t.find(a=>a.id===n.id);o&&(o.acceptsChildren=en(n));let i=e.find(a=>a.id===n.id&&a.externalImportPath);i&&(n.filePath=i.filePath,n.relFilePath=i.relFilePath)}),r}function Zi(e,t){Z(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),Z(t.description)?e.description=t.description:t.description===null&&delete e.description,Z(t.image)?e.image=t.image:t.image===null&&delete e.image}function ea(e,t){Z(t.type)&&(e.type=t.type),Z(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,Z(t.defaultValue)||ut(t.defaultValue)||Ge(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,Z(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function $e(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),u=e.extname(a).toLowerCase();if(u===".tsx"||u===".jsx"||u===".ts"||u===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getAppRootDir()),await G(e,[...t])}function Ae(e,t,r){return et(e,t,r.variableName)?t:ta(e,t,r)}function ta(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),u=e.ts.factory.createVariableStatement([s],a),p=[...t.statements,u];return e.ts.factory.updateSourceFile(t,p)}async function Fe(e,t,r,n,o,i,a,s){let u=await $e(e),[p,d,m,c]=await Promise.all([pr(e,u),dr(e),ln(e),st(e)]),f=p.map(S=>S.cmpInfo),C=d.components,l={components:le(f,C),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ce(f),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return l.components=await tt(e,l.components),l;let D=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let S=x.map(E=>{let O=p.find(z=>z.cmpInfo.id===E);if(!O)throw new Error(`Component ${E} not found`);return O}),P=Array.from(new Set(S.map(E=>E.cmpInfo.filePath))),A=await G(e,P);for(let E of S){let O=l.components.find(y=>y.id===E.cmpInfo.id),z=await nt(e,E,A);oe(O,z);let j=f.findIndex(y=>y.id===E.cmpInfo.id);f[j].inputs=z;let F=Se(E.cmpInfo.id,f,C,r,n,o,i);if(e.sdkVersion===w.gen2){let{elements:y,elmIndex:H,statementIndex:ue,statement:Y,variableDeclaration:L}=await oa(e,g,E);if(F.addCmpToRegistry)y.push(ra(e,F.addCmpToRegistry)),D=!0;else if(F.removeCmpFromRegistry)y.splice(H,1),D=!0;else if(F.updateRegisteredCmp){let X=Q(e,y[H],F.updateRegisteredCmp);y[H]=e.ts.factory.updateObjectLiteralExpression(X,[xr(e,F.updateRegisteredCmp),...X.properties.slice(1)]),D=!0}if(D&&a){let X=[...g.statements];X[ue]=e.ts.factory.updateVariableStatement(Y,Y.modifiers,e.ts.factory.updateVariableDeclarationList(Y.declarationList,[e.ts.factory.updateVariableDeclaration(L,L.name,L.exclamationToken,L.type,e.ts.factory.createArrayLiteralExpression(he(e,y)))])),g=e.ts.factory.updateSourceFile(g,X),g=Cr(e,F,g),g=v(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),g=Ae(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),l.components=F.components,C=F.components.filter(Me=>Me.isRegistered)}}else{let y=[...g.statements];F.addCmpToRegistry?(y.push(er(e,F.addCmpToRegistry)),D=!0):F.removeCmpFromRegistry?(y.splice(F.nodeIndex,1),D=!0):F.updateRegisteredCmp&&(y[F.nodeIndex]=nn(e,y[F.nodeIndex],F.updateRegisteredCmp),D=!0),D&&a&&(g=e.ts.factory.updateSourceFile(g,y),g=v(e,g,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),g=gr(e,g,m),g=Cr(e,F,g),O?.acceptsChildren&&(g=v(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),l.components=F.components,C=F.components.filter(H=>H.isRegistered))}}}if(D&&a){g=Ee(e,g),g=xe(e,g),e.appDir&&(g=fr(e,g));let S=_(e,g);S=se(S),e.appDir&&(S=mr(S)),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return l}function xr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",ia(e,t))}function na(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function ra(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([xr(e,t),...t.acceptsChildren?[na(e)]:[]],!0),t)}async function oa(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a; } // If the "content" is falsy and the page is // not being previewed in Builder, render the // DefaultErrorPage with a 404. return ; } `.trimStart():` "use client"; ${t?'import { ComponentProps } from "react";':""} import { BuilderComponent, useIsPreviewing } from "@builder.io/react"; import { ${t?"BuilderContent, ":""}builder } from '@builder.io/sdk'; import DefaultErrorPage from "next/error"; import ${JSON.stringify(B(e,e.builderComponentPath,e.registryPath))}; ${t?` type BuilderPageProps = ComponentProps;`:""} // Builder Public API Key set in .env file builder.init(process.env.${ge}${t?"!":""}); export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) { // Call the useIsPreviewing hook to determine if // the page is being previewed in Builder const isPreviewing = useIsPreviewing(); // If "content" has a value or the page is being previewed in Builder, // render the BuilderComponent with the specified content and model props. if (content || isPreviewing) { return ; } // If the "content" is falsy and the page is // not being previewed in Builder, render the // DefaultErrorPage with a 404. return ; } `.trimStart()}function Ar({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=B(e,t,e.builderComponentPath);return e.sdkVersion===w.gen2?` import { fetchOneEntry } from "@builder.io/sdk-react"; import { RenderBuilderContent } from ${JSON.stringify(o)}; // Builder Public API Key set in .env file const PUBLIC_API_KEY = process.env.${ge}${n?"!":""}; ${n?` interface PageProps { params: { page: string[]; }; }`:""} export default async function Page(props${n?": PageProps":""}) { const builderModelName = "${r}"; // Use the page path specified in the URL to fetch the content const urlPath = "/" + (props.params?.page?.join("/") || ""); const content = await fetchOneEntry({ // Get the page content from Builder with the specified options apiKey: PUBLIC_API_KEY, model: builderModelName, userAttributes: { urlPath }, }); return ( <> {/* Render the Builder page */} ); } `.trimStart():` import { builder } from "@builder.io/sdk"; import { RenderBuilderContent } from ${JSON.stringify(o)}; // Builder Public API Key set in .env file builder.init(process.env.${ge}${n?"!":""}); ${n?` interface PageProps { params: { page: string[]; }; }`:""} export default async function Page(props${n?": PageProps":""}) { const builderModelName = "${r}"; const content = await builder // Get the page content from Builder with the specified options .get(builderModelName, { userAttributes: { // Use the page path specified in the URL to fetch the content urlPath: "/" + (props?.params?.page?.join("/") || ""), }, }) // Convert the result to a promise .toPromise(); return ( <> {/* Render the Builder page */} ); } `.trimStart()}async function ua(e,t,r){let n=`[...page].${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,Fr({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function pa(e,t,r){let n=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,Fr({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function Fr({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return e.sdkVersion===w.gen2?` import React from "react"; import { useRouter } from "next/router"; ${n?'import type { BuilderContent } from "@builder.io/sdk-react";':""} import { Content, fetchEntries, fetchOneEntry, isPreviewing, } from "@builder.io/sdk-react"; import DefaultErrorPage from "next/error"; import Head from "next/head"; ${n?'import { GetStaticProps } from "next";':""} import { CUSTOM_COMPONENTS } from ${JSON.stringify(B(e,e.builderComponentPath,e.registryPath))}; const BUILDER_API_KEY = process.env.${ge}${n?"!":""}; // Define a function that fetches the Builder // content for a given page export const getStaticProps${n?": GetStaticProps":""} = async ({ params }) => { const urlPath = "/" + (Array.isArray(params?.page) ? params.page.join("/") : params?.page || ""); // Fetch the builder content for the given page const page = await fetchOneEntry({ apiKey: BUILDER_API_KEY, model: "${r}", userAttributes: { urlPath }, }); return { // Return the page content as props props: { page }, // Revalidate the content every 5 seconds revalidate: 5, }; }; ${r==="page"?` // Define a function that generates the // static paths for all pages in Builder export async function getStaticPaths() { // Get a list of all pages in Builder const pages = await fetchEntries({ apiKey: BUILDER_API_KEY, model: "page", // We only need the URL field fields: "data.url", options: { noTargeting: true }, }); // Generate the static paths for all pages in Builder return { paths: pages.map((page) => \`\${page.data?.url}\`), fallback: "blocking", }; } `:""} // Define the Page component export default function Page(props${n?": { page: BuilderContent | null }":""}) { const router = useRouter(); const canShowContent = props.page || isPreviewing(router.asPath); // If the page content is not available // and not in preview/editing mode, show a 404 error page if (!canShowContent) { return ; } // If the page content is available, render // the BuilderComponent with the page content return ( <> {props.page?.data?.title} {/* Render the Builder page */} ); } `:` import React from "react"; import { useRouter } from "next/router"; import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react"; import DefaultErrorPage from "next/error"; import Head from "next/head";${n?` import { BuilderContent } from "@builder.io/sdk";`:""}${n?` import { GetStaticProps } from "next";`:""} import ${JSON.stringify(B(e,t,e.registryPath))}; builder.init(process.env.${ge}${n?"!":""}); // Define a function that fetches the Builder // content for a given page export const getStaticProps${n?": GetStaticProps":""} = async ({ params }) => { // Fetch the builder content for the given page const page = await builder .get("${r}", { userAttributes: { urlPath: "/" + ((params?.page${n?" as string[]":""})?.join("/") || ""), }, }) .toPromise(); // Return the page content as props return { props: { page: page || null, }, // Revalidate the content every 5 seconds revalidate: 5, }; }; ${r==="page"?`// Define a function that generates the // static paths for all pages in Builder export async function getStaticPaths() { // Get a list of all pages in Builder const pages = await builder.getAll("page", { // We only need the URL field fields: "data.url", options: { noTargeting: true }, }); // Generate the static paths for all pages in Builder return { paths: pages.map((page) => String(page.data?.url)).filter(url => url !== '/'), fallback: 'blocking', }; }`:""} // Define the Page component export default function Page({ page }${n?": { page: BuilderContent | null }":""}) { const router = useRouter(); const isPreviewing = useIsPreviewing(); // If the page content is not available // and not in preview mode, show a 404 error page if (!page && !isPreviewing) { return ; } // If the page content is available, render // the BuilderComponent with the page content return ( <> {page?.data?.title} {/* Render the Builder page */} ); } `.trimStart()}async function la(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:u}=ca(e);if(!await e.exists(i)){let p=await e.formatCode(i,s);await e.writeFile(i,p),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,u),t.push({filePath:a,modifiedType:"create"})),i}function ca(e){let t=e.typescriptEnabled,r=` "use client" import React, { useState } from "react"; import styles from "./styles.module.css"; ${t?` interface CounterProps { initialCount?: number; }`:""} function Counter({ initialCount = 99 }${t?": CounterProps":""}) { const [count, setCount] = useState(initialCount); const increment = () => { setCount((prevCount) => prevCount + 1); }; const decrement = () => { setCount((prevCount) => prevCount - 1); }; return (
{count}
); } export default Counter; `.trimStart(),n=` .counter { margin: 32px auto; display: flex; width: 100%; max-width: 190px; } .btn { width: 42px; font-size: 32px; font-weight: bold; background-color: #1c6bd1; color: white; border: none; border-radius: 4px; cursor: pointer; line-height: 1.4; } .btn:hover { opacity: 0.8; } .count { flex: 1; font-size: 42px; text-align: center; } `.trimStart();return{component:r,styles:n}}async function Pr(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===w.gen2){let i=ma(e);await e.writeFile(e.registryPath,i)}else await e.writeFile(e.registryPath,"");t.push({filePath:e.registryPath,modifiedType:"create"})}if(!r)return;let o=(await Fe(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===r);o&&await Fe(e,o.id,!0,!1,null,null,!0,!1)}function ma(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-react"; export const CUSTOM_COMPONENTS: RegisteredComponent[] = [ ];`:`export const CUSTOM_COMPONENTS = [ ]; `}async function ot(e){let t=await bt(e,e.getRepoRootDir());if(t&&typeof t=="object"){let r=new Set(Object.keys({...t.dependencies,...t.devDependencies}));if(r.has("@builder.io/sdk-react"))return w.gen2;if(r.has("@builder.io/react"))return w.gen1}return null}async function yr(e){let t=await fa(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>hr(t),ensureFigmaImportPage:()=>Er(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>Fe(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await Fe(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Fe(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Fe(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Fe(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Fe(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>st(t),setPublicApiKey:n=>Qn(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===w.gen2?[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-react"}]:[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>de(t,n)}}async function fa(e){let t=e.getAppRootDir(),r=e.join(t,"src"),n=await da(e),o=await ln(e),i=`builder-registry.${o?"ts":"js"}`,a={},s={...e,addExternalPackage:u=>{a[e.join(t,u,"index.ts")]=`export * from "${u}";`},readFileSync:u=>a[u]??e.readFileSync(u),existsSync:u=>!!a[u]||e.existsSync(u),readdirSync:u=>{let p=e.readdirSync(u);return u===t?[...p,...Object.keys(a).map(d=>d.slice(t.length+1))]:p},readdir:async u=>{let p=await e.readdir(u);return u===t?[...p,...Object.keys(a).map(d=>d.slice(t.length+1))]:p},appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(e.sdkVersion?s.sdkVersion=e.sdkVersion:s.sdkVersion=await ot(s),await e.exists(r)){s.srcDir=r,s.componentsDir=e.join(r,"components");let u=e.join(r,"app");await e.exists(u)&&(s.appDir=u);let p=e.join(r,"pages");await e.exists(p)&&(s.pagesDir=p),s.registryPath=e.join(r,i)}else s.componentsDir=e.join(t,"components"),s.registryPath=e.join(t,i);if(s.builderComponentPath=e.join(s.componentsDir,`builder.${o?"tsx":"jsx"}`),!s.appDir){let u=e.join(t,"app");await e.exists(u)&&(s.appDir=u)}if(!s.pagesDir){let u=e.join(t,"pages");await e.exists(u)&&(s.pagesDir=u)}if(!s.appDir&&!s.pagesDir)throw new Error(`Could not find Next.js "app" or "pages" directory. Searched in "${t}".`);return s}function ln(e){let t=e.join(e.getAppRootDir(),"tsconfig.json");return e.exists(t)}async function da(e){let t=e.join(e.getAppRootDir(),"next.config.ts");if(await e.exists(t))return t;let r=e.join(e.getAppRootDir(),"next.config.mjs");if(await e.exists(r))return r;let n=e.join(e.getAppRootDir(),"next.config.js");if(await e.exists(n))return n;throw new Error(`Could not find Next.js config file. Searched for "next.config.ts", "next.config.mjs" and "next.config.js" in "${e.getAppRootDir()}".`)}async function gt(e){return await ke(e,[".env"],Tr)}async function wr(e,t){ga(t);let r=await gt(e),n=await Le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function ga(e){typeof process<"u"&&(process.env[Tr]=e)}var Tr="PUBLIC_BUILDER_API_KEY";function br(e,t,r){if(r.length===0)return e;let n=e.split(` `),o=n.findIndex(s=>s.includes(r));if(o===-1||n.some(s=>s.includes(t[0])))return e;let a=["/**",...t.map(s=>` * ${s.trim()}`)," */"];return n.splice(o,0,...a),n.join(` `)}async function Ir(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(a.startsWith(".")||xa.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let u=await Ot(e,o,s,i);r.push(...u)})),r}async function Rr(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return Da(e,t,n)}return null}function Da(e,t,r){let n=I(e,r);return Ot(e,null,t,n)}async function Ot(e,t,r,n){r=e.normalize(r);let o=[],i=ae(e,n);return await Promise.all(i.map(async a=>{let s=await Ca(e,t,r,a);s&&o.push(s)})),o}async function Ca(e,t,r,n){let o=e.relative(e.getAppRootDir(),r),i=$(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=vr(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let u=a.name.text;return{cmpInfo:{id:await V(e,r,u),displayFilePath:k(e,r),name:K(u),inputs:[],exportName:n.isDefaultExport?"default":u,exportType:n.isDefaultExport?"default":"named",importName:u,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=vr(e,n.node);if(a)return{cmpInfo:{id:await V(e,r,"default"),displayFilePath:k(e,r),name:ie(e,r),inputs:[],exportName:"default",exportType:"default",importName:Ue(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function vr(e,t){if(t&&e.ts.isCallExpression(t)&&e.ts.isIdentifier(t.expression)&&t.expression.text==="component$"&&t.arguments.length>0){let r=t.arguments[0];if(e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r))return{callExpression:t,fnNode:r}}return null}var xa=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function Nr(e,t){let r=t.node.fnNode;if((e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r))&&r.parameters.length>0){let{sourceFile:o,typeChecker:i}=await Ze(e,t.cmpInfo.filePath,null);if(!(await Ot(e,i,t.cmpInfo.filePath,o)).find(u=>u.cmpInfo.id===t.cmpInfo.id))throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return ze(e,i,r)}return[]}async function Br(e){return cn(e)}async function cn(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,ha),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var ha=`import type { RegisteredComponent } from "@builder.io/sdk-qwik"; export const CUSTOM_COMPONENTS: RegisteredComponent[] = [ ]; `;async function Or(e){await cn(e);let t=await e.readFile(e.registryPath);return t?Ea(e,t):{components:[],sourceFile:I(e,"")}}async function Ea(e,t){let r=I(e,t);return Sa(e,r)}async function Sa(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await mn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function mn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=K(a)),n.importName=a;let s=await De(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=$(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let u=await Rr(e,s.filePath);if(u&&u.length>0)if(u.length===1)n.exportName=u[0].cmpInfo.exportName;else{let p=u.find(d=>d.cmpInfo.exportName===a);p&&(n.exportName=p.cmpInfo.exportName)}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await V(e,n.filePath,n.exportName)),n}async function kr(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),u=e.extname(a).toLowerCase();if(u===".tsx"||u===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getAppRootDir()),await G(e,[...t])}async function qe(e,t,r,n,o,i,a,s){let u=await kr(e),[p,d,m]=await Promise.all([Ir(e,u),Or(e),gt(e)]),c=p.map(l=>l.cmpInfo),f=d.components,C={components:le(c,f),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ce(c),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return C;if(t!=null){let l=p.find(F=>F.cmpInfo.id===t);if(!l)throw new Error(`Component ${t} not found`);let D=d.sourceFile,g=C.components.find(F=>F.id===t),x=await Nr(e,l);oe(g,x),t=Array.isArray(t)?t[0]:t;let S=Se(t,c,f,r,n,o,i),{elements:P,elmIndex:A,statementIndex:E,statement:O,variableDeclaration:z}=await Fa(e,D,l),j=!1;if(S.addCmpToRegistry?(P.push(Aa(e,S.addCmpToRegistry)),j=!0):S.removeCmpFromRegistry?(P.splice(A,1),j=!0):S.updateRegisteredCmp&&(P[A]=Q(e,P[A],S.updateRegisteredCmp),j=!0),j&&a){let F=[...D.statements];F[E]=e.ts.factory.updateVariableStatement(O,O.modifiers,e.ts.factory.updateVariableDeclarationList(O.declarationList,[e.ts.factory.updateVariableDeclaration(z,z.name,z.exclamationToken,z.type,e.ts.factory.createArrayLiteralExpression(he(e,P)))])),D=e.ts.factory.updateSourceFile(D,F),g.exportType==="named"?D=v(e,D,{namedImports:[g.importName],importPath:B(e,e.registryPath,g.filePath)}):D=v(e,D,{defaultImport:g.importName,importPath:B(e,e.registryPath,g.filePath)}),D=v(e,D,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),D=Ae(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),D=Ee(e,D),D=xe(e,D);let y=_(e,D);y=se(y),y=br(y,Pa,"CUSTOM_COMPONENTS"),y=await e.formatCode(e.registryPath,y),await e.writeFile(e.registryPath,y)}C.components=S.components}return C}function Aa(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Fa(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>Br(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>qe(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:async n=>{},loadComponent:async n=>{let o=await qe(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>qe(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>qe(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>qe(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>qe(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>gt(t),setPublicApiKey:n=>wr(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>de(t,n)}}async function ya(e){let t=await at(e,e.getAppRootDir(),"components");if(!t)throw new Error(`Could not find components directory within project: ${e.getAppRootDir()}`);let r=e.join(t,"builder-registry.ts"),n=e.join(e.getAppRootDir(),".env");return{...e,componentsDir:t,registryPath:r,envPath:n}}async function Dt(e){return await ke(e,[".env"],Ct)}async function _r(e,t){let r=await Dt(e),n=await Le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Ct="PUBLIC_BUILDER_KEY";var wa=new Set(["dist","node_modules"]);async function jr(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker(),i=e.join(e.getAppRootDir(),"build");return await Promise.all(n.map(async a=>{let s=e.basename(a.fileName);if(s.startsWith(".")||s==="node_modules"||It(e,wa,a.fileName)||Ta.has(s)||s.includes("$."))return;let u=e.normalize(a.fileName);if(u===e.remixConfigPath||u===e.registryPath||u===i)return;let p=await je(e,o,u,a);r.push(...p)})),r}var Ta=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function $r(e){await kt(e);let t=await e.readFile(e.registryPath);return t?ba(e,t):{components:[],sourceFile:I(e,"")}}async function ba(e,t){let r=I(e,t);return va(e,r)}async function va(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await fn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function fn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};e.sdkVersion===w.gen2&&Xe(e,r)&&(n.acceptsChildren=!0);for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let d=s.arguments[0];e.ts.isIdentifier(d)&&(a=d.text)}if(!a)continue;n.name===""&&(n.name=K(a)),n.importName=a;let u=await De(e,e.registryPath,t,a);if(!u)continue;if(n.filePath=u.filePath,n.relFilePath=u.relFilePath,await e.exists(u.filePath)?n.importPath=$(e,u.filePath):(n.externalImportPath=u.importPath,n.importPath=n.externalImportPath),n.displayFilePath=u.displayFilePath,n.exportType=u.exportType,n.externalImportPath)n.exportName=a;else{let p=await ar(e,u.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let d=p.find(m=>m.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await V(e,n.filePath,n.exportName,n.externalImportPath)),n}async function Pe(e,t,r,n,o,i,a,s){let u=await $e(e),[p,d,m]=await Promise.all([jr(e,u),$r(e),Dt(e)]),c=p.map(x=>x.cmpInfo),f=d.components,C={components:le(c,f),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ce(c),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return C.components=await tt(e,C.components),C;let l=!1,D=d.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let x=g.map(A=>{let E=p.find(O=>O.cmpInfo.id===A);if(!E)throw new Error(`Component ${A} not found`);return E}),S=Array.from(new Set(x.map(A=>A.cmpInfo.filePath))),P=await G(e,S);for(let A of x){let E=C.components.find(L=>L.id===A.cmpInfo.id),O=await nt(e,A,P);oe(E,O);let z=c.findIndex(L=>L.id===A.cmpInfo.id);c[z].inputs=O;let j=Se(A.cmpInfo.id,c,f,r,n,o,i),{elements:F,elmIndex:y,statementIndex:H,statement:ue,variableDeclaration:Y}=await Ra(e,D,A);if(j.addCmpToRegistry)F.push(Ia(e,j.addCmpToRegistry)),l=!0;else if(j.removeCmpFromRegistry)F.splice(y,1),l=!0;else if(j.updateRegisteredCmp){let L=Q(e,F[y],j.updateRegisteredCmp);F[y]=e.ts.factory.updateObjectLiteralExpression(L,[Vr(e,j.updateRegisteredCmp),...L.properties.slice(1)]),l=!0}if(l&&a){let L=[...D.statements];L[H]=e.ts.factory.updateVariableStatement(ue,ue.modifiers,e.ts.factory.updateVariableDeclarationList(ue.declarationList,[e.ts.factory.updateVariableDeclaration(Y,Y.name,Y.exclamationToken,Y.type,e.ts.factory.createArrayLiteralExpression(he(e,F)))])),D=e.ts.factory.updateSourceFile(D,L),E.exportType==="named"?D=v(e,D,{namedImports:[E.importName],importPath:E.externalImportPath?E.externalImportPath:B(e,e.registryPath,E.filePath)}):D=v(e,D,{defaultImport:E.importName,importPath:E.externalImportPath?E.externalImportPath:B(e,e.registryPath,E.filePath)});let X=e.sdkVersion===w.gen2?"@builder.io/sdk-react":"@builder.io/react";D=v(e,D,{namedImports:["RegisteredComponent"],importPath:X,isTypeOnly:!0}),E.acceptsChildren&&e.sdkVersion!==w.gen2&&(D=v(e,D,{namedImports:["withChildren"],importPath:"@builder.io/react"})),D=Ae(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),C.components=j.components,f=j.components.filter(Me=>Me.isRegistered)}}}if(l&&a){D=Ee(e,D),D=xe(e,D);let x=_(e,D);x=se(x),x=await e.formatCode(e.registryPath,x),await e.writeFile(e.registryPath,x)}return C}function Vr(e,t){if(e.sdkVersion===w.gen2)return e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName));let r=e.ts.factory.createIdentifier(t.importName),n=t.acceptsChildren?e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("withChildren"),void 0,[r]):r;return e.ts.factory.createPropertyAssignment("component",n)}function Ia(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([Vr(e,t),...t.acceptsChildren&&e.sdkVersion===w.gen2?[e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())]:[]],!0),t)}async function Ra(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;au.name==="@shopify/remix-oxygen")&&(s=`context.env.${Ct}`),n&&(s+="!"),e.sdkVersion===w.gen2?` import { Content, fetchOneEntry, getBuilderSearchParams, isPreviewing, } from "@builder.io/sdk-react"; ${n?'import type { LoaderFunctionArgs } from "@remix-run/node";':""} import { useLoaderData } from "@remix-run/react"; import { fetch ${n?"as webFetch":""}} from "@remix-run/web-fetch"; import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)}; export const loader = async ({ params, request }${n?": LoaderFunctionArgs":""}) => { const builderApiKey = ${s}; const url = new URL(request.url); const urlPath = \`/\${params["slug"] || ""}\`; const page = await fetchOneEntry({ model: "${r}", apiKey: builderApiKey, options: getBuilderSearchParams(url.searchParams), userAttributes: { urlPath }, fetch: webFetch, }); if (!page && !isPreviewing(url.search)) { throw new Response("Page Not Found", { status: 404, statusText: "Page not found in Builder.io", }); } return { page, builderApiKey }; }; // Define and render the page. export default function Page() { const { page, builderApiKey } = useLoaderData${n?"":""}(); // Render the page content from Builder.io return ( ); } `:` import { BuilderComponent, builder } from "@builder.io/react"; import { useLoaderData } from "@remix-run/react"; import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)}; ${i} // Fetch contents of the page export const loader = async ({ params, request, context }${a}) => { // Initialize the Builder client and pass in your Public API Key const builderApiKey = ${s}; builder.init(builderApiKey); // Fetch data content from Builder.io based on the URL path const page = await builder .get("${r}", { userAttributes: { urlPath: "/" + params["*"], }, locale: params.locale, }) .toPromise(); // Verify the user is previewing or editing in Builder const isPreviewing = new URL(request.url).searchParams.has("builder.preview"); // If the page is not found and the user is not previewing, throw a 404. // The CatchBoundary component will catch the error if (!page && !isPreviewing) { throw new Response("Page Not Found", { status: 404, statusText: "We couldn't find this page, please check your url path and if the page is published on Builder.io.", }); } return { page, builderApiKey }; }; // Define and render the page. export default function Page() { // Use the useLoaderData hook to get the Page data from "loader" above. const { page, builderApiKey } = useLoaderData${n?"":""}(); // Render the page content from Builder.io return ( ); } ${n?` declare global { interface Env { ${Ct}: string; } } `:""} `}async function Oa(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:u}=ka(e),p=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${p}`),!p){let m=await e.formatCode(i,s);await e.writeFile(i,m),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,u),t.push({filePath:a,modifiedType:"create"})),i}function ka(e){let t=e.typescriptEnabled,r=` import { useState } from "react"; import styles from "./styles.module.css"; ${t?` interface CounterProps { initialCount?: number; }`:""} function Counter({ initialCount = 99 }${t?": CounterProps":""}) { const [count, setCount] = useState(initialCount); const increment = () => { setCount((prevCount) => prevCount + 1); }; const decrement = () => { setCount((prevCount) => prevCount - 1); }; return (
{count}
); } export default Counter; `.trimStart(),n=` .counter { margin: 32px auto; display: flex; width: 100%; max-width: 190px; color: #1c6bd1; } .btn { width: 42px; font-size: 32px; font-weight: bold; background-color: #1c6bd1; color: white; border: none; border-radius: 4px; cursor: pointer; line-height: 1.4; } .btn:hover { opacity: 0.8; } .count { flex: 1; font-size: 42px; text-align: center; } `.trimStart();return{component:r,styles:n}}async function La(e,t){let n=(await Pe(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await Pe(e,n.id,!0,!1,null,null,!0,!1)}async function kt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,_a(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function _a(e){let t=e.sdkVersion===w.gen2;return e.typescriptEnabled?`import type { RegisteredComponent } from ${t?'"@builder.io/sdk-react"':'"@builder.io/react"'}; export const CUSTOM_COMPONENTS: RegisteredComponent[] = [ ];`:`export const CUSTOM_COMPONENTS = [ ]; `}async function zr(e){let t=await ja(e);return{builderPageOptions:async()=>{let n="/builder-demo",o=t.hasLocaleParam?`/en-us${n}`:void 0;return{templateContentId:"a5c9eef7909d4fc99554264a17de22c9",pathname:n,localePathname:o,title:"Builder + Remix Demo Page"}},ensureBuilderSetup:()=>Kr(t),ensureFigmaImportPage:()=>Mr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>Pe(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await Pe(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Pe(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Pe(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Pe(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Pe(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Dt(t),setPublicApiKey:n=>_r(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===w.gen2?[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-react"}]:[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>de(t,n)}}async function ja(e){let t=await Ka(e),r=e.getAppRootDir(),n=await Ma(e),o=e.dirname(n),i=e.join(o,"components"),a=await $a(e),s=`builder-registry.${a?"ts":"js"}`,u=e.join(o,s),p={},d={...e,registryPath:u,remixConfigPath:t,typescriptEnabled:a,appDir:o,componentsDir:i,routesDir:n,hasLocaleParam:await Va(e,n),addExternalPackage:m=>{p[e.join(r,m,"index.ts")]=`export * from "${m}";`},readFileSync:m=>p[m]??e.readFileSync(m),existsSync:m=>!!p[m]||e.existsSync(m),readdirSync:m=>{let c=e.readdirSync(m);return m===r?[...c,...Object.keys(p).map(f=>f.slice(r.length+1))]:c},readdir:async m=>{let c=await e.readdir(m);return m===r?[...c,...Object.keys(p).map(f=>f.slice(r.length+1))]:c}};return e.sdkVersion?d.sdkVersion=e.sdkVersion:d.sdkVersion=await ot(d),d}function $a(e){let t=e.join(e.getAppRootDir(),"tsconfig.json");return e.exists(t)}async function Va(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Ka(e){let t=["remix.config.ts","remix.config.js","vite.config.ts","vite.config.js"];for(let r of t){let n=e.join(e.getAppRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find Remix config file. Searched for ${t.join(", ")} in "${e.getAppRootDir()}".`)}async function Ma(e){let t=await at(e,e.getAppRootDir(),"routes");if(t)return t;throw new Error(`Could not find Remix "routes" directory in "${e.getAppRootDir()}". Please ensure this command is ran from within your Remix project's directory.`)}async function xt(e){let t=[".env"],r=e.configType==="vite"?ht:Lt;return await ke(e,t,r)}async function qr(e,t){let r=await xt(e),n=await Le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ht="VITE_PUBLIC_BUILDER_KEY",Lt="YOUR_PUBLIC_BUILDER_KEY";function Jr(e,t){let r=`Builder.registerComponent( `;r+=` ${t.importName}, `,r+=` { name: "${t.name}", } `,r+=");";let n=vt(e,r);return dn(e,n,t)}function dn(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=Q(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function Qr(e){let t=await e.readFile(e.registryPath);return t?Ua(e,t):{components:[],sourceFile:I(e,"")}}async function Ua(e,t){let r=I(e,t);return e.sdkVersion===w.gen2?Ja(e,r):za(e,r)}async function za(e,t){let r=[];for(let n=0;ne.ts.isImportDeclaration(p)),u=s.find(p=>p.importClause&&p.importClause.name?.text===n.text);if(u){let p=u.moduleSpecifier;if(!e.ts.isStringLiteral(p))return null;a.filePath=await gn(e,p.text),a.relFilePath=e.relative(e.getAppRootDir(),a.filePath),a.importPath=$(e,a.filePath),a.name=ie(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let p=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(f=>f.name.text===n.text));if(!p)return null;let d=p.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let m=await gn(e,d.text);a.filePath=await gn(e,d.text),a.relFilePath=e.relative(e.getAppRootDir(),a.filePath),await e.exists(m)?a.importPath=$(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=K(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=ne(e,a,o),a.displayFilePath=k(e,a.filePath),a.filePath&&a.exportName&&(a.id=await V(e,a.filePath,a.exportName,a.externalImportPath)),a}function gn(e,t){return ft(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function Ja(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Dn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function Dn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};Xe(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(N(e,i)==="component"){let s,{initializer:u}=i;if(e.ts.isIdentifier(u)&&(s=u.text),!s)continue;n.name===""&&(n.name=K(s)),n.importName=s;let p=await De(e,e.registryPath,t,s);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,await e.exists(p.filePath)?n.importPath=$(e,p.filePath):(n.externalImportPath=p.importPath,n.importPath=n.externalImportPath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),m=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(m){let c=m.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(C=>!C.importClause||!C.importClause.namedBindings||!e.ts.isNamedImports(C.importClause.namedBindings)?!1:C.importClause.namedBindings.elements.some(l=>l.name.text===s));if(!c)return null;let f=c.moduleSpecifier;if(!e.ts.isStringLiteral(f))return null;n.exportName=s}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await V(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ye(e,t,r,n,o,i,a,s){let u=await $e(e),[p,d,m,c]=await Promise.all([sr(e,u),Qr(e),Cn(e),xt(e)]),f=p.map(S=>S.cmpInfo),C=d.components,l={components:le(f,C),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ce(f),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return l.components=await tt(e,l.components),l;let D=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let S=x.map(E=>{let O=p.find(z=>z.cmpInfo.id===E);if(!O)throw new Error(`Component ${E} not found`);return O}),P=Array.from(new Set(S.map(E=>E.cmpInfo.filePath))),A=await G(e,P);for(let E of S){let O=l.components.find(y=>y.id===E.cmpInfo.id),z=await nt(e,E,A);oe(O,z);let j=f.findIndex(y=>y.id===E.cmpInfo.id);f[j].inputs=z;let F=Se(E.cmpInfo.id,f,C,r,n,o,i);if(e.sdkVersion===w.gen2){let{elements:y,elmIndex:H,statementIndex:ue,statement:Y,variableDeclaration:L}=await Qa(e,g,E);if(F.addCmpToRegistry)y.push(Wa(e,F.addCmpToRegistry)),D=!0;else if(F.removeCmpFromRegistry)y.splice(H,1),D=!0;else if(F.updateRegisteredCmp){let X=Q(e,y[H],F.updateRegisteredCmp),Me=e.ts.factory.createIdentifier(F.updateRegisteredCmp.importName);y[H]=e.ts.factory.updateObjectLiteralExpression(X,[e.ts.factory.createPropertyAssignment("component",Me),...X.properties.slice(1)]),D=!0}if(D&&a){let X=[...g.statements];X[ue]=e.ts.factory.updateVariableStatement(Y,Y.modifiers,e.ts.factory.updateVariableDeclarationList(Y.declarationList,[e.ts.factory.updateVariableDeclaration(L,L.name,L.exclamationToken,L.type,e.ts.factory.createArrayLiteralExpression(he(e,y)))])),g=e.ts.factory.updateSourceFile(g,X),g=Wr(e,F,g),g=v(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),g=Ae(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),l.components=F.components,C=F.components.filter(Me=>Me.isRegistered)}}else{let y=[...g.statements];F.addCmpToRegistry?(y.push(Jr(e,F.addCmpToRegistry)),D=!0):F.removeCmpFromRegistry?(y.splice(F.nodeIndex,1),D=!0):F.updateRegisteredCmp&&(y[F.nodeIndex]=dn(e,y[F.nodeIndex],F.updateRegisteredCmp),D=!0),D&&a&&(g=e.ts.factory.updateSourceFile(g,y),g=v(e,g,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),g=Wr(e,F,g),O?.acceptsChildren&&(g=v(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),l.components=F.components,C=F.components.filter(H=>H.isRegistered))}}}if(D&&a){g=Ee(e,g),g=xe(e,g);let S=_(e,g);S=se(S),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return l}async function Qa(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a":""}(null); // get the page content from Builder React.useEffect(() => { fetchOneEntry({ model: MODEL_NAME, apiKey: BUILDER_API_KEY, userAttributes: { urlPath: window.location.pathname, }, options: getBuilderSearchParams(new URL(location.href).searchParams), }) .then((content) => { if (content) { setContent(content); } setNotFound(!content); }) .catch((err) => { console.log("Oops: ", err); }); }, []); // If no page is found, return // a 404 page from your code. if (notFound && !isPreviewing()) { return
404 Page Not Found
; } // return the page when found return ( <> {/* Render the Builder page */} ); } `:` import React from "react"; import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react"; import ${JSON.stringify(B(e,t,e.registryPath))}; // Builder Public API Key set in .env file ${e.configType==="vite"?`builder.init(import.meta.env.${ht}${n?"!":""})`:`builder.init("${Lt}")`} export default function BuilderPage() { const isPreviewingInBuilder = useIsPreviewing(); const [notFound, setNotFound] = React.useState(false); const [content, setContent] = React.useState(null); // get the page content from Builder React.useEffect(() => { async function fetchContent() { const content = await builder .get("${r}", { url: window.location.pathname, }) .promise(); setContent(content); setNotFound(!content); // if the page title is found, // set the document title if (content?.data.title) { document.title = content.data.title; } } fetchContent(); }, []); if (content === null) { return; } // If no page is found, return // a 404 page from your code. if (notFound && !isPreviewingInBuilder) { return
404 Page Not Found
; } // return the page when found return ( <> {/* Render the Builder page */} ); } `.trimStart()}async function Xr(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===w.gen2){let i=Ha(e);await e.writeFile(e.registryPath,i)}else await e.writeFile(e.registryPath,"");t.push({filePath:e.registryPath,modifiedType:"create"})}if(!r)return;let o=(await ye(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===r);o&&await ye(e,o.id,!0,!1,null,null,!0,!1)}async function Ya(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:u}=Ga(e);if(!await e.exists(i)){let p=await e.formatCode(i,s);await e.writeFile(i,p),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,u),t.push({filePath:a,modifiedType:"create"})),i}function Ga(e){let t=e.typescriptEnabled,r=` "use client" import React, { useState } from "react"; import styles from "./styles.module.css"; ${t?` interface CounterProps { initialCount?: number; }`:""} function Counter({ initialCount = 99 }${t?": CounterProps":""}) { const [count, setCount] = useState(initialCount); const increment = () => { setCount((prevCount) => prevCount + 1); }; const decrement = () => { setCount((prevCount) => prevCount - 1); }; return (
{count}
); } export default Counter; `.trimStart(),n=` .counter { margin: 32px auto; display: flex; width: 100%; max-width: 190px; } .btn { width: 42px; font-size: 32px; font-weight: bold; background-color: #1c6bd1; color: white; border: none; border-radius: 4px; cursor: pointer; line-height: 1.4; } .btn:hover { opacity: 0.8; } .count { flex: 1; font-size: 42px; text-align: center; } `.trimStart();return{component:r,styles:n}}function Ha(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-react"; export const CUSTOM_COMPONENTS: RegisteredComponent[] = [ ];`:`export const CUSTOM_COMPONENTS = [ ]; `}async function Zr(e){let t=await Xa(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>Yr(t),ensureFigmaImportPage:()=>Gr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>ye(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await ye(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>ye(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>ye(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>ye(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>ye(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>xt(t),setPublicApiKey:n=>qr(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===w.gen2?[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-react"}]:[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>de(t,n)}}async function Xa(e){let t=await Za(e),r=e.getAppRootDir(),n=e.join(r,"src"),o=await Cn(e),i=`builder-registry.${o?"ts":"js"}`,a={},s={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,configType:"",addExternalPackage:u=>{a[e.join(r,u,"index.ts")]=`export * from "${u}";`},readFileSync:u=>a[u]??e.readFileSync(u),existsSync:u=>!!a[u]||e.existsSync(u),readdirSync:u=>{let p=e.readdirSync(u);return u===r?[...p,...Object.keys(a).map(d=>d.slice(r.length+1))]:p},readdir:async u=>{let p=await e.readdir(u);return u===r?[...p,...Object.keys(a).map(d=>d.slice(r.length+1))]:p}};return e.sdkVersion?s.sdkVersion=e.sdkVersion:s.sdkVersion=await ot(s),t.includes("webpack.config")&&(s.configType="webpack"),t.includes("vite.config")&&(s.configType="vite"),await e.exists(n)?(s.srcDir=n,s.componentsDir=e.join(n,"components"),s.registryPath=e.join(n,i),s.builderComponentPath=e.join(s.srcDir,`builder-page.${o?"tsx":"jsx"}`)):(s.componentsDir=e.join(r,"components"),s.registryPath=e.join(r,i),s.builderComponentPath=e.join(r,`builder-page.${o?"tsx":"jsx"}`)),s}function Cn(e){let t=e.join(e.getAppRootDir(),"tsconfig.json");return e.exists(t)}async function Za(e){let t=["vite.config.ts","vite.config.js","webpack.config.js","webpack.config.ts"];for(let r of t){let n=e.join(e.getAppRootDir(),r);if(await e.exists(n))return n}if(e.ignoreMissingConfig)return"";throw new Error(`Could not find React config file. Searched for ${t.join(", ")} in "${e.getAppRootDir()}".`)}async function Et(e){return await es(e,["environment.ts"],_t)}async function eo(e,t){let r=await Et(e),n=await os(e,r.file,r.envKey,t);return{...r,modifiedType:n}}async function es(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getAppRootDir(),"src","environments",o),a=await ts(e,i);if(typeof a=="string"&&a.length>0&&a!=="YOUR_API_KEY")return n.envValue=a,n.file=i,n}return n.file=e.join(e.getAppRootDir(),"src","environments",t[t.length-1]),n}async function ts(e,t){let r=await e.readFile(t);return r?ns(e,r):""}function ns(e,t){let r=I(e,t),n="",i=et(e,r,"environment");if(i&&i.statement.declarationList.declarations.length>0){let s=i.statement.declarationList.declarations[0].initializer;s&&e.ts.isObjectLiteralExpression(s)&&s.properties.forEach(u=>{e.ts.isPropertyAssignment(u)&&e.ts.isIdentifier(u.name)&&u.name.text===_t&&e.ts.isStringLiteral(u.initializer)&&(n=u.initializer.text)})}return n}async function rs(e,t,r,n){let o=I(e,t),a=et(e,o,"environment");if(a&&a.statement.declarationList.declarations.length>0){let s=a.statement.declarationList,u=s.declarations[0],p=u.initializer;if(p&&e.ts.isObjectLiteralExpression(p)){let d=e.ts.factory.createPropertyAssignment(e.ts.factory.createIdentifier(r),e.ts.factory.createStringLiteral(n)),m=e.ts.factory.createNodeArray([...p.properties,d]),c=e.ts.factory.updateObjectLiteralExpression(p,m),f=e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,c),C=e.ts.factory.updateVariableDeclarationList(s,[f]);return e.ts.factory.updateVariableStatement(a.statement,a.statement.modifiers,C)}return null}return null}async function os(e,t,r,n){let o=await e.readFile(t);if(o)if(o.includes(r))e.debug(`"${r}" already set in ${t}`);else{e.debug(`Add "${r}" to ${t}`);let i=await rs(e,o,r,n);if(i){let a=_(e,i),s=await e.formatCode(t,a);await e.writeFile(t,s)}return"update"}else{e.debug(`Creating new env file with "${r}" at ${t}`);let i=` // https://www.builder.io/c/docs/using-your-api-key export const environment = { production: false, builderApiKey: "${n}", }; `.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var _t="builderApiKey";async function to(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(ss(e,i.fileName)||a.startsWith(".")||a==="node_modules"||is.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let u=await jt(e,o,s,i);r.push(...u)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var is=new Set([]),as=new Set(["node_modules"]);function ss(e,t){for(let r of as)if(e.dirname(t).includes(r))return!0;return!1}async function no(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return us(e,t,n)}return null}function us(e,t,r){let n=I(e,r);return jt(e,null,t,n)}async function jt(e,t,r,n){let o=[];r=e.normalize(r);let i=n.statements.filter(u=>e.ts.isClassDeclaration(u)&&ms(e,u)),a=await ls(e,t,r,n),s=ds(e,n);return await Promise.all(i.map(async u=>{let p=await ps(e,t,r,u,s);o.push(...p)})),o.push(...a),o}async function xn(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Ze(e,t.cmpInfo.filePath,r),a=(await jt(e,o,t.cmpInfo.filePath,n)).find(s=>s.cmpInfo.id===t.cmpInfo.id);if(!a)throw new Error(`Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return a.cmpInfo.inputs}return[]}async function ro(e,t,r){if(!r.some(s=>!s.isRegistered))return r;let o=await G(e,r.map(s=>s.filePath)),i=o.getTypeChecker();return await Promise.all(r.filter(s=>!(s.name.endsWith("Page")||s.name.endsWith("Module")||s.name==="AppComponent")).map(async s=>{if(!s.isRegistered){let u=o.getSourceFile(s.filePath);if(u){let d=(await jt(e,i,s.filePath,u)).find(m=>m.cmpInfo.id===s.id);if(d){s.inputs=ze(e,i,d.node.fnNode);let m=t.find(c=>c.cmpInfo.id===s.id);if(m){let c=await xn(e,m,o);oe(s,c)}}}}return s}))}async function ps(e,t,r,n,o){let i=[],a=e.relative(e.getAppRootDir(),r),s=$(e,r),u=n.name?.text;if(!u)return i;let p=!1;n.modifiers&&(p=n.modifiers.some(f=>f.kind===e.ts.SyntaxKind.DefaultKeyword));let d=p?"default":u,m=p?"default":"named",c=[];return n.members.forEach(f=>{if(e.ts.isPropertyDeclaration(f)){let C=e.ts.getDecorators(f);C&&C.forEach(l=>{if(cs(e,l)&&e.ts.isIdentifier(f.name)){let D="any";if(f.type&&t){let x=t.getTypeAtLocation(f.type);D=t.typeToString(x)}else D=fs(e,f.type);let g={name:f.name.text,type:o[D]?"string":D};o[D]&&(g.enum=o[D]),c.push(g)}})}}),i.push({cmpInfo:{id:await V(e,r,u),displayFilePath:k(e,r),name:K(u),inputs:c,exportName:d,exportType:m,importName:u,filePath:r,relFilePath:a,importPath:s},node:{name:u,fnNode:n,deps:void 0}}),i}async function ls(e,t,r,n){let o=[],i=e.relative(e.getAppRootDir(),r),a=$(e,r);for(let s of n.statements)if(e.ts.isExportDeclaration(s)&&s.exportClause&&e.ts.isNamedExports(s.exportClause))for(let u of s.exportClause.elements){let p=u.name?.text;if(!p)continue;let d=p,m="named",c=[];if(t){let l=t.getSymbolAtLocation(u.name);if(l){let D=t.getDeclaredTypeOfSymbol(l);t.getPropertiesOfType(D).forEach(x=>{let S=x.getDeclarations();S&&S.forEach(P=>{if(e.ts.isPropertyDeclaration(P)){let A=t.getTypeAtLocation(P),E={name:x.getName(),type:gs(e,t,A)};c.push(E)}})})}}let f=e.ts.isExportSpecifier(u)&&u.parent?u.parent.parent:void 0,C;if(f){let l=f.moduleSpecifier;if(l&&e.ts.isStringLiteral(l)){let D=t?.getSymbolAtLocation(l);if(D&&D.declarations&&D.declarations.length>0){let g=D.declarations[0];(!e.ts.isSourceFile(g)||e.ts.isSourceFile(g)&&g.fileName.includes("node_modules"))&&(C=l.text)}}}o.push({cmpInfo:{id:await V(e,r,p,C),displayFilePath:k(e,r),name:K(p),inputs:c,exportName:d,exportType:m,importName:p,filePath:r,relFilePath:i,importPath:C||a,externalImportPath:C},node:{name:p,fnNode:u,deps:void 0}})}return o}function cs(e,t){if(e.ts.isCallExpression(t.expression)){let r=t.expression;if(e.ts.isIdentifier(r.expression))return r.expression?.text==="Input"}return!1}function ms(e,t){return!!e.ts.getDecorators(t)?.some(o=>e.ts.isCallExpression(o.expression)&&e.ts.isIdentifier(o.expression.expression)&&o.expression.expression.text==="Component")}function fs(e,t){if(!t)return"any";let r="any";switch(t.kind){case e.ts.SyntaxKind.StringKeyword:r="string";break;case e.ts.SyntaxKind.NumberKeyword:r="number";break;case e.ts.SyntaxKind.BooleanKeyword:r="boolean";break;case e.ts.SyntaxKind.TypeReference:e.ts.isTypeReferenceNode(t);break}return r.includes("|")?"string":r}function ds(e,t){let r={};return e.ts.forEachChild(t,n=>{e.ts.isTypeAliasDeclaration(n)&&e.ts.isUnionTypeNode(n.type)&&n.type.types.every(o=>e.ts.isLiteralTypeNode(o)&&e.ts.isStringLiteral(o.literal))&&(r[n.name.text]=n.type.types.map(o=>o.literal.text))}),r}function gs(e,t,r){let n=t.typeToString(r);if(n==="any"){let o=r.getSymbol();if(o){let i=o.getDeclarations();if(i&&i.length>0){let a=i[0];if(e.ts.isVariableDeclaration(a)){let s=a.type;s&&(n=t.typeToString(t.getTypeAtLocation(s)))}}}}return n}async function $t(e,t,r){let n=e.typescriptEnabled?".ts":".js",o=`app.module${n}`,i=e.join(e.appDir,o),a=await e.readFile(i);if(!a){console.error(`Unable to read app.module.${n} at ${i}`);return}let s=await Ds(e,i,t,r,a);if(!s){console.error(`Unable to update app.module.${n} at ${i}`);return}return await e.writeFile(i,s),i}async function Ds(e,t,r,n,o){let i=o,a=I(e,o),s=B(e,t,n);a=v(e,a,{namedImports:[r],importPath:s}),a=v(e,a,{namedImports:["Content"],importPath:"@builder.io/sdk-angular"});let u=[];for(let p of a.statements)if(e.ts.isClassDeclaration(p)&&p.name?.text==="AppModule"){let d=Cs(e,r,p);u.push(d)}else u.push(p);return a=e.ts.factory.updateSourceFile(a,u),i=_(e,a),i}function Cs(e,t,r){let n=e.ts.getDecorators(r);if(n){for(let o of n)if(e.ts.isCallExpression(o.expression)&&e.ts.isIdentifier(o.expression.expression)&&o.expression.expression.text==="NgModule"){let i=o.expression.arguments;if(i.length===1&&e.ts.isObjectLiteralExpression(i[0])){let a=oo(e,i[0],"declarations",t);if(a){let s=oo(e,a,"imports","Content");if(s&&(a=s),a){let u=e.ts.factory.updateDecorator(o,e.ts.factory.updateCallExpression(o.expression,o.expression.expression,o.expression.typeArguments,[a])),d=[...n.map(m=>m===o?u:m),...e.ts.getModifiers(r)||[]];return e.ts.factory.updateClassDeclaration(r,d,r.name,r.typeParameters,r.heritageClauses,r.members)}}}}}return r}function oo(e,t,r,n){let o=[...t.properties],i=o.findIndex(s=>N(e,s)===r);if(i>-1){let s=o[i];if(e.ts.isPropertyAssignment(s)&&s.initializer&&e.ts.isArrayLiteralExpression(s.initializer)){let u=io(e,s.initializer,n);return u?(o[i]=e.ts.factory.updatePropertyAssignment(s,s.name,u),e.ts.factory.updateObjectLiteralExpression(t,o)):null}return null}let a=io(e,e.ts.factory.createArrayLiteralExpression([],!0),n);return a?e.ts.factory.updateObjectLiteralExpression(t,[...o,e.ts.factory.createPropertyAssignment(r,a)]):null}function io(e,t,r){return t.elements.some(o=>e.ts.isIdentifier(o)?o.text===r:!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier(r)])}async function hn(e,t,r,n){var o;try{if(e.magicast){let a=`app.routes${e.typescriptEnabled?".ts":".js"}`,s=e.join(e.appDir,a),u=await e.magicast.loadFile(s);(o=u.exports).routes||(o.routes=[]);let p=u.exports.routes;if(p.find(m=>m.path===t))return;let d=e.magicast.builders.raw("{}");if(d.path=t,d.component=e.magicast.builders.raw(r),p.push(d),u.imports.$items.find(m=>m.imported===r))return;u.imports.$append({imported:r,from:n}),await e.magicast.writeFile(u,s)}}catch(i){console.error(i)}}var xs=/[\u1680\u2000-\u200A\u202F\u205F\u3000]/,hs=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C60\u0C61\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D5F-\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1C80-\u1C88\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA8FD\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE80-\uDEAA\uDF00-\uDF19]|\uD806[\uDCA0-\uDCDF\uDCFF\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE83\uDE86-\uDE89\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4\uDD00-\uDD43]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]/,Es=/[\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0300-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u0483-\u0487\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u05D0-\u05EA\u05F0-\u05F2\u0610-\u061A\u0620-\u0669\u066E-\u06D3\u06D5-\u06DC\u06DF-\u06E8\u06EA-\u06FC\u06FF\u0710-\u074A\u074D-\u07B1\u07C0-\u07F5\u07FA\u0800-\u082D\u0840-\u085B\u0860-\u086A\u08A0-\u08B4\u08B6-\u08BD\u08D4-\u08E1\u08E3-\u0963\u0966-\u096F\u0971-\u0983\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BC-\u09C4\u09C7\u09C8\u09CB-\u09CE\u09D7\u09DC\u09DD\u09DF-\u09E3\u09E6-\u09F1\u09FC\u0A01-\u0A03\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A59-\u0A5C\u0A5E\u0A66-\u0A75\u0A81-\u0A83\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABC-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AD0\u0AE0-\u0AE3\u0AE6-\u0AEF\u0AF9-\u0AFF\u0B01-\u0B03\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3C-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B5C\u0B5D\u0B5F-\u0B63\u0B66-\u0B6F\u0B71\u0B82\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD0\u0BD7\u0BE6-\u0BEF\u0C00-\u0C03\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C58-\u0C5A\u0C60-\u0C63\u0C66-\u0C6F\u0C80-\u0C83\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBC-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CDE\u0CE0-\u0CE3\u0CE6-\u0CEF\u0CF1\u0CF2\u0D00-\u0D03\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D44\u0D46-\u0D48\u0D4A-\u0D4E\u0D54-\u0D57\u0D5F-\u0D63\u0D66-\u0D6F\u0D7A-\u0D7F\u0D82\u0D83\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DE6-\u0DEF\u0DF2\u0DF3\u0E01-\u0E3A\u0E40-\u0E4E\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB9\u0EBB-\u0EBD\u0EC0-\u0EC4\u0EC6\u0EC8-\u0ECD\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F18\u0F19\u0F20-\u0F29\u0F35\u0F37\u0F39\u0F3E-\u0F47\u0F49-\u0F6C\u0F71-\u0F84\u0F86-\u0F97\u0F99-\u0FBC\u0FC6\u1000-\u1049\u1050-\u109D\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u135D-\u135F\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u170C\u170E-\u1714\u1720-\u1734\u1740-\u1753\u1760-\u176C\u176E-\u1770\u1772\u1773\u1780-\u17D3\u17D7\u17DC\u17DD\u17E0-\u17E9\u180B-\u180D\u1810-\u1819\u1820-\u1877\u1880-\u18AA\u18B0-\u18F5\u1900-\u191E\u1920-\u192B\u1930-\u193B\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19D9\u1A00-\u1A1B\u1A20-\u1A5E\u1A60-\u1A7C\u1A7F-\u1A89\u1A90-\u1A99\u1AA7\u1AB0-\u1ABD\u1B00-\u1B4B\u1B50-\u1B59\u1B6B-\u1B73\u1B80-\u1BF3\u1C00-\u1C37\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1CD0-\u1CD2\u1CD4-\u1CF9\u1D00-\u1DF9\u1DFB-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u203F\u2040\u2054\u2071\u207F\u2090-\u209C\u20D0-\u20DC\u20E1\u20E5-\u20F0\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2160-\u2188\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D7F-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2DE0-\u2DFF\u2E2F\u3005-\u3007\u3021-\u302F\u3031-\u3035\u3038-\u303C\u3041-\u3096\u3099\u309A\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312E\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FEA\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66F\uA674-\uA67D\uA67F-\uA6F1\uA717-\uA71F\uA722-\uA788\uA78B-\uA7AE\uA7B0-\uA7B7\uA7F7-\uA827\uA840-\uA873\uA880-\uA8C5\uA8D0-\uA8D9\uA8E0-\uA8F7\uA8FB\uA8FD\uA900-\uA92D\uA930-\uA953\uA960-\uA97C\uA980-\uA9C0\uA9CF-\uA9D9\uA9E0-\uA9FE\uAA00-\uAA36\uAA40-\uAA4D\uAA50-\uAA59\uAA60-\uAA76\uAA7A-\uAAC2\uAADB-\uAADD\uAAE0-\uAAEF\uAAF2-\uAAF6\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB65\uAB70-\uABEA\uABEC\uABED\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE00-\uFE0F\uFE20-\uFE2F\uFE33\uFE34\uFE4D-\uFE4F\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF3F\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD40-\uDD74\uDDFD\uDE80-\uDE9C\uDEA0-\uDED0\uDEE0\uDF00-\uDF1F\uDF2D-\uDF4A\uDF50-\uDF7A\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDCE0-\uDCF2\uDCF4\uDCF5\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00-\uDE03\uDE05\uDE06\uDE0C-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE38-\uDE3A\uDE3F\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE6\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2]|\uD804[\uDC00-\uDC46\uDC66-\uDC6F\uDC7F-\uDCBA\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD00-\uDD34\uDD36-\uDD3F\uDD50-\uDD73\uDD76\uDD80-\uDDC4\uDDCA-\uDDCC\uDDD0-\uDDDA\uDDDC\uDE00-\uDE11\uDE13-\uDE37\uDE3E\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEEA\uDEF0-\uDEF9\uDF00-\uDF03\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3C-\uDF44\uDF47\uDF48\uDF4B-\uDF4D\uDF50\uDF57\uDF5D-\uDF63\uDF66-\uDF6C\uDF70-\uDF74]|\uD805[\uDC00-\uDC4A\uDC50-\uDC59\uDC80-\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDB5\uDDB8-\uDDC0\uDDD8-\uDDDD\uDE00-\uDE40\uDE44\uDE50-\uDE59\uDE80-\uDEB7\uDEC0-\uDEC9\uDF00-\uDF19\uDF1D-\uDF2B\uDF30-\uDF39]|\uD806[\uDCA0-\uDCE9\uDCFF\uDE00-\uDE3E\uDE47\uDE50-\uDE83\uDE86-\uDE99\uDEC0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC36\uDC38-\uDC40\uDC50-\uDC59\uDC72-\uDC8F\uDC92-\uDCA7\uDCA9-\uDCB6\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD36\uDD3A\uDD3C\uDD3D\uDD3F-\uDD47\uDD50-\uDD59]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|[\uD80C\uD81C-\uD820\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDED0-\uDEED\uDEF0-\uDEF4\uDF00-\uDF36\uDF40-\uDF43\uDF50-\uDF59\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50-\uDF7E\uDF8F-\uDF9F\uDFE0\uDFE1]|\uD821[\uDC00-\uDFEC]|\uD822[\uDC00-\uDEF2]|\uD82C[\uDC00-\uDD1E\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99\uDC9D\uDC9E]|\uD834[\uDD65-\uDD69\uDD6D-\uDD72\uDD7B-\uDD82\uDD85-\uDD8B\uDDAA-\uDDAD\uDE42-\uDE44]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD836[\uDE00-\uDE36\uDE3B-\uDE6C\uDE75\uDE84\uDE9B-\uDE9F\uDEA1-\uDEAF]|\uD838[\uDC00-\uDC06\uDC08-\uDC18\uDC1B-\uDC21\uDC23\uDC24\uDC26-\uDC2A]|\uD83A[\uDC00-\uDCC4\uDCD0-\uDCD6\uDD00-\uDD4A\uDD50-\uDD59]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uDB40[\uDD00-\uDDEF]/,En={Space_Separator:xs,ID_Start:hs,ID_Continue:Es},q={isSpaceSeparator(e){return typeof e=="string"&&En.Space_Separator.test(e)},isIdStartChar(e){return typeof e=="string"&&(e>="a"&&e<="z"||e>="A"&&e<="Z"||e==="$"||e==="_"||En.ID_Start.test(e))},isIdContinueChar(e){return typeof e=="string"&&(e>="a"&&e<="z"||e>="A"&&e<="Z"||e>="0"&&e<="9"||e==="$"||e==="_"||e==="\u200C"||e==="\u200D"||En.ID_Continue.test(e))},isDigit(e){return typeof e=="string"&&/[0-9]/.test(e)},isHexDigit(e){return typeof e=="string"&&/[0-9A-Fa-f]/.test(e)}},An,ee,be,Kt,Ve,ce,W,yn,At,Ss=function(t,r){An=String(t),ee="start",be=[],Kt=0,Ve=1,ce=0,W=void 0,yn=void 0,At=void 0;do W=As(),ys[ee]();while(W.type!=="eof");return typeof r=="function"?Fn({"":At},"",r):At};function Fn(e,t,r){let n=e[t];if(n!=null&&typeof n=="object")if(Array.isArray(n))for(let o=0;o0;){let r=ve();if(!q.isHexDigit(r))throw U(h());e+=h()}return String.fromCodePoint(parseInt(e,16))}var ys={start(){if(W.type==="eof")throw Qe();Sn()},beforePropertyName(){switch(W.type){case"identifier":case"string":yn=W.value,ee="afterPropertyName";return;case"punctuator":Vt();return;case"eof":throw Qe()}},afterPropertyName(){if(W.type==="eof")throw Qe();ee="beforePropertyValue"},beforePropertyValue(){if(W.type==="eof")throw Qe();Sn()},beforeArrayValue(){if(W.type==="eof")throw Qe();if(W.type==="punctuator"&&W.value==="]"){Vt();return}Sn()},afterPropertyValue(){if(W.type==="eof")throw Qe();switch(W.value){case",":ee="beforePropertyName";return;case"}":Vt()}},afterArrayValue(){if(W.type==="eof")throw Qe();switch(W.value){case",":ee="beforeArrayValue";return;case"]":Vt()}},end(){}};function Sn(){let e;switch(W.type){case"punctuator":switch(W.value){case"{":e={};break;case"[":e=[];break}break;case"null":case"boolean":case"numeric":case"string":e=W.value;break}if(At===void 0)At=e;else{let t=be[be.length-1];Array.isArray(t)?t.push(e):Object.defineProperty(t,yn,{value:e,writable:!0,enumerable:!0,configurable:!0})}if(e!==null&&typeof e=="object")be.push(e),Array.isArray(e)?ee="beforeArrayValue":ee="beforePropertyName";else{let t=be[be.length-1];t==null?ee="end":Array.isArray(t)?ee="afterArrayValue":ee="afterPropertyValue"}}function Vt(){be.pop();let e=be[be.length-1];e==null?ee="end":Array.isArray(e)?ee="afterArrayValue":ee="afterPropertyValue"}function U(e){return Mt(e===void 0?`JSON5: invalid end of input at ${Ve}:${ce}`:`JSON5: invalid character '${uo(e)}' at ${Ve}:${ce}`)}function Qe(){return Mt(`JSON5: invalid end of input at ${Ve}:${ce}`)}function ao(){return ce-=5,Mt(`JSON5: invalid identifier character at ${Ve}:${ce}`)}function ws(e){console.warn(`JSON5: '${uo(e)}' in strings is not valid ECMAScript; consider escaping`)}function uo(e){let t={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"};if(t[e])return t[e];if(e<" "){let r=e.charCodeAt(0).toString(16);return"\\x"+("00"+r).substring(r.length)}return e}function Mt(e){let t=new SyntaxError(e);return t.lineNumber=Ve,t.columnNumber=ce,t}var Ts=function(t,r,n){let o=[],i="",a,s,u="",p;if(r!=null&&typeof r=="object"&&!Array.isArray(r)&&(n=r.space,p=r.quote,r=r.replacer),typeof r=="function")s=r;else if(Array.isArray(r)){a=[];for(let l of r){let D;typeof l=="string"?D=l:(typeof l=="number"||l instanceof String||l instanceof Number)&&(D=String(l)),D!==void 0&&a.indexOf(D)<0&&a.push(D)}}return n instanceof Number?n=Number(n):n instanceof String&&(n=String(n)),typeof n=="number"?n>0&&(n=Math.min(10,Math.floor(n)),u=" ".substr(0,n)):typeof n=="string"&&(u=n.substr(0,10)),d("",{"":t});function d(l,D){let g=D[l];switch(g!=null&&(typeof g.toJSON5=="function"?g=g.toJSON5(l):typeof g.toJSON=="function"&&(g=g.toJSON(l))),s&&(g=s.call(D,l,g)),g instanceof Number?g=Number(g):g instanceof String?g=String(g):g instanceof Boolean&&(g=g.valueOf()),g){case null:return"null";case!0:return"true";case!1:return"false"}if(typeof g=="string")return m(g,!1);if(typeof g=="number")return String(g);if(typeof g=="object")return Array.isArray(g)?C(g):c(g)}function m(l){let D={"'":.1,'"':.2},g={"'":"\\'",'"':'\\"',"\\":"\\\\","\b":"\\b","\f":"\\f","\n":"\\n","\r":"\\r"," ":"\\t","\v":"\\v","\0":"\\0","\u2028":"\\u2028","\u2029":"\\u2029"},x="";for(let P=0;PD[P]=0)throw TypeError("Converting circular structure to JSON5");o.push(l);let D=i;i=i+u;let g=a||Object.keys(l),x=[];for(let P of g){let A=d(P,l);if(A!==void 0){let E=f(P)+":";u!==""&&(E+=" "),E+=A,x.push(E)}}let S;if(x.length===0)S="{}";else{let P;if(u==="")P=x.join(","),S="{"+P+"}";else{let A=`, `+i;P=x.join(A),S=`{ `+i+P+`, `+D+"}"}}return o.pop(),i=D,S}function f(l){if(l.length===0)return m(l,!0);let D=String.fromCodePoint(l.codePointAt(0));if(!q.isIdStartChar(D))return m(l,!0);for(let g=D.length;g=0)throw TypeError("Converting circular structure to JSON5");o.push(l);let D=i;i=i+u;let g=[];for(let S=0;So.filePath===t);n&&await we(e,n.id,!0,!1,null,null,!0,!1)}function fo(e,t,r,n,o,i){let a=!e.hasAppModule,s=B(e,r,e.registryPath),u=e.join(e.getAppRootDir(),"src","environments","environment.ts"),p=B(e,r,u),d=i?`
404 - Content not found
`:` `;return` import { Component, Input } from '@angular/core'; import { fetchOneEntry, type BuilderContent${i?", isPreviewing":""} } from '@builder.io/sdk-angular'; ${a?"import { Content } from '@builder.io/sdk-angular';":""} ${a?"import { CommonModule } from '@angular/common';":""} import { environment } from ${JSON.stringify(p)}; import { CUSTOM_COMPONENTS } from ${JSON.stringify(s)}; @Component({ selector: 'app-${n}', ${a?"standalone: true,":""} ${a?"imports: [Content, CommonModule],":""} template: \` ${d} \`, }) export class ${t} { ${i?`isPreviewing = isPreviewing(); `:""} @Input() model = '${o}'; apiKey = environment.${_t}; ${e.typescriptEnabled?` content: BuilderContent | null = null; `:` content = null; `} customComponents = CUSTOM_COMPONENTS; async ngOnInit() { const urlPath = window.location.pathname || '/'; const builderContent = await fetchOneEntry({ model: this.model, apiKey: this.apiKey, userAttributes: { urlPath, }, }); if (!builderContent) { return; } this.content = builderContent; } } `.trimStart()}function Rs(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-angular"; export const CUSTOM_COMPONENTS: RegisteredComponent[] = [ ];`:`export const CUSTOM_COMPONENTS = [ ]; `}async function Ns(e,t){let n=e.typescriptEnabled?"ts":"js",o=e.join(e.componentsDir,`counter.component.${n}`),i=await e.exists(o);e.debug(`angularEnsureCounterComponent, hasCounterCmp: ${i}`);let a=Bs(e);if(!i){let s=await e.formatCode(o,a);await e.writeFile(o,s),t.push({filePath:o,modifiedType:"create"})}return o}function Bs(e){return` import { Component, Input } from '@angular/core'; @Component({ selector: 'app-counter', ${e.hasAppModule?"":"standalone: true,"} template: \`
{{ count }}
\`, styles: [ \` .counter { margin: 32px auto; display: flex; width: 100%; max-width: 190px; } .btn { width: 42px; font-size: 32px; font-weight: bold; background-color: #1c6bd1; color: white; border: none; border-radius: 4px; cursor: pointer; line-height: 1.4; } .btn:hover { opacity: 0.8; } .count { flex: 1; font-size: 42px; text-align: center; margin: 0 8px; } \`, ], }) export class Counter { @Input() initialCount: number = 99; count: number; constructor() { this.count = this.initialCount; } ngOnInit(): void { this.count = this.initialCount; } increment(): void { this.count += 1; } decrement(): void { this.count -= 1; } } `.trimStart()}async function go(e){await Ut(e);let t=await e.readFile(e.registryPath);return t?Os(e,t):{components:[],sourceFile:I(e,"")}}async function Os(e,t){let r=I(e,t);return ks(e,r)}async function ks(e,t){let r=[],n=J(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await wn(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:te(r)}}async function wn(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(N(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=K(a)),n.importName=a;let u=await De(e,e.registryPath,t,a);if(!u)continue;if(n.filePath=u.filePath,n.relFilePath=u.relFilePath,await e.exists(u.filePath)?n.importPath=$(e,u.filePath):(n.externalImportPath=u.importPath,n.importPath=n.externalImportPath),n.displayFilePath=u.displayFilePath,n.exportType=u.exportType,n.externalImportPath)n.exportName=a;else{let p=await no(e,u.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let d=p.find(m=>m.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}}continue}}return n=ne(e,n,r),n.filePath&&n.exportName&&(n.id=await V(e,n.filePath,n.exportName,n.externalImportPath)),n}async function we(e,t,r,n,o,i,a,s){let u=await $e(e),[p,d,m]=await Promise.all([to(e,u),go(e),Et(e)]),c=p.map(x=>x.cmpInfo),f=d.components,C={components:le(c,f),registryPath:e.registryPath,registryDisplayPath:k(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:Ce(c),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return C.components=await ro(e,p,C.components),C;let l=!1,D=d.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let x=g.map(A=>{let E=p.find(O=>O.cmpInfo.id===A);if(!E)throw new Error(`Component ${A} not found`);return E}),S=Array.from(new Set(x.map(A=>A.cmpInfo.filePath))),P=await G(e,S);for(let A of x){let E=C.components.find(L=>L.id===A.cmpInfo.id),O=await xn(e,A,P);oe(E,O);let z=c.findIndex(L=>L.id===A.cmpInfo.id);c[z].inputs=O;let j=Se(A.cmpInfo.id,c,f,r,n,o,i),{elements:F,elmIndex:y,statementIndex:H,statement:ue,variableDeclaration:Y}=await _s(e,D,A);if(j.addCmpToRegistry)F.push(Ls(e,j.addCmpToRegistry)),l=!0;else if(j.removeCmpFromRegistry)F.splice(y,1),l=!0;else if(j.updateRegisteredCmp){let L=Q(e,F[y],j.updateRegisteredCmp);F[y]=e.ts.factory.updateObjectLiteralExpression(L,[Do(e,j.updateRegisteredCmp),...L.properties.slice(1)]),l=!0}if(l&&a){let L=[...D.statements];L[H]=e.ts.factory.updateVariableStatement(ue,ue.modifiers,e.ts.factory.updateVariableDeclarationList(ue.declarationList,[e.ts.factory.updateVariableDeclaration(Y,Y.name,Y.exclamationToken,Y.type,e.ts.factory.createArrayLiteralExpression(he(e,F)))])),D=e.ts.factory.updateSourceFile(D,L),E.exportType==="named"?D=v(e,D,{namedImports:[E.importName],importPath:E.externalImportPath?E.externalImportPath:B(e,e.registryPath,E.filePath)}):D=v(e,D,{defaultImport:E.importName,importPath:E.externalImportPath?E.externalImportPath:B(e,e.registryPath,E.filePath)}),D=v(e,D,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),D=Ae(e,D,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),C.components=j.components,f=j.components.filter(X=>X.isRegistered)}}}if(l&&a){D=Ee(e,D),D=xe(e,D);let x=_(e,D);x=se(x),x=await e.formatCode(e.registryPath,x),await e.writeFile(e.registryPath,x)}return C}function Do(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Ls(e,t){return Q(e,e.ts.factory.createObjectLiteralExpression([Do(e,t)],!0),t)}async function _s(e,t,r){let n=J(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>co(t),ensureFigmaImportPage:()=>mo(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>we(t,null,!1,!1,null,null,!1,!!o?.readAllInputTypes),addExternalPackage:async o=>{r[o]||(r[o]=`export * from "${o}";`)},loadComponent:async o=>{let i=await we(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>we(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>we(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>we(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>we(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Et(t),setPublicApiKey:o=>eo(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>fe(t),setCache:o=>de(t,o)}}async function js(e){let t=await Vs(e),r=e.getAppRootDir(),n=e.join(r,"src"),o=await $s(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:"",angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);a.srcDir=n,a.appDir=e.join(n,"app"),a.componentsDir=e.join(a.appDir,"components"),a.registryPath=e.join(a.appDir,i),a.builderPageComponentPath=e.join(a.componentsDir,`builder-page.component.${o?"ts":"js"}`);let s=`app.module.${o?"ts":"js"}`,u=e.join(a.appDir,s);return await e.exists(u)&&(a.hasAppModule=!0),a}function $s(e){let t=e.join(e.getAppRootDir(),"tsconfig.json");return e.exists(t)}async function Vs(e){let t=e.join(e.getAppRootDir(),"angular.json");if(await e.exists(t))return t;let r=e.join(e.getAppRootDir(),"project.json");if(await e.exists(r))return r;throw new Error(`Could not find Angular config file. Searched for angular.json & project.json in "${e.getAppRootDir()}".`)}var Yt=ii(Io(),1);async function Ro(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:pe(e.relative(e.getAppRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:re(i.inputs)};return re(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,Yt.compress)(n);return btoa(JSON.stringify(o))}async function No(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,Yt.decompress)(o),a=re(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let u=pe(e.normalize(s.filePath)),p=n.components.find(m=>pe(m.filePath).endsWith(u)&&m.exportName===s.exportName);if(!p){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${p.id})`,p.filePath),await t.registerComponent({cmpId:p.id});for(let m of s.inputs)e.debug(`set input (${p.id})`),await t.setRegisteredComponentInput({cmpId:p.id,name:m.name,type:m.type,required:m.required,defaultValue:m.defaultValue,friendlyName:m.friendlyName,helperText:m.helperText});e.debug(`set input (${p.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:p.id,name:s.name,image:s.image,description:s.description});a=re(d)}return a}var me={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Gf={[me.react]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[me.remix]:[{version:w.gen1,recommended:!1},{version:w.gen2,recommended:!0}],[me.angular]:[{version:w.gen2,recommended:!0}],[me.next]:[{version:w.gen1,recommended:!0},{version:w.gen2,recommended:!1}],[me.qwik]:[{version:w.gen2,recommended:!0}]};async function Bo(e,t){let r=[],n=new Set;async function o(s){let u=e.join(s,"package.json");try{let p=await e.readFile(u);if(p===null)throw new Error(`Failed to read package.json at ${u}`);let d=JSON.parse(p);if(n.has(d.name))return null;n.add(d.name);let m={name:d.name,subPackages:[]},c=await e.readdir(s);for(let f of c)f!=="node_modules"&&(await e.stat(e.join(s,f))).isDirectory()&&m.subPackages.push(f);return r.push(m),m}catch(p){return console.error(`Error reading package.json at ${s}:`,p),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),u={...s.dependencies,...s.devDependencies};for(let p of Object.keys(u)){let d=e.join(t,"node_modules",p);await o(d)}if(s.workspaces)for(let p of s.workspaces){let d=await e.readdir(e.join(t,p));for(let m of d){let c=e.join(t,p,m);await o(c)}}}return r}var lu={"@builder.io/qwik-city":Lr,next:yr,"@remix-run/react":zr,react:Zr,"@angular/core":Co},cu={"@builder.io/qwik-city":me.qwik,next:me.next,"@remix-run/react":me.remix,react:me.react,"@angular/core":me.angular};async function Oo(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await Oe(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getAppRootDir()}`);for(let t of e.frameworks){let r=lu[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Ro(e,n),importRegistry:i=>No(e,n,i),framework:cu[t.name],findAllDependencies:async()=>await Bo(e,e.getRepoRootDir())}}}throw new Error(`Devtools framework not found for ${e.getAppRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function ko(e){function t(m){if(typeof m!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(m))}function r(m,c){let f="",C=0,l=-1,D=0,g;for(let x=0;x<=m.length;++x){if(x2){let S=f.lastIndexOf("/");if(S!==f.length-1){S===-1?(f="",C=0):(f=f.slice(0,S),C=f.length-1-f.lastIndexOf("/")),l=x,D=0;continue}}else if(f.length===2||f.length===1){f="",C=0,l=x,D=0;continue}}c&&(f.length>0?f+="/..":f="..",C=2)}else f.length>0?f+="/"+m.slice(l+1,x):f=m.slice(l+1,x),C=x-l-1;l=x,D=0}else g===46&&D!==-1?++D:D=-1}return f}let n=function(...c){let f="",C=!1;for(let l=c.length-1;l>=-1&&!C;l--){let D;l>=0?D=c[l]:e.cwd?D=e.cwd():D="/",t(D),D.length!==0&&(f=D+"/"+f,C=D.charCodeAt(0)===47)}return f=r(f,!C),C?f.length>0?"/"+f:"/":f.length>0?f:"."},o=function(c){if(t(c),c.length===0)return".";let f=c.charCodeAt(0)===47,C=c.charCodeAt(c.length-1)===47;return c=r(c,!f),c.length===0&&!f&&(c="."),c.length>0&&C&&(c+="/"),f?"/"+c:c};return{relative:function(c,f){if(t(c),t(f),c===f||(c=n(c),f=n(f),c===f))return"";let C=1;for(;CP){if(f.charCodeAt(g+E)===47)return f.slice(g+E+1);if(E===0)return f.slice(g+E)}else D>P&&(c.charCodeAt(C+E)===47?A=E:E===0&&(A=0));break}let z=c.charCodeAt(C+E),j=f.charCodeAt(g+E);if(z!==j)break;z===47&&(A=E)}let O="";for(E=C+A+1;E<=l;++E)(E===l||c.charCodeAt(E)===47)&&(O.length===0?O+="..":O+="/..");return O.length>0?O+f.slice(g+A):(g+=A,f.charCodeAt(g)===47&&++g,f.slice(g))},resolve:n,join:function(...c){if(c.length===0)return".";let f;for(let C=0;C0&&(f===void 0?f=l:f+="/"+l)}return f===void 0?".":o(f)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,f){if(f!==void 0&&typeof f!="string")throw new TypeError('"ext" argument must be a string');t(c);let C=0,l=-1,D=!0,g;if(f!==void 0&&f.length>0&&f.length<=c.length){if(f.length===c.length&&f===c)return"";let x=f.length-1,S=-1;for(g=c.length-1;g>=0;--g){let P=c.charCodeAt(g);if(P===47){if(!D){C=g+1;break}}else S===-1&&(D=!1,S=g+1),x>=0&&(P===f.charCodeAt(x)?--x===-1&&(l=g):(x=-1,l=S))}return C===l?l=S:l===-1&&(l=c.length),c.slice(C,l)}else{for(g=c.length-1;g>=0;--g)if(c.charCodeAt(g)===47){if(!D){C=g+1;break}}else l===-1&&(D=!1,l=g+1);return l===-1?"":c.slice(C,l)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let f=c.charCodeAt(0),C=f===47,l=-1,D=!0;for(let g=c.length-1;g>=1;--g)if(f=c.charCodeAt(g),f===47){if(!D){l=g;break}}else D=!1;return l===-1?C?"/":".":C&&l===1?"//":c.slice(0,l)},extname:function(c){t(c);let f=-1,C=0,l=-1,D=!0,g=0;for(let x=c.length-1;x>=0;--x){let S=c.charCodeAt(x);if(S===47){if(!D){C=x+1;break}continue}l===-1&&(D=!1,l=x+1),S===46?f===-1?f=x:g!==1&&(g=1):f!==-1&&(g=-1)}return f===-1||l===-1||g===0||g===1&&f===l-1&&f===C+1?"":c.slice(f,l)}}}async function Lo(e){let t=e.getRepoRootDir?e.getRepoRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=ko({cwd:r,...e}),o=new Map,i=l=>n.normalize(n.resolve(r(),l)),a=l=>{for(let[D]of o)if((D+"/").startsWith(l))return!0;return l===t()},s=l=>(l=i(l),o.has(l)?!0:a(l)),u=l=>{l=i(l);let D=l===t()?l:l+"/",g=D.split("/").length-1,x=[];for(let[S]of o)if(S.split("/").slice(0,g).join("/")+"/"===D){let E=S.split("/")[g];E&&!x.includes(E)&&x.push(E)}return x.sort()},p=l=>{l=i(l);let D=o.get(l);return typeof D=="string"?D:null},d=l=>(l=i(l),{isFile:()=>o.has(l),isDirectory:()=>!o.has(l)&&a(l)}),m=async l=>{if(typeof crypto<"u"){let x=new TextEncoder().encode(l),S=await crypto.subtle.digest("SHA-256",x);return Array.from(new Uint8Array(S)).map(P=>P.toString(16).padStart(2,"0")).join("")}let D=0;for(let g=0;gs(l),existsSync:s,readdir:async l=>u(l),readdirSync:u,readFile:async l=>p(l),readFileSync:p,stat:async l=>d(l),statSync:d,writeFile:async(l,D)=>{l=i(l),o.set(l,D);let g={path:l,basename:n.basename(l),dirname:n.dirname(l),extname:n.extname(l)};for(let x of c)await x(g)},hash:m,getDeviceId:async()=>typeof navigator<"u"?m(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(l,D)=>D,on:(l,D)=>{l==="change"&&c.add(D)},off:(l,D)=>{l==="change"&&c.delete(D)},debug:(...l)=>{console.debug("[builder-dev-tools]",...l)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null,magicast:void 0},C=await Oe(f);return f.getFrameworks=e.getFrameworks?e.getFrameworks:()=>C,f}async function _o(e,t,r){let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(jo(e,n))return o;let a=ae(e,n,"cjs"),s=ae(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let m=d.statement;if(!e.ts.isVariableStatement(m))throw new Error(`Unexpected export type in ${t} Found config content: ${r} The config file must follow one of these formats: 1. const nextConfig = { /* config */ } export default nextConfig 2. const nextConfig = (phase, config) => ({ /* config */ }) export default nextConfig 3. export default { /* config */ } Current export type: ${m.kind?e.ts.SyntaxKind[m.kind]:"none"}`);let c=d.statement;if(e.ts.isVariableStatement(c)){let f=[...c.declarationList.declarations];if(f.length!==1)throw new Error("Expected a single variable declaration");let C=f[0];if(!C.initializer)throw new Error("Expected an initializer on the declaration");let l=C.initializer;if(e.ts.isObjectLiteralExpression(l)||e.ts.isCallExpression(l)){let D="BuilderDevTools()",g=[...n.statements],x=g.indexOf(c);return g[x]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(C,C.name,C.exclamationToken,C.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(D),void 0,[l]))])),n=e.ts.factory.updateSourceFile(n,g),n=v(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error(`Unexpected initializer on the variable statement in ${t} Found config content: ${r} The config variable must be initialized with either: 1. An object literal: const nextConfig = { /* config */ } 2. A function call: const nextConfig = withSomePlugin({ /* config */ }) Current initializer type: ${l?.kind?e.ts.SyntaxKind[l.kind]:"none"} Expected types: ObjectLiteralExpression or CallExpression`)}}let u=a[0];if(!u.isDefaultExport)throw new Error(`Expected a default export from ${t} Found config content: ${r} Detected export type: ${u?.statement.kind??"none"} Valid formats: 1. module.exports = { ... } 2. module.exports = (phase, config) => { return { ... } } 3. export default { ... }`);if(e.ts.isObjectLiteralExpression(u.node)||e.ts.isCallExpression(u.node)){let d=u.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let m=d.expression;if(!e.ts.isBinaryExpression(m))throw new Error("Expected a binary expression for the default export");let c=Vn(e,n);n=c.sourceFile;let f=[...n.statements],C=f.indexOf(d);return f[C]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(m,m.left,m.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[m.right]))),n=e.ts.factory.updateSourceFile(n,f),o.content=_(e,n),o.hasContentUpdates=!0,o}let p=u.statement;if(e.ts.isVariableStatement(p)){let d=[...p.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let m=d[0];if(!m.initializer)throw new Error("Expected an initializer on the declaration");let c=m.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let f=Vn(e,n);n=f.sourceFile;let C=[...n.statements],l=C.indexOf(p);return C[l]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,[e.ts.factory.updateVariableDeclaration(m,m.name,m.exclamationToken,m.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(f.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error(`Unexpected initializer on the variable statement in ${t} Found config content: ${r} The config variable must be initialized with either: 1. An object literal: const nextConfig = { /* config */ } 2. A function call: const nextConfig = withSomePlugin({ /* config */ }) Current initializer type: ${c.kind} Expected types: ${e.ts.SyntaxKind.ObjectLiteralExpression} or ${e.ts.SyntaxKind.CallExpression}`)}if(e.ts.isArrowFunction(u.node)){let d=u.node,m=u.statement;if(!e.ts.isExpressionStatement(m))throw new Error("Expected an expression statement for the default export");let c=m.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let C=u.node.body;if(!e.ts.isBlock(C))throw new Error("Expected a block body on the next config function");let l=[...C.statements],D=l.findIndex(A=>e.ts.isReturnStatement(A));if(D===-1)throw new Error("Expected a return statement on the next config function");let g=l[D],x=Vn(e,n);n=x.sourceFile,l[D]=e.ts.factory.updateReturnStatement(g,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(x.withFnVariableName),void 0,[g.expression]));let S=[...n.statements],P=S.indexOf(m);return S[P]=e.ts.factory.updateExpressionStatement(m,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(C,l)))),n=e.ts.factory.updateSourceFile(n,S),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function jo(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Vn(e,t){let r=jo(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function Ko(e,t,r){let n=I(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Mo(e,n))return o;let a=ae(e,n,"cjs"),s=ae(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let u=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let m=d.statement;if(!e.ts.isExportAssignment(m))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(m.expression)){let c="builderDevTools()",f=mu(e,m.expression);if(!f)return o;let C=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[f]),l=[...n.statements],D=l.indexOf(m);return l[D]=e.ts.factory.updateExportAssignment(m,m.modifiers,C),n=e.ts.factory.updateSourceFile(n,l),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=_(e,n),o.hasContentUpdates=!0,o}}if(!u.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(u.node)||e.ts.isCallExpression(u.node)){let d=u.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let m=d.expression;if(!e.ts.isBinaryExpression(m))throw new Error("Expected a binary expression for the default export");let c=$o(e,n);n=c.sourceFile;let f=[...n.statements],C=f.indexOf(d);return f[C]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(m,m.left,m.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[m.right]))),n=e.ts.factory.updateSourceFile(n,f),o.content=_(e,n),o.hasContentUpdates=!0,o}let p=u.statement;if(e.ts.isVariableStatement(p)){let d=[...p.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let m=d[0];if(!m.initializer)throw new Error("Expected an initializer on the declaration");let c=m.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let f=$o(e,n);n=f.sourceFile;let C=[...n.statements],l=C.indexOf(p);return C[l]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,[e.ts.factory.updateVariableDeclaration(m,m.name,m.exclamationToken,m.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(f.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,C),o.content=_(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function Mo(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function $o(e,t){let r=Mo(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function mu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Vo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Vo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Vo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function zo(e,t,r){let n=I(e,r),o=ae(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let u=[...i.node.arguments];if(u.length===0)throw new Error("Expected an argument in defineConfig()");let p=u[0];if(e.ts.isArrowFunction(p)){let d=fu(e,p);if(!d)return s;u[0]=e.ts.factory.updateArrowFunction(p,p.modifiers,p.typeParameters,p.parameters,p.type,p.equalsGreaterThanToken,d);let m=[...n.statements],c=m.indexOf(a);return m[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,u)),n=e.ts.factory.updateSourceFile(n,m),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(p)){let d=Kn(e,p);if(!d)return s;let m=[...n.statements],c=m.indexOf(a);return m[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,m),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let u=Kn(e,a.expression);if(!u)return s;let p=[...n.statements],d=p.indexOf(a);return p[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,u),n=e.ts.factory.updateSourceFile(n,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=_(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function fu(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=Kn(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function Kn(e,t){if(Du(e)){let i=du(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Uo(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Uo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Uo(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function du(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=gu(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Mn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function gu(e,t){let r=[...t.properties],n=r.findIndex(i=>N(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Mn(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Mn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function Mn(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Du(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function qo(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Qo(e,t,r){e.debug("Angular config updates are currently in progress...");try{await hu(e)}catch{console.error("Unable to update package.json.")}return await Cu(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Cu(e){let t=e.getAppRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getAppRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await xu(e,o);await e.writeFile(n,i)}async function xu(e,t){let r=t,n=I(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=` builderDevTools().catch((err: Error) => console.error("Error starting dev tools:", err) );`;return r=_(e,n),o||(r+=i),r}async function hu(e){let t=e.getRepoRootDir(),r=e.join(t,"package.json"),n=await e.readFile(r);if(!n)throw new Error(`Unable to read package.json at ${r}`);let o=Eu(e,n);o&&await e.writeFile(r,o)}function Eu(e,t){let r=JSON.parse(t);if(r.scripts=r.scripts||{},r.scripts[Jo])return;let n=r.scripts.start||r.scripts.dev||"ng serve";if(!n.includes("concurrently")){let o=e.getRepoRootDir(),i=e.getAppRootDir(),a=o===i?"":` --cwd ${e.relative(o,i)}`,s=`concurrently "${n}" "${Su}${a}"`;r.scripts.start=s,r.scripts[Jo]=s}return JSON.stringify(r,null,2)+` `}var Jo="builder-dev",Su="npx builder-dev-tools";var Yo=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:_o},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:zo},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:Ko},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:qo},{id:"angular",configFileNames:["angular.json","project.json"],ensureConfigPlugin:Qo}];async function Un(e){let t=e.resolve("/");for(let n of Yo)for(let o of n.configFileNames){let i=e.getAppRootDir();for(let a=0;a<10;a++)try{let s=e.join(i,o),u=e.readFileSync(s);if(typeof u=="string")return{id:n.id,filePath:s,content:u};if(i===t)break;i=e.dirname(i)}catch(s){if((s?.message??"").includes("Invalid path"))break;throw s}}if((await Oe(e)).some(n=>n.name==="next")){let n=e.join(e.getAppRootDir(),"next.config.js");return await e.writeFile(n,Wo),{id:"next",filePath:n,content:Wo}}return null}async function Go(e){let t=await Un(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await Yo.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=se(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var Wo=` /** @type {import('next').NextConfig} */ const nextConfig = { } module.exports = nextConfig `.trimStart();var Ho="/~builder-dev-tools.js";function Xo(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(Ho,e);t.searchParams.set("v",wt);let r=JSON.stringify(wt),n=`/* Builder Devtools v${wt} */ `;return n+=`(() => { `,n+=` if (typeof document !== "undefined") { `,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]"); `,n+=` if (!devToolsScript) { `,n+=` devToolsScript = document.createElement("script"); `,n+=` devToolsScript.setAttribute("src", ${JSON.stringify(t)}); `,n+=` devToolsScript.setAttribute("data-builder-dev-tools", ${r}); `,n+=` devToolsScript.setAttribute("async", ""); `,n+=` document.head.appendChild(devToolsScript); `,n+=` } `,n+=` } `,n+=`})(); `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var wt="1.1.38";