remix-intlayer 9.5.4

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 (128) hide show
  1. package/README.md +331 -0
  2. package/dist/cjs/IntlayerProvider.cjs +36 -0
  3. package/dist/cjs/IntlayerProvider.cjs.map +1 -0
  4. package/dist/cjs/context.cjs +23 -0
  5. package/dist/cjs/context.cjs.map +1 -0
  6. package/dist/cjs/format/index.cjs +20 -0
  7. package/dist/cjs/format/useCompact.cjs +18 -0
  8. package/dist/cjs/format/useCompact.cjs.map +1 -0
  9. package/dist/cjs/format/useCurrency.cjs +18 -0
  10. package/dist/cjs/format/useCurrency.cjs.map +1 -0
  11. package/dist/cjs/format/useDate.cjs +27 -0
  12. package/dist/cjs/format/useDate.cjs.map +1 -0
  13. package/dist/cjs/format/useIntl.cjs +24 -0
  14. package/dist/cjs/format/useIntl.cjs.map +1 -0
  15. package/dist/cjs/format/useList.cjs +18 -0
  16. package/dist/cjs/format/useList.cjs.map +1 -0
  17. package/dist/cjs/format/useNumber.cjs +21 -0
  18. package/dist/cjs/format/useNumber.cjs.map +1 -0
  19. package/dist/cjs/format/usePercentage.cjs +18 -0
  20. package/dist/cjs/format/usePercentage.cjs.map +1 -0
  21. package/dist/cjs/format/useRelativeTime.cjs +18 -0
  22. package/dist/cjs/format/useRelativeTime.cjs.map +1 -0
  23. package/dist/cjs/format/useUnit.cjs +18 -0
  24. package/dist/cjs/format/useUnit.cjs.map +1 -0
  25. package/dist/cjs/html/index.cjs +33 -0
  26. package/dist/cjs/index.cjs +17 -0
  27. package/dist/cjs/localeRouting.cjs +211 -0
  28. package/dist/cjs/localeRouting.cjs.map +1 -0
  29. package/dist/cjs/markdown/index.cjs +45 -0
  30. package/dist/cjs/middleware.cjs +92 -0
  31. package/dist/cjs/middleware.cjs.map +1 -0
  32. package/dist/cjs/persistLocale.cjs +51 -0
  33. package/dist/cjs/persistLocale.cjs.map +1 -0
  34. package/dist/cjs/requestStorage.cjs +25 -0
  35. package/dist/cjs/requestStorage.cjs.map +1 -0
  36. package/dist/cjs/resolveLocale.cjs +21 -0
  37. package/dist/cjs/resolveLocale.cjs.map +1 -0
  38. package/dist/cjs/useDictionary.cjs +33 -0
  39. package/dist/cjs/useDictionary.cjs.map +1 -0
  40. package/dist/cjs/useIntlayer.cjs +31 -0
  41. package/dist/cjs/useIntlayer.cjs.map +1 -0
  42. package/dist/cjs/useLocale.cjs +33 -0
  43. package/dist/cjs/useLocale.cjs.map +1 -0
  44. package/dist/esm/IntlayerProvider.mjs +35 -0
  45. package/dist/esm/IntlayerProvider.mjs.map +1 -0
  46. package/dist/esm/context.mjs +21 -0
  47. package/dist/esm/context.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 +9 -0
  69. package/dist/esm/localeRouting.mjs +210 -0
  70. package/dist/esm/localeRouting.mjs.map +1 -0
  71. package/dist/esm/markdown/index.mjs +3 -0
  72. package/dist/esm/middleware.mjs +91 -0
  73. package/dist/esm/middleware.mjs.map +1 -0
  74. package/dist/esm/persistLocale.mjs +49 -0
  75. package/dist/esm/persistLocale.mjs.map +1 -0
  76. package/dist/esm/requestStorage.mjs +22 -0
  77. package/dist/esm/requestStorage.mjs.map +1 -0
  78. package/dist/esm/resolveLocale.mjs +20 -0
  79. package/dist/esm/resolveLocale.mjs.map +1 -0
  80. package/dist/esm/useDictionary.mjs +32 -0
  81. package/dist/esm/useDictionary.mjs.map +1 -0
  82. package/dist/esm/useIntlayer.mjs +30 -0
  83. package/dist/esm/useIntlayer.mjs.map +1 -0
  84. package/dist/esm/useLocale.mjs +32 -0
  85. package/dist/esm/useLocale.mjs.map +1 -0
  86. package/dist/types/IntlayerProvider.d.ts +39 -0
  87. package/dist/types/IntlayerProvider.d.ts.map +1 -0
  88. package/dist/types/context.d.ts +31 -0
  89. package/dist/types/context.d.ts.map +1 -0
  90. package/dist/types/format/index.d.ts +10 -0
  91. package/dist/types/format/useCompact.d.ts +5 -0
  92. package/dist/types/format/useCompact.d.ts.map +1 -0
  93. package/dist/types/format/useCurrency.d.ts +5 -0
  94. package/dist/types/format/useCurrency.d.ts.map +1 -0
  95. package/dist/types/format/useDate.d.ts +8 -0
  96. package/dist/types/format/useDate.d.ts.map +1 -0
  97. package/dist/types/format/useIntl.d.ts +15 -0
  98. package/dist/types/format/useIntl.d.ts.map +1 -0
  99. package/dist/types/format/useList.d.ts +5 -0
  100. package/dist/types/format/useList.d.ts.map +1 -0
  101. package/dist/types/format/useNumber.d.ts +8 -0
  102. package/dist/types/format/useNumber.d.ts.map +1 -0
  103. package/dist/types/format/usePercentage.d.ts +5 -0
  104. package/dist/types/format/usePercentage.d.ts.map +1 -0
  105. package/dist/types/format/useRelativeTime.d.ts +5 -0
  106. package/dist/types/format/useRelativeTime.d.ts.map +1 -0
  107. package/dist/types/format/useUnit.d.ts +5 -0
  108. package/dist/types/format/useUnit.d.ts.map +1 -0
  109. package/dist/types/html/index.d.ts +2 -0
  110. package/dist/types/index.d.ts +8 -0
  111. package/dist/types/localeRouting.d.ts +75 -0
  112. package/dist/types/localeRouting.d.ts.map +1 -0
  113. package/dist/types/markdown/index.d.ts +2 -0
  114. package/dist/types/middleware.d.ts +49 -0
  115. package/dist/types/middleware.d.ts.map +1 -0
  116. package/dist/types/persistLocale.d.ts +16 -0
  117. package/dist/types/persistLocale.d.ts.map +1 -0
  118. package/dist/types/requestStorage.d.ts +21 -0
  119. package/dist/types/requestStorage.d.ts.map +1 -0
  120. package/dist/types/resolveLocale.d.ts +16 -0
  121. package/dist/types/resolveLocale.d.ts.map +1 -0
  122. package/dist/types/useDictionary.d.ts +24 -0
  123. package/dist/types/useDictionary.d.ts.map +1 -0
  124. package/dist/types/useIntlayer.d.ts +21 -0
  125. package/dist/types/useIntlayer.d.ts.map +1 -0
  126. package/dist/types/useLocale.d.ts +25 -0
  127. package/dist/types/useLocale.d.ts.map +1 -0
  128. package/package.json +129 -0
