astro-intlayer 9.5.4 → 9.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/_virtual/_rolldown/runtime.cjs +28 -0
  3. package/dist/cjs/client/format/index.cjs +57 -0
  4. package/dist/cjs/client/index.cjs +81 -0
  5. package/dist/cjs/client/localeRedirect.cjs +64 -0
  6. package/dist/cjs/client/localeRedirect.cjs.map +1 -0
  7. package/dist/cjs/format/index.cjs +20 -0
  8. package/dist/cjs/format/useCompact.cjs +18 -0
  9. package/dist/cjs/format/useCompact.cjs.map +1 -0
  10. package/dist/cjs/format/useCurrency.cjs +18 -0
  11. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  12. package/dist/cjs/format/useDate.cjs +27 -0
  13. package/dist/cjs/format/useDate.cjs.map +1 -0
  14. package/dist/cjs/format/useIntl.cjs +24 -0
  15. package/dist/cjs/format/useIntl.cjs.map +1 -0
  16. package/dist/cjs/format/useList.cjs +18 -0
  17. package/dist/cjs/format/useList.cjs.map +1 -0
  18. package/dist/cjs/format/useNumber.cjs +21 -0
  19. package/dist/cjs/format/useNumber.cjs.map +1 -0
  20. package/dist/cjs/format/usePercentage.cjs +18 -0
  21. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  22. package/dist/cjs/format/useRelativeTime.cjs +18 -0
  23. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  24. package/dist/cjs/format/useUnit.cjs +18 -0
  25. package/dist/cjs/format/useUnit.cjs.map +1 -0
  26. package/dist/cjs/html/index.cjs +33 -0
  27. package/dist/cjs/index.cjs +33 -35
  28. package/dist/cjs/index.cjs.map +1 -1
  29. package/dist/cjs/integration.cjs +77 -0
  30. package/dist/cjs/integration.cjs.map +1 -0
  31. package/dist/cjs/markdown/index.cjs +45 -0
  32. package/dist/cjs/middleware.cjs +103 -0
  33. package/dist/cjs/middleware.cjs.map +1 -0
  34. package/dist/cjs/requestStorage.cjs +24 -0
  35. package/dist/cjs/requestStorage.cjs.map +1 -0
  36. package/dist/cjs/useDictionary.cjs +38 -0
  37. package/dist/cjs/useDictionary.cjs.map +1 -0
  38. package/dist/cjs/useIntlayer.cjs +38 -0
  39. package/dist/cjs/useIntlayer.cjs.map +1 -0
  40. package/dist/cjs/useLocale.cjs +41 -0
  41. package/dist/cjs/useLocale.cjs.map +1 -0
  42. package/dist/cjs/withInertOnChange.cjs +17 -0
  43. package/dist/cjs/withInertOnChange.cjs.map +1 -0
  44. package/dist/esm/client/format/index.mjs +3 -0
  45. package/dist/esm/client/index.mjs +3 -0
  46. package/dist/esm/client/localeRedirect.mjs +62 -0
  47. package/dist/esm/client/localeRedirect.mjs.map +1 -0
  48. package/dist/esm/format/index.mjs +11 -0
  49. package/dist/esm/format/useCompact.mjs +17 -0
  50. package/dist/esm/format/useCompact.mjs.map +1 -0
  51. package/dist/esm/format/useCurrency.mjs +17 -0
  52. package/dist/esm/format/useCurrency.mjs.map +1 -0
  53. package/dist/esm/format/useDate.mjs +26 -0
  54. package/dist/esm/format/useDate.mjs.map +1 -0
  55. package/dist/esm/format/useIntl.mjs +23 -0
  56. package/dist/esm/format/useIntl.mjs.map +1 -0
  57. package/dist/esm/format/useList.mjs +17 -0
  58. package/dist/esm/format/useList.mjs.map +1 -0
  59. package/dist/esm/format/useNumber.mjs +20 -0
  60. package/dist/esm/format/useNumber.mjs.map +1 -0
  61. package/dist/esm/format/usePercentage.mjs +17 -0
  62. package/dist/esm/format/usePercentage.mjs.map +1 -0
  63. package/dist/esm/format/useRelativeTime.mjs +17 -0
  64. package/dist/esm/format/useRelativeTime.mjs.map +1 -0
  65. package/dist/esm/format/useUnit.mjs +17 -0
  66. package/dist/esm/format/useUnit.mjs.map +1 -0
  67. package/dist/esm/html/index.mjs +3 -0
  68. package/dist/esm/index.mjs +30 -36
  69. package/dist/esm/index.mjs.map +1 -1
  70. package/dist/esm/integration.mjs +75 -0
  71. package/dist/esm/integration.mjs.map +1 -0
  72. package/dist/esm/markdown/index.mjs +3 -0
  73. package/dist/esm/middleware.mjs +100 -0
  74. package/dist/esm/middleware.mjs.map +1 -0
  75. package/dist/esm/requestStorage.mjs +21 -0
  76. package/dist/esm/requestStorage.mjs.map +1 -0
  77. package/dist/esm/useDictionary.mjs +37 -0
  78. package/dist/esm/useDictionary.mjs.map +1 -0
  79. package/dist/esm/useIntlayer.mjs +37 -0
  80. package/dist/esm/useIntlayer.mjs.map +1 -0
  81. package/dist/esm/useLocale.mjs +40 -0
  82. package/dist/esm/useLocale.mjs.map +1 -0
  83. package/dist/esm/withInertOnChange.mjs +16 -0
  84. package/dist/esm/withInertOnChange.mjs.map +1 -0
  85. package/dist/types/client/format/index.d.ts +2 -0
  86. package/dist/types/client/index.d.ts +2 -0
  87. package/dist/types/client/localeRedirect.d.ts +26 -0
  88. package/dist/types/client/localeRedirect.d.ts.map +1 -0
  89. package/dist/types/format/index.d.ts +10 -0
  90. package/dist/types/format/useCompact.d.ts +5 -0
  91. package/dist/types/format/useCompact.d.ts.map +1 -0
  92. package/dist/types/format/useCurrency.d.ts +5 -0
  93. package/dist/types/format/useCurrency.d.ts.map +1 -0
  94. package/dist/types/format/useDate.d.ts +8 -0
  95. package/dist/types/format/useDate.d.ts.map +1 -0
  96. package/dist/types/format/useIntl.d.ts +15 -0
  97. package/dist/types/format/useIntl.d.ts.map +1 -0
  98. package/dist/types/format/useList.d.ts +5 -0
  99. package/dist/types/format/useList.d.ts.map +1 -0
  100. package/dist/types/format/useNumber.d.ts +8 -0
  101. package/dist/types/format/useNumber.d.ts.map +1 -0
  102. package/dist/types/format/usePercentage.d.ts +5 -0
  103. package/dist/types/format/usePercentage.d.ts.map +1 -0
  104. package/dist/types/format/useRelativeTime.d.ts +5 -0
  105. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  106. package/dist/types/format/useUnit.d.ts +5 -0
  107. package/dist/types/format/useUnit.d.ts.map +1 -0
  108. package/dist/types/html/index.d.ts +2 -0
  109. package/dist/types/index.d.ts +13 -6
  110. package/dist/types/index.d.ts.map +1 -1
  111. package/dist/types/integration.d.ts +41 -0
  112. package/dist/types/integration.d.ts.map +1 -0
  113. package/dist/types/markdown/index.d.ts +2 -0
  114. package/dist/types/middleware.d.ts +54 -0
  115. package/dist/types/middleware.d.ts.map +1 -0
  116. package/dist/types/requestStorage.d.ts +22 -0
  117. package/dist/types/requestStorage.d.ts.map +1 -0
  118. package/dist/types/useDictionary.d.ts +29 -0
  119. package/dist/types/useDictionary.d.ts.map +1 -0
  120. package/dist/types/useIntlayer.d.ts +28 -0
  121. package/dist/types/useIntlayer.d.ts.map +1 -0
  122. package/dist/types/useLocale.d.ts +29 -0
  123. package/dist/types/useLocale.d.ts.map +1 -0
  124. package/dist/types/withInertOnChange.d.ts +12 -0
  125. package/dist/types/withInertOnChange.d.ts.map +1 -0
  126. package/package.json +96 -6
