@stacksjs/stx 0.2.41 → 0.2.42

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
@@ -14795,7 +14795,7 @@ ${Q}`}var h$=null;function m7($,Z){if(Z.theme===!1)return $;let Y=typeof Z.theme
14795
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
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
- `)){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 bG($,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="${SG(G)}" href="${SG(K)}">`)}let Q=`${X}${U4(Z,Y.defaultLocale,Y.defaultLocale)}`;return J.push(`<link rel="alternate" hreflang="x-default" href="${SG(Q)}">`),J.join(`
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,Q)=>{let G=UY(Z,Y,Q);return J==="!"?G:yS(G)})}function U4($,Z,Y){if(Z===Y)return $;if($==="/")return`/${Z}/`;if($==="/404.html")return`/${Z}/404.html`;return`/${Z}${$}`}function bG($,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="${SG(G)}" href="${SG(K)}">`)}let Q=`${X}${U4(Z,Y.defaultLocale,Y.defaultLocale)}`;return J.push(`<link rel="alternate" hreflang="x-default" href="${SG(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 SG($){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 CG=()=>{};var{Glob:xS}=globalThis.Bun;import{cpSync as vS,existsSync as zY,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((j)=>j.endsWith(".html")),U=c7($,fO.cwd()),_=new Set(W.map(BY));for(let j of W){let H=_4(X,j),O=gO(H,"utf8"),F=BY(j),L=U?U.locales:[$.seo?.locale?.split(/[_-]/)[0]??"en"];for(let V of L){let N=O;if(N=nS(N),U)N=p7(N,U,V);if(N=await E0(N,fO.cwd()),N=f7(N,$,$.pages?.[F],F),U)N=rS(N,$,U,V,F),N=sS(N,V,U.defaultLocale,_);if(N=m7(N,$),N=aS(N),U)N=N.replace(/<\/body>/i,`${i7(U,V)}
14800
14800
  </body>`);if($.spa!==!1)N=await u7(N,$.router);let A=U?lS(F,V,U.defaultLocale):j,w=_4(X,A);if(vO(pS(w),{recursive:!0}),_Y(w,N),U&&V!==U.defaultLocale&&A!==j);}}if(zY(J))vS(J,X,{recursive:!0});let B=_4(X,"404.html");if(!zY(B)&&zY(_4(X,"index.html"))){let j=gO(_4(X,"index.html"),"utf8").replace(/<title>[^<]*<\/title>/i,`<title>404 \u2014 ${oS($.name)}</title>`);_Y(B,j)}if($.sitemap!==!1){let j=[],H=W.filter((F)=>F!=="404.html").map(BY),O=U?U.locales:[null];for(let F of H){let L=$.pages?.[F];for(let V of O){let N=V&&U?U4(F,V,U.defaultLocale):F;j.push({path:N,page:L})}}_Y(_4(X,"sitemap.xml"),h7($,j))}let z=d7($);if(z!==null)_Y(_4(X,"robots.txt"),z);let q=W.map(BY);return{outDir:X,pages:q,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 BY($){if($==="index.html")return"/";return`/${$.replace(/\.html$/,"").replace(/\/index$/,"")}`}function xG($,Z=$){let Y=[];if(!zY($))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}
14801
14801
  ${W}`);return $}function PG($){return $.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function sS($,Z,Y,X){if(Z===Y)return $;return $.replace(/<a\b([^>]*?)\bhref="(\/[^"]*)"([^>]*)>/gi,(J,Q,G,K)=>{if(G.startsWith("//"))return J;if(G===`/${Z}`||G===`/${Z}/`||G.startsWith(`/${Z}/`))return J;let W=G.match(/^(\/[^?#]*)(.*)$/);if(!W)return J;let[,U,_]=W,B=U==="/"?"/":U.replace(/\/$/,"");if(!X.has(B))return J;let z=B==="/"?`/${Z}/`:`/${Z}${B}`;return`<a${Q}href="${z}${_}"${K}>`})}function aS($){if(/<main\b/i.test($)||/\bdata-stx-content\b/i.test($))return $;let Z=$.match(/<body\b[^>]*>/i),Y=$.search(/<\/body\s*>/i);if(!Z||Y<0)return $;let X=Z.index+Z[0].length,J=$.slice(X,Y),Q=0,G=[...J.matchAll(/<\/nav>/gi)];if(G.length>0){let z=G[G.length-1];Q=z.index+z[0].length}let K=J.length,W=J.search(/<footer\b/i);if(W!==-1)K=Math.min(K,W);let U=J.search(/<script\b[^>]*data-stx-(?:theme-toggle|reparent-progress)\b/i);if(U!==-1)K=Math.min(K,U);if(K<=Q)return $;let _=J.slice(Q,K);if(!_.trim())return $;let B=`${J.slice(0,Q)}
@@ -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 iC($,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 nC($,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 rC($,Z){return JSON.stringify({version:3,file:"output.zig",sources:["input.stx"],mappings:""})}function vF(){return`id_${++sC}`}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 aC($){return $.charAt(0).toUpperCase()+$.slice(1)}function oC($){let Z=[],Y=/<script[^>]*>([\s\S]*?)<\/script>/gi,X;while((X=Y.exec($))!==null)Z.push(X[1]);return Z}function tC($){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,sC=0,eC,$P;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"}]]);eC={compileToNative:SF,createHotReloadServer:fF,NATIVE_COMPONENTS:UK},$P=eC});import{spawn as cF}from"child_process";import k0 from"fs";import ZP from"os";import t from"path";import x from"process";import{CLI as YP}from"@stacksjs/clapp";var r4="0.2.41";N6();fG();o2();XQ();O4();$Q();var __dirname="/home/runner/work/stx/stx/packages/stx/bin",q0=new YP("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("["),XP=($)=>$.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 JP($,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(ZP.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 nC($,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 rC($,Z){return JSON.stringify({version:3,file:"output.zig",sources:["input.stx"],mappings:""})}function vF(){return`id_${++sC}`}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 aC($){return $.charAt(0).toUpperCase()+$.slice(1)}function oC($){let Z=[],Y=/<script[^>]*>([\s\S]*?)<\/script>/gi,X;while((X=Y.exec($))!==null)Z.push(X[1]);return Z}function tC($){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,sC=0,eC,$P;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"}]]);eC={compileToNative:SF,createHotReloadServer:fF,NATIVE_COMPONENTS:UK},$P=eC});import{spawn as cF}from"child_process";import k0 from"fs";import ZP from"os";import t from"path";import x from"process";import{CLI as YP}from"@stacksjs/clapp";var r4="0.2.42";N6();fG();o2();XQ();O4();$Q();var __dirname="/home/runner/work/stx/stx/packages/stx/bin",q0=new YP("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("["),XP=($)=>$.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 JP($,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(ZP.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 QP=x.argv.length>=3&&(XP(x.argv[2])&&k0.existsSync(x.argv[2])||n$(x.argv[2]));if(QP){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 a2(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
@@ -15037,7 +15037,7 @@ ${Q}`}var L7=null;function U6($,Z){if(Z.theme===!1)return $;let Y=typeof Z.theme
15037
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
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 q6($,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
- `)){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]=qI(U)}return Z}function qI($){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 z6($,Z,Y){return $.replace(/\{t:([a-zA-Z][\w.-]*)\}/g,(X,J)=>zI(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="${qQ(G)}" href="${qQ(K)}">`)}let Q=`${X}${t1(Z,Y.defaultLocale,Y.defaultLocale)}`;return J.push(`<link rel="alternate" hreflang="x-default" href="${qQ(Q)}">`),J.join(`
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]=qI(U)}return Z}function qI($){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 z6($,Z,Y){return $.replace(/\{t(!?):([a-zA-Z][\w.-]*)\}/g,(X,J,Q)=>{let G=UZ(Z,Y,Q);return J==="!"?G:zI(G)})}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="${qQ(G)}" href="${qQ(K)}">`)}let Q=`${X}${t1(Z,Y.defaultLocale,Y.defaultLocale)}`;return J.push(`<link rel="alternate" hreflang="x-default" href="${qQ(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 qQ($){return $.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function zI($){return $.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var jQ=()=>{};var{Glob:jI}=globalThis.Bun;import{cpSync as HI,existsSync as jZ,mkdirSync as ZH,readFileSync as YH,readdirSync as OI,rmSync as LI,statSync as FI,unlinkSync as VI,writeFileSync as qZ}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((z)=>z.endsWith(".html")),_=q6($,XH.cwd()),B=new Set(W.map(zZ));for(let z of W){let H=e1(X,z),O=YH(H,"utf8"),F=zZ(z),L=_?_.locales:[$.seo?.locale?.split(/[_-]/)[0]??"en"];for(let V of L){let A=O;if(A=EI(A),_)A=z6(A,_,V);if(A=await V0(A,XH.cwd()),A=K6(A,$,$.pages?.[F],F),_)A=II(A,$,_,V,F),A=DI(A,V,_.defaultLocale,B);if(A=U6(A,$),A=kI(A),_)A=A.replace(/<\/body>/i,`${H6(_,V)}
15042
15042
  </body>`);if($.spa!==!1)A=await B6(A,$.router);let N=_?MI(F,V,_.defaultLocale):z,w=e1(X,N);if(ZH(RI(w),{recursive:!0}),qZ(w,A),_&&V!==_.defaultLocale&&N!==z);}}if(jZ(J))HI(J,X,{recursive:!0});let U=e1(X,"404.html");if(!jZ(U)&&jZ(e1(X,"index.html"))){let z=YH(e1(X,"index.html"),"utf8").replace(/<title>[^<]*<\/title>/i,`<title>404 \u2014 ${SI($.name)}</title>`);qZ(U,z)}if($.sitemap!==!1){let z=[],H=W.filter((F)=>F!=="404.html").map(zZ),O=_?_.locales:[null];for(let F of H){let L=$.pages?.[F];for(let V of O){let A=V&&_?t1(F,V,_.defaultLocale):F;z.push({path:A,page:L})}}qZ(e1(X,"sitemap.xml"),W6($,z))}let q=_6($);if(q!==null)qZ(e1(X,"robots.txt"),q);let j=W.map(zZ);return{outDir:X,pages:j,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 zZ($){if($==="index.html")return"/";return`/${$.replace(/\.html$/,"").replace(/\/index$/,"")}`}function LQ($,Z=$){let Y=[];if(!jZ($))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}
15043
15043
  ${W}`);return $}function HQ($){return $.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function DI($,Z,Y,X){if(Z===Y)return $;return $.replace(/<a\b([^>]*?)\bhref="(\/[^"]*)"([^>]*)>/gi,(J,Q,G,K)=>{if(G.startsWith("//"))return J;if(G===`/${Z}`||G===`/${Z}/`||G.startsWith(`/${Z}/`))return J;let W=G.match(/^(\/[^?#]*)(.*)$/);if(!W)return J;let[,_,B]=W,U=_==="/"?"/":_.replace(/\/$/,"");if(!X.has(U))return J;let q=U==="/"?`/${Z}/`:`/${Z}${U}`;return`<a${Q}href="${q}${B}"${K}>`})}function kI($){if(/<main\b/i.test($)||/\bdata-stx-content\b/i.test($))return $;let Z=$.match(/<body\b[^>]*>/i),Y=$.search(/<\/body\s*>/i);if(!Z||Y<0)return $;let X=Z.index+Z[0].length,J=$.slice(X,Y),Q=0,G=[...J.matchAll(/<\/nav>/gi)];if(G.length>0){let q=G[G.length-1];Q=q.index+q[0].length}let K=J.length,W=J.search(/<footer\b/i);if(W!==-1)K=Math.min(K,W);let _=J.search(/<script\b[^>]*data-stx-(?:theme-toggle|reparent-progress)\b/i);if(_!==-1)K=Math.min(K,_);if(K<=Q)return $;let B=J.slice(Q,K);if(!B.trim())return $;let U=`${J.slice(0,Q)}
@@ -21,10 +21,21 @@ export declare function resolveI18n(site: SiteConfig, projectRoot?: string): Res
21
21
  */
22
22
  export declare function translate(i18n: ResolvedI18n, locale: string, key: string): string;
23
23
  /**
24
- * Replace `{t:key}` markers in HTML with the translated string for
25
- * the given locale. The key syntax sidesteps stx's `{{ ... }}`
26
- * templating (which evaluates as JS at build time and would render
27
- * `t(...)` calls as empty when no `t` binding exists in scope).
24
+ * Replace `{t:key}` and `{t!:key}` markers in HTML with the translated
25
+ * string for the given locale. The key syntax sidesteps stx's
26
+ * `{{ ... }}` templating (which evaluates as JS at build time and
27
+ * would render `t(...)` calls as empty when no `t` binding exists
28
+ * in scope).
29
+ *
30
+ * Two variants:
31
+ * - `{t:key}` — value is HTML-escaped before substitution. Default
32
+ * for ordinary text. Safe for any translator-supplied string.
33
+ * - `{t!:key}` — value is substituted *raw*, without escaping. Use
34
+ * this when the translation needs inline markup (e.g. `<strong>`,
35
+ * `<a>`, `<br>`) so different languages can place emphasis where
36
+ * their grammar requires. Translation values for these keys live
37
+ * in the project's own translation files, so the trust boundary
38
+ * is the same as the page template itself.
28
39
  *
29
40
  * Keys may use letters, digits, `_`, `.`, `-`. Anything that doesn't
30
41
  * match the pattern is left alone — runs after stx has finished its
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx",
3
3
  "type": "module",
4
- "version": "0.2.41",
4
+ "version": "0.2.42",
5
5
  "description": "A performant UI Framework. Powered by Bun.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",
@@ -119,7 +119,7 @@
119
119
  "@stacksjs/desktop": "0.2.35",
120
120
  "@stacksjs/sanitizer": "0.2.35",
121
121
  "@stacksjs/ts-craft": "^0.0.2",
122
- "bun-plugin-stx": "0.2.41",
122
+ "bun-plugin-stx": "0.2.42",
123
123
  "bunfig": "^0.15.6",
124
124
  "stx-router": "0.2.38",
125
125
  "ts-broadcasting": "^0.0.4",