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