@papyrus-sdk/ui-react 0.2.11 → 0.2.14
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 +122 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +125 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -82,7 +82,6 @@ var Topbar = ({
|
|
|
82
82
|
if (pageCount <= 0) return;
|
|
83
83
|
const nextPage = Math.max(1, Math.min(pageCount, isNaN(page) ? 1 : page));
|
|
84
84
|
engine.goToPage(nextPage);
|
|
85
|
-
setDocumentState({ currentPage: nextPage });
|
|
86
85
|
triggerScrollToPage(nextPage - 1);
|
|
87
86
|
};
|
|
88
87
|
const handleFileUpload = async (event) => {
|
|
@@ -124,7 +123,7 @@ var Topbar = ({
|
|
|
124
123
|
children: /* @__PURE__ */ jsxs(
|
|
125
124
|
"div",
|
|
126
125
|
{
|
|
127
|
-
className: `absolute inset-x-0 bottom-0 rounded-t-2xl border-x border-t p-4 pb-6 shadow-2xl ${isDark ? "bg-[#
|
|
126
|
+
className: `absolute inset-x-0 bottom-0 rounded-t-2xl border-x border-t p-4 pb-6 shadow-2xl ${isDark ? "bg-[#1a1a1a] border-[#333] text-white" : "bg-white border-gray-200 text-gray-900"}`,
|
|
128
127
|
children: [
|
|
129
128
|
/* @__PURE__ */ jsx("div", { className: "mx-auto mb-4 h-1.5 w-10 rounded-full bg-gray-400/60" }),
|
|
130
129
|
/* @__PURE__ */ jsxs("div", { className: "mb-4 flex items-center justify-between", children: [
|
|
@@ -138,7 +137,7 @@ var Topbar = ({
|
|
|
138
137
|
/* @__PURE__ */ jsx(
|
|
139
138
|
"button",
|
|
140
139
|
{
|
|
141
|
-
className: `p-2 rounded-md ${isDark ? "text-
|
|
140
|
+
className: `p-2 rounded-md ${isDark ? "text-gray-200 hover:bg-white/10" : "text-gray-700 hover:bg-gray-100"}`,
|
|
142
141
|
onClick: () => setShowMobileMenu(false),
|
|
143
142
|
"aria-label": "Fechar menu",
|
|
144
143
|
children: /* @__PURE__ */ jsx(
|
|
@@ -166,12 +165,12 @@ var Topbar = ({
|
|
|
166
165
|
showZoomControls && /* @__PURE__ */ jsxs(
|
|
167
166
|
"div",
|
|
168
167
|
{
|
|
169
|
-
className: `rounded-xl border p-3 ${isDark ? "bg-[#
|
|
168
|
+
className: `rounded-xl border p-3 ${isDark ? "bg-[#2a2a2a] border-[#444] text-gray-100" : "bg-gray-50 border-gray-200"}`,
|
|
170
169
|
children: [
|
|
171
170
|
/* @__PURE__ */ jsx(
|
|
172
171
|
"div",
|
|
173
172
|
{
|
|
174
|
-
className: `mb-2 text-xs ${isDark ? "text-
|
|
173
|
+
className: `mb-2 text-xs ${isDark ? "text-gray-300" : "text-gray-600"}`,
|
|
175
174
|
children: "Zoom"
|
|
176
175
|
}
|
|
177
176
|
),
|
|
@@ -205,7 +204,7 @@ var Topbar = ({
|
|
|
205
204
|
/* @__PURE__ */ jsxs(
|
|
206
205
|
"span",
|
|
207
206
|
{
|
|
208
|
-
className: `text-sm font-semibold ${isDark ? "text-
|
|
207
|
+
className: `text-sm font-semibold ${isDark ? "text-gray-100" : "text-gray-800"}`,
|
|
209
208
|
children: [
|
|
210
209
|
Math.round(zoom * 100),
|
|
211
210
|
"%"
|
|
@@ -245,12 +244,12 @@ var Topbar = ({
|
|
|
245
244
|
showPageThemeSelector && /* @__PURE__ */ jsxs(
|
|
246
245
|
"div",
|
|
247
246
|
{
|
|
248
|
-
className: `rounded-xl border p-3 ${isDark ? "bg-[#
|
|
247
|
+
className: `rounded-xl border p-3 ${isDark ? "bg-[#2a2a2a] border-[#444] text-gray-100" : "bg-gray-50 border-gray-200"}`,
|
|
249
248
|
children: [
|
|
250
249
|
/* @__PURE__ */ jsx(
|
|
251
250
|
"div",
|
|
252
251
|
{
|
|
253
|
-
className: `mb-2 text-xs ${isDark ? "text-
|
|
252
|
+
className: `mb-2 text-xs ${isDark ? "text-gray-300" : "text-gray-600"}`,
|
|
254
253
|
children: "Tema da p\xE1gina"
|
|
255
254
|
}
|
|
256
255
|
),
|
|
@@ -260,7 +259,7 @@ var Topbar = ({
|
|
|
260
259
|
onClick: () => {
|
|
261
260
|
setDocumentState({ pageTheme: theme.id });
|
|
262
261
|
},
|
|
263
|
-
className: `rounded-lg border px-2 py-2 text-xs font-semibold ${pageTheme === theme.id ? "text-white" : isDark ? "text-
|
|
262
|
+
className: `rounded-lg border px-2 py-2 text-xs font-semibold ${pageTheme === theme.id ? "text-white" : isDark ? "text-gray-300 border-[#444]" : "text-gray-700 border-gray-300"}`,
|
|
264
263
|
style: pageTheme === theme.id ? {
|
|
265
264
|
backgroundColor: accentColor,
|
|
266
265
|
borderColor: accentColor
|
|
@@ -278,7 +277,7 @@ var Topbar = ({
|
|
|
278
277
|
onClick: () => {
|
|
279
278
|
setDocumentState({ uiTheme: isDark ? "light" : "dark" });
|
|
280
279
|
},
|
|
281
|
-
className: `w-full rounded-xl border px-3 py-3 text-left text-sm font-medium flex items-center gap-2 ${isDark ? "bg-[#
|
|
280
|
+
className: `w-full rounded-xl border px-3 py-3 text-left text-sm font-medium flex items-center gap-2 ${isDark ? "bg-[#2a2a2a] border-[#444] text-gray-100" : "bg-gray-50 border-gray-200 text-gray-800"}`,
|
|
282
281
|
children: [
|
|
283
282
|
/* @__PURE__ */ jsx(
|
|
284
283
|
"svg",
|
|
@@ -423,7 +422,7 @@ var Topbar = ({
|
|
|
423
422
|
title && /* @__PURE__ */ jsx(
|
|
424
423
|
"span",
|
|
425
424
|
{
|
|
426
|
-
className: `text-sm font-semibold truncate min-w-0 max-w-[35vw] sm:max-w-[260px] ${isDark ? "text-gray-200" : "text-gray-700"}`,
|
|
425
|
+
className: `hidden sm:inline text-sm font-semibold truncate min-w-0 max-w-[35vw] sm:max-w-[260px] ${isDark ? "text-gray-200" : "text-gray-700"}`,
|
|
427
426
|
title: typeof title === "string" ? title : void 0,
|
|
428
427
|
children: title
|
|
429
428
|
}
|
|
@@ -1016,7 +1015,6 @@ var SidebarLeft = ({ engine }) => {
|
|
|
1016
1015
|
active: currentPage === idx + 1,
|
|
1017
1016
|
onClick: () => {
|
|
1018
1017
|
engine.goToPage(idx + 1);
|
|
1019
|
-
setDocumentState({ currentPage: idx + 1 });
|
|
1020
1018
|
triggerScrollToPage(idx);
|
|
1021
1019
|
}
|
|
1022
1020
|
},
|
|
@@ -1337,9 +1335,16 @@ import { useViewerStore as useViewerStore5 } from "@papyrus-sdk/core";
|
|
|
1337
1335
|
// components/PageRenderer.tsx
|
|
1338
1336
|
import { useEffect as useEffect3, useMemo, useRef as useRef3, useState as useState4 } from "react";
|
|
1339
1337
|
import { useViewerStore as useViewerStore4, papyrusEvents } from "@papyrus-sdk/core";
|
|
1340
|
-
import {
|
|
1338
|
+
import {
|
|
1339
|
+
PapyrusEventType
|
|
1340
|
+
} from "@papyrus-sdk/types";
|
|
1341
1341
|
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1342
|
-
var PageRenderer = ({
|
|
1342
|
+
var PageRenderer = ({
|
|
1343
|
+
engine,
|
|
1344
|
+
pageIndex,
|
|
1345
|
+
availableWidth,
|
|
1346
|
+
onMeasuredSize
|
|
1347
|
+
}) => {
|
|
1343
1348
|
const containerRef = useRef3(null);
|
|
1344
1349
|
const canvasRef = useRef3(null);
|
|
1345
1350
|
const htmlLayerRef = useRef3(null);
|
|
@@ -1373,7 +1378,12 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1373
1378
|
} = useViewerStore4();
|
|
1374
1379
|
const renderTargetType = engine.getRenderTargetType?.() ?? "canvas";
|
|
1375
1380
|
const isElementRender = renderTargetType === "element";
|
|
1376
|
-
const textMarkupTools = /* @__PURE__ */ new Set([
|
|
1381
|
+
const textMarkupTools = /* @__PURE__ */ new Set([
|
|
1382
|
+
"highlight",
|
|
1383
|
+
"underline",
|
|
1384
|
+
"squiggly",
|
|
1385
|
+
"strikeout"
|
|
1386
|
+
]);
|
|
1377
1387
|
const canSelectText = activeTool === "select" || textMarkupTools.has(activeTool);
|
|
1378
1388
|
const hasSearchHits = useMemo(
|
|
1379
1389
|
() => Boolean(searchQuery?.trim()) && searchResults.some((res) => res.pageIndex === pageIndex),
|
|
@@ -1449,7 +1459,11 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1449
1459
|
if (!active || !textLayerRef.current) return;
|
|
1450
1460
|
if (!isElementRender) {
|
|
1451
1461
|
textLayerRef.current.innerHTML = "";
|
|
1452
|
-
await engine.renderTextLayer(
|
|
1462
|
+
await engine.renderTextLayer(
|
|
1463
|
+
pageIndex,
|
|
1464
|
+
textLayerRef.current,
|
|
1465
|
+
textRenderScale
|
|
1466
|
+
);
|
|
1453
1467
|
}
|
|
1454
1468
|
if (!active || !textLayerRef.current) return;
|
|
1455
1469
|
if (!isElementRender && displaySize) {
|
|
@@ -1472,13 +1486,24 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1472
1486
|
return () => {
|
|
1473
1487
|
active = false;
|
|
1474
1488
|
};
|
|
1475
|
-
}, [
|
|
1489
|
+
}, [
|
|
1490
|
+
engine,
|
|
1491
|
+
pageIndex,
|
|
1492
|
+
zoom,
|
|
1493
|
+
rotation,
|
|
1494
|
+
isElementRender,
|
|
1495
|
+
fitScale,
|
|
1496
|
+
displaySize,
|
|
1497
|
+
pageSize
|
|
1498
|
+
]);
|
|
1476
1499
|
useEffect3(() => {
|
|
1477
1500
|
if (isElementRender) return;
|
|
1478
1501
|
const layer = textLayerRef.current;
|
|
1479
1502
|
if (!layer) return;
|
|
1480
1503
|
const query = searchQuery?.trim().toLowerCase();
|
|
1481
|
-
const existingMarks = Array.from(
|
|
1504
|
+
const existingMarks = Array.from(
|
|
1505
|
+
layer.querySelectorAll("mark.papyrus-search-hit")
|
|
1506
|
+
);
|
|
1482
1507
|
existingMarks.forEach((mark) => {
|
|
1483
1508
|
const parent = mark.parentNode;
|
|
1484
1509
|
if (!parent) return;
|
|
@@ -1507,7 +1532,9 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1507
1532
|
let index = lower.indexOf(query, cursor);
|
|
1508
1533
|
while (index !== -1) {
|
|
1509
1534
|
if (index > cursor) {
|
|
1510
|
-
fragment.appendChild(
|
|
1535
|
+
fragment.appendChild(
|
|
1536
|
+
document.createTextNode(text.slice(cursor, index))
|
|
1537
|
+
);
|
|
1511
1538
|
}
|
|
1512
1539
|
const mark = document.createElement("mark");
|
|
1513
1540
|
mark.className = "papyrus-search-hit";
|
|
@@ -1522,7 +1549,14 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1522
1549
|
const parent = textNode.parentNode;
|
|
1523
1550
|
if (parent) parent.replaceChild(fragment, textNode);
|
|
1524
1551
|
});
|
|
1525
|
-
}, [
|
|
1552
|
+
}, [
|
|
1553
|
+
searchQuery,
|
|
1554
|
+
hasSearchHits,
|
|
1555
|
+
pageIndex,
|
|
1556
|
+
isElementRender,
|
|
1557
|
+
activeSearchIndex,
|
|
1558
|
+
textLayerVersion
|
|
1559
|
+
]);
|
|
1526
1560
|
const handleMouseDown = (e) => {
|
|
1527
1561
|
setSelectionMenu(null);
|
|
1528
1562
|
if (activeTool === "ink") {
|
|
@@ -1613,25 +1647,41 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1613
1647
|
};
|
|
1614
1648
|
});
|
|
1615
1649
|
const uniqueRects = rects.filter((rect, index, list) => {
|
|
1616
|
-
const key = `${Math.round(rect.x * 1e4)}-${Math.round(
|
|
1617
|
-
|
|
1650
|
+
const key = `${Math.round(rect.x * 1e4)}-${Math.round(
|
|
1651
|
+
rect.y * 1e4
|
|
1652
|
+
)}-${Math.round(rect.width * 1e4)}-${Math.round(
|
|
1653
|
+
rect.height * 1e4
|
|
1654
|
+
)}`;
|
|
1655
|
+
return list.findIndex(
|
|
1656
|
+
(r) => `${Math.round(r.x * 1e4)}-${Math.round(
|
|
1657
|
+
r.y * 1e4
|
|
1658
|
+
)}-${Math.round(r.width * 1e4)}-${Math.round(
|
|
1659
|
+
r.height * 1e4
|
|
1660
|
+
)}` === key
|
|
1661
|
+
) === index;
|
|
1618
1662
|
});
|
|
1619
|
-
const mergedRects = uniqueRects.reduce(
|
|
1620
|
-
|
|
1621
|
-
const
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1663
|
+
const mergedRects = uniqueRects.reduce(
|
|
1664
|
+
(acc, rect) => {
|
|
1665
|
+
const target = acc.find((r) => {
|
|
1666
|
+
const closeY = Math.abs(r.y - rect.y) < 2e-3 && Math.abs(r.height - rect.height) < 2e-3;
|
|
1667
|
+
const overlaps = rect.x <= r.x + r.width + 2e-3 && rect.x + rect.width >= r.x - 2e-3;
|
|
1668
|
+
return closeY && overlaps;
|
|
1669
|
+
});
|
|
1670
|
+
if (!target) {
|
|
1671
|
+
acc.push({ ...rect });
|
|
1672
|
+
return acc;
|
|
1673
|
+
}
|
|
1674
|
+
const left = Math.min(target.x, rect.x);
|
|
1675
|
+
const right = Math.max(
|
|
1676
|
+
target.x + target.width,
|
|
1677
|
+
rect.x + rect.width
|
|
1678
|
+
);
|
|
1679
|
+
target.x = left;
|
|
1680
|
+
target.width = right - left;
|
|
1627
1681
|
return acc;
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
target.x = left;
|
|
1632
|
-
target.width = right - left;
|
|
1633
|
-
return acc;
|
|
1634
|
-
}, []);
|
|
1682
|
+
},
|
|
1683
|
+
[]
|
|
1684
|
+
);
|
|
1635
1685
|
if (mergedRects.length) {
|
|
1636
1686
|
const xs = mergedRects.map((r) => r.x);
|
|
1637
1687
|
const ys = mergedRects.map((r) => r.y);
|
|
@@ -1724,7 +1774,7 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1724
1774
|
"div",
|
|
1725
1775
|
{
|
|
1726
1776
|
ref: containerRef,
|
|
1727
|
-
className: `relative inline-block shadow-2xl bg-white mb-10
|
|
1777
|
+
className: `relative inline-block shadow-2xl bg-white mb-10 ${canSelectText ? "" : "no-select cursor-crosshair"}`,
|
|
1728
1778
|
style: { scrollMarginTop: "20px", minHeight: "100px" },
|
|
1729
1779
|
onMouseDown: handleMouseDown,
|
|
1730
1780
|
onMouseMove: handleMouseMove,
|
|
@@ -1735,7 +1785,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1735
1785
|
"canvas",
|
|
1736
1786
|
{
|
|
1737
1787
|
ref: canvasRef,
|
|
1738
|
-
style: {
|
|
1788
|
+
style: {
|
|
1789
|
+
filter: getPageFilter(),
|
|
1790
|
+
display: isElementRender ? "none" : "block"
|
|
1791
|
+
},
|
|
1739
1792
|
className: "block"
|
|
1740
1793
|
}
|
|
1741
1794
|
),
|
|
@@ -1744,7 +1797,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1744
1797
|
{
|
|
1745
1798
|
ref: htmlLayerRef,
|
|
1746
1799
|
className: "block",
|
|
1747
|
-
style: {
|
|
1800
|
+
style: {
|
|
1801
|
+
filter: getPageFilter(),
|
|
1802
|
+
display: isElementRender ? "block" : "none"
|
|
1803
|
+
}
|
|
1748
1804
|
}
|
|
1749
1805
|
),
|
|
1750
1806
|
/* @__PURE__ */ jsx4(
|
|
@@ -1935,7 +1991,17 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
|
|
|
1935
1991
|
className: "absolute inset-0",
|
|
1936
1992
|
viewBox: `${ann.rect.x} ${ann.rect.y} ${ann.rect.width} ${ann.rect.height}`,
|
|
1937
1993
|
preserveAspectRatio: "none",
|
|
1938
|
-
children: /* @__PURE__ */ jsx4(
|
|
1994
|
+
children: /* @__PURE__ */ jsx4(
|
|
1995
|
+
"path",
|
|
1996
|
+
{
|
|
1997
|
+
d,
|
|
1998
|
+
fill: "none",
|
|
1999
|
+
stroke: ann.color,
|
|
2000
|
+
strokeWidth: 8e-3,
|
|
2001
|
+
strokeLinecap: "round",
|
|
2002
|
+
strokeLinejoin: "round"
|
|
2003
|
+
}
|
|
2004
|
+
)
|
|
1939
2005
|
}
|
|
1940
2006
|
);
|
|
1941
2007
|
};
|
|
@@ -1978,7 +2044,24 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
|
|
|
1978
2044
|
onDelete();
|
|
1979
2045
|
},
|
|
1980
2046
|
className: "absolute -top-3 -right-3 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600",
|
|
1981
|
-
children: /* @__PURE__ */ jsx4(
|
|
2047
|
+
children: /* @__PURE__ */ jsx4(
|
|
2048
|
+
"svg",
|
|
2049
|
+
{
|
|
2050
|
+
className: "w-3 h-3",
|
|
2051
|
+
fill: "none",
|
|
2052
|
+
stroke: "currentColor",
|
|
2053
|
+
viewBox: "0 0 24 24",
|
|
2054
|
+
children: /* @__PURE__ */ jsx4(
|
|
2055
|
+
"path",
|
|
2056
|
+
{
|
|
2057
|
+
strokeLinecap: "round",
|
|
2058
|
+
strokeLinejoin: "round",
|
|
2059
|
+
strokeWidth: 3,
|
|
2060
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
2061
|
+
}
|
|
2062
|
+
)
|
|
2063
|
+
}
|
|
2064
|
+
)
|
|
1982
2065
|
}
|
|
1983
2066
|
)
|
|
1984
2067
|
]
|