@tobyt/expo-pdf-markup 0.3.1 → 0.4.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @tobyt/expo-pdf-markup
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 519e27b: Update metro config plugin so it works in a monorepo too
8
+ - 4898177: The onPageChanged event now returns page width and height.
9
+ - 5423941: When using gestures to zoom on Web, only the PDF is zoomed in/out instead of the entire UI.
10
+
11
+ ### Patch Changes
12
+
13
+ - f15901a: Move spacer in Web implementation so it only appears inbetween pages
14
+
3
15
  ## 0.3.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -112,8 +112,8 @@ export default function App() {
112
112
  annotationLineWidth={3}
113
113
  annotations={annotations}
114
114
  onLoadComplete={({ nativeEvent: { pageCount } }) => console.log(`Loaded ${pageCount} pages`)}
115
- onPageChanged={({ nativeEvent: { page, pageCount } }) =>
116
- console.log(`Page ${page + 1} of ${pageCount}`)
115
+ onPageChanged={({ nativeEvent: { page, pageCount, pageWidth, pageHeight } }) =>
116
+ console.log(`Page ${page + 1} of ${pageCount} (${pageWidth}×${pageHeight}pt)`)
117
117
  }
118
118
  onAnnotationsChanged={({ nativeEvent }) => setAnnotations(nativeEvent.annotations)}
119
119
  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: ((page: Int, pageCount: Int) -> Unit)? = null
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
- onPageChangeListener?.invoke(page, pageBitmaps.size)
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
 
@@ -27,8 +27,15 @@ class ExpoPdfMarkupView(context: Context, appContext: AppContext) : ExpoView(con
27
27
 
28
28
  init {
29
29
  addView(pdfView)
30
- pdfView.onPageChangeListener = { page, pageCount ->
31
- onPageChanged(mapOf("page" to page, "pageCount" to pageCount))
30
+ pdfView.onPageChangeListener = { page, pageCount, pageWidth, pageHeight ->
31
+ onPageChanged(
32
+ mapOf(
33
+ "page" to page,
34
+ "pageCount" to pageCount,
35
+ "pageWidth" to pageWidth,
36
+ "pageHeight" to pageHeight
37
+ )
38
+ )
32
39
  }
33
40
  pdfView.onAnnotationsChangedListener = {
34
41
  emitAnnotationsChanged()
@@ -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. */
@@ -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;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvD,MAAM,MAAM,gBAAgB,GAAG;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CA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AC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,SAAS,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IACzE,6CAA6C;IAC7C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,OAAO,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IAChE,wHAAwH;IACxH,oBAAoB,CAAC,EAAE,CAAC,KAAK,EAAE;QAAE,WAAW,EAAE;YAAE,WAAW,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,KAAK,IAAI,CAAC;IACjF,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: { nativeEvent: { page: number; pageCount: number } }) => 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 style?: StyleProp<ViewStyle>;\n};\n"]}
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 style?: StyleProp<ViewStyle>;\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;AAmB/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AAsQD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAiOtE"}
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;AAmB/B,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAEnD;AA+QD,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,qBAwTtE"}
@@ -11,7 +11,12 @@ if (!pdfjs.GlobalWorkerOptions.workerSrc) {
11
11
  export function setPdfJsWorkerSrc(url) {
12
12
  pdfjs.GlobalWorkerOptions.workerSrc = url;
13
13
  }
14
- function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotationColor, annotationLineWidth, onAnnotationAdded, onAnnotationRemoved, onTextInputRequested, containerRef, }) {
14
+ // ---------------------------------------------------------------------------
15
+ // Zoom constants
16
+ // ---------------------------------------------------------------------------
17
+ const MIN_ZOOM = 1;
18
+ const MAX_ZOOM = 5;
19
+ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotationColor, annotationLineWidth, zoomLevel, onAnnotationAdded, onAnnotationRemoved, onTextInputRequested, containerRef, }) {
15
20
  const pdfCanvasRef = React.useRef(null);
16
21
  const annotCanvasRef = React.useRef(null);
17
22
  const pageRef = React.useRef(null);
@@ -106,7 +111,7 @@ function PageView({ doc, pageIndex, meta, annotations, annotationMode, annotatio
106
111
  }, [redrawAnnotations]);
107
112
  function getCanvasPoint(e) {
108
113
  const rect = e.currentTarget.getBoundingClientRect();
109
- return { x: e.clientX - rect.left, y: e.clientY - rect.top };
114
+ return { x: (e.clientX - rect.left) / zoomLevel, y: (e.clientY - rect.top) / zoomLevel };
110
115
  }
111
116
  function handlePointerDown(e) {
112
117
  if (annotationMode === 'none')
@@ -243,6 +248,8 @@ export default function ExpoPdfMarkupView(props) {
243
248
  const pageContainerRefs = React.useRef([]);
244
249
  const docRef = React.useRef(null);
245
250
  const loadingSourceRef = React.useRef(null);
251
+ const [zoomLevel, setZoomLevel] = React.useState(1);
252
+ const zoomRef = React.useRef(1);
246
253
  // ResizeObserver → containerWidth
247
254
  React.useEffect(() => {
248
255
  const el = scrollContainerRef.current;
@@ -255,6 +262,77 @@ export default function ExpoPdfMarkupView(props) {
255
262
  ro.observe(el);
256
263
  return () => ro.disconnect();
257
264
  }, []);
265
+ // Pinch-to-zoom: intercept ctrl+wheel (trackpad pinch) and two-finger touch pinch.
266
+ // Zooms only the PDF content, leaving the rest of the UI at 1×.
267
+ React.useEffect(() => {
268
+ const el = scrollContainerRef.current;
269
+ if (!el)
270
+ return;
271
+ function applyZoom(newZoom, originX, originY) {
272
+ const clamped = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, newZoom));
273
+ if (clamped === zoomRef.current)
274
+ return;
275
+ const ratio = clamped / zoomRef.current;
276
+ // Keep the origin point (pointer/pinch centre) stationary in the viewport.
277
+ const nextScrollLeft = (el.scrollLeft + originX) * ratio - originX;
278
+ const nextScrollTop = (el.scrollTop + originY) * ratio - originY;
279
+ zoomRef.current = clamped;
280
+ setZoomLevel(clamped);
281
+ // Apply after React re-renders so the CSS zoom is in effect before we set scroll.
282
+ requestAnimationFrame(() => {
283
+ el.scrollLeft = Math.max(0, nextScrollLeft);
284
+ el.scrollTop = Math.max(0, nextScrollTop);
285
+ });
286
+ }
287
+ function onWheel(e) {
288
+ if (!e.ctrlKey)
289
+ return;
290
+ e.preventDefault();
291
+ const rect = el.getBoundingClientRect();
292
+ const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
293
+ applyZoom(zoomRef.current * factor, e.clientX - rect.left, e.clientY - rect.top);
294
+ }
295
+ let pinchStart = null;
296
+ function getTouchDist(touches) {
297
+ const dx = touches[0].clientX - touches[1].clientX;
298
+ const dy = touches[0].clientY - touches[1].clientY;
299
+ return Math.sqrt(dx * dx + dy * dy);
300
+ }
301
+ function onTouchStart(e) {
302
+ if (e.touches.length !== 2)
303
+ return;
304
+ const rect = el.getBoundingClientRect();
305
+ pinchStart = {
306
+ dist: getTouchDist(e.touches),
307
+ zoom: zoomRef.current,
308
+ midX: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,
309
+ midY: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,
310
+ };
311
+ }
312
+ function onTouchMove(e) {
313
+ if (e.touches.length !== 2 || !pinchStart)
314
+ return;
315
+ e.preventDefault();
316
+ const dist = getTouchDist(e.touches);
317
+ applyZoom(pinchStart.zoom * (dist / pinchStart.dist), pinchStart.midX, pinchStart.midY);
318
+ }
319
+ function onTouchEnd(e) {
320
+ if (e.touches.length < 2)
321
+ pinchStart = null;
322
+ }
323
+ el.addEventListener('wheel', onWheel, { passive: false });
324
+ el.addEventListener('touchstart', onTouchStart, { passive: true });
325
+ el.addEventListener('touchmove', onTouchMove, { passive: false });
326
+ el.addEventListener('touchend', onTouchEnd);
327
+ el.addEventListener('touchcancel', onTouchEnd);
328
+ return () => {
329
+ el.removeEventListener('wheel', onWheel);
330
+ el.removeEventListener('touchstart', onTouchStart);
331
+ el.removeEventListener('touchmove', onTouchMove);
332
+ el.removeEventListener('touchend', onTouchEnd);
333
+ el.removeEventListener('touchcancel', onTouchEnd);
334
+ };
335
+ }, []);
258
336
  // Load PDF when source or containerWidth changes
259
337
  React.useEffect(() => {
260
338
  if (!source || containerWidth <= 0)
@@ -347,7 +425,14 @@ export default function ExpoPdfMarkupView(props) {
347
425
  }
348
426
  if (topPage !== -1 && topPage !== lastReported) {
349
427
  lastReported = topPage;
350
- onPageChanged?.({ nativeEvent: { page: topPage, pageCount: doc.numPages } });
428
+ onPageChanged?.({
429
+ nativeEvent: {
430
+ page: topPage,
431
+ pageCount: doc.numPages,
432
+ pageWidth: pageMetas[topPage]?.pdfWidth ?? 0,
433
+ pageHeight: pageMetas[topPage]?.pdfHeight ?? 0,
434
+ },
435
+ });
351
436
  }
352
437
  }, { root: scrollContainerRef.current, threshold: 0.1 });
353
438
  for (const el of els)
@@ -398,17 +483,20 @@ export default function ExpoPdfMarkupView(props) {
398
483
  const styleObj = style;
399
484
  return (<div ref={scrollContainerRef} style={{
400
485
  overflowY: 'scroll',
486
+ overflowX: 'auto',
401
487
  backgroundColor,
402
488
  height: '100%',
403
489
  ...styleObj,
404
490
  }}>
405
- {doc &&
491
+ <div style={{ zoom: zoomLevel }}>
492
+ {doc &&
406
493
  pageMetas.map((meta, i) => (<React.Fragment key={i}>
407
- <div style={{ height: 8 }} aria-hidden/>
408
- <PageView doc={doc} pageIndex={i} meta={meta} annotations={annotations} annotationMode={annotationMode} annotationColor={annotationColor} annotationLineWidth={annotationLineWidth} onAnnotationAdded={handleAnnotationAdded} onAnnotationRemoved={handleAnnotationRemoved} onTextInputRequested={handleTextInputRequested} containerRef={(el) => {
494
+ <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
495
  pageContainerRefs.current[i] = el;
410
496
  }}/>
411
- </React.Fragment>))}
497
+ {i < pageMetas.length - 1 && <div style={{ height: 8 }} aria-hidden/>}
498
+ </React.Fragment>))}
499
+ </div>
412
500
  </div>);
413
501
  }
414
502
  //# 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,EACv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C,CAAC,CAAC,CACrB;YAAA,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,WAAW,EACtC;YAAA,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,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,EAEN;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,E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BACpC,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 // 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 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 (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 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"]}
@@ -16,6 +16,7 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
16
16
  inkShapeLayer?.strokeColor = (AnnotationSerializer.colorFromHex(annotationColor) ?? .red).cgColor
17
17
  }
