@tobyt/expo-pdf-markup 0.2.3 → 0.3.1
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 +16 -0
- package/README.md +85 -4
- package/build/ExpoPdfMarkup.types.d.ts +1 -1
- package/build/ExpoPdfMarkup.types.d.ts.map +1 -1
- package/build/ExpoPdfMarkup.types.js.map +1 -1
- package/build/ExpoPdfMarkupView.web.d.ts +3 -1
- package/build/ExpoPdfMarkupView.web.d.ts.map +1 -1
- package/build/ExpoPdfMarkupView.web.js +410 -4
- package/build/ExpoPdfMarkupView.web.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -0
- package/build/index.js.map +1 -1
- package/build/pdfjs.d.ts +2 -0
- package/build/pdfjs.d.ts.map +1 -0
- package/build/pdfjs.js +6 -0
- package/build/pdfjs.js.map +1 -0
- package/build/pdfjs.web.d.ts +2 -0
- package/build/pdfjs.web.d.ts.map +1 -0
- package/build/pdfjs.web.js +2 -0
- package/build/pdfjs.web.js.map +1 -0
- package/build/web/annotationUtils.d.ts +37 -0
- package/build/web/annotationUtils.d.ts.map +1 -0
- package/build/web/annotationUtils.js +213 -0
- package/build/web/annotationUtils.js.map +1 -0
- package/build/web/types.d.ts +13 -0
- package/build/web/types.d.ts.map +1 -0
- package/build/web/types.js +2 -0
- package/build/web/types.js.map +1 -0
- package/ios/ExpoPdfMarkupView.swift +5 -1
- package/metro.d.ts +5 -0
- package/metro.js +90 -0
- package/package.json +8 -1
- package/src/ExpoPdfMarkup.types.ts +1 -1
- package/src/ExpoPdfMarkupView.web.tsx +512 -5
- package/src/index.ts +1 -0
- package/src/pdfjs.ts +5 -0
- package/src/pdfjs.web.ts +1 -0
- package/src/web/annotationUtils.ts +257 -0
- package/src/web/types.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoPdfMarkupView.web.js","sourceRoot":"","sources":["../src/ExpoPdfMarkupView.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAI1C,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAA6B;IACrE,OAAO,CACL,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CACtF;MAAA,CAAC,IAAI,CAAC,wCAAwC,EAAE,IAAI,CACtD;IAAA,EAAE,IAAI,CAAC,CACR,CAAC;AACJ,CAAC","sourcesContent":["import * as React from 'react';\nimport { Text, View } from 'react-native';\n\nimport { ExpoPdfMarkupViewProps } from './ExpoPdfMarkup.types';\n\nexport default function ExpoPdfMarkupView(props: ExpoPdfMarkupViewProps) {\n return (\n <View style={[{ flex: 1, alignItems: 'center', justifyContent: 'center' }, props.style]}>\n <Text>PDF viewing is not yet supported on web.</Text>\n </View>\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,yEAAyE;IACzE,KAAK,CAAC,mBAAmB,CAAC,SAAS,GAAG,qBAAqB,CAAC;AAC9D,CAAC;AAED,iFAAiF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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"]}
|
package/build/index.d.ts
CHANGED
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,cAAc,uBAAuB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,cAAc,uBAAuB,CAAC"}
|
package/build/index.js
CHANGED
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,cAAc,uBAAuB,CAAC","sourcesContent":["export { default as ExpoPdfMarkupView } from './ExpoPdfMarkupView';\nexport * from './ExpoPdfMarkup.types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAC5C,cAAc,uBAAuB,CAAC","sourcesContent":["export { default as ExpoPdfMarkupView } from './ExpoPdfMarkupView';\nexport { setPdfJsWorkerSrc } from './pdfjs';\nexport * from './ExpoPdfMarkup.types';\n"]}
|
package/build/pdfjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfjs.d.ts","sourceRoot":"","sources":["../src/pdfjs.ts"],"names":[],"mappings":"AAEA,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAEpD"}
|
package/build/pdfjs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfjs.js","sourceRoot":"","sources":["../src/pdfjs.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,6DAA6D;AAC7D,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,kBAAkB;AACpB,CAAC","sourcesContent":["// Native stub — pdfjs-dist is not available on iOS/Android.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function setPdfJsWorkerSrc(_url: string): void {\n // no-op on native\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfjs.web.d.ts","sourceRoot":"","sources":["../src/pdfjs.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pdfjs.web.js","sourceRoot":"","sources":["../src/pdfjs.web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["export { setPdfJsWorkerSrc } from './ExpoPdfMarkupView.web';\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Annotation, AnnotationBounds, AnnotationPoint, AnnotationsData } from '../ExpoPdfMarkup.types';
|
|
2
|
+
import type { PdfPageMeta } from './types';
|
|
3
|
+
/** Convert canvas pixel coords → PDF user-space coords (y-up) */
|
|
4
|
+
export declare function canvasToPdf(canvasX: number, canvasY: number, scale: number, pageHeight: number): AnnotationPoint;
|
|
5
|
+
/** Convert PDF user-space coords (y-up) → canvas pixel coords */
|
|
6
|
+
export declare function pdfToCanvas(pdfX: number, pdfY: number, scale: number, pageHeight: number): {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Convert a PDF bounds rect (y-up, y = bottom edge) → canvas rect (y-down, y = top edge).
|
|
12
|
+
* All values are in CSS pixels (not physical pixels).
|
|
13
|
+
*/
|
|
14
|
+
export declare function pdfBoundsToCanvas(bounds: AnnotationBounds, scale: number, pageHeight: number): {
|
|
15
|
+
x: number;
|
|
16
|
+
y: number;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Convert a canvas drag rect (minX/Y, maxX/Y in CSS pixels) → PDF bounds (y-up).
|
|
22
|
+
* `bounds.y` is the bottom edge in PDF space, consistent with iOS/Android.
|
|
23
|
+
*/
|
|
24
|
+
export declare function canvasRectToPdfBounds(minX: number, minY: number, maxX: number, maxY: number, scale: number, pageHeight: number): AnnotationBounds;
|
|
25
|
+
export declare function distanceToSegment(point: AnnotationPoint, a: AnnotationPoint, b: AnnotationPoint): number;
|
|
26
|
+
/** Return the topmost annotation hit at pdfPoint on pageIndex, or null. */
|
|
27
|
+
export declare function hitTestAnnotation(pdfPoint: AnnotationPoint, annotations: Annotation[], pageIndex: number): Annotation | null;
|
|
28
|
+
/**
|
|
29
|
+
* Draw all annotations for pageIndex onto ctx.
|
|
30
|
+
* meta.scale is CSS-pixels-per-PDF-point; canvas backing = CSS * devicePixelRatio,
|
|
31
|
+
* but the caller should have called ctx.scale(dpr, dpr) so we work in CSS pixels here.
|
|
32
|
+
*/
|
|
33
|
+
export declare function drawAnnotationsOnCanvas(ctx: CanvasRenderingContext2D, annotations: Annotation[], pageIndex: number, meta: PdfPageMeta): void;
|
|
34
|
+
export declare function parseAnnotations(json?: string): AnnotationsData;
|
|
35
|
+
export declare function serializeAnnotations(data: AnnotationsData): string;
|
|
36
|
+
export declare function newAnnotationId(): string;
|
|
37
|
+
//# sourceMappingURL=annotationUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotationUtils.d.ts","sourceRoot":"","sources":["../../src/web/annotationUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,eAAe,EAChB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM3C,iEAAiE;AACjE,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,eAAe,CAKjB;AAED,iEAAiE;AACjE,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAA;CAAE,CAK1B;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB;IAAE,CAAC,EAAE,MAAM,CAAC;IAAC,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAOzD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GACjB,gBAAgB,CAOlB;AAMD,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,eAAe,EACtB,CAAC,EAAE,eAAe,EAClB,CAAC,EAAE,eAAe,GACjB,MAAM,CAgBR;AAWD,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,eAAe,EACzB,WAAW,EAAE,UAAU,EAAE,EACzB,SAAS,EAAE,MAAM,GAChB,UAAU,GAAG,IAAI,CAyBnB;AAMD;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,GAAG,EAAE,wBAAwB,EAC7B,WAAW,EAAE,UAAU,EAAE,EACzB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,WAAW,GAChB,IAAI,CAqEN;AAMD,wBAAgB,gBAAgB,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,eAAe,CAc/D;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,CAElE;AAED,wBAAgB,eAAe,IAAI,MAAM,CAKxC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Coordinate transforms
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
/** Convert canvas pixel coords → PDF user-space coords (y-up) */
|
|
5
|
+
export function canvasToPdf(canvasX, canvasY, scale, pageHeight) {
|
|
6
|
+
return {
|
|
7
|
+
x: canvasX / scale,
|
|
8
|
+
y: pageHeight - canvasY / scale,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Convert PDF user-space coords (y-up) → canvas pixel coords */
|
|
12
|
+
export function pdfToCanvas(pdfX, pdfY, scale, pageHeight) {
|
|
13
|
+
return {
|
|
14
|
+
x: pdfX * scale,
|
|
15
|
+
y: (pageHeight - pdfY) * scale,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Convert a PDF bounds rect (y-up, y = bottom edge) → canvas rect (y-down, y = top edge).
|
|
20
|
+
* All values are in CSS pixels (not physical pixels).
|
|
21
|
+
*/
|
|
22
|
+
export function pdfBoundsToCanvas(bounds, scale, pageHeight) {
|
|
23
|
+
return {
|
|
24
|
+
x: bounds.x * scale,
|
|
25
|
+
y: (pageHeight - bounds.y - bounds.height) * scale,
|
|
26
|
+
width: bounds.width * scale,
|
|
27
|
+
height: bounds.height * scale,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Convert a canvas drag rect (minX/Y, maxX/Y in CSS pixels) → PDF bounds (y-up).
|
|
32
|
+
* `bounds.y` is the bottom edge in PDF space, consistent with iOS/Android.
|
|
33
|
+
*/
|
|
34
|
+
export function canvasRectToPdfBounds(minX, minY, maxX, maxY, scale, pageHeight) {
|
|
35
|
+
return {
|
|
36
|
+
x: minX / scale,
|
|
37
|
+
y: pageHeight - maxY / scale,
|
|
38
|
+
width: (maxX - minX) / scale,
|
|
39
|
+
height: (maxY - minY) / scale,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Hit testing (ported from AnnotationHitTester.kt)
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
export function distanceToSegment(point, a, b) {
|
|
46
|
+
const dx = b.x - a.x;
|
|
47
|
+
const dy = b.y - a.y;
|
|
48
|
+
const lenSq = dx * dx + dy * dy;
|
|
49
|
+
if (lenSq === 0) {
|
|
50
|
+
const px = point.x - a.x;
|
|
51
|
+
const py = point.y - a.y;
|
|
52
|
+
return Math.sqrt(px * px + py * py);
|
|
53
|
+
}
|
|
54
|
+
let t = ((point.x - a.x) * dx + (point.y - a.y) * dy) / lenSq;
|
|
55
|
+
t = Math.max(0, Math.min(1, t));
|
|
56
|
+
const projX = a.x + t * dx;
|
|
57
|
+
const projY = a.y + t * dy;
|
|
58
|
+
const ex = point.x - projX;
|
|
59
|
+
const ey = point.y - projY;
|
|
60
|
+
return Math.sqrt(ex * ex + ey * ey);
|
|
61
|
+
}
|
|
62
|
+
function boundsContains(bounds, point) {
|
|
63
|
+
return (point.x >= bounds.x &&
|
|
64
|
+
point.x <= bounds.x + bounds.width &&
|
|
65
|
+
point.y >= bounds.y &&
|
|
66
|
+
point.y <= bounds.y + bounds.height);
|
|
67
|
+
}
|
|
68
|
+
/** Return the topmost annotation hit at pdfPoint on pageIndex, or null. */
|
|
69
|
+
export function hitTestAnnotation(pdfPoint, annotations, pageIndex) {
|
|
70
|
+
const onPage = annotations.filter((a) => a.page === pageIndex);
|
|
71
|
+
for (let i = onPage.length - 1; i >= 0; i--) {
|
|
72
|
+
const annotation = onPage[i];
|
|
73
|
+
if (annotation.type === 'ink') {
|
|
74
|
+
const tolerance = Math.max(annotation.lineWidth ?? 2, 10);
|
|
75
|
+
const paths = annotation.paths ?? [];
|
|
76
|
+
for (const stroke of paths) {
|
|
77
|
+
if (stroke.length === 1) {
|
|
78
|
+
const dx = pdfPoint.x - stroke[0].x;
|
|
79
|
+
const dy = pdfPoint.y - stroke[0].y;
|
|
80
|
+
if (Math.sqrt(dx * dx + dy * dy) <= tolerance)
|
|
81
|
+
return annotation;
|
|
82
|
+
}
|
|
83
|
+
for (let j = 0; j < stroke.length - 1; j++) {
|
|
84
|
+
if (distanceToSegment(pdfPoint, stroke[j], stroke[j + 1]) <= tolerance) {
|
|
85
|
+
return annotation;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
const bounds = annotation.bounds;
|
|
92
|
+
if (bounds && boundsContains(bounds, pdfPoint))
|
|
93
|
+
return annotation;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
// ---------------------------------------------------------------------------
|
|
99
|
+
// Canvas drawing (mirrors AnnotationRenderer.kt)
|
|
100
|
+
// ---------------------------------------------------------------------------
|
|
101
|
+
/**
|
|
102
|
+
* Draw all annotations for pageIndex onto ctx.
|
|
103
|
+
* meta.scale is CSS-pixels-per-PDF-point; canvas backing = CSS * devicePixelRatio,
|
|
104
|
+
* but the caller should have called ctx.scale(dpr, dpr) so we work in CSS pixels here.
|
|
105
|
+
*/
|
|
106
|
+
export function drawAnnotationsOnCanvas(ctx, annotations, pageIndex, meta) {
|
|
107
|
+
const { scale, pdfHeight } = meta;
|
|
108
|
+
for (const annotation of annotations) {
|
|
109
|
+
if (annotation.page !== pageIndex)
|
|
110
|
+
continue;
|
|
111
|
+
switch (annotation.type) {
|
|
112
|
+
case 'ink': {
|
|
113
|
+
const paths = annotation.paths ?? [];
|
|
114
|
+
ctx.save();
|
|
115
|
+
ctx.strokeStyle = annotation.color;
|
|
116
|
+
ctx.lineWidth = (annotation.lineWidth ?? 2) * scale;
|
|
117
|
+
ctx.lineCap = 'round';
|
|
118
|
+
ctx.lineJoin = 'round';
|
|
119
|
+
for (const stroke of paths) {
|
|
120
|
+
if (stroke.length === 0)
|
|
121
|
+
continue;
|
|
122
|
+
ctx.beginPath();
|
|
123
|
+
for (let i = 0; i < stroke.length; i++) {
|
|
124
|
+
const { x, y } = pdfToCanvas(stroke[i].x, stroke[i].y, scale, pdfHeight);
|
|
125
|
+
if (i === 0)
|
|
126
|
+
ctx.moveTo(x, y);
|
|
127
|
+
else
|
|
128
|
+
ctx.lineTo(x, y);
|
|
129
|
+
}
|
|
130
|
+
ctx.stroke();
|
|
131
|
+
}
|
|
132
|
+
ctx.restore();
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
case 'highlight': {
|
|
136
|
+
const bounds = annotation.bounds;
|
|
137
|
+
if (!bounds)
|
|
138
|
+
break;
|
|
139
|
+
const rect = pdfBoundsToCanvas(bounds, scale, pdfHeight);
|
|
140
|
+
ctx.save();
|
|
141
|
+
ctx.globalAlpha = annotation.alpha ?? 0.5;
|
|
142
|
+
ctx.fillStyle = annotation.color;
|
|
143
|
+
ctx.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
144
|
+
ctx.restore();
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case 'underline': {
|
|
148
|
+
const bounds = annotation.bounds;
|
|
149
|
+
if (!bounds)
|
|
150
|
+
break;
|
|
151
|
+
// Underline sits at the bottom of bounds (PDF y = bounds.y = bottom edge)
|
|
152
|
+
const left = bounds.x * scale;
|
|
153
|
+
const bottom = (pdfHeight - bounds.y) * scale;
|
|
154
|
+
const right = left + bounds.width * scale;
|
|
155
|
+
ctx.save();
|
|
156
|
+
ctx.strokeStyle = annotation.color;
|
|
157
|
+
ctx.lineWidth = scale;
|
|
158
|
+
ctx.beginPath();
|
|
159
|
+
ctx.moveTo(left, bottom);
|
|
160
|
+
ctx.lineTo(right, bottom);
|
|
161
|
+
ctx.stroke();
|
|
162
|
+
ctx.restore();
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case 'text':
|
|
166
|
+
case 'freeText': {
|
|
167
|
+
const bounds = annotation.bounds;
|
|
168
|
+
const text = annotation.contents;
|
|
169
|
+
if (!bounds || !text)
|
|
170
|
+
break;
|
|
171
|
+
const fontSize = (annotation.fontSize ?? 16) * scale;
|
|
172
|
+
ctx.save();
|
|
173
|
+
ctx.fillStyle = annotation.color;
|
|
174
|
+
ctx.font = `${fontSize}px sans-serif`;
|
|
175
|
+
const canvasTop = (pdfHeight - bounds.y - bounds.height) * scale;
|
|
176
|
+
ctx.fillText(text, bounds.x * scale, canvasTop + fontSize);
|
|
177
|
+
ctx.restore();
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
// ---------------------------------------------------------------------------
|
|
184
|
+
// Serialization
|
|
185
|
+
// ---------------------------------------------------------------------------
|
|
186
|
+
export function parseAnnotations(json) {
|
|
187
|
+
if (!json)
|
|
188
|
+
return { version: 1, annotations: [] };
|
|
189
|
+
try {
|
|
190
|
+
const data = JSON.parse(json);
|
|
191
|
+
if (!Array.isArray(data?.annotations))
|
|
192
|
+
return { version: 1, annotations: [] };
|
|
193
|
+
// Deduplicate by id — last wins
|
|
194
|
+
const seen = new Map();
|
|
195
|
+
for (const a of data.annotations) {
|
|
196
|
+
seen.set(a.id, a);
|
|
197
|
+
}
|
|
198
|
+
return { version: 1, annotations: Array.from(seen.values()) };
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
return { version: 1, annotations: [] };
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
export function serializeAnnotations(data) {
|
|
205
|
+
return JSON.stringify(data);
|
|
206
|
+
}
|
|
207
|
+
export function newAnnotationId() {
|
|
208
|
+
if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {
|
|
209
|
+
return crypto.randomUUID();
|
|
210
|
+
}
|
|
211
|
+
return Math.random().toString(36).slice(2) + Date.now().toString(36);
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=annotationUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotationUtils.js","sourceRoot":"","sources":["../../src/web/annotationUtils.ts"],"names":[],"mappings":"AAQA,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E,iEAAiE;AACjE,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,OAAe,EACf,KAAa,EACb,UAAkB;IAElB,OAAO;QACL,CAAC,EAAE,OAAO,GAAG,K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ED,MAAM,UAAU,eAAe;IAC7B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;QAC7E,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type {\n Annotation,\n AnnotationBounds,\n AnnotationPoint,\n AnnotationsData,\n} from '../ExpoPdfMarkup.types';\nimport type { PdfPageMeta } from './types';\n\n// ---------------------------------------------------------------------------\n// Coordinate transforms\n// ---------------------------------------------------------------------------\n\n/** Convert canvas pixel coords → PDF user-space coords (y-up) */\nexport function canvasToPdf(\n canvasX: number,\n canvasY: number,\n scale: number,\n pageHeight: number\n): AnnotationPoint {\n return {\n x: canvasX / scale,\n y: pageHeight - canvasY / scale,\n };\n}\n\n/** Convert PDF user-space coords (y-up) → canvas pixel coords */\nexport function pdfToCanvas(\n pdfX: number,\n pdfY: number,\n scale: number,\n pageHeight: number\n): { x: number; y: number } {\n return {\n x: pdfX * scale,\n y: (pageHeight - pdfY) * scale,\n };\n}\n\n/**\n * Convert a PDF bounds rect (y-up, y = bottom edge) → canvas rect (y-down, y = top edge).\n * All values are in CSS pixels (not physical pixels).\n */\nexport function pdfBoundsToCanvas(\n bounds: AnnotationBounds,\n scale: number,\n pageHeight: number\n): { x: number; y: number; width: number; height: number } {\n return {\n x: bounds.x * scale,\n y: (pageHeight - bounds.y - bounds.height) * scale,\n width: bounds.width * scale,\n height: bounds.height * scale,\n };\n}\n\n/**\n * Convert a canvas drag rect (minX/Y, maxX/Y in CSS pixels) → PDF bounds (y-up).\n * `bounds.y` is the bottom edge in PDF space, consistent with iOS/Android.\n */\nexport function canvasRectToPdfBounds(\n minX: number,\n minY: number,\n maxX: number,\n maxY: number,\n scale: number,\n pageHeight: number\n): AnnotationBounds {\n return {\n x: minX / scale,\n y: pageHeight - maxY / scale,\n width: (maxX - minX) / scale,\n height: (maxY - minY) / scale,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Hit testing (ported from AnnotationHitTester.kt)\n// ---------------------------------------------------------------------------\n\nexport function distanceToSegment(\n point: AnnotationPoint,\n a: AnnotationPoint,\n b: AnnotationPoint\n): number {\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const lenSq = dx * dx + dy * dy;\n if (lenSq === 0) {\n const px = point.x - a.x;\n const py = point.y - a.y;\n return Math.sqrt(px * px + py * py);\n }\n let t = ((point.x - a.x) * dx + (point.y - a.y) * dy) / lenSq;\n t = Math.max(0, Math.min(1, t));\n const projX = a.x + t * dx;\n const projY = a.y + t * dy;\n const ex = point.x - projX;\n const ey = point.y - projY;\n return Math.sqrt(ex * ex + ey * ey);\n}\n\nfunction boundsContains(bounds: AnnotationBounds, point: AnnotationPoint): boolean {\n return (\n point.x >= bounds.x &&\n point.x <= bounds.x + bounds.width &&\n point.y >= bounds.y &&\n point.y <= bounds.y + bounds.height\n );\n}\n\n/** Return the topmost annotation hit at pdfPoint on pageIndex, or null. */\nexport function hitTestAnnotation(\n pdfPoint: AnnotationPoint,\n annotations: Annotation[],\n pageIndex: number\n): Annotation | null {\n const onPage = annotations.filter((a) => a.page === pageIndex);\n for (let i = onPage.length - 1; i >= 0; i--) {\n const annotation = onPage[i];\n if (annotation.type === 'ink') {\n const tolerance = Math.max(annotation.lineWidth ?? 2, 10);\n const paths = annotation.paths ?? [];\n for (const stroke of paths) {\n if (stroke.length === 1) {\n const dx = pdfPoint.x - stroke[0].x;\n const dy = pdfPoint.y - stroke[0].y;\n if (Math.sqrt(dx * dx + dy * dy) <= tolerance) return annotation;\n }\n for (let j = 0; j < stroke.length - 1; j++) {\n if (distanceToSegment(pdfPoint, stroke[j], stroke[j + 1]) <= tolerance) {\n return annotation;\n }\n }\n }\n } else {\n const bounds = annotation.bounds;\n if (bounds && boundsContains(bounds, pdfPoint)) return annotation;\n }\n }\n return null;\n}\n\n// ---------------------------------------------------------------------------\n// Canvas drawing (mirrors AnnotationRenderer.kt)\n// ---------------------------------------------------------------------------\n\n/**\n * Draw all annotations for pageIndex onto ctx.\n * meta.scale is CSS-pixels-per-PDF-point; canvas backing = CSS * devicePixelRatio,\n * but the caller should have called ctx.scale(dpr, dpr) so we work in CSS pixels here.\n */\nexport function drawAnnotationsOnCanvas(\n ctx: CanvasRenderingContext2D,\n annotations: Annotation[],\n pageIndex: number,\n meta: PdfPageMeta\n): void {\n const { scale, pdfHeight } = meta;\n for (const annotation of annotations) {\n if (annotation.page !== pageIndex) continue;\n switch (annotation.type) {\n case 'ink': {\n const paths = annotation.paths ?? [];\n ctx.save();\n ctx.strokeStyle = annotation.color;\n ctx.lineWidth = (annotation.lineWidth ?? 2) * scale;\n ctx.lineCap = 'round';\n ctx.lineJoin = 'round';\n for (const stroke of paths) {\n if (stroke.length === 0) continue;\n ctx.beginPath();\n for (let i = 0; i < stroke.length; i++) {\n const { x, y } = pdfToCanvas(stroke[i].x, stroke[i].y, scale, pdfHeight);\n if (i === 0) ctx.moveTo(x, y);\n else ctx.lineTo(x, y);\n }\n ctx.stroke();\n }\n ctx.restore();\n break;\n }\n case 'highlight': {\n const bounds = annotation.bounds;\n if (!bounds) break;\n const rect = pdfBoundsToCanvas(bounds, scale, pdfHeight);\n ctx.save();\n ctx.globalAlpha = annotation.alpha ?? 0.5;\n ctx.fillStyle = annotation.color;\n ctx.fillRect(rect.x, rect.y, rect.width, rect.height);\n ctx.restore();\n break;\n }\n case 'underline': {\n const bounds = annotation.bounds;\n if (!bounds) break;\n // Underline sits at the bottom of bounds (PDF y = bounds.y = bottom edge)\n const left = bounds.x * scale;\n const bottom = (pdfHeight - bounds.y) * scale;\n const right = left + bounds.width * scale;\n ctx.save();\n ctx.strokeStyle = annotation.color;\n ctx.lineWidth = scale;\n ctx.beginPath();\n ctx.moveTo(left, bottom);\n ctx.lineTo(right, bottom);\n ctx.stroke();\n ctx.restore();\n break;\n }\n case 'text':\n case 'freeText': {\n const bounds = annotation.bounds;\n const text = annotation.contents;\n if (!bounds || !text) break;\n const fontSize = (annotation.fontSize ?? 16) * scale;\n ctx.save();\n ctx.fillStyle = annotation.color;\n ctx.font = `${fontSize}px sans-serif`;\n const canvasTop = (pdfHeight - bounds.y - bounds.height) * scale;\n ctx.fillText(text, bounds.x * scale, canvasTop + fontSize);\n ctx.restore();\n break;\n }\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Serialization\n// ---------------------------------------------------------------------------\n\nexport function parseAnnotations(json?: string): AnnotationsData {\n if (!json) return { version: 1, annotations: [] };\n try {\n const data = JSON.parse(json) as AnnotationsData;\n if (!Array.isArray(data?.annotations)) return { version: 1, annotations: [] };\n // Deduplicate by id — last wins\n const seen = new Map<string, Annotation>();\n for (const a of data.annotations) {\n seen.set(a.id, a);\n }\n return { version: 1, annotations: Array.from(seen.values()) };\n } catch {\n return { version: 1, annotations: [] };\n }\n}\n\nexport function serializeAnnotations(data: AnnotationsData): string {\n return JSON.stringify(data);\n}\n\nexport function newAnnotationId(): string {\n if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') {\n return crypto.randomUUID();\n }\n return Math.random().toString(36).slice(2) + Date.now().toString(36);\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type PdfPageMeta = {
|
|
2
|
+
/** PDF page width in PDF user-space points */
|
|
3
|
+
pdfWidth: number;
|
|
4
|
+
/** PDF page height in PDF user-space points */
|
|
5
|
+
pdfHeight: number;
|
|
6
|
+
/** Pixels per PDF point (containerWidth / pdfWidth) */
|
|
7
|
+
scale: number;
|
|
8
|
+
/** Canvas backing width in physical pixels (CSS width × devicePixelRatio) */
|
|
9
|
+
canvasWidth: number;
|
|
10
|
+
/** Canvas backing height in physical pixels (CSS height × devicePixelRatio) */
|
|
11
|
+
canvasHeight: number;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/web/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG;IACxB,8CAA8C;IAC9C,QAAQ,EAAE,MAAM,CAAC;IACjB,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,uDAAuD;IACvD,KAAK,EAAE,MAAM,CAAC;IACd,6EAA6E;IAC7E,WAAW,EAAE,MAAM,CAAC;IACpB,+EAA+E;IAC/E,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/web/types.ts"],"names":[],"mappings":"","sourcesContent":["export type PdfPageMeta = {\n /** PDF page width in PDF user-space points */\n pdfWidth: number;\n /** PDF page height in PDF user-space points */\n pdfHeight: number;\n /** Pixels per PDF point (containerWidth / pdfWidth) */\n scale: number;\n /** Canvas backing width in physical pixels (CSS width × devicePixelRatio) */\n canvasWidth: number;\n /** Canvas backing height in physical pixels (CSS height × devicePixelRatio) */\n canvasHeight: number;\n};\n"]}
|
|
@@ -11,7 +11,11 @@ class ExpoPdfMarkupView: ExpoView, UIGestureRecognizerDelegate {
|
|
|
11
11
|
private var currentSource: String?
|
|
12
12
|
private var currentAnnotationsJSON: String?
|
|
13
13
|
private var currentMode: String = "none"
|
|
14
|
-
var annotationColor: String = "#FF0000"
|
|
14
|
+
var annotationColor: String = "#FF0000" {
|
|
15
|
+
didSet {
|
|
16
|
+
inkShapeLayer?.strokeColor = (AnnotationSerializer.colorFromHex(annotationColor) ?? .red).cgColor
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
var annotationLineWidth: CGFloat = 2.0
|
|
16
20
|
|
|
17
21
|
private var inkPanGesture: UIPanGestureRecognizer?
|
package/metro.d.ts
ADDED
package/metro.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metro config plugin for @tobyt/expo-pdf-markup.
|
|
3
|
+
*
|
|
4
|
+
* Add to your metro.config.js:
|
|
5
|
+
*
|
|
6
|
+
* const { getDefaultConfig } = require('expo/metro-config');
|
|
7
|
+
* const { withPdfMarkup } = require('@tobyt/expo-pdf-markup/metro');
|
|
8
|
+
* const config = getDefaultConfig(__dirname);
|
|
9
|
+
* module.exports = withPdfMarkup(config);
|
|
10
|
+
*
|
|
11
|
+
* This does two things:
|
|
12
|
+
* 1. Patches `import.meta` in pdfjs-dist source before Babel/hermes-parser
|
|
13
|
+
* sees it (pdfjs-dist v4 uses it in a Node.js-only code path that is dead
|
|
14
|
+
* code in the browser, but Metro bundles as a non-module script so the
|
|
15
|
+
* browser's JS engine refuses to parse the bundle).
|
|
16
|
+
* 2. Copies the pdfjs worker file to <projectRoot>/public/pdf.worker.min.mjs
|
|
17
|
+
* so it is served at /pdf.worker.min.mjs (same-origin, no CORS issues).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
'use strict';
|
|
21
|
+
|
|
22
|
+
const fs = require('fs');
|
|
23
|
+
const path = require('path');
|
|
24
|
+
|
|
25
|
+
// ---------------------------------------------------------------------------
|
|
26
|
+
// Babel transformer interface
|
|
27
|
+
// Metro loads this file as the babelTransformer, so it must export `transform`.
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
let _upstream = null;
|
|
31
|
+
function upstream(projectRoot) {
|
|
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
|
+
);
|
|
40
|
+
_upstream = require(
|
|
41
|
+
path.join(expoDir, 'node_modules/@expo/metro-config/build/babel-transformer')
|
|
42
|
+
);
|
|
43
|
+
return _upstream;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
module.exports.transform = function transform({ filename, src, options, plugins }) {
|
|
47
|
+
// Replace `import.meta` with `({})` in pdfjs-dist files before any parser
|
|
48
|
+
// sees the source. `({}).url` → undefined, which is harmless: the method
|
|
49
|
+
// that uses it (NodeCanvasFactory._createCanvas) is Node.js-only dead code.
|
|
50
|
+
if (filename.includes('pdfjs-dist') && src.includes('import.meta')) {
|
|
51
|
+
src = src.replace(/import\.meta/g, '({})');
|
|
52
|
+
}
|
|
53
|
+
return upstream(options.projectRoot).transform({ filename, src, options, plugins });
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// Metro config helper
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
|
|
60
|
+
module.exports.withPdfMarkup = function withPdfMarkup(config) {
|
|
61
|
+
// 1. Swap in this file as the babel transformer so import.meta is patched.
|
|
62
|
+
config.transformer.babelTransformerPath = require.resolve('./metro.js');
|
|
63
|
+
|
|
64
|
+
// 2. Copy the pdfjs worker to <projectRoot>/public/ so it is served at
|
|
65
|
+
// /pdf.worker.min.mjs (same-origin). Only copies if not already present,
|
|
66
|
+
// so repeated Metro restarts are fast.
|
|
67
|
+
const projectRoot = config.projectRoot ?? process.cwd();
|
|
68
|
+
const publicDir = path.join(projectRoot, 'public');
|
|
69
|
+
const dest = path.join(publicDir, 'pdf.worker.min.mjs');
|
|
70
|
+
|
|
71
|
+
if (!fs.existsSync(dest)) {
|
|
72
|
+
let workerSrc;
|
|
73
|
+
try {
|
|
74
|
+
workerSrc = require.resolve('pdfjs-dist/build/pdf.worker.min.mjs');
|
|
75
|
+
} catch {
|
|
76
|
+
console.warn(
|
|
77
|
+
'[expo-pdf-markup] Could not find pdfjs-dist. ' +
|
|
78
|
+
'Install it as a dependency to enable web PDF rendering.'
|
|
79
|
+
);
|
|
80
|
+
return config;
|
|
81
|
+
}
|
|
82
|
+
if (!fs.existsSync(publicDir)) {
|
|
83
|
+
fs.mkdirSync(publicDir, { recursive: true });
|
|
84
|
+
}
|
|
85
|
+
fs.copyFileSync(workerSrc, dest);
|
|
86
|
+
console.log('[expo-pdf-markup] Copied pdfjs worker → ' + dest);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return config;
|
|
90
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tobyt/expo-pdf-markup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "An Expo module for displaying and annotating PDFs",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
"@types/react-test-renderer": "^19.1.0",
|
|
58
58
|
"expo": "^55.0.5",
|
|
59
59
|
"expo-module-scripts": "^55.0.2",
|
|
60
|
+
"pdfjs-dist": "^4.10.38",
|
|
60
61
|
"react-native": "0.83.2",
|
|
61
62
|
"react-native-web": "^0.21.2",
|
|
62
63
|
"typedoc": "^0.28.17"
|
|
@@ -66,7 +67,13 @@
|
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
69
|
"expo": "*",
|
|
70
|
+
"pdfjs-dist": ">=3.0.0",
|
|
69
71
|
"react": "*",
|
|
70
72
|
"react-native": "*"
|
|
73
|
+
},
|
|
74
|
+
"peerDependenciesMeta": {
|
|
75
|
+
"pdfjs-dist": {
|
|
76
|
+
"optional": true
|
|
77
|
+
}
|
|
71
78
|
}
|
|
72
79
|
}
|
|
@@ -54,7 +54,7 @@ export type AnnotationsData = {
|
|
|
54
54
|
export type AnnotationMode = 'none' | 'ink' | 'highlight' | 'underline' | 'text' | 'eraser';
|
|
55
55
|
|
|
56
56
|
export type ExpoPdfMarkupViewProps = {
|
|
57
|
-
/**
|
|
57
|
+
/** Absolute local file path of the PDF to display. */
|
|
58
58
|
source: string;
|
|
59
59
|
/** 0-based page number to display. Can be used to restore scroll position on orientation change. */
|
|
60
60
|
page?: number;
|