@i18n-micro/vitepress 1.1.13 → 2.0.0

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.
Files changed (45) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +13 -91
  3. package/dist/adapter-BbqZKi2F.cjs +2 -0
  4. package/dist/adapter-BbqZKi2F.cjs.map +1 -0
  5. package/dist/adapter-DTS0CTC7.js +131 -0
  6. package/dist/adapter-DTS0CTC7.js.map +1 -0
  7. package/dist/config.cjs +6 -6
  8. package/dist/config.cjs.map +1 -1
  9. package/dist/config.d.cts +7 -0
  10. package/dist/config.d.ts +7 -0
  11. package/dist/config.mjs +129 -220
  12. package/dist/config.mjs.map +1 -1
  13. package/dist/create-Bo6VND8l.js +87 -0
  14. package/dist/create-Bo6VND8l.js.map +1 -0
  15. package/dist/create-Dn1m6fyc.cjs +2 -0
  16. package/dist/create-Dn1m6fyc.cjs.map +1 -0
  17. package/dist/index.cjs +1 -1
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +8 -0
  20. package/dist/index.d.ts +8 -0
  21. package/dist/index.mjs +6 -7
  22. package/dist/index.mjs.map +1 -1
  23. package/dist/node.cjs +1 -1
  24. package/dist/node.cjs.map +1 -1
  25. package/dist/node.mjs +3 -4
  26. package/dist/theme.cjs +1 -1
  27. package/dist/theme.cjs.map +1 -1
  28. package/dist/theme.d.cts +42 -1
  29. package/dist/theme.d.ts +42 -1
  30. package/dist/theme.mjs +9 -7
  31. package/dist/theme.mjs.map +1 -1
  32. package/dist/vitepress-locales-CwOlvAa0.cjs.map +1 -1
  33. package/dist/{vitepress-locales-DOhKs3q5.js → vitepress-locales-DYuP6i_x.js} +2 -3
  34. package/dist/{vitepress-locales-DOhKs3q5.js.map → vitepress-locales-DYuP6i_x.js.map} +1 -1
  35. package/package.json +24 -13
  36. package/dist/adapter-CAJNI6Sw.js +0 -127
  37. package/dist/adapter-CAJNI6Sw.js.map +0 -1
  38. package/dist/adapter-eYZZOC9d.cjs +0 -2
  39. package/dist/adapter-eYZZOC9d.cjs.map +0 -1
  40. package/dist/create-C_dXg23X.js +0 -81
  41. package/dist/create-C_dXg23X.js.map +0 -1
  42. package/dist/create-Cwu2djcO.cjs +0 -2
  43. package/dist/create-Cwu2djcO.cjs.map +0 -1
  44. package/dist/plugin/virtual-stubs/config.d.cts +0 -14
  45. package/dist/runtime/define-theme.d.cts +0 -39
package/dist/theme.d.cts CHANGED
@@ -2,6 +2,40 @@ import { Locale } from '@i18n-micro/types';
2
2
  import { PluralFunc } from '@i18n-micro/types';
3
3
  import { Theme } from 'vitepress';
4
4
  import { Translations } from '@i18n-micro/types';
5
+ import { VueI18nOptions } from '@i18n-micro/vue';
6
+
7
+ declare interface CreateI18nOptions {
8
+ locale: string;
9
+ fallbackLocale?: string;
10
+ locales?: Locale[];
11
+ defaultLocale?: string;
12
+ messages?: Record<string, Translations>;
13
+ /**
14
+ * Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
15
+ * Loaded from `locales/pages/**` when using `withI18n`.
16
+ */
17
+ routeMessages?: Record<string, Record<string, Translations>>;
18
+ plural?: PluralFunc;
19
+ missingWarn?: boolean;
20
+ numberFormats?: VueI18nOptions['numberFormats'];
21
+ datetimeFormats?: VueI18nOptions['datetimeFormats'];
22
+ timeZone?: string;
23
+ missingHandler?: (locale: string, key: string, routeName: string) => void;
24
+ /**
25
+ * Sync i18n locale from the VitePress URL path on every navigation.
26
+ * @default true
27
+ */
28
+ syncWithVitePress?: boolean;
29
+ /**
30
+ * Map VitePress locale keys to i18n codes (`root` → default locale code).
31
+ */
32
+ localeKeyToCode?: Record<string, string>;
33
+ /**
34
+ * VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher
35
+ * do not treat the base segment as content / double-prefix links.
36
+ */
37
+ base?: string;
38
+ }
5
39
 
6
40
  /**
7
41
  * Zero-boilerplate theme wiring. Requires `withI18n(...)` in `.vitepress/config`
@@ -27,10 +61,14 @@ export declare interface DefineI18nThemeOptions {
27
61
  */
28
62
  enhanceApp?: NonNullable<Theme['enhanceApp']>;
29
63
  /**
30
- * Overrides not serializable into `virtual:i18n-micro/config`.
64
+ * Overrides for this theme: `plural` and `missingHandler` cannot be serialized into
65
+ * `virtual:i18n-micro/config`; the formats and `timeZone` default to what `withI18n` got.
31
66
  */
32
67
  plural?: PluralFunc;
33
68
  missingHandler?: (locale: string, key: string, routeName: string) => void;
69
+ numberFormats?: CreateI18nOptions['numberFormats'];
70
+ datetimeFormats?: CreateI18nOptions['datetimeFormats'];
71
+ timeZone?: string;
34
72
  localeKeyToCode?: Record<string, string>;
35
73
  /**
36
74
  * Optional overrides (tests / advanced). Defaults come from `virtual:i18n-micro/*`
@@ -53,6 +91,9 @@ declare interface VirtualI18nConfig {
53
91
  localeKeyToCode: Record<string, string>;
54
92
  /** VitePress `site.base` (normalized, trailing slash preserved from config). */
55
93
  base?: string;
94
+ numberFormats?: CreateI18nOptions['numberFormats'];
95
+ datetimeFormats?: CreateI18nOptions['datetimeFormats'];
96
+ timeZone?: string;
56
97
  }
57
98
 
58
99
  export { }
package/dist/theme.d.ts CHANGED
@@ -2,6 +2,40 @@ import { Locale } from '@i18n-micro/types';
2
2
  import { PluralFunc } from '@i18n-micro/types';
3
3
  import { Theme } from 'vitepress';
4
4
  import { Translations } from '@i18n-micro/types';