@@ -0,0 +1,100 @@
1
+ import { requestStorage } from "./requestStorage.mjs";
2
+ import { getLocaleFromRequest, resolveProxyMode } from "@intlayer/core/localization";
3
+ import * as builtConfiguration from "@intlayer/config/built";
4
+ import { createIntlayerWebProxyHandler } from "vite-intlayer/web-proxy-handler";
5
+
6
+ //#region src/middleware.ts
7
+ /**
8
+ * Whether `astro dev` is serving the app. Vite inlines `import.meta.env.DEV`
9
+ * into the server bundle; the optional chain keeps the module loadable where
10
+ * no bundler defines it (`process.env.NODE_ENV` cannot be used instead: the
11
+ * package build inlines it).
12
+ */
13
+ const isDevServer = import.meta.env?.DEV === true;
14
+ const configuration = builtConfiguration;
15
+ const { internationalization: internationalization$1, routing: routing$1 } = configuration;
16
+ /**
17
+ * Locale-routing proxy shared with the Vite dev server and the Nitro handler.
18
+ *
19
+ * `undefined` when `routing.enableProxy` is `false`. In auto mode (option
20
+ * unset) `astro dev` keeps routing URL-driven: the stored locale is not a
21
+ * redirect source, exactly like the Vite proxy mounted on the same dev server,
22
+ * so the two never disagree.
23
+ */
24
+ const proxy = resolveProxyMode(routing$1.enableProxy) === "disabled" ? void 0 : createIntlayerWebProxyHandler({
25
+ configuration,
26
+ isDevServer
27
+ });
28
+ /**
29
+ * Appends the headers the proxy produced (the persisted locale cookie) to the
30
+ * rendered response. Some responses ship immutable headers, in which case the
31
+ * body is re-wrapped in a fresh `Response`.
32
+ */
33
+ const withProxyHeaders = (response, headers) => {
34
+ const entries = [...headers];
35
+ if (entries.length === 0) return response;
36
+ const applyHeaders = (target) => {
37
+ for (const [name, value] of entries) target.headers.append(name, value);
38
+ return target;
39
+ };
40
+ try {
41
+ return applyHeaders(response);
42
+ } catch {
43
+ return applyHeaders(new Response(response.body, response));
44
+ }
45
+ };
46
+ /**
47
+ * Astro middleware resolving the request locale into `Astro.locals.intlayer`.
48
+ *
49
+ * Priority: the URL (path prefix or `?locale=` search param, in every routing
50
+ * mode but `no-prefix`), then the locale persisted by the client (cookie or
51
+ * custom header), then `Accept-Language` negotiation.
52
+ *
53
+ * On server-rendered requests it also runs the Intlayer locale-routing proxy,
54
+ * so a visitor whose stored locale is `fr` is redirected from `/` to `/fr`
55
+ * (per `routing.mode`) and the resolved locale is persisted on the response.
56
+ * Only redirects are honoured: the proxy's internal rewrites target
57
+ * prefix-based routers, while Astro pages already resolve the locale from the
58
+ * URL they are rendered for. Prerendered pages are served as static files, so
59
+ * nothing can redirect them at request time and the proxy is skipped.
60
+ *
61
+ * The `intlayer()` integration registers it automatically, before the user
62
+ * middleware, so `Astro.locals.intlayer` is available in every page, endpoint
63
+ * and middleware. The rest of the request renders inside an
64
+ * `AsyncLocalStorage` scope bound to those locals, which is how the hooks of
65
+ * `astro-intlayer/server` read the locale with no argument.
66
+ *
67
+ * @example
68
+ * ```ts
69
+ * // src/middleware.ts — only needed when composing it by hand
70
+ * import { onRequest as intlayer } from 'astro-intlayer/middleware';
71
+ * import { sequence } from 'astro:middleware';
72
+ *
73
+ * export const onRequest = sequence(intlayer, myMiddleware);
74
+ * ```
75
+ */
76
+ const onRequest = async (context, next) => {
77
+ let proxyOutcome;
78
+ if (proxy && !context.isPrerendered) {
79
+ const outcome = proxy({
80
+ url: context.url,
81
+ headers: context.request.headers
82
+ });
83
+ if (outcome.kind === "response") return outcome.response;
84
+ proxyOutcome = outcome;
85
+ }
86
+ context.locals.intlayer = {
87
+ locale: await getLocaleFromRequest({
88
+ url: context.url,
89
+ headers: context.isPrerendered ? new Headers() : context.request.headers
90
+ }),
91
+ defaultLocale: internationalization$1.defaultLocale,
92
+ availableLocales: internationalization$1.locales
93
+ };
94
+ const response = await requestStorage.run(context.locals, next);
95
+ return proxyOutcome ? withProxyHeaders(response, proxyOutcome.headers) : response;
96
+ };
97
+
98
+ //#endregion
99
+ export { onRequest };
100
+ //# sourceMappingURL=middleware.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.mjs","names":["routing","internationalization"],"sources":["../../src/middleware.ts"],"sourcesContent":["import * as builtConfiguration from '@intlayer/config/built';\nimport {\n getLocaleFromRequest,\n resolveProxyMode,\n} from '@intlayer/core/localization';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type { MiddlewareHandler } from 'astro';\nimport {\n createIntlayerWebProxyHandler,\n type WebProxyOutcome,\n} from 'vite-intlayer/web-proxy-handler';\nimport { requestStorage } from './requestStorage';\n\n/** Proxy outcome letting the request continue to the page. */\ntype WebProxyNextOutcome = Extract<WebProxyOutcome, { kind: 'next' }>;\n\n/**\n * Whether `astro dev` is serving the app. Vite inlines `import.meta.env.DEV`\n * into the server bundle; the optional chain keeps the module loadable where\n * no bundler defines it (`process.env.NODE_ENV` cannot be used instead: the\n * package build inlines it).\n */\nconst isDevServer =\n (import.meta as { env?: { DEV?: boolean } }).env?.DEV === true;\n\nconst configuration = builtConfiguration as unknown as IntlayerConfig;\nconst { internationalization, routing } = configuration;\n\n/**\n * Locale-routing proxy shared with the Vite dev server and the Nitro handler.\n *\n * `undefined` when `routing.enableProxy` is `false`. In auto mode (option\n * unset) `astro dev` keeps routing URL-driven: the stored locale is not a\n * redirect source, exactly like the Vite proxy mounted on the same dev server,\n * so the two never disagree.\n */\nconst proxy =\n resolveProxyMode(routing.enableProxy) === 'disabled'\n ? undefined\n : createIntlayerWebProxyHandler({\n configuration,\n isDevServer,\n });\n\n/**\n * Appends the headers the proxy produced (the persisted locale cookie) to the\n * rendered response. Some responses ship immutable headers, in which case the\n * body is re-wrapped in a fresh `Response`.\n */\nconst withProxyHeaders = (response: Response, headers: Headers): Response => {\n const entries = [...headers];\n if (entries.length === 0) return response;\n\n const applyHeaders = (target: Response) => {\n for (const [name, value] of entries) {\n target.headers.append(name, value);\n }\n return target;\n };\n\n try {\n return applyHeaders(response);\n } catch {\n return applyHeaders(new Response(response.body, response));\n }\n};\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 * On server-rendered requests it also runs the Intlayer locale-routing proxy,\n * so a visitor whose stored locale is `fr` is redirected from `/` to `/fr`\n * (per `routing.mode`) and the resolved locale is persisted on the response.\n * Only redirects are honoured: the proxy's internal rewrites target\n * prefix-based routers, while Astro pages already resolve the locale from the\n * URL they are rendered for. Prerendered pages are served as static files, so\n * nothing can redirect them at request time and the proxy is skipped.\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 let proxyOutcome: WebProxyNextOutcome | undefined;\n\n if (proxy && !context.isPrerendered) {\n const outcome = proxy({\n url: context.url,\n headers: context.request.headers,\n });\n\n if (outcome.kind === 'response') return outcome.response;\n proxyOutcome = outcome;\n }\n\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 const response = await requestStorage.run(context.locals, next);\n\n return proxyOutcome\n ? withProxyHeaders(response, proxyOutcome.headers)\n : response;\n};\n"],"mappings":";;;;;;;;;;;;AAuBA,MAAM,cACH,YAA4C,KAAK,QAAQ;AAE5D,MAAM,gBAAgB;AACtB,MAAM,EAAE,8CAAsB,uBAAY;;;;;;;;;AAU1C,MAAM,QACJ,iBAAiBA,UAAQ,WAAW,MAAM,aACtC,SACA,8BAA8B;CAC5B;CACA;AACF,CAAC;;;;;;AAOP,MAAM,oBAAoB,UAAoB,YAA+B;CAC3E,MAAM,UAAU,CAAC,GAAG,OAAO;CAC3B,IAAI,QAAQ,WAAW,GAAG,OAAO;CAEjC,MAAM,gBAAgB,WAAqB;EACzC,KAAK,MAAM,CAAC,MAAM,UAAU,SAC1B,OAAO,QAAQ,OAAO,MAAM,KAAK;EAEnC,OAAO;CACT;CAEA,IAAI;EACF,OAAO,aAAa,QAAQ;CAC9B,QAAQ;EACN,OAAO,aAAa,IAAI,SAAS,SAAS,MAAM,QAAQ,CAAC;CAC3D;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,MAAa,YAA+B,OAAO,SAAS,SAAS;CACnE,IAAI;CAEJ,IAAI,SAAS,CAAC,QAAQ,eAAe;EACnC,MAAM,UAAU,MAAM;GACpB,KAAK,QAAQ;GACb,SAAS,QAAQ,QAAQ;EAC3B,CAAC;EAED,IAAI,QAAQ,SAAS,YAAY,OAAO,QAAQ;EAChD,eAAe;CACjB;CAEA,QAAQ,OAAO,WAAW;EACxB,QAAQ,MAAM,qBAAqB;GACjC,KAAK,QAAQ;GAIb,SAAS,QAAQ,gBAAgB,IAAI,QAAQ,IAAI,QAAQ,QAAQ;EACnE,CAAC;EACD,eAAeC,uBAAqB;EACpC,kBAAkBA,uBAAqB;CACzC;CAEA,MAAM,WAAW,MAAM,eAAe,IAAI,QAAQ,QAAQ,IAAI;CAE9D,OAAO,eACH,iBAAiB,UAAU,aAAa,OAAO,IAC/C;AACN"}
@@ -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,26 @@
1
+ //#region src/client/localeRedirect.d.ts
2
+ /**
3
+ * Computes where a prerendered page should send the visitor so it matches the
4
+ * locale they stored (cookie, localStorage or sessionStorage, per
5
+ * `routing.storage`).
6
+ *
7
+ * Mirrors the redirect the Intlayer proxy performs on server-rendered requests,
8
+ * for pages served as static files where no server can read the cookie:
9
+ * - the URL wins over storage, so a localized URL is never redirected;
10
+ * - `routing.enableProxy: false` and `no-prefix` routing disable it;
11
+ * - in auto mode a dev server keeps routing URL-driven, like the proxy.
12
+ *
13
+ * @param url - The URL of the current page.
14
+ * @param isDevServer - Whether `astro dev` is serving the page.
15
+ * @returns The localized URL to navigate to, or `undefined` to stay put.
16
+ */
17
+ export declare const getStoredLocaleRedirect: (url: URL, isDevServer: boolean) => string | undefined;
18
+ /**
19
+ * Sends the visitor of a prerendered page to the URL of their stored locale.
20
+ *
21
+ * Injected on every page by the `intlayer()` integration; a no-op once the URL
22
+ * already names a locale, so a redirected page does not redirect again.
23
+ */
24
+ export declare const redirectToStoredLocale: () => void;
25
+ //#endregion
26
+ //# sourceMappingURL=localeRedirect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"localeRedirect.d.ts","names":[],"sources":["../../../src/client/localeRedirect.ts"],"mappings":";;;;;;;;;;;;;;;;qBAwCa,0BAAuB,KAC7B,KAAG;;;;;;;qBAoCG"}
@@ -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 };
@@ -1,3 +1,8 @@
1
+ import { IntlayerLocals } from "./middleware.js";
2
+ import { getIntlayerLocals } from "./requestStorage.js";
3
+ import { useDictionary } from "./useDictionary.js";
4
+ import { useIntlayer } from "./useIntlayer.js";
5
+ import { UseLocaleProps, UseLocaleResult, useLocale } from "./useLocale.js";
1
6
  import { AstroIntegration } from "astro";
