@builder.io/dev-tools 1.0.19 → 1.0.20
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/core/index.cjs +167 -36
- package/core/index.mjs +167 -36
- package/node/index.cjs +1 -1
- package/node/index.mjs +1 -1
- package/package.json +1 -1
- package/server/index.cjs +28 -9
- package/server/index.mjs +28 -9
- package/types/core/adapters/angular/angular-app-module-imports.d.ts +3 -0
- package/types/core/adapters/angular/angular-app-module-imports.unit.d.ts +1 -0
- package/types/core/adapters/angular/angular-ensure-builder-setup.d.ts +1 -1
- package/types/core/adapters/angular/index.d.ts +1 -0
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 eo=Object.create;var nt=Object.defineProperty;var to=Object.getOwnPropertyDescriptor;var no=Object.getOwnPropertyNames;var ro=Object.getPrototypeOf,oo=Object.prototype.hasOwnProperty;var fe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),io=(e,t)=>{for(var r in t)nt(e,r,{get:t[r],enumerable:!0})},on=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of no(t))!oo.call(e,o)&&o!==r&&nt(e,o,{get:()=>t[o],enumerable:!(n=to(t,o))||n.enumerable});return e};var ao=(e,t,r)=>(r=e!=null?eo(ro(e)):{},on(t||!e||!e.__esModule?nt(r,"default",{value:e,enumerable:!0}):r,e)),so=e=>on(nt({},"__esModule",{value:!0}),e);var zt=fe(ut=>{"use strict";Object.defineProperty(ut,"__esModule",{value:!0});function Tr(e){return Object.prototype.toString.call(e)}ut.getType=Tr;function Da(e){throw new TypeError("unsupported data type: "+Tr(e))}ut.throwUnknownDataType=Da});var qt=fe(ue=>{"use strict";Object.defineProperty(ue,"__esModule",{value:!0});var pe="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);pe+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);pe+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);pe+=t}var ke=pe.length,Ut={};for(let e=0;e<ke;e++){let t=pe[e];Ut[t]=e}function Mt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Ut[o];i*=r,t+=i,r*=ke}return t}ue.s_to_int=Mt;function yr(e){let t=BigInt(0),r=BigInt(1),n=BigInt(ke);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Ut[i]);a*=r,t+=a,r*=n}return t}ue.s_to_big_int=yr;function Qt(e){if(e===0)return pe[0];let t=[];for(;e!==0;){let r=e%ke,n=pe[r];t.push(n),e-=r,e/=ke}return t.reverse().join("")}ue.int_to_s=Qt;function wr(e){let t=BigInt(0),r=BigInt(ke);if(e===t)return pe[0];let n=[];for(;e!==t;){let o=e%r,i=pe[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}ue.big_int_to_s=wr;function ft(e){return e.split("").reverse().join("")}function Dr(e){if(e<0)return"-"+Dr(-e);let[t,r]=e.toString().split(".");if(!r)return Qt(e);let n;r&&([r,n]=r.split("e")),t=mt(t),r=ft(r),r=mt(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=ft(n),n=mt(n),o+=n}return o}ue.num_to_s=Dr;function mt(e){let t=+e;return t.toString()===e?Qt(t):":"+wr(BigInt(e))}ue.int_str_to_s=mt;function Kt(e){return e[0]===":"?yr(e.substring(1)).toString():Mt(e).toString()}function Pr(e){if(e[0]==="-")return-Pr(e.substr(1));let[t,r,n]=e.split(".");if(!r)return Mt(t);t=Kt(t),r=Kt(r),r=ft(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Kt(n),n=ft(n),o+=i?-n:+n}return+o}ue.s_to_num=Pr});var Wt=fe(me=>{"use strict";Object.defineProperty(me,"__esModule",{value:!0});var Jt=qt();function Pa(e){return"n|"+Jt.num_to_s(e)}me.encodeNum=Pa;function Ea(e){return e=e.replace("n|",""),Jt.s_to_num(e)}me.decodeNum=Ea;function va(e){return typeof e=="number"?e:Jt.s_to_int(e)}me.decodeKey=va;function ba(e){return e?"b|T":"b|F"}me.encodeBool=ba;function Ia(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}me.decodeBool=Ia;function Na(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}me.encodeStr=Na;function Ra(e){return e[0]+e[1]==="s|"?e.substr(2):e}me.decodeStr=Ra});var Er=fe(Yt=>{"use strict";Object.defineProperty(Yt,"__esModule",{value:!0});Yt.config={sort_key:!1}});var Gt=fe(Pe=>{"use strict";Object.defineProperty(Pe,"__esModule",{value:!0});var Aa=Er(),Fa=zt(),Ht=Wt(),La=qt();function Oa(e){return e.store.toArray()}Pe.memToValues=Oa;function vr(){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}}}Pe.makeInMemoryStore=vr;function br(){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}}}Pe.makeInMemoryCache=br;function ka(){return{store:vr(),cache:br(),keyCount:0}}Pe.makeInMemoryMemory=ka;function De(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=La.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function ja(e,t){Aa.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=Xe(e,t,void 0);return e.cache.setSchema(r,n),n}function Xe(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return Xe(e,null,r);break;case"object":if(t===null)return De(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":Xe(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),De(e,n)}else{let n=Object.keys(t);if(n.length===0)return De(e,"o|");let o="o",i=ja(e,n);o+="|"+i;for(let a of n){let s=t[a],l=Xe(e,s,t);o+="|"+l}return De(e,o)}case"boolean":return De(e,Ht.encodeBool(t));case"number":return De(e,Ht.encodeNum(t));case"string":return De(e,Ht.encodeStr(t))}return Fa.throwUnknownDataType(t)}Pe.addValue=Xe});var Zt=fe(et=>{"use strict";Object.defineProperty(et,"__esModule",{value:!0});var _a=zt(),dt=Wt(),Xt=Gt();function Ba(e){let t=Xt.makeInMemoryMemory(),r=Xt.addValue(t,e,void 0);return[Xt.memToValues(t),r]}et.compress=Ba;function $a(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=Ze(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let l=i[s-2],c=n[s];c=Ze(e,c),r[l]=c}return r}function Va(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=Ze(e,a),o[i]=a}return o}function Ze(e,t){if(t===""||t==="_")return null;let r=dt.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 dt.decodeBool(n);case"o|":return $a(e,n);case"n|":return dt.decodeNum(n);case"a|":return Va(e,n);default:return dt.decodeStr(n)}}return _a.throwUnknownDataType(n)}et.decode=Ze;function za(e){let[t,r]=e;return Ze(t,r)}et.decompress=za});var Nr=fe(gt=>{"use strict";Object.defineProperty(gt,"__esModule",{value:!0});function Ka(e){for(let t in e)e[t]===void 0&&delete e[t]}gt.trimUndefined=Ka;function Ua(e){Ir(e,new Set)}gt.trimUndefinedRecursively=Ua;function Ir(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)&&Ir(n,t)}}});var Fr=fe(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});var Rr=Zt();Se.compress=Rr.compress;Se.decompress=Rr.decompress;var Ma=Zt();Se.decode=Ma.decode;var Qa=Gt();Se.addValue=Qa.addValue;var Ar=Nr();Se.trimUndefined=Ar.trimUndefined;Se.trimUndefinedRecursively=Ar.trimUndefinedRecursively});var rs={};io(rs,{createDevTools:()=>kr,createDevToolsSys:()=>_r,detectFrameworks:()=>de,detectFrameworksFromPackageJson:()=>Ct,ensureConfigPlugin:()=>Gr,findBuildToolConfig:()=>rn,getClientScript:()=>Zr,parseDotEnvContent:()=>St,version:()=>tt});module.exports=so(rs);async function an(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 sn(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 je(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 l=await je(e,a,r);if(l)return l}}))).find(i=>typeof i=="string")}async function de(e){let t=[],r=await an(e,e.getRootDir());if(r){let n=Ct(r);t.push(...n)}return t}function Ct(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of lo)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var lo=["@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 Z(e){let t=ln(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function ee(e,t){t=typeof t=="object"&&t!=null?t:{};let r=ln(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function ln(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function ge(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await co(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 co(e,t){let r=await e.readFile(t);return typeof r=="string"?St(r):null}function St(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 xe(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 _e(e){return await ge(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],Te)}async function cn(e,t){let r=await _e(e),n=await xe(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Te="NEXT_PUBLIC_BUILDER_API_KEY";function D(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest)}function rt(e,t=""){let r=D(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function v(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 L(e,t,r){t=W(t),r=W(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=W(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function W(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Pe(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return sn(o==="index"?e.basename(e.dirname(t)):o)}function sn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=W(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function _(e,t){let r=W(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 R(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 M(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function k(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 _e(e){return typeof e=="number"}function ve(e){return typeof e=="boolean"}function z(e){return typeof e=="string"}function Be(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function K(e){return JSON.parse(JSON.stringify(e))}function $e(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=lo(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,l)=>l!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,Ve(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,Ve(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function lo(e,t,r){return t.properties.findIndex(n=>A(e,n)===r)}function ze(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return po(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return co(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 co(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=A(e,n);o&&(r[o]=ze(e,n.initializer))}}return r}function po(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>ze(e,r)):[]}function A(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 Ve(e,t){return St(e,t,new WeakSet)}function St(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)?uo(e,t,r):typeof t=="object"?mo(e,t,r):e.ts.factory.createIdentifier(t)}function uo(e,t,r){let n=t.map(o=>St(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function mo(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,St(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function Te(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 l=a.heritageClauses?.find(c=>c.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(l){for(let c of l)if(t.getSymbolAtLocation(c.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(c)){let m=c.typeArguments;if(m){let u=m[0];o=t.getTypeFromTypeNode(u).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let l=s[0].getParameters();l.length>0&&(o=t.getTypeOfSymbolAtLocation(l[0],r).getProperties())}}}if(o)for(let i of o){let a=fo(e,t,i);a&&n.push(a)}return n=n.filter(cn),n.length>0?n:go(e,r)}function fo(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 l=t.getTypeFromTypeNode(n.type),c=t.typeToString(l),d=Tt(c);d.knownType?i=d.builderType:ho(c)||l.flags&e.ts.TypeFlags.StringLike?i="string":l.flags&e.ts.TypeFlags.NumberLike?i="number":l.flags&e.ts.TypeFlags.IndexedAccess?i="list":l.flags&e.ts.TypeFlags.Object||l.isUnion()&&l.types.every(m=>m.flags&e.ts.TypeFlags.Object)||l.isIntersection()&&l.types.some(m=>m.flags&e.ts.TypeFlags.Object)?i="object":i="string",c!==i&&(a=c)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let l=yo(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},l&&l.length>0&&s.type==="string"&&l.every(So)?s.enum=l.map(To):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function go(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 l=s.jsDocPropertyTags;if(l)for(let c of l){if(!e.ts.isJSDocPropertyLikeTag(c))continue;let d=c.name;if(!e.ts.isQualifiedName(d))continue;let m=c.typeExpression;if(!m)continue;let u="";switch(m.type.kind){case e.ts.SyntaxKind.StringKeyword:{u="string";break}case e.ts.SyntaxKind.NumberKeyword:{u="number";break}case e.ts.SyntaxKind.BooleanKeyword:{u="boolean";break}default:continue}let x={name:d.right.text,type:u,isRegistered:!1};r.push(x)}}return r.filter(cn)}var xo=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function ho(e){return typeof e!="string"?!1:!!xo.some(t=>e.includes(t))}function Tt(e){return typeof e=="string"&&(e=e.trim(),Co.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var Co=[{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 So(e){return/^['"].*['"]$/.test(e)}function To(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var yo=(e,t,r)=>{let n=new Set;ln(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},wo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},ln=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{ln(e,t,o,n)});else if(r.isLiteral()){let o=wo(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!Do.has(t.toLowerCase())}var Do=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 H(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=A(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=Eo(e,n.initializer);G(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=ze(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function Eo(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Po(e,n));return r}function Po(e,t){let r=ze(e,t),n=Fo(r);return n.isRegistered=!0,n}function U(e,t,r){let n=bo(r);return t=$e(e,t,"name",n.name,!1),t=$e(e,t,"description",n.description),t=$e(e,t,"image",n.image),t=vo(e,t,n),Lo(e,t)}function vo(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 $e(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=No(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 bo(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Io)}}function Io(e){let t={name:e.name,type:e.type};return(z(e.defaultValue)||_e(e.defaultValue)||ve(e.defaultValue))&&(t.defaultValue=e.defaultValue),z(e.friendlyName)&&(t.friendlyName=e.friendlyName),z(e.helperText)&&(t.helperText=e.helperText),e.required===!0&&(t.required=!0),Array.isArray(e.enum)&&(t.enum=e.enum),e.hideFromUI===!0&&(t.hideFromUI=!0),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(t.meta=e.meta),t}function No(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>A(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=Ro(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(u=>A(e,u)==="name"),s=i.properties.find(u=>A(e,u)==="name"),l=a?.initializer,c=s?.initializer,d=l&&e.ts.isStringLiteral(l)?l.text:"zz",m=c&&e.ts.isStringLiteral(c)?c.text:"zz";return d.toLowerCase().localeCompare(m.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Ro(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=A(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=pn(e,t[n],r);else{let o=pn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function pn(e,t,r){let n=t.properties.filter(i=>e.ts.isPropertyAssignment(i)),o=Object.keys(r).filter(i=>i!=="isRegistered");for(let i of o)n=Ao(e,n,r,i);return n=Oo(e,n.filter(i=>{let a=A(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Ao(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,Ve(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,Ve(e,r[n]))),t}function G(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=yt(e)}function Fo(e){let t=Tt(e.type),r={name:e.name.trim(),type:t.builderType};return z(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(z(e.defaultValue)||_e(e.defaultValue)||ve(e.defaultValue))&&(r.defaultValue=e.defaultValue),z(e.helperText)&&(r.helperText=e.helperText),ve(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),wt(r)}function yt(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 wt(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 Lo(e,t){let r=[...t.properties].sort((n,o)=>{let i=A(e,n)||"zz",a=A(e,o)||"zz";if(i==="inputs")return 1;let s=un.indexOf(i),l=un.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var un=["component","name","description"];function Oo(e,t){return[...t].sort((n,o)=>{let i=A(e,n)||"zz",a=A(e,o)||"zz",s=mn.indexOf(i),l=mn.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)})}var mn=["name","type"];function fn(e,t){let r=`Builder.registerComponent(
|
|
11
|
+
`}return""}function b(e,t,r){t=W(t),r=W(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=W(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function W(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Ee(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return pn(o==="index"?e.basename(e.dirname(t)):o)}function pn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=W(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function _(e,t){let r=W(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 F(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 M(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function k(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 Be(e){return typeof e=="number"}function ve(e){return typeof e=="boolean"}function z(e){return typeof e=="string"}function $e(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function K(e){return JSON.parse(JSON.stringify(e))}function ze(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=uo(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,l)=>l!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,Ve(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,Ve(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function uo(e,t,r){return t.properties.findIndex(n=>I(e,n)===r)}function Ke(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return fo(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return mo(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 mo(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=I(e,n);o&&(r[o]=Ke(e,n.initializer))}}return r}function fo(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Ke(e,r)):[]}function I(e,t){if(t&&e.ts.isPropertyAssignment(t)){let r=t.name;switch(r.kind){case e.ts.SyntaxKind.Identifier:return r.text;case e.ts.SyntaxKind.StringLiteral:case e.ts.SyntaxKind.NumericLiteral:return r.text;case e.ts.SyntaxKind.ComputedPropertyName:let n=r.expression;if(e.ts.isStringLiteral(n)||e.ts.isNumericLiteral(n))return r.expression.text}}}function Ve(e,t){return Tt(e,t,new WeakSet)}function Tt(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)?go(e,t,r):typeof t=="object"?xo(e,t,r):e.ts.factory.createIdentifier(t)}function go(e,t,r){let n=t.map(o=>Tt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function xo(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,Tt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function ye(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 l=a.heritageClauses?.find(c=>c.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(l){for(let c of l)if(t.getSymbolAtLocation(c.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(c)){let u=c.typeArguments;if(u){let m=u[0];o=t.getTypeFromTypeNode(m).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let l=s[0].getParameters();l.length>0&&(o=t.getTypeOfSymbolAtLocation(l[0],r).getProperties())}}}if(o)for(let i of o){let a=ho(e,t,i);a&&n.push(a)}return n=n.filter(mn),n.length>0?n:Co(e,r)}function ho(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 l=t.getTypeFromTypeNode(n.type),c=t.typeToString(l),d=yt(c);d.knownType?i=d.builderType:To(c)||l.flags&e.ts.TypeFlags.StringLike?i="string":l.flags&e.ts.TypeFlags.NumberLike?i="number":l.flags&e.ts.TypeFlags.IndexedAccess?i="list":l.flags&e.ts.TypeFlags.Object||l.isUnion()&&l.types.every(u=>u.flags&e.ts.TypeFlags.Object)||l.isIntersection()&&l.types.some(u=>u.flags&e.ts.TypeFlags.Object)?i="object":i="string",c!==i&&(a=c)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let l=Po(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},l&&l.length>0&&s.type==="string"&&l.every(wo)?s.enum=l.map(Do):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function Co(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 l=s.jsDocPropertyTags;if(l)for(let c of l){if(!e.ts.isJSDocPropertyLikeTag(c))continue;let d=c.name;if(!e.ts.isQualifiedName(d))continue;let u=c.typeExpression;if(!u)continue;let m="";switch(u.type.kind){case e.ts.SyntaxKind.StringKeyword:{m="string";break}case e.ts.SyntaxKind.NumberKeyword:{m="number";break}case e.ts.SyntaxKind.BooleanKeyword:{m="boolean";break}default:continue}let x={name:d.right.text,type:m,isRegistered:!1};r.push(x)}}return r.filter(mn)}var So=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function To(e){return typeof e!="string"?!1:!!So.some(t=>e.includes(t))}function yt(e){return typeof e=="string"&&(e=e.trim(),yo.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var yo=[{value:"boolean",text:"boolean"},{value:"color",text:"color (provides a color in hex or rgb)"},{value:"date",text:"date (same format as the Date constructor)"},{value:"email",text:"email"},{value:"file",text:"file (uploads a file and provides a url)"},{value:"list",text:"list (collection of items)"},{value:"longText",text:"longText (multiline text editor)"},{value:"number",text:"number"},{value:"object",text:"object (set of specific names and values)"},{value:"richText",text:"richText (provides value as html)"},{value:"string",text:"string"}];function wo(e){return/^['"].*['"]$/.test(e)}function Do(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Po=(e,t,r)=>{let n=new Set;un(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},Eo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},un=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{un(e,t,o,n)});else if(r.isLiteral()){let o=Eo(e,t,r);n.add(o)}};function mn(e){let t=e?.name;if(typeof t!="string"||t===""||t.startsWith("aria")||t.startsWith("data-"))return!1;if(t.startsWith("on")&&t.length>2){let r=t.charAt(2);if(r.toUpperCase()===r)return!1}return!vo.has(t.toLowerCase())}var vo=new Set(["about","accessKey","accessKeyLabel","asChild","autoCapitalize","autoCorrect","autoFocus","autoSave","blur","contentEditable","contextMenu","dangerouslySetInnerHTML","datatype","defaultChecked","defaultValue","dir","draggable","enterKeyHint","focus","form","formAction","formEncType","formMethod","formNoValidate","formTarget","inlist","innerText","inputMode","is","isContentEditable","itemID","itemProp","itemRef","itemScope","itemType","lang","nonce","offsetHeight","offsetLeft","offsetTop","offsetWidth","outerText","prefix","property","radioGroup","rel","resource","results","rev","role","security","slot","spellCheck","suppressContentEditableWarning","suppressHydrationWarning","tabIndex","translate","typeof","unselectable","vocab"].map(e=>e.toLowerCase()));function H(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=I(e,n);if(o==="name"&&e.ts.isStringLiteral(n.initializer)){t.name=n.initializer.text;continue}if(o==="description"&&e.ts.isStringLiteral(n.initializer)){t.description=n.initializer.text;continue}if(o==="image"&&e.ts.isStringLiteral(n.initializer)){t.image=n.initializer.text;continue}if(o==="inputs"&&e.ts.isArrayLiteralExpression(n.initializer)){let i=bo(e,n.initializer);G(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Ke(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function bo(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Io(e,n));return r}function Io(e,t){let r=Ke(e,t),n=ko(r);return n.isRegistered=!0,n}function U(e,t,r){let n=Ro(r);return t=ze(e,t,"name",n.name,!1),t=ze(e,t,"description",n.description),t=ze(e,t,"image",n.image),t=No(e,t,n),jo(e,t)}function No(e,t,r){let n=null,o=t.properties.filter(s=>e.ts.isPropertyAssignment(s)&&e.ts.isIdentifier(s.name)),i=o.findIndex(s=>e.ts.isIdentifier(s.name)&&s.name.text==="inputs"),a=[...r.inputs??[]];if(i>-1){if(a.length===0)return ze(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=Fo(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 Ro(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Ao)}}function Ao(e){let t={name:e.name,type:e.type};return(z(e.defaultValue)||Be(e.defaultValue)||ve(e.defaultValue))&&(t.defaultValue=e.defaultValue),z(e.friendlyName)&&(t.friendlyName=e.friendlyName),z(e.helperText)&&(t.helperText=e.helperText),e.required===!0&&(t.required=!0),Array.isArray(e.enum)&&(t.enum=e.enum),e.hideFromUI===!0&&(t.hideFromUI=!0),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(t.meta=e.meta),t}function Fo(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>I(e,s)==="name");if(!i)return!1;let a=i.initializer;return e.ts.isStringLiteral(a)?r.some(s=>s.name===a.text):!1});for(let o of r)n=Lo(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(m=>I(e,m)==="name"),s=i.properties.find(m=>I(e,m)==="name"),l=a?.initializer,c=s?.initializer,d=l&&e.ts.isStringLiteral(l)?l.text:"zz",u=c&&e.ts.isStringLiteral(c)?c.text:"zz";return d.toLowerCase().localeCompare(u.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Lo(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=I(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=fn(e,t[n],r);else{let o=fn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function fn(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=Oo(e,n,r,i);return n=_o(e,n.filter(i=>{let a=I(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Oo(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,Ve(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,Ve(e,r[n]))),t}function G(e,t){for(let r of t){let n=e.inputs.findIndex(o=>o.name===r.name);n>-1?(r.isRegistered||!e.inputs[n].isRegistered)&&(e.inputs[n]=r):e.inputs.push(r)}e.acceptsChildren=wt(e)}function ko(e){let t=yt(e.type),r={name:e.name.trim(),type:t.builderType};return z(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(z(e.defaultValue)||Be(e.defaultValue)||ve(e.defaultValue))&&(r.defaultValue=e.defaultValue),z(e.helperText)&&(r.helperText=e.helperText),ve(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),Dt(r)}function wt(e){let t=e.inputs.some(n=>n.name==="children"),r=e.inputs.some(n=>n.meta?.ts==="ReactNode");return!!(t||r||e.acceptsChildren===!0)}function Dt(e){if(e.name==="children"&&(e.hideFromUI=!0,delete e.required),e.type==="object"&&e.defaultValue==null&&(e.hideFromUI=!0),e.type==="list"&&e.defaultValue==null&&(e.hideFromUI=!0),e.meta){let t=e.meta.ts;typeof t=="string"&&(t=t.trim(),t.endsWith("ReactNode")&&(t="ReactNode"),e.meta.ts=t,t==="ReactNode"&&(e.hideFromUI=!0))}return e}function jo(e,t){let r=[...t.properties].sort((n,o)=>{let i=I(e,n)||"zz",a=I(e,o)||"zz";if(i==="inputs")return 1;let s=dn.indexOf(i),l=dn.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var dn=["component","name","description"];function _o(e,t){return[...t].sort((n,o)=>{let i=I(e,n)||"zz",a=I(e,o)||"zz",s=gn.indexOf(i),l=gn.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)})}var gn=["name","type"];function xn(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 l=Ke.get(a);if(l)return D(e,l.content)}let s=e.readFileSync(a);if(s==null){let l=e.basename(a),c=e.extname(l).toLowerCase();if(a.startsWith(n)&&c===".ts"&&(s=gn.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new ot(l)}return a.includes("node_modules")&&(s?Ke.set(a,{exists:!0,content:s}):Ke.set(a,{exists:!1})),D(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return ko(e,i,t)}catch(a){if(a instanceof ot){await jo(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function ko(e,t,r){let n={rootNames:[...r],options:{},host:t},o=e.ts.findConfigFile(e.dirname(r[0]),i=>e.existsSync(i));if(o){let i=dn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let l=e.readFileSync(s);return typeof l=="string"?l:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(l,c)=>e.readdirSync(l),fileExists:l=>e.existsSync(l),readFile:l=>e.readFileSync(l)||void 0},e.dirname(o),void 0,o).options,dn.set(o,i))}i&&(n.options=K(i))}return n.options.moduleResolution=e.ts.ModuleResolutionKind.Node16,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 be(e,t,r){r||(r=await V(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 ot=class{constructor(t){this.libName=t}};async function jo(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;rt.has(t)||rt.set(t,fetch(r).then(n=>n.text()).then(n=>{gn.set(t,n)})),await rt.get(t),rt.delete(t)}var gn=new Map,rt=new Map,Ke=new Map,dn=new Map;function E(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=_o(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=Bo(e,t,r.defaultImport,r.importPath,n)),t}function _o(e,t,r,n,o,i){return i==="cjs"?hn(e,t,null,r,n):xn(e,t,null,r,n,o)}function Bo(e,t,r,n,o){return o==="cjs"?hn(e,t,r,null,n):xn(e,t,r,null,n,!1)}function xn(e,t,r,n,o,i){let a=[...t.statements],s=0,l=!1,c=!1;for(let p=0;p<a.length;p++){let x=a[p];if(!e.ts.isImportDeclaration(x)||(s=p,!x.moduleSpecifier||!e.ts.isStringLiteral(x.moduleSpecifier))||x.moduleSpecifier.text!==o||!!x.importClause?.isTypeOnly!==i)continue;let f=[],g=x.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&f.push(...g.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,T)=>C.name.text.localeCompare(T.name.text)),l=!0}let h=x.importClause?x.importClause.name:void 0;if(typeof r=="string"){if(h&&h.text===r)return t;h=e.ts.factory.createIdentifier(r),c=!0}if(l||c)return a[p]=e.ts.factory.updateImportDeclaration(x,void 0,e.ts.factory.createImportClause(i,h,e.ts.factory.createNamedImports(f)),x.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,m;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(m=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let u=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,m),e.ts.factory.createStringLiteral(o));return a.splice(s,0,u),e.ts.factory.updateSourceFile(t,a)}function hn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let l=i[s];if(e.ts.isVariableStatement(l))for(let c=0;c<l.declarationList.declarations.length;c++){let d=[...l.declarationList.declarations],m=d[c],u=m.initializer;if(!u||!e.ts.isCallExpression(u))continue;let p=u.expression;if(!e.ts.isIdentifier(p)||p.text!=="require"||u.arguments.length!==1)continue;let x=u.arguments[0];if(e.ts.isStringLiteral(x)&&(a=s,x.text===o)){if(e.ts.isIdentifier(m.name)&&typeof r=="string")return m.name.text===r?t:(d[c]=e.ts.factory.updateVariableDeclaration(m,e.ts.factory.createIdentifier(r),m.exclamationToken,m.type,m.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(m.name)&&typeof n=="string"){let f=[...m.name.elements];return f.some(h=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)?!1:h.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((h,C)=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:h.name.text.localeCompare(C.name.text)),d[c]=e.ts.factory.updateVariableDeclaration(m,e.ts.factory.createObjectBindingPattern(f),m.exclamationToken,m.type,m.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.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 Q(e,t,r="esm"){return r==="cjs"?$o(e,t):Vo(e,t)}function Vo(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 l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.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 $o(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 l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.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 Ie(e,t,r,n){let o=zo(e,r,n);if(o){let i=await Ue(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:R(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function Ne(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 q(e,t,r){let n=Ne(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 it(e,t){if(t){if(Ko(e,t))return!0;let r=!1;if(t.forEachChild(n=>{it(e,n)&&(r=!0)}),r)return!0}return!1}function Ko(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 Ue(e,t){let r=e.extname(t).toLowerCase();if(r===""||!Et.includes(r)){for(let n of Et){let o=t+n;if(await e.exists(o))return o}for(let n of Et){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var Et=[".tsx",".jsx",".ts",".js"];function Me(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=Uo(e,i);return a?[{name:a}]:void 0}function Uo(e,t){if(typeof t=="string"){t=e.normalize(W(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 te(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 Re(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await V(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 c=(await xe(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);c&&(a.inputs=Te(e,o,c.node.fnNode))}}return a}))}async function Ae(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await be(e,t.cmpInfo.filePath,r),a=(await xe(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 Te(e,o,a.node.fnNode)}return[]}async function Cn(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 Mo(e,t,n)}return null}function Mo(e,t,r){let n=D(e,r);return xe(e,null,t,n)}async function xe(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=Q(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await Qo(e,t,r,a);o.push(...s)})),o}async function Qo(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=_(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Be(s.name.text))continue;let l=Qe(e,t,s.initializer);if(l){let c=l.name||s.name.text,d=n.isDefaultExport?"default":c,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:R(e,r),name:j(c),inputs:[],exportName:d,exportType:m,importName:c,filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}}return o}if(e.ts.isArrowFunction(n.node)){let s=Qe(e,t,n.node);if(s){let l=Y(e,r),c=n.isDefaultExport?"default":l,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:R(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:Pe(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&&!Be(s))return o;let l=Qe(e,t,n.node);if(l){let c=l.name||Y(e,r),d=n.isDefaultExport||!l.name?"default":l.name,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:R(e,r),name:c,inputs:[],exportName:d,exportType:m,importName:l.name||Pe(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}return o}if(e.ts.isExportSpecifier(n.node)&&Be(n.node.getText())){let s=Qe(e,t,n.node);if(s){let l=s.name||Y(e,r),c=n.isDefaultExport||!s.name?"default":s.name,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:R(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:s.name||Pe(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function Qe(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return it(e,r.body)?{name:"",fnNode:r,deps:Me(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return it(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Me(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:Qe(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)||!Be(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Me(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Me(e,t,n)}}return null}async function Sn(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(Jo(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await xe(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var qo=new Set(["node_modules","dist"]);function Jo(e,t){for(let r of qo)if(e.dirname(t).includes(r))return!0;return!1}async function Tn(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&&Wo.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 l=await xe(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Wo=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 ne(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 l=a.moduleSpecifier.text;if(!l.startsWith(".")&&!l.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,[...Pt(e,r),...Pt(e,n),...Pt(e,o),...i])}function J(e){let t=e.split(`
|
|
21
|
+
`,r+=");";let n=rt(e,r);return Pt(e,n,t)}function Pt(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]=U(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function $(e,t){if(!Array.isArray(t)||t.length===0)throw new Error(`createTsProgram() Invalid filePaths: ${t}`);let r=await sn(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=Ue.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}Ue.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 l=Ue.get(a);if(l)return D(e,l.content)}let s=e.readFileSync(a);if(s==null){let l=e.basename(a),c=e.extname(l).toLowerCase();if(a.startsWith(n)&&c===".ts"&&(s=Cn.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new it(l)}return a.includes("node_modules")&&(s?Ue.set(a,{exists:!0,content:s}):Ue.set(a,{exists:!1})),D(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return Bo(e,i,t)}catch(a){if(a instanceof it){await $o(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Bo(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=hn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let l=e.readFileSync(s);return typeof l=="string"?l:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(l,c)=>e.readdirSync(l),fileExists:l=>e.existsSync(l),readFile:l=>e.readFileSync(l)||void 0},e.dirname(o),void 0,o).options,hn.set(o,i))}i&&(n.options=K(i))}return n.options.moduleResolution=e.ts.ModuleResolutionKind.Node16,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 be(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 it=class{constructor(t){this.libName=t}};async function $o(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;ot.has(t)||ot.set(t,fetch(r).then(n=>n.text()).then(n=>{Cn.set(t,n)})),await ot.get(t),ot.delete(t)}var Cn=new Map,ot=new Map,Ue=new Map,hn=new Map;function P(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Vo(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=zo(e,t,r.defaultImport,r.importPath,n)),t}function Vo(e,t,r,n,o,i){return i==="cjs"?Tn(e,t,null,r,n):Sn(e,t,null,r,n,o)}function zo(e,t,r,n,o){return o==="cjs"?Tn(e,t,r,null,n):Sn(e,t,r,null,n,!1)}function Sn(e,t,r,n,o,i){let a=[...t.statements],s=0,l=!1,c=!1;for(let p=0;p<a.length;p++){let x=a[p];if(!e.ts.isImportDeclaration(x)||(s=p,!x.moduleSpecifier||!e.ts.isStringLiteral(x.moduleSpecifier))||x.moduleSpecifier.text!==o||!!x.importClause?.isTypeOnly!==i)continue;let f=[],g=x.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&f.push(...g.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,T)=>C.name.text.localeCompare(T.name.text)),l=!0}let h=x.importClause?x.importClause.name:void 0;if(typeof r=="string"){if(h&&h.text===r)return t;h=e.ts.factory.createIdentifier(r),c=!0}if(l||c)return a[p]=e.ts.factory.updateImportDeclaration(x,void 0,e.ts.factory.createImportClause(i,h,e.ts.factory.createNamedImports(f)),x.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,u;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(u=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let m=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,u),e.ts.factory.createStringLiteral(o));return a.splice(s,0,m),e.ts.factory.updateSourceFile(t,a)}function Tn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let l=i[s];if(e.ts.isVariableStatement(l))for(let c=0;c<l.declarationList.declarations.length;c++){let d=[...l.declarationList.declarations],u=d[c],m=u.initializer;if(!m||!e.ts.isCallExpression(m))continue;let p=m.expression;if(!e.ts.isIdentifier(p)||p.text!=="require"||m.arguments.length!==1)continue;let x=m.arguments[0];if(e.ts.isStringLiteral(x)&&(a=s,x.text===o)){if(e.ts.isIdentifier(u.name)&&typeof r=="string")return u.name.text===r?t:(d[c]=e.ts.factory.updateVariableDeclaration(u,e.ts.factory.createIdentifier(r),u.exclamationToken,u.type,u.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(u.name)&&typeof n=="string"){let f=[...u.name.elements];return f.some(h=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)?!1:h.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((h,C)=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:h.name.text.localeCompare(C.name.text)),d[c]=e.ts.factory.updateVariableDeclaration(u,e.ts.factory.createObjectBindingPattern(f),u.exclamationToken,u.type,u.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.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 Q(e,t,r="esm"){return r==="cjs"?Uo(e,t):Ko(e,t)}function Ko(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 l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.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 Uo(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 l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.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 Mo(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 Ie(e,t,r,n){let o=Mo(e,r,n);if(o){let i=await Me(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:F(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function Ne(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 q(e,t,r){let n=Ne(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 at(e,t){if(t){if(Qo(e,t))return!0;let r=!1;if(t.forEachChild(n=>{at(e,n)&&(r=!0)}),r)return!0}return!1}function Qo(e,t){return e.ts.isJsxElement(t)||e.ts.isJsxOpeningElement(t)||e.ts.isJsxOpeningFragment(t)||e.ts.isJsxSelfClosingElement(t)||e.ts.isJsxFragment(t)||e.ts.isJsxChild(t)}async function Me(e,t){let r=e.extname(t).toLowerCase();if(r===""||!Et.includes(r)){for(let n of Et){let o=t+n;if(await e.exists(o))return o}for(let n of Et){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var Et=[".tsx",".jsx",".ts",".js"];function Qe(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=qo(e,i);return a?[{name:a}]:void 0}function qo(e,t){if(typeof t=="string"){t=e.normalize(W(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 te(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 Re(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=>{if(!a.isRegistered){let s=n.getSourceFile(a.filePath);if(s){let c=(await he(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);c&&(a.inputs=ye(e,o,c.node.fnNode))}}return a}))}async function Ae(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await be(e,t.cmpInfo.filePath,r),a=(await he(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 ye(e,o,a.node.fnNode)}return[]}async function yn(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 Jo(e,t,n)}return null}function Jo(e,t,r){let n=D(e,r);return he(e,null,t,n)}async function he(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=Q(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await Wo(e,t,r,a);o.push(...s)})),o}async function Wo(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=_(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!$e(s.name.text))continue;let l=qe(e,t,s.initializer);if(l){let c=l.name||s.name.text,d=n.isDefaultExport?"default":c,u=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:F(e,r),name:j(c),inputs:[],exportName:d,exportType:u,importName:c,filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}}return o}if(e.ts.isArrowFunction(n.node)){let s=qe(e,t,n.node);if(s){let l=Y(e,r),c=n.isDefaultExport?"default":l,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:F(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:Ee(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&&!$e(s))return o;let l=qe(e,t,n.node);if(l){let c=l.name||Y(e,r),d=n.isDefaultExport||!l.name?"default":l.name,u=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:F(e,r),name:c,inputs:[],exportName:d,exportType:u,importName:l.name||Ee(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}return o}if(e.ts.isExportSpecifier(n.node)&&$e(n.node.getText())){let s=qe(e,t,n.node);if(s){let l=s.name||Y(e,r),c=n.isDefaultExport||!s.name?"default":s.name,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:F(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:s.name||Ee(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function qe(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return at(e,r.body)?{name:"",fnNode:r,deps:Qe(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return at(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Qe(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:qe(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)||!$e(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Qe(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Qe(e,t,n)}}return null}async function wn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.normalize(i.fileName);if(Ho(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await he(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Yo=new Set(["node_modules","dist"]);function Ho(e,t){for(let r of Yo)if(e.dirname(t).includes(r))return!0;return!1}async function Dn(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&&Go.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 l=await he(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Go=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 ne(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 l=a.moduleSpecifier.text;if(!l.startsWith(".")&&!l.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,[...vt(e,r),...vt(e,n),...vt(e,o),...i])}function J(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,19 +28,19 @@ ${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 En(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 Fe(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=wn(e,r),i=wn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function wn(e,t){let r=t.properties.find(n=>A(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function Pn(e){let t=await e.readFile(e.registryPath);return t?Yo(e,t):{components:[],sourceFile:D(e,"")}}async function Yo(e,t){let r=D(e,t);return Ho(e,r)}async function Ho(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 c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let m=c[0];if(e.ts.isCallExpression(m)){let u=e.ts.isIdentifier(m.expression)&&m.expression.text;if(u==="withChildren"){let x=It(e,m.arguments[0]);if(e.ts.isCallExpression(x)){let f=await vt(e,n,x,d,!0);f&&r.push(f)}else{let f=x;if(e.ts.isIdentifier(f)){let g=await bt(e,t,n,f,d,!0);g&&r.push(g)}}continue}if(u==="dynamic"){let x=await vt(e,n,m,d,!1);x&&r.push(x);continue}let p=It(e,m.arguments[0]);if(e.ts.isCallExpression(p)&&e.ts.isIdentifier(p.expression)&&p.expression.text==="dynamic"){let x=await vt(e,n,p,d,!1);x&&r.push(x);continue}if(e.ts.isIdentifier(p)){let x=await bt(e,t,n,p,d,!1);x&&r.push(x);continue}continue}if(e.ts.isIdentifier(m)){let u=await bt(e,t,n,m,d,!1);u&&r.push(u);continue}}return{sourceFile:t,components:M(r)}}function It(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:It(e,t.arguments[0]):t}async function vt(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 l=s.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let d=l.arguments[0];if(!e.ts.isStringLiteral(d))return null;let m=d.text;i.filePath=await at(e,m),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let c=l.expression;if(!e.ts.isParenthesizedExpression(c))return null;let d=c.expression;if(!e.ts.isAwaitExpression(d))return null;let m=d.expression;if(!e.ts.isCallExpression(m)||m.expression.kind!==e.ts.SyntaxKind.ImportKeyword||m.arguments.length!==1)return null;let p=m.arguments[0];if(!e.ts.isStringLiteral(p)||!e.ts.isIdentifier(l.name))return null;let x=p.text;i.filePath=await at(e,x),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=j(l.name.text),i.importName=l.name.text,i.exportName=l.name.text,i.exportType="named"}else return null;return i=H(e,i,n),i.displayFilePath=R(e,i.filePath),i.filePath&&i.exportName&&(i.id=await k(e,i.filePath,i.exportName)),i}async function bt(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(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await at(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(m=>!m.importClause||!m.importClause.namedBindings||!e.ts.isNamedImports(m.importClause.namedBindings)?!1:m.importClause.namedBindings.elements.some(u=>u.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await at(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=H(e,a,o),a.displayFilePath=R(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function at(e,t){return Ue(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function vn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let c=0;c<i.length;c++){let d=i[c];if(e.ts.isImportDeclaration(d)){o=c;continue}if(!e.ts.isExpressionStatement(d))continue;let m=d.expression;if(!e.ts.isCallExpression(m))continue;let u=m.expression;if(!e.ts.isPropertyAccessExpression(u))continue;let p=u.expression;if(!e.ts.isIdentifier(p)||p.text!=="builder")continue;if(u.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(Se)),s=r?e.ts.factory.createNonNullExpression(a):a,l=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,l),e.ts.factory.updateSourceFile(t,i)}function re(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 l=[...s.elements];for(let c=l.length-1;c>=0;c--){let d=l[c];if(e.ts.isImportSpecifier(d)){let m=d.name;if(m&&e.ts.isIdentifier(m)){let u=m.text;bn(e,t,u)||l.splice(c,1)}}}if(l.length===0)a=!0;else if(s.elements.length!==l.length){let c=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(l)),d=e.ts.factory.updateImportDeclaration(i,void 0,c,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;bn(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function bn(e,t,r){let n=!1;function o(i){if(!e.ts.isImportDeclaration(i)){if(e.ts.isIdentifier(i)&&i.text===r){n=!0;return}e.ts.forEachChild(i,o)}}return e.ts.forEachChild(t,o),n}function oe(e,t,r,n,o,i,a){let s=null,l=null,c=null,d=-1;t=K(t),r=K(r);let m=t.find(p=>p.id===e),u=r.find(p=>p.id===e);if(n)u||(s={...K(m),inputs:K(m.inputs).map(p=>(p.isRegistered=!0,p))},d=r.length,r.push(s));else if(typeof u?.nodeIndex=="number"&&u.nodeIndex>-1){if(o)d=u.nodeIndex,l=K(u),r=r.filter(p=>p.id!==e);else if(i!=null)Go(u,i),d=u.nodeIndex,c=u;else if(a!=null){let p=u.inputs.find(x=>x.name===a.name);p&&(a.registerInput===!1?p.isRegistered=!1:(Xo(p,a),p.isRegistered=!0),c=u,d=u.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:c,nodeIndex:d,components:X(t,r)}}function X(e,t){let r=M([...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(wt),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=yt(n))}),r}function Go(e,t){z(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),z(t.description)?e.description=t.description:t.description===null&&delete e.description,z(t.image)?e.image=t.image:t.image===null&&delete e.image}function Xo(e,t){z(t.type)&&(e.type=t.type),z(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,z(t.defaultValue)||_e(t.defaultValue)||ve(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,z(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function he(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),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".jsx"||l===".ts"||l===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await V(e,[...t])}async function ie(e,t,r,n,o,i,a,s){let l=await he(e),[c,d,m,u]=await Promise.all([Tn(e,l),Pn(e),Nt(e),je(e)]),p=c.map(T=>T.cmpInfo),x=d.components,f={components:X(p,x),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(p),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Re(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let T=C.map(S=>{let P=c.find(O=>O.cmpInfo.id===S);if(!P)throw new Error(`Component ${S} not found`);return P}),F=Array.from(new Set(T.map(S=>S.cmpInfo.filePath))),w=await V(e,F);for(let S of T){let P=f.components.find(I=>I.id===S.cmpInfo.id),O=await Ae(e,S,w);G(P,O);let v=p.findIndex(I=>I.id===S.cmpInfo.id);p[v].inputs=O;let y=oe(S.cmpInfo.id,p,x,r,n,o,i),b=[...h.statements];if(y.addCmpToRegistry?(b.push(fn(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(b.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(b[y.nodeIndex]=Dt(e,b[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a){if(h=e.ts.factory.updateSourceFile(h,b),h=E(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=vn(e,h,m),e.appDir){let I=y.addCmpToRegistry||y.updateRegisteredCmp;if(I){let $=L(e,e.registryPath,I.filePath);I.exportType==="default"?h=E(e,h,{defaultImport:I.importName,importPath:$}):I.exportType==="named"&&(h=E(e,h,{namedImports:[I.importName],importPath:$}))}}else h=E(e,h,{defaultImport:"dynamic",importPath:"next/dynamic"});P?.acceptsChildren&&(h=E(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=y.components,x=y.components.filter(I=>I.isRegistered)}}}if(g&&a){h=re(e,h),h=ne(e,h),e.appDir&&(h=En(e,h));let T=N(e,h);T=J(T),e.appDir&&(T=Dn(T)),T=await e.formatCode(e.registryPath,T),await e.writeFile(e.registryPath,T)}return f}async function In(e){let t=[],r=await oi(e,t);return await ai(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await ei(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await ni(e,e.pagesDir,t)),t}async function Nn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await Zo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await ri(e,e.pagesDir,t)),t}async function Zo(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,Rn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function ei(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,Rn({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,ti(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function ti(e){let t=e.typescriptEnabled;return`
|
|
31
|
+
`}function vt(e,t){return t.sort((r,n)=>{let o=Pn(e,r),i=Pn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function Pn(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 vn(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
|
|
32
|
+
${e}`),e}function bn(e,t){let r=t.statements.filter(n=>!(e.ts.isExpressionStatement(n)&&e.ts.isStringLiteral(n.expression)&&e.ts.isStringLiteral(n.expression)&&n.expression.text==="use client"));return e.ts.factory.updateSourceFile(t,r)}function Fe(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=En(e,r),i=En(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function En(e,t){let r=t.properties.find(n=>I(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function In(e){let t=await e.readFile(e.registryPath);return t?Xo(e,t):{components:[],sourceFile:D(e,"")}}async function Xo(e,t){let r=D(e,t);return Zo(e,r)}async function Zo(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 c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let u=c[0];if(e.ts.isCallExpression(u)){let m=e.ts.isIdentifier(u.expression)&&u.expression.text;if(m==="withChildren"){let x=Nt(e,u.arguments[0]);if(e.ts.isCallExpression(x)){let f=await bt(e,n,x,d,!0);f&&r.push(f)}else{let f=x;if(e.ts.isIdentifier(f)){let g=await It(e,t,n,f,d,!0);g&&r.push(g)}}continue}if(m==="dynamic"){let x=await bt(e,n,u,d,!1);x&&r.push(x);continue}let p=Nt(e,u.arguments[0]);if(e.ts.isCallExpression(p)&&e.ts.isIdentifier(p.expression)&&p.expression.text==="dynamic"){let x=await bt(e,n,p,d,!1);x&&r.push(x);continue}if(e.ts.isIdentifier(p)){let x=await It(e,t,n,p,d,!1);x&&r.push(x);continue}continue}if(e.ts.isIdentifier(u)){let m=await It(e,t,n,u,d,!1);m&&r.push(m);continue}}return{sourceFile:t,components:M(r)}}function Nt(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:Nt(e,t.arguments[0]):t}async function bt(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let l=s.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let d=l.arguments[0];if(!e.ts.isStringLiteral(d))return null;let u=d.text;i.filePath=await st(e,u),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let c=l.expression;if(!e.ts.isParenthesizedExpression(c))return null;let d=c.expression;if(!e.ts.isAwaitExpression(d))return null;let u=d.expression;if(!e.ts.isCallExpression(u)||u.expression.kind!==e.ts.SyntaxKind.ImportKeyword||u.arguments.length!==1)return null;let p=u.arguments[0];if(!e.ts.isStringLiteral(p)||!e.ts.isIdentifier(l.name))return null;let x=p.text;i.filePath=await st(e,x),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=j(l.name.text),i.importName=l.name.text,i.exportName=l.name.text,i.exportType="named"}else return null;return i=H(e,i,n),i.displayFilePath=F(e,i.filePath),i.filePath&&i.exportName&&(i.id=await k(e,i.filePath,i.exportName)),i}async function It(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(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await st(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(u=>!u.importClause||!u.importClause.namedBindings||!e.ts.isNamedImports(u.importClause.namedBindings)?!1:u.importClause.namedBindings.elements.some(m=>m.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await st(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=H(e,a,o),a.displayFilePath=F(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function st(e,t){return Me(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function Nn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let c=0;c<i.length;c++){let d=i[c];if(e.ts.isImportDeclaration(d)){o=c;continue}if(!e.ts.isExpressionStatement(d))continue;let u=d.expression;if(!e.ts.isCallExpression(u))continue;let m=u.expression;if(!e.ts.isPropertyAccessExpression(m))continue;let p=m.expression;if(!e.ts.isIdentifier(p)||p.text!=="builder")continue;if(m.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(Te)),s=r?e.ts.factory.createNonNullExpression(a):a,l=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,l),e.ts.factory.updateSourceFile(t,i)}function re(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 l=[...s.elements];for(let c=l.length-1;c>=0;c--){let d=l[c];if(e.ts.isImportSpecifier(d)){let u=d.name;if(u&&e.ts.isIdentifier(u)){let m=u.text;Rn(e,t,m)||l.splice(c,1)}}}if(l.length===0)a=!0;else if(s.elements.length!==l.length){let c=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(l)),d=e.ts.factory.updateImportDeclaration(i,void 0,c,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;Rn(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Rn(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 oe(e,t,r,n,o,i,a){let s=null,l=null,c=null,d=-1;t=K(t),r=K(r);let u=t.find(p=>p.id===e),m=r.find(p=>p.id===e);if(n)m||(s={...K(u),inputs:K(u.inputs).map(p=>(p.isRegistered=!0,p))},d=r.length,r.push(s));else if(typeof m?.nodeIndex=="number"&&m.nodeIndex>-1){if(o)d=m.nodeIndex,l=K(m),r=r.filter(p=>p.id!==e);else if(i!=null)ei(m,i),d=m.nodeIndex,c=m;else if(a!=null){let p=m.inputs.find(x=>x.name===a.name);p&&(a.registerInput===!1?p.isRegistered=!1:(ti(p,a),p.isRegistered=!0),c=m,d=m.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:c,nodeIndex:d,components:X(t,r)}}function X(e,t){let r=M([...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(Dt),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=wt(n))}),r}function ei(e,t){z(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),z(t.description)?e.description=t.description:t.description===null&&delete e.description,z(t.image)?e.image=t.image:t.image===null&&delete e.image}function ti(e,t){z(t.type)&&(e.type=t.type),z(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,z(t.defaultValue)||Be(t.defaultValue)||ve(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,z(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function Ce(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),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".jsx"||l===".ts"||l===".js"){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 l=await Ce(e),[c,d,u,m]=await Promise.all([Dn(e,l),In(e),Rt(e),_e(e)]),p=c.map(T=>T.cmpInfo),x=d.components,f={components:X(p,x),registryPath:e.registryPath,registryDisplayPath:F(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(p),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Re(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let T=C.map(S=>{let E=c.find(O=>O.cmpInfo.id===S);if(!E)throw new Error(`Component ${S} not found`);return E}),L=Array.from(new Set(T.map(S=>S.cmpInfo.filePath))),w=await $(e,L);for(let S of T){let E=f.components.find(A=>A.id===S.cmpInfo.id),O=await Ae(e,S,w);G(E,O);let N=p.findIndex(A=>A.id===S.cmpInfo.id);p[N].inputs=O;let y=oe(S.cmpInfo.id,p,x,r,n,o,i),R=[...h.statements];if(y.addCmpToRegistry?(R.push(xn(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(R.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(R[y.nodeIndex]=Pt(e,R[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a){if(h=e.ts.factory.updateSourceFile(h,R),h=P(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=Nn(e,h,u),e.appDir){let A=y.addCmpToRegistry||y.updateRegisteredCmp;if(A){let V=b(e,e.registryPath,A.filePath);A.exportType==="default"?h=P(e,h,{defaultImport:A.importName,importPath:V}):A.exportType==="named"&&(h=P(e,h,{namedImports:[A.importName],importPath:V}))}}else h=P(e,h,{defaultImport:"dynamic",importPath:"next/dynamic"});E?.acceptsChildren&&(h=P(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=y.components,x=y.components.filter(A=>A.isRegistered)}}}if(g&&a){h=re(e,h),h=ne(e,h),e.appDir&&(h=bn(e,h));let T=v(e,h);T=J(T),e.appDir&&(T=vn(T)),T=await e.formatCode(e.registryPath,T),await e.writeFile(e.registryPath,T)}return f}async function An(e){let t=[],r=await si(e,t);return await ci(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await ri(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await ii(e,e.pagesDir,t)),t}async function Fn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await ni(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await ai(e,e.pagesDir,t)),t}async function ni(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,Ln({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function ri(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,Ln({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,oi(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function oi(e){let t=e.typescriptEnabled;return`
|
|
33
33
|
"use client";
|
|
34
34
|
${t?'import { ComponentProps } from "react";':""}
|
|
35
35
|
import { BuilderComponent, useIsPreviewing } from "@builder.io/react";
|
|
36
36
|
import { ${t?"BuilderContent, ":""}builder } from '@builder.io/sdk';
|
|
37
37
|
import DefaultErrorPage from "next/error";
|
|
38
|
-
import ${JSON.stringify(
|
|
38
|
+
import ${JSON.stringify(b(e,e.builderComponentPath,e.registryPath))};
|
|
39
39
|
${t?`
|
|
40
40
|
type BuilderPageProps = ComponentProps<typeof BuilderComponent>;`:""}
|
|
41
41
|
|
|
42
42
|
// Builder Public API Key set in .env file
|
|
43
|
-
builder.init(process.env.${
|
|
43
|
+
builder.init(process.env.${Te}${t?"!":""});
|
|
44
44
|
|
|
45
45
|
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
46
46
|
// Call the useIsPreviewing hook to determine if
|
|
@@ -56,12 +56,12 @@ export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":
|
|
|
56
56
|
// DefaultErrorPage with a 404.
|
|
57
57
|
return <DefaultErrorPage statusCode={404} />;
|
|
58
58
|
}
|
|
59
|
-
`.trimStart()}function
|
|
59
|
+
`.trimStart()}function Ln({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=b(e,t,e.builderComponentPath);return`
|
|
60
60
|
import { builder } from "@builder.io/sdk";
|
|
61
61
|
import { RenderBuilderContent } from ${JSON.stringify(o)};
|
|
62
62
|
|
|
63
63
|
// Builder Public API Key set in .env file
|
|
64
|
-
builder.init(process.env.${
|
|
64
|
+
builder.init(process.env.${Te}${n?"!":""});
|
|
65
65
|
${n?`
|
|
66
66
|
interface PageProps {
|
|
67
67
|
params: {
|
|
@@ -90,7 +90,7 @@ export default async function Page(props${n?": PageProps":""}) {
|
|
|
90
90
|
</>
|
|
91
91
|
);
|
|
92
92
|
}
|
|
93
|
-
`.trimStart()}async function
|
|
93
|
+
`.trimStart()}async function ii(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,On({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function ai(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,On({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function On({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return`
|
|
94
94
|
import React from "react";
|
|
95
95
|
import { useRouter } from "next/router";
|
|
96
96
|
import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
|
|
@@ -98,9 +98,9 @@ import DefaultErrorPage from "next/error";
|
|
|
98
98
|
import Head from "next/head";${n?`
|
|
99
99
|
import { BuilderContent } from "@builder.io/sdk";`:""}${n?`
|
|
100
100
|
import { GetStaticProps } from "next";`:""}
|
|
101
|
-
import ${JSON.stringify(
|
|
101
|
+
import ${JSON.stringify(b(e,t,e.registryPath))};
|
|
102
102
|
|
|
103
|
-
builder.init(process.env.${
|
|
103
|
+
builder.init(process.env.${Te}${n?"!":""});
|
|
104
104
|
|
|
105
105
|
// Define a function that fetches the Builder
|
|
106
106
|
// content for a given page
|
|
@@ -164,7 +164,7 @@ export default function Page({ page }${n?": { page: BuilderContent | null }":""}
|
|
|
164
164
|
</>
|
|
165
165
|
);
|
|
166
166
|
}
|
|
167
|
-
`.trimStart()}async function
|
|
167
|
+
`.trimStart()}async function si(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:l}=li(e);if(!await e.exists(i)){let c=await e.formatCode(i,s);await e.writeFile(i,c),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function li(e){let t=e.typescriptEnabled,r=`
|
|
168
168
|
"use client"
|
|
169
169
|
import React, { useState } from "react";
|
|
170
170
|
import styles from "./styles.module.css";
|
|
@@ -227,13 +227,13 @@ export default Counter;
|
|
|
227
227
|
font-size: 42px;
|
|
228
228
|
text-align: center;
|
|
229
229
|
}
|
|
230
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
230
|
+
`.trimStart();return{component:r,styles:n}}async function ci(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await ie(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await ie(e,o.id,!0,!1,null,null,!0,!1)}async function kn(e){let t=await pi(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>An(t),ensureFigmaImportPage:()=>Fn(t),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:()=>_e(t),setPublicApiKey:n=>cn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function pi(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await ui(e),o=await Rt(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(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 l=e.join(r,"pages");await e.exists(l)&&(a.pagesDir=l),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 Rt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function ui(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 Je(e){return await ge(e,[".env"],_n)}async function jn(e,t){mi(t);let r=await Je(e),n=await xe(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function mi(e){typeof process<"u"&&(process.env[_n]=e)}var _n="PUBLIC_BUILDER_API_KEY";function Bn(e,t,r){if(r.length===0)return e;let n=e.split(`
|
|
231
231
|
`),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(`
|
|
232
|
-
`)}function Le(e,t,r){return Ne(e,t,r.variableName)?t:
|
|
232
|
+
`)}function Le(e,t,r){return Ne(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),l=e.ts.factory.createVariableStatement([s],a),c=[...t.statements,l];return e.ts.factory.updateSourceFile(t,c)}async function Vn(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(".")||xi.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await lt(e,o,s,i);r.push(...l)})),r}async function zn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return di(e,t,n)}return null}function di(e,t,r){let n=D(e,r);return lt(e,null,t,n)}async function lt(e,t,r,n){r=e.normalize(r);let o=[],i=Q(e,n);return await Promise.all(i.map(async a=>{let s=await gi(e,t,r,a);s&&o.push(s)})),o}async function gi(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=_(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=$n(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let l=a.name.text;return{cmpInfo:{id:await k(e,r,l),displayFilePath:F(e,r),name:j(l),inputs:[],exportName:n.isDefaultExport?"default":l,exportType:n.isDefaultExport?"default":"named",importName:l,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=$n(e,n.node);if(a)return{cmpInfo:{id:await k(e,r,"default"),displayFilePath:F(e,r),name:Y(e,r),inputs:[],exportName:"default",exportType:"default",importName:Ee(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function $n(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 xi=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function Kn(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 be(e,t.cmpInfo.filePath,null);if(!(await lt(e,i,t.cmpInfo.filePath,o)).find(l=>l.cmpInfo.id===t.cmpInfo.id))throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return ye(e,i,r)}return[]}async function Un(e){return At(e)}async function At(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,hi),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var hi=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
|
|
233
233
|
|
|
234
234
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
235
235
|
];
|
|
236
|
-
`;async function zn(e){await Rt(e);let t=await e.readFile(e.registryPath);return t?gi(e,t):{components:[],sourceFile:D(e,"")}}async function gi(e,t){let r=D(e,t);return xi(e,r)}async function xi(e,t){let r=[],n=q(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await At(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:M(r)}}async function At(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(A(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 Ie(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=_(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let l=await Bn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let c=l.find(d=>d.cmpInfo.exportName===a);c&&(n.exportName=c.cmpInfo.exportName)}continue}}return n=H(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function Kn(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),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await V(e,[...t])}async function ye(e,t,r,n,o,i,a,s){let l=await Kn(e),[c,d,m]=await Promise.all([_n(e,l),zn(e),qe(e)]),u=c.map(f=>f.cmpInfo),p=d.components,x={components:X(u,p),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(u),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return x;if(t!=null){let f=c.find(y=>y.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let g=d.sourceFile,h=x.components.find(y=>y.id===t),C=await Vn(e,f);G(h,C),t=Array.isArray(t)?t[0]:t;let T=oe(t,u,p,r,n,o,i),{elements:F,elmIndex:w,statementIndex:S,statement:P,variableDeclaration:O}=await Ci(e,g,f),v=!1;if(T.addCmpToRegistry?(F.push(hi(e,T.addCmpToRegistry)),v=!0):T.removeCmpFromRegistry?(F.splice(w,1),v=!0):T.updateRegisteredCmp&&(F[w]=U(e,F[w],T.updateRegisteredCmp),v=!0),v&&a){let y=[...g.statements];y[S]=e.ts.factory.updateVariableStatement(P,P.modifiers,e.ts.factory.updateVariableDeclarationList(P.declarationList,[e.ts.factory.updateVariableDeclaration(O,O.name,O.exclamationToken,O.type,e.ts.factory.createArrayLiteralExpression(Fe(e,F)))])),g=e.ts.factory.updateSourceFile(g,y),h.exportType==="named"?g=E(e,g,{namedImports:[h.importName],importPath:L(e,e.registryPath,h.filePath)}):g=E(e,g,{defaultImport:h.importName,importPath:L(e,e.registryPath,h.filePath)}),g=E(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=Le(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=re(e,g),g=ne(e,g);let b=N(e,g);b=J(b),b=kn(b,Si,"CUSTOM_COMPONENTS"),b=await e.formatCode(e.registryPath,b),await e.writeFile(e.registryPath,b)}x.components=T.components}return x}function hi(e,t){return U(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Ci(e,t,r){let n=q(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await At(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Si=["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 Un(e){let t=await Ti(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>$n(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>ye(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await ye(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>ye(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>ye(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>ye(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>ye(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>qe(t),setPublicApiKey:n=>Ln(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function Ti(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 Je(e){return await de(e,[".env"],We)}async function Mn(e,t){let r=await Je(e),n=await ge(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var We="PUBLIC_BUILDER_KEY";async function Qn(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"||yi.has(s)||s.includes("$."))return;let l=e.normalize(a.fileName);if(l===e.remixConfigPath||l===e.registryPath||l===i)return;let c=await xe(e,o,l,a);r.push(...c)})),r}var yi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function qn(e){await Lt(e);let t=await e.readFile(e.registryPath);return t?wi(e,t):{components:[],sourceFile:D(e,"")}}async function wi(e,t){let r=D(e,t);return Di(e,r)}async function Di(e,t){let r=[],n=q(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Ft(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:M(r)}}async function Ft(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(A(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let m=s.arguments[0];e.ts.isIdentifier(m)&&(a=m.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let l=await Ie(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=_(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let c=await Cn(e,l.filePath);if(c&&c.length>0)if(c.length===1)n.exportName=c[0].cmpInfo.exportName;else{let d=c.find(m=>m.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=H(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function ae(e,t,r,n,o,i,a,s){let l=await he(e),[c,d,m]=await Promise.all([Qn(e,l),qn(e),Je(e)]),u=c.map(C=>C.cmpInfo),p=d.components,x={components:X(u,p),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(u),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await Re(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(w=>{let S=c.find(P=>P.cmpInfo.id===w);if(!S)throw new Error(`Component ${w} not found`);return S}),T=Array.from(new Set(C.map(w=>w.cmpInfo.filePath))),F=await V(e,T);for(let w of C){let S=x.components.find(B=>B.id===w.cmpInfo.id),P=await Ae(e,w,F);G(S,P);let O=u.findIndex(B=>B.id===w.cmpInfo.id);u[O].inputs=P;let v=oe(w.cmpInfo.id,u,p,r,n,o,i),{elements:y,elmIndex:b,statementIndex:I,statement:$,variableDeclaration:le}=await Pi(e,g,w);if(v.addCmpToRegistry)y.push(Ei(e,v.addCmpToRegistry)),f=!0;else if(v.removeCmpFromRegistry)y.splice(b,1),f=!0;else if(v.updateRegisteredCmp){let B=U(e,y[b],v.updateRegisteredCmp);y[b]=e.ts.factory.updateObjectLiteralExpression(B,[Jn(e,v.updateRegisteredCmp),...B.properties.slice(1)]),f=!0}if(f&&a){let B=[...g.statements];B[I]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(le,le.name,le.exclamationToken,le.type,e.ts.factory.createArrayLiteralExpression(Fe(e,y)))])),g=e.ts.factory.updateSourceFile(g,B),S.exportType==="named"?g=E(e,g,{namedImports:[S.importName],importPath:L(e,e.registryPath,S.filePath)}):g=E(e,g,{defaultImport:S.importName,importPath:L(e,e.registryPath,S.filePath)}),g=E(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),S.acceptsChildren&&(g=E(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=Le(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=v.components,p=v.components.filter(xt=>xt.isRegistered)}}}if(f&&a){g=re(e,g),g=ne(e,g);let C=N(e,g);C=J(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function Jn(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 Ei(e,t){return U(e,e.ts.factory.createObjectLiteralExpression([Jn(e,t)],!0),t)}async function Pi(e,t,r){let n=q(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 Ft(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Wn(e){let t=[],r=await Ii(e,t);return t.push(...await Lt(e)),await Ri(e,r),await bi(e,t),t}async function Yn(e){let t=[];return await vi(e,t),t}async function vi(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,Hn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function bi(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,Hn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function Hn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=L(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${We}`;return e.getFrameworks().some(l=>l.name==="@shopify/remix-oxygen")&&(s=`context.env.${We}`),n&&(s+="!"),`
|
|
236
|
+
`;async function Mn(e){await At(e);let t=await e.readFile(e.registryPath);return t?Ci(e,t):{components:[],sourceFile:D(e,"")}}async function Ci(e,t){let r=D(e,t);return Si(e,r)}async function Si(e,t){let r=[],n=q(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Ft(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:M(r)}}async function Ft(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(I(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await Ie(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=_(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let l=await zn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let c=l.find(d=>d.cmpInfo.exportName===a);c&&(n.exportName=c.cmpInfo.exportName)}continue}}return n=H(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function Qn(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),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}async function we(e,t,r,n,o,i,a,s){let l=await Qn(e),[c,d,u]=await Promise.all([Vn(e,l),Mn(e),Je(e)]),m=c.map(f=>f.cmpInfo),p=d.components,x={components:X(m,p),registryPath:e.registryPath,registryDisplayPath:F(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x;if(t!=null){let f=c.find(y=>y.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let g=d.sourceFile,h=x.components.find(y=>y.id===t),C=await Kn(e,f);G(h,C),t=Array.isArray(t)?t[0]:t;let T=oe(t,m,p,r,n,o,i),{elements:L,elmIndex:w,statementIndex:S,statement:E,variableDeclaration:O}=await yi(e,g,f),N=!1;if(T.addCmpToRegistry?(L.push(Ti(e,T.addCmpToRegistry)),N=!0):T.removeCmpFromRegistry?(L.splice(w,1),N=!0):T.updateRegisteredCmp&&(L[w]=U(e,L[w],T.updateRegisteredCmp),N=!0),N&&a){let y=[...g.statements];y[S]=e.ts.factory.updateVariableStatement(E,E.modifiers,e.ts.factory.updateVariableDeclarationList(E.declarationList,[e.ts.factory.updateVariableDeclaration(O,O.name,O.exclamationToken,O.type,e.ts.factory.createArrayLiteralExpression(Fe(e,L)))])),g=e.ts.factory.updateSourceFile(g,y),h.exportType==="named"?g=P(e,g,{namedImports:[h.importName],importPath:b(e,e.registryPath,h.filePath)}):g=P(e,g,{defaultImport:h.importName,importPath:b(e,e.registryPath,h.filePath)}),g=P(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=Le(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=re(e,g),g=ne(e,g);let R=v(e,g);R=J(R),R=Bn(R,wi,"CUSTOM_COMPONENTS"),R=await e.formatCode(e.registryPath,R),await e.writeFile(e.registryPath,R)}x.components=T.components}return x}function Ti(e,t){return U(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function yi(e,t,r){let n=q(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 Ft(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var wi=["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 qn(e){let t=await Di(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>Un(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>we(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await we(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>we(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>we(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>we(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>we(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Je(t),setPublicApiKey:n=>jn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function Di(e){let t=await je(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 We(e){return await ge(e,[".env"],Ye)}async function Jn(e,t){let r=await We(e),n=await xe(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Ye="PUBLIC_BUILDER_KEY";async function Wn(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"||Pi.has(s)||s.includes("$."))return;let l=e.normalize(a.fileName);if(l===e.remixConfigPath||l===e.registryPath||l===i)return;let c=await he(e,o,l,a);r.push(...c)})),r}var Pi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Yn(e){await Ot(e);let t=await e.readFile(e.registryPath);return t?Ei(e,t):{components:[],sourceFile:D(e,"")}}async function Ei(e,t){let r=D(e,t);return vi(e,r)}async function vi(e,t){let r=[],n=q(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:M(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};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(I(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let u=s.arguments[0];e.ts.isIdentifier(u)&&(a=u.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let l=await Ie(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=_(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let c=await yn(e,l.filePath);if(c&&c.length>0)if(c.length===1)n.exportName=c[0].cmpInfo.exportName;else{let d=c.find(u=>u.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=H(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function ae(e,t,r,n,o,i,a,s){let l=await Ce(e),[c,d,u]=await Promise.all([Wn(e,l),Yn(e),We(e)]),m=c.map(C=>C.cmpInfo),p=d.components,x={components:X(m,p),registryPath:e.registryPath,registryDisplayPath:F(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await Re(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(w=>{let S=c.find(E=>E.cmpInfo.id===w);if(!S)throw new Error(`Component ${w} not found`);return S}),T=Array.from(new Set(C.map(w=>w.cmpInfo.filePath))),L=await $(e,T);for(let w of C){let S=x.components.find(B=>B.id===w.cmpInfo.id),E=await Ae(e,w,L);G(S,E);let O=m.findIndex(B=>B.id===w.cmpInfo.id);m[O].inputs=E;let N=oe(w.cmpInfo.id,m,p,r,n,o,i),{elements:y,elmIndex:R,statementIndex:A,statement:V,variableDeclaration:ce}=await Ii(e,g,w);if(N.addCmpToRegistry)y.push(bi(e,N.addCmpToRegistry)),f=!0;else if(N.removeCmpFromRegistry)y.splice(R,1),f=!0;else if(N.updateRegisteredCmp){let B=U(e,y[R],N.updateRegisteredCmp);y[R]=e.ts.factory.updateObjectLiteralExpression(B,[Hn(e,N.updateRegisteredCmp),...B.properties.slice(1)]),f=!0}if(f&&a){let B=[...g.statements];B[A]=e.ts.factory.updateVariableStatement(V,V.modifiers,e.ts.factory.updateVariableDeclarationList(V.declarationList,[e.ts.factory.updateVariableDeclaration(ce,ce.name,ce.exclamationToken,ce.type,e.ts.factory.createArrayLiteralExpression(Fe(e,y)))])),g=e.ts.factory.updateSourceFile(g,B),S.exportType==="named"?g=P(e,g,{namedImports:[S.importName],importPath:b(e,e.registryPath,S.filePath)}):g=P(e,g,{defaultImport:S.importName,importPath:b(e,e.registryPath,S.filePath)}),g=P(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),S.acceptsChildren&&(g=P(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=Le(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=N.components,p=N.components.filter(ht=>ht.isRegistered)}}}if(f&&a){g=re(e,g),g=ne(e,g);let C=v(e,g);C=J(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function Hn(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 bi(e,t){return U(e,e.ts.factory.createObjectLiteralExpression([Hn(e,t)],!0),t)}async function Ii(e,t,r){let n=q(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}}async function Gn(e){let t=[],r=await Ai(e,t);return t.push(...await Ot(e)),await Li(e,r),await Ri(e,t),t}async function Xn(e){let t=[];return await Ni(e,t),t}async function Ni(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,Zn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Ri(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,Zn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function Zn({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.${Ye}`;return e.getFrameworks().some(l=>l.name==="@shopify/remix-oxygen")&&(s=`context.env.${Ye}`),n&&(s+="!"),`
|
|
237
237
|
import { BuilderComponent, builder } from "@builder.io/react";
|
|
238
238
|
import { useLoaderData } from "@remix-run/react";
|
|
239
239
|
import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
|
|
@@ -290,11 +290,11 @@ export default function Page() {
|
|
|
290
290
|
${n?`
|
|
291
291
|
declare global {
|
|
292
292
|
interface Env {
|
|
293
|
-
${
|
|
293
|
+
${Ye}: string;
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
`:""}
|
|
297
|
-
`}async function
|
|
297
|
+
`}async function Ai(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:l}=Fi(e),c=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${c}`),!c){let u=await e.formatCode(i,s);await e.writeFile(i,u),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function Fi(e){let t=e.typescriptEnabled,r=`
|
|
298
298
|
import { useState } from "react";
|
|
299
299
|
import styles from "./styles.module.css";
|
|
300
300
|
${t?`
|
|
@@ -357,23 +357,23 @@ export default Counter;
|
|
|
357
357
|
font-size: 42px;
|
|
358
358
|
text-align: center;
|
|
359
359
|
}
|
|
360
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
360
|
+
`.trimStart();return{component:r,styles:n}}async function Li(e,t){let n=(await ae(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await ae(e,n.id,!0,!1,null,null,!0,!1)}async function Ot(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Oi(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function Oi(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/react";
|
|
361
361
|
|
|
362
362
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
363
363
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
364
364
|
];
|
|
365
|
-
`}async function
|
|
365
|
+
`}async function er(e){let t=await ki(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:()=>Gn(t),ensureFigmaImportPage:()=>Xn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>ae(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await ae(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>ae(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>ae(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>ae(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>ae(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>We(t),setPublicApiKey:n=>Jn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function ki(e){let t=await Bi(e),r=await $i(e),n=e.dirname(r),o=e.join(n,"components"),i=await ji(e),a=`builder-registry.${i?"ts":"js"}`,s=e.join(n,a);return{...e,registryPath:s,remixConfigPath:t,typescriptEnabled:i,appDir:n,componentsDir:o,routesDir:r,hasLocaleParam:await _i(e,r)}}function ji(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function _i(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Bi(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 $i(e){let t=await je(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 He(e){let t=[".env"],r=e.configType==="vite"?ct:kt;return await ge(e,t,r)}async function tr(e,t){let r=await He(e),n=await xe(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ct="VITE_PUBLIC_BUILDER_KEY",kt="YOUR_PUBLIC_BUILDER_KEY";function nr(e,t){let r=`Builder.registerComponent(
|
|
366
366
|
`;r+=` ${t.importName},
|
|
367
367
|
`,r+=` {
|
|
368
368
|
name: "${t.name}",
|
|
369
369
|
}
|
|
370
|
-
`,r+=");";let n=
|
|
370
|
+
`,r+=");";let n=rt(e,r);return jt(e,n,t)}function jt(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=U(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function or(e){let t=await e.readFile(e.registryPath);return t?Vi(e,t):{components:[],sourceFile:D(e,"")}}async function Vi(e,t){let r=D(e,t);return zi(e,r)}async function zi(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 c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let u=c[0];if(e.ts.isIdentifier(u)){let m=await Ki(e,t,n,u,d,!1);m&&r.push(m);continue}}return{sourceFile:t,components:M(r)}}async function Ki(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(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await rr(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(u=>!u.importClause||!u.importClause.namedBindings||!e.ts.isNamedImports(u.importClause.namedBindings)?!1:u.importClause.namedBindings.elements.some(m=>m.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await rr(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=H(e,a,o),a.displayFilePath=F(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function rr(e,t){return Me(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function se(e,t,r,n,o,i,a,s){let l=await Ce(e),[c,d,u,m]=await Promise.all([wn(e,l),or(e),_t(e),He(e)]),p=c.map(T=>T.cmpInfo),x=d.components,f={components:X(p,x),registryPath:e.registryPath,registryDisplayPath:F(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(p),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Re(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let T=C.map(S=>{let E=c.find(O=>O.cmpInfo.id===S);if(!E)throw new Error(`Component ${S} not found`);return E}),L=Array.from(new Set(T.map(S=>S.cmpInfo.filePath))),w=await $(e,L);for(let S of T){let E=f.components.find(A=>A.id===S.cmpInfo.id),O=await Ae(e,S,w);G(E,O);let N=p.findIndex(A=>A.id===S.cmpInfo.id);p[N].inputs=O;let y=oe(S.cmpInfo.id,p,x,r,n,o,i),R=[...h.statements];if(y.addCmpToRegistry?(R.push(nr(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(R.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(R[y.nodeIndex]=jt(e,R[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a){h=e.ts.factory.updateSourceFile(h,R),h=P(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"});let A=y.addCmpToRegistry||y.updateRegisteredCmp;if(A){let V=b(e,e.registryPath,A.filePath);A.exportType==="default"?h=P(e,h,{defaultImport:A.importName,importPath:V}):A.exportType==="named"&&(h=P(e,h,{namedImports:[A.importName],importPath:V}))}E?.acceptsChildren&&(h=P(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=y.components,x=y.components.filter(V=>V.isRegistered)}}}if(g&&a){h=re(e,h),h=ne(e,h);let T=v(e,h);T=J(T),T=await e.formatCode(e.registryPath,T),await e.writeFile(e.registryPath,T)}return f}async function ir(e){let t=[],r=await Qi(e,t);if(await Mi(e,r,t),!await e.exists(e.builderComponentPath)){let n=await e.formatCode(e.builderComponentPath,Ui(e));await e.writeFile(e.builderComponentPath,n),t.push({filePath:e.builderComponentPath,modifiedType:"create"})}return t}async function ar(e){return[]}function Ui(e){let t=e.typescriptEnabled;return`
|
|
371
371
|
import React from "react";
|
|
372
372
|
import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
|
|
373
|
-
import ${JSON.stringify(
|
|
373
|
+
import ${JSON.stringify(b(e,e.builderComponentPath,e.registryPath))};
|
|
374
374
|
|
|
375
375
|
// Builder Public API Key set in .env file
|
|
376
|
-
${e.configType==="vite"?`builder.init(import.meta.env.${
|
|
376
|
+
${e.configType==="vite"?`builder.init(import.meta.env.${ct}${t?"!":""})`:`builder.init("${kt}")`}
|
|
377
377
|
|
|
378
378
|
export default function BuilderPage() {
|
|
379
379
|
const isPreviewingInBuilder = useIsPreviewing();
|
|
@@ -418,7 +418,7 @@ export default function BuilderPage() {
|
|
|
418
418
|
</>
|
|
419
419
|
);
|
|
420
420
|
}
|
|
421
|
-
`.trimStart()}async function
|
|
421
|
+
`.trimStart()}async function Mi(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await se(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await se(e,o.id,!0,!1,null,null,!0,!1)}async function Qi(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:l}=qi(e);if(!await e.exists(i)){let c=await e.formatCode(i,s);await e.writeFile(i,c),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function qi(e){let t=e.typescriptEnabled,r=`
|
|
422
422
|
"use client"
|
|
423
423
|
import React, { useState } from "react";
|
|
424
424
|
import styles from "./styles.module.css";
|
|
@@ -481,28 +481,159 @@ export default Counter;
|
|
|
481
481
|
font-size: 42px;
|
|
482
482
|
text-align: center;
|
|
483
483
|
}
|
|
484
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
484
|
+
`.trimStart();return{component:r,styles:n}}async function sr(e){let t=await Ji(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>ir(t),ensureFigmaImportPage:()=>ar(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>se(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await se(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>se(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>se(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>se(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>se(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>He(t),setPublicApiKey:n=>tr(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function Ji(e){let t=await Wi(e),r=e.getRootDir(),n=e.join(r,"src"),o=await _t(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,configType:""};return 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 _t(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Wi(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}throw new Error(`Could not find React config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}async function Ge(e){return await Yi(e,["environment.ts"],Oe)}async function lr(e,t){let r=await Ge(e),n=await Zi(e,r.file,r.envKey,t);return{...r,modifiedType:n}}async function Yi(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 Hi(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 Hi(e,t){let r=await e.readFile(t);return r?Gi(e,r):""}function Gi(e,t){let r=D(e,t),n="",i=Ne(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(l=>{e.ts.isPropertyAssignment(l)&&e.ts.isIdentifier(l.name)&&l.name.text===Oe&&e.ts.isStringLiteral(l.initializer)&&(n=l.initializer.text)})}return n}async function Xi(e,t,r,n){let o=D(e,t),a=Ne(e,o,"environment");if(a&&a.statement.declarationList.declarations.length>0){let s=a.statement.declarationList,l=s.declarations[0],c=l.initializer;if(c&&e.ts.isObjectLiteralExpression(c)){let d=e.ts.factory.createPropertyAssignment(e.ts.factory.createIdentifier(r),e.ts.factory.createStringLiteral(n)),u=e.ts.factory.createNodeArray([...c.properties,d]),m=e.ts.factory.updateObjectLiteralExpression(c,u),p=e.ts.factory.updateVariableDeclaration(l,l.name,l.exclamationToken,l.type,m),x=e.ts.factory.updateVariableDeclarationList(s,[p]);return e.ts.factory.updateVariableStatement(a.statement,a.statement.modifiers,x)}return null}return null}async function Zi(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 Xi(e,o,r,n);if(i){let a=v(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=`
|
|
485
485
|
// https://www.builder.io/c/docs/using-your-api-key
|
|
486
486
|
export const environment = {
|
|
487
487
|
production: false,
|
|
488
488
|
builderApiKey: "${n}",
|
|
489
489
|
};
|
|
490
|
-
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var
|
|
490
|
+
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var Oe="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(na(e,i.fileName)||a.startsWith(".")||a==="node_modules"||ea.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await pt(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var ea=new Set([]),ta=new Set(["node_modules"]);function na(e,t){for(let r of ta)if(e.dirname(t).includes(r))return!0;return!1}async function pr(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return ra(e,t,n)}return null}function ra(e,t,r){let n=D(e,r);return pt(e,null,t,n)}async function pt(e,t,r,n){let o=[];r=e.normalize(r);let i=n.statements.filter(s=>e.ts.isClassDeclaration(s)&&aa(e,s)),a=la(e,n);return await Promise.all(i.map(async s=>{let l=await oa(e,t,r,s,a);o.push(...l)})),o}async function ur(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await be(e,t.cmpInfo.filePath,r),a=(await pt(e,o,t.cmpInfo.filePath,n)).find(s=>s.cmpInfo.id===t.cmpInfo.id);if(!a)throw new Error(`Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return a.cmpInfo.inputs}return[]}async function mr(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=>{if(!a.isRegistered){let s=n.getSourceFile(a.filePath);if(s){let c=(await pt(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);c&&(a.inputs=ye(e,o,c.node.fnNode))}}return a}))}async function oa(e,t,r,n,o){let i=[],a=e.relative(e.getRootDir(),r),s=_(e,r),l=n.name?.text;if(!l)return i;let c=!1;n.modifiers&&(c=n.modifiers.some(p=>p.kind===e.ts.SyntaxKind.DefaultKeyword));let d=c?"default":l,u=c?"default":"named",m=[];return n.members.forEach(p=>{if(e.ts.isPropertyDeclaration(p)){let x=e.ts.getDecorators(p);x&&x.forEach(f=>{if(ia(e,f)&&e.ts.isIdentifier(p.name)){let g="any";if(p.type&&t){let C=t.getTypeAtLocation(p.type);g=t.typeToString(C)}else g=sa(e,p.type);let h={name:p.name.text,type:o[g]?"string":g};o[g]&&(h.enum=o[g]),m.push(h)}})}}),i.push({cmpInfo:{id:await k(e,r,l),displayFilePath:F(e,r),name:j(l),inputs:m,exportName:d,exportType:u,importName:l,filePath:r,relFilePath:a,importPath:s},node:{name:l,fnNode:n,deps:void 0}}),i}function ia(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 aa(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 sa(e,t){if(!t)return"any";let r="any";switch(t.kind){case e.ts.SyntaxKind.StringKeyword:r="string";break;case e.ts.SyntaxKind.NumberKeyword:r="number";break;case e.ts.SyntaxKind.BooleanKeyword:r="boolean";break;case e.ts.SyntaxKind.TypeReference:e.ts.isTypeReferenceNode(t);break}return r.includes("|")?"string":r}function la(e,t){let r={};return e.ts.forEachChild(t,n=>{e.ts.isTypeAliasDeclaration(n)&&e.ts.isUnionTypeNode(n.type)&&n.type.types.every(o=>e.ts.isLiteralTypeNode(o)&&e.ts.isStringLiteral(o.literal))&&(r[n.name.text]=n.type.types.map(o=>o.literal.text))}),r}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 ca(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 ca(e,t,r){let o=e.typescriptEnabled?"ts":"js",i=r,a=D(e,r),s=b(e,t,e.builderPageComponentPath),l=e.join(e.componentsDir,`counter.component.${o}`);a=P(e,a,{namedImports:["BuilderPage"],importPath:s});let c=b(e,t,l);a=P(e,a,{namedImports:["Counter"],importPath:c}),a=P(e,a,{namedImports:["Content"],importPath:"@builder.io/sdk-angular"});let d=[];for(let u of a.statements)if(e.ts.isClassDeclaration(u)&&u.name?.text==="AppModule"){let m=pa(e,u);d.push(m)}else d.push(u);return a=e.ts.factory.updateSourceFile(a,d),i=v(e,a),i}function pa(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=Bt(e,o[0],"declarations","BuilderPage");if(i&&(i=Bt(e,i,"declarations","Counter"),i&&(i=Bt(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])),l=[...r.map(c=>c===n?a:c),...e.ts.getModifiers(t)||[]];return e.ts.factory.updateClassDeclaration(t,l,t.name,t.typeParameters,t.heritageClauses,t.members)}}}}return t}function Bt(e,t,r,n){let o=[...t.properties],i=o.findIndex(s=>I(e,s)===r);if(i>-1){let s=o[i];if(e.ts.isPropertyAssignment(s)&&s.initializer&&e.ts.isArrayLiteralExpression(s.initializer)){let l=fr(e,s.initializer,n);if(l)return o[i]=e.ts.factory.updatePropertyAssignment(s,s.name,l),e.ts.factory.updateObjectLiteralExpression(t,o)}return null}let a=fr(e,e.ts.factory.createArrayLiteralExpression([],!0),n);return a?e.ts.factory.updateObjectLiteralExpression(t,[...o,e.ts.factory.createPropertyAssignment(r,a)]):null}function fr(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 gr(e){let t=[],r=await da(e,t);if(t.push(...await $t(e)),await ua(e,r),!await e.exists(e.builderPageComponentPath)){let o=await e.formatCode(e.builderPageComponentPath,ma(e));await e.writeFile(e.builderPageComponentPath,o),t.push({filePath:e.builderPageComponentPath,modifiedType:"create"})}let n=await dr(e);return n&&t.push({filePath:n,modifiedType:"update"}),t}async function $t(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,fa(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}async function xr(e){return[]}async function ua(e,t){let n=(await le(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await le(e,n.id,!0,!1,null,null,!0,!1)}function ma(e){let t=b(e,e.builderPageComponentPath,e.registryPath),r=e.join(e.getRootDir(),"src","environments","environment.ts"),n=b(e,e.builderPageComponentPath,r);return`
|
|
491
|
+
import { Component, ChangeDetectorRef } from '@angular/core';
|
|
492
|
+
import { _processContentResult, fetchOneEntry } from '@builder.io/sdk-angular';
|
|
493
|
+
import { environment } from ${JSON.stringify(n)};
|
|
494
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(t)};
|
|
495
|
+
|
|
496
|
+
${e.typescriptEnabled?`
|
|
497
|
+
interface BuilderProps {
|
|
498
|
+
apiVersion: string;
|
|
499
|
+
canTrack?: boolean;
|
|
500
|
+
trustedHosts?: undefined;
|
|
501
|
+
apiKey: string;
|
|
502
|
+
model: string;
|
|
503
|
+
content: any;
|
|
504
|
+
}`:""}
|
|
505
|
+
|
|
506
|
+
@Component({
|
|
507
|
+
selector: 'app-builder-page',
|
|
508
|
+
template: \`
|
|
509
|
+
<content-variants
|
|
510
|
+
[model]="model"
|
|
511
|
+
[content]="content"
|
|
512
|
+
[apiKey]="apiKey"
|
|
513
|
+
[customComponents]="customComponents"
|
|
514
|
+
></content-variants>
|
|
515
|
+
\`,
|
|
516
|
+
})
|
|
517
|
+
export class BuilderPage {
|
|
518
|
+
title = 'builder page';
|
|
519
|
+
${e.typescriptEnabled?`
|
|
520
|
+
apiKey: BuilderProps['apiKey'] = environment.${Oe};
|
|
521
|
+
model: BuilderProps['model'] = 'page';
|
|
522
|
+
content: BuilderProps['content'];
|
|
523
|
+
`:`
|
|
524
|
+
apiKey = environment.${Oe};
|
|
525
|
+
model = 'page';
|
|
526
|
+
content = null;
|
|
527
|
+
`}
|
|
528
|
+
|
|
529
|
+
customComponents = CUSTOM_COMPONENTS;
|
|
530
|
+
|
|
531
|
+
constructor(private cdr: ChangeDetectorRef) {}
|
|
532
|
+
|
|
533
|
+
async ngOnInit() {
|
|
534
|
+
const urlPath = window.location.pathname || '/';
|
|
535
|
+
|
|
536
|
+
const builderContent = await fetchOneEntry({
|
|
537
|
+
model: 'page',
|
|
538
|
+
apiKey: environment.${Oe},
|
|
539
|
+
userAttributes: {
|
|
540
|
+
urlPath,
|
|
541
|
+
},
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
if (!builderContent) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
this.content = builderContent;
|
|
549
|
+
|
|
550
|
+
this.cdr.detectChanges();
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
`.trimStart()}function fa(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-angular";
|
|
491
555
|
|
|
492
556
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
493
557
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
494
558
|
];
|
|
495
|
-
`}async function dr(e){await ur(e);let t=await e.readFile(e.registryPath);return t?sa(e,t):{components:[],sourceFile:D(e,"")}}async function sa(e,t){let r=D(e,t);return la(e,r)}async function la(e,t){let r=[],n=q(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:M(r)}}async function _t(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(A(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 l=await Ie(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=_(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let c=await lr(e,l.filePath);if(c&&c.length>0)if(c.length===1)n.exportName=c[0].cmpInfo.exportName;else{let d=c.find(m=>m.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=H(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function we(e,t,r,n,o,i,a,s){let l=await he(e),[c,d,m]=await Promise.all([sr(e,l),dr(e),He(e)]),u=c.map(C=>C.cmpInfo),p=d.components,x={components:X(u,p),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(u),publicApiKey:m.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await pr(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(w=>{let S=c.find(P=>P.cmpInfo.id===w);if(!S)throw new Error(`Component ${w} not found`);return S}),T=Array.from(new Set(C.map(w=>w.cmpInfo.filePath))),F=await V(e,T);for(let w of C){let S=x.components.find(B=>B.id===w.cmpInfo.id),P=await cr(e,w,F);G(S,P);let O=u.findIndex(B=>B.id===w.cmpInfo.id);u[O].inputs=P;let v=oe(w.cmpInfo.id,u,p,r,n,o,i),{elements:y,elmIndex:b,statementIndex:I,statement:$,variableDeclaration:le}=await pa(e,g,w);if(v.addCmpToRegistry)y.push(ca(e,v.addCmpToRegistry)),f=!0;else if(v.removeCmpFromRegistry)y.splice(b,1),f=!0;else if(v.updateRegisteredCmp){let B=U(e,y[b],v.updateRegisteredCmp);y[b]=e.ts.factory.updateObjectLiteralExpression(B,[gr(e,v.updateRegisteredCmp),...B.properties.slice(1)]),f=!0}if(f&&a){let B=[...g.statements];B[I]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(le,le.name,le.exclamationToken,le.type,e.ts.factory.createArrayLiteralExpression(Fe(e,y)))])),g=e.ts.factory.updateSourceFile(g,B),S.exportType==="named"?g=E(e,g,{namedImports:[S.importName],importPath:L(e,e.registryPath,S.filePath)}):g=E(e,g,{defaultImport:S.importName,importPath:L(e,e.registryPath,S.filePath)}),g=E(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=Le(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=v.components,p=v.components.filter(xt=>xt.isRegistered)}}}if(f&&a){g=re(e,g),g=ne(e,g);let C=N(e,g);C=J(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function gr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function ca(e,t){return U(e,e.ts.factory.createObjectLiteralExpression([gr(e,t)],!0),t)}async function pa(e,t,r){let n=q(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 xr(e){let t=await ua(e);return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>mr(t),ensureFigmaImportPage:()=>fr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>we(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await we(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>we(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>we(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>we(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>we(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>He(t),setPublicApiKey:n=>ir(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function ua(e){let t=await fa(e),r=e.getRootDir(),n=e.join(r,"src"),o=await ma(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:"",angularConfigPath:t,typescriptEnabled:o};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);return a.srcDir=n,a.appDir=e.join(n,"app"),a.componentsDir=e.join(n,"components"),a.registryPath=e.join(a.appDir,i),a}function ma(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function fa(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 gt=ro(Nr(),1);async function Rr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:W(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:K(i.inputs)};return K(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,gt.compress)(n);return btoa(JSON.stringify(o))}async function Ar(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,gt.decompress)(o),a=K(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let l=W(e.normalize(s.filePath)),c=n.components.find(m=>W(m.filePath).endsWith(l)&&m.exportName===s.exportName);if(!c){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${c.id})`,c.filePath),await t.registerComponent({cmpId:c.id});for(let m of s.inputs)e.debug(`set input (${c.id})`),await t.setRegisteredComponentInput({cmpId:c.id,name:m.name,type:m.type,required:m.required,defaultValue:m.defaultValue,friendlyName:m.friendlyName,helperText:m.helperText});e.debug(`set input (${c.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:c.id,name:s.name,image:s.image,description:s.description});a=K(d)}return a}var _a={"@builder.io/qwik-city":Un,next:Fn,"@remix-run/react":Gn,react:or,"@angular/core":xr};async function Fr(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 fe(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=_a[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Rr(e,n),importRegistry:i=>Ar(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Lr(e){function t(m){if(typeof m!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(m))}function r(m,u){let p="",x=0,f=-1,g=0,h;for(let C=0;C<=m.length;++C){if(C<m.length)h=m.charCodeAt(C);else{if(h===47)break;h=47}if(h===47){if(!(f===C-1||g===1))if(f!==C-1&&g===2){if(p.length<2||x!==2||p.charCodeAt(p.length-1)!==46||p.charCodeAt(p.length-2)!==46){if(p.length>2){let T=p.lastIndexOf("/");if(T!==p.length-1){T===-1?(p="",x=0):(p=p.slice(0,T),x=p.length-1-p.lastIndexOf("/")),f=C,g=0;continue}}else if(p.length===2||p.length===1){p="",x=0,f=C,g=0;continue}}u&&(p.length>0?p+="/..":p="..",x=2)}else p.length>0?p+="/"+m.slice(f+1,C):p=m.slice(f+1,C),x=C-f-1;f=C,g=0}else h===46&&g!==-1?++g:g=-1}return p}let n=function(...u){let p="",x=!1;for(let f=u.length-1;f>=-1&&!x;f--){let g;f>=0?g=u[f]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(p=g+"/"+p,x=g.charCodeAt(0)===47)}return p=r(p,!x),x?p.length>0?"/"+p:"/":p.length>0?p:"."},o=function(u){if(t(u),u.length===0)return".";let p=u.charCodeAt(0)===47,x=u.charCodeAt(u.length-1)===47;return u=r(u,!p),u.length===0&&!p&&(u="."),u.length>0&&x&&(u+="/"),p?"/"+u:u};return{relative:function(u,p){if(t(u),t(p),u===p||(u=n(u),p=n(p),u===p))return"";let x=1;for(;x<u.length&&u.charCodeAt(x)===47;++x);let f=u.length,g=f-x,h=1;for(;h<p.length&&p.charCodeAt(h)===47;++h);let T=p.length-h,F=g<T?g:T,w=-1,S=0;for(;S<=F;++S){if(S===F){if(T>F){if(p.charCodeAt(h+S)===47)return p.slice(h+S+1);if(S===0)return p.slice(h+S)}else g>F&&(u.charCodeAt(x+S)===47?w=S:S===0&&(w=0));break}let O=u.charCodeAt(x+S),v=p.charCodeAt(h+S);if(O!==v)break;O===47&&(w=S)}let P="";for(S=x+w+1;S<=f;++S)(S===f||u.charCodeAt(S)===47)&&(P.length===0?P+="..":P+="/..");return P.length>0?P+p.slice(h+w):(h+=w,p.charCodeAt(h)===47&&++h,p.slice(h))},resolve:n,join:function(...u){if(u.length===0)return".";let p;for(let x=0;x<u.length;++x){let f=u[x];t(f),f.length>0&&(p===void 0?p=f:p+="/"+f)}return p===void 0?".":o(p)},isAbsolute:function(u){return t(u),u.length>0&&u.charCodeAt(0)===47},basename:function(u,p){if(p!==void 0&&typeof p!="string")throw new TypeError('"ext" argument must be a string');t(u);let x=0,f=-1,g=!0,h;if(p!==void 0&&p.length>0&&p.length<=u.length){if(p.length===u.length&&p===u)return"";let C=p.length-1,T=-1;for(h=u.length-1;h>=0;--h){let F=u.charCodeAt(h);if(F===47){if(!g){x=h+1;break}}else T===-1&&(g=!1,T=h+1),C>=0&&(F===p.charCodeAt(C)?--C===-1&&(f=h):(C=-1,f=T))}return x===f?f=T:f===-1&&(f=u.length),u.slice(x,f)}else{for(h=u.length-1;h>=0;--h)if(u.charCodeAt(h)===47){if(!g){x=h+1;break}}else f===-1&&(g=!1,f=h+1);return f===-1?"":u.slice(x,f)}},normalize:o,dirname:function(u){if(t(u),u.length===0)return".";let p=u.charCodeAt(0),x=p===47,f=-1,g=!0;for(let h=u.length-1;h>=1;--h)if(p=u.charCodeAt(h),p===47){if(!g){f=h;break}}else g=!1;return f===-1?x?"/":".":x&&f===1?"//":u.slice(0,f)},extname:function(u){t(u);let p=-1,x=0,f=-1,g=!0,h=0;for(let C=u.length-1;C>=0;--C){let T=u.charCodeAt(C);if(T===47){if(!g){x=C+1;break}continue}f===-1&&(g=!1,f=C+1),T===46?p===-1?p=C:h!==1&&(h=1):p!==-1&&(h=-1)}return p===-1||f===-1||h===0||h===1&&p===f-1&&p===x+1?"":u.slice(p,f)}}}async function Or(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Lr({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[g]of o)if((g+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),l=f=>{f=i(f);let g=f===t()?f:f+"/",h=g.split("/").length-1,C=[];for(let[T]of o)if(T.split("/").slice(0,h).join("/")+"/"===g){let S=T.split("/")[h];S&&!C.includes(S)&&C.push(S)}return C.sort()},c=f=>{f=i(f);let g=o.get(f);return typeof g=="string"?g:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),m=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),T=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(T)).map(F=>F.toString(16).padStart(2,"0")).join("")}let g=0;for(let h=0;h<f.length;h++){let C=f.charCodeAt(h);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},u=new Set,p={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>l(f),readdirSync:l,readFile:async f=>c(f),readFileSync:c,stat:async f=>d(f),statSync:d,writeFile:async(f,g)=>{f=i(f),o.set(f,g);let h={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of u)await C(h)},hash:m,getDeviceId:async()=>typeof navigator<"u"?m(navigator.userAgent):"",formatCode:async(f,g)=>g,on:(f,g)=>{f==="change"&&u.add(g)},off:(f,g)=>{f==="change"&&u.delete(g)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0"},x=await fe(p);return p.getFrameworks=e.getFrameworks?e.getFrameworks:()=>x,p}async function kr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(jr(e,n))return o;let a=Q(e,n,"cjs"),s=Q(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let m=d.statement;if(!e.ts.isVariableStatement(m))throw new Error(`Expected an export assignment from ${t}`);let u=d.statement;if(e.ts.isVariableStatement(u)){let p=[...u.declarationList.declarations];if(p.length!==1)throw new Error("Expected a single variable declaration");let x=p[0];if(!x.initializer)throw new Error("Expected an initializer on the declaration");let f=x.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let g="BuilderDevTools()",h=[...n.statements],C=h.indexOf(u);return h[C]=e.ts.factory.updateVariableStatement(u,u.modifiers,e.ts.factory.updateVariableDeclarationList(u.declarationList,[e.ts.factory.updateVariableDeclaration(x,x.name,x.exclamationToken,x.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,h),n=E(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 l=a[0];if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let m=d.expression;if(!e.ts.isBinaryExpression(m))throw new Error("Expected a binary expression for the default export");let u=Gt(e,n);n=u.sourceFile;let p=[...n.statements],x=p.indexOf(d);return p[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(m,m.left,m.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[m.right]))),n=e.ts.factory.updateSourceFile(n,p),o.content=N(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let m=d[0];if(!m.initializer)throw new Error("Expected an initializer on the declaration");let u=m.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let p=Gt(e,n);n=p.sourceFile;let x=[...n.statements],f=x.indexOf(c);return x[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(m,m.name,m.exclamationToken,m.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(l.node)){let d=l.node,m=l.statement;if(!e.ts.isExpressionStatement(m))throw new Error("Expected an expression statement for the default export");let u=m.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let x=l.node.body;if(!e.ts.isBlock(x))throw new Error("Expected a block body on the next config function");let f=[...x.statements],g=f.findIndex(w=>e.ts.isReturnStatement(w));if(g===-1)throw new Error("Expected a return statement on the next config function");let h=f[g],C=Gt(e,n);n=C.sourceFile,f[g]=e.ts.factory.updateReturnStatement(h,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[h.expression]));let T=[...n.statements],F=T.indexOf(m);return T[F]=e.ts.factory.updateExpressionStatement(m,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(x,f)))),n=e.ts.factory.updateSourceFile(n,T),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function jr(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 Gt(e,t){let r=jr(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 Vr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if($r(e,n))return o;let a=Q(e,n,"cjs"),s=Q(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let l=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let m=d.statement;if(!e.ts.isExportAssignment(m))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(m.expression)){let u="builderDevTools()",p=Ba(e,m.expression);if(!p)return o;let x=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u),void 0,[p]),f=[...n.statements],g=f.indexOf(m);return f[g]=e.ts.factory.updateExportAssignment(m,m.modifiers,x),n=e.ts.factory.updateSourceFile(n,f),n=E(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=N(e,n),o.hasContentUpdates=!0,o}}if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let m=d.expression;if(!e.ts.isBinaryExpression(m))throw new Error("Expected a binary expression for the default export");let u=_r(e,n);n=u.sourceFile;let p=[...n.statements],x=p.indexOf(d);return p[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(m,m.left,m.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[m.right]))),n=e.ts.factory.updateSourceFile(n,p),o.content=N(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let m=d[0];if(!m.initializer)throw new Error("Expected an initializer on the declaration");let u=m.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let p=_r(e,n);n=p.sourceFile;let x=[...n.statements],f=x.indexOf(c);return x[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(m,m.name,m.exclamationToken,m.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,x),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 $r(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 _r(e,t){let r=$r(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 Ba(e,t){let r=[...t.properties],n=r.findIndex(i=>A(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Br(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=Br(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Br(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 Kr(e,t,r){let n=D(e,r),o=Q(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 l=[...i.node.arguments];if(l.length===0)throw new Error("Expected an argument in defineConfig()");let c=l[0];if(e.ts.isArrowFunction(c)){let d=Va(e,c);if(!d)return s;l[0]=e.ts.factory.updateArrowFunction(c,c.modifiers,c.typeParameters,c.parameters,c.type,c.equalsGreaterThanToken,d);let m=[...n.statements],u=m.indexOf(a);return m[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,l)),n=e.ts.factory.updateSourceFile(n,m),n=E(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=N(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(c)){let d=Xt(e,c);if(!d)return s;let m=[...n.statements],u=m.indexOf(a);return m[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,m),n=E(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 l=Xt(e,a.expression);if(!l)return s;let c=[...n.statements],d=c.indexOf(a);return c[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,l),n=e.ts.factory.updateSourceFile(n,c),n=E(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 Va(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=Xt(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function Xt(e,t){if(Ka(e)){let i=$a(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>A(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 $a(e,t){let r=[...t.properties],n=r.findIndex(i=>A(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=za(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=Zt(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 za(e,t){let r=[...t.properties],n=r.findIndex(i=>A(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Zt(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=Zt(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function Zt(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 Ka(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function Ur(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 Qr(e,t,r){e.debug("Angular config updates are currently in progress...");try{await Qa(e)}catch{console.error("Unable to update package.json.")}return await Ua(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Ua(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 Ma(e,o);await e.writeFile(n,i)}async function Ma(e,t){let r=t,n=D(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=`
|
|
559
|
+
`}async function da(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=ga();if(!i){let s=await e.formatCode(o,a);await e.writeFile(o,s),t.push({filePath:o,modifiedType:"create"})}return o}function ga(){return`
|
|
560
|
+
import { Component, Input } from '@angular/core';
|
|
561
|
+
|
|
562
|
+
@Component({
|
|
563
|
+
selector: 'app-counter',
|
|
564
|
+
template: \`
|
|
565
|
+
<div class="counter">
|
|
566
|
+
<button class="btn" (click)="decrement()">-</button>
|
|
567
|
+
<span class="count">{{ count }}</span>
|
|
568
|
+
<button class="btn" (click)="increment()">+</button>
|
|
569
|
+
</div>
|
|
570
|
+
\`,
|
|
571
|
+
styles: [
|
|
572
|
+
\`
|
|
573
|
+
.counter {
|
|
574
|
+
margin: 32px auto;
|
|
575
|
+
display: flex;
|
|
576
|
+
width: 100%;
|
|
577
|
+
max-width: 190px;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
.btn {
|
|
581
|
+
width: 42px;
|
|
582
|
+
font-size: 32px;
|
|
583
|
+
font-weight: bold;
|
|
584
|
+
background-color: #1c6bd1;
|
|
585
|
+
color: white;
|
|
586
|
+
border: none;
|
|
587
|
+
border-radius: 4px;
|
|
588
|
+
cursor: pointer;
|
|
589
|
+
line-height: 1.4;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
.btn:hover {
|
|
593
|
+
opacity: 0.8;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
.count {
|
|
597
|
+
flex: 1;
|
|
598
|
+
font-size: 42px;
|
|
599
|
+
text-align: center;
|
|
600
|
+
margin: 0 8px;
|
|
601
|
+
}
|
|
602
|
+
\`,
|
|
603
|
+
],
|
|
604
|
+
})
|
|
605
|
+
export class Counter {
|
|
606
|
+
@Input() initialCount: number = 99;
|
|
607
|
+
count: number;
|
|
608
|
+
|
|
609
|
+
constructor() {
|
|
610
|
+
this.count = this.initialCount;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
ngOnInit(): void {
|
|
614
|
+
this.count = this.initialCount;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
increment(): void {
|
|
618
|
+
this.count += 1;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
decrement(): void {
|
|
622
|
+
this.count -= 1;
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
`.trimStart()}async function hr(e){await $t(e);let t=await e.readFile(e.registryPath);return t?xa(e,t):{components:[],sourceFile:D(e,"")}}async function xa(e,t){let r=D(e,t);return ha(e,r)}async function ha(e,t){let r=[],n=q(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:M(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(I(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 l=await Ie(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=_(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let c=await pr(e,l.filePath);if(c&&c.length>0)if(c.length===1)n.exportName=c[0].cmpInfo.exportName;else{let d=c.find(u=>u.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=H(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function le(e,t,r,n,o,i,a,s){let l=await Ce(e),[c,d,u]=await Promise.all([cr(e,l),hr(e),Ge(e)]),m=c.map(C=>C.cmpInfo),p=d.components,x={components:X(m,p),registryPath:e.registryPath,registryDisplayPath:F(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:te(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await mr(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(w=>{let S=c.find(E=>E.cmpInfo.id===w);if(!S)throw new Error(`Component ${w} not found`);return S}),T=Array.from(new Set(C.map(w=>w.cmpInfo.filePath))),L=await $(e,T);for(let w of C){let S=x.components.find(B=>B.id===w.cmpInfo.id),E=await ur(e,w,L);G(S,E);let O=m.findIndex(B=>B.id===w.cmpInfo.id);m[O].inputs=E;let N=oe(w.cmpInfo.id,m,p,r,n,o,i),{elements:y,elmIndex:R,statementIndex:A,statement:V,variableDeclaration:ce}=await Sa(e,g,w);if(N.addCmpToRegistry)y.push(Ca(e,N.addCmpToRegistry)),f=!0;else if(N.removeCmpFromRegistry)y.splice(R,1),f=!0;else if(N.updateRegisteredCmp){let B=U(e,y[R],N.updateRegisteredCmp);y[R]=e.ts.factory.updateObjectLiteralExpression(B,[Cr(e,N.updateRegisteredCmp),...B.properties.slice(1)]),f=!0}if(f&&a){let B=[...g.statements];B[A]=e.ts.factory.updateVariableStatement(V,V.modifiers,e.ts.factory.updateVariableDeclarationList(V.declarationList,[e.ts.factory.updateVariableDeclaration(ce,ce.name,ce.exclamationToken,ce.type,e.ts.factory.createArrayLiteralExpression(Fe(e,y)))])),g=e.ts.factory.updateSourceFile(g,B),S.exportType==="named"?g=P(e,g,{namedImports:[S.importName],importPath:b(e,e.registryPath,S.filePath)}):g=P(e,g,{defaultImport:S.importName,importPath:b(e,e.registryPath,S.filePath)}),g=P(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=Le(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=N.components,p=N.components.filter(ht=>ht.isRegistered)}}}if(f&&a){g=re(e,g),g=ne(e,g);let C=v(e,g);C=J(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function Cr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Ca(e,t){return U(e,e.ts.factory.createObjectLiteralExpression([Cr(e,t)],!0),t)}async function Sa(e,t,r){let n=q(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}}async function Sr(e){let t=await Ta(e);return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>gr(t),ensureFigmaImportPage:()=>xr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>le(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await le(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>le(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>le(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>le(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>le(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ge(t),setPublicApiKey:n=>lr(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>Z(t),setCache:n=>ee(t,n)}}async function Ta(e){let t=await wa(e),r=e.getRootDir(),n=e.join(r,"src"),o=await ya(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:"",angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:""};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);return 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"}`),a}function ya(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function wa(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 xt=ao(Fr(),1);async function Lr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:W(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:K(i.inputs)};return K(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,xt.compress)(n);return btoa(JSON.stringify(o))}async function Or(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,xt.decompress)(o),a=K(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let l=W(e.normalize(s.filePath)),c=n.components.find(u=>W(u.filePath).endsWith(l)&&u.exportName===s.exportName);if(!c){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${c.id})`,c.filePath),await t.registerComponent({cmpId:c.id});for(let u of s.inputs)e.debug(`set input (${c.id})`),await t.setRegisteredComponentInput({cmpId:c.id,name:u.name,type:u.type,required:u.required,defaultValue:u.defaultValue,friendlyName:u.friendlyName,helperText:u.helperText});e.debug(`set input (${c.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:c.id,name:s.name,image:s.image,description:s.description});a=K(d)}return a}var qa={"@builder.io/qwik-city":qn,next:kn,"@remix-run/react":er,react:sr,"@angular/core":Sr};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 de(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=qa[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Lr(e,n),importRegistry:i=>Or(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function jr(e){function t(u){if(typeof u!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(u))}function r(u,m){let p="",x=0,f=-1,g=0,h;for(let C=0;C<=u.length;++C){if(C<u.length)h=u.charCodeAt(C);else{if(h===47)break;h=47}if(h===47){if(!(f===C-1||g===1))if(f!==C-1&&g===2){if(p.length<2||x!==2||p.charCodeAt(p.length-1)!==46||p.charCodeAt(p.length-2)!==46){if(p.length>2){let T=p.lastIndexOf("/");if(T!==p.length-1){T===-1?(p="",x=0):(p=p.slice(0,T),x=p.length-1-p.lastIndexOf("/")),f=C,g=0;continue}}else if(p.length===2||p.length===1){p="",x=0,f=C,g=0;continue}}m&&(p.length>0?p+="/..":p="..",x=2)}else p.length>0?p+="/"+u.slice(f+1,C):p=u.slice(f+1,C),x=C-f-1;f=C,g=0}else h===46&&g!==-1?++g:g=-1}return p}let n=function(...m){let p="",x=!1;for(let f=m.length-1;f>=-1&&!x;f--){let g;f>=0?g=m[f]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(p=g+"/"+p,x=g.charCodeAt(0)===47)}return p=r(p,!x),x?p.length>0?"/"+p:"/":p.length>0?p:"."},o=function(m){if(t(m),m.length===0)return".";let p=m.charCodeAt(0)===47,x=m.charCodeAt(m.length-1)===47;return m=r(m,!p),m.length===0&&!p&&(m="."),m.length>0&&x&&(m+="/"),p?"/"+m:m};return{relative:function(m,p){if(t(m),t(p),m===p||(m=n(m),p=n(p),m===p))return"";let x=1;for(;x<m.length&&m.charCodeAt(x)===47;++x);let f=m.length,g=f-x,h=1;for(;h<p.length&&p.charCodeAt(h)===47;++h);let T=p.length-h,L=g<T?g:T,w=-1,S=0;for(;S<=L;++S){if(S===L){if(T>L){if(p.charCodeAt(h+S)===47)return p.slice(h+S+1);if(S===0)return p.slice(h+S)}else g>L&&(m.charCodeAt(x+S)===47?w=S:S===0&&(w=0));break}let O=m.charCodeAt(x+S),N=p.charCodeAt(h+S);if(O!==N)break;O===47&&(w=S)}let E="";for(S=x+w+1;S<=f;++S)(S===f||m.charCodeAt(S)===47)&&(E.length===0?E+="..":E+="/..");return E.length>0?E+p.slice(h+w):(h+=w,p.charCodeAt(h)===47&&++h,p.slice(h))},resolve:n,join:function(...m){if(m.length===0)return".";let p;for(let x=0;x<m.length;++x){let f=m[x];t(f),f.length>0&&(p===void 0?p=f:p+="/"+f)}return p===void 0?".":o(p)},isAbsolute:function(m){return t(m),m.length>0&&m.charCodeAt(0)===47},basename:function(m,p){if(p!==void 0&&typeof p!="string")throw new TypeError('"ext" argument must be a string');t(m);let x=0,f=-1,g=!0,h;if(p!==void 0&&p.length>0&&p.length<=m.length){if(p.length===m.length&&p===m)return"";let C=p.length-1,T=-1;for(h=m.length-1;h>=0;--h){let L=m.charCodeAt(h);if(L===47){if(!g){x=h+1;break}}else T===-1&&(g=!1,T=h+1),C>=0&&(L===p.charCodeAt(C)?--C===-1&&(f=h):(C=-1,f=T))}return x===f?f=T:f===-1&&(f=m.length),m.slice(x,f)}else{for(h=m.length-1;h>=0;--h)if(m.charCodeAt(h)===47){if(!g){x=h+1;break}}else f===-1&&(g=!1,f=h+1);return f===-1?"":m.slice(x,f)}},normalize:o,dirname:function(m){if(t(m),m.length===0)return".";let p=m.charCodeAt(0),x=p===47,f=-1,g=!0;for(let h=m.length-1;h>=1;--h)if(p=m.charCodeAt(h),p===47){if(!g){f=h;break}}else g=!1;return f===-1?x?"/":".":x&&f===1?"//":m.slice(0,f)},extname:function(m){t(m);let p=-1,x=0,f=-1,g=!0,h=0;for(let C=m.length-1;C>=0;--C){let T=m.charCodeAt(C);if(T===47){if(!g){x=C+1;break}continue}f===-1&&(g=!1,f=C+1),T===46?p===-1?p=C:h!==1&&(h=1):p!==-1&&(h=-1)}return p===-1||f===-1||h===0||h===1&&p===f-1&&p===x+1?"":m.slice(p,f)}}}async function _r(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=jr({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[g]of o)if((g+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),l=f=>{f=i(f);let g=f===t()?f:f+"/",h=g.split("/").length-1,C=[];for(let[T]of o)if(T.split("/").slice(0,h).join("/")+"/"===g){let S=T.split("/")[h];S&&!C.includes(S)&&C.push(S)}return C.sort()},c=f=>{f=i(f);let g=o.get(f);return typeof g=="string"?g:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),u=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),T=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(T)).map(L=>L.toString(16).padStart(2,"0")).join("")}let g=0;for(let h=0;h<f.length;h++){let C=f.charCodeAt(h);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},m=new Set,p={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>l(f),readdirSync:l,readFile:async f=>c(f),readFileSync:c,stat:async f=>d(f),statSync:d,writeFile:async(f,g)=>{f=i(f),o.set(f,g);let h={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of m)await C(h)},hash:u,getDeviceId:async()=>typeof navigator<"u"?u(navigator.userAgent):"",formatCode:async(f,g)=>g,on:(f,g)=>{f==="change"&&m.add(g)},off:(f,g)=>{f==="change"&&m.delete(g)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0"},x=await de(p);return p.getFrameworks=e.getFrameworks?e.getFrameworks:()=>x,p}async function Br(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if($r(e,n))return o;let a=Q(e,n,"cjs"),s=Q(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let u=d.statement;if(!e.ts.isVariableStatement(u))throw new Error(`Expected an export assignment from ${t}`);let m=d.statement;if(e.ts.isVariableStatement(m)){let p=[...m.declarationList.declarations];if(p.length!==1)throw new Error("Expected a single variable declaration");let x=p[0];if(!x.initializer)throw new Error("Expected an initializer on the declaration");let f=x.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let g="BuilderDevTools()",h=[...n.statements],C=h.indexOf(m);return h[C]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(x,x.name,x.exclamationToken,x.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,h),n=P(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=v(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let l=a[0];if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let u=d.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let m=en(e,n);n=m.sourceFile;let p=[...n.statements],x=p.indexOf(d);return p[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[u.right]))),n=e.ts.factory.updateSourceFile(n,p),o.content=v(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let u=d[0];if(!u.initializer)throw new Error("Expected an initializer on the declaration");let m=u.initializer;if(e.ts.isObjectLiteralExpression(m)||e.ts.isCallExpression(m)){let p=en(e,n);n=p.sourceFile;let x=[...n.statements],f=x.indexOf(c);return x[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[m]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=v(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(l.node)){let d=l.node,u=l.statement;if(!e.ts.isExpressionStatement(u))throw new Error("Expected an expression statement for the default export");let m=u.expression;if(!e.ts.isBinaryExpression(m))throw new Error("Expected a binary expression for the default export");let x=l.node.body;if(!e.ts.isBlock(x))throw new Error("Expected a block body on the next config function");let f=[...x.statements],g=f.findIndex(w=>e.ts.isReturnStatement(w));if(g===-1)throw new Error("Expected a return statement on the next config function");let h=f[g],C=en(e,n);n=C.sourceFile,f[g]=e.ts.factory.updateReturnStatement(h,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[h.expression]));let T=[...n.statements],L=T.indexOf(u);return T[L]=e.ts.factory.updateExpressionStatement(u,e.ts.factory.updateBinaryExpression(m,m.left,m.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(x,f)))),n=e.ts.factory.updateSourceFile(n,T),o.content=v(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function $r(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 en(e,t){let r=$r(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 Kr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Ur(e,n))return o;let a=Q(e,n,"cjs"),s=Q(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let l=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let u=d.statement;if(!e.ts.isExportAssignment(u))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(u.expression)){let m="builderDevTools()",p=Ja(e,u.expression);if(!p)return o;let x=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m),void 0,[p]),f=[...n.statements],g=f.indexOf(u);return f[g]=e.ts.factory.updateExportAssignment(u,u.modifiers,x),n=e.ts.factory.updateSourceFile(n,f),n=P(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=v(e,n),o.hasContentUpdates=!0,o}}if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let u=d.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let m=Vr(e,n);n=m.sourceFile;let p=[...n.statements],x=p.indexOf(d);return p[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[u.right]))),n=e.ts.factory.updateSourceFile(n,p),o.content=v(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let u=d[0];if(!u.initializer)throw new Error("Expected an initializer on the declaration");let m=u.initializer;if(e.ts.isObjectLiteralExpression(m)||e.ts.isCallExpression(m)){let p=Vr(e,n);n=p.sourceFile;let x=[...n.statements],f=x.indexOf(c);return x[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[m]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=v(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function Ur(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 Vr(e,t){let r=Ur(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 Ja(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=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("serverDependenciesToBundle",o)]):null}function zr(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 Qr(e,t,r){let n=D(e,r),o=Q(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 l=[...i.node.arguments];if(l.length===0)throw new Error("Expected an argument in defineConfig()");let c=l[0];if(e.ts.isArrowFunction(c)){let d=Wa(e,c);if(!d)return s;l[0]=e.ts.factory.updateArrowFunction(c,c.modifiers,c.typeParameters,c.parameters,c.type,c.equalsGreaterThanToken,d);let u=[...n.statements],m=u.indexOf(a);return u[m]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,l)),n=e.ts.factory.updateSourceFile(n,u),n=P(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=v(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(c)){let d=tn(e,c);if(!d)return s;let u=[...n.statements],m=u.indexOf(a);return u[m]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,u),n=P(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=v(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let l=tn(e,a.expression);if(!l)return s;let c=[...n.statements],d=c.indexOf(a);return c[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,l),n=e.ts.factory.updateSourceFile(n,c),n=P(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=v(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Wa(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=tn(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function tn(e,t){if(Ga(e)){let i=Ya(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Mr(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=Mr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Mr(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 Ya(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Ha(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=nn(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 Ha(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=nn(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=nn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function nn(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 Ga(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function qr(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 Wr(e,t,r){e.debug("Angular config updates are currently in progress...");try{await es(e)}catch{console.error("Unable to update package.json.")}return await Xa(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Xa(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 Za(e,o);await e.writeFile(n,i)}async function Za(e,t){let r=t,n=D(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=P(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
496
627
|
builderDevTools().catch((err: Error) =>
|
|
497
628
|
console.error("Error starting dev tools:", err)
|
|
498
|
-
);`;return r=
|
|
499
|
-
`}var
|
|
629
|
+
);`;return r=v(e,n),o||(r+=i),r}async function es(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=ts(n);o&&await e.writeFile(r,o)}function ts(e){let t=JSON.parse(e);if(t.scripts=t.scripts||{},t.scripts[Jr])return;let r=t.scripts.start||t.scripts.dev||"ng serve";return t.scripts[Jr]=`concurrently "${r}" "${ns}"`,JSON.stringify(t,null,2)+`
|
|
630
|
+
`}var Jr="builder-dev",ns="npx builder-dev-tools";var Hr=[{id:"angular",configFileNames:["angular.json"],ensureConfigPlugin:Wr},{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:Br},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:Qr},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:Kr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:qr}];async function rn(e){let t=e.resolve("/");for(let n of Hr)for(let o of n.configFileNames){let i=e.getRootDir();for(let a=0;a<10;a++)try{let s=e.join(i,o),l=e.readFileSync(s);if(typeof l=="string")return{id:n.id,filePath:s,content:l};if(i===t)break;i=e.dirname(i)}catch(s){if((s?.message??"").includes("Invalid path"))break;throw s}}if((await de(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,Yr),{id:"next",filePath:n,content:Yr}}return null}async function Gr(e){let t=await rn(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await Hr.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=J(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var Yr=`
|
|
500
631
|
/** @type {import('next').NextConfig} */
|
|
501
632
|
const nextConfig = {
|
|
502
633
|
}
|
|
503
634
|
|
|
504
635
|
module.exports = nextConfig
|
|
505
|
-
`.trimStart();var
|
|
636
|
+
`.trimStart();var Xr="/~builder-dev-tools.js";function Zr(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(Xr,e);t.searchParams.set("v",tt);let r=JSON.stringify(tt),n=`/* Builder Devtools v${tt} */
|
|
506
637
|
`;return n+=`(() => {
|
|
507
638
|
`,n+=` if (typeof document !== "undefined") {
|
|
508
639
|
`,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]");
|
|
@@ -515,4 +646,4 @@ module.exports = nextConfig
|
|
|
515
646
|
`,n+=` }
|
|
516
647
|
`,n+=` }
|
|
517
648
|
`,n+=`})();
|
|
518
|
-
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var
|
|
649
|
+
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var tt="1.0.20";
|