astro-intlayer 9.5.4 → 9.5.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.
Files changed (126) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/_virtual/_rolldown/runtime.cjs +28 -0
  3. package/dist/cjs/client/format/index.cjs +57 -0
  4. package/dist/cjs/client/index.cjs +81 -0
  5. package/dist/cjs/client/localeRedirect.cjs +64 -0
  6. package/dist/cjs/client/localeRedirect.cjs.map +1 -0
  7. package/dist/cjs/format/index.cjs +20 -0
  8. package/dist/cjs/format/useCompact.cjs +18 -0
  9. package/dist/cjs/format/useCompact.cjs.map +1 -0
  10. package/dist/cjs/format/useCurrency.cjs +18 -0
  11. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  12. package/dist/cjs/format/useDate.cjs +27 -0
  13. package/dist/cjs/format/useDate.cjs.map +1 -0
  14. package/dist/cjs/format/useIntl.cjs +24 -0
  15. package/dist/cjs/format/useIntl.cjs.map +1 -0
  16. package/dist/cjs/format/useList.cjs +18 -0
  17. package/dist/cjs/format/useList.cjs.map +1 -0
  18. package/dist/cjs/format/useNumber.cjs +21 -0
  19. package/dist/cjs/format/useNumber.cjs.map +1 -0
  20. package/dist/cjs/format/usePercentage.cjs +18 -0
  21. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  22. package/dist/cjs/format/useRelativeTime.cjs +18 -0
  23. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  24. package/dist/cjs/format/useUnit.cjs +18 -0
  25. package/dist/cjs/format/useUnit.cjs.map +1 -0
  26. package/dist/cjs/html/index.cjs +33 -0
  27. package/dist/cjs/index.cjs +33 -35
  28. package/dist/cjs/index.cjs.map +1 -1
  29. package/dist/cjs/integration.cjs +77 -0
  30. package/dist/cjs/integration.cjs.map +1 -0
  31. package/dist/cjs/markdown/index.cjs +45 -0
  32. package/dist/cjs/middleware.cjs +103 -0
  33. package/dist/cjs/middleware.cjs.map +1 -0
  34. package/dist/cjs/requestStorage.cjs +24 -0
  35. package/dist/cjs/requestStorage.cjs.map +1 -0
  36. package/dist/cjs/useDictionary.cjs +38 -0
  37. package/dist/cjs/useDictionary.cjs.map +1 -0
  38. package/dist/cjs/useIntlayer.cjs +38 -0
  39. package/dist/cjs/useIntlayer.cjs.map +1 -0
  40. package/dist/cjs/useLocale.cjs +41 -0
  41. package/dist/cjs/useLocale.cjs.map +1 -0
  42. package/dist/cjs/withInertOnChange.cjs +17 -0
  43. package/dist/cjs/withInertOnChange.cjs.map +1 -0
  44. package/dist/esm/client/format/index.mjs +3 -0
  45. package/dist/esm/client/index.mjs +3 -0
  46. package/dist/esm/client/localeRedirect.mjs +62 -0
  47. package/dist/esm/client/localeRedirect.mjs.map +1 -0
  48. package/dist/esm/format/index.mjs +11 -0
  49. package/dist/esm/format/useCompact.mjs +17 -0
  50. package/dist/esm/format/useCompact.mjs.map +1 -0
  51. package/dist/esm/format/useCurrency.mjs +17 -0
  52. package/dist/esm/format/useCurrency.mjs.map +1 -0
  53. package/dist/esm/format/useDate.mjs +26 -0
  54. package/dist/esm/format/useDate.mjs.map +1 -0
  55. package/dist/esm/format/useIntl.mjs +23 -0
  56. package/dist/esm/format/useIntl.mjs.map +1 -0
  57. package/dist/esm/format/useList.mjs +17 -0
  58. package/dist/esm/format/useList.mjs.map +1 -0
  59. package/dist/esm/format/useNumber.mjs +20 -0
  60. package/dist/esm/format/useNumber.mjs.map +1 -0
  61. package/dist/esm/format/usePercentage.mjs +17 -0
  62. package/dist/esm/format/usePercentage.mjs.map +1 -0
  63. package/dist/esm/format/useRelativeTime.mjs +17 -0
  64. package/dist/esm/format/useRelativeTime.mjs.map +1 -0
  65. package/dist/esm/format/useUnit.mjs +17 -0
  66. package/dist/esm/format/useUnit.mjs.map +1 -0
  67. package/dist/esm/html/index.mjs +3 -0
  68. package/dist/esm/index.mjs +30 -36
  69. package/dist/esm/index.mjs.map +1 -1
  70. package/dist/esm/integration.mjs +75 -0
  71. package/dist/esm/integration.mjs.map +1 -0
  72. package/dist/esm/markdown/index.mjs +3 -0
  73. package/dist/esm/middleware.mjs +100 -0
  74. package/dist/esm/middleware.mjs.map +1 -0
  75. package/dist/esm/requestStorage.mjs +21 -0
  76. package/dist/esm/requestStorage.mjs.map +1 -0
  77. package/dist/esm/useDictionary.mjs +37 -0
  78. package/dist/esm/useDictionary.mjs.map +1 -0
  79. package/dist/esm/useIntlayer.mjs +37 -0
  80. package/dist/esm/useIntlayer.mjs.map +1 -0
  81. package/dist/esm/useLocale.mjs +40 -0
  82. package/dist/esm/useLocale.mjs.map +1 -0
  83. package/dist/esm/withInertOnChange.mjs +16 -0
  84. package/dist/esm/withInertOnChange.mjs.map +1 -0
  85. package/dist/types/client/format/index.d.ts +2 -0
  86. package/dist/types/client/index.d.ts +2 -0
  87. package/dist/types/client/localeRedirect.d.ts +26 -0
  88. package/dist/types/client/localeRedirect.d.ts.map +1 -0
  89. package/dist/types/format/index.d.ts +10 -0
  90. package/dist/types/format/useCompact.d.ts +5 -0
  91. package/dist/types/format/useCompact.d.ts.map +1 -0
  92. package/dist/types/format/useCurrency.d.ts +5 -0
  93. package/dist/types/format/useCurrency.d.ts.map +1 -0
  94. package/dist/types/format/useDate.d.ts +8 -0
  95. package/dist/types/format/useDate.d.ts.map +1 -0
  96. package/dist/types/format/useIntl.d.ts +15 -0
  97. package/dist/types/format/useIntl.d.ts.map +1 -0
  98. package/dist/types/format/useList.d.ts +5 -0
  99. package/dist/types/format/useList.d.ts.map +1 -0
  100. package/dist/types/format/useNumber.d.ts +8 -0
  101. package/dist/types/format/useNumber.d.ts.map +1 -0
  102. package/dist/types/format/usePercentage.d.ts +5 -0
  103. package/dist/types/format/usePercentage.d.ts.map +1 -0
  104. package/dist/types/format/useRelativeTime.d.ts +5 -0
  105. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  106. package/dist/types/format/useUnit.d.ts +5 -0
  107. package/dist/types/format/useUnit.d.ts.map +1 -0
  108. package/dist/types/html/index.d.ts +2 -0
  109. package/dist/types/index.d.ts +13 -6
  110. package/dist/types/index.d.ts.map +1 -1
  111. package/dist/types/integration.d.ts +41 -0
  112. package/dist/types/integration.d.ts.map +1 -0
  113. package/dist/types/markdown/index.d.ts +2 -0
  114. package/dist/types/middleware.d.ts +54 -0
  115. package/dist/types/middleware.d.ts.map +1 -0
  116. package/dist/types/requestStorage.d.ts +22 -0
  117. package/dist/types/requestStorage.d.ts.map +1 -0
  118. package/dist/types/useDictionary.d.ts +29 -0
  119. package/dist/types/useDictionary.d.ts.map +1 -0
  120. package/dist/types/useIntlayer.d.ts +28 -0
  121. package/dist/types/useIntlayer.d.ts.map +1 -0
  122. package/dist/types/useLocale.d.ts +29 -0
  123. package/dist/types/useLocale.d.ts.map +1 -0
  124. package/dist/types/withInertOnChange.d.ts +12 -0
  125. package/dist/types/withInertOnChange.d.ts.map +1 -0
  126. package/package.json +96 -6
