pdf-tsx 0.11.0 → 0.12.0

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 (73) hide show
  1. package/README.md +43 -2
  2. package/dist/cjs/components/PDFViewer.cjs +1 -1
  3. package/dist/cjs/components/PDFViewer.module.cjs +1 -1
  4. package/dist/cjs/components/features/PDFAnnotations.cjs +1 -1
  5. package/dist/cjs/components/features/PDFAnnotations.module.cjs +1 -1
  6. package/dist/cjs/components/features/PDFAttachments.cjs +1 -1
  7. package/dist/cjs/components/features/PDFChangeFile.cjs +1 -1
  8. package/dist/cjs/components/features/PDFDownloadButton.cjs +1 -1
  9. package/dist/cjs/components/features/PDFNavigation.cjs +1 -1
  10. package/dist/cjs/components/features/PDFOutline.cjs +1 -1
  11. package/dist/cjs/components/features/PDFPageFit.cjs +1 -1
  12. package/dist/cjs/components/features/PDFPrintButton.cjs +1 -1
  13. package/dist/cjs/components/features/PDFRotationControl.cjs +1 -1
  14. package/dist/cjs/components/features/PDFSearch.cjs +1 -1
  15. package/dist/cjs/components/features/PDFSidebarToggle.cjs +1 -1
  16. package/dist/cjs/components/features/PDFSignatures.cjs +1 -1
  17. package/dist/cjs/components/features/PDFThemeToggle.cjs +1 -1
  18. package/dist/cjs/components/features/PDFThumbnails.cjs +1 -1
  19. package/dist/cjs/components/features/PDFZoomControls.cjs +1 -1
  20. package/dist/cjs/components/ui/PDFToolbar.cjs +1 -1
  21. package/dist/cjs/context/LabelsContext.cjs +1 -0
  22. package/dist/cjs/context/labelsContextValue.cjs +1 -0
  23. package/dist/cjs/hooks/useAnnotationLayer.cjs +1 -1
  24. package/dist/cjs/hooks/useAnnotations.cjs +1 -1
  25. package/dist/cjs/hooks/useLabels.cjs +1 -0
  26. package/dist/cjs/index.cjs +1 -1
  27. package/dist/cjs/labels.cjs +1 -0
  28. package/dist/cjs/pdf-tsx.css +1 -1
  29. package/dist/components/PDFViewer.d.ts +1 -0
  30. package/dist/components/features/PDFChangeFile.d.ts +1 -1
  31. package/dist/components/features/PDFDownloadButton.d.ts +1 -1
  32. package/dist/components/features/PDFNavigation.d.ts +1 -1
  33. package/dist/components/features/PDFPageFit.d.ts +1 -1
  34. package/dist/components/features/PDFPrintButton.d.ts +1 -1
  35. package/dist/components/features/PDFRotationControl.d.ts +1 -1
  36. package/dist/components/features/PDFSearch.d.ts +3 -2
  37. package/dist/components/features/PDFSidebarToggle.d.ts +1 -1
  38. package/dist/components/features/PDFThemeToggle.d.ts +1 -1
  39. package/dist/components/features/PDFZoomControls.d.ts +1 -1
  40. package/dist/context/LabelsContext.d.ts +7 -0
  41. package/dist/context/labelsContextValue.d.ts +2 -0
  42. package/dist/es/components/PDFViewer.js +309 -191
  43. package/dist/es/components/PDFViewer.module.js +21 -16
  44. package/dist/es/components/features/PDFAnnotations.js +132 -62
  45. package/dist/es/components/features/PDFAnnotations.module.js +12 -12
  46. package/dist/es/components/features/PDFAttachments.js +42 -41
  47. package/dist/es/components/features/PDFChangeFile.js +17 -16
  48. package/dist/es/components/features/PDFDownloadButton.js +15 -14
  49. package/dist/es/components/features/PDFNavigation.js +39 -38
  50. package/dist/es/components/features/PDFOutline.js +46 -45
  51. package/dist/es/components/features/PDFPageFit.js +19 -18
  52. package/dist/es/components/features/PDFPrintButton.js +14 -13
  53. package/dist/es/components/features/PDFRotationControl.js +12 -11
  54. package/dist/es/components/features/PDFSearch.js +71 -55
  55. package/dist/es/components/features/PDFSidebarToggle.js +13 -12
  56. package/dist/es/components/features/PDFSignatures.js +87 -84
  57. package/dist/es/components/features/PDFThemeToggle.js +12 -11
  58. package/dist/es/components/features/PDFThumbnails.js +33 -32
  59. package/dist/es/components/features/PDFZoomControls.js +23 -22
  60. package/dist/es/components/ui/PDFToolbar.js +56 -55
  61. package/dist/es/context/LabelsContext.js +14 -0
  62. package/dist/es/context/labelsContextValue.js +5 -0
  63. package/dist/es/hooks/useAnnotationLayer.js +37 -20
  64. package/dist/es/hooks/useAnnotations.js +5 -3
  65. package/dist/es/hooks/useLabels.js +9 -0
  66. package/dist/es/index.js +22 -21
  67. package/dist/es/labels.js +124 -0
  68. package/dist/es/pdf-tsx.css +1 -1
  69. package/dist/hooks/useAnnotationLayer.d.ts +15 -1
  70. package/dist/hooks/useLabels.d.ts +2 -0
  71. package/dist/index.d.ts +2 -0
  72. package/dist/labels.d.ts +51 -0
  73. package/package.json +2 -1
