@papyrus-sdk/ui-react 0.2.12 → 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 CHANGED
@@ -451,7 +451,7 @@ var Topbar = ({
451
451
  title && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
452
452
  "span",
453
453
  {
454
- 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"}`,
455
455
  title: typeof title === "string" ? title : void 0,
456
456
  children: title
457
457
  }
@@ -1366,7 +1366,12 @@ var import_react4 = require("react");
1366
1366
  var import_core4 = require("@papyrus-sdk/core");
1367
1367
  var import_types = require("@papyrus-sdk/types");
1368
1368
  var import_jsx_runtime4 = require("react/jsx-runtime");
1369
- var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1369
+ var PageRenderer = ({
1370
+ engine,
1371
+ pageIndex,
1372
+ availableWidth,
1373
+ onMeasuredSize
1374
+ }) => {
1370
1375
  const containerRef = (0, import_react4.useRef)(null);
1371
1376
  const canvasRef = (0, import_react4.useRef)(null);
1372
1377
  const htmlLayerRef = (0, import_react4.useRef)(null);
@@ -1400,7 +1405,12 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1400
1405
  } = (0, import_core4.useViewerStore)();
1401
1406
  const renderTargetType = engine.getRenderTargetType?.() ?? "canvas";
1402
1407
  const isElementRender = renderTargetType === "element";
1403
- const textMarkupTools = /* @__PURE__ */ new Set(["highlight", "underline", "squiggly", "strikeout"]);
1408
+ const textMarkupTools = /* @__PURE__ */ new Set([
1409
+ "highlight",
1410
+ "underline",
1411
+ "squiggly",
1412
+ "strikeout"
1413
+ ]);
1404
1414
  const canSelectText = activeTool === "select" || textMarkupTools.has(activeTool);
1405
1415
  const hasSearchHits = (0, import_react4.useMemo)(
1406
1416
  () => Boolean(searchQuery?.trim()) && searchResults.some((res) => res.pageIndex === pageIndex),
@@ -1476,7 +1486,11 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1476
1486
  if (!active || !textLayerRef.current) return;
1477
1487
  if (!isElementRender) {
1478
1488
  textLayerRef.current.innerHTML = "";
1479
- await engine.renderTextLayer(pageIndex, textLayerRef.current, textRenderScale);
1489
+ await engine.renderTextLayer(
1490
+ pageIndex,
1491
+ textLayerRef.current,
1492
+ textRenderScale
1493
+ );
1480
1494
  }
1481
1495
  if (!active || !textLayerRef.current) return;
1482
1496
  if (!isElementRender && displaySize) {
@@ -1499,13 +1513,24 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1499
1513
  return () => {
1500
1514
  active = false;
1501
1515
  };
1502
- }, [engine, pageIndex, zoom, rotation, isElementRender, fitScale, displaySize, pageSize]);
1516
+ }, [
1517
+ engine,
1518
+ pageIndex,
1519
+ zoom,
1520
+ rotation,
1521
+ isElementRender,
1522
+ fitScale,
1523
+ displaySize,
1524
+ pageSize
1525
+ ]);
1503
1526
  (0, import_react4.useEffect)(() => {
1504
1527
  if (isElementRender) return;
1505
1528
  const layer = textLayerRef.current;
1506
1529
  if (!layer) return;
1507
1530
  const query = searchQuery?.trim().toLowerCase();
1508
- const existingMarks = Array.from(layer.querySelectorAll("mark.papyrus-search-hit"));
1531
+ const existingMarks = Array.from(
1532
+ layer.querySelectorAll("mark.papyrus-search-hit")
1533
+ );
1509
1534
  existingMarks.forEach((mark) => {
1510
1535
  const parent = mark.parentNode;
1511
1536
  if (!parent) return;
@@ -1534,7 +1559,9 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1534
1559
  let index = lower.indexOf(query, cursor);
1535
1560
  while (index !== -1) {
1536
1561
  if (index > cursor) {
1537
- fragment.appendChild(document.createTextNode(text.slice(cursor, index)));
1562
+ fragment.appendChild(
1563
+ document.createTextNode(text.slice(cursor, index))
1564
+ );
1538
1565
  }
1539
1566
  const mark = document.createElement("mark");
1540
1567
  mark.className = "papyrus-search-hit";
@@ -1549,7 +1576,14 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1549
1576
  const parent = textNode.parentNode;
1550
1577
  if (parent) parent.replaceChild(fragment, textNode);
1551
1578
  });
1552
- }, [searchQuery, hasSearchHits, pageIndex, isElementRender, activeSearchIndex, textLayerVersion]);
1579
+ }, [
1580
+ searchQuery,
1581
+ hasSearchHits,
1582
+ pageIndex,
1583
+ isElementRender,
1584
+ activeSearchIndex,
1585
+ textLayerVersion
1586
+ ]);
1553
1587
  const handleMouseDown = (e) => {
1554
1588
  setSelectionMenu(null);
1555
1589
  if (activeTool === "ink") {
@@ -1640,25 +1674,41 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1640
1674
  };
1641
1675
  });
