@fluentic/i18n 0.0.0-stage → 0.1.0-beta.2

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 (60) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE +21 -0
  3. package/README.md +29 -2
  4. package/dist/adapter.d.ts +6 -0
  5. package/dist/adapter.js +5 -0
  6. package/dist/compact-E3zj3Z8d.js +34 -0
  7. package/dist/compact-E3zj3Z8d.js.map +1 -0
  8. package/dist/compiled.d.ts +29 -0
  9. package/dist/compiled.js +53 -0
  10. package/dist/compiled.js.map +1 -0
  11. package/dist/compiler-support.d.ts +4 -0
  12. package/dist/compiler-support.js +4 -0
  13. package/dist/core/format.d.ts +11 -0
  14. package/dist/core/i18n.d.ts +26 -0
  15. package/dist/core/index.d.ts +1 -0
  16. package/dist/core/index.js +5 -0
  17. package/dist/core/types.d.ts +79 -0
  18. package/dist/hash-VJlyT31Z.js +90 -0
  19. package/dist/hash-VJlyT31Z.js.map +1 -0
  20. package/dist/hydration-store-BK6UxrtJ.js +13 -0
  21. package/dist/hydration-store-BK6UxrtJ.js.map +1 -0
  22. package/dist/hydration-store.d.ts +29 -0
  23. package/dist/hydration.d.ts +7 -0
  24. package/dist/hydration.js +35 -0
  25. package/dist/hydration.js.map +1 -0
  26. package/dist/index.d.ts +6 -0
  27. package/dist/index.js +5 -0
  28. package/dist/interpreter-BfzvLLrD.js +187 -0
  29. package/dist/interpreter-BfzvLLrD.js.map +1 -0
  30. package/dist/manager-BgMJWXWY.js +183 -0
  31. package/dist/manager-BgMJWXWY.js.map +1 -0
  32. package/dist/manager.d.ts +62 -0
  33. package/dist/message-D4jK2Lzc.js +9 -0
  34. package/dist/message-D4jK2Lzc.js.map +1 -0
  35. package/dist/react.d.ts +48 -0
  36. package/dist/react.js +64 -0
  37. package/dist/react.js.map +1 -0
  38. package/dist/registry-manager.d.ts +7 -0
  39. package/dist/runtime-DXnGeCBw.js +110 -0
  40. package/dist/runtime-DXnGeCBw.js.map +1 -0
  41. package/dist/shared/compact.d.ts +5 -0
  42. package/dist/shared/formatting.d.ts +11 -0
  43. package/dist/shared/hash.d.ts +7 -0
  44. package/dist/shared/interpreter.d.ts +2 -0
  45. package/dist/shared/message.d.ts +2 -0
  46. package/dist/shared/runtime.d.ts +49 -0
  47. package/dist/src-ON68XIog.js +144 -0
  48. package/dist/src-ON68XIog.js.map +1 -0
  49. package/dist/state-manager.d.ts +6 -0
  50. package/dist/state.d.ts +8 -0
  51. package/dist/storage-manager.d.ts +14 -0
  52. package/dist/translation-manager-BkmFnlb_.js +114 -0
  53. package/dist/translation-manager-BkmFnlb_.js.map +1 -0
  54. package/dist/translation-manager.d.ts +34 -0
  55. package/dist/translation.d.ts +20 -0
  56. package/dist/types-BkDsJfVD.js +13 -0
  57. package/dist/types-BkDsJfVD.js.map +1 -0
  58. package/dist/types.d.ts +3 -0
  59. package/dist/types.js +1 -0
  60. package/package.json +96 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # @fluentic/i18n
2
+
3
+ ## 0.1.0-beta.2
4
+
5
+ ### Additional beta.2 changes
6
+
7
+ - Notify loader lifecycle hooks after successful language selections so persistent caches can track selected languages.
8
+
9
+ ### Patch Changes
10
+
11
+ - Add `t.jsx(() => element)` as a fine-grained React boundary that refreshes one element's translated string props without rerendering its parent component.
12
+ - Move server snapshot transfer out of the SPA manager and into the explicit `@fluentic/i18n/hydration` entry point.
13
+ - Harden lazy catalog loading, compiled catalog validation, locale fallback, and concurrent language switching.
14
+ - Generate and publish declaration files from TypeScript 7 instead of exposing package source files as types.
15
+
16
+ ## 0.1.0-beta.1
17
+
18
+ ### Minor Changes
19
+
20
+ - Publish the first public beta of the typed Fluentic i18n runtime and React bindings.
21
+ - Add optional build-time ICU compilation for Babel, Vite, Rollup, esbuild, and webpack.
22
+ - Load JSONL or array catalogs in compiled and uncompiled formats, with locale fallback and deterministic message hashing.
23
+ - Add isolated managers, reactive language state, rich-message rendering, and configurable JSX line breaks.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Fluentic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,30 @@
1
- # Temporary Holding Version
1
+ # @fluentic/i18n
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Universal message declarations and synchronous rendering. Import `t` and `I18nRegistry` here in shared business/UI modules. Install a platform adapter for rendering and management:
4
+
5
+ - `@fluentic/i18n-web`: React SPA/browser.
6
+ - `@fluentic/i18n-rn`: React Native / Expo.
7
+ - `@fluentic/i18n-nextjs`: Next.js App Router.
8
+
9
+ ```ts
10
+ import { t } from '@fluentic/i18n';
11
+ import { I18nManager } from '@fluentic/i18n-web';
12
+ const greeting = t.msg('Hello {name}', { name: String });
13
+ I18nManager.configure({ languageId: 'en' });
14
+ await I18nManager.init();
15
+ t.text(greeting, { name: 'Ada' });
16
+ ```
17
+
18
+ `t.msg` is inert and safe at module scope. `t.text` returns a string; `t.jsx` returns JSX synchronously. Initialize before rendering. Persistence is opt-in.
19
+
20
+ For a fine-grained React update boundary, wrap one element whose string props use `t.text`:
21
+
22
+ ```tsx
23
+ t.jsx(() => <input placeholder={t.text('Search')} />);
24
+ ```
25
+
26
+ Only that wrapper reruns when the language changes. Use `I18nState.use()` instead when rerendering the whole component is more convenient.
27
+
28
+ The default runtime uses cached `intl-messageformat`. Install the separate Node-only `@fluentic/i18n-compiler` package, set `compiled: true` or `compiled: { hashLength: 8 }` for the CLI, and add its `/vite`, `/rollup`, `/esbuild`, `/webpack`, `/babel`, or `/nextjs` integration. Adding a compiler integration always compiles source; its only compilation option is `hashLength`, which defaults to the value in shared CLI config. Compiled merged catalogs start with `{"compiled":true}` followed by short base64url-keyed compact messages.
29
+
30
+ See [platforms](../../docs/docs/runtime/platforms.md), [compiler](../../docs/docs/runtime/compilation.md), [API](../../docs/docs/api.md), and the projects under `examples/`.
@@ -0,0 +1,6 @@
1
+ export type * from './core/types';
2
+ export * from './manager';
3
+ export * from './shared/compact';
4
+ export * from './shared/runtime';
5
+ export * from './state-manager';
6
+ export * from './storage-manager';
@@ -0,0 +1,5 @@
1
+ import { a as getFormats, c as renderJsxCallback, d as setLanguageId, f as setRuntimeResolver, i as defaultRuntime, l as setFormats, m as withRuntime, n as createRuntime, o as getRuntime, p as setTranslationGetter, r as createTagHandler, s as noTranslate, t as I18nRegistry, u as setGetJsxHandler } from "./runtime-DXnGeCBw.js";
2
+ import { n as validateCompact, t as COMPACT_VERSION } from "./compact-E3zj3Z8d.js";
3
+ import { n as defineTranslationLoader } from "./translation-manager-BkmFnlb_.js";
4
+ import { a as createLocalStorage, i as defaultManaged, n as createI18nManager, o as createStorageManager, r as defaultI18nState, s as createStateManager, t as I18nManager } from "./manager-BgMJWXWY.js";
5
+ export { COMPACT_VERSION, I18nManager, I18nRegistry, createI18nManager, createLocalStorage, createRuntime, createStateManager, createStorageManager, createTagHandler, defaultI18nState, defaultManaged, defaultRuntime, defineTranslationLoader, getFormats, getRuntime, noTranslate, renderJsxCallback, setFormats, setGetJsxHandler, setLanguageId, setRuntimeResolver, setTranslationGetter, validateCompact, withRuntime };
@@ -0,0 +1,34 @@
1
+ // src/shared/compact.ts
2
+ const COMPACT_VERSION = 1;
3
+ function validateCompact(value, depth = 0) {
4
+ if (depth > 100) throw new TypeError("[i18n] compact message nesting exceeds 100");
5
+ if (typeof value === "string") return;
6
+ if (!Array.isArray(value)) throw new TypeError("[i18n] invalid compact message");
7
+ for (const part of value) {
8
+ if (typeof part === "string") continue;
9
+ if (!Array.isArray(part)) throw new TypeError("[i18n] invalid compact instruction");
10
+ const [op, name] = part;
11
+ const lengths = {
12
+ 0: 2,
13
+ 1: 3,
14
+ 2: 3,
15
+ 3: 3,
16
+ 4: 3,
17
+ 5: 5,
18
+ 6: 1,
19
+ 7: 3
20
+ };
21
+ if (!Object.prototype.hasOwnProperty.call(lengths, op) || part.length !== lengths[op] || op !== 6 && typeof name !== "string") throw new TypeError("[i18n] invalid compact opcode");
22
+ if (op >= 1 && op <= 3 && part[2] !== null && typeof part[2] !== "string" && (typeof part[2] !== "object" || Array.isArray(part[2]))) throw new TypeError("[i18n] invalid compact format");
23
+ if (op === 5 && (typeof part[2] !== "number" || !Number.isFinite(part[2]) || ![0, 1].includes(part[3]))) throw new TypeError("[i18n] invalid compact plural");
24
+ if (op === 4 || op === 5) {
25
+ const branches = part[op === 4 ? 2 : 4];
26
+ if (!branches || typeof branches !== "object" || Array.isArray(branches) || !Object.prototype.hasOwnProperty.call(branches, "other")) throw new TypeError("[i18n] missing other branch");
27
+ for (const child of Object.values(branches)) validateCompact(child, depth + 1);
28
+ }
29
+ if (op === 7) validateCompact(part[2], depth + 1);
30
+ }
31
+ }
32
+ export { validateCompact as n, COMPACT_VERSION as t };
33
+
34
+ //# sourceMappingURL=compact-E3zj3Z8d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compact-E3zj3Z8d.js","names":[],"sources":["../src/shared/compact.ts"],"sourcesContent":["/** Compact message format v1. Strings are literal messages or literal parts. */\nexport type CompactMessage = string | CompactPart[];\n\nexport type CompactPart =\n | string\n | [0, string]\n | [1, string, string | Record<string, unknown> | null]\n | [2 | 3, string, string | Record<string, unknown> | null]\n | [4, string, Record<string, CompactMessage>]\n | [5, string, number, 0 | 1, Record<string, CompactMessage>]\n | [6]\n | [7, string, CompactMessage];\n\nexport const COMPACT_VERSION = 1;\n\nexport function validateCompact(value: unknown, depth = 0): asserts value is CompactMessage {\n if (depth > 100) throw new TypeError('[i18n] compact message nesting exceeds 100');\n if (typeof value === 'string') return;\n if (!Array.isArray(value)) throw new TypeError('[i18n] invalid compact message');\n\n for (const part of value) {\n if (typeof part === 'string') continue;\n if (!Array.isArray(part)) throw new TypeError('[i18n] invalid compact instruction');\n\n const [op, name] = part;\n const lengths: Record<number, number> = { 0: 2, 1: 3, 2: 3, 3: 3, 4: 3, 5: 5, 6: 1, 7: 3 };\n\n if (\n !Object.prototype.hasOwnProperty.call(lengths, op) || part.length !== lengths[op] ||\n (op !== 6 && typeof name !== 'string')\n ) throw new TypeError('[i18n] invalid compact opcode');\n if (\n op >= 1 && op <= 3 && part[2] !== null && typeof part[2] !== 'string' &&\n (typeof part[2] !== 'object' || Array.isArray(part[2]))\n ) throw new TypeError('[i18n] invalid compact format');\n if (op === 5 && (typeof part[2] !== 'number' || !Number.isFinite(part[2]) || ![0, 1].includes(part[3]))) {\n throw new TypeError('[i18n] invalid compact plural');\n }\n if (op === 4 || op === 5) {\n const branches = part[op === 4 ? 2 : 4];\n\n if (\n !branches || typeof branches !== 'object' || Array.isArray(branches) ||\n !Object.prototype.hasOwnProperty.call(branches, 'other')\n ) throw new TypeError('[i18n] missing other branch');\n\n for (const child of Object.values(branches)) validateCompact(child, depth + 1);\n }\n if (op === 7) validateCompact(part[2], depth + 1);\n }\n}\n"],"mappings":";AAa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AO,QAAQ,GAAG,gBAAgB,OAAO,QAAQ,CAAC;EAC/E;EACA,IAAI,OAAO,GAAG,gBAAgB,KAAK,IAAI,QAAQ,CAAC;CAClD;AACF"}
@@ -0,0 +1,29 @@
1
+ import { type TApi } from './core/i18n';
2
+ import type { DescriptorRenderArgs, I18nJsxOutput, I18nTagElement, I18nTagValue, MessageDescriptor, MessageParams, MessageSchema, TryRenderArgs } from './core/types';
3
+ import type { CompactMessage } from './shared/compact';
4
+ export type CompiledPayload = readonly [id: string, fallback: CompactMessage];
5
+ export type CompiledTextRenderer = {
6
+ (message: CompiledPayload, params?: MessageParams): string;
7
+ <Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): string;
8
+ };
9
+ export type CompiledJsxRenderer = {
10
+ (render: () => I18nTagElement): I18nJsxOutput;
11
+ (message: CompiledPayload, params?: MessageParams): I18nJsxOutput;
12
+ <Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): I18nJsxOutput;
13
+ };
14
+ export type CompiledTApi = Omit<TApi<I18nJsxOutput, I18nTagValue>, 'msg' | 'text' | 'jsx' | 'try' | 'context' | 'note' | 'meta'> & {
15
+ msg<Schema extends MessageSchema | undefined = undefined>(message: CompiledPayload, schema?: Schema): MessageDescriptor<string, Schema>;
16
+ text: CompiledTextRenderer;
17
+ jsx: CompiledJsxRenderer;
18
+ try<T>(renderer: CompiledTextRenderer, value: T, ...args: TryRenderArgs<T>): T extends {
19
+ readonly __fluenticMessage: true;
20
+ } ? string : T;
21
+ try<T>(renderer: CompiledJsxRenderer, value: T, ...args: TryRenderArgs<T>): T extends {
22
+ readonly __fluenticMessage: true;
23
+ } ? I18nJsxOutput : T;
24
+ };
25
+ export declare const t: CompiledTApi;
26
+ export * from './core/types';
27
+ export type { CompactMessage, CompactPart } from './shared/compact';
28
+ export { I18nRegistry, noTranslate, setFormats } from './shared/runtime';
29
+ export { defineTranslationLoader } from './translation-manager';
@@ -0,0 +1,53 @@
1
+ import { c as renderJsxCallback, l as setFormats, o as getRuntime, r as createTagHandler, s as noTranslate, t as I18nRegistry } from "./runtime-DXnGeCBw.js";
2
+ import { n as isMessageSchemaValue, r as isMessageTagHandler, t as isMessageDescriptor } from "./types-BkDsJfVD.js";
3
+ import { n as createFormatting, t as interpret } from "./interpreter-BfzvLLrD.js";
4
+ import { n as defineTranslationLoader } from "./translation-manager-BkmFnlb_.js";
5
+ // src/compiled.ts
6
+ const formatting = /* @__PURE__ */ createFormatting(interpret, true);
7
+ function descriptor(payload, schema) {
8
+ if (!Array.isArray(payload) || payload.length !== 2 || typeof payload[0] !== "string") throw new TypeError("[i18n] compiled runtime requires compiled messages; enable the Fluentic plugin");
9
+ return Object.freeze({
10
+ __fluenticMessage: true,
11
+ text: payload[0],
12
+ compiled: payload,
13
+ context: null,
14
+ schema: schema ?? {},
15
+ notes: [],
16
+ meta: void 0
17
+ });
18
+ }
19
+ function options(message, params) {
20
+ return {
21
+ msg: isMessageDescriptor(message) ? message : descriptor(message),
22
+ params
23
+ };
24
+ }
25
+ const t = {
26
+ msg: descriptor,
27
+ text(message, params) {
28
+ return formatting.getText(options(message, params));
29
+ },
30
+ jsx(message, params) {
31
+ if (typeof message === "function") return renderJsxCallback(message);
32
+ return formatting.getJsx(options(message, params));
33
+ },
34
+ clone(message) {
35
+ return Object.freeze({ ...message });
36
+ },
37
+ params(params = {}) {
38
+ return params ?? {};
39
+ },
40
+ tag(value) {
41
+ if (typeof value === "function") return createTagHandler(value);
42
+ const adapt = getRuntime().tagElement;
43
+ if (!adapt) throw new Error("[i18n] element tags require a platform adapter");
44
+ return createTagHandler(adapt(value));
45
+ },
46
+ try(renderer, value, params) {
47
+ return isMessageDescriptor(value) ? renderer(value, params) : value;
48
+ },
49
+ notranslate: noTranslate
50
+ };
51
+ export { I18nRegistry, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };
52
+
53
+ //# sourceMappingURL=compiled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiled.js","names":[],"sources":["../src/compiled.ts"],"sourcesContent":["import { type TApi } from './core/i18n';\nimport { isMessageDescriptor } from './core/types';\nimport type {\n DescriptorRenderArgs,\n I18nJsxOutput,\n I18nTagElement,\n I18nTagValue,\n MessageDescriptor,\n MessageParams,\n MessageSchema,\n TryRenderArgs,\n} from './core/types';\nimport type { CompactMessage } from './shared/compact';\nimport { createFormatting } from './shared/formatting';\nimport { interpret } from './shared/interpreter';\nimport { createTagHandler, getRuntime, noTranslate, renderJsxCallback } from './shared/runtime';\n\nexport type CompiledPayload = readonly [id: string, fallback: CompactMessage];\n\nexport type CompiledTextRenderer = {\n (message: CompiledPayload, params?: MessageParams): string;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): string;\n};\n\nexport type CompiledJsxRenderer = {\n (render: () => I18nTagElement): I18nJsxOutput;\n (message: CompiledPayload, params?: MessageParams): I18nJsxOutput;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): I18nJsxOutput;\n};\n\nexport type CompiledTApi =\n & Omit<TApi<I18nJsxOutput, I18nTagValue>, 'msg' | 'text' | 'jsx' | 'try' | 'context' | 'note' | 'meta'>\n & {\n msg<Schema extends MessageSchema | undefined = undefined>(\n message: CompiledPayload,\n schema?: Schema,\n ): MessageDescriptor<string, Schema>;\n text: CompiledTextRenderer;\n jsx: CompiledJsxRenderer;\n try<T>(\n renderer: CompiledTextRenderer,\n value: T,\n ...args: TryRenderArgs<T>\n ): T extends { readonly __fluenticMessage: true; } ? string\n : T;\n try<T>(\n renderer: CompiledJsxRenderer,\n value: T,\n ...args: TryRenderArgs<T>\n ): T extends { readonly __fluenticMessage: true; } ? I18nJsxOutput : T;\n };\n\nconst formatting = /* @__PURE__ */ createFormatting(interpret, true);\n\nfunction descriptor<Schema extends MessageSchema | undefined = undefined>(\n payload: CompiledPayload,\n schema?: Schema,\n): MessageDescriptor<string, Schema> {\n if (!Array.isArray(payload) || payload.length !== 2 || typeof payload[0] !== 'string') {\n throw new TypeError('[i18n] compiled runtime requires compiled messages; enable the Fluentic plugin');\n }\n\n return Object.freeze({\n __fluenticMessage: true,\n text: payload[0],\n compiled: payload,\n context: null,\n schema: schema ?? {},\n notes: [],\n meta: undefined,\n }) as unknown as MessageDescriptor<string, Schema>;\n}\n\nfunction options(\n message: CompiledPayload | MessageDescriptor<string, MessageSchema | undefined>,\n params?: MessageParams,\n) {\n return { msg: isMessageDescriptor(message) ? message : descriptor(message), params };\n}\n\nexport const t = {\n msg: descriptor,\n text(message: CompiledPayload | MessageDescriptor<string, MessageSchema | undefined>, params?: MessageParams) {\n return formatting.getText(options(message, params));\n },\n jsx(\n message: CompiledPayload | MessageDescriptor<string, MessageSchema | undefined> | (() => I18nTagElement),\n params?: MessageParams,\n ) {\n if (typeof message === 'function') return renderJsxCallback(message);\n\n return formatting.getJsx(options(message, params));\n },\n clone(message: MessageDescriptor) {\n return Object.freeze({ ...message });\n },\n params(params: MessageParams | null = {}) {\n return params ?? {};\n },\n tag(value: unknown) {\n if (typeof value === 'function') return createTagHandler(value as (chunks: unknown[]) => unknown);\n\n const adapt = getRuntime().tagElement;\n\n if (!adapt) throw new Error('[i18n] element tags require a platform adapter');\n\n return createTagHandler(adapt(value));\n },\n try(renderer: (message: unknown, params?: MessageParams) => unknown, value: unknown, params?: MessageParams) {\n return isMessageDescriptor(value) ? renderer(value, params) : value;\n },\n notranslate: noTranslate,\n} as unknown as CompiledTApi;\nexport * from './core/types';\nexport type { CompactMessage, CompactPart } from './shared/compact';\nexport { I18nRegistry, noTranslate, setFormats } from './shared/runtime';\nexport { defineTranslationLoader } from './translation-manager';\n"],"mappings":";;;;;AA0DA,MAAM,aAA6B,iCAAiB,WAAW,IAAI;AAEnE,SAAS,WACP,SACA,QACmC;CACnC,IAAI,CAAC,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW,KAAK,OAAO,QAAQ,OAAO,UAC3E,MAAM,IAAI,UAAU,gFAAgF;CAGtG,OAAO,OAAO,OAAO;EACnB,mBAAmB;EACnB,MAAM,QAAQ;EACd,UAAU;EACV,SAAS;EACT,QAAQ,UAAU,CAAC;EACnB,OAAO,CAAC;EACR,MAAM,KAAA;CACR,CAAC;AACH;AAEA,SAAS,QACP,SACA,QACA;CACA,OAAO;EAAE,KAAK,oBAAoB,OAAO,IAAI,UAAU,WAAW,OAAO;EAAG;CAAO;AACrF;AAEA,MAAa,IAAI;CACf,KAAK;CACL,KAAK,SAAiF,QAAwB;EAC5G,OAAO,WAAW,QAAQ,QAAQ,SAAS,MAAM,CAAC;CACpD;CACA,IACE,SACA,QACA;EACA,IAAI,OAAO,YAAY,YAAY,OAAO,kBAAkB,OAAO;EAEnE,OAAO,WAAW,OAAO,QAAQ,SAAS,MAAM,CAAC;CACnD;CACA,MAAM,SAA4B;EAChC,OAAO,OAAO,OAAO,EAAE,GAAG,QAAQ,CAAC;CACrC;CACA,OAAO,SAA+B,CAAC,GAAG;EACxC,OAAO,UAAU,CAAC;CACpB;CACA,IAAI,OAAgB;EAClB,IAAI,OAAO,UAAU,YAAY,OAAO,iBAAiB,KAAuC;EAEhG,MAAM,QAAQ,WAAW,CAAC,CAAC;EAE3B,IAAI,CAAC,OAAO,MAAM,IAAI,MAAM,gDAAgD;EAE5E,OAAO,iBAAiB,MAAM,KAAK,CAAC;CACtC;CACA,IAAI,UAAiE,OAAgB,QAAwB;EAC3G,OAAO,oBAAoB,KAAK,IAAI,SAAS,OAAO,MAAM,IAAI;CAChE;CACA,aAAa;AACf"}
@@ -0,0 +1,4 @@
1
+ export type { CompactMessage, CompactPart } from './shared/compact';
2
+ export { COMPACT_VERSION } from './shared/compact';
3
+ export { DEFAULT_HASH_LENGTH, MAX_HASH_LENGTH, messageHash, MIN_HASH_LENGTH, normalizeHashLength } from './shared/hash';
4
+ export { normalizeMessage } from './shared/message';
@@ -0,0 +1,4 @@
1
+ import { t as normalizeMessage } from "./message-D4jK2Lzc.js";
2
+ import { t as COMPACT_VERSION } from "./compact-E3zj3Z8d.js";
3
+ import { a as normalizeHashLength, i as messageHash, n as MAX_HASH_LENGTH, r as MIN_HASH_LENGTH, t as DEFAULT_HASH_LENGTH } from "./hash-VJlyT31Z.js";
4
+ export { COMPACT_VERSION, DEFAULT_HASH_LENGTH, MAX_HASH_LENGTH, MIN_HASH_LENGTH, messageHash, normalizeHashLength, normalizeMessage };
@@ -0,0 +1,11 @@
1
+ declare const formatting: {
2
+ getText: (options: import("./types").MessageFormatOptions, runtime?: import("./format").Runtime) => string;
3
+ getJsx: (options: import("./types").MessageFormatOptions) => unknown;
4
+ getMessageParts: (options: import("./types").MessageFormatOptions, runtime?: import("./format").Runtime, jsx?: boolean) => unknown[];
5
+ formatMessage: (options: import("./types").MessageFormatOptions, runtime?: import("./format").Runtime) => string;
6
+ };
7
+ export * from '../shared/runtime';
8
+ export declare const getText: (...args: Parameters<typeof formatting.getText>) => string;
9
+ export declare const getJsx: (...args: Parameters<typeof formatting.getJsx>) => unknown;
10
+ export declare const getMessageParts: (...args: Parameters<typeof formatting.getMessageParts>) => unknown[];
11
+ export declare const formatMessage: typeof getText;
@@ -0,0 +1,26 @@
1
+ import type { Formatting } from '../shared/formatting';
2
+ import { noTranslate } from '../shared/runtime';
3
+ import type { I18nJsxOutput, I18nTagElement, I18nTagValue } from './types';
4
+ import type { JsxRenderer, MessageDescriptor, MessageMeta, MessageParams, MessageSchema, MessageTagHandler, TextRenderer, TryRenderArgs } from './types';
5
+ export type MessageApi<JsxOutput = unknown> = {
6
+ context(name: string): MessageApi<JsxOutput>;
7
+ note(note: string): MessageApi<JsxOutput>;
8
+ meta(meta: MessageMeta): MessageApi<JsxOutput>;
9
+ msg<const Text extends string, const Schema extends MessageSchema | undefined = undefined>(message: Text, schema?: Schema): MessageDescriptor<Text, Schema>;
10
+ text: TextRenderer;
11
+ jsx: JsxRenderer<JsxOutput>;
12
+ };
13
+ export type TApi<JsxOutput = unknown, TagValue = unknown> = MessageApi<JsxOutput> & {
14
+ clone<const Text extends string, const Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>): MessageDescriptor<Text, Schema>;
15
+ params<Params extends MessageParams>(params?: Params | null): Params;
16
+ tag(element: I18nTagElement): MessageTagHandler<I18nTagValue, I18nTagElement>;
17
+ tag<T = TagValue, R = TagValue>(handler: (chunks: Array<string | T>) => R): MessageTagHandler<T, R>;
18
+ try<T>(renderer: TextRenderer, value: T, ...args: TryRenderArgs<T>): T extends {
19
+ readonly __fluenticMessage: true;
20
+ } ? string : T;
21
+ try<T>(renderer: JsxRenderer<JsxOutput>, value: T, ...args: TryRenderArgs<T>): T extends {
22
+ readonly __fluenticMessage: true;
23
+ } ? JsxOutput : T;
24
+ notranslate: typeof noTranslate;
25
+ };
26
+ export declare function createT({ getText, getJsx }: Formatting): TApi<I18nJsxOutput, I18nTagValue>;
@@ -0,0 +1 @@
1
+ export * from '../index';
@@ -0,0 +1,5 @@
1
+ import { t } from "../src-ON68XIog.js";
2
+ import { l as setFormats, s as noTranslate, t as I18nRegistry } from "../runtime-DXnGeCBw.js";
3
+ import { n as isMessageSchemaValue, r as isMessageTagHandler, t as isMessageDescriptor } from "../types-BkDsJfVD.js";
4
+ import { n as defineTranslationLoader } from "../translation-manager-BkmFnlb_.js";
5
+ export { I18nRegistry, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };
@@ -0,0 +1,79 @@
1
+ import type { CompactMessage } from '../shared/compact';
2
+ import type { I18nJsxConfig } from '../types';
3
+ export type { I18nJsxConfig } from '../types';
4
+ export type I18nJsxOutput = I18nJsxConfig extends {
5
+ JSX: infer Output;
6
+ } ? NonNullable<Output> : unknown;
7
+ export type I18nTagElement = I18nJsxConfig extends {
8
+ Element: infer Element;
9
+ } ? Element : never;
10
+ export type I18nTagValue = I18nJsxConfig extends {
11
+ Value: infer Value;
12
+ } ? Value : unknown;
13
+ export type PrimitiveType = string | number | boolean | null | undefined;
14
+ export type LanguageId = string;
15
+ export type JsonValue = string | number | boolean | null | JsonValue[] | {
16
+ [key: string]: JsonValue;
17
+ };
18
+ export type MessageMeta = JsonValue;
19
+ export type MessageContext = string;
20
+ export type MessageSchemaValue = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;
21
+ export type MessageSchema = Partial<Record<string, MessageSchemaValue>>;
22
+ export type InferMessageSchema<Schema extends MessageSchema> = {
23
+ [Key in keyof Schema]: Schema[Key] extends StringConstructor ? string : Schema[Key] extends NumberConstructor ? number : Schema[Key] extends BooleanConstructor ? boolean : Schema[Key] extends DateConstructor ? Date : never;
24
+ };
25
+ export type MessageDescriptor<Text extends string = string, Schema extends MessageSchema | undefined = MessageSchema> = {
26
+ readonly __fluenticMessage: true;
27
+ readonly text: Text;
28
+ readonly compiled?: readonly [string, CompactMessage];
29
+ readonly context: MessageContext | null;
30
+ readonly schema: Schema extends MessageSchema ? Schema : MessageSchema;
31
+ readonly notes: readonly string[];
32
+ readonly meta: MessageMeta | undefined;
33
+ };
34
+ export type AnyMessageDescriptor = MessageDescriptor<string, MessageSchema | undefined>;
35
+ export type MessageValueContext = {
36
+ languageId: LanguageId;
37
+ };
38
+ export type MessageValueFactory<T = unknown> = (context: MessageValueContext) => T;
39
+ export type MessageTagHandler<T = unknown, R = unknown> = ((chunks: Array<string | T>) => R) & {
40
+ readonly __fluenticTagHandler: true;
41
+ };
42
+ export type MessageRuntimeValue = PrimitiveType | Date | AnyMessageDescriptor | MessageValueFactory | Pick<MessageTagHandler, '__fluenticTagHandler'>;
43
+ export type MessageParam = MessageRuntimeValue;
44
+ export type MessageParams = Record<string, MessageParam>;
45
+ export type MessageInput = string | AnyMessageDescriptor;
46
+ export type InferRuntimeParams<Schema extends MessageSchema> = {
47
+ [Key in keyof InferMessageSchema<Schema>]: InferMessageSchema<Schema>[Key] | MessageValueFactory<InferMessageSchema<Schema>[Key]>;
48
+ };
49
+ export type DescriptorRenderArgs<Schema extends MessageSchema | undefined> = Schema extends undefined ? [params?: MessageParams] : keyof Schema extends never ? [] : Schema extends MessageSchema ? [params: InferRuntimeParams<Schema>] : never;
50
+ export type TryRenderArgs<Value> = Value extends {
51
+ readonly __fluenticMessage: true;
52
+ } ? Value extends MessageDescriptor<string, infer Schema> ? Schema extends MessageSchema | undefined ? DescriptorRenderArgs<Schema> : [params: MessageParams] : [params: MessageParams] : [params?: MessageParams];
53
+ export type TextRenderer = {
54
+ <Text extends string>(message: Text, params?: MessageParams): string;
55
+ <Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): string;
56
+ };
57
+ export type JsxRenderer<Output = unknown> = {
58
+ (render: () => I18nTagElement): Output;
59
+ <Text extends string>(message: Text, params?: MessageParams): Output;
60
+ <Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): Output;
61
+ };
62
+ export type MessageFormatOptions = {
63
+ msg: MessageInput;
64
+ params?: MessageParams;
65
+ languageId?: LanguageId;
66
+ };
67
+ export type GetJsxHandler<Output = unknown> = (options: MessageFormatOptions) => Output;
68
+ export type CompiledTranslation = {
69
+ compiled: CompactMessage;
70
+ };
71
+ export type TranslationGetter = (args: {
72
+ languageId: LanguageId;
73
+ context: MessageContext | null;
74
+ message: string;
75
+ getCompiledId?: () => string;
76
+ }) => CompactMessage | CompiledTranslation | null;
77
+ export declare function isMessageDescriptor(value: unknown): value is AnyMessageDescriptor;
78
+ export declare function isMessageTagHandler(value: unknown): value is MessageTagHandler;
79
+ export declare function isMessageSchemaValue(value: unknown): value is MessageSchemaValue;
@@ -0,0 +1,90 @@
1
+ // src/shared/hash.ts
2
+ const MASK_64 = 18446744073709551615n;
3
+ const C1 = 9782798678568883157n;
4
+ const C2 = 5545529020109919103n;
5
+ const BASE64URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
6
+ const DEFAULT_HASH_LENGTH = 8;
7
+ const MIN_HASH_LENGTH = 6;
8
+ const MAX_HASH_LENGTH = 22;
9
+ function normalizeHashLength(length = 8) {
10
+ if (!Number.isInteger(length) || length < 6 || length > 22) throw new RangeError(`[i18n] compiled.hashLength must be an integer from 6 to 22`);
11
+ return length;
12
+ }
13
+ function rotateLeft(value, bits) {
14
+ return (value << bits | value >> 64n - bits) & MASK_64;
15
+ }
16
+ function mixFinal(value) {
17
+ value ^= value >> 33n;
18
+ value = value * 18397679294719823053n & MASK_64;
19
+ value ^= value >> 33n;
20
+ value = value * 14181476777654086739n & MASK_64;
21
+ return (value ^ value >> 33n) & MASK_64;
22
+ }
23
+ function read64(bytes, offset) {
24
+ let value = 0n;
25
+ for (let index = 0; index < 8; index += 1) value |= BigInt(bytes[offset + index]) << BigInt(index * 8);
26
+ return value;
27
+ }
28
+ function encodeBase64Url(bytes) {
29
+ let result = "";
30
+ for (let index = 0; index < bytes.length; index += 3) {
31
+ const a = bytes[index];
32
+ const b = bytes[index + 1];
33
+ const c = bytes[index + 2];
34
+ result += BASE64URL[a >> 2];
35
+ result += BASE64URL[(a & 3) << 4 | (b ?? 0) >> 4];
36
+ if (b !== void 0) result += BASE64URL[(b & 15) << 2 | (c ?? 0) >> 6];
37
+ if (c !== void 0) result += BASE64URL[c & 63];
38
+ }
39
+ return result;
40
+ }
41
+ /** MurmurHash3 x64 128-bit, encoded as unpadded base64url. */
42
+ function murmurHash128(value) {
43
+ const bytes = new TextEncoder().encode(value);
44
+ const blocks = Math.floor(bytes.length / 16);
45
+ let h1 = 0n;
46
+ let h2 = 0n;
47
+ for (let block = 0; block < blocks; block += 1) {
48
+ let k1 = read64(bytes, block * 16);
49
+ let k2 = read64(bytes, block * 16 + 8);
50
+ k1 = rotateLeft(k1 * C1 & MASK_64, 31n) * C2 & MASK_64;
51
+ h1 ^= k1;
52
+ h1 = (rotateLeft(h1, 27n) + h2) * 5n + 1390208809n & MASK_64;
53
+ k2 = rotateLeft(k2 * C2 & MASK_64, 33n) * C1 & MASK_64;
54
+ h2 ^= k2;
55
+ h2 = (rotateLeft(h2, 31n) + h1) * 5n + 944331445n & MASK_64;
56
+ }
57
+ const tail = blocks * 16;
58
+ let k1 = 0n;
59
+ let k2 = 0n;
60
+ for (let index = bytes.length - 1; index >= tail + 8; index -= 1) k2 = k2 << 8n | BigInt(bytes[index]);
61
+ for (let index = Math.min(bytes.length, tail + 8) - 1; index >= tail; index -= 1) k1 = k1 << 8n | BigInt(bytes[index]);
62
+ if (k2) {
63
+ k2 = rotateLeft(k2 * C2 & MASK_64, 33n) * C1 & MASK_64;
64
+ h2 ^= k2;
65
+ }
66
+ if (k1) {
67
+ k1 = rotateLeft(k1 * C1 & MASK_64, 31n) * C2 & MASK_64;
68
+ h1 ^= k1;
69
+ }
70
+ h1 ^= BigInt(bytes.length);
71
+ h2 ^= BigInt(bytes.length);
72
+ h1 = h1 + h2 & MASK_64;
73
+ h2 = h2 + h1 & MASK_64;
74
+ h1 = mixFinal(h1);
75
+ h2 = mixFinal(h2);
76
+ h1 = h1 + h2 & MASK_64;
77
+ h2 = h2 + h1 & MASK_64;
78
+ const output = /* @__PURE__ */ new Uint8Array(16);
79
+ for (let index = 0; index < 8; index += 1) {
80
+ output[index] = Number(h1 >> BigInt(index * 8) & 255n);
81
+ output[index + 8] = Number(h2 >> BigInt(index * 8) & 255n);
82
+ }
83
+ return encodeBase64Url(output);
84
+ }
85
+ function messageHash(identity, length = 8) {
86
+ return murmurHash128(identity).slice(0, normalizeHashLength(length));
87
+ }
88
+ export { normalizeHashLength as a, messageHash as i, MAX_HASH_LENGTH as n, MIN_HASH_LENGTH as r, DEFAULT_HASH_LENGTH as t };
89
+
90
+ //# sourceMappingURL=hash-VJlyT31Z.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash-VJlyT31Z.js","names":[],"sources":["../src/shared/hash.ts"],"sourcesContent":["const MASK_64 = 0xffffffffffffffffn;\nconst C1 = 0x87c37b91114253d5n;\nconst C2 = 0x4cf5ad432745937fn;\nconst BASE64URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_';\n\nexport const DEFAULT_HASH_LENGTH = 8;\nexport const MIN_HASH_LENGTH = 6;\nexport const MAX_HASH_LENGTH = 22;\n\nexport function normalizeHashLength(length = DEFAULT_HASH_LENGTH): number {\n if (!Number.isInteger(length) || length < MIN_HASH_LENGTH || length > MAX_HASH_LENGTH) {\n throw new RangeError(`[i18n] compiled.hashLength must be an integer from ${MIN_HASH_LENGTH} to ${MAX_HASH_LENGTH}`);\n }\n return length;\n}\n\nfunction rotateLeft(value: bigint, bits: bigint): bigint {\n return ((value << bits) | (value >> (64n - bits))) & MASK_64;\n}\n\nfunction mixFinal(value: bigint): bigint {\n value ^= value >> 33n;\n value = value * 0xff51afd7ed558ccdn & MASK_64;\n value ^= value >> 33n;\n value = value * 0xc4ceb9fe1a85ec53n & MASK_64;\n return (value ^ value >> 33n) & MASK_64;\n}\n\nfunction read64(bytes: Uint8Array, offset: number): bigint {\n let value = 0n;\n for (let index = 0; index < 8; index += 1) value |= BigInt(bytes[offset + index]) << BigInt(index * 8);\n return value;\n}\n\nfunction encodeBase64Url(bytes: Uint8Array): string {\n let result = '';\n for (let index = 0; index < bytes.length; index += 3) {\n const a = bytes[index];\n const b = bytes[index + 1];\n const c = bytes[index + 2];\n result += BASE64URL[a >> 2];\n result += BASE64URL[(a & 3) << 4 | (b ?? 0) >> 4];\n if (b !== undefined) result += BASE64URL[(b & 15) << 2 | (c ?? 0) >> 6];\n if (c !== undefined) result += BASE64URL[c & 63];\n }\n return result;\n}\n\n/** MurmurHash3 x64 128-bit, encoded as unpadded base64url. */\nexport function murmurHash128(value: string): string {\n const bytes = new TextEncoder().encode(value);\n const blocks = Math.floor(bytes.length / 16);\n let h1 = 0n;\n let h2 = 0n;\n\n for (let block = 0; block < blocks; block += 1) {\n let k1 = read64(bytes, block * 16);\n let k2 = read64(bytes, block * 16 + 8);\n k1 = rotateLeft(k1 * C1 & MASK_64, 31n) * C2 & MASK_64;\n h1 ^= k1;\n h1 = (rotateLeft(h1, 27n) + h2) * 5n + 0x52dce729n & MASK_64;\n k2 = rotateLeft(k2 * C2 & MASK_64, 33n) * C1 & MASK_64;\n h2 ^= k2;\n h2 = (rotateLeft(h2, 31n) + h1) * 5n + 0x38495ab5n & MASK_64;\n }\n\n const tail = blocks * 16;\n let k1 = 0n;\n let k2 = 0n;\n for (let index = bytes.length - 1; index >= tail + 8; index -= 1) {\n k2 = k2 << 8n | BigInt(bytes[index]);\n }\n for (let index = Math.min(bytes.length, tail + 8) - 1; index >= tail; index -= 1) {\n k1 = k1 << 8n | BigInt(bytes[index]);\n }\n if (k2) {\n k2 = rotateLeft(k2 * C2 & MASK_64, 33n) * C1 & MASK_64;\n h2 ^= k2;\n }\n if (k1) {\n k1 = rotateLeft(k1 * C1 & MASK_64, 31n) * C2 & MASK_64;\n h1 ^= k1;\n }\n\n h1 ^= BigInt(bytes.length);\n h2 ^= BigInt(bytes.length);\n h1 = h1 + h2 & MASK_64;\n h2 = h2 + h1 & MASK_64;\n h1 = mixFinal(h1);\n h2 = mixFinal(h2);\n h1 = h1 + h2 & MASK_64;\n h2 = h2 + h1 & MASK_64;\n const output = new Uint8Array(16);\n for (let index = 0; index < 8; index += 1) {\n output[index] = Number(h1 >> BigInt(index * 8) & 0xffn);\n output[index + 8] = Number(h2 >> BigInt(index * 8) & 0xffn);\n }\n return encodeBase64Url(output);\n}\n\nexport function messageHash(identity: string, length = DEFAULT_HASH_LENGTH): string {\n return murmurHash128(identity).slice(0, normalizeHashLength(length));\n}\n"],"mappings":";AAAA,MAAM,UAAU;AAChB,MAAM,KAAK;AACX,MAAM,KAAK;AACX,MAAM,YAAY;AAElB,MAAa,sBAAsB;AACnC,MAAa,kBAAkB;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IAAK;CAC5D;CACA,OAAO,gBAAgB,MAAM;AAC/B;AAEA,SAAgB,YAAY,UAAkB,SAAA,GAAsC;CAClF,OAAO,cAAc,QAAQ,CAAC,CAAC,MAAM,GAAG,oBAAoB,MAAM,CAAC;AACrE"}
@@ -0,0 +1,13 @@
1
+ // src/hydration-store.ts
2
+ const controllers = /* @__PURE__ */ new WeakMap();
3
+ function registerHydration(target, controller) {
4
+ controllers.set(target, controller);
5
+ }
6
+ function getHydration(target) {
7
+ const controller = controllers.get(target);
8
+ if (!controller) throw new TypeError("[i18n] hydration requires an i18n manager instance");
9
+ return controller;
10
+ }
11
+ export { registerHydration as n, getHydration as t };
12
+
13
+ //# sourceMappingURL=hydration-store-BK6UxrtJ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydration-store-BK6UxrtJ.js","names":[],"sources":["../src/hydration-store.ts"],"sourcesContent":["import type { Formats, Runtime } from './shared/runtime';\nimport type { Catalog } from './translation-manager';\n\nexport type I18nSnapshot = {\n languageId: string;\n fallbackLanguageId?: string;\n translations: Record<string, Catalog>;\n formats?: Partial<Formats>;\n compiledLanguages?: string[];\n};\n\ntype HydrationController = {\n runtime: Runtime;\n state: {\n set(value: Partial<{ languageId: string; isLoading: boolean; ready: boolean; }>): void;\n };\n translations: {\n catalogs: Record<string, Catalog>;\n compiledCatalogs: Record<string, boolean>;\n };\n getFallbackLanguageId(): string | undefined;\n setFallbackLanguageId(languageId: string | undefined): void;\n invalidate(): void;\n};\n\nconst controllers = new WeakMap<object, HydrationController>();\n\nexport function registerHydration(target: object, controller: HydrationController): void {\n controllers.set(target, controller);\n}\n\nexport function getHydration(target: object): HydrationController {\n const controller = controllers.get(target);\n\n if (!controller) throw new TypeError('[i18n] hydration requires an i18n manager instance');\n\n return controller;\n}\n"],"mappings":";AAyBA,MAAM,8BAAc,IAAI,QAAqC;AAE7D,SAAgB,kBAAkB,QAAgB,YAAuC;CACvF,YAAY,IAAI,QAAQ,UAAU;AACpC;AAEA,SAAgB,aAAa,QAAqC;CAChE,MAAM,aAAa,YAAY,IAAI,MAAM;CAEzC,IAAI,CAAC,YAAY,MAAM,IAAI,UAAU,oDAAoD;CAEzF,OAAO;AACT"}
@@ -0,0 +1,29 @@
1
+ import type { Formats, Runtime } from './shared/runtime';
2
+ import type { Catalog } from './translation-manager';
3
+ export type I18nSnapshot = {
4
+ languageId: string;
5
+ fallbackLanguageId?: string;
6
+ translations: Record<string, Catalog>;
7
+ formats?: Partial<Formats>;
8
+ compiledLanguages?: string[];
9
+ };
10
+ type HydrationController = {
11
+ runtime: Runtime;
12
+ state: {
13
+ set(value: Partial<{
14
+ languageId: string;
15
+ isLoading: boolean;
16
+ ready: boolean;
17
+ }>): void;
18
+ };
19
+ translations: {
20
+ catalogs: Record<string, Catalog>;
21
+ compiledCatalogs: Record<string, boolean>;
22
+ };
23
+ getFallbackLanguageId(): string | undefined;
24
+ setFallbackLanguageId(languageId: string | undefined): void;
25
+ invalidate(): void;
26
+ };
27
+ export declare function registerHydration(target: object, controller: HydrationController): void;
28
+ export declare function getHydration(target: object): HydrationController;
29
+ export {};
@@ -0,0 +1,7 @@
1
+ import { type I18nSnapshot } from './hydration-store';
2
+ import type { ManagedI18n } from './manager';
3
+ export type { I18nSnapshot } from './hydration-store';
4
+ /** Capture loaded catalogs and locale state for transfer to another runtime. */
5
+ export declare function getSnapshot(instance: ManagedI18n): I18nSnapshot;
6
+ /** Initialize a runtime from a server-produced snapshot without loading catalogs. */
7
+ export declare function hydrate(instance: ManagedI18n, snapshot: I18nSnapshot): void;
@@ -0,0 +1,35 @@
1
+ import { a as getFormats } from "./runtime-DXnGeCBw.js";
2
+ import { t as getHydration } from "./hydration-store-BK6UxrtJ.js";
3
+ // src/hydration.ts
4
+ /** Capture loaded catalogs and locale state for transfer to another runtime. */
5
+ function getSnapshot(instance) {
6
+ const { runtime, translations, getFallbackLanguageId } = getHydration(instance);
7
+ return {
8
+ languageId: runtime.languageId,
9
+ fallbackLanguageId: getFallbackLanguageId(),
10
+ translations: Object.fromEntries(Object.entries(translations.catalogs).map(([id, catalog]) => [id, { ...catalog }])),
11
+ formats: getFormats(runtime, runtime.languageId),
12
+ compiledLanguages: Object.keys(translations.compiledCatalogs).filter((id) => translations.compiledCatalogs[id])
13
+ };
14
+ }
15
+ /** Initialize a runtime from a server-produced snapshot without loading catalogs. */
16
+ function hydrate(instance, snapshot) {
17
+ const { runtime, state, translations, setFallbackLanguageId, invalidate } = getHydration(instance);
18
+ invalidate();
19
+ for (const id of Object.keys(translations.catalogs)) delete translations.catalogs[id];
20
+ for (const id of Object.keys(translations.compiledCatalogs)) delete translations.compiledCatalogs[id];
21
+ for (const [id, catalog] of Object.entries(snapshot.translations)) translations.catalogs[id] = Object.assign(Object.create(null), catalog);
22
+ for (const id of snapshot.compiledLanguages ?? []) translations.compiledCatalogs[id] = true;
23
+ runtime.formats = snapshot.formats ?? {};
24
+ runtime.languageId = snapshot.languageId;
25
+ setFallbackLanguageId(snapshot.fallbackLanguageId);
26
+ runtime.ready = true;
27
+ state.set({
28
+ languageId: snapshot.languageId,
29
+ ready: true,
30
+ isLoading: false
31
+ });
32
+ }
33
+ export { getSnapshot, hydrate };
34
+
35
+ //# sourceMappingURL=hydration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hydration.js","names":[],"sources":["../src/hydration.ts"],"sourcesContent":["import { getHydration, type I18nSnapshot } from './hydration-store';\nimport type { ManagedI18n } from './manager';\nimport { getFormats } from './shared/runtime';\n\nexport type { I18nSnapshot } from './hydration-store';\n\n/** Capture loaded catalogs and locale state for transfer to another runtime. */\nexport function getSnapshot(instance: ManagedI18n): I18nSnapshot {\n const { runtime, translations, getFallbackLanguageId } = getHydration(instance);\n\n return {\n languageId: runtime.languageId,\n fallbackLanguageId: getFallbackLanguageId(),\n translations: Object.fromEntries(\n Object.entries(translations.catalogs).map(([id, catalog]) => [id, { ...catalog }]),\n ),\n formats: getFormats(runtime, runtime.languageId),\n compiledLanguages: Object.keys(translations.compiledCatalogs).filter(\n (id) => translations.compiledCatalogs[id],\n ),\n };\n}\n\n/** Initialize a runtime from a server-produced snapshot without loading catalogs. */\nexport function hydrate(instance: ManagedI18n, snapshot: I18nSnapshot): void {\n const { runtime, state, translations, setFallbackLanguageId, invalidate } = getHydration(instance);\n invalidate();\n\n for (const id of Object.keys(translations.catalogs)) delete translations.catalogs[id];\n for (const id of Object.keys(translations.compiledCatalogs)) delete translations.compiledCatalogs[id];\n for (const [id, catalog] of Object.entries(snapshot.translations)) {\n translations.catalogs[id] = Object.assign(Object.create(null), catalog);\n }\n\n for (const id of snapshot.compiledLanguages ?? []) translations.compiledCatalogs[id] = true;\n\n runtime.formats = snapshot.formats ?? {};\n runtime.languageId = snapshot.languageId;\n setFallbackLanguageId(snapshot.fallbackLanguageId);\n runtime.ready = true;\n state.set({ languageId: snapshot.languageId, ready: true, isLoading: false });\n}\n"],"mappings":";;;;AAOA,SAAgB,YAAY,UAAqC;CAC/D,MAAM,EAAE,SAAS,cAAc,0BAA0B,aAAa,QAAQ;CAE9E,OAAO;EACL,YAAY,QAAQ;EACpB,oBAAoB,sBAAsB;EAC1C,cAAc,OAAO,YACnB,OAAO,QAAQ,aAAa,QAAQ,CAAC,CAAC,KAAK,CAAC,IAAI,aAAa,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC,CACnF;EACA,SAAS,WAAW,SAAS,QAAQ,UAAU;EAC/C,mBAAmB,OAAO,KAAK,aAAa,gBAAgB,CAAC,CAAC,QAC3D,OAAO,aAAa,iBAAiB,GACxC;CACF;AACF;;AAGA,SAAgB,QAAQ,UAAuB,UAA8B;CAC3E,MAAM,EAAE,SAAS,OAAO,cAAc,uBAAuB,eAAe,aAAa,QAAQ;CACjG,WAAW;CAEX,KAAK,MAAM,MAAM,OAAO,KAAK,aAAa,QAAQ,GAAG,OAAO,aAAa,SAAS;CAClF,KAAK,MAAM,MAAM,OAAO,KAAK,aAAa,gBAAgB,GAAG,OAAO,aAAa,iBAAiB;CAClG,KAAK,MAAM,CAAC,IAAI,YAAY,OAAO,QAAQ,SAAS,YAAY,GAC9D,aAAa,SAAS,MAAM,OAAO,OAAO,OAAO,OAAO,IAAI,GAAG,OAAO;CAGxE,KAAK,MAAM,MAAM,SAAS,qBAAqB,CAAC,GAAG,aAAa,iBAAiB,MAAM;CAEvF,QAAQ,UAAU,SAAS,WAAW,CAAC;CACvC,QAAQ,aAAa,SAAS;CAC9B,sBAAsB,SAAS,kBAAkB;CACjD,QAAQ,QAAQ;CAChB,MAAM,IAAI;EAAE,YAAY,SAAS;EAAY,OAAO;EAAM,WAAW;CAAM,CAAC;AAC9E"}
@@ -0,0 +1,6 @@
1
+ export declare const t: import(".").TApi<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, import("react").ReactNode>;
2
+ export type { MessageApi, TApi } from './core/i18n';
3
+ export * from './core/types';
4
+ export { I18nRegistry, noTranslate, setFormats } from './shared/runtime';
5
+ export { defineTranslationLoader } from './translation-manager';
6
+ export type { TranslationData, TranslationItem, TranslationLoader, TranslationLoaderMap } from './translation-manager';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { t } from "./src-ON68XIog.js";
2
+ import { l as setFormats, s as noTranslate, t as I18nRegistry } from "./runtime-DXnGeCBw.js";
3
+ import { n as isMessageSchemaValue, r as isMessageTagHandler, t as isMessageDescriptor } from "./types-BkDsJfVD.js";
4
+ import { n as defineTranslationLoader } from "./translation-manager-BkmFnlb_.js";
5
+ export { I18nRegistry, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };