@builder.io/dev-tools 0.2.30 → 0.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/core/index.cjs CHANGED
@@ -1,14 +1,14 @@
1
- "use strict";var gr=Object.create;var Be=Object.defineProperty;var xr=Object.getOwnPropertyDescriptor;var hr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,Cr=Object.prototype.hasOwnProperty;var W=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),wr=(e,t)=>{for(var r in t)Be(e,r,{get:t[r],enumerable:!0})},_t=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hr(t))!Cr.call(e,o)&&o!==r&&Be(e,o,{get:()=>t[o],enumerable:!(n=xr(t,o))||n.enumerable});return e};var yr=(e,t,r)=>(r=e!=null?gr(Sr(e)):{},_t(t||!e||!e.__esModule?Be(r,"default",{value:e,enumerable:!0}):r,e)),Tr=e=>_t(Be({},"__esModule",{value:!0}),e);var yt=W(et=>{"use strict";Object.defineProperty(et,"__esModule",{value:!0});function jn(e){return Object.prototype.toString.call(e)}et.getType=jn;function Zo(e){throw new TypeError("unsupported data type: "+jn(e))}et.throwUnknownDataType=Zo});var bt=W(q=>{"use strict";Object.defineProperty(q,"__esModule",{value:!0});var Q="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);Q+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);Q+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);Q+=t}var we=Q.length,Et={};for(let e=0;e<we;e++){let t=Q[e];Et[t]=e}function Dt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Et[o];i*=r,t+=i,r*=we}return t}q.s_to_int=Dt;function _n(e){let t=BigInt(0),r=BigInt(1),n=BigInt(we);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Et[i]);a*=r,t+=a,r*=n}return t}q.s_to_big_int=_n;function vt(e){if(e===0)return Q[0];let t=[];for(;e!==0;){let r=e%we,n=Q[r];t.push(n),e-=r,e/=we}return t.reverse().join("")}q.int_to_s=vt;function Bn(e){let t=BigInt(0),r=BigInt(we);if(e===t)return Q[0];let n=[];for(;e!==t;){let o=e%r,i=Q[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}q.big_int_to_s=Bn;function nt(e){return e.split("").reverse().join("")}function Vn(e){if(e<0)return"-"+Vn(-e);let[t,r]=e.toString().split(".");if(!r)return vt(e);let n;r&&([r,n]=r.split("e")),t=tt(t),r=nt(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=nt(n),n=tt(n),o+=n}return o}q.num_to_s=Vn;function tt(e){let t=+e;return t.toString()===e?vt(t):":"+Bn(BigInt(e))}q.int_str_to_s=tt;function Tt(e){return e[0]===":"?_n(e.substring(1)).toString():Dt(e).toString()}function $n(e){if(e[0]==="-")return-$n(e.substr(1));let[t,r,n]=e.split(".");if(!r)return Dt(t);t=Tt(t),r=Tt(r),r=nt(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Tt(n),n=nt(n),o+=i?-n:+n}return+o}q.s_to_num=$n});var It=W(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});var Pt=bt();function ei(e){return"n|"+Pt.num_to_s(e)}J.encodeNum=ei;function ti(e){return e=e.replace("n|",""),Pt.s_to_num(e)}J.decodeNum=ti;function ni(e){return typeof e=="number"?e:Pt.s_to_int(e)}J.decodeKey=ni;function ri(e){return e?"b|T":"b|F"}J.encodeBool=ri;function oi(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}J.decodeBool=oi;function ii(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}J.encodeStr=ii;function ai(e){return e[0]+e[1]==="s|"?e.substr(2):e}J.decodeStr=ai});var zn=W(Nt=>{"use strict";Object.defineProperty(Nt,"__esModule",{value:!0});Nt.config={sort_key:!1}});var Ft=W(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});var si=zn(),li=yt(),Rt=It(),ci=bt();function pi(e){return e.store.toArray()}ce.memToValues=pi;function Un(){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}}}ce.makeInMemoryStore=Un;function Mn(){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}}}ce.makeInMemoryCache=Mn;function ui(){return{store:Un(),cache:Mn(),keyCount:0}}ce.makeInMemoryMemory=ui;function le(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=ci.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function fi(e,t){si.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=Le(e,t,void 0);return e.cache.setSchema(r,n),n}function Le(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return Le(e,null,r);break;case"object":if(t===null)return le(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":Le(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),le(e,n)}else{let n=Object.keys(t);if(n.length===0)return le(e,"o|");let o="o",i=fi(e,n);o+="|"+i;for(let a of n){let s=t[a],l=Le(e,s,t);o+="|"+l}return le(e,o)}case"boolean":return le(e,Rt.encodeBool(t));case"number":return le(e,Rt.encodeNum(t));case"string":return le(e,Rt.encodeStr(t))}return li.throwUnknownDataType(t)}ce.addValue=Le});var Lt=W(ke=>{"use strict";Object.defineProperty(ke,"__esModule",{value:!0});var mi=yt(),rt=It(),At=Ft();function di(e){let t=At.makeInMemoryMemory(),r=At.addValue(t,e,void 0);return[At.memToValues(t),r]}ke.compress=di;function gi(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=Oe(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let l=i[s-2],m=n[s];m=Oe(e,m),r[l]=m}return r}function xi(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=Oe(e,a),o[i]=a}return o}function Oe(e,t){if(t===""||t==="_")return null;let r=rt.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 rt.decodeBool(n);case"o|":return gi(e,n);case"n|":return rt.decodeNum(n);case"a|":return xi(e,n);default:return rt.decodeStr(n)}}return mi.throwUnknownDataType(n)}ke.decode=Oe;function hi(e){let[t,r]=e;return Oe(t,r)}ke.decompress=hi});var Qn=W(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});function Si(e){for(let t in e)e[t]===void 0&&delete e[t]}ot.trimUndefined=Si;function Ci(e){Kn(e,new Set)}ot.trimUndefinedRecursively=Ci;function Kn(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)&&Kn(n,t)}}});var Wn=W(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});var qn=Lt();te.compress=qn.compress;te.decompress=qn.decompress;var wi=Lt();te.decode=wi.decode;var yi=Ft();te.addValue=yi.addValue;var Jn=Qn();te.trimUndefined=Jn.trimUndefined;te.trimUndefinedRecursively=Jn.trimUndefinedRecursively});var vi={};wr(vi,{createDevTools:()=>Gn,createDevToolsSys:()=>Zn,detectFrameworks:()=>H,detectFrameworksFromPackageJson:()=>at,ensureConfigPlugin:()=>ur,findBuildToolConfig:()=>jt,getClientScript:()=>mr,parseDotEnvContent:()=>st,version:()=>je});module.exports=Tr(vi);async function Bt(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 Vt(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 ye(e,t,r){let n=await e.readdir(t);return n.includes(r)?e.join(t,r):(await Promise.all(n.map(async i=>{if(i.startsWith(".")||i==="node_modules")return;let a=e.join(t,i);if((await e.stat(a)).isDirectory()){let l=await ye(e,a,r);if(l)return l}}))).find(i=>typeof i=="string")}async function H(e){let t=[],r=await Bt(e,e.getRootDir());if(r){let n=at(r);t.push(...n)}return t}function at(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of Er)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var Er=["@shopify/remix-oxygen","@shopify/hydrogen","@builder.io/qwik-city","@remix-run/react","@sveltejs/kit","astro","gatsby","next","nuxt","@builder.io/qwik","angular","react","solid-js","svelte","vue"];async function ue(e){let t=$t(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function fe(e,t){t=typeof t=="object"&&t!=null?t:{};let r=$t(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function $t(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function me(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await Dr(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 Dr(e,t){let r=await e.readFile(t);return typeof r=="string"?st(r):null}function st(e){let t={},r=e.replace(/\r\n?/gm,`
2
- `),n;for(;(n=vr.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 vr=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function de(e,t,r,n){let o="# https://www.builder.io/c/docs/using-your-api-key",i=await e.readFile(t);if(i)if(i.includes(r))if(i.includes(n))e.debug(`"${r}" with "${n}" already set in ${t}`);else return e.debug(`Replace "${r}" in ${t}`),i=i.replace(new RegExp(`${r}=.*`),`${r}=${n}`),await e.writeFile(t,i),"update";else return e.debug(`Append "${r}" to ${t}`),i+=`
1
+ "use strict";var xr=Object.create;var Ve=Object.defineProperty;var hr=Object.getOwnPropertyDescriptor;var Sr=Object.getOwnPropertyNames;var Cr=Object.getPrototypeOf,wr=Object.prototype.hasOwnProperty;var H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Tr=(e,t)=>{for(var r in t)Ve(e,r,{get:t[r],enumerable:!0})},Bt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Sr(t))!wr.call(e,o)&&o!==r&&Ve(e,o,{get:()=>t[o],enumerable:!(n=hr(t,o))||n.enumerable});return e};var yr=(e,t,r)=>(r=e!=null?xr(Cr(e)):{},Bt(t||!e||!e.__esModule?Ve(r,"default",{value:e,enumerable:!0}):r,e)),Er=e=>Bt(Ve({},"__esModule",{value:!0}),e);var yt=H(tt=>{"use strict";Object.defineProperty(tt,"__esModule",{value:!0});function _n(e){return Object.prototype.toString.call(e)}tt.getType=_n;function ei(e){throw new TypeError("unsupported data type: "+_n(e))}tt.throwUnknownDataType=ei});var bt=H(J=>{"use strict";Object.defineProperty(J,"__esModule",{value:!0});var q="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);q+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);q+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);q+=t}var Te=q.length,Dt={};for(let e=0;e<Te;e++){let t=q[e];Dt[t]=e}function vt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Dt[o];i*=r,t+=i,r*=Te}return t}J.s_to_int=vt;function Bn(e){let t=BigInt(0),r=BigInt(1),n=BigInt(Te);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Dt[i]);a*=r,t+=a,r*=n}return t}J.s_to_big_int=Bn;function Pt(e){if(e===0)return q[0];let t=[];for(;e!==0;){let r=e%Te,n=q[r];t.push(n),e-=r,e/=Te}return t.reverse().join("")}J.int_to_s=Pt;function Vn(e){let t=BigInt(0),r=BigInt(Te);if(e===t)return q[0];let n=[];for(;e!==t;){let o=e%r,i=q[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}J.big_int_to_s=Vn;function rt(e){return e.split("").reverse().join("")}function $n(e){if(e<0)return"-"+$n(-e);let[t,r]=e.toString().split(".");if(!r)return Pt(e);let n;r&&([r,n]=r.split("e")),t=nt(t),r=rt(r),r=nt(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=rt(n),n=nt(n),o+=n}return o}J.num_to_s=$n;function nt(e){let t=+e;return t.toString()===e?Pt(t):":"+Vn(BigInt(e))}J.int_str_to_s=nt;function Et(e){return e[0]===":"?Bn(e.substring(1)).toString():vt(e).toString()}function zn(e){if(e[0]==="-")return-zn(e.substr(1));let[t,r,n]=e.split(".");if(!r)return vt(t);t=Et(t),r=Et(r),r=rt(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Et(n),n=rt(n),o+=i?-n:+n}return+o}J.s_to_num=zn});var Nt=H(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});var It=bt();function ti(e){return"n|"+It.num_to_s(e)}W.encodeNum=ti;function ni(e){return e=e.replace("n|",""),It.s_to_num(e)}W.decodeNum=ni;function ri(e){return typeof e=="number"?e:It.s_to_int(e)}W.decodeKey=ri;function oi(e){return e?"b|T":"b|F"}W.encodeBool=oi;function ii(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}W.decodeBool=ii;function ai(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}W.encodeStr=ai;function si(e){return e[0]+e[1]==="s|"?e.substr(2):e}W.decodeStr=si});var Un=H(Rt=>{"use strict";Object.defineProperty(Rt,"__esModule",{value:!0});Rt.config={sort_key:!1}});var At=H(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});var li=Un(),ci=yt(),Ft=Nt(),pi=bt();function ui(e){return e.store.toArray()}pe.memToValues=ui;function Mn(){let e=[];return{forEach(t){for(let r=0;r<e.length;r++)if(t(e[r])==="break")return},add(t){e.push(t)},toArray(){return e}}}pe.makeInMemoryStore=Mn;function Kn(){let e=Object.create(null),t=Object.create(null);return{getValue(r){return e[r]},getSchema(r){return t[r]},forEachValue(r){for(let[n,o]of Object.entries(e))if(r(n,o)==="break")return},forEachSchema(r){for(let[n,o]of Object.entries(t))if(r(n,o)==="break")return},setValue(r,n){e[r]=n},setSchema(r,n){t[r]=n},hasValue(r){return r in e},hasSchema(r){return r in t}}}pe.makeInMemoryCache=Kn;function fi(){return{store:Mn(),cache:Kn(),keyCount:0}}pe.makeInMemoryMemory=fi;function ce(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=pi.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function mi(e,t){li.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=Oe(e,t,void 0);return e.cache.setSchema(r,n),n}function Oe(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return Oe(e,null,r);break;case"object":if(t===null)return ce(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":Oe(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),ce(e,n)}else{let n=Object.keys(t);if(n.length===0)return ce(e,"o|");let o="o",i=mi(e,n);o+="|"+i;for(let a of n){let s=t[a],l=Oe(e,s,t);o+="|"+l}return ce(e,o)}case"boolean":return ce(e,Ft.encodeBool(t));case"number":return ce(e,Ft.encodeNum(t));case"string":return ce(e,Ft.encodeStr(t))}return ci.throwUnknownDataType(t)}pe.addValue=Oe});var Ot=H(je=>{"use strict";Object.defineProperty(je,"__esModule",{value:!0});var di=yt(),ot=Nt(),Lt=At();function gi(e){let t=Lt.makeInMemoryMemory(),r=Lt.addValue(t,e,void 0);return[Lt.memToValues(t),r]}je.compress=gi;function xi(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=ke(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let l=i[s-2],m=n[s];m=ke(e,m),r[l]=m}return r}function hi(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=ke(e,a),o[i]=a}return o}function ke(e,t){if(t===""||t==="_")return null;let r=ot.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 ot.decodeBool(n);case"o|":return xi(e,n);case"n|":return ot.decodeNum(n);case"a|":return hi(e,n);default:return ot.decodeStr(n)}}return di.throwUnknownDataType(n)}je.decode=ke;function Si(e){let[t,r]=e;return ke(t,r)}je.decompress=Si});var qn=H(it=>{"use strict";Object.defineProperty(it,"__esModule",{value:!0});function Ci(e){for(let t in e)e[t]===void 0&&delete e[t]}it.trimUndefined=Ci;function wi(e){Qn(e,new Set)}it.trimUndefinedRecursively=wi;function Qn(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)&&Qn(n,t)}}});var Hn=H(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});var Jn=Ot();ne.compress=Jn.compress;ne.decompress=Jn.decompress;var Ti=Ot();ne.decode=Ti.decode;var yi=At();ne.addValue=yi.addValue;var Wn=qn();ne.trimUndefined=Wn.trimUndefined;ne.trimUndefinedRecursively=Wn.trimUndefinedRecursively});var Pi={};Tr(Pi,{createDevTools:()=>Xn,createDevToolsSys:()=>er,detectFrameworks:()=>Y,detectFrameworksFromPackageJson:()=>st,ensureConfigPlugin:()=>fr,findBuildToolConfig:()=>_t,getClientScript:()=>dr,parseDotEnvContent:()=>lt,version:()=>_e});module.exports=Er(Pi);async function Vt(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 $t(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 ye(e,t,r){let n=await e.readdir(t);return n.includes(r)?e.join(t,r):(await Promise.all(n.map(async i=>{if(i.startsWith(".")||i==="node_modules")return;let a=e.join(t,i);if((await e.stat(a)).isDirectory()){let l=await ye(e,a,r);if(l)return l}}))).find(i=>typeof i=="string")}async function Y(e){let t=[],r=await Vt(e,e.getRootDir());if(r){let n=st(r);t.push(...n)}return t}function st(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of Dr)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var Dr=["@shopify/remix-oxygen","@shopify/hydrogen","@builder.io/qwik-city","@remix-run/react","@sveltejs/kit","astro","gatsby","next","nuxt","@builder.io/qwik","angular","react","solid-js","svelte","vue"];async function fe(e){let t=zt(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function me(e,t){t=typeof t=="object"&&t!=null?t:{};let r=zt(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function zt(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function de(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await vr(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 vr(e,t){let r=await e.readFile(t);return typeof r=="string"?lt(r):null}function lt(e){let t={},r=e.replace(/\r\n?/gm,`
2
+ `),n;for(;(n=Pr.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 Pr=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function ge(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 Te(e){return await me(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],ne)}async function zt(e,t){let r=await Te(e),n=await de(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ne="NEXT_PUBLIC_BUILDER_API_KEY";function E(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest)}function Ut(e,t=""){let r=E(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function I(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()+`
9
+ `),await e.writeFile(t,i),"create";return null}async function Ee(e){return await de(e,[".env.local",".env.development.local",".env.production.local",".env.development",".env.production",".env"],re)}async function Ut(e,t){let r=await Ee(e),n=await ge(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var re="NEXT_PUBLIC_BUILDER_API_KEY";function E(e,t=""){return e.ts.createSourceFile("module.tsx",typeof t=="string"?t:"",e.ts.ScriptTarget.Latest)}function Mt(e,t=""){let r=E(e,t?.trim());if(r.statements.length===0)throw new Error(`No statements found in code: ${t}`);return r.statements[0]}function I(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 A(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 Ee(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return Mt(o==="index"?e.basename(e.dirname(t)):o)}function Mt(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 N(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 G(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 De(e){return typeof e=="number"}function ge(e){return typeof e=="boolean"}function L(e){return typeof e=="string"}function Ve(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function B(e){return JSON.parse(JSON.stringify(e))}function be(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=br(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,l)=>l!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,ve(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,ve(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function br(e,t,r){return t.properties.findIndex(n=>D(e,n)===r)}function Pe(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return Ir(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return Pr(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 Pr(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=D(e,n);o&&(r[o]=Pe(e,n.initializer))}}return r}function Ir(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Pe(e,r)):[]}function D(e,t){if(t&&e.ts.isPropertyAssignment(t)){let r=t.name;switch(r.kind){case e.ts.SyntaxKind.Identifier:return r.text;case e.ts.SyntaxKind.StringLiteral:case e.ts.SyntaxKind.NumericLiteral:return r.text;case e.ts.SyntaxKind.ComputedPropertyName:let n=r.expression;if(e.ts.isStringLiteral(n)||e.ts.isNumericLiteral(n))return r.expression.text}}}function ve(e,t){return lt(e,t,new WeakSet)}function lt(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)?Nr(e,t,r):typeof t=="object"?Rr(e,t,r):e.ts.factory.createIdentifier(t)}function Nr(e,t,r){let n=t.map(o=>lt(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Rr(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,lt(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function Ie(e,t,r){let n=[];if(!r)return n;let o=[];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 a=t.getTypeAtLocation(r).getCallSignatures();if(a.length>0){let s=a[0].getParameters();s.length>0&&(o=t.getTypeOfSymbolAtLocation(s[0],r).getProperties())}}for(let i of o){let a=Fr(e,t,i);a&&n.push(a)}return n=n.filter(Qt),n.length>0?n:Ar(e,r)}function Fr(e,t,r){let n=r.valueDeclaration,o=r.getName();if(n||(n=r.getDeclarations()?.[0]),n&&e.ts.isPropertySignature(n)){if(o!=="children"&&n.getSourceFile().fileName.includes("node_modules/@types/"))return null;let i="string",a;if(n?.type){let l=t.getTypeFromTypeNode(n.type),m=t.typeToString(l),d=ct(m);d.knownType?i=d.builderType:Or(m)||l.flags&e.ts.TypeFlags.StringLike?i="string":l.flags&e.ts.TypeFlags.NumberLike?i="number":l.flags&e.ts.TypeFlags.IndexedAccess?i="list":l.flags&e.ts.TypeFlags.Object||l.isUnion()&&l.types.every(f=>f.flags&e.ts.TypeFlags.Object)||l.isIntersection()&&l.types.some(f=>f.flags&e.ts.TypeFlags.Object)?i="object":i="string",m!==i&&(a=m)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let l=Br(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},l&&l.length>0&&s.type==="string"&&l.every(jr)?s.enum=l.map(_r):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function Ar(e,t){let r=[],n=e.ts.getJSDocCommentsAndTags(t);for(let o of n)if(!(!e.ts.isJSDoc(o)||!o.tags))for(let i of o.tags){if(!e.ts.isJSDocParameterTag(i)||i.tagName.text!=="param")continue;let s=i.typeExpression?.type;if(!s||!e.ts.isJSDocTypeLiteral(s))continue;let l=s.jsDocPropertyTags;if(l)for(let m of l){if(!e.ts.isJSDocPropertyLikeTag(m))continue;let d=m.name;if(!e.ts.isQualifiedName(d))continue;let f=m.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(Qt)}var Lr=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function Or(e){return typeof e!="string"?!1:!!Lr.some(t=>e.includes(t))}function ct(e){return typeof e=="string"&&(e=e.trim(),kr.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var kr=[{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 jr(e){return/^['"].*['"]$/.test(e)}function _r(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Br=(e,t,r)=>{let n=new Set;Kt(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},Vr=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Kt=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Kt(e,t,o,n)});else if(r.isLiteral()){let o=Vr(e,t,r);n.add(o)}};function Qt(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!$r.has(t.toLowerCase())}var $r=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 re(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=D(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=zr(e,n.initializer);oe(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Pe(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function zr(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Ur(e,n));return r}function Ur(e,t){let r=Pe(e,t),n=Hr(r);return n.isRegistered=!0,n}function X(e,t,r){let n=Kr(r);return t=be(e,t,"name",n.name,!1),t=be(e,t,"description",n.description),t=be(e,t,"image",n.image),t=Mr(e,t,n),Yr(e,t)}function Mr(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 be(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=qr(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 Kr(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Qr)}}function Qr(e){let t={name:e.name,type:e.type};return(L(e.defaultValue)||De(e.defaultValue)||ge(e.defaultValue))&&(t.defaultValue=e.defaultValue),L(e.friendlyName)&&(t.friendlyName=e.friendlyName),L(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 qr(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>D(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=Jr(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>D(e,c)==="name"),s=i.properties.find(c=>D(e,c)==="name"),l=a?.initializer,m=s?.initializer,d=l&&e.ts.isStringLiteral(l)?l.text:"zz",f=m&&e.ts.isStringLiteral(m)?m.text:"zz";return d.toLowerCase().localeCompare(f.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Jr(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=D(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=qt(e,t[n],r);else{let o=qt(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function qt(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=Wr(e,n,r,i);return n=Gr(e,n.filter(i=>{let a=D(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Wr(e,t,r,n){let o=t.findIndex(i=>e.ts.isIdentifier(i.name)&&i.name.text===n);return o>-1?t[o]=e.ts.factory.updatePropertyAssignment(t[o],t[o].name,ve(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,ve(e,r[n]))),t}function oe(e,t){for(let o of t){let i=e.inputs.findIndex(a=>a.name===o.name);i>-1?(o.isRegistered||!e.inputs[i].isRegistered)&&(e.inputs[i]=o):e.inputs.push(o)}let r=e.inputs.some(o=>o.name==="children"),n=e.inputs.some(o=>o.meta?.ts==="ReactNode");r||n?e.acceptsChildren=!0:e.acceptsChildren||(e.acceptsChildren=!1)}function Hr(e){let t=ct(e.type),r={name:e.name.trim(),type:t.builderType};return L(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(L(e.defaultValue)||De(e.defaultValue)||ge(e.defaultValue))&&(r.defaultValue=e.defaultValue),L(e.helperText)&&(r.helperText=e.helperText),ge(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),pt(r)}function pt(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 Yr(e,t){let r=[...t.properties].sort((n,o)=>{let i=D(e,n)||"zz",a=D(e,o)||"zz";if(i==="inputs")return 1;let s=Jt.indexOf(i),l=Jt.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var Jt=["component","name","description"];function Gr(e,t){return[...t].sort((n,o)=>{let i=D(e,n)||"zz",a=D(e,o)||"zz",s=Wt.indexOf(i),l=Wt.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)})}var Wt=["name","type"];function Ht(e,t){let r=`Builder.registerComponent(
11
+ `}return""}function A(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 De(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return Kt(o==="index"?e.basename(e.dirname(t)):o)}function Kt(e){return j(e).replace(/ /g,"")}function G(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 B(e,t){let r=z(e.relative(e.getRootDir(),t));return 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)),e.getFrameworks().some(o=>o.name.includes("next"))?"@/"+r:"~/"+r}function N(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 X(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 ve(e){return typeof e=="number"}function xe(e){return typeof e=="boolean"}function L(e){return typeof e=="string"}function $e(e){return typeof e=="string"?/^[A-Z][A-Za-z0-9]*$/.test(e):!1}function V(e){return JSON.parse(JSON.stringify(e))}function be(e,t,r,n,o=!0){let i=t.properties.filter(s=>e.ts.isPropertyAssignment(s)),a=br(e,t,r);return a>-1?n==null&&o?e.ts.factory.updateObjectLiteralExpression(t,i.filter((s,l)=>l!==a)):(i[a]=e.ts.factory.updatePropertyAssignment(i[a],i[a].name,Pe(e,n)),e.ts.factory.updateObjectLiteralExpression(t,i)):(n!=null&&i.push(e.ts.factory.createPropertyAssignment(r,Pe(e,n))),e.ts.factory.updateObjectLiteralExpression(t,i))}function br(e,t,r){return t.properties.findIndex(n=>D(e,n)===r)}function Ie(e,t){switch(t.kind){case e.ts.SyntaxKind.ArrayLiteralExpression:return Nr(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return Ir(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 Ir(e,t){let r={};if(t&&e.ts.isObjectLiteralExpression(t)){for(let n of t.properties)if(e.ts.isPropertyAssignment(n)){let o=D(e,n);o&&(r[o]=Ie(e,n.initializer))}}return r}function Nr(e,t){return t&&e.ts.isArrayLiteralExpression(t)?t.elements.map(r=>Ie(e,r)):[]}function D(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 Pe(e,t){return ct(e,t,new WeakSet)}function ct(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)?Rr(e,t,r):typeof t=="object"?Fr(e,t,r):e.ts.factory.createIdentifier(t)}function Rr(e,t,r){let n=t.map(o=>ct(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Fr(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,ct(e,t[o],r)));return e.ts.factory.createObjectLiteralExpression(n,!0)}function Ne(e,t,r){let n=[];if(!r)return n;let o=[];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 a=t.getTypeAtLocation(r).getCallSignatures();if(a.length>0){let s=a[0].getParameters();s.length>0&&(o=t.getTypeOfSymbolAtLocation(s[0],r).getProperties())}}for(let i of o){let a=Ar(e,t,i);a&&n.push(a)}return n=n.filter(qt),n.length>0?n:Lr(e,r)}function Ar(e,t,r){let n=r.valueDeclaration,o=r.getName();if(n||(n=r.getDeclarations()?.[0]),n&&e.ts.isPropertySignature(n)){if(o!=="children"&&n.getSourceFile().fileName.includes("node_modules/@types/"))return null;let i="string",a;if(n?.type){let l=t.getTypeFromTypeNode(n.type),m=t.typeToString(l),d=pt(m);d.knownType?i=d.builderType:kr(m)||l.flags&e.ts.TypeFlags.StringLike?i="string":l.flags&e.ts.TypeFlags.NumberLike?i="number":l.flags&e.ts.TypeFlags.IndexedAccess?i="list":l.flags&e.ts.TypeFlags.Object||l.isUnion()&&l.types.every(p=>p.flags&e.ts.TypeFlags.Object)||l.isIntersection()&&l.types.some(p=>p.flags&e.ts.TypeFlags.Object)?i="object":i="string",m!==i&&(a=m)}let s={name:o,type:i,isRegistered:!1};if(a&&n.type){let l=Vr(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},l&&l.length>0&&s.type==="string"&&l.every(_r)?s.enum=l.map(Br):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}function Lr(e,t){let r=[],n=e.ts.getJSDocCommentsAndTags(t);for(let o of n)if(!(!e.ts.isJSDoc(o)||!o.tags))for(let i of o.tags){if(!e.ts.isJSDocParameterTag(i)||i.tagName.text!=="param")continue;let s=i.typeExpression?.type;if(!s||!e.ts.isJSDocTypeLiteral(s))continue;let l=s.jsDocPropertyTags;if(l)for(let m of l){if(!e.ts.isJSDocPropertyLikeTag(m))continue;let d=m.name;if(!e.ts.isQualifiedName(d))continue;let p=m.typeExpression;if(!p)continue;let c="";switch(p.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(qt)}var Or=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function kr(e){return typeof e!="string"?!1:!!Or.some(t=>e.includes(t))}function pt(e){return typeof e=="string"&&(e=e.trim(),jr.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var jr=[{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 _r(e){return/^['"].*['"]$/.test(e)}function Br(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Vr=(e,t,r)=>{let n=new Set;Qt(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},$r=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Qt=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Qt(e,t,o,n)});else if(r.isLiteral()){let o=$r(e,t,r);n.add(o)}};function qt(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!zr.has(t.toLowerCase())}var zr=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 oe(e,t,r){for(let n of r.properties){if(!e.ts.isPropertyAssignment(n))continue;let o=D(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=Ur(e,n.initializer);ie(t,i);continue}if(o==="meta"&&e.ts.isObjectLiteralExpression(n.initializer)){let i=Ie(e,n.initializer);i&&typeof i=="object"&&(t.meta=i);continue}}return t}function Ur(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Mr(e,n));return r}function Mr(e,t){let r=Ie(e,t),n=Yr(r);return n.isRegistered=!0,n}function Z(e,t,r){let n=Qr(r);return t=be(e,t,"name",n.name,!1),t=be(e,t,"description",n.description),t=be(e,t,"image",n.image),t=Kr(e,t,n),Gr(e,t)}function Kr(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 be(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=Jr(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 Qr(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(qr)}}function qr(e){let t={name:e.name,type:e.type};return(L(e.defaultValue)||ve(e.defaultValue)||xe(e.defaultValue))&&(t.defaultValue=e.defaultValue),L(e.friendlyName)&&(t.friendlyName=e.friendlyName),L(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 Jr(e,t,r){let n=t.elements.filter(o=>{if(!e.ts.isObjectLiteralExpression(o))return!1;let i=o.properties.find(s=>D(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=Wr(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(c=>D(e,c)==="name"),s=i.properties.find(c=>D(e,c)==="name"),l=a?.initializer,m=s?.initializer,d=l&&e.ts.isStringLiteral(l)?l.text:"zz",p=m&&e.ts.isStringLiteral(m)?m.text:"zz";return d.toLowerCase().localeCompare(p.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function Wr(e,t,r){let n=t.findIndex(o=>o.properties.some(i=>{let a=D(e,i);return e.ts.isPropertyAssignment(i)&&a==="name"&&e.ts.isStringLiteral(i.initializer)&&i.initializer.text===r.name}));if(n>-1)t[n]=Jt(e,t[n],r);else{let o=Jt(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Jt(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=Hr(e,n,r,i);return n=Xr(e,n.filter(i=>{let a=D(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function Hr(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,Pe(e,r[n])):t.push(e.ts.factory.createPropertyAssignment(n,Pe(e,r[n]))),t}function ie(e,t){for(let o of t){let i=e.inputs.findIndex(a=>a.name===o.name);i>-1?(o.isRegistered||!e.inputs[i].isRegistered)&&(e.inputs[i]=o):e.inputs.push(o)}let r=e.inputs.some(o=>o.name==="children"),n=e.inputs.some(o=>o.meta?.ts==="ReactNode");r||n?e.acceptsChildren=!0:e.acceptsChildren||(e.acceptsChildren=!1)}function Yr(e){let t=pt(e.type),r={name:e.name.trim(),type:t.builderType};return L(e.friendlyName)&&e.friendlyName.trim()!==e.name.trim()&&(r.friendlyName=e.friendlyName),(L(e.defaultValue)||ve(e.defaultValue)||xe(e.defaultValue))&&(r.defaultValue=e.defaultValue),L(e.helperText)&&(r.helperText=e.helperText),xe(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),ut(r)}function ut(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 Gr(e,t){let r=[...t.properties].sort((n,o)=>{let i=D(e,n)||"zz",a=D(e,o)||"zz";if(i==="inputs")return 1;let s=Wt.indexOf(i),l=Wt.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)});return e.ts.factory.updateObjectLiteralExpression(t,r)}var Wt=["component","name","description"];function Xr(e,t){return[...t].sort((n,o)=>{let i=D(e,n)||"zz",a=D(e,o)||"zz",s=Ht.indexOf(i),l=Ht.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)})}var Ht=["name","type"];function Yt(e,t){let r=`Builder.registerComponent(
12
12
  `;if(e.appDir)t.acceptsChildren?r+=` withChildren(${t.importName}),
13
13
  `:r+=` ${t.importName},
14
14
  `;else{let o=A(e,e.registryPath,t.filePath);t.exportName==="default"?t.acceptsChildren?r+=` withChildren(dynamic(() => import(${JSON.stringify(o)}))),
@@ -18,8 +18,8 @@ ${r}=${n}
18
18
  `}r+=` {
19
19
  name: "${t.name}",
20
20
  }
21
- `,r+=");";let n=Ut(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;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]=X(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function $(e,t){if(!Array.isArray(t)||t.length===0)throw new Error(`createTsProgram() Invalid filePaths: ${t}`);let r=await Vt(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=Ne.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}Ne.set(a,s)}return s.exists}return o.has(a)||o.set(a,e.existsSync(a)),o.get(a)},getCanonicalFileName:a=>e.normalize(a),getCurrentDirectory:()=>e.cwd(),getDefaultLibFileName:()=>e.join(n,"lib.d.ts"),getDefaultLibLocation:()=>n,getNewLine:()=>`
22
- `,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let l=Ne.get(a);if(l)return E(e,l.content)}let s=e.readFileSync(a);if(s==null){let l=e.basename(a),m=e.extname(l).toLowerCase();if(a.startsWith(n)&&m===".ts"&&(s=Gt.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new ze(l)}return a.includes("node_modules")&&(s?Ne.set(a,{exists:!0,content:s}):Ne.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 Xr(e,i,t)}catch(a){if(a instanceof ze){await Zr(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Xr(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=Yt.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let l=e.readFileSync(s);return typeof l=="string"?l:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(l,m)=>e.readdirSync(l),fileExists:l=>e.existsSync(l),readFile:l=>e.readFileSync(l)||void 0},e.dirname(o),void 0,o).options,Yt.set(o,i))}i&&(n.options=B(i))}return n.options.moduleResolution=e.ts.ModuleResolutionKind.Node16,n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function Ue(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 ze=class{constructor(t){this.libName=t}};async function Zr(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;$e.has(t)||$e.set(t,fetch(r).then(n=>n.text()).then(n=>{Gt.set(t,n)})),await $e.get(t),$e.delete(t)}var Gt=new Map,$e=new Map,Ne=new Map,Yt=new Map;function v(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=eo(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=to(e,t,r.defaultImport,r.importPath,n)),t}function eo(e,t,r,n,o,i){return i==="cjs"?Zt(e,t,null,r,n):Xt(e,t,null,r,n,o)}function to(e,t,r,n,o){return o==="cjs"?Zt(e,t,r,null,n):Xt(e,t,r,null,n,!1)}function Xt(e,t,r,n,o,i){let a=[...t.statements],s=0,l=!1,m=!1;for(let p=0;p<a.length;p++){let h=a[p];if(!e.ts.isImportDeclaration(h)||(s=p,!h.moduleSpecifier||!e.ts.isStringLiteral(h.moduleSpecifier))||h.moduleSpecifier.text!==o||!!h.importClause?.isTypeOnly!==i)continue;let u=[],g=h.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&u.push(...g.elements),typeof n=="string"){if(u.some(S=>S.name.text===n))return t;u.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),u.sort((S,C)=>S.name.text.localeCompare(C.name.text)),l=!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),m=!0}if(l||m)return a[p]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,x,e.ts.factory.createNamedImports(u)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let 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 Zt(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let l=i[s];if(e.ts.isVariableStatement(l))for(let m=0;m<l.declarationList.declarations.length;m++){let d=[...l.declarationList.declarations],f=d[m],c=f.initializer;if(!c||!e.ts.isCallExpression(c))continue;let p=c.expression;if(!e.ts.isIdentifier(p)||p.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[m]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createIdentifier(r),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(f.name)&&typeof n=="string"){let u=[...f.name.elements];return u.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(u.push(e.ts.factory.createBindingElement(void 0,void 0,n)),u.sort((x,S)=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)||!e.ts.isBindingElement(S)||!e.ts.isIdentifier(S.name)?0:x.name.text.localeCompare(S.name.text)),d[m]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createObjectBindingPattern(u),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function V(e,t,r="esm"){return r==="cjs"?ro(e,t):no(e,t)}function no(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(e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function ro(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s});else e.ts.isFunctionDeclaration(s)&&s.name&&s.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s})}else r.push({isDefaultExport:!0,statement:n,node:i});continue}}return r}function oo(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 Me(e,t,r,n){let o=oo(e,r,n);if(o){let i=await dt(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:N(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function mt(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 Z(e,t,r){let n=mt(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 Ke(e,t){if(t){if(io(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Ke(e,n)&&(r=!0)}),r)return!0}return!1}function io(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 dt(e,t){let r=e.extname(t).toLowerCase();if(r===""||!ft.includes(r)){for(let n of ft){let o=t+n;if(await e.exists(o))return o}for(let n of ft){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var ft=[".tsx",".jsx",".ts",".js"];function Qe(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=ao(e,i);return a?[{name:a}]:void 0}function ao(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 xe(e){let t=[];for(let r of e)if(r.dependencies)for(let n of r.dependencies)t.some(o=>o.name===n.name)||t.push({...n});return t.sort((r,n)=>r.name.localeCompare(n.name))}async function Je(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await $(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 m=(await ie(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);m&&(a.inputs=Ie(e,o,m.node.fnNode))}}return a}))}async function We(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Ue(e,t.cmpInfo.filePath,r),a=(await ie(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 Ie(e,o,a.node.fnNode)}return[]}async function en(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 so(e,t,n)}return null}function so(e,t,r){let n=E(e,r);return ie(e,null,t,n)}async function ie(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=V(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await lo(e,t,r,a);o.push(...s)})),o}async function lo(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r);if(e.ts.isVariableStatement(n.node)){for(let a of n.node.declarationList.declarations){if(!e.ts.isIdentifier(a.name)||!Ve(a.name.text))continue;let s=qe(e,t,a.initializer);if(s){let l=s.name||a.name.text,m=n.isDefaultExport?"default":l,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:j(l),inputs:[],exportName:m,exportType:d,importName:l,filePath:r,relFilePath:i,dependencies:s.deps},node:s})}}return o}if(e.ts.isArrowFunction(n.node)){let a=qe(e,t,n.node);if(a){let s=Y(e,r),l=n.isDefaultExport?"default":s,m=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,l),displayFilePath:N(e,r),name:s,inputs:[],exportName:l,exportType:m,importName:Ee(e,r),filePath:r,relFilePath:i,dependencies:a.deps},node:a})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let a=n.node.name?.text;if(a&&!Ve(a))return o;let s=qe(e,t,n.node);if(s){let l=s.name||Y(e,r),m=n.isDefaultExport||!s.name?"default":s.name,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:l,inputs:[],exportName:m,exportType:d,importName:s.name||Ee(e,r),filePath:r,relFilePath:i,dependencies:s.deps},node:s})}return o}return o}function qe(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Ke(e,r.body)?{name:"",fnNode:r,deps:Qe(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Ke(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Qe(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:qe(e,t,o[0])}if(!t)return null;if(e.ts.isPropertyAccessExpression(r)){let n=r.expression,o=r.name;if(!e.ts.isIdentifier(n)||!e.ts.isIdentifier(o)||!Ve(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:Qe(e,t,o)}}return null}async function tn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(e.appDir&&co.has(a))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let l=await ie(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var co=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 he(e,t){let r=[],n=[],o=[],i=[];for(let a of t.statements){if(e.ts.isImportDeclaration(a)){if(e.ts.isStringLiteral(a.moduleSpecifier)){let l=a.moduleSpecifier.text;if(!l.startsWith(".")&&!l.startsWith("/")){r.push(a);continue}}let s=a.importClause;if(s){if(s.namedBindings){n.push(a);continue}if(s.name){n.push(a);continue}}o.push(a);continue}i.push(a)}return e.ts.factory.updateSourceFile(t,[...gt(e,r),...gt(e,n),...gt(e,o),...i])}function ee(e){let t=e.split(`
21
+ `,r+=");";let n=Mt(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]=Z(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function U(e,t){if(!Array.isArray(t)||t.length===0)throw new Error(`createTsProgram() Invalid filePaths: ${t}`);let r=await $t(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=Re.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}Re.set(a,s)}return s.exists}return o.has(a)||o.set(a,e.existsSync(a)),o.get(a)},getCanonicalFileName:a=>e.normalize(a),getCurrentDirectory:()=>e.cwd(),getDefaultLibFileName:()=>e.join(n,"lib.d.ts"),getDefaultLibLocation:()=>n,getNewLine:()=>`
22
+ `,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let l=Re.get(a);if(l)return E(e,l.content)}let s=e.readFileSync(a);if(s==null){let l=e.basename(a),m=e.extname(l).toLowerCase();if(a.startsWith(n)&&m===".ts"&&(s=Xt.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new Ue(l)}return a.includes("node_modules")&&(s?Re.set(a,{exists:!0,content:s}):Re.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 Zr(e,i,t)}catch(a){if(a instanceof Ue){await eo(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Zr(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=Gt.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let l=e.readFileSync(s);return typeof l=="string"?l:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(l,m)=>e.readdirSync(l),fileExists:l=>e.existsSync(l),readFile:l=>e.readFileSync(l)||void 0},e.dirname(o),void 0,o).options,Gt.set(o,i))}i&&(n.options=V(i))}return n.options.moduleResolution=e.ts.ModuleResolutionKind.Node16,n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function Me(e,t,r){r||(r=await U(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 Ue=class{constructor(t){this.libName=t}};async function eo(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;ze.has(t)||ze.set(t,fetch(r).then(n=>n.text()).then(n=>{Xt.set(t,n)})),await ze.get(t),ze.delete(t)}var Xt=new Map,ze=new Map,Re=new Map,Gt=new Map;function v(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=to(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=no(e,t,r.defaultImport,r.importPath,n)),t}function to(e,t,r,n,o,i){return i==="cjs"?en(e,t,null,r,n):Zt(e,t,null,r,n,o)}function no(e,t,r,n,o){return o==="cjs"?en(e,t,r,null,n):Zt(e,t,r,null,n,!1)}function Zt(e,t,r,n,o,i){let a=[...t.statements],s=0,l=!1,m=!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 f=[],g=h.importClause?.namedBindings;if(g&&e.ts.isNamedImports(g)&&g.elements&&f.push(...g.elements),typeof n=="string"){if(f.some(S=>S.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((S,C)=>S.name.text.localeCompare(C.name.text)),l=!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),m=!0}if(l||m)return a[u]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,x,e.ts.factory.createNamedImports(f)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,p;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(p=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,p),e.ts.factory.createStringLiteral(o));return a.splice(s,0,c),e.ts.factory.updateSourceFile(t,a)}function en(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let l=i[s];if(e.ts.isVariableStatement(l))for(let m=0;m<l.declarationList.declarations.length;m++){let d=[...l.declarationList.declarations],p=d[m],c=p.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(p.name)&&typeof r=="string")return p.name.text===r?t:(d[m]=e.ts.factory.updateVariableDeclaration(p,e.ts.factory.createIdentifier(r),p.exclamationToken,p.type,p.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(p.name)&&typeof n=="string"){let f=[...p.name.elements];return f.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((x,S)=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)||!e.ts.isBindingElement(S)||!e.ts.isIdentifier(S.name)?0:x.name.text.localeCompare(S.name.text)),d[m]=e.ts.factory.updateVariableDeclaration(p,e.ts.factory.createObjectBindingPattern(f),p.exclamationToken,p.type,p.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function $(e,t,r="esm"){return r==="cjs"?oo(e,t):ro(e,t)}function ro(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(e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function oo(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s});else e.ts.isFunctionDeclaration(s)&&s.name&&s.name.text===a&&r.push({isDefaultExport:!0,statement:s,node:s})}else r.push({isDefaultExport:!0,statement:n,node:i});continue}}return r}function io(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 Ke(e,t,r,n){let o=io(e,r,n);if(o){let i=await gt(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:N(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function dt(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 ee(e,t,r){let n=dt(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 Qe(e,t){if(t){if(ao(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Qe(e,n)&&(r=!0)}),r)return!0}return!1}function ao(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 gt(e,t){let r=e.extname(t).toLowerCase();if(r===""||!mt.includes(r)){for(let n of mt){let o=t+n;if(await e.exists(o))return o}for(let n of mt){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var mt=[".tsx",".jsx",".ts",".js"];function qe(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=so(e,i);return a?[{name:a}]:void 0}function so(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 he(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 We(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await U(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 m=(await ae(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);m&&(a.inputs=Ne(e,o,m.node.fnNode))}}return a}))}async function He(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await Me(e,t.cmpInfo.filePath,r),a=(await ae(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 tn(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 lo(e,t,n)}return null}function lo(e,t,r){let n=E(e,r);return ae(e,null,t,n)}async function ae(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=$(e,n);return r=e.normalize(r),await Promise.all(i.map(async a=>{let s=await co(e,t,r,a);o.push(...s)})),o}async function co(e,t,r,n){let o=[],i=e.relative(e.getRootDir(),r),a=B(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!$e(s.name.text))continue;let l=Je(e,t,s.initializer);if(l){let m=l.name||s.name.text,d=n.isDefaultExport?"default":m,p=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:N(e,r),name:j(m),inputs:[],exportName:d,exportType:p,importName:m,filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}}return o}if(e.ts.isArrowFunction(n.node)){let s=Je(e,t,n.node);if(s){let l=G(e,r),m=n.isDefaultExport?"default":l,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:l,inputs:[],exportName:m,exportType:d,importName:De(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let s=n.node.name?.text;if(s&&!$e(s))return o;let l=Je(e,t,n.node);if(l){let m=l.name||G(e,r),d=n.isDefaultExport||!l.name?"default":l.name,p=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,d),displayFilePath:N(e,r),name:m,inputs:[],exportName:d,exportType:p,importName:l.name||De(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}return o}return o}function Je(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Qe(e,r.body)?{name:"",fnNode:r,deps:qe(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Qe(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:qe(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:Je(e,t,o[0])}if(!t)return null;if(e.ts.isPropertyAccessExpression(r)){let n=r.expression,o=r.name;if(!e.ts.isIdentifier(n)||!e.ts.isIdentifier(o)||!$e(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:qe(e,t,o)}}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.basename(i.fileName);if(e.appDir&&po.has(a))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let l=await ae(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var po=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 Se(e,t){let r=[],n=[],o=[],i=[];for(let a of t.statements){if(e.ts.isImportDeclaration(a)){if(e.ts.isStringLiteral(a.moduleSpecifier)){let l=a.moduleSpecifier.text;if(!l.startsWith(".")&&!l.startsWith("/")){r.push(a);continue}}let s=a.importClause;if(s){if(s.namedBindings){n.push(a);continue}if(s.name){n.push(a);continue}}o.push(a);continue}i.push(a)}return e.ts.factory.updateSourceFile(t,[...xt(e,r),...xt(e,n),...xt(e,o),...i])}function te(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,8 +28,8 @@ ${r}=${n}
28
28
  `+o),o.trim().startsWith("export ")&&(o=`
29
29
  `+o)),e=o+`
30
30
  `+e}return e.trim()+`
31
- `}function gt(e,t){return t.sort((r,n)=>{let o=nn(e,r),i=nn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function nn(e,t){let r=t.importClause;if(r){let n=r.namedBindings;if(n&&e.ts.isNamedImports(n)&&n.elements.length>0)return n.elements[0].name.text;if(r.name)return r.name.text}return t.moduleSpecifier&&e.ts.isStringLiteral(t.moduleSpecifier)?t.moduleSpecifier.text:""}function on(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
32
- ${e}`),e}function an(e,t){let r=t.statements.filter(n=>!(e.ts.isExpressionStatement(n)&&e.ts.isStringLiteral(n.expression)&&e.ts.isStringLiteral(n.expression)&&n.expression.text==="use client"));return e.ts.factory.updateSourceFile(t,r)}function He(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=rn(e,r),i=rn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function rn(e,t){let r=t.properties.find(n=>D(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function cn(e){let t=await e.readFile(e.registryPath);return t?po(e,t):{components:[],sourceFile:E(e,"")}}async function po(e,t){let r=E(e,t);return uo(e,r)}async function uo(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 m=i.arguments;if(m.length<2)continue;let d=m[1];if(!e.ts.isObjectLiteralExpression(d))continue;let f=m[0];if(e.ts.isCallExpression(f)){if((e.ts.isIdentifier(f.expression)&&f.expression.text)==="withChildren"){let h=f.arguments[0];if(e.ts.isCallExpression(h)){let u=await sn(e,n,h,d,!0);u&&r.push(u)}else{let u=f.arguments[0];if(e.ts.isIdentifier(u)){let g=await ln(e,t,n,u,d,!0);g&&r.push(g)}}continue}let p=await sn(e,n,f,d,!1);p&&r.push(p);continue}if(e.ts.isIdentifier(f)){let c=await ln(e,t,n,f,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:G(r)}}async function sn(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let l=s.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let d=l.arguments[0];if(!e.ts.isStringLiteral(d))return null;let f=d.text;i.filePath=await Ye(e,f),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.name=Y(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let m=l.expression;if(!e.ts.isParenthesizedExpression(m))return null;let d=m.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 p=f.arguments[0];if(!e.ts.isStringLiteral(p)||!e.ts.isIdentifier(l.name))return null;let h=p.text;i.filePath=await Ye(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.name=j(l.name.text),i.importName=l.name.text,i.exportName=l.name.text,i.exportType="named"}else return null;return i=re(e,i,n),i.displayFilePath=N(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName)),i}async function ln(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(m=>e.ts.isImportDeclaration(m)),l=s.find(m=>m.importClause&&m.importClause.name?.text===n.text);if(l){let m=l.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;a.filePath=await Ye(e,m.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.name=Y(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let m=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(!m)return null;let d=m.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await Ye(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=re(e,a,o),a.displayFilePath=N(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName)),a}function Ye(e,t){return dt(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function pn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let m=0;m<i.length;m++){let d=i[m];if(e.ts.isImportDeclaration(d)){o=m;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 p=c.expression;if(!e.ts.isIdentifier(p)||p.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(ne)),s=r?e.ts.factory.createNonNullExpression(a):a,l=e.ts.factory.createExpressionStatement(e.ts.factory.createCallExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("builder"),e.ts.factory.createIdentifier("init")),void 0,[s]));return i.splice(o+1,0,l),e.ts.factory.updateSourceFile(t,i)}function 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 l=[...s.elements];for(let m=l.length-1;m>=0;m--){let d=l[m];if(e.ts.isImportSpecifier(d)){let f=d.name;if(f&&e.ts.isIdentifier(f)){let c=f.text;un(e,t,c)||l.splice(m,1)}}}if(l.length===0)a=!0;else if(s.elements.length!==l.length){let m=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(l)),d=e.ts.factory.updateImportDeclaration(i,void 0,m,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;un(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function un(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 Ce(e,t,r,n,o,i,a){let s=null,l=null,m=null,d=-1;t=B(t),r=B(r);let f=t.find(p=>p.id===e),c=r.find(p=>p.id===e);if(n)c||(s={...B(f),inputs:B(f.inputs).map(p=>(p.isRegistered=!0,p))},d=r.length,r.push(s));else if(typeof c?.nodeIndex=="number"&&c.nodeIndex>-1){if(o)d=c.nodeIndex,l=B(c),r=r.filter(p=>p.id!==e);else if(i!=null)fo(c,i),d=c.nodeIndex,m=c;else if(a!=null){let p=c.inputs.find(h=>h.name===a.name);p&&(a.registerInput===!1?p.isRegistered=!1:(mo(p,a),p.isRegistered=!0),m=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:m,nodeIndex:d,components:ae(t,r)}}function ae(e,t){let r=G([...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(pt),n.inputs.sort((o,i)=>o.name.toLowerCase().localeCompare(i.name.toLowerCase()))}),r}function fo(e,t){L(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),L(t.description)?e.description=t.description:t.description===null&&delete e.description,L(t.image)?e.image=t.image:t.image===null&&delete e.image}function mo(e,t){L(t.type)&&(e.type=t.type),L(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,L(t.defaultValue)||De(t.defaultValue)||ge(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,L(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 Ge(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".jsx"||l===".ts"||l===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}async function U(e,t,r,n,o,i,a,s){let l=await Ge(e),[m,d,f,c]=await Promise.all([tn(e,l),cn(e),xt(e),Te(e)]),p=m.map(C=>C.cmpInfo),h=d.components,u={components:ae(p,h),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(p),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return u.components=await Je(e,u.components),u;let g=!1,x=d.sourceFile,S=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(S.length>0){let C=S.map(w=>{let P=m.find(O=>O.cmpInfo.id===w);if(!P)throw new Error(`Component ${w} not found`);return P}),b=Array.from(new Set(C.map(w=>w.cmpInfo.filePath))),y=await $(e,b);for(let w of C){let P=u.components.find(k=>k.id===w.cmpInfo.id),O=await We(e,w,y);oe(P,O);let R=p.findIndex(k=>k.id===w.cmpInfo.id);p[R].inputs=O;let T=Ce(w.cmpInfo.id,p,h,r,n,o,i),F=[...x.statements];if(T.addCmpToRegistry?(F.push(Ht(e,T.addCmpToRegistry)),g=!0):T.removeCmpFromRegistry?(F.splice(T.nodeIndex,1),g=!0):T.updateRegisteredCmp&&(F[T.nodeIndex]=ut(e,F[T.nodeIndex],T.updateRegisteredCmp),g=!0),g&&a){if(x=e.ts.factory.updateSourceFile(x,F),x=v(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=pn(e,x,f),e.appDir){let k=T.addCmpToRegistry||T.updateRegisteredCmp;if(k){let pe=A(e,e.registryPath,k.filePath);k.exportType==="default"?x=v(e,x,{defaultImport:k.importName,importPath:pe}):k.exportType==="named"&&(x=v(e,x,{namedImports:[k.importName],importPath:pe}))}}else x=v(e,x,{defaultImport:"dynamic",importPath:"next/dynamic"});P?.acceptsChildren&&(x=v(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),u.components=T.components,h=T.components.filter(k=>k.isRegistered)}}}if(g&&a){x=Se(e,x),x=he(e,x),e.appDir&&(x=an(e,x));let C=I(e,x);C=ee(C),e.appDir&&(C=on(C)),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return u}async function fn(e){let t=[],r=await wo(e,t);return await To(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await xo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await So(e,e.pagesDir,t)),t}async function mn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await go(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await Co(e,e.pagesDir,t)),t}async function go(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,dn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function xo(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,dn({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,ho(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function ho(e){let t=e.typescriptEnabled;return`
31
+ `}function xt(e,t){return t.sort((r,n)=>{let o=rn(e,r),i=rn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function rn(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 an(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
32
+ ${e}`),e}function sn(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 Ye(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=on(e,r),i=on(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function on(e,t){let r=t.properties.find(n=>D(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function pn(e){let t=await e.readFile(e.registryPath);return t?uo(e,t):{components:[],sourceFile:E(e,"")}}async function uo(e,t){let r=E(e,t);return fo(e,r)}async function fo(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 m=i.arguments;if(m.length<2)continue;let d=m[1];if(!e.ts.isObjectLiteralExpression(d))continue;let p=m[0];if(e.ts.isCallExpression(p)){if((e.ts.isIdentifier(p.expression)&&p.expression.text)==="withChildren"){let h=p.arguments[0];if(e.ts.isCallExpression(h)){let f=await ln(e,n,h,d,!0);f&&r.push(f)}else{let f=p.arguments[0];if(e.ts.isIdentifier(f)){let g=await cn(e,t,n,f,d,!0);g&&r.push(g)}}continue}let u=await ln(e,n,p,d,!1);u&&r.push(u);continue}if(e.ts.isIdentifier(p)){let c=await cn(e,t,n,p,d,!1);c&&r.push(c);continue}}return{sourceFile:t,components:X(r)}}async function ln(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let l=s.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let d=l.arguments[0];if(!e.ts.isStringLiteral(d))return null;let p=d.text;i.filePath=await Ge(e,p),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=B(e,i.filePath),i.name=G(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let m=l.expression;if(!e.ts.isParenthesizedExpression(m))return null;let d=m.expression;if(!e.ts.isAwaitExpression(d))return null;let p=d.expression;if(!e.ts.isCallExpression(p)||p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let u=p.arguments[0];if(!e.ts.isStringLiteral(u)||!e.ts.isIdentifier(l.name))return null;let h=u.text;i.filePath=await Ge(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=B(e,i.filePath),i.name=j(l.name.text),i.importName=l.name.text,i.exportName=l.name.text,i.exportType="named"}else return null;return i=oe(e,i,n),i.displayFilePath=N(e,i.filePath),i.filePath&&i.exportName&&(i.id=await _(e,i.filePath,i.exportName)),i}async function cn(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(m=>e.ts.isImportDeclaration(m)),l=s.find(m=>m.importClause&&m.importClause.name?.text===n.text);if(l){let m=l.moduleSpecifier;if(!e.ts.isStringLiteral(m))return null;a.filePath=await Ge(e,m.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=B(e,a.filePath),a.name=G(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let m=s.find(p=>!p.importClause||!p.importClause.namedBindings||!e.ts.isNamedImports(p.importClause.namedBindings)?!1:p.importClause.namedBindings.elements.some(c=>c.name.text===n.text));if(!m)return null;let d=m.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await Ge(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=B(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=oe(e,a,o),a.displayFilePath=N(e,a.filePath),a.filePath&&a.exportName&&(a.id=await _(e,a.filePath,a.exportName)),a}function Ge(e,t){return gt(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function un(e,t,r){let n=!1,o=0,i=[...t.statements];for(let m=0;m<i.length;m++){let d=i[m];if(e.ts.isImportDeclaration(d)){o=m;continue}if(!e.ts.isExpressionStatement(d))continue;let p=d.expression;if(!e.ts.isCallExpression(p))continue;let c=p.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(re)),s=r?e.ts.factory.createNonNullExpression(a):a,l=e.ts.factory.createExpressionStatement(e.ts.factory.createCallExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("builder"),e.ts.factory.createIdentifier("init")),void 0,[s]));return i.splice(o+1,0,l),e.ts.factory.updateSourceFile(t,i)}function 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 l=[...s.elements];for(let m=l.length-1;m>=0;m--){let d=l[m];if(e.ts.isImportSpecifier(d)){let p=d.name;if(p&&e.ts.isIdentifier(p)){let c=p.text;fn(e,t,c)||l.splice(m,1)}}}if(l.length===0)a=!0;else if(s.elements.length!==l.length){let m=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(l)),d=e.ts.factory.updateImportDeclaration(i,void 0,m,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;fn(e,t,l)||(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 we(e,t,r,n,o,i,a){let s=null,l=null,m=null,d=-1;t=V(t),r=V(r);let p=t.find(u=>u.id===e),c=r.find(u=>u.id===e);if(n)c||(s={...V(p),inputs:V(p.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,l=V(c),r=r.filter(u=>u.id!==e);else if(i!=null)mo(c,i),d=c.nodeIndex,m=c;else if(a!=null){let u=c.inputs.find(h=>h.name===a.name);u&&(a.registerInput===!1?u.isRegistered=!1:(go(u,a),u.isRegistered=!0),m=c,d=c.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:m,nodeIndex:d,components:se(t,r)}}function se(e,t){let r=X([...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(ut),n.inputs.sort((o,i)=>o.name.toLowerCase().localeCompare(i.name.toLowerCase()))}),r}function mo(e,t){L(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),L(t.description)?e.description=t.description:t.description===null&&delete e.description,L(t.image)?e.image=t.image:t.image===null&&delete e.image}function go(e,t){L(t.type)&&(e.type=t.type),L(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,L(t.defaultValue)||ve(t.defaultValue)||xe(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,L(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 Xe(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".jsx"||l===".ts"||l===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await U(e,[...t])}async function M(e,t,r,n,o,i,a,s){let l=await Xe(e),[m,d,p,c]=await Promise.all([nn(e,l),pn(e),ht(e),Ee(e)]),u=m.map(C=>C.cmpInfo),h=d.components,f={components:se(u,h),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:he(u),publicApiKey:c.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await We(e,f.components),f;let g=!1,x=d.sourceFile,S=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(S.length>0){let C=S.map(w=>{let b=m.find(O=>O.cmpInfo.id===w);if(!b)throw new Error(`Component ${w} not found`);return b}),P=Array.from(new Set(C.map(w=>w.cmpInfo.filePath))),T=await U(e,P);for(let w of C){let b=f.components.find(k=>k.id===w.cmpInfo.id),O=await He(e,w,T);ie(b,O);let R=u.findIndex(k=>k.id===w.cmpInfo.id);u[R].inputs=O;let y=we(w.cmpInfo.id,u,h,r,n,o,i),F=[...x.statements];if(y.addCmpToRegistry?(F.push(Yt(e,y.addCmpToRegistry)),g=!0):y.removeCmpFromRegistry?(F.splice(y.nodeIndex,1),g=!0):y.updateRegisteredCmp&&(F[y.nodeIndex]=ft(e,F[y.nodeIndex],y.updateRegisteredCmp),g=!0),g&&a){if(x=e.ts.factory.updateSourceFile(x,F),x=v(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=un(e,x,p),e.appDir){let k=y.addCmpToRegistry||y.updateRegisteredCmp;if(k){let ue=A(e,e.registryPath,k.filePath);k.exportType==="default"?x=v(e,x,{defaultImport:k.importName,importPath:ue}):k.exportType==="named"&&(x=v(e,x,{namedImports:[k.importName],importPath:ue}))}}else x=v(e,x,{defaultImport:"dynamic",importPath:"next/dynamic"});b?.acceptsChildren&&(x=v(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=y.components,h=y.components.filter(k=>k.isRegistered)}}}if(g&&a){x=Ce(e,x),x=Se(e,x),e.appDir&&(x=sn(e,x));let C=I(e,x);C=te(C),e.appDir&&(C=an(C)),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return f}async function mn(e){let t=[],r=await To(e,t);return await Eo(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await ho(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await Co(e,e.pagesDir,t)),t}async function dn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await xo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await wo(e,e.pagesDir,t)),t}async function xo(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,gn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function ho(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,gn({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,So(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function So(e){let t=e.typescriptEnabled;return`
33
33
  "use client";
34
34
  ${t?'import { ComponentProps } from "react";':""}
35
35
  import { BuilderComponent, useIsPreviewing } from "@builder.io/react";
@@ -40,7 +40,7 @@ ${t?`
40
40
  type BuilderPageProps = ComponentProps<typeof BuilderComponent>;`:""}
41
41
 
42
42
  // Builder Public API Key set in .env file
43
- builder.init(process.env.${ne}${t?"!":""});
43
+ builder.init(process.env.${re}${t?"!":""});
44
44
 
45
45
  export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":""}) {
46
46
  // Call the useIsPreviewing hook to determine if
@@ -56,12 +56,12 @@ export function RenderBuilderContent({ content, model }${t?": BuilderPageProps":
56
56
  // DefaultErrorPage with a 404.
57
57
  return <DefaultErrorPage statusCode={404} />;
58
58
  }
59
- `.trimStart()}function dn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=A(e,t,e.builderComponentPath);return`
59
+ `.trimStart()}function gn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=A(e,t,e.builderComponentPath);return`
60
60
  import { builder } from "@builder.io/sdk";
61
61
  import { RenderBuilderContent } from ${JSON.stringify(o)};
62
62
 
63
63
  // Builder Public API Key set in .env file
64
- builder.init(process.env.${ne}${n?"!":""});
64
+ builder.init(process.env.${re}${n?"!":""});
65
65
  ${n?`
66
66
  interface PageProps {
67
67
  params: {
@@ -90,7 +90,7 @@ export default async function Page(props${n?": PageProps":""}) {
90
90
  </>
91
91
  );
92
92
  }
93
- `.trimStart()}async function So(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,gn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function Co(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,gn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function gn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return`
93
+ `.trimStart()}async function Co(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,xn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function wo(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,xn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function xn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return`
94
94
  import React from "react";
95
95
  import { useRouter } from "next/router";
96
96
  import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
@@ -100,7 +100,7 @@ import { BuilderContent } from "@builder.io/sdk";`:""}${n?`
100
100
  import { GetStaticProps } from "next";`:""}
101
101
  import ${JSON.stringify(A(e,t,e.registryPath))};
102
102
 
103
- builder.init(process.env.${ne}${n?"!":""});
103
+ builder.init(process.env.${re}${n?"!":""});
104
104
 
105
105
  // Define a function that fetches the Builder
106
106
  // content for a given page
@@ -164,7 +164,7 @@ export default function Page({ page }${n?": { page: BuilderContent | null }":""}
164
164
  </>
165
165
  );
166
166
  }
167
- `.trimStart()}async function wo(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=yo(e);if(!await e.exists(i)){let m=await e.formatCode(i,s);await e.writeFile(i,m),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function yo(e){let t=e.typescriptEnabled,r=`
167
+ `.trimStart()}async function To(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=yo(e);if(!await e.exists(i)){let m=await e.formatCode(i,s);await e.writeFile(i,m),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function yo(e){let t=e.typescriptEnabled,r=`
168
168
  "use client"
169
169
  import React, { useState } from "react";
170
170
  import styles from "./styles.module.css";
@@ -227,13 +227,13 @@ export default Counter;
227
227
  font-size: 42px;
228
228
  text-align: center;
229
229
  }
230
- `.trimStart();return{component:r,styles:n}}async function To(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await U(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await U(e,o.id,!0,!1,null,null,!0,!1)}async function xn(e){let t=await Eo(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>fn(t),ensureFigmaImportPage:()=>mn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>U(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await U(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>U(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>U(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>U(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>U(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Te(t),setPublicApiKey:n=>zt(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ue(t),setCache:n=>fe(t,n)}}async function Eo(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await Do(e),o=await xt(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(await e.exists(r)){a.srcDir=r,a.componentsDir=e.join(r,"components");let s=e.join(r,"app");await e.exists(s)&&(a.appDir=s);let l=e.join(r,"pages");await e.exists(l)&&(a.pagesDir=l),a.registryPath=e.join(r,i)}else a.componentsDir=e.join(t,"components"),a.registryPath=e.join(t,i);if(a.builderComponentPath=e.join(a.componentsDir,`builder.${o?"tsx":"jsx"}`),!a.appDir){let s=e.join(t,"app");await e.exists(s)&&(a.appDir=s)}if(!a.pagesDir){let s=e.join(t,"pages");await e.exists(s)&&(a.pagesDir=s)}if(!a.appDir&&!a.pagesDir)throw new Error(`Could not find Next.js "app" or "pages" directory. Searched in "${t}".`);return a}function xt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Do(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 Re(e){return await me(e,[".env"],Sn)}async function hn(e,t){vo(t);let r=await Re(e),n=await de(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function vo(e){typeof process<"u"&&(process.env[Sn]=e)}var Sn="PUBLIC_BUILDER_API_KEY";function Cn(e,t,r){if(r.length===0)return e;let n=e.split(`
230
+ `.trimStart();return{component:r,styles:n}}async function Eo(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await M(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await M(e,o.id,!0,!1,null,null,!0,!1)}async function hn(e){let t=await Do(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>mn(t),ensureFigmaImportPage:()=>dn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>M(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await M(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>M(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>M(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>M(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>M(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ee(t),setPublicApiKey:n=>Ut(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>me(t,n)}}async function Do(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await vo(e),o=await ht(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,appDir:null,pagesDir:null,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",nextConfigPath:n,typescriptEnabled:o};if(await e.exists(r)){a.srcDir=r,a.componentsDir=e.join(r,"components");let s=e.join(r,"app");await e.exists(s)&&(a.appDir=s);let l=e.join(r,"pages");await e.exists(l)&&(a.pagesDir=l),a.registryPath=e.join(r,i)}else a.componentsDir=e.join(t,"components"),a.registryPath=e.join(t,i);if(a.builderComponentPath=e.join(a.componentsDir,`builder.${o?"tsx":"jsx"}`),!a.appDir){let s=e.join(t,"app");await e.exists(s)&&(a.appDir=s)}if(!a.pagesDir){let s=e.join(t,"pages");await e.exists(s)&&(a.pagesDir=s)}if(!a.appDir&&!a.pagesDir)throw new Error(`Could not find Next.js "app" or "pages" directory. Searched in "${t}".`);return a}function ht(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function vo(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 Fe(e){return await de(e,[".env"],Cn)}async function Sn(e,t){Po(t);let r=await Fe(e),n=await ge(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function Po(e){typeof process<"u"&&(process.env[Cn]=e)}var Cn="PUBLIC_BUILDER_API_KEY";function wn(e,t,r){if(r.length===0)return e;let n=e.split(`
231
231
  `),o=n.findIndex(s=>s.includes(r));if(o===-1||n.some(s=>s.includes(t[0])))return e;let a=["/**",...t.map(s=>` * ${s.trim()}`)," */"];return n.splice(o,0,...a),n.join(`
232
- `)}function Xe(e,t,r){return mt(e,t,r.variableName)?t:bo(e,t,r)}function bo(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),l=e.ts.factory.createVariableStatement([s],a),m=[...t.statements,l];return e.ts.factory.updateSourceFile(t,m)}async function yn(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(".")||No.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await Ze(e,o,s,i);r.push(...l)})),r}async function Tn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return Po(e,t,n)}return null}function Po(e,t,r){let n=E(e,r);return Ze(e,null,t,n)}async function Ze(e,t,r,n){r=e.normalize(r);let o=[],i=V(e,n);return await Promise.all(i.map(async a=>{let s=await Io(e,t,r,a);s&&o.push(s)})),o}async function Io(e,t,r,n){let o=e.relative(e.getRootDir(),r);if(e.ts.isVariableStatement(n.node))for(let i of n.node.declarationList.declarations){let a=wn(e,i.initializer);if(a&&e.ts.isIdentifier(i.name)){let s=i.name.text;return{cmpInfo:{id:await _(e,r,s),displayFilePath:N(e,r),name:j(s),inputs:[],exportName:n.isDefaultExport?"default":s,exportType:n.isDefaultExport?"default":"named",importName:s,filePath:r,relFilePath:o},node:a}}}else if(e.ts.isCallExpression(n.node)){let i=wn(e,n.node);if(i)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:N(e,r),name:Y(e,r),inputs:[],exportName:"default",exportType:"default",importName:Ee(e,r),filePath:r,relFilePath:o},node:i}}return null}function wn(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 No=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function En(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 Ue(e,t.cmpInfo.filePath,null);if(!(await Ze(e,i,t.cmpInfo.filePath,o)).find(l=>l.cmpInfo.id===t.cmpInfo.id))throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return Ie(e,i,r)}return[]}async function Dn(e){return ht(e)}async function ht(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Ro),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var Ro=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
232
+ `)}function Ze(e,t,r){return dt(e,t,r.variableName)?t:bo(e,t,r)}function bo(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),l=e.ts.factory.createVariableStatement([s],a),m=[...t.statements,l];return e.ts.factory.updateSourceFile(t,m)}async function yn(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(".")||Ro.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await et(e,o,s,i);r.push(...l)})),r}async function En(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return Io(e,t,n)}return null}function Io(e,t,r){let n=E(e,r);return et(e,null,t,n)}async function et(e,t,r,n){r=e.normalize(r);let o=[],i=$(e,n);return await Promise.all(i.map(async a=>{let s=await No(e,t,r,a);s&&o.push(s)})),o}async function No(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=B(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=Tn(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let l=a.name.text;return{cmpInfo:{id:await _(e,r,l),displayFilePath:N(e,r),name:j(l),inputs:[],exportName:n.isDefaultExport?"default":l,exportType:n.isDefaultExport?"default":"named",importName:l,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=Tn(e,n.node);if(a)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:N(e,r),name:G(e,r),inputs:[],exportName:"default",exportType:"default",importName:De(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function Tn(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 Ro=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function Dn(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 Me(e,t.cmpInfo.filePath,null);if(!(await et(e,i,t.cmpInfo.filePath,o)).find(l=>l.cmpInfo.id===t.cmpInfo.id))throw new Error(`createComponentInputs() Could not find component ${t.cmpInfo.name} in ${t.cmpInfo.filePath}`);return Ne(e,i,r)}return[]}async function vn(e){return St(e)}async function St(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Fo),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var Fo=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
233
233
 
234
234
  export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
235
235
  ];
236
- `;async function vn(e){await ht(e);let t=await e.readFile(e.registryPath);return t?Fo(e,t):{components:[],sourceFile:E(e,"")}}async function Fo(e,t){let r=E(e,t);return Ao(e,r)}async function Ao(e,t){let r=[],n=Z(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await St(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:G(r)}}async function St(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(D(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 Me(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let l=await Tn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let m=l.find(d=>d.cmpInfo.exportName===a);m&&(n.exportName=m.cmpInfo.exportName)}continue}}return n=re(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function bn(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}async function se(e,t,r,n,o,i,a,s){let l=await bn(e),[m,d,f]=await Promise.all([yn(e,l),vn(e),Re(e)]),c=m.map(u=>u.cmpInfo),p=d.components,h={components:ae(c,p),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let u=m.find(T=>T.cmpInfo.id===t);if(!u)throw new Error(`Component ${t} not found`);let g=d.sourceFile,x=h.components.find(T=>T.id===t),S=await En(e,u);oe(x,S),t=Array.isArray(t)?t[0]:t;let C=Ce(t,c,p,r,n,o,i),{elements:b,elmIndex:y,statementIndex:w,statement:P,variableDeclaration:O}=await Oo(e,g,u),R=!1;if(C.addCmpToRegistry?(b.push(Lo(e,C.addCmpToRegistry)),R=!0):C.removeCmpFromRegistry?(b.splice(y,1),R=!0):C.updateRegisteredCmp&&(b[y]=X(e,b[y],C.updateRegisteredCmp),R=!0),R&&a){let T=[...g.statements];T[w]=e.ts.factory.updateVariableStatement(P,P.modifiers,e.ts.factory.updateVariableDeclarationList(P.declarationList,[e.ts.factory.updateVariableDeclaration(O,O.name,O.exclamationToken,O.type,e.ts.factory.createArrayLiteralExpression(He(e,b)))])),g=e.ts.factory.updateSourceFile(g,T),x.exportType==="named"?g=v(e,g,{namedImports:[x.importName],importPath:A(e,e.registryPath,x.filePath)}):g=v(e,g,{defaultImport:x.importName,importPath:A(e,e.registryPath,x.filePath)}),g=v(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=Xe(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=Se(e,g),g=he(e,g);let F=I(e,g);F=ee(F),F=Cn(F,ko,"CUSTOM_COMPONENTS"),F=await e.formatCode(e.registryPath,F),await e.writeFile(e.registryPath,F)}h.components=C.components}return h}function Lo(e,t){return X(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Oo(e,t,r){let n=Z(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 St(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var ko=["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 Pn(e){let t=await jo(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>Dn(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>se(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await se(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>se(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>se(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>se(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>se(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Re(t),setPublicApiKey:n=>hn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>ue(t),setCache:n=>fe(t,n)}}async function jo(e){let t=await ye(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 Fe(e){return await me(e,[".env"],Ae)}async function In(e,t){let r=await Fe(e),n=await de(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Ae="PUBLIC_BUILDER_KEY";async function Nn(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"||_o.has(s)||s.includes("$."))return;let l=e.normalize(a.fileName);if(l===e.remixConfigPath||l===e.registryPath||l===i)return;let m=await ie(e,o,l,a);r.push(...m)})),r}var _o=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Rn(e){await wt(e);let t=await e.readFile(e.registryPath);return t?Bo(e,t):{components:[],sourceFile:E(e,"")}}async function Bo(e,t){let r=E(e,t);return Vo(e,r)}async function Vo(e,t){let r=[],n=Z(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Ct(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:G(r)}}async function Ct(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",inputs:[],acceptsChildren:!1};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(D(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 l=await Me(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let m=await en(e,l.filePath);if(m&&m.length>0)if(m.length===1)n.exportName=m[0].cmpInfo.exportName;else{let d=m.find(f=>f.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=re(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function M(e,t,r,n,o,i,a,s){let l=await Ge(e),[m,d,f]=await Promise.all([Nn(e,l),Rn(e),Fe(e)]),c=m.map(S=>S.cmpInfo),p=d.components,h={components:ae(c,p),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(c),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await Je(e,h.components),h;let u=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let S=x.map(y=>{let w=m.find(P=>P.cmpInfo.id===y);if(!w)throw new Error(`Component ${y} not found`);return w}),C=Array.from(new Set(S.map(y=>y.cmpInfo.filePath))),b=await $(e,C);for(let y of S){let w=h.components.find(K=>K.id===y.cmpInfo.id),P=await We(e,y,b);oe(w,P);let O=c.findIndex(K=>K.id===y.cmpInfo.id);c[O].inputs=P;let R=Ce(y.cmpInfo.id,c,p,r,n,o,i),{elements:T,elmIndex:F,statementIndex:k,statement:pe,variableDeclaration:_e}=await zo(e,g,y);if(R.addCmpToRegistry)T.push($o(e,R.addCmpToRegistry)),u=!0;else if(R.removeCmpFromRegistry)T.splice(F,1),u=!0;else if(R.updateRegisteredCmp){let K=X(e,T[F],R.updateRegisteredCmp);T[F]=e.ts.factory.updateObjectLiteralExpression(K,[Fn(e,R.updateRegisteredCmp),...K.properties.slice(1)]),u=!0}if(u&&a){let K=[...g.statements];K[k]=e.ts.factory.updateVariableStatement(pe,pe.modifiers,e.ts.factory.updateVariableDeclarationList(pe.declarationList,[e.ts.factory.updateVariableDeclaration(_e,_e.name,_e.exclamationToken,_e.type,e.ts.factory.createArrayLiteralExpression(He(e,T)))])),g=e.ts.factory.updateSourceFile(g,K),w.exportType==="named"?g=v(e,g,{namedImports:[w.importName],importPath:A(e,e.registryPath,w.filePath)}):g=v(e,g,{defaultImport:w.importName,importPath:A(e,e.registryPath,w.filePath)}),g=v(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),w.acceptsChildren&&(g=v(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=Xe(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=R.components,p=R.components.filter(dr=>dr.isRegistered)}}}if(u&&a){g=Se(e,g),g=he(e,g);let S=I(e,g);S=ee(S),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return h}function Fn(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 $o(e,t){return X(e,e.ts.factory.createObjectLiteralExpression([Fn(e,t)],!0),t)}async function zo(e,t,r){let n=Z(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 Ct(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function An(e){let t=[],r=await Ko(e,t);return t.push(...await wt(e)),await qo(e,r),await Mo(e,t),t}async function Ln(e){let t=[];return await Uo(e,t),t}async function Uo(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,On({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Mo(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,On({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function On({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=A(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${Ae}`;return e.getFrameworks().some(l=>l.name==="@shopify/remix-oxygen")&&(s=`context.env.${Ae}`),n&&(s+="!"),`
236
+ `;async function Pn(e){await St(e);let t=await e.readFile(e.registryPath);return t?Ao(e,t):{components:[],sourceFile:E(e,"")}}async function Ao(e,t){let r=E(e,t);return Lo(e,r)}async function Lo(e,t){let r=[],n=ee(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Ct(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:X(r)}}async function Ct(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(D(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 Ke(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=B(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let l=await En(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let m=l.find(d=>d.cmpInfo.exportName===a);m&&(n.exportName=m.cmpInfo.exportName)}continue}}return n=oe(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function bn(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".ts"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await U(e,[...t])}async function le(e,t,r,n,o,i,a,s){let l=await bn(e),[m,d,p]=await Promise.all([yn(e,l),Pn(e),Fe(e)]),c=m.map(f=>f.cmpInfo),u=d.components,h={components:se(c,u),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:he(c),publicApiKey:p.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let f=m.find(y=>y.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let g=d.sourceFile,x=h.components.find(y=>y.id===t),S=await Dn(e,f);ie(x,S),t=Array.isArray(t)?t[0]:t;let C=we(t,c,u,r,n,o,i),{elements:P,elmIndex:T,statementIndex:w,statement:b,variableDeclaration:O}=await ko(e,g,f),R=!1;if(C.addCmpToRegistry?(P.push(Oo(e,C.addCmpToRegistry)),R=!0):C.removeCmpFromRegistry?(P.splice(T,1),R=!0):C.updateRegisteredCmp&&(P[T]=Z(e,P[T],C.updateRegisteredCmp),R=!0),R&&a){let y=[...g.statements];y[w]=e.ts.factory.updateVariableStatement(b,b.modifiers,e.ts.factory.updateVariableDeclarationList(b.declarationList,[e.ts.factory.updateVariableDeclaration(O,O.name,O.exclamationToken,O.type,e.ts.factory.createArrayLiteralExpression(Ye(e,P)))])),g=e.ts.factory.updateSourceFile(g,y),x.exportType==="named"?g=v(e,g,{namedImports:[x.importName],importPath:A(e,e.registryPath,x.filePath)}):g=v(e,g,{defaultImport:x.importName,importPath:A(e,e.registryPath,x.filePath)}),g=v(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),g=Ze(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),g=Ce(e,g),g=Se(e,g);let F=I(e,g);F=te(F),F=wn(F,jo,"CUSTOM_COMPONENTS"),F=await e.formatCode(e.registryPath,F),await e.writeFile(e.registryPath,F)}h.components=C.components}return h}function Oo(e,t){return Z(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function ko(e,t,r){let n=ee(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 Ct(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var jo=["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 In(e){let t=await _o(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>vn(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>le(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await le(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>le(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>le(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>le(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>le(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Fe(t),setPublicApiKey:n=>Sn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>me(t,n)}}async function _o(e){let t=await ye(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 Ae(e){return await de(e,[".env"],Le)}async function Nn(e,t){let r=await Ae(e),n=await ge(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var Le="PUBLIC_BUILDER_KEY";async function Rn(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"||Bo.has(s)||s.includes("$."))return;let l=e.normalize(a.fileName);if(l===e.remixConfigPath||l===e.registryPath||l===i)return;let m=await ae(e,o,l,a);r.push(...m)})),r}var Bo=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Fn(e){await Tt(e);let t=await e.readFile(e.registryPath);return t?Vo(e,t):{components:[],sourceFile:E(e,"")}}async function Vo(e,t){let r=E(e,t);return $o(e,r)}async function $o(e,t){let r=[],n=ee(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await wt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:X(r)}}async function wt(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(D(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 p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let l=await Ke(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=B(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let m=await tn(e,l.filePath);if(m&&m.length>0)if(m.length===1)n.exportName=m[0].cmpInfo.exportName;else{let d=m.find(p=>p.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=oe(e,n,r),n.filePath&&n.exportName&&(n.id=await _(e,n.filePath,n.exportName)),n}async function K(e,t,r,n,o,i,a,s){let l=await Xe(e),[m,d,p]=await Promise.all([Rn(e,l),Fn(e),Ae(e)]),c=m.map(S=>S.cmpInfo),u=d.components,h={components:se(c,u),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:he(c),publicApiKey:p.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await We(e,h.components),h;let f=!1,g=d.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let S=x.map(T=>{let w=m.find(b=>b.cmpInfo.id===T);if(!w)throw new Error(`Component ${T} not found`);return w}),C=Array.from(new Set(S.map(T=>T.cmpInfo.filePath))),P=await U(e,C);for(let T of S){let w=h.components.find(Q=>Q.id===T.cmpInfo.id),b=await He(e,T,P);ie(w,b);let O=c.findIndex(Q=>Q.id===T.cmpInfo.id);c[O].inputs=b;let R=we(T.cmpInfo.id,c,u,r,n,o,i),{elements:y,elmIndex:F,statementIndex:k,statement:ue,variableDeclaration:Be}=await Uo(e,g,T);if(R.addCmpToRegistry)y.push(zo(e,R.addCmpToRegistry)),f=!0;else if(R.removeCmpFromRegistry)y.splice(F,1),f=!0;else if(R.updateRegisteredCmp){let Q=Z(e,y[F],R.updateRegisteredCmp);y[F]=e.ts.factory.updateObjectLiteralExpression(Q,[An(e,R.updateRegisteredCmp),...Q.properties.slice(1)]),f=!0}if(f&&a){let Q=[...g.statements];Q[k]=e.ts.factory.updateVariableStatement(ue,ue.modifiers,e.ts.factory.updateVariableDeclarationList(ue.declarationList,[e.ts.factory.updateVariableDeclaration(Be,Be.name,Be.exclamationToken,Be.type,e.ts.factory.createArrayLiteralExpression(Ye(e,y)))])),g=e.ts.factory.updateSourceFile(g,Q),w.exportType==="named"?g=v(e,g,{namedImports:[w.importName],importPath:A(e,e.registryPath,w.filePath)}):g=v(e,g,{defaultImport:w.importName,importPath:A(e,e.registryPath,w.filePath)}),g=v(e,g,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),w.acceptsChildren&&(g=v(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),g=Ze(e,g,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=R.components,u=R.components.filter(gr=>gr.isRegistered)}}}if(f&&a){g=Ce(e,g),g=Se(e,g);let S=I(e,g);S=te(S),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return h}function An(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 zo(e,t){return Z(e,e.ts.factory.createObjectLiteralExpression([An(e,t)],!0),t)}async function Uo(e,t,r){let n=ee(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 wt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Ln(e){let t=[],r=await Qo(e,t);return t.push(...await Tt(e)),await Jo(e,r),await Ko(e,t),t}async function On(e){let t=[];return await Mo(e,t),t}async function Mo(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,kn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function Ko(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,kn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function kn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=A(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${Le}`;return e.getFrameworks().some(l=>l.name==="@shopify/remix-oxygen")&&(s=`context.env.${Le}`),n&&(s+="!"),`
237
237
  import { BuilderComponent, builder } from "@builder.io/react";
238
238
  import { useLoaderData } from "@remix-run/react";
239
239
  import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
@@ -290,11 +290,11 @@ export default function Page() {
290
290
  ${n?`
291
291
  declare global {
292
292
  interface Env {
293
- ${Ae}: string;
293
+ ${Le}: string;
294
294
  }
295
295
  }
296
296
  `:""}
297
- `}async function Ko(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=Qo(e),m=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${m}`),!m){let f=await e.formatCode(i,s);await e.writeFile(i,f),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function Qo(e){let t=e.typescriptEnabled,r=`
297
+ `}async function Qo(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=qo(e),m=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${m}`),!m){let p=await e.formatCode(i,s);await e.writeFile(i,p),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function qo(e){let t=e.typescriptEnabled,r=`
298
298
  import { useState } from "react";
299
299
  import styles from "./styles.module.css";
300
300
  ${t?`
@@ -357,18 +357,18 @@ export default Counter;
357
357
  font-size: 42px;
358
358
  text-align: center;
359
359
  }
360
- `.trimStart();return{component:r,styles:n}}async function qo(e,t){let n=(await M(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await M(e,n.id,!0,!1,null,null,!0,!1)}async function wt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Jo(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function Jo(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/react";
360
+ `.trimStart();return{component:r,styles:n}}async function Jo(e,t){let n=(await K(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await K(e,n.id,!0,!1,null,null,!0,!1)}async function Tt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Wo(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function Wo(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/react";
361
361
 
362
362
  export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
363
363
  ];`:`export const CUSTOM_COMPONENTS = [
364
364
  ];
365
- `}async function kn(e){let t=await Wo(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:()=>An(t),ensureFigmaImportPage:()=>Ln(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>M(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await M(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>M(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>M(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>M(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>M(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Fe(t),setPublicApiKey:n=>In(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ue(t),setCache:n=>fe(t,n)}}async function Wo(e){let t=await Go(e),r=await Xo(e),n=e.dirname(r),o=e.join(n,"components"),i=await Ho(e),a=`builder-registry.${i?"ts":"js"}`,s=e.join(n,a);return{...e,registryPath:s,remixConfigPath:t,typescriptEnabled:i,appDir:n,componentsDir:o,routesDir:r,hasLocaleParam:await Yo(e,r)}}function Ho(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Yo(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Go(e){let t=["remix.config.ts","remix.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 Xo(e){let t=await ye(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.`)}var it=yr(Wn(),1);async function Hn(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:B(i.inputs)};return B(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,it.compress)(n);return btoa(JSON.stringify(o))}async function Yn(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,it.decompress)(o),a=B(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let l=z(e.normalize(s.filePath)),m=n.components.find(f=>z(f.filePath).endsWith(l)&&f.exportName===s.exportName);if(!m){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${m.id})`,m.filePath),await t.registerComponent({cmpId:m.id});for(let f of s.inputs)e.debug(`set input (${m.id})`),await t.setRegisteredComponentInput({cmpId:m.id,name:f.name,type:f.type,required:f.required,defaultValue:f.defaultValue,friendlyName:f.friendlyName,helperText:f.helperText});e.debug(`set input (${m.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:m.id,name:s.name,image:s.image,description:s.description});a=B(d)}return a}var Ti={"@builder.io/qwik-city":Pn,next:xn,"@remix-run/react":kn};async function Gn(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 H(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=Ti[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Hn(e,n),importRegistry:i=>Yn(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Xn(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 p="",h=0,u=-1,g=0,x;for(let S=0;S<=f.length;++S){if(S<f.length)x=f.charCodeAt(S);else{if(x===47)break;x=47}if(x===47){if(!(u===S-1||g===1))if(u!==S-1&&g===2){if(p.length<2||h!==2||p.charCodeAt(p.length-1)!==46||p.charCodeAt(p.length-2)!==46){if(p.length>2){let C=p.lastIndexOf("/");if(C!==p.length-1){C===-1?(p="",h=0):(p=p.slice(0,C),h=p.length-1-p.lastIndexOf("/")),u=S,g=0;continue}}else if(p.length===2||p.length===1){p="",h=0,u=S,g=0;continue}}c&&(p.length>0?p+="/..":p="..",h=2)}else p.length>0?p+="/"+f.slice(u+1,S):p=f.slice(u+1,S),h=S-u-1;u=S,g=0}else x===46&&g!==-1?++g:g=-1}return p}let n=function(...c){let p="",h=!1;for(let u=c.length-1;u>=-1&&!h;u--){let g;u>=0?g=c[u]:e.cwd?g=e.cwd():g="/",t(g),g.length!==0&&(p=g+"/"+p,h=g.charCodeAt(0)===47)}return p=r(p,!h),h?p.length>0?"/"+p:"/":p.length>0?p:"."},o=function(c){if(t(c),c.length===0)return".";let p=c.charCodeAt(0)===47,h=c.charCodeAt(c.length-1)===47;return c=r(c,!p),c.length===0&&!p&&(c="."),c.length>0&&h&&(c+="/"),p?"/"+c:c};return{relative:function(c,p){if(t(c),t(p),c===p||(c=n(c),p=n(p),c===p))return"";let h=1;for(;h<c.length&&c.charCodeAt(h)===47;++h);let u=c.length,g=u-h,x=1;for(;x<p.length&&p.charCodeAt(x)===47;++x);let C=p.length-x,b=g<C?g:C,y=-1,w=0;for(;w<=b;++w){if(w===b){if(C>b){if(p.charCodeAt(x+w)===47)return p.slice(x+w+1);if(w===0)return p.slice(x+w)}else g>b&&(c.charCodeAt(h+w)===47?y=w:w===0&&(y=0));break}let O=c.charCodeAt(h+w),R=p.charCodeAt(x+w);if(O!==R)break;O===47&&(y=w)}let P="";for(w=h+y+1;w<=u;++w)(w===u||c.charCodeAt(w)===47)&&(P.length===0?P+="..":P+="/..");return P.length>0?P+p.slice(x+y):(x+=y,p.charCodeAt(x)===47&&++x,p.slice(x))},resolve:n,join:function(...c){if(c.length===0)return".";let p;for(let h=0;h<c.length;++h){let u=c[h];t(u),u.length>0&&(p===void 0?p=u:p+="/"+u)}return p===void 0?".":o(p)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,p){if(p!==void 0&&typeof p!="string")throw new TypeError('"ext" argument must be a string');t(c);let h=0,u=-1,g=!0,x;if(p!==void 0&&p.length>0&&p.length<=c.length){if(p.length===c.length&&p===c)return"";let S=p.length-1,C=-1;for(x=c.length-1;x>=0;--x){let b=c.charCodeAt(x);if(b===47){if(!g){h=x+1;break}}else C===-1&&(g=!1,C=x+1),S>=0&&(b===p.charCodeAt(S)?--S===-1&&(u=x):(S=-1,u=C))}return h===u?u=C:u===-1&&(u=c.length),c.slice(h,u)}else{for(x=c.length-1;x>=0;--x)if(c.charCodeAt(x)===47){if(!g){h=x+1;break}}else u===-1&&(g=!1,u=x+1);return u===-1?"":c.slice(h,u)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let p=c.charCodeAt(0),h=p===47,u=-1,g=!0;for(let x=c.length-1;x>=1;--x)if(p=c.charCodeAt(x),p===47){if(!g){u=x;break}}else g=!1;return u===-1?h?"/":".":h&&u===1?"//":c.slice(0,u)},extname:function(c){t(c);let p=-1,h=0,u=-1,g=!0,x=0;for(let S=c.length-1;S>=0;--S){let C=c.charCodeAt(S);if(C===47){if(!g){h=S+1;break}continue}u===-1&&(g=!1,u=S+1),C===46?p===-1?p=S:x!==1&&(x=1):p!==-1&&(x=-1)}return p===-1||u===-1||x===0||x===1&&p===u-1&&p===h+1?"":c.slice(p,u)}}}async function Zn(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Xn({cwd:r,...e}),o=new Map,i=u=>n.normalize(n.resolve(r(),u)),a=u=>{for(let[g]of o)if((g+"/").startsWith(u))return!0;return u===t()},s=u=>(u=i(u),o.has(u)?!0:a(u)),l=u=>{u=i(u);let g=u===t()?u:u+"/",x=g.split("/").length-1,S=[];for(let[C]of o)if(C.split("/").slice(0,x).join("/")+"/"===g){let w=C.split("/")[x];w&&!S.includes(w)&&S.push(w)}return S.sort()},m=u=>{u=i(u);let g=o.get(u);return typeof g=="string"?g:null},d=u=>(u=i(u),{isFile:()=>o.has(u),isDirectory:()=>!o.has(u)&&a(u)}),f=async u=>{if(typeof crypto<"u"){let S=new TextEncoder().encode(u),C=await crypto.subtle.digest("SHA-256",S);return Array.from(new Uint8Array(C)).map(b=>b.toString(16).padStart(2,"0")).join("")}let g=0;for(let x=0;x<u.length;x++){let S=u.charCodeAt(x);g=(g<<5)-g+S,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,p={getRootDir:t,cwd:r,exists:async u=>s(u),existsSync:s,readdir:async u=>l(u),readdirSync:l,readFile:async u=>m(u),readFileSync:m,stat:async u=>d(u),statSync:d,writeFile:async(u,g)=>{u=i(u),o.set(u,g);let x={path:u,basename:n.basename(u),dirname:n.dirname(u),extname:n.extname(u)};for(let S of c)await S(x)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",formatCode:async(u,g)=>g,on:(u,g)=>{u==="change"&&c.add(g)},off:(u,g)=>{u==="change"&&c.delete(g)},debug:(...u)=>{console.debug("[builder-dev-tools]",...u)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0"},h=await H(p);return p.getFrameworks=()=>h,p}async function er(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(tr(e,n))return o;let a=V(e,n,"cjs"),s=V(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 p=[...c.declarationList.declarations];if(p.length!==1)throw new Error("Expected a single variable declaration");let h=p[0];if(!h.initializer)throw new Error("Expected an initializer on the declaration");let u=h.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let g="BuilderDevTools()",x=[...n.statements],S=x.indexOf(c);return x[S]=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,[u]))])),n=e.ts.factory.updateSourceFile(n,x),n=v(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let l=a[0];if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let f=d.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=Ot(e,n);n=c.sourceFile;let p=[...n.statements],h=p.indexOf(d);return p[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,p),o.content=I(e,n),o.hasContentUpdates=!0,o}let m=l.statement;if(e.ts.isVariableStatement(m)){let d=[...m.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 p=Ot(e,n);n=p.sourceFile;let h=[...n.statements],u=h.indexOf(m);return h[u]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(l.node)){let d=l.node,f=l.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=l.node.body;if(!e.ts.isBlock(h))throw new Error("Expected a block body on the next config function");let u=[...h.statements],g=u.findIndex(y=>e.ts.isReturnStatement(y));if(g===-1)throw new Error("Expected a return statement on the next config function");let x=u[g],S=Ot(e,n);n=S.sourceFile,u[g]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(S.withFnVariableName),void 0,[x.expression]));let C=[...n.statements],b=C.indexOf(f);return C[b]=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,u)))),n=e.ts.factory.updateSourceFile(n,C),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function tr(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 Ot(e,t){let r=tr(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 or(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(ir(e,n))return o;let a=V(e,n,"cjs"),s=V(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let l=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let 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()",p=Ei(e,f.expression);if(!p)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[p]),u=[...n.statements],g=u.indexOf(f);return u[g]=e.ts.factory.updateExportAssignment(f,f.modifiers,h),n=e.ts.factory.updateSourceFile(n,u),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=I(e,n),o.hasContentUpdates=!0,o}}if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let f=d.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let c=nr(e,n);n=c.sourceFile;let p=[...n.statements],h=p.indexOf(d);return p[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,p),o.content=I(e,n),o.hasContentUpdates=!0,o}let m=l.statement;if(e.ts.isVariableStatement(m)){let d=[...m.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 p=nr(e,n);n=p.sourceFile;let h=[...n.statements],u=h.indexOf(m);return h[u]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function ir(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 nr(e,t){let r=ir(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 Ei(e,t){let r=[...t.properties],n=r.findIndex(i=>D(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=rr(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=rr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function rr(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 sr(e,t,r){let n=E(e,r),o=V(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let l=[...i.node.arguments];if(l.length===0)throw new Error("Expected an argument in defineConfig()");let m=l[0];if(e.ts.isArrowFunction(m)){let d=Di(e,m);if(!d)return s;l[0]=e.ts.factory.updateArrowFunction(m,m.modifiers,m.typeParameters,m.parameters,m.type,m.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,l)),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=I(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(m)){let d=kt(e,m);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=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=I(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let l=kt(e,a.expression);if(!l)return s;let m=[...n.statements],d=m.indexOf(a);return m[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,l),n=e.ts.factory.updateSourceFile(n,m),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=I(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Di(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=kt(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function kt(e,t){let r=[...t.properties],n=r.findIndex(i=>D(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=ar(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=ar(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function ar(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,[])])}async function lr(e,t,r){throw new Error("Webpack config updates not implemented")}var pr=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:er},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:or},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:sr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:lr}];async function jt(e){let t=e.resolve("/");for(let n of pr)for(let o of n.configFileNames){let i=e.getRootDir();for(let a=0;a<10;a++)try{let s=e.join(i,o),l=e.readFileSync(s);if(typeof l=="string")return{id:n.id,filePath:s,content:l};if(i===t)break;i=e.dirname(i)}catch(s){if((s?.message??"").includes("Invalid path"))break;throw s}}if((await H(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,cr),{id:"next",filePath:n,content:cr}}return null}async function ur(e){let t=await jt(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await pr.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=ee(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var cr=`
365
+ `}async function jn(e){let t=await Ho(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:()=>Ln(t),ensureFigmaImportPage:()=>On(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>K(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await K(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>K(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>K(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>K(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>K(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ae(t),setPublicApiKey:n=>Nn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>fe(t),setCache:n=>me(t,n)}}async function Ho(e){let t=await Xo(e),r=await Zo(e),n=e.dirname(r),o=e.join(n,"components"),i=await Yo(e),a=`builder-registry.${i?"ts":"js"}`,s=e.join(n,a);return{...e,registryPath:s,remixConfigPath:t,typescriptEnabled:i,appDir:n,componentsDir:o,routesDir:r,hasLocaleParam:await Go(e,r)}}function Yo(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Go(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Xo(e){let t=["remix.config.ts","remix.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 Zo(e){let t=await ye(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.`)}var at=yr(Hn(),1);async function Yn(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:V(i.inputs)};return V(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,at.compress)(n);return btoa(JSON.stringify(o))}async function Gn(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,at.decompress)(o),a=V(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let l=z(e.normalize(s.filePath)),m=n.components.find(p=>z(p.filePath).endsWith(l)&&p.exportName===s.exportName);if(!m){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${m.id})`,m.filePath),await t.registerComponent({cmpId:m.id});for(let p of s.inputs)e.debug(`set input (${m.id})`),await t.setRegisteredComponentInput({cmpId:m.id,name:p.name,type:p.type,required:p.required,defaultValue:p.defaultValue,friendlyName:p.friendlyName,helperText:p.helperText});e.debug(`set input (${m.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:m.id,name:s.name,image:s.image,description:s.description});a=V(d)}return a}var Ei={"@builder.io/qwik-city":In,next:hn,"@remix-run/react":jn};async function Xn(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 Y(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=Ei[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>Yn(e,n),importRegistry:i=>Gn(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Zn(e){function t(p){if(typeof p!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(p))}function r(p,c){let u="",h=0,f=-1,g=0,x;for(let S=0;S<=p.length;++S){if(S<p.length)x=p.charCodeAt(S);else{if(x===47)break;x=47}if(x===47){if(!(f===S-1||g===1))if(f!==S-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 C=u.lastIndexOf("/");if(C!==u.length-1){C===-1?(u="",h=0):(u=u.slice(0,C),h=u.length-1-u.lastIndexOf("/")),f=S,g=0;continue}}else if(u.length===2||u.length===1){u="",h=0,f=S,g=0;continue}}c&&(u.length>0?u+="/..":u="..",h=2)}else u.length>0?u+="/"+p.slice(f+1,S):u=p.slice(f+1,S),h=S-f-1;f=S,g=0}else x===46&&g!==-1?++g:g=-1}return u}let n=function(...c){let u="",h=!1;for(let f=c.length-1;f>=-1&&!h;f--){let g;f>=0?g=c[f]: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 f=c.length,g=f-h,x=1;for(;x<u.length&&u.charCodeAt(x)===47;++x);let C=u.length-x,P=g<C?g:C,T=-1,w=0;for(;w<=P;++w){if(w===P){if(C>P){if(u.charCodeAt(x+w)===47)return u.slice(x+w+1);if(w===0)return u.slice(x+w)}else g>P&&(c.charCodeAt(h+w)===47?T=w:w===0&&(T=0));break}let O=c.charCodeAt(h+w),R=u.charCodeAt(x+w);if(O!==R)break;O===47&&(T=w)}let b="";for(w=h+T+1;w<=f;++w)(w===f||c.charCodeAt(w)===47)&&(b.length===0?b+="..":b+="/..");return b.length>0?b+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 f=c[h];t(f),f.length>0&&(u===void 0?u=f:u+="/"+f)}return u===void 0?".":o(u)},isAbsolute:function(c){return t(c),c.length>0&&c.charCodeAt(0)===47},basename:function(c,u){if(u!==void 0&&typeof u!="string")throw new TypeError('"ext" argument must be a string');t(c);let h=0,f=-1,g=!0,x;if(u!==void 0&&u.length>0&&u.length<=c.length){if(u.length===c.length&&u===c)return"";let S=u.length-1,C=-1;for(x=c.length-1;x>=0;--x){let P=c.charCodeAt(x);if(P===47){if(!g){h=x+1;break}}else C===-1&&(g=!1,C=x+1),S>=0&&(P===u.charCodeAt(S)?--S===-1&&(f=x):(S=-1,f=C))}return h===f?f=C:f===-1&&(f=c.length),c.slice(h,f)}else{for(x=c.length-1;x>=0;--x)if(c.charCodeAt(x)===47){if(!g){h=x+1;break}}else f===-1&&(g=!1,f=x+1);return f===-1?"":c.slice(h,f)}},normalize:o,dirname:function(c){if(t(c),c.length===0)return".";let u=c.charCodeAt(0),h=u===47,f=-1,g=!0;for(let x=c.length-1;x>=1;--x)if(u=c.charCodeAt(x),u===47){if(!g){f=x;break}}else g=!1;return f===-1?h?"/":".":h&&f===1?"//":c.slice(0,f)},extname:function(c){t(c);let u=-1,h=0,f=-1,g=!0,x=0;for(let S=c.length-1;S>=0;--S){let C=c.charCodeAt(S);if(C===47){if(!g){h=S+1;break}continue}f===-1&&(g=!1,f=S+1),C===46?u===-1?u=S:x!==1&&(x=1):u!==-1&&(x=-1)}return u===-1||f===-1||x===0||x===1&&u===f-1&&u===h+1?"":c.slice(u,f)}}}async function er(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Zn({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[g]of o)if((g+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),l=f=>{f=i(f);let g=f===t()?f:f+"/",x=g.split("/").length-1,S=[];for(let[C]of o)if(C.split("/").slice(0,x).join("/")+"/"===g){let w=C.split("/")[x];w&&!S.includes(w)&&S.push(w)}return S.sort()},m=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)}),p=async f=>{if(typeof crypto<"u"){let S=new TextEncoder().encode(f),C=await crypto.subtle.digest("SHA-256",S);return Array.from(new Uint8Array(C)).map(P=>P.toString(16).padStart(2,"0")).join("")}let g=0;for(let x=0;x<f.length;x++){let S=f.charCodeAt(x);g=(g<<5)-g+S,g|=0}return Number(Math.abs(g)).toString(36)},c=new Set,u={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>l(f),readdirSync:l,readFile:async f=>m(f),readFileSync:m,stat:async f=>d(f),statSync:d,writeFile:async(f,g)=>{f=i(f),o.set(f,g);let x={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let S of c)await S(x)},hash:p,getDeviceId:async()=>typeof navigator<"u"?p(navigator.userAgent):"",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"},h=await Y(u);return u.getFrameworks=()=>h,u}async function tr(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(nr(e,n))return o;let a=$(e,n,"cjs"),s=$(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 p=d.statement;if(!e.ts.isVariableStatement(p))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 f=h.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let g="BuilderDevTools()",x=[...n.statements],S=x.indexOf(c);return x[S]=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,[f]))])),n=e.ts.factory.updateSourceFile(n,x),n=v(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let l=a[0];if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let p=d.expression;if(!e.ts.isBinaryExpression(p))throw new Error("Expected a binary expression for the default export");let c=kt(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(p,p.left,p.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[p.right]))),n=e.ts.factory.updateSourceFile(n,u),o.content=I(e,n),o.hasContentUpdates=!0,o}let m=l.statement;if(e.ts.isVariableStatement(m)){let d=[...m.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let p=d[0];if(!p.initializer)throw new Error("Expected an initializer on the declaration");let c=p.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let u=kt(e,n);n=u.sourceFile;let h=[...n.statements],f=h.indexOf(m);return h[f]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(l.node)){let d=l.node,p=l.statement;if(!e.ts.isExpressionStatement(p))throw new Error("Expected an expression statement for the default export");let c=p.expression;if(!e.ts.isBinaryExpression(c))throw new Error("Expected a binary expression for the default export");let h=l.node.body;if(!e.ts.isBlock(h))throw new Error("Expected a block body on the next config function");let f=[...h.statements],g=f.findIndex(T=>e.ts.isReturnStatement(T));if(g===-1)throw new Error("Expected a return statement on the next config function");let x=f[g],S=kt(e,n);n=S.sourceFile,f[g]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(S.withFnVariableName),void 0,[x.expression]));let C=[...n.statements],P=C.indexOf(p);return C[P]=e.ts.factory.updateExpressionStatement(p,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,f)))),n=e.ts.factory.updateSourceFile(n,C),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function nr(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 kt(e,t){let r=nr(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 ir(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(ar(e,n))return o;let a=$(e,n,"cjs"),s=$(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let l=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let p=d.statement;if(!e.ts.isExportAssignment(p))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(p.expression)){let c="builderDevTools()",u=Di(e,p.expression);if(!u)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c),void 0,[u]),f=[...n.statements],g=f.indexOf(p);return f[g]=e.ts.factory.updateExportAssignment(p,p.modifiers,h),n=e.ts.factory.updateSourceFile(n,f),n=v(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=I(e,n),o.hasContentUpdates=!0,o}}if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let p=d.expression;if(!e.ts.isBinaryExpression(p))throw new Error("Expected a binary expression for the default export");let c=rr(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(p,p.left,p.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(c.withFnVariableName),void 0,[p.right]))),n=e.ts.factory.updateSourceFile(n,u),o.content=I(e,n),o.hasContentUpdates=!0,o}let m=l.statement;if(e.ts.isVariableStatement(m)){let d=[...m.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let p=d[0];if(!p.initializer)throw new Error("Expected an initializer on the declaration");let c=p.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let u=rr(e,n);n=u.sourceFile;let h=[...n.statements],f=h.indexOf(m);return h[f]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[c]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function ar(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 rr(e,t){let r=ar(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 Di(e,t){let r=[...t.properties],n=r.findIndex(i=>D(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=or(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=or(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function or(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 lr(e,t,r){let n=E(e,r),o=$(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let l=[...i.node.arguments];if(l.length===0)throw new Error("Expected an argument in defineConfig()");let m=l[0];if(e.ts.isArrowFunction(m)){let d=vi(e,m);if(!d)return s;l[0]=e.ts.factory.updateArrowFunction(m,m.modifiers,m.typeParameters,m.parameters,m.type,m.equalsGreaterThanToken,d);let p=[...n.statements],c=p.indexOf(a);return p[c]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,l)),n=e.ts.factory.updateSourceFile(n,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=I(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(m)){let d=jt(e,m);if(!d)return s;let p=[...n.statements],c=p.indexOf(a);return p[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,p),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=I(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let l=jt(e,a.expression);if(!l)return s;let m=[...n.statements],d=m.indexOf(a);return m[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,l),n=e.ts.factory.updateSourceFile(n,m),n=v(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=I(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function vi(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=jt(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function jt(e,t){let r=[...t.properties],n=r.findIndex(i=>D(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=sr(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=sr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function sr(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,[])])}async function cr(e,t,r){throw new Error("Webpack config updates not implemented")}var ur=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:tr},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:ir},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:lr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:cr}];async function _t(e){let t=e.resolve("/");for(let n of ur)for(let o of n.configFileNames){let i=e.getRootDir();for(let a=0;a<10;a++)try{let s=e.join(i,o),l=e.readFileSync(s);if(typeof l=="string")return{id:n.id,filePath:s,content:l};if(i===t)break;i=e.dirname(i)}catch(s){if((s?.message??"").includes("Invalid path"))break;throw s}}if((await Y(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,pr),{id:"next",filePath:n,content:pr}}return null}async function fr(e){let t=await _t(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await ur.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=te(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var pr=`
366
366
  /** @type {import('next').NextConfig} */
367
367
  const nextConfig = {
368
368
  }
369
369
 
370
370
  module.exports = nextConfig
371
- `.trimStart();var fr="/~builder-dev-tools.js";function mr(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(fr,e);t.searchParams.set("v",je);let r=JSON.stringify(je),n=`/* Builder Devtools v${je} */
371
+ `.trimStart();var mr="/~builder-dev-tools.js";function dr(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(mr,e);t.searchParams.set("v",_e);let r=JSON.stringify(_e),n=`/* Builder Devtools v${_e} */
372
372
  `;return n+=`(() => {
373
373
  `,n+=` if (typeof document !== "undefined") {
374
374
  `,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]");
@@ -381,4 +381,4 @@ module.exports = nextConfig
381
381
  `,n+=` }
382
382
  `,n+=` }
383
383
  `,n+=`})();
384
- `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var je="0.2.30";
384
+ `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var _e="0.2.31";