@stacksjs/stx 0.2.39 → 0.2.40

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/dist/cli.js CHANGED
@@ -14790,11 +14790,11 @@ ${$}`}function Y1($){return $.replace(/&/g,"&").replace(/"/g,""").repla
14790
14790
  `)}async function wS(){if(h$!==null)return h$;try{let $=await import("stx-router");if(typeof $.getRouterScript==="function")h$=$.getRouterScript();else h$=""}catch{h$=""}return h$}async function u7($,Z){let Y=await wS();if(!Y)return $;let X={interceptAllLinks:!0,container:"body",...Z},Q=`${`<script>window.__stxRouterConfig=${JSON.stringify(X)};</script>
14791
14791
  `}<script>${Y}</script>`;if(/<\/body>/i.test($))return $.replace(/<\/body>/i,`${Q}
14792
14792
  </body>`);return`${$}
14793
- ${Q}`}var h$=null;function m7($,Z){if(Z.theme===!1)return $;let Y=typeof Z.theme==="object"&&Z.theme!==null?Z.theme:{},X=Y.default??"dark",J=Y.storageKey??"theme",Q=Y.colors?.light??"#ffffff",G=Y.colors?.dark??"#000000";if(X==="dark"){if(!/<html\b[^>]*\bclass=/.test($))$=$.replace(/<html\b([^>]*)>/i,'<html$1 class="dark">');else if(!/<html\b[^>]*\bclass="[^"]*\bdark\b/.test($))$=$.replace(/<html\b([^>]*\bclass=")([^"]*)(")/i,"<html$1$2 dark$3")}if(!$.includes("data-stx-theme-meta")&&/<head\b[^>]*>/i.test($)){let W=['<meta name="color-scheme" content="dark light" data-stx-theme-meta="1">',`<meta name="theme-color" content="${X==="dark"?G:Q}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: light)" content="${Q}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${G}" data-stx-theme-meta="1">`].join(`
14793
+ ${Q}`}var h$=null;function m7($,Z){if(Z.theme===!1)return $;let Y=typeof Z.theme==="object"&&Z.theme!==null?Z.theme:{},X=Y.default??"dark",J=Y.storageKey??"theme",Q=Y.colors?.light??"#ffffff",G=Y.colors?.dark??"#000000";if(X==="dark"){if(!/<html\b[^>]*\bclass=/.test($))$=$.replace(/<html\b([^>]*)>/i,'<html$1 class="dark">');else if(!/<html\b[^>]*\bclass="[^"]*\bdark\b/.test($))$=$.replace(/<html\b([^>]*\bclass=")([^"]*)(")/i,"<html$1$2 dark$3")}if(!$.includes("data-stx-theme-meta")&&/<head\b[^>]*>/i.test($)){let K=['<meta name="color-scheme" content="dark light" data-stx-theme-meta="1">',`<meta name="theme-color" media="(prefers-color-scheme: light)" content="${Q}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${G}" data-stx-theme-meta="1">`].join(`
14794
14794
  `);$=$.replace(/<head\b([^>]*)>/i,`<head$1>
14795
- ${W}`)}if(!$.includes("__stxThemeGuard")&&/<head\b[^>]*>/i.test($)){let K=`<script data-stx-theme-guard="1">${RS(X,J,Q,G)};window.__stxThemeGuard=1;</script>`;$=$.replace(/<head\b([^>]*)>/i,`<head$1>
14795
+ ${K}`)}if(!$.includes("__stxThemeGuard")&&/<head\b[^>]*>/i.test($)){let K=`<script data-stx-theme-guard="1">${RS(X,J,Q,G)};window.__stxThemeGuard=1;</script>`;$=$.replace(/<head\b([^>]*)>/i,`<head$1>
14796
14796
  ${K}`)}if(!$.includes("__stxThemeToggle")&&/<\/body>/i.test($)){let K=`<script data-stx-theme-toggle="1">${MS(J,Q,G)};window.__stxThemeToggle=1;</script>`;$=$.replace(/<\/body>/i,`${K}
14797
- </body>`)}return $}var RS=($,Z,Y,X)=>`(function(){try{var k=${JSON.stringify(Z)};var t=localStorage.getItem(k);var html=document.documentElement;var isDark=t===null?(${JSON.stringify($)}==='dark'||(${JSON.stringify($)}==='auto'&&window.matchMedia('(prefers-color-scheme: dark)').matches)):t==='dark';html.classList[isDark?'add':'remove']('dark');var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(X)}:${JSON.stringify(Y)})}catch(e){}})();`,MS=($,Z,Y)=>`document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#theme-toggle');if(!t)return;var html=document.documentElement;var isDark=html.classList.toggle('dark');try{localStorage.setItem(${JSON.stringify($)},isDark?'dark':'light')}catch(e){}var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(Y)}:${JSON.stringify(Z)})});`;import{existsSync as ES,readFileSync as TS}from"fs";import{join as IS,resolve as DS}from"path";import kS from"process";function c7($,Z=kS.cwd()){let Y=$.i18n;if(!Y||!Array.isArray(Y.locales)||Y.locales.length===0)return null;let X=Y.defaultLocale??Y.locales[0],J=SS(Y,Z);return{locales:Y.locales,defaultLocale:X,labels:Y.labels??Object.fromEntries(Y.locales.map((Q)=>[Q,Q.toUpperCase()])),translations:J,pickerSelector:Y.pickerSelector??"#lang-picker"}}function SS($,Z){let Y=$.translations??{},X={},J=$.translationsDir,Q=J===!1?null:DS(Z,typeof J==="string"&&J?J:"translations"),G=$.format??"json";for(let K of $.locales){let W=Q?bS(Q,K,G):{};X[K]={...W,...Y[K]??{}}}return X}function bS($,Z,Y){let X=Y==="json"?[`${Z}.json`]:[`${Z}.${Y}`,`${Z}.${Y==="yaml"?"yml":"yaml"}`];for(let J of X){let Q=IS($,J);if(!ES(Q))continue;try{let G=TS(Q,"utf8"),K=Y==="json"?JSON.parse(G):CS(G);return xO(K)}catch{continue}}return{}}function xO($,Z="",Y={}){if(!$||typeof $!=="object")return Y;for(let[X,J]of Object.entries($)){let Q=Z?`${Z}.${X}`:X;if(J&&typeof J==="object"&&!Array.isArray(J))xO(J,Q,Y);else if(typeof J==="string")Y[Q]=J;else if(typeof J==="number"||typeof J==="boolean")Y[Q]=String(J)}return Y}function CS($){let Z={},Y=[{obj:Z,indent:-1}];for(let X of $.split(`
14797
+ </body>`)}return $}var RS=($,Z,Y,X)=>`(function(){function read(){try{var k=${JSON.stringify(Z)};var t=localStorage.getItem(k);return t===null?(${JSON.stringify($)}==='dark'||(${JSON.stringify($)}==='auto'&&window.matchMedia('(prefers-color-scheme: dark)').matches)):t==='dark'}catch(e){return ${JSON.stringify($)}==='dark'}}function apply(){var isDark=read();var html=document.documentElement;html.classList[isDark?'add':'remove']('dark');var color=isDark?${JSON.stringify(X)}:${JSON.stringify(Y)};var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc){tc.setAttribute('content',color)}else if(document.head){tc=document.createElement('meta');tc.setAttribute('name','theme-color');tc.setAttribute('content',color);tc.setAttribute('data-stx-theme-meta','1');document.head.insertBefore(tc,document.head.firstChild)}}apply();window.addEventListener('stx:navigate',apply);window.addEventListener('popstate',apply)})();`,MS=($,Z,Y)=>`document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#theme-toggle');if(!t)return;var html=document.documentElement;var isDark=html.classList.toggle('dark');try{localStorage.setItem(${JSON.stringify($)},isDark?'dark':'light')}catch(e){}var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(Y)}:${JSON.stringify(Z)})});`;import{existsSync as ES,readFileSync as TS}from"fs";import{join as IS,resolve as DS}from"path";import kS from"process";function c7($,Z=kS.cwd()){let Y=$.i18n;if(!Y||!Array.isArray(Y.locales)||Y.locales.length===0)return null;let X=Y.defaultLocale??Y.locales[0],J=SS(Y,Z);return{locales:Y.locales,defaultLocale:X,labels:Y.labels??Object.fromEntries(Y.locales.map((Q)=>[Q,Q.toUpperCase()])),translations:J,pickerSelector:Y.pickerSelector??"#lang-picker"}}function SS($,Z){let Y=$.translations??{},X={},J=$.translationsDir,Q=J===!1?null:DS(Z,typeof J==="string"&&J?J:"translations"),G=$.format??"json";for(let K of $.locales){let W=Q?bS(Q,K,G):{};X[K]={...W,...Y[K]??{}}}return X}function bS($,Z,Y){let X=Y==="json"?[`${Z}.json`]:[`${Z}.${Y}`,`${Z}.${Y==="yaml"?"yml":"yaml"}`];for(let J of X){let Q=IS($,J);if(!ES(Q))continue;try{let G=TS(Q,"utf8"),K=Y==="json"?JSON.parse(G):CS(G);return xO(K)}catch{continue}}return{}}function xO($,Z="",Y={}){if(!$||typeof $!=="object")return Y;for(let[X,J]of Object.entries($)){let Q=Z?`${Z}.${X}`:X;if(J&&typeof J==="object"&&!Array.isArray(J))xO(J,Q,Y);else if(typeof J==="string")Y[Q]=J;else if(typeof J==="number"||typeof J==="boolean")Y[Q]=String(J)}return Y}function CS($){let Z={},Y=[{obj:Z,indent:-1}];for(let X of $.split(`
14798
14798
  `)){let J=X.replace(/#.*$/,"").trimEnd();if(!J.trim())continue;let Q=J.search(/\S/);if(Q===-1)continue;while(Y.length>1&&Y[Y.length-1].indent>=Q)Y.pop();let G=Y[Y.length-1].obj,K=J.match(/^(\s*)(\S[^:]*):\s*(.*)$/);if(!K)continue;let[,,W,U]=K,_=W.trim(),B=U.trim();if(B==="")G[_]={},Y.push({obj:G[_],indent:Q});else G[_]=PS(B)}return Z}function PS($){if($.startsWith("'")&&$.endsWith("'")||$.startsWith('"')&&$.endsWith('"'))return $.slice(1,-1);return $}function UY($,Z,Y){let X=$.translations[Z]?.[Y];if(typeof X==="string")return X;let J=$.translations[$.defaultLocale]?.[Y];if(typeof J==="string")return J;return Y}function p7($,Z,Y){return $.replace(/\{t:([a-zA-Z][\w.-]*)\}/g,(X,J)=>yS(UY(Z,Y,J)))}function U4($,Z,Y){if(Z===Y)return $;if($==="/")return`/${Z}/`;if($==="/404.html")return`/${Z}/404.html`;return`/${Z}${$}`}function SG($,Z){for(let Y of Z){if($===`/${Y}`||$===`/${Y}/`)return{locale:Y,path:"/"};if($.startsWith(`/${Y}/`))return{locale:Y,path:$.slice(Y.length+1)}}return{locale:null,path:$}}function l7($,Z,Y){let X=$.replace(/\/$/,""),J=[];for(let G of Y.locales){let K=`${X}${U4(Z,G,Y.defaultLocale)}`;J.push(`<link rel="alternate" hreflang="${kG(G)}" href="${kG(K)}">`)}let Q=`${X}${U4(Z,Y.defaultLocale,Y.defaultLocale)}`;return J.push(`<link rel="alternate" hreflang="x-default" href="${kG(Q)}">`),J.join(`