@@ -0,0 +1,62 @@
1
+ import { getLocalizedUrl, isProxyStorageLocaleEnabled, resolveProxyMode } from "@intlayer/core/localization";
2
+ import { internationalization, routing } from "@intlayer/config/built";
3
+ import { getLocaleFromStorageClient } from "@intlayer/core/utils";
4
+
5
+ //#region src/client/localeRedirect.ts
6
+ /**
7
+ * Locale explicitly carried by a URL — path prefix, or `?locale=` in
8
+ * `search-params` mode. `undefined` when the URL is unlocalized, which in
9
+ * `prefix-no-default` mode means it belongs to the default locale.
10
+ */
11
+ const getExplicitUrlLocale = (url) => {
12
+ const candidate = routing.mode === "search-params" ? url.searchParams.get("locale") : url.pathname.split("/")[1];
13
+ return candidate && internationalization.locales.includes(candidate) ? candidate : void 0;
14
+ };
15
+ /**
16
+ * Computes where a prerendered page should send the visitor so it matches the
17
+ * locale they stored (cookie, localStorage or sessionStorage, per
18
+ * `routing.storage`).
19
+ *
20
+ * Mirrors the redirect the Intlayer proxy performs on server-rendered requests,
21
+ * for pages served as static files where no server can read the cookie:
22
+ * - the URL wins over storage, so a localized URL is never redirected;
23
+ * - `routing.enableProxy: false` and `no-prefix` routing disable it;
24
+ * - in auto mode a dev server keeps routing URL-driven, like the proxy.
25
+ *
26
+ * @param url - The URL of the current page.
27
+ * @param isDevServer - Whether `astro dev` is serving the page.
28
+ * @returns The localized URL to navigate to, or `undefined` to stay put.
29
+ */
30
+ const getStoredLocaleRedirect = (url, isDevServer) => {
31
+ const proxyMode = resolveProxyMode(routing.enableProxy);
32
+ if (proxyMode === "disabled") return;
33
+ if (!isProxyStorageLocaleEnabled(proxyMode, isDevServer)) return;
34
+ if (routing.mode === "no-prefix") return;
35
+ if (getExplicitUrlLocale(url)) return;
36
+ const storedLocale = getLocaleFromStorageClient();
37
+ if (!storedLocale || storedLocale === internationalization.defaultLocale) return;
38
+ const currentPath = `${url.pathname}${url.search}${url.hash}`;
39
+ const localizedPath = getLocalizedUrl(currentPath, storedLocale);
40
+ return localizedPath === currentPath ? void 0 : localizedPath;
41
+ };
42
+ /**
43
+ * Whether `astro dev` is serving the page. Vite inlines `import.meta.env.DEV`
44
+ * into the client bundle; the optional chain keeps the module loadable where
45
+ * no bundler defines it.
46
+ */
47
+ const isDevServer = import.meta.env?.DEV === true;
48
+ /**
49
+ * Sends the visitor of a prerendered page to the URL of their stored locale.
50
+ *
51
+ * Injected on every page by the `intlayer()` integration; a no-op once the URL
52
+ * already names a locale, so a redirected page does not redirect again.
53
+ */
54
+ const redirectToStoredLocale = () => {
55
+ if (typeof window === "undefined") return;
56
+ const target = getStoredLocaleRedirect(new URL(window.location.href), isDevServer);
57
+ if (target) window.location.replace(target);
58
+ };
59
+
60
+ //#endregion
61
+ export { getStoredLocaleRedirect, redirectToStoredLocale };
62
+ //# sourceMappingURL=localeRedirect.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeRedirect.mjs","names":[],"sources":["../../../src/client/localeRedirect.ts"],"sourcesContent":["import { internationalization, routing } from '@intlayer/config/built';\nimport {\n getLocalizedUrl,\n isProxyStorageLocaleEnabled,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport { getLocaleFromStorageClient } from '@intlayer/core/utils';\nimport type { Locale } from '@intlayer/types/allLocales';\n\n/**\n * Locale explicitly carried by a URL — path prefix, or `?locale=` in\n * `search-params` mode. `undefined` when the URL is unlocalized, which in\n * `prefix-no-default` mode means it belongs to the default locale.\n */\nconst getExplicitUrlLocale = (url: URL): Locale | undefined => {\n const candidate =\n routing.mode === 'search-params'\n ? url.searchParams.get('locale')\n : url.pathname.split('/')[1];\n\n return candidate && internationalization.locales.includes(candidate as Locale)\n ? (candidate as Locale)\n : undefined;\n};\n\n/**\n * Computes where a prerendered page should send the visitor so it matches the\n * locale they stored (cookie, localStorage or sessionStorage, per\n * `routing.storage`).\n *\n * Mirrors the redirect the Intlayer proxy performs on server-rendered requests,\n * for pages served as static files where no server can read the cookie:\n * - the URL wins over storage, so a localized URL is never redirected;\n * - `routing.enableProxy: false` and `no-prefix` routing disable it;\n * - in auto mode a dev server keeps routing URL-driven, like the proxy.\n *\n * @param url - The URL of the current page.\n * @param isDevServer - Whether `astro dev` is serving the page.\n * @returns The localized URL to navigate to, or `undefined` to stay put.\n */\nexport const getStoredLocaleRedirect = (\n url: URL,\n isDevServer: boolean\n): string | undefined => {\n const proxyMode = resolveProxyMode(routing.enableProxy);\n\n if (proxyMode === 'disabled') return;\n if (!isProxyStorageLocaleEnabled(proxyMode, isDevServer)) return;\n if (routing.mode === 'no-prefix') return;\n if (getExplicitUrlLocale(url)) return;\n\n const storedLocale = getLocaleFromStorageClient();\n\n if (!storedLocale || storedLocale === internationalization.defaultLocale) {\n return;\n }\n\n const currentPath = `${url.pathname}${url.search}${url.hash}`;\n const localizedPath = getLocalizedUrl(currentPath, storedLocale);\n\n return localizedPath === currentPath ? undefined : localizedPath;\n};\n\n/**\n * Whether `astro dev` is serving the page. Vite inlines `import.meta.env.DEV`\n * into the client bundle; the optional chain keeps the module loadable where\n * no bundler defines it.\n */\nconst isDevServer =\n (import.meta as { env?: { DEV?: boolean } }).env?.DEV === true;\n\n/**\n * Sends the visitor of a prerendered page to the URL of their stored locale.\n *\n * Injected on every page by the `intlayer()` integration; a no-op once the URL\n * already names a locale, so a redirected page does not redirect again.\n */\nexport const redirectToStoredLocale = (): void => {\n if (typeof window === 'undefined') return;\n\n const target = getStoredLocaleRedirect(\n new URL(window.location.href),\n isDevServer\n );\n\n if (target) window.location.replace(target);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAM,wBAAwB,QAAiC;CAC7D,MAAM,YACJ,QAAQ,SAAS,kBACb,IAAI,aAAa,IAAI,QAAQ,IAC7B,IAAI,SAAS,MAAM,GAAG,CAAC,CAAC;CAE9B,OAAO,aAAa,qBAAqB,QAAQ,SAAS,SAAmB,IACxE,YACD;AACN;;;;;;;;;;;;;;;;AAiBA,MAAa,2BACX,KACA,gBACuB;CACvB,MAAM,YAAY,iBAAiB,QAAQ,WAAW;CAEtD,IAAI,cAAc,YAAY;CAC9B,IAAI,CAAC,4BAA4B,WAAW,WAAW,GAAG;CAC1D,IAAI,QAAQ,SAAS,aAAa;CAClC,IAAI,qBAAqB,GAAG,GAAG;CAE/B,MAAM,eAAe,2BAA2B;CAEhD,IAAI,CAAC,gBAAgB,iBAAiB,qBAAqB,eACzD;CAGF,MAAM,cAAc,GAAG,IAAI,WAAW,IAAI,SAAS,IAAI;CACvD,MAAM,gBAAgB,gBAAgB,aAAa,YAAY;CAE/D,OAAO,kBAAkB,cAAc,SAAY;AACrD;;;;;;AAOA,MAAM,cACH,YAA4C,KAAK,QAAQ;;;;;;;AAQ5D,MAAa,+BAAqC;CAChD,IAAI,OAAO,WAAW,aAAa;CAEnC,MAAM,SAAS,wBACb,IAAI,IAAI,OAAO,SAAS,IAAI,GAC5B,WACF;CAEA,IAAI,QAAQ,OAAO,SAAS,QAAQ,MAAM;AAC5C"}
@@ -0,0 +1,11 @@
1
+ import { useCompact } from "./useCompact.mjs";
2
+ import { useCurrency } from "./useCurrency.mjs";
3
+ import { useDate } from "./useDate.mjs";
4
+ import { useIntl } from "./useIntl.mjs";
5
+ import { useList } from "./useList.mjs";
6
+ import { useNumber } from "./useNumber.mjs";
7
+ import { usePercentage } from "./usePercentage.mjs";
8
+ import { useRelativeTime } from "./useRelativeTime.mjs";
9
+ import { useUnit } from "./useUnit.mjs";
10
+
11
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { compact } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useCompact.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useCompact = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => compact(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useCompact };
17
+ //# sourceMappingURL=useCompact.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../src/format/useCompact.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { compact } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useCompact = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,mBAAmB;CAC9B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,QAAQ,KAAK,IAAI;EACf,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { currency } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useCurrency.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useCurrency = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => currency(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useCurrency };
17
+ //# sourceMappingURL=useCurrency.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../src/format/useCurrency.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { currency } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useCurrency = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,oBAAoB;CAC/B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,SAAS,KAAK,IAAI;EAChB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,26 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { date, presets } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useDate.ts
6
+ const { defaultLocale } = internationalization;
7
+ /**
8
+ * Astro hook that provides a localized date/time formatter bound to the request locale.
9
+ */
10
+ const useDate = () => {
11
+ const locale = getRequestLocale() ?? defaultLocale;
12
+ return (...args) => {
13
+ const options = typeof args[1] === "string" ? {
14
+ ...presets[args[1]],
15
+ locale
16
+ } : {
17
+ ...args[1],
18
+ locale: args[1]?.locale ?? locale
19
+ };
20
+ return date(args[0], options);
21
+ };
22
+ };
23
+
24
+ //#endregion
25
+ export { useDate };
26
+ //# sourceMappingURL=useDate.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDate.mjs","names":[],"sources":["../../../src/format/useDate.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { date, presets } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\n/**\n * Astro hook that provides a localized date/time formatter bound to the request locale.\n */\nexport const useDate = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof date>) => {\n const options =\n typeof args[1] === 'string'\n ? { ...presets[args[1]], locale }\n : { ...args[1], locale: args[1]?.locale ?? locale };\n\n return date(args[0], options as Parameters<typeof date>[1]);\n };\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;;;;AAK1B,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SAAkC;EAC3C,MAAM,UACJ,OAAO,KAAK,OAAO,WACf;GAAE,GAAG,QAAQ,KAAK;GAAK;EAAO,IAC9B;GAAE,GAAG,KAAK;GAAI,QAAQ,KAAK,EAAE,EAAE,UAAU;EAAO;EAEtD,OAAO,KAAK,KAAK,IAAI,OAAqC;CAC5D;AACF"}
@@ -0,0 +1,23 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { bindIntl } from "@intlayer/core/utils";
4
+
5
+ //#region src/format/useIntl.ts
6
+ const { defaultLocale } = internationalization;
7
+ /**
8
+ * Astro hook that provides a locale-bound `Intl` object.
9
+ *
10
+ * It uses the request locale on the server, falling back to the configured
11
+ * default locale.
12
+ */
13
+ const useIntl = (locale) => {
14
+ const currentLocale = locale ?? getRequestLocale() ?? defaultLocale;
15
+ return {
16
+ intl: bindIntl(currentLocale),
17
+ subscribe: () => () => {}
18
+ };
19
+ };
20
+
21
+ //#endregion
22
+ export { useIntl };
23
+ //# sourceMappingURL=useIntl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../src/format/useIntl.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { bindIntl, type WrappedIntl } from '@intlayer/core/utils';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\n/**\n * Astro hook that provides a locale-bound `Intl` object.\n *\n * It uses the request locale on the server, falling back to the configured\n * default locale.\n */\nexport const useIntl = (\n locale?: LocalesValues\n): {\n intl: WrappedIntl;\n subscribe: (callback: (intl: WrappedIntl) => void) => () => void;\n} => {\n const currentLocale =\n locale ?? getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n const intl = bindIntl(currentLocale);\n\n return {\n intl,\n subscribe: () => () => {},\n };\n};\n"],"mappings":";;;;;AAQA,MAAM,EAAE,kBAAkB;;;;;;;AAQ1B,MAAa,WACX,WAIG;CACH,MAAM,gBACJ,UAAU,iBAAiB,KAAM;CAGnC,OAAO;EACL,MAHW,SAAS,aAGjB;EACH,uBAAuB,CAAC;CAC1B;AACF"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { list } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useList.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useList = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => list(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useList };
17
+ //# sourceMappingURL=useList.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useList.mjs","names":[],"sources":["../../../src/format/useList.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { list } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useList = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,KAAK,KAAK,IAAI;EACZ,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,20 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { number } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useNumber.ts
6
+ const { defaultLocale } = internationalization;
7
+ /**
8
+ * Astro hook that provides a localized number formatter bound to the request locale.
9
+ */
10
+ const useNumber = () => {
11
+ const locale = getRequestLocale() ?? defaultLocale;
12
+ return (...args) => number(args[0], {
13
+ ...args[1],
14
+ locale: args[1]?.locale ?? locale
15
+ });
16
+ };
17
+
18
+ //#endregion
19
+ export { useNumber };
20
+ //# sourceMappingURL=useNumber.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../src/format/useNumber.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { number } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\n/**\n * Astro hook that provides a localized number formatter bound to the request locale.\n */\nexport const useNumber = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;;;;AAK1B,MAAa,kBAAkB;CAC7B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,OAAO,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { percentage } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/usePercentage.ts
6
+ const { defaultLocale } = internationalization;
7
+ const usePercentage = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => percentage(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { usePercentage };
17
+ //# sourceMappingURL=usePercentage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../src/format/usePercentage.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { percentage } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const usePercentage = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,sBAAsB;CACjC,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,WAAW,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { relativeTime } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useRelativeTime.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useRelativeTime = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => relativeTime(args[0], args[1], {
10
+ ...args[2],
11
+ locale: args[2]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useRelativeTime };
17
+ //# sourceMappingURL=useRelativeTime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { relativeTime } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useRelativeTime = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,wBAAwB;CACnC,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,aAAa,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { units } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useUnit.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useUnit = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => units(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useUnit };
17
+ //# sourceMappingURL=useUnit.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../src/format/useUnit.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { units } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useUnit = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,MAAM,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,3 @@
1
+ import { installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer } from "vanilla-intlayer/html";
2
+
3
+ export { installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer };
@@ -1,23 +1,24 @@
1
- import { emitRewrittenPages } from "./emitRewrittenPages.mjs";
2
- import { resolve } from "node:path";
3
- import { getConfiguration } from "@intlayer/config/node";
4
- import { getAlias } from "@intlayer/config/utils";
5
- import { prepareIntlayer } from "@intlayer/engine/build";
6
- import { INTLAYER_NO_EXTERNAL_PATTERN, intlayer as intlayer$1 } from "vite-intlayer";
1
+ import { getIntlayerLocals } from "./requestStorage.mjs";
2
+ import { useDictionary } from "./useDictionary.mjs";
3
+ import { useIntlayer } from "./useIntlayer.mjs";
4
+ import { useLocale } from "./useLocale.mjs";
7
5
 
