@papyrus-sdk/ui-react 0.1.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.
package/dist/index.js ADDED
@@ -0,0 +1,726 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // index.ts
20
+ var index_exports = {};
21
+ __export(index_exports, {
22
+ PageRenderer: () => PageRenderer_default,
23
+ SidebarLeft: () => SidebarLeft_default,
24
+ SidebarRight: () => SidebarRight_default,
25
+ Topbar: () => Topbar_default,
26
+ Viewer: () => Viewer_default
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // components/Topbar.tsx
31
+ var import_react = require("react");
32
+ var import_core = require("@papyrus-sdk/core");
33
+ var import_jsx_runtime = require("react/jsx-runtime");
34
+ var Topbar = ({ engine }) => {
35
+ const {
36
+ currentPage,
37
+ pageCount,
38
+ zoom,
39
+ uiTheme,
40
+ pageTheme,
41
+ setDocumentState,
42
+ accentColor,
43
+ toggleSidebarLeft,
44
+ toggleSidebarRight,
45
+ triggerScrollToPage
46
+ } = (0, import_core.useViewerStore)();
47
+ const fileInputRef = (0, import_react.useRef)(null);
48
+ const [pageInput, setPageInput] = (0, import_react.useState)(currentPage.toString());
49
+ const [showPageThemes, setShowPageThemes] = (0, import_react.useState)(false);
50
+ const isDark = uiTheme === "dark";
51
+ (0, import_react.useEffect)(() => {
52
+ setPageInput(currentPage.toString());
53
+ }, [currentPage]);
54
+ const handleZoom = (delta) => {
55
+ const newZoom = Math.max(0.2, Math.min(5, zoom + delta));
56
+ engine.setZoom(newZoom);
57
+ setDocumentState({ zoom: newZoom });
58
+ };
59
+ const handlePageChange = (page) => {
60
+ const p = Math.max(1, Math.min(pageCount, isNaN(page) ? 1 : page));
61
+ engine.goToPage(p);
62
+ setDocumentState({ currentPage: p });
63
+ triggerScrollToPage(p - 1);
64
+ };
65
+ const themes = [
66
+ { id: "normal", name: "Original", color: "bg-white" },
67
+ { id: "sepia", name: "S\xE9pia", color: "bg-[#f4ecd8]" },
68
+ { id: "dark", name: "Invertido", color: "bg-gray-800" },
69
+ { id: "high-contrast", name: "Contraste", color: "bg-black" }
70
+ ];
71
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `h-14 border-b flex items-center justify-between px-4 z-50 transition-colors duration-200 ${isDark ? "bg-[#1a1a1a] border-[#333] text-white" : "bg-white border-gray-200 text-gray-800"}`, children: [
72
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center space-x-3", children: [
73
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: toggleSidebarLeft, className: `p-2 rounded-md ${isDark ? "hover:bg-white/10" : "hover:bg-gray-100"}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M4 6h16M4 12h16M4 18h16" }) }) }),
74
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "font-bold text-lg tracking-tight", style: { color: accentColor }, children: [
75
+ "Papyrus",
76
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: isDark ? "text-white" : "text-gray-900", children: "Core" })
77
+ ] })
78
+ ] }),
79
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center space-x-4", children: [
80
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `flex items-center rounded-lg p-1 space-x-1 border ${isDark ? "bg-[#2a2a2a] border-[#444]" : "bg-gray-50 border-gray-200"}`, children: [
81
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => handlePageChange(currentPage - 1), className: "p-1.5 rounded transition-all hover:brightness-110", style: { color: accentColor }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M15 19l-7-7 7-7" }) }) }),
82
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
83
+ "input",
84
+ {
85
+ type: "text",
86
+ className: "w-10 text-center bg-transparent focus:outline-none font-bold text-sm",
87
+ value: pageInput,
88
+ onChange: (e) => setPageInput(e.target.value),
89
+ onKeyDown: (e) => e.key === "Enter" && handlePageChange(parseInt(pageInput)),
90
+ onBlur: () => handlePageChange(parseInt(pageInput))
91
+ }
92
+ ),
93
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "opacity-40 px-1", children: "/" }),
94
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "opacity-80 text-sm", children: pageCount }),
95
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => handlePageChange(currentPage + 1), className: "p-1.5 rounded transition-all hover:brightness-110", style: { color: accentColor }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" }) }) })
96
+ ] }),
97
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: `flex items-center rounded-lg p-1 border ${isDark ? "bg-[#2a2a2a] border-[#444]" : "bg-gray-50 border-gray-200"}`, children: [
98
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => handleZoom(-0.1), className: "p-1.5 rounded hover:brightness-110", style: { color: accentColor }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M20 12H4" }) }) }),
99
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "px-3 text-xs font-bold min-w-[50px] text-center", children: [
100
+ Math.round(zoom * 100),
101
+ "%"
102
+ ] }),
103
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => handleZoom(0.1), className: "p-1.5 rounded hover:brightness-110", style: { color: accentColor }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M12 4v16m8-8H4" }) }) })
104
+ ] })
105
+ ] }),
106
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "flex items-center space-x-3", children: [
107
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "relative", children: [
108
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
109
+ "button",
110
+ {
111
+ onClick: () => setShowPageThemes(!showPageThemes),
112
+ className: `flex items-center space-x-2 px-3 py-1.5 rounded-md text-xs font-bold border transition-all ${isDark ? "bg-[#2a2a2a] border-[#444]" : "bg-gray-50 border-gray-200"}`,
113
+ children: [
114
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `w-3 h-3 rounded-full border ${themes.find((t) => t.id === pageTheme)?.color}` }),
115
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "TEMA" })
116
+ ]
117
+ }
118
+ ),
119
+ showPageThemes && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `absolute top-full right-0 mt-2 w-48 rounded-lg shadow-xl border p-2 z-[60] ${isDark ? "bg-[#2a2a2a] border-[#444]" : "bg-white border-gray-200"}`, children: themes.map((t) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
120
+ "button",
121
+ {
122
+ onClick: () => {
123
+ setDocumentState({ pageTheme: t.id });
124
+ setShowPageThemes(false);
125
+ },
126
+ className: `w-full flex items-center space-x-3 px-3 py-2 rounded-md text-sm ${pageTheme === t.id ? "text-white" : isDark ? "hover:bg-white/10 text-gray-300" : "hover:bg-gray-50 text-gray-700"}`,
127
+ style: pageTheme === t.id ? { backgroundColor: accentColor } : void 0,
128
+ children: [
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: `w-3 h-3 rounded-full border ${t.color}` }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: t.name })
131
+ ]
132
+ },
133
+ t.id
134
+ )) })
135
+ ] }),
136
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => setDocumentState({ uiTheme: isDark ? "light" : "dark" }), className: `p-2 rounded-full ${isDark ? "bg-yellow-500/10 text-yellow-500" : "bg-gray-100 text-gray-500"}`, children: isDark ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-5 h-5", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 2a1 1 0 011 1v1a1 1 0 11-2 0V3a1 1 0 011-1zm4 8a4 4 0 11-8 0 4 4 0 018 0zm-.464 4.95l.707.707a1 1 0 001.414-1.414l-.707-.707a1 1 0 00-1.414 1.414z" }) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-5 h-5", fill: "currentColor", viewBox: "0 0 20 20", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M17.293 13.293A8 8 0 016.707 2.707a8.001 8.001 0 1010.586 10.586z" }) }) }),
137
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
138
+ "button",
139
+ {
140
+ onClick: () => fileInputRef.current?.click(),
141
+ className: "px-4 py-1.5 text-white rounded-md text-sm font-bold shadow-md active:scale-95",
142
+ style: { backgroundColor: accentColor },
143
+ children: "UPLOAD"
144
+ }
145
+ ),
146
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", { type: "file", ref: fileInputRef, className: "hidden", accept: ".pdf", onChange: async (e) => {
147
+ const file = e.target.files?.[0];
148
+ if (file) {
149
+ setDocumentState({ isLoaded: false });
150
+ await engine.load(file);
151
+ setDocumentState({ isLoaded: true, pageCount: engine.getPageCount(), currentPage: 1, outline: await engine.getOutline() });
152
+ }
153
+ } }),
154
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { onClick: () => toggleSidebarRight("search"), className: `p-2 rounded-md ${isDark ? "hover:bg-white/10" : "hover:bg-gray-100"}`, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" }) }) })
155
+ ] })
156
+ ] });
157
+ };
158
+ var Topbar_default = Topbar;
159
+
160
+ // components/SidebarLeft.tsx
161
+ var import_react2 = require("react");
162
+ var import_core2 = require("@papyrus-sdk/core");
163
+ var import_jsx_runtime2 = require("react/jsx-runtime");
164
+ var withAlpha = (hex, alpha) => {
165
+ const normalized = hex.replace("#", "").trim();
166
+ const value = normalized.length === 3 ? normalized.split("").map((c) => c + c).join("") : normalized;
167
+ if (value.length !== 6) return hex;
168
+ const r = parseInt(value.slice(0, 2), 16);
169
+ const g = parseInt(value.slice(2, 4), 16);
170
+ const b = parseInt(value.slice(4, 6), 16);
171
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
172
+ };
173
+ var Thumbnail = ({ engine, pageIndex, active, isDark, accentColor, onClick }) => {
174
+ const canvasRef = (0, import_react2.useRef)(null);
175
+ const accentSoft = withAlpha(accentColor, 0.12);
176
+ (0, import_react2.useEffect)(() => {
177
+ if (canvasRef.current) {
178
+ engine.renderPage(pageIndex, canvasRef.current, 0.15);
179
+ }
180
+ }, [engine, pageIndex]);
181
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
182
+ "div",
183
+ {
184
+ onClick,
185
+ className: `p-3 cursor-pointer transition-all rounded-lg border-2 ${active ? "shadow-sm" : "border-transparent"}`,
186
+ style: active ? { borderColor: accentColor, backgroundColor: accentSoft } : void 0,
187
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-col items-center", children: [
188
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: `shadow-lg rounded overflow-hidden mb-2 border ${isDark ? "border-[#333]" : "border-gray-200"}`, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("canvas", { ref: canvasRef, className: "max-w-full h-auto bg-white" }) }),
189
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: `text-[11px] font-bold ${active ? "" : isDark ? "text-gray-500" : "text-gray-400"}`, style: active ? { color: accentColor } : void 0, children: pageIndex + 1 })
190
+ ] })
191
+ }
192
+ );
193
+ };
194
+ var OutlineNode = ({ item, engine, isDark, accentColor, depth = 0 }) => {
195
+ const { triggerScrollToPage, outlineSearchQuery } = (0, import_core2.useViewerStore)();
196
+ const [expanded, setExpanded] = (0, import_react2.useState)(true);
197
+ const accentSoft = withAlpha(accentColor, 0.2);
198
+ const matchesSearch = outlineSearchQuery === "" || item.title.toLowerCase().includes(outlineSearchQuery.toLowerCase());
199
+ const hasMatchingChildren = item.children?.some((child) => child.title.toLowerCase().includes(outlineSearchQuery.toLowerCase()));
200
+ if (!matchesSearch && !hasMatchingChildren && outlineSearchQuery !== "") return null;
201
+ const handleClick = () => {
202
+ if (item.pageIndex >= 0) {
203
+ engine.goToPage(item.pageIndex + 1);
204
+ triggerScrollToPage(item.pageIndex);
205
+ }
206
+ };
207
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex flex-col", children: [
208
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
209
+ "div",
210
+ {
211
+ className: `flex items-center py-1.5 px-3 rounded-md transition-colors group ${item.pageIndex >= 0 ? "cursor-pointer" : "cursor-default"} ${isDark ? "hover:bg-white/10" : "hover:bg-gray-100"}`,
212
+ style: { paddingLeft: `${depth * 14 + 8}px` },
213
+ onClick: handleClick,
214
+ children: [
215
+ item.children && item.children.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
216
+ "button",
217
+ {
218
+ className: `mr-1 text-gray-400 transition-transform p-1`,
219
+ style: { color: accentColor, transform: expanded ? "rotate(90deg)" : "rotate(0deg)" },
220
+ onClick: (e) => {
221
+ e.stopPropagation();
222
+ setExpanded(!expanded);
223
+ },
224
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "w-3 h-3", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M9 5l7 7-7 7" }) })
225
+ }
226
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "w-5" }),
227
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
228
+ "span",
229
+ {
230
+ className: `text-[13px] leading-tight font-medium truncate ${isDark ? "text-gray-200" : "text-gray-700"}`,
231
+ style: matchesSearch && outlineSearchQuery ? { backgroundColor: accentSoft, color: accentColor } : void 0,
232
+ children: item.title
233
+ }
234
+ )
235
+ ]
236
+ }
237
+ ),
238
+ expanded && item.children && item.children.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex flex-col", children: item.children.map((child, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OutlineNode, { item: child, engine, isDark, accentColor, depth: depth + 1 }, i)) })
239
+ ] });
240
+ };
241
+ var SidebarLeft = ({ engine }) => {
242
+ const {
243
+ pageCount,
244
+ currentPage,
245
+ setDocumentState,
246
+ sidebarLeftOpen,
247
+ uiTheme,
248
+ triggerScrollToPage,
249
+ sidebarLeftTab,
250
+ setSidebarLeftTab,
251
+ outline,
252
+ outlineSearchQuery,
253
+ setOutlineSearch,
254
+ accentColor
255
+ } = (0, import_core2.useViewerStore)();
256
+ const isDark = uiTheme === "dark";
257
+ if (!sidebarLeftOpen) return null;
258
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `w-72 border-r flex flex-col h-full shrink-0 overflow-hidden transition-colors duration-200 ${isDark ? "bg-[#2a2a2a] border-[#3a3a3a]" : "bg-[#fcfcfc] border-gray-200"}`, children: [
259
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: `p-4 border-b flex flex-col space-y-4 ${isDark ? "border-[#3a3a3a]" : "border-gray-100"}`, children: [
260
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-center justify-between", children: [
261
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { className: `text-sm font-bold uppercase tracking-widest ${isDark ? "text-gray-100" : "text-gray-800"}`, children: sidebarLeftTab === "thumbnails" ? "Thumbnails" : "Sum\xE1rio" }),
262
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("button", { onClick: () => setDocumentState({ sidebarLeftOpen: false }), className: "text-gray-400 hover:text-gray-600", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) })
263
+ ] }),
264
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex gap-1", children: [
265
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
266
+ "button",
267
+ {
268
+ onClick: () => setSidebarLeftTab("thumbnails"),
269
+ className: `p-2 rounded-md ${sidebarLeftTab === "thumbnails" ? isDark ? "bg-white/10 text-white" : "bg-white shadow-sm border border-gray-200" : "text-gray-400"}`,
270
+ style: sidebarLeftTab === "thumbnails" && !isDark ? { color: accentColor } : void 0,
271
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2 2V6z" }) })
272
+ }
273
+ ),
274
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
275
+ "button",
276
+ {
277
+ onClick: () => setSidebarLeftTab("summary"),
278
+ className: `p-2 rounded-md ${sidebarLeftTab === "summary" ? isDark ? "bg-white/10 text-white" : "bg-white shadow-sm border border-gray-200" : "text-gray-400"}`,
279
+ style: sidebarLeftTab === "summary" && !isDark ? { color: accentColor } : void 0,
280
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M4 6h16M4 12h16M4 18h7" }) })
281
+ }
282
+ )
283
+ ] })
284
+ ] }),
285
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex-1 overflow-y-auto custom-scrollbar p-3", children: sidebarLeftTab === "thumbnails" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "space-y-1", children: Array.from({ length: pageCount }).map((_, idx) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Thumbnail, { engine, pageIndex: idx, isDark, accentColor, active: currentPage === idx + 1, onClick: () => {
286
+ engine.goToPage(idx + 1);
287
+ setDocumentState({ currentPage: idx + 1 });
288
+ triggerScrollToPage(idx);
289
+ } }, idx)) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex flex-col space-y-0.5", children: outline.map((item, i) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(OutlineNode, { item, engine, isDark, accentColor }, i)) }) })
290
+ ] });
291
+ };
292
+ var SidebarLeft_default = SidebarLeft;
293
+
294
+ // components/SidebarRight.tsx
295
+ var import_react3 = require("react");
296
+ var import_core3 = require("@papyrus-sdk/core");
297
+ var import_jsx_runtime3 = require("react/jsx-runtime");
298
+ var withAlpha2 = (hex, alpha) => {
299
+ const normalized = hex.replace("#", "").trim();
300
+ const value = normalized.length === 3 ? normalized.split("").map((c) => c + c).join("") : normalized;
301
+ if (value.length !== 6) return hex;
302
+ const r = parseInt(value.slice(0, 2), 16);
303
+ const g = parseInt(value.slice(2, 4), 16);
304
+ const b = parseInt(value.slice(4, 6), 16);
305
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
306
+ };
307
+ var SidebarRight = ({ engine }) => {
308
+ const {
309
+ sidebarRightOpen,
310
+ sidebarRightTab,
311
+ toggleSidebarRight,
312
+ searchResults,
313
+ activeSearchIndex,
314
+ uiTheme,
315
+ setSearch,
316
+ setDocumentState,
317
+ triggerScrollToPage,
318
+ annotations,
319
+ accentColor
320
+ } = (0, import_core3.useViewerStore)();
321
+ const [query, setQuery] = (0, import_react3.useState)("");
322
+ const [isSearching, setIsSearching] = (0, import_react3.useState)(false);
323
+ const searchService = new import_core3.SearchService(engine);
324
+ const isDark = uiTheme === "dark";
325
+ const accentSoft = withAlpha2(accentColor, 0.12);
326
+ const handleSearch = async (e) => {
327
+ e.preventDefault();
328
+ if (!query.trim()) {
329
+ setSearch("", []);
330
+ return;
331
+ }
332
+ setIsSearching(true);
333
+ const results = await searchService.search(query);
334
+ setSearch(query, results);
335
+ setIsSearching(false);
336
+ };
337
+ if (!sidebarRightOpen) return null;
338
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `w-80 border-l flex flex-col h-full shrink-0 transition-colors duration-200 shadow-2xl z-40 ${isDark ? "bg-[#1a1a1a] border-[#333]" : "bg-white border-gray-200"}`, children: [
339
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `p-4 border-b flex items-center justify-between shrink-0 ${isDark ? "border-[#333]" : "border-gray-100"}`, children: [
340
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex space-x-6", children: [
341
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
342
+ "button",
343
+ {
344
+ onClick: () => toggleSidebarRight("search"),
345
+ className: `text-[10px] font-black uppercase tracking-widest pb-1 transition-all ${sidebarRightTab === "search" ? "border-b-2" : "text-gray-400"}`,
346
+ style: sidebarRightTab === "search" ? { color: accentColor, borderColor: accentColor } : void 0,
347
+ children: "Busca"
348
+ }
349
+ ),
350
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
351
+ "button",
352
+ {
353
+ onClick: () => toggleSidebarRight("annotations"),
354
+ className: `text-[10px] font-black uppercase tracking-widest pb-1 transition-all ${sidebarRightTab === "annotations" ? "border-b-2" : "text-gray-400"}`,
355
+ style: sidebarRightTab === "annotations" ? { color: accentColor, borderColor: accentColor } : void 0,
356
+ children: "Notas"
357
+ }
358
+ )
359
+ ] }),
360
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { onClick: () => toggleSidebarRight(), className: "text-gray-400 hover:text-red-500 transition-colors", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M6 18L18 6M6 6l12 12" }) }) })
361
+ ] }),
362
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex-1 overflow-y-auto p-4 custom-scrollbar bg-opacity-50", children: sidebarRightTab === "search" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-4", children: [
363
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("form", { onSubmit: handleSearch, className: "relative mb-6", children: [
364
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
365
+ "input",
366
+ {
367
+ type: "text",
368
+ className: `w-full rounded-lg px-4 py-2.5 text-xs outline-none border transition-all shadow-inner font-medium ${isDark ? "bg-[#2a2a2a] text-white border-[#444] focus:border-blue-500" : "bg-gray-100 border-gray-200 focus:bg-white focus:border-blue-400"}`,
369
+ placeholder: "O que voc\xEA procura?",
370
+ value: query,
371
+ onChange: (e) => setQuery(e.target.value)
372
+ }
373
+ ),
374
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "submit", className: "absolute right-3 top-2.5 text-gray-400 transition-colors", style: { color: accentColor }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2.5, d: "M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" }) }) })
375
+ ] }),
376
+ isSearching && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex flex-col items-center justify-center py-12 space-y-3", children: [
377
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-6 h-6 border-2 border-t-transparent rounded-full animate-spin", style: { borderColor: accentColor } }),
378
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[10px] font-bold text-gray-500 uppercase", children: "Varrendo documento..." })
379
+ ] }),
380
+ !isSearching && searchResults.map((res, idx) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
381
+ "div",
382
+ {
383
+ onClick: () => {
384
+ setDocumentState({ activeSearchIndex: idx });
385
+ triggerScrollToPage(res.pageIndex);
386
+ },
387
+ className: `p-4 rounded-xl border-2 cursor-pointer transition-all group hover:scale-[1.02] ${idx === activeSearchIndex ? "shadow-lg" : isDark ? "border-[#333] hover:border-[#555] bg-[#222]" : "border-gray-50 hover:border-gray-200 bg-gray-50/50 hover:bg-white"}`,
388
+ style: idx === activeSearchIndex ? { borderColor: accentColor, backgroundColor: accentSoft } : void 0,
389
+ children: [
390
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-between mb-2", children: [
391
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
392
+ "span",
393
+ {
394
+ className: `text-[10px] font-black uppercase tracking-tighter ${idx === activeSearchIndex ? "" : "text-gray-400"}`,
395
+ style: idx === activeSearchIndex ? { color: accentColor } : void 0,
396
+ children: [
397
+ "P\xC1GINA ",
398
+ res.pageIndex + 1
399
+ ]
400
+ }
401
+ ),
402
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
403
+ "svg",
404
+ {
405
+ className: `w-3 h-3 transition-transform ${idx === activeSearchIndex ? "" : "text-gray-300"}`,
406
+ style: idx === activeSearchIndex ? { color: accentColor } : void 0,
407
+ fill: "none",
408
+ stroke: "currentColor",
409
+ viewBox: "0 0 24 24",
410
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M9 5l7 7-7 7" })
411
+ }
412
+ )
413
+ ] }),
414
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { className: `text-[11px] font-medium leading-relaxed italic ${isDark ? "text-gray-400" : "text-gray-600"}`, children: [
415
+ "...",
416
+ res.text,
417
+ "..."
418
+ ] })
419
+ ]
420
+ },
421
+ idx
422
+ ))
423
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "space-y-3", children: [
424
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "text-[9px] font-black text-gray-400 uppercase tracking-[0.2em] mb-6 flex items-center", children: [
425
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: "WORKSET" }),
426
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex-1 h-px bg-current ml-3 opacity-10" })
427
+ ] }),
428
+ annotations.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "text-center py-20", children: [
429
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-12 h-12 bg-gray-500/10 rounded-full flex items-center justify-center mx-auto mb-4", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { className: "w-6 h-6 text-gray-400", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" }) }) }),
430
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-[10px] font-bold text-gray-400 uppercase tracking-widest", children: "Sem anota\xE7\xF5es" })
431
+ ] }) : annotations.map((ann) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: `p-4 rounded-xl border group transition-all cursor-pointer ${isDark ? "bg-[#222] border-[#333] hover:border-[#444]" : "bg-white border-gray-100 shadow-sm hover:shadow-md"}`, children: [
432
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center justify-between mb-3", children: [
433
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex items-center space-x-2", children: [
434
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "w-2.5 h-2.5 rounded-full", style: { backgroundColor: ann.color } }),
435
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "text-[10px] font-black", style: { color: accentColor }, children: [
436
+ "P",
437
+ ann.pageIndex + 1
438
+ ] })
439
+ ] }),
440
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "text-[9px] text-gray-400 font-bold", children: new Date(ann.createdAt).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) })
441
+ ] }),
442
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: `text-[11px] font-bold uppercase tracking-tight ${isDark ? "text-gray-200" : "text-gray-700"}`, children: ann.type })
443
+ ] }, ann.id))
444
+ ] }) })
445
+ ] });
446
+ };
447
+ var SidebarRight_default = SidebarRight;
448
+
449
+ // components/Viewer.tsx
450
+ var import_react5 = require("react");
451
+ var import_core5 = require("@papyrus-sdk/core");
452
+
453
+ // components/PageRenderer.tsx
454
+ var import_react4 = require("react");
455
+ var import_core4 = require("@papyrus-sdk/core");
456
+ var import_types = require("@papyrus-sdk/types");
457
+ var import_jsx_runtime4 = require("react/jsx-runtime");
458
+ var PageRenderer = ({ engine, pageIndex }) => {
459
+ const containerRef = (0, import_react4.useRef)(null);
460
+ const canvasRef = (0, import_react4.useRef)(null);
461
+ const textLayerRef = (0, import_react4.useRef)(null);
462
+ const [loading, setLoading] = (0, import_react4.useState)(true);
463
+ const [isDragging, setIsDragging] = (0, import_react4.useState)(false);
464
+ const [startPos, setStartPos] = (0, import_react4.useState)({ x: 0, y: 0 });
465
+ const [currentRect, setCurrentRect] = (0, import_react4.useState)({ x: 0, y: 0, w: 0, h: 0 });
466
+ const {
467
+ zoom,
468
+ rotation,
469
+ pageTheme,
470
+ scrollToPageSignal,
471
+ setDocumentState,
472
+ annotations,
473
+ addAnnotation,
474
+ activeTool,
475
+ removeAnnotation,
476
+ selectedAnnotationId,
477
+ setSelectedAnnotation,
478
+ accentColor
479
+ } = (0, import_core4.useViewerStore)();
480
+ (0, import_react4.useEffect)(() => {
481
+ if (scrollToPageSignal === pageIndex && containerRef.current) {
482
+ containerRef.current.scrollIntoView({ behavior: "smooth", block: "start" });
483
+ setDocumentState({ scrollToPageSignal: null });
484
+ }
485
+ }, [scrollToPageSignal, pageIndex, setDocumentState]);
486
+ (0, import_react4.useEffect)(() => {
487
+ let active = true;
488
+ const render = async () => {
489
+ if (!canvasRef.current || !textLayerRef.current) return;
490
+ setLoading(true);
491
+ try {
492
+ const RENDER_SCALE = 2;
493
+ await engine.renderPage(pageIndex, canvasRef.current, RENDER_SCALE);
494
+ textLayerRef.current.innerHTML = "";
495
+ await engine.renderTextLayer(pageIndex, textLayerRef.current, RENDER_SCALE);
496
+ } catch (err) {
497
+ console.error("[Papyrus] Falha na renderiza\xE7\xE3o:", err);
498
+ } finally {
499
+ if (active) setLoading(false);
500
+ }
501
+ };
502
+ render();
503
+ return () => {
504
+ active = false;
505
+ };
506
+ }, [engine, pageIndex, zoom, rotation]);
507
+ const handleMouseDown = (e) => {
508
+ if (activeTool === "select") return;
509
+ const rect = containerRef.current?.getBoundingClientRect();
510
+ if (!rect) return;
511
+ setIsDragging(true);
512
+ const x = e.clientX - rect.left;
513
+ const y = e.clientY - rect.top;
514
+ setStartPos({ x, y });
515
+ setCurrentRect({ x, y, w: 0, h: 0 });
516
+ };
517
+ const handleMouseMove = (e) => {
518
+ if (!isDragging) return;
519
+ const rect = containerRef.current?.getBoundingClientRect();
520
+ if (!rect) return;
521
+ const currentX = e.clientX - rect.left;
522
+ const currentY = e.clientY - rect.top;
523
+ setCurrentRect({
524
+ x: Math.min(startPos.x, currentX),
525
+ y: Math.min(startPos.y, currentY),
526
+ w: Math.abs(currentX - startPos.x),
527
+ h: Math.abs(currentY - startPos.y)
528
+ });
529
+ };
530
+ const handleMouseUp = (e) => {
531
+ if (isDragging) {
532
+ setIsDragging(false);
533
+ if (currentRect.w > 5 && currentRect.h > 5) {
534
+ const rect = containerRef.current?.getBoundingClientRect();
535
+ if (rect) {
536
+ addAnnotation({
537
+ id: Math.random().toString(36).substr(2, 9),
538
+ pageIndex,
539
+ type: activeTool,
540
+ rect: {
541
+ x: currentRect.x / rect.width,
542
+ y: currentRect.y / rect.height,
543
+ width: currentRect.w / rect.width,
544
+ height: currentRect.h / rect.height
545
+ },
546
+ color: activeTool === "highlight" ? "#fbbf24" : activeTool === "strikeout" ? "#ef4444" : accentColor,
547
+ content: activeTool === "text" || activeTool === "comment" ? "" : void 0,
548
+ createdAt: Date.now()
549
+ });
550
+ }
551
+ }
552
+ setCurrentRect({ x: 0, y: 0, w: 0, h: 0 });
553
+ return;
554
+ }
555
+ if (activeTool === "select") {
556
+ const selection = window.getSelection();
557
+ const selectedText = selection?.toString().trim();
558
+ if (selectedText) {
559
+ import_core4.papyrusEvents.emit(import_types.PapyrusEventType.TEXT_SELECTED, {
560
+ text: selectedText,
561
+ pageIndex
562
+ });
563
+ }
564
+ }
565
+ };
566
+ const getPageFilter = () => {
567
+ switch (pageTheme) {
568
+ case "sepia":
569
+ return "sepia(0.6) contrast(1.1) brightness(0.95)";
570
+ case "dark":
571
+ return "invert(0.9) hue-rotate(180deg) brightness(1.1)";
572
+ case "high-contrast":
573
+ return "contrast(2) grayscale(1)";
574
+ default:
575
+ return "none";
576
+ }
577
+ };
578
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
579
+ "div",
580
+ {
581
+ ref: containerRef,
582
+ className: `relative inline-block shadow-2xl bg-white mb-10 transition-all ${activeTool !== "select" ? "no-select cursor-crosshair" : ""}`,
583
+ style: { scrollMarginTop: "20px", minHeight: "100px" },
584
+ onMouseDown: handleMouseDown,
585
+ onMouseMove: handleMouseMove,
586
+ onMouseUp: handleMouseUp,
587
+ children: [
588
+ loading && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "absolute inset-0 bg-gray-50 flex items-center justify-center z-10 animate-pulse", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "text-[10px] font-black text-gray-400 uppercase tracking-widest", children: "Sincronizando..." }) }),
589
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("canvas", { ref: canvasRef, style: { filter: getPageFilter() }, className: "block" }),
590
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
591
+ "div",
592
+ {
593
+ ref: textLayerRef,
594
+ className: "textLayer",
595
+ style: { pointerEvents: activeTool === "select" ? "auto" : "none" }
596
+ }
597
+ ),
598
+ isDragging && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
599
+ "div",
600
+ {
601
+ className: "absolute border-2 z-[40] pointer-events-none",
602
+ style: {
603
+ borderColor: accentColor,
604
+ backgroundColor: `${accentColor}33`,
605
+ left: currentRect.x,
606
+ top: currentRect.y,
607
+ width: currentRect.w,
608
+ height: currentRect.h
609
+ }
610
+ }
611
+ ),
612
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "absolute inset-0 pointer-events-none z-20", children: annotations.filter((a) => a.pageIndex === pageIndex).map((ann) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
613
+ AnnotationItem,
614
+ {
615
+ ann,
616
+ isSelected: selectedAnnotationId === ann.id,
617
+ accentColor,
618
+ onDelete: () => removeAnnotation(ann.id),
619
+ onSelect: () => setSelectedAnnotation(ann.id)
620
+ },
621
+ ann.id
622
+ )) })
623
+ ]
624
+ }
625
+ );
626
+ };
627
+ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
628
+ const isText = ann.type === "text" || ann.type === "comment";
629
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
630
+ "div",
631
+ {
632
+ className: `absolute pointer-events-auto transition-all ${isSelected ? "shadow-xl z-30" : "z-10"}`,
633
+ style: {
634
+ left: `${ann.rect.x * 100}%`,
635
+ top: `${ann.rect.y * 100}%`,
636
+ width: `${ann.rect.width * 100}%`,
637
+ height: `${ann.rect.height * 100}%`,
638
+ backgroundColor: ann.type === "highlight" ? `${ann.color}77` : "transparent",
639
+ borderBottom: ann.type === "strikeout" ? `2px solid ${ann.color}` : "none",
640
+ outline: isSelected ? `2px solid ${accentColor}` : void 0
641
+ },
642
+ onClick: (e) => {
643
+ e.stopPropagation();
644
+ onSelect();
645
+ },
646
+ children: [
647
+ isText && isSelected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "absolute top-full mt-2 w-64 bg-white shadow-2xl rounded-xl p-4 border border-gray-100 z-50", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
648
+ "textarea",
649
+ {
650
+ className: "w-full bg-transparent border-none focus:ring-0 p-0 text-gray-800 text-xs font-medium",
651
+ placeholder: "Escreva sua nota...",
652
+ rows: 3,
653
+ defaultValue: ann.content || "",
654
+ autoFocus: true
655
+ }
656
+ ) }),
657
+ isSelected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
658
+ "button",
659
+ {
660
+ onClick: (e) => {
661
+ e.stopPropagation();
662
+ onDelete();
663
+ },
664
+ className: "absolute -top-3 -right-3 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600",
665
+ children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { className: "w-3 h-3", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M6 18L18 6M6 6l12 12" }) })
666
+ }
667
+ )
668
+ ]
669
+ }
670
+ );
671
+ };
672
+ var PageRenderer_default = PageRenderer;
673
+
674
+ // components/Viewer.tsx
675
+ var import_jsx_runtime5 = require("react/jsx-runtime");
676
+ var Viewer = ({ engine }) => {
677
+ const { viewMode, pageCount, currentPage, activeTool, uiTheme, setDocumentState, accentColor } = (0, import_core5.useViewerStore)();
678
+ const isDark = uiTheme === "dark";
679
+ const viewerRef = (0, import_react5.useRef)(null);
680
+ (0, import_react5.useEffect)(() => {
681
+ const observer = new IntersectionObserver((entries) => {
682
+ entries.forEach((entry) => {
683
+ if (entry.isIntersecting) {
684
+ const pageIndex = parseInt(entry.target.getAttribute("data-page-index") || "0");
685
+ if (pageIndex + 1 !== currentPage) setDocumentState({ currentPage: pageIndex + 1 });
686
+ }
687
+ });
688
+ }, { root: viewerRef.current, threshold: 0.5 });
689
+ const pageElements = viewerRef.current?.querySelectorAll(".page-container");
690
+ pageElements?.forEach((el) => observer.observe(el));
691
+ return () => {
692
+ pageElements?.forEach((el) => observer.unobserve(el));
693
+ observer.disconnect();
694
+ };
695
+ }, [pageCount, setDocumentState, currentPage]);
696
+ const pages = Array.from({ length: pageCount }).map((_, i) => i);
697
+ const tools = [
698
+ { id: "select", name: "Select", icon: "M15 15l-2 5L9 9l11 4-5 2zm0 0l5 5" },
699
+ { id: "highlight", name: "Marker", icon: "M15.232 5.232l3.536 3.536m-2.036-5.036a2.5 2.5 0 113.536 3.536L6.5 21.036H3v-3.572L16.732 3.732z" },
700
+ { id: "strikeout", name: "Strike", icon: "M13 10V3L4 14h7v7l9-11h-7z" },
701
+ { id: "comment", name: "Note", icon: "M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z" }
702
+ ];
703
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: viewerRef, className: `flex-1 overflow-auto flex flex-col items-center py-16 relative custom-scrollbar scroll-smooth ${isDark ? "bg-[#121212]" : "bg-[#e9ecef]"}`, children: [
704
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-col items-center gap-6 w-full", children: pages.map((idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { "data-page-index": idx, className: "page-container", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PageRenderer_default, { engine, pageIndex: idx }) }, idx)) }),
705
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `fixed bottom-10 left-1/2 -translate-x-1/2 shadow-2xl rounded-2xl p-2 flex border z-50 ${isDark ? "bg-[#2a2a2a]/90 border-[#3a3a3a] backdrop-blur-xl" : "bg-white/95 border-gray-100 backdrop-blur-md"}`, children: tools.map((tool) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
706
+ "button",
707
+ {
708
+ onClick: () => setDocumentState({ activeTool: tool.id }),
709
+ className: `w-10 h-10 rounded-xl flex items-center justify-center transition-all ${activeTool === tool.id ? "text-white shadow-lg" : "text-gray-400"}`,
710
+ style: activeTool === tool.id ? { backgroundColor: accentColor } : void 0,
711
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { className: "w-5 h-5", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: tool.icon }) })
712
+ },
713
+ tool.id
714
+ )) })
715
+ ] });
716
+ };
717
+ var Viewer_default = Viewer;
718
+ // Annotate the CommonJS export names for ESM import in node:
719
+ 0 && (module.exports = {
720
+ PageRenderer,
721
+ SidebarLeft,
722
+ SidebarRight,
723
+ Topbar,
724
+ Viewer
725
+ });
726
+ //# sourceMappingURL=index.js.map