@i18n-micro/vitepress 1.1.0 → 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/adapter-CAJNI6Sw.js +127 -0
- package/dist/adapter-CAJNI6Sw.js.map +1 -0
- package/dist/adapter-eYZZOC9d.cjs +2 -0
- package/dist/adapter-eYZZOC9d.cjs.map +1 -0
- package/dist/config.cjs +13 -19
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs +329 -336
- package/dist/config.mjs.map +1 -1
- package/dist/create-C_dXg23X.js +81 -0
- package/dist/create-C_dXg23X.js.map +1 -0
- package/dist/create-Cwu2djcO.cjs +2 -0
- package/dist/create-Cwu2djcO.cjs.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +20 -31
- package/dist/index.mjs.map +1 -1
- package/dist/node.cjs +2 -2
- package/dist/node.cjs.map +1 -1
- package/dist/node.mjs +22 -25
- package/dist/node.mjs.map +1 -1
- package/dist/theme.cjs +2 -2
- package/dist/theme.cjs.map +1 -1
- package/dist/theme.mjs +35 -34
- package/dist/theme.mjs.map +1 -1
- package/dist/vitepress-locales-CwOlvAa0.cjs +2 -0
- package/dist/vitepress-locales-CwOlvAa0.cjs.map +1 -0
- package/dist/vitepress-locales-DOhKs3q5.js +27 -0
- package/dist/vitepress-locales-DOhKs3q5.js.map +1 -0
- package/package.json +14 -14
- package/dist/adapter-BJ-0ltIc.cjs +0 -2
- package/dist/adapter-BJ-0ltIc.cjs.map +0 -1
- package/dist/adapter-BnsyIKhp.js +0 -128
- package/dist/adapter-BnsyIKhp.js.map +0 -1
- package/dist/create-BgMbe0w1.cjs +0 -2
- package/dist/create-BgMbe0w1.cjs.map +0 -1
- package/dist/create-Dev8Q66O.js +0 -80
- package/dist/create-Dev8Q66O.js.map +0 -1
- package/dist/vitepress-locales-6msv22Sn.js +0 -27
- package/dist/vitepress-locales-6msv22Sn.js.map +0 -1
- package/dist/vitepress-locales-Cz4AutfI.cjs +0 -2
- package/dist/vitepress-locales-Cz4AutfI.cjs.map +0 -1
package/dist/theme.mjs
CHANGED
|
@@ -1,35 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
1
|
+
import { n as e } from "./adapter-CAJNI6Sw.js";
|
|
2
|
+
import { t } from "./create-C_dXg23X.js";
|
|
3
|
+
import { config as n } from "virtual:i18n-micro/config";
|
|
4
|
+
import { messages as r, routeMessages as i } from "virtual:i18n-micro/messages";
|
|
5
|
+
//#region src/runtime/define-theme.ts
|
|
6
|
+
function a(a, o = {}) {
|
|
7
|
+
let s = o.enhanceApp, c = a.enhanceApp, l = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
return {
|
|
9
|
+
...a,
|
|
10
|
+
async enhanceApp(a) {
|
|
11
|
+
let u = l.get(a.app);
|
|
12
|
+
if (!u) {
|
|
13
|
+
let s = o.config ?? n, c = o.messages ?? r, d = o.routeMessages ?? i, f = s.localeCodes.length ? s.localeCodes : s.locales.map((e) => e.code), p = o.localeKeyToCode ?? s.localeKeyToCode, m = e(a.router.route.path, f, s.defaultLocale, p, s.base);
|
|
14
|
+
u = t({
|
|
15
|
+
locale: m,
|
|
16
|
+
defaultLocale: s.defaultLocale,
|
|
17
|
+
fallbackLocale: s.fallbackLocale,
|
|
18
|
+
locales: s.locales,
|
|
19
|
+
messages: c,
|
|
20
|
+
routeMessages: d,
|
|
21
|
+
missingWarn: s.missingWarn ?? void 0,
|
|
22
|
+
syncWithVitePress: s.syncWithVitePress,
|
|
23
|
+
localeKeyToCode: p,
|
|
24
|
+
base: s.base,
|
|
25
|
+
plural: o.plural,
|
|
26
|
+
missingHandler: o.missingHandler
|
|
27
|
+
}), l.set(a.app, u);
|
|
28
|
+
}
|
|
29
|
+
u.enhanceApp(a), c && await c(a), s && await s(a), u.enhanceApp(a);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
31
32
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
//# sourceMappingURL=theme.mjs.map
|
|
33
|
+
//#endregion
|
|
34
|
+
export { a as defineI18nTheme };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=theme.mjs.map
|
package/dist/theme.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.mjs","sources":["../src/runtime/define-theme.ts"],"sourcesContent":["import type { PluralFunc, Translations } from '@i18n-micro/types'\nimport type { Theme } from 'vitepress'\nimport { config as virtualConfig } from 'virtual:i18n-micro/config'\nimport { messages as virtualMessages, routeMessages as virtualRouteMessages } from 'virtual:i18n-micro/messages'\nimport { createI18n, type CreateI18nResult } from './create'\nimport { getLocaleFromPath } from '../router/adapter'\nimport type { VirtualI18nConfig } from '../plugin/with-i18n'\n\ntype EnhanceAppContext = Parameters<NonNullable<Theme['enhanceApp']>>[0]\n\nexport interface DefineI18nThemeOptions {\n /**\n * Extra `enhanceApp` run after i18n is installed.\n */\n enhanceApp?: NonNullable<Theme['enhanceApp']>\n /**\n * Overrides not serializable into `virtual:i18n-micro/config`.\n */\n plural?: PluralFunc\n missingHandler?: (locale: string, key: string, routeName: string) => void\n localeKeyToCode?: Record<string, string>\n /**\n * Optional overrides (tests / advanced). Defaults come from `virtual:i18n-micro/*`\n * registered by `withI18n`.\n */\n config?: VirtualI18nConfig\n messages?: Record<string, Translations>\n routeMessages?: Record<string, Record<string, Translations>>\n}\n\n/**\n * Zero-boilerplate theme wiring. Requires `withI18n(...)` in `.vitepress/config`\n * so virtual config + messages modules exist.\n *\n * Uses **static** `virtual:i18n-micro/*` imports so VitePress SSG can rewrite them.\n * Import this helper from `@i18n-micro/vitepress/theme` (not the root entry) so Node\n * config evaluation never loads virtual modules.\n *\n * @example\n * ```ts\n * import DefaultTheme from 'vitepress/theme'\n * import { defineI18nTheme } from '@i18n-micro/vitepress/theme'\n *\n * export default defineI18nTheme(DefaultTheme)\n * ```\n */\nexport function defineI18nTheme<T extends Theme>(base: T, options: DefineI18nThemeOptions = {}): T {\n const userEnhance = options.enhanceApp\n const baseEnhance = base.enhanceApp\n\n // Per app instance (SSR-safe: WeakMap by app).\n const byApp = new WeakMap<object, CreateI18nResult>()\n\n return {\n ...base,\n async enhanceApp(ctx: EnhanceAppContext) {\n let installed = byApp.get(ctx.app)\n if (!installed) {\n // Cast via `unknown`: root typecheck also sees Astro's ambient `virtual:i18n-micro/config`.\n const config = (options.config ?? virtualConfig) as unknown as VirtualI18nConfig\n const messages = options.messages ?? (virtualMessages as Record<string, Translations>)\n const routeMessages = options.routeMessages ?? (virtualRouteMessages as Record<string, Record<string, Translations>>)\n\n const localeCodes = config.localeCodes.length ? config.localeCodes : config.locales.map((l) => l.code)\n const localeKeyToCode = options.localeKeyToCode ?? config.localeKeyToCode\n const initialLocale = getLocaleFromPath(ctx.router.route.path, localeCodes, config.defaultLocale, localeKeyToCode, config.base)\n\n installed = createI18n({\n locale: initialLocale,\n defaultLocale: config.defaultLocale,\n fallbackLocale: config.fallbackLocale,\n locales: config.locales,\n messages,\n routeMessages,\n missingWarn: config.missingWarn ?? undefined,\n syncWithVitePress: config.syncWithVitePress,\n localeKeyToCode,\n base: config.base,\n plural: options.plural,\n missingHandler: options.missingHandler,\n })\n byApp.set(ctx.app, installed)\n }\n\n // Install plugin first so base/user enhanceApp can use $t / components.\n installed.enhanceApp(ctx as unknown as Parameters<typeof installed.enhanceApp>[0])\n if (baseEnhance) await baseEnhance(ctx)\n if (userEnhance) await userEnhance(ctx)\n // Re-run so route sync wraps any onAfterRouteChange set by base/user.\n installed.enhanceApp(ctx as unknown as Parameters<typeof installed.enhanceApp>[0])\n },\n }\n}\n"],"
|
|
1
|
+
{"version":3,"file":"theme.mjs","names":[],"sources":["../src/runtime/define-theme.ts"],"sourcesContent":["import type { PluralFunc, Translations } from '@i18n-micro/types'\nimport type { Theme } from 'vitepress'\nimport { config as virtualConfig } from 'virtual:i18n-micro/config'\nimport { messages as virtualMessages, routeMessages as virtualRouteMessages } from 'virtual:i18n-micro/messages'\nimport { createI18n, type CreateI18nResult } from './create'\nimport { getLocaleFromPath } from '../router/adapter'\nimport type { VirtualI18nConfig } from '../plugin/with-i18n'\n\ntype EnhanceAppContext = Parameters<NonNullable<Theme['enhanceApp']>>[0]\n\nexport interface DefineI18nThemeOptions {\n /**\n * Extra `enhanceApp` run after i18n is installed.\n */\n enhanceApp?: NonNullable<Theme['enhanceApp']>\n /**\n * Overrides not serializable into `virtual:i18n-micro/config`.\n */\n plural?: PluralFunc\n missingHandler?: (locale: string, key: string, routeName: string) => void\n localeKeyToCode?: Record<string, string>\n /**\n * Optional overrides (tests / advanced). Defaults come from `virtual:i18n-micro/*`\n * registered by `withI18n`.\n */\n config?: VirtualI18nConfig\n messages?: Record<string, Translations>\n routeMessages?: Record<string, Record<string, Translations>>\n}\n\n/**\n * Zero-boilerplate theme wiring. Requires `withI18n(...)` in `.vitepress/config`\n * so virtual config + messages modules exist.\n *\n * Uses **static** `virtual:i18n-micro/*` imports so VitePress SSG can rewrite them.\n * Import this helper from `@i18n-micro/vitepress/theme` (not the root entry) so Node\n * config evaluation never loads virtual modules.\n *\n * @example\n * ```ts\n * import DefaultTheme from 'vitepress/theme'\n * import { defineI18nTheme } from '@i18n-micro/vitepress/theme'\n *\n * export default defineI18nTheme(DefaultTheme)\n * ```\n */\nexport function defineI18nTheme<T extends Theme>(base: T, options: DefineI18nThemeOptions = {}): T {\n const userEnhance = options.enhanceApp\n const baseEnhance = base.enhanceApp\n\n // Per app instance (SSR-safe: WeakMap by app).\n const byApp = new WeakMap<object, CreateI18nResult>()\n\n return {\n ...base,\n async enhanceApp(ctx: EnhanceAppContext) {\n let installed = byApp.get(ctx.app)\n if (!installed) {\n // Cast via `unknown`: root typecheck also sees Astro's ambient `virtual:i18n-micro/config`.\n const config = (options.config ?? virtualConfig) as unknown as VirtualI18nConfig\n const messages = options.messages ?? (virtualMessages as Record<string, Translations>)\n const routeMessages = options.routeMessages ?? (virtualRouteMessages as Record<string, Record<string, Translations>>)\n\n const localeCodes = config.localeCodes.length ? config.localeCodes : config.locales.map((l) => l.code)\n const localeKeyToCode = options.localeKeyToCode ?? config.localeKeyToCode\n const initialLocale = getLocaleFromPath(ctx.router.route.path, localeCodes, config.defaultLocale, localeKeyToCode, config.base)\n\n installed = createI18n({\n locale: initialLocale,\n defaultLocale: config.defaultLocale,\n fallbackLocale: config.fallbackLocale,\n locales: config.locales,\n messages,\n routeMessages,\n missingWarn: config.missingWarn ?? undefined,\n syncWithVitePress: config.syncWithVitePress,\n localeKeyToCode,\n base: config.base,\n plural: options.plural,\n missingHandler: options.missingHandler,\n })\n byApp.set(ctx.app, installed)\n }\n\n // Install plugin first so base/user enhanceApp can use $t / components.\n installed.enhanceApp(ctx as unknown as Parameters<typeof installed.enhanceApp>[0])\n if (baseEnhance) await baseEnhance(ctx)\n if (userEnhance) await userEnhance(ctx)\n // Re-run so route sync wraps any onAfterRouteChange set by base/user.\n installed.enhanceApp(ctx as unknown as Parameters<typeof installed.enhanceApp>[0])\n },\n }\n}\n"],"mappings":";;;;;AA8CA,SAAgB,EAAiC,GAAS,IAAkC,CAAC,GAAM;CACjG,IAAM,IAAc,EAAQ,YACtB,IAAc,EAAK,YAGnB,oBAAQ,IAAI,QAAkC;CAEpD,OAAO;EACL,GAAG;EACH,MAAM,WAAW,GAAwB;GACvC,IAAI,IAAY,EAAM,IAAI,EAAI,GAAG;GACjC,IAAI,CAAC,GAAW;IAEd,IAAM,IAAU,EAAQ,UAAU,GAC5B,IAAW,EAAQ,YAAa,GAChC,IAAgB,EAAQ,iBAAkB,GAE1C,IAAc,EAAO,YAAY,SAAS,EAAO,cAAc,EAAO,QAAQ,KAAK,MAAM,EAAE,IAAI,GAC/F,IAAkB,EAAQ,mBAAmB,EAAO,iBACpD,IAAgB,EAAkB,EAAI,OAAO,MAAM,MAAM,GAAa,EAAO,eAAe,GAAiB,EAAO,IAAI;IAgB9H,AAdA,IAAY,EAAW;KACrB,QAAQ;KACR,eAAe,EAAO;KACtB,gBAAgB,EAAO;KACvB,SAAS,EAAO;KAChB,UAAA;KACA,eAAA;KACA,aAAa,EAAO,eAAe,KAAA;KACnC,mBAAmB,EAAO;KAC1B;KACA,MAAM,EAAO;KACb,QAAQ,EAAQ;KAChB,gBAAgB,EAAQ;IAC1B,CAAC,GACD,EAAM,IAAI,EAAI,KAAK,CAAS;GAC9B;GAOA,AAJA,EAAU,WAAW,CAA4D,GAC7E,KAAa,MAAM,EAAY,CAAG,GAClC,KAAa,MAAM,EAAY,CAAG,GAEtC,EAAU,WAAW,CAA4D;EACnF;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function e(e,t,n){for(let[t,r]of Object.entries(n))if(r===e)return t;return e===t?`root`:e}function t(t,n,r={}){let i=r.localeKeyToCode??{},a={};for(let r of t){let t=e(r.code,n,i),o=t===`root`?r.code:t,s={label:r.displayName||r.code.toUpperCase(),lang:r.iso||r.code};t!==`root`&&(s.link=`/${o}/`),a[t]=s}if(!a.root){let e=t.find(e=>e.code===n)??t[0];e&&(a.root={label:e.displayName||e.code.toUpperCase(),lang:e.iso||e.code})}return a}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
|
|
2
|
+
//# sourceMappingURL=vitepress-locales-CwOlvAa0.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitepress-locales-CwOlvAa0.cjs","names":[],"sources":["../src/plugin/vitepress-locales.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\n\n/**\n * Minimal VitePress `locales` entry used by the default theme language menu.\n */\nexport interface VitePressLocaleEntry {\n label: string\n lang: string\n link?: string\n}\n\nexport interface BuildVitePressLocalesOptions {\n /**\n * Map VitePress locale keys → i18n codes (`root` → default).\n * When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL\n * prefix / config key uses the VP key.\n */\n localeKeyToCode?: Record<string, string>\n}\n\nfunction localeKeyFromCode(code: string, defaultLocale: string, localeKeyToCode: Record<string, string>): string {\n for (const [key, mapped] of Object.entries(localeKeyToCode)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n}\n\n/**\n * Build VitePress `config.locales` from i18n-micro `Locale[]`.\n * Default locale becomes `root` (no URL prefix); others get `/{key}/`.\n */\nexport function buildVitePressLocales(\n locales: Locale[],\n defaultLocale: string,\n options: BuildVitePressLocalesOptions = {},\n): Record<string, VitePressLocaleEntry> {\n const localeKeyToCode = options.localeKeyToCode ?? {}\n const result: Record<string, VitePressLocaleEntry> = {}\n\n for (const loc of locales) {\n const key = localeKeyFromCode(loc.code, defaultLocale, localeKeyToCode)\n const urlKey = key === 'root' ? loc.code : key\n const entry: VitePressLocaleEntry = {\n label: loc.displayName || loc.code.toUpperCase(),\n lang: loc.iso || loc.code,\n }\n if (key !== 'root') {\n entry.link = `/${urlKey}/`\n }\n result[key] = entry\n }\n\n if (!result.root) {\n const fallback = locales.find((l) => l.code === defaultLocale) ?? locales[0]\n if (fallback) {\n result.root = {\n label: fallback.displayName || fallback.code.toUpperCase(),\n lang: fallback.iso || fallback.code,\n }\n }\n }\n\n return result\n}\n"],"mappings":"AAoBA,SAAS,EAAkB,EAAc,EAAuB,EAAiD,CAC/G,IAAK,GAAM,CAAC,EAAK,KAAW,OAAO,QAAQ,CAAe,EACxD,GAAI,IAAW,EAAM,OAAO,EAG9B,OADI,IAAS,EAAsB,OAC5B,CACT,CAMA,SAAgB,EACd,EACA,EACA,EAAwC,CAAC,EACH,CACtC,IAAM,EAAkB,EAAQ,iBAAmB,CAAC,EAC9C,EAA+C,CAAC,EAEtD,IAAK,IAAM,KAAO,EAAS,CACzB,IAAM,EAAM,EAAkB,EAAI,KAAM,EAAe,CAAe,EAChE,EAAS,IAAQ,OAAS,EAAI,KAAO,EACrC,EAA8B,CAClC,MAAO,EAAI,aAAe,EAAI,KAAK,YAAY,EAC/C,KAAM,EAAI,KAAO,EAAI,IACvB,EACI,IAAQ,SACV,EAAM,KAAO,IAAI,EAAO,IAE1B,EAAO,GAAO,CAChB,CAEA,GAAI,CAAC,EAAO,KAAM,CAChB,IAAM,EAAW,EAAQ,KAAM,GAAM,EAAE,OAAS,CAAa,GAAK,EAAQ,GACtE,IACF,EAAO,KAAO,CACZ,MAAO,EAAS,aAAe,EAAS,KAAK,YAAY,EACzD,KAAM,EAAS,KAAO,EAAS,IACjC,EAEJ,CAEA,OAAO,CACT"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/plugin/vitepress-locales.ts
|
|
2
|
+
function e(e, t, n) {
|
|
3
|
+
for (let [t, r] of Object.entries(n)) if (r === e) return t;
|
|
4
|
+
return e === t ? "root" : e;
|
|
5
|
+
}
|
|
6
|
+
function t(t, n, r = {}) {
|
|
7
|
+
let i = r.localeKeyToCode ?? {}, a = {};
|
|
8
|
+
for (let r of t) {
|
|
9
|
+
let t = e(r.code, n, i), o = t === "root" ? r.code : t, s = {
|
|
10
|
+
label: r.displayName || r.code.toUpperCase(),
|
|
11
|
+
lang: r.iso || r.code
|
|
12
|
+
};
|
|
13
|
+
t !== "root" && (s.link = `/${o}/`), a[t] = s;
|
|
14
|
+
}
|
|
15
|
+
if (!a.root) {
|
|
16
|
+
let e = t.find((e) => e.code === n) ?? t[0];
|
|
17
|
+
e && (a.root = {
|
|
18
|
+
label: e.displayName || e.code.toUpperCase(),
|
|
19
|
+
lang: e.iso || e.code
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { t };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=vitepress-locales-DOhKs3q5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitepress-locales-DOhKs3q5.js","names":[],"sources":["../src/plugin/vitepress-locales.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\n\n/**\n * Minimal VitePress `locales` entry used by the default theme language menu.\n */\nexport interface VitePressLocaleEntry {\n label: string\n lang: string\n link?: string\n}\n\nexport interface BuildVitePressLocalesOptions {\n /**\n * Map VitePress locale keys → i18n codes (`root` → default).\n * When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL\n * prefix / config key uses the VP key.\n */\n localeKeyToCode?: Record<string, string>\n}\n\nfunction localeKeyFromCode(code: string, defaultLocale: string, localeKeyToCode: Record<string, string>): string {\n for (const [key, mapped] of Object.entries(localeKeyToCode)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n}\n\n/**\n * Build VitePress `config.locales` from i18n-micro `Locale[]`.\n * Default locale becomes `root` (no URL prefix); others get `/{key}/`.\n */\nexport function buildVitePressLocales(\n locales: Locale[],\n defaultLocale: string,\n options: BuildVitePressLocalesOptions = {},\n): Record<string, VitePressLocaleEntry> {\n const localeKeyToCode = options.localeKeyToCode ?? {}\n const result: Record<string, VitePressLocaleEntry> = {}\n\n for (const loc of locales) {\n const key = localeKeyFromCode(loc.code, defaultLocale, localeKeyToCode)\n const urlKey = key === 'root' ? loc.code : key\n const entry: VitePressLocaleEntry = {\n label: loc.displayName || loc.code.toUpperCase(),\n lang: loc.iso || loc.code,\n }\n if (key !== 'root') {\n entry.link = `/${urlKey}/`\n }\n result[key] = entry\n }\n\n if (!result.root) {\n const fallback = locales.find((l) => l.code === defaultLocale) ?? locales[0]\n if (fallback) {\n result.root = {\n label: fallback.displayName || fallback.code.toUpperCase(),\n lang: fallback.iso || fallback.code,\n }\n }\n }\n\n return result\n}\n"],"mappings":";AAoBA,SAAS,EAAkB,GAAc,GAAuB,GAAiD;CAC/G,KAAK,IAAM,CAAC,GAAK,MAAW,OAAO,QAAQ,CAAe,GACxD,IAAI,MAAW,GAAM,OAAO;CAG9B,OADI,MAAS,IAAsB,SAC5B;AACT;AAMA,SAAgB,EACd,GACA,GACA,IAAwC,CAAC,GACH;CACtC,IAAM,IAAkB,EAAQ,mBAAmB,CAAC,GAC9C,IAA+C,CAAC;CAEtD,KAAK,IAAM,KAAO,GAAS;EACzB,IAAM,IAAM,EAAkB,EAAI,MAAM,GAAe,CAAe,GAChE,IAAS,MAAQ,SAAS,EAAI,OAAO,GACrC,IAA8B;GAClC,OAAO,EAAI,eAAe,EAAI,KAAK,YAAY;GAC/C,MAAM,EAAI,OAAO,EAAI;EACvB;EAIA,AAHI,MAAQ,WACV,EAAM,OAAO,IAAI,EAAO,KAE1B,EAAO,KAAO;CAChB;CAEA,IAAI,CAAC,EAAO,MAAM;EAChB,IAAM,IAAW,EAAQ,MAAM,MAAM,EAAE,SAAS,CAAa,KAAK,EAAQ;EAC1E,AAAI,MACF,EAAO,OAAO;GACZ,OAAO,EAAS,eAAe,EAAS,KAAK,YAAY;GACzD,MAAM,EAAS,OAAO,EAAS;EACjC;CAEJ;CAEA,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/vitepress",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.6",
|
|
4
4
|
"description": "VitePress bindings for i18n-micro — runtime dictionaries, MD components, and locale switcher.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"documentation",
|
|
@@ -84,25 +84,25 @@
|
|
|
84
84
|
"access": "public"
|
|
85
85
|
},
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@i18n-micro/
|
|
88
|
-
"@i18n-micro/
|
|
89
|
-
"@i18n-micro/
|
|
90
|
-
"@i18n-micro/
|
|
91
|
-
"@i18n-micro/
|
|
87
|
+
"@i18n-micro/core": "^1.3.16",
|
|
88
|
+
"@i18n-micro/utils": "^1.0.21",
|
|
89
|
+
"@i18n-micro/types": "^1.2.13",
|
|
90
|
+
"@i18n-micro/vue": "^1.4.4",
|
|
91
|
+
"@i18n-micro/node": "^1.2.14"
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
94
|
"@types/node": "^20.19.26",
|
|
95
|
-
"publint": "^0.3.
|
|
96
|
-
"typescript": "^
|
|
97
|
-
"vite": "^
|
|
98
|
-
"vite-plugin-dts": "^
|
|
99
|
-
"vitepress": "^2.0.0-alpha.
|
|
100
|
-
"vitest": "^4.1.
|
|
101
|
-
"vue": "^3.5.
|
|
95
|
+
"publint": "^0.3.24",
|
|
96
|
+
"typescript": "^6.0.3",
|
|
97
|
+
"vite": "^8.2.2",
|
|
98
|
+
"vite-plugin-dts": "^5.1.0",
|
|
99
|
+
"vitepress": "^2.0.0-alpha.20",
|
|
100
|
+
"vitest": "^4.1.11",
|
|
101
|
+
"vue": "^3.5.42"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"vitepress": ">=1.0.0 || >=2.0.0-alpha.0",
|
|
105
|
-
"vue": "^3.5.
|
|
105
|
+
"vue": "^3.5.42"
|
|
106
106
|
},
|
|
107
107
|
"engines": {
|
|
108
108
|
"node": ">=18"
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const j=require("vue");function g(i){const o=i.indexOf("#"),e=i.indexOf("?");let n=i.length;return o>=0&&(n=Math.min(n,o)),e>=0&&(n=Math.min(n,e)),{pathname:i.slice(0,n)||"/",extras:i.slice(n)}}function p(i,o){if(!o||o==="/")return i;const e=o.endsWith("/")?o.slice(0,-1):o;if(!e)return i;const{pathname:n,extras:c}=g(i);return n===e?`/${c}`:n.startsWith(`${e}/`)?`${n.slice(e.length)||"/"}${c}`:i}function x(i,o,e={}){const n=s=>{for(const[a,f]of Object.entries(e))if(f===s)return a;return s===o?"root":s},c=new Map;for(const s of i){if(s===o)continue;const a=n(s),f=a==="root"?s:a;c.set(f,s),f!==s&&c.set(s,s)}return c}function K(i,o,e,n={},c){const{pathname:s}=g(p(i,c)),a=s.split("/").filter(Boolean)[0];return a===void 0?e:x(o,e,n).get(a)??e}function L(i,o,e,n={},c){const{pathname:s}=g(p(i,c)),a=s.split("/").filter(Boolean),f=a[0];return f!==void 0&&(e!==void 0?x(o,e,n).has(f)&&a.shift():o.includes(f)&&a.shift()),a.length===0?"index":a.join("-").replace(/\.html$/,"")}function V(i){return j.defineComponent({name:"VitePressI18nLink",props:{to:{type:String,required:!0},style:{type:Object,default:void 0}},setup(o,{slots:e}){return()=>j.h("a",{href:o.to,style:o.style,onClick:n=>{n.defaultPrevented||n.button===0&&(n.metaKey||n.altKey||n.ctrlKey||n.shiftKey||(n.preventDefault(),i?i(o.to):typeof window<"u"&&window.location.assign(o.to)))}},e.default?.())}})}function z(i){const{locales:o,defaultLocale:e,localeKeyToCode:n={},base:c,getPath:s,go:a}=i,f=o.map(t=>t.code),l={...n},C=x(f,e,l),S=[...C.keys()],d=c&&c!=="/"?c:void 0,B=t=>l[t]?l[t]:t==="root"?e:t,v=t=>{for(const[r,u]of Object.entries(l))if(u===t)return r;return t===e?"root":t},O=t=>{if(t===e)return null;const r=v(t);return r==="root"?t:r},T=t=>{const r=t==="/"||t.endsWith("/"),u=t.split("/").filter(Boolean),h=u[0];return h!==void 0&&C.has(h)&&u.shift(),{segments:u,hadTrailingSlash:r}},R=t=>{const{pathname:r,extras:u}=g(p(t,d)),{segments:h,hadTrailingSlash:m}=T(r);let w=h.length===0?"/":`/${h.join("/")}`;return w!=="/"&&m&&(w+="/"),`${w}${u}`},y=(t,r)=>{const{pathname:u,extras:h}=g(p(t,d)),{segments:m,hadTrailingSlash:w}=T(u),k=O(r);k&&m.unshift(k);let P=m.length===0?"/":`/${m.join("/")}`;return P!=="/"&&w&&(P+="/"),`${P}${h}`},b=(t,r)=>y(t,r),q=(t,r)=>{const u=typeof t=="string"?t:t.path||"/";return y(u,r)},F=(t,r=!1)=>{if(a){a(t,{replace:r});return}typeof window<"u"&&(r?window.location.replace(t):window.location.assign(t))},$=()=>s?s():typeof window<"u"?window.location.pathname+window.location.search+window.location.hash:"/";return{localeCodes:f,defaultLocale:e,localeKeyToCode:l,urlPrefixes:S,base:d,codeFromLocaleKey:B,localeKeyFromCode:v,getLocaleFromPath:t=>K(t,f,e,l,d),switchLocalePath:b,localizePath:y,removeLocaleFromPath:R,routeNameFromPath:t=>L(t,f,e,l,d),linkComponent:V(a),getCurrentPath:()=>p($(),d),push:t=>{F(t.path,!1)},replace:t=>{F(t.path,!0)},resolvePath:q,getRoute:()=>{const t=p($(),d),r=typeof window<"u"?new URL(t,window.location.origin):new URL(t,"http://localhost");return{fullPath:r.pathname+r.search+r.hash,query:Object.fromEntries(r.searchParams)}}}}exports.createVitePressRouterAdapter=z;exports.getLocaleFromPath=K;exports.routeNameFromPath=L;exports.stripSiteBase=p;
|
|
2
|
-
//# sourceMappingURL=adapter-BJ-0ltIc.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-BJ-0ltIc.cjs","sources":["../src/router/adapter.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\nimport type { I18nRoutingStrategy } from '@i18n-micro/vue'\nimport { defineComponent, h, type Component, type PropType } from 'vue'\n\nexport interface VitePressRouterLike {\n route: {\n path: string\n hash?: string\n query?: string\n }\n go: (to: string, options?: { initialLoad?: boolean; replace?: boolean }) => void | Promise<void>\n onAfterRouteChange?: (to: string) => unknown\n}\n\nexport type VitePressGo = (href: string, options?: { replace?: boolean }) => void | Promise<void>\n\nexport interface VitePressRouterAdapterOptions {\n locales: Locale[]\n defaultLocale: string\n /**\n * Map VitePress locale keys (`root`, `fr`) to i18n locale codes.\n * Defaults: `root` → `defaultLocale`, other keys → same string as the key.\n * URL prefixes always use VitePress keys; i18n uses codes.\n */\n localeKeyToCode?: Record<string, string>\n /**\n * VitePress `site.base` (e.g. `/openapi_docs/`). Stripped from paths before\n * locale / route-name detection. Returned localize paths are base-relative\n * (VitePress / `withBase` re-applies the base).\n */\n base?: string\n getPath?: () => string\n go?: VitePressGo\n}\n\nexport interface VitePressRouterAdapter extends I18nRoutingStrategy {\n getLocaleFromPath: (path: string) => string\n switchLocalePath: (path: string, newLocale: string) => string\n localizePath: (path: string, locale: string) => string\n removeLocaleFromPath: (path: string) => string\n /** Page dictionary route name (`/fr/guide/demo` → `guide-demo`). */\n routeNameFromPath: (path: string) => string\n /** Resolve VitePress locale key (`root` / `fr`) to i18n code. */\n codeFromLocaleKey: (localeKey: string) => string\n /** Resolve i18n code to VitePress locale key. */\n localeKeyFromCode: (code: string) => string\n localeCodes: string[]\n defaultLocale: string\n /** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */\n localeKeyToCode: Record<string, string>\n /** URL path prefixes (VitePress locale keys except `root`). */\n urlPrefixes: string[]\n /** VitePress `site.base` used when constructing this adapter (may be undefined). */\n base?: string\n}\n\n/** Path helpers exposed on `createI18n` instances (slice of the router adapter). */\nexport type PathMethods = Pick<\n VitePressRouterAdapter,\n 'localizePath' | 'switchLocalePath' | 'getLocaleFromPath' | 'removeLocaleFromPath' | 'routeNameFromPath'\n>\n\nfunction splitPathAndExtras(path: string): { pathname: string; extras: string } {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n let cut = path.length\n if (hashIndex >= 0) cut = Math.min(cut, hashIndex)\n if (queryIndex >= 0) cut = Math.min(cut, queryIndex)\n return {\n pathname: path.slice(0, cut) || '/',\n extras: path.slice(cut),\n }\n}\n\n/**\n * Strip VitePress `site.base` from a path. Leaves query/hash intact.\n * No-op when `base` is missing or `/`.\n */\nexport function stripSiteBase(path: string, base?: string): string {\n if (!base || base === '/') return path\n const normalized = base.endsWith('/') ? base.slice(0, -1) : base\n if (!normalized) return path\n const { pathname, extras } = splitPathAndExtras(path)\n if (pathname === normalized) return `/${extras}`\n if (pathname.startsWith(`${normalized}/`)) {\n return `${pathname.slice(normalized.length) || '/'}${extras}`\n }\n return path\n}\n\n/**\n * Build URL prefix → i18n code map.\n * Prefixes are VitePress locale keys (and codes when they differ), never `root`.\n */\nexport function buildUrlPrefixToCode(\n localeCodes: string[],\n defaultLocale: string,\n localeKeyToCode: Record<string, string> = {},\n): Map<string, string> {\n const keyFromCode = (code: string): string => {\n for (const [key, mapped] of Object.entries(localeKeyToCode)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n }\n\n const prefixToCode = new Map<string, string>()\n for (const code of localeCodes) {\n if (code === defaultLocale) continue\n const key = keyFromCode(code)\n const urlKey = key === 'root' ? code : key\n prefixToCode.set(urlKey, code)\n if (urlKey !== code) prefixToCode.set(code, code)\n }\n return prefixToCode\n}\n\n/**\n * Detect i18n locale code from a URL path (prefix_except_default).\n * Path prefixes are VitePress locale keys; return value is the i18n code.\n * Pass `base` when the path may include VitePress `site.base` (SSG).\n */\nexport function getLocaleFromPath(\n path: string,\n localeCodes: string[],\n defaultLocale: string,\n localeKeyToCode: Record<string, string> = {},\n base?: string,\n): string {\n const { pathname } = splitPathAndExtras(stripSiteBase(path, base))\n const first = pathname.split('/').filter(Boolean)[0]\n if (first === undefined) return defaultLocale\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCode)\n return prefixToCode.get(first) ?? defaultLocale\n}\n\n/**\n * Route name for page-scoped dictionaries (`/guide/demo` → `guide-demo`).\n * Strips VitePress URL prefixes (keys), not only raw i18n codes.\n *\n * When `defaultLocale` is omitted (legacy 2-arg call), any segment that matches a\n * listed locale code is stripped — callers must not rely on `localeCodes[0]` as default.\n */\nexport function routeNameFromPath(\n path: string,\n localeCodes: string[],\n defaultLocale?: string,\n localeKeyToCode: Record<string, string> = {},\n base?: string,\n): string {\n const { pathname } = splitPathAndExtras(stripSiteBase(path, base))\n const segments = pathname.split('/').filter(Boolean)\n const first = segments[0]\n if (first !== undefined) {\n if (defaultLocale !== undefined) {\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCode)\n if (prefixToCode.has(first)) segments.shift()\n } else if (localeCodes.includes(first)) {\n segments.shift()\n }\n }\n if (segments.length === 0) return 'index'\n return segments.join('-').replace(/\\.html$/, '')\n}\n\nfunction createVitePressLinkComponent(go?: VitePressGo): Component {\n return defineComponent({\n name: 'VitePressI18nLink',\n props: {\n to: { type: String, required: true },\n style: { type: Object as PropType<Record<string, string>>, default: undefined },\n },\n setup(props, { slots }) {\n return () =>\n h(\n 'a',\n {\n href: props.to,\n style: props.style,\n onClick: (e: MouseEvent) => {\n if (e.defaultPrevented) return\n if (e.button !== 0) return\n if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return\n e.preventDefault()\n if (go) {\n void go(props.to)\n } else if (typeof window !== 'undefined') {\n window.location.assign(props.to)\n }\n },\n },\n slots.default?.(),\n )\n },\n })\n}\n\n/**\n * VitePress path adapter (prefix_except_default semantics):\n * default locale has no URL prefix; other locales use `/{vitepressKey}/…`.\n * i18n locale values remain `locale.code` (via `localeKeyToCode`).\n */\nexport function createVitePressRouterAdapter(options: VitePressRouterAdapterOptions): VitePressRouterAdapter {\n const { locales, defaultLocale, localeKeyToCode = {}, base, getPath, go } = options\n const localeCodes = locales.map((loc) => loc.code)\n const localeKeyToCodeSnapshot = { ...localeKeyToCode }\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCodeSnapshot)\n const urlPrefixes = [...prefixToCode.keys()]\n const siteBase = base && base !== '/' ? base : undefined\n\n const codeFromLocaleKey = (localeKey: string): string => {\n if (localeKeyToCodeSnapshot[localeKey]) return localeKeyToCodeSnapshot[localeKey]!\n if (localeKey === 'root') return defaultLocale\n return localeKey\n }\n\n const localeKeyFromCode = (code: string): string => {\n for (const [key, mapped] of Object.entries(localeKeyToCodeSnapshot)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n }\n\n const urlPrefixForCode = (code: string): string | null => {\n if (code === defaultLocale) return null\n const key = localeKeyFromCode(code)\n return key === 'root' ? code : key\n }\n\n const stripPrefix = (pathname: string): { segments: string[]; hadTrailingSlash: boolean } => {\n const hadTrailingSlash = pathname === '/' || pathname.endsWith('/')\n const segments = pathname.split('/').filter(Boolean)\n const first = segments[0]\n if (first !== undefined && prefixToCode.has(first)) {\n segments.shift()\n }\n return { segments, hadTrailingSlash }\n }\n\n const removeLocaleFromPath = (path: string): string => {\n const { pathname, extras } = splitPathAndExtras(stripSiteBase(path, siteBase))\n const { segments, hadTrailingSlash } = stripPrefix(pathname)\n let clean = segments.length === 0 ? '/' : `/${segments.join('/')}`\n if (clean !== '/' && hadTrailingSlash) clean += '/'\n return `${clean}${extras}`\n }\n\n const localizePath = (path: string, locale: string): string => {\n const { pathname, extras } = splitPathAndExtras(stripSiteBase(path, siteBase))\n const { segments, hadTrailingSlash } = stripPrefix(pathname)\n const prefix = urlPrefixForCode(locale)\n if (prefix) segments.unshift(prefix)\n let localized = segments.length === 0 ? '/' : `/${segments.join('/')}`\n if (localized !== '/' && hadTrailingSlash) localized += '/'\n return `${localized}${extras}`\n }\n\n const switchLocalePath = (path: string, newLocale: string): string => {\n return localizePath(path, newLocale)\n }\n\n const resolvePath = (to: string | { path?: string }, locale: string): string => {\n const path = typeof to === 'string' ? to : to.path || '/'\n return localizePath(path, locale)\n }\n\n const navigate = (href: string, replace = false) => {\n if (go) {\n void go(href, { replace })\n return\n }\n if (typeof window !== 'undefined') {\n if (replace) {\n window.location.replace(href)\n } else {\n window.location.assign(href)\n }\n }\n }\n\n const currentFullPath = (): string => {\n if (getPath) return getPath()\n if (typeof window !== 'undefined') {\n return window.location.pathname + window.location.search + window.location.hash\n }\n return '/'\n }\n\n return {\n localeCodes,\n defaultLocale,\n localeKeyToCode: localeKeyToCodeSnapshot,\n urlPrefixes,\n base: siteBase,\n codeFromLocaleKey,\n localeKeyFromCode,\n getLocaleFromPath: (path: string) => getLocaleFromPath(path, localeCodes, defaultLocale, localeKeyToCodeSnapshot, siteBase),\n switchLocalePath,\n localizePath,\n removeLocaleFromPath,\n routeNameFromPath: (path: string) => routeNameFromPath(path, localeCodes, defaultLocale, localeKeyToCodeSnapshot, siteBase),\n linkComponent: createVitePressLinkComponent(go),\n getCurrentPath: () => stripSiteBase(currentFullPath(), siteBase),\n push: (target: { path: string }) => {\n navigate(target.path, false)\n },\n replace: (target: { path: string }) => {\n navigate(target.path, true)\n },\n resolvePath,\n getRoute: () => {\n const path = stripSiteBase(currentFullPath(), siteBase)\n const url = typeof window !== 'undefined' ? new URL(path, window.location.origin) : new URL(path, 'http://localhost')\n return {\n fullPath: url.pathname + url.search + url.hash,\n query: Object.fromEntries(url.searchParams),\n }\n },\n }\n}\n"],"names":["splitPathAndExtras","path","hashIndex","queryIndex","cut","stripSiteBase","base","normalized","pathname","extras","buildUrlPrefixToCode","localeCodes","defaultLocale","localeKeyToCode","keyFromCode","code","key","mapped","prefixToCode","urlKey","getLocaleFromPath","first","routeNameFromPath","segments","createVitePressLinkComponent","go","defineComponent","props","slots","h","e","createVitePressRouterAdapter","options","locales","getPath","loc","localeKeyToCodeSnapshot","urlPrefixes","siteBase","codeFromLocaleKey","localeKey","localeKeyFromCode","urlPrefixForCode","stripPrefix","hadTrailingSlash","removeLocaleFromPath","clean","localizePath","locale","prefix","localized","switchLocalePath","newLocale","resolvePath","to","navigate","href","replace","currentFullPath","target","url"],"mappings":"oCA8DA,SAASA,EAAmBC,EAAoD,CAC9E,MAAMC,EAAYD,EAAK,QAAQ,GAAG,EAC5BE,EAAaF,EAAK,QAAQ,GAAG,EACnC,IAAIG,EAAMH,EAAK,OACf,OAAIC,GAAa,IAAGE,EAAM,KAAK,IAAIA,EAAKF,CAAS,GAC7CC,GAAc,IAAGC,EAAM,KAAK,IAAIA,EAAKD,CAAU,GAC5C,CACL,SAAUF,EAAK,MAAM,EAAGG,CAAG,GAAK,IAChC,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QAAUA,GAA6B,CACrCJ,EAASI,EAAO,KAAM,EAAI,CAC5B,EACA,YAAAN,EACA,SAAU,IAAM,CACd,MAAMpD,EAAOI,EAAcqD,EAAA,EAAmBpB,CAAQ,EAChDsB,EAAM,OAAO,OAAW,IAAc,IAAI,IAAI3D,EAAM,OAAO,SAAS,MAAM,EAAI,IAAI,IAAIA,EAAM,kBAAkB,EACpH,MAAO,CACL,SAAU2D,EAAI,SAAWA,EAAI,OAASA,EAAI,KAC1C,MAAO,OAAO,YAAYA,EAAI,YAAY,CAAA,CAE9C,CAAA,CAEJ"}
|
package/dist/adapter-BnsyIKhp.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { defineComponent as b, h as R } from "vue";
|
|
2
|
-
function g(i) {
|
|
3
|
-
const o = i.indexOf("#"), e = i.indexOf("?");
|
|
4
|
-
let n = i.length;
|
|
5
|
-
return o >= 0 && (n = Math.min(n, o)), e >= 0 && (n = Math.min(n, e)), {
|
|
6
|
-
pathname: i.slice(0, n) || "/",
|
|
7
|
-
extras: i.slice(n)
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function p(i, o) {
|
|
11
|
-
if (!o || o === "/") return i;
|
|
12
|
-
const e = o.endsWith("/") ? o.slice(0, -1) : o;
|
|
13
|
-
if (!e) return i;
|
|
14
|
-
const { pathname: n, extras: c } = g(i);
|
|
15
|
-
return n === e ? `/${c}` : n.startsWith(`${e}/`) ? `${n.slice(e.length) || "/"}${c}` : i;
|
|
16
|
-
}
|
|
17
|
-
function P(i, o, e = {}) {
|
|
18
|
-
const n = (s) => {
|
|
19
|
-
for (const [a, f] of Object.entries(e))
|
|
20
|
-
if (f === s) return a;
|
|
21
|
-
return s === o ? "root" : s;
|
|
22
|
-
}, c = /* @__PURE__ */ new Map();
|
|
23
|
-
for (const s of i) {
|
|
24
|
-
if (s === o) continue;
|
|
25
|
-
const a = n(s), f = a === "root" ? s : a;
|
|
26
|
-
c.set(f, s), f !== s && c.set(s, s);
|
|
27
|
-
}
|
|
28
|
-
return c;
|
|
29
|
-
}
|
|
30
|
-
function q(i, o, e, n = {}, c) {
|
|
31
|
-
const { pathname: s } = g(p(i, c)), a = s.split("/").filter(Boolean)[0];
|
|
32
|
-
return a === void 0 ? e : P(o, e, n).get(a) ?? e;
|
|
33
|
-
}
|
|
34
|
-
function z(i, o, e, n = {}, c) {
|
|
35
|
-
const { pathname: s } = g(p(i, c)), a = s.split("/").filter(Boolean), f = a[0];
|
|
36
|
-
return f !== void 0 && (e !== void 0 ? P(o, e, n).has(f) && a.shift() : o.includes(f) && a.shift()), a.length === 0 ? "index" : a.join("-").replace(/\.html$/, "");
|
|
37
|
-
}
|
|
38
|
-
function I(i) {
|
|
39
|
-
return b({
|
|
40
|
-
name: "VitePressI18nLink",
|
|
41
|
-
props: {
|
|
42
|
-
to: { type: String, required: !0 },
|
|
43
|
-
style: { type: Object, default: void 0 }
|
|
44
|
-
},
|
|
45
|
-
setup(o, { slots: e }) {
|
|
46
|
-
return () => R(
|
|
47
|
-
"a",
|
|
48
|
-
{
|
|
49
|
-
href: o.to,
|
|
50
|
-
style: o.style,
|
|
51
|
-
onClick: (n) => {
|
|
52
|
-
n.defaultPrevented || n.button === 0 && (n.metaKey || n.altKey || n.ctrlKey || n.shiftKey || (n.preventDefault(), i ? i(o.to) : typeof window < "u" && window.location.assign(o.to)));
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
e.default?.()
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function U(i) {
|
|
61
|
-
const { locales: o, defaultLocale: e, localeKeyToCode: n = {}, base: c, getPath: s, go: a } = i, f = o.map((t) => t.code), u = { ...n }, C = P(f, e, u), j = [...C.keys()], d = c && c !== "/" ? c : void 0, K = (t) => u[t] ? u[t] : t === "root" ? e : t, v = (t) => {
|
|
62
|
-
for (const [r, l] of Object.entries(u))
|
|
63
|
-
if (l === t) return r;
|
|
64
|
-
return t === e ? "root" : t;
|
|
65
|
-
}, L = (t) => {
|
|
66
|
-
if (t === e) return null;
|
|
67
|
-
const r = v(t);
|
|
68
|
-
return r === "root" ? t : r;
|
|
69
|
-
}, T = (t) => {
|
|
70
|
-
const r = t === "/" || t.endsWith("/"), l = t.split("/").filter(Boolean), h = l[0];
|
|
71
|
-
return h !== void 0 && C.has(h) && l.shift(), { segments: l, hadTrailingSlash: r };
|
|
72
|
-
}, O = (t) => {
|
|
73
|
-
const { pathname: r, extras: l } = g(p(t, d)), { segments: h, hadTrailingSlash: m } = T(r);
|
|
74
|
-
let w = h.length === 0 ? "/" : `/${h.join("/")}`;
|
|
75
|
-
return w !== "/" && m && (w += "/"), `${w}${l}`;
|
|
76
|
-
}, y = (t, r) => {
|
|
77
|
-
const { pathname: l, extras: h } = g(p(t, d)), { segments: m, hadTrailingSlash: w } = T(l), F = L(r);
|
|
78
|
-
F && m.unshift(F);
|
|
79
|
-
let x = m.length === 0 ? "/" : `/${m.join("/")}`;
|
|
80
|
-
return x !== "/" && w && (x += "/"), `${x}${h}`;
|
|
81
|
-
}, S = (t, r) => y(t, r), B = (t, r) => {
|
|
82
|
-
const l = typeof t == "string" ? t : t.path || "/";
|
|
83
|
-
return y(l, r);
|
|
84
|
-
}, $ = (t, r = !1) => {
|
|
85
|
-
if (a) {
|
|
86
|
-
a(t, { replace: r });
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
typeof window < "u" && (r ? window.location.replace(t) : window.location.assign(t));
|
|
90
|
-
}, k = () => s ? s() : typeof window < "u" ? window.location.pathname + window.location.search + window.location.hash : "/";
|
|
91
|
-
return {
|
|
92
|
-
localeCodes: f,
|
|
93
|
-
defaultLocale: e,
|
|
94
|
-
localeKeyToCode: u,
|
|
95
|
-
urlPrefixes: j,
|
|
96
|
-
base: d,
|
|
97
|
-
codeFromLocaleKey: K,
|
|
98
|
-
localeKeyFromCode: v,
|
|
99
|
-
getLocaleFromPath: (t) => q(t, f, e, u, d),
|
|
100
|
-
switchLocalePath: S,
|
|
101
|
-
localizePath: y,
|
|
102
|
-
removeLocaleFromPath: O,
|
|
103
|
-
routeNameFromPath: (t) => z(t, f, e, u, d),
|
|
104
|
-
linkComponent: I(a),
|
|
105
|
-
getCurrentPath: () => p(k(), d),
|
|
106
|
-
push: (t) => {
|
|
107
|
-
$(t.path, !1);
|
|
108
|
-
},
|
|
109
|
-
replace: (t) => {
|
|
110
|
-
$(t.path, !0);
|
|
111
|
-
},
|
|
112
|
-
resolvePath: B,
|
|
113
|
-
getRoute: () => {
|
|
114
|
-
const t = p(k(), d), r = typeof window < "u" ? new URL(t, window.location.origin) : new URL(t, "http://localhost");
|
|
115
|
-
return {
|
|
116
|
-
fullPath: r.pathname + r.search + r.hash,
|
|
117
|
-
query: Object.fromEntries(r.searchParams)
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
export {
|
|
123
|
-
U as c,
|
|
124
|
-
q as g,
|
|
125
|
-
z as r,
|
|
126
|
-
p as s
|
|
127
|
-
};
|
|
128
|
-
//# sourceMappingURL=adapter-BnsyIKhp.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"adapter-BnsyIKhp.js","sources":["../src/router/adapter.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\nimport type { I18nRoutingStrategy } from '@i18n-micro/vue'\nimport { defineComponent, h, type Component, type PropType } from 'vue'\n\nexport interface VitePressRouterLike {\n route: {\n path: string\n hash?: string\n query?: string\n }\n go: (to: string, options?: { initialLoad?: boolean; replace?: boolean }) => void | Promise<void>\n onAfterRouteChange?: (to: string) => unknown\n}\n\nexport type VitePressGo = (href: string, options?: { replace?: boolean }) => void | Promise<void>\n\nexport interface VitePressRouterAdapterOptions {\n locales: Locale[]\n defaultLocale: string\n /**\n * Map VitePress locale keys (`root`, `fr`) to i18n locale codes.\n * Defaults: `root` → `defaultLocale`, other keys → same string as the key.\n * URL prefixes always use VitePress keys; i18n uses codes.\n */\n localeKeyToCode?: Record<string, string>\n /**\n * VitePress `site.base` (e.g. `/openapi_docs/`). Stripped from paths before\n * locale / route-name detection. Returned localize paths are base-relative\n * (VitePress / `withBase` re-applies the base).\n */\n base?: string\n getPath?: () => string\n go?: VitePressGo\n}\n\nexport interface VitePressRouterAdapter extends I18nRoutingStrategy {\n getLocaleFromPath: (path: string) => string\n switchLocalePath: (path: string, newLocale: string) => string\n localizePath: (path: string, locale: string) => string\n removeLocaleFromPath: (path: string) => string\n /** Page dictionary route name (`/fr/guide/demo` → `guide-demo`). */\n routeNameFromPath: (path: string) => string\n /** Resolve VitePress locale key (`root` / `fr`) to i18n code. */\n codeFromLocaleKey: (localeKey: string) => string\n /** Resolve i18n code to VitePress locale key. */\n localeKeyFromCode: (code: string) => string\n localeCodes: string[]\n defaultLocale: string\n /** Snapshot of mapping used when building the adapter (for `i18nRouting` serialization). */\n localeKeyToCode: Record<string, string>\n /** URL path prefixes (VitePress locale keys except `root`). */\n urlPrefixes: string[]\n /** VitePress `site.base` used when constructing this adapter (may be undefined). */\n base?: string\n}\n\n/** Path helpers exposed on `createI18n` instances (slice of the router adapter). */\nexport type PathMethods = Pick<\n VitePressRouterAdapter,\n 'localizePath' | 'switchLocalePath' | 'getLocaleFromPath' | 'removeLocaleFromPath' | 'routeNameFromPath'\n>\n\nfunction splitPathAndExtras(path: string): { pathname: string; extras: string } {\n const hashIndex = path.indexOf('#')\n const queryIndex = path.indexOf('?')\n let cut = path.length\n if (hashIndex >= 0) cut = Math.min(cut, hashIndex)\n if (queryIndex >= 0) cut = Math.min(cut, queryIndex)\n return {\n pathname: path.slice(0, cut) || '/',\n extras: path.slice(cut),\n }\n}\n\n/**\n * Strip VitePress `site.base` from a path. Leaves query/hash intact.\n * No-op when `base` is missing or `/`.\n */\nexport function stripSiteBase(path: string, base?: string): string {\n if (!base || base === '/') return path\n const normalized = base.endsWith('/') ? base.slice(0, -1) : base\n if (!normalized) return path\n const { pathname, extras } = splitPathAndExtras(path)\n if (pathname === normalized) return `/${extras}`\n if (pathname.startsWith(`${normalized}/`)) {\n return `${pathname.slice(normalized.length) || '/'}${extras}`\n }\n return path\n}\n\n/**\n * Build URL prefix → i18n code map.\n * Prefixes are VitePress locale keys (and codes when they differ), never `root`.\n */\nexport function buildUrlPrefixToCode(\n localeCodes: string[],\n defaultLocale: string,\n localeKeyToCode: Record<string, string> = {},\n): Map<string, string> {\n const keyFromCode = (code: string): string => {\n for (const [key, mapped] of Object.entries(localeKeyToCode)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n }\n\n const prefixToCode = new Map<string, string>()\n for (const code of localeCodes) {\n if (code === defaultLocale) continue\n const key = keyFromCode(code)\n const urlKey = key === 'root' ? code : key\n prefixToCode.set(urlKey, code)\n if (urlKey !== code) prefixToCode.set(code, code)\n }\n return prefixToCode\n}\n\n/**\n * Detect i18n locale code from a URL path (prefix_except_default).\n * Path prefixes are VitePress locale keys; return value is the i18n code.\n * Pass `base` when the path may include VitePress `site.base` (SSG).\n */\nexport function getLocaleFromPath(\n path: string,\n localeCodes: string[],\n defaultLocale: string,\n localeKeyToCode: Record<string, string> = {},\n base?: string,\n): string {\n const { pathname } = splitPathAndExtras(stripSiteBase(path, base))\n const first = pathname.split('/').filter(Boolean)[0]\n if (first === undefined) return defaultLocale\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCode)\n return prefixToCode.get(first) ?? defaultLocale\n}\n\n/**\n * Route name for page-scoped dictionaries (`/guide/demo` → `guide-demo`).\n * Strips VitePress URL prefixes (keys), not only raw i18n codes.\n *\n * When `defaultLocale` is omitted (legacy 2-arg call), any segment that matches a\n * listed locale code is stripped — callers must not rely on `localeCodes[0]` as default.\n */\nexport function routeNameFromPath(\n path: string,\n localeCodes: string[],\n defaultLocale?: string,\n localeKeyToCode: Record<string, string> = {},\n base?: string,\n): string {\n const { pathname } = splitPathAndExtras(stripSiteBase(path, base))\n const segments = pathname.split('/').filter(Boolean)\n const first = segments[0]\n if (first !== undefined) {\n if (defaultLocale !== undefined) {\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCode)\n if (prefixToCode.has(first)) segments.shift()\n } else if (localeCodes.includes(first)) {\n segments.shift()\n }\n }\n if (segments.length === 0) return 'index'\n return segments.join('-').replace(/\\.html$/, '')\n}\n\nfunction createVitePressLinkComponent(go?: VitePressGo): Component {\n return defineComponent({\n name: 'VitePressI18nLink',\n props: {\n to: { type: String, required: true },\n style: { type: Object as PropType<Record<string, string>>, default: undefined },\n },\n setup(props, { slots }) {\n return () =>\n h(\n 'a',\n {\n href: props.to,\n style: props.style,\n onClick: (e: MouseEvent) => {\n if (e.defaultPrevented) return\n if (e.button !== 0) return\n if (e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) return\n e.preventDefault()\n if (go) {\n void go(props.to)\n } else if (typeof window !== 'undefined') {\n window.location.assign(props.to)\n }\n },\n },\n slots.default?.(),\n )\n },\n })\n}\n\n/**\n * VitePress path adapter (prefix_except_default semantics):\n * default locale has no URL prefix; other locales use `/{vitepressKey}/…`.\n * i18n locale values remain `locale.code` (via `localeKeyToCode`).\n */\nexport function createVitePressRouterAdapter(options: VitePressRouterAdapterOptions): VitePressRouterAdapter {\n const { locales, defaultLocale, localeKeyToCode = {}, base, getPath, go } = options\n const localeCodes = locales.map((loc) => loc.code)\n const localeKeyToCodeSnapshot = { ...localeKeyToCode }\n const prefixToCode = buildUrlPrefixToCode(localeCodes, defaultLocale, localeKeyToCodeSnapshot)\n const urlPrefixes = [...prefixToCode.keys()]\n const siteBase = base && base !== '/' ? base : undefined\n\n const codeFromLocaleKey = (localeKey: string): string => {\n if (localeKeyToCodeSnapshot[localeKey]) return localeKeyToCodeSnapshot[localeKey]!\n if (localeKey === 'root') return defaultLocale\n return localeKey\n }\n\n const localeKeyFromCode = (code: string): string => {\n for (const [key, mapped] of Object.entries(localeKeyToCodeSnapshot)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n }\n\n const urlPrefixForCode = (code: string): string | null => {\n if (code === defaultLocale) return null\n const key = localeKeyFromCode(code)\n return key === 'root' ? code : key\n }\n\n const stripPrefix = (pathname: string): { segments: string[]; hadTrailingSlash: boolean } => {\n const hadTrailingSlash = pathname === '/' || pathname.endsWith('/')\n const segments = pathname.split('/').filter(Boolean)\n const first = segments[0]\n if (first !== undefined && prefixToCode.has(first)) {\n segments.shift()\n }\n return { segments, hadTrailingSlash }\n }\n\n const removeLocaleFromPath = (path: string): string => {\n const { pathname, extras } = splitPathAndExtras(stripSiteBase(path, siteBase))\n const { segments, hadTrailingSlash } = stripPrefix(pathname)\n let clean = segments.length === 0 ? '/' : `/${segments.join('/')}`\n if (clean !== '/' && hadTrailingSlash) clean += '/'\n return `${clean}${extras}`\n }\n\n const localizePath = (path: string, locale: string): string => {\n const { pathname, extras } = splitPathAndExtras(stripSiteBase(path, siteBase))\n const { segments, hadTrailingSlash } = stripPrefix(pathname)\n const prefix = urlPrefixForCode(locale)\n if (prefix) segments.unshift(prefix)\n let localized = segments.length === 0 ? '/' : `/${segments.join('/')}`\n if (localized !== '/' && hadTrailingSlash) localized += '/'\n return `${localized}${extras}`\n }\n\n const switchLocalePath = (path: string, newLocale: string): string => {\n return localizePath(path, newLocale)\n }\n\n const resolvePath = (to: string | { path?: string }, locale: string): string => {\n const path = typeof to === 'string' ? to : to.path || '/'\n return localizePath(path, locale)\n }\n\n const navigate = (href: string, replace = false) => {\n if (go) {\n void go(href, { replace })\n return\n }\n if (typeof window !== 'undefined') {\n if (replace) {\n window.location.replace(href)\n } else {\n window.location.assign(href)\n }\n }\n }\n\n const currentFullPath = (): string => {\n if (getPath) return getPath()\n if (typeof window !== 'undefined') {\n return window.location.pathname + window.location.search + window.location.hash\n }\n return '/'\n }\n\n return {\n localeCodes,\n defaultLocale,\n localeKeyToCode: localeKeyToCodeSnapshot,\n urlPrefixes,\n base: siteBase,\n codeFromLocaleKey,\n localeKeyFromCode,\n getLocaleFromPath: (path: string) => getLocaleFromPath(path, localeCodes, defaultLocale, localeKeyToCodeSnapshot, siteBase),\n switchLocalePath,\n localizePath,\n removeLocaleFromPath,\n routeNameFromPath: (path: string) => routeNameFromPath(path, localeCodes, defaultLocale, localeKeyToCodeSnapshot, siteBase),\n linkComponent: createVitePressLinkComponent(go),\n getCurrentPath: () => stripSiteBase(currentFullPath(), siteBase),\n push: (target: { path: string }) => {\n navigate(target.path, false)\n },\n replace: (target: { path: string }) => {\n navigate(target.path, true)\n },\n resolvePath,\n getRoute: () => {\n const path = stripSiteBase(currentFullPath(), siteBase)\n const url = typeof window !== 'undefined' ? new URL(path, window.location.origin) : new URL(path, 'http://localhost')\n return {\n fullPath: url.pathname + url.search + url.hash,\n query: Object.fromEntries(url.searchParams),\n }\n },\n }\n}\n"],"names":["splitPathAndExtras","path","hashIndex","queryIndex","cut","stripSiteBase","base","normalized","pathname","extras","buildUrlPrefixToCode","localeCodes","defaultLocale","localeKeyToCode","keyFromCode","code","key","mapped","prefixToCode","urlKey","getLocaleFromPath","first","routeNameFromPath","segments","createVitePressLinkComponent","go","defineComponent","props","slots","h","e","createVitePressRouterAdapter","options","locales","getPath","loc","localeKeyToCodeSnapshot","urlPrefixes","siteBase","codeFromLocaleKey","localeKey","localeKeyFromCode","urlPrefixForCode","stripPrefix","hadTrailingSlash","removeLocaleFromPath","clean","localizePath","locale","prefix","localized","switchLocalePath","newLocale","resolvePath","to","navigate","href","replace","currentFullPath","target","url"],"mappings":";AA8DA,SAASA,EAAmBC,GAAoD;AAC9E,QAAMC,IAAYD,EAAK,QAAQ,GAAG,GAC5BE,IAAaF,EAAK,QAAQ,GAAG;AACnC,MAAIG,IAAMH,EAAK;AACf,SAAIC,KAAa,MAAGE,IAAM,KAAK,IAAIA,GAAKF,CAAS,IAC7CC,KAAc,MAAGC,IAAM,KAAK,IAAIA,GAAKD,CAAU,IAC5C;AAAA,IACL,UAAUF,EAAK,MAAM,GAAGG,CAAG,KAAK;AAA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,GAAMU,GAAaC,GAAewB,GAAyBE,CAAQ;AAAA,IAC1H,kBAAAa;AAAA,IACA,cAAAJ;AAAA,IACA,sBAAAF;AAAA,IACA,mBAAmB,CAAC5C,MAAiBqB,EAAkBrB,GAAMU,GAAaC,GAAewB,GAAyBE,CAAQ;AAAA,IAC1H,eAAed,EAA6BC,CAAE;AAAA,IAC9C,gBAAgB,MAAMpB,EAAcqD,EAAA,GAAmBpB,CAAQ;AAAA,IAC/D,MAAM,CAACqB,MAA6B;AAClC,MAAAJ,EAASI,EAAO,MAAM,EAAK;AAAA,IAC7B;AAAA,IACA,SAAS,CAACA,MAA6B;AACrC,MAAAJ,EAASI,EAAO,MAAM,EAAI;AAAA,IAC5B;AAAA,IACA,aAAAN;AAAA,IACA,UAAU,MAAM;AACd,YAAMpD,IAAOI,EAAcqD,EAAA,GAAmBpB,CAAQ,GAChDsB,IAAM,OAAO,SAAW,MAAc,IAAI,IAAI3D,GAAM,OAAO,SAAS,MAAM,IAAI,IAAI,IAAIA,GAAM,kBAAkB;AACpH,aAAO;AAAA,QACL,UAAU2D,EAAI,WAAWA,EAAI,SAASA,EAAI;AAAA,QAC1C,OAAO,OAAO,YAAYA,EAAI,YAAY;AAAA,MAAA;AAAA,IAE9C;AAAA,EAAA;AAEJ;"}
|
package/dist/create-BgMbe0w1.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";const L=require("@i18n-micro/utils/parse-path"),R=require("@i18n-micro/vue"),P=require("./adapter-BJ-0ltIc.cjs");function v(e,n,l){if(l)for(const[i,a]of Object.entries(l))for(const[c,h]of Object.entries(a))e.global.addRouteTranslations(c,i,L.mergeRouteTranslationsWithRoot(n?.[c],h),!1)}function F(e){const n=e.defaultLocale||e.locale,l=e.locales??[],i=e.syncWithVitePress!==!1,a=R.createI18n({locale:e.locale,fallbackLocale:e.fallbackLocale??n,messages:e.messages,plural:e.plural,missingWarn:e.missingWarn,missingHandler:e.missingHandler,locales:l,defaultLocale:n});v(a,e.messages,e.routeMessages);const c=P.createVitePressRouterAdapter({locales:l,defaultLocale:n,localeKeyToCode:e.localeKeyToCode,base:e.base}),h={localizePath:c.localizePath,switchLocalePath:c.switchLocalePath,getLocaleFromPath:c.getLocaleFromPath,removeLocaleFromPath:c.removeLocaleFromPath,routeNameFromPath:c.routeNameFromPath};a.global.extend(h);const y=new Set(Object.keys(e.routeMessages??{})),f=new WeakMap;return Object.assign(a,h,{get i18n(){return a.global},enhanceApp:p=>{const{app:d,router:u}=p;let t=f.get(d);if(!t){const r=P.createVitePressRouterAdapter({locales:l,defaultLocale:n,localeKeyToCode:e.localeKeyToCode,base:e.base,getPath:()=>{const o=u.route;return`${o.path}${o.query||""}${o.hash||""}`},go:(o,s)=>u.go(o,s)});d.use(a),a.setRoutingStrategy(r),t={adapter:r,boundSyncHandler:null,chainedPrevious:void 0},f.set(d,t)}if(!i)return;const{adapter:m}=t,b=(r=u.route.path)=>{const o=m.getLocaleFromPath(r);a.global.getLocale()!==o&&(a.global.locale=o);const s=m.routeNameFromPath(r);a.global.setRoute(y.has(s)?s:"index")};b();const g=u.onAfterRouteChange;g!==t.boundSyncHandler&&(t.chainedPrevious=typeof g=="function"?g:void 0),t.boundSyncHandler=async r=>{typeof t.chainedPrevious=="function"&&await t.chainedPrevious(r);const o=r.startsWith("http")?(()=>{const s=new URL(r);return s.pathname+s.search+s.hash})():r;b(o)},u.onAfterRouteChange=t.boundSyncHandler}})}exports.createI18n=F;
|
|
2
|
-
//# sourceMappingURL=create-BgMbe0w1.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-BgMbe0w1.cjs","sources":["../src/runtime/create.ts"],"sourcesContent":["import type { Locale, PluralFunc, Translations } from '@i18n-micro/types'\nimport { mergeRouteTranslationsWithRoot } from '@i18n-micro/utils/parse-path'\nimport { createI18n as createVueI18n, type I18nPlugin } from '@i18n-micro/vue'\nimport type { App, Ref } from 'vue'\nimport { createVitePressRouterAdapter, type PathMethods, type VitePressRouterAdapter, type VitePressRouterLike } from '../router/adapter'\n\nexport type { PathMethods }\n\nexport interface CreateI18nOptions {\n locale: string\n fallbackLocale?: string\n locales?: Locale[]\n defaultLocale?: string\n messages?: Record<string, Translations>\n /**\n * Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.\n * Loaded from `locales/pages/**` when using `withI18n`.\n */\n routeMessages?: Record<string, Record<string, Translations>>\n plural?: PluralFunc\n missingWarn?: boolean\n missingHandler?: (locale: string, key: string, routeName: string) => void\n /**\n * Sync i18n locale from the VitePress URL path on every navigation.\n * @default true\n */\n syncWithVitePress?: boolean\n /**\n * Map VitePress locale keys to i18n codes (`root` → default locale code).\n */\n localeKeyToCode?: Record<string, string>\n /**\n * VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher\n * do not treat the base segment as content / double-prefix links.\n */\n base?: string\n}\n\nexport interface VitePressSiteDataLike {\n locales?: Record<string, { lang?: string; link?: string; label?: string }>\n}\n\nexport type CreateI18nResult = I18nPlugin &\n PathMethods & {\n /** Same as `.global` (VueI18n + path methods). */\n i18n: I18nPlugin['global'] & PathMethods\n enhanceApp: (ctx: { app: App; router: VitePressRouterLike; siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike }) => void\n }\n\nfunction applyRouteMessages(\n plugin: I18nPlugin,\n root: Record<string, Translations> | undefined,\n routeMessages: Record<string, Record<string, Translations>> | undefined,\n): void {\n if (!routeMessages) return\n for (const [routeName, byLocale] of Object.entries(routeMessages)) {\n for (const [locale, translations] of Object.entries(byLocale)) {\n plugin.global.addRouteTranslations(locale, routeName, mergeRouteTranslationsWithRoot(root?.[locale], translations), false)\n }\n }\n}\n\n/**\n * Universal VitePress i18n: Vue plugin + path helpers + `enhanceApp` sync.\n * Path methods are the router adapter’s own functions (no wrapper layer).\n */\nexport function createI18n(options: CreateI18nOptions): CreateI18nResult {\n const defaultLocale = options.defaultLocale || options.locale\n const locales = options.locales ?? []\n const syncWithVitePress = options.syncWithVitePress !== false\n\n const plugin = createVueI18n({\n locale: options.locale,\n fallbackLocale: options.fallbackLocale ?? defaultLocale,\n messages: options.messages,\n plural: options.plural,\n missingWarn: options.missingWarn,\n missingHandler: options.missingHandler,\n locales,\n defaultLocale,\n })\n\n applyRouteMessages(plugin, options.messages, options.routeMessages)\n\n const paths = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n base: options.base,\n })\n const pathMethods: PathMethods = {\n localizePath: paths.localizePath,\n switchLocalePath: paths.switchLocalePath,\n getLocaleFromPath: paths.getLocaleFromPath,\n removeLocaleFromPath: paths.removeLocaleFromPath,\n routeNameFromPath: paths.routeNameFromPath,\n }\n plugin.global.extend(pathMethods)\n\n const pageRouteNames = new Set(Object.keys(options.routeMessages ?? {}))\n\n const byApp = new WeakMap<\n object,\n {\n adapter: VitePressRouterAdapter\n boundSyncHandler: ((to: string) => unknown) | null\n chainedPrevious: ((to: string) => unknown) | undefined\n }\n >()\n\n const enhanceApp = (ctx: { app: App; router: VitePressRouterLike; siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike }) => {\n const { app, router } = ctx\n\n let state = byApp.get(app)\n if (!state) {\n const adapter = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n base: options.base,\n getPath: () => {\n const route = router.route\n return `${route.path}${route.query || ''}${route.hash || ''}`\n },\n go: (href, navOptions) => router.go(href, navOptions),\n })\n\n app.use(plugin)\n plugin.setRoutingStrategy(adapter)\n state = { adapter, boundSyncHandler: null, chainedPrevious: undefined }\n byApp.set(app, state)\n }\n\n if (!syncWithVitePress) return\n\n const { adapter } = state\n const sync = (path = router.route.path) => {\n const nextLocale = adapter.getLocaleFromPath(path)\n if (plugin.global.getLocale() !== nextLocale) {\n plugin.global.locale = nextLocale\n }\n const derived = adapter.routeNameFromPath(path)\n plugin.global.setRoute(pageRouteNames.has(derived) ? derived : 'index')\n }\n\n sync()\n\n const current = router.onAfterRouteChange\n if (current !== state.boundSyncHandler) {\n state.chainedPrevious = typeof current === 'function' ? current : undefined\n }\n state.boundSyncHandler = async (to: string) => {\n if (typeof state.chainedPrevious === 'function') {\n await state.chainedPrevious(to)\n }\n const path = to.startsWith('http')\n ? (() => {\n const url = new URL(to)\n return url.pathname + url.search + url.hash\n })()\n : to\n sync(path)\n }\n router.onAfterRouteChange = state.boundSyncHandler\n }\n\n return Object.assign(plugin, pathMethods, {\n get i18n() {\n return plugin.global as I18nPlugin['global'] & PathMethods\n },\n enhanceApp,\n }) as CreateI18nResult\n}\n"],"names":["applyRouteMessages","plugin","root","routeMessages","routeName","byLocale","locale","translations","mergeRouteTranslationsWithRoot","createI18n","options","defaultLocale","locales","syncWithVitePress","createVueI18n","paths","createVitePressRouterAdapter","pathMethods","pageRouteNames","byApp","ctx","app","router","state","adapter","route","href","navOptions","sync","path","nextLocale","derived","current","to","url"],"mappings":"8HAiDA,SAASA,EACPC,EACAC,EACAC,EACM,CACN,GAAKA,EACL,SAAW,CAACC,EAAWC,CAAQ,IAAK,OAAO,QAAQF,CAAa,EAC9D,SAAW,CAACG,EAAQC,CAAY,IAAK,OAAO,QAAQF,CAAQ,EAC1DJ,EAAO,OAAO,qBAAqBK,EAAQF,EAAWI,iCAA+BN,IAAOI,CAAM,EAAGC,CAAY,EAAG,EAAK,CAG/H,CAMO,SAASE,EAAWC,EAA8C,CACvE,MAAMC,EAAgBD,EAAQ,eAAiBA,EAAQ,OACjDE,EAAUF,EAAQ,SAAW,CAAA,EAC7BG,EAAoBH,EAAQ,oBAAsB,GAElDT,EAASa,EAAAA,WAAc,CAC3B,OAAQJ,EAAQ,OAChB,eAAgBA,EAAQ,gBAAkBC,EAC1C,SAAUD,EAAQ,SAClB,OAAQA,EAAQ,OAChB,YAAaA,EAAQ,YACrB,eAAgBA,EAAQ,eACxB,QAAAE,EACA,cAAAD,CAAA,CACD,EAEDX,EAAmBC,EAAQS,EAAQ,SAAUA,EAAQ,aAAa,EAElE,MAAMK,EAAQ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6B,IAChC7B,EAAO,OAAO,OAAS6B,GAEzB,MAAMC,EAAUP,EAAQ,kBAAkBK,CAAI,EAC9C5B,EAAO,OAAO,SAASiB,EAAe,IAAIa,CAAO,EAAIA,EAAU,OAAO,CACxE,EAEAH,EAAA,EAEA,MAAMI,EAAUV,EAAO,mBACnBU,IAAYT,EAAM,mBACpBA,EAAM,gBAAkB,OAAOS,GAAY,WAAaA,EAAU,QAEpET,EAAM,iBAAmB,MAAOU,GAAe,CACzC,OAAOV,EAAM,iBAAoB,YACnC,MAAMA,EAAM,gBAAgBU,CAAE,EAEhC,MAAMJ,EAAOI,EAAG,WAAW,MAAM,GAC5B,IAAM,CACL,MAAMC,EAAM,IAAI,IAAID,CAAE,EACtB,OAAOC,EAAI,SAAWA,EAAI,OAASA,EAAI,IACzC,KACAD,EACJL,EAAKC,CAAI,CACX,EACAP,EAAO,mBAAqBC,EAAM,gBACpC,CAME,CACD,CACH"}
|
package/dist/create-Dev8Q66O.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { mergeRouteTranslationsWithRoot as L } from "@i18n-micro/utils/parse-path";
|
|
2
|
-
import { createI18n as R } from "@i18n-micro/vue";
|
|
3
|
-
import { c as y } from "./adapter-BnsyIKhp.js";
|
|
4
|
-
function v(e, l, n) {
|
|
5
|
-
if (n)
|
|
6
|
-
for (const [i, a] of Object.entries(n))
|
|
7
|
-
for (const [c, h] of Object.entries(a))
|
|
8
|
-
e.global.addRouteTranslations(c, i, L(l?.[c], h), !1);
|
|
9
|
-
}
|
|
10
|
-
function C(e) {
|
|
11
|
-
const l = e.defaultLocale || e.locale, n = e.locales ?? [], i = e.syncWithVitePress !== !1, a = R({
|
|
12
|
-
locale: e.locale,
|
|
13
|
-
fallbackLocale: e.fallbackLocale ?? l,
|
|
14
|
-
messages: e.messages,
|
|
15
|
-
plural: e.plural,
|
|
16
|
-
missingWarn: e.missingWarn,
|
|
17
|
-
missingHandler: e.missingHandler,
|
|
18
|
-
locales: n,
|
|
19
|
-
defaultLocale: l
|
|
20
|
-
});
|
|
21
|
-
v(a, e.messages, e.routeMessages);
|
|
22
|
-
const c = y({
|
|
23
|
-
locales: n,
|
|
24
|
-
defaultLocale: l,
|
|
25
|
-
localeKeyToCode: e.localeKeyToCode,
|
|
26
|
-
base: e.base
|
|
27
|
-
}), h = {
|
|
28
|
-
localizePath: c.localizePath,
|
|
29
|
-
switchLocalePath: c.switchLocalePath,
|
|
30
|
-
getLocaleFromPath: c.getLocaleFromPath,
|
|
31
|
-
removeLocaleFromPath: c.removeLocaleFromPath,
|
|
32
|
-
routeNameFromPath: c.routeNameFromPath
|
|
33
|
-
};
|
|
34
|
-
a.global.extend(h);
|
|
35
|
-
const P = new Set(Object.keys(e.routeMessages ?? {})), m = /* @__PURE__ */ new WeakMap();
|
|
36
|
-
return Object.assign(a, h, {
|
|
37
|
-
get i18n() {
|
|
38
|
-
return a.global;
|
|
39
|
-
},
|
|
40
|
-
enhanceApp: (p) => {
|
|
41
|
-
const { app: d, router: u } = p;
|
|
42
|
-
let t = m.get(d);
|
|
43
|
-
if (!t) {
|
|
44
|
-
const o = y({
|
|
45
|
-
locales: n,
|
|
46
|
-
defaultLocale: l,
|
|
47
|
-
localeKeyToCode: e.localeKeyToCode,
|
|
48
|
-
base: e.base,
|
|
49
|
-
getPath: () => {
|
|
50
|
-
const r = u.route;
|
|
51
|
-
return `${r.path}${r.query || ""}${r.hash || ""}`;
|
|
52
|
-
},
|
|
53
|
-
go: (r, s) => u.go(r, s)
|
|
54
|
-
});
|
|
55
|
-
d.use(a), a.setRoutingStrategy(o), t = { adapter: o, boundSyncHandler: null, chainedPrevious: void 0 }, m.set(d, t);
|
|
56
|
-
}
|
|
57
|
-
if (!i) return;
|
|
58
|
-
const { adapter: f } = t, b = (o = u.route.path) => {
|
|
59
|
-
const r = f.getLocaleFromPath(o);
|
|
60
|
-
a.global.getLocale() !== r && (a.global.locale = r);
|
|
61
|
-
const s = f.routeNameFromPath(o);
|
|
62
|
-
a.global.setRoute(P.has(s) ? s : "index");
|
|
63
|
-
};
|
|
64
|
-
b();
|
|
65
|
-
const g = u.onAfterRouteChange;
|
|
66
|
-
g !== t.boundSyncHandler && (t.chainedPrevious = typeof g == "function" ? g : void 0), t.boundSyncHandler = async (o) => {
|
|
67
|
-
typeof t.chainedPrevious == "function" && await t.chainedPrevious(o);
|
|
68
|
-
const r = o.startsWith("http") ? (() => {
|
|
69
|
-
const s = new URL(o);
|
|
70
|
-
return s.pathname + s.search + s.hash;
|
|
71
|
-
})() : o;
|
|
72
|
-
b(r);
|
|
73
|
-
}, u.onAfterRouteChange = t.boundSyncHandler;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
export {
|
|
78
|
-
C as c
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=create-Dev8Q66O.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"create-Dev8Q66O.js","sources":["../src/runtime/create.ts"],"sourcesContent":["import type { Locale, PluralFunc, Translations } from '@i18n-micro/types'\nimport { mergeRouteTranslationsWithRoot } from '@i18n-micro/utils/parse-path'\nimport { createI18n as createVueI18n, type I18nPlugin } from '@i18n-micro/vue'\nimport type { App, Ref } from 'vue'\nimport { createVitePressRouterAdapter, type PathMethods, type VitePressRouterAdapter, type VitePressRouterLike } from '../router/adapter'\n\nexport type { PathMethods }\n\nexport interface CreateI18nOptions {\n locale: string\n fallbackLocale?: string\n locales?: Locale[]\n defaultLocale?: string\n messages?: Record<string, Translations>\n /**\n * Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.\n * Loaded from `locales/pages/**` when using `withI18n`.\n */\n routeMessages?: Record<string, Record<string, Translations>>\n plural?: PluralFunc\n missingWarn?: boolean\n missingHandler?: (locale: string, key: string, routeName: string) => void\n /**\n * Sync i18n locale from the VitePress URL path on every navigation.\n * @default true\n */\n syncWithVitePress?: boolean\n /**\n * Map VitePress locale keys to i18n codes (`root` → default locale code).\n */\n localeKeyToCode?: Record<string, string>\n /**\n * VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher\n * do not treat the base segment as content / double-prefix links.\n */\n base?: string\n}\n\nexport interface VitePressSiteDataLike {\n locales?: Record<string, { lang?: string; link?: string; label?: string }>\n}\n\nexport type CreateI18nResult = I18nPlugin &\n PathMethods & {\n /** Same as `.global` (VueI18n + path methods). */\n i18n: I18nPlugin['global'] & PathMethods\n enhanceApp: (ctx: { app: App; router: VitePressRouterLike; siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike }) => void\n }\n\nfunction applyRouteMessages(\n plugin: I18nPlugin,\n root: Record<string, Translations> | undefined,\n routeMessages: Record<string, Record<string, Translations>> | undefined,\n): void {\n if (!routeMessages) return\n for (const [routeName, byLocale] of Object.entries(routeMessages)) {\n for (const [locale, translations] of Object.entries(byLocale)) {\n plugin.global.addRouteTranslations(locale, routeName, mergeRouteTranslationsWithRoot(root?.[locale], translations), false)\n }\n }\n}\n\n/**\n * Universal VitePress i18n: Vue plugin + path helpers + `enhanceApp` sync.\n * Path methods are the router adapter’s own functions (no wrapper layer).\n */\nexport function createI18n(options: CreateI18nOptions): CreateI18nResult {\n const defaultLocale = options.defaultLocale || options.locale\n const locales = options.locales ?? []\n const syncWithVitePress = options.syncWithVitePress !== false\n\n const plugin = createVueI18n({\n locale: options.locale,\n fallbackLocale: options.fallbackLocale ?? defaultLocale,\n messages: options.messages,\n plural: options.plural,\n missingWarn: options.missingWarn,\n missingHandler: options.missingHandler,\n locales,\n defaultLocale,\n })\n\n applyRouteMessages(plugin, options.messages, options.routeMessages)\n\n const paths = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n base: options.base,\n })\n const pathMethods: PathMethods = {\n localizePath: paths.localizePath,\n switchLocalePath: paths.switchLocalePath,\n getLocaleFromPath: paths.getLocaleFromPath,\n removeLocaleFromPath: paths.removeLocaleFromPath,\n routeNameFromPath: paths.routeNameFromPath,\n }\n plugin.global.extend(pathMethods)\n\n const pageRouteNames = new Set(Object.keys(options.routeMessages ?? {}))\n\n const byApp = new WeakMap<\n object,\n {\n adapter: VitePressRouterAdapter\n boundSyncHandler: ((to: string) => unknown) | null\n chainedPrevious: ((to: string) => unknown) | undefined\n }\n >()\n\n const enhanceApp = (ctx: { app: App; router: VitePressRouterLike; siteData?: Ref<VitePressSiteDataLike> | VitePressSiteDataLike }) => {\n const { app, router } = ctx\n\n let state = byApp.get(app)\n if (!state) {\n const adapter = createVitePressRouterAdapter({\n locales,\n defaultLocale,\n localeKeyToCode: options.localeKeyToCode,\n base: options.base,\n getPath: () => {\n const route = router.route\n return `${route.path}${route.query || ''}${route.hash || ''}`\n },\n go: (href, navOptions) => router.go(href, navOptions),\n })\n\n app.use(plugin)\n plugin.setRoutingStrategy(adapter)\n state = { adapter, boundSyncHandler: null, chainedPrevious: undefined }\n byApp.set(app, state)\n }\n\n if (!syncWithVitePress) return\n\n const { adapter } = state\n const sync = (path = router.route.path) => {\n const nextLocale = adapter.getLocaleFromPath(path)\n if (plugin.global.getLocale() !== nextLocale) {\n plugin.global.locale = nextLocale\n }\n const derived = adapter.routeNameFromPath(path)\n plugin.global.setRoute(pageRouteNames.has(derived) ? derived : 'index')\n }\n\n sync()\n\n const current = router.onAfterRouteChange\n if (current !== state.boundSyncHandler) {\n state.chainedPrevious = typeof current === 'function' ? current : undefined\n }\n state.boundSyncHandler = async (to: string) => {\n if (typeof state.chainedPrevious === 'function') {\n await state.chainedPrevious(to)\n }\n const path = to.startsWith('http')\n ? (() => {\n const url = new URL(to)\n return url.pathname + url.search + url.hash\n })()\n : to\n sync(path)\n }\n router.onAfterRouteChange = state.boundSyncHandler\n }\n\n return Object.assign(plugin, pathMethods, {\n get i18n() {\n return plugin.global as I18nPlugin['global'] & PathMethods\n },\n enhanceApp,\n }) as CreateI18nResult\n}\n"],"names":["applyRouteMessages","plugin","root","routeMessages","routeName","byLocale","locale","translations","mergeRouteTranslationsWithRoot","createI18n","options","defaultLocale","locales","syncWithVitePress","createVueI18n","paths","createVitePressRouterAdapter","pathMethods","pageRouteNames","byApp","ctx","app","router","state","adapter","route","href","navOptions","sync","path","nextLocale","derived","current","to","url"],"mappings":";;;AAiDA,SAASA,EACPC,GACAC,GACAC,GACM;AACN,MAAKA;AACL,eAAW,CAACC,GAAWC,CAAQ,KAAK,OAAO,QAAQF,CAAa;AAC9D,iBAAW,CAACG,GAAQC,CAAY,KAAK,OAAO,QAAQF,CAAQ;AAC1D,QAAAJ,EAAO,OAAO,qBAAqBK,GAAQF,GAAWI,EAA+BN,IAAOI,CAAM,GAAGC,CAAY,GAAG,EAAK;AAG/H;AAMO,SAASE,EAAWC,GAA8C;AACvE,QAAMC,IAAgBD,EAAQ,iBAAiBA,EAAQ,QACjDE,IAAUF,EAAQ,WAAW,CAAA,GAC7BG,IAAoBH,EAAQ,sBAAsB,IAElDT,IAASa,EAAc;AAAA,IAC3B,QAAQJ,EAAQ;AAAA,IAChB,gBAAgBA,EAAQ,kBAAkBC;AAAA,IAC1C,UAAUD,EAAQ;AAAA,IAClB,QAAQA,EAAQ;AAAA,IAChB,aAAaA,EAAQ;AAAA,IACrB,gBAAgBA,EAAQ;AAAA,IACxB,SAAAE;AAAA,IACA,eAAAD;AAAA,EAAA,CACD;AAED,EAAAX,EAAmBC,GAAQS,EAAQ,UAAUA,EAAQ,aAAa;AAElE,QAAMK,IAAQC,EAA6B;AAAA,IACzC,SAAAJ;AAAA,IACA,eAAAD;AAAA,IACA,iBAAiBD,EAAQ;AAAA,IACzB,MAAMA,EAAQ;AAAA,EAAA,CACf,GACKO,IAA2B;AAAA,IAC/B,cAAcF,EAAM;AAAA,IACpB,kBAAkBA,EAAM;AAAA,IACxB,mBAAmBA,EAAM;AAAA,IACzB,sBAAsBA,EAAM;AAAA,IAC5B,mBAAmBA,EAAM;AAAA,EAAA;AAE3B,EAAAd,EAAO,OAAO,OAAOgB,CAAW;AAEhC,QAAMC,IAAiB,IAAI,IAAI,OAAO,K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,MAAYT,EAAM,qBACpBA,EAAM,kBAAkB,OAAOS,KAAY,aAAaA,IAAU,SAEpET,EAAM,mBAAmB,OAAOU,MAAe;AAC7C,QAAI,OAAOV,EAAM,mBAAoB,cACnC,MAAMA,EAAM,gBAAgBU,CAAE;AAEhC,cAAMJ,IAAOI,EAAG,WAAW,MAAM,KAC5B,MAAM;AACL,gBAAMC,IAAM,IAAI,IAAID,CAAE;AACtB,iBAAOC,EAAI,WAAWA,EAAI,SAASA,EAAI;AAAA,QACzC,OACAD;AACJ,QAAAL,EAAKC,CAAI;AAAA,MACX,GACAP,EAAO,qBAAqBC,EAAM;AAAA,IACpC;AAAA,EAME,CACD;AACH;"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
function a(e, n, c) {
|
|
2
|
-
for (const [s, t] of Object.entries(c))
|
|
3
|
-
if (t === e) return s;
|
|
4
|
-
return e === n ? "root" : e;
|
|
5
|
-
}
|
|
6
|
-
function d(e, n, c = {}) {
|
|
7
|
-
const s = c.localeKeyToCode ?? {}, t = {};
|
|
8
|
-
for (const o of e) {
|
|
9
|
-
const r = a(o.code, n, s), l = r === "root" ? o.code : r, i = {
|
|
10
|
-
label: o.displayName || o.code.toUpperCase(),
|
|
11
|
-
lang: o.iso || o.code
|
|
12
|
-
};
|
|
13
|
-
r !== "root" && (i.link = `/${l}/`), t[r] = i;
|
|
14
|
-
}
|
|
15
|
-
if (!t.root) {
|
|
16
|
-
const o = e.find((r) => r.code === n) ?? e[0];
|
|
17
|
-
o && (t.root = {
|
|
18
|
-
label: o.displayName || o.code.toUpperCase(),
|
|
19
|
-
lang: o.iso || o.code
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return t;
|
|
23
|
-
}
|
|
24
|
-
export {
|
|
25
|
-
d as b
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=vitepress-locales-6msv22Sn.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vitepress-locales-6msv22Sn.js","sources":["../src/plugin/vitepress-locales.ts"],"sourcesContent":["import type { Locale } from '@i18n-micro/types'\n\n/**\n * Minimal VitePress `locales` entry used by the default theme language menu.\n */\nexport interface VitePressLocaleEntry {\n label: string\n lang: string\n link?: string\n}\n\nexport interface BuildVitePressLocalesOptions {\n /**\n * Map VitePress locale keys → i18n codes (`root` → default).\n * When a non-default code maps to a short VP key (`fr` → `fr-FR`), the URL\n * prefix / config key uses the VP key.\n */\n localeKeyToCode?: Record<string, string>\n}\n\nfunction localeKeyFromCode(code: string, defaultLocale: string, localeKeyToCode: Record<string, string>): string {\n for (const [key, mapped] of Object.entries(localeKeyToCode)) {\n if (mapped === code) return key\n }\n if (code === defaultLocale) return 'root'\n return code\n}\n\n/**\n * Build VitePress `config.locales` from i18n-micro `Locale[]`.\n * Default locale becomes `root` (no URL prefix); others get `/{key}/`.\n */\nexport function buildVitePressLocales(\n locales: Locale[],\n defaultLocale: string,\n options: BuildVitePressLocalesOptions = {},\n): Record<string, VitePressLocaleEntry> {\n const localeKeyToCode = options.localeKeyToCode ?? {}\n const result: Record<string, VitePressLocaleEntry> = {}\n\n for (const loc of locales) {\n const key = localeKeyFromCode(loc.code, defaultLocale, localeKeyToCode)\n const urlKey = key === 'root' ? loc.code : key\n const entry: VitePressLocaleEntry = {\n label: loc.displayName || loc.code.toUpperCase(),\n lang: loc.iso || loc.code,\n }\n if (key !== 'root') {\n entry.link = `/${urlKey}/`\n }\n result[key] = entry\n }\n\n if (!result.root) {\n const fallback = locales.find((l) => l.code === defaultLocale) ?? locales[0]\n if (fallback) {\n result.root = {\n label: fallback.displayName || fallback.code.toUpperCase(),\n lang: fallback.iso || fallback.code,\n }\n }\n }\n\n return result\n}\n"],"names":["localeKeyFromCode","code","defaultLocale","localeKeyToCode","key","mapped","buildVitePressLocales","locales","options","result","loc","urlKey","entry","fallback","l"],"mappings":"AAoBA,SAASA,EAAkBC,GAAcC,GAAuBC,GAAiD;AAC/G,aAAW,CAACC,GAAKC,CAAM,KAAK,OAAO,QAAQF,CAAe;AACxD,QAAIE,MAAWJ,EAAM,QAAOG;AAE9B,SAAIH,MAASC,IAAsB,SAC5BD;AACT;AAMO,SAASK,EACdC,GACAL,GACAM,IAAwC,CAAA,GACF;AACtC,QAAML,IAAkBK,EAAQ,mBAAmB,CAAA,GAC7CC,IAA+C,CAAA;AAErD,aAAWC,KAAOH,GAAS;AACzB,UAAMH,IAAMJ,EAAkBU,EAAI,MAAMR,GAAeC,CAAe,GAChEQ,IAASP,MAAQ,SAASM,EAAI,OAAON,GACrCQ,IAA8B;AAAA,MAClC,OAAOF,EAAI,eAAeA,EAAI,KAAK,YAAA;AAAA,MACnC,MAAMA,EAAI,OAAOA,EAAI;AAAA,IAAA;AAEvB,IAAIN,MAAQ,WACVQ,EAAM,OAAO,IAAID,CAAM,MAEzBF,EAAOL,CAAG,IAAIQ;AAAA,EAChB;AAEA,MAAI,CAACH,EAAO,MAAM;AAChB,UAAMI,IAAWN,EAAQ,KAAK,CAACO,MAAMA,EAAE,SAASZ,CAAa,KAAKK,EAAQ,CAAC;AAC3E,IAAIM,MACFJ,EAAO,OAAO;AAAA,MACZ,OAAOI,EAAS,eAAeA,EAAS,KAAK,YAAA;AAAA,MAC7C,MAAMA,EAAS,OAAOA,EAAS;AAAA,IAAA;AAAA,EAGrC;AAEA,SAAOJ;AACT;"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";function a(e,n,s){for(const[c,t]of Object.entries(s))if(t===e)return c;return e===n?"root":e}function d(e,n,s={}){const c=s.localeKeyToCode??{},t={};for(const o of e){const r=a(o.code,n,c),l=r==="root"?o.code:r,i={label:o.displayName||o.code.toUpperCase(),lang:o.iso||o.code};r!=="root"&&(i.link=`/${l}/`),t[r]=i}if(!t.root){const o=e.find(r=>r.code===n)??e[0];o&&(t.root={label:o.displayName||o.code.toUpperCase(),lang:o.iso||o.code})}return t}exports.buildVitePressLocales=d;
|
|
2
|
-
//# sourceMappingURL=vitepress-locales-Cz4AutfI.cjs.map
|