@builder.io/dev-tools 0.2.24 → 0.2.25

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.mjs CHANGED
@@ -1,6 +1,6 @@
1
- var cr=Object.create;var Lt=Object.defineProperty;var pr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var J=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var dr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ur(t))!mr.call(e,o)&&o!==r&&Lt(e,o,{get:()=>t[o],enumerable:!(n=pr(t,o))||n.enumerable});return e};var gr=(e,t,r)=>(r=e!=null?cr(fr(e)):{},dr(t||!e||!e.__esModule?Lt(r,"default",{value:e,enumerable:!0}):r,e));var Ct=J(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});function Ln(e){return Object.prototype.toString.call(e)}Xe.getType=Ln;function qo(e){throw new TypeError("unsupported data type: "+Ln(e))}Xe.throwUnknownDataType=qo});var Et=J(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,wt={};for(let e=0;e<we;e++){let t=Q[e];wt[t]=e}function yt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=wt[o];i*=r,t+=i,r*=we}return t}q.s_to_int=yt;function kn(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(wt[i]);a*=r,t+=a,r*=n}return t}q.s_to_big_int=kn;function Tt(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=Tt;function On(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=On;function et(e){return e.split("").reverse().join("")}function jn(e){if(e<0)return"-"+jn(-e);let[t,r]=e.toString().split(".");if(!r)return Tt(e);let n;r&&([r,n]=r.split("e")),t=Ze(t),r=et(r),r=Ze(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=et(n),n=Ze(n),o+=n}return o}q.num_to_s=jn;function Ze(e){let t=+e;return t.toString()===e?Tt(t):":"+On(BigInt(e))}q.int_str_to_s=Ze;function St(e){return e[0]===":"?kn(e.substring(1)).toString():yt(e).toString()}function _n(e){if(e[0]==="-")return-_n(e.substr(1));let[t,r,n]=e.split(".");if(!r)return yt(t);t=St(t),r=St(r),r=et(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=St(n),n=et(n),o+=i?-n:+n}return+o}q.s_to_num=_n});var vt=J(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});var Dt=Et();function Wo(e){return"n|"+Dt.num_to_s(e)}W.encodeNum=Wo;function Jo(e){return e=e.replace("n|",""),Dt.s_to_num(e)}W.decodeNum=Jo;function Ho(e){return typeof e=="number"?e:Dt.s_to_int(e)}W.decodeKey=Ho;function Yo(e){return e?"b|T":"b|F"}W.encodeBool=Yo;function Go(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}W.decodeBool=Go;function Xo(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}W.encodeStr=Xo;function Zo(e){return e[0]+e[1]==="s|"?e.substr(2):e}W.decodeStr=Zo});var Bn=J(bt=>{"use strict";Object.defineProperty(bt,"__esModule",{value:!0});bt.config={sort_key:!1}});var It=J(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});var ei=Bn(),ti=Ct(),Pt=vt(),ni=Et();function ri(e){return e.store.toArray()}ce.memToValues=ri;function Vn(){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=Vn;function $n(){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=$n;function oi(){return{store:Vn(),cache:$n(),keyCount:0}}ce.makeInMemoryMemory=oi;function le(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=ni.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function ii(e,t){ei.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=ii(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,Pt.encodeBool(t));case"number":return le(e,Pt.encodeNum(t));case"string":return le(e,Pt.encodeStr(t))}return ti.throwUnknownDataType(t)}ce.addValue=Le});var Rt=J(Oe=>{"use strict";Object.defineProperty(Oe,"__esModule",{value:!0});var ai=Ct(),tt=vt(),Nt=It();function si(e){let t=Nt.makeInMemoryMemory(),r=Nt.addValue(t,e,void 0);return[Nt.memToValues(t),r]}Oe.compress=si;function li(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 ci(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=tt.decodeKey(t),n=e[r];if(n===null)return n;switch(typeof n){case"undefined":return n;case"number":return n;case"string":switch(n[0]+n[1]){case"b|":return tt.decodeBool(n);case"o|":return li(e,n);case"n|":return tt.decodeNum(n);case"a|":return ci(e,n);default:return tt.decodeStr(n)}}return ai.throwUnknownDataType(n)}Oe.decode=ke;function pi(e){let[t,r]=e;return ke(t,r)}Oe.decompress=pi});var Un=J(nt=>{"use strict";Object.defineProperty(nt,"__esModule",{value:!0});function ui(e){for(let t in e)e[t]===void 0&&delete e[t]}nt.trimUndefined=ui;function fi(e){zn(e,new Set)}nt.trimUndefinedRecursively=fi;function zn(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)&&zn(n,t)}}});var Qn=J(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});var Mn=Rt();ee.compress=Mn.compress;ee.decompress=Mn.decompress;var mi=Rt();ee.decode=mi.decode;var di=It();ee.addValue=di.addValue;var Kn=Un();ee.trimUndefined=Kn.trimUndefined;ee.trimUndefinedRecursively=Kn.trimUndefinedRecursively});async function kt(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 Ot(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 te(e){let t=[],r=await kt(e,e.getRootDir());if(r){let n=jt(r);t.push(...n)}return t}function jt(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of xr)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var xr=["@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 hr(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 hr(e,t){let r=await e.readFile(t);return typeof r=="string"?Bt(r):null}function Bt(e){let t={},r=e.replace(/\r\n?/gm,`
2
- `),n;for(;(n=Cr.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 Cr=/(?:^|^)\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
+ var cr=Object.create;var Lt=Object.defineProperty;var pr=Object.getOwnPropertyDescriptor;var ur=Object.getOwnPropertyNames;var fr=Object.getPrototypeOf,mr=Object.prototype.hasOwnProperty;var J=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var dr=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ur(t))!mr.call(e,o)&&o!==r&&Lt(e,o,{get:()=>t[o],enumerable:!(n=pr(t,o))||n.enumerable});return e};var gr=(e,t,r)=>(r=e!=null?cr(fr(e)):{},dr(t||!e||!e.__esModule?Lt(r,"default",{value:e,enumerable:!0}):r,e));var St=J(Xe=>{"use strict";Object.defineProperty(Xe,"__esModule",{value:!0});function Ln(e){return Object.prototype.toString.call(e)}Xe.getType=Ln;function qo(e){throw new TypeError("unsupported data type: "+Ln(e))}Xe.throwUnknownDataType=qo});var Et=J(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,wt={};for(let e=0;e<we;e++){let t=Q[e];wt[t]=e}function yt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=wt[o];i*=r,t+=i,r*=we}return t}q.s_to_int=yt;function On(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(wt[i]);a*=r,t+=a,r*=n}return t}q.s_to_big_int=On;function Tt(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=Tt;function kn(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=kn;function et(e){return e.split("").reverse().join("")}function jn(e){if(e<0)return"-"+jn(-e);let[t,r]=e.toString().split(".");if(!r)return Tt(e);let n;r&&([r,n]=r.split("e")),t=Ze(t),r=et(r),r=Ze(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=et(n),n=Ze(n),o+=n}return o}q.num_to_s=jn;function Ze(e){let t=+e;return t.toString()===e?Tt(t):":"+kn(BigInt(e))}q.int_str_to_s=Ze;function Ct(e){return e[0]===":"?On(e.substring(1)).toString():yt(e).toString()}function _n(e){if(e[0]==="-")return-_n(e.substr(1));let[t,r,n]=e.split(".");if(!r)return yt(t);t=Ct(t),r=Ct(r),r=et(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=Ct(n),n=et(n),o+=i?-n:+n}return+o}q.s_to_num=_n});var vt=J(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});var Dt=Et();function Wo(e){return"n|"+Dt.num_to_s(e)}W.encodeNum=Wo;function Jo(e){return e=e.replace("n|",""),Dt.s_to_num(e)}W.decodeNum=Jo;function Ho(e){return typeof e=="number"?e:Dt.s_to_int(e)}W.decodeKey=Ho;function Yo(e){return e?"b|T":"b|F"}W.encodeBool=Yo;function Go(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}W.decodeBool=Go;function Xo(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}W.encodeStr=Xo;function Zo(e){return e[0]+e[1]==="s|"?e.substr(2):e}W.decodeStr=Zo});var Bn=J(bt=>{"use strict";Object.defineProperty(bt,"__esModule",{value:!0});bt.config={sort_key:!1}});var It=J(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});var ei=Bn(),ti=St(),Pt=vt(),ni=Et();function ri(e){return e.store.toArray()}ce.memToValues=ri;function Vn(){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=Vn;function $n(){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=$n;function oi(){return{store:Vn(),cache:$n(),keyCount:0}}ce.makeInMemoryMemory=oi;function le(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=ni.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function ii(e,t){ei.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=ii(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,Pt.encodeBool(t));case"number":return le(e,Pt.encodeNum(t));case"string":return le(e,Pt.encodeStr(t))}return ti.throwUnknownDataType(t)}ce.addValue=Le});var Rt=J(ke=>{"use strict";Object.defineProperty(ke,"__esModule",{value:!0});var ai=St(),tt=vt(),Nt=It();function si(e){let t=Nt.makeInMemoryMemory(),r=Nt.addValue(t,e,void 0);return[Nt.memToValues(t),r]}ke.compress=si;function li(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 ci(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=tt.decodeKey(t),n=e[r];if(n===null)return n;switch(typeof n){case"undefined":return n;case"number":return n;case"string":switch(n[0]+n[1]){case"b|":return tt.decodeBool(n);case"o|":return li(e,n);case"n|":return tt.decodeNum(n);case"a|":return ci(e,n);default:return tt.decodeStr(n)}}return ai.throwUnknownDataType(n)}ke.decode=Oe;function pi(e){let[t,r]=e;return Oe(t,r)}ke.decompress=pi});var Un=J(nt=>{"use strict";Object.defineProperty(nt,"__esModule",{value:!0});function ui(e){for(let t in e)e[t]===void 0&&delete e[t]}nt.trimUndefined=ui;function fi(e){zn(e,new Set)}nt.trimUndefinedRecursively=fi;function zn(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)&&zn(n,t)}}});var Qn=J(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});var Mn=Rt();ee.compress=Mn.compress;ee.decompress=Mn.decompress;var mi=Rt();ee.decode=mi.decode;var di=It();ee.addValue=di.addValue;var Kn=Un();ee.trimUndefined=Kn.trimUndefined;ee.trimUndefinedRecursively=Kn.trimUndefinedRecursively});async function Ot(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 kt(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 te(e){let t=[],r=await Ot(e,e.getRootDir());if(r){let n=jt(r);t.push(...n)}return t}function jt(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of xr)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var xr=["@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 hr(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 hr(e,t){let r=await e.readFile(t);return typeof r=="string"?Bt(r):null}function Bt(e){let t={},r=e.replace(/\r\n?/gm,`
2
+ `),n;for(;(n=Sr.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 Sr=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function de(e,t,r,n){let o="# https://www.builder.io/c/docs/using-your-api-key",i=await e.readFile(t);if(i)if(i.includes(r))if(i.includes(n))e.debug(`"${r}" with "${n}" already set in ${t}`);else return e.debug(`Replace "${r}" in ${t}`),i=i.replace(new RegExp(`${r}=.*`),`${r}=${n}`),await e.writeFile(t,i),"update";else return e.debug(`Append "${r}" to ${t}`),i+=`
4
4
 
5
5
  ${o}
6
6
  ${r}=${n}
@@ -8,7 +8,7 @@ ${r}=${n}
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
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 Vt(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 $t(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 zt(o==="index"?e.basename(e.dirname(t)):o)}function zt(e){return j(e).replace(/ /g,"")}function H(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 Y(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 _e(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=Sr(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 Sr(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 yr(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return wr(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 wr(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 yr(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 it(e,t,new WeakSet)}function it(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)?Tr(e,t,r):typeof t=="object"?Er(e,t,r):e.ts.factory.createIdentifier(t)}function Tr(e,t,r){let n=t.map(o=>it(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Er(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,it(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=Dr(e,t,i);a&&n.push(a)}return n.filter(Ar)}function Dr(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),g=at(m);g.knownType?i=g.builderType:br(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=Rr(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},l&&l.length>0&&s.type==="string"&&l.every(Ir)?s.enum=l.map(Nr):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}var vr=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function br(e){return typeof e!="string"?!1:!!vr.some(t=>e.includes(t))}function at(e){return typeof e=="string"&&(e=e.trim(),Pr.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var Pr=[{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 Ir(e){return/^['"].*['"]$/.test(e)}function Nr(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Rr=(e,t,r)=>{let n=new Set;Ut(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},Fr=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Ut=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Ut(e,t,o,n)});else if(r.isLiteral()){let o=Fr(e,t,r);n.add(o)}};function Ar(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!Lr.has(t.toLowerCase())}var Lr=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=kr(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 kr(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(Or(e,n));return r}function Or(e,t){let r=Pe(e,t),n=Ur(r);return n.isRegistered=!0,n}function G(e,t,r){let n=_r(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=jr(e,t,n),Mr(e,t)}function jr(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=Vr(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 _r(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Br)}}function Br(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 Vr(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=$r(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(u=>D(e,u)==="name"),s=i.properties.find(u=>D(e,u)==="name"),l=a?.initializer,m=s?.initializer,g=l&&e.ts.isStringLiteral(l)?l.text:"zz",f=m&&e.ts.isStringLiteral(m)?m.text:"zz";return g.toLowerCase().localeCompare(f.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function $r(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]=Mt(e,t[n],r);else{let o=Mt(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Mt(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=zr(e,n,r,i);return n=Kr(e,n.filter(i=>{let a=D(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function zr(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 Ur(e){let t=at(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),st(r)}function st(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 Mr(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=Kt.indexOf(i),l=Kt.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 Kt=["component","name","description"];function Kr(e,t){return[...t].sort((n,o)=>{let i=D(e,n)||"zz",a=D(e,o)||"zz",s=Qt.indexOf(i),l=Qt.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)})}var Qt=["name","type"];function qt(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 Ee(e,t){let r=e.extname(t),n=e.basename(t,r).split(/[\/\\]/),o=n[n.length-1];return zt(o==="index"?e.basename(e.dirname(t)):o)}function zt(e){return j(e).replace(/ /g,"")}function H(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 Y(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 _e(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=Cr(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 Cr(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 yr(e,t);case e.ts.SyntaxKind.ObjectLiteralExpression:return wr(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 wr(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 yr(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 it(e,t,new WeakSet)}function it(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)?Tr(e,t,r):typeof t=="object"?Er(e,t,r):e.ts.factory.createIdentifier(t)}function Tr(e,t,r){let n=t.map(o=>it(e,o,r));return e.ts.factory.createArrayLiteralExpression(n,!0)}function Er(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,it(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=Dr(e,t,i);a&&n.push(a)}return n.filter(Ar)}function Dr(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),g=at(m);g.knownType?i=g.builderType:br(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=Rr(e,t,t.getTypeFromTypeNode(n.type));s.meta=s.meta||{},l&&l.length>0&&s.type==="string"&&l.every(Ir)?s.enum=l.map(Nr):s.meta.ts=a}return n.questionToken||(s.required=!0),s}return null}var vr=["ClassicComponent","FunctionComponent","IntrinsicElements","JSX","ReactNode","ReactElement","ReactPortal"];function br(e){return typeof e!="string"?!1:!!vr.some(t=>e.includes(t))}function at(e){return typeof e=="string"&&(e=e.trim(),Pr.some(t=>t.value===e))?{builderType:e,knownType:!0}:{builderType:"string",knownType:!1}}var Pr=[{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 Ir(e){return/^['"].*['"]$/.test(e)}function Nr(e){return(e.startsWith('"')||e.startsWith("'"))&&(e.endsWith('"')||e.endsWith("'"))?e.slice(1,-1):e}var Rr=(e,t,r)=>{let n=new Set;Ut(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},Fr=(e,t,r)=>{let n=e.ts.TypeFormatFlags.InElementType|e.ts.TypeFormatFlags.NoTruncation;return t.typeToString(r,void 0,n)},Ut=(e,t,r,n)=>{if(r.isUnion())r.types.forEach(o=>{Ut(e,t,o,n)});else if(r.isLiteral()){let o=Fr(e,t,r);n.add(o)}};function Ar(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!Lr.has(t.toLowerCase())}var Lr=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=Or(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 Or(e,t){let r=[];for(let n of t.elements)e.ts.isObjectLiteralExpression(n)&&r.push(kr(e,n));return r}function kr(e,t){let r=Pe(e,t),n=Ur(r);return n.isRegistered=!0,n}function G(e,t,r){let n=_r(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=jr(e,t,n),Mr(e,t)}function jr(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=Vr(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 _r(e){return{name:e.name,description:e.description,image:e.image,inputs:(e.inputs||[]).filter(r=>r.isRegistered).map(Br)}}function Br(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 Vr(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=$r(e,n,o);return n.sort((o,i)=>{let a=o.properties.find(u=>D(e,u)==="name"),s=i.properties.find(u=>D(e,u)==="name"),l=a?.initializer,m=s?.initializer,g=l&&e.ts.isStringLiteral(l)?l.text:"zz",f=m&&e.ts.isStringLiteral(m)?m.text:"zz";return g.toLowerCase().localeCompare(f.toLowerCase())}),e.ts.factory.updateArrayLiteralExpression(t,n)}function $r(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]=Mt(e,t[n],r);else{let o=Mt(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("name",e.ts.factory.createStringLiteral(r.name))],!0),r);t.push(o)}return t}function Mt(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=zr(e,n,r,i);return n=Kr(e,n.filter(i=>{let a=D(e,i);return o.includes(a)})),e.ts.factory.updateObjectLiteralExpression(t,n)}function zr(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 Ur(e){let t=at(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),st(r)}function st(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 Mr(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=Kt.indexOf(i),l=Kt.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 Kt=["component","name","description"];function Kr(e,t){return[...t].sort((n,o)=>{let i=D(e,n)||"zz",a=D(e,o)||"zz",s=Qt.indexOf(i),l=Qt.indexOf(a);return s>-1?l>-1&&s>l?1:-1:l>-1?s>-1&&l<s?-1:1:i.localeCompare(a)})}var Qt=["name","type"];function qt(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=$t(e,r);return lt(e,n,t)}function lt(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]=G(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 Ot(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=Jt.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new Ve(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 Qr(e,i,t)}catch(a){if(a instanceof Ve){await qr(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Qr(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=Wt.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,Wt.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 $e(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 Ve=class{constructor(t){this.libName=t}};async function qr(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;Be.has(t)||Be.set(t,fetch(r).then(n=>n.text()).then(n=>{Jt.set(t,n)})),await Be.get(t),Be.delete(t)}var Jt=new Map,Be=new Map,Ne=new Map,Wt=new Map;function v(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Wr(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=Jr(e,t,r.defaultImport,r.importPath,n)),t}function Wr(e,t,r,n,o,i){return i==="cjs"?Yt(e,t,null,r,n):Ht(e,t,null,r,n,o)}function Jr(e,t,r,n,o){return o==="cjs"?Yt(e,t,r,null,n):Ht(e,t,r,null,n,!1)}function Ht(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 c=[],d=h.importClause?.namedBindings;if(d&&e.ts.isNamedImports(d)&&d.elements&&c.push(...d.elements),typeof n=="string"){if(c.some(C=>C.name.text===n))return t;c.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),c.sort((C,S)=>C.name.text.localeCompare(S.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(c)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let g,f;typeof r=="string"&&(g=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(f=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let u=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,g,f),e.ts.factory.createStringLiteral(o));return a.splice(s,0,u),e.ts.factory.updateSourceFile(t,a)}function Yt(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 g=[...l.declarationList.declarations],f=g[m],u=f.initializer;if(!u||!e.ts.isCallExpression(u))continue;let p=u.expression;if(!e.ts.isIdentifier(p)||p.text!=="require"||u.arguments.length!==1)continue;let h=u.arguments[0];if(e.ts.isStringLiteral(h)&&(a=s,h.text===o)){if(e.ts.isIdentifier(f.name)&&typeof r=="string")return f.name.text===r?t:(g[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,g)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(f.name)&&typeof n=="string"){let c=[...f.name.elements];return c.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(c.push(e.ts.factory.createBindingElement(void 0,void 0,n)),c.sort((x,C)=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:x.name.text.localeCompare(C.name.text)),g[m]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createObjectBindingPattern(c),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,g)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function V(e,t,r="esm"){return r==="cjs"?Yr(e,t):Hr(e,t)}function Hr(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 Yr(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 Gr(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 ze(e,t,r,n){let o=Gr(e,r,n);if(o){let i=await ut(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 pt(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 X(e,t,r){let n=pt(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 Ue(e,t){if(t){if(Xr(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Ue(e,n)&&(r=!0)}),r)return!0}return!1}function Xr(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 ut(e,t){let r=e.extname(t).toLowerCase();if(r===""||!ct.includes(r)){for(let n of ct){let o=t+n;if(await e.exists(o))return o}for(let n of ct){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var ct=[".tsx",".jsx",".ts",".js"];function Me(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=Zr(e,i);return a?[{name:a}]:void 0}function Zr(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 Qe(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(g=>g.cmpInfo.id===a.id);m&&(a.inputs=Ie(e,o,m.node.fnNode))}}return a}))}async function qe(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await $e(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 Gt(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 eo(e,t,n)}return null}function eo(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 to(e,t,r,a);o.push(...s)})),o}async function to(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)||!_e(a.name.text))continue;let s=Ke(e,t,a.initializer);if(s){let l=s.name||a.name.text,m=n.isDefaultExport?"default":l,g=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:j(l),inputs:[],exportName:m,exportType:g,importName:l,filePath:r,relFilePath:i,dependencies:s.deps},node:s})}}return o}if(e.ts.isArrowFunction(n.node)){let a=Ke(e,t,n.node);if(a){let s=H(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&&!_e(a))return o;let s=Ke(e,t,n.node);if(s){let l=s.name||H(e,r),m=n.isDefaultExport||!s.name?"default":s.name,g=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:l,inputs:[],exportName:m,exportType:g,importName:s.name||Ee(e,r),filePath:r,relFilePath:i,dependencies:s.deps},node:s})}return o}return o}function Ke(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Ue(e,r.body)?{name:"",fnNode:r,deps:Me(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Ue(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Me(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:Ke(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:Me(e,t,o)}}return null}async function Xt(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&&no.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 no=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,[...ft(e,r),...ft(e,n),...ft(e,o),...i])}function Z(e){let t=e.split(`
21
+ `,r+=");";let n=$t(e,r);return lt(e,n,t)}function lt(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]=G(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 kt(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=Jt.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new Ve(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 Qr(e,i,t)}catch(a){if(a instanceof Ve){await qr(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function Qr(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=Wt.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,Wt.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 $e(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 Ve=class{constructor(t){this.libName=t}};async function qr(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;Be.has(t)||Be.set(t,fetch(r).then(n=>n.text()).then(n=>{Jt.set(t,n)})),await Be.get(t),Be.delete(t)}var Jt=new Map,Be=new Map,Ne=new Map,Wt=new Map;function v(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=Wr(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=Jr(e,t,r.defaultImport,r.importPath,n)),t}function Wr(e,t,r,n,o,i){return i==="cjs"?Yt(e,t,null,r,n):Ht(e,t,null,r,n,o)}function Jr(e,t,r,n,o){return o==="cjs"?Yt(e,t,r,null,n):Ht(e,t,r,null,n,!1)}function Ht(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 c=[],d=h.importClause?.namedBindings;if(d&&e.ts.isNamedImports(d)&&d.elements&&c.push(...d.elements),typeof n=="string"){if(c.some(S=>S.name.text===n))return t;c.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),c.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(c)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let g,f;typeof r=="string"&&(g=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(f=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let u=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,g,f),e.ts.factory.createStringLiteral(o));return a.splice(s,0,u),e.ts.factory.updateSourceFile(t,a)}function Yt(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 g=[...l.declarationList.declarations],f=g[m],u=f.initializer;if(!u||!e.ts.isCallExpression(u))continue;let p=u.expression;if(!e.ts.isIdentifier(p)||p.text!=="require"||u.arguments.length!==1)continue;let h=u.arguments[0];if(e.ts.isStringLiteral(h)&&(a=s,h.text===o)){if(e.ts.isIdentifier(f.name)&&typeof r=="string")return f.name.text===r?t:(g[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,g)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(f.name)&&typeof n=="string"){let c=[...f.name.elements];return c.some(x=>!e.ts.isBindingElement(x)||!e.ts.isIdentifier(x.name)?!1:x.name.text===n)?t:(c.push(e.ts.factory.createBindingElement(void 0,void 0,n)),c.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)),g[m]=e.ts.factory.updateVariableDeclaration(f,e.ts.factory.createObjectBindingPattern(c),f.exclamationToken,f.type,f.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,g)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function V(e,t,r="esm"){return r==="cjs"?Yr(e,t):Hr(e,t)}function Hr(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 Yr(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 Gr(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 ze(e,t,r,n){let o=Gr(e,r,n);if(o){let i=await ut(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 pt(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 X(e,t,r){let n=pt(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 Ue(e,t){if(t){if(Xr(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Ue(e,n)&&(r=!0)}),r)return!0}return!1}function Xr(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 ut(e,t){let r=e.extname(t).toLowerCase();if(r===""||!ct.includes(r)){for(let n of ct){let o=t+n;if(await e.exists(o))return o}for(let n of ct){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var ct=[".tsx",".jsx",".ts",".js"];function Me(e,t,r){if(!r||!t)return;let n=t.getSymbolAtLocation(r);if(!n)return;let o=n.valueDeclaration;if(!o)return;let i=o.getSourceFile().fileName,a=Zr(e,i);return a?[{name:a}]:void 0}function Zr(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 Qe(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(g=>g.cmpInfo.id===a.id);m&&(a.inputs=Ie(e,o,m.node.fnNode))}}return a}))}async function qe(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await $e(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 Gt(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 eo(e,t,n)}return null}function eo(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 to(e,t,r,a);o.push(...s)})),o}async function to(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)||!_e(a.name.text))continue;let s=Ke(e,t,a.initializer);if(s){let l=s.name||a.name.text,m=n.isDefaultExport?"default":l,g=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:j(l),inputs:[],exportName:m,exportType:g,importName:l,filePath:r,relFilePath:i,dependencies:s.deps},node:s})}}return o}if(e.ts.isArrowFunction(n.node)){let a=Ke(e,t,n.node);if(a){let s=H(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&&!_e(a))return o;let s=Ke(e,t,n.node);if(s){let l=s.name||H(e,r),m=n.isDefaultExport||!s.name?"default":s.name,g=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await _(e,r,m),displayFilePath:N(e,r),name:l,inputs:[],exportName:m,exportType:g,importName:s.name||Ee(e,r),filePath:r,relFilePath:i,dependencies:s.deps},node:s})}return o}return o}function Ke(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Ue(e,r.body)?{name:"",fnNode:r,deps:Me(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Ue(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:Me(e,t,r)}:null;if(e.ts.isCallExpression(r)){let n=r.expression;if(!e.ts.isPropertyAccessExpression(n))return null;let o=r.arguments;if(o.length===0)return null;let i=n.expression;if(!e.ts.isIdentifier(i)||i.text!=="React")return null;let a=n.name;return!e.ts.isIdentifier(a)||a.text!=="forwardRef"?null:Ke(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:Me(e,t,o)}}return null}async function Xt(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&&no.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 no=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,[...ft(e,r),...ft(e,n),...ft(e,o),...i])}function Z(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=`
@@ -29,7 +29,7 @@ ${r}=${n}
29
29
  `+o)),e=o+`
30
30
  `+e}return e.trim()+`
31
31
  `}function ft(e,t){return t.sort((r,n)=>{let o=Zt(e,r),i=Zt(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function Zt(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 tn(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
32
- ${e}`),e}function nn(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 We(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=en(e,r),i=en(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function en(e,t){let r=t.properties.find(n=>D(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function an(e){let t=await e.readFile(e.registryPath);return t?ro(e,t):{components:[],sourceFile:E(e,"")}}async function ro(e,t){let r=E(e,t);return oo(e,r)}async function oo(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 g=m[1];if(!e.ts.isObjectLiteralExpression(g))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 c=await rn(e,n,h,g,!0);c&&r.push(c)}else{let c=f.arguments[0];if(e.ts.isIdentifier(c)){let d=await on(e,t,n,c,g,!0);d&&r.push(d)}}continue}let p=await rn(e,n,f,g,!1);p&&r.push(p);continue}if(e.ts.isIdentifier(f)){let u=await on(e,t,n,f,g,!1);u&&r.push(u);continue}}return{sourceFile:t,components:Y(r)}}async function rn(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 g=l.arguments[0];if(!e.ts.isStringLiteral(g))return null;let f=g.text;i.filePath=await Je(e,f),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.name=H(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 g=m.expression;if(!e.ts.isAwaitExpression(g))return null;let f=g.expression;if(!e.ts.isCallExpression(f)||f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let p=f.arguments[0];if(!e.ts.isStringLiteral(p)||!e.ts.isIdentifier(l.name))return null;let h=p.text;i.filePath=await Je(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 on(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 Je(e,m.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.name=H(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(u=>u.name.text===n.text));if(!m)return null;let g=m.moduleSpecifier;if(!e.ts.isStringLiteral(g))return null;a.filePath=await Je(e,g.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 Je(e,t){return ut(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function sn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let m=0;m<i.length;m++){let g=i[m];if(e.ts.isImportDeclaration(g)){o=m;continue}if(!e.ts.isExpressionStatement(g))continue;let f=g.expression;if(!e.ts.isCallExpression(f))continue;let u=f.expression;if(!e.ts.isPropertyAccessExpression(u))continue;let p=u.expression;if(!e.ts.isIdentifier(p)||p.text!=="builder")continue;if(u.name.text=="init"){n=!0;break}else continue}if(n)return t;let a=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("process"),e.ts.factory.createIdentifier("env")),e.ts.factory.createIdentifier(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 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 g=l[m];if(e.ts.isImportSpecifier(g)){let f=g.name;if(f&&e.ts.isIdentifier(f)){let u=f.text;ln(e,t,u)||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)),g=e.ts.factory.updateImportDeclaration(i,void 0,m,i.moduleSpecifier,void 0);r[o]=g,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;ln(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function ln(e,t,r){let n=!1;function o(i){if(!e.ts.isImportDeclaration(i)){if(e.ts.isIdentifier(i)&&i.text===r){n=!0;return}e.ts.forEachChild(i,o)}}return e.ts.forEachChild(t,o),n}function Se(e,t,r,n,o,i,a){let s=null,l=null,m=null,g=-1;t=B(t),r=B(r);let f=t.find(p=>p.id===e),u=r.find(p=>p.id===e);if(n)u||(s={...B(f),inputs:B(f.inputs).map(p=>(p.isRegistered=!0,p))},g=r.length,r.push(s));else if(typeof u?.nodeIndex=="number"&&u.nodeIndex>-1){if(o)g=u.nodeIndex,l=B(u),r=r.filter(p=>p.id!==e);else if(i!=null)io(u,i),g=u.nodeIndex,m=u;else if(a!=null){let p=u.inputs.find(h=>h.name===a.name);p&&(a.registerInput===!1?p.isRegistered=!1:(ao(p,a),p.isRegistered=!0),m=u,g=u.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:m,nodeIndex:g,components:ae(t,r)}}function ae(e,t){let r=Y([...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(st),n.inputs.sort((o,i)=>o.name.toLowerCase().localeCompare(i.name.toLowerCase()))}),r}function io(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 ao(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 He(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".jsx"||l===".ts"||l===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}async function U(e,t,r,n,o,i,a,s){let l=await He(e),[m,g,f,u]=await Promise.all([Xt(e,l),an(e),mt(e),Te(e)]),p=m.map(S=>S.cmpInfo),h=g.components,c={components:ae(p,h),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(p),publicApiKey:u.envValue??void 0};if(s)return c.components=await Qe(e,c.components),c;let d=!1,x=g.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let S=C.map(w=>{let P=m.find(k=>k.cmpInfo.id===w);if(!P)throw new Error(`Component ${w} not found`);return P}),b=Array.from(new Set(S.map(w=>w.cmpInfo.filePath))),y=await $(e,b);for(let w of S){let P=c.components.find(O=>O.id===w.cmpInfo.id),k=await qe(e,w,y);oe(P,k);let R=p.findIndex(O=>O.id===w.cmpInfo.id);p[R].inputs=k;let T=Se(w.cmpInfo.id,p,h,r,n,o,i),F=[...x.statements];if(T.addCmpToRegistry?(F.push(qt(e,T.addCmpToRegistry)),d=!0):T.removeCmpFromRegistry?(F.splice(T.nodeIndex,1),d=!0):T.updateRegisteredCmp&&(F[T.nodeIndex]=lt(e,F[T.nodeIndex],T.updateRegisteredCmp),d=!0),d&&a){if(x=e.ts.factory.updateSourceFile(x,F),x=v(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=sn(e,x,f),e.appDir){let O=T.addCmpToRegistry||T.updateRegisteredCmp;if(O){let pe=A(e,e.registryPath,O.filePath);O.exportType==="default"?x=v(e,x,{defaultImport:O.importName,importPath:pe}):O.exportType==="named"&&(x=v(e,x,{namedImports:[O.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"})),c.components=T.components,h=T.components.filter(O=>O.isRegistered)}}}if(d&&a){x=Ce(e,x),x=he(e,x),e.appDir&&(x=nn(e,x));let S=I(e,x);S=Z(S),e.appDir&&(S=tn(S)),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return c}async function cn(e){let t=[],r=await fo(e,t);return await go(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await lo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await po(e,e.pagesDir,t)),t}async function pn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await so(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await uo(e,e.pagesDir,t)),t}async function so(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,un({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function lo(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,un({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,co(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function co(e){let t=e.typescriptEnabled;return`
32
+ ${e}`),e}function nn(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 We(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=en(e,r),i=en(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function en(e,t){let r=t.properties.find(n=>D(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function an(e){let t=await e.readFile(e.registryPath);return t?ro(e,t):{components:[],sourceFile:E(e,"")}}async function ro(e,t){let r=E(e,t);return oo(e,r)}async function oo(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 g=m[1];if(!e.ts.isObjectLiteralExpression(g))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 c=await rn(e,n,h,g,!0);c&&r.push(c)}else{let c=f.arguments[0];if(e.ts.isIdentifier(c)){let d=await on(e,t,n,c,g,!0);d&&r.push(d)}}continue}let p=await rn(e,n,f,g,!1);p&&r.push(p);continue}if(e.ts.isIdentifier(f)){let u=await on(e,t,n,f,g,!1);u&&r.push(u);continue}}return{sourceFile:t,components:Y(r)}}async function rn(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 g=l.arguments[0];if(!e.ts.isStringLiteral(g))return null;let f=g.text;i.filePath=await Je(e,f),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.name=H(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 g=m.expression;if(!e.ts.isAwaitExpression(g))return null;let f=g.expression;if(!e.ts.isCallExpression(f)||f.expression.kind!==e.ts.SyntaxKind.ImportKeyword||f.arguments.length!==1)return null;let p=f.arguments[0];if(!e.ts.isStringLiteral(p)||!e.ts.isIdentifier(l.name))return null;let h=p.text;i.filePath=await Je(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 on(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 Je(e,m.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.name=H(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(u=>u.name.text===n.text));if(!m)return null;let g=m.moduleSpecifier;if(!e.ts.isStringLiteral(g))return null;a.filePath=await Je(e,g.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 Je(e,t){return ut(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function sn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let m=0;m<i.length;m++){let g=i[m];if(e.ts.isImportDeclaration(g)){o=m;continue}if(!e.ts.isExpressionStatement(g))continue;let f=g.expression;if(!e.ts.isCallExpression(f))continue;let u=f.expression;if(!e.ts.isPropertyAccessExpression(u))continue;let p=u.expression;if(!e.ts.isIdentifier(p)||p.text!=="builder")continue;if(u.name.text=="init"){n=!0;break}else continue}if(n)return t;let a=e.ts.factory.createPropertyAccessExpression(e.ts.factory.createPropertyAccessExpression(e.ts.factory.createIdentifier("process"),e.ts.factory.createIdentifier("env")),e.ts.factory.createIdentifier(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 g=l[m];if(e.ts.isImportSpecifier(g)){let f=g.name;if(f&&e.ts.isIdentifier(f)){let u=f.text;ln(e,t,u)||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)),g=e.ts.factory.updateImportDeclaration(i,void 0,m,i.moduleSpecifier,void 0);r[o]=g,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;ln(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function ln(e,t,r){let n=!1;function o(i){if(!e.ts.isImportDeclaration(i)){if(e.ts.isIdentifier(i)&&i.text===r){n=!0;return}e.ts.forEachChild(i,o)}}return e.ts.forEachChild(t,o),n}function Ce(e,t,r,n,o,i,a){let s=null,l=null,m=null,g=-1;t=B(t),r=B(r);let f=t.find(p=>p.id===e),u=r.find(p=>p.id===e);if(n)u||(s={...B(f),inputs:B(f.inputs).map(p=>(p.isRegistered=!0,p))},g=r.length,r.push(s));else if(typeof u?.nodeIndex=="number"&&u.nodeIndex>-1){if(o)g=u.nodeIndex,l=B(u),r=r.filter(p=>p.id!==e);else if(i!=null)io(u,i),g=u.nodeIndex,m=u;else if(a!=null){let p=u.inputs.find(h=>h.name===a.name);p&&(a.registerInput===!1?p.isRegistered=!1:(ao(p,a),p.isRegistered=!0),m=u,g=u.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:m,nodeIndex:g,components:ae(t,r)}}function ae(e,t){let r=Y([...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(st),n.inputs.sort((o,i)=>o.name.toLowerCase().localeCompare(i.name.toLowerCase()))}),r}function io(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 ao(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 He(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),l=e.extname(a).toLowerCase();if(l===".tsx"||l===".jsx"||l===".ts"||l===".js"){t.add(s);return}(await e.stat(s)).isDirectory()&&await r(s)}))};return await r(e.getRootDir()),await $(e,[...t])}async function U(e,t,r,n,o,i,a,s){let l=await He(e),[m,g,f,u]=await Promise.all([Xt(e,l),an(e),mt(e),Te(e)]),p=m.map(C=>C.cmpInfo),h=g.components,c={components:ae(p,h),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(p),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return c.components=await Qe(e,c.components),c;let d=!1,x=g.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=c.components.find(k=>k.id===w.cmpInfo.id),O=await qe(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(qt(e,T.addCmpToRegistry)),d=!0):T.removeCmpFromRegistry?(F.splice(T.nodeIndex,1),d=!0):T.updateRegisteredCmp&&(F[T.nodeIndex]=lt(e,F[T.nodeIndex],T.updateRegisteredCmp),d=!0),d&&a){if(x=e.ts.factory.updateSourceFile(x,F),x=v(e,x,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),x=sn(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"})),c.components=T.components,h=T.components.filter(k=>k.isRegistered)}}}if(d&&a){x=Se(e,x),x=he(e,x),e.appDir&&(x=nn(e,x));let C=I(e,x);C=Z(C),e.appDir&&(C=tn(C)),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return c}async function cn(e){let t=[],r=await fo(e,t);return await go(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await lo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await po(e,e.pagesDir,t)),t}async function pn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await so(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await uo(e,e.pagesDir,t)),t}async function so(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,un({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function lo(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,un({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,co(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function co(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";
@@ -232,13 +232,13 @@ export default Counter;
232
232
  font-size: 42px;
233
233
  text-align: center;
234
234
  }
235
- `.trimStart();return{component:r,styles:n}}async function go(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 mn(e){let t=await xo(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>cn(t),ensureFigmaImportPage:()=>pn(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=>Vt(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 xo(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await ho(e),o=await mt(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 mt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function ho(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"],gn)}async function dn(e,t){Co(t);let r=await Re(e),n=await de(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function Co(e){typeof process<"u"&&(process.env[gn]=e)}var gn="PUBLIC_BUILDER_API_KEY";function xn(e,t,r){if(r.length===0)return e;let n=e.split(`
235
+ `.trimStart();return{component:r,styles:n}}async function go(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 mn(e){let t=await xo(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>cn(t),ensureFigmaImportPage:()=>pn(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=>Vt(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 xo(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await ho(e),o=await mt(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 mt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function ho(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"],gn)}async function dn(e,t){So(t);let r=await Re(e),n=await de(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function So(e){typeof process<"u"&&(process.env[gn]=e)}var gn="PUBLIC_BUILDER_API_KEY";function xn(e,t,r){if(r.length===0)return e;let n=e.split(`
236
236
  `),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(`
237
- `)}function Ye(e,t,r){return pt(e,t,r.variableName)?t:So(e,t,r)}function So(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 Cn(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(".")||To.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await Ge(e,o,s,i);r.push(...l)})),r}async function Sn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return wo(e,t,n)}return null}function wo(e,t,r){let n=E(e,r);return Ge(e,null,t,n)}async function Ge(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 yo(e,t,r,a);s&&o.push(s)})),o}async function yo(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=hn(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=hn(e,n.node);if(i)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:N(e,r),name:H(e,r),inputs:[],exportName:"default",exportType:"default",importName:Ee(e,r),filePath:r,relFilePath:o},node:i}}return null}function hn(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 To=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function wn(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 $e(e,t.cmpInfo.filePath,null);if(!(await Ge(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 yn(e){return dt(e)}async function dt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Eo),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var Eo=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
237
+ `)}function Ye(e,t,r){return pt(e,t,r.variableName)?t:Co(e,t,r)}function Co(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 Sn(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(".")||To.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await Ge(e,o,s,i);r.push(...l)})),r}async function Cn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return wo(e,t,n)}return null}function wo(e,t,r){let n=E(e,r);return Ge(e,null,t,n)}async function Ge(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 yo(e,t,r,a);s&&o.push(s)})),o}async function yo(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=hn(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=hn(e,n.node);if(i)return{cmpInfo:{id:await _(e,r,"default"),displayFilePath:N(e,r),name:H(e,r),inputs:[],exportName:"default",exportType:"default",importName:Ee(e,r),filePath:r,relFilePath:o},node:i}}return null}function hn(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 To=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function wn(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 $e(e,t.cmpInfo.filePath,null);if(!(await Ge(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 yn(e){return dt(e)}async function dt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Eo),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var Eo=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
238
238
 
239
239
  export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
240
240
  ];
241
- `;async function Tn(e){await dt(e);let t=await e.readFile(e.registryPath);return t?Do(e,t):{components:[],sourceFile:E(e,"")}}async function Do(e,t){let r=E(e,t);return vo(e,r)}async function vo(e,t){let r=[],n=X(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await gt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Y(r)}}async function gt(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 ze(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 Sn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let m=l.find(g=>g.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 En(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 En(e),[m,g,f]=await Promise.all([Cn(e,l),Tn(e),Re(e)]),u=m.map(c=>c.cmpInfo),p=g.components,h={components:ae(u,p),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(u),publicApiKey:f.envValue??void 0};if(s)return h;if(t!=null){let c=m.find(T=>T.cmpInfo.id===t);if(!c)throw new Error(`Component ${t} not found`);let d=g.sourceFile,x=h.components.find(T=>T.id===t),C=await wn(e,c);oe(x,C),t=Array.isArray(t)?t[0]:t;let S=Se(t,u,p,r,n,o,i),{elements:b,elmIndex:y,statementIndex:w,statement:P,variableDeclaration:k}=await Po(e,d,c),R=!1;if(S.addCmpToRegistry?(b.push(bo(e,S.addCmpToRegistry)),R=!0):S.removeCmpFromRegistry?(b.splice(y,1),R=!0):S.updateRegisteredCmp&&(b[y]=G(e,b[y],S.updateRegisteredCmp),R=!0),R&&a){let T=[...d.statements];T[w]=e.ts.factory.updateVariableStatement(P,P.modifiers,e.ts.factory.updateVariableDeclarationList(P.declarationList,[e.ts.factory.updateVariableDeclaration(k,k.name,k.exclamationToken,k.type,e.ts.factory.createArrayLiteralExpression(We(e,b)))])),d=e.ts.factory.updateSourceFile(d,T),x.exportType==="named"?d=v(e,d,{namedImports:[x.importName],importPath:A(e,e.registryPath,x.filePath)}):d=v(e,d,{defaultImport:x.importName,importPath:A(e,e.registryPath,x.filePath)}),d=v(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),d=Ye(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),d=Ce(e,d),d=he(e,d);let F=I(e,d);F=Z(F),F=xn(F,Io,"CUSTOM_COMPONENTS"),F=await e.formatCode(e.registryPath,F),await e.writeFile(e.registryPath,F)}h.components=S.components}return h}function bo(e,t){return G(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Po(e,t,r){let n=X(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 gt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Io=["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 Dn(e){let t=await No(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>yn(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=>dn(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 No(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 vn(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 bn(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"||Ro.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 Ro=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Pn(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=X(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await xt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Y(r)}}async function xt(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 ze(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 Gt(e,l.filePath);if(m&&m.length>0)if(m.length===1)n.exportName=m[0].cmpInfo.exportName;else{let g=m.find(f=>f.cmpInfo.exportName===a);g&&(n.exportName=g.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 He(e),[m,g,f]=await Promise.all([bn(e,l),Pn(e),Fe(e)]),u=m.map(C=>C.cmpInfo),p=g.components,h={components:ae(u,p),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(u),publicApiKey:f.envValue??void 0};if(s)return h.components=await Qe(e,h.components),h;let c=!1,d=g.sourceFile,x=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(x.length>0){let C=x.map(y=>{let w=m.find(P=>P.cmpInfo.id===y);if(!w)throw new Error(`Component ${y} not found`);return w}),S=Array.from(new Set(C.map(y=>y.cmpInfo.filePath))),b=await $(e,S);for(let y of C){let w=h.components.find(K=>K.id===y.cmpInfo.id),P=await qe(e,y,b);oe(w,P);let k=u.findIndex(K=>K.id===y.cmpInfo.id);u[k].inputs=P;let R=Se(y.cmpInfo.id,u,p,r,n,o,i),{elements:T,elmIndex:F,statementIndex:O,statement:pe,variableDeclaration:je}=await ko(e,d,y);if(R.addCmpToRegistry)T.push(Lo(e,R.addCmpToRegistry)),c=!0;else if(R.removeCmpFromRegistry)T.splice(F,1),c=!0;else if(R.updateRegisteredCmp){let K=G(e,T[F],R.updateRegisteredCmp);T[F]=e.ts.factory.updateObjectLiteralExpression(K,[In(e,R.updateRegisteredCmp),...K.properties.slice(1)]),c=!0}if(c&&a){let K=[...d.statements];K[O]=e.ts.factory.updateVariableStatement(pe,pe.modifiers,e.ts.factory.updateVariableDeclarationList(pe.declarationList,[e.ts.factory.updateVariableDeclaration(je,je.name,je.exclamationToken,je.type,e.ts.factory.createArrayLiteralExpression(We(e,T)))])),d=e.ts.factory.updateSourceFile(d,K),w.exportType==="named"?d=v(e,d,{namedImports:[w.importName],importPath:A(e,e.registryPath,w.filePath)}):d=v(e,d,{defaultImport:w.importName,importPath:A(e,e.registryPath,w.filePath)}),d=v(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),w.acceptsChildren&&(d=v(e,d,{namedImports:["withChildren"],importPath:"@builder.io/react"})),d=Ye(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=R.components,p=R.components.filter(lr=>lr.isRegistered)}}}if(c&&a){d=Ce(e,d),d=he(e,d);let C=I(e,d);C=Z(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function In(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 Lo(e,t){return G(e,e.ts.factory.createObjectLiteralExpression([In(e,t)],!0),t)}async function ko(e,t,r){let n=X(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 xt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Nn(e){let t=[],r=await _o(e,t);return t.push(...await ht(e)),await Vo(e,r),await jo(e,t),t}async function Rn(e){let t=[];return await Oo(e,t),t}async function Oo(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,Fn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function jo(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,Fn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function Fn({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+="!"),`
241
+ `;async function Tn(e){await dt(e);let t=await e.readFile(e.registryPath);return t?Do(e,t):{components:[],sourceFile:E(e,"")}}async function Do(e,t){let r=E(e,t);return vo(e,r)}async function vo(e,t){let r=[],n=X(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await gt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Y(r)}}async function gt(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 ze(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 Cn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let m=l.find(g=>g.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 En(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 En(e),[m,g,f]=await Promise.all([Sn(e,l),Tn(e),Re(e)]),u=m.map(c=>c.cmpInfo),p=g.components,h={components:ae(u,p),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(u),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let c=m.find(T=>T.cmpInfo.id===t);if(!c)throw new Error(`Component ${t} not found`);let d=g.sourceFile,x=h.components.find(T=>T.id===t),S=await wn(e,c);oe(x,S),t=Array.isArray(t)?t[0]:t;let C=Ce(t,u,p,r,n,o,i),{elements:b,elmIndex:y,statementIndex:w,statement:P,variableDeclaration:O}=await Po(e,d,c),R=!1;if(C.addCmpToRegistry?(b.push(bo(e,C.addCmpToRegistry)),R=!0):C.removeCmpFromRegistry?(b.splice(y,1),R=!0):C.updateRegisteredCmp&&(b[y]=G(e,b[y],C.updateRegisteredCmp),R=!0),R&&a){let T=[...d.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(We(e,b)))])),d=e.ts.factory.updateSourceFile(d,T),x.exportType==="named"?d=v(e,d,{namedImports:[x.importName],importPath:A(e,e.registryPath,x.filePath)}):d=v(e,d,{defaultImport:x.importName,importPath:A(e,e.registryPath,x.filePath)}),d=v(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),d=Ye(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),d=Se(e,d),d=he(e,d);let F=I(e,d);F=Z(F),F=xn(F,Io,"CUSTOM_COMPONENTS"),F=await e.formatCode(e.registryPath,F),await e.writeFile(e.registryPath,F)}h.components=C.components}return h}function bo(e,t){return G(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Po(e,t,r){let n=X(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 gt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Io=["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 Dn(e){let t=await No(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>yn(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=>dn(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 No(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 vn(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 bn(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"||Ro.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 Ro=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Pn(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=X(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await xt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Y(r)}}async function xt(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 ze(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 Gt(e,l.filePath);if(m&&m.length>0)if(m.length===1)n.exportName=m[0].cmpInfo.exportName;else{let g=m.find(f=>f.cmpInfo.exportName===a);g&&(n.exportName=g.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 He(e),[m,g,f]=await Promise.all([bn(e,l),Pn(e),Fe(e)]),u=m.map(S=>S.cmpInfo),p=g.components,h={components:ae(u,p),registryPath:e.registryPath,registryDisplayPath:N(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:xe(u),publicApiKey:f.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await Qe(e,h.components),h;let c=!1,d=g.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 qe(e,y,b);oe(w,P);let O=u.findIndex(K=>K.id===y.cmpInfo.id);u[O].inputs=P;let R=Ce(y.cmpInfo.id,u,p,r,n,o,i),{elements:T,elmIndex:F,statementIndex:k,statement:pe,variableDeclaration:je}=await Oo(e,d,y);if(R.addCmpToRegistry)T.push(Lo(e,R.addCmpToRegistry)),c=!0;else if(R.removeCmpFromRegistry)T.splice(F,1),c=!0;else if(R.updateRegisteredCmp){let K=G(e,T[F],R.updateRegisteredCmp);T[F]=e.ts.factory.updateObjectLiteralExpression(K,[In(e,R.updateRegisteredCmp),...K.properties.slice(1)]),c=!0}if(c&&a){let K=[...d.statements];K[k]=e.ts.factory.updateVariableStatement(pe,pe.modifiers,e.ts.factory.updateVariableDeclarationList(pe.declarationList,[e.ts.factory.updateVariableDeclaration(je,je.name,je.exclamationToken,je.type,e.ts.factory.createArrayLiteralExpression(We(e,T)))])),d=e.ts.factory.updateSourceFile(d,K),w.exportType==="named"?d=v(e,d,{namedImports:[w.importName],importPath:A(e,e.registryPath,w.filePath)}):d=v(e,d,{defaultImport:w.importName,importPath:A(e,e.registryPath,w.filePath)}),d=v(e,d,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),w.acceptsChildren&&(d=v(e,d,{namedImports:["withChildren"],importPath:"@builder.io/react"})),d=Ye(e,d,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=R.components,p=R.components.filter(lr=>lr.isRegistered)}}}if(c&&a){d=Se(e,d),d=he(e,d);let S=I(e,d);S=Z(S),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return h}function In(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 Lo(e,t){return G(e,e.ts.factory.createObjectLiteralExpression([In(e,t)],!0),t)}async function Oo(e,t,r){let n=X(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 xt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function Nn(e){let t=[],r=await _o(e,t);return t.push(...await ht(e)),await Vo(e,r),await jo(e,t),t}async function Rn(e){let t=[];return await ko(e,t),t}async function ko(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,Fn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function jo(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,Fn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function Fn({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+="!"),`
242
242
  import { BuilderComponent, builder } from "@builder.io/react";
243
243
  import { useLoaderData } from "@remix-run/react";
244
244
  import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
@@ -367,7 +367,7 @@ export default Counter;
367
367
  export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
368
368
  ];`:`export const CUSTOM_COMPONENTS = [
369
369
  ];
370
- `}async function An(e){let t=await zo(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:()=>Nn(t),ensureFigmaImportPage:()=>Rn(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=>vn(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 zo(e){let t=await Ko(e),r=await Qo(e),n=e.dirname(r),o=e.join(n,"components"),i=await Uo(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 Mo(e,r)}}function Uo(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Mo(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Ko(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 Qo(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 rt=gr(Qn(),1);async function qn(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,rt.compress)(n);return btoa(JSON.stringify(o))}async function Wn(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,rt.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 g=await t.setRegisteredComponentInfo({cmpId:m.id,name:s.name,image:s.image,description:s.description});a=B(g)}return a}var gi={"@builder.io/qwik-city":Dn,next:mn,"@remix-run/react":An};async function xi(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await te(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getRootDir()}`);for(let t of e.frameworks){let r=gi[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>qn(e,n),importRegistry:i=>Wn(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Jn(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,u){let p="",h=0,c=-1,d=0,x;for(let C=0;C<=f.length;++C){if(C<f.length)x=f.charCodeAt(C);else{if(x===47)break;x=47}if(x===47){if(!(c===C-1||d===1))if(c!==C-1&&d===2){if(p.length<2||h!==2||p.charCodeAt(p.length-1)!==46||p.charCodeAt(p.length-2)!==46){if(p.length>2){let S=p.lastIndexOf("/");if(S!==p.length-1){S===-1?(p="",h=0):(p=p.slice(0,S),h=p.length-1-p.lastIndexOf("/")),c=C,d=0;continue}}else if(p.length===2||p.length===1){p="",h=0,c=C,d=0;continue}}u&&(p.length>0?p+="/..":p="..",h=2)}else p.length>0?p+="/"+f.slice(c+1,C):p=f.slice(c+1,C),h=C-c-1;c=C,d=0}else x===46&&d!==-1?++d:d=-1}return p}let n=function(...u){let p="",h=!1;for(let c=u.length-1;c>=-1&&!h;c--){let d;c>=0?d=u[c]:e.cwd?d=e.cwd():d="/",t(d),d.length!==0&&(p=d+"/"+p,h=d.charCodeAt(0)===47)}return p=r(p,!h),h?p.length>0?"/"+p:"/":p.length>0?p:"."},o=function(u){if(t(u),u.length===0)return".";let p=u.charCodeAt(0)===47,h=u.charCodeAt(u.length-1)===47;return u=r(u,!p),u.length===0&&!p&&(u="."),u.length>0&&h&&(u+="/"),p?"/"+u:u};return{relative:function(u,p){if(t(u),t(p),u===p||(u=n(u),p=n(p),u===p))return"";let h=1;for(;h<u.length&&u.charCodeAt(h)===47;++h);let c=u.length,d=c-h,x=1;for(;x<p.length&&p.charCodeAt(x)===47;++x);let S=p.length-x,b=d<S?d:S,y=-1,w=0;for(;w<=b;++w){if(w===b){if(S>b){if(p.charCodeAt(x+w)===47)return p.slice(x+w+1);if(w===0)return p.slice(x+w)}else d>b&&(u.charCodeAt(h+w)===47?y=w:w===0&&(y=0));break}let k=u.charCodeAt(h+w),R=p.charCodeAt(x+w);if(k!==R)break;k===47&&(y=w)}let P="";for(w=h+y+1;w<=c;++w)(w===c||u.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(...u){if(u.length===0)return".";let p;for(let h=0;h<u.length;++h){let c=u[h];t(c),c.length>0&&(p===void 0?p=c:p+="/"+c)}return p===void 0?".":o(p)},isAbsolute:function(u){return t(u),u.length>0&&u.charCodeAt(0)===47},basename:function(u,p){if(p!==void 0&&typeof p!="string")throw new TypeError('"ext" argument must be a string');t(u);let h=0,c=-1,d=!0,x;if(p!==void 0&&p.length>0&&p.length<=u.length){if(p.length===u.length&&p===u)return"";let C=p.length-1,S=-1;for(x=u.length-1;x>=0;--x){let b=u.charCodeAt(x);if(b===47){if(!d){h=x+1;break}}else S===-1&&(d=!1,S=x+1),C>=0&&(b===p.charCodeAt(C)?--C===-1&&(c=x):(C=-1,c=S))}return h===c?c=S:c===-1&&(c=u.length),u.slice(h,c)}else{for(x=u.length-1;x>=0;--x)if(u.charCodeAt(x)===47){if(!d){h=x+1;break}}else c===-1&&(d=!1,c=x+1);return c===-1?"":u.slice(h,c)}},normalize:o,dirname:function(u){if(t(u),u.length===0)return".";let p=u.charCodeAt(0),h=p===47,c=-1,d=!0;for(let x=u.length-1;x>=1;--x)if(p=u.charCodeAt(x),p===47){if(!d){c=x;break}}else d=!1;return c===-1?h?"/":".":h&&c===1?"//":u.slice(0,c)},extname:function(u){t(u);let p=-1,h=0,c=-1,d=!0,x=0;for(let C=u.length-1;C>=0;--C){let S=u.charCodeAt(C);if(S===47){if(!d){h=C+1;break}continue}c===-1&&(d=!1,c=C+1),S===46?p===-1?p=C:x!==1&&(x=1):p!==-1&&(x=-1)}return p===-1||c===-1||x===0||x===1&&p===c-1&&p===h+1?"":u.slice(p,c)}}}async function hi(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Jn({cwd:r,...e}),o=new Map,i=c=>n.normalize(n.resolve(r(),c)),a=c=>{for(let[d]of o)if((d+"/").startsWith(c))return!0;return c===t()},s=c=>(c=i(c),o.has(c)?!0:a(c)),l=c=>{c=i(c);let d=c===t()?c:c+"/",x=d.split("/").length-1,C=[];for(let[S]of o)if(S.split("/").slice(0,x).join("/")+"/"===d){let w=S.split("/")[x];w&&!C.includes(w)&&C.push(w)}return C.sort()},m=c=>{c=i(c);let d=o.get(c);return typeof d=="string"?d:null},g=c=>(c=i(c),{isFile:()=>o.has(c),isDirectory:()=>!o.has(c)&&a(c)}),f=async c=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(c),S=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(S)).map(b=>b.toString(16).padStart(2,"0")).join("")}let d=0;for(let x=0;x<c.length;x++){let C=c.charCodeAt(x);d=(d<<5)-d+C,d|=0}return Number(Math.abs(d)).toString(36)},u=new Set,p={getRootDir:t,cwd:r,exists:async c=>s(c),existsSync:s,readdir:async c=>l(c),readdirSync:l,readFile:async c=>m(c),readFileSync:m,stat:async c=>g(c),statSync:g,writeFile:async(c,d)=>{c=i(c),o.set(c,d);let x={path:c,basename:n.basename(c),dirname:n.dirname(c),extname:n.extname(c)};for(let C of u)await C(x)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",formatCode:async(c,d)=>d,on:(c,d)=>{c==="change"&&u.add(d)},off:(c,d)=>{c==="change"&&u.delete(d)},debug:(...c)=>{console.debug("[builder-dev-tools]",...c)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e},h=await te(p);return p.getFrameworks=()=>h,p}async function Hn(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Yn(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 g=s[0];if(!g.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=g.statement;if(!e.ts.isVariableStatement(f))throw new Error(`Expected an export assignment from ${t}`);let u=g.statement;if(e.ts.isVariableStatement(u)){let p=[...u.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 c=h.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let d="BuilderDevTools()",x=[...n.statements],C=x.indexOf(u);return x[C]=e.ts.factory.updateVariableStatement(u,u.modifiers,e.ts.factory.updateVariableDeclarationList(u.declarationList,[e.ts.factory.updateVariableDeclaration(h,h.name,h.exclamationToken,h.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d),void 0,[c]))])),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 g=l.statement;if(!e.ts.isExpressionStatement(g))throw new Error("Expected an expression statement for the default export");let f=g.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let u=Ft(e,n);n=u.sourceFile;let p=[...n.statements],h=p.indexOf(g);return p[h]=e.ts.factory.updateExpressionStatement(g,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.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 g=[...m.declarationList.declarations];if(g.length!==1)throw new Error("Expected a single variable declaration");let f=g[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let u=f.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let p=Ft(e,n);n=p.sourceFile;let h=[...n.statements],c=h.indexOf(m);return h[c]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[u]))])),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 g=l.node,f=l.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let u=f.expression;if(!e.ts.isBinaryExpression(u))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 c=[...h.statements],d=c.findIndex(y=>e.ts.isReturnStatement(y));if(d===-1)throw new Error("Expected a return statement on the next config function");let x=c[d],C=Ft(e,n);n=C.sourceFile,c[d]=e.ts.factory.updateReturnStatement(x,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[x.expression]));let S=[...n.statements],b=S.indexOf(f);return S[b]=e.ts.factory.updateExpressionStatement(f,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.updateArrowFunction(g,g.modifiers,g.typeParameters,g.parameters,g.type,g.equalsGreaterThanToken,e.ts.factory.updateBlock(h,c)))),n=e.ts.factory.updateSourceFile(n,S),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function Yn(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 Ft(e,t){let r=Yn(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 Zn(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(er(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 g=s[0];if(!g.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=g.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let u="builderDevTools()",p=Ci(e,f.expression);if(!p)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u),void 0,[p]),c=[...n.statements],d=c.indexOf(f);return c[d]=e.ts.factory.updateExportAssignment(f,f.modifiers,h),n=e.ts.factory.updateSourceFile(n,c),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 g=l.statement;if(!e.ts.isExpressionStatement(g))throw new Error("Expected an expression statement for the default export");let f=g.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let u=Gn(e,n);n=u.sourceFile;let p=[...n.statements],h=p.indexOf(g);return p[h]=e.ts.factory.updateExpressionStatement(g,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.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 g=[...m.declarationList.declarations];if(g.length!==1)throw new Error("Expected a single variable declaration");let f=g[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let u=f.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let p=Gn(e,n);n=p.sourceFile;let h=[...n.statements],c=h.indexOf(m);return h[c]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[u]))])),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 er(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 Gn(e,t){let r=er(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 Ci(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=Xn(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=Xn(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Xn(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 nr(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 g=Si(e,m);if(!g)return s;l[0]=e.ts.factory.updateArrowFunction(m,m.modifiers,m.typeParameters,m.parameters,m.type,m.equalsGreaterThanToken,g);let f=[...n.statements],u=f.indexOf(a);return f[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,l)),n=e.ts.factory.updateSourceFile(n,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 g=At(e,m);if(!g)return s;let f=[...n.statements],u=f.indexOf(a);return f[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[g])),n=e.ts.factory.updateSourceFile(n,f),n=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=At(e,a.expression);if(!l)return s;let m=[...n.statements],g=m.indexOf(a);return m[g]=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 Si(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=At(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function At(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=tr(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=tr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function tr(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 rr(e,t,r){throw new Error("Webpack config updates not implemented")}var ir=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:Hn},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:Zn},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:nr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:rr}];async function ar(e){let t=e.resolve("/");for(let n of ir)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 te(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,or),{id:"next",filePath:n,content:or}}return null}async function wi(e){let t=await ar(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await ir.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=Z(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var or=`
370
+ `}async function An(e){let t=await zo(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:()=>Nn(t),ensureFigmaImportPage:()=>Rn(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=>vn(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 zo(e){let t=await Ko(e),r=await Qo(e),n=e.dirname(r),o=e.join(n,"components"),i=await Uo(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 Mo(e,r)}}function Uo(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Mo(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function Ko(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 Qo(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 rt=gr(Qn(),1);async function qn(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,rt.compress)(n);return btoa(JSON.stringify(o))}async function Wn(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,rt.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 g=await t.setRegisteredComponentInfo({cmpId:m.id,name:s.name,image:s.image,description:s.description});a=B(g)}return a}var gi={"@builder.io/qwik-city":Dn,next:mn,"@remix-run/react":An};async function xi(e){if(!e.ts)throw new Error("createDevTools() requires a TypeScript instance passed to the 'ts' option");if((!e.frameworks||e.frameworks.length===0)&&(e.frameworks=await te(e)),e.frameworks.length===0)throw new Error(`Supported Devtools framework for not found within ${e.getRootDir()}`);for(let t of e.frameworks){let r=gi[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>qn(e,n),importRegistry:i=>Wn(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function Jn(e){function t(f){if(typeof f!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(f))}function r(f,u){let p="",h=0,c=-1,d=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(!(c===S-1||d===1))if(c!==S-1&&d===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("/")),c=S,d=0;continue}}else if(p.length===2||p.length===1){p="",h=0,c=S,d=0;continue}}u&&(p.length>0?p+="/..":p="..",h=2)}else p.length>0?p+="/"+f.slice(c+1,S):p=f.slice(c+1,S),h=S-c-1;c=S,d=0}else x===46&&d!==-1?++d:d=-1}return p}let n=function(...u){let p="",h=!1;for(let c=u.length-1;c>=-1&&!h;c--){let d;c>=0?d=u[c]:e.cwd?d=e.cwd():d="/",t(d),d.length!==0&&(p=d+"/"+p,h=d.charCodeAt(0)===47)}return p=r(p,!h),h?p.length>0?"/"+p:"/":p.length>0?p:"."},o=function(u){if(t(u),u.length===0)return".";let p=u.charCodeAt(0)===47,h=u.charCodeAt(u.length-1)===47;return u=r(u,!p),u.length===0&&!p&&(u="."),u.length>0&&h&&(u+="/"),p?"/"+u:u};return{relative:function(u,p){if(t(u),t(p),u===p||(u=n(u),p=n(p),u===p))return"";let h=1;for(;h<u.length&&u.charCodeAt(h)===47;++h);let c=u.length,d=c-h,x=1;for(;x<p.length&&p.charCodeAt(x)===47;++x);let C=p.length-x,b=d<C?d: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 d>b&&(u.charCodeAt(h+w)===47?y=w:w===0&&(y=0));break}let O=u.charCodeAt(h+w),R=p.charCodeAt(x+w);if(O!==R)break;O===47&&(y=w)}let P="";for(w=h+y+1;w<=c;++w)(w===c||u.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(...u){if(u.length===0)return".";let p;for(let h=0;h<u.length;++h){let c=u[h];t(c),c.length>0&&(p===void 0?p=c:p+="/"+c)}return p===void 0?".":o(p)},isAbsolute:function(u){return t(u),u.length>0&&u.charCodeAt(0)===47},basename:function(u,p){if(p!==void 0&&typeof p!="string")throw new TypeError('"ext" argument must be a string');t(u);let h=0,c=-1,d=!0,x;if(p!==void 0&&p.length>0&&p.length<=u.length){if(p.length===u.length&&p===u)return"";let S=p.length-1,C=-1;for(x=u.length-1;x>=0;--x){let b=u.charCodeAt(x);if(b===47){if(!d){h=x+1;break}}else C===-1&&(d=!1,C=x+1),S>=0&&(b===p.charCodeAt(S)?--S===-1&&(c=x):(S=-1,c=C))}return h===c?c=C:c===-1&&(c=u.length),u.slice(h,c)}else{for(x=u.length-1;x>=0;--x)if(u.charCodeAt(x)===47){if(!d){h=x+1;break}}else c===-1&&(d=!1,c=x+1);return c===-1?"":u.slice(h,c)}},normalize:o,dirname:function(u){if(t(u),u.length===0)return".";let p=u.charCodeAt(0),h=p===47,c=-1,d=!0;for(let x=u.length-1;x>=1;--x)if(p=u.charCodeAt(x),p===47){if(!d){c=x;break}}else d=!1;return c===-1?h?"/":".":h&&c===1?"//":u.slice(0,c)},extname:function(u){t(u);let p=-1,h=0,c=-1,d=!0,x=0;for(let S=u.length-1;S>=0;--S){let C=u.charCodeAt(S);if(C===47){if(!d){h=S+1;break}continue}c===-1&&(d=!1,c=S+1),C===46?p===-1?p=S:x!==1&&(x=1):p!==-1&&(x=-1)}return p===-1||c===-1||x===0||x===1&&p===c-1&&p===h+1?"":u.slice(p,c)}}}async function hi(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=Jn({cwd:r,...e}),o=new Map,i=c=>n.normalize(n.resolve(r(),c)),a=c=>{for(let[d]of o)if((d+"/").startsWith(c))return!0;return c===t()},s=c=>(c=i(c),o.has(c)?!0:a(c)),l=c=>{c=i(c);let d=c===t()?c:c+"/",x=d.split("/").length-1,S=[];for(let[C]of o)if(C.split("/").slice(0,x).join("/")+"/"===d){let w=C.split("/")[x];w&&!S.includes(w)&&S.push(w)}return S.sort()},m=c=>{c=i(c);let d=o.get(c);return typeof d=="string"?d:null},g=c=>(c=i(c),{isFile:()=>o.has(c),isDirectory:()=>!o.has(c)&&a(c)}),f=async c=>{if(typeof crypto<"u"){let S=new TextEncoder().encode(c),C=await crypto.subtle.digest("SHA-256",S);return Array.from(new Uint8Array(C)).map(b=>b.toString(16).padStart(2,"0")).join("")}let d=0;for(let x=0;x<c.length;x++){let S=c.charCodeAt(x);d=(d<<5)-d+S,d|=0}return Number(Math.abs(d)).toString(36)},u=new Set,p={getRootDir:t,cwd:r,exists:async c=>s(c),existsSync:s,readdir:async c=>l(c),readdirSync:l,readFile:async c=>m(c),readFileSync:m,stat:async c=>g(c),statSync:g,writeFile:async(c,d)=>{c=i(c),o.set(c,d);let x={path:c,basename:n.basename(c),dirname:n.dirname(c),extname:n.extname(c)};for(let S of u)await S(x)},hash:f,getDeviceId:async()=>typeof navigator<"u"?f(navigator.userAgent):"",formatCode:async(c,d)=>d,on:(c,d)=>{c==="change"&&u.add(d)},off:(c,d)=>{c==="change"&&u.delete(d)},debug:(...c)=>{console.debug("[builder-dev-tools]",...c)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0"},h=await te(p);return p.getFrameworks=()=>h,p}async function Hn(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Yn(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 g=s[0];if(!g.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=g.statement;if(!e.ts.isVariableStatement(f))throw new Error(`Expected an export assignment from ${t}`);let u=g.statement;if(e.ts.isVariableStatement(u)){let p=[...u.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 c=h.initializer;if(e.ts.isObjectLiteralExpression(c)||e.ts.isCallExpression(c)){let d="BuilderDevTools()",x=[...n.statements],S=x.indexOf(u);return x[S]=e.ts.factory.updateVariableStatement(u,u.modifiers,e.ts.factory.updateVariableDeclarationList(u.declarationList,[e.ts.factory.updateVariableDeclaration(h,h.name,h.exclamationToken,h.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(d),void 0,[c]))])),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 g=l.statement;if(!e.ts.isExpressionStatement(g))throw new Error("Expected an expression statement for the default export");let f=g.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let u=Ft(e,n);n=u.sourceFile;let p=[...n.statements],h=p.indexOf(g);return p[h]=e.ts.factory.updateExpressionStatement(g,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.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 g=[...m.declarationList.declarations];if(g.length!==1)throw new Error("Expected a single variable declaration");let f=g[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let u=f.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let p=Ft(e,n);n=p.sourceFile;let h=[...n.statements],c=h.indexOf(m);return h[c]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[u]))])),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 g=l.node,f=l.statement;if(!e.ts.isExpressionStatement(f))throw new Error("Expected an expression statement for the default export");let u=f.expression;if(!e.ts.isBinaryExpression(u))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 c=[...h.statements],d=c.findIndex(y=>e.ts.isReturnStatement(y));if(d===-1)throw new Error("Expected a return statement on the next config function");let x=c[d],S=Ft(e,n);n=S.sourceFile,c[d]=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(u,u.left,u.operatorToken,e.ts.factory.updateArrowFunction(g,g.modifiers,g.typeParameters,g.parameters,g.type,g.equalsGreaterThanToken,e.ts.factory.updateBlock(h,c)))),n=e.ts.factory.updateSourceFile(n,C),o.content=I(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function Yn(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 Ft(e,t){let r=Yn(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 Zn(e,t,r){let n=E(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(er(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 g=s[0];if(!g.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let f=g.statement;if(!e.ts.isExportAssignment(f))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(f.expression)){let u="builderDevTools()",p=Si(e,f.expression);if(!p)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u),void 0,[p]),c=[...n.statements],d=c.indexOf(f);return c[d]=e.ts.factory.updateExportAssignment(f,f.modifiers,h),n=e.ts.factory.updateSourceFile(n,c),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 g=l.statement;if(!e.ts.isExpressionStatement(g))throw new Error("Expected an expression statement for the default export");let f=g.expression;if(!e.ts.isBinaryExpression(f))throw new Error("Expected a binary expression for the default export");let u=Gn(e,n);n=u.sourceFile;let p=[...n.statements],h=p.indexOf(g);return p[h]=e.ts.factory.updateExpressionStatement(g,e.ts.factory.updateBinaryExpression(f,f.left,f.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.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 g=[...m.declarationList.declarations];if(g.length!==1)throw new Error("Expected a single variable declaration");let f=g[0];if(!f.initializer)throw new Error("Expected an initializer on the declaration");let u=f.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let p=Gn(e,n);n=p.sourceFile;let h=[...n.statements],c=h.indexOf(m);return h[c]=e.ts.factory.updateVariableStatement(m,m.modifiers,e.ts.factory.updateVariableDeclarationList(m.declarationList,[e.ts.factory.updateVariableDeclaration(f,f.name,f.exclamationToken,f.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(p.withFnVariableName),void 0,[u]))])),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 er(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 Gn(e,t){let r=er(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 Si(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=Xn(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=Xn(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function Xn(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 nr(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 g=Ci(e,m);if(!g)return s;l[0]=e.ts.factory.updateArrowFunction(m,m.modifiers,m.typeParameters,m.parameters,m.type,m.equalsGreaterThanToken,g);let f=[...n.statements],u=f.indexOf(a);return f[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,l)),n=e.ts.factory.updateSourceFile(n,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 g=At(e,m);if(!g)return s;let f=[...n.statements],u=f.indexOf(a);return f[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[g])),n=e.ts.factory.updateSourceFile(n,f),n=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=At(e,a.expression);if(!l)return s;let m=[...n.statements],g=m.indexOf(a);return m[g]=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 Ci(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=At(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function At(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=tr(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=tr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function tr(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 rr(e,t,r){throw new Error("Webpack config updates not implemented")}var ir=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:Hn},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:Zn},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:nr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:rr}];async function ar(e){let t=e.resolve("/");for(let n of ir)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 te(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,or),{id:"next",filePath:n,content:or}}return null}async function wi(e){let t=await ar(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await ir.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=Z(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var or=`
371
371
  /** @type {import('next').NextConfig} */
372
372
  const nextConfig = {
373
373
  }
@@ -386,4 +386,4 @@ module.exports = nextConfig
386
386
  `,n+=` }
387
387
  `,n+=` }
388
388
  `,n+=`})();
389
- `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var ot="0.2.24";export{xi as createDevTools,hi as createDevToolsSys,te as detectFrameworks,jt as detectFrameworksFromPackageJson,wi as ensureConfigPlugin,ar as findBuildToolConfig,yi as getClientScript,Bt as parseDotEnvContent,ot as version};
389
+ `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var ot="0.2.25";export{xi as createDevTools,hi as createDevToolsSys,te as detectFrameworks,jt as detectFrameworksFromPackageJson,wi as ensureConfigPlugin,ar as findBuildToolConfig,yi as getClientScript,Bt as parseDotEnvContent,ot as version};
package/node/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var x=Object.create;var u=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var O=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var j=(t,o)=>{for(var n in o)u(t,n,{get:o[n],enumerable:!0})},w=(t,o,n,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of C(o))!N.call(t,i)&&i!==n&&u(t,i,{get:()=>o[i],enumerable:!(a=T(o,i))||a.enumerable});return t};var g=(t,o,n)=>(n=t!=null?x(O(t)):{},w(o||!t||!t.__esModule?u(n,"default",{value:t,enumerable:!0}):n,t)),P=t=>w(u({},"__esModule",{value:!0}),t);var E={};j(E,{createDevToolsNodeSys:()=>b});module.exports=P(E);var s=require("fs/promises"),v=require("crypto"),d=require("fs"),p=require("os"),l=g(require("path"),1),h=g(require("prettier"),1),D=g(require("typescript"),1),F=g(require("launch-editor"),1);async function S(t,o){let n=t.resolve("/");for(let a=0;a<20;a++){let i=t.join(o,"package.json"),f=await t.readFile(i);if(f)return JSON.parse(f);if(o===n)break;o=t.dirname(o)}return null}async function k(t){let o=[],n=await S(t,t.getRootDir());if(n){let a=$(n);o.push(...a)}return o}function $(t){let o=[];if(t&&typeof t=="object"){let n=new Set(Object.keys({...t.dependencies,...t.devDependencies}));for(let a of R)n.has(a)&&(o.some(i=>i.name===a)||o.push({name:a}))}return o}var R=["@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 b(t){let o=new Set,n=(...e)=>{if(process.env.DEBUG){let r=new Date,c=`${String(r.getMinutes()).padStart(2,"0")}:${String(r.getSeconds()).padStart(2,"0")}.${String(r.getMilliseconds()).padStart(3,"0")}`;console.debug(c,"[builder-dev-tools]",...e)}},a=async e=>{let r=(0,v.createHash)("md5");return r.update(e),r.digest("hex")},i={...l.default,getRootDir:()=>l.default.normalize(t.getRootDir()),cwd:()=>process.cwd(),exists:async e=>{try{return await(0,s.access)(e),!0}catch{return!1}},existsSync:e=>(0,d.existsSync)(e),readdir:async(e,r)=>{let c=await(0,s.readdir)(e);return r?c.map(m=>l.default.join(e,m)):c},readdirSync:e=>(0,d.readdirSync)(e),readFile:async e=>{y(t,e);try{return await(0,s.readFile)(e,"utf-8")}catch(r){if(r.code==="ENOENT")return null;throw n(r,e),r}},readFileSync(e){y(t,e);try{return(0,d.readFileSync)(e,"utf-8")}catch(r){if(r.code==="ENOENT")return null;throw n(r,e),r}},stat:async e=>await(0,s.stat)(e),statSync:e=>(0,d.statSync)(e),writeFile:async(e,r)=>{y(t,e),e=l.default.normalize(e);let c={path:e,basename:l.default.basename(e),dirname:l.default.dirname(e),extname:l.default.extname(e)};await(0,s.mkdir)(l.default.dirname(e),{recursive:!0}),await(0,s.writeFile)(e,r);for(let m of o)await m(c)},hash:a,getDeviceId:()=>a(`${(0,p.hostname)()}:${(0,p.homedir)()}`),formatCode:async(e,r)=>{let c=null;try{c=await h.default.resolveConfig(e)}catch{}return h.default.format(r,{...c,filepath:e})},on:(e,r)=>{e==="change"&&o.add(r)},off:(e,r)=>{e==="change"&&o.delete(r)},debug:n,launchEditor:async e=>{try{let r=e.filePath;typeof e.line=="number"&&(r+=`:${e.line}`,typeof e.column=="number"&&(r+=`:${e.column}`)),(0,F.default)(r,"code",(c,m)=>{console.error(`Failed to launch editor for ${c}`),m&&console.error(m)})}catch(r){console.error(`Failed to launch editor for ${String(r.message||r)}`)}},platform:()=>({runtime:"node",os:process.platform}),getFrameworks:()=>[],ts:D.default},f=await k(i);return i.getFrameworks=()=>f,i}function y(t,o){if(t.skipValidate)return;if(!o)throw new Error(`Invalid path: ${o} (7340)`);o=l.default.normalize(l.default.resolve(o));let n=t.getRootDir();if(!o.startsWith(n))throw new Error(`Invalid path: ${o} (7341)`)}0&&(module.exports={createDevToolsNodeSys});
1
+ "use strict";var b=Object.create;var u=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var N=Object.getPrototypeOf,C=Object.prototype.hasOwnProperty;var E=(t,o)=>{for(var n in o)u(t,n,{get:o[n],enumerable:!0})},h=(t,o,n,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of T(o))!C.call(t,i)&&i!==n&&u(t,i,{get:()=>o[i],enumerable:!(a=x(o,i))||a.enumerable});return t};var g=(t,o,n)=>(n=t!=null?b(N(t)):{},h(o||!t||!t.__esModule?u(n,"default",{value:t,enumerable:!0}):n,t)),R=t=>h(u({},"__esModule",{value:!0}),t);var $={};E($,{createDevToolsNodeSys:()=>O});module.exports=R($);var s=require("fs/promises"),D=require("crypto"),d=require("fs"),p=require("os"),l=g(require("path"),1),S=g(require("prettier"),1),v=g(require("typescript"),1),F=g(require("launch-editor"),1);async function w(t,o){let n=t.resolve("/");for(let a=0;a<20;a++){let i=t.join(o,"package.json"),f=await t.readFile(i);if(f)return JSON.parse(f);if(o===n)break;o=t.dirname(o)}return null}async function k(t){let o=[],n=await w(t,t.getRootDir());if(n){let a=j(n);o.push(...a)}return o}function j(t){let o=[];if(t&&typeof t=="object"){let n=new Set(Object.keys({...t.dependencies,...t.devDependencies}));for(let a of P)n.has(a)&&(o.some(i=>i.name===a)||o.push({name:a}))}return o}var P=["@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 O(t){let o=new Set,n=(...e)=>{if(process.env.DEBUG){let r=new Date,c=`${String(r.getMinutes()).padStart(2,"0")}:${String(r.getSeconds()).padStart(2,"0")}.${String(r.getMilliseconds()).padStart(3,"0")}`;console.debug(c,"[builder-dev-tools]",...e)}},a=async e=>{let r=(0,D.createHash)("md5");return r.update(e),r.digest("hex")},i={...l.default,getRootDir:()=>l.default.normalize(t.getRootDir()),cwd:()=>process.cwd(),exists:async e=>{try{return await(0,s.access)(e),!0}catch{return!1}},existsSync:e=>(0,d.existsSync)(e),readdir:async(e,r)=>{let c=await(0,s.readdir)(e);return r?c.map(m=>l.default.join(e,m)):c},readdirSync:e=>(0,d.readdirSync)(e),readFile:async e=>{y(t,e);try{return await(0,s.readFile)(e,"utf-8")}catch(r){if(r.code==="ENOENT")return null;throw n(r,e),r}},readFileSync(e){y(t,e);try{return(0,d.readFileSync)(e,"utf-8")}catch(r){if(r.code==="ENOENT")return null;throw n(r,e),r}},stat:async e=>await(0,s.stat)(e),statSync:e=>(0,d.statSync)(e),writeFile:async(e,r)=>{y(t,e),e=l.default.normalize(e);let c={path:e,basename:l.default.basename(e),dirname:l.default.dirname(e),extname:l.default.extname(e)};await(0,s.mkdir)(l.default.dirname(e),{recursive:!0}),await(0,s.writeFile)(e,r);for(let m of o)await m(c)},hash:a,getDeviceId:()=>a(`${(0,p.hostname)()}:${(0,p.homedir)()}`),formatCode:async(e,r)=>{let c=null;try{c=await S.default.resolveConfig(e)}catch{}return S.default.format(r,{...c,filepath:e})},on:(e,r)=>{e==="change"&&o.add(r)},off:(e,r)=>{e==="change"&&o.delete(r)},debug:n,launchEditor:async e=>{try{let r=e.filePath;typeof e.line=="number"&&(r+=`:${e.line}`,typeof e.column=="number"&&(r+=`:${e.column}`)),(0,F.default)(r,"code",(c,m)=>{console.error(`Failed to launch editor for ${c}`),m&&console.error(m)})}catch(r){console.error(`Failed to launch editor for ${String(r.message||r)}`)}},platform:()=>({runtime:"node",os:process.platform}),getFrameworks:()=>[],ts:v.default,version:"0.2.25"},f=await k(i);return i.getFrameworks=()=>f,i}function y(t,o){if(t.skipValidate)return;if(!o)throw new Error(`Invalid path: ${o} (7340)`);o=l.default.normalize(l.default.resolve(o));let n=t.getRootDir();if(!o.startsWith(n))throw new Error(`Invalid path: ${o} (7341)`)}0&&(module.exports={createDevToolsNodeSys});
package/node/index.mjs CHANGED
@@ -1 +1 @@
1
- import{access as h,mkdir as w,readdir as S,readFile as k,stat as v,writeFile as D}from"fs/promises";import{createHash as F}from"crypto";import{existsSync as b,readdirSync as x,readFileSync as T,statSync as C}from"fs";import{homedir as O,hostname as N}from"os";import s from"path";import g from"prettier";import j from"typescript";import P from"launch-editor";async function f(r,o){let n=r.resolve("/");for(let a=0;a<20;a++){let c=r.join(o,"package.json"),d=await r.readFile(c);if(d)return JSON.parse(d);if(o===n)break;o=r.dirname(o)}return null}async function u(r){let o=[],n=await f(r,r.getRootDir());if(n){let a=p(n);o.push(...a)}return o}function p(r){let o=[];if(r&&typeof r=="object"){let n=new Set(Object.keys({...r.dependencies,...r.devDependencies}));for(let a of y)n.has(a)&&(o.some(c=>c.name===a)||o.push({name:a}))}return o}var y=["@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 $(r){let o=new Set,n=(...e)=>{if(process.env.DEBUG){let t=new Date,i=`${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}.${String(t.getMilliseconds()).padStart(3,"0")}`;console.debug(i,"[builder-dev-tools]",...e)}},a=async e=>{let t=F("md5");return t.update(e),t.digest("hex")},c={...s,getRootDir:()=>s.normalize(r.getRootDir()),cwd:()=>process.cwd(),exists:async e=>{try{return await h(e),!0}catch{return!1}},existsSync:e=>b(e),readdir:async(e,t)=>{let i=await S(e);return t?i.map(l=>s.join(e,l)):i},readdirSync:e=>x(e),readFile:async e=>{m(r,e);try{return await k(e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw n(t,e),t}},readFileSync(e){m(r,e);try{return T(e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw n(t,e),t}},stat:async e=>await v(e),statSync:e=>C(e),writeFile:async(e,t)=>{m(r,e),e=s.normalize(e);let i={path:e,basename:s.basename(e),dirname:s.dirname(e),extname:s.extname(e)};await w(s.dirname(e),{recursive:!0}),await D(e,t);for(let l of o)await l(i)},hash:a,getDeviceId:()=>a(`${N()}:${O()}`),formatCode:async(e,t)=>{let i=null;try{i=await g.resolveConfig(e)}catch{}return g.format(t,{...i,filepath:e})},on:(e,t)=>{e==="change"&&o.add(t)},off:(e,t)=>{e==="change"&&o.delete(t)},debug:n,launchEditor:async e=>{try{let t=e.filePath;typeof e.line=="number"&&(t+=`:${e.line}`,typeof e.column=="number"&&(t+=`:${e.column}`)),P(t,"code",(i,l)=>{console.error(`Failed to launch editor for ${i}`),l&&console.error(l)})}catch(t){console.error(`Failed to launch editor for ${String(t.message||t)}`)}},platform:()=>({runtime:"node",os:process.platform}),getFrameworks:()=>[],ts:j},d=await u(c);return c.getFrameworks=()=>d,c}function m(r,o){if(r.skipValidate)return;if(!o)throw new Error(`Invalid path: ${o} (7340)`);o=s.normalize(s.resolve(o));let n=r.getRootDir();if(!o.startsWith(n))throw new Error(`Invalid path: ${o} (7341)`)}export{$ as createDevToolsNodeSys};
1
+ import{access as S,mkdir as h,readdir as w,readFile as k,stat as D,writeFile as v}from"fs/promises";import{createHash as F}from"crypto";import{existsSync as O,readdirSync as b,readFileSync as x,statSync as T}from"fs";import{homedir as N,hostname as C}from"os";import s from"path";import g from"prettier";import E from"typescript";import R from"launch-editor";async function f(r,o){let n=r.resolve("/");for(let a=0;a<20;a++){let c=r.join(o,"package.json"),d=await r.readFile(c);if(d)return JSON.parse(d);if(o===n)break;o=r.dirname(o)}return null}async function u(r){let o=[],n=await f(r,r.getRootDir());if(n){let a=p(n);o.push(...a)}return o}function p(r){let o=[];if(r&&typeof r=="object"){let n=new Set(Object.keys({...r.dependencies,...r.devDependencies}));for(let a of y)n.has(a)&&(o.some(c=>c.name===a)||o.push({name:a}))}return o}var y=["@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 j(r){let o=new Set,n=(...e)=>{if(process.env.DEBUG){let t=new Date,i=`${String(t.getMinutes()).padStart(2,"0")}:${String(t.getSeconds()).padStart(2,"0")}.${String(t.getMilliseconds()).padStart(3,"0")}`;console.debug(i,"[builder-dev-tools]",...e)}},a=async e=>{let t=F("md5");return t.update(e),t.digest("hex")},c={...s,getRootDir:()=>s.normalize(r.getRootDir()),cwd:()=>process.cwd(),exists:async e=>{try{return await S(e),!0}catch{return!1}},existsSync:e=>O(e),readdir:async(e,t)=>{let i=await w(e);return t?i.map(l=>s.join(e,l)):i},readdirSync:e=>b(e),readFile:async e=>{m(r,e);try{return await k(e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw n(t,e),t}},readFileSync(e){m(r,e);try{return x(e,"utf-8")}catch(t){if(t.code==="ENOENT")return null;throw n(t,e),t}},stat:async e=>await D(e),statSync:e=>T(e),writeFile:async(e,t)=>{m(r,e),e=s.normalize(e);let i={path:e,basename:s.basename(e),dirname:s.dirname(e),extname:s.extname(e)};await h(s.dirname(e),{recursive:!0}),await v(e,t);for(let l of o)await l(i)},hash:a,getDeviceId:()=>a(`${C()}:${N()}`),formatCode:async(e,t)=>{let i=null;try{i=await g.resolveConfig(e)}catch{}return g.format(t,{...i,filepath:e})},on:(e,t)=>{e==="change"&&o.add(t)},off:(e,t)=>{e==="change"&&o.delete(t)},debug:n,launchEditor:async e=>{try{let t=e.filePath;typeof e.line=="number"&&(t+=`:${e.line}`,typeof e.column=="number"&&(t+=`:${e.column}`)),R(t,"code",(i,l)=>{console.error(`Failed to launch editor for ${i}`),l&&console.error(l)})}catch(t){console.error(`Failed to launch editor for ${String(t.message||t)}`)}},platform:()=>({runtime:"node",os:process.platform}),getFrameworks:()=>[],ts:E,version:"0.2.25"},d=await u(c);return c.getFrameworks=()=>d,c}function m(r,o){if(r.skipValidate)return;if(!o)throw new Error(`Invalid path: ${o} (7340)`);o=s.normalize(s.resolve(o));let n=r.getRootDir();if(!o.startsWith(n))throw new Error(`Invalid path: ${o} (7341)`)}export{j as createDevToolsNodeSys};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/dev-tools",
3
- "version": "0.2.24",
3
+ "version": "0.2.25",
4
4
  "description": "Builder.io Visual CMS Devtools",
5
5
  "type": "module",
6
6
  "main": "./core/index.cjs",