@papyrus-sdk/ui-react-native 0.2.21 → 0.2.23

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Papyrus Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.mts CHANGED
@@ -11,6 +11,15 @@ interface ViewerProps {
11
11
  removeClippedSubviews?: boolean;
12
12
  useDedicatedAndroidPdfViewer?: boolean;
13
13
  viewerMode?: PdfViewerMode;
14
+ onTextSelected?: (payload: {
15
+ text: string;
16
+ pageIndex: number;
17
+ }) => void;
18
+ onDefineSelection?: (payload: {
19
+ text: string;
20
+ pageIndex: number;
21
+ }) => void;
22
+ selectionActionLabel?: string;
14
23
  }
15
24
  declare const Viewer: React.FC<ViewerProps>;
16
25
 
@@ -26,6 +35,15 @@ interface PageRendererProps {
26
35
  horizontalPadding?: number;
27
36
  spacing?: number;
28
37
  onSelectionDragActiveChange?: (active: boolean) => void;
38
+ onTextSelected?: (payload: {
39
+ text: string;
40
+ pageIndex: number;
41
+ }) => void;
42
+ onDefineSelection?: (payload: {
43
+ text: string;
44
+ pageIndex: number;
45
+ }) => void;
46
+ selectionActionLabel?: string;
29
47
  gestureScrollLockActive?: boolean;
30
48
  lastPinchEndedAt?: number | null;
31
49
  requestSelectionVerticalAutoscroll?: (absoluteY: number) => number;
@@ -101,8 +119,13 @@ declare function ReadingShell({ engine, title, documentType, thumbsInitialCount,
101
119
 
102
120
  type DedicatedAndroidPdfViewerProps = {
103
121
  engine: DocumentEngine;
122
+ onDefineSelection?: (payload: {
123
+ text: string;
124
+ pageIndex: number;
125
+ }) => void;
126
+ selectionActionLabel?: string;
104
127
  };
105
- declare function DedicatedAndroidPdfViewer({ engine, }: DedicatedAndroidPdfViewerProps): react_jsx_runtime.JSX.Element;
128
+ declare function DedicatedAndroidPdfViewer({ engine, onDefineSelection, selectionActionLabel, }: DedicatedAndroidPdfViewerProps): react_jsx_runtime.JSX.Element;
106
129
 
107
130
  type OverflowSheetProps = {
108
131
  visible: boolean;
package/dist/index.d.ts CHANGED
@@ -11,6 +11,15 @@ interface ViewerProps {
11
11
  removeClippedSubviews?: boolean;
12
12
  useDedicatedAndroidPdfViewer?: boolean;
13
13
  viewerMode?: PdfViewerMode;
14
+ onTextSelected?: (payload: {
15
+ text: string;
16
+ pageIndex: number;
17
+ }) => void;
18
+ onDefineSelection?: (payload: {
19
+ text: string;
20
+ pageIndex: number;
21
+ }) => void;
22
+ selectionActionLabel?: string;
14
23
  }
15
24
  declare const Viewer: React.FC<ViewerProps>;
16
25
 
@@ -26,6 +35,15 @@ interface PageRendererProps {
26
35
  horizontalPadding?: number;
27
36
  spacing?: number;
28
37
  onSelectionDragActiveChange?: (active: boolean) => void;
38
+ onTextSelected?: (payload: {
39
+ text: string;
40
+ pageIndex: number;
41
+ }) => void;
42
+ onDefineSelection?: (payload: {
43
+ text: string;
44
+ pageIndex: number;
45
+ }) => void;
46
+ selectionActionLabel?: string;
29
47
  gestureScrollLockActive?: boolean;
30
48
  lastPinchEndedAt?: number | null;
31
49
  requestSelectionVerticalAutoscroll?: (absoluteY: number) => number;
@@ -101,8 +119,13 @@ declare function ReadingShell({ engine, title, documentType, thumbsInitialCount,
101
119
 
102
120
  type DedicatedAndroidPdfViewerProps = {
103
121
  engine: DocumentEngine;
122
+ onDefineSelection?: (payload: {
123
+ text: string;
124
+ pageIndex: number;
125
+ }) => void;
126
+ selectionActionLabel?: string;
104
127
  };
105
- declare function DedicatedAndroidPdfViewer({ engine, }: DedicatedAndroidPdfViewerProps): react_jsx_runtime.JSX.Element;
128
+ declare function DedicatedAndroidPdfViewer({ engine, onDefineSelection, selectionActionLabel, }: DedicatedAndroidPdfViewerProps): react_jsx_runtime.JSX.Element;
106
129
 
107
130
  type OverflowSheetProps = {
108
131
  visible: boolean;
package/dist/index.js CHANGED
@@ -21632,6 +21632,7 @@ var import_react_native = require("react-native");
21632
21632
  var import_react_native_gesture_handler = require("react-native-gesture-handler");
21633
21633
  var import_react_native_svg = __toESM(require("react-native-svg"));
21634
21634
  var import_core = require("@papyrus-sdk/core");
21635
+ var import_types = require("@papyrus-sdk/types");
21635
21636
  var import_engine_native = require("@papyrus-sdk/engine-native");
21636
21637
 
21637
21638
  // perf/mobilePerf.ts
@@ -22088,6 +22089,14 @@ var resolvePdfBasePageWidth = ({
22088
22089
  horizontalPadding
22089
22090
  }) => Math.max(0, viewportWidth - horizontalPadding * 2);
22090
22091
 
22092
+ // components/selectionEvent.ts
22093
+ var notifyTextSelection = (handler, payload) => {
22094
+ const text = payload.text.replace(/\s+/g, " ").trim();
22095
+ if (!text) return false;
22096
+ handler?.({ ...payload, text });
22097
+ return Boolean(handler);
22098
+ };
22099
+
22091
22100
  // components/PageRenderer.tsx
22092
22101
  var import_jsx_runtime = require("react/jsx-runtime");
22093
22102
  var TEXT_MARKUP_TOOLS = /* @__PURE__ */ new Set([
@@ -22162,6 +22171,9 @@ var PageRenderer = ({
22162
22171
  horizontalPadding = 16,
22163
22172
  spacing = 24,
22164
22173
  onSelectionDragActiveChange,
22174
+ onTextSelected,
22175
+ onDefineSelection,
22176
+ selectionActionLabel,
22165
22177
  gestureScrollLockActive = false,
22166
22178
  lastPinchEndedAt = null,
22167
22179
  requestSelectionVerticalAutoscroll
@@ -22507,6 +22519,17 @@ var PageRenderer = ({
22507
22519
  return;
22508
22520
  }
22509
22521
  const selectedText = selection.text || "";
22522
+ const normalizedText = selectedText.replace(/\s+/g, " ").trim();
22523
+ if (normalizedText) {
22524
+ import_core.papyrusEvents.emit(import_types.PapyrusEventType.TEXT_SELECTED, {
22525
+ text: normalizedText,
22526
+ pageIndex
22527
+ });
22528
+ }
22529
+ notifyTextSelection(onTextSelected, {
22530
+ text: normalizedText,
22531
+ pageIndex
22532
+ });
22510
22533
  logSelectionPerf("selection.ready", {
22511
22534
  tool: activeTool,
22512
22535
  sourceRectCount: selection.rects.length,
@@ -23442,6 +23465,20 @@ var PageRenderer = ({
23442
23465
  }
23443
23466
  ],
23444
23467
  children: [
23468
+ onDefineSelection ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
23469
+ import_react_native.Pressable,
23470
+ {
23471
+ onPress: (event) => {
23472
+ stopPressPropagation(event);
23473
+ onDefineSelection({
23474
+ text: selectionText,
23475
+ pageIndex
23476
+ });
23477
+ },
23478
+ style: [styles.selectionAction, styles.defineSelectionAction],
23479
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: styles.defineSelectionText, children: selectionActionLabel ?? "Definir" })
23480
+ }
23481
+ ) : null,
23445
23482
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
23446
23483
  import_react_native.Pressable,
23447
23484
  {
@@ -23741,6 +23778,15 @@ var styles = import_react_native.StyleSheet.create({
23741
23778
  justifyContent: "center",
23742
23779
  marginRight: 10
23743
23780
  },
23781
+ defineSelectionAction: {
23782
+ width: 58,
23783
+ paddingHorizontal: 6
23784
+ },
23785
+ defineSelectionText: {
23786
+ color: "#FFFFFF",
23787
+ fontSize: 11,
23788
+ fontWeight: "700"
23789
+ },
23744
23790
  selectionActionLast: {
23745
23791
  marginRight: 0
23746
23792
  },
@@ -23772,7 +23818,7 @@ var styles = import_react_native.StyleSheet.create({
23772
23818
  borderRadius: 3
23773
23819
  }
23774
23820
  });
23775
- var arePageRendererPropsEqual = (previous, next) => previous.engine === next.engine && previous.pageIndex === next.pageIndex && previous.scale === next.scale && previous.PageViewComponent === next.PageViewComponent && previous.availableWidth === next.availableWidth && previous.pageViewportWidth === next.pageViewportWidth && previous.horizontalPadding === next.horizontalPadding && previous.spacing === next.spacing && previous.onSelectionDragActiveChange === next.onSelectionDragActiveChange && previous.gestureScrollLockActive === next.gestureScrollLockActive && previous.lastPinchEndedAt === next.lastPinchEndedAt && previous.requestSelectionVerticalAutoscroll === next.requestSelectionVerticalAutoscroll;
23821
+ var arePageRendererPropsEqual = (previous, next) => previous.engine === next.engine && previous.pageIndex === next.pageIndex && previous.scale === next.scale && previous.PageViewComponent === next.PageViewComponent && previous.availableWidth === next.availableWidth && previous.pageViewportWidth === next.pageViewportWidth && previous.horizontalPadding === next.horizontalPadding && previous.spacing === next.spacing && previous.onSelectionDragActiveChange === next.onSelectionDragActiveChange && previous.onTextSelected === next.onTextSelected && previous.onDefineSelection === next.onDefineSelection && previous.selectionActionLabel === next.selectionActionLabel && previous.gestureScrollLockActive === next.gestureScrollLockActive && previous.lastPinchEndedAt === next.lastPinchEndedAt && previous.requestSelectionVerticalAutoscroll === next.requestSelectionVerticalAutoscroll;
23776
23822
  var PageRenderer_default = (0, import_react.memo)(PageRenderer, arePageRendererPropsEqual);
23777
23823
 
23778
23824
  // components/WebViewViewer.tsx
@@ -24601,6 +24647,11 @@ var IconCommentBubble = ({
24601
24647
  /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_native_svg2.Circle, { cx: "15", cy: "11", r: "1", fill: color })
24602
24648
  ] });
24603
24649
 
24650
+ // components/selectionToolbarModel.ts
24651
+ var getSelectionToolbarActions = (label = "Definir") => [
24652
+ { id: "dictionary", label }
24653
+ ];
24654
+
24604
24655
  // components/DedicatedAndroidPdfViewer.tsx
24605
24656
  var import_jsx_runtime4 = require("react/jsx-runtime");
24606
24657
  var TEXT_MARKUP_TOOLS2 = /* @__PURE__ */ new Set(["highlight", "underline", "squiggly", "strikeout"]);
@@ -24613,7 +24664,9 @@ var getDedicatedAndroidPdfEngineId = (engine) => {
24613
24664
  return typeof engineId === "string" && engineId.length > 0 ? engineId : null;
24614
24665
  };
24615
24666
  function DedicatedAndroidPdfViewer({
24616
- engine
24667
+ engine,
24668
+ onDefineSelection,
24669
+ selectionActionLabel
24617
24670
  }) {
24618
24671
  const pageTheme = (0, import_core3.useViewerStore)((state) => state.pageTheme);
24619
24672
  const zoom = (0, import_core3.useViewerStore)((state) => state.zoom);
@@ -24796,6 +24849,27 @@ function DedicatedAndroidPdfViewer({
24796
24849
  }
24797
24850
  ),
24798
24851
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.View, { style: styles3.selectionToolbar, pointerEvents: "box-none", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react_native3.View, { style: styles3.toolbarContent, children: [
24852
+ onDefineSelection && getSelectionToolbarActions(selectionActionLabel).map((action) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
24853
+ import_react_native3.Pressable,
24854
+ {
24855
+ accessibilityRole: "button",
24856
+ accessibilityLabel: action.label,
24857
+ onPress: () => {
24858
+ const currentSelection = selectionRef.current;
24859
+ if (!currentSelection) return;
24860
+ onDefineSelection({
24861
+ text: currentSelection.text,
24862
+ pageIndex: currentSelection.pageIndex
24863
+ });
24864
+ },
24865
+ style: [styles3.toolbarButton, styles3.dictionaryButton],
24866
+ children: [
24867
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(IconInfo, { size: 16, color: "#fff" }),
24868
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_native3.Text, { style: styles3.toolbarButtonText, children: action.label })
24869
+ ]
24870
+ },
24871
+ action.id
24872
+ )),
24799
24873
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
24800
24874
  import_react_native3.Pressable,
24801
24875
  {
@@ -24877,6 +24951,11 @@ var styles3 = import_react_native3.StyleSheet.create({
24877
24951
  alignItems: "center",
24878
24952
  justifyContent: "center"
24879
24953
  },
24954
+ dictionaryButton: {
24955
+ width: 118,
24956
+ flexDirection: "row",
24957
+ gap: 6
24958
+ },
24880
24959
  overlay: {
24881
24960
  ...import_react_native3.StyleSheet.absoluteFillObject,
24882
24961
  zIndex: 40
@@ -24926,7 +25005,10 @@ var Viewer = ({
24926
25005
  maxToRenderPerBatch,
24927
25006
  removeClippedSubviews,
24928
25007
  useDedicatedAndroidPdfViewer,
24929
- viewerMode
25008
+ viewerMode,
25009
+ onTextSelected,
25010
+ onDefineSelection,
25011
+ selectionActionLabel
24930
25012
  }) => {
24931
25013
  const pageCount = (0, import_core4.useViewerStore)((state) => state.pageCount);
24932
25014
  const currentPage = (0, import_core4.useViewerStore)((state) => state.currentPage);
@@ -26062,6 +26144,9 @@ var Viewer = ({
26062
26144
  pageViewportWidth: columnWidth,
26063
26145
  spacing: DOUBLE_PAGE_SPACING,
26064
26146
  onSelectionDragActiveChange: setSelectionDragActive,
26147
+ onTextSelected,
26148
+ onDefineSelection,
26149
+ selectionActionLabel,
26065
26150
  gestureScrollLockActive,
26066
26151
  lastPinchEndedAt,
26067
26152
  requestSelectionVerticalAutoscroll: handleSelectionVerticalAutoscroll
@@ -26078,6 +26163,9 @@ var Viewer = ({
26078
26163
  pageViewportWidth: columnWidth,
26079
26164
  spacing: DOUBLE_PAGE_SPACING,
26080
26165
  onSelectionDragActiveChange: setSelectionDragActive,
26166
+ onTextSelected,
26167
+ onDefineSelection,
26168
+ selectionActionLabel,
26081
26169
  gestureScrollLockActive,
26082
26170
  lastPinchEndedAt,
26083
26171
  requestSelectionVerticalAutoscroll: handleSelectionVerticalAutoscroll
@@ -26097,6 +26185,9 @@ var Viewer = ({
26097
26185
  pageViewportWidth: documentSurfaceWidth,
26098
26186
  spacing: CONTINUOUS_PAGE_SPACING,
26099
26187
  onSelectionDragActiveChange: setSelectionDragActive,
26188
+ onTextSelected,
26189
+ onDefineSelection,
26190
+ selectionActionLabel,
26100
26191
  gestureScrollLockActive,
26101
26192
  lastPinchEndedAt,
26102
26193
  requestSelectionVerticalAutoscroll: handleSelectionVerticalAutoscroll
@@ -26120,7 +26211,14 @@ var Viewer = ({
26120
26211
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native4.View, { style: [styles4.container, isDark && styles4.containerDark], children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(WebViewViewer_default, { engine }) });
26121
26212
  }
26122
26213
  if (isNativePdfViewer) {
26123
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native4.View, { style: [styles4.container, isDark && styles4.containerDark], children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DedicatedAndroidPdfViewer, { engine }) });
26214
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native4.View, { style: [styles4.container, isDark && styles4.containerDark], children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
26215
+ DedicatedAndroidPdfViewer,
26216
+ {
26217
+ engine,
26218
+ onDefineSelection,
26219
+ selectionActionLabel
26220
+ }
26221
+ ) });
26124
26222
  }
26125
26223
  if (isSingle) {
26126
26224
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native4.View, { style: [styles4.container, isDark && styles4.containerDark], children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_native_gesture_handler2.GestureDetector, { gesture: viewerPinchGesture, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
@@ -26186,6 +26284,9 @@ var Viewer = ({
26186
26284
  pageViewportWidth: documentSurfaceWidth,
26187
26285
  spacing: 32,
26188
26286
  onSelectionDragActiveChange: setSelectionDragActive,
26287
+ onTextSelected,
26288
+ onDefineSelection,
26289
+ selectionActionLabel,
26189
26290
  gestureScrollLockActive,
26190
26291
  lastPinchEndedAt,
26191
26292
  requestSelectionVerticalAutoscroll: handleSelectionVerticalAutoscroll