@papyrus-sdk/ui-react 0.2.12 → 0.2.15

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.mjs CHANGED
@@ -422,7 +422,7 @@ var Topbar = ({
422
422
  title && /* @__PURE__ */ jsx(
423
423
  "span",
424
424
  {
425
- 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"}`,
426
426
  title: typeof title === "string" ? title : void 0,
427
427
  children: title
428
428
  }
@@ -1335,9 +1335,16 @@ import { useViewerStore as useViewerStore5 } from "@papyrus-sdk/core";
1335
1335
  // components/PageRenderer.tsx
1336
1336
  import { useEffect as useEffect3, useMemo, useRef as useRef3, useState as useState4 } from "react";
1337
1337
  import { useViewerStore as useViewerStore4, papyrusEvents } from "@papyrus-sdk/core";
1338
- import { PapyrusEventType } from "@papyrus-sdk/types";
1338
+ import {
1339
+ PapyrusEventType
1340
+ } from "@papyrus-sdk/types";
1339
1341
  import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
1340
- var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1342
+ var PageRenderer = ({
1343
+ engine,
1344
+ pageIndex,
1345
+ availableWidth,
1346
+ onMeasuredSize
1347
+ }) => {
1341
1348
  const containerRef = useRef3(null);
1342
1349
  const canvasRef = useRef3(null);
1343
1350
  const htmlLayerRef = useRef3(null);
@@ -1371,7 +1378,12 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1371
1378
  } = useViewerStore4();
1372
1379
  const renderTargetType = engine.getRenderTargetType?.() ?? "canvas";
1373
1380
  const isElementRender = renderTargetType === "element";
1374
- const textMarkupTools = /* @__PURE__ */ new Set(["highlight", "underline", "squiggly", "strikeout"]);
1381
+ const textMarkupTools = /* @__PURE__ */ new Set([
1382
+ "highlight",
1383
+ "underline",
1384
+ "squiggly",
1385
+ "strikeout"
1386
+ ]);
1375
1387
  const canSelectText = activeTool === "select" || textMarkupTools.has(activeTool);
1376
1388
  const hasSearchHits = useMemo(
1377
1389
  () => Boolean(searchQuery?.trim()) && searchResults.some((res) => res.pageIndex === pageIndex),
@@ -1447,7 +1459,11 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1447
1459
  if (!active || !textLayerRef.current) return;
1448
1460
  if (!isElementRender) {
1449
1461
  textLayerRef.current.innerHTML = "";
1450
- await engine.renderTextLayer(pageIndex, textLayerRef.current, textRenderScale);
1462
+ await engine.renderTextLayer(
1463
+ pageIndex,
1464
+ textLayerRef.current,
1465
+ textRenderScale
1466
+ );
1451
1467
  }
1452
1468
  if (!active || !textLayerRef.current) return;
1453
1469
  if (!isElementRender && displaySize) {
@@ -1470,13 +1486,24 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1470
1486
  return () => {
1471
1487
  active = false;
1472
1488
  };
1473
- }, [engine, pageIndex, zoom, rotation, isElementRender, fitScale, displaySize, pageSize]);
1489
+ }, [
1490
+ engine,
1491
+ pageIndex,
1492
+ zoom,
1493
+ rotation,
1494
+ isElementRender,
1495
+ fitScale,
1496
+ displaySize,
1497
+ pageSize
1498
+ ]);
1474
1499
  useEffect3(() => {
1475
1500
  if (isElementRender) return;
1476
1501
  const layer = textLayerRef.current;
1477
1502
  if (!layer) return;
1478
1503
  const query = searchQuery?.trim().toLowerCase();
1479
- const existingMarks = Array.from(layer.querySelectorAll("mark.papyrus-search-hit"));
1504
+ const existingMarks = Array.from(
1505
+ layer.querySelectorAll("mark.papyrus-search-hit")
1506
+ );
1480
1507
  existingMarks.forEach((mark) => {
1481
1508
  const parent = mark.parentNode;
1482
1509
  if (!parent) return;
@@ -1505,7 +1532,9 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1505
1532
  let index = lower.indexOf(query, cursor);
1506
1533
  while (index !== -1) {
1507
1534
  if (index > cursor) {
1508
- fragment.appendChild(document.createTextNode(text.slice(cursor, index)));
1535
+ fragment.appendChild(
1536
+ document.createTextNode(text.slice(cursor, index))
1537
+ );
1509
1538
  }
1510
1539
  const mark = document.createElement("mark");
1511
1540
  mark.className = "papyrus-search-hit";
@@ -1520,7 +1549,14 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1520
1549
  const parent = textNode.parentNode;
1521
1550
  if (parent) parent.replaceChild(fragment, textNode);
1522
1551
  });
1523
- }, [searchQuery, hasSearchHits, pageIndex, isElementRender, activeSearchIndex, textLayerVersion]);
1552
+ }, [
1553
+ searchQuery,
1554
+ hasSearchHits,
1555
+ pageIndex,
1556
+ isElementRender,
1557
+ activeSearchIndex,
1558
+ textLayerVersion
1559
+ ]);
1524
1560
  const handleMouseDown = (e) => {
1525
1561
  setSelectionMenu(null);
1526
1562
  if (activeTool === "ink") {
@@ -1611,25 +1647,41 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1611
1647
  };
1612
1648
  });
1613
1649
  const uniqueRects = rects.filter((rect, index, list) => {
1614
- const key = `${Math.round(rect.x * 1e4)}-${Math.round(rect.y * 1e4)}-${Math.round(rect.width * 1e4)}-${Math.round(rect.height * 1e4)}`;
1615
- 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;
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;
1616
1662
  });
1617
- const mergedRects = uniqueRects.reduce((acc, rect) => {
1618
- const target = acc.find((r) => {
1619
- const closeY = Math.abs(r.y - rect.y) < 2e-3 && Math.abs(r.height - rect.height) < 2e-3;
1620
- const overlaps = rect.x <= r.x + r.width + 2e-3 && rect.x + rect.width >= r.x - 2e-3;
1621
- return closeY && overlaps;
1622
- });
1623
- if (!target) {
1624
- acc.push({ ...rect });
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;
1625
1681
  return acc;
1626
- }
1627
- const left = Math.min(target.x, rect.x);
1628
- const right = Math.max(target.x + target.width, rect.x + rect.width);
1629
- target.x = left;
1630
- target.width = right - left;
1631
- return acc;
1632
- }, []);
1682
+ },
1683
+ []
1684
+ );
1633
1685
  if (mergedRects.length) {
1634
1686
  const xs = mergedRects.map((r) => r.x);
1635
1687
  const ys = mergedRects.map((r) => r.y);
@@ -1722,7 +1774,7 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1722
1774
  "div",
1723
1775
  {
1724
1776
  ref: containerRef,
1725
- className: `relative inline-block shadow-2xl bg-white mb-10 transition-all ${canSelectText ? "" : "no-select cursor-crosshair"}`,
1777
+ className: `relative inline-block shadow-2xl bg-white mb-10 ${canSelectText ? "" : "no-select cursor-crosshair"}`,
1726
1778
  style: { scrollMarginTop: "20px", minHeight: "100px" },
1727
1779
  onMouseDown: handleMouseDown,
1728
1780
  onMouseMove: handleMouseMove,
@@ -1733,7 +1785,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1733
1785
  "canvas",
1734
1786
  {
1735
1787
  ref: canvasRef,
1736
- style: { filter: getPageFilter(), display: isElementRender ? "none" : "block" },
1788
+ style: {
1789
+ filter: getPageFilter(),
1790
+ display: isElementRender ? "none" : "block"
1791
+ },
1737
1792
  className: "block"
1738
1793
  }
1739
1794
  ),
@@ -1742,7 +1797,10 @@ var PageRenderer = ({ engine, pageIndex, availableWidth, onMeasuredSize }) => {
1742
1797
  {
1743
1798
  ref: htmlLayerRef,
1744
1799
  className: "block",
1745
- style: { filter: getPageFilter(), display: isElementRender ? "block" : "none" }
1800
+ style: {
1801
+ filter: getPageFilter(),
1802
+ display: isElementRender ? "block" : "none"
1803
+ }
1746
1804
  }
1747
1805
  ),
1748
1806
  /* @__PURE__ */ jsx4(
@@ -1933,7 +1991,17 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
1933
1991
  className: "absolute inset-0",
1934
1992
  viewBox: `${ann.rect.x} ${ann.rect.y} ${ann.rect.width} ${ann.rect.height}`,
1935
1993
  preserveAspectRatio: "none",
1936
- children: /* @__PURE__ */ jsx4("path", { d, fill: "none", stroke: ann.color, strokeWidth: 8e-3, strokeLinecap: "round", strokeLinejoin: "round" })
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
+ )
1937
2005
  }
1938
2006
  );
1939
2007
  };
@@ -1976,7 +2044,24 @@ var AnnotationItem = ({ ann, isSelected, accentColor, onDelete, onSelect }) => {
1976
2044
  onDelete();
1977
2045
  },
1978
2046
  className: "absolute -top-3 -right-3 bg-red-500 text-white rounded-full p-1 shadow-lg hover:bg-red-600",
1979
- children: /* @__PURE__ */ jsx4("svg", { className: "w-3 h-3", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx4("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 3, d: "M6 18L18 6M6 6l12 12" }) })
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
+ )
1980
2065
  }
1981
2066
  )
1982
2067
  ]