14799
14799
  `)}function i7($,Z){return`<script data-stx-lang-picker="1">window.__stxI18n=${JSON.stringify({locales:$.locales,defaultLocale:$.defaultLocale,current:Z,pickerSelector:$.pickerSelector})};(function(){var d=window.__stxI18n;function localeFromPath(p){for(var i=0;i<d.locales.length;i++){var c=d.locales[i];if(p==='/'+c||p==='/'+c+'/')return c;if(p.indexOf('/'+c+'/')===0)return c}return d.defaultLocale}function localePathFor(loc,p){var stripped=p;for(var i=0;i<d.locales.length;i++){var c=d.locales[i];if(p==='/'+c||p==='/'+c+'/'){stripped='/';break}if(p.indexOf('/'+c+'/')===0){stripped=p.slice(c.length+1);break}}if(loc===d.defaultLocale)return stripped;if(stripped==='/')return '/'+loc+'/';return '/'+loc+stripped}function syncFromUrl(){var loc=localeFromPath(location.pathname);d.current=loc;var picker=document.querySelector(d.pickerSelector);if(picker){var btns=picker.querySelectorAll('[data-lang]');for(var i=0;i<btns.length;i++){if(btns[i].getAttribute('data-lang')===loc)btns[i].setAttribute('aria-current','true');else btns[i].removeAttribute('aria-current')}}if(document.documentElement.lang!==loc)document.documentElement.lang=loc}syncFromUrl();window.addEventListener('stx:navigate',syncFromUrl);window.addEventListener('popstate',syncFromUrl);document.addEventListener('click',function(e){var btn=e.target&&e.target.closest&&e.target.closest('['+'data-lang'+']');if(!btn)return;var picker=document.querySelector(d.pickerSelector);if(!picker||!picker.contains(btn))return;e.preventDefault();var loc=btn.getAttribute('data-lang');var dest=localePathFor(loc,location.pathname);if(window.__stxRouter&&window.__stxRouter.navigate)window.__stxRouter.navigate(dest);else location.assign(dest)});})();</script>`}function kG($){return $.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function yS($){return $.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var bG=()=>{};var{Glob:xS}=globalThis.Bun;import{cpSync as vS,existsSync as BY,mkdirSync as vO,readFileSync as gO,readdirSync as gS,rmSync as fS,statSync as hS,unlinkSync as dS,writeFileSync as _Y}from"fs";import{dirname as uS,join as _4,relative as mS}from"path";import fO from"process";import cS from"bun-plugin-stx";async function yG($){let Z=Date.now(),Y=$.pagesDir??"pages",X=$.outDir??"dist",J=$.publicDir??"public";if(!$.noClean)fS(X,{recursive:!0,force:!0});vO(X,{recursive:!0});let Q=new xS(`${Y}/**/*.stx`),G=await Array.fromAsync(Q.scan("."));if(G.length===0)throw Error(`No .stx files found in ${Y}/`);let K=await Bun.build({entrypoints:G,outdir:X,plugins:[cS()],naming:{entry:"[name].[ext]"}});if(!K.success)throw console.error(K.logs),Error("Build failed");iS(X);let W=xG(X).filter((q)=>q.endsWith(".html")),U=c7($,fO.cwd());for(let q of W){let j=_4(X,q),H=gO(j,"utf8"),O=CG(q),F=U?U.locales:[$.seo?.locale?.split(/[_-]/)[0]??"en"];for(let L of F){let V=H;if(V=nS(V),U)V=p7(V,U,L);if(V=await E0(V,fO.cwd()),V=f7(V,$,$.pages?.[O],O),U)V=rS(V,$,U,L,O);if(V=m7(V,$),V=sS(V),U)V=V.replace(/<\/body>/i,`${i7(U,L)}