5
+ import { VueI18nOptions } from '@i18n-micro/vue';
6
+
7
+ declare interface CreateI18nOptions {
8
+ locale: string;
9
+ fallbackLocale?: string;
10
+ locales?: Locale[];
11
+ defaultLocale?: string;
12
+ messages?: Record<string, Translations>;
13
+ /**
14
+ * Page-scoped dictionaries keyed by route name (`guide-demo`), then locale.
15
+ * Loaded from `locales/pages/**` when using `withI18n`.
16
+ */
17
+ routeMessages?: Record<string, Record<string, Translations>>;
18
+ plural?: PluralFunc;
19
+ missingWarn?: boolean;
20
+ numberFormats?: VueI18nOptions['numberFormats'];
21
+ datetimeFormats?: VueI18nOptions['datetimeFormats'];
22
+ timeZone?: string;
23
+ missingHandler?: (locale: string, key: string, routeName: string) => void;
24
+ /**
25
+ * Sync i18n locale from the VitePress URL path on every navigation.
26
+ * @default true
27
+ */
28
+ syncWithVitePress?: boolean;
29
+ /**
30
+ * Map VitePress locale keys to i18n codes (`root` → default locale code).
31
+ */
32
+ localeKeyToCode?: Record<string, string>;
33
+ /**
34
+ * VitePress `site.base`. Needed so SSG paths (`withBase`) and lang switcher
35
+ * do not treat the base segment as content / double-prefix links.
36
+ */
37
+ base?: string;
38
+ }
5
39
 
6
40
  /**
7
41
  * Zero-boilerplate theme wiring. Requires `withI18n(...)` in `.vitepress/config`
@@ -27,10 +61,14 @@ export declare interface DefineI18nThemeOptions {
27
61
  */
28
62
  enhanceApp?: NonNullable<Theme['enhanceApp']>;
29
63
  /**
30
- * Overrides not serializable into `virtual:i18n-micro/config`.
64
+ * Overrides for this theme: `plural` and `missingHandler` cannot be serialized into
65
+ * `virtual:i18n-micro/config`; the formats and `timeZone` default to what `withI18n` got.
31
66
  */
32
67
  plural?: PluralFunc;
33
68
  missingHandler?: (locale: string, key: string, routeName: string) => void;
69
+ numberFormats?: CreateI18nOptions['numberFormats'];
70
+ datetimeFormats?: CreateI18nOptions['datetimeFormats'];
71
+ timeZone?: string;
34
72
  localeKeyToCode?: Record<string, string>;
35
73
  /**
36
74
  * Optional overrides (tests / advanced). Defaults come from `virtual:i18n-micro/*`
@@ -53,6 +91,9 @@ declare interface VirtualI18nConfig {
53
91
  localeKeyToCode: Record<string, string>;
54
92
  /** VitePress `site.base` (normalized, trailing slash preserved from config). */
55
93
  base?: string;
94
+ numberFormats?: CreateI18nOptions['numberFormats'];
95
+ datetimeFormats?: CreateI18nOptions['datetimeFormats'];
96
+ timeZone?: string;
56
97
  }
57
98
 
58
99
  export { }
package/dist/theme.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import { n as e } from "./adapter-CAJNI6Sw.js";
2
- import { t } from "./create-C_dXg23X.js";
1
+ import { t as e } from "./create-Bo6VND8l.js";
2
+ import { n as t } from "./adapter-DTS0CTC7.js";
3
3
  import { config as n } from "virtual:i18n-micro/config";
4
4
  import { messages as r, routeMessages as i } from "virtual:i18n-micro/messages";
