@tobyt/expo-pdf-markup 0.3.1 โ 0.5.0
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/CHANGELOG.md +20 -0
- package/README.md +7 -5
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/ContinuousPdfView.kt +6 -2
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupModule.kt +16 -1
- package/android/src/main/java/dev/terhoeven/expopdfmarkup/ExpoPdfMarkupView.kt +28 -3
- package/build/ExpoPdfMarkup.types.d.ts +8 -0
- package/build/ExpoPdfMarkup.types.d.ts.map +1 -1
- package/build/ExpoPdfMarkup.types.js.map +1 -1
- package/build/ExpoPdfMarkupView.d.ts +1 -1
- package/build/ExpoPdfMarkupView.d.ts.map +1 -1
- package/build/ExpoPdfMarkupView.js +15 -3
- package/build/ExpoPdfMarkupView.js.map +1 -1
- package/build/ExpoPdfMarkupView.web.d.ts.map +1 -1
- package/build/ExpoPdfMarkupView.web.js +104 -12
- package/build/ExpoPdfMarkupView.web.js.map +1 -1
- package/build/pdfjs.d.ts.map +1 -1
- package/build/pdfjs.js +0 -1
- package/build/pdfjs.js.map +1 -1
- package/ios/ExpoPdfMarkupModule.swift +12 -1
- package/ios/ExpoPdfMarkupView.swift +28 -1
- package/metro.js +6 -8
- package/package.json +1 -1
- package/src/ExpoPdfMarkup.types.ts +9 -1
- package/src/ExpoPdfMarkupView.tsx +34 -4
- package/src/ExpoPdfMarkupView.web.tsx +128 -27
- package/src/pdfjs.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @tobyt/expo-pdf-markup
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 049130a: Example app is now deployed to Github Pages
|
|
8
|
+
- 049130a: Default pdfjs worker source for web implementation is now relative
|
|
9
|
+
- e62d562: Support optionally rendering text input prompt on JavaScript side
|
|
10
|
+
|
|
11
|
+
## 0.4.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 519e27b: Update metro config plugin so it works in a monorepo too
|
|
16
|
+
- 4898177: The onPageChanged event now returns page width and height.
|
|
17
|
+
- 5423941: When using gestures to zoom on Web, only the PDF is zoomed in/out instead of the entire UI.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- f15901a: Move spacer in Web implementation so it only appears inbetween pages
|
|
22
|
+
|
|
3
23
|
## 0.3.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
An Expo module for displaying and annotating PDFs, with support for iOS, Android, and Web.
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
**[๐ API Reference](https://tobyt42.github.io/expo-pdf-markup/api/)** ยท **[๐ Example App](https://tobyt42.github.io/expo-pdf-markup/example/)**
|
|
11
|
+
|
|
12
|
+
> **Status:** Early development โ actively tested in the [Choir](https://www.thechoirapp.com) app.
|
|
11
13
|
|
|
12
14
|
## Platform support
|
|
13
15
|
|
|
@@ -50,7 +52,7 @@ module.exports = withPdfMarkup(config);
|
|
|
50
52
|
`withPdfMarkup` does two things automatically:
|
|
51
53
|
|
|
52
54
|
1. **Patches `import.meta`** in pdfjs-dist so Metro can bundle it (pdfjs-dist v4 uses ESM syntax in a Node.js-only code path that is otherwise unreachable in a browser).
|
|
53
|
-
2. **Copies the pdfjs worker** to `public/pdf.worker.min.mjs` in your project root so it is served
|
|
55
|
+
2. **Copies the pdfjs worker** to `public/pdf.worker.min.mjs` in your project root so it is served alongside your app (same-origin, no CORS issues). The default worker URL is `./pdf.worker.min.mjs` (relative to the page), so it works whether your app is hosted at the root or a sub-path.
|
|
54
56
|
|
|
55
57
|
The `public/pdf.worker.min.mjs` file is regenerated on each Metro start if missing, so you can add it to `.gitignore`:
|
|
56
58
|
|
|
@@ -79,7 +81,7 @@ setPdfPath(asset.localUri.replace('file://', ''));
|
|
|
79
81
|
|
|
80
82
|
## Usage
|
|
81
83
|
|
|
82
|
-
Full API reference is available at **[tobyt42.github.io/expo-pdf-markup](https://tobyt42.github.io/expo-pdf-markup/types/ExpoPdfMarkupViewProps.html)**.
|
|
84
|
+
Full API reference is available at **[tobyt42.github.io/expo-pdf-markup](https://tobyt42.github.io/expo-pdf-markup/api/types/ExpoPdfMarkupViewProps.html)**.
|
|
83
85
|
|
|
84
86
|
```tsx
|
|
85
87
|
import { ExpoPdfMarkupView } from '@tobyt/expo-pdf-markup';
|
|
@@ -112,8 +114,8 @@ export default function App() {
|
|
|
112
114
|
annotationLineWidth={3}
|
|
113
115
|
annotations={annotations}
|
|
114
116
|
onLoadComplete={({ nativeEvent: { pageCount } }) => console.log(`Loaded ${pageCount} pages`)}
|
|
115
|
-
onPageChanged={({ nativeEvent: { page, pageCount } }) =>
|
|
116
|
-
console.log(`Page ${page + 1} of ${pageCount}`)
|
|
117
|
+
onPageChanged={({ nativeEvent: { page, pageCount, pageWidth, pageHeight } }) =>
|
|
118
|
+
console.log(`Page ${page + 1} of ${pageCount} (${pageWidth}ร${pageHeight}pt)`)
|
|
117
119
|
}
|
|
118
120
|
onAnnotationsChanged={({ nativeEvent }) => setAnnotations(nativeEvent.annotations)}
|
|
119
121
|
onError={({ nativeEvent: { message } }) => console.error(message)}
|
|
@@ -38,7 +38,9 @@ class ContinuousPdfView(context: Context) : View(context) {
|
|
|
38
38
|
private val scaleDetector = ScaleGestureDetector(context, ScaleListener())
|
|
39
39
|
private val gestureDetector = GestureDetector(context, GestureListener())
|
|
40
40
|
|
|
41
|
-
var onPageChangeListener: (
|
|
41
|
+
var onPageChangeListener: (
|
|
42
|
+
(page: Int, pageCount: Int, pageWidth: Int, pageHeight: Int) -> Unit
|
|
43
|
+
)? = null
|
|
42
44
|
|
|
43
45
|
// Annotation state
|
|
44
46
|
var annotations: List<AnnotationModel> = emptyList()
|
|
@@ -466,7 +468,9 @@ class ContinuousPdfView(context: Context) : View(context) {
|
|
|
466
468
|
val page = getVisiblePage()
|
|
467
469
|
if (page != lastNotifiedPage) {
|
|
468
470
|
lastNotifiedPage = page
|
|
469
|
-
|
|
471
|
+
val pw = if (page < pageWidths.size) pageWidths[page] else 0
|
|
472
|
+
val ph = if (page < pageHeights.size) pageHeights[page] else 0
|
|
473
|
+
onPageChangeListener?.invoke(page, pageBitmaps.size, pw, ph)
|
|
470
474
|
}
|
|
471
475
|
}
|
|
472
476
|
|
|
@@ -46,6 +46,11 @@ class ExpoPdfMarkupModule : Module() {
|
|
|
46
46
|
override fun definition() = ModuleDefinition {
|
|
47
47
|
Name("ExpoPdfMarkup")
|
|
48
48
|
|
|
49
|
+
AsyncFunction("provideTextInput") { viewTag: Int, text: String? ->
|
|
50
|
+
val view = appContext.findView<ExpoPdfMarkupView>(viewTag)
|
|
51
|
+
view?.provideTextInput(text)
|
|
52
|
+
}
|
|
53
|
+
|
|
49
54
|
View(ExpoPdfMarkupView::class) {
|
|
50
55
|
Prop("source") { view: ExpoPdfMarkupView, source: String ->
|
|
51
56
|
view.loadPdf(source)
|
|
@@ -75,7 +80,17 @@ class ExpoPdfMarkupModule : Module() {
|
|
|
75
80
|
view.setAnnotationLineWidth(width)
|
|
76
81
|
}
|
|
77
82
|
|
|
78
|
-
|
|
83
|
+
Prop("useJsTextDialog") { view: ExpoPdfMarkupView, use: Boolean? ->
|
|
84
|
+
view.useJsTextDialog = use ?: false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
Events(
|
|
88
|
+
"onPageChanged",
|
|
89
|
+
"onLoadComplete",
|
|
90
|
+
"onError",
|
|
91
|
+
"onAnnotationsChanged",
|
|
92
|
+
"onTextInputRequested"
|
|
93
|
+
)
|
|
79
94
|
}
|
|
80
95
|
}
|
|
81
96
|
}
|
|
@@ -19,22 +19,40 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
19
19
|
private val onLoadComplete by EventDispatcher()
|
|
20
20
|
private val onError by EventDispatcher()
|
|
21
21
|
private val onAnnotationsChanged by EventDispatcher()
|
|
22
|
+
private val onTextInputRequested by EventDispatcher()
|
|
22
23
|
|
|
23
24
|
private var renderer: PdfRenderer? = null
|
|
24
25
|
private var fileDescriptor: ParcelFileDescriptor? = null
|
|
25
26
|
private var currentSource: String? = null
|
|
26
27
|
private var pendingAnnotationsJson: String? = null
|
|
28
|
+
var useJsTextDialog: Boolean = false
|
|
29
|
+
|
|
30
|
+
private var pendingTextPage: Int = -1
|
|
31
|
+
private var pendingTextPoint: AnnotationPoint? = null
|
|
27
32
|
|
|
28
33
|
init {
|
|
29
34
|
addView(pdfView)
|
|
30
|
-
pdfView.onPageChangeListener = { page, pageCount ->
|
|
31
|
-
onPageChanged(
|
|
35
|
+
pdfView.onPageChangeListener = { page, pageCount, pageWidth, pageHeight ->
|
|
36
|
+
onPageChanged(
|
|
37
|
+
mapOf(
|
|
38
|
+
"page" to page,
|
|
39
|
+
"pageCount" to pageCount,
|
|
40
|
+
"pageWidth" to pageWidth,
|
|
41
|
+
"pageHeight" to pageHeight
|
|
42
|
+
)
|
|
43
|
+
)
|
|
32
44
|
}
|
|
33
45
|
pdfView.onAnnotationsChangedListener = {
|
|
34
46
|
emitAnnotationsChanged()
|
|
35
47
|
}
|
|
36
48
|
pdfView.onTextInputRequested = { page, point ->
|
|
37
|
-
|
|
49
|
+
if (useJsTextDialog) {
|
|
50
|
+
pendingTextPage = page
|
|
51
|
+
pendingTextPoint = point
|
|
52
|
+
onTextInputRequested(emptyMap<String, Any>())
|
|
53
|
+
} else {
|
|
54
|
+
showTextInputDialog(page, point)
|
|
55
|
+
}
|
|
38
56
|
}
|
|
39
57
|
}
|
|
40
58
|
|
|
@@ -107,6 +125,13 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
|
|
|
107
125
|
onAnnotationsChanged(mapOf("annotations" to json))
|
|
108
126
|
}
|
|
109
127
|
|
|
128
|
+
fun provideTextInput(text: String?) {
|
|
129
|
+
val page = pendingTextPage.also { pendingTextPage = -1 }
|
|
130
|
+
val point = pendingTextPoint.also { pendingTextPoint = null }
|
|
131
|
+
if (page < 0 || point == null || text.isNullOrEmpty()) return
|
|
132
|
+
pdfView.addTextAnnotation(page, point, text)
|
|
133
|
+
}
|
|
134
|
+
|
|
110
135
|
private fun showTextInputDialog(page: Int, point: AnnotationPoint) {
|
|
111
136
|
val editText = EditText(context).apply {
|
|
112
137
|
hint = "Enter text"
|
|
@@ -71,6 +71,8 @@ export type ExpoPdfMarkupViewProps = {
|
|
|
71
71
|
nativeEvent: {
|
|
72
72
|
page: number;
|
|
73
73
|
pageCount: number;
|
|
74
|
+
pageWidth: number;
|
|
75
|
+
pageHeight: number;
|
|
74
76
|
};
|
|
75
77
|
}) => void;
|
|
76
78
|
/** Fired once the document has finished loading. */
|
|
@@ -91,6 +93,12 @@ export type ExpoPdfMarkupViewProps = {
|
|
|
91
93
|
annotations: string;
|
|
92
94
|
};
|
|
93
95
|
}) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Optional async callback for the text annotation tool. When provided, this is called instead of
|
|
98
|
+
* the native platform dialog (UIAlertController / AlertDialog) when the user taps to place a text
|
|
99
|
+
* annotation. Return the text string to create the annotation, or `null` to cancel.
|
|
100
|
+
*/
|
|
101
|
+
onTextInputRequested?: () => Promise<string | null>;
|
|
94
102
|
style?: StyleProp<ViewStyle>;
|
|
95
103
|
};
|
|
96
104
|
//# sourceMappingURL=ExpoPdfMarkup.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkup.types.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkup.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,MAAM,eAAe,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC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MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACpD,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkup.types.js","sourceRoot":"","sources":["../src/ExpoPdfMarkup.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StyleProp, ViewStyle } from 'react-native';\n\nexport type AnnotationPoint = { x: number; y: number };\n\nexport type AnnotationBounds = { x: number; y: number; width: number; height: number };\n\nexport type InkAnnotation = {\n id: string;\n type: 'ink';\n page: number;\n color: string;\n lineWidth: number;\n paths: AnnotationPoint[][];\n createdAt?: number;\n};\n\nexport type HighlightAnnotation = {\n id: string;\n type: 'highlight';\n page: number;\n color: string;\n alpha?: number;\n bounds: AnnotationBounds;\n createdAt?: number;\n};\n\nexport type UnderlineAnnotation = {\n id: string;\n type: 'underline';\n page: number;\n color: string;\n bounds: AnnotationBounds;\n createdAt?: number;\n};\n\nexport type TextAnnotation = {\n id: string;\n type: 'text' | 'freeText';\n page: number;\n color: string;\n bounds: AnnotationBounds;\n contents?: string;\n fontSize?: number;\n createdAt?: number;\n};\n\nexport type Annotation = InkAnnotation | HighlightAnnotation | UnderlineAnnotation | TextAnnotation;\n\nexport type AnnotationsData = {\n version: 1;\n annotations: Annotation[];\n};\n\nexport type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'eraser';\n\nexport type ExpoPdfMarkupViewProps = {\n /** Absolute local file path of the PDF to display. */\n source: string;\n /** 0-based page number to display. Can be used to restore scroll position on orientation change. */\n page?: number;\n /** Background colour shown behind the PDF pages. */\n backgroundColor?: string;\n /** Serialised {@link AnnotationsData} JSON string to load when the document opens. */\n annotations?: string;\n /** Active annotation tool. Defaults to `'none'` (view-only). */\n annotationMode?: AnnotationMode;\n /** Colour applied to new annotations, as a CSS colour string (e.g. `'#FF0000'`). */\n annotationColor?: string;\n /** Stroke width in points applied to new ink annotations. */\n annotationLineWidth?: number;\n /** Fired when the visible page changes. */\n onPageChanged?: (event: {
|
|
1
|
+
{"version":3,"file":"ExpoPdfMarkup.types.js","sourceRoot":"","sources":["../src/ExpoPdfMarkup.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { StyleProp, ViewStyle } from 'react-native';\n\nexport type AnnotationPoint = { x: number; y: number };\n\nexport type AnnotationBounds = { x: number; y: number; width: number; height: number };\n\nexport type InkAnnotation = {\n id: string;\n type: 'ink';\n page: number;\n color: string;\n lineWidth: number;\n paths: AnnotationPoint[][];\n createdAt?: number;\n};\n\nexport type HighlightAnnotation = {\n id: string;\n type: 'highlight';\n page: number;\n color: string;\n alpha?: number;\n bounds: AnnotationBounds;\n createdAt?: number;\n};\n\nexport type UnderlineAnnotation = {\n id: string;\n type: 'underline';\n page: number;\n color: string;\n bounds: AnnotationBounds;\n createdAt?: number;\n};\n\nexport type TextAnnotation = {\n id: string;\n type: 'text' | 'freeText';\n page: number;\n color: string;\n bounds: AnnotationBounds;\n contents?: string;\n fontSize?: number;\n createdAt?: number;\n};\n\nexport type Annotation = InkAnnotation | HighlightAnnotation | UnderlineAnnotation | TextAnnotation;\n\nexport type AnnotationsData = {\n version: 1;\n annotations: Annotation[];\n};\n\nexport type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'eraser';\n\nexport type ExpoPdfMarkupViewProps = {\n /** Absolute local file path of the PDF to display. */\n source: string;\n /** 0-based page number to display. Can be used to restore scroll position on orientation change. */\n page?: number;\n /** Background colour shown behind the PDF pages. */\n backgroundColor?: string;\n /** Serialised {@link AnnotationsData} JSON string to load when the document opens. */\n annotations?: string;\n /** Active annotation tool. Defaults to `'none'` (view-only). */\n annotationMode?: AnnotationMode;\n /** Colour applied to new annotations, as a CSS colour string (e.g. `'#FF0000'`). */\n annotationColor?: string;\n /** Stroke width in points applied to new ink annotations. */\n annotationLineWidth?: number;\n /** Fired when the visible page changes. */\n onPageChanged?: (event: {\n nativeEvent: { page: number; pageCount: number; pageWidth: number; pageHeight: number };\n }) => void;\n /** Fired once the document has finished loading. */\n onLoadComplete?: (event: { nativeEvent: { pageCount: number } }) => void;\n /** Fired when the document fails to load. */\n onError?: (event: { nativeEvent: { message: string } }) => void;\n /** Fired after annotations are created or edited. `annotations` is a serialised {@link AnnotationsData} JSON string. */\n onAnnotationsChanged?: (event: { nativeEvent: { annotations: string } }) => void;\n /**\n * Optional async callback for the text annotation tool. When provided, this is called instead of\n * the native platform dialog (UIAlertController / AlertDialog) when the user taps to place a text\n * annotation. Return the text string to create the annotation, or `null` to cancel.\n */\n onTextInputRequested?: () => Promise<string | null>;\n style?: StyleProp<ViewStyle>;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';
|
|
3
|
-
export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps): React.JSX.Element;
|
|
3
|
+
export default function ExpoPdfMarkupView({ onTextInputRequested, ...props }: ExpoPdfMarkupViewProps): React.JSX.Element;
|
|
4
4
|
//# sourceMappingURL=ExpoPdfMarkupView.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkupView.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoPdfMarkupView.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAa/D,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,oBAAoB,EACpB,GAAG,KAAK,EACT,EAAE,sBAAsB,qBAmBxB"}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
-
import { requireNativeView } from 'expo';
|
|
1
|
+
import { requireNativeModule, requireNativeView } from 'expo';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { findNodeHandle } from 'react-native';
|
|
3
4
|
const NativeView = requireNativeView('ExpoPdfMarkup');
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
const NativeModule = requireNativeModule('ExpoPdfMarkup');
|
|
6
|
+
export default function ExpoPdfMarkupView({ onTextInputRequested, ...props }) {
|
|
7
|
+
const nativeRef = React.useRef(null);
|
|
8
|
+
const handleNativeTextInputRequested = React.useCallback(async () => {
|
|
9
|
+
if (!onTextInputRequested)
|
|
10
|
+
return;
|
|
11
|
+
const tag = findNodeHandle(nativeRef.current);
|
|
12
|
+
if (tag == null)
|
|
13
|
+
return;
|
|
14
|
+
const text = await onTextInputRequested();
|
|
15
|
+
await NativeModule.provideTextInput(tag, text ?? null);
|
|
16
|
+
}, [onTextInputRequested]);
|
|
17
|
+
return (<NativeView ref={nativeRef} {...props} useJsTextDialog={!!onTextInputRequested} onTextInputRequested={onTextInputRequested ? handleNativeTextInputRequested : undefined}/>);
|
|
6
18
|
}
|
|
7
19
|
//# sourceMappingURL=ExpoPdfMarkupView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkupView.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoPdfMarkupView.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAC9D,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAS9C,MAAM,UAAU,GAAG,iBAAiB,CAAC,eAAe,CAEnD,CAAC;AAEF,MAAM,YAAY,GAAG,mBAAmB,CAAC,eAAe,CAAC,CAAC;AAE1D,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,oBAAoB,EACpB,GAAG,KAAK,EACe;IACvB,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAU,IAAI,CAAC,CAAC;IAE9C,MAAM,8BAA8B,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,IAAI,EAAE;QAClE,IAAI,CAAC,oBAAoB;YAAE,OAAO;QAClC,MAAM,GAAG,GAAG,cAAc,CAAC,SAAS,CAAC,OAA+C,CAAC,CAAC;QACtF,IAAI,GAAG,IAAI,IAAI;YAAE,OAAO;QACxB,MAAM,IAAI,GAAG,MAAM,oBAAoB,EAAE,CAAC;QAC1C,MAAM,YAAY,CAAC,gBAAgB,CAAC,GAAG,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC;IACzD,CAAC,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAE3B,OAAO,CACL,CAAC,UAAU,CACT,GAAG,CAAC,CAAC,SAAS,CAAC,CACf,IAAI,KAAK,CAAC,CACV,eAAe,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CACxC,oBAAoB,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,8BAA8B,CAAC,CAAC,CAAC,SAAS,CAAC,EACxF,CACH,CAAC;AACJ,CAAC","sourcesContent":["import { requireNativeModule, requireNativeView } from 'expo';\nimport * as React from 'react';\nimport { findNodeHandle } from 'react-native';\n\nimport { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';\n\ntype NativeViewProps = Omit<ExpoPdfMarkupViewProps, 'onTextInputRequested'> & {\n useJsTextDialog?: boolean;\n onTextInputRequested?: (event: { nativeEvent: Record<string, never> }) => void;\n};\n\nconst NativeView = requireNativeView('ExpoPdfMarkup') as React.ForwardRefExoticComponent<\n NativeViewProps & React.RefAttributes<unknown>\n>;\n\nconst NativeModule = requireNativeModule('ExpoPdfMarkup');\n\nexport default function ExpoPdfMarkupView({\n onTextInputRequested,\n ...props\n}: ExpoPdfMarkupViewProps) {\n const nativeRef = React.useRef<unknown>(null);\n\n const handleNativeTextInputRequested = React.useCallback(async () => {\n if (!onTextInputRequested) return;\n const tag = findNodeHandle(nativeRef.current as Parameters<typeof findNodeHandle>[0]);\n if (tag == null) return;\n const text = await onTextInputRequested();\n await NativeModule.provideTextInput(tag, text ?? null);\n }, [onTextInputRequested]);\n\n return (\n <NativeView\n ref={nativeRef}\n {...props}\n useJsTextDialog={!!onTextInputRequested}\n onTextInputRequested={onTextInputRequested ? handleNativeTextInputRequested : undefined}\n />\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkupView.web.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAIV,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"ExpoPdfMarkupView.web.d.ts","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAIV,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAqB/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AA+QD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBA2TtE"}
|
|
@@ -4,14 +4,21 @@ import { canvasRectToPdfBounds, canvasToPdf, drawAnnotationsOnCanvas, hitTestAnn
|
|
|
4
4
|
// Configure pdfjs worker once at module level (consumers can override before mounting)
|
|
5
5
|
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
|
|
6
6
|
// Default: served from public/ by withPdfMarkup() in metro.js.
|
|
7
|
+
// Relative URL so the worker resolves correctly regardless of the sub-path
|
|
8
|
+
// the app is hosted at (e.g. /example/ on GitHub Pages).
|
|
7
9
|
// Override with setPdfJsWorkerSrc() if using a different bundler or CDN.
|
|
8
|
-
pdfjs.GlobalWorkerOptions.workerSrc = '
|
|
10
|
+
pdfjs.GlobalWorkerOptions.workerSrc = './pdf.worker.min.mjs';
|
|
9
11
|
}
|
|
10
12
|
/** Allow consumers to override the pdfjs worker URL before mounting the view. */
|
|
11
13
|
export function setPdfJsWorkerSrc(url) {
|
|
12
14
|
pdfjs.GlobalWorkerOptions.workerSrc = url;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Zoom constants
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
const MIN_ZOOM = 1;
|
|
20
|
+
const MAX_ZOOM = 5;
|
|
21
|
+
function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotationColor, annotationLineWidth, zoomLevel, onAnnotationAdded, onAnnotationRemoved, onTextInputRequested, containerRef, }) {
|
|
15
22
|
const pdfCanvasRef = React.useRef(null);
|
|
16
23
|
const annotCanvasRef = React.useRef(null);
|
|
17
24
|
const pageRef = React.useRef(null);
|
|
@@ -106,7 +113,7 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
|
|
|
106
113
|
}, [redrawAnnotations]);
|
|
107
114
|
function getCanvasPoint(e) {
|
|
108
115
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
109
|
-
return { x: e.clientX - rect.left, y: e.clientY - rect.top };
|
|
116
|
+
return { x: (e.clientX - rect.left) / zoomLevel, y: (e.clientY - rect.top) / zoomLevel };
|
|
110
117
|
}
|
|
111
118
|
function handlePointerDown(e) {
|
|
112
119
|
if (annotationMode === 'none')
|
|
@@ -233,7 +240,7 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
|
|
|
233
240
|
// Main component
|
|
234
241
|
// ---------------------------------------------------------------------------
|
|
235
242
|
export default function ExpoPdfMarkupView(props) {
|
|
236
|
-
const { source, page: propPage, backgroundColor = '#f0f0f0', annotations: annotationsProp, annotationMode = 'none', annotationColor = '#FF0000', annotationLineWidth = 2, onPageChanged, onLoadComplete, onError, onAnnotationsChanged, style, } = props;
|
|
243
|
+
const { source, page: propPage, backgroundColor = '#f0f0f0', annotations: annotationsProp, annotationMode = 'none', annotationColor = '#FF0000', annotationLineWidth = 2, onPageChanged, onLoadComplete, onError, onAnnotationsChanged, onTextInputRequested, style, } = props;
|
|
237
244
|
const scrollContainerRef = React.useRef(null);
|
|
238
245
|
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
239
246
|
const [doc, setDoc] = React.useState(null);
|
|
@@ -243,6 +250,8 @@ export default function ExpoPdfMarkupView(props) {
|
|
|
243
250
|
const pageContainerRefs = React.useRef([]);
|
|
244
251
|
const docRef = React.useRef(null);
|
|
245
252
|
const loadingSourceRef = React.useRef(null);
|
|
253
|
+
const [zoomLevel, setZoomLevel] = React.useState(1);
|
|
254
|
+
const zoomRef = React.useRef(1);
|
|
246
255
|
// ResizeObserver โ containerWidth
|
|
247
256
|
React.useEffect(() => {
|
|
248
257
|
const el = scrollContainerRef.current;
|
|
@@ -255,6 +264,77 @@ export default function ExpoPdfMarkupView(props) {
|
|
|
255
264
|
ro.observe(el);
|
|
256
265
|
return () => ro.disconnect();
|
|
257
266
|
}, []);
|
|
267
|
+
// Pinch-to-zoom: intercept ctrl+wheel (trackpad pinch) and two-finger touch pinch.
|
|
268
|
+
// Zooms only the PDF content, leaving the rest of the UI at 1ร.
|
|
269
|
+
React.useEffect(() => {
|
|
270
|
+
const el = scrollContainerRef.current;
|
|
271
|
+
if (!el)
|
|
272
|
+
return;
|
|
273
|
+
function applyZoom(newZoom, originX, originY) {
|
|
274
|
+
const clamped = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, newZoom));
|
|
275
|
+
if (clamped === zoomRef.current)
|
|
276
|
+
return;
|
|
277
|
+
const ratio = clamped / zoomRef.current;
|
|
278
|
+
// Keep the origin point (pointer/pinch centre) stationary in the viewport.
|
|
279
|
+
const nextScrollLeft = (el.scrollLeft + originX) * ratio - originX;
|
|
280
|
+
const nextScrollTop = (el.scrollTop + originY) * ratio - originY;
|
|
281
|
+
zoomRef.current = clamped;
|
|
282
|
+
setZoomLevel(clamped);
|
|
283
|
+
// Apply after React re-renders so the CSS zoom is in effect before we set scroll.
|
|
284
|
+
requestAnimationFrame(() => {
|
|
285
|
+
el.scrollLeft = Math.max(0, nextScrollLeft);
|
|
286
|
+
el.scrollTop = Math.max(0, nextScrollTop);
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function onWheel(e) {
|
|
290
|
+
if (!e.ctrlKey)
|
|
291
|
+
return;
|
|
292
|
+
e.preventDefault();
|
|
293
|
+
const rect = el.getBoundingClientRect();
|
|
294
|
+
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
|
295
|
+
applyZoom(zoomRef.current * factor, e.clientX - rect.left, e.clientY - rect.top);
|
|
296
|
+
}
|
|
297
|
+
let pinchStart = null;
|
|
298
|
+
function getTouchDist(touches) {
|
|
299
|
+
const dx = touches[0].clientX - touches[1].clientX;
|
|
300
|
+
const dy = touches[0].clientY - touches[1].clientY;
|
|
301
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
302
|
+
}
|
|
303
|
+
function onTouchStart(e) {
|
|
304
|
+
if (e.touches.length !== 2)
|
|
305
|
+
return;
|
|
306
|
+
const rect = el.getBoundingClientRect();
|
|
307
|
+
pinchStart = {
|
|
308
|
+
dist: getTouchDist(e.touches),
|
|
309
|
+
zoom: zoomRef.current,
|
|
310
|
+
midX: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,
|
|
311
|
+
midY: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
function onTouchMove(e) {
|
|
315
|
+
if (e.touches.length !== 2 || !pinchStart)
|
|
316
|
+
return;
|
|
317
|
+
e.preventDefault();
|
|
318
|
+
const dist = getTouchDist(e.touches);
|
|
319
|
+
applyZoom(pinchStart.zoom * (dist / pinchStart.dist), pinchStart.midX, pinchStart.midY);
|
|
320
|
+
}
|
|
321
|
+
function onTouchEnd(e) {
|
|
322
|
+
if (e.touches.length < 2)
|
|
323
|
+
pinchStart = null;
|
|
324
|
+
}
|
|
325
|
+
el.addEventListener('wheel', onWheel, { passive: false });
|
|
326
|
+
el.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
327
|
+
el.addEventListener('touchmove', onTouchMove, { passive: false });
|
|
328
|
+
el.addEventListener('touchend', onTouchEnd);
|
|
329
|
+
el.addEventListener('touchcancel', onTouchEnd);
|
|
330
|
+
return () => {
|
|
331
|
+
el.removeEventListener('wheel', onWheel);
|
|
332
|
+
el.removeEventListener('touchstart', onTouchStart);
|
|
333
|
+
el.removeEventListener('touchmove', onTouchMove);
|
|
334
|
+
el.removeEventListener('touchend', onTouchEnd);
|
|
335
|
+
el.removeEventListener('touchcancel', onTouchEnd);
|
|
336
|
+
};
|
|
337
|
+
}, []);
|
|
258
338
|
// Load PDF when source or containerWidth changes
|
|
259
339
|
React.useEffect(() => {
|
|
260
340
|
if (!source || containerWidth <= 0)
|
|
@@ -347,7 +427,14 @@ export default function ExpoPdfMarkupView(props) {
|
|
|
347
427
|
}
|
|
348
428
|
if (topPage !== -1 && topPage !== lastReported) {
|
|
349
429
|
lastReported = topPage;
|
|
350
|
-
onPageChanged?.({
|
|
430
|
+
onPageChanged?.({
|
|
431
|
+
nativeEvent: {
|
|
432
|
+
page: topPage,
|
|
433
|
+
pageCount: doc.numPages,
|
|
434
|
+
pageWidth: pageMetas[topPage]?.pdfWidth ?? 0,
|
|
435
|
+
pageHeight: pageMetas[topPage]?.pdfHeight ?? 0,
|
|
436
|
+
},
|
|
437
|
+
});
|
|
351
438
|
}
|
|
352
439
|
}, { root: scrollContainerRef.current, threshold: 0.1 });
|
|
353
440
|
for (const el of els)
|
|
@@ -372,8 +459,10 @@ export default function ExpoPdfMarkupView(props) {
|
|
|
372
459
|
return next;
|
|
373
460
|
});
|
|
374
461
|
}, [onAnnotationsChanged]);
|
|
375
|
-
const handleTextInputRequested = React.useCallback((pageIndex, pdfPoint) => {
|
|
376
|
-
const text =
|
|
462
|
+
const handleTextInputRequested = React.useCallback(async (pageIndex, pdfPoint) => {
|
|
463
|
+
const text = onTextInputRequested
|
|
464
|
+
? await onTextInputRequested()
|
|
465
|
+
: window.prompt('Enter annotation text:');
|
|
377
466
|
if (!text)
|
|
378
467
|
return;
|
|
379
468
|
const fontSize = 16;
|
|
@@ -394,21 +483,24 @@ export default function ExpoPdfMarkupView(props) {
|
|
|
394
483
|
fontSize,
|
|
395
484
|
createdAt: Date.now(),
|
|
396
485
|
});
|
|
397
|
-
}, [annotationColor, handleAnnotationAdded]);
|
|
486
|
+
}, [annotationColor, handleAnnotationAdded, onTextInputRequested]);
|
|
398
487
|
const styleObj = style;
|
|
399
488
|
return (<div ref={scrollContainerRef} style={{
|
|
400
489
|
overflowY: 'scroll',
|
|
490
|
+
overflowX: 'auto',
|
|
401
491
|
backgroundColor,
|
|
402
492
|
height: '100%',
|
|
403
493
|
...styleObj,
|
|
404
494
|
}}>
|
|
405
|
-
{
|
|
495
|
+
<div style={{ zoom: zoomLevel }}>
|
|
496
|
+
{doc &&
|
|
406
497
|
pageMetas.map((meta, i) => (<React.Fragment key={i}>
|
|
407
|
-
|
|
408
|
-
<PageView doc={doc} pageIndex={i} meta={meta} annotations={annotations} annotationMode={annotationMode} annotationColor={annotationColor} annotationLineWidth={annotationLineWidth} onAnnotationAdded={handleAnnotationAdded} onAnnotationRemoved={handleAnnotationRemoved} onTextInputRequested={handleTextInputRequested} containerRef={(el) => {
|
|
498
|
+
<PageView doc={doc} pageIndex={i} meta={meta} annotations={annotations} annotationMode={annotationMode} annotationColor={annotationColor} annotationLineWidth={annotationLineWidth} zoomLevel={zoomLevel} onAnnotationAdded={handleAnnotationAdded} onAnnotationRemoved={handleAnnotationRemoved} onTextInputRequested={handleTextInputRequested} containerRef={(el) => {
|
|
409
499
|
pageContainerRefs.current[i] = el;
|
|
410
500
|
}}/>
|
|
411
|
-
|
|
501
|
+
{i < pageMetas.length - 1 && <div style={{ height: 8 }} aria-hidden/>}
|
|
502
|
+
</React.Fragment>))}
|
|
503
|
+
</div>
|
|
412
504
|
</div>);
|
|
413
505
|
}
|
|
414
506
|
//# sourceMappingURL=ExpoPdfMarkupView.web.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkupView.web.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,uFAAuF;AACvF,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE,CAAC;IACzC,+DAA+D;IAC/D,yEAAyE;IACzE,KAAK,CAAC,mBAAmB,CAAC,SAAS,GAAG,qBAAqB,CAAC;AAC9D,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,KAAK,CAAC,mBAAmB,CAAC,SAAS,GAAG,GAAG,CAAC;AAC5C,CAAC;AAoBD,SAAS,QAAQ,CAAC,EAChB,GAAG,EACH,SAAS,EACT,IAAI,EACJ,WAAW,EACX,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,GACE;IACd,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAoB,IAAI,CAAC,CAAC;IAC3D,MAAM,cAAc,GAAG,KAAK,CA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AEN;UAAA,EAAE,KAAK,CAAC,QAAQ,CAAC,CAClB,CAAC,CACN;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC","sourcesContent":["import * as pdfjs from 'pdfjs-dist';\nimport type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';\nimport * as React from 'react';\n\nimport type {\n Annotation,\n AnnotationMode,\n AnnotationPoint,\n ExpoPdfMarkupViewProps,\n} from './ExpoPdfMarkup.types';\nimport {\n canvasRectToPdfBounds,\n canvasToPdf,\n drawAnnotationsOnCanvas,\n hitTestAnnotation,\n newAnnotationId,\n parseAnnotations,\n serializeAnnotations,\n} from './web/annotationUtils';\nimport type { PdfPageMeta } from './web/types';\n\n// Configure pdfjs worker once at module level (consumers can override before mounting)\nif (!pdfjs.GlobalWorkerOptions.workerSrc) {\n // Default: served from public/ by withPdfMarkup() in metro.js.\n // Override with setPdfJsWorkerSrc() if using a different bundler or CDN.\n pdfjs.GlobalWorkerOptions.workerSrc = '/pdf.worker.min.mjs';\n}\n\n/** Allow consumers to override the pdfjs worker URL before mounting the view. */\nexport function setPdfJsWorkerSrc(url: string): void {\n pdfjs.GlobalWorkerOptions.workerSrc = url;\n}\n\n// ---------------------------------------------------------------------------\n// PageView\n// ---------------------------------------------------------------------------\n\ntype PageViewProps = {\n doc: PDFDocumentProxy;\n pageIndex: number;\n meta: PdfPageMeta;\n annotations: Annotation[];\n annotationMode: AnnotationMode;\n annotationColor: string;\n annotationLineWidth: number;\n onAnnotationAdded: (annotation: Annotation) => void;\n onAnnotationRemoved: (id: string) => void;\n onTextInputRequested: (pageIndex: number, pdfPoint: AnnotationPoint) => void;\n containerRef: (el: HTMLDivElement | null) => void;\n};\n\nfunction PageView({\n doc,\n pageIndex,\n meta,\n annotations,\n annotationMode,\n annotationColor,\n annotationLineWidth,\n onAnnotationAdded,\n onAnnotationRemoved,\n onTextInputRequested,\n containerRef,\n}: PageViewProps) {\n const pdfCanvasRef = React.useRef<HTMLCanvasElement>(null);\n const annotCanvasRef = React.useRef<HTMLCanvasElement>(null);\n const pageRef = React.useRef<PDFPageProxy | null>(null);\n const renderTaskRef = React.useRef<ReturnType<PDFPageProxy['render']> | null>(null);\n const pointerDownRef = React.useRef(false);\n const inkPointsRef = React.useRef<{ x: number; y: number }[]>([]);\n const dragStartRef = React.useRef<{ x: number; y: number } | null>(null);\n const dragCurrentRef = React.useRef<{ x: number; y: number } | null>(null);\n\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio ?? 1 : 1;\n const cssWidth = meta.canvasWidth / dpr;\n const cssHeight = meta.canvasHeight / dpr;\n\n // Render PDF page onto pdfCanvas\n React.useEffect(() => {\n let cancelled = false;\n async function render() {\n if (!pdfCanvasRef.current) return;\n renderTaskRef.current?.cancel();\n renderTaskRef.current = null;\n const page = await doc.getPage(pageIndex + 1);\n if (cancelled) {\n page.cleanup();\n return;\n }\n pageRef.current = page;\n const canvas = pdfCanvasRef.current;\n if (!canvas) return;\n canvas.width = meta.canvasWidth;\n canvas.height = meta.canvasHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n const viewport = page.getViewport({ scale: meta.scale * dpr });\n const task = page.render({ canvasContext: ctx, viewport });\n renderTaskRef.current = task;\n try {\n await task.promise;\n } catch {\n // Render cancelled โ ignore\n }\n }\n render();\n return () => {\n cancelled = true;\n renderTaskRef.current?.cancel();\n };\n }, [doc, pageIndex, meta, dpr]);\n\n // Draw annotations on annotCanvas\n const redrawAnnotations = React.useCallback(\n (liveInkPoints?: { x: number; y: number }[], dragRect?: DOMRect) => {\n const canvas = annotCanvasRef.current;\n if (!canvas) return;\n canvas.width = meta.canvasWidth;\n canvas.height = meta.canvasHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.scale(dpr, dpr);\n drawAnnotationsOnCanvas(ctx, annotations, pageIndex, meta);\n // Live ink preview\n if (liveInkPoints && liveInkPoints.length > 1) {\n ctx.save();\n ctx.strokeStyle = annotationColor;\n ctx.lineWidth = annotationLineWidth * meta.scale;\n ctx.lineCap = 'round';\n ctx.lineJoin = 'round';\n ctx.beginPath();\n for (let i = 0; i < liveInkPoints.length; i++) {\n const pt = liveInkPoints[i];\n if (i === 0) ctx.moveTo(pt.x, pt.y);\n else ctx.lineTo(pt.x, pt.y);\n }\n ctx.stroke();\n ctx.restore();\n }\n // Live drag rect preview (highlight/underline)\n if (dragRect) {\n ctx.save();\n ctx.strokeStyle = annotationColor;\n ctx.lineWidth = 1;\n ctx.setLineDash([4, 4]);\n ctx.strokeRect(dragRect.x, dragRect.y, dragRect.width, dragRect.height);\n ctx.restore();\n }\n },\n [annotations, pageIndex, meta, dpr, annotationColor, annotationLineWidth]\n );\n\n React.useEffect(() => {\n redrawAnnotations();\n }, [redrawAnnotations]);\n\n function getCanvasPoint(e: React.PointerEvent<HTMLCanvasElement>): { x: number; y: number } {\n const rect = (e.currentTarget as HTMLCanvasElement).getBoundingClientRect();\n return { x: e.clientX - rect.left, y: e.clientY - rect.top };\n }\n\n function handlePointerDown(e: React.PointerEvent<HTMLCanvasElement>) {\n if (annotationMode === 'none') return;\n e.currentTarget.setPointerCapture(e.pointerId);\n const pt = getCanvasPoint(e);\n pointerDownRef.current = true;\n if (annotationMode === 'ink') {\n inkPointsRef.current = [pt];\n } else if (annotationMode === 'highlight' || annotationMode === 'underline') {\n dragStartRef.current = pt;\n dragCurrentRef.current = pt;\n }\n }\n\n function handlePointerMove(e: React.PointerEvent<HTMLCanvasElement>) {\n if (!pointerDownRef.current) return;\n const pt = getCanvasPoint(e);\n if (annotationMode === 'ink') {\n inkPointsRef.current.push(pt);\n redrawAnnotations(inkPointsRef.current);\n } else if (annotationMode === 'highlight' || annotationMode === 'underline') {\n dragCurrentRef.current = pt;\n const start = dragStartRef.current!;\n const minX = Math.min(start.x, pt.x);\n const minY = Math.min(start.y, pt.y);\n const w = Math.abs(pt.x - start.x);\n const h = Math.abs(pt.y - start.y);\n redrawAnnotations(undefined, new DOMRect(minX, minY, w, h));\n }\n }\n\n function handlePointerUp(e: React.PointerEvent<HTMLCanvasElement>) {\n if (!pointerDownRef.current && annotationMode !== 'text' && annotationMode !== 'eraser') return;\n pointerDownRef.current = false;\n const pt = getCanvasPoint(e);\n const { scale, pdfHeight } = meta;\n\n if (annotationMode === 'ink') {\n const cssPoints = inkPointsRef.current;\n inkPointsRef.current = [];\n if (cssPoints.length === 0) return;\n const pdfPoints = cssPoints.map((p) => canvasToPdf(p.x, p.y, scale, pdfHeight));\n onAnnotationAdded({\n id: newAnnotationId(),\n type: 'ink',\n page: pageIndex,\n color: annotationColor,\n lineWidth: annotationLineWidth,\n paths: [pdfPoints],\n createdAt: Date.now(),\n });\n } else if (annotationMode === 'highlight' || annotationMode === 'underline') {\n const start = dragStartRef.current;\n dragStartRef.current = null;\n dragCurrentRef.current = null;\n if (!start) return;\n const minX = Math.min(start.x, pt.x);\n const minY = Math.min(start.y, pt.y);\n const maxX = Math.max(start.x, pt.x);\n const maxY = Math.max(start.y, pt.y);\n if (maxX - minX < 2 || maxY - minY < 2) return;\n const bounds = canvasRectToPdfBounds(minX, minY, maxX, maxY, scale, pdfHeight);\n if (annotationMode === 'highlight') {\n onAnnotationAdded({\n id: newAnnotationId(),\n type: 'highlight',\n page: pageIndex,\n color: annotationColor,\n alpha: 0.5,\n bounds,\n createdAt: Date.now(),\n });\n } else {\n onAnnotationAdded({\n id: newAnnotationId(),\n type: 'underline',\n page: pageIndex,\n color: annotationColor,\n bounds,\n createdAt: Date.now(),\n });\n }\n } else if (annotationMode === 'text') {\n const pdfPoint = canvasToPdf(pt.x, pt.y, scale, pdfHeight);\n onTextInputRequested(pageIndex, pdfPoint);\n } else if (annotationMode === 'eraser') {\n const pdfPoint = canvasToPdf(pt.x, pt.y, scale, pdfHeight);\n const hit = hitTestAnnotation(pdfPoint, annotations, pageIndex);\n if (hit) onAnnotationRemoved(hit.id);\n }\n }\n\n const pointerEvents = annotationMode === 'none' ? 'none' : 'auto';\n\n return (\n <div\n ref={containerRef}\n style={{ position: 'relative', width: cssWidth, height: cssHeight, margin: '0 auto' }}\n >\n <canvas\n ref={pdfCanvasRef}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: cssWidth,\n height: cssHeight,\n pointerEvents: 'none',\n }}\n />\n <canvas\n ref={annotCanvasRef}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: cssWidth,\n height: cssHeight,\n cursor: 'crosshair',\n pointerEvents,\n }}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={handlePointerUp}\n />\n </div>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Main component\n// ---------------------------------------------------------------------------\n\nexport default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {\n const {\n source,\n page: propPage,\n backgroundColor = '#f0f0f0',\n annotations: annotationsProp,\n annotationMode = 'none',\n annotationColor = '#FF0000',\n annotationLineWidth = 2,\n onPageChanged,\n onLoadComplete,\n onError,\n onAnnotationsChanged,\n style,\n } = props;\n\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n const [containerWidth, setContainerWidth] = React.useState(0);\n const [doc, setDoc] = React.useState<PDFDocumentProxy | null>(null);\n const [pageMetas, setPageMetas] = React.useState<PdfPageMeta[]>([]);\n const [annotations, setAnnotations] = React.useState<Annotation[]>([]);\n const lastAnnotationsJsonRef = React.useRef<string | undefined>(undefined);\n const pageContainerRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n const docRef = React.useRef<PDFDocumentProxy | null>(null);\n const loadingSourceRef = React.useRef<string | null>(null);\n\n // ResizeObserver โ containerWidth\n React.useEffect(() => {\n const el = scrollContainerRef.current;\n if (!el) return;\n const ro = new ResizeObserver((entries) => {\n const width = entries[0]?.contentRect.width ?? 0;\n setContainerWidth(width);\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n // Load PDF when source or containerWidth changes\n React.useEffect(() => {\n if (!source || containerWidth <= 0) return;\n let cancelled = false;\n loadingSourceRef.current = source;\n\n async function load() {\n try {\n const task = pdfjs.getDocument(source);\n const loadedDoc = await task.promise;\n if (cancelled || loadingSourceRef.current !== source) {\n loadedDoc.destroy();\n return;\n }\n const metas: PdfPageMeta[] = [];\n const dpr = window.devicePixelRatio ?? 1;\n for (let i = 1; i <= loadedDoc.numPages; i++) {\n const pg = await loadedDoc.getPage(i);\n if (cancelled) {\n pg.cleanup();\n loadedDoc.destroy();\n return;\n }\n const viewport = pg.getViewport({ scale: 1 });\n const scale = containerWidth / viewport.width;\n const cssHeight = viewport.height * scale;\n metas.push({\n pdfWidth: viewport.width,\n pdfHeight: viewport.height,\n scale,\n canvasWidth: Math.round(containerWidth * dpr),\n canvasHeight: Math.round(cssHeight * dpr),\n });\n pg.cleanup();\n }\n docRef.current?.destroy();\n docRef.current = loadedDoc;\n setDoc(loadedDoc);\n setPageMetas(metas);\n pageContainerRefs.current = new Array(loadedDoc.numPages).fill(null);\n onLoadComplete?.({ nativeEvent: { pageCount: loadedDoc.numPages } });\n } catch (err) {\n if (!cancelled) {\n onError?.({\n nativeEvent: { message: err instanceof Error ? err.message : String(err) },\n });\n }\n }\n }\n load();\n return () => {\n cancelled = true;\n };\n }, [source, containerWidth]); // intentionally omit callbacks โ they should not re-trigger a PDF load\n\n // Sync annotations prop โ state (guard round-trips)\n React.useEffect(() => {\n if (annotationsProp === lastAnnotationsJsonRef.current) return;\n lastAnnotationsJsonRef.current = annotationsProp;\n const parsed = parseAnnotations(annotationsProp);\n setAnnotations(parsed.annotations);\n }, [annotationsProp]);\n\n // Scroll to propPage\n React.useEffect(() => {\n if (propPage == null || !doc) return;\n const el = pageContainerRefs.current[propPage];\n el?.scrollIntoView({ behavior: 'instant' as ScrollBehavior });\n }, [propPage, doc]);\n\n // IntersectionObserver โ onPageChanged\n React.useEffect(() => {\n if (!doc || pageMetas.length === 0) return;\n const els = pageContainerRefs.current.filter(Boolean) as HTMLDivElement[];\n if (els.length === 0) return;\n let lastReported = -1;\n const io = new IntersectionObserver(\n (entries) => {\n let topPage = -1;\n let topY = Infinity;\n for (const entry of entries) {\n if (entry.isIntersecting) {\n const idx = els.indexOf(entry.target as HTMLDivElement);\n if (idx !== -1 && entry.boundingClientRect.top < topY) {\n topY = entry.boundingClientRect.top;\n topPage = idx;\n }\n }\n }\n if (topPage !== -1 && topPage !== lastReported) {\n lastReported = topPage;\n onPageChanged?.({ nativeEvent: { page: topPage, pageCount: doc.numPages } });\n }\n },\n { root: scrollContainerRef.current, threshold: 0.1 }\n );\n for (const el of els) io.observe(el);\n return () => io.disconnect();\n }, [doc, pageMetas, onPageChanged]);\n\n const handleAnnotationAdded = React.useCallback(\n (annotation: Annotation) => {\n setAnnotations((prev) => {\n const next = [...prev, annotation];\n const json = serializeAnnotations({ version: 1, annotations: next });\n lastAnnotationsJsonRef.current = json;\n onAnnotationsChanged?.({ nativeEvent: { annotations: json } });\n return next;\n });\n },\n [onAnnotationsChanged]\n );\n\n const handleAnnotationRemoved = React.useCallback(\n (id: string) => {\n setAnnotations((prev) => {\n const next = prev.filter((a) => a.id !== id);\n const json = serializeAnnotations({ version: 1, annotations: next });\n lastAnnotationsJsonRef.current = json;\n onAnnotationsChanged?.({ nativeEvent: { annotations: json } });\n return next;\n });\n },\n [onAnnotationsChanged]\n );\n\n const handleTextInputRequested = React.useCallback(\n (pageIndex: number, pdfPoint: AnnotationPoint) => {\n const text = window.prompt('Enter annotation text:');\n if (!text) return;\n const fontSize = 16;\n const estimatedWidth = text.length * fontSize * 0.6;\n const bounds = {\n x: pdfPoint.x,\n y: pdfPoint.y,\n width: estimatedWidth,\n height: fontSize * 1.5,\n };\n handleAnnotationAdded({\n id: newAnnotationId(),\n type: 'text',\n page: pageIndex,\n color: annotationColor,\n bounds,\n contents: text,\n fontSize,\n createdAt: Date.now(),\n });\n },\n [annotationColor, handleAnnotationAdded]\n );\n\n const styleObj = style as React.CSSProperties | undefined;\n\n return (\n <div\n ref={scrollContainerRef}\n style={{\n overflowY: 'scroll',\n backgroundColor,\n height: '100%',\n ...styleObj,\n }}\n >\n {doc &&\n pageMetas.map((meta, i) => (\n <React.Fragment key={i}>\n <div style={{ height: 8 }} aria-hidden />\n <PageView\n doc={doc}\n pageIndex={i}\n meta={meta}\n annotations={annotations}\n annotationMode={annotationMode}\n annotationColor={annotationColor}\n annotationLineWidth={annotationLineWidth}\n onAnnotationAdded={handleAnnotationAdded}\n onAnnotationRemoved={handleAnnotationRemoved}\n onTextInputRequested={handleTextInputRequested}\n containerRef={(el) => {\n pageContainerRefs.current[i] = el;\n }}\n />\n </React.Fragment>\n ))}\n </div>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoPdfMarkupView.web.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAEpC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,EACL,qBAAqB,EACrB,WAAW,EACX,uBAAuB,EACvB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,uBAAuB,CAAC;AAG/B,uFAAuF;AACvF,IAAI,CAAC,KAAK,CAAC,mBAAmB,CAAC,SAAS,EAAE,CAAC;IACzC,+DAA+D;IAC/D,2EAA2E;IAC3E,yDAAyD;IACzD,yEAAyE;IACzE,KAAK,CAAC,mBAAmB,CAAC,SAAS,GAAG,sBAAsB,CAAC;AAC/D,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,iBAAiB,CAAC,GAAW;IAC3C,KAAK,CAAC,mBAAmB,CAAC,SAAS,GAAG,GAAG,CAAC;AAC5C,CAAC;AAED,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,MAAM,QAAQ,GAAG,CAAC,CAAC;AAqBnB,SAAS,QAAQ,CAAC,EAChB,GAAG,EACH,SAAS,EACT,IAAI,EACJ,WAAW,EACX,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,SA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S,EAAE,CAAC,CAC9B;QAAA,CAAC,GAAG;YACF,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CACzB,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CACrB;cAAA,CAAC,QAAQ,CACP,GAAG,CAAC,CAAC,GAAG,CAAC,CACT,SAAS,CAAC,CAAC,CAAC,CAAC,CACb,IAAI,CAAC,CAAC,IAAI,CAAC,CACX,WAAW,CAAC,CAAC,WAAW,CAAC,CACzB,cAAc,CAAC,CAAC,cAAc,CAAC,CAC/B,eAAe,CAAC,CAAC,eAAe,CAAC,CACjC,mBAAmB,CAAC,CAAC,mBAAmB,CAAC,CACzC,SAAS,CAAC,CAAC,SAAS,CAAC,CACrB,iBAAiB,CAAC,CAAC,qBAAqB,CAAC,CACzC,mBAAmB,CAAC,CAAC,uBAAuB,CAAC,CAC7C,oBAAoB,CAAC,CAAC,wBAAwB,CAAC,CAC/C,YAAY,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE;oBACnB,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC;gBACpC,CAAC,CAAC,EAEJ;cAAA,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,WAAW,EAAG,CACxE;YAAA,EAAE,KAAK,CAAC,QAAQ,CAAC,CAClB,CAAC,CACN;MAAA,EAAE,GAAG,CACP;IAAA,EAAE,GAAG,CAAC,CACP,CAAC;AACJ,CAAC","sourcesContent":["import * as pdfjs from 'pdfjs-dist';\nimport type { PDFDocumentProxy, PDFPageProxy } from 'pdfjs-dist';\nimport * as React from 'react';\n\nimport type {\n Annotation,\n AnnotationMode,\n AnnotationPoint,\n ExpoPdfMarkupViewProps,\n} from './ExpoPdfMarkup.types';\nimport {\n canvasRectToPdfBounds,\n canvasToPdf,\n drawAnnotationsOnCanvas,\n hitTestAnnotation,\n newAnnotationId,\n parseAnnotations,\n serializeAnnotations,\n} from './web/annotationUtils';\nimport type { PdfPageMeta } from './web/types';\n\n// Configure pdfjs worker once at module level (consumers can override before mounting)\nif (!pdfjs.GlobalWorkerOptions.workerSrc) {\n // Default: served from public/ by withPdfMarkup() in metro.js.\n // Relative URL so the worker resolves correctly regardless of the sub-path\n // the app is hosted at (e.g. /example/ on GitHub Pages).\n // Override with setPdfJsWorkerSrc() if using a different bundler or CDN.\n pdfjs.GlobalWorkerOptions.workerSrc = './pdf.worker.min.mjs';\n}\n\n/** Allow consumers to override the pdfjs worker URL before mounting the view. */\nexport function setPdfJsWorkerSrc(url: string): void {\n pdfjs.GlobalWorkerOptions.workerSrc = url;\n}\n\n// ---------------------------------------------------------------------------\n// Zoom constants\n// ---------------------------------------------------------------------------\n\nconst MIN_ZOOM = 1;\nconst MAX_ZOOM = 5;\n\n// ---------------------------------------------------------------------------\n// PageView\n// ---------------------------------------------------------------------------\n\ntype PageViewProps = {\n doc: PDFDocumentProxy;\n pageIndex: number;\n meta: PdfPageMeta;\n annotations: Annotation[];\n annotationMode: AnnotationMode;\n annotationColor: string;\n annotationLineWidth: number;\n zoomLevel: number;\n onAnnotationAdded: (annotation: Annotation) => void;\n onAnnotationRemoved: (id: string) => void;\n onTextInputRequested: (pageIndex: number, pdfPoint: AnnotationPoint) => void;\n containerRef: (el: HTMLDivElement | null) => void;\n};\n\nfunction PageView({\n doc,\n pageIndex,\n meta,\n annotations,\n annotationMode,\n annotationColor,\n annotationLineWidth,\n zoomLevel,\n onAnnotationAdded,\n onAnnotationRemoved,\n onTextInputRequested,\n containerRef,\n}: PageViewProps) {\n const pdfCanvasRef = React.useRef<HTMLCanvasElement>(null);\n const annotCanvasRef = React.useRef<HTMLCanvasElement>(null);\n const pageRef = React.useRef<PDFPageProxy | null>(null);\n const renderTaskRef = React.useRef<ReturnType<PDFPageProxy['render']> | null>(null);\n const pointerDownRef = React.useRef(false);\n const inkPointsRef = React.useRef<{ x: number; y: number }[]>([]);\n const dragStartRef = React.useRef<{ x: number; y: number } | null>(null);\n const dragCurrentRef = React.useRef<{ x: number; y: number } | null>(null);\n\n const dpr = typeof window !== 'undefined' ? window.devicePixelRatio ?? 1 : 1;\n const cssWidth = meta.canvasWidth / dpr;\n const cssHeight = meta.canvasHeight / dpr;\n\n // Render PDF page onto pdfCanvas\n React.useEffect(() => {\n let cancelled = false;\n async function render() {\n if (!pdfCanvasRef.current) return;\n renderTaskRef.current?.cancel();\n renderTaskRef.current = null;\n const page = await doc.getPage(pageIndex + 1);\n if (cancelled) {\n page.cleanup();\n return;\n }\n pageRef.current = page;\n const canvas = pdfCanvasRef.current;\n if (!canvas) return;\n canvas.width = meta.canvasWidth;\n canvas.height = meta.canvasHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n const viewport = page.getViewport({ scale: meta.scale * dpr });\n const task = page.render({ canvasContext: ctx, viewport });\n renderTaskRef.current = task;\n try {\n await task.promise;\n } catch {\n // Render cancelled โ ignore\n }\n }\n render();\n return () => {\n cancelled = true;\n renderTaskRef.current?.cancel();\n };\n }, [doc, pageIndex, meta, dpr]);\n\n // Draw annotations on annotCanvas\n const redrawAnnotations = React.useCallback(\n (liveInkPoints?: { x: number; y: number }[], dragRect?: DOMRect) => {\n const canvas = annotCanvasRef.current;\n if (!canvas) return;\n canvas.width = meta.canvasWidth;\n canvas.height = meta.canvasHeight;\n const ctx = canvas.getContext('2d');\n if (!ctx) return;\n ctx.scale(dpr, dpr);\n drawAnnotationsOnCanvas(ctx, annotations, pageIndex, meta);\n // Live ink preview\n if (liveInkPoints && liveInkPoints.length > 1) {\n ctx.save();\n ctx.strokeStyle = annotationColor;\n ctx.lineWidth = annotationLineWidth * meta.scale;\n ctx.lineCap = 'round';\n ctx.lineJoin = 'round';\n ctx.beginPath();\n for (let i = 0; i < liveInkPoints.length; i++) {\n const pt = liveInkPoints[i];\n if (i === 0) ctx.moveTo(pt.x, pt.y);\n else ctx.lineTo(pt.x, pt.y);\n }\n ctx.stroke();\n ctx.restore();\n }\n // Live drag rect preview (highlight/underline)\n if (dragRect) {\n ctx.save();\n ctx.strokeStyle = annotationColor;\n ctx.lineWidth = 1;\n ctx.setLineDash([4, 4]);\n ctx.strokeRect(dragRect.x, dragRect.y, dragRect.width, dragRect.height);\n ctx.restore();\n }\n },\n [annotations, pageIndex, meta, dpr, annotationColor, annotationLineWidth]\n );\n\n React.useEffect(() => {\n redrawAnnotations();\n }, [redrawAnnotations]);\n\n function getCanvasPoint(e: React.PointerEvent<HTMLCanvasElement>): { x: number; y: number } {\n const rect = (e.currentTarget as HTMLCanvasElement).getBoundingClientRect();\n return { x: (e.clientX - rect.left) / zoomLevel, y: (e.clientY - rect.top) / zoomLevel };\n }\n\n function handlePointerDown(e: React.PointerEvent<HTMLCanvasElement>) {\n if (annotationMode === 'none') return;\n e.currentTarget.setPointerCapture(e.pointerId);\n const pt = getCanvasPoint(e);\n pointerDownRef.current = true;\n if (annotationMode === 'ink') {\n inkPointsRef.current = [pt];\n } else if (annotationMode === 'highlight' || annotationMode === 'underline') {\n dragStartRef.current = pt;\n dragCurrentRef.current = pt;\n }\n }\n\n function handlePointerMove(e: React.PointerEvent<HTMLCanvasElement>) {\n if (!pointerDownRef.current) return;\n const pt = getCanvasPoint(e);\n if (annotationMode === 'ink') {\n inkPointsRef.current.push(pt);\n redrawAnnotations(inkPointsRef.current);\n } else if (annotationMode === 'highlight' || annotationMode === 'underline') {\n dragCurrentRef.current = pt;\n const start = dragStartRef.current!;\n const minX = Math.min(start.x, pt.x);\n const minY = Math.min(start.y, pt.y);\n const w = Math.abs(pt.x - start.x);\n const h = Math.abs(pt.y - start.y);\n redrawAnnotations(undefined, new DOMRect(minX, minY, w, h));\n }\n }\n\n function handlePointerUp(e: React.PointerEvent<HTMLCanvasElement>) {\n if (!pointerDownRef.current && annotationMode !== 'text' && annotationMode !== 'eraser') return;\n pointerDownRef.current = false;\n const pt = getCanvasPoint(e);\n const { scale, pdfHeight } = meta;\n\n if (annotationMode === 'ink') {\n const cssPoints = inkPointsRef.current;\n inkPointsRef.current = [];\n if (cssPoints.length === 0) return;\n const pdfPoints = cssPoints.map((p) => canvasToPdf(p.x, p.y, scale, pdfHeight));\n onAnnotationAdded({\n id: newAnnotationId(),\n type: 'ink',\n page: pageIndex,\n color: annotationColor,\n lineWidth: annotationLineWidth,\n paths: [pdfPoints],\n createdAt: Date.now(),\n });\n } else if (annotationMode === 'highlight' || annotationMode === 'underline') {\n const start = dragStartRef.current;\n dragStartRef.current = null;\n dragCurrentRef.current = null;\n if (!start) return;\n const minX = Math.min(start.x, pt.x);\n const minY = Math.min(start.y, pt.y);\n const maxX = Math.max(start.x, pt.x);\n const maxY = Math.max(start.y, pt.y);\n if (maxX - minX < 2 || maxY - minY < 2) return;\n const bounds = canvasRectToPdfBounds(minX, minY, maxX, maxY, scale, pdfHeight);\n if (annotationMode === 'highlight') {\n onAnnotationAdded({\n id: newAnnotationId(),\n type: 'highlight',\n page: pageIndex,\n color: annotationColor,\n alpha: 0.5,\n bounds,\n createdAt: Date.now(),\n });\n } else {\n onAnnotationAdded({\n id: newAnnotationId(),\n type: 'underline',\n page: pageIndex,\n color: annotationColor,\n bounds,\n createdAt: Date.now(),\n });\n }\n } else if (annotationMode === 'text') {\n const pdfPoint = canvasToPdf(pt.x, pt.y, scale, pdfHeight);\n onTextInputRequested(pageIndex, pdfPoint);\n } else if (annotationMode === 'eraser') {\n const pdfPoint = canvasToPdf(pt.x, pt.y, scale, pdfHeight);\n const hit = hitTestAnnotation(pdfPoint, annotations, pageIndex);\n if (hit) onAnnotationRemoved(hit.id);\n }\n }\n\n const pointerEvents = annotationMode === 'none' ? 'none' : 'auto';\n\n return (\n <div\n ref={containerRef}\n style={{ position: 'relative', width: cssWidth, height: cssHeight, margin: '0 auto' }}\n >\n <canvas\n ref={pdfCanvasRef}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: cssWidth,\n height: cssHeight,\n pointerEvents: 'none',\n }}\n />\n <canvas\n ref={annotCanvasRef}\n style={{\n position: 'absolute',\n top: 0,\n left: 0,\n width: cssWidth,\n height: cssHeight,\n cursor: 'crosshair',\n pointerEvents,\n }}\n onPointerDown={handlePointerDown}\n onPointerMove={handlePointerMove}\n onPointerUp={handlePointerUp}\n />\n </div>\n );\n}\n\n// ---------------------------------------------------------------------------\n// Main component\n// ---------------------------------------------------------------------------\n\nexport default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {\n const {\n source,\n page: propPage,\n backgroundColor = '#f0f0f0',\n annotations: annotationsProp,\n annotationMode = 'none',\n annotationColor = '#FF0000',\n annotationLineWidth = 2,\n onPageChanged,\n onLoadComplete,\n onError,\n onAnnotationsChanged,\n onTextInputRequested,\n style,\n } = props;\n\n const scrollContainerRef = React.useRef<HTMLDivElement>(null);\n const [containerWidth, setContainerWidth] = React.useState(0);\n const [doc, setDoc] = React.useState<PDFDocumentProxy | null>(null);\n const [pageMetas, setPageMetas] = React.useState<PdfPageMeta[]>([]);\n const [annotations, setAnnotations] = React.useState<Annotation[]>([]);\n const lastAnnotationsJsonRef = React.useRef<string | undefined>(undefined);\n const pageContainerRefs = React.useRef<(HTMLDivElement | null)[]>([]);\n const docRef = React.useRef<PDFDocumentProxy | null>(null);\n const loadingSourceRef = React.useRef<string | null>(null);\n const [zoomLevel, setZoomLevel] = React.useState(1);\n const zoomRef = React.useRef(1);\n\n // ResizeObserver โ containerWidth\n React.useEffect(() => {\n const el = scrollContainerRef.current;\n if (!el) return;\n const ro = new ResizeObserver((entries) => {\n const width = entries[0]?.contentRect.width ?? 0;\n setContainerWidth(width);\n });\n ro.observe(el);\n return () => ro.disconnect();\n }, []);\n\n // Pinch-to-zoom: intercept ctrl+wheel (trackpad pinch) and two-finger touch pinch.\n // Zooms only the PDF content, leaving the rest of the UI at 1ร.\n React.useEffect(() => {\n const el = scrollContainerRef.current;\n if (!el) return;\n\n function applyZoom(newZoom: number, originX: number, originY: number) {\n const clamped = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, newZoom));\n if (clamped === zoomRef.current) return;\n const ratio = clamped / zoomRef.current;\n // Keep the origin point (pointer/pinch centre) stationary in the viewport.\n const nextScrollLeft = (el!.scrollLeft + originX) * ratio - originX;\n const nextScrollTop = (el!.scrollTop + originY) * ratio - originY;\n zoomRef.current = clamped;\n setZoomLevel(clamped);\n // Apply after React re-renders so the CSS zoom is in effect before we set scroll.\n requestAnimationFrame(() => {\n el!.scrollLeft = Math.max(0, nextScrollLeft);\n el!.scrollTop = Math.max(0, nextScrollTop);\n });\n }\n\n function onWheel(e: WheelEvent) {\n if (!e.ctrlKey) return;\n e.preventDefault();\n const rect = el!.getBoundingClientRect();\n const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;\n applyZoom(zoomRef.current * factor, e.clientX - rect.left, e.clientY - rect.top);\n }\n\n let pinchStart: { dist: number; zoom: number; midX: number; midY: number } | null = null;\n\n function getTouchDist(touches: TouchList): number {\n const dx = touches[0].clientX - touches[1].clientX;\n const dy = touches[0].clientY - touches[1].clientY;\n return Math.sqrt(dx * dx + dy * dy);\n }\n\n function onTouchStart(e: TouchEvent) {\n if (e.touches.length !== 2) return;\n const rect = el!.getBoundingClientRect();\n pinchStart = {\n dist: getTouchDist(e.touches),\n zoom: zoomRef.current,\n midX: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,\n midY: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,\n };\n }\n\n function onTouchMove(e: TouchEvent) {\n if (e.touches.length !== 2 || !pinchStart) return;\n e.preventDefault();\n const dist = getTouchDist(e.touches);\n applyZoom(pinchStart.zoom * (dist / pinchStart.dist), pinchStart.midX, pinchStart.midY);\n }\n\n function onTouchEnd(e: TouchEvent) {\n if (e.touches.length < 2) pinchStart = null;\n }\n\n el.addEventListener('wheel', onWheel, { passive: false });\n el.addEventListener('touchstart', onTouchStart, { passive: true });\n el.addEventListener('touchmove', onTouchMove, { passive: false });\n el.addEventListener('touchend', onTouchEnd);\n el.addEventListener('touchcancel', onTouchEnd);\n return () => {\n el.removeEventListener('wheel', onWheel);\n el.removeEventListener('touchstart', onTouchStart);\n el.removeEventListener('touchmove', onTouchMove);\n el.removeEventListener('touchend', onTouchEnd);\n el.removeEventListener('touchcancel', onTouchEnd);\n };\n }, []);\n\n // Load PDF when source or containerWidth changes\n React.useEffect(() => {\n if (!source || containerWidth <= 0) return;\n let cancelled = false;\n loadingSourceRef.current = source;\n\n async function load() {\n try {\n const task = pdfjs.getDocument(source);\n const loadedDoc = await task.promise;\n if (cancelled || loadingSourceRef.current !== source) {\n loadedDoc.destroy();\n return;\n }\n const metas: PdfPageMeta[] = [];\n const dpr = window.devicePixelRatio ?? 1;\n for (let i = 1; i <= loadedDoc.numPages; i++) {\n const pg = await loadedDoc.getPage(i);\n if (cancelled) {\n pg.cleanup();\n loadedDoc.destroy();\n return;\n }\n const viewport = pg.getViewport({ scale: 1 });\n const scale = containerWidth / viewport.width;\n const cssHeight = viewport.height * scale;\n metas.push({\n pdfWidth: viewport.width,\n pdfHeight: viewport.height,\n scale,\n canvasWidth: Math.round(containerWidth * dpr),\n canvasHeight: Math.round(cssHeight * dpr),\n });\n pg.cleanup();\n }\n docRef.current?.destroy();\n docRef.current = loadedDoc;\n setDoc(loadedDoc);\n setPageMetas(metas);\n pageContainerRefs.current = new Array(loadedDoc.numPages).fill(null);\n onLoadComplete?.({ nativeEvent: { pageCount: loadedDoc.numPages } });\n } catch (err) {\n if (!cancelled) {\n onError?.({\n nativeEvent: { message: err instanceof Error ? err.message : String(err) },\n });\n }\n }\n }\n load();\n return () => {\n cancelled = true;\n };\n }, [source, containerWidth]); // intentionally omit callbacks โ they should not re-trigger a PDF load\n\n // Sync annotations prop โ state (guard round-trips)\n React.useEffect(() => {\n if (annotationsProp === lastAnnotationsJsonRef.current) return;\n lastAnnotationsJsonRef.current = annotationsProp;\n const parsed = parseAnnotations(annotationsProp);\n setAnnotations(parsed.annotations);\n }, [annotationsProp]);\n\n // Scroll to propPage\n React.useEffect(() => {\n if (propPage == null || !doc) return;\n const el = pageContainerRefs.current[propPage];\n el?.scrollIntoView({ behavior: 'instant' as ScrollBehavior });\n }, [propPage, doc]);\n\n // IntersectionObserver โ onPageChanged\n React.useEffect(() => {\n if (!doc || pageMetas.length === 0) return;\n const els = pageContainerRefs.current.filter(Boolean) as HTMLDivElement[];\n if (els.length === 0) return;\n let lastReported = -1;\n const io = new IntersectionObserver(\n (entries) => {\n let topPage = -1;\n let topY = Infinity;\n for (const entry of entries) {\n if (entry.isIntersecting) {\n const idx = els.indexOf(entry.target as HTMLDivElement);\n if (idx !== -1 && entry.boundingClientRect.top < topY) {\n topY = entry.boundingClientRect.top;\n topPage = idx;\n }\n }\n }\n if (topPage !== -1 && topPage !== lastReported) {\n lastReported = topPage;\n onPageChanged?.({\n nativeEvent: {\n page: topPage,\n pageCount: doc.numPages,\n pageWidth: pageMetas[topPage]?.pdfWidth ?? 0,\n pageHeight: pageMetas[topPage]?.pdfHeight ?? 0,\n },\n });\n }\n },\n { root: scrollContainerRef.current, threshold: 0.1 }\n );\n for (const el of els) io.observe(el);\n return () => io.disconnect();\n }, [doc, pageMetas, onPageChanged]);\n\n const handleAnnotationAdded = React.useCallback(\n (annotation: Annotation) => {\n setAnnotations((prev) => {\n const next = [...prev, annotation];\n const json = serializeAnnotations({ version: 1, annotations: next });\n lastAnnotationsJsonRef.current = json;\n onAnnotationsChanged?.({ nativeEvent: { annotations: json } });\n return next;\n });\n },\n [onAnnotationsChanged]\n );\n\n const handleAnnotationRemoved = React.useCallback(\n (id: string) => {\n setAnnotations((prev) => {\n const next = prev.filter((a) => a.id !== id);\n const json = serializeAnnotations({ version: 1, annotations: next });\n lastAnnotationsJsonRef.current = json;\n onAnnotationsChanged?.({ nativeEvent: { annotations: json } });\n return next;\n });\n },\n [onAnnotationsChanged]\n );\n\n const handleTextInputRequested = React.useCallback(\n async (pageIndex: number, pdfPoint: AnnotationPoint) => {\n const text = onTextInputRequested\n ? await onTextInputRequested()\n : window.prompt('Enter annotation text:');\n if (!text) return;\n const fontSize = 16;\n const estimatedWidth = text.length * fontSize * 0.6;\n const bounds = {\n x: pdfPoint.x,\n y: pdfPoint.y,\n width: estimatedWidth,\n height: fontSize * 1.5,\n };\n handleAnnotationAdded({\n id: newAnnotationId(),\n type: 'text',\n page: pageIndex,\n color: annotationColor,\n bounds,\n contents: text,\n fontSize,\n createdAt: Date.now(),\n });\n },\n [annotationColor, handleAnnotationAdded, onTextInputRequested]\n );\n\n const styleObj = style as React.CSSProperties | undefined;\n\n return (\n <div\n ref={scrollContainerRef}\n style={{\n overflowY: 'scroll',\n overflowX: 'auto',\n backgroundColor,\n height: '100%',\n ...styleObj,\n }}\n >\n <div style={{ zoom: zoomLevel }}>\n {doc &&\n pageMetas.map((meta, i) => (\n <React.Fragment key={i}>\n <PageView\n doc={doc}\n pageIndex={i}\n meta={meta}\n annotations={annotations}\n annotationMode={annotationMode}\n annotationColor={annotationColor}\n annotationLineWidth={annotationLineWidth}\n zoomLevel={zoomLevel}\n onAnnotationAdded={handleAnnotationAdded}\n onAnnotationRemoved={handleAnnotationRemoved}\n onTextInputRequested={handleTextInputRequested}\n containerRef={(el) => {\n pageContainerRefs.current[i] = el;\n }}\n />\n {i < pageMetas.length - 1 && <div style={{ height: 8 }} aria-hidden />}\n </React.Fragment>\n ))}\n </div>\n </div>\n );\n}\n"]}
|
package/build/pdfjs.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfjs.d.ts","sourceRoot":"","sources":["../src/pdfjs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"pdfjs.d.ts","sourceRoot":"","sources":["../src/pdfjs.ts"],"names":[],"mappings":"AACA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEpD"}
|
package/build/pdfjs.js
CHANGED
package/build/pdfjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pdfjs.js","sourceRoot":"","sources":["../src/pdfjs.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"pdfjs.js","sourceRoot":"","sources":["../src/pdfjs.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,kBAAkB;AACpB,CAAC","sourcesContent":["// Native stub โ pdfjs-dist is not available on iOS/Android.\nexport function setPdfJsWorkerSrc(_url: string): void {\n // no-op on native\n}\n"]}
|
|
@@ -4,6 +4,13 @@ public class ExpoPdfMarkupModule: Module {
|
|
|
4
4
|
public func definition() -> ModuleDefinition {
|
|
5
5
|
Name("ExpoPdfMarkup")
|
|
6
6
|
|
|
7
|
+
AsyncFunction("provideTextInput") { (viewTag: Int, text: String?) in
|
|
8
|
+
DispatchQueue.main.async {
|
|
9
|
+
guard let view = self.appContext?.findView(withTag: viewTag, ofType: ExpoPdfMarkupView.self) else { return }
|
|
10
|
+
view.provideTextInput(text: text)
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
7
14
|
View(ExpoPdfMarkupView.self) {
|
|
8
15
|
Prop("source") { (view: ExpoPdfMarkupView, source: String) in
|
|
9
16
|
view.loadPdf(from: source)
|
|
@@ -33,7 +40,11 @@ public class ExpoPdfMarkupModule: Module {
|
|
|
33
40
|
view.annotationLineWidth = CGFloat(width ?? 2.0)
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
|
|
43
|
+
Prop("useJsTextDialog") { (view: ExpoPdfMarkupView, use: Bool?) in
|
|
44
|
+
view.useJsTextDialog = use ?? false
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Events("onPageChanged", "onLoadComplete", "onError", "onAnnotationsChanged", "onTextInputRequested")
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
}
|
|
@@ -7,6 +7,7 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
7
7
|
let onLoadComplete = EventDispatcher()
|
|
8
8
|
let onError = EventDispatcher()
|
|
9
9
|
let onAnnotationsChanged = EventDispatcher()
|
|
10
|
+
let onTextInputRequested = EventDispatcher()
|
|
10
11
|
|
|
11
12
|
private var currentSource: String?
|
|
12
13
|
private var currentAnnotationsJSON: String?
|
|
@@ -16,7 +17,9 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
16
17
|
inkShapeLayer?.strokeColor = (AnnotationSerializer.colorFromHex(annotationColor) ?? .red).cgColor
|
|
17
18
|
}
|
|
18
19
|
}
|
|
20
|
+
|
|
19
21
|
var annotationLineWidth: CGFloat = 2.0
|
|
22
|
+
var useJsTextDialog: Bool = false
|
|
20
23
|
|
|
21
24
|
private var inkPanGesture: UIPanGestureRecognizer?
|
|
22
25
|
private var inkShapeLayer: CAShapeLayer?
|
|
@@ -27,6 +30,9 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
27
30
|
private var selectionDebounceTimer: Timer?
|
|
28
31
|
private var currentMarkupType: String?
|
|
29
32
|
|
|
33
|
+
private var pendingTextPage: PDFPage?
|
|
34
|
+
private var pendingTextPoint: CGPoint?
|
|
35
|
+
|
|
30
36
|
required init(appContext: AppContext? = nil) {
|
|
31
37
|
super.init(appContext: appContext)
|
|
32
38
|
clipsToBounds = true
|
|
@@ -467,6 +473,13 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
467
473
|
|
|
468
474
|
let pdfPoint = pdfView.convert(location, to: page)
|
|
469
475
|
|
|
476
|
+
if useJsTextDialog {
|
|
477
|
+
pendingTextPage = page
|
|
478
|
+
pendingTextPoint = pdfPoint
|
|
479
|
+
onTextInputRequested([:])
|
|
480
|
+
return
|
|
481
|
+
}
|
|
482
|
+
|
|
470
483
|
// Show text input dialog
|
|
471
484
|
guard let viewController = findViewController() else { return }
|
|
472
485
|
let alert = UIAlertController(title: "Add Text", message: nil, preferredStyle: .alert)
|
|
@@ -483,6 +496,14 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
483
496
|
viewController.present(alert, animated: true)
|
|
484
497
|
}
|
|
485
498
|
|
|
499
|
+
func provideTextInput(text: String?) {
|
|
500
|
+
guard let page = pendingTextPage, let point = pendingTextPoint else { return }
|
|
501
|
+
pendingTextPage = nil
|
|
502
|
+
pendingTextPoint = nil
|
|
503
|
+
guard let text, !text.isEmpty else { return }
|
|
504
|
+
addFreeTextAnnotation(text: text, at: point, on: page)
|
|
505
|
+
}
|
|
506
|
+
|
|
486
507
|
private func addFreeTextAnnotation(text: String, at point: CGPoint, on page: PDFPage) {
|
|
487
508
|
let fontSize: CGFloat = 16.0
|
|
488
509
|
let font = UIFont.systemFont(ofSize: fontSize)
|
|
@@ -540,6 +561,12 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
540
561
|
|
|
541
562
|
let pageIndex = document.index(for: currentPage)
|
|
542
563
|
let pageCount = document.pageCount
|
|
543
|
-
|
|
564
|
+
let bounds = currentPage.bounds(for: pdfView.displayBox)
|
|
565
|
+
onPageChanged([
|
|
566
|
+
"page": pageIndex,
|
|
567
|
+
"pageCount": pageCount,
|
|
568
|
+
"pageWidth": bounds.width,
|
|
569
|
+
"pageHeight": bounds.height,
|
|
570
|
+
])
|
|
544
571
|
}
|
|
545
572
|
}
|
package/metro.js
CHANGED
|
@@ -30,15 +30,13 @@ const path = require('path');
|
|
|
30
30
|
let _upstream = null;
|
|
31
31
|
function upstream(projectRoot) {
|
|
32
32
|
if (_upstream) return _upstream;
|
|
33
|
-
// Resolve expo
|
|
34
|
-
//
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
|
|
38
|
-
require.resolve('expo/package.json', { paths: [projectRoot] })
|
|
39
|
-
);
|
|
33
|
+
// Resolve @expo/metro-config from the consumer's project root. Using
|
|
34
|
+
// require.resolve with a paths option works in both standard installs (where
|
|
35
|
+
// @expo/metro-config is a transitive dep reachable from the project) and hoisted
|
|
36
|
+
// monorepos (where it is deduplicated to the workspace root). Hard-coding the
|
|
37
|
+
// path through expo's own node_modules directory breaks in the monorepo case.
|
|
40
38
|
_upstream = require(
|
|
41
|
-
|
|
39
|
+
require.resolve('@expo/metro-config/build/babel-transformer', { paths: [projectRoot] })
|
|
42
40
|
);
|
|
43
41
|
return _upstream;
|
|
44
42
|
}
|
package/package.json
CHANGED
|
@@ -69,12 +69,20 @@ export type ExpoPdfMarkupViewProps = {
|
|
|
69
69
|
/** Stroke width in points applied to new ink annotations. */
|
|
70
70
|
annotationLineWidth?: number;
|
|
71
71
|
/** Fired when the visible page changes. */
|
|
72
|
-
onPageChanged?: (event: {
|
|
72
|
+
onPageChanged?: (event: {
|
|
73
|
+
nativeEvent: { page: number; pageCount: number; pageWidth: number; pageHeight: number };
|
|
74
|
+
}) => void;
|
|
73
75
|
/** Fired once the document has finished loading. */
|
|
74
76
|
onLoadComplete?: (event: { nativeEvent: { pageCount: number } }) => void;
|
|
75
77
|
/** Fired when the document fails to load. */
|
|
76
78
|
onError?: (event: { nativeEvent: { message: string } }) => void;
|
|
77
79
|
/** Fired after annotations are created or edited. `annotations` is a serialised {@link AnnotationsData} JSON string. */
|
|
78
80
|
onAnnotationsChanged?: (event: { nativeEvent: { annotations: string } }) => void;
|
|
81
|
+
/**
|
|
82
|
+
* Optional async callback for the text annotation tool. When provided, this is called instead of
|
|
83
|
+
* the native platform dialog (UIAlertController / AlertDialog) when the user taps to place a text
|
|
84
|
+
* annotation. Return the text string to create the annotation, or `null` to cancel.
|
|
85
|
+
*/
|
|
86
|
+
onTextInputRequested?: () => Promise<string | null>;
|
|
79
87
|
style?: StyleProp<ViewStyle>;
|
|
80
88
|
};
|
|
@@ -1,10 +1,40 @@
|
|
|
1
|
-
import { requireNativeView } from 'expo';
|
|
1
|
+
import { requireNativeModule, requireNativeView } from 'expo';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { findNodeHandle } from 'react-native';
|
|
3
4
|
|
|
4
5
|
import { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';
|
|
5
6
|
|
|
6
|
-
|
|
7
|
+
type NativeViewProps = Omit<ExpoPdfMarkupViewProps, 'onTextInputRequested'> & {
|
|
8
|
+
useJsTextDialog?: boolean;
|
|
9
|
+
onTextInputRequested?: (event: { nativeEvent: Record<string, never> }) => void;
|
|
10
|
+
};
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
const NativeView = requireNativeView('ExpoPdfMarkup') as React.ForwardRefExoticComponent<
|
|
13
|
+
NativeViewProps & React.RefAttributes<unknown>
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
const NativeModule = requireNativeModule('ExpoPdfMarkup');
|
|
17
|
+
|
|
18
|
+
export default function ExpoPdfMarkupView({
|
|
19
|
+
onTextInputRequested,
|
|
20
|
+
...props
|
|
21
|
+
}: ExpoPdfMarkupViewProps) {
|
|
22
|
+
const nativeRef = React.useRef<unknown>(null);
|
|
23
|
+
|
|
24
|
+
const handleNativeTextInputRequested = React.useCallback(async () => {
|
|
25
|
+
if (!onTextInputRequested) return;
|
|
26
|
+
const tag = findNodeHandle(nativeRef.current as Parameters<typeof findNodeHandle>[0]);
|
|
27
|
+
if (tag == null) return;
|
|
28
|
+
const text = await onTextInputRequested();
|
|
29
|
+
await NativeModule.provideTextInput(tag, text ?? null);
|
|
30
|
+
}, [onTextInputRequested]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<NativeView
|
|
34
|
+
ref={nativeRef}
|
|
35
|
+
{...props}
|
|
36
|
+
useJsTextDialog={!!onTextInputRequested}
|
|
37
|
+
onTextInputRequested={onTextInputRequested ? handleNativeTextInputRequested : undefined}
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
10
40
|
}
|
|
@@ -22,8 +22,10 @@ import type { PdfPageMeta } from './web/types';
|
|
|
22
22
|
// Configure pdfjs worker once at module level (consumers can override before mounting)
|
|
23
23
|
if (!pdfjs.GlobalWorkerOptions.workerSrc) {
|
|
24
24
|
// Default: served from public/ by withPdfMarkup() in metro.js.
|
|
25
|
+
// Relative URL so the worker resolves correctly regardless of the sub-path
|
|
26
|
+
// the app is hosted at (e.g. /example/ on GitHub Pages).
|
|
25
27
|
// Override with setPdfJsWorkerSrc() if using a different bundler or CDN.
|
|
26
|
-
pdfjs.GlobalWorkerOptions.workerSrc = '
|
|
28
|
+
pdfjs.GlobalWorkerOptions.workerSrc = './pdf.worker.min.mjs';
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/** Allow consumers to override the pdfjs worker URL before mounting the view. */
|
|
@@ -31,6 +33,13 @@ export function setPdfJsWorkerSrc(url: string): void {
|
|
|
31
33
|
pdfjs.GlobalWorkerOptions.workerSrc = url;
|
|
32
34
|
}
|
|
33
35
|
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Zoom constants
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
const MIN_ZOOM = 1;
|
|
41
|
+
const MAX_ZOOM = 5;
|
|
42
|
+
|
|
34
43
|
// ---------------------------------------------------------------------------
|
|
35
44
|
// PageView
|
|
36
45
|
// ---------------------------------------------------------------------------
|
|
@@ -43,6 +52,7 @@ type PageViewProps = {
|
|
|
43
52
|
annotationMode: AnnotationMode;
|
|
44
53
|
annotationColor: string;
|
|
45
54
|
annotationLineWidth: number;
|
|
55
|
+
zoomLevel: number;
|
|
46
56
|
onAnnotationAdded: (annotation: Annotation) => void;
|
|
47
57
|
onAnnotationRemoved: (id: string) => void;
|
|
48
58
|
onTextInputRequested: (pageIndex: number, pdfPoint: AnnotationPoint) => void;
|
|
@@ -57,6 +67,7 @@ function PageView({
|
|
|
57
67
|
annotationMode,
|
|
58
68
|
annotationColor,
|
|
59
69
|
annotationLineWidth,
|
|
70
|
+
zoomLevel,
|
|
60
71
|
onAnnotationAdded,
|
|
61
72
|
onAnnotationRemoved,
|
|
62
73
|
onTextInputRequested,
|
|
@@ -156,7 +167,7 @@ function PageView({
|
|
|
156
167
|
|
|
157
168
|
function getCanvasPoint(e: React.PointerEvent<HTMLCanvasElement>): { x: number; y: number } {
|
|
158
169
|
const rect = (e.currentTarget as HTMLCanvasElement).getBoundingClientRect();
|
|
159
|
-
return { x: e.clientX - rect.left, y: e.clientY - rect.top };
|
|
170
|
+
return { x: (e.clientX - rect.left) / zoomLevel, y: (e.clientY - rect.top) / zoomLevel };
|
|
160
171
|
}
|
|
161
172
|
|
|
162
173
|
function handlePointerDown(e: React.PointerEvent<HTMLCanvasElement>) {
|
|
@@ -304,6 +315,7 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
304
315
|
onLoadComplete,
|
|
305
316
|
onError,
|
|
306
317
|
onAnnotationsChanged,
|
|
318
|
+
onTextInputRequested,
|
|
307
319
|
style,
|
|
308
320
|
} = props;
|
|
309
321
|
|
|
@@ -316,6 +328,8 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
316
328
|
const pageContainerRefs = React.useRef<(HTMLDivElement | null)[]>([]);
|
|
317
329
|
const docRef = React.useRef<PDFDocumentProxy | null>(null);
|
|
318
330
|
const loadingSourceRef = React.useRef<string | null>(null);
|
|
331
|
+
const [zoomLevel, setZoomLevel] = React.useState(1);
|
|
332
|
+
const zoomRef = React.useRef(1);
|
|
319
333
|
|
|
320
334
|
// ResizeObserver โ containerWidth
|
|
321
335
|
React.useEffect(() => {
|
|
@@ -329,6 +343,80 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
329
343
|
return () => ro.disconnect();
|
|
330
344
|
}, []);
|
|
331
345
|
|
|
346
|
+
// Pinch-to-zoom: intercept ctrl+wheel (trackpad pinch) and two-finger touch pinch.
|
|
347
|
+
// Zooms only the PDF content, leaving the rest of the UI at 1ร.
|
|
348
|
+
React.useEffect(() => {
|
|
349
|
+
const el = scrollContainerRef.current;
|
|
350
|
+
if (!el) return;
|
|
351
|
+
|
|
352
|
+
function applyZoom(newZoom: number, originX: number, originY: number) {
|
|
353
|
+
const clamped = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, newZoom));
|
|
354
|
+
if (clamped === zoomRef.current) return;
|
|
355
|
+
const ratio = clamped / zoomRef.current;
|
|
356
|
+
// Keep the origin point (pointer/pinch centre) stationary in the viewport.
|
|
357
|
+
const nextScrollLeft = (el!.scrollLeft + originX) * ratio - originX;
|
|
358
|
+
const nextScrollTop = (el!.scrollTop + originY) * ratio - originY;
|
|
359
|
+
zoomRef.current = clamped;
|
|
360
|
+
setZoomLevel(clamped);
|
|
361
|
+
// Apply after React re-renders so the CSS zoom is in effect before we set scroll.
|
|
362
|
+
requestAnimationFrame(() => {
|
|
363
|
+
el!.scrollLeft = Math.max(0, nextScrollLeft);
|
|
364
|
+
el!.scrollTop = Math.max(0, nextScrollTop);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function onWheel(e: WheelEvent) {
|
|
369
|
+
if (!e.ctrlKey) return;
|
|
370
|
+
e.preventDefault();
|
|
371
|
+
const rect = el!.getBoundingClientRect();
|
|
372
|
+
const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
|
|
373
|
+
applyZoom(zoomRef.current * factor, e.clientX - rect.left, e.clientY - rect.top);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
let pinchStart: { dist: number; zoom: number; midX: number; midY: number } | null = null;
|
|
377
|
+
|
|
378
|
+
function getTouchDist(touches: TouchList): number {
|
|
379
|
+
const dx = touches[0].clientX - touches[1].clientX;
|
|
380
|
+
const dy = touches[0].clientY - touches[1].clientY;
|
|
381
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function onTouchStart(e: TouchEvent) {
|
|
385
|
+
if (e.touches.length !== 2) return;
|
|
386
|
+
const rect = el!.getBoundingClientRect();
|
|
387
|
+
pinchStart = {
|
|
388
|
+
dist: getTouchDist(e.touches),
|
|
389
|
+
zoom: zoomRef.current,
|
|
390
|
+
midX: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,
|
|
391
|
+
midY: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function onTouchMove(e: TouchEvent) {
|
|
396
|
+
if (e.touches.length !== 2 || !pinchStart) return;
|
|
397
|
+
e.preventDefault();
|
|
398
|
+
const dist = getTouchDist(e.touches);
|
|
399
|
+
applyZoom(pinchStart.zoom * (dist / pinchStart.dist), pinchStart.midX, pinchStart.midY);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function onTouchEnd(e: TouchEvent) {
|
|
403
|
+
if (e.touches.length < 2) pinchStart = null;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
el.addEventListener('wheel', onWheel, { passive: false });
|
|
407
|
+
el.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
408
|
+
el.addEventListener('touchmove', onTouchMove, { passive: false });
|
|
409
|
+
el.addEventListener('touchend', onTouchEnd);
|
|
410
|
+
el.addEventListener('touchcancel', onTouchEnd);
|
|
411
|
+
return () => {
|
|
412
|
+
el.removeEventListener('wheel', onWheel);
|
|
413
|
+
el.removeEventListener('touchstart', onTouchStart);
|
|
414
|
+
el.removeEventListener('touchmove', onTouchMove);
|
|
415
|
+
el.removeEventListener('touchend', onTouchEnd);
|
|
416
|
+
el.removeEventListener('touchcancel', onTouchEnd);
|
|
417
|
+
};
|
|
418
|
+
}, []);
|
|
419
|
+
|
|
332
420
|
// Load PDF when source or containerWidth changes
|
|
333
421
|
React.useEffect(() => {
|
|
334
422
|
if (!source || containerWidth <= 0) return;
|
|
@@ -420,7 +508,14 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
420
508
|
}
|
|
421
509
|
if (topPage !== -1 && topPage !== lastReported) {
|
|
422
510
|
lastReported = topPage;
|
|
423
|
-
onPageChanged?.({
|
|
511
|
+
onPageChanged?.({
|
|
512
|
+
nativeEvent: {
|
|
513
|
+
page: topPage,
|
|
514
|
+
pageCount: doc.numPages,
|
|
515
|
+
pageWidth: pageMetas[topPage]?.pdfWidth ?? 0,
|
|
516
|
+
pageHeight: pageMetas[topPage]?.pdfHeight ?? 0,
|
|
517
|
+
},
|
|
518
|
+
});
|
|
424
519
|
}
|
|
425
520
|
},
|
|
426
521
|
{ root: scrollContainerRef.current, threshold: 0.1 }
|
|
@@ -456,8 +551,10 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
456
551
|
);
|
|
457
552
|
|
|
458
553
|
const handleTextInputRequested = React.useCallback(
|
|
459
|
-
(pageIndex: number, pdfPoint: AnnotationPoint) => {
|
|
460
|
-
const text =
|
|
554
|
+
async (pageIndex: number, pdfPoint: AnnotationPoint) => {
|
|
555
|
+
const text = onTextInputRequested
|
|
556
|
+
? await onTextInputRequested()
|
|
557
|
+
: window.prompt('Enter annotation text:');
|
|
461
558
|
if (!text) return;
|
|
462
559
|
const fontSize = 16;
|
|
463
560
|
const estimatedWidth = text.length * fontSize * 0.6;
|
|
@@ -478,7 +575,7 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
478
575
|
createdAt: Date.now(),
|
|
479
576
|
});
|
|
480
577
|
},
|
|
481
|
-
[annotationColor, handleAnnotationAdded]
|
|
578
|
+
[annotationColor, handleAnnotationAdded, onTextInputRequested]
|
|
482
579
|
);
|
|
483
580
|
|
|
484
581
|
const styleObj = style as React.CSSProperties | undefined;
|
|
@@ -488,32 +585,36 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
|
|
|
488
585
|
ref={scrollContainerRef}
|
|
489
586
|
style={{
|
|
490
587
|
overflowY: 'scroll',
|
|
588
|
+
overflowX: 'auto',
|
|
491
589
|
backgroundColor,
|
|
492
590
|
height: '100%',
|
|
493
591
|
...styleObj,
|
|
494
592
|
}}
|
|
495
593
|
>
|
|
496
|
-
{
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
<
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
594
|
+
<div style={{ zoom: zoomLevel }}>
|
|
595
|
+
{doc &&
|
|
596
|
+
pageMetas.map((meta, i) => (
|
|
597
|
+
<React.Fragment key={i}>
|
|
598
|
+
<PageView
|
|
599
|
+
doc={doc}
|
|
600
|
+
pageIndex={i}
|
|
601
|
+
meta={meta}
|
|
602
|
+
annotations={annotations}
|
|
603
|
+
annotationMode={annotationMode}
|
|
604
|
+
annotationColor={annotationColor}
|
|
605
|
+
annotationLineWidth={annotationLineWidth}
|
|
606
|
+
zoomLevel={zoomLevel}
|
|
607
|
+
onAnnotationAdded={handleAnnotationAdded}
|
|
608
|
+
onAnnotationRemoved={handleAnnotationRemoved}
|
|
609
|
+
onTextInputRequested={handleTextInputRequested}
|
|
610
|
+
containerRef={(el) => {
|
|
611
|
+
pageContainerRefs.current[i] = el;
|
|
612
|
+
}}
|
|
613
|
+
/>
|
|
614
|
+
{i < pageMetas.length - 1 && <div style={{ height: 8 }} aria-hidden />}
|
|
615
|
+
</React.Fragment>
|
|
616
|
+
))}
|
|
617
|
+
</div>
|
|
517
618
|
</div>
|
|
518
619
|
);
|
|
519
620
|
}
|