@builder.io/dev-tools 1.0.8 → 1.0.9

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,4 +1,4 @@
1
- var br=Object.create;var Ut=Object.defineProperty;var Ir=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var Rr=Object.getPrototypeOf,Fr=Object.prototype.hasOwnProperty;var oe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ar=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Nr(t))!Fr.call(e,o)&&o!==r&&Ut(e,o,{get:()=>t[o],enumerable:!(n=Ir(t,o))||n.enumerable});return e};var Lr=(e,t,r)=>(r=e!=null?br(Rr(e)):{},Ar(t||!e||!e.__esModule?Ut(r,"default",{value:e,enumerable:!0}):r,e));var bt=oe(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});function Gn(e){return Object.prototype.toString.call(e)}ot.getType=Gn;function Ti(e){throw new TypeError("unsupported data type: "+Gn(e))}ot.throwUnknownDataType=Ti});var At=oe(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});var te="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);te+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);te+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);te+=t}var ve=te.length,Nt={};for(let e=0;e<ve;e++){let t=te[e];Nt[t]=e}function Rt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Nt[o];i*=r,t+=i,r*=ve}return t}ne.s_to_int=Rt;function Xn(e){let t=BigInt(0),r=BigInt(1),n=BigInt(ve);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Nt[i]);a*=r,t+=a,r*=n}return t}ne.s_to_big_int=Xn;function Ft(e){if(e===0)return te[0];let t=[];for(;e!==0;){let r=e%ve,n=te[r];t.push(n),e-=r,e/=ve}return t.reverse().join("")}ne.int_to_s=Ft;function Zn(e){let t=BigInt(0),r=BigInt(ve);if(e===t)return te[0];let n=[];for(;e!==t;){let o=e%r,i=te[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}ne.big_int_to_s=Zn;function at(e){return e.split("").reverse().join("")}function er(e){if(e<0)return"-"+er(-e);let[t,r]=e.toString().split(".");if(!r)return Ft(e);let n;r&&([r,n]=r.split("e")),t=it(t),r=at(r),r=it(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=at(n),n=it(n),o+=n}return o}ne.num_to_s=er;function it(e){let t=+e;return t.toString()===e?Ft(t):":"+Zn(BigInt(e))}ne.int_str_to_s=it;function It(e){return e[0]===":"?Xn(e.substring(1)).toString():Rt(e).toString()}function tr(e){if(e[0]==="-")return-tr(e.substr(1));let[t,r,n]=e.split(".");if(!r)return Rt(t);t=It(t),r=It(r),r=at(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=It(n),n=at(n),o+=i?-n:+n}return+o}ne.s_to_num=tr});var Ot=oe(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});var Lt=At();function wi(e){return"n|"+Lt.num_to_s(e)}re.encodeNum=wi;function Ei(e){return e=e.replace("n|",""),Lt.s_to_num(e)}re.decodeNum=Ei;function yi(e){return typeof e=="number"?e:Lt.s_to_int(e)}re.decodeKey=yi;function Pi(e){return e?"b|T":"b|F"}re.encodeBool=Pi;function Di(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}re.decodeBool=Di;function vi(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}re.encodeStr=vi;function bi(e){return e[0]+e[1]==="s|"?e.substr(2):e}re.decodeStr=bi});var nr=oe(kt=>{"use strict";Object.defineProperty(kt,"__esModule",{value:!0});kt.config={sort_key:!1}});var _t=oe(Te=>{"use strict";Object.defineProperty(Te,"__esModule",{value:!0});var Ii=nr(),Ni=bt(),jt=Ot(),Ri=At();function Fi(e){return e.store.toArray()}Te.memToValues=Fi;function rr(){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}}}Te.makeInMemoryStore=rr;function or(){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}}}Te.makeInMemoryCache=or;function Ai(){return{store:rr(),cache:or(),keyCount:0}}Te.makeInMemoryMemory=Ai;function Se(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=Ri.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function Li(e,t){Ii.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=Ue(e,t,void 0);return e.cache.setSchema(r,n),n}function Ue(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return Ue(e,null,r);break;case"object":if(t===null)return Se(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":Ue(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),Se(e,n)}else{let n=Object.keys(t);if(n.length===0)return Se(e,"o|");let o="o",i=Li(e,n);o+="|"+i;for(let a of n){let s=t[a],l=Ue(e,s,t);o+="|"+l}return Se(e,o)}case"boolean":return Se(e,jt.encodeBool(t));case"number":return Se(e,jt.encodeNum(t));case"string":return Se(e,jt.encodeStr(t))}return Ni.throwUnknownDataType(t)}Te.addValue=Ue});var Vt=oe(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});var Oi=bt(),st=Ot(),Bt=_t();function ki(e){let t=Bt.makeInMemoryMemory(),r=Bt.addValue(t,e,void 0);return[Bt.memToValues(t),r]}Qe.compress=ki;function ji(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=Me(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let l=i[s-2],c=n[s];c=Me(e,c),r[l]=c}return r}function _i(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=Me(e,a),o[i]=a}return o}function Me(e,t){if(t===""||t==="_")return null;let r=st.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 st.decodeBool(n);case"o|":return ji(e,n);case"n|":return st.decodeNum(n);case"a|":return _i(e,n);default:return st.decodeStr(n)}}return Oi.throwUnknownDataType(n)}Qe.decode=Me;function Bi(e){let[t,r]=e;return Me(t,r)}Qe.decompress=Bi});var ar=oe(lt=>{"use strict";Object.defineProperty(lt,"__esModule",{value:!0});function Vi(e){for(let t in e)e[t]===void 0&&delete e[t]}lt.trimUndefined=Vi;function $i(e){ir(e,new Set)}lt.trimUndefinedRecursively=$i;function ir(e,t){t.add(e);for(let r in e)if(e[r]===void 0)delete e[r];else{let n=e[r];n&&typeof n=="object"&&!t.has(n)&&ir(n,t)}}});var cr=oe(ge=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});var sr=Vt();ge.compress=sr.compress;ge.decompress=sr.decompress;var zi=Vt();ge.decode=zi.decode;var Ki=_t();ge.addValue=Ki.addValue;var lr=ar();ge.trimUndefined=lr.trimUndefined;ge.trimUndefinedRecursively=lr.trimUndefinedRecursively});async function Mt(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 Qt(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 be(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 be(e,a,r);if(l)return l}}))).find(i=>typeof i=="string")}async function xe(e){let t=[],r=await Mt(e,e.getRootDir());if(r){let n=qt(r);t.push(...n)}return t}function qt(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of Or)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var Or=["@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 ie(e){let t=Wt(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function ae(e,t){t=typeof t=="object"&&t!=null?t:{};let r=Wt(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function Wt(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function se(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await kr(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 kr(e,t){let r=await e.readFile(t);return typeof r=="string"?Jt(r):null}function Jt(e){let t={},r=e.replace(/\r\n?/gm,`
1
+ var br=Object.create;var Ut=Object.defineProperty;var Ir=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var Rr=Object.getPrototypeOf,Fr=Object.prototype.hasOwnProperty;var oe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ar=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Nr(t))!Fr.call(e,o)&&o!==r&&Ut(e,o,{get:()=>t[o],enumerable:!(n=Ir(t,o))||n.enumerable});return e};var Lr=(e,t,r)=>(r=e!=null?br(Rr(e)):{},Ar(t||!e||!e.__esModule?Ut(r,"default",{value:e,enumerable:!0}):r,e));var bt=oe(ot=>{"use strict";Object.defineProperty(ot,"__esModule",{value:!0});function Gn(e){return Object.prototype.toString.call(e)}ot.getType=Gn;function Ei(e){throw new TypeError("unsupported data type: "+Gn(e))}ot.throwUnknownDataType=Ei});var At=oe(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});var te="";for(let e=0;e<10;e++){let t=String.fromCharCode(48+e);te+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(65+e);te+=t}for(let e=0;e<26;e++){let t=String.fromCharCode(97+e);te+=t}var ve=te.length,Nt={};for(let e=0;e<ve;e++){let t=te[e];Nt[t]=e}function Rt(e){let t=0,r=1;for(let n=e.length-1;n>=0;n--){let o=e[n],i=Nt[o];i*=r,t+=i,r*=ve}return t}ne.s_to_int=Rt;function Xn(e){let t=BigInt(0),r=BigInt(1),n=BigInt(ve);for(let o=e.length-1;o>=0;o--){let i=e[o],a=BigInt(Nt[i]);a*=r,t+=a,r*=n}return t}ne.s_to_big_int=Xn;function Ft(e){if(e===0)return te[0];let t=[];for(;e!==0;){let r=e%ve,n=te[r];t.push(n),e-=r,e/=ve}return t.reverse().join("")}ne.int_to_s=Ft;function Zn(e){let t=BigInt(0),r=BigInt(ve);if(e===t)return te[0];let n=[];for(;e!==t;){let o=e%r,i=te[Number(o)];n.push(i),e-=o,e/=r}return n.reverse().join("")}ne.big_int_to_s=Zn;function at(e){return e.split("").reverse().join("")}function er(e){if(e<0)return"-"+er(-e);let[t,r]=e.toString().split(".");if(!r)return Ft(e);let n;r&&([r,n]=r.split("e")),t=it(t),r=at(r),r=it(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=at(n),n=it(n),o+=n}return o}ne.num_to_s=er;function it(e){let t=+e;return t.toString()===e?Ft(t):":"+Zn(BigInt(e))}ne.int_str_to_s=it;function It(e){return e[0]===":"?Xn(e.substring(1)).toString():Rt(e).toString()}function tr(e){if(e[0]==="-")return-tr(e.substr(1));let[t,r,n]=e.split(".");if(!r)return Rt(t);t=It(t),r=It(r),r=at(r);let o=t+"."+r;if(n){o+="e";let i=!1;n[0]==="-"&&(i=!0,n=n.slice(1)),n=It(n),n=at(n),o+=i?-n:+n}return+o}ne.s_to_num=tr});var Ot=oe(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});var Lt=At();function yi(e){return"n|"+Lt.num_to_s(e)}re.encodeNum=yi;function Pi(e){return e=e.replace("n|",""),Lt.s_to_num(e)}re.decodeNum=Pi;function Di(e){return typeof e=="number"?e:Lt.s_to_int(e)}re.decodeKey=Di;function vi(e){return e?"b|T":"b|F"}re.encodeBool=vi;function bi(e){switch(e){case"b|T":return!0;case"b|F":return!1}return!!e}re.decodeBool=bi;function Ii(e){switch(e[0]+e[1]){case"b|":case"o|":case"n|":case"a|":case"s|":e="s|"+e}return e}re.encodeStr=Ii;function Ni(e){return e[0]+e[1]==="s|"?e.substr(2):e}re.decodeStr=Ni});var nr=oe(kt=>{"use strict";Object.defineProperty(kt,"__esModule",{value:!0});kt.config={sort_key:!1}});var _t=oe(Te=>{"use strict";Object.defineProperty(Te,"__esModule",{value:!0});var Ri=nr(),Fi=bt(),jt=Ot(),Ai=At();function Li(e){return e.store.toArray()}Te.memToValues=Li;function rr(){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}}}Te.makeInMemoryStore=rr;function or(){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}}}Te.makeInMemoryCache=or;function Oi(){return{store:rr(),cache:or(),keyCount:0}}Te.makeInMemoryMemory=Oi;function Se(e,t){if(e.cache.hasValue(t))return e.cache.getValue(t);let r=e.keyCount++,n=Ai.num_to_s(r);return e.store.add(t),e.cache.setValue(t,n),n}function ki(e,t){Ri.config.sort_key&&t.sort();let r=t.join(",");if(e.cache.hasSchema(r))return e.cache.getSchema(r);let n=Ue(e,t,void 0);return e.cache.setSchema(r,n),n}function Ue(e,t,r){if(t===null)return"";switch(typeof t){case"undefined":if(Array.isArray(r))return Ue(e,null,r);break;case"object":if(t===null)return Se(e,null);if(Array.isArray(t)){let n="a";for(let o=0;o<t.length;o++){let i=t[o],a=i===null?"_":Ue(e,i,t);n+="|"+a}return n==="a"&&(n="a|"),Se(e,n)}else{let n=Object.keys(t);if(n.length===0)return Se(e,"o|");let o="o",i=ki(e,n);o+="|"+i;for(let a of n){let s=t[a],l=Ue(e,s,t);o+="|"+l}return Se(e,o)}case"boolean":return Se(e,jt.encodeBool(t));case"number":return Se(e,jt.encodeNum(t));case"string":return Se(e,jt.encodeStr(t))}return Fi.throwUnknownDataType(t)}Te.addValue=Ue});var Vt=oe(Qe=>{"use strict";Object.defineProperty(Qe,"__esModule",{value:!0});var ji=bt(),st=Ot(),Bt=_t();function _i(e){let t=Bt.makeInMemoryMemory(),r=Bt.addValue(t,e,void 0);return[Bt.memToValues(t),r]}Qe.compress=_i;function Bi(e,t){if(t==="o|")return{};let r={},n=t.split("|"),o=n[1],i=Me(e,o),a=n.length;a-2===1&&!Array.isArray(i)&&(i=[i]);for(let s=2;s<a;s++){let l=i[s-2],c=n[s];c=Me(e,c),r[l]=c}return r}function Vi(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=Me(e,a),o[i]=a}return o}function Me(e,t){if(t===""||t==="_")return null;let r=st.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 st.decodeBool(n);case"o|":return Bi(e,n);case"n|":return st.decodeNum(n);case"a|":return Vi(e,n);default:return st.decodeStr(n)}}return ji.throwUnknownDataType(n)}Qe.decode=Me;function $i(e){let[t,r]=e;return Me(t,r)}Qe.decompress=$i});var ar=oe(lt=>{"use strict";Object.defineProperty(lt,"__esModule",{value:!0});function zi(e){for(let t in e)e[t]===void 0&&delete e[t]}lt.trimUndefined=zi;function Ki(e){ir(e,new Set)}lt.trimUndefinedRecursively=Ki;function ir(e,t){t.add(e);for(let r in e)if(e[r]===void 0)delete e[r];else{let n=e[r];n&&typeof n=="object"&&!t.has(n)&&ir(n,t)}}});var cr=oe(ge=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});var sr=Vt();ge.compress=sr.compress;ge.decompress=sr.decompress;var Ui=Vt();ge.decode=Ui.decode;var Mi=_t();ge.addValue=Mi.addValue;var lr=ar();ge.trimUndefined=lr.trimUndefined;ge.trimUndefinedRecursively=lr.trimUndefinedRecursively});async function Mt(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 Qt(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 be(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 be(e,a,r);if(l)return l}}))).find(i=>typeof i=="string")}async function xe(e){let t=[],r=await Mt(e,e.getRootDir());if(r){let n=qt(r);t.push(...n)}return t}function qt(e){let t=[];if(e&&typeof e=="object"){let r=new Set(Object.keys({...e.dependencies,...e.devDependencies}));for(let n of Or)r.has(n)&&(t.some(o=>o.name===n)||t.push({name:n}))}return t}var Or=["@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 ie(e){let t=Wt(e),r=await e.readFile(t);return typeof r=="string"?JSON.parse(r):{}}async function ae(e,t){t=typeof t=="object"&&t!=null?t:{};let r=Wt(e);await e.writeFile(r,JSON.stringify(t??{},null,2))}function Wt(e){let t=e.getRootDir();return e.join(t,"node_modules",".builder","builder-cache.json")}async function se(e,t,r){let n={envKey:r,envValue:null,file:""};for(let o of t){let i=e.join(e.getRootDir(),o),a=await kr(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 kr(e,t){let r=await e.readFile(t);return typeof r=="string"?Jt(r):null}function Jt(e){let t={},r=e.replace(/\r\n?/gm,`
2
2
  `),n;for(;(n=jr.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
3
  `),i=i.replace(/\\r/g,"\r")),t[o]=i}return t}var jr=/(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/gm;async function le(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
 
@@ -19,7 +19,7 @@ ${r}=${n}
19
19
  name: "${t.name}",
20
20
  }
21
21
  `,r+=");";let n=We(e,r);return gt(e,n,t)}function gt(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]=q(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 Qt(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=ke.get(a);if(!s){try{e.statSync(a).isFile()?s={exists:!0,content:e.readFileSync(a)}:s={exists:!1}}catch{s={exists:!1}}ke.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=ke.get(a);if(l)return D(e,l.content)}let s=e.readFileSync(a);if(s==null){let l=e.basename(a),c=e.extname(l).toLowerCase();if(a.startsWith(n)&&c===".ts"&&(s=on.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new Ye(l)}return a.includes("node_modules")&&(s?ke.set(a,{exists:!0,content:s}):ke.set(a,{exists:!1})),D(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return co(e,i,t)}catch(a){if(a instanceof Ye){await po(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function co(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=rn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let l=e.readFileSync(s);return typeof l=="string"?l:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(l,c)=>e.readdirSync(l),fileExists:l=>e.existsSync(l),readFile:l=>e.readFileSync(l)||void 0},e.dirname(o),void 0,o).options,rn.set(o,i))}i&&(n.options=V(i))}return n.options.moduleResolution=e.ts.ModuleResolutionKind.Node16,n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function He(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 Ye=class{constructor(t){this.libName=t}};async function po(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;Je.has(t)||Je.set(t,fetch(r).then(n=>n.text()).then(n=>{on.set(t,n)})),await Je.get(t),Je.delete(t)}var on=new Map,Je=new Map,ke=new Map,rn=new Map;function y(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=uo(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=mo(e,t,r.defaultImport,r.importPath,n)),t}function uo(e,t,r,n,o,i){return i==="cjs"?sn(e,t,null,r,n):an(e,t,null,r,n,o)}function mo(e,t,r,n,o){return o==="cjs"?sn(e,t,r,null,n):an(e,t,r,null,n,!1)}function an(e,t,r,n,o,i){let a=[...t.statements],s=0,l=!1,c=!1;for(let m=0;m<a.length;m++){let h=a[m];if(!e.ts.isImportDeclaration(h)||(s=m,!h.moduleSpecifier||!e.ts.isStringLiteral(h.moduleSpecifier))||h.moduleSpecifier.text!==o||!!h.importClause?.isTypeOnly!==i)continue;let f=[],x=h.importClause?.namedBindings;if(x&&e.ts.isNamedImports(x)&&x.elements&&f.push(...x.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,S)=>C.name.text.localeCompare(S.name.text)),l=!0}let g=h.importClause?h.importClause.name:void 0;if(typeof r=="string"){if(g&&g.text===r)return t;g=e.ts.factory.createIdentifier(r),c=!0}if(l||c)return a[m]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,g,e.ts.factory.createNamedImports(f)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,p;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(p=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let u=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,p),e.ts.factory.createStringLiteral(o));return a.splice(s,0,u),e.ts.factory.updateSourceFile(t,a)}function sn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let l=i[s];if(e.ts.isVariableStatement(l))for(let c=0;c<l.declarationList.declarations.length;c++){let d=[...l.declarationList.declarations],p=d[c],u=p.initializer;if(!u||!e.ts.isCallExpression(u))continue;let m=u.expression;if(!e.ts.isIdentifier(m)||m.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(p.name)&&typeof r=="string")return p.name.text===r?t:(d[c]=e.ts.factory.updateVariableDeclaration(p,e.ts.factory.createIdentifier(r),p.exclamationToken,p.type,p.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(p.name)&&typeof n=="string"){let f=[...p.name.elements];return f.some(g=>!e.ts.isBindingElement(g)||!e.ts.isIdentifier(g.name)?!1:g.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((g,C)=>!e.ts.isBindingElement(g)||!e.ts.isIdentifier(g.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:g.name.text.localeCompare(C.name.text)),d[c]=e.ts.factory.updateVariableDeclaration(p,e.ts.factory.createObjectBindingPattern(f),p.exclamationToken,p.type,p.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function z(e,t,r="esm"){return r==="cjs"?go(e,t):fo(e,t)}function fo(e,t){let r=[];for(let n of t.statements){if(e.ts.isExportDeclaration(n)){if(n.exportClause&&e.ts.isNamedExports(n.exportClause)){for(let o of n.exportClause.elements)if(n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:o}),e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function go(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let 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 xo(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 Ge(e,t,r,n){let o=xo(e,r,n);if(o){let i=await je(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:R(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function ht(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 ce(e,t,r){let n=ht(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 Xe(e,t){if(t){if(ho(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Xe(e,n)&&(r=!0)}),r)return!0}return!1}function ho(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 je(e,t){let r=e.extname(t).toLowerCase();if(r===""||!xt.includes(r)){for(let n of xt){let o=t+n;if(await e.exists(o))return o}for(let n of xt){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var xt=[".tsx",".jsx",".ts",".js"];function _e(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=Co(e,i);return a?[{name:a}]:void 0}function Co(e,t){if(typeof t=="string"){t=e.normalize(U(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 pe(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 ye(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await $(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{if(!a.isRegistered){let s=n.getSourceFile(a.filePath);if(s){let c=(await ue(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);c&&(a.inputs=Oe(e,o,c.node.fnNode))}}return a}))}async function Pe(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await He(e,t.cmpInfo.filePath,r),a=(await ue(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 Oe(e,o,a.node.fnNode)}return[]}async function ln(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return So(e,t,n)}return null}function So(e,t,r){let n=D(e,r);return ue(e,null,t,n)}async function ue(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=z(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),a=_(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Re(s.name.text))continue;let l=Be(e,t,s.initializer);if(l){let c=l.name||s.name.text,d=n.isDefaultExport?"default":c,p=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:R(e,r),name:j(c),inputs:[],exportName:d,exportType:p,importName:c,filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}}return o}if(e.ts.isArrowFunction(n.node)){let s=Be(e,t,n.node);if(s){let l=M(e,r),c=n.isDefaultExport?"default":l,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:R(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:we(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let s=n.node.name?.text;if(s&&!Re(s))return o;let l=Be(e,t,n.node);if(l){let c=l.name||M(e,r),d=n.isDefaultExport||!l.name?"default":l.name,p=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:R(e,r),name:c,inputs:[],exportName:d,exportType:p,importName:l.name||we(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}return o}if(e.ts.isExportSpecifier(n.node)&&Re(n.node.getText())){let s=Be(e,t,n.node);if(s){let l=s.name||M(e,r),c=n.isDefaultExport||!s.name?"default":s.name,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:R(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:s.name||we(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function Be(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Xe(e,r.body)?{name:"",fnNode:r,deps:_e(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Xe(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:_e(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:Be(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)||!Re(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:_e(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:_e(e,t,n)}}return null}async function cn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.normalize(i.fileName);if(a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await ue(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}async function pn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(e.appDir&&wo.has(a)||e.dirname(i.fileName).includes("node_modules"))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let l=await ue(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var wo=new Set(["default.tsx","default.ts","default.jsx","default.js","error.tsx","error.ts","error.jsx","error.js","layout.tsx","layout.ts","layout.jsx","layout.js","loading.tsx","loading.ts","loading.jsx","loading.js","not-found.tsx","not-found.ts","not-found.jsx","not-found.js","page.tsx","page.ts","page.jsx","page.js","route.tsx","route.ts","route.jsx","route.js","template.tsx","template.ts","template.jsx","template.js"]);function me(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,[...Ct(e,r),...Ct(e,n),...Ct(e,o),...i])}function W(e){let t=e.split(`
22
+ `,getSourceFile:a=>{if(a=e.normalize(a),a.includes("node_modules")){let l=ke.get(a);if(l)return D(e,l.content)}let s=e.readFileSync(a);if(s==null){let l=e.basename(a),c=e.extname(l).toLowerCase();if(a.startsWith(n)&&c===".ts"&&(s=on.get(l),s==null&&typeof self<"u"&&typeof fetch=="function"))throw new Ye(l)}return a.includes("node_modules")&&(s?ke.set(a,{exists:!0,content:s}):ke.set(a,{exists:!1})),D(e,s)},readFile:a=>{let s=e.readFileSync(a);return typeof s=="string"?s:void 0},useCaseSensitiveFileNames:()=>!1,writeFile:()=>{}};for(;;)try{return co(e,i,t)}catch(a){if(a instanceof Ye){await po(e,a.libName);continue}throw console.error("createTsProgram",a),new Error(`createTsProgram() Could not create program for: ${t[0]}`)}}function co(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=rn.get(o);if(!i){let a=e.ts.readConfigFile(o,s=>{let l=e.readFileSync(s);return typeof l=="string"?l:void 0});a.error?console.error("error reading tsconfig for createTsProgram"):(i=e.ts.parseJsonConfigFileContent(a.config,e.ts.sys||{useCaseSensitiveFileNames:!1,readDirectory:(l,c)=>e.readdirSync(l),fileExists:l=>e.existsSync(l),readFile:l=>e.readFileSync(l)||void 0},e.dirname(o),void 0,o).options,rn.set(o,i))}i&&(n.options=V(i))}return n.options.moduleResolution=e.ts.ModuleResolutionKind.Node16,n.options.noEmit=!0,n.options.isolatedModules=!1,n.options.strict=!1,n.options.jsx=e.ts.JsxEmit.Preserve,n.options.allowJs=!0,e.ts.createProgram(n)}async function He(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 Ye=class{constructor(t){this.libName=t}};async function po(e,t){let r=`https://cdn.jsdelivr.net/npm/typescript@${e.ts.version}/lib/${t}`;Je.has(t)||Je.set(t,fetch(r).then(n=>n.text()).then(n=>{on.set(t,n)})),await Je.get(t),Je.delete(t)}var on=new Map,Je=new Map,ke=new Map,rn=new Map;function y(e,t,r,n="esm"){return Array.isArray(r.namedImports)&&r.namedImports.forEach(o=>{t=uo(e,t,o,r.importPath,!!r.isTypeOnly,n)}),typeof r.defaultImport=="string"&&(t=mo(e,t,r.defaultImport,r.importPath,n)),t}function uo(e,t,r,n,o,i){return i==="cjs"?sn(e,t,null,r,n):an(e,t,null,r,n,o)}function mo(e,t,r,n,o){return o==="cjs"?sn(e,t,r,null,n):an(e,t,r,null,n,!1)}function an(e,t,r,n,o,i){let a=[...t.statements],s=0,l=!1,c=!1;for(let m=0;m<a.length;m++){let h=a[m];if(!e.ts.isImportDeclaration(h)||(s=m,!h.moduleSpecifier||!e.ts.isStringLiteral(h.moduleSpecifier))||h.moduleSpecifier.text!==o||!!h.importClause?.isTypeOnly!==i)continue;let f=[],x=h.importClause?.namedBindings;if(x&&e.ts.isNamedImports(x)&&x.elements&&f.push(...x.elements),typeof n=="string"){if(f.some(C=>C.name.text===n))return t;f.push(e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))),f.sort((C,S)=>C.name.text.localeCompare(S.name.text)),l=!0}let g=h.importClause?h.importClause.name:void 0;if(typeof r=="string"){if(g&&g.text===r)return t;g=e.ts.factory.createIdentifier(r),c=!0}if(l||c)return a[m]=e.ts.factory.updateImportDeclaration(h,void 0,e.ts.factory.createImportClause(i,g,e.ts.factory.createNamedImports(f)),h.moduleSpecifier,void 0),e.ts.factory.updateSourceFile(t,a)}let d,p;typeof r=="string"&&(d=e.ts.factory.createIdentifier(r)),typeof n=="string"&&(p=e.ts.factory.createNamedImports([e.ts.factory.createImportSpecifier(!1,void 0,e.ts.factory.createIdentifier(n))]));let u=e.ts.factory.createImportDeclaration(void 0,e.ts.factory.createImportClause(i,d,p),e.ts.factory.createStringLiteral(o));return a.splice(s,0,u),e.ts.factory.updateSourceFile(t,a)}function sn(e,t,r,n,o){let i=[...t.statements],a=0;for(let s=0;s<i.length;s++){let l=i[s];if(e.ts.isVariableStatement(l))for(let c=0;c<l.declarationList.declarations.length;c++){let d=[...l.declarationList.declarations],p=d[c],u=p.initializer;if(!u||!e.ts.isCallExpression(u))continue;let m=u.expression;if(!e.ts.isIdentifier(m)||m.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(p.name)&&typeof r=="string")return p.name.text===r?t:(d[c]=e.ts.factory.updateVariableDeclaration(p,e.ts.factory.createIdentifier(r),p.exclamationToken,p.type,p.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i));if(e.ts.isObjectBindingPattern(p.name)&&typeof n=="string"){let f=[...p.name.elements];return f.some(g=>!e.ts.isBindingElement(g)||!e.ts.isIdentifier(g.name)?!1:g.name.text===n)?t:(f.push(e.ts.factory.createBindingElement(void 0,void 0,n)),f.sort((g,C)=>!e.ts.isBindingElement(g)||!e.ts.isIdentifier(g.name)||!e.ts.isBindingElement(C)||!e.ts.isIdentifier(C.name)?0:g.name.text.localeCompare(C.name.text)),d[c]=e.ts.factory.updateVariableDeclaration(p,e.ts.factory.createObjectBindingPattern(f),p.exclamationToken,p.type,p.initializer),i[s]=e.ts.factory.updateVariableStatement(l,l.modifiers,e.ts.factory.updateVariableDeclarationList(l.declarationList,d)),e.ts.factory.updateSourceFile(t,i))}}}}if(typeof r=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}if(typeof n=="string"){let s=e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(e.ts.factory.createObjectBindingPattern([e.ts.factory.createBindingElement(void 0,void 0,n)]),void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral(o)]))],e.ts.NodeFlags.Const));return i.splice(a,0,s),e.ts.factory.updateSourceFile(t,i)}return t}function z(e,t,r="esm"){return r==="cjs"?go(e,t):fo(e,t)}function fo(e,t){let r=[];for(let n of t.statements){if(e.ts.isExportDeclaration(n)){if(n.exportClause&&e.ts.isNamedExports(n.exportClause)){for(let o of n.exportClause.elements)if(n.moduleSpecifier&&r.push({isDefaultExport:!1,statement:n,node:o}),e.ts.isIdentifier(o.name)){let i=o.name.text;for(let a of t.statements)if(e.ts.isVariableStatement(a))for(let s of a.declarationList.declarations)e.ts.isIdentifier(s.name)&&s.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a});else e.ts.isFunctionDeclaration(a)&&a.name&&a.name.text===i&&r.push({isDefaultExport:!1,statement:a,node:a})}}continue}if(e.ts.isExportAssignment(n)){let o=n.flags===e.ts.NodeFlags.None,i=n.expression;if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements){if(e.ts.isVariableStatement(s))for(let l of s.declarationList.declarations)e.ts.isIdentifier(l.name)&&l.name.text===a&&r.push({isDefaultExport:o,statement:s,node:s});e.ts.isFunctionDeclaration(s)&&s.name?.text===a&&r.push({isDefaultExport:o,statement:s,node:s})}}else(e.ts.isArrowFunction(i)||e.ts.isCallExpression(i)||e.ts.isFunctionDeclaration(i)||e.ts.isObjectLiteralExpression(i))&&r.push({isDefaultExport:o,statement:n,node:i});continue}if((e.ts.isVariableStatement(n)||e.ts.isFunctionDeclaration(n))&&n.modifiers&&n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.ExportKeyword)){r.push({isDefaultExport:n.modifiers.some(o=>o.kind===e.ts.SyntaxKind.DefaultKeyword),statement:n,node:n});continue}}return r}function go(e,t){let r=[];for(let n of t.statements)if(e.ts.isExpressionStatement(n)&&e.ts.isBinaryExpression(n.expression)&&e.ts.isPropertyAccessExpression(n.expression.left)){let o=n.expression.left,i=n.expression.right;if(!e.ts.isIdentifier(o.expression))continue;if(o.expression.text==="module"&&o.name.text==="exports"){if(e.ts.isIdentifier(i)){let a=i.text;for(let s of t.statements)if(e.ts.isVariableStatement(s))for(let 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 xo(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 Ge(e,t,r,n){let o=xo(e,r,n);if(o){let i=await je(e,e.normalize(e.resolve(e.dirname(t),o.importPath))),a=e.relative(e.getRootDir(),i);return{displayFilePath:R(e,i),filePath:i,relFilePath:a,importPath:o.importPath,exportType:o.exportType}}return null}function ht(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 ce(e,t,r){let n=ht(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 Xe(e,t){if(t){if(ho(e,t))return!0;let r=!1;if(t.forEachChild(n=>{Xe(e,n)&&(r=!0)}),r)return!0}return!1}function ho(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 je(e,t){let r=e.extname(t).toLowerCase();if(r===""||!xt.includes(r)){for(let n of xt){let o=t+n;if(await e.exists(o))return o}for(let n of xt){let o=e.join(t,"index"+n);if(await e.exists(o))return o}}return t}var xt=[".tsx",".jsx",".ts",".js"];function _e(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=Co(e,i);return a?[{name:a}]:void 0}function Co(e,t){if(typeof t=="string"){t=e.normalize(U(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 pe(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 ye(e,t){if(!t.some(a=>!a.isRegistered))return t;let n=await $(e,t.map(a=>a.filePath)),o=n.getTypeChecker();return await Promise.all(t.map(async a=>{if(!a.isRegistered){let s=n.getSourceFile(a.filePath);if(s){let c=(await ue(e,o,a.filePath,s)).find(d=>d.cmpInfo.id===a.id);c&&(a.inputs=Oe(e,o,c.node.fnNode))}}return a}))}async function Pe(e,t,r){if(t.node.fnNode){let{sourceFile:n,typeChecker:o}=await He(e,t.cmpInfo.filePath,r),a=(await ue(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 Oe(e,o,a.node.fnNode)}return[]}async function ln(e,t){let r=e.extname(t).toLowerCase();if(r===".tsx"||r===".jsx"||r===".ts"||r===".js"){let n=await e.readFile(t);if(n)return So(e,t,n)}return null}function So(e,t,r){let n=D(e,r);return ue(e,null,t,n)}async function ue(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=z(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),a=_(e,r);if(e.ts.isVariableStatement(n.node)){for(let s of n.node.declarationList.declarations){if(!e.ts.isIdentifier(s.name)||!Re(s.name.text))continue;let l=Be(e,t,s.initializer);if(l){let c=l.name||s.name.text,d=n.isDefaultExport?"default":c,p=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:R(e,r),name:j(c),inputs:[],exportName:d,exportType:p,importName:c,filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}}return o}if(e.ts.isArrowFunction(n.node)){let s=Be(e,t,n.node);if(s){let l=M(e,r),c=n.isDefaultExport?"default":l,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:R(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:we(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}if(e.ts.isFunctionExpression(n.node)||e.ts.isFunctionDeclaration(n.node)){let s=n.node.name?.text;if(s&&!Re(s))return o;let l=Be(e,t,n.node);if(l){let c=l.name||M(e,r),d=n.isDefaultExport||!l.name?"default":l.name,p=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,d),displayFilePath:R(e,r),name:c,inputs:[],exportName:d,exportType:p,importName:l.name||we(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:l.deps},node:l})}return o}if(e.ts.isExportSpecifier(n.node)&&Re(n.node.getText())){let s=Be(e,t,n.node);if(s){let l=s.name||M(e,r),c=n.isDefaultExport||!s.name?"default":s.name,d=n.isDefaultExport?"default":"named";o.push({cmpInfo:{id:await k(e,r,c),displayFilePath:R(e,r),name:l,inputs:[],exportName:c,exportType:d,importName:s.name||we(e,r),filePath:r,relFilePath:i,importPath:a,dependencies:s.deps},node:s})}return o}return o}function Be(e,t,r){if(!r)return null;if(e.ts.isArrowFunction(r))return Xe(e,r.body)?{name:"",fnNode:r,deps:_e(e,t,r)}:null;if(e.ts.isFunctionExpression(r)||e.ts.isFunctionDeclaration(r))return Xe(e,r.body)?{name:r.name?.text||"",fnNode:r,deps:_e(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:Be(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)||!Re(o.text))return null;let a=t.getTypeAtLocation(o).getCallSignatures();if(a.length>0&&a[0].getParameters().length>0)return{name:"",fnNode:o,deps:_e(e,t,o)}}if(e.ts.isExportSpecifier(r)){let n=r.name;return{name:n.text||"",fnNode:n,deps:_e(e,t,n)}}return null}async function cn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.normalize(i.fileName);if(Eo(e,i.fileName)||a===e.reactConfigPath||a===e.registryPath||a===e.builderComponentPath)return;let s=await ue(e,o,a,i);r.push(...s)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var wo=new Set(["node_modules","dist"]);function Eo(e,t){for(let r of wo)if(e.dirname(t).includes(r))return!0;return!1}async function pn(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&&yo.has(a)||e.dirname(i.fileName).includes("node_modules"))return;let s=e.normalize(i.fileName);if(s===e.nextConfigPath||s===e.registryPath||s===e.builderComponentPath)return;let l=await ue(e,o,s,i);r.push(...l)})),r.sort((i,a)=>i.cmpInfo.name.localeCompare(a.cmpInfo.name))}var yo=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 me(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,[...Ct(e,r),...Ct(e,n),...Ct(e,o),...i])}function W(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 Ct(e,t){return t.sort((r,n)=>{let o=un(e,r),i=un(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())})}function un(e,t){let r=t.importClause;if(r){let n=r.namedBindings;if(n&&e.ts.isNamedImports(n)&&n.elements.length>0)return n.elements[0].name.text;if(r.name)return r.name.text}return t.moduleSpecifier&&e.ts.isStringLiteral(t.moduleSpecifier)?t.moduleSpecifier.text:""}function fn(e){return typeof e=="string"&&!e.includes("'use client'")&&!e.includes(`"use client"'`)&&(e=`"use client"
32
- ${e}`),e}function dn(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 Ze(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=mn(e,r),i=mn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function mn(e,t){let r=t.properties.find(n=>b(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function hn(e){let t=await e.readFile(e.registryPath);return t?Eo(e,t):{components:[],sourceFile:D(e,"")}}async function Eo(e,t){let r=D(e,t);return yo(e,r)}async function yo(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let p=c[0];if(e.ts.isCallExpression(p)){if((e.ts.isIdentifier(p.expression)&&p.expression.text)==="withChildren"){let h=p.arguments[0];if(e.ts.isCallExpression(h)){let f=await gn(e,n,h,d,!0);f&&r.push(f)}else{let f=p.arguments[0];if(e.ts.isIdentifier(f)){let x=await xn(e,t,n,f,d,!0);x&&r.push(x)}}continue}let m=await gn(e,n,p,d,!1);m&&r.push(m);continue}if(e.ts.isIdentifier(p)){let u=await xn(e,t,n,p,d,!1);u&&r.push(u);continue}}return{sourceFile:t,components:Q(r)}}async function gn(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let l=s.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let d=l.arguments[0];if(!e.ts.isStringLiteral(d))return null;let p=d.text;i.filePath=await et(e,p),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=M(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let c=l.expression;if(!e.ts.isParenthesizedExpression(c))return null;let d=c.expression;if(!e.ts.isAwaitExpression(d))return null;let p=d.expression;if(!e.ts.isCallExpression(p)||p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let m=p.arguments[0];if(!e.ts.isStringLiteral(m)||!e.ts.isIdentifier(l.name))return null;let h=m.text;i.filePath=await et(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=j(l.name.text),i.importName=l.name.text,i.exportName=l.name.text,i.exportType="named"}else return null;return i=X(e,i,n),i.displayFilePath=R(e,i.filePath),i.filePath&&i.exportName&&(i.id=await k(e,i.filePath,i.exportName)),i}async function xn(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await et(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=M(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(p=>!p.importClause||!p.importClause.namedBindings||!e.ts.isNamedImports(p.importClause.namedBindings)?!1:p.importClause.namedBindings.elements.some(u=>u.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await et(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=X(e,a,o),a.displayFilePath=R(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function et(e,t){return je(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function Cn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let c=0;c<i.length;c++){let d=i[c];if(e.ts.isImportDeclaration(d)){o=c;continue}if(!e.ts.isExpressionStatement(d))continue;let p=d.expression;if(!e.ts.isCallExpression(p))continue;let u=p.expression;if(!e.ts.isPropertyAccessExpression(u))continue;let m=u.expression;if(!e.ts.isIdentifier(m)||m.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(he)),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 fe(e,t){let r=[...t.statements],n=!1;for(let o=t.statements.length-1;o>=0;o--){let i=t.statements[o];if(e.ts.isImportDeclaration(i)&&i.importClause){let a=!1,s=i.importClause.namedBindings;if(s&&e.ts.isNamedImports(s)&&s.elements){let l=[...s.elements];for(let c=l.length-1;c>=0;c--){let d=l[c];if(e.ts.isImportSpecifier(d)){let p=d.name;if(p&&e.ts.isIdentifier(p)){let u=p.text;Sn(e,t,u)||l.splice(c,1)}}}if(l.length===0)a=!0;else if(s.elements.length!==l.length){let c=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(l)),d=e.ts.factory.updateImportDeclaration(i,void 0,c,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;Sn(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Sn(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 de(e,t,r,n,o,i,a){let s=null,l=null,c=null,d=-1;t=V(t),r=V(r);let p=t.find(m=>m.id===e),u=r.find(m=>m.id===e);if(n)u||(s={...V(p),inputs:V(p.inputs).map(m=>(m.isRegistered=!0,m))},d=r.length,r.push(s));else if(typeof u?.nodeIndex=="number"&&u.nodeIndex>-1){if(o)d=u.nodeIndex,l=V(u),r=r.filter(m=>m.id!==e);else if(i!=null)Po(u,i),d=u.nodeIndex,c=u;else if(a!=null){let m=u.inputs.find(h=>h.name===a.name);m&&(a.registerInput===!1?m.isRegistered=!1:(Do(m,a),m.isRegistered=!0),c=u,d=u.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:c,nodeIndex:d,components:ee(t,r)}}function ee(e,t){let r=Q([...t.map(n=>(n.isRegistered=!0,n)),...e.filter(n=>!t.some(o=>o.id===n.id)).map(n=>(n.isRegistered=!1,n))]);return r.forEach(n=>{n.inputs=n.inputs.map(dt),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=ft(n))}),r}function Po(e,t){B(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),B(t.description)?e.description=t.description:t.description===null&&delete e.description,B(t.image)?e.image=t.image:t.image===null&&delete e.image}function Do(e,t){B(t.type)&&(e.type=t.type),B(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,B(t.defaultValue)||Ne(t.defaultValue)||Ee(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,B(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function De(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),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 J(e,t,r,n,o,i,a,s){let l=await De(e),[c,d,p,u]=await Promise.all([pn(e,l),hn(e),St(e),Ie(e)]),m=c.map(S=>S.cmpInfo),h=d.components,f={components:ee(m,h),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await ye(e,f.components),f;let x=!1,g=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let S=C.map(T=>{let P=c.find(L=>L.cmpInfo.id===T);if(!P)throw new Error(`Component ${T} not found`);return P}),I=Array.from(new Set(S.map(T=>T.cmpInfo.filePath))),E=await $(e,I);for(let T of S){let P=f.components.find(v=>v.id===T.cmpInfo.id),L=await Pe(e,T,E);Z(P,L);let O=m.findIndex(v=>v.id===T.cmpInfo.id);m[O].inputs=L;let w=de(T.cmpInfo.id,m,h,r,n,o,i),N=[...g.statements];if(w.addCmpToRegistry?(N.push(nn(e,w.addCmpToRegistry)),x=!0):w.removeCmpFromRegistry?(N.splice(w.nodeIndex,1),x=!0):w.updateRegisteredCmp&&(N[w.nodeIndex]=gt(e,N[w.nodeIndex],w.updateRegisteredCmp),x=!0),x&&a){if(g=e.ts.factory.updateSourceFile(g,N),g=y(e,g,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),g=Cn(e,g,p),e.appDir){let v=w.addCmpToRegistry||w.updateRegisteredCmp;if(v){let K=A(e,e.registryPath,v.filePath);v.exportType==="default"?g=y(e,g,{defaultImport:v.importName,importPath:K}):v.exportType==="named"&&(g=y(e,g,{namedImports:[v.importName],importPath:K}))}}else g=y(e,g,{defaultImport:"dynamic",importPath:"next/dynamic"});P?.acceptsChildren&&(g=y(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=w.components,h=w.components.filter(v=>v.isRegistered)}}}if(x&&a){g=fe(e,g),g=me(e,g),e.appDir&&(g=dn(e,g));let S=F(e,g);S=W(S),e.appDir&&(S=fn(S)),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return f}async function Tn(e){let t=[],r=await Fo(e,t);return await Lo(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await bo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await No(e,e.pagesDir,t)),t}async function wn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await vo(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await Ro(e,e.pagesDir,t)),t}async function vo(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,En({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function bo(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,En({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,Io(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function Io(e){let t=e.typescriptEnabled;return`
32
+ ${e}`),e}function dn(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 Ze(e,t){return t.sort((r,n)=>{if(e.ts.isObjectLiteralExpression(r)&&e.ts.isObjectLiteralExpression(n)){let o=mn(e,r),i=mn(e,n);return o.toLocaleLowerCase().localeCompare(i.toLocaleLowerCase())}return 1})}function mn(e,t){let r=t.properties.find(n=>b(e,n)==="name");return r&&e.ts.isPropertyAssignment(r)&&e.ts.isStringLiteral(r.initializer)?r.initializer.text:"zzzz"}async function hn(e){let t=await e.readFile(e.registryPath);return t?Po(e,t):{components:[],sourceFile:D(e,"")}}async function Po(e,t){let r=D(e,t);return Do(e,r)}async function Do(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let p=c[0];if(e.ts.isCallExpression(p)){if((e.ts.isIdentifier(p.expression)&&p.expression.text)==="withChildren"){let h=p.arguments[0];if(e.ts.isCallExpression(h)){let f=await gn(e,n,h,d,!0);f&&r.push(f)}else{let f=p.arguments[0];if(e.ts.isIdentifier(f)){let x=await xn(e,t,n,f,d,!0);x&&r.push(x)}}continue}let m=await gn(e,n,p,d,!1);m&&r.push(m);continue}if(e.ts.isIdentifier(p)){let u=await xn(e,t,n,p,d,!1);u&&r.push(u);continue}}return{sourceFile:t,components:Q(r)}}async function gn(e,t,r,n,o){let i={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:t,acceptsChildren:o},a=r.arguments;if(a.length===0)return null;let s=a[0];if(!e.ts.isArrowFunction(s))return null;let l=s.body;if(e.ts.isCallExpression(l)){if(l.expression.kind!==e.ts.SyntaxKind.ImportKeyword||l.arguments.length!==1)return null;let d=l.arguments[0];if(!e.ts.isStringLiteral(d))return null;let p=d.text;i.filePath=await et(e,p),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=M(e,i.filePath),i.importName="default",i.exportName="default",i.exportType="default"}else if(e.ts.isPropertyAccessExpression(l)){let c=l.expression;if(!e.ts.isParenthesizedExpression(c))return null;let d=c.expression;if(!e.ts.isAwaitExpression(d))return null;let p=d.expression;if(!e.ts.isCallExpression(p)||p.expression.kind!==e.ts.SyntaxKind.ImportKeyword||p.arguments.length!==1)return null;let m=p.arguments[0];if(!e.ts.isStringLiteral(m)||!e.ts.isIdentifier(l.name))return null;let h=m.text;i.filePath=await et(e,h),i.relFilePath=e.relative(e.getRootDir(),i.filePath),i.importPath=_(e,i.filePath),i.name=j(l.name.text),i.importName=l.name.text,i.exportName=l.name.text,i.exportType="named"}else return null;return i=X(e,i,n),i.displayFilePath=R(e,i.filePath),i.filePath&&i.exportName&&(i.id=await k(e,i.filePath,i.exportName)),i}async function xn(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await et(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=M(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(p=>!p.importClause||!p.importClause.namedBindings||!e.ts.isNamedImports(p.importClause.namedBindings)?!1:p.importClause.namedBindings.elements.some(u=>u.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await et(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=X(e,a,o),a.displayFilePath=R(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function et(e,t){return je(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}function Cn(e,t,r){let n=!1,o=0,i=[...t.statements];for(let c=0;c<i.length;c++){let d=i[c];if(e.ts.isImportDeclaration(d)){o=c;continue}if(!e.ts.isExpressionStatement(d))continue;let p=d.expression;if(!e.ts.isCallExpression(p))continue;let u=p.expression;if(!e.ts.isPropertyAccessExpression(u))continue;let m=u.expression;if(!e.ts.isIdentifier(m)||m.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(he)),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 fe(e,t){let r=[...t.statements],n=!1;for(let o=t.statements.length-1;o>=0;o--){let i=t.statements[o];if(e.ts.isImportDeclaration(i)&&i.importClause){let a=!1,s=i.importClause.namedBindings;if(s&&e.ts.isNamedImports(s)&&s.elements){let l=[...s.elements];for(let c=l.length-1;c>=0;c--){let d=l[c];if(e.ts.isImportSpecifier(d)){let p=d.name;if(p&&e.ts.isIdentifier(p)){let u=p.text;Sn(e,t,u)||l.splice(c,1)}}}if(l.length===0)a=!0;else if(s.elements.length!==l.length){let c=e.ts.factory.updateImportClause(i.importClause,!1,i.importClause.name,e.ts.factory.createNamedImports(l)),d=e.ts.factory.updateImportDeclaration(i,void 0,c,i.moduleSpecifier,void 0);r[o]=d,n=!0}}else if(i.importClause.name&&e.ts.isIdentifier(i.importClause.name)){let l=i.importClause.name.text;Sn(e,t,l)||(a=!0)}a&&(r.splice(o,1),n=!0)}}return n?e.ts.factory.updateSourceFile(t,r):t}function Sn(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 de(e,t,r,n,o,i,a){let s=null,l=null,c=null,d=-1;t=V(t),r=V(r);let p=t.find(m=>m.id===e),u=r.find(m=>m.id===e);if(n)u||(s={...V(p),inputs:V(p.inputs).map(m=>(m.isRegistered=!0,m))},d=r.length,r.push(s));else if(typeof u?.nodeIndex=="number"&&u.nodeIndex>-1){if(o)d=u.nodeIndex,l=V(u),r=r.filter(m=>m.id!==e);else if(i!=null)vo(u,i),d=u.nodeIndex,c=u;else if(a!=null){let m=u.inputs.find(h=>h.name===a.name);m&&(a.registerInput===!1?m.isRegistered=!1:(bo(m,a),m.isRegistered=!0),c=u,d=u.nodeIndex)}}return{addCmpToRegistry:s,removeCmpFromRegistry:l,updateRegisteredCmp:c,nodeIndex:d,components:ee(t,r)}}function ee(e,t){let r=Q([...t.map(n=>(n.isRegistered=!0,n)),...e.filter(n=>!t.some(o=>o.id===n.id)).map(n=>(n.isRegistered=!1,n))]);return r.forEach(n=>{n.inputs=n.inputs.map(dt),n.inputs.sort((i,a)=>i.name.toLowerCase().localeCompare(a.name.toLowerCase()));let o=t.find(i=>i.id===n.id);o&&(o.acceptsChildren=ft(n))}),r}function vo(e,t){B(t.name)?e.name=t.name:t.name===null&&(e.name=e.importName),B(t.description)?e.description=t.description:t.description===null&&delete e.description,B(t.image)?e.image=t.image:t.image===null&&delete e.image}function bo(e,t){B(t.type)&&(e.type=t.type),B(t.friendlyName)?e.friendlyName=t.friendlyName:t.friendlyName===null&&delete e.friendlyName,B(t.defaultValue)||Ne(t.defaultValue)||Ee(t.defaultValue)?e.defaultValue=t.defaultValue:t.defaultValue===null&&delete e.defaultValue,B(t.helperText)?e.helperText=t.helperText:t.helperText===null&&delete e.helperText,t.required===!0?e.required=t.required:(t.required===null||t.required===!1)&&delete e.required}async function De(e){let t=new Set,r=async o=>{let i=await e.readdir(o);await Promise.all(i.map(async a=>{if(a.startsWith(".")||a==="node_modules")return;let s=e.join(o,a),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 J(e,t,r,n,o,i,a,s){let l=await De(e),[c,d,p,u]=await Promise.all([pn(e,l),hn(e),St(e),Ie(e)]),m=c.map(S=>S.cmpInfo),h=d.components,f={components:ee(m,h),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await ye(e,f.components),f;let x=!1,g=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let S=C.map(T=>{let P=c.find(L=>L.cmpInfo.id===T);if(!P)throw new Error(`Component ${T} not found`);return P}),I=Array.from(new Set(S.map(T=>T.cmpInfo.filePath))),E=await $(e,I);for(let T of S){let P=f.components.find(v=>v.id===T.cmpInfo.id),L=await Pe(e,T,E);Z(P,L);let O=m.findIndex(v=>v.id===T.cmpInfo.id);m[O].inputs=L;let w=de(T.cmpInfo.id,m,h,r,n,o,i),N=[...g.statements];if(w.addCmpToRegistry?(N.push(nn(e,w.addCmpToRegistry)),x=!0):w.removeCmpFromRegistry?(N.splice(w.nodeIndex,1),x=!0):w.updateRegisteredCmp&&(N[w.nodeIndex]=gt(e,N[w.nodeIndex],w.updateRegisteredCmp),x=!0),x&&a){if(g=e.ts.factory.updateSourceFile(g,N),g=y(e,g,{namedImports:["Builder","builder"],importPath:"@builder.io/react"}),g=Cn(e,g,p),e.appDir){let v=w.addCmpToRegistry||w.updateRegisteredCmp;if(v){let K=A(e,e.registryPath,v.filePath);v.exportType==="default"?g=y(e,g,{defaultImport:v.importName,importPath:K}):v.exportType==="named"&&(g=y(e,g,{namedImports:[v.importName],importPath:K}))}}else g=y(e,g,{defaultImport:"dynamic",importPath:"next/dynamic"});P?.acceptsChildren&&(g=y(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=w.components,h=w.components.filter(v=>v.isRegistered)}}}if(x&&a){g=fe(e,g),g=me(e,g),e.appDir&&(g=dn(e,g));let S=F(e,g);S=W(S),e.appDir&&(S=fn(S)),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return f}async function Tn(e){let t=[],r=await Lo(e,t);return await ko(e,r,t),e.appDir?(e.debug(`ensure builder setup for next.js app ${e.appDir}`),await No(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure builder setup for next.js pages ${e.pagesDir}`),await Fo(e,e.pagesDir,t)),t}async function wn(e){let t=[];return e.appDir?(e.debug(`ensure figma-imports setup for next.js app ${e.appDir}`),await Io(e,e.appDir,t)):e.pagesDir&&(e.debug(`ensure figma-imports setup for next.js pages ${e.pagesDir}`),await Ao(e,e.pagesDir,t)),t}async function Io(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,En({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function No(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,En({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,Ro(e));await e.writeFile(e.builderComponentPath,i),r.push({filePath:e.builderComponentPath,modifiedType:"create"})}}function Ro(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";
@@ -90,7 +90,7 @@ export default async function Page(props${n?": PageProps":""}) {
90
90
  </>
91
91
  );
92
92
  }
93
- `.trimStart()}async function No(e,t,r){let n=`[...page].${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,yn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function Ro(e,t,r){let n=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,yn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function yn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return`
93
+ `.trimStart()}async function Fo(e,t,r){let n=`[...page].${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,yn({sys:e,routePath:o,modelName:"page"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}async function Ao(e,t,r){let n=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`,o=e.join(t,n);if(!await e.exists(o)){let i=await e.formatCode(o,yn({sys:e,routePath:o,modelName:"figma-imports"}));await e.writeFile(o,i),r.push({filePath:o,modifiedType:"create"})}}function yn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled;return`
94
94
  import React from "react";
95
95
  import { useRouter } from "next/router";
96
96
  import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
@@ -164,7 +164,7 @@ export default function Page({ page }${n?": { page: BuilderContent | null }":""}
164
164
  </>
165
165
  );
166
166
  }
167
- `.trimStart()}async function Fo(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=Ao(e);if(!await e.exists(i)){let c=await e.formatCode(i,s);await e.writeFile(i,c),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function Ao(e){let t=e.typescriptEnabled,r=`
167
+ `.trimStart()}async function Lo(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=Oo(e);if(!await e.exists(i)){let c=await e.formatCode(i,s);await e.writeFile(i,c),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function Oo(e){let t=e.typescriptEnabled,r=`
168
168
  "use client"
169
169
  import React, { useState } from "react";
170
170
  import styles from "./styles.module.css";
@@ -227,13 +227,13 @@ export default Counter;
227
227
  font-size: 42px;
228
228
  text-align: center;
229
229
  }
230
- `.trimStart();return{component:r,styles:n}}async function Lo(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await J(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await J(e,o.id,!0,!1,null,null,!0,!1)}async function Pn(e){let t=await Oo(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>Tn(t),ensureFigmaImportPage:()=>wn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>J(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await J(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>J(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>J(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>J(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>J(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ie(t),setPublicApiKey:n=>Yt(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function Oo(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await ko(e),o=await St(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 St(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function ko(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 Ve(e){return await se(e,[".env"],vn)}async function Dn(e,t){jo(t);let r=await Ve(e),n=await le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function jo(e){typeof process<"u"&&(process.env[vn]=e)}var vn="PUBLIC_BUILDER_API_KEY";function bn(e,t,r){if(r.length===0)return e;let n=e.split(`
230
+ `.trimStart();return{component:r,styles:n}}async function ko(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await J(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await J(e,o.id,!0,!1,null,null,!0,!1)}async function Pn(e){let t=await jo(e);return{builderPageOptions:async()=>({templateContentId:"3de2f13211234071a4b19a17b4fbc5a7",pathname:"/builder-demo",title:"Builder + Next.js Demo Page"}),ensureBuilderSetup:()=>Tn(t),ensureFigmaImportPage:()=>wn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>J(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await J(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>J(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>J(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>J(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>J(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ie(t),setPublicApiKey:n=>Yt(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function jo(e){let t=e.getRootDir(),r=e.join(t,"src"),n=await _o(e),o=await St(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 St(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function _o(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 Ve(e){return await se(e,[".env"],vn)}async function Dn(e,t){Bo(t);let r=await Ve(e),n=await le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}function Bo(e){typeof process<"u"&&(process.env[vn]=e)}var vn="PUBLIC_BUILDER_API_KEY";function bn(e,t,r){if(r.length===0)return e;let n=e.split(`
231
231
  `),o=n.findIndex(s=>s.includes(r));if(o===-1||n.some(s=>s.includes(t[0])))return e;let a=["/**",...t.map(s=>` * ${s.trim()}`)," */"];return n.splice(o,0,...a),n.join(`
232
- `)}function tt(e,t,r){return ht(e,t,r.variableName)?t:_o(e,t,r)}function _o(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),l=e.ts.factory.createVariableStatement([s],a),c=[...t.statements,l];return e.ts.factory.updateSourceFile(t,c)}async function Nn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(a.startsWith(".")||$o.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await nt(e,o,s,i);r.push(...l)})),r}async function Rn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return Bo(e,t,n)}return null}function Bo(e,t,r){let n=D(e,r);return nt(e,null,t,n)}async function nt(e,t,r,n){r=e.normalize(r);let o=[],i=z(e,n);return await Promise.all(i.map(async a=>{let s=await Vo(e,t,r,a);s&&o.push(s)})),o}async function Vo(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=_(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=In(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let l=a.name.text;return{cmpInfo:{id:await k(e,r,l),displayFilePath:R(e,r),name:j(l),inputs:[],exportName:n.isDefaultExport?"default":l,exportType:n.isDefaultExport?"default":"named",importName:l,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=In(e,n.node);if(a)return{cmpInfo:{id:await k(e,r,"default"),displayFilePath:R(e,r),name:M(e,r),inputs:[],exportName:"default",exportType:"default",importName:we(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function In(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 $o=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function Fn(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 He(e,t.cmpInfo.filePath,null);if(!(await nt(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 Oe(e,i,r)}return[]}async function An(e){return Tt(e)}async function Tt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,zo),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var zo=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
232
+ `)}function tt(e,t,r){return ht(e,t,r.variableName)?t:Vo(e,t,r)}function Vo(e,t,r){let n=typeof r.arrayType=="string"?e.ts.factory.createArrayTypeNode(e.ts.factory.createTypeReferenceNode(r.arrayType,void 0)):void 0,o=e.ts.factory.createArrayLiteralExpression([]),i=e.ts.factory.createVariableDeclaration(r.variableName,void 0,n,o),a=e.ts.factory.createVariableDeclarationList([i],e.ts.NodeFlags.Const),s=e.ts.factory.createModifier(e.ts.SyntaxKind.ExportKeyword),l=e.ts.factory.createVariableStatement([s],a),c=[...t.statements,l];return e.ts.factory.updateSourceFile(t,c)}async function Nn(e,t){let r=[],n=t.getSourceFiles(),o=t.getTypeChecker();return await Promise.all(n.map(async i=>{let a=e.basename(i.fileName);if(a.startsWith(".")||Ko.has(a))return;let s=e.normalize(i.fileName);if(s===e.registryPath)return;let l=await nt(e,o,s,i);r.push(...l)})),r}async function Rn(e,t){if(e.extname(t).toLowerCase()===".tsx"){let n=await e.readFile(t);if(n)return $o(e,t,n)}return null}function $o(e,t,r){let n=D(e,r);return nt(e,null,t,n)}async function nt(e,t,r,n){r=e.normalize(r);let o=[],i=z(e,n);return await Promise.all(i.map(async a=>{let s=await zo(e,t,r,a);s&&o.push(s)})),o}async function zo(e,t,r,n){let o=e.relative(e.getRootDir(),r),i=_(e,r);if(e.ts.isVariableStatement(n.node))for(let a of n.node.declarationList.declarations){let s=In(e,a.initializer);if(s&&e.ts.isIdentifier(a.name)){let l=a.name.text;return{cmpInfo:{id:await k(e,r,l),displayFilePath:R(e,r),name:j(l),inputs:[],exportName:n.isDefaultExport?"default":l,exportType:n.isDefaultExport?"default":"named",importName:l,filePath:r,relFilePath:o,importPath:i},node:s}}}else if(e.ts.isCallExpression(n.node)){let a=In(e,n.node);if(a)return{cmpInfo:{id:await k(e,r,"default"),displayFilePath:R(e,r),name:M(e,r),inputs:[],exportName:"default",exportType:"default",importName:we(e,r),filePath:r,relFilePath:o,importPath:i},node:a}}return null}function In(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 Ko=new Set(["node_modules","layout.tsx","404.tsx","router-head.tsx"]);async function Fn(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 He(e,t.cmpInfo.filePath,null);if(!(await nt(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 Oe(e,i,r)}return[]}async function An(e){return Tt(e)}async function Tt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,Uo),t.push({filePath:e.registryPath,modifiedType:"create"})),t}var Uo=`import type { RegisteredComponent } from "@builder.io/sdk-qwik";
233
233
 
234
234
  export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
235
235
  ];
236
- `;async function Ln(e){await Tt(e);let t=await e.readFile(e.registryPath);return t?Ko(e,t):{components:[],sourceFile:D(e,"")}}async function Ko(e,t){let r=D(e,t);return Uo(e,r)}async function Uo(e,t){let r=[],n=ce(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await wt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function wt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await Ge(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=_(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let l=await Rn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let c=l.find(d=>d.cmpInfo.exportName===a);c&&(n.exportName=c.cmpInfo.exportName)}continue}}return n=X(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function On(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 Ce(e,t,r,n,o,i,a,s){let l=await On(e),[c,d,p]=await Promise.all([Nn(e,l),Ln(e),Ve(e)]),u=c.map(f=>f.cmpInfo),m=d.components,h={components:ee(u,m),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(u),publicApiKey:p.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let f=c.find(w=>w.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let x=d.sourceFile,g=h.components.find(w=>w.id===t),C=await Fn(e,f);Z(g,C),t=Array.isArray(t)?t[0]:t;let S=de(t,u,m,r,n,o,i),{elements:I,elmIndex:E,statementIndex:T,statement:P,variableDeclaration:L}=await Qo(e,x,f),O=!1;if(S.addCmpToRegistry?(I.push(Mo(e,S.addCmpToRegistry)),O=!0):S.removeCmpFromRegistry?(I.splice(E,1),O=!0):S.updateRegisteredCmp&&(I[E]=q(e,I[E],S.updateRegisteredCmp),O=!0),O&&a){let w=[...x.statements];w[T]=e.ts.factory.updateVariableStatement(P,P.modifiers,e.ts.factory.updateVariableDeclarationList(P.declarationList,[e.ts.factory.updateVariableDeclaration(L,L.name,L.exclamationToken,L.type,e.ts.factory.createArrayLiteralExpression(Ze(e,I)))])),x=e.ts.factory.updateSourceFile(x,w),g.exportType==="named"?x=y(e,x,{namedImports:[g.importName],importPath:A(e,e.registryPath,g.filePath)}):x=y(e,x,{defaultImport:g.importName,importPath:A(e,e.registryPath,g.filePath)}),x=y(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),x=tt(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x=fe(e,x),x=me(e,x);let N=F(e,x);N=W(N),N=bn(N,qo,"CUSTOM_COMPONENTS"),N=await e.formatCode(e.registryPath,N),await e.writeFile(e.registryPath,N)}h.components=S.components}return h}function Mo(e,t){return q(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Qo(e,t,r){let n=ce(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await wt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var qo=["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 kn(e){let t=await Wo(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>An(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ce(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Ce(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ce(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ce(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ce(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ce(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ve(t),setPublicApiKey:n=>Dn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function Wo(e){let t=await be(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 $e(e){return await se(e,[".env"],ze)}async function jn(e,t){let r=await $e(e),n=await le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ze="PUBLIC_BUILDER_KEY";async function _n(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"||Jo.has(s)||s.includes("$."))return;let l=e.normalize(a.fileName);if(l===e.remixConfigPath||l===e.registryPath||l===i)return;let c=await ue(e,o,l,a);r.push(...c)})),r}var Jo=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Bn(e){await yt(e);let t=await e.readFile(e.registryPath);return t?Yo(e,t):{components:[],sourceFile:D(e,"")}}async function Yo(e,t){let r=D(e,t);return Ho(e,r)}async function Ho(e,t){let r=[],n=ce(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Et(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function Et(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let l=await Ge(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=_(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let c=await ln(e,l.filePath);if(c&&c.length>0)if(c.length===1)n.exportName=c[0].cmpInfo.exportName;else{let d=c.find(p=>p.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=X(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function Y(e,t,r,n,o,i,a,s){let l=await De(e),[c,d,p]=await Promise.all([_n(e,l),Bn(e),$e(e)]),u=c.map(C=>C.cmpInfo),m=d.components,h={components:ee(u,m),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(u),publicApiKey:p.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await ye(e,h.components),h;let f=!1,x=d.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let C=g.map(E=>{let T=c.find(P=>P.cmpInfo.id===E);if(!T)throw new Error(`Component ${E} not found`);return T}),S=Array.from(new Set(C.map(E=>E.cmpInfo.filePath))),I=await $(e,S);for(let E of C){let T=h.components.find(G=>G.id===E.cmpInfo.id),P=await Pe(e,E,I);Z(T,P);let L=u.findIndex(G=>G.id===E.cmpInfo.id);u[L].inputs=P;let O=de(E.cmpInfo.id,u,m,r,n,o,i),{elements:w,elmIndex:N,statementIndex:v,statement:K,variableDeclaration:qe}=await Xo(e,x,E);if(O.addCmpToRegistry)w.push(Go(e,O.addCmpToRegistry)),f=!0;else if(O.removeCmpFromRegistry)w.splice(N,1),f=!0;else if(O.updateRegisteredCmp){let G=q(e,w[N],O.updateRegisteredCmp);w[N]=e.ts.factory.updateObjectLiteralExpression(G,[Vn(e,O.updateRegisteredCmp),...G.properties.slice(1)]),f=!0}if(f&&a){let G=[...x.statements];G[v]=e.ts.factory.updateVariableStatement(K,K.modifiers,e.ts.factory.updateVariableDeclarationList(K.declarationList,[e.ts.factory.updateVariableDeclaration(qe,qe.name,qe.exclamationToken,qe.type,e.ts.factory.createArrayLiteralExpression(Ze(e,w)))])),x=e.ts.factory.updateSourceFile(x,G),T.exportType==="named"?x=y(e,x,{namedImports:[T.importName],importPath:A(e,e.registryPath,T.filePath)}):x=y(e,x,{defaultImport:T.importName,importPath:A(e,e.registryPath,T.filePath)}),x=y(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),T.acceptsChildren&&(x=y(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),x=tt(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=O.components,m=O.components.filter(vr=>vr.isRegistered)}}}if(f&&a){x=fe(e,x),x=me(e,x);let C=F(e,x);C=W(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function Vn(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 Go(e,t){return q(e,e.ts.factory.createObjectLiteralExpression([Vn(e,t)],!0),t)}async function Xo(e,t,r){let n=ce(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 Et(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function $n(e){let t=[],r=await ti(e,t);return t.push(...await yt(e)),await ri(e,r),await ei(e,t),t}async function zn(e){let t=[];return await Zo(e,t),t}async function Zo(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,Kn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function ei(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,Kn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function Kn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=A(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${ze}`;return e.getFrameworks().some(l=>l.name==="@shopify/remix-oxygen")&&(s=`context.env.${ze}`),n&&(s+="!"),`
236
+ `;async function Ln(e){await Tt(e);let t=await e.readFile(e.registryPath);return t?Mo(e,t):{components:[],sourceFile:D(e,"")}}async function Mo(e,t){let r=D(e,t);return Qo(e,r)}async function Qo(e,t){let r=[],n=ce(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await wt(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function wt(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[]};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"&&e.ts.isIdentifier(o.initializer)){let a=o.initializer.text;n.name===""&&(n.name=j(a)),n.importName=a;let s=await Ge(e,e.registryPath,t,a);if(!s)continue;n.filePath=s.filePath,n.relFilePath=s.relFilePath,n.importPath=_(e,s.filePath),n.displayFilePath=s.displayFilePath,n.exportType=s.exportType;let l=await Rn(e,s.filePath);if(l&&l.length>0)if(l.length===1)n.exportName=l[0].cmpInfo.exportName;else{let c=l.find(d=>d.cmpInfo.exportName===a);c&&(n.exportName=c.cmpInfo.exportName)}continue}}return n=X(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function On(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 Ce(e,t,r,n,o,i,a,s){let l=await On(e),[c,d,p]=await Promise.all([Nn(e,l),Ln(e),Ve(e)]),u=c.map(f=>f.cmpInfo),m=d.components,h={components:ee(u,m),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(u),publicApiKey:p.envValue??void 0,devToolsVersion:e.version};if(s)return h;if(t!=null){let f=c.find(w=>w.cmpInfo.id===t);if(!f)throw new Error(`Component ${t} not found`);let x=d.sourceFile,g=h.components.find(w=>w.id===t),C=await Fn(e,f);Z(g,C),t=Array.isArray(t)?t[0]:t;let S=de(t,u,m,r,n,o,i),{elements:I,elmIndex:E,statementIndex:T,statement:P,variableDeclaration:L}=await Wo(e,x,f),O=!1;if(S.addCmpToRegistry?(I.push(qo(e,S.addCmpToRegistry)),O=!0):S.removeCmpFromRegistry?(I.splice(E,1),O=!0):S.updateRegisteredCmp&&(I[E]=q(e,I[E],S.updateRegisteredCmp),O=!0),O&&a){let w=[...x.statements];w[T]=e.ts.factory.updateVariableStatement(P,P.modifiers,e.ts.factory.updateVariableDeclarationList(P.declarationList,[e.ts.factory.updateVariableDeclaration(L,L.name,L.exclamationToken,L.type,e.ts.factory.createArrayLiteralExpression(Ze(e,I)))])),x=e.ts.factory.updateSourceFile(x,w),g.exportType==="named"?x=y(e,x,{namedImports:[g.importName],importPath:A(e,e.registryPath,g.filePath)}):x=y(e,x,{defaultImport:g.importName,importPath:A(e,e.registryPath,g.filePath)}),x=y(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/sdk-qwik",isTypeOnly:!0}),x=tt(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),x=fe(e,x),x=me(e,x);let N=F(e,x);N=W(N),N=bn(N,Jo,"CUSTOM_COMPONENTS"),N=await e.formatCode(e.registryPath,N),await e.writeFile(e.registryPath,N)}h.components=S.components}return h}function qo(e,t){return q(e,e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("component",e.ts.factory.createIdentifier(t.importName))],!0),t)}async function Wo(e,t,r){let n=ce(e,t,"CUSTOM_COMPONENTS");if(!n)throw new Error(`Exported name of the Builder registry must be "CUSTOM_COMPONENTS". Please update your Builder registry file: ${e.registryPath}`);let o=n.arrayLiteralExp.elements.filter(a=>e.ts.isObjectLiteralExpression(a)),i=-1;for(let a=0;a<o.length;a++)if((await wt(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}var Jo=["This array is used to integrate custom components within Builder.","https://www.builder.io/c/docs/custom-components-intro","",'These components will be found the "Custom Components"',"section of Builder's visual editor.",'You can also turn on "components only mode" to limit',"editing to only these components.","https://www.builder.io/c/docs/guides/components-only-mode"];async function kn(e){let t=await Yo(e);return{builderPageOptions:async()=>({templateContentId:"dc70f1d979ad416d8fd357137eb9ddfb",pathname:"/",title:"Builder + Qwik Demo Page"}),ensureBuilderSetup:()=>An(t),ensureFigmaImportPage:async()=>[],getRegistryPath:()=>t.registryPath,getRegistry:n=>Ce(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Ce(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Ce(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Ce(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Ce(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Ce(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ve(t),setPublicApiKey:n=>Dn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/sdk-qwik"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function Yo(e){let t=await be(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 $e(e){return await se(e,[".env"],ze)}async function jn(e,t){let r=await $e(e),n=await le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var ze="PUBLIC_BUILDER_KEY";async function _n(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"||Ho.has(s)||s.includes("$."))return;let l=e.normalize(a.fileName);if(l===e.remixConfigPath||l===e.registryPath||l===i)return;let c=await ue(e,o,l,a);r.push(...c)})),r}var Ho=new Set(["root.tsx","root.ts","root.jsx","root.js","_index.tsx","_index.jsx","_index.ts","_index.js"]);async function Bn(e){await yt(e);let t=await e.readFile(e.registryPath);return t?Go(e,t):{components:[],sourceFile:D(e,"")}}async function Go(e,t){let r=D(e,t);return Xo(e,r)}async function Xo(e,t){let r=[],n=ce(e,t,"CUSTOM_COMPONENTS");return n&&await Promise.all(n.arrayLiteralExp.elements.map(async(o,i)=>{let a=await Et(e,t,o);a&&(a.nodeIndex=i,r.push(a))})),{sourceFile:t,components:Q(r)}}async function Et(e,t,r){if(!e.ts.isObjectLiteralExpression(r))return null;let n={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],acceptsChildren:!1};for(let o of r.properties){if(!e.ts.isPropertyAssignment(o)||!e.ts.isIdentifier(o.name))continue;if(b(e,o)==="component"){let a,{initializer:s}=o;if(e.ts.isIdentifier(s))a=s.text;else if(e.ts.isCallExpression(s)){(e.ts.isIdentifier(s.expression)&&s.expression.text)==="withChildren"&&(n.acceptsChildren=!0);let p=s.arguments[0];e.ts.isIdentifier(p)&&(a=p.text)}if(!a)continue;n.name===""&&(n.name=j(a)),n.importName=a;let l=await Ge(e,e.registryPath,t,a);if(!l)continue;n.filePath=l.filePath,n.relFilePath=l.relFilePath,n.importPath=_(e,l.filePath),n.displayFilePath=l.displayFilePath,n.exportType=l.exportType;let c=await ln(e,l.filePath);if(c&&c.length>0)if(c.length===1)n.exportName=c[0].cmpInfo.exportName;else{let d=c.find(p=>p.cmpInfo.exportName===a);d&&(n.exportName=d.cmpInfo.exportName)}continue}}return n=X(e,n,r),n.filePath&&n.exportName&&(n.id=await k(e,n.filePath,n.exportName)),n}async function Y(e,t,r,n,o,i,a,s){let l=await De(e),[c,d,p]=await Promise.all([_n(e,l),Bn(e),$e(e)]),u=c.map(C=>C.cmpInfo),m=d.components,h={components:ee(u,m),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(u),publicApiKey:p.envValue??void 0,devToolsVersion:e.version};if(s)return h.components=await ye(e,h.components),h;let f=!1,x=d.sourceFile,g=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(g.length>0){let C=g.map(E=>{let T=c.find(P=>P.cmpInfo.id===E);if(!T)throw new Error(`Component ${E} not found`);return T}),S=Array.from(new Set(C.map(E=>E.cmpInfo.filePath))),I=await $(e,S);for(let E of C){let T=h.components.find(G=>G.id===E.cmpInfo.id),P=await Pe(e,E,I);Z(T,P);let L=u.findIndex(G=>G.id===E.cmpInfo.id);u[L].inputs=P;let O=de(E.cmpInfo.id,u,m,r,n,o,i),{elements:w,elmIndex:N,statementIndex:v,statement:K,variableDeclaration:qe}=await ei(e,x,E);if(O.addCmpToRegistry)w.push(Zo(e,O.addCmpToRegistry)),f=!0;else if(O.removeCmpFromRegistry)w.splice(N,1),f=!0;else if(O.updateRegisteredCmp){let G=q(e,w[N],O.updateRegisteredCmp);w[N]=e.ts.factory.updateObjectLiteralExpression(G,[Vn(e,O.updateRegisteredCmp),...G.properties.slice(1)]),f=!0}if(f&&a){let G=[...x.statements];G[v]=e.ts.factory.updateVariableStatement(K,K.modifiers,e.ts.factory.updateVariableDeclarationList(K.declarationList,[e.ts.factory.updateVariableDeclaration(qe,qe.name,qe.exclamationToken,qe.type,e.ts.factory.createArrayLiteralExpression(Ze(e,w)))])),x=e.ts.factory.updateSourceFile(x,G),T.exportType==="named"?x=y(e,x,{namedImports:[T.importName],importPath:A(e,e.registryPath,T.filePath)}):x=y(e,x,{defaultImport:T.importName,importPath:A(e,e.registryPath,T.filePath)}),x=y(e,x,{namedImports:["RegisteredComponent"],importPath:"@builder.io/react",isTypeOnly:!0}),T.acceptsChildren&&(x=y(e,x,{namedImports:["withChildren"],importPath:"@builder.io/react"})),x=tt(e,x,{variableName:"CUSTOM_COMPONENTS",arrayType:"RegisteredComponent"}),h.components=O.components,m=O.components.filter(vr=>vr.isRegistered)}}}if(f&&a){x=fe(e,x),x=me(e,x);let C=F(e,x);C=W(C),C=await e.formatCode(e.registryPath,C),await e.writeFile(e.registryPath,C)}return h}function Vn(e,t){let r=e.ts.factory.createIdentifier(t.importName),n=t.acceptsChildren?e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("withChildren"),void 0,[r]):r;return e.ts.factory.createPropertyAssignment("component",n)}function Zo(e,t){return q(e,e.ts.factory.createObjectLiteralExpression([Vn(e,t)],!0),t)}async function ei(e,t,r){let n=ce(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 Et(e,t,o[a]))?.id===r.cmpInfo.id){i=a;break}return{...n,elements:o,elmIndex:i}}async function $n(e){let t=[],r=await ri(e,t);return t.push(...await yt(e)),await ii(e,r),await ni(e,t),t}async function zn(e){let t=[];return await ti(e,t),t}async function ti(e,t){let r=`figma-imports.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureFigmaImportRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureFigmaImportRoute, hasRoute: ${o}`);let i=await e.formatCode(n,Kn({sys:e,routePath:n,modelName:"figma-imports"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}async function ni(e,t){let r=`$.${e.typescriptEnabled?"tsx":"jsx"}`;e.hasLocaleParam&&(e.debug("remixEnsureAppRoute, hasLocaleParam"),r=`($locale).${r}`);let n=e.join(e.routesDir,r),o=await e.exists(n);e.debug(`remixEnsureAppRoute, hasRoute: ${o}`);let i=await e.formatCode(n,Kn({sys:e,routePath:n,modelName:"page"}));await e.writeFile(n,i),t.push({filePath:n,modifiedType:o?"update":"create"})}function Kn({sys:e,routePath:t,modelName:r}){let n=e.typescriptEnabled,o=A(e,t,e.registryPath),i="",a="";n&&(i="import type { LoaderArgs } from '@remix-run/server-runtime';",a=": LoaderArgs");let s=`process.env.${ze}`;return e.getFrameworks().some(l=>l.name==="@shopify/remix-oxygen")&&(s=`context.env.${ze}`),n&&(s+="!"),`
237
237
  import { BuilderComponent, builder } from "@builder.io/react";
238
238
  import { useLoaderData } from "@remix-run/react";
239
239
  import { CUSTOM_COMPONENTS } from ${JSON.stringify(o)};
@@ -294,7 +294,7 @@ declare global {
294
294
  }
295
295
  }
296
296
  `:""}
297
- `}async function ti(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=ni(e),c=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${c}`),!c){let p=await e.formatCode(i,s);await e.writeFile(i,p),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function ni(e){let t=e.typescriptEnabled,r=`
297
+ `}async function ri(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=oi(e),c=await e.exists(i);if(e.debug(`remixEnsureCounterComponent, hasCounterCmp: ${c}`),!c){let p=await e.formatCode(i,s);await e.writeFile(i,p),t.push({filePath:i,modifiedType:"create"})}let d=await e.exists(a);return e.debug(`remixEnsureCounterComponent, hasCounterStyles: ${d}`),d||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function oi(e){let t=e.typescriptEnabled,r=`
298
298
  import { useState } from "react";
299
299
  import styles from "./styles.module.css";
300
300
  ${t?`
@@ -357,19 +357,18 @@ export default Counter;
357
357
  font-size: 42px;
358
358
  text-align: center;
359
359
  }
360
- `.trimStart();return{component:r,styles:n}}async function ri(e,t){let n=(await Y(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await Y(e,n.id,!0,!1,null,null,!0,!1)}async function yt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,oi(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function oi(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/react";
360
+ `.trimStart();return{component:r,styles:n}}async function ii(e,t){let n=(await Y(e,null,!1,!1,null,null,!1,!1)).components.find(o=>o.filePath===t);n&&await Y(e,n.id,!0,!1,null,null,!0,!1)}async function yt(e){let t=[];return await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,ai(e)),t.push({filePath:e.registryPath,modifiedType:"create"})),t}function ai(e){return e.typescriptEnabled?`import type { RegisteredComponent } from "@builder.io/react";
361
361
 
362
362
  export const CUSTOM_COMPONENTS: RegisteredComponent[] = [
363
363
  ];`:`export const CUSTOM_COMPONENTS = [
364
364
  ];
365
- `}async function Un(e){let t=await ii(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:()=>$n(t),ensureFigmaImportPage:()=>zn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>Y(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Y(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Y(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Y(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Y(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Y(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>$e(t),setPublicApiKey:n=>jn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function ii(e){let t=await li(e),r=await ci(e),n=e.dirname(r),o=e.join(n,"components"),i=await ai(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 si(e,r)}}function ai(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function si(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function li(e){let t=["remix.config.ts","remix.config.js","vite.config.ts","vite.config.js"];for(let r of t){let n=e.join(e.getRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find Remix config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}async function ci(e){let t=await be(e,e.getRootDir(),"routes");if(t)return t;throw new Error(`Could not find Remix "routes" directory in "${e.getRootDir()}". Please ensure this command is ran from within your Remix project's directory.`)}async function Ke(e){let t=[".env"],r=e.configType==="vite"?rt:Pt;return await se(e,t,r)}async function Mn(e,t){let r=await Ke(e),n=await le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var rt="VITE_PUBLIC_BUILDER_KEY",Pt="YOUR_PUBLIC_BUILDER_KEY";function Qn(e,t){let r=`Builder.registerComponent(
365
+ `}async function Un(e){let t=await si(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:()=>$n(t),ensureFigmaImportPage:()=>zn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>Y(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await Y(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>Y(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>Y(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>Y(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>Y(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>$e(t),setPublicApiKey:n=>jn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function si(e){let t=await pi(e),r=await ui(e),n=e.dirname(r),o=e.join(n,"components"),i=await li(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 ci(e,r)}}function li(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function ci(e,t){return(await e.readdir(t)).some(n=>n.startsWith("($locale)."))}async function pi(e){let t=["remix.config.ts","remix.config.js","vite.config.ts","vite.config.js"];for(let r of t){let n=e.join(e.getRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find Remix config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}async function ui(e){let t=await be(e,e.getRootDir(),"routes");if(t)return t;throw new Error(`Could not find Remix "routes" directory in "${e.getRootDir()}". Please ensure this command is ran from within your Remix project's directory.`)}async function Ke(e){let t=[".env"],r=e.configType==="vite"?rt:Pt;return await se(e,t,r)}async function Mn(e,t){let r=await Ke(e),n=await le(e,r.file,r.envKey,t);return{...r,modifiedType:n}}var rt="VITE_PUBLIC_BUILDER_KEY",Pt="YOUR_PUBLIC_BUILDER_KEY";function Qn(e,t){let r=`Builder.registerComponent(
366
366
  `;r+=` ${t.importName},
367
367
  `,r+=` {
368
368
  name: "${t.name}",
369
369
  }
370
- `,r+=");";let n=We(e,r);return Dt(e,n,t)}function Dt(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=q(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function Wn(e){let t=await e.readFile(e.registryPath);return t?pi(e,t):{components:[],sourceFile:D(e,"")}}async function pi(e,t){let r=D(e,t);return ui(e,r)}async function ui(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let p=c[0];if(e.ts.isIdentifier(p)){let u=await mi(e,t,n,p,d,!1);u&&r.push(u);continue}}return{sourceFile:t,components:Q(r)}}async function mi(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await qn(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=M(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(p=>!p.importClause||!p.importClause.namedBindings||!e.ts.isNamedImports(p.importClause.namedBindings)?!1:p.importClause.namedBindings.elements.some(u=>u.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await qn(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=X(e,a,o),a.displayFilePath=R(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function qn(e,t){return je(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function H(e,t,r,n,o,i,a,s){let l=await De(e),[c,d,p,u]=await Promise.all([cn(e,l),Wn(e),vt(e),Ke(e)]),m=c.map(S=>S.cmpInfo),h=d.components,f={components:ee(m,h),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await ye(e,f.components),f;let x=!1,g=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let S=C.map(T=>{let P=c.find(L=>L.cmpInfo.id===T);if(!P)throw new Error(`Component ${T} not found`);return P}),I=Array.from(new Set(S.map(T=>T.cmpInfo.filePath))),E=await $(e,I);for(let T of S){let P=f.components.find(v=>v.id===T.cmpInfo.id),L=await Pe(e,T,E);Z(P,L);let O=m.findIndex(v=>v.id===T.cmpInfo.id);m[O].inputs=L;let w=de(T.cmpInfo.id,m,h,r,n,o,i),N=[...g.statements];if(w.addCmpToRegistry?(N.push(Qn(e,w.addCmpToRegistry)),x=!0):w.removeCmpFromRegistry?(N.splice(w.nodeIndex,1),x=!0):w.updateRegisteredCmp&&(N[w.nodeIndex]=Dt(e,N[w.nodeIndex],w.updateRegisteredCmp),x=!0),x&&a){g=e.ts.factory.updateSourceFile(g,N),g=y(e,g,{namedImports:["Builder","builder"],importPath:"@builder.io/react"});let v=w.addCmpToRegistry||w.updateRegisteredCmp;if(v){let K=A(e,e.registryPath,v.filePath);v.exportType==="default"?g=y(e,g,{defaultImport:v.importName,importPath:K}):v.exportType==="named"&&(g=y(e,g,{namedImports:[v.importName],importPath:K}))}P?.acceptsChildren&&(g=y(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=w.components,h=w.components.filter(K=>K.isRegistered)}}}if(x&&a){g=fe(e,g),g=me(e,g);let S=F(e,g);S=W(S),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return f}async function Jn(e){let t=[],r=await xi(e,t);if(await gi(e,r,t),!await e.exists(e.builderComponentPath)){let n=await e.formatCode(e.builderComponentPath,fi(e));await e.writeFile(e.builderComponentPath,n),t.push({filePath:e.builderComponentPath,modifiedType:"create"})}if(!await e.exists(e.builderPageCssPath)){let n=await e.formatCode(e.builderPageCssPath,di());await e.writeFile(e.builderPageCssPath,n),t.push({filePath:e.builderPageCssPath,modifiedType:"create"})}return t}async function Yn(e){return[]}function fi(e){let t=e.typescriptEnabled;return`
371
- "use client";
372
- import { useEffect, useState } from "react";
370
+ `,r+=");";let n=We(e,r);return Dt(e,n,t)}function Dt(e,t,r){if(!e.ts.isExpressionStatement(t))return t;let n=t.expression;if(!e.ts.isCallExpression(n))return t;let o=[...n.arguments];if(o.length<2)return t;let i=o[1];return e.ts.isObjectLiteralExpression(i)?(o[1]=q(e,i,r),e.ts.factory.updateExpressionStatement(t,e.ts.factory.updateCallExpression(n,n.expression,n.typeArguments,o))):t}async function Wn(e){let t=await e.readFile(e.registryPath);return t?mi(e,t):{components:[],sourceFile:D(e,"")}}async function mi(e,t){let r=D(e,t);return fi(e,r)}async function fi(e,t){let r=[];for(let n=0;n<t.statements.length;n++){let o=t.statements[n];if(!e.ts.isExpressionStatement(o))continue;let i=o.expression;if(!e.ts.isCallExpression(i))continue;let a=i.expression;if(!e.ts.isPropertyAccessExpression(a))continue;let s=a.expression;if(!e.ts.isIdentifier(s)||s.text!=="Builder"||a.name.text!=="registerComponent")continue;let c=i.arguments;if(c.length<2)continue;let d=c[1];if(!e.ts.isObjectLiteralExpression(d))continue;let p=c[0];if(e.ts.isIdentifier(p)){let u=await di(e,t,n,p,d,!1);u&&r.push(u);continue}}return{sourceFile:t,components:Q(r)}}async function di(e,t,r,n,o,i){let a={id:"",name:"",displayFilePath:"",exportName:"",importName:"",filePath:"",relFilePath:"",importPath:"",inputs:[],nodeIndex:r,acceptsChildren:i},s=t.statements.filter(c=>e.ts.isImportDeclaration(c)),l=s.find(c=>c.importClause&&c.importClause.name?.text===n.text);if(l){let c=l.moduleSpecifier;if(!e.ts.isStringLiteral(c))return null;a.filePath=await qn(e,c.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=M(e,a.filePath),a.importName=n.text,a.exportName="default",a.exportType="default"}else{let c=s.find(p=>!p.importClause||!p.importClause.namedBindings||!e.ts.isNamedImports(p.importClause.namedBindings)?!1:p.importClause.namedBindings.elements.some(u=>u.name.text===n.text));if(!c)return null;let d=c.moduleSpecifier;if(!e.ts.isStringLiteral(d))return null;a.filePath=await qn(e,d.text),a.relFilePath=e.relative(e.getRootDir(),a.filePath),a.importPath=_(e,a.filePath),a.name=j(n.text),a.importName=n.text,a.exportName=n.text,a.exportType="named"}return a=X(e,a,o),a.displayFilePath=R(e,a.filePath),a.filePath&&a.exportName&&(a.id=await k(e,a.filePath,a.exportName)),a}function qn(e,t){return je(e,e.normalize(e.resolve(e.dirname(e.registryPath),t)))}async function H(e,t,r,n,o,i,a,s){let l=await De(e),[c,d,p,u]=await Promise.all([cn(e,l),Wn(e),vt(e),Ke(e)]),m=c.map(S=>S.cmpInfo),h=d.components,f={components:ee(m,h),registryPath:e.registryPath,registryDisplayPath:R(e,e.registryPath),frameworks:e.getFrameworks(),dependencies:pe(m),publicApiKey:u.envValue??void 0,devToolsVersion:e.version};if(s)return f.components=await ye(e,f.components),f;let x=!1,g=d.sourceFile,C=Array.isArray(t)?t:typeof t=="string"?[t]:[];if(C.length>0){let S=C.map(T=>{let P=c.find(L=>L.cmpInfo.id===T);if(!P)throw new Error(`Component ${T} not found`);return P}),I=Array.from(new Set(S.map(T=>T.cmpInfo.filePath))),E=await $(e,I);for(let T of S){let P=f.components.find(v=>v.id===T.cmpInfo.id),L=await Pe(e,T,E);Z(P,L);let O=m.findIndex(v=>v.id===T.cmpInfo.id);m[O].inputs=L;let w=de(T.cmpInfo.id,m,h,r,n,o,i),N=[...g.statements];if(w.addCmpToRegistry?(N.push(Qn(e,w.addCmpToRegistry)),x=!0):w.removeCmpFromRegistry?(N.splice(w.nodeIndex,1),x=!0):w.updateRegisteredCmp&&(N[w.nodeIndex]=Dt(e,N[w.nodeIndex],w.updateRegisteredCmp),x=!0),x&&a){g=e.ts.factory.updateSourceFile(g,N),g=y(e,g,{namedImports:["Builder","builder"],importPath:"@builder.io/react"});let v=w.addCmpToRegistry||w.updateRegisteredCmp;if(v){let K=A(e,e.registryPath,v.filePath);v.exportType==="default"?g=y(e,g,{defaultImport:v.importName,importPath:K}):v.exportType==="named"&&(g=y(e,g,{namedImports:[v.importName],importPath:K}))}P?.acceptsChildren&&(g=y(e,g,{namedImports:["withChildren"],importPath:"@builder.io/react"})),f.components=w.components,h=w.components.filter(K=>K.isRegistered)}}}if(x&&a){g=fe(e,g),g=me(e,g);let S=F(e,g);S=W(S),S=await e.formatCode(e.registryPath,S),await e.writeFile(e.registryPath,S)}return f}async function Jn(e){let t=[],r=await Ci(e,t);if(await hi(e,r,t),!await e.exists(e.builderComponentPath)){let n=await e.formatCode(e.builderComponentPath,gi(e));await e.writeFile(e.builderComponentPath,n),t.push({filePath:e.builderComponentPath,modifiedType:"create"})}if(!await e.exists(e.builderPageCssPath)){let n=await e.formatCode(e.builderPageCssPath,xi());await e.writeFile(e.builderPageCssPath,n),t.push({filePath:e.builderPageCssPath,modifiedType:"create"})}return t}async function Yn(e){return[]}function gi(e){let t=e.typescriptEnabled;return`
371
+ import React from "react";
373
372
  import { BuilderComponent, builder, useIsPreviewing } from "@builder.io/react";
374
373
  import ${JSON.stringify(A(e,e.builderComponentPath,e.registryPath))};
375
374
  import "./builder.css";
@@ -379,11 +378,11 @@ ${e.configType==="vite"?`builder.init(import.meta.env.${rt}${t?"!":""}`:`builder
379
378
 
380
379
  export default function BuilderPage() {
381
380
  const isPreviewingInBuilder = useIsPreviewing();
382
- const [notFound, setNotFound] = useState(false);
383
- const [content, setContent] = useState(null);
381
+ const [notFound, setNotFound] = React.useState(false);
382
+ const [content, setContent] = React.useState(null);
384
383
 
385
384
  // get the page content from Builder
386
- useEffect(() => {
385
+ React.useEffect(() => {
387
386
  async function fetchContent() {
388
387
  const content = await builder
389
388
  .get("page", {
@@ -420,7 +419,7 @@ export default function BuilderPage() {
420
419
  </>
421
420
  );
422
421
  }
423
- `.trimStart()}function di(){return`
422
+ `.trimStart()}function xi(){return`
424
423
  a {
425
424
  font-weight: 500;
426
425
  color: #000;
@@ -439,7 +438,7 @@ export default function BuilderPage() {
439
438
  padding: 0px;
440
439
  }
441
440
 
442
- `.trimStart()}async function gi(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await H(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await H(e,o.id,!0,!1,null,null,!0,!1)}async function xi(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=hi(e);if(!await e.exists(i)){let c=await e.formatCode(i,s);await e.writeFile(i,c),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function hi(e){let t=e.typescriptEnabled,r=`
441
+ `.trimStart()}async function hi(e,t,r){await e.exists(e.registryPath)||(await e.writeFile(e.registryPath,""),r.push({filePath:e.registryPath,modifiedType:"create"}));let o=(await H(e,null,!1,!1,null,null,!1,!1)).components.find(i=>i.filePath===t);o&&await H(e,o.id,!0,!1,null,null,!0,!1)}async function Ci(e,t){let n=e.typescriptEnabled?"tsx":"jsx",o=e.join(e.componentsDir,"Counter"),i=e.join(o,`Counter.${n}`),a=e.join(o,"styles.module.css"),{component:s,styles:l}=Si(e);if(!await e.exists(i)){let c=await e.formatCode(i,s);await e.writeFile(i,c),t.push({filePath:i,modifiedType:"create"})}return await e.exists(a)||(await e.writeFile(a,l),t.push({filePath:a,modifiedType:"create"})),i}function Si(e){let t=e.typescriptEnabled,r=`
443
442
  "use client"
444
443
  import React, { useState } from "react";
445
444
  import styles from "./styles.module.css";
@@ -502,13 +501,13 @@ export default Counter;
502
501
  font-size: 42px;
503
502
  text-align: center;
504
503
  }
505
- `.trimStart();return{component:r,styles:n}}async function Hn(e){let t=await Ci(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>Jn(t),ensureFigmaImportPage:()=>Yn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>H(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await H(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>H(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>H(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>H(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>H(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ke(t),setPublicApiKey:n=>Mn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function Ci(e){let t=await Si(e),r=e.getRootDir(),n=e.join(r,"src"),o=await vt(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,builderPageCssPath:"",configType:""};return t.includes("webpack.config")&&(a.configType="webpack"),t.includes("vite.config")&&(a.configType="vite"),await e.exists(n)?(a.srcDir=n,a.componentsDir=e.join(n,"components"),a.registryPath=e.join(n,i),a.builderComponentPath=e.join(a.srcDir,`builder.${o?"tsx":"jsx"}`),a.builderPageCssPath=e.join(a.srcDir,"builder.css")):(a.componentsDir=e.join(r,"components"),a.registryPath=e.join(r,i),a.builderComponentPath=e.join(r,`builder.${o?"tsx":"jsx"}`),a.builderPageCssPath=e.join(r,"builder.css")),a}function vt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function Si(e){let t=["vite.config.ts","vite.config.js","webpack.config.js","webpack.config.ts"];for(let r of t){let n=e.join(e.getRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find React config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}var ct=Lr(cr(),1);async function pr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:U(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:V(i.inputs)};return V(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,ct.compress)(n);return btoa(JSON.stringify(o))}async function ur(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,ct.decompress)(o),a=V(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let l=U(e.normalize(s.filePath)),c=n.components.find(p=>U(p.filePath).endsWith(l)&&p.exportName===s.exportName);if(!c){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${c.id})`,c.filePath),await t.registerComponent({cmpId:c.id});for(let p of s.inputs)e.debug(`set input (${c.id})`),await t.setRegisteredComponentInput({cmpId:c.id,name:p.name,type:p.type,required:p.required,defaultValue:p.defaultValue,friendlyName:p.friendlyName,helperText:p.helperText});e.debug(`set input (${c.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:c.id,name:s.name,image:s.image,description:s.description});a=V(d)}return a}var Ui={"@builder.io/qwik-city":kn,next:Pn,"@remix-run/react":Un,react:Hn};async function Mi(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 xe(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=Ui[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>pr(e,n),importRegistry:i=>ur(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function mr(e){function t(p){if(typeof p!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(p))}function r(p,u){let m="",h=0,f=-1,x=0,g;for(let C=0;C<=p.length;++C){if(C<p.length)g=p.charCodeAt(C);else{if(g===47)break;g=47}if(g===47){if(!(f===C-1||x===1))if(f!==C-1&&x===2){if(m.length<2||h!==2||m.charCodeAt(m.length-1)!==46||m.charCodeAt(m.length-2)!==46){if(m.length>2){let S=m.lastIndexOf("/");if(S!==m.length-1){S===-1?(m="",h=0):(m=m.slice(0,S),h=m.length-1-m.lastIndexOf("/")),f=C,x=0;continue}}else if(m.length===2||m.length===1){m="",h=0,f=C,x=0;continue}}u&&(m.length>0?m+="/..":m="..",h=2)}else m.length>0?m+="/"+p.slice(f+1,C):m=p.slice(f+1,C),h=C-f-1;f=C,x=0}else g===46&&x!==-1?++x:x=-1}return m}let n=function(...u){let m="",h=!1;for(let f=u.length-1;f>=-1&&!h;f--){let x;f>=0?x=u[f]:e.cwd?x=e.cwd():x="/",t(x),x.length!==0&&(m=x+"/"+m,h=x.charCodeAt(0)===47)}return m=r(m,!h),h?m.length>0?"/"+m:"/":m.length>0?m:"."},o=function(u){if(t(u),u.length===0)return".";let m=u.charCodeAt(0)===47,h=u.charCodeAt(u.length-1)===47;return u=r(u,!m),u.length===0&&!m&&(u="."),u.length>0&&h&&(u+="/"),m?"/"+u:u};return{relative:function(u,m){if(t(u),t(m),u===m||(u=n(u),m=n(m),u===m))return"";let h=1;for(;h<u.length&&u.charCodeAt(h)===47;++h);let f=u.length,x=f-h,g=1;for(;g<m.length&&m.charCodeAt(g)===47;++g);let S=m.length-g,I=x<S?x:S,E=-1,T=0;for(;T<=I;++T){if(T===I){if(S>I){if(m.charCodeAt(g+T)===47)return m.slice(g+T+1);if(T===0)return m.slice(g+T)}else x>I&&(u.charCodeAt(h+T)===47?E=T:T===0&&(E=0));break}let L=u.charCodeAt(h+T),O=m.charCodeAt(g+T);if(L!==O)break;L===47&&(E=T)}let P="";for(T=h+E+1;T<=f;++T)(T===f||u.charCodeAt(T)===47)&&(P.length===0?P+="..":P+="/..");return P.length>0?P+m.slice(g+E):(g+=E,m.charCodeAt(g)===47&&++g,m.slice(g))},resolve:n,join:function(...u){if(u.length===0)return".";let m;for(let h=0;h<u.length;++h){let f=u[h];t(f),f.length>0&&(m===void 0?m=f:m+="/"+f)}return m===void 0?".":o(m)},isAbsolute:function(u){return t(u),u.length>0&&u.charCodeAt(0)===47},basename:function(u,m){if(m!==void 0&&typeof m!="string")throw new TypeError('"ext" argument must be a string');t(u);let h=0,f=-1,x=!0,g;if(m!==void 0&&m.length>0&&m.length<=u.length){if(m.length===u.length&&m===u)return"";let C=m.length-1,S=-1;for(g=u.length-1;g>=0;--g){let I=u.charCodeAt(g);if(I===47){if(!x){h=g+1;break}}else S===-1&&(x=!1,S=g+1),C>=0&&(I===m.charCodeAt(C)?--C===-1&&(f=g):(C=-1,f=S))}return h===f?f=S:f===-1&&(f=u.length),u.slice(h,f)}else{for(g=u.length-1;g>=0;--g)if(u.charCodeAt(g)===47){if(!x){h=g+1;break}}else f===-1&&(x=!1,f=g+1);return f===-1?"":u.slice(h,f)}},normalize:o,dirname:function(u){if(t(u),u.length===0)return".";let m=u.charCodeAt(0),h=m===47,f=-1,x=!0;for(let g=u.length-1;g>=1;--g)if(m=u.charCodeAt(g),m===47){if(!x){f=g;break}}else x=!1;return f===-1?h?"/":".":h&&f===1?"//":u.slice(0,f)},extname:function(u){t(u);let m=-1,h=0,f=-1,x=!0,g=0;for(let C=u.length-1;C>=0;--C){let S=u.charCodeAt(C);if(S===47){if(!x){h=C+1;break}continue}f===-1&&(x=!1,f=C+1),S===46?m===-1?m=C:g!==1&&(g=1):m!==-1&&(g=-1)}return m===-1||f===-1||g===0||g===1&&m===f-1&&m===h+1?"":u.slice(m,f)}}}async function Qi(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=mr({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[x]of o)if((x+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),l=f=>{f=i(f);let x=f===t()?f:f+"/",g=x.split("/").length-1,C=[];for(let[S]of o)if(S.split("/").slice(0,g).join("/")+"/"===x){let T=S.split("/")[g];T&&!C.includes(T)&&C.push(T)}return C.sort()},c=f=>{f=i(f);let x=o.get(f);return typeof x=="string"?x:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),p=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),S=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(S)).map(I=>I.toString(16).padStart(2,"0")).join("")}let x=0;for(let g=0;g<f.length;g++){let C=f.charCodeAt(g);x=(x<<5)-x+C,x|=0}return Number(Math.abs(x)).toString(36)},u=new Set,m={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>l(f),readdirSync:l,readFile:async f=>c(f),readFileSync:c,stat:async f=>d(f),statSync:d,writeFile:async(f,x)=>{f=i(f),o.set(f,x);let g={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of u)await C(g)},hash:p,getDeviceId:async()=>typeof navigator<"u"?p(navigator.userAgent):"",formatCode:async(f,x)=>x,on:(f,x)=>{f==="change"&&u.add(x)},off:(f,x)=>{f==="change"&&u.delete(x)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0"},h=await xe(m);return m.getFrameworks=e.getFrameworks?e.getFrameworks:()=>h,m}async function fr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(dr(e,n))return o;let a=z(e,n,"cjs"),s=z(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let p=d.statement;if(!e.ts.isVariableStatement(p))throw new Error(`Expected an export assignment from ${t}`);let u=d.statement;if(e.ts.isVariableStatement(u)){let m=[...u.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let h=m[0];if(!h.initializer)throw new Error("Expected an initializer on the declaration");let f=h.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let x="BuilderDevTools()",g=[...n.statements],C=g.indexOf(u);return g[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(x),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,g),n=y(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let l=a[0];if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let p=d.expression;if(!e.ts.isBinaryExpression(p))throw new Error("Expected a binary expression for the default export");let u=$t(e,n);n=u.sourceFile;let m=[...n.statements],h=m.indexOf(d);return m[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(p,p.left,p.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[p.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=F(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let p=d[0];if(!p.initializer)throw new Error("Expected an initializer on the declaration");let u=p.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let m=$t(e,n);n=m.sourceFile;let h=[...n.statements],f=h.indexOf(c);return h[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(l.node)){let d=l.node,p=l.statement;if(!e.ts.isExpressionStatement(p))throw new Error("Expected an expression statement for the default export");let u=p.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 f=[...h.statements],x=f.findIndex(E=>e.ts.isReturnStatement(E));if(x===-1)throw new Error("Expected a return statement on the next config function");let g=f[x],C=$t(e,n);n=C.sourceFile,f[x]=e.ts.factory.updateReturnStatement(g,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[g.expression]));let S=[...n.statements],I=S.indexOf(p);return S[I]=e.ts.factory.updateExpressionStatement(p,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(h,f)))),n=e.ts.factory.updateSourceFile(n,S),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function dr(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 $t(e,t){let r=dr(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function hr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Cr(e,n))return o;let a=z(e,n,"cjs"),s=z(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let l=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let p=d.statement;if(!e.ts.isExportAssignment(p))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(p.expression)){let u="builderDevTools()",m=qi(e,p.expression);if(!m)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u),void 0,[m]),f=[...n.statements],x=f.indexOf(p);return f[x]=e.ts.factory.updateExportAssignment(p,p.modifiers,h),n=e.ts.factory.updateSourceFile(n,f),n=y(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=F(e,n),o.hasContentUpdates=!0,o}}if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let p=d.expression;if(!e.ts.isBinaryExpression(p))throw new Error("Expected a binary expression for the default export");let u=gr(e,n);n=u.sourceFile;let m=[...n.statements],h=m.indexOf(d);return m[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(p,p.left,p.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[p.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=F(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let p=d[0];if(!p.initializer)throw new Error("Expected an initializer on the declaration");let u=p.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let m=gr(e,n);n=m.sourceFile;let h=[...n.statements],f=h.indexOf(c);return h[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function Cr(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 gr(e,t){let r=Cr(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 qi(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=xr(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=xr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function xr(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 Tr(e,t,r){let n=D(e,r),o=z(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let l=[...i.node.arguments];if(l.length===0)throw new Error("Expected an argument in defineConfig()");let c=l[0];if(e.ts.isArrowFunction(c)){let d=Wi(e,c);if(!d)return s;l[0]=e.ts.factory.updateArrowFunction(c,c.modifiers,c.typeParameters,c.parameters,c.type,c.equalsGreaterThanToken,d);let p=[...n.statements],u=p.indexOf(a);return p[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,p),n=y(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(c)){let d=zt(e,c);if(!d)return s;let p=[...n.statements],u=p.indexOf(a);return p[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,p),n=y(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let l=zt(e,a.expression);if(!l)return s;let c=[...n.statements],d=c.indexOf(a);return c[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,l),n=e.ts.factory.updateSourceFile(n,c),n=y(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Wi(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=zt(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function zt(e,t){if(Hi(e)){let i=Ji(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Sr(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Sr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Sr(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function Ji(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Yi(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=Kt(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function Yi(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Kt(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=Kt(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function Kt(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Hi(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function wr(e,t,r){return console.log("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}var yr=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:fr},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:Tr},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:hr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:wr}];async function Pr(e){let t=e.resolve("/");for(let n of yr)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 xe(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,Er),{id:"next",filePath:n,content:Er}}return null}async function Gi(e){let t=await Pr(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await yr.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=W(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var Er=`
504
+ `.trimStart();return{component:r,styles:n}}async function Hn(e){let t=await Ti(e);return{builderPageOptions:async()=>({templateContentId:"2e36438034894a8abf279ea9e6d3596f",pathname:"/builder-demo",title:"Builder + React Demo Page"}),ensureBuilderSetup:()=>Jn(t),ensureFigmaImportPage:()=>Yn(t),getRegistryPath:()=>t.registryPath,getRegistry:n=>H(t,null,!1,!1,null,null,!1,!!n?.readAllInputTypes),loadComponent:async n=>{let o=await H(t,n.cmpId,!1,!1,null,null,!1,!1);return{...o,component:o.components.find(i=>i.id===n.cmpId)}},registerComponent:n=>H(t,n.cmpId,!0,!1,null,null,!0,!1),setRegisteredComponentInfo:n=>H(t,n.cmpId,!1,!1,n,null,!0,!1),setRegisteredComponentInput:n=>H(t,n.cmpId,!1,!1,null,n,!0,!1),unregisterComponent:n=>H(t,n.cmpId,!1,!0,null,null,!0,!1),getPublicApiKey:()=>Ke(t),setPublicApiKey:n=>Mn(t,n.publicApiKey),getDependencies:()=>[{name:"@builder.io/dev-tools"},{name:"@builder.io/react"},{name:"@builder.io/sdk"}],getDevRunCommand:()=>"dev",getCache:()=>ie(t),setCache:n=>ae(t,n)}}async function Ti(e){let t=await wi(e),r=e.getRootDir(),n=e.join(r,"src"),o=await vt(e),i=`builder-registry.${o?"ts":"js"}`,a={...e,srcDir:null,builderComponentPath:"",componentsDir:"",registryPath:"",reactConfigPath:t,typescriptEnabled:o,builderPageCssPath:"",configType:""};return t.includes("webpack.config")&&(a.configType="webpack"),t.includes("vite.config")&&(a.configType="vite"),await e.exists(n)?(a.srcDir=n,a.componentsDir=e.join(n,"components"),a.registryPath=e.join(n,i),a.builderComponentPath=e.join(a.srcDir,`builder.${o?"tsx":"jsx"}`),a.builderPageCssPath=e.join(a.srcDir,"builder.css")):(a.componentsDir=e.join(r,"components"),a.registryPath=e.join(r,i),a.builderComponentPath=e.join(r,`builder.${o?"tsx":"jsx"}`),a.builderPageCssPath=e.join(r,"builder.css")),a}function vt(e){let t=e.join(e.getRootDir(),"tsconfig.json");return e.exists(t)}async function wi(e){let t=["vite.config.ts","vite.config.js","webpack.config.js","webpack.config.ts"];for(let r of t){let n=e.join(e.getRootDir(),r);if(await e.exists(n))return n}throw new Error(`Could not find React config file. Searched for ${t.join(", ")} in "${e.getRootDir()}".`)}var ct=Lr(cr(),1);async function pr(e,t){let n={components:(await t.getRegistry()).components.filter(i=>i.isRegistered).map(i=>{let a={filePath:U(e.relative(e.getRootDir(),i.filePath)),name:i.name,image:i.image,description:i.description,exportName:i.exportName,inputs:V(i.inputs)};return V(a)}),version:1};e.debug("exporting registry components:",n.components.length);let o=(0,ct.compress)(n);return btoa(JSON.stringify(o))}async function ur(e,t,r){if(typeof r!="string")throw new Error("Invalid registry to import");let n=await t.getRegistry(),o=JSON.parse(atob(r)),i=(0,ct.decompress)(o),a=V(n);e.debug("importing registry components:",i.components.length);for(let s of i.components){let l=U(e.normalize(s.filePath)),c=n.components.find(p=>U(p.filePath).endsWith(l)&&p.exportName===s.exportName);if(!c){console.error(`Could not find component to register: ${s.filePath}, ${s.exportName}`);continue}e.debug(`register (${c.id})`,c.filePath),await t.registerComponent({cmpId:c.id});for(let p of s.inputs)e.debug(`set input (${c.id})`),await t.setRegisteredComponentInput({cmpId:c.id,name:p.name,type:p.type,required:p.required,defaultValue:p.defaultValue,friendlyName:p.friendlyName,helperText:p.helperText});e.debug(`set input (${c.id}) info`);let d=await t.setRegisteredComponentInfo({cmpId:c.id,name:s.name,image:s.image,description:s.description});a=V(d)}return a}var Qi={"@builder.io/qwik-city":kn,next:Pn,"@remix-run/react":Un,react:Hn};async function qi(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 xe(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=Qi[t.name];if(r){let n=await r(e);return{...n,exportRegistry:()=>pr(e,n),importRegistry:i=>ur(e,n,i)}}}throw new Error(`Devtools framework not found for ${e.getRootDir()}, ${JSON.stringify(e.frameworks,null,2)}`)}function mr(e){function t(p){if(typeof p!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(p))}function r(p,u){let m="",h=0,f=-1,x=0,g;for(let C=0;C<=p.length;++C){if(C<p.length)g=p.charCodeAt(C);else{if(g===47)break;g=47}if(g===47){if(!(f===C-1||x===1))if(f!==C-1&&x===2){if(m.length<2||h!==2||m.charCodeAt(m.length-1)!==46||m.charCodeAt(m.length-2)!==46){if(m.length>2){let S=m.lastIndexOf("/");if(S!==m.length-1){S===-1?(m="",h=0):(m=m.slice(0,S),h=m.length-1-m.lastIndexOf("/")),f=C,x=0;continue}}else if(m.length===2||m.length===1){m="",h=0,f=C,x=0;continue}}u&&(m.length>0?m+="/..":m="..",h=2)}else m.length>0?m+="/"+p.slice(f+1,C):m=p.slice(f+1,C),h=C-f-1;f=C,x=0}else g===46&&x!==-1?++x:x=-1}return m}let n=function(...u){let m="",h=!1;for(let f=u.length-1;f>=-1&&!h;f--){let x;f>=0?x=u[f]:e.cwd?x=e.cwd():x="/",t(x),x.length!==0&&(m=x+"/"+m,h=x.charCodeAt(0)===47)}return m=r(m,!h),h?m.length>0?"/"+m:"/":m.length>0?m:"."},o=function(u){if(t(u),u.length===0)return".";let m=u.charCodeAt(0)===47,h=u.charCodeAt(u.length-1)===47;return u=r(u,!m),u.length===0&&!m&&(u="."),u.length>0&&h&&(u+="/"),m?"/"+u:u};return{relative:function(u,m){if(t(u),t(m),u===m||(u=n(u),m=n(m),u===m))return"";let h=1;for(;h<u.length&&u.charCodeAt(h)===47;++h);let f=u.length,x=f-h,g=1;for(;g<m.length&&m.charCodeAt(g)===47;++g);let S=m.length-g,I=x<S?x:S,E=-1,T=0;for(;T<=I;++T){if(T===I){if(S>I){if(m.charCodeAt(g+T)===47)return m.slice(g+T+1);if(T===0)return m.slice(g+T)}else x>I&&(u.charCodeAt(h+T)===47?E=T:T===0&&(E=0));break}let L=u.charCodeAt(h+T),O=m.charCodeAt(g+T);if(L!==O)break;L===47&&(E=T)}let P="";for(T=h+E+1;T<=f;++T)(T===f||u.charCodeAt(T)===47)&&(P.length===0?P+="..":P+="/..");return P.length>0?P+m.slice(g+E):(g+=E,m.charCodeAt(g)===47&&++g,m.slice(g))},resolve:n,join:function(...u){if(u.length===0)return".";let m;for(let h=0;h<u.length;++h){let f=u[h];t(f),f.length>0&&(m===void 0?m=f:m+="/"+f)}return m===void 0?".":o(m)},isAbsolute:function(u){return t(u),u.length>0&&u.charCodeAt(0)===47},basename:function(u,m){if(m!==void 0&&typeof m!="string")throw new TypeError('"ext" argument must be a string');t(u);let h=0,f=-1,x=!0,g;if(m!==void 0&&m.length>0&&m.length<=u.length){if(m.length===u.length&&m===u)return"";let C=m.length-1,S=-1;for(g=u.length-1;g>=0;--g){let I=u.charCodeAt(g);if(I===47){if(!x){h=g+1;break}}else S===-1&&(x=!1,S=g+1),C>=0&&(I===m.charCodeAt(C)?--C===-1&&(f=g):(C=-1,f=S))}return h===f?f=S:f===-1&&(f=u.length),u.slice(h,f)}else{for(g=u.length-1;g>=0;--g)if(u.charCodeAt(g)===47){if(!x){h=g+1;break}}else f===-1&&(x=!1,f=g+1);return f===-1?"":u.slice(h,f)}},normalize:o,dirname:function(u){if(t(u),u.length===0)return".";let m=u.charCodeAt(0),h=m===47,f=-1,x=!0;for(let g=u.length-1;g>=1;--g)if(m=u.charCodeAt(g),m===47){if(!x){f=g;break}}else x=!1;return f===-1?h?"/":".":h&&f===1?"//":u.slice(0,f)},extname:function(u){t(u);let m=-1,h=0,f=-1,x=!0,g=0;for(let C=u.length-1;C>=0;--C){let S=u.charCodeAt(C);if(S===47){if(!x){h=C+1;break}continue}f===-1&&(x=!1,f=C+1),S===46?m===-1?m=C:g!==1&&(g=1):m!==-1&&(g=-1)}return m===-1||f===-1||g===0||g===1&&m===f-1&&m===h+1?"":u.slice(m,f)}}}async function Wi(e){let t=e.getRootDir?e.getRootDir:()=>"/",r=e.cwd?e.cwd:()=>"/",n=mr({cwd:r,...e}),o=new Map,i=f=>n.normalize(n.resolve(r(),f)),a=f=>{for(let[x]of o)if((x+"/").startsWith(f))return!0;return f===t()},s=f=>(f=i(f),o.has(f)?!0:a(f)),l=f=>{f=i(f);let x=f===t()?f:f+"/",g=x.split("/").length-1,C=[];for(let[S]of o)if(S.split("/").slice(0,g).join("/")+"/"===x){let T=S.split("/")[g];T&&!C.includes(T)&&C.push(T)}return C.sort()},c=f=>{f=i(f);let x=o.get(f);return typeof x=="string"?x:null},d=f=>(f=i(f),{isFile:()=>o.has(f),isDirectory:()=>!o.has(f)&&a(f)}),p=async f=>{if(typeof crypto<"u"){let C=new TextEncoder().encode(f),S=await crypto.subtle.digest("SHA-256",C);return Array.from(new Uint8Array(S)).map(I=>I.toString(16).padStart(2,"0")).join("")}let x=0;for(let g=0;g<f.length;g++){let C=f.charCodeAt(g);x=(x<<5)-x+C,x|=0}return Number(Math.abs(x)).toString(36)},u=new Set,m={getRootDir:t,cwd:r,exists:async f=>s(f),existsSync:s,readdir:async f=>l(f),readdirSync:l,readFile:async f=>c(f),readFileSync:c,stat:async f=>d(f),statSync:d,writeFile:async(f,x)=>{f=i(f),o.set(f,x);let g={path:f,basename:n.basename(f),dirname:n.dirname(f),extname:n.extname(f)};for(let C of u)await C(g)},hash:p,getDeviceId:async()=>typeof navigator<"u"?p(navigator.userAgent):"",formatCode:async(f,x)=>x,on:(f,x)=>{f==="change"&&u.add(x)},off:(f,x)=>{f==="change"&&u.delete(x)},debug:(...f)=>{console.debug("[builder-dev-tools]",...f)},launchEditor:async()=>{},platform:()=>({runtime:"",os:""}),getFrameworks:()=>[],...n,...e,version:"0.0.0"},h=await xe(m);return m.getFrameworks=e.getFrameworks?e.getFrameworks:()=>h,m}async function fr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(dr(e,n))return o;let a=z(e,n,"cjs"),s=z(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let p=d.statement;if(!e.ts.isVariableStatement(p))throw new Error(`Expected an export assignment from ${t}`);let u=d.statement;if(e.ts.isVariableStatement(u)){let m=[...u.declarationList.declarations];if(m.length!==1)throw new Error("Expected a single variable declaration");let h=m[0];if(!h.initializer)throw new Error("Expected an initializer on the declaration");let f=h.initializer;if(e.ts.isObjectLiteralExpression(f)||e.ts.isCallExpression(f)){let x="BuilderDevTools()",g=[...n.statements],C=g.indexOf(u);return g[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(x),void 0,[f]))])),n=e.ts.factory.updateSourceFile(n,g),n=y(e,n,{defaultImport:"BuilderDevTools",importPath:"@builder.io/dev-tools/next"}),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}}let l=a[0];if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let p=d.expression;if(!e.ts.isBinaryExpression(p))throw new Error("Expected a binary expression for the default export");let u=$t(e,n);n=u.sourceFile;let m=[...n.statements],h=m.indexOf(d);return m[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(p,p.left,p.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[p.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=F(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let p=d[0];if(!p.initializer)throw new Error("Expected an initializer on the declaration");let u=p.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let m=$t(e,n);n=m.sourceFile;let h=[...n.statements],f=h.indexOf(c);return h[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}if(e.ts.isArrowFunction(l.node)){let d=l.node,p=l.statement;if(!e.ts.isExpressionStatement(p))throw new Error("Expected an expression statement for the default export");let u=p.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 f=[...h.statements],x=f.findIndex(E=>e.ts.isReturnStatement(E));if(x===-1)throw new Error("Expected a return statement on the next config function");let g=f[x],C=$t(e,n);n=C.sourceFile,f[x]=e.ts.factory.updateReturnStatement(g,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(C.withFnVariableName),void 0,[g.expression]));let S=[...n.statements],I=S.indexOf(p);return S[I]=e.ts.factory.updateExpressionStatement(p,e.ts.factory.updateBinaryExpression(u,u.left,u.operatorToken,e.ts.factory.updateArrowFunction(d,d.modifiers,d.typeParameters,d.parameters,d.type,d.equalsGreaterThanToken,e.ts.factory.updateBlock(h,f)))),n=e.ts.factory.updateSourceFile(n,S),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected export type")}function dr(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 $t(e,t){let r=dr(e,t);return r||(r="withBuilderDevTools",t=e.ts.factory.updateSourceFile(t,[e.ts.factory.createVariableStatement(void 0,e.ts.factory.createVariableDeclarationList([e.ts.factory.createVariableDeclaration(r,void 0,void 0,e.ts.factory.createCallExpression(e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("require"),void 0,[e.ts.factory.createStringLiteral("@builder.io/dev-tools/next")]),void 0,[]))],e.ts.NodeFlags.Const)),...t.statements])),{withFnVariableName:r,sourceFile:t}}async function hr(e,t,r){let n=D(e,r),o={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(Cr(e,n))return o;let a=z(e,n,"cjs"),s=z(e,n);if(a.length!==1&&s.length!==1)throw new Error(`Expected an export from ${t}`);let l=a[0];if(s.length===1){let d=s[0];if(!d.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let p=d.statement;if(!e.ts.isExportAssignment(p))throw new Error(`Expected an export assignment from ${t}`);if(e.ts.isObjectLiteralExpression(p.expression)){let u="builderDevTools()",m=Ji(e,p.expression);if(!m)return o;let h=e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u),void 0,[m]),f=[...n.statements],x=f.indexOf(p);return f[x]=e.ts.factory.updateExportAssignment(p,p.modifiers,h),n=e.ts.factory.updateSourceFile(n,f),n=y(e,n,{defaultImport:"builderDevTools",importPath:"@builder.io/dev-tools/remix"}),o.content=F(e,n),o.hasContentUpdates=!0,o}}if(!l.isDefaultExport)throw new Error(`Expected a default export from ${t}`);if(e.ts.isObjectLiteralExpression(l.node)||e.ts.isCallExpression(l.node)){let d=l.statement;if(!e.ts.isExpressionStatement(d))throw new Error("Expected an expression statement for the default export");let p=d.expression;if(!e.ts.isBinaryExpression(p))throw new Error("Expected a binary expression for the default export");let u=gr(e,n);n=u.sourceFile;let m=[...n.statements],h=m.indexOf(d);return m[h]=e.ts.factory.updateExpressionStatement(d,e.ts.factory.updateBinaryExpression(p,p.left,p.operatorToken,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(u.withFnVariableName),void 0,[p.right]))),n=e.ts.factory.updateSourceFile(n,m),o.content=F(e,n),o.hasContentUpdates=!0,o}let c=l.statement;if(e.ts.isVariableStatement(c)){let d=[...c.declarationList.declarations];if(d.length!==1)throw new Error("Expected a single variable declaration");let p=d[0];if(!p.initializer)throw new Error("Expected an initializer on the declaration");let u=p.initializer;if(e.ts.isObjectLiteralExpression(u)||e.ts.isCallExpression(u)){let m=gr(e,n);n=m.sourceFile;let h=[...n.statements],f=h.indexOf(c);return h[f]=e.ts.factory.updateVariableStatement(c,c.modifiers,e.ts.factory.updateVariableDeclarationList(c.declarationList,[e.ts.factory.updateVariableDeclaration(p,p.name,p.exclamationToken,p.type,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier(m.withFnVariableName),void 0,[u]))])),n=e.ts.factory.updateSourceFile(n,h),o.content=F(e,n),o.hasContentUpdates=!0,o}throw new Error("Unexpected initializer on the variable statement")}throw new Error("Unexpected export type")}function Cr(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 gr(e,t){let r=Cr(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 Ji(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="serverDependenciesToBundle");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=xr(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=xr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("serverDependenciesToBundle",o)]):null}function xr(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 Tr(e,t,r){let n=D(e,r),o=z(e,n);if(o.length!==1)throw new Error(`Expected an export from ${t}`);let i=o[0];if(!i.isDefaultExport)throw new Error(`Expected a default export from ${t}`);let a=i.statement;if(!e.ts.isExportAssignment(a))throw new Error(`Expected an export assignment from ${t}`);let s={content:r,filePath:t,fileName:e.basename(t),hasContentUpdates:!1};if(e.ts.isCallExpression(i.node)&&e.ts.isIdentifier(i.node.expression)&&i.node.expression.text==="defineConfig"){let l=[...i.node.arguments];if(l.length===0)throw new Error("Expected an argument in defineConfig()");let c=l[0];if(e.ts.isArrowFunction(c)){let d=Yi(e,c);if(!d)return s;l[0]=e.ts.factory.updateArrowFunction(c,c.modifiers,c.typeParameters,c.parameters,c.type,c.equalsGreaterThanToken,d);let p=[...n.statements],u=p.indexOf(a);return p[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,p),n=y(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}if(e.ts.isObjectLiteralExpression(c)){let d=zt(e,c);if(!d)return s;let p=[...n.statements],u=p.indexOf(a);return p[u]=e.ts.factory.updateExportAssignment(a,void 0,e.ts.factory.updateCallExpression(i.node,i.node.expression,i.node.typeArguments,[d])),n=e.ts.factory.updateSourceFile(n,p),n=y(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}throw new Error("Unsupported argument in defineConfig()")}if(e.ts.isObjectLiteralExpression(a.expression)){let l=zt(e,a.expression);if(!l)return s;let c=[...n.statements],d=c.indexOf(a);return c[d]=e.ts.factory.updateExportAssignment(a,a.modifiers,l),n=e.ts.factory.updateSourceFile(n,c),n=y(e,n,{namedImports:["builderDevTools"],importPath:"@builder.io/dev-tools/vite"}),s.content=F(e,n),s.hasContentUpdates=!0,s}throw new Error(`Unable to parse ${t}`)}function Yi(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=zt(e,i.expression);return a?(n[o]=e.ts.factory.updateReturnStatement(i,a),e.ts.factory.updateBlock(r,n)):null}function zt(e,t){if(Xi(e)){let i=Hi(e,t);i&&(t=i)}let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="plugins");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Sr(e,i.initializer);if(a)return r[n]=e.ts.factory.updatePropertyAssignment(i,i.name,a),e.ts.factory.updateObjectLiteralExpression(t,r)}return null}let o=Sr(e,e.ts.factory.createArrayLiteralExpression([],!0));return o?e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("plugins",o)]):null}function Sr(e,t){return t.elements.some(n=>e.ts.isCallExpression(n)&&e.ts.isIdentifier(n.expression)?n.expression.text==="builderDevTools":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createCallExpression(e.ts.factory.createIdentifier("builderDevTools"),void 0,[])])}function Hi(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="ssr");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isObjectLiteralExpression(i.initializer)){let a=Gi(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=Kt(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o){let i=e.ts.factory.createObjectLiteralExpression([e.ts.factory.createPropertyAssignment("noExternal",o)]);return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("ssr",i)])}return null}function Gi(e,t){let r=[...t.properties],n=r.findIndex(i=>b(e,i)==="noExternal");if(n>-1){let i=r[n];if(e.ts.isPropertyAssignment(i)&&i.initializer&&e.ts.isArrayLiteralExpression(i.initializer)){let a=Kt(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=Kt(e,e.ts.factory.createArrayLiteralExpression([],!0));if(o)return e.ts.factory.updateObjectLiteralExpression(t,[...r,e.ts.factory.createPropertyAssignment("noExternal",o)])}function Kt(e,t){return t.elements.some(n=>e.ts.isStringLiteral(n)?n.text==="@builder.io/react":!1)?null:e.ts.factory.updateArrayLiteralExpression(t,[...t.elements,e.ts.factory.createStringLiteral("@builder.io/react")])}function Xi(e){return e.getFrameworks().some(t=>t.name==="@remix-run/react")}async function wr(e,t,r){return e.debug("Webpack config updates are currently in progress..."),{content:r,fileName:e.basename(t),filePath:t,hasContentUpdates:!0}}var yr=[{id:"next",configFileNames:["next.config.ts","next.config.js","next.config.mjs"],ensureConfigPlugin:fr},{id:"vite",configFileNames:["vite.config.ts","vite.config.js"],ensureConfigPlugin:Tr},{id:"remix",configFileNames:["remix.config.ts","remix.config.js"],ensureConfigPlugin:hr},{id:"webpack",configFileNames:["webpack.config.ts","webpack.config.js"],ensureConfigPlugin:wr}];async function Pr(e){let t=e.resolve("/");for(let n of yr)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 xe(e)).some(n=>n.name==="next")){let n=e.join(e.getRootDir(),"next.config.js");return await e.writeFile(n,Er),{id:"next",filePath:n,content:Er}}return null}async function Zi(e){let t=await Pr(e);if(!t)throw new Error("Unable to find config file, such as next.config.js or vite.config.js.");let n=await yr.find(o=>o.id===t.id).ensureConfigPlugin(e,t.filePath,t.content);return n.hasContentUpdates&&(n.content=W(n.content),n.content=await e.formatCode(n.filePath,n.content),await e.writeFile(t.filePath,n.content)),n}var Er=`
506
505
  /** @type {import('next').NextConfig} */
507
506
  const nextConfig = {
508
507
  }
509
508
 
510
509
  module.exports = nextConfig
511
- `.trimStart();var Dr="/~builder-dev-tools.js";function Xi(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(Dr,e);t.searchParams.set("v",pt);let r=JSON.stringify(pt),n=`/* Builder Devtools v${pt} */
510
+ `.trimStart();var Dr="/~builder-dev-tools.js";function ea(e){try{if(typeof e!="string"||e.trim().length===0)return console.error("Missing devtool server url"),"";let t=new URL(Dr,e);t.searchParams.set("v",pt);let r=JSON.stringify(pt),n=`/* Builder Devtools v${pt} */
512
511
  `;return n+=`(() => {
513
512
  `,n+=` if (typeof document !== "undefined") {
514
513
  `,n+=` let devToolsScript = document.head.querySelector("script[data-builder-dev-tools]");
@@ -521,4 +520,4 @@ module.exports = nextConfig
521
520
  `,n+=` }
522
521
  `,n+=` }
523
522
  `,n+=`})();
524
- `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var pt="1.0.8";export{Mi as createDevTools,Qi as createDevToolsSys,xe as detectFrameworks,qt as detectFrameworksFromPackageJson,Gi as ensureConfigPlugin,Pr as findBuildToolConfig,Xi as getClientScript,Jt as parseDotEnvContent,pt as version};
523
+ `,n}catch(t){return console.error(`Failed to create devtools client script: ${t.message||t}`),""}}var pt="1.0.9";export{qi as createDevTools,Wi as createDevToolsSys,xe as detectFrameworks,qt as detectFrameworksFromPackageJson,Zi as ensureConfigPlugin,Pr as findBuildToolConfig,ea as getClientScript,Jt as parseDotEnvContent,pt as version};