builder.io 1.1.16 → 1.1.17-3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/index.cjs +840 -408
- package/cli/index.cjs.map +7 -0
- package/cli/main.cjs +2 -0
- package/core/index.cjs +186 -92
- package/core/index.mjs +186 -92
- package/figma/index.cjs +1 -1
- package/figma/index.mjs +1 -1
- package/node/index.cjs +3 -1
- package/node/index.mjs +3 -1
- package/package.json +10 -6
- package/remix/build.cjs +1 -1
- package/remix/index.mjs +1 -1
- package/server/index.cjs +32 -50
- package/server/index.mjs +32 -50
- package/types/cli/builder-add/interface.d.ts +5 -2
- package/types/cli/builder-add/options.d.ts +2 -7
- package/types/cli/constants.d.ts +1 -0
- package/types/cli/credentials.d.ts +2 -1
- package/types/cli/figma-publish.d.ts +20 -2
- package/types/cli/figma.d.ts +1 -0
- package/types/cli/generate.d.ts +2 -1
- package/types/cli/index.d.ts +0 -1
- package/types/cli/sync-utils.d.ts +10 -0
- package/types/client/client-api.d.ts +1 -1
- package/types/common/ast/component-info.d.ts +1 -0
- package/types/common/builder/builder-api.d.ts +2 -1
- package/types/common/constants.d.ts +1 -0
- package/types/common/utils.d.ts +2 -1
- package/types/core/adapters/angular/angular-app-module-imports.d.ts +2 -2
- package/types/core/adapters/angular/angular-ensure-builder-setup.d.ts +1 -1
- package/types/core/adapters/next/index.d.ts +1 -0
- package/types/core/adapters/next/next-registry-parse.d.ts +0 -1
- package/types/core/adapters/react/index.d.ts +1 -0
- package/types/core/adapters/react/react-ensure-builder-setup.d.ts +2 -2
- package/types/core/adapters/react/react-registry-parse.d.ts +2 -1
- package/types/core/adapters/react/react-registry.d.ts +1 -1
- package/types/core/adapters/react/react-test-utils.d.ts +3 -2
- package/types/core/adapters/remix/index.d.ts +1 -0
- package/types/core/adapters/remix/remix-ensure-builder-setup.d.ts +1 -1
- package/types/core/adapters/remix/remix-registry-parse.d.ts +1 -1
- package/types/core/adapters/remix/remix-registry.d.ts +1 -1
- package/types/core/adapters/remix/remix-test-utils.d.ts +3 -2
- package/types/core/find-dependencies.d.ts +7 -0
- package/types/figma/index.d.ts +1 -0
- package/types/node/node-sys.d.ts +1 -0
- package/types/server/builder-connect.d.ts +2 -2
- package/types/types.d.ts +83 -1
- package/vite/index.cjs +1 -1
- package/vite/index.mjs +1 -1
- package/webpack/index.cjs +14 -15
- package/webpack/index.mjs +14 -15
package/core/index.mjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
var
|
|
2
|
-
`),n;for(;(n=
|
|
3
|
-
`),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var
|
|
1
|
+
var go=Object.create;var mn=Object.defineProperty;var xo=Object.getOwnPropertyDescriptor;var ho=Object.getOwnPropertyNames;var Co=Object.getPrototypeOf,So=Object.prototype.hasOwnProperty;var Pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Po=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ho(t))!So.call(e,o)&&o!==r&&mn(e,o,{get:()=>t[o],enumerable:!(n=xo(t,o))||n.enumerable});return e};var Eo=(e,t,r)=>(r=e!=null?go(Co(e)):{},Po(t||!e||!e.__esModule?mn(r,"default",{value:e,enumerable:!0}):r,e));var Wt=Pe(Et=>{"use strict";Object.defineProperty(Et,"__esModule",{value:!0});function _r(e){return Object.prototype.toString.call(e)}Et.getType=_r;function za(e){throw new TypeError("unsupported data type: "+_r(e))}Et.throwUnknownDataType=za});var Zt=Pe(Ce=>{"use strict";Object.defineProperty(Ce,"__esModule",{value:!0});var he="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);he+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);he+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);he+=t}var Ue=he.length,Gt={};for(let e=0;e<Ue;e++){let t=he[e];Gt[t]=e}function Ht(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Gt[o];i*=r,t+=i,r*=Ue}return t}Ce.s_to_int=Ht;function jr(e){let t=BigInt(0),r=BigInt(1),n=BigInt(Ue);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Gt[i]);a*=r,t+=a,r*=n}return t}Ce.s_to_big_int=jr;function Xt(e){if(e===0)return he[0];let t=[];for(;e!==0;){let r=e%Ue,n=he[r];t.push(n),e-=r,e/=Ue}return t.reverse().join("")}Ce.int_to_s=Xt;function Br(e){let t=BigInt(0),r=BigInt(Ue);if(e===t)return he[0];let n=[];for(;e!==t;){let o=e%r,i=he[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}Ce.big_int_to_s=Br;function Dt(e){return e.split("").reverse().join("")}function Vr(e){if(e<0)return"-"+Vr(-e);let[t,r]=e.toString().split(".");if(!r)return Xt(e);let n;r&&([r,n]=r.split("e")),t=Tt(t),r=Dt(r),r=Tt(r);let o=t+"."+r;if(n){switch(o+=".",n[0]){case"+":n=n.slice(1);break;case"-":o+="-",n=n.slice(1);break}n=Dt(n),n=Tt(n),o+=n}return o}Ce.num_to_s=Vr;function Tt(e){let t=+e;return t.toString()===e?Xt(t):":"+Br(BigInt(e))}Ce.int_str_to_s=Tt;function Yt(e){return e[0]===":"?jr(e.substring(1)).toString():Ht(e).toString()}function Kr(e){if(e[0]==="-")return-Kr(e.substr(1));let[t,r,n]=e.split(".");if(!r)return Ht(t);t=Yt(t),r=Yt(r),r=Dt(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Yt(n),n=Dt(n),o+=i?-n:+n}return+o}Ce.s_to_num=Kr});var tn=Pe(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});var en=Zt();function qa(e){return"n|"+en.num_to_s(e)}Se.encodeNum=qa;function Ja(e){return e=e.replace("n|",""),en.s_to_num(e)}Se.decodeNum=Ja;function Qa(e){return typeof e=="number"?e:en.s_to_int(e)}Se.decodeKey=Qa;function Wa(e){return e?"b|T":"b|F"}Se.encodeBool=Wa;function Ya(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}Se.decodeBool=Ya;function Ga(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}Se.encodeStr=Ga;function Ha(e){return e[0]+e[1]==="s|"?e.substr(2):e}Se.decodeStr=Ha});var $r=Pe(nn=>{"use strict";Object.defineProperty(nn,"__esModule",{value:!0});nn.config={sort_key:!1}});var on=Pe(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});var Xa=$r(),Za=Wt(),rn=tn(),es=Zt();function ts(e){return e.store.toArray()}Oe.memToValues=ts;function Mr(){let e=[];return{forEach(t){for(let r=0;r<e.length;r++)if(t(e[r])==="break")return},add(t){e.push(t)},toArray(){return e}}}Oe.makeInMemoryStore=Mr;function Ur(){let e=Object.create(null),t=Object.create(null);return{getValue(r){return e[r]},getSchema(r){return t[r]},forEachValue(r){for(let[n,o]of Object.entries(e))if(r(n,o)==="break")return},forEachSchema(r){for(let[n,o]of Object.entries(t))if(r(n,o)==="break")return},setValue(r,n){e[r]=n},setSchema(r,n){t[r]=n},hasValue(r){return r in e},hasSchema(r){return r in t}}}Oe.makeInMemoryCache=Ur;function ns(){return{store:Mr(),cache:Ur(),keyCount:0}}Oe.makeInMemoryMemory=ns;function Fe(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=es.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function rs(e,t){Xa.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=it(e,t,void 0);return e.cache.setSchema(r,n),n}function it(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return it(e,null,r);break;case"object":if(t===null)return Fe(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":it(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),Fe(e,n)}else{let n=Object.keys(t);if(n.length===0)return Fe(e,"o|");let o="o",i=rs(e,n);o+="|"+i;for(let a of n){let s=t[a],p=it(e,s,t);o+="|"+p}return Fe(e,o)}case"boolean":return Fe(e,rn.encodeBool(t));case"number":return Fe(e,rn.encodeNum(t));case"string":return Fe(e,rn.encodeStr(t))}return Za.throwUnknownDataType(t)}Oe.addValue=it});var sn=Pe(st=>{"use strict";Object.defineProperty(st,"__esModule",{value:!0});var os=Wt(),yt=tn(),an=on();function is(e){let t=an.makeInMemoryMemory(),r=an.addValue(t,e,void 0);return[an.memToValues(t),r]}st.compress=is;function as(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=at(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let p=i[s-2],l=n[s];l=at(e,l),r[p]=l}return r}function ss(e,t){if(t==="a|")return[];let r=t.split("|"),n=r.length-1,o=new Array(n);for(let i=0;i<n;i++){let a=r[i+1];a=at(e,a),o[i]=a}return o}function at(e,t){if(t===""||t==="_")return null;let r=yt.decodeKey(t),n=e[r];if(n===null)return n;switch(typeof n){case"undefined":return n;case"number":return n;case"string":switch(n[0]+n[1]){case"b|":return yt.decodeBool(n);case"o|":return as(e,n);case"n|":return yt.decodeNum(n);case"a|":return ss(e,n);default:return yt.decodeStr(n)}}return os.throwUnknownDataType(n)}st.decode=at;function ps(e){let[t,r]=e;return at(t,r)}st.decompress=ps});var qr=Pe(wt=>{"use strict";Object.defineProperty(wt,"__esModule",{value:!0});function ls(e){for(let t in e)e[t]===void 0&&delete e[t]}wt.trimUndefined=ls;function cs(e){zr(e,new Set)}wt.trimUndefinedRecursively=cs;function zr(e,t){t.add(e);for(let r in e)if(e[r]===void 0)delete e[r];else{let n=e[r];n&&typeof n=="object"&&!t.has(n)&&zr(n,t)}}});var Wr=Pe(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});var Jr=sn();ve.compress=Jr.compress;ve.decompress=Jr.decompress;var ms=sn();ve.decode=ms.decode;var us=on();ve.addValue=us.addValue;var Qr=qr();ve.trimUndefined=Qr.trimUndefined;ve.trimUndefinedRecursively=Qr.trimUndefinedRecursively});async function pt(e,t){let r=e.resolve("/");for(let n=0;n<20;n++){let o=e.join(t,"package.json"),i=await e.readFile(o);if(i)return JSON.parse(i);if(t===r)break;t=e.dirname(t)}return null}async function un(e,t){for(let r=0;r<20;r++){let n=e.dirname(t),o=e.join(n,"node_modules");if(await e.exists(o))return o;if(t===e.getRootDir())break;t=e.dirname(t)}return e.join(e.getRootDir(),"node_modules")}async function ze(e,t,r){let n=await e.readdir(t);return n.includes(r)?e.join(t,r):(await Promise.all(n.map(async i=>{if(i.startsWith(".")||i==="node_modules")return;let a=e.join(t,i);if((await e.stat(a)).isDirectory()){let p=await ze(e,a,r);if(p)return p}}))).find(i=>typeof i=="string")}async function be(e){let t=[],r=await pt(e,e.getRootDir());if(r){let n=fn(r);t.push(...n)}return t}function fn(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of To)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var To=["@shopify/remix-oxygen","@shopify/hydrogen","@builder.io/qwik-city","@remix-run/react","@sveltejs/kit","astro","gatsby","next","nuxt","@builder.io/qwik","@angular/core","react","solid-js","svelte","vue"];async function re(e){let t=dn(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function oe(e,t){t=typeof t=="object"&&t!=null?t:{};let r=dn(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function dn(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function Ee(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await Do(e,i);if(a){let s=a[r];if(typeof s=="string"&&s.length>0&&s!=="YOUR_API_KEY")return n.envValue=s,n.file=i,n}}return n.file=e.join(e.getRootDir(),t[t.length-1]),n}async function Do(e,t){let r=await e.readFile(t);return typeof r=="string"?gn(r):null}function gn(e){let t={},r=e.replace(/\r\n?/gm,`
|
|
2
|
+
`),n;for(;(n=yo.exec(r))!=null;){let o=n[1],i=n[2]||"";i=i.trim();let a=i[0];i=i.replace(/^(['"`])([\s\S]*)\1$/gm,"$2"),a==='"'&&(i=i.replace(/\\n/g,`
|
|
3
|
+
`),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var yo=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function Te(e,t,r,n){let o="# https://www.builder.io/c/docs/using-your-api-key",i=await e.readFile(t);if(i)if(i.includes(r))if(i.includes(n))e.debug(`"${r}" with "${n}" already set in ${t}`);else return e.debug(`Replace "${r}" in ${t}`),i=i.replace(new RegExp(`${r}=.*`),`${r}=${n}`),await e.writeFile(t,i),"update";else return e.debug(`Append "${r}" to ${t}`),i+=`
|
|
4
4
|
|
|
5
5
|
${o}
|
|
6
6
|
${r}=${n}
|
|
7
7
|
|
|
8
8
|
`,await e.writeFile(t,i),"update";else return e.debug(`Creating new .env file with "${r}" at ${t}`),i=[o,`${r}=${n}`,""].join(`
|
|
9
|
-
`),await e.writeFile(t,i),"create";return null}async function
|
|
9
|
+
`),await e.writeFile(t,i),"create";return null}async function qe(e){return await Ee(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],ie)}async function xn(e,t){let r=await qe(e),n=await Te(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ie="NEXT_PUBLIC_BUILDER_API_KEY";var D={gen1:"Gen 1",gen2:"Gen 2"};function v(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest,void 0)}function lt(e,t=""){let r=v(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function O(e,t,r){if(t){let n=e.ts.createPrinter({newLine:e.ts.NewLineKind.LineFeed,removeComments:r});return e.ts.isSourceFile(t)?n.printFile(t).trim()+`
|
|
10
10
|
`:n.printNode(e.ts.EmitHint.Unspecified,t,e.ts.createSourceFile("module.tsx","",e.ts.ScriptTarget.Latest)).trim()+`
|
|
11
|
-
`}return""}function v(e,t,r){t=X(t),r=X(r),t=e.dirname(t);let n=e.basename(r,e.extname(r));r=e.dirname(r);let o;return n==="index"?o=e.relative(t,r):o=e.relative(t,e.join(r,n)),o=X(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function X(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Ae(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return mn(o==="index"?e.basename(e.dirname(t)):o)}function mn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=X(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function k(e,t){let r=X(e.relative(e.getRootDir(),t));r=r.split("/").filter(o=>o!=="."&&o!==".."&&o!=="").join("/"),r.endsWith(".tsx")||r.endsWith(".jsx")?r=r.slice(0,-4):(r.endsWith(".ts")||r.endsWith(".js"))&&(r=r.slice(0,-3));let n=e.getFrameworks();return r.startsWith("src/")&&(r=r.slice(4)),n.some(o=>o.name.includes("next"))?"@/"+r:"~/"+r}function A(e,t){let r=t,n=[];for(let o=0;o<2;o++){let i=e.basename(r);if(!i||i==="components")break;n.unshift(i),r=e.dirname(r)}return n.join("/")}function j(e){for(e=e.replace(/([A-Z])/g," $1").replace(/\./g," ").replace(/_/g," ").replace(/-/g," ").replace(/\s/g," ").trim();e.includes(" ");)e=e.replace(/ /g," ");return e.split(" ").map(t=>t.length>2?t[0].toUpperCase()+t.slice(1):t).join("").trim()}function Q(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function _(e,t,r){if(typeof r!="string"||r==="")throw new Error(`getComponentId(), exportName must be a non-empty string, received: ${r}, ${t}`);return t=e.normalize(t),(await e.hash(t+"#"+r)).substring(0,8)}function Me(e){return typeof e=="number"}function Fe(e){return typeof e=="boolean"}function U(e){return typeof e=="string"}function Ue(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function J(e){return JSON.parse(JSON.stringify(e))}function qe(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=mo(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,p)=>p!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,ze(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,ze(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function mo(e,t,r){return t.properties.findIndex(n=>b(e,n)===r)}function Qe(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return go(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return fo(e,t);case e.ts.SyntaxKind.StringLiteral:return t.text;case e.ts.SyntaxKind.NumericLiteral:return Number(t.text);case e.ts.SyntaxKind.NoSubstitutionTemplateLiteral:return t.text;case e.ts.SyntaxKind.TrueKeyword:return!0;case e.ts.SyntaxKind.FalseKeyword:return!1;case e.ts.SyntaxKind.Identifier:switch(t.escapedText){case"undefined":return;case"null":return null;case"String":return String;case"Number":return Number;case"Boolean":return Boolean;case"NaN":return NaN}}}function fo(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=b(e,n);o&&(r[o]=Qe(e,n.initializer))}}return r}function go(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Qe(e,r)):[]}function b(e,t){if(t&&e.ts.isPropertyAssignment(t)){let r=t.name;switch(r.kind){case e.ts.SyntaxKind.Identifier:return r.text;case e.ts.SyntaxKind.StringLiteral:case e.ts.SyntaxKind.NumericLiteral:return r.text;case e.ts.SyntaxKind.ComputedPropertyName:let n=r.expression;if(e.ts.isStringLiteral(n)||e.ts.isNumericLiteral(n))return r.expression.text}}}function ze(e,t){return yt(e,t,new WeakSet)}function yt(e,t,r){return t===void 0?e.ts.factory.createIdentifier("undefined"):t===null?e.ts.factory.createIdentifier("null"):typeof t=="string"?e.ts.factory.createStringLiteral(t):typeof t=="number"?isNaN(t)?e.ts.factory.createIdentifier("NaN"):e.ts.factory.createNumericLiteral(t):t===!0?e.ts.factory.createTrue():t===!1?e.ts.factory.createFalse():t===String?e.ts.factory.createIdentifier("String"):t===Number?e.ts.factory.createIdentifier("Number"):t===Boolean?e.ts.factory.createIdentifier("Boolean"):Array.isArray(t)?xo(e,t,r):typeof t=="object"?ho(e,t,r):e.ts.factory.createIdentifier(t)}function xo(e,t,r){let n=t.map(o=>yt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function ho(e,t,r){if(r.has(t))return e.ts.factory.createIdentifier("undefined");r.add(t);let n=Object.keys(t).map(o=>e.ts.factory.createPropertyAssignment(o,yt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function be(e,t,r){let n=[];if(!r)return n;let o=null;if(e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r)){let i=r.parameters;if(i.length>0){let a=i[0],s=t.getTypeAtLocation(a);s.aliasTypeArguments&&s.aliasTypeArguments.length>0?o=s.aliasTypeArguments[0].getProperties():o=s.getProperties()}}else if(e.ts.isIdentifier(r)){let i=t.getTypeAtLocation(r),a=i.symbol?.valueDeclaration;if(a&&e.ts.isClassDeclaration(a)){let p=a.heritageClauses?.find(l=>l.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(p){for(let l of p)if(t.getSymbolAtLocation(l.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(l)){let f=l.typeArguments;if(f){let c=f[0];o=t.getTypeFromTypeNode(c).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[0],r).getProperties())}}}if(o)for(let i of o){let a=Co(e,t,i);a&&n.push(a)}return n=n.filter(dn),n.length>0?n:So(e,r)}function Co(e,t,r){let n=r.valueDeclaration,o=r.getName();if(n||(n=r.getDeclarations()?.[0]),n&&e.ts.isPropertySignature(n)){if(o!=="children"&&n.getSourceFile().fileName.includes("node_modules/@types/"))return null;let i="string",a;if(n?.type){let p=t.getTypeFromTypeNode(n.type),l=t.typeToString(p),d=Tt(l);d.knownType?i=d.builderType:yo(l)||p.flags&e.ts.TypeFlags.StringLike?i="string":p.flags&e.ts.TypeFlags.NumberLike?i="number":p.flags&e.ts.TypeFlags.IndexedAccess?i="list":p.flags&e.ts.TypeFlags.Object||p.isUnion()&&p.types.every(f=>f.flags&e.ts.TypeFlags.Object)||p.isIntersection()&&p.types.some(f=>f.flags&e.ts.TypeFlags.Object)?i="object":i="string",l!==i&&(a=l)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let p=wo(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},p&&p.length>0&&s.type==="string"&&p.every(Do)?s.enum=p.map(Eo):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function So(e,t){let r=[],n=e.ts.getJSDocCommentsAndTags(t);for(let o of n)if(!(!e.ts.isJSDoc(o)||!o.tags))for(let i of o.tags){if(!e.ts.isJSDocParameterTag(i)||i.tagName.text!=="param")continue;let s=i.typeExpression?.type;if(!s||!e.ts.isJSDocTypeLiteral(s))continue;let p=s.jsDocPropertyTags;if(p)for(let l of p){if(!e.ts.isJSDocPropertyLikeTag(l))continue;let d=l.name;if(!e.ts.isQualifiedName(d))continue;let f=l.typeExpression;if(!f)continue;let c="";switch(f.type.kind){case e.ts.SyntaxKind.StringKeyword:{c="string";break}case e.ts.SyntaxKind.NumberKeyword:{c="number";break}case e.ts.SyntaxKind.BooleanKeyword:{c="boolean";break}default:continue}let h={name:d.right.text,type:c,isRegistered:!1};r.push(h)}}return r.filter(dn)}var Po=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function yo(e){return typeof e!="string"?!1:!!Po.some(t=>e.includes(t))}function Tt(e){return typeof e=="string"&&(e=e.trim(),To.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var To=[{value:"boolean",text:"boolean"},{value:"color",text:"color (provides a color in hex or rgb)"},{value:"date",text:"date (same format as the Date constructor)"},{value:"email",text:"email"},{value:"file",text:"file (uploads a file and provides a url)"},{value:"list",text:"list (collection of items)"},{value:"longText",text:"longText (multiline text editor)"},{value:"number",text:"number"},{value:"object",text:"object (set of specific names and values)"},{value:"richText",text:"richText (provides value as html)"},{value:"string",text:"string"}];function Do(e){return/^['"].*['"]$/.test(e)}function Eo(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var wo=(e,t,r)=>{let n=new Set;fn(e,t,r,n);let o=n.delete("true"),i=n.delete("false");(o||i)&&n.add("boolean");let a=Array.from(n.keys()).sort();if(a.length>1&&(a=a.map(s=>s.indexOf("=>")>=0?`(${s})`:s)),!(a.length>20))return a},vo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},fn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{fn(e,t,o,n)});else if(r.isLiteral()){let o=vo(e,t,r);n.add(o)}};function dn(e){let t=e?.name;if(typeof t!="string"||t===""||t.startsWith("aria")||t.startsWith("data-"))return!1;if(t.startsWith("on")&&t.length>2){let r=t.charAt(2);if(r.toUpperCase()===r)return!1}return!bo.has(t.toLowerCase())}var bo=new Set(["about","accessKey","accessKeyLabel","asChild","autoCapitalize","autoCorrect","autoFocus","autoSave","blur","contentEditable","contextMenu","dangerouslySetInnerHTML","datatype","defaultChecked","defaultValue","dir","draggable","enterKeyHint","focus","form","formAction","formEncType","formMethod","formNoValidate","formTarget","inlist","innerText","inputMode","is","isContentEditable","itemID","itemProp","itemRef","itemScope","itemType","lang","nonce","offsetHeight","offsetLeft","offsetTop","offsetWidth","outerText","prefix","property","radioGroup","rel","resource","results","rev","role","security","slot","spellCheck","suppressContentEditableWarning","suppressHydrationWarning","tabIndex","translate","typeof","unselectable","vocab"].map(e=>e.toLowerCase()));function W(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=b(e,n);if(o==="name"&&e.ts.isStringLiteral(n.initializer)){t.name=n.initializer.text;continue}if(o==="description"&&e.ts.isStringLiteral(n.initializer)){t.description=n.initializer.text;continue}if(o==="image"&&e.ts.isStringLiteral(n.initializer)){t.image=n.initializer.text;continue}if(o==="inputs"&&e.ts.isArrayLiteralExpression(n.initializer)){let i=Io(e,n.initializer);Z(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Qe(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function Io(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Ro(e,n));return r}function Ro(e,t){let r=Qe(e,t),n=_o(r);return n.isRegistered=!0,n}function K(e,t,r){let n=Ao(r);return t=qe(e,t,"name",n.name,!1),t=qe(e,t,"description",n.description),t=qe(e,t,"image",n.image),t=No(e,t,n),jo(e,t)}function No(e,t,r){let n=null,o=t.properties.filter(s=>e.ts.isPropertyAssignment(s)&&e.ts.isIdentifier(s.name)),i=o.findIndex(s=>e.ts.isIdentifier(s.name)&&s.name.text==="inputs"),a=[...r.inputs??[]];if(i>-1){if(a.length===0)return qe(e,t,"inputs",null);let s=o[i];e.ts.isPropertyAssignment(s)&&e.ts.isArrayLiteralExpression(s.initializer)&&(n=s.initializer)}return a.length===0?t:(n=Oo(e,n||e.ts.factory.createArrayLiteralExpression(),a),i>-1?o[i]=e.ts.factory.updatePropertyAssignment(o[i],o[i].name,n):o.push(e.ts.factory.createPropertyAssignment("inputs",n)),e.ts.factory.updateObjectLiteralExpression(t,o))}function Ao(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Fo)}}function Fo(e){let t={name:e.name,type:e.type};return(U(e.defaultValue)||Me(e.defaultValue)||Fe(e.defaultValue))&&(t.defaultValue=e.defaultValue),U(e.friendlyName)&&(t.friendlyName=e.friendlyName),U(e.helperText)&&(t.helperText=e.helperText),e.required===!0&&(t.required=!0),Array.isArray(e.enum)&&(t.enum=e.enum),e.hideFromUI===!0&&(t.hideFromUI=!0),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(t.meta=e.meta),t}function Oo(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>b(e,s)==="name");if(!i)return!1;let a=i.initializer;return e.ts.isStringLiteral(a)?r.some(s=>s.name===a.text):!1});for(let o of r)n=Lo(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>b(e,c)==="name"),s=i.properties.find(c=>b(e,c)==="name"),p=a?.initializer,l=s?.initializer,d=p&&e.ts.isStringLiteral(p)?p.text:"zz",f=l&&e.ts.isStringLiteral(l)?l.text:"zz";return d.toLowerCase().localeCompare(f.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Lo(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=b(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=gn(e,t[n],r);else{let o=gn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function gn(e,t,r){let n=t.properties.filter(i=>e.ts.isPropertyAssignment(i)),o=Object.keys(r).filter(i=>i!=="isRegistered");for(let i of o)n=ko(e,n,r,i);return n=Bo(e,n.filter(i=>{let a=b(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function ko(e,t,r,n){let o=t.findIndex(i=>e.ts.isIdentifier(i.name)&&i.name.text===n);return o>-1?t[o]=e.ts.factory.updatePropertyAssignment(t[o],t[o].name,ze(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,ze(e,r[n]))),t}function Z(e,t){for(let r of t){let n=e.inputs.findIndex(o=>o.name===r.name);n>-1?(r.isRegistered||!e.inputs[n].isRegistered)&&(e.inputs[n]=r):e.inputs.push(r)}e.acceptsChildren=Dt(e)}function _o(e){let t=Tt(e.type),r={name:e.name.trim(),type:t.builderType};return U(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(U(e.defaultValue)||Me(e.defaultValue)||Fe(e.defaultValue))&&(r.defaultValue=e.defaultValue),U(e.helperText)&&(r.helperText=e.helperText),Fe(e.required)&&(r.required=e.required),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(r.meta=e.meta),Array.isArray(e.enum)&&e.enum.length>0&&(r.enum=e.enum),e.hideFromUI===!0&&(r.hideFromUI=!0),Et(r)}function Dt(e){let t=e.inputs.some(n=>n.name==="children"),r=e.inputs.some(n=>n.meta?.ts==="ReactNode");return!!(t||r||e.acceptsChildren===!0)}function Et(e){if(e.name==="children"&&(e.hideFromUI=!0,delete e.required),e.type==="object"&&e.defaultValue==null&&(e.hideFromUI=!0),e.type==="list"&&e.defaultValue==null&&(e.hideFromUI=!0),e.meta){let t=e.meta.ts;typeof t=="string"&&(t=t.trim(),t.endsWith("ReactNode")&&(t="ReactNode"),e.meta.ts=t,t==="ReactNode"&&(e.hideFromUI=!0))}return e}function jo(e,t){let r=[...t.properties].sort((n,o)=>{let i=b(e,n)||"zz",a=b(e,o)||"zz";if(i==="inputs")return 1;let s=xn.indexOf(i),p=xn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var xn=["component","name","description"];function Bo(e,t){return[...t].sort((n,o)=>{let i=b(e,n)||"zz",a=b(e,o)||"zz",s=hn.indexOf(i),p=hn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)})}var hn=["name","type"];function Cn(e,t){let r=`Builder.registerComponent(
|
|
11
|
+
`}return""}function R(e,t,r){t=Z(t),r=Z(r),t=e.dirname(t);let n=e.basename(r,e.extname(r));r=e.dirname(r);let o;return n==="index"?o=e.relative(t,r):o=e.relative(t,e.join(r,n)),o=Z(e.normalize(o)),o.startsWith(".")||(o="./"+o),o}function Z(e){return e.startsWith("\\\\?\\")?e:e.replace(/\\/g,"/")}function Re(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return hn(o==="index"?e.basename(e.dirname(t)):o)}function hn(e){return j(e).replace(/ /g,"")}function Y(e,t){let r=e.extname(t),n=Z(e.basename(t,r)).split("/").pop();return j(n==="index"?e.basename(e.dirname(t)):n)}function L(e,t){let r=Z(e.relative(e.getRootDir(),t));r=r.split("/").filter(o=>o!=="."&&o!==".."&&o!=="").join("/"),r.endsWith(".tsx")||r.endsWith(".jsx")?r=r.slice(0,-4):(r.endsWith(".ts")||r.endsWith(".js"))&&(r=r.slice(0,-3));let n=e.getFrameworks();return r.startsWith("src/")&&(r=r.slice(4)),n.some(o=>o.name.includes("next"))?"@/"+r:"~/"+r}function A(e,t){let r=t,n=[];for(let o=0;o<2;o++){let i=e.basename(r);if(!i||i==="components")break;n.unshift(i),r=e.dirname(r)}return n.join("/")}function j(e){for(e=e.replace(/([A-Z])/g," $1").replace(/\./g," ").replace(/_/g," ").replace(/-/g," ").replace(/\s/g," ").trim();e.includes(" ");)e=e.replace(/ /g," ");return e.split(" ").map(t=>t.length>2?t[0].toUpperCase()+t.slice(1):t).join("").trim()}function J(e){return e.sort((t,r)=>t.name.toLocaleLowerCase().localeCompare(r.name.toLocaleLowerCase()))}async function _(e,t,r,n){if(typeof r!="string"||r==="")throw new Error(`getComponentId(), exportName must be a non-empty string, received: ${r}, ${t}`);return n&&(t=n),t=e.normalize(t),(await e.hash(t+"#"+r)).substring(0,8)}function Je(e){return typeof e=="number"}function ke(e){return typeof e=="boolean"}function q(e){return typeof e=="string"}function Le(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function W(e){return JSON.parse(JSON.stringify(e))}function ct(e,t,r){for(let n of t)if(e.dirname(r).includes(n))return!0;return!1}function We(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=wo(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,p)=>p!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,Qe(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,Qe(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function wo(e,t,r){return t.properties.findIndex(n=>I(e,n)===r)}function Ye(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return Io(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return vo(e,t);case e.ts.SyntaxKind.StringLiteral:return t.text;case e.ts.SyntaxKind.NumericLiteral:return Number(t.text);case e.ts.SyntaxKind.NoSubstitutionTemplateLiteral:return t.text;case e.ts.SyntaxKind.TrueKeyword:return!0;case e.ts.SyntaxKind.FalseKeyword:return!1;case e.ts.SyntaxKind.Identifier:switch(t.escapedText){case"undefined":return;case"null":return null;case"String":return String;case"Number":return Number;case"Boolean":return Boolean;case"NaN":return NaN}}}function vo(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=I(e,n);o&&(r[o]=Ye(e,n.initializer))}}return r}function Io(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Ye(e,r)):[]}function I(e,t){if(t&&e.ts.isPropertyAssignment(t)){let r=t.name;switch(r.kind){case e.ts.SyntaxKind.Identifier:return r.text;case e.ts.SyntaxKind.StringLiteral:case e.ts.SyntaxKind.NumericLiteral:return r.text;case e.ts.SyntaxKind.ComputedPropertyName:let n=r.expression;if(e.ts.isStringLiteral(n)||e.ts.isNumericLiteral(n))return r.expression.text}}}function Qe(e,t){return bt(e,t,new WeakSet)}function bt(e,t,r){return t===void 0?e.ts.factory.createIdentifier("undefined"):t===null?e.ts.factory.createIdentifier("null"):typeof t=="string"?e.ts.factory.createStringLiteral(t):typeof t=="number"?isNaN(t)?e.ts.factory.createIdentifier("NaN"):e.ts.factory.createNumericLiteral(t):t===!0?e.ts.factory.createTrue():t===!1?e.ts.factory.createFalse():t===String?e.ts.factory.createIdentifier("String"):t===Number?e.ts.factory.createIdentifier("Number"):t===Boolean?e.ts.factory.createIdentifier("Boolean"):Array.isArray(t)?bo(e,t,r):typeof t=="object"?Ro(e,t,r):e.ts.factory.createIdentifier(t)}function bo(e,t,r){let n=t.map(o=>bt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Ro(e,t,r){if(r.has(t))return e.ts.factory.createIdentifier("undefined");r.add(t);let n=Object.keys(t).map(o=>e.ts.factory.createPropertyAssignment(o,bt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function Ne(e,t,r){let n=[];if(!r)return n;let o=null;if(e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r)){let i=r.parameters;if(i.length>0){let a=i[0],s=t.getTypeAtLocation(a);s.aliasTypeArguments&&s.aliasTypeArguments.length>0?o=s.aliasTypeArguments[0].getProperties():o=s.getProperties()}}else if(e.ts.isIdentifier(r)){let i=t.getTypeAtLocation(r),a=i.symbol?.valueDeclaration;if(a&&e.ts.isClassDeclaration(a)){let p=a.heritageClauses?.find(l=>l.token===e.ts.SyntaxKind.ExtendsKeyword)?.types;if(p){for(let l of p)if(t.getSymbolAtLocation(l.expression)?.name==="Component"){if(e.ts.isExpressionWithTypeArguments(l)){let u=l.typeArguments;if(u){let c=u[0];o=t.getTypeFromTypeNode(c).getProperties()}}break}}}if(!o){let s=i.getCallSignatures();if(s.length>0){let p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[0],r).getProperties())}}}else if(e.ts.isExportSpecifier(r)){let i=t.getSymbolAtLocation(r.name);if(i){let s=t.getTypeOfSymbolAtLocation(i,r).getCallSignatures();if(s.length>0){let p=s[0].getParameters();p.length>0&&(o=t.getTypeOfSymbolAtLocation(p[0],r).getProperties())}}}if(o)for(let i of o){let a=No(e,t,i);a&&n.push(a)}return n=n.filter(Sn),n.length>0?n:Ao(e,r)}function No(e,t,r){let n=r.valueDeclaration,o=r.getName();if(n||(n=r.getDeclarations()?.[0]),n&&e.ts.isPropertySignature(n)){if(o!=="children"&&n.getSourceFile().fileName.includes("node_modules/@types/"))return null;let i="string",a;if(n?.type){let p=t.getTypeFromTypeNode(n.type),l=t.typeToString(p),d=Rt(l);d.knownType?i=d.builderType:Oo(l)||p.flags&e.ts.TypeFlags.StringLike?i="string":p.flags&e.ts.TypeFlags.NumberLike?i="number":p.flags&e.ts.TypeFlags.IndexedAccess?i="list":p.flags&e.ts.TypeFlags.Object||p.isUnion()&&p.types.every(u=>u.flags&e.ts.TypeFlags.Object)||p.isIntersection()&&p.types.some(u=>u.flags&e.ts.TypeFlags.Object)?i="object":i="string",l!==i&&(a=l)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let p=jo(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},p&&p.length>0&&s.type==="string"&&p.every(Lo)?s.enum=p.map(_o):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function Ao(e,t){let r=[],n=e.ts.getJSDocCommentsAndTags(t);for(let o of n)if(!(!e.ts.isJSDoc(o)||!o.tags))for(let i of o.tags){if(!e.ts.isJSDocParameterTag(i)||i.tagName.text!=="param")continue;let s=i.typeExpression?.type;if(!s||!e.ts.isJSDocTypeLiteral(s))continue;let p=s.jsDocPropertyTags;if(p)for(let l of p){if(!e.ts.isJSDocPropertyLikeTag(l))continue;let d=l.name;if(!e.ts.isQualifiedName(d))continue;let u=l.typeExpression;if(!u)continue;let c="";switch(u.type.kind){case e.ts.SyntaxKind.StringKeyword:{c="string";break}case e.ts.SyntaxKind.NumberKeyword:{c="number";break}case e.ts.SyntaxKind.BooleanKeyword:{c="boolean";break}default:continue}let x={name:d.right.text,type:c,isRegistered:!1};r.push(x)}}return r.filter(Sn)}var Fo=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function Oo(e){return typeof e!="string"?!1:!!Fo.some(t=>e.includes(t))}function Rt(e){return typeof e=="string"&&(e=e.trim(),ko.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var ko=[{value:"boolean",text:"boolean"},{value:"color",text:"color (provides a color in hex or rgb)"},{value:"date",text:"date (same format as the Date constructor)"},{value:"email",text:"email"},{value:"file",text:"file (uploads a file and provides a url)"},{value:"list",text:"list (collection of items)"},{value:"longText",text:"longText (multiline text editor)"},{value:"number",text:"number"},{value:"object",text:"object (set of specific names and values)"},{value:"richText",text:"richText (provides value as html)"},{value:"string",text:"string"}];function Lo(e){return/^['"].*['"]$/.test(e)}function _o(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var jo=(e,t,r)=>{let n=new Set;Cn(e,t,r,n);let o=n.delete("true"),i=n.delete("false");(o||i)&&n.add("boolean");let a=Array.from(n.keys()).sort();if(a.length>1&&(a=a.map(s=>s.indexOf("=>")>=0?`(${s})`:s)),!(a.length>20))return a},Bo=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Cn=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Cn(e,t,o,n)});else if(r.isLiteral()){let o=Bo(e,t,r);n.add(o)}};function Sn(e){let t=e?.name;if(typeof t!="string"||t===""||t.startsWith("aria")||t.startsWith("data-"))return!1;if(t.startsWith("on")&&t.length>2){let r=t.charAt(2);if(r.toUpperCase()===r)return!1}return!Vo.has(t.toLowerCase())}var Vo=new Set(["about","accessKey","accessKeyLabel","asChild","autoCapitalize","autoCorrect","autoFocus","autoSave","blur","contentEditable","contextMenu","dangerouslySetInnerHTML","datatype","defaultChecked","defaultValue","dir","draggable","enterKeyHint","focus","form","formAction","formEncType","formMethod","formNoValidate","formTarget","inlist","innerText","inputMode","is","isContentEditable","itemID","itemProp","itemRef","itemScope","itemType","lang","nonce","offsetHeight","offsetLeft","offsetTop","offsetWidth","outerText","prefix","property","radioGroup","rel","resource","results","rev","role","security","slot","spellCheck","suppressContentEditableWarning","suppressHydrationWarning","tabIndex","translate","typeof","unselectable","vocab"].map(e=>e.toLowerCase()));function Q(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=I(e,n);if(o==="name"&&e.ts.isStringLiteral(n.initializer)){t.name=n.initializer.text;continue}if(o==="description"&&e.ts.isStringLiteral(n.initializer)){t.description=n.initializer.text;continue}if(o==="image"&&e.ts.isStringLiteral(n.initializer)){t.image=n.initializer.text;continue}if(o==="inputs"&&e.ts.isArrayLiteralExpression(n.initializer)){let i=Ko(e,n.initializer);ee(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Ye(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function Ko(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push($o(e,n));return r}function $o(e,t){let r=Ye(e,t),n=Wo(r);return n.isRegistered=!0,n}function K(e,t,r){let n=Uo(r);return t=We(e,t,"name",n.name,!1),t=We(e,t,"description",n.description),t=We(e,t,"image",n.image),t=Mo(e,t,n),Yo(e,t)}function Mo(e,t,r){let n=null,o=t.properties.filter(s=>e.ts.isPropertyAssignment(s)&&e.ts.isIdentifier(s.name)),i=o.findIndex(s=>e.ts.isIdentifier(s.name)&&s.name.text==="inputs"),a=[...r.inputs??[]];if(i>-1){if(a.length===0)return We(e,t,"inputs",null);let s=o[i];e.ts.isPropertyAssignment(s)&&e.ts.isArrayLiteralExpression(s.initializer)&&(n=s.initializer)}return a.length===0?t:(n=qo(e,n||e.ts.factory.createArrayLiteralExpression(),a),i>-1?o[i]=e.ts.factory.updatePropertyAssignment(o[i],o[i].name,n):o.push(e.ts.factory.createPropertyAssignment("inputs",n)),e.ts.factory.updateObjectLiteralExpression(t,o))}function Uo(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(zo)}}function zo(e){let t={name:e.name,type:e.type};return(q(e.defaultValue)||Je(e.defaultValue)||ke(e.defaultValue))&&(t.defaultValue=e.defaultValue),q(e.friendlyName)&&(t.friendlyName=e.friendlyName),q(e.helperText)&&(t.helperText=e.helperText),e.required===!0&&(t.required=!0),Array.isArray(e.enum)&&(t.enum=e.enum),e.hideFromUI===!0&&(t.hideFromUI=!0),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(t.meta=e.meta),t}function qo(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>I(e,s)==="name");if(!i)return!1;let a=i.initializer;return e.ts.isStringLiteral(a)?r.some(s=>s.name===a.text):!1});for(let o of r)n=Jo(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>I(e,c)==="name"),s=i.properties.find(c=>I(e,c)==="name"),p=a?.initializer,l=s?.initializer,d=p&&e.ts.isStringLiteral(p)?p.text:"zz",u=l&&e.ts.isStringLiteral(l)?l.text:"zz";return d.toLowerCase().localeCompare(u.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Jo(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=I(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=Pn(e,t[n],r);else{let o=Pn(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Pn(e,t,r){let n=t.properties.filter(i=>e.ts.isPropertyAssignment(i)),o=Object.keys(r).filter(i=>i!=="isRegistered");for(let i of o)n=Qo(e,n,r,i);return n=Go(e,n.filter(i=>{let a=I(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Qo(e,t,r,n){let o=t.findIndex(i=>e.ts.isIdentifier(i.name)&&i.name.text===n);return o>-1?t[o]=e.ts.factory.updatePropertyAssignment(t[o],t[o].name,Qe(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,Qe(e,r[n]))),t}function ee(e,t){for(let r of t){let n=e.inputs.findIndex(o=>o.name===r.name);n>-1?(r.isRegistered||!e.inputs[n].isRegistered)&&(e.inputs[n]=r):e.inputs.push(r)}e.acceptsChildren=Nt(e)}function Wo(e){let t=Rt(e.type),r={name:e.name.trim(),type:t.builderType};return q(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(q(e.defaultValue)||Je(e.defaultValue)||ke(e.defaultValue))&&(r.defaultValue=e.defaultValue),q(e.helperText)&&(r.helperText=e.helperText),ke(e.required)&&(r.required=e.required),typeof e.meta=="object"&&e.meta!=null&&Object.keys(e.meta).length>0&&(r.meta=e.meta),Array.isArray(e.enum)&&e.enum.length>0&&(r.enum=e.enum),e.hideFromUI===!0&&(r.hideFromUI=!0),At(r)}function Nt(e){let t=e.inputs.some(n=>n.name==="children"),r=e.inputs.some(n=>n.meta?.ts==="ReactNode");return!!(t||r||e.acceptsChildren===!0)}function At(e){if(e.name==="children"&&(e.hideFromUI=!0,delete e.required),e.type==="object"&&e.defaultValue==null&&(e.hideFromUI=!0),e.type==="list"&&e.defaultValue==null&&(e.hideFromUI=!0),e.meta){let t=e.meta.ts;typeof t=="string"&&(t=t.trim(),t.endsWith("ReactNode")&&(t="ReactNode"),e.meta.ts=t,t==="ReactNode"&&(e.hideFromUI=!0))}return e}function Yo(e,t){let r=[...t.properties].sort((n,o)=>{let i=I(e,n)||"zz",a=I(e,o)||"zz";if(i==="inputs")return 1;let s=En.indexOf(i),p=En.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var En=["component","name","description"];function Go(e,t){return[...t].sort((n,o)=>{let i=I(e,n)||"zz",a=I(e,o)||"zz",s=Tn.indexOf(i),p=Tn.indexOf(a);return s>-1?p>-1&&s>p?1:-1:p>-1?s>-1&&p<s?-1:1:i.localeCompare(a)})}var Tn=["name","type"];function _e(e,t){for(let r of t.properties){if(!e.ts.isPropertyAssignment(r)||!e.ts.isIdentifier(r.name))continue;if(I(e,r)==="canHaveChildren"){let{initializer:o}=r;return o.kind===e.ts.SyntaxKind.TrueKeyword}}return!1}function Dn(e,t){let r=`Builder.registerComponent(
|
|
12
12
|
`;if(e.appDir)t.acceptsChildren?r+=` withChildren(${t.importName}),
|
|
13
13
|
`:r+=` ${t.importName},
|
|
14
|
-
`;else{let o=
|
|
14
|
+
`;else{let o=t.externalImportPath?t.externalImportPath:R(e,e.registryPath,t.filePath);t.exportName==="default"?t.acceptsChildren?r+=` withChildren(dynamic(() => import(${JSON.stringify(o)}))),
|
|
15
15
|
`:r+=` dynamic(() => import(${JSON.stringify(o)})),
|
|
16
16
|
`:t.acceptsChildren?r+=` withChildren(dynamic(async () => (await import(${JSON.stringify(o)})).${t.exportName})),
|
|
17
17
|
`:r+=` dynamic(async () => (await import(${JSON.stringify(o)})).${t.exportName}),
|
|
18
18
|
`}r+=` {
|
|
19
19
|
name: "${t.name}",
|
|
20
20
|
}
|
|
21
|
-
`,r+=");";let n=
|
|
22
|
-
`,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let p=Je.get(a);if(p)return E(e,p.content)}let s=e.readFileSync(a);if(s==null){let p=e.basename(a),l=e.extname(p).toLowerCase();if(a.startsWith(n)&&l===".ts"&&(s=Pn.get(p),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new pt(p)}return a.includes("node_modules")&&(s?Je.set(a,{exists:!0,content:s}):Je.set(a,{exists:!1})),E(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return Vo(e,i,t)}catch(a){if(a instanceof pt){await $o(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Vo(e,t,r){let n={rootNames:[...r],options:{},host:t},o=e.ts.findConfigFile(e.dirname(r[0]),i=>e.existsSync(i));if(o){let i=Sn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let p=e.readFileSync(s);return typeof p=="string"?p:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(p,l)=>e.readdirSync(p),fileExists:p=>e.existsSync(p),readFile:p=>e.readFileSync(p)||void 0},e.dirname(o),void 0,o).options,Sn.set(o,i))}i&&(n.options=J(i))}return n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function Oe(e,t,r){r||(r=await $(e,[t]));let n=r.getSourceFile(t);if(!n)throw new Error(`getTypeChecker() Could not find source file: ${t}`);return{typeChecker:r.getTypeChecker(),sourceFile:n}}var pt=class{constructor(t){this.libName=t}};async function $o(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;st.has(t)||st.set(t,fetch(r).then(n=>n.text()).then(n=>{Pn.set(t,n)})),await st.get(t),st.delete(t)}var Pn=new Map,st=new Map,Je=new Map,Sn=new Map;function D(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Ko(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=Mo(e,t,r.defaultImport,r.importPath,n)),t}function Ko(e,t,r,n,o,i){return i==="cjs"?Tn(e,t,null,r,n):yn(e,t,null,r,n,o)}function Mo(e,t,r,n,o){return o==="cjs"?Tn(e,t,r,null,n):yn(e,t,r,null,n,!1)}function yn(e,t,r,n,o,i){let a=[...t.statements],s=0,p=!1,l=!1;for(let u=0;u<a.length;u++){let h=a[u];if(!e.ts.isImportDeclaration(h)||(s=u,!h.moduleSpecifier||!e.ts.isStringLiteral(h.moduleSpecifier))||h.moduleSpecifier.text!==o||!!h.importClause?.isTypeOnly!==i)continue;let m=[],g=h.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&m.push(...g.elements),typeof n=="string"){if(m.some(C=>C.name.text===n))return t;m.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),m.sort((C,P)=>C.name.text.localeCompare(P.name.text)),p=!0}let x=h.importClause?h.importClause.name:void 0;if(typeof r=="string"){if(x&&x.text===r)return t;x=e.ts.factory.createIdentifier(r),l=!0}if(p||l)return a[u]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,x,e.ts.factory.createNamedImports(m)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,f;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(f=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let c=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,f),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function Tn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let p=i[s];if(e.ts.isVariableStatement(p))for(let l=0;l<p.declarationList.declarations.length;l++){let d=[...p.declarationList.declarations],f=d[l],c=f.initializer;if(!c||!e.ts.isCallExpression(c))continue;let u=c.expression;if(!e.ts.isIdentifier(u)||u.text!=="require"||c.arguments.length!==1)continue;let h=c.arguments[0];if(e.ts.isStringLiteral(h)&&(a=s,h.text===o)){if(e.ts.isIdentifier(f.name)&&typeof r=="string")return f.name.text===r?t:(d[l]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createIdentifier(r),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(f.name)&&typeof n=="string"){let m=[...f.name.elements];return m.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(m.push(e.ts.factory.createBindingElement(void 0,void 0,n)),m.sort((x,C)=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:x.name.text.localeCompare(C.name.text)),d[l]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createObjectBindingPattern(m),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function G(e,t,r="esm"){return r==="cjs"?zo(e,t):Uo(e,t)}function Uo(e,t){let r=[];for(let n of t.statements){if(e.ts.isExportDeclaration(n)){if(n.exportClause&&e.ts.isNamedExports(n.exportClause)){for(let o of n.exportClause.elements)if(n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:o}),e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function zo(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s});else e.ts.isFunctionDeclaration(s)&&s.name&&s.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s})}else r.push({isDefaultExport:!0,statement:n,node:i});continue}}return r}function qo(e,t,r){for(let n of t.statements)if(e.ts.isImportDeclaration(n)&&n.importClause){if(n.importClause.namedBindings&&e.ts.isNamedImports(n.importClause.namedBindings)){for(let o of n.importClause.namedBindings.elements)if(e.ts.isIdentifier(o.name)&&o.name.text===r&&e.ts.isStringLiteral(n.moduleSpecifier))return{importPath:n.moduleSpecifier.text,exportType:"named"}}if(n.importClause.name&&n.importClause.name.text===r&&e.ts.isStringLiteral(n.moduleSpecifier))return{importPath:n.moduleSpecifier.text,exportType:"default"}}return null}async function Pe(e,t,r,n){let o=qo(e,r,n);if(o){let i=await We(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:A(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function Le(e,t,r){for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(e.ts.isVariableStatement(o)){for(let i of o.declarationList.declarations)if(e.ts.isIdentifier(i.name)&&i.name.text===r)return{statement:o,statementIndex:n}}}return null}function M(e,t,r){let n=Le(e,t,r);if(n&&n.statement.declarationList.declarations.length>0){let o=n.statement.declarationList.declarations[0];if(o.initializer&&e.ts.isArrayLiteralExpression(o.initializer))return{statement:n.statement,statementIndex:n.statementIndex,variableDeclaration:o,arrayLiteralExp:o.initializer}}return null}function lt(e,t){if(t){if(Qo(e,t))return!0;let r=!1;if(t.forEachChild(n=>{lt(e,n)&&(r=!0)}),r)return!0}return!1}function Qo(e,t){return e.ts.isJsxElement(t)||e.ts.isJsxOpeningElement(t)||e.ts.isJsxOpeningFragment(t)||e.ts.isJsxSelfClosingElement(t)||e.ts.isJsxFragment(t)||e.ts.isJsxChild(t)}async function We(e,t){let r=e.extname(t).toLowerCase();if(r===""||!vt.includes(r)){for(let n of vt){let o=t+n;if(await e.exists(o))return o}for(let n of vt){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var vt=[".tsx",".jsx",".ts",".js"];function Ye(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=Jo(e,i);return a?[{name:a}]:void 0}function Jo(e,t){if(typeof t=="string"){t=e.normalize(X(t));let r=t.split("/"),n=r.lastIndexOf("node_modules");if(n>-1){let o=r.slice(n+1),i=o[0];if(i)return i.startsWith("@")&&o[1]&&(i+="/"+o[1]),i}}}function ie(e){let t=[];for(let r of e)if(r.dependencies)for(let n of r.dependencies)t.some(o=>o.name===n.name)||t.push({...n});return t.sort((r,n)=>r.name.localeCompare(n.name))}async function ke(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await $(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{let s=n.getSourceFile(a.filePath);if(s){let l=(await ye(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=be(e,o,l.node.fnNode))}return a}))}async function _e(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Oe(e,t.cmpInfo.filePath,r),a=(await ye(e,o,t.cmpInfo.filePath,n)).find(s=>s.cmpInfo.id===t.cmpInfo.id);if(!a)throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return be(e,o,a.node.fnNode)}return[]}async function Dn(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return Wo(e,t,n)}return null}function Wo(e,t,r){let n=E(e,r);return ye(e,null,t,n)}async function ye(e,t,r,n){let o=[];for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isStringLiteral(a.expression)&&a.expression.text==="use server")return o;let i=G(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await Yo(e,t,r,a);o.push(...s)})),o}async function Yo(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=k(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Ue(s.name.text))continue;let p=Ge(e,t,s.initializer);if(p){let l=p.name||s.name.text,d=n.isDefaultExport?"default":l,f=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:j(l),inputs:[],exportName:d,exportType:f,importName:l,filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}}return o}if(e.ts.isArrowFunction(n.node)){let s=Ge(e,t,n.node);if(s){let p=Y(e,r),l=n.isDefaultExport?"default":p,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:A(e,r),name:p,inputs:[],exportName:l,exportType:d,importName:Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let s=n.node.name?.text;if(s&&!Ue(s))return o;let p=Ge(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,f=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:f,importName:p.name||Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}return o}if(e.ts.isExportSpecifier(n.node)&&Ue(n.node.getText())){let s=Ge(e,t,n.node);if(s){let p=s.name||Y(e,r),l=n.isDefaultExport||!s.name?"default":s.name,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:A(e,r),name:p,inputs:[],exportName:l,exportType:d,importName:s.name||Ae(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function Ge(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return lt(e,r.body)?{name:"",fnNode:r,deps:Ye(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return lt(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Ye(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:Ge(e,t,o[0])}if(!t)return null;if(e.ts.isPropertyAccessExpression(r)){let n=r.expression,o=r.name;if(!e.ts.isIdentifier(n)||!e.ts.isIdentifier(o)||!Ue(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Ye(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Ye(e,t,n)}}return null}async function En(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.normalize(i.fileName);if(Ho(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await ye(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Go=new Set(["node_modules","dist"]);function Ho(e,t){for(let r of Go)if(e.dirname(t).includes(r))return!0;return!1}async function wn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(e.appDir&&Xo.has(a)||e.dirname(i.fileName).includes("node_modules"))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let p=await ye(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Xo=new Set(["default.tsx","default.ts","default.jsx","default.js","error.tsx","error.ts","error.jsx","error.js","layout.tsx","layout.ts","layout.jsx","layout.js","loading.tsx","loading.ts","loading.jsx","loading.js","not-found.tsx","not-found.ts","not-found.jsx","not-found.js","page.tsx","page.ts","page.jsx","page.js","route.tsx","route.ts","route.jsx","route.js","template.tsx","template.ts","template.jsx","template.js"]);function ae(e,t){let r=[],n=[],o=[],i=[];for(let a of t.statements){if(e.ts.isImportDeclaration(a)){if(e.ts.isStringLiteral(a.moduleSpecifier)){let p=a.moduleSpecifier.text;if(!p.startsWith(".")&&!p.startsWith("/")){r.push(a);continue}}let s=a.importClause;if(s){if(s.namedBindings){n.push(a);continue}if(s.name){n.push(a);continue}}o.push(a);continue}i.push(a)}return e.ts.factory.updateSourceFile(t,[...bt(e,r),...bt(e,n),...bt(e,o),...i])}function H(e){let t=e.split(`
|
|
21
|
+
`,r+=");";let n=lt(e,r);return Ft(e,n,t)}function Ft(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;r.acceptsChildren?e.ts.isCallExpression(o[0])&&e.ts.isIdentifier(o[0].expression)&&o[0].expression.text==="withChildren"||(o[0]=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("withChildren"),void 0,[o[0]])):e.ts.isCallExpression(o[0])&&e.ts.isIdentifier(o[0].expression)&&o[0].expression.text==="withChildren"&&(o[0]=o[0].arguments[0]);let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=K(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function M(e,t){if(!Array.isArray(t)||t.length===0)throw new Error(`createTsProgram() Invalid filePaths: ${t}`);let r=await un(e,t[0]),n=e.join(r,"typescript","lib"),o=new Map,i={fileExists:a=>{if(a=e.normalize(a),a.includes("node_modules")){let s=Ge.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}Ge.set(a,s)}return s.exists}return o.has(a)||o.set(a,e.existsSync(a)),o.get(a)},getCanonicalFileName:a=>e.normalize(a),getCurrentDirectory:()=>e.cwd(),getDefaultLibFileName:()=>e.join(n,"lib.d.ts"),getDefaultLibLocation:()=>n,getNewLine:()=>`
|
|
22
|
+
`,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let p=Ge.get(a);if(p)return v(e,p.content)}let s=e.readFileSync(a);if(s==null){let p=e.basename(a),l=e.extname(p).toLowerCase();if(a.startsWith(n)&&l===".ts"&&(s=wn.get(p),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new ut(p)}return a.includes("node_modules")&&(s?Ge.set(a,{exists:!0,content:s}):Ge.set(a,{exists:!1})),v(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return Ho(e,i,t)}catch(a){if(a instanceof ut){await Xo(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Ho(e,t,r){let n={rootNames:[...r],options:{},host:t},o=e.ts.findConfigFile(e.dirname(r[0]),i=>e.existsSync(i));if(o){let i=yn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let p=e.readFileSync(s);return typeof p=="string"?p:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(p,l)=>e.readdirSync(p),fileExists:p=>e.existsSync(p),readFile:p=>e.readFileSync(p)||void 0},e.dirname(o),void 0,o).options,yn.set(o,i))}i&&(n.options=W(i))}return n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function je(e,t,r){r||(r=await M(e,[t]));let n=r.getSourceFile(t);if(!n)throw new Error(`getTypeChecker() Could not find source file: ${t}`);return{typeChecker:r.getTypeChecker(),sourceFile:n}}var ut=class{constructor(t){this.libName=t}};async function Xo(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;mt.has(t)||mt.set(t,fetch(r).then(n=>n.text()).then(n=>{wn.set(t,n)})),await mt.get(t),mt.delete(t)}var wn=new Map,mt=new Map,Ge=new Map,yn=new Map;function w(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Zo(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=ei(e,t,r.defaultImport,r.importPath,n)),t}function Zo(e,t,r,n,o,i){return i==="cjs"?In(e,t,null,r,n):vn(e,t,null,r,n,o)}function ei(e,t,r,n,o){return o==="cjs"?In(e,t,r,null,n):vn(e,t,r,null,n,!1)}function vn(e,t,r,n,o,i){let a=[...t.statements],s=0,p=!1,l=!1;for(let m=0;m<a.length;m++){let x=a[m];if(!e.ts.isImportDeclaration(x)||(s=m,!x.moduleSpecifier||!e.ts.isStringLiteral(x.moduleSpecifier))||x.moduleSpecifier.text!==o||!!x.importClause?.isTypeOnly!==i)continue;let f=[],g=x.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&f.push(...g.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,P)=>C.name.text.localeCompare(P.name.text)),p=!0}let h=x.importClause?x.importClause.name:void 0;if(typeof r=="string"){if(h&&h.text===r)return t;h=e.ts.factory.createIdentifier(r),l=!0}if(p||l)return a[m]=e.ts.factory.updateImportDeclaration(x,void 0,e.ts.factory.createImportClause(i,h,e.ts.factory.createNamedImports(f)),x.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,u;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(u=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let c=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,u),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function In(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let p=i[s];if(e.ts.isVariableStatement(p))for(let l=0;l<p.declarationList.declarations.length;l++){let d=[...p.declarationList.declarations],u=d[l],c=u.initializer;if(!c||!e.ts.isCallExpression(c))continue;let m=c.expression;if(!e.ts.isIdentifier(m)||m.text!=="require"||c.arguments.length!==1)continue;let x=c.arguments[0];if(e.ts.isStringLiteral(x)&&(a=s,x.text===o)){if(e.ts.isIdentifier(u.name)&&typeof r=="string")return u.name.text===r?t:(d[l]=e.ts.factory.updateVariableDeclaration(u,e.ts.factory.createIdentifier(r),u.exclamationToken,u.type,u.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(u.name)&&typeof n=="string"){let f=[...u.name.elements];return f.some(h=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)?!1:h.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((h,C)=>!e.ts.isBindingElement(h)||!e.ts.isIdentifier(h.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:h.name.text.localeCompare(C.name.text)),d[l]=e.ts.factory.updateVariableDeclaration(u,e.ts.factory.createObjectBindingPattern(f),u.exclamationToken,u.type,u.initializer),i[s]=e.ts.factory.updateVariableStatement(p,p.modifiers,e.ts.factory.updateVariableDeclarationList(p.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function G(e,t,r="esm"){return r==="cjs"?ni(e,t):ti(e,t)}function ti(e,t){let r=[];for(let n of t.statements){if(e.ts.isExportDeclaration(n)){if(n.exportClause&&e.ts.isNamedExports(n.exportClause)){for(let o of n.exportClause.elements)if(n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:o}),e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}else!n.exportClause&&n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:n});continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function ni(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let p of s.declarationList.declarations)e.ts.isIdentifier(p.name)&&p.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s});else e.ts.isFunctionDeclaration(s)&&s.name&&s.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s})}else r.push({isDefaultExport:!0,statement:n,node:i});continue}}return r}function ri(e,t,r){for(let n of t.statements)if(e.ts.isImportDeclaration(n)&&n.importClause){if(n.importClause.namedBindings&&e.ts.isNamedImports(n.importClause.namedBindings)){for(let o of n.importClause.namedBindings.elements)if(e.ts.isIdentifier(o.name)&&o.name.text===r&&e.ts.isStringLiteral(n.moduleSpecifier))return{importPath:n.moduleSpecifier.text,exportType:"named"}}if(n.importClause.name&&n.importClause.name.text===r&&e.ts.isStringLiteral(n.moduleSpecifier))return{importPath:n.moduleSpecifier.text,exportType:"default"}}return null}async function ae(e,t,r,n){let o=ri(e,r,n);if(o){let i=await He(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:A(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function Be(e,t,r){for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(e.ts.isVariableStatement(o)){for(let i of o.declarationList.declarations)if(e.ts.isIdentifier(i.name)&&i.name.text===r)return{statement:o,statementIndex:n}}}return null}function V(e,t,r){let n=Be(e,t,r);if(n&&n.statement.declarationList.declarations.length>0){let o=n.statement.declarationList.declarations[0];if(o.initializer&&e.ts.isArrayLiteralExpression(o.initializer))return{statement:n.statement,statementIndex:n.statementIndex,variableDeclaration:o,arrayLiteralExp:o.initializer}}return null}function ft(e,t){if(t){if(oi(e,t))return!0;let r=!1;if(t.forEachChild(n=>{ft(e,n)&&(r=!0)}),r)return!0}return!1}function oi(e,t){return e.ts.isJsxElement(t)||e.ts.isJsxOpeningElement(t)||e.ts.isJsxOpeningFragment(t)||e.ts.isJsxSelfClosingElement(t)||e.ts.isJsxFragment(t)||e.ts.isJsxChild(t)}async function He(e,t){let r=e.extname(t).toLowerCase();if(r===""||!Ot.includes(r)){for(let n of Ot){let o=t+n;if(await e.exists(o))return o}for(let n of Ot){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var Ot=[".tsx",".jsx",".ts",".js"];function Xe(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=ii(e,i);return a?[{name:a}]:void 0}function ii(e,t){if(typeof t=="string"){t=e.normalize(Z(t));let r=t.split("/"),n=r.lastIndexOf("node_modules");if(n>-1){let o=r.slice(n+1),i=o[0];if(i)return i.startsWith("@")&&o[1]&&(i+="/"+o[1]),i}}}function se(e){let t=[];for(let r of e)if(r.dependencies)for(let n of r.dependencies)t.some(o=>o.name===n.name)||t.push({...n});return t.sort((r,n)=>r.name.localeCompare(n.name))}async function Ve(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await M(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{let s=n.getSourceFile(a.filePath);if(s){let l=(await ye(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=Ne(e,o,l.node.fnNode))}return a}))}async function Ke(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await je(e,t.cmpInfo.filePath,r),a=(await ye(e,o,t.cmpInfo.filePath,n)).find(s=>s.cmpInfo.id===t.cmpInfo.id);if(!a)throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return Ne(e,o,a.node.fnNode)}return[]}async function Rn(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return ai(e,t,n)}return null}function ai(e,t,r){let n=v(e,r);return ye(e,null,t,n)}async function ye(e,t,r,n){let o=[];for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isStringLiteral(a.expression)&&a.expression.text==="use server")return o;let i=G(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await si(e,t,r,a);o.push(...s)})),o}async function si(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=L(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Le(s.name.text))continue;let p=De(e,t,s.initializer);if(p){let l=p.name||s.name.text,d=n.isDefaultExport?"default":l,u=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:j(l),inputs:[],exportName:d,exportType:u,importName:l,filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}}return o}if(e.ts.isArrowFunction(n.node)){let s=De(e,t,n.node);if(s){let p=Y(e,r),l=n.isDefaultExport?"default":p,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:A(e,r),name:p,inputs:[],exportName:l,exportType:d,importName:Re(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let s=n.node.name?.text;if(s&&!Le(s))return o;let p=De(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,u=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:u,importName:p.name||Re(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:p.deps},node:p})}return o}if(e.ts.isExportSpecifier(n.node)&&Le(n.node.getText())){let s,p=De(e,t,n.node);if(p){let l=p.name||Y(e,r),d=n.isDefaultExport||!p.name?"default":p.name,u=n.isDefaultExport?"default":"named",m=n.node.parent.parent.moduleSpecifier;if(m&&e.ts.isStringLiteral(m)){let x=t?.getSymbolAtLocation(m);if(x&&x.declarations&&x.declarations.length>0){let f=x.declarations[0];(!e.ts.isSourceFile(f)||e.ts.isSourceFile(f)&&f.fileName.includes("node_modules"))&&(s=m.text)}}o.push({cmpInfo:{id:await _(e,r,d,s),displayFilePath:A(e,r),name:l,inputs:[],exportName:d,exportType:u,importName:p.name||Re(e,r),filePath:r,relFilePath:i,importPath:s||a,externalImportPath:s,dependencies:p.deps},node:p})}return o}if(e.ts.isExportDeclaration(n.node)&&n.node.exportClause===void 0){let s=n.node.moduleSpecifier;if(s&&e.ts.isStringLiteral(s)){let p=await li(e,t,r,s);o.push(...p)}return o}return o}function De(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return ft(e,r.body)?{name:"",fnNode:r,deps:Xe(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return ft(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Xe(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:De(e,t,o[0])}if(!t)return null;if(e.ts.isPropertyAccessExpression(r)){let n=r.expression,o=r.name;if(!e.ts.isIdentifier(n)||!e.ts.isIdentifier(o)||!Le(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Xe(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:Xe(e,t,n)}}if(e.ts.isExpressionStatement(r)){let n=r.expression;if(e.ts.isAsExpression(n)&&e.ts.isIdentifier(n.type)&&n.type.text==="default")return De(e,t,n.expression)}if(e.ts.isVariableStatement(r)){for(let n of r.declarationList.declarations)if(n.initializer&&e.ts.isAsExpression(n.initializer)){let o=n.initializer;if(e.ts.isIdentifier(o.type)&&o.type.text==="default"){let i=De(e,t,o.expression);if(i&&e.ts.isIdentifier(n.name))return{name:n.name.text,fnNode:i.fnNode,deps:i.deps}}}}return null}async function Nn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.normalize(i.fileName);if(ct(e,pi,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await ye(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var pi=new Set(["node_modules","dist"]);async function li(e,t,r,n){let o=[],i=n.text;if(!t)return o;try{let a=t.getSymbolAtLocation(n);if(!a)return o;let s=t.getExportsOfModule(a);for(let p of s){let l=p.valueDeclaration||p.declarations?.[0];if(!l)continue;let d=p.name;if(!Le(d)&&d!=="default"||!An(e,t,l))continue;let u=De(e,t,l);if(u){let c=p.name,m=c==="default"?"default":"named",x=j(c),f=c==="default"?Re(e,r):c;o.push({cmpInfo:{id:await _(e,r,c,i),displayFilePath:A(e,r),name:x,inputs:[],exportName:c,exportType:m,importName:f,filePath:r,relFilePath:e.relative(e.getRootDir(),r),importPath:i,externalImportPath:i,dependencies:u.deps},node:u})}}}catch(a){console.error(`Error processing module ${i}:`,a)}return o}function An(e,t,r){if(e.ts.isInterfaceDeclaration(r)||e.ts.isTypeAliasDeclaration(r))return!1;if(e.ts.isExportSpecifier(r)){let n=t.getSymbolAtLocation(r.name);if(n){let i=t.getAliasedSymbol(n).declarations?.[0];if(i)return An(e,t,i)}return!1}if(e.ts.isFunctionDeclaration(r)||e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r)){let n=t.getSignatureFromDeclaration(r);if(n){let o=t.getReturnTypeOfSignature(n);return bn(o,t)}}return e.ts.isClassDeclaration(r)?r.heritageClauses?.some(o=>o.types.some(i=>i.expression.getText()==="React.Component"||i.expression.getText()==="Component"))??!1:e.ts.isVariableDeclaration(r)?t.getTypeAtLocation(r).getCallSignatures().some(i=>bn(t.getReturnTypeOfSignature(i),t)):!1}function bn(e,t){let r=t.typeToString(e);return r==="JSX.Element"||r==="Element"||r.includes("ReactElement")||r.includes("React.ReactElement")||r.includes("ReactNode")}async function Fn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(e.appDir&&ci.has(a)||e.dirname(i.fileName).includes("node_modules"))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let p=await ye(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var ci=new Set(["default.tsx","default.ts","default.jsx","default.js","error.tsx","error.ts","error.jsx","error.js","layout.tsx","layout.ts","layout.jsx","layout.js","loading.tsx","loading.ts","loading.jsx","loading.js","not-found.tsx","not-found.ts","not-found.jsx","not-found.js","page.tsx","page.ts","page.jsx","page.js","route.tsx","route.ts","route.jsx","route.js","template.tsx","template.ts","template.jsx","template.js"]);function pe(e,t){let r=[],n=[],o=[],i=[];for(let a of t.statements){if(e.ts.isImportDeclaration(a)){if(e.ts.isStringLiteral(a.moduleSpecifier)){let p=a.moduleSpecifier.text;if(!p.startsWith(".")&&!p.startsWith("/")){r.push(a);continue}}let s=a.importClause;if(s){if(s.namedBindings){n.push(a);continue}if(s.name){n.push(a);continue}}o.push(a);continue}i.push(a)}return e.ts.factory.updateSourceFile(t,[...kt(e,r),...kt(e,n),...kt(e,o),...i])}function H(e){let t=e.split(`
|
|
23
23
|
`).map(n=>n.trimEnd());e="";let r=!1;for(let n=t.length-1;n>=0;n--){let o=t[n];!r&&o.startsWith("import ")&&(r=!0,o=o+`
|
|
24
24
|
`),/^builder.init(.*)$/.test(o)&&(o=o+`
|
|
25
25
|
`),t[n-1]&&!t[n-1].includes("*/")&&(o.trim().startsWith("Builder.registerComponent")&&(o=`
|
|
@@ -28,23 +28,23 @@ ${r}=${n}
|
|
|
28
28
|
`+o),o.trim().startsWith("export ")&&(o=`
|
|
29
29
|
`+o)),e=o+`
|
|
30
30
|
`+e}return e.trim()+`
|
|
31
|
-
`}function
|
|
32
|
-
${e}`),e}function Rn(e,t){let r=t.statements.filter(n=>!(e.ts.isExpressionStatement(n)&&e.ts.isStringLiteral(n.expression)&&e.ts.isStringLiteral(n.expression)&&n.expression.text==="use client"));return e.ts.factory.updateSourceFile(t,r)}function Te(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=bn(e,r),i=bn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function bn(e,t){let r=t.properties.find(n=>b(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function Nn(e){let t=await e.readFile(e.registryPath);return t?Zo(e,t):{components:[],sourceFile:E(e,"")}}async function Zo(e,t){let r=E(e,t);return e.sdkVersion===O.gen2?ti(e,r):ei(e,r)}async function ei(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let l=i.arguments;if(l.length<2)continue;let d=l[1];if(!e.ts.isObjectLiteralExpression(d))continue;let f=l[0];if(e.ts.isCallExpression(f)){let c=e.ts.isIdentifier(f.expression)&&f.expression.text;if(c==="withChildren"){let h=Nt(e,f.arguments[0]);if(e.ts.isCallExpression(h)){let m=await It(e,n,h,d,!0);m&&r.push(m)}else{let m=h;if(e.ts.isIdentifier(m)){let g=await Rt(e,t,n,m,d,!0);g&&r.push(g)}}continue}if(c==="dynamic"){let h=await It(e,n,f,d,!1);h&&r.push(h);continue}let u=Nt(e,f.arguments[0]);if(e.ts.isCallExpression(u)&&e.ts.isIdentifier(u.expression)&&u.expression.text==="dynamic"){let h=await It(e,n,u,d,!1);h&&r.push(h);continue}if(e.ts.isIdentifier(u)){let h=await Rt(e,t,n,u,d,!1);h&&r.push(h);continue}continue}if(e.ts.isIdentifier(f)){let c=await Rt(e,t,n,f,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:Q(r)}}function Nt(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:Nt(e,t.arguments[0]):t}async function It(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let p=s.body;if(e.ts.isCallExpression(p)){if(p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let d=p.arguments[0];if(!e.ts.isStringLiteral(d))return null;let f=d.text;i.filePath=await je(e,f),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=k(e,i.filePath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(p)){let l=p.expression;if(!e.ts.isParenthesizedExpression(l))return null;let d=l.expression;if(!e.ts.isAwaitExpression(d))return null;let f=d.expression;if(!e.ts.isCallExpression(f)||f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let u=f.arguments[0];if(!e.ts.isStringLiteral(u)||!e.ts.isIdentifier(p.name))return null;let h=u.text;i.filePath=await je(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=k(e,i.filePath),i.name=j(p.name.text),i.importName=p.name.text,i.exportName=p.name.text,i.exportType="named"}else return null;return i=W(e,i,n),i.displayFilePath=A(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName)),i}async function Rt(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(l=>e.ts.isImportDeclaration(l)),p=s.find(l=>l.importClause&&l.importClause.name?.text===n.text);if(p){let l=p.moduleSpecifier;if(!e.ts.isStringLiteral(l))return null;a.filePath=await je(e,l.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(f=>!f.importClause||!f.importClause.namedBindings||!e.ts.isNamedImports(f.importClause.namedBindings)?!1:f.importClause.namedBindings.elements.some(c=>c.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await je(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=k(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=W(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName)),a}function je(e,t){return We(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function An(e,t,r){let n=!1,o=0,i=[...t.statements];for(let l=0;l<i.length;l++){let d=i[l];if(e.ts.isImportDeclaration(d)){o=l;continue}if(!e.ts.isExpressionStatement(d))continue;let f=d.expression;if(!e.ts.isCallExpression(f))continue;let c=f.expression;if(!e.ts.isPropertyAccessExpression(c))continue;let u=c.expression;if(!e.ts.isIdentifier(u)||u.text!=="builder")continue;if(c.name.text=="init"){n=!0;break}else continue}if(n)return t;let a=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("process"),e.ts.factory.createIdentifier("env")),e.ts.factory.createIdentifier(oe)),s=r?e.ts.factory.createNonNullExpression(a):a,p=e.ts.factory.createExpressionStatement(e.ts.factory.createCallExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("builder"),e.ts.factory.createIdentifier("init")),void 0,[s]));return i.splice(o+1,0,p),e.ts.factory.updateSourceFile(t,i)}async function ti(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await At(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function At(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};ni(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(b(e,i)==="component"){let s,{initializer:p}=i;if(e.ts.isCallExpression(p)&&(e.ts.isIdentifier(p.expression)&&p.expression.text)==="dynamic"){let u=p.arguments;if(u.length===0)return null;let h=u[0];if(!e.ts.isArrowFunction(h))return null;let m=h.body;if(e.ts.isCallExpression(m)){if(m.expression.kind!==e.ts.SyntaxKind.ImportKeyword||m.arguments.length!==1)return null;let x=m.arguments[0];if(!e.ts.isStringLiteral(x))return null;let C=x.text;n.filePath=await je(e,C),n.relFilePath=e.relative(e.getRootDir(),n.filePath),n.importPath=k(e,n.filePath),n.name=Y(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(m)){let g=m.expression;if(!e.ts.isParenthesizedExpression(g))return null;let x=g.expression;if(!e.ts.isAwaitExpression(x))return null;let C=x.expression;if(!e.ts.isCallExpression(C)||C.expression.kind!==e.ts.SyntaxKind.ImportKeyword||C.arguments.length!==1)return null;let I=C.arguments[0];if(!e.ts.isStringLiteral(I)||!e.ts.isIdentifier(m.name))return null;let T=I.text;n.filePath=await je(e,T),n.relFilePath=e.relative(e.getRootDir(),n.filePath),n.importPath=k(e,n.filePath),n.name=j(m.name.text),n.importName=m.name.text,n.exportName=m.name.text,n.exportType="named"}else return null;return n=W(e,n,r),n.displayFilePath=A(e,n.filePath),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await Pe(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=k(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),f=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(f){let c=f.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(h=>!h.importClause||!h.importClause.namedBindings||!e.ts.isNamedImports(h.importClause.namedBindings)?!1:h.importClause.namedBindings.elements.some(m=>m.name.text===s));if(!c)return null;let u=c.moduleSpecifier;if(!e.ts.isStringLiteral(u))return null;n.exportName=s}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}function ni(e,t){for(let r of t.properties){if(!e.ts.isPropertyAssignment(r)||!e.ts.isIdentifier(r.name))continue;if(b(e,r)==="canHaveChildren"){let{initializer:o}=r;return o.kind===e.ts.SyntaxKind.TrueKeyword}}return!1}function se(e,t){let r=[...t.statements],n=!1;for(let o=t.statements.length-1;o>=0;o--){let i=t.statements[o];if(e.ts.isImportDeclaration(i)&&i.importClause){let a=!1,s=i.importClause.namedBindings;if(s&&e.ts.isNamedImports(s)&&s.elements){let p=[...s.elements];for(let l=p.length-1;l>=0;l--){let d=p[l];if(e.ts.isImportSpecifier(d)){let f=d.name;if(f&&e.ts.isIdentifier(f)){let c=f.text;Fn(e,t,c)||p.splice(l,1)}}}if(p.length===0)a=!0;else if(s.elements.length!==p.length){let l=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(p)),d=e.ts.factory.updateImportDeclaration(i,void 0,l,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let p=i.importClause.name.text;Fn(e,t,p)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Fn(e,t,r){let n=!1;function o(i){if(!e.ts.isImportDeclaration(i)){if(e.ts.isIdentifier(i)&&i.text===r){n=!0;return}e.ts.forEachChild(i,o)}}return e.ts.forEachChild(t,o),n}function pe(e,t,r,n,o,i,a){let s=null,p=null,l=null,d=-1;t=J(t),r=J(r);let f=t.find(u=>u.id===e),c=r.find(u=>u.id===e);if(n)c||(s={...J(f),inputs:J(f.inputs).map(u=>(u.isRegistered=!0,u))},d=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)d=c.nodeIndex,p=J(c),r=r.filter(u=>u.id!==e);else if(i!=null)ri(c,i),d=c.nodeIndex,l=c;else if(a!=null){let u=c.inputs.find(h=>h.name===a.name);u&&(a.registerInput===!1?u.isRegistered=!1:(oi(u,a),u.isRegistered=!0),l=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:p,updateRegisteredCmp:l,nodeIndex:d,components:ee(t,r)}}function ee(e,t){let r=Q([...t.map(n=>(n.isRegistered=!0,n)),...e.filter(n=>!t.some(o=>o.id===n.id)).map(n=>(n.isRegistered=!1,n))]);return r.forEach(n=>{n.inputs=n.inputs.map(Et),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=Dt(n))}),r}function ri(e,t){U(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),U(t.description)?e.description=t.description:t.description===null&&delete e.description,U(t.image)?e.image=t.image:t.image===null&&delete e.image}function oi(e,t){U(t.type)&&(e.type=t.type),U(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,U(t.defaultValue)||Me(t.defaultValue)||Fe(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,U(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function De(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".jsx"||p===".ts"||p===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}function Ee(e,t,r){return Le(e,t,r.variableName)?t:ii(e,t,r)}function ii(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),p=e.ts.factory.createVariableStatement([s],a),l=[...t.statements,p];return e.ts.factory.updateSourceFile(t,l)}async function le(e,t,r,n,o,i,a,s){let p=await De(e),[l,d,f,c]=await Promise.all([wn(e,p),Nn(e),Ft(e),Ke(e)]),u=l.map(P=>P.cmpInfo),h=d.components,m={components:ee(u,h),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(u),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return m.components=await ke(e,m.components),m;let g=!1,x=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let R=l.find(B=>B.cmpInfo.id===S);if(!R)throw new Error(`Component ${S} not found`);return R}),I=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),T=await $(e,I);for(let S of P){let R=m.components.find(w=>w.id===S.cmpInfo.id),B=await _e(e,S,T);Z(R,B);let F=u.findIndex(w=>w.id===S.cmpInfo.id);u[F].inputs=B;let y=pe(S.cmpInfo.id,u,h,r,n,o,i);if(e.sdkVersion===O.gen2){let{elements:w,elmIndex:V,statementIndex:z,statement:q,variableDeclaration:L}=await pi(e,x,S);if(y.addCmpToRegistry)w.push(si(e,y.addCmpToRegistry)),g=!0;else if(y.removeCmpFromRegistry)w.splice(V,1),g=!0;else if(y.updateRegisteredCmp){let fe=K(e,w[V],y.updateRegisteredCmp);w[V]=e.ts.factory.updateObjectLiteralExpression(fe,[Ln(e,y.updateRegisteredCmp),...fe.properties.slice(1)]),g=!0}if(g&&a){let fe=[...x.statements];fe[z]=e.ts.factory.updateVariableStatement(q,q.modifiers,e.ts.factory.updateVariableDeclarationList(q.declarationList,[e.ts.factory.updateVariableDeclaration(L,L.name,L.exclamationToken,L.type,e.ts.factory.createArrayLiteralExpression(Te(e,w)))])),x=e.ts.factory.updateSourceFile(x,fe),x=On(e,y,x),x=D(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),x=Ee(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),m.components=y.components,h=y.components.filter(to=>to.isRegistered)}}else{let w=[...x.statements];y.addCmpToRegistry?(w.push(Cn(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(w.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(w[y.nodeIndex]=wt(e,w[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a&&(x=e.ts.factory.updateSourceFile(x,w),x=D(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=An(e,x,f),x=On(e,y,x),R?.acceptsChildren&&(x=D(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),m.components=y.components,h=y.components.filter(V=>V.isRegistered))}}}if(g&&a){x=se(e,x),x=ae(e,x),e.appDir&&(x=Rn(e,x));let P=N(e,x);P=H(P),e.appDir&&(P=In(P)),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return m}function Ln(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",li(e,t))}function ai(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function si(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([Ln(e,t),...t.acceptsChildren?[ai(e)]:[]],!0),t)}async function pi(e,t,r){let n=M(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await At(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function On(e,t,r){if(e.appDir){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=v(e,e.registryPath,n.filePath);n.exportType==="default"?r=D(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=D(e,r,{namedImports:[n.importName],importPath:o}))}}else r=D(e,r,{defaultImport:"dynamic",importPath:"next/dynamic"});return r}function li(e,t){let r=v(e,e.registryPath,t.filePath),n=t.exportName!=="default",o;n?o=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createAwaitExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)])),e.ts.factory.createIdentifier(t.exportName)):o=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)]);let i=e.ts.factory.createArrowFunction(n?[e.ts.factory.createModifier(e.ts.SyntaxKind.AsyncKeyword)]:void 0,void 0,[],void 0,e.ts.factory.createToken(e.ts.SyntaxKind.EqualsGreaterThanToken),o);return e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("dynamic"),void 0,[i])}async function kn(e){let t=[],r=await gi(e,t);return await hi(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await ui(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await fi(e,e.pagesDir,t)),t}async function _n(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await ci(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await di(e,e.pagesDir,t)),t}async function ci(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"figma-imports",n);if(!await e.exists(o)){let i=await e.formatCode(o,jn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function ui(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"[...page]",n);if(!await e.exists(o)){let i=await e.formatCode(o,jn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,mi(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function mi(e){let t=e.typescriptEnabled;return e.sdkVersion===O.gen2?`
|
|
31
|
+
`}function kt(e,t){return t.sort((r,n)=>{let o=On(e,r),i=On(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function On(e,t){let r=t.importClause;if(r){let n=r.namedBindings;if(n&&e.ts.isNamedImports(n)&&n.elements.length>0)return n.elements[0].name.text;if(r.name)return r.name.text}return t.moduleSpecifier&&e.ts.isStringLiteral(t.moduleSpecifier)?t.moduleSpecifier.text:""}function Ln(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
|
|
32
|
+
${e}`),e}function _n(e,t){let r=t.statements.filter(n=>!(e.ts.isExpressionStatement(n)&&e.ts.isStringLiteral(n.expression)&&e.ts.isStringLiteral(n.expression)&&n.expression.text==="use client"));return e.ts.factory.updateSourceFile(t,r)}function le(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=kn(e,r),i=kn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function kn(e,t){let r=t.properties.find(n=>I(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function jn(e){let t=await e.readFile(e.registryPath);return t?mi(e,t):{components:[],sourceFile:v(e,"")}}async function mi(e,t){let r=v(e,t);return e.sdkVersion===D.gen2?fi(e,r):ui(e,r)}async function ui(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let l=i.arguments;if(l.length<2)continue;let d=l[1];if(!e.ts.isObjectLiteralExpression(d))continue;let u=l[0];if(e.ts.isCallExpression(u)){let c=e.ts.isIdentifier(u.expression)&&u.expression.text;if(c==="withChildren"){let x=jt(e,u.arguments[0]);if(e.ts.isCallExpression(x)){let f=await Lt(e,n,x,d,!0);f&&r.push(f)}else{let f=x;if(e.ts.isIdentifier(f)){let g=await _t(e,t,n,f,d,!0);g&&r.push(g)}}continue}if(c==="dynamic"){let x=await Lt(e,n,u,d,!1);x&&r.push(x);continue}let m=jt(e,u.arguments[0]);if(e.ts.isCallExpression(m)&&e.ts.isIdentifier(m.expression)&&m.expression.text==="dynamic"){let x=await Lt(e,n,m,d,!1);x&&r.push(x);continue}if(e.ts.isIdentifier(m)){let x=await _t(e,t,n,m,d,!1);x&&r.push(x);continue}continue}if(e.ts.isIdentifier(u)){let c=await _t(e,t,n,u,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:J(r)}}function jt(e,t){return e.ts.isCallExpression(t)?(e.ts.isIdentifier(t.expression)&&t.expression.text)==="dynamic"?t:jt(e,t.arguments[0]):t}async function Lt(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let p=s.body;if(e.ts.isCallExpression(p)){if(p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let d=p.arguments[0];if(!e.ts.isStringLiteral(d))return null;let u=d.text,c=await $e(e,u);i.filePath=c,i.relFilePath=e.relative(e.getRootDir(),i.filePath),await e.exists(c)?i.importPath=L(e,i.filePath):(i.externalImportPath=u,i.importPath=i.externalImportPath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(p)){let l=p.expression;if(!e.ts.isParenthesizedExpression(l))return null;let d=l.expression;if(!e.ts.isAwaitExpression(d))return null;let u=d.expression;if(!e.ts.isCallExpression(u)||u.expression.kind!==e.ts.SyntaxKind.ImportKeyword||u.arguments.length!==1)return null;let m=u.arguments[0];if(!e.ts.isStringLiteral(m)||!e.ts.isIdentifier(p.name))return null;let x=m.text,f=await $e(e,x);i.filePath=f,i.relFilePath=e.relative(e.getRootDir(),i.filePath),await e.exists(f)?i.importPath=L(e,i.filePath):(i.externalImportPath=x,i.importPath=i.externalImportPath),i.name=j(p.name.text),i.importName=p.name.text,i.exportName=p.name.text,i.exportType="named"}else return null;return i=Q(e,i,n),i.displayFilePath=A(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName,i.externalImportPath)),i}async function _t(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(l=>e.ts.isImportDeclaration(l)),p=s.find(l=>l.importClause&&l.importClause.name?.text===n.text);if(p){let l=p.moduleSpecifier;if(!e.ts.isStringLiteral(l))return null;let d=await $e(e,l.text);a.filePath=d,a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(d)?a.importPath=L(e,a.filePath):(a.externalImportPath=l.text,a.importPath=a.externalImportPath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(m=>m.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let u=await $e(e,d.text);a.filePath=u,a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(u)?a.importPath=L(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=Q(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName,a.externalImportPath)),a}function $e(e,t){return He(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function Bn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let l=0;l<i.length;l++){let d=i[l];if(e.ts.isImportDeclaration(d)){o=l;continue}if(!e.ts.isExpressionStatement(d))continue;let u=d.expression;if(!e.ts.isCallExpression(u))continue;let c=u.expression;if(!e.ts.isPropertyAccessExpression(c))continue;let m=c.expression;if(!e.ts.isIdentifier(m)||m.text!=="builder")continue;if(c.name.text=="init"){n=!0;break}else continue}if(n)return t;let a=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("process"),e.ts.factory.createIdentifier("env")),e.ts.factory.createIdentifier(ie)),s=r?e.ts.factory.createNonNullExpression(a):a,p=e.ts.factory.createExpressionStatement(e.ts.factory.createCallExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("builder"),e.ts.factory.createIdentifier("init")),void 0,[s]));return i.splice(o+1,0,p),e.ts.factory.updateSourceFile(t,i)}async function fi(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Bt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Bt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};_e(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(I(e,i)==="component"){let s,{initializer:p}=i;if(e.ts.isCallExpression(p)&&(e.ts.isIdentifier(p.expression)&&p.expression.text)==="dynamic"){let m=p.arguments;if(m.length===0)return null;let x=m[0];if(!e.ts.isArrowFunction(x))return null;let f=x.body;if(e.ts.isCallExpression(f)){if(f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let h=f.arguments[0];if(!e.ts.isStringLiteral(h))return null;let C=h.text,P=await $e(e,C);n.filePath=P,n.relFilePath=e.relative(e.getRootDir(),n.filePath),await e.exists(P)?n.importPath=L(e,n.filePath):(n.externalImportPath=C,n.importPath=n.externalImportPath),n.name=Y(e,n.filePath),n.importName="default",n.exportName="default",n.exportType="default"}else if(e.ts.isPropertyAccessExpression(f)){let g=f.expression;if(!e.ts.isParenthesizedExpression(g))return null;let h=g.expression;if(!e.ts.isAwaitExpression(h))return null;let C=h.expression;if(!e.ts.isCallExpression(C)||C.expression.kind!==e.ts.SyntaxKind.ImportKeyword||C.arguments.length!==1)return null;let b=C.arguments[0];if(!e.ts.isStringLiteral(b)||!e.ts.isIdentifier(f.name))return null;let y=b.text,S=await $e(e,y);n.filePath=S,n.relFilePath=e.relative(e.getRootDir(),n.filePath),await e.exists(S)?n.importPath=L(e,n.filePath):(n.externalImportPath=y,n.importPath=n.externalImportPath),n.name=j(f.name.text),n.importName=f.name.text,n.exportName=f.name.text,n.exportType="named"}else return null;return n=Q(e,n,r),n.displayFilePath=A(e,n.filePath),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await ae(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,await e.exists(l.filePath)?n.importPath=L(e,l.filePath):(n.externalImportPath=l.importPath,n.importPath=n.externalImportPath),n.importPath=L(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),u=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(u){let c=u.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(x=>!x.importClause||!x.importClause.namedBindings||!e.ts.isNamedImports(x.importClause.namedBindings)?!1:x.importClause.namedBindings.elements.some(f=>f.name.text===s));if(!c)return null;let m=c.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;n.exportName=s}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}function ce(e,t){let r=[...t.statements],n=!1;for(let o=t.statements.length-1;o>=0;o--){let i=t.statements[o];if(e.ts.isImportDeclaration(i)&&i.importClause){let a=!1,s=i.importClause.namedBindings;if(s&&e.ts.isNamedImports(s)&&s.elements){let p=[...s.elements];for(let l=p.length-1;l>=0;l--){let d=p[l];if(e.ts.isImportSpecifier(d)){let u=d.name;if(u&&e.ts.isIdentifier(u)){let c=u.text;Vn(e,t,c)||p.splice(l,1)}}}if(p.length===0)a=!0;else if(s.elements.length!==p.length){let l=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(p)),d=e.ts.factory.updateImportDeclaration(i,void 0,l,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let p=i.importClause.name.text;Vn(e,t,p)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Vn(e,t,r){let n=!1;function o(i){if(!e.ts.isImportDeclaration(i)){if(e.ts.isIdentifier(i)&&i.text===r){n=!0;return}e.ts.forEachChild(i,o)}}return e.ts.forEachChild(t,o),n}function me(e,t,r,n,o,i,a){let s=null,p=null,l=null,d=-1;t=W(t),r=W(r);let u=t.find(m=>m.id===e),c=r.find(m=>m.id===e);if(n)c||(s={...W(u),inputs:W(u.inputs).map(m=>(m.isRegistered=!0,m))},d=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)d=c.nodeIndex,p=W(c),r=r.filter(m=>m.id!==e);else if(i!=null)di(c,i),d=c.nodeIndex,l=c;else if(a!=null){let m=c.inputs.find(x=>x.name===a.name);m&&(a.registerInput===!1?m.isRegistered=!1:(gi(m,a),m.isRegistered=!0),l=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:p,updateRegisteredCmp:l,nodeIndex:d,components:te(t,r)}}function te(e,t){let r=J([...t.map(n=>(n.isRegistered=!0,n)),...e.filter(n=>!t.some(o=>o.id===n.id)).map(n=>(n.isRegistered=!1,n))]);return r.forEach(n=>{n.inputs=n.inputs.map(At),n.inputs.sort((a,s)=>a.name.toLowerCase().localeCompare(s.name.toLowerCase()));let o=t.find(a=>a.id===n.id);o&&(o.acceptsChildren=Nt(n));let i=e.find(a=>a.id===n.id&&a.externalImportPath);i&&(n.filePath=i.filePath,n.relFilePath=i.relFilePath)}),r}function di(e,t){q(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),q(t.description)?e.description=t.description:t.description===null&&delete e.description,q(t.image)?e.image=t.image:t.image===null&&delete e.image}function gi(e,t){q(t.type)&&(e.type=t.type),q(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,q(t.defaultValue)||Je(t.defaultValue)||ke(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,q(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function we(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".jsx"||p===".ts"||p===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await M(e,[...t])}function ue(e,t,r){return Be(e,t,r.variableName)?t:xi(e,t,r)}function xi(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),p=e.ts.factory.createVariableStatement([s],a),l=[...t.statements,p];return e.ts.factory.updateSourceFile(t,l)}async function fe(e,t,r,n,o,i,a,s){let p=await we(e),[l,d,u,c]=await Promise.all([Fn(e,p),jn(e),Vt(e),qe(e)]),m=l.map(P=>P.cmpInfo),x=d.components,f={components:te(m,x),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(m),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Ve(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let N=l.find(B=>B.cmpInfo.id===S);if(!N)throw new Error(`Component ${S} not found`);return N}),b=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),y=await M(e,b);for(let S of P){let N=f.components.find(T=>T.id===S.cmpInfo.id),B=await Ke(e,S,y);ee(N,B);let k=m.findIndex(T=>T.id===S.cmpInfo.id);m[k].inputs=B;let E=me(S.cmpInfo.id,m,x,r,n,o,i);if(e.sdkVersion===D.gen2){let{elements:T,elmIndex:U,statementIndex:X,statement:$,variableDeclaration:F}=await Si(e,h,S);if(E.addCmpToRegistry)T.push(Ci(e,E.addCmpToRegistry)),g=!0;else if(E.removeCmpFromRegistry)T.splice(U,1),g=!0;else if(E.updateRegisteredCmp){let z=K(e,T[U],E.updateRegisteredCmp);T[U]=e.ts.factory.updateObjectLiteralExpression(z,[$n(e,E.updateRegisteredCmp),...z.properties.slice(1)]),g=!0}if(g&&a){let z=[...h.statements];z[X]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(F,F.name,F.exclamationToken,F.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),h=e.ts.factory.updateSourceFile(h,z),h=Kn(e,E,h),h=w(e,h,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),h=ue(e,h,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),f.components=E.components,x=E.components.filter(Ie=>Ie.isRegistered)}}else{let T=[...h.statements];E.addCmpToRegistry?(T.push(Dn(e,E.addCmpToRegistry)),g=!0):E.removeCmpFromRegistry?(T.splice(E.nodeIndex,1),g=!0):E.updateRegisteredCmp&&(T[E.nodeIndex]=Ft(e,T[E.nodeIndex],E.updateRegisteredCmp),g=!0),g&&a&&(h=e.ts.factory.updateSourceFile(h,T),h=w(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=Bn(e,h,u),h=Kn(e,E,h),N?.acceptsChildren&&(h=w(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=E.components,x=E.components.filter(U=>U.isRegistered))}}}if(g&&a){h=ce(e,h),h=pe(e,h),e.appDir&&(h=_n(e,h));let P=O(e,h);P=H(P),e.appDir&&(P=Ln(P)),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return f}function $n(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.appDir?e.ts.factory.createPropertyAssignment("component",r):e.ts.factory.createPropertyAssignment("component",Pi(e,t))}function hi(e){return e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())}function Ci(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([$n(e,t),...t.acceptsChildren?[hi(e)]:[]],!0),t)}async function Si(e,t,r){let n=V(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await Bt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function Kn(e,t,r){if(e.appDir){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=n.externalImportPath?n.externalImportPath:R(e,e.registryPath,n.filePath);n.exportType==="default"?r=w(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=w(e,r,{namedImports:[n.importName],importPath:o}))}}else r=w(e,r,{defaultImport:"dynamic",importPath:"next/dynamic"});return r}function Pi(e,t){let r=t.externalImportPath?t.externalImportPath:R(e,e.registryPath,t.filePath),n=t.exportName!=="default",o;n?o=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createAwaitExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)])),e.ts.factory.createIdentifier(t.exportName)):o=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("import"),void 0,[e.ts.factory.createStringLiteral(r)]);let i=e.ts.factory.createArrowFunction(n?[e.ts.factory.createModifier(e.ts.SyntaxKind.AsyncKeyword)]:void 0,void 0,[],void 0,e.ts.factory.createToken(e.ts.SyntaxKind.EqualsGreaterThanToken),o);return e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("dynamic"),void 0,[i])}async function Mn(e){let t=[],r=await wi(e,t);return await Qn(e,t,r),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await Ti(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await Di(e,e.pagesDir,t)),t}async function Un(e){let t=[];return await Qn(e,t),e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await Ei(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await yi(e,e.pagesDir,t)),t}async function Ei(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"figma-imports",n);if(!await e.exists(o)){let i=await e.formatCode(o,qn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,zn(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}async function Ti(e,t,r){let n=`page.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,"[...page]",n);if(!await e.exists(o)){let i=await e.formatCode(o,qn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}if(!await e.exists(e.builderComponentPath)){let i=await e.formatCode(e.builderComponentPath,zn(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function zn(e){let t=e.typescriptEnabled;return e.sdkVersion===D.gen2?`
|
|
33
33
|
"use client";
|
|
34
34
|
import { ${t?"BuilderContent, ":""} isPreviewing, Content } from "@builder.io/sdk-react";
|
|
35
35
|
import DefaultErrorPage from "next/error";
|
|
36
|
-
import { CUSTOM_COMPONENTS } from ${JSON.stringify(
|
|
36
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(R(e,e.builderComponentPath,e.registryPath))};
|
|
37
37
|
${t?`
|
|
38
38
|
interface BuilderPageProps {
|
|
39
39
|
content: BuilderContent | null;
|
|
40
40
|
model: string;
|
|
41
41
|
}`:""}
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
// Builder Public API Key set in .env file
|
|
44
|
-
const builderApiKey = process.env.${
|
|
45
|
-
|
|
46
|
-
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
47
|
-
// Call the isPreviewing hook to determine if
|
|
44
|
+
const builderApiKey = process.env.${ie}${t?"!":""};
|
|
45
|
+
|
|
46
|
+
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
47
|
+
// Call the isPreviewing hook to determine if
|
|
48
48
|
// the page is being previewed in Builder
|
|
49
49
|
// If "content" has a value or the page is being previewed in Builder,
|
|
50
50
|
// render the BuilderComponent with the specified content and model props.
|
|
@@ -56,44 +56,44 @@ interface BuilderPageProps {
|
|
|
56
56
|
customComponents={CUSTOM_COMPONENTS}
|
|
57
57
|
/>;
|
|
58
58
|
}
|
|
59
|
-
// If the "content" is falsy and the page is
|
|
60
|
-
// not being previewed in Builder, render the
|
|
59
|
+
// If the "content" is falsy and the page is
|
|
60
|
+
// not being previewed in Builder, render the
|
|
61
61
|
// DefaultErrorPage with a 404.
|
|
62
|
-
return <DefaultErrorPage statusCode={404} />;
|
|
63
|
-
}
|
|
62
|
+
return <DefaultErrorPage statusCode={404} />;
|
|
63
|
+
}
|
|
64
64
|
`.trimStart():`
|
|
65
65
|
"use client";
|
|
66
66
|
${t?'import { ComponentProps } from "react";':""}
|
|
67
|
-
import { BuilderComponent, useIsPreviewing } from "@builder.io/react";
|
|
67
|
+
import { BuilderComponent, useIsPreviewing } from "@builder.io/react";
|
|
68
68
|
import { ${t?"BuilderContent, ":""}builder } from '@builder.io/sdk';
|
|
69
69
|
import DefaultErrorPage from "next/error";
|
|
70
|
-
import ${JSON.stringify(
|
|
70
|
+
import ${JSON.stringify(R(e,e.builderComponentPath,e.registryPath))};
|
|
71
71
|
${t?`
|
|
72
72
|
type BuilderPageProps = ComponentProps<typeof BuilderComponent>;`:""}
|
|
73
73
|
|
|
74
74
|
// Builder Public API Key set in .env file
|
|
75
|
-
builder.init(process.env.${
|
|
75
|
+
builder.init(process.env.${ie}${t?"!":""});
|
|
76
76
|
|
|
77
|
-
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
78
|
-
// Call the useIsPreviewing hook to determine if
|
|
77
|
+
export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
|
|
78
|
+
// Call the useIsPreviewing hook to determine if
|
|
79
79
|
// the page is being previewed in Builder
|
|
80
|
-
const isPreviewing = useIsPreviewing();
|
|
80
|
+
const isPreviewing = useIsPreviewing();
|
|
81
81
|
// If "content" has a value or the page is being previewed in Builder,
|
|
82
82
|
// render the BuilderComponent with the specified content and model props.
|
|
83
83
|
if (content || isPreviewing) {
|
|
84
84
|
return <BuilderComponent content={content} model={model} />;
|
|
85
85
|
}
|
|
86
|
-
// If the "content" is falsy and the page is
|
|
87
|
-
// not being previewed in Builder, render the
|
|
86
|
+
// If the "content" is falsy and the page is
|
|
87
|
+
// not being previewed in Builder, render the
|
|
88
88
|
// DefaultErrorPage with a 404.
|
|
89
|
-
return <DefaultErrorPage statusCode={404} />;
|
|
90
|
-
}
|
|
91
|
-
`.trimStart()}function
|
|
89
|
+
return <DefaultErrorPage statusCode={404} />;
|
|
90
|
+
}
|
|
91
|
+
`.trimStart()}function qn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=R(e,t,e.builderComponentPath);return e.sdkVersion===D.gen2?`
|
|
92
92
|
import { fetchOneEntry } from "@builder.io/sdk-react";
|
|
93
93
|
import { RenderBuilderContent } from ${JSON.stringify(o)};
|
|
94
94
|
|
|
95
95
|
// Builder Public API Key set in .env file
|
|
96
|
-
const PUBLIC_API_KEY = process.env.${
|
|
96
|
+
const PUBLIC_API_KEY = process.env.${ie}${n?"!":""};
|
|
97
97
|
|
|
98
98
|
${n?`
|
|
99
99
|
interface PageProps {
|
|
@@ -127,7 +127,7 @@ import { builder } from "@builder.io/sdk";
|
|
|
127
127
|
import { RenderBuilderContent } from ${JSON.stringify(o)};
|
|
128
128
|
|
|
129
129
|
// Builder Public API Key set in .env file
|
|
130
|
-
builder.init(process.env.${
|
|
130
|
+
builder.init(process.env.${ie}${n?"!":""});
|
|
131
131
|
${n?`
|
|
132
132
|
interface PageProps {
|
|
133
133
|
params: {
|
|
@@ -156,7 +156,7 @@ export default async function Page(props${n?": PageProps":""}) {
|
|
|
156
156
|
</>
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
|
-
`.trimStart()}async function
|
|
159
|
+
`.trimStart()}async function Di(e,t,r){let n=`[...page].${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,Jn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function yi(e,t,r){let n=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,Jn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function Jn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return e.sdkVersion===D.gen2?`
|
|
160
160
|
import React from "react";
|
|
161
161
|
import { useRouter } from "next/router";
|
|
162
162
|
${n?'import type { BuilderContent } from "@builder.io/sdk-react";':""}
|
|
@@ -169,9 +169,9 @@ import {
|
|
|
169
169
|
import DefaultErrorPage from "next/error";
|
|
170
170
|
import Head from "next/head";
|
|
171
171
|
${n?'import { GetStaticProps } from "next";':""}
|
|
172
|
-
import { CUSTOM_COMPONENTS } from ${JSON.stringify(
|
|
172
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(R(e,e.builderComponentPath,e.registryPath))};
|
|
173
173
|
|
|
174
|
-
const BUILDER_API_KEY = process.env.${
|
|
174
|
+
const BUILDER_API_KEY = process.env.${ie}${n?"!":""};
|
|
175
175
|
|
|
176
176
|
// Define a function that fetches the Builder
|
|
177
177
|
// content for a given page
|
|
@@ -252,9 +252,9 @@ import DefaultErrorPage from "next/error";
|
|
|
252
252
|
import Head from "next/head";${n?`
|
|
253
253
|
import { BuilderContent } from "@builder.io/sdk";`:""}${n?`
|
|
254
254
|
import { GetStaticProps } from "next";`:""}
|
|
255
|
-
import ${JSON.stringify(
|
|
255
|
+
import ${JSON.stringify(R(e,t,e.registryPath))};
|
|
256
256
|
|
|
257
|
-
builder.init(process.env.${
|
|
257
|
+
builder.init(process.env.${ie}${n?"!":""});
|
|
258
258
|
|
|
259
259
|
// Define a function that fetches the Builder
|
|
260
260
|
// content for a given page
|
|
@@ -318,7 +318,7 @@ export default function Page({ page }${n?": { page: BuilderContent | null }":""}
|
|
|
318
318
|
</>
|
|
319
319
|
);
|
|
320
320
|
}
|
|
321
|
-
`.trimStart()}async function
|
|
321
|
+
`.trimStart()}async function wi(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:p}=vi(e);if(!await e.exists(i)){let l=await e.formatCode(i,s);await e.writeFile(i,l),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,p),t.push({filePath:a,modifiedType:"create"})),i}function vi(e){let t=e.typescriptEnabled,r=`
|
|
322
322
|
"use client"
|
|
323
323
|
import React, { useState } from "react";
|
|
324
324
|
import styles from "./styles.module.css";
|
|
@@ -381,18 +381,67 @@ export default Counter;
|
|
|
381
381
|
font-size: 42px;
|
|
382
382
|
text-align: center;
|
|
383
383
|
}
|
|
384
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
385
|
-
|
|
384
|
+
`.trimStart();return{component:r,styles:n}}async function Qn(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===D.gen2){let i=Ii(e);await e.writeFile(e.registryPath,i)}else await e.writeFile(e.registryPath,"");t.push({filePath:e.registryPath,modifiedType:"create"})}if(!r)return;let o=(await fe(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===r);o&&await fe(e,o.id,!0,!1,null,null,!0,!1)}function Ii(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-react";
|
|
385
|
+
|
|
386
386
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
387
387
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
388
388
|
];
|
|
389
|
-
`}async function
|
|
389
|
+
`}async function Me(e){let t=await pt(e,e.getRootDir());if(t&&typeof t=="object"){let r=new Set(Object.keys({...t.dependencies,...t.devDependencies}));if(r.has("@builder.io/sdk-react"))return D.gen2;if(r.has("@builder.io/react"))return D.gen1}return null}async function Wn(e){let t=await bi(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>Mn(t),ensureFigmaImportPage:()=>Un(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>fe(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await fe(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>fe(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>fe(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>fe(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>fe(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>qe(t),setPublicApiKey:n=>xn(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===D.gen2?[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-react"}]:[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function bi(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await Ri(e),o=await Vt(e),i=`builder-registry.${o?"ts":"js"}`,a={},s={...e,addExternalPackage:p=>{a[e.join(t,p,"index.ts")]=`export * from "${p}";`},readFileSync:p=>a[p]??e.readFileSync(p),existsSync:p=>!!a[p]||e.existsSync(p),readdirSync:p=>{let l=e.readdirSync(p);return p===t?[...l,...Object.keys(a).map(d=>d.slice(t.length+1))]:l},readdir:async p=>{let l=await e.readdir(p);return p===t?[...l,...Object.keys(a).map(d=>d.slice(t.length+1))]:l},appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(e.sdkVersion?s.sdkVersion=e.sdkVersion:s.sdkVersion=await Me(s),await e.exists(r)){s.srcDir=r,s.componentsDir=e.join(r,"components");let p=e.join(r,"app");await e.exists(p)&&(s.appDir=p);let l=e.join(r,"pages");await e.exists(l)&&(s.pagesDir=l),s.registryPath=e.join(r,i)}else s.componentsDir=e.join(t,"components"),s.registryPath=e.join(t,i);if(s.builderComponentPath=e.join(s.componentsDir,`builder.${o?"tsx":"jsx"}`),!s.appDir){let p=e.join(t,"app");await e.exists(p)&&(s.appDir=p)}if(!s.pagesDir){let p=e.join(t,"pages");await e.exists(p)&&(s.pagesDir=p)}if(!s.appDir&&!s.pagesDir)throw new Error(`Could not find Next.js "app" or "pages" directory. Searched in "${t}".`);return s}function Vt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Ri(e){let t=e.join(e.getRootDir(),"next.config.ts");if(await e.exists(t))return t;let r=e.join(e.getRootDir(),"next.config.mjs");if(await e.exists(r))return r;let n=e.join(e.getRootDir(),"next.config.js");if(await e.exists(n))return n;throw new Error(`Could not find Next.js config file. Searched for "next.config.ts", "next.config.mjs" and "next.config.js" in "${e.getRootDir()}".`)}async function Ze(e){return await Ee(e,[".env"],Gn)}async function Yn(e,t){Ni(t);let r=await Ze(e),n=await Te(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function Ni(e){typeof process<"u"&&(process.env[Gn]=e)}var Gn="PUBLIC_BUILDER_API_KEY";function Hn(e,t,r){if(r.length===0)return e;let n=e.split(`
|
|
390
390
|
`),o=n.findIndex(s=>s.includes(r));if(o===-1||n.some(s=>s.includes(t[0])))return e;let a=["/**",...t.map(s=>` * ${s.trim()}`)," */"];return n.splice(o,0,...a),n.join(`
|
|
391
|
-
`)}async function
|
|
391
|
+
`)}async function Zn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(a.startsWith(".")||Oi.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let p=await dt(e,o,s,i);r.push(...p)})),r}async function er(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return Ai(e,t,n)}return null}function Ai(e,t,r){let n=v(e,r);return dt(e,null,t,n)}async function dt(e,t,r,n){r=e.normalize(r);let o=[],i=G(e,n);return await Promise.all(i.map(async a=>{let s=await Fi(e,t,r,a);s&&o.push(s)})),o}async function Fi(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=L(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=Xn(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let p=a.name.text;return{cmpInfo:{id:await _(e,r,p),displayFilePath:A(e,r),name:j(p),inputs:[],exportName:n.isDefaultExport?"default":p,exportType:n.isDefaultExport?"default":"named",importName:p,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=Xn(e,n.node);if(a)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:A(e,r),name:Y(e,r),inputs:[],exportName:"default",exportType:"default",importName:Re(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function Xn(e,t){if(t&&e.ts.isCallExpression(t)&&e.ts.isIdentifier(t.expression)&&t.expression.text==="component$"&&t.arguments.length>0){let r=t.arguments[0];if(e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r))return{callExpression:t,fnNode:r}}return null}var Oi=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function tr(e,t){let r=t.node.fnNode;if((e.ts.isArrowFunction(r)||e.ts.isFunctionExpression(r))&&r.parameters.length>0){let{sourceFile:o,typeChecker:i}=await je(e,t.cmpInfo.filePath,null);if(!(await dt(e,i,t.cmpInfo.filePath,o)).find(p=>p.cmpInfo.id===t.cmpInfo.id))throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return Ne(e,i,r)}return[]}async function nr(e){return Kt(e)}async function Kt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,ki),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var ki=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
|
|
392
392
|
|
|
393
393
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
394
394
|
];
|
|
395
|
-
`;async function Wn(e){await Ot(e);let t=await e.readFile(e.registryPath);return t?vi(e,t):{components:[],sourceFile:E(e,"")}}async function vi(e,t){let r=E(e,t);return bi(e,r)}async function bi(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Lt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function Lt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await Pe(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=k(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let p=await qn(e,s.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let l=p.find(d=>d.cmpInfo.exportName===a);l&&(n.exportName=l.cmpInfo.exportName)}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function Yn(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}async function Ie(e,t,r,n,o,i,a,s){let p=await Yn(e),[l,d,f]=await Promise.all([zn(e,p),Wn(e),He(e)]),c=l.map(m=>m.cmpInfo),u=d.components,h={components:ee(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let m=l.find(y=>y.cmpInfo.id===t);if(!m)throw new Error(`Component ${t} not found`);let g=d.sourceFile,x=h.components.find(y=>y.id===t),C=await Qn(e,m);Z(x,C),t=Array.isArray(t)?t[0]:t;let P=pe(t,c,u,r,n,o,i),{elements:I,elmIndex:T,statementIndex:S,statement:R,variableDeclaration:B}=await Ri(e,g,m),F=!1;if(P.addCmpToRegistry?(I.push(Ii(e,P.addCmpToRegistry)),F=!0):P.removeCmpFromRegistry?(I.splice(T,1),F=!0):P.updateRegisteredCmp&&(I[T]=K(e,I[T],P.updateRegisteredCmp),F=!0),F&&a){let y=[...g.statements];y[S]=e.ts.factory.updateVariableStatement(R,R.modifiers,e.ts.factory.updateVariableDeclarationList(R.declarationList,[e.ts.factory.updateVariableDeclaration(B,B.name,B.exclamationToken,B.type,e.ts.factory.createArrayLiteralExpression(Te(e,I)))])),g=e.ts.factory.updateSourceFile(g,y),x.exportType==="named"?g=D(e,g,{namedImports:[x.importName],importPath:v(e,e.registryPath,x.filePath)}):g=D(e,g,{defaultImport:x.importName,importPath:v(e,e.registryPath,x.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=Ee(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=se(e,g),g=ae(e,g);let w=N(e,g);w=H(w),w=Mn(w,Ni,"CUSTOM_COMPONENTS"),w=await e.formatCode(e.registryPath,w),await e.writeFile(e.registryPath,w)}h.components=P.components}return h}function Ii(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Ri(e,t,r){let n=M(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await Lt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Ni=["This array is used to integrate custom components within Builder.","https://www.builder.io/c/docs/custom-components-intro","",'These components will be found the "Custom Components"',"section of Builder's visual editor.",'You can also turn on "components only mode" to limit',"editing to only these components.","https://www.builder.io/c/docs/guides/components-only-mode"];async function Gn(e){let t=await Ai(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>Jn(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ie(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Ie(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ie(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ie(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ie(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ie(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>He(t),setPublicApiKey:n=>$n(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>ne(t),setCache:n=>re(t,n)}}async function Ai(e){let t=await $e(e,e.getRootDir(),"components");if(!t)throw new Error(`Could not find components directory within project: ${e.getRootDir()}`);let r=e.join(t,"builder-registry.ts"),n=e.join(e.getRootDir(),".env");return{...e,componentsDir:t,registryPath:r,envPath:n}}async function Xe(e){return await Ce(e,[".env"],Ze)}async function Hn(e,t){let r=await Xe(e),n=await Se(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Ze="PUBLIC_BUILDER_KEY";async function Xn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker(),i=e.join(e.getRootDir(),"build");return await Promise.all(n.map(async a=>{let s=e.basename(a.fileName);if(s.startsWith(".")||s==="node_modules"||Fi.has(s)||s.includes("$."))return;let p=e.normalize(a.fileName);if(p===e.remixConfigPath||p===e.registryPath||p===i)return;let l=await ye(e,o,p,a);r.push(...l)})),r}var Fi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Zn(e){await _t(e);let t=await e.readFile(e.registryPath);return t?Oi(e,t):{components:[],sourceFile:E(e,"")}}async function Oi(e,t){let r=E(e,t);return Li(e,r)}async function Li(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await kt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function kt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let f=s.arguments[0];e.ts.isIdentifier(f)&&(a=f.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await Pe(e,e.registryPath,t,a);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,n.importPath=k(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await Dn(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(f=>f.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function ce(e,t,r,n,o,i,a,s){let p=await De(e),[l,d,f]=await Promise.all([Xn(e,p),Zn(e),Xe(e)]),c=l.map(C=>C.cmpInfo),u=d.components,h={components:ee(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await ke(e,h.components),h;let m=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(T=>{let S=l.find(R=>R.cmpInfo.id===T);if(!S)throw new Error(`Component ${T} not found`);return S}),P=Array.from(new Set(C.map(T=>T.cmpInfo.filePath))),I=await $(e,P);for(let T of C){let S=h.components.find(L=>L.id===T.cmpInfo.id),R=await _e(e,T,I);Z(S,R);let B=c.findIndex(L=>L.id===T.cmpInfo.id);c[B].inputs=R;let F=pe(T.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:w,statementIndex:V,statement:z,variableDeclaration:q}=await _i(e,g,T);if(F.addCmpToRegistry)y.push(ki(e,F.addCmpToRegistry)),m=!0;else if(F.removeCmpFromRegistry)y.splice(w,1),m=!0;else if(F.updateRegisteredCmp){let L=K(e,y[w],F.updateRegisteredCmp);y[w]=e.ts.factory.updateObjectLiteralExpression(L,[er(e,F.updateRegisteredCmp),...L.properties.slice(1)]),m=!0}if(m&&a){let L=[...g.statements];L[V]=e.ts.factory.updateVariableStatement(z,z.modifiers,e.ts.factory.updateVariableDeclarationList(z.declarationList,[e.ts.factory.updateVariableDeclaration(q,q.name,q.exclamationToken,q.type,e.ts.factory.createArrayLiteralExpression(Te(e,y)))])),g=e.ts.factory.updateSourceFile(g,L),S.exportType==="named"?g=D(e,g,{namedImports:[S.importName],importPath:v(e,e.registryPath,S.filePath)}):g=D(e,g,{defaultImport:S.importName,importPath:v(e,e.registryPath,S.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),S.acceptsChildren&&(g=D(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=Ee(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=F.components,u=F.components.filter(fe=>fe.isRegistered)}}}if(m&&a){g=se(e,g),g=ae(e,g);let C=N(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function er(e,t){let r=e.ts.factory.createIdentifier(t.importName),n=t.acceptsChildren?e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("withChildren"),void 0,[r]):r;return e.ts.factory.createPropertyAssignment("component",n)}function ki(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([er(e,t)],!0),t)}async function _i(e,t,r){let n=M(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await kt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function tr(e){let t=[],r=await Vi(e,t);return t.push(...await _t(e)),await Ki(e,r),await Bi(e,t),t}async function nr(e){let t=[];return await ji(e,t),t}async function ji(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,rr({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Bi(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,rr({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function rr({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=v(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${Ze}`;return e.getFrameworks().some(p=>p.name==="@shopify/remix-oxygen")&&(s=`context.env.${Ze}`),n&&(s+="!"),`
|
|
395
|
+
`;async function rr(e){await Kt(e);let t=await e.readFile(e.registryPath);return t?Li(e,t):{components:[],sourceFile:v(e,"")}}async function Li(e,t){let r=v(e,t);return _i(e,r)}async function _i(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await $t(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function $t(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(I(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await ae(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=L(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let p=await er(e,s.filePath);if(p&&p.length>0)if(p.length===1)n.exportName=p[0].cmpInfo.exportName;else{let l=p.find(d=>d.cmpInfo.exportName===a);l&&(n.exportName=l.cmpInfo.exportName)}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function or(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),p=e.extname(a).toLowerCase();if(p===".tsx"||p===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await M(e,[...t])}async function Ae(e,t,r,n,o,i,a,s){let p=await or(e),[l,d,u]=await Promise.all([Zn(e,p),rr(e),Ze(e)]),c=l.map(f=>f.cmpInfo),m=d.components,x={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x;if(t!=null){let f=l.find(E=>E.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let g=d.sourceFile,h=x.components.find(E=>E.id===t),C=await tr(e,f);ee(h,C),t=Array.isArray(t)?t[0]:t;let P=me(t,c,m,r,n,o,i),{elements:b,elmIndex:y,statementIndex:S,statement:N,variableDeclaration:B}=await Bi(e,g,f),k=!1;if(P.addCmpToRegistry?(b.push(ji(e,P.addCmpToRegistry)),k=!0):P.removeCmpFromRegistry?(b.splice(y,1),k=!0):P.updateRegisteredCmp&&(b[y]=K(e,b[y],P.updateRegisteredCmp),k=!0),k&&a){let E=[...g.statements];E[S]=e.ts.factory.updateVariableStatement(N,N.modifiers,e.ts.factory.updateVariableDeclarationList(N.declarationList,[e.ts.factory.updateVariableDeclaration(B,B.name,B.exclamationToken,B.type,e.ts.factory.createArrayLiteralExpression(le(e,b)))])),g=e.ts.factory.updateSourceFile(g,E),h.exportType==="named"?g=w(e,g,{namedImports:[h.importName],importPath:R(e,e.registryPath,h.filePath)}):g=w(e,g,{defaultImport:h.importName,importPath:R(e,e.registryPath,h.filePath)}),g=w(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=ce(e,g),g=pe(e,g);let T=O(e,g);T=H(T),T=Hn(T,Vi,"CUSTOM_COMPONENTS"),T=await e.formatCode(e.registryPath,T),await e.writeFile(e.registryPath,T)}x.components=P.components}return x}function ji(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Bi(e,t,r){let n=V(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await $t(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Vi=["This array is used to integrate custom components within Builder.","https://www.builder.io/c/docs/custom-components-intro","",'These components will be found the "Custom Components"',"section of Builder's visual editor.",'You can also turn on "components only mode" to limit',"editing to only these components.","https://www.builder.io/c/docs/guides/components-only-mode"];async function ir(e){let t=await Ki(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>nr(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ae(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:async n=>{},loadComponent:async n=>{let o=await Ae(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ae(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ae(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ae(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ae(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ze(t),setPublicApiKey:n=>Yn(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function Ki(e){let t=await ze(e,e.getRootDir(),"components");if(!t)throw new Error(`Could not find components directory within project: ${e.getRootDir()}`);let r=e.join(t,"builder-registry.ts"),n=e.join(e.getRootDir(),".env");return{...e,componentsDir:t,registryPath:r,envPath:n}}async function et(e){return await Ee(e,[".env"],tt)}async function ar(e,t){let r=await et(e),n=await Te(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var tt="PUBLIC_BUILDER_KEY";var $i=new Set(["dist","node_modules"]);async function sr(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker(),i=e.join(e.getRootDir(),"build");return await Promise.all(n.map(async a=>{let s=e.basename(a.fileName);if(s.startsWith(".")||s==="node_modules"||ct(e,$i,a.fileName)||Mi.has(s)||s.includes("$."))return;let p=e.normalize(a.fileName);if(p===e.remixConfigPath||p===e.registryPath||p===i)return;let l=await ye(e,o,p,a);r.push(...l)})),r}var Mi=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function pr(e){await gt(e);let t=await e.readFile(e.registryPath);return t?Ui(e,t):{components:[],sourceFile:v(e,"")}}async function Ui(e,t){let r=v(e,t);return zi(e,r)}async function zi(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Mt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Mt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};e.sdkVersion===D.gen2&&_e(e,r)&&(n.acceptsChildren=!0);for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(I(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let d=s.arguments[0];e.ts.isIdentifier(d)&&(a=d.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await ae(e,e.registryPath,t,a);if(!p)continue;if(n.filePath=p.filePath,n.relFilePath=p.relFilePath,await e.exists(p.filePath)?n.importPath=L(e,p.filePath):(n.externalImportPath=p.importPath,n.importPath=n.externalImportPath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType,n.externalImportPath)n.exportName=a;else{let l=await Rn(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(u=>u.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}async function de(e,t,r,n,o,i,a,s){let p=await we(e),[l,d,u]=await Promise.all([sr(e,p),pr(e),et(e)]),c=l.map(C=>C.cmpInfo),m=d.components,x={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await Ve(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(y=>{let S=l.find(N=>N.cmpInfo.id===y);if(!S)throw new Error(`Component ${y} not found`);return S}),P=Array.from(new Set(C.map(y=>y.cmpInfo.filePath))),b=await M(e,P);for(let y of C){let S=x.components.find(F=>F.id===y.cmpInfo.id),N=await Ke(e,y,b);ee(S,N);let B=c.findIndex(F=>F.id===y.cmpInfo.id);c[B].inputs=N;let k=me(y.cmpInfo.id,c,m,r,n,o,i),{elements:E,elmIndex:T,statementIndex:U,statement:X,variableDeclaration:$}=await Ji(e,g,y);if(k.addCmpToRegistry)E.push(qi(e,k.addCmpToRegistry)),f=!0;else if(k.removeCmpFromRegistry)E.splice(T,1),f=!0;else if(k.updateRegisteredCmp){let F=K(e,E[T],k.updateRegisteredCmp);E[T]=e.ts.factory.updateObjectLiteralExpression(F,[lr(e,k.updateRegisteredCmp),...F.properties.slice(1)]),f=!0}if(f&&a){let F=[...g.statements];F[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration($,$.name,$.exclamationToken,$.type,e.ts.factory.createArrayLiteralExpression(le(e,E)))])),g=e.ts.factory.updateSourceFile(g,F),S.exportType==="named"?g=w(e,g,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)}):g=w(e,g,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)});let z=e.sdkVersion===D.gen2?"@builder.io/sdk-react":"@builder.io/react";g=w(e,g,{namedImports:["RegisteredComponent"],importPath:z,isTypeOnly:!0}),S.acceptsChildren&&e.sdkVersion!==D.gen2&&(g=w(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=k.components,m=k.components.filter(Ie=>Ie.isRegistered)}}}if(f&&a){g=ce(e,g),g=pe(e,g);let C=O(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function lr(e,t){if(e.sdkVersion===D.gen2)return e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName));let r=e.ts.factory.createIdentifier(t.importName),n=t.acceptsChildren?e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("withChildren"),void 0,[r]):r;return e.ts.factory.createPropertyAssignment("component",n)}function qi(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([lr(e,t),...t.acceptsChildren&&e.sdkVersion===D.gen2?[e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())]:[]],!0),t)}async function Ji(e,t,r){let n=V(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await Mt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function cr(e){let t=[],r=await Yi(e,t);return t.push(...await gt(e)),await Hi(e,r),await Wi(e,t),t}async function mr(e){let t=[];return t.push(...await gt(e)),await Qi(e,t),t}async function Qi(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,ur({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Wi(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`),e.sdkVersion===D.gen2&&(r=`($slug)._index.${e.typescriptEnabled?"tsx":"jsx"}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,ur({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function ur({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=R(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${tt}`;return e.getFrameworks().some(p=>p.name==="@shopify/remix-oxygen")&&(s=`context.env.${tt}`),n&&(s+="!"),e.sdkVersion===D.gen2?`
|
|
396
|
+
|
|
397
|
+
import {
|
|
398
|
+
Content,
|
|
399
|
+
fetchOneEntry,
|
|
400
|
+
getBuilderSearchParams,
|
|
401
|
+
isPreviewing,
|
|
402
|
+
} from "@builder.io/sdk-react";
|
|
403
|
+
${n?'import type { LoaderFunctionArgs } from "@remix-run/node";':""}
|
|
404
|
+
import { useLoaderData } from "@remix-run/react";
|
|
405
|
+
import { fetch ${n?"as webFetch":""}} from "@remix-run/web-fetch";
|
|
406
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
|
|
407
|
+
|
|
408
|
+
export const loader = async ({ params, request }${n?": LoaderFunctionArgs":""}) => {
|
|
409
|
+
const builderApiKey = ${s};
|
|
410
|
+
const url = new URL(request.url);
|
|
411
|
+
const urlPath = \`/\${params["slug"] || ""}\`;
|
|
412
|
+
|
|
413
|
+
const page = await fetchOneEntry({
|
|
414
|
+
model: "${r}",
|
|
415
|
+
apiKey: builderApiKey,
|
|
416
|
+
options: getBuilderSearchParams(url.searchParams),
|
|
417
|
+
userAttributes: { urlPath },
|
|
418
|
+
fetch: webFetch,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
if (!page && !isPreviewing(url.search)) {
|
|
422
|
+
throw new Response("Page Not Found", {
|
|
423
|
+
status: 404,
|
|
424
|
+
statusText: "Page not found in Builder.io",
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return { page, builderApiKey };
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
// Define and render the page.
|
|
432
|
+
export default function Page() {
|
|
433
|
+
const { page, builderApiKey } = useLoaderData${n?"<typeof loader>":""}();
|
|
434
|
+
// Render the page content from Builder.io
|
|
435
|
+
return (
|
|
436
|
+
<Content
|
|
437
|
+
model="${r}"
|
|
438
|
+
apiKey={builderApiKey}
|
|
439
|
+
content={page}
|
|
440
|
+
customComponents={CUSTOM_COMPONENTS}
|
|
441
|
+
/>
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
`:`
|
|
396
445
|
import { BuilderComponent, builder } from "@builder.io/react";
|
|
397
446
|
import { useLoaderData } from "@remix-run/react";
|
|
398
447
|
import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
|
|
@@ -449,11 +498,11 @@ export default function Page() {
|
|
|
449
498
|
${n?`
|
|
450
499
|
declare global {
|
|
451
500
|
interface Env {
|
|
452
|
-
${
|
|
501
|
+
${tt}: string;
|
|
453
502
|
}
|
|
454
503
|
}
|
|
455
504
|
`:""}
|
|
456
|
-
`}async function
|
|
505
|
+
`}async function Yi(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:p}=Gi(e),l=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${l}`),!l){let u=await e.formatCode(i,s);await e.writeFile(i,u),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,p),t.push({filePath:a,modifiedType:"create"})),i}function Gi(e){let t=e.typescriptEnabled,r=`
|
|
457
506
|
import { useState } from "react";
|
|
458
507
|
import styles from "./styles.module.css";
|
|
459
508
|
${t?`
|
|
@@ -516,23 +565,82 @@ export default Counter;
|
|
|
516
565
|
font-size: 42px;
|
|
517
566
|
text-align: center;
|
|
518
567
|
}
|
|
519
|
-
`.trimStart();return{component:r,styles:n}}async function
|
|
568
|
+
`.trimStart();return{component:r,styles:n}}async function Hi(e,t){let n=(await de(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await de(e,n.id,!0,!1,null,null,!0,!1)}async function gt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Xi(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function Xi(e){let t=e.sdkVersion===D.gen2;return e.typescriptEnabled?`import type { RegisteredComponent } from ${t?'"@builder.io/sdk-react"':'"@builder.io/react"'};
|
|
520
569
|
|
|
521
570
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
522
571
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
523
572
|
];
|
|
524
|
-
`}async function
|
|
573
|
+
`}async function fr(e){let t=await Zi(e);return{builderPageOptions:async()=>{let n="/builder-demo",o=t.hasLocaleParam?`/en-us${n}`:void 0;return{templateContentId:"a5c9eef7909d4fc99554264a17de22c9",pathname:n,localePathname:o,title:"Builder + Remix Demo Page"}},ensureBuilderSetup:()=>cr(t),ensureFigmaImportPage:()=>mr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>de(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await de(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>de(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>de(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>de(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>de(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>et(t),setPublicApiKey:n=>ar(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===D.gen2?[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-react"}]:[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function Zi(e){let t=await na(e),r=e.getRootDir(),n=await ra(e),o=e.dirname(n),i=e.join(o,"components"),a=await ea(e),s=`builder-registry.${a?"ts":"js"}`,p=e.join(o,s),l={},d={...e,registryPath:p,remixConfigPath:t,typescriptEnabled:a,appDir:o,componentsDir:i,routesDir:n,hasLocaleParam:await ta(e,n),addExternalPackage:u=>{l[e.join(r,u,"index.ts")]=`export * from "${u}";`},readFileSync:u=>l[u]??e.readFileSync(u),existsSync:u=>!!l[u]||e.existsSync(u),readdirSync:u=>{let c=e.readdirSync(u);return u===r?[...c,...Object.keys(l).map(m=>m.slice(r.length+1))]:c},readdir:async u=>{let c=await e.readdir(u);return u===r?[...c,...Object.keys(l).map(m=>m.slice(r.length+1))]:c}};return e.sdkVersion?d.sdkVersion=e.sdkVersion:d.sdkVersion=await Me(d),d}function ea(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function ta(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function na(e){let t=["remix.config.ts","remix.config.js","vite.config.ts","vite.config.js"];for(let r of t){let n=e.join(e.getRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find Remix config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}async function ra(e){let t=await ze(e,e.getRootDir(),"routes");if(t)return t;throw new Error(`Could not find Remix "routes" directory in "${e.getRootDir()}". Please ensure this command is ran from within your Remix project's directory.`)}async function nt(e){let t=[".env"],r=e.configType==="vite"?rt:xt;return await Ee(e,t,r)}async function dr(e,t){let r=await nt(e),n=await Te(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var rt="VITE_PUBLIC_BUILDER_KEY",xt="YOUR_PUBLIC_BUILDER_KEY";function gr(e,t){let r=`Builder.registerComponent(
|
|
525
574
|
`;r+=` ${t.importName},
|
|
526
575
|
`,r+=` {
|
|
527
576
|
name: "${t.name}",
|
|
528
577
|
}
|
|
529
|
-
`,r+=");";let n=
|
|
578
|
+
`,r+=");";let n=lt(e,r);return Ut(e,n,t)}function Ut(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=K(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function xr(e){let t=await e.readFile(e.registryPath);return t?oa(e,t):{components:[],sourceFile:v(e,"")}}async function oa(e,t){let r=v(e,t);return e.sdkVersion===D.gen2?sa(e,r):ia(e,r)}async function ia(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let l=i.arguments;if(l.length<2)continue;let d=l[1];if(!e.ts.isObjectLiteralExpression(d))continue;let u=l[0];if(e.ts.isIdentifier(u)){let c=await aa(e,t,n,u,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:J(r)}}async function aa(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(l=>e.ts.isImportDeclaration(l)),p=s.find(l=>l.importClause&&l.importClause.name?.text===n.text);if(p){let l=p.moduleSpecifier;if(!e.ts.isStringLiteral(l))return null;a.filePath=await zt(e,l.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=L(e,a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let l=s.find(c=>!c.importClause||!c.importClause.namedBindings||!e.ts.isNamedImports(c.importClause.namedBindings)?!1:c.importClause.namedBindings.elements.some(m=>m.name.text===n.text));if(!l)return null;let d=l.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;let u=await zt(e,d.text);a.filePath=await zt(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),await e.exists(u)?a.importPath=L(e,a.filePath):(a.externalImportPath=d.text,a.importPath=a.externalImportPath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=Q(e,a,o),a.displayFilePath=A(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName,a.externalImportPath)),a}function zt(e,t){return He(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function sa(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await qt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function qt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};_e(e,r)&&(n.acceptsChildren=!0);for(let i of r.properties){if(!e.ts.isPropertyAssignment(i)||!e.ts.isIdentifier(i.name))continue;if(I(e,i)==="component"){let s,{initializer:p}=i;if(e.ts.isIdentifier(p)&&(s=p.text),!s)continue;n.name===""&&(n.name=j(s)),n.importName=s;let l=await ae(e,e.registryPath,t,s);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,await e.exists(l.filePath)?n.importPath=L(e,l.filePath):(n.externalImportPath=l.importPath,n.importPath=n.externalImportPath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let d=t.statements.filter(c=>e.ts.isImportDeclaration(c)),u=d.find(c=>c.importClause&&c.importClause.name?.text===s);if(u){let c=u.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;n.exportName="default"}else{let c=d.find(x=>!x.importClause||!x.importClause.namedBindings||!e.ts.isNamedImports(x.importClause.namedBindings)?!1:x.importClause.namedBindings.elements.some(f=>f.name.text===s));if(!c)return null;let m=c.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;n.exportName=s}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}async function ge(e,t,r,n,o,i,a,s){let p=await we(e),[l,d,u,c]=await Promise.all([Nn(e,p),xr(e),Jt(e),nt(e)]),m=l.map(P=>P.cmpInfo),x=d.components,f={components:te(m,x),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(m),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await Ve(e,f.components),f;let g=!1,h=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let P=C.map(S=>{let N=l.find(B=>B.cmpInfo.id===S);if(!N)throw new Error(`Component ${S} not found`);return N}),b=Array.from(new Set(P.map(S=>S.cmpInfo.filePath))),y=await M(e,b);for(let S of P){let N=f.components.find(T=>T.id===S.cmpInfo.id),B=await Ke(e,S,y);ee(N,B);let k=m.findIndex(T=>T.id===S.cmpInfo.id);m[k].inputs=B;let E=me(S.cmpInfo.id,m,x,r,n,o,i);if(e.sdkVersion===D.gen2){let{elements:T,elmIndex:U,statementIndex:X,statement:$,variableDeclaration:F}=await pa(e,h,S);if(E.addCmpToRegistry)T.push(la(e,E.addCmpToRegistry)),g=!0;else if(E.removeCmpFromRegistry)T.splice(U,1),g=!0;else if(E.updateRegisteredCmp){let z=K(e,T[U],E.updateRegisteredCmp),Ie=e.ts.factory.createIdentifier(E.updateRegisteredCmp.importName);T[U]=e.ts.factory.updateObjectLiteralExpression(z,[e.ts.factory.createPropertyAssignment("component",Ie),...z.properties.slice(1)]),g=!0}if(g&&a){let z=[...h.statements];z[X]=e.ts.factory.updateVariableStatement($,$.modifiers,e.ts.factory.updateVariableDeclarationList($.declarationList,[e.ts.factory.updateVariableDeclaration(F,F.name,F.exclamationToken,F.type,e.ts.factory.createArrayLiteralExpression(le(e,T)))])),h=e.ts.factory.updateSourceFile(h,z),h=hr(e,E,h),h=w(e,h,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-react",isTypeOnly:!0}),h=ue(e,h,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),f.components=E.components,x=E.components.filter(Ie=>Ie.isRegistered)}}else{let T=[...h.statements];E.addCmpToRegistry?(T.push(gr(e,E.addCmpToRegistry)),g=!0):E.removeCmpFromRegistry?(T.splice(E.nodeIndex,1),g=!0):E.updateRegisteredCmp&&(T[E.nodeIndex]=Ut(e,T[E.nodeIndex],E.updateRegisteredCmp),g=!0),g&&a&&(h=e.ts.factory.updateSourceFile(h,T),h=w(e,h,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),h=hr(e,E,h),N?.acceptsChildren&&(h=w(e,h,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=E.components,x=E.components.filter(U=>U.isRegistered))}}}if(g&&a){h=ce(e,h),h=pe(e,h);let P=O(e,h);P=H(P),P=await e.formatCode(e.registryPath,P),await e.writeFile(e.registryPath,P)}return f}async function pa(e,t,r){let n=V(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await qt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}function la(e,t){let r=e.ts.factory.createIdentifier(t.importName);return K(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",r),...t.acceptsChildren?[e.ts.factory.createPropertyAssignment("canHaveChildren",e.ts.factory.createTrue())]:[]],!0),t)}function hr(e,t,r){let n=t.addCmpToRegistry||t.updateRegisteredCmp;if(n){let o=n.externalImportPath?n.externalImportPath:R(e,e.registryPath,n.filePath);n.exportType==="default"?r=w(e,r,{defaultImport:n.importName,importPath:o}):n.exportType==="named"&&(r=w(e,r,{namedImports:[n.importName],importPath:o}))}return r}async function Cr(e){let t=[],r=await ca(e,t);if(await Er(e,t,r),!await e.exists(e.builderComponentPath)){let n=await e.formatCode(e.builderComponentPath,Pr(e,e.builderComponentPath));await e.writeFile(e.builderComponentPath,n),t.push({filePath:e.builderComponentPath,modifiedType:"create"})}return t}async function Sr(e){let t=[];await Er(e,t);let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`,n=e.join(e.componentsDir,r);if(!await e.exists(n)){let o=await e.formatCode(n,Pr(e,n,"figma-imports"));await e.writeFile(n,o),t.push({filePath:n,modifiedType:"create"})}return t}function Pr(e,t,r="page"){let n=e.typescriptEnabled;return e.sdkVersion===D.gen2?`
|
|
579
|
+
import React from "react";
|
|
580
|
+
import {
|
|
581
|
+
Content,
|
|
582
|
+
fetchOneEntry,
|
|
583
|
+
getBuilderSearchParams,
|
|
584
|
+
isPreviewing,
|
|
585
|
+
${n?"type BuilderContent,":""}
|
|
586
|
+
} from "@builder.io/sdk-react";
|
|
587
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(R(e,t,e.registryPath))};
|
|
588
|
+
|
|
589
|
+
// Builder Public API Key set in .env file
|
|
590
|
+
const BUILDER_API_KEY = ${e.configType==="vite"?`import.meta.env.${rt};`:`${xt};`}
|
|
591
|
+
const MODEL_NAME = "${r}";
|
|
592
|
+
|
|
593
|
+
export default function BuilderPage() {
|
|
594
|
+
const [notFound, setNotFound] = React.useState(false);
|
|
595
|
+
const [content, setContent] = React.useState${n?"<BuilderContent | null>":""}(null);
|
|
596
|
+
|
|
597
|
+
// get the page content from Builder
|
|
598
|
+
React.useEffect(() => {
|
|
599
|
+
fetchOneEntry({
|
|
600
|
+
model: MODEL_NAME,
|
|
601
|
+
apiKey: BUILDER_API_KEY,
|
|
602
|
+
userAttributes: {
|
|
603
|
+
urlPath: window.location.pathname,
|
|
604
|
+
},
|
|
605
|
+
options: getBuilderSearchParams(new URL(location.href).searchParams),
|
|
606
|
+
})
|
|
607
|
+
.then((content) => {
|
|
608
|
+
if (content) {
|
|
609
|
+
setContent(content);
|
|
610
|
+
}
|
|
611
|
+
setNotFound(!content);
|
|
612
|
+
})
|
|
613
|
+
.catch((err) => {
|
|
614
|
+
console.log("Oops: ", err);
|
|
615
|
+
});
|
|
616
|
+
}, []);
|
|
617
|
+
|
|
618
|
+
// If no page is found, return
|
|
619
|
+
// a 404 page from your code.
|
|
620
|
+
if (notFound && !isPreviewing()) {
|
|
621
|
+
return <div>404 Page Not Found</div>;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// return the page when found
|
|
625
|
+
return (
|
|
626
|
+
<>
|
|
627
|
+
{/* Render the Builder page */}
|
|
628
|
+
<Content
|
|
629
|
+
content={content}
|
|
630
|
+
model={MODEL_NAME}
|
|
631
|
+
apiKey={BUILDER_API_KEY}
|
|
632
|
+
customComponents={CUSTOM_COMPONENTS}
|
|
633
|
+
/>
|
|
634
|
+
</>
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
`:`
|
|
530
638
|
import React from "react";
|
|
531
639
|
import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
|
|
532
|
-
import ${JSON.stringify(
|
|
640
|
+
import ${JSON.stringify(R(e,t,e.registryPath))};
|
|
533
641
|
|
|
534
642
|
// Builder Public API Key set in .env file
|
|
535
|
-
${e.configType==="vite"?`builder.init(import.meta.env.${
|
|
643
|
+
${e.configType==="vite"?`builder.init(import.meta.env.${rt}${n?"!":""})`:`builder.init("${xt}")`}
|
|
536
644
|
|
|
537
645
|
export default function BuilderPage() {
|
|
538
646
|
const isPreviewingInBuilder = useIsPreviewing();
|
|
@@ -543,7 +651,7 @@ export default function BuilderPage() {
|
|
|
543
651
|
React.useEffect(() => {
|
|
544
652
|
async function fetchContent() {
|
|
545
653
|
const content = await builder
|
|
546
|
-
.get("
|
|
654
|
+
.get("${r}", {
|
|
547
655
|
url: window.location.pathname,
|
|
548
656
|
})
|
|
549
657
|
.promise();
|
|
@@ -573,11 +681,11 @@ export default function BuilderPage() {
|
|
|
573
681
|
return (
|
|
574
682
|
<>
|
|
575
683
|
{/* Render the Builder page */}
|
|
576
|
-
<BuilderComponent model="
|
|
684
|
+
<BuilderComponent model="${r}" content={content} />
|
|
577
685
|
</>
|
|
578
686
|
);
|
|
579
687
|
}
|
|
580
|
-
`.trimStart()}async function
|
|
688
|
+
`.trimStart()}async function Er(e,t,r){if(!await e.exists(e.registryPath)){if(e.sdkVersion===D.gen2){let i=ua(e);await e.writeFile(e.registryPath,i)}else await e.writeFile(e.registryPath,"");t.push({filePath:e.registryPath,modifiedType:"create"})}if(!r)return;let o=(await ge(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===r);o&&await ge(e,o.id,!0,!1,null,null,!0,!1)}async function ca(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:p}=ma(e);if(!await e.exists(i)){let l=await e.formatCode(i,s);await e.writeFile(i,l),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,p),t.push({filePath:a,modifiedType:"create"})),i}function ma(e){let t=e.typescriptEnabled,r=`
|
|
581
689
|
"use client"
|
|
582
690
|
import React, { useState } from "react";
|
|
583
691
|
import styles from "./styles.module.css";
|
|
@@ -640,24 +748,29 @@ export default Counter;
|
|
|
640
748
|
font-size: 42px;
|
|
641
749
|
text-align: center;
|
|
642
750
|
}
|
|
643
|
-
`.trimStart();return{component:r,styles:n}}
|
|
751
|
+
`.trimStart();return{component:r,styles:n}}function ua(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-react";
|
|
752
|
+
|
|
753
|
+
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
754
|
+
];`:`export const CUSTOM_COMPONENTS = [
|
|
755
|
+
];
|
|
756
|
+
`}async function Tr(e){let t=await fa(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>Cr(t),ensureFigmaImportPage:()=>Sr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>ge(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),addExternalPackage:n=>{t.addExternalPackage(n)},loadComponent:async n=>{let o=await ge(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>ge(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>ge(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>ge(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>ge(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>nt(t),setPublicApiKey:n=>dr(t,n.publicApiKey),getDependencies:n=>n.sdkVersion===D.gen2?[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-react"}]:[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>re(t),setCache:n=>oe(t,n)}}async function fa(e){let t=await da(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Jt(e),i=`builder-registry.${o?"ts":"js"}`,a={},s={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,configType:"",addExternalPackage:p=>{a[e.join(r,p,"index.ts")]=`export * from "${p}";`},readFileSync:p=>a[p]??e.readFileSync(p),existsSync:p=>!!a[p]||e.existsSync(p),readdirSync:p=>{let l=e.readdirSync(p);return p===r?[...l,...Object.keys(a).map(d=>d.slice(r.length+1))]:l},readdir:async p=>{let l=await e.readdir(p);return p===r?[...l,...Object.keys(a).map(d=>d.slice(r.length+1))]:l}};return e.sdkVersion?s.sdkVersion=e.sdkVersion:s.sdkVersion=await Me(s),t.includes("webpack.config")&&(s.configType="webpack"),t.includes("vite.config")&&(s.configType="vite"),await e.exists(n)?(s.srcDir=n,s.componentsDir=e.join(n,"components"),s.registryPath=e.join(n,i),s.builderComponentPath=e.join(s.srcDir,`builder-page.${o?"tsx":"jsx"}`)):(s.componentsDir=e.join(r,"components"),s.registryPath=e.join(r,i),s.builderComponentPath=e.join(r,`builder-page.${o?"tsx":"jsx"}`)),s}function Jt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function da(e){let t=["vite.config.ts","vite.config.js","webpack.config.js","webpack.config.ts"];for(let r of t){let n=e.join(e.getRootDir(),r);if(await e.exists(n))return n}if(e.ignoreMissingConfig)return"";throw new Error(`Could not find React config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}async function ot(e){return await ga(e,["environment.ts"],ht)}async function Dr(e,t){let r=await ot(e),n=await Sa(e,r.file,r.envKey,t);return{...r,modifiedType:n}}async function ga(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),"src","environments",o),a=await xa(e,i);if(typeof a=="string"&&a.length>0&&a!=="YOUR_API_KEY")return n.envValue=a,n.file=i,n}return n.file=e.join(e.getRootDir(),"src","environments",t[t.length-1]),n}async function xa(e,t){let r=await e.readFile(t);return r?ha(e,r):""}function ha(e,t){let r=v(e,t),n="",i=Be(e,r,"environment");if(i&&i.statement.declarationList.declarations.length>0){let s=i.statement.declarationList.declarations[0].initializer;s&&e.ts.isObjectLiteralExpression(s)&&s.properties.forEach(p=>{e.ts.isPropertyAssignment(p)&&e.ts.isIdentifier(p.name)&&p.name.text===ht&&e.ts.isStringLiteral(p.initializer)&&(n=p.initializer.text)})}return n}async function Ca(e,t,r,n){let o=v(e,t),a=Be(e,o,"environment");if(a&&a.statement.declarationList.declarations.length>0){let s=a.statement.declarationList,p=s.declarations[0],l=p.initializer;if(l&&e.ts.isObjectLiteralExpression(l)){let d=e.ts.factory.createPropertyAssignment(e.ts.factory.createIdentifier(r),e.ts.factory.createStringLiteral(n)),u=e.ts.factory.createNodeArray([...l.properties,d]),c=e.ts.factory.updateObjectLiteralExpression(l,u),m=e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,c),x=e.ts.factory.updateVariableDeclarationList(s,[m]);return e.ts.factory.updateVariableStatement(a.statement,a.statement.modifiers,x)}return null}return null}async function Sa(e,t,r,n){let o=await e.readFile(t);if(o)if(o.includes(r))e.debug(`"${r}" already set in ${t}`);else{e.debug(`Add "${r}" to ${t}`);let i=await Ca(e,o,r,n);if(i){let a=O(e,i),s=await e.formatCode(t,a);await e.writeFile(t,s)}return"update"}else{e.debug(`Creating new env file with "${r}" at ${t}`);let i=`
|
|
644
757
|
// https://www.builder.io/c/docs/using-your-api-key
|
|
645
758
|
export const environment = {
|
|
646
759
|
production: false,
|
|
647
760
|
builderApiKey: "${n}",
|
|
648
761
|
};
|
|
649
|
-
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var
|
|
762
|
+
`.trimStart(),a=await e.formatCode(t,i);return await e.writeFile(t,a),"create"}return null}var ht="builderApiKey";async function yr(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(Ta(e,i.fileName)||a.startsWith(".")||a==="node_modules"||Pa.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let p=await Ct(e,o,s,i);r.push(...p)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var Pa=new Set([]),Ea=new Set(["node_modules"]);function Ta(e,t){for(let r of Ea)if(e.dirname(t).includes(r))return!0;return!1}async function wr(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return Da(e,t,n)}return null}function Da(e,t,r){let n=v(e,r);return Ct(e,null,t,n)}async function Ct(e,t,r,n){let o=[];r=e.normalize(r);let i=n.statements.filter(p=>e.ts.isClassDeclaration(p)&&Ia(e,p)),a=await wa(e,t,r,n),s=Ra(e,n);return await Promise.all(i.map(async p=>{let l=await ya(e,t,r,p,s);o.push(...l)})),o.push(...a),o}async function vr(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await je(e,t.cmpInfo.filePath,r),a=(await Ct(e,o,t.cmpInfo.filePath,n)).find(s=>s.cmpInfo.id===t.cmpInfo.id);if(!a)throw new Error(`Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return a.cmpInfo.inputs}return[]}async function Ir(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await M(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{if(!a.isRegistered){let s=n.getSourceFile(a.filePath);if(s){let l=(await Ct(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);l&&(a.inputs=Ne(e,o,l.node.fnNode))}}return a}))}async function ya(e,t,r,n,o){let i=[],a=e.relative(e.getRootDir(),r),s=L(e,r),p=n.name?.text;if(!p)return i;let l=!1;n.modifiers&&(l=n.modifiers.some(m=>m.kind===e.ts.SyntaxKind.DefaultKeyword));let d=l?"default":p,u=l?"default":"named",c=[];return n.members.forEach(m=>{if(e.ts.isPropertyDeclaration(m)){let x=e.ts.getDecorators(m);x&&x.forEach(f=>{if(va(e,f)&&e.ts.isIdentifier(m.name)){let g="any";if(m.type&&t){let C=t.getTypeAtLocation(m.type);g=t.typeToString(C)}else g=ba(e,m.type);let h={name:m.name.text,type:o[g]?"string":g};o[g]&&(h.enum=o[g]),c.push(h)}})}}),i.push({cmpInfo:{id:await _(e,r,p),displayFilePath:A(e,r),name:j(p),inputs:c,exportName:d,exportType:u,importName:p,filePath:r,relFilePath:a,importPath:s},node:{name:p,fnNode:n,deps:void 0}}),i}async function wa(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=L(e,r);for(let s of n.statements)if(e.ts.isExportDeclaration(s)&&s.exportClause&&e.ts.isNamedExports(s.exportClause))for(let p of s.exportClause.elements){let l=p.name?.text;if(!l)continue;let d=l,u="named",c=[];if(t){let f=t.getSymbolAtLocation(p.name);if(f){let g=t.getDeclaredTypeOfSymbol(f);t.getPropertiesOfType(g).forEach(C=>{let P=C.getDeclarations();P&&P.forEach(b=>{if(e.ts.isPropertyDeclaration(b)){let y=t.getTypeAtLocation(b),S={name:C.getName(),type:Na(e,t,y)};c.push(S)}})})}}let m=e.ts.isExportSpecifier(p)&&p.parent?p.parent.parent:void 0,x;if(m){let f=m.moduleSpecifier;if(f&&e.ts.isStringLiteral(f)){let g=t?.getSymbolAtLocation(f);if(g&&g.declarations&&g.declarations.length>0){let h=g.declarations[0];(!e.ts.isSourceFile(h)||e.ts.isSourceFile(h)&&h.fileName.includes("node_modules"))&&(x=f.text)}}}o.push({cmpInfo:{id:await _(e,r,l,x),displayFilePath:A(e,r),name:j(l),inputs:c,exportName:d,exportType:u,importName:l,filePath:r,relFilePath:i,importPath:x||a,externalImportPath:x},node:{name:l,fnNode:p,deps:void 0}})}return o}function va(e,t){if(e.ts.isCallExpression(t.expression)){let r=t.expression;if(e.ts.isIdentifier(r.expression))return r.expression?.text==="Input"}return!1}function Ia(e,t){return!!e.ts.getDecorators(t)?.some(o=>e.ts.isCallExpression(o.expression)&&e.ts.isIdentifier(o.expression.expression)&&o.expression.expression.text==="Component")}function ba(e,t){if(!t)return"any";let r="any";switch(t.kind){case e.ts.SyntaxKind.StringKeyword:r="string";break;case e.ts.SyntaxKind.NumberKeyword:r="number";break;case e.ts.SyntaxKind.BooleanKeyword:r="boolean";break;case e.ts.SyntaxKind.TypeReference:e.ts.isTypeReferenceNode(t);break}return r.includes("|")?"string":r}function Ra(e,t){let r={};return e.ts.forEachChild(t,n=>{e.ts.isTypeAliasDeclaration(n)&&e.ts.isUnionTypeNode(n.type)&&n.type.types.every(o=>e.ts.isLiteralTypeNode(o)&&e.ts.isStringLiteral(o.literal))&&(r[n.name.text]=n.type.types.map(o=>o.literal.text))}),r}function Na(e,t,r){let n=t.typeToString(r);if(n==="any"){let o=r.getSymbol();if(o){let i=o.getDeclarations();if(i&&i.length>0){let a=i[0];if(e.ts.isVariableDeclaration(a)){let s=a.type;s&&(n=t.typeToString(t.getTypeAtLocation(s)))}}}}return n}async function St(e,t,r){let n=e.typescriptEnabled?".ts":".js",o=`app.module${n}`,i=e.join(e.appDir,o),a=await e.readFile(i);if(!a){console.error(`Unable to read app.module.${n} at ${i}`);return}let s=await Aa(e,i,t,r,a);if(!s){console.error(`Unable to update app.module.${n} at ${i}`);return}return await e.writeFile(i,s),i}async function Aa(e,t,r,n,o){let i=o,a=v(e,o),s=R(e,t,n);a=w(e,a,{namedImports:[r],importPath:s}),a=w(e,a,{namedImports:["Content"],importPath:"@builder.io/sdk-angular"});let p=[];for(let l of a.statements)if(e.ts.isClassDeclaration(l)&&l.name?.text==="AppModule"){let d=Fa(e,r,l);p.push(d)}else p.push(l);return a=e.ts.factory.updateSourceFile(a,p),i=O(e,a),i}function Fa(e,t,r){let n=e.ts.getDecorators(r);if(n){for(let o of n)if(e.ts.isCallExpression(o.expression)&&e.ts.isIdentifier(o.expression.expression)&&o.expression.expression.text==="NgModule"){let i=o.expression.arguments;if(i.length===1&&e.ts.isObjectLiteralExpression(i[0])){let a=br(e,i[0],"declarations",t);if(a){let s=br(e,a,"imports","Content");if(s&&(a=s),a){let p=e.ts.factory.updateDecorator(o,e.ts.factory.updateCallExpression(o.expression,o.expression.expression,o.expression.typeArguments,[a])),d=[...n.map(u=>u===o?p:u),...e.ts.getModifiers(r)||[]];return e.ts.factory.updateClassDeclaration(r,d,r.name,r.typeParameters,r.heritageClauses,r.members)}}}}}return r}function br(e,t,r,n){let o=[...t.properties],i=o.findIndex(s=>I(e,s)===r);if(i>-1){let s=o[i];if(e.ts.isPropertyAssignment(s)&&s.initializer&&e.ts.isArrayLiteralExpression(s.initializer)){let p=Rr(e,s.initializer,n);return p?(o[i]=e.ts.factory.updatePropertyAssignment(s,s.name,p),e.ts.factory.updateObjectLiteralExpression(t,o)):null}return null}let a=Rr(e,e.ts.factory.createArrayLiteralExpression([],!0),n);return a?e.ts.factory.updateObjectLiteralExpression(t,[...o,e.ts.factory.createPropertyAssignment(r,a)]):null}function Rr(e,t,r){return t.elements.some(o=>e.ts.isIdentifier(o)?o.text===r:!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier(r)])}async function Nr(e){let t=[],r=await La(e,t);t.push(...await Pt(e)),await Oa(e,r);let n="BuilderPage";if(!await e.exists(e.builderPageComponentPath)){let o=await e.formatCode(e.builderPageComponentPath,Fr(e,n,e.builderPageComponentPath,"builder-page","page"));await e.writeFile(e.builderPageComponentPath,o),t.push({filePath:e.builderPageComponentPath,modifiedType:"create"})}if(e.hasAppModule){await St(e,"Counter",r);let o=await St(e,n,e.builderPageComponentPath);o&&t.push({filePath:o,modifiedType:"update"})}return t}async function Ar(e){let t=[];t.push(...await Pt(e));let r="FigmaImportsPage",n=e.join(e.componentsDir,`figma-imports.component.${e.typescriptEnabled?"ts":"js"}`);if(!await e.exists(n)){let o=await e.formatCode(n,Fr(e,r,n,"figma-imports","figma-imports"));await e.writeFile(n,o),t.push({filePath:n,modifiedType:"create"})}if(e.hasAppModule){let o=await St(e,r,n);o&&t.push({filePath:o,modifiedType:"update"})}return t}async function Pt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,ka(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}async function Oa(e,t){let n=(await xe(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await xe(e,n.id,!0,!1,null,null,!0,!1)}function Fr(e,t,r,n,o){let i=!e.hasAppModule,a=R(e,r,e.registryPath),s=e.join(e.getRootDir(),"src","environments","environment.ts"),p=R(e,r,s);return`
|
|
650
763
|
import { Component, Input } from '@angular/core';
|
|
651
764
|
import { fetchOneEntry, type BuilderContent } from '@builder.io/sdk-angular';
|
|
652
|
-
${
|
|
653
|
-
${
|
|
654
|
-
import { environment } from ${JSON.stringify(
|
|
655
|
-
import { CUSTOM_COMPONENTS } from ${JSON.stringify(
|
|
765
|
+
${i?"import { Content } from '@builder.io/sdk-angular';":""}
|
|
766
|
+
${i?"import { CommonModule } from '@angular/common';":""}
|
|
767
|
+
import { environment } from ${JSON.stringify(p)};
|
|
768
|
+
import { CUSTOM_COMPONENTS } from ${JSON.stringify(a)};
|
|
656
769
|
|
|
657
770
|
@Component({
|
|
658
|
-
selector: 'app
|
|
659
|
-
${
|
|
660
|
-
${
|
|
771
|
+
selector: 'app-${n}',
|
|
772
|
+
${i?"standalone: true,":""}
|
|
773
|
+
${i?"imports: [Content, CommonModule],":""}
|
|
661
774
|
template: \`
|
|
662
775
|
<ng-container *ngIf="content; else notFound">
|
|
663
776
|
<builder-content
|
|
@@ -673,12 +786,12 @@ import { CUSTOM_COMPONENTS } from ${JSON.stringify(r)};
|
|
|
673
786
|
</ng-template>
|
|
674
787
|
\`,
|
|
675
788
|
})
|
|
676
|
-
export class
|
|
789
|
+
export class ${t} {
|
|
677
790
|
title = 'builder page';
|
|
678
791
|
|
|
679
|
-
@Input() model ${e.typescriptEnabled?": string":""} = '
|
|
792
|
+
@Input() model ${e.typescriptEnabled?": string":""} = '${o}';
|
|
680
793
|
|
|
681
|
-
apiKey = environment.${
|
|
794
|
+
apiKey = environment.${ht};
|
|
682
795
|
${e.typescriptEnabled?`
|
|
683
796
|
content: BuilderContent | null = null;
|
|
684
797
|
`:`
|
|
@@ -706,12 +819,12 @@ export class BuilderPage {
|
|
|
706
819
|
}
|
|
707
820
|
}
|
|
708
821
|
|
|
709
|
-
`.trimStart()}function
|
|
822
|
+
`.trimStart()}function ka(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/sdk-angular";
|
|
710
823
|
|
|
711
824
|
export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
|
|
712
825
|
];`:`export const CUSTOM_COMPONENTS = [
|
|
713
826
|
];
|
|
714
|
-
`}async function
|
|
827
|
+
`}async function La(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=_a(e);if(!i){let s=await e.formatCode(o,a);await e.writeFile(o,s),t.push({filePath:o,modifiedType:"create"})}return o}function _a(e){return`
|
|
715
828
|
import { Component, Input } from '@angular/core';
|
|
716
829
|
|
|
717
830
|
@Component({
|
|
@@ -779,36 +892,17 @@ export class Counter {
|
|
|
779
892
|
}
|
|
780
893
|
}
|
|
781
894
|
|
|
782
|
-
`.trimStart()}async function va(e,t){let r=`figma-imports.component.${e.typescriptEnabled?"ts":"js"}`,n=e.join(e.componentsDir,r);if(!await e.exists(n)){let o=await e.formatCode(n,ba(e,n));await e.writeFile(n,o),t.push({filePath:n,modifiedType:"create"})}}function ba(e,t){let r=!e.hasAppModule,n=v(e,t,e.builderPageComponentPath);return`
|
|
783
|
-
import { Component } from '@angular/core';
|
|
784
|
-
${r?"import { CommonModule } from '@angular/common';":""}
|
|
785
|
-
|
|
786
|
-
${r?`import { BuilderPage } from ${JSON.stringify(n)};`:""}
|
|
787
|
-
|
|
788
|
-
@Component({
|
|
789
|
-
selector: 'app-figma-imports',
|
|
790
|
-
${r?"standalone: true,":""}
|
|
791
|
-
${r?"imports: [BuilderPage, CommonModule],":""}
|
|
792
|
-
template: \`
|
|
793
|
-
<app-builder-page [model]="'figma-imports'"></app-builder-page>
|
|
794
|
-
\`,
|
|
795
|
-
})
|
|
796
|
-
export class FigmaImportsPage {
|
|
797
|
-
title = 'figma imports';
|
|
798
|
-
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
`.trimStart()}async function yr(e){await Kt(e);let t=await e.readFile(e.registryPath);return t?Ia(e,t):{components:[],sourceFile:E(e,"")}}async function Ia(e,t){let r=E(e,t);return Ra(e,r)}async function Ra(e,t){let r=[],n=M(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Mt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function Mt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let d=s.arguments[0];e.ts.isIdentifier(d)&&(a=d.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await Pe(e,e.registryPath,t,a);if(!p)continue;n.filePath=p.filePath,n.relFilePath=p.relFilePath,n.importPath=k(e,p.filePath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType;let l=await dr(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(f=>f.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=W(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function me(e,t,r,n,o,i,a,s){let p=await De(e),[l,d,f]=await Promise.all([fr(e,p),yr(e),tt(e)]),c=l.map(C=>C.cmpInfo),u=d.components,h={components:ee(c,u),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:ie(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await xr(e,h.components),h;let m=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(T=>{let S=l.find(R=>R.cmpInfo.id===T);if(!S)throw new Error(`Component ${T} not found`);return S}),P=Array.from(new Set(C.map(T=>T.cmpInfo.filePath))),I=await $(e,P);for(let T of C){let S=h.components.find(L=>L.id===T.cmpInfo.id),R=await gr(e,T,I);Z(S,R);let B=c.findIndex(L=>L.id===T.cmpInfo.id);c[B].inputs=R;let F=pe(T.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:w,statementIndex:V,statement:z,variableDeclaration:q}=await Aa(e,g,T);if(F.addCmpToRegistry)y.push(Na(e,F.addCmpToRegistry)),m=!0;else if(F.removeCmpFromRegistry)y.splice(w,1),m=!0;else if(F.updateRegisteredCmp){let L=K(e,y[w],F.updateRegisteredCmp);y[w]=e.ts.factory.updateObjectLiteralExpression(L,[Tr(e,F.updateRegisteredCmp),...L.properties.slice(1)]),m=!0}if(m&&a){let L=[...g.statements];L[V]=e.ts.factory.updateVariableStatement(z,z.modifiers,e.ts.factory.updateVariableDeclarationList(z.declarationList,[e.ts.factory.updateVariableDeclaration(q,q.name,q.exclamationToken,q.type,e.ts.factory.createArrayLiteralExpression(Te(e,y)))])),g=e.ts.factory.updateSourceFile(g,L),S.exportType==="named"?g=D(e,g,{namedImports:[S.importName],importPath:v(e,e.registryPath,S.filePath)}):g=D(e,g,{defaultImport:S.importName,importPath:v(e,e.registryPath,S.filePath)}),g=D(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=Ee(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=F.components,u=F.components.filter(fe=>fe.isRegistered)}}}if(m&&a){g=se(e,g),g=ae(e,g);let C=N(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function Tr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Na(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([Tr(e,t)],!0),t)}async function Aa(e,t,r){let n=M(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await Mt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Dr(e){let t=await Fa(e);return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Sr(t),ensureFigmaImportPage:()=>Pr(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>me(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await me(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>me(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>me(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>me(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>me(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>tt(t),setPublicApiKey:n=>mr(t,n.publicApiKey),getDependencies:n=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>ne(t),setCache:n=>re(t,n)}}async function Fa(e){let t=await La(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Oa(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:"",angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);a.srcDir=n,a.appDir=e.join(n,"app"),a.componentsDir=e.join(a.appDir,"components"),a.registryPath=e.join(a.appDir,i),a.builderPageComponentPath=e.join(a.componentsDir,`builder-page.component.${o?"ts":"js"}`);let s=`app.module.${o?"ts":"js"}`,p=e.join(a.appDir,s);return await e.exists(p)&&(a.hasAppModule=!0),a}function Oa(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function La(e){let t=e.join(e.getRootDir(),"angular.json");if(await e.exists(t))return t;throw new Error(`Could not find Angular config file. Searched for angular.json in "${e.getRootDir()}".`)}var St=po(_r(),1);async function jr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:X(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:J(i.inputs)};return J(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,St.compress)(n);return btoa(JSON.stringify(o))}async function Br(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,St.decompress)(o),a=J(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let p=X(e.normalize(s.filePath)),l=n.components.find(f=>X(f.filePath).endsWith(p)&&f.exportName===s.exportName);if(!l){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${l.id})`,l.filePath),await t.registerComponent({cmpId:l.id});for(let f of s.inputs)e.debug(`set input (${l.id})`),await t.setRegisteredComponentInput({cmpId:l.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${l.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:l.id,name:s.name,image:s.image,description:s.description});a=J(d)}return a}var te={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Rm={[te.react]:[{version:O.gen1,recommended:!0}],[te.remix]:[{version:O.gen1,recommended:!1}],[te.angular]:[{version:O.gen2,recommended:!0}],[te.next]:[{version:O.gen1,recommended:!0},{version:O.gen2,recommended:!1}],[te.qwik]:[{version:O.gen2,recommended:!0}]};var os={"@builder.io/qwik-city":Gn,next:Vn,"@remix-run/react":or,react:ur,"@angular/core":Dr},is={"@builder.io/qwik-city":te.qwik,next:te.next,"@remix-run/react":te.remix,react:te.react,"@angular/core":te.angular};async function as(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await ve(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getRootDir()}`);for(let t of e.frameworks){let r=os[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>jr(e,n),importRegistry:i=>Br(e,n,i),framework:is[t.name]}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Vr(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,c){let u="",h=0,m=-1,g=0,x;for(let C=0;C<=f.length;++C){if(C<f.length)x=f.charCodeAt(C);else{if(x===47)break;x=47}if(x===47){if(!(m===C-1||g===1))if(m!==C-1&&g===2){if(u.length<2||h!==2||u.charCodeAt(u.length-1)!==46||u.charCodeAt(u.length-2)!==46){if(u.length>2){let P=u.lastIndexOf("/");if(P!==u.length-1){P===-1?(u="",h=0):(u=u.slice(0,P),h=u.length-1-u.lastIndexOf("/")),m=C,g=0;continue}}else if(u.length===2||u.length===1){u="",h=0,m=C,g=0;continue}}c&&(u.length>0?u+="/..":u="..",h=2)}else u.length>0?u+="/"+f.slice(m+1,C):u=f.slice(m+1,C),h=C-m-1;m=C,g=0}else x===46&&g!==-1?++g:g=-1}return u}let n=function(...c){let u="",h=!1;for(let m=c.length-1;m>=-1&&!h;m--){let g;m>=0?g=c[m]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(u=g+"/"+u,h=g.charCodeAt(0)===47)}return u=r(u,!h),h?u.length>0?"/"+u:"/":u.length>0?u:"."},o=function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0)===47,h=c.charCodeAt(c.length-1)===47;return c=r(c,!u),c.length===0&&!u&&(c="."),c.length>0&&h&&(c+="/"),u?"/"+c:c};return{relative:function(c,u){if(t(c),t(u),c===u||(c=n(c),u=n(u),c===u))return"";let h=1;for(;h<c.length&&c.charCodeAt(h)===47;++h);let m=c.length,g=m-h,x=1;for(;x<u.length&&u.charCodeAt(x)===47;++x);let P=u.length-x,I=g<P?g:P,T=-1,S=0;for(;S<=I;++S){if(S===I){if(P>I){if(u.charCodeAt(x+S)===47)return u.slice(x+S+1);if(S===0)return u.slice(x+S)}else g>I&&(c.charCodeAt(h+S)===47?T=S:S===0&&(T=0));break}let B=c.charCodeAt(h+S),F=u.charCodeAt(x+S);if(B!==F)break;B===47&&(T=S)}let R="";for(S=h+T+1;S<=m;++S)(S===m||c.charCodeAt(S)===47)&&(R.length===0?R+="..":R+="/..");return R.length>0?R+u.slice(x+T):(x+=T,u.charCodeAt(x)===47&&++x,u.slice(x))},resolve:n,join:function(...c){if(c.length===0)return".";let u;for(let h=0;h<c.length;++h){let m=c[h];t(m),m.length>0&&(u===void 0?u=m:u+="/"+m)}return u===void 0?".":o(u)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,u){if(u!==void 0&&typeof u!="string")throw new TypeError('"ext" argument must be a string');t(c);let h=0,m=-1,g=!0,x;if(u!==void 0&&u.length>0&&u.length<=c.length){if(u.length===c.length&&u===c)return"";let C=u.length-1,P=-1;for(x=c.length-1;x>=0;--x){let I=c.charCodeAt(x);if(I===47){if(!g){h=x+1;break}}else P===-1&&(g=!1,P=x+1),C>=0&&(I===u.charCodeAt(C)?--C===-1&&(m=x):(C=-1,m=P))}return h===m?m=P:m===-1&&(m=c.length),c.slice(h,m)}else{for(x=c.length-1;x>=0;--x)if(c.charCodeAt(x)===47){if(!g){h=x+1;break}}else m===-1&&(g=!1,m=x+1);return m===-1?"":c.slice(h,m)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0),h=u===47,m=-1,g=!0;for(let x=c.length-1;x>=1;--x)if(u=c.charCodeAt(x),u===47){if(!g){m=x;break}}else g=!1;return m===-1?h?"/":".":h&&m===1?"//":c.slice(0,m)},extname:function(c){t(c);let u=-1,h=0,m=-1,g=!0,x=0;for(let C=c.length-1;C>=0;--C){let P=c.charCodeAt(C);if(P===47){if(!g){h=C+1;break}continue}m===-1&&(g=!1,m=C+1),P===46?u===-1?u=C:x!==1&&(x=1):u!==-1&&(x=-1)}return u===-1||m===-1||x===0||x===1&&u===m-1&&u===h+1?"":c.slice(u,m)}}}async function ss(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Vr({cwd:r,...e}),o=new Map,i=m=>n.normalize(n.resolve(r(),m)),a=m=>{for(let[g]of o)if((g+"/").startsWith(m))return!0;return m===t()},s=m=>(m=i(m),o.has(m)?!0:a(m)),p=m=>{m=i(m);let g=m===t()?m:m+"/",x=g.split("/").length-1,C=[];for(let[P]of o)if(P.split("/").slice(0,x).join("/")+"/"===g){let S=P.split("/")[x];S&&!C.includes(S)&&C.push(S)}return C.sort()},l=m=>{m=i(m);let g=o.get(m);return typeof g=="string"?g:null},d=m=>(m=i(m),{isFile:()=>o.has(m),isDirectory:()=>!o.has(m)&&a(m)}),f=async m=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(m),P=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(P)).map(I=>I.toString(16).padStart(2,"0")).join("")}let g=0;for(let x=0;x<m.length;x++){let C=m.charCodeAt(x);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,u={getRootDir:t,cwd:r,exists:async m=>s(m),existsSync:s,readdir:async m=>p(m),readdirSync:p,readFile:async m=>l(m),readFileSync:l,stat:async m=>d(m),statSync:d,writeFile:async(m,g)=>{m=i(m),o.set(m,g);let x={path:m,basename:n.basename(m),dirname:n.dirname(m),extname:n.extname(m)};for(let C of c)await C(x)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",formatCode:async(m,g)=>g,on:(m,g)=>{m==="change"&&c.add(g)},off:(m,g)=>{m==="change"&&c.delete(g)},debug:(...m)=>{console.debug("[builder-dev-tools]",...m)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null},h=await ve(u);return u.getFrameworks=e.getFrameworks?e.getFrameworks:()=>h,u}async function $r(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Kr(e,n))return o;let a=G(e,n,"cjs"),s=G(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=d.statement;if(!e.ts.isVariableStatement(f))throw new Error(`Expected an export assignment from ${t}`);let c=d.statement;if(e.ts.isVariableStatement(c)){let u=[...c.declarationList.declarations];if(u.length!==1)throw new Error("Expected a single variable declaration");let h=u[0];if(!h.initializer)throw new Error("Expected an initializer on the declaration");let m=h.initializer;if(e.ts.isObjectLiteralExpression(m)||e.ts.isCallExpression(m)){let g="BuilderDevTools()",x=[...n.statements],C=x.indexOf(c);return x[C]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(h,h.name,h.exclamationToken,h.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[m]))])),n=e.ts.factory.updateSourceFile(n,x),n=D(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let p=a[0];if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let f=d.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=nn(e,n);n=c.sourceFile;let u=[...n.statements],h=u.indexOf(d);return u[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,u),o.content=N(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let f=d[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let u=nn(e,n);n=u.sourceFile;let h=[...n.statements],m=h.indexOf(l);return h[m]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(p.node)){let d=p.node,f=p.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let c=f.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let h=p.node.body;if(!e.ts.isBlock(h))throw new Error("Expected a block body on the next config function");let m=[...h.statements],g=m.findIndex(T=>e.ts.isReturnStatement(T));if(g===-1)throw new Error("Expected a return statement on the next config function");let x=m[g],C=nn(e,n);n=C.sourceFile,m[g]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[x.expression]));let P=[...n.statements],I=P.indexOf(f);return P[I]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(h,m)))),n=e.ts.factory.updateSourceFile(n,P),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function Kr(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function nn(e,t){let r=Kr(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function zr(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(qr(e,n))return o;let a=G(e,n,"cjs"),s=G(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let p=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=d.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let c="builderDevTools()",u=ps(e,f.expression);if(!u)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[u]),m=[...n.statements],g=m.indexOf(f);return m[g]=e.ts.factory.updateExportAssignment(f,f.modifiers,h),n=e.ts.factory.updateSourceFile(n,m),n=D(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=N(e,n),o.hasContentUpdates=!0,o}}if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let f=d.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Mr(e,n);n=c.sourceFile;let u=[...n.statements],h=u.indexOf(d);return u[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[f.right]))),n=e.ts.factory.updateSourceFile(n,u),o.content=N(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let f=d[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let c=f.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let u=Mr(e,n);n=u.sourceFile;let h=[...n.statements],m=h.indexOf(l);return h[m]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=N(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function qr(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function Mr(e,t){let r=qr(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function ps(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Ur(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Ur(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Ur(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function Jr(e,t,r){let n=E(e,r),o=G(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let p=[...i.node.arguments];if(p.length===0)throw new Error("Expected an argument in defineConfig()");let l=p[0];if(e.ts.isArrowFunction(l)){let d=ls(e,l);if(!d)return s;p[0]=e.ts.factory.updateArrowFunction(l,l.modifiers,l.typeParameters,l.parameters,l.type,l.equalsGreaterThanToken,d);let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,p)),n=e.ts.factory.updateSourceFile(n,f),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=N(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(l)){let d=rn(e,l);if(!d)return s;let f=[...n.statements],c=f.indexOf(a);return f[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,f),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=N(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let p=rn(e,a.expression);if(!p)return s;let l=[...n.statements],d=l.indexOf(a);return l[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,p),n=e.ts.factory.updateSourceFile(n,l),n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=N(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function ls(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=rn(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function rn(e,t){if(ms(e)){let i=cs(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Qr(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Qr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Qr(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function cs(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=us(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=on(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function us(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=on(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=on(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function on(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function ms(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function Wr(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Gr(e,t,r){e.debug("Angular config updates are currently in progress...");try{await gs(e)}catch{console.error("Unable to update package.json.")}return await fs(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function fs(e){let t=e.getRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await ds(e,o);await e.writeFile(n,i)}async function ds(e,t){let r=t,n=E(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=D(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
895
|
+
`.trimStart()}async function Or(e){await Pt(e);let t=await e.readFile(e.registryPath);return t?ja(e,t):{components:[],sourceFile:v(e,"")}}async function ja(e,t){let r=v(e,t);return Ba(e,r)}async function Ba(e,t){let r=[],n=V(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Qt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:J(r)}}async function Qt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(I(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){let l=s.arguments[0];e.ts.isIdentifier(l)&&(a=l.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let p=await ae(e,e.registryPath,t,a);if(!p)continue;if(n.filePath=p.filePath,n.relFilePath=p.relFilePath,await e.exists(p.filePath)?n.importPath=L(e,p.filePath):(n.externalImportPath=p.importPath,n.importPath=n.externalImportPath),n.displayFilePath=p.displayFilePath,n.exportType=p.exportType,n.externalImportPath)n.exportName=a;else{let l=await wr(e,p.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let d=l.find(u=>u.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}}continue}}return n=Q(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName,n.externalImportPath)),n}async function xe(e,t,r,n,o,i,a,s){let p=await we(e),[l,d,u]=await Promise.all([yr(e,p),Or(e),ot(e)]),c=l.map(C=>C.cmpInfo),m=d.components,x={components:te(c,m),registryPath:e.registryPath,registryDisplayPath:A(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:se(c),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return x.components=await Ir(e,x.components),x;let f=!1,g=d.sourceFile,h=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(h.length>0){let C=h.map(y=>{let S=l.find(N=>N.cmpInfo.id===y);if(!S)throw new Error(`Component ${y} not found`);return S}),P=Array.from(new Set(C.map(y=>y.cmpInfo.filePath))),b=await M(e,P);for(let y of C){let S=x.components.find(F=>F.id===y.cmpInfo.id),N=await vr(e,y,b);ee(S,N);let B=c.findIndex(F=>F.id===y.cmpInfo.id);c[B].inputs=N;let k=me(y.cmpInfo.id,c,m,r,n,o,i),{elements:E,elmIndex:T,statementIndex:U,statement:X,variableDeclaration:$}=await Ka(e,g,y);if(k.addCmpToRegistry)E.push(Va(e,k.addCmpToRegistry)),f=!0;else if(k.removeCmpFromRegistry)E.splice(T,1),f=!0;else if(k.updateRegisteredCmp){let F=K(e,E[T],k.updateRegisteredCmp);E[T]=e.ts.factory.updateObjectLiteralExpression(F,[kr(e,k.updateRegisteredCmp),...F.properties.slice(1)]),f=!0}if(f&&a){let F=[...g.statements];F[U]=e.ts.factory.updateVariableStatement(X,X.modifiers,e.ts.factory.updateVariableDeclarationList(X.declarationList,[e.ts.factory.updateVariableDeclaration($,$.name,$.exclamationToken,$.type,e.ts.factory.createArrayLiteralExpression(le(e,E)))])),g=e.ts.factory.updateSourceFile(g,F),S.exportType==="named"?g=w(e,g,{namedImports:[S.importName],importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)}):g=w(e,g,{defaultImport:S.importName,importPath:S.externalImportPath?S.externalImportPath:R(e,e.registryPath,S.filePath)}),g=w(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-angular",isTypeOnly:!0}),g=ue(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x.components=k.components,m=k.components.filter(z=>z.isRegistered)}}}if(f&&a){g=ce(e,g),g=pe(e,g);let C=O(e,g);C=H(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return x}function kr(e,t){let r=e.ts.factory.createIdentifier(t.importName);return e.ts.factory.createPropertyAssignment("component",r)}function Va(e,t){return K(e,e.ts.factory.createObjectLiteralExpression([kr(e,t)],!0),t)}async function Ka(e,t,r){let n=V(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await Qt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Lr(e){let t=await $a(e),r={};return{builderPageOptions:async()=>({templateContentId:"f0b8016ac92e474699293211a268ebaa",pathname:"/builder-demo",title:"Builder + Angular Demo Page"}),ensureBuilderSetup:()=>Nr(t),ensureFigmaImportPage:()=>Ar(t),getRegistryPath:()=>t.registryPath,getRegistry:o=>xe(t,null,!1,!1,null,null,!1,!!o?.readAllInputTypes),addExternalPackage:async o=>{r[o]||(r[o]=`export * from "${o}";`)},loadComponent:async o=>{let i=await xe(t,o.cmpId,!1,!1,null,null,!1,!1);return{...i,component:i.components.find(a=>a.id===o.cmpId)}},registerComponent:o=>xe(t,o.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:o=>xe(t,o.cmpId,!1,!1,o,null,!0,!1),setRegisteredComponentInput:o=>xe(t,o.cmpId,!1,!1,null,o,!0,!1),unregisterComponent:o=>xe(t,o.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>ot(t),setPublicApiKey:o=>Dr(t,o.publicApiKey),getDependencies:o=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-angular"},{name:"concurrently"}],getDevRunCommand:()=>"builder-dev",getCache:()=>re(t),setCache:o=>oe(t,o)}}async function $a(e){let t=await Ua(e),r=e.getRootDir(),n=e.join(r,"src"),o=await Ma(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:"",appDir:"",componentsDir:"",registryPath:"",angularConfigPath:t,typescriptEnabled:o,builderPageComponentPath:"",hasAppModule:!1};if(!await e.exists(n))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);a.srcDir=n,a.appDir=e.join(n,"app"),a.componentsDir=e.join(a.appDir,"components"),a.registryPath=e.join(a.appDir,i),a.builderPageComponentPath=e.join(a.componentsDir,`builder-page.component.${o?"ts":"js"}`);let s=`app.module.${o?"ts":"js"}`,p=e.join(a.appDir,s);return await e.exists(p)&&(a.hasAppModule=!0),a}function Ma(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Ua(e){let t=e.join(e.getRootDir(),"angular.json");if(await e.exists(t))return t;throw new Error(`Could not find Angular config file. Searched for angular.json in "${e.getRootDir()}".`)}var vt=Eo(Wr(),1);async function Yr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:Z(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:W(i.inputs)};return W(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,vt.compress)(n);return btoa(JSON.stringify(o))}async function Gr(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,vt.decompress)(o),a=W(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let p=Z(e.normalize(s.filePath)),l=n.components.find(u=>Z(u.filePath).endsWith(p)&&u.exportName===s.exportName);if(!l){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${l.id})`,l.filePath),await t.registerComponent({cmpId:l.id});for(let u of s.inputs)e.debug(`set input (${l.id})`),await t.setRegisteredComponentInput({cmpId:l.id,name:u.name,type:u.type,required:u.required,defaultValue:u.defaultValue,friendlyName:u.friendlyName,helperText:u.helperText});e.debug(`set input (${l.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:l.id,name:s.name,image:s.image,description:s.description});a=W(d)}return a}var ne={react:"react",remix:"remix",angular:"angular",next:"next",qwik:"qwik"},Wu={[ne.react]:[{version:D.gen1,recommended:!0},{version:D.gen2,recommended:!1}],[ne.remix]:[{version:D.gen1,recommended:!1},{version:D.gen2,recommended:!0}],[ne.angular]:[{version:D.gen2,recommended:!0}],[ne.next]:[{version:D.gen1,recommended:!0},{version:D.gen2,recommended:!1}],[ne.qwik]:[{version:D.gen2,recommended:!0}]};async function Hr(e,t){let r=[],n=new Set;async function o(s){let p=e.join(s,"package.json");try{let l=await e.readFile(p);if(l===null)throw new Error(`Failed to read package.json at ${p}`);let d=JSON.parse(l);if(n.has(d.name))return null;n.add(d.name);let u={name:d.name,subPackages:[]},c=await e.readdir(s);for(let m of c)m!=="node_modules"&&(await e.stat(e.join(s,m))).isDirectory()&&u.subPackages.push(m);return r.push(u),u}catch(l){return console.error(`Error reading package.json at ${s}:`,l),null}}let i=e.join(t,"package.json"),a=await e.readFile(i);if(a!==null){let s=JSON.parse(a),p={...s.dependencies,...s.devDependencies};for(let l of Object.keys(p)){let d=e.join(t,"node_modules",l);await o(d)}if(s.workspaces)for(let l of s.workspaces){let d=await e.readdir(e.join(t,l));for(let u of d){let c=e.join(t,l,u);await o(c)}}}return r}var fs={"@builder.io/qwik-city":ir,next:Wn,"@remix-run/react":fr,react:Tr,"@angular/core":Lr},ds={"@builder.io/qwik-city":ne.qwik,next:ne.next,"@remix-run/react":ne.remix,react:ne.react,"@angular/core":ne.angular};async function gs(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await be(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getRootDir()}`);for(let t of e.frameworks){let r=fs[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Yr(e,n),importRegistry:i=>Gr(e,n,i),framework:ds[t.name],findAllDependencies:async()=>await Hr(e,e.getRootDir())}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Xr(e){function t(u){if(typeof u!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(u))}function r(u,c){let m="",x=0,f=-1,g=0,h;for(let C=0;C<=u.length;++C){if(C<u.length)h=u.charCodeAt(C);else{if(h===47)break;h=47}if(h===47){if(!(f===C-1||g===1))if(f!==C-1&&g===2){if(m.length<2||x!==2||m.charCodeAt(m.length-1)!==46||m.charCodeAt(m.length-2)!==46){if(m.length>2){let P=m.lastIndexOf("/");if(P!==m.length-1){P===-1?(m="",x=0):(m=m.slice(0,P),x=m.length-1-m.lastIndexOf("/")),f=C,g=0;continue}}else if(m.length===2||m.length===1){m="",x=0,f=C,g=0;continue}}c&&(m.length>0?m+="/..":m="..",x=2)}else m.length>0?m+="/"+u.slice(f+1,C):m=u.slice(f+1,C),x=C-f-1;f=C,g=0}else h===46&&g!==-1?++g:g=-1}return m}let n=function(...c){let m="",x=!1;for(let f=c.length-1;f>=-1&&!x;f--){let g;f>=0?g=c[f]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(m=g+"/"+m,x=g.charCodeAt(0)===47)}return m=r(m,!x),x?m.length>0?"/"+m:"/":m.length>0?m:"."},o=function(c){if(t(c),c.length===0)return".";let m=c.charCodeAt(0)===47,x=c.charCodeAt(c.length-1)===47;return c=r(c,!m),c.length===0&&!m&&(c="."),c.length>0&&x&&(c+="/"),m?"/"+c:c};return{relative:function(c,m){if(t(c),t(m),c===m||(c=n(c),m=n(m),c===m))return"";let x=1;for(;x<c.length&&c.charCodeAt(x)===47;++x);let f=c.length,g=f-x,h=1;for(;h<m.length&&m.charCodeAt(h)===47;++h);let P=m.length-h,b=g<P?g:P,y=-1,S=0;for(;S<=b;++S){if(S===b){if(P>b){if(m.charCodeAt(h+S)===47)return m.slice(h+S+1);if(S===0)return m.slice(h+S)}else g>b&&(c.charCodeAt(x+S)===47?y=S:S===0&&(y=0));break}let B=c.charCodeAt(x+S),k=m.charCodeAt(h+S);if(B!==k)break;B===47&&(y=S)}let N="";for(S=x+y+1;S<=f;++S)(S===f||c.charCodeAt(S)===47)&&(N.length===0?N+="..":N+="/..");return N.length>0?N+m.slice(h+y):(h+=y,m.charCodeAt(h)===47&&++h,m.slice(h))},resolve:n,join:function(...c){if(c.length===0)return".";let m;for(let x=0;x<c.length;++x){let f=c[x];t(f),f.length>0&&(m===void 0?m=f:m+="/"+f)}return m===void 0?".":o(m)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,m){if(m!==void 0&&typeof m!="string")throw new TypeError('"ext" argument must be a string');t(c);let x=0,f=-1,g=!0,h;if(m!==void 0&&m.length>0&&m.length<=c.length){if(m.length===c.length&&m===c)return"";let C=m.length-1,P=-1;for(h=c.length-1;h>=0;--h){let b=c.charCodeAt(h);if(b===47){if(!g){x=h+1;break}}else P===-1&&(g=!1,P=h+1),C>=0&&(b===m.charCodeAt(C)?--C===-1&&(f=h):(C=-1,f=P))}return x===f?f=P:f===-1&&(f=c.length),c.slice(x,f)}else{for(h=c.length-1;h>=0;--h)if(c.charCodeAt(h)===47){if(!g){x=h+1;break}}else f===-1&&(g=!1,f=h+1);return f===-1?"":c.slice(x,f)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let m=c.charCodeAt(0),x=m===47,f=-1,g=!0;for(let h=c.length-1;h>=1;--h)if(m=c.charCodeAt(h),m===47){if(!g){f=h;break}}else g=!1;return f===-1?x?"/":".":x&&f===1?"//":c.slice(0,f)},extname:function(c){t(c);let m=-1,x=0,f=-1,g=!0,h=0;for(let C=c.length-1;C>=0;--C){let P=c.charCodeAt(C);if(P===47){if(!g){x=C+1;break}continue}f===-1&&(g=!1,f=C+1),P===46?m===-1?m=C:h!==1&&(h=1):m!==-1&&(h=-1)}return m===-1||f===-1||h===0||h===1&&m===f-1&&m===x+1?"":c.slice(m,f)}}}async function xs(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Xr({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[g]of o)if((g+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),p=f=>{f=i(f);let g=f===t()?f:f+"/",h=g.split("/").length-1,C=[];for(let[P]of o)if(P.split("/").slice(0,h).join("/")+"/"===g){let S=P.split("/")[h];S&&!C.includes(S)&&C.push(S)}return C.sort()},l=f=>{f=i(f);let g=o.get(f);return typeof g=="string"?g:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),u=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),P=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(P)).map(b=>b.toString(16).padStart(2,"0")).join("")}let g=0;for(let h=0;h<f.length;h++){let C=f.charCodeAt(h);g=(g<<5)-g+C,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,m={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>p(f),readdirSync:p,readFile:async f=>l(f),readFileSync:l,stat:async f=>d(f),statSync:d,writeFile:async(f,g)=>{f=i(f),o.set(f,g);let h={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of c)await C(h)},hash:u,getDeviceId:async()=>typeof navigator<"u"?u(navigator.userAgent):"",getRepoInfo:async()=>({remoteUrl:"",defaultBranch:"",currentBranch:"",commit:""}),formatCode:async(f,g)=>g,on:(f,g)=>{f==="change"&&c.add(g)},off:(f,g)=>{f==="change"&&c.delete(g)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0",sdkVersion:null,kind:null},x=await be(m);return m.getFrameworks=e.getFrameworks?e.getFrameworks:()=>x,m}async function Zr(e,t,r){let n=v(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(eo(e,n))return o;let a=G(e,n,"cjs"),s=G(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let u=d.statement;if(!e.ts.isVariableStatement(u))throw new Error(`Expected an export assignment from ${t}`);let c=d.statement;if(e.ts.isVariableStatement(c)){let m=[...c.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let x=m[0];if(!x.initializer)throw new Error("Expected an initializer on the declaration");let f=x.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let g="BuilderDevTools()",h=[...n.statements],C=h.indexOf(c);return h[C]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(x,x.name,x.exclamationToken,x.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(g),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,h),n=w(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let p=a[0];if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let u=d.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let c=pn(e,n);n=c.sourceFile;let m=[...n.statements],x=m.indexOf(d);return m[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[u.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=O(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let u=d[0];if(!u.initializer)throw new Error("Expected an initializer on the declaration");let c=u.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let m=pn(e,n);n=m.sourceFile;let x=[...n.statements],f=x.indexOf(l);return x[f]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(p.node)){let d=p.node,u=p.statement;if(!e.ts.isExpressionStatement(u))throw new Error("Expected an expression statement for the default export");let c=u.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let x=p.node.body;if(!e.ts.isBlock(x))throw new Error("Expected a block body on the next config function");let f=[...x.statements],g=f.findIndex(y=>e.ts.isReturnStatement(y));if(g===-1)throw new Error("Expected a return statement on the next config function");let h=f[g],C=pn(e,n);n=C.sourceFile,f[g]=e.ts.factory.updateReturnStatement(h,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[h.expression]));let P=[...n.statements],b=P.indexOf(u);return P[b]=e.ts.factory.updateExpressionStatement(u,e.ts.factory.updateBinaryExpression(c,c.left,c.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(x,f)))),n=e.ts.factory.updateSourceFile(n,P),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function eo(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/next"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function pn(e,t){let r=eo(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function ro(e,t,r){let n=v(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(oo(e,n))return o;let a=G(e,n,"cjs"),s=G(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let p=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let u=d.statement;if(!e.ts.isExportAssignment(u))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(u.expression)){let c="builderDevTools()",m=hs(e,u.expression);if(!m)return o;let x=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[m]),f=[...n.statements],g=f.indexOf(u);return f[g]=e.ts.factory.updateExportAssignment(u,u.modifiers,x),n=e.ts.factory.updateSourceFile(n,f),n=w(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=O(e,n),o.hasContentUpdates=!0,o}}if(!p.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(p.node)||e.ts.isCallExpression(p.node)){let d=p.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let u=d.expression;if(!e.ts.isBinaryExpression(u))throw new Error("Expected a binary expression for the default export");let c=to(e,n);n=c.sourceFile;let m=[...n.statements],x=m.indexOf(d);return m[x]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[u.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=O(e,n),o.hasContentUpdates=!0,o}let l=p.statement;if(e.ts.isVariableStatement(l)){let d=[...l.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let u=d[0];if(!u.initializer)throw new Error("Expected an initializer on the declaration");let c=u.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let m=to(e,n);n=m.sourceFile;let x=[...n.statements],f=x.indexOf(l);return x[f]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,[e.ts.factory.updateVariableDeclaration(u,u.name,u.exclamationToken,u.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,x),o.content=O(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function oo(e,t){for(let r of t.statements)if(e.ts.isVariableStatement(r))for(let n of r.declarationList.declarations){if(!n.initializer||!e.ts.isCallExpression(n.initializer))continue;let o=n.initializer.expression;if(!e.ts.isCallExpression(o)||!e.ts.isIdentifier(o.expression)||o.expression.text!=="require")continue;let i=o.arguments[0];if(!(!i||!e.ts.isStringLiteral(i))&&i.text==="@builder.io/dev-tools/remix"&&e.ts.isIdentifier(n.name))return n.name.text}return null}function to(e,t){let r=oo(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/remix")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}function hs(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=no(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=no(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function no(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createIdentifier('"@builder.io/react"')])}async function ao(e,t,r){let n=v(e,r),o=G(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let p=[...i.node.arguments];if(p.length===0)throw new Error("Expected an argument in defineConfig()");let l=p[0];if(e.ts.isArrowFunction(l)){let d=Cs(e,l);if(!d)return s;p[0]=e.ts.factory.updateArrowFunction(l,l.modifiers,l.typeParameters,l.parameters,l.type,l.equalsGreaterThanToken,d);let u=[...n.statements],c=u.indexOf(a);return u[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,p)),n=e.ts.factory.updateSourceFile(n,u),n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(l)){let d=ln(e,l);if(!d)return s;let u=[...n.statements],c=u.indexOf(a);return u[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,u),n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let p=ln(e,a.expression);if(!p)return s;let l=[...n.statements],d=l.indexOf(a);return l[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,p),n=e.ts.factory.updateSourceFile(n,l),n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=O(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Cs(e,t){let r=t.body;if(!e.ts.isBlock(r))return null;let n=[...r.statements],o=n.findIndex(s=>e.ts.isReturnStatement(s));if(o===-1){let s=e.ts.factory.createReturnStatement(e.ts.factory.createObjectLiteralExpression());n.push(s),o=n.length-1}let i=n[o];if(!i.expression||!e.ts.isObjectLiteralExpression(i.expression))return null;let a=ln(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function ln(e,t){if(Es(e)){let i=Ss(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=io(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=io(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function io(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function Ss(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Ps(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=cn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function Ps(e,t){let r=[...t.properties],n=r.findIndex(i=>I(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=cn(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=cn(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function cn(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Es(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function so(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function lo(e,t,r){e.debug("Angular config updates are currently in progress...");try{await ys(e)}catch{console.error("Unable to update package.json.")}return await Ts(e),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}async function Ts(e){let t=e.getRootDir(),r=e.join(t,"src");if(!await e.exists(r))throw new Error(`Could not find src directory. Searched for src in "${e.getRootDir()}".`);let n=e.join(r,"main.ts"),o=await e.readFile(n);if(!o)throw new Error(`Unable to read main.ts at ${n}`);let i=await Ds(e,o);await e.writeFile(n,i)}async function Ds(e,t){let r=t,n=v(e,t),o=!1;for(let a of n.statements)if(e.ts.isExpressionStatement(a)&&e.ts.isCallExpression(a.expression)&&e.ts.isPropertyAccessExpression(a.expression.expression)&&e.ts.isCallExpression(a.expression.expression.expression)&&e.ts.isIdentifier(a.expression.expression.expression.expression)&&a.expression.expression.expression.expression.text==="builderDevTools"){o=!0;break}n=w(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/angular"});let i=`
|
|
802
896
|
builderDevTools().catch((err: Error) =>
|
|
803
897
|
console.error("Error starting dev tools:", err)
|
|
804
|
-
);`;return r=
|
|
805
|
-
`}var
|
|
898
|
+
);`;return r=O(e,n),o||(r+=i),r}async function ys(e){let t=e.getRootDir(),r=e.join(t,"package.json"),n=await e.readFile(r);if(!n)throw new Error(`Unable to read package.json at ${r}`);let o=ws(n);o&&await e.writeFile(r,o)}function ws(e){let t=JSON.parse(e);if(t.scripts=t.scripts||{},t.scripts[po])return;let r=t.scripts.start||t.scripts.dev||"ng serve";return t.scripts[po]=`concurrently "${r}" "${vs}"`,JSON.stringify(t,null,2)+`
|
|
899
|
+
`}var po="builder-dev",vs="npx builder-dev-tools";var mo=[{id:"angular",configFileNames:["angular.json"],ensureConfigPlugin:lo},{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:Zr},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:ao},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:ro},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:so}];async function uo(e){let t=e.resolve("/");for(let n of mo)for(let o of n.configFileNames){let i=e.getRootDir();for(let a=0;a<10;a++)try{let s=e.join(i,o),p=e.readFileSync(s);if(typeof p=="string")return{id:n.id,filePath:s,content:p};if(i===t)break;i=e.dirname(i)}catch(s){if((s?.message??"").includes("Invalid path"))break;throw s}}if((await be(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,co),{id:"next",filePath:n,content:co}}return null}async function Is(e){let t=await uo(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await mo.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=H(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var co=`
|
|
806
900
|
/** @type {import('next').NextConfig} */
|
|
807
901
|
const nextConfig = {
|
|
808
902
|
}
|
|
809
903
|
|
|
810
904
|
module.exports = nextConfig
|
|
811
|
-
`.trimStart();var
|
|
905
|
+
`.trimStart();var fo="/~builder-dev-tools.js";function bs(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(fo,e);t.searchParams.set("v",It);let r=JSON.stringify(It),n=`/* Builder Devtools v${It} */
|
|
812
906
|
`;return n+=`(() => {
|
|
813
907
|
`,n+=` if (typeof document !== "undefined") {
|
|
814
908
|
`,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]");
|
|
@@ -821,4 +915,4 @@ module.exports = nextConfig
|
|
|
821
915
|
`,n+=` }
|
|
822
916
|
`,n+=` }
|
|
823
917
|
`,n+=`})();
|
|
824
|
-
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var
|
|
918
|
+
`,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var It="1.1.26";export{gs as createDevTools,xs as createDevToolsSys,be as detectFrameworks,fn as detectFrameworksFromPackageJson,Is as ensureConfigPlugin,uo as findBuildToolConfig,bs as getClientScript,gn as parseDotEnvContent,It as version};
|