builder.io 1.1.26 → 1.1.27-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.cjs +236 -187
- package/cli/index.cjs.map +3 -3
- package/core/index.cjs +87 -38
- package/core/index.mjs +87 -38
- package/package.json +2 -2
- package/server/index.cjs +2 -2
- package/server/index.mjs +2 -2
- package/types/common/ast/component-info.d.ts +1 -0
- package/types/common/utils.d.ts +1 -0
- package/types/core/adapters/next/next-registry-parse.d.ts +0 -1
- package/types/core/adapters/react/react-registry-parse.d.ts +0 -1
- package/types/core/adapters/remix/remix-ensure-builder-setup.d.ts +1 -1
- package/types/core/adapters/remix/remix-registry-parse.d.ts +1 -1
- package/types/core/adapters/remix/remix-registry.d.ts +1 -1
- package/types/core/adapters/remix/remix-test-utils.d.ts +3 -2
package/core/index.cjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`),n;for(;(n=
|
|
3
|
-
`),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var
|
|
1
|
+
"use strict";var Po=Object.create;var lt=Object.defineProperty;var Eo=Object.getOwnPropertyDescriptor;var To=Object.getOwnPropertyNames;var Do=Object.getPrototypeOf,yo=Object.prototype.hasOwnProperty;var Pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wo=(e,t)=>{for(var r in t)lt(e,r,{get:t[r],enumerable:!0})},gn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of To(t))!yo.call(e,o)&&o!==r&<(e,o,{get:()=>t[o],enumerable:!(n=Eo(t,o))||n.enumerable});return e};var vo=(e,t,r)=>(r=e!=null?Po(Do(e)):{},gn(t||!e||!e.__esModule?lt(r,"default",{value:e,enumerable:!0}):r,e)),Io=e=>gn(lt({},"__esModule",{value:!0}),e);var Ht=Pe(Dt=>{"use strict";Object.defineProperty(Dt,"__esModule",{value:!0});function Br(e){return Object.prototype.toString.call(e)}Dt.getType=Br;function Ga(e){throw new TypeError("unsupported data type: "+Br(e))}Dt.throwUnknownDataType=Ga});var nn=Pe(Ce=>{"use strict";Object.defineProperty(Ce,"__esModule",{value:!0});var he="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);he+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);he+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);he+=t}var Ue=he.length,Zt={};for(let e=0;e<Ue;e++){let t=he[e];Zt[t]=e}function en(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Zt[o];i*=r,t+=i,r*=Ue}return t}Ce.s_to_int=en;function Vr(e){let t=BigInt(0),r=BigInt(1),n=BigInt(Ue);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Zt[i]);a*=r,t+=a,r*=n}return t}Ce.s_to_big_int=Vr;function tn(e){if(e===0)return he[0];let t=[];for(;e!==0;){let r=e%Ue,n=he[r];t.push(n),e-=r,e/=Ue}return t.reverse().join("")}Ce.int_to_s=tn;function Kr(e){let t=BigInt(0),r=BigInt(Ue);if(e===t)return he[0];let n=[];for(;e!==t;){let o=e%r,i=he[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}Ce.big_int_to_s=Kr;function wt(e){return e.split("").reverse().join("")}function $r(e){if(e<0)return"-"+$r(-e);let[t,r]=e.toString().split(".");if(!r)return tn(e);let n;r&&([r,n]=r.split("e")),t=yt(t),r=wt(r),r=yt(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=wt(n),n=yt(n),o+=n}return o}Ce.num_to_s=$r;function yt(e){let t=+e;return t.toString()===e?tn(t):":"+Kr(BigInt(e))}Ce.int_str_to_s=yt;function Xt(e){return e[0]===":"?Vr(e.substring(1)).toString():en(e).toString()}function Mr(e){if(e[0]==="-")return-Mr(e.substr(1));let[t,r,n]=e.split(".");if(!r)return en(t);t=Xt(t),r=Xt(r),r=wt(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Xt(n),n=wt(n),o+=i?-n:+n}return+o}Ce.s_to_num=Mr});var on=Pe(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});var rn=nn();function Ha(e){return"n|"+rn.num_to_s(e)}Se.encodeNum=Ha;function Xa(e){return e=e.replace("n|",""),rn.s_to_num(e)}Se.decodeNum=Xa;function Za(e){return typeof e=="number"?e:rn.s_to_int(e)}Se.decodeKey=Za;function es(e){return e?"b|T":"b|F"}Se.encodeBool=es;function ts(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}Se.decodeBool=ts;function ns(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}Se.encodeStr=ns;function rs(e){return e[0]+e[1]==="s|"?e.substr(2):e}Se.decodeStr=rs});var Ur=Pe(an=>{"use strict";Object.defineProperty(an,"__esModule",{value:!0});an.config={sort_key:!1}});var pn=Pe(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});var os=Ur(),is=Ht(),sn=on(),as=nn();function ss(e){return e.store.toArray()}Oe.memToValues=ss;function zr(){let e=[];return{forEach(t){for(let r=0;r<e.length;r++)if(t(e[r])==="break")return},add(t){e.push(t)},toArray(){return e}}}Oe.makeInMemoryStore=zr;function qr(){let e=Object.create(null),t=Object.create(null);return{getValue(r){return e[r]},getSchema(r){return t[r]},forEachValue(r){for(let[n,o]of Object.entries(e))if(r(n,o)==="break")return},forEachSchema(r){for(let[n,o]of Object.entries(t))if(r(n,o)==="break")return},setValue(r,n){e[r]=n},setSchema(r,n){t[r]=n},hasValue(r){return r in e},hasSchema(r){return r in t}}}Oe.makeInMemoryCache=qr;function ps(){return{store:zr(),cache:qr(),keyCount:0}}Oe.makeInMemoryMemory=ps;function Fe(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=as.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function ls(e,t){os.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=it(e,t,void 0);return e.cache.setSchema(r,n),n}function it(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return it(e,null,r);break;case"object":if(t===null)return Fe(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":it(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),Fe(e,n)}else{let n=Object.keys(t);if(n.length===0)return Fe(e,"o|");let o="o",i=ls(e,n);o+="|"+i;for(let a of n){let s=t[a],p=it(e,s,t);o+="|"+p}return Fe(e,o)}case"boolean":return Fe(e,sn.encodeBool(t));case"number":return Fe(e,sn.encodeNum(t));case"string":return Fe(e,sn.encodeStr(t))}return is.throwUnknownDataType(t)}Oe.addValue=it});var cn=Pe(st=>{"use strict";Object.defineProperty(st,"__esModule",{value:!0});var cs=Ht(),vt=on(),ln=pn();function ms(e){let t=ln.makeInMemoryMemory(),r=ln.addValue(t,e,void 0);return[ln.memToValues(t),r]}st.compress=ms;function us(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=at(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let p=i[s-2],l=n[s];l=at(e,l),r[p]=l}return r}function fs(e,t){if(t==="a|")return[];let r=t.split("|"),n=r.length-1,o=new Array(n);for(let i=0;i<n;i++){let a=r[i+1];a=at(e,a),o[i]=a}return o}function at(e,t){if(t===""||t==="_")return null;let r=vt.decodeKey(t),n=e[r];if(n===null)return n;switch(typeof n){case"undefined":return n;case"number":return n;case"string":switch(n[0]+n[1]){case"b|":return vt.decodeBool(n);case"o|":return us(e,n);case"n|":return vt.decodeNum(n);case"a|":return fs(e,n);default:return vt.decodeStr(n)}}return cs.throwUnknownDataType(n)}st.decode=at;function ds(e){let[t,r]=e;return at(t,r)}st.decompress=ds});var Qr=Pe(It=>{"use strict";Object.defineProperty(It,"__esModule",{value:!0});function gs(e){for(let t in e)e[t]===void 0&&delete e[t]}It.trimUndefined=gs;function xs(e){Jr(e,new Set)}It.trimUndefinedRecursively=xs;function Jr(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)&&Jr(n,t)}}});var Gr=Pe(Ie=>{"use strict";Object.defineProperty(Ie,"__esModule",{value:!0});var Wr=cn();Ie.compress=Wr.compress;Ie.decompress=Wr.decompress;var hs=cn();Ie.decode=hs.decode;var Cs=pn();Ie.addValue=Cs.addValue;var Yr=Qr();Ie.trimUndefined=Yr.trimUndefined;Ie.trimUndefinedRecursively=Yr.trimUndefinedRecursively});var As={};wo(As,{createDevTools:()=>eo,createDevToolsSys:()=>no,detectFrameworks:()=>Ee,detectFrameworksFromPackageJson:()=>Rt,ensureConfigPlugin:()=>ho,findBuildToolConfig:()=>dn,getClientScript:()=>So,parseDotEnvContent:()=>Nt,version:()=>pt});module.exports=Io(As);async function ct(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 xn(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.getRootDir())break;t=e.dirname(t)}return e.join(e.getRootDir(),"node_modules")}async function ze(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 p=await ze(e,a,r);if(p)return p}}))).find(i=>typeof i=="string")}async function Ee(e){let t=[],r=await ct(e,e.getRootDir());if(r){let n=Rt(r);t.push(...n)}return t}function Rt(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of bo)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var bo=["@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 re(e){let t=hn(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function oe(e,t){t=typeof t=="object"&&t!=null?t:{};let r=hn(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function hn(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function Te(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await Ro(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.getRootDir(),t[t.length-1]),n}async function Ro(e,t){let r=await e.readFile(t);return typeof r=="string"?Nt(r):null}function Nt(e){let t={},r=e.replace(/\r\n?/gm,`
|
|
2
|
+
`),n;for(;(n=No.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,`
|
|
3
|
+
`),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var No=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function De(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+=`
|
|
4
4
|
|
|
5
5
|
${o}
|
|
6
6
|
${r}=${n}
|
|
7
7
|
|
|
8
8
|
`,await e.writeFile(t,i),"update";else return e.debug(`Creating new .env file with "${r}" at ${t}`),i=[o,`${r}=${n}`,""].join(`
|
|
9
|
-
`),await e.writeFile(t,i),"create";return null}async function
|
|
9
|
+
`),await e.writeFile(t,i),"create";return null}async function qe(e){return await Te(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],ie)}async function Cn(e,t){let r=await qe(e),n=await De(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ie="NEXT_PUBLIC_BUILDER_API_KEY";var D={gen1:"Gen 1",gen2:"Gen 2"};function v(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest,void 0)}function mt(e,t=""){let r=v(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function O(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()+`
|
|
10
10
|
`:n.printNode(e.ts.EmitHint.Unspecified,t,e.ts.createSourceFile("module.tsx","",e.ts.ScriptTarget.Latest)).trim()+`
|
|
11
|
-
`}return""}function I(e,t,r){t=Z(t),r=Z(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=Z(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function Z(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Ie(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return xn(o==="index"?e.basename(e.dirname(t)):o)}function xn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=Z(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function L(e,t){let r=Z(e.relative(e.getRootDir(),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 A(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 j(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 J(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function _(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 qe(e){return typeof e=="number"}function Oe(e){return typeof e=="boolean"}function q(e){return typeof e=="string"}function ke(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function W(e){return JSON.parse(JSON.stringify(e))}function Qe(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=Ro(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,p)=>p!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,Je(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,Je(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function Ro(e,t,r){return t.properties.findIndex(n=>v(e,n)===r)}function We(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return Ao(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return No(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 No(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=v(e,n);o&&(r[o]=We(e,n.initializer))}}return r}function Ao(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>We(e,r)):[]}function v(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 Je(e,t){return Rt(e,t,new WeakSet)}function Rt(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)?Fo(e,t,r):typeof t=="object"?Oo(e,t,r):e.ts.factory.createIdentifier(t)}function Fo(e,t,r){let n=t.map(o=>Rt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Oo(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,Rt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function Re(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 p=a.heritageClauses?.find(l=>l.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(p){for(let l of p)if(t.getSymbolAtLocation(l.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(l)){let m=l.typeArguments;if(m){let c=m[0];o=t.getTypeFromTypeNode(c).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[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 p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[0],r).getProperties())}}}if(o)for(let i of o){let a=ko(e,t,i);a&&n.push(a)}return n=n.filter(Cn),n.length>0?n:Lo(e,r)}function ko(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 p=t.getTypeFromTypeNode(n.type),l=t.typeToString(p),d=Nt(l);d.knownType?i=d.builderType:jo(l)||p.flags&e.ts.TypeFlags.StringLike?i="string":p.flags&e.ts.TypeFlags.NumberLike?i="number":p.flags&e.ts.TypeFlags.IndexedAccess?i="list":p.flags&e.ts.TypeFlags.Object||p.isUnion()&&p.types.every(m=>m.flags&e.ts.TypeFlags.Object)||p.isIntersection()&&p.types.some(m=>m.flags&e.ts.TypeFlags.Object)?i="object":i="string",l!==i&&(a=l)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let p=$o(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},p&&p.length>0&&s.type==="string"&&p.every(Vo)?s.enum=p.map(Ko):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function Lo(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 p=s.jsDocPropertyTags;if(p)for(let l of p){if(!e.ts.isJSDocPropertyLikeTag(l))continue;let d=l.name;if(!e.ts.isQualifiedName(d))continue;let m=l.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 x={name:d.right.text,type:c,isRegistered:!1};r.push(x)}}return r.filter(Cn)}var _o=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function jo(e){return typeof e!="string"?!1:!!_o.some(t=>e.includes(t))}function Nt(e){return typeof e=="string"&&(e=e.trim(),Bo.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var Bo=[{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 Vo(e){return/^['"].*['"]$/.test(e)}function Ko(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var $o=(e,t,r)=>{let n=new Set;hn(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},Mo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},hn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{hn(e,t,o,n)});else if(r.isLiteral()){let o=Mo(e,t,r);n.add(o)}};function Cn(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!Uo.has(t.toLowerCase())}var Uo=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 Q(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=v(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=zo(e,n.initializer);ee(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=We(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function zo(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(qo(e,n));return r}function qo(e,t){let r=We(e,t),n=Xo(r);return n.isRegistered=!0,n}function K(e,t,r){let n=Qo(r);return t=Qe(e,t,"name",n.name,!1),t=Qe(e,t,"description",n.description),t=Qe(e,t,"image",n.image),t=Jo(e,t,n),Zo(e,t)}function Jo(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 Qe(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=Yo(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 Qo(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Wo)}}function Wo(e){let t={name:e.name,type:e.type};return(q(e.defaultValue)||qe(e.defaultValue)||Oe(e.defaultValue))&&(t.defaultValue=e.defaultValue),q(e.friendlyName)&&(t.friendlyName=e.friendlyName),q(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 Yo(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>v(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=Go(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>v(e,c)==="name"),s=i.properties.find(c=>v(e,c)==="name"),p=a?.initializer,l=s?.initializer,d=p&&e.ts.isStringLiteral(p)?p.text:"zz",m=l&&e.ts.isStringLiteral(l)?l.text:"zz";return d.toLowerCase().localeCompare(m.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Go(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=v(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=Sn(e,t[n],r);else{let o=Sn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Sn(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=Ho(e,n,r,i);return n=ei(e,n.filter(i=>{let a=v(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Ho(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,Je(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,Je(e,r[n]))),t}function ee(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=At(e)}function Xo(e){let t=Nt(e.type),r={name:e.name.trim(),type:t.builderType};return q(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(q(e.defaultValue)||qe(e.defaultValue)||Oe(e.defaultValue))&&(r.defaultValue=e.defaultValue),q(e.helperText)&&(r.helperText=e.helperText),Oe(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),Ft(r)}function At(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 Ft(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 Zo(e,t){let r=[...t.properties].sort((n,o)=>{let i=v(e,n)||"zz",a=v(e,o)||"zz";if(i==="inputs")return 1;let s=Pn.indexOf(i),p=Pn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var Pn=["component","name","description"];function ei(e,t){return[...t].sort((n,o)=>{let i=v(e,n)||"zz",a=v(e,o)||"zz",s=yn.indexOf(i),p=yn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)})}var yn=["name","type"];function Tn(e,t){let r=`Builder.registerComponent(
|
|
11
|
+
`}return""}function R(e,t,r){t=Z(t),r=Z(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=Z(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function Z(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Re(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return Sn(o==="index"?e.basename(e.dirname(t)):o)}function Sn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=Z(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function L(e,t){let r=Z(e.relative(e.getRootDir(),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 A(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 j(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 J(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function _(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 Je(e){return typeof e=="number"}function ke(e){return typeof e=="boolean"}function q(e){return typeof e=="string"}function Le(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function W(e){return JSON.parse(JSON.stringify(e))}function ut(e,t,r){for(let n of t)if(e.dirname(r).includes(n))return!0;return!1}function We(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=Ao(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,p)=>p!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,Qe(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,Qe(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function Ao(e,t,r){return t.properties.findIndex(n=>I(e,n)===r)}function Ye(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return Oo(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return Fo(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 Fo(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=I(e,n);o&&(r[o]=Ye(e,n.initializer))}}return r}function Oo(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Ye(e,r)):[]}function I(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 Qe(e,t){return At(e,t,new WeakSet)}function At(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)?ko(e,t,r):typeof t=="object"?Lo(e,t,r):e.ts.factory.createIdentifier(t)}function ko(e,t,r){let n=t.map(o=>At(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Lo(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,At(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function Ne(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 p=a.heritageClauses?.find(l=>l.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(p){for(let l of p)if(t.getSymbolAtLocation(l.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(l)){let u=l.typeArguments;if(u){let c=u[0];o=t.getTypeFromTypeNode(c).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[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 p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[0],r).getProperties())}}}if(o)for(let i of o){let a=_o(e,t,i);a&&n.push(a)}return n=n.filter(En),n.length>0?n:jo(e,r)}function _o(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 p=t.getTypeFromTypeNode(n.type),l=t.typeToString(p),d=Ft(l);d.knownType?i=d.builderType:Vo(l)||p.flags&e.ts.TypeFlags.StringLike?i="string":p.flags&e.ts.TypeFlags.NumberLike?i="number":p.flags&e.ts.TypeFlags.IndexedAccess?i="list":p.flags&e.ts.TypeFlags.Object||p.isUnion()&&p.types.every(u=>u.flags&e.ts.TypeFlags.Object)||p.isIntersection()&&p.types.some(u=>u.flags&e.ts.TypeFlags.Object)?i="object":i="string",l!==i&&(a=l)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let p=Uo(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},p&&p.length>0&&s.type==="string"&&p.every($o)?s.enum=p.map(Mo):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function jo(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 p=s.jsDocPropertyTags;if(p)for(let l of p){if(!e.ts.isJSDocPropertyLikeTag(l))continue;let d=l.name;if(!e.ts.isQualifiedName(d))continue;let u=l.typeExpression;if(!u)continue;let c="";switch(u.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 x={name:d.right.text,type:c,isRegistered:!1};r.push(x)}}return r.filter(En)}var Bo=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function Vo(e){return typeof e!="string"?!1:!!Bo.some(t=>e.includes(t))}function Ft(e){return typeof e=="string"&&(e=e.trim(),Ko.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var Ko=[{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 $o(e){return/^['"].*['"]$/.test(e)}function Mo(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Uo=(e,t,r)=>{let n=new Set;Pn(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},zo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Pn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Pn(e,t,o,n)});else if(r.isLiteral()){let o=zo(e,t,r);n.add(o)}};function En(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!qo.has(t.toLowerCase())}var qo=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 Q(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=I(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=Jo(e,n.initializer);ee(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Ye(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function Jo(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Qo(e,n));return r}function Qo(e,t){let r=Ye(e,t),n=ei(r);return n.isRegistered=!0,n}function K(e,t,r){let n=Yo(r);return t=We(e,t,"name",n.name,!1),t=We(e,t,"description",n.description),t=We(e,t,"image",n.image),t=Wo(e,t,n),ti(e,t)}function Wo(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 We(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=Ho(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 Yo(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Go)}}function Go(e){let t={name:e.name,type:e.type};return(q(e.defaultValue)||Je(e.defaultValue)||ke(e.defaultValue))&&(t.defaultValue=e.defaultValue),q(e.friendlyName)&&(t.friendlyName=e.friendlyName),q(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 Ho(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>I(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=Xo(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>I(e,c)==="name"),s=i.properties.find(c=>I(e,c)==="name"),p=a?.initializer,l=s?.initializer,d=p&&e.ts.isStringLiteral(p)?p.text:"zz",u=l&&e.ts.isStringLiteral(l)?l.text:"zz";return d.toLowerCase().localeCompare(u.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Xo(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=I(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=Tn(e,t[n],r);else{let o=Tn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Tn(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=Zo(e,n,r,i);return n=ni(e,n.filter(i=>{let a=I(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Zo(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,Qe(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,Qe(e,r[n]))),t}function ee(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=Ot(e)}function ei(e){let t=Ft(e.type),r={name:e.name.trim(),type:t.builderType};return q(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(q(e.defaultValue)||Je(e.defaultValue)||ke(e.defaultValue))&&(r.defaultValue=e.defaultValue),q(e.helperText)&&(r.helperText=e.helperText),ke(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),kt(r)}function Ot(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 kt(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 ti(e,t){let r=[...t.properties].sort((n,o)=>{let i=I(e,n)||"zz",a=I(e,o)||"zz";if(i==="inputs")return 1;let s=Dn.indexOf(i),p=Dn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var Dn=["component","name","description"];function ni(e,t){return[...t].sort((n,o)=>{let i=I(e,n)||"zz",a=I(e,o)||"zz",s=yn.indexOf(i),p=yn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)})}var yn=["name","type"];function _e(e,t){for(let r of t.properties){if(!e.ts.isPropertyAssignment(r)||!e.ts.isIdentifier(r.name))continue;if(I(e,r)==="canHaveChildren"){let{initializer:o}=r;return o.kind===e.ts.SyntaxKind.TrueKeyword}}return!1}function wn(e,t){let r=`Builder.registerComponent(
|
|
12
12
|
`;if(e.appDir)t.acceptsChildren?r+=` withChildren(${t.importName}),
|
|
13
13
|
`:r+=` ${t.importName},
|
|
14
|
-
`;else{let o=t.externalImportPath?t.externalImportPath:
|
|
14
|
+
`;else{let o=t.externalImportPath?t.externalImportPath:R(e,e.registryPath,t.filePath);t.exportName==="default"?t.acceptsChildren?r+=` withChildren(dynamic(() => import(${JSON.stringify(o)}))),
|
|
15
15
|
`:r+=` dynamic(() => import(${JSON.stringify(o)})),
|
|
16
16
|
`:t.acceptsChildren?r+=` withChildren(dynamic(async () => (await import(${JSON.stringify(o)})).${t.exportName})),
|
|
17
17
|
`:r+=` dynamic(async () => (await import(${JSON.stringify(o)})).${t.exportName}),
|
|
18
18
|
`}r+=` {
|
|
19
19
|
name: "${t.name}",
|
|
20
20
|
}
|
|
21
|
-
`,r+=");";let n=
|
|
22
|
-
`,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let p=Ye.get(a);if(p)return w(e,p.content)}let s=e.readFileSync(a);if(s==null){let p=e.basename(a),l=e.extname(p).toLowerCase();if(a.startsWith(n)&&l===".ts"&&(s=Dn.get(p),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new ut(p)}return a.includes("node_modules")&&(s?Ye.set(a,{exists:!0,content:s}):Ye.set(a,{exists:!1})),w(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return ti(e,i,t)}catch(a){if(a instanceof ut){await ni(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function ti(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=En.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let p=e.readFileSync(s);return typeof p=="string"?p:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(p,l)=>e.readdirSync(p),fileExists:p=>e.existsSync(p),readFile:p=>e.readFileSync(p)||void 0},e.dirname(o),void 0,o).options,En.set(o,i))}i&&(n.options=W(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 Le(e,t,r){r||(r=await M(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 ut=class{constructor(t){this.libName=t}};async function ni(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;mt.has(t)||mt.set(t,fetch(r).then(n=>n.text()).then(n=>{Dn.set(t,n)})),await mt.get(t),mt.delete(t)}var Dn=new Map,mt=new Map,Ye=new Map,En=new Map;function D(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=ri(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=oi(e,t,r.defaultImport,r.importPath,n)),t}function ri(e,t,r,n,o,i){return i==="cjs"?vn(e,t,null,r,n):wn(e,t,null,r,n,o)}function oi(e,t,r,n,o){return o==="cjs"?vn(e,t,r,null,n):wn(e,t,r,null,n,!1)}function wn(e,t,r,n,o,i){let a=[...t.statements],s=0,p=!1,l=!1;for(let u=0;u<a.length;u++){let x=a[u];if(!e.ts.isImportDeclaration(x)||(s=u,!x.moduleSpecifier||!e.ts.isStringLiteral(x.moduleSpecifier))||x.moduleSpecifier.text!==o||!!x.importClause?.isTypeOnly!==i)continue;let f=[],g=x.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&f.push(...g.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,P)=>C.name.text.localeCompare(P.name.text)),p=!0}let h=x.importClause?x.importClause.name:void 0;if(typeof r=="string"){if(h&&h.text===r)return t;h=e.ts.factory.createIdentifier(r),l=!0}if(p||l)return a[u]=e.ts.factory.updateImportDeclaration(x,void 0,e.ts.factory.createImportClause(i,h,e.ts.factory.createNamedImports(f)),x.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 vn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let p=i[s];if(e.ts.isVariableStatement(p))for(let l=0;l<p.declarationList.declarations.length;l++){let d=[...p.declarationList.declarations],m=d[l],c=m.initializer;if(!c||!e.ts.isCallExpression(c))continue;let u=c.expression;if(!e.ts.isIdentifier(u)||u.text!=="require"||c.arguments.length!==1)continue;let x=c.arguments[0];if(e.ts.isStringLiteral(x)&&(a=s,x.text===o)){if(e.ts.isIdentifier(m.name)&&typeof r=="string")return m.name.text===r?t:(d[l]=e.ts.factory.updateVariableDeclaration(m,e.ts.factory.createIdentifier(r),m.exclamationToken,m.type,m.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(m.name)&&typeof n=="string"){let f=[...m.name.elements];return f.some(h=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)?!1:h.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((h,C)=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:h.name.text.localeCompare(C.name.text)),d[l]=e.ts.factory.updateVariableDeclaration(m,e.ts.factory.createObjectBindingPattern(f),m.exclamationToken,m.type,m.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.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 G(e,t,r="esm"){return r==="cjs"?ai(e,t):ii(e,t)}function ii(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 p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.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 ai(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 p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.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 si(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 ae(e,t,r,n){let o=si(e,r,n);if(o){let i=await Ge(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:A(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function _e(e,t,r){for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(e.ts.isVariableStatement(o)){for(let i of o.declarationList.declarations)if(e.ts.isIdentifier(i.name)&&i.name.text===r)return{statement:o,statementIndex:n}}}return null}function V(e,t,r){let n=_e(e,t,r);if(n&&n.statement.declarationList.declarations.length>0){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 ft(e,t){if(t){if(pi(e,t))return!0;let r=!1;if(t.forEachChild(n=>{ft(e,n)&&(r=!0)}),r)return!0}return!1}function pi(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 Ge(e,t){let r=e.extname(t).toLowerCase();if(r===""||!kt.includes(r)){for(let n of kt){let o=t+n;if(await e.exists(o))return o}for(let n of kt){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var kt=[".tsx",".jsx",".ts",".js"];function He(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=li(e,i);return a?[{name:a}]:void 0}function li(e,t){if(typeof t=="string"){t=e.normalize(Z(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 se(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 je(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await M(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 l=(await we(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=Re(e,o,l.node.fnNode))}return a}))}async function Be(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Le(e,t.cmpInfo.filePath,r),a=(await we(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 Re(e,o,a.node.fnNode)}return[]}async function In(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 ci(e,t,n)}return null}function ci(e,t,r){let n=w(e,r);return we(e,null,t,n)}async function we(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=G(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await mi(e,t,r,a);o.push(...s)})),o}async function mi(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=L(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!ke(s.name.text))continue;let p=De(e,t,s.initializer);if(p){let l=p.name||s.name.text,d=n.isDefaultExport?"default":l,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:j(l),inputs:[],exportName:d,exportType:m,importName:l,filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}}return o}if(e.ts.isArrowFunction(n.node)){let s=De(e,t,n.node);if(s){let p=Y(e,r),l=n.isDefaultExport?"default":p,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:A(e,r),name:p,inputs:[],exportName:l,exportType:d,importName:Ie(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&&!ke(s))return o;let p=De(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:m,importName:p.name||Ie(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}return o}if(e.ts.isExportSpecifier(n.node)&&ke(n.node.getText())){let s,p=De(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,m=n.isDefaultExport?"default":"named",u=n.node.parent.parent.moduleSpecifier;if(u&&e.ts.isStringLiteral(u)){let x=t?.getSymbolAtLocation(u);if(x&&x.declarations&&x.declarations.length>0){let f=x.declarations[0];(!e.ts.isSourceFile(f)||e.ts.isSourceFile(f)&&f.fileName.includes("node_modules"))&&(s=u.text)}}o.push({cmpInfo:{id:await _(e,r,d,s),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:m,importName:p.name||Ie(e,r),filePath:r,relFilePath:i,importPath:s||a,externalImportPath:s,dependencies:p.deps},node:p})}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 p=await di(e,t,r,s);o.push(...p)}return o}return o}function De(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return ft(e,r.body)?{name:"",fnNode:r,deps:He(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return ft(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:He(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:De(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)||!ke(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:He(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:He(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 De(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=De(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 Rn(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(fi(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await we(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var ui=new Set(["node_modules","dist"]);function fi(e,t){for(let r of ui)if(e.dirname(t).includes(r))return!0;return!1}async function di(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 p of s){let l=p.valueDeclaration||p.declarations?.[0];if(!l)continue;let d=p.name;if(!ke(d)&&d!=="default"||!Nn(e,t,l))continue;let m=De(e,t,l);if(m){let c=p.name,u=c==="default"?"default":"named",x=j(c),f=c==="default"?Ie(e,r):c;o.push({cmpInfo:{id:await _(e,r,c,i),displayFilePath:A(e,r),name:x,inputs:[],exportName:c,exportType:u,importName:f,filePath:r,relFilePath:e.relative(e.getRootDir(),r),importPath:i,externalImportPath:i,dependencies:m.deps},node:m})}}}catch(a){console.error(`Error processing module ${i}:`,a)}return o}function Nn(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 Nn(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 bn(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=>bn(t.getReturnTypeOfSignature(i),t)):!1}function bn(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 An(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&&gi.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 p=await we(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var gi=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 pe(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 p=a.moduleSpecifier.text;if(!p.startsWith(".")&&!p.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,[...Lt(e,r),...Lt(e,n),...Lt(e,o),...i])}function H(e){let t=e.split(`
|
|
21
|
+
`,r+=");";let n=mt(e,r);return Lt(e,n,t)}function Lt(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]=K(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function M(e,t){if(!Array.isArray(t)||t.length===0)throw new Error(`createTsProgram() Invalid filePaths: ${t}`);let r=await xn(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=Ge.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}Ge.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:()=>`
|
|
22
|
+
`,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let p=Ge.get(a);if(p)return v(e,p.content)}let s=e.readFileSync(a);if(s==null){let p=e.basename(a),l=e.extname(p).toLowerCase();if(a.startsWith(n)&&l===".ts"&&(s=In.get(p),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new dt(p)}return a.includes("node_modules")&&(s?Ge.set(a,{exists:!0,content:s}):Ge.set(a,{exists:!1})),v(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return ri(e,i,t)}catch(a){if(a instanceof dt){await oi(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function ri(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=vn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let p=e.readFileSync(s);return typeof p=="string"?p:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(p,l)=>e.readdirSync(p),fileExists:p=>e.existsSync(p),readFile:p=>e.readFileSync(p)||void 0},e.dirname(o),void 0,o).options,vn.set(o,i))}i&&(n.options=W(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 je(e,t,r){r||(r=await M(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 dt=class{constructor(t){this.libName=t}};async function oi(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;ft.has(t)||ft.set(t,fetch(r).then(n=>n.text()).then(n=>{In.set(t,n)})),await ft.get(t),ft.delete(t)}var In=new Map,ft=new Map,Ge=new Map,vn=new Map;function w(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=ii(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=ai(e,t,r.defaultImport,r.importPath,n)),t}function ii(e,t,r,n,o,i){return i==="cjs"?Rn(e,t,null,r,n):bn(e,t,null,r,n,o)}function ai(e,t,r,n,o){return o==="cjs"?Rn(e,t,r,null,n):bn(e,t,r,null,n,!1)}function bn(e,t,r,n,o,i){let a=[...t.statements],s=0,p=!1,l=!1;for(let m=0;m<a.length;m++){let x=a[m];if(!e.ts.isImportDeclaration(x)||(s=m,!x.moduleSpecifier||!e.ts.isStringLiteral(x.moduleSpecifier))||x.moduleSpecifier.text!==o||!!x.importClause?.isTypeOnly!==i)continue;let f=[],g=x.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&f.push(...g.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,P)=>C.name.text.localeCompare(P.name.text)),p=!0}let h=x.importClause?x.importClause.name:void 0;if(typeof r=="string"){if(h&&h.text===r)return t;h=e.ts.factory.createIdentifier(r),l=!0}if(p||l)return a[m]=e.ts.factory.updateImportDeclaration(x,void 0,e.ts.factory.createImportClause(i,h,e.ts.factory.createNamedImports(f)),x.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,u;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(u=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,u),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function Rn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let p=i[s];if(e.ts.isVariableStatement(p))for(let l=0;l<p.declarationList.declarations.length;l++){let d=[...p.declarationList.declarations],u=d[l],c=u.initializer;if(!c||!e.ts.isCallExpression(c))continue;let m=c.expression;if(!e.ts.isIdentifier(m)||m.text!=="require"||c.arguments.length!==1)continue;let x=c.arguments[0];if(e.ts.isStringLiteral(x)&&(a=s,x.text===o)){if(e.ts.isIdentifier(u.name)&&typeof r=="string")return u.name.text===r?t:(d[l]=e.ts.factory.updateVariableDeclaration(u,e.ts.factory.createIdentifier(r),u.exclamationToken,u.type,u.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(u.name)&&typeof n=="string"){let f=[...u.name.elements];return f.some(h=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)?!1:h.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((h,C)=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:h.name.text.localeCompare(C.name.text)),d[l]=e.ts.factory.updateVariableDeclaration(u,e.ts.factory.createObjectBindingPattern(f),u.exclamationToken,u.type,u.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.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 G(e,t,r="esm"){return r==="cjs"?pi(e,t):si(e,t)}function si(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 p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.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 pi(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 p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.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 li(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 ae(e,t,r,n){let o=li(e,r,n);if(o){let i=await He(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:A(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function Be(e,t,r){for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(e.ts.isVariableStatement(o)){for(let i of o.declarationList.declarations)if(e.ts.isIdentifier(i.name)&&i.name.text===r)return{statement:o,statementIndex:n}}}return null}function V(e,t,r){let n=Be(e,t,r);if(n&&n.statement.declarationList.declarations.length>0){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 gt(e,t){if(t){if(ci(e,t))return!0;let r=!1;if(t.forEachChild(n=>{gt(e,n)&&(r=!0)}),r)return!0}return!1}function ci(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 He(e,t){let r=e.extname(t).toLowerCase();if(r===""||!_t.includes(r)){for(let n of _t){let o=t+n;if(await e.exists(o))return o}for(let n of _t){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var _t=[".tsx",".jsx",".ts",".js"];function Xe(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=mi(e,i);return a?[{name:a}]:void 0}function mi(e,t){if(typeof t=="string"){t=e.normalize(Z(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 se(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 Ve(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await M(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 l=(await we(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=Ne(e,o,l.node.fnNode))}return a}))}async function Ke(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await je(e,t.cmpInfo.filePath,r),a=(await we(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 Ne(e,o,a.node.fnNode)}return[]}async function An(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 ui(e,t,n)}return null}function ui(e,t,r){let n=v(e,r);return we(e,null,t,n)}async function we(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=G(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await fi(e,t,r,a);o.push(...s)})),o}async function fi(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=L(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Le(s.name.text))continue;let p=ye(e,t,s.initializer);if(p){let l=p.name||s.name.text,d=n.isDefaultExport?"default":l,u=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:j(l),inputs:[],exportName:d,exportType:u,importName:l,filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}}return o}if(e.ts.isArrowFunction(n.node)){let s=ye(e,t,n.node);if(s){let p=Y(e,r),l=n.isDefaultExport?"default":p,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:A(e,r),name:p,inputs:[],exportName:l,exportType:d,importName:Re(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&&!Le(s))return o;let p=ye(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,u=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:u,importName:p.name||Re(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}return o}if(e.ts.isExportSpecifier(n.node)&&Le(n.node.getText())){let s,p=ye(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,u=n.isDefaultExport?"default":"named",m=n.node.parent.parent.moduleSpecifier;if(m&&e.ts.isStringLiteral(m)){let x=t?.getSymbolAtLocation(m);if(x&&x.declarations&&x.declarations.length>0){let f=x.declarations[0];(!e.ts.isSourceFile(f)||e.ts.isSourceFile(f)&&f.fileName.includes("node_modules"))&&(s=m.text)}}o.push({cmpInfo:{id:await _(e,r,d,s),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:u,importName:p.name||Re(e,r),filePath:r,relFilePath:i,importPath:s||a,externalImportPath:s,dependencies:p.deps},node:p})}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 p=await gi(e,t,r,s);o.push(...p)}return o}return o}function ye(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return gt(e,r.body)?{name:"",fnNode:r,deps:Xe(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return gt(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Xe(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:ye(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)||!Le(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Xe(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Xe(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 ye(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=ye(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 Fn(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(ut(e,di,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await we(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var di=new Set(["node_modules","dist"]);async function gi(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 p of s){let l=p.valueDeclaration||p.declarations?.[0];if(!l)continue;let d=p.name;if(!Le(d)&&d!=="default"||!On(e,t,l))continue;let u=ye(e,t,l);if(u){let c=p.name,m=c==="default"?"default":"named",x=j(c),f=c==="default"?Re(e,r):c;o.push({cmpInfo:{id:await _(e,r,c,i),displayFilePath:A(e,r),name:x,inputs:[],exportName:c,exportType:m,importName:f,filePath:r,relFilePath:e.relative(e.getRootDir(),r),importPath:i,externalImportPath:i,dependencies:u.deps},node:u})}}}catch(a){console.error(`Error processing module ${i}:`,a)}return o}function On(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 On(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 Nn(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=>Nn(t.getReturnTypeOfSignature(i),t)):!1}function Nn(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 kn(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&&xi.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 p=await we(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var xi=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 pe(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 p=a.moduleSpecifier.text;if(!p.startsWith(".")&&!p.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,[...jt(e,r),...jt(e,n),...jt(e,o),...i])}function H(e){let t=e.split(`
|
|
23
23
|
`).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+`
|
|
24
24
|
`),/^builder.init(.*)$/.test(o)&&(o=o+`
|
|
25
25
|
`),t[n-1]&&!t[n-1].includes("*/")&&(o.trim().startsWith("Builder.registerComponent")&&(o=`
|
|
@@ -28,12 +28,12 @@ ${r}=${n}
|
|
|
28
28
|
`+o),o.trim().startsWith("export ")&&(o=`
|
|
29
29
|
`+o)),e=o+`
|
|
30
30
|
`+e}return e.trim()+`
|
|
31
|
-
`}function
|
|
32
|
-
${e}`),e}function Ln(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 le(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=On(e,r),i=On(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function On(e,t){let r=t.properties.find(n=>v(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function _n(e){let t=await e.readFile(e.registryPath);return t?xi(e,t):{components:[],sourceFile:w(e,"")}}async function xi(e,t){let r=w(e,t);return e.sdkVersion===b.gen2?Ci(e,r):hi(e,r)}async function hi(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let l=i.arguments;if(l.length<2)continue;let d=l[1];if(!e.ts.isObjectLiteralExpression(d))continue;let m=l[0];if(e.ts.isCallExpression(m)){let c=e.ts.isIdentifier(m.expression)&&m.expression.text;if(c==="withChildren"){let x=Bt(e,m.arguments[0]);if(e.ts.isCallExpression(x)){let f=await _t(e,n,x,d,!0);f&&r.push(f)}else{let f=x;if(e.ts.isIdentifier(f)){let g=await jt(e,t,n,f,d,!0);g&&r.push(g)}}continue}if(c==="dynamic"){let x=await _t(e,n,m,d,!1);x&&r.push(x);continue}let u=Bt(e,m.arguments[0]);if(e.ts.isCallExpression(u)&&e.ts.isIdentifier(u.expression)&&u.expression.text==="dynamic"){let x=await _t(e,n,u,d,!1);x&&r.push(x);continue}if(e.ts.isIdentifier(u)){let x=await jt(e,t,n,u,d,!1);x&&r.push(x);continue}continue}if(e.ts.isIdentifier(m)){let c=await jt(e,t,n,m,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:J(r)}}function Bt(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:Bt(e,t.arguments[0]):t}async function _t(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let p=s.body;if(e.ts.isCallExpression(p)){if(p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let d=p.arguments[0];if(!e.ts.isStringLiteral(d))return null;let m=d.text,c=await Ve(e,m);i.filePath=c,i.relFilePath=e.relative(e.getRootDir(),i.filePath),await e.exists(c)?i.importPath=L(e,i.filePath):(i.externalImportPath=m,i.importPath=i.externalImportPath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(p)){let l=p.expression;if(!e.ts.isParenthesizedExpression(l))return null;let d=l.expression;if(!e.ts.isAwaitExpression(d))return null;let m=d.expression;if(!e.ts.isCallExpression(m)||m.expression.kind!==e.ts.SyntaxKind.ImportKeyword||m.arguments.length!==1)return null;let u=m.arguments[0];if(!e.ts.isStringLiteral(u)||!e.ts.isIdentifier(p.name))return null;let x=u.text,f=await Ve(e,x);i.filePath=f,i.relFilePath=e.relative(e.getRootDir(),i.filePath),await e.exists(f)?i.importPath=L(e,i.filePath):(i.externalImportPath=x,i.importPath=i.externalImportPath),i.name=j(p.name.text),i.importName=p.name.text,i.exportName=p.name.text,i.exportType="named"}else return null;return i=Q(e,i,n),i.displayFilePath=A(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName,i.externalImportPath)),i}async function jt(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(l=>e.ts.isImportDeclaration(l)),p=s.find(l=>l.importClause&&l.importClause.name?.text===n.text);if(p){let l=p.moduleSpecifier;if(!e.ts.isStringLiteral(l))return null;let d=await Ve(e,l.text);a.filePath=d,a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(d)?a.importPath=L(e,a.filePath):(a.externalImportPath=l.text,a.importPath=a.externalImportPath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(u=>u.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let m=await Ve(e,d.text);a.filePath=m,a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(m)?a.importPath=L(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=Q(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName,a.externalImportPath)),a}function Ve(e,t){return Ge(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function jn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let l=0;l<i.length;l++){let d=i[l];if(e.ts.isImportDeclaration(d)){o=l;continue}if(!e.ts.isExpressionStatement(d))continue;let m=d.expression;if(!e.ts.isCallExpression(m))continue;let c=m.expression;if(!e.ts.isPropertyAccessExpression(c))continue;let u=c.expression;if(!e.ts.isIdentifier(u)||u.text!=="builder")continue;if(c.name.text=="init"){n=!0;break}else continue}if(n)return t;let a=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("process"),e.ts.factory.createIdentifier("env")),e.ts.factory.createIdentifier(ie)),s=r?e.ts.factory.createNonNullExpression(a):a,p=e.ts.factory.createExpressionStatement(e.ts.factory.createCallExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("builder"),e.ts.factory.createIdentifier("init")),void 0,[s]));return i.splice(o+1,0,p),e.ts.factory.updateSourceFile(t,i)}async function Ci(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Vt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Vt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};Si(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(v(e,i)==="component"){let s,{initializer:p}=i;if(e.ts.isCallExpression(p)&&(e.ts.isIdentifier(p.expression)&&p.expression.text)==="dynamic"){let u=p.arguments;if(u.length===0)return null;let x=u[0];if(!e.ts.isArrowFunction(x))return null;let f=x.body;if(e.ts.isCallExpression(f)){if(f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let h=f.arguments[0];if(!e.ts.isStringLiteral(h))return null;let C=h.text,P=await Ve(e,C);n.filePath=P,n.relFilePath=e.relative(e.getRootDir(),n.filePath),await e.exists(P)?n.importPath=L(e,n.filePath):(n.externalImportPath=C,n.importPath=n.externalImportPath),n.name=Y(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(f)){let g=f.expression;if(!e.ts.isParenthesizedExpression(g))return null;let h=g.expression;if(!e.ts.isAwaitExpression(h))return null;let C=h.expression;if(!e.ts.isCallExpression(C)||C.expression.kind!==e.ts.SyntaxKind.ImportKeyword||C.arguments.length!==1)return null;let R=C.arguments[0];if(!e.ts.isStringLiteral(R)||!e.ts.isIdentifier(f.name))return null;let E=R.text,S=await Ve(e,E);n.filePath=S,n.relFilePath=e.relative(e.getRootDir(),n.filePath),await e.exists(S)?n.importPath=L(e,n.filePath):(n.externalImportPath=E,n.importPath=n.externalImportPath),n.name=j(f.name.text),n.importName=f.name.text,n.exportName=f.name.text,n.exportType="named"}else return null;return n=Q(e,n,r),n.displayFilePath=A(e,n.filePath),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await ae(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,await e.exists(l.filePath)?n.importPath=L(e,l.filePath):(n.externalImportPath=l.importPath,n.importPath=n.externalImportPath),n.importPath=L(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.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(x=>!x.importClause||!x.importClause.namedBindings||!e.ts.isNamedImports(x.importClause.namedBindings)?!1:x.importClause.namedBindings.elements.some(f=>f.name.text===s));if(!c)return null;let u=c.moduleSpecifier;if(!e.ts.isStringLiteral(u))return null;n.exportName=s}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}function Si(e,t){for(let r of t.properties){if(!e.ts.isPropertyAssignment(r)||!e.ts.isIdentifier(r.name))continue;if(v(e,r)==="canHaveChildren"){let{initializer:o}=r;return o.kind===e.ts.SyntaxKind.TrueKeyword}}return!1}function ce(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 p=[...s.elements];for(let l=p.length-1;l>=0;l--){let d=p[l];if(e.ts.isImportSpecifier(d)){let m=d.name;if(m&&e.ts.isIdentifier(m)){let c=m.text;Bn(e,t,c)||p.splice(l,1)}}}if(p.length===0)a=!0;else if(s.elements.length!==p.length){let l=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(p)),d=e.ts.factory.updateImportDeclaration(i,void 0,l,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let p=i.importClause.name.text;Bn(e,t,p)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Bn(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 me(e,t,r,n,o,i,a){let s=null,p=null,l=null,d=-1;t=W(t),r=W(r);let m=t.find(u=>u.id===e),c=r.find(u=>u.id===e);if(n)c||(s={...W(m),inputs:W(m.inputs).map(u=>(u.isRegistered=!0,u))},d=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)d=c.nodeIndex,p=W(c),r=r.filter(u=>u.id!==e);else if(i!=null)Pi(c,i),d=c.nodeIndex,l=c;else if(a!=null){let u=c.inputs.find(x=>x.name===a.name);u&&(a.registerInput===!1?u.isRegistered=!1:(yi(u,a),u.isRegistered=!0),l=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:p,updateRegisteredCmp:l,nodeIndex:d,components:te(t,r)}}function te(e,t){let r=J([...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(Ft),n.inputs.sort((a,s)=>a.name.toLowerCase().localeCompare(s.name.toLowerCase()));let o=t.find(a=>a.id===n.id);o&&(o.acceptsChildren=At(n));let i=e.find(a=>a.id===n.id&&a.externalImportPath);i&&(n.filePath=i.filePath,n.relFilePath=i.relFilePath)}),r}function Pi(e,t){q(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),q(t.description)?e.description=t.description:t.description===null&&delete e.description,q(t.image)?e.image=t.image:t.image===null&&delete e.image}function yi(e,t){q(t.type)&&(e.type=t.type),q(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,q(t.defaultValue)||qe(t.defaultValue)||Oe(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,q(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 ve(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),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".jsx"||p===".ts"||p===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await M(e,[...t])}function ue(e,t,r){return _e(e,t,r.variableName)?t:Ti(e,t,r)}function Ti(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),p=e.ts.factory.createVariableStatement([s],a),l=[...t.statements,p];return e.ts.factory.updateSourceFile(t,l)}async function fe(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,m,c]=await Promise.all([An(e,p),_n(e),Kt(e),ze(e)]),u=l.map(P=>P.cmpInfo),x=d.components,f={components:te(u,x),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(u),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await je(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let N=l.find(B=>B.cmpInfo.id===S);if(!N)throw new Error(`Component ${S} not found`);return N}),R=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),E=await M(e,R);for(let S of P){let N=f.components.find(T=>T.id===S.cmpInfo.id),B=await Be(e,S,E);ee(N,B);let k=u.findIndex(T=>T.id===S.cmpInfo.id);u[k].inputs=B;let y=me(S.cmpInfo.id,u,x,r,n,o,i);if(e.sdkVersion===b.gen2){let{elements:T,elmIndex:U,statementIndex:X,statement:$,variableDeclaration:F}=await wi(e,h,S);if(y.addCmpToRegistry)T.push(Di(e,y.addCmpToRegistry)),g=!0;else if(y.removeCmpFromRegistry)T.splice(U,1),g=!0;else if(y.updateRegisteredCmp){let z=K(e,T[U],y.updateRegisteredCmp);T[U]=e.ts.factory.updateObjectLiteralExpression(z,[Kn(e,y.updateRegisteredCmp),...z.properties.slice(1)]),g=!0}if(g&&a){let z=[...h.statements];z[X]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(F,F.name,F.exclamationToken,F.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),h=e.ts.factory.updateSourceFile(h,z),h=Vn(e,y,h),h=D(e,h,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),h=ue(e,h,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),f.components=y.components,x=y.components.filter(Me=>Me.isRegistered)}}else{let T=[...h.statements];y.addCmpToRegistry?(T.push(Tn(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(T.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(T[y.nodeIndex]=Ot(e,T[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a&&(h=e.ts.factory.updateSourceFile(h,T),h=D(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=jn(e,h,m),h=Vn(e,y,h),N?.acceptsChildren&&(h=D(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=y.components,x=y.components.filter(U=>U.isRegistered))}}}if(g&&a){h=ce(e,h),h=pe(e,h),e.appDir&&(h=Ln(e,h));let P=O(e,h);P=H(P),e.appDir&&(P=kn(P)),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return f}function Kn(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",vi(e,t))}function Ei(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function Di(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([Kn(e,t),...t.acceptsChildren?[Ei(e)]:[]],!0),t)}async function wi(e,t,r){let n=V(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<o.length;a++)if((await Vt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function Vn(e,t,r){if(e.appDir){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=n.externalImportPath?n.externalImportPath:I(e,e.registryPath,n.filePath);n.exportType==="default"?r=D(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=D(e,r,{namedImports:[n.importName],importPath:o}))}}else r=D(e,r,{defaultImport:"dynamic",importPath:"next/dynamic"});return r}function vi(e,t){let r=t.externalImportPath?t.externalImportPath:I(e,e.registryPath,t.filePath),n=t.exportName!=="default",o;n?o=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createAwaitExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)])),e.ts.factory.createIdentifier(t.exportName)):o=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)]);let i=e.ts.factory.createArrowFunction(n?[e.ts.factory.createModifier(e.ts.SyntaxKind.AsyncKeyword)]:void 0,void 0,[],void 0,e.ts.factory.createToken(e.ts.SyntaxKind.EqualsGreaterThanToken),o);return e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("dynamic"),void 0,[i])}async function $n(e){let t=[],r=await Ai(e,t);return await Jn(e,t,r),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await Ii(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await Ri(e,e.pagesDir,t)),t}async function Mn(e){let t=[];return await Jn(e,t),e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await bi(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await Ni(e,e.pagesDir,t)),t}async function bi(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"figma-imports",n);if(!await e.exists(o)){let i=await e.formatCode(o,zn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,Un(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}async function Ii(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"[...page]",n);if(!await e.exists(o)){let i=await e.formatCode(o,zn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,Un(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function Un(e){let t=e.typescriptEnabled;return e.sdkVersion===b.gen2?`
|
|
31
|
+
`}function jt(e,t){return t.sort((r,n)=>{let o=Ln(e,r),i=Ln(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function Ln(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 jn(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
|
|
32
|
+
${e}`),e}function Bn(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 le(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=_n(e,r),i=_n(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function _n(e,t){let r=t.properties.find(n=>I(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function Vn(e){let t=await e.readFile(e.registryPath);return t?hi(e,t):{components:[],sourceFile:v(e,"")}}async function hi(e,t){let r=v(e,t);return e.sdkVersion===D.gen2?Si(e,r):Ci(e,r)}async function Ci(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let l=i.arguments;if(l.length<2)continue;let d=l[1];if(!e.ts.isObjectLiteralExpression(d))continue;let u=l[0];if(e.ts.isCallExpression(u)){let c=e.ts.isIdentifier(u.expression)&&u.expression.text;if(c==="withChildren"){let x=Kt(e,u.arguments[0]);if(e.ts.isCallExpression(x)){let f=await Bt(e,n,x,d,!0);f&&r.push(f)}else{let f=x;if(e.ts.isIdentifier(f)){let g=await Vt(e,t,n,f,d,!0);g&&r.push(g)}}continue}if(c==="dynamic"){let x=await Bt(e,n,u,d,!1);x&&r.push(x);continue}let m=Kt(e,u.arguments[0]);if(e.ts.isCallExpression(m)&&e.ts.isIdentifier(m.expression)&&m.expression.text==="dynamic"){let x=await Bt(e,n,m,d,!1);x&&r.push(x);continue}if(e.ts.isIdentifier(m)){let x=await Vt(e,t,n,m,d,!1);x&&r.push(x);continue}continue}if(e.ts.isIdentifier(u)){let c=await Vt(e,t,n,u,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:J(r)}}function Kt(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:Kt(e,t.arguments[0]):t}async function Bt(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let p=s.body;if(e.ts.isCallExpression(p)){if(p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let d=p.arguments[0];if(!e.ts.isStringLiteral(d))return null;let u=d.text,c=await $e(e,u);i.filePath=c,i.relFilePath=e.relative(e.getRootDir(),i.filePath),await e.exists(c)?i.importPath=L(e,i.filePath):(i.externalImportPath=u,i.importPath=i.externalImportPath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(p)){let l=p.expression;if(!e.ts.isParenthesizedExpression(l))return null;let d=l.expression;if(!e.ts.isAwaitExpression(d))return null;let u=d.expression;if(!e.ts.isCallExpression(u)||u.expression.kind!==e.ts.SyntaxKind.ImportKeyword||u.arguments.length!==1)return null;let m=u.arguments[0];if(!e.ts.isStringLiteral(m)||!e.ts.isIdentifier(p.name))return null;let x=m.text,f=await $e(e,x);i.filePath=f,i.relFilePath=e.relative(e.getRootDir(),i.filePath),await e.exists(f)?i.importPath=L(e,i.filePath):(i.externalImportPath=x,i.importPath=i.externalImportPath),i.name=j(p.name.text),i.importName=p.name.text,i.exportName=p.name.text,i.exportType="named"}else return null;return i=Q(e,i,n),i.displayFilePath=A(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName,i.externalImportPath)),i}async function Vt(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(l=>e.ts.isImportDeclaration(l)),p=s.find(l=>l.importClause&&l.importClause.name?.text===n.text);if(p){let l=p.moduleSpecifier;if(!e.ts.isStringLiteral(l))return null;let d=await $e(e,l.text);a.filePath=d,a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(d)?a.importPath=L(e,a.filePath):(a.externalImportPath=l.text,a.importPath=a.externalImportPath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(m=>m.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let u=await $e(e,d.text);a.filePath=u,a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(u)?a.importPath=L(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=Q(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName,a.externalImportPath)),a}function $e(e,t){return He(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function Kn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let l=0;l<i.length;l++){let d=i[l];if(e.ts.isImportDeclaration(d)){o=l;continue}if(!e.ts.isExpressionStatement(d))continue;let u=d.expression;if(!e.ts.isCallExpression(u))continue;let c=u.expression;if(!e.ts.isPropertyAccessExpression(c))continue;let m=c.expression;if(!e.ts.isIdentifier(m)||m.text!=="builder")continue;if(c.name.text=="init"){n=!0;break}else continue}if(n)return t;let a=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("process"),e.ts.factory.createIdentifier("env")),e.ts.factory.createIdentifier(ie)),s=r?e.ts.factory.createNonNullExpression(a):a,p=e.ts.factory.createExpressionStatement(e.ts.factory.createCallExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("builder"),e.ts.factory.createIdentifier("init")),void 0,[s]));return i.splice(o+1,0,p),e.ts.factory.updateSourceFile(t,i)}async function Si(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await $t(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function $t(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};_e(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(I(e,i)==="component"){let s,{initializer:p}=i;if(e.ts.isCallExpression(p)&&(e.ts.isIdentifier(p.expression)&&p.expression.text)==="dynamic"){let m=p.arguments;if(m.length===0)return null;let x=m[0];if(!e.ts.isArrowFunction(x))return null;let f=x.body;if(e.ts.isCallExpression(f)){if(f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let h=f.arguments[0];if(!e.ts.isStringLiteral(h))return null;let C=h.text,P=await $e(e,C);n.filePath=P,n.relFilePath=e.relative(e.getRootDir(),n.filePath),await e.exists(P)?n.importPath=L(e,n.filePath):(n.externalImportPath=C,n.importPath=n.externalImportPath),n.name=Y(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(f)){let g=f.expression;if(!e.ts.isParenthesizedExpression(g))return null;let h=g.expression;if(!e.ts.isAwaitExpression(h))return null;let C=h.expression;if(!e.ts.isCallExpression(C)||C.expression.kind!==e.ts.SyntaxKind.ImportKeyword||C.arguments.length!==1)return null;let b=C.arguments[0];if(!e.ts.isStringLiteral(b)||!e.ts.isIdentifier(f.name))return null;let y=b.text,S=await $e(e,y);n.filePath=S,n.relFilePath=e.relative(e.getRootDir(),n.filePath),await e.exists(S)?n.importPath=L(e,n.filePath):(n.externalImportPath=y,n.importPath=n.externalImportPath),n.name=j(f.name.text),n.importName=f.name.text,n.exportName=f.name.text,n.exportType="named"}else return null;return n=Q(e,n,r),n.displayFilePath=A(e,n.filePath),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await ae(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,await e.exists(l.filePath)?n.importPath=L(e,l.filePath):(n.externalImportPath=l.importPath,n.importPath=n.externalImportPath),n.importPath=L(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),u=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(u){let c=u.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(x=>!x.importClause||!x.importClause.namedBindings||!e.ts.isNamedImports(x.importClause.namedBindings)?!1:x.importClause.namedBindings.elements.some(f=>f.name.text===s));if(!c)return null;let m=c.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;n.exportName=s}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}function ce(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 p=[...s.elements];for(let l=p.length-1;l>=0;l--){let d=p[l];if(e.ts.isImportSpecifier(d)){let u=d.name;if(u&&e.ts.isIdentifier(u)){let c=u.text;$n(e,t,c)||p.splice(l,1)}}}if(p.length===0)a=!0;else if(s.elements.length!==p.length){let l=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(p)),d=e.ts.factory.updateImportDeclaration(i,void 0,l,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let p=i.importClause.name.text;$n(e,t,p)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function $n(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 me(e,t,r,n,o,i,a){let s=null,p=null,l=null,d=-1;t=W(t),r=W(r);let u=t.find(m=>m.id===e),c=r.find(m=>m.id===e);if(n)c||(s={...W(u),inputs:W(u.inputs).map(m=>(m.isRegistered=!0,m))},d=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)d=c.nodeIndex,p=W(c),r=r.filter(m=>m.id!==e);else if(i!=null)Pi(c,i),d=c.nodeIndex,l=c;else if(a!=null){let m=c.inputs.find(x=>x.name===a.name);m&&(a.registerInput===!1?m.isRegistered=!1:(Ei(m,a),m.isRegistered=!0),l=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:p,updateRegisteredCmp:l,nodeIndex:d,components:te(t,r)}}function te(e,t){let r=J([...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(kt),n.inputs.sort((a,s)=>a.name.toLowerCase().localeCompare(s.name.toLowerCase()));let o=t.find(a=>a.id===n.id);o&&(o.acceptsChildren=Ot(n));let i=e.find(a=>a.id===n.id&&a.externalImportPath);i&&(n.filePath=i.filePath,n.relFilePath=i.relFilePath)}),r}function Pi(e,t){q(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),q(t.description)?e.description=t.description:t.description===null&&delete e.description,q(t.image)?e.image=t.image:t.image===null&&delete e.image}function Ei(e,t){q(t.type)&&(e.type=t.type),q(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,q(t.defaultValue)||Je(t.defaultValue)||ke(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,q(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 ve(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),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".jsx"||p===".ts"||p===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await M(e,[...t])}function ue(e,t,r){return Be(e,t,r.variableName)?t:Ti(e,t,r)}function Ti(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),p=e.ts.factory.createVariableStatement([s],a),l=[...t.statements,p];return e.ts.factory.updateSourceFile(t,l)}async function fe(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,u,c]=await Promise.all([kn(e,p),Vn(e),Mt(e),qe(e)]),m=l.map(P=>P.cmpInfo),x=d.components,f={components:te(m,x),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(m),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Ve(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let N=l.find(B=>B.cmpInfo.id===S);if(!N)throw new Error(`Component ${S} not found`);return N}),b=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),y=await M(e,b);for(let S of P){let N=f.components.find(T=>T.id===S.cmpInfo.id),B=await Ke(e,S,y);ee(N,B);let k=m.findIndex(T=>T.id===S.cmpInfo.id);m[k].inputs=B;let E=me(S.cmpInfo.id,m,x,r,n,o,i);if(e.sdkVersion===D.gen2){let{elements:T,elmIndex:U,statementIndex:X,statement:$,variableDeclaration:F}=await wi(e,h,S);if(E.addCmpToRegistry)T.push(yi(e,E.addCmpToRegistry)),g=!0;else if(E.removeCmpFromRegistry)T.splice(U,1),g=!0;else if(E.updateRegisteredCmp){let z=K(e,T[U],E.updateRegisteredCmp);T[U]=e.ts.factory.updateObjectLiteralExpression(z,[Un(e,E.updateRegisteredCmp),...z.properties.slice(1)]),g=!0}if(g&&a){let z=[...h.statements];z[X]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(F,F.name,F.exclamationToken,F.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),h=e.ts.factory.updateSourceFile(h,z),h=Mn(e,E,h),h=w(e,h,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),h=ue(e,h,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),f.components=E.components,x=E.components.filter(be=>be.isRegistered)}}else{let T=[...h.statements];E.addCmpToRegistry?(T.push(wn(e,E.addCmpToRegistry)),g=!0):E.removeCmpFromRegistry?(T.splice(E.nodeIndex,1),g=!0):E.updateRegisteredCmp&&(T[E.nodeIndex]=Lt(e,T[E.nodeIndex],E.updateRegisteredCmp),g=!0),g&&a&&(h=e.ts.factory.updateSourceFile(h,T),h=w(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=Kn(e,h,u),h=Mn(e,E,h),N?.acceptsChildren&&(h=w(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=E.components,x=E.components.filter(U=>U.isRegistered))}}}if(g&&a){h=ce(e,h),h=pe(e,h),e.appDir&&(h=Bn(e,h));let P=O(e,h);P=H(P),e.appDir&&(P=jn(P)),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return f}function Un(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",vi(e,t))}function Di(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function yi(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([Un(e,t),...t.acceptsChildren?[Di(e)]:[]],!0),t)}async function wi(e,t,r){let n=V(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<o.length;a++)if((await $t(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function Mn(e,t,r){if(e.appDir){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=n.externalImportPath?n.externalImportPath:R(e,e.registryPath,n.filePath);n.exportType==="default"?r=w(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=w(e,r,{namedImports:[n.importName],importPath:o}))}}else r=w(e,r,{defaultImport:"dynamic",importPath:"next/dynamic"});return r}function vi(e,t){let r=t.externalImportPath?t.externalImportPath:R(e,e.registryPath,t.filePath),n=t.exportName!=="default",o;n?o=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createAwaitExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)])),e.ts.factory.createIdentifier(t.exportName)):o=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)]);let i=e.ts.factory.createArrowFunction(n?[e.ts.factory.createModifier(e.ts.SyntaxKind.AsyncKeyword)]:void 0,void 0,[],void 0,e.ts.factory.createToken(e.ts.SyntaxKind.EqualsGreaterThanToken),o);return e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("dynamic"),void 0,[i])}async function zn(e){let t=[],r=await Ai(e,t);return await Yn(e,t,r),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await bi(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await Ri(e,e.pagesDir,t)),t}async function qn(e){let t=[];return await Yn(e,t),e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await Ii(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await Ni(e,e.pagesDir,t)),t}async function Ii(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"figma-imports",n);if(!await e.exists(o)){let i=await e.formatCode(o,Qn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,Jn(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}async function bi(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"[...page]",n);if(!await e.exists(o)){let i=await e.formatCode(o,Qn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,Jn(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function Jn(e){let t=e.typescriptEnabled;return e.sdkVersion===D.gen2?`
|
|
33
33
|
"use client";
|
|
34
34
|
import { ${t?"BuilderContent, ":""} isPreviewing, Content } from "@builder.io/sdk-react";
|
|
35
35
|
import DefaultErrorPage from "next/error";
|
|
36
|
-
import { CUSTOM_COMPONENTS } from ${JSON.stringify(
|
|
36
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(R(e,e.builderComponentPath,e.registryPath))};
|
|
37
37
|
${t?`
|
|
38
38
|
interface BuilderPageProps {
|
|
39
39
|
content: BuilderContent | null;
|
|
@@ -67,7 +67,7 @@ ${t?'import { ComponentProps } from "react";':""}
|
|
|
67
67
|
import { BuilderComponent, useIsPreviewing } from "@builder.io/react";
|
|
68
68
|
import { ${t?"BuilderContent, ":""}builder } from '@builder.io/sdk';
|
|
69
69
|
import DefaultErrorPage from "next/error";
|
|
70
|
-
import ${JSON.stringify(
|
|
70
|
+
import ${JSON.stringify(R(e,e.builderComponentPath,e.registryPath))};
|
|
71
71
|
${t?`
|
|
72
72
|
type BuilderPageProps = ComponentProps<typeof BuilderComponent>;`:""}
|
|
73
73
|
|
|
@@ -88,7 +88,7 @@ export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":
|
|
|
88
88
|
// DefaultErrorPage with a 404.
|
|
89
89
|
return <DefaultErrorPage statusCode={404} />;
|
|
90
90
|
}
|
|
91
|
-
`.trimStart()}function
|
|
91
|
+
`.trimStart()}function Qn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=R(e,t,e.builderComponentPath);return e.sdkVersion===D.gen2?`
|
|
92
92
|
import { fetchOneEntry } from "@builder.io/sdk-react";
|
|
93
93
|
import { RenderBuilderContent } from ${JSON.stringify(o)};
|
|
94
94
|
|
|
@@ -156,7 +156,7 @@ export default async function Page(props${n?": PageProps":""}) {
|
|
|
156
156
|
</>
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
|
-
`.trimStart()}async function Ri(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,
|
|
159
|
+
`.trimStart()}async function Ri(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,Wn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function Ni(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,Wn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function Wn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return e.sdkVersion===D.gen2?`
|
|
160
160
|
import React from "react";
|
|
161
161
|
import { useRouter } from "next/router";
|
|
162
162
|
${n?'import type { BuilderContent } from "@builder.io/sdk-react";':""}
|
|
@@ -169,7 +169,7 @@ import {
|
|
|
169
169
|
import DefaultErrorPage from "next/error";
|
|
170
170
|
import Head from "next/head";
|
|
171
171
|
${n?'import { GetStaticProps } from "next";':""}
|
|
172
|
-
import { CUSTOM_COMPONENTS } from ${JSON.stringify(
|
|
172
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(R(e,e.builderComponentPath,e.registryPath))};
|
|
173
173
|
|
|
174
174
|
const BUILDER_API_KEY = process.env.${ie}${n?"!":""};
|
|
175
175
|
|
|
@@ -252,7 +252,7 @@ import DefaultErrorPage from "next/error";
|
|
|
252
252
|
import Head from "next/head";${n?`
|
|
253
253
|
import { BuilderContent } from "@builder.io/sdk";`:""}${n?`
|
|
254
254
|
import { GetStaticProps } from "next";`:""}
|
|
255
|
-
import ${JSON.stringify(
|
|
255
|
+
import ${JSON.stringify(R(e,t,e.registryPath))};
|
|
256
256
|
|
|
257
257
|
builder.init(process.env.${ie}${n?"!":""});
|
|
258
258
|
|
|
@@ -381,18 +381,67 @@ export default Counter;
|
|
|
381
381
|
font-size: 42px;
|
|
382
382
|
text-align: center;
|
|
383
383
|
}
|
|
384
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
384
|
+
`.trimStart();return{component:r,styles:n}}async function Yn(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===D.gen2){let i=Oi(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 Oi(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-react";
|
|
385
385
|
|
|
386
386
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
387
387
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
388
388
|
];
|
|
389
|
-
`}async function
|
|
389
|
+
`}async function Me(e){let t=await ct(e,e.getRootDir());if(t&&typeof t=="object"){let r=new Set(Object.keys({...t.dependencies,...t.devDependencies}));if(r.has("@builder.io/sdk-react"))return D.gen2;if(r.has("@builder.io/react"))return D.gen1}return null}async function Gn(e){let t=await ki(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>zn(t),ensureFigmaImportPage:()=>qn(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:()=>qe(t),setPublicApiKey:n=>Cn(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===D.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:()=>re(t),setCache:n=>oe(t,n)}}async function ki(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await Li(e),o=await Mt(e),i=`builder-registry.${o?"ts":"js"}`,a={},s={...e,addExternalPackage:p=>{a[e.join(t,p,"index.ts")]=`export * from "${p}";`},readFileSync:p=>a[p]??e.readFileSync(p),existsSync:p=>!!a[p]||e.existsSync(p),readdirSync:p=>{let l=e.readdirSync(p);return p===t?[...l,...Object.keys(a).map(d=>d.slice(t.length+1))]:l},readdir:async p=>{let l=await e.readdir(p);return p===t?[...l,...Object.keys(a).map(d=>d.slice(t.length+1))]:l},appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(e.sdkVersion?s.sdkVersion=e.sdkVersion:s.sdkVersion=await Me(s),await e.exists(r)){s.srcDir=r,s.componentsDir=e.join(r,"components");let p=e.join(r,"app");await e.exists(p)&&(s.appDir=p);let l=e.join(r,"pages");await e.exists(l)&&(s.pagesDir=l),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 p=e.join(t,"app");await e.exists(p)&&(s.appDir=p)}if(!s.pagesDir){let p=e.join(t,"pages");await e.exists(p)&&(s.pagesDir=p)}if(!s.appDir&&!s.pagesDir)throw new Error(`Could not find Next.js "app" or "pages" directory. Searched in "${t}".`);return s}function Mt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Li(e){let t=e.join(e.getRootDir(),"next.config.ts");if(await e.exists(t))return t;let r=e.join(e.getRootDir(),"next.config.mjs");if(await e.exists(r))return r;let n=e.join(e.getRootDir(),"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.getRootDir()}".`)}async function Ze(e){return await Te(e,[".env"],Xn)}async function Hn(e,t){_i(t);let r=await Ze(e),n=await De(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function _i(e){typeof process<"u"&&(process.env[Xn]=e)}var Xn="PUBLIC_BUILDER_API_KEY";function Zn(e,t,r){if(r.length===0)return e;let n=e.split(`
|
|
390
390
|
`),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(`
|
|
391
|
-
`)}async function
|
|
391
|
+
`)}async function tr(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(".")||Vi.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let p=await xt(e,o,s,i);r.push(...p)})),r}async function nr(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return ji(e,t,n)}return null}function ji(e,t,r){let n=v(e,r);return xt(e,null,t,n)}async function xt(e,t,r,n){r=e.normalize(r);let o=[],i=G(e,n);return await Promise.all(i.map(async a=>{let s=await Bi(e,t,r,a);s&&o.push(s)})),o}async function Bi(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=L(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=er(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let p=a.name.text;return{cmpInfo:{id:await _(e,r,p),displayFilePath:A(e,r),name:j(p),inputs:[],exportName:n.isDefaultExport?"default":p,exportType:n.isDefaultExport?"default":"named",importName:p,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=er(e,n.node);if(a)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:A(e,r),name:Y(e,r),inputs:[],exportName:"default",exportType:"default",importName:Re(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function er(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 Vi=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function rr(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 je(e,t.cmpInfo.filePath,null);if(!(await xt(e,i,t.cmpInfo.filePath,o)).find(p=>p.cmpInfo.id===t.cmpInfo.id))throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return Ne(e,i,r)}return[]}async function or(e){return Ut(e)}async function Ut(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Ki),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var Ki=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
|
|
392
392
|
|
|
393
393
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
394
394
|
];
|
|
395
|
-
`;async function nr(e){await $t(e);let t=await e.readFile(e.registryPath);return t?$i(e,t):{components:[],sourceFile:w(e,"")}}async function $i(e,t){let r=w(e,t);return Mi(e,r)}async function Mi(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Mt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Mt(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(v(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await ae(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=L(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let p=await Zn(e,s.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let l=p.find(d=>d.cmpInfo.exportName===a);l&&(n.exportName=l.cmpInfo.exportName)}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function rr(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),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await M(e,[...t])}async function Ne(e,t,r,n,o,i,a,s){let p=await rr(e),[l,d,m]=await Promise.all([Xn(e,p),nr(e),Xe(e)]),c=l.map(f=>f.cmpInfo),u=d.components,x={components:te(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return x;if(t!=null){let f=l.find(y=>y.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let g=d.sourceFile,h=x.components.find(y=>y.id===t),C=await er(e,f);ee(h,C),t=Array.isArray(t)?t[0]:t;let P=me(t,c,u,r,n,o,i),{elements:R,elmIndex:E,statementIndex:S,statement:N,variableDeclaration:B}=await zi(e,g,f),k=!1;if(P.addCmpToRegistry?(R.push(Ui(e,P.addCmpToRegistry)),k=!0):P.removeCmpFromRegistry?(R.splice(E,1),k=!0):P.updateRegisteredCmp&&(R[E]=K(e,R[E],P.updateRegisteredCmp),k=!0),k&&a){let y=[...g.statements];y[S]=e.ts.factory.updateVariableStatement(N,N.modifiers,e.ts.factory.updateVariableDeclarationList(N.declarationList,[e.ts.factory.updateVariableDeclaration(B,B.name,B.exclamationToken,B.type,e.ts.factory.createArrayLiteralExpression(le(e,R)))])),g=e.ts.factory.updateSourceFile(g,y),h.exportType==="named"?g=D(e,g,{namedImports:[h.importName],importPath:I(e,e.registryPath,h.filePath)}):g=D(e,g,{defaultImport:h.importName,importPath:I(e,e.registryPath,h.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=ce(e,g),g=pe(e,g);let T=O(e,g);T=H(T),T=Gn(T,qi,"CUSTOM_COMPONENTS"),T=await e.formatCode(e.registryPath,T),await e.writeFile(e.registryPath,T)}x.components=P.components}return x}function Ui(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function zi(e,t,r){let n=V(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<o.length;a++)if((await Mt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var qi=["This array is used to integrate custom components within Builder.","https://www.builder.io/c/docs/custom-components-intro","",'These components will be found the "Custom Components"',"section of Builder's visual editor.",'You can also turn on "components only mode" to limit',"editing to only these components.","https://www.builder.io/c/docs/guides/components-only-mode"];async function or(e){let t=await Ji(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>tr(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ne(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:async n=>{},loadComponent:async n=>{let o=await Ne(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ne(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ne(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ne(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ne(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Xe(t),setPublicApiKey:n=>Wn(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function Ji(e){let t=await Ue(e,e.getRootDir(),"components");if(!t)throw new Error(`Could not find components directory within project: ${e.getRootDir()}`);let r=e.join(t,"builder-registry.ts"),n=e.join(e.getRootDir(),".env");return{...e,componentsDir:t,registryPath:r,envPath:n}}async function Ze(e){return await Te(e,[".env"],et)}async function ir(e,t){let r=await Ze(e),n=await Ee(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var et="PUBLIC_BUILDER_KEY";async function ar(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker(),i=e.join(e.getRootDir(),"build");return await Promise.all(n.map(async a=>{let s=e.basename(a.fileName);if(s.startsWith(".")||s==="node_modules"||Qi.has(s)||s.includes("$."))return;let p=e.normalize(a.fileName);if(p===e.remixConfigPath||p===e.registryPath||p===i)return;let l=await we(e,o,p,a);r.push(...l)})),r}var Qi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function sr(e){await gt(e);let t=await e.readFile(e.registryPath);return t?Wi(e,t):{components:[],sourceFile:w(e,"")}}async function Wi(e,t){let r=w(e,t);return Yi(e,r)}async function Yi(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Ut(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Ut(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(v(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 m=s.arguments[0];e.ts.isIdentifier(m)&&(a=m.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await ae(e,e.registryPath,t,a);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,n.importPath=L(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await In(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(m=>m.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function de(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,m]=await Promise.all([ar(e,p),sr(e),Ze(e)]),c=l.map(C=>C.cmpInfo),u=d.components,x={components:te(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await je(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(E=>{let S=l.find(N=>N.cmpInfo.id===E);if(!S)throw new Error(`Component ${E} not found`);return S}),P=Array.from(new Set(C.map(E=>E.cmpInfo.filePath))),R=await M(e,P);for(let E of C){let S=x.components.find(F=>F.id===E.cmpInfo.id),N=await Be(e,E,R);ee(S,N);let B=c.findIndex(F=>F.id===E.cmpInfo.id);c[B].inputs=N;let k=me(E.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:T,statementIndex:U,statement:X,variableDeclaration:$}=await Hi(e,g,E);if(k.addCmpToRegistry)y.push(Gi(e,k.addCmpToRegistry)),f=!0;else if(k.removeCmpFromRegistry)y.splice(T,1),f=!0;else if(k.updateRegisteredCmp){let F=K(e,y[T],k.updateRegisteredCmp);y[T]=e.ts.factory.updateObjectLiteralExpression(F,[pr(e,k.updateRegisteredCmp),...F.properties.slice(1)]),f=!0}if(f&&a){let F=[...g.statements];F[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration($,$.name,$.exclamationToken,$.type,e.ts.factory.createArrayLiteralExpression(le(e,y)))])),g=e.ts.factory.updateSourceFile(g,F),S.exportType==="named"?g=D(e,g,{namedImports:[S.importName],importPath:I(e,e.registryPath,S.filePath)}):g=D(e,g,{defaultImport:S.importName,importPath:I(e,e.registryPath,S.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),S.acceptsChildren&&(g=D(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=k.components,u=k.components.filter(z=>z.isRegistered)}}}if(f&&a){g=ce(e,g),g=pe(e,g);let C=O(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function pr(e,t){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 Gi(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([pr(e,t)],!0),t)}async function Hi(e,t,r){let n=V(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<o.length;a++)if((await Ut(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function lr(e){let t=[],r=await ea(e,t);return t.push(...await gt(e)),await na(e,r),await Zi(e,t),t}async function cr(e){let t=[];return t.push(...await gt(e)),await Xi(e,t),t}async function Xi(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,mr({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Zi(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,mr({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function mr({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=I(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${et}`;return e.getFrameworks().some(p=>p.name==="@shopify/remix-oxygen")&&(s=`context.env.${et}`),n&&(s+="!"),`
|
|
395
|
+
`;async function ir(e){await Ut(e);let t=await e.readFile(e.registryPath);return t?$i(e,t):{components:[],sourceFile:v(e,"")}}async function $i(e,t){let r=v(e,t);return Mi(e,r)}async function Mi(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await zt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function zt(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(I(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await ae(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=L(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let p=await nr(e,s.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let l=p.find(d=>d.cmpInfo.exportName===a);l&&(n.exportName=l.cmpInfo.exportName)}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function ar(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),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await M(e,[...t])}async function Ae(e,t,r,n,o,i,a,s){let p=await ar(e),[l,d,u]=await Promise.all([tr(e,p),ir(e),Ze(e)]),c=l.map(f=>f.cmpInfo),m=d.components,x={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x;if(t!=null){let f=l.find(E=>E.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let g=d.sourceFile,h=x.components.find(E=>E.id===t),C=await rr(e,f);ee(h,C),t=Array.isArray(t)?t[0]:t;let P=me(t,c,m,r,n,o,i),{elements:b,elmIndex:y,statementIndex:S,statement:N,variableDeclaration:B}=await zi(e,g,f),k=!1;if(P.addCmpToRegistry?(b.push(Ui(e,P.addCmpToRegistry)),k=!0):P.removeCmpFromRegistry?(b.splice(y,1),k=!0):P.updateRegisteredCmp&&(b[y]=K(e,b[y],P.updateRegisteredCmp),k=!0),k&&a){let E=[...g.statements];E[S]=e.ts.factory.updateVariableStatement(N,N.modifiers,e.ts.factory.updateVariableDeclarationList(N.declarationList,[e.ts.factory.updateVariableDeclaration(B,B.name,B.exclamationToken,B.type,e.ts.factory.createArrayLiteralExpression(le(e,b)))])),g=e.ts.factory.updateSourceFile(g,E),h.exportType==="named"?g=w(e,g,{namedImports:[h.importName],importPath:R(e,e.registryPath,h.filePath)}):g=w(e,g,{defaultImport:h.importName,importPath:R(e,e.registryPath,h.filePath)}),g=w(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=ce(e,g),g=pe(e,g);let T=O(e,g);T=H(T),T=Zn(T,qi,"CUSTOM_COMPONENTS"),T=await e.formatCode(e.registryPath,T),await e.writeFile(e.registryPath,T)}x.components=P.components}return x}function Ui(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function zi(e,t,r){let n=V(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<o.length;a++)if((await zt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var qi=["This array is used to integrate custom components within Builder.","https://www.builder.io/c/docs/custom-components-intro","",'These components will be found the "Custom Components"',"section of Builder's visual editor.",'You can also turn on "components only mode" to limit',"editing to only these components.","https://www.builder.io/c/docs/guides/components-only-mode"];async function sr(e){let t=await Ji(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>or(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ae(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:async n=>{},loadComponent:async n=>{let o=await Ae(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ae(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ae(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ae(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ae(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ze(t),setPublicApiKey:n=>Hn(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function Ji(e){let t=await ze(e,e.getRootDir(),"components");if(!t)throw new Error(`Could not find components directory within project: ${e.getRootDir()}`);let r=e.join(t,"builder-registry.ts"),n=e.join(e.getRootDir(),".env");return{...e,componentsDir:t,registryPath:r,envPath:n}}async function et(e){return await Te(e,[".env"],tt)}async function pr(e,t){let r=await et(e),n=await De(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var tt="PUBLIC_BUILDER_KEY";var Qi=new Set(["dist","node_modules"]);async function lr(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker(),i=e.join(e.getRootDir(),"build");return await Promise.all(n.map(async a=>{let s=e.basename(a.fileName);if(s.startsWith(".")||s==="node_modules"||ut(e,Qi,a.fileName)||Wi.has(s)||s.includes("$."))return;let p=e.normalize(a.fileName);if(p===e.remixConfigPath||p===e.registryPath||p===i)return;let l=await we(e,o,p,a);r.push(...l)})),r}var Wi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function cr(e){await ht(e);let t=await e.readFile(e.registryPath);return t?Yi(e,t):{components:[],sourceFile:v(e,"")}}async function Yi(e,t){let r=v(e,t);return Gi(e,r)}async function Gi(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await qt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function qt(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===D.gen2&&_e(e,r)&&(n.acceptsChildren=!0);for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(I(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=j(a)),n.importName=a;let p=await ae(e,e.registryPath,t,a);if(!p)continue;if(n.filePath=p.filePath,n.relFilePath=p.relFilePath,await e.exists(p.filePath)?n.importPath=L(e,p.filePath):(n.externalImportPath=p.importPath,n.importPath=n.externalImportPath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType,n.externalImportPath)n.exportName=a;else{let l=await An(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(u=>u.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}async function de(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,u]=await Promise.all([lr(e,p),cr(e),et(e)]),c=l.map(C=>C.cmpInfo),m=d.components,x={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await Ve(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(y=>{let S=l.find(N=>N.cmpInfo.id===y);if(!S)throw new Error(`Component ${y} not found`);return S}),P=Array.from(new Set(C.map(y=>y.cmpInfo.filePath))),b=await M(e,P);for(let y of C){let S=x.components.find(F=>F.id===y.cmpInfo.id),N=await Ke(e,y,b);ee(S,N);let B=c.findIndex(F=>F.id===y.cmpInfo.id);c[B].inputs=N;let k=me(y.cmpInfo.id,c,m,r,n,o,i),{elements:E,elmIndex:T,statementIndex:U,statement:X,variableDeclaration:$}=await Xi(e,g,y);if(k.addCmpToRegistry)E.push(Hi(e,k.addCmpToRegistry)),f=!0;else if(k.removeCmpFromRegistry)E.splice(T,1),f=!0;else if(k.updateRegisteredCmp){let F=K(e,E[T],k.updateRegisteredCmp);E[T]=e.ts.factory.updateObjectLiteralExpression(F,[mr(e,k.updateRegisteredCmp),...F.properties.slice(1)]),f=!0}if(f&&a){let F=[...g.statements];F[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration($,$.name,$.exclamationToken,$.type,e.ts.factory.createArrayLiteralExpression(le(e,E)))])),g=e.ts.factory.updateSourceFile(g,F),S.exportType==="named"?g=w(e,g,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)}):g=w(e,g,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)});let z=e.sdkVersion===D.gen2?"@builder.io/sdk-react":"@builder.io/react";g=w(e,g,{namedImports:["RegisteredComponent"],importPath:z,isTypeOnly:!0}),S.acceptsChildren&&e.sdkVersion!==D.gen2&&(g=w(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=k.components,m=k.components.filter(be=>be.isRegistered)}}}if(f&&a){g=ce(e,g),g=pe(e,g);let C=O(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function mr(e,t){if(e.sdkVersion===D.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 Hi(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([mr(e,t),...t.acceptsChildren&&e.sdkVersion===D.gen2?[e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())]:[]],!0),t)}async function Xi(e,t,r){let n=V(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<o.length;a++)if((await qt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function ur(e){let t=[],r=await ta(e,t);return t.push(...await ht(e)),await ra(e,r),await ea(e,t),t}async function fr(e){let t=[];return t.push(...await ht(e)),await Zi(e,t),t}async function Zi(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,dr({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function ea(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`),e.sdkVersion===D.gen2&&(r=`($slug)._index.${e.typescriptEnabled?"tsx":"jsx"}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,dr({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function dr({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=R(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${tt}`;return e.getFrameworks().some(p=>p.name==="@shopify/remix-oxygen")&&(s=`context.env.${tt}`),n&&(s+="!"),e.sdkVersion===D.gen2?`
|
|
396
|
+
|
|
397
|
+
import {
|
|
398
|
+
Content,
|
|
399
|
+
fetchOneEntry,
|
|
400
|
+
getBuilderSearchParams,
|
|
401
|
+
isPreviewing,
|
|
402
|
+
} from "@builder.io/sdk-react";
|
|
403
|
+
${n?'import type { LoaderFunctionArgs } from "@remix-run/node";':""}
|
|
404
|
+
import { useLoaderData } from "@remix-run/react";
|
|
405
|
+
import { fetch ${n?"as webFetch":""}} from "@remix-run/web-fetch";
|
|
406
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
|
|
407
|
+
|
|
408
|
+
export const loader = async ({ params, request }${n?": LoaderFunctionArgs":""}) => {
|
|
409
|
+
const builderApiKey = ${s};
|
|
410
|
+
const url = new URL(request.url);
|
|
411
|
+
const urlPath = \`/\${params["slug"] || ""}\`;
|
|
412
|
+
|
|
413
|
+
const page = await fetchOneEntry({
|
|
414
|
+
model: "${r}",
|
|
415
|
+
apiKey: builderApiKey,
|
|
416
|
+
options: getBuilderSearchParams(url.searchParams),
|
|
417
|
+
userAttributes: { urlPath },
|
|
418
|
+
fetch: webFetch,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
if (!page && !isPreviewing(url.search)) {
|
|
422
|
+
throw new Response("Page Not Found", {
|
|
423
|
+
status: 404,
|
|
424
|
+
statusText: "Page not found in Builder.io",
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return { page, builderApiKey };
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// Define and render the page.
|
|
432
|
+
export default function Page() {
|
|
433
|
+
const { page, builderApiKey } = useLoaderData${n?"<typeof loader>":""}();
|
|
434
|
+
// Render the page content from Builder.io
|
|
435
|
+
return (
|
|
436
|
+
<Content
|
|
437
|
+
model="${r}"
|
|
438
|
+
apiKey={builderApiKey}
|
|
439
|
+
content={page}
|
|
440
|
+
customComponents={CUSTOM_COMPONENTS}
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
`:`
|
|
396
445
|
import { BuilderComponent, builder } from "@builder.io/react";
|
|
397
446
|
import { useLoaderData } from "@remix-run/react";
|
|
398
447
|
import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
|
|
@@ -449,11 +498,11 @@ export default function Page() {
|
|
|
449
498
|
${n?`
|
|
450
499
|
declare global {
|
|
451
500
|
interface Env {
|
|
452
|
-
${
|
|
501
|
+
${tt}: string;
|
|
453
502
|
}
|
|
454
503
|
}
|
|
455
504
|
`:""}
|
|
456
|
-
`}async function
|
|
505
|
+
`}async function ta(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:p}=na(e),l=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${l}`),!l){let u=await e.formatCode(i,s);await e.writeFile(i,u),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,p),t.push({filePath:a,modifiedType:"create"})),i}function na(e){let t=e.typescriptEnabled,r=`
|
|
457
506
|
import { useState } from "react";
|
|
458
507
|
import styles from "./styles.module.css";
|
|
459
508
|
${t?`
|
|
@@ -516,17 +565,17 @@ export default Counter;
|
|
|
516
565
|
font-size: 42px;
|
|
517
566
|
text-align: center;
|
|
518
567
|
}
|
|
519
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
568
|
+
`.trimStart();return{component:r,styles:n}}async function ra(e,t){let n=(await de(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await de(e,n.id,!0,!1,null,null,!0,!1)}async function ht(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,oa(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function oa(e){let t=e.sdkVersion===D.gen2;return e.typescriptEnabled?`import type { RegisteredComponent } from ${t?'"@builder.io/sdk-react"':'"@builder.io/react"'};
|
|
520
569
|
|
|
521
570
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
522
571
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
523
572
|
];
|
|
524
|
-
`}async function
|
|
573
|
+
`}async function gr(e){let t=await ia(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:()=>ur(t),ensureFigmaImportPage:()=>fr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>de(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await de(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>de(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>de(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>de(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>de(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>et(t),setPublicApiKey:n=>pr(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===D.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:()=>re(t),setCache:n=>oe(t,n)}}async function ia(e){let t=await pa(e),r=e.getRootDir(),n=await la(e),o=e.dirname(n),i=e.join(o,"components"),a=await aa(e),s=`builder-registry.${a?"ts":"js"}`,p=e.join(o,s),l={},d={...e,registryPath:p,remixConfigPath:t,typescriptEnabled:a,appDir:o,componentsDir:i,routesDir:n,hasLocaleParam:await sa(e,n),addExternalPackage:u=>{l[e.join(r,u,"index.ts")]=`export * from "${u}";`},readFileSync:u=>l[u]??e.readFileSync(u),existsSync:u=>!!l[u]||e.existsSync(u),readdirSync:u=>{let c=e.readdirSync(u);return u===r?[...c,...Object.keys(l).map(m=>m.slice(r.length+1))]:c},readdir:async u=>{let c=await e.readdir(u);return u===r?[...c,...Object.keys(l).map(m=>m.slice(r.length+1))]:c}};return e.sdkVersion?d.sdkVersion=e.sdkVersion:d.sdkVersion=await Me(d),d}function aa(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function sa(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function pa(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.getRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find Remix config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}async function la(e){let t=await ze(e,e.getRootDir(),"routes");if(t)return t;throw new Error(`Could not find Remix "routes" directory in "${e.getRootDir()}". Please ensure this command is ran from within your Remix project's directory.`)}async function nt(e){let t=[".env"],r=e.configType==="vite"?rt:Ct;return await Te(e,t,r)}async function xr(e,t){let r=await nt(e),n=await De(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var rt="VITE_PUBLIC_BUILDER_KEY",Ct="YOUR_PUBLIC_BUILDER_KEY";function hr(e,t){let r=`Builder.registerComponent(
|
|
525
574
|
`;r+=` ${t.importName},
|
|
526
575
|
`,r+=` {
|
|
527
576
|
name: "${t.name}",
|
|
528
577
|
}
|
|
529
|
-
`,r+=");";let n=
|
|
578
|
+
`,r+=");";let n=mt(e,r);return Jt(e,n,t)}function Jt(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]=K(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function Cr(e){let t=await e.readFile(e.registryPath);return t?ca(e,t):{components:[],sourceFile:v(e,"")}}async function ca(e,t){let r=v(e,t);return e.sdkVersion===D.gen2?fa(e,r):ma(e,r)}async function ma(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let l=i.arguments;if(l.length<2)continue;let d=l[1];if(!e.ts.isObjectLiteralExpression(d))continue;let u=l[0];if(e.ts.isIdentifier(u)){let c=await ua(e,t,n,u,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:J(r)}}async function ua(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(l=>e.ts.isImportDeclaration(l)),p=s.find(l=>l.importClause&&l.importClause.name?.text===n.text);if(p){let l=p.moduleSpecifier;if(!e.ts.isStringLiteral(l))return null;a.filePath=await Qt(e,l.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=L(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(m=>m.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let u=await Qt(e,d.text);a.filePath=await Qt(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(u)?a.importPath=L(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=Q(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName,a.externalImportPath)),a}function Qt(e,t){return He(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function fa(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Wt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Wt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};_e(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(I(e,i)==="component"){let s,{initializer:p}=i;if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await ae(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,await e.exists(l.filePath)?n.importPath=L(e,l.filePath):(n.externalImportPath=l.importPath,n.importPath=n.externalImportPath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),u=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(u){let c=u.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(x=>!x.importClause||!x.importClause.namedBindings||!e.ts.isNamedImports(x.importClause.namedBindings)?!1:x.importClause.namedBindings.elements.some(f=>f.name.text===s));if(!c)return null;let m=c.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;n.exportName=s}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ge(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,u,c]=await Promise.all([Fn(e,p),Cr(e),Yt(e),nt(e)]),m=l.map(P=>P.cmpInfo),x=d.components,f={components:te(m,x),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(m),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Ve(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let N=l.find(B=>B.cmpInfo.id===S);if(!N)throw new Error(`Component ${S} not found`);return N}),b=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),y=await M(e,b);for(let S of P){let N=f.components.find(T=>T.id===S.cmpInfo.id),B=await Ke(e,S,y);ee(N,B);let k=m.findIndex(T=>T.id===S.cmpInfo.id);m[k].inputs=B;let E=me(S.cmpInfo.id,m,x,r,n,o,i);if(e.sdkVersion===D.gen2){let{elements:T,elmIndex:U,statementIndex:X,statement:$,variableDeclaration:F}=await da(e,h,S);if(E.addCmpToRegistry)T.push(ga(e,E.addCmpToRegistry)),g=!0;else if(E.removeCmpFromRegistry)T.splice(U,1),g=!0;else if(E.updateRegisteredCmp){let z=K(e,T[U],E.updateRegisteredCmp),be=e.ts.factory.createIdentifier(E.updateRegisteredCmp.importName);T[U]=e.ts.factory.updateObjectLiteralExpression(z,[e.ts.factory.createPropertyAssignment("component",be),...z.properties.slice(1)]),g=!0}if(g&&a){let z=[...h.statements];z[X]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(F,F.name,F.exclamationToken,F.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),h=e.ts.factory.updateSourceFile(h,z),h=Sr(e,E,h),h=w(e,h,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),h=ue(e,h,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),f.components=E.components,x=E.components.filter(be=>be.isRegistered)}}else{let T=[...h.statements];E.addCmpToRegistry?(T.push(hr(e,E.addCmpToRegistry)),g=!0):E.removeCmpFromRegistry?(T.splice(E.nodeIndex,1),g=!0):E.updateRegisteredCmp&&(T[E.nodeIndex]=Jt(e,T[E.nodeIndex],E.updateRegisteredCmp),g=!0),g&&a&&(h=e.ts.factory.updateSourceFile(h,T),h=w(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=Sr(e,E,h),N?.acceptsChildren&&(h=w(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=E.components,x=E.components.filter(U=>U.isRegistered))}}}if(g&&a){h=ce(e,h),h=pe(e,h);let P=O(e,h);P=H(P),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return f}async function da(e,t,r){let n=V(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<o.length;a++)if((await Wt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function ga(e,t){let r=e.ts.factory.createIdentifier(t.importName);return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",r),...t.acceptsChildren?[e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())]:[]],!0),t)}function Sr(e,t,r){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=n.externalImportPath?n.externalImportPath:R(e,e.registryPath,n.filePath);n.exportType==="default"?r=w(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=w(e,r,{namedImports:[n.importName],importPath:o}))}return r}async function Pr(e){let t=[],r=await xa(e,t);if(await Dr(e,t,r),!await e.exists(e.builderComponentPath)){let n=await e.formatCode(e.builderComponentPath,Tr(e,e.builderComponentPath));await e.writeFile(e.builderComponentPath,n),t.push({filePath:e.builderComponentPath,modifiedType:"create"})}return t}async function Er(e){let t=[];await Dr(e,t);let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`,n=e.join(e.componentsDir,r);if(!await e.exists(n)){let o=await e.formatCode(n,Tr(e,n,"figma-imports"));await e.writeFile(n,o),t.push({filePath:n,modifiedType:"create"})}return t}function Tr(e,t,r="page"){let n=e.typescriptEnabled;return e.sdkVersion===D.gen2?`
|
|
530
579
|
import React from "react";
|
|
531
580
|
import {
|
|
532
581
|
Content,
|
|
@@ -535,10 +584,10 @@ export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
|
535
584
|
isPreviewing,
|
|
536
585
|
${n?"type BuilderContent,":""}
|
|
537
586
|
} from "@builder.io/sdk-react";
|
|
538
|
-
import { CUSTOM_COMPONENTS } from ${JSON.stringify(
|
|
587
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(R(e,t,e.registryPath))};
|
|
539
588
|
|
|
540
589
|
// Builder Public API Key set in .env file
|
|
541
|
-
const BUILDER_API_KEY = ${e.configType==="vite"?`import.meta.env.${
|
|
590
|
+
const BUILDER_API_KEY = ${e.configType==="vite"?`import.meta.env.${rt};`:`${Ct};`}
|
|
542
591
|
const MODEL_NAME = "${r}";
|
|
543
592
|
|
|
544
593
|
export default function BuilderPage() {
|
|
@@ -588,10 +637,10 @@ export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
|
588
637
|
`:`
|
|
589
638
|
import React from "react";
|
|
590
639
|
import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
|
|
591
|
-
import ${JSON.stringify(
|
|
640
|
+
import ${JSON.stringify(R(e,t,e.registryPath))};
|
|
592
641
|
|
|
593
642
|
// Builder Public API Key set in .env file
|
|
594
|
-
${e.configType==="vite"?`builder.init(import.meta.env.${
|
|
643
|
+
${e.configType==="vite"?`builder.init(import.meta.env.${rt}${n?"!":""})`:`builder.init("${Ct}")`}
|
|
595
644
|
|
|
596
645
|
export default function BuilderPage() {
|
|
597
646
|
const isPreviewingInBuilder = useIsPreviewing();
|
|
@@ -636,7 +685,7 @@ export default function BuilderPage() {
|
|
|
636
685
|
</>
|
|
637
686
|
);
|
|
638
687
|
}
|
|
639
|
-
`.trimStart()}async function
|
|
688
|
+
`.trimStart()}async function Dr(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===D.gen2){let i=Ca(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 ge(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===r);o&&await ge(e,o.id,!0,!1,null,null,!0,!1)}async function xa(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:p}=ha(e);if(!await e.exists(i)){let l=await e.formatCode(i,s);await e.writeFile(i,l),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,p),t.push({filePath:a,modifiedType:"create"})),i}function ha(e){let t=e.typescriptEnabled,r=`
|
|
640
689
|
"use client"
|
|
641
690
|
import React, { useState } from "react";
|
|
642
691
|
import styles from "./styles.module.css";
|
|
@@ -704,13 +753,13 @@ export default Counter;
|
|
|
704
753
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
705
754
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
706
755
|
];
|
|
707
|
-
`}async function
|
|
756
|
+
`}async function yr(e){let t=await Sa(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>Pr(t),ensureFigmaImportPage:()=>Er(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>ge(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await ge(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>ge(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>ge(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>ge(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>ge(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>nt(t),setPublicApiKey:n=>xr(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===D.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:()=>re(t),setCache:n=>oe(t,n)}}async function Sa(e){let t=await Pa(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Yt(e),i=`builder-registry.${o?"ts":"js"}`,a={},s={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,configType:"",addExternalPackage:p=>{a[e.join(r,p,"index.ts")]=`export * from "${p}";`},readFileSync:p=>a[p]??e.readFileSync(p),existsSync:p=>!!a[p]||e.existsSync(p),readdirSync:p=>{let l=e.readdirSync(p);return p===r?[...l,...Object.keys(a).map(d=>d.slice(r.length+1))]:l},readdir:async p=>{let l=await e.readdir(p);return p===r?[...l,...Object.keys(a).map(d=>d.slice(r.length+1))]:l}};return e.sdkVersion?s.sdkVersion=e.sdkVersion:s.sdkVersion=await Me(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 Yt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Pa(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.getRootDir(),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.getRootDir()}".`)}async function ot(e){return await Ea(e,["environment.ts"],St)}async function wr(e,t){let r=await ot(e),n=await wa(e,r.file,r.envKey,t);return{...r,modifiedType:n}}async function Ea(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),"src","environments",o),a=await Ta(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.getRootDir(),"src","environments",t[t.length-1]),n}async function Ta(e,t){let r=await e.readFile(t);return r?Da(e,r):""}function Da(e,t){let r=v(e,t),n="",i=Be(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(p=>{e.ts.isPropertyAssignment(p)&&e.ts.isIdentifier(p.name)&&p.name.text===St&&e.ts.isStringLiteral(p.initializer)&&(n=p.initializer.text)})}return n}async function ya(e,t,r,n){let o=v(e,t),a=Be(e,o,"environment");if(a&&a.statement.declarationList.declarations.length>0){let s=a.statement.declarationList,p=s.declarations[0],l=p.initializer;if(l&&e.ts.isObjectLiteralExpression(l)){let d=e.ts.factory.createPropertyAssignment(e.ts.factory.createIdentifier(r),e.ts.factory.createStringLiteral(n)),u=e.ts.factory.createNodeArray([...l.properties,d]),c=e.ts.factory.updateObjectLiteralExpression(l,u),m=e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,c),x=e.ts.factory.updateVariableDeclarationList(s,[m]);return e.ts.factory.updateVariableStatement(a.statement,a.statement.modifiers,x)}return null}return null}async function wa(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 ya(e,o,r,n);if(i){let a=O(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=`
|
|
708
757
|
// https://www.builder.io/c/docs/using-your-api-key
|
|
709
758
|
export const environment = {
|
|
710
759
|
production: false,
|
|
711
760
|
builderApiKey: "${n}",
|
|
712
761
|
};
|
|
713
|
-
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var
|
|
762
|
+
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var St="builderApiKey";async function vr(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(ba(e,i.fileName)||a.startsWith(".")||a==="node_modules"||va.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let p=await Pt(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var va=new Set([]),Ia=new Set(["node_modules"]);function ba(e,t){for(let r of Ia)if(e.dirname(t).includes(r))return!0;return!1}async function Ir(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 Ra(e,t,n)}return null}function Ra(e,t,r){let n=v(e,r);return Pt(e,null,t,n)}async function Pt(e,t,r,n){let o=[];r=e.normalize(r);let i=n.statements.filter(p=>e.ts.isClassDeclaration(p)&&Oa(e,p)),a=await Aa(e,t,r,n),s=La(e,n);return await Promise.all(i.map(async p=>{let l=await Na(e,t,r,p,s);o.push(...l)})),o.push(...a),o}async function br(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await je(e,t.cmpInfo.filePath,r),a=(await Pt(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 Rr(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await M(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{if(!a.isRegistered){let s=n.getSourceFile(a.filePath);if(s){let l=(await Pt(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=Ne(e,o,l.node.fnNode))}}return a}))}async function Na(e,t,r,n,o){let i=[],a=e.relative(e.getRootDir(),r),s=L(e,r),p=n.name?.text;if(!p)return i;let l=!1;n.modifiers&&(l=n.modifiers.some(m=>m.kind===e.ts.SyntaxKind.DefaultKeyword));let d=l?"default":p,u=l?"default":"named",c=[];return n.members.forEach(m=>{if(e.ts.isPropertyDeclaration(m)){let x=e.ts.getDecorators(m);x&&x.forEach(f=>{if(Fa(e,f)&&e.ts.isIdentifier(m.name)){let g="any";if(m.type&&t){let C=t.getTypeAtLocation(m.type);g=t.typeToString(C)}else g=ka(e,m.type);let h={name:m.name.text,type:o[g]?"string":g};o[g]&&(h.enum=o[g]),c.push(h)}})}}),i.push({cmpInfo:{id:await _(e,r,p),displayFilePath:A(e,r),name:j(p),inputs:c,exportName:d,exportType:u,importName:p,filePath:r,relFilePath:a,importPath:s},node:{name:p,fnNode:n,deps:void 0}}),i}async function Aa(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=L(e,r);for(let s of n.statements)if(e.ts.isExportDeclaration(s)&&s.exportClause&&e.ts.isNamedExports(s.exportClause))for(let p of s.exportClause.elements){let l=p.name?.text;if(!l)continue;let d=l,u="named",c=[];if(t){let f=t.getSymbolAtLocation(p.name);if(f){let g=t.getDeclaredTypeOfSymbol(f);t.getPropertiesOfType(g).forEach(C=>{let P=C.getDeclarations();P&&P.forEach(b=>{if(e.ts.isPropertyDeclaration(b)){let y=t.getTypeAtLocation(b),S={name:C.getName(),type:_a(e,t,y)};c.push(S)}})})}}let m=e.ts.isExportSpecifier(p)&&p.parent?p.parent.parent:void 0,x;if(m){let f=m.moduleSpecifier;if(f&&e.ts.isStringLiteral(f)){let g=t?.getSymbolAtLocation(f);if(g&&g.declarations&&g.declarations.length>0){let h=g.declarations[0];(!e.ts.isSourceFile(h)||e.ts.isSourceFile(h)&&h.fileName.includes("node_modules"))&&(x=f.text)}}}o.push({cmpInfo:{id:await _(e,r,l,x),displayFilePath:A(e,r),name:j(l),inputs:c,exportName:d,exportType:u,importName:l,filePath:r,relFilePath:i,importPath:x||a,externalImportPath:x},node:{name:l,fnNode:p,deps:void 0}})}return o}function Fa(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 Oa(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 ka(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 La(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 _a(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 Et(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 ja(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 ja(e,t,r,n,o){let i=o,a=v(e,o),s=R(e,t,n);a=w(e,a,{namedImports:[r],importPath:s}),a=w(e,a,{namedImports:["Content"],importPath:"@builder.io/sdk-angular"});let p=[];for(let l of a.statements)if(e.ts.isClassDeclaration(l)&&l.name?.text==="AppModule"){let d=Ba(e,r,l);p.push(d)}else p.push(l);return a=e.ts.factory.updateSourceFile(a,p),i=O(e,a),i}function Ba(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=Nr(e,i[0],"declarations",t);if(a){let s=Nr(e,a,"imports","Content");if(s&&(a=s),a){let p=e.ts.factory.updateDecorator(o,e.ts.factory.updateCallExpression(o.expression,o.expression.expression,o.expression.typeArguments,[a])),d=[...n.map(u=>u===o?p:u),...e.ts.getModifiers(r)||[]];return e.ts.factory.updateClassDeclaration(r,d,r.name,r.typeParameters,r.heritageClauses,r.members)}}}}}return r}function Nr(e,t,r,n){let o=[...t.properties],i=o.findIndex(s=>I(e,s)===r);if(i>-1){let s=o[i];if(e.ts.isPropertyAssignment(s)&&s.initializer&&e.ts.isArrayLiteralExpression(s.initializer)){let p=Ar(e,s.initializer,n);return p?(o[i]=e.ts.factory.updatePropertyAssignment(s,s.name,p),e.ts.factory.updateObjectLiteralExpression(t,o)):null}return null}let a=Ar(e,e.ts.factory.createArrayLiteralExpression([],!0),n);return a?e.ts.factory.updateObjectLiteralExpression(t,[...o,e.ts.factory.createPropertyAssignment(r,a)]):null}function Ar(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 Fr(e){let t=[],r=await $a(e,t);t.push(...await Tt(e)),await Va(e,r);let n="BuilderPage";if(!await e.exists(e.builderPageComponentPath)){let o=await e.formatCode(e.builderPageComponentPath,kr(e,n,e.builderPageComponentPath,"builder-page","page"));await e.writeFile(e.builderPageComponentPath,o),t.push({filePath:e.builderPageComponentPath,modifiedType:"create"})}if(e.hasAppModule){await Et(e,"Counter",r);let o=await Et(e,n,e.builderPageComponentPath);o&&t.push({filePath:o,modifiedType:"update"})}return t}async function Or(e){let t=[];t.push(...await Tt(e));let r="FigmaImportsPage",n=e.join(e.componentsDir,`figma-imports.component.${e.typescriptEnabled?"ts":"js"}`);if(!await e.exists(n)){let o=await e.formatCode(n,kr(e,r,n,"figma-imports","figma-imports"));await e.writeFile(n,o),t.push({filePath:n,modifiedType:"create"})}if(e.hasAppModule){let o=await Et(e,r,n);o&&t.push({filePath:o,modifiedType:"update"})}return t}async function Tt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Ka(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}async function Va(e,t){let n=(await xe(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await xe(e,n.id,!0,!1,null,null,!0,!1)}function kr(e,t,r,n,o){let i=!e.hasAppModule,a=R(e,r,e.registryPath),s=e.join(e.getRootDir(),"src","environments","environment.ts"),p=R(e,r,s);return`
|
|
714
763
|
import { Component, Input } from '@angular/core';
|
|
715
764
|
import { fetchOneEntry, type BuilderContent } from '@builder.io/sdk-angular';
|
|
716
765
|
${i?"import { Content } from '@builder.io/sdk-angular';":""}
|
|
@@ -742,7 +791,7 @@ export class ${t} {
|
|
|
742
791
|
|
|
743
792
|
@Input() model ${e.typescriptEnabled?": string":""} = '${o}';
|
|
744
793
|
|
|
745
|
-
apiKey = environment.${
|
|
794
|
+
apiKey = environment.${St};
|
|
746
795
|
${e.typescriptEnabled?`
|
|
747
796
|
content: BuilderContent | null = null;
|
|
748
797
|
`:`
|
|
@@ -843,17 +892,17 @@ export class Counter {
|
|
|
843
892
|
}
|
|
844
893
|
}
|
|
845
894
|
|
|
846
|
-
`.trimStart()}async function Or(e){await Pt(e);let t=await e.readFile(e.registryPath);return t?Ua(e,t):{components:[],sourceFile:w(e,"")}}async function Ua(e,t){let r=w(e,t);return za(e,r)}async function za(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Qt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Qt(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(v(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let d=s.arguments[0];e.ts.isIdentifier(d)&&(a=d.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await ae(e,e.registryPath,t,a);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,n.importPath=L(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await wr(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(m=>m.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function xe(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,m]=await Promise.all([Dr(e,p),Or(e),rt(e)]),c=l.map(C=>C.cmpInfo),u=d.components,x={components:te(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await br(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(E=>{let S=l.find(N=>N.cmpInfo.id===E);if(!S)throw new Error(`Component ${E} not found`);return S}),P=Array.from(new Set(C.map(E=>E.cmpInfo.filePath))),R=await M(e,P);for(let E of C){let S=x.components.find(F=>F.id===E.cmpInfo.id),N=await vr(e,E,R);ee(S,N);let B=c.findIndex(F=>F.id===E.cmpInfo.id);c[B].inputs=N;let k=me(E.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:T,statementIndex:U,statement:X,variableDeclaration:$}=await Ja(e,g,E);if(k.addCmpToRegistry)y.push(qa(e,k.addCmpToRegistry)),f=!0;else if(k.removeCmpFromRegistry)y.splice(T,1),f=!0;else if(k.updateRegisteredCmp){let F=K(e,y[T],k.updateRegisteredCmp);y[T]=e.ts.factory.updateObjectLiteralExpression(F,[kr(e,k.updateRegisteredCmp),...F.properties.slice(1)]),f=!0}if(f&&a){let F=[...g.statements];F[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration($,$.name,$.exclamationToken,$.type,e.ts.factory.createArrayLiteralExpression(le(e,y)))])),g=e.ts.factory.updateSourceFile(g,F),S.exportType==="named"?g=D(e,g,{namedImports:[S.importName],importPath:I(e,e.registryPath,S.filePath)}):g=D(e,g,{defaultImport:S.importName,importPath:I(e,e.registryPath,S.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=k.components,u=k.components.filter(z=>z.isRegistered)}}}if(f&&a){g=ce(e,g),g=pe(e,g);let C=O(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function kr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function qa(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([kr(e,t)],!0),t)}async function Ja(e,t,r){let n=V(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<o.length;a++)if((await Qt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Lr(e){let t=await Qa(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Nr(t),ensureFigmaImportPage:()=>Ar(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>xe(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 xe(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>xe(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>xe(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>xe(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>xe(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>rt(t),setPublicApiKey:o=>Er(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>re(t),setCache:o=>oe(t,o)}}async function Qa(e){let t=await Ya(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Wa(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.getRootDir()}".`);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"}`,p=e.join(a.appDir,s);return await e.exists(p)&&(a.hasAppModule=!0),a}function Wa(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Ya(e){let t=e.join(e.getRootDir(),"angular.json");if(await e.exists(t))return t;throw new Error(`Could not find Angular config file. Searched for angular.json in "${e.getRootDir()}".`)}var vt=Do(Wr(),1);async function Yr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:Z(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:W(i.inputs)};return W(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,vt.compress)(n);return btoa(JSON.stringify(o))}async function Gr(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,vt.decompress)(o),a=W(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let p=Z(e.normalize(s.filePath)),l=n.components.find(m=>Z(m.filePath).endsWith(p)&&m.exportName===s.exportName);if(!l){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${l.id})`,l.filePath),await t.registerComponent({cmpId:l.id});for(let m of s.inputs)e.debug(`set input (${l.id})`),await t.setRegisteredComponentInput({cmpId:l.id,name:m.name,type:m.type,required:m.required,defaultValue:m.defaultValue,friendlyName:m.friendlyName,helperText:m.helperText});e.debug(`set input (${l.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:l.id,name:s.name,image:s.image,description:s.description});a=W(d)}return a}var ne={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Qu={[ne.react]:[{version:b.gen1,recommended:!0},{version:b.gen2,recommended:!1}],[ne.remix]:[{version:b.gen1,recommended:!1}],[ne.angular]:[{version:b.gen2,recommended:!0}],[ne.next]:[{version:b.gen1,recommended:!0},{version:b.gen2,recommended:!1}],[ne.qwik]:[{version:b.gen2,recommended:!0}]};async function Hr(e,t){let r=[],n=new Set;async function o(s){let p=e.join(s,"package.json");try{let l=await e.readFile(p);if(l===null)throw new Error(`Failed to read package.json at ${p}`);let d=JSON.parse(l);if(n.has(d.name))return null;n.add(d.name);let m={name:d.name,subPackages:[]},c=await e.readdir(s);for(let u of c)u!=="node_modules"&&(await e.stat(e.join(s,u))).isDirectory()&&m.subPackages.push(u);return r.push(m),m}catch(l){return console.error(`Error reading package.json at ${s}:`,l),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),p={...s.dependencies,...s.devDependencies};for(let l of Object.keys(p)){let d=e.join(t,"node_modules",l);await o(d)}if(s.workspaces)for(let l of s.workspaces){let d=await e.readdir(e.join(t,l));for(let m of d){let c=e.join(t,l,m);await o(c)}}}return r}var Ss={"@builder.io/qwik-city":or,next:Qn,"@remix-run/react":ur,react:Tr,"@angular/core":Lr},Ps={"@builder.io/qwik-city":ne.qwik,next:ne.next,"@remix-run/react":ne.remix,react:ne.react,"@angular/core":ne.angular};async function Xr(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 ye(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getRootDir()}`);for(let t of e.frameworks){let r=Ss[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Yr(e,n),importRegistry:i=>Gr(e,n,i),framework:Ps[t.name],findAllDependencies:async()=>await Hr(e,e.getRootDir())}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Zr(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 u="",x=0,f=-1,g=0,h;for(let C=0;C<=m.length;++C){if(C<m.length)h=m.charCodeAt(C);else{if(h===47)break;h=47}if(h===47){if(!(f===C-1||g===1))if(f!==C-1&&g===2){if(u.length<2||x!==2||u.charCodeAt(u.length-1)!==46||u.charCodeAt(u.length-2)!==46){if(u.length>2){let P=u.lastIndexOf("/");if(P!==u.length-1){P===-1?(u="",x=0):(u=u.slice(0,P),x=u.length-1-u.lastIndexOf("/")),f=C,g=0;continue}}else if(u.length===2||u.length===1){u="",x=0,f=C,g=0;continue}}c&&(u.length>0?u+="/..":u="..",x=2)}else u.length>0?u+="/"+m.slice(f+1,C):u=m.slice(f+1,C),x=C-f-1;f=C,g=0}else h===46&&g!==-1?++g:g=-1}return u}let n=function(...c){let u="",x=!1;for(let f=c.length-1;f>=-1&&!x;f--){let g;f>=0?g=c[f]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(u=g+"/"+u,x=g.charCodeAt(0)===47)}return u=r(u,!x),x?u.length>0?"/"+u:"/":u.length>0?u:"."},o=function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0)===47,x=c.charCodeAt(c.length-1)===47;return c=r(c,!u),c.length===0&&!u&&(c="."),c.length>0&&x&&(c+="/"),u?"/"+c:c};return{relative:function(c,u){if(t(c),t(u),c===u||(c=n(c),u=n(u),c===u))return"";let x=1;for(;x<c.length&&c.charCodeAt(x)===47;++x);let f=c.length,g=f-x,h=1;for(;h<u.length&&u.charCodeAt(h)===47;++h);let P=u.length-h,R=g<P?g:P,E=-1,S=0;for(;S<=R;++S){if(S===R){if(P>R){if(u.charCodeAt(h+S)===47)return u.slice(h+S+1);if(S===0)return u.slice(h+S)}else g>R&&(c.charCodeAt(x+S)===47?E=S:S===0&&(E=0));break}let B=c.charCodeAt(x+S),k=u.charCodeAt(h+S);if(B!==k)break;B===47&&(E=S)}let N="";for(S=x+E+1;S<=f;++S)(S===f||c.charCodeAt(S)===47)&&(N.length===0?N+="..":N+="/..");return N.length>0?N+u.slice(h+E):(h+=E,u.charCodeAt(h)===47&&++h,u.slice(h))},resolve:n,join:function(...c){if(c.length===0)return".";let u;for(let x=0;x<c.length;++x){let f=c[x];t(f),f.length>0&&(u===void 0?u=f:u+="/"+f)}return u===void 0?".":o(u)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,u){if(u!==void 0&&typeof u!="string")throw new TypeError('"ext" argument must be a string');t(c);let x=0,f=-1,g=!0,h;if(u!==void 0&&u.length>0&&u.length<=c.length){if(u.length===c.length&&u===c)return"";let C=u.length-1,P=-1;for(h=c.length-1;h>=0;--h){let R=c.charCodeAt(h);if(R===47){if(!g){x=h+1;break}}else P===-1&&(g=!1,P=h+1),C>=0&&(R===u.charCodeAt(C)?--C===-1&&(f=h):(C=-1,f=P))}return x===f?f=P:f===-1&&(f=c.length),c.slice(x,f)}else{for(h=c.length-1;h>=0;--h)if(c.charCodeAt(h)===47){if(!g){x=h+1;break}}else f===-1&&(g=!1,f=h+1);return f===-1?"":c.slice(x,f)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0),x=u===47,f=-1,g=!0;for(let h=c.length-1;h>=1;--h)if(u=c.charCodeAt(h),u===47){if(!g){f=h;break}}else g=!1;return f===-1?x?"/":".":x&&f===1?"//":c.slice(0,f)},extname:function(c){t(c);let u=-1,x=0,f=-1,g=!0,h=0;for(let C=c.length-1;C>=0;--C){let P=c.charCodeAt(C);if(P===47){if(!g){x=C+1;break}continue}f===-1&&(g=!1,f=C+1),P===46?u===-1?u=C:h!==1&&(h=1):u!==-1&&(h=-1)}return u===-1||f===-1||h===0||h===1&&u===f-1&&u===x+1?"":c.slice(u,f)}}}async function eo(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Zr({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[g]of o)if((g+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),p=f=>{f=i(f);let g=f===t()?f:f+"/",h=g.split("/").length-1,C=[];for(let[P]of o)if(P.split("/").slice(0,h).join("/")+"/"===g){let S=P.split("/")[h];S&&!C.includes(S)&&C.push(S)}return C.sort()},l=f=>{f=i(f);let g=o.get(f);return typeof g=="string"?g:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),m=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),P=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(P)).map(R=>R.toString(16).padStart(2,"0")).join("")}let g=0;for(let h=0;h<f.length;h++){let C=f.charCodeAt(h);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,u={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>p(f),readdirSync:p,readFile:async f=>l(f),readFileSync:l,stat:async f=>d(f),statSync:d,writeFile:async(f,g)=>{f=i(f),o.set(f,g);let h={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of c)await C(h)},hash:m,getDeviceId:async()=>typeof navigator<"u"?m(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(f,g)=>g,on:(f,g)=>{f==="change"&&c.add(g)},off:(f,g)=>{f==="change"&&c.delete(g)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null},x=await ye(u);return u.getFrameworks=e.getFrameworks?e.getFrameworks:()=>x,u}async function to(e,t,r){let n=w(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(no(e,n))return o;let a=G(e,n,"cjs"),s=G(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(`Expected an export assignment from ${t}`);let c=d.statement;if(e.ts.isVariableStatement(c)){let u=[...c.declarationList.declarations];if(u.length!==1)throw new Error("Expected a single variable declaration");let x=u[0];if(!x.initializer)throw new Error("Expected an initializer on the declaration");let f=x.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let g="BuilderDevTools()",h=[...n.statements],C=h.indexOf(c);return h[C]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(x,x.name,x.exclamationToken,x.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,h),n=D(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let p=a[0];if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.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=pn(e,n);n=c.sourceFile;let u=[...n.statements],x=u.indexOf(d);return u[x]=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,u),o.content=O(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.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 u=pn(e,n);n=u.sourceFile;let x=[...n.statements],f=x.indexOf(l);return x[f]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(m,m.name,m.exclamationToken,m.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(p.node)){let d=p.node,m=p.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 x=p.node.body;if(!e.ts.isBlock(x))throw new Error("Expected a block body on the next config function");let f=[...x.statements],g=f.findIndex(E=>e.ts.isReturnStatement(E));if(g===-1)throw new Error("Expected a return statement on the next config function");let h=f[g],C=pn(e,n);n=C.sourceFile,f[g]=e.ts.factory.updateReturnStatement(h,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[h.expression]));let P=[...n.statements],R=P.indexOf(m);return P[R]=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(x,f)))),n=e.ts.factory.updateSourceFile(n,P),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function no(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 pn(e,t){let r=no(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 io(e,t,r){let n=w(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(ao(e,n))return o;let a=G(e,n,"cjs"),s=G(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let p=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()",u=ys(e,m.expression);if(!u)return o;let x=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[u]),f=[...n.statements],g=f.indexOf(m);return f[g]=e.ts.factory.updateExportAssignment(m,m.modifiers,x),n=e.ts.factory.updateSourceFile(n,f),n=D(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=O(e,n),o.hasContentUpdates=!0,o}}if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.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=ro(e,n);n=c.sourceFile;let u=[...n.statements],x=u.indexOf(d);return u[x]=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,u),o.content=O(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.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 u=ro(e,n);n=u.sourceFile;let x=[...n.statements],f=x.indexOf(l);return x[f]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(m,m.name,m.exclamationToken,m.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function ao(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 ro(e,t){let r=ao(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 ys(e,t){let r=[...t.properties],n=r.findIndex(i=>v(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=oo(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=oo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function oo(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 po(e,t,r){let n=w(e,r),o=G(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 p=[...i.node.arguments];if(p.length===0)throw new Error("Expected an argument in defineConfig()");let l=p[0];if(e.ts.isArrowFunction(l)){let d=Ts(e,l);if(!d)return s;p[0]=e.ts.factory.updateArrowFunction(l,l.modifiers,l.typeParameters,l.parameters,l.type,l.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,p)),n=e.ts.factory.updateSourceFile(n,m),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(l)){let d=ln(e,l);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=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let p=ln(e,a.expression);if(!p)return s;let l=[...n.statements],d=l.indexOf(a);return l[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,p),n=e.ts.factory.updateSourceFile(n,l),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Ts(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=ln(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function ln(e,t){if(ws(e)){let i=Es(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>v(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=so(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=so(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function so(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 Es(e,t){let r=[...t.properties],n=r.findIndex(i=>v(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Ds(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=cn(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 Ds(e,t){let r=[...t.properties],n=r.findIndex(i=>v(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=cn(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=cn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function cn(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 ws(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function lo(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 mo(e,t,r){e.debug("Angular config updates are currently in progress...");try{await Is(e)}catch{console.error("Unable to update package.json.")}return await vs(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function vs(e){let t=e.getRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);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 bs(e,o);await e.writeFile(n,i)}async function bs(e,t){let r=t,n=w(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=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
895
|
+
`.trimStart()}async function Lr(e){await Tt(e);let t=await e.readFile(e.registryPath);return t?Ua(e,t):{components:[],sourceFile:v(e,"")}}async function Ua(e,t){let r=v(e,t);return za(e,r)}async function za(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Gt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Gt(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(I(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let l=s.arguments[0];e.ts.isIdentifier(l)&&(a=l.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await ae(e,e.registryPath,t,a);if(!p)continue;if(n.filePath=p.filePath,n.relFilePath=p.relFilePath,await e.exists(p.filePath)?n.importPath=L(e,p.filePath):(n.externalImportPath=p.importPath,n.importPath=n.externalImportPath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType,n.externalImportPath)n.exportName=a;else{let l=await Ir(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(u=>u.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}async function xe(e,t,r,n,o,i,a,s){let p=await ve(e),[l,d,u]=await Promise.all([vr(e,p),Lr(e),ot(e)]),c=l.map(C=>C.cmpInfo),m=d.components,x={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await Rr(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(y=>{let S=l.find(N=>N.cmpInfo.id===y);if(!S)throw new Error(`Component ${y} not found`);return S}),P=Array.from(new Set(C.map(y=>y.cmpInfo.filePath))),b=await M(e,P);for(let y of C){let S=x.components.find(F=>F.id===y.cmpInfo.id),N=await br(e,y,b);ee(S,N);let B=c.findIndex(F=>F.id===y.cmpInfo.id);c[B].inputs=N;let k=me(y.cmpInfo.id,c,m,r,n,o,i),{elements:E,elmIndex:T,statementIndex:U,statement:X,variableDeclaration:$}=await Ja(e,g,y);if(k.addCmpToRegistry)E.push(qa(e,k.addCmpToRegistry)),f=!0;else if(k.removeCmpFromRegistry)E.splice(T,1),f=!0;else if(k.updateRegisteredCmp){let F=K(e,E[T],k.updateRegisteredCmp);E[T]=e.ts.factory.updateObjectLiteralExpression(F,[_r(e,k.updateRegisteredCmp),...F.properties.slice(1)]),f=!0}if(f&&a){let F=[...g.statements];F[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration($,$.name,$.exclamationToken,$.type,e.ts.factory.createArrayLiteralExpression(le(e,E)))])),g=e.ts.factory.updateSourceFile(g,F),S.exportType==="named"?g=w(e,g,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)}):g=w(e,g,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)}),g=w(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=k.components,m=k.components.filter(z=>z.isRegistered)}}}if(f&&a){g=ce(e,g),g=pe(e,g);let C=O(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function _r(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function qa(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([_r(e,t)],!0),t)}async function Ja(e,t,r){let n=V(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<o.length;a++)if((await Gt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function jr(e){let t=await Qa(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Fr(t),ensureFigmaImportPage:()=>Or(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>xe(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 xe(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>xe(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>xe(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>xe(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>xe(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>ot(t),setPublicApiKey:o=>wr(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>re(t),setCache:o=>oe(t,o)}}async function Qa(e){let t=await Ya(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Wa(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.getRootDir()}".`);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"}`,p=e.join(a.appDir,s);return await e.exists(p)&&(a.hasAppModule=!0),a}function Wa(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Ya(e){let t=e.join(e.getRootDir(),"angular.json");if(await e.exists(t))return t;throw new Error(`Could not find Angular config file. Searched for angular.json in "${e.getRootDir()}".`)}var bt=vo(Gr(),1);async function Hr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:Z(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:W(i.inputs)};return W(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,bt.compress)(n);return btoa(JSON.stringify(o))}async function Xr(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,bt.decompress)(o),a=W(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let p=Z(e.normalize(s.filePath)),l=n.components.find(u=>Z(u.filePath).endsWith(p)&&u.exportName===s.exportName);if(!l){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${l.id})`,l.filePath),await t.registerComponent({cmpId:l.id});for(let u of s.inputs)e.debug(`set input (${l.id})`),await t.setRegisteredComponentInput({cmpId:l.id,name:u.name,type:u.type,required:u.required,defaultValue:u.defaultValue,friendlyName:u.friendlyName,helperText:u.helperText});e.debug(`set input (${l.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:l.id,name:s.name,image:s.image,description:s.description});a=W(d)}return a}var ne={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Hu={[ne.react]:[{version:D.gen1,recommended:!0},{version:D.gen2,recommended:!1}],[ne.remix]:[{version:D.gen1,recommended:!1},{version:D.gen2,recommended:!0}],[ne.angular]:[{version:D.gen2,recommended:!0}],[ne.next]:[{version:D.gen1,recommended:!0},{version:D.gen2,recommended:!1}],[ne.qwik]:[{version:D.gen2,recommended:!0}]};async function Zr(e,t){let r=[],n=new Set;async function o(s){let p=e.join(s,"package.json");try{let l=await e.readFile(p);if(l===null)throw new Error(`Failed to read package.json at ${p}`);let d=JSON.parse(l);if(n.has(d.name))return null;n.add(d.name);let u={name:d.name,subPackages:[]},c=await e.readdir(s);for(let m of c)m!=="node_modules"&&(await e.stat(e.join(s,m))).isDirectory()&&u.subPackages.push(m);return r.push(u),u}catch(l){return console.error(`Error reading package.json at ${s}:`,l),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),p={...s.dependencies,...s.devDependencies};for(let l of Object.keys(p)){let d=e.join(t,"node_modules",l);await o(d)}if(s.workspaces)for(let l of s.workspaces){let d=await e.readdir(e.join(t,l));for(let u of d){let c=e.join(t,l,u);await o(c)}}}return r}var Ss={"@builder.io/qwik-city":sr,next:Gn,"@remix-run/react":gr,react:yr,"@angular/core":jr},Ps={"@builder.io/qwik-city":ne.qwik,next:ne.next,"@remix-run/react":ne.remix,react:ne.react,"@angular/core":ne.angular};async function eo(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 Ee(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getRootDir()}`);for(let t of e.frameworks){let r=Ss[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Hr(e,n),importRegistry:i=>Xr(e,n,i),framework:Ps[t.name],findAllDependencies:async()=>await Zr(e,e.getRootDir())}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function to(e){function t(u){if(typeof u!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(u))}function r(u,c){let m="",x=0,f=-1,g=0,h;for(let C=0;C<=u.length;++C){if(C<u.length)h=u.charCodeAt(C);else{if(h===47)break;h=47}if(h===47){if(!(f===C-1||g===1))if(f!==C-1&&g===2){if(m.length<2||x!==2||m.charCodeAt(m.length-1)!==46||m.charCodeAt(m.length-2)!==46){if(m.length>2){let P=m.lastIndexOf("/");if(P!==m.length-1){P===-1?(m="",x=0):(m=m.slice(0,P),x=m.length-1-m.lastIndexOf("/")),f=C,g=0;continue}}else if(m.length===2||m.length===1){m="",x=0,f=C,g=0;continue}}c&&(m.length>0?m+="/..":m="..",x=2)}else m.length>0?m+="/"+u.slice(f+1,C):m=u.slice(f+1,C),x=C-f-1;f=C,g=0}else h===46&&g!==-1?++g:g=-1}return m}let n=function(...c){let m="",x=!1;for(let f=c.length-1;f>=-1&&!x;f--){let g;f>=0?g=c[f]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(m=g+"/"+m,x=g.charCodeAt(0)===47)}return m=r(m,!x),x?m.length>0?"/"+m:"/":m.length>0?m:"."},o=function(c){if(t(c),c.length===0)return".";let m=c.charCodeAt(0)===47,x=c.charCodeAt(c.length-1)===47;return c=r(c,!m),c.length===0&&!m&&(c="."),c.length>0&&x&&(c+="/"),m?"/"+c:c};return{relative:function(c,m){if(t(c),t(m),c===m||(c=n(c),m=n(m),c===m))return"";let x=1;for(;x<c.length&&c.charCodeAt(x)===47;++x);let f=c.length,g=f-x,h=1;for(;h<m.length&&m.charCodeAt(h)===47;++h);let P=m.length-h,b=g<P?g:P,y=-1,S=0;for(;S<=b;++S){if(S===b){if(P>b){if(m.charCodeAt(h+S)===47)return m.slice(h+S+1);if(S===0)return m.slice(h+S)}else g>b&&(c.charCodeAt(x+S)===47?y=S:S===0&&(y=0));break}let B=c.charCodeAt(x+S),k=m.charCodeAt(h+S);if(B!==k)break;B===47&&(y=S)}let N="";for(S=x+y+1;S<=f;++S)(S===f||c.charCodeAt(S)===47)&&(N.length===0?N+="..":N+="/..");return N.length>0?N+m.slice(h+y):(h+=y,m.charCodeAt(h)===47&&++h,m.slice(h))},resolve:n,join:function(...c){if(c.length===0)return".";let m;for(let x=0;x<c.length;++x){let f=c[x];t(f),f.length>0&&(m===void 0?m=f:m+="/"+f)}return m===void 0?".":o(m)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,m){if(m!==void 0&&typeof m!="string")throw new TypeError('"ext" argument must be a string');t(c);let x=0,f=-1,g=!0,h;if(m!==void 0&&m.length>0&&m.length<=c.length){if(m.length===c.length&&m===c)return"";let C=m.length-1,P=-1;for(h=c.length-1;h>=0;--h){let b=c.charCodeAt(h);if(b===47){if(!g){x=h+1;break}}else P===-1&&(g=!1,P=h+1),C>=0&&(b===m.charCodeAt(C)?--C===-1&&(f=h):(C=-1,f=P))}return x===f?f=P:f===-1&&(f=c.length),c.slice(x,f)}else{for(h=c.length-1;h>=0;--h)if(c.charCodeAt(h)===47){if(!g){x=h+1;break}}else f===-1&&(g=!1,f=h+1);return f===-1?"":c.slice(x,f)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let m=c.charCodeAt(0),x=m===47,f=-1,g=!0;for(let h=c.length-1;h>=1;--h)if(m=c.charCodeAt(h),m===47){if(!g){f=h;break}}else g=!1;return f===-1?x?"/":".":x&&f===1?"//":c.slice(0,f)},extname:function(c){t(c);let m=-1,x=0,f=-1,g=!0,h=0;for(let C=c.length-1;C>=0;--C){let P=c.charCodeAt(C);if(P===47){if(!g){x=C+1;break}continue}f===-1&&(g=!1,f=C+1),P===46?m===-1?m=C:h!==1&&(h=1):m!==-1&&(h=-1)}return m===-1||f===-1||h===0||h===1&&m===f-1&&m===x+1?"":c.slice(m,f)}}}async function no(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=to({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[g]of o)if((g+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),p=f=>{f=i(f);let g=f===t()?f:f+"/",h=g.split("/").length-1,C=[];for(let[P]of o)if(P.split("/").slice(0,h).join("/")+"/"===g){let S=P.split("/")[h];S&&!C.includes(S)&&C.push(S)}return C.sort()},l=f=>{f=i(f);let g=o.get(f);return typeof g=="string"?g:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),u=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),P=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(P)).map(b=>b.toString(16).padStart(2,"0")).join("")}let g=0;for(let h=0;h<f.length;h++){let C=f.charCodeAt(h);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,m={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>p(f),readdirSync:p,readFile:async f=>l(f),readFileSync:l,stat:async f=>d(f),statSync:d,writeFile:async(f,g)=>{f=i(f),o.set(f,g);let h={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of c)await C(h)},hash:u,getDeviceId:async()=>typeof navigator<"u"?u(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(f,g)=>g,on:(f,g)=>{f==="change"&&c.add(g)},off:(f,g)=>{f==="change"&&c.delete(g)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null},x=await Ee(m);return m.getFrameworks=e.getFrameworks?e.getFrameworks:()=>x,m}async function ro(e,t,r){let n=v(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(oo(e,n))return o;let a=G(e,n,"cjs"),s=G(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 u=d.statement;if(!e.ts.isVariableStatement(u))throw new Error(`Expected an export assignment from ${t}`);let c=d.statement;if(e.ts.isVariableStatement(c)){let m=[...c.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let x=m[0];if(!x.initializer)throw new Error("Expected an initializer on the declaration");let f=x.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let g="BuilderDevTools()",h=[...n.statements],C=h.indexOf(c);return h[C]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(x,x.name,x.exclamationToken,x.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,h),n=w(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let p=a[0];if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let u=d.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let c=mn(e,n);n=c.sourceFile;let m=[...n.statements],x=m.indexOf(d);return m[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[u.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=O(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let u=d[0];if(!u.initializer)throw new Error("Expected an initializer on the declaration");let c=u.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let m=mn(e,n);n=m.sourceFile;let x=[...n.statements],f=x.indexOf(l);return x[f]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(p.node)){let d=p.node,u=p.statement;if(!e.ts.isExpressionStatement(u))throw new Error("Expected an expression statement for the default export");let c=u.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let x=p.node.body;if(!e.ts.isBlock(x))throw new Error("Expected a block body on the next config function");let f=[...x.statements],g=f.findIndex(y=>e.ts.isReturnStatement(y));if(g===-1)throw new Error("Expected a return statement on the next config function");let h=f[g],C=mn(e,n);n=C.sourceFile,f[g]=e.ts.factory.updateReturnStatement(h,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[h.expression]));let P=[...n.statements],b=P.indexOf(u);return P[b]=e.ts.factory.updateExpressionStatement(u,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(x,f)))),n=e.ts.factory.updateSourceFile(n,P),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function oo(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 mn(e,t){let r=oo(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 so(e,t,r){let n=v(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(po(e,n))return o;let a=G(e,n,"cjs"),s=G(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let p=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let u=d.statement;if(!e.ts.isExportAssignment(u))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(u.expression)){let c="builderDevTools()",m=Es(e,u.expression);if(!m)return o;let x=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[m]),f=[...n.statements],g=f.indexOf(u);return f[g]=e.ts.factory.updateExportAssignment(u,u.modifiers,x),n=e.ts.factory.updateSourceFile(n,f),n=w(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=O(e,n),o.hasContentUpdates=!0,o}}if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let u=d.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let c=io(e,n);n=c.sourceFile;let m=[...n.statements],x=m.indexOf(d);return m[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[u.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=O(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let u=d[0];if(!u.initializer)throw new Error("Expected an initializer on the declaration");let c=u.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let m=io(e,n);n=m.sourceFile;let x=[...n.statements],f=x.indexOf(l);return x[f]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function po(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 io(e,t){let r=po(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 Es(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=ao(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=ao(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function ao(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 co(e,t,r){let n=v(e,r),o=G(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 p=[...i.node.arguments];if(p.length===0)throw new Error("Expected an argument in defineConfig()");let l=p[0];if(e.ts.isArrowFunction(l)){let d=Ts(e,l);if(!d)return s;p[0]=e.ts.factory.updateArrowFunction(l,l.modifiers,l.typeParameters,l.parameters,l.type,l.equalsGreaterThanToken,d);let u=[...n.statements],c=u.indexOf(a);return u[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,p)),n=e.ts.factory.updateSourceFile(n,u),n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(l)){let d=un(e,l);if(!d)return s;let u=[...n.statements],c=u.indexOf(a);return u[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,u),n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let p=un(e,a.expression);if(!p)return s;let l=[...n.statements],d=l.indexOf(a);return l[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,p),n=e.ts.factory.updateSourceFile(n,l),n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Ts(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=un(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function un(e,t){if(ws(e)){let i=Ds(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=lo(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=lo(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function lo(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 Ds(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=ys(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=fn(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 ys(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=fn(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=fn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function fn(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 ws(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function mo(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 fo(e,t,r){e.debug("Angular config updates are currently in progress...");try{await bs(e)}catch{console.error("Unable to update package.json.")}return await vs(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function vs(e){let t=e.getRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);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 Is(e,o);await e.writeFile(n,i)}async function Is(e,t){let r=t,n=v(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=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
847
896
|
builderDevTools().catch((err: Error) =>
|
|
848
897
|
console.error("Error starting dev tools:", err)
|
|
849
|
-
);`;return r=O(e,n),o||(r+=i),r}async function
|
|
850
|
-
`}var
|
|
898
|
+
);`;return r=O(e,n),o||(r+=i),r}async function bs(e){let t=e.getRootDir(),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=Rs(n);o&&await e.writeFile(r,o)}function Rs(e){let t=JSON.parse(e);if(t.scripts=t.scripts||{},t.scripts[uo])return;let r=t.scripts.start||t.scripts.dev||"ng serve";return t.scripts[uo]=`concurrently "${r}" "${Ns}"`,JSON.stringify(t,null,2)+`
|
|
899
|
+
`}var uo="builder-dev",Ns="npx builder-dev-tools";var xo=[{id:"angular",configFileNames:["angular.json"],ensureConfigPlugin:fo},{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:ro},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:co},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:so},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:mo}];async function dn(e){let t=e.resolve("/");for(let n of xo)for(let o of n.configFileNames){let i=e.getRootDir();for(let a=0;a<10;a++)try{let s=e.join(i,o),p=e.readFileSync(s);if(typeof p=="string")return{id:n.id,filePath:s,content:p};if(i===t)break;i=e.dirname(i)}catch(s){if((s?.message??"").includes("Invalid path"))break;throw s}}if((await Ee(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,go),{id:"next",filePath:n,content:go}}return null}async function ho(e){let t=await dn(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await xo.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=H(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var go=`
|
|
851
900
|
/** @type {import('next').NextConfig} */
|
|
852
901
|
const nextConfig = {
|
|
853
902
|
}
|
|
854
903
|
|
|
855
904
|
module.exports = nextConfig
|
|
856
|
-
`.trimStart();var
|
|
905
|
+
`.trimStart();var Co="/~builder-dev-tools.js";function So(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(Co,e);t.searchParams.set("v",pt);let r=JSON.stringify(pt),n=`/* Builder Devtools v${pt} */
|
|
857
906
|
`;return n+=`(() => {
|
|
858
907
|
`,n+=` if (typeof document !== "undefined") {
|
|
859
908
|
`,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]");
|
|
@@ -866,4 +915,4 @@ module.exports = nextConfig
|
|
|
866
915
|
`,n+=` }
|
|
867
916
|
`,n+=` }
|
|
868
917
|
`,n+=`})();
|
|
869
|
-
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var
|
|
918
|
+
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var pt="1.1.26";
|