@i18n-micro/route-strategy 1.1.11 → 1.1.12

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.
@@ -0,0 +1,3 @@
1
+ import { LocaleRoutesConfig } from '../strategies/types';
2
+ /** True when localization is disabled via `globalLocaleRoutes[key] === false`. */
3
+ export declare function isLocalizationDisabledForPage(globalLocaleRoutes: LocaleRoutesConfig, originalPath: string, pageName: string): boolean;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("node:path"),S=require("node:fs"),k=require("@i18n-micro/core"),b=l=>l.map(e=>({...e})),K=l=>!!(l.redirect&&!l.file),F=(l,e,t,s="localized-")=>t?`${s}${l}-${e}`:`${s}${l}`,C=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,""),M=(l,e,t)=>t&&l!==e.code,T=(l,e)=>(typeof l=="string"?l:l.code)===e.code,H=[/^\/sitemap.*\.xml$/,/^\/sitemap\.xml$/,/^\/robots\.txt$/,/^\/favicon\.ico$/,/^\/apple-touch-icon.*\.png$/,/^\/manifest\.json$/,/^\/sw\.js$/,/^\/workbox-.*\.js$/,/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/];function E(l,e){if(/(?:^|\/)__[^/]+/.test(l))return!0;for(const t of H)if(t.test(l))return!0;if(e){for(const t of e)if(typeof t=="string"){if(t.includes("*")||t.includes("?")){if(new RegExp(t.replace(/\*/g,".*").replace(/\?/g,".")).test(l))return!0}else if(l===t||l.startsWith(t))return!0}else if(t instanceof RegExp&&t.test(l))return!0}return!1}function J(l,e){const t=l.reduce((o,a)=>{const r=o.find(i=>i.code===a.code);return r?Object.assign(r,a):o.push(a),o},[]).filter(o=>!o.disabled),s=t.find(o=>o.code===e)??{code:e};return{locales:t,defaultLocale:s}}function x(l){return l.split("/").map(e=>e.startsWith("[...")&&e.endsWith("]")?`:${e.substring(4,e.length-1)}(.*)*`:e.startsWith("[")&&e.endsWith("]")?`:${e.substring(1,e.length-1)}`:e).join("/")}const R=l=>{if(!l)return"";const e=w.posix.normalize(l).replace(/\/+$/,"");return e==="."?"":e},g=l=>l.startsWith("/")?l.slice(1):l;function G(...l){return w.posix.join(...l)}function Q(l){if(!(typeof l>"u"))return l.startsWith("/")&&l.endsWith("/")?l?.slice(1,-1):l}function X(l){return!l||!/[\u0080-\uFFFF]/.test(l)?l:l.split("/").map(e=>!e||e.startsWith(":")||!/[\u0080-\uFFFF]/.test(e)?e:encodeURI(e)).join("/")}function V(l){const e=X(l);return e!==l?[e]:[]}function A(l,e,t){const s=Q(t?.toString()),o=s||(Array.isArray(l)?l.join("|"):l),a=e;return R(w.posix.join("/",`:locale(${o})`,a))}function q(l){const e=l;return R(e)}const Y=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,"");function j(l){return g(l)||"/"}function _(l,e,t,s=""){const o={};return l.forEach(a=>{const r=Y(a.name,a.path),i=R(G(s,a.path??"")),n=j(i),d=x(i),c=e[n]||e[d]||e[r];if(c)typeof c=="object"&&(o[n]=c);else{const h=t[r];h&&typeof h=="object"&&!Array.isArray(h)&&(o[n]=h)}if(a.children?.length){const h=R(G(s,a.path??""));Object.assign(o,_(a.children,e,t,h))}}),o}function Z(l,e,t,s){if(!l||Object.keys(l).length===0)return!0;const o=x(t),a=g(o)||"/",r=a==="/"?"/":a,i=l[o]??l[t]??l[a]??l[r]??(a!=="/"?l[`/${a}`]:void 0);if(!Array.isArray(i)||i.length===0)return!0;const n=e.map(c=>c.code),d=i.filter(c=>n.includes(c));return d.length===0?!0:d.includes(s)}function ee(l){const e={};if(!l)return e;for(const t in l){const s=x(t),o=l[t];if(typeof o=="object"){const a={};for(const r in o){const i=o[r];i&&(a[r]=x(i))}e[s]=a}else e[s]=o}return e}class te{constructor(e){this.locales=e.locales,this.defaultLocale=this.findLocaleByCode(e.locales,e.defaultLocaleCode)??{code:e.defaultLocaleCode},this.strategy=e.strategy,this.globalLocaleRoutes=ee(e.globalLocaleRoutes??{}),this.filesLocaleRoutes=e.filesLocaleRoutes??{},this.routeLocales=e.routeLocales??{},this.localizedPaths=_(e.pages,this.globalLocaleRoutes,this.filesLocaleRoutes),this.activeLocaleCodes=this.locales.filter(t=>t.code!==this.defaultLocale.code||k.isPrefixAndDefaultStrategy(this.strategy)||k.isPrefixStrategy(this.strategy)).map(t=>t.code),this.excludePatterns=e.excludePatterns,this.customRegex=e.customRegex,this.noPrefixRedirect=e.noPrefixRedirect??!1,this.localizedRouteNamePrefix=e.localizedRouteNamePrefix??"localized-",this.fallbackRedirectComponentPath=e.fallbackRedirectComponentPath,this.rawGlobalLocaleRoutes=e.rawGlobalLocaleRoutes}findLocaleByCode(e,t){return e.find(s=>s.code===t)}getAllowedLocales(e,t){const s=this.routeLocales[e]??this.routeLocales[t];return s?.length?s.filter(o=>this.locales.some(a=>a.code===o)):this.locales.map(o=>o.code)}getCustomPath(e,t){const s=j(e);return this.localizedPaths[s]?.[t]}getCustomPathsForPage(e,t){const s=j(e);return this.localizedPaths[s]??this.localizedPaths[t]}hasLocaleRestrictions(e,t){return!!(this.routeLocales[e]??this.routeLocales[t])}filterLocaleCodesWithoutCustomPaths(e){const t=j(e);return this.activeLocaleCodes.filter(s=>!this.localizedPaths[t]?.[s])}}function y(l,e){const t=(e??"").trim();return t.startsWith("/")?R(t):R(w.posix.join(l||"",t))}function z(l,e){const{path:t,name:s,children:o,meta:a,alias:r}=e,i={...l,path:t};return s!==void 0&&(i.name=s),o!==void 0&&(i.children=o),a!==void 0&&(i.meta={...l.meta,...a}),r!==void 0?(i.alias=r,i.meta={...i.meta,alias:r}):"alias"in e&&(i.alias=void 0,i.meta={...i.meta,alias:void 0}),i}function ae(l){const e=l.alias,t=l.meta?.alias,s=e??t;return Array.isArray(s)?s:[]}function O(l,e,t,s="localized-"){const o=ae(l);if(!o.length)return[];const a=[];for(const r of o){const i=A(e,r,t);a.push(z(l,{path:i,name:`${s}${l.name??""}`,alias:void 0,meta:{alias:void 0},children:l.children}))}return a}class W{processPage(e,t){if(e.path===void 0)throw new Error("page.path is required");if(K(e))return[e];if(e.path&&E(e.path,t.excludePatterns))return[e];const s=e.path??"",o=C(e.name,e.path),a=x(s);return t.globalLocaleRoutes[o]===!1||t.globalLocaleRoutes[a]===!1?[e]:this.generateVariants(e,t)}postProcess(e,t){return e}localizeChildren(e,t,s,o,a,r){return e.flatMap(i=>this.localizeChild(i,t,s,o,a,r))}localizeChildrenAllLocales(e,t,s,o,a){return e.flatMap(r=>this.localizeChildAllLocales(r,t,s,o,a))}localizeChildAllLocales(e,t,s,o,a){const r=y(s,e.path??""),i=y(t,e.path??""),n=j(i),d=a.localizedPaths[n];if(d)return o.flatMap(f=>{const P=d[f]??y(t,e.path??"");return this.localizeChild(e,P,s,f,a,!0)});const c=R(e.path??""),h=g(c),u=this.localizeChildrenAllLocales(b(e.children??[]),i,r,o,a),m=`${a.localizedRouteNamePrefix}${e.name??""}`;return[z(e,{path:h,name:m,children:u})]}localizeChild(e,t,s,o,a,r){const i=y(s,e.path??""),n=a.getCustomPath(i,o),d=g(R(n||(e.path??""))),c=n??y(t,e.path??""),h=this.localizeChildren(b(e.children??[]),c,i,o,a,r),u=C(e.name,e.path),m=`${a.localizedRouteNamePrefix}${u}-${o}`;return[z(e,{path:d,name:m,children:h})]}buildRoutePathForLocales(e,t,s,o,a,r,i){if(o){const n=e.includes(i);return r||!n?A(e,s,a):R(s)}return A(e,t,a)}}class se extends W{generateVariants(e,t){const s=e.path??"",o=C(e.name,e.path),a=t.getAllowedLocales(s,o),r=t.getCustomPathsForPage(s,o),i=b(e.children??[]),n=[];if(n.push(e),r)for(const d of a){const c=r[d];if(!c)continue;const h=R(c),u=R(s);if(h===u)continue;const m=q(c),f=F(o,d,!0),P=this.localizeChildrenForNoPrefix(i,h,s,s,d,t,1);n.push(z(e,{path:m,name:f,children:P,alias:[],meta:{alias:[]}})),t.noPrefixRedirect&&d===t.defaultLocale.code&&h!==u&&(e.redirect=h)}return n.push(...O(e,a,t.customRegex,t.localizedRouteNamePrefix)),n}localizeChildrenForNoPrefix(e,t,s,o,a,r,i){return e.map(n=>{const d=y(s,n.path??"");let c,h;if(i===1){const P=r.getCustomPath(d,a);if(P){const L=R(P);c=g(L),h=L}else{const L=R(n.path??"");c=g(L),h=y(t,n.path??"")}}else{const P=R(n.path??"");c=g(P),h=y(t,n.path??"")}const u=this.localizeChildrenForNoPrefix(b(n.children??[]),h,d,o,a,r,i+1),m=C(n.name,n.path),f=F(m,a,!0);return z(n,{path:c,name:f,children:u})})}}function oe(l){const e=l.alias??l.meta?.alias;return Array.isArray(e)?e:[]}class le extends W{generateVariants(e,t){const s=e.path??"",o=C(e.name,e.path),a=t.getAllowedLocales(s,o),r=t.getCustomPathsForPage(s,o),i=b(e.children??[]),n=[];if(r)for(const c of a){const h=r[c],u=h?R(h):s,m=A(c,u,t.customRegex),f=F(o,c,!!h,t.localizedRouteNamePrefix),P=h??s,L=this.localizeChildren(i,P,s,c,t,!0),p=V(m);n.push(z(e,{path:m,name:f,children:L,alias:p.length?p:void 0,meta:{alias:p.length?p:[]}}))}else{const c=A(a,s,t.customRegex),h=F(o,a[0],!1,t.localizedRouteNamePrefix),u=this.localizeChildrenAllLocales(i,s,s,a,t);n.push(z(e,{path:c,name:h,children:u,alias:[],meta:{alias:[]}}))}const d=oe(e);if(d.length)for(const c of d){const h=A(a,c,t.customRegex);n.push(z(e,{path:h,name:`${t.localizedRouteNamePrefix}${e.name??""}`,alias:void 0,meta:{alias:void 0}}))}return n}postProcess(e,t){const s=e.filter(a=>{if(a.name==="index"&&a.path==="/")return!1;const r=a.path??"";return!!(r&&E(r,t.excludePatterns)||t.globalLocaleRoutes[a.name??""]===!1||/^\/:locale/.test(r)||r==="/")}),o=t.defaultLocale.code;for(const[a,r]of Object.entries(t.globalLocaleRoutes)){if(r===!1||typeof r!="object")continue;const i=r[o];if(!i)continue;const n=a.startsWith("/")?a:`/${a}`,d=`/${o}${i.startsWith("/")?i:`/${i}`}`;n!==d&&s.push({path:n,name:`redirect-${a.replace(/\//g,"-")}`,redirect:d})}return t.fallbackRedirectComponentPath&&s.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),s}}class ie extends W{generateVariants(e,t){const s=e.path??"",o=C(e.name,e.path),a=t.getAllowedLocales(s,o),r=t.getCustomPathsForPage(s,o),i=b(e.children??[]),n=[],d=t.defaultLocale.code;n.push(e);const c=t.locales.filter(u=>a.includes(u.code));if(c.length>0)if(r)for(const u of c){const m=r[u.code];if(m)if(u.code===d){const f=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,s,t);f&&n.push(f);const P=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!0,u.code,s,t);P&&n.push(P)}else{const f=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,s,t);f&&n.push(f)}else{const f=this.createLocalizedRoute(e,[u.code],i,!1,"",t.customRegex,!1,u.code,s,t);f&&n.push(f)}}else{const u=c.map(f=>f.code),m=this.createLocalizedRoute(e,u,i,!1,"",t.customRegex,!1,!0,s,t);m&&n.push(m)}const h=O(e,a,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const s=[],o=[];for(const a of e){const r=a.name??"";typeof r=="string"&&r.startsWith(t.localizedRouteNamePrefix)?o.push(a):s.push(a)}return[...s,...o]}createLocalizedRoute(e,t,s,o,a="",r,i=!1,n=!1,d,c){const h=this.buildRoutePathForLocales(t,e.path??"",a,o,r,i,c.defaultLocale.code);if(!h||!(o&&a)&&h===e.path||t.length===0)return null;const m=t[0];if(!m)return null;const f=d??e.path??"",P=F(C(e.name??"",f),m,o,c.localizedRouteNamePrefix),L=i||m!==c.defaultLocale.code,p=t.length===1?this.localizeChildren(s,h,f,m,c,L):this.localizeChildrenAllLocales(s,h,f,t,c);return z(e,{path:h,name:P,children:p,alias:[],meta:{alias:[]}})}}class re extends W{generateVariants(e,t){const s=e.path??"",o=C(e.name,e.path),a=t.getAllowedLocales(s,o),r=t.getCustomPathsForPage(s,o),i=b(e.children??[]),n=[],d=t.defaultLocale.code;if(a.includes(d)){const u=r?.[d],m=u?R(u):s,f=u?{[d]:u}:{},P=this.createLocalizedChildren(i,s,[d],!1,!1,!1,f,t);n.push(z(e,{path:m,name:e.name,children:P}))}const c=t.locales.filter(u=>a.includes(u.code)&&u.code!==d);if(c.length)if(r)for(const u of c){const m=r[u.code];if(m){const f=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,s,t);f&&n.push(f)}else{const f=this.createLocalizedRoute(e,[u.code],i,!1,"",t.customRegex,!1,u.code,s,t);f&&n.push(f)}}else{const u=c.map(f=>f.code),m=this.createLocalizedRoute(e,u,i,!1,"",t.customRegex,!1,!0,s,t);m&&n.push(m)}const h=O(e,a,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const s=[],o=[];for(const r of e){const i=r.name??"";typeof i=="string"&&i.startsWith(t.localizedRouteNamePrefix)?o.push(r):s.push(r)}const a=[...s,...o];return t.fallbackRedirectComponentPath&&a.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),a}createLocalizedChildren(e,t,s,o=!0,a=!1,r=!1,i={},n){return e.flatMap(d=>this.createLocalizedVariants(d,t,s,o,a,r,i,n))}createLocalizedVariants(e,t,s,o,a,r=!1,i,n){const d=R(e.path??""),c=y(t,e.path??""),h=j(c),u=n.localizedPaths[h],m=!!u,f=[];if(!m){const P=g(d),L=this.createLocalizedChildren(b(e.children??[]),y(t,e.path??""),s,o,a,r,i,n),p=this.buildChildRouteName(e.name,r,n);return f.push(z(e,{path:P,name:p,children:L})),f}for(const P of s){const L=i?.[P],p=!!L,$=u?.[P];let N=R($||(e.path??""));p&&L&&($?N=R($):N=y(L,e.path??""));const v=M(P,n.defaultLocale,a)?A(P,N,n.customRegex):N,B=g(v),D=$?R($):p?L:y(t,e.path??""),I=this.createLocalizedChildren(b(e.children??[]),D,[P],o,a,P,{...i,[P]:D},n),U=this.buildLocalizedRouteName(C(e.name,e.path),P,o,!!u,n);f.push(z(e,{path:B,name:U,children:I}))}return f}buildChildRouteName(e,t,s){return t===!0?`${s.localizedRouteNamePrefix}${e}`:typeof t=="string"?`${s.localizedRouteNamePrefix}${e}-${t}`:e}createLocalizedRoute(e,t,s,o,a="",r,i=!1,n=!1,d,c){const h=this.buildRoutePathForLocales(t,e.path??"",a,o,r,i,c.defaultLocale.code);if(!h||h===e.path||t.length===0)return null;const u=t[0];if(!u)return null;const m=d??e.path??"",f=F(C(e.name??"",m),u,o,c.localizedRouteNamePrefix);return z(e,{path:h,name:f,children:this.createLocalizedChildren(s,m,t,!0,!1,n,{[u]:a},c),alias:[],meta:{alias:[]}})}buildLocalizedRouteName(e,t,s,o=!1,a){return s?o?`${a.localizedRouteNamePrefix}${e}-${t}`:t&&!T(t,a.defaultLocale)?`${a.localizedRouteNamePrefix}${e}-${t}`:`${a.localizedRouteNamePrefix}${e}`:e}}function ne(l){switch(l){case"no_prefix":return new se;case"prefix":return new le;case"prefix_and_default":return new ie;case"prefix_except_default":return new re;default:throw new Error(`Unknown route strategy: ${l}`)}}class ce{constructor(e){this.localizedPaths={};const{locales:t,defaultLocaleCode:s,strategy:o,globalLocaleRoutes:a,filesLocaleRoutes:r={},routeLocales:i={},noPrefixRedirect:n,excludePatterns:d,localizedRouteNamePrefix:c="localized-",customRegexMatcher:h,fallbackRedirectComponentPath:u}=e,m=J(t,s);this.locales=m.locales,this.defaultLocale=m.defaultLocale,this.strategy=o,this.noPrefixRedirect=n,this.excludePatterns=d,this.localizedRouteNamePrefix=c,this.customRegex=h,this.fallbackRedirectComponentPath=u,this.activeLocaleCodes=this.computeActiveLocaleCodes();const f={};for(const P in a){const L=x(P),p=a[P];if(typeof p=="object"){const $={};for(const N in p){const v=p[N];v&&($[N]=x(v))}f[L]=$}else f[L]=p}this.globalLocaleRoutes=f,this.rawGlobalLocaleRoutes=a??{},this.filesLocaleRoutes=r??{},this.routeLocales=i??{}}computeActiveLocaleCodes(){return this.locales.filter(e=>e.code!==this.defaultLocale.code||k.isPrefixAndDefaultStrategy(this.strategy)||k.isPrefixStrategy(this.strategy)).map(e=>e.code)}extendPages(e){const t=new te({locales:this.locales,defaultLocaleCode:this.defaultLocale.code,strategy:this.strategy,globalLocaleRoutes:this.globalLocaleRoutes,filesLocaleRoutes:this.filesLocaleRoutes,routeLocales:this.routeLocales,pages:e,excludePatterns:this.excludePatterns,customRegex:this.customRegex,noPrefixRedirect:this.noPrefixRedirect,localizedRouteNamePrefix:this.localizedRouteNamePrefix,fallbackRedirectComponentPath:this.fallbackRedirectComponentPath,rawGlobalLocaleRoutes:this.rawGlobalLocaleRoutes});this.localizedPaths=t.localizedPaths;const s=ne(this.strategy),o=[...e],a=[];for(const i of o)a.push(...s.processPage(i,t));const r=s.postProcess(a,t);e.length=0,e.push(...r)}extractLocalizedPaths(e,t=""){return _(e,this.globalLocaleRoutes,this.filesLocaleRoutes,t)}ensureTranslationFilesExist(e,t,s,o){this.locales.forEach(a=>{const r=w.join(s,t,`${a.code}.json`);this.ensureFileExists(r),o||e.forEach(i=>{const n=w.join(s,t,"pages",`${i}/${a.code}.json`);this.ensureFileExists(n)})})}ensureFileExists(e){try{const t=w.dirname(e);S.existsSync(t)||S.mkdirSync(t,{recursive:!0}),S.existsSync(e)||S.writeFileSync(e,JSON.stringify({}),"utf-8")}catch{}}resolveLocalizedPath(e,t){const s=x(e),o=g(s)||"/";let a;const r=this.globalLocaleRoutes[o],i=this.globalLocaleRoutes[s];r&&typeof r=="object"&&!Array.isArray(r)?a=r[t]:i&&typeof i=="object"&&!Array.isArray(i)&&(a=i[t]);const n=!!a,d=a?R(a):R(s)||"";let c=!1;if(this.strategy==="no_prefix"?c=!1:this.strategy==="prefix"||this.strategy==="prefix_and_default"?c=!0:this.strategy==="prefix_except_default"&&(c=t!==this.defaultLocale.code),t===this.defaultLocale.code&&!n&&(this.strategy==="prefix_except_default"||this.strategy==="no_prefix")&&(c=!1),!c)return R(d)||"/";const h=g(d);return h?R(`/${t}/${h}`):`/${t}`}generateDataRoutes(e,t,s){const o=[],a=this.collectPageNames(e);for(const r of this.locales)if(o.push(`/${t}/index/${r.code}/data.json`),!s)for(const i of a)o.push(`/${t}/${i}/${r.code}/data.json`);return o}collectPageNames(e){const t=new Set,s=o=>{for(const a of o)typeof a.name=="string"&&a.name.length>0&&t.add(a.name),a.children&&a.children.length>0&&s(a.children)};return s(e),[...t]}}exports.RouteGenerator=ce;exports.buildEncodedPathAliases=V;exports.buildFullPath=A;exports.buildFullPathNoPrefix=q;exports.buildRouteName=F;exports.cloneArray=b;exports.extractLocalizedPaths=_;exports.isInternalPath=E;exports.isLocaleAllowedForUnlocalizedRoute=Z;exports.isLocaleDefault=T;exports.isPageRedirectOnly=K;exports.normalizePath=R;exports.normalizeRouteKey=x;exports.removeLeadingSlash=g;exports.shouldAddLocalePrefix=M;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("node:path"),k=require("node:fs"),_=require("@i18n-micro/core"),C=l=>l.map(e=>({...e})),M=l=>!!(l.redirect&&!l.file),j=(l,e,t,a="localized-")=>t?`${a}${l}-${e}`:`${a}${l}`,b=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,""),T=(l,e,t)=>t&&l!==e.code,V=(l,e)=>(typeof l=="string"?l:l.code)===e.code,J=[/^\/sitemap.*\.xml$/,/^\/sitemap\.xml$/,/^\/robots\.txt$/,/^\/favicon\.ico$/,/^\/apple-touch-icon.*\.png$/,/^\/manifest\.json$/,/^\/sw\.js$/,/^\/workbox-.*\.js$/,/\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/];function K(l,e){if(/(?:^|\/)__[^/]+/.test(l))return!0;for(const t of J)if(t.test(l))return!0;if(e){for(const t of e)if(typeof t=="string"){if(t.includes("*")||t.includes("?")){if(new RegExp(t.replace(/\*/g,".*").replace(/\?/g,".")).test(l))return!0}else if(l===t||l.startsWith(t))return!0}else if(t instanceof RegExp&&t.test(l))return!0}return!1}function Q(l,e){const t=l.reduce((o,s)=>{const r=o.find(i=>i.code===s.code);return r?Object.assign(r,s):o.push(s),o},[]).filter(o=>!o.disabled),a=t.find(o=>o.code===e)??{code:e};return{locales:t,defaultLocale:a}}function A(l){return l.split("/").map(e=>e.startsWith("[...")&&e.endsWith("]")?`:${e.substring(4,e.length-1)}(.*)*`:e.startsWith("[")&&e.endsWith("]")?`:${e.substring(1,e.length-1)}`:e).join("/")}const R=l=>{if(!l)return"";const e=w.posix.normalize(l).replace(/\/+$/,"");return e==="."?"":e},z=l=>l.startsWith("/")?l.slice(1):l;function G(...l){return w.posix.join(...l)}function X(l){if(!(typeof l>"u"))return l.startsWith("/")&&l.endsWith("/")?l?.slice(1,-1):l}function Y(l){return!l||!/[\u0080-\uFFFF]/.test(l)?l:l.split("/").map(e=>!e||e.startsWith(":")||!/[\u0080-\uFFFF]/.test(e)?e:encodeURI(e)).join("/")}function q(l){const e=Y(l);return e!==l?[e]:[]}function N(l,e,t){const a=X(t?.toString()),o=a||(Array.isArray(l)?l.join("|"):l),s=e;return R(w.posix.join("/",`:locale(${o})`,s))}function B(l){const e=l;return R(e)}const Z=(l,e)=>l??(e??"").replace(/[^a-z0-9]/gi,"-").replace(/^-+|-+$/g,"");function F(l){return z(l)||"/"}function W(l,e,t,a=""){const o={};return l.forEach(s=>{const r=Z(s.name,s.path),i=R(G(a,s.path??"")),n=F(i),f=A(i),c=e[n]||e[f]||e[r];if(c)typeof c=="object"&&(o[n]=c);else{const h=t[r];h&&typeof h=="object"&&!Array.isArray(h)&&(o[n]=h)}if(s.children?.length){const h=R(G(a,s.path??""));Object.assign(o,W(s.children,e,t,h))}}),o}function v(l,e,t){const a=A(e),o=F(e);return l[t]===!1||l[a]===!1||l[o]===!1||l[z(a)]===!1}function ee(l,e,t,a){if(!l||Object.keys(l).length===0)return!0;const o=A(t),s=z(o)||"/",r=s==="/"?"/":s,i=l[o]??l[t]??l[s]??l[r]??(s!=="/"?l[`/${s}`]:void 0);if(!Array.isArray(i)||i.length===0)return!0;const n=e.map(c=>c.code),f=i.filter(c=>n.includes(c));return f.length===0?!0:f.includes(a)}function te(l){const e={};if(!l)return e;for(const t in l){const a=A(t),o=l[t];if(typeof o=="object"){const s={};for(const r in o){const i=o[r];i&&(s[r]=A(i))}e[a]=s}else e[a]=o}return e}class ae{constructor(e){this.locales=e.locales,this.defaultLocale=this.findLocaleByCode(e.locales,e.defaultLocaleCode)??{code:e.defaultLocaleCode},this.strategy=e.strategy,this.globalLocaleRoutes=te(e.globalLocaleRoutes??{}),this.filesLocaleRoutes=e.filesLocaleRoutes??{},this.routeLocales=e.routeLocales??{},this.localizedPaths=W(e.pages,this.globalLocaleRoutes,this.filesLocaleRoutes),this.activeLocaleCodes=this.locales.filter(t=>t.code!==this.defaultLocale.code||_.isPrefixAndDefaultStrategy(this.strategy)||_.isPrefixStrategy(this.strategy)).map(t=>t.code),this.excludePatterns=e.excludePatterns,this.customRegex=e.customRegex,this.noPrefixRedirect=e.noPrefixRedirect??!1,this.localizedRouteNamePrefix=e.localizedRouteNamePrefix??"localized-",this.fallbackRedirectComponentPath=e.fallbackRedirectComponentPath,this.rawGlobalLocaleRoutes=e.rawGlobalLocaleRoutes}findLocaleByCode(e,t){return e.find(a=>a.code===t)}getAllowedLocales(e,t){const a=this.routeLocales[e]??this.routeLocales[t];return a?.length?a.filter(o=>this.locales.some(s=>s.code===o)):this.locales.map(o=>o.code)}getCustomPath(e,t){const a=F(e);return this.localizedPaths[a]?.[t]}getCustomPathsForPage(e,t){const a=F(e);return this.localizedPaths[a]??this.localizedPaths[t]}hasLocaleRestrictions(e,t){return!!(this.routeLocales[e]??this.routeLocales[t])}filterLocaleCodesWithoutCustomPaths(e){const t=F(e);return this.activeLocaleCodes.filter(a=>!this.localizedPaths[t]?.[a])}}function y(l,e){const t=(e??"").trim();return t.startsWith("/")?R(t):R(w.posix.join(l||"",t))}function g(l,e){const{path:t,name:a,children:o,meta:s,alias:r}=e,i={...l,path:t};return a!==void 0&&(i.name=a),o!==void 0&&(i.children=o),s!==void 0&&(i.meta={...l.meta,...s}),r!==void 0?(i.alias=r,i.meta={...i.meta,alias:r}):"alias"in e&&(i.alias=void 0,i.meta={...i.meta,alias:void 0}),i}function se(l){const e=l.alias,t=l.meta?.alias,a=e??t;return Array.isArray(a)?a:[]}function O(l,e,t,a="localized-"){const o=se(l);if(!o.length)return[];const s=[];for(const r of o){const i=N(e,r,t);s.push(g(l,{path:i,name:`${a}${l.name??""}`,alias:void 0,meta:{alias:void 0},children:l.children}))}return s}class E{processPage(e,t){if(e.path===void 0)throw new Error("page.path is required");if(M(e))return[e];if(e.path&&K(e.path,t.excludePatterns))return[e];const a=e.path??"",o=b(e.name,e.path);return v(t.globalLocaleRoutes,a,o)?[e]:this.generateVariants(e,t)}postProcess(e,t){return e}localizeChildren(e,t,a,o,s,r){return e.flatMap(i=>this.localizeChild(i,t,a,o,s,r))}localizeChildrenAllLocales(e,t,a,o,s){return e.flatMap(r=>this.localizeChildAllLocales(r,t,a,o,s))}localizeChildAllLocales(e,t,a,o,s){const r=y(a,e.path??""),i=b(e.name,e.path);if(v(s.globalLocaleRoutes,r,i))return[e];const n=y(t,e.path??""),f=F(n),c=s.localizedPaths[f];if(c)return o.flatMap(P=>{const L=c[P]??y(t,e.path??"");return this.localizeChild(e,L,a,P,s,!0)});const h=R(e.path??""),u=z(h),m=this.localizeChildrenAllLocales(C(e.children??[]),n,r,o,s),d=`${s.localizedRouteNamePrefix}${e.name??""}`;return[g(e,{path:u,name:d,children:m})]}localizeChild(e,t,a,o,s,r){const i=y(a,e.path??""),n=b(e.name,e.path);if(v(s.globalLocaleRoutes,i,n))return[e];const f=s.getCustomPath(i,o),c=z(R(f||(e.path??""))),h=f??y(t,e.path??""),u=this.localizeChildren(C(e.children??[]),h,i,o,s,r),m=b(e.name,e.path),d=`${s.localizedRouteNamePrefix}${m}-${o}`;return[g(e,{path:c,name:d,children:u})]}buildRoutePathForLocales(e,t,a,o,s,r,i){if(o){const n=e.includes(i);return r||!n?N(e,a,s):R(a)}return N(e,t,s)}}class oe extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[];if(n.push(e),r)for(const f of s){const c=r[f];if(!c)continue;const h=R(c),u=R(a);if(h===u)continue;const m=B(c),d=j(o,f,!0),P=this.localizeChildrenForNoPrefix(i,h,a,a,f,t,1);n.push(g(e,{path:m,name:d,children:P,alias:[],meta:{alias:[]}})),t.noPrefixRedirect&&f===t.defaultLocale.code&&h!==u&&(e.redirect=h)}return n.push(...O(e,s,t.customRegex,t.localizedRouteNamePrefix)),n}localizeChildrenForNoPrefix(e,t,a,o,s,r,i){return e.map(n=>{const f=y(a,n.path??"");let c,h;if(i===1){const P=r.getCustomPath(f,s);if(P){const L=R(P);c=z(L),h=L}else{const L=R(n.path??"");c=z(L),h=y(t,n.path??"")}}else{const P=R(n.path??"");c=z(P),h=y(t,n.path??"")}const u=this.localizeChildrenForNoPrefix(C(n.children??[]),h,f,o,s,r,i+1),m=b(n.name,n.path),d=j(m,s,!0);return g(n,{path:c,name:d,children:u})})}}function le(l){const e=l.alias??l.meta?.alias;return Array.isArray(e)?e:[]}class ie extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[];if(r)for(const c of s){const h=r[c],u=h?R(h):a,m=N(c,u,t.customRegex),d=j(o,c,!!h,t.localizedRouteNamePrefix),P=h??a,L=this.localizeChildren(i,P,a,c,t,!0),p=q(m);n.push(g(e,{path:m,name:d,children:L,alias:p.length?p:void 0,meta:{alias:p.length?p:[]}}))}else{const c=N(s,a,t.customRegex),h=j(o,s[0],!1,t.localizedRouteNamePrefix),u=this.localizeChildrenAllLocales(i,a,a,s,t);n.push(g(e,{path:c,name:h,children:u,alias:[],meta:{alias:[]}}))}const f=le(e);if(f.length)for(const c of f){const h=N(s,c,t.customRegex);n.push(g(e,{path:h,name:`${t.localizedRouteNamePrefix}${e.name??""}`,alias:void 0,meta:{alias:void 0}}))}return n}postProcess(e,t){const a=e.filter(s=>{if(s.name==="index"&&s.path==="/")return!1;const r=s.path??"";return!!(r&&K(r,t.excludePatterns)||v(t.globalLocaleRoutes,r,s.name??"")||/^\/:locale/.test(r)||r==="/")}),o=t.defaultLocale.code;for(const[s,r]of Object.entries(t.globalLocaleRoutes)){if(r===!1||typeof r!="object")continue;const i=r[o];if(!i)continue;const n=s.startsWith("/")?s:`/${s}`,f=`/${o}${i.startsWith("/")?i:`/${i}`}`;n!==f&&a.push({path:n,name:`redirect-${s.replace(/\//g,"-")}`,redirect:f})}return t.fallbackRedirectComponentPath&&a.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),a}}class re extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[],f=t.defaultLocale.code;n.push(e);const c=t.locales.filter(u=>s.includes(u.code));if(c.length>0)if(r)for(const u of c){const m=r[u.code];if(m)if(u.code===f){const d=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,a,t);d&&n.push(d);const P=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!0,u.code,a,t);P&&n.push(P)}else{const d=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,a,t);d&&n.push(d)}else{const d=this.createLocalizedRoute(e,[u.code],i,!1,"",t.customRegex,!1,u.code,a,t);d&&n.push(d)}}else{const u=c.map(d=>d.code),m=this.createLocalizedRoute(e,u,i,!1,"",t.customRegex,!1,!0,a,t);m&&n.push(m)}const h=O(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const a=[],o=[];for(const s of e){const r=s.name??"";typeof r=="string"&&r.startsWith(t.localizedRouteNamePrefix)?o.push(s):a.push(s)}return[...a,...o]}createLocalizedRoute(e,t,a,o,s="",r,i=!1,n=!1,f,c){const h=this.buildRoutePathForLocales(t,e.path??"",s,o,r,i,c.defaultLocale.code);if(!h||!(o&&s)&&h===e.path||t.length===0)return null;const m=t[0];if(!m)return null;const d=f??e.path??"",P=j(b(e.name??"",d),m,o,c.localizedRouteNamePrefix),L=i||m!==c.defaultLocale.code,p=t.length===1?this.localizeChildren(a,h,d,m,c,L):this.localizeChildrenAllLocales(a,h,d,t,c);return g(e,{path:h,name:P,children:p,alias:[],meta:{alias:[]}})}}class ne extends E{generateVariants(e,t){const a=e.path??"",o=b(e.name,e.path),s=t.getAllowedLocales(a,o),r=t.getCustomPathsForPage(a,o),i=C(e.children??[]),n=[],f=t.defaultLocale.code;if(s.includes(f)){const u=r?.[f],m=u?R(u):a,d=u?{[f]:u}:{},P=this.createLocalizedChildren(i,a,[f],!1,!1,!1,d,t);n.push(g(e,{path:m,name:e.name,children:P}))}const c=t.locales.filter(u=>s.includes(u.code)&&u.code!==f);if(c.length)if(r)for(const u of c){const m=r[u.code];if(m){const d=this.createLocalizedRoute(e,[u.code],i,!0,m,t.customRegex,!1,u.code,a,t);d&&n.push(d)}else{const d=this.createLocalizedRoute(e,[u.code],i,!1,"",t.customRegex,!1,u.code,a,t);d&&n.push(d)}}else{const u=c.map(d=>d.code),m=this.createLocalizedRoute(e,u,i,!1,"",t.customRegex,!1,!0,a,t);m&&n.push(m)}const h=O(e,s,t.customRegex,t.localizedRouteNamePrefix);return h.length&&n.push(...h),n}postProcess(e,t){const a=[],o=[];for(const r of e){const i=r.name??"";typeof i=="string"&&i.startsWith(t.localizedRouteNamePrefix)?o.push(r):a.push(r)}const s=[...a,...o];return t.fallbackRedirectComponentPath&&s.push({path:"/:pathMatch(.*)*",name:"custom-fallback-route",file:t.fallbackRedirectComponentPath,meta:{globalLocaleRoutes:t.rawGlobalLocaleRoutes??t.globalLocaleRoutes}}),s}createLocalizedChildren(e,t,a,o=!0,s=!1,r=!1,i={},n){return e.flatMap(f=>this.createLocalizedVariants(f,t,a,o,s,r,i,n))}createLocalizedVariants(e,t,a,o,s,r=!1,i,n){const f=R(e.path??""),c=y(t,e.path??""),h=F(c),u=n.localizedPaths[h],m=!!u,d=[];if(!m){const P=z(f),L=this.createLocalizedChildren(C(e.children??[]),y(t,e.path??""),a,o,s,r,i,n),p=this.buildChildRouteName(e.name,r,n);return d.push(g(e,{path:P,name:p,children:L})),d}for(const P of a){const L=i?.[P],p=!!L,$=u?.[P];let x=R($||(e.path??""));p&&L&&($?x=R($):x=y(L,e.path??""));const S=T(P,n.defaultLocale,s)?N(P,x,n.customRegex):x,I=z(S),D=$?R($):p?L:y(t,e.path??""),U=this.createLocalizedChildren(C(e.children??[]),D,[P],o,s,P,{...i,[P]:D},n),H=this.buildLocalizedRouteName(b(e.name,e.path),P,o,!!u,n);d.push(g(e,{path:I,name:H,children:U}))}return d}buildChildRouteName(e,t,a){return t===!0?`${a.localizedRouteNamePrefix}${e}`:typeof t=="string"?`${a.localizedRouteNamePrefix}${e}-${t}`:e}createLocalizedRoute(e,t,a,o,s="",r,i=!1,n=!1,f,c){const h=this.buildRoutePathForLocales(t,e.path??"",s,o,r,i,c.defaultLocale.code);if(!h||h===e.path||t.length===0)return null;const u=t[0];if(!u)return null;const m=f??e.path??"",d=j(b(e.name??"",m),u,o,c.localizedRouteNamePrefix);return g(e,{path:h,name:d,children:this.createLocalizedChildren(a,m,t,!0,!1,n,{[u]:s},c),alias:[],meta:{alias:[]}})}buildLocalizedRouteName(e,t,a,o=!1,s){return a?o?`${s.localizedRouteNamePrefix}${e}-${t}`:t&&!V(t,s.defaultLocale)?`${s.localizedRouteNamePrefix}${e}-${t}`:`${s.localizedRouteNamePrefix}${e}`:e}}function ce(l){switch(l){case"no_prefix":return new oe;case"prefix":return new ie;case"prefix_and_default":return new re;case"prefix_except_default":return new ne;default:throw new Error(`Unknown route strategy: ${l}`)}}class ue{constructor(e){this.localizedPaths={};const{locales:t,defaultLocaleCode:a,strategy:o,globalLocaleRoutes:s,filesLocaleRoutes:r={},routeLocales:i={},noPrefixRedirect:n,excludePatterns:f,localizedRouteNamePrefix:c="localized-",customRegexMatcher:h,fallbackRedirectComponentPath:u}=e,m=Q(t,a);this.locales=m.locales,this.defaultLocale=m.defaultLocale,this.strategy=o,this.noPrefixRedirect=n,this.excludePatterns=f,this.localizedRouteNamePrefix=c,this.customRegex=h,this.fallbackRedirectComponentPath=u,this.activeLocaleCodes=this.computeActiveLocaleCodes();const d={};for(const P in s){const L=A(P),p=s[P];if(typeof p=="object"){const $={};for(const x in p){const S=p[x];S&&($[x]=A(S))}d[L]=$}else d[L]=p}this.globalLocaleRoutes=d,this.rawGlobalLocaleRoutes=s??{},this.filesLocaleRoutes=r??{},this.routeLocales=i??{}}computeActiveLocaleCodes(){return this.locales.filter(e=>e.code!==this.defaultLocale.code||_.isPrefixAndDefaultStrategy(this.strategy)||_.isPrefixStrategy(this.strategy)).map(e=>e.code)}extendPages(e){const t=new ae({locales:this.locales,defaultLocaleCode:this.defaultLocale.code,strategy:this.strategy,globalLocaleRoutes:this.globalLocaleRoutes,filesLocaleRoutes:this.filesLocaleRoutes,routeLocales:this.routeLocales,pages:e,excludePatterns:this.excludePatterns,customRegex:this.customRegex,noPrefixRedirect:this.noPrefixRedirect,localizedRouteNamePrefix:this.localizedRouteNamePrefix,fallbackRedirectComponentPath:this.fallbackRedirectComponentPath,rawGlobalLocaleRoutes:this.rawGlobalLocaleRoutes});this.localizedPaths=t.localizedPaths;const a=ce(this.strategy),o=[...e],s=[];for(const i of o)s.push(...a.processPage(i,t));const r=a.postProcess(s,t);e.length=0,e.push(...r)}extractLocalizedPaths(e,t=""){return W(e,this.globalLocaleRoutes,this.filesLocaleRoutes,t)}ensureTranslationFilesExist(e,t,a,o){this.locales.forEach(s=>{const r=w.join(a,t,`${s.code}.json`);this.ensureFileExists(r),o||e.forEach(i=>{const n=w.join(a,t,"pages",`${i}/${s.code}.json`);this.ensureFileExists(n)})})}ensureFileExists(e){try{const t=w.dirname(e);k.existsSync(t)||k.mkdirSync(t,{recursive:!0}),k.existsSync(e)||k.writeFileSync(e,JSON.stringify({}),"utf-8")}catch{}}resolveLocalizedPath(e,t){const a=A(e),o=z(a)||"/";let s;const r=this.globalLocaleRoutes[o],i=this.globalLocaleRoutes[a];r&&typeof r=="object"&&!Array.isArray(r)?s=r[t]:i&&typeof i=="object"&&!Array.isArray(i)&&(s=i[t]);const n=!!s,f=s?R(s):R(a)||"";let c=!1;if(this.strategy==="no_prefix"?c=!1:this.strategy==="prefix"||this.strategy==="prefix_and_default"?c=!0:this.strategy==="prefix_except_default"&&(c=t!==this.defaultLocale.code),t===this.defaultLocale.code&&!n&&(this.strategy==="prefix_except_default"||this.strategy==="no_prefix")&&(c=!1),!c)return R(f)||"/";const h=z(f);return h?R(`/${t}/${h}`):`/${t}`}generateDataRoutes(e,t,a){const o=[],s=this.collectPageNames(e);for(const r of this.locales)if(o.push(`/${t}/index/${r.code}/data.json`),!a)for(const i of s)o.push(`/${t}/${i}/${r.code}/data.json`);return o}collectPageNames(e){const t=new Set,a=o=>{for(const s of o)typeof s.name=="string"&&s.name.length>0&&t.add(s.name),s.children&&s.children.length>0&&a(s.children)};return a(e),[...t]}}exports.RouteGenerator=ue;exports.buildEncodedPathAliases=q;exports.buildFullPath=N;exports.buildFullPathNoPrefix=B;exports.buildRouteName=j;exports.cloneArray=C;exports.extractLocalizedPaths=W;exports.isInternalPath=K;exports.isLocaleAllowedForUnlocalizedRoute=ee;exports.isLocaleDefault=V;exports.isLocalizationDisabledForPage=v;exports.isPageRedirectOnly=M;exports.normalizePath=R;exports.normalizeRouteKey=A;exports.removeLeadingSlash=z;exports.shouldAddLocalePrefix=T;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { extractLocalizedPaths, LocalizedPathsMap } from './core/localized-paths';
2
+ import { isLocalizationDisabledForPage } from './core/localization-disabled';
2
3
  import { isLocaleAllowedForUnlocalizedRoute } from './locale-route-access';