2
7
  //#region src/index.d.ts
3
8
  /**
@@ -7,12 +12,14 @@ import { AstroIntegration } from "astro";
7
12
  * 1. Preparing Intlayer resources (dictionaries) at config setup.
8
13
  * 2. Injecting Vite plugins for aliases, locale-based routing (middleware), and build optimizations (prune).
9
14
  * 3. Configuring Vite aliases for dictionary access.
10
- * 4. Emitting the prerendered pages at their rewritten (localized) URLs.
15
+ * 4. Registering the `astro-intlayer/middleware`, which resolves the request
16
+ * locale into `Astro.locals.intlayer` for the `useLocale` / `useIntlayer` /
17
+ * `useDictionary` hooks of this package.
18
+ * 5. Emitting the prerendered pages at their rewritten (localized) URLs.
11
19
  *
12
- * The dev-time content watcher is not started here: the bundled
13
- * `vite-intlayer` plugin already starts one from `configureServer`, and
14
- * `watch()` subscribes anew on every call, so doing both would rebuild each
15
- * content edit twice.
20
+ * The implementation is loaded lazily: this entry is also the one pages import
21
+ * their hooks from, and it must not drag the Node-only tooling into their
22
+ * server bundle.
16
23
  *
17
24
  * @returns An Astro integration object.
18
25
  *
@@ -29,5 +36,5 @@ import { AstroIntegration } from "astro";
29
36
  */
