// @bun
var{defineProperty:W,getOwnPropertyNames:T,getOwnPropertyDescriptor:Y}=Object,z=Object.prototype.hasOwnProperty;function U(B){return this[B]}var v=(B)=>{var D=(_??=new WeakMap).get(B),C;if(D)return D;if(D=W({},"__esModule",{value:!0}),B&&typeof B==="object"||typeof B==="function"){for(var G of T(B))if(!z.call(D,G))W(D,G,{get:U.bind(B,G),enumerable:!(C=Y(B,G))||C.enumerable})}return _.set(B,D),D},_;var K=(B)=>B;function O(B,D){this[B]=K.bind(null,D)}var f=(B,D)=>{for(var C in D)W(B,C,{get:D[C],enumerable:!0,configurable:!0,set:O.bind(D,C)})};var V=(B,D)=>()=>(B&&(D=B(B=0)),D);var k=import.meta.require;import{existsSync as F,readFileSync as R}from"fs";import{join as S,resolve as x}from"path";import g from"process";function p(B,D=g.cwd()){let C=B.i18n;if(!C||!Array.isArray(C.locales)||C.locales.length===0)return null;let G=C.defaultLocale??C.locales[0],E=A(C,D);return{locales:C.locales,defaultLocale:G,labels:C.labels??Object.fromEntries(C.locales.map((I)=>[I,I.toUpperCase()])),translations:E,pickerSelector:C.pickerSelector??"#lang-picker"}}function A(B,D){let C=B.translations??{},G={},E=B.translationsDir,I=E===!1?null:x(D,typeof E==="string"&&E?E:"translations"),J=B.format??"json";for(let M of B.locales){let N=I?L(I,M,J):{};G[M]={...N,...C[M]??{}}}return G}function L(B,D,C){let G=C==="json"?[`${D}.json`]:[`${D}.${C}`,`${D}.${C==="yaml"?"yml":"yaml"}`];for(let E of G){let I=S(B,E);if(!F(I))continue;try{let J=R(I,"utf8"),M=C==="json"?JSON.parse(J):P(J);return q(M)}catch{continue}}return{}}function q(B,D="",C={}){if(!B||typeof B!=="object")return C;for(let[G,E]of Object.entries(B)){let I=D?`${D}.${G}`:G;if(E&&typeof E==="object"&&!Array.isArray(E))q(E,I,C);else if(typeof E==="string")C[I]=E;else if(typeof E==="number"||typeof E==="boolean")C[I]=String(E)}return C}function P(B){let D={},C=[{obj:D,indent:-1}];for(let G of B.split(`
`)){let E=G.replace(/#.*$/,"").trimEnd();if(!E.trim())continue;let I=E.search(/\S/);if(I===-1)continue;while(C.length>1&&C[C.length-1].indent>=I)C.pop();let J=C[C.length-1].obj,M=E.match(/^(\s*)(\S[^:]*):\s*(.*)$/);if(!M)continue;let[,,N,H]=M,Q=N.trim(),Z=H.trim();if(Z==="")J[Q]={},C.push({obj:J[Q],indent:I});else J[Q]=w(Z)}return D}function w(B){if(B.startsWith("'")&&B.endsWith("'")||B.startsWith('"')&&B.endsWith('"'))return B.slice(1,-1);return B}function j(B,D,C){let G=B.translations[D]?.[C];if(typeof G==="string")return G;let E=B.translations[B.defaultLocale]?.[C];if(typeof E==="string")return E;return C}function s(B,D,C){return B.replace(/\{t(!?):([a-zA-Z][\w.-]*)\}/g,(G,E,I)=>{let J=j(D,C,I);return E==="!"?J:b(J)})}function $(B,D,C){if(D===C)return B;if(B==="/")return`/${D}/`;if(B==="/404.html")return`/${D}/404.html`;return`/${D}${B}`}function r(B,D){for(let C of D){if(B===`/${C}`||B===`/${C}/`)return{locale:C,path:"/"};if(B.startsWith(`/${C}/`))return{locale:C,path:B.slice(C.length+1)}}return{locale:null,path:B}}function c(B,D,C){let G=B.replace(/\/$/,""),E=[];for(let J of C.locales){let M=`${G}${$(D,J,C.defaultLocale)}`;E.push(`<link rel="alternate" hreflang="${X(J)}" href="${X(M)}">`)}let I=`${G}${$(D,C.defaultLocale,C.defaultLocale)}`;return E.push(`<link rel="alternate" hreflang="x-default" href="${X(I)}">`),E.join(`
  `)}function n(B,D){return`<script data-stx-lang-picker="1">window.__stxI18n=${JSON.stringify({locales:B.locales,defaultLocale:B.defaultLocale,current:D,pickerSelector:B.pickerSelector})};(function(){function cfg(){return window.__stxI18n}function localeFromPath(p){var d=cfg();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 d=cfg();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}cfg().localizeHref=function(href){try{var u=new URL(href,location.origin);if(u.origin!==location.origin)return href;return localePathFor(localeFromPath(location.pathname),u.pathname)+(u.search||'')+(u.hash||'')}catch(_){return href}};function syncFromUrl(){var d=cfg();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++){var b=btns[i];if(b.getAttribute('data-lang')===loc)b.setAttribute('aria-current','true');else b.removeAttribute('aria-current')}}if(document.documentElement.lang!==loc)document.documentElement.lang=loc}function onLangClick(e){var d=cfg();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();e.stopPropagation();var loc=btn.getAttribute('data-lang');if(!loc||loc===localeFromPath(location.pathname))return;var dest=localePathFor(loc,location.pathname);var r=window.__stxRouter;if(r&&r.navigate)r.navigate(dest,true,true);else location.assign(dest)}syncFromUrl();if(window.__stxLangPickerBound){document.removeEventListener('click',window.__stxLangPickerClick,true);window.removeEventListener('stx:navigate',window.__stxLangPickerSync);window.removeEventListener('popstate',window.__stxLangPickerSync)}window.__stxLangPickerClick=onLangClick;window.__stxLangPickerSync=syncFromUrl;window.__stxLangPickerBound=1;document.addEventListener('click',onLangClick,true);window.addEventListener('stx:navigate',syncFromUrl);window.addEventListener('popstate',syncFromUrl)})();</script>`}function X(B){return B.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function b(B){return B.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}var y=()=>{};y();export{j as translate,r as stripLocalePrefix,p as resolveI18n,$ as localizePath,n as buildLangPickerScript,c as buildAlternateLinks,s as applyTranslations};
