@embedpdf/react 3.0.0-next.13 → 3.0.0-next.15

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 (232) hide show
  1. package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.cts +877 -0
  2. package/dist/AnnotationList-CkijRHet-HEFNUIZe.d.ts +877 -0
  3. package/dist/actions.cjs +25 -5
  4. package/dist/actions.cjs.map +1 -1
  5. package/dist/actions.d.cts +18 -5
  6. package/dist/actions.d.ts +18 -5
  7. package/dist/actions.js +22 -6
  8. package/dist/actions.js.map +1 -1
  9. package/dist/anchored-DeX95xSd.d.ts +85 -0
  10. package/dist/anchored-DzN3JywS.d.cts +85 -0
  11. package/dist/anchored.cjs +71 -28
  12. package/dist/anchored.cjs.map +1 -1
  13. package/dist/anchored.d.cts +2 -45
  14. package/dist/anchored.d.ts +2 -45
  15. package/dist/anchored.js +56 -19
  16. package/dist/anchored.js.map +1 -1
  17. package/dist/annotation-B48UT2ln.d.ts +302 -0
  18. package/dist/annotation-C1ttM8Wj.js +708 -0
  19. package/dist/annotation-C1ttM8Wj.js.map +1 -0
  20. package/dist/annotation-C9dVwo9b.d.cts +302 -0
  21. package/dist/annotation-Dex5EBda.cjs +830 -0
  22. package/dist/annotation-Dex5EBda.cjs.map +1 -0
  23. package/dist/annotation.cjs +20 -783
  24. package/dist/annotation.d.cts +2 -2
  25. package/dist/annotation.d.ts +2 -2
  26. package/dist/annotation.js +2 -768
  27. package/dist/commands.cjs +68 -28
  28. package/dist/commands.cjs.map +1 -1
  29. package/dist/commands.d.cts +37 -10
  30. package/dist/commands.d.ts +37 -10
  31. package/dist/commands.js +68 -31
  32. package/dist/commands.js.map +1 -1
  33. package/dist/form-55izw0jS.js +511 -0
  34. package/dist/form-55izw0jS.js.map +1 -0
  35. package/dist/form-BNqQfGGH.cjs +548 -0
  36. package/dist/form-BNqQfGGH.cjs.map +1 -0
  37. package/dist/form.cjs +5 -5
  38. package/dist/form.d.cts +32 -25
  39. package/dist/form.d.ts +32 -25
  40. package/dist/form.js +2 -3
  41. package/dist/history.cjs +38 -0
  42. package/dist/history.cjs.map +1 -0
  43. package/dist/history.d.cts +27 -0
  44. package/dist/history.d.ts +27 -0
  45. package/dist/history.js +27 -0
  46. package/dist/history.js.map +1 -0
  47. package/dist/i18n.cjs +26 -30
  48. package/dist/i18n.cjs.map +1 -1
  49. package/dist/i18n.d.cts +24 -21
  50. package/dist/i18n.d.ts +24 -21
  51. package/dist/i18n.js +24 -31
  52. package/dist/i18n.js.map +1 -1
  53. package/dist/index.cjs +213 -57
  54. package/dist/index.d.cts +32 -31
  55. package/dist/index.d.ts +32 -31
  56. package/dist/index.js +33 -29
  57. package/dist/inert-CmBEbKCn.cjs +19 -0
  58. package/dist/inert-CmBEbKCn.cjs.map +1 -0
  59. package/dist/inert-D8fkennb.js +14 -0
  60. package/dist/inert-D8fkennb.js.map +1 -0
  61. package/dist/interaction.cjs +48 -102
  62. package/dist/interaction.cjs.map +1 -1
  63. package/dist/interaction.d.cts +23 -32
  64. package/dist/interaction.d.ts +23 -32
  65. package/dist/interaction.js +33 -102
  66. package/dist/interaction.js.map +1 -1
  67. package/dist/link.cjs +65 -104
  68. package/dist/link.cjs.map +1 -1
  69. package/dist/link.d.cts +21 -16
  70. package/dist/link.d.ts +22 -17
  71. package/dist/link.js +67 -107
  72. package/dist/link.js.map +1 -1
  73. package/dist/measurement.cjs +56 -0
  74. package/dist/measurement.cjs.map +1 -0
  75. package/dist/measurement.d.cts +38 -0
  76. package/dist/measurement.d.ts +38 -0
  77. package/dist/measurement.js +42 -0
  78. package/dist/measurement.js.map +1 -0
  79. package/dist/metadata.cjs +20 -7
  80. package/dist/metadata.cjs.map +1 -1
  81. package/dist/metadata.d.cts +22 -7
  82. package/dist/metadata.d.ts +22 -7
  83. package/dist/metadata.js +20 -10
  84. package/dist/metadata.js.map +1 -1
  85. package/dist/page-edit.cjs +7 -3
  86. package/dist/page-edit.cjs.map +1 -1
  87. package/dist/page-edit.d.cts +6 -2
  88. package/dist/page-edit.d.ts +6 -2
  89. package/dist/page-edit.js +7 -4
  90. package/dist/page-edit.js.map +1 -1
  91. package/dist/page-layers-Bkaaz8Zf.js +26 -0
  92. package/dist/page-layers-Bkaaz8Zf.js.map +1 -0
  93. package/dist/page-layers-BloZDoOV.cjs +37 -0
  94. package/dist/page-layers-BloZDoOV.cjs.map +1 -0
  95. package/dist/page-view.cjs +89 -82
  96. package/dist/page-view.cjs.map +1 -1
  97. package/dist/page-view.d.cts +14 -7
  98. package/dist/page-view.d.ts +18 -11
  99. package/dist/page-view.js +86 -81
  100. package/dist/page-view.js.map +1 -1
  101. package/dist/redaction.cjs +30 -15
  102. package/dist/redaction.cjs.map +1 -1
  103. package/dist/redaction.d.cts +27 -9
  104. package/dist/redaction.d.ts +27 -9
  105. package/dist/redaction.js +29 -18
  106. package/dist/redaction.js.map +1 -1
  107. package/dist/render.cjs +71 -46
  108. package/dist/render.cjs.map +1 -1
  109. package/dist/render.d.cts +17 -5
  110. package/dist/render.d.ts +17 -5
  111. package/dist/render.js +70 -49
  112. package/dist/render.js.map +1 -1
  113. package/dist/runtime-B6xcPsEb.js +398 -0
  114. package/dist/runtime-B6xcPsEb.js.map +1 -0
  115. package/dist/runtime-DBEBlpQV.d.cts +237 -0
  116. package/dist/runtime-V3MVMb91.d.ts +237 -0
  117. package/dist/runtime-fzpGv78v.cjs +555 -0
  118. package/dist/runtime-fzpGv78v.cjs.map +1 -0
  119. package/dist/runtime.cjs +45 -324
  120. package/dist/runtime.d.cts +2 -2
  121. package/dist/runtime.d.ts +2 -2
  122. package/dist/runtime.js +2 -306
  123. package/dist/search.cjs +81 -50
  124. package/dist/search.cjs.map +1 -1
  125. package/dist/search.d.cts +36 -24
  126. package/dist/search.d.ts +36 -24
  127. package/dist/search.js +81 -53
  128. package/dist/search.js.map +1 -1
  129. package/dist/selection.cjs +105 -108
  130. package/dist/selection.cjs.map +1 -1
  131. package/dist/selection.d.cts +54 -26
  132. package/dist/selection.d.ts +56 -28
  133. package/dist/selection.js +103 -110
  134. package/dist/selection.js.map +1 -1
  135. package/dist/shell.cjs +36 -21
  136. package/dist/shell.cjs.map +1 -1
  137. package/dist/shell.d.cts +32 -17
  138. package/dist/shell.d.ts +32 -17
  139. package/dist/shell.js +36 -24
  140. package/dist/shell.js.map +1 -1
  141. package/dist/signature.cjs +29 -48
  142. package/dist/signature.cjs.map +1 -1
  143. package/dist/signature.d.cts +26 -26
  144. package/dist/signature.d.ts +26 -26
  145. package/dist/signature.js +30 -48
  146. package/dist/signature.js.map +1 -1
  147. package/dist/stage-BIG6aeVd.cjs +369 -0
  148. package/dist/stage-BIG6aeVd.cjs.map +1 -0
  149. package/dist/stage-ByFPD-Fv.d.cts +117 -0
  150. package/dist/stage-DaboaheR.d.ts +117 -0
  151. package/dist/stage-DoVekb83.js +302 -0
  152. package/dist/stage-DoVekb83.js.map +1 -0
  153. package/dist/stage-scope-CQgCuf1w.cjs +46 -0
  154. package/dist/stage-scope-CQgCuf1w.cjs.map +1 -0
  155. package/dist/stage-scope-D7ZeNduT.js +23 -0
  156. package/dist/stage-scope-D7ZeNduT.js.map +1 -0
  157. package/dist/stage.cjs +12 -235
  158. package/dist/stage.d.cts +2 -116
  159. package/dist/stage.d.ts +2 -116
  160. package/dist/stage.js +3 -228
  161. package/dist/stamp.cjs +41 -35
  162. package/dist/stamp.cjs.map +1 -1
  163. package/dist/stamp.d.cts +25 -18
  164. package/dist/stamp.d.ts +25 -18
  165. package/dist/stamp.js +40 -37
  166. package/dist/stamp.js.map +1 -1
  167. package/dist/state-0K1I5cM4.d.cts +29 -0
  168. package/dist/state-0K1I5cM4.d.ts +29 -0
  169. package/dist/state-CbgxhwLA.js +62 -0
  170. package/dist/state-CbgxhwLA.js.map +1 -0
  171. package/dist/state-CsfZy_Eq.cjs +73 -0
  172. package/dist/state-CsfZy_Eq.cjs.map +1 -0
  173. package/dist/svg-shapes-Dm1yTR1b.js +40 -0
  174. package/dist/svg-shapes-Dm1yTR1b.js.map +1 -0
  175. package/dist/svg-shapes-zo0GNkc9.cjs +53 -0
  176. package/dist/svg-shapes-zo0GNkc9.cjs.map +1 -0
  177. package/dist/toolbar.cjs +297 -295
  178. package/dist/toolbar.cjs.map +1 -1
  179. package/dist/toolbar.d.cts +58 -68
  180. package/dist/toolbar.d.ts +67 -77
  181. package/dist/toolbar.js +271 -293
  182. package/dist/toolbar.js.map +1 -1
  183. package/dist/view-manager.cjs +34 -0
  184. package/dist/view-manager.cjs.map +1 -0
  185. package/dist/view-manager.d.cts +21 -0
  186. package/dist/view-manager.d.ts +21 -0
  187. package/dist/view-manager.js +23 -0
  188. package/dist/view-manager.js.map +1 -0
  189. package/package.json +41 -38
  190. package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.cts +0 -546
  191. package/dist/AnnotationListSnapshot-D3mFut1e-C_GMpK25.d.ts +0 -546
  192. package/dist/annotation-BCED_p9H.d.cts +0 -160
  193. package/dist/annotation-anchors-CetwM1g7.js +0 -15
  194. package/dist/annotation-anchors-CetwM1g7.js.map +0 -1
  195. package/dist/annotation-anchors-DuYRBJLl.cjs +0 -26
  196. package/dist/annotation-anchors-DuYRBJLl.cjs.map +0 -1
  197. package/dist/annotation-hooks-BB5ZhPpf.cjs +0 -16
  198. package/dist/annotation-hooks-BB5ZhPpf.cjs.map +0 -1
  199. package/dist/annotation-hooks-Df8EmzDO.js +0 -11
  200. package/dist/annotation-hooks-Df8EmzDO.js.map +0 -1
  201. package/dist/annotation-k38KDlIZ.d.ts +0 -160
  202. package/dist/annotation-menu.cjs +0 -64
  203. package/dist/annotation-menu.cjs.map +0 -1
  204. package/dist/annotation-menu.d.cts +0 -33
  205. package/dist/annotation-menu.d.ts +0 -33
  206. package/dist/annotation-menu.js +0 -48
  207. package/dist/annotation-menu.js.map +0 -1
  208. package/dist/annotation.cjs.map +0 -1
  209. package/dist/annotation.js.map +0 -1
  210. package/dist/form-BVumS7up.cjs +0 -926
  211. package/dist/form-BVumS7up.cjs.map +0 -1
  212. package/dist/form-CK3mp99m.js +0 -895
  213. package/dist/form-CK3mp99m.js.map +0 -1
  214. package/dist/rolldown-runtime-BBjsoOtd.js +0 -27
  215. package/dist/runtime-DE76hlnl.d.ts +0 -216
  216. package/dist/runtime-umHA_xHt.d.cts +0 -216
  217. package/dist/runtime.cjs.map +0 -1
  218. package/dist/runtime.js.map +0 -1
  219. package/dist/scrollbar.cjs +0 -241
  220. package/dist/scrollbar.cjs.map +0 -1
  221. package/dist/scrollbar.d.cts +0 -42
  222. package/dist/scrollbar.d.ts +0 -42
  223. package/dist/scrollbar.js +0 -213
  224. package/dist/scrollbar.js.map +0 -1
  225. package/dist/stage.cjs.map +0 -1
  226. package/dist/stage.js.map +0 -1
  227. package/dist/views.cjs +0 -35
  228. package/dist/views.cjs.map +0 -1
  229. package/dist/views.d.cts +0 -21
  230. package/dist/views.d.ts +0 -21
  231. package/dist/views.js +0 -27
  232. package/dist/views.js.map +0 -1
package/dist/form.d.cts CHANGED
@@ -1,35 +1,42 @@
1
- import { o as AnnotationRenderer } from "./annotation-BCED_p9H.cjs";
2
- import { t as FormSnapshot } from "./AnnotationListSnapshot-D3mFut1e-C_GMpK25.cjs";
3
- import { FormFieldDTO } from "@embedpdf/plugin-form";
1
+ import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.cjs";
2
+ import { i as FormKind, n as FormFieldDTO } from "./AnnotationList-CkijRHet-HEFNUIZe.cjs";
3
+ import { EventHook } from "@embedpdf/core";
4
+ import { FormCapability, FormFieldRef, FormFieldValue } from "@embedpdf/plugin-form";
4
5
  export * from "@embedpdf/plugin-form";
5
6
  //#region src/form.d.ts
6
7
  /**
7
- * The form plugin's renderer entry, ready for
8
- * `<AnnotationLayer renderers={[formWidgetRenderer]} />`. It answers for the
9
- * PLUGIN-registered 'form-widgets' Behavior — the form plugin decides when
10
- * widgets are fill controls vs. editable annotations, never the app.
8
+ * The form's fields on one page: their pictures, and the controls people fill
9
+ * them in with. Put it above the page's picture (`<RenderLayer>`, and
10
+ * `<AnnotationLayer>` when the annotation plugin is registered); while it's
11
+ * there, the render layer leaves the fields out of the page's picture. The
12
+ * controls show while the active tool fills forms (the `pointer` and `pan`
13
+ * tools do), and stand down in design mode, where fields are boxes you
14
+ * select and move.
11
15
  */
12
- declare const formWidgetRenderer: AnnotationRenderer;
16
+ declare function FormLayer(): import("react/jsx-runtime").JSX.Element;
17
+ /** The form API for the surrounding document: reading, filling, form data and building. */
18
+ declare function useForm(): FormCapability;
19
+ /** Subscribe to one form event while mounted: `useFormEvent((form) => form.onValueChanged, handler)`. */
20
+ declare function useFormEvent<T>(select: (form: FormCapability) => EventHook<T>, handler: (event: T) => void): void;
13
21
  /**
14
- * Fill-mode form controls for one page, positioned from the form model's own
15
- * widget geometry — the ANNOTATION-LESS path (a fill-only viewer whose page
16
- * pixels come from an annotated RenderLayer raster). Active whenever the
17
- * active tool carries the 'form-fill' tag (the built-in pointer/pan tools
18
- * do); any other tool stands the controls down. Do not mount next to an
19
- * AnnotationLayer wired with `formWidgetBehaviors`.
22
+ * The form's state: every field, whether it's read, what kind of form the
23
+ * document has, and the field of the selected widget (the page's State
24
+ * table, declared once in `formState`). Takes a selector, and re-renders only
25
+ * when what it returns changes.
20
26
  */
21
- declare function FormLayer(): import("react/jsx-runtime").JSX.Element | null;
22
- /** The form capability — values, interchange, design-mode verbs. */
23
- declare function useForm(): import("@embedpdf/plugin-form").FormCapability;
24
- /** The reconciled form snapshot (null until the first load lands),
25
- * re-rendering on every form model change. */
26
- declare function useFormSnapshot(): FormSnapshot | null;
27
+ declare const useFormState: StateHook<{
28
+ fields: readonly FormFieldDTO[];
29
+ status: import("@embedpdf/core").ResourceStatus;
30
+ formKind: FormKind;
31
+ selectedField: FormFieldDTO | null;
32
+ }>;
33
+ /** The form settings (`validation`, `focus`, `fields`), with or without a document. Takes a selector. */
34
+ declare const useFormSettings: SettingsHook<import("@embedpdf/plugin-form").FormSettings>;
27
35
  /**
28
- * The FIELD behind the currently selected widget annotation (single
29
- * selection), or null. The design-mode join: widget selection lives in the
30
- * annotation plane, field properties live here.
36
+ * One field's value, in the shape `setValue()` takes, or `null`: re-renders
37
+ * only when that field's value changes. Empty without a document.
31
38
  */
32
- declare function useFormField(): FormFieldDTO | null;
39
+ declare function useFormValue(ref: FormFieldRef): FormFieldValue | null;
33
40
  //#endregion
34
- export { FormLayer, formWidgetRenderer, useForm, useFormField, useFormSnapshot };
41
+ export { FormLayer, useForm, useFormEvent, useFormSettings, useFormState, useFormValue };
35
42
  //# sourceMappingURL=form.d.cts.map
package/dist/form.d.ts CHANGED
@@ -1,35 +1,42 @@
1
- import { o as AnnotationRenderer } from "./annotation-k38KDlIZ.js";
2
- import { t as FormSnapshot } from "./AnnotationListSnapshot-D3mFut1e-C_GMpK25.js";
3
- import { FormFieldDTO } from "@embedpdf/plugin-form";
1
+ import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.js";
2
+ import { i as FormKind, n as FormFieldDTO } from "./AnnotationList-CkijRHet-HEFNUIZe.js";
3
+ import { EventHook } from "@embedpdf/core";
4
+ import { FormCapability, FormFieldRef, FormFieldValue } from "@embedpdf/plugin-form";
4
5
  export * from "@embedpdf/plugin-form";
5
6
  //#region src/form.d.ts
6
7
  /**
7
- * The form plugin's renderer entry, ready for
8
- * `<AnnotationLayer renderers={[formWidgetRenderer]} />`. It answers for the
9
- * PLUGIN-registered 'form-widgets' Behavior — the form plugin decides when
10
- * widgets are fill controls vs. editable annotations, never the app.
8
+ * The form's fields on one page: their pictures, and the controls people fill
9
+ * them in with. Put it above the page's picture (`<RenderLayer>`, and
10
+ * `<AnnotationLayer>` when the annotation plugin is registered); while it's
11
+ * there, the render layer leaves the fields out of the page's picture. The
12
+ * controls show while the active tool fills forms (the `pointer` and `pan`
13
+ * tools do), and stand down in design mode, where fields are boxes you
14
+ * select and move.
11
15
  */
12
- declare const formWidgetRenderer: AnnotationRenderer;
16
+ declare function FormLayer(): import("react/jsx-runtime").JSX.Element;
17
+ /** The form API for the surrounding document: reading, filling, form data and building. */
18
+ declare function useForm(): FormCapability;
19
+ /** Subscribe to one form event while mounted: `useFormEvent((form) => form.onValueChanged, handler)`. */
20
+ declare function useFormEvent<T>(select: (form: FormCapability) => EventHook<T>, handler: (event: T) => void): void;
13
21
  /**
14
- * Fill-mode form controls for one page, positioned from the form model's own
15
- * widget geometry — the ANNOTATION-LESS path (a fill-only viewer whose page
16
- * pixels come from an annotated RenderLayer raster). Active whenever the
17
- * active tool carries the 'form-fill' tag (the built-in pointer/pan tools
18
- * do); any other tool stands the controls down. Do not mount next to an
19
- * AnnotationLayer wired with `formWidgetBehaviors`.
22
+ * The form's state: every field, whether it's read, what kind of form the
23
+ * document has, and the field of the selected widget (the page's State
24
+ * table, declared once in `formState`). Takes a selector, and re-renders only
25
+ * when what it returns changes.
20
26
  */
21
- declare function FormLayer(): import("react/jsx-runtime").JSX.Element | null;
22
- /** The form capability — values, interchange, design-mode verbs. */
23
- declare function useForm(): import("@embedpdf/plugin-form").FormCapability;
24
- /** The reconciled form snapshot (null until the first load lands),
25
- * re-rendering on every form model change. */
26
- declare function useFormSnapshot(): FormSnapshot | null;
27
+ declare const useFormState: StateHook<{
28
+ fields: readonly FormFieldDTO[];
29
+ status: import("@embedpdf/core").ResourceStatus;
30
+ formKind: FormKind;
31
+ selectedField: FormFieldDTO | null;
32
+ }>;
33
+ /** The form settings (`validation`, `focus`, `fields`), with or without a document. Takes a selector. */
34
+ declare const useFormSettings: SettingsHook<import("@embedpdf/plugin-form").FormSettings>;
27
35
  /**
28
- * The FIELD behind the currently selected widget annotation (single
29
- * selection), or null. The design-mode join: widget selection lives in the
30
- * annotation plane, field properties live here.
36
+ * One field's value, in the shape `setValue()` takes, or `null`: re-renders
37
+ * only when that field's value changes. Empty without a document.
31
38
  */
32
- declare function useFormField(): FormFieldDTO | null;
39
+ declare function useFormValue(ref: FormFieldRef): FormFieldValue | null;
33
40
  //#endregion
34
- export { FormLayer, formWidgetRenderer, useForm, useFormField, useFormSnapshot };
41
+ export { FormLayer, useForm, useFormEvent, useFormSettings, useFormState, useFormValue };
35
42
  //# sourceMappingURL=form.d.ts.map
package/dist/form.js CHANGED
@@ -1,4 +1,3 @@
1
- import "./runtime.js";
2
- import { a as useFormSnapshot, i as useFormField, n as formWidgetRenderer, r as useForm, t as FormLayer } from "./form-CK3mp99m.js";
1
+ import { a as useFormState, i as useFormSettings, n as useForm, o as useFormValue, r as useFormEvent, t as FormLayer } from "./form-55izw0jS.js";
3
2
  export * from "@embedpdf/plugin-form";
4
- export { FormLayer, formWidgetRenderer, useForm, useFormField, useFormSnapshot };
3
+ export { FormLayer, useForm, useFormEvent, useFormSettings, useFormState, useFormValue };
@@ -0,0 +1,38 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("./rolldown-runtime-DDXJien1.cjs");
3
+ const require_runtime = require("./runtime-fzpGv78v.cjs");
4
+ const require_state = require("./state-CsfZy_Eq.cjs");
5
+ let _embedpdf_plugin_history = require("@embedpdf/plugin-history");
6
+ //#region src/history.ts
7
+ /**
8
+ * The history (undo, redo, canUndo, canRedo, the labels, clear) of the
9
+ * surrounding `<DocumentScope>`'s document, else the active one. Outside a
10
+ * document, every method throws `not-ready`.
11
+ */
12
+ function useHistory() {
13
+ return require_runtime.useCapability(_embedpdf_plugin_history.HistoryToken);
14
+ }
15
+ /**
16
+ * Whether undo and redo can run, and what they would undo and redo (the
17
+ * page's State table, declared once in `historyState`). Takes a selector, and
18
+ * re-renders only when what it returns changes.
19
+ */
20
+ const useHistoryState = require_state.stateHook(_embedpdf_plugin_history.historyState);
21
+ /** Subscribe to one history event for the mounted lifetime: `useHistoryEvent((history) => history.onUndone, handler)`. */
22
+ function useHistoryEvent(select, handler) {
23
+ require_runtime.useCapabilityEvent(_embedpdf_plugin_history.HistoryToken, select, handler);
24
+ }
25
+ //#endregion
26
+ exports.useHistory = useHistory;
27
+ exports.useHistoryEvent = useHistoryEvent;
28
+ exports.useHistoryState = useHistoryState;
29
+ Object.keys(_embedpdf_plugin_history).forEach(function(k) {
30
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
31
+ enumerable: true,
32
+ get: function() {
33
+ return _embedpdf_plugin_history[k];
34
+ }
35
+ });
36
+ });
37
+
38
+ //# sourceMappingURL=history.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.cjs","names":["useCapability","HistoryToken","stateHook","historyState"],"sources":["../src/history.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-history: undo and redo of what you\n * change through the viewer, one history per open document. An action shows\n * undone at once, even while it is still on its way to the engine.\n *\n * const history = useHistory();\n * const { canUndo, undoLabel } = useHistoryState();\n * <button disabled={!canUndo} onClick={() => history.undo()}>Undo</button>\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-history';\nimport type { EventHook } from '@embedpdf/core';\nimport { HistoryToken, historyState, type HistoryCapability } from '@embedpdf/plugin-history';\n\nimport { useCapability, useCapabilityEvent } from './runtime';\nimport { stateHook } from './state';\n\n/**\n * The history (undo, redo, canUndo, canRedo, the labels, clear) of the\n * surrounding `<DocumentScope>`'s document, else the active one. Outside a\n * document, every method throws `not-ready`.\n */\nexport function useHistory(): HistoryCapability {\n return useCapability(HistoryToken);\n}\n\n/**\n * Whether undo and redo can run, and what they would undo and redo (the\n * page's State table, declared once in `historyState`). Takes a selector, and\n * re-renders only when what it returns changes.\n */\nexport const useHistoryState = stateHook(historyState);\n\n/** Subscribe to one history event for the mounted lifetime: `useHistoryEvent((history) => history.onUndone, handler)`. */\nexport function useHistoryEvent<T>(\n select: (history: HistoryCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(HistoryToken, select, handler);\n}\n"],"mappings":";;;;;;;;;;;AAuBA,SAAgB,aAAgC;CAC9C,OAAOA,gBAAAA,cAAcC,yBAAAA,YAAY;AACnC;;;;;;AAOA,MAAa,kBAAkBC,cAAAA,UAAUC,yBAAAA,YAAY;;AAGrD,SAAgB,gBACd,QACA,SACM;CACN,gBAAA,mBAAmBF,yBAAAA,cAAc,QAAQ,OAAO;AAClD"}
@@ -0,0 +1,27 @@
1
+ import { n as StateHook } from "./state-0K1I5cM4.cjs";
2
+ import { EventHook } from "@embedpdf/core";
3
+ import { HistoryCapability } from "@embedpdf/plugin-history";
4
+ export * from "@embedpdf/plugin-history";
5
+ //#region src/history.d.ts
6
+ /**
7
+ * The history (undo, redo, canUndo, canRedo, the labels, clear) of the
8
+ * surrounding `<DocumentScope>`'s document, else the active one. Outside a
9
+ * document, every method throws `not-ready`.
10
+ */
11
+ declare function useHistory(): HistoryCapability;
12
+ /**
13
+ * Whether undo and redo can run, and what they would undo and redo (the
14
+ * page's State table, declared once in `historyState`). Takes a selector, and
15
+ * re-renders only when what it returns changes.
16
+ */
17
+ declare const useHistoryState: StateHook<{
18
+ canUndo: boolean;
19
+ canRedo: boolean;
20
+ undoLabel: import("@embedpdf/core").ChangeLabel | null;
21
+ redoLabel: import("@embedpdf/core").ChangeLabel | null;
22
+ }>;
23
+ /** Subscribe to one history event for the mounted lifetime: `useHistoryEvent((history) => history.onUndone, handler)`. */
24
+ declare function useHistoryEvent<T>(select: (history: HistoryCapability) => EventHook<T>, handler: (event: T) => void): void;
25
+ //#endregion
26
+ export { useHistory, useHistoryEvent, useHistoryState };
27
+ //# sourceMappingURL=history.d.cts.map
@@ -0,0 +1,27 @@
1
+ import { n as StateHook } from "./state-0K1I5cM4.js";
2
+ import { EventHook } from "@embedpdf/core";
3
+ import { HistoryCapability } from "@embedpdf/plugin-history";
4
+ export * from "@embedpdf/plugin-history";
5
+ //#region src/history.d.ts
6
+ /**
7
+ * The history (undo, redo, canUndo, canRedo, the labels, clear) of the
8
+ * surrounding `<DocumentScope>`'s document, else the active one. Outside a
9
+ * document, every method throws `not-ready`.
10
+ */
11
+ declare function useHistory(): HistoryCapability;
12
+ /**
13
+ * Whether undo and redo can run, and what they would undo and redo (the
14
+ * page's State table, declared once in `historyState`). Takes a selector, and
15
+ * re-renders only when what it returns changes.
16
+ */
17
+ declare const useHistoryState: StateHook<{
18
+ canUndo: boolean;
19
+ canRedo: boolean;
20
+ undoLabel: import("@embedpdf/core").ChangeLabel | null;
21
+ redoLabel: import("@embedpdf/core").ChangeLabel | null;
22
+ }>;
23
+ /** Subscribe to one history event for the mounted lifetime: `useHistoryEvent((history) => history.onUndone, handler)`. */
24
+ declare function useHistoryEvent<T>(select: (history: HistoryCapability) => EventHook<T>, handler: (event: T) => void): void;
25
+ //#endregion
26
+ export { useHistory, useHistoryEvent, useHistoryState };
27
+ //# sourceMappingURL=history.d.ts.map
@@ -0,0 +1,27 @@
1
+ import { f as useCapability, p as useCapabilityEvent } from "./runtime-B6xcPsEb.js";
2
+ import { n as stateHook } from "./state-CbgxhwLA.js";
3
+ import { HistoryToken, historyState } from "@embedpdf/plugin-history";
4
+ export * from "@embedpdf/plugin-history";
5
+ //#region src/history.ts
6
+ /**
7
+ * The history (undo, redo, canUndo, canRedo, the labels, clear) of the
8
+ * surrounding `<DocumentScope>`'s document, else the active one. Outside a
9
+ * document, every method throws `not-ready`.
10
+ */
11
+ function useHistory() {
12
+ return useCapability(HistoryToken);
13
+ }
14
+ /**
15
+ * Whether undo and redo can run, and what they would undo and redo (the
16
+ * page's State table, declared once in `historyState`). Takes a selector, and
17
+ * re-renders only when what it returns changes.
18
+ */
19
+ const useHistoryState = stateHook(historyState);
20
+ /** Subscribe to one history event for the mounted lifetime: `useHistoryEvent((history) => history.onUndone, handler)`. */
21
+ function useHistoryEvent(select, handler) {
22
+ useCapabilityEvent(HistoryToken, select, handler);
23
+ }
24
+ //#endregion
25
+ export { useHistory, useHistoryEvent, useHistoryState };
26
+
27
+ //# sourceMappingURL=history.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"history.js","names":[],"sources":["../src/history.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-history: undo and redo of what you\n * change through the viewer, one history per open document. An action shows\n * undone at once, even while it is still on its way to the engine.\n *\n * const history = useHistory();\n * const { canUndo, undoLabel } = useHistoryState();\n * <button disabled={!canUndo} onClick={() => history.undo()}>Undo</button>\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-history';\nimport type { EventHook } from '@embedpdf/core';\nimport { HistoryToken, historyState, type HistoryCapability } from '@embedpdf/plugin-history';\n\nimport { useCapability, useCapabilityEvent } from './runtime';\nimport { stateHook } from './state';\n\n/**\n * The history (undo, redo, canUndo, canRedo, the labels, clear) of the\n * surrounding `<DocumentScope>`'s document, else the active one. Outside a\n * document, every method throws `not-ready`.\n */\nexport function useHistory(): HistoryCapability {\n return useCapability(HistoryToken);\n}\n\n/**\n * Whether undo and redo can run, and what they would undo and redo (the\n * page's State table, declared once in `historyState`). Takes a selector, and\n * re-renders only when what it returns changes.\n */\nexport const useHistoryState = stateHook(historyState);\n\n/** Subscribe to one history event for the mounted lifetime: `useHistoryEvent((history) => history.onUndone, handler)`. */\nexport function useHistoryEvent<T>(\n select: (history: HistoryCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(HistoryToken, select, handler);\n}\n"],"mappings":";;;;;;;;;;AAuBA,SAAgB,aAAgC;CAC9C,OAAO,cAAc,YAAY;AACnC;;;;;;AAOA,MAAa,kBAAkB,UAAU,YAAY;;AAGrD,SAAgB,gBACd,QACA,SACM;CACN,mBAAmB,cAAc,QAAQ,OAAO;AAClD"}
package/dist/i18n.cjs CHANGED
@@ -1,44 +1,40 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_runtime = require("./runtime.cjs");
3
- let react = require("react");
2
+ require("./rolldown-runtime-DDXJien1.cjs");
3
+ const require_runtime = require("./runtime-fzpGv78v.cjs");
4
+ const require_state = require("./state-CsfZy_Eq.cjs");
4
5
  let _embedpdf_plugin_i18n = require("@embedpdf/plugin-i18n");
5
6
  //#region src/i18n.ts
6
- /** The raw i18n capability (t / setLocale / locales / dir / …). */
7
- const useI18n = () => require_runtime.useCapability(_embedpdf_plugin_i18n.I18nToken);
7
+ /** The i18n capability: `t`, `setLocale`, `addTranslations`, `registerLocale`, the settings calls. */
8
+ function useI18n() {
9
+ return require_runtime.useCapability(_embedpdf_plugin_i18n.I18nToken);
10
+ }
11
+ /** Subscribe to one i18n event for the mounted lifetime: `useI18nEvent((i18n) => i18n.onLocaleChanged, handler)`. */
12
+ function useI18nEvent(select, handler) {
13
+ require_runtime.useCapabilityEvent(_embedpdf_plugin_i18n.I18nToken, select, handler);
14
+ }
8
15
  /**
9
- * A reactive translate function. New identity whenever i18n state changes
10
- * (locale switch, pack registered), so memoized children re-render too.
11
- *
12
- * const t = useT();
13
- * <button title={t('commands.zoom.in')}>+</button>
14
- * <span>{t('pages', { params: { count } })}</span>
16
+ * The current language, how it reads, every language you can switch to, and the one loading (the
17
+ * translations page's State table, declared once in `i18nState`). Takes a selector, and
18
+ * re-renders only when what it returns changes.
15
19
  */
16
- function useT() {
17
- const i18n = require_runtime.useCapability(_embedpdf_plugin_i18n.I18nToken);
18
- return (0, react.useMemo)(() => (key, options) => i18n.t(key, options), [i18n, require_runtime.useKernelValue((k) => k.getState().plugins["i18n"])]);
19
- }
20
- const localeListEqual = (a, b) => a.length === b.length && a.every((x, i) => x.code === b[i].code && x.name === b[i].name && x.loaded === b[i].loaded);
20
+ const useI18nState = require_state.stateHook(_embedpdf_plugin_i18n.i18nState);
21
+ /** The i18n settings (`locale`, `fallbackLocale`, `locales`, `loaders`). Takes a selector. */
22
+ const useI18nSettings = require_state.settingsHook(_embedpdf_plugin_i18n.I18nToken);
21
23
  /**
22
- * Everything a locale switcher needs, reactive.
24
+ * A translate function that re-renders the component when the language or the strings change,
25
+ * and keeps its identity otherwise, so memoized children holding it re-render too.
23
26
  *
24
- * const { locale, locales, loading, setLocale } = useLocale();
27
+ * const t = useT();
28
+ * <span>{t('search.results', { params: { count } })}</span>
25
29
  */
26
- function useLocale() {
27
- const i18n = require_runtime.useCapability(_embedpdf_plugin_i18n.I18nToken);
28
- const locale = require_runtime.useSelector(_embedpdf_plugin_i18n.I18nToken, (c) => c.locale());
29
- const dir = require_runtime.useSelector(_embedpdf_plugin_i18n.I18nToken, (c) => c.dir());
30
- const loading = require_runtime.useSelector(_embedpdf_plugin_i18n.I18nToken, (c) => c.loading());
31
- return {
32
- locale,
33
- dir,
34
- locales: require_runtime.useSelector(_embedpdf_plugin_i18n.I18nToken, (c) => c.locales(), localeListEqual),
35
- loading,
36
- setLocale: i18n.setLocale
37
- };
30
+ function useT() {
31
+ return require_runtime.useSelector(_embedpdf_plugin_i18n.I18nToken, (i18n) => i18n.getTranslator());
38
32
  }
39
33
  //#endregion
40
34
  exports.useI18n = useI18n;
41
- exports.useLocale = useLocale;
35
+ exports.useI18nEvent = useI18nEvent;
36
+ exports.useI18nSettings = useI18nSettings;
37
+ exports.useI18nState = useI18nState;
42
38
  exports.useT = useT;
43
39
  Object.keys(_embedpdf_plugin_i18n).forEach(function(k) {
44
40
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
package/dist/i18n.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.cjs","names":["useCapability","I18nToken","useKernelValue","useSelector"],"sources":["../src/i18n.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-i18n — sugar over the generic\n * binding, nothing more. The plugin keeps locale packs in the store, so\n * reactivity is the kernel's one change stream; there are no emitters to\n * subscribe and no per-plugin plumbing.\n *\n * Because the capability is workspace-scoped and engine-free, these hooks\n * work from the FIRST frame — including inside `<Viewer fallback>` — while\n * the engine is still booting.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-i18n';\nimport { useMemo } from 'react';\nimport { I18nToken } from '@embedpdf/plugin-i18n';\nimport type { LocaleInfo, TranslateOptions } from '@embedpdf/plugin-i18n';\nimport { useCapability, useKernelValue, useSelector } from './runtime';\n\n/** The raw i18n capability (t / setLocale / locales / dir / …). */\nexport const useI18n = () => useCapability(I18nToken);\n\n/**\n * A reactive translate function. New identity whenever i18n state changes\n * (locale switch, pack registered), so memoized children re-render too.\n *\n * const t = useT();\n * <button title={t('commands.zoom.in')}>+</button>\n * <span>{t('pages', { params: { count } })}</span>\n */\nexport function useT(): (key: string, options?: TranslateOptions) => string {\n const i18n = useCapability(I18nToken);\n const slice = useKernelValue((k) => k.getState().plugins['i18n']);\n return useMemo(() => (key, options) => i18n.t(key, options), [i18n, slice]);\n}\n\nconst localeListEqual = (a: LocaleInfo[], b: LocaleInfo[]): boolean =>\n a.length === b.length &&\n a.every((x, i) => x.code === b[i].code && x.name === b[i].name && x.loaded === b[i].loaded);\n\n/**\n * Everything a locale switcher needs, reactive.\n *\n * const { locale, locales, loading, setLocale } = useLocale();\n */\nexport function useLocale(): {\n locale: string;\n dir: 'ltr' | 'rtl';\n locales: LocaleInfo[];\n /** Code of a lazy pack being fetched, if any — show a spinner on it. */\n loading: string | null;\n setLocale: (code: string) => void;\n} {\n const i18n = useCapability(I18nToken);\n const locale = useSelector(I18nToken, (c) => c.locale());\n const dir = useSelector(I18nToken, (c) => c.dir());\n const loading = useSelector(I18nToken, (c) => c.loading());\n const locales = useSelector(I18nToken, (c) => c.locales(), localeListEqual);\n return { locale, dir, locales, loading, setLocale: i18n.setLocale };\n}\n"],"mappings":";;;;;;AAmBA,MAAa,gBAAgBA,gBAAAA,cAAcC,sBAAAA,SAAS;;;;;;;;;AAUpD,SAAgB,OAA4D;CAC1E,MAAM,OAAOD,gBAAAA,cAAcC,sBAAAA,SAAS;CAEpC,QAAA,GAAA,MAAA,QAAA,QAAsB,KAAK,YAAY,KAAK,EAAE,KAAK,OAAO,GAAG,CAAC,MADhDC,gBAAAA,gBAAgB,MAAM,EAAE,SAAS,CAAC,CAAC,QAAQ,OACe,CAAC,CAAC;AAC5E;AAEA,MAAM,mBAAmB,GAAiB,MACxC,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,MAAM;;;;;;AAO5F,SAAgB,YAOd;CACA,MAAM,OAAOF,gBAAAA,cAAcC,sBAAAA,SAAS;CACpC,MAAM,SAASE,gBAAAA,YAAYF,sBAAAA,YAAY,MAAM,EAAE,OAAO,CAAC;CACvD,MAAM,MAAME,gBAAAA,YAAYF,sBAAAA,YAAY,MAAM,EAAE,IAAI,CAAC;CACjD,MAAM,UAAUE,gBAAAA,YAAYF,sBAAAA,YAAY,MAAM,EAAE,QAAQ,CAAC;CAEzD,OAAO;EAAE;EAAQ;EAAK,SADNE,gBAAAA,YAAYF,sBAAAA,YAAY,MAAM,EAAE,QAAQ,GAAG,eAC/B;EAAG;EAAS,WAAW,KAAK;CAAU;AACpE"}
1
+ {"version":3,"file":"i18n.cjs","names":["useCapability","I18nToken","stateHook","i18nState","settingsHook","useSelector"],"sources":["../src/i18n.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-i18n. The plugin is workspace-scoped\n * and needs no engine, so these hooks work from the first frame, before a\n * document opens: a loading screen and a password prompt translate too.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-i18n';\nimport { I18nToken, i18nState } from '@embedpdf/plugin-i18n';\nimport type { I18nCapability, TranslateOptions } from '@embedpdf/plugin-i18n';\nimport type { EventHook } from '@embedpdf/core';\nimport { useCapability, useCapabilityEvent, useSelector } from './runtime';\nimport { settingsHook, stateHook } from './state';\n\n/** The i18n capability: `t`, `setLocale`, `addTranslations`, `registerLocale`, the settings calls. */\nexport function useI18n(): I18nCapability {\n return useCapability(I18nToken);\n}\n\n/** Subscribe to one i18n event for the mounted lifetime: `useI18nEvent((i18n) => i18n.onLocaleChanged, handler)`. */\nexport function useI18nEvent<T>(\n select: (i18n: I18nCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(I18nToken, select, handler);\n}\n\n/**\n * The current language, how it reads, every language you can switch to, and the one loading (the\n * translations page's State table, declared once in `i18nState`). Takes a selector, and\n * re-renders only when what it returns changes.\n */\nexport const useI18nState = stateHook(i18nState);\n\n/** The i18n settings (`locale`, `fallbackLocale`, `locales`, `loaders`). Takes a selector. */\nexport const useI18nSettings = settingsHook(I18nToken);\n\n/**\n * A translate function that re-renders the component when the language or the strings change,\n * and keeps its identity otherwise, so memoized children holding it re-render too.\n *\n * const t = useT();\n * <span>{t('search.results', { params: { count } })}</span>\n */\nexport function useT(): (key: string, options?: TranslateOptions) => string {\n return useSelector(I18nToken, (i18n) => i18n.getTranslator());\n}\n"],"mappings":";;;;;;;AAeA,SAAgB,UAA0B;CACxC,OAAOA,gBAAAA,cAAcC,sBAAAA,SAAS;AAChC;;AAGA,SAAgB,aACd,QACA,SACM;CACN,gBAAA,mBAAmBA,sBAAAA,WAAW,QAAQ,OAAO;AAC/C;;;;;;AAOA,MAAa,eAAeC,cAAAA,UAAUC,sBAAAA,SAAS;;AAG/C,MAAa,kBAAkBC,cAAAA,aAAaH,sBAAAA,SAAS;;;;;;;;AASrD,SAAgB,OAA4D;CAC1E,OAAOI,gBAAAA,YAAYJ,sBAAAA,YAAY,SAAS,KAAK,cAAc,CAAC;AAC9D"}
package/dist/i18n.d.cts CHANGED
@@ -1,30 +1,33 @@
1
- import { LocaleInfo, TranslateOptions } from "@embedpdf/plugin-i18n";
1
+ import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.cjs";
2
+ import { EventHook } from "@embedpdf/core";
3
+ import { I18nCapability, TranslateOptions } from "@embedpdf/plugin-i18n";
2
4
  export * from "@embedpdf/plugin-i18n";
3
5
  //#region src/i18n.d.ts
4
- /** The raw i18n capability (t / setLocale / locales / dir / …). */
5
- declare const useI18n: () => import("@embedpdf/plugin-i18n").I18nCapability;
6
+ /** The i18n capability: `t`, `setLocale`, `addTranslations`, `registerLocale`, the settings calls. */
7
+ declare function useI18n(): I18nCapability;
8
+ /** Subscribe to one i18n event for the mounted lifetime: `useI18nEvent((i18n) => i18n.onLocaleChanged, handler)`. */
9
+ declare function useI18nEvent<T>(select: (i18n: I18nCapability) => EventHook<T>, handler: (event: T) => void): void;
6
10
  /**
7
- * A reactive translate function. New identity whenever i18n state changes
8
- * (locale switch, pack registered), so memoized children re-render too.
9
- *
10
- * const t = useT();
11
- * <button title={t('commands.zoom.in')}>+</button>
12
- * <span>{t('pages', { params: { count } })}</span>
11
+ * The current language, how it reads, every language you can switch to, and the one loading (the
12
+ * translations page's State table, declared once in `i18nState`). Takes a selector, and
13
+ * re-renders only when what it returns changes.
13
14
  */
14
- declare function useT(): (key: string, options?: TranslateOptions) => string;
15
+ declare const useI18nState: StateHook<{
16
+ locale: string;
17
+ direction: import("@embedpdf/plugin-i18n").TextDirection;
18
+ locales: readonly import("@embedpdf/plugin-i18n").LocaleInfo[];
19
+ loading: string | null;
20
+ }>;
21
+ /** The i18n settings (`locale`, `fallbackLocale`, `locales`, `loaders`). Takes a selector. */
22
+ declare const useI18nSettings: SettingsHook<import("@embedpdf/plugin-i18n").I18nSettings>;
15
23
  /**
16
- * Everything a locale switcher needs, reactive.
24
+ * A translate function that re-renders the component when the language or the strings change,
25
+ * and keeps its identity otherwise, so memoized children holding it re-render too.
17
26
  *
18
- * const { locale, locales, loading, setLocale } = useLocale();
27
+ * const t = useT();
28
+ * <span>{t('search.results', { params: { count } })}</span>
19
29
  */
20
- declare function useLocale(): {
21
- locale: string;
22
- dir: 'ltr' | 'rtl';
23
- locales: LocaleInfo[];
24
- /** Code of a lazy pack being fetched, if any — show a spinner on it. */
25
- loading: string | null;
26
- setLocale: (code: string) => void;
27
- };
30
+ declare function useT(): (key: string, options?: TranslateOptions) => string;
28
31
  //#endregion
29
- export { useI18n, useLocale, useT };
32
+ export { useI18n, useI18nEvent, useI18nSettings, useI18nState, useT };
30
33
  //# sourceMappingURL=i18n.d.cts.map
package/dist/i18n.d.ts CHANGED
@@ -1,30 +1,33 @@
1
- import { LocaleInfo, TranslateOptions } from "@embedpdf/plugin-i18n";
1
+ import { n as StateHook, t as SettingsHook } from "./state-0K1I5cM4.js";
2
+ import { EventHook } from "@embedpdf/core";
3
+ import { I18nCapability, TranslateOptions } from "@embedpdf/plugin-i18n";
2
4
  export * from "@embedpdf/plugin-i18n";
3
5
  //#region src/i18n.d.ts
4
- /** The raw i18n capability (t / setLocale / locales / dir / …). */
5
- declare const useI18n: () => import("@embedpdf/plugin-i18n").I18nCapability;
6
+ /** The i18n capability: `t`, `setLocale`, `addTranslations`, `registerLocale`, the settings calls. */
7
+ declare function useI18n(): I18nCapability;
8
+ /** Subscribe to one i18n event for the mounted lifetime: `useI18nEvent((i18n) => i18n.onLocaleChanged, handler)`. */
9
+ declare function useI18nEvent<T>(select: (i18n: I18nCapability) => EventHook<T>, handler: (event: T) => void): void;
6
10
  /**
7
- * A reactive translate function. New identity whenever i18n state changes
8
- * (locale switch, pack registered), so memoized children re-render too.
9
- *
10
- * const t = useT();
11
- * <button title={t('commands.zoom.in')}>+</button>
12
- * <span>{t('pages', { params: { count } })}</span>
11
+ * The current language, how it reads, every language you can switch to, and the one loading (the
12
+ * translations page's State table, declared once in `i18nState`). Takes a selector, and
13
+ * re-renders only when what it returns changes.
13
14
  */
14
- declare function useT(): (key: string, options?: TranslateOptions) => string;
15
+ declare const useI18nState: StateHook<{
16
+ locale: string;
17
+ direction: import("@embedpdf/plugin-i18n").TextDirection;
18
+ locales: readonly import("@embedpdf/plugin-i18n").LocaleInfo[];
19
+ loading: string | null;
20
+ }>;
21
+ /** The i18n settings (`locale`, `fallbackLocale`, `locales`, `loaders`). Takes a selector. */
22
+ declare const useI18nSettings: SettingsHook<import("@embedpdf/plugin-i18n").I18nSettings>;
15
23
  /**
16
- * Everything a locale switcher needs, reactive.
24
+ * A translate function that re-renders the component when the language or the strings change,
25
+ * and keeps its identity otherwise, so memoized children holding it re-render too.
17
26
  *
18
- * const { locale, locales, loading, setLocale } = useLocale();
27
+ * const t = useT();
28
+ * <span>{t('search.results', { params: { count } })}</span>
19
29
  */
20
- declare function useLocale(): {
21
- locale: string;
22
- dir: 'ltr' | 'rtl';
23
- locales: LocaleInfo[];
24
- /** Code of a lazy pack being fetched, if any — show a spinner on it. */
25
- loading: string | null;
26
- setLocale: (code: string) => void;
27
- };
30
+ declare function useT(): (key: string, options?: TranslateOptions) => string;
28
31
  //#endregion
29
- export { useI18n, useLocale, useT };
32
+ export { useI18n, useI18nEvent, useI18nSettings, useI18nState, useT };
30
33
  //# sourceMappingURL=i18n.d.ts.map
package/dist/i18n.js CHANGED
@@ -1,42 +1,35 @@
1
- import { useCapability, useKernelValue, useSelector } from "./runtime.js";
2
- import { useMemo } from "react";
3
- import { I18nToken } from "@embedpdf/plugin-i18n";
1
+ import { E as useSelector, f as useCapability, p as useCapabilityEvent } from "./runtime-B6xcPsEb.js";
2
+ import { n as stateHook, t as settingsHook } from "./state-CbgxhwLA.js";
3
+ import { I18nToken, i18nState } from "@embedpdf/plugin-i18n";
4
4
  export * from "@embedpdf/plugin-i18n";
5
5
  //#region src/i18n.ts
6
- /** The raw i18n capability (t / setLocale / locales / dir / …). */
7
- const useI18n = () => useCapability(I18nToken);
6
+ /** The i18n capability: `t`, `setLocale`, `addTranslations`, `registerLocale`, the settings calls. */
7
+ function useI18n() {
8
+ return useCapability(I18nToken);
9
+ }
10
+ /** Subscribe to one i18n event for the mounted lifetime: `useI18nEvent((i18n) => i18n.onLocaleChanged, handler)`. */
11
+ function useI18nEvent(select, handler) {
12
+ useCapabilityEvent(I18nToken, select, handler);
13
+ }
8
14
  /**
9
- * A reactive translate function. New identity whenever i18n state changes
10
- * (locale switch, pack registered), so memoized children re-render too.
11
- *
12
- * const t = useT();
13
- * <button title={t('commands.zoom.in')}>+</button>
14
- * <span>{t('pages', { params: { count } })}</span>
15
+ * The current language, how it reads, every language you can switch to, and the one loading (the
16
+ * translations page's State table, declared once in `i18nState`). Takes a selector, and
17
+ * re-renders only when what it returns changes.
15
18
  */
16
- function useT() {
17
- const i18n = useCapability(I18nToken);
18
- return useMemo(() => (key, options) => i18n.t(key, options), [i18n, useKernelValue((k) => k.getState().plugins["i18n"])]);
19
- }
20
- const localeListEqual = (a, b) => a.length === b.length && a.every((x, i) => x.code === b[i].code && x.name === b[i].name && x.loaded === b[i].loaded);
19
+ const useI18nState = stateHook(i18nState);
20
+ /** The i18n settings (`locale`, `fallbackLocale`, `locales`, `loaders`). Takes a selector. */
21
+ const useI18nSettings = settingsHook(I18nToken);
21
22
  /**
22
- * Everything a locale switcher needs, reactive.
23
+ * A translate function that re-renders the component when the language or the strings change,
24
+ * and keeps its identity otherwise, so memoized children holding it re-render too.
23
25
  *
24
- * const { locale, locales, loading, setLocale } = useLocale();
26
+ * const t = useT();
27
+ * <span>{t('search.results', { params: { count } })}</span>
25
28
  */
26
- function useLocale() {
27
- const i18n = useCapability(I18nToken);
28
- const locale = useSelector(I18nToken, (c) => c.locale());
29
- const dir = useSelector(I18nToken, (c) => c.dir());
30
- const loading = useSelector(I18nToken, (c) => c.loading());
31
- return {
32
- locale,
33
- dir,
34
- locales: useSelector(I18nToken, (c) => c.locales(), localeListEqual),
35
- loading,
36
- setLocale: i18n.setLocale
37
- };
29
+ function useT() {
30
+ return useSelector(I18nToken, (i18n) => i18n.getTranslator());
38
31
  }
39
32
  //#endregion
40
- export { useI18n, useLocale, useT };
33
+ export { useI18n, useI18nEvent, useI18nSettings, useI18nState, useT };
41
34
 
42
35
  //# sourceMappingURL=i18n.js.map
package/dist/i18n.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"i18n.js","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-i18n — sugar over the generic\n * binding, nothing more. The plugin keeps locale packs in the store, so\n * reactivity is the kernel's one change stream; there are no emitters to\n * subscribe and no per-plugin plumbing.\n *\n * Because the capability is workspace-scoped and engine-free, these hooks\n * work from the FIRST frame — including inside `<Viewer fallback>` — while\n * the engine is still booting.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-i18n';\nimport { useMemo } from 'react';\nimport { I18nToken } from '@embedpdf/plugin-i18n';\nimport type { LocaleInfo, TranslateOptions } from '@embedpdf/plugin-i18n';\nimport { useCapability, useKernelValue, useSelector } from './runtime';\n\n/** The raw i18n capability (t / setLocale / locales / dir / …). */\nexport const useI18n = () => useCapability(I18nToken);\n\n/**\n * A reactive translate function. New identity whenever i18n state changes\n * (locale switch, pack registered), so memoized children re-render too.\n *\n * const t = useT();\n * <button title={t('commands.zoom.in')}>+</button>\n * <span>{t('pages', { params: { count } })}</span>\n */\nexport function useT(): (key: string, options?: TranslateOptions) => string {\n const i18n = useCapability(I18nToken);\n const slice = useKernelValue((k) => k.getState().plugins['i18n']);\n return useMemo(() => (key, options) => i18n.t(key, options), [i18n, slice]);\n}\n\nconst localeListEqual = (a: LocaleInfo[], b: LocaleInfo[]): boolean =>\n a.length === b.length &&\n a.every((x, i) => x.code === b[i].code && x.name === b[i].name && x.loaded === b[i].loaded);\n\n/**\n * Everything a locale switcher needs, reactive.\n *\n * const { locale, locales, loading, setLocale } = useLocale();\n */\nexport function useLocale(): {\n locale: string;\n dir: 'ltr' | 'rtl';\n locales: LocaleInfo[];\n /** Code of a lazy pack being fetched, if any — show a spinner on it. */\n loading: string | null;\n setLocale: (code: string) => void;\n} {\n const i18n = useCapability(I18nToken);\n const locale = useSelector(I18nToken, (c) => c.locale());\n const dir = useSelector(I18nToken, (c) => c.dir());\n const loading = useSelector(I18nToken, (c) => c.loading());\n const locales = useSelector(I18nToken, (c) => c.locales(), localeListEqual);\n return { locale, dir, locales, loading, setLocale: i18n.setLocale };\n}\n"],"mappings":";;;;;;AAmBA,MAAa,gBAAgB,cAAc,SAAS;;;;;;;;;AAUpD,SAAgB,OAA4D;CAC1E,MAAM,OAAO,cAAc,SAAS;CAEpC,OAAO,eAAe,KAAK,YAAY,KAAK,EAAE,KAAK,OAAO,GAAG,CAAC,MADhD,gBAAgB,MAAM,EAAE,SAAS,CAAC,CAAC,QAAQ,OACe,CAAC,CAAC;AAC5E;AAEA,MAAM,mBAAmB,GAAiB,MACxC,EAAE,WAAW,EAAE,UACf,EAAE,OAAO,GAAG,MAAM,EAAE,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC,QAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,MAAM;;;;;;AAO5F,SAAgB,YAOd;CACA,MAAM,OAAO,cAAc,SAAS;CACpC,MAAM,SAAS,YAAY,YAAY,MAAM,EAAE,OAAO,CAAC;CACvD,MAAM,MAAM,YAAY,YAAY,MAAM,EAAE,IAAI,CAAC;CACjD,MAAM,UAAU,YAAY,YAAY,MAAM,EAAE,QAAQ,CAAC;CAEzD,OAAO;EAAE;EAAQ;EAAK,SADN,YAAY,YAAY,MAAM,EAAE,QAAQ,GAAG,eAC/B;EAAG;EAAS,WAAW,KAAK;CAAU;AACpE"}
1
+ {"version":3,"file":"i18n.js","names":[],"sources":["../src/i18n.ts"],"sourcesContent":["/**\n * The React surface for @embedpdf/plugin-i18n. The plugin is workspace-scoped\n * and needs no engine, so these hooks work from the first frame, before a\n * document opens: a loading screen and a password prompt translate too.\n */\n\n// One-line-per-feature: registration travels with the UI.\nexport * from '@embedpdf/plugin-i18n';\nimport { I18nToken, i18nState } from '@embedpdf/plugin-i18n';\nimport type { I18nCapability, TranslateOptions } from '@embedpdf/plugin-i18n';\nimport type { EventHook } from '@embedpdf/core';\nimport { useCapability, useCapabilityEvent, useSelector } from './runtime';\nimport { settingsHook, stateHook } from './state';\n\n/** The i18n capability: `t`, `setLocale`, `addTranslations`, `registerLocale`, the settings calls. */\nexport function useI18n(): I18nCapability {\n return useCapability(I18nToken);\n}\n\n/** Subscribe to one i18n event for the mounted lifetime: `useI18nEvent((i18n) => i18n.onLocaleChanged, handler)`. */\nexport function useI18nEvent<T>(\n select: (i18n: I18nCapability) => EventHook<T>,\n handler: (event: T) => void,\n): void {\n useCapabilityEvent(I18nToken, select, handler);\n}\n\n/**\n * The current language, how it reads, every language you can switch to, and the one loading (the\n * translations page's State table, declared once in `i18nState`). Takes a selector, and\n * re-renders only when what it returns changes.\n */\nexport const useI18nState = stateHook(i18nState);\n\n/** The i18n settings (`locale`, `fallbackLocale`, `locales`, `loaders`). Takes a selector. */\nexport const useI18nSettings = settingsHook(I18nToken);\n\n/**\n * A translate function that re-renders the component when the language or the strings change,\n * and keeps its identity otherwise, so memoized children holding it re-render too.\n *\n * const t = useT();\n * <span>{t('search.results', { params: { count } })}</span>\n */\nexport function useT(): (key: string, options?: TranslateOptions) => string {\n return useSelector(I18nToken, (i18n) => i18n.getTranslator());\n}\n"],"mappings":";;;;;;AAeA,SAAgB,UAA0B;CACxC,OAAO,cAAc,SAAS;AAChC;;AAGA,SAAgB,aACd,QACA,SACM;CACN,mBAAmB,WAAW,QAAQ,OAAO;AAC/C;;;;;;AAOA,MAAa,eAAe,UAAU,SAAS;;AAG/C,MAAa,kBAAkB,aAAa,SAAS;;;;;;;;AASrD,SAAgB,OAA4D;CAC1E,OAAO,YAAY,YAAY,SAAS,KAAK,cAAc,CAAC;AAC9D"}