8
6
  //#region src/index.ts
9
7
  /**
10
- * Keeps the intlayer packages out of Node's native module loader in *every*
11
- * Vite environment Astro renders from.
8
+ * Package self-reference to the Node-only half of the integration.
12
9
  *
13
- * A static dev server renders from `ssr`, but other setups render from Astro's
14
- * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only
15
- * seeds the `ssr` one. Declaring it per environment covers the rest.
10
+ * Kept in a variable so the `import()` below is not statically analyzable:
11
+ * Astro bundles this package into the server build (`ssr.noExternal`), and a
12
+ * literal specifier would make the bundler follow it into `vite-intlayer`,
13
+ * `@intlayer/engine` and the framework compilers — which have no business in
14
+ * the server build, and do not even bundle (`velocityjs`, …). Left alone, the
15
+ * import only runs from `astro.config`, in Node.
16
16
  */
17
- const intlayerNoExternalEnvironments = () => ({
18
- name: "astro-intlayer-no-external",
19
- configEnvironment: () => ({ resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] } })
20
- });
17
+ const integrationSpecifier = "astro-intlayer/integration";
18
+ const loadIntegration = () => import(
19
+ /* @vite-ignore */
20
+ integrationSpecifier
21
+ );
21
22
  /**
22
23
  * Astro integration for Intlayer.
23
24
  *
@@ -25,12 +26,14 @@ const intlayerNoExternalEnvironments = () => ({
25
26
  * 1. Preparing Intlayer resources (dictionaries) at config setup.
26
27
  * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).
27
28
  * 3. Configuring Vite aliases for dictionary access.
28
- * 4. Emitting the prerendered pages at their rewritten (localized) URLs.
29
+ * 4. Registering the `astro-intlayer/middleware`, which resolves the request
30
+ * locale into `Astro.locals.intlayer` for the `useLocale` / `useIntlayer` /
31
+ * `useDictionary` hooks of this package.
32
+ * 5. Emitting the prerendered pages at their rewritten (localized) URLs.
29
33
  *
30
- * The dev-time content watcher is not started here: the bundled
31
- * `vite-intlayer` plugin already starts one from `configureServer`, and
32
- * `watch()` subscribes anew on every call, so doing both would rebuild each
33
- * content edit twice.
34
+ * The implementation is loaded lazily: this entry is also the one pages import
35
+ * their hooks from, and it must not drag the Node-only tooling into their
36
+ * server bundle.
34
37
  *
35
38
  * @returns An Astro integration object.
36
39
  *
@@ -48,26 +51,17 @@ const intlayerNoExternalEnvironments = () => ({
48
51
  const intlayer = () => ({
49
52
  name: "astro-intlayer",
50
53
  hooks: {
51
- "astro:config:setup": async ({ updateConfig }) => {
52
- const configuration = getConfiguration();
53
- await prepareIntlayer(configuration);
54
- updateConfig({ vite: {
55
- plugins: [intlayer$1(), intlayerNoExternalEnvironments()],
56
- resolve: { alias: { ...getAlias({
57
- configuration,
58
- formatter: (value) => resolve(value)
59
- }) } },
60
- ssr: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] }
61
- } });
54
+ "astro:config:setup": async (options) => {
55
+ const { configSetup } = await loadIntegration();
56
+ await configSetup(options);
62
57
  },
63
- "astro:build:done": async ({ dir, logger }) => {
64
- const configuration = getConfiguration();
65
- const emittedPages = await emitRewrittenPages(configuration, dir);
66
- if (emittedPages.length > 0) logger.info(`Emitted ${emittedPages.length} rewritten page(s): ${emittedPages.map(([from, to]) => `${from} \u2192 ${to}`).join(", ")}`);
58
+ "astro:build:done": async (options) => {
59
+ const { buildDone } = await loadIntegration();
60
+ await buildDone(options);
67
61
  }
68
62
  }
69
63
  });
70
64
 
71
65
  //#endregion
72
- export { intlayer as default, intlayer };
66
+ export { intlayer as default, intlayer, getIntlayerLocals, useDictionary, useIntlayer, useLocale };
73
67
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["viteIntlayerPlugin"],"sources":["../../src/index.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n INTLAYER_NO_EXTERNAL_PATTERN,\n intlayer as viteIntlayerPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Keeps the intlayer packages out of Node's native module loader in *every*\n * Vite environment Astro renders from.\n *\n * A static dev server renders from `ssr`, but other setups render from Astro's\n * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only\n * seeds the `ssr` one. Declaring it per environment covers the rest.\n */\nconst intlayerNoExternalEnvironments = (): PluginOption => ({\n name: 'astro-intlayer-no-external',\n configEnvironment: () => ({\n resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] },\n }),\n});\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * The dev-time content watcher is not started here: the bundled\n * `vite-intlayer` plugin already starts one from `configureServer`, and\n * `watch()` subscribes anew on every call, so doing both would rebuild each\n * content edit twice.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async ({ updateConfig }) => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n updateConfig({\n vite: {\n plugins: [\n viteIntlayerPlugin(),\n intlayerNoExternalEnvironments(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n // `astro-intlayer` is tagged with the `astro` keyword, so Astro\n // treats it as an Astro package and crawls its dependency tree\n // (`vitefu`), force-externalizing every dependency it finds —\n // `@intlayer/core`, `@intlayer/config`, … — into\n // `resolve.external`. Vite checks `external` before `noExternal`,\n // so the `ssr.noExternal` that `vite-intlayer` returns from its\n // Vite `config` hook loses that race and the packages are loaded\n // natively by Node, stranding dictionary edits behind Node's\n // require cache. Declaring it here instead runs before the crawl,\n // which drops explicitly no-externalized packages from its result.\n ssr: {\n noExternal: [INTLAYER_NO_EXTERNAL_PATTERN],\n },\n },\n });\n },\n\n // Astro renders each page from its canonical file-system route, so a\n // static build has no file for the localized paths declared in\n // `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n // `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n 'astro:build:done': async ({ dir, logger }) => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,MAAM,wCAAsD;CAC1D,MAAM;CACN,0BAA0B,EACxB,SAAS,EAAE,YAAY,CAAC,4BAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,EAAE,mBAAmB;GAChD,MAAM,gBAAgB,iBAAiB;GAGvC,MAAM,gBAAgB,aAAa;GAEnC,aAAa,EACX,MAAM;IACJ,SAAS,CACPA,WAAmB,GACnB,+BAA+B,CACjC;IACA,SAAS,EACP,OAAO,EACL,GAAG,SAAS;KACV;KACA,YAAY,UAAU,QAAQ,KAAK;IACrC,CAAC,EACH,EACF;IAWA,KAAK,EACH,YAAY,CAAC,4BAA4B,EAC3C;GACF,EACF,CAAC;EACH;EAMA,oBAAoB,OAAO,EAAE,KAAK,aAAa;GAC7C,MAAM,gBAAgB,iBAAiB;GAEvC,MAAM,eAAe,MAAM,mBAAmB,eAAe,GAAG;GAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;EAEJ;CACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/index.ts"],"sourcesContent":["import type { AstroIntegration } from 'astro';\n\nexport type { IntlayerLocals } from './middleware';\nexport { getIntlayerLocals } from './requestStorage';\nexport { useDictionary } from './useDictionary';\nexport { useIntlayer } from './useIntlayer';\nexport type { UseLocaleProps, UseLocaleResult } from './useLocale';\nexport { useLocale } from './useLocale';\n\n/**\n * Package self-reference to the Node-only half of the integration.\n *\n * Kept in a variable so the `import()` below is not statically analyzable:\n * Astro bundles this package into the server build (`ssr.noExternal`), and a\n * literal specifier would make the bundler follow it into `vite-intlayer`,\n * `@intlayer/engine` and the framework compilers — which have no business in\n * the server build, and do not even bundle (`velocityjs`, …). Left alone, the\n * import only runs from `astro.config`, in Node.\n */\nconst integrationSpecifier = 'astro-intlayer/integration';\n\nconst loadIntegration = (): Promise<typeof import('./integration')> =>\n import(/* @vite-ignore */ integrationSpecifier);\n\n/**\n * Astro integration for Intlayer.\n *\n * It handles:\n * 1. Preparing Intlayer resources (dictionaries) at config setup.\n * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).\n * 3. Configuring Vite aliases for dictionary access.\n * 4. Registering the `astro-intlayer/middleware`, which resolves the request\n * locale into `Astro.locals.intlayer` for the `useLocale` / `useIntlayer` /\n * `useDictionary` hooks of this package.\n * 5. Emitting the prerendered pages at their rewritten (localized) URLs.\n *\n * The implementation is loaded lazily: this entry is also the one pages import\n * their hooks from, and it must not drag the Node-only tooling into their\n * server bundle.\n *\n * @returns An Astro integration object.\n *\n * @example\n * ```ts\n * // astro.config.mjs\n * import { defineConfig } from 'astro/config';\n * import { intlayer } from 'astro-intlayer';\n *\n * export default defineConfig({\n * integrations: [intlayer()],\n * });\n * ```\n */\nexport const intlayer = (): AstroIntegration =>\n ({\n name: 'astro-intlayer',\n hooks: {\n 'astro:config:setup': async (options) => {\n const { configSetup } = await loadIntegration();\n\n await configSetup(options);\n },\n 'astro:build:done': async (options) => {\n const { buildDone } = await loadIntegration();\n\n await buildDone(options);\n },\n },\n }) satisfies AstroIntegration;\n\n/**\n * Alias of {@link intlayer}, kept so `astro add astro-intlayer` works.\n *\n * Astro's CLI codemod always writes a default import\n * (`import intlayer from 'astro-intlayer'`) without checking what the package\n * exports, so the integration has to be reachable that way too. The named\n * export stays the documented one.\n */\nexport default intlayer;\n"],"mappings":";;;;;;;;;;;;;;;;AAmBA,MAAM,uBAAuB;AAE7B,MAAM,wBACJ;;CAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+B5B,MAAa,kBACV;CACC,MAAM;CACN,OAAO;EACL,sBAAsB,OAAO,YAAY;GACvC,MAAM,EAAE,gBAAgB,MAAM,gBAAgB;GAE9C,MAAM,YAAY,OAAO;EAC3B;EACA,oBAAoB,OAAO,YAAY;GACrC,MAAM,EAAE,cAAc,MAAM,gBAAgB;GAE5C,MAAM,UAAU,OAAO;EACzB;CACF;AACF"}
@@ -0,0 +1,75 @@
1
+ import { emitRewrittenPages } from "./emitRewrittenPages.mjs";
2
+ import { resolve } from "node:path";
3
+ import { formatProxyEnabledMessage, resolveProxyMode } from "@intlayer/core/localization";
4
+ import { getAppLogger } from "@intlayer/config/logger";
5
+ import { getConfiguration } from "@intlayer/config/node";
6
+ import { getAlias } from "@intlayer/config/utils";
7
+ import { prepareIntlayer } from "@intlayer/engine/build";
8
+ import { INTLAYER_NO_EXTERNAL_PATTERN, intlayer } from "vite-intlayer";
9
+
10
+ //#region src/integration.ts
11
+ /**
12
+ * Keeps the intlayer packages out of Node's native module loader in *every*
13
+ * Vite environment Astro renders from.
14
+ *
15
+ * A static dev server renders from `ssr`, but other setups render from Astro's
16
+ * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only
17
+ * seeds the `ssr` one. Declaring it per environment covers the rest.
18
+ */
19
+ const intlayerNoExternalEnvironments = () => ({
20
+ name: "astro-intlayer-no-external",
21
+ configEnvironment: () => ({ resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] } })
22
+ });
23
+ /**
24
+ * `astro:config:setup`:
25
+ * 1. Prepares the Intlayer resources (dictionaries).
26
+ * 2. Injects the Vite plugins for aliases, locale-based routing and build
27
+ * optimizations (prune).
28
+ * 3. Configures the Vite aliases for dictionary access.
29
+ * 4. Registers the `astro-intlayer/middleware`, which resolves the request
30
+ * locale into `Astro.locals.intlayer` for the hooks and redirects
31
+ * server-rendered requests to the visitor's locale.
32
+ * 5. Injects the client-side locale redirect, which does the same for
33
+ * prerendered pages: served as static files, nothing else can read the
34
+ * stored locale there.
35
+ *
36
+ * The dev-time content watcher is not started here: the bundled
37
+ * `vite-intlayer` plugin already starts one from `configureServer`, and
38
+ * `watch()` subscribes anew on every call, so doing both would rebuild each
39
+ * content edit twice.
40
+ */
41
+ const configSetup = async ({ command, updateConfig, addMiddleware, injectScript }) => {
42
+ const configuration = getConfiguration();
43
+ await prepareIntlayer(configuration);
44
+ addMiddleware({
45
+ entrypoint: "astro-intlayer/middleware",
46
+ order: "pre"
47
+ });
48
+ if (resolveProxyMode(configuration.routing.enableProxy) !== "disabled") {
49
+ injectScript("page", `import { redirectToStoredLocale } from 'astro-intlayer/client/locale-redirect';\nredirectToStoredLocale();`);
50
+ if (command === "preview") getAppLogger(configuration)(formatProxyEnabledMessage(false), { level: "info" });
51
+ }
52
+ updateConfig({ vite: {
53
+ plugins: [intlayer(), intlayerNoExternalEnvironments()],
54
+ resolve: { alias: { ...getAlias({
55
+ configuration,
56
+ formatter: (value) => resolve(value)
57
+ }) } },
58
+ ssr: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] }
59
+ } });
60
+ };
61
+ /**
62
+ * `astro:build:done`: Astro renders each page from its canonical file-system
63
+ * route, so a static build has no file for the localized paths declared in
64
+ * `routing.rewrite`. Mirror them here, otherwise the URLs produced by
65
+ * `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.
66
+ */
67
+ const buildDone = async ({ dir, logger }) => {
68
+ const configuration = getConfiguration();
69
+ const emittedPages = await emitRewrittenPages(configuration, dir);
70
+ if (emittedPages.length > 0) logger.info(`Emitted ${emittedPages.length} rewritten page(s): ${emittedPages.map(([from, to]) => `${from} \u2192 ${to}`).join(", ")}`);
71
+ };
72
+
73
+ //#endregion
74
+ export { buildDone, configSetup };
75
+ //# sourceMappingURL=integration.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.mjs","names":["viteIntlayerPlugin"],"sources":["../../src/integration.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport { getConfiguration } from '@intlayer/config/node';\nimport { getAlias } from '@intlayer/config/utils';\nimport {\n formatProxyEnabledMessage,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport { prepareIntlayer } from '@intlayer/engine/build';\nimport type { AstroIntegration } from 'astro';\nimport type { PluginOption } from 'vite';\nimport {\n INTLAYER_NO_EXTERNAL_PATTERN,\n intlayer as viteIntlayerPlugin,\n} from 'vite-intlayer';\nimport { emitRewrittenPages } from './emitRewrittenPages';\n\n/**\n * Keeps the intlayer packages out of Node's native module loader in *every*\n * Vite environment Astro renders from.\n *\n * A static dev server renders from `ssr`, but other setups render from Astro's\n * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only\n * seeds the `ssr` one. Declaring it per environment covers the rest.\n */\nconst intlayerNoExternalEnvironments = (): PluginOption => ({\n name: 'astro-intlayer-no-external',\n configEnvironment: () => ({\n resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] },\n }),\n});\n\n/**\n * Node-only half of the integration, loaded lazily by the `astro-intlayer`\n * entry when a hook runs.\n *\n * Pages import their hooks from that same entry, and Astro bundles the whole\n * package into the server build (`ssr.noExternal`), so the config loader,\n * `@intlayer/engine` and `vite-intlayer` must stay behind a dynamic import:\n * a static one would put them in the module graph of every page.\n */\n\ntype ConfigSetupOptions = Parameters<\n NonNullable<AstroIntegration['hooks']['astro:config:setup']>\n>[0];\n\ntype BuildDoneOptions = Parameters<\n NonNullable<AstroIntegration['hooks']['astro:build:done']>\n>[0];\n\n/**\n * `astro:config:setup`:\n * 1. Prepares the Intlayer resources (dictionaries).\n * 2. Injects the Vite plugins for aliases, locale-based routing and build\n * optimizations (prune).\n * 3. Configures the Vite aliases for dictionary access.\n * 4. Registers the `astro-intlayer/middleware`, which resolves the request\n * locale into `Astro.locals.intlayer` for the hooks and redirects\n * server-rendered requests to the visitor's locale.\n * 5. Injects the client-side locale redirect, which does the same for\n * prerendered pages: served as static files, nothing else can read the\n * stored locale there.\n *\n * The dev-time content watcher is not started here: the bundled\n * `vite-intlayer` plugin already starts one from `configureServer`, and\n * `watch()` subscribes anew on every call, so doing both would rebuild each\n * content edit twice.\n */\nexport const configSetup = async ({\n command,\n updateConfig,\n addMiddleware,\n injectScript,\n}: ConfigSetupOptions): Promise<void> => {\n const configuration = getConfiguration();\n\n // Prepare once per process start to ensure generated entries exist\n await prepareIntlayer(configuration);\n\n // Runs before the user middleware so `Astro.locals.intlayer` is set\n // everywhere, including in a hand-written `src/middleware.ts`.\n addMiddleware({\n entrypoint: 'astro-intlayer/middleware',\n order: 'pre',\n });\n\n const proxyMode = resolveProxyMode(configuration.routing.enableProxy);\n\n if (proxyMode !== 'disabled') {\n injectScript(\n 'page',\n `import { redirectToStoredLocale } from 'astro-intlayer/client/locale-redirect';\\nredirectToStoredLocale();`\n );\n\n // `dev` and `build` are announced by the bundled `vite-intlayer` plugin.\n // `astro preview` runs no Vite plugin, so the served output is announced\n // here: the stored locale drives redirects again once the output is\n // served — by the middleware on server-rendered pages, by the injected\n // script on static ones.\n if (command === 'preview') {\n getAppLogger(configuration)(formatProxyEnabledMessage(false), {\n level: 'info',\n });\n }\n }\n\n updateConfig({\n vite: {\n plugins: [\n viteIntlayerPlugin(),\n intlayerNoExternalEnvironments(),\n ] as PluginOption[],\n resolve: {\n alias: {\n ...getAlias({\n configuration,\n formatter: (value) => resolve(value),\n }),\n },\n },\n // `astro-intlayer` is tagged with the `astro` keyword, so Astro\n // treats it as an Astro package and crawls its dependency tree\n // (`vitefu`), force-externalizing every dependency it finds —\n // `@intlayer/core`, `@intlayer/config`, … — into\n // `resolve.external`. Vite checks `external` before `noExternal`,\n // so the `ssr.noExternal` that `vite-intlayer` returns from its\n // Vite `config` hook loses that race and the packages are loaded\n // natively by Node, stranding dictionary edits behind Node's\n // require cache. Declaring it here instead runs before the crawl,\n // which drops explicitly no-externalized packages from its result.\n ssr: {\n noExternal: [INTLAYER_NO_EXTERNAL_PATTERN],\n },\n },\n });\n};\n\n/**\n * `astro:build:done`: Astro renders each page from its canonical file-system\n * route, so a static build has no file for the localized paths declared in\n * `routing.rewrite`. Mirror them here, otherwise the URLs produced by\n * `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.\n */\nexport const buildDone = async ({\n dir,\n logger,\n}: BuildDoneOptions): Promise<void> => {\n const configuration = getConfiguration();\n\n const emittedPages = await emitRewrittenPages(configuration, dir);\n\n if (emittedPages.length > 0) {\n logger.info(\n `Emitted ${emittedPages.length} rewritten page(s): ${emittedPages\n .map(([from, to]) => `${from} \\u2192 ${to}`)\n .join(', ')}`\n );\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAyBA,MAAM,wCAAsD;CAC1D,MAAM;CACN,0BAA0B,EACxB,SAAS,EAAE,YAAY,CAAC,4BAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,cAAc,OAAO,EAChC,SACA,cACA,eACA,mBACuC;CACvC,MAAM,gBAAgB,iBAAiB;CAGvC,MAAM,gBAAgB,aAAa;CAInC,cAAc;EACZ,YAAY;EACZ,OAAO;CACT,CAAC;CAID,IAFkB,iBAAiB,cAAc,QAAQ,WAE7C,MAAM,YAAY;EAC5B,aACE,QACA,4GACF;EAOA,IAAI,YAAY,WACd,aAAa,aAAa,CAAC,CAAC,0BAA0B,KAAK,GAAG,EAC5D,OAAO,OACT,CAAC;CAEL;CAEA,aAAa,EACX,MAAM;EACJ,SAAS,CACPA,SAAmB,GACnB,+BAA+B,CACjC;EACA,SAAS,EACP,OAAO,EACL,GAAG,SAAS;GACV;GACA,YAAY,UAAU,QAAQ,KAAK;EACrC,CAAC,EACH,EACF;EAWA,KAAK,EACH,YAAY,CAAC,4BAA4B,EAC3C;CACF,EACF,CAAC;AACH;;;;;;;AAQA,MAAa,YAAY,OAAO,EAC9B,KACA,aACqC;CACrC,MAAM,gBAAgB,iBAAiB;CAEvC,MAAM,eAAe,MAAM,mBAAmB,eAAe,GAAG;CAEhE,IAAI,aAAa,SAAS,GACxB,OAAO,KACL,WAAW,aAAa,OAAO,sBAAsB,aAClD,KAAK,CAAC,MAAM,QAAQ,GAAG,KAAK,UAAU,IAAI,CAAC,CAC3C,KAAK,IAAI,GACd;AAEJ"}
@@ -0,0 +1,3 @@
1
+ import { compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer } from "vanilla-intlayer/markdown";
2
+
3
+ export { compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer };