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,67 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_emitRewrittenPages = require('./emitRewrittenPages.cjs');
3
+ let node_path = require("node:path");
4
+ let _intlayer_config_node = require("@intlayer/config/node");
5
+ let _intlayer_config_utils = require("@intlayer/config/utils");
6
+ let _intlayer_engine_build = require("@intlayer/engine/build");
7
+ let vite_intlayer = require("vite-intlayer");
8
+
9
+ //#region src/integration.ts
10
+ /**
11
+ * Keeps the intlayer packages out of Node's native module loader in *every*
12
+ * Vite environment Astro renders from.
13
+ *
14
+ * A static dev server renders from `ssr`, but other setups render from Astro's
15
+ * `astro` or `prerender` environments, and a top-level `ssr.noExternal` only
16
+ * seeds the `ssr` one. Declaring it per environment covers the rest.
17
+ */
18
+ const intlayerNoExternalEnvironments = () => ({
19
+ name: "astro-intlayer-no-external",
20
+ configEnvironment: () => ({ resolve: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] } })
21
+ });
22
+ /**
23
+ * `astro:config:setup`:
24
+ * 1. Prepares the Intlayer resources (dictionaries).
25
+ * 2. Injects the Vite plugins for aliases, locale-based routing and build
26
+ * optimizations (prune).
27
+ * 3. Configures the Vite aliases for dictionary access.
28
+ * 4. Registers the `astro-intlayer/middleware`, which resolves the request
29
+ * locale into `Astro.locals.intlayer` for the hooks.
30
+ *
31
+ * The dev-time content watcher is not started here: the bundled
32
+ * `vite-intlayer` plugin already starts one from `configureServer`, and
33
+ * `watch()` subscribes anew on every call, so doing both would rebuild each
34
+ * content edit twice.
35
+ */
36
+ const configSetup = async ({ updateConfig, addMiddleware }) => {
37
+ const configuration = (0, _intlayer_config_node.getConfiguration)();
38
+ await (0, _intlayer_engine_build.prepareIntlayer)(configuration);
39
+ addMiddleware({
40
+ entrypoint: "astro-intlayer/middleware",
41
+ order: "pre"
42
+ });
43
+ updateConfig({ vite: {
44
+ plugins: [(0, vite_intlayer.intlayer)(), intlayerNoExternalEnvironments()],
45
+ resolve: { alias: { ...(0, _intlayer_config_utils.getAlias)({
46
+ configuration,
47
+ formatter: (value) => (0, node_path.resolve)(value)
48
+ }) } },
49
+ ssr: { noExternal: [vite_intlayer.INTLAYER_NO_EXTERNAL_PATTERN] }
50
+ } });
51
+ };
52
+ /**
53
+ * `astro:build:done`: Astro renders each page from its canonical file-system
54
+ * route, so a static build has no file for the localized paths declared in
55
+ * `routing.rewrite`. Mirror them here, otherwise the URLs produced by
56
+ * `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.
57
+ */
58
+ const buildDone = async ({ dir, logger }) => {
59
+ const configuration = (0, _intlayer_config_node.getConfiguration)();
60
+ const emittedPages = await require_emitRewrittenPages.emitRewrittenPages(configuration, dir);
61
+ if (emittedPages.length > 0) logger.info(`Emitted ${emittedPages.length} rewritten page(s): ${emittedPages.map(([from, to]) => `${from} \u2192 ${to}`).join(", ")}`);
62
+ };
63
+
64
+ //#endregion
65
+ exports.buildDone = buildDone;
66
+ exports.configSetup = configSetup;
67
+ //# sourceMappingURL=integration.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.cjs","names":["INTLAYER_NO_EXTERNAL_PATTERN","getConfiguration","prepareIntlayer","viteIntlayerPlugin","getAlias","resolve","emitRewrittenPages"],"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,CAACA,0CAA4B,EAAE,EACxD;AACF;;;;;;;;;;;;;;;AAkCA,MAAa,cAAc,OAAO,EAChC,cACA,oBACuC;CACvC,MAAM,oBAAgBC,wCAAiB;CAGvC,UAAMC,wCAAgB,aAAa;CAInC,cAAc;EACZ,YAAY;EACZ,OAAO;CACT,CAAC;CAED,aAAa,EACX,MAAM;EACJ,SAAS,KACPC,wBAAmB,GACnB,+BAA+B,CACjC;EACA,SAAS,EACP,OAAO,EACL,OAAGC,iCAAS;GACV;GACA,YAAY,cAAUC,mBAAQ,KAAK;EACrC,CAAC,EACH,EACF;EAWA,KAAK,EACH,YAAY,CAACL,0CAA4B,EAC3C;CACF,EACF,CAAC;AACH;;;;;;;AAQA,MAAa,YAAY,OAAO,EAC9B,KACA,aACqC;CACrC,MAAM,oBAAgBC,wCAAiB;CAEvC,MAAM,eAAe,MAAMK,8CAAmB,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,45 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let vanilla_intlayer_markdown = require("vanilla-intlayer/markdown");
3
+
4
+ Object.defineProperty(exports, 'compileMarkdown', {
5
+ enumerable: true,
6
+ get: function () {
7
+ return vanilla_intlayer_markdown.compileMarkdown;
8
+ }
9
+ });
10
+ Object.defineProperty(exports, 'installIntlayerMarkdown', {
11
+ enumerable: true,
12
+ get: function () {
13
+ return vanilla_intlayer_markdown.installIntlayerMarkdown;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, 'installIntlayerMarkdownDynamic', {
17
+ enumerable: true,
18
+ get: function () {
19
+ return vanilla_intlayer_markdown.installIntlayerMarkdownDynamic;
20
+ }
21
+ });
22
+ Object.defineProperty(exports, 'parseMarkdown', {
23
+ enumerable: true,
24
+ get: function () {
25
+ return vanilla_intlayer_markdown.parseMarkdown;
26
+ }
27
+ });
28
+ Object.defineProperty(exports, 'renderMarkdown', {
29
+ enumerable: true,
30
+ get: function () {
31
+ return vanilla_intlayer_markdown.renderMarkdown;
32
+ }
33
+ });
34
+ Object.defineProperty(exports, 'useMarkdown', {
35
+ enumerable: true,
36
+ get: function () {
37
+ return vanilla_intlayer_markdown.useMarkdown;
38
+ }
39
+ });
40
+ Object.defineProperty(exports, 'useMarkdownRenderer', {
41
+ enumerable: true,
42
+ get: function () {
43
+ return vanilla_intlayer_markdown.useMarkdownRenderer;
44
+ }
45
+ });
@@ -0,0 +1,43 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_requestStorage = require('./requestStorage.cjs');
3
+ let _intlayer_core_localization = require("@intlayer/core/localization");
4
+ let _intlayer_config_built = require("@intlayer/config/built");
5
+
6
+ //#region src/middleware.ts
7
+ /**
8
+ * Astro middleware resolving the request locale into `Astro.locals.intlayer`.
9
+ *
10
+ * Priority: the URL (path prefix or `?locale=` search param, in every routing
11
+ * mode but `no-prefix`), then the locale persisted by the client (cookie or
12
+ * custom header), then `Accept-Language` negotiation.
13
+ *
14
+ * The `intlayer()` integration registers it automatically, before the user
15
+ * middleware, so `Astro.locals.intlayer` is available in every page, endpoint
16
+ * and middleware. The rest of the request renders inside an
17
+ * `AsyncLocalStorage` scope bound to those locals, which is how the hooks of
18
+ * `astro-intlayer/server` read the locale with no argument.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * // src/middleware.ts — only needed when composing it by hand
23
+ * import { onRequest as intlayer } from 'astro-intlayer/middleware';
24
+ * import { sequence } from 'astro:middleware';
25
+ *
26
+ * export const onRequest = sequence(intlayer, myMiddleware);
27
+ * ```
28
+ */
29
+ const onRequest = async (context, next) => {
30
+ context.locals.intlayer = {
31
+ locale: await (0, _intlayer_core_localization.getLocaleFromRequest)({
32
+ url: context.url,
33
+ headers: context.isPrerendered ? new Headers() : context.request.headers
34
+ }),
35
+ defaultLocale: _intlayer_config_built.internationalization.defaultLocale,
36
+ availableLocales: _intlayer_config_built.internationalization.locales
37
+ };
38
+ return require_requestStorage.requestStorage.run(context.locals, next);
39
+ };
40
+
41
+ //#endregion
42
+ exports.onRequest = onRequest;
43
+ //# sourceMappingURL=middleware.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.cjs","names":["getLocaleFromRequest","internationalization","requestStorage"],"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,UAAMA,kDAAqB;GACjC,KAAK,QAAQ;GAIb,SAAS,QAAQ,gBAAgB,IAAI,QAAQ,IAAI,QAAQ,QAAQ;EACnE,CAAC;EACD,eAAeC,4CAAqB;EACpC,kBAAkBA,4CAAqB;CACzC;CAEA,OAAOC,sCAAe,IAAI,QAAQ,QAAQ,IAAI;AAChD"}
@@ -0,0 +1,24 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let node_async_hooks = require("node:async_hooks");
3
+
4
+ //#region src/requestStorage.ts
5
+ /**
6
+ * `Astro.locals` of the request being rendered, made available to every
7
+ * function running inside the middleware scope — page and component
8
+ * frontmatter, endpoints, nested middleware — without passing `Astro` around.
9
+ */
10
+ const requestStorage = new node_async_hooks.AsyncLocalStorage();
11
+ /**
12
+ * Returns the Intlayer locals of the request being rendered, if any.
13
+ */
14
+ const getIntlayerLocals = () => requestStorage.getStore()?.intlayer;
15
+ /**
16
+ * Returns the locale of the request being rendered, if any.
17
+ */
18
+ const getRequestLocale = () => getIntlayerLocals()?.locale;
19
+
20
+ //#endregion
21
+ exports.getIntlayerLocals = getIntlayerLocals;
22
+ exports.getRequestLocale = getRequestLocale;
23
+ exports.requestStorage = requestStorage;
24
+ //# sourceMappingURL=requestStorage.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestStorage.cjs","names":["AsyncLocalStorage"],"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,IAAIA,mCAE/B;;;;AAKH,MAAa,0BACX,eAAe,SAAS,CAAC,EAAE;;;;AAK7B,MAAa,yBACX,kBAAkB,CAAC,EAAE"}
@@ -0,0 +1,38 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_requestStorage = require('./requestStorage.cjs');
3
+ const require_withInertOnChange = require('./withInertOnChange.cjs');
4
+ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
5
+ let vanilla_intlayer = require("vanilla-intlayer");
6
+
7
+ //#region src/useDictionary.ts
8
+ /**
9
+ * Transforms an imported dictionary (or qualified dictionary group) and returns
10
+ * its content for the locale of the request being rendered, read from
11
+ * `Astro.locals.intlayer`.
12
+ *
13
+ * The second argument is either a locale or a selector object
14
+ * (`{ item }`, `{ variant }`, optionally with `locale`); it takes precedence
15
+ * over the request locale.
16
+ *
17
+ * Same signature and content shape as the client-side hook this entry resolves
18
+ * to in the browser (`vanilla-intlayer`).
19
+ *
20
+ * @example
21
+ * ```astro
22
+ * ---
23
+ * import { useDictionary } from 'astro-intlayer';
24
+ * import homeContent from '../content/home.content';
25
+ *
26
+ * const { title } = useDictionary(homeContent);
27
+ * ---
28
+ * ```
29
+ */
30
+ const useDictionary = (dictionary, localeOrSelector) => require_withInertOnChange.withInertOnChange((0, vanilla_intlayer.getDictionary)(dictionary, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
31
+ localeOrSelector,
32
+ contextLocale: require_requestStorage.getRequestLocale(),
33
+ dictionaryKey: dictionary.key
34
+ })));
35
+
36
+ //#endregion
37
+ exports.useDictionary = useDictionary;
38
+ //# sourceMappingURL=useDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.cjs","names":["withInertOnChange","getDictionary","resolveDictionaryArgument","getRequestLocale"],"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,qBAOAA,gDACEC,gCACE,gBACAC,gEAA0B;CACxB;CACA,eAAeC,wCAAiB;CAChC,eAAe,WAAW;AAC5B,CAAC,CACH,CACF"}
@@ -0,0 +1,38 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_requestStorage = require('./requestStorage.cjs');
3
+ const require_withInertOnChange = require('./withInertOnChange.cjs');
4
+ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
5
+ let vanilla_intlayer = require("vanilla-intlayer");
6
+
7
+ //#region src/useIntlayer.ts
8
+ /**
9
+ * Picks one dictionary by its key and returns its content for the locale of
10
+ * the request being rendered, read from `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`), so a call moves between the
18
+ * frontmatter and a `<script>` unchanged.
19
+ *
20
+ * @example
21
+ * ```astro
22
+ * ---
23
+ * import { useIntlayer } from 'astro-intlayer';
24
+ *
25
+ * const { title, description } = useIntlayer('home');
26
+ * ---
27
+ * <h1>{title}</h1>
28
+ * ```
29
+ */
30
+ const useIntlayer = (key, localeOrSelector) => require_withInertOnChange.withInertOnChange((0, vanilla_intlayer.getIntlayer)(key, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
31
+ localeOrSelector,
32
+ contextLocale: require_requestStorage.getRequestLocale(),
33
+ dictionaryKey: key
34
+ })));
35
+
36
+ //#endregion
37
+ exports.useIntlayer = useIntlayer;
38
+ //# sourceMappingURL=useIntlayer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntlayer.cjs","names":["withInertOnChange","getIntlayer","resolveDictionaryArgument","getRequestLocale"],"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,qBAIAA,gDACEC,8BACE,SACAC,gEAA0B;CACxB;CACA,eAAeC,wCAAiB;CAChC,eAAe;AACjB,CAAC,CACH,CACF"}
@@ -0,0 +1,41 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_requestStorage = require('./requestStorage.cjs');
3
+ let _intlayer_config_built = require("@intlayer/config/built");
4
+
5
+ //#region src/useLocale.ts
6
+ const { defaultLocale, locales: availableLocales } = _intlayer_config_built.internationalization;
7
+ /**
8
+ * Returns the locale of the request being rendered, read from
9
+ * `Astro.locals.intlayer`, with the configured default and available locales.
10
+ *
11
+ * Falls back to the default locale outside of a request, i.e. when the
12
+ * `astro-intlayer/middleware` did not run.
13
+ *
14
+ * Same shape as the client-side hook this entry resolves to in the browser
15
+ * (`vanilla-intlayer`). A request has no locale to switch, so `setLocale` and
16
+ * `subscribe` are inert here: switch the locale from a `<script>`, where the
17
+ * same import gives the client implementation.
18
+ *
19
+ * @example
20
+ * ```astro
21
+ * ---
22
+ * import { useLocale } from 'astro-intlayer';
23
+ *
24
+ * const { locale, availableLocales } = useLocale();
25
+ * ---
26
+ * <html lang={locale}>
27
+ * ```
28
+ */
29
+ const useLocale = (_props = {}) => ({
30
+ locale: require_requestStorage.getRequestLocale() ?? defaultLocale,
31
+ defaultLocale,
32
+ availableLocales,
33
+ setLocale: () => {
34
+ console.warn("[astro-intlayer] setLocale() has no effect during a server render. Call it from a client <script> instead.");
35
+ },
36
+ subscribe: () => () => {}
37
+ });
38
+
39
+ //#endregion
40
+ exports.useLocale = useLocale;
41
+ //# sourceMappingURL=useLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.cjs","names":["internationalization","getRequestLocale"],"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,qBAAqBA;;;;;;;;;;;;;;;;;;;;;;;AAwBrD,MAAa,aAAa,SAAyB,CAAC,OAAwB;CAC1E,QAAQC,wCAAiB,KAAM;CAChB;CACG;CAClB,iBAAiB;EACf,QAAQ,KACN,4GACF;CACF;CACA,uBAAuB,CAAC;AAC1B"}
@@ -0,0 +1,17 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region src/withInertOnChange.ts
3
+ /**
4
+ * Gives server-rendered content the `.onChange()` of its client counterpart.
5
+ *
6
+ * The locale cannot change during a server render, so the subscription never
7
+ * fires; it only keeps the content shape identical on both sides of the
8
+ * `astro-intlayer` entry.
9
+ */
10
+ const withInertOnChange = (content) => {
11
+ if (content !== null && typeof content === "object") content.onChange = () => content;
12
+ return content;
13
+ };
14
+
15
+ //#endregion
16
+ exports.withInertOnChange = withInertOnChange;
17
+ //# sourceMappingURL=withInertOnChange.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withInertOnChange.cjs","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,3 @@
1
+ import { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit } from "vanilla-intlayer/format";
2
+
3
+ export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
@@ -0,0 +1,3 @@
1
+ import { getDictionary, getIntlayer, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage } from "vanilla-intlayer";
2
+
3
+ export { getDictionary, getIntlayer, installIntlayer, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useDictionary, useDictionaryDynamic, useIntlayer, useLocale, useLocaleCookie, useLocaleStorage };
@@ -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"}