3
4
  import { RouteGenerator, RouteGeneratorOptions } from './route-generator';
4
5
  import { buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, buildRouteName, cloneArray, isInternalPath, isLocaleDefault, isPageRedirectOnly, normalizePath, normalizeRouteKey, removeLeadingSlash, shouldAddLocalePrefix } from './utils';
5
- export { RouteGenerator, type RouteGeneratorOptions, isLocaleAllowedForUnlocalizedRoute, extractLocalizedPaths, type LocalizedPathsMap, isInternalPath, normalizeRouteKey, normalizePath, cloneArray, isPageRedirectOnly, removeLeadingSlash, buildRouteName, shouldAddLocalePrefix, isLocaleDefault, buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, };
6
+ export { RouteGenerator, type RouteGeneratorOptions, isLocaleAllowedForUnlocalizedRoute, extractLocalizedPaths, type LocalizedPathsMap, isLocalizationDisabledForPage, isInternalPath, normalizeRouteKey, normalizePath, cloneArray, isPageRedirectOnly, removeLeadingSlash, buildRouteName, shouldAddLocalePrefix, isLocaleDefault, buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { extractLocalizedPaths, LocalizedPathsMap } from './core/localized-paths';
2
+ import { isLocalizationDisabledForPage } from './core/localization-disabled';
2
3
  import { isLocaleAllowedForUnlocalizedRoute } from './locale-route-access';
3
4
  import { RouteGenerator, RouteGeneratorOptions } from './route-generator';
4
5
  import { buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, buildRouteName, cloneArray, isInternalPath, isLocaleDefault, isPageRedirectOnly, normalizePath, normalizeRouteKey, removeLeadingSlash, shouldAddLocalePrefix } from './utils';
5
- export { RouteGenerator, type RouteGeneratorOptions, isLocaleAllowedForUnlocalizedRoute, extractLocalizedPaths, type LocalizedPathsMap, isInternalPath, normalizeRouteKey, normalizePath, cloneArray, isPageRedirectOnly, removeLeadingSlash, buildRouteName, shouldAddLocalePrefix, isLocaleDefault, buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, };
6
+ export { RouteGenerator, type RouteGeneratorOptions, isLocaleAllowedForUnlocalizedRoute, extractLocalizedPaths, type LocalizedPathsMap, isLocalizationDisabledForPage, isInternalPath, normalizeRouteKey, normalizePath, cloneArray, isPageRedirectOnly, removeLeadingSlash, buildRouteName, shouldAddLocalePrefix, isLocaleDefault, buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, };
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import A from "node:path";
2
- import { existsSync as E, mkdirSync as B, writeFileSync as I } from "node:fs";
3
- import { isPrefixAndDefaultStrategy as K, isPrefixStrategy as O } from "@i18n-micro/core";
4
- const $ = (l) => l.map((e) => ({ ...e })), U = (l) => !!(l.redirect && !l.file), j = (l, e, t, s = "localized-") => t ? `${s}${l}-${e}` : `${s}${l}`, b = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), q = (l, e, t) => t && l !== e.code, H = (l, e) => (typeof l == "string" ? l : l.code) === e.code, J = [
1
+ import w from "node:path";
2
+ import { existsSync as K, mkdirSync as I, writeFileSync as U } from "node:fs";
3
+ import { isPrefixAndDefaultStrategy as O, isPrefixStrategy as D } from "@i18n-micro/core";
4
+ const $ = (l) => l.map((e) => ({ ...e })), q = (l) => !!(l.redirect && !l.file), j = (l, e, t, a = "localized-") => t ? `${a}${l}-${e}` : `${a}${l}`, b = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, ""), H = (l, e, t) => t && l !== e.code, J = (l, e) => (typeof l == "string" ? l : l.code) === e.code, Q = [
5
5
  /^\/sitemap.*\.xml$/,
6
6
  /^\/sitemap\.xml$/,
7
7
  /^\/robots\.txt$/,
@@ -12,10 +12,10 @@ const $ = (l) => l.map((e) => ({ ...e })), U = (l) => !!(l.redirect && !l.file),
12
12
  /^\/workbox-.*\.js$/,
13
13
  /\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/
14
14
  ];
