builder.io 1.1.20 → 1.1.22
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 +499 -345
- package/core/index.cjs +110 -46
- package/core/index.mjs +110 -46
- package/node/index.cjs +1 -1
- package/node/index.mjs +1 -1
- package/package.json +2 -3
- package/remix/build.cjs +1 -1
- package/remix/index.mjs +1 -1
- package/server/index.cjs +5 -5
- package/server/index.mjs +5 -5
- package/types/cli/credentials.d.ts +2 -1
- package/types/cli/figma-publish.d.ts +1 -1
- package/types/cli/figma.d.ts +1 -0
- package/types/cli/index.d.ts +1 -0
- package/types/core/adapters/react/react-ensure-builder-setup.d.ts +1 -1
- package/types/core/adapters/react/react-registry-parse.d.ts +3 -1
- package/types/core/adapters/react/react-registry.d.ts +1 -1
- package/types/core/adapters/react/react-test-utils.d.ts +3 -2
- package/vite/index.cjs +1 -1
- package/vite/index.mjs +1 -1
- package/webpack/index.cjs +15 -14
- package/webpack/index.mjs +15 -14
- package/cli/index.cjs.map +0 -7
- package/cli/main.cjs +0 -2
package/core/index.mjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),n;for(;(n=
|
|
3
|
-
`),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var
|
|
1
|
+
var oo=Object.create;var pn=Object.defineProperty;var io=Object.getOwnPropertyDescriptor;var ao=Object.getOwnPropertyNames;var so=Object.getPrototypeOf,po=Object.prototype.hasOwnProperty;var Pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var lo=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ao(t))!po.call(e,o)&&o!==r&&pn(e,o,{get:()=>t[o],enumerable:!(n=io(t,o))||n.enumerable});return e};var co=(e,t,r)=>(r=e!=null?oo(so(e)):{},lo(t||!e||!e.__esModule?pn(r,"default",{value:e,enumerable:!0}):r,e));var qt=Pe(xt=>{"use strict";Object.defineProperty(xt,"__esModule",{value:!0});function br(e){return Object.prototype.toString.call(e)}xt.getType=br;function Ma(e){throw new TypeError("unsupported data type: "+br(e))}xt.throwUnknownDataType=Ma});var Gt=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 Ve=he.length,Jt={};for(let e=0;e<Ve;e++){let t=he[e];Jt[t]=e}function Wt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Jt[o];i*=r,t+=i,r*=Ve}return t}Ce.s_to_int=Wt;function Ir(e){let t=BigInt(0),r=BigInt(1),n=BigInt(Ve);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Jt[i]);a*=r,t+=a,r*=n}return t}Ce.s_to_big_int=Ir;function Yt(e){if(e===0)return he[0];let t=[];for(;e!==0;){let r=e%Ve,n=he[r];t.push(n),e-=r,e/=Ve}return t.reverse().join("")}Ce.int_to_s=Yt;function Rr(e){let t=BigInt(0),r=BigInt(Ve);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=Rr;function Ct(e){return e.split("").reverse().join("")}function Nr(e){if(e<0)return"-"+Nr(-e);let[t,r]=e.toString().split(".");if(!r)return Yt(e);let n;r&&([r,n]=r.split("e")),t=ht(t),r=Ct(r),r=ht(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=Ct(n),n=ht(n),o+=n}return o}Ce.num_to_s=Nr;function ht(e){let t=+e;return t.toString()===e?Yt(t):":"+Rr(BigInt(e))}Ce.int_str_to_s=ht;function Qt(e){return e[0]===":"?Ir(e.substring(1)).toString():Wt(e).toString()}function Ar(e){if(e[0]==="-")return-Ar(e.substr(1));let[t,r,n]=e.split(".");if(!r)return Wt(t);t=Qt(t),r=Qt(r),r=Ct(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Qt(n),n=Ct(n),o+=i?-n:+n}return+o}Ce.s_to_num=Ar});var Xt=Pe(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});var Ht=Gt();function Ua(e){return"n|"+Ht.num_to_s(e)}Se.encodeNum=Ua;function za(e){return e=e.replace("n|",""),Ht.s_to_num(e)}Se.decodeNum=za;function qa(e){return typeof e=="number"?e:Ht.s_to_int(e)}Se.decodeKey=qa;function Qa(e){return e?"b|T":"b|F"}Se.encodeBool=Qa;function Ja(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}Se.decodeBool=Ja;function Wa(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}Se.encodeStr=Wa;function Ya(e){return e[0]+e[1]==="s|"?e.substr(2):e}Se.decodeStr=Ya});var Fr=Pe(Zt=>{"use strict";Object.defineProperty(Zt,"__esModule",{value:!0});Zt.config={sort_key:!1}});var tn=Pe(Ne=>{"use strict";Object.defineProperty(Ne,"__esModule",{value:!0});var Ga=Fr(),Ha=qt(),en=Xt(),Xa=Gt();function Za(e){return e.store.toArray()}Ne.memToValues=Za;function Or(){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}}}Ne.makeInMemoryStore=Or;function Lr(){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}}}Ne.makeInMemoryCache=Lr;function es(){return{store:Or(),cache:Lr(),keyCount:0}}Ne.makeInMemoryMemory=es;function Re(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=Xa.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function ts(e,t){Ga.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=ot(e,t,void 0);return e.cache.setSchema(r,n),n}function ot(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return ot(e,null,r);break;case"object":if(t===null)return Re(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":ot(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),Re(e,n)}else{let n=Object.keys(t);if(n.length===0)return Re(e,"o|");let o="o",i=ts(e,n);o+="|"+i;for(let a of n){let s=t[a],p=ot(e,s,t);o+="|"+p}return Re(e,o)}case"boolean":return Re(e,en.encodeBool(t));case"number":return Re(e,en.encodeNum(t));case"string":return Re(e,en.encodeStr(t))}return Ha.throwUnknownDataType(t)}Ne.addValue=ot});var rn=Pe(at=>{"use strict";Object.defineProperty(at,"__esModule",{value:!0});var ns=qt(),St=Xt(),nn=tn();function rs(e){let t=nn.makeInMemoryMemory(),r=nn.addValue(t,e,void 0);return[nn.memToValues(t),r]}at.compress=rs;function os(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=it(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=it(e,l),r[p]=l}return r}function is(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=it(e,a),o[i]=a}return o}function it(e,t){if(t===""||t==="_")return null;let r=St.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 St.decodeBool(n);case"o|":return os(e,n);case"n|":return St.decodeNum(n);case"a|":return is(e,n);default:return St.decodeStr(n)}}return ns.throwUnknownDataType(n)}at.decode=it;function as(e){let[t,r]=e;return it(t,r)}at.decompress=as});var _r=Pe(Pt=>{"use strict";Object.defineProperty(Pt,"__esModule",{value:!0});function ss(e){for(let t in e)e[t]===void 0&&delete e[t]}Pt.trimUndefined=ss;function ps(e){kr(e,new Set)}Pt.trimUndefinedRecursively=ps;function kr(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)&&kr(n,t)}}});var Vr=Pe(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});var jr=rn();we.compress=jr.compress;we.decompress=jr.decompress;var ls=rn();we.decode=ls.decode;var cs=tn();we.addValue=cs.addValue;var Br=_r();we.trimUndefined=Br.trimUndefined;we.trimUndefinedRecursively=Br.trimUndefinedRecursively});async function st(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 ln(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 Ke(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 Ke(e,a,r);if(p)return p}}))).find(i=>typeof i=="string")}async function ve(e){let t=[],r=await st(e,e.getRootDir());if(r){let n=cn(r);t.push(...n)}return t}function cn(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of mo)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var mo=["@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=mn(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=mn(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function mn(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 uo(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 uo(e,t){let r=await e.readFile(t);return typeof r=="string"?un(r):null}function un(e){let t={},r=e.replace(/\r\n?/gm,`
|
|
2
|
+
`),n;for(;(n=fo.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 fo=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function ye(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 Me(e){return await Te(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],ie)}async function fn(e,t){let r=await Me(e),n=await ye(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ie="NEXT_PUBLIC_BUILDER_API_KEY";var I={gen1:"Gen 1",gen2:"Gen 2"};function w(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest,void 0)}function pt(e,t=""){let r=w(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function F(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 v(e,t,r){t=X(t),r=X(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=X(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function X(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Ae(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return mn(o==="index"?e.basename(e.dirname(t)):o)}function mn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=X(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function k(e,t){let r=X(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 Q(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function _(e,t,r){if(typeof r!="string"||r==="")throw new Error(`getComponentId(), exportName must be a non-empty string, received: ${r}, ${t}`);return t=e.normalize(t),(await e.hash(t+"#"+r)).substring(0,8)}function Me(e){return typeof e=="number"}function Fe(e){return typeof e=="boolean"}function U(e){return typeof e=="string"}function Ue(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function J(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=mo(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,ze(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,ze(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function mo(e,t,r){return t.properties.findIndex(n=>b(e,n)===r)}function Qe(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return go(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=b(e,n);o&&(r[o]=Qe(e,n.initializer))}}return r}function go(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Qe(e,r)):[]}function b(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 ze(e,t){return yt(e,t,new WeakSet)}function yt(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)?xo(e,t,r):typeof t=="object"?ho(e,t,r):e.ts.factory.createIdentifier(t)}function xo(e,t,r){let n=t.map(o=>yt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function ho(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,yt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function be(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 f=l.typeArguments;if(f){let c=f[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())}}}if(o)for(let i of o){let a=Co(e,t,i);a&&n.push(a)}return n=n.filter(dn),n.length>0?n:So(e,r)}function Co(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=Tt(l);d.knownType?i=d.builderType:yo(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(f=>f.flags&e.ts.TypeFlags.Object)||p.isIntersection()&&p.types.some(f=>f.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=wo(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},p&&p.length>0&&s.type==="string"&&p.every(Do)?s.enum=p.map(Eo):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function So(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 f=l.typeExpression;if(!f)continue;let c="";switch(f.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 h={name:d.right.text,type:c,isRegistered:!1};r.push(h)}}return r.filter(dn)}var Po=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function yo(e){return typeof e!="string"?!1:!!Po.some(t=>e.includes(t))}function Tt(e){return typeof e=="string"&&(e=e.trim(),To.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var To=[{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 Do(e){return/^['"].*['"]$/.test(e)}function Eo(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var wo=(e,t,r)=>{let n=new Set;fn(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},vo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},fn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{fn(e,t,o,n)});else if(r.isLiteral()){let o=vo(e,t,r);n.add(o)}};function dn(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!bo.has(t.toLowerCase())}var bo=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 W(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=b(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=Io(e,n.initializer);Z(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Qe(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function Io(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Ro(e,n));return r}function Ro(e,t){let r=Qe(e,t),n=_o(r);return n.isRegistered=!0,n}function K(e,t,r){let n=Ao(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=No(e,t,n),jo(e,t)}function No(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=Oo(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 Ao(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Fo)}}function Fo(e){let t={name:e.name,type:e.type};return(U(e.defaultValue)||Me(e.defaultValue)||Fe(e.defaultValue))&&(t.defaultValue=e.defaultValue),U(e.friendlyName)&&(t.friendlyName=e.friendlyName),U(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 Oo(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>b(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=Lo(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>b(e,c)==="name"),s=i.properties.find(c=>b(e,c)==="name"),p=a?.initializer,l=s?.initializer,d=p&&e.ts.isStringLiteral(p)?p.text:"zz",f=l&&e.ts.isStringLiteral(l)?l.text:"zz";return d.toLowerCase().localeCompare(f.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Lo(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=b(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=gn(e,t[n],r);else{let o=gn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function gn(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=ko(e,n,r,i);return n=Bo(e,n.filter(i=>{let a=b(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function ko(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,ze(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,ze(e,r[n]))),t}function Z(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=Dt(e)}function _o(e){let t=Tt(e.type),r={name:e.name.trim(),type:t.builderType};return U(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(U(e.defaultValue)||Me(e.defaultValue)||Fe(e.defaultValue))&&(r.defaultValue=e.defaultValue),U(e.helperText)&&(r.helperText=e.helperText),Fe(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),Et(r)}function Dt(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 Et(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 jo(e,t){let r=[...t.properties].sort((n,o)=>{let i=b(e,n)||"zz",a=b(e,o)||"zz";if(i==="inputs")return 1;let s=xn.indexOf(i),p=xn.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 xn=["component","name","description"];function Bo(e,t){return[...t].sort((n,o)=>{let i=b(e,n)||"zz",a=b(e,o)||"zz",s=hn.indexOf(i),p=hn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)})}var hn=["name","type"];function Cn(e,t){let r=`Builder.registerComponent(
|
|
11
|
+
`}return""}function b(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 Ae(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return dn(o==="index"?e.basename(e.dirname(t)):o)}function dn(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 k(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 O(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 Q(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function _(e,t,r){if(typeof r!="string"||r==="")throw new Error(`getComponentId(), exportName must be a non-empty string, received: ${r}, ${t}`);return t=e.normalize(t),(await e.hash(t+"#"+r)).substring(0,8)}function Ue(e){return typeof e=="number"}function Fe(e){return typeof e=="boolean"}function q(e){return typeof e=="string"}function ze(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=go(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 go(e,t,r){return t.properties.findIndex(n=>v(e,n)===r)}function Je(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return ho(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return xo(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 xo(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]=Je(e,n.initializer))}}return r}function ho(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Je(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 qe(e,t){return Dt(e,t,new WeakSet)}function Dt(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)?Co(e,t,r):typeof t=="object"?So(e,t,r):e.ts.factory.createIdentifier(t)}function Co(e,t,r){let n=t.map(o=>Dt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function So(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,Dt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function be(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 f=l.typeArguments;if(f){let c=f[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())}}}if(o)for(let i of o){let a=Po(e,t,i);a&&n.push(a)}return n=n.filter(xn),n.length>0?n:To(e,r)}function Po(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),g=Et(l);g.knownType?i=g.builderType:Do(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(f=>f.flags&e.ts.TypeFlags.Object)||p.isIntersection()&&p.types.some(f=>f.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=bo(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},p&&p.length>0&&s.type==="string"&&p.every(wo)?s.enum=p.map(vo):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function To(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 g=l.name;if(!e.ts.isQualifiedName(g))continue;let f=l.typeExpression;if(!f)continue;let c="";switch(f.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 h={name:g.right.text,type:c,isRegistered:!1};r.push(h)}}return r.filter(xn)}var yo=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function Do(e){return typeof e!="string"?!1:!!yo.some(t=>e.includes(t))}function Et(e){return typeof e=="string"&&(e=e.trim(),Eo.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var Eo=[{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 wo(e){return/^['"].*['"]$/.test(e)}function vo(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var bo=(e,t,r)=>{let n=new Set;gn(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},Io=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},gn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{gn(e,t,o,n)});else if(r.isLiteral()){let o=Io(e,t,r);n.add(o)}};function xn(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!Ro.has(t.toLowerCase())}var Ro=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 J(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=No(e,n.initializer);ee(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Je(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function No(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Ao(e,n));return r}function Ao(e,t){let r=Je(e,t),n=Bo(r);return n.isRegistered=!0,n}function $(e,t,r){let n=Oo(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=Fo(e,t,n),Vo(e,t)}function Fo(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=ko(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 Oo(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Lo)}}function Lo(e){let t={name:e.name,type:e.type};return(q(e.defaultValue)||Ue(e.defaultValue)||Fe(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 ko(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=_o(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,g=p&&e.ts.isStringLiteral(p)?p.text:"zz",f=l&&e.ts.isStringLiteral(l)?l.text:"zz";return g.toLowerCase().localeCompare(f.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function _o(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]=hn(e,t[n],r);else{let o=hn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function hn(e,t,r){let n=t.properties.filter(i=>e.ts.isPropertyAssignment(i)),o=Object.keys(r).filter(i=>i!=="isRegistered");for(let i of o)n=jo(e,n,r,i);return n=$o(e,n.filter(i=>{let a=v(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function jo(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=wt(e)}function Bo(e){let t=Et(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)||Ue(e.defaultValue)||Fe(e.defaultValue))&&(r.defaultValue=e.defaultValue),q(e.helperText)&&(r.helperText=e.helperText),Fe(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),vt(r)}function wt(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 vt(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 Vo(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=Cn.indexOf(i),p=Cn.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 Cn=["component","name","description"];function $o(e,t){return[...t].sort((n,o)=>{let i=v(e,n)||"zz",a=v(e,o)||"zz",s=Sn.indexOf(i),p=Sn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)})}var Sn=["name","type"];function Pn(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=
|
|
14
|
+
`;else{let o=b(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=Je.get(a);if(p)return E(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=Pn.get(p),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new pt(p)}return a.includes("node_modules")&&(s?Je.set(a,{exists:!0,content:s}):Je.set(a,{exists:!1})),E(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return Vo(e,i,t)}catch(a){if(a instanceof pt){await $o(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Vo(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=Sn.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,Sn.set(o,i))}i&&(n.options=J(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 Oe(e,t,r){r||(r=await $(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 pt=class{constructor(t){this.libName=t}};async function $o(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;st.has(t)||st.set(t,fetch(r).then(n=>n.text()).then(n=>{Pn.set(t,n)})),await st.get(t),st.delete(t)}var Pn=new Map,st=new Map,Je=new Map,Sn=new Map;function D(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Ko(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=Mo(e,t,r.defaultImport,r.importPath,n)),t}function Ko(e,t,r,n,o,i){return i==="cjs"?Tn(e,t,null,r,n):yn(e,t,null,r,n,o)}function Mo(e,t,r,n,o){return o==="cjs"?Tn(e,t,r,null,n):yn(e,t,r,null,n,!1)}function yn(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 h=a[u];if(!e.ts.isImportDeclaration(h)||(s=u,!h.moduleSpecifier||!e.ts.isStringLiteral(h.moduleSpecifier))||h.moduleSpecifier.text!==o||!!h.importClause?.isTypeOnly!==i)continue;let m=[],g=h.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&m.push(...g.elements),typeof n=="string"){if(m.some(C=>C.name.text===n))return t;m.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),m.sort((C,P)=>C.name.text.localeCompare(P.name.text)),p=!0}let x=h.importClause?h.importClause.name:void 0;if(typeof r=="string"){if(x&&x.text===r)return t;x=e.ts.factory.createIdentifier(r),l=!0}if(p||l)return a[u]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,x,e.ts.factory.createNamedImports(m)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,f;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(f=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,f),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function Tn(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],f=d[l],c=f.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 h=c.arguments[0];if(e.ts.isStringLiteral(h)&&(a=s,h.text===o)){if(e.ts.isIdentifier(f.name)&&typeof r=="string")return f.name.text===r?t:(d[l]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createIdentifier(r),f.exclamationToken,f.type,f.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(f.name)&&typeof n=="string"){let m=[...f.name.elements];return m.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(m.push(e.ts.factory.createBindingElement(void 0,void 0,n)),m.sort((x,C)=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:x.name.text.localeCompare(C.name.text)),d[l]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createObjectBindingPattern(m),f.exclamationToken,f.type,f.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"?zo(e,t):Uo(e,t)}function Uo(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})}}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 zo(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 qo(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 Pe(e,t,r,n){let o=qo(e,r,n);if(o){let i=await We(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 Le(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 M(e,t,r){let n=Le(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 lt(e,t){if(t){if(Qo(e,t))return!0;let r=!1;if(t.forEachChild(n=>{lt(e,n)&&(r=!0)}),r)return!0}return!1}function Qo(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 We(e,t){let r=e.extname(t).toLowerCase();if(r===""||!vt.includes(r)){for(let n of vt){let o=t+n;if(await e.exists(o))return o}for(let n of vt){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var vt=[".tsx",".jsx",".ts",".js"];function Ye(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=Jo(e,i);return a?[{name:a}]:void 0}function Jo(e,t){if(typeof t=="string"){t=e.normalize(X(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 ie(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 ke(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await $(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 ye(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=be(e,o,l.node.fnNode))}return a}))}async function _e(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Oe(e,t.cmpInfo.filePath,r),a=(await ye(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 be(e,o,a.node.fnNode)}return[]}async function Dn(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 Wo(e,t,n)}return null}function Wo(e,t,r){let n=E(e,r);return ye(e,null,t,n)}async function ye(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 Yo(e,t,r,a);o.push(...s)})),o}async function Yo(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=k(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Ue(s.name.text))continue;let p=Ge(e,t,s.initializer);if(p){let l=p.name||s.name.text,d=n.isDefaultExport?"default":l,f=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:j(l),inputs:[],exportName:d,exportType:f,importName:l,filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}}return o}if(e.ts.isArrowFunction(n.node)){let s=Ge(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:Ae(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&&!Ue(s))return o;let p=Ge(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,f=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:f,importName:p.name||Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}return o}if(e.ts.isExportSpecifier(n.node)&&Ue(n.node.getText())){let s=Ge(e,t,n.node);if(s){let p=s.name||Y(e,r),l=n.isDefaultExport||!s.name?"default":s.name,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:s.name||Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function Ge(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return lt(e,r.body)?{name:"",fnNode:r,deps:Ye(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return lt(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Ye(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:Ge(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)||!Ue(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Ye(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Ye(e,t,n)}}return null}async function En(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(Ho(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await ye(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Go=new Set(["node_modules","dist"]);function Ho(e,t){for(let r of Go)if(e.dirname(t).includes(r))return!0;return!1}async function wn(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&&Xo.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 ye(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Xo=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 ae(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,[...bt(e,r),...bt(e,n),...bt(e,o),...i])}function H(e){let t=e.split(`
|
|
21
|
+
`,r+=");";let n=pt(e,r);return bt(e,n,t)}function bt(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]=$(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 ln(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=We.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}We.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=We.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=yn.get(p),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new ct(p)}return a.includes("node_modules")&&(s?We.set(a,{exists:!0,content:s}):We.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 Ko(e,i,t)}catch(a){if(a instanceof ct){await Mo(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Ko(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=Tn.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,Tn.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 Oe(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 ct=class{constructor(t){this.libName=t}};async function Mo(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;lt.has(t)||lt.set(t,fetch(r).then(n=>n.text()).then(n=>{yn.set(t,n)})),await lt.get(t),lt.delete(t)}var yn=new Map,lt=new Map,We=new Map,Tn=new Map;function E(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Uo(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=zo(e,t,r.defaultImport,r.importPath,n)),t}function Uo(e,t,r,n,o,i){return i==="cjs"?En(e,t,null,r,n):Dn(e,t,null,r,n,o)}function zo(e,t,r,n,o){return o==="cjs"?En(e,t,r,null,n):Dn(e,t,r,null,n,!1)}function Dn(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 h=a[m];if(!e.ts.isImportDeclaration(h)||(s=m,!h.moduleSpecifier||!e.ts.isStringLiteral(h.moduleSpecifier))||h.moduleSpecifier.text!==o||!!h.importClause?.isTypeOnly!==i)continue;let u=[],d=h.importClause?.namedBindings;if(d&&e.ts.isNamedImports(d)&&d.elements&&u.push(...d.elements),typeof n=="string"){if(u.some(C=>C.name.text===n))return t;u.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),u.sort((C,P)=>C.name.text.localeCompare(P.name.text)),p=!0}let x=h.importClause?h.importClause.name:void 0;if(typeof r=="string"){if(x&&x.text===r)return t;x=e.ts.factory.createIdentifier(r),l=!0}if(p||l)return a[m]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,x,e.ts.factory.createNamedImports(u)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let g,f;typeof r=="string"&&(g=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(f=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,g,f),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function En(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 g=[...p.declarationList.declarations],f=g[l],c=f.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 h=c.arguments[0];if(e.ts.isStringLiteral(h)&&(a=s,h.text===o)){if(e.ts.isIdentifier(f.name)&&typeof r=="string")return f.name.text===r?t:(g[l]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createIdentifier(r),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,g)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(f.name)&&typeof n=="string"){let u=[...f.name.elements];return u.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(u.push(e.ts.factory.createBindingElement(void 0,void 0,n)),u.sort((x,C)=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:x.name.text.localeCompare(C.name.text)),g[l]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createObjectBindingPattern(u),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,g)),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"?Qo(e,t):qo(e,t)}function qo(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})}}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 Qo(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 Jo(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=Jo(e,r,n);if(o){let i=await Ye(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:O(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function Le(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=Le(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 mt(e,t){if(t){if(Wo(e,t))return!0;let r=!1;if(t.forEachChild(n=>{mt(e,n)&&(r=!0)}),r)return!0}return!1}function Wo(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 Ye(e,t){let r=e.extname(t).toLowerCase();if(r===""||!It.includes(r)){for(let n of It){let o=t+n;if(await e.exists(o))return o}for(let n of It){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var It=[".tsx",".jsx",".ts",".js"];function Ge(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=Yo(e,i);return a?[{name:a}]:void 0}function Yo(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 ke(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 De(e,o,a.filePath,s)).find(g=>g.cmpInfo.id===a.id);l&&(a.inputs=be(e,o,l.node.fnNode))}return a}))}async function _e(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Oe(e,t.cmpInfo.filePath,r),a=(await De(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 be(e,o,a.node.fnNode)}return[]}async function wn(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 Go(e,t,n)}return null}function Go(e,t,r){let n=w(e,r);return De(e,null,t,n)}async function De(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 Ho(e,t,r,a);o.push(...s)})),o}async function Ho(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=k(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!ze(s.name.text))continue;let p=He(e,t,s.initializer);if(p){let l=p.name||s.name.text,g=n.isDefaultExport?"default":l,f=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,g),displayFilePath:O(e,r),name:j(l),inputs:[],exportName:g,exportType:f,importName:l,filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}}return o}if(e.ts.isArrowFunction(n.node)){let s=He(e,t,n.node);if(s){let p=Y(e,r),l=n.isDefaultExport?"default":p,g=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:O(e,r),name:p,inputs:[],exportName:l,exportType:g,importName:Ae(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&&!ze(s))return o;let p=He(e,t,n.node);if(p){let l=p.name||Y(e,r),g=n.isDefaultExport||!p.name?"default":p.name,f=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,g),displayFilePath:O(e,r),name:l,inputs:[],exportName:g,exportType:f,importName:p.name||Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}return o}if(e.ts.isExportSpecifier(n.node)&&ze(n.node.getText())){let s=He(e,t,n.node);if(s){let p=s.name||Y(e,r),l=n.isDefaultExport||!s.name?"default":s.name,g=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:O(e,r),name:p,inputs:[],exportName:l,exportType:g,importName:s.name||Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function He(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return mt(e,r.body)?{name:"",fnNode:r,deps:Ge(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return mt(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Ge(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:He(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)||!ze(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Ge(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Ge(e,t,n)}}return null}async function vn(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(Zo(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await De(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Xo=new Set(["node_modules","dist"]);function Zo(e,t){for(let r of Xo)if(e.dirname(t).includes(r))return!0;return!1}async function bn(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&&ei.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 De(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var ei=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,[...Rt(e,r),...Rt(e,n),...Rt(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 Rn(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 Te(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=bn(e,r),i=bn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function bn(e,t){let r=t.properties.find(n=>b(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function Nn(e){let t=await e.readFile(e.registryPath);return t?Zo(e,t):{components:[],sourceFile:E(e,"")}}async function Zo(e,t){let r=E(e,t);return e.sdkVersion===O.gen2?ti(e,r):ei(e,r)}async function ei(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 f=l[0];if(e.ts.isCallExpression(f)){let c=e.ts.isIdentifier(f.expression)&&f.expression.text;if(c==="withChildren"){let h=Nt(e,f.arguments[0]);if(e.ts.isCallExpression(h)){let m=await It(e,n,h,d,!0);m&&r.push(m)}else{let m=h;if(e.ts.isIdentifier(m)){let g=await Rt(e,t,n,m,d,!0);g&&r.push(g)}}continue}if(c==="dynamic"){let h=await It(e,n,f,d,!1);h&&r.push(h);continue}let u=Nt(e,f.arguments[0]);if(e.ts.isCallExpression(u)&&e.ts.isIdentifier(u.expression)&&u.expression.text==="dynamic"){let h=await It(e,n,u,d,!1);h&&r.push(h);continue}if(e.ts.isIdentifier(u)){let h=await Rt(e,t,n,u,d,!1);h&&r.push(h);continue}continue}if(e.ts.isIdentifier(f)){let c=await Rt(e,t,n,f,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:Q(r)}}function Nt(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:Nt(e,t.arguments[0]):t}async function It(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 f=d.text;i.filePath=await je(e,f),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=k(e,i.filePath),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 f=d.expression;if(!e.ts.isCallExpression(f)||f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let u=f.arguments[0];if(!e.ts.isStringLiteral(u)||!e.ts.isIdentifier(p.name))return null;let h=u.text;i.filePath=await je(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=k(e,i.filePath),i.name=j(p.name.text),i.importName=p.name.text,i.exportName=p.name.text,i.exportType="named"}else return null;return i=W(e,i,n),i.displayFilePath=A(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName)),i}async function Rt(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 je(e,l.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(f=>!f.importClause||!f.importClause.namedBindings||!e.ts.isNamedImports(f.importClause.namedBindings)?!1:f.importClause.namedBindings.elements.some(c=>c.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await je(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=W(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName)),a}function je(e,t){return We(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function An(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 f=d.expression;if(!e.ts.isCallExpression(f))continue;let c=f.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(oe)),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 ti(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await At(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function At(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};ni(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(b(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 h=u[0];if(!e.ts.isArrowFunction(h))return null;let m=h.body;if(e.ts.isCallExpression(m)){if(m.expression.kind!==e.ts.SyntaxKind.ImportKeyword||m.arguments.length!==1)return null;let x=m.arguments[0];if(!e.ts.isStringLiteral(x))return null;let C=x.text;n.filePath=await je(e,C),n.relFilePath=e.relative(e.getRootDir(),n.filePath),n.importPath=k(e,n.filePath),n.name=Y(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(m)){let g=m.expression;if(!e.ts.isParenthesizedExpression(g))return null;let x=g.expression;if(!e.ts.isAwaitExpression(x))return null;let C=x.expression;if(!e.ts.isCallExpression(C)||C.expression.kind!==e.ts.SyntaxKind.ImportKeyword||C.arguments.length!==1)return null;let I=C.arguments[0];if(!e.ts.isStringLiteral(I)||!e.ts.isIdentifier(m.name))return null;let T=I.text;n.filePath=await je(e,T),n.relFilePath=e.relative(e.getRootDir(),n.filePath),n.importPath=k(e,n.filePath),n.name=j(m.name.text),n.importName=m.name.text,n.exportName=m.name.text,n.exportType="named"}else return null;return n=W(e,n,r),n.displayFilePath=A(e,n.filePath),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await Pe(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=k(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),f=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(f){let c=f.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(h=>!h.importClause||!h.importClause.namedBindings||!e.ts.isNamedImports(h.importClause.namedBindings)?!1:h.importClause.namedBindings.elements.some(m=>m.name.text===s));if(!c)return null;let u=c.moduleSpecifier;if(!e.ts.isStringLiteral(u))return null;n.exportName=s}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}function ni(e,t){for(let r of t.properties){if(!e.ts.isPropertyAssignment(r)||!e.ts.isIdentifier(r.name))continue;if(b(e,r)==="canHaveChildren"){let{initializer:o}=r;return o.kind===e.ts.SyntaxKind.TrueKeyword}}return!1}function se(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 f=d.name;if(f&&e.ts.isIdentifier(f)){let c=f.text;Fn(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;Fn(e,t,p)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Fn(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 pe(e,t,r,n,o,i,a){let s=null,p=null,l=null,d=-1;t=J(t),r=J(r);let f=t.find(u=>u.id===e),c=r.find(u=>u.id===e);if(n)c||(s={...J(f),inputs:J(f.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=J(c),r=r.filter(u=>u.id!==e);else if(i!=null)ri(c,i),d=c.nodeIndex,l=c;else if(a!=null){let u=c.inputs.find(h=>h.name===a.name);u&&(a.registerInput===!1?u.isRegistered=!1:(oi(u,a),u.isRegistered=!0),l=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:p,updateRegisteredCmp:l,nodeIndex:d,components:ee(t,r)}}function ee(e,t){let r=Q([...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(Et),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=Dt(n))}),r}function ri(e,t){U(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),U(t.description)?e.description=t.description:t.description===null&&delete e.description,U(t.image)?e.image=t.image:t.image===null&&delete e.image}function oi(e,t){U(t.type)&&(e.type=t.type),U(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,U(t.defaultValue)||Me(t.defaultValue)||Fe(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,U(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 De(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 $(e,[...t])}function Ee(e,t,r){return Le(e,t,r.variableName)?t:ii(e,t,r)}function ii(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 le(e,t,r,n,o,i,a,s){let p=await De(e),[l,d,f,c]=await Promise.all([wn(e,p),Nn(e),Ft(e),Ke(e)]),u=l.map(P=>P.cmpInfo),h=d.components,m={components:ee(u,h),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(u),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return m.components=await ke(e,m.components),m;let g=!1,x=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let R=l.find(B=>B.cmpInfo.id===S);if(!R)throw new Error(`Component ${S} not found`);return R}),I=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),T=await $(e,I);for(let S of P){let R=m.components.find(w=>w.id===S.cmpInfo.id),B=await _e(e,S,T);Z(R,B);let F=u.findIndex(w=>w.id===S.cmpInfo.id);u[F].inputs=B;let y=pe(S.cmpInfo.id,u,h,r,n,o,i);if(e.sdkVersion===O.gen2){let{elements:w,elmIndex:V,statementIndex:z,statement:q,variableDeclaration:L}=await pi(e,x,S);if(y.addCmpToRegistry)w.push(si(e,y.addCmpToRegistry)),g=!0;else if(y.removeCmpFromRegistry)w.splice(V,1),g=!0;else if(y.updateRegisteredCmp){let fe=K(e,w[V],y.updateRegisteredCmp);w[V]=e.ts.factory.updateObjectLiteralExpression(fe,[Ln(e,y.updateRegisteredCmp),...fe.properties.slice(1)]),g=!0}if(g&&a){let fe=[...x.statements];fe[z]=e.ts.factory.updateVariableStatement(q,q.modifiers,e.ts.factory.updateVariableDeclarationList(q.declarationList,[e.ts.factory.updateVariableDeclaration(L,L.name,L.exclamationToken,L.type,e.ts.factory.createArrayLiteralExpression(Te(e,w)))])),x=e.ts.factory.updateSourceFile(x,fe),x=On(e,y,x),x=D(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),x=Ee(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),m.components=y.components,h=y.components.filter(to=>to.isRegistered)}}else{let w=[...x.statements];y.addCmpToRegistry?(w.push(Cn(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(w.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(w[y.nodeIndex]=wt(e,w[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a&&(x=e.ts.factory.updateSourceFile(x,w),x=D(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=An(e,x,f),x=On(e,y,x),R?.acceptsChildren&&(x=D(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),m.components=y.components,h=y.components.filter(V=>V.isRegistered))}}}if(g&&a){x=se(e,x),x=ae(e,x),e.appDir&&(x=Rn(e,x));let P=N(e,x);P=H(P),e.appDir&&(P=In(P)),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return m}function Ln(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",li(e,t))}function ai(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function si(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([Ln(e,t),...t.acceptsChildren?[ai(e)]:[]],!0),t)}async function pi(e,t,r){let n=M(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 At(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function On(e,t,r){if(e.appDir){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=v(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 li(e,t){let r=v(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 kn(e){let t=[],r=await gi(e,t);return await hi(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await ui(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await fi(e,e.pagesDir,t)),t}async function _n(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await ci(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await di(e,e.pagesDir,t)),t}async function ci(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,jn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function ui(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,jn({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,mi(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function mi(e){let t=e.typescriptEnabled;return e.sdkVersion===O.gen2?`
|
|
31
|
+
`}function Rt(e,t){return t.sort((r,n)=>{let o=In(e,r),i=In(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function In(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 Nn(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
|
|
32
|
+
${e}`),e}function An(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=Rn(e,r),i=Rn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function Rn(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 Fn(e){let t=await e.readFile(e.registryPath);return t?ti(e,t):{components:[],sourceFile:w(e,"")}}async function ti(e,t){let r=w(e,t);return e.sdkVersion===I.gen2?ri(e,r):ni(e,r)}async function ni(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 g=l[1];if(!e.ts.isObjectLiteralExpression(g))continue;let f=l[0];if(e.ts.isCallExpression(f)){let c=e.ts.isIdentifier(f.expression)&&f.expression.text;if(c==="withChildren"){let h=Ft(e,f.arguments[0]);if(e.ts.isCallExpression(h)){let u=await Nt(e,n,h,g,!0);u&&r.push(u)}else{let u=h;if(e.ts.isIdentifier(u)){let d=await At(e,t,n,u,g,!0);d&&r.push(d)}}continue}if(c==="dynamic"){let h=await Nt(e,n,f,g,!1);h&&r.push(h);continue}let m=Ft(e,f.arguments[0]);if(e.ts.isCallExpression(m)&&e.ts.isIdentifier(m.expression)&&m.expression.text==="dynamic"){let h=await Nt(e,n,m,g,!1);h&&r.push(h);continue}if(e.ts.isIdentifier(m)){let h=await At(e,t,n,m,g,!1);h&&r.push(h);continue}continue}if(e.ts.isIdentifier(f)){let c=await At(e,t,n,f,g,!1);c&&r.push(c);continue}}return{sourceFile:t,components:Q(r)}}function Ft(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:Ft(e,t.arguments[0]):t}async function Nt(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 g=p.arguments[0];if(!e.ts.isStringLiteral(g))return null;let f=g.text;i.filePath=await je(e,f),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=k(e,i.filePath),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 g=l.expression;if(!e.ts.isAwaitExpression(g))return null;let f=g.expression;if(!e.ts.isCallExpression(f)||f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let m=f.arguments[0];if(!e.ts.isStringLiteral(m)||!e.ts.isIdentifier(p.name))return null;let h=m.text;i.filePath=await je(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=k(e,i.filePath),i.name=j(p.name.text),i.importName=p.name.text,i.exportName=p.name.text,i.exportType="named"}else return null;return i=J(e,i,n),i.displayFilePath=O(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName)),i}async function At(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 je(e,l.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(f=>!f.importClause||!f.importClause.namedBindings||!e.ts.isNamedImports(f.importClause.namedBindings)?!1:f.importClause.namedBindings.elements.some(c=>c.name.text===n.text));if(!l)return null;let g=l.moduleSpecifier;if(!e.ts.isStringLiteral(g))return null;a.filePath=await je(e,g.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=J(e,a,o),a.displayFilePath=O(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName)),a}function je(e,t){return Ye(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function On(e,t,r){let n=!1,o=0,i=[...t.statements];for(let l=0;l<i.length;l++){let g=i[l];if(e.ts.isImportDeclaration(g)){o=l;continue}if(!e.ts.isExpressionStatement(g))continue;let f=g.expression;if(!e.ts.isCallExpression(f))continue;let c=f.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 ri(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 Ot(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function Ot(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};oi(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 m=p.arguments;if(m.length===0)return null;let h=m[0];if(!e.ts.isArrowFunction(h))return null;let u=h.body;if(e.ts.isCallExpression(u)){if(u.expression.kind!==e.ts.SyntaxKind.ImportKeyword||u.arguments.length!==1)return null;let x=u.arguments[0];if(!e.ts.isStringLiteral(x))return null;let C=x.text;n.filePath=await je(e,C),n.relFilePath=e.relative(e.getRootDir(),n.filePath),n.importPath=k(e,n.filePath),n.name=Y(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(u)){let d=u.expression;if(!e.ts.isParenthesizedExpression(d))return null;let x=d.expression;if(!e.ts.isAwaitExpression(x))return null;let C=x.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(u.name))return null;let D=R.text;n.filePath=await je(e,D),n.relFilePath=e.relative(e.getRootDir(),n.filePath),n.importPath=k(e,n.filePath),n.name=j(u.name.text),n.importName=u.name.text,n.exportName=u.name.text,n.exportType="named"}else return null;return n=J(e,n,r),n.displayFilePath=O(e,n.filePath),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),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,n.importPath=k(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let g=t.statements.filter(c=>e.ts.isImportDeclaration(c)),f=g.find(c=>c.importClause&&c.importClause.name?.text===s);if(f){let c=f.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=g.find(h=>!h.importClause||!h.importClause.namedBindings||!e.ts.isNamedImports(h.importClause.namedBindings)?!1:h.importClause.namedBindings.elements.some(u=>u.name.text===s));if(!c)return null;let m=c.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;n.exportName=s}continue}}return n=J(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}function oi(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 g=p[l];if(e.ts.isImportSpecifier(g)){let f=g.name;if(f&&e.ts.isIdentifier(f)){let c=f.text;Ln(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)),g=e.ts.factory.updateImportDeclaration(i,void 0,l,i.moduleSpecifier,void 0);r[o]=g,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let p=i.importClause.name.text;Ln(e,t,p)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Ln(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,g=-1;t=W(t),r=W(r);let f=t.find(m=>m.id===e),c=r.find(m=>m.id===e);if(n)c||(s={...W(f),inputs:W(f.inputs).map(m=>(m.isRegistered=!0,m))},g=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)g=c.nodeIndex,p=W(c),r=r.filter(m=>m.id!==e);else if(i!=null)ii(c,i),g=c.nodeIndex,l=c;else if(a!=null){let m=c.inputs.find(h=>h.name===a.name);m&&(a.registerInput===!1?m.isRegistered=!1:(ai(m,a),m.isRegistered=!0),l=c,g=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:p,updateRegisteredCmp:l,nodeIndex:g,components:te(t,r)}}function te(e,t){let r=Q([...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(vt),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=wt(n))}),r}function ii(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 ai(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)||Ue(t.defaultValue)||Fe(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 Ee(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 Le(e,t,r.variableName)?t:si(e,t,r)}function si(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 Ee(e),[l,g,f,c]=await Promise.all([bn(e,p),Fn(e),Lt(e),Me(e)]),m=l.map(P=>P.cmpInfo),h=g.components,u={components:te(m,h),registryPath:e.registryPath,registryDisplayPath:O(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(m),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return u.components=await ke(e,u.components),u;let d=!1,x=g.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))),D=await M(e,R);for(let S of P){let N=u.components.find(y=>y.id===S.cmpInfo.id),B=await _e(e,S,D);ee(N,B);let L=m.findIndex(y=>y.id===S.cmpInfo.id);m[L].inputs=B;let T=me(S.cmpInfo.id,m,h,r,n,o,i);if(e.sdkVersion===I.gen2){let{elements:y,elmIndex:U,statementIndex:X,statement:K,variableDeclaration:A}=await ci(e,x,S);if(T.addCmpToRegistry)y.push(li(e,T.addCmpToRegistry)),d=!0;else if(T.removeCmpFromRegistry)y.splice(U,1),d=!0;else if(T.updateRegisteredCmp){let z=$(e,y[U],T.updateRegisteredCmp);y[U]=e.ts.factory.updateObjectLiteralExpression(z,[_n(e,T.updateRegisteredCmp),...z.properties.slice(1)]),d=!0}if(d&&a){let z=[...x.statements];z[X]=e.ts.factory.updateVariableStatement(K,K.modifiers,e.ts.factory.updateVariableDeclarationList(K.declarationList,[e.ts.factory.updateVariableDeclaration(A,A.name,A.exclamationToken,A.type,e.ts.factory.createArrayLiteralExpression(le(e,y)))])),x=e.ts.factory.updateSourceFile(x,z),x=kn(e,T,x),x=E(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),x=ue(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),u.components=T.components,h=T.components.filter($e=>$e.isRegistered)}}else{let y=[...x.statements];T.addCmpToRegistry?(y.push(Pn(e,T.addCmpToRegistry)),d=!0):T.removeCmpFromRegistry?(y.splice(T.nodeIndex,1),d=!0):T.updateRegisteredCmp&&(y[T.nodeIndex]=bt(e,y[T.nodeIndex],T.updateRegisteredCmp),d=!0),d&&a&&(x=e.ts.factory.updateSourceFile(x,y),x=E(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=On(e,x,f),x=kn(e,T,x),N?.acceptsChildren&&(x=E(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),u.components=T.components,h=T.components.filter(U=>U.isRegistered))}}}if(d&&a){x=ce(e,x),x=pe(e,x),e.appDir&&(x=An(e,x));let P=F(e,x);P=H(P),e.appDir&&(P=Nn(P)),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return u}function _n(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",mi(e,t))}function pi(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function li(e,t){return $(e,e.ts.factory.createObjectLiteralExpression([_n(e,t),...t.acceptsChildren?[pi(e)]:[]],!0),t)}async function ci(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 Ot(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function kn(e,t,r){if(e.appDir){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=b(e,e.registryPath,n.filePath);n.exportType==="default"?r=E(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=E(e,r,{namedImports:[n.importName],importPath:o}))}}else r=E(e,r,{defaultImport:"dynamic",importPath:"next/dynamic"});return r}function mi(e,t){let r=b(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 jn(e){let t=[],r=await hi(e,t);return await Si(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await fi(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await gi(e,e.pagesDir,t)),t}async function Bn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await ui(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await xi(e,e.pagesDir,t)),t}async function ui(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,Vn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function fi(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,Vn({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,di(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function di(e){let t=e.typescriptEnabled;return e.sdkVersion===I.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(b(e,e.builderComponentPath,e.registryPath))};
|
|
37
37
|
${t?`
|
|
38
38
|
interface BuilderPageProps {
|
|
39
39
|
content: BuilderContent | null;
|
|
@@ -41,7 +41,7 @@ interface BuilderPageProps {
|
|
|
41
41
|
}`:""}
|
|
42
42
|
|
|
43
43
|
// Builder Public API Key set in .env file
|
|
44
|
-
const builderApiKey = process.env.${
|
|
44
|
+
const builderApiKey = process.env.${ie}${t?"!":""};
|
|
45
45
|
|
|
46
46
|
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
47
47
|
// Call the isPreviewing hook to determine if
|
|
@@ -67,12 +67,12 @@ ${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(b(e,e.builderComponentPath,e.registryPath))};
|
|
71
71
|
${t?`
|
|
72
72
|
type BuilderPageProps = ComponentProps<typeof BuilderComponent>;`:""}
|
|
73
73
|
|
|
74
74
|
// Builder Public API Key set in .env file
|
|
75
|
-
builder.init(process.env.${
|
|
75
|
+
builder.init(process.env.${ie}${t?"!":""});
|
|
76
76
|
|
|
77
77
|
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
78
78
|
// Call the useIsPreviewing hook to determine if
|
|
@@ -88,12 +88,12 @@ 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 Vn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=b(e,t,e.builderComponentPath);return e.sdkVersion===I.gen2?`
|
|
92
92
|
import { fetchOneEntry } from "@builder.io/sdk-react";
|
|
93
93
|
import { RenderBuilderContent } from ${JSON.stringify(o)};
|
|
94
94
|
|
|
95
95
|
// Builder Public API Key set in .env file
|
|
96
|
-
const PUBLIC_API_KEY = process.env.${
|
|
96
|
+
const PUBLIC_API_KEY = process.env.${ie}${n?"!":""};
|
|
97
97
|
|
|
98
98
|
${n?`
|
|
99
99
|
interface PageProps {
|
|
@@ -127,7 +127,7 @@ import { builder } from "@builder.io/sdk";
|
|
|
127
127
|
import { RenderBuilderContent } from ${JSON.stringify(o)};
|
|
128
128
|
|
|
129
129
|
// Builder Public API Key set in .env file
|
|
130
|
-
builder.init(process.env.${
|
|
130
|
+
builder.init(process.env.${ie}${n?"!":""});
|
|
131
131
|
${n?`
|
|
132
132
|
interface PageProps {
|
|
133
133
|
params: {
|
|
@@ -156,7 +156,7 @@ export default async function Page(props${n?": PageProps":""}) {
|
|
|
156
156
|
</>
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
|
-
`.trimStart()}async function
|
|
159
|
+
`.trimStart()}async function gi(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,$n({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function xi(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,$n({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function $n({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return e.sdkVersion===I.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,9 +169,9 @@ 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(b(e,e.builderComponentPath,e.registryPath))};
|
|
173
173
|
|
|
174
|
-
const BUILDER_API_KEY = process.env.${
|
|
174
|
+
const BUILDER_API_KEY = process.env.${ie}${n?"!":""};
|
|
175
175
|
|
|
176
176
|
// Define a function that fetches the Builder
|
|
177
177
|
// content for a given page
|
|
@@ -252,9 +252,9 @@ 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(b(e,t,e.registryPath))};
|
|
256
256
|
|
|
257
|
-
builder.init(process.env.${
|
|
257
|
+
builder.init(process.env.${ie}${n?"!":""});
|
|
258
258
|
|
|
259
259
|
// Define a function that fetches the Builder
|
|
260
260
|
// content for a given page
|
|
@@ -318,7 +318,7 @@ export default function Page({ page }${n?": { page: BuilderContent | null }":""}
|
|
|
318
318
|
</>
|
|
319
319
|
);
|
|
320
320
|
}
|
|
321
|
-
`.trimStart()}async function
|
|
321
|
+
`.trimStart()}async function hi(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}=Ci(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 Ci(e){let t=e.typescriptEnabled,r=`
|
|
322
322
|
"use client"
|
|
323
323
|
import React, { useState } from "react";
|
|
324
324
|
import styles from "./styles.module.css";
|
|
@@ -381,18 +381,18 @@ 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 Si(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===I.gen2){let i=Pi(e);await e.writeFile(e.registryPath,i)}else await e.writeFile(e.registryPath,"");r.push({filePath:e.registryPath,modifiedType:"create"})}let o=(await fe(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await fe(e,o.id,!0,!1,null,null,!0,!1)}function Pi(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 Be(e){let t=await
|
|
389
|
+
`}async function Be(e){let t=await st(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 I.gen2;if(r.has("@builder.io/react"))return I.gen1}return null}async function Kn(e){let t=await Ti(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>jn(t),ensureFigmaImportPage:()=>Bn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>fe(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),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:()=>Me(t),setPublicApiKey:n=>fn(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===I.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 Ti(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await yi(e),o=await Lt(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(e.sdkVersion?a.sdkVersion=e.sdkVersion:a.sdkVersion=await Be(a),await e.exists(r)){a.srcDir=r,a.componentsDir=e.join(r,"components");let s=e.join(r,"app");await e.exists(s)&&(a.appDir=s);let p=e.join(r,"pages");await e.exists(p)&&(a.pagesDir=p),a.registryPath=e.join(r,i)}else a.componentsDir=e.join(t,"components"),a.registryPath=e.join(t,i);if(a.builderComponentPath=e.join(a.componentsDir,`builder.${o?"tsx":"jsx"}`),!a.appDir){let s=e.join(t,"app");await e.exists(s)&&(a.appDir=s)}if(!a.pagesDir){let s=e.join(t,"pages");await e.exists(s)&&(a.pagesDir=s)}if(!a.appDir&&!a.pagesDir)throw new Error(`Could not find Next.js "app" or "pages" directory. Searched in "${t}".`);return a}function Lt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function yi(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 Xe(e){return await Te(e,[".env"],Un)}async function Mn(e,t){Di(t);let r=await Xe(e),n=await ye(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function Di(e){typeof process<"u"&&(process.env[Un]=e)}var Un="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 Qn(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 ut(e,o,s,i);r.push(...p)})),r}async function Jn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return Ei(e,t,n)}return null}function Ei(e,t,r){let n=w(e,r);return ut(e,null,t,n)}async function ut(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 wi(e,t,r,a);s&&o.push(s)})),o}async function wi(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=k(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=qn(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let p=a.name.text;return{cmpInfo:{id:await _(e,r,p),displayFilePath:O(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=qn(e,n.node);if(a)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:O(e,r),name:Y(e,r),inputs:[],exportName:"default",exportType:"default",importName:Ae(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function qn(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 Wn(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 Oe(e,t.cmpInfo.filePath,null);if(!(await ut(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 be(e,i,r)}return[]}async function Yn(e){return kt(e)}async function kt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,bi),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var bi=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
|
|
392
392
|
|
|
393
393
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
394
394
|
];
|
|
395
|
-
`;async function Wn(e){await Ot(e);let t=await e.readFile(e.registryPath);return t?vi(e,t):{components:[],sourceFile:E(e,"")}}async function vi(e,t){let r=E(e,t);return bi(e,r)}async function bi(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Lt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function Lt(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(b(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 Pe(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=k(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let p=await qn(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=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function Yn(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 $(e,[...t])}async function Ie(e,t,r,n,o,i,a,s){let p=await Yn(e),[l,d,f]=await Promise.all([zn(e,p),Wn(e),He(e)]),c=l.map(m=>m.cmpInfo),u=d.components,h={components:ee(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let m=l.find(y=>y.cmpInfo.id===t);if(!m)throw new Error(`Component ${t} not found`);let g=d.sourceFile,x=h.components.find(y=>y.id===t),C=await Qn(e,m);Z(x,C),t=Array.isArray(t)?t[0]:t;let P=pe(t,c,u,r,n,o,i),{elements:I,elmIndex:T,statementIndex:S,statement:R,variableDeclaration:B}=await Ri(e,g,m),F=!1;if(P.addCmpToRegistry?(I.push(Ii(e,P.addCmpToRegistry)),F=!0):P.removeCmpFromRegistry?(I.splice(T,1),F=!0):P.updateRegisteredCmp&&(I[T]=K(e,I[T],P.updateRegisteredCmp),F=!0),F&&a){let y=[...g.statements];y[S]=e.ts.factory.updateVariableStatement(R,R.modifiers,e.ts.factory.updateVariableDeclarationList(R.declarationList,[e.ts.factory.updateVariableDeclaration(B,B.name,B.exclamationToken,B.type,e.ts.factory.createArrayLiteralExpression(Te(e,I)))])),g=e.ts.factory.updateSourceFile(g,y),x.exportType==="named"?g=D(e,g,{namedImports:[x.importName],importPath:v(e,e.registryPath,x.filePath)}):g=D(e,g,{defaultImport:x.importName,importPath:v(e,e.registryPath,x.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=Ee(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=se(e,g),g=ae(e,g);let w=N(e,g);w=H(w),w=Mn(w,Ni,"CUSTOM_COMPONENTS"),w=await e.formatCode(e.registryPath,w),await e.writeFile(e.registryPath,w)}h.components=P.components}return h}function Ii(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Ri(e,t,r){let n=M(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 Lt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Ni=["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 Gn(e){let t=await Ai(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>Jn(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ie(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Ie(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ie(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ie(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ie(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ie(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>He(t),setPublicApiKey:n=>$n(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>ne(t),setCache:n=>re(t,n)}}async function Ai(e){let t=await $e(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 Xe(e){return await Ce(e,[".env"],Ze)}async function Hn(e,t){let r=await Xe(e),n=await Se(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Ze="PUBLIC_BUILDER_KEY";async function Xn(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"||Fi.has(s)||s.includes("$."))return;let p=e.normalize(a.fileName);if(p===e.remixConfigPath||p===e.registryPath||p===i)return;let l=await ye(e,o,p,a);r.push(...l)})),r}var Fi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Zn(e){await _t(e);let t=await e.readFile(e.registryPath);return t?Oi(e,t):{components:[],sourceFile:E(e,"")}}async function Oi(e,t){let r=E(e,t);return Li(e,r)}async function Li(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await kt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function kt(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(b(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 f=s.arguments[0];e.ts.isIdentifier(f)&&(a=f.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await Pe(e,e.registryPath,t,a);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,n.importPath=k(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await Dn(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(f=>f.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function ce(e,t,r,n,o,i,a,s){let p=await De(e),[l,d,f]=await Promise.all([Xn(e,p),Zn(e),Xe(e)]),c=l.map(C=>C.cmpInfo),u=d.components,h={components:ee(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await ke(e,h.components),h;let m=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(T=>{let S=l.find(R=>R.cmpInfo.id===T);if(!S)throw new Error(`Component ${T} not found`);return S}),P=Array.from(new Set(C.map(T=>T.cmpInfo.filePath))),I=await $(e,P);for(let T of C){let S=h.components.find(L=>L.id===T.cmpInfo.id),R=await _e(e,T,I);Z(S,R);let B=c.findIndex(L=>L.id===T.cmpInfo.id);c[B].inputs=R;let F=pe(T.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:w,statementIndex:V,statement:z,variableDeclaration:q}=await _i(e,g,T);if(F.addCmpToRegistry)y.push(ki(e,F.addCmpToRegistry)),m=!0;else if(F.removeCmpFromRegistry)y.splice(w,1),m=!0;else if(F.updateRegisteredCmp){let L=K(e,y[w],F.updateRegisteredCmp);y[w]=e.ts.factory.updateObjectLiteralExpression(L,[er(e,F.updateRegisteredCmp),...L.properties.slice(1)]),m=!0}if(m&&a){let L=[...g.statements];L[V]=e.ts.factory.updateVariableStatement(z,z.modifiers,e.ts.factory.updateVariableDeclarationList(z.declarationList,[e.ts.factory.updateVariableDeclaration(q,q.name,q.exclamationToken,q.type,e.ts.factory.createArrayLiteralExpression(Te(e,y)))])),g=e.ts.factory.updateSourceFile(g,L),S.exportType==="named"?g=D(e,g,{namedImports:[S.importName],importPath:v(e,e.registryPath,S.filePath)}):g=D(e,g,{defaultImport:S.importName,importPath:v(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=Ee(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=F.components,u=F.components.filter(fe=>fe.isRegistered)}}}if(m&&a){g=se(e,g),g=ae(e,g);let C=N(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function er(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 ki(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([er(e,t)],!0),t)}async function _i(e,t,r){let n=M(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 kt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function tr(e){let t=[],r=await Vi(e,t);return t.push(...await _t(e)),await Ki(e,r),await Bi(e,t),t}async function nr(e){let t=[];return await ji(e,t),t}async function ji(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,rr({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Bi(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,rr({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function rr({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=v(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${Ze}`;return e.getFrameworks().some(p=>p.name==="@shopify/remix-oxygen")&&(s=`context.env.${Ze}`),n&&(s+="!"),`
|
|
395
|
+
`;async function Gn(e){await kt(e);let t=await e.readFile(e.registryPath);return t?Ii(e,t):{components:[],sourceFile:w(e,"")}}async function Ii(e,t){let r=w(e,t);return Ri(e,r)}async function Ri(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:Q(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:[]};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=k(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let p=await Jn(e,s.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let l=p.find(g=>g.cmpInfo.exportName===a);l&&(n.exportName=l.cmpInfo.exportName)}continue}}return n=J(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function Hn(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 Ie(e,t,r,n,o,i,a,s){let p=await Hn(e),[l,g,f]=await Promise.all([Qn(e,p),Gn(e),Xe(e)]),c=l.map(u=>u.cmpInfo),m=g.components,h={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:O(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let u=l.find(T=>T.cmpInfo.id===t);if(!u)throw new Error(`Component ${t} not found`);let d=g.sourceFile,x=h.components.find(T=>T.id===t),C=await Wn(e,u);ee(x,C),t=Array.isArray(t)?t[0]:t;let P=me(t,c,m,r,n,o,i),{elements:R,elmIndex:D,statementIndex:S,statement:N,variableDeclaration:B}=await Ai(e,d,u),L=!1;if(P.addCmpToRegistry?(R.push(Ni(e,P.addCmpToRegistry)),L=!0):P.removeCmpFromRegistry?(R.splice(D,1),L=!0):P.updateRegisteredCmp&&(R[D]=$(e,R[D],P.updateRegisteredCmp),L=!0),L&&a){let T=[...d.statements];T[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)))])),d=e.ts.factory.updateSourceFile(d,T),x.exportType==="named"?d=E(e,d,{namedImports:[x.importName],importPath:b(e,e.registryPath,x.filePath)}):d=E(e,d,{defaultImport:x.importName,importPath:b(e,e.registryPath,x.filePath)}),d=E(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),d=ue(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),d=ce(e,d),d=pe(e,d);let y=F(e,d);y=H(y),y=zn(y,Fi,"CUSTOM_COMPONENTS"),y=await e.formatCode(e.registryPath,y),await e.writeFile(e.registryPath,y)}h.components=P.components}return h}function Ni(e,t){return $(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Ai(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}}var Fi=["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 Xn(e){let t=await Oi(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>Yn(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ie(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Ie(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ie(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ie(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ie(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ie(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Xe(t),setPublicApiKey:n=>Mn(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 Oi(e){let t=await Ke(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 Zn(e,t){let r=await Ze(e),n=await ye(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var et="PUBLIC_BUILDER_KEY";async function er(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"||Li.has(s)||s.includes("$."))return;let p=e.normalize(a.fileName);if(p===e.remixConfigPath||p===e.registryPath||p===i)return;let l=await De(e,o,p,a);r.push(...l)})),r}var Li=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function tr(e){await Bt(e);let t=await e.readFile(e.registryPath);return t?ki(e,t):{components:[],sourceFile:w(e,"")}}async function ki(e,t){let r=w(e,t);return _i(e,r)}async function _i(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 jt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function jt(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 f=s.arguments[0];e.ts.isIdentifier(f)&&(a=f.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=k(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await wn(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let g=l.find(f=>f.cmpInfo.exportName===a);g&&(n.exportName=g.cmpInfo.exportName)}continue}}return n=J(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 Ee(e),[l,g,f]=await Promise.all([er(e,p),tr(e),Ze(e)]),c=l.map(C=>C.cmpInfo),m=g.components,h={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:O(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await ke(e,h.components),h;let u=!1,d=g.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(D=>{let S=l.find(N=>N.cmpInfo.id===D);if(!S)throw new Error(`Component ${D} not found`);return S}),P=Array.from(new Set(C.map(D=>D.cmpInfo.filePath))),R=await M(e,P);for(let D of C){let S=h.components.find(A=>A.id===D.cmpInfo.id),N=await _e(e,D,R);ee(S,N);let B=c.findIndex(A=>A.id===D.cmpInfo.id);c[B].inputs=N;let L=me(D.cmpInfo.id,c,m,r,n,o,i),{elements:T,elmIndex:y,statementIndex:U,statement:X,variableDeclaration:K}=await Bi(e,d,D);if(L.addCmpToRegistry)T.push(ji(e,L.addCmpToRegistry)),u=!0;else if(L.removeCmpFromRegistry)T.splice(y,1),u=!0;else if(L.updateRegisteredCmp){let A=$(e,T[y],L.updateRegisteredCmp);T[y]=e.ts.factory.updateObjectLiteralExpression(A,[nr(e,L.updateRegisteredCmp),...A.properties.slice(1)]),u=!0}if(u&&a){let A=[...d.statements];A[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration(K,K.name,K.exclamationToken,K.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),d=e.ts.factory.updateSourceFile(d,A),S.exportType==="named"?d=E(e,d,{namedImports:[S.importName],importPath:b(e,e.registryPath,S.filePath)}):d=E(e,d,{defaultImport:S.importName,importPath:b(e,e.registryPath,S.filePath)}),d=E(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),S.acceptsChildren&&(d=E(e,d,{namedImports:["withChildren"],importPath:"@builder.io/react"})),d=ue(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=L.components,m=L.components.filter(z=>z.isRegistered)}}}if(u&&a){d=ce(e,d),d=pe(e,d);let C=F(e,d);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function nr(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 ji(e,t){return $(e,e.ts.factory.createObjectLiteralExpression([nr(e,t)],!0),t)}async function Bi(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 jt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function rr(e){let t=[],r=await Ki(e,t);return t.push(...await Bt(e)),await Ui(e,r),await $i(e,t),t}async function or(e){let t=[];return await Vi(e,t),t}async function Vi(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,ir({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function $i(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,ir({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function ir({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=b(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+="!"),`
|
|
396
396
|
import { BuilderComponent, builder } from "@builder.io/react";
|
|
397
397
|
import { useLoaderData } from "@remix-run/react";
|
|
398
398
|
import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
|
|
@@ -449,11 +449,11 @@ export default function Page() {
|
|
|
449
449
|
${n?`
|
|
450
450
|
declare global {
|
|
451
451
|
interface Env {
|
|
452
|
-
${
|
|
452
|
+
${et}: string;
|
|
453
453
|
}
|
|
454
454
|
}
|
|
455
455
|
`:""}
|
|
456
|
-
`}async function
|
|
456
|
+
`}async function Ki(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}=Mi(e),l=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${l}`),!l){let f=await e.formatCode(i,s);await e.writeFile(i,f),t.push({filePath:i,modifiedType:"create"})}let g=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${g}`),g||(await e.writeFile(a,p),t.push({filePath:a,modifiedType:"create"})),i}function Mi(e){let t=e.typescriptEnabled,r=`
|
|
457
457
|
import { useState } from "react";
|
|
458
458
|
import styles from "./styles.module.css";
|
|
459
459
|
${t?`
|
|
@@ -516,23 +516,82 @@ export default Counter;
|
|
|
516
516
|
font-size: 42px;
|
|
517
517
|
text-align: center;
|
|
518
518
|
}
|
|
519
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
519
|
+
`.trimStart();return{component:r,styles:n}}async function Ui(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 Bt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,zi(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function zi(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/react";
|
|
520
520
|
|
|
521
521
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
522
522
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
523
523
|
];
|
|
524
|
-
`}async function
|
|
524
|
+
`}async function ar(e){let t=await qi(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:()=>rr(t),ensureFigmaImportPage:()=>or(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>de(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),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:()=>Ze(t),setPublicApiKey:n=>Zn(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===I.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 qi(e){let t=await Wi(e),r=await Yi(e),n=e.dirname(r),o=e.join(n,"components"),i=await Qi(e),a=`builder-registry.${i?"ts":"js"}`,s=e.join(n,a),p={...e,registryPath:s,remixConfigPath:t,typescriptEnabled:i,appDir:n,componentsDir:o,routesDir:r,hasLocaleParam:await Ji(e,r)};return p.sdkVersion=await Be(p),p}function Qi(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Ji(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Wi(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 Yi(e){let t=await Ke(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 tt(e){let t=[".env"],r=e.configType==="vite"?nt:ft;return await Te(e,t,r)}async function sr(e,t){let r=await tt(e),n=await ye(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var nt="VITE_PUBLIC_BUILDER_KEY",ft="YOUR_PUBLIC_BUILDER_KEY";function pr(e,t){let r=`Builder.registerComponent(
|
|
525
525
|
`;r+=` ${t.importName},
|
|
526
526
|
`,r+=` {
|
|
527
527
|
name: "${t.name}",
|
|
528
528
|
}
|
|
529
|
-
`,r+=");";let n=
|
|
529
|
+
`,r+=");";let n=pt(e,r);return Vt(e,n,t)}function Vt(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]=$(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?Gi(e,t):{components:[],sourceFile:w(e,"")}}async function Gi(e,t){let r=w(e,t);return e.sdkVersion===I.gen2?Zi(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 g=l[1];if(!e.ts.isObjectLiteralExpression(g))continue;let f=l[0];if(e.ts.isIdentifier(f)){let c=await Xi(e,t,n,f,g,!1);c&&r.push(c);continue}}return{sourceFile:t,components:Q(r)}}async function Xi(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 lr(e,l.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(f=>!f.importClause||!f.importClause.namedBindings||!e.ts.isNamedImports(f.importClause.namedBindings)?!1:f.importClause.namedBindings.elements.some(c=>c.name.text===n.text));if(!l)return null;let g=l.moduleSpecifier;if(!e.ts.isStringLiteral(g))return null;a.filePath=await lr(e,g.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=J(e,a,o),a.displayFilePath=O(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName)),a}function lr(e,t){return Ye(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function Zi(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:Q(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};ea(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.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,n.importPath=k(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let g=t.statements.filter(c=>e.ts.isImportDeclaration(c)),f=g.find(c=>c.importClause&&c.importClause.name?.text===s);if(f){let c=f.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=g.find(h=>!h.importClause||!h.importClause.namedBindings||!e.ts.isNamedImports(h.importClause.namedBindings)?!1:h.importClause.namedBindings.elements.some(u=>u.name.text===s));if(!c)return null;let m=c.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;n.exportName=s}continue}}return n=J(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}function ea(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}async function ge(e,t,r,n,o,i,a,s){let p=await Ee(e),[l,g,f,c]=await Promise.all([vn(e,p),cr(e),Kt(e),tt(e)]),m=l.map(P=>P.cmpInfo),h=g.components,u={components:te(m,h),registryPath:e.registryPath,registryDisplayPath:O(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(m),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return u.components=await ke(e,u.components),u;let d=!1,x=g.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))),D=await M(e,R);for(let S of P){let N=u.components.find(y=>y.id===S.cmpInfo.id),B=await _e(e,S,D);ee(N,B);let L=m.findIndex(y=>y.id===S.cmpInfo.id);m[L].inputs=B;let T=me(S.cmpInfo.id,m,h,r,n,o,i);if(e.sdkVersion===I.gen2){let{elements:y,elmIndex:U,statementIndex:X,statement:K,variableDeclaration:A}=await ta(e,x,S);if(T.addCmpToRegistry)y.push(na(e,T.addCmpToRegistry)),d=!0;else if(T.removeCmpFromRegistry)y.splice(U,1),d=!0;else if(T.updateRegisteredCmp){let z=$(e,y[U],T.updateRegisteredCmp),$e=e.ts.factory.createIdentifier(T.updateRegisteredCmp.importName);y[U]=e.ts.factory.updateObjectLiteralExpression(z,[e.ts.factory.createPropertyAssignment("component",$e),...z.properties.slice(1)]),d=!0}if(d&&a){let z=[...x.statements];z[X]=e.ts.factory.updateVariableStatement(K,K.modifiers,e.ts.factory.updateVariableDeclarationList(K.declarationList,[e.ts.factory.updateVariableDeclaration(A,A.name,A.exclamationToken,A.type,e.ts.factory.createArrayLiteralExpression(le(e,y)))])),x=e.ts.factory.updateSourceFile(x,z),x=mr(e,T,x),x=E(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),x=ue(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),u.components=T.components,h=T.components.filter($e=>$e.isRegistered)}}else{let y=[...x.statements];T.addCmpToRegistry?(y.push(pr(e,T.addCmpToRegistry)),d=!0):T.removeCmpFromRegistry?(y.splice(T.nodeIndex,1),d=!0):T.updateRegisteredCmp&&(y[T.nodeIndex]=Vt(e,y[T.nodeIndex],T.updateRegisteredCmp),d=!0),d&&a&&(x=e.ts.factory.updateSourceFile(x,y),x=E(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=mr(e,T,x),N?.acceptsChildren&&(x=E(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),u.components=T.components,h=T.components.filter(U=>U.isRegistered))}}}if(d&&a){x=ce(e,x),x=pe(e,x);let P=F(e,x);P=H(P),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return u}async function ta(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 na(e,t){let r=e.ts.factory.createIdentifier(t.importName);return $(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 mr(e,t,r){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=b(e,e.registryPath,n.filePath);n.exportType==="default"?r=E(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=E(e,r,{namedImports:[n.importName],importPath:o}))}return r}async function ur(e){let t=[],r=await ia(e,t);if(await oa(e,r,t),!await e.exists(e.builderComponentPath)){let n=await e.formatCode(e.builderComponentPath,ra(e));await e.writeFile(e.builderComponentPath,n),t.push({filePath:e.builderComponentPath,modifiedType:"create"})}return t}async function fr(e){return[]}function ra(e){let t=e.typescriptEnabled;return e.sdkVersion===I.gen2?`
|
|
530
|
+
import React from "react";
|
|
531
|
+
import {
|
|
532
|
+
Content,
|
|
533
|
+
fetchOneEntry,
|
|
534
|
+
getBuilderSearchParams,
|
|
535
|
+
isPreviewing,
|
|
536
|
+
${t?"type BuilderContent,":""}
|
|
537
|
+
} from "@builder.io/sdk-react";
|
|
538
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(b(e,e.builderComponentPath,e.registryPath))};
|
|
539
|
+
|
|
540
|
+
// Builder Public API Key set in .env file
|
|
541
|
+
const BUILDER_API_KEY = ${e.configType==="vite"?`import.meta.env.${nt};`:`${ft};`}
|
|
542
|
+
const MODEL_NAME = "page";
|
|
543
|
+
|
|
544
|
+
export default function BuilderPage() {
|
|
545
|
+
const [notFound, setNotFound] = React.useState(false);
|
|
546
|
+
const [content, setContent] = React.useState${t?"<BuilderContent | null>":""}(null);
|
|
547
|
+
|
|
548
|
+
// get the page content from Builder
|
|
549
|
+
React.useEffect(() => {
|
|
550
|
+
fetchOneEntry({
|
|
551
|
+
model: MODEL_NAME,
|
|
552
|
+
apiKey: BUILDER_API_KEY,
|
|
553
|
+
userAttributes: {
|
|
554
|
+
urlPath: window.location.pathname,
|
|
555
|
+
},
|
|
556
|
+
options: getBuilderSearchParams(new URL(location.href).searchParams),
|
|
557
|
+
})
|
|
558
|
+
.then((content) => {
|
|
559
|
+
if (content) {
|
|
560
|
+
setContent(content);
|
|
561
|
+
}
|
|
562
|
+
setNotFound(!content);
|
|
563
|
+
})
|
|
564
|
+
.catch((err) => {
|
|
565
|
+
console.log("Oops: ", err);
|
|
566
|
+
});
|
|
567
|
+
}, []);
|
|
568
|
+
|
|
569
|
+
// If no page is found, return
|
|
570
|
+
// a 404 page from your code.
|
|
571
|
+
if (notFound && !isPreviewing()) {
|
|
572
|
+
return <div>404 Page Not Found</div>;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// return the page when found
|
|
576
|
+
return (
|
|
577
|
+
<>
|
|
578
|
+
{/* Render the Builder page */}
|
|
579
|
+
<Content
|
|
580
|
+
content={content}
|
|
581
|
+
model={MODEL_NAME}
|
|
582
|
+
apiKey={BUILDER_API_KEY}
|
|
583
|
+
customComponents={CUSTOM_COMPONENTS}
|
|
584
|
+
/>
|
|
585
|
+
</>
|
|
586
|
+
);
|
|
587
|
+
}
|
|
588
|
+
`:`
|
|
530
589
|
import React from "react";
|
|
531
590
|
import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
|
|
532
|
-
import ${JSON.stringify(
|
|
591
|
+
import ${JSON.stringify(b(e,e.builderComponentPath,e.registryPath))};
|
|
533
592
|
|
|
534
593
|
// Builder Public API Key set in .env file
|
|
535
|
-
${e.configType==="vite"?`builder.init(import.meta.env.${
|
|
594
|
+
${e.configType==="vite"?`builder.init(import.meta.env.${nt}${t?"!":""})`:`builder.init("${ft}")`}
|
|
536
595
|
|
|
537
596
|
export default function BuilderPage() {
|
|
538
597
|
const isPreviewingInBuilder = useIsPreviewing();
|
|
@@ -577,7 +636,7 @@ export default function BuilderPage() {
|
|
|
577
636
|
</>
|
|
578
637
|
);
|
|
579
638
|
}
|
|
580
|
-
`.trimStart()}async function
|
|
639
|
+
`.trimStart()}async function oa(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===I.gen2){let i=sa(e);await e.writeFile(e.registryPath,i)}else await e.writeFile(e.registryPath,"");r.push({filePath:e.registryPath,modifiedType:"create"})}let o=(await ge(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await ge(e,o.id,!0,!1,null,null,!0,!1)}async function ia(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}=aa(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 aa(e){let t=e.typescriptEnabled,r=`
|
|
581
640
|
"use client"
|
|
582
641
|
import React, { useState } from "react";
|
|
583
642
|
import styles from "./styles.module.css";
|
|
@@ -640,13 +699,18 @@ export default Counter;
|
|
|
640
699
|
font-size: 42px;
|
|
641
700
|
text-align: center;
|
|
642
701
|
}
|
|
643
|
-
`.trimStart();return{component:r,styles:n}}
|
|
702
|
+
`.trimStart();return{component:r,styles:n}}function sa(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-react";
|
|
703
|
+
|
|
704
|
+
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
705
|
+
];`:`export const CUSTOM_COMPONENTS = [
|
|
706
|
+
];
|
|
707
|
+
`}async function dr(e){let t=await pa(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>ur(t),ensureFigmaImportPage:()=>fr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>ge(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),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:()=>tt(t),setPublicApiKey:n=>sr(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===I.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 pa(e){let t=await la(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Kt(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,configType:""};return e.sdkVersion?a.sdkVersion=e.sdkVersion:a.sdkVersion=await Be(a),t.includes("webpack.config")&&(a.configType="webpack"),t.includes("vite.config")&&(a.configType="vite"),await e.exists(n)?(a.srcDir=n,a.componentsDir=e.join(n,"components"),a.registryPath=e.join(n,i),a.builderComponentPath=e.join(a.srcDir,`builder-page.${o?"tsx":"jsx"}`)):(a.componentsDir=e.join(r,"components"),a.registryPath=e.join(r,i),a.builderComponentPath=e.join(r,`builder-page.${o?"tsx":"jsx"}`)),a}function Kt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function la(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 rt(e){return await ca(e,["environment.ts"],dt)}async function gr(e,t){let r=await rt(e),n=await da(e,r.file,r.envKey,t);return{...r,modifiedType:n}}async function ca(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 ma(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 ma(e,t){let r=await e.readFile(t);return r?ua(e,r):""}function ua(e,t){let r=w(e,t),n="",i=Le(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===dt&&e.ts.isStringLiteral(p.initializer)&&(n=p.initializer.text)})}return n}async function fa(e,t,r,n){let o=w(e,t),a=Le(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 g=e.ts.factory.createPropertyAssignment(e.ts.factory.createIdentifier(r),e.ts.factory.createStringLiteral(n)),f=e.ts.factory.createNodeArray([...l.properties,g]),c=e.ts.factory.updateObjectLiteralExpression(l,f),m=e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,c),h=e.ts.factory.updateVariableDeclarationList(s,[m]);return e.ts.factory.updateVariableStatement(a.statement,a.statement.modifiers,h)}return null}return null}async function da(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 fa(e,o,r,n);if(i){let a=F(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=`
|
|
644
708
|
// https://www.builder.io/c/docs/using-your-api-key
|
|
645
709
|
export const environment = {
|
|
646
710
|
production: false,
|
|
647
711
|
builderApiKey: "${n}",
|
|
648
712
|
};
|
|
649
|
-
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var
|
|
713
|
+
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var dt="builderApiKey";async function xr(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(ha(e,i.fileName)||a.startsWith(".")||a==="node_modules"||ga.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let p=await gt(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var ga=new Set([]),xa=new Set(["node_modules"]);function ha(e,t){for(let r of xa)if(e.dirname(t).includes(r))return!0;return!1}async function hr(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 Ca(e,t,n)}return null}function Ca(e,t,r){let n=w(e,r);return gt(e,null,t,n)}async function gt(e,t,r,n){let o=[];r=e.normalize(r);let i=n.statements.filter(p=>e.ts.isClassDeclaration(p)&&ya(e,p)),a=await Pa(e,t,r,n),s=Ea(e,n);return await Promise.all(i.map(async p=>{let l=await Sa(e,t,r,p,s);o.push(...l)})),o.push(...a),o}async function Cr(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Oe(e,t.cmpInfo.filePath,r),a=(await gt(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 Sr(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 gt(e,o,a.filePath,s)).find(g=>g.cmpInfo.id===a.id);l&&(a.inputs=be(e,o,l.node.fnNode))}}return a}))}async function Sa(e,t,r,n,o){let i=[],a=e.relative(e.getRootDir(),r),s=k(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 g=l?"default":p,f=l?"default":"named",c=[];return n.members.forEach(m=>{if(e.ts.isPropertyDeclaration(m)){let h=e.ts.getDecorators(m);h&&h.forEach(u=>{if(Ta(e,u)&&e.ts.isIdentifier(m.name)){let d="any";if(m.type&&t){let C=t.getTypeAtLocation(m.type);d=t.typeToString(C)}else d=Da(e,m.type);let x={name:m.name.text,type:o[d]?"string":d};o[d]&&(x.enum=o[d]),c.push(x)}})}}),i.push({cmpInfo:{id:await _(e,r,p),displayFilePath:O(e,r),name:j(p),inputs:c,exportName:g,exportType:f,importName:p,filePath:r,relFilePath:a,importPath:s},node:{name:p,fnNode:n,deps:void 0}}),i}async function Pa(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=k(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 g=l,f="named",c=[];if(t){let m=t.getSymbolAtLocation(p.name);if(m){let h=t.getDeclaredTypeOfSymbol(m);t.getPropertiesOfType(h).forEach(d=>{let x=d.getDeclarations();x&&x.forEach(C=>{if(e.ts.isPropertyDeclaration(C)){let P=t.getTypeAtLocation(C),R={name:d.getName(),type:wa(e,t,P)};c.push(R)}})})}}o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:O(e,r),name:j(l),inputs:c,exportName:g,exportType:f,importName:l,filePath:r,relFilePath:i,importPath:a},node:{name:l,fnNode:p,deps:void 0}})}return o}function Ta(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 ya(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 Da(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 Ea(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 wa(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 Tr(e){let t=e.typescriptEnabled?".ts":".js",r=`app.module${t}`,n=e.join(e.appDir,r),o=await e.readFile(n);if(!o){console.error(`Unable to read app.module.${t} at ${n}`);return}let i=await va(e,n,o);if(!i){console.error(`Unable to update app.module.${t} at ${n}`);return}return await e.writeFile(n,i),n}async function va(e,t,r){let o=e.typescriptEnabled?"ts":"js",i=r,a=w(e,r),s=b(e,t,e.builderPageComponentPath),p=e.join(e.componentsDir,`counter.component.${o}`);a=E(e,a,{namedImports:["BuilderPage"],importPath:s});let l=b(e,t,p);a=E(e,a,{namedImports:["Counter"],importPath:l}),a=E(e,a,{namedImports:["Content"],importPath:"@builder.io/sdk-angular"});let g=[];for(let f of a.statements)if(e.ts.isClassDeclaration(f)&&f.name?.text==="AppModule"){let c=ba(e,f);g.push(c)}else g.push(f);return a=e.ts.factory.updateSourceFile(a,g),i=F(e,a),i}function ba(e,t){let r=e.ts.getDecorators(t);if(r){for(let n of r)if(e.ts.isCallExpression(n.expression)&&e.ts.isIdentifier(n.expression.expression)&&n.expression.expression.text==="NgModule"){let o=n.expression.arguments;if(o.length===1&&e.ts.isObjectLiteralExpression(o[0])){let i=Mt(e,o[0],"declarations","BuilderPage");if(i&&(i=Mt(e,i,"declarations","Counter"),i&&(i=Mt(e,i,"imports","Content"),i))){let a=e.ts.factory.updateDecorator(n,e.ts.factory.updateCallExpression(n.expression,n.expression.expression,n.expression.typeArguments,[i])),p=[...r.map(l=>l===n?a:l),...e.ts.getModifiers(t)||[]];return e.ts.factory.updateClassDeclaration(t,p,t.name,t.typeParameters,t.heritageClauses,t.members)}}}}return t}function Mt(e,t,r,n){let o=[...t.properties],i=o.findIndex(s=>v(e,s)===r);if(i>-1){let s=o[i];if(e.ts.isPropertyAssignment(s)&&s.initializer&&e.ts.isArrayLiteralExpression(s.initializer)){let p=Pr(e,s.initializer,n);if(p)return o[i]=e.ts.factory.updatePropertyAssignment(s,s.name,p),e.ts.factory.updateObjectLiteralExpression(t,o)}return null}let a=Pr(e,e.ts.factory.createArrayLiteralExpression([],!0),n);return a?e.ts.factory.updateObjectLiteralExpression(t,[...o,e.ts.factory.createPropertyAssignment(r,a)]):null}function Pr(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 yr(e){let t=[],r=await Aa(e,t);if(t.push(...await Ut(e)),await Ia(e,r),!await e.exists(e.builderPageComponentPath)){let n=await e.formatCode(e.builderPageComponentPath,Ra(e));await e.writeFile(e.builderPageComponentPath,n),t.push({filePath:e.builderPageComponentPath,modifiedType:"create"})}if(e.hasAppModule){let n=await Tr(e);n&&t.push({filePath:n,modifiedType:"update"})}return t}async function Ut(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Na(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}async function Dr(e){let t=[];return await Oa(e,t),t}async function Ia(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 Ra(e){let t=!e.hasAppModule,r=b(e,e.builderPageComponentPath,e.registryPath),n=e.join(e.getRootDir(),"src","environments","environment.ts"),o=b(e,e.builderPageComponentPath,n);return`
|
|
650
714
|
import { Component, Input } from '@angular/core';
|
|
651
715
|
import { fetchOneEntry, type BuilderContent } from '@builder.io/sdk-angular';
|
|
652
716
|
${t?"import { Content } from '@builder.io/sdk-angular';":""}
|
|
@@ -678,7 +742,7 @@ export class BuilderPage {
|
|
|
678
742
|
|
|
679
743
|
@Input() model ${e.typescriptEnabled?": string":""} = 'page'; // Default model is 'page'
|
|
680
744
|
|
|
681
|
-
apiKey = environment.${
|
|
745
|
+
apiKey = environment.${dt};
|
|
682
746
|
${e.typescriptEnabled?`
|
|
683
747
|
content: BuilderContent | null = null;
|
|
684
748
|
`:`
|
|
@@ -706,12 +770,12 @@ export class BuilderPage {
|
|
|
706
770
|
}
|
|
707
771
|
}
|
|
708
772
|
|
|
709
|
-
`.trimStart()}function
|
|
773
|
+
`.trimStart()}function Na(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-angular";
|
|
710
774
|
|
|
711
775
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
712
776
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
713
777
|
];
|
|
714
|
-
`}async function
|
|
778
|
+
`}async function Aa(e,t){let n=e.typescriptEnabled?"ts":"js",o=e.join(e.componentsDir,`counter.component.${n}`),i=await e.exists(o);e.debug(`angularEnsureCounterComponent, hasCounterCmp: ${i}`);let a=Fa(e);if(!i){let s=await e.formatCode(o,a);await e.writeFile(o,s),t.push({filePath:o,modifiedType:"create"})}return o}function Fa(e){return`
|
|
715
779
|
import { Component, Input } from '@angular/core';
|
|
716
780
|
|
|
717
781
|
@Component({
|
|
@@ -779,7 +843,7 @@ export class Counter {
|
|
|
779
843
|
}
|
|
780
844
|
}
|
|
781
845
|
|
|
782
|
-
`.trimStart()}async function
|
|
846
|
+
`.trimStart()}async function Oa(e,t){let r=`figma-imports.component.${e.typescriptEnabled?"ts":"js"}`,n=e.join(e.componentsDir,r);if(!await e.exists(n)){let o=await e.formatCode(n,La(e,n));await e.writeFile(n,o),t.push({filePath:n,modifiedType:"create"})}}function La(e,t){let r=!e.hasAppModule,n=b(e,t,e.builderPageComponentPath);return`
|
|
783
847
|
import { Component } from '@angular/core';
|
|
784
848
|
${r?"import { CommonModule } from '@angular/common';":""}
|
|
785
849
|
|
|
@@ -798,17 +862,17 @@ export class FigmaImportsPage {
|
|
|
798
862
|
|
|
799
863
|
}
|
|
800
864
|
|
|
801
|
-
`.trimStart()}async function yr(e){await Kt(e);let t=await e.readFile(e.registryPath);return t?Ia(e,t):{components:[],sourceFile:E(e,"")}}async function Ia(e,t){let r=E(e,t);return Ra(e,r)}async function Ra(e,t){let r=[],n=M(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:Q(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(b(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 Pe(e,e.registryPath,t,a);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,n.importPath=k(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await dr(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(f=>f.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function me(e,t,r,n,o,i,a,s){let p=await De(e),[l,d,f]=await Promise.all([fr(e,p),yr(e),tt(e)]),c=l.map(C=>C.cmpInfo),u=d.components,h={components:ee(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await xr(e,h.components),h;let m=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(T=>{let S=l.find(R=>R.cmpInfo.id===T);if(!S)throw new Error(`Component ${T} not found`);return S}),P=Array.from(new Set(C.map(T=>T.cmpInfo.filePath))),I=await $(e,P);for(let T of C){let S=h.components.find(L=>L.id===T.cmpInfo.id),R=await gr(e,T,I);Z(S,R);let B=c.findIndex(L=>L.id===T.cmpInfo.id);c[B].inputs=R;let F=pe(T.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:w,statementIndex:V,statement:z,variableDeclaration:q}=await Aa(e,g,T);if(F.addCmpToRegistry)y.push(Na(e,F.addCmpToRegistry)),m=!0;else if(F.removeCmpFromRegistry)y.splice(w,1),m=!0;else if(F.updateRegisteredCmp){let L=K(e,y[w],F.updateRegisteredCmp);y[w]=e.ts.factory.updateObjectLiteralExpression(L,[Tr(e,F.updateRegisteredCmp),...L.properties.slice(1)]),m=!0}if(m&&a){let L=[...g.statements];L[V]=e.ts.factory.updateVariableStatement(z,z.modifiers,e.ts.factory.updateVariableDeclarationList(z.declarationList,[e.ts.factory.updateVariableDeclaration(q,q.name,q.exclamationToken,q.type,e.ts.factory.createArrayLiteralExpression(Te(e,y)))])),g=e.ts.factory.updateSourceFile(g,L),S.exportType==="named"?g=D(e,g,{namedImports:[S.importName],importPath:v(e,e.registryPath,S.filePath)}):g=D(e,g,{defaultImport:S.importName,importPath:v(e,e.registryPath,S.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=Ee(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=F.components,u=F.components.filter(fe=>fe.isRegistered)}}}if(m&&a){g=se(e,g),g=ae(e,g);let C=N(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function Tr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Na(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([Tr(e,t)],!0),t)}async function Aa(e,t,r){let n=M(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}}async function Dr(e){let t=await Fa(e);return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Sr(t),ensureFigmaImportPage:()=>Pr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>me(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await me(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>me(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>me(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>me(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>me(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>tt(t),setPublicApiKey:n=>mr(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>ne(t),setCache:n=>re(t,n)}}async function Fa(e){let t=await La(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Oa(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 Oa(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function La(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 St=po(_r(),1);async function jr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:X(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:J(i.inputs)};return J(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,St.compress)(n);return btoa(JSON.stringify(o))}async function Br(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,St.decompress)(o),a=J(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let p=X(e.normalize(s.filePath)),l=n.components.find(f=>X(f.filePath).endsWith(p)&&f.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 f of s.inputs)e.debug(`set input (${l.id})`),await t.setRegisteredComponentInput({cmpId:l.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.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=J(d)}return a}var te={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Rm={[te.react]:[{version:O.gen1,recommended:!0}],[te.remix]:[{version:O.gen1,recommended:!1}],[te.angular]:[{version:O.gen2,recommended:!0}],[te.next]:[{version:O.gen1,recommended:!0},{version:O.gen2,recommended:!1}],[te.qwik]:[{version:O.gen2,recommended:!0}]};var os={"@builder.io/qwik-city":Gn,next:Vn,"@remix-run/react":or,react:ur,"@angular/core":Dr},is={"@builder.io/qwik-city":te.qwik,next:te.next,"@remix-run/react":te.remix,react:te.react,"@angular/core":te.angular};async function as(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 ve(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=os[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>jr(e,n),importRegistry:i=>Br(e,n,i),framework:is[t.name]}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Vr(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let u="",h=0,m=-1,g=0,x;for(let C=0;C<=f.length;++C){if(C<f.length)x=f.charCodeAt(C);else{if(x===47)break;x=47}if(x===47){if(!(m===C-1||g===1))if(m!==C-1&&g===2){if(u.length<2||h!==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="",h=0):(u=u.slice(0,P),h=u.length-1-u.lastIndexOf("/")),m=C,g=0;continue}}else if(u.length===2||u.length===1){u="",h=0,m=C,g=0;continue}}c&&(u.length>0?u+="/..":u="..",h=2)}else u.length>0?u+="/"+f.slice(m+1,C):u=f.slice(m+1,C),h=C-m-1;m=C,g=0}else x===46&&g!==-1?++g:g=-1}return u}let n=function(...c){let u="",h=!1;for(let m=c.length-1;m>=-1&&!h;m--){let g;m>=0?g=c[m]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(u=g+"/"+u,h=g.charCodeAt(0)===47)}return u=r(u,!h),h?u.length>0?"/"+u:"/":u.length>0?u:"."},o=function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0)===47,h=c.charCodeAt(c.length-1)===47;return c=r(c,!u),c.length===0&&!u&&(c="."),c.length>0&&h&&(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 h=1;for(;h<c.length&&c.charCodeAt(h)===47;++h);let m=c.length,g=m-h,x=1;for(;x<u.length&&u.charCodeAt(x)===47;++x);let P=u.length-x,I=g<P?g:P,T=-1,S=0;for(;S<=I;++S){if(S===I){if(P>I){if(u.charCodeAt(x+S)===47)return u.slice(x+S+1);if(S===0)return u.slice(x+S)}else g>I&&(c.charCodeAt(h+S)===47?T=S:S===0&&(T=0));break}let B=c.charCodeAt(h+S),F=u.charCodeAt(x+S);if(B!==F)break;B===47&&(T=S)}let R="";for(S=h+T+1;S<=m;++S)(S===m||c.charCodeAt(S)===47)&&(R.length===0?R+="..":R+="/..");return R.length>0?R+u.slice(x+T):(x+=T,u.charCodeAt(x)===47&&++x,u.slice(x))},resolve:n,join:function(...c){if(c.length===0)return".";let u;for(let h=0;h<c.length;++h){let m=c[h];t(m),m.length>0&&(u===void 0?u=m:u+="/"+m)}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 h=0,m=-1,g=!0,x;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(x=c.length-1;x>=0;--x){let I=c.charCodeAt(x);if(I===47){if(!g){h=x+1;break}}else P===-1&&(g=!1,P=x+1),C>=0&&(I===u.charCodeAt(C)?--C===-1&&(m=x):(C=-1,m=P))}return h===m?m=P:m===-1&&(m=c.length),c.slice(h,m)}else{for(x=c.length-1;x>=0;--x)if(c.charCodeAt(x)===47){if(!g){h=x+1;break}}else m===-1&&(g=!1,m=x+1);return m===-1?"":c.slice(h,m)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0),h=u===47,m=-1,g=!0;for(let x=c.length-1;x>=1;--x)if(u=c.charCodeAt(x),u===47){if(!g){m=x;break}}else g=!1;return m===-1?h?"/":".":h&&m===1?"//":c.slice(0,m)},extname:function(c){t(c);let u=-1,h=0,m=-1,g=!0,x=0;for(let C=c.length-1;C>=0;--C){let P=c.charCodeAt(C);if(P===47){if(!g){h=C+1;break}continue}m===-1&&(g=!1,m=C+1),P===46?u===-1?u=C:x!==1&&(x=1):u!==-1&&(x=-1)}return u===-1||m===-1||x===0||x===1&&u===m-1&&u===h+1?"":c.slice(u,m)}}}async function ss(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Vr({cwd:r,...e}),o=new Map,i=m=>n.normalize(n.resolve(r(),m)),a=m=>{for(let[g]of o)if((g+"/").startsWith(m))return!0;return m===t()},s=m=>(m=i(m),o.has(m)?!0:a(m)),p=m=>{m=i(m);let g=m===t()?m:m+"/",x=g.split("/").length-1,C=[];for(let[P]of o)if(P.split("/").slice(0,x).join("/")+"/"===g){let S=P.split("/")[x];S&&!C.includes(S)&&C.push(S)}return C.sort()},l=m=>{m=i(m);let g=o.get(m);return typeof g=="string"?g:null},d=m=>(m=i(m),{isFile:()=>o.has(m),isDirectory:()=>!o.has(m)&&a(m)}),f=async m=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(m),P=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(P)).map(I=>I.toString(16).padStart(2,"0")).join("")}let g=0;for(let x=0;x<m.length;x++){let C=m.charCodeAt(x);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,u={getRootDir:t,cwd:r,exists:async m=>s(m),existsSync:s,readdir:async m=>p(m),readdirSync:p,readFile:async m=>l(m),readFileSync:l,stat:async m=>d(m),statSync:d,writeFile:async(m,g)=>{m=i(m),o.set(m,g);let x={path:m,basename:n.basename(m),dirname:n.dirname(m),extname:n.extname(m)};for(let C of c)await C(x)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",formatCode:async(m,g)=>g,on:(m,g)=>{m==="change"&&c.add(g)},off:(m,g)=>{m==="change"&&c.delete(g)},debug:(...m)=>{console.debug("[builder-dev-tools]",...m)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null},h=await ve(u);return u.getFrameworks=e.getFrameworks?e.getFrameworks:()=>h,u}async function $r(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Kr(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 f=d.statement;if(!e.ts.isVariableStatement(f))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 h=u[0];if(!h.initializer)throw new Error("Expected an initializer on the declaration");let m=h.initializer;if(e.ts.isObjectLiteralExpression(m)||e.ts.isCallExpression(m)){let g="BuilderDevTools()",x=[...n.statements],C=x.indexOf(c);return x[C]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(h,h.name,h.exclamationToken,h.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[m]))])),n=e.ts.factory.updateSourceFile(n,x),n=D(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=N(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 f=d.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=nn(e,n);n=c.sourceFile;let u=[...n.statements],h=u.indexOf(d);return u[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,u),o.content=N(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 f=d[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let u=nn(e,n);n=u.sourceFile;let h=[...n.statements],m=h.indexOf(l);return h[m]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=N(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,f=p.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let h=p.node.body;if(!e.ts.isBlock(h))throw new Error("Expected a block body on the next config function");let m=[...h.statements],g=m.findIndex(T=>e.ts.isReturnStatement(T));if(g===-1)throw new Error("Expected a return statement on the next config function");let x=m[g],C=nn(e,n);n=C.sourceFile,m[g]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[x.expression]));let P=[...n.statements],I=P.indexOf(f);return P[I]=e.ts.factory.updateExpressionStatement(f,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(h,m)))),n=e.ts.factory.updateSourceFile(n,P),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function Kr(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 nn(e,t){let r=Kr(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 zr(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(qr(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 f=d.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",u=ps(e,f.expression);if(!u)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[u]),m=[...n.statements],g=m.indexOf(f);return m[g]=e.ts.factory.updateExportAssignment(f,f.modifiers,h),n=e.ts.factory.updateSourceFile(n,m),n=D(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=N(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 f=d.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Mr(e,n);n=c.sourceFile;let u=[...n.statements],h=u.indexOf(d);return u[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,u),o.content=N(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 f=d[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let u=Mr(e,n);n=u.sourceFile;let h=[...n.statements],m=h.indexOf(l);return h[m]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function qr(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 Mr(e,t){let r=qr(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 ps(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Ur(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=Ur(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Ur(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 Jr(e,t,r){let n=E(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=ls(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 f=[...n.statements],c=f.indexOf(a);return f[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,f),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=N(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(l)){let d=rn(e,l);if(!d)return s;let f=[...n.statements],c=f.indexOf(a);return f[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,f),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=N(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let p=rn(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=N(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function ls(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=rn(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function rn(e,t){if(ms(e)){let i=cs(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Qr(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=Qr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Qr(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 cs(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=us(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=on(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 us(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=on(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=on(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function on(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 ms(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function Wr(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 Gr(e,t,r){e.debug("Angular config updates are currently in progress...");try{await gs(e)}catch{console.error("Unable to update package.json.")}return await fs(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function fs(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 ds(e,o);await e.writeFile(n,i)}async function ds(e,t){let r=t,n=E(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=`
|
|
865
|
+
`.trimStart()}async function Er(e){await Ut(e);let t=await e.readFile(e.registryPath);return t?ka(e,t):{components:[],sourceFile:w(e,"")}}async function ka(e,t){let r=w(e,t);return _a(e,r)}async function _a(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:Q(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(v(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let g=s.arguments[0];e.ts.isIdentifier(g)&&(a=g.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=k(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await hr(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let g=l.find(f=>f.cmpInfo.exportName===a);g&&(n.exportName=g.cmpInfo.exportName)}continue}}return n=J(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 Ee(e),[l,g,f]=await Promise.all([xr(e,p),Er(e),rt(e)]),c=l.map(C=>C.cmpInfo),m=g.components,h={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:O(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await Sr(e,h.components),h;let u=!1,d=g.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(D=>{let S=l.find(N=>N.cmpInfo.id===D);if(!S)throw new Error(`Component ${D} not found`);return S}),P=Array.from(new Set(C.map(D=>D.cmpInfo.filePath))),R=await M(e,P);for(let D of C){let S=h.components.find(A=>A.id===D.cmpInfo.id),N=await Cr(e,D,R);ee(S,N);let B=c.findIndex(A=>A.id===D.cmpInfo.id);c[B].inputs=N;let L=me(D.cmpInfo.id,c,m,r,n,o,i),{elements:T,elmIndex:y,statementIndex:U,statement:X,variableDeclaration:K}=await Ba(e,d,D);if(L.addCmpToRegistry)T.push(ja(e,L.addCmpToRegistry)),u=!0;else if(L.removeCmpFromRegistry)T.splice(y,1),u=!0;else if(L.updateRegisteredCmp){let A=$(e,T[y],L.updateRegisteredCmp);T[y]=e.ts.factory.updateObjectLiteralExpression(A,[wr(e,L.updateRegisteredCmp),...A.properties.slice(1)]),u=!0}if(u&&a){let A=[...d.statements];A[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration(K,K.name,K.exclamationToken,K.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),d=e.ts.factory.updateSourceFile(d,A),S.exportType==="named"?d=E(e,d,{namedImports:[S.importName],importPath:b(e,e.registryPath,S.filePath)}):d=E(e,d,{defaultImport:S.importName,importPath:b(e,e.registryPath,S.filePath)}),d=E(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),d=ue(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=L.components,m=L.components.filter(z=>z.isRegistered)}}}if(u&&a){d=ce(e,d),d=pe(e,d);let C=F(e,d);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function wr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function ja(e,t){return $(e,e.ts.factory.createObjectLiteralExpression([wr(e,t)],!0),t)}async function Ba(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}}async function vr(e){let t=await Va(e);return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>yr(t),ensureFigmaImportPage:()=>Dr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>xe(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await xe(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>xe(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>xe(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>xe(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>xe(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>rt(t),setPublicApiKey:n=>gr(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function Va(e){let t=await Ka(e),r=e.getRootDir(),n=e.join(r,"src"),o=await $a(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 $a(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Ka(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 Tt=co(Vr(),1);async function $r(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,Tt.compress)(n);return btoa(JSON.stringify(o))}async function Kr(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,Tt.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(f=>Z(f.filePath).endsWith(p)&&f.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 f of s.inputs)e.debug(`set input (${l.id})`),await t.setRegisteredComponentInput({cmpId:l.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${l.id}) info`);let g=await t.setRegisteredComponentInfo({cmpId:l.id,name:s.name,image:s.image,description:s.description});a=W(g)}return a}var ne={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Mu={[ne.react]:[{version:I.gen1,recommended:!0},{version:I.gen2,recommended:!1}],[ne.remix]:[{version:I.gen1,recommended:!1}],[ne.angular]:[{version:I.gen2,recommended:!0}],[ne.next]:[{version:I.gen1,recommended:!0},{version:I.gen2,recommended:!1}],[ne.qwik]:[{version:I.gen2,recommended:!0}]};var ms={"@builder.io/qwik-city":Xn,next:Kn,"@remix-run/react":ar,react:dr,"@angular/core":vr},us={"@builder.io/qwik-city":ne.qwik,next:ne.next,"@remix-run/react":ne.remix,react:ne.react,"@angular/core":ne.angular};async function fs(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 ve(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=ms[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>$r(e,n),importRegistry:i=>Kr(e,n,i),framework:us[t.name]}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Mr(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let m="",h=0,u=-1,d=0,x;for(let C=0;C<=f.length;++C){if(C<f.length)x=f.charCodeAt(C);else{if(x===47)break;x=47}if(x===47){if(!(u===C-1||d===1))if(u!==C-1&&d===2){if(m.length<2||h!==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="",h=0):(m=m.slice(0,P),h=m.length-1-m.lastIndexOf("/")),u=C,d=0;continue}}else if(m.length===2||m.length===1){m="",h=0,u=C,d=0;continue}}c&&(m.length>0?m+="/..":m="..",h=2)}else m.length>0?m+="/"+f.slice(u+1,C):m=f.slice(u+1,C),h=C-u-1;u=C,d=0}else x===46&&d!==-1?++d:d=-1}return m}let n=function(...c){let m="",h=!1;for(let u=c.length-1;u>=-1&&!h;u--){let d;u>=0?d=c[u]:e.cwd?d=e.cwd():d="/",t(d),d.length!==0&&(m=d+"/"+m,h=d.charCodeAt(0)===47)}return m=r(m,!h),h?m.length>0?"/"+m:"/":m.length>0?m:"."},o=function(c){if(t(c),c.length===0)return".";let m=c.charCodeAt(0)===47,h=c.charCodeAt(c.length-1)===47;return c=r(c,!m),c.length===0&&!m&&(c="."),c.length>0&&h&&(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 h=1;for(;h<c.length&&c.charCodeAt(h)===47;++h);let u=c.length,d=u-h,x=1;for(;x<m.length&&m.charCodeAt(x)===47;++x);let P=m.length-x,R=d<P?d:P,D=-1,S=0;for(;S<=R;++S){if(S===R){if(P>R){if(m.charCodeAt(x+S)===47)return m.slice(x+S+1);if(S===0)return m.slice(x+S)}else d>R&&(c.charCodeAt(h+S)===47?D=S:S===0&&(D=0));break}let B=c.charCodeAt(h+S),L=m.charCodeAt(x+S);if(B!==L)break;B===47&&(D=S)}let N="";for(S=h+D+1;S<=u;++S)(S===u||c.charCodeAt(S)===47)&&(N.length===0?N+="..":N+="/..");return N.length>0?N+m.slice(x+D):(x+=D,m.charCodeAt(x)===47&&++x,m.slice(x))},resolve:n,join:function(...c){if(c.length===0)return".";let m;for(let h=0;h<c.length;++h){let u=c[h];t(u),u.length>0&&(m===void 0?m=u:m+="/"+u)}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 h=0,u=-1,d=!0,x;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(x=c.length-1;x>=0;--x){let R=c.charCodeAt(x);if(R===47){if(!d){h=x+1;break}}else P===-1&&(d=!1,P=x+1),C>=0&&(R===m.charCodeAt(C)?--C===-1&&(u=x):(C=-1,u=P))}return h===u?u=P:u===-1&&(u=c.length),c.slice(h,u)}else{for(x=c.length-1;x>=0;--x)if(c.charCodeAt(x)===47){if(!d){h=x+1;break}}else u===-1&&(d=!1,u=x+1);return u===-1?"":c.slice(h,u)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let m=c.charCodeAt(0),h=m===47,u=-1,d=!0;for(let x=c.length-1;x>=1;--x)if(m=c.charCodeAt(x),m===47){if(!d){u=x;break}}else d=!1;return u===-1?h?"/":".":h&&u===1?"//":c.slice(0,u)},extname:function(c){t(c);let m=-1,h=0,u=-1,d=!0,x=0;for(let C=c.length-1;C>=0;--C){let P=c.charCodeAt(C);if(P===47){if(!d){h=C+1;break}continue}u===-1&&(d=!1,u=C+1),P===46?m===-1?m=C:x!==1&&(x=1):m!==-1&&(x=-1)}return m===-1||u===-1||x===0||x===1&&m===u-1&&m===h+1?"":c.slice(m,u)}}}async function ds(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Mr({cwd:r,...e}),o=new Map,i=u=>n.normalize(n.resolve(r(),u)),a=u=>{for(let[d]of o)if((d+"/").startsWith(u))return!0;return u===t()},s=u=>(u=i(u),o.has(u)?!0:a(u)),p=u=>{u=i(u);let d=u===t()?u:u+"/",x=d.split("/").length-1,C=[];for(let[P]of o)if(P.split("/").slice(0,x).join("/")+"/"===d){let S=P.split("/")[x];S&&!C.includes(S)&&C.push(S)}return C.sort()},l=u=>{u=i(u);let d=o.get(u);return typeof d=="string"?d:null},g=u=>(u=i(u),{isFile:()=>o.has(u),isDirectory:()=>!o.has(u)&&a(u)}),f=async u=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(u),P=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(P)).map(R=>R.toString(16).padStart(2,"0")).join("")}let d=0;for(let x=0;x<u.length;x++){let C=u.charCodeAt(x);d=(d<<5)-d+C,d|=0}return Number(Math.abs(d)).toString(36)},c=new Set,m={getRootDir:t,cwd:r,exists:async u=>s(u),existsSync:s,readdir:async u=>p(u),readdirSync:p,readFile:async u=>l(u),readFileSync:l,stat:async u=>g(u),statSync:g,writeFile:async(u,d)=>{u=i(u),o.set(u,d);let x={path:u,basename:n.basename(u),dirname:n.dirname(u),extname:n.extname(u)};for(let C of c)await C(x)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",formatCode:async(u,d)=>d,on:(u,d)=>{u==="change"&&c.add(d)},off:(u,d)=>{u==="change"&&c.delete(d)},debug:(...u)=>{console.debug("[builder-dev-tools]",...u)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null},h=await ve(m);return m.getFrameworks=e.getFrameworks?e.getFrameworks:()=>h,m}async function Ur(e,t,r){let n=w(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(zr(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 g=s[0];if(!g.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=g.statement;if(!e.ts.isVariableStatement(f))throw new Error(`Expected an export assignment from ${t}`);let c=g.statement;if(e.ts.isVariableStatement(c)){let m=[...c.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let h=m[0];if(!h.initializer)throw new Error("Expected an initializer on the declaration");let u=h.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let d="BuilderDevTools()",x=[...n.statements],C=x.indexOf(c);return x[C]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(h,h.name,h.exclamationToken,h.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,x),n=E(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=F(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 g=p.statement;if(!e.ts.isExpressionStatement(g))throw new Error("Expected an expression statement for the default export");let f=g.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=on(e,n);n=c.sourceFile;let m=[...n.statements],h=m.indexOf(g);return m[h]=e.ts.factory.updateExpressionStatement(g,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=F(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let g=[...l.declarationList.declarations];if(g.length!==1)throw new Error("Expected a single variable declaration");let f=g[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let m=on(e,n);n=m.sourceFile;let h=[...n.statements],u=h.indexOf(l);return h[u]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(p.node)){let g=p.node,f=p.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let h=p.node.body;if(!e.ts.isBlock(h))throw new Error("Expected a block body on the next config function");let u=[...h.statements],d=u.findIndex(D=>e.ts.isReturnStatement(D));if(d===-1)throw new Error("Expected a return statement on the next config function");let x=u[d],C=on(e,n);n=C.sourceFile,u[d]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[x.expression]));let P=[...n.statements],R=P.indexOf(f);return P[R]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.updateArrowFunction(g,g.modifiers,g.typeParameters,g.parameters,g.type,g.equalsGreaterThanToken,e.ts.factory.updateBlock(h,u)))),n=e.ts.factory.updateSourceFile(n,P),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function zr(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 on(e,t){let r=zr(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 Jr(e,t,r){let n=w(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Wr(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 g=s[0];if(!g.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=g.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",m=gs(e,f.expression);if(!m)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[m]),u=[...n.statements],d=u.indexOf(f);return u[d]=e.ts.factory.updateExportAssignment(f,f.modifiers,h),n=e.ts.factory.updateSourceFile(n,u),n=E(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=F(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 g=p.statement;if(!e.ts.isExpressionStatement(g))throw new Error("Expected an expression statement for the default export");let f=g.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=qr(e,n);n=c.sourceFile;let m=[...n.statements],h=m.indexOf(g);return m[h]=e.ts.factory.updateExpressionStatement(g,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=F(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let g=[...l.declarationList.declarations];if(g.length!==1)throw new Error("Expected a single variable declaration");let f=g[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let m=qr(e,n);n=m.sourceFile;let h=[...n.statements],u=h.indexOf(l);return h[u]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function Wr(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 qr(e,t){let r=Wr(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 gs(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=Qr(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=Qr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Qr(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 Gr(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 g=xs(e,l);if(!g)return s;p[0]=e.ts.factory.updateArrowFunction(l,l.modifiers,l.typeParameters,l.parameters,l.type,l.equalsGreaterThanToken,g);let f=[...n.statements],c=f.indexOf(a);return f[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,f),n=E(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(l)){let g=an(e,l);if(!g)return s;let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[g])),n=e.ts.factory.updateSourceFile(n,f),n=E(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let p=an(e,a.expression);if(!p)return s;let l=[...n.statements],g=l.indexOf(a);return l[g]=e.ts.factory.updateExportAssignment(a,a.modifiers,p),n=e.ts.factory.updateSourceFile(n,l),n=E(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function xs(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=an(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function an(e,t){if(Ss(e)){let i=hs(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=Yr(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=Yr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Yr(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 hs(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=Cs(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=sn(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 Cs(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=sn(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=sn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function sn(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 Ss(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function Hr(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 Zr(e,t,r){e.debug("Angular config updates are currently in progress...");try{await ys(e)}catch{console.error("Unable to update package.json.")}return await Ps(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Ps(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 Ts(e,o);await e.writeFile(n,i)}async function Ts(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=E(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
802
866
|
builderDevTools().catch((err: Error) =>
|
|
803
867
|
console.error("Error starting dev tools:", err)
|
|
804
|
-
);`;return r=
|
|
805
|
-
`}var
|
|
868
|
+
);`;return r=F(e,n),o||(r+=i),r}async function ys(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=Ds(n);o&&await e.writeFile(r,o)}function Ds(e){let t=JSON.parse(e);if(t.scripts=t.scripts||{},t.scripts[Xr])return;let r=t.scripts.start||t.scripts.dev||"ng serve";return t.scripts[Xr]=`concurrently "${r}" "${Es}"`,JSON.stringify(t,null,2)+`
|
|
869
|
+
`}var Xr="builder-dev",Es="npx builder-dev-tools";var to=[{id:"angular",configFileNames:["angular.json"],ensureConfigPlugin:Zr},{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:Ur},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:Gr},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:Jr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:Hr}];async function no(e){let t=e.resolve("/");for(let n of to)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 ve(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,eo),{id:"next",filePath:n,content:eo}}return null}async function ws(e){let t=await no(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await to.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 eo=`
|
|
806
870
|
/** @type {import('next').NextConfig} */
|
|
807
871
|
const nextConfig = {
|
|
808
872
|
}
|
|
809
873
|
|
|
810
874
|
module.exports = nextConfig
|
|
811
|
-
`.trimStart();var
|
|
875
|
+
`.trimStart();var ro="/~builder-dev-tools.js";function vs(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(ro,e);t.searchParams.set("v",yt);let r=JSON.stringify(yt),n=`/* Builder Devtools v${yt} */
|
|
812
876
|
`;return n+=`(() => {
|
|
813
877
|
`,n+=` if (typeof document !== "undefined") {
|
|
814
878
|
`,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]");
|
|
@@ -821,4 +885,4 @@ module.exports = nextConfig
|
|
|
821
885
|
`,n+=` }
|
|
822
886
|
`,n+=` }
|
|
823
887
|
`,n+=`})();
|
|
824
|
-
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var
|
|
888
|
+
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var yt="1.1.22";export{fs as createDevTools,ds as createDevToolsSys,ve as detectFrameworks,cn as detectFrameworksFromPackageJson,ws as ensureConfigPlugin,no as findBuildToolConfig,vs as getClientScript,un as parseDotEnvContent,yt as version};
|