14800
14800
  </body>`);if($.spa!==!1)V=await u7(V,$.router);let N=U?lS(O,L,U.defaultLocale):q,A=_4(X,N);if(vO(pS(A),{recursive:!0}),_Y(A,V),U&&L!==U.defaultLocale&&N!==q);}}if(BY(J))vS(J,X,{recursive:!0});let _=_4(X,"404.html");if(!BY(_)&&BY(_4(X,"index.html"))){let q=gO(_4(X,"index.html"),"utf8").replace(/<title>[^<]*<\/title>/i,`<title>404 \u2014 ${aS($.name)}</title>`);_Y(_,q)}if($.sitemap!==!1){let q=[],j=W.filter((O)=>O!=="404.html").map(CG),H=U?U.locales:[null];for(let O of j){let F=$.pages?.[O];for(let L of H){let V=L&&U?U4(O,L,U.defaultLocale):O;q.push({path:V,page:F})}}_Y(_4(X,"sitemap.xml"),h7($,q))}let B=d7($);if(B!==null)_Y(_4(X,"robots.txt"),B);let z=W.map(CG);return{outDir:X,pages:z,durationMs:Date.now()-Z}}function pS($){return uS($)}function lS($,Z,Y){let X=U4($,Z,Y);if(X==="/")return"index.html";let J=X.replace(/^\//,"").replace(/\/$/,"");if(!J.includes("/")){if(Z!==Y&&J===Z)return`${Z}/index.html`;return`${J}.html`}return`${J}.html`.replace(/\.html\.html$/,".html")}function CG($){if($==="index.html")return"/";return`/${$.replace(/\.html$/,"").replace(/\/index$/,"")}`}function xG($,Z=$){let Y=[];if(!BY($))return Y;for(let X of gS($,{withFileTypes:!0})){let J=_4($,X.name);if(X.isDirectory())Y.push(...xG(J,Z));else Y.push(mS(Z,J))}return Y}function iS($){for(let Z of xG($)){if(!/^chunk-.*\.js(?:\.map)?$/.test(Z))continue;let Y=_4($,Z);try{if(hS(Y).size===0)dS(Y)}catch{}}}function nS($){return $.replace(/<script[^>]*src=["']\.\/chunk-[^"']*\.js["'][^>]*><\/script>\s*/g,"")}function rS($,Z,Y,X,J){if(!Y)return $;if(/<html\b[^>]*\blang=/i.test($))$=$.replace(/<html\b([^>]*)\blang="[^"]*"/i,`<html$1lang="${X}"`);else $=$.replace(/<html\b([^>]*)>/i,`<html$1 lang="${X}">`);let Q=`${Z.url.replace(/\/$/,"")}${U4(J,X,Y.defaultLocale)}`;if(/<link rel="canonical"/.test($))$=$.replace(/<link rel="canonical"[^>]*>/,`<link rel="canonical" href="${PG(Q)}">`);let G=X.includes("_")||X.includes("-")?X:X.toLowerCase();if(/<meta property="og:locale"/.test($))$=$.replace(/<meta property="og:locale"[^>]*>/,`<meta property="og:locale" content="${PG(G)}">`);if(/<meta property="og:url"/.test($))$=$.replace(/<meta property="og:url"[^>]*>/,`<meta property="og:url" content="${PG(Q)}">`);let K=l7(Z.url,J,Y);if(!$.includes("hreflang="))$=$.replace(/<link rel="canonical"[^>]*>/,(W)=>`${K}
