@i18n-micro/route-strategy 1.1.4 → 1.1.6

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