@@ -0,0 +1,21 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_IntlayerProvider = require('./IntlayerProvider.cjs');
3
+ const require_middleware = require('./middleware.cjs');
4
+
5
+ //#region src/resolveLocale.ts
6
+ /**
7
+ * A component `Handle` carries its context store under `context`, whereas a
8
+ * `RequestContext` exposes `get`/`set` directly.
9
+ */
10
+ const isHandle = (source) => "context" in source && typeof source.context?.get === "function";
11
+ /**
12
+ * Reads the locale published to the given source, if any.
13
+ */
14
+ const resolveLocale = (source) => {
15
+ if (isHandle(source)) return source.context.get(require_IntlayerProvider.IntlayerProvider)?.locale;
16
+ return source.get(require_middleware.Intlayer)?.locale;
17
+ };
18
+
19
+ //#endregion
20
+ exports.resolveLocale = resolveLocale;
21
+ //# sourceMappingURL=resolveLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLocale.cjs","names":["IntlayerProvider","Intlayer"],"sources":["../../src/resolveLocale.ts"],"sourcesContent":["import type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport type { RequestContext } from 'remix/router';\nimport type { Handle } from 'remix/ui';\nimport { IntlayerProvider } from './IntlayerProvider';\nimport { Intlayer, type IntlayerState } from './middleware';\n\n/**\n * Where a hook reads the current locale from:\n * - a Remix router `RequestContext`, populated by the `intlayer()` middleware\n * - a Remix UI component `Handle`, populated by an ancestor `IntlayerProvider`\n */\nexport type IntlayerSource = RequestContext<any, any> | Handle<any, any>;\n\n/**\n * A component `Handle` carries its context store under `context`, whereas a\n * `RequestContext` exposes `get`/`set` directly.\n */\nconst isHandle = (source: IntlayerSource): source is Handle<any, any> =>\n 'context' in source &&\n typeof (source as Handle<any, any>).context?.get === 'function';\n\n/**\n * Reads the locale published to the given source, if any.\n */\nexport const resolveLocale = (\n source: IntlayerSource\n): DeclaredLocales | undefined => {\n if (isHandle(source)) {\n return source.context.get(IntlayerProvider)?.locale;\n }\n\n return (source.get(Intlayer) as IntlayerState | undefined)?.locale;\n};\n"],"mappings":";;;;;;;;;AAiBA,MAAM,YAAY,WAChB,aAAa,UACb,OAAQ,OAA4B,SAAS,QAAQ;;;;AAKvD,MAAa,iBACX,WACgC;CAChC,IAAI,SAAS,MAAM,GACjB,OAAO,OAAO,QAAQ,IAAIA,yCAAgB,CAAC,EAAE;CAG/C,OAAQ,OAAO,IAAIC,2BAAQ,CAAC,EAAgC;AAC9D"}
@@ -0,0 +1,33 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_requestStorage = require('./requestStorage.cjs');
3
+ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
4
+ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
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 handled.
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
+ * @example
16
+ * ```ts
17
+ * import homeContent from './home.content';
18
+ *
19
+ * router.get('/', () => {
20
+ * const { title } = useDictionary(homeContent);
21
+ * return new Response(title);
22
+ * });
23
+ * ```
24
+ */
25
+ const useDictionary = (dictionary, localeOrSelector) => (0, _intlayer_core_interpreter.getDictionary)(dictionary, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
26
+ localeOrSelector,
27
+ contextLocale: require_requestStorage.getRequestLocale(),
28
+ dictionaryKey: dictionary.key
29
+ }));
30
+
31
+ //#endregion
32
+ exports.useDictionary = useDictionary;
33
+ //# sourceMappingURL=useDictionary.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDictionary.cjs","names":["getDictionary","resolveDictionaryArgument","getRequestLocale"],"sources":["../../src/useDictionary.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport { getDictionary } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from './requestStorage';\n\n/**\n * Transforms an imported dictionary (or qualified dictionary group) and returns\n * its content for the locale of the request being handled.\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 * @example\n * ```ts\n * import homeContent from './home.content';\n *\n * router.get('/', () => {\n * const { title } = useDictionary(homeContent);\n * return new Response(title);\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) =>\n getDictionary<T, A>(\n dictionary,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: getRequestLocale(),\n dictionaryKey: dictionary.key,\n }) as A\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,iBAMX,YACA,yBAEAA,0CACE,gBACAC,gEAA0B;CACxB;CACA,eAAeC,wCAAiB;CAChC,eAAe,WAAW;AAC5B,CAAC,CACH"}
@@ -0,0 +1,31 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_requestStorage = require('./requestStorage.cjs');
3
+ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
4
+ let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
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 handled.
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
+ * @example
16
+ * ```ts
17
+ * router.get('/', () => {
18
+ * const { title } = useIntlayer('home');
19
+ * return new Response(title);
20
+ * });
21
+ * ```
22
+ */
23
+ const useIntlayer = (key, localeOrSelector) => (0, _intlayer_core_interpreter.getIntlayer)(key, (0, _intlayer_core_dictionaryManipulator.resolveDictionaryArgument)({
24
+ localeOrSelector,
25
+ contextLocale: require_requestStorage.getRequestLocale(),
26
+ dictionaryKey: key
27
+ }));
28
+
29
+ //#endregion
30
+ exports.useIntlayer = useIntlayer;
31
+ //# sourceMappingURL=useIntlayer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useIntlayer.cjs","names":["getIntlayer","resolveDictionaryArgument","getRequestLocale"],"sources":["../../src/useIntlayer.ts"],"sourcesContent":["import { resolveDictionaryArgument } from '@intlayer/core/dictionaryManipulator';\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from './requestStorage';\n\n/**\n * Picks one dictionary by its key and returns its content for the locale of\n * the request being handled.\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 * @example\n * ```ts\n * router.get('/', () => {\n * const { title } = useIntlayer('home');\n * return new Response(title);\n * });\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) =>\n getIntlayer<T, A>(\n key,\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: getRequestLocale(),\n dictionaryKey: key as string,\n }) as A\n );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,eAIX,KACA,yBAEAA,wCACE,SACAC,gEAA0B;CACxB;CACA,eAAeC,wCAAiB;CAChC,eAAe;AACjB,CAAC,CACH"}
@@ -0,0 +1,33 @@
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 handled, with the configured
9
+ * default and available locales.
10
+ *
11
+ * Falls back to the default locale outside of a request, i.e. when the
12
+ * `intlayer()` middleware did not run.
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * router.get('/', () => {
17
+ * const { locale, availableLocales } = useLocale();
18
+ * return Response.json({ locale, availableLocales });
19
+ * });
20
+ * ```
21
+ */
22
+ const useLocale = () => {
23
+ const state = require_requestStorage.getIntlayerState();
24
+ return {
25
+ locale: state?.locale ?? defaultLocale,
26
+ defaultLocale: state?.defaultLocale ?? defaultLocale,
27
+ availableLocales: state?.availableLocales ?? availableLocales
28
+ };
29
+ };
30
+
31
+ //#endregion
32
+ exports.useLocale = useLocale;
33
+ //# sourceMappingURL=useLocale.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useLocale.cjs","names":["internationalization","getIntlayerState"],"sources":["../../src/useLocale.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getIntlayerState, getRequestLocale } from './requestStorage';\n\nexport type UseLocaleResult = {\n locale: DeclaredLocales;\n defaultLocale: DeclaredLocales;\n availableLocales: DeclaredLocales[];\n};\n\nconst { defaultLocale, locales: availableLocales } = internationalization;\n\n/**\n * Returns the locale of the request being handled, with the configured\n * default and available locales.\n *\n * Falls back to the default locale outside of a request, i.e. when the\n * `intlayer()` middleware did not run.\n *\n * @example\n * ```ts\n * router.get('/', () => {\n * const { locale, availableLocales } = useLocale();\n * return Response.json({ locale, availableLocales });\n * });\n * ```\n */\nexport const useLocale = (): UseLocaleResult => {\n const state = getIntlayerState();\n\n return {\n locale: state?.locale ?? (defaultLocale as DeclaredLocales),\n defaultLocale:\n state?.defaultLocale ?? (defaultLocale as DeclaredLocales),\n availableLocales:\n state?.availableLocales ?? (availableLocales as DeclaredLocales[]),\n };\n};\n"],"mappings":";;;;;AAUA,MAAM,EAAE,eAAe,SAAS,qBAAqBA;;;;;;;;;;;;;;;;AAiBrD,MAAa,kBAAmC;CAC9C,MAAM,QAAQC,wCAAiB;CAE/B,OAAO;EACL,QAAQ,OAAO,UAAW;EAC1B,eACE,OAAO,iBAAkB;EAC3B,kBACE,OAAO,oBAAqB;CAChC;AACF"}
@@ -0,0 +1,35 @@
1
+ import { internationalization } from "@intlayer/config/built";
2
+
3
+ //#region src/IntlayerProvider.ts
4
+ /**
5
+ * Remix UI component that publishes the locale to every descendant component,
6
+ * so the hooks of this package can read it from their `Handle`.
7
+ *
8
+ * Nested providers shadow outer ones, following the Remix UI context rules.
9
+ *
10
+ * @example
11
+ * ```tsx
12
+ * router.get('/', (context) =>
13
+ * context.render(
14
+ * <IntlayerProvider locale={context.intlayer.locale}>
15
+ * <HomePage />
16
+ * </IntlayerProvider>
17
+ * )
18
+ * );
19
+ *
20
+ * function HomePage(handle: Handle) {
21
+ * const { title } = useIntlayer('home', handle);
22
+ * return () => <h1>{title}</h1>;
23
+ * }
24
+ * ```
25
+ */
26
+ const IntlayerProvider = (handle) => {
27
+ return () => {
28
+ handle.context.set({ locale: handle.props.locale ?? internationalization.defaultLocale });
29
+ return handle.props.children;
30
+ };
31
+ };
32
+
33
+ //#endregion
34
+ export { IntlayerProvider };
35
+ //# sourceMappingURL=IntlayerProvider.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../src/IntlayerProvider.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { Handle, RemixNode } from 'remix/ui';\n\nexport type IntlayerProviderProps = {\n /** Locale to render the subtree with. Defaults to the configured default locale. */\n locale?: LocalesValues;\n children?: RemixNode;\n};\n\n/**\n * Context value published by {@link IntlayerProvider} to its descendants.\n */\nexport type IntlayerProviderContext = {\n locale: DeclaredLocales;\n};\n\n/**\n * Remix UI component that publishes the locale to every descendant component,\n * so the hooks of this package can read it from their `Handle`.\n *\n * Nested providers shadow outer ones, following the Remix UI context rules.\n *\n * @example\n * ```tsx\n * router.get('/', (context) =>\n * context.render(\n * <IntlayerProvider locale={context.intlayer.locale}>\n * <HomePage />\n * </IntlayerProvider>\n * )\n * );\n *\n * function HomePage(handle: Handle) {\n * const { title } = useIntlayer('home', handle);\n * return () => <h1>{title}</h1>;\n * }\n * ```\n */\nexport const IntlayerProvider = (\n handle: Handle<IntlayerProviderProps, IntlayerProviderContext>\n): (() => RemixNode) => {\n // Published from the render function so a later `locale` prop change is\n // visible to the descendants rendered right after.\n return () => {\n handle.context.set({\n locale: (handle.props.locale ??\n internationalization.defaultLocale) as DeclaredLocales,\n });\n\n return handle.props.children;\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,MAAa,oBACX,WACsB;CAGtB,aAAa;EACX,OAAO,QAAQ,IAAI,EACjB,QAAS,OAAO,MAAM,UACpB,qBAAqB,cACzB,CAAC;EAED,OAAO,OAAO,MAAM;CACtB;AACF"}
@@ -0,0 +1,21 @@
1
+ import { createContextKey } from "remix/router";
2
+
3
+ //#region src/context.ts
4
+ /**
5
+ * Request-context key holding the {@link IntlayerState} of the current request.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * router.get('/', (context) => Response.json({ locale: context.get(Intlayer).locale }));
10
+ * ```
11
+ */
12
+ const Intlayer = createContextKey();
13
+ /**
14
+ * Name of the direct property installed on the request context by the middleware,
15
+ * so `context.intlayer` mirrors `context.get(Intlayer)`.
16
+ */
17
+ const INTLAYER_CONTEXT_PROPERTY = "intlayer";
18
+
19
+ //#endregion
20
+ export { INTLAYER_CONTEXT_PROPERTY, Intlayer };
21
+ //# sourceMappingURL=context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.mjs","names":[],"sources":["../../src/context.ts"],"sourcesContent":["import type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { createContextKey } from 'remix/router';\n\n/**\n * Intlayer state attached to the Remix `RequestContext` by the {@link intlayer} middleware.\n */\nexport type IntlayerState = {\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\n/**\n * Request-context key holding the {@link IntlayerState} of the current request.\n *\n * @example\n * ```ts\n * router.get('/', (context) => Response.json({ locale: context.get(Intlayer).locale }));\n * ```\n */\nexport const Intlayer: { defaultValue?: IntlayerState } =\n createContextKey<IntlayerState>();\n\n/**\n * Name of the direct property installed on the request context by the middleware,\n * so `context.intlayer` mirrors `context.get(Intlayer)`.\n */\nexport const INTLAYER_CONTEXT_PROPERTY = 'intlayer';\n"],"mappings":";;;;;;;;;;;AAuBA,MAAa,WACX,iBAAgC;;;;;AAMlC,MAAa,4BAA4B"}
@@ -0,0 +1,11 @@
1
+ import { useUnit } from "./useUnit.mjs";
2
+ import { useDate } from "./useDate.mjs";
3
+ import { useNumber } from "./useNumber.mjs";
4
+ import { useRelativeTime } from "./useRelativeTime.mjs";
5
+ import { useCompact } from "./useCompact.mjs";
6
+ import { useIntl } from "./useIntl.mjs";
7
+ import { useList } from "./useList.mjs";
8
+ import { usePercentage } from "./usePercentage.mjs";
9
+ import { useCurrency } from "./useCurrency.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
+ * Remix 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 * Remix 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
+ * Remix hook that provides a locale-bound `Intl` object.
9
+ *
10
+ * It uses the request locale when running inside a request handler,
11
+ * falling back to the configured 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 * Remix hook that provides a locale-bound `Intl` object.\n *\n * It uses the request locale when running inside a request handler,\n * falling back to the configured 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
+ * Remix 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 * Remix hook that provides a localized number formatter bound to the request locale.\n */\nexport const useNumber = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;;;;AAK1B,MAAa,kBAAkB;CAC7B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,OAAO,KAAK,IAAI;EACd,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { percentage } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/usePercentage.ts
6
+ const { defaultLocale } = internationalization;
7
+ const usePercentage = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => percentage(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { usePercentage };
17
+ //# sourceMappingURL=usePercentage.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../src/format/usePercentage.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { percentage } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const usePercentage = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,sBAAsB;CACjC,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,WAAW,KAAK,IAAI;EAClB,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { relativeTime } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useRelativeTime.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useRelativeTime = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => relativeTime(args[0], args[1], {
10
+ ...args[2],
11
+ locale: args[2]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useRelativeTime };
17
+ //# sourceMappingURL=useRelativeTime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../src/format/useRelativeTime.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { relativeTime } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useRelativeTime = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,wBAAwB;CACnC,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,aAAa,KAAK,IAAI,KAAK,IAAI;EAC7B,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,17 @@
1
+ import { getRequestLocale } from "../requestStorage.mjs";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { units } from "@intlayer/core/formatters";
4
+
5
+ //#region src/format/useUnit.ts
6
+ const { defaultLocale } = internationalization;
7
+ const useUnit = () => {
8
+ const locale = getRequestLocale() ?? defaultLocale;
9
+ return (...args) => units(args[0], {
10
+ ...args[1],
11
+ locale: args[1]?.locale ?? locale
12
+ });
13
+ };
14
+
15
+ //#endregion
16
+ export { useUnit };
17
+ //# sourceMappingURL=useUnit.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../src/format/useUnit.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { units } from '@intlayer/core/formatters';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { getRequestLocale } from '../requestStorage';\n\nconst { defaultLocale } = internationalization;\n\nexport const useUnit = () => {\n const locale = getRequestLocale() ?? (defaultLocale as DeclaredLocales);\n\n return (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":";;;;;AAKA,MAAM,EAAE,kBAAkB;AAE1B,MAAa,gBAAgB;CAC3B,MAAM,SAAS,iBAAiB,KAAM;CAEtC,QAAQ,GAAG,SACT,MAAM,KAAK,IAAI;EACb,GAAG,KAAK;EACR,QAAQ,KAAK,EAAE,EAAE,UAAU;CAC7B,CAAC;AACL"}
@@ -0,0 +1,3 @@
1
+ import { installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer } from "vanilla-intlayer/html";
2
+
3
+ export { installIntlayerHTML, installIntlayerHTMLDynamic, renderHTML, useHTML, useHTMLRenderer };
@@ -0,0 +1,9 @@
1
+ import { INTLAYER_CONTEXT_PROPERTY, Intlayer } from "./context.mjs";
2
+ import { createLocaleRouting } from "./localeRouting.mjs";
3
+ import { getIntlayerState } from "./requestStorage.mjs";
4
+ import { intlayer } from "./middleware.mjs";
5
+ import { useIntlayer } from "./useIntlayer.mjs";
6
+ import { useLocale } from "./useLocale.mjs";
7
+ import { useDictionary } from "./useDictionary.mjs";
8
+
9
+ export { INTLAYER_CONTEXT_PROPERTY, Intlayer, createLocaleRouting, getIntlayerState, intlayer, useDictionary, useIntlayer, useLocale };