@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.js
CHANGED
|
@@ -111,7 +111,6 @@ var Topbar = ({
|
|
|
111
111
|
if (pageCount <= 0) return;
|
|
112
112
|
const nextPage = Math.max(1, Math.min(pageCount, isNaN(page) ? 1 : page));
|
|
113
113
|
engine.goToPage(nextPage);
|
|
114
|
-
setDocumentState({ currentPage: nextPage });
|
|
115
114
|
triggerScrollToPage(nextPage - 1);
|
|
116
115
|
};
|
|
117
116
|
const handleFileUpload = async (event) => {
|
|
@@ -153,7 +152,7 @@ var Topbar = ({
|
|
|
153
152
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
154
153
|
"div",
|
|
155
154
|
{
|
|
156
|
-
className: `absolute inset-x-0 bottom-0 rounded-t-2xl border-x border-t p-4 pb-6 shadow-2xl ${isDark ? "bg-[#
|
|
155
|
+
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"}`,
|
|
157
156
|
children: [
|
|
158
157
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "mx-auto mb-4 h-1.5 w-10 rounded-full bg-gray-400/60" }),
|
|
159
158
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "mb-4 flex items-center justify-between", children: [
|
|
@@ -167,7 +166,7 @@ var Topbar = ({
|
|
|
167
166
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
168
167
|
"button",
|
|
169
168
|
{
|
|
170
|
-
className: `p-2 rounded-md ${isDark ? "text-
|
|
169
|
+
className: `p-2 rounded-md ${isDark ? "text-gray-200 hover:bg-white/10" : "text-gray-700 hover:bg-gray-100"}`,
|
|
171
170
|
onClick: () => setShowMobileMenu(false),
|
|
172
171
|
"aria-label": "Fechar menu",
|
|
173
172
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -195,12 +194,12 @@ var Topbar = ({
|
|
|
195
194
|
showZoomControls && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
196
195
|
"div",
|
|
197
196
|
{
|
|
198
|
-
className: `rounded-xl border p-3 ${isDark ? "bg-[#
|
|
197
|
+
className: `rounded-xl border p-3 ${isDark ? "bg-[#2a2a2a] border-[#444] text-gray-100" : "bg-gray-50 border-gray-200"}`,
|
|
199
198
|
children: [
|
|
200
199
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
201
200
|
"div",
|
|
202
201
|
{
|
|
203
|
-
className: `mb-2 text-xs ${isDark ? "text-
|
|
202
|
+
className: `mb-2 text-xs ${isDark ? "text-gray-300" : "text-gray-600"}`,
|
|
204
203
|
children: "Zoom"
|
|
205
204
|
}
|
|
206
205
|
),
|
|
@@ -234,7 +233,7 @@ var Topbar = ({
|
|
|
234
233
|
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
235
234
|
"span",
|
|
236
235
|
{
|
|
237
|
-
className: `text-sm font-semibold ${isDark ? "text-
|
|
236
|
+
className: `text-sm font-semibold ${isDark ? "text-gray-100" : "text-gray-800"}`,
|
|
238
237
|
children: [
|
|
239
238
|
Math.round(zoom * 100),
|
|
240
239
|
"%"
|
|
@@ -274,12 +273,12 @@ var Topbar = ({
|
|
|
274
273
|
showPageThemeSelector && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
275
274
|
"div",
|
|
276
275
|
{
|
|
277
|
-
className: `rounded-xl border p-3 ${isDark ? "bg-[#
|
|
276
|
+
className: `rounded-xl border p-3 ${isDark ? "bg-[#2a2a2a] border-[#444] text-gray-100" : "bg-gray-50 border-gray-200"}`,
|
|
278
277
|
children: [
|
|
279
278
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
280
279
|
"div",
|
|
281
280
|
{
|
|
282
|
-
className: `mb-2 text-xs ${isDark ? "text-
|
|
281
|
+
className: `mb-2 text-xs ${isDark ? "text-gray-300" : "text-gray-600"}`,
|
|
283
282
|
children: "Tema da p\xE1gina"
|
|
284
283
|
}
|
|
285
284
|
),
|
|
@@ -289,7 +288,7 @@ var Topbar = ({
|
|
|
289
288
|
onClick: () => {
|
|
290
289
|
setDocumentState({ pageTheme: theme.id });
|
|
291
290
|
},
|
|
292
|
-
className: `rounded-lg border px-2 py-2 text-xs font-semibold ${pageTheme === theme.id ? "text-white" : isDark ? "text-
|
|
291
|
+
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"}`,
|
|
293
292
|
style: pageTheme === theme.id ? {
|
|
294
293
|
backgroundColor: accentColor,
|
|
295
294
|
borderColor: accentColor
|
|
@@ -307,7 +306,7 @@ var Topbar = ({
|
|
|
307
306
|
onClick: () => {
|
|
308
307
|
setDocumentState({ uiTheme: isDark ? "light" : "dark" });
|
|
309
308
|
},
|
|
310
|
-
className: `w-full rounded-xl border px-3 py-3 text-left text-sm font-medium flex items-center gap-2 ${isDark ? "bg-[#
|
|
309
|
+
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"}`,
|
|
311
310
|
children: [
|
|
312
311
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
313
312
|
"svg",
|
|
@@ -452,7 +451,7 @@ var Topbar = ({
|
|
|
452
451
|
title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
453
452
|
"span",
|
|
454
453
|
{
|
|
455
|
-
className: `text-sm font-semibold truncate min-w-0 max-w-[35vw] sm:max-w-[260px] ${isDark ? "text-gray-200" : "text-gray-700"}`,
|
|
454
|
+
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"}`,
|
|
456
455
|
title: typeof title === "string" ? title : void 0,
|
|
457
456
|
children: title
|
|
458
457
|
}
|
|
@@ -1045,7 +1044,6 @@ var SidebarLeft = ({ engine }) => {
|
|
|
1045
1044
|
active: currentPage === idx + 1,
|
|
1046
1045
|
onClick: () => {
|
|
1047
1046
|
engine.goToPage(idx + 1);
|
|
1048
|
-
setDocumentState({ currentPage: idx + 1 });
|
|
1049
1047
|
triggerScrollToPage(idx);
|
|
1050
1048
|
}
|
|
1051
1049
|
},
|
|
@@ -1368,7 +1366,12 @@ var import_react4 = require("react");
|
|
|
1368
1366
|
var import_core4 = require("@papyrus-sdk/core");
|
|
1369
1367
|
var import_types = require("@papyrus-sdk/types");
|
|
1370
1368
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1371
|
-
var PageRenderer = ({
|
|
1369
|
+
var PageRenderer = ({
|
|
1370
|
+
engine,
|
|
1371
|
+
pageIndex,
|
|
1372
|
+
availableWidth,
|
|
1373
|
+
onMeasuredSize
|
|
1374
|
+
}) => {
|
|
1372
1375
|
const containerRef = (0, import_react4.useRef)(null);
|
|
1373
1376
|
const canvasRef = (0, import_react4.useRef)(null);
|
|
1374
1377
|
const htmlLayerRef = (0, import_react4.useRef)(null);
|
|
@@ -1402,7 +1405,12 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1402
1405
|
} = (0, import_core4.useViewerStore)();
|
|
1403
1406
|
const renderTargetType = engine.getRenderTargetType?.() ?? "canvas";
|
|
1404
1407
|
const isElementRender = renderTargetType === "element";
|
|
1405
|
-
const textMarkupTools = /* @__PURE__ */ new Set([
|
|
1408
|
+
const textMarkupTools = /* @__PURE__ */ new Set([
|
|
1409
|
+
"highlight",
|
|
1410
|
+
"underline",
|
|
1411
|
+
"squiggly",
|
|
1412
|
+
"strikeout"
|
|
1413
|
+
]);
|
|
1406
1414
|
const canSelectText = activeTool === "select" || textMarkupTools.has(activeTool);
|
|
1407
1415
|
const hasSearchHits = (0, import_react4.useMemo)(
|
|
1408
1416
|
() => Boolean(searchQuery?.trim()) && searchResults.some((res) => res.pageIndex === pageIndex),
|
|
@@ -1478,7 +1486,11 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1478
1486
|
if (!active || !textLayerRef.current) return;
|
|
1479
1487
|
if (!isElementRender) {
|
|
1480
1488
|
textLayerRef.current.innerHTML = "";
|
|
1481
|
-
await engine.renderTextLayer(
|
|
1489
|
+
await engine.renderTextLayer(
|
|
1490
|
+
pageIndex,
|
|
1491
|
+
textLayerRef.current,
|
|
1492
|
+
textRenderScale
|
|
1493
|
+
);
|
|
1482
1494
|
}
|
|
1483
1495
|
if (!active || !textLayerRef.current) return;
|
|
1484
1496
|
if (!isElementRender && displaySize) {
|
|
@@ -1501,13 +1513,24 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1501
1513
|
return () => {
|
|
1502
1514
|
active = false;
|
|
1503
1515
|
};
|
|
1504
|
-
}, [
|
|
1516
|
+
}, [
|
|
1517
|
+
engine,
|
|
1518
|
+
pageIndex,
|
|
1519
|
+
zoom,
|
|
1520
|
+
rotation,
|
|
1521
|
+
isElementRender,
|
|
1522
|
+
fitScale,
|
|
1523
|
+
displaySize,
|
|
1524
|
+
pageSize
|
|
1525
|
+
]);
|
|
1505
1526
|
(0, import_react4.useEffect)(() => {
|
|
1506
1527
|
if (isElementRender) return;
|
|
1507
1528
|
const layer = textLayerRef.current;
|
|
1508
1529
|
if (!layer) return;
|
|
1509
1530
|
const query = searchQuery?.trim().toLowerCase();
|
|
1510
|
-
const existingMarks = Array.from(
|
|
1531
|
+
const existingMarks = Array.from(
|
|
1532
|
+
layer.querySelectorAll("mark.papyrus-search-hit")
|
|
1533
|
+
);
|
|
1511
1534
|
existingMarks.forEach((mark) => {
|
|
1512
1535
|
const parent = mark.parentNode;
|
|
1513
1536
|
if (!parent) return;
|
|
@@ -1536,7 +1559,9 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1536
1559
|
let index = lower.indexOf(query, cursor);
|
|
1537
1560
|
while (index !== -1) {
|
|
1538
1561
|
if (index > cursor) {
|
|
1539
|
-
fragment.appendChild(
|
|
1562
|
+
fragment.appendChild(
|
|
1563
|
+
document.createTextNode(text.slice(cursor, index))
|
|
1564
|
+
);
|
|
1540
1565
|
}
|
|
1541
1566
|
const mark = document.createElement("mark");
|
|
1542
1567
|
mark.className = "papyrus-search-hit";
|
|
@@ -1551,7 +1576,14 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1551
1576
|
const parent = textNode.parentNode;
|
|
1552
1577
|
if (parent) parent.replaceChild(fragment, textNode);
|
|
1553
1578
|
});
|
|
1554
|
-
}, [
|
|
1579
|
+
}, [
|
|
1580
|
+
searchQuery,
|
|
1581
|
+
hasSearchHits,
|
|
1582
|
+
pageIndex,
|
|
1583
|
+
isElementRender,
|
|
1584
|
+
activeSearchIndex,
|
|
1585
|
+
textLayerVersion
|
|
1586
|
+
]);
|
|
1555
1587
|
const handleMouseDown = (e) => {
|
|
1556
1588
|
setSelectionMenu(null);
|
|
1557
1589
|
if (activeTool === "ink") {
|
|
@@ -1642,25 +1674,41 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1642
1674
|
};
|
|
1643
1675
|
});
|
|
1644
1676
|
const uniqueRects = rects.filter((rect, index, list) => {
|
|
1645
|
-
const key = `${Math.round(rect.x * 1e4)}-${Math.round(
|
|
1646
|
-
|
|
1677
|
+
const key = `${Math.round(rect.x * 1e4)}-${Math.round(
|
|
1678
|
+
rect.y * 1e4
|
|
1679
|
+
)}-${Math.round(rect.width * 1e4)}-${Math.round(
|
|
1680
|
+
rect.height * 1e4
|
|
1681
|
+
)}`;
|
|
1682
|
+
return list.findIndex(
|
|
1683
|
+
(r) => `${Math.round(r.x * 1e4)}-${Math.round(
|
|
1684
|
+
r.y * 1e4
|
|
1685
|
+
)}-${Math.round(r.width * 1e4)}-${Math.round(
|
|
1686
|
+
r.height * 1e4
|
|
1687
|
+
)}` === key
|
|
1688
|
+
) === index;
|
|
1647
1689
|
});
|
|
1648
|
-
const mergedRects = uniqueRects.reduce(
|
|
1649
|
-
|
|
1650
|
-
const
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1690
|
+
const mergedRects = uniqueRects.reduce(
|
|
1691
|
+
(acc, rect) => {
|
|
1692
|
+
const target = acc.find((r) => {
|
|
1693
|
+
const closeY = Math.abs(r.y - rect.y) < 2e-3 && Math.abs(r.height - rect.height) < 2e-3;
|
|
1694
|
+
const overlaps = rect.x <= r.x + r.width + 2e-3 && rect.x + rect.width >= r.x - 2e-3;
|
|
1695
|
+
return closeY && overlaps;
|
|
1696
|
+
});
|
|
1697
|
+
if (!target) {
|
|
1698
|
+
acc.push({ ...rect });
|
|
1699
|
+
return acc;
|
|
1700
|
+
}
|
|
1701
|
+
const left = Math.min(target.x, rect.x);
|
|
1702
|
+
const right = Math.max(
|
|
1703
|
+
target.x + target.width,
|
|
1704
|
+
rect.x + rect.width
|
|
1705
|
+
);
|
|
1706
|
+
target.x = left;
|
|
1707
|
+
target.width = right - left;
|
|
1656
1708
|
return acc;
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
target.x = left;
|
|
1661
|
-
target.width = right - left;
|
|
1662
|
-
return acc;
|
|
1663
|
-
}, []);
|
|
1709
|
+
},
|
|
1710
|
+
[]
|
|
1711
|
+
);
|
|
1664
1712
|
if (mergedRects.length) {
|
|
1665
1713
|
const xs = mergedRects.map((r) => r.x);
|
|
1666
1714
|
const ys = mergedRects.map((r) => r.y);
|
|
@@ -1753,7 +1801,7 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1753
1801
|
"div",
|
|
1754
1802
|
{
|
|
1755
1803
|
ref: containerRef,
|
|
1756
|
-
className: `relative inline-block shadow-2xl bg-white mb-10
|
|
1804
|
+
className: `relative inline-block shadow-2xl bg-white mb-10 ${canSelectText ? "" : "no-select cursor-crosshair"}`,
|
|
1757
1805
|
style: { scrollMarginTop: "20px", minHeight: "100px" },
|
|
1758
1806
|
onMouseDown: handleMouseDown,
|
|
1759
1807
|
onMouseMove: handleMouseMove,
|
|
@@ -1764,7 +1812,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1764
1812
|
"canvas",
|
|
1765
1813
|
{
|
|
1766
1814
|
ref: canvasRef,
|
|
1767
|
-
style: {
|
|
1815
|
+
style: {
|
|
1816
|
+
filter: getPageFilter(),
|
|
1817
|
+
display: isElementRender ? "none" : "block"
|
|
1818
|
+
},
|
|
1768
1819
|
className: "block"
|
|
1769
1820
|
}
|
|
1770
1821
|
),
|
|
@@ -1773,7 +1824,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
|
|
|
1773
1824
|
{
|
|
1774
1825
|
ref: htmlLayerRef,
|
|
1775
1826
|
className: "block",
|
|
1776
|
-
style: {
|
|
1827
|
+
style: {
|
|
1828
|
+
filter: getPageFilter(),
|
|
1829
|
+
display: isElementRender ? "block" : "none"
|
|
1830
|
+
}
|
|
1777
1831
|
}
|
|
1778
1832
|
),
|
|
1779
1833
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
@@ -1964,7 +2018,17 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
|
|
|
1964
2018
|
className: "absolute inset-0",
|
|
1965
2019
|
viewBox: `${ann.rect.x} ${ann.rect.y} ${ann.rect.width} ${ann.rect.height}`,
|
|
1966
2020
|
preserveAspectRatio: "none",
|
|
1967
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2021
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2022
|
+
"path",
|
|
2023
|
+
{
|
|
2024
|
+
d,
|
|
2025
|
+
fill: "none",
|
|
2026
|
+
stroke: ann.color,
|
|
2027
|
+
strokeWidth: 8e-3,
|
|
2028
|
+
strokeLinecap: "round",
|
|
2029
|
+
strokeLinejoin: "round"
|
|
2030
|
+
}
|
|
2031
|
+
)
|
|
1968
2032
|
}
|
|
1969
2033
|
);
|
|
1970
2034
|
};
|
|
@@ -2007,7 +2071,24 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
|
|
|
2007
2071
|
onDelete();
|
|
2008
2072
|
},
|
|
2009
2073
|
className: "absolute -top-3 -right-3 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600",
|
|
2010
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2074
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2075
|
+
"svg",
|
|
2076
|
+
{
|
|
2077
|
+
className: "w-3 h-3",
|
|
2078
|
+
fill: "none",
|
|
2079
|
+
stroke: "currentColor",
|
|
2080
|
+
viewBox: "0 0 24 24",
|
|
2081
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
2082
|
+
"path",
|
|
2083
|
+
{
|
|
2084
|
+
strokeLinecap: "round",
|
|
2085
|
+
strokeLinejoin: "round",
|
|
2086
|
+
strokeWidth: 3,
|
|
2087
|
+
d: "M6 18L18 6M6 6l12 12"
|
|
2088
|
+
}
|
|
2089
|
+
)
|
|
2090
|
+
}
|
|
2091
|
+
)
|
|
2011
2092
|
}
|
|
2012
2093
|
)
|
|
2013
2094
|
]
|