15
- function D(l, e) {
15
+ function M(l, e) {
16
16
  if (/(?:^|\/)__[^/]+/.test(l))
17
17
  return !0;
18
- for (const t of J)
18
+ for (const t of Q)
19
19
  if (t.test(l))
20
20
  return !0;
21
21
  if (e) {
@@ -30,12 +30,12 @@ function D(l, e) {
30
30
  }
31
31
  return !1;
32
32
  }
33
- function Q(l, e) {
34
- const t = l.reduce((o, a) => {
35
- const r = o.find((i) => i.code === a.code);
36
- return r ? Object.assign(r, a) : o.push(a), o;
37
- }, []).filter((o) => !o.disabled), s = t.find((o) => o.code === e) ?? { code: e };
38
- return { locales: t, defaultLocale: s };
33
+ function X(l, e) {
34
+ const t = l.reduce((o, s) => {
35
+ const r = o.find((i) => i.code === s.code);
36
+ return r ? Object.assign(r, s) : o.push(s), o;
37
+ }, []).filter((o) => !o.disabled), a = t.find((o) => o.code === e) ?? { code: e };
38
+ return { locales: t, defaultLocale: a };
39
39
  }
40
40
  function N(l) {
41
41
  return l.split("/").map((e) => e.startsWith("[...") && e.endsWith("]") ? `:${e.substring(4, e.length - 1)}(.*)*` : e.startsWith("[") && e.endsWith("]") ? `:${e.substring(1, e.length - 1)}` : e).join("/");
@@ -43,138 +43,142 @@ function N(l) {
43
43
  const R = (l) => {
44
44
  if (!l)
45
45
  return "";
46
- const e = A.posix.normalize(l).replace(/\/+$/, "");
46
+ const e = w.posix.normalize(l).replace(/\/+$/, "");
47
47
  return e === "." ? "" : e;
48
- }, y = (l) => l.startsWith("/") ? l.slice(1) : l;
48
+ }, g = (l) => l.startsWith("/") ? l.slice(1) : l;
49
49
  function G(...l) {
50
- return A.posix.join(...l);
50
+ return w.posix.join(...l);
51
51
  }
52
- function X(l) {
52
+ function Y(l) {
53
53
  if (!(typeof l > "u"))
54
54
  return l.startsWith("/") && l.endsWith("/") ? l?.slice(1, -1) : l;
55
55
  }
56
- function Y(l) {
56
+ function Z(l) {
57
57
  return !l || !/[\u0080-\uFFFF]/.test(l) ? l : l.split("/").map((e) => !e || e.startsWith(":") || !/[\u0080-\uFFFF]/.test(e) ? e : encodeURI(e)).join("/");
58
58
  }
59
- function Z(l) {
60
- const e = Y(l);
59
+ function ee(l) {
60
+ const e = Z(l);
61
61
  return e !== l ? [e] : [];
62
62
  }
63
- function w(l, e, t) {
64
- const s = X(t?.toString()), o = s || (Array.isArray(l) ? l.join("|") : l), a = e;
65
- return R(A.posix.join("/", `:locale(${o})`, a));
63
+ function x(l, e, t) {
64
+ const a = Y(t?.toString()), o = a || (Array.isArray(l) ? l.join("|") : l), s = e;
65
+ return R(w.posix.join("/", `:locale(${o})`, s));
66
66
  }
67
- function ee(l) {
67
+ function te(l) {
68
68
  const e = l;
69
69
  return R(e);
70
70
  }
71
- const te = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
71
+ const ae = (l, e) => l ?? (e ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
72
72
  function F(l) {
73
- return y(l) || "/";
73
+ return g(l) || "/";
74
74
  }
75
- function k(l, e, t, s = "") {
75
+ function _(l, e, t, a = "") {
76
76
  const o = {};
77
- return l.forEach((a) => {
78
- const r = te(a.name, a.path), i = R(G(s, a.path ?? "")), n = F(i), f = N(i), c = e[n] || e[f] || e[r];
77
+ return l.forEach((s) => {
78
+ const r = ae(s.name, s.path), i = R(G(a, s.path ?? "")), n = F(i), f = N(i), c = e[n] || e[f] || e[r];
79
79
  if (c)
80
80
  typeof c == "object" && (o[n] = c);
81
81
  else {
82
82
  const h = t[r];
83
83
  h && typeof h == "object" && !Array.isArray(h) && (o[n] = h);
84
84
  }
85
- if (a.children?.length) {
86
- const h = R(G(s, a.path ?? ""));
87
- Object.assign(o, k(a.children, e, t, h));
85
+ if (s.children?.length) {
86
+ const h = R(G(a, s.path ?? ""));
87
+ Object.assign(o, _(s.children, e, t, h));
88
88
  }
89
89
  }), o;
90
90
  }
91
- function me(l, e, t, s) {
91
+ function S(l, e, t) {
92
+ const a = N(e), o = F(e);
93
+ return l[t] === !1 || l[a] === !1 || l[o] === !1 || l[g(a)] === !1;
94
+ }
95
+ function Pe(l, e, t, a) {
92
96
  if (!l || Object.keys(l).length === 0)
93
97
  return !0;
94
- const o = N(t), a = y(o) || "/", r = a === "/" ? "/" : a, i = l[o] ?? l[t] ?? l[a] ?? l[r] ?? (a !== "/" ? l[`/${a}`] : void 0);
98
+ const o = N(t), s = g(o) || "/", r = s === "/" ? "/" : s, i = l[o] ?? l[t] ?? l[s] ?? l[r] ?? (s !== "/" ? l[`/${s}`] : void 0);
95
99
  if (!Array.isArray(i) || i.length === 0)
96
100
  return !0;
97
101
  const n = e.map((c) => c.code), f = i.filter((c) => n.includes(c));
98
- return f.length === 0 ? !0 : f.includes(s);
102
+ return f.length === 0 ? !0 : f.includes(a);
99
103
  }
100
- function ae(l) {
104
+ function se(l) {
101
105
  const e = {};
102
106
  if (!l) return e;
103
107
  for (const t in l) {
104
- const s = N(t), o = l[t];
108
+ const a = N(t), o = l[t];
105
109
  if (typeof o == "object") {
106
- const a = {};
110
+ const s = {};
107
111
  for (const r in o) {
108
112
  const i = o[r];
109
- i && (a[r] = N(i));
113
+ i && (s[r] = N(i));
110
114
  }
111
- e[s] = a;
115
+ e[a] = s;
112
116
  } else
113
- e[s] = o;
117
+ e[a] = o;
114
118
  }
115
119
  return e;
116
120
  }
117
- class se {
121
+ class oe {
118
122
  constructor(e) {
119
- this.locales = e.locales, this.defaultLocale = this.findLocaleByCode(e.locales, e.defaultLocaleCode) ?? { code: e.defaultLocaleCode }, this.strategy = e.strategy, this.globalLocaleRoutes = ae(e.globalLocaleRoutes ?? {}), this.filesLocaleRoutes = e.filesLocaleRoutes ?? {}, this.routeLocales = e.routeLocales ?? {}, this.localizedPaths = k(e.pages, this.globalLocaleRoutes, this.filesLocaleRoutes), this.activeLocaleCodes = this.locales.filter((t) => t.code !== this.defaultLocale.code || K(this.strategy) || O(this.strategy)).map((t) => t.code), this.excludePatterns = e.excludePatterns, this.customRegex = e.customRegex, this.noPrefixRedirect = e.noPrefixRedirect ?? !1, this.localizedRouteNamePrefix = e.localizedRouteNamePrefix ?? "localized-", this.fallbackRedirectComponentPath = e.fallbackRedirectComponentPath, this.rawGlobalLocaleRoutes = e.rawGlobalLocaleRoutes;
123
+ this.locales = e.locales, this.defaultLocale = this.findLocaleByCode(e.locales, e.defaultLocaleCode) ?? { code: e.defaultLocaleCode }, this.strategy = e.strategy, this.globalLocaleRoutes = se(e.globalLocaleRoutes ?? {}), this.filesLocaleRoutes = e.filesLocaleRoutes ?? {}, this.routeLocales = e.routeLocales ?? {}, this.localizedPaths = _(e.pages, this.globalLocaleRoutes, this.filesLocaleRoutes), this.activeLocaleCodes = this.locales.filter((t) => t.code !== this.defaultLocale.code || O(this.strategy) || D(this.strategy)).map((t) => t.code), this.excludePatterns = e.excludePatterns, this.customRegex = e.customRegex, this.noPrefixRedirect = e.noPrefixRedirect ?? !1, this.localizedRouteNamePrefix = e.localizedRouteNamePrefix ?? "localized-", this.fallbackRedirectComponentPath = e.fallbackRedirectComponentPath, this.rawGlobalLocaleRoutes = e.rawGlobalLocaleRoutes;
120
124
  }
121
125
  findLocaleByCode(e, t) {
122
- return e.find((s) => s.code === t);
126
+ return e.find((a) => a.code === t);
123
127
  }
124
128
  /**
125
129
  * Returns the list of locale codes allowed for a page (respecting routeLocales).
126
130
  */
127
131
  getAllowedLocales(e, t) {
128
- const s = this.routeLocales[e] ?? this.routeLocales[t];
129
- return s?.length ? s.filter((o) => this.locales.some((a) => a.code === o)) : this.locales.map((o) => o.code);
132
+ const a = this.routeLocales[e] ?? this.routeLocales[t];
133
+ return a?.length ? a.filter((o) => this.locales.some((s) => s.code === o)) : this.locales.map((o) => o.code);
130
134
  }
131
135
  /**
132
136
  * Returns a custom path for a given locale by original page path, if any.
133
137
  */
134
138
  getCustomPath(e, t) {
135
- const s = F(e);
136
- return this.localizedPaths[s]?.[t];
139
+ const a = F(e);
140
+ return this.localizedPaths[a]?.[t];
137
141
  }
138
142
  /**
139
143
  * Returns a map of custom paths (locale → path) for a page by path key or name.
140
144
  */
141
145
  getCustomPathsForPage(e, t) {
142
- const s = F(e);
143
- return this.localizedPaths[s] ?? this.localizedPaths[t];
146
+ const a = F(e);
147
+ return this.localizedPaths[a] ?? this.localizedPaths[t];
144
148
  }
145
149
  hasLocaleRestrictions(e, t) {
146
150
  return !!(this.routeLocales[e] ?? this.routeLocales[t]);
147
151
  }
148
152
  filterLocaleCodesWithoutCustomPaths(e) {
149
153
  const t = F(e);
150
- return this.activeLocaleCodes.filter((s) => !this.localizedPaths[t]?.[s]);
154
+ return this.activeLocaleCodes.filter((a) => !this.localizedPaths[t]?.[a]);
151
155
  }
152
156
  }
153
- function g(l, e) {
157
+ function y(l, e) {
154
158
  const t = (e ?? "").trim();
155
- return t.startsWith("/") ? R(t) : R(A.posix.join(l || "", t));
159
+ return t.startsWith("/") ? R(t) : R(w.posix.join(l || "", t));
156
160
  }
157
161
  function z(l, e) {
158
- const { path: t, name: s, children: o, meta: a, alias: r } = e, i = {
162
+ const { path: t, name: a, children: o, meta: s, alias: r } = e, i = {
159
163
  ...l,
160
164
  path: t
161
165
  };
162
- return s !== void 0 && (i.name = s), o !== void 0 && (i.children = o), a !== void 0 && (i.meta = { ...l.meta, ...a }), r !== void 0 ? (i.alias = r, i.meta = { ...i.meta, alias: r }) : "alias" in e && (i.alias = void 0, i.meta = { ...i.meta, alias: void 0 }), i;
166
+ return a !== void 0 && (i.name = a), o !== void 0 && (i.children = o), s !== void 0 && (i.meta = { ...l.meta, ...s }), r !== void 0 ? (i.alias = r, i.meta = { ...i.meta, alias: r }) : "alias" in e && (i.alias = void 0, i.meta = { ...i.meta, alias: void 0 }), i;
163
167
  }
164
- function oe(l) {
165
- const e = l.alias, t = l.meta?.alias, s = e ?? t;
166
- return Array.isArray(s) ? s : [];
168
+ function le(l) {
169
+ const e = l.alias, t = l.meta?.alias, a = e ?? t;
170
+ return Array.isArray(a) ? a : [];
167
171
  }
168
- function _(l, e, t, s = "localized-") {
169
- const o = oe(l);
172
+ function W(l, e, t, a = "localized-") {
173
+ const o = le(l);
170
174
  if (!o.length) return [];
171
- const a = [];
175
+ const s = [];
172
176
  for (const r of o) {
173
- const i = w(e, r, t);
174
- a.push(
177
+ const i = x(e, r, t);
178
+ s.push(
175
179
  z(l, {
176
180
  path: i,
177
- name: `${s}${l.name ?? ""}`,
181
+ name: `${a}${l.name ?? ""}`,
178
182
  alias: void 0,
179
183
  meta: { alias: void 0 },
180
184
  // Important: if the source page has children, the alias route
@@ -184,18 +188,18 @@ function _(l, e, t, s = "localized-") {
184
188
  })
185
189
  );
186
190
  }
187
- return a;
191
+ return s;
188
192
  }
189
- class S {
193
+ class k {
190
194
  processPage(e, t) {
191
195
  if (e.path === void 0)
192
196
  throw new Error("page.path is required");
193
- if (U(e))
197
+ if (q(e))
194
198
  return [e];
195
- if (e.path && D(e.path, t.excludePatterns))
199
+ if (e.path && M(e.path, t.excludePatterns))
196
200
  return [e];
197
- const s = e.path ?? "", o = b(e.name, e.path), a = N(s);
198
- return t.globalLocaleRoutes[o] === !1 || t.globalLocaleRoutes[a] === !1 ? [e] : this.generateVariants(e, t);
201
+ const a = e.path ?? "", o = b(e.name, e.path);
202
+ return S(t.globalLocaleRoutes, a, o) ? [e] : this.generateVariants(e, t);
199
203
  }
200
204
  postProcess(e, t) {
201
205
  return e;
@@ -206,39 +210,45 @@ class S {
206
210
  * - parentLocalizedPath used for the final path,
207
211
  * and returns an array of localized child routes.
208
212
  */
209
- localizeChildren(e, t, s, o, a, r) {
210
- return e.flatMap((i) => this.localizeChild(i, t, s, o, a, r));
213
+ localizeChildren(e, t, a, o, s, r) {
214
+ return e.flatMap((i) => this.localizeChild(i, t, a, o, s, r));
211
215
  }
212
216
  /**
213
217
  * Variant for a single route with :locale(locale1|locale2) — without custom paths.
214
218
  * Returns a single child route with a relative path and recursively localized children.
215
219
  */
216
- localizeChildrenAllLocales(e, t, s, o, a) {
217
- return e.flatMap((r) => this.localizeChildAllLocales(r, t, s, o, a));
218
- }
219
- localizeChildAllLocales(e, t, s, o, a) {
220
- const r = g(s, e.path ?? ""), i = g(t, e.path ?? ""), n = F(i), f = a.localizedPaths[n];
221
- if (f)
222
- return o.flatMap((d) => {
223
- const P = f[d] ?? g(t, e.path ?? "");
224
- return this.localizeChild(e, P, s, d, a, !0);
220
+ localizeChildrenAllLocales(e, t, a, o, s) {
221
+ return e.flatMap((r) => this.localizeChildAllLocales(r, t, a, o, s));
222
+ }
223
+ localizeChildAllLocales(e, t, a, o, s) {
224
+ const r = y(a, e.path ?? ""), i = b(e.name, e.path);
225
+ if (S(s.globalLocaleRoutes, r, i))
226
+ return [e];
227
+ const n = y(t, e.path ?? ""), f = F(n), c = s.localizedPaths[f];
228
+ if (c)
229
+ return o.flatMap((P) => {
230
+ const p = c[P] ?? y(t, e.path ?? "");
231
+ return this.localizeChild(e, p, a, P, s, !0);
225
232
  });
226
- const c = R(e.path ?? ""), h = y(c), u = this.localizeChildrenAllLocales($(e.children ?? []), i, r, o, a), m = `${a.localizedRouteNamePrefix}${e.name ?? ""}`;
233
+ const h = R(e.path ?? ""), u = g(h), m = this.localizeChildrenAllLocales($(e.children ?? []), n, r, o, s), d = `${s.localizedRouteNamePrefix}${e.name ?? ""}`;
227
234
  return [
228
235
  z(e, {
229
- path: h,
230
- name: m,
231
- children: u
236
+ path: u,
237
+ name: d,
238
+ children: m
232
239
  })
233
240
  ];
234
241
  }
235
- localizeChild(e, t, s, o, a, r) {
236
- const i = g(s, e.path ?? ""), n = a.getCustomPath(i, o), f = y(R(n || (e.path ?? ""))), c = n ?? g(t, e.path ?? ""), h = this.localizeChildren($(e.children ?? []), c, i, o, a, r), u = b(e.name, e.path), m = `${a.localizedRouteNamePrefix}${u}-${o}`;
242
+ localizeChild(e, t, a, o, s, r) {
243
+ const i = y(a, e.path ?? ""), n = b(e.name, e.path);
244
+ if (S(s.globalLocaleRoutes, i, n))
245
+ return [e];
246
+ const f = s.getCustomPath(i, o), c = g(R(f || (e.path ?? ""))), h = f ?? y(t, e.path ?? ""), u = this.localizeChildren($(e.children ?? []), h, i, o, s, r), m = b(e.name, e.path), d = `${s.localizedRouteNamePrefix}${m}-${o}`;
237
247
  return [
238
248
  z(e, {
239
- path: f,
240
- name: m,
241
- children: h
249
+ path: c,
250
+ name: d,
251
+ children: u
242
252
  })
243
253
  ];
244
254
  }
@@ -249,25 +259,25 @@ class S {
249
259
  *
250
260
  * The logic matches what used to be duplicated in each strategy's buildRoutePath.
251
261
  */
252
- buildRoutePathForLocales(e, t, s, o, a, r, i) {
262
+ buildRoutePathForLocales(e, t, a, o, s, r, i) {
253
263
  if (o) {
254
264
  const n = e.includes(i);
255
- return r || !n ? w(e, s, a) : R(s);
265
+ return r || !n ? x(e, a, s) : R(a);
256
266
  }
257
- return w(e, t, a);
267
+ return x(e, t, s);
258
268
  }
259
269
  }
260
- class le extends S {
270
+ class ie extends k {
261
271
  generateVariants(e, t) {
262
- const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [];
272
+ const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [];
263
273
  if (n.push(e), r)
264
- for (const f of a) {
274
+ for (const f of s) {
265
275
  const c = r[f];
266
276
  if (!c) continue;
267
- const h = R(c), u = R(s);
277
+ const h = R(c), u = R(a);
268
278
  if (h === u)
269
279
  continue;
270
- const m = ee(c), d = j(o, f, !0), P = this.localizeChildrenForNoPrefix(i, h, s, s, f, t, 1);
280
+ const m = te(c), d = j(o, f, !0), P = this.localizeChildrenForNoPrefix(i, h, a, a, f, t, 1);
271
281
  n.push(
272
282
  z(e, {
273
283
  path: m,
@@ -278,7 +288,7 @@ class le extends S {
278
288
  })
279
289
  ), t.noPrefixRedirect && f === t.defaultLocale.code && h !== u && (e.redirect = h);
280
290
  }
281
- return n.push(..._(e, a, t.customRegex, t.localizedRouteNamePrefix)), n;
291
+ return n.push(...W(e, s, t.customRegex, t.localizedRouteNamePrefix)), n;
282
292
  }
283
293
  /**
284
294
  * Localizes the children tree for the no_prefix strategy.
@@ -286,32 +296,32 @@ class le extends S {
286
296
  * - on the first level, custom paths (globalLocaleRoutes/filesLocaleRoutes) are applied;
287
297
  * - on deeper levels, path stays as a segment (item, detail, etc.).
288
298
  */
289
- localizeChildrenForNoPrefix(e, t, s, o, a, r, i) {
299
+ localizeChildrenForNoPrefix(e, t, a, o, s, r, i) {
290
300
  return e.map((n) => {
291
- const f = g(s, n.path ?? "");
301
+ const f = y(a, n.path ?? "");
292
302
  let c, h;
293
303
  if (i === 1) {
294
- const P = r.getCustomPath(f, a);
304
+ const P = r.getCustomPath(f, s);
295
305
  if (P) {
296
- const L = R(P);
297
- c = y(L), h = L;
306
+ const p = R(P);
307
+ c = g(p), h = p;
298
308
  } else {
299
- const L = R(n.path ?? "");
300
- c = y(L), h = g(t, n.path ?? "");
309
+ const p = R(n.path ?? "");
310
+ c = g(p), h = y(t, n.path ?? "");
301
311
  }
302
312
  } else {
303
313
  const P = R(n.path ?? "");
304
- c = y(P), h = g(t, n.path ?? "");
314
+ c = g(P), h = y(t, n.path ?? "");
305
315
  }
306
316
  const u = this.localizeChildrenForNoPrefix(
307
317
  $(n.children ?? []),
308
318
  h,
309
319
  f,
310
320
  o,
311
- a,
321
+ s,
312
322
  r,
313
323
  i + 1
314
- ), m = b(n.name, n.path), d = j(m, a, !0);
324
+ ), m = b(n.name, n.path), d = j(m, s, !0);
315
325
  return z(n, {
316
326
  path: c,
317
327
  name: d,
@@ -320,28 +330,28 @@ class le extends S {
320
330
  });
321
331
  }
322
332
  }
323
- function ie(l) {
333
+ function re(l) {
324
334
  const e = l.alias ?? l.meta?.alias;
325
335
  return Array.isArray(e) ? e : [];
326
336
  }
327
- class re extends S {
337
+ class ne extends k {
328
338
  generateVariants(e, t) {
329
- const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [];
339
+ const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [];
330
340
  if (r)
331
- for (const c of a) {
332
- const h = r[c], u = h ? R(h) : s, m = w(c, u, t.customRegex), d = j(o, c, !!h, t.localizedRouteNamePrefix), P = h ?? s, L = this.localizeChildren(i, P, s, c, t, !0), p = Z(m);
341
+ for (const c of s) {
342
+ const h = r[c], u = h ? R(h) : a, m = x(c, u, t.customRegex), d = j(o, c, !!h, t.localizedRouteNamePrefix), P = h ?? a, p = this.localizeChildren(i, P, a, c, t, !0), L = ee(m);
333
343
  n.push(
334
344
  z(e, {
335
345
  path: m,
336
346
  name: d,
337
- children: L,
338
- alias: p.length ? p : void 0,
339
- meta: { alias: p.length ? p : [] }
347
+ children: p,
348
+ alias: L.length ? L : void 0,
349
+ meta: { alias: L.length ? L : [] }
340
350
  })
341
351
  );
342
352
  }
343
353
  else {
344
- const c = w(a, s, t.customRegex), h = j(o, a[0], !1, t.localizedRouteNamePrefix), u = this.localizeChildrenAllLocales(i, s, s, a, t);
354
+ const c = x(s, a, t.customRegex), h = j(o, s[0], !1, t.localizedRouteNamePrefix), u = this.localizeChildrenAllLocales(i, a, a, s, t);
345
355
  n.push(
346
356
  z(e, {
347
357
  path: c,
@@ -352,10 +362,10 @@ class re extends S {
352
362
  })
353
363
  );
354
364
  }
355
- const f = ie(e);
365
+ const f = re(e);
356
366
  if (f.length)
357
367
  for (const c of f) {
358
- const h = w(a, c, t.customRegex);
368
+ const h = x(s, c, t.customRegex);
359
369
  n.push(
360
370
  z(e, {
361
371
  path: h,
@@ -368,37 +378,37 @@ class re extends S {
368
378
  return n;
369
379
  }
370
380
  postProcess(e, t) {
371
- const s = e.filter((a) => {
372
- if (a.name === "index" && a.path === "/") return !1;
373
- const r = a.path ?? "";
374
- return !!(r && D(r, t.excludePatterns) || t.globalLocaleRoutes[a.name ?? ""] === !1 || /^\/:locale/.test(r) || r === "/");
381
+ const a = e.filter((s) => {
382
+ if (s.name === "index" && s.path === "/") return !1;
383
+ const r = s.path ?? "";
384
+ return !!(r && M(r, t.excludePatterns) || S(t.globalLocaleRoutes, r, s.name ?? "") || /^\/:locale/.test(r) || r === "/");
375
385
  }), o = t.defaultLocale.code;
376
- for (const [a, r] of Object.entries(t.globalLocaleRoutes)) {
386
+ for (const [s, r] of Object.entries(t.globalLocaleRoutes)) {
377
387
  if (r === !1 || typeof r != "object") continue;
378
388
  const i = r[o];
379
389
  if (!i) continue;
380
- const n = a.startsWith("/") ? a : `/${a}`, f = `/${o}${i.startsWith("/") ? i : `/${i}`}`;
381
- n !== f && s.push({
390
+ const n = s.startsWith("/") ? s : `/${s}`, f = `/${o}${i.startsWith("/") ? i : `/${i}`}`;
391
+ n !== f && a.push({
382
392
  path: n,
383
- name: `redirect-${a.replace(/\//g, "-")}`,
393
+ name: `redirect-${s.replace(/\//g, "-")}`,
384
394
  redirect: f
385
395
  });
386
396
  }
387
- return t.fallbackRedirectComponentPath && s.push({
397
+ return t.fallbackRedirectComponentPath && a.push({
388
398
  path: "/:pathMatch(.*)*",
389
399
  name: "custom-fallback-route",
390
400
  file: t.fallbackRedirectComponentPath,
391
401
  meta: {
392
402
  globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes
393
403
  }
394
- }), s;
404
+ }), a;
395
405
  }
396
406
  }
397
- class ne extends S {
407
+ class ce extends k {
398
408
  generateVariants(e, t) {
399
- const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
409
+ const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
400
410
  n.push(e);
401
- const c = t.locales.filter((u) => a.includes(u.code));
411
+ const c = t.locales.filter((u) => s.includes(u.code));
402
412
  if (c.length > 0)
403
413
  if (r)
404
414
  for (const u of c) {
@@ -414,7 +424,7 @@ class ne extends S {
414
424
  t.customRegex,
415
425
  !1,
416
426
  u.code,
417
- s,
427
+ a,
418
428
  t
419
429
  );
420
430
  d && n.push(d);
@@ -427,7 +437,7 @@ class ne extends S {
427
437
  t.customRegex,
428
438
  !0,
429
439
  u.code,
430
- s,
440
+ a,
431
441
  t
432
442
  );
433
443
  P && n.push(P);
@@ -441,7 +451,7 @@ class ne extends S {
441
451
  t.customRegex,
442
452
  !1,
443
453
  u.code,
444
- s,
454
+ a,
445
455
  t
446
456
  );
447
457
  d && n.push(d);
@@ -456,7 +466,7 @@ class ne extends S {
456
466
  t.customRegex,
457
467
  !1,
458
468
  u.code,
459
- s,
469
+ a,
460
470
  t
461
471
  );
462
472
  d && n.push(d);
@@ -472,33 +482,33 @@ class ne extends S {
472
482
  t.customRegex,
473
483
  !1,
474
484
  !0,
475
- s,
485
+ a,
476
486
  t
477
487
  );
478
488
  m && n.push(m);
479
489
  }
480
- const h = _(e, a, t.customRegex, t.localizedRouteNamePrefix);
490
+ const h = W(e, s, t.customRegex, t.localizedRouteNamePrefix);
481
491
  return h.length && n.push(...h), n;
482
492
  }
483
493
  postProcess(e, t) {
484
- const s = [], o = [];
485
- for (const a of e) {
486
- const r = a.name ?? "";
487
- typeof r == "string" && r.startsWith(t.localizedRouteNamePrefix) ? o.push(a) : s.push(a);
494
+ const a = [], o = [];
495
+ for (const s of e) {
496
+ const r = s.name ?? "";
497
+ typeof r == "string" && r.startsWith(t.localizedRouteNamePrefix) ? o.push(s) : a.push(s);
488
498
  }
489
- return [...s, ...o];
499
+ return [...a, ...o];
490
500
  }
491
- createLocalizedRoute(e, t, s, o, a = "", r, i = !1, n = !1, f, c) {
501
+ createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f, c) {
492
502
  const h = this.buildRoutePathForLocales(
493
503
  t,
494
504
  e.path ?? "",
495
- a,
505
+ s,
496
506
  o,
497
507
  r,
498
508
  i,
499
509
  c.defaultLocale.code
500
510
  );
501
- if (!h || !(o && a) && h === e.path || t.length === 0) return null;
511
+ if (!h || !(o && s) && h === e.path || t.length === 0) return null;
502
512
  const m = t[0];
503
513
  if (!m) return null;
504
514
  const d = f ?? e.path ?? "", P = j(
@@ -506,23 +516,23 @@ class ne extends S {
506
516
  m,
507
517
  o,
508
518
  c.localizedRouteNamePrefix
509
- ), L = i || m !== c.defaultLocale.code, p = t.length === 1 ? this.localizeChildren(s, h, d, m, c, L) : this.localizeChildrenAllLocales(s, h, d, t, c);
519
+ ), p = i || m !== c.defaultLocale.code, L = t.length === 1 ? this.localizeChildren(a, h, d, m, c, p) : this.localizeChildrenAllLocales(a, h, d, t, c);
510
520
  return z(e, {
511
521
  path: h,
512
522
  name: P,
513
- children: p,
523
+ children: L,
514
524
  alias: [],
515
525
  meta: { alias: [] }
516
526
  });
517
527
  }
518
528
  }
519
- class ce extends S {
529
+ class ue extends k {
520
530
  generateVariants(e, t) {
521
- const s = e.path ?? "", o = b(e.name, e.path), a = t.getAllowedLocales(s, o), r = t.getCustomPathsForPage(s, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
522
- if (a.includes(f)) {
523
- const u = r?.[f], m = u ? R(u) : s, d = u ? { [f]: u } : {}, P = this.createLocalizedChildren(
531
+ const a = e.path ?? "", o = b(e.name, e.path), s = t.getAllowedLocales(a, o), r = t.getCustomPathsForPage(a, o), i = $(e.children ?? []), n = [], f = t.defaultLocale.code;
532
+ if (s.includes(f)) {
533
+ const u = r?.[f], m = u ? R(u) : a, d = u ? { [f]: u } : {}, P = this.createLocalizedChildren(
524
534
  i,
525
- s,
535
+ a,
526
536
  [f],
527
537
  !1,
528
538
  !1,
@@ -538,7 +548,7 @@ class ce extends S {
538
548
  })
539
549
  );
540
550
  }
541
- const c = t.locales.filter((u) => a.includes(u.code) && u.code !== f);
551
+ const c = t.locales.filter((u) => s.includes(u.code) && u.code !== f);
542
552
  if (c.length)
543
553
  if (r)
544
554
  for (const u of c) {
@@ -553,7 +563,7 @@ class ce extends S {
553
563
  t.customRegex,
554
564
  !1,
555
565
  u.code,
556
- s,
566
+ a,
557
567
  t
558
568
  );
559
569
  d && n.push(d);
@@ -567,7 +577,7 @@ class ce extends S {
567
577
  t.customRegex,
568
578
  !1,
569
579
  u.code,
570
- s,
580
+ a,
571
581
  t
572
582
  );
573
583
  d && n.push(d);
@@ -583,73 +593,73 @@ class ce extends S {
583
593
  t.customRegex,
584
594
  !1,
585
595
  !0,
586
- s,
596
+ a,
587
597
  t
588
598
  );
589
599
  m && n.push(m);
590
600
  }
591
- const h = _(e, a, t.customRegex, t.localizedRouteNamePrefix);
601
+ const h = W(e, s, t.customRegex, t.localizedRouteNamePrefix);
592
602
  return h.length && n.push(...h), n;
593
603
  }
594
604
  postProcess(e, t) {
595
- const s = [], o = [];
605
+ const a = [], o = [];
596
606
  for (const r of e) {
597
607
  const i = r.name ?? "";
598
- typeof i == "string" && i.startsWith(t.localizedRouteNamePrefix) ? o.push(r) : s.push(r);
608
+ typeof i == "string" && i.startsWith(t.localizedRouteNamePrefix) ? o.push(r) : a.push(r);
599
609
  }
600
- const a = [...s, ...o];
601
- return t.fallbackRedirectComponentPath && a.push({
610
+ const s = [...a, ...o];
611
+ return t.fallbackRedirectComponentPath && s.push({
602
612
  path: "/:pathMatch(.*)*",
603
613
  name: "custom-fallback-route",
604
614
  file: t.fallbackRedirectComponentPath,
605
615
  meta: {
606
616
  globalLocaleRoutes: t.rawGlobalLocaleRoutes ?? t.globalLocaleRoutes
607
617
  }
608
- }), a;
618
+ }), s;
609
619
  }
610
- createLocalizedChildren(e, t, s, o = !0, a = !1, r = !1, i = {}, n) {
620
+ createLocalizedChildren(e, t, a, o = !0, s = !1, r = !1, i = {}, n) {
611
621
  return e.flatMap(
612
- (f) => this.createLocalizedVariants(f, t, s, o, a, r, i, n)
622
+ (f) => this.createLocalizedVariants(f, t, a, o, s, r, i, n)
613
623
  );
614
624
  }
615
- createLocalizedVariants(e, t, s, o, a, r = !1, i, n) {
616
- const f = R(e.path ?? ""), c = g(t, e.path ?? ""), h = F(c), u = n.localizedPaths[h], m = !!u, d = [];
625
+ createLocalizedVariants(e, t, a, o, s, r = !1, i, n) {
626
+ const f = R(e.path ?? ""), c = y(t, e.path ?? ""), h = F(c), u = n.localizedPaths[h], m = !!u, d = [];
617
627
  if (!m) {
618
- const P = y(f), L = this.createLocalizedChildren(
628
+ const P = g(f), p = this.createLocalizedChildren(
619
629
  $(e.children ?? []),
620
- g(t, e.path ?? ""),
621
- s,
622
- o,
630
+ y(t, e.path ?? ""),
623
631
  a,
632
+ o,
633
+ s,
624
634
  r,
625
635
  i,
626
636
  n
627
- ), p = this.buildChildRouteName(e.name, r, n);
637
+ ), L = this.buildChildRouteName(e.name, r, n);
628
638
  return d.push(
629
639
  z(e, {
630
640
  path: P,
631
- name: p,
632
- children: L
641
+ name: L,
642
+ children: p
633
643
  })
634
644
  ), d;
635
645
  }
636
- for (const P of s) {
637
- const L = i?.[P], p = !!L, C = u?.[P];
638
- let x = R(C || (e.path ?? ""));
639
- p && L && (C ? x = R(C) : x = g(L, e.path ?? ""));
640
- const v = q(P, n.defaultLocale, a) ? w(P, x, n.customRegex) : x, M = y(v), W = C ? R(C) : p ? L : g(t, e.path ?? ""), T = this.createLocalizedChildren(
646
+ for (const P of a) {
647
+ const p = i?.[P], L = !!p, C = u?.[P];
648
+ let A = R(C || (e.path ?? ""));
649
+ L && p && (C ? A = R(C) : A = y(p, e.path ?? ""));
650
+ const v = H(P, n.defaultLocale, s) ? x(P, A, n.customRegex) : A, T = g(v), E = C ? R(C) : L ? p : y(t, e.path ?? ""), V = this.createLocalizedChildren(
641
651
  $(e.children ?? []),
642
- W,
652
+ E,
643
653
  [P],
644
654
  o,
645
- a,
655
+ s,
646
656
  P,
647
657
  {
648
658
  ...i,
649
- [P]: W
659
+ [P]: E
650
660
  },
651
661
  n
652
- ), V = this.buildLocalizedRouteName(
662
+ ), B = this.buildLocalizedRouteName(
653
663
  b(e.name, e.path),
654
664
  P,
655
665
  o,
@@ -658,22 +668,22 @@ class ce extends S {
658
668
  );
659
669
  d.push(
660
670
  z(e, {
661
- path: M,
662
- name: V,
663
- children: T
671
+ path: T,
672
+ name: B,
673
+ children: V
664
674
  })
665
675
  );
666
676
  }
667
677
  return d;
668
678
  }
669
- buildChildRouteName(e, t, s) {
670
- return t === !0 ? `${s.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${s.localizedRouteNamePrefix}${e}-${t}` : e;
679
+ buildChildRouteName(e, t, a) {
680
+ return t === !0 ? `${a.localizedRouteNamePrefix}${e}` : typeof t == "string" ? `${a.localizedRouteNamePrefix}${e}-${t}` : e;
671
681
  }
672
- createLocalizedRoute(e, t, s, o, a = "", r, i = !1, n = !1, f, c) {
682
+ createLocalizedRoute(e, t, a, o, s = "", r, i = !1, n = !1, f, c) {
673
683
  const h = this.buildRoutePathForLocales(
674
684
  t,
675
685
  e.path ?? "",
676
- a,
686
+ s,
677
687
  o,
678
688
  r,
679
689
  i,
@@ -692,45 +702,45 @@ class ce extends S {
692
702
  path: h,
693
703
  name: d,
694
704
  children: this.createLocalizedChildren(
695
- s,
705
+ a,
696
706
  m,
697
707
  t,
698
708
  !0,
699
709
  !1,
700
710
  n,
701
- { [u]: a },
711
+ { [u]: s },
702
712
  c
703
713
  ),
704
714
  alias: [],
705
715
  meta: { alias: [] }
706
716
  });
707
717
  }
708
- buildLocalizedRouteName(e, t, s, o = !1, a) {
709
- return s ? o ? `${a.localizedRouteNamePrefix}${e}-${t}` : t && !H(t, a.defaultLocale) ? `${a.localizedRouteNamePrefix}${e}-${t}` : `${a.localizedRouteNamePrefix}${e}` : e;
718
+ buildLocalizedRouteName(e, t, a, o = !1, s) {
719
+ return a ? o ? `${s.localizedRouteNamePrefix}${e}-${t}` : t && !J(t, s.defaultLocale) ? `${s.localizedRouteNamePrefix}${e}-${t}` : `${s.localizedRouteNamePrefix}${e}` : e;
710
720
  }
711
721
  }
712
- function ue(l) {
722
+ function he(l) {
713
723
  switch (l) {
714
724
  case "no_prefix":
715
- return new le();
725
+ return new ie();
716
726
  case "prefix":
717
- return new re();
718
- case "prefix_and_default":
719
727
  return new ne();
720
- case "prefix_except_default":
728
+ case "prefix_and_default":
721
729
  return new ce();
730
+ case "prefix_except_default":
731
+ return new ue();
722
732
  default:
723
733
  throw new Error(`Unknown route strategy: ${l}`);
724
734
  }
725
735
  }
726
- class Pe {
736
+ class Re {
727
737
  constructor(e) {
728
738
  this.localizedPaths = {};
729
739
  const {
730
740
  locales: t,
731
- defaultLocaleCode: s,
741
+ defaultLocaleCode: a,
732
742
  strategy: o,
733
- globalLocaleRoutes: a,
743
+ globalLocaleRoutes: s,
734
744
  filesLocaleRoutes: r = {},
735
745
  routeLocales: i = {},
736
746
  noPrefixRedirect: n,
@@ -738,28 +748,28 @@ class Pe {
738
748
  localizedRouteNamePrefix: c = "localized-",
739
749
  customRegexMatcher: h,
740
750
  fallbackRedirectComponentPath: u
741
- } = e, m = Q(t, s);
751
+ } = e, m = X(t, a);
742
752
  this.locales = m.locales, this.defaultLocale = m.defaultLocale, this.strategy = o, this.noPrefixRedirect = n, this.excludePatterns = f, this.localizedRouteNamePrefix = c, this.customRegex = h, this.fallbackRedirectComponentPath = u, this.activeLocaleCodes = this.computeActiveLocaleCodes();
743
753
  const d = {};
744
- for (const P in a) {
745
- const L = N(P), p = a[P];
746
- if (typeof p == "object") {
754
+ for (const P in s) {
755
+ const p = N(P), L = s[P];
756
+ if (typeof L == "object") {
747
757
  const C = {};
748
- for (const x in p) {
749
- const v = p[x];
750
- v && (C[x] = N(v));
758
+ for (const A in L) {
759
+ const v = L[A];
760
+ v && (C[A] = N(v));
751
761
  }
752
- d[L] = C;
762
+ d[p] = C;
753
763
  } else
754
- d[L] = p;
764
+ d[p] = L;
755
765
  }
756
- this.globalLocaleRoutes = d, this.rawGlobalLocaleRoutes = a ?? {}, this.filesLocaleRoutes = r ?? {}, this.routeLocales = i ?? {};
766
+ this.globalLocaleRoutes = d, this.rawGlobalLocaleRoutes = s ?? {}, this.filesLocaleRoutes = r ?? {}, this.routeLocales = i ?? {};
757
767
  }
758
768
  computeActiveLocaleCodes() {
759
- return this.locales.filter((e) => e.code !== this.defaultLocale.code || K(this.strategy) || O(this.strategy)).map((e) => e.code);
769
+ return this.locales.filter((e) => e.code !== this.defaultLocale.code || O(this.strategy) || D(this.strategy)).map((e) => e.code);
760
770
  }
761
771
  extendPages(e) {
762
- const t = new se({
772
+ const t = new oe({
763
773
  locales: this.locales,
764
774
  defaultLocaleCode: this.defaultLocale.code,
765
775
  strategy: this.strategy,
@@ -775,31 +785,31 @@ class Pe {
775
785
  rawGlobalLocaleRoutes: this.rawGlobalLocaleRoutes
776
786
  });
777
787
  this.localizedPaths = t.localizedPaths;
778
- const s = ue(this.strategy), o = [...e], a = [];
788
+ const a = he(this.strategy), o = [...e], s = [];
779
789
  for (const i of o)
780
- a.push(...s.processPage(i, t));
781
- const r = s.postProcess(a, t);
790
+ s.push(...a.processPage(i, t));
791
+ const r = a.postProcess(s, t);
782
792
  e.length = 0, e.push(...r);
783
793
  }
784
794
  extractLocalizedPaths(e, t = "") {
785
- return k(e, this.globalLocaleRoutes, this.filesLocaleRoutes, t);
795
+ return _(e, this.globalLocaleRoutes, this.filesLocaleRoutes, t);
786
796
  }
787
797
  /**
788
798
  * Creates global and per-page translation JSON files for the current resolved locales.
789
799
  */
790
- ensureTranslationFilesExist(e, t, s, o) {
791
- this.locales.forEach((a) => {
792
- const r = A.join(s, t, `${a.code}.json`);
800
+ ensureTranslationFilesExist(e, t, a, o) {
801
+ this.locales.forEach((s) => {
802
+ const r = w.join(a, t, `${s.code}.json`);
793
803
  this.ensureFileExists(r), o || e.forEach((i) => {
794
- const n = A.join(s, t, "pages", `${i}/${a.code}.json`);
804
+ const n = w.join(a, t, "pages", `${i}/${s.code}.json`);
795
805
  this.ensureFileExists(n);
796
806
  });
797
807
  });
798
808
  }
799
809
  ensureFileExists(e) {
800
810
  try {
801
- const t = A.dirname(e);
802
- E(t) || B(t, { recursive: !0 }), E(e) || I(e, JSON.stringify({}), "utf-8");
811
+ const t = w.dirname(e);
812
+ K(t) || I(t, { recursive: !0 }), K(e) || U(e, JSON.stringify({}), "utf-8");
803
813
  } catch {
804
814
  }
805
815
  }
@@ -809,15 +819,15 @@ class Pe {
809
819
  * Used by nitro:config and prerender so route rules work with custom paths (e.g. /de/ueber-uns).
810
820
  */
811
821
  resolveLocalizedPath(e, t) {
812
- const s = N(e), o = y(s) || "/";
813
- let a;
814
- const r = this.globalLocaleRoutes[o], i = this.globalLocaleRoutes[s];
815
- r && typeof r == "object" && !Array.isArray(r) ? a = r[t] : i && typeof i == "object" && !Array.isArray(i) && (a = i[t]);
816
- const n = !!a, f = a ? R(a) : R(s) || "";
822
+ const a = N(e), o = g(a) || "/";
823
+ let s;
824
+ const r = this.globalLocaleRoutes[o], i = this.globalLocaleRoutes[a];
825
+ r && typeof r == "object" && !Array.isArray(r) ? s = r[t] : i && typeof i == "object" && !Array.isArray(i) && (s = i[t]);
826
+ const n = !!s, f = s ? R(s) : R(a) || "";
817
827
  let c = !1;
818
828
  if (this.strategy === "no_prefix" ? c = !1 : this.strategy === "prefix" || this.strategy === "prefix_and_default" ? c = !0 : this.strategy === "prefix_except_default" && (c = t !== this.defaultLocale.code), t === this.defaultLocale.code && !n && (this.strategy === "prefix_except_default" || this.strategy === "no_prefix") && (c = !1), !c)
819
829
  return R(f) || "/";
820
- const h = y(f);
830
+ const h = g(f);
821
831
  return h ? R(`/${t}/${h}`) : `/${t}`;
822
832
  }
823
833
  /**
@@ -825,36 +835,37 @@ class Pe {
825
835
  * When disablePageLocales is true, only index routes are generated (all pages share root translations).
826
836
  * Otherwise, generates index + per-page routes for each locale.
827
837
  */
828
- generateDataRoutes(e, t, s) {
829
- const o = [], a = this.collectPageNames(e);
838
+ generateDataRoutes(e, t, a) {
839
+ const o = [], s = this.collectPageNames(e);
830
840
  for (const r of this.locales)
831
- if (o.push(`/${t}/index/${r.code}/data.json`), !s)
832
- for (const i of a)
841
+ if (o.push(`/${t}/index/${r.code}/data.json`), !a)
842
+ for (const i of s)
833
843
  o.push(`/${t}/${i}/${r.code}/data.json`);
834
844
  return o;
835
845
  }
836
846
  collectPageNames(e) {
837
- const t = /* @__PURE__ */ new Set(), s = (o) => {
838
- for (const a of o)
839
- typeof a.name == "string" && a.name.length > 0 && t.add(a.name), a.children && a.children.length > 0 && s(a.children);
847
+ const t = /* @__PURE__ */ new Set(), a = (o) => {
848
+ for (const s of o)
849
+ typeof s.name == "string" && s.name.length > 0 && t.add(s.name), s.children && s.children.length > 0 && a(s.children);
840
850
  };
841
- return s(e), [...t];
851
+ return a(e), [...t];
842
852
  }
843
853
  }
844
854
  export {
845
- Pe as RouteGenerator,
846
- Z as buildEncodedPathAliases,
847
- w as buildFullPath,
848
- ee as buildFullPathNoPrefix,
855
+ Re as RouteGenerator,
856
+ ee as buildEncodedPathAliases,
857
+ x as buildFullPath,
858
+ te as buildFullPathNoPrefix,
849
859
  j as buildRouteName,
850
860
  $ as cloneArray,
851
- k as extractLocalizedPaths,
852
- D as isInternalPath,
853
- me as isLocaleAllowedForUnlocalizedRoute,
854
- H as isLocaleDefault,
855
- U as isPageRedirectOnly,
861
+ _ as extractLocalizedPaths,
862
+ M as isInternalPath,
863
+ Pe as isLocaleAllowedForUnlocalizedRoute,
864
+ J as isLocaleDefault,
865
+ S as isLocalizationDisabledForPage,
866
+ q as isPageRedirectOnly,
856
867
  R as normalizePath,
857
868
  N as normalizeRouteKey,
858
- y as removeLeadingSlash,
859
- q as shouldAddLocalePrefix
869
+ g as removeLeadingSlash,
870
+ H as shouldAddLocalePrefix
860
871
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/route-strategy",
3
- "version": "1.1.11",
3
+ "version": "1.1.12",
4
4
  "description": "Locale-aware route generator for Nuxt i18n micro",
5
5
  "keywords": [
6
6
  "i18n",
@@ -63,17 +63,14 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@nuxt/schema": "^3.18.1 || ^4.0.0",
66
- "@i18n-micro/core": "1.3.4",
67
- "@i18n-micro/types": "1.2.6"
66
+ "@i18n-micro/core": "1.3.8",
67
+ "@i18n-micro/types": "1.2.7"
68
68
  },
69
69
  "devDependencies": {
70
- "@types/jest": "^29.5.14",
71
- "jest": "^29.7.0",
72
70
  "publint": "^0.3.17",
73
- "ts-jest": "^29.4.6",
74
- "vite": "^7.3.1",
71
+ "vite": "^7.3.6",
75
72
  "vite-plugin-dts": "^4.5.4",
76
- "vitest": "^3.2.4"
73
+ "vitest": "^4.1.10"
77
74
  },
78
75
  "engines": {
79
76
  "node": ">=18"
@@ -81,7 +78,7 @@
81
78
  "scripts": {
82
79
  "build": "vite build",
83
80
  "check:package": "publint",
84
- "test": "jest",
81
+ "test": "vitest run",
85
82
  "test:dist": "vitest run --config vitest.dist.config.ts"
86
83
  }
87
84
  }