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