1642
1676
  const uniqueRects = rects.filter((rect, index, list) => {
1643
- const key = `${Math.round(rect.x * 1e4)}-${Math.round(rect.y * 1e4)}-${Math.round(rect.width * 1e4)}-${Math.round(rect.height * 1e4)}`;
1644
- return list.findIndex((r) => `${Math.round(r.x * 1e4)}-${Math.round(r.y * 1e4)}-${Math.round(r.width * 1e4)}-${Math.round(r.height * 1e4)}` === key) === index;
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;
1645
1689
  });
1646
- const mergedRects = uniqueRects.reduce((acc, rect) => {
1647
- const target = acc.find((r) => {
1648
- const closeY = Math.abs(r.y - rect.y) < 2e-3 && Math.abs(r.height - rect.height) < 2e-3;
1649
- const overlaps = rect.x <= r.x + r.width + 2e-3 && rect.x + rect.width >= r.x - 2e-3;
1650
- return closeY && overlaps;
1651
- });
1652
- if (!target) {
1653
- acc.push({ ...rect });
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;
1654
1708
  return acc;
1655
- }
1656
- const left = Math.min(target.x, rect.x);
1657
- const right = Math.max(target.x + target.width, rect.x + rect.width);
1658
- target.x = left;
1659
- target.width = right - left;
1660
- return acc;
1661
- }, []);
1709
+ },
1710
+ []
1711
+ );
1662
1712
  if (mergedRects.length) {
1663
1713
  const xs = mergedRects.map((r) => r.x);
1664
1714
  const ys = mergedRects.map((r) => r.y);
@@ -1751,7 +1801,7 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1751
1801
  "div",
1752
1802
  {
1753
1803
  ref: containerRef,
1754
- className: `relative inline-block shadow-2xl bg-white mb-10 transition-all ${canSelectText ? "" : "no-select cursor-crosshair"}`,
1804
+ className: `relative inline-block shadow-2xl bg-white mb-10 ${canSelectText ? "" : "no-select cursor-crosshair"}`,
1755
1805
  style: { scrollMarginTop: "20px", minHeight: "100px" },
1756
1806
  onMouseDown: handleMouseDown,
1757
1807
  onMouseMove: handleMouseMove,
@@ -1762,7 +1812,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1762
1812
  "canvas",
1763
1813
  {
1764
1814
  ref: canvasRef,
1765
- style: { filter: getPageFilter(), display: isElementRender ? "none" : "block" },
1815
+ style: {
1816
+ filter: getPageFilter(),
1817
+ display: isElementRender ? "none" : "block"
1818
+ },
1766
1819
  className: "block"
1767
1820
  }
1768
1821
  ),
@@ -1771,7 +1824,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1771
1824
  {
1772
1825
  ref: htmlLayerRef,
1773
1826
  className: "block",
1774
- style: { filter: getPageFilter(), display: isElementRender ? "block" : "none" }
1827
+ style: {
1828
+ filter: getPageFilter(),
1829
+ display: isElementRender ? "block" : "none"
1830
+ }
1775
1831
  }
1776
1832
  ),
1777
1833
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
@@ -1962,7 +2018,17 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
1962
2018
  className: "absolute inset-0",
1963
2019
  viewBox: `${ann.rect.x} ${ann.rect.y} ${ann.rect.width} ${ann.rect.height}`,
1964
2020
  preserveAspectRatio: "none",
1965
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d, fill: "none", stroke: ann.color, strokeWidth: 8e-3, strokeLinecap: "round", strokeLinejoin: "round" })
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
+ )
1966
2032
  }
1967
2033
  );
1968
2034
  };
@@ -2005,7 +2071,24 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
2005
2071
  onDelete();
2006
2072
  },
2007
2073
  className: "absolute -top-3 -right-3 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600",
2008
- 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" }) })
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
+ )
2009
2092
  }
2010
2093
  )
2011
2094
  ]