5
- //#region src/runtime/define-theme.ts
5
+ // src/runtime/define-theme.ts
6
6
  function a(a, o = {}) {
7
7
  let s = o.enhanceApp, c = a.enhanceApp, l = /* @__PURE__ */ new WeakMap();
8
8
  return {
@@ -10,8 +10,8 @@ function a(a, o = {}) {
10
10
  async enhanceApp(a) {
11
11
  let u = l.get(a.app);
12
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({
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 = t(a.router.route.path, f, s.defaultLocale, p, s.base);
14
+ u = e({
15
15
  locale: m,
16
16
  defaultLocale: s.defaultLocale,
17
17
  fallbackLocale: s.fallbackLocale,
@@ -23,14 +23,16 @@ function a(a, o = {}) {
23
23
  localeKeyToCode: p,
24
24
  base: s.base,
25
25
  plural: o.plural,
26
- missingHandler: o.missingHandler
26
+ missingHandler: o.missingHandler,
27
+ numberFormats: o.numberFormats ?? s.numberFormats,
28
+ datetimeFormats: o.datetimeFormats ?? s.datetimeFormats,
29
+ timeZone: o.timeZone ?? s.timeZone
27
30
  }), l.set(a.app, u);
28
31
  }
29
32
  u.enhanceApp(a), c && await c(a), s && await s(a), u.enhanceApp(a);
30
33
  }
31
34
  };
32
35
  }
33
- //#endregion
34
36
  export { a as defineI18nTheme };
35
37
 
36
38
  //# sourceMappingURL=theme.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.mjs","names":["config","virtualConfig","messages","virtualMessages","routeMessages","virtualRouteMessages","getLocaleFromPath","defineI18nTheme","userEnhance","options","baseEnhance","base","byApp","installed","ctx","config$1","config","messages$1","messages","routeMessages$1","routeMessages","localeCodes","l","localeKeyToCode","initialLocale","createI18n"],"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,SAAgBO,EAAiC,GAAS,IAAkC,CAAC,GAAM;CACjG,IAAMC,IAAcC,EAAQ,YACtBC,IAAcC,EAAK,YAGnBC,oBAAQ,IAAI,QAAkC;CAEpD,OAAO;EACL,GAAGD;EACH,MAAM,WAAW,GAAwB;GACvC,IAAIE,IAAYD,EAAM,IAAIE,EAAI,GAAG;GACjC,IAAI,CAACD,GAAW;IAEd,IAAMb,IAAUS,EAAQ,UAAUR,GAC5BC,IAAWO,EAAQ,YAAaN,GAChCC,IAAgBK,EAAQ,iBAAkBJ,GAE1CgB,IAAcrB,EAAO,YAAY,SAASA,EAAO,cAAcA,EAAO,QAAQ,KAAK,MAAMsB,EAAE,IAAI,GAC/FC,IAAkBd,EAAQ,mBAAmBT,EAAO,iBACpDwB,IAAgBlB,EAAkBQ,EAAI,OAAO,MAAM,MAAMO,GAAarB,EAAO,eAAeuB,GAAiBvB,EAAO,IAAI;IAgB9H,AAdA,IAAYyB,EAAW;KACrB,QAAQD;KACR,eAAexB,EAAO;KACtB,gBAAgBA,EAAO;KACvB,SAASA,EAAO;KAChB,UAAAiB;KACA,eAAAE;KACA,aAAanB,EAAO,eAAe,KAAA;KACnC,mBAAmBA,EAAO;KAC1B;KACA,MAAMA,EAAO;KACb,QAAQS,EAAQ;KAChB,gBAAgBA,EAAQ;IAC1B,CAAC,GACDG,EAAM,IAAIE,EAAI,KAAKD,CAAS;GAC9B;GAOA,AAJAA,EAAU,WAAWC,CAA4D,GAC7EJ,KAAa,MAAMA,EAAYI,CAAG,GAClCN,KAAa,MAAMA,EAAYM,CAAG,GAEtCD,EAAU,WAAWC,CAA4D;EACnF;CACF;AACF"}
1
+ {"version":3,"file":"theme.mjs","names":["config","virtualConfig","messages","virtualMessages","routeMessages","virtualRouteMessages","createI18n","getLocaleFromPath","defineI18nTheme","userEnhance","options","baseEnhance","base","byApp","installed","ctx","config$1","config","messages$1","messages","routeMessages$1","routeMessages","localeCodes","l","localeKeyToCode","initialLocale"],"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 CreateI18nOptions, 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 for this theme: `plural` and `missingHandler` cannot be serialized into\n * `virtual:i18n-micro/config`; the formats and `timeZone` default to what `withI18n` got.\n */\n plural?: PluralFunc\n missingHandler?: (locale: string, key: string, routeName: string) => void\n numberFormats?: CreateI18nOptions['numberFormats']\n datetimeFormats?: CreateI18nOptions['datetimeFormats']\n timeZone?: string\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 numberFormats: options.numberFormats ?? config.numberFormats,\n datetimeFormats: options.datetimeFormats ?? config.datetimeFormats,\n timeZone: options.timeZone ?? config.timeZone,\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":";;;;;AAkDA,SAAgBQ,EAAiC,GAAS,IAAkC,CAAC,GAAM;CACjG,IAAMC,IAAcC,EAAQ,YACtBC,IAAcC,EAAK,YAGnBC,oBAAQ,IAAI,QAAkC;CAEpD,OAAO;EACL,GAAGD;EACH,MAAM,WAAW,GAAwB;GACvC,IAAIE,IAAYD,EAAM,IAAIE,EAAI,GAAG;GACjC,IAAI,CAACD,GAAW;IAEd,IAAMd,IAAUU,EAAQ,UAAUT,GAC5BC,IAAWQ,EAAQ,YAAaP,GAChCC,IAAgBM,EAAQ,iBAAkBL,GAE1CiB,IAActB,EAAO,YAAY,SAASA,EAAO,cAAcA,EAAO,QAAQ,KAAK,MAAMuB,EAAE,IAAI,GAC/FC,IAAkBd,EAAQ,mBAAmBV,EAAO,iBACpDyB,IAAgBlB,EAAkBQ,EAAI,OAAO,MAAM,MAAMO,GAAatB,EAAO,eAAewB,GAAiBxB,EAAO,IAAI;IAmB9H,AAjBA,IAAYM,EAAW;KACrB,QAAQmB;KACR,eAAezB,EAAO;KACtB,gBAAgBA,EAAO;KACvB,SAASA,EAAO;KAChB,UAAAkB;KACA,eAAAE;KACA,aAAapB,EAAO,eAAe,KAAA;KACnC,mBAAmBA,EAAO;KAC1B;KACA,MAAMA,EAAO;KACb,QAAQU,EAAQ;KAChB,gBAAgBA,EAAQ;KACxB,eAAeA,EAAQ,iBAAiBV,EAAO;KAC/C,iBAAiBU,EAAQ,mBAAmBV,EAAO;KACnD,UAAUU,EAAQ,YAAYV,EAAO;IACvC,CAAC,GACDa,EAAM,IAAIE,EAAI,KAAKD,CAAS;GAC9B;GAOA,AAJAA,EAAU,WAAWC,CAA4D,GAC7EJ,KAAa,MAAMA,EAAYI,CAAG,GAClCN,KAAa,MAAMA,EAAYM,CAAG,GAEtCD,EAAU,WAAWC,CAA4D;EACnF;CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"vitepress-locales-CwOlvAa0.cjs","names":["localeKeyFromCode","key","mapped","localeKeyToCode","code","defaultLocale","buildVitePressLocales","options","result","loc","locales","urlKey","entry","fallback","l"],"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,SAASA,EAAkB,EAAc,EAAuB,EAAiD,CAC/G,IAAK,GAAM,CAACC,EAAKC,KAAW,OAAO,QAAQC,CAAe,EACxD,GAAID,IAAWE,EAAM,OAAOH,EAG9B,OADIG,IAASC,EAAsB,OAC5BD,CACT,CAMA,SAAgBE,EACd,EACA,EACA,EAAwC,CAAC,EACH,CACtC,IAAMH,EAAkBI,EAAQ,iBAAmB,CAAC,EAC9CC,EAA+C,CAAC,EAEtD,IAAK,IAAMC,KAAOC,EAAS,CACzB,IAAMT,EAAMD,EAAkBS,EAAI,KAAMJ,EAAeF,CAAe,EAChEQ,EAASV,IAAQ,OAASQ,EAAI,KAAOR,EACrCW,EAA8B,CAClC,MAAOH,EAAI,aAAeA,EAAI,KAAK,YAAY,EAC/C,KAAMA,EAAI,KAAOA,EAAI,IACvB,EACIR,IAAQ,SACV,EAAM,KAAO,IAAIU,EAAO,IAE1B,EAAOV,GAAOW,CAChB,CAEA,GAAI,CAACJ,EAAO,KAAM,CAChB,IAAMK,EAAWH,EAAQ,KAAM,GAAMI,EAAE,OAAST,CAAa,GAAKK,EAAQ,GACtEG,IACF,EAAO,KAAO,CACZ,MAAOA,EAAS,aAAeA,EAAS,KAAK,YAAY,EACzD,KAAMA,EAAS,KAAOA,EAAS,IACjC,EAEJ,CAEA,OAAOL,CACT"}
1
+ {"version":3,"file":"vitepress-locales-CwOlvAa0.cjs","names":["localeKeyFromCode","key","mapped","localeKeyToCode","code","defaultLocale","buildVitePressLocales","options","result","loc","locales","urlKey","entry","fallback","l"],"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,SAASA,EAAkB,EAAc,EAAuB,EAAiD,CAC/G,IAAK,GAAM,CAACC,EAAKC,KAAW,OAAO,QAAQC,CAAe,EACxD,GAAID,IAAWE,EAAM,OAAOH,EAG9B,OADIG,IAASC,EAAsB,OAC5BD,CACT,CAMA,SAAgBE,EACd,EACA,EACA,EAAwC,CAAC,EACH,CACtC,IAAMH,EAAkBI,EAAQ,iBAAmB,CAAC,EAC9CC,EAA+C,CAAC,EAEtD,IAAK,IAAMC,KAAOC,EAAS,CACzB,IAAMT,EAAMD,EAAkBS,EAAI,KAAMJ,EAAeF,CAAe,EAChEQ,EAASV,IAAQ,OAASQ,EAAI,KAAOR,EACrCW,EAA8B,CAClC,MAAOH,EAAI,aAAeA,EAAI,KAAK,YAAY,EAC/C,KAAMA,EAAI,KAAOA,EAAI,IACvB,EACIR,IAAQ,SACV,EAAM,KAAO,IAAIU,EAAO,IAE1B,EAAOV,GAAOW,CAChB,CAEA,GAAI,CAACJ,EAAO,KAAM,CAChB,IAAMK,EAAWH,EAAQ,KAAM,GAAMI,EAAE,OAAST,CAAa,GAAKK,EAAQ,GACtEG,IACF,EAAO,KAAO,CACZ,MAAOA,EAAS,aAAeA,EAAS,KAAK,YAAY,EACzD,KAAMA,EAAS,KAAOA,EAAS,IACjC,EAEJ,CAEA,OAAOL,CACT,C"}
@@ -1,4 +1,4 @@
1
- //#region src/plugin/vitepress-locales.ts
1
+ // src/plugin/vitepress-locales.ts
2
2
  function e(e, t, n) {
3
3
  for (let [t, r] of Object.entries(n)) if (r === e) return t;
4
4
  return e === t ? "root" : e;
@@ -21,7 +21,6 @@ function t(t, n, r = {}) {
21
21
  }
22
22
  return a;
23
23
  }
24
- //#endregion
25
24
  export { t };
26
25
 
27
- //# sourceMappingURL=vitepress-locales-DOhKs3q5.js.map
26
+ //# sourceMappingURL=vitepress-locales-DYuP6i_x.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vitepress-locales-DOhKs3q5.js","names":["localeKeyFromCode","key","mapped","localeKeyToCode","code","defaultLocale","buildVitePressLocales","options","result","loc","locales","urlKey","entry","fallback","l"],"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,SAASA,EAAkB,GAAc,GAAuB,GAAiD;CAC/G,KAAK,IAAM,CAACC,GAAKC,MAAW,OAAO,QAAQC,CAAe,GACxD,IAAID,MAAWE,GAAM,OAAOH;CAG9B,OADIG,MAASC,IAAsB,SAC5BD;AACT;AAMA,SAAgBE,EACd,GACA,GACA,IAAwC,CAAC,GACH;CACtC,IAAMH,IAAkBI,EAAQ,mBAAmB,CAAC,GAC9CC,IAA+C,CAAC;CAEtD,KAAK,IAAMC,KAAOC,GAAS;EACzB,IAAMT,IAAMD,EAAkBS,EAAI,MAAMJ,GAAeF,CAAe,GAChEQ,IAASV,MAAQ,SAASQ,EAAI,OAAOR,GACrCW,IAA8B;GAClC,OAAOH,EAAI,eAAeA,EAAI,KAAK,YAAY;GAC/C,MAAMA,EAAI,OAAOA,EAAI;EACvB;EAIA,AAHIR,MAAQ,WACV,EAAM,OAAO,IAAIU,EAAO,KAE1B,EAAOV,KAAOW;CAChB;CAEA,IAAI,CAACJ,EAAO,MAAM;EAChB,IAAMK,IAAWH,EAAQ,MAAM,MAAMI,EAAE,SAAST,CAAa,KAAKK,EAAQ;EAC1E,AAAIG,MACF,EAAO,OAAO;GACZ,OAAOA,EAAS,eAAeA,EAAS,KAAK,YAAY;GACzD,MAAMA,EAAS,OAAOA,EAAS;EACjC;CAEJ;CAEA,OAAOL;AACT"}
1
+ {"version":3,"file":"vitepress-locales-DYuP6i_x.js","names":["localeKeyFromCode","key","mapped","localeKeyToCode","code","defaultLocale","buildVitePressLocales","options","result","loc","locales","urlKey","entry","fallback","l"],"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,SAASA,EAAkB,GAAc,GAAuB,GAAiD;CAC/G,KAAK,IAAM,CAACC,GAAKC,MAAW,OAAO,QAAQC,CAAe,GACxD,IAAID,MAAWE,GAAM,OAAOH;CAG9B,OADIG,MAASC,IAAsB,SAC5BD;AACT;AAMA,SAAgBE,EACd,GACA,GACA,IAAwC,CAAC,GACH;CACtC,IAAMH,IAAkBI,EAAQ,mBAAmB,CAAC,GAC9CC,IAA+C,CAAC;CAEtD,KAAK,IAAMC,KAAOC,GAAS;EACzB,IAAMT,IAAMD,EAAkBS,EAAI,MAAMJ,GAAeF,CAAe,GAChEQ,IAASV,MAAQ,SAASQ,EAAI,OAAOR,GACrCW,IAA8B;GAClC,OAAOH,EAAI,eAAeA,EAAI,KAAK,YAAY;GAC/C,MAAMA,EAAI,OAAOA,EAAI;EACvB;EAIA,AAHIR,MAAQ,WACV,EAAM,OAAO,IAAIU,EAAO,KAE1B,EAAOV,KAAOW;CAChB;CAEA,IAAI,CAACJ,EAAO,MAAM;EAChB,IAAMK,IAAWH,EAAQ,MAAM,MAAMI,EAAE,SAAST,CAAa,KAAKK,EAAQ;EAC1E,AAAIG,MACF,EAAO,OAAO;GACZ,OAAOA,EAAS,eAAeA,EAAS,KAAK,YAAY;GACzD,MAAMA,EAAS,OAAOA,EAAS;EACjC;CAEJ;CAEA,OAAOL;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/vitepress",
3
- "version": "1.1.13",
3
+ "version": "2.0.0",
4
4
  "description": "VitePress bindings for i18n-micro — runtime dictionaries, MD components, and locale switcher.",
5
5
  "keywords": [
6
6
  "documentation",
@@ -15,6 +15,11 @@
15
15
  "url": "https://github.com/s00d/nuxt-i18n-micro/issues"
16
16
  },
17
17
  "license": "MIT",
18
+ "author": {
19
+ "name": "s00d",
20
+ "email": "Virus191288@gmail.com",
21
+ "url": "https://s00d.github.io/"
22
+ },
18
23
  "repository": {
19
24
  "type": "git",
20
25
  "url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
@@ -84,28 +89,34 @@
84
89
  "access": "public"
85
90
  },
86
91
  "dependencies": {
87
- "@i18n-micro/types": "^1.2.18",
88
- "@i18n-micro/node": "^1.2.21",
89
- "@i18n-micro/core": "^1.3.22",
90
- "@i18n-micro/vue": "^1.4.10",
91
- "@i18n-micro/utils": "^1.0.27"
92
+ "@i18n-micro/node": "^2.0.0",
93
+ "@i18n-micro/core": "^2.0.0",
94
+ "@i18n-micro/utils": "^2.0.0",
95
+ "@i18n-micro/types": "^2.0.0",
96
+ "@i18n-micro/vue": "^2.0.0"
92
97
  },
93
98
  "devDependencies": {
94
99
  "@types/node": "^22.19.0",
95
- "publint": "^0.3.24",
100
+ "publint": "^0.3.25",
96
101
  "typescript": "6.0.3",
97
- "vite": "^8.3.1",
98
- "vite-plugin-dts": "^5.1.1",
102
+ "vite": "^8.3.5",
103
+ "vite-plugin-dts": "^5.1.2",
99
104
  "vitepress": "^2.0.0-alpha.20",
100
- "vitest": "^5.0.2",
101
- "vue": "^3.5.43"
105
+ "vitest": "^5.1.0",
106
+ "vue": "^3.5.44"
102
107
  },
103
108
  "peerDependencies": {
109
+ "vite": ">=5.4.0",
104
110
  "vitepress": ">=1.0.0 || >=2.0.0-alpha.0",
105
- "vue": "^3.5.43"
111
+ "vue": "^3.3.0"
112
+ },
113
+ "peerDependenciesMeta": {
114
+ "vite": {
115
+ "optional": true
116
+ }
106
117
  },
107
118
  "engines": {
108
- "node": ">=18"
119
+ "node": ">=20"
109
120
  },
110
121
  "scripts": {
111
122
  "build": "vite build",
@@ -1,127 +0,0 @@
1
- import { defineComponent as e, h as t } from "vue";
2
- //#region src/router/adapter.ts
3
- function n(e) {
4
- let t = e.indexOf("#"), n = e.indexOf("?"), r = e.length;
5
- return t >= 0 && (r = Math.min(r, t)), n >= 0 && (r = Math.min(r, n)), {
6
- pathname: e.slice(0, r) || "/",
7
- extras: e.slice(r)
8
- };
9
- }
10
- function r(e, t) {
11
- if (!t || t === "/") return e;
12
- let r = t.endsWith("/") ? t.slice(0, -1) : t;
13
- if (!r) return e;
14
- let { pathname: i, extras: a } = n(e);
15
- return i === r ? `/${a}` : i.startsWith(`${r}/`) ? `${i.slice(r.length) || "/"}${a}` : e;
16
- }
17
- function i(e, t, n = {}) {
18
- let r = (e) => {
19
- for (let [t, r] of Object.entries(n)) if (r === e) return t;
20
- return e === t ? "root" : e;
21
- }, i = /* @__PURE__ */ new Map();
22
- for (let n of e) {
23
- if (n === t) continue;
24
- let e = r(n), a = e === "root" ? n : e;
25
- i.set(a, n), a !== n && i.set(n, n);
26
- }
27
- return i;
28
- }
29
- function a(e, t, a, o = {}, s) {
30
- let { pathname: c } = n(r(e, s)), l = c.split("/").filter(Boolean)[0];
31
- return l === void 0 ? a : i(t, a, o).get(l) ?? a;
32
- }
33
- function o(e, t, a, o = {}, s) {
34
- let { pathname: c } = n(r(e, s)), l = c.split("/").filter(Boolean), u = l[0];
35
- return u !== void 0 && (a === void 0 ? t.includes(u) && l.shift() : i(t, a, o).has(u) && l.shift()), l.length === 0 ? "index" : l.join("-").replace(/\.html$/, "");
36
- }
37
- function s(n) {
38
- return e({
39
- name: "VitePressI18nLink",
40
- props: {
41
- to: {
42
- type: String,
43
- required: !0
44
- },
45
- style: {
46
- type: Object,
47
- default: void 0
48
- }
49
- },
50
- setup(e, { slots: r }) {
51
- return () => t("a", {
52
- href: e.to,
53
- style: e.style,
54
- onClick: (t) => {
55
- t.defaultPrevented || t.button === 0 && (t.metaKey || t.altKey || t.ctrlKey || t.shiftKey || (t.preventDefault(), n ? n(e.to) : typeof window < "u" && window.location.assign(e.to)));
56
- }
57
- }, r.default?.());
58
- }
59
- });
60
- }
61
- function c(e) {
62
- let { locales: t, defaultLocale: c, localeKeyToCode: l = {}, base: u, getPath: d, go: f } = e, p = t.map((e) => e.code), m = { ...l }, h = i(p, c, m), g = [...h.keys()], _ = u && u !== "/" ? u : void 0, v = (e) => m[e] ? m[e] : e === "root" ? c : e, y = (e) => {
63
- for (let [t, n] of Object.entries(m)) if (n === e) return t;
64
- return e === c ? "root" : e;
65
- }, b = (e) => {
66
- if (e === c) return null;
67
- let t = y(e);
68
- return t === "root" ? e : t;
69
- }, x = (e) => {
70
- let t = e === "/" || e.endsWith("/"), n = e.split("/").filter(Boolean), r = n[0];
71
- return r !== void 0 && h.has(r) && n.shift(), {
72
- segments: n,
73
- hadTrailingSlash: t
74
- };
75
- }, S = (e) => {
76
- let { pathname: t, extras: i } = n(r(e, _)), { segments: a, hadTrailingSlash: o } = x(t), s = a.length === 0 ? "/" : `/${a.join("/")}`;
77
- return s !== "/" && o && (s += "/"), `${s}${i}`;
78
- }, C = (e, t) => {
79
- let { pathname: i, extras: a } = n(r(e, _)), { segments: o, hadTrailingSlash: s } = x(i), c = b(t);
80
- c && o.unshift(c);
81
- let l = o.length === 0 ? "/" : `/${o.join("/")}`;
82
- return l !== "/" && s && (l += "/"), `${l}${a}`;
83
- }, w = (e, t) => C(e, t), T = (e, t) => {
84
- let n = typeof e == "string" ? e : e.path || "/";
85
- return C(n, t);
86
- }, E = (e, t = !1) => {
87
- if (f) {
88
- f(e, { replace: t });
89
- return;
90
- }
91
- typeof window < "u" && (t ? window.location.replace(e) : window.location.assign(e));
92
- }, D = () => d ? d() : typeof window < "u" ? window.location.pathname + window.location.search + window.location.hash : "/";
93
- return {
94
- localeCodes: p,
95
- defaultLocale: c,
96
- localeKeyToCode: m,
97
- urlPrefixes: g,
98
- base: _,
99
- codeFromLocaleKey: v,
100
- localeKeyFromCode: y,
101
- getLocaleFromPath: (e) => a(e, p, c, m, _),
102
- switchLocalePath: w,
103
- localizePath: C,
104
- removeLocaleFromPath: S,
105
- routeNameFromPath: (e) => o(e, p, c, m, _),
106
- linkComponent: s(f),
107
- getCurrentPath: () => r(D(), _),
108
- push: (e) => {
109
- E(e.path, !1);
110
- },
111
- replace: (e) => {
112
- E(e.path, !0);
113
- },
114
- resolvePath: T,
115
- getRoute: () => {
116
- let e = r(D(), _), t = typeof window < "u" ? new URL(e, window.location.origin) : new URL(e, "http://localhost");
117
- return {
118
- fullPath: t.pathname + t.search + t.hash,
119
- query: Object.fromEntries(t.searchParams)
120
- };
121
- }
122
- };
123
- }
124
- //#endregion
125
- export { r as i, a as n, o as r, c as t };
126
-
127
- //# sourceMappingURL=adapter-CAJNI6Sw.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter-CAJNI6Sw.js","names":["splitPathAndExtras","hashIndex","path","queryIndex","cut","stripSiteBase","base","normalized","pathname","extras","buildUrlPrefixToCode","keyFromCode","key","mapped","localeKeyToCode","code","defaultLocale","prefixToCode","localeCodes","urlKey","getLocaleFromPath","first","routeNameFromPath","segments","createVitePressLinkComponent","defineComponent","h","props","e","go","slots","createVitePressRouterAdapter","options","locales","loc","localeKeyToCodeSnapshot","urlPrefixes","siteBase","codeFromLocaleKey","localeKey","localeKeyFromCode","urlPrefixForCode","stripPrefix","hadTrailingSlash","removeLocaleFromPath","clean","localizePath","prefix","locale","localized","switchLocalePath","newLocale","resolvePath","to","navigate","href","replace","currentFullPath","getPath","target","url"],"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"],"mappings":";;AA8DA,SAASA,EAAmB,GAAoD;CAC9E,IAAMC,IAAYC,EAAK,QAAQ,GAAG,GAC5BC,IAAaD,EAAK,QAAQ,GAAG,GAC/BE,IAAMF,EAAK;CAGf,OAFID,KAAa,MAAG,IAAM,KAAK,IAAIG,GAAKH,CAAS,IAC7CE,KAAc,MAAG,IAAM,KAAK,IAAIC,GAAKD,CAAU,IAC5C;EACL,UAAUD,EAAK,MAAM,GAAGE,CAAG,KAAK;EAChC,QAAQF,EAAK,MAAME,CAAG;CACxB;AACF;AAMA,SAAgBC,EAAc,GAAc,GAAuB;CACjE,IAAI,CAACC,KAAQA,MAAS,KAAK,OAAOJ;CAClC,IAAMK,IAAaD,EAAK,SAAS,GAAG,IAAIA,EAAK,MAAM,GAAG,EAAE,IAAIA;CAC5D,IAAI,CAACC,GAAY,OAAOL;CACxB,IAAM,EAAE,aAAU,cAAWF,EAAmBE,CAAI;CAKpD,OAJIM,MAAaD,IAAmB,IAAIE,MACpCD,EAAS,WAAW,GAAGD,EAAW,EAAE,IAC/B,GAAGC,EAAS,MAAMD,EAAW,MAAM,KAAK,MAAME,MAEhDP;AACT;AAMA,SAAgBQ,EACd,GACA,GACA,IAA0C,CAAC,GACtB;CACrB,IAAMC,KAAe,MAAyB;EAC5C,KAAK,IAAM,CAACC,GAAKC,MAAW,OAAO,QAAQC,CAAe,GACxD,IAAID,MAAWE,GAAM,OAAOH;EAG9B,OADIG,MAASC,IAAsB,SAC5BD;CACT,GAEME,oBAAe,IAAI,IAAoB;CAC7C,KAAK,IAAMF,KAAQG,GAAa;EAC9B,IAAIH,MAASC,GAAe;EAC5B,IAAMJ,IAAMD,EAAYI,CAAI,GACtBI,IAASP,MAAQ,SAASG,IAAOH;EAEvC,AADAK,EAAa,IAAIE,GAAQJ,CAAI,GACzBI,MAAWJ,KAAME,EAAa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GAAGpB,CAAQ;EAC/D,OAAO,MAA6B;GAClC,EAASsB,EAAO,MAAM,EAAK;EAC7B;EACA,UAAU,MAA6B;GACrC,EAASA,EAAO,MAAM,EAAI;EAC5B;EACA;EACA,gBAAgB;GACd,IAAMzD,IAAOG,EAAcoD,EAAgB,GAAGpB,CAAQ,GAChDuB,IAAM,OAAO,SAAW,MAAc,IAAI,IAAI1D,GAAM,OAAO,SAAS,MAAM,IAAI,IAAI,IAAIA,GAAM,kBAAkB;GACpH,OAAO;IACL,UAAU0D,EAAI,WAAWA,EAAI,SAASA,EAAI;IAC1C,OAAO,OAAO,YAAYA,EAAI,YAAY;GAC5C;EACF;CACF;AACF"}
@@ -1,2 +0,0 @@
1
- let e=require("vue");function t(e){let t=e.indexOf(`#`),n=e.indexOf(`?`),r=e.length;return t>=0&&(r=Math.min(r,t)),n>=0&&(r=Math.min(r,n)),{pathname:e.slice(0,r)||`/`,extras:e.slice(r)}}function n(e,n){if(!n||n===`/`)return e;let r=n.endsWith(`/`)?n.slice(0,-1):n;if(!r)return e;let{pathname:i,extras:a}=t(e);return i===r?`/${a}`:i.startsWith(`${r}/`)?`${i.slice(r.length)||`/`}${a}`:e}function r(e,t,n={}){let r=e=>{for(let[t,r]of Object.entries(n))if(r===e)return t;return e===t?`root`:e},i=new Map;for(let n of e){if(n===t)continue;let e=r(n),a=e===`root`?n:e;i.set(a,n),a!==n&&i.set(n,n)}return i}function i(e,i,a,o={},s){let{pathname:c}=t(n(e,s)),l=c.split(`/`).filter(Boolean)[0];return l===void 0?a:r(i,a,o).get(l)??a}function a(e,i,a,o={},s){let{pathname:c}=t(n(e,s)),l=c.split(`/`).filter(Boolean),u=l[0];return u!==void 0&&(a===void 0?i.includes(u)&&l.shift():r(i,a,o).has(u)&&l.shift()),l.length===0?`index`:l.join(`-`).replace(/\.html$/,``)}function o(t){return(0,e.defineComponent)({name:`VitePressI18nLink`,props:{to:{type:String,required:!0},style:{type:Object,default:void 0}},setup(n,{slots:r}){return()=>(0,e.h)(`a`,{href:n.to,style:n.style,onClick:e=>{e.defaultPrevented||e.button===0&&(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||(e.preventDefault(),t?t(n.to):typeof window<`u`&&window.location.assign(n.to)))}},r.default?.())}})}function s(e){let{locales:s,defaultLocale:c,localeKeyToCode:l={},base:u,getPath:d,go:f}=e,p=s.map(e=>e.code),m={...l},h=r(p,c,m),g=[...h.keys()],_=u&&u!==`/`?u:void 0,v=e=>m[e]?m[e]:e===`root`?c:e,y=e=>{for(let[t,n]of Object.entries(m))if(n===e)return t;return e===c?`root`:e},b=e=>{if(e===c)return null;let t=y(e);return t===`root`?e:t},x=e=>{let t=e===`/`||e.endsWith(`/`),n=e.split(`/`).filter(Boolean),r=n[0];return r!==void 0&&h.has(r)&&n.shift(),{segments:n,hadTrailingSlash:t}},S=e=>{let{pathname:r,extras:i}=t(n(e,_)),{segments:a,hadTrailingSlash:o}=x(r),s=a.length===0?`/`:`/${a.join(`/`)}`;return s!==`/`&&o&&(s+=`/`),`${s}${i}`},C=(e,r)=>{let{pathname:i,extras:a}=t(n(e,_)),{segments:o,hadTrailingSlash:s}=x(i),c=b(r);c&&o.unshift(c);let l=o.length===0?`/`:`/${o.join(`/`)}`;return l!==`/`&&s&&(l+=`/`),`${l}${a}`},w=(e,t)=>C(e,t),T=(e,t)=>{let n=typeof e==`string`?e:e.path||`/`;return C(n,t)},E=(e,t=!1)=>{if(f){f(e,{replace:t});return}typeof window<`u`&&(t?window.location.replace(e):window.location.assign(e))},D=()=>d?d():typeof window<`u`?window.location.pathname+window.location.search+window.location.hash:`/`;return{localeCodes:p,defaultLocale:c,localeKeyToCode:m,urlPrefixes:g,base:_,codeFromLocaleKey:v,localeKeyFromCode:y,getLocaleFromPath:e=>i(e,p,c,m,_),switchLocalePath:w,localizePath:C,removeLocaleFromPath:S,routeNameFromPath:e=>a(e,p,c,m,_),linkComponent:o(f),getCurrentPath:()=>n(D(),_),push:e=>{E(e.path,!1)},replace:e=>{E(e.path,!0)},resolvePath:T,getRoute:()=>{let e=n(D(),_),t=typeof window<`u`?new URL(e,window.location.origin):new URL(e,`http://localhost`);return{fullPath:t.pathname+t.search+t.hash,query:Object.fromEntries(t.searchParams)}}}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return s}});
2
- //# sourceMappingURL=adapter-eYZZOC9d.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"adapter-eYZZOC9d.cjs","names":["defineComponent","h","vue","splitPathAndExtras","hashIndex","path","queryIndex","cut","stripSiteBase","base","normalized","pathname","extras","buildUrlPrefixToCode","keyFromCode","key","mapped","localeKeyToCode","code","defaultLocale","prefixToCode","localeCodes","urlKey","getLocaleFromPath","first","routeNameFromPath","segments","createVitePressLinkComponent","props","go","slots","createVitePressRouterAdapter","options","locales","loc","localeKeyToCodeSnapshot","urlPrefixes","siteBase","codeFromLocaleKey","localeKey","localeKeyFromCode","urlPrefixForCode","stripPrefix","hadTrailingSlash","removeLocaleFromPath","clean","localizePath","prefix","locale","localized","switchLocalePath","newLocale","resolvePath","to","navigate","href","replace","currentFullPath","getPath","target","url"],"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"],"mappings":"qBA8DA,SAASG,EAAmB,EAAoD,CAC9E,IAAMC,EAAYC,EAAK,QAAQ,GAAG,EAC5BC,EAAaD,EAAK,QAAQ,GAAG,EAC/BE,EAAMF,EAAK,OAGf,OAFID,GAAa,IAAG,EAAM,KAAK,IAAIG,EAAKH,CAAS,GAC7CE,GAAc,IAAG,EAAM,KAAK,IAAIC,EAAKD,CAAU,GAC5C,CACL,SAAUD,EAAK,MAAM,EAAGE,CAAG,GAAK,IAChC,OAAQF,EAAK,MAAME,CAAG,CACxB,CACF,CAMA,SAAgBC,EAAc,EAAc,EAAuB,CACjE,GAAI,CAACC,GAAQA,IAAS,IAAK,OAAOJ,EAClC,IAAMK,EAAaD,EAAK,SAAS,GAAG,EAAIA,EAAK,MAAM,EAAG,EAAE,EAAIA,EAC5D,GAAI,CAACC,EAAY,OAAOL,EACxB,GAAM,CAAE,WAAU,UAAWF,EAAmBE,CAAI,EAKpD,OAJIM,IAAaD,EAAmB,IAAIE,IACpCD,EAAS,WAAW,GAAGD,EAAW,EAAE,EAC/B,GAAGC,EAAS,MAAMD,E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AChBC,EACF,OAAO,SAAS,QAAQD,CAAI,EAE5B,OAAO,SAAS,OAAOA,CAAI,EAGjC,EAEME,MACAC,EAAgBA,EAAQ,EACxB,OAAO,OAAW,IACb,OAAO,SAAS,SAAW,OAAO,SAAS,OAAS,OAAO,SAAS,KAEtE,IAGT,MAAO,CACL,cACA,gBACA,gBAAiBvB,EACjB,cACA,KAAME,EACN,oBACA,oBACA,kBAAoB,GAAiBd,EAAkBlB,EAAMgB,EAAaF,EAAegB,EAAyBE,CAAQ,EAC1H,mBACA,eACA,uBACA,kBAAoB,GAAiBZ,EAAkBpB,EAAMgB,EAAaF,EAAegB,EAAyBE,CAAQ,EAC1H,cAAeV,EAA6BE,CAAE,EAC9C,mBAAsBrB,EAAciD,EAAgB,EAAGpB,CAAQ,EAC/D,KAAO,GAA6B,CAClCiB,EAASK,EAAO,KAAM,EAAK,CAC7B,EACA,QAAU,GAA6B,CACrCL,EAASK,EAAO,KAAM,EAAI,CAC5B,EACA,cACA,aAAgB,CACd,IAAMtD,EAAOG,EAAciD,EAAgB,EAAGpB,CAAQ,EAChDuB,EAAM,OAAO,OAAW,IAAc,IAAI,IAAIvD,EAAM,OAAO,SAAS,MAAM,EAAI,IAAI,IAAIA,EAAM,kBAAkB,EACpH,MAAO,CACL,SAAUuD,EAAI,SAAWA,EAAI,OAASA,EAAI,KAC1C,MAAO,OAAO,YAAYA,EAAI,YAAY,CAC5C,CACF,CACF,CACF"}
@@ -1,81 +0,0 @@
1
- import { t as e } from "./adapter-CAJNI6Sw.js";
2
- import { mergeRouteTranslationsWithRoot as t } from "@i18n-micro/utils/parse-path";
3
- import { createI18n as n } from "@i18n-micro/vue";
4
- //#region src/runtime/create.ts
5
- function r(e, n, r) {
6
- if (r) for (let [i, a] of Object.entries(r)) for (let [r, o] of Object.entries(a)) e.global.addRouteTranslations(r, i, t(n?.[r], o), !1);
7
- }
8
- function i(t) {
9
- let i = t.defaultLocale || t.locale, a = t.locales ?? [], o = t.syncWithVitePress !== !1, s = n({
10
- locale: t.locale,
11
- fallbackLocale: t.fallbackLocale ?? i,
12
- messages: t.messages,
13
- plural: t.plural,
14
- missingWarn: t.missingWarn,
15
- missingHandler: t.missingHandler,
16
- locales: a,
17
- defaultLocale: i
18
- });
19
- r(s, t.messages, t.routeMessages);
20
- let c = e({
21
- locales: a,
22
- defaultLocale: i,
23
- localeKeyToCode: t.localeKeyToCode,
24
- base: t.base
25
- }), l = {
26
- localizePath: c.localizePath,
27
- switchLocalePath: c.switchLocalePath,
28
- getLocaleFromPath: c.getLocaleFromPath,
29
- removeLocaleFromPath: c.removeLocaleFromPath,
30
- routeNameFromPath: c.routeNameFromPath
31
- };
32
- s.global.extend(l);
33
- let u = new Set(Object.keys(t.routeMessages ?? {})), d = /* @__PURE__ */ new WeakMap();
34
- return Object.assign(s, l, {
35
- get i18n() {
36
- return s.global;
37
- },
38
- enhanceApp: (n) => {
39
- let { app: r, router: c } = n, l = d.get(r);
40
- if (!l) {
41
- let n = e({
42
- locales: a,
43
- defaultLocale: i,
44
- localeKeyToCode: t.localeKeyToCode,
45
- base: t.base,
46
- getPath: () => {
47
- let e = c.route;
48
- return `${e.path}${e.query || ""}${e.hash || ""}`;
49
- },
50
- go: (e, t) => c.go(e, t)
51
- });
52
- r.use(s), s.setRoutingStrategy(n), l = {
53
- adapter: n,
54
- boundSyncHandler: null,
55
- chainedPrevious: void 0
56
- }, d.set(r, l);
57
- }
58
- if (!o) return;
59
- let { adapter: f } = l, p = (e = c.route.path) => {
60
- let t = f.getLocaleFromPath(e);
61
- s.global.getLocale() !== t && (s.global.locale = t);
62
- let n = f.routeNameFromPath(e);
63
- s.global.setRoute(u.has(n) ? n : "index");
64
- };
65
- p();
66
- let m = c.onAfterRouteChange;
67
- m !== l.boundSyncHandler && (l.chainedPrevious = typeof m == "function" ? m : void 0), l.boundSyncHandler = async (e) => {
68
- typeof l.chainedPrevious == "function" && await l.chainedPrevious(e);
69
- let t = e.startsWith("http") ? (() => {
70
- let t = new URL(e);
71
- return t.pathname + t.search + t.hash;
72
- })() : e;
73
- p(t);
74
- }, c.onAfterRouteChange = l.boundSyncHandler;
75
- }
76
- });
77
- }
78
- //#endregion
79
- export { i as t };
80
-
81
- //# sourceMappingURL=create-C_dXg23X.js.map