@@ -18218,7 +18218,7 @@ else {
18218
18218
  `)}function xF($,Z){let Y=" ".repeat(Z),X=[];for(let[K,W]of Object.entries($.props))if(W.type==="literal"){let U=typeof W.value==="string"?`"${W.value}"`:String(W.value);X.push(`${K}: ${U}`)}let J=X.length>0?`{ ${X.join(", ")} }`:"{}",Q=$.children.map((K)=>K.type==="text"?`"${K.props.text?.type==="literal"?K.props.text.value:""}"`:xF(K,Z+1)),G=Q.length>0?`,
18219
18219
  ${Y} [${Q.join(`,
18220
18220
  ${Y} `)}]`:"";return`Craft.create("${$.zigType}", ${J}${G})`}function lC($,Z,Y){if(Z.target==="universal"){let X=[];X.push("// Universal entry point"),X.push("");for(let[J,Q]of Y)X.push(`// --- ${J.toUpperCase()} ---`),X.push(`#if ${J.toUpperCase()}`),X.push(Q),X.push("#endif"),X.push("");return X.join(`
18221
- `)}return Y.get(Z.target)||GK($,Z)}function iC($,Z,Y){let X=[];function J(Q){X.push({name:Q.zigType,hash:gF(JSON.stringify(Q.props)),props:Object.keys(Q.props),events:Array.from(Q.events.keys()),slots:[],isNative:Q.zigType.startsWith("craft.")});for(let G of Q.children)J(G)}return J(Z),{version:"1.0.0",components:X,entry:$.id,assets:[],styles:$.styles}}function nC($,Z){return JSON.stringify({version:3,file:"output.zig",sources:["input.stx"],mappings:""})}function vF(){return`id_${++rC}`}function gF($){let Z=0;for(let Y=0;Y<$.length;Y++){let X=$.charCodeAt(Y);Z=(Z<<5)-Z+X,Z=Z&Z}return Math.abs(Z).toString(36)}function sC($){return $.charAt(0).toUpperCase()+$.slice(1)}function aC($){let Z=[],Y=/<script[^>]*>([\s\S]*?)<\/script>/gi,X;while((X=Y.exec($))!==null)Z.push(X[1]);return Z}function oC($){let Z=[],Y=/<style[^>]*>([\s\S]*?)<\/style>/gi,X;while((X=Y.exec($))!==null)Z.push(X[1]);return Z}function KK($){let Z=$.type==="component"?1:0;if($.children)for(let Y of $.children)Z+=KK(Y);return Z}function WK($){let Z=$.zigType.startsWith("craft.")?1:0;for(let Y of $.children)Z+=WK(Y);return Z}function fF($){return{start:async()=>{console.log("[craft-compiler] Hot reload server started")},stop:async()=>{console.log("[craft-compiler] Hot reload server stopped")},notifyChange:(Z)=>{console.log(`[craft-compiler] File changed: ${Z}`)}}}var UK,rC=0,tC,eC;var dF=D(()=>{UK=new Map([["craft-button",{name:"Button",zigType:"craft.Button",props:[{name:"variant",type:"string",required:!1,default:"primary"},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onclick",type:"callback",required:!1}],children:"single"}],["craft-text-input",{name:"TextInput",zigType:"craft.TextInput",props:[{name:"value",type:"string",required:!1,default:""},{name:"placeholder",type:"string",required:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-textarea",{name:"TextArea",zigType:"craft.TextArea",props:[{name:"value",type:"string",required:!1,default:""},{name:"placeholder",type:"string",required:!1},{name:"rows",type:"number",required:!1,default:3},{name:"disabled",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-checkbox",{name:"Checkbox",zigType:"craft.Checkbox",props:[{name:"checked",type:"boolean",required:!1,default:!1},{name:"label",type:"string",required:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-select",{name:"Select",zigType:"craft.Select",props:[{name:"value",type:"string",required:!1},{name:"options",type:"array",required:!0},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-slider",{name:"Slider",zigType:"craft.Slider",props:[{name:"value",type:"number",required:!1,default:0},{name:"min",type:"number",required:!1,default:0},{name:"max",type:"number",required:!1,default:100},{name:"step",type:"number",required:!1,default:1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-toggle",{name:"Toggle",zigType:"craft.Toggle",props:[{name:"checked",type:"boolean",required:!1,default:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-modal",{name:"Modal",zigType:"craft.Modal",props:[{name:"open",type:"boolean",required:!1,default:!1},{name:"title",type:"string",required:!1},{name:"closable",type:"boolean",required:!1,default:!0},{name:"onclose",type:"callback",required:!1}],children:"multiple"}],["craft-alert",{name:"Alert",zigType:"craft.Alert",props:[{name:"variant",type:"string",required:!1,default:"info"},{name:"title",type:"string",required:!1},{name:"dismissible",type:"boolean",required:!1,default:!1}],children:"single"}],["craft-progress",{name:"ProgressBar",zigType:"craft.ProgressBar",props:[{name:"value",type:"number",required:!1,default:0},{name:"max",type:"number",required:!1,default:100},{name:"indeterminate",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-spinner",{name:"Spinner",zigType:"craft.Spinner",props:[{name:"size",type:"number",required:!1,default:24}],children:"none"}],["craft-avatar",{name:"Avatar",zigType:"craft.Avatar",props:[{name:"src",type:"string",required:!1},{name:"alt",type:"string",required:!1},{name:"size",type:"number",required:!1,default:40}],children:"none"}],["craft-badge",{name:"Badge",zigType:"craft.Badge",props:[{name:"variant",type:"string",required:!1,default:"default"}],children:"single"}],["craft-card",{name:"Card",zigType:"craft.Card",props:[{name:"padding",type:"number",required:!1,default:16}],children:"multiple"}],["craft-accordion",{name:"Accordion",zigType:"craft.Accordion",props:[{name:"title",type:"string",required:!0},{name:"open",type:"boolean",required:!1,default:!1}],children:"multiple"}],["craft-tabs",{name:"TabView",zigType:"craft.TabView",props:[{name:"activeTab",type:"number",required:!1,default:0},{name:"ontabchange",type:"callback",required:!1}],children:"multiple"}],["craft-tooltip",{name:"Tooltip",zigType:"craft.Tooltip",props:[{name:"content",type:"string",required:!0},{name:"position",type:"string",required:!1,default:"top"}],children:"single"}],["craft-date-picker",{name:"DatePicker",zigType:"craft.DatePicker",props:[{name:"value",type:"string",required:!1},{name:"min",type:"string",required:!1},{name:"max",type:"string",required:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-time-picker",{name:"TimePicker",zigType:"craft.TimePicker",props:[{name:"value",type:"string",required:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-color-picker",{name:"ColorPicker",zigType:"craft.ColorPicker",props:[{name:"value",type:"color",required:!1,default:"#000000"},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-data-table",{name:"DataTable",zigType:"craft.DataTable",props:[{name:"data",type:"array",required:!0},{name:"columns",type:"array",required:!0},{name:"sortable",type:"boolean",required:!1,default:!1},{name:"paginated",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-virtual-list",{name:"VirtualList",zigType:"craft.VirtualList",props:[{name:"items",type:"array",required:!0},{name:"itemHeight",type:"number",required:!1,default:48},{name:"renderItem",type:"callback",required:!0}],children:"none"}],["craft-tree-view",{name:"TreeView",zigType:"craft.TreeView",props:[{name:"data",type:"object",required:!0},{name:"expandable",type:"boolean",required:!1,default:!0}],children:"none"}]]);tC={compileToNative:SF,createHotReloadServer:fF,NATIVE_COMPONENTS:UK},eC=tC});import{spawn as cF}from"child_process";import k0 from"fs";import $P from"os";import t from"path";import x from"process";import{CLI as ZP}from"@stacksjs/clapp";var r4="0.2.39";N6();fG();a2();YQ();O4();e2();var __dirname="/home/runner/work/stx/stx/packages/stx/bin",q0=new ZP("stx");function uF($){let Z=typeof $==="string"?Number.parseInt($,10):$;if(Number.isNaN(Z))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(Z<1024||Z>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function mF($){try{if(!k0.existsSync($)){let Y=t.dirname($),X=t.basename($);if(k0.existsSync(Y)){let Q=k0.readdirSync(Y).filter((K)=>K.toLowerCase().includes(X.toLowerCase().substring(0,3))||K.endsWith(".stx")||K.endsWith(".md")),G=Q.length>0?`File not found. Similar files in ${Y}: ${Q.slice(0,3).join(", ")}`:`File not found. Directory ${Y} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${$}`,suggestion:G}}return{isValid:!1,error:`File does not exist: ${$}`,suggestion:"Check the file path and try again"}}if(k0.statSync($).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${$}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(Z){return{isValid:!1,error:`Cannot access file: ${$}`,suggestion:"Check file permissions and path"}}}function _K($){let Z=typeof $==="string"?Number.parseInt($,10):$;if(Number.isNaN(Z))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(Z<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(Z>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var n$=($)=>$.includes("*")||$.includes("?")||$.includes("{")||$.includes("["),YP=($)=>$.endsWith(".stx")||$.endsWith(".md");function i$($,Z=1){if(console.error(`\u274C ${$.error}`),$.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${$.suggestion}`);x.exit(Z)}async function XP($,Z){try{let Y=["test"],X=[];if($&&$.length>0)for(let W of $)if(n$(W))try{let U=await Array.fromAsync(new Bun.Glob(W).scan({onlyFiles:!0,absolute:!0}));if(U.length===0)console.warn(`Warning: No files found matching pattern: ${W}`);else if(X.push(...U),Z.verbose)console.log(`Found ${U.length} file(s) matching pattern: ${W}`)}catch(U){return console.error(`Error expanding glob pattern ${W}:`,U),!1}else X.push(W);if(X.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(Y.push(...X),Z.filter)Y.push("--pattern",Z.filter);if(Z.timeout)Y.push("--timeout",Z.timeout.toString());if(Z.reporter&&Z.reporter!=="default")if(Z.reporter==="junit"){let W=t.join($P.tmpdir(),`stx-test-report-${Date.now()}.xml`);Y.push("--reporter",Z.reporter),Y.push("--reporter-outfile",W)}else console.warn(`Warning: Reporter '${Z.reporter}' is not supported. Using default reporter.`);if(Z.coverage)Y.push("--coverage");if(Z.watch)Y.push("--watch");Y.push("--preload",t.join(__dirname,"../../../test-utils/happy-dom.ts"));let J={...x.env,STX_TEST_MODE:"true",STX_TEST_UI:Z.ui?"true":"false",STX_TEST_VERBOSE:Z.verbose?"true":"false"},Q="bun";if(Z.verbose)console.log(`Running: ${Q} ${Y.join(" ")}`);let G=performance.now(),K=cF(Q,Y,{stdio:"inherit",shell:!1,env:J});return new Promise((W)=>{K.on("close",(U)=>{let B=((performance.now()-G)/1000).toFixed(2);if(U===0)W(!0);else W(!1)}),x.on("SIGINT",()=>{console.log(`
18221
+ `)}return Y.get(Z.target)||GK($,Z)}function iC($,Z,Y){let X=[];function J(Q){X.push({name:Q.zigType,hash:gF(JSON.stringify(Q.props)),props:Object.keys(Q.props),events:Array.from(Q.events.keys()),slots:[],isNative:Q.zigType.startsWith("craft.")});for(let G of Q.children)J(G)}return J(Z),{version:"1.0.0",components:X,entry:$.id,assets:[],styles:$.styles}}function nC($,Z){return JSON.stringify({version:3,file:"output.zig",sources:["input.stx"],mappings:""})}function vF(){return`id_${++rC}`}function gF($){let Z=0;for(let Y=0;Y<$.length;Y++){let X=$.charCodeAt(Y);Z=(Z<<5)-Z+X,Z=Z&Z}return Math.abs(Z).toString(36)}function sC($){return $.charAt(0).toUpperCase()+$.slice(1)}function aC($){let Z=[],Y=/<script[^>]*>([\s\S]*?)<\/script>/gi,X;while((X=Y.exec($))!==null)Z.push(X[1]);return Z}function oC($){let Z=[],Y=/<style[^>]*>([\s\S]*?)<\/style>/gi,X;while((X=Y.exec($))!==null)Z.push(X[1]);return Z}function KK($){let Z=$.type==="component"?1:0;if($.children)for(let Y of $.children)Z+=KK(Y);return Z}function WK($){let Z=$.zigType.startsWith("craft.")?1:0;for(let Y of $.children)Z+=WK(Y);return Z}function fF($){return{start:async()=>{console.log("[craft-compiler] Hot reload server started")},stop:async()=>{console.log("[craft-compiler] Hot reload server stopped")},notifyChange:(Z)=>{console.log(`[craft-compiler] File changed: ${Z}`)}}}var UK,rC=0,tC,eC;var dF=D(()=>{UK=new Map([["craft-button",{name:"Button",zigType:"craft.Button",props:[{name:"variant",type:"string",required:!1,default:"primary"},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onclick",type:"callback",required:!1}],children:"single"}],["craft-text-input",{name:"TextInput",zigType:"craft.TextInput",props:[{name:"value",type:"string",required:!1,default:""},{name:"placeholder",type:"string",required:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-textarea",{name:"TextArea",zigType:"craft.TextArea",props:[{name:"value",type:"string",required:!1,default:""},{name:"placeholder",type:"string",required:!1},{name:"rows",type:"number",required:!1,default:3},{name:"disabled",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-checkbox",{name:"Checkbox",zigType:"craft.Checkbox",props:[{name:"checked",type:"boolean",required:!1,default:!1},{name:"label",type:"string",required:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-select",{name:"Select",zigType:"craft.Select",props:[{name:"value",type:"string",required:!1},{name:"options",type:"array",required:!0},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-slider",{name:"Slider",zigType:"craft.Slider",props:[{name:"value",type:"number",required:!1,default:0},{name:"min",type:"number",required:!1,default:0},{name:"max",type:"number",required:!1,default:100},{name:"step",type:"number",required:!1,default:1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-toggle",{name:"Toggle",zigType:"craft.Toggle",props:[{name:"checked",type:"boolean",required:!1,default:!1},{name:"disabled",type:"boolean",required:!1,default:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-modal",{name:"Modal",zigType:"craft.Modal",props:[{name:"open",type:"boolean",required:!1,default:!1},{name:"title",type:"string",required:!1},{name:"closable",type:"boolean",required:!1,default:!0},{name:"onclose",type:"callback",required:!1}],children:"multiple"}],["craft-alert",{name:"Alert",zigType:"craft.Alert",props:[{name:"variant",type:"string",required:!1,default:"info"},{name:"title",type:"string",required:!1},{name:"dismissible",type:"boolean",required:!1,default:!1}],children:"single"}],["craft-progress",{name:"ProgressBar",zigType:"craft.ProgressBar",props:[{name:"value",type:"number",required:!1,default:0},{name:"max",type:"number",required:!1,default:100},{name:"indeterminate",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-spinner",{name:"Spinner",zigType:"craft.Spinner",props:[{name:"size",type:"number",required:!1,default:24}],children:"none"}],["craft-avatar",{name:"Avatar",zigType:"craft.Avatar",props:[{name:"src",type:"string",required:!1},{name:"alt",type:"string",required:!1},{name:"size",type:"number",required:!1,default:40}],children:"none"}],["craft-badge",{name:"Badge",zigType:"craft.Badge",props:[{name:"variant",type:"string",required:!1,default:"default"}],children:"single"}],["craft-card",{name:"Card",zigType:"craft.Card",props:[{name:"padding",type:"number",required:!1,default:16}],children:"multiple"}],["craft-accordion",{name:"Accordion",zigType:"craft.Accordion",props:[{name:"title",type:"string",required:!0},{name:"open",type:"boolean",required:!1,default:!1}],children:"multiple"}],["craft-tabs",{name:"TabView",zigType:"craft.TabView",props:[{name:"activeTab",type:"number",required:!1,default:0},{name:"ontabchange",type:"callback",required:!1}],children:"multiple"}],["craft-tooltip",{name:"Tooltip",zigType:"craft.Tooltip",props:[{name:"content",type:"string",required:!0},{name:"position",type:"string",required:!1,default:"top"}],children:"single"}],["craft-date-picker",{name:"DatePicker",zigType:"craft.DatePicker",props:[{name:"value",type:"string",required:!1},{name:"min",type:"string",required:!1},{name:"max",type:"string",required:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-time-picker",{name:"TimePicker",zigType:"craft.TimePicker",props:[{name:"value",type:"string",required:!1},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-color-picker",{name:"ColorPicker",zigType:"craft.ColorPicker",props:[{name:"value",type:"color",required:!1,default:"#000000"},{name:"onchange",type:"callback",required:!1}],children:"none"}],["craft-data-table",{name:"DataTable",zigType:"craft.DataTable",props:[{name:"data",type:"array",required:!0},{name:"columns",type:"array",required:!0},{name:"sortable",type:"boolean",required:!1,default:!1},{name:"paginated",type:"boolean",required:!1,default:!1}],children:"none"}],["craft-virtual-list",{name:"VirtualList",zigType:"craft.VirtualList",props:[{name:"items",type:"array",required:!0},{name:"itemHeight",type:"number",required:!1,default:48},{name:"renderItem",type:"callback",required:!0}],children:"none"}],["craft-tree-view",{name:"TreeView",zigType:"craft.TreeView",props:[{name:"data",type:"object",required:!0},{name:"expandable",type:"boolean",required:!1,default:!0}],children:"none"}]]);tC={compileToNative:SF,createHotReloadServer:fF,NATIVE_COMPONENTS:UK},eC=tC});import{spawn as cF}from"child_process";import k0 from"fs";import $P from"os";import t from"path";import x from"process";import{CLI as ZP}from"@stacksjs/clapp";var r4="0.2.40";N6();fG();a2();YQ();O4();e2();var __dirname="/home/runner/work/stx/stx/packages/stx/bin",q0=new ZP("stx");function uF($){let Z=typeof $==="string"?Number.parseInt($,10):$;if(Number.isNaN(Z))return{isValid:!1,error:"Port must be a valid number",suggestion:"Try using a number between 1024 and 65535"};if(Z<1024||Z>65535)return{isValid:!1,error:"Port must be between 1024 and 65535",suggestion:"Try using a port between 1024 and 65535"};return{isValid:!0}}function mF($){try{if(!k0.existsSync($)){let Y=t.dirname($),X=t.basename($);if(k0.existsSync(Y)){let Q=k0.readdirSync(Y).filter((K)=>K.toLowerCase().includes(X.toLowerCase().substring(0,3))||K.endsWith(".stx")||K.endsWith(".md")),G=Q.length>0?`File not found. Similar files in ${Y}: ${Q.slice(0,3).join(", ")}`:`File not found. Directory ${Y} exists but doesn't contain the specified file.`;return{isValid:!1,error:`File does not exist: ${$}`,suggestion:G}}return{isValid:!1,error:`File does not exist: ${$}`,suggestion:"Check the file path and try again"}}if(k0.statSync($).isDirectory())return{isValid:!1,error:`Expected file but got directory: ${$}`,suggestion:"Specify a .stx or .md file path"};return{isValid:!0}}catch(Z){return{isValid:!1,error:`Cannot access file: ${$}`,suggestion:"Check file permissions and path"}}}function _K($){let Z=typeof $==="string"?Number.parseInt($,10):$;if(Number.isNaN(Z))return{isValid:!1,error:"Timeout must be a valid number",suggestion:"Specify timeout in milliseconds (e.g., 5000 for 5 seconds)"};if(Z<100)return{isValid:!1,error:"Timeout too short (minimum 100ms)",suggestion:"Use a timeout of at least 100ms"};if(Z>300000)return{isValid:!1,error:"Timeout too long (maximum 5 minutes)",suggestion:"Use a timeout of less than 300000ms (5 minutes)"};return{isValid:!0}}var n$=($)=>$.includes("*")||$.includes("?")||$.includes("{")||$.includes("["),YP=($)=>$.endsWith(".stx")||$.endsWith(".md");function i$($,Z=1){if(console.error(`\u274C ${$.error}`),$.suggestion)console.error(`\uD83D\uDCA1 suggestion: ${$.suggestion}`);x.exit(Z)}async function XP($,Z){try{let Y=["test"],X=[];if($&&$.length>0)for(let W of $)if(n$(W))try{let U=await Array.fromAsync(new Bun.Glob(W).scan({onlyFiles:!0,absolute:!0}));if(U.length===0)console.warn(`Warning: No files found matching pattern: ${W}`);else if(X.push(...U),Z.verbose)console.log(`Found ${U.length} file(s) matching pattern: ${W}`)}catch(U){return console.error(`Error expanding glob pattern ${W}:`,U),!1}else X.push(W);if(X.length===0)return console.error("Error: No test files found matching the provided patterns."),!1;if(Y.push(...X),Z.filter)Y.push("--pattern",Z.filter);if(Z.timeout)Y.push("--timeout",Z.timeout.toString());if(Z.reporter&&Z.reporter!=="default")if(Z.reporter==="junit"){let W=t.join($P.tmpdir(),`stx-test-report-${Date.now()}.xml`);Y.push("--reporter",Z.reporter),Y.push("--reporter-outfile",W)}else console.warn(`Warning: Reporter '${Z.reporter}' is not supported. Using default reporter.`);if(Z.coverage)Y.push("--coverage");if(Z.watch)Y.push("--watch");Y.push("--preload",t.join(__dirname,"../../../test-utils/happy-dom.ts"));let J={...x.env,STX_TEST_MODE:"true",STX_TEST_UI:Z.ui?"true":"false",STX_TEST_VERBOSE:Z.verbose?"true":"false"},Q="bun";if(Z.verbose)console.log(`Running: ${Q} ${Y.join(" ")}`);let G=performance.now(),K=cF(Q,Y,{stdio:"inherit",shell:!1,env:J});return new Promise((W)=>{K.on("close",(U)=>{let B=((performance.now()-G)/1000).toFixed(2);if(U===0)W(!0);else W(!1)}),x.on("SIGINT",()=>{console.log(`
18222
18222
  Test run interrupted`),K.kill("SIGINT"),x.exit(1)})})}catch(Y){return console.error("Error running tests:",Y instanceof Error?Y.message:String(Y)),!1}}var JP=x.argv.length>=3&&(YP(x.argv[2])&&k0.existsSync(x.argv[2])||n$(x.argv[2]));if(JP){let $=x.argv[2],Z={port:3000,watch:!0,cache:!0,markdown:{syntaxHighlighting:{enabled:!0,serverSide:!0,defaultTheme:"github-dark",highlightUnknownLanguages:!0}}};for(let Y=3;Y<x.argv.length;Y++){let X=x.argv[Y];if(X==="--port"&&Y+1<x.argv.length){let J=uF(x.argv[++Y]);if(!J.isValid)i$(J);Z.port=Number.parseInt(x.argv[Y],10)}else if(X==="--no-watch")Z.watch=!1;else if(X==="--highlight-theme"&&Y+1<x.argv.length){if(!Z.markdown)Z.markdown={};if(!Z.markdown.syntaxHighlighting)Z.markdown.syntaxHighlighting={};Z.markdown.syntaxHighlighting.defaultTheme=x.argv[++Y]}else if(X==="--no-highlight"){if(!Z.markdown)Z.markdown={};if(!Z.markdown.syntaxHighlighting)Z.markdown.syntaxHighlighting={};Z.markdown.syntaxHighlighting.enabled=!1}else if(X==="--no-highlight-unknown"){if(!Z.markdown)Z.markdown={};if(!Z.markdown.syntaxHighlighting)Z.markdown.syntaxHighlighting={};Z.markdown.syntaxHighlighting.highlightUnknownLanguages=!1}else if(X==="--no-cache")Z.cache=!1;else if(X==="--native")Z.native=!0}if(n$($))try{let Y=await Array.fromAsync(new Bun.Glob($).scan({onlyFiles:!0,absolute:!0})),X=$.endsWith(".stx")?Y.filter((K)=>K.endsWith(".stx")):$.endsWith(".md")?Y.filter((K)=>K.endsWith(".md")):Y.filter((K)=>K.endsWith(".stx")||K.endsWith(".md")),J=$.split("*")[0].replace(/\/$/,"")||".",Q=t.resolve(J);try{let K=new Bun.Glob("**/*.stx"),U=(await Array.fromAsync(K.scan({cwd:Q,onlyFiles:!0,absolute:!0}))).filter((_)=>/\[.+\]/.test(t.basename(_)));for(let _ of U)if(!X.includes(_))X.push(_)}catch{}if(X.length===0)console.error(`Error: No STX or Markdown files found matching pattern: ${$}`),x.exit(1);if(!await r7(X,Z))x.exit(1)}catch(Y){console.error("Failed to process files:",Y),x.exit(1)}else n7($,Z).catch((Y)=>{console.error("Failed to start dev server:",Y),x.exit(1)})}else{let $=function(X,J){let Q=[];for(let G=0;G<=J.length;G++)Q[G]=[G];for(let G=0;G<=X.length;G++)Q[0][G]=G;for(let G=1;G<=J.length;G++)for(let K=1;K<=X.length;K++)if(J.charAt(G-1)===X.charAt(K-1))Q[G][K]=Q[G-1][K-1];else Q[G][K]=Math.min(Q[G-1][K-1]+1,Q[G][K-1]+1,Q[G-1][K]+1);return Q[J.length][X.length]};q0.command("docs","Generate documentation for components, templates, and directives").option("--output <dir>","Output directory for documentation",{default:"docs"}).option("--format <format>","Documentation format (markdown, html, json)",{default:"markdown"}).option("--components-dir <dir>","Components directory",{default:"components"}).option("--templates-dir <dir>","Templates directory",{default:"."}).option("--no-components","Disable components documentation").option("--no-templates","Disable templates documentation").option("--no-directives","Disable directives documentation").option("--extra-content <content>","Extra content to include in documentation").example("stx docs --output docs --format html").action(async(X)=>{try{if(await s2(X))console.log("Documentation generated successfully."),x.exit(0);else console.error("Documentation generation failed."),x.exit(1)}catch(J){console.error("Error generating documentation:",J),x.exit(1)}}),q0.command("iconify <command>","Generate Iconify icon packages").option("--output <dir>","Output directory for generated packages",{default:"packages"}).option("--icons <icons>","Comma-separated list of specific icons to generate").example("stx iconify list").example("stx iconify generate mdi").example("stx iconify generate lucide --icons home,settings,user").action(async(X,J)=>{try{let{fetchCollections:Q,generatePackage:G}=await import("@stacksjs/iconify-generator");if(X==="list"){console.log(`
18223
18223
  \uD83D\uDCDA Fetching available icon collections...
18224
18224
  `);let K=await Q(),W=Object.entries(K).sort((U,_)=>_[1].total-U[1].total);console.log(`Available collections:
package/dist/index.js CHANGED
@@ -15032,11 +15032,11 @@ ${$}`}function o0($){return $.replace(/&/g,"&amp;").replace(/"/g,"&quot;").repla
15032
15032
  `)}async function ZI(){if(L7!==null)return L7;try{let $=await import("stx-router");if(typeof $.getRouterScript==="function")L7=$.getRouterScript();else L7=""}catch{L7=""}return L7}async function B6($,Z){let Y=await ZI();if(!Y)return $;let X={interceptAllLinks:!0,container:"body",...Z},Q=`${`<script>window.__stxRouterConfig=${JSON.stringify(X)};</script>
15033
15033
  `}<script>${Y}</script>`;if(/<\/body>/i.test($))return $.replace(/<\/body>/i,`${Q}
15034
15034
  </body>`);return`${$}
15035
- ${Q}`}var L7=null;function U6($,Z){if(Z.theme===!1)return $;let Y=typeof Z.theme==="object"&&Z.theme!==null?Z.theme:{},X=Y.default??"dark",J=Y.storageKey??"theme",Q=Y.colors?.light??"#ffffff",G=Y.colors?.dark??"#000000";if(X==="dark"){if(!/<html\b[^>]*\bclass=/.test($))$=$.replace(/<html\b([^>]*)>/i,'<html$1 class="dark">');else if(!/<html\b[^>]*\bclass="[^"]*\bdark\b/.test($))$=$.replace(/<html\b([^>]*\bclass=")([^"]*)(")/i,"<html$1$2 dark$3")}if(!$.includes("data-stx-theme-meta")&&/<head\b[^>]*>/i.test($)){let W=['<meta name="color-scheme" content="dark light" data-stx-theme-meta="1">',`<meta name="theme-color" content="${X==="dark"?G:Q}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: light)" content="${Q}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${G}" data-stx-theme-meta="1">`].join(`
15035
+ ${Q}`}var L7=null;function U6($,Z){if(Z.theme===!1)return $;let Y=typeof Z.theme==="object"&&Z.theme!==null?Z.theme:{},X=Y.default??"dark",J=Y.storageKey??"theme",Q=Y.colors?.light??"#ffffff",G=Y.colors?.dark??"#000000";if(X==="dark"){if(!/<html\b[^>]*\bclass=/.test($))$=$.replace(/<html\b([^>]*)>/i,'<html$1 class="dark">');else if(!/<html\b[^>]*\bclass="[^"]*\bdark\b/.test($))$=$.replace(/<html\b([^>]*\bclass=")([^"]*)(")/i,"<html$1$2 dark$3")}if(!$.includes("data-stx-theme-meta")&&/<head\b[^>]*>/i.test($)){let K=['<meta name="color-scheme" content="dark light" data-stx-theme-meta="1">',`<meta name="theme-color" media="(prefers-color-scheme: light)" content="${Q}" data-stx-theme-meta="1">`,`<meta name="theme-color" media="(prefers-color-scheme: dark)" content="${G}" data-stx-theme-meta="1">`].join(`
15036
15036
  `);$=$.replace(/<head\b([^>]*)>/i,`<head$1>
15037
- ${W}`)}if(!$.includes("__stxThemeGuard")&&/<head\b[^>]*>/i.test($)){let K=`<script data-stx-theme-guard="1">${YI(X,J,Q,G)};window.__stxThemeGuard=1;</script>`;$=$.replace(/<head\b([^>]*)>/i,`<head$1>
15037
+ ${K}`)}if(!$.includes("__stxThemeGuard")&&/<head\b[^>]*>/i.test($)){let K=`<script data-stx-theme-guard="1">${YI(X,J,Q,G)};window.__stxThemeGuard=1;</script>`;$=$.replace(/<head\b([^>]*)>/i,`<head$1>
15038
15038
  ${K}`)}if(!$.includes("__stxThemeToggle")&&/<\/body>/i.test($)){let K=`<script data-stx-theme-toggle="1">${XI(J,Q,G)};window.__stxThemeToggle=1;</script>`;$=$.replace(/<\/body>/i,`${K}
15039
- </body>`)}return $}var YI=($,Z,Y,X)=>`(function(){try{var k=${JSON.stringify(Z)};var t=localStorage.getItem(k);var html=document.documentElement;var isDark=t===null?(${JSON.stringify($)}==='dark'||(${JSON.stringify($)}==='auto'&&window.matchMedia('(prefers-color-scheme: dark)').matches)):t==='dark';html.classList[isDark?'add':'remove']('dark');var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(X)}:${JSON.stringify(Y)})}catch(e){}})();`,XI=($,Z,Y)=>`document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#theme-toggle');if(!t)return;var html=document.documentElement;var isDark=html.classList.toggle('dark');try{localStorage.setItem(${JSON.stringify($)},isDark?'dark':'light')}catch(e){}var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(Y)}:${JSON.stringify(Z)})});`;import{existsSync as JI,readFileSync as QI}from"fs";import{join as GI,resolve as KI}from"path";import WI from"process";function z6($,Z=WI.cwd()){let Y=$.i18n;if(!Y||!Array.isArray(Y.locales)||Y.locales.length===0)return null;let X=Y.defaultLocale??Y.locales[0],J=_I(Y,Z);return{locales:Y.locales,defaultLocale:X,labels:Y.labels??Object.fromEntries(Y.locales.map((Q)=>[Q,Q.toUpperCase()])),translations:J,pickerSelector:Y.pickerSelector??"#lang-picker"}}function _I($,Z){let Y=$.translations??{},X={},J=$.translationsDir,Q=J===!1?null:KI(Z,typeof J==="string"&&J?J:"translations"),G=$.format??"json";for(let K of $.locales){let W=Q?BI(Q,K,G):{};X[K]={...W,...Y[K]??{}}}return X}function BI($,Z,Y){let X=Y==="json"?[`${Z}.json`]:[`${Z}.${Y}`,`${Z}.${Y==="yaml"?"yml":"yaml"}`];for(let J of X){let Q=GI($,J);if(!JI(Q))continue;try{let G=QI(Q,"utf8"),K=Y==="json"?JSON.parse(G):UI(G);return $H(K)}catch{continue}}return{}}function $H($,Z="",Y={}){if(!$||typeof $!=="object")return Y;for(let[X,J]of Object.entries($)){let Q=Z?`${Z}.${X}`:X;if(J&&typeof J==="object"&&!Array.isArray(J))$H(J,Q,Y);else if(typeof J==="string")Y[Q]=J;else if(typeof J==="number"||typeof J==="boolean")Y[Q]=String(J)}return Y}function UI($){let Z={},Y=[{obj:Z,indent:-1}];for(let X of $.split(`
15039
+ </body>`)}return $}var YI=($,Z,Y,X)=>`(function(){function read(){try{var k=${JSON.stringify(Z)};var t=localStorage.getItem(k);return t===null?(${JSON.stringify($)}==='dark'||(${JSON.stringify($)}==='auto'&&window.matchMedia('(prefers-color-scheme: dark)').matches)):t==='dark'}catch(e){return ${JSON.stringify($)}==='dark'}}function apply(){var isDark=read();var html=document.documentElement;html.classList[isDark?'add':'remove']('dark');var color=isDark?${JSON.stringify(X)}:${JSON.stringify(Y)};var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc){tc.setAttribute('content',color)}else if(document.head){tc=document.createElement('meta');tc.setAttribute('name','theme-color');tc.setAttribute('content',color);tc.setAttribute('data-stx-theme-meta','1');document.head.insertBefore(tc,document.head.firstChild)}}apply();window.addEventListener('stx:navigate',apply);window.addEventListener('popstate',apply)})();`,XI=($,Z,Y)=>`document.addEventListener('click',function(e){var t=e.target&&e.target.closest&&e.target.closest('#theme-toggle');if(!t)return;var html=document.documentElement;var isDark=html.classList.toggle('dark');try{localStorage.setItem(${JSON.stringify($)},isDark?'dark':'light')}catch(e){}var tc=document.querySelector('meta[name="theme-color"]:not([media])');if(tc)tc.setAttribute('content',isDark?${JSON.stringify(Y)}:${JSON.stringify(Z)})});`;import{existsSync as JI,readFileSync as QI}from"fs";import{join as GI,resolve as KI}from"path";import WI from"process";function z6($,Z=WI.cwd()){let Y=$.i18n;if(!Y||!Array.isArray(Y.locales)||Y.locales.length===0)return null;let X=Y.defaultLocale??Y.locales[0],J=_I(Y,Z);return{locales:Y.locales,defaultLocale:X,labels:Y.labels??Object.fromEntries(Y.locales.map((Q)=>[Q,Q.toUpperCase()])),translations:J,pickerSelector:Y.pickerSelector??"#lang-picker"}}function _I($,Z){let Y=$.translations??{},X={},J=$.translationsDir,Q=J===!1?null:KI(Z,typeof J==="string"&&J?J:"translations"),G=$.format??"json";for(let K of $.locales){let W=Q?BI(Q,K,G):{};X[K]={...W,...Y[K]??{}}}return X}function BI($,Z,Y){let X=Y==="json"?[`${Z}.json`]:[`${Z}.${Y}`,`${Z}.${Y==="yaml"?"yml":"yaml"}`];for(let J of X){let Q=GI($,J);if(!JI(Q))continue;try{let G=QI(Q,"utf8"),K=Y==="json"?JSON.parse(G):UI(G);return $H(K)}catch{continue}}return{}}function $H($,Z="",Y={}){if(!$||typeof $!=="object")return Y;for(let[X,J]of Object.entries($)){let Q=Z?`${Z}.${X}`:X;if(J&&typeof J==="object"&&!Array.isArray(J))$H(J,Q,Y);else if(typeof J==="string")Y[Q]=J;else if(typeof J==="number"||typeof J==="boolean")Y[Q]=String(J)}return Y}function UI($){let Z={},Y=[{obj:Z,indent:-1}];for(let X of $.split(`
15040
15040
  `)){let J=X.replace(/#.*$/,"").trimEnd();if(!J.trim())continue;let Q=J.search(/\S/);if(Q===-1)continue;while(Y.length>1&&Y[Y.length-1].indent>=Q)Y.pop();let G=Y[Y.length-1].obj,K=J.match(/^(\s*)(\S[^:]*):\s*(.*)$/);if(!K)continue;let[,,W,_]=K,B=W.trim(),U=_.trim();if(U==="")G[B]={},Y.push({obj:G[B],indent:Q});else G[B]=zI(U)}return Z}function zI($){if($.startsWith("'")&&$.endsWith("'")||$.startsWith('"')&&$.endsWith('"'))return $.slice(1,-1);return $}function UZ($,Z,Y){let X=$.translations[Z]?.[Y];if(typeof X==="string")return X;let J=$.translations[$.defaultLocale]?.[Y];if(typeof J==="string")return J;return Y}function q6($,Z,Y){return $.replace(/\{t:([a-zA-Z][\w.-]*)\}/g,(X,J)=>qI(UZ(Z,Y,J)))}function t1($,Z,Y){if(Z===Y)return $;if($==="/")return`/${Z}/`;if($==="/404.html")return`/${Z}/404.html`;return`/${Z}${$}`}function zQ($,Z){for(let Y of Z){if($===`/${Y}`||$===`/${Y}/`)return{locale:Y,path:"/"};if($.startsWith(`/${Y}/`))return{locale:Y,path:$.slice(Y.length+1)}}return{locale:null,path:$}}function j6($,Z,Y){let X=$.replace(/\/$/,""),J=[];for(let G of Y.locales){let K=`${X}${t1(Z,G,Y.defaultLocale)}`;J.push(`<link rel="alternate" hreflang="${UQ(G)}" href="${UQ(K)}">`)}let Q=`${X}${t1(Z,Y.defaultLocale,Y.defaultLocale)}`;return J.push(`<link rel="alternate" hreflang="x-default" href="${UQ(Q)}">`),J.join(`
15041
15041
  `)}function H6($,Z){return`<script data-stx-lang-picker="1">window.__stxI18n=${JSON.stringify({locales:$.locales,defaultLocale:$.defaultLocale,current:Z,pickerSelector:$.pickerSelector})};(function(){var d=window.__stxI18n;function localeFromPath(p){for(var i=0;i<d.locales.length;i++){var c=d.locales[i];if(p==='/'+c||p==='/'+c+'/')return c;if(p.indexOf('/'+c+'/')===0)return c}return d.defaultLocale}function localePathFor(loc,p){var stripped=p;for(var i=0;i<d.locales.length;i++){var c=d.locales[i];if(p==='/'+c||p==='/'+c+'/'){stripped='/';break}if(p.indexOf('/'+c+'/')===0){stripped=p.slice(c.length+1);break}}if(loc===d.defaultLocale)return stripped;if(stripped==='/')return '/'+loc+'/';return '/'+loc+stripped}function syncFromUrl(){var loc=localeFromPath(location.pathname);d.current=loc;var picker=document.querySelector(d.pickerSelector);if(picker){var btns=picker.querySelectorAll('[data-lang]');for(var i=0;i<btns.length;i++){if(btns[i].getAttribute('data-lang')===loc)btns[i].setAttribute('aria-current','true');else btns[i].removeAttribute('aria-current')}}if(document.documentElement.lang!==loc)document.documentElement.lang=loc}syncFromUrl();window.addEventListener('stx:navigate',syncFromUrl);window.addEventListener('popstate',syncFromUrl);document.addEventListener('click',function(e){var btn=e.target&&e.target.closest&&e.target.closest('['+'data-lang'+']');if(!btn)return;var picker=document.querySelector(d.pickerSelector);if(!picker||!picker.contains(btn))return;e.preventDefault();var loc=btn.getAttribute('data-lang');var dest=localePathFor(loc,location.pathname);if(window.__stxRouter&&window.__stxRouter.navigate)window.__stxRouter.navigate(dest);else location.assign(dest)});})();</script>`}function UQ($){return $.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function qI($){return $.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var qQ=()=>{};var{Glob:jI}=globalThis.Bun;import{cpSync as HI,existsSync as qZ,mkdirSync as ZH,readFileSync as YH,readdirSync as OI,rmSync as LI,statSync as FI,unlinkSync as VI,writeFileSync as zZ}from"fs";import{dirname as NI,join as e1,relative as AI}from"path";import XH from"process";import wI from"bun-plugin-stx";async function OQ($){let Z=Date.now(),Y=$.pagesDir??"pages",X=$.outDir??"dist",J=$.publicDir??"public";if(!$.noClean)LI(X,{recursive:!0,force:!0});ZH(X,{recursive:!0});let Q=new jI(`${Y}/**/*.stx`),G=await Array.fromAsync(Q.scan("."));if(G.length===0)throw Error(`No .stx files found in ${Y}/`);let K=await Bun.build({entrypoints:G,outdir:X,plugins:[wI()],naming:{entry:"[name].[ext]"}});if(!K.success)throw console.error(K.logs),Error("Build failed");TI(X);let W=LQ(X).filter((q)=>q.endsWith(".html")),_=z6($,XH.cwd());for(let q of W){let j=e1(X,q),H=YH(j,"utf8"),O=jQ(q),F=_?_.locales:[$.seo?.locale?.split(/[_-]/)[0]??"en"];for(let L of F){let V=H;if(V=EI(V),_)V=q6(V,_,L);if(V=await V0(V,XH.cwd()),V=K6(V,$,$.pages?.[O],O),_)V=II(V,$,_,L,O);if(V=U6(V,$),V=DI(V),_)V=V.replace(/<\/body>/i,`${H6(_,L)}
15042
15042
  </body>`);if($.spa!==!1)V=await B6(V,$.router);let A=_?MI(O,L,_.defaultLocale):q,N=e1(X,A);if(ZH(RI(N),{recursive:!0}),zZ(N,V),_&&L!==_.defaultLocale&&A!==q);}}if(qZ(J))HI(J,X,{recursive:!0});let B=e1(X,"404.html");if(!qZ(B)&&qZ(e1(X,"index.html"))){let q=YH(e1(X,"index.html"),"utf8").replace(/<title>[^<]*<\/title>/i,`<title>404 \u2014 ${kI($.name)}</title>`);zZ(B,q)}if($.sitemap!==!1){let q=[],j=W.filter((O)=>O!=="404.html").map(jQ),H=_?_.locales:[null];for(let O of j){let F=$.pages?.[O];for(let L of H){let V=L&&_?t1(O,L,_.defaultLocale):O;q.push({path:V,page:F})}}zZ(e1(X,"sitemap.xml"),W6($,q))}let U=_6($);if(U!==null)zZ(e1(X,"robots.txt"),U);let z=W.map(jQ);return{outDir:X,pages:z,durationMs:Date.now()-Z}}function RI($){return NI($)}function MI($,Z,Y){let X=t1($,Z,Y);if(X==="/")return"index.html";let J=X.replace(/^\//,"").replace(/\/$/,"");if(!J.includes("/")){if(Z!==Y&&J===Z)return`${Z}/index.html`;return`${J}.html`}return`${J}.html`.replace(/\.html\.html$/,".html")}function jQ($){if($==="index.html")return"/";return`/${$.replace(/\.html$/,"").replace(/\/index$/,"")}`}function LQ($,Z=$){let Y=[];if(!qZ($))return Y;for(let X of OI($,{withFileTypes:!0})){let J=e1($,X.name);if(X.isDirectory())Y.push(...LQ(J,Z));else Y.push(AI(Z,J))}return Y}function TI($){for(let Z of LQ($)){if(!/^chunk-.*\.js(?:\.map)?$/.test(Z))continue;let Y=e1($,Z);try{if(FI(Y).size===0)VI(Y)}catch{}}}function EI($){return $.replace(/<script[^>]*src=["']\.\/chunk-[^"']*\.js["'][^>]*><\/script>\s*/g,"")}function II($,Z,Y,X,J){if(!Y)return $;if(/<html\b[^>]*\blang=/i.test($))$=$.replace(/<html\b([^>]*)\blang="[^"]*"/i,`<html$1lang="${X}"`);else $=$.replace(/<html\b([^>]*)>/i,`<html$1 lang="${X}">`);let Q=`${Z.url.replace(/\/$/,"")}${t1(J,X,Y.defaultLocale)}`;if(/<link rel="canonical"/.test($))$=$.replace(/<link rel="canonical"[^>]*>/,`<link rel="canonical" href="${HQ(Q)}">`);let G=X.includes("_")||X.includes("-")?X:X.toLowerCase();if(/<meta property="og:locale"/.test($))$=$.replace(/<meta property="og:locale"[^>]*>/,`<meta property="og:locale" content="${HQ(G)}">`);if(/<meta property="og:url"/.test($))$=$.replace(/<meta property="og:url"[^>]*>/,`<meta property="og:url" content="${HQ(Q)}">`);let K=j6(Z.url,J,Y);if(!$.includes("hreflang="))$=$.replace(/<link rel="canonical"[^>]*>/,(W)=>`${K}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.39",
4
+ "version": "0.2.40",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",