18
18
  }
19
+
19
20
  var annotationLineWidth: CGFloat = 2.0
20
21
 
21
22
  private var inkPanGesture: UIPanGestureRecognizer?
@@ -540,6 +541,12 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
540
541
 
541
542
  let pageIndex = document.index(for: currentPage)
542
543
  let pageCount = document.pageCount
543
- onPageChanged(["page": pageIndex, "pageCount": pageCount])
544
+ let bounds = currentPage.bounds(for: pdfView.displayBox)
545
+ onPageChanged([
546
+ "page": pageIndex,
547
+ "pageCount": pageCount,
548
+ "pageWidth": bounds.width,
549
+ "pageHeight": bounds.height,
550
+ ])
544
551
  }
545
552
  }
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 relative to the *consumer's* project root (passed via options),
34
- // not relative to this file's location. This file lives inside the library
35
- // package which may have its own copy of expo without @expo/metro-config nested
36
- // inside it.
37
- const expoDir = path.dirname(
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
- path.join(expoDir, 'node_modules/@expo/metro-config/build/babel-transformer')
39
+ require.resolve('@expo/metro-config/build/babel-transformer', { paths: [projectRoot] })
42
40
  );
43
41
  return _upstream;
44
42
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tobyt/expo-pdf-markup",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "An Expo module for displaying and annotating PDFs",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -69,7 +69,9 @@ 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: { nativeEvent: { page: number; pageCount: number } }) => void;
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. */
@@ -31,6 +31,13 @@ export function setPdfJsWorkerSrc(url: string): void {
31
31
  pdfjs.GlobalWorkerOptions.workerSrc = url;
32
32
  }
33
33
 
34
+ // ---------------------------------------------------------------------------
35
+ // Zoom constants
36
+ // ---------------------------------------------------------------------------
37
+
38
+ const MIN_ZOOM = 1;
39
+ const MAX_ZOOM = 5;
40
+
34
41
  // ---------------------------------------------------------------------------
35
42
  // PageView
36
43
  // ---------------------------------------------------------------------------
@@ -43,6 +50,7 @@ type PageViewProps = {
43
50
  annotationMode: AnnotationMode;
44
51
  annotationColor: string;
45
52
  annotationLineWidth: number;
53
+ zoomLevel: number;
46
54
  onAnnotationAdded: (annotation: Annotation) => void;
47
55
  onAnnotationRemoved: (id: string) => void;
48
56
  onTextInputRequested: (pageIndex: number, pdfPoint: AnnotationPoint) => void;
@@ -57,6 +65,7 @@ function PageView({
57
65
  annotationMode,
58
66
  annotationColor,
59
67
  annotationLineWidth,
68
+ zoomLevel,
60
69
  onAnnotationAdded,
61
70
  onAnnotationRemoved,
62
71
  onTextInputRequested,
@@ -156,7 +165,7 @@ function PageView({
156
165
 
157
166
  function getCanvasPoint(e: React.PointerEvent<HTMLCanvasElement>): { x: number; y: number } {
158
167
  const rect = (e.currentTarget as HTMLCanvasElement).getBoundingClientRect();
159
- return { x: e.clientX - rect.left, y: e.clientY - rect.top };
168
+ return { x: (e.clientX - rect.left) / zoomLevel, y: (e.clientY - rect.top) / zoomLevel };
160
169
  }
161
170
 
162
171
  function handlePointerDown(e: React.PointerEvent<HTMLCanvasElement>) {
@@ -316,6 +325,8 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
316
325
  const pageContainerRefs = React.useRef<(HTMLDivElement | null)[]>([]);
317
326
  const docRef = React.useRef<PDFDocumentProxy | null>(null);
318
327
  const loadingSourceRef = React.useRef<string | null>(null);
328
+ const [zoomLevel, setZoomLevel] = React.useState(1);
329
+ const zoomRef = React.useRef(1);
319
330
 
320
331
  // ResizeObserver → containerWidth
321
332
  React.useEffect(() => {
@@ -329,6 +340,80 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
329
340
  return () => ro.disconnect();
330
341
  }, []);
331
342
 
343
+ // Pinch-to-zoom: intercept ctrl+wheel (trackpad pinch) and two-finger touch pinch.
344
+ // Zooms only the PDF content, leaving the rest of the UI at 1×.
345
+ React.useEffect(() => {
346
+ const el = scrollContainerRef.current;
347
+ if (!el) return;
348
+
349
+ function applyZoom(newZoom: number, originX: number, originY: number) {
350
+ const clamped = Math.max(MIN_ZOOM, Math.min(MAX_ZOOM, newZoom));
351
+ if (clamped === zoomRef.current) return;
352
+ const ratio = clamped / zoomRef.current;
353
+ // Keep the origin point (pointer/pinch centre) stationary in the viewport.
354
+ const nextScrollLeft = (el!.scrollLeft + originX) * ratio - originX;
355
+ const nextScrollTop = (el!.scrollTop + originY) * ratio - originY;
356
+ zoomRef.current = clamped;
357
+ setZoomLevel(clamped);
358
+ // Apply after React re-renders so the CSS zoom is in effect before we set scroll.
359
+ requestAnimationFrame(() => {
360
+ el!.scrollLeft = Math.max(0, nextScrollLeft);
361
+ el!.scrollTop = Math.max(0, nextScrollTop);
362
+ });
363
+ }
364
+
365
+ function onWheel(e: WheelEvent) {
366
+ if (!e.ctrlKey) return;
367
+ e.preventDefault();
368
+ const rect = el!.getBoundingClientRect();
369
+ const factor = e.deltaY < 0 ? 1.1 : 1 / 1.1;
370
+ applyZoom(zoomRef.current * factor, e.clientX - rect.left, e.clientY - rect.top);
371
+ }
372
+
373
+ let pinchStart: { dist: number; zoom: number; midX: number; midY: number } | null = null;
374
+
375
+ function getTouchDist(touches: TouchList): number {
376
+ const dx = touches[0].clientX - touches[1].clientX;
377
+ const dy = touches[0].clientY - touches[1].clientY;
378
+ return Math.sqrt(dx * dx + dy * dy);
379
+ }
380
+
381
+ function onTouchStart(e: TouchEvent) {
382
+ if (e.touches.length !== 2) return;
383
+ const rect = el!.getBoundingClientRect();
384
+ pinchStart = {
385
+ dist: getTouchDist(e.touches),
386
+ zoom: zoomRef.current,
387
+ midX: (e.touches[0].clientX + e.touches[1].clientX) / 2 - rect.left,
388
+ midY: (e.touches[0].clientY + e.touches[1].clientY) / 2 - rect.top,
389
+ };
390
+ }
391
+
392
+ function onTouchMove(e: TouchEvent) {
393
+ if (e.touches.length !== 2 || !pinchStart) return;
394
+ e.preventDefault();
395
+ const dist = getTouchDist(e.touches);
396
+ applyZoom(pinchStart.zoom * (dist / pinchStart.dist), pinchStart.midX, pinchStart.midY);
397
+ }
398
+
399
+ function onTouchEnd(e: TouchEvent) {
400
+ if (e.touches.length < 2) pinchStart = null;
401
+ }
402
+
403
+ el.addEventListener('wheel', onWheel, { passive: false });
404
+ el.addEventListener('touchstart', onTouchStart, { passive: true });
405
+ el.addEventListener('touchmove', onTouchMove, { passive: false });
406
+ el.addEventListener('touchend', onTouchEnd);
407
+ el.addEventListener('touchcancel', onTouchEnd);
408
+ return () => {
409
+ el.removeEventListener('wheel', onWheel);
410
+ el.removeEventListener('touchstart', onTouchStart);
411
+ el.removeEventListener('touchmove', onTouchMove);
412
+ el.removeEventListener('touchend', onTouchEnd);
413
+ el.removeEventListener('touchcancel', onTouchEnd);
414
+ };
415
+ }, []);
416
+
332
417
  // Load PDF when source or containerWidth changes
333
418
  React.useEffect(() => {
334
419
  if (!source || containerWidth <= 0) return;
@@ -420,7 +505,14 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
420
505
  }
421
506
  if (topPage !== -1 && topPage !== lastReported) {
422
507
  lastReported = topPage;
423
- onPageChanged?.({ nativeEvent: { page: topPage, pageCount: doc.numPages } });
508
+ onPageChanged?.({
509
+ nativeEvent: {
510
+ page: topPage,
511
+ pageCount: doc.numPages,
512
+ pageWidth: pageMetas[topPage]?.pdfWidth ?? 0,
513
+ pageHeight: pageMetas[topPage]?.pdfHeight ?? 0,
514
+ },
515
+ });
424
516
  }
425
517
  },
426
518
  { root: scrollContainerRef.current, threshold: 0.1 }
@@ -488,32 +580,36 @@ export default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {
488
580
  ref={scrollContainerRef}
489
581
  style={{
490
582
  overflowY: 'scroll',
583
+ overflowX: 'auto',
491
584
  backgroundColor,
492
585
  height: '100%',
493
586
  ...styleObj,
494
587
  }}
495
588
  >
496
- {doc &&
497
- pageMetas.map((meta, i) => (
498
- <React.Fragment key={i}>
499
- <div style={{ height: 8 }} aria-hidden />
500
- <PageView
501
- doc={doc}
502
- pageIndex={i}
503
- meta={meta}
504
- annotations={annotations}
505
- annotationMode={annotationMode}
506
- annotationColor={annotationColor}
507
- annotationLineWidth={annotationLineWidth}
508
- onAnnotationAdded={handleAnnotationAdded}
509
- onAnnotationRemoved={handleAnnotationRemoved}
510
- onTextInputRequested={handleTextInputRequested}
511
- containerRef={(el) => {
512
- pageContainerRefs.current[i] = el;
513
- }}
514
- />
515
- </React.Fragment>
516
- ))}
589
+ <div style={{ zoom: zoomLevel }}>
590
+ {doc &&
591
+ pageMetas.map((meta, i) => (
592
+ <React.Fragment key={i}>
593
+ <PageView
594
+ doc={doc}
595
+ pageIndex={i}
596
+ meta={meta}
597
+ annotations={annotations}
598
+ annotationMode={annotationMode}
599
+ annotationColor={annotationColor}
600
+ annotationLineWidth={annotationLineWidth}
601
+ zoomLevel={zoomLevel}
602
+ onAnnotationAdded={handleAnnotationAdded}
603
+ onAnnotationRemoved={handleAnnotationRemoved}
604
+ onTextInputRequested={handleTextInputRequested}
605
+ containerRef={(el) => {
606
+ pageContainerRefs.current[i] = el;
607
+ }}
608
+ />
609
+ {i < pageMetas.length - 1 && <div style={{ height: 8 }} aria-hidden />}
610
+ </React.Fragment>
611
+ ))}
612
+ </div>
517
613
  </div>
518
614
  );
519
615
  }