30
37
  export declare const intlayer: () => AstroIntegration;
31
38
  //#endregion
32
- export { intlayer as default };
39
+ export { type IntlayerLocals, type UseLocaleProps, type UseLocaleResult, intlayer as default, getIntlayerLocals, useDictionary, useIntlayer, useLocale };
33
40
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsDa,gBAAe"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAqDa,gBAAe"}
@@ -0,0 +1,41 @@
1
+ import { AstroIntegration } from "astro";
2
+ //#region src/integration.d.ts
3
+ /**
4
+ * Node-only half of the integration, loaded lazily by the `astro-intlayer`
5
+ * entry when a hook runs.
6
+ *
7
+ * Pages import their hooks from that same entry, and Astro bundles the whole
8
+ * package into the server build (`ssr.noExternal`), so the config loader,
9
+ * `@intlayer/engine` and `vite-intlayer` must stay behind a dynamic import:
10
+ * a static one would put them in the module graph of every page.
11
+ */
12
+ type ConfigSetupOptions = Parameters<NonNullable<AstroIntegration['hooks']['astro:config:setup']>>[0];
13
+ type BuildDoneOptions = Parameters<NonNullable<AstroIntegration['hooks']['astro:build:done']>>[0];
14
+ /**
15
+ * `astro:config:setup`:
16
+ * 1. Prepares the Intlayer resources (dictionaries).
17
+ * 2. Injects the Vite plugins for aliases, locale-based routing and build
18
+ * optimizations (prune).
19
+ * 3. Configures the Vite aliases for dictionary access.
20
+ * 4. Registers the `astro-intlayer/middleware`, which resolves the request
21
+ * locale into `Astro.locals.intlayer` for the hooks and redirects
22
+ * server-rendered requests to the visitor's locale.
23
+ * 5. Injects the client-side locale redirect, which does the same for
24
+ * prerendered pages: served as static files, nothing else can read the
25
+ * stored locale there.
26
+ *
27
+ * The dev-time content watcher is not started here: the bundled
28
+ * `vite-intlayer` plugin already starts one from `configureServer`, and
29
+ * `watch()` subscribes anew on every call, so doing both would rebuild each
30
+ * content edit twice.
31
+ */
32
+ export declare const configSetup: ({ command, updateConfig, addMiddleware, injectScript }: ConfigSetupOptions) => Promise<void>;
33
+ /**
34
+ * `astro:build:done`: Astro renders each page from its canonical file-system
35
+ * route, so a static build has no file for the localized paths declared in
36
+ * `routing.rewrite`. Mirror them here, otherwise the URLs produced by
37
+ * `getLocalizedUrl` (links, hreflang, sitemap) 404 once deployed.
38
+ */
39
+ export declare const buildDone: ({ dir, logger }: BuildDoneOptions) => Promise<void>;
40
+ //#endregion
41
+ //# sourceMappingURL=integration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"integration.d.ts","names":[],"sources":["../../src/integration.ts"],"mappings":";;;;;;;;;;;KA0CK,qBAAqB,WACxB,YAAY;KAGT,mBAAmB,WACtB,YAAY;;;;;;;;;;;;;;;;;;;qBAqBD,gBAAW,SAAA,cAAA,eAAA,gBAKrB,uBAAqB;;;;;;;qBAsEX,cAAS,KAAA,UAGnB,qBAAmB"}
@@ -0,0 +1,2 @@
1
+ import { IntlayerMarkdownPluginOptions, IntlayerMarkdownProvider, MarkdownCompilerOptions, MarkdownProviderOptions, ParsedMarkdown, RenderMarkdownFunction, RenderMarkdownProps, compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer } from "vanilla-intlayer/markdown";
2
+ export { type IntlayerMarkdownPluginOptions, type IntlayerMarkdownProvider, type MarkdownCompilerOptions, type MarkdownProviderOptions, type ParsedMarkdown, type RenderMarkdownFunction, type RenderMarkdownProps, compileMarkdown, installIntlayerMarkdown, installIntlayerMarkdownDynamic, parseMarkdown, renderMarkdown, useMarkdown, useMarkdownRenderer };
@@ -0,0 +1,54 @@
1
+ import { DeclaredLocales } from "@intlayer/types/module_augmentation";
2
+ import { MiddlewareHandler } from "astro";
3
+ //#region src/middleware.d.ts
4
+ /**
5
+ * Intlayer state stored in `Astro.locals.intlayer` by the {@link onRequest} middleware.
6
+ */
7
+ export type IntlayerLocals = {
8
+ /** Locale resolved for the current request. */
9
+ locale: DeclaredLocales;
10
+ /** Locale configured as fallback in `intlayer.config.ts`. */
11
+ defaultLocale: DeclaredLocales;
12
+ /** Every locale declared in `intlayer.config.ts`. */
13
+ availableLocales: DeclaredLocales[];
14
+ };
15
+ declare global {
16
+ namespace App {
17
+ interface Locals {
18
+ intlayer: IntlayerLocals;
19
+ }
20
+ }
21
+ }
22
+ /**
23
+ * Astro middleware resolving the request locale into `Astro.locals.intlayer`.
24
+ *
25
+ * Priority: the URL (path prefix or `?locale=` search param, in every routing
26
+ * mode but `no-prefix`), then the locale persisted by the client (cookie or
27
+ * custom header), then `Accept-Language` negotiation.
28
+ *
29
+ * On server-rendered requests it also runs the Intlayer locale-routing proxy,
30
+ * so a visitor whose stored locale is `fr` is redirected from `/` to `/fr`
31
+ * (per `routing.mode`) and the resolved locale is persisted on the response.
32
+ * Only redirects are honoured: the proxy's internal rewrites target
33
+ * prefix-based routers, while Astro pages already resolve the locale from the
34
+ * URL they are rendered for. Prerendered pages are served as static files, so
35
+ * nothing can redirect them at request time and the proxy is skipped.
36
+ *
37
+ * The `intlayer()` integration registers it automatically, before the user
38
+ * middleware, so `Astro.locals.intlayer` is available in every page, endpoint
39
+ * and middleware. The rest of the request renders inside an
40
+ * `AsyncLocalStorage` scope bound to those locals, which is how the hooks of
41
+ * `astro-intlayer/server` read the locale with no argument.
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // src/middleware.ts — only needed when composing it by hand
46
+ * import { onRequest as intlayer } from 'astro-intlayer/middleware';
47
+ * import { sequence } from 'astro:middleware';
48
+ *
49
+ * export const onRequest = sequence(intlayer, myMiddleware);
50
+ * ```
51
+ */
52
+ export declare const onRequest: MiddlewareHandler;
53
+ //#endregion
54
+ //# sourceMappingURL=middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.d.ts","names":[],"sources":["../../src/middleware.ts"],"mappings":";;;;;;YAuEY;;EAEV,QAAQ;;EAER,eAAe;;EAEf,kBAAkB;;QAGZ;YACI;cACE;MACR,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAmCH,WAAW"}