astro-intlayer 9.5.4 → 9.5.5

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 (119) hide show
  1. package/README.md +2 -1
  2. package/dist/cjs/client/format/index.cjs +57 -0
  3. package/dist/cjs/client/index.cjs +81 -0
  4. package/dist/cjs/format/index.cjs +20 -0
  5. package/dist/cjs/format/useCompact.cjs +18 -0
  6. package/dist/cjs/format/useCompact.cjs.map +1 -0
  7. package/dist/cjs/format/useCurrency.cjs +18 -0
  8. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  9. package/dist/cjs/format/useDate.cjs +27 -0
  10. package/dist/cjs/format/useDate.cjs.map +1 -0
  11. package/dist/cjs/format/useIntl.cjs +24 -0
  12. package/dist/cjs/format/useIntl.cjs.map +1 -0
  13. package/dist/cjs/format/useList.cjs +18 -0
  14. package/dist/cjs/format/useList.cjs.map +1 -0
  15. package/dist/cjs/format/useNumber.cjs +21 -0
  16. package/dist/cjs/format/useNumber.cjs.map +1 -0
  17. package/dist/cjs/format/usePercentage.cjs +18 -0
  18. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  19. package/dist/cjs/format/useRelativeTime.cjs +18 -0
  20. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  21. package/dist/cjs/format/useUnit.cjs +18 -0
  22. package/dist/cjs/format/useUnit.cjs.map +1 -0
  23. package/dist/cjs/html/index.cjs +33 -0
  24. package/dist/cjs/index.cjs +33 -35
  25. package/dist/cjs/index.cjs.map +1 -1
  26. package/dist/cjs/integration.cjs +67 -0
  27. package/dist/cjs/integration.cjs.map +1 -0
  28. package/dist/cjs/markdown/index.cjs +45 -0
  29. package/dist/cjs/middleware.cjs +43 -0
  30. package/dist/cjs/middleware.cjs.map +1 -0
  31. package/dist/cjs/requestStorage.cjs +24 -0
  32. package/dist/cjs/requestStorage.cjs.map +1 -0
  33. package/dist/cjs/useDictionary.cjs +38 -0
  34. package/dist/cjs/useDictionary.cjs.map +1 -0
  35. package/dist/cjs/useIntlayer.cjs +38 -0
  36. package/dist/cjs/useIntlayer.cjs.map +1 -0
  37. package/dist/cjs/useLocale.cjs +41 -0
  38. package/dist/cjs/useLocale.cjs.map +1 -0
  39. package/dist/cjs/withInertOnChange.cjs +17 -0
  40. package/dist/cjs/withInertOnChange.cjs.map +1 -0
  41. package/dist/esm/client/format/index.mjs +3 -0
  42. package/dist/esm/client/index.mjs +3 -0
  43. package/dist/esm/format/index.mjs +11 -0
  44. package/dist/esm/format/useCompact.mjs +17 -0
  45. package/dist/esm/format/useCompact.mjs.map +1 -0
  46. package/dist/esm/format/useCurrency.mjs +17 -0
  47. package/dist/esm/format/useCurrency.mjs.map +1 -0
  48. package/dist/esm/format/useDate.mjs +26 -0
  49. package/dist/esm/format/useDate.mjs.map +1 -0
  50. package/dist/esm/format/useIntl.mjs +23 -0
  51. package/dist/esm/format/useIntl.mjs.map +1 -0
  52. package/dist/esm/format/useList.mjs +17 -0
  53. package/dist/esm/format/useList.mjs.map +1 -0
  54. package/dist/esm/format/useNumber.mjs +20 -0
  55. package/dist/esm/format/useNumber.mjs.map +1 -0
  56. package/dist/esm/format/usePercentage.mjs +17 -0
  57. package/dist/esm/format/usePercentage.mjs.map +1 -0
  58. package/dist/esm/format/useRelativeTime.mjs +17 -0
  59. package/dist/esm/format/useRelativeTime.mjs.map +1 -0
  60. package/dist/esm/format/useUnit.mjs +17 -0
  61. package/dist/esm/format/useUnit.mjs.map +1 -0
  62. package/dist/esm/html/index.mjs +3 -0
  63. package/dist/esm/index.mjs +30 -36
  64. package/dist/esm/index.mjs.map +1 -1
  65. package/dist/esm/integration.mjs +65 -0
  66. package/dist/esm/integration.mjs.map +1 -0
  67. package/dist/esm/markdown/index.mjs +3 -0
  68. package/dist/esm/middleware.mjs +42 -0
  69. package/dist/esm/middleware.mjs.map +1 -0
  70. package/dist/esm/requestStorage.mjs +21 -0
  71. package/dist/esm/requestStorage.mjs.map +1 -0
  72. package/dist/esm/useDictionary.mjs +37 -0
  73. package/dist/esm/useDictionary.mjs.map +1 -0
  74. package/dist/esm/useIntlayer.mjs +37 -0
  75. package/dist/esm/useIntlayer.mjs.map +1 -0
  76. package/dist/esm/useLocale.mjs +40 -0
  77. package/dist/esm/useLocale.mjs.map +1 -0
  78. package/dist/esm/withInertOnChange.mjs +16 -0
  79. package/dist/esm/withInertOnChange.mjs.map +1 -0
  80. package/dist/types/client/format/index.d.ts +2 -0
  81. package/dist/types/client/index.d.ts +2 -0
  82. package/dist/types/format/index.d.ts +10 -0
  83. package/dist/types/format/useCompact.d.ts +5 -0
  84. package/dist/types/format/useCompact.d.ts.map +1 -0
  85. package/dist/types/format/useCurrency.d.ts +5 -0
  86. package/dist/types/format/useCurrency.d.ts.map +1 -0
  87. package/dist/types/format/useDate.d.ts +8 -0
  88. package/dist/types/format/useDate.d.ts.map +1 -0
  89. package/dist/types/format/useIntl.d.ts +15 -0
  90. package/dist/types/format/useIntl.d.ts.map +1 -0
  91. package/dist/types/format/useList.d.ts +5 -0
  92. package/dist/types/format/useList.d.ts.map +1 -0
  93. package/dist/types/format/useNumber.d.ts +8 -0
  94. package/dist/types/format/useNumber.d.ts.map +1 -0
  95. package/dist/types/format/usePercentage.d.ts +5 -0
  96. package/dist/types/format/usePercentage.d.ts.map +1 -0
  97. package/dist/types/format/useRelativeTime.d.ts +5 -0
  98. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  99. package/dist/types/format/useUnit.d.ts +5 -0
  100. package/dist/types/format/useUnit.d.ts.map +1 -0
  101. package/dist/types/html/index.d.ts +2 -0
  102. package/dist/types/index.d.ts +13 -6
  103. package/dist/types/index.d.ts.map +1 -1
  104. package/dist/types/integration.d.ts +37 -0
  105. package/dist/types/integration.d.ts.map +1 -0
  106. package/dist/types/markdown/index.d.ts +2 -0
  107. package/dist/types/middleware.d.ts +46 -0
  108. package/dist/types/middleware.d.ts.map +1 -0
  109. package/dist/types/requestStorage.d.ts +22 -0
  110. package/dist/types/requestStorage.d.ts.map +1 -0
  111. package/dist/types/useDictionary.d.ts +29 -0
  112. package/dist/types/useDictionary.d.ts.map +1 -0
  113. package/dist/types/useIntlayer.d.ts +28 -0
  114. package/dist/types/useIntlayer.d.ts.map +1 -0
  115. package/dist/types/useLocale.d.ts +29 -0
  116. package/dist/types/useLocale.d.ts.map +1 -0
  117. package/dist/types/withInertOnChange.d.ts +12 -0
  118. package/dist/types/withInertOnChange.d.ts.map +1 -0
  119. package/package.json +88 -6
@@ -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,65 @@
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 } from "vite-intlayer";
7
+
8
+ //#region src/integration.ts
9
+ /**
10
+ * Keeps the intlayer packages out of Node's native module loader in *every*
11
+ * Vite environment Astro renders from.
12
+ *
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.
16
+ */
17
+ const intlayerNoExternalEnvironments = () => ({
18
+ name: "astro-intlayer-no-external",
19
+ configEnvironment: () => ({ resolve: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] } })
20
+ });
21
+ /**
22
+ * `astro:config:setup`:
23
+ * 1. Prepares the Intlayer resources (dictionaries).
24
+ * 2. Injects the Vite plugins for aliases, locale-based routing and build
25
+ * optimizations (prune).
26
+ * 3. Configures the Vite aliases for dictionary access.
27
+ * 4. Registers the `astro-intlayer/middleware`, which resolves the request
28
+ * locale into `Astro.locals.intlayer` for the hooks.
29
+ *
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
+ */
35
+ const configSetup = async ({ updateConfig, addMiddleware }) => {
36
+ const configuration = getConfiguration();
37
+ await prepareIntlayer(configuration);
38
+ addMiddleware({
39
+ entrypoint: "astro-intlayer/middleware",
40
+ order: "pre"
41
+ });
42
+ updateConfig({ vite: {
43
+ plugins: [intlayer(), intlayerNoExternalEnvironments()],
44
+ resolve: { alias: { ...getAlias({
45
+ configuration,
46
+ formatter: (value) => resolve(value)
47
+ }) } },
48
+ ssr: { noExternal: [INTLAYER_NO_EXTERNAL_PATTERN] }
49
+ } });
50
+ };
51
+ /**
52
+ * `astro:build:done`: Astro renders each page from its canonical file-system
53
+ * route, so a static build has no file for the localized paths declared in
54
+ * `routing.rewrite`. Mirror them here, otherwise the URLs produced by
55
+ * `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.
56
+ */
57
+ const buildDone = async ({ dir, logger }) => {
58
+ const configuration = getConfiguration();
59
+ const emittedPages = await emitRewrittenPages(configuration, dir);
60
+ if (emittedPages.length > 0) logger.info(`Emitted ${emittedPages.length} rewritten page(s): ${emittedPages.map(([from, to]) => `${from} \u2192 ${to}`).join(", ")}`);
61
+ };
62
+
63
+ //#endregion
64
+ export { buildDone, configSetup };
65
+ //# 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 { 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 * 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.\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 updateConfig,\n addMiddleware,\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 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":";;;;;;;;;;;;;;;;AAoBA,MAAM,wCAAsD;CAC1D,MAAM;CACN,0BAA0B,EACxB,SAAS,EAAE,YAAY,CAAC,4BAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;AAkCA,MAAa,cAAc,OAAO,EAChC,cACA,oBACuC;CACvC,MAAM,gBAAgB,iBAAiB;CAGvC,MAAM,gBAAgB,aAAa;CAInC,cAAc;EACZ,YAAY;EACZ,OAAO;CACT,CAAC;CAED,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 };
@@ -0,0 +1,42 @@
1
+ import { requestStorage } from "./requestStorage.mjs";
2
+ import { getLocaleFromRequest } from "@intlayer/core/localization";
3
+ import { internationalization } from "@intlayer/config/built";
4
+
5
+ //#region src/middleware.ts
6
+ /**
7
+ * Astro middleware resolving the request locale into `Astro.locals.intlayer`.
8
+ *
9
+ * Priority: the URL (path prefix or `?locale=` search param, in every routing
10
+ * mode but `no-prefix`), then the locale persisted by the client (cookie or
11
+ * custom header), then `Accept-Language` negotiation.
12
+ *
13
+ * The `intlayer()` integration registers it automatically, before the user
14
+ * middleware, so `Astro.locals.intlayer` is available in every page, endpoint
15
+ * and middleware. The rest of the request renders inside an
16
+ * `AsyncLocalStorage` scope bound to those locals, which is how the hooks of
17
+ * `astro-intlayer/server` read the locale with no argument.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * // src/middleware.ts — only needed when composing it by hand
22
+ * import { onRequest as intlayer } from 'astro-intlayer/middleware';
23
+ * import { sequence } from 'astro:middleware';
24
+ *
25
+ * export const onRequest = sequence(intlayer, myMiddleware);
26
+ * ```
27
+ */
28
+ const onRequest = async (context, next) => {
29
+ context.locals.intlayer = {
30
+ locale: await getLocaleFromRequest({
31
+ url: context.url,
32
+ headers: context.isPrerendered ? new Headers() : context.request.headers
33
+ }),
34
+ defaultLocale: internationalization.defaultLocale,
35
+ availableLocales: internationalization.locales
36
+ };
37
+ return requestStorage.run(context.locals, next);
38
+ };
39
+
40
+ //#endregion
41
+ export { onRequest };
42
+ //# sourceMappingURL=middleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.mjs","names":[],"sources":["../../src/middleware.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { getLocaleFromRequest } from '@intlayer/core/localization';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type { MiddlewareHandler } from 'astro';\nimport { requestStorage } from './requestStorage';\n\n/**\n * Intlayer state stored in `Astro.locals.intlayer` by the {@link onRequest} middleware.\n */\nexport type IntlayerLocals = {\n /** Locale resolved for the current request. */\n locale: DeclaredLocales;\n /** Locale configured as fallback in `intlayer.config.ts`. */\n defaultLocale: DeclaredLocales;\n /** Every locale declared in `intlayer.config.ts`. */\n availableLocales: DeclaredLocales[];\n};\n\ndeclare global {\n namespace App {\n interface Locals {\n intlayer: IntlayerLocals;\n }\n }\n}\n\n/**\n * Astro middleware resolving the request locale into `Astro.locals.intlayer`.\n *\n * Priority: the URL (path prefix or `?locale=` search param, in every routing\n * mode but `no-prefix`), then the locale persisted by the client (cookie or\n * custom header), then `Accept-Language` negotiation.\n *\n * The `intlayer()` integration registers it automatically, before the user\n * middleware, so `Astro.locals.intlayer` is available in every page, endpoint\n * and middleware. The rest of the request renders inside an\n * `AsyncLocalStorage` scope bound to those locals, which is how the hooks of\n * `astro-intlayer/server` read the locale with no argument.\n *\n * @example\n * ```ts\n * // src/middleware.ts — only needed when composing it by hand\n * import { onRequest as intlayer } from 'astro-intlayer/middleware';\n * import { sequence } from 'astro:middleware';\n *\n * export const onRequest = sequence(intlayer, myMiddleware);\n * ```\n */\nexport const onRequest: MiddlewareHandler = async (context, next) => {\n context.locals.intlayer = {\n locale: await getLocaleFromRequest({\n url: context.url,\n // A prerendered page is rendered once and served to every visitor, so\n // its locale can only come from the URL. Reading the request headers\n // there would also make Astro warn on every page of the build.\n headers: context.isPrerendered ? new Headers() : context.request.headers,\n }),\n defaultLocale: internationalization.defaultLocale as DeclaredLocales,\n availableLocales: internationalization.locales as DeclaredLocales[],\n };\n\n return requestStorage.run(context.locals, next);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgDA,MAAa,YAA+B,OAAO,SAAS,SAAS;CACnE,QAAQ,OAAO,WAAW;EACxB,QAAQ,MAAM,qBAAqB;GACjC,KAAK,QAAQ;GAIb,SAAS,QAAQ,gBAAgB,IAAI,QAAQ,IAAI,QAAQ,QAAQ;EACnE,CAAC;EACD,eAAe,qBAAqB;EACpC,kBAAkB,qBAAqB;CACzC;CAEA,OAAO,eAAe,IAAI,QAAQ,QAAQ,IAAI;AAChD"}
@@ -0,0 +1,21 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+
3
+ //#region src/requestStorage.ts
4
+ /**
5
+ * `Astro.locals` of the request being rendered, made available to every
6
+ * function running inside the middleware scope — page and component
7
+ * frontmatter, endpoints, nested middleware — without passing `Astro` around.
8
+ */
9
+ const requestStorage = new AsyncLocalStorage();
10
+ /**
11
+ * Returns the Intlayer locals of the request being rendered, if any.
12
+ */
13
+ const getIntlayerLocals = () => requestStorage.getStore()?.intlayer;
14
+ /**
15
+ * Returns the locale of the request being rendered, if any.
16
+ */
17
+ const getRequestLocale = () => getIntlayerLocals()?.locale;
18
+
19
+ //#endregion
20
+ export { getIntlayerLocals, getRequestLocale, requestStorage };
21
+ //# sourceMappingURL=requestStorage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestStorage.mjs","names":[],"sources":["../../src/requestStorage.ts"],"sourcesContent":["import { AsyncLocalStorage } from 'node:async_hooks';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type { IntlayerLocals } from './middleware';\n\n/**\n * `Astro.locals` of the request being rendered, made available to every\n * function running inside the middleware scope — page and component\n * frontmatter, endpoints, nested middleware — without passing `Astro` around.\n */\nexport const requestStorage = new AsyncLocalStorage<{\n intlayer?: IntlayerLocals;\n}>();\n\n/**\n * Returns the Intlayer locals of the request being rendered, if any.\n */\nexport const getIntlayerLocals = (): IntlayerLocals | undefined =>\n requestStorage.getStore()?.intlayer;\n\n/**\n * Returns the locale of the request being rendered, if any.\n */\nexport const getRequestLocale = (): DeclaredLocales | undefined =>\n getIntlayerLocals()?.locale;\n"],"mappings":";;;;;;;;AASA,MAAa,iBAAiB,IAAI,kBAE/B;;;;AAKH,MAAa,0BACX,eAAe,SAAS,CAAC,EAAE;;;;AAK7B,MAAa,yBACX,kBAAkB,CAAC,EAAE"}
@@ -0,0 +1,37 @@
1
+ import { getRequestLocale } from "./requestStorage.mjs";
2
+ import { withInertOnChange } from "./withInertOnChange.mjs";
3
+ import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
4
+ import { getDictionary } from "vanilla-intlayer";
5
+
6
+ //#region src/useDictionary.ts
7
+ /**
8
+ * Transforms an imported dictionary (or qualified dictionary group) and returns
9
+ * its content for the locale of the request being rendered, read from
10
+ * `Astro.locals.intlayer`.
11
+ *
12
+ * The second argument is either a locale or a selector object
13
+ * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
14
+ * over the request locale.
15
+ *
16
+ * Same signature and content shape as the client-side hook this entry resolves
17
+ * to in the browser (`vanilla-intlayer`).
18
+ *
19
+ * @example
20
+ * ```astro
21
+ * ---
22
+ * import { useDictionary } from 'astro-intlayer';
23
+ * import homeContent from '../content/home.content';
24
+ *
25
+ * const { title } = useDictionary(homeContent);
26
+ * ---
27
+ * ```
28
+ */
29
+ const useDictionary = (dictionary, localeOrSelector) => withInertOnChange(getDictionary(dictionary, resolveDictionaryArgument({
30
+ localeOrSelector,
31
+ contextLocale: getRequestLocale(),
32
+ dictionaryKey: dictionary.key
33
+ })));
34
+
35
+ //#endregion
36
+ export { useDictionary };
37
+ //# sourceMappingURL=useDictionary.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../src/useDictionary.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n ResolveQualifiedDictionaryContent,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DeepTransformContent,\n getDictionary,\n type WithOnChange,\n} from 'vanilla-intlayer';\nimport { getRequestLocale } from './requestStorage';\nimport { withInertOnChange } from './withInertOnChange';\n\n/**\n * Transforms an imported dictionary (or qualified dictionary group) and returns\n * its content for the locale of the request being rendered, read from\n * `Astro.locals.intlayer`.\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence\n * over the request locale.\n *\n * Same signature and content shape as the client-side hook this entry resolves\n * to in the browser (`vanilla-intlayer`).\n *\n * @example\n * ```astro\n * ---\n * import { useDictionary } from 'astro-intlayer';\n * import homeContent from '../content/home.content';\n *\n * const { title } = useDictionary(homeContent);\n * ---\n * ```\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<\n ResolveQualifiedDictionaryContent<T, A>,\n ExtractSelectorLocale<A>\n >\n> =>\n withInertOnChange(\n getDictionary<T, A>(\n dictionary,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: getRequestLocale(),\n dictionaryKey: dictionary.key,\n }) as A\n )\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,iBAMX,YACA,qBAOA,kBACE,cACE,YACA,0BAA0B;CACxB;CACA,eAAe,iBAAiB;CAChC,eAAe,WAAW;AAC5B,CAAC,CACH,CACF"}
@@ -0,0 +1,37 @@
1
+ import { getRequestLocale } from "./requestStorage.mjs";
2
+ import { withInertOnChange } from "./withInertOnChange.mjs";
3
+ import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
4
+ import { getIntlayer } from "vanilla-intlayer";
5
+
6
+ //#region src/useIntlayer.ts
7
+ /**
8
+ * Picks one dictionary by its key and returns its content for the locale of
9
+ * the request being rendered, read from `Astro.locals.intlayer`.
10
+ *
11
+ * The second argument is either a locale or a selector object
12
+ * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
13
+ * over the request locale.
14
+ *
15
+ * Same signature and content shape as the client-side hook this entry resolves
16
+ * to in the browser (`vanilla-intlayer`), so a call moves between the
17
+ * frontmatter and a `<script>` unchanged.
18
+ *
19
+ * @example
20
+ * ```astro
21
+ * ---
22
+ * import { useIntlayer } from 'astro-intlayer';
23
+ *
24
+ * const { title, description } = useIntlayer('home');
25
+ * ---
26
+ * <h1>{title}</h1>
27
+ * ```
28
+ */
29
+ const useIntlayer = (key, localeOrSelector) => withInertOnChange(getIntlayer(key, resolveDictionaryArgument({
30
+ localeOrSelector,
31
+ contextLocale: getRequestLocale(),
32
+ dictionaryKey: key
33
+ })));
34
+
35
+ //#endregion
36
+ export { useIntlayer };
37
+ //# sourceMappingURL=useIntlayer.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../src/useIntlayer.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryResult,\n DictionarySelectorForKey,\n ExtractSelectorLocale,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport {\n type DeepTransformContent,\n getIntlayer,\n type WithOnChange,\n} from 'vanilla-intlayer';\nimport { getRequestLocale } from './requestStorage';\nimport { withInertOnChange } from './withInertOnChange';\n\n/**\n * Picks one dictionary by its key and returns its content for the locale of\n * the request being rendered, read from `Astro.locals.intlayer`.\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence\n * over the request locale.\n *\n * Same signature and content shape as the client-side hook this entry resolves\n * to in the browser (`vanilla-intlayer`), so a call moves between the\n * frontmatter and a `<script>` unchanged.\n *\n * @example\n * ```astro\n * ---\n * import { useIntlayer } from 'astro-intlayer';\n *\n * const { title, description } = useIntlayer('home');\n * ---\n * <h1>{title}</h1>\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n): WithOnChange<\n DeepTransformContent<DictionaryRegistryResult<T, A>, ExtractSelectorLocale<A>>\n> =>\n withInertOnChange(\n getIntlayer<T, A>(\n key,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: getRequestLocale(),\n dictionaryKey: key as string,\n }) as A\n )\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,eAIX,KACA,qBAIA,kBACE,YACE,KACA,0BAA0B;CACxB;CACA,eAAe,iBAAiB;CAChC,eAAe;AACjB,CAAC,CACH,CACF"}
@@ -0,0 +1,40 @@
1
+ import { getRequestLocale } from "./requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+
4
+ //#region src/useLocale.ts
5
+ const { defaultLocale, locales: availableLocales } = internationalization;
6
+ /**
7
+ * Returns the locale of the request being rendered, read from
8
+ * `Astro.locals.intlayer`, with the configured default and available locales.
9
+ *
10
+ * Falls back to the default locale outside of a request, i.e. when the
11
+ * `astro-intlayer/middleware` did not run.
12
+ *
13
+ * Same shape as the client-side hook this entry resolves to in the browser
14
+ * (`vanilla-intlayer`). A request has no locale to switch, so `setLocale` and
15
+ * `subscribe` are inert here: switch the locale from a `<script>`, where the
16
+ * same import gives the client implementation.
17
+ *
18
+ * @example
19
+ * ```astro
20
+ * ---
21
+ * import { useLocale } from 'astro-intlayer';
22
+ *
23
+ * const { locale, availableLocales } = useLocale();
24
+ * ---
25
+ * <html lang={locale}>
26
+ * ```
27
+ */
28
+ const useLocale = (_props = {}) => ({
29
+ locale: getRequestLocale() ?? defaultLocale,
30
+ defaultLocale,
31
+ availableLocales,
32
+ setLocale: () => {
33
+ console.warn("[astro-intlayer] setLocale() has no effect during a server render. Call it from a client <script> instead.");
34
+ },
35
+ subscribe: () => () => {}
36
+ });
37
+
38
+ //#endregion
39
+ export { useLocale };
40
+ //# sourceMappingURL=useLocale.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.mjs","names":[],"sources":["../../src/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type {\n UseLocaleProps,\n UseLocaleResult as VanillaUseLocaleResult,\n} from 'vanilla-intlayer';\nimport { getRequestLocale } from './requestStorage';\n\nexport type { UseLocaleProps } from 'vanilla-intlayer';\n\nexport type UseLocaleResult = VanillaUseLocaleResult;\n\nconst { defaultLocale, locales: availableLocales } = internationalization;\n\n/**\n * Returns the locale of the request being rendered, read from\n * `Astro.locals.intlayer`, with the configured default and available locales.\n *\n * Falls back to the default locale outside of a request, i.e. when the\n * `astro-intlayer/middleware` did not run.\n *\n * Same shape as the client-side hook this entry resolves to in the browser\n * (`vanilla-intlayer`). A request has no locale to switch, so `setLocale` and\n * `subscribe` are inert here: switch the locale from a `<script>`, where the\n * same import gives the client implementation.\n *\n * @example\n * ```astro\n * ---\n * import { useLocale } from 'astro-intlayer';\n *\n * const { locale, availableLocales } = useLocale();\n * ---\n * <html lang={locale}>\n * ```\n */\nexport const useLocale = (_props: UseLocaleProps = {}): UseLocaleResult => ({\n locale: getRequestLocale() ?? (defaultLocale as DeclaredLocales),\n defaultLocale: defaultLocale as DeclaredLocales,\n availableLocales: availableLocales as DeclaredLocales[],\n setLocale: () => {\n console.warn(\n '[astro-intlayer] setLocale() has no effect during a server render. Call it from a client <script> instead.'\n );\n },\n subscribe: () => () => {},\n});\n"],"mappings":";;;;AAYA,MAAM,EAAE,eAAe,SAAS,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;AAwBrD,MAAa,aAAa,SAAyB,CAAC,OAAwB;CAC1E,QAAQ,iBAAiB,KAAM;CAChB;CACG;CAClB,iBAAiB;EACf,QAAQ,KACN,4GACF;CACF;CACA,uBAAuB,CAAC;AAC1B"}
@@ -0,0 +1,16 @@
1
+ //#region src/withInertOnChange.ts
2
+ /**
3
+ * Gives server-rendered content the `.onChange()` of its client counterpart.
4
+ *
5
+ * The locale cannot change during a server render, so the subscription never
6
+ * fires; it only keeps the content shape identical on both sides of the
7
+ * `astro-intlayer` entry.
8
+ */
9
+ const withInertOnChange = (content) => {
10
+ if (content !== null && typeof content === "object") content.onChange = () => content;
11
+ return content;
12
+ };
13
+
14
+ //#endregion
15
+ export { withInertOnChange };
16
+ //# sourceMappingURL=withInertOnChange.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withInertOnChange.mjs","names":[],"sources":["../../src/withInertOnChange.ts"],"sourcesContent":["import type { WithOnChange } from 'vanilla-intlayer';\n\n/**\n * Gives server-rendered content the `.onChange()` of its client counterpart.\n *\n * The locale cannot change during a server render, so the subscription never\n * fires; it only keeps the content shape identical on both sides of the\n * `astro-intlayer` entry.\n */\nexport const withInertOnChange = <T>(content: T): WithOnChange<T> => {\n // A selector can resolve to null or a primitive; only objects carry `.onChange`.\n if (content !== null && typeof content === 'object') {\n (content as WithOnChange<T>).onChange = () => content as WithOnChange<T>;\n }\n\n return content as WithOnChange<T>;\n};\n"],"mappings":";;;;;;;;AASA,MAAa,qBAAwB,YAAgC;CAEnE,IAAI,YAAY,QAAQ,OAAO,YAAY,UACzC,AAAC,QAA4B,iBAAiB;CAGhD,OAAO;AACT"}
@@ -0,0 +1,2 @@
1
+ import { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit } from "vanilla-intlayer/format";
2
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -0,0 +1,2 @@
1
+ import { DeepTransformContent, IntlayerNode, UseLocaleProps, UseLocaleResult, WithOnChange, getDictionary, getIntlayer, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage } from "vanilla-intlayer";
2
+ export { type DeepTransformContent, type IntlayerNode, type UseLocaleProps, type UseLocaleResult, type WithOnChange, getDictionary, getIntlayer, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage };
@@ -0,0 +1,10 @@
1
+ import { useCompact } from "./useCompact.js";
2
+ import { useCurrency } from "./useCurrency.js";
3
+ import { useDate } from "./useDate.js";
4
+ import { useIntl } from "./useIntl.js";
5
+ import { useList } from "./useList.js";
6
+ import { useNumber } from "./useNumber.js";
7
+ import { usePercentage } from "./usePercentage.js";
8
+ import { useRelativeTime } from "./useRelativeTime.js";
9
+ import { useUnit } from "./useUnit.js";
10
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -0,0 +1,5 @@
1
+ import { compact } from "@intlayer/core/formatters";
2
+ //#region src/format/useCompact.d.ts
3
+ export declare const useCompact: () => (...args: Parameters<typeof compact>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=useCompact.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../src/format/useCompact.ts"],"mappings":";;qBAOa,sBAAU,MAGJ,kBAAkB"}
@@ -0,0 +1,5 @@
1
+ import { currency } from "@intlayer/core/formatters";
2
+ //#region src/format/useCurrency.d.ts
3
+ export declare const useCurrency: () => (...args: Parameters<typeof currency>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=useCurrency.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../src/format/useCurrency.ts"],"mappings":";;qBAOa,uBAAW,MAGL,kBAAkB"}
@@ -0,0 +1,8 @@
1
+ import { date } from "@intlayer/core/formatters";
2
+ //#region src/format/useDate.d.ts
3
+ /**
4
+ * Astro hook that provides a localized date/time formatter bound to the request locale.
5
+ */
6
+ export declare const useDate: () => (...args: Parameters<typeof date>) => string;
7
+ //#endregion
8
+ //# sourceMappingURL=useDate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDate.d.ts","names":[],"sources":["../../../src/format/useDate.ts"],"mappings":";;;;;qBAUa,mBAAO,MAGD,kBAAkB"}
@@ -0,0 +1,15 @@
1
+ import { WrappedIntl } from "@intlayer/core/utils";
2
+ import { LocalesValues } from "@intlayer/types/module_augmentation";
3
+ //#region src/format/useIntl.d.ts
4
+ /**
5
+ * Astro hook that provides a locale-bound `Intl` object.
6
+ *
7
+ * It uses the request locale on the server, falling back to the configured
8
+ * default locale.
9
+ */
10
+ export declare const useIntl: (locale?: LocalesValues) => {
11
+ intl: WrappedIntl;
12
+ subscribe: (callback: (intl: WrappedIntl) => void) => () => void;
13
+ };
14
+ //#endregion
15
+ //# sourceMappingURL=useIntl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntl.d.ts","names":[],"sources":["../../../src/format/useIntl.ts"],"mappings":";;;;;;;;;qBAgBa,UAAO,SACT;EAET,MAAM;EACN,YAAY,WAAW,MAAM"}
@@ -0,0 +1,5 @@
1
+ import { list } from "@intlayer/core/formatters";
2
+ //#region src/format/useList.d.ts
3
+ export declare const useList: () => (...args: Parameters<typeof list>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=useList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useList.d.ts","names":[],"sources":["../../../src/format/useList.ts"],"mappings":";;qBAOa,mBAAO,MAGD,kBAAkB"}
@@ -0,0 +1,8 @@
1
+ import { number } from "@intlayer/core/formatters";
2
+ //#region src/format/useNumber.d.ts
3
+ /**
4
+ * Astro hook that provides a localized number formatter bound to the request locale.
5
+ */
6
+ export declare const useNumber: () => (...args: Parameters<typeof number>) => string;
7
+ //#endregion
8
+ //# sourceMappingURL=useNumber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../src/format/useNumber.ts"],"mappings":";;;;;qBAUa,qBAAS,MAGH,kBAAkB"}
@@ -0,0 +1,5 @@
1
+ import { percentage } from "@intlayer/core/formatters";
2
+ //#region src/format/usePercentage.d.ts
3
+ export declare const usePercentage: () => (...args: Parameters<typeof percentage>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=usePercentage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../src/format/usePercentage.ts"],"mappings":";;qBAOa,yBAAa,MAGP,kBAAkB"}
@@ -0,0 +1,5 @@
1
+ import { relativeTime } from "@intlayer/core/formatters";
2
+ //#region src/format/useRelativeTime.d.ts
3
+ export declare const useRelativeTime: () => (...args: Parameters<typeof relativeTime>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=useRelativeTime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"mappings":";;qBAOa,2BAAe,MAGT,kBAAkB"}
@@ -0,0 +1,5 @@
1
+ import { units } from "@intlayer/core/formatters";
2
+ //#region src/format/useUnit.d.ts
3
+ export declare const useUnit: () => (...args: Parameters<typeof units>) => string;
4
+ //#endregion
5
+ //# sourceMappingURL=useUnit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../src/format/useUnit.ts"],"mappings":";;qBAOa,mBAAO,MAGD,kBAAkB"}
@@ -0,0 +1,2 @@
1
+ import { HTMLComponents, IntlayerHTMLPluginOptions, IntlayerHTMLProvider, RenderHTMLFunction, RenderHTMLOptions, RenderHTMLProps, installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer } from "vanilla-intlayer/html";
2
+ export { type HTMLComponents, type IntlayerHTMLPluginOptions, type IntlayerHTMLProvider, type RenderHTMLFunction, type RenderHTMLOptions, type RenderHTMLProps, installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer };