@embedpdf/plugin-i18n 2.15.0 → 3.0.0-next.1

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 (64) hide show
  1. package/LICENSE +192 -21
  2. package/dist/index.cjs +268 -2
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.d.cts +159 -0
  5. package/dist/index.d.ts +159 -1
  6. package/dist/index.js +262 -397
  7. package/dist/index.js.map +1 -1
  8. package/package.json +18 -58
  9. package/dist/lib/actions.d.ts +0 -15
  10. package/dist/lib/i18n-plugin.d.ts +0 -28
  11. package/dist/lib/index.d.ts +0 -9
  12. package/dist/lib/locales/en.d.ts +0 -2
  13. package/dist/lib/locales/es.d.ts +0 -2
  14. package/dist/lib/locales/index.d.ts +0 -2
  15. package/dist/lib/manifest.d.ts +0 -4
  16. package/dist/lib/reducer.d.ts +0 -5
  17. package/dist/lib/types.d.ts +0 -104
  18. package/dist/preact/adapter.d.ts +0 -5
  19. package/dist/preact/core.d.ts +0 -1
  20. package/dist/preact/index.cjs +0 -2
  21. package/dist/preact/index.cjs.map +0 -1
  22. package/dist/preact/index.d.ts +0 -1
  23. package/dist/preact/index.js +0 -70
  24. package/dist/preact/index.js.map +0 -1
  25. package/dist/react/adapter.d.ts +0 -2
  26. package/dist/react/core.d.ts +0 -1
  27. package/dist/react/index.cjs +0 -2
  28. package/dist/react/index.cjs.map +0 -1
  29. package/dist/react/index.d.ts +0 -1
  30. package/dist/react/index.js +0 -69
  31. package/dist/react/index.js.map +0 -1
  32. package/dist/shared/components/index.d.ts +0 -1
  33. package/dist/shared/components/translate.d.ts +0 -35
  34. package/dist/shared/hooks/index.d.ts +0 -1
  35. package/dist/shared/hooks/use-i18n.d.ts +0 -43
  36. package/dist/shared/index.d.ts +0 -3
  37. package/dist/shared-preact/components/index.d.ts +0 -1
  38. package/dist/shared-preact/components/translate.d.ts +0 -35
  39. package/dist/shared-preact/hooks/index.d.ts +0 -1
  40. package/dist/shared-preact/hooks/use-i18n.d.ts +0 -43
  41. package/dist/shared-preact/index.d.ts +0 -3
  42. package/dist/shared-react/components/index.d.ts +0 -1
  43. package/dist/shared-react/components/translate.d.ts +0 -35
  44. package/dist/shared-react/hooks/index.d.ts +0 -1
  45. package/dist/shared-react/hooks/use-i18n.d.ts +0 -43
  46. package/dist/shared-react/index.d.ts +0 -3
  47. package/dist/svelte/components/Translate.svelte.d.ts +0 -9
  48. package/dist/svelte/components/index.d.ts +0 -1
  49. package/dist/svelte/hooks/index.d.ts +0 -1
  50. package/dist/svelte/hooks/use-i18n.svelte.d.ts +0 -41
  51. package/dist/svelte/index.cjs +0 -2
  52. package/dist/svelte/index.cjs.map +0 -1
  53. package/dist/svelte/index.d.ts +0 -3
  54. package/dist/svelte/index.js +0 -90
  55. package/dist/svelte/index.js.map +0 -1
  56. package/dist/vue/components/index.d.ts +0 -1
  57. package/dist/vue/components/translate.vue.d.ts +0 -9
  58. package/dist/vue/hooks/index.d.ts +0 -1
  59. package/dist/vue/hooks/use-i18n.d.ts +0 -30
  60. package/dist/vue/index.cjs +0 -2
  61. package/dist/vue/index.cjs.map +0 -1
  62. package/dist/vue/index.d.ts +0 -3
  63. package/dist/vue/index.js +0 -99
  64. package/dist/vue/index.js.map +0 -1
@@ -0,0 +1,159 @@
1
+ //#region src/types.d.ts
2
+ /**
3
+ * @embedpdf/plugin-i18n — the contract.
4
+ *
5
+ * Translation is pure data over pure state: locale packs live IN the store
6
+ * (not in a side-table), so `t()` is a pure read, every consumer is reactive
7
+ * through the one kernel change stream, and the whole thing serializes (SSR,
8
+ * snapshots, persist). Workspace-scoped, `requires: []`, never touches the
9
+ * engine or the DOM — the capability is alive from `createKernel()`, before
10
+ * a single WASM byte is fetched. The plugin ships NO strings: mechanism here,
11
+ * content (locale packs) in the product that embeds it.
12
+ */
13
+ /** Nested tree of translation strings. Leaves interpolate `{param}` slots. */
14
+ interface TranslationDictionary {
15
+ readonly [key: string]: string | TranslationDictionary;
16
+ }
17
+ interface Locale {
18
+ /** BCP-47 code: 'en', 'es', 'ar', 'zh-Hans'. */
19
+ readonly code: string;
20
+ /** Native display name: 'Español' — what a locale switcher shows. */
21
+ readonly name: string;
22
+ /** Text direction for viewer chrome. Defaults to 'ltr'. */
23
+ readonly dir?: 'ltr' | 'rtl';
24
+ readonly translations: TranslationDictionary;
25
+ }
26
+ interface I18nState {
27
+ readonly locale: string;
28
+ readonly fallbackLocale: string;
29
+ /** Registered packs by code — the lookup table `t()` reads. */
30
+ readonly locales: Readonly<Record<string, Locale>>;
31
+ /** Code of a lazy pack currently being fetched (drives switcher spinners). */
32
+ readonly loading: string | null;
33
+ }
34
+ type I18nAction =
35
+ /** Switch to a REGISTERED locale. The reducer ignores unregistered codes —
36
+ * loading a lazy pack goes through LOAD_STARTED (the capability routes). */
37
+ {
38
+ type: 'I18N/SET_LOCALE';
39
+ locale: string;
40
+ } | {
41
+ type: 'I18N/REGISTER_LOCALE';
42
+ locale: Locale;
43
+ } | {
44
+ type: 'I18N/LOAD_STARTED';
45
+ locale: string;
46
+ } | {
47
+ type: 'I18N/LOAD_FAILED';
48
+ locale: string;
49
+ };
50
+ interface I18nConfig {
51
+ /**
52
+ * Startup locale. Compute platform inputs OUTSIDE the plugin — it never
53
+ * touches the DOM:
54
+ *
55
+ * ```ts
56
+ * i18nPlugin({ locale: negotiateLocale(codes, navigator.languages) ?? 'en' })
57
+ * ```
58
+ *
59
+ * May name a `loaders` pack: the fallback locale shows until the pack
60
+ * arrives (effects fetch it at startup). Defaults to `fallbackLocale`.
61
+ */
62
+ locale?: string;
63
+ /** The pack tried when a key misses the current locale. Default 'en'. */
64
+ fallbackLocale?: string;
65
+ /** Eagerly available packs. */
66
+ locales?: Locale[];
67
+ /**
68
+ * Lazy packs: code → loader. `setLocale(code)` fetches on demand (in
69
+ * effects), registers the pack, then switches. Until a lazy pack loads, a
70
+ * locale switcher shows its code as the name — register eagerly (packs are
71
+ * small) when you want native names in the switcher up front.
72
+ */
73
+ loaders?: Record<string, () => Promise<Locale>>;
74
+ }
75
+ interface TranslateOptions {
76
+ /**
77
+ * `{slot}` interpolation values. When `count` is a number and the key
78
+ * resolves to a branch object, the branch is picked by CLDR plural
79
+ * category (`Intl.PluralRules`), falling back to `other`:
80
+ *
81
+ * ```ts
82
+ * // pages: { one: '{count} page', other: '{count} pages' }
83
+ * t('pages', { params: { count: 1 } }) // '1 page'
84
+ * ```
85
+ */
86
+ params?: Record<string, string | number>;
87
+ /** Returned (interpolated) when the key misses every pack — instead of the key. */
88
+ fallback?: string;
89
+ }
90
+ /** A locale as a switcher sees it — registered packs plus not-yet-loaded lazy ones. */
91
+ interface LocaleInfo {
92
+ readonly code: string;
93
+ /** Native name; the bare code until a lazy pack has loaded. */
94
+ readonly name: string;
95
+ readonly dir: 'ltr' | 'rtl';
96
+ readonly loaded: boolean;
97
+ }
98
+ interface I18nCapability {
99
+ /** Translate a key: current locale → fallback locale → `options.fallback` → the key. */
100
+ t(key: string, options?: TranslateOptions): string;
101
+ locale(): string;
102
+ /** Text direction of the CURRENT locale — wire to `dir=` on the shell. */
103
+ dir(): 'ltr' | 'rtl';
104
+ /** Every known locale (registered + lazy), in registration order. */
105
+ locales(): LocaleInfo[];
106
+ /** Code of the lazy pack being fetched right now, if any. */
107
+ loading(): string | null;
108
+ /** Switch locale; fetches the pack first when it's a lazy one. */
109
+ setLocale(code: string): void;
110
+ /** Register a pack at runtime (customer-supplied translations). */
111
+ registerLocale(locale: Locale): void;
112
+ }
113
+ declare const I18nToken: import("@embedpdf/core").CapabilityToken<I18nCapability>;
114
+ //#endregion
115
+ //#region src/i18n.plugin.d.ts
116
+ /**
117
+ * The i18n plugin: workspace-scoped (locale is a workspace concern) with NO
118
+ * dependencies — engine-free, DOM-free. Its capability is built synchronously
119
+ * in `createKernel()`, so the shell translates from the first frame, while
120
+ * the engine is still booting.
121
+ */
122
+ declare const i18nPlugin: (config?: I18nConfig) => import("@embedpdf/core").PluginDef<I18nState, I18nAction, I18nCapability>;
123
+ //#endregion
124
+ //#region src/negotiate.d.ts
125
+ /**
126
+ * Pure BCP-47 locale negotiation — strings in, string out. The plugin never
127
+ * reads the platform; the EMBEDDER feeds it whatever request list its
128
+ * environment offers:
129
+ *
130
+ * ```ts
131
+ * // browser shell: negotiateLocale(['en', 'es', 'ar'], navigator.languages)
132
+ * // server render: negotiateLocale(codes, parseAcceptLanguage(header))
133
+ * ```
134
+ *
135
+ * Matching, per requested code in preference order:
136
+ * 1. exact match (case-insensitive): 'es-MX' → 'es-MX'
137
+ * 2. request narrowed to its language: 'en-GB' → 'en'
138
+ * 3. any available dialect of the language: 'zh' → 'zh-Hans'
139
+ *
140
+ * Returns the matched code exactly as it appears in `available`, or null.
141
+ */
142
+ declare function negotiateLocale(available: readonly string[], requested: readonly string[]): string | null;
143
+ //#endregion
144
+ //#region src/translate.d.ts
145
+ /** Replace `{slot}` markers; unknown slots stay verbatim (visible in QA). */
146
+ declare function interpolate(text: string, params?: Record<string, string | number>): string;
147
+ interface TranslateResult {
148
+ readonly text: string;
149
+ /** False when the key missed every pack (text is then the fallback or the key). */
150
+ readonly found: boolean;
151
+ }
152
+ /**
153
+ * Resolve a key against the state: current locale → fallback locale →
154
+ * `options.fallback` (interpolated too) → the key itself.
155
+ */
156
+ declare function translate(state: I18nState, key: string, options?: TranslateOptions): TranslateResult;
157
+ //#endregion
158
+ export { type I18nCapability, type I18nConfig, type I18nState, I18nToken, type Locale, type LocaleInfo, type TranslateOptions, type TranslateResult, type TranslationDictionary, i18nPlugin, interpolate, negotiateLocale, translate };
159
+ //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1 +1,159 @@
1
- export * from './lib';
1
+ //#region src/types.d.ts
2
+ /**
3
+ * @embedpdf/plugin-i18n — the contract.
4
+ *
5
+ * Translation is pure data over pure state: locale packs live IN the store
6
+ * (not in a side-table), so `t()` is a pure read, every consumer is reactive
7
+ * through the one kernel change stream, and the whole thing serializes (SSR,
8
+ * snapshots, persist). Workspace-scoped, `requires: []`, never touches the
9
+ * engine or the DOM — the capability is alive from `createKernel()`, before
10
+ * a single WASM byte is fetched. The plugin ships NO strings: mechanism here,
11
+ * content (locale packs) in the product that embeds it.
12
+ */
13
+ /** Nested tree of translation strings. Leaves interpolate `{param}` slots. */
14
+ interface TranslationDictionary {
15
+ readonly [key: string]: string | TranslationDictionary;
16
+ }
17
+ interface Locale {
18
+ /** BCP-47 code: 'en', 'es', 'ar', 'zh-Hans'. */
19
+ readonly code: string;
20
+ /** Native display name: 'Español' — what a locale switcher shows. */
21
+ readonly name: string;
22
+ /** Text direction for viewer chrome. Defaults to 'ltr'. */
23
+ readonly dir?: 'ltr' | 'rtl';
24
+ readonly translations: TranslationDictionary;
25
+ }
26
+ interface I18nState {
27
+ readonly locale: string;
28
+ readonly fallbackLocale: string;
29
+ /** Registered packs by code — the lookup table `t()` reads. */
30
+ readonly locales: Readonly<Record<string, Locale>>;
31
+ /** Code of a lazy pack currently being fetched (drives switcher spinners). */
32
+ readonly loading: string | null;
33
+ }
34
+ type I18nAction =
35
+ /** Switch to a REGISTERED locale. The reducer ignores unregistered codes —
36
+ * loading a lazy pack goes through LOAD_STARTED (the capability routes). */
37
+ {
38
+ type: 'I18N/SET_LOCALE';
39
+ locale: string;
40
+ } | {
41
+ type: 'I18N/REGISTER_LOCALE';
42
+ locale: Locale;
43
+ } | {
44
+ type: 'I18N/LOAD_STARTED';
45
+ locale: string;
46
+ } | {
47
+ type: 'I18N/LOAD_FAILED';
48
+ locale: string;
49
+ };
50
+ interface I18nConfig {
51
+ /**
52
+ * Startup locale. Compute platform inputs OUTSIDE the plugin — it never
53
+ * touches the DOM:
54
+ *
55
+ * ```ts
56
+ * i18nPlugin({ locale: negotiateLocale(codes, navigator.languages) ?? 'en' })
57
+ * ```
58
+ *
59
+ * May name a `loaders` pack: the fallback locale shows until the pack
60
+ * arrives (effects fetch it at startup). Defaults to `fallbackLocale`.
61
+ */
62
+ locale?: string;
63
+ /** The pack tried when a key misses the current locale. Default 'en'. */
64
+ fallbackLocale?: string;
65
+ /** Eagerly available packs. */
66
+ locales?: Locale[];
67
+ /**
68
+ * Lazy packs: code → loader. `setLocale(code)` fetches on demand (in
69
+ * effects), registers the pack, then switches. Until a lazy pack loads, a
70
+ * locale switcher shows its code as the name — register eagerly (packs are
71
+ * small) when you want native names in the switcher up front.
72
+ */
73
+ loaders?: Record<string, () => Promise<Locale>>;
74
+ }
75
+ interface TranslateOptions {
76
+ /**
77
+ * `{slot}` interpolation values. When `count` is a number and the key
78
+ * resolves to a branch object, the branch is picked by CLDR plural
79
+ * category (`Intl.PluralRules`), falling back to `other`:
80
+ *
81
+ * ```ts
82
+ * // pages: { one: '{count} page', other: '{count} pages' }
83
+ * t('pages', { params: { count: 1 } }) // '1 page'
84
+ * ```
85
+ */
86
+ params?: Record<string, string | number>;
87
+ /** Returned (interpolated) when the key misses every pack — instead of the key. */
88
+ fallback?: string;
89
+ }
90
+ /** A locale as a switcher sees it — registered packs plus not-yet-loaded lazy ones. */
91
+ interface LocaleInfo {
92
+ readonly code: string;
93
+ /** Native name; the bare code until a lazy pack has loaded. */
94
+ readonly name: string;
95
+ readonly dir: 'ltr' | 'rtl';
96
+ readonly loaded: boolean;
97
+ }
98
+ interface I18nCapability {
99
+ /** Translate a key: current locale → fallback locale → `options.fallback` → the key. */
100
+ t(key: string, options?: TranslateOptions): string;
101
+ locale(): string;
102
+ /** Text direction of the CURRENT locale — wire to `dir=` on the shell. */
103
+ dir(): 'ltr' | 'rtl';
104
+ /** Every known locale (registered + lazy), in registration order. */
105
+ locales(): LocaleInfo[];
106
+ /** Code of the lazy pack being fetched right now, if any. */
107
+ loading(): string | null;
108
+ /** Switch locale; fetches the pack first when it's a lazy one. */
109
+ setLocale(code: string): void;
110
+ /** Register a pack at runtime (customer-supplied translations). */
111
+ registerLocale(locale: Locale): void;
112
+ }
113
+ declare const I18nToken: import("@embedpdf/core").CapabilityToken<I18nCapability>;
114
+ //#endregion
115
+ //#region src/i18n.plugin.d.ts
116
+ /**
117
+ * The i18n plugin: workspace-scoped (locale is a workspace concern) with NO
118
+ * dependencies — engine-free, DOM-free. Its capability is built synchronously
119
+ * in `createKernel()`, so the shell translates from the first frame, while
120
+ * the engine is still booting.
121
+ */
122
+ declare const i18nPlugin: (config?: I18nConfig) => import("@embedpdf/core").PluginDef<I18nState, I18nAction, I18nCapability>;
123
+ //#endregion
124
+ //#region src/negotiate.d.ts
125
+ /**
126
+ * Pure BCP-47 locale negotiation — strings in, string out. The plugin never
127
+ * reads the platform; the EMBEDDER feeds it whatever request list its
128
+ * environment offers:
129
+ *
130
+ * ```ts
131
+ * // browser shell: negotiateLocale(['en', 'es', 'ar'], navigator.languages)
132
+ * // server render: negotiateLocale(codes, parseAcceptLanguage(header))
133
+ * ```
134
+ *
135
+ * Matching, per requested code in preference order:
136
+ * 1. exact match (case-insensitive): 'es-MX' → 'es-MX'
137
+ * 2. request narrowed to its language: 'en-GB' → 'en'
138
+ * 3. any available dialect of the language: 'zh' → 'zh-Hans'
139
+ *
140
+ * Returns the matched code exactly as it appears in `available`, or null.
141
+ */
142
+ declare function negotiateLocale(available: readonly string[], requested: readonly string[]): string | null;
143
+ //#endregion
144
+ //#region src/translate.d.ts
145
+ /** Replace `{slot}` markers; unknown slots stay verbatim (visible in QA). */
146
+ declare function interpolate(text: string, params?: Record<string, string | number>): string;
147
+ interface TranslateResult {
148
+ readonly text: string;
149
+ /** False when the key missed every pack (text is then the fallback or the key). */
150
+ readonly found: boolean;
151
+ }
152
+ /**
153
+ * Resolve a key against the state: current locale → fallback locale →
154
+ * `options.fallback` (interpolated too) → the key itself.
155
+ */
156
+ declare function translate(state: I18nState, key: string, options?: TranslateOptions): TranslateResult;
157
+ //#endregion
158
+ export { type I18nCapability, type I18nConfig, type I18nState, I18nToken, type Locale, type LocaleInfo, type TranslateOptions, type TranslateResult, type TranslationDictionary, i18nPlugin, interpolate, negotiateLocale, translate };
159
+ //# sourceMappingURL=index.d.ts.map