@@ -1,25 +1,26 @@
1
1
  import { usePDFViewer as e } from "../../context/PDFViewerContext.js";
2
2
  import { computeFit as t } from "../../utils/pdfFit.js";
3
- import { useSignatures as n } from "../../hooks/useSignatures.js";
4
- import r from "./PDFSignatures.module.js";
5
- import { memo as i, useCallback as a } from "react";
6
- import { jsx as o, jsxs as s } from "react/jsx-runtime";
3
+ import { useLabels as n } from "../../hooks/useLabels.js";
4
+ import { useSignatures as r } from "../../hooks/useSignatures.js";
5
+ import i from "./PDFSignatures.module.js";
6
+ import { memo as a, useCallback as o } from "react";
7
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
7
8
  //#region src/components/features/PDFSignatures.tsx
8
- function c(e) {
9
+ function l(e) {
9
10
  if (!e) return;
10
11
  let t = e.match(/D:(\d{4})(\d{2})(\d{2})(\d{2})?(\d{2})?(\d{2})?/);
11
12
  if (!t) return e;
12
13
  let [, n, r, i, a = "00", o = "00"] = t;
13
14
  return `${i}/${r}/${n} ${a}:${o}`;
14
15
  }
15
- function l() {
16
- return /* @__PURE__ */ o("svg", {
16
+ function u() {
17
+ return /* @__PURE__ */ s("svg", {
17
18
  width: "10",
18
19
  height: "10",
19
20
  viewBox: "0 0 10 10",
20
21
  fill: "none",
21
22
  "aria-hidden": !0,
22
- children: /* @__PURE__ */ o("path", {
23
+ children: /* @__PURE__ */ s("path", {
23
24
  d: "M1.5 5L3.8 7.5L8.5 2.5",
24
25
  stroke: "currentColor",
25
26
  strokeWidth: "1.6",
@@ -28,14 +29,14 @@ function l() {
28
29
  })
29
30
  });
30
31
  }
31
- function u() {
32
- return /* @__PURE__ */ o("svg", {
32
+ function d() {
33
+ return /* @__PURE__ */ s("svg", {
33
34
  width: "10",
34
35
  height: "10",
35
36
  viewBox: "0 0 10 10",
36
37
  fill: "none",
37
38
  "aria-hidden": !0,
38
- children: /* @__PURE__ */ o("circle", {
39
+ children: /* @__PURE__ */ s("circle", {
39
40
  cx: "5",
40
41
  cy: "5",
41
42
  r: "3.7",
@@ -45,115 +46,117 @@ function u() {
45
46
  })
46
47
  });
47
48
  }
48
- var d = i(function({ sig: e, onNavigate: t }) {
49
- let n = !!e.rect, i = `${r.card} ${e.signed ? r.cardSigned : ""} ${n ? r.cardClickable : ""}`, d = a(() => t(e), [t, e]), f = /* @__PURE__ */ s("div", {
50
- className: r.cardBody,
51
- children: [/* @__PURE__ */ s("div", {
52
- className: r.cardHeader,
53
- children: [/* @__PURE__ */ o("span", {
54
- className: r.fieldName,
49
+ var f = a(function({ sig: e, labels: t, onNavigate: n }) {
50
+ let r = !!e.rect, a = `${i.card} ${e.signed ? i.cardSigned : ""} ${r ? i.cardClickable : ""}`, f = o(() => n(e), [n, e]), p = /* @__PURE__ */ c("div", {
51
+ className: i.cardBody,
52
+ children: [/* @__PURE__ */ c("div", {
53
+ className: i.cardHeader,
54
+ children: [/* @__PURE__ */ s("span", {
55
+ className: i.fieldName,
55
56
  children: e.fieldName
56
- }), /* @__PURE__ */ s("span", {
57
- className: `${r.statusChip} ${e.signed ? r.statusChipSigned : ""}`,
58
- children: [e.signed ? /* @__PURE__ */ o(l, {}) : /* @__PURE__ */ o(u, {}), e.signed ? "Firmato" : "Non firmato"]
57
+ }), /* @__PURE__ */ c("span", {
58
+ className: `${i.statusChip} ${e.signed ? i.statusChipSigned : ""}`,
59
+ children: [e.signed ? /* @__PURE__ */ s(u, {}) : /* @__PURE__ */ s(d, {}), e.signed ? t.signatureSigned : t.signatureUnsigned]
59
60
  })]
60
- }), (e.signerName || e.signDate || e.reason || e.location) && /* @__PURE__ */ s("div", {
61
- className: r.fieldList,
61
+ }), (e.signerName || e.signDate || e.reason || e.location) && /* @__PURE__ */ c("div", {
62
+ className: i.fieldList,
62
63
  children: [
63
- e.signerName && /* @__PURE__ */ s("div", {
64
- className: r.fieldRow,
65
- children: [/* @__PURE__ */ o("span", {
66
- className: r.fieldLabel,
67
- children: "Firmatario"
68
- }), /* @__PURE__ */ o("span", {
69
- className: r.fieldValue,
64
+ e.signerName && /* @__PURE__ */ c("div", {
65
+ className: i.fieldRow,
66
+ children: [/* @__PURE__ */ s("span", {
67
+ className: i.fieldLabel,
68
+ children: t.signatureSignerLabel
69
+ }), /* @__PURE__ */ s("span", {
70
+ className: i.fieldValue,
70
71
  children: e.signerName
71
72
  })]
72
73
  }),
73
- e.signDate && /* @__PURE__ */ s("div", {
74
- className: r.fieldRow,
75
- children: [/* @__PURE__ */ o("span", {
76
- className: r.fieldLabel,
77
- children: "Data"
78
- }), /* @__PURE__ */ o("span", {
79
- className: r.fieldValue,
80
- children: c(e.signDate)
74
+ e.signDate && /* @__PURE__ */ c("div", {
75
+ className: i.fieldRow,
76
+ children: [/* @__PURE__ */ s("span", {
77
+ className: i.fieldLabel,
78
+ children: t.signatureDateLabel
79
+ }), /* @__PURE__ */ s("span", {
80
+ className: i.fieldValue,
81
+ children: l(e.signDate)
81
82
  })]
82
83
  }),
83
- e.reason && /* @__PURE__ */ s("div", {
84
- className: r.fieldRow,
85
- children: [/* @__PURE__ */ o("span", {
86
- className: r.fieldLabel,
87
- children: "Motivo"
88
- }), /* @__PURE__ */ o("span", {
89
- className: r.fieldValue,
84
+ e.reason && /* @__PURE__ */ c("div", {
85
+ className: i.fieldRow,
86
+ children: [/* @__PURE__ */ s("span", {
87
+ className: i.fieldLabel,
88
+ children: t.signatureReasonLabel
89
+ }), /* @__PURE__ */ s("span", {
90
+ className: i.fieldValue,
90
91
  children: e.reason
91
92
  })]
92
93
  }),
93
- e.location && /* @__PURE__ */ s("div", {
94
- className: r.fieldRow,
95
- children: [/* @__PURE__ */ o("span", {
96
- className: r.fieldLabel,
97
- children: "Luogo"
98
- }), /* @__PURE__ */ o("span", {
99
- className: r.fieldValue,
94
+ e.location && /* @__PURE__ */ c("div", {
95
+ className: i.fieldRow,
96
+ children: [/* @__PURE__ */ s("span", {
97
+ className: i.fieldLabel,
98
+ children: t.signatureLocationLabel
99
+ }), /* @__PURE__ */ s("span", {
100
+ className: i.fieldValue,
100
101
  children: e.location
101
102
  })]
102
103
  })
103
104
  ]
104
105
  })]
105
106
  });
106
- return n ? /* @__PURE__ */ o("button", {
107
+ return r ? /* @__PURE__ */ s("button", {
107
108
  type: "button",
108
- className: i,
109
- onClick: d,
110
- children: f
111
- }) : /* @__PURE__ */ o("div", {
112
- className: i,
113
- children: f
109
+ className: a,
110
+ onClick: f,
111
+ children: p
112
+ }) : /* @__PURE__ */ s("div", {
113
+ className: a,
114
+ children: p
114
115
  });
115
116
  });
116
- function f({ icon: t }) {
117
- let { pdf: i } = e(), { signatures: a, loading: c } = n({ pdf: i }), l = a.length;
118
- return /* @__PURE__ */ s("span", {
119
- className: r.iconWrapper,
120
- children: [t, !c && l > 0 && /* @__PURE__ */ o("span", {
121
- className: r.badge,
117
+ function p({ icon: t }) {
118
+ let { pdf: n } = e(), { signatures: a, loading: o } = r({ pdf: n }), l = a.length;
119
+ return /* @__PURE__ */ c("span", {
120
+ className: i.iconWrapper,
121
+ children: [t, !o && l > 0 && /* @__PURE__ */ s("span", {
122
+ className: i.badge,
122
123
  children: l > 99 ? "99+" : l
123
124
  })]
124
125
  });
125
126
  }
126
- function p() {
127
- let { pdf: i, goToPage: c, setHighlight: l, setZoom: u, rotation: f, containerRef: p } = e(), { signatures: m, loading: h } = n({ pdf: i }), g = a(async (e) => {
128
- i && p.current && u(await t("page", i, p.current, f)), c(e.page), e.rect && l({
127
+ function m() {
128
+ let { pdf: a, goToPage: l, setHighlight: u, setZoom: d, setFitMode: p, rotation: m, containerRef: h } = e(), g = n(), { signatures: _, loading: v } = r({ pdf: a }), y = o(async (e) => {
129
+ p("page"), a && h.current && d(await t("page", a, h.current, m)), l(e.page), e.rect && u({
129
130
  page: e.page,
130
131
  pdfRect: e.rect
131
132
  });
132
133
  }, [
133
- i,
134
+ a,
135
+ h,
136
+ m,
137
+ l,
138
+ d,
134
139
  p,
135
- f,
136
- c,
137
- u,
138
- l
140
+ u
139
141
  ]);
140
- return /* @__PURE__ */ s("div", {
141
- className: r.list,
142
+ return /* @__PURE__ */ c("div", {
143
+ className: i.list,
142
144
  children: [
143
- h && /* @__PURE__ */ o("div", {
144
- className: r.emptyState,
145
- children: "Caricamento..."
145
+ v && /* @__PURE__ */ s("div", {
146
+ className: i.emptyState,
147
+ children: g.signaturesLoading
146
148
  }),
147
- !h && m.length === 0 && /* @__PURE__ */ o("div", {
148
- className: r.emptyState,
149
- children: "Nessuna firma rilevata."
149
+ !v && _.length === 0 && /* @__PURE__ */ s("div", {
150
+ className: i.emptyState,
151
+ children: g.signaturesEmpty
150
152
  }),
151
- !h && m.map((e, t) => /* @__PURE__ */ o(d, {
153
+ !v && _.map((e, t) => /* @__PURE__ */ s(f, {
152
154
  sig: e,
153
- onNavigate: g
155
+ labels: g,
156
+ onNavigate: y
154
157
  }, t))
155
158
  ]
156
159
  });
157
160
  }
158
161
  //#endregion
159
- export { p as PDFSignatures, f as PDFSignaturesIcon };
162
+ export { m as PDFSignatures, p as PDFSignaturesIcon };
@@ -1,16 +1,17 @@
1
- import { ToolbarButton as e } from "../ui/ToolbarButton.js";
2
- import { useTheme as t } from "../../hooks/useTheme.js";
1
+ import { useLabels as e } from "../../hooks/useLabels.js";
2
+ import { ToolbarButton as t } from "../ui/ToolbarButton.js";
3
+ import { useTheme as n } from "../../hooks/useTheme.js";
3
4
  import "react";
4
- import { jsx as n } from "react/jsx-runtime";
5
+ import { jsx as r } from "react/jsx-runtime";
5
6
  //#region src/components/features/PDFThemeToggle.tsx
6
- function r({ lightIcon: r, darkIcon: i }) {
7
- let { isDark: a, toggleTheme: o } = t();
8
- return /* @__PURE__ */ n(e, {
9
- onClick: o,
10
- title: a ? "Switch to light mode" : "Switch to dark mode",
11
- children: a ? r : i
7
+ function i({ lightIcon: i, darkIcon: a }) {
8
+ let { isDark: o, toggleTheme: s } = n(), c = e();
9
+ return /* @__PURE__ */ r(t, {
10
+ onClick: s,
11
+ title: o ? c.switchToLightTitle : c.switchToDarkTitle,
12
+ children: o ? i : a
12
13
  });
13
14
  }
14
- r.toolbarLabel = "Tema";
15
+ i.toolbarLabelKey = "themeToolbarLabel";
15
16
  //#endregion
16
- export { r as PDFThemeToggle };
17
+ export { i as PDFThemeToggle };
@@ -1,54 +1,55 @@
1
1
  import { usePDFViewer as e } from "../../context/PDFViewerContext.js";
2
- import { useThumbnails as t } from "../../hooks/useThumbnails.js";
3
- import n from "./PDFThumbnails.module.js";
4
- import { useEffect as r, useRef as i, useState as a } from "react";
5
- import { jsx as o, jsxs as s } from "react/jsx-runtime";
2
+ import { useLabels as t } from "../../hooks/useLabels.js";
3
+ import { useThumbnails as n } from "../../hooks/useThumbnails.js";
4
+ import r from "./PDFThumbnails.module.js";
5
+ import { useEffect as i, useRef as a, useState as o } from "react";
6
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
6
7
  //#region src/components/features/PDFThumbnails.tsx
7
- var c = 3;
8
- function l(e, t, n) {
8
+ var l = 3;
9
+ function u(e, t, n) {
9
10
  let r = new Set(t);
10
11
  for (let t of e) {
11
12
  if (!t.isIntersecting) continue;
12
13
  let e = Number(t.target.dataset.page);
13
- for (let t = Math.max(1, e - c); t <= Math.min(n, e + c); t++) r.add(t);
14
+ for (let t = Math.max(1, e - l); t <= Math.min(n, e + l); t++) r.add(t);
14
15
  }
15
16
  let i = Array.from(r).sort((e, t) => e - t);
16
17
  return i.join(",") === t.join(",") ? t : i;
17
18
  }
18
- function u() {
19
- let { pdf: c, rotation: u, currentPage: d, goToPage: f, numPages: p } = e(), m = i([]), [h, g] = a([]), { thumbnails: _ } = t({
20
- pdf: c,
21
- rotation: u,
22
- visiblePages: h
19
+ function d() {
20
+ let { pdf: l, rotation: d, currentPage: f, goToPage: p, numPages: m } = e(), h = t(), g = a([]), [_, v] = o([]), { thumbnails: y } = n({
21
+ pdf: l,
22
+ rotation: d,
23
+ visiblePages: _
23
24
  });
24
- return r(() => {
25
- if (p === 0) return;
26
- let e = new IntersectionObserver((e) => g((t) => l(e, t, p)), { threshold: 0 });
27
- return m.current.forEach((t) => {
25
+ return i(() => {
26
+ if (m === 0) return;
27
+ let e = new IntersectionObserver((e) => v((t) => u(e, t, m)), { threshold: 0 });
28
+ return g.current.forEach((t) => {
28
29
  t && e.observe(t);
29
30
  }), () => e.disconnect();
30
- }, [p]), /* @__PURE__ */ o("div", {
31
- className: n.thumbnailList,
32
- children: Array.from({ length: p }, (e, t) => {
33
- let r = t + 1, i = _[t], a = d === r;
34
- return /* @__PURE__ */ s("div", {
35
- className: `${n.thumbnailItem} ${a ? n.thumbnailItemActive : ""}`,
36
- onClick: () => f(r),
31
+ }, [m]), /* @__PURE__ */ s("div", {
32
+ className: r.thumbnailList,
33
+ children: Array.from({ length: m }, (e, t) => {
34
+ let n = t + 1, i = y[t], a = f === n;
35
+ return /* @__PURE__ */ c("div", {
36
+ className: `${r.thumbnailItem} ${a ? r.thumbnailItemActive : ""}`,
37
+ onClick: () => p(n),
37
38
  ref: (e) => {
38
- m.current[t] = e;
39
+ g.current[t] = e;
39
40
  },
40
- "data-page": r,
41
- children: [i ? /* @__PURE__ */ o("img", {
41
+ "data-page": n,
42
+ children: [i ? /* @__PURE__ */ s("img", {
42
43
  src: i,
43
- className: `${n.thumbnailImg} ${a ? n.thumbnailImgActive : ""}`,
44
- alt: `Anteprima pagina ${r}`
45
- }) : /* @__PURE__ */ o("div", { className: n.thumbnailSkeleton }), /* @__PURE__ */ o("div", {
46
- className: `${n.thumbnailLabel} ${a ? n.thumbnailLabelActive : ""}`,
47
- children: r
44
+ className: `${r.thumbnailImg} ${a ? r.thumbnailImgActive : ""}`,
45
+ alt: `${h.thumbnailAlt} ${n}`
46
+ }) : /* @__PURE__ */ s("div", { className: r.thumbnailSkeleton }), /* @__PURE__ */ s("div", {
47
+ className: `${r.thumbnailLabel} ${a ? r.thumbnailLabelActive : ""}`,
48
+ children: n
48
49
  })]
49
50
  }, t);
50
51
  })
51
52
  });
52
53
  }
53
54
  //#endregion
54
- export { u as PDFThumbnails };
55
+ export { d as PDFThumbnails };
@@ -1,30 +1,31 @@
1
1
  import { usePDFViewer as e } from "../../context/PDFViewerContext.js";
2
- import { ToolbarButton as t } from "../ui/ToolbarButton.js";
3
- import n from "./PDFZoomControls.module.js";
4
- import { useCallback as r } from "react";
5
- import { Fragment as i, jsx as a, jsxs as o } from "react/jsx-runtime";
2
+ import { useLabels as t } from "../../hooks/useLabels.js";
3
+ import { ToolbarButton as n } from "../ui/ToolbarButton.js";
4
+ import r from "./PDFZoomControls.module.js";
5
+ import { useCallback as i } from "react";
6
+ import { Fragment as a, jsx as o, jsxs as s } from "react/jsx-runtime";
6
7
  //#region src/components/features/PDFZoomControls.tsx
7
- function s({ zoomOutIcon: s, zoomInIcon: c }) {
8
- let { zoom: l, setZoom: u, setFitMode: d } = e(), f = r((e) => {
9
- d(null), u((t) => Math.min(Math.max(t + e, .2), 3));
10
- }, [d, u]), p = r(() => f(-.2), [f]), m = r(() => f(.2), [f]);
11
- return /* @__PURE__ */ o(i, { children: [
12
- /* @__PURE__ */ a(t, {
13
- onClick: p,
14
- title: "Riduci zoom",
15
- children: s
8
+ function c({ zoomOutIcon: c, zoomInIcon: l }) {
9
+ let { zoom: u, setZoom: d, setFitMode: f } = e(), p = t(), m = i((e) => {
10
+ f(null), d((t) => Math.min(Math.max(t + e, .2), 3));
11
+ }, [f, d]), h = i(() => m(-.2), [m]), g = i(() => m(.2), [m]);
12
+ return /* @__PURE__ */ s(a, { children: [
13
+ /* @__PURE__ */ o(n, {
14
+ onClick: h,
15
+ title: p.zoomOutTitle,
16
+ children: c
16
17
  }),
17
- /* @__PURE__ */ o("span", {
18
- className: n.zoomLabel,
19
- children: [Math.round(l * 100), "%"]
18
+ /* @__PURE__ */ s("span", {
19
+ className: r.zoomLabel,
20
+ children: [Math.round(u * 100), "%"]
20
21
  }),
21
- /* @__PURE__ */ a(t, {
22
- onClick: m,
23
- title: "Aumenta zoom",
24
- children: c
22
+ /* @__PURE__ */ o(n, {
23
+ onClick: g,
24
+ title: p.zoomInTitle,
25
+ children: l
25
26
  })
26
27
  ] });
27
28
  }
28
- s.toolbarLabel = "Zoom";
29
+ c.toolbarLabelKey = "zoomToolbarLabel";
29
30
  //#endregion
30
- export { s as PDFZoomControls };
31
+ export { c as PDFZoomControls };
@@ -1,85 +1,86 @@
1
- import { ToolbarButton as e } from "./ToolbarButton.js";
2
- import t from "./PDFToolbar.module.js";
3
- import { PDFToolbarDropdownContext as n } from "./PDFToolbarDropdownContext.js";
4
- import r, { useCallback as i, useEffect as a, useLayoutEffect as o, useRef as s, useState as c } from "react";
5
- import { jsx as l, jsxs as u } from "react/jsx-runtime";
1
+ import { useLabels as e } from "../../hooks/useLabels.js";
2
+ import { ToolbarButton as t } from "./ToolbarButton.js";
3
+ import n from "./PDFToolbar.module.js";
4
+ import { PDFToolbarDropdownContext as r } from "./PDFToolbarDropdownContext.js";
5
+ import i, { useCallback as a, useEffect as o, useLayoutEffect as s, useRef as c, useState as l } from "react";
6
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
6
7
  //#region src/components/ui/PDFToolbar.tsx
7
- var d = 40;
8
- function f({ children: f, overflowIcon: p = "···" }) {
9
- let m = s(null), h = s([]), g = s([]), [_, v] = c(null), [y, b] = c(!1), x = s(null), S = r.Children.toArray(f), C = i(() => {
10
- let e = m.current, t = g.current;
8
+ var f = 40;
9
+ function p({ children: p, overflowIcon: m = "···" }) {
10
+ let h = e(), g = c(null), _ = c([]), v = c([]), [y, b] = l(null), [x, S] = l(!1), C = c(null), w = i.Children.toArray(p), T = a(() => {
11
+ let e = g.current, t = v.current;
11
12
  if (!e || t.length === 0) return;
12
13
  let n = e.offsetWidth;
13
14
  if (t.reduce((e, t) => e + t, 0) <= n) {
14
- v(null);
15
+ b(null);
15
16
  return;
16
17
  }
17
18
  let r = 0, i = 0;
18
- for (let e = 0; e < t.length && r + t[e] + d <= n; e++) r += t[e], i++;
19
- v(i);
19
+ for (let e = 0; e < t.length && r + t[e] + f <= n; e++) r += t[e], i++;
20
+ b(i);
20
21
  }, []);
21
- o(() => {
22
- g.current = h.current.slice(0, S.length).map((e) => e?.offsetWidth ?? 0), C();
23
- }, []), a(() => {
24
- let e = m.current;
22
+ s(() => {
23
+ v.current = _.current.slice(0, w.length).map((e) => e?.offsetWidth ?? 0), T();
24
+ }, []), o(() => {
25
+ let e = g.current;
25
26
  if (!e) return;
26
- let t = new ResizeObserver(() => C());
27
+ let t = new ResizeObserver(() => T());
27
28
  return t.observe(e), () => t.disconnect();
28
- }, [C]), a(() => {
29
- if (!y) return;
29
+ }, [T]), o(() => {
30
+ if (!x) return;
30
31
  let e = (e) => {
31
- x.current?.contains(e.target) || b(!1);
32
+ C.current?.contains(e.target) || S(!1);
32
33
  };
33
34
  return document.addEventListener("mousedown", e), () => document.removeEventListener("mousedown", e);
34
- }, [y]);
35
- let w = _ !== null && _ < S.length, T = w ? S.slice(_) : [];
36
- return /* @__PURE__ */ u("div", {
37
- ref: m,
38
- className: t.toolbar,
39
- children: [S.map((e, n) => /* @__PURE__ */ l("div", {
35
+ }, [x]);
36
+ let E = y !== null && y < w.length, D = E ? w.slice(y) : [];
37
+ return /* @__PURE__ */ d("div", {
38
+ ref: g,
39
+ className: n.toolbar,
40
+ children: [w.map((e, t) => /* @__PURE__ */ u("div", {
40
41
  ref: (e) => {
41
- h.current[n] = e;
42
+ _.current[t] = e;
42
43
  },
43
- className: t.item,
44
- style: _ !== null && n >= _ ? { display: "none" } : void 0,
44
+ className: n.item,
45
+ style: y !== null && t >= y ? { display: "none" } : void 0,
45
46
  children: e
46
- }, n)), w && /* @__PURE__ */ u("div", {
47
- ref: x,
48
- className: t.overflowWrapper,
49
- children: [/* @__PURE__ */ l(e, {
50
- onClick: () => b((e) => !e),
51
- "aria-label": "Altre opzioni",
52
- "aria-expanded": y,
47
+ }, t)), E && /* @__PURE__ */ d("div", {
48
+ ref: C,
49
+ className: n.overflowWrapper,
50
+ children: [/* @__PURE__ */ u(t, {
51
+ onClick: () => S((e) => !e),
52
+ "aria-label": h.toolbarMoreOptions,
53
+ "aria-expanded": x,
53
54
  "aria-haspopup": "true",
54
- title: "Altre opzioni",
55
- className: y ? t.overflowBtnActive : void 0,
56
- children: p
57
- }), y && /* @__PURE__ */ l("div", {
58
- className: t.dropdown,
55
+ title: h.toolbarMoreOptions,
56
+ className: x ? n.overflowBtnActive : void 0,
57
+ children: m
58
+ }), x && /* @__PURE__ */ u("div", {
59
+ className: n.dropdown,
59
60
  role: "menu",
60
- children: T.map((e, i) => {
61
- let a = r.isValidElement(e) ? e.type.toolbarLabel : void 0;
62
- return /* @__PURE__ */ l("div", {
63
- className: t.dropdownItem,
61
+ children: D.map((e, t) => {
62
+ let a = i.isValidElement(e) ? e.type.toolbarLabelKey : void 0, o = a ? h[a] : void 0;
63
+ return /* @__PURE__ */ u("div", {
64
+ className: n.dropdownItem,
64
65
  role: "menuitem",
65
- children: a ? /* @__PURE__ */ u("div", {
66
- className: t.labeledItem,
67
- children: [/* @__PURE__ */ l("span", {
68
- className: t.itemLabel,
69
- children: a
70
- }), /* @__PURE__ */ l("div", {
71
- className: t.itemContent,
66
+ children: o ? /* @__PURE__ */ d("div", {
67
+ className: n.labeledItem,
68
+ children: [/* @__PURE__ */ u("span", {
69
+ className: n.itemLabel,
70
+ children: o
71
+ }), /* @__PURE__ */ u("div", {
72
+ className: n.itemContent,
72
73
  children: e
73
74
  })]
74
- }) : /* @__PURE__ */ l(n.Provider, {
75
+ }) : /* @__PURE__ */ u(r.Provider, {
75
76
  value: !0,
76
77
  children: e
77
78
  })
78
- }, i);
79
+ }, t);
79
80
  })
80
81
  })]
81
82
  })]
82
83
  });
83
84
  }
84
85
  //#endregion
85
- export { f as PDFToolbar };
86
+ export { p as PDFToolbar };
@@ -0,0 +1,14 @@
1
+ import { englishLabels as e, italianLabels as t } from "../labels.js";
2
+ import { LabelsContext as n } from "./labelsContextValue.js";
3
+ import { useMemo as r } from "react";
4
+ import { jsx as i } from "react/jsx-runtime";
5
+ //#region src/context/LabelsContext.tsx
6
+ function a({ children: a, language: o }) {
7
+ let s = r(() => o === "it" ? t : e, [o]);
8
+ return /* @__PURE__ */ i(n.Provider, {
9
+ value: s,
10
+ children: a
11
+ });
12
+ }
13
+ //#endregion
14
+ export { a as LabelsProvider };
@@ -0,0 +1,5 @@
1
+ import { createContext as e } from "react";
2
+ //#region src/context/labelsContextValue.ts
3
+ var t = e(null);
4
+ //#endregion
5
+